Skip to content

Conversation

@LunaStev
Copy link
Member

Summary

This PR refactors the build pipeline by splitting the monolithic compilation process into distinct Compile-to-Object and Link-Object phases. This modular approach aligns with standard compiler toolchains (like GCC/Clang), enabling better build system integration and paving the way for multi-file project support.

Key Changes

1. Compilation Phase (compile_ir_to_object)

  • Renamed compile_ir_to_machine_code to compile_ir_to_object.
  • Object Generation: Now generates .o object files instead of final executables.
  • Improved I/O: Removed temporary IR file creation; LLVM IR is now streamed directly to Clang via stdin using the -x ir flag.
  • Compile-Only Mode: Added the -c flag to ensure only compilation occurs.
  • Output: Object files are saved to target/{stem}.o.

2. Linking Phase (link_objects)

  • Introduced a new link_objects function to handle the final binary generation.
  • Flexibility: Accepts multiple object files as input.
  • Library Support: Added support for custom library paths (-L) and library names (-l).
  • Defaults: Links against libc and libm by default.

3. Pipeline Update (runner.rs)

  • Updated the main execution flow to reflect the split phases:
    1. Generate LLVM IR from Wave source.
    2. Compile IR to an object file (.o).
    3. Link the object file to produce the final executable.
    4. Execute the resulting binary.

Benefits

  • Incremental Compilation: Allows recompiling only changed modules in future multi-file projects.
  • External Linking: Supports linking with external static/dynamic libraries.
  • Performance: Reduced filesystem I/O overhead by eliminating intermediate .ll files.
  • Standardization: Matches the workflow of standard C/C++ build systems.

Example Workflow

graph LR
    A[Wave Source] -->|Frontend| B[LLVM IR]
    B -->|Compile| C[Object File]
    C -->|Link| D[Executable]
    E[Libraries] --> D
Loading

Split monolithic clang invocation into distinct compile-to-object and
link-object phases for better build system integration.

Changes:
- Rename compile_ir_to_machine_code to compile_ir_to_object:
  - Generate .o object files instead of executables
  - Add -c flag for compile-only mode
  - Use stdin pipe for IR input instead of temp file
  - Accept LLVM IR via -x ir flag
  - Output to target/{stem}.o
- Add link_objects function for separate linking:
  - Accept multiple object files as input
  - Support custom library paths (-L flags)
  - Support custom libraries (-l flags)
  - Link with libc and libm by default
  - Generate final executable
- Update runner.rs compilation pipeline:
  - Call compile_ir_to_object to generate .o file
  - Call link_objects with object file and empty lib lists
  - Generate executable in target/{stem}
  - Execute final linked binary
- Remove temporary IR file writing:
  - Stream IR directly to clang via stdin
  - Eliminate target/temp.ll intermediate file
  - Reduce filesystem I/O overhead

Benefits:
- Enables incremental compilation (recompile only changed modules)
- Supports linking with external static/dynamic libraries
- Matches standard compiler toolchain workflow (gcc/clang)
- Prepares for future multi-file project support
- Allows custom linker scripts and flags

Example workflow:
  1. Wave source -> LLVM IR
  2. LLVM IR -> object file (.o)
  3. Object file(s) + libs -> executable

This establishes a proper compilation pipeline compatible with C/C++
build systems and package managers.

Signed-off-by: LunaStev <luna@lunastev.org>
@LunaStev LunaStev self-assigned this Dec 19, 2025
@LunaStev LunaStev merged commit 6e3907b into wavefnd:master Dec 19, 2025
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