use crate::prelude::*;
-pub fn trans_mono_item<'a, 'tcx: 'a>(
- cx: &mut CodegenCx<'a, 'tcx, CurrentBackend>,
- mono_item: MonoItem<'tcx>,
-) {
+pub fn trans_mono_item<'a, 'tcx: 'a>(cx: &mut CodegenCx<'a, 'tcx>, mono_item: MonoItem<'tcx>) {
let tcx = cx.tcx;
+ let context = &mut cx.context;
match mono_item {
MonoItem::Fn(inst) => match inst {
String::from_utf8_lossy(&mir.into_inner())
));
- let func_id = trans_fn(cx.tcx, cx.module, &mut cx.constants, &mut cx.context, inst);
- cx.defined_functions.push(func_id);
+ let res = each_module!(cx, |(ccx, m)| trans_fn(tcx, *m, ccx, context, inst));
+ if let Some(func_id) = res.jit {
+ cx.defined_functions.push(func_id);
+ };
}
Instance {
def: InstanceDef::DropGlue(_, _),
inst => unimpl!("Unimplemented instance {:?}", inst),
},
MonoItem::Static(def_id) => {
- crate::constant::codegen_static(&mut cx.constants, def_id);
+ each_module!(cx, |(ccx, _m)| {
+ crate::constant::codegen_static(ccx, def_id);
+ });
}
MonoItem::GlobalAsm(node_id) => cx
.tcx
fn trans_fn<'a, 'tcx: 'a>(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
- module: &mut Module<SimpleJITBackend>,
+ module: &mut Module<impl Backend>,
constants: &mut crate::constant::ConstantCx,
context: &mut Context,
instance: Instance<'tcx>,
};
}
+macro_rules! each_module {
+ ($cx:expr, |$p:pat| $res:expr) => {
+ ModuleTup {
+ jit: $cx.jit.as_mut().map(|$p| $res),
+ faerie: $cx.faerie.as_mut().map(|$p| $res),
+ }
+ };
+}
+
mod abi;
mod analyze;
mod base;
pub use crate::common::Variable;
pub use crate::common::*;
- pub use crate::CodegenCx;
+ pub use crate::{CodegenCx, ModuleTup};
pub fn should_codegen(tcx: TyCtxt) -> bool {
::std::env::var("SHOULD_CODEGEN").is_ok()
}
}
+use crate::constant::ConstantCx;
use crate::prelude::*;
-pub struct CodegenCx<'a, 'tcx: 'a, B: Backend + 'a> {
+pub struct CodegenCx<'a, 'tcx: 'a> {
pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
- pub module: &'a mut Module<B>,
- pub constants: crate::constant::ConstantCx,
+ pub jit: Option<(ConstantCx, &'a mut Module<SimpleJITBackend>)>,
+ pub faerie: Option<(ConstantCx, &'a mut Module<FaerieBackend>)>,
pub defined_functions: Vec<FuncId>,
// Cache
pub context: Context,
}
+pub struct ModuleTup<T> {
+ jit: Option<T>,
+ faerie: Option<T>,
+}
+
struct CraneliftMetadataLoader;
impl MetadataLoader for CraneliftMetadataLoader {
use std::io::Write;
let mut cx = CodegenCx {
tcx,
- module: &mut jit_module,
- constants: Default::default(),
+ jit: Some((ConstantCx::default(), &mut jit_module)),
+ faerie: Some((ConstantCx::default(), &mut faerie_module)),
defined_functions: Vec::new(),
context: Context::new(),
}
}
- cx.constants.finalize(tcx, &mut cx.module);
+ match cx {
+ CodegenCx {
+ tcx,
+ jit,
+ faerie,
+ defined_functions: _,
+ context: _,
+ } => {
+ jit.map(|jit| jit.0.finalize(tcx, jit.1));
+ faerie.map(|faerie| faerie.0.finalize(tcx, faerie.1));
+ }
+ }
let after = ::std::time::Instant::now();
println!("time: {:?}", after - before);
cx.defined_functions
};
+ tcx.sess.abort_if_errors();
+
tcx.sess.warn("Compiled everything");
// TODO: this doesn't work most of the time
jit_module.finish();
} else if should_codegen(tcx) {
- for func_id in defined_functions {
- jit_module.finalize_function(func_id);
- }
+ jit_module.finalize_all();
+ faerie_module.finalize_all();
tcx.sess.warn("Finalized everything");
}