diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/add.rs | 9 | ||||
-rw-r--r-- | examples/fib.rs | 11 |
2 files changed, 10 insertions, 10 deletions
diff --git a/examples/add.rs b/examples/add.rs index 687d205..3ad8893 100644 --- a/examples/add.rs +++ b/examples/add.rs @@ -27,11 +27,12 @@ fn main() { asm.call(rax); asm.ret(); - let code = asm.into_code(); - std::fs::write("jit.asm", &code).unwrap(); - let mut rt = Runtime::new(); - let add42 = unsafe { rt.add_code::<extern "C" fn(u32) -> u32>(code) }; + let add42 = unsafe { rt.add_code::<extern "C" fn(u32) -> u32>(asm.into_code()) }; + + // Write out JIT code for visualization. + // Disassemble for example with `ndisasm -b 64 jit.asm`. + rt.dump(); let res = add42(5); assert_eq!(res, 47); diff --git a/examples/fib.rs b/examples/fib.rs index b495067..c38589f 100644 --- a/examples/fib.rs +++ b/examples/fib.rs @@ -62,14 +62,13 @@ fn main() { asm.bind(&mut end); asm.ret(); - // Write out JIT code for visualization. - // Disassemble for example with `ndisasm -b 64 jit.asm`. - let code = asm.into_code(); - std::fs::write("jit.asm", &code).unwrap(); - // Move code into executable page and get function pointer to it. let mut rt = Runtime::new(); - let fib = unsafe { rt.add_code::<extern "C" fn(u64) -> u64>(code) }; + let fib = unsafe { rt.add_code::<extern "C" fn(u64) -> u64>(asm.into_code()) }; + + // Write out JIT code for visualization. + // Disassemble for example with `ndisasm -b 64 jit.asm`. + rt.dump(); for n in 0..15 { let fib_jit = fib(n); |