.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),
});
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)
};
mod base;
mod common;
mod constant;
-mod pretty_clif;
mod metadata;
+mod pretty_clif;
mod prelude {
pub use std::any::Any;
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(),
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");
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),
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,
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) {
-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;
// 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();