From b58d4b034ad372e13384179721fb345a51febfce Mon Sep 17 00:00:00 2001 From: Johannes Stoelp Date: Thu, 19 Dec 2024 18:30:19 +0100 Subject: example: use Runtime::dump rather than writing bytes out by hand --- examples/add.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'examples/add.rs') 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:: u32>(code) }; + let add42 = unsafe { rt.add_code:: 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); -- cgit v1.2.3