Remove CodegenCx

This commit is contained in:
bjorn3 2018-08-26 16:58:52 +02:00
parent e66f012d79
commit 42887dfdd9
2 changed files with 29 additions and 37 deletions

View file

@ -10,11 +10,13 @@ impl Drop for PrintOnPanic {
}
pub fn trans_mono_item<'a, 'tcx: 'a>(
cx: &mut CodegenCx<'a, 'tcx, impl Backend>,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
module: &mut Module<impl Backend>,
caches: &mut Caches,
ccx: &mut crate::constant::ConstantCx,
mono_item: MonoItem<'tcx>,
) {
let tcx = cx.tcx;
let context = &mut cx.context;
let context = &mut caches.context;
match mono_item {
MonoItem::Fn(inst) => {
@ -30,7 +32,7 @@ pub fn trans_mono_item<'a, 'tcx: 'a>(
| InstanceDef::ClosureOnceShim { .. }
| InstanceDef::CloneShim(_, _) => {
// FIXME fix write_mir_pretty for these instances
format!("{:#?}", cx.tcx.instance_mir(inst.def)).into_bytes()
format!("{:#?}", tcx.instance_mir(inst.def)).into_bytes()
}
InstanceDef::Intrinsic(_) => bug!("tried to codegen intrinsic"),
};
@ -38,13 +40,12 @@ pub fn trans_mono_item<'a, 'tcx: 'a>(
"target/out/mir/".to_string() + &format!("{:?}", inst.def_id()).replace('/', "@");
::std::fs::write(mir_file_name, mir).unwrap();
trans_fn(tcx, cx.module, &mut cx.ccx, context, inst);
trans_fn(tcx, module, ccx, context, inst);
}
MonoItem::Static(def_id) => {
crate::constant::codegen_static(&mut cx.ccx, def_id);
crate::constant::codegen_static(ccx, def_id);
}
MonoItem::GlobalAsm(node_id) => cx
.tcx
MonoItem::GlobalAsm(node_id) => tcx
.sess
.fatal(&format!("Unimplemented global asm mono item {:?}", node_id)),
}

View file

@ -90,8 +90,7 @@ mod prelude {
pub use crate::abi::*;
pub use crate::base::{trans_operand, trans_place};
pub use crate::common::*;
pub use crate::{CodegenCx, ModuleTup};
pub use crate::Caches;
pub fn should_codegen(sess: &Session) -> bool {
//return true;
@ -103,20 +102,16 @@ mod prelude {
use crate::constant::ConstantCx;
use crate::prelude::*;
pub struct CodegenCx<'a, 'tcx: 'a, B: Backend + 'static> {
pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
pub module: &'a mut Module<B>,
pub ccx: ConstantCx,
// Cache
pub struct Caches {
pub context: Context,
}
pub struct ModuleTup<T> {
#[allow(dead_code)]
jit: Option<T>,
#[allow(dead_code)]
faerie: Option<T>,
impl Caches {
fn new() -> Self {
Caches {
context: Context::new(),
}
}
}
struct CraneliftCodegenBackend;
@ -360,23 +355,18 @@ fn codegen_mono_items<'a, 'tcx: 'a>(
) {
use std::io::Write;
let mut cx = CodegenCx {
tcx,
module,
ccx: ConstantCx::default(),
context: Context::new(),
};
let mut caches = Caches::new();
let mut ccx = ConstantCx::default();
let mut log = ::std::fs::File::create("target/out/log.txt").unwrap();
let before = ::std::time::Instant::now();
for mono_item in mono_items {
let cx = &mut cx;
let res = ::std::panic::catch_unwind(::std::panic::AssertUnwindSafe(move || {
base::trans_mono_item(cx, *mono_item);
let res = ::std::panic::catch_unwind(::std::panic::AssertUnwindSafe(|| {
base::trans_mono_item(tcx, module, &mut caches, &mut ccx, *mono_item);
}));
if let Err(err) = res {
match err.downcast::<NonFatal>() {
Ok(non_fatal) => {
@ -388,9 +378,9 @@ fn codegen_mono_items<'a, 'tcx: 'a>(
}
}
maybe_create_entry_wrapper(&mut cx);
maybe_create_entry_wrapper(tcx, module);
cx.ccx.finalize(tcx, cx.module);
ccx.finalize(tcx, module);
let after = ::std::time::Instant::now();
println!("time: {:?}", after - before);
@ -410,12 +400,13 @@ pub fn __rustc_codegen_backend() -> Box<CodegenBackend> {
/// Create the `main` function which will initialize the rust runtime and call
/// users main function.
fn maybe_create_entry_wrapper(cx: &mut CodegenCx<impl Backend + 'static>) {
fn maybe_create_entry_wrapper<'a, 'tcx: 'a>(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
module: &mut Module<impl Backend + 'static>,
) {
use rustc::middle::lang_items::StartFnLangItem;
use rustc::session::config::EntryFnType;
let tcx = cx.tcx;
let (main_def_id, use_start_lang_item) = match *tcx.sess.entry_fn.borrow() {
Some((id, _, entry_ty)) => (
tcx.hir.local_def_id(id),
@ -427,7 +418,7 @@ fn maybe_create_entry_wrapper(cx: &mut CodegenCx<impl Backend + 'static>) {
None => return,
};
create_entry_fn(tcx, cx.module, main_def_id, use_start_lang_item);;
create_entry_fn(tcx, module, main_def_id, use_start_lang_item);;
fn create_entry_fn<'a, 'tcx: 'a>(
tcx: TyCtxt<'a, 'tcx, 'tcx>,