Skip to content

Conversation

@Scheremo
Copy link
Contributor

This patch makes real literal conversion safer and clearer, and adds tests.

  • Direct lowering for AST real literals

    • RvalueExprVisitor::visit(RealLiteral) now emits a moore.real_constant via an MLIR FloatAttr (f64) directly, avoiding the older materializeSVReal path.
  • Safer constant folding for reals

    • Reworked Context::materializeSVReal(...):
      • Verifies the AST type is floating before proceeding.
      • Coerces slang::ConstantValue to the expected kind (real/shortreal) using Slang conversions.
      • Avoids calling .real() / .shortReal() unless the corresponding is*() predicate holds.
      • Emits moore.real_literal / moore.shortreal_literal with the correct MLIR float type (f64/f32).
  • RealLiteral module in basic.sv

    • Checks emission of moore.real_constant 5.000000e-01
    • Verifies implicit conversion to shortreal via a moore.conversion from !moore.f64!moore.f32
    • Confirms variable initializations for both real and shortreal.

@Scheremo Scheremo marked this pull request as ready for review October 19, 2025 16:22
Copy link
Contributor

@fabianschuiki fabianschuiki left a comment

Choose a reason for hiding this comment

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

LGTM

This patch makes real literal conversion safer and clearer, and adds tests.

- **Direct lowering for AST real literals**
  - `RvalueExprVisitor::visit(RealLiteral)` now emits a `moore.real_constant` via an MLIR `FloatAttr` (f64) directly, avoiding the older `materializeSVReal` path.

- **Safer constant folding for reals**
  - Reworked `Context::materializeSVReal(...)`:
    - Verifies the AST type is floating before proceeding.
    - **Coerces** `slang::ConstantValue` to the expected kind (`real`/`shortreal`) using Slang conversions.
    - Avoids calling `.real()` / `.shortReal()` unless the corresponding `is*()` predicate holds.
    - Emits `moore.real_literal` / `moore.shortreal_literal` with the correct MLIR float type (`f64`/`f32`).

- **`RealLiteral` module** in `basic.sv`
  - Checks emission of `moore.real_constant 5.000000e-01`
  - Verifies implicit conversion to `shortreal` via a `moore.conversion` from `!moore.f64` → `!moore.f32`
  - Confirms variable initializations for both `real` and `shortreal`.
@Scheremo Scheremo merged commit 8b5e782 into llvm:main Oct 20, 2025
6 checks passed
@Scheremo Scheremo deleted the pr-fix-svreal branch October 21, 2025 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants