Skip to content

Commit

Permalink
wip TOYWASM_USE_SEPARATE_VALIDATE
Browse files Browse the repository at this point in the history
  • Loading branch information
yamt committed May 7, 2024
1 parent e48a68d commit c9f51bf
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmake/ToywasmConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ endif()
# TOYWASM_USE_SEPARATE_EXECUTE=ON -> faster execution
# TOYWASM_USE_SEPARATE_EXECUTE=OFF -> smaller code
option(TOYWASM_USE_SEPARATE_EXECUTE "Use separate execute callback" ON)
option(TOYWASM_USE_SEPARATE_VALIDATE "Use separate validation callback" ON)

# TOYWASM_USE_TAILCALL=ON
# enable -mtail-call for wasm target
Expand Down
57 changes: 57 additions & 0 deletions lib/insn.c
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,13 @@ schedule_exception(struct exec_context *ectx)
#define EXECUTING (ctx->exec != NULL)
#define ECTX (ctx->exec)
#endif
#if defined(TOYWASM_USE_SEPARATE_VALIDATE)
#define VALIDATING false
#define VCTX ((struct validation_context *)NULL)
#else
#define VALIDATING (ctx->validation != NULL)
#define VCTX (ctx->validation)
#endif
#define INSN_IMPL(NAME) \
int process_##NAME(const uint8_t **pp, const uint8_t *ep, \
struct context *ctx)
Expand Down Expand Up @@ -680,6 +685,58 @@ schedule_exception(struct exec_context *ectx)
#undef STACK_ADJ
#endif /* defined(TOYWASM_USE_SEPARATE_EXECUTE) */

#if defined(TOYWASM_USE_SEPARATE_VALIDATE)
#define EXECUTING false
#define ECTX ((struct exec_context *)NULL)
#define VALIDATING true
#define VCTX ctx
#define INSN_IMPL(NAME) \
int validate_##NAME(const uint8_t **pp, const uint8_t *ep, \
struct validation_context *ctx)
#define LOAD_PC const uint8_t *p __attribute__((__unused__)) = *pp
#define SAVE_PC *pp = p
#define RELOAD_PC
#define SAVE_STACK_PTR
#define LOAD_STACK_PTR
#define ORIG_PC (*pp)
#define INSN_SUCCESS return 0
#define INSN_SUCCESS_RETURN INSN_SUCCESS
#define PREPARE_FOR_POSSIBLE_RESTART
#define INSN_FAIL_RESTARTABLE(NAME) INSN_FAIL
#define INSN_FAIL \
assert(ret != 0); \
assert(!IS_RESTARTABLE(ret)); \
return ret
#undef push_val
#undef pop_val
#define push_val(v, csz, ctx) do {} while (0)
#define pop_val(v, csz, ctx) do {} while (0)
#define STACK NULL
#define STACK_ADJ(n) do {} while(0)

#include "insn_impl.h"

#undef EXECUTING
#undef ECTX
#undef VALIDATING
#undef VCTX
#undef INSN_IMPL
#undef LOAD_PC
#undef SAVE_PC
#undef RELOAD_PC
#undef SAVE_STACK_PTR
#undef LOAD_STACK_PTR
#undef ORIG_PC
#undef PREPARE_FOR_POSSIBLE_RESTART
#undef INSN_SUCCESS
#undef INSN_SUCCESS_RETURN
#undef INSN_FAIL
#undef INSN_FAIL_RESTARTABLE
#undef ep
#undef STACK
#undef STACK_ADJ
#endif /* defined(TOYWASM_USE_SEPARATE_EXECUTE) */

#if defined(TOYWASM_USE_SEPARATE_EXECUTE)
typedef int (*exec_func_t)(const uint8_t *, struct cell *,
struct exec_context *);
Expand Down
1 change: 1 addition & 0 deletions lib/toywasm_config.c.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const char *const toywasm_config_string =
"\tTOYWASM_USE_SEPARATE_EXECUTE = @TOYWASM_USE_SEPARATE_EXECUTE@\n"
"\tTOYWASM_USE_SEPARATE_VALIDATE = @TOYWASM_USE_SEPARATE_VALIDATE@\n"
"\tTOYWASM_USE_TAILCALL = @TOYWASM_USE_TAILCALL@\n"
"\tTOYWASM_FORCE_USE_TAILCALL = @TOYWASM_FORCE_USE_TAILCALL@\n"
"\tTOYWASM_USE_SIMD = @TOYWASM_USE_SIMD@\n"
Expand Down
1 change: 1 addition & 0 deletions lib/toywasm_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define _TOYWASM_CONFIG_H

#cmakedefine TOYWASM_USE_SEPARATE_EXECUTE
#cmakedefine TOYWASM_USE_SEPARATE_VALIDATE
#cmakedefine TOYWASM_USE_TAILCALL
#cmakedefine TOYWASM_FORCE_USE_TAILCALL
#cmakedefine TOYWASM_USE_SIMD
Expand Down

0 comments on commit c9f51bf

Please sign in to comment.