diff options
| -rw-r--r-- | chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala | 4 | ||||
| -rw-r--r-- | chiselFrontend/src/main/scala/chisel3/core/Bits.scala | 20 | ||||
| -rw-r--r-- | chiselFrontend/src/main/scala/chisel3/core/package.scala | 8 | ||||
| -rw-r--r-- | src/main/scala/chisel3/compatibility.scala | 48 | ||||
| -rw-r--r-- | src/main/scala/chisel3/compatibility/Main.scala | 19 | ||||
| -rw-r--r-- | src/main/scala/chisel3/compatibility/debug.scala | 10 | ||||
| -rw-r--r-- | src/main/scala/chisel3/compatibility/throwException.scala | 14 | ||||
| -rw-r--r-- | src/main/scala/chisel3/package.scala | 9 |
8 files changed, 67 insertions, 65 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala b/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala index 77a1b57a..8fdcb260 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala @@ -261,14 +261,14 @@ trait VecLike[T <: Data] extends collection.IndexedSeq[T] with HasId { def forall(p: T => Bool): Bool = macro SourceInfoTransform.pArg def do_forall(p: T => Bool)(implicit sourceInfo: SourceInfo): Bool = - (this map p).fold(Bool(true))(_ && _) + (this map p).fold(true.B)(_ && _) /** Outputs true if p outputs true for at least one element. */ def exists(p: T => Bool): Bool = macro SourceInfoTransform.pArg def do_exists(p: T => Bool)(implicit sourceInfo: SourceInfo): Bool = - (this map p).fold(Bool(false))(_ || _) + (this map p).fold(false.B)(_ || _) /** Outputs true if the vector contains at least one element equal to x (using * the === operator). diff --git a/chiselFrontend/src/main/scala/chisel3/core/Bits.scala b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala index aa73abf5..b81679b6 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/Bits.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala @@ -92,7 +92,7 @@ sealed abstract class Bits(width: Width, override val litArg: Option[LitArg]) Builder.error(s"Negative bit indices are illegal (got $x)") } if (isLit()) { - Bool(((litValue() >> x.toInt) & 1) == 1) + (((litValue() >> x.toInt) & 1) == 1).asBool } else { Binding.checkSynthesizable(this, s"'this' ($this)") pushOp(DefPrim(sourceInfo, Bool(), BitsExtractOp, this.ref, ILit(x), ILit(x))) @@ -698,7 +698,7 @@ sealed class Bool(lit: Option[ULit] = None) extends UInt(Width(1), lit) { override private[chisel3] def fromInt(value: BigInt, width: Int): this.type = { require((value == 0 || value == 1) && width == 1) - Bool(value == 1).asInstanceOf[this.type] + (value == 1).asBool.asInstanceOf[this.type] } // REVIEW TODO: Why does this need to exist and have different conventions @@ -736,31 +736,23 @@ sealed class Bool(lit: Option[ULit] = None) extends UInt(Width(1), lit) { def do_asClock(implicit sourceInfo: SourceInfo): Clock = pushOp(DefPrim(sourceInfo, Clock(), AsClockOp, ref)) } -object Bool { +trait BoolFactory { /** Creates an empty Bool. */ def apply(): Bool = new Bool() /** Creates Bool literal. */ - def apply(x: Boolean): Bool = Lit(x) - def Lit(x: Boolean): Bool = { + protected[chisel3] def Lit(x: Boolean): Bool = { val result = new Bool(Some(ULit(if (x) 1 else 0, Width(1)))) // Bind result to being an Literal result.binding = LitBinding() result } - /** Create a UInt with a specified direction and width - compatibility with Chisel2. */ - def apply(dir: Direction): Bool = { - val result = apply() - dir match { - case Direction.Input => Input(result) - case Direction.Output => Output(result) - case Direction.Unspecified => result - } - } } +object Bool extends BoolFactory + object Mux { /** Creates a mux, whose output is one of the inputs depending on the * value of the condition. diff --git a/chiselFrontend/src/main/scala/chisel3/core/package.scala b/chiselFrontend/src/main/scala/chisel3/core/package.scala index 7fb05c75..ac10a140 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/package.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/package.scala @@ -104,7 +104,13 @@ package chisel3 { } implicit class fromBooleanToLiteral(val x: Boolean) { - def B: Bool = Bool(x) // scalastyle:ignore method.name + /** Boolean to Bool conversion, recommended style for constants. + */ + def B: Bool = Bool.Lit(x) // scalastyle:ignore method.name + + /** Boolean to Bool conversion, recommended style for variables. + */ + def asBool: Bool = Bool.Lit(x) } implicit class fromDoubleToLiteral(val x: Double) { diff --git a/src/main/scala/chisel3/compatibility.scala b/src/main/scala/chisel3/compatibility.scala index a9365ac3..9d0e266b 100644 --- a/src/main/scala/chisel3/compatibility.scala +++ b/src/main/scala/chisel3/compatibility.scala @@ -113,6 +113,22 @@ package object Chisel { // scalastyle:ignore package.object.name } } + trait BoolFactory extends chisel3.core.BoolFactory { + /** Creates Bool literal. + */ + def apply(x: Boolean): Bool = Lit(x) + + /** Create a UInt with a specified direction and width - compatibility with Chisel2. */ + def apply(dir: Direction): Bool = { + val result = apply() + dir match { + case chisel3.core.Direction.Input => chisel3.core.Input(result) + case chisel3.core.Direction.Output => chisel3.core.Output(result) + case chisel3.core.Direction.Unspecified => result + } + } + } + type Element = chisel3.core.Element type Bits = chisel3.core.Bits object Bits extends UIntFactory @@ -122,7 +138,7 @@ package object Chisel { // scalastyle:ignore package.object.name type SInt = chisel3.core.SInt object SInt extends SIntFactory type Bool = chisel3.core.Bool - val Bool = chisel3.core.Bool + object Bool extends BoolFactory val Mux = chisel3.core.Mux type BlackBox = chisel3.core.BlackBox @@ -152,9 +168,33 @@ package object Chisel { // scalastyle:ignore package.object.name type BackendCompilationUtilities = chisel3.BackendCompilationUtilities val Driver = chisel3.Driver val ImplicitConversions = chisel3.util.ImplicitConversions - val chiselMain = chisel3.compatibility.chiselMain - val throwException = chisel3.compatibility.throwException - val debug = chisel3.compatibility.debug + + object chiselMain { + import java.io.File + + def apply[T <: Module](args: Array[String], gen: () => T): Unit = + Predef.assert(false, "No more chiselMain in Chisel3") + + def run[T <: Module] (args: Array[String], gen: () => T): Unit = { + val circuit = Driver.elaborate(gen) + Driver.parseArgs(args) + val output_file = new File(Driver.targetDir + "/" + circuit.name + ".fir") + Driver.dumpFirrtl(circuit, Option(output_file)) + } + } + + @deprecated("debug doesn't do anything in Chisel3 as no pruning happens in the frontend", "chisel3") + object debug { // scalastyle:ignore object.name + def apply (arg: Data): Data = arg + } + + @throws(classOf[Exception]) + object throwException { + def apply(s: String, t: Throwable = null) = { + val xcpt = new Exception(s, t) + throw xcpt + } + } object testers { // scalastyle:ignore object.name type BasicTester = chisel3.testers.BasicTester diff --git a/src/main/scala/chisel3/compatibility/Main.scala b/src/main/scala/chisel3/compatibility/Main.scala deleted file mode 100644 index a41599a3..00000000 --- a/src/main/scala/chisel3/compatibility/Main.scala +++ /dev/null @@ -1,19 +0,0 @@ -// See LICENSE for license details. - -package chisel3.compatibility - -import java.io.File - -import chisel3._ - -@deprecated("chiselMain doesn't exist in Chisel3", "3.0") object chiselMain { - def apply[T <: Module](args: Array[String], gen: () => T): Unit = - Predef.assert(false, "No more chiselMain in Chisel3") - - def run[T <: Module] (args: Array[String], gen: () => T): Unit = { - val circuit = Driver.elaborate(gen) - Driver.parseArgs(args) - val output_file = new File(Driver.targetDir + "/" + circuit.name + ".fir") - Driver.dumpFirrtl(circuit, Option(output_file)) - } -} diff --git a/src/main/scala/chisel3/compatibility/debug.scala b/src/main/scala/chisel3/compatibility/debug.scala deleted file mode 100644 index d9f6e4b0..00000000 --- a/src/main/scala/chisel3/compatibility/debug.scala +++ /dev/null @@ -1,10 +0,0 @@ -// See LICENSE for license details. - -package chisel3.compatibility - -import chisel3.core._ - -@deprecated("debug doesn't do anything in Chisel3 as no pruning happens in the frontend", "chisel3") -object debug { // scalastyle:ignore object.name - def apply (arg: Data): Data = arg -} diff --git a/src/main/scala/chisel3/compatibility/throwException.scala b/src/main/scala/chisel3/compatibility/throwException.scala deleted file mode 100644 index 3e8b33e6..00000000 --- a/src/main/scala/chisel3/compatibility/throwException.scala +++ /dev/null @@ -1,14 +0,0 @@ -// See LICENSE for license details. - -package chisel3.compatibility - -import chisel3._ - -@deprecated("throwException doesn't exist in Chisel3", "3.0.0") -@throws(classOf[Exception]) -object throwException { - def apply(s: String, t: Throwable = null) = { - val xcpt = new Exception(s, t) - throw xcpt - } -} diff --git a/src/main/scala/chisel3/package.scala b/src/main/scala/chisel3/package.scala index 1a100480..8ac76867 100644 --- a/src/main/scala/chisel3/package.scala +++ b/src/main/scala/chisel3/package.scala @@ -93,6 +93,13 @@ package object chisel3 { // scalastyle:ignore package.object.name def Lit(value: BigInt, width: Int): SInt = Lit(value, Width(width)) } + trait BoolFactory extends chisel3.core.BoolFactory { + /** Creates Bool literal. + */ + @deprecated("chisel3, will be removed by end of 2016, use x.B") + def apply(x: Boolean): Bool = Lit(x) + } + object Bits extends UIntFactory type Num[T <: Data] = chisel3.core.Num[T] type UInt = chisel3.core.UInt @@ -102,7 +109,7 @@ package object chisel3 { // scalastyle:ignore package.object.name type FixedPoint = chisel3.core.FixedPoint val FixedPoint = chisel3.core.FixedPoint type Bool = chisel3.core.Bool - val Bool = chisel3.core.Bool + object Bool extends BoolFactory val Mux = chisel3.core.Mux type BlackBox = chisel3.core.BlackBox |
