1 //: Raise an error when operand metadata is used in non-code segments.
 2 
 3 :(scenario operand_metadata_outside_code_segment)
 4 % Hide_errors = true;
 5 == 0x1  # code segment
 6 cd 0x80/imm8
 7 == 0x1000  # data segment
 8 cd 12/imm8
 9 +error: 12/imm8: metadata imm8 is only allowed in the (first) code segment
10 
11 :(before "Pack Operands(segment code)")
12 ensure_operands_only_in_code_segments(p);
13 if (trace_contains_errors()) return;
14 :(code)
15 void ensure_operands_only_in_code_segments(const program& p) {
16   trace(99, "transform") << "-- ensure operands only in code segments" << end();
17   if (p.segments.empty()) return;
18   for (int i = /*skip code segment*/1;  i < SIZE(p.segments);  ++i) {
19     const segment& seg = p.segments.at(i);
20     for (int j = 0;  j < SIZE(seg.lines);  ++j) {
21       const line& l = seg.lines.at(j);
22       for (int k = 0;  k < SIZE(l.words);  ++k) {
23         const word& w = l.words.at(k);
24         for (map<string, uint32_t>::iterator p = Operand_bound.begin();  p != Operand_bound.end();  ++p)
25           if (has_metadata(w, p->first))
26             raise << w.original << ": metadata " << p->first << " is only allowed in the (first) code segment\n" << end();
27       }
28     }
29   }
30 }