]> git.lizzy.rs Git - rust.git/commitdiff
Use either SimpleJIT or faerie, but not both
authorbjorn3 <bjorn3@users.noreply.github.com>
Wed, 15 Aug 2018 12:45:32 +0000 (14:45 +0200)
committerbjorn3 <bjorn3@users.noreply.github.com>
Wed, 15 Aug 2018 12:45:32 +0000 (14:45 +0200)
src/abi.rs
src/lib.rs
src/metadata.rs

index 9c8d1a13a2e1a9314a72405aac14ca0e977a5b0b..55fcc277a9a2ef806bbed8109ab92985d988cf97 100644 (file)
@@ -336,7 +336,8 @@ enum ArgKind {
                 .unwrap()
                 .contains(crate::analyze::Flags::NOT_SSA)
             {
-                fx.bcx.declare_var(mir_var(local), fx.cton_type(ty).unwrap());
+                fx.bcx
+                    .declare_var(mir_var(local), fx.cton_type(ty).unwrap());
                 match get_pass_mode(fx.tcx, fx.self_sig().abi, ty, false) {
                     PassMode::NoPass => unimplemented!("pass mode nopass"),
                     PassMode::ByVal(_) => fx.bcx.def_var(mir_var(local), ebb_param),
@@ -401,7 +402,8 @@ enum ArgKind {
             });
             CPlace::from_stack_slot(fx, stack_slot, ty)
         } else {
-            fx.bcx.declare_var(mir_var(local), fx.cton_type(ty).unwrap());
+            fx.bcx
+                .declare_var(mir_var(local), fx.cton_type(ty).unwrap());
             CPlace::Var(local, layout)
         };
 
index 22089a1241fff6925600e3f883a4fb234d0b1203..1cf5abd873d9a83d7753496d8b67deb807a20c03 100644 (file)
@@ -60,8 +60,8 @@ macro_rules! each_module {
 mod base;
 mod common;
 mod constant;
-mod pretty_clif;
 mod metadata;
+mod pretty_clif;
 
 mod prelude {
     pub use std::any::Any;
@@ -222,22 +222,31 @@ fn codegen_crate<'a, 'tcx>(
         let isa = cranelift::codegen::isa::lookup(target_lexicon::Triple::host())
             .unwrap()
             .finish(flags);
-        let mut jit_module: Module<SimpleJITBackend> = Module::new(SimpleJITBuilder::new());
-        let mut faerie_module: Module<FaerieBackend> = Module::new(
-            FaerieBuilder::new(
-                isa,
-                "some_file.o".to_string(),
-                FaerieTrapCollection::Disabled,
-                FaerieBuilder::default_libcall_names(),
-            ).unwrap(),
-        );
+        let (mut jit_module, mut faerie_module): (
+            Option<Module<SimpleJITBackend>>,
+            Option<Module<FaerieBackend>>,
+        ) = if std::env::var("SHOULD_RUN").is_ok() {
+            (Some(Module::new(SimpleJITBuilder::new())), None)
+        } else {
+            (
+                None,
+                Some(Module::new(
+                    FaerieBuilder::new(
+                        isa,
+                        "some_file.o".to_string(),
+                        FaerieTrapCollection::Disabled,
+                        FaerieBuilder::default_libcall_names(),
+                    ).unwrap(),
+                )),
+            )
+        };
 
         let defined_functions = {
             use std::io::Write;
             let mut cx = CodegenCx {
                 tcx,
-                jit: Some((ConstantCx::default(), &mut jit_module)),
-                faerie: Some((ConstantCx::default(), &mut faerie_module)),
+                jit: jit_module.as_mut().map(|m| (ConstantCx::default(), m)),
+                faerie: faerie_module.as_mut().map(|m| (ConstantCx::default(), m)),
                 defined_functions: Vec::new(),
 
                 context: Context::new(),
@@ -294,7 +303,7 @@ fn codegen_crate<'a, 'tcx>(
         tcx.sess.warn("Compiled everything");
 
         // TODO: this doesn't work most of the time
-        if std::env::var("SHOULD_RUN").is_ok() {
+        if let Some(mut jit_module) = jit_module {
             tcx.sess.warn("Rustc codegen cranelift will JIT run the executable, because the SHOULD_RUN env var is set");
             let start_wrapper = tcx.lang_items().start_fn().expect("no start lang item");
 
@@ -320,14 +329,13 @@ fn codegen_crate<'a, 'tcx>(
             jit_module.finish();
             ::std::process::exit(0);
         } else if should_codegen(tcx.sess) {
-            jit_module.finalize_all();
-            faerie_module.finalize_all();
+            faerie_module.as_mut().map(|m| m.finalize_all());
 
             tcx.sess.warn("Finalized everything");
         }
 
         Box::new(OngoingCodegen {
-            product: faerie_module.finish(),
+            product: faerie_module.unwrap().finish(),
             metadata: metadata.raw_data,
             crate_name: tcx.crate_name(LOCAL_CRATE),
             crate_hash: tcx.crate_hash(LOCAL_CRATE),
@@ -348,7 +356,8 @@ fn join_codegen_and_link(
         let mut artifact = ongoing_codegen.product.artifact;
         let metadata = ongoing_codegen.metadata;
 
-        let metadata_name = ".rustc.clif_metadata".to_string() + &ongoing_codegen.crate_hash.to_string();
+        let metadata_name =
+            ".rustc.clif_metadata".to_string() + &ongoing_codegen.crate_hash.to_string();
         artifact
             .declare_with(
                 &metadata_name,
@@ -373,7 +382,10 @@ fn join_codegen_and_link(
                     let mut builder = ar::Builder::new(file);
                     builder
                         .append(
-                            &ar::Header::new(metadata_name.as_bytes().to_vec(), metadata.len() as u64),
+                            &ar::Header::new(
+                                metadata_name.as_bytes().to_vec(),
+                                metadata.len() as u64,
+                            ),
                             ::std::io::Cursor::new(metadata.clone()),
                         ).unwrap();
                     if should_codegen(sess) {
index 384f59f171a904032019cc28bf45489d1e30b6e0..29bb1c8e32571d5fbd219999423dfb98fd856a17 100644 (file)
@@ -1,7 +1,7 @@
-use std::path::Path;
-use std::fs::File;
-use rustc_data_structures::owning_ref::{self, OwningRef};
 use rustc::middle::cstore::MetadataLoader;
+use rustc_data_structures::owning_ref::{self, OwningRef};
+use std::fs::File;
+use std::path::Path;
 
 pub struct CraneliftMetadataLoader;
 
@@ -15,7 +15,11 @@ fn get_rlib_metadata(
         // Iterate over all entries in the archive:
         while let Some(entry_result) = archive.next_entry() {
             let mut entry = entry_result.map_err(|e| format!("{:?}", e))?;
-            if entry.header().identifier().starts_with(b".rustc.clif_metadata") {
+            if entry
+                .header()
+                .identifier()
+                .starts_with(b".rustc.clif_metadata")
+            {
                 let mut buf = Vec::new();
                 ::std::io::copy(&mut entry, &mut buf).map_err(|e| format!("{:?}", e))?;
                 let buf: OwningRef<Vec<u8>, [u8]> = OwningRef::new(buf).into();