1
Fork 0
rust/src/driver/mod.rs

55 lines
2 KiB
Rust
Raw Normal View History

//! Drivers are responsible for calling [`codegen_fn`] or [`codegen_static`] for each mono item and
//! performing any further actions like JIT executing or writing object files.
//!
//! [`codegen_fn`]: crate::base::codegen_fn
//! [`codegen_static`]: crate::constant::codegen_static
use rustc_middle::mir::mono::{Linkage as RLinkage, MonoItem, Visibility};
2019-05-04 16:54:25 +02:00
use crate::prelude::*;
pub(crate) mod aot;
2020-07-09 14:23:00 +02:00
#[cfg(feature = "jit")]
pub(crate) mod jit;
2019-05-04 16:54:25 +02:00
fn predefine_mono_items<'tcx>(
tcx: TyCtxt<'tcx>,
module: &mut dyn Module,
mono_items: &[(MonoItem<'tcx>, (RLinkage, Visibility))],
2019-05-04 16:54:25 +02:00
) {
tcx.sess.time("predefine functions", || {
let is_compiler_builtins = tcx.is_compiler_builtins(LOCAL_CRATE);
for &(mono_item, (linkage, visibility)) in mono_items {
match mono_item {
MonoItem::Fn(instance) => {
let name = tcx.symbol_name(instance).name;
let _inst_guard = crate::PrintOnPanic(|| format!("{:?} {}", instance, name));
let sig =
get_function_sig(tcx, module.target_config().default_call_conv, instance);
let linkage = crate::linkage::get_clif_linkage(
mono_item,
linkage,
visibility,
is_compiler_builtins,
);
module.declare_function(name, linkage, &sig).unwrap();
}
MonoItem::Static(_) | MonoItem::GlobalAsm(_) => {}
}
2019-05-04 16:54:25 +02:00
}
});
}
fn time<R>(tcx: TyCtxt<'_>, display: bool, name: &'static str, f: impl FnOnce() -> R) -> R {
if display {
println!("[{:<30}: {}] start", tcx.crate_name(LOCAL_CRATE), name);
2020-03-12 11:17:19 +01:00
let before = std::time::Instant::now();
let res = tcx.sess.time(name, f);
2020-03-12 11:17:19 +01:00
let after = std::time::Instant::now();
println!("[{:<30}: {}] end time: {:?}", tcx.crate_name(LOCAL_CRATE), name, after - before);
2020-03-12 11:17:19 +01:00
res
} else {
tcx.sess.time(name, f)
2020-03-12 11:17:19 +01:00
}
2019-05-04 16:54:25 +02:00
}