This commit is contained in:
bjorn3 2018-09-09 14:45:23 +02:00
parent 6196146ac4
commit e7ca9a186b
4 changed files with 22 additions and 16 deletions

View File

@ -35,7 +35,7 @@ build_lib() {
}
run_bin() {
SHOULD_RUN=1 $RUSTC $1 --crate-type bin
SHOULD_RUN=1 $RUSTC $@ --crate-type bin
}
build_example_bin() {
@ -58,15 +58,18 @@ RUSTC="rustc -Zcodegen-backend=$(pwd)/target/$channel/librustc_codegen_cranelift
rm -r target/out || true
mkdir -p target/out/clif
echo "[BUILD] mini_core"
build_lib mini_core examples/mini_core.rs
$RUSTC examples/example.rs --crate-type lib
# SimpleJIT is broken
# run_bin examples/mini_core_hello_world.rs
echo "[JIT] mini_core_hello_world"
run_bin examples/mini_core_hello_world.rs --cfg jit
echo "[AOT] mini_core_hello_world"
build_example_bin mini_core_hello_world examples/mini_core_hello_world.rs
echo "[BUILD] core"
time $RUSTC target/libcore/src/libcore/lib.rs --crate-type lib --crate-name core -Cincremental=target/incremental_core
cat target/out/log.txt | sort | uniq -c
#extract_data libcore.rlib core.o

View File

@ -17,6 +17,10 @@ unsafe extern "C" fn my_puts(s: *const u8) {
puts(s);
}
// TODO remove when jit supports linking rlibs
#[cfg(jit)]
fn panic<T>(_: T) { loop {} }
#[lang = "termination"]
trait Termination {
fn report(self) -> i32;
@ -61,8 +65,12 @@ fn main() {
let ptr: *const u8 = hello as *const [u8] as *const u8;
puts(ptr);
let world = box "World!\0";
puts(*world as *const str as *const u8);
// TODO remove when jit supports linking rlibs
#[cfg(not(jit))]
{
let world = box "World!\0";
puts(*world as *const str as *const u8);
}
if intrinsics::size_of_val(hello) as u8 != 6 {
panic(&("", "", 0, 0));

View File

@ -27,9 +27,7 @@ impl ConstantCx {
//println!("todo {:?}", self.todo);
define_all_allocs(tcx, module, &mut self);
//println!("done {:?}", self.done);
for data_id in self.done.drain() {
module.finalize_data(data_id);
}
self.done.clear();
}
}

View File

@ -230,9 +230,8 @@ impl CodegenBackend for CraneliftCodegenBackend {
codegen_mono_items(tcx, &mut jit_module, &mono_items);
tcx.sess.abort_if_errors();
tcx.sess.warn("Compiled everything");
tcx.sess.warn("Rustc codegen cranelift will JIT run the executable, because the SHOULD_RUN env var is set");
println!("Compiled everything");
println!("Rustc codegen cranelift will JIT run the executable, because the SHOULD_RUN env var is set");
let sig = Signature {
params: vec![
@ -246,14 +245,14 @@ impl CodegenBackend for CraneliftCodegenBackend {
.declare_function("main", Linkage::Import, &sig)
.unwrap();
let finalized_main: *const u8 = jit_module.finalize_function(main_func_id);
jit_module.finalize_all();
tcx.sess.warn("Finalized everything");
let finalized_main: *const u8 = jit_module.get_finalized_function(main_func_id);
println!("🎉 Finalized everything");
let f: extern "C" fn(isize, *const *const u8) -> isize =
unsafe { ::std::mem::transmute(finalized_main) };
let res = f(0, 0 as *const _);
tcx.sess.warn(&format!("main returned {}", res));
tcx.sess.warn(&format!("🚀 main returned {}", res));
jit_module.finish();
::std::process::exit(0);
@ -271,11 +270,9 @@ impl CodegenBackend for CraneliftCodegenBackend {
codegen_mono_items(tcx, &mut faerie_module, &mono_items);
tcx.sess.abort_if_errors();
tcx.sess.warn("Compiled everything");
if should_codegen(tcx.sess) {
faerie_module.finalize_all();
tcx.sess.warn("Finalized everything");
}
return Box::new(OngoingCodegen {