From c504ca566124d1f097e7fe8a2f9f67c1c59e9ccf Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Tue, 14 Jan 2020 01:48:06 -0800 Subject: 5893 --- html/036labels.cc.html | 80 +++++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 40 deletions(-) (limited to 'html/036labels.cc.html') diff --git a/html/036labels.cc.html b/html/036labels.cc.html index ccf0ae1a..96657216 100644 --- a/html/036labels.cc.html +++ b/html/036labels.cc.html @@ -84,7 +84,7 @@ if ('onhashchange' in window) { 25 //: programs. 26 27 void test_Entry_label() { - 28 run( + 28 run( 29 "== code 0x1\n" 30 "05 0x0d0c0b0a/imm32\n" 31 "Entry:\n" @@ -96,8 +96,8 @@ if ('onhashchange' in window) { 37 CHECK_TRACE_DOESNT_CONTAIN("run: 0x00000001 opcode: 05"); 38 } 39 - 40 :(before "End looks_like_hex_int(s) Detectors") - 41 if (SIZE(s) == 2) return true; + 40 :(before "End looks_like_hex_int(s) Detectors") + 41 if (SIZE(s) == 2) return true; 42 43 :(code) 44 void test_pack_immediate_ignores_single_byte_nondigit_operand() { @@ -153,7 +153,7 @@ if ('onhashchange' in window) { 94 } 95 if (isdigit(s.at(0))) 96 raise << "'" << s << "' starts with a digit, and so can be confused with a number; use a different name.\n" << end(); - 97 if (SIZE(s) == 2) + 97 if (SIZE(s) == 2) 98 raise << "'" << s << "' is two characters long, which can look like raw hex bytes at a glance; use a different name\n" << end(); 99 } 100 @@ -170,12 +170,12 @@ if ('onhashchange' in window) { 111 ); 112 } 113 -114 :(before "End Level-2 Transforms") -115 Transform.push_back(rewrite_labels); +114 :(before "End Transforms") +115 Transform.push_back(rewrite_labels); 116 :(code) 117 void rewrite_labels(program& p) { 118 trace(3, "transform") << "-- rewrite labels" << end(); -119 if (p.segments.empty()) return; +119 if (p.segments.empty()) return; 120 segment& code = *find(p, "code"); 121 map<string, int32_t> byte_index; // values are unsigned, but we're going to do subtractions on them so they need to fit in 31 bits 122 compute_byte_indices_for_labels(code, byte_index); @@ -183,18 +183,18 @@ if ('onhashchange' in window) { 124 drop_labels(code); 125 if (trace_contains_errors()) return; 126 replace_labels_with_displacements(code, byte_index); -127 if (contains_key(byte_index, "Entry")) -128 p.entry = code.start + get(byte_index, "Entry"); +127 if (contains_key(byte_index, "Entry")) +128 p.entry = code.start + get(byte_index, "Entry"); 129 } 130 131 void compute_byte_indices_for_labels(const segment& code, map<string, int32_t>& byte_index) { 132 int current_byte = 0; -133 for (int i = 0; i < SIZE(code.lines); ++i) { -134 const line& inst = code.lines.at(i); -135 if (Source_lines_file.is_open() && !inst.original.empty() && /*not a label*/ *inst.words.at(0).data.rbegin() != ':') -136 Source_lines_file << "0x" << HEXWORD << (code.start + current_byte) << ' ' << inst.original << '\n'; -137 for (int j = 0; j < SIZE(inst.words); ++j) { -138 const word& curr = inst.words.at(j); +133 for (int i = 0; i < SIZE(code.lines); ++i) { +134 const line& inst = code.lines.at(i); +135 if (Source_lines_file.is_open() && !inst.original.empty() && /*not a label*/ *inst.words.at(0).data.rbegin() != ':') +136 Source_lines_file << "0x" << HEXWORD << (code.start + current_byte) << ' ' << inst.original << '\n'; +137 for (int j = 0; j < SIZE(inst.words); ++j) { +138 const word& curr = inst.words.at(j); 139 // hack: if we have any operand metadata left after previous transforms, 140 // deduce its size 141 // Maybe we should just move this transform to before instruction @@ -219,17 +219,17 @@ if ('onhashchange' in window) { 160 // ensure labels look sufficiently different from raw hex 161 check_valid_name(label); 162 if (trace_contains_errors()) return; -163 if (contains_any_operand_metadata(curr)) +163 if (contains_any_operand_metadata(curr)) 164 raise << "'" << to_string(inst) << "': label definition (':') not allowed in operand\n" << end(); 165 if (j > 0) -166 raise << "'" << to_string(inst) << "': labels can only be the first word in a line.\n" << end(); +166 raise << "'" << to_string(inst) << "': labels can only be the first word in a line.\n" << end(); 167 if (Labels_file.is_open()) -168 Labels_file << "0x" << HEXWORD << (code.start + current_byte) << ' ' << label << '\n'; -169 if (contains_key(byte_index, label) && label != "Entry") { +168 Labels_file << "0x" << HEXWORD << (code.start + current_byte) << ' ' << label << '\n'; +169 if (contains_key(byte_index, label) && label != "Entry") { 170 raise << "duplicate label '" << label << "'\n" << end(); 171 return; 172 } -173 put(byte_index, label, current_byte); +173 put(byte_index, label, current_byte); 174 trace(99, "transform") << "label '" << label << "' is at address " << (current_byte+code.start) << end(); 175 // no modifying current_byte; label definitions won't be in the final binary 176 } @@ -238,23 +238,23 @@ if ('onhashchange' in window) { 179 } 180 181 :(before "End Globals") -182 bool Dump_debug_info = false; // currently used only by 'subx translate' +182 bool Dump_debug_info = false; // currently used only by 'bootstrap translate' 183 ofstream Labels_file; 184 ofstream Source_lines_file; 185 :(before "End Commandline Options") -186 else if (is_equal(*arg, "--debug")) { +186 else if (is_equal(*arg, "--debug")) { 187 Dump_debug_info = true; 188 // End --debug Settings 189 } 190 //: wait to open "labels" for writing until we're sure we aren't trying to read it -191 :(after "Begin subx translate") +191 :(after "Begin bootstrap translate") 192 if (Dump_debug_info) { 193 cerr << "saving address->label information to 'labels'\n"; 194 Labels_file.open("labels"); 195 cerr << "saving address->source information to 'source_lines'\n"; 196 Source_lines_file.open("source_lines"); 197 } -198 :(before "End subx translate") +198 :(before "End bootstrap translate") 199 if (Dump_debug_info) { 200 Labels_file.close(); 201 Source_lines_file.close(); @@ -262,10 +262,10 @@ if ('onhashchange' in window) { 203 204 :(code) 205 void drop_labels(segment& code) { -206 for (int i = 0; i < SIZE(code.lines); ++i) { -207 line& inst = code.lines.at(i); -208 vector<word>::iterator new_end = remove_if(inst.words.begin(), inst.words.end(), is_label); -209 inst.words.erase(new_end, inst.words.end()); +206 for (int i = 0; i < SIZE(code.lines); ++i) { +207 line& inst = code.lines.at(i); +208 vector<word>::iterator new_end = remove_if(inst.words.begin(), inst.words.end(), is_label); +209 inst.words.erase(new_end, inst.words.end()); 210 } 211 } 212 @@ -275,13 +275,13 @@ if ('onhashchange' in window) { 216 217 void replace_labels_with_displacements(segment& code, const map<string, int32_t>& byte_index) { 218 int32_t byte_index_next_instruction_starts_at = 0; -219 for (int i = 0; i < SIZE(code.lines); ++i) { -220 line& inst = code.lines.at(i); +219 for (int i = 0; i < SIZE(code.lines); ++i) { +220 line& inst = code.lines.at(i); 221 byte_index_next_instruction_starts_at += num_bytes(inst); -222 line new_inst; -223 for (int j = 0; j < SIZE(inst.words); ++j) { -224 const word& curr = inst.words.at(j); -225 if (contains_key(byte_index, curr.data)) { +222 line new_inst; +223 for (int j = 0; j < SIZE(inst.words); ++j) { +224 const word& curr = inst.words.at(j); +225 if (contains_key(byte_index, curr.data)) { 226 int32_t displacement = static_cast<int32_t>(get(byte_index, curr.data)) - byte_index_next_instruction_starts_at; 227 if (has_operand_metadata(curr, "disp8")) { 228 if (displacement > 0x7f || displacement < -0x7f) @@ -302,19 +302,19 @@ if ('onhashchange' in window) { 243 } 244 } 245 else { -246 new_inst.words.push_back(curr); +246 new_inst.words.push_back(curr); 247 } 248 } -249 inst.words.swap(new_inst.words); +249 inst.words.swap(new_inst.words); 250 trace(99, "transform") << "instruction after transform: '" << data_to_string(inst) << "'" << end(); 251 } 252 } 253 254 string data_to_string(const line& inst) { 255 ostringstream out; -256 for (int i = 0; i < SIZE(inst.words); ++i) { +256 for (int i = 0; i < SIZE(inst.words); ++i) { 257 if (i > 0) out << ' '; -258 out << inst.words.at(i).data; +258 out << inst.words.at(i).data; 259 } 260 return out.str(); 261 } @@ -432,7 +432,7 @@ if ('onhashchange' in window) { 373 } 374 375 // This test could do with some refactoring. -376 // We're duplicating the flow inside `subx translate`, but without +376 // We're duplicating the flow inside `bootstrap translate`, but without 377 // reading/writing files. 378 // We can't just use run(string) because most of our tests allow programs 379 // without 'Entry' labels, as a convenience. @@ -470,7 +470,7 @@ if ('onhashchange' in window) { 411 ); 412 } 413 -414 :(before "End size_of(word w) Special-cases") +414 :(before "End size_of(word w) Special-cases") 415 else if (is_label(w)) 416 return 0; -- cgit 1.4.1-2-gfad0