Remove CodegenCx
This commit is contained in:
parent
e66f012d79
commit
42887dfdd9
2 changed files with 29 additions and 37 deletions
17
src/base.rs
17
src/base.rs
|
@ -10,11 +10,13 @@ impl Drop for PrintOnPanic {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn trans_mono_item<'a, 'tcx: 'a>(
|
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>,
|
mono_item: MonoItem<'tcx>,
|
||||||
) {
|
) {
|
||||||
let tcx = cx.tcx;
|
let context = &mut caches.context;
|
||||||
let context = &mut cx.context;
|
|
||||||
|
|
||||||
match mono_item {
|
match mono_item {
|
||||||
MonoItem::Fn(inst) => {
|
MonoItem::Fn(inst) => {
|
||||||
|
@ -30,7 +32,7 @@ pub fn trans_mono_item<'a, 'tcx: 'a>(
|
||||||
| InstanceDef::ClosureOnceShim { .. }
|
| InstanceDef::ClosureOnceShim { .. }
|
||||||
| InstanceDef::CloneShim(_, _) => {
|
| InstanceDef::CloneShim(_, _) => {
|
||||||
// FIXME fix write_mir_pretty for these instances
|
// 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"),
|
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('/', "@");
|
"target/out/mir/".to_string() + &format!("{:?}", inst.def_id()).replace('/', "@");
|
||||||
::std::fs::write(mir_file_name, mir).unwrap();
|
::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) => {
|
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
|
MonoItem::GlobalAsm(node_id) => tcx
|
||||||
.tcx
|
|
||||||
.sess
|
.sess
|
||||||
.fatal(&format!("Unimplemented global asm mono item {:?}", node_id)),
|
.fatal(&format!("Unimplemented global asm mono item {:?}", node_id)),
|
||||||
}
|
}
|
||||||
|
|
49
src/lib.rs
49
src/lib.rs
|
@ -90,8 +90,7 @@ mod prelude {
|
||||||
pub use crate::abi::*;
|
pub use crate::abi::*;
|
||||||
pub use crate::base::{trans_operand, trans_place};
|
pub use crate::base::{trans_operand, trans_place};
|
||||||
pub use crate::common::*;
|
pub use crate::common::*;
|
||||||
|
pub use crate::Caches;
|
||||||
pub use crate::{CodegenCx, ModuleTup};
|
|
||||||
|
|
||||||
pub fn should_codegen(sess: &Session) -> bool {
|
pub fn should_codegen(sess: &Session) -> bool {
|
||||||
//return true;
|
//return true;
|
||||||
|
@ -103,20 +102,16 @@ mod prelude {
|
||||||
use crate::constant::ConstantCx;
|
use crate::constant::ConstantCx;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
pub struct CodegenCx<'a, 'tcx: 'a, B: Backend + 'static> {
|
pub struct Caches {
|
||||||
pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|
||||||
pub module: &'a mut Module<B>,
|
|
||||||
pub ccx: ConstantCx,
|
|
||||||
|
|
||||||
// Cache
|
|
||||||
pub context: Context,
|
pub context: Context,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ModuleTup<T> {
|
impl Caches {
|
||||||
#[allow(dead_code)]
|
fn new() -> Self {
|
||||||
jit: Option<T>,
|
Caches {
|
||||||
#[allow(dead_code)]
|
context: Context::new(),
|
||||||
faerie: Option<T>,
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CraneliftCodegenBackend;
|
struct CraneliftCodegenBackend;
|
||||||
|
@ -360,23 +355,18 @@ fn codegen_mono_items<'a, 'tcx: 'a>(
|
||||||
) {
|
) {
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
let mut cx = CodegenCx {
|
let mut caches = Caches::new();
|
||||||
tcx,
|
let mut ccx = ConstantCx::default();
|
||||||
module,
|
|
||||||
ccx: ConstantCx::default(),
|
|
||||||
|
|
||||||
context: Context::new(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut log = ::std::fs::File::create("target/out/log.txt").unwrap();
|
let mut log = ::std::fs::File::create("target/out/log.txt").unwrap();
|
||||||
|
|
||||||
let before = ::std::time::Instant::now();
|
let before = ::std::time::Instant::now();
|
||||||
|
|
||||||
for mono_item in mono_items {
|
for mono_item in mono_items {
|
||||||
let cx = &mut cx;
|
let res = ::std::panic::catch_unwind(::std::panic::AssertUnwindSafe(|| {
|
||||||
let res = ::std::panic::catch_unwind(::std::panic::AssertUnwindSafe(move || {
|
base::trans_mono_item(tcx, module, &mut caches, &mut ccx, *mono_item);
|
||||||
base::trans_mono_item(cx, *mono_item);
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if let Err(err) = res {
|
if let Err(err) = res {
|
||||||
match err.downcast::<NonFatal>() {
|
match err.downcast::<NonFatal>() {
|
||||||
Ok(non_fatal) => {
|
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();
|
let after = ::std::time::Instant::now();
|
||||||
println!("time: {:?}", after - before);
|
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
|
/// Create the `main` function which will initialize the rust runtime and call
|
||||||
/// users main function.
|
/// 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::middle::lang_items::StartFnLangItem;
|
||||||
use rustc::session::config::EntryFnType;
|
use rustc::session::config::EntryFnType;
|
||||||
|
|
||||||
let tcx = cx.tcx;
|
|
||||||
|
|
||||||
let (main_def_id, use_start_lang_item) = match *tcx.sess.entry_fn.borrow() {
|
let (main_def_id, use_start_lang_item) = match *tcx.sess.entry_fn.borrow() {
|
||||||
Some((id, _, entry_ty)) => (
|
Some((id, _, entry_ty)) => (
|
||||||
tcx.hir.local_def_id(id),
|
tcx.hir.local_def_id(id),
|
||||||
|
@ -427,7 +418,7 @@ fn maybe_create_entry_wrapper(cx: &mut CodegenCx<impl Backend + 'static>) {
|
||||||
None => return,
|
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>(
|
fn create_entry_fn<'a, 'tcx: 'a>(
|
||||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue