Skip to content

Commit e7ca9a1

Browse files
committed
Fix jit
1 parent 6196146 commit e7ca9a1

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

build.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ build_lib() {
3535
}
3636

3737
run_bin() {
38-
SHOULD_RUN=1 $RUSTC $1 --crate-type bin
38+
SHOULD_RUN=1 $RUSTC $@ --crate-type bin
3939
}
4040

4141
build_example_bin() {
@@ -58,15 +58,18 @@ RUSTC="rustc -Zcodegen-backend=$(pwd)/target/$channel/librustc_codegen_cranelift
5858
rm -r target/out || true
5959
mkdir -p target/out/clif
6060

61+
echo "[BUILD] mini_core"
6162
build_lib mini_core examples/mini_core.rs
6263

6364
$RUSTC examples/example.rs --crate-type lib
6465

65-
# SimpleJIT is broken
66-
# run_bin examples/mini_core_hello_world.rs
66+
echo "[JIT] mini_core_hello_world"
67+
run_bin examples/mini_core_hello_world.rs --cfg jit
6768

69+
echo "[AOT] mini_core_hello_world"
6870
build_example_bin mini_core_hello_world examples/mini_core_hello_world.rs
6971

72+
echo "[BUILD] core"
7073
time $RUSTC target/libcore/src/libcore/lib.rs --crate-type lib --crate-name core -Cincremental=target/incremental_core
7174
cat target/out/log.txt | sort | uniq -c
7275
#extract_data libcore.rlib core.o

examples/mini_core_hello_world.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ unsafe extern "C" fn my_puts(s: *const u8) {
1717
puts(s);
1818
}
1919

20+
// TODO remove when jit supports linking rlibs
21+
#[cfg(jit)]
22+
fn panic<T>(_: T) { loop {} }
23+
2024
#[lang = "termination"]
2125
trait Termination {
2226
fn report(self) -> i32;
@@ -61,8 +65,12 @@ fn main() {
6165
let ptr: *const u8 = hello as *const [u8] as *const u8;
6266
puts(ptr);
6367

64-
let world = box "World!\0";
65-
puts(*world as *const str as *const u8);
68+
// TODO remove when jit supports linking rlibs
69+
#[cfg(not(jit))]
70+
{
71+
let world = box "World!\0";
72+
puts(*world as *const str as *const u8);
73+
}
6674

6775
if intrinsics::size_of_val(hello) as u8 != 6 {
6876
panic(&("", "", 0, 0));

src/constant.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ impl ConstantCx {
2727
//println!("todo {:?}", self.todo);
2828
define_all_allocs(tcx, module, &mut self);
2929
//println!("done {:?}", self.done);
30-
for data_id in self.done.drain() {
31-
module.finalize_data(data_id);
32-
}
30+
self.done.clear();
3331
}
3432
}
3533

src/lib.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,8 @@ impl CodegenBackend for CraneliftCodegenBackend {
230230
codegen_mono_items(tcx, &mut jit_module, &mono_items);
231231

232232
tcx.sess.abort_if_errors();
233-
tcx.sess.warn("Compiled everything");
234-
235-
tcx.sess.warn("Rustc codegen cranelift will JIT run the executable, because the SHOULD_RUN env var is set");
233+
println!("Compiled everything");
234+
println!("Rustc codegen cranelift will JIT run the executable, because the SHOULD_RUN env var is set");
236235

237236
let sig = Signature {
238237
params: vec![
@@ -246,14 +245,14 @@ impl CodegenBackend for CraneliftCodegenBackend {
246245
.declare_function("main", Linkage::Import, &sig)
247246
.unwrap();
248247

249-
let finalized_main: *const u8 = jit_module.finalize_function(main_func_id);
250248
jit_module.finalize_all();
251-
tcx.sess.warn("Finalized everything");
249+
let finalized_main: *const u8 = jit_module.get_finalized_function(main_func_id);
250+
println!("🎉 Finalized everything");
252251

253252
let f: extern "C" fn(isize, *const *const u8) -> isize =
254253
unsafe { ::std::mem::transmute(finalized_main) };
255254
let res = f(0, 0 as *const _);
256-
tcx.sess.warn(&format!("main returned {}", res));
255+
tcx.sess.warn(&format!("🚀 main returned {}", res));
257256

258257
jit_module.finish();
259258
::std::process::exit(0);
@@ -271,11 +270,9 @@ impl CodegenBackend for CraneliftCodegenBackend {
271270
codegen_mono_items(tcx, &mut faerie_module, &mono_items);
272271

273272
tcx.sess.abort_if_errors();
274-
tcx.sess.warn("Compiled everything");
275273

276274
if should_codegen(tcx.sess) {
277275
faerie_module.finalize_all();
278-
tcx.sess.warn("Finalized everything");
279276
}
280277

281278
return Box::new(OngoingCodegen {

0 commit comments

Comments
 (0)