Skip to content

Commit

Permalink
[ExportVerilog] Make ExprEmitter sensitive to assignment-like context (
Browse files Browse the repository at this point in the history
…#6329)

Make the `ExprEmitter` track whether the current expressions is being
emitted into an assignment-like context. Fix the emission of struct and
array aggregates to only use `'{...}` assignment patterns when the
expression is in such an assignment-like context. These patterns cannot
be used otherwise.

For packed arrays and structs, pick `'{...}` assignment patterns or
`{...}` concatenation based on whether they are printed in an
assignment-like context or not.

For unpacked arrays (and later unpacked structs), properly emit an error
if they are being printed outside an assignment-like context. Unpacked
values cannot be created inline arbitrarily. Instead, the
`PrepareForEmission` pass has to spill them into a separate variable to
artificially construct an assignment-like context (the initializer of or
assignment to the spill declaration).

We currently seem to do the right thing for unpacked arrays already,
such that `PrepareForEmission` does not have to do any additional
spilling. Basically, by virtue of spilling arrays and structs to
declarations anyway such that they can be accessed into, we are already
working around the assignment-like context problem. However, as we build
out more support for unpacked data types, we need to update
`PrepareForEmission` to make it check if an expression requires an
assignment-like context, and if it does, spill the declaration for that
reason.

Fixes #6275.
  • Loading branch information
fabianschuiki authored Nov 6, 2023
1 parent e7820d0 commit a9c98bb
Show file tree
Hide file tree
Showing 3 changed files with 230 additions and 116 deletions.
Loading

0 comments on commit a9c98bb

Please sign in to comment.