summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorducky2016-11-17 13:31:23 -0800
committerducky2016-11-21 13:31:12 -0800
commitd89b54acc5a41dcc7498d97af314e58f6cd891c8 (patch)
tree56a6079adff466d91ab3a054d506c8a65b138c07
parentc270598ddb8cbfa32f8c86cc5187c89d00e6ded0 (diff)
Refactor some code
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/package.scala14
-rw-r--r--src/main/scala/chisel3/compatibility.scala47
-rw-r--r--src/main/scala/chisel3/package.scala32
3 files changed, 45 insertions, 48 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/package.scala b/chiselFrontend/src/main/scala/chisel3/core/package.scala
index 3defb4f9..4a032523 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/package.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/package.scala
@@ -76,21 +76,19 @@ package chisel3 {
implicit class fromStringToLiteral(val x: String) {
/** String to UInt parse, recommended style for constants.
*/
- def U: UInt = UInt.Lit(fromStringToLiteral.parse(x), fromStringToLiteral.parsedWidth(x)) // scalastyle:ignore method.name
+ def U: UInt = UInt.Lit(parse(x), parsedWidth(x)) // scalastyle:ignore method.name
/** String to UInt parse with specified width, recommended style for constants.
*/
- def U(width: Width): UInt = UInt.Lit(fromStringToLiteral.parse(x), width) // scalastyle:ignore method.name
+ def U(width: Width): UInt = UInt.Lit(parse(x), width) // scalastyle:ignore method.name
/** String to UInt parse, recommended style for variables.
*/
- def asUInt: UInt = UInt.Lit(fromStringToLiteral.parse(x), fromStringToLiteral.parsedWidth(x))
+ def asUInt: UInt = UInt.Lit(parse(x), parsedWidth(x))
/** String to UInt parse with specified width, recommended style for variables.
*/
- def asUInt(width: Width): UInt = UInt.Lit(fromStringToLiteral.parse(x), width)
- }
+ def asUInt(width: Width): UInt = UInt.Lit(parse(x), width)
- object fromStringToLiteral {
- def parse(n: String) = {
+ protected def parse(n: String) = {
val (base, num) = n.splitAt(1)
val radix = base match {
case "x" | "h" => 16
@@ -102,7 +100,7 @@ package chisel3 {
BigInt(num.filterNot(_ == '_'), radix)
}
- def parsedWidth(n: String) =
+ protected def parsedWidth(n: String) =
if (n(0) == 'b') {
Width(n.length-1)
} else if (n(0) == 'h') {
diff --git a/src/main/scala/chisel3/compatibility.scala b/src/main/scala/chisel3/compatibility.scala
index 625628dd..fbe37f50 100644
--- a/src/main/scala/chisel3/compatibility.scala
+++ b/src/main/scala/chisel3/compatibility.scala
@@ -45,29 +45,28 @@ package object Chisel { // scalastyle:ignore package.object.name
*/
trait UIntFactory extends chisel3.core.UIntFactory {
/** Create a UInt literal with inferred width. */
- def apply(n: String): UInt = Lit(chisel3.core.fromStringToLiteral.parse(n),
- chisel3.core.fromStringToLiteral.parsedWidth(n))
+ def apply(n: String): UInt = n.asUInt
/** Create a UInt literal with fixed width. */
- def apply(n: String, width: Int): UInt = Lit(chisel3.core.fromStringToLiteral.parse(n),
- Width(width))
+ def apply(n: String, width: Int): UInt = n.asUInt(width.W)
/** Create a UInt literal with specified width. */
- def apply(value: BigInt, width: Width): UInt = Lit(value, width)
+ def apply(value: BigInt, width: Width): UInt = value.asUInt(width)
/** Create a UInt literal with fixed width. */
- def apply(value: BigInt, width: Int): UInt = Lit(value, Width(width))
+ def apply(value: BigInt, width: Int): UInt = value.asUInt(width.W)
/** Create a UInt with a specified width - compatibility with Chisel2. */
// NOTE: This resolves UInt(width = 32)
- def apply(dir: Option[Direction] = None, width: Int): UInt = apply(Width(width))
+ def apply(dir: Option[Direction] = None, width: Int): UInt = apply(width.W)
/** Create a UInt literal with inferred width.- compatibility with Chisel2. */
- def apply(value: BigInt): UInt = apply(value, Width())
+ def apply(value: BigInt): UInt = value.asUInt
+
/** Create a UInt with a specified direction and width - compatibility with Chisel2. */
- def apply(dir: Direction, width: Int): UInt = apply(dir, Width(width))
+ def apply(dir: Direction, width: Int): UInt = apply(dir, width.W)
/** 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)
+ def apply(dir: Direction, width: Width): UInt = {
+ val result = apply(width)
dir match {
case chisel3.core.Direction.Input => chisel3.core.Input(result)
case chisel3.core.Direction.Output => chisel3.core.Output(result)
@@ -76,7 +75,7 @@ package object Chisel { // scalastyle:ignore package.object.name
}
/** Create a UInt with a specified width */
- def width(width: Int): UInt = apply(Width(width))
+ def width(width: Int): UInt = apply(width.W)
/** Create a UInt port with specified width. */
def width(width: Width): UInt = apply(width)
@@ -86,29 +85,29 @@ package object Chisel { // scalastyle:ignore package.object.name
*/
trait SIntFactory extends chisel3.core.SIntFactory {
/** Create a SInt type or port with fixed width. */
- def width(width: Int): SInt = apply(Width(width))
+ def width(width: Int): SInt = apply(width.W)
/** Create an SInt type with specified width. */
def width(width: Width): SInt = apply(width)
/** Create an SInt literal with inferred width. */
- def apply(value: BigInt): SInt = Lit(value)
+ def apply(value: BigInt): SInt = value.S
/** Create an SInt literal with fixed width. */
- def apply(value: BigInt, width: Int): SInt = Lit(value, width)
+ def apply(value: BigInt, width: Int): SInt = value.S(width.W)
/** Create an SInt literal with specified width. */
- def apply(value: BigInt, width: Width): SInt = Lit(value, width)
+ def apply(value: BigInt, width: Width): SInt = value.S(width)
- def Lit(value: BigInt): SInt = Lit(value, Width())
- def Lit(value: BigInt, width: Int): SInt = Lit(value, Width(width))
+ def Lit(value: BigInt): SInt = value.S
+ def Lit(value: BigInt, width: Int): SInt = value.S(width.W)
/** Create a SInt with a specified width - compatibility with Chisel2. */
- def apply(dir: Option[Direction] = None, width: Int): SInt = apply(Width(width))
+ def apply(dir: Option[Direction] = None, width: Int): SInt = apply(width.W)
/** Create a SInt with a specified direction and width - compatibility with Chisel2. */
- def apply(dir: Direction, width: Int): SInt = apply(dir, Width(width))
+ def apply(dir: Direction, width: Int): SInt = apply(dir, width.W)
/** Create a SInt with a specified direction, but unspecified width - compatibility with Chisel2. */
def apply(dir: Direction): SInt = apply(dir, Width())
- def apply(dir: Direction, wWidth: Width): SInt = {
- val result = apply(wWidth)
+ def apply(dir: Direction, width: Width): SInt = {
+ val result = apply(width)
dir match {
case chisel3.core.Direction.Input => chisel3.core.Input(result)
case chisel3.core.Direction.Output => chisel3.core.Output(result)
@@ -122,7 +121,7 @@ package object Chisel { // scalastyle:ignore package.object.name
trait BoolFactory extends chisel3.core.BoolFactory {
/** Creates Bool literal.
*/
- def apply(x: Boolean): Bool = Lit(x)
+ def apply(x: Boolean): Bool = x.B
/** Create a UInt with a specified direction and width - compatibility with Chisel2. */
def apply(dir: Direction): Bool = {
@@ -175,6 +174,7 @@ package object Chisel { // scalastyle:ignore package.object.name
val Driver = chisel3.Driver
val ImplicitConversions = chisel3.util.ImplicitConversions
+ // Deprecated as of Chisel3
object chiselMain {
import java.io.File
@@ -194,6 +194,7 @@ package object Chisel { // scalastyle:ignore package.object.name
def apply (arg: Data): Data = arg
}
+ // Deprecated as of Chsiel3
@throws(classOf[Exception])
object throwException {
def apply(s: String, t: Throwable = null) = {
diff --git a/src/main/scala/chisel3/package.scala b/src/main/scala/chisel3/package.scala
index 5b02be34..326f8d7c 100644
--- a/src/main/scala/chisel3/package.scala
+++ b/src/main/scala/chisel3/package.scala
@@ -33,7 +33,7 @@ package object chisel3 { // scalastyle:ignore package.object.name
type Bits = chisel3.core.Bits
/** This contains literal constructor factory methods that are deprecated as of Chisel3.
- * These will be removed very soon. It's recommended you move your code soon.
+ * These will be removed very soon. It's recommended you port your code ASAP.
*
* Some recommended regex replacements:
* (note: these are not guaranteed to handle all edge cases! check all replacements!)
@@ -48,32 +48,30 @@ package object chisel3 { // scalastyle:ignore package.object.name
trait UIntFactory extends chisel3.core.UIntFactory {
/** Create a UInt literal with inferred width. */
@deprecated("use n.U", "chisel3, will be removed by end of 2016")
- def apply(n: String): UInt = Lit(chisel3.core.fromStringToLiteral.parse(n),
- chisel3.core.fromStringToLiteral.parsedWidth(n))
+ def apply(n: String): UInt = n.asUInt
/** Create a UInt literal with fixed width. */
@deprecated("use n.U(width.W)", "chisel3, will be removed by end of 2016")
- def apply(n: String, width: Int): UInt = Lit(chisel3.core.fromStringToLiteral.parse(n),
- Width(width))
+ def apply(n: String, width: Int): UInt = n.asUInt(width.W)
/** Create a UInt literal with specified width. */
@deprecated("use value.U(width)", "chisel3, will be removed by end of 2016")
- def apply(value: BigInt, width: Width): UInt = Lit(value, width)
+ def apply(value: BigInt, width: Width): UInt = value.asUInt(width)
/** Create a UInt literal with fixed width. */
@deprecated("use value.U(width.W)", "chisel3, will be removed by end of 2016")
- def apply(value: BigInt, width: Int): UInt = Lit(value, Width(width))
+ def apply(value: BigInt, width: Int): UInt = value.asUInt(width.W)
/** Create a UInt with a specified width - compatibility with Chisel2. */
@deprecated("use UInt(width.W)", "chisel3, will be removed by end of 2016")
- def apply(dir: Option[Direction] = None, width: Int): UInt = apply(Width(width))
+ def apply(dir: Option[Direction] = None, width: Int): UInt = apply(width.W)
/** Create a UInt literal with inferred width.- compatibility with Chisel2. */
@deprecated("use value.U", "chisel3, will be removed by end of 2016")
- def apply(value: BigInt): UInt = apply(value, Width())
+ def apply(value: BigInt): UInt = value.asUInt
/** Create a UInt with a specified width */
@deprecated("use UInt(width.W)", "chisel3, will be removed by end of 2016")
- def width(width: Int): UInt = apply(Width(width))
+ def width(width: Int): UInt = apply(width.W)
/** Create a UInt port with specified width. */
@deprecated("use UInt(width)", "chisel3, will be removed by end of 2016")
@@ -86,27 +84,27 @@ package object chisel3 { // scalastyle:ignore package.object.name
trait SIntFactory extends chisel3.core.SIntFactory {
/** Create a SInt type or port with fixed width. */
@deprecated("use SInt(width.W)", "chisel3, will be removed by end of 2016")
- def width(width: Int): SInt = apply(Width(width))
+ def width(width: Int): SInt = apply(width.W)
/** Create an SInt type with specified width. */
@deprecated("use SInt(width)", "chisel3, will be removed by end of 2016")
def width(width: Width): SInt = apply(width)
/** Create an SInt literal with inferred width. */
@deprecated("use value.S", "chisel3, will be removed by end of 2016")
- def apply(value: BigInt): SInt = Lit(value)
+ def apply(value: BigInt): SInt = value.asSInt
/** Create an SInt literal with fixed width. */
@deprecated("use value.S(width.W)", "chisel3, will be removed by end of 2016")
- def apply(value: BigInt, width: Int): SInt = Lit(value, width)
+ def apply(value: BigInt, width: Int): SInt = value.asSInt(width.W)
/** Create an SInt literal with specified width. */
@deprecated("use value.S(width)", "chisel3, will be removed by end of 2016")
- def apply(value: BigInt, width: Width): SInt = Lit(value, width)
+ def apply(value: BigInt, width: Width): SInt = value.asSInt(width)
@deprecated("use value.S", "chisel3, will be removed by end of 2016")
- def Lit(value: BigInt): SInt = Lit(value, Width())
+ def Lit(value: BigInt): SInt = value.asSInt
@deprecated("use value.S(width)", "chisel3, will be removed by end of 2016")
- def Lit(value: BigInt, width: Int): SInt = Lit(value, Width(width))
+ def Lit(value: BigInt, width: Int): SInt = value.asSInt(width.W)
}
/** This contains literal constructor factory methods that are deprecated as of Chisel3.
@@ -116,7 +114,7 @@ package object chisel3 { // scalastyle:ignore package.object.name
/** Creates Bool literal.
*/
@deprecated("use x.B", "chisel3, will be removed by end of 2016")
- def apply(x: Boolean): Bool = Lit(x)
+ def apply(x: Boolean): Bool = x.B
}
object Bits extends UIntFactory