Skip to content
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

[ImportVerilog] Add assign and pre/post increment/decrement expressions #6859

Merged
merged 1 commit into from Mar 22, 2024

Conversation

fabianschuiki
Copy link
Contributor

Add support for pre and post increment and decrement expressions, like x++ and --x, as well as assign expressions, like a += 5. Slang represents these assignments as Assign(a, Add(LValueRef, 5)) in the AST. The LValueRef node contextually refers to the parent assignment's left-hand side. To deal with this, also add a corresponding lvalue stack to the conversion context. Assignments push and pop their lvalues onto and off of this stack.

These expressions require a mechanism in the IR to express when a variable is read. To capture this, add a new moore.read_lvalue op. It currently looks like an identity operation with a MemRead side effect. Further down the road, we may want to introduce a proper reference type for variables, ports, nets, and other things, and have read_lvalue and the various assigns operate on that type instead. This sets the foundation for that.

@fabianschuiki fabianschuiki added the Verilog/SystemVerilog Involving a Verilog dialect label Mar 20, 2024
Copy link
Member

@hailongSun2000 hailongSun2000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Member

@maerhart maerhart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just some minor comments.

include/circt/Dialect/Moore/MooreOps.td Outdated Show resolved Hide resolved
include/circt/Dialect/Moore/MooreOps.td Outdated Show resolved Hide resolved
include/circt/Dialect/Moore/MooreOps.td Outdated Show resolved Hide resolved
@@ -53,6 +53,13 @@ struct ExprVisitor {
return {};
}

// Handle references to the left-hand side of a parent assignment.
Value visit(const slang::ast::LValueReferenceExpression &expr) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do continuous assignments use a different system for lvalues or can they not be nested?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They don't allow for the += syntax. += is always a blocking assignment within a procedural block.

lib/Conversion/ImportVerilog/Expressions.cpp Show resolved Hide resolved
Add support for pre and post increment and decrement expressions, like
`x++` and `--x`, as well as assign expressions, like `a += 5`. Slang
represents these assignments as `Assign(a, Add(LValueRef, 5))` in the
AST. The `LValueRef` node contextually refers to the parent assignment's
left-hand side. To deal with this, also add a corresponding lvalue stack
to the conversion context. Assignments push and pop their lvalues onto
and off of this stack.

These expressions require a mechanism in the IR to express _when_ a
variable is read. To capture this, add a new `moore.read_lvalue` op.
It currently looks like an identity operation with a `MemRead` side
effect. Further down the road, we may want to introduce a proper
reference type for variables, ports, nets, and other things, and have
`read_lvalue` and the various assigns operate on that type instead. This
sets the foundation for that.

Co-authored-by: Hailong Sun <hailong.sun@terapines.com>
Co-authored-by: ShiZuoye <albertethon@163.com>
Co-authored-by: hunterzju <hunter_ht@zju.edu.cn>
Co-authored-by: Anqi Yu <anqi.yu@terapines.com>
@fabianschuiki fabianschuiki merged commit 8ec0523 into main Mar 22, 2024
4 checks passed
@fabianschuiki fabianschuiki deleted the fschuiki/slang-assign-exprs branch March 22, 2024 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Verilog/SystemVerilog Involving a Verilog dialect
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants