Skip to content

Conversation

@LunaStev
Copy link
Member

@LunaStev LunaStev commented Jan 3, 2026

This PR restructures the LLVM code generation backend by breaking down the monolithic llvm_codegen.rs file into a modular directory structure. This change aims to improve code maintainability, clarify the responsibilities of different codegen components, and simplify future extensions to the Wave compiler backend.

Key Changes

1. Modular Directory Structure

The single llvm_codegen.rs file has been replaced by the llvm_temporary/llvm_codegen/ module with the following sub-components:

  • mod.rs: The main entry point that re-exports public API functions.
  • ir.rs: Contains the core AST traversal logic and the primary generate_ir function.
  • address.rs: Specialized logic for memory address calculation (generate_address_ir).
  • types.rs: Manages type conversion logic (wave_type_to_llvm_type) and the VariableInfo structure.
  • consts.rs: Handles the creation of LLVM constant values (create_llvm_const_value).
  • format.rs: Bridging logic for Wave format strings to C-style printf/scanf formats.
  • legacy.rs: Preserves legacy functions for backward compatibility with TokenType.

2. Signature Updates & Refactoring

  • Context Propagation: Updated wave_format_to_c to accept an LLVM Context reference. This is necessary for accurate floating-point type checking during format string generation.
  • Internal Call Updates: Synchronized gen_print_format_ir within statement/io.rs to pass the required context to the updated formatting functions.
  • Logic Migration: Moved all logic from the original file into these specialized modules without changing the underlying behavior of the IR generation.

3. Cleanup

  • Deleted the original front/llvm_temporary/src/llvm_temporary/llvm_codegen.rs file.

Impact

  • No Behavioral Changes: The generated LLVM IR remains identical. This is a purely structural refactor.
  • Maintainability: Developers can now navigate specialized files rather than searching through a single massive file.
  • Scalability: New codegen features (like complex type mappings or optimization passes) now have clear locations for integration.

Split the monolithic `llvm_codegen.rs` into specialized submodules for better organization and maintainability.

Changes:
- **Module Structure**:
  - `llvm_temporary/llvm_codegen/` (New directory)
    - `mod.rs`: Re-exports public functions.
    - `ir.rs`: Core AST traversal and module/function setup (`generate_ir`).
    - `address.rs`: Memory address calculation (`generate_address_ir`).
    - `types.rs`: Type conversion (`wave_type_to_llvm_type`) and `VariableInfo`.
    - `consts.rs`: Constant creation (`create_llvm_const_value`).
    - `format.rs`: Format string parsing (`wave_format_to_c`, `wave_format_to_scanf`).
    - `legacy.rs`: Deprecated `TokenType`-based functions (kept for compatibility).
- **Refactoring**:
  - Moved relevant functions from `llvm_codegen.rs` to their respective new files.
  - Updated `wave_format_to_c` signature to accept `Context` reference (required for float type checking).
  - Updated `gen_print_format_ir` in `statement/io.rs` to pass `context` to `wave_format_to_c`.
- **Cleanup**: Removed the original single `llvm_codegen.rs` file.

This modularization clarifies the responsibilities of the codegen backend and simplifies future extensions.

Signed-off-by: LunaStev <luna@lunastev.org>
@LunaStev LunaStev merged commit 882e769 into wavefnd:master Jan 3, 2026
2 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