Skip to content

Commit 860c4b3

Browse files
authored
Merge pull request #1329 from Shaikh-Ubaid/wasm_x86_text_bugs
WASM_X86: Use alphabets and underscore for label names
2 parents 1aeff83 + 4cf57bf commit 860c4b3

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

src/libasr/codegen/wasm_to_x86.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class X86Visitor : public WASMDecoder<X86Visitor>,
3636
std::vector<std::string> loop_unique_id;
3737
uint32_t cur_nesting_length;
3838
int32_t last_vis_i32_const, last_last_vis_i32_const;
39-
std::unordered_map<int32_t, std::string> loc_to_str;
39+
std::map<std::string, std::string> label_to_str;
4040

4141
X86Visitor(X86Assembler &m_a, Allocator &al,
4242
diag::Diagnostics &diagonostics, Vec<uint8_t> &code)
@@ -79,15 +79,14 @@ class X86Visitor : public WASMDecoder<X86Visitor>,
7979
std::string label =
8080
"string" + std::to_string(last_last_vis_i32_const);
8181
emit_print(m_a, label,
82-
loc_to_str[last_last_vis_i32_const].size());
82+
label_to_str[label].size());
8383
break;
8484
}
8585
case 5: { // flush_buf
86-
std::string label = "string-1";
86+
std::string label = "string_newline";
8787
std::string msg = "\n";
88-
int32_t loc = -1; // tmp negative index used
8988
emit_print(m_a, label, msg.size());
90-
loc_to_str[loc] = msg;
89+
label_to_str["string_newline"] = msg;
9190
break;
9291
}
9392
case 6: { // set_exit_code
@@ -312,7 +311,8 @@ class X86Visitor : public WASMDecoder<X86Visitor>,
312311
for (uint32_t i = 0; i < data_segments.size(); i++) {
313312
offset = data_segments[i].insts_start_index;
314313
decode_instructions();
315-
loc_to_str[last_vis_i32_const] = data_segments[i].text;
314+
std::string label = "string" + std::to_string(last_vis_i32_const);
315+
label_to_str[label] = data_segments[i].text;
316316
}
317317

318318
for (uint32_t i = 0; i < type_indices.size(); i++) {
@@ -347,9 +347,8 @@ class X86Visitor : public WASMDecoder<X86Visitor>,
347347
}
348348
}
349349

350-
for (auto &s : loc_to_str) {
351-
std::string label = "string" + std::to_string(s.first);
352-
emit_data_string(m_a, label, s.second);
350+
for (auto &s : label_to_str) {
351+
emit_data_string(m_a, s.first, s.second);
353352
}
354353

355354
emit_elf32_footer(m_a);

src/libasr/codegen/x86_assembler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ void emit_print_int(X86Assembler &a, const std::string &name)
140140
a.asm_jge_label(".print_int_"); // if num >= 0 then print it
141141

142142
// print "-" and then negate the integer
143-
emit_print(a, "string-", 1U);
143+
emit_print(a, "string_neg", 1U);
144144
// ecx value changed during print so fetch back
145145
a.asm_mov_r32_m32(X86Reg::ecx, &base, nullptr, 1, 8);
146146
a.asm_neg_r32(X86Reg::ecx);
@@ -199,7 +199,7 @@ void emit_print_int(X86Assembler &a, const std::string &name)
199199
a.asm_pop_r32(X86Reg::ebp);
200200
a.asm_ret();
201201

202-
emit_data_string(a, "string-", "-"); // - symbol for printing negative ints
202+
emit_data_string(a, "string_neg", "-"); // - symbol for printing negative ints
203203
}
204204

205205
} // namespace LFortran

0 commit comments

Comments
 (0)