summaryrefslogtreecommitdiff
path: root/src/interpreter.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/interpreter.h')
-rw-r--r--src/interpreter.h354
1 files changed, 177 insertions, 177 deletions
diff --git a/src/interpreter.h b/src/interpreter.h
index 6db10fc9..0c0dde2a 100644
--- a/src/interpreter.h
+++ b/src/interpreter.h
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#ifndef WASM_INTERPRETER_H_
-#define WASM_INTERPRETER_H_
+#ifndef WABT_INTERPRETER_H_
+#define WABT_INTERPRETER_H_
#include <stdint.h>
@@ -25,7 +25,7 @@
#include "vector.h"
#include "writer.h"
-struct WasmStream;
+struct WabtStream;
#define FOREACH_INTERPRETER_RESULT(V) \
V(OK, "ok") \
@@ -64,181 +64,181 @@ struct WasmStream;
/* the expected export kind doesn't match. */ \
V(EXPORT_KIND_MISMATCH, "export kind mismatch")
-typedef enum WasmInterpreterResult {
-#define V(name, str) WASM_INTERPRETER_##name,
+typedef enum WabtInterpreterResult {
+#define V(name, str) WABT_INTERPRETER_##name,
FOREACH_INTERPRETER_RESULT(V)
#undef V
-} WasmInterpreterResult;
+} WabtInterpreterResult;
-#define WASM_INVALID_INDEX ((uint32_t)~0)
-#define WASM_INVALID_OFFSET ((uint32_t)~0)
-#define WASM_TABLE_ENTRY_SIZE (sizeof(uint32_t) * 2 + sizeof(uint8_t))
-#define WASM_TABLE_ENTRY_OFFSET_OFFSET 0
-#define WASM_TABLE_ENTRY_DROP_OFFSET sizeof(uint32_t)
-#define WASM_TABLE_ENTRY_KEEP_OFFSET (sizeof(uint32_t) * 2)
+#define WABT_INVALID_INDEX ((uint32_t)~0)
+#define WABT_INVALID_OFFSET ((uint32_t)~0)
+#define WABT_TABLE_ENTRY_SIZE (sizeof(uint32_t) * 2 + sizeof(uint8_t))
+#define WABT_TABLE_ENTRY_OFFSET_OFFSET 0
+#define WABT_TABLE_ENTRY_DROP_OFFSET sizeof(uint32_t)
+#define WABT_TABLE_ENTRY_KEEP_OFFSET (sizeof(uint32_t) * 2)
enum {
/* push space on the value stack for N entries */
- WASM_OPCODE_ALLOCA = WASM_NUM_OPCODES,
- WASM_OPCODE_BR_UNLESS,
- WASM_OPCODE_CALL_HOST,
- WASM_OPCODE_DATA,
- WASM_OPCODE_DROP_KEEP,
- WASM_NUM_INTERPRETER_OPCODES,
+ WABT_OPCODE_ALLOCA = WABT_NUM_OPCODES,
+ WABT_OPCODE_BR_UNLESS,
+ WABT_OPCODE_CALL_HOST,
+ WABT_OPCODE_DATA,
+ WABT_OPCODE_DROP_KEEP,
+ WABT_NUM_INTERPRETER_OPCODES,
};
-WASM_STATIC_ASSERT(WASM_NUM_INTERPRETER_OPCODES <= 256);
-
-typedef uint32_t WasmUint32;
-WASM_DEFINE_ARRAY(uint32, WasmUint32);
-
-/* TODO(binji): identical to WasmFuncSignature. Share? */
-typedef struct WasmInterpreterFuncSignature {
- WasmTypeVector param_types;
- WasmTypeVector result_types;
-} WasmInterpreterFuncSignature;
-WASM_DEFINE_VECTOR(interpreter_func_signature, WasmInterpreterFuncSignature);
-
-typedef struct WasmInterpreterTable {
- WasmLimits limits;
- WasmUint32Array func_indexes;
-} WasmInterpreterTable;
-WASM_DEFINE_VECTOR(interpreter_table, WasmInterpreterTable);
-
-typedef struct WasmInterpreterMemory {
- WasmAllocator* allocator;
+WABT_STATIC_ASSERT(WABT_NUM_INTERPRETER_OPCODES <= 256);
+
+typedef uint32_t WabtUint32;
+WABT_DEFINE_ARRAY(uint32, WabtUint32);
+
+/* TODO(binji): identical to WabtFuncSignature. Share? */
+typedef struct WabtInterpreterFuncSignature {
+ WabtTypeVector param_types;
+ WabtTypeVector result_types;
+} WabtInterpreterFuncSignature;
+WABT_DEFINE_VECTOR(interpreter_func_signature, WabtInterpreterFuncSignature);
+
+typedef struct WabtInterpreterTable {
+ WabtLimits limits;
+ WabtUint32Array func_indexes;
+} WabtInterpreterTable;
+WABT_DEFINE_VECTOR(interpreter_table, WabtInterpreterTable);
+
+typedef struct WabtInterpreterMemory {
+ WabtAllocator* allocator;
void* data;
- WasmLimits page_limits;
+ WabtLimits page_limits;
uint32_t byte_size; /* Cached from page_limits. */
-} WasmInterpreterMemory;
-WASM_DEFINE_VECTOR(interpreter_memory, WasmInterpreterMemory);
+} WabtInterpreterMemory;
+WABT_DEFINE_VECTOR(interpreter_memory, WabtInterpreterMemory);
-typedef union WasmInterpreterValue {
+typedef union WabtInterpreterValue {
uint32_t i32;
uint64_t i64;
uint32_t f32_bits;
uint64_t f64_bits;
-} WasmInterpreterValue;
-WASM_DEFINE_ARRAY(interpreter_value, WasmInterpreterValue);
-
-typedef struct WasmInterpreterTypedValue {
- WasmType type;
- WasmInterpreterValue value;
-} WasmInterpreterTypedValue;
-WASM_DEFINE_VECTOR(interpreter_typed_value, WasmInterpreterTypedValue);
-
-typedef struct WasmInterpreterGlobal {
- WasmInterpreterTypedValue typed_value;
- WasmBool mutable_;
+} WabtInterpreterValue;
+WABT_DEFINE_ARRAY(interpreter_value, WabtInterpreterValue);
+
+typedef struct WabtInterpreterTypedValue {
+ WabtType type;
+ WabtInterpreterValue value;
+} WabtInterpreterTypedValue;
+WABT_DEFINE_VECTOR(interpreter_typed_value, WabtInterpreterTypedValue);
+
+typedef struct WabtInterpreterGlobal {
+ WabtInterpreterTypedValue typed_value;
+ WabtBool mutable_;
uint32_t import_index; /* or INVALID_INDEX if not imported */
-} WasmInterpreterGlobal;
-WASM_DEFINE_VECTOR(interpreter_global, WasmInterpreterGlobal);
+} WabtInterpreterGlobal;
+WABT_DEFINE_VECTOR(interpreter_global, WabtInterpreterGlobal);
-typedef struct WasmInterpreterImport {
- WasmStringSlice module_name;
- WasmStringSlice field_name;
- WasmExternalKind kind;
+typedef struct WabtInterpreterImport {
+ WabtStringSlice module_name;
+ WabtStringSlice field_name;
+ WabtExternalKind kind;
union {
struct {
uint32_t sig_index;
} func;
struct {
- WasmLimits limits;
+ WabtLimits limits;
} table, memory;
struct {
- WasmType type;
- WasmBool mutable_;
+ WabtType type;
+ WabtBool mutable_;
} global;
};
-} WasmInterpreterImport;
-WASM_DEFINE_ARRAY(interpreter_import, WasmInterpreterImport);
+} WabtInterpreterImport;
+WABT_DEFINE_ARRAY(interpreter_import, WabtInterpreterImport);
-struct WasmInterpreterFunc;
+struct WabtInterpreterFunc;
-typedef WasmResult (*WasmInterpreterHostFuncCallback)(
- const struct WasmInterpreterFunc* func,
- const WasmInterpreterFuncSignature* sig,
+typedef WabtResult (*WabtInterpreterHostFuncCallback)(
+ const struct WabtInterpreterFunc* func,
+ const WabtInterpreterFuncSignature* sig,
uint32_t num_args,
- WasmInterpreterTypedValue* args,
+ WabtInterpreterTypedValue* args,
uint32_t num_results,
- WasmInterpreterTypedValue* out_results,
+ WabtInterpreterTypedValue* out_results,
void* user_data);
-typedef struct WasmInterpreterFunc {
+typedef struct WabtInterpreterFunc {
uint32_t sig_index;
- WasmBool is_host;
+ WabtBool is_host;
union {
struct {
uint32_t offset;
uint32_t local_decl_count;
uint32_t local_count;
- WasmTypeVector param_and_local_types;
+ WabtTypeVector param_and_local_types;
} defined;
struct {
- WasmStringSlice module_name;
- WasmStringSlice field_name;
- WasmInterpreterHostFuncCallback callback;
+ WabtStringSlice module_name;
+ WabtStringSlice field_name;
+ WabtInterpreterHostFuncCallback callback;
void* user_data;
} host;
};
-} WasmInterpreterFunc;
-WASM_DEFINE_VECTOR(interpreter_func, WasmInterpreterFunc);
+} WabtInterpreterFunc;
+WABT_DEFINE_VECTOR(interpreter_func, WabtInterpreterFunc);
-typedef struct WasmInterpreterExport {
- WasmStringSlice name; /* Owned by the export_bindings hash */
- WasmExternalKind kind;
+typedef struct WabtInterpreterExport {
+ WabtStringSlice name; /* Owned by the export_bindings hash */
+ WabtExternalKind kind;
uint32_t index;
-} WasmInterpreterExport;
-WASM_DEFINE_VECTOR(interpreter_export, WasmInterpreterExport);
+} WabtInterpreterExport;
+WABT_DEFINE_VECTOR(interpreter_export, WabtInterpreterExport);
-typedef struct WasmPrintErrorCallback {
+typedef struct WabtPrintErrorCallback {
void* user_data;
void (*print_error)(const char* msg, void* user_data);
-} WasmPrintErrorCallback;
+} WabtPrintErrorCallback;
-typedef struct WasmInterpreterHostImportDelegate {
+typedef struct WabtInterpreterHostImportDelegate {
void *user_data;
- WasmResult (*import_func)(WasmInterpreterImport*,
- WasmInterpreterFunc*,
- WasmInterpreterFuncSignature*,
- WasmPrintErrorCallback,
+ WabtResult (*import_func)(WabtInterpreterImport*,
+ WabtInterpreterFunc*,
+ WabtInterpreterFuncSignature*,
+ WabtPrintErrorCallback,
void* user_data);
- WasmResult (*import_table)(WasmInterpreterImport*,
- WasmInterpreterTable*,
- WasmPrintErrorCallback,
+ WabtResult (*import_table)(WabtInterpreterImport*,
+ WabtInterpreterTable*,
+ WabtPrintErrorCallback,
void* user_data);
- WasmResult (*import_memory)(WasmInterpreterImport*,
- WasmInterpreterMemory*,
- WasmPrintErrorCallback,
+ WabtResult (*import_memory)(WabtInterpreterImport*,
+ WabtInterpreterMemory*,
+ WabtPrintErrorCallback,
void* user_data);
- WasmResult (*import_global)(WasmInterpreterImport*,
- WasmInterpreterGlobal*,
- WasmPrintErrorCallback,
+ WabtResult (*import_global)(WabtInterpreterImport*,
+ WabtInterpreterGlobal*,
+ WabtPrintErrorCallback,
void* user_data);
-} WasmInterpreterHostImportDelegate;
+} WabtInterpreterHostImportDelegate;
-typedef struct WasmInterpreterModule {
- WasmStringSlice name;
- WasmInterpreterExportVector exports;
- WasmBindingHash export_bindings;
+typedef struct WabtInterpreterModule {
+ WabtStringSlice name;
+ WabtInterpreterExportVector exports;
+ WabtBindingHash export_bindings;
uint32_t memory_index; /* INVALID_INDEX if not defined */
uint32_t table_index; /* INVALID_INDEX if not defined */
- WasmBool is_host;
+ WabtBool is_host;
union {
struct {
- WasmInterpreterImportArray imports;
+ WabtInterpreterImportArray imports;
uint32_t start_func_index; /* INVALID_INDEX if not defined */
size_t istream_start;
size_t istream_end;
} defined;
struct {
- WasmInterpreterHostImportDelegate import_delegate;
+ WabtInterpreterHostImportDelegate import_delegate;
} host;
};
-} WasmInterpreterModule;
-WASM_DEFINE_VECTOR(interpreter_module, WasmInterpreterModule);
+} WabtInterpreterModule;
+WABT_DEFINE_VECTOR(interpreter_module, WabtInterpreterModule);
/* Used to track and reset the state of the environment. */
-typedef struct WasmInterpreterEnvironmentMark {
+typedef struct WabtInterpreterEnvironmentMark {
size_t modules_size;
size_t sigs_size;
size_t funcs_size;
@@ -246,89 +246,89 @@ typedef struct WasmInterpreterEnvironmentMark {
size_t tables_size;
size_t globals_size;
size_t istream_size;
-} WasmInterpreterEnvironmentMark;
-
-typedef struct WasmInterpreterEnvironment {
- WasmInterpreterModuleVector modules;
- WasmInterpreterFuncSignatureVector sigs;
- WasmInterpreterFuncVector funcs;
- WasmInterpreterMemoryVector memories;
- WasmInterpreterTableVector tables;
- WasmInterpreterGlobalVector globals;
- WasmOutputBuffer istream;
- WasmBindingHash module_bindings;
- WasmBindingHash registered_module_bindings;
-} WasmInterpreterEnvironment;
-
-typedef struct WasmInterpreterThread {
- WasmAllocator* allocator;
- WasmInterpreterEnvironment* env;
- WasmInterpreterValueArray value_stack;
- WasmUint32Array call_stack;
- WasmInterpreterValue* value_stack_top;
- WasmInterpreterValue* value_stack_end;
+} WabtInterpreterEnvironmentMark;
+
+typedef struct WabtInterpreterEnvironment {
+ WabtInterpreterModuleVector modules;
+ WabtInterpreterFuncSignatureVector sigs;
+ WabtInterpreterFuncVector funcs;
+ WabtInterpreterMemoryVector memories;
+ WabtInterpreterTableVector tables;
+ WabtInterpreterGlobalVector globals;
+ WabtOutputBuffer istream;
+ WabtBindingHash module_bindings;
+ WabtBindingHash registered_module_bindings;
+} WabtInterpreterEnvironment;
+
+typedef struct WabtInterpreterThread {
+ WabtAllocator* allocator;
+ WabtInterpreterEnvironment* env;
+ WabtInterpreterValueArray value_stack;
+ WabtUint32Array call_stack;
+ WabtInterpreterValue* value_stack_top;
+ WabtInterpreterValue* value_stack_end;
uint32_t* call_stack_top;
uint32_t* call_stack_end;
uint32_t pc;
/* a temporary buffer that is for passing args to host functions */
- WasmInterpreterTypedValueVector host_args;
-} WasmInterpreterThread;
+ WabtInterpreterTypedValueVector host_args;
+} WabtInterpreterThread;
-#define WASM_INTERPRETER_THREAD_OPTIONS_DEFAULT \
- { 512 * 1024 / sizeof(WasmInterpreterValue), 64 * 1024, WASM_INVALID_OFFSET }
+#define WABT_INTERPRETER_THREAD_OPTIONS_DEFAULT \
+ { 512 * 1024 / sizeof(WabtInterpreterValue), 64 * 1024, WABT_INVALID_OFFSET }
-typedef struct WasmInterpreterThreadOptions {
+typedef struct WabtInterpreterThreadOptions {
uint32_t value_stack_size;
uint32_t call_stack_size;
uint32_t pc;
-} WasmInterpreterThreadOptions;
+} WabtInterpreterThreadOptions;
-WASM_EXTERN_C_BEGIN
-WasmBool is_nan_f32(uint32_t f32_bits);
-WasmBool is_nan_f64(uint64_t f64_bits);
-WasmBool wasm_func_signatures_are_equal(WasmInterpreterEnvironment* env,
+WABT_EXTERN_C_BEGIN
+WabtBool wabt_is_nan_f32(uint32_t f32_bits);
+WabtBool wabt_is_nan_f64(uint64_t f64_bits);
+WabtBool wabt_func_signatures_are_equal(WabtInterpreterEnvironment* env,
uint32_t sig_index_0,
uint32_t sig_index_1);
-void wasm_init_interpreter_environment(WasmAllocator* allocator,
- WasmInterpreterEnvironment* env);
-void wasm_destroy_interpreter_environment(WasmAllocator* allocator,
- WasmInterpreterEnvironment* env);
-WasmInterpreterEnvironmentMark wasm_mark_interpreter_environment(
- WasmInterpreterEnvironment* env);
-void wasm_reset_interpreter_environment_to_mark(
- WasmAllocator* allocator,
- WasmInterpreterEnvironment* env,
- WasmInterpreterEnvironmentMark mark);
-WasmInterpreterModule* wasm_append_host_module(WasmAllocator* allocator,
- WasmInterpreterEnvironment* env,
- WasmStringSlice name);
-void wasm_init_interpreter_thread(WasmAllocator* allocator,
- WasmInterpreterEnvironment* env,
- WasmInterpreterThread* thread,
- WasmInterpreterThreadOptions* options);
-WasmInterpreterResult wasm_push_thread_value(WasmInterpreterThread* thread,
- WasmInterpreterValue value);
-void wasm_destroy_interpreter_thread(WasmAllocator* allocator,
- WasmInterpreterThread* thread);
-WasmInterpreterResult wasm_call_host(WasmInterpreterThread* thread,
- WasmInterpreterFunc* func);
-WasmInterpreterResult wasm_run_interpreter(WasmInterpreterThread* thread,
+void wabt_init_interpreter_environment(WabtAllocator* allocator,
+ WabtInterpreterEnvironment* env);
+void wabt_destroy_interpreter_environment(WabtAllocator* allocator,
+ WabtInterpreterEnvironment* env);
+WabtInterpreterEnvironmentMark wabt_mark_interpreter_environment(
+ WabtInterpreterEnvironment* env);
+void wabt_reset_interpreter_environment_to_mark(
+ WabtAllocator* allocator,
+ WabtInterpreterEnvironment* env,
+ WabtInterpreterEnvironmentMark mark);
+WabtInterpreterModule* wabt_append_host_module(WabtAllocator* allocator,
+ WabtInterpreterEnvironment* env,
+ WabtStringSlice name);
+void wabt_init_interpreter_thread(WabtAllocator* allocator,
+ WabtInterpreterEnvironment* env,
+ WabtInterpreterThread* thread,
+ WabtInterpreterThreadOptions* options);
+WabtInterpreterResult wabt_push_thread_value(WabtInterpreterThread* thread,
+ WabtInterpreterValue value);
+void wabt_destroy_interpreter_thread(WabtAllocator* allocator,
+ WabtInterpreterThread* thread);
+WabtInterpreterResult wabt_call_host(WabtInterpreterThread* thread,
+ WabtInterpreterFunc* func);
+WabtInterpreterResult wabt_run_interpreter(WabtInterpreterThread* thread,
uint32_t num_instructions,
uint32_t* call_stack_return_top);
-void wasm_trace_pc(WasmInterpreterThread* thread, struct WasmStream* stream);
-void wasm_disassemble(WasmInterpreterEnvironment* env,
- struct WasmStream* stream,
+void wabt_trace_pc(WabtInterpreterThread* thread, struct WabtStream* stream);
+void wabt_disassemble(WabtInterpreterEnvironment* env,
+ struct WabtStream* stream,
uint32_t from,
uint32_t to);
-void wasm_disassemble_module(WasmInterpreterEnvironment* env,
- struct WasmStream* stream,
- WasmInterpreterModule* module);
+void wabt_disassemble_module(WabtInterpreterEnvironment* env,
+ struct WabtStream* stream,
+ WabtInterpreterModule* module);
-WasmInterpreterExport* wasm_get_interpreter_export_by_name(
- WasmInterpreterModule* module,
- const WasmStringSlice* name);
-WASM_EXTERN_C_END
+WabtInterpreterExport* wabt_get_interpreter_export_by_name(
+ WabtInterpreterModule* module,
+ const WabtStringSlice* name);
+WABT_EXTERN_C_END
-#endif /* WASM_INTERPRETER_H_ */
+#endif /* WABT_INTERPRETER_H_ */