summaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/wasm-interp.c259
-rw-r--r--src/tools/wasm-link.c64
-rw-r--r--src/tools/wasm2wast.c38
-rw-r--r--src/tools/wasmdump.c17
-rw-r--r--src/tools/wasmopcodecnt.c110
-rw-r--r--src/tools/wast-desugar.c35
-rw-r--r--src/tools/wast2wasm.c42
7 files changed, 196 insertions, 369 deletions
diff --git a/src/tools/wasm-interp.c b/src/tools/wasm-interp.c
index aadea1d3..782e7190 100644
--- a/src/tools/wasm-interp.c
+++ b/src/tools/wasm-interp.c
@@ -19,13 +19,11 @@
#include <stdio.h>
#include <stdlib.h>
-#include "allocator.h"
#include "binary-reader.h"
#include "binary-reader-interpreter.h"
#include "interpreter.h"
#include "literal.h"
#include "option-parser.h"
-#include "stack-allocator.h"
#include "stream.h"
#define INSTRUCTION_QUANTUM 1000
@@ -44,7 +42,6 @@ static WabtInterpreterThreadOptions s_thread_options =
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 WabtBinaryErrorHandler s_error_handler =
@@ -69,7 +66,6 @@ enum {
FLAG_TRACE,
FLAG_SPEC,
FLAG_RUN_ALL_EXPORTS,
- FLAG_USE_LIBC_ALLOCATOR,
NUM_FLAGS
};
@@ -107,8 +103,6 @@ static WabtOption s_options[] = {
"run spec tests (input file should be .json)"},
{FLAG_RUN_ALL_EXPORTS, 0, "run-all-exports", NULL, NOPE,
"run all the exported functions, in order. useful for testing"},
- {FLAG_USE_LIBC_ALLOCATOR, 0, "use-libc-allocator", NULL, NOPE,
- "use malloc, free, etc. instead of stack allocator"},
};
WABT_STATIC_ASSERT(NUM_FLAGS == WABT_ARRAY_SIZE(s_options));
@@ -149,10 +143,6 @@ static void on_option(struct WabtOptionParser* parser,
case FLAG_RUN_ALL_EXPORTS:
s_run_all_exports = WABT_TRUE;
break;
-
- case FLAG_USE_LIBC_ALLOCATOR:
- s_use_libc_allocator = WABT_TRUE;
- break;
}
}
@@ -323,8 +313,7 @@ static WabtInterpreterResult push_args(
return WABT_INTERPRETER_OK;
}
-static void copy_results(WabtAllocator* allocator,
- WabtInterpreterThread* thread,
+static void copy_results(WabtInterpreterThread* thread,
const WabtInterpreterFuncSignature* sig,
WabtInterpreterTypedValueVector* out_results) {
size_t expected_results = sig->result_types.size;
@@ -335,8 +324,7 @@ static void copy_results(WabtAllocator* allocator,
/* Don't clear out the vector, in case it is being reused. Just reset the
* size to zero. */
out_results->size = 0;
- wabt_resize_interpreter_typed_value_vector(allocator, out_results,
- expected_results);
+ wabt_resize_interpreter_typed_value_vector(out_results, expected_results);
size_t i;
for (i = 0; i < expected_results; ++i) {
out_results->data[i].type = sig->result_types.data[i];
@@ -345,7 +333,6 @@ static void copy_results(WabtAllocator* allocator,
}
static WabtInterpreterResult run_function(
- WabtAllocator* allocator,
WabtInterpreterThread* thread,
uint32_t func_index,
const WabtInterpreterTypedValueVector* args,
@@ -362,7 +349,7 @@ static WabtInterpreterResult run_function(
? wabt_call_host(thread, func)
: run_defined_function(thread, func->defined.offset);
if (iresult == WABT_INTERPRETER_OK)
- copy_results(allocator, thread, sig, out_results);
+ copy_results(thread, sig, out_results);
}
/* Always reset the value and call stacks */
@@ -371,8 +358,7 @@ static WabtInterpreterResult run_function(
return iresult;
}
-static WabtInterpreterResult run_start_function(WabtAllocator* allocator,
- WabtInterpreterThread* thread,
+static WabtInterpreterResult run_start_function(WabtInterpreterThread* thread,
WabtInterpreterModule* module) {
if (module->defined.start_func_index == WABT_INVALID_INDEX)
return WABT_INTERPRETER_OK;
@@ -384,14 +370,13 @@ static WabtInterpreterResult run_start_function(WabtAllocator* allocator,
WABT_ZERO_MEMORY(args);
WABT_ZERO_MEMORY(results);
- WabtInterpreterResult iresult = run_function(
- allocator, thread, module->defined.start_func_index, &args, &results);
+ WabtInterpreterResult iresult =
+ run_function(thread, module->defined.start_func_index, &args, &results);
assert(results.size == 0);
return iresult;
}
static WabtInterpreterResult run_export(
- WabtAllocator* allocator,
WabtInterpreterThread* thread,
const WabtInterpreterExport* export,
const WabtInterpreterTypedValueVector* args,
@@ -402,11 +387,10 @@ static WabtInterpreterResult run_export(
}
assert(export->kind == WABT_EXTERNAL_KIND_FUNC);
- return run_function(allocator, thread, export->index, args, out_results);
+ return run_function(thread, export->index, args, out_results);
}
static WabtInterpreterResult run_export_by_name(
- WabtAllocator* allocator,
WabtInterpreterThread* thread,
WabtInterpreterModule* module,
const WabtStringSlice* name,
@@ -419,11 +403,10 @@ static WabtInterpreterResult run_export_by_name(
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);
+ return run_export(thread, export, args, out_results);
}
static WabtInterpreterResult get_global_export_by_name(
- WabtAllocator* allocator,
WabtInterpreterThread* thread,
WabtInterpreterModule* module,
const WabtStringSlice* name,
@@ -441,13 +424,11 @@ static WabtInterpreterResult get_global_export_by_name(
/* Don't clear out the vector, in case it is being reused. Just reset the
* size to zero. */
out_results->size = 0;
- wabt_append_interpreter_typed_value_value(allocator, out_results,
- &global->typed_value);
+ wabt_append_interpreter_typed_value_value(out_results, &global->typed_value);
return WABT_INTERPRETER_OK;
}
-static void run_all_exports(WabtAllocator* allocator,
- WabtInterpreterModule* module,
+static void run_all_exports(WabtInterpreterModule* module,
WabtInterpreterThread* thread,
RunVerbosity verbose) {
WabtInterpreterTypedValueVector args;
@@ -457,19 +438,17 @@ static void run_all_exports(WabtAllocator* allocator,
uint32_t i;
for (i = 0; i < module->exports.size; ++i) {
WabtInterpreterExport* export = &module->exports.data[i];
- WabtInterpreterResult iresult =
- run_export(allocator, thread, export, &args, &results);
+ WabtInterpreterResult iresult = run_export(thread, export, &args, &results);
if (verbose) {
print_call(wabt_empty_string_slice(), export->name, &args, &results,
iresult);
}
}
- wabt_destroy_interpreter_typed_value_vector(allocator, &args);
- wabt_destroy_interpreter_typed_value_vector(allocator, &results);
+ wabt_destroy_interpreter_typed_value_vector(&args);
+ wabt_destroy_interpreter_typed_value_vector(&results);
}
-static WabtResult read_module(WabtAllocator* allocator,
- const char* module_filename,
+static WabtResult read_module(const char* module_filename,
WabtInterpreterEnvironment* env,
WabtBinaryErrorHandler* error_handler,
WabtInterpreterModule** out_module) {
@@ -479,18 +458,16 @@ static WabtResult read_module(WabtAllocator* allocator,
*out_module = NULL;
- result = wabt_read_file(allocator, module_filename, &data, &size);
+ result = wabt_read_file(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);
+ result = wabt_read_binary_interpreter(
+ env, data, size, &s_read_binary_options, error_handler, out_module);
if (WABT_SUCCEEDED(result)) {
if (s_verbose)
wabt_disassemble_module(env, s_stdout_stream, *out_module);
}
- wabt_free(allocator, data);
+ wabt_free(data);
}
return result;
}
@@ -572,8 +549,7 @@ static WabtResult spectest_import_memory(WabtInterpreterImport* import,
memory->page_limits.initial = 1;
memory->page_limits.max = 2;
memory->byte_size = memory->page_limits.initial * WABT_MAX_PAGES;
- memory->data = wabt_alloc_zero(memory->allocator, memory->byte_size,
- WABT_DEFAULT_ALIGN);
+ memory->data = wabt_alloc_zero(memory->byte_size);
return WABT_OK;
} else {
print_error(callback, "unknown host memory import " PRIimport,
@@ -622,40 +598,36 @@ static WabtResult spectest_import_global(WabtInterpreterImport* import,
}
}
-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"));
+static void init_environment(WabtInterpreterEnvironment* env) {
+ wabt_init_interpreter_environment(env);
+ WabtInterpreterModule* host_module =
+ wabt_append_host_module(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 WabtResult read_and_run_module(WabtAllocator* allocator,
- const char* module_filename) {
+static WabtResult read_and_run_module(const char* module_filename) {
WabtResult result;
WabtInterpreterEnvironment env;
WabtInterpreterModule* module = NULL;
WabtInterpreterThread thread;
- init_environment(allocator, &env);
- wabt_init_interpreter_thread(allocator, &env, &thread, &s_thread_options);
- result =
- read_module(allocator, module_filename, &env, &s_error_handler, &module);
+ init_environment(&env);
+ wabt_init_interpreter_thread(&env, &thread, &s_thread_options);
+ result = read_module(module_filename, &env, &s_error_handler, &module);
if (WABT_SUCCEEDED(result)) {
- WabtInterpreterResult iresult =
- run_start_function(allocator, &thread, module);
+ WabtInterpreterResult iresult = run_start_function(&thread, module);
if (iresult == WABT_INTERPRETER_OK) {
if (s_run_all_exports)
- run_all_exports(allocator, module, &thread, RUN_VERBOSE);
+ run_all_exports(module, &thread, RUN_VERBOSE);
} else {
print_interpreter_result("error running start function", iresult);
}
}
- wabt_destroy_interpreter_thread(allocator, &thread);
- wabt_destroy_interpreter_environment(allocator, &env);
+ wabt_destroy_interpreter_thread(&thread);
+ wabt_destroy_interpreter_environment(&env);
return result;
}
@@ -664,7 +636,6 @@ WABT_DEFINE_VECTOR(interpreter_thread, WabtInterpreterThread);
/* An extremely simple JSON parser that only knows how to parse the expected
* format from wast2wabt. */
typedef struct Context {
- WabtAllocator* allocator;
WabtInterpreterEnvironment env;
WabtInterpreterThread thread;
WabtInterpreterModule* last_module;
@@ -937,7 +908,7 @@ static WabtResult parse_type_vector(Context* ctx, WabtTypeVector* out_types) {
WabtType type;
CHECK_RESULT(parse_type_object(ctx, &type));
first = WABT_FALSE;
- wabt_append_type_value(ctx->allocator, out_types, &type);
+ wabt_append_type_value(out_types, &type);
}
return WABT_OK;
}
@@ -1001,8 +972,7 @@ static WabtResult parse_const_vector(
EXPECT(",");
WabtInterpreterTypedValue value;
CHECK_RESULT(parse_const(ctx, &value));
- wabt_append_interpreter_typed_value_value(ctx->allocator, out_values,
- &value);
+ wabt_append_interpreter_typed_value_value(out_values, &value);
first = WABT_FALSE;
}
return WABT_OK;
@@ -1039,7 +1009,7 @@ static char* create_module_path(Context* ctx, WabtStringSlice filename) {
const char* spec_json_filename = ctx->loc.filename;
WabtStringSlice dirname = get_dirname(spec_json_filename);
size_t path_len = dirname.length + 1 + filename.length + 1;
- char* path = wabt_alloc(ctx->allocator, path_len, 1);
+ char* path = wabt_alloc(path_len);
if (dirname.length == 0) {
wabt_snprintf(path, path_len, PRIstringslice,
@@ -1059,33 +1029,33 @@ static WabtResult on_module_command(Context* ctx,
char* path = create_module_path(ctx, filename);
WabtInterpreterEnvironmentMark mark =
wabt_mark_interpreter_environment(&ctx->env);
- WabtResult result = read_module(ctx->allocator, path, &ctx->env,
- &s_error_handler, &ctx->last_module);
+ WabtResult result =
+ read_module(path, &ctx->env, &s_error_handler, &ctx->last_module);
if (WABT_FAILED(result)) {
- wabt_reset_interpreter_environment_to_mark(ctx->allocator, &ctx->env, mark);
+ wabt_reset_interpreter_environment_to_mark(&ctx->env, mark);
print_command_error(ctx, "error reading module: \"%s\"", path);
- wabt_free(ctx->allocator, path);
+ wabt_free(path);
return WABT_ERROR;
}
- wabt_free(ctx->allocator, path);
+ wabt_free(path);
WabtInterpreterResult iresult =
- run_start_function(ctx->allocator, &ctx->thread, ctx->last_module);
+ run_start_function(&ctx->thread, ctx->last_module);
if (iresult != WABT_INTERPRETER_OK) {
- wabt_reset_interpreter_environment_to_mark(ctx->allocator, &ctx->env, mark);
+ wabt_reset_interpreter_environment_to_mark(&ctx->env, mark);
print_interpreter_result("error running start function", iresult);
return WABT_ERROR;
}
if (!wabt_string_slice_is_empty(&name)) {
- ctx->last_module->name = wabt_dup_string_slice(ctx->allocator, name);
+ ctx->last_module->name = wabt_dup_string_slice(name);
/* The binding also needs its own copy of the name. */
- WabtStringSlice binding_name = wabt_dup_string_slice(ctx->allocator, name);
- WabtBinding* binding = wabt_insert_binding(
- ctx->allocator, &ctx->env.module_bindings, &binding_name);
+ WabtStringSlice binding_name = wabt_dup_string_slice(name);
+ WabtBinding* binding =
+ wabt_insert_binding(&ctx->env.module_bindings, &binding_name);
binding->index = ctx->env.modules.size - 1;
}
return WABT_OK;
@@ -1111,9 +1081,9 @@ static WabtResult run_action(Context* ctx,
switch (action->type) {
case ACTION_TYPE_INVOKE:
- *out_iresult = run_export_by_name(ctx->allocator, &ctx->thread, module,
- &action->field_name, &action->args,
- out_results, verbose);
+ *out_iresult =
+ run_export_by_name(&ctx->thread, module, &action->field_name,
+ &action->args, out_results, verbose);
if (verbose) {
print_call(wabt_empty_string_slice(), action->field_name, &action->args,
out_results, *out_iresult);
@@ -1121,9 +1091,8 @@ static WabtResult run_action(Context* ctx,
return WABT_OK;
case ACTION_TYPE_GET: {
- *out_iresult =
- get_global_export_by_name(ctx->allocator, &ctx->thread, module,
- &action->field_name, out_results);
+ *out_iresult = get_global_export_by_name(
+ &ctx->thread, module, &action->field_name, out_results);
return WABT_OK;
}
@@ -1148,38 +1117,37 @@ static WabtResult on_action_command(Context* ctx, Action* action) {
}
}
- wabt_destroy_interpreter_typed_value_vector(ctx->allocator, &results);
+ wabt_destroy_interpreter_typed_value_vector(&results);
return result;
}
static WabtBinaryErrorHandler* new_custom_error_handler(Context* ctx,
const char* desc) {
size_t header_size = ctx->source_filename.length + strlen(desc) + 100;
- char* header = wabt_alloc(ctx->allocator, header_size, 1);
+ char* header = wabt_alloc(header_size);
wabt_snprintf(header, header_size, PRIstringslice ":%d: %s passed",
WABT_PRINTF_STRING_SLICE_ARG(ctx->source_filename),
ctx->command_line_number, desc);
- WabtDefaultErrorHandlerInfo* info = wabt_alloc_zero(
- ctx->allocator, sizeof(WabtDefaultErrorHandlerInfo), WABT_DEFAULT_ALIGN);
+ WabtDefaultErrorHandlerInfo* info =
+ wabt_alloc_zero(sizeof(WabtDefaultErrorHandlerInfo));
info->header = header;
info->out_file = stdout;
info->print_header = WABT_PRINT_ERROR_HEADER_ONCE;
- WabtBinaryErrorHandler* error_handler = wabt_alloc_zero(
- ctx->allocator, sizeof(WabtBinaryErrorHandler), WABT_DEFAULT_ALIGN);
+ WabtBinaryErrorHandler* error_handler =
+ wabt_alloc_zero(sizeof(WabtBinaryErrorHandler));
error_handler->on_error = wabt_default_binary_error_callback;
error_handler->user_data = info;
return error_handler;
}
static void destroy_custom_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);
+ wabt_free((void*)info->header);
+ wabt_free(info);
+ wabt_free(error_handler);
}
static WabtResult on_assert_malformed_command(Context* ctx,
@@ -1189,13 +1157,12 @@ static WabtResult on_assert_malformed_command(Context* ctx,
new_custom_error_handler(ctx, "assert_malformed");
WabtInterpreterEnvironment env;
WABT_ZERO_MEMORY(env);
- init_environment(ctx->allocator, &env);
+ init_environment(&env);
ctx->total++;
char* path = create_module_path(ctx, filename);
WabtInterpreterModule* module;
- WabtResult result =
- read_module(ctx->allocator, path, &env, error_handler, &module);
+ WabtResult result = read_module(path, &env, error_handler, &module);
if (WABT_FAILED(result)) {
ctx->passed++;
result = WABT_OK;
@@ -1204,9 +1171,9 @@ static WabtResult on_assert_malformed_command(Context* ctx,
result = WABT_ERROR;
}
- wabt_free(ctx->allocator, path);
- wabt_destroy_interpreter_environment(ctx->allocator, &env);
- destroy_custom_error_handler(ctx->allocator, error_handler);
+ wabt_free(path);
+ wabt_destroy_interpreter_environment(&env);
+ destroy_custom_error_handler(error_handler);
return result;
}
@@ -1237,9 +1204,9 @@ static WabtResult on_register_command(Context* ctx,
return WABT_ERROR;
}
- WabtStringSlice dup_as = wabt_dup_string_slice(ctx->allocator, as);
- WabtBinding* binding = wabt_insert_binding(
- ctx->allocator, &ctx->env.registered_module_bindings, &dup_as);
+ WabtStringSlice dup_as = wabt_dup_string_slice(as);
+ WabtBinding* binding =
+ wabt_insert_binding(&ctx->env.registered_module_bindings, &dup_as);
binding->index = module_index;
return WABT_OK;
}
@@ -1255,9 +1222,8 @@ static WabtResult on_assert_unlinkable_command(Context* ctx,
WabtInterpreterModule* module;
WabtInterpreterEnvironmentMark mark =
wabt_mark_interpreter_environment(&ctx->env);
- WabtResult result =
- read_module(ctx->allocator, path, &ctx->env, error_handler, &module);
- wabt_reset_interpreter_environment_to_mark(ctx->allocator, &ctx->env, mark);
+ WabtResult result = read_module(path, &ctx->env, error_handler, &module);
+ wabt_reset_interpreter_environment_to_mark(&ctx->env, mark);
if (WABT_FAILED(result)) {
ctx->passed++;
@@ -1267,8 +1233,8 @@ static WabtResult on_assert_unlinkable_command(Context* ctx,
result = WABT_ERROR;
}
- wabt_free(ctx->allocator, path);
- destroy_custom_error_handler(ctx->allocator, error_handler);
+ wabt_free(path);
+ destroy_custom_error_handler(error_handler);
return result;
}
@@ -1279,13 +1245,12 @@ static WabtResult on_assert_invalid_command(Context* ctx,
new_custom_error_handler(ctx, "assert_invalid");
WabtInterpreterEnvironment env;
WABT_ZERO_MEMORY(env);
- init_environment(ctx->allocator, &env);
+ init_environment(&env);
ctx->total++;
char* path = create_module_path(ctx, filename);
WabtInterpreterModule* module;
- WabtResult result =
- read_module(ctx->allocator, path, &env, error_handler, &module);
+ WabtResult result = read_module(path, &env, error_handler, &module);
if (WABT_FAILED(result)) {
ctx->passed++;
result = WABT_OK;
@@ -1294,9 +1259,9 @@ static WabtResult on_assert_invalid_command(Context* ctx,
result = WABT_ERROR;
}
- wabt_free(ctx->allocator, path);
- wabt_destroy_interpreter_environment(ctx->allocator, &env);
- destroy_custom_error_handler(ctx->allocator, error_handler);
+ wabt_free(path);
+ wabt_destroy_interpreter_environment(&env);
+ destroy_custom_error_handler(error_handler);
return result;
}
@@ -1308,12 +1273,10 @@ static WabtResult on_assert_uninstantiable_command(Context* ctx,
WabtInterpreterModule* module;
WabtInterpreterEnvironmentMark mark =
wabt_mark_interpreter_environment(&ctx->env);
- WabtResult result =
- read_module(ctx->allocator, path, &ctx->env, &s_error_handler, &module);
+ WabtResult result = read_module(path, &ctx->env, &s_error_handler, &module);
if (WABT_SUCCEEDED(result)) {
- WabtInterpreterResult iresult =
- run_start_function(ctx->allocator, &ctx->thread, module);
+ WabtInterpreterResult iresult = run_start_function(&ctx->thread, module);
if (iresult == WABT_INTERPRETER_OK) {
print_command_error(ctx, "expected error running start function: \"%s\"",
path);
@@ -1327,8 +1290,8 @@ static WabtResult on_assert_uninstantiable_command(Context* ctx,
result = WABT_ERROR;
}
- wabt_reset_interpreter_environment_to_mark(ctx->allocator, &ctx->env, mark);
- wabt_free(ctx->allocator, path);
+ wabt_reset_interpreter_environment_to_mark(&ctx->env, mark);
+ wabt_free(path);
return result;
}
@@ -1390,7 +1353,7 @@ static WabtResult on_assert_return_command(
if (WABT_SUCCEEDED(result))
ctx->passed++;
- wabt_destroy_interpreter_typed_value_vector(ctx->allocator, &results);
+ wabt_destroy_interpreter_typed_value_vector(&results);
return result;
}
@@ -1446,7 +1409,7 @@ static WabtResult on_assert_return_nan_command(Context* ctx, Action* action) {
if (WABT_SUCCEEDED(result))
ctx->passed++;
- wabt_destroy_interpreter_typed_value_vector(ctx->allocator, &results);
+ wabt_destroy_interpreter_typed_value_vector(&results);
return WABT_OK;
}
@@ -1468,7 +1431,7 @@ static WabtResult on_assert_trap_command(Context* ctx,
}
}
- wabt_destroy_interpreter_typed_value_vector(ctx->allocator, &results);
+ wabt_destroy_interpreter_typed_value_vector(&results);
return result;
}
@@ -1489,12 +1452,12 @@ static WabtResult on_assert_exhaustion_command(Context* ctx,
}
}
- wabt_destroy_interpreter_typed_value_vector(ctx->allocator, &results);
+ wabt_destroy_interpreter_typed_value_vector(&results);
return result;
}
-static void destroy_action(WabtAllocator* allocator, Action* action) {
- wabt_destroy_interpreter_typed_value_vector(allocator, &action->args);
+static void destroy_action(Action* action) {
+ wabt_destroy_interpreter_typed_value_vector(&action->args);
}
static WabtResult parse_command(Context* ctx) {
@@ -1521,7 +1484,7 @@ static WabtResult parse_command(Context* ctx) {
EXPECT(",");
CHECK_RESULT(parse_action(ctx, &action));
on_action_command(ctx, &action);
- destroy_action(ctx->allocator, &action);
+ destroy_action(&action);
} else if (match(ctx, "\"register\"")) {
WabtStringSlice as;
WabtStringSlice name;
@@ -1597,8 +1560,8 @@ static WabtResult parse_command(Context* ctx) {
EXPECT_KEY("expected");
CHECK_RESULT(parse_const_vector(ctx, &expected));
on_assert_return_command(ctx, &action, &expected);
- wabt_destroy_interpreter_typed_value_vector(ctx->allocator, &expected);
- destroy_action(ctx->allocator, &action);
+ wabt_destroy_interpreter_typed_value_vector(&expected);
+ destroy_action(&action);
} else if (match(ctx, "\"assert_return_nan\"")) {
Action action;
WabtTypeVector expected;
@@ -1613,8 +1576,8 @@ static WabtResult parse_command(Context* ctx) {
EXPECT_KEY("expected");
CHECK_RESULT(parse_type_vector(ctx, &expected));
on_assert_return_nan_command(ctx, &action);
- wabt_destroy_type_vector(ctx->allocator, &expected);
- destroy_action(ctx->allocator, &action);
+ wabt_destroy_type_vector(&expected);
+ destroy_action(&action);
} else if (match(ctx, "\"assert_trap\"")) {
Action action;
WabtStringSlice text;
@@ -1628,7 +1591,7 @@ static WabtResult parse_command(Context* ctx) {
EXPECT(",");
PARSE_KEY_STRING_VALUE("text", &text);
on_assert_trap_command(ctx, &action, text);
- destroy_action(ctx->allocator, &action);
+ destroy_action(&action);
} else if (match(ctx, "\"assert_exhaustion\"")) {
Action action;
WabtStringSlice text;
@@ -1640,7 +1603,7 @@ static WabtResult parse_command(Context* ctx) {
EXPECT(",");
CHECK_RESULT(parse_action(ctx, &action));
on_assert_exhaustion_command(ctx, &action);
- destroy_action(ctx->allocator, &action);
+ destroy_action(&action);
} else {
print_command_error(ctx, "unknown command type");
return WABT_ERROR;
@@ -1667,27 +1630,23 @@ static WabtResult parse_commands(Context* ctx) {
}
static void destroy_context(Context* ctx) {
- wabt_destroy_interpreter_thread(ctx->allocator, &ctx->thread);
- wabt_destroy_interpreter_environment(ctx->allocator, &ctx->env);
- wabt_free(ctx->allocator, ctx->json_data);
+ wabt_destroy_interpreter_thread(&ctx->thread);
+ wabt_destroy_interpreter_environment(&ctx->env);
+ wabt_free(ctx->json_data);
}
-static WabtResult read_and_run_spec_json(WabtAllocator* allocator,
- const char* spec_json_filename) {
+static WabtResult read_and_run_spec_json(const char* spec_json_filename) {
Context 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);
- wabt_init_interpreter_thread(allocator, &ctx.env, &ctx.thread,
- &s_thread_options);
+ init_environment(&ctx.env);
+ wabt_init_interpreter_thread(&ctx.env, &ctx.thread, &s_thread_options);
void* data;
size_t size;
- WabtResult result =
- wabt_read_file(allocator, spec_json_filename, &data, &size);
+ WabtResult result = wabt_read_file(spec_json_filename, &data, &size);
if (WABT_FAILED(result))
return WABT_ERROR;
@@ -1701,28 +1660,14 @@ static WabtResult read_and_run_spec_json(WabtAllocator* allocator,
}
int main(int argc, char** argv) {
- WabtStackAllocator stack_allocator;
- WabtAllocator* allocator;
-
wabt_init_stdio();
parse_options(argc, argv);
s_stdout_stream = wabt_init_stdout_stream();
- if (s_use_libc_allocator) {
- allocator = &g_wabt_libc_allocator;
- } else {
- wabt_init_stack_allocator(&stack_allocator, &g_wabt_libc_allocator);
- allocator = &stack_allocator.allocator;
- }
- WabtResult result;
if (s_spec) {
- result = read_and_run_spec_json(allocator, s_infile);
+ return read_and_run_spec_json(s_infile);
} else {
- result = read_and_run_module(allocator, s_infile);
+ return read_and_run_module(s_infile);
}
-
- wabt_print_allocator_stats(allocator);
- wabt_destroy_allocator(allocator);
- return result;
}
diff --git a/src/tools/wasm-link.c b/src/tools/wasm-link.c
index 07bd20c8..1e65e0f8 100644
--- a/src/tools/wasm-link.c
+++ b/src/tools/wasm-link.c
@@ -16,7 +16,6 @@
#include "wasm-link.h"
-#include "allocator.h"
#include "binary-reader.h"
#include "binding-hash.h"
#include "binary-writer.h"
@@ -62,7 +61,6 @@ typedef struct Context {
WabtStream stream;
WabtLinkerInputBinaryVector inputs;
ssize_t current_section_payload_offset;
- WabtAllocator* allocator;
} Context;
static void on_option(struct WabtOptionParser* parser,
@@ -91,8 +89,7 @@ static void on_option(struct WabtOptionParser* parser,
}
static void on_argument(struct WabtOptionParser* parser, const char* argument) {
- WabtAllocator* allocator = parser->user_data;
- wabt_append_string_value(allocator, &s_infiles, &argument);
+ wabt_append_string_value(&s_infiles, &argument);
}
static void on_option_error(struct WabtOptionParser* parser,
@@ -100,7 +97,7 @@ static void on_option_error(struct WabtOptionParser* parser,
WABT_FATAL("%s\n", message);
}
-static void parse_options(WabtAllocator* allocator, int argc, char** argv) {
+static void parse_options(int argc, char** argv) {
WabtOptionParser parser;
WABT_ZERO_MEMORY(parser);
parser.description = s_description;
@@ -109,7 +106,6 @@ static void parse_options(WabtAllocator* allocator, int argc, char** argv) {
parser.on_option = on_option;
parser.on_argument = on_argument;
parser.on_error = on_option_error;
- parser.user_data = allocator;
wabt_parse_options(&parser, argc, argv);
if (!s_infiles.size) {
@@ -118,25 +114,24 @@ static void parse_options(WabtAllocator* allocator, int argc, char** argv) {
}
}
-void wabt_destroy_section(WabtAllocator* allocator, WabtSection* section) {
- wabt_destroy_reloc_vector(allocator, &section->relocations);
+void wabt_destroy_section(WabtSection* section) {
+ wabt_destroy_reloc_vector(&section->relocations);
switch (section->section_code) {
case WABT_BINARY_SECTION_DATA:
- wabt_destroy_data_segment_vector(allocator, &section->data_segments);
+ wabt_destroy_data_segment_vector(&section->data_segments);
break;
default:
break;
}
}
-void wabt_destroy_binary(WabtAllocator* allocator,
- WabtLinkerInputBinary* binary) {
- WABT_DESTROY_VECTOR_AND_ELEMENTS(allocator, binary->sections, section);
- wabt_destroy_function_import_vector(allocator, &binary->function_imports);
- wabt_destroy_global_import_vector(allocator, &binary->global_imports);
- wabt_destroy_string_slice_vector(allocator, &binary->debug_names);
- wabt_destroy_export_vector(allocator, &binary->exports);
- wabt_free(allocator, binary->data);
+void wabt_destroy_binary(WabtLinkerInputBinary* binary) {
+ WABT_DESTROY_VECTOR_AND_ELEMENTS(binary->sections, section);
+ wabt_destroy_function_import_vector(&binary->function_imports);
+ wabt_destroy_global_import_vector(&binary->global_imports);
+ wabt_destroy_string_slice_vector(&binary->debug_names);
+ wabt_destroy_export_vector(&binary->exports);
+ wabt_free(binary->data);
}
static uint32_t relocate_func_index(WabtLinkerInputBinary* binary,
@@ -631,15 +626,13 @@ static void resolve_symbols(Context* ctx) {
WabtLinkerInputBinary* binary = &ctx->inputs.data[i];
for (j = 0; j < binary->exports.size; j++) {
WabtExport* export = &binary->exports.data[j];
- ExportInfo* info = wabt_append_export_info(ctx->allocator, &export_list);
+ ExportInfo* info = wabt_append_export_info(&export_list);
info->export = export;
info->binary = binary;
/* TODO(sbc): Handle duplicate names */
- WabtStringSlice name =
- wabt_dup_string_slice(ctx->allocator, export->name);
- WabtBinding* binding =
- wabt_insert_binding(ctx->allocator, &export_map, &name);
+ WabtStringSlice name = wabt_dup_string_slice(export->name);
+ WabtBinding* binding = wabt_insert_binding(&export_map, &name);
binding->index = export_list.size - 1;
}
}
@@ -672,8 +665,8 @@ static void resolve_symbols(Context* ctx) {
}
}
- wabt_destroy_export_info_vector(ctx->allocator, &export_list);
- wabt_destroy_binding_hash(ctx->allocator, &export_map);
+ wabt_destroy_export_info_vector(&export_list);
+ wabt_destroy_binding_hash(&export_map);
}
static void calculate_reloc_offsets(Context* ctx) {
@@ -739,7 +732,7 @@ static void write_binary(Context* ctx) {
for (i = 0; i < binary->sections.size; i++) {
WabtSection* s = &binary->sections.data[i];
WabtSectionPtrVector* sec_list = &sections[s->section_code];
- wabt_append_section_ptr_value(ctx->allocator, sec_list, &s);
+ wabt_append_section_ptr_value(sec_list, &s);
}
}
@@ -760,7 +753,7 @@ static void write_binary(Context* ctx) {
}
for (i = 0; i < WABT_NUM_BINARY_SECTIONS; i++) {
- wabt_destroy_section_ptr_vector(ctx->allocator, &sections[i]);
+ wabt_destroy_section_ptr_vector(&sections[i]);
}
}
@@ -789,7 +782,7 @@ static void dump_reloc_offsets(Context* ctx) {
static WabtResult perform_link(Context* ctx) {
WabtMemoryWriter writer;
WABT_ZERO_MEMORY(writer);
- if (WABT_FAILED(wabt_init_mem_writer(ctx->allocator, &writer)))
+ if (WABT_FAILED(wabt_init_mem_writer(&writer)))
WABT_FATAL("unable to open memory writer for writing\n");
WabtStream* log_stream = NULL;
@@ -818,9 +811,8 @@ int main(int argc, char** argv) {
Context context;
WABT_ZERO_MEMORY(context);
- context.allocator = &g_wabt_libc_allocator;
- parse_options(context.allocator, argc, argv);
+ parse_options(argc, argv);
WabtResult result = WABT_OK;
size_t i;
@@ -830,15 +822,14 @@ int main(int argc, char** argv) {
wabt_writef(&s_log_stream, "reading file: %s\n", input_filename);
void* data;
size_t size;
- result = wabt_read_file(context.allocator, input_filename, &data, &size);
+ result = wabt_read_file(input_filename, &data, &size);
if (WABT_FAILED(result))
return result;
- WabtLinkerInputBinary* b =
- wabt_append_binary(context.allocator, &context.inputs);
+ WabtLinkerInputBinary* b = wabt_append_binary(&context.inputs);
b->data = data;
b->size = size;
b->filename = input_filename;
- result = wabt_read_binary_linker(context.allocator, b);
+ result = wabt_read_binary_linker(b);
if (WABT_FAILED(result))
WABT_FATAL("error parsing file: %s\n", input_filename);
}
@@ -848,10 +839,7 @@ int main(int argc, char** argv) {
return result;
/* Cleanup */
- WABT_DESTROY_VECTOR_AND_ELEMENTS(context.allocator, context.inputs, binary);
- wabt_destroy_string_vector(context.allocator, &s_infiles);
-
- wabt_print_allocator_stats(context.allocator);
- wabt_destroy_allocator(context.allocator);
+ WABT_DESTROY_VECTOR_AND_ELEMENTS(context.inputs, binary);
+ wabt_destroy_string_vector(&s_infiles);
return result;
}
diff --git a/src/tools/wasm2wast.c b/src/tools/wasm2wast.c
index 1800b3bb..5015dbbd 100644
--- a/src/tools/wasm2wast.c
+++ b/src/tools/wasm2wast.c
@@ -19,7 +19,6 @@
#include <stdio.h>
#include <stdlib.h>
-#include "allocator.h"
#include "apply-names.h"
#include "ast.h"
#include "ast-writer.h"
@@ -27,7 +26,6 @@
#include "binary-reader-ast.h"
#include "generate-names.h"
#include "option-parser.h"
-#include "stack-allocator.h"
#include "stream.h"
#include "writer.h"
@@ -37,7 +35,6 @@ static int s_verbose;
static const char* s_infile;
static const char* s_outfile;
static WabtReadBinaryOptions s_read_binary_options = {NULL, WABT_TRUE};
-static WabtBool s_use_libc_allocator;
static WabtBool s_generate_names;
static WabtBinaryErrorHandler s_error_handler =
@@ -53,7 +50,6 @@ enum {
FLAG_VERBOSE,
FLAG_HELP,
FLAG_OUTPUT,
- FLAG_USE_LIBC_ALLOCATOR,
FLAG_NO_DEBUG_NAMES,
FLAG_GENERATE_NAMES,
NUM_FLAGS
@@ -76,8 +72,6 @@ static WabtOption s_options[] = {
{FLAG_HELP, 'h', "help", NULL, NOPE, "print this help message"},
{FLAG_OUTPUT, 'o', "output", "FILENAME", YEP,
"output file for the generated wast file, by default use stdout"},
- {FLAG_USE_LIBC_ALLOCATOR, 0, "use-libc-allocator", NULL, NOPE,
- "use malloc, free, etc. instead of stack allocator"},
{FLAG_NO_DEBUG_NAMES, 0, "no-debug-names", NULL, NOPE,
"Ignore debug names in the binary file"},
{FLAG_GENERATE_NAMES, 0, "generate-names", NULL, NOPE,
@@ -105,10 +99,6 @@ static void on_option(struct WabtOptionParser* parser,
s_outfile = argument;
break;
- case FLAG_USE_LIBC_ALLOCATOR:
- s_use_libc_allocator = WABT_TRUE;
- break;
-
case FLAG_NO_DEBUG_NAMES:
s_read_binary_options.read_debug_names = WABT_FALSE;
break;
@@ -147,35 +137,26 @@ static void parse_options(int argc, char** argv) {
int main(int argc, char** argv) {
WabtResult result;
- WabtStackAllocator stack_allocator;
- WabtAllocator* allocator;
wabt_init_stdio();
parse_options(argc, argv);
- if (s_use_libc_allocator) {
- allocator = &g_wabt_libc_allocator;
- } else {
- wabt_init_stack_allocator(&stack_allocator, &g_wabt_libc_allocator);
- allocator = &stack_allocator.allocator;
- }
-
void* data;
size_t size;
- result = wabt_read_file(allocator, s_infile, &data, &size);
+ result = wabt_read_file(s_infile, &data, &size);
if (WABT_SUCCEEDED(result)) {
WabtModule module;
WABT_ZERO_MEMORY(module);
- result = wabt_read_binary_ast(allocator, data, size, &s_read_binary_options,
+ result = wabt_read_binary_ast(data, size, &s_read_binary_options,
&s_error_handler, &module);
if (WABT_SUCCEEDED(result)) {
if (s_generate_names)
- result = wabt_generate_names(allocator, &module);
+ result = wabt_generate_names(&module);
if (WABT_SUCCEEDED(result)) {
/* TODO(binji): This shouldn't fail; if a name can't be applied
* (because the index is invalid, say) it should just be skipped. */
- WabtResult dummy_result = wabt_apply_names(allocator, &module);
+ WabtResult dummy_result = wabt_apply_names(&module);
WABT_USE(dummy_result);
}
@@ -188,18 +169,13 @@ int main(int argc, char** argv) {
}
if (WABT_SUCCEEDED(result)) {
- result = wabt_write_ast(allocator, &file_writer.base, &module);
+ result = wabt_write_ast(&file_writer.base, &module);
wabt_close_file_writer(&file_writer);
}
}
-
- if (s_use_libc_allocator)
- wabt_destroy_module(allocator, &module);
+ wabt_destroy_module(&module);
}
-
- wabt_free(allocator, data);
- wabt_print_allocator_stats(allocator);
- wabt_destroy_allocator(allocator);
+ wabt_free(data);
}
return result;
}
diff --git a/src/tools/wasmdump.c b/src/tools/wasmdump.c
index 564fc00c..fd1488e5 100644
--- a/src/tools/wasmdump.c
+++ b/src/tools/wasmdump.c
@@ -18,7 +18,6 @@
#include <stdlib.h>
#include <string.h>
-#include "allocator.h"
#include "common.h"
#include "option-parser.h"
#include "stream.h"
@@ -143,11 +142,9 @@ int main(int argc, char** argv) {
return 1;
}
- WabtAllocator* allocator = &g_wabt_libc_allocator;
-
void* data;
size_t size;
- WabtResult result = wabt_read_file(allocator, s_objdump_options.infile, &data, &size);
+ WabtResult result = wabt_read_file(s_objdump_options.infile, &data, &size);
if (WABT_FAILED(result))
return result;
@@ -165,14 +162,14 @@ int main(int argc, char** argv) {
}
s_objdump_options.mode = WABT_DUMP_PREPASS;
- result = wabt_read_binary_objdump(allocator, data, size, &s_objdump_options);
+ result = wabt_read_binary_objdump(data, size, &s_objdump_options);
if (WABT_FAILED(result))
goto done;
// Pass 1: Print the section headers
if (s_objdump_options.headers) {
s_objdump_options.mode = WABT_DUMP_HEADERS;
- result = wabt_read_binary_objdump(allocator, data, size, &s_objdump_options);
+ result = wabt_read_binary_objdump(data, size, &s_objdump_options);
if (WABT_FAILED(result))
goto done;
s_objdump_options.print_header = 0;
@@ -180,14 +177,14 @@ int main(int argc, char** argv) {
// Pass 2: Print extra information based on section type
if (s_objdump_options.details) {
s_objdump_options.mode = WABT_DUMP_DETAILS;
- result = wabt_read_binary_objdump(allocator, data, size, &s_objdump_options);
+ result = wabt_read_binary_objdump(data, size, &s_objdump_options);
if (WABT_FAILED(result))
goto done;
s_objdump_options.print_header = 0;
}
if (s_objdump_options.disassemble) {
s_objdump_options.mode = WABT_DUMP_DISASSEMBLE;
- result = wabt_read_binary_objdump(allocator, data, size, &s_objdump_options);
+ result = wabt_read_binary_objdump(data, size, &s_objdump_options);
if (WABT_FAILED(result))
goto done;
s_objdump_options.print_header = 0;
@@ -195,10 +192,10 @@ int main(int argc, char** argv) {
// Pass 3: Dump to raw contents of the sections
if (s_objdump_options.raw) {
s_objdump_options.mode = WABT_DUMP_RAW_DATA;
- result = wabt_read_binary_objdump(allocator, data, size, &s_objdump_options);
+ result = wabt_read_binary_objdump(data, size, &s_objdump_options);
}
done:
- wabt_free(allocator, data);
+ wabt_free(data);
return result;
}
diff --git a/src/tools/wasmopcodecnt.c b/src/tools/wasmopcodecnt.c
index a6dacb89..5d6a4855 100644
--- a/src/tools/wasmopcodecnt.c
+++ b/src/tools/wasmopcodecnt.c
@@ -20,11 +20,9 @@
#include <stdio.h>
#include <stdlib.h>
-#include "allocator.h"
#include "binary-reader.h"
#include "binary-reader-opcnt.h"
#include "option-parser.h"
-#include "stack-allocator.h"
#include "stream.h"
#include "vector-sort.h"
@@ -42,8 +40,6 @@ static const char* s_separator = ": ";
static WabtReadBinaryOptions s_read_binary_options =
WABT_READ_BINARY_OPTIONS_DEFAULT;
-static WabtBool s_use_libc_allocator;
-
static WabtFileWriter s_log_stream_writer;
static WabtStream s_log_stream;
@@ -54,7 +50,6 @@ enum {
FLAG_VERBOSE,
FLAG_HELP,
FLAG_OUTPUT,
- FLAG_USE_LIBC_ALLOCATOR,
FLAG_CUTOFF,
FLAG_SEPARATOR,
NUM_FLAGS
@@ -82,12 +77,6 @@ static WabtOption s_options[] = {
"FILENAME",
YEP,
"output file for the opcode counts, by default use stdout"},
- {FLAG_USE_LIBC_ALLOCATOR,
- 0,
- "use-libc-allocator",
- NULL,
- NOPE,
- "use malloc, free, etc. instead of stack allocator"},
{FLAG_CUTOFF,
'c',
"cutoff",
@@ -124,10 +113,6 @@ static void on_option(struct WabtOptionParser* parser,
s_outfile = argument;
break;
- case FLAG_USE_LIBC_ALLOCATOR:
- s_use_libc_allocator = WABT_TRUE;
- break;
-
case FLAG_CUTOFF:
s_cutoff = atol(argument);
break;
@@ -302,10 +287,12 @@ static int int_pair_counter_gt(WabtIntPairCounter* counter_1,
return 0;
}
-static void display_sorted_int_counter_vector(
- FILE* out, const char* title, struct WabtAllocator* allocator,
- WabtIntCounterVector* vec, int_counter_lt_fcn lt_fcn,
- display_name_fcn display_fcn, const char* opcode_name) {
+static void display_sorted_int_counter_vector(FILE* out,
+ const char* title,
+ WabtIntCounterVector* vec,
+ int_counter_lt_fcn lt_fcn,
+ display_name_fcn display_fcn,
+ const char* opcode_name) {
if (vec->size == 0)
return;
@@ -316,22 +303,25 @@ static void display_sorted_int_counter_vector(
for (i = 0; i < vec->size; ++i) {
if (vec->data[i].count < s_cutoff)
continue;
- wabt_append_int_counter_value(allocator, &filtered_vec, &vec->data[i]);
+ wabt_append_int_counter_value(&filtered_vec, &vec->data[i]);
}
WabtIntCounterVector sorted_vec;
WABT_ZERO_MEMORY(sorted_vec);
- wabt_sort_int_counter_vector(allocator, &filtered_vec, &sorted_vec,
+ wabt_sort_int_counter_vector(&filtered_vec, &sorted_vec,
swap_int_counters, lt_fcn);
fprintf(out, "%s\n", title);
display_int_counter_vector(out, &sorted_vec, display_fcn, opcode_name);
- wabt_destroy_int_counter_vector(allocator, &filtered_vec);
- wabt_destroy_int_counter_vector(allocator, &sorted_vec);
+ wabt_destroy_int_counter_vector(&filtered_vec);
+ wabt_destroy_int_counter_vector(&sorted_vec);
}
static void display_sorted_int_pair_counter_vector(
- FILE* out, const char* title, struct WabtAllocator* allocator,
- WabtIntPairCounterVector* vec, int_pair_counter_lt_fcn lt_fcn,
- display_name_fcn display_first_fcn, display_name_fcn display_second_fcn,
+ FILE* out,
+ const char* title,
+ WabtIntPairCounterVector* vec,
+ int_pair_counter_lt_fcn lt_fcn,
+ display_name_fcn display_first_fcn,
+ display_name_fcn display_second_fcn,
const char* opcode_name) {
if (vec->size == 0)
return;
@@ -343,16 +333,16 @@ static void display_sorted_int_pair_counter_vector(
for (i = 0; i < vec->size; ++i) {
if (vec->data[i].count < s_cutoff)
continue;
- wabt_append_int_pair_counter_value(allocator, &filtered_vec, &vec->data[i]);
+ wabt_append_int_pair_counter_value(&filtered_vec, &vec->data[i]);
}
WABT_ZERO_MEMORY(sorted_vec);
- wabt_sort_int_pair_counter_vector(allocator, &filtered_vec, &sorted_vec,
+ wabt_sort_int_pair_counter_vector(&filtered_vec, &sorted_vec,
swap_int_pair_counters, lt_fcn);
fprintf(out, "%s\n", title);
display_int_pair_counter_vector(out, &sorted_vec, display_first_fcn,
display_second_fcn, opcode_name);
- wabt_destroy_int_pair_counter_vector(allocator, &filtered_vec);
- wabt_destroy_int_pair_counter_vector(allocator, &sorted_vec);
+ wabt_destroy_int_pair_counter_vector(&filtered_vec);
+ wabt_destroy_int_pair_counter_vector(&sorted_vec);
}
int main(int argc, char** argv) {
@@ -360,25 +350,13 @@ int main(int argc, char** argv) {
wabt_init_stdio();
parse_options(argc, argv);
- WabtStackAllocator stack_allocator;
- WabtAllocator *allocator;
- if (s_use_libc_allocator) {
- allocator = &g_wabt_libc_allocator;
- } else {
- wabt_init_stack_allocator(&stack_allocator, &g_wabt_libc_allocator);
- allocator = &stack_allocator.allocator;
- }
-
-
void* data;
size_t size;
- WabtResult result = wabt_read_file(allocator, s_infile, &data, &size);
+ WabtResult result = wabt_read_file(s_infile, &data, &size);
if (WABT_FAILED(result)) {
const char* input_name = s_infile ? s_infile : "stdin";
ERROR("Unable to parse: %s", input_name);
- wabt_free(allocator, data);
- wabt_print_allocator_stats(allocator);
- wabt_destroy_allocator(allocator);
+ wabt_free(data);
}
FILE* out = stdout;
if (s_outfile) {
@@ -389,42 +367,36 @@ int main(int argc, char** argv) {
}
if (WABT_SUCCEEDED(result)) {
WabtOpcntData opcnt_data;
- wabt_init_opcnt_data(allocator, &opcnt_data);
- result = wabt_read_binary_opcnt(
- allocator, data, size, &s_read_binary_options, &opcnt_data);
+ wabt_init_opcnt_data(&opcnt_data);
+ result =
+ wabt_read_binary_opcnt(data, size, &s_read_binary_options, &opcnt_data);
if (WABT_SUCCEEDED(result)) {
display_sorted_int_counter_vector(
- out, "Opcode counts:", allocator, &opcnt_data.opcode_vec,
- opcode_counter_gt, display_opcode_name, NULL);
+ out, "Opcode counts:", &opcnt_data.opcode_vec, opcode_counter_gt,
+ display_opcode_name, NULL);
display_sorted_int_counter_vector(
- out, "\ni32.const:", allocator, &opcnt_data.i32_const_vec,
- int_counter_gt, display_intmax,
- wabt_get_opcode_name(WABT_OPCODE_I32_CONST));
+ out, "\ni32.const:", &opcnt_data.i32_const_vec, int_counter_gt,
+ display_intmax, wabt_get_opcode_name(WABT_OPCODE_I32_CONST));
display_sorted_int_counter_vector(
- out, "\nget_local:", allocator, &opcnt_data.get_local_vec,
- int_counter_gt, display_intmax,
- wabt_get_opcode_name(WABT_OPCODE_GET_LOCAL));
+ out, "\nget_local:", &opcnt_data.get_local_vec, int_counter_gt,
+ display_intmax, wabt_get_opcode_name(WABT_OPCODE_GET_LOCAL));
display_sorted_int_counter_vector(
- out, "\nset_local:", allocator, &opcnt_data.set_local_vec,
- int_counter_gt, display_intmax,
- wabt_get_opcode_name(WABT_OPCODE_SET_LOCAL));
+ out, "\nset_local:", &opcnt_data.set_local_vec, int_counter_gt,
+ display_intmax, wabt_get_opcode_name(WABT_OPCODE_SET_LOCAL));
display_sorted_int_counter_vector(
- out, "\ntee_local:", allocator, &opcnt_data.tee_local_vec,
- int_counter_gt, display_intmax,
- wabt_get_opcode_name(WABT_OPCODE_TEE_LOCAL));
+ out, "\ntee_local:", &opcnt_data.tee_local_vec, int_counter_gt,
+ display_intmax, wabt_get_opcode_name(WABT_OPCODE_TEE_LOCAL));
display_sorted_int_pair_counter_vector(
- out, "\ni32.load:", allocator, &opcnt_data.i32_load_vec,
- int_pair_counter_gt, display_intmax, display_intmax,
+ out, "\ni32.load:", &opcnt_data.i32_load_vec, int_pair_counter_gt,
+ display_intmax, display_intmax,
wabt_get_opcode_name(WABT_OPCODE_I32_LOAD));
display_sorted_int_pair_counter_vector(
- out, "\ni32.store:", allocator, &opcnt_data.i32_store_vec,
- int_pair_counter_gt, display_intmax, display_intmax,
+ out, "\ni32.store:", &opcnt_data.i32_store_vec, int_pair_counter_gt,
+ display_intmax, display_intmax,
wabt_get_opcode_name(WABT_OPCODE_I32_STORE));
}
- wabt_destroy_opcnt_data(allocator, &opcnt_data);
+ wabt_destroy_opcnt_data(&opcnt_data);
}
- wabt_free(allocator, data);
- wabt_print_allocator_stats(allocator);
- wabt_destroy_allocator(allocator);
+ wabt_free(data);
return result;
}
diff --git a/src/tools/wast-desugar.c b/src/tools/wast-desugar.c
index 4eaa6d2c..79d0e6cf 100644
--- a/src/tools/wast-desugar.c
+++ b/src/tools/wast-desugar.c
@@ -28,7 +28,6 @@
#include "config.h"
#include "generate-names.h"
#include "option-parser.h"
-#include "stack-allocator.h"
#include "stream.h"
#include "writer.h"
@@ -36,7 +35,6 @@
static const char* s_infile;
static const char* s_outfile;
-static WabtBool s_use_libc_allocator;
static WabtBool s_generate_names;
static WabtSourceErrorHandler s_error_handler =
@@ -45,7 +43,6 @@ static WabtSourceErrorHandler s_error_handler =
enum {
FLAG_HELP,
FLAG_OUTPUT,
- FLAG_USE_LIBC_ALLOCATOR,
FLAG_GENERATE_NAMES,
NUM_FLAGS
};
@@ -68,9 +65,6 @@ static WabtOption s_options[] = {
"print this help message"},
{FLAG_OUTPUT, 'o', "output", "FILE", WABT_OPTION_HAS_ARGUMENT,
"output file for the formatted file"},
- {FLAG_USE_LIBC_ALLOCATOR, 0, "use-libc-allocator", NULL,
- WABT_OPTION_NO_ARGUMENT,
- "use malloc, free, etc. instead of stack allocator"},
{FLAG_GENERATE_NAMES, 0, "generate-names", NULL, WABT_OPTION_NO_ARGUMENT,
"Give auto-generated names to non-named functions, types, etc."},
};
@@ -89,10 +83,6 @@ static void on_option(struct WabtOptionParser* parser,
s_outfile = argument;
break;
- case FLAG_USE_LIBC_ALLOCATOR:
- s_use_libc_allocator = WABT_TRUE;
- break;
-
case FLAG_GENERATE_NAMES:
s_generate_names = WABT_TRUE;
break;
@@ -126,7 +116,6 @@ static void parse_options(int argc, char** argv) {
}
typedef struct Context {
- WabtAllocator* allocator;
WabtMemoryWriter json_writer;
WabtMemoryWriter module_writer;
WabtStream json_stream;
@@ -136,20 +125,10 @@ typedef struct Context {
} Context;
int main(int argc, char** argv) {
- WabtStackAllocator stack_allocator;
- WabtAllocator* allocator;
-
wabt_init_stdio();
parse_options(argc, argv);
- if (s_use_libc_allocator) {
- allocator = &g_wabt_libc_allocator;
- } else {
- wabt_init_stack_allocator(&stack_allocator, &g_wabt_libc_allocator);
- allocator = &stack_allocator.allocator;
- }
-
- WabtAstLexer* lexer = wabt_new_ast_file_lexer(allocator, s_infile);
+ WabtAstLexer* lexer = wabt_new_ast_file_lexer(s_infile);
if (!lexer)
WABT_FATAL("unable to read %s\n", s_infile);
@@ -162,10 +141,10 @@ int main(int argc, char** argv) {
WABT_FATAL("no module in file.\n");
if (s_generate_names)
- result = wabt_generate_names(allocator, module);
+ result = wabt_generate_names(module);
if (WABT_SUCCEEDED(result))
- result = wabt_apply_names(allocator, module);
+ result = wabt_apply_names(module);
if (WABT_SUCCEEDED(result)) {
WabtFileWriter file_writer;
@@ -176,18 +155,14 @@ int main(int argc, char** argv) {
}
if (WABT_SUCCEEDED(result)) {
- result = wabt_write_ast(allocator, &file_writer.base, module);
+ result = wabt_write_ast(&file_writer.base, module);
wabt_close_file_writer(&file_writer);
}
}
}
wabt_destroy_ast_lexer(lexer);
-
- if (s_use_libc_allocator)
- wabt_destroy_script(&script);
- wabt_print_allocator_stats(allocator);
- wabt_destroy_allocator(allocator);
+ wabt_destroy_script(&script);
return result;
}
diff --git a/src/tools/wast2wasm.c b/src/tools/wast2wasm.c
index 8af8c71c..df2e481b 100644
--- a/src/tools/wast2wasm.c
+++ b/src/tools/wast2wasm.c
@@ -28,7 +28,6 @@
#include "common.h"
#include "option-parser.h"
#include "resolve-names.h"
-#include "stack-allocator.h"
#include "stream.h"
#include "validator.h"
#include "writer.h"
@@ -44,7 +43,6 @@ static WabtWriteBinaryOptions s_write_binary_options =
static WabtWriteBinarySpecOptions s_write_binary_spec_options =
WABT_WRITE_BINARY_SPEC_OPTIONS_DEFAULT;
static WabtBool s_spec;
-static WabtBool s_use_libc_allocator;
static WabtBool s_validate = WABT_TRUE;
static WabtSourceErrorHandler s_error_handler =
@@ -62,7 +60,6 @@ enum {
FLAG_OUTPUT,
FLAG_RELOCATABLE,
FLAG_SPEC,
- FLAG_USE_LIBC_ALLOCATOR,
FLAG_NO_CANONICALIZE_LEB128S,
FLAG_DEBUG_NAMES,
FLAG_NO_CHECK,
@@ -100,8 +97,6 @@ static WabtOption s_options[] = {
{FLAG_SPEC, 0, "spec", NULL, NOPE,
"parse a file with multiple modules and assertions, like the spec "
"tests"},
- {FLAG_USE_LIBC_ALLOCATOR, 0, "use-libc-allocator", NULL, NOPE,
- "use malloc, free, etc. instead of stack allocator"},
{FLAG_NO_CANONICALIZE_LEB128S, 0, "no-canonicalize-leb128s", NULL, NOPE,
"Write all LEB128 sizes as 5-bytes instead of their minimal size"},
{FLAG_DEBUG_NAMES, 0, "debug-names", NULL, NOPE,
@@ -141,10 +136,6 @@ static void on_option(struct WabtOptionParser* parser,
s_spec = WABT_TRUE;
break;
- case FLAG_USE_LIBC_ALLOCATOR:
- s_use_libc_allocator = WABT_TRUE;
- break;
-
case FLAG_NO_CANONICALIZE_LEB128S:
s_write_binary_options.canonicalize_lebs = WABT_FALSE;
break;
@@ -199,22 +190,12 @@ static void write_buffer_to_file(const char* filename,
}
int main(int argc, char** argv) {
- WabtStackAllocator stack_allocator;
- WabtAllocator* allocator;
-
wabt_init_stdio();
wabt_init_file_stream_from_existing(&s_log_stream, stdout);
parse_options(argc, argv);
- if (s_use_libc_allocator) {
- allocator = &g_wabt_libc_allocator;
- } else {
- wabt_init_stack_allocator(&stack_allocator, &g_wabt_libc_allocator);
- allocator = &stack_allocator.allocator;
- }
-
- WabtAstLexer* lexer = wabt_new_ast_file_lexer(allocator, s_infile);
+ WabtAstLexer* lexer = wabt_new_ast_file_lexer(s_infile);
if (!lexer)
WABT_FATAL("unable to read file: %s\n", s_infile);
@@ -222,30 +203,27 @@ int main(int argc, char** argv) {
WabtResult result = wabt_parse_ast(lexer, &script, &s_error_handler);
if (WABT_SUCCEEDED(result)) {
- result =
- wabt_resolve_names_script(allocator, lexer, &script, &s_error_handler);
+ result = wabt_resolve_names_script(lexer, &script, &s_error_handler);
- if (WABT_SUCCEEDED(result) && s_validate) {
- result =
- wabt_validate_script(allocator, lexer, &script, &s_error_handler);
- }
+ if (WABT_SUCCEEDED(result) && s_validate)
+ result = wabt_validate_script(lexer, &script, &s_error_handler);
if (WABT_SUCCEEDED(result)) {
if (s_spec) {
s_write_binary_spec_options.json_filename = s_outfile;
s_write_binary_spec_options.write_binary_options =
s_write_binary_options;
- result = wabt_write_binary_spec_script(allocator, &script, s_infile,
+ result = wabt_write_binary_spec_script(&script, s_infile,
&s_write_binary_spec_options);
} else {
WabtMemoryWriter writer;
WABT_ZERO_MEMORY(writer);
- if (WABT_FAILED(wabt_init_mem_writer(allocator, &writer)))
+ if (WABT_FAILED(wabt_init_mem_writer(&writer)))
WABT_FATAL("unable to open memory writer for writing\n");
WabtModule* module = wabt_get_first_module(&script);
if (module) {
- result = wabt_write_binary_module(allocator, &writer.base, module,
+ result = wabt_write_binary_module(&writer.base, module,
&s_write_binary_options);
} else {
WABT_FATAL("no module found\n");
@@ -259,10 +237,6 @@ int main(int argc, char** argv) {
}
wabt_destroy_ast_lexer(lexer);
-
- if (s_use_libc_allocator)
- wabt_destroy_script(&script);
- wabt_print_allocator_stats(allocator);
- wabt_destroy_allocator(allocator);
+ wabt_destroy_script(&script);
return result;
}