Skip to content

Commit 9b13170

Browse files
ubaidskcertik
authored andcommitted
WASM_X86: Fix return values from function calls
1 parent 344f2c6 commit 9b13170

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/libasr/codegen/wasm_to_x86.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,15 @@ class X86Visitor : public BaseWASMVisitor<X86Visitor> {
5151
std::to_string(func_index) +
5252
" not yet supported";
5353
}
54-
} else {
55-
m_a.asm_call_label(exports[func_index - 7].name);
54+
return;
5655
}
5756

57+
uint32_t imports_adjusted_func_index = func_index - 7U;
58+
m_a.asm_call_label(exports[imports_adjusted_func_index].name);
59+
60+
5861
// Pop the passed function arguments
59-
wasm::FuncType func_type = func_types[type_indices[func_index]];
62+
wasm::FuncType func_type = func_types[type_indices[imports_adjusted_func_index]];
6063
for (uint32_t i = 0; i < func_type.param_types.size(); i++) {
6164
m_a.asm_pop_r32(X86Reg::eax);
6265
}
@@ -68,7 +71,7 @@ class X86Visitor : public BaseWASMVisitor<X86Visitor> {
6871
m_a.asm_mov_r32_m32(
6972
X86Reg::eax, &base, nullptr, 1,
7073
-(4 * (func_type.param_types.size() + 2 +
71-
func_codes[func_index].locals.size() + 1)));
74+
func_codes[imports_adjusted_func_index].locals.size() + 1)));
7275

7376
// push eax value onto stack
7477
m_a.asm_push_r32(X86Reg::eax);

0 commit comments

Comments
 (0)