diff options
author | Kartik Agaram <vc@akkartik.com> | 2018-08-04 23:30:04 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2018-08-04 23:30:04 -0700 |
commit | 3e61fd93a3e31df1ab32c2c1fc1e8b354d410c23 (patch) | |
tree | 72b84af6ad41512443a7dbb9be55fc29dfb25a45 /subx | |
parent | 7f7d3dcca5d1974174782bc71009a808a573eae7 (diff) | |
download | mu-3e61fd93a3e31df1ab32c2c1fc1e8b354d410c23.tar.gz |
4484 - warn when programming in raw hex
Diffstat (limited to 'subx')
-rw-r--r-- | subx/003trace.cc | 2 | ||||
-rw-r--r-- | subx/034discourage_raw_hex.cc | 21 |
2 files changed, 22 insertions, 1 deletions
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; + } + } +} |