about summary refs log tree commit diff stats
path: root/subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2018-08-04 15:54:51 -0700
committerKartik Agaram <vc@akkartik.com>2018-08-04 15:54:51 -0700
commit55b4627de1fcdd5f139994759d0929515204b6d8 (patch)
tree6b4f2d70134134dd187b9a1f17c51ca179ea2b0f /subx
parenta2001d15a1a6a5a726dbe6b2b88d3f72d5d5e391 (diff)
downloadmu-55b4627de1fcdd5f139994759d0929515204b6d8.tar.gz
4473
Better organize registration of transforms in main().
Diffstat (limited to 'subx')
-rw-r--r--subx/029translate.cc41
-rw-r--r--subx/030check_operands.cc2
-rw-r--r--subx/031check_operand_bounds.cc2
-rw-r--r--subx/032pack_operands.cc2
-rw-r--r--subx/033non_code_segment.cc2
-rw-r--r--subx/034labels.cc2
6 files changed, 27 insertions, 24 deletions
diff --git a/subx/029translate.cc b/subx/029translate.cc
index 166762d9..1d5e940e 100644
--- a/subx/029translate.cc
+++ b/subx/029translate.cc
@@ -16,6 +16,25 @@
 //:
 //: Higher levels usually transform code on the basis of metadata.
 
+:(before "End Main")
+if (is_equal(argv[1], "translate")) {
+  START_TRACING_UNTIL_END_OF_SCOPE;
+  assert(argc > 3);
+  program p;
+  ifstream fin(argv[2]);
+  if (!fin) {
+    cerr << "could not open " << argv[2] << '\n';
+    return 1;
+  }
+  parse(fin, p);
+  if (trace_contains_errors()) return 1;
+  transform(p);
+  if (trace_contains_errors()) return 1;
+  save_elf(p, argv[3]);
+  if (trace_contains_errors()) unlink(argv[3]);
+  return 0;
+}
+
 //: Ordering transforms is a well-known hard problem when building compilers.
 //: In our case we also have the additional notion of layers. The ordering of
 //: layers can have nothing in common with the ordering of transforms when
@@ -77,25 +96,9 @@
 //: goals are basically to always have a working program after any layer, to
 //: have the order of layers make narrative sense, and to order transforms
 //: correctly at runtime.
-
-:(before "End Main")
-if (is_equal(argv[1], "translate")) {
-  START_TRACING_UNTIL_END_OF_SCOPE;
-  assert(argc > 3);
-  program p;
-  ifstream fin(argv[2]);
-  if (!fin) {
-    cerr << "could not open " << argv[2] << '\n';
-    return 1;
-  }
-  parse(fin, p);
-  if (trace_contains_errors()) return 1;
-  transform(p);
-  if (trace_contains_errors()) return 1;
-  save_elf(p, argv[3]);
-  if (trace_contains_errors()) unlink(argv[3]);
-  return 0;
-}
+:(before "End One-time Setup")
+// Begin Transforms
+// End Transforms
 
 :(code)
 // write out a program to a bare-bones ELF file
diff --git a/subx/030check_operands.cc b/subx/030check_operands.cc
index 2b253ab6..0a233272 100644
--- a/subx/030check_operands.cc
+++ b/subx/030check_operands.cc
@@ -58,7 +58,7 @@ cerr << "  instructions\n";
   cd                                                                                                                                                # int ??
 +error: 'cd' (software interrupt): missing imm8 operand
 
-:(before "End One-time Setup")
+:(before "End Transforms")
 Transform.push_back(check_operands);
 
 :(code)
diff --git a/subx/031check_operand_bounds.cc b/subx/031check_operand_bounds.cc
index cca4ab24..f72451a0 100644
--- a/subx/031check_operand_bounds.cc
+++ b/subx/031check_operand_bounds.cc
@@ -22,7 +22,7 @@ put(Operand_bound, "disp16", 1<<16);
 put(Operand_bound, "imm8", 1<<8);
 // no bound needed for imm32
 
-:(before "End One-time Setup")
+:(before "End Transforms")
 Transform.push_back(check_operand_bounds);
 :(code)
 void check_operand_bounds(/*const*/ program& p) {
diff --git a/subx/032pack_operands.cc b/subx/032pack_operands.cc
index f8effd16..675d38fc 100644
--- a/subx/032pack_operands.cc
+++ b/subx/032pack_operands.cc
@@ -41,7 +41,7 @@ b9 0x080490a7/imm32  # copy to ECX
 +transform: packing instruction 'b9 0x080490a7/imm32'
 +transform: instruction after packing: 'b9 a7 90 04 08'
 
-:(before "End One-time Setup")
+:(before "End Transforms")
 Transform.push_back(pack_operands);
 
 :(code)
diff --git a/subx/033non_code_segment.cc b/subx/033non_code_segment.cc
index 5006e9a1..720eefc2 100644
--- a/subx/033non_code_segment.cc
+++ b/subx/033non_code_segment.cc
@@ -8,7 +8,7 @@ cd 0x80/imm8
 cd 12/imm8
 +error: 12/imm8: metadata imm8 is only allowed in the (first) code segment
 
-:(before "End One-time Setup")
+:(before "End Transforms")
 Transform.push_back(ensure_operands_only_in_code_segments);
 :(code)
 void ensure_operands_only_in_code_segments(/*const*/ program& p) {
diff --git a/subx/034labels.cc b/subx/034labels.cc
index 78190c6d..1bbf9b5b 100644
--- a/subx/034labels.cc
+++ b/subx/034labels.cc
@@ -11,7 +11,7 @@ loop:
             05                                                                                                                              0x0d0c0b0a/imm32  # add to EAX
 +transform: label 'loop' is at address 1
 
-:(before "End One-time Setup")
+:(before "End Transforms")
 Transform.push_back(rewrite_labels);
 
 :(code)