diff options
| author | Richard Lin | 2018-11-01 17:06:35 -0700 |
|---|---|---|
| committer | GitHub | 2018-11-01 17:06:35 -0700 |
| commit | 1910f708bb99e906bf83dc13fbedd95d40410d98 (patch) | |
| tree | b5a36df0d64f1f2de2a9b0d435c342832b2dabc5 /chiselFrontend/src/main/scala | |
| parent | 4dddde56d0c1a66a05457c7dda409238d2de8e8a (diff) | |
Add BigInt / Int to Bool conversion (0.B, 1.B) (#913)
Diffstat (limited to 'chiselFrontend/src/main/scala')
| -rw-r--r-- | chiselFrontend/src/main/scala/chisel3/core/package.scala | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/package.scala b/chiselFrontend/src/main/scala/chisel3/core/package.scala index f68ce0e8..99c9a7ae 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/package.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/package.scala @@ -24,6 +24,13 @@ package chisel3 { * `0.asUInt(16)` (instead of `16.W`) compile without error and produce undesired results. */ implicit class fromBigIntToLiteral(bigint: BigInt) { + /** Int to Bool conversion, allowing compact syntax like 1.B and 0.B + */ + def B: Bool = bigint match { + case bigint if bigint == 0 => Bool.Lit(false) + case bigint if bigint == 1 => Bool.Lit(true) + case bigint => Builder.error(s"Cannot convert $bigint to Bool, must be 0 or 1"); Bool.Lit(false) + } /** Int to UInt conversion, recommended style for constants. */ def U: UInt = UInt.Lit(bigint, Width()) // scalastyle:ignore method.name |
