diff options
| author | Jack Koenig | 2017-02-28 10:24:29 -0800 |
|---|---|---|
| committer | Jack Koenig | 2017-03-01 18:01:28 -0600 |
| commit | 7f280a5b0821c61284e9bf9ed7780cc825f7f3e8 (patch) | |
| tree | 700d511e93c4058c627bb28ecc507d0c49eb6758 /src/main/scala | |
| parent | 51f8f4a5e868a8e655091e3e61445d3cd772d2ba (diff) | |
Allow nested digit fields in subfield expressions
Workaround for #470. This allows parsing DoubleLits in subfield
expressions.
Diffstat (limited to 'src/main/scala')
| -rw-r--r-- | src/main/scala/firrtl/Visitor.scala | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/main/scala/firrtl/Visitor.scala b/src/main/scala/firrtl/Visitor.scala index 2db46271..73555a37 100644 --- a/src/main/scala/firrtl/Visitor.scala +++ b/src/main/scala/firrtl/Visitor.scala @@ -17,6 +17,12 @@ class Visitor(infoMode: InfoMode) extends FIRRTLBaseVisitor[FirrtlNode] { // Strip file path private def stripPath(filename: String) = filename.drop(filename.lastIndexOf("/") + 1) + // Check if identifier is made of legal characters + private def legalId(id: String) = { + val legalChars = ('A' to 'Z').toSet ++ ('a' to 'z').toSet ++ ('0' to '9').toSet ++ Set('_', '$') + id forall legalChars + } + def visit[FirrtlNode](ctx: FIRRTLParser.CircuitContext): Circuit = visitCircuit(ctx) // These regex have to change if grammar changes @@ -315,7 +321,19 @@ class Visitor(infoMode: InfoMode) extends FIRRTLBaseVisitor[FirrtlNode] { case "mux(" => Mux(visitExp(ctx.exp(0)), visitExp(ctx.exp(1)), visitExp(ctx.exp(2)), UnknownType) case _ => ctx.getChild(1).getText match { - case "." => new SubField(visitExp(ctx.exp(0)), ctx.fieldId.getText, UnknownType) + case "." => + val expr1 = visitExp(ctx.exp(0)) + // TODO Workaround for #470 + if (ctx.fieldId == null) { + ctx.DoubleLit.getText.split('.') match { + case Array(a, b) if legalId(a) && legalId(b) => + val inner = new SubField(expr1, a, UnknownType) + new SubField(inner, b, UnknownType) + case Array() => throw new ParserException(s"Illegal Expression at ${ctx.getText}") + } + } else { + new SubField(expr1, ctx.fieldId.getText, UnknownType) + } case "[" => if (ctx.exp(1) == null) new SubIndex(visitExp(ctx.exp(0)), string2Int(ctx.intLit(0).getText), UnknownType) else new SubAccess(visitExp(ctx.exp(0)), visitExp(ctx.exp(1)), UnknownType) |
