Skip to content

fix(compiler): const_propagate LHS guard, reassigned var check, &&/|| lexer#365

Merged
gHashTag merged 1 commit intomasterfrom
fix/fpga-optimizer-and-lexer
Apr 8, 2026
Merged

fix(compiler): const_propagate LHS guard, reassigned var check, &&/|| lexer#365
gHashTag merged 1 commit intomasterfrom
fix/fpga-optimizer-and-lexer

Conversation

@gHashTag
Copy link
Copy Markdown
Owner

@gHashTag gHashTag commented Apr 8, 2026

Summary

Three critical compiler fixes for Verilog codegen correctness:

  1. const_propagate LHS guardreplace_ident_with_literal and propagate_ident now skip children[0] of StmtAssign nodes, preventing assignment targets from being replaced with literals (was producing 0 = (0 | ...))

  2. Reassigned variable checkconst_propagate now checks if a variable is reassigned before propagating its initial value. Previously const result = 0; result = result | ... would replace all result with 0

  3. && / || lexer tokens — Lexer now recognizes && and || as multi-char tokens. Parser maps them to logical and/or operators. Previously && was two & (bitwise AND) tokens

Impact

  • MAC spec: result = (result | pack_trit(...)) now correct (was 0 = (0 | ...))
  • Bridge spec: && expressions now produce && in Verilog (was & &)
  • All 5 FPGA specs pass Yosys Verilog frontend parsing
  • Remaining: array+field access (a[i]_field) and expression grouping need further work

Closes #359

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
@gHashTag gHashTag merged commit d6332e1 into master Apr 8, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(fpga): instantiate UART/SPI/TopLevel modules in synthesis, fix type-suffixed literals

1 participant