diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-03-30 20:59:57 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-03-30 20:59:57 +0100 |
| commit | 61dc72b00e586f5ff408c3f4caf257a577ef58f3 (patch) | |
| tree | 2573b9093a3177ab66cd12bc99a937c24822537d | |
| parent | edb25f1cf8333743894877c8d9787cbeeb394321 (diff) | |
Reuse function context
| -rw-r--r-- | patio-to-cranelift/src/main.rs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/patio-to-cranelift/src/main.rs b/patio-to-cranelift/src/main.rs index 4778ce09..6fb81b61 100644 --- a/patio-to-cranelift/src/main.rs +++ b/patio-to-cranelift/src/main.rs @@ -115,9 +115,8 @@ fn compile_function_definition( &signature, ).unwrap(); - // TODO: reuse context - let mut func_context = cranelift_codegen::Context::for_function(func); - context.module.define_function(func_id, &mut func_context).unwrap(); + context.enter_function(func); + context.module.define_function(func_id, &mut context.cranelift_context).unwrap(); } fn cranelift_signature<'a>( @@ -192,6 +191,7 @@ fn patio_type_to_cranelift_type( } struct CompilerContext { + cranelift_context: cranelift_codegen::Context, module: ObjectModule, next_func_name_index: u32, target_triple: target_lexicon::Triple, @@ -200,6 +200,7 @@ struct CompilerContext { impl CompilerContext { fn new(module: ObjectModule, target_triple: target_lexicon::Triple) -> Self { CompilerContext { + cranelift_context: cranelift_codegen::Context::new(), module, next_func_name_index: 0, target_triple, @@ -214,6 +215,10 @@ impl CompilerContext { self.next_func_name_index += 1; name } + + fn enter_function(&mut self, cranelift_function: cranelift_codegen::ir::Function) { + self.cranelift_context.func = cranelift_function; + } } #[derive(Debug)] |
