MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / roundtrip

Function roundtrip

cranelift/assembler-x64/src/fuzz.rs:26–43  ·  view source on GitHub ↗

Take a random assembly instruction and check its encoding and pretty-printing against a known-good disassembler. # Panics This function panics to express failure as expected by the `arbitrary` fuzzer infrastructure. It may fail during assembly, disassembly, or when comparing the disassembled strings.

(inst: &Inst<FuzzRegs>)

Source from the content-addressed store, hash-verified

24/// fuzzer infrastructure. It may fail during assembly, disassembly, or when
25/// comparing the disassembled strings.
26pub fn roundtrip(inst: &Inst<FuzzRegs>) {
27 // Check that we can actually assemble this instruction.
28 let assembled = assemble(inst);
29 let expected = disassemble(&assembled, inst);
30
31 // Check that our pretty-printed output matches the known-good output. Trim
32 // off the instruction offset first.
33 let expected = expected.split_once(' ').unwrap().1;
34 let actual = inst.to_string();
35 if expected != actual && expected.trim() != fix_up(&actual) {
36 println!("> {inst}");
37 println!(" debug: {inst:x?}");
38 println!(" assembled: {}", pretty_print_hexadecimal(&assembled));
39 println!(" expected (capstone): {expected}");
40 println!(" actual (to_string): {actual}");
41 assert_eq!(expected, &actual);
42 }
43}
44
45/// Use this assembler to emit machine code into a byte buffer.
46///

Callers 2

smokeFunction · 0.70
callqFunction · 0.70

Calls 5

assembleFunction · 0.85
disassembleFunction · 0.85
fix_upFunction · 0.85
unwrapMethod · 0.45
to_stringMethod · 0.45

Tested by 2

smokeFunction · 0.56
callqFunction · 0.56