diff options
| author | azidar | 2016-01-31 13:51:20 -0800 |
|---|---|---|
| committer | azidar | 2016-02-09 18:57:06 -0800 |
| commit | 69c51cb9c4a8dca4041416e31b8cdce14bcb11b3 (patch) | |
| tree | e32fdc895299a9308c4c9d4d70591ecafa2900ce /src | |
| parent | 81d9f637121462dafac3bf6df8a539c206783361 (diff) | |
Updated SInt/UInt emission to match stanza. Still need to update to new syntax.
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/scala/firrtl/Utils.scala | 3 | ||||
| -rw-r--r-- | src/main/scala/firrtl/Visitor.scala | 26 |
2 files changed, 26 insertions, 3 deletions
diff --git a/src/main/scala/firrtl/Utils.scala b/src/main/scala/firrtl/Utils.scala index fc0debbe..50d7b50b 100644 --- a/src/main/scala/firrtl/Utils.scala +++ b/src/main/scala/firrtl/Utils.scala @@ -234,7 +234,8 @@ object Utils { implicit class BigIntUtils(bi: BigInt){ def serialize(implicit flags: FlagMap = FlagMap): String = - "\"h" + bi.toString(16) + "\"" + if (bi < BigInt(0)) "\"h" + bi.toString(16).substring(1) + "\"" + else "\"h" + bi.toString(16) + "\"" } implicit class ASTUtils(ast: AST) { diff --git a/src/main/scala/firrtl/Visitor.scala b/src/main/scala/firrtl/Visitor.scala index 56d3bbe7..3ccb16c6 100644 --- a/src/main/scala/firrtl/Visitor.scala +++ b/src/main/scala/firrtl/Visitor.scala @@ -38,6 +38,28 @@ class Visitor(val fullFilename: String) extends FIRRTLBaseVisitor[AST] case _ => throw new Exception("Invalid String for conversion to BigInt " + s) } } + private def string2SignedBigInt(s: String): BigInt = { + // private define legal patterns + val HexPattern = """\"*h([a-zA-Z0-9]+)\"*""".r + val DecPattern = """(\+|-)?([1-9]\d*)""".r + val ZeroPattern = "0".r + val NegPattern = "(89AaBbCcDdEeFf)".r + s match { + case ZeroPattern(_*) => BigInt(0) + case HexPattern(hexdigits) => + hexdigits(1) match { + case NegPattern(_) =>{ + BigInt("-" + hexdigits,16) + } + case _ => BigInt(hexdigits, 16) + } + case DecPattern(sign, num) => { + if (sign != null) BigInt(sign + num,10) + else BigInt(num,10) + } + case _ => throw new Exception("Invalid String for conversion to BigInt " + s) + } + } private def string2Int(s: String): Int = string2BigInt(s).toInt private def getInfo(ctx: ParserRuleContext): Info = FileInfo(filename, ctx.getStart().getLine(), ctx.getStart().getCharPositionInLine()) @@ -173,9 +195,9 @@ class Visitor(val fullFilename: String) extends FIRRTLBaseVisitor[AST] case "SInt" => { val (width, value) = if (ctx.getChildCount > 4) - (IntWidth(string2BigInt(ctx.IntLit(0).getText)), string2BigInt(ctx.IntLit(1).getText)) + (IntWidth(string2BigInt(ctx.IntLit(0).getText)), string2SignedBigInt(ctx.IntLit(1).getText)) else { - val bigint = string2BigInt(ctx.IntLit(0).getText) + val bigint = string2SignedBigInt(ctx.IntLit(0).getText) (IntWidth(BigInt(bigint.bitLength + 1)),bigint) } SIntValue(value, width) |
