diff options
author | Kartik Agaram <vc@akkartik.com> | 2019-02-13 00:01:14 -0800 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2019-02-13 00:01:14 -0800 |
commit | a630d7fb9666bbacdd714ddc12d3c42ef1466ba7 (patch) | |
tree | c265456ff5ff1b576b2c26251b9c32ba7eb8b38a /subx/034compute_segment_address.cc | |
parent | ac73f9caf3cd0e9f8ea112394955a8c9bc18ac88 (diff) | |
download | mu-a630d7fb9666bbacdd714ddc12d3c42ef1466ba7.tar.gz |
4959
It's always seemed ugly to explain the rules for segment names. Let's just always require a fixed name for the code and data segments.
Diffstat (limited to 'subx/034compute_segment_address.cc')
-rw-r--r-- | subx/034compute_segment_address.cc | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/subx/034compute_segment_address.cc b/subx/034compute_segment_address.cc index b6c191e4..d37060a4 100644 --- a/subx/034compute_segment_address.cc +++ b/subx/034compute_segment_address.cc @@ -34,12 +34,15 @@ if (!starts_with(segment_title, "0x")) { Currently_parsing_named_segment = true; if (!contains_key(Segment_index, segment_title)) { trace(99, "parse") << "new segment '" << segment_title << "'" << end(); - if (segment_title == "code") - put(Segment_index, segment_title, 0); - else if (segment_title == "data") - put(Segment_index, segment_title, 1); - else - put(Segment_index, segment_title, max(2, SIZE(out.segments))); + if (out.segments.empty() && segment_title != "code") { + raise << "first segment must be 'code' but is '" << segment_title << "'\n" << end(); + return; + } + if (SIZE(out.segments) == 1 && segment_title != "data") { + raise << "second segment must be 'data' but is '" << segment_title << "'\n" << end(); + return; + } + put(Segment_index, segment_title, SIZE(out.segments)); out.segments.push_back(segment()); } else { @@ -50,10 +53,7 @@ if (!starts_with(segment_title, "0x")) { :(before "End flush(p, lines) Special-cases") if (Currently_parsing_named_segment) { - if (p.segments.empty() || Currently_parsing_segment_index < 0) { - raise << "input does not start with a '==' section header\n" << end(); - return; - } + assert(!p.segments.empty()); trace(99, "parse") << "flushing to segment" << end(); vector<line>& curr_segment_data = p.segments.at(Currently_parsing_segment_index).lines; curr_segment_data.insert(curr_segment_data.begin(), lines.begin(), lines.end()); @@ -81,6 +81,25 @@ if (Currently_parsing_named_segment) { +load: 0x0900005c -> 0c +load: 0x0900005d -> 0d +:(scenario error_on_missing_segment_header) +% Hide_errors = true; +05/add-to-EAX 0/imm32 ++error: input does not start with a '==' section header + +:(scenario error_on_first_segment_not_code) +% Hide_errors = true; +== data +05 00 00 00 00 ++error: first segment must be 'code' but is 'data' + +:(scenario error_on_second_segment_not_data) +% Hide_errors = true; +== code +05/add-to-EAX 0/imm32 +== bss +05 00 00 00 00 ++error: second segment must be 'data' but is 'bss' + //: compute segment address :(before "End Level-2 Transforms") |