diff --git a/src/libasr/codegen/wasm_to_x86.cpp b/src/libasr/codegen/wasm_to_x86.cpp index 1aaa00ffa2..f5c0f4ea04 100644 --- a/src/libasr/codegen/wasm_to_x86.cpp +++ b/src/libasr/codegen/wasm_to_x86.cpp @@ -36,7 +36,7 @@ class X86Visitor : public WASMDecoder, std::vector loop_unique_id; uint32_t cur_nesting_length; int32_t last_vis_i32_const, last_last_vis_i32_const; - std::unordered_map loc_to_str; + std::map label_to_str; X86Visitor(X86Assembler &m_a, Allocator &al, diag::Diagnostics &diagonostics, Vec &code) @@ -79,15 +79,14 @@ class X86Visitor : public WASMDecoder, std::string label = "string" + std::to_string(last_last_vis_i32_const); emit_print(m_a, label, - loc_to_str[last_last_vis_i32_const].size()); + label_to_str[label].size()); break; } case 5: { // flush_buf - std::string label = "string-1"; + std::string label = "string_newline"; std::string msg = "\n"; - int32_t loc = -1; // tmp negative index used emit_print(m_a, label, msg.size()); - loc_to_str[loc] = msg; + label_to_str["string_newline"] = msg; break; } case 6: { // set_exit_code @@ -312,7 +311,8 @@ class X86Visitor : public WASMDecoder, for (uint32_t i = 0; i < data_segments.size(); i++) { offset = data_segments[i].insts_start_index; decode_instructions(); - loc_to_str[last_vis_i32_const] = data_segments[i].text; + std::string label = "string" + std::to_string(last_vis_i32_const); + label_to_str[label] = data_segments[i].text; } for (uint32_t i = 0; i < type_indices.size(); i++) { @@ -347,9 +347,8 @@ class X86Visitor : public WASMDecoder, } } - for (auto &s : loc_to_str) { - std::string label = "string" + std::to_string(s.first); - emit_data_string(m_a, label, s.second); + for (auto &s : label_to_str) { + emit_data_string(m_a, s.first, s.second); } emit_elf32_footer(m_a); diff --git a/src/libasr/codegen/x86_assembler.cpp b/src/libasr/codegen/x86_assembler.cpp index 50dd196cdb..04c6dbd36a 100644 --- a/src/libasr/codegen/x86_assembler.cpp +++ b/src/libasr/codegen/x86_assembler.cpp @@ -140,7 +140,7 @@ void emit_print_int(X86Assembler &a, const std::string &name) a.asm_jge_label(".print_int_"); // if num >= 0 then print it // print "-" and then negate the integer - emit_print(a, "string-", 1U); + emit_print(a, "string_neg", 1U); // ecx value changed during print so fetch back a.asm_mov_r32_m32(X86Reg::ecx, &base, nullptr, 1, 8); a.asm_neg_r32(X86Reg::ecx); @@ -199,7 +199,7 @@ void emit_print_int(X86Assembler &a, const std::string &name) a.asm_pop_r32(X86Reg::ebp); a.asm_ret(); - emit_data_string(a, "string-", "-"); // - symbol for printing negative ints + emit_data_string(a, "string_neg", "-"); // - symbol for printing negative ints } } // namespace LFortran