Skip to content

Commit d916a2b

Browse files
authored
Merge pull request #1380 from Shaikh-Ubaid/wasm_x86_fix_text_format
WASM_X86: Fix text format
2 parents 7aaedcc + 54a04c6 commit d916a2b

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

src/libasr/codegen/wasm_to_x86.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class X86Visitor : public WASMDecoder<X86Visitor>,
5555
switch (func_index) {
5656
case 0: { // print_i32
5757
m_a.asm_call_label("print_i32");
58+
m_a.asm_pop_r32(X86Reg::eax);
5859
break;
5960
}
6061
case 1: { // print_i64

src/libasr/codegen/x86_assembler.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void emit_elf32_header(X86Assembler &a, uint32_t p_flags) {
5151
a.asm_dw_imm16(2); // e_type
5252
a.asm_dw_imm16(3); // e_machine
5353
a.asm_dd_imm32(1); // e_version
54-
a.asm_dd_label("e_entry"); // e_entry
54+
a.asm_dd_label("_start"); // e_entry
5555
a.asm_dd_label("e_phoff"); // e_phoff
5656
a.asm_dd_imm32(0); // e_shoff
5757
a.asm_dd_imm32(0); // e_flags
@@ -80,8 +80,7 @@ void emit_elf32_header(X86Assembler &a, uint32_t p_flags) {
8080
}
8181

8282
void emit_elf32_footer(X86Assembler &a) {
83-
a.add_var("e_entry", a.get_defined_symbol("_start").value);
84-
a.add_var("filesize", a.pos()-a.origin());
83+
a.add_var_size("filesize");
8584
}
8685

8786
void emit_exit(X86Assembler &a, const std::string &name,

src/libasr/codegen/x86_assembler.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,8 @@ class X86Assembler {
362362
m_asm_code = "BITS 64\n";
363363
emit(" ", "org " + i2s((uint64_t)m_origin) + "\n"); // specify origin info
364364
} else {
365-
m_asm_code = "BITS 32\n\n";
365+
m_asm_code = "BITS 32\n";
366+
emit(" ", "org " + i2s(m_origin) + "\n"); // specify origin info
366367
}
367368
#endif
368369
}

src/lpython/tests/test_asm.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ TEST_CASE("Store and get instructions") {
6565
std::string asm_code = a.get_asm();
6666
std::string ref = S(R"""(
6767
BITS 32
68+
org 0x08048000
6869
6970
pop eax
7071
jz 0x0d
@@ -300,6 +301,7 @@ TEST_CASE("Memory operand") {
300301
std::string asm_code = a.get_asm();
301302
std::string ref = S(R"""(
302303
BITS 32
304+
org 0x08048000
303305
304306
inc [ebx]
305307
inc [ebx+3]
@@ -369,6 +371,7 @@ TEST_CASE("elf32 binary") {
369371
std::string asm_code = a.get_asm();
370372
std::string ref = S(R"""(
371373
BITS 32
374+
org 0x08048000
372375
373376
ehdr:
374377
db 0x7f
@@ -390,7 +393,7 @@ BITS 32
390393
dw 0x0002
391394
dw 0x0003
392395
dd 0x00000001
393-
dd e_entry
396+
dd _start
394397
dd e_phoff
395398
dd 0x00000000
396399
dd 0x00000000
@@ -444,10 +447,7 @@ e_phoff equ 0x00000034
444447
mov ebx, 0x00000000
445448
int 0x80
446449
447-
e_entry equ 0x08048061
448-
449-
450-
filesize equ 0x00000088
450+
filesize equ $ - $$
451451
452452
)""");
453453
CHECK(asm_code == ref);

0 commit comments

Comments
 (0)