-
Notifications
You must be signed in to change notification settings - Fork 28
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
[minor] Add String Type, Format String Placeholder #45
base: main
Are you sure you want to change the base?
Conversation
Awesome! Few comments/observations: Should this type be mentioned in type equivalence section(s)? What happens if a String wire is invalidated? Can we have a register of type String, or a memory? (probably not?) Wires and other constructs of type String seem useful for plumbing strings to operations that consume them-- like an argument to printf or maybe used in an assert (which seems missing from the grammar?). What does it mean for a circuit if there's a wire of type String (assuming not optimized/constant-prop'd away)? Verifying printf format strings is important for security/bugs in the C/software world, maybe our example shouldn't encourage this pattern for same reasons? Should the syntax for a string literal also be specified? What characters are supported (regardless of encoding used)-- presumably at least printable ASCII is required to be supported? Maybe it's best to not grapple with too much of this (UTF-8 all the things) to accommodate as many use cases as possible. https://github.com/chipsalliance/firrtl-spec/blob/main/spec.md#unsigned-integers-from-literal-bits mentions using a string to specify a UInt, which we probably don't want to support (may require runtime handling of the string). More generally the spec+grammar and other operations mention "string" not just the parameter type this is introduced for. I guess this is same as earlier comment-- let's be clear about where "string" (which seems to mean quoted sequence of characters, aka a simple conventional string literal) is allowed and where "String" (this new ground type) is allowed. |
If you can have a wire of type string, does that mean that you could have conditional assignments to these String type wires? How would that translate to verilog if the format string is different depending on a |
I'm intending to roll back the scope of this to narrowly define the Thanks for the great comments. (I got a little out over my skis here.) Answering questions:
If it is defined for connections, then yes.
This is a great question. Given existing FIRRTL semantics, this is likely an indeterminate value, i.e., the compiler can choose any value. 😬 This sounds idiotic, so it's likely that we don't do this. A prerequisite to disallowing this is to change
Megan was asking about this, too. I originally thought no. An analog type fits into this category (and intended usage) of allowable in a wire because it's only passed around, but never put into a register. However, I think this just requires some more thinking. I can see a weird utility in being able to register a string. That would, however, require defining both an encoding an a length for a The real question here is does a Since I don't have a broad use case, I should keep this narrow to just sufficient for parameters.
We need some mechanism to pass these things around. I pulled the printf case out of thin air. This really matters for parameters. The simpler case is to allow It is not initially necessary to allow for
This follows from #46. @darthscsi has brought up the distinction between types which are hardware (he called them "synth") vs. those which are metaprogramming. The intent of this proposal is that strings are only used for the latter. However, I can see the eventual need to wrestle with this.
Again: I'm out over my skis. The point is totally valid and I agree that we don't want to be doing this right now. I don think it's totally reasonable to add the
Yeah, we should clarify places where it can take a
Yes, we should define what a string literal is. Supported characters seems tough. I think it's fine to leave this as the existing language I added around "the encoding of a string is implementation defined". It is perhaps better to say, "An implementation must accepts ASCII-encoded strings. An implementation may accept any other string encoding." I'm not totally sure how to handle this in a good way.
Yes. This should only be a
I'll rollback this PR to not include this. However, it's reasonable to think through some consequences of this. (It's interesting!) Because this is implicitly now a hardware string, then it would be equivalent to a vector of some size that is a function of the length and encoding. It would then inherit the same properties of any other wire. Actually using this as the printf string would be bad (for reasons that @dtzSiFive brought up around you don't know how many arguments it takes). This motivates clearly separating what is a
Allowing this to be used as the actual printf string could lead to runtime errors (or invalid prints) and should be avoided. (And reiterating that I don't want to push on this right now!) |
85a228b
to
26db283
Compare
Add a string type to the FIRRTL spec. This is intended to clarify the type of an external module's string parameter as well as the type of the argument to certain operations that expect a literal string. (Previously, this was effectively unspecified.) Signed-off-by: Schuyler Eldridge <[email protected]>
26db283
to
62f5f11
Compare
This is now relaxed to only add a Thanks again for all the feedback. |
How do you plan to ensure that all expressions involving metaprogramming types can be resolved at compile time? Are you planning to introduce something along the lines of |
@@ -2867,7 +2901,8 @@ width = "<" , int , ">" ; | |||
binarypoint = "<<" , int , ">>" ; | |||
type_ground = "Clock" | "Reset" | "AsyncReset" | |||
| ( "UInt" | "SInt" | "Analog" ) , [ width ] | |||
| "Fixed" , [ width ] , [ binarypoint ] ; | |||
| "Fixed" , [ width ] , [ binarypoint ] | |||
| "String" ; |
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.
can we remove this from type_ground
so that we aren't confusing whether a Reg
can hold a String
and whatnot? it seems like we don't need it except for parameter
and printf
in this PR?
Add a string type to the FIRRTL spec. This is intended to clarify the
type of an external module's string parameter as well as the type of the
argument to certain operations that expect a literal
string. (Previously, this was effectively unspecified.)
Signed-off-by: Schuyler Eldridge [email protected]