diff options
| author | ducky | 2016-11-16 18:47:36 -0800 |
|---|---|---|
| committer | ducky | 2016-11-21 13:30:22 -0800 |
| commit | e0b277a40693476247a68e7c52672b547d7ceb17 (patch) | |
| tree | 14d2a8de52243c4dc3bd4d1420f7cc436676a6e9 | |
| parent | 15a8d3818a1b185051b260ffc82da1fb4a60a45e (diff) | |
Deprecate things, split more things
| -rw-r--r-- | chiselFrontend/src/main/scala/chisel3/core/Bits.scala | 30 | ||||
| -rw-r--r-- | chiselFrontend/src/main/scala/chisel3/core/package.scala | 33 | ||||
| -rw-r--r-- | src/main/scala/chisel3/compatibility.scala | 12 | ||||
| -rw-r--r-- | src/main/scala/chisel3/package.scala | 34 |
4 files changed, 54 insertions, 55 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Bits.scala b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala index 1d3f9243..70da27fc 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/Bits.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala @@ -533,12 +533,6 @@ trait UIntFactory { /** Create a UInt port with specified width. */ def apply(width: Width): UInt = new UInt(width) - protected[chisel3] def Lit(value: BigInt, width: Int): UInt = Lit(value, Width(width)) - /** Create a UInt literal with inferred width. */ - protected[chisel3] def Lit(value: BigInt): UInt = Lit(value, Width()) - protected[chisel3] def Lit(n: String): UInt = Lit(parse(n), parsedWidth(n)) - /** Create a UInt literal with fixed width. */ - protected[chisel3] def Lit(n: String, width: Int): UInt = Lit(parse(n), width) /** Create a UInt literal with specified width. */ protected[chisel3] def Lit(value: BigInt, width: Width): UInt = { val lit = ULit(value, width) @@ -547,35 +541,15 @@ trait UIntFactory { result.binding = LitBinding() result } + /** Create a UInt with the specified range */ def apply(range: Range): UInt = { - width(range.getWidth) + apply(range.getWidth) } /** Create a UInt with the specified range */ def apply(range: (NumericBound[Int], NumericBound[Int])): UInt = { apply(KnownUIntRange(range._1, range._2)) } - - protected def parse(n: String) = { - val (base, num) = n.splitAt(1) - val radix = base match { - case "x" | "h" => 16 - case "d" => 10 - case "o" => 8 - case "b" => 2 - case _ => Builder.error(s"Invalid base $base"); 2 - } - BigInt(num.filterNot(_ == '_'), radix) - } - - protected def parsedWidth(n: String) = - if (n(0) == 'b') { - Width(n.length-1) - } else if (n(0) == 'h') { - Width((n.length-1) * 4) - } else { - Width() - } } object UInt extends UIntFactory diff --git a/chiselFrontend/src/main/scala/chisel3/core/package.scala b/chiselFrontend/src/main/scala/chisel3/core/package.scala index 46dfbe20..554e6238 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/package.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/package.scala @@ -1,4 +1,6 @@ package chisel3 { + import internal.Builder + package object core { import internal.firrtl.Width @@ -21,8 +23,8 @@ package chisel3 { def asUInt(): UInt = UInt.Lit(x, Width()) def asSInt(): SInt = SInt(x, Width()) - def asUInt(width: Int): UInt = UInt.Lit(x, width) - def asSInt(width: Int): SInt = SInt(x, width) + def asUInt(width: Int): UInt = UInt.Lit(x, Width(width)) + def asSInt(width: Int): SInt = SInt(x, Width(width)) } implicit class fromBigIntToLiteral(val x: BigInt) { @@ -31,12 +33,35 @@ package chisel3 { def asUInt(): UInt = UInt.Lit(x, Width()) def asSInt(): SInt = SInt(x, Width()) - def asUInt(width: Int): UInt = UInt.Lit(x, width) + def asUInt(width: Int): UInt = UInt.Lit(x, Width(width)) def asSInt(width: Int): SInt = SInt(x, width) } implicit class fromStringToLiteral(val x: String) { - def U: UInt = UInt.Lit(x) // scalastyle:ignore method.name + def U: UInt = UInt.Lit(fromStringToLiteral.parse(x), fromStringToLiteral.parsedWidth(x)) // scalastyle:ignore method.name + } + + object fromStringToLiteral { + def parse(n: String) = { + val (base, num) = n.splitAt(1) + val radix = base match { + case "x" | "h" => 16 + case "d" => 10 + case "o" => 8 + case "b" => 2 + case _ => Builder.error(s"Invalid base $base"); 2 + } + BigInt(num.filterNot(_ == '_'), radix) + } + + def parsedWidth(n: String) = + if (n(0) == 'b') { + Width(n.length-1) + } else if (n(0) == 'h') { + Width((n.length-1) * 4) + } else { + Width() + } } implicit class fromBooleanToLiteral(val x: Boolean) { diff --git a/src/main/scala/chisel3/compatibility.scala b/src/main/scala/chisel3/compatibility.scala index 7157b4d4..ac0caa45 100644 --- a/src/main/scala/chisel3/compatibility.scala +++ b/src/main/scala/chisel3/compatibility.scala @@ -42,13 +42,12 @@ package object Chisel { // scalastyle:ignore package.object.name trait UIntFactory extends chisel3.core.UIntFactory { import chisel3.internal.firrtl.Width - /** Create a UInt with a specified width */ - def width(width: Int): UInt = apply(Width(width)) - /** Create a UInt literal with inferred width. */ - def apply(n: String): UInt = Lit(n) + def apply(n: String): UInt = Lit(chisel3.core.fromStringToLiteral.parse(n), + chisel3.core.fromStringToLiteral.parsedWidth(n)) /** Create a UInt literal with fixed width. */ - def apply(n: String, width: Int): UInt = Lit(parse(n), width) + def apply(n: String, width: Int): UInt = Lit(chisel3.core.fromStringToLiteral.parse(n), + Width(width)) /** Create a UInt literal with specified width. */ def apply(value: BigInt, width: Width): UInt = Lit(value, width) @@ -74,6 +73,9 @@ package object Chisel { // scalastyle:ignore package.object.name } } + /** Create a UInt with a specified width */ + def width(width: Int): UInt = apply(Width(width)) + /** Create a UInt port with specified width. */ def width(width: Width): UInt = apply(width) } diff --git a/src/main/scala/chisel3/package.scala b/src/main/scala/chisel3/package.scala index 07dcdaca..84a4779e 100644 --- a/src/main/scala/chisel3/package.scala +++ b/src/main/scala/chisel3/package.scala @@ -33,39 +33,37 @@ package object chisel3 { // scalastyle:ignore package.object.name type Bits = chisel3.core.Bits trait UIntFactory extends chisel3.core.UIntFactory { - /** Create a UInt with a specified width */ - def width(width: Int): UInt = apply(Width(width)) - /** Create a UInt literal with inferred width. */ - def apply(n: String): UInt = Lit(n) + @deprecated("chisel3, will be removed by end of 2016, use n.U") + def apply(n: String): UInt = Lit(chisel3.core.fromStringToLiteral.parse(n), + chisel3.core.fromStringToLiteral.parsedWidth(n)) /** Create a UInt literal with fixed width. */ - def apply(n: String, width: Int): UInt = Lit(parse(n), width) + @deprecated("chisel3, will be removed by end of 2016, use n.U(width: Width)") + def apply(n: String, width: Int): UInt = Lit(chisel3.core.fromStringToLiteral.parse(n), + Width(width)) /** Create a UInt literal with specified width. */ + @deprecated("chisel3, will be removed by end of 2016, use value.U(width: Width)") def apply(value: BigInt, width: Width): UInt = Lit(value, width) /** Create a UInt literal with fixed width. */ + @deprecated("chisel3, will be removed by end of 2016, use value.U(width: Width)") def apply(value: BigInt, width: Int): UInt = Lit(value, Width(width)) /** Create a UInt with a specified width - compatibility with Chisel2. */ - // NOTE: This resolves UInt(width = 32) + @deprecated("chisel3, will be removed by end of 2016, use UInt(width: Width)") def apply(dir: Option[Direction] = None, width: Int): UInt = apply(Width(width)) + /** Create a UInt literal with inferred width.- compatibility with Chisel2. */ + @deprecated("chisel3, will be removed by end of 2016, use value.U") def apply(value: BigInt): UInt = apply(value, Width()) - /** Create a UInt with a specified direction and width - compatibility with Chisel2. */ - def apply(dir: Direction, width: Int): UInt = apply(dir, Width(width)) - /** Create a UInt with a specified direction, but unspecified width - compatibility with Chisel2. */ - def apply(dir: Direction): UInt = apply(dir, Width()) - def apply(dir: Direction, wWidth: Width): UInt = { - val result = apply(wWidth) - dir match { - case chisel3.core.Direction.Input => Input(result) - case chisel3.core.Direction.Output => Output(result) - case chisel3.core.Direction.Unspecified => result - } - } + + /** Create a UInt with a specified width */ + @deprecated("chisel3, will be removed by end of 2016, use UInt(width: Width)") + def width(width: Int): UInt = apply(Width(width)) /** Create a UInt port with specified width. */ + @deprecated("chisel3, will be removed by end of 2016, use UInt(width: Width)") def width(width: Width): UInt = apply(width) } |
