From cb7b403210f13e721739d58dab9000ec51ed2d0a Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Mon, 25 Feb 2019 00:26:48 -0800 Subject: 4989 --- html/subx/035labels.cc.html | 48 ++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'html/subx/035labels.cc.html') diff --git a/html/subx/035labels.cc.html b/html/subx/035labels.cc.html index 5056247f..62856945 100644 --- a/html/subx/035labels.cc.html +++ b/html/subx/035labels.cc.html @@ -88,8 +88,8 @@ if ('onhashchange' in window) { 26 05 0x0d0c0b0a/imm32 27 Entry: 28 05 0x0d0c0b0a/imm32 - 29 +run: inst: 0x00000006 - 30 -run: inst: 0x00000001 + 29 +run: 0x00000006 opcode: 05 + 30 -run: 0x00000001 opcode: 05 31 32 :(before "End Globals") 33 uint32_t Entry_address = 0; @@ -132,19 +132,19 @@ if ('onhashchange' in window) { 70 :(code) 71 void check_valid_name(const string& s) { 72 if (s.empty()) { - 73 raise << "empty name!\n" << end(); + 73 raise << "empty name!\n" << end(); 74 return; 75 } 76 if (s.at(0) == '-') - 77 raise << "'" << s << "' starts with '-', which can be confused with a negative number; use a different name\n" << end(); + 77 raise << "'" << s << "' starts with '-', which can be confused with a negative number; use a different name\n" << end(); 78 if (s.substr(0, 2) == "0x") { - 79 raise << "'" << s << "' looks like a hex number; use a different name\n" << end(); + 79 raise << "'" << s << "' looks like a hex number; use a different name\n" << end(); 80 return; 81 } 82 if (isdigit(s.at(0))) - 83 raise << "'" << s << "' starts with a digit, and so can be confused with a negative number; use a different name.\n" << end(); + 83 raise << "'" << s << "' starts with a digit, and so can be confused with a negative number; use a different name.\n" << end(); 84 if (SIZE(s) == 2) - 85 raise << "'" << s << "' is two characters long which can look like raw hex bytes at a glance; use a different name\n" << end(); + 85 raise << "'" << s << "' is two characters long which can look like raw hex bytes at a glance; use a different name\n" << end(); 86 } 87 88 //: Now that that's done, let's start using names as labels. @@ -156,17 +156,17 @@ if ('onhashchange' in window) { 94 +transform: label 'loop' is at address 1 95 96 :(before "End Level-2 Transforms") - 97 Transform.push_back(rewrite_labels); + 97 Transform.push_back(rewrite_labels); 98 :(code) 99 void rewrite_labels(program& p) { -100 trace(99, "transform") << "-- rewrite labels" << end(); +100 trace(3, "transform") << "-- rewrite labels" << end(); 101 if (p.segments.empty()) return; 102 segment& code = p.segments.at(0); 103 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 104 compute_byte_indices_for_labels(code, byte_index); -105 if (trace_contains_errors()) return; +105 if (trace_contains_errors()) return; 106 drop_labels(code); -107 if (trace_contains_errors()) return; +107 if (trace_contains_errors()) return; 108 replace_labels_with_displacements(code, byte_index); 109 if (contains_key(byte_index, "Entry")) 110 Entry_address = code.start + get(byte_index, "Entry"); @@ -185,12 +185,12 @@ if ('onhashchange' in window) { 123 // have to deal with bitfields. 124 if (has_operand_metadata(curr, "disp32") || has_operand_metadata(curr, "imm32")) { 125 if (*curr.data.rbegin() == ':') -126 raise << "'" << to_string(inst) << "': don't use ':' when jumping to labels\n" << end(); +126 raise << "'" << to_string(inst) << "': don't use ':' when jumping to labels\n" << end(); 127 current_byte += 4; 128 } 129 else if (has_operand_metadata(curr, "disp16")) { 130 if (*curr.data.rbegin() == ':') -131 raise << "'" << to_string(inst) << "': don't use ':' when jumping to labels\n" << end(); +131 raise << "'" << to_string(inst) << "': don't use ':' when jumping to labels\n" << end(); 132 current_byte += 2; 133 } 134 // automatically handle /disp8 and /imm8 here @@ -201,19 +201,19 @@ if ('onhashchange' in window) { 139 string label = drop_last(curr.data); 140 // ensure labels look sufficiently different from raw hex 141 check_valid_name(label); -142 if (trace_contains_errors()) return; +142 if (trace_contains_errors()) return; 143 if (contains_any_operand_metadata(curr)) -144 raise << "'" << to_string(inst) << "': label definition (':') not allowed in operand\n" << end(); +144 raise << "'" << to_string(inst) << "': label definition (':') not allowed in operand\n" << end(); 145 if (j > 0) -146 raise << "'" << to_string(inst) << "': labels can only be the first word in a line.\n" << end(); +146 raise << "'" << to_string(inst) << "': labels can only be the first word in a line.\n" << end(); 147 if (Map_file.is_open()) -148 Map_file << "0x" << HEXWORD << (code.start + current_byte) << ' ' << label << '\n'; +148 Map_file << "0x" << HEXWORD << (code.start + current_byte) << ' ' << label << '\n'; 149 if (contains_key(byte_index, label) && label != "Entry") { -150 raise << "duplicate label '" << label << "'\n" << end(); +150 raise << "duplicate label '" << label << "'\n" << end(); 151 return; 152 } 153 put(byte_index, label, current_byte); -154 trace(99, "transform") << "label '" << label << "' is at address " << (current_byte+code.start) << end(); +154 trace(99, "transform") << "label '" << label << "' is at address " << (current_byte+code.start) << end(); 155 // no modifying current_byte; label definitions won't be in the final binary 156 } 157 } @@ -261,13 +261,13 @@ if ('onhashchange' in window) { 199 int32_t displacement = static_cast<int32_t>(get(byte_index, curr.data)) - byte_index_next_instruction_starts_at; 200 if (has_operand_metadata(curr, "disp8")) { 201 if (displacement > 0xff || displacement < -0x7f) -202 raise << "'" << to_string(inst) << "': label too far away for displacement " << std::hex << displacement << " to fit in 8 bits\n" << end(); +202 raise << "'" << to_string(inst) << "': label too far away for displacement " << std::hex << displacement << " to fit in 8 bits\n" << end(); 203 else 204 emit_hex_bytes(new_inst, displacement, 1); 205 } 206 else if (has_operand_metadata(curr, "disp16")) { 207 if (displacement > 0xffff || displacement < -0x7fff) -208 raise << "'" << to_string(inst) << "': label too far away for displacement " << std::hex << displacement << " to fit in 16 bits\n" << end(); +208 raise << "'" << to_string(inst) << "': label too far away for displacement " << std::hex << displacement << " to fit in 16 bits\n" << end(); 209 else 210 emit_hex_bytes(new_inst, displacement, 2); 211 } @@ -280,7 +280,7 @@ if ('onhashchange' in window) { 218 } 219 } 220 inst.words.swap(new_inst.words); -221 trace(99, "transform") << "instruction after transform: '" << data_to_string(inst) << "'" << end(); +221 trace(99, "transform") << "instruction after transform: '" << data_to_string(inst) << "'" << end(); 222 } 223 } 224 @@ -320,9 +320,9 @@ if ('onhashchange' in window) { 258 +transform: label '$loop2' is at address 1 259 +transform: label '$loop3' is at address a 260 # first jump is to -7 -261 +transform: instruction after transform: 'eb f9' +261 +transform: instruction after transform: 'eb f9' 262 # second jump is to 0 (fall through) -263 +transform: instruction after transform: 'eb 00' +263 +transform: instruction after transform: 'eb 00' 264 265 :(scenario duplicate_label) 266 % Hide_errors = true; -- cgit 1.4.1-2-gfad0