From 3e61fd93a3e31df1ab32c2c1fc1e8b354d410c23 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Sat, 4 Aug 2018 23:30:04 -0700 Subject: 4484 - warn when programming in raw hex --- subx/003trace.cc | 2 +- subx/034discourage_raw_hex.cc | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 subx/034discourage_raw_hex.cc diff --git a/subx/003trace.cc b/subx/003trace.cc index 84af9a4a..7dab5d5c 100644 --- a/subx/003trace.cc +++ b/subx/003trace.cc @@ -158,7 +158,7 @@ void trace_stream::newline() { string curr_contents = curr_stream->str(); if (!curr_contents.empty()) { past_lines.push_back(trace_line(curr_depth, trim(curr_label), curr_contents)); // preserve indent in contents - if ((!Hide_errors && curr_label == "error") + if ((!Hide_errors && curr_depth <= Warn_depth) || Dump_trace || (!Dump_label.empty() && curr_label == Dump_label)) cerr << curr_label << ": " << curr_contents << '\n'; 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; + } + } +} -- cgit 1.4.1-2-gfad0