From c8a3ccbeb89221d726542a89b42ddb26827af1f4 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Sat, 27 Jul 2019 18:26:18 -0700 Subject: 5490 --- html/036global_variables.cc.html | 120 +++++++++++++++++++-------------------- 1 file changed, 60 insertions(+), 60 deletions(-) (limited to 'html/036global_variables.cc.html') diff --git a/html/036global_variables.cc.html b/html/036global_variables.cc.html index 427657c8..d36e16de 100644 --- a/html/036global_variables.cc.html +++ b/html/036global_variables.cc.html @@ -2,7 +2,7 @@ -Mu - subx/036global_variables.cc +Mu - 036global_variables.cc @@ -57,7 +57,7 @@ if ('onhashchange' in window) { -https://github.com/akkartik/mu/blob/master/subx/036global_variables.cc +https://github.com/akkartik/mu/blob/master/036global_variables.cc
   1 //: Global variables.
   2 //:
@@ -69,7 +69,7 @@ if ('onhashchange' in window) {
   8 
   9 :(code)
  10 void test_global_variable() {
- 11   run(
+ 11   run(
  12       "== code 0x1\n"
  13       "b9  x/imm32\n"
  14       "== data 0x2000\n"
@@ -82,7 +82,7 @@ if ('onhashchange' in window) {
  21 }
  22 
  23 :(before "End Level-2 Transforms")
- 24 Transform.push_back(rewrite_global_variables);
+ 24 Transform.push_back(rewrite_global_variables);
  25 :(code)
  26 void rewrite_global_variables(program& p) {
  27   trace(3, "transform") << "-- rewrite global variables" << end();
@@ -95,36 +95,36 @@ if ('onhashchange' in window) {
  34 }
  35 
  36 void compute_addresses_for_global_variables(const program& p, map<string, uint32_t>& address) {
- 37   for (int i = 0;  i < SIZE(p.segments);  ++i) {
- 38     if (p.segments.at(i).name != "code")
- 39       compute_addresses_for_global_variables(p.segments.at(i), address);
+ 37   for (int i = 0;  i < SIZE(p.segments);  ++i) {
+ 38     if (p.segments.at(i).name != "code")
+ 39       compute_addresses_for_global_variables(p.segments.at(i), address);
  40   }
  41 }
  42 
  43 void compute_addresses_for_global_variables(const segment& s, map<string, uint32_t>& address) {
  44   int current_address = s.start;
- 45   for (int i = 0;  i < SIZE(s.lines);  ++i) {
- 46     const line& inst = s.lines.at(i);
- 47     for (int j = 0;  j < SIZE(inst.words);  ++j) {
- 48       const word& curr = inst.words.at(j);
+ 45   for (int i = 0;  i < SIZE(s.lines);  ++i) {
+ 46     const line& inst = s.lines.at(i);
+ 47     for (int j = 0;  j < SIZE(inst.words);  ++j) {
+ 48       const word& curr = inst.words.at(j);
  49       if (*curr.data.rbegin() != ':') {
  50         current_address += size_of(curr);
  51       }
  52       else {
- 53         string variable = drop_last(curr.data);
+ 53         string variable = drop_last(curr.data);
  54         // ensure variables look sufficiently different from raw hex
- 55         check_valid_name(variable);
+ 55         check_valid_name(variable);
  56         if (trace_contains_errors()) return;
  57         if (j > 0)
- 58           raise << "'" << to_string(inst) << "': global variable names can only be the first word in a line.\n" << end();
- 59         if (Labels_file.is_open())
- 60           Labels_file << "0x" << HEXWORD << current_address << ' ' << variable << '\n';
- 61         if (contains_key(address, variable)) {
+ 58           raise << "'" << to_string(inst) << "': global variable names can only be the first word in a line.\n" << end();
+ 59         if (Labels_file.is_open())
+ 60           Labels_file << "0x" << HEXWORD << current_address << ' ' << variable << '\n';
+ 61         if (contains_key(address, variable)) {
  62           raise << "duplicate global '" << variable << "'\n" << end();
  63           return;
  64         }
- 65         put(address, variable, current_address);
- 66         trace(99, "transform") << "global variable '" << variable << "' is at address 0x" << HEXWORD << current_address << end();
+ 65         put(address, variable, current_address);
+ 66         trace(99, "transform") << "global variable '" << variable << "' is at address 0x" << HEXWORD << current_address << end();
  67         // no modifying current_address; global variable definitions won't be in the final binary
  68       }
  69     }
@@ -132,17 +132,17 @@ if ('onhashchange' in window) {
  71 }
  72 
  73 void drop_global_variables(program& p) {
- 74   for (int i = 0;  i < SIZE(p.segments);  ++i) {
- 75     if (p.segments.at(i).name != "code")
- 76       drop_labels(p.segments.at(i));
+ 74   for (int i = 0;  i < SIZE(p.segments);  ++i) {
+ 75     if (p.segments.at(i).name != "code")
+ 76       drop_labels(p.segments.at(i));
  77   }
  78 }
  79 
  80 void replace_global_variables_with_addresses(program& p, const map<string, uint32_t>& address) {
- 81   if (p.segments.empty()) return;
- 82   for (int i = 0;  i < SIZE(p.segments);  ++i) {
- 83     segment& curr = p.segments.at(i);
- 84     if (curr.name == "code")
+ 81   if (p.segments.empty()) return;
+ 82   for (int i = 0;  i < SIZE(p.segments);  ++i) {
+ 83     segment& curr = p.segments.at(i);
+ 84     if (curr.name == "code")
  85       replace_global_variables_in_code_segment(curr, address);
  86     else
  87       replace_global_variables_in_data_segment(curr, address);
@@ -150,15 +150,15 @@ if ('onhashchange' in window) {
  89 }
  90 
  91 void replace_global_variables_in_code_segment(segment& code, const map<string, uint32_t>& address) {
- 92   for (int i = 0;  i < SIZE(code.lines);  ++i) {
- 93     line& inst = code.lines.at(i);
- 94     line new_inst;
- 95     for (int j = 0;  j < SIZE(inst.words);  ++j) {
- 96       const word& curr = inst.words.at(j);
+ 92   for (int i = 0;  i < SIZE(code.lines);  ++i) {
+ 93     line& inst = code.lines.at(i);
+ 94     line new_inst;
+ 95     for (int j = 0;  j < SIZE(inst.words);  ++j) {
+ 96       const word& curr = inst.words.at(j);
  97       if (!contains_key(address, curr.data)) {
  98         if (!looks_like_hex_int(curr.data))
  99           raise << "missing reference to global '" << curr.data << "'\n" << end();
-100         new_inst.words.push_back(curr);
+100         new_inst.words.push_back(curr);
 101         continue;
 102       }
 103       if (!valid_use_of_global_variable(curr)) {
@@ -167,19 +167,19 @@ if ('onhashchange' in window) {
 106       }
 107       emit_hex_bytes(new_inst, get(address, curr.data), 4);
 108     }
-109     inst.words.swap(new_inst.words);
+109     inst.words.swap(new_inst.words);
 110     trace(99, "transform") << "instruction after transform: '" << data_to_string(inst) << "'" << end();
 111   }
 112 }
 113 
 114 void replace_global_variables_in_data_segment(segment& data, const map<string, uint32_t>& address) {
-115   for (int i = 0;  i < SIZE(data.lines);  ++i) {
-116     line& l = data.lines.at(i);
-117     line new_l;
-118     for (int j = 0;  j < SIZE(l.words);  ++j) {
-119       const word& curr = l.words.at(j);
+115   for (int i = 0;  i < SIZE(data.lines);  ++i) {
+116     line& l = data.lines.at(i);
+117     line new_l;
+118     for (int j = 0;  j < SIZE(l.words);  ++j) {
+119       const word& curr = l.words.at(j);
 120       if (!contains_key(address, curr.data)) {
-121         if (looks_like_hex_int(curr.data)) {
+121         if (looks_like_hex_int(curr.data)) {
 122           if (has_operand_metadata(curr, "imm32"))
 123             emit_hex_bytes(new_l, curr, 4);
 124           else if (has_operand_metadata(curr, "imm16"))
@@ -193,18 +193,18 @@ if ('onhashchange' in window) {
 132           else if (has_operand_metadata(curr, "disp32"))
 133             raise << "can't use /disp32 in a non-code segment\n" << end();
 134           else
-135             new_l.words.push_back(curr);
+135             new_l.words.push_back(curr);
 136         }
 137         else {
 138           raise << "missing reference to global '" << curr.data << "'\n" << end();
-139           new_l.words.push_back(curr);
+139           new_l.words.push_back(curr);
 140         }
 141         continue;
 142       }
-143       trace(99, "transform") << curr.data << " maps to " << HEXWORD << get(address, curr.data) << end();
+143       trace(99, "transform") << curr.data << " maps to " << HEXWORD << get(address, curr.data) << end();
 144       emit_hex_bytes(new_l, get(address, curr.data), 4);
 145     }
-146     l.words.swap(new_l.words);
+146     l.words.swap(new_l.words);
 147     trace(99, "transform") << "after transform: '" << data_to_string(l) << "'" << end();
 148   }
 149 }
@@ -219,15 +219,15 @@ if ('onhashchange' in window) {
 158 //: requires first saving some data early before we pack operands
 159 
 160 :(after "Begin Level-2 Transforms")
-161 Transform.push_back(correlate_disp32_with_mod);
+161 Transform.push_back(correlate_disp32_with_mod);
 162 :(code)
 163 void correlate_disp32_with_mod(program& p) {
-164   if (p.segments.empty()) return;
+164   if (p.segments.empty()) return;
 165   segment& code = *find(p, "code");
-166   for (int i = 0;  i < SIZE(code.lines);  ++i) {
-167     line& inst = code.lines.at(i);
-168     for (int j = 0;  j < SIZE(inst.words);  ++j) {
-169       word& curr = inst.words.at(j);
+166   for (int i = 0;  i < SIZE(code.lines);  ++i) {
+167     line& inst = code.lines.at(i);
+168     for (int j = 0;  j < SIZE(inst.words);  ++j) {
+169       word& curr = inst.words.at(j);
 170       if (has_operand_metadata(curr, "disp32")
 171           && has_operand_metadata(inst, "mod"))
 172         curr.metadata.push_back("has_mod");
@@ -243,14 +243,14 @@ if ('onhashchange' in window) {
 182 
 183 :(code)
 184 bool has_metadata(const word& w, const string& m) {
-185   for (int i = 0;  i < SIZE(w.metadata);  ++i)
+185   for (int i = 0;  i < SIZE(w.metadata);  ++i)
 186     if (w.metadata.at(i) == m) return true;
 187   return false;
 188 }
 189 
 190 void test_global_variable_disallowed_in_jump() {
 191   Hide_errors = true;
-192   run(
+192   run(
 193       "== code 0x1\n"
 194       "eb/jump  x/disp8\n"
 195       "== data 0x2000\n"
@@ -266,7 +266,7 @@ if ('onhashchange' in window) {
 205 
 206 void test_global_variable_disallowed_in_call() {
 207   Hide_errors = true;
-208   run(
+208   run(
 209       "== code 0x1\n"
 210       "e8/call  x/disp32\n"
 211       "== data 0x2000\n"
@@ -281,7 +281,7 @@ if ('onhashchange' in window) {
 220 }
 221 
 222 void test_global_variable_in_data_segment() {
-223   run(
+223   run(
 224       "== code 0x1\n"
 225       "b9  x/imm32\n"
 226       "== data 0x2000\n"
@@ -301,7 +301,7 @@ if ('onhashchange' in window) {
 240 }
 241 
 242 void test_raw_number_with_imm32_in_data_segment() {
-243   run(
+243   run(
 244       "== code 0x1\n"
 245       "b9  x/imm32\n"
 246       "== data 0x2000\n"
@@ -320,7 +320,7 @@ if ('onhashchange' in window) {
 259 
 260 void test_duplicate_global_variable() {
 261   Hide_errors = true;
-262   run(
+262   run(
 263       "== code 0x1\n"
 264       "40/increment-EAX\n"
 265       "== data 0x2000\n"
@@ -334,7 +334,7 @@ if ('onhashchange' in window) {
 273 }
 274 
 275 void test_global_variable_disp32_with_modrm() {
-276   run(
+276   run(
 277       "== code 0x1\n"
 278       "8b/copy 0/mod/indirect 5/rm32/.disp32 2/r32/EDX x/disp32\n"
 279       "== data 0x2000\n"
@@ -356,11 +356,11 @@ if ('onhashchange' in window) {
 295 
 296 string to_full_string(const line& in) {
 297   ostringstream out;
-298   for (int i = 0;  i < SIZE(in.words);  ++i) {
+298   for (int i = 0;  i < SIZE(in.words);  ++i) {
 299     if (i > 0) out << ' ';
-300     out << in.words.at(i).data;
-301     for (int j = 0;  j < SIZE(in.words.at(i).metadata);  ++j)
-302       out << '/' << in.words.at(i).metadata.at(j);
+300     out << in.words.at(i).data;
+301     for (int j = 0;  j < SIZE(in.words.at(i).metadata);  ++j)
+302       out << '/' << in.words.at(i).metadata.at(j);
 303   }
 304   return out.str();
 305 }
-- 
cgit 1.4.1-2-gfad0