fix(compiler): const_propagate LHS guard, reassigned var check, &&/|| lexer#365
Merged
fix(compiler): const_propagate LHS guard, reassigned var check, &&/|| lexer#365
Conversation
Three fixes: 1. const_propagate: skip LHS of StmtAssign (was replacing assignment targets with literal 0, producing '0 = ...' in Verilog) 2. const_propagate: don't propagate vars that are reassigned later (was replacing 'result' with '0' in RHS even after mutation) 3. Lexer: recognize && and || as multi-char tokens, parse as logical and/or operators instead of bitwise &/| MAC and Bridge specs now parse in Yosys frontend (remaining issues: array+field access 'a[i]_field' and expression grouping precedence). Closes #359
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three critical compiler fixes for Verilog codegen correctness:
const_propagate LHS guard —
replace_ident_with_literalandpropagate_identnow skipchildren[0]ofStmtAssignnodes, preventing assignment targets from being replaced with literals (was producing0 = (0 | ...))Reassigned variable check —
const_propagatenow checks if a variable is reassigned before propagating its initial value. Previouslyconst result = 0; result = result | ...would replace allresultwith0&& / || lexer tokens — Lexer now recognizes
&&and||as multi-char tokens. Parser maps them to logical and/or operators. Previously&&was two&(bitwise AND) tokensImpact
result = (result | pack_trit(...))now correct (was0 = (0 | ...))&&expressions now produce&&in Verilog (was& &)a[i]_field) and expression grouping need further workCloses #359