about summary refs log tree commit diff stats
path: root/subx/011run.cc
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-07-25 10:40:27 -0700
committerKartik Agaram <vc@akkartik.com>2019-07-25 10:40:27 -0700
commitef52bbf908f4cba70fa95b54a32d28035fda545c (patch)
tree760b0954928e9949f6d326183437a7e58d2782bc /subx/011run.cc
parent8bc689672480339f6975c94fcce120a46a8fa7df (diff)
downloadmu-ef52bbf908f4cba70fa95b54a32d28035fda545c.tar.gz
5472 - disallow programs without `Entry` labels
This makes the C++ translator more consistent with the self-hosted
translator.

We go through some contortions to continue supporting unit tests without
'Entry' labels. But we still want to throw good errors when translating
.subx files at the commandline.
Diffstat (limited to 'subx/011run.cc')
-rw-r--r--subx/011run.cc12
1 files changed, 8 insertions, 4 deletions
diff --git a/subx/011run.cc b/subx/011run.cc
index 4c53d781..d9877c4d 100644
--- a/subx/011run.cc
+++ b/subx/011run.cc
@@ -16,8 +16,8 @@ put_new(Help, "syntax",
   "the segment and a (sometimes approximate) starting address in memory.\n"
   "The name 'code' is special; instructions to execute should always go here.\n"
   "\n"
-  "The resulting binary starts running from the start of the segment by default.\n"
-  "To start elsewhere in the code segment, define a special label called 'Entry'.\n"
+  "The resulting binary starts running code from a label called 'Entry'\n"
+  "in the code segment.\n"
   "\n"
   "Segments with the same name get merged together. This rule helps keep functions and\n"
   "their data close together in .subx files.\n"
@@ -91,6 +91,10 @@ void run(const string& text_bytes) {
   if (trace_contains_errors()) return;
   load(p);
   if (trace_contains_errors()) return;
+  if (p.entry)
+    EIP = p.entry;
+  else
+    EIP = find(p, "code")->start;  // just in unit tests
   while (EIP < End_of_program)
     run_one_instruction();
 }
@@ -99,7 +103,9 @@ void run(const string& text_bytes) {
 
 :(before "End Types")
 struct program {
+  uint32_t entry;
   vector<segment> segments;
+  program() { entry = 0; }
 };
 :(before "struct program")
 struct segment {
@@ -281,8 +287,6 @@ void load(const program& p) {
     }
     if (seg.name == "code") {
       End_of_program = addr;
-      EIP = seg.start;
-      // End Initialize EIP
     }
   }
 }