Skip to content

Commit

Permalink
Add toString method to BitPat (#1819)
Browse files Browse the repository at this point in the history
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit 2a56c65)

# Conflicts:
#	src/main/scala/chisel3/util/BitPat.scala
  • Loading branch information
yqszxx authored and mergify-bot committed Mar 18, 2021
1 parent f5d61ee commit be93c02
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main/scala/chisel3/util/BitPat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,20 @@ sealed class BitPat(val value: BigInt, val mask: BigInt, width: Int) extends Sou
!(this === that)
}

<<<<<<< HEAD
def != (that: UInt): Bool = macro SourceInfoTransform.thatArg
@chiselRuntimeDeprecated
@deprecated("Use '=/=', which avoids potential precedence problems", "3.0")
def do_!= (that: UInt)
(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = {
this =/= that
=======
override def toString = {
"BitPat(" +
(0 until width).map(i =>
if (((mask >> i) & 1) == 1) if (((value >> i) & 1) == 1) "1" else "0" else "?"
).reverse.reduce(_ + _) +
")"
>>>>>>> 2a56c654... Add toString method to BitPat (#1819)
}
}
17 changes: 17 additions & 0 deletions src/test/scala/chiselTests/util/BitPatSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: Apache-2.0

package chiselTests.util

import chisel3.util.BitPat
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers


class BitPatSpec extends AnyFlatSpec with Matchers {
behavior of classOf[BitPat].toString

it should "convert a BitPat to readable form" in {
val testPattern = "0" * 32 + "1" * 32 + "?" * 32 + "?01" * 32
BitPat("b" + testPattern).toString should be (s"BitPat($testPattern)")
}
}

0 comments on commit be93c02

Please sign in to comment.