aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorJohannes Stoelp <johannes.stoelp@gmail.com>2024-12-19 18:30:19 +0100
committerJohannes Stoelp <johannes.stoelp@gmail.com>2024-12-19 18:30:19 +0100
commitb58d4b034ad372e13384179721fb345a51febfce (patch)
treee84e4707560910b21e0c7262f5fcc654aed6c88b /examples
parent40bcea9b225cd5936d14715e8f3cb8dc366baece (diff)
downloadjuicebox-asm-b58d4b034ad372e13384179721fb345a51febfce.tar.gz
juicebox-asm-b58d4b034ad372e13384179721fb345a51febfce.zip
example: use Runtime::dump rather than writing bytes out by hand
Diffstat (limited to 'examples')
-rw-r--r--examples/add.rs9
-rw-r--r--examples/fib.rs11
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);