about summary refs log tree commit diff stats
path: root/subx/028translate.cc
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-07-25 17:15:20 -0700
committerKartik Agaram <vc@akkartik.com>2019-07-25 17:15:20 -0700
commit68ccf4d3245e78c869f25ffc5078f267eb22a9ee (patch)
tree40be5d4393a2112ced92c244fadb87c37607a5d7 /subx/028translate.cc
parent6dff1f28b4a513ab51e21cc9ee2680797dc62e49 (diff)
downloadmu-68ccf4d3245e78c869f25ffc5078f267eb22a9ee.tar.gz
5478 - disallow programs without 'data' segments
Now all known discrepancies between C++ and SubX translators are fixed.
If a SubX program builds with C++, it should also build fine with just
SubX.

(If it doesn't build with C++, all bets are off. The self-hosted SubX
translator has negligible error-detection or handling.)
Diffstat (limited to 'subx/028translate.cc')
-rw-r--r--subx/028translate.cc6
1 files changed, 6 insertions, 0 deletions
diff --git a/subx/028translate.cc b/subx/028translate.cc
index 46f4f219..d3a6a8ac 100644
--- a/subx/028translate.cc
+++ b/subx/028translate.cc
@@ -80,10 +80,16 @@ void save_elf(const program& p, const string& filename) {
 }
 
 void save_elf(const program& p, ostream& out) {
+  // validation: stay consistent with the self-hosted translator
   if (p.entry == 0) {
     raise << "no 'Entry' label found\n" << end();
     return;
   }
+  if (find(p, "data") == NULL) {
+    raise << "must include a 'data' segment\n" << end();
+    return;
+  }
+  // processing
   write_elf_header(out, p);
   for (size_t i = 0;  i < p.segments.size();  ++i)
     write_segment(p.segments.at(i), out);