Skip to content

Commit 5644698

Browse files
committed
move fetch_exec_next_insn to insn.c
1 parent 83ab9ea commit 5644698

File tree

3 files changed

+37
-39
lines changed

3 files changed

+37
-39
lines changed

lib/exec.c

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,43 +1034,6 @@ do_branch(struct exec_context *ctx, uint32_t labelidx, bool goto_else)
10341034
rewind_stack(ctx, height, arity);
10351035
}
10361036

1037-
int
1038-
fetch_exec_next_insn(const uint8_t *p, struct cell *stack,
1039-
struct exec_context *ctx)
1040-
{
1041-
#if !(defined(TOYWASM_USE_SEPARATE_EXECUTE) && defined(TOYWASM_USE_TAILCALL))
1042-
assert(ctx->p == p);
1043-
#endif
1044-
assert(ctx->event == EXEC_EVENT_NONE);
1045-
assert(ctx->frames.lsize > 0);
1046-
#if defined(TOYWASM_ENABLE_TRACING_INSN)
1047-
uint32_t pc = ptr2pc(ctx->instance->module, p);
1048-
#endif
1049-
uint32_t op = *p++;
1050-
#if defined(TOYWASM_USE_SEPARATE_EXECUTE)
1051-
xlog_trace_insn("exec %06" PRIx32 ": %s (%02" PRIx32 ")", pc,
1052-
instructions[op].name, op);
1053-
const struct exec_instruction_desc *desc = &exec_instructions[op];
1054-
#if defined(TOYWASM_USE_TAILCALL)
1055-
__musttail
1056-
#endif
1057-
return desc->fetch_exec(p, stack, ctx);
1058-
#else
1059-
const struct instruction_desc *desc = &instructions[op];
1060-
if (__predict_false(desc->next_table != NULL)) {
1061-
op = read_leb_u32_nocheck(&p);
1062-
desc = &desc->next_table[op];
1063-
}
1064-
xlog_trace_insn("exec %06" PRIx32 ": %s", pc, desc->name);
1065-
assert(desc->process != NULL);
1066-
struct context common_ctx;
1067-
memset(&common_ctx, 0, sizeof(common_ctx));
1068-
common_ctx.exec = ctx;
1069-
ctx->p = p;
1070-
return desc->process(&ctx->p, NULL, &common_ctx);
1071-
#endif
1072-
}
1073-
10741037
static int
10751038
restart_insn(struct exec_context *ctx)
10761039
{

lib/insn.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,3 +994,40 @@ instruction_name(const struct exec_instruction_desc *exec_table, uint32_t op)
994994
}
995995
#endif /* defined(TOYWASM_USE_SEPARATE_EXECUTE) && \
996996
defined(TOYWASM_ENABLE_TRACING_INSN) */
997+
998+
int
999+
fetch_exec_next_insn(const uint8_t *p, struct cell *stack,
1000+
struct exec_context *ctx)
1001+
{
1002+
#if !(defined(TOYWASM_USE_SEPARATE_EXECUTE) && defined(TOYWASM_USE_TAILCALL))
1003+
assert(ctx->p == p);
1004+
#endif
1005+
assert(ctx->event == EXEC_EVENT_NONE);
1006+
assert(ctx->frames.lsize > 0);
1007+
#if defined(TOYWASM_ENABLE_TRACING_INSN)
1008+
uint32_t pc = ptr2pc(ctx->instance->module, p);
1009+
#endif
1010+
uint32_t op = *p++;
1011+
#if defined(TOYWASM_USE_SEPARATE_EXECUTE)
1012+
xlog_trace_insn("exec %06" PRIx32 ": %s (%02" PRIx32 ")", pc,
1013+
instructions[op].name, op);
1014+
const struct exec_instruction_desc *desc = &exec_instructions[op];
1015+
#if defined(TOYWASM_USE_TAILCALL)
1016+
__musttail
1017+
#endif
1018+
return desc->fetch_exec(p, stack, ctx);
1019+
#else
1020+
const struct instruction_desc *desc = &instructions[op];
1021+
if (__predict_false(desc->next_table != NULL)) {
1022+
op = read_leb_u32_nocheck(&p);
1023+
desc = &desc->next_table[op];
1024+
}
1025+
xlog_trace_insn("exec %06" PRIx32 ": %s", pc, desc->name);
1026+
assert(desc->process != NULL);
1027+
struct context common_ctx;
1028+
memset(&common_ctx, 0, sizeof(common_ctx));
1029+
common_ctx.exec = ctx;
1030+
ctx->p = p;
1031+
return desc->process(&ctx->p, NULL, &common_ctx);
1032+
#endif
1033+
}

lib/insn.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,5 @@ struct instruction_desc {
3939
#define INSN_FLAG_EXTENDED_CONST 0
4040
#endif
4141

42-
extern const struct exec_instruction_desc exec_instructions[];
43-
4442
extern const struct instruction_desc instructions[];
4543
extern const size_t instructions_size;

0 commit comments

Comments
 (0)