-
Notifications
You must be signed in to change notification settings - Fork 302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Moore] Add FVIntegerAttr #7461
Conversation
Add the `FVIntegerAttr`, an attribute containing an `FVInt` value. This allows four-valued integer constants to be used as attributes on operations and for constant folding to occur on such values. In contrast to the builtin `IntegerAttr`, `FVIntegerAttr` does not have a type yet. The type can be added later as soon as we have a concrete use case. I expect us to eventually move `FVIntegerAttr` into the HW dialect once we are happy with its design. Other parts of CIRCT will eventually want to reason about four-valued integers as well. The parsing and printing of the attribute tries to make the `FVInt` read like a plain old `APInt` when there are no X or Z bits present. Otherwise it falls back to printing as hexadecimal or binary number. To distinguish the different representations and to allow constants with X or Z to be parsed as keywords, a `h` and `b` prefix is used for the hexadecimal and binary formatting, respectively. Examples of the attribute: #moore.fvint<42 : 32> #moore.fvint<-42 : 32> #moore.fvint<1234567890123456789012345678901234567890 : 131> #moore.fvint<hABCDEFXZ0123456789 : 72> #moore.fvint<b1010XZ01 : 8>
e3e17a1
to
67009e2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the boilerplate to add the attribute looks good. The printer/parser is nice, looks good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Learned some new coding. LGTM 🎉!
Thanks for the reviews 😃 Going to land this. |
Add the
FVIntegerAttr
, an attribute containing anFVInt
value. This allows four-valued integer constants to be used as attributes on operations and for constant folding to occur on such values. In contrast to the builtinIntegerAttr
,FVIntegerAttr
does not have a type yet. The type can be added later as soon as we have a concrete use case.I expect us to eventually move
FVIntegerAttr
into the HW dialect once we are happy with its design. Other parts of CIRCT will eventually want to reason about four-valued integers as well.The parsing and printing of the attribute tries to make the
FVInt
read like a plain oldAPInt
when there are no X or Z bits present. Otherwise it falls back to printing as hexadecimal or binary number. To distinguish the different representations and to allow constants with X or Z to be parsed as keywords, ah
andb
prefix is used for the hexadecimal and binary formatting, respectively.Examples of the attribute: