about summary refs log tree commit diff
path: root/src/driver
diff options
context:
space:
mode:
authorbjorn3 <bjorn3@users.noreply.github.com>2021-02-23 21:00:33 +0100
committerGitHub <noreply@github.com>2021-02-23 21:00:33 +0100
commit86c594426f247ae34ef12f5e4dfd97f5ffe093c8 (patch)
treed5683974c4cf47d1debe8e3b5b247e4ece43779a /src/driver
parentc24744657021aa20bb577eb0e23cc8dcee55805c (diff)
parent73d3a1c14ad1703644667f8cb0df8e4d316aa4e1 (diff)
Merge pull request #1144 from bjorn3/dynamic_module
Use dynamic dispatch for the inner Module
Diffstat (limited to 'src/driver')
-rw-r--r--src/driver/aot.rs6
-rw-r--r--src/driver/jit.rs17
-rw-r--r--src/driver/mod.rs2
3 files changed, 12 insertions, 13 deletions
diff --git a/src/driver/aot.rs b/src/driver/aot.rs
index 1a26642a49b..07c6c27817c 100644
--- a/src/driver/aot.rs
+++ b/src/driver/aot.rs
@@ -119,12 +119,12 @@ fn module_codegen(
     let cgu = tcx.codegen_unit(cgu_name);
     let mono_items = cgu.items_in_deterministic_order(tcx);
 
-    let module = new_module(tcx, cgu_name.as_str().to_string());
+    let mut module = new_module(tcx, cgu_name.as_str().to_string());
 
     let mut cx = crate::CodegenCx::new(
         tcx,
         backend_config,
-        module,
+        &mut module,
         tcx.sess.opts.debuginfo != DebugInfo::None,
     );
     super::predefine_mono_items(&mut cx, &mono_items);
@@ -150,7 +150,7 @@ fn module_codegen(
             }
         }
     }
-    let (mut module, global_asm, debug, mut unwind_context) =
+    let (global_asm, debug, mut unwind_context) =
         tcx.sess.time("finalize CodegenCx", || cx.finalize());
     crate::main_shim::maybe_create_entry_wrapper(tcx, &mut module, &mut unwind_context);
 
diff --git a/src/driver/jit.rs b/src/driver/jit.rs
index bab4586e7f6..beb316c58c3 100644
--- a/src/driver/jit.rs
+++ b/src/driver/jit.rs
@@ -57,7 +57,7 @@ pub(super) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
         .into_iter()
         .collect::<Vec<(_, (_, _))>>();
 
-    let mut cx = crate::CodegenCx::new(tcx, backend_config, jit_module, false);
+    let mut cx = crate::CodegenCx::new(tcx, backend_config, &mut jit_module, false);
 
     super::time(tcx, "codegen mono items", || {
         super::predefine_mono_items(&mut cx, &mono_items);
@@ -85,7 +85,7 @@ pub(super) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
         }
     });
 
-    let (mut jit_module, global_asm, _debug, mut unwind_context) =
+    let (global_asm, _debug, mut unwind_context) =
         tcx.sess.time("finalize CodegenCx", || cx.finalize());
     jit_module.finalize_definitions();
 
@@ -145,21 +145,20 @@ extern "C" fn __clif_jit_fn(instance_ptr: *const Instance<'static>) -> *const u8
             let jit_module = jit_module.as_mut().unwrap();
             let backend_config =
                 BACKEND_CONFIG.with(|backend_config| backend_config.borrow().clone().unwrap());
-            let mut cx = crate::CodegenCx::new(tcx, backend_config, jit_module, false);
 
             let name = tcx.symbol_name(instance).name.to_string();
-            let sig = crate::abi::get_function_sig(tcx, cx.module.isa().triple(), instance);
-            let func_id = cx
-                .module
+            let sig = crate::abi::get_function_sig(tcx, jit_module.isa().triple(), instance);
+            let func_id = jit_module
                 .declare_function(&name, Linkage::Export, &sig)
                 .unwrap();
-            cx.module.prepare_for_function_redefine(func_id).unwrap();
+            jit_module.prepare_for_function_redefine(func_id).unwrap();
 
+            let mut cx = crate::CodegenCx::new(tcx, backend_config, jit_module, false);
             tcx.sess.time("codegen fn", || {
                 crate::base::codegen_fn(&mut cx, instance, Linkage::Export)
             });
 
-            let (jit_module, global_asm, _debug_context, unwind_context) = cx.finalize();
+            let (global_asm, _debug_context, unwind_context) = cx.finalize();
             assert!(global_asm.is_empty());
             jit_module.finalize_definitions();
             std::mem::forget(unsafe { unwind_context.register_jit(&jit_module) });
@@ -233,7 +232,7 @@ fn load_imported_symbols_for_jit(tcx: TyCtxt<'_>) -> Vec<(String, *const u8)> {
     imported_symbols
 }
 
-pub(super) fn codegen_shim<'tcx>(cx: &mut CodegenCx<'tcx, impl Module>, inst: Instance<'tcx>) {
+pub(super) fn codegen_shim<'tcx>(cx: &mut CodegenCx<'_, 'tcx>, inst: Instance<'tcx>) {
     let tcx = cx.tcx;
 
     let pointer_type = cx.module.target_config().pointer_type();
diff --git a/src/driver/mod.rs b/src/driver/mod.rs
index 360810cb58e..91cfde654f9 100644
--- a/src/driver/mod.rs
+++ b/src/driver/mod.rs
@@ -43,7 +43,7 @@ pub(crate) fn codegen_crate(
 }
 
 fn predefine_mono_items<'tcx>(
-    cx: &mut crate::CodegenCx<'tcx, impl Module>,
+    cx: &mut crate::CodegenCx<'_, 'tcx>,
     mono_items: &[(MonoItem<'tcx>, (RLinkage, Visibility))],
 ) {
     cx.tcx.sess.time("predefine functions", || {