Skip to content

Major Infrastructure Upgrade: LLVM 21, Opaque Pointers, and GUI Tooling#291

Merged
LunaStev merged 11 commits intowavefnd:masterfrom
LunaStev:feat/upgrade-to-LLVM-21-implement-opaque-pointer-support-and-add-GUI-build-tool
Feb 15, 2026
Merged

Major Infrastructure Upgrade: LLVM 21, Opaque Pointers, and GUI Tooling#291
LunaStev merged 11 commits intowavefnd:masterfrom
LunaStev:feat/upgrade-to-LLVM-21-implement-opaque-pointer-support-and-add-GUI-build-tool

Conversation

@LunaStev
Copy link
Member

This PR represents a major leap in the Wave compiler's infrastructure. It upgrades the core backend to LLVM 21 and completes the migration to Opaque Pointers, which is now the standard in modern LLVM. Additionally, the lexer has been fully modularized, and a new graphical build manager has been added to the toolchain to improve the developer experience.


Key Changes

1. LLVM 21 & Opaque Pointer Migration

  • Inkwell Upgrade: Upgraded inkwell to 0.8.0 and llvm-sys to 211.0.0 to support LLVM 21.
  • Opaque Pointer Implementation:
    • Since LLVM pointers no longer carry pointee information (e.g., i32* is now just ptr), the backend has been refactored to explicitly track and provide types for all memory operations.
    • Updated build_load, build_store, and build_gep calls project-wide to include explicit LLVM types.
    • Refactored address.rs and lvalue.rs to ensure Wave-level type information is correctly mapped to these new opaque pointer instructions.
  • Modern Optimization Pipeline: Switched from the legacy PassManagerBuilder to the modern LLVM PassBuilder, enabling more efficient optimization passes (up to O3) and better alignment with current LLVM standards.

2. Lexer Modularization

The lexer has been decomposed into specialized submodules for better maintainability:

  • core / cursor: Foundational types and source navigation.
  • scan / ident: Token dispatch and keyword mapping.
  • literals / trivia: Detailed parsing for strings/chars and whitespace/comment handling.

3. GUI Build Manager & Tooling

  • Tkinter GUI: Added a graphical interface to the x.py script. Developers can now manage build targets, installations, and configurations through a visual window.
  • Cross-Compilation: Improved the x.py logic to support cross-compiling for x86_64-pc-windows-gnu from Linux hosts using MinGW LLVM prefixes.
  • Target Management: Fixed various pathing issues in the backend related to the target/ directory structure.

4. Bug Fixes & ABI Compliance

  • Varargs Promotion: Fixed a bug where small integers and floats were not correctly promoted when passed to C varargs functions like printf. Small integers are now promoted to i32 and floats to double, ensuring C ABI compliance.
  • I/O Ambiguity: Adjusted printf and scanf logic to manually track C-string status, as the opaque ptr type no longer distinguishes between string buffers and other memory pointers.

Example Impact

LLVM IR Change (Opaque Pointers):

; Old (Typed Pointers)
%val = load i32, i32* %ptr

; New (Opaque Pointers in LLVM 21)
%val = load i32, ptr %ptr

Benefits

  • Future-Proofing: Aligning with LLVM 21 ensures compatibility with the latest hardware optimizations and security features.
  • Maintainability: The modular lexer and explicit type tracking in codegen reduce the risk of subtle memory-related bugs in the compiler.
  • Accessibility: The GUI build manager makes it significantly easier for new developers to set up and build the Wave toolchain.

…UI build tool

This commit performs a major infrastructure upgrade to the LLVM backend,
transitioning to LLVM 21 (via Inkwell 0.8.0). The primary focus is the
implementation of "Opaque Pointer" safety, requiring explicit type
tracking throughout the codegen. It also introduces a graphical build
manager for the toolchain.

Changes:
- **LLVM Backend Upgrade**:
  - Upgraded Inkwell to 0.8.0 and LLVM-sys to 211.0.0.
  - Migrated from typed pointers to **Opaque Pointers**.
  - Updated all `build_load`, `build_store`, and `build_gep` calls to
    provide explicit LLVM types, as pointers no longer carry pointee
    information.
  - Refactored `address.rs` and `lvalue.rs` to infer Wave-level types
    during IR generation to ensure correct instruction emission.
- **Optimization & Codegen**:
  - Replaced the legacy `PassManagerBuilder` with the new LLVM **PassBuilder**,
    supporting modern optimization pipelines (e.g., `default<O3>`).
  - Improved aggregate handling in function calls with better size-based
    packing/unpacking and bitcasting.
  - Adjusted IO logic (`printf`/`scanf`) to manually track C-string
    status since LLVM `ptr` is now ambiguous.
- **Lexer Refactoring**:
  - Modularized the lexer by splitting logic into `core`, `cursor`,
    `trivia`, `literals`, `ident`, and `scan` modules.
  - Cleaned up internal imports and visibility.
- **Build System & Tooling**:
  - Added a Tkinter-based **GUI Build Manager** to `x.py` for managing
    targets and installations visually.
  - Improved cross-compilation support in `x.py` for `x86_64-pc-windows-gnu`
    targets from Linux hosts using MinGW LLVM prefixes.
  - Fixed target directory pathing in the backend.
- **Bug Fixes**:
  - Fixed type promotion for C varargs in `printf` (e.g., promoting small
    integers to `i32` and floats to `double`).

This update modernizes the compiler backend and prepares the architecture
for future LLVM versions while providing a more user-friendly build
interface.

Signed-off-by: LunaStev <luna@lunastev.org>
@LunaStev LunaStev self-assigned this Feb 15, 2026
Signed-off-by: LunaStev <luna@lunastev.org>
Signed-off-by: LunaStev <luna@lunastev.org>
Signed-off-by: LunaStev <luna@lunastev.org>
Signed-off-by: LunaStev <luna@lunastev.org>
Signed-off-by: LunaStev <luna@lunastev.org>
Signed-off-by: LunaStev <luna@lunastev.org>
Signed-off-by: LunaStev <luna@lunastev.org>
Signed-off-by: LunaStev <luna@lunastev.org>
Signed-off-by: LunaStev <luna@lunastev.org>
Signed-off-by: LunaStev <luna@lunastev.org>
@LunaStev LunaStev merged commit bf79572 into wavefnd:master Feb 15, 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

Comments