Skip to content

WASM_X86: Fix text format #1380

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 3 commits into from
Dec 24, 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
1 change: 1 addition & 0 deletions src/libasr/codegen/wasm_to_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class X86Visitor : public WASMDecoder<X86Visitor>,
switch (func_index) {
case 0: { // print_i32
m_a.asm_call_label("print_i32");
m_a.asm_pop_r32(X86Reg::eax);
break;
}
case 1: { // print_i64
Expand Down
5 changes: 2 additions & 3 deletions src/libasr/codegen/x86_assembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void emit_elf32_header(X86Assembler &a, uint32_t p_flags) {
a.asm_dw_imm16(2); // e_type
a.asm_dw_imm16(3); // e_machine
a.asm_dd_imm32(1); // e_version
a.asm_dd_label("e_entry"); // e_entry
a.asm_dd_label("_start"); // e_entry
a.asm_dd_label("e_phoff"); // e_phoff
a.asm_dd_imm32(0); // e_shoff
a.asm_dd_imm32(0); // e_flags
Expand Down Expand Up @@ -80,8 +80,7 @@ void emit_elf32_header(X86Assembler &a, uint32_t p_flags) {
}

void emit_elf32_footer(X86Assembler &a) {
a.add_var("e_entry", a.get_defined_symbol("_start").value);
a.add_var("filesize", a.pos()-a.origin());
a.add_var_size("filesize");
}

void emit_exit(X86Assembler &a, const std::string &name,
Expand Down
3 changes: 2 additions & 1 deletion src/libasr/codegen/x86_assembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,8 @@ class X86Assembler {
m_asm_code = "BITS 64\n";
emit(" ", "org " + i2s((uint64_t)m_origin) + "\n"); // specify origin info
} else {
m_asm_code = "BITS 32\n\n";
m_asm_code = "BITS 32\n";
emit(" ", "org " + i2s(m_origin) + "\n"); // specify origin info
}
#endif
}
Expand Down
10 changes: 5 additions & 5 deletions src/lpython/tests/test_asm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ TEST_CASE("Store and get instructions") {
std::string asm_code = a.get_asm();
std::string ref = S(R"""(
BITS 32
org 0x08048000

pop eax
jz 0x0d
Expand Down Expand Up @@ -300,6 +301,7 @@ TEST_CASE("Memory operand") {
std::string asm_code = a.get_asm();
std::string ref = S(R"""(
BITS 32
org 0x08048000

inc [ebx]
inc [ebx+3]
Expand Down Expand Up @@ -369,6 +371,7 @@ TEST_CASE("elf32 binary") {
std::string asm_code = a.get_asm();
std::string ref = S(R"""(
BITS 32
org 0x08048000

ehdr:
db 0x7f
Expand All @@ -390,7 +393,7 @@ BITS 32
dw 0x0002
dw 0x0003
dd 0x00000001
dd e_entry
dd _start
dd e_phoff
dd 0x00000000
dd 0x00000000
Expand Down Expand Up @@ -444,10 +447,7 @@ e_phoff equ 0x00000034
mov ebx, 0x00000000
int 0x80

e_entry equ 0x08048061


filesize equ 0x00000088
filesize equ $ - $$

)""");
CHECK(asm_code == ref);
Expand Down