diff options
| author | azidar | 2015-08-25 14:51:08 -0700 |
|---|---|---|
| committer | azidar | 2015-08-25 14:51:08 -0700 |
| commit | 9fd6d47c5ee82e4dac924e15b60f2a519d566b14 (patch) | |
| tree | 999ea3f223d228cef7f84ae7647ec95db7294e56 /src/main/stanza/ir-parser.stanza | |
| parent | eb1ab67b6cc3fd4a549da563bf643bd519d7562e (diff) | |
Removed IntWidth, now only use LongWidth. Now do width inference for Constants in parser, and correctly subtract 1 (except when 0) when calculating width from num-bits of BigInt
Diffstat (limited to 'src/main/stanza/ir-parser.stanza')
| -rw-r--r-- | src/main/stanza/ir-parser.stanza | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/main/stanza/ir-parser.stanza b/src/main/stanza/ir-parser.stanza index adffc62d..d3d9c379 100644 --- a/src/main/stanza/ir-parser.stanza +++ b/src/main/stanza/ir-parser.stanza @@ -5,6 +5,7 @@ defpackage firrtl/parser : import stz/parser import firrtl/lexer import bigint2 + import firrtl/ir-utils ;======= Convenience Functions ======== defn first-info? (form) -> FileInfo|False : @@ -227,7 +228,7 @@ defsyntax firrtl : accdir = (rdwr) : RDWR defrule width : - width = (?x:#int) : IntWidth(x) + width = (?x:#int) : LongWidth(x) width = (?) : UnknownWidth() ;Main Statement Productions @@ -285,8 +286,19 @@ defsyntax firrtl : (t:UIntType) : if (v as Int) < 0 : FPE(form, "UIntValue cannot be negative.") - UIntValue(BigIntLit(v as Int), width(t)) - (t:SIntType) : SIntValue(BigIntLit(v as Int), width(t)) + match(width(t)) : + (w:LongWidth) : + UIntValue(BigIntLit(v as Int,to-int(width(w))),w) + (w) : + val num-bits = req-num-bits(v as Int) + UIntValue(BigIntLit(v as Int,num-bits), LongWidth(max(1,num-bits - 1))) + (t:SIntType) : + match(width(t)) : + (w:LongWidth) : + SIntValue(BigIntLit(v as Int,to-int(width(w))),w) + (w) : + val num-bits = req-num-bits(v as Int) + SIntValue(BigIntLit(v as Int,num-bits), LongWidth(num-bits)) expterm = (?op:#sym(?es:#exp ... ?ints:#int ... ?rest ...)) : if not empty?(rest) : |
