Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Scheremo
Copy link
Contributor

This commit introduces explicit conversion operations between real and integer types in the Moore dialect, following IEEE 1800-2023 §6.24.1 Cast operator and §6.12 Real, shortreal and realtime data types. It also extends VerilogImport to recognize and materialize these conversions during AST translation.

  • Dialect (MooreOps.td)

    • Added RealToIntOp for rounding real/shortreal values to two-valued integers.
    • Added IntToRealOp for widening integer values to real/shortreal.
    • Both ops marked Pure with explicit assembly formats.
  • Import logic (Expressions.cpp)

    • Added conversion handling in Context::materializeConversion:
      • RealType -> IntType -> RealToIntOp
      • IntType -> RealType -> IntToRealOp
  • Tests

    • SystemVerilog import
      • Added basic.sv tests verifying correct lowering of real'(expr) and int'(expr) casts for all real/int width combinations (f32/i32, f64/i64).
      • Updated builtins.sv to expect moore.int_to_real instead of a generic conversion op.
    • Dialect MLIR
      • Added basic.mlir tests ensuring proper parsing/printing and type mapping for 32- and 64-bit conversions.

@Scheremo Scheremo force-pushed the pr-real-to-int branch 5 times, most recently from 1021e73 to 543f25b Compare October 13, 2025 18:41
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.

Really cool, thanks for adding these! LGTM 🥳

This commit introduces explicit conversion operations between real and integer types in the Moore dialect, following IEEE 1800-2023 §6.24.1 *Cast operator* and §6.12 *Real, shortreal and realtime data types*.
It also extends VerilogImport to recognize and materialize these conversions during AST translation.

- **Dialect (`MooreOps.td`)**
  - Added `RealToIntOp` for rounding real/shortreal values to two-valued integers.
  - Added `IntToRealOp` for widening integer values to real/shortreal.
  - Both ops marked `Pure` with explicit assembly formats.

- **Import logic (`Expressions.cpp`)**
  - Added conversion handling in `Context::materializeConversion`:
    - `RealType` -> `IntType` -> `RealToIntOp`
    - `IntType` -> `RealType` -> `IntToRealOp`

- **Tests**
  - **SystemVerilog import**
    - Added `basic.sv` tests verifying correct lowering of `real'(expr)` and `int'(expr)` casts for all real/int width combinations (`f32/i32`, `f64/i64`).
    - Updated `builtins.sv` to expect `moore.int_to_real` instead of a generic `conversion` op.
  - **Dialect MLIR**
    - Added `basic.mlir` tests ensuring proper parsing/printing and type mapping for 32- and 64-bit conversions.
@Scheremo Scheremo marked this pull request as ready for review October 13, 2025 19:08
@Scheremo Scheremo merged commit a1e2484 into llvm:main Oct 13, 2025
7 checks passed
@Scheremo Scheremo deleted the pr-real-to-int branch October 21, 2025 07:49
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.

2 participants