switch away from macro for nasm tests
This commit is contained in:
@@ -34,15 +34,16 @@ const WIDTHS: &[Width] = &[Width::B8, Width::B16, Width::B32, Width::B64];
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn mov() {
|
fn mov() {
|
||||||
|
let c = &mut Code::default();
|
||||||
for &r1 in Reg::IMPORTANT {
|
for &r1 in Reg::IMPORTANT {
|
||||||
for &r2 in Reg::IMPORTANT {
|
for &r2 in Reg::IMPORTANT {
|
||||||
eq!(format!("mov {r1}, {r2}"), mov(r1, r2));
|
eq(c, format!("mov {r1}, {r2}"), |c| c.mov(r1, r2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for &r1 in Reg::IMPORTANT {
|
for &r1 in Reg::IMPORTANT {
|
||||||
for &imm in IMMS {
|
for &imm in IMMS {
|
||||||
eq!(format!("mov {r1}, {imm}"), mov(r1, imm));
|
eq(c, format!("mov {r1}, {imm}"), |c| c.mov(r1, imm));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,47 +52,42 @@ fn mov() {
|
|||||||
for &imm in IMMS {
|
for &imm in IMMS {
|
||||||
for &width in WIDTHS {
|
for &width in WIDTHS {
|
||||||
let mem = mem(reg, disp, width);
|
let mem = mem(reg, disp, width);
|
||||||
eq!(format!("mov {mem}, {imm}"), mov(mem, imm));
|
eq(c, format!("mov {mem}, {imm}"), |c| c.mov(mem, imm));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn u_to_i(u: u64) -> i64 {
|
fn eq(
|
||||||
match u {
|
code: &mut Code,
|
||||||
0..0x100 => u as i8 as i64,
|
asm: impl AsRef<str>,
|
||||||
0x100..0x10000 => u as i16 as i64,
|
instr: impl FnOnce(&mut Code) -> Result<(), CompilerMsg>,
|
||||||
0x10000..0x100000000 => u as i32 as i64,
|
) {
|
||||||
0x100000000.. => u as i64,
|
let asm = asm.as_ref();
|
||||||
}
|
let expected = nasm(asm);
|
||||||
}
|
let res = instr(code);
|
||||||
|
match (expected, res) {
|
||||||
macro_rules! eq {
|
(Ok(expected), Err(e)) => {
|
||||||
($asm:expr, $instr:ident $args:tt $(,)?) => {
|
panic!(
|
||||||
let asm = $asm;
|
"{asm}: failed to compile: {}\nexpected: {expected:x?}",
|
||||||
let expected = nasm(asm.as_ref());
|
e.msg
|
||||||
let mut code = Code::default();
|
);
|
||||||
let res = code.$instr $args;
|
}
|
||||||
match (expected, res) {
|
(Err(e), Ok(_)) => {
|
||||||
(Ok(expected), Err(e)) => {
|
let res = &code.bytes[..];
|
||||||
panic!("{asm}: failed to compile: {}\nexpected: {expected:x?}", e.msg);
|
panic!("{asm}: should not have compiled:\n{e}\ngot: {res:x?}");
|
||||||
}
|
}
|
||||||
(Err(e), Ok(_)) => {
|
(Err(_), Err(_)) => (),
|
||||||
let res = &code.bytes[..];
|
(Ok(expected), Ok(_)) => {
|
||||||
panic!("{asm}: should not have compiled:\n{e}\ngot: {res:x?}");
|
let res = &code.bytes[..];
|
||||||
}
|
if expected != res {
|
||||||
(Err(_), Err(_)) => (),
|
panic!("{asm}: expected {expected:x?}, got {res:x?}")
|
||||||
(Ok(expected), Ok(_)) => {
|
|
||||||
let res = &code.bytes[..];
|
|
||||||
if expected != res {
|
|
||||||
panic!("{asm}: expected {expected:x?}, got {res:x?}")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
code.bytes.clear();
|
||||||
}
|
}
|
||||||
use eq;
|
|
||||||
|
|
||||||
fn nasm(input: &str) -> Result<Vec<u8>, String> {
|
fn nasm(input: &str) -> Result<Vec<u8>, String> {
|
||||||
let fin = "/tmp/69420nasm_in.asm";
|
let fin = "/tmp/69420nasm_in.asm";
|
||||||
|
|||||||
Reference in New Issue
Block a user