Skip to content

WASM_X86: Use alphabets and underscore for label names #1329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/libasr/codegen/wasm_to_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class X86Visitor : public WASMDecoder<X86Visitor>,
std::vector<std::string> loop_unique_id;
uint32_t cur_nesting_length;
int32_t last_vis_i32_const, last_last_vis_i32_const;
std::unordered_map<int32_t, std::string> loc_to_str;
std::map<std::string, std::string> label_to_str;

X86Visitor(X86Assembler &m_a, Allocator &al,
diag::Diagnostics &diagonostics, Vec<uint8_t> &code)
Expand Down Expand Up @@ -79,15 +79,14 @@ class X86Visitor : public WASMDecoder<X86Visitor>,
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
Expand Down Expand Up @@ -312,7 +311,8 @@ class X86Visitor : public WASMDecoder<X86Visitor>,
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++) {
Expand Down Expand Up @@ -347,9 +347,8 @@ class X86Visitor : public WASMDecoder<X86Visitor>,
}
}

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);
Expand Down
4 changes: 2 additions & 2 deletions src/libasr/codegen/x86_assembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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