1 //: Now that we have operand metadata, start warning on instructions that
 2 //: don't use it.
 3 //:
 4 //: While SubX will let you write raw machine code, don't do that unless you
 5 //: have a very good reason.
 6 
 7 :(before "Pack Operands(segment code)")
 8 warn_on_raw_hex(code);
 9 if (trace_contains_errors()) return;
10 :(code)
11 void warn_on_raw_hex(const segment& code) {
12   trace(99, "transform") << "-- warn on raw hex instructions" << end();
13   for (int i = 0;  i < SIZE(code.lines);  ++i) {
14     const line& inst = code.lines.at(i);
15     if (all_hex_bytes(inst) && has_operands(inst)) {
16       warn << "'" << to_string(inst) << "': using raw hex is not recommended\n" << end();
17       break;
18     }
19   }
20 }
21 
22 :(scenarios transform)
23 :(scenario warn_on_hex_bytes_without_operands)
24 == 0x1
25 bb 2a 00 00 00  # copy 0x2a (42) to EBX
26 +warn: 'bb 2a 00 00 00': using raw hex is not recommended
27 
28 :(scenario warn_on_non_operand_metadata)
29 == 0x1
30 bb 2a 00/foo 00/bar 00  # copy 0x2a (42) to EBX
31 +warn: 'bb 2a 00/foo 00/bar 00': using raw hex is not recommended
32 
33 :(scenario no_warn_on_instructions_without_operands)
34 == 0x1
35 55  # push EBP
36 -warn: '55': using raw hex is not recommended