#[cfg(not(any(target_arch = "x86_64", target_os = "linux")))]
compile_error!("Only supported on x86_64 with SystemV abi");
use juicebox_asm::insn::*;
use juicebox_asm::{Asm, Imm16, Imm64, Imm8, Label, Reg16, Reg64::*, Runtime};
use juicebox_asm::{MemOp, MemOp16, MemOp32, MemOp64, MemOp8};
extern "C" fn add(a: u32, b: u32) -> u32 {
a + b
}
fn main() {
let mut asm1 = Asm::new();
asm1.xor(r11, r11);
assert!(0x7fu8 <= i8::MAX as u8);
asm1.add(MemOp::IndirectBaseIndex(rdi, r11), Imm8::from(0x10u8));
asm1.ret();
let code = asm1.into_code();
std::fs::write("jit.asm", &code).unwrap();
let mut asm2 = Asm::new();
asm2.mov(Reg16::cx, Imm16::from(1u16));
asm2.mov(MemOp::Indirect(rdi), Reg16::cx);
asm2.ret();
let mut rt = Runtime::new();
let fn1 = unsafe { rt.add_code::<extern "C" fn(*mut u64)>(code) };
let fn2 = unsafe { rt.add_code::<extern "C" fn(*mut u64)>(asm2.into_code()) };
let mut data = 0xffff_ffff_ffff_ff00u64;
fn1(&mut data as *mut u64);
println!("data={:x}", data);
let mut data = 0xffff_ffff_ffff_ffffu64;
fn2(&mut data as *mut u64);
println!("data={:x}", data);
}