Summary
Implement code generation in Gradient. Convert IR to machine code (via Rust kernel).
Background
With IR generation (Phase 6), we can now generate machine code. This phase orchestrates the Rust kernel's code generators.
Target State
Full code generation with:
- IR to native (via Cranelift in Rust kernel)
- IR to WASM (via WASM backend in Rust kernel)
- Linking and output
Implementation Requirements
Architecture
Gradient code generation orchestrates Rust kernel:
fn generate_native(ir: IrModule, options: CompileOptions) -> !{FS} CompiledOutput:
// Call into Rust kernel to use Cranelift
ret call_rust_codegen(ir, "native")
fn generate_wasm(ir: IrModule, options: CompileOptions) -> !{FS} CompiledOutput:
// Call into Rust kernel to use WASM backend
ret call_rust_codegen(ir, "wasm")
Functions
-
generate(ir: IrModule, target: Target) -> CompiledOutput
- Select code generator
- Call Rust kernel
- Return result
-
link(objects: ObjectList, output: String) -> !{FS} ()
- Link object files
- Use system linker via Rust kernel
-
emit_module(ir: IrModule, options: CompileOptions) -> !{FS} ()
- Full pipeline: generate + link
- Handle multiple targets
Targets
- Native (x86_64, ARM64 via Cranelift)
- WASM (wasm32 via WASM backend)
- Future: LLVM, other architectures
Acceptance Criteria
Part Of
- Epic: Full Self-Hosting with Rust Kernel
- Phase: 7 of 7 (FINAL)
Effort
~5 days, ~1,000 lines of Gradient
Dependencies
Completion Criteria
When this phase is complete:
- ✅ Compiler can compile itself
- ✅
gradient-compiler is 95%+ Gradient code
- ✅ Rust kernel is minimal (~2,000 lines)
- ✅ Full self-hosting achieved
Summary
Implement code generation in Gradient. Convert IR to machine code (via Rust kernel).
Background
With IR generation (Phase 6), we can now generate machine code. This phase orchestrates the Rust kernel's code generators.
Target State
Full code generation with:
Implementation Requirements
Architecture
Gradient code generation orchestrates Rust kernel:
Functions
generate(ir: IrModule, target: Target) -> CompiledOutput
link(objects: ObjectList, output: String) -> !{FS} ()
emit_module(ir: IrModule, options: CompileOptions) -> !{FS} ()
Targets
Acceptance Criteria
Part Of
Effort
~5 days, ~1,000 lines of Gradient
Dependencies
Completion Criteria
When this phase is complete:
gradient-compileris 95%+ Gradient code