Skip to content

Commit f841890

Browse files
committed
Keep call imms in code
1 parent f59cf4f commit f841890

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

lib/fizzy/execute.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ ExecutionResult execute(Instance& instance, FuncIdx func_idx, const Value* args,
616616
}
617617
case Instr::call:
618618
{
619-
const auto called_func_idx = read<uint32_t>(immediates);
619+
const auto called_func_idx = read<uint32_t>(pc);
620620
const auto& called_func_type = instance.module->get_function_type(called_func_idx);
621621

622622
if (!invoke_function(called_func_type, called_func_idx, instance, stack, depth))
@@ -627,7 +627,7 @@ ExecutionResult execute(Instance& instance, FuncIdx func_idx, const Value* args,
627627
{
628628
assert(instance.table != nullptr);
629629

630-
const auto expected_type_idx = read<uint32_t>(immediates);
630+
const auto expected_type_idx = read<uint32_t>(pc);
631631
assert(expected_type_idx < instance.module->typesec.size());
632632

633633
const auto elem_idx = stack.pop().as<uint32_t>();

lib/fizzy/parser_expr.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -690,8 +690,9 @@ parser_result<Code> parse_expr(const uint8_t* pos, const uint8_t* end, FuncIdx f
690690
update_operand_stack(
691691
frame, operand_stack, callee_func_type.inputs, callee_func_type.outputs);
692692

693-
push(code.immediates, callee_func_idx);
694-
break;
693+
code.instructions.push_back(opcode);
694+
push(code.instructions, callee_func_idx);
695+
continue;
695696
}
696697

697698
case Instr::call_indirect:
@@ -709,13 +710,14 @@ parser_result<Code> parse_expr(const uint8_t* pos, const uint8_t* end, FuncIdx f
709710
update_operand_stack(
710711
frame, operand_stack, callee_func_type.inputs, callee_func_type.outputs);
711712

712-
push(code.immediates, callee_type_idx);
713-
714713
uint8_t table_idx;
715714
std::tie(table_idx, pos) = parse_byte(pos, end);
716715
if (table_idx != 0)
717716
throw parser_error{"invalid tableidx encountered with call_indirect"};
718-
break;
717+
718+
code.instructions.push_back(opcode);
719+
push(code.instructions, callee_type_idx);
720+
continue;
719721
}
720722

721723
case Instr::local_get:

0 commit comments

Comments
 (0)