From cdfff1a18d2203b8493f8700ab694c1c05ef6161 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Sun, 16 Dec 2018 20:52:47 -0800 Subject: 4869 --- html/subx/035labels.cc.html | 56 ++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'html/subx/035labels.cc.html') diff --git a/html/subx/035labels.cc.html b/html/subx/035labels.cc.html index 6c5f4220..3185ffff 100644 --- a/html/subx/035labels.cc.html +++ b/html/subx/035labels.cc.html @@ -85,7 +85,7 @@ if ('onhashchange' in window) { 20 //: the above rules will remain inviolate. 21 22 :(before "End looks_like_hex_int(s) Detectors") - 23 if (SIZE(s) == 2) return true; + 23 if (SIZE(s) == 2) return true; 24 25 :(scenarios transform) 26 :(scenario pack_immediate_ignores_single_byte_nondigit_operand) @@ -116,19 +116,19 @@ if ('onhashchange' in window) { 51 :(code) 52 void check_valid_name(const string& s) { 53 if (s.empty()) { - 54 raise << "empty name!\n" << end(); + 54 raise << "empty name!\n" << end(); 55 return; 56 } 57 if (s.at(0) == '-') - 58 raise << "'" << s << "' starts with '-', which can be confused with a negative number; use a different name\n" << end(); + 58 raise << "'" << s << "' starts with '-', which can be confused with a negative number; use a different name\n" << end(); 59 if (s.substr(0, 2) == "0x") { - 60 raise << "'" << s << "' looks like a hex number; use a different name\n" << end(); + 60 raise << "'" << s << "' looks like a hex number; use a different name\n" << end(); 61 return; 62 } 63 if (isdigit(s.at(0))) - 64 raise << "'" << s << "' starts with a digit, and so can be confused with a negative number; use a different name.\n" << end(); - 65 if (SIZE(s) == 2) - 66 raise << "'" << s << "' is two characters long which can look like raw hex bytes at a glance; use a different name\n" << end(); + 64 raise << "'" << s << "' starts with a digit, and so can be confused with a negative number; use a different name.\n" << end(); + 65 if (SIZE(s) == 2) + 66 raise << "'" << s << "' is two characters long which can look like raw hex bytes at a glance; use a different name\n" << end(); 67 } 68 69 //: Now that that's done, let's start using names as labels. @@ -143,22 +143,22 @@ if ('onhashchange' in window) { 78 Transform.push_back(rewrite_labels); 79 :(code) 80 void rewrite_labels(program& p) { - 81 trace(99, "transform") << "-- rewrite labels" << end(); + 81 trace(99, "transform") << "-- rewrite labels" << end(); 82 if (p.segments.empty()) return; 83 segment& code = p.segments.at(0); 84 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 85 compute_byte_indices_for_labels(code, byte_index); - 86 if (trace_contains_errors()) return; + 86 if (trace_contains_errors()) return; 87 drop_labels(code); - 88 if (trace_contains_errors()) return; + 88 if (trace_contains_errors()) return; 89 replace_labels_with_displacements(code, byte_index); 90 } 91 92 void compute_byte_indices_for_labels(const segment& code, map<string, int32_t>& byte_index) { 93 int current_byte = 0; - 94 for (int i = 0; i < SIZE(code.lines); ++i) { + 94 for (int i = 0; i < SIZE(code.lines); ++i) { 95 const line& inst = code.lines.at(i); - 96 for (int j = 0; j < SIZE(inst.words); ++j) { + 96 for (int j = 0; j < SIZE(inst.words); ++j) { 97 const word& curr = inst.words.at(j); 98 // hack: if we have any operand metadata left after previous transforms, 99 // deduce its size @@ -167,12 +167,12 @@ if ('onhashchange' in window) { 102 // have to deal with bitfields. 103 if (has_operand_metadata(curr, "disp32") || has_operand_metadata(curr, "imm32")) { 104 if (*curr.data.rbegin() == ':') -105 raise << "'" << to_string(inst) << "': don't use ':' when jumping to labels\n" << end(); +105 raise << "'" << to_string(inst) << "': don't use ':' when jumping to labels\n" << end(); 106 current_byte += 4; 107 } 108 else if (has_operand_metadata(curr, "disp16")) { 109 if (*curr.data.rbegin() == ':') -110 raise << "'" << to_string(inst) << "': don't use ':' when jumping to labels\n" << end(); +110 raise << "'" << to_string(inst) << "': don't use ':' when jumping to labels\n" << end(); 111 current_byte += 2; 112 } 113 // automatically handle /disp8 and /imm8 here @@ -183,15 +183,15 @@ if ('onhashchange' in window) { 118 string label = drop_last(curr.data); 119 // ensure labels look sufficiently different from raw hex 120 check_valid_name(label); -121 if (trace_contains_errors()) return; +121 if (trace_contains_errors()) return; 122 if (contains_any_operand_metadata(curr)) -123 raise << "'" << to_string(inst) << "': label definition (':') not allowed in operand\n" << end(); +123 raise << "'" << to_string(inst) << "': label definition (':') not allowed in operand\n" << end(); 124 if (j > 0) -125 raise << "'" << to_string(inst) << "': labels can only be the first word in a line.\n" << end(); +125 raise << "'" << to_string(inst) << "': labels can only be the first word in a line.\n" << end(); 126 if (Map_file.is_open()) 127 Map_file << "0x" << HEXWORD << (code.start + current_byte) << ' ' << label << '\n'; -128 put(byte_index, label, current_byte); -129 trace(99, "transform") << "label '" << label << "' is at address " << (current_byte+code.start) << end(); +128 put(byte_index, label, current_byte); +129 trace(99, "transform") << "label '" << label << "' is at address " << (current_byte+code.start) << end(); 130 // no modifying current_byte; label definitions won't be in the final binary 131 } 132 } @@ -202,7 +202,7 @@ if ('onhashchange' in window) { 137 bool Dump_map = false; // currently used only by 'subx translate' 138 ofstream Map_file; 139 :(before "End Commandline Options") -140 else if (is_equal(*arg, "--map")) { +140 else if (is_equal(*arg, "--map")) { 141 Dump_map = true; 142 // End --map Settings 143 } @@ -216,7 +216,7 @@ if ('onhashchange' in window) { 151 152 :(code) 153 void drop_labels(segment& code) { -154 for (int i = 0; i < SIZE(code.lines); ++i) { +154 for (int i = 0; i < SIZE(code.lines); ++i) { 155 line& inst = code.lines.at(i); 156 vector<word>::iterator new_end = remove_if(inst.words.begin(), inst.words.end(), is_label); 157 inst.words.erase(new_end, inst.words.end()); @@ -229,23 +229,23 @@ if ('onhashchange' in window) { 164 165 void replace_labels_with_displacements(segment& code, const map<string, int32_t>& byte_index) { 166 int32_t byte_index_next_instruction_starts_at = 0; -167 for (int i = 0; i < SIZE(code.lines); ++i) { +167 for (int i = 0; i < SIZE(code.lines); ++i) { 168 line& inst = code.lines.at(i); 169 byte_index_next_instruction_starts_at += num_bytes(inst); 170 line new_inst; -171 for (int j = 0; j < SIZE(inst.words); ++j) { +171 for (int j = 0; j < SIZE(inst.words); ++j) { 172 const word& curr = inst.words.at(j); -173 if (contains_key(byte_index, curr.data)) { +173 if (contains_key(byte_index, curr.data)) { 174 int32_t displacement = static_cast<int32_t>(get(byte_index, curr.data)) - byte_index_next_instruction_starts_at; 175 if (has_operand_metadata(curr, "disp8")) { 176 if (displacement > 0xff || displacement < -0x7f) -177 raise << "'" << to_string(inst) << "': label too far away for displacement " << std::hex << displacement << " to fit in 8 bits\n" << end(); +177 raise << "'" << to_string(inst) << "': label too far away for displacement " << std::hex << displacement << " to fit in 8 bits\n" << end(); 178 else 179 emit_hex_bytes(new_inst, displacement, 1); 180 } 181 else if (has_operand_metadata(curr, "disp16")) { 182 if (displacement > 0xffff || displacement < -0x7fff) -183 raise << "'" << to_string(inst) << "': label too far away for displacement " << std::hex << displacement << " to fit in 16 bits\n" << end(); +183 raise << "'" << to_string(inst) << "': label too far away for displacement " << std::hex << displacement << " to fit in 16 bits\n" << end(); 184 else 185 emit_hex_bytes(new_inst, displacement, 2); 186 } @@ -258,13 +258,13 @@ if ('onhashchange' in window) { 193 } 194 } 195 inst.words.swap(new_inst.words); -196 trace(99, "transform") << "instruction after transform: '" << data_to_string(inst) << "'" << end(); +196 trace(99, "transform") << "instruction after transform: '" << data_to_string(inst) << "'" << end(); 197 } 198 } 199 200 string data_to_string(const line& inst) { 201 ostringstream out; -202 for (int i = 0; i < SIZE(inst.words); ++i) { +202 for (int i = 0; i < SIZE(inst.words); ++i) { 203 if (i > 0) out << ' '; 204 out << inst.words.at(i).data; 205 } -- cgit 1.4.1-2-gfad0