about summary refs log tree commit diff stats
path: root/subx/034discourage_raw_hex.cc
diff options
context:
space:
mode:
Diffstat (limited to 'subx/034discourage_raw_hex.cc')
-rw-r--r--subx/034discourage_raw_hex.cc21
1 files changed, 21 insertions, 0 deletions
diff --git a/subx/034discourage_raw_hex.cc b/subx/034discourage_raw_hex.cc
new file mode 100644
index 00000000..e5393bab
--- /dev/null
+++ b/subx/034discourage_raw_hex.cc
@@ -0,0 +1,21 @@
+//: Now that we have operand metadata, start warning on instructions that
+//: don't use it.
+//:
+//: While SubX will let you write raw machine code, don't do that unless you
+//: have a very good reason.
+
+:(after "Begin Level-2 Transforms")
+Transform.push_back(warn_on_raw_jumps);
+:(code)
+void warn_on_raw_jumps(/*const*/ program& p) {
+  if (p.segments.empty()) return;
+  segment& code = p.segments.at(0);
+  trace(99, "transform") << "-- warn on raw hex instructions" << end();
+  for (int i = 0;  i < SIZE(code.lines);  ++i) {
+    line& inst = code.lines.at(i);
+    if (all_hex_bytes(inst) && has_operands(inst)) {
+      warn << "'" << to_string(inst) << "': using raw hex is not recommended.\n" << end();
+      break;
+    }
+  }
+}