Skip to content

fix: code review - latch detection, naming, I2C decoding, signal matching - #5

Merged
egg-rolls merged 2 commits into
mainfrom
fix/code-review-issues
Jun 16, 2026
Merged

egg-rolls merged 2 commits into
mainfrom
fix/code-review-issues

Conversation

@egg-rolls

Copy link
Copy Markdown
Owner

Summary

This PR fixes several issues found during code review of the SuperRTL codebase.

1. Fix case statement depth counting in latch detection

  • File: src/superrtl/tools/review.py
  • Issue: The _check_latch_inference function initialized depth = 0 when detecting a case statement, but the first case keyword was then matched by "case" in case_line inside the loop, incrementing depth to 1 immediately. This meant the loop would look for one extra endcase that didn't exist, potentially running past the actual end of the case block.
  • Fix: Changed depth = 0 to depth = 1 and added j != i guard to skip double-counting the first case.

2. Improve camelCase naming detection

  • File: src/superrtl/tools/review.py
  • Issue: The _check_naming function excluded all signals starting with clk or rst from camelCase warnings, including longer names like clkDivider or rstGenerator that should use snake_case.
  • Fix: Added length check to only allow short common prefixes (6 chars or less) like clkDiv, rstN.

3. Fix I2C 10-bit address decoding

  • File: src/superrtl/tools/protocol_decode.py
  • Issue: The address_bits config parameter was read from config but never used in the actual decoding logic. All addresses were decoded as 7-bit regardless of the setting.
  • Fix: Implemented proper 10-bit I2C address parsing per the I2C specification (first byte = 11110xx0, second byte = full address bits).

4. Improve signal name matching precision

  • File: src/superrtl/tools/protocol_decode.py
  • Issue: The _get_signal_values function used simple substring matching (in), which could incorrectly match signals like tx_data when looking for tx, or spi_miso when looking for sck (because sck appears in spi_sck).
  • Fix: Implemented prioritized matching: exact match > prefix match (with delimiter boundary check for _, ., [) > substring fallback.

5. Enable I2C ACK detection

  • File: src/superrtl/tools/protocol_decode.py
  • Issue: I2C ACK detection code was present but commented out with pass.
  • Fix: Enabled the ACK detection logic to read SDA state during the 9th clock cycle.

Testing

  • All 154 tests pass (8 skipped due to missing EDA tools)
  • No new test failures introduced

- Fix _check_latch_inference depth counter initialization (start at 1 instead of 0)
- Improve _check_naming camelCase detection (allow short clk/rst prefixes)
- Fix I2C protocol decoder to use address_bits config for 10-bit addresses
- Improve signal name matching in _get_signal_values (exact > prefix > contains)
- Enable ACK detection in I2C decoder

These fixes address potential bugs found during code review:
1. Case statement depth counting was off by one
2. CamelCase naming check was too permissive for clk/rst prefixes
3. I2C 10-bit address decoding was not implemented
4. Signal matching could incorrectly match substrings
@egg-rolls
egg-rolls merged commit 3086b8d into main Jun 16, 2026
13 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.

1 participant