From e63a058b04d428cd407528b0276cc0413b581be2 Mon Sep 17 00:00:00 2001 From: Jack Date: Mon, 8 Feb 2016 23:33:07 -0800 Subject: Bug Fixes in handling hyphens as part of IDs, proper handling of negative IntLits (all IntLits handled by Parser and Visitor the same, checks come later), also delete first and last char of string literals since those characters are the quotes. --- src/main/antlr4/FIRRTL.g4 | 2 +- src/main/scala/firrtl/Visitor.scala | 19 ++++--------------- 2 files changed, 5 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/main/antlr4/FIRRTL.g4 b/src/main/antlr4/FIRRTL.g4 index e0e10d45..6e6b972f 100644 --- a/src/main/antlr4/FIRRTL.g4 +++ b/src/main/antlr4/FIRRTL.g4 @@ -208,7 +208,7 @@ Id fragment IdNondigit : Nondigit - | [~!@#$%^*-+=?/] + | [~!@#$%^*\-+=?/] ; Comment diff --git a/src/main/scala/firrtl/Visitor.scala b/src/main/scala/firrtl/Visitor.scala index cba4543c..f77a3f58 100644 --- a/src/main/scala/firrtl/Visitor.scala +++ b/src/main/scala/firrtl/Visitor.scala @@ -28,18 +28,6 @@ class Visitor(val fullFilename: String) extends FIRRTLBaseVisitor[AST] // These regex have to change if grammar changes private def string2BigInt(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 - s match { - case ZeroPattern(_*) => BigInt(0) - case HexPattern(hexdigits) => BigInt(hexdigits, 16) - case DecPattern(sign, num) => BigInt(num) - 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 @@ -164,7 +152,8 @@ class Visitor(val fullFilename: String) extends FIRRTLBaseVisitor[AST] Conditionally(info, visitExp(ctx.exp(0)), visitBlock(ctx.block(0)), alt) } case "stop(" => Stop(info, string2Int(ctx.IntLit(0).getText), visitExp(ctx.exp(0)), visitExp(ctx.exp(1))) - case "printf(" => Print(info, ctx.StringLit.getText, ctx.exp.drop(2).map(visitExp), + // Stip first and last character of string since they are the surrounding double quotes + case "printf(" => Print(info, ctx.StringLit.getText.tail.init, ctx.exp.drop(2).map(visitExp), visitExp(ctx.exp(0)), visitExp(ctx.exp(1))) case "skip" => Empty() // If we don't match on the first child, try the next one @@ -203,9 +192,9 @@ class Visitor(val fullFilename: String) extends FIRRTLBaseVisitor[AST] case "SInt" => { val (width, value) = if (ctx.getChildCount > 4) - (IntWidth(string2BigInt(ctx.IntLit(0).getText)), string2SignedBigInt(ctx.IntLit(1).getText)) + (IntWidth(string2BigInt(ctx.IntLit(0).getText)), string2BigInt(ctx.IntLit(1).getText)) else { - val bigint = string2SignedBigInt(ctx.IntLit(0).getText) + val bigint = string2BigInt(ctx.IntLit(0).getText) (IntWidth(BigInt(bigint.bitLength + 1)),bigint) } SIntValue(value, width) -- cgit v1.2.3