summaryrefslogtreecommitdiff
path: root/src/tools/wasm-interp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/wasm-interp.c')
-rw-r--r--src/tools/wasm-interp.c1188
1 files changed, 594 insertions, 594 deletions
diff --git a/src/tools/wasm-interp.c b/src/tools/wasm-interp.c
index 4a8a9c58..aadea1d3 100644
--- a/src/tools/wasm-interp.c
+++ b/src/tools/wasm-interp.c
@@ -35,26 +35,26 @@
static const char* s_trap_strings[] = {FOREACH_INTERPRETER_RESULT(V)};
#undef V
-static WasmBool s_verbose;
+static WabtBool s_verbose;
static const char* s_infile;
-static WasmReadBinaryOptions s_read_binary_options =
- WASM_READ_BINARY_OPTIONS_DEFAULT;
-static WasmInterpreterThreadOptions s_thread_options =
- WASM_INTERPRETER_THREAD_OPTIONS_DEFAULT;
-static WasmBool s_trace;
-static WasmBool s_spec;
-static WasmBool s_run_all_exports;
-static WasmBool s_use_libc_allocator;
-static WasmStream* s_stdout_stream;
+static WabtReadBinaryOptions s_read_binary_options =
+ WABT_READ_BINARY_OPTIONS_DEFAULT;
+static WabtInterpreterThreadOptions s_thread_options =
+ WABT_INTERPRETER_THREAD_OPTIONS_DEFAULT;
+static WabtBool s_trace;
+static WabtBool s_spec;
+static WabtBool s_run_all_exports;
+static WabtBool s_use_libc_allocator;
+static WabtStream* s_stdout_stream;
-static WasmBinaryErrorHandler s_error_handler =
- WASM_BINARY_ERROR_HANDLER_DEFAULT;
+static WabtBinaryErrorHandler s_error_handler =
+ WABT_BINARY_ERROR_HANDLER_DEFAULT;
-static WasmFileWriter s_log_stream_writer;
-static WasmStream s_log_stream;
+static WabtFileWriter s_log_stream_writer;
+static WabtStream s_log_stream;
-#define NOPE WASM_OPTION_NO_ARGUMENT
-#define YEP WASM_OPTION_HAS_ARGUMENT
+#define NOPE WABT_OPTION_NO_ARGUMENT
+#define YEP WABT_OPTION_HAS_ARGUMENT
typedef enum RunVerbosity {
RUN_QUIET = 0,
@@ -94,7 +94,7 @@ static const char s_description[] =
" # value stack size to 100 elements\n"
" $ wasm-interp test.wasm -V 100 --run-all-exports\n";
-static WasmOption s_options[] = {
+static WabtOption s_options[] = {
{FLAG_VERBOSE, 'v', "verbose", NULL, NOPE,
"use multiple times for more info"},
{FLAG_HELP, 'h', "help", NULL, NOPE, "print this help message"},
@@ -110,21 +110,21 @@ static WasmOption s_options[] = {
{FLAG_USE_LIBC_ALLOCATOR, 0, "use-libc-allocator", NULL, NOPE,
"use malloc, free, etc. instead of stack allocator"},
};
-WASM_STATIC_ASSERT(NUM_FLAGS == WASM_ARRAY_SIZE(s_options));
+WABT_STATIC_ASSERT(NUM_FLAGS == WABT_ARRAY_SIZE(s_options));
-static void on_option(struct WasmOptionParser* parser,
- struct WasmOption* option,
+static void on_option(struct WabtOptionParser* parser,
+ struct WabtOption* option,
const char* argument) {
switch (option->id) {
case FLAG_VERBOSE:
s_verbose++;
- wasm_init_file_writer_existing(&s_log_stream_writer, stdout);
- wasm_init_stream(&s_log_stream, &s_log_stream_writer.base, NULL);
+ wabt_init_file_writer_existing(&s_log_stream_writer, stdout);
+ wabt_init_stream(&s_log_stream, &s_log_stream_writer.base, NULL);
s_read_binary_options.log_stream = &s_log_stream;
break;
case FLAG_HELP:
- wasm_print_help(parser, PROGRAM_NAME);
+ wabt_print_help(parser, PROGRAM_NAME);
exit(0);
break;
@@ -139,53 +139,53 @@ static void on_option(struct WasmOptionParser* parser,
break;
case FLAG_TRACE:
- s_trace = WASM_TRUE;
+ s_trace = WABT_TRUE;
break;
case FLAG_SPEC:
- s_spec = WASM_TRUE;
+ s_spec = WABT_TRUE;
break;
case FLAG_RUN_ALL_EXPORTS:
- s_run_all_exports = WASM_TRUE;
+ s_run_all_exports = WABT_TRUE;
break;
case FLAG_USE_LIBC_ALLOCATOR:
- s_use_libc_allocator = WASM_TRUE;
+ s_use_libc_allocator = WABT_TRUE;
break;
}
}
-static void on_argument(struct WasmOptionParser* parser, const char* argument) {
+static void on_argument(struct WabtOptionParser* parser, const char* argument) {
s_infile = argument;
}
-static void on_option_error(struct WasmOptionParser* parser,
+static void on_option_error(struct WabtOptionParser* parser,
const char* message) {
- WASM_FATAL("%s\n", message);
+ WABT_FATAL("%s\n", message);
}
static void parse_options(int argc, char** argv) {
- WasmOptionParser parser;
- WASM_ZERO_MEMORY(parser);
+ WabtOptionParser parser;
+ WABT_ZERO_MEMORY(parser);
parser.description = s_description;
parser.options = s_options;
- parser.num_options = WASM_ARRAY_SIZE(s_options);
+ parser.num_options = WABT_ARRAY_SIZE(s_options);
parser.on_option = on_option;
parser.on_argument = on_argument;
parser.on_error = on_option_error;
- wasm_parse_options(&parser, argc, argv);
+ wabt_parse_options(&parser, argc, argv);
if (s_spec && s_run_all_exports)
- WASM_FATAL("--spec and --run-all-exports are incompatible.\n");
+ WABT_FATAL("--spec and --run-all-exports are incompatible.\n");
if (!s_infile) {
- wasm_print_help(&parser, PROGRAM_NAME);
- WASM_FATAL("No filename given.\n");
+ wabt_print_help(&parser, PROGRAM_NAME);
+ WABT_FATAL("No filename given.\n");
}
}
-static WasmStringSlice get_dirname(const char* s) {
+static WabtStringSlice get_dirname(const char* s) {
/* strip everything after and including the last slash, e.g.:
*
* s = "foo/bar/baz", => "foo/bar"
@@ -196,7 +196,7 @@ static WasmStringSlice get_dirname(const char* s) {
if (last_slash == NULL)
last_slash = s;
- WasmStringSlice result;
+ WabtStringSlice result;
result.start = s;
result.length = last_slash - s;
return result;
@@ -207,27 +207,27 @@ static WasmStringSlice get_dirname(const char* s) {
static void sprint_typed_value(char* buffer,
size_t size,
- const WasmInterpreterTypedValue* tv) {
+ const WabtInterpreterTypedValue* tv) {
switch (tv->type) {
- case WASM_TYPE_I32:
- wasm_snprintf(buffer, size, "i32:%u", tv->value.i32);
+ case WABT_TYPE_I32:
+ wabt_snprintf(buffer, size, "i32:%u", tv->value.i32);
break;
- case WASM_TYPE_I64:
- wasm_snprintf(buffer, size, "i64:%" PRIu64, tv->value.i64);
+ case WABT_TYPE_I64:
+ wabt_snprintf(buffer, size, "i64:%" PRIu64, tv->value.i64);
break;
- case WASM_TYPE_F32: {
+ case WABT_TYPE_F32: {
float value;
memcpy(&value, &tv->value.f32_bits, sizeof(float));
- wasm_snprintf(buffer, size, "f32:%g", value);
+ wabt_snprintf(buffer, size, "f32:%g", value);
break;
}
- case WASM_TYPE_F64: {
+ case WABT_TYPE_F64: {
double value;
memcpy(&value, &tv->value.f64_bits, sizeof(double));
- wasm_snprintf(buffer, size, "f64:%g", value);
+ wabt_snprintf(buffer, size, "f64:%g", value);
break;
}
@@ -237,13 +237,13 @@ static void sprint_typed_value(char* buffer,
}
}
-static void print_typed_value(const WasmInterpreterTypedValue* tv) {
+static void print_typed_value(const WabtInterpreterTypedValue* tv) {
char buffer[MAX_TYPED_VALUE_CHARS];
sprint_typed_value(buffer, sizeof(buffer), tv);
printf("%s", buffer);
}
-static void print_typed_values(const WasmInterpreterTypedValue* values,
+static void print_typed_values(const WabtInterpreterTypedValue* values,
size_t num_values) {
size_t i;
for (i = 0; i < num_values; ++i) {
@@ -254,26 +254,26 @@ static void print_typed_values(const WasmInterpreterTypedValue* values,
}
static void print_typed_value_vector(
- const WasmInterpreterTypedValueVector* values) {
+ const WabtInterpreterTypedValueVector* values) {
print_typed_values(&values->data[0], values->size);
}
static void print_interpreter_result(const char* desc,
- WasmInterpreterResult iresult) {
+ WabtInterpreterResult iresult) {
printf("%s: %s\n", desc, s_trap_strings[iresult]);
}
-static void print_call(WasmStringSlice module_name,
- WasmStringSlice func_name,
- const WasmInterpreterTypedValueVector* args,
- const WasmInterpreterTypedValueVector* results,
- WasmInterpreterResult iresult) {
+static void print_call(WabtStringSlice module_name,
+ WabtStringSlice func_name,
+ const WabtInterpreterTypedValueVector* args,
+ const WabtInterpreterTypedValueVector* results,
+ WabtInterpreterResult iresult) {
if (module_name.length)
- printf(PRIstringslice ".", WASM_PRINTF_STRING_SLICE_ARG(module_name));
- printf(PRIstringslice "(", WASM_PRINTF_STRING_SLICE_ARG(func_name));
+ printf(PRIstringslice ".", WABT_PRINTF_STRING_SLICE_ARG(module_name));
+ printf(PRIstringslice "(", WABT_PRINTF_STRING_SLICE_ARG(func_name));
print_typed_value_vector(args);
printf(") =>");
- if (iresult == WASM_INTERPRETER_OK) {
+ if (iresult == WABT_INTERPRETER_OK) {
if (results->size > 0) {
printf(" ");
print_typed_value_vector(results);
@@ -284,58 +284,58 @@ static void print_call(WasmStringSlice module_name,
}
}
-static WasmInterpreterResult run_defined_function(WasmInterpreterThread* thread,
+static WabtInterpreterResult run_defined_function(WabtInterpreterThread* thread,
uint32_t offset) {
thread->pc = offset;
- WasmInterpreterResult iresult = WASM_INTERPRETER_OK;
+ WabtInterpreterResult iresult = WABT_INTERPRETER_OK;
uint32_t quantum = s_trace ? 1 : INSTRUCTION_QUANTUM;
uint32_t* call_stack_return_top = thread->call_stack_top;
- while (iresult == WASM_INTERPRETER_OK) {
+ while (iresult == WABT_INTERPRETER_OK) {
if (s_trace)
- wasm_trace_pc(thread, s_stdout_stream);
- iresult = wasm_run_interpreter(thread, quantum, call_stack_return_top);
+ wabt_trace_pc(thread, s_stdout_stream);
+ iresult = wabt_run_interpreter(thread, quantum, call_stack_return_top);
}
- if (iresult != WASM_INTERPRETER_RETURNED)
+ if (iresult != WABT_INTERPRETER_RETURNED)
return iresult;
/* use OK instead of RETURNED for consistency */
- return WASM_INTERPRETER_OK;
+ return WABT_INTERPRETER_OK;
}
-static WasmInterpreterResult push_args(
- WasmInterpreterThread* thread,
- const WasmInterpreterFuncSignature* sig,
- const WasmInterpreterTypedValueVector* args) {
+static WabtInterpreterResult push_args(
+ WabtInterpreterThread* thread,
+ const WabtInterpreterFuncSignature* sig,
+ const WabtInterpreterTypedValueVector* args) {
if (sig->param_types.size != args->size)
- return WASM_INTERPRETER_ARGUMENT_TYPE_MISMATCH;
+ return WABT_INTERPRETER_ARGUMENT_TYPE_MISMATCH;
size_t i;
for (i = 0; i < sig->param_types.size; ++i) {
if (sig->param_types.data[i] != args->data[i].type)
- return WASM_INTERPRETER_ARGUMENT_TYPE_MISMATCH;
+ return WABT_INTERPRETER_ARGUMENT_TYPE_MISMATCH;
- WasmInterpreterResult iresult =
- wasm_push_thread_value(thread, args->data[i].value);
- if (iresult != WASM_INTERPRETER_OK) {
+ WabtInterpreterResult iresult =
+ wabt_push_thread_value(thread, args->data[i].value);
+ if (iresult != WABT_INTERPRETER_OK) {
thread->value_stack_top = thread->value_stack.data;
return iresult;
}
}
- return WASM_INTERPRETER_OK;
+ return WABT_INTERPRETER_OK;
}
-static void copy_results(WasmAllocator* allocator,
- WasmInterpreterThread* thread,
- const WasmInterpreterFuncSignature* sig,
- WasmInterpreterTypedValueVector* out_results) {
+static void copy_results(WabtAllocator* allocator,
+ WabtInterpreterThread* thread,
+ const WabtInterpreterFuncSignature* sig,
+ WabtInterpreterTypedValueVector* out_results) {
size_t expected_results = sig->result_types.size;
size_t value_stack_depth = thread->value_stack_top - thread->value_stack.data;
- WASM_USE(value_stack_depth);
+ WABT_USE(value_stack_depth);
assert(expected_results == value_stack_depth);
/* Don't clear out the vector, in case it is being reused. Just reset the
* size to zero. */
out_results->size = 0;
- wasm_resize_interpreter_typed_value_vector(allocator, out_results,
+ wabt_resize_interpreter_typed_value_vector(allocator, out_results,
expected_results);
size_t i;
for (i = 0; i < expected_results; ++i) {
@@ -344,24 +344,24 @@ static void copy_results(WasmAllocator* allocator,
}
}
-static WasmInterpreterResult run_function(
- WasmAllocator* allocator,
- WasmInterpreterThread* thread,
+static WabtInterpreterResult run_function(
+ WabtAllocator* allocator,
+ WabtInterpreterThread* thread,
uint32_t func_index,
- const WasmInterpreterTypedValueVector* args,
- WasmInterpreterTypedValueVector* out_results) {
+ const WabtInterpreterTypedValueVector* args,
+ WabtInterpreterTypedValueVector* out_results) {
assert(func_index < thread->env->funcs.size);
- WasmInterpreterFunc* func = &thread->env->funcs.data[func_index];
+ WabtInterpreterFunc* func = &thread->env->funcs.data[func_index];
uint32_t sig_index = func->sig_index;
assert(sig_index < thread->env->sigs.size);
- WasmInterpreterFuncSignature* sig = &thread->env->sigs.data[sig_index];
+ WabtInterpreterFuncSignature* sig = &thread->env->sigs.data[sig_index];
- WasmInterpreterResult iresult = push_args(thread, sig, args);
- if (iresult == WASM_INTERPRETER_OK) {
+ WabtInterpreterResult iresult = push_args(thread, sig, args);
+ if (iresult == WABT_INTERPRETER_OK) {
iresult = func->is_host
- ? wasm_call_host(thread, func)
+ ? wabt_call_host(thread, func)
: run_defined_function(thread, func->defined.offset);
- if (iresult == WASM_INTERPRETER_OK)
+ if (iresult == WABT_INTERPRETER_OK)
copy_results(allocator, thread, sig, out_results);
}
@@ -371,238 +371,238 @@ static WasmInterpreterResult run_function(
return iresult;
}
-static WasmInterpreterResult run_start_function(WasmAllocator* allocator,
- WasmInterpreterThread* thread,
- WasmInterpreterModule* module) {
- if (module->defined.start_func_index == WASM_INVALID_INDEX)
- return WASM_INTERPRETER_OK;
+static WabtInterpreterResult run_start_function(WabtAllocator* allocator,
+ WabtInterpreterThread* thread,
+ WabtInterpreterModule* module) {
+ if (module->defined.start_func_index == WABT_INVALID_INDEX)
+ return WABT_INTERPRETER_OK;
if (s_trace)
printf(">>> running start function:\n");
- WasmInterpreterTypedValueVector args;
- WasmInterpreterTypedValueVector results;
- WASM_ZERO_MEMORY(args);
- WASM_ZERO_MEMORY(results);
+ WabtInterpreterTypedValueVector args;
+ WabtInterpreterTypedValueVector results;
+ WABT_ZERO_MEMORY(args);
+ WABT_ZERO_MEMORY(results);
- WasmInterpreterResult iresult = run_function(
+ WabtInterpreterResult iresult = run_function(
allocator, thread, module->defined.start_func_index, &args, &results);
assert(results.size == 0);
return iresult;
}
-static WasmInterpreterResult run_export(
- WasmAllocator* allocator,
- WasmInterpreterThread* thread,
- const WasmInterpreterExport* export,
- const WasmInterpreterTypedValueVector* args,
- WasmInterpreterTypedValueVector* out_results) {
+static WabtInterpreterResult run_export(
+ WabtAllocator* allocator,
+ WabtInterpreterThread* thread,
+ const WabtInterpreterExport* export,
+ const WabtInterpreterTypedValueVector* args,
+ WabtInterpreterTypedValueVector* out_results) {
if (s_trace) {
printf(">>> running export \"" PRIstringslice "\":\n",
- WASM_PRINTF_STRING_SLICE_ARG(export->name));
+ WABT_PRINTF_STRING_SLICE_ARG(export->name));
}
- assert(export->kind == WASM_EXTERNAL_KIND_FUNC);
+ assert(export->kind == WABT_EXTERNAL_KIND_FUNC);
return run_function(allocator, thread, export->index, args, out_results);
}
-static WasmInterpreterResult run_export_by_name(
- WasmAllocator* allocator,
- WasmInterpreterThread* thread,
- WasmInterpreterModule* module,
- const WasmStringSlice* name,
- const WasmInterpreterTypedValueVector* args,
- WasmInterpreterTypedValueVector* out_results,
+static WabtInterpreterResult run_export_by_name(
+ WabtAllocator* allocator,
+ WabtInterpreterThread* thread,
+ WabtInterpreterModule* module,
+ const WabtStringSlice* name,
+ const WabtInterpreterTypedValueVector* args,
+ WabtInterpreterTypedValueVector* out_results,
RunVerbosity verbose) {
- WasmInterpreterExport* export =
- wasm_get_interpreter_export_by_name(module, name);
+ WabtInterpreterExport* export =
+ wabt_get_interpreter_export_by_name(module, name);
if (!export)
- return WASM_INTERPRETER_UNKNOWN_EXPORT;
- if (export->kind != WASM_EXTERNAL_KIND_FUNC)
- return WASM_INTERPRETER_EXPORT_KIND_MISMATCH;
+ return WABT_INTERPRETER_UNKNOWN_EXPORT;
+ if (export->kind != WABT_EXTERNAL_KIND_FUNC)
+ return WABT_INTERPRETER_EXPORT_KIND_MISMATCH;
return run_export(allocator, thread, export, args, out_results);
}
-static WasmInterpreterResult get_global_export_by_name(
- WasmAllocator* allocator,
- WasmInterpreterThread* thread,
- WasmInterpreterModule* module,
- const WasmStringSlice* name,
- WasmInterpreterTypedValueVector* out_results) {
- WasmInterpreterExport* export =
- wasm_get_interpreter_export_by_name(module, name);
+static WabtInterpreterResult get_global_export_by_name(
+ WabtAllocator* allocator,
+ WabtInterpreterThread* thread,
+ WabtInterpreterModule* module,
+ const WabtStringSlice* name,
+ WabtInterpreterTypedValueVector* out_results) {
+ WabtInterpreterExport* export =
+ wabt_get_interpreter_export_by_name(module, name);
if (!export)
- return WASM_INTERPRETER_UNKNOWN_EXPORT;
- if (export->kind != WASM_EXTERNAL_KIND_GLOBAL)
- return WASM_INTERPRETER_EXPORT_KIND_MISMATCH;
+ return WABT_INTERPRETER_UNKNOWN_EXPORT;
+ if (export->kind != WABT_EXTERNAL_KIND_GLOBAL)
+ return WABT_INTERPRETER_EXPORT_KIND_MISMATCH;
assert(export->index < thread->env->globals.size);
- WasmInterpreterGlobal* global = &thread->env->globals.data[export->index];
+ WabtInterpreterGlobal* global = &thread->env->globals.data[export->index];
/* Don't clear out the vector, in case it is being reused. Just reset the
* size to zero. */
out_results->size = 0;
- wasm_append_interpreter_typed_value_value(allocator, out_results,
+ wabt_append_interpreter_typed_value_value(allocator, out_results,
&global->typed_value);
- return WASM_INTERPRETER_OK;
+ return WABT_INTERPRETER_OK;
}
-static void run_all_exports(WasmAllocator* allocator,
- WasmInterpreterModule* module,
- WasmInterpreterThread* thread,
+static void run_all_exports(WabtAllocator* allocator,
+ WabtInterpreterModule* module,
+ WabtInterpreterThread* thread,
RunVerbosity verbose) {
- WasmInterpreterTypedValueVector args;
- WasmInterpreterTypedValueVector results;
- WASM_ZERO_MEMORY(args);
- WASM_ZERO_MEMORY(results);
+ WabtInterpreterTypedValueVector args;
+ WabtInterpreterTypedValueVector results;
+ WABT_ZERO_MEMORY(args);
+ WABT_ZERO_MEMORY(results);
uint32_t i;
for (i = 0; i < module->exports.size; ++i) {
- WasmInterpreterExport* export = &module->exports.data[i];
- WasmInterpreterResult iresult =
+ WabtInterpreterExport* export = &module->exports.data[i];
+ WabtInterpreterResult iresult =
run_export(allocator, thread, export, &args, &results);
if (verbose) {
- print_call(wasm_empty_string_slice(), export->name, &args, &results,
+ print_call(wabt_empty_string_slice(), export->name, &args, &results,
iresult);
}
}
- wasm_destroy_interpreter_typed_value_vector(allocator, &args);
- wasm_destroy_interpreter_typed_value_vector(allocator, &results);
+ wabt_destroy_interpreter_typed_value_vector(allocator, &args);
+ wabt_destroy_interpreter_typed_value_vector(allocator, &results);
}
-static WasmResult read_module(WasmAllocator* allocator,
+static WabtResult read_module(WabtAllocator* allocator,
const char* module_filename,
- WasmInterpreterEnvironment* env,
- WasmBinaryErrorHandler* error_handler,
- WasmInterpreterModule** out_module) {
- WasmResult result;
+ WabtInterpreterEnvironment* env,
+ WabtBinaryErrorHandler* error_handler,
+ WabtInterpreterModule** out_module) {
+ WabtResult result;
void* data;
size_t size;
*out_module = NULL;
- result = wasm_read_file(allocator, module_filename, &data, &size);
- if (WASM_SUCCEEDED(result)) {
- WasmAllocator* memory_allocator = &g_wasm_libc_allocator;
- result = wasm_read_binary_interpreter(allocator, memory_allocator, env,
+ result = wabt_read_file(allocator, module_filename, &data, &size);
+ if (WABT_SUCCEEDED(result)) {
+ WabtAllocator* memory_allocator = &g_wabt_libc_allocator;
+ result = wabt_read_binary_interpreter(allocator, memory_allocator, env,
data, size, &s_read_binary_options,
error_handler, out_module);
- if (WASM_SUCCEEDED(result)) {
+ if (WABT_SUCCEEDED(result)) {
if (s_verbose)
- wasm_disassemble_module(env, s_stdout_stream, *out_module);
+ wabt_disassemble_module(env, s_stdout_stream, *out_module);
}
- wasm_free(allocator, data);
+ wabt_free(allocator, data);
}
return result;
}
-static WasmResult default_host_callback(const WasmInterpreterFunc* func,
- const WasmInterpreterFuncSignature* sig,
+static WabtResult default_host_callback(const 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) {
- memset(out_results, 0, sizeof(WasmInterpreterTypedValue) * num_results);
+ memset(out_results, 0, sizeof(WabtInterpreterTypedValue) * num_results);
uint32_t i;
for (i = 0; i < num_results; ++i)
out_results[i].type = sig->result_types.data[i];
- WasmInterpreterTypedValueVector vec_args;
+ WabtInterpreterTypedValueVector vec_args;
vec_args.size = num_args;
vec_args.data = args;
- WasmInterpreterTypedValueVector vec_results;
+ WabtInterpreterTypedValueVector vec_results;
vec_results.size = num_results;
vec_results.data = out_results;
printf("called host ");
print_call(func->host.module_name, func->host.field_name, &vec_args,
- &vec_results, WASM_INTERPRETER_OK);
- return WASM_OK;
+ &vec_results, WABT_INTERPRETER_OK);
+ return WABT_OK;
}
#define PRIimport "\"" PRIstringslice "." PRIstringslice "\""
#define PRINTF_IMPORT_ARG(x) \
- WASM_PRINTF_STRING_SLICE_ARG((x).module_name) \
- , WASM_PRINTF_STRING_SLICE_ARG((x).field_name)
+ WABT_PRINTF_STRING_SLICE_ARG((x).module_name) \
+ , WABT_PRINTF_STRING_SLICE_ARG((x).field_name)
-static void WASM_PRINTF_FORMAT(2, 3)
- print_error(WasmPrintErrorCallback callback, const char* format, ...) {
- WASM_SNPRINTF_ALLOCA(buffer, length, format);
+static void WABT_PRINTF_FORMAT(2, 3)
+ print_error(WabtPrintErrorCallback callback, const char* format, ...) {
+ WABT_SNPRINTF_ALLOCA(buffer, length, format);
callback.print_error(buffer, callback.user_data);
}
-static WasmResult spectest_import_func(WasmInterpreterImport* import,
- WasmInterpreterFunc* func,
- WasmInterpreterFuncSignature* sig,
- WasmPrintErrorCallback callback,
+static WabtResult spectest_import_func(WabtInterpreterImport* import,
+ WabtInterpreterFunc* func,
+ WabtInterpreterFuncSignature* sig,
+ WabtPrintErrorCallback callback,
void* user_data) {
- if (wasm_string_slice_eq_cstr(&import->field_name, "print")) {
+ if (wabt_string_slice_eq_cstr(&import->field_name, "print")) {
func->host.callback = default_host_callback;
- return WASM_OK;
+ return WABT_OK;
} else {
print_error(callback, "unknown host function import " PRIimport,
PRINTF_IMPORT_ARG(*import));
- return WASM_ERROR;
+ return WABT_ERROR;
}
}
-static WasmResult spectest_import_table(WasmInterpreterImport* import,
- WasmInterpreterTable* table,
- WasmPrintErrorCallback callback,
+static WabtResult spectest_import_table(WabtInterpreterImport* import,
+ WabtInterpreterTable* table,
+ WabtPrintErrorCallback callback,
void* user_data) {
- if (wasm_string_slice_eq_cstr(&import->field_name, "table")) {
- table->limits.has_max = WASM_TRUE;
+ if (wabt_string_slice_eq_cstr(&import->field_name, "table")) {
+ table->limits.has_max = WABT_TRUE;
table->limits.initial = 10;
table->limits.max = 20;
- return WASM_OK;
+ return WABT_OK;
} else {
print_error(callback, "unknown host table import " PRIimport,
PRINTF_IMPORT_ARG(*import));
- return WASM_ERROR;
+ return WABT_ERROR;
}
}
-static WasmResult spectest_import_memory(WasmInterpreterImport* import,
- WasmInterpreterMemory* memory,
- WasmPrintErrorCallback callback,
+static WabtResult spectest_import_memory(WabtInterpreterImport* import,
+ WabtInterpreterMemory* memory,
+ WabtPrintErrorCallback callback,
void* user_data) {
- if (wasm_string_slice_eq_cstr(&import->field_name, "memory")) {
- memory->page_limits.has_max = WASM_TRUE;
+ if (wabt_string_slice_eq_cstr(&import->field_name, "memory")) {
+ memory->page_limits.has_max = WABT_TRUE;
memory->page_limits.initial = 1;
memory->page_limits.max = 2;
- memory->byte_size = memory->page_limits.initial * WASM_MAX_PAGES;
- memory->data = wasm_alloc_zero(memory->allocator, memory->byte_size,
- WASM_DEFAULT_ALIGN);
- return WASM_OK;
+ memory->byte_size = memory->page_limits.initial * WABT_MAX_PAGES;
+ memory->data = wabt_alloc_zero(memory->allocator, memory->byte_size,
+ WABT_DEFAULT_ALIGN);
+ return WABT_OK;
} else {
print_error(callback, "unknown host memory import " PRIimport,
PRINTF_IMPORT_ARG(*import));
- return WASM_ERROR;
+ return WABT_ERROR;
}
}
-static WasmResult spectest_import_global(WasmInterpreterImport* import,
- WasmInterpreterGlobal* global,
- WasmPrintErrorCallback callback,
+static WabtResult spectest_import_global(WabtInterpreterImport* import,
+ WabtInterpreterGlobal* global,
+ WabtPrintErrorCallback callback,
void* user_data) {
- if (wasm_string_slice_eq_cstr(&import->field_name, "global")) {
+ if (wabt_string_slice_eq_cstr(&import->field_name, "global")) {
switch (global->typed_value.type) {
- case WASM_TYPE_I32:
+ case WABT_TYPE_I32:
global->typed_value.value.i32 = 666;
break;
- case WASM_TYPE_F32: {
+ case WABT_TYPE_F32: {
float value = 666.6f;
memcpy(&global->typed_value.value.f32_bits, &value, sizeof(value));
break;
}
- case WASM_TYPE_I64:
+ case WABT_TYPE_I64:
global->typed_value.value.i64 = 666;
break;
- case WASM_TYPE_F64: {
+ case WABT_TYPE_F64: {
double value = 666.6;
memcpy(&global->typed_value.value.f64_bits, &value, sizeof(value));
break;
@@ -611,72 +611,72 @@ static WasmResult spectest_import_global(WasmInterpreterImport* import,
default:
print_error(callback, "bad type for host global import " PRIimport,
PRINTF_IMPORT_ARG(*import));
- return WASM_ERROR;
+ return WABT_ERROR;
}
- return WASM_OK;
+ return WABT_OK;
} else {
print_error(callback, "unknown host global import " PRIimport,
PRINTF_IMPORT_ARG(*import));
- return WASM_ERROR;
+ return WABT_ERROR;
}
}
-static void init_environment(WasmAllocator* allocator,
- WasmInterpreterEnvironment* env) {
- wasm_init_interpreter_environment(allocator, env);
- WasmInterpreterModule* host_module = wasm_append_host_module(
- allocator, env, wasm_string_slice_from_cstr("spectest"));
+static void init_environment(WabtAllocator* allocator,
+ WabtInterpreterEnvironment* env) {
+ wabt_init_interpreter_environment(allocator, env);
+ WabtInterpreterModule* host_module = wabt_append_host_module(
+ allocator, env, wabt_string_slice_from_cstr("spectest"));
host_module->host.import_delegate.import_func = spectest_import_func;
host_module->host.import_delegate.import_table = spectest_import_table;
host_module->host.import_delegate.import_memory = spectest_import_memory;
host_module->host.import_delegate.import_global = spectest_import_global;
}
-static WasmResult read_and_run_module(WasmAllocator* allocator,
+static WabtResult read_and_run_module(WabtAllocator* allocator,
const char* module_filename) {
- WasmResult result;
- WasmInterpreterEnvironment env;
- WasmInterpreterModule* module = NULL;
- WasmInterpreterThread thread;
+ WabtResult result;
+ WabtInterpreterEnvironment env;
+ WabtInterpreterModule* module = NULL;
+ WabtInterpreterThread thread;
init_environment(allocator, &env);
- wasm_init_interpreter_thread(allocator, &env, &thread, &s_thread_options);
+ wabt_init_interpreter_thread(allocator, &env, &thread, &s_thread_options);
result =
read_module(allocator, module_filename, &env, &s_error_handler, &module);
- if (WASM_SUCCEEDED(result)) {
- WasmInterpreterResult iresult =
+ if (WABT_SUCCEEDED(result)) {
+ WabtInterpreterResult iresult =
run_start_function(allocator, &thread, module);
- if (iresult == WASM_INTERPRETER_OK) {
+ if (iresult == WABT_INTERPRETER_OK) {
if (s_run_all_exports)
run_all_exports(allocator, module, &thread, RUN_VERBOSE);
} else {
print_interpreter_result("error running start function", iresult);
}
}
- wasm_destroy_interpreter_thread(allocator, &thread);
- wasm_destroy_interpreter_environment(allocator, &env);
+ wabt_destroy_interpreter_thread(allocator, &thread);
+ wabt_destroy_interpreter_environment(allocator, &env);
return result;
}
-WASM_DEFINE_VECTOR(interpreter_thread, WasmInterpreterThread);
+WABT_DEFINE_VECTOR(interpreter_thread, WabtInterpreterThread);
/* An extremely simple JSON parser that only knows how to parse the expected
- * format from wast2wasm. */
+ * format from wast2wabt. */
typedef struct Context {
- WasmAllocator* allocator;
- WasmInterpreterEnvironment env;
- WasmInterpreterThread thread;
- WasmInterpreterModule* last_module;
+ WabtAllocator* allocator;
+ WabtInterpreterEnvironment env;
+ WabtInterpreterThread thread;
+ WabtInterpreterModule* last_module;
/* Parsing info */
char* json_data;
size_t json_data_size;
- WasmStringSlice source_filename;
+ WabtStringSlice source_filename;
size_t json_offset;
- WasmLocation loc;
- WasmLocation prev_loc;
- WasmBool has_prev_loc;
+ WabtLocation loc;
+ WabtLocation prev_loc;
+ WabtBool has_prev_loc;
uint32_t command_line_number;
/* Test info */
@@ -691,15 +691,15 @@ typedef enum ActionType {
typedef struct Action {
ActionType type;
- WasmStringSlice module_name;
- WasmStringSlice field_name;
- WasmInterpreterTypedValueVector args;
+ WabtStringSlice module_name;
+ WabtStringSlice field_name;
+ WabtInterpreterTypedValueVector args;
} Action;
#define CHECK_RESULT(x) \
do { \
- if (WASM_FAILED(x)) \
- return WASM_ERROR; \
+ if (WABT_FAILED(x)) \
+ return WABT_ERROR; \
} while (0)
#define EXPECT(x) CHECK_RESULT(expect(ctx, x))
@@ -707,18 +707,18 @@ typedef struct Action {
#define PARSE_KEY_STRING_VALUE(key, value) \
CHECK_RESULT(parse_key_string_value(ctx, key, value))
-static void WASM_PRINTF_FORMAT(2, 3)
+static void WABT_PRINTF_FORMAT(2, 3)
print_parse_error(Context* ctx, const char* format, ...) {
- WASM_SNPRINTF_ALLOCA(buffer, length, format);
+ WABT_SNPRINTF_ALLOCA(buffer, length, format);
fprintf(stderr, "%s:%d:%d: %s\n", ctx->loc.filename, ctx->loc.line,
ctx->loc.first_column, buffer);
}
-static void WASM_PRINTF_FORMAT(2, 3)
+static void WABT_PRINTF_FORMAT(2, 3)
print_command_error(Context* ctx, const char* format, ...) {
- WASM_SNPRINTF_ALLOCA(buffer, length, format);
+ WABT_SNPRINTF_ALLOCA(buffer, length, format);
printf(PRIstringslice ":%u: %s\n",
- WASM_PRINTF_STRING_SLICE_ARG(ctx->source_filename),
+ WABT_PRINTF_STRING_SLICE_ARG(ctx->source_filename),
ctx->command_line_number, buffer);
}
@@ -726,7 +726,7 @@ static void putback_char(Context* ctx) {
assert(ctx->has_prev_loc);
ctx->json_offset--;
ctx->loc = ctx->prev_loc;
- ctx->has_prev_loc = WASM_FALSE;
+ ctx->has_prev_loc = WABT_FALSE;
}
static int read_char(Context* ctx) {
@@ -740,7 +740,7 @@ static int read_char(Context* ctx) {
} else {
ctx->loc.first_column++;
}
- ctx->has_prev_loc = WASM_TRUE;
+ ctx->has_prev_loc = WABT_TRUE;
return c;
}
@@ -763,42 +763,42 @@ static void skip_whitespace(Context* ctx) {
}
}
-static WasmBool match(Context* ctx, const char* s) {
+static WabtBool match(Context* ctx, const char* s) {
skip_whitespace(ctx);
- WasmLocation start_loc = ctx->loc;
+ WabtLocation start_loc = ctx->loc;
size_t start_offset = ctx->json_offset;
while (*s && *s == read_char(ctx))
s++;
if (*s == 0) {
- return WASM_TRUE;
+ return WABT_TRUE;
} else {
ctx->json_offset = start_offset;
ctx->loc = start_loc;
- return WASM_FALSE;
+ return WABT_FALSE;
}
}
-static WasmResult expect(Context* ctx, const char* s) {
+static WabtResult expect(Context* ctx, const char* s) {
if (match(ctx, s)) {
- return WASM_OK;
+ return WABT_OK;
} else {
print_parse_error(ctx, "expected %s", s);
- return WASM_ERROR;
+ return WABT_ERROR;
}
}
-static WasmResult expect_key(Context* ctx, const char* key) {
+static WabtResult expect_key(Context* ctx, const char* key) {
size_t keylen = strlen(key);
size_t quoted_len = keylen + 2 + 1;
char* quoted = alloca(quoted_len);
- wasm_snprintf(quoted, quoted_len, "\"%s\"", key);
+ wabt_snprintf(quoted, quoted_len, "\"%s\"", key);
EXPECT(quoted);
EXPECT(":");
- return WASM_OK;
+ return WABT_OK;
}
-static WasmResult parse_uint32(Context* ctx, uint32_t* out_int) {
+static WabtResult parse_uint32(Context* ctx, uint32_t* out_int) {
uint32_t result = 0;
skip_whitespace(ctx);
while (1) {
@@ -808,7 +808,7 @@ static WasmResult parse_uint32(Context* ctx, uint32_t* out_int) {
result = result * 10 + (uint32_t)(c - '0');
if (result < last_result) {
print_parse_error(ctx, "uint32 overflow");
- return WASM_ERROR;
+ return WABT_ERROR;
}
} else {
putback_char(ctx);
@@ -816,18 +816,18 @@ static WasmResult parse_uint32(Context* ctx, uint32_t* out_int) {
}
}
*out_int = result;
- return WASM_OK;
+ return WABT_OK;
}
-static WasmResult parse_string(Context* ctx, WasmStringSlice* out_string) {
- WASM_ZERO_MEMORY(*out_string);
+static WabtResult parse_string(Context* ctx, WabtStringSlice* out_string) {
+ WABT_ZERO_MEMORY(*out_string);
skip_whitespace(ctx);
if (read_char(ctx) != '"') {
print_parse_error(ctx, "expected string");
- return WASM_ERROR;
+ return WABT_ERROR;
}
- /* Modify json_data in-place so we can use the WasmStringSlice directly
+ /* Modify json_data in-place so we can use the WabtStringSlice directly
* without having to allocate additional memory; this is only necessary when
* the string contains an escape, but we do it always because the code is
* simpler. */
@@ -843,7 +843,7 @@ static WasmResult parse_string(Context* ctx, WasmStringSlice* out_string) {
c = read_char(ctx);
if (c != 'u') {
print_parse_error(ctx, "expected escape: \\uxxxx");
- return WASM_ERROR;
+ return WABT_ERROR;
}
int i;
uint16_t code = 0;
@@ -858,7 +858,7 @@ static WasmResult parse_string(Context* ctx, WasmStringSlice* out_string) {
cval = c - 'A' + 10;
} else {
print_parse_error(ctx, "expected hex char");
- return WASM_ERROR;
+ return WABT_ERROR;
}
code = (code << 4) + cval;
}
@@ -874,78 +874,78 @@ static WasmResult parse_string(Context* ctx, WasmStringSlice* out_string) {
}
}
out_string->length = p - start;
- return WASM_OK;
+ return WABT_OK;
}
-static WasmResult parse_key_string_value(Context* ctx,
+static WabtResult parse_key_string_value(Context* ctx,
const char* key,
- WasmStringSlice* out_string) {
- WASM_ZERO_MEMORY(*out_string);
+ WabtStringSlice* out_string) {
+ WABT_ZERO_MEMORY(*out_string);
EXPECT_KEY(key);
return parse_string(ctx, out_string);
}
-static WasmResult parse_opt_name_string_value(Context* ctx,
- WasmStringSlice* out_string) {
- WASM_ZERO_MEMORY(*out_string);
+static WabtResult parse_opt_name_string_value(Context* ctx,
+ WabtStringSlice* out_string) {
+ WABT_ZERO_MEMORY(*out_string);
if (match(ctx, "\"name\"")) {
EXPECT(":");
CHECK_RESULT(parse_string(ctx, out_string));
EXPECT(",");
}
- return WASM_OK;
+ return WABT_OK;
}
-static WasmResult parse_line(Context* ctx) {
+static WabtResult parse_line(Context* ctx) {
EXPECT_KEY("line");
CHECK_RESULT(parse_uint32(ctx, &ctx->command_line_number));
- return WASM_OK;
+ return WABT_OK;
}
-static WasmResult parse_type_object(Context* ctx, WasmType* out_type) {
- WasmStringSlice type_str;
+static WabtResult parse_type_object(Context* ctx, WabtType* out_type) {
+ WabtStringSlice type_str;
EXPECT("{");
PARSE_KEY_STRING_VALUE("type", &type_str);
EXPECT("}");
- if (wasm_string_slice_eq_cstr(&type_str, "i32")) {
- *out_type = WASM_TYPE_I32;
- return WASM_OK;
- } else if (wasm_string_slice_eq_cstr(&type_str, "f32")) {
- *out_type = WASM_TYPE_F32;
- return WASM_OK;
- } else if (wasm_string_slice_eq_cstr(&type_str, "i64")) {
- *out_type = WASM_TYPE_I64;
- return WASM_OK;
- } else if (wasm_string_slice_eq_cstr(&type_str, "f64")) {
- *out_type = WASM_TYPE_F64;
- return WASM_OK;
+ if (wabt_string_slice_eq_cstr(&type_str, "i32")) {
+ *out_type = WABT_TYPE_I32;
+ return WABT_OK;
+ } else if (wabt_string_slice_eq_cstr(&type_str, "f32")) {
+ *out_type = WABT_TYPE_F32;
+ return WABT_OK;
+ } else if (wabt_string_slice_eq_cstr(&type_str, "i64")) {
+ *out_type = WABT_TYPE_I64;
+ return WABT_OK;
+ } else if (wabt_string_slice_eq_cstr(&type_str, "f64")) {
+ *out_type = WABT_TYPE_F64;
+ return WABT_OK;
} else {
print_parse_error(ctx, "unknown type: \"" PRIstringslice "\"",
- WASM_PRINTF_STRING_SLICE_ARG(type_str));
- return WASM_ERROR;
+ WABT_PRINTF_STRING_SLICE_ARG(type_str));
+ return WABT_ERROR;
}
}
-static WasmResult parse_type_vector(Context* ctx, WasmTypeVector* out_types) {
- WASM_ZERO_MEMORY(*out_types);
+static WabtResult parse_type_vector(Context* ctx, WabtTypeVector* out_types) {
+ WABT_ZERO_MEMORY(*out_types);
EXPECT("[");
- WasmBool first = WASM_TRUE;
+ WabtBool first = WABT_TRUE;
while (!match(ctx, "]")) {
if (!first)
EXPECT(",");
- WasmType type;
+ WabtType type;
CHECK_RESULT(parse_type_object(ctx, &type));
- first = WASM_FALSE;
- wasm_append_type_value(ctx->allocator, out_types, &type);
+ first = WABT_FALSE;
+ wabt_append_type_value(ctx->allocator, out_types, &type);
}
- return WASM_OK;
+ return WABT_OK;
}
-static WasmResult parse_const(Context* ctx,
- WasmInterpreterTypedValue* out_value) {
- WasmStringSlice type_str;
- WasmStringSlice value_str;
+static WabtResult parse_const(Context* ctx,
+ WabtInterpreterTypedValue* out_value) {
+ WabtStringSlice type_str;
+ WabtStringSlice value_str;
EXPECT("{");
PARSE_KEY_STRING_VALUE("type", &type_str);
EXPECT(",");
@@ -955,61 +955,61 @@ static WasmResult parse_const(Context* ctx,
const char* value_start = value_str.start;
const char* value_end = value_str.start + value_str.length;
- if (wasm_string_slice_eq_cstr(&type_str, "i32")) {
+ if (wabt_string_slice_eq_cstr(&type_str, "i32")) {
uint32_t value;
- CHECK_RESULT(wasm_parse_int32(value_start, value_end, &value,
- WASM_PARSE_UNSIGNED_ONLY));
- out_value->type = WASM_TYPE_I32;
+ CHECK_RESULT(wabt_parse_int32(value_start, value_end, &value,
+ WABT_PARSE_UNSIGNED_ONLY));
+ out_value->type = WABT_TYPE_I32;
out_value->value.i32 = value;
- return WASM_OK;
- } else if (wasm_string_slice_eq_cstr(&type_str, "f32")) {
+ return WABT_OK;
+ } else if (wabt_string_slice_eq_cstr(&type_str, "f32")) {
uint32_t value_bits;
- CHECK_RESULT(wasm_parse_int32(value_start, value_end, &value_bits,
- WASM_PARSE_UNSIGNED_ONLY));
- out_value->type = WASM_TYPE_F32;
+ CHECK_RESULT(wabt_parse_int32(value_start, value_end, &value_bits,
+ WABT_PARSE_UNSIGNED_ONLY));
+ out_value->type = WABT_TYPE_F32;
out_value->value.f32_bits = value_bits;
- return WASM_OK;
- } else if (wasm_string_slice_eq_cstr(&type_str, "i64")) {
+ return WABT_OK;
+ } else if (wabt_string_slice_eq_cstr(&type_str, "i64")) {
uint64_t value;
- CHECK_RESULT(wasm_parse_int64(value_start, value_end, &value,
- WASM_PARSE_UNSIGNED_ONLY));
- out_value->type = WASM_TYPE_I64;
+ CHECK_RESULT(wabt_parse_int64(value_start, value_end, &value,
+ WABT_PARSE_UNSIGNED_ONLY));
+ out_value->type = WABT_TYPE_I64;
out_value->value.i64 = value;
- return WASM_OK;
- } else if (wasm_string_slice_eq_cstr(&type_str, "f64")) {
+ return WABT_OK;
+ } else if (wabt_string_slice_eq_cstr(&type_str, "f64")) {
uint64_t value_bits;
- CHECK_RESULT(wasm_parse_int64(value_start, value_end, &value_bits,
- WASM_PARSE_UNSIGNED_ONLY));
- out_value->type = WASM_TYPE_F64;
+ CHECK_RESULT(wabt_parse_int64(value_start, value_end, &value_bits,
+ WABT_PARSE_UNSIGNED_ONLY));
+ out_value->type = WABT_TYPE_F64;
out_value->value.f64_bits = value_bits;
- return WASM_OK;
+ return WABT_OK;
} else {
print_parse_error(ctx, "unknown type: \"" PRIstringslice "\"",
- WASM_PRINTF_STRING_SLICE_ARG(type_str));
- return WASM_ERROR;
+ WABT_PRINTF_STRING_SLICE_ARG(type_str));
+ return WABT_ERROR;
}
}
-static WasmResult parse_const_vector(
+static WabtResult parse_const_vector(
Context* ctx,
- WasmInterpreterTypedValueVector* out_values) {
- WASM_ZERO_MEMORY(*out_values);
+ WabtInterpreterTypedValueVector* out_values) {
+ WABT_ZERO_MEMORY(*out_values);
EXPECT("[");
- WasmBool first = WASM_TRUE;
+ WabtBool first = WABT_TRUE;
while (!match(ctx, "]")) {
if (!first)
EXPECT(",");
- WasmInterpreterTypedValue value;
+ WabtInterpreterTypedValue value;
CHECK_RESULT(parse_const(ctx, &value));
- wasm_append_interpreter_typed_value_value(ctx->allocator, out_values,
+ wabt_append_interpreter_typed_value_value(ctx->allocator, out_values,
&value);
- first = WASM_FALSE;
+ first = WABT_FALSE;
}
- return WASM_OK;
+ return WABT_OK;
}
-static WasmResult parse_action(Context* ctx, Action* out_action) {
- WASM_ZERO_MEMORY(*out_action);
+static WabtResult parse_action(Context* ctx, Action* out_action) {
+ WABT_ZERO_MEMORY(*out_action);
EXPECT_KEY("action");
EXPECT("{");
EXPECT_KEY("type");
@@ -1032,82 +1032,82 @@ static WasmResult parse_action(Context* ctx, Action* out_action) {
CHECK_RESULT(parse_const_vector(ctx, &out_action->args));
}
EXPECT("}");
- return WASM_OK;
+ return WABT_OK;
}
-static char* create_module_path(Context* ctx, WasmStringSlice filename) {
+static char* create_module_path(Context* ctx, WabtStringSlice filename) {
const char* spec_json_filename = ctx->loc.filename;
- WasmStringSlice dirname = get_dirname(spec_json_filename);
+ WabtStringSlice dirname = get_dirname(spec_json_filename);
size_t path_len = dirname.length + 1 + filename.length + 1;
- char* path = wasm_alloc(ctx->allocator, path_len, 1);
+ char* path = wabt_alloc(ctx->allocator, path_len, 1);
if (dirname.length == 0) {
- wasm_snprintf(path, path_len, PRIstringslice,
- WASM_PRINTF_STRING_SLICE_ARG(filename));
+ wabt_snprintf(path, path_len, PRIstringslice,
+ WABT_PRINTF_STRING_SLICE_ARG(filename));
} else {
- wasm_snprintf(path, path_len, PRIstringslice "/" PRIstringslice,
- WASM_PRINTF_STRING_SLICE_ARG(dirname),
- WASM_PRINTF_STRING_SLICE_ARG(filename));
+ wabt_snprintf(path, path_len, PRIstringslice "/" PRIstringslice,
+ WABT_PRINTF_STRING_SLICE_ARG(dirname),
+ WABT_PRINTF_STRING_SLICE_ARG(filename));
}
return path;
}
-static WasmResult on_module_command(Context* ctx,
- WasmStringSlice filename,
- WasmStringSlice name) {
+static WabtResult on_module_command(Context* ctx,
+ WabtStringSlice filename,
+ WabtStringSlice name) {
char* path = create_module_path(ctx, filename);
- WasmInterpreterEnvironmentMark mark =
- wasm_mark_interpreter_environment(&ctx->env);
- WasmResult result = read_module(ctx->allocator, path, &ctx->env,
+ WabtInterpreterEnvironmentMark mark =
+ wabt_mark_interpreter_environment(&ctx->env);
+ WabtResult result = read_module(ctx->allocator, path, &ctx->env,
&s_error_handler, &ctx->last_module);
- if (WASM_FAILED(result)) {
- wasm_reset_interpreter_environment_to_mark(ctx->allocator, &ctx->env, mark);
+ if (WABT_FAILED(result)) {
+ wabt_reset_interpreter_environment_to_mark(ctx->allocator, &ctx->env, mark);
print_command_error(ctx, "error reading module: \"%s\"", path);
- wasm_free(ctx->allocator, path);
- return WASM_ERROR;
+ wabt_free(ctx->allocator, path);
+ return WABT_ERROR;
}
- wasm_free(ctx->allocator, path);
+ wabt_free(ctx->allocator, path);
- WasmInterpreterResult iresult =
+ WabtInterpreterResult iresult =
run_start_function(ctx->allocator, &ctx->thread, ctx->last_module);
- if (iresult != WASM_INTERPRETER_OK) {
- wasm_reset_interpreter_environment_to_mark(ctx->allocator, &ctx->env, mark);
+ if (iresult != WABT_INTERPRETER_OK) {
+ wabt_reset_interpreter_environment_to_mark(ctx->allocator, &ctx->env, mark);
print_interpreter_result("error running start function", iresult);
- return WASM_ERROR;
+ return WABT_ERROR;
}
- if (!wasm_string_slice_is_empty(&name)) {
- ctx->last_module->name = wasm_dup_string_slice(ctx->allocator, name);
+ if (!wabt_string_slice_is_empty(&name)) {
+ ctx->last_module->name = wabt_dup_string_slice(ctx->allocator, name);
/* The binding also needs its own copy of the name. */
- WasmStringSlice binding_name = wasm_dup_string_slice(ctx->allocator, name);
- WasmBinding* binding = wasm_insert_binding(
+ WabtStringSlice binding_name = wabt_dup_string_slice(ctx->allocator, name);
+ WabtBinding* binding = wabt_insert_binding(
ctx->allocator, &ctx->env.module_bindings, &binding_name);
binding->index = ctx->env.modules.size - 1;
}
- return WASM_OK;
+ return WABT_OK;
}
-static WasmResult run_action(Context* ctx,
+static WabtResult run_action(Context* ctx,
Action* action,
- WasmInterpreterResult* out_iresult,
- WasmInterpreterTypedValueVector* out_results,
+ WabtInterpreterResult* out_iresult,
+ WabtInterpreterTypedValueVector* out_results,
RunVerbosity verbose) {
- WASM_ZERO_MEMORY(*out_results);
+ WABT_ZERO_MEMORY(*out_results);
int module_index;
- if (!wasm_string_slice_is_empty(&action->module_name)) {
- module_index = wasm_find_binding_index_by_name(&ctx->env.module_bindings,
+ if (!wabt_string_slice_is_empty(&action->module_name)) {
+ module_index = wabt_find_binding_index_by_name(&ctx->env.module_bindings,
&action->module_name);
} else {
module_index = (int)ctx->env.modules.size - 1;
}
assert(module_index < (int)ctx->env.modules.size);
- WasmInterpreterModule* module = &ctx->env.modules.data[module_index];
+ WabtInterpreterModule* module = &ctx->env.modules.data[module_index];
switch (action->type) {
case ACTION_TYPE_INVOKE:
@@ -1115,115 +1115,115 @@ static WasmResult run_action(Context* ctx,
&action->field_name, &action->args,
out_results, verbose);
if (verbose) {
- print_call(wasm_empty_string_slice(), action->field_name, &action->args,
+ print_call(wabt_empty_string_slice(), action->field_name, &action->args,
out_results, *out_iresult);
}
- return WASM_OK;
+ return WABT_OK;
case ACTION_TYPE_GET: {
*out_iresult =
get_global_export_by_name(ctx->allocator, &ctx->thread, module,
&action->field_name, out_results);
- return WASM_OK;
+ return WABT_OK;
}
default:
print_command_error(ctx, "invalid action type %d", action->type);
- return WASM_ERROR;
+ return WABT_ERROR;
}
}
-static WasmResult on_action_command(Context* ctx, Action* action) {
- WasmInterpreterTypedValueVector results;
- WasmInterpreterResult iresult;
+static WabtResult on_action_command(Context* ctx, Action* action) {
+ WabtInterpreterTypedValueVector results;
+ WabtInterpreterResult iresult;
ctx->total++;
- WasmResult result = run_action(ctx, action, &iresult, &results, RUN_VERBOSE);
- if (WASM_SUCCEEDED(result)) {
- if (iresult == WASM_INTERPRETER_OK) {
+ WabtResult result = run_action(ctx, action, &iresult, &results, RUN_VERBOSE);
+ if (WABT_SUCCEEDED(result)) {
+ if (iresult == WABT_INTERPRETER_OK) {
ctx->passed++;
} else {
print_command_error(ctx, "unexpected trap: %s", s_trap_strings[iresult]);
- result = WASM_ERROR;
+ result = WABT_ERROR;
}
}
- wasm_destroy_interpreter_typed_value_vector(ctx->allocator, &results);
+ wabt_destroy_interpreter_typed_value_vector(ctx->allocator, &results);
return result;
}
-static WasmBinaryErrorHandler* new_custom_error_handler(Context* ctx,
+static WabtBinaryErrorHandler* new_custom_error_handler(Context* ctx,
const char* desc) {
size_t header_size = ctx->source_filename.length + strlen(desc) + 100;
- char* header = wasm_alloc(ctx->allocator, header_size, 1);
- wasm_snprintf(header, header_size, PRIstringslice ":%d: %s passed",
- WASM_PRINTF_STRING_SLICE_ARG(ctx->source_filename),
+ char* header = wabt_alloc(ctx->allocator, header_size, 1);
+ wabt_snprintf(header, header_size, PRIstringslice ":%d: %s passed",
+ WABT_PRINTF_STRING_SLICE_ARG(ctx->source_filename),
ctx->command_line_number, desc);
- WasmDefaultErrorHandlerInfo* info = wasm_alloc_zero(
- ctx->allocator, sizeof(WasmDefaultErrorHandlerInfo), WASM_DEFAULT_ALIGN);
+ WabtDefaultErrorHandlerInfo* info = wabt_alloc_zero(
+ ctx->allocator, sizeof(WabtDefaultErrorHandlerInfo), WABT_DEFAULT_ALIGN);
info->header = header;
info->out_file = stdout;
- info->print_header = WASM_PRINT_ERROR_HEADER_ONCE;
+ info->print_header = WABT_PRINT_ERROR_HEADER_ONCE;
- WasmBinaryErrorHandler* error_handler = wasm_alloc_zero(
- ctx->allocator, sizeof(WasmBinaryErrorHandler), WASM_DEFAULT_ALIGN);
- error_handler->on_error = wasm_default_binary_error_callback;
+ WabtBinaryErrorHandler* error_handler = wabt_alloc_zero(
+ ctx->allocator, sizeof(WabtBinaryErrorHandler), WABT_DEFAULT_ALIGN);
+ error_handler->on_error = wabt_default_binary_error_callback;
error_handler->user_data = info;
return error_handler;
}
static void destroy_custom_error_handler(
- WasmAllocator* allocator,
- WasmBinaryErrorHandler* error_handler) {
- WasmDefaultErrorHandlerInfo* info = error_handler->user_data;
- wasm_free(allocator, (void*)info->header);
- wasm_free(allocator, info);
- wasm_free(allocator, error_handler);
-}
-
-static WasmResult on_assert_malformed_command(Context* ctx,
- WasmStringSlice filename,
- WasmStringSlice text) {
- WasmBinaryErrorHandler* error_handler =
+ WabtAllocator* allocator,
+ WabtBinaryErrorHandler* error_handler) {
+ WabtDefaultErrorHandlerInfo* info = error_handler->user_data;
+ wabt_free(allocator, (void*)info->header);
+ wabt_free(allocator, info);
+ wabt_free(allocator, error_handler);
+}
+
+static WabtResult on_assert_malformed_command(Context* ctx,
+ WabtStringSlice filename,
+ WabtStringSlice text) {
+ WabtBinaryErrorHandler* error_handler =
new_custom_error_handler(ctx, "assert_malformed");
- WasmInterpreterEnvironment env;
- WASM_ZERO_MEMORY(env);
+ WabtInterpreterEnvironment env;
+ WABT_ZERO_MEMORY(env);
init_environment(ctx->allocator, &env);
ctx->total++;
char* path = create_module_path(ctx, filename);
- WasmInterpreterModule* module;
- WasmResult result =
+ WabtInterpreterModule* module;
+ WabtResult result =
read_module(ctx->allocator, path, &env, error_handler, &module);
- if (WASM_FAILED(result)) {
+ if (WABT_FAILED(result)) {
ctx->passed++;
- result = WASM_OK;
+ result = WABT_OK;
} else {
print_command_error(ctx, "expected module to be malformed: \"%s\"", path);
- result = WASM_ERROR;
+ result = WABT_ERROR;
}
- wasm_free(ctx->allocator, path);
- wasm_destroy_interpreter_environment(ctx->allocator, &env);
+ wabt_free(ctx->allocator, path);
+ wabt_destroy_interpreter_environment(ctx->allocator, &env);
destroy_custom_error_handler(ctx->allocator, error_handler);
return result;
}
-static WasmResult on_register_command(Context* ctx,
- WasmStringSlice name,
- WasmStringSlice as) {
+static WabtResult on_register_command(Context* ctx,
+ WabtStringSlice name,
+ WabtStringSlice as) {
int module_index;
- if (!wasm_string_slice_is_empty(&name)) {
+ if (!wabt_string_slice_is_empty(&name)) {
/* The module names can be different than their registered names. We don't
* keep a hash for the module names (just the registered names), so we'll
* just iterate over all the modules to find it. */
size_t i;
module_index = -1;
for (i = 0; i < ctx->env.modules.size; ++i) {
- const WasmStringSlice* module_name = &ctx->env.modules.data[i].name;
- if (!wasm_string_slice_is_empty(module_name) &&
- wasm_string_slices_are_equal(&name, module_name)) {
+ const WabtStringSlice* module_name = &ctx->env.modules.data[i].name;
+ if (!wabt_string_slice_is_empty(module_name) &&
+ wabt_string_slices_are_equal(&name, module_name)) {
module_index = (int)i;
break;
}
@@ -1234,135 +1234,135 @@ static WasmResult on_register_command(Context* ctx,
if (module_index < 0 || module_index >= (int)ctx->env.modules.size) {
print_command_error(ctx, "unknown module in register");
- return WASM_ERROR;
+ return WABT_ERROR;
}
- WasmStringSlice dup_as = wasm_dup_string_slice(ctx->allocator, as);
- WasmBinding* binding = wasm_insert_binding(
+ WabtStringSlice dup_as = wabt_dup_string_slice(ctx->allocator, as);
+ WabtBinding* binding = wabt_insert_binding(
ctx->allocator, &ctx->env.registered_module_bindings, &dup_as);
binding->index = module_index;
- return WASM_OK;
+ return WABT_OK;
}
-static WasmResult on_assert_unlinkable_command(Context* ctx,
- WasmStringSlice filename,
- WasmStringSlice text) {
- WasmBinaryErrorHandler* error_handler =
+static WabtResult on_assert_unlinkable_command(Context* ctx,
+ WabtStringSlice filename,
+ WabtStringSlice text) {
+ WabtBinaryErrorHandler* error_handler =
new_custom_error_handler(ctx, "assert_unlinkable");
ctx->total++;
char* path = create_module_path(ctx, filename);
- WasmInterpreterModule* module;
- WasmInterpreterEnvironmentMark mark =
- wasm_mark_interpreter_environment(&ctx->env);
- WasmResult result =
+ WabtInterpreterModule* module;
+ WabtInterpreterEnvironmentMark mark =
+ wabt_mark_interpreter_environment(&ctx->env);
+ WabtResult result =
read_module(ctx->allocator, path, &ctx->env, error_handler, &module);
- wasm_reset_interpreter_environment_to_mark(ctx->allocator, &ctx->env, mark);
+ wabt_reset_interpreter_environment_to_mark(ctx->allocator, &ctx->env, mark);
- if (WASM_FAILED(result)) {
+ if (WABT_FAILED(result)) {
ctx->passed++;
- result = WASM_OK;
+ result = WABT_OK;
} else {
print_command_error(ctx, "expected module to be unlinkable: \"%s\"", path);
- result = WASM_ERROR;
+ result = WABT_ERROR;
}
- wasm_free(ctx->allocator, path);
+ wabt_free(ctx->allocator, path);
destroy_custom_error_handler(ctx->allocator, error_handler);
return result;
}
-static WasmResult on_assert_invalid_command(Context* ctx,
- WasmStringSlice filename,
- WasmStringSlice text) {
- WasmBinaryErrorHandler* error_handler =
+static WabtResult on_assert_invalid_command(Context* ctx,
+ WabtStringSlice filename,
+ WabtStringSlice text) {
+ WabtBinaryErrorHandler* error_handler =
new_custom_error_handler(ctx, "assert_invalid");
- WasmInterpreterEnvironment env;
- WASM_ZERO_MEMORY(env);
+ WabtInterpreterEnvironment env;
+ WABT_ZERO_MEMORY(env);
init_environment(ctx->allocator, &env);
ctx->total++;
char* path = create_module_path(ctx, filename);
- WasmInterpreterModule* module;
- WasmResult result =
+ WabtInterpreterModule* module;
+ WabtResult result =
read_module(ctx->allocator, path, &env, error_handler, &module);
- if (WASM_FAILED(result)) {
+ if (WABT_FAILED(result)) {
ctx->passed++;
- result = WASM_OK;
+ result = WABT_OK;
} else {
print_command_error(ctx, "expected module to be invalid: \"%s\"", path);
- result = WASM_ERROR;
+ result = WABT_ERROR;
}
- wasm_free(ctx->allocator, path);
- wasm_destroy_interpreter_environment(ctx->allocator, &env);
+ wabt_free(ctx->allocator, path);
+ wabt_destroy_interpreter_environment(ctx->allocator, &env);
destroy_custom_error_handler(ctx->allocator, error_handler);
return result;
}
-static WasmResult on_assert_uninstantiable_command(Context* ctx,
- WasmStringSlice filename,
- WasmStringSlice text) {
+static WabtResult on_assert_uninstantiable_command(Context* ctx,
+ WabtStringSlice filename,
+ WabtStringSlice text) {
ctx->total++;
char* path = create_module_path(ctx, filename);
- WasmInterpreterModule* module;
- WasmInterpreterEnvironmentMark mark =
- wasm_mark_interpreter_environment(&ctx->env);
- WasmResult result =
+ WabtInterpreterModule* module;
+ WabtInterpreterEnvironmentMark mark =
+ wabt_mark_interpreter_environment(&ctx->env);
+ WabtResult result =
read_module(ctx->allocator, path, &ctx->env, &s_error_handler, &module);
- if (WASM_SUCCEEDED(result)) {
- WasmInterpreterResult iresult =
+ if (WABT_SUCCEEDED(result)) {
+ WabtInterpreterResult iresult =
run_start_function(ctx->allocator, &ctx->thread, module);
- if (iresult == WASM_INTERPRETER_OK) {
+ if (iresult == WABT_INTERPRETER_OK) {
print_command_error(ctx, "expected error running start function: \"%s\"",
path);
- result = WASM_ERROR;
+ result = WABT_ERROR;
} else {
ctx->passed++;
- result = WASM_OK;
+ result = WABT_OK;
}
} else {
print_command_error(ctx, "error reading module: \"%s\"", path);
- result = WASM_ERROR;
+ result = WABT_ERROR;
}
- wasm_reset_interpreter_environment_to_mark(ctx->allocator, &ctx->env, mark);
- wasm_free(ctx->allocator, path);
+ wabt_reset_interpreter_environment_to_mark(ctx->allocator, &ctx->env, mark);
+ wabt_free(ctx->allocator, path);
return result;
}
-static WasmBool typed_values_are_equal(const WasmInterpreterTypedValue* tv1,
- const WasmInterpreterTypedValue* tv2) {
+static WabtBool typed_values_are_equal(const WabtInterpreterTypedValue* tv1,
+ const WabtInterpreterTypedValue* tv2) {
if (tv1->type != tv2->type)
- return WASM_FALSE;
+ return WABT_FALSE;
switch (tv1->type) {
- case WASM_TYPE_I32: return tv1->value.i32 == tv2->value.i32;
- case WASM_TYPE_F32: return tv1->value.f32_bits == tv2->value.f32_bits;
- case WASM_TYPE_I64: return tv1->value.i64 == tv2->value.i64;
- case WASM_TYPE_F64: return tv1->value.f64_bits == tv2->value.f64_bits;
- default: assert(0); return WASM_FALSE;
+ case WABT_TYPE_I32: return tv1->value.i32 == tv2->value.i32;
+ case WABT_TYPE_F32: return tv1->value.f32_bits == tv2->value.f32_bits;
+ case WABT_TYPE_I64: return tv1->value.i64 == tv2->value.i64;
+ case WABT_TYPE_F64: return tv1->value.f64_bits == tv2->value.f64_bits;
+ default: assert(0); return WABT_FALSE;
}
}
-static WasmResult on_assert_return_command(
+static WabtResult on_assert_return_command(
Context* ctx,
Action* action,
- WasmInterpreterTypedValueVector* expected) {
- WasmInterpreterTypedValueVector results;
- WasmInterpreterResult iresult;
+ WabtInterpreterTypedValueVector* expected) {
+ WabtInterpreterTypedValueVector results;
+ WabtInterpreterResult iresult;
ctx->total++;
- WasmResult result = run_action(ctx, action, &iresult, &results, RUN_QUIET);
+ WabtResult result = run_action(ctx, action, &iresult, &results, RUN_QUIET);
- if (WASM_SUCCEEDED(result)) {
- if (iresult == WASM_INTERPRETER_OK) {
+ if (WABT_SUCCEEDED(result)) {
+ if (iresult == WABT_INTERPRETER_OK) {
if (results.size == expected->size) {
size_t i;
for (i = 0; i < results.size; ++i) {
- const WasmInterpreterTypedValue* expected_tv = &expected->data[i];
- const WasmInterpreterTypedValue* actual_tv = &results.data[i];
+ const WabtInterpreterTypedValue* expected_tv = &expected->data[i];
+ const WabtInterpreterTypedValue* actual_tv = &results.data[i];
if (!typed_values_are_equal(expected_tv, actual_tv)) {
char expected_str[MAX_TYPED_VALUE_CHARS];
char actual_str[MAX_TYPED_VALUE_CHARS];
@@ -1371,7 +1371,7 @@ static WasmResult on_assert_return_command(
print_command_error(ctx, "mismatch in result %" PRIzd
" of assert_return: expected %s, got %s",
i, expected_str, actual_str);
- result = WASM_ERROR;
+ result = WABT_ERROR;
}
}
} else {
@@ -1379,132 +1379,132 @@ static WasmResult on_assert_return_command(
ctx, "result length mismatch in assert_return: expected %" PRIzd
", got %" PRIzd,
expected->size, results.size);
- result = WASM_ERROR;
+ result = WABT_ERROR;
}
} else {
print_command_error(ctx, "unexpected trap: %s", s_trap_strings[iresult]);
- result = WASM_ERROR;
+ result = WABT_ERROR;
}
}
- if (WASM_SUCCEEDED(result))
+ if (WABT_SUCCEEDED(result))
ctx->passed++;
- wasm_destroy_interpreter_typed_value_vector(ctx->allocator, &results);
+ wabt_destroy_interpreter_typed_value_vector(ctx->allocator, &results);
return result;
}
-static WasmResult on_assert_return_nan_command(Context* ctx, Action* action) {
- WasmInterpreterTypedValueVector results;
- WasmInterpreterResult iresult;
+static WabtResult on_assert_return_nan_command(Context* ctx, Action* action) {
+ WabtInterpreterTypedValueVector results;
+ WabtInterpreterResult iresult;
ctx->total++;
- WasmResult result = run_action(ctx, action, &iresult, &results, RUN_QUIET);
- if (WASM_SUCCEEDED(result)) {
- if (iresult == WASM_INTERPRETER_OK) {
+ WabtResult result = run_action(ctx, action, &iresult, &results, RUN_QUIET);
+ if (WABT_SUCCEEDED(result)) {
+ if (iresult == WABT_INTERPRETER_OK) {
if (results.size != 1) {
print_command_error(ctx, "expected one result, got %" PRIzd,
results.size);
- result = WASM_ERROR;
+ result = WABT_ERROR;
}
- const WasmInterpreterTypedValue* actual = &results.data[0];
+ const WabtInterpreterTypedValue* actual = &results.data[0];
switch (actual->type) {
- case WASM_TYPE_F32:
- if (!is_nan_f32(actual->value.f32_bits)) {
+ case WABT_TYPE_F32:
+ if (!wabt_is_nan_f32(actual->value.f32_bits)) {
char actual_str[MAX_TYPED_VALUE_CHARS];
sprint_typed_value(actual_str, sizeof(actual_str), actual);
print_command_error(ctx, "expected result to be nan, got %s",
actual_str);
- result = WASM_ERROR;
+ result = WABT_ERROR;
}
break;
- case WASM_TYPE_F64:
- if (!is_nan_f64(actual->value.f64_bits)) {
+ case WABT_TYPE_F64:
+ if (!wabt_is_nan_f64(actual->value.f64_bits)) {
char actual_str[MAX_TYPED_VALUE_CHARS];
sprint_typed_value(actual_str, sizeof(actual_str), actual);
print_command_error(ctx, "expected result to be nan, got %s",
actual_str);
- result = WASM_ERROR;
+ result = WABT_ERROR;
}
break;
default:
print_command_error(ctx,
"expected result type to be f32 or f64, got %s",
- wasm_get_type_name(actual->type));
- result = WASM_ERROR;
+ wabt_get_type_name(actual->type));
+ result = WABT_ERROR;
break;
}
} else {
print_command_error(ctx, "unexpected trap: %s", s_trap_strings[iresult]);
- result = WASM_ERROR;
+ result = WABT_ERROR;
}
}
- if (WASM_SUCCEEDED(result))
+ if (WABT_SUCCEEDED(result))
ctx->passed++;
- wasm_destroy_interpreter_typed_value_vector(ctx->allocator, &results);
- return WASM_OK;
+ wabt_destroy_interpreter_typed_value_vector(ctx->allocator, &results);
+ return WABT_OK;
}
-static WasmResult on_assert_trap_command(Context* ctx,
+static WabtResult on_assert_trap_command(Context* ctx,
Action* action,
- WasmStringSlice text) {
- WasmInterpreterTypedValueVector results;
- WasmInterpreterResult iresult;
+ WabtStringSlice text) {
+ WabtInterpreterTypedValueVector results;
+ WabtInterpreterResult iresult;
ctx->total++;
- WasmResult result = run_action(ctx, action, &iresult, &results, RUN_QUIET);
- if (WASM_SUCCEEDED(result)) {
- if (iresult != WASM_INTERPRETER_OK) {
+ WabtResult result = run_action(ctx, action, &iresult, &results, RUN_QUIET);
+ if (WABT_SUCCEEDED(result)) {
+ if (iresult != WABT_INTERPRETER_OK) {
ctx->passed++;
} else {
print_command_error(ctx, "expected trap: \"" PRIstringslice "\"",
- WASM_PRINTF_STRING_SLICE_ARG(text));
- result = WASM_ERROR;
+ WABT_PRINTF_STRING_SLICE_ARG(text));
+ result = WABT_ERROR;
}
}
- wasm_destroy_interpreter_typed_value_vector(ctx->allocator, &results);
+ wabt_destroy_interpreter_typed_value_vector(ctx->allocator, &results);
return result;
}
-static WasmResult on_assert_exhaustion_command(Context* ctx,
+static WabtResult on_assert_exhaustion_command(Context* ctx,
Action* action) {
- WasmInterpreterTypedValueVector results;
- WasmInterpreterResult iresult;
+ WabtInterpreterTypedValueVector results;
+ WabtInterpreterResult iresult;
ctx->total++;
- WasmResult result = run_action(ctx, action, &iresult, &results, RUN_QUIET);
- if (WASM_SUCCEEDED(result)) {
- if (iresult == WASM_INTERPRETER_TRAP_CALL_STACK_EXHAUSTED ||
- iresult == WASM_INTERPRETER_TRAP_VALUE_STACK_EXHAUSTED) {
+ WabtResult result = run_action(ctx, action, &iresult, &results, RUN_QUIET);
+ if (WABT_SUCCEEDED(result)) {
+ if (iresult == WABT_INTERPRETER_TRAP_CALL_STACK_EXHAUSTED ||
+ iresult == WABT_INTERPRETER_TRAP_VALUE_STACK_EXHAUSTED) {
ctx->passed++;
} else {
print_command_error(ctx, "expected call stack exhaustion");
- result = WASM_ERROR;
+ result = WABT_ERROR;
}
}
- wasm_destroy_interpreter_typed_value_vector(ctx->allocator, &results);
+ wabt_destroy_interpreter_typed_value_vector(ctx->allocator, &results);
return result;
}
-static void destroy_action(WasmAllocator* allocator, Action* action) {
- wasm_destroy_interpreter_typed_value_vector(allocator, &action->args);
+static void destroy_action(WabtAllocator* allocator, Action* action) {
+ wabt_destroy_interpreter_typed_value_vector(allocator, &action->args);
}
-static WasmResult parse_command(Context* ctx) {
+static WabtResult parse_command(Context* ctx) {
EXPECT("{");
EXPECT_KEY("type");
if (match(ctx, "\"module\"")) {
- WasmStringSlice name;
- WasmStringSlice filename;
- WASM_ZERO_MEMORY(name);
- WASM_ZERO_MEMORY(filename);
+ WabtStringSlice name;
+ WabtStringSlice filename;
+ WABT_ZERO_MEMORY(name);
+ WABT_ZERO_MEMORY(filename);
EXPECT(",");
CHECK_RESULT(parse_line(ctx));
@@ -1514,7 +1514,7 @@ static WasmResult parse_command(Context* ctx) {
on_module_command(ctx, filename, name);
} else if (match(ctx, "\"action\"")) {
Action action;
- WASM_ZERO_MEMORY(action);
+ WABT_ZERO_MEMORY(action);
EXPECT(",");
CHECK_RESULT(parse_line(ctx));
@@ -1523,10 +1523,10 @@ static WasmResult parse_command(Context* ctx) {
on_action_command(ctx, &action);
destroy_action(ctx->allocator, &action);
} else if (match(ctx, "\"register\"")) {
- WasmStringSlice as;
- WasmStringSlice name;
- WASM_ZERO_MEMORY(as);
- WASM_ZERO_MEMORY(name);
+ WabtStringSlice as;
+ WabtStringSlice name;
+ WABT_ZERO_MEMORY(as);
+ WABT_ZERO_MEMORY(name);
EXPECT(",");
CHECK_RESULT(parse_line(ctx));
@@ -1535,10 +1535,10 @@ static WasmResult parse_command(Context* ctx) {
PARSE_KEY_STRING_VALUE("as", &as);
on_register_command(ctx, name, as);
} else if (match(ctx, "\"assert_malformed\"")) {
- WasmStringSlice filename;
- WasmStringSlice text;
- WASM_ZERO_MEMORY(filename);
- WASM_ZERO_MEMORY(text);
+ WabtStringSlice filename;
+ WabtStringSlice text;
+ WABT_ZERO_MEMORY(filename);
+ WABT_ZERO_MEMORY(text);
EXPECT(",");
CHECK_RESULT(parse_line(ctx));
@@ -1548,8 +1548,8 @@ static WasmResult parse_command(Context* ctx) {
PARSE_KEY_STRING_VALUE("text", &text);
on_assert_malformed_command(ctx, filename, text);
} else if (match(ctx, "\"assert_invalid\"")) {
- WasmStringSlice filename;
- WasmStringSlice text;
+ WabtStringSlice filename;
+ WabtStringSlice text;
EXPECT(",");
CHECK_RESULT(parse_line(ctx));
EXPECT(",");
@@ -1558,10 +1558,10 @@ static WasmResult parse_command(Context* ctx) {
PARSE_KEY_STRING_VALUE("text", &text);
on_assert_invalid_command(ctx, filename, text);
} else if (match(ctx, "\"assert_unlinkable\"")) {
- WasmStringSlice filename;
- WasmStringSlice text;
- WASM_ZERO_MEMORY(filename);
- WASM_ZERO_MEMORY(text);
+ WabtStringSlice filename;
+ WabtStringSlice text;
+ WABT_ZERO_MEMORY(filename);
+ WABT_ZERO_MEMORY(text);
EXPECT(",");
CHECK_RESULT(parse_line(ctx));
@@ -1571,10 +1571,10 @@ static WasmResult parse_command(Context* ctx) {
PARSE_KEY_STRING_VALUE("text", &text);
on_assert_unlinkable_command(ctx, filename, text);
} else if (match(ctx, "\"assert_uninstantiable\"")) {
- WasmStringSlice filename;
- WasmStringSlice text;
- WASM_ZERO_MEMORY(filename);
- WASM_ZERO_MEMORY(text);
+ WabtStringSlice filename;
+ WabtStringSlice text;
+ WABT_ZERO_MEMORY(filename);
+ WABT_ZERO_MEMORY(text);
EXPECT(",");
CHECK_RESULT(parse_line(ctx));
@@ -1585,9 +1585,9 @@ static WasmResult parse_command(Context* ctx) {
on_assert_uninstantiable_command(ctx, filename, text);
} else if (match(ctx, "\"assert_return\"")) {
Action action;
- WasmInterpreterTypedValueVector expected;
- WASM_ZERO_MEMORY(action);
- WASM_ZERO_MEMORY(expected);
+ WabtInterpreterTypedValueVector expected;
+ WABT_ZERO_MEMORY(action);
+ WABT_ZERO_MEMORY(expected);
EXPECT(",");
CHECK_RESULT(parse_line(ctx));
@@ -1597,29 +1597,29 @@ static WasmResult parse_command(Context* ctx) {
EXPECT_KEY("expected");
CHECK_RESULT(parse_const_vector(ctx, &expected));
on_assert_return_command(ctx, &action, &expected);
- wasm_destroy_interpreter_typed_value_vector(ctx->allocator, &expected);
+ wabt_destroy_interpreter_typed_value_vector(ctx->allocator, &expected);
destroy_action(ctx->allocator, &action);
} else if (match(ctx, "\"assert_return_nan\"")) {
Action action;
- WasmTypeVector expected;
- WASM_ZERO_MEMORY(action);
+ WabtTypeVector expected;
+ WABT_ZERO_MEMORY(action);
EXPECT(",");
CHECK_RESULT(parse_line(ctx));
EXPECT(",");
CHECK_RESULT(parse_action(ctx, &action));
EXPECT(",");
- /* Not needed for wasm-interp, but useful for other parsers. */
+ /* Not needed for wabt-interp, but useful for other parsers. */
EXPECT_KEY("expected");
CHECK_RESULT(parse_type_vector(ctx, &expected));
on_assert_return_nan_command(ctx, &action);
- wasm_destroy_type_vector(ctx->allocator, &expected);
+ wabt_destroy_type_vector(ctx->allocator, &expected);
destroy_action(ctx->allocator, &action);
} else if (match(ctx, "\"assert_trap\"")) {
Action action;
- WasmStringSlice text;
- WASM_ZERO_MEMORY(action);
- WASM_ZERO_MEMORY(text);
+ WabtStringSlice text;
+ WABT_ZERO_MEMORY(action);
+ WABT_ZERO_MEMORY(text);
EXPECT(",");
CHECK_RESULT(parse_line(ctx));
@@ -1631,9 +1631,9 @@ static WasmResult parse_command(Context* ctx) {
destroy_action(ctx->allocator, &action);
} else if (match(ctx, "\"assert_exhaustion\"")) {
Action action;
- WasmStringSlice text;
- WASM_ZERO_MEMORY(action);
- WASM_ZERO_MEMORY(text);
+ WabtStringSlice text;
+ WABT_ZERO_MEMORY(action);
+ WABT_ZERO_MEMORY(text);
EXPECT(",");
CHECK_RESULT(parse_line(ctx));
@@ -1643,53 +1643,53 @@ static WasmResult parse_command(Context* ctx) {
destroy_action(ctx->allocator, &action);
} else {
print_command_error(ctx, "unknown command type");
- return WASM_ERROR;
+ return WABT_ERROR;
}
EXPECT("}");
- return WASM_OK;
+ return WABT_OK;
}
-static WasmResult parse_commands(Context* ctx) {
+static WabtResult parse_commands(Context* ctx) {
EXPECT("{");
PARSE_KEY_STRING_VALUE("source_filename", &ctx->source_filename);
EXPECT(",");
EXPECT_KEY("commands");
EXPECT("[");
- WasmBool first = WASM_TRUE;
+ WabtBool first = WABT_TRUE;
while (!match(ctx, "]")) {
if (!first)
EXPECT(",");
CHECK_RESULT(parse_command(ctx));
- first = WASM_FALSE;
+ first = WABT_FALSE;
}
EXPECT("}");
- return WASM_OK;
+ return WABT_OK;
}
static void destroy_context(Context* ctx) {
- wasm_destroy_interpreter_thread(ctx->allocator, &ctx->thread);
- wasm_destroy_interpreter_environment(ctx->allocator, &ctx->env);
- wasm_free(ctx->allocator, ctx->json_data);
+ wabt_destroy_interpreter_thread(ctx->allocator, &ctx->thread);
+ wabt_destroy_interpreter_environment(ctx->allocator, &ctx->env);
+ wabt_free(ctx->allocator, ctx->json_data);
}
-static WasmResult read_and_run_spec_json(WasmAllocator* allocator,
+static WabtResult read_and_run_spec_json(WabtAllocator* allocator,
const char* spec_json_filename) {
Context ctx;
- WASM_ZERO_MEMORY(ctx);
+ WABT_ZERO_MEMORY(ctx);
ctx.allocator = allocator;
ctx.loc.filename = spec_json_filename;
ctx.loc.line = 1;
ctx.loc.first_column = 1;
init_environment(allocator, &ctx.env);
- wasm_init_interpreter_thread(allocator, &ctx.env, &ctx.thread,
+ wabt_init_interpreter_thread(allocator, &ctx.env, &ctx.thread,
&s_thread_options);
void* data;
size_t size;
- WasmResult result =
- wasm_read_file(allocator, spec_json_filename, &data, &size);
- if (WASM_FAILED(result))
- return WASM_ERROR;
+ WabtResult result =
+ wabt_read_file(allocator, spec_json_filename, &data, &size);
+ if (WABT_FAILED(result))
+ return WABT_ERROR;
ctx.json_data = data;
ctx.json_data_size = size;
@@ -1701,28 +1701,28 @@ static WasmResult read_and_run_spec_json(WasmAllocator* allocator,
}
int main(int argc, char** argv) {
- WasmStackAllocator stack_allocator;
- WasmAllocator* allocator;
+ WabtStackAllocator stack_allocator;
+ WabtAllocator* allocator;
- wasm_init_stdio();
+ wabt_init_stdio();
parse_options(argc, argv);
- s_stdout_stream = wasm_init_stdout_stream();
+ s_stdout_stream = wabt_init_stdout_stream();
if (s_use_libc_allocator) {
- allocator = &g_wasm_libc_allocator;
+ allocator = &g_wabt_libc_allocator;
} else {
- wasm_init_stack_allocator(&stack_allocator, &g_wasm_libc_allocator);
+ wabt_init_stack_allocator(&stack_allocator, &g_wabt_libc_allocator);
allocator = &stack_allocator.allocator;
}
- WasmResult result;
+ WabtResult result;
if (s_spec) {
result = read_and_run_spec_json(allocator, s_infile);
} else {
result = read_and_run_module(allocator, s_infile);
}
- wasm_print_allocator_stats(allocator);
- wasm_destroy_allocator(allocator);
+ wabt_print_allocator_stats(allocator);
+ wabt_destroy_allocator(allocator);
return result;
}