diff options
Diffstat (limited to 'src')
63 files changed, 2335 insertions, 3624 deletions
diff --git a/src/allocator.c b/src/allocator.c deleted file mode 100644 index d29f8553..00000000 --- a/src/allocator.c +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright 2016 WebAssembly Community Group participants - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "allocator.h" - -#include <assert.h> -#include <setjmp.h> -#include <stdint.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -typedef struct MemInfo { - void* real_pointer; /* pointer as returned from malloc */ - size_t size; -} MemInfo; - -static WabtBool s_has_jmpbuf; -static jmp_buf s_jmpbuf; - -#ifndef NDEBUG -static WabtBool is_power_of_two(size_t x) { - return x && ((x & (x - 1)) == 0); -} - -static WabtBool is_aligned(void* p, size_t align) { - return ((intptr_t)p & (align - 1)) == 0; -} -#endif /* NDEBUG */ - -static void* align_up(void* p, size_t align) { - return (void*)(((intptr_t)p + align - 1) & ~(align - 1)); -} - -static void* libc_alloc(WabtAllocator* allocator, - size_t size, - size_t align, - const char* file, - int line) { - assert(is_power_of_two(align)); - if (align < sizeof(void*)) - align = sizeof(void*); - - void* p = malloc(size + sizeof(MemInfo) + align - 1); - if (!p) { - if (s_has_jmpbuf) - longjmp(s_jmpbuf, 1); - WABT_FATAL("%s:%d: memory allocation failed\n", file, line); - } - - void* aligned = align_up((void*)((size_t)p + sizeof(MemInfo)), align); - MemInfo* mem_info = (MemInfo*)aligned - 1; - assert(is_aligned(mem_info, sizeof(void*))); - mem_info->real_pointer = p; - mem_info->size = size; - return aligned; -} - -static void libc_free(WabtAllocator* allocator, - void* p, - const char* file, - int line) { - if (!p) - return; - - MemInfo* mem_info = (MemInfo*)p - 1; - free(mem_info->real_pointer); -} - -/* nothing to destroy */ -static void libc_destroy(WabtAllocator* allocator) {} - -static void* libc_realloc(WabtAllocator* allocator, - void* p, - size_t size, - size_t align, - const char* file, - int line) { - if (!p) - return libc_alloc(allocator, size, align, NULL, 0); - - MemInfo* mem_info = (MemInfo*)p - 1; - void* new_p = libc_alloc(allocator, size, align, NULL, 0); - size_t copy_size = size > mem_info->size ? mem_info->size : size; - memcpy(new_p, p, copy_size); - free(mem_info->real_pointer); - return new_p; -} - -/* mark/reset_to_mark are not supported by the libc allocator */ -static WabtAllocatorMark libc_mark(WabtAllocator* allocator) { - return NULL; -} - -static void libc_reset_to_mark(WabtAllocator* allocator, - WabtAllocatorMark mark) {} - -static void libc_print_stats(WabtAllocator* allocator) { - /* TODO(binji): nothing for now, implement later */ -} - -static int libc_setjmp_handler(WabtAllocator* allocator) { - s_has_jmpbuf = WABT_TRUE; - return setjmp(s_jmpbuf); -} - -WabtAllocator g_wabt_libc_allocator = { - libc_alloc, libc_realloc, libc_free, libc_destroy, - libc_mark, libc_reset_to_mark, libc_print_stats, libc_setjmp_handler}; - -WabtAllocator* wabt_get_libc_allocator(void) { - return &g_wabt_libc_allocator; -} diff --git a/src/allocator.h b/src/allocator.h deleted file mode 100644 index 433ce85f..00000000 --- a/src/allocator.h +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright 2016 WebAssembly Community Group participants - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef WABT_ALLOCATOR_H_ -#define WABT_ALLOCATOR_H_ - -#include <stdlib.h> -#include <string.h> - -#include "common.h" - -#define WABT_DEFAULT_ALIGN sizeof(void*) - -typedef void* WabtAllocatorMark; - -typedef struct WabtAllocator { - void* (*alloc)(struct WabtAllocator*, - size_t size, - size_t align, - const char* file, - int line); - void* (*realloc)(struct WabtAllocator*, - void* p, - size_t size, - size_t align, - const char* file, - int line); - void (*free)(struct WabtAllocator*, void* p, const char* file, int line); - /* destroy the allocator */ - void (*destroy)(struct WabtAllocator*); - /* mark/reset_to_mark are only supported by the stack allocator */ - WabtAllocatorMark (*mark)(struct WabtAllocator*); - void (*reset_to_mark)(struct WabtAllocator*, WabtAllocatorMark); - void (*print_stats)(struct WabtAllocator*); - /* set the location to longjmp to if allocation fails. the return value is 0 - * for normal execution, and 1 if an allocation failed. */ - int (*setjmp_handler)(struct WabtAllocator*); -} WabtAllocator; - -extern WabtAllocator g_wabt_libc_allocator; - -#define wabt_alloc(allocator, size, align) \ - (allocator)->alloc((allocator), (size), (align), __FILE__, __LINE__) - -#define wabt_alloc_zero(allocator, size, align) \ - wabt_alloc_zero_((allocator), (size), (align), __FILE__, __LINE__) - -#define wabt_realloc(allocator, p, size, align) \ - (allocator)->realloc((allocator), (p), (size), (align), __FILE__, __LINE__) - -#define wabt_free(allocator, p) \ - (allocator)->free((allocator), (p), __FILE__, __LINE__) - -#define wabt_destroy_allocator(allocator) (allocator)->destroy(allocator) -#define wabt_mark(allocator) (allocator)->mark(allocator) - -#define wabt_reset_to_mark(allocator, mark) \ - (allocator)->reset_to_mark(allocator, mark) - -#define wabt_print_allocator_stats(allocator) \ - (allocator)->print_stats(allocator) - -#define wabt_strndup(allocator, s, len) \ - wabt_strndup_(allocator, s, len, __FILE__, __LINE__) - -#define wabt_dup_string_slice(allocator, str) \ - wabt_dup_string_slice_(allocator, str, __FILE__, __LINE__) - -WABT_EXTERN_C_BEGIN - -WabtAllocator* wabt_get_libc_allocator(void); - -static WABT_INLINE void* wabt_alloc_zero_(WabtAllocator* allocator, - size_t size, - size_t align, - const char* file, - int line) { - void* result = allocator->alloc(allocator, size, align, file, line); - memset(result, 0, size); - return result; -} - -static WABT_INLINE char* wabt_strndup_(WabtAllocator* allocator, - const char* s, - size_t len, - const char* file, - int line) { - size_t real_len = 0; - const char* p = s; - while (real_len < len && *p) { - p++; - real_len++; - } - - char* new_s = (char*)allocator->alloc(allocator, real_len + 1, 1, file, line); - memcpy(new_s, s, real_len); - new_s[real_len] = 0; - return new_s; -} - -static WABT_INLINE WabtStringSlice -wabt_dup_string_slice_(WabtAllocator* allocator, - WabtStringSlice str, - const char* file, - int line) { - WabtStringSlice result; - result.start = wabt_strndup_(allocator, str.start, str.length, file, line); - result.length = str.length; - return result; -} - -WABT_EXTERN_C_END - -#endif /* WABT_ALLOCATOR_H_ */ diff --git a/src/apply-names.c b/src/apply-names.c index 084a22fc..e7bf63a8 100644 --- a/src/apply-names.c +++ b/src/apply-names.c @@ -19,7 +19,6 @@ #include <assert.h> #include <stdio.h> -#include "allocator.h" #include "ast.h" #define CHECK_RESULT(expr) \ @@ -32,7 +31,6 @@ typedef WabtLabel* LabelPtr; WABT_DEFINE_VECTOR(label_ptr, LabelPtr); typedef struct Context { - WabtAllocator* allocator; WabtModule* module; WabtFunc* current_func; WabtExprVisitor visitor; @@ -43,7 +41,7 @@ typedef struct Context { } Context; static void push_label(Context* ctx, WabtLabel* label) { - wabt_append_label_ptr_value(ctx->allocator, &ctx->labels, &label); + wabt_append_label_ptr_value(&ctx->labels, &label); } static void pop_label(Context* ctx) { @@ -67,66 +65,54 @@ static WabtLabel* find_label_by_var(Context* ctx, WabtVar* var) { } } -static void use_name_for_var(WabtAllocator* allocator, - WabtStringSlice* name, - WabtVar* var) { +static void use_name_for_var(WabtStringSlice* name, WabtVar* var) { if (var->type == WABT_VAR_TYPE_NAME) { assert(wabt_string_slices_are_equal(name, &var->name)); } if (name && name->start) { var->type = WABT_VAR_TYPE_NAME; - var->name = wabt_dup_string_slice(allocator, *name); + var->name = wabt_dup_string_slice(*name); } } -static WabtResult use_name_for_func_type_var(WabtAllocator* allocator, - WabtModule* module, - WabtVar* var) { +static WabtResult use_name_for_func_type_var(WabtModule* module, WabtVar* var) { WabtFuncType* func_type = wabt_get_func_type_by_var(module, var); if (func_type == NULL) return WABT_ERROR; - use_name_for_var(allocator, &func_type->name, var); + use_name_for_var(&func_type->name, var); return WABT_OK; } -static WabtResult use_name_for_func_var(WabtAllocator* allocator, - WabtModule* module, - WabtVar* var) { +static WabtResult use_name_for_func_var(WabtModule* module, WabtVar* var) { WabtFunc* func = wabt_get_func_by_var(module, var); if (func == NULL) return WABT_ERROR; - use_name_for_var(allocator, &func->name, var); + use_name_for_var(&func->name, var); return WABT_OK; } -static WabtResult use_name_for_global_var(WabtAllocator* allocator, - WabtModule* module, - WabtVar* var) { +static WabtResult use_name_for_global_var(WabtModule* module, WabtVar* var) { WabtGlobal* global = wabt_get_global_by_var(module, var); if (global == NULL) return WABT_ERROR; - use_name_for_var(allocator, &global->name, var); + use_name_for_var(&global->name, var); return WABT_OK; } -static WabtResult use_name_for_table_var(WabtAllocator* allocator, - WabtModule* module, - WabtVar* var) { +static WabtResult use_name_for_table_var(WabtModule* module, WabtVar* var) { WabtTable* table = wabt_get_table_by_var(module, var); if (table == NULL) return WABT_ERROR; - use_name_for_var(allocator, &table->name, var); + use_name_for_var(&table->name, var); return WABT_OK; } -static WabtResult use_name_for_memory_var(WabtAllocator* allocator, - WabtModule* module, - WabtVar* var) { +static WabtResult use_name_for_memory_var(WabtModule* module, WabtVar* var) { WabtMemory* memory = wabt_get_memory_by_var(module, var); if (memory == NULL) return WABT_ERROR; - use_name_for_var(allocator, &memory->name, var); + use_name_for_var(&memory->name, var); return WABT_OK; } @@ -158,7 +144,7 @@ static WabtResult use_name_for_param_and_local_var(Context* ctx, if (name->start) { var->type = WABT_VAR_TYPE_NAME; - var->name = wabt_dup_string_slice(ctx->allocator, *name); + var->name = wabt_dup_string_slice(*name); return var->name.start != NULL ? WABT_OK : WABT_ERROR; } return WABT_OK; @@ -191,14 +177,14 @@ static WabtResult end_loop_expr(WabtExpr* expr, void* user_data) { static WabtResult on_br_expr(WabtExpr* expr, void* user_data) { Context* ctx = user_data; WabtLabel* label = find_label_by_var(ctx, &expr->br.var); - use_name_for_var(ctx->allocator, label, &expr->br.var); + use_name_for_var(label, &expr->br.var); return WABT_OK; } static WabtResult on_br_if_expr(WabtExpr* expr, void* user_data) { Context* ctx = user_data; WabtLabel* label = find_label_by_var(ctx, &expr->br_if.var); - use_name_for_var(ctx->allocator, label, &expr->br_if.var); + use_name_for_var(label, &expr->br_if.var); return WABT_OK; } @@ -209,32 +195,30 @@ static WabtResult on_br_table_expr(WabtExpr* expr, void* user_data) { for (i = 0; i < targets->size; ++i) { WabtVar* target = &targets->data[i]; WabtLabel* label = find_label_by_var(ctx, target); - use_name_for_var(ctx->allocator, label, target); + use_name_for_var(label, target); } WabtLabel* label = find_label_by_var(ctx, &expr->br_table.default_target); - use_name_for_var(ctx->allocator, label, &expr->br_table.default_target); + use_name_for_var(label, &expr->br_table.default_target); return WABT_OK; } static WabtResult on_call_expr(WabtExpr* expr, void* user_data) { Context* ctx = user_data; - CHECK_RESULT( - use_name_for_func_var(ctx->allocator, ctx->module, &expr->call.var)); + CHECK_RESULT(use_name_for_func_var(ctx->module, &expr->call.var)); return WABT_OK; } static WabtResult on_call_indirect_expr(WabtExpr* expr, void* user_data) { Context* ctx = user_data; - CHECK_RESULT(use_name_for_func_type_var(ctx->allocator, ctx->module, - &expr->call_indirect.var)); + CHECK_RESULT( + use_name_for_func_type_var(ctx->module, &expr->call_indirect.var)); return WABT_OK; } static WabtResult on_get_global_expr(WabtExpr* expr, void* user_data) { Context* ctx = user_data; - CHECK_RESULT(use_name_for_global_var(ctx->allocator, ctx->module, - &expr->get_global.var)); + CHECK_RESULT(use_name_for_global_var(ctx->module, &expr->get_global.var)); return WABT_OK; } @@ -259,8 +243,7 @@ static WabtResult end_if_expr(WabtExpr* expr, void* user_data) { static WabtResult on_set_global_expr(WabtExpr* expr, void* user_data) { Context* ctx = user_data; - CHECK_RESULT(use_name_for_global_var(ctx->allocator, ctx->module, - &expr->set_global.var)); + CHECK_RESULT(use_name_for_global_var(ctx->module, &expr->set_global.var)); return WABT_OK; } @@ -283,17 +266,15 @@ static WabtResult visit_func(Context* ctx, WabtFunc* func) { ctx->current_func = func; if (wabt_decl_has_func_type(&func->decl)) { - CHECK_RESULT(use_name_for_func_type_var(ctx->allocator, ctx->module, - &func->decl.type_var)); + CHECK_RESULT(use_name_for_func_type_var(ctx->module, &func->decl.type_var)); } - wabt_make_type_binding_reverse_mapping( - ctx->allocator, &func->decl.sig.param_types, &func->param_bindings, - &ctx->param_index_to_name); + wabt_make_type_binding_reverse_mapping(&func->decl.sig.param_types, + &func->param_bindings, + &ctx->param_index_to_name); - wabt_make_type_binding_reverse_mapping(ctx->allocator, &func->local_types, - &func->local_bindings, - &ctx->local_index_to_name); + wabt_make_type_binding_reverse_mapping( + &func->local_types, &func->local_bindings, &ctx->local_index_to_name); CHECK_RESULT(wabt_visit_func(func, &ctx->visitor)); ctx->current_func = NULL; @@ -304,7 +285,7 @@ static WabtResult visit_export(Context* ctx, uint32_t export_index, WabtExport* export) { if (export->kind == WABT_EXTERNAL_KIND_FUNC) { - use_name_for_func_var(ctx->allocator, ctx->module, &export->var); + use_name_for_func_var(ctx->module, &export->var); } return WABT_OK; } @@ -313,11 +294,9 @@ static WabtResult visit_elem_segment(Context* ctx, uint32_t elem_segment_index, WabtElemSegment* segment) { size_t i; - CHECK_RESULT( - use_name_for_table_var(ctx->allocator, ctx->module, &segment->table_var)); + CHECK_RESULT(use_name_for_table_var(ctx->module, &segment->table_var)); for (i = 0; i < segment->vars.size; ++i) { - CHECK_RESULT(use_name_for_func_var(ctx->allocator, ctx->module, - &segment->vars.data[i])); + CHECK_RESULT(use_name_for_func_var(ctx->module, &segment->vars.data[i])); } return WABT_OK; } @@ -325,8 +304,7 @@ static WabtResult visit_elem_segment(Context* ctx, static WabtResult visit_data_segment(Context* ctx, uint32_t data_segment_index, WabtDataSegment* segment) { - CHECK_RESULT(use_name_for_memory_var(ctx->allocator, ctx->module, - &segment->memory_var)); + CHECK_RESULT(use_name_for_memory_var(ctx->module, &segment->memory_var)); return WABT_OK; } @@ -343,10 +321,9 @@ static WabtResult visit_module(Context* ctx, WabtModule* module) { return WABT_OK; } -WabtResult wabt_apply_names(WabtAllocator* allocator, WabtModule* module) { +WabtResult wabt_apply_names(WabtModule* module) { Context ctx; WABT_ZERO_MEMORY(ctx); - ctx.allocator = allocator; ctx.module = module; ctx.visitor.user_data = &ctx; ctx.visitor.begin_block_expr = begin_block_expr; @@ -366,8 +343,8 @@ WabtResult wabt_apply_names(WabtAllocator* allocator, WabtModule* module) { ctx.visitor.on_set_local_expr = on_set_local_expr; ctx.visitor.on_tee_local_expr = on_tee_local_expr; WabtResult result = visit_module(&ctx, module); - wabt_destroy_string_slice_vector(allocator, &ctx.param_index_to_name); - wabt_destroy_string_slice_vector(allocator, &ctx.local_index_to_name); - wabt_destroy_label_ptr_vector(allocator, &ctx.labels); + wabt_destroy_string_slice_vector(&ctx.param_index_to_name); + wabt_destroy_string_slice_vector(&ctx.local_index_to_name); + wabt_destroy_label_ptr_vector(&ctx.labels); return result; } diff --git a/src/apply-names.h b/src/apply-names.h index ec055153..4bfd546c 100644 --- a/src/apply-names.h +++ b/src/apply-names.h @@ -19,7 +19,6 @@ #include "common.h" -struct WabtAllocator; struct WabtModule; /* Use function, import, function type, parameter and local names in WabtVars @@ -38,7 +37,7 @@ struct WabtModule; * (call $foo ...) */ WABT_EXTERN_C_BEGIN -WabtResult wabt_apply_names(struct WabtAllocator*, struct WabtModule*); +WabtResult wabt_apply_names(struct WabtModule*); WABT_EXTERN_C_END #endif /* WABT_APPLY_NAMES_H_ */ diff --git a/src/array.h b/src/array.h index 0182d772..e1f37a79 100644 --- a/src/array.h +++ b/src/array.h @@ -19,40 +19,35 @@ #include <stddef.h> -#include "allocator.h" #include "common.h" -#define WABT_DEFINE_ARRAY(name, type) \ - typedef struct type##Array { \ - type* data; \ - size_t size; \ - } type##Array; \ - \ - WABT_EXTERN_C_BEGIN \ - static WABT_INLINE void wabt_destroy_##name##_array( \ - struct WabtAllocator* allocator, type##Array* array) WABT_UNUSED; \ - static WABT_INLINE void wabt_new_##name##_array( \ - struct WabtAllocator* allocator, type##Array* array, size_t size) \ - WABT_UNUSED; \ - WABT_EXTERN_C_END \ - \ - void wabt_destroy_##name##_array(struct WabtAllocator* allocator, \ - type##Array* array) { \ - wabt_free(allocator, array->data); \ - } \ - void wabt_new_##name##_array(struct WabtAllocator* allocator, \ - type##Array* array, size_t size) { \ - array->size = size; \ - array->data = \ - wabt_alloc_zero(allocator, size * sizeof(type), WABT_DEFAULT_ALIGN); \ +#define WABT_DEFINE_ARRAY(name, type) \ + typedef struct type##Array { \ + type* data; \ + size_t size; \ + } type##Array; \ + \ + WABT_EXTERN_C_BEGIN \ + static WABT_INLINE void wabt_destroy_##name##_array(type##Array* array) \ + WABT_UNUSED; \ + static WABT_INLINE void wabt_new_##name##_array(type##Array* array, \ + size_t size) WABT_UNUSED; \ + WABT_EXTERN_C_END \ + \ + void wabt_destroy_##name##_array(type##Array* array) { \ + wabt_free(array->data); \ + } \ + void wabt_new_##name##_array(type##Array* array, size_t size) { \ + array->size = size; \ + array->data = wabt_alloc_zero(size * sizeof(type)); \ } -#define WABT_DESTROY_ARRAY_AND_ELEMENTS(allocator, v, name) \ - { \ - size_t i; \ - for (i = 0; i < (v).size; ++i) \ - wabt_destroy_##name(allocator, &((v).data[i])); \ - wabt_destroy_##name##_array(allocator, &(v)); \ +#define WABT_DESTROY_ARRAY_AND_ELEMENTS(v, name) \ + { \ + size_t i; \ + for (i = 0; i < (v).size; ++i) \ + wabt_destroy_##name(&((v).data[i])); \ + wabt_destroy_##name##_array(&(v)); \ } #endif /* WABT_ARRAY_H_ */ diff --git a/src/ast-lexer.c b/src/ast-lexer.c index c7cf645b..8298b927 100644 --- a/src/ast-lexer.c +++ b/src/ast-lexer.c @@ -21,7 +21,6 @@ #include "config.h" -#include "allocator.h" #include "ast-parser.h" #include "ast-parser-lexer-shared.h" #include "vector.h" @@ -114,8 +113,7 @@ static WabtResult fill(WabtLocation* loc, /* TODO(binji): could just alloc instead, because we know we'll need to * memmove below */ - char* new_buffer = wabt_realloc(lexer->allocator, lexer->buffer, - new_buffer_size, WABT_DEFAULT_ALIGN); + char* new_buffer = wabt_realloc(lexer->buffer, new_buffer_size); if (new_buffer == NULL) { wabt_ast_parser_error(loc, lexer, parser, "unable to reallocate lexer buffer."); @@ -468,22 +466,17 @@ int wabt_ast_lexer_lex(WABT_AST_PARSER_STYPE* lval, } } -static WabtAstLexer* wabt_new_lexer(WabtAllocator* allocator, - WabtAstLexerSourceType type, +static WabtAstLexer* wabt_new_lexer(WabtAstLexerSourceType type, const char* filename) { - WabtAstLexer* lexer = - wabt_alloc_zero(allocator, sizeof(WabtAstLexer), WABT_DEFAULT_ALIGN); - lexer->allocator = allocator; + WabtAstLexer* lexer = wabt_alloc_zero(sizeof(WabtAstLexer)); lexer->line = 1; lexer->filename = filename; lexer->source.type = type; return lexer; } -WabtAstLexer* wabt_new_ast_file_lexer(WabtAllocator* allocator, - const char* filename) { - WabtAstLexer* lexer = - wabt_new_lexer(allocator, WABT_LEXER_SOURCE_TYPE_FILE, filename); +WabtAstLexer* wabt_new_ast_file_lexer(const char* filename) { + WabtAstLexer* lexer = wabt_new_lexer(WABT_LEXER_SOURCE_TYPE_FILE, filename); lexer->source.file = fopen(filename, "rb"); if (!lexer->source.file) { wabt_destroy_ast_lexer(lexer); @@ -492,12 +485,10 @@ WabtAstLexer* wabt_new_ast_file_lexer(WabtAllocator* allocator, return lexer; } -WabtAstLexer* wabt_new_ast_buffer_lexer(WabtAllocator* allocator, - const char* filename, +WabtAstLexer* wabt_new_ast_buffer_lexer(const char* filename, const void* data, size_t size) { - WabtAstLexer* lexer = - wabt_new_lexer(allocator, WABT_LEXER_SOURCE_TYPE_BUFFER, filename); + WabtAstLexer* lexer = wabt_new_lexer(WABT_LEXER_SOURCE_TYPE_BUFFER, filename); lexer->source.buffer.data = data; lexer->source.buffer.size = size; lexer->source.buffer.read_offset = 0; @@ -507,12 +498,8 @@ WabtAstLexer* wabt_new_ast_buffer_lexer(WabtAllocator* allocator, void wabt_destroy_ast_lexer(WabtAstLexer* lexer) { if (lexer->source.type == WABT_LEXER_SOURCE_TYPE_FILE && lexer->source.file) fclose(lexer->source.file); - wabt_free(lexer->allocator, lexer->buffer); - wabt_free(lexer->allocator, lexer); -} - -WabtAllocator* wabt_ast_lexer_get_allocator(WabtAstLexer* lexer) { - return lexer->allocator; + wabt_free(lexer->buffer); + wabt_free(lexer); } typedef enum WabtLineOffsetPosition { diff --git a/src/ast-lexer.h b/src/ast-lexer.h index e06672f5..d85f0fb4 100644 --- a/src/ast-lexer.h +++ b/src/ast-lexer.h @@ -23,8 +23,6 @@ #include "common.h" #include "vector.h" -struct WabtAllocator; - typedef enum WabtAstLexerSourceType { WABT_LEXER_SOURCE_TYPE_FILE, WABT_LEXER_SOURCE_TYPE_BUFFER, @@ -43,7 +41,6 @@ typedef struct WabtAstLexerSource { } WabtAstLexerSource; typedef struct WabtAstLexer { - struct WabtAllocator* allocator; WabtAstLexerSource source; const char* filename; int line; @@ -63,10 +60,8 @@ typedef struct WabtAstLexer { WABT_EXTERN_C_BEGIN -WabtAstLexer* wabt_new_ast_file_lexer(struct WabtAllocator*, - const char* filename); -WabtAstLexer* wabt_new_ast_buffer_lexer(struct WabtAllocator*, - const char* filename, +WabtAstLexer* wabt_new_ast_file_lexer(const char* filename); +WabtAstLexer* wabt_new_ast_buffer_lexer(const char* filename, const void* data, size_t size); void wabt_destroy_ast_lexer(WabtAstLexer*); diff --git a/src/ast-parser-lexer-shared.c b/src/ast-parser-lexer-shared.c index 327ec69f..8c41e3ca 100644 --- a/src/ast-parser-lexer-shared.c +++ b/src/ast-parser-lexer-shared.c @@ -71,69 +71,64 @@ void wabt_ast_format_error(WabtSourceErrorHandler* error_handler, va_end(args_copy); } -void wabt_destroy_optional_export(WabtAllocator* allocator, - WabtOptionalExport* export_) { +void wabt_destroy_optional_export(WabtOptionalExport* export_) { if (export_->has_export) - wabt_destroy_export(allocator, &export_->export_); + wabt_destroy_export(&export_->export_); } -void wabt_destroy_exported_func(WabtAllocator* allocator, - WabtExportedFunc* exported_func) { - wabt_destroy_optional_export(allocator, &exported_func->export_); - wabt_destroy_func(allocator, exported_func->func); - wabt_free(allocator, exported_func->func); +void wabt_destroy_exported_func(WabtExportedFunc* exported_func) { + wabt_destroy_optional_export(&exported_func->export_); + wabt_destroy_func(exported_func->func); + wabt_free(exported_func->func); } -void wabt_destroy_text_list(WabtAllocator* allocator, WabtTextList* text_list) { +void wabt_destroy_text_list(WabtTextList* text_list) { WabtTextListNode* node = text_list->first; while (node) { WabtTextListNode* next = node->next; - wabt_destroy_string_slice(allocator, &node->text); - wabt_free(allocator, node); + wabt_destroy_string_slice(&node->text); + wabt_free(node); node = next; } } -void wabt_destroy_func_fields(struct WabtAllocator* allocator, - WabtFuncField* func_field) { +void wabt_destroy_func_fields(WabtFuncField* func_field) { /* destroy the entire linked-list */ while (func_field) { WabtFuncField* next_func_field = func_field->next; switch (func_field->type) { case WABT_FUNC_FIELD_TYPE_EXPRS: - wabt_destroy_expr_list(allocator, func_field->first_expr); + wabt_destroy_expr_list(func_field->first_expr); break; case WABT_FUNC_FIELD_TYPE_PARAM_TYPES: case WABT_FUNC_FIELD_TYPE_LOCAL_TYPES: case WABT_FUNC_FIELD_TYPE_RESULT_TYPES: - wabt_destroy_type_vector(allocator, &func_field->types); + wabt_destroy_type_vector(&func_field->types); break; case WABT_FUNC_FIELD_TYPE_BOUND_PARAM: case WABT_FUNC_FIELD_TYPE_BOUND_LOCAL: - wabt_destroy_string_slice(allocator, &func_field->bound_type.name); + wabt_destroy_string_slice(&func_field->bound_type.name); break; } - wabt_free(allocator, func_field); + wabt_free(func_field); func_field = next_func_field; } } -void wabt_destroy_exported_memory(WabtAllocator* allocator, - WabtExportedMemory* memory) { - wabt_destroy_memory(allocator, &memory->memory); - wabt_destroy_optional_export(allocator, &memory->export_); +void wabt_destroy_exported_memory(WabtExportedMemory* memory) { + wabt_destroy_memory(&memory->memory); + wabt_destroy_optional_export(&memory->export_); if (memory->has_data_segment) - wabt_destroy_data_segment(allocator, &memory->data_segment); + wabt_destroy_data_segment(&memory->data_segment); } -void wabt_destroy_exported_table(WabtAllocator* allocator, - WabtExportedTable* table) { - wabt_destroy_table(allocator, &table->table); - wabt_destroy_optional_export(allocator, &table->export_); +void wabt_destroy_exported_table(WabtExportedTable* table) { + wabt_destroy_table(&table->table); + wabt_destroy_optional_export(&table->export_); if (table->has_elem_segment) - wabt_destroy_elem_segment(allocator, &table->elem_segment); + wabt_destroy_elem_segment(&table->elem_segment); } diff --git a/src/ast-parser-lexer-shared.h b/src/ast-parser-lexer-shared.h index e8982636..f66e19e6 100644 --- a/src/ast-parser-lexer-shared.h +++ b/src/ast-parser-lexer-shared.h @@ -30,8 +30,6 @@ #define WABT_INVALID_LINE_OFFSET ((size_t)~0) -struct WabtAllocator; - typedef struct WabtExprList { WabtExpr* first; WabtExpr* last; @@ -149,14 +147,12 @@ typedef union WabtToken { } WabtToken; typedef struct WabtAstParser { - struct WabtAllocator* allocator; WabtScript script; WabtSourceErrorHandler* error_handler; int errors; } WabtAstParser; WABT_EXTERN_C_BEGIN -struct WabtAllocator* wabt_ast_lexer_get_allocator(WabtAstLexer* lexer); int wabt_ast_lexer_lex(union WabtToken*, struct WabtLocation*, WabtAstLexer*, @@ -177,13 +173,13 @@ void wabt_ast_format_error(WabtSourceErrorHandler*, WabtAstLexer*, const char* format, va_list); -void wabt_destroy_optional_export(WabtAllocator*, WabtOptionalExport*); -void wabt_destroy_exported_func(WabtAllocator*, WabtExportedFunc*); -void wabt_destroy_exported_global(WabtAllocator*, WabtExportedFunc*); -void wabt_destroy_exported_memory(WabtAllocator*, WabtExportedMemory*); -void wabt_destroy_exported_table(WabtAllocator*, WabtExportedTable*); -void wabt_destroy_func_fields(WabtAllocator*, WabtFuncField*); -void wabt_destroy_text_list(WabtAllocator*, WabtTextList*); +void wabt_destroy_optional_export(WabtOptionalExport*); +void wabt_destroy_exported_func(WabtExportedFunc*); +void wabt_destroy_exported_global(WabtExportedFunc*); +void wabt_destroy_exported_memory(WabtExportedMemory*); +void wabt_destroy_exported_table(WabtExportedTable*); +void wabt_destroy_func_fields(WabtFuncField*); +void wabt_destroy_text_list(WabtTextList*); WABT_EXTERN_C_END #endif /* WABT_AST_PARSER_LEXER_SHARED_H_ */ diff --git a/src/ast-parser.y b/src/ast-parser.y index cff755ce..4fc591c2 100644 --- a/src/ast-parser.y +++ b/src/ast-parser.y @@ -20,7 +20,6 @@ #include <stdio.h> #include <stdlib.h> -#include "allocator.h" #include "ast-parser.h" #include "ast-parser-lexer-shared.h" #include "binary-reader-ast.h" @@ -40,8 +39,8 @@ defines are available. */ #define YYMAXDEPTH 10000000 -#define DUPTEXT(dst, src) \ - (dst).start = wabt_strndup(parser->allocator, (src).start, (src).length); \ +#define DUPTEXT(dst, src) \ + (dst).start = wabt_strndup((src).start, (src).length); \ (dst).length = (src).length #define YYLLOC_DEFAULT(Current, Rhs, N) \ @@ -61,27 +60,26 @@ #define APPEND_FIELD_TO_LIST(module, field, KIND, kind, loc_, item) \ do { \ - field = wabt_append_module_field(parser->allocator, module); \ + field = wabt_append_module_field(module); \ field->loc = loc_; \ field->type = WABT_MODULE_FIELD_TYPE_##KIND; \ field->kind = item; \ } while (0) -#define APPEND_ITEM_TO_VECTOR(module, Kind, kind, kinds, item_ptr) \ - do { \ - Wabt##Kind* dummy = item_ptr; \ - wabt_append_##kind##_ptr_value(parser->allocator, &(module)->kinds, \ - &dummy); \ +#define APPEND_ITEM_TO_VECTOR(module, Kind, kind, kinds, item_ptr) \ + do { \ + Wabt##Kind* dummy = item_ptr; \ + wabt_append_##kind##_ptr_value(&(module)->kinds, &dummy); \ } while (0) -#define INSERT_BINDING(module, kind, kinds, loc_, name) \ - do \ - if ((name).start) { \ - WabtBinding* binding = wabt_insert_binding( \ - parser->allocator, &(module)->kind##_bindings, &(name)); \ - binding->loc = loc_; \ - binding->index = (module)->kinds.size - 1; \ - } \ +#define INSERT_BINDING(module, kind, kinds, loc_, name) \ + do \ + if ((name).start) { \ + WabtBinding* binding = \ + wabt_insert_binding(&(module)->kind##_bindings, &(name)); \ + binding->loc = loc_; \ + binding->index = (module)->kinds.size - 1; \ + } \ while (0) #define APPEND_INLINE_EXPORT(module, KIND, loc_, value, index_) \ @@ -124,12 +122,12 @@ WABT_PRINTF_STRING_SLICE_ARG(begin_label), \ WABT_PRINTF_STRING_SLICE_ARG(end_label)); \ } \ - wabt_destroy_string_slice(parser->allocator, &(end_label)); \ + wabt_destroy_string_slice(&(end_label)); \ } \ } while (0) -#define YYMALLOC(size) wabt_alloc(parser->allocator, size, WABT_DEFAULT_ALIGN) -#define YYFREE(p) wabt_free(parser->allocator, p) +#define YYMALLOC(size) wabt_alloc(size) +#define YYFREE(p) wabt_free(p) #define USE_NATURAL_ALIGNMENT (~0) @@ -137,40 +135,39 @@ static WabtExprList join_exprs1(WabtLocation* loc, WabtExpr* expr1); static WabtExprList join_exprs2(WabtLocation* loc, WabtExprList* expr1, WabtExpr* expr2); -static WabtFuncField* new_func_field(WabtAllocator* allocator) { - return wabt_alloc_zero(allocator, sizeof(WabtFuncField), WABT_DEFAULT_ALIGN); +static WabtFuncField* new_func_field(void) { + return wabt_alloc_zero(sizeof(WabtFuncField)); } -static WabtFunc* new_func(WabtAllocator* allocator) { - return wabt_alloc_zero(allocator, sizeof(WabtFunc), WABT_DEFAULT_ALIGN); +static WabtFunc* new_func(void) { + return wabt_alloc_zero(sizeof(WabtFunc)); } -static WabtCommand* new_command(WabtAllocator* allocator) { - return wabt_alloc_zero(allocator, sizeof(WabtCommand), WABT_DEFAULT_ALIGN); +static WabtCommand* new_command(void) { + return wabt_alloc_zero(sizeof(WabtCommand)); } -static WabtModule* new_module(WabtAllocator* allocator) { - return wabt_alloc_zero(allocator, sizeof(WabtModule), WABT_DEFAULT_ALIGN); +static WabtModule* new_module(void) { + return wabt_alloc_zero(sizeof(WabtModule)); } -static WabtImport* new_import(WabtAllocator* allocator) { - return wabt_alloc_zero(allocator, sizeof(WabtImport), WABT_DEFAULT_ALIGN); +static WabtImport* new_import(void) { + return wabt_alloc_zero(sizeof(WabtImport)); } -static WabtTextListNode* new_text_list_node(WabtAllocator* allocator) { - return wabt_alloc_zero(allocator, sizeof(WabtTextListNode), - WABT_DEFAULT_ALIGN); +static WabtTextListNode* new_text_list_node(void) { + return wabt_alloc_zero(sizeof(WabtTextListNode)); } static WabtResult parse_const(WabtType type, WabtLiteralType literal_type, const char* s, const char* end, WabtConst* out); -static void dup_text_list(WabtAllocator*, WabtTextList* text_list, - void** out_data, size_t* out_size); +static void dup_text_list(WabtTextList * text_list, void** out_data, + size_t* out_size); static WabtBool is_empty_signature(WabtFuncSignature* sig); -static void append_implicit_func_declaration(WabtAllocator*, WabtLocation*, - WabtModule*, WabtFuncDeclaration*); +static void append_implicit_func_declaration(WabtLocation*, WabtModule*, + WabtFuncDeclaration*); typedef struct BinaryErrorCallbackData { WabtLocation* loc; @@ -257,32 +254,32 @@ static void on_read_binary_error(uint32_t offset, const char* error, /* These non-terminals use the types below that have destructors, but the * memory is shared with the lexer, so should not be destroyed. */ %destructor {} ALIGN_EQ_NAT OFFSET_EQ_NAT TEXT VAR NAT INT FLOAT -%destructor { wabt_destroy_block(parser->allocator, &$$); } <block> -%destructor { wabt_destroy_command(parser->allocator, $$); wabt_free(parser->allocator, $$); } <command> -%destructor { wabt_destroy_command_vector_and_elements(parser->allocator, &$$); } <commands> -%destructor { wabt_destroy_const_vector(parser->allocator, &$$); } <consts> -%destructor { wabt_destroy_elem_segment(parser->allocator, &$$); } <elem_segment> -%destructor { wabt_destroy_export(parser->allocator, &$$); } <export_> -%destructor { wabt_destroy_exported_func(parser->allocator, &$$); } <exported_func> -%destructor { wabt_destroy_exported_memory(parser->allocator, &$$); } <exported_memory> -%destructor { wabt_destroy_exported_table(parser->allocator, &$$); } <exported_table> -%destructor { wabt_destroy_expr(parser->allocator, $$); } <expr> -%destructor { wabt_destroy_expr_list(parser->allocator, $$.first); } <expr_list> -%destructor { wabt_destroy_func_fields(parser->allocator, $$); } <func_fields> -%destructor { wabt_destroy_func(parser->allocator, $$); wabt_free(parser->allocator, $$); } <func> -%destructor { wabt_destroy_func_signature(parser->allocator, &$$); } <func_sig> -%destructor { wabt_destroy_func_type(parser->allocator, &$$); } <func_type> -%destructor { wabt_destroy_import(parser->allocator, $$); wabt_free(parser->allocator, $$); } <import> -%destructor { wabt_destroy_data_segment(parser->allocator, &$$); } <data_segment> -%destructor { wabt_destroy_module(parser->allocator, $$); wabt_free(parser->allocator, $$); } <module> -%destructor { wabt_destroy_raw_module(parser->allocator, &$$); } <raw_module> -%destructor { wabt_destroy_string_slice(parser->allocator, &$$.text); } <literal> +%destructor { wabt_destroy_block(&$$); } <block> +%destructor { wabt_destroy_command($$); wabt_free($$); } <command> +%destructor { wabt_destroy_command_vector_and_elements(&$$); } <commands> +%destructor { wabt_destroy_const_vector(&$$); } <consts> +%destructor { wabt_destroy_elem_segment(&$$); } <elem_segment> +%destructor { wabt_destroy_export(&$$); } <export_> +%destructor { wabt_destroy_exported_func(&$$); } <exported_func> +%destructor { wabt_destroy_exported_memory(&$$); } <exported_memory> +%destructor { wabt_destroy_exported_table(&$$); } <exported_table> +%destructor { wabt_destroy_expr($$); } <expr> +%destructor { wabt_destroy_expr_list($$.first); } <expr_list> +%destructor { wabt_destroy_func_fields($$); } <func_fields> +%destructor { wabt_destroy_func($$); wabt_free($$); } <func> +%destructor { wabt_destroy_func_signature(&$$); } <func_sig> +%destructor { wabt_destroy_func_type(&$$); } <func_type> +%destructor { wabt_destroy_import($$); wabt_free($$); } <import> +%destructor { wabt_destroy_data_segment(&$$); } <data_segment> +%destructor { wabt_destroy_module($$); wabt_free($$); } <module> +%destructor { wabt_destroy_raw_module(&$$); } <raw_module> +%destructor { wabt_destroy_string_slice(&$$.text); } <literal> %destructor { wabt_destroy_script(&$$); } <script> -%destructor { wabt_destroy_string_slice(parser->allocator, &$$); } <text> -%destructor { wabt_destroy_text_list(parser->allocator, &$$); } <text_list> -%destructor { wabt_destroy_type_vector(parser->allocator, &$$); } <types> -%destructor { wabt_destroy_var_vector_and_elements(parser->allocator, &$$); } <vars> -%destructor { wabt_destroy_var(parser->allocator, &$$); } <var> +%destructor { wabt_destroy_string_slice(&$$); } <text> +%destructor { wabt_destroy_text_list(&$$); } <text_list> +%destructor { wabt_destroy_type_vector(&$$); } <types> +%destructor { wabt_destroy_var_vector_and_elements(&$$); } <vars> +%destructor { wabt_destroy_var(&$$); } <var> %nonassoc LOW @@ -296,14 +293,14 @@ static void on_read_binary_error(uint32_t offset, const char* error, non_empty_text_list : TEXT { - WabtTextListNode* node = new_text_list_node(parser->allocator); + WabtTextListNode* node = new_text_list_node(); DUPTEXT(node->text, $1); node->next = NULL; $$.first = $$.last = node; } | non_empty_text_list TEXT { $$ = $1; - WabtTextListNode* node = new_text_list_node(parser->allocator); + WabtTextListNode* node = new_text_list_node(); DUPTEXT(node->text, $2); node->next = NULL; $$.last->next = node; @@ -325,7 +322,7 @@ quoted_text : text_list.last = &node; void* data; size_t size; - dup_text_list(parser->allocator, &text_list, &data, &size); + dup_text_list(&text_list, &data, &size); $$.start = data; $$.length = size; } @@ -337,7 +334,7 @@ value_type_list : /* empty */ { WABT_ZERO_MEMORY($$); } | value_type_list VALUE_TYPE { $$ = $1; - wabt_append_type_value(parser->allocator, &$$, &$2); + wabt_append_type_value(&$$, &$2); } ; elem_type : @@ -441,7 +438,7 @@ var_list : /* empty */ { WABT_ZERO_MEMORY($$); } | var_list var { $$ = $1; - wabt_append_var_value(parser->allocator, &$$, &$2); + wabt_append_var_value(&$$, &$2); } ; bind_var_opt : @@ -487,75 +484,75 @@ instr : ; plain_instr : UNREACHABLE { - $$ = wabt_new_unreachable_expr(parser->allocator); + $$ = wabt_new_unreachable_expr(); } | NOP { - $$ = wabt_new_nop_expr(parser->allocator); + $$ = wabt_new_nop_expr(); } | DROP { - $$ = wabt_new_drop_expr(parser->allocator); + $$ = wabt_new_drop_expr(); } | SELECT { - $$ = wabt_new_select_expr(parser->allocator); + $$ = wabt_new_select_expr(); } | BR var { - $$ = wabt_new_br_expr(parser->allocator); + $$ = wabt_new_br_expr(); $$->br.var = $2; } | BR_IF var { - $$ = wabt_new_br_if_expr(parser->allocator); + $$ = wabt_new_br_if_expr(); $$->br_if.var = $2; } | BR_TABLE var_list var { - $$ = wabt_new_br_table_expr(parser->allocator); + $$ = wabt_new_br_table_expr(); $$->br_table.targets = $2; $$->br_table.default_target = $3; } | RETURN { - $$ = wabt_new_return_expr(parser->allocator); + $$ = wabt_new_return_expr(); } | CALL var { - $$ = wabt_new_call_expr(parser->allocator); + $$ = wabt_new_call_expr(); $$->call.var = $2; } | CALL_INDIRECT var { - $$ = wabt_new_call_indirect_expr(parser->allocator); + $$ = wabt_new_call_indirect_expr(); $$->call_indirect.var = $2; } | GET_LOCAL var { - $$ = wabt_new_get_local_expr(parser->allocator); + $$ = wabt_new_get_local_expr(); $$->get_local.var = $2; } | SET_LOCAL var { - $$ = wabt_new_set_local_expr(parser->allocator); + $$ = wabt_new_set_local_expr(); $$->set_local.var = $2; } | TEE_LOCAL var { - $$ = wabt_new_tee_local_expr(parser->allocator); + $$ = wabt_new_tee_local_expr(); $$->tee_local.var = $2; } | GET_GLOBAL var { - $$ = wabt_new_get_global_expr(parser->allocator); + $$ = wabt_new_get_global_expr(); $$->get_global.var = $2; } | SET_GLOBAL var { - $$ = wabt_new_set_global_expr(parser->allocator); + $$ = wabt_new_set_global_expr(); $$->set_global.var = $2; } | LOAD offset_opt align_opt { - $$ = wabt_new_load_expr(parser->allocator); + $$ = wabt_new_load_expr(); $$->load.opcode = $1; $$->load.offset = $2; $$->load.align = $3; } | STORE offset_opt align_opt { - $$ = wabt_new_store_expr(parser->allocator); + $$ = wabt_new_store_expr(); $$->store.opcode = $1; $$->store.offset = $2; $$->store.align = $3; } | CONST literal { - $$ = wabt_new_const_expr(parser->allocator); + $$ = wabt_new_const_expr(); $$->const_.loc = @1; if (WABT_FAILED(parse_const($1, $2.type, $2.text.start, $2.text.start + $2.text.length, @@ -564,52 +561,52 @@ plain_instr : "invalid literal \"" PRIstringslice "\"", WABT_PRINTF_STRING_SLICE_ARG($2.text)); } - wabt_free(parser->allocator, (char*)$2.text.start); + wabt_free((char*)$2.text.start); } | UNARY { - $$ = wabt_new_unary_expr(parser->allocator); + $$ = wabt_new_unary_expr(); $$->unary.opcode = $1; } | BINARY { - $$ = wabt_new_binary_expr(parser->allocator); + $$ = wabt_new_binary_expr(); $$->binary.opcode = $1; } | COMPARE { - $$ = wabt_new_compare_expr(parser->allocator); + $$ = wabt_new_compare_expr(); $$->compare.opcode = $1; } | CONVERT { - $$ = wabt_new_convert_expr(parser->allocator); + $$ = wabt_new_convert_expr(); $$->convert.opcode = $1; } | CURRENT_MEMORY { - $$ = wabt_new_current_memory_expr(parser->allocator); + $$ = wabt_new_current_memory_expr(); } | GROW_MEMORY { - $$ = wabt_new_grow_memory_expr(parser->allocator); + $$ = wabt_new_grow_memory_expr(); } ; block_instr : BLOCK labeling_opt block END labeling_opt { - $$ = wabt_new_block_expr(parser->allocator); + $$ = wabt_new_block_expr(); $$->block = $3; $$->block.label = $2; CHECK_END_LABEL(@5, $$->block.label, $5); } | LOOP labeling_opt block END labeling_opt { - $$ = wabt_new_loop_expr(parser->allocator); + $$ = wabt_new_loop_expr(); $$->loop = $3; $$->loop.label = $2; CHECK_END_LABEL(@5, $$->block.label, $5); } | IF labeling_opt block END labeling_opt { - $$ = wabt_new_if_expr(parser->allocator); + $$ = wabt_new_if_expr(); $$->if_.true_ = $3; $$->if_.true_.label = $2; CHECK_END_LABEL(@5, $$->block.label, $5); } | IF labeling_opt block ELSE labeling_opt instr_list END labeling_opt { - $$ = wabt_new_if_expr(parser->allocator); + $$ = wabt_new_if_expr(); $$->if_.true_ = $3; $$->if_.true_.label = $2; $$->if_.false_ = $6.first; @@ -634,13 +631,13 @@ expr1 : $$ = join_exprs2(&@1, &$2, $1); } | BLOCK labeling_opt block { - WabtExpr* expr = wabt_new_block_expr(parser->allocator); + WabtExpr* expr = wabt_new_block_expr(); expr->block = $3; expr->block.label = $2; $$ = join_exprs1(&@1, expr); } | LOOP labeling_opt block { - WabtExpr* expr = wabt_new_loop_expr(parser->allocator); + WabtExpr* expr = wabt_new_loop_expr(); expr->loop = $3; expr->loop.label = $2; $$ = join_exprs1(&@1, expr); @@ -655,35 +652,35 @@ expr1 : ; if_ : LPAR THEN instr_list RPAR LPAR ELSE instr_list RPAR { - WabtExpr* expr = wabt_new_if_expr(parser->allocator); + WabtExpr* expr = wabt_new_if_expr(); expr->if_.true_.first = $3.first; expr->if_.false_ = $7.first; $$ = join_exprs1(&@1, expr); } | LPAR THEN instr_list RPAR { - WabtExpr* expr = wabt_new_if_expr(parser->allocator); + WabtExpr* expr = wabt_new_if_expr(); expr->if_.true_.first = $3.first; $$ = join_exprs1(&@1, expr); } | expr LPAR THEN instr_list RPAR LPAR ELSE instr_list RPAR { - WabtExpr* expr = wabt_new_if_expr(parser->allocator); + WabtExpr* expr = wabt_new_if_expr(); expr->if_.true_.first = $4.first; expr->if_.false_ = $8.first; $$ = join_exprs2(&@1, &$1, expr); } | expr LPAR THEN instr_list RPAR { - WabtExpr* expr = wabt_new_if_expr(parser->allocator); + WabtExpr* expr = wabt_new_if_expr(); expr->if_.true_.first = $4.first; $$ = join_exprs2(&@1, &$1, expr); } | expr expr expr { - WabtExpr* expr = wabt_new_if_expr(parser->allocator); + WabtExpr* expr = wabt_new_if_expr(); expr->if_.true_.first = $2.first; expr->if_.false_ = $3.first; $$ = join_exprs2(&@1, &$1, expr); } | expr expr { - WabtExpr* expr = wabt_new_if_expr(parser->allocator); + WabtExpr* expr = wabt_new_if_expr(); expr->if_.true_.first = $2.first; $$ = join_exprs2(&@1, &$1, expr); } @@ -715,19 +712,19 @@ const_expr : func_fields : func_body | LPAR RESULT value_type_list RPAR func_body { - $$ = new_func_field(parser->allocator); + $$ = new_func_field(); $$->type = WABT_FUNC_FIELD_TYPE_RESULT_TYPES; $$->types = $3; $$->next = $5; } | LPAR PARAM value_type_list RPAR func_fields { - $$ = new_func_field(parser->allocator); + $$ = new_func_field(); $$->type = WABT_FUNC_FIELD_TYPE_PARAM_TYPES; $$->types = $3; $$->next = $5; } | LPAR PARAM bind_var VALUE_TYPE RPAR func_fields { - $$ = new_func_field(parser->allocator); + $$ = new_func_field(); $$->type = WABT_FUNC_FIELD_TYPE_BOUND_PARAM; $$->bound_type.loc = @2; $$->bound_type.name = $3; @@ -737,19 +734,19 @@ func_fields : ; func_body : instr_list { - $$ = new_func_field(parser->allocator); + $$ = new_func_field(); $$->type = WABT_FUNC_FIELD_TYPE_EXPRS; $$->first_expr = $1.first; $$->next = NULL; } | LPAR LOCAL value_type_list RPAR func_body { - $$ = new_func_field(parser->allocator); + $$ = new_func_field(); $$->type = WABT_FUNC_FIELD_TYPE_LOCAL_TYPES; $$->types = $3; $$->next = $5; } | LPAR LOCAL bind_var VALUE_TYPE RPAR func_body { - $$ = new_func_field(parser->allocator); + $$ = new_func_field(); $$->type = WABT_FUNC_FIELD_TYPE_BOUND_LOCAL; $$->bound_type.loc = @2; $$->bound_type.name = $3; @@ -759,7 +756,7 @@ func_body : ; func_info : func_fields { - $$ = new_func(parser->allocator); + $$ = new_func(); WabtFuncField* field = $1; while (field) { @@ -775,8 +772,8 @@ func_info : field->type == WABT_FUNC_FIELD_TYPE_PARAM_TYPES ? &$$->decl.sig.param_types : &$$->local_types; - wabt_extend_types(parser->allocator, types, &field->types); - wabt_destroy_type_vector(parser->allocator, &field->types); + wabt_extend_types(types, &field->types); + wabt_destroy_type_vector(&field->types); break; } @@ -792,10 +789,9 @@ func_info : bindings = &$$->local_bindings; } - wabt_append_type_value(parser->allocator, types, - &field->bound_type.type); - WabtBinding* binding = wabt_insert_binding( - parser->allocator, bindings, &field->bound_type.name); + wabt_append_type_value(types, &field->bound_type.type); + WabtBinding* binding = + wabt_insert_binding(bindings, &field->bound_type.name); binding->loc = field->bound_type.loc; binding->index = types->size - 1; break; @@ -807,7 +803,7 @@ func_info : } /* we steal memory from the func field, but not the linked list nodes */ - wabt_free(parser->allocator, field); + wabt_free(field); field = next; } } @@ -878,7 +874,7 @@ table : } | LPAR TABLE bind_var_opt inline_export_opt elem_type LPAR ELEM var_list RPAR RPAR { - WabtExpr* expr = wabt_new_const_expr(parser->allocator); + WabtExpr* expr = wabt_new_const_expr(); expr->loc = @2; expr->const_.type = WABT_TYPE_I32; expr->const_.u32 = 0; @@ -900,8 +896,8 @@ data : WABT_ZERO_MEMORY($$); $$.memory_var = $3; $$.offset = $4.first; - dup_text_list(parser->allocator, &$5, &$$.data, &$$.size); - wabt_destroy_text_list(parser->allocator, &$5); + dup_text_list(&$5, &$$.data, &$$.size); + wabt_destroy_text_list(&$5); } | LPAR DATA offset text_list RPAR { WABT_ZERO_MEMORY($$); @@ -909,8 +905,8 @@ data : $$.memory_var.type = WABT_VAR_TYPE_INDEX; $$.memory_var.index = 0; $$.offset = $3.first; - dup_text_list(parser->allocator, &$4, &$$.data, &$$.size); - wabt_destroy_text_list(parser->allocator, &$4); + dup_text_list(&$4, &$$.data, &$$.size); + wabt_destroy_text_list(&$4); } ; @@ -923,7 +919,7 @@ memory : $$.export_ = $4; } | LPAR MEMORY bind_var_opt inline_export LPAR DATA text_list RPAR RPAR { - WabtExpr* expr = wabt_new_const_expr(parser->allocator); + WabtExpr* expr = wabt_new_const_expr(); expr->loc = @2; expr->const_.type = WABT_TYPE_I32; expr->const_.u32 = 0; @@ -931,9 +927,8 @@ memory : WABT_ZERO_MEMORY($$); $$.has_data_segment = WABT_TRUE; $$.data_segment.offset = expr; - dup_text_list(parser->allocator, &$7, &$$.data_segment.data, - &$$.data_segment.size); - wabt_destroy_text_list(parser->allocator, &$7); + dup_text_list(&$7, &$$.data_segment.data, &$$.data_segment.size); + wabt_destroy_text_list(&$7); uint32_t byte_size = WABT_ALIGN_UP_TO_PAGE($$.data_segment.size); uint32_t page_size = WABT_BYTES_TO_PAGES(byte_size); $$.memory.name = $3; @@ -944,7 +939,7 @@ memory : } /* Duplicate above for empty inline_export_opt to avoid LR(1) conflict. */ | LPAR MEMORY bind_var_opt LPAR DATA text_list RPAR RPAR { - WabtExpr* expr = wabt_new_const_expr(parser->allocator); + WabtExpr* expr = wabt_new_const_expr(); expr->loc = @2; expr->const_.type = WABT_TYPE_I32; expr->const_.u32 = 0; @@ -952,9 +947,8 @@ memory : WABT_ZERO_MEMORY($$); $$.has_data_segment = WABT_TRUE; $$.data_segment.offset = expr; - dup_text_list(parser->allocator, &$6, &$$.data_segment.data, - &$$.data_segment.size); - wabt_destroy_text_list(parser->allocator, &$6); + dup_text_list(&$6, &$$.data_segment.data, &$$.data_segment.size); + wabt_destroy_text_list(&$6); uint32_t byte_size = WABT_ALIGN_UP_TO_PAGE($$.data_segment.size); uint32_t page_size = WABT_BYTES_TO_PAGES(byte_size); $$.memory.name = $3; @@ -987,32 +981,32 @@ global : import_kind : LPAR FUNC bind_var_opt type_use RPAR { - $$ = new_import(parser->allocator); + $$ = new_import(); $$->kind = WABT_EXTERNAL_KIND_FUNC; $$->func.name = $3; $$->func.decl.flags = WABT_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; $$->func.decl.type_var = $4; } | LPAR FUNC bind_var_opt func_sig RPAR { - $$ = new_import(parser->allocator); + $$ = new_import(); $$->kind = WABT_EXTERNAL_KIND_FUNC; $$->func.name = $3; $$->func.decl.sig = $4; } | LPAR TABLE bind_var_opt table_sig RPAR { - $$ = new_import(parser->allocator); + $$ = new_import(); $$->kind = WABT_EXTERNAL_KIND_TABLE; $$->table = $4; $$->table.name = $3; } | LPAR MEMORY bind_var_opt memory_sig RPAR { - $$ = new_import(parser->allocator); + $$ = new_import(); $$->kind = WABT_EXTERNAL_KIND_MEMORY; $$->memory = $4; $$->memory.name = $3; } | LPAR GLOBAL bind_var_opt global_type RPAR { - $$ = new_import(parser->allocator); + $$ = new_import(); $$->kind = WABT_EXTERNAL_KIND_GLOBAL; $$->global = $4; $$->global.name = $3; @@ -1059,7 +1053,7 @@ import : inline_import : LPAR IMPORT quoted_text quoted_text RPAR { - $$ = new_import(parser->allocator); + $$ = new_import(); $$->module_name = $3; $$->field_name = $4; } @@ -1129,7 +1123,7 @@ start : module_fields : /* empty */ { - $$ = new_module(parser->allocator); + $$ = new_module(); } | module_fields type_def { $$ = $1; @@ -1184,12 +1178,11 @@ module_fields : $$ = $1; WabtModuleField* field; APPEND_FIELD_TO_LIST($$, field, FUNC, func, @2, *$2.func); - append_implicit_func_declaration(parser->allocator, &@2, $$, - &field->func.decl); + append_implicit_func_declaration(&@2, $$, &field->func.decl); APPEND_ITEM_TO_VECTOR($$, Func, func, funcs, &field->func); INSERT_BINDING($$, func, funcs, @2, $2.func->name); APPEND_INLINE_EXPORT($$, FUNC, @2, $2, $$->funcs.size - 1); - wabt_free(parser->allocator, $2.func); + wabt_free($2.func); } | module_fields elem { $$ = $1; @@ -1221,8 +1214,7 @@ module_fields : CHECK_IMPORT_ORDERING($$, global, globals, @2); switch ($2->kind) { case WABT_EXTERNAL_KIND_FUNC: - append_implicit_func_declaration(parser->allocator, &@2, $$, - &field->import.func.decl); + append_implicit_func_declaration(&@2, $$, &field->import.func.decl); APPEND_ITEM_TO_VECTOR($$, Func, func, funcs, &field->import.func); INSERT_BINDING($$, func, funcs, @2, field->import.func.name); $$->num_func_imports++; @@ -1248,12 +1240,12 @@ module_fields : assert(0); break; } - wabt_free(parser->allocator, $2); + wabt_free($2); APPEND_ITEM_TO_VECTOR($$, Import, import, imports, &field->import); } | module_fields export { $$ = $1; - WabtModuleField* field = wabt_append_module_field(parser->allocator, $$); + WabtModuleField* field = wabt_append_module_field($$); APPEND_FIELD_TO_LIST($$, field, EXPORT, export_, @2, $2); APPEND_ITEM_TO_VECTOR($$, Export, export, exports, &field->export_); INSERT_BINDING($$, export, exports, @2, $2.name); @@ -1287,8 +1279,8 @@ raw_module : $$.type = WABT_RAW_MODULE_TYPE_BINARY; $$.binary.name = $3; $$.binary.loc = @2; - dup_text_list(parser->allocator, &$4, &$$.binary.data, &$$.binary.size); - wabt_destroy_text_list(parser->allocator, &$4); + dup_text_list(&$4, &$$.binary.data, &$$.binary.size); + wabt_destroy_text_list(&$4); } ; @@ -1298,7 +1290,7 @@ module : $$ = $1.text; } else { assert($1.type == WABT_RAW_MODULE_TYPE_BINARY); - $$ = new_module(parser->allocator); + $$ = new_module(); WabtReadBinaryOptions options = WABT_READ_BINARY_OPTIONS_DEFAULT; BinaryErrorCallbackData user_data; user_data.loc = &$1.binary.loc; @@ -1307,9 +1299,9 @@ module : WabtBinaryErrorHandler error_handler; error_handler.on_error = on_read_binary_error; error_handler.user_data = &user_data; - wabt_read_binary_ast(parser->allocator, $1.binary.data, $1.binary.size, - &options, &error_handler, $$); - wabt_free(parser->allocator, $1.binary.data); + wabt_read_binary_ast($1.binary.data, $1.binary.size, &options, + &error_handler, $$); + wabt_free($1.binary.data); $$->name = $1.binary.name; $$->loc = $1.binary.loc; } @@ -1351,48 +1343,48 @@ action : assertion : LPAR ASSERT_MALFORMED raw_module quoted_text RPAR { - $$ = new_command(parser->allocator); + $$ = new_command(); $$->type = WABT_COMMAND_TYPE_ASSERT_MALFORMED; $$->assert_malformed.module = $3; $$->assert_malformed.text = $4; } | LPAR ASSERT_INVALID raw_module quoted_text RPAR { - $$ = new_command(parser->allocator); + $$ = new_command(); $$->type = WABT_COMMAND_TYPE_ASSERT_INVALID; $$->assert_invalid.module = $3; $$->assert_invalid.text = $4; } | LPAR ASSERT_UNLINKABLE raw_module quoted_text RPAR { - $$ = new_command(parser->allocator); + $$ = new_command(); $$->type = WABT_COMMAND_TYPE_ASSERT_UNLINKABLE; $$->assert_unlinkable.module = $3; $$->assert_unlinkable.text = $4; } | LPAR ASSERT_TRAP raw_module quoted_text RPAR { - $$ = new_command(parser->allocator); + $$ = new_command(); $$->type = WABT_COMMAND_TYPE_ASSERT_UNINSTANTIABLE; $$->assert_uninstantiable.module = $3; $$->assert_uninstantiable.text = $4; } | LPAR ASSERT_RETURN action const_list RPAR { - $$ = new_command(parser->allocator); + $$ = new_command(); $$->type = WABT_COMMAND_TYPE_ASSERT_RETURN; $$->assert_return.action = $3; $$->assert_return.expected = $4; } | LPAR ASSERT_RETURN_NAN action RPAR { - $$ = new_command(parser->allocator); + $$ = new_command(); $$->type = WABT_COMMAND_TYPE_ASSERT_RETURN_NAN; $$->assert_return_nan.action = $3; } | LPAR ASSERT_TRAP action quoted_text RPAR { - $$ = new_command(parser->allocator); + $$ = new_command(); $$->type = WABT_COMMAND_TYPE_ASSERT_TRAP; $$->assert_trap.action = $3; $$->assert_trap.text = $4; } | LPAR ASSERT_EXHAUSTION action quoted_text RPAR { - $$ = new_command(parser->allocator); + $$ = new_command(); $$->type = WABT_COMMAND_TYPE_ASSERT_EXHAUSTION; $$->assert_trap.action = $3; $$->assert_trap.text = $4; @@ -1401,19 +1393,19 @@ assertion : cmd : action { - $$ = new_command(parser->allocator); + $$ = new_command(); $$->type = WABT_COMMAND_TYPE_ACTION; $$->action = $1; } | assertion | module { - $$ = new_command(parser->allocator); + $$ = new_command(); $$->type = WABT_COMMAND_TYPE_MODULE; $$->module = *$1; - wabt_free(parser->allocator, $1); + wabt_free($1); } | LPAR REGISTER quoted_text script_var_opt RPAR { - $$ = new_command(parser->allocator); + $$ = new_command(); $$->type = WABT_COMMAND_TYPE_REGISTER; $$->register_.module_name = $3; $$->register_.var = $4; @@ -1424,8 +1416,8 @@ cmd_list : /* empty */ { WABT_ZERO_MEMORY($$); } | cmd_list cmd { $$ = $1; - wabt_append_command_value(parser->allocator, &$$, $2); - wabt_free(parser->allocator, $2); + wabt_append_command_value(&$$, $2); + wabt_free($2); } ; @@ -1438,21 +1430,20 @@ const : "invalid literal \"" PRIstringslice "\"", WABT_PRINTF_STRING_SLICE_ARG($3.text)); } - wabt_free(parser->allocator, (char*)$3.text.start); + wabt_free((char*)$3.text.start); } ; const_list : /* empty */ { WABT_ZERO_MEMORY($$); } | const_list const { $$ = $1; - wabt_append_const_value(parser->allocator, &$$, &$2); + wabt_append_const_value(&$$, &$2); } ; script : cmd_list { WABT_ZERO_MEMORY($$); - $$.allocator = parser->allocator; $$.commands = $1; int last_module_index = -1; @@ -1469,10 +1460,9 @@ script : if (module->name.length == 0) continue; - WabtStringSlice module_name = - wabt_dup_string_slice(parser->allocator, module->name); - WabtBinding* binding = wabt_insert_binding( - parser->allocator, &$$.module_bindings, &module_name); + WabtStringSlice module_name = wabt_dup_string_slice(module->name); + WabtBinding* binding = + wabt_insert_binding(&$$.module_bindings, &module_name); binding->loc = module->loc; binding->index = i; break; @@ -1632,8 +1622,7 @@ static size_t copy_string_contents(WabtStringSlice* text, char* dest) { return dest - dest_start; } -static void dup_text_list(WabtAllocator* allocator, - WabtTextList* text_list, +static void dup_text_list(WabtTextList* text_list, void** out_data, size_t* out_size) { /* walk the linked list to see how much total space is needed */ @@ -1648,7 +1637,7 @@ static void dup_text_list(WabtAllocator* allocator, size_t size = (end > src) ? (end - src) : 0; total_size += size; } - char* result = wabt_alloc(allocator, total_size, 1); + char* result = wabt_alloc(total_size); char* dest = result; for (node = text_list->first; node; node = node->next) { size_t actual_size = copy_string_contents(&node->text, dest); @@ -1662,8 +1651,7 @@ static WabtBool is_empty_signature(WabtFuncSignature* sig) { return sig->result_types.size == 0 && sig->param_types.size == 0; } -static void append_implicit_func_declaration(WabtAllocator* allocator, - WabtLocation* loc, +static void append_implicit_func_declaration(WabtLocation* loc, WabtModule* module, WabtFuncDeclaration* decl) { if (wabt_decl_has_func_type(decl)) @@ -1671,10 +1659,10 @@ static void append_implicit_func_declaration(WabtAllocator* allocator, int sig_index = wabt_get_func_type_index_by_decl(module, decl); if (sig_index == -1) { - wabt_append_implicit_func_type(allocator, loc, module, &decl->sig); + wabt_append_implicit_func_type(loc, module, &decl->sig); } else { /* signature already exists, share that one and destroy this one */ - wabt_destroy_func_signature(allocator, &decl->sig); + wabt_destroy_func_signature(&decl->sig); WabtFuncSignature* sig = &module->func_types.data[sig_index]->sig; decl->sig = *sig; } @@ -1687,9 +1675,6 @@ WabtResult wabt_parse_ast(WabtAstLexer* lexer, WabtSourceErrorHandler* error_handler) { WabtAstParser parser; WABT_ZERO_MEMORY(parser); - WabtAllocator* allocator = wabt_ast_lexer_get_allocator(lexer); - parser.allocator = allocator; - parser.script.allocator = allocator; parser.error_handler = error_handler; int result = wabt_ast_parser_parse(lexer, &parser); *out_script = parser.script; diff --git a/src/ast-writer.c b/src/ast-writer.c index c50ce640..b6d64b71 100644 --- a/src/ast-writer.c +++ b/src/ast-writer.c @@ -31,9 +31,6 @@ #define NO_FORCE_NEWLINE 0 #define FORCE_NEWLINE 1 -#define ALLOC_FAILURE \ - fprintf(stderr, "%s:%d: allocation failed\n", __FILE__, __LINE__) - static const uint8_t s_is_char_escaped[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -55,7 +52,6 @@ typedef enum NextChar { } NextChar; typedef struct Context { - WabtAllocator* allocator; WabtStream stream; WabtResult result; int indent; @@ -526,8 +522,7 @@ static void write_type_bindings(Context* ctx, const WabtFunc* func, const WabtTypeVector* types, const WabtBindingHash* bindings) { - wabt_make_type_binding_reverse_mapping(ctx->allocator, types, bindings, - &ctx->index_to_name); + wabt_make_type_binding_reverse_mapping(types, bindings, &ctx->index_to_name); /* named params/locals must be specified by themselves, but nameless * params/locals can be compressed, e.g.: @@ -748,17 +743,14 @@ static void write_module(Context* ctx, const WabtModule* module) { write_next_char(ctx); } -WabtResult wabt_write_ast(WabtAllocator* allocator, - WabtWriter* writer, - const WabtModule* module) { +WabtResult wabt_write_ast(WabtWriter* writer, const WabtModule* module) { Context ctx; WABT_ZERO_MEMORY(ctx); - ctx.allocator = allocator; ctx.result = WABT_OK; wabt_init_stream(&ctx.stream, writer, NULL); write_module(&ctx, module); /* the memory for the actual string slice is shared with the module, so we * only need to free the vector */ - wabt_destroy_string_slice_vector(allocator, &ctx.index_to_name); + wabt_destroy_string_slice_vector(&ctx.index_to_name); return ctx.result; } diff --git a/src/ast-writer.h b/src/ast-writer.h index 09ee9f3b..1581b23f 100644 --- a/src/ast-writer.h +++ b/src/ast-writer.h @@ -19,12 +19,10 @@ #include "common.h" -struct WabtAllocator; struct WabtModule; struct WabtWriter; -WABT_EXTERN_C WabtResult wabt_write_ast(struct WabtAllocator*, - struct WabtWriter*, +WABT_EXTERN_C WabtResult wabt_write_ast(struct WabtWriter*, const struct WabtModule*); #endif /* WABT_AST_WRITER_H_ */ @@ -19,8 +19,6 @@ #include <assert.h> #include <stddef.h> -#include "allocator.h" - int wabt_get_index_from_var(const WabtBindingHash* hash, const WabtVar* var) { if (var->type == WABT_VAR_TYPE_NAME) return wabt_find_binding_index_by_name(hash, &var->name); @@ -155,12 +153,11 @@ WabtModule* wabt_get_module_by_var(const WabtScript* script, } void wabt_make_type_binding_reverse_mapping( - struct WabtAllocator* allocator, const WabtTypeVector* types, const WabtBindingHash* bindings, WabtStringSliceVector* out_reverse_mapping) { uint32_t num_names = types->size; - wabt_reserve_string_slices(allocator, out_reverse_mapping, num_names); + wabt_reserve_string_slices(out_reverse_mapping, num_names); out_reverse_mapping->size = num_names; memset(out_reverse_mapping->data, 0, num_names * sizeof(WabtStringSlice)); @@ -201,10 +198,8 @@ void wabt_find_duplicate_bindings(const WabtBindingHash* bindings, } } -WabtModuleField* wabt_append_module_field(struct WabtAllocator* allocator, - WabtModule* module) { - WabtModuleField* result = - wabt_alloc_zero(allocator, sizeof(WabtModuleField), WABT_DEFAULT_ALIGN); +WabtModuleField* wabt_append_module_field(WabtModule* module) { + WabtModuleField* result = wabt_alloc_zero(sizeof(WabtModuleField)); if (!module->first_field) module->first_field = result; else if (module->last_field) @@ -213,58 +208,40 @@ WabtModuleField* wabt_append_module_field(struct WabtAllocator* allocator, return result; } -WabtFuncType* wabt_append_implicit_func_type(struct WabtAllocator* allocator, - WabtLocation* loc, +WabtFuncType* wabt_append_implicit_func_type(WabtLocation* loc, WabtModule* module, WabtFuncSignature* sig) { - WabtModuleField* field = wabt_append_module_field(allocator, module); + WabtModuleField* field = wabt_append_module_field(module); field->loc = *loc; field->type = WABT_MODULE_FIELD_TYPE_FUNC_TYPE; field->func_type.sig = *sig; WabtFuncType* func_type_ptr = &field->func_type; - wabt_append_func_type_ptr_value(allocator, &module->func_types, - &func_type_ptr); + wabt_append_func_type_ptr_value(&module->func_types, &func_type_ptr); return func_type_ptr; } -#define ALLOC_EXPR_TYPE_ZERO(allocator, member) \ - wabt_alloc_zero(allocator, \ - offsetof(WabtExpr, member) + sizeof(((WabtExpr*)0)->member), \ - WABT_DEFAULT_ALIGN) - -#define FOREACH_EXPR_TYPE(V) \ - V(WABT_EXPR_TYPE_BINARY, binary, binary) \ - V(WABT_EXPR_TYPE_BLOCK, block, block) \ - V(WABT_EXPR_TYPE_BR, br, br) \ - V(WABT_EXPR_TYPE_BR_IF, br_if, br_if) \ - V(WABT_EXPR_TYPE_BR_TABLE, br_table, br_table) \ - V(WABT_EXPR_TYPE_CALL, call, call) \ - V(WABT_EXPR_TYPE_CALL_INDIRECT, call_indirect, call_indirect) \ - V(WABT_EXPR_TYPE_COMPARE, compare, compare) \ - V(WABT_EXPR_TYPE_CONST, const, const_) \ - V(WABT_EXPR_TYPE_CONVERT, convert, convert) \ - V(WABT_EXPR_TYPE_GET_GLOBAL, get_global, get_global) \ - V(WABT_EXPR_TYPE_GET_LOCAL, get_local, get_local) \ - V(WABT_EXPR_TYPE_IF, if, if_) \ - V(WABT_EXPR_TYPE_LOAD, load, load) \ - V(WABT_EXPR_TYPE_LOOP, loop, loop) \ - V(WABT_EXPR_TYPE_SET_GLOBAL, set_global, set_global) \ - V(WABT_EXPR_TYPE_SET_LOCAL, set_local, set_local) \ - V(WABT_EXPR_TYPE_STORE, store, store) \ - V(WABT_EXPR_TYPE_TEE_LOCAL, tee_local, tee_local) \ - V(WABT_EXPR_TYPE_UNARY, unary, unary) - -#define DEFINE_NEW_EXPR(type_, name, member) \ - WabtExpr* wabt_new_##name##_expr(WabtAllocator* allocator) { \ - WabtExpr* result = ALLOC_EXPR_TYPE_ZERO(allocator, member); \ - result->type = type_; \ - return result; \ - } -FOREACH_EXPR_TYPE(DEFINE_NEW_EXPR) -#undef DEFINE_NEW_EXPR - -#define FOREACH_EMPTY_EXPR_TYPE(V) \ +#define FOREACH_EXPR_TYPE(V) \ + V(WABT_EXPR_TYPE_BINARY, binary) \ + V(WABT_EXPR_TYPE_BLOCK, block) \ + V(WABT_EXPR_TYPE_BR, br) \ + V(WABT_EXPR_TYPE_BR_IF, br_if) \ + V(WABT_EXPR_TYPE_BR_TABLE, br_table) \ + V(WABT_EXPR_TYPE_CALL, call) \ + V(WABT_EXPR_TYPE_CALL_INDIRECT, call_indirect) \ + V(WABT_EXPR_TYPE_COMPARE, compare) \ + V(WABT_EXPR_TYPE_CONST, const) \ + V(WABT_EXPR_TYPE_CONVERT, convert) \ + V(WABT_EXPR_TYPE_GET_GLOBAL, get_global) \ + V(WABT_EXPR_TYPE_GET_LOCAL, get_local) \ + V(WABT_EXPR_TYPE_IF, if) \ + V(WABT_EXPR_TYPE_LOAD, load) \ + V(WABT_EXPR_TYPE_LOOP, loop) \ + V(WABT_EXPR_TYPE_SET_GLOBAL, set_global) \ + V(WABT_EXPR_TYPE_SET_LOCAL, set_local) \ + V(WABT_EXPR_TYPE_STORE, store) \ + V(WABT_EXPR_TYPE_TEE_LOCAL, tee_local) \ + V(WABT_EXPR_TYPE_UNARY, unary) \ V(WABT_EXPR_TYPE_CURRENT_MEMORY, current_memory) \ V(WABT_EXPR_TYPE_DROP, drop) \ V(WABT_EXPR_TYPE_GROW_MEMORY, grow_memory) \ @@ -273,95 +250,86 @@ FOREACH_EXPR_TYPE(DEFINE_NEW_EXPR) V(WABT_EXPR_TYPE_SELECT, select) \ V(WABT_EXPR_TYPE_UNREACHABLE, unreachable) -#define DEFINE_NEW_EMPTY_EXPR(type_, name) \ - WabtExpr* wabt_new_##name##_expr(WabtAllocator* allocator) { \ - WabtExpr* result = ALLOC_EXPR_TYPE_ZERO(allocator, next); \ - result->type = type_; \ - return result; \ +#define DEFINE_NEW_EXPR(type_, name) \ + WabtExpr* wabt_new_##name##_expr(void) { \ + WabtExpr* result = wabt_alloc_zero(sizeof(WabtExpr)); \ + result->type = type_; \ + return result; \ } -FOREACH_EMPTY_EXPR_TYPE(DEFINE_NEW_EMPTY_EXPR) -#undef DEFINE_NEW_EMPTY_EXPR - -WabtExpr* wabt_new_empty_expr(struct WabtAllocator* allocator, - WabtExprType type) { - WabtExpr* result = ALLOC_EXPR_TYPE_ZERO(allocator, next); - result->type = type; - return result; -} +FOREACH_EXPR_TYPE(DEFINE_NEW_EXPR) +#undef DEFINE_NEW_EXPR -void wabt_destroy_var(WabtAllocator* allocator, WabtVar* var) { +void wabt_destroy_var(WabtVar* var) { if (var->type == WABT_VAR_TYPE_NAME) - wabt_destroy_string_slice(allocator, &var->name); + wabt_destroy_string_slice(&var->name); } -void wabt_destroy_var_vector_and_elements(WabtAllocator* allocator, - WabtVarVector* vars) { - WABT_DESTROY_VECTOR_AND_ELEMENTS(allocator, *vars, var); +void wabt_destroy_var_vector_and_elements(WabtVarVector* vars) { + WABT_DESTROY_VECTOR_AND_ELEMENTS(*vars, var); } -void wabt_destroy_func_signature(WabtAllocator* allocator, - WabtFuncSignature* sig) { - wabt_destroy_type_vector(allocator, &sig->param_types); - wabt_destroy_type_vector(allocator, &sig->result_types); +void wabt_destroy_func_signature(WabtFuncSignature* sig) { + wabt_destroy_type_vector(&sig->param_types); + wabt_destroy_type_vector(&sig->result_types); } -void wabt_destroy_expr_list(WabtAllocator* allocator, WabtExpr* first) { +void wabt_destroy_expr_list(WabtExpr* first) { WabtExpr* expr = first; while (expr) { WabtExpr* next = expr->next; - wabt_destroy_expr(allocator, expr); + wabt_destroy_expr(expr); expr = next; } } -void wabt_destroy_block(WabtAllocator* allocator, WabtBlock* block) { - wabt_destroy_string_slice(allocator, &block->label); - wabt_destroy_type_vector(allocator, &block->sig); - wabt_destroy_expr_list(allocator, block->first); +void wabt_destroy_block(WabtBlock* block) { + wabt_destroy_string_slice(&block->label); + wabt_destroy_type_vector(&block->sig); + wabt_destroy_expr_list(block->first); } -void wabt_destroy_expr(WabtAllocator* allocator, WabtExpr* expr) { +void wabt_destroy_expr(WabtExpr* expr) { switch (expr->type) { case WABT_EXPR_TYPE_BLOCK: - wabt_destroy_block(allocator, &expr->block); + wabt_destroy_block(&expr->block); break; case WABT_EXPR_TYPE_BR: - wabt_destroy_var(allocator, &expr->br.var); + wabt_destroy_var(&expr->br.var); break; case WABT_EXPR_TYPE_BR_IF: - wabt_destroy_var(allocator, &expr->br_if.var); + wabt_destroy_var(&expr->br_if.var); break; case WABT_EXPR_TYPE_BR_TABLE: - WABT_DESTROY_VECTOR_AND_ELEMENTS(allocator, expr->br_table.targets, var); - wabt_destroy_var(allocator, &expr->br_table.default_target); + WABT_DESTROY_VECTOR_AND_ELEMENTS(expr->br_table.targets, var); + wabt_destroy_var(&expr->br_table.default_target); break; case WABT_EXPR_TYPE_CALL: - wabt_destroy_var(allocator, &expr->call.var); + wabt_destroy_var(&expr->call.var); break; case WABT_EXPR_TYPE_CALL_INDIRECT: - wabt_destroy_var(allocator, &expr->call_indirect.var); + wabt_destroy_var(&expr->call_indirect.var); break; case WABT_EXPR_TYPE_GET_GLOBAL: - wabt_destroy_var(allocator, &expr->get_global.var); + wabt_destroy_var(&expr->get_global.var); break; case WABT_EXPR_TYPE_GET_LOCAL: - wabt_destroy_var(allocator, &expr->get_local.var); + wabt_destroy_var(&expr->get_local.var); break; case WABT_EXPR_TYPE_IF: - wabt_destroy_block(allocator, &expr->if_.true_); - wabt_destroy_expr_list(allocator, expr->if_.false_); + wabt_destroy_block(&expr->if_.true_); + wabt_destroy_expr_list(expr->if_.false_); break; case WABT_EXPR_TYPE_LOOP: - wabt_destroy_block(allocator, &expr->loop); + wabt_destroy_block(&expr->loop); break; case WABT_EXPR_TYPE_SET_GLOBAL: - wabt_destroy_var(allocator, &expr->set_global.var); + wabt_destroy_var(&expr->set_global.var); break; case WABT_EXPR_TYPE_SET_LOCAL: - wabt_destroy_var(allocator, &expr->set_local.var); + wabt_destroy_var(&expr->set_local.var); break; case WABT_EXPR_TYPE_TEE_LOCAL: - wabt_destroy_var(allocator, &expr->tee_local.var); + wabt_destroy_var(&expr->tee_local.var); break; case WABT_EXPR_TYPE_BINARY: @@ -380,45 +348,44 @@ void wabt_destroy_expr(WabtAllocator* allocator, WabtExpr* expr) { case WABT_EXPR_TYPE_UNREACHABLE: break; } - wabt_free(allocator, expr); + wabt_free(expr); } -void wabt_destroy_func_declaration(WabtAllocator* allocator, - WabtFuncDeclaration* decl) { - wabt_destroy_var(allocator, &decl->type_var); +void wabt_destroy_func_declaration(WabtFuncDeclaration* decl) { + wabt_destroy_var(&decl->type_var); if (!(decl->flags & WABT_FUNC_DECLARATION_FLAG_SHARED_SIGNATURE)) - wabt_destroy_func_signature(allocator, &decl->sig); + wabt_destroy_func_signature(&decl->sig); } -void wabt_destroy_func(WabtAllocator* allocator, WabtFunc* func) { - wabt_destroy_string_slice(allocator, &func->name); - wabt_destroy_func_declaration(allocator, &func->decl); - wabt_destroy_type_vector(allocator, &func->local_types); - wabt_destroy_binding_hash(allocator, &func->param_bindings); - wabt_destroy_binding_hash(allocator, &func->local_bindings); - wabt_destroy_expr_list(allocator, func->first_expr); +void wabt_destroy_func(WabtFunc* func) { + wabt_destroy_string_slice(&func->name); + wabt_destroy_func_declaration(&func->decl); + wabt_destroy_type_vector(&func->local_types); + wabt_destroy_binding_hash(&func->param_bindings); + wabt_destroy_binding_hash(&func->local_bindings); + wabt_destroy_expr_list(func->first_expr); } -void wabt_destroy_global(WabtAllocator* allocator, WabtGlobal* global) { - wabt_destroy_string_slice(allocator, &global->name); - wabt_destroy_expr_list(allocator, global->init_expr); +void wabt_destroy_global(WabtGlobal* global) { + wabt_destroy_string_slice(&global->name); + wabt_destroy_expr_list(global->init_expr); } -void wabt_destroy_import(WabtAllocator* allocator, WabtImport* import) { - wabt_destroy_string_slice(allocator, &import->module_name); - wabt_destroy_string_slice(allocator, &import->field_name); +void wabt_destroy_import(WabtImport* import) { + wabt_destroy_string_slice(&import->module_name); + wabt_destroy_string_slice(&import->field_name); switch (import->kind) { case WABT_EXTERNAL_KIND_FUNC: - wabt_destroy_func(allocator, &import->func); + wabt_destroy_func(&import->func); break; case WABT_EXTERNAL_KIND_TABLE: - wabt_destroy_table(allocator, &import->table); + wabt_destroy_table(&import->table); break; case WABT_EXTERNAL_KIND_MEMORY: - wabt_destroy_memory(allocator, &import->memory); + wabt_destroy_memory(&import->memory); break; case WABT_EXTERNAL_KIND_GLOBAL: - wabt_destroy_global(allocator, &import->global); + wabt_destroy_global(&import->global); break; case WABT_NUM_EXTERNAL_KINDS: assert(0); @@ -426,168 +393,158 @@ void wabt_destroy_import(WabtAllocator* allocator, WabtImport* import) { } } -void wabt_destroy_export(WabtAllocator* allocator, WabtExport* export) { - wabt_destroy_string_slice(allocator, &export->name); - wabt_destroy_var(allocator, &export->var); +void wabt_destroy_export(WabtExport* export) { + wabt_destroy_string_slice(&export->name); + wabt_destroy_var(&export->var); } -void wabt_destroy_func_type(WabtAllocator* allocator, WabtFuncType* func_type) { - wabt_destroy_string_slice(allocator, &func_type->name); - wabt_destroy_func_signature(allocator, &func_type->sig); +void wabt_destroy_func_type(WabtFuncType* func_type) { + wabt_destroy_string_slice(&func_type->name); + wabt_destroy_func_signature(&func_type->sig); } -void wabt_destroy_data_segment(WabtAllocator* allocator, - WabtDataSegment* data) { - wabt_destroy_var(allocator, &data->memory_var); - wabt_destroy_expr_list(allocator, data->offset); - wabt_free(allocator, data->data); +void wabt_destroy_data_segment(WabtDataSegment* data) { + wabt_destroy_var(&data->memory_var); + wabt_destroy_expr_list(data->offset); + wabt_free(data->data); } -void wabt_destroy_memory(struct WabtAllocator* allocator, WabtMemory* memory) { - wabt_destroy_string_slice(allocator, &memory->name); +void wabt_destroy_memory(WabtMemory* memory) { + wabt_destroy_string_slice(&memory->name); } -void wabt_destroy_table(struct WabtAllocator* allocator, WabtTable* table) { - wabt_destroy_string_slice(allocator, &table->name); +void wabt_destroy_table(WabtTable* table) { + wabt_destroy_string_slice(&table->name); } -static void destroy_module_field(WabtAllocator* allocator, - WabtModuleField* field) { +static void destroy_module_field(WabtModuleField* field) { switch (field->type) { case WABT_MODULE_FIELD_TYPE_FUNC: - wabt_destroy_func(allocator, &field->func); + wabt_destroy_func(&field->func); break; case WABT_MODULE_FIELD_TYPE_GLOBAL: - wabt_destroy_global(allocator, &field->global); + wabt_destroy_global(&field->global); break; case WABT_MODULE_FIELD_TYPE_IMPORT: - wabt_destroy_import(allocator, &field->import); + wabt_destroy_import(&field->import); break; case WABT_MODULE_FIELD_TYPE_EXPORT: - wabt_destroy_export(allocator, &field->export_); + wabt_destroy_export(&field->export_); break; case WABT_MODULE_FIELD_TYPE_FUNC_TYPE: - wabt_destroy_func_type(allocator, &field->func_type); + wabt_destroy_func_type(&field->func_type); break; case WABT_MODULE_FIELD_TYPE_TABLE: - wabt_destroy_table(allocator, &field->table); + wabt_destroy_table(&field->table); break; case WABT_MODULE_FIELD_TYPE_ELEM_SEGMENT: - wabt_destroy_elem_segment(allocator, &field->elem_segment); + wabt_destroy_elem_segment(&field->elem_segment); break; case WABT_MODULE_FIELD_TYPE_MEMORY: - wabt_destroy_memory(allocator, &field->memory); + wabt_destroy_memory(&field->memory); break; case WABT_MODULE_FIELD_TYPE_DATA_SEGMENT: - wabt_destroy_data_segment(allocator, &field->data_segment); + wabt_destroy_data_segment(&field->data_segment); break; case WABT_MODULE_FIELD_TYPE_START: - wabt_destroy_var(allocator, &field->start); + wabt_destroy_var(&field->start); break; } } -void wabt_destroy_module(WabtAllocator* allocator, WabtModule* module) { - wabt_destroy_string_slice(allocator, &module->name); +void wabt_destroy_module(WabtModule* module) { + wabt_destroy_string_slice(&module->name); WabtModuleField* field = module->first_field; while (field != NULL) { WabtModuleField* next_field = field->next; - destroy_module_field(allocator, field); - wabt_free(allocator, field); + destroy_module_field(field); + wabt_free(field); field = next_field; } /* everything that follows shares data with the module fields above, so we only need to destroy the containing vectors */ - wabt_destroy_func_ptr_vector(allocator, &module->funcs); - wabt_destroy_global_ptr_vector(allocator, &module->globals); - wabt_destroy_import_ptr_vector(allocator, &module->imports); - wabt_destroy_export_ptr_vector(allocator, &module->exports); - wabt_destroy_func_type_ptr_vector(allocator, &module->func_types); - wabt_destroy_table_ptr_vector(allocator, &module->tables); - wabt_destroy_elem_segment_ptr_vector(allocator, &module->elem_segments); - wabt_destroy_memory_ptr_vector(allocator, &module->memories); - wabt_destroy_data_segment_ptr_vector(allocator, &module->data_segments); - wabt_destroy_binding_hash_entry_vector(allocator, - &module->func_bindings.entries); - wabt_destroy_binding_hash_entry_vector(allocator, - &module->global_bindings.entries); - wabt_destroy_binding_hash_entry_vector(allocator, - &module->export_bindings.entries); - wabt_destroy_binding_hash_entry_vector(allocator, - &module->func_type_bindings.entries); - wabt_destroy_binding_hash_entry_vector(allocator, - &module->table_bindings.entries); - wabt_destroy_binding_hash_entry_vector(allocator, - &module->memory_bindings.entries); -} - -void wabt_destroy_raw_module(WabtAllocator* allocator, WabtRawModule* raw) { + wabt_destroy_func_ptr_vector(&module->funcs); + wabt_destroy_global_ptr_vector(&module->globals); + wabt_destroy_import_ptr_vector(&module->imports); + wabt_destroy_export_ptr_vector(&module->exports); + wabt_destroy_func_type_ptr_vector(&module->func_types); + wabt_destroy_table_ptr_vector(&module->tables); + wabt_destroy_elem_segment_ptr_vector(&module->elem_segments); + wabt_destroy_memory_ptr_vector(&module->memories); + wabt_destroy_data_segment_ptr_vector(&module->data_segments); + wabt_destroy_binding_hash_entry_vector(&module->func_bindings.entries); + wabt_destroy_binding_hash_entry_vector(&module->global_bindings.entries); + wabt_destroy_binding_hash_entry_vector(&module->export_bindings.entries); + wabt_destroy_binding_hash_entry_vector(&module->func_type_bindings.entries); + wabt_destroy_binding_hash_entry_vector(&module->table_bindings.entries); + wabt_destroy_binding_hash_entry_vector(&module->memory_bindings.entries); +} + +void wabt_destroy_raw_module(WabtRawModule* raw) { if (raw->type == WABT_RAW_MODULE_TYPE_TEXT) { - wabt_destroy_module(allocator, raw->text); - wabt_free(allocator, raw->text); + wabt_destroy_module(raw->text); + wabt_free(raw->text); } else { - wabt_destroy_string_slice(allocator, &raw->binary.name); - wabt_free(allocator, raw->binary.data); + wabt_destroy_string_slice(&raw->binary.name); + wabt_free(raw->binary.data); } } -void wabt_destroy_action(WabtAllocator* allocator, WabtAction* action) { - wabt_destroy_var(allocator, &action->module_var); +void wabt_destroy_action(WabtAction* action) { + wabt_destroy_var(&action->module_var); switch (action->type) { case WABT_ACTION_TYPE_INVOKE: - wabt_destroy_string_slice(allocator, &action->invoke.name); - wabt_destroy_const_vector(allocator, &action->invoke.args); + wabt_destroy_string_slice(&action->invoke.name); + wabt_destroy_const_vector(&action->invoke.args); break; case WABT_ACTION_TYPE_GET: - wabt_destroy_string_slice(allocator, &action->get.name); + wabt_destroy_string_slice(&action->get.name); break; } } -void wabt_destroy_command(WabtAllocator* allocator, WabtCommand* command) { +void wabt_destroy_command(WabtCommand* command) { switch (command->type) { case WABT_COMMAND_TYPE_MODULE: - wabt_destroy_module(allocator, &command->module); + wabt_destroy_module(&command->module); break; case WABT_COMMAND_TYPE_ACTION: - wabt_destroy_action(allocator, &command->action); + wabt_destroy_action(&command->action); break; case WABT_COMMAND_TYPE_REGISTER: - wabt_destroy_string_slice(allocator, &command->register_.module_name); - wabt_destroy_var(allocator, &command->register_.var); + wabt_destroy_string_slice(&command->register_.module_name); + wabt_destroy_var(&command->register_.var); break; case WABT_COMMAND_TYPE_ASSERT_MALFORMED: - wabt_destroy_raw_module(allocator, &command->assert_malformed.module); - wabt_destroy_string_slice(allocator, &command->assert_malformed.text); + wabt_destroy_raw_module(&command->assert_malformed.module); + wabt_destroy_string_slice(&command->assert_malformed.text); break; case WABT_COMMAND_TYPE_ASSERT_INVALID: case WABT_COMMAND_TYPE_ASSERT_INVALID_NON_BINARY: - wabt_destroy_raw_module(allocator, &command->assert_invalid.module); - wabt_destroy_string_slice(allocator, &command->assert_invalid.text); + wabt_destroy_raw_module(&command->assert_invalid.module); + wabt_destroy_string_slice(&command->assert_invalid.text); break; case WABT_COMMAND_TYPE_ASSERT_UNLINKABLE: - wabt_destroy_raw_module(allocator, &command->assert_unlinkable.module); - wabt_destroy_string_slice(allocator, &command->assert_unlinkable.text); + wabt_destroy_raw_module(&command->assert_unlinkable.module); + wabt_destroy_string_slice(&command->assert_unlinkable.text); break; case WABT_COMMAND_TYPE_ASSERT_UNINSTANTIABLE: - wabt_destroy_raw_module(allocator, - &command->assert_uninstantiable.module); - wabt_destroy_string_slice(allocator, - &command->assert_uninstantiable.text); + wabt_destroy_raw_module(&command->assert_uninstantiable.module); + wabt_destroy_string_slice(&command->assert_uninstantiable.text); break; case WABT_COMMAND_TYPE_ASSERT_RETURN: - wabt_destroy_action(allocator, &command->assert_return.action); - wabt_destroy_const_vector(allocator, &command->assert_return.expected); + wabt_destroy_action(&command->assert_return.action); + wabt_destroy_const_vector(&command->assert_return.expected); break; case WABT_COMMAND_TYPE_ASSERT_RETURN_NAN: - wabt_destroy_action(allocator, &command->assert_return_nan.action); + wabt_destroy_action(&command->assert_return_nan.action); break; case WABT_COMMAND_TYPE_ASSERT_TRAP: case WABT_COMMAND_TYPE_ASSERT_EXHAUSTION: - wabt_destroy_action(allocator, &command->assert_trap.action); - wabt_destroy_string_slice(allocator, &command->assert_trap.text); + wabt_destroy_action(&command->assert_trap.action); + wabt_destroy_string_slice(&command->assert_trap.text); break; case WABT_NUM_COMMAND_TYPES: assert(0); @@ -595,22 +552,19 @@ void wabt_destroy_command(WabtAllocator* allocator, WabtCommand* command) { } } -void wabt_destroy_command_vector_and_elements(WabtAllocator* allocator, - WabtCommandVector* commands) { - WABT_DESTROY_VECTOR_AND_ELEMENTS(allocator, *commands, command); +void wabt_destroy_command_vector_and_elements(WabtCommandVector* commands) { + WABT_DESTROY_VECTOR_AND_ELEMENTS(*commands, command); } -void wabt_destroy_elem_segment(WabtAllocator* allocator, - WabtElemSegment* elem) { - wabt_destroy_var(allocator, &elem->table_var); - wabt_destroy_expr_list(allocator, elem->offset); - WABT_DESTROY_VECTOR_AND_ELEMENTS(allocator, elem->vars, var); +void wabt_destroy_elem_segment(WabtElemSegment* elem) { + wabt_destroy_var(&elem->table_var); + wabt_destroy_expr_list(elem->offset); + WABT_DESTROY_VECTOR_AND_ELEMENTS(elem->vars, var); } void wabt_destroy_script(WabtScript* script) { - WABT_DESTROY_VECTOR_AND_ELEMENTS(script->allocator, script->commands, - command); - wabt_destroy_binding_hash(script->allocator, &script->module_bindings); + WABT_DESTROY_VECTOR_AND_ELEMENTS(script->commands, command); + wabt_destroy_binding_hash(&script->module_bindings); } #define CHECK_RESULT(expr) \ @@ -361,7 +361,6 @@ typedef struct WabtCommand { WABT_DEFINE_VECTOR(command, WabtCommand); typedef struct WabtScript { - struct WabtAllocator* allocator; WabtCommandVector commands; WabtBindingHash module_bindings; } WabtScript; @@ -402,67 +401,64 @@ typedef struct WabtExprVisitor { } WabtExprVisitor; WABT_EXTERN_C_BEGIN -WabtModuleField* wabt_append_module_field(struct WabtAllocator*, WabtModule*); +WabtModuleField* wabt_append_module_field(WabtModule*); /* ownership of the function signature is passed to the module */ -WabtFuncType* wabt_append_implicit_func_type(struct WabtAllocator*, - WabtLocation*, +WabtFuncType* wabt_append_implicit_func_type(WabtLocation*, WabtModule*, WabtFuncSignature*); /* WabtExpr creation functions */ -WabtExpr* wabt_new_binary_expr(struct WabtAllocator*); -WabtExpr* wabt_new_block_expr(struct WabtAllocator*); -WabtExpr* wabt_new_br_expr(struct WabtAllocator*); -WabtExpr* wabt_new_br_if_expr(struct WabtAllocator*); -WabtExpr* wabt_new_br_table_expr(struct WabtAllocator*); -WabtExpr* wabt_new_call_expr(struct WabtAllocator*); -WabtExpr* wabt_new_call_indirect_expr(struct WabtAllocator*); -WabtExpr* wabt_new_compare_expr(struct WabtAllocator*); -WabtExpr* wabt_new_const_expr(struct WabtAllocator*); -WabtExpr* wabt_new_convert_expr(struct WabtAllocator*); -WabtExpr* wabt_new_current_memory_expr(struct WabtAllocator*); -WabtExpr* wabt_new_drop_expr(struct WabtAllocator*); -WabtExpr* wabt_new_get_global_expr(struct WabtAllocator*); -WabtExpr* wabt_new_get_local_expr(struct WabtAllocator*); -WabtExpr* wabt_new_grow_memory_expr(struct WabtAllocator*); -WabtExpr* wabt_new_if_expr(struct WabtAllocator*); -WabtExpr* wabt_new_load_expr(struct WabtAllocator*); -WabtExpr* wabt_new_loop_expr(struct WabtAllocator*); -WabtExpr* wabt_new_nop_expr(struct WabtAllocator*); -WabtExpr* wabt_new_return_expr(struct WabtAllocator*); -WabtExpr* wabt_new_select_expr(struct WabtAllocator*); -WabtExpr* wabt_new_set_global_expr(struct WabtAllocator*); -WabtExpr* wabt_new_set_local_expr(struct WabtAllocator*); -WabtExpr* wabt_new_store_expr(struct WabtAllocator*); -WabtExpr* wabt_new_tee_local_expr(struct WabtAllocator*); -WabtExpr* wabt_new_unary_expr(struct WabtAllocator*); -WabtExpr* wabt_new_unreachable_expr(struct WabtAllocator*); +WabtExpr* wabt_new_binary_expr(void); +WabtExpr* wabt_new_block_expr(void); +WabtExpr* wabt_new_br_expr(void); +WabtExpr* wabt_new_br_if_expr(void); +WabtExpr* wabt_new_br_table_expr(void); +WabtExpr* wabt_new_call_expr(void); +WabtExpr* wabt_new_call_indirect_expr(void); +WabtExpr* wabt_new_compare_expr(void); +WabtExpr* wabt_new_const_expr(void); +WabtExpr* wabt_new_convert_expr(void); +WabtExpr* wabt_new_current_memory_expr(void); +WabtExpr* wabt_new_drop_expr(void); +WabtExpr* wabt_new_get_global_expr(void); +WabtExpr* wabt_new_get_local_expr(void); +WabtExpr* wabt_new_grow_memory_expr(void); +WabtExpr* wabt_new_if_expr(void); +WabtExpr* wabt_new_load_expr(void); +WabtExpr* wabt_new_loop_expr(void); +WabtExpr* wabt_new_nop_expr(void); +WabtExpr* wabt_new_return_expr(void); +WabtExpr* wabt_new_select_expr(void); +WabtExpr* wabt_new_set_global_expr(void); +WabtExpr* wabt_new_set_local_expr(void); +WabtExpr* wabt_new_store_expr(void); +WabtExpr* wabt_new_tee_local_expr(void); +WabtExpr* wabt_new_unary_expr(void); +WabtExpr* wabt_new_unreachable_expr(void); /* destruction functions. not needed unless you're creating your own AST elements */ void wabt_destroy_script(struct WabtScript*); -void wabt_destroy_action(struct WabtAllocator*, struct WabtAction*); -void wabt_destroy_block(struct WabtAllocator*, struct WabtBlock*); -void wabt_destroy_command_vector_and_elements(struct WabtAllocator*, - WabtCommandVector*); -void wabt_destroy_command(struct WabtAllocator*, WabtCommand*); -void wabt_destroy_data_segment(struct WabtAllocator*, WabtDataSegment*); -void wabt_destroy_elem_segment(struct WabtAllocator*, WabtElemSegment*); -void wabt_destroy_export(struct WabtAllocator*, WabtExport*); -void wabt_destroy_expr(struct WabtAllocator*, WabtExpr*); -void wabt_destroy_expr_list(struct WabtAllocator*, WabtExpr*); -void wabt_destroy_func_declaration(struct WabtAllocator*, WabtFuncDeclaration*); -void wabt_destroy_func_signature(struct WabtAllocator*, WabtFuncSignature*); -void wabt_destroy_func_type(struct WabtAllocator*, WabtFuncType*); -void wabt_destroy_func(struct WabtAllocator*, WabtFunc*); -void wabt_destroy_import(struct WabtAllocator*, WabtImport*); -void wabt_destroy_memory(struct WabtAllocator*, WabtMemory*); -void wabt_destroy_module(struct WabtAllocator*, WabtModule*); -void wabt_destroy_raw_module(struct WabtAllocator*, WabtRawModule*); -void wabt_destroy_table(struct WabtAllocator*, WabtTable*); -void wabt_destroy_var_vector_and_elements(struct WabtAllocator*, - WabtVarVector*); -void wabt_destroy_var(struct WabtAllocator*, WabtVar*); +void wabt_destroy_action(struct WabtAction*); +void wabt_destroy_block(struct WabtBlock*); +void wabt_destroy_command_vector_and_elements(WabtCommandVector*); +void wabt_destroy_command(WabtCommand*); +void wabt_destroy_data_segment(WabtDataSegment*); +void wabt_destroy_elem_segment(WabtElemSegment*); +void wabt_destroy_export(WabtExport*); +void wabt_destroy_expr(WabtExpr*); +void wabt_destroy_expr_list(WabtExpr*); +void wabt_destroy_func_declaration(WabtFuncDeclaration*); +void wabt_destroy_func_signature(WabtFuncSignature*); +void wabt_destroy_func_type(WabtFuncType*); +void wabt_destroy_func(WabtFunc*); +void wabt_destroy_import(WabtImport*); +void wabt_destroy_memory(WabtMemory*); +void wabt_destroy_module(WabtModule*); +void wabt_destroy_raw_module(WabtRawModule*); +void wabt_destroy_table(WabtTable*); +void wabt_destroy_var_vector_and_elements(WabtVarVector*); +void wabt_destroy_var(WabtVar*); /* traversal functions */ WabtResult wabt_visit_func(WabtFunc* func, WabtExprVisitor*); @@ -503,7 +499,6 @@ WabtModule* wabt_get_module_by_var(const WabtScript* script, const WabtVar* var); void wabt_make_type_binding_reverse_mapping( - struct WabtAllocator*, const WabtTypeVector*, const WabtBindingHash*, WabtStringSliceVector* out_reverse_mapping); diff --git a/src/binary-reader-ast.c b/src/binary-reader-ast.c index b010c76f..d03d8a7b 100644 --- a/src/binary-reader-ast.c +++ b/src/binary-reader-ast.c @@ -22,7 +22,6 @@ #include <stdint.h> #include <stdio.h> -#include "allocator.h" #include "ast.h" #include "binary-reader.h" #include "common.h" @@ -41,7 +40,6 @@ typedef struct LabelNode { WABT_DEFINE_VECTOR(label_node, LabelNode); typedef struct Context { - WabtAllocator* allocator; WabtBinaryErrorHandler* error_handler; WabtModule* module; @@ -67,7 +65,7 @@ static void push_label(Context* ctx, label.first = first; label.last = NULL; ctx->max_depth++; - wabt_append_label_node_value(ctx->allocator, &ctx->label_stack, &label); + wabt_append_label_node_value(&ctx->label_stack, &label); } static WabtResult pop_label(Context* ctx) { @@ -102,7 +100,7 @@ static void dup_name(Context* ctx, WabtStringSlice* name, WabtStringSlice* out_name) { if (name->length > 0) { - *out_name = wabt_dup_string_slice(ctx->allocator, *name); + *out_name = wabt_dup_string_slice(*name); } else { WABT_ZERO_MEMORY(*out_name); } @@ -111,7 +109,7 @@ static void dup_name(Context* ctx, static WabtResult append_expr(Context* ctx, WabtExpr* expr) { LabelNode* label; if (WABT_FAILED(top_label(ctx, &label))) { - wabt_free(ctx->allocator, expr); + wabt_free(expr); return WABT_ERROR; } if (*label->first) { @@ -138,7 +136,7 @@ static void on_error(WabtBinaryReaderContext* reader_context, static WabtResult on_signature_count(uint32_t count, void* user_data) { Context* ctx = user_data; - wabt_reserve_func_type_ptrs(ctx->allocator, &ctx->module->func_types, count); + wabt_reserve_func_type_ptrs(&ctx->module->func_types, count); return WABT_OK; } @@ -149,34 +147,32 @@ static WabtResult on_signature(uint32_t index, WabtType* result_types, void* user_data) { Context* ctx = user_data; - WabtModuleField* field = - wabt_append_module_field(ctx->allocator, ctx->module); + WabtModuleField* field = wabt_append_module_field(ctx->module); field->type = WABT_MODULE_FIELD_TYPE_FUNC_TYPE; WabtFuncType* func_type = &field->func_type; WABT_ZERO_MEMORY(*func_type); - wabt_reserve_types(ctx->allocator, &func_type->sig.param_types, param_count); + wabt_reserve_types(&func_type->sig.param_types, param_count); func_type->sig.param_types.size = param_count; memcpy(func_type->sig.param_types.data, param_types, param_count * sizeof(WabtType)); - wabt_reserve_types(ctx->allocator, &func_type->sig.result_types, - result_count); + wabt_reserve_types(&func_type->sig.result_types, result_count); func_type->sig.result_types.size = result_count; memcpy(func_type->sig.result_types.data, result_types, result_count * sizeof(WabtType)); assert(index < ctx->module->func_types.capacity); WabtFuncTypePtr* func_type_ptr = - wabt_append_func_type_ptr(ctx->allocator, &ctx->module->func_types); + wabt_append_func_type_ptr(&ctx->module->func_types); *func_type_ptr = func_type; return WABT_OK; } static WabtResult on_import_count(uint32_t count, void* user_data) { Context* ctx = user_data; - wabt_reserve_import_ptrs(ctx->allocator, &ctx->module->imports, count); + wabt_reserve_import_ptrs(&ctx->module->imports, count); return WABT_OK; } @@ -187,17 +183,15 @@ static WabtResult on_import(uint32_t index, Context* ctx = user_data; assert(index < ctx->module->imports.capacity); - WabtModuleField* field = - wabt_append_module_field(ctx->allocator, ctx->module); + WabtModuleField* field = wabt_append_module_field(ctx->module); field->type = WABT_MODULE_FIELD_TYPE_IMPORT; WabtImport* import = &field->import; WABT_ZERO_MEMORY(*import); - import->module_name = wabt_dup_string_slice(ctx->allocator, module_name); - import->field_name = wabt_dup_string_slice(ctx->allocator, field_name); + import->module_name = wabt_dup_string_slice(module_name); + import->field_name = wabt_dup_string_slice(field_name); - WabtImportPtr* import_ptr = - wabt_append_import_ptr(ctx->allocator, &ctx->module->imports); + WabtImportPtr* import_ptr = wabt_append_import_ptr(&ctx->module->imports); *import_ptr = import; return WABT_OK; } @@ -219,7 +213,7 @@ static WabtResult on_import_func(uint32_t import_index, import->func.decl.sig = ctx->module->func_types.data[sig_index]->sig; WabtFuncPtr func_ptr = &import->func; - wabt_append_func_ptr_value(ctx->allocator, &ctx->module->funcs, &func_ptr); + wabt_append_func_ptr_value(&ctx->module->funcs, &func_ptr); ctx->module->num_func_imports++; return WABT_OK; } @@ -236,7 +230,7 @@ static WabtResult on_import_table(uint32_t import_index, import->table.elem_limits = *elem_limits; WabtTablePtr table_ptr = &import->table; - wabt_append_table_ptr_value(ctx->allocator, &ctx->module->tables, &table_ptr); + wabt_append_table_ptr_value(&ctx->module->tables, &table_ptr); ctx->module->num_table_imports++; return WABT_OK; } @@ -252,8 +246,7 @@ static WabtResult on_import_memory(uint32_t import_index, import->memory.page_limits = *page_limits; WabtMemoryPtr memory_ptr = &import->memory; - wabt_append_memory_ptr_value(ctx->allocator, &ctx->module->memories, - &memory_ptr); + wabt_append_memory_ptr_value(&ctx->module->memories, &memory_ptr); ctx->module->num_memory_imports++; return WABT_OK; } @@ -271,8 +264,7 @@ static WabtResult on_import_global(uint32_t import_index, import->global.mutable_ = mutable_; WabtGlobalPtr global_ptr = &import->global; - wabt_append_global_ptr_value(ctx->allocator, &ctx->module->globals, - &global_ptr); + wabt_append_global_ptr_value(&ctx->module->globals, &global_ptr); ctx->module->num_global_imports++; return WABT_OK; } @@ -280,8 +272,7 @@ static WabtResult on_import_global(uint32_t import_index, static WabtResult on_function_signatures_count(uint32_t count, void* user_data) { Context* ctx = user_data; - wabt_reserve_func_ptrs(ctx->allocator, - &ctx->module->funcs, + wabt_reserve_func_ptrs(&ctx->module->funcs, ctx->module->num_func_imports + count); return WABT_OK; } @@ -293,8 +284,7 @@ static WabtResult on_function_signature(uint32_t index, assert(index < ctx->module->funcs.capacity); assert(sig_index < ctx->module->func_types.size); - WabtModuleField* field = - wabt_append_module_field(ctx->allocator, ctx->module); + WabtModuleField* field = wabt_append_module_field(ctx->module); field->type = WABT_MODULE_FIELD_TYPE_FUNC; WabtFunc* func = &field->func; @@ -305,15 +295,14 @@ static WabtResult on_function_signature(uint32_t index, func->decl.type_var.index = sig_index; func->decl.sig = ctx->module->func_types.data[sig_index]->sig; - WabtFuncPtr* func_ptr = - wabt_append_func_ptr(ctx->allocator, &ctx->module->funcs); + WabtFuncPtr* func_ptr = wabt_append_func_ptr(&ctx->module->funcs); *func_ptr = func; return WABT_OK; } static WabtResult on_table_count(uint32_t count, void* user_data) { Context* ctx = user_data; - wabt_reserve_table_ptrs(ctx->allocator, &ctx->module->tables, + wabt_reserve_table_ptrs(&ctx->module->tables, ctx->module->num_table_imports + count); return WABT_OK; } @@ -325,23 +314,21 @@ static WabtResult on_table(uint32_t index, Context* ctx = user_data; assert(index < ctx->module->tables.capacity); - WabtModuleField* field = - wabt_append_module_field(ctx->allocator, ctx->module); + WabtModuleField* field = wabt_append_module_field(ctx->module); field->type = WABT_MODULE_FIELD_TYPE_TABLE; WabtTable* table = &field->table; WABT_ZERO_MEMORY(*table); table->elem_limits = *elem_limits; - WabtTablePtr* table_ptr = - wabt_append_table_ptr(ctx->allocator, &ctx->module->tables); + WabtTablePtr* table_ptr = wabt_append_table_ptr(&ctx->module->tables); *table_ptr = table; return WABT_OK; } static WabtResult on_memory_count(uint32_t count, void* user_data) { Context* ctx = user_data; - wabt_reserve_memory_ptrs(ctx->allocator, &ctx->module->memories, + wabt_reserve_memory_ptrs(&ctx->module->memories, ctx->module->num_memory_imports + count); return WABT_OK; } @@ -352,23 +339,21 @@ static WabtResult on_memory(uint32_t index, Context* ctx = user_data; assert(index < ctx->module->memories.capacity); - WabtModuleField* field = - wabt_append_module_field(ctx->allocator, ctx->module); + WabtModuleField* field = wabt_append_module_field(ctx->module); field->type = WABT_MODULE_FIELD_TYPE_MEMORY; WabtMemory* memory = &field->memory; WABT_ZERO_MEMORY(*memory); memory->page_limits = *page_limits; - WabtMemoryPtr* memory_ptr = - wabt_append_memory_ptr(ctx->allocator, &ctx->module->memories); + WabtMemoryPtr* memory_ptr = wabt_append_memory_ptr(&ctx->module->memories); *memory_ptr = memory; return WABT_OK; } static WabtResult on_global_count(uint32_t count, void* user_data) { Context* ctx = user_data; - wabt_reserve_global_ptrs(ctx->allocator, &ctx->module->globals, + wabt_reserve_global_ptrs(&ctx->module->globals, ctx->module->num_global_imports + count); return WABT_OK; } @@ -380,8 +365,7 @@ static WabtResult begin_global(uint32_t index, Context* ctx = user_data; assert(index < ctx->module->globals.capacity); - WabtModuleField* field = - wabt_append_module_field(ctx->allocator, ctx->module); + WabtModuleField* field = wabt_append_module_field(ctx->module); field->type = WABT_MODULE_FIELD_TYPE_GLOBAL; WabtGlobal* global = &field->global; @@ -389,8 +373,7 @@ static WabtResult begin_global(uint32_t index, global->type = type; global->mutable_ = mutable_; - WabtGlobalPtr* global_ptr = - wabt_append_global_ptr(ctx->allocator, &ctx->module->globals); + WabtGlobalPtr* global_ptr = wabt_append_global_ptr(&ctx->module->globals); *global_ptr = global; return WABT_OK; } @@ -411,7 +394,7 @@ static WabtResult end_global_init_expr(uint32_t index, void* user_data) { static WabtResult on_export_count(uint32_t count, void* user_data) { Context* ctx = user_data; - wabt_reserve_export_ptrs(ctx->allocator, &ctx->module->exports, count); + wabt_reserve_export_ptrs(&ctx->module->exports, count); return WABT_OK; } @@ -421,13 +404,12 @@ static WabtResult on_export(uint32_t index, WabtStringSlice name, void* user_data) { Context* ctx = user_data; - WabtModuleField* field = - wabt_append_module_field(ctx->allocator, ctx->module); + WabtModuleField* field = wabt_append_module_field(ctx->module); field->type = WABT_MODULE_FIELD_TYPE_EXPORT; WabtExport* export = &field->export_; WABT_ZERO_MEMORY(*export); - export->name = wabt_dup_string_slice(ctx->allocator, name); + export->name = wabt_dup_string_slice(name); switch (kind) { case WABT_EXTERNAL_KIND_FUNC: assert(item_index < ctx->module->funcs.size); @@ -450,16 +432,14 @@ static WabtResult on_export(uint32_t index, export->kind = kind; assert(index < ctx->module->exports.capacity); - WabtExportPtr* export_ptr = - wabt_append_export_ptr(ctx->allocator, &ctx->module->exports); + WabtExportPtr* export_ptr = wabt_append_export_ptr(&ctx->module->exports); *export_ptr = export; return WABT_OK; } static WabtResult on_start_function(uint32_t func_index, void* user_data) { Context* ctx = user_data; - WabtModuleField* field = - wabt_append_module_field(ctx->allocator, ctx->module); + WabtModuleField* field = wabt_append_module_field(ctx->module); field->type = WABT_MODULE_FIELD_TYPE_START; field->start.type = WABT_VAR_TYPE_INDEX; @@ -493,8 +473,7 @@ static WabtResult on_local_decl(uint32_t decl_index, Context* ctx = user_data; size_t old_local_count = ctx->current_func->local_types.size; size_t new_local_count = old_local_count + count; - wabt_reserve_types(ctx->allocator, &ctx->current_func->local_types, - new_local_count); + wabt_reserve_types(&ctx->current_func->local_types, new_local_count); WabtTypeVector* types = &ctx->current_func->local_types; size_t i; for (i = 0; i < count; ++i) @@ -505,7 +484,7 @@ static WabtResult on_local_decl(uint32_t decl_index, static WabtResult on_binary_expr(WabtOpcode opcode, void* user_data) { Context* ctx = user_data; - WabtExpr* expr = wabt_new_binary_expr(ctx->allocator); + WabtExpr* expr = wabt_new_binary_expr(); expr->binary.opcode = opcode; return append_expr(ctx, expr); } @@ -514,12 +493,12 @@ static WabtResult on_block_expr(uint32_t num_types, WabtType* sig_types, void* user_data) { Context* ctx = user_data; - WabtExpr* expr = wabt_new_block_expr(ctx->allocator); + WabtExpr* expr = wabt_new_block_expr(); WabtTypeVector src; WABT_ZERO_MEMORY(src); src.size = num_types; src.data = sig_types; - wabt_extend_types(ctx->allocator, &expr->block.sig, &src); + wabt_extend_types(&expr->block.sig, &src); append_expr(ctx, expr); push_label(ctx, WABT_LABEL_TYPE_BLOCK, &expr->block.first); return WABT_OK; @@ -527,7 +506,7 @@ static WabtResult on_block_expr(uint32_t num_types, static WabtResult on_br_expr(uint32_t depth, void* user_data) { Context* ctx = user_data; - WabtExpr* expr = wabt_new_br_expr(ctx->allocator); + WabtExpr* expr = wabt_new_br_expr(); expr->br.var.type = WABT_VAR_TYPE_INDEX; expr->br.var.index = depth; return append_expr(ctx, expr); @@ -535,7 +514,7 @@ static WabtResult on_br_expr(uint32_t depth, void* user_data) { static WabtResult on_br_if_expr(uint32_t depth, void* user_data) { Context* ctx = user_data; - WabtExpr* expr = wabt_new_br_if_expr(ctx->allocator); + WabtExpr* expr = wabt_new_br_if_expr(); expr->br_if.var.type = WABT_VAR_TYPE_INDEX; expr->br_if.var.index = depth; return append_expr(ctx, expr); @@ -546,8 +525,8 @@ static WabtResult on_br_table_expr(WabtBinaryReaderContext* context, uint32_t* target_depths, uint32_t default_target_depth) { Context* ctx = context->user_data; - WabtExpr* expr = wabt_new_br_table_expr(ctx->allocator); - wabt_reserve_vars(ctx->allocator, &expr->br_table.targets, num_targets); + WabtExpr* expr = wabt_new_br_table_expr(); + wabt_reserve_vars(&expr->br_table.targets, num_targets); expr->br_table.targets.size = num_targets; uint32_t i; for (i = 0; i < num_targets; ++i) { @@ -563,7 +542,7 @@ static WabtResult on_br_table_expr(WabtBinaryReaderContext* context, static WabtResult on_call_expr(uint32_t func_index, void* user_data) { Context* ctx = user_data; assert(func_index < ctx->module->funcs.size); - WabtExpr* expr = wabt_new_call_expr(ctx->allocator); + WabtExpr* expr = wabt_new_call_expr(); expr->call.var.type = WABT_VAR_TYPE_INDEX; expr->call.var.index = func_index; return append_expr(ctx, expr); @@ -572,7 +551,7 @@ static WabtResult on_call_expr(uint32_t func_index, void* user_data) { static WabtResult on_call_indirect_expr(uint32_t sig_index, void* user_data) { Context* ctx = user_data; assert(sig_index < ctx->module->func_types.size); - WabtExpr* expr = wabt_new_call_indirect_expr(ctx->allocator); + WabtExpr* expr = wabt_new_call_indirect_expr(); expr->call_indirect.var.type = WABT_VAR_TYPE_INDEX; expr->call_indirect.var.index = sig_index; return append_expr(ctx, expr); @@ -580,27 +559,27 @@ static WabtResult on_call_indirect_expr(uint32_t sig_index, void* user_data) { static WabtResult on_compare_expr(WabtOpcode opcode, void* user_data) { Context* ctx = user_data; - WabtExpr* expr = wabt_new_compare_expr(ctx->allocator); + WabtExpr* expr = wabt_new_compare_expr(); expr->compare.opcode = opcode; return append_expr(ctx, expr); } static WabtResult on_convert_expr(WabtOpcode opcode, void* user_data) { Context* ctx = user_data; - WabtExpr* expr = wabt_new_convert_expr(ctx->allocator); + WabtExpr* expr = wabt_new_convert_expr(); expr->convert.opcode = opcode; return append_expr(ctx, expr); } static WabtResult on_current_memory_expr(void* user_data) { Context* ctx = user_data; - WabtExpr* expr = wabt_new_current_memory_expr(ctx->allocator); + WabtExpr* expr = wabt_new_current_memory_expr(); return append_expr(ctx, expr); } static WabtResult on_drop_expr(void* user_data) { Context* ctx = user_data; - WabtExpr* expr = wabt_new_drop_expr(ctx->allocator); + WabtExpr* expr = wabt_new_drop_expr(); return append_expr(ctx, expr); } @@ -630,7 +609,7 @@ static WabtResult on_end_expr(void* user_data) { static WabtResult on_f32_const_expr(uint32_t value_bits, void* user_data) { Context* ctx = user_data; - WabtExpr* expr = wabt_new_const_expr(ctx->allocator); + WabtExpr* expr = wabt_new_const_expr(); expr->const_.type = WABT_TYPE_F32; expr->const_.f32_bits = value_bits; return append_expr(ctx, expr); @@ -638,7 +617,7 @@ static WabtResult on_f32_const_expr(uint32_t value_bits, void* user_data) { static WabtResult on_f64_const_expr(uint64_t value_bits, void* user_data) { Context* ctx = user_data; - WabtExpr* expr = wabt_new_const_expr(ctx->allocator); + WabtExpr* expr = wabt_new_const_expr(); expr->const_.type = WABT_TYPE_F64; expr->const_.f64_bits = value_bits; return append_expr(ctx, expr); @@ -646,7 +625,7 @@ static WabtResult on_f64_const_expr(uint64_t value_bits, void* user_data) { static WabtResult on_get_global_expr(uint32_t global_index, void* user_data) { Context* ctx = user_data; - WabtExpr* expr = wabt_new_get_global_expr(ctx->allocator); + WabtExpr* expr = wabt_new_get_global_expr(); expr->get_global.var.type = WABT_VAR_TYPE_INDEX; expr->get_global.var.index = global_index; return append_expr(ctx, expr); @@ -654,7 +633,7 @@ static WabtResult on_get_global_expr(uint32_t global_index, void* user_data) { static WabtResult on_get_local_expr(uint32_t local_index, void* user_data) { Context* ctx = user_data; - WabtExpr* expr = wabt_new_get_local_expr(ctx->allocator); + WabtExpr* expr = wabt_new_get_local_expr(); expr->get_local.var.type = WABT_VAR_TYPE_INDEX; expr->get_local.var.index = local_index; return append_expr(ctx, expr); @@ -662,13 +641,13 @@ static WabtResult on_get_local_expr(uint32_t local_index, void* user_data) { static WabtResult on_grow_memory_expr(void* user_data) { Context* ctx = user_data; - WabtExpr* expr = wabt_new_grow_memory_expr(ctx->allocator); + WabtExpr* expr = wabt_new_grow_memory_expr(); return append_expr(ctx, expr); } static WabtResult on_i32_const_expr(uint32_t value, void* user_data) { Context* ctx = user_data; - WabtExpr* expr = wabt_new_const_expr(ctx->allocator); + WabtExpr* expr = wabt_new_const_expr(); expr->const_.type = WABT_TYPE_I32; expr->const_.u32 = value; return append_expr(ctx, expr); @@ -676,7 +655,7 @@ static WabtResult on_i32_const_expr(uint32_t value, void* user_data) { static WabtResult on_i64_const_expr(uint64_t value, void* user_data) { Context* ctx = user_data; - WabtExpr* expr = wabt_new_const_expr(ctx->allocator); + WabtExpr* expr = wabt_new_const_expr(); expr->const_.type = WABT_TYPE_I64; expr->const_.u64 = value; return append_expr(ctx, expr); @@ -686,12 +665,12 @@ static WabtResult on_if_expr(uint32_t num_types, WabtType* sig_types, void* user_data) { Context* ctx = user_data; - WabtExpr* expr = wabt_new_if_expr(ctx->allocator); + WabtExpr* expr = wabt_new_if_expr(); WabtTypeVector src; WABT_ZERO_MEMORY(src); src.size = num_types; src.data = sig_types; - wabt_extend_types(ctx->allocator, &expr->if_.true_.sig, &src); + wabt_extend_types(&expr->if_.true_.sig, &src); append_expr(ctx, expr); push_label(ctx, WABT_LABEL_TYPE_IF, &expr->if_.true_.first); return WABT_OK; @@ -702,7 +681,7 @@ static WabtResult on_load_expr(WabtOpcode opcode, uint32_t offset, void* user_data) { Context* ctx = user_data; - WabtExpr* expr = wabt_new_load_expr(ctx->allocator); + WabtExpr* expr = wabt_new_load_expr(); expr->load.opcode = opcode; expr->load.align = 1 << alignment_log2; expr->load.offset = offset; @@ -713,12 +692,12 @@ static WabtResult on_loop_expr(uint32_t num_types, WabtType* sig_types, void* user_data) { Context* ctx = user_data; - WabtExpr* expr = wabt_new_loop_expr(ctx->allocator); + WabtExpr* expr = wabt_new_loop_expr(); WabtTypeVector src; WABT_ZERO_MEMORY(src); src.size = num_types; src.data = sig_types; - wabt_extend_types(ctx->allocator, &expr->loop.sig, &src); + wabt_extend_types(&expr->loop.sig, &src); append_expr(ctx, expr); push_label(ctx, WABT_LABEL_TYPE_LOOP, &expr->loop.first); return WABT_OK; @@ -726,25 +705,25 @@ static WabtResult on_loop_expr(uint32_t num_types, static WabtResult on_nop_expr(void* user_data) { Context* ctx = user_data; - WabtExpr* expr = wabt_new_nop_expr(ctx->allocator); + WabtExpr* expr = wabt_new_nop_expr(); return append_expr(ctx, expr); } static WabtResult on_return_expr(void* user_data) { Context* ctx = user_data; - WabtExpr* expr = wabt_new_return_expr(ctx->allocator); + WabtExpr* expr = wabt_new_return_expr(); return append_expr(ctx, expr); } static WabtResult on_select_expr(void* user_data) { Context* ctx = user_data; - WabtExpr* expr = wabt_new_select_expr(ctx->allocator); + WabtExpr* expr = wabt_new_select_expr(); return append_expr(ctx, expr); } static WabtResult on_set_global_expr(uint32_t global_index, void* user_data) { Context* ctx = user_data; - WabtExpr* expr = wabt_new_set_global_expr(ctx->allocator); + WabtExpr* expr = wabt_new_set_global_expr(); expr->set_global.var.type = WABT_VAR_TYPE_INDEX; expr->set_global.var.index = global_index; return append_expr(ctx, expr); @@ -752,7 +731,7 @@ static WabtResult on_set_global_expr(uint32_t global_index, void* user_data) { static WabtResult on_set_local_expr(uint32_t local_index, void* user_data) { Context* ctx = user_data; - WabtExpr* expr = wabt_new_set_local_expr(ctx->allocator); + WabtExpr* expr = wabt_new_set_local_expr(); expr->set_local.var.type = WABT_VAR_TYPE_INDEX; expr->set_local.var.index = local_index; return append_expr(ctx, expr); @@ -763,7 +742,7 @@ static WabtResult on_store_expr(WabtOpcode opcode, uint32_t offset, void* user_data) { Context* ctx = user_data; - WabtExpr* expr = wabt_new_store_expr(ctx->allocator); + WabtExpr* expr = wabt_new_store_expr(); expr->store.opcode = opcode; expr->store.align = 1 << alignment_log2; expr->store.offset = offset; @@ -772,7 +751,7 @@ static WabtResult on_store_expr(WabtOpcode opcode, static WabtResult on_tee_local_expr(uint32_t local_index, void* user_data) { Context* ctx = user_data; - WabtExpr* expr = wabt_new_tee_local_expr(ctx->allocator); + WabtExpr* expr = wabt_new_tee_local_expr(); expr->tee_local.var.type = WABT_VAR_TYPE_INDEX; expr->tee_local.var.index = local_index; return append_expr(ctx, expr); @@ -780,14 +759,14 @@ static WabtResult on_tee_local_expr(uint32_t local_index, void* user_data) { static WabtResult on_unary_expr(WabtOpcode opcode, void* user_data) { Context* ctx = user_data; - WabtExpr* expr = wabt_new_unary_expr(ctx->allocator); + WabtExpr* expr = wabt_new_unary_expr(); expr->unary.opcode = opcode; return append_expr(ctx, expr); } static WabtResult on_unreachable_expr(void* user_data) { Context* ctx = user_data; - WabtExpr* expr = wabt_new_unreachable_expr(ctx->allocator); + WabtExpr* expr = wabt_new_unreachable_expr(); return append_expr(ctx, expr); } @@ -800,7 +779,7 @@ static WabtResult end_function_body(uint32_t index, void* user_data) { static WabtResult on_elem_segment_count(uint32_t count, void* user_data) { Context* ctx = user_data; - wabt_reserve_elem_segment_ptrs(ctx->allocator, &ctx->module->elem_segments, + wabt_reserve_elem_segment_ptrs(&ctx->module->elem_segments, count); return WABT_OK; } @@ -809,8 +788,7 @@ static WabtResult begin_elem_segment(uint32_t index, uint32_t table_index, void* user_data) { Context* ctx = user_data; - WabtModuleField* field = - wabt_append_module_field(ctx->allocator, ctx->module); + WabtModuleField* field = wabt_append_module_field(ctx->module); field->type = WABT_MODULE_FIELD_TYPE_ELEM_SEGMENT; WabtElemSegment* segment = &field->elem_segment; @@ -821,7 +799,7 @@ static WabtResult begin_elem_segment(uint32_t index, assert(index == ctx->module->elem_segments.size); assert(index < ctx->module->elem_segments.capacity); WabtElemSegmentPtr* segment_ptr = - wabt_append_elem_segment_ptr(ctx->allocator, &ctx->module->elem_segments); + wabt_append_elem_segment_ptr(&ctx->module->elem_segments); *segment_ptr = segment; return WABT_OK; } @@ -848,7 +826,7 @@ static WabtResult on_elem_segment_function_index_count( Context* ctx = context->user_data; assert(index == ctx->module->elem_segments.size - 1); WabtElemSegment* segment = ctx->module->elem_segments.data[index]; - wabt_reserve_vars(ctx->allocator, &segment->vars, count); + wabt_reserve_vars(&segment->vars, count); return WABT_OK; } @@ -858,7 +836,7 @@ static WabtResult on_elem_segment_function_index(uint32_t index, Context* ctx = user_data; assert(index == ctx->module->elem_segments.size - 1); WabtElemSegment* segment = ctx->module->elem_segments.data[index]; - WabtVar* var = wabt_append_var(ctx->allocator, &segment->vars); + WabtVar* var = wabt_append_var(&segment->vars); var->type = WABT_VAR_TYPE_INDEX; var->index = func_index; return WABT_OK; @@ -866,8 +844,7 @@ static WabtResult on_elem_segment_function_index(uint32_t index, static WabtResult on_data_segment_count(uint32_t count, void* user_data) { Context* ctx = user_data; - wabt_reserve_data_segment_ptrs(ctx->allocator, &ctx->module->data_segments, - count); + wabt_reserve_data_segment_ptrs(&ctx->module->data_segments, count); return WABT_OK; } @@ -875,8 +852,7 @@ static WabtResult begin_data_segment(uint32_t index, uint32_t memory_index, void* user_data) { Context* ctx = user_data; - WabtModuleField* field = - wabt_append_module_field(ctx->allocator, ctx->module); + WabtModuleField* field = wabt_append_module_field(ctx->module); field->type = WABT_MODULE_FIELD_TYPE_DATA_SEGMENT; WabtDataSegment* segment = &field->data_segment; @@ -887,7 +863,7 @@ static WabtResult begin_data_segment(uint32_t index, assert(index == ctx->module->data_segments.size); assert(index < ctx->module->data_segments.capacity); WabtDataSegmentPtr* segment_ptr = - wabt_append_data_segment_ptr(ctx->allocator, &ctx->module->data_segments); + wabt_append_data_segment_ptr(&ctx->module->data_segments); *segment_ptr = segment; return WABT_OK; } @@ -914,7 +890,7 @@ static WabtResult on_data_segment_data(uint32_t index, Context* ctx = user_data; assert(index == ctx->module->data_segments.size - 1); WabtDataSegment* segment = ctx->module->data_segments.data[index]; - segment->data = wabt_alloc(ctx->allocator, size, WABT_DEFAULT_ALIGN); + segment->data = wabt_alloc(size); segment->size = size; memcpy(segment->data, data, size); return WABT_OK; @@ -939,8 +915,8 @@ static WabtResult on_function_name(uint32_t index, WabtStringSlice new_name; dup_name(ctx, &name, &new_name); - WabtBinding* binding = wabt_insert_binding( - ctx->allocator, &ctx->module->func_bindings, &new_name); + WabtBinding* binding = + wabt_insert_binding(&ctx->module->func_bindings, &new_name); binding->index = index; WabtFunc* func = ctx->module->funcs.data[index]; @@ -968,7 +944,7 @@ static WabtResult on_init_expr_f32_const_expr(uint32_t index, uint32_t value, void* user_data) { Context* ctx = user_data; - WabtExpr* expr = wabt_new_const_expr(ctx->allocator); + WabtExpr* expr = wabt_new_const_expr(); expr->const_.type = WABT_TYPE_F32; expr->const_.f32_bits = value; *ctx->current_init_expr = expr; @@ -979,7 +955,7 @@ static WabtResult on_init_expr_f64_const_expr(uint32_t index, uint64_t value, void* user_data) { Context* ctx = user_data; - WabtExpr* expr = wabt_new_const_expr(ctx->allocator); + WabtExpr* expr = wabt_new_const_expr(); expr->const_.type = WABT_TYPE_F64; expr->const_.f64_bits = value; *ctx->current_init_expr = expr; @@ -990,7 +966,7 @@ static WabtResult on_init_expr_get_global_expr(uint32_t index, uint32_t global_index, void* user_data) { Context* ctx = user_data; - WabtExpr* expr = wabt_new_get_global_expr(ctx->allocator); + WabtExpr* expr = wabt_new_get_global_expr(); expr->get_global.var.type = WABT_VAR_TYPE_INDEX; expr->get_global.var.index = global_index; *ctx->current_init_expr = expr; @@ -1001,7 +977,7 @@ static WabtResult on_init_expr_i32_const_expr(uint32_t index, uint32_t value, void* user_data) { Context* ctx = user_data; - WabtExpr* expr = wabt_new_const_expr(ctx->allocator); + WabtExpr* expr = wabt_new_const_expr(); expr->const_.type = WABT_TYPE_I32; expr->const_.u32 = value; *ctx->current_init_expr = expr; @@ -1012,7 +988,7 @@ static WabtResult on_init_expr_i64_const_expr(uint32_t index, uint64_t value, void* user_data) { Context* ctx = user_data; - WabtExpr* expr = wabt_new_const_expr(ctx->allocator); + WabtExpr* expr = wabt_new_const_expr(); expr->const_.type = WABT_TYPE_I64; expr->const_.u64 = value; *ctx->current_init_expr = expr; @@ -1041,7 +1017,7 @@ static WabtResult on_local_name(uint32_t func_index, bindings = &func->local_bindings; index = local_index - num_params; } - binding = wabt_insert_binding(ctx->allocator, bindings, &new_name); + binding = wabt_insert_binding(bindings, &new_name); binding->index = index; return WABT_OK; } @@ -1142,20 +1118,18 @@ static WabtBinaryReader s_binary_reader = { .on_init_expr_i64_const_expr = on_init_expr_i64_const_expr, }; -static void wabt_destroy_label_node(WabtAllocator* allocator, LabelNode* node) { +static void wabt_destroy_label_node(LabelNode* node) { if (*node->first) - wabt_destroy_expr_list(allocator, *node->first); + wabt_destroy_expr_list(*node->first); } -WabtResult wabt_read_binary_ast(struct WabtAllocator* allocator, - const void* data, +WabtResult wabt_read_binary_ast(const void* data, size_t size, const WabtReadBinaryOptions* options, WabtBinaryErrorHandler* error_handler, struct WabtModule* out_module) { Context ctx; WABT_ZERO_MEMORY(ctx); - ctx.allocator = allocator; ctx.error_handler = error_handler; ctx.module = out_module; @@ -1164,10 +1138,9 @@ WabtResult wabt_read_binary_ast(struct WabtAllocator* allocator, reader = s_binary_reader; reader.user_data = &ctx; - WabtResult result = - wabt_read_binary(allocator, data, size, &reader, 1, options); - WABT_DESTROY_VECTOR_AND_ELEMENTS(allocator, ctx.label_stack, label_node); + WabtResult result = wabt_read_binary(data, size, &reader, 1, options); + WABT_DESTROY_VECTOR_AND_ELEMENTS(ctx.label_stack, label_node); if (WABT_FAILED(result)) - wabt_destroy_module(allocator, out_module); + wabt_destroy_module(out_module); return result; } diff --git a/src/binary-reader-ast.h b/src/binary-reader-ast.h index 512a75ba..c4dec0af 100644 --- a/src/binary-reader-ast.h +++ b/src/binary-reader-ast.h @@ -19,13 +19,11 @@ #include "common.h" -struct WabtAllocator; struct WabtModule; struct WabtReadBinaryOptions; WABT_EXTERN_C_BEGIN -WabtResult wabt_read_binary_ast(struct WabtAllocator* allocator, - const void* data, +WabtResult wabt_read_binary_ast(const void* data, size_t size, const struct WabtReadBinaryOptions* options, WabtBinaryErrorHandler*, diff --git a/src/binary-reader-interpreter.c b/src/binary-reader-interpreter.c index 9a44f7a8..cb1ab7de 100644 --- a/src/binary-reader-interpreter.c +++ b/src/binary-reader-interpreter.c @@ -21,7 +21,6 @@ #include <stdarg.h> #include <stdio.h> -#include "allocator.h" #include "binary-reader.h" #include "interpreter.h" #include "type-checker.h" @@ -65,10 +64,8 @@ typedef struct Label { WABT_DEFINE_VECTOR(label, Label); typedef struct Context { - WabtAllocator* allocator; WabtBinaryReader* reader; WabtBinaryErrorHandler* error_handler; - WabtAllocator* memory_allocator; WabtInterpreterEnvironment* env; WabtInterpreterModule* module; WabtInterpreterFunc* current_func; @@ -252,10 +249,10 @@ static WabtResult append_fixup(Context* ctx, Uint32VectorVector* fixups_vector, uint32_t index) { if (index >= fixups_vector->size) - wabt_resize_uint32_vector_vector(ctx->allocator, fixups_vector, index + 1); + wabt_resize_uint32_vector_vector(fixups_vector, index + 1); Uint32Vector* fixups = &fixups_vector->data[index]; uint32_t offset = get_istream_offset(ctx); - wabt_append_uint32_value(ctx->allocator, fixups, &offset); + wabt_append_uint32_value(fixups, &offset); return WABT_OK; } @@ -358,11 +355,11 @@ static void on_error(WabtBinaryReaderContext* ctx, const char* message) { static WabtResult on_signature_count(uint32_t count, void* user_data) { Context* ctx = user_data; - wabt_resize_uint32_vector(ctx->allocator, &ctx->sig_index_mapping, count); + wabt_resize_uint32_vector(&ctx->sig_index_mapping, count); uint32_t i; for (i = 0; i < count; ++i) ctx->sig_index_mapping.data[i] = ctx->env->sigs.size + i; - wabt_resize_interpreter_func_signature_vector(ctx->allocator, &ctx->env->sigs, + wabt_resize_interpreter_func_signature_vector(&ctx->env->sigs, ctx->env->sigs.size + count); return WABT_OK; } @@ -376,11 +373,11 @@ static WabtResult on_signature(uint32_t index, Context* ctx = user_data; WabtInterpreterFuncSignature* sig = get_signature_by_module_index(ctx, index); - wabt_reserve_types(ctx->allocator, &sig->param_types, param_count); + wabt_reserve_types(&sig->param_types, param_count); sig->param_types.size = param_count; memcpy(sig->param_types.data, param_types, param_count * sizeof(WabtType)); - wabt_reserve_types(ctx->allocator, &sig->result_types, result_count); + wabt_reserve_types(&sig->result_types, result_count); sig->result_types.size = result_count; memcpy(sig->result_types.data, result_types, result_count * sizeof(WabtType)); return WABT_OK; @@ -388,8 +385,7 @@ static WabtResult on_signature(uint32_t index, static WabtResult on_import_count(uint32_t count, void* user_data) { Context* ctx = user_data; - wabt_new_interpreter_import_array(ctx->allocator, - &ctx->module->defined.imports, count); + wabt_new_interpreter_import_array(&ctx->module->defined.imports, count); return WABT_OK; } @@ -400,8 +396,8 @@ static WabtResult on_import(uint32_t index, Context* ctx = user_data; assert(index < ctx->module->defined.imports.size); WabtInterpreterImport* import = &ctx->module->defined.imports.data[index]; - import->module_name = wabt_dup_string_slice(ctx->allocator, module_name); - import->field_name = wabt_dup_string_slice(ctx->allocator, field_name); + import->module_name = wabt_dup_string_slice(module_name); + import->field_name = wabt_dup_string_slice(field_name); int module_index = wabt_find_binding_index_by_name( &ctx->env->registered_module_bindings, &import->module_name); if (module_index < 0) { @@ -488,13 +484,13 @@ static WabtResult append_export(Context* ctx, } WabtInterpreterExport* export = - wabt_append_interpreter_export(ctx->allocator, &module->exports); - export->name = wabt_dup_string_slice(ctx->allocator, name); + wabt_append_interpreter_export(&module->exports); + export->name = wabt_dup_string_slice(name); export->kind = kind; export->index = item_index; - WabtBinding* binding = wabt_insert_binding( - ctx->allocator, &module->export_bindings, &export->name); + WabtBinding* binding = + wabt_insert_binding(&module->export_bindings, &export->name); binding->index = module->exports.size - 1; return WABT_OK; } @@ -524,8 +520,7 @@ static WabtResult on_import_func(uint32_t import_index, uint32_t func_env_index; if (ctx->is_host_import) { - WabtInterpreterFunc* func = - wabt_append_interpreter_func(ctx->allocator, &ctx->env->funcs); + WabtInterpreterFunc* func = wabt_append_interpreter_func(&ctx->env->funcs); func->is_host = WABT_TRUE; func->sig_index = import->func.sig_index; func->host.module_name = import->module_name; @@ -554,15 +549,13 @@ static WabtResult on_import_func(uint32_t import_index, func_env_index = ctx->import_env_index; } - wabt_append_uint32_value(ctx->allocator, &ctx->func_index_mapping, - &func_env_index); + wabt_append_uint32_value(&ctx->func_index_mapping, &func_env_index); ctx->num_func_imports++; return WABT_OK; } static void init_table_func_indexes(Context* ctx, WabtInterpreterTable* table) { - wabt_new_uint32_array(ctx->allocator, &table->func_indexes, - table->limits.initial); + wabt_new_uint32_array(&table->func_indexes, table->limits.initial); size_t i; for (i = 0; i < table->func_indexes.size; ++i) table->func_indexes.data[i] = WABT_INVALID_INDEX; @@ -585,7 +578,7 @@ static WabtResult on_import_table(uint32_t import_index, if (ctx->is_host_import) { WabtInterpreterTable* table = - wabt_append_interpreter_table(ctx->allocator, &ctx->env->tables); + wabt_append_interpreter_table(&ctx->env->tables); table->limits = *elem_limits; init_table_func_indexes(ctx, table); @@ -628,8 +621,7 @@ static WabtResult on_import_memory(uint32_t import_index, if (ctx->is_host_import) { WabtInterpreterMemory* memory = - wabt_append_interpreter_memory(ctx->allocator, &ctx->env->memories); - memory->allocator = ctx->memory_allocator; + wabt_append_interpreter_memory(&ctx->env->memories); WabtInterpreterHostImportDelegate* host_delegate = &ctx->host_import_module->host.import_delegate; @@ -669,7 +661,7 @@ static WabtResult on_import_global(uint32_t import_index, uint32_t global_env_index = ctx->env->globals.size - 1; if (ctx->is_host_import) { WabtInterpreterGlobal* global = - wabt_append_interpreter_global(ctx->allocator, &ctx->env->globals); + wabt_append_interpreter_global(&ctx->env->globals); global->typed_value.type = type; global->mutable_ = mutable; @@ -689,8 +681,7 @@ static WabtResult on_import_global(uint32_t import_index, import->global.mutable_ = mutable; global_env_index = ctx->import_env_index; } - wabt_append_uint32_value(ctx->allocator, &ctx->global_index_mapping, - &global_env_index); + wabt_append_uint32_value(&ctx->global_index_mapping, &global_env_index); ctx->num_global_imports++; return WABT_OK; } @@ -699,14 +690,13 @@ static WabtResult on_function_signatures_count(uint32_t count, void* user_data) { Context* ctx = user_data; size_t old_size = ctx->func_index_mapping.size; - wabt_resize_uint32_vector(ctx->allocator, &ctx->func_index_mapping, - old_size + count); + wabt_resize_uint32_vector(&ctx->func_index_mapping, old_size + count); uint32_t i; for (i = 0; i < count; ++i) ctx->func_index_mapping.data[old_size + i] = ctx->env->funcs.size + i; - wabt_resize_interpreter_func_vector(ctx->allocator, &ctx->env->funcs, + wabt_resize_interpreter_func_vector(&ctx->env->funcs, ctx->env->funcs.size + count); - wabt_resize_uint32_vector_vector(ctx->allocator, &ctx->func_fixups, count); + wabt_resize_uint32_vector_vector(&ctx->func_fixups, count); return WABT_OK; } @@ -730,7 +720,7 @@ static WabtResult on_table(uint32_t index, return WABT_ERROR; } WabtInterpreterTable* table = - wabt_append_interpreter_table(ctx->allocator, &ctx->env->tables); + wabt_append_interpreter_table(&ctx->env->tables); table->limits = *elem_limits; init_table_func_indexes(ctx, table); ctx->module->table_index = ctx->env->tables.size - 1; @@ -746,12 +736,10 @@ static WabtResult on_memory(uint32_t index, return WABT_ERROR; } WabtInterpreterMemory* memory = - wabt_append_interpreter_memory(ctx->allocator, &ctx->env->memories); - memory->allocator = ctx->memory_allocator; + wabt_append_interpreter_memory(&ctx->env->memories); memory->page_limits = *page_limits; memory->byte_size = page_limits->initial * WABT_PAGE_SIZE; - memory->data = wabt_alloc_zero(ctx->memory_allocator, memory->byte_size, - WABT_DEFAULT_ALIGN); + memory->data = wabt_alloc_zero(memory->byte_size); ctx->module->memory_index = ctx->env->memories.size - 1; return WABT_OK; } @@ -759,12 +747,11 @@ static WabtResult on_memory(uint32_t index, static WabtResult on_global_count(uint32_t count, void* user_data) { Context* ctx = user_data; size_t old_size = ctx->global_index_mapping.size; - wabt_resize_uint32_vector(ctx->allocator, &ctx->global_index_mapping, - old_size + count); + wabt_resize_uint32_vector(&ctx->global_index_mapping, old_size + count); uint32_t i; for (i = 0; i < count; ++i) ctx->global_index_mapping.data[old_size + i] = ctx->env->globals.size + i; - wabt_resize_interpreter_global_vector(ctx->allocator, &ctx->env->globals, + wabt_resize_interpreter_global_vector(&ctx->env->globals, ctx->env->globals.size + count); return WABT_OK; } @@ -992,7 +979,7 @@ static WabtResult on_data_segment_data(uint32_t index, } static void push_label(Context* ctx, uint32_t offset, uint32_t fixup_offset) { - Label* label = wabt_append_label(ctx->allocator, &ctx->label_stack); + Label* label = wabt_append_label(&ctx->label_stack); label->offset = offset; label->fixup_offset = fixup_offset; } @@ -1006,7 +993,7 @@ static void pop_label(Context* ctx) { uint32_t to = ctx->depth_fixups.size; uint32_t i; for (i = from; i < to; ++i) - wabt_destroy_uint32_vector(ctx->allocator, &ctx->depth_fixups.data[i]); + wabt_destroy_uint32_vector(&ctx->depth_fixups.data[i]); ctx->depth_fixups.size = ctx->label_stack.size; } } @@ -1036,7 +1023,7 @@ static WabtResult begin_function_body(WabtBinaryReaderContext* context, /* append param types */ for (i = 0; i < sig->param_types.size; ++i) { - wabt_append_type_value(ctx->allocator, &func->defined.param_and_local_types, + wabt_append_type_value(&func->defined.param_and_local_types, &sig->param_types.data[i]); } @@ -1078,8 +1065,7 @@ static WabtResult on_local_decl(uint32_t decl_index, uint32_t i; for (i = 0; i < count; ++i) { - wabt_append_type_value(ctx->allocator, &func->defined.param_and_local_types, - &type); + wabt_append_type_value(&func->defined.param_and_local_types, &type); } if (decl_index == func->defined.local_decl_count - 1) { @@ -1551,20 +1537,16 @@ static WabtBinaryReader s_binary_reader_segments = { }; static void destroy_context(Context* ctx) { - wabt_destroy_label_vector(ctx->allocator, &ctx->label_stack); - WABT_DESTROY_VECTOR_AND_ELEMENTS(ctx->allocator, ctx->depth_fixups, - uint32_vector); - WABT_DESTROY_VECTOR_AND_ELEMENTS(ctx->allocator, ctx->func_fixups, - uint32_vector); - wabt_destroy_uint32_vector(ctx->allocator, &ctx->sig_index_mapping); - wabt_destroy_uint32_vector(ctx->allocator, &ctx->func_index_mapping); - wabt_destroy_uint32_vector(ctx->allocator, &ctx->global_index_mapping); + wabt_destroy_label_vector(&ctx->label_stack); + WABT_DESTROY_VECTOR_AND_ELEMENTS(ctx->depth_fixups, uint32_vector); + WABT_DESTROY_VECTOR_AND_ELEMENTS(ctx->func_fixups, uint32_vector); + wabt_destroy_uint32_vector(&ctx->sig_index_mapping); + wabt_destroy_uint32_vector(&ctx->func_index_mapping); + wabt_destroy_uint32_vector(&ctx->global_index_mapping); wabt_destroy_typechecker(&ctx->typechecker); } -WabtResult wabt_read_binary_interpreter(WabtAllocator* allocator, - WabtAllocator* memory_allocator, - WabtInterpreterEnvironment* env, +WabtResult wabt_read_binary_interpreter(WabtInterpreterEnvironment* env, const void* data, size_t size, const WabtReadBinaryOptions* options, @@ -1575,16 +1557,13 @@ WabtResult wabt_read_binary_interpreter(WabtAllocator* allocator, WabtInterpreterEnvironmentMark mark = wabt_mark_interpreter_environment(env); - WabtInterpreterModule* module = - wabt_append_interpreter_module(allocator, &env->modules); + WabtInterpreterModule* module = wabt_append_interpreter_module(&env->modules); WABT_ZERO_MEMORY(ctx); WABT_ZERO_MEMORY(reader); - ctx.allocator = allocator; ctx.reader = &reader; ctx.error_handler = error_handler; - ctx.memory_allocator = memory_allocator; ctx.env = env; ctx.module = module; ctx.module->is_host = WABT_FALSE; @@ -1599,29 +1578,28 @@ WabtResult wabt_read_binary_interpreter(WabtAllocator* allocator, WabtTypeCheckerErrorHandler tc_error_handler; tc_error_handler.on_error = on_typechecker_error; tc_error_handler.user_data = &ctx; - ctx.typechecker.allocator = allocator; ctx.typechecker.error_handler = &tc_error_handler; reader = s_binary_reader; reader.user_data = &ctx; const uint32_t num_function_passes = 1; - WabtResult result = wabt_read_binary(allocator, data, size, &reader, - num_function_passes, options); + WabtResult result = + wabt_read_binary(data, size, &reader, num_function_passes, options); wabt_steal_mem_writer_output_buffer(&ctx.istream_writer, &env->istream); if (WABT_SUCCEEDED(result)) { /* Another pass on the read binary to assign data and elem segments. */ reader = s_binary_reader_segments; reader.user_data = &ctx; - result = wabt_read_binary(allocator, data, size, &reader, - num_function_passes, options); + result = + wabt_read_binary(data, size, &reader, num_function_passes, options); assert(WABT_SUCCEEDED(result)); env->istream.size = ctx.istream_offset; ctx.module->defined.istream_end = env->istream.size; *out_module = module; } else { - wabt_reset_interpreter_environment_to_mark(allocator, env, mark); + wabt_reset_interpreter_environment_to_mark(env, mark); *out_module = NULL; } destroy_context(&ctx); diff --git a/src/binary-reader-interpreter.h b/src/binary-reader-interpreter.h index 4f1b9c14..b242c55f 100644 --- a/src/binary-reader-interpreter.h +++ b/src/binary-reader-interpreter.h @@ -19,15 +19,12 @@ #include "common.h" -struct WabtAllocator; struct WabtInterpreterEnvironment; struct WabtInterpreterModule; struct WabtReadBinaryOptions; WABT_EXTERN_C_BEGIN WabtResult wabt_read_binary_interpreter( - struct WabtAllocator* allocator, - struct WabtAllocator* memory_allocator, struct WabtInterpreterEnvironment* env, const void* data, size_t size, diff --git a/src/binary-reader-linker.c b/src/binary-reader-linker.c index 21fd0a31..f09a4339 100644 --- a/src/binary-reader-linker.c +++ b/src/binary-reader-linker.c @@ -22,7 +22,6 @@ #define RELOC_SIZE 5 typedef struct Context { - WabtAllocator* allocator; WabtLinkerInputBinary* binary; WabtSection* reloc_section; @@ -63,8 +62,7 @@ static WabtResult on_reloc(WabtRelocType type, WABT_FATAL("invalid relocation offset: %#x\n", offset); } - WabtReloc* reloc = - wabt_append_reloc(ctx->allocator, &ctx->reloc_section->relocations); + WabtReloc* reloc = wabt_append_reloc(&ctx->reloc_section->relocations); reloc->type = type; reloc->offset = offset; @@ -89,8 +87,8 @@ static WabtResult on_import_func(uint32_t import_index, uint32_t sig_index, void* user_data) { Context* ctx = user_data; - WabtFunctionImport* import = wabt_append_function_import( - ctx->allocator, &ctx->binary->function_imports); + WabtFunctionImport* import = + wabt_append_function_import(&ctx->binary->function_imports); import->name = ctx->import_name; import->sig_index = sig_index; import->active = WABT_TRUE; @@ -105,7 +103,7 @@ static WabtResult on_import_global(uint32_t import_index, void* user_data) { Context* ctx = user_data; WabtGlobalImport* import = - wabt_append_global_import(ctx->allocator, &ctx->binary->global_imports); + wabt_append_global_import(&ctx->binary->global_imports); import->name = ctx->import_name; import->type = type; import->mutable = mutable; @@ -118,7 +116,7 @@ static WabtResult begin_section(WabtBinaryReaderContext* ctx, uint32_t size) { Context* context = ctx->user_data; WabtLinkerInputBinary* binary = context->binary; - WabtSection* sec = wabt_append_section(context->allocator, &binary->sections); + WabtSection* sec = wabt_append_section(&binary->sections); context->current_section = sec; sec->section_code = section_code; sec->size = size; @@ -220,8 +218,7 @@ static WabtResult begin_data_segment(uint32_t index, void* user_data) { Context* ctx = user_data; WabtSection* sec = ctx->current_section; - WabtDataSegment* segment = - wabt_append_data_segment(ctx->allocator, &sec->data_segments); + WabtDataSegment* segment = wabt_append_data_segment(&sec->data_segments); segment->memory_index = memory_index; return WABT_OK; } @@ -258,8 +255,7 @@ static WabtResult on_export(uint32_t index, WabtStringSlice name, void* user_data) { Context* ctx = user_data; - WabtExport* export = - wabt_append_export(ctx->allocator, &ctx->binary->exports); + WabtExport* export = wabt_append_export(&ctx->binary->exports); export->name = name; export->kind = kind; export->index = item_index; @@ -270,8 +266,7 @@ static WabtResult on_function_name(uint32_t index, WabtStringSlice name, void* user_data) { Context* ctx = user_data; - wabt_append_string_slice_value(ctx->allocator, &ctx->binary->debug_names, - &name); + wabt_append_string_slice_value(&ctx->binary->debug_names, &name); return WABT_OK; } @@ -302,11 +297,9 @@ static WabtBinaryReader s_binary_reader = { .on_function_name = on_function_name, }; -WabtResult wabt_read_binary_linker(struct WabtAllocator* allocator, - WabtLinkerInputBinary* input_info) { +WabtResult wabt_read_binary_linker(WabtLinkerInputBinary* input_info) { Context context; WABT_ZERO_MEMORY(context); - context.allocator = allocator; context.binary = input_info; WabtBinaryReader reader; @@ -316,6 +309,6 @@ WabtResult wabt_read_binary_linker(struct WabtAllocator* allocator, WabtReadBinaryOptions read_options = WABT_READ_BINARY_OPTIONS_DEFAULT; read_options.read_debug_names = WABT_TRUE; - return wabt_read_binary(allocator, input_info->data, input_info->size, - &reader, 1, &read_options); + return wabt_read_binary(input_info->data, input_info->size, &reader, 1, + &read_options); } diff --git a/src/binary-reader-linker.h b/src/binary-reader-linker.h index 4371592e..3420a8b6 100644 --- a/src/binary-reader-linker.h +++ b/src/binary-reader-linker.h @@ -20,13 +20,11 @@ #include "common.h" #include "stream.h" -struct WabtAllocator; struct WabtLinkerInputBinary; WABT_EXTERN_C_BEGIN -WabtResult wabt_read_binary_linker(struct WabtAllocator* allocator, - struct WabtLinkerInputBinary* input_info); +WabtResult wabt_read_binary_linker(struct WabtLinkerInputBinary* input_info); WABT_EXTERN_C_END diff --git a/src/binary-reader-objdump.c b/src/binary-reader-objdump.c index 12d29244..700f12d3 100644 --- a/src/binary-reader-objdump.c +++ b/src/binary-reader-objdump.c @@ -30,7 +30,6 @@ WABT_DEFINE_VECTOR(uint32, Uint32); typedef struct Context { WabtObjdumpOptions* options; - WabtAllocator* allocator; WabtStream* out_stream; const uint8_t* data; size_t size; @@ -580,8 +579,7 @@ static WabtResult on_function_name(uint32_t index, print_details(ctx, " - func[%d] " PRIstringslice "\n", index, WABT_PRINTF_STRING_SLICE_ARG(name)); if (ctx->options->mode == WABT_DUMP_PREPASS) - wabt_append_string_slice_value(ctx->allocator, - &ctx->options->function_names, &name); + wabt_append_string_slice_value(&ctx->options->function_names, &name); return WABT_OK; } @@ -619,8 +617,7 @@ WabtResult on_reloc(WabtRelocType type, WabtReloc reloc; reloc.offset = offset; reloc.type = type; - wabt_append_reloc_value(ctx->allocator, &ctx->options->code_relocations, - &reloc); + wabt_append_reloc_value(&ctx->options->code_relocations, &reloc); } return WABT_OK; } @@ -726,13 +723,11 @@ static WabtBinaryReader s_binary_reader = { .on_init_expr_get_global_expr = on_init_expr_get_global_expr, }; -WabtResult wabt_read_binary_objdump(struct WabtAllocator* allocator, - const uint8_t* data, +WabtResult wabt_read_binary_objdump(const uint8_t* data, size_t size, WabtObjdumpOptions* options) { Context context; WABT_ZERO_MEMORY(context); - context.allocator = allocator; context.header_printed = WABT_FALSE; context.print_details = WABT_FALSE; context.section_found = WABT_FALSE; @@ -768,5 +763,5 @@ WabtResult wabt_read_binary_objdump(struct WabtAllocator* allocator, WabtReadBinaryOptions read_options = WABT_READ_BINARY_OPTIONS_DEFAULT; read_options.read_debug_names = WABT_TRUE; - return wabt_read_binary(allocator, data, size, &reader, 1, &read_options); + return wabt_read_binary(data, size, &reader, 1, &read_options); } diff --git a/src/binary-reader-objdump.h b/src/binary-reader-objdump.h index 3e029fcd..f0b55e6a 100644 --- a/src/binary-reader-objdump.h +++ b/src/binary-reader-objdump.h @@ -21,7 +21,6 @@ #include "stream.h" #include "vector.h" -struct WabtAllocator; struct WabtModule; struct WabtReadBinaryOptions; @@ -58,8 +57,7 @@ typedef struct WabtObjdumpOptions { WABT_EXTERN_C_BEGIN -WabtResult wabt_read_binary_objdump(struct WabtAllocator* allocator, - const uint8_t* data, +WabtResult wabt_read_binary_objdump(const uint8_t* data, size_t size, WabtObjdumpOptions* options); diff --git a/src/binary-reader-opcnt.c b/src/binary-reader-opcnt.c index 0a3a3035..c1b7ac38 100644 --- a/src/binary-reader-opcnt.c +++ b/src/binary-reader-opcnt.c @@ -22,17 +22,14 @@ #include <stdint.h> #include <stdio.h> -#include "allocator.h" #include "binary-reader.h" #include "common.h" typedef struct Context { - WabtAllocator* allocator; WabtOpcntData* opcnt_data; } Context; -static WabtResult add_int_counter_value(struct WabtAllocator* allocator, - WabtIntCounterVector* vec, +static WabtResult add_int_counter_value(WabtIntCounterVector* vec, intmax_t value) { size_t i; for (i = 0; i < vec->size; ++i) { @@ -44,13 +41,13 @@ static WabtResult add_int_counter_value(struct WabtAllocator* allocator, WabtIntCounter counter; counter.value = value; counter.count = 1; - wabt_append_int_counter_value(allocator, vec, &counter); + wabt_append_int_counter_value(vec, &counter); return WABT_OK; } -static WabtResult add_int_pair_counter_value(struct WabtAllocator* allocator, - WabtIntPairCounterVector* vec, - intmax_t first, intmax_t second) { +static WabtResult add_int_pair_counter_value(WabtIntPairCounterVector* vec, + intmax_t first, + intmax_t second) { size_t i; for (i = 0; i < vec->size; ++i) { if (vec->data[i].first == first && vec->data[i].second == second) { @@ -62,7 +59,7 @@ static WabtResult add_int_pair_counter_value(struct WabtAllocator* allocator, counter.first = first; counter.second = second; counter.count = 1; - wabt_append_int_pair_counter_value(allocator, vec, &counter); + wabt_append_int_pair_counter_value(vec, &counter); return WABT_OK; } @@ -74,8 +71,7 @@ static WabtResult on_opcode(WabtBinaryReaderContext* context, WabtIntCounter Counter; Counter.value = opcnt_vec->size; Counter.count = 0; - wabt_append_int_counter_value(ctx->opcnt_data->allocator, - opcnt_vec, &Counter); + wabt_append_int_counter_value(opcnt_vec, &Counter); } ++opcnt_vec->data[opcode].count; return WABT_OK; @@ -83,26 +79,22 @@ static WabtResult on_opcode(WabtBinaryReaderContext* context, static WabtResult on_i32_const_expr(uint32_t value, void* user_data) { Context* ctx = user_data; - return add_int_counter_value(ctx->opcnt_data->allocator, - &ctx->opcnt_data->i32_const_vec, (int32_t)value); + return add_int_counter_value(&ctx->opcnt_data->i32_const_vec, (int32_t)value); } static WabtResult on_get_local_expr(uint32_t local_index, void* user_data) { Context* ctx = user_data; - return add_int_counter_value(ctx->opcnt_data->allocator, - &ctx->opcnt_data->get_local_vec, local_index); + return add_int_counter_value(&ctx->opcnt_data->get_local_vec, local_index); } static WabtResult on_set_local_expr(uint32_t local_index, void* user_data) { Context* ctx = user_data; - return add_int_counter_value(ctx->opcnt_data->allocator, - &ctx->opcnt_data->set_local_vec, local_index); + return add_int_counter_value(&ctx->opcnt_data->set_local_vec, local_index); } static WabtResult on_tee_local_expr(uint32_t local_index, void* user_data) { Context* ctx = user_data; - return add_int_counter_value(ctx->opcnt_data->allocator, - &ctx->opcnt_data->tee_local_vec, local_index); + return add_int_counter_value(&ctx->opcnt_data->tee_local_vec, local_index); } static WabtResult on_load_expr(WabtOpcode opcode, @@ -111,8 +103,7 @@ static WabtResult on_load_expr(WabtOpcode opcode, void* user_data) { Context* ctx = user_data; if (opcode == WABT_OPCODE_I32_LOAD) - return add_int_pair_counter_value(ctx->opcnt_data->allocator, - &ctx->opcnt_data->i32_load_vec, + return add_int_pair_counter_value(&ctx->opcnt_data->i32_load_vec, alignment_log2, offset); return WABT_OK; } @@ -123,8 +114,7 @@ static WabtResult on_store_expr(WabtOpcode opcode, void* user_data) { Context* ctx = user_data; if (opcode == WABT_OPCODE_I32_STORE) - return add_int_pair_counter_value(ctx->opcnt_data->allocator, - &ctx->opcnt_data->i32_store_vec, + return add_int_pair_counter_value(&ctx->opcnt_data->i32_store_vec, alignment_log2, offset); return WABT_OK; } @@ -149,29 +139,23 @@ static WabtBinaryReader s_binary_reader = { .on_store_expr = on_store_expr }; -void wabt_init_opcnt_data(struct WabtAllocator* allocator, - WabtOpcntData* data) { +void wabt_init_opcnt_data(WabtOpcntData* data) { WABT_ZERO_MEMORY(*data); - data->allocator = allocator; } -void wabt_destroy_opcnt_data(struct WabtAllocator* allocator, - WabtOpcntData* data) { - assert(allocator == data->allocator); - wabt_destroy_int_counter_vector(allocator, &data->opcode_vec); - wabt_destroy_int_counter_vector(allocator, &data->i32_const_vec); - wabt_destroy_int_counter_vector(allocator, &data->get_local_vec); - wabt_destroy_int_pair_counter_vector(allocator, &data->i32_load_vec); +void wabt_destroy_opcnt_data(WabtOpcntData* data) { + wabt_destroy_int_counter_vector(&data->opcode_vec); + wabt_destroy_int_counter_vector(&data->i32_const_vec); + wabt_destroy_int_counter_vector(&data->get_local_vec); + wabt_destroy_int_pair_counter_vector(&data->i32_load_vec); } -WabtResult wabt_read_binary_opcnt(struct WabtAllocator* allocator, - const void* data, +WabtResult wabt_read_binary_opcnt(const void* data, size_t size, const struct WabtReadBinaryOptions* options, WabtOpcntData* opcnt_data) { Context ctx; WABT_ZERO_MEMORY(ctx); - ctx.allocator = allocator; ctx.opcnt_data = opcnt_data; WabtBinaryReader reader; @@ -179,6 +163,6 @@ WabtResult wabt_read_binary_opcnt(struct WabtAllocator* allocator, reader = s_binary_reader; reader.user_data = &ctx; - return wabt_read_binary(allocator, data, size, &reader, 1, options); + return wabt_read_binary(data, size, &reader, 1, options); } diff --git a/src/binary-reader-opcnt.h b/src/binary-reader-opcnt.h index a1314665..21c0d1d2 100644 --- a/src/binary-reader-opcnt.h +++ b/src/binary-reader-opcnt.h @@ -20,7 +20,6 @@ #include "common.h" #include "vector.h" -struct WabtAllocator; struct WabtModule; struct WabtReadBinaryOptions; @@ -42,7 +41,6 @@ typedef struct WabtIntPairCounter { WABT_DEFINE_VECTOR(int_pair_counter, WabtIntPairCounter); typedef struct WabtOpcntData { - struct WabtAllocator* allocator; WabtIntCounterVector opcode_vec; WabtIntCounterVector i32_const_vec; WabtIntCounterVector get_local_vec; @@ -52,12 +50,10 @@ typedef struct WabtOpcntData { WabtIntPairCounterVector i32_store_vec; } WabtOpcntData; -void wabt_init_opcnt_data(struct WabtAllocator* allocator, WabtOpcntData* data); -void wabt_destroy_opcnt_data(struct WabtAllocator* allocator, - WabtOpcntData* data); +void wabt_init_opcnt_data(WabtOpcntData* data); +void wabt_destroy_opcnt_data(WabtOpcntData* data); -WabtResult wabt_read_binary_opcnt(struct WabtAllocator* allocator, - const void* data, +WabtResult wabt_read_binary_opcnt(const void* data, size_t size, const struct WabtReadBinaryOptions* options, WabtOpcntData* opcnt_data); diff --git a/src/binary-reader.c b/src/binary-reader.c index 85cb48b9..8fdd6574 100644 --- a/src/binary-reader.c +++ b/src/binary-reader.c @@ -24,7 +24,6 @@ #include <stdio.h> #include <string.h> -#include "allocator.h" #include "binary.h" #include "config.h" #include "stream.h" @@ -107,7 +106,6 @@ WABT_DEFINE_VECTOR(uint32, Uint32); RAISE_ERROR(__VA_ARGS__); typedef struct Context { - WabtAllocator* allocator; const uint8_t* data; size_t data_size; size_t offset; @@ -425,8 +423,8 @@ static uint32_t num_total_globals(Context* ctx) { } static void destroy_context(Context* ctx) { - wabt_destroy_type_vector(ctx->allocator, &ctx->param_types); - wabt_destroy_uint32_vector(ctx->allocator, &ctx->target_depths); + wabt_destroy_type_vector(&ctx->param_types); + wabt_destroy_uint32_vector(&ctx->target_depths); } /* Logging */ @@ -1327,8 +1325,7 @@ static void read_function_body(Context* ctx, uint32_t end_offset) { uint32_t num_targets; in_u32_leb128(ctx, &num_targets, "br_table target count"); if (num_targets > ctx->target_depths.capacity) { - wabt_reserve_uint32s(ctx->allocator, &ctx->target_depths, - num_targets); + wabt_reserve_uint32s(&ctx->target_depths, num_targets); ctx->target_depths.size = num_targets; } @@ -1746,7 +1743,7 @@ static void read_type_section(Context* ctx, uint32_t section_size) { in_u32_leb128(ctx, &num_params, "function param count"); if (num_params > ctx->param_types.capacity) - wabt_reserve_types(ctx->allocator, &ctx->param_types, num_params); + wabt_reserve_types(&ctx->param_types, num_params); uint32_t j; for (j = 0; j < num_params; ++j) { @@ -2091,8 +2088,7 @@ static void read_sections(Context* ctx) { } } -WabtResult wabt_read_binary(WabtAllocator* allocator, - const void* data, +WabtResult wabt_read_binary(const void* data, size_t size, WabtBinaryReader* reader, uint32_t num_function_passes, @@ -2109,7 +2105,6 @@ WabtResult wabt_read_binary(WabtAllocator* allocator, WABT_ZERO_MEMORY(context); /* all the macros assume a Context* named ctx */ Context* ctx = &context; - ctx->allocator = allocator; ctx->data = data; ctx->data_size = ctx->read_end = size; ctx->reader = options->log_stream ? &logging_reader : reader; @@ -2121,10 +2116,8 @@ WabtResult wabt_read_binary(WabtAllocator* allocator, return WABT_ERROR; } - wabt_reserve_types(allocator, &ctx->param_types, - INITIAL_PARAM_TYPES_CAPACITY); - wabt_reserve_uint32s(allocator, &ctx->target_depths, - INITIAL_BR_TABLE_TARGET_CAPACITY); + wabt_reserve_types(&ctx->param_types, INITIAL_PARAM_TYPES_CAPACITY); + wabt_reserve_uint32s(&ctx->target_depths, INITIAL_BR_TABLE_TARGET_CAPACITY); uint32_t magic; in_u32(ctx, &magic, "magic"); diff --git a/src/binary-reader.h b/src/binary-reader.h index b202c4c4..5f13ebe5 100644 --- a/src/binary-reader.h +++ b/src/binary-reader.h @@ -23,8 +23,6 @@ #include "binary.h" #include "common.h" -struct WabtAllocator; - #define WABT_READ_BINARY_OPTIONS_DEFAULT \ { NULL, WABT_FALSE } @@ -324,8 +322,7 @@ typedef struct WabtBinaryReader { } WabtBinaryReader; WABT_EXTERN_C_BEGIN -WabtResult wabt_read_binary(struct WabtAllocator* allocator, - const void* data, +WabtResult wabt_read_binary(const void* data, size_t size, WabtBinaryReader* reader, uint32_t num_function_passes, diff --git a/src/binary-writer-spec.c b/src/binary-writer-spec.c index ff31b396..ae916905 100644 --- a/src/binary-writer-spec.c +++ b/src/binary-writer-spec.c @@ -27,7 +27,6 @@ #include "writer.h" typedef struct Context { - WabtAllocator* allocator; WabtMemoryWriter json_writer; WabtStream json_stream; WabtStringSlice source_filename; @@ -97,7 +96,7 @@ static WabtStringSlice get_basename(const char* s) { static char* get_module_filename(Context* ctx) { size_t buflen = ctx->module_filename_noext.length + 20; - char* str = wabt_alloc(ctx->allocator, buflen, WABT_DEFAULT_ALIGN); + char* str = wabt_alloc(buflen); size_t length = wabt_snprintf(str, buflen, PRIstringslice ".%" PRIzd ".wasm", WABT_PRINTF_STRING_SLICE_ARG(ctx->module_filename_noext), @@ -295,11 +294,10 @@ static void write_module(Context* ctx, char* filename, const WabtModule* module) { WabtMemoryWriter writer; - WabtResult result = wabt_init_mem_writer(ctx->allocator, &writer); + WabtResult result = wabt_init_mem_writer(&writer); if (WABT_SUCCEEDED(result)) { WabtWriteBinaryOptions options = ctx->spec_options->write_binary_options; - result = wabt_write_binary_module(ctx->allocator, &writer.base, module, - &options); + result = wabt_write_binary_module(&writer.base, module, &options); if (WABT_SUCCEEDED(result) && ctx->write_modules) result = wabt_write_output_buffer_to_file(&writer.buf, filename); wabt_close_mem_writer(&writer); @@ -338,7 +336,7 @@ static void write_invalid_module(Context* ctx, write_key(ctx, "text"); write_escaped_string_slice(ctx, text); write_raw_module(ctx, filename, module); - wabt_free(ctx->allocator, filename); + wabt_free(filename); } static void write_commands(Context* ctx, WabtScript* script) { @@ -375,7 +373,7 @@ static void write_commands(Context* ctx, WabtScript* script) { write_key(ctx, "filename"); write_escaped_string_slice(ctx, get_basename(filename)); write_module(ctx, filename, module); - wabt_free(ctx->allocator, filename); + wabt_free(filename); ctx->num_modules++; last_module_index = (int)i; break; @@ -474,14 +472,12 @@ static void write_commands(Context* ctx, WabtScript* script) { } WabtResult wabt_write_binary_spec_script( - WabtAllocator* allocator, WabtScript* script, const char* source_filename, const WabtWriteBinarySpecOptions* spec_options) { assert(source_filename); Context ctx; WABT_ZERO_MEMORY(ctx); - ctx.allocator = allocator; ctx.spec_options = spec_options; ctx.result = WABT_OK; ctx.source_filename.start = source_filename; @@ -491,7 +487,7 @@ WabtResult wabt_write_binary_spec_script( : source_filename); ctx.write_modules = ctx.spec_options->json_filename != NULL; - WabtResult result = wabt_init_mem_writer(ctx.allocator, &ctx.json_writer); + WabtResult result = wabt_init_mem_writer(&ctx.json_writer); if (WABT_SUCCEEDED(result)) { wabt_init_stream(&ctx.json_stream, &ctx.json_writer.base, NULL); write_commands(&ctx, script); diff --git a/src/binary-writer-spec.h b/src/binary-writer-spec.h index 5a9dea90..cb4d3d23 100644 --- a/src/binary-writer-spec.h +++ b/src/binary-writer-spec.h @@ -21,7 +21,6 @@ #include "binary-writer.h" #include "common.h" -struct WabtAllocator; struct WabtWriter; #define WABT_WRITE_BINARY_SPEC_OPTIONS_DEFAULT \ @@ -33,8 +32,7 @@ typedef struct WabtWriteBinarySpecOptions { } WabtWriteBinarySpecOptions; WABT_EXTERN_C_BEGIN -WabtResult wabt_write_binary_spec_script(struct WabtAllocator*, - struct WabtScript*, +WabtResult wabt_write_binary_spec_script(struct WabtScript*, const char* source_filename, const WabtWriteBinarySpecOptions*); WABT_EXTERN_C_END diff --git a/src/binary-writer.c b/src/binary-writer.c index 82d5b430..61a26e70 100644 --- a/src/binary-writer.c +++ b/src/binary-writer.c @@ -54,7 +54,6 @@ typedef struct RelocSection { WABT_DEFINE_VECTOR(reloc_section, RelocSection); typedef struct Context { - WabtAllocator* allocator; WabtStream stream; WabtStream* log_stream; const WabtWriteBinaryOptions* options; @@ -68,9 +67,8 @@ typedef struct Context { size_t last_section_payload_offset; } Context; -void wabt_destroy_reloc_section(WabtAllocator* allocator, - RelocSection* reloc_section) { - wabt_destroy_reloc_vector(allocator, &reloc_section->relocations); +void wabt_destroy_reloc_section(RelocSection* reloc_section) { + wabt_destroy_reloc_vector(&reloc_section->relocations); } static uint8_t log2_u32(uint32_t x) { @@ -327,15 +325,14 @@ static void add_reloc(Context* ctx, WabtRelocType reloc_type) { if (!ctx->current_reloc_section || ctx->current_reloc_section->section_code != ctx->last_section_type) { ctx->current_reloc_section = - wabt_append_reloc_section(ctx->allocator, &ctx->reloc_sections); + wabt_append_reloc_section(&ctx->reloc_sections); ctx->current_reloc_section->name = wabt_get_section_name(ctx->last_section_type); ctx->current_reloc_section->section_code = ctx->last_section_type; } // Add a new relocation to the curent reloc section - Reloc* r = wabt_append_reloc(ctx->allocator, - &ctx->current_reloc_section->relocations); + Reloc* r = wabt_append_reloc(&ctx->current_reloc_section->relocations); r->type = reloc_type; r->offset = ctx->stream.offset - ctx->last_section_payload_offset; } @@ -903,8 +900,7 @@ static WabtResult write_module(Context* ctx, const WabtModule* module) { if (num_params_and_locals) { wabt_make_type_binding_reverse_mapping( - ctx->allocator, &func->decl.sig.param_types, &func->param_bindings, - &index_to_name); + &func->decl.sig.param_types, &func->param_bindings, &index_to_name); size_t j; for (j = 0; j < num_params; ++j) { WabtStringSlice name = index_to_name.data[j]; @@ -914,8 +910,7 @@ static WabtResult write_module(Context* ctx, const WabtModule* module) { } wabt_make_type_binding_reverse_mapping( - ctx->allocator, &func->local_types, &func->local_bindings, - &index_to_name); + &func->local_types, &func->local_bindings, &index_to_name); for (j = 0; j < num_locals; ++j) { WabtStringSlice name = index_to_name.data[j]; wabt_snprintf(desc, sizeof(desc), "local name %" PRIzd, @@ -927,27 +922,24 @@ static WabtResult write_module(Context* ctx, const WabtModule* module) { } end_section(ctx); - wabt_destroy_string_slice_vector(ctx->allocator, &index_to_name); + wabt_destroy_string_slice_vector(&index_to_name); } if (ctx->options->relocatable) { for (i = 0; i < ctx->reloc_sections.size; i++) { write_reloc_section(ctx, &ctx->reloc_sections.data[i]); } - WABT_DESTROY_VECTOR_AND_ELEMENTS(ctx->allocator, ctx->reloc_sections, - reloc_section); + WABT_DESTROY_VECTOR_AND_ELEMENTS(ctx->reloc_sections, reloc_section); } return ctx->stream.result; } -WabtResult wabt_write_binary_module(WabtAllocator* allocator, - WabtWriter* writer, +WabtResult wabt_write_binary_module(WabtWriter* writer, const WabtModule* module, const WabtWriteBinaryOptions* options) { Context ctx; WABT_ZERO_MEMORY(ctx); - ctx.allocator = allocator; ctx.options = options; ctx.log_stream = options->log_stream; wabt_init_stream(&ctx.stream, writer, ctx.log_stream); diff --git a/src/binary-writer.h b/src/binary-writer.h index 9171b347..04c61fa0 100644 --- a/src/binary-writer.h +++ b/src/binary-writer.h @@ -19,7 +19,6 @@ #include "common.h" -struct WabtAllocator; struct WabtModule; struct WabtScript; struct WabtWriter; @@ -37,8 +36,7 @@ typedef struct WabtWriteBinaryOptions { } WabtWriteBinaryOptions; WABT_EXTERN_C_BEGIN -WabtResult wabt_write_binary_module(struct WabtAllocator*, - struct WabtWriter*, +WabtResult wabt_write_binary_module(struct WabtWriter*, const struct WabtModule*, const WabtWriteBinaryOptions*); diff --git a/src/binding-hash.c b/src/binding-hash.c index 4e83d18b..c64d8b22 100644 --- a/src/binding-hash.c +++ b/src/binding-hash.c @@ -88,14 +88,11 @@ static WabtBindingHashEntry* hash_new_entry(WabtBindingHash* hash, return entry; } -static void hash_resize(WabtAllocator* allocator, - WabtBindingHash* hash, - size_t desired_capacity) { +static void hash_resize(WabtBindingHash* hash, size_t desired_capacity) { WabtBindingHash new_hash; WABT_ZERO_MEMORY(new_hash); /* TODO(binji): better plural */ - wabt_reserve_binding_hash_entrys(allocator, &new_hash.entries, - desired_capacity); + wabt_reserve_binding_hash_entrys(&new_hash.entries, desired_capacity); /* update the free list */ size_t i; @@ -123,19 +120,18 @@ static void hash_resize(WabtAllocator* allocator, /* we are sharing the WabtStringSlices, so we only need to destroy the old * binding vector */ - wabt_destroy_binding_hash_entry_vector(allocator, &hash->entries); + wabt_destroy_binding_hash_entry_vector(&hash->entries); *hash = new_hash; } -WabtBinding* wabt_insert_binding(WabtAllocator* allocator, - WabtBindingHash* hash, +WabtBinding* wabt_insert_binding(WabtBindingHash* hash, const WabtStringSlice* name) { if (hash->entries.size == 0) - hash_resize(allocator, hash, INITIAL_HASH_CAPACITY); + hash_resize(hash, INITIAL_HASH_CAPACITY); if (!hash->free_head) { /* no more free space, allocate more */ - hash_resize(allocator, hash, hash->entries.capacity * 2); + hash_resize(hash, hash->entries.capacity * 2); } WabtBindingHashEntry* entry = hash_new_entry(hash, name); @@ -159,29 +155,25 @@ int wabt_find_binding_index_by_name(const WabtBindingHash* hash, return -1; } -void wabt_remove_binding(struct WabtAllocator* allocator, - WabtBindingHash* hash, - const WabtStringSlice* name) { +void wabt_remove_binding(WabtBindingHash* hash, const WabtStringSlice* name) { int index = wabt_find_binding_index_by_name(hash, name); if (index == -1) return; WabtBindingHashEntry* entry = &hash->entries.data[index]; - wabt_destroy_string_slice(allocator, &entry->binding.name); + wabt_destroy_string_slice(&entry->binding.name); WABT_ZERO_MEMORY(*entry); } -static void destroy_binding_hash_entry(WabtAllocator* allocator, - WabtBindingHashEntry* entry) { - wabt_destroy_string_slice(allocator, &entry->binding.name); +static void destroy_binding_hash_entry(WabtBindingHashEntry* entry) { + wabt_destroy_string_slice(&entry->binding.name); } -void wabt_destroy_binding_hash(WabtAllocator* allocator, - WabtBindingHash* hash) { +void wabt_destroy_binding_hash(WabtBindingHash* hash) { /* Can't use WABT_DESTROY_VECTOR_AND_ELEMENTS, because it loops over size, not * capacity. */ size_t i; for (i = 0; i < hash->entries.capacity; ++i) - destroy_binding_hash_entry(allocator, &hash->entries.data[i]); - wabt_destroy_binding_hash_entry_vector(allocator, &hash->entries); + destroy_binding_hash_entry(&hash->entries.data[i]); + wabt_destroy_binding_hash_entry_vector(&hash->entries); } diff --git a/src/binding-hash.h b/src/binding-hash.h index 0c3f4e46..c751548e 100644 --- a/src/binding-hash.h +++ b/src/binding-hash.h @@ -20,8 +20,6 @@ #include "common.h" #include "vector.h" -struct WabtAllocator; - typedef struct WabtBinding { WabtLocation loc; WabtStringSlice name; @@ -41,17 +39,13 @@ typedef struct WabtBindingHash { } WabtBindingHash; WABT_EXTERN_C_BEGIN -WabtBinding* wabt_insert_binding(struct WabtAllocator*, - WabtBindingHash*, - const WabtStringSlice*); -void wabt_remove_binding(struct WabtAllocator*, - WabtBindingHash*, - const WabtStringSlice*); +WabtBinding* wabt_insert_binding(WabtBindingHash*, const WabtStringSlice*); +void wabt_remove_binding(WabtBindingHash*, const WabtStringSlice*); WabtBool wabt_hash_entry_is_free(const WabtBindingHashEntry*); /* returns -1 if the name is not in the hash */ int wabt_find_binding_index_by_name(const WabtBindingHash*, const WabtStringSlice* name); -void wabt_destroy_binding_hash(struct WabtAllocator*, WabtBindingHash*); +void wabt_destroy_binding_hash(WabtBindingHash*); WABT_EXTERN_C_END #endif /* WABT_BINDING_HASH_H_ */ diff --git a/src/common.c b/src/common.c index 7a2225c6..d5cdfe63 100644 --- a/src/common.c +++ b/src/common.c @@ -26,8 +26,6 @@ #include <io.h> #endif -#include "allocator.h" - #define V(rtype, type1, type2, mem_size, code, NAME, text) \ [code] = {text, WABT_TYPE_##rtype, WABT_TYPE_##type1, WABT_TYPE_##type2, \ mem_size}, @@ -98,13 +96,12 @@ WabtBool wabt_string_slices_are_equal(const WabtStringSlice* a, memcmp(a->start, b->start, a->length) == 0; } -void wabt_destroy_string_slice(WabtAllocator* allocator, WabtStringSlice* str) { +void wabt_destroy_string_slice(WabtStringSlice* str) { assert(str); - wabt_free(allocator, (void*)str->start); + wabt_free((void*)str->start); } -WabtResult wabt_read_file(WabtAllocator* allocator, - const char* filename, +WabtResult wabt_read_file(const char* filename, void** out_data, size_t* out_size) { FILE* infile = fopen(filename, "rb"); @@ -129,7 +126,7 @@ WabtResult wabt_read_file(WabtAllocator* allocator, return WABT_ERROR; } - void* data = wabt_alloc(allocator, size, WABT_DEFAULT_ALIGN); + void* data = wabt_alloc(size); if (size != 0 && fread(data, size, 1, infile) != 1) { fprintf(stderr, "fread failed.\n"); return WABT_ERROR; diff --git a/src/common.h b/src/common.h index e11841e7..410f6149 100644 --- a/src/common.h +++ b/src/common.h @@ -22,6 +22,8 @@ #include <stddef.h> #include <stdint.h> #include <stdio.h> +#include <stdlib.h> +#include <string.h> #include "config.h" @@ -66,8 +68,6 @@ } \ va_end(args_copy) -struct WabtAllocator; - typedef enum WabtBool { WABT_FALSE, WABT_TRUE, @@ -403,6 +403,46 @@ typedef struct WabtLiteral { } WabtLiteral; WABT_EXTERN_C_BEGIN +static WABT_INLINE void* wabt_alloc(size_t size) { + return malloc(size); +} + +static WABT_INLINE void* wabt_alloc_zero(size_t size) { + return calloc(size, 1); +} + +static WABT_INLINE void* wabt_realloc(void* p, size_t size) { + /* Realloc normally frees if size is 0, but we don't want that behavior. */ + if (size == 0) + return p; + return realloc(p, size); +} + +static WABT_INLINE void wabt_free(void* p) { + free(p); +} + +static WABT_INLINE char* wabt_strndup(const char* s, size_t len) { + size_t real_len = 0; + const char* p = s; + while (real_len < len && *p) { + p++; + real_len++; + } + + char* new_s = (char*)wabt_alloc(real_len + 1); + memcpy(new_s, s, real_len); + new_s[real_len] = 0; + return new_s; +} + +static WABT_INLINE WabtStringSlice wabt_dup_string_slice(WabtStringSlice str) { + WabtStringSlice result; + result.start = wabt_strndup(str.start, str.length); + result.length = str.length; + return result; +} + /* return 1 if |alignment| matches the alignment of |opcode|, or if |alignment| * is WABT_USE_NATURAL_ALIGNMENT */ WabtBool wabt_is_naturally_aligned(WabtOpcode opcode, uint32_t alignment); @@ -413,14 +453,14 @@ uint32_t wabt_get_opcode_alignment(WabtOpcode opcode, uint32_t alignment); WabtStringSlice wabt_empty_string_slice(void); WabtBool wabt_string_slice_eq_cstr(const WabtStringSlice* s1, const char* s2); -WabtBool wabt_string_slice_startswith(const WabtStringSlice* s1, const char* s2); +WabtBool wabt_string_slice_startswith(const WabtStringSlice* s1, + const char* s2); WabtStringSlice wabt_string_slice_from_cstr(const char* string); WabtBool wabt_string_slice_is_empty(const WabtStringSlice*); WabtBool wabt_string_slices_are_equal(const WabtStringSlice*, const WabtStringSlice*); -void wabt_destroy_string_slice(struct WabtAllocator*, WabtStringSlice*); -WabtResult wabt_read_file(struct WabtAllocator* allocator, - const char* filename, +void wabt_destroy_string_slice(WabtStringSlice*); +WabtResult wabt_read_file(const char* filename, void** out_data, size_t* out_size); diff --git a/src/emscripten-exported.json b/src/emscripten-exported.json index 05f1f694..43f4dff1 100644 --- a/src/emscripten-exported.json +++ b/src/emscripten-exported.json @@ -4,7 +4,6 @@ "_wabt_append_module_field", "_wabt_apply_names", "_wabt_ast_format_error", -"_wabt_ast_lexer_get_allocator", "_wabt_ast_lexer_get_source_line", "_wabt_ast_lexer_lex", "_wabt_ast_parser_error", @@ -44,7 +43,6 @@ "_wabt_destroy_raw_module", "_wabt_destroy_reloc_section", "_wabt_destroy_script", -"_wabt_destroy_stack_allocator", "_wabt_destroy_string_slice", "_wabt_destroy_table", "_wabt_destroy_text_list", @@ -71,7 +69,6 @@ "_wabt_get_global_index_by_var", "_wabt_get_index_from_var", "_wabt_get_interpreter_export_by_name", -"_wabt_get_libc_allocator", "_wabt_get_local_index_by_var", "_wabt_get_memory_by_var", "_wabt_get_memory_index_by_var", @@ -89,7 +86,6 @@ "_wabt_init_mem_writer", "_wabt_init_mem_writer_existing", "_wabt_init_output_buffer", -"_wabt_init_stack_allocator", "_wabt_init_stderr_stream", "_wabt_init_stdio", "_wabt_init_stdout_stream", @@ -131,13 +127,6 @@ "_wabt_new_tee_local_expr", "_wabt_new_unary_expr", "_wabt_new_unreachable_expr", -"_wabt_offsetof_allocator_alloc", -"_wabt_offsetof_allocator_destroy", -"_wabt_offsetof_allocator_free", -"_wabt_offsetof_allocator_mark", -"_wabt_offsetof_allocator_print_stats", -"_wabt_offsetof_allocator_realloc", -"_wabt_offsetof_allocator_reset_to_mark", "_wabt_offsetof_binary_error_handler_on_error", "_wabt_offsetof_binary_error_handler_user_data", "_wabt_offsetof_location_filename", @@ -146,7 +135,6 @@ "_wabt_offsetof_location_line", "_wabt_offsetof_memory_writer_base", "_wabt_offsetof_memory_writer_buf", -"_wabt_offsetof_output_buffer_allocator", "_wabt_offsetof_output_buffer_capacity", "_wabt_offsetof_output_buffer_size", "_wabt_offsetof_output_buffer_start", @@ -154,7 +142,6 @@ "_wabt_offsetof_source_error_handler_on_error", "_wabt_offsetof_source_error_handler_source_line_max_length", "_wabt_offsetof_source_error_handler_user_data", -"_wabt_offsetof_stack_allocator_allocator", "_wabt_offsetof_stream_log_stream", "_wabt_offsetof_stream_offset", "_wabt_offsetof_stream_result", @@ -188,7 +175,6 @@ "_wabt_resolve_names_module", "_wabt_resolve_names_script", "_wabt_run_interpreter", -"_wabt_sizeof_allocator", "_wabt_sizeof_binary_error_handler", "_wabt_sizeof_location", "_wabt_sizeof_memory_writer", @@ -197,7 +183,6 @@ "_wabt_sizeof_read_binary_options", "_wabt_sizeof_script", "_wabt_sizeof_source_error_handler", -"_wabt_sizeof_stack_allocator", "_wabt_sizeof_stream", "_wabt_sizeof_string_slice", "_wabt_sizeof_write_binary_options", @@ -235,4 +220,4 @@ "_wabt_write_u32_leb128_at", "_wabt_write_u64", "_wabt_write_u8", -"_wabt_writef"]
\ No newline at end of file +"_wabt_writef"] diff --git a/src/emscripten-helpers.c b/src/emscripten-helpers.c index a4a159c4..4e8d92f6 100644 --- a/src/emscripten-helpers.c +++ b/src/emscripten-helpers.c @@ -19,12 +19,10 @@ #include <stddef.h> -#include "allocator.h" #include "ast.h" #include "binary-reader.h" #include "binary-writer.h" #include "common.h" -#include "stack-allocator.h" #include "stream.h" #include "writer.h" @@ -66,10 +64,6 @@ WABT_EXTERN_C_BEGIN /* clang-format off */ DEFINE_STRUCT( - WabtAllocator, allocator, - alloc, realloc, free, destroy, mark, reset_to_mark, print_stats) - -DEFINE_STRUCT( WabtBinaryErrorHandler, binary_error_handler, on_error, user_data) @@ -86,7 +80,7 @@ DEFINE_STRUCT0( DEFINE_STRUCT( WabtOutputBuffer, output_buffer, - allocator, start, size, capacity) + start, size, capacity) DEFINE_STRUCT( WabtReadBinaryOptions, read_binary_options, @@ -100,10 +94,6 @@ DEFINE_STRUCT( on_error, source_line_max_length, user_data) DEFINE_STRUCT( - WabtStackAllocator, stack_allocator, - allocator); - -DEFINE_STRUCT( WabtStream, stream, writer, offset, result, log_stream) diff --git a/src/generate-names.c b/src/generate-names.c index cab129ba..98aa448f 100644 --- a/src/generate-names.c +++ b/src/generate-names.c @@ -19,7 +19,6 @@ #include <assert.h> #include <stdio.h> -#include "allocator.h" #include "ast.h" #define CHECK_RESULT(expr) \ @@ -29,7 +28,6 @@ } while (0) typedef struct Context { - WabtAllocator* allocator; WabtModule* module; WabtExprVisitor visitor; WabtStringSliceVector index_to_name; @@ -40,8 +38,7 @@ static WabtBool has_name(WabtStringSlice* str) { return str->length > 0; } -static void generate_name(WabtAllocator* allocator, - const char* prefix, +static void generate_name(const char* prefix, uint32_t index, WabtStringSlice* str) { size_t prefix_len = strlen(prefix); @@ -52,39 +49,35 @@ static void generate_name(WabtAllocator* allocator, WabtStringSlice buf; buf.length = actual_len; buf.start = buffer; - *str = wabt_dup_string_slice(allocator, buf); + *str = wabt_dup_string_slice(buf); } -static void maybe_generate_name(WabtAllocator* allocator, - const char* prefix, +static void maybe_generate_name(const char* prefix, uint32_t index, WabtStringSlice* str) { if (!has_name(str)) - generate_name(allocator, prefix, index, str); + generate_name(prefix, index, str); } -static void generate_and_bind_name(WabtAllocator* allocator, - WabtBindingHash* bindings, +static void generate_and_bind_name(WabtBindingHash* bindings, const char* prefix, uint32_t index, WabtStringSlice* str) { - generate_name(allocator, prefix, index, str); + generate_name(prefix, index, str); WabtBinding* binding; - binding = wabt_insert_binding(allocator, bindings, str); + binding = wabt_insert_binding(bindings, str); binding->index = index; } -static void maybe_generate_and_bind_name(WabtAllocator* allocator, - WabtBindingHash* bindings, +static void maybe_generate_and_bind_name(WabtBindingHash* bindings, const char* prefix, uint32_t index, WabtStringSlice* str) { if (!has_name(str)) - generate_and_bind_name(allocator, bindings, prefix, index, str); + generate_and_bind_name(bindings, prefix, index, str); } -static void generate_and_bind_local_names(WabtAllocator* allocator, - WabtStringSliceVector* index_to_name, +static void generate_and_bind_local_names(WabtStringSliceVector* index_to_name, WabtBindingHash* bindings, const char* prefix) { size_t i; @@ -94,29 +87,26 @@ static void generate_and_bind_local_names(WabtAllocator* allocator, continue; WabtStringSlice new_name; - generate_and_bind_name(allocator, bindings, prefix, i, &new_name); + generate_and_bind_name(bindings, prefix, i, &new_name); index_to_name->data[i] = new_name; } } static WabtResult begin_block_expr(WabtExpr* expr, void* user_data) { Context* ctx = user_data; - maybe_generate_name(ctx->allocator, "$B", ctx->label_count++, - &expr->block.label); + maybe_generate_name("$B", ctx->label_count++, &expr->block.label); return WABT_OK; } static WabtResult begin_loop_expr(WabtExpr* expr, void* user_data) { Context* ctx = user_data; - maybe_generate_name(ctx->allocator, "$L", ctx->label_count++, - &expr->loop.label); + maybe_generate_name("$L", ctx->label_count++, &expr->loop.label); return WABT_OK; } static WabtResult begin_if_expr(WabtExpr* expr, void* user_data) { Context* ctx = user_data; - maybe_generate_name(ctx->allocator, "$L", ctx->label_count++, - &expr->if_.true_.label); + maybe_generate_name("$L", ctx->label_count++, &expr->if_.true_.label); return WABT_OK; } @@ -124,20 +114,18 @@ static WabtResult begin_if_expr(WabtExpr* expr, void* user_data) { static WabtResult visit_func(Context* ctx, uint32_t func_index, WabtFunc* func) { - maybe_generate_and_bind_name(ctx->allocator, &ctx->module->func_bindings, - "$f", func_index, &func->name); + maybe_generate_and_bind_name(&ctx->module->func_bindings, "$f", func_index, + &func->name); wabt_make_type_binding_reverse_mapping( - ctx->allocator, &func->decl.sig.param_types, &func->param_bindings, - &ctx->index_to_name); - generate_and_bind_local_names(ctx->allocator, &ctx->index_to_name, - &func->param_bindings, "$p"); + &func->decl.sig.param_types, &func->param_bindings, &ctx->index_to_name); + generate_and_bind_local_names(&ctx->index_to_name, &func->param_bindings, + "$p"); - wabt_make_type_binding_reverse_mapping(ctx->allocator, &func->local_types, - &func->local_bindings, - &ctx->index_to_name); - generate_and_bind_local_names(ctx->allocator, &ctx->index_to_name, - &func->local_bindings, "$l"); + wabt_make_type_binding_reverse_mapping( + &func->local_types, &func->local_bindings, &ctx->index_to_name); + generate_and_bind_local_names(&ctx->index_to_name, &func->local_bindings, + "$l"); ctx->label_count = 0; CHECK_RESULT(wabt_visit_func(func, &ctx->visitor)); @@ -147,32 +135,32 @@ static WabtResult visit_func(Context* ctx, static WabtResult visit_global(Context* ctx, uint32_t global_index, WabtGlobal* global) { - maybe_generate_and_bind_name(ctx->allocator, &ctx->module->global_bindings, - "$g", global_index, &global->name); + maybe_generate_and_bind_name(&ctx->module->global_bindings, "$g", + global_index, &global->name); return WABT_OK; } static WabtResult visit_func_type(Context* ctx, uint32_t func_type_index, WabtFuncType* func_type) { - maybe_generate_and_bind_name(ctx->allocator, &ctx->module->func_type_bindings, - "$t", func_type_index, &func_type->name); + maybe_generate_and_bind_name(&ctx->module->func_type_bindings, "$t", + func_type_index, &func_type->name); return WABT_OK; } static WabtResult visit_table(Context* ctx, uint32_t table_index, WabtTable* table) { - maybe_generate_and_bind_name(ctx->allocator, &ctx->module->table_bindings, - "$T", table_index, &table->name); + maybe_generate_and_bind_name(&ctx->module->table_bindings, "$T", table_index, + &table->name); return WABT_OK; } static WabtResult visit_memory(Context* ctx, uint32_t memory_index, WabtMemory* memory) { - maybe_generate_and_bind_name(ctx->allocator, &ctx->module->memory_bindings, - "$M", memory_index, &memory->name); + maybe_generate_and_bind_name(&ctx->module->memory_bindings, "$M", + memory_index, &memory->name); return WABT_OK; } @@ -191,16 +179,15 @@ static WabtResult visit_module(Context* ctx, WabtModule* module) { return WABT_OK; } -WabtResult wabt_generate_names(WabtAllocator* allocator, WabtModule* module) { +WabtResult wabt_generate_names(WabtModule* module) { Context ctx; WABT_ZERO_MEMORY(ctx); - ctx.allocator = allocator; ctx.visitor.user_data = &ctx; ctx.visitor.begin_block_expr = begin_block_expr; ctx.visitor.begin_loop_expr = begin_loop_expr; ctx.visitor.begin_if_expr = begin_if_expr; ctx.module = module; WabtResult result = visit_module(&ctx, module); - wabt_destroy_string_slice_vector(allocator, &ctx.index_to_name); + wabt_destroy_string_slice_vector(&ctx.index_to_name); return result; } diff --git a/src/generate-names.h b/src/generate-names.h index 0d29bfb9..ad4d2073 100644 --- a/src/generate-names.h +++ b/src/generate-names.h @@ -19,11 +19,10 @@ #include "common.h" -struct WabtAllocator; struct WabtModule; WABT_EXTERN_C_BEGIN -WabtResult wabt_generate_names(struct WabtAllocator*, struct WabtModule*); +WabtResult wabt_generate_names(struct WabtModule*); WABT_EXTERN_C_END #endif /* WABT_GENERATE_NAMES_H_ */ diff --git a/src/interpreter.c b/src/interpreter.c index d99da283..1de70232 100644 --- a/src/interpreter.c +++ b/src/interpreter.c @@ -46,71 +46,55 @@ static const char* wabt_get_interpreter_opcode_name(uint8_t opcode) { return s_interpreter_opcode_name[opcode]; } -void wabt_init_interpreter_environment(WabtAllocator* allocator, - WabtInterpreterEnvironment* env) { +void wabt_init_interpreter_environment(WabtInterpreterEnvironment* env) { WABT_ZERO_MEMORY(*env); - wabt_init_output_buffer(allocator, &env->istream, INITIAL_ISTREAM_CAPACITY); + wabt_init_output_buffer(&env->istream, INITIAL_ISTREAM_CAPACITY); } static void wabt_destroy_interpreter_func_signature( - WabtAllocator* allocator, WabtInterpreterFuncSignature* sig) { - wabt_destroy_type_vector(allocator, &sig->param_types); - wabt_destroy_type_vector(allocator, &sig->result_types); + wabt_destroy_type_vector(&sig->param_types); + wabt_destroy_type_vector(&sig->result_types); } -static void wabt_destroy_interpreter_func( - WabtAllocator* allocator, - WabtInterpreterFunc* func) { +static void wabt_destroy_interpreter_func(WabtInterpreterFunc* func) { if (!func->is_host) - wabt_destroy_type_vector(allocator, &func->defined.param_and_local_types); + wabt_destroy_type_vector(&func->defined.param_and_local_types); } -static void wabt_destroy_interpreter_memory(WabtAllocator* unused, - WabtInterpreterMemory* memory) { - if (memory->allocator) { - wabt_free(memory->allocator, memory->data); - } else { - assert(memory->data == NULL); - } +static void wabt_destroy_interpreter_memory(WabtInterpreterMemory* memory) { + wabt_free(memory->data); } -static void wabt_destroy_interpreter_table(WabtAllocator* allocator, - WabtInterpreterTable* table) { - wabt_destroy_uint32_array(allocator, &table->func_indexes); +static void wabt_destroy_interpreter_table(WabtInterpreterTable* table) { + wabt_destroy_uint32_array(&table->func_indexes); } -static void wabt_destroy_interpreter_import(WabtAllocator* allocator, - WabtInterpreterImport* import) { - wabt_destroy_string_slice(allocator, &import->module_name); - wabt_destroy_string_slice(allocator, &import->field_name); +static void wabt_destroy_interpreter_import(WabtInterpreterImport* import) { + wabt_destroy_string_slice(&import->module_name); + wabt_destroy_string_slice(&import->field_name); } -static void wabt_destroy_interpreter_module(WabtAllocator* allocator, - WabtInterpreterModule* module) { - wabt_destroy_interpreter_export_vector(allocator, &module->exports); - wabt_destroy_binding_hash(allocator, &module->export_bindings); - wabt_destroy_string_slice(allocator, &module->name); +static void wabt_destroy_interpreter_module(WabtInterpreterModule* module) { + wabt_destroy_interpreter_export_vector(&module->exports); + wabt_destroy_binding_hash(&module->export_bindings); + wabt_destroy_string_slice(&module->name); if (!module->is_host) { - WABT_DESTROY_ARRAY_AND_ELEMENTS(allocator, module->defined.imports, + WABT_DESTROY_ARRAY_AND_ELEMENTS(module->defined.imports, interpreter_import); } } -void wabt_destroy_interpreter_environment(WabtAllocator* allocator, - WabtInterpreterEnvironment* env) { - WABT_DESTROY_VECTOR_AND_ELEMENTS(allocator, env->modules, - interpreter_module); - WABT_DESTROY_VECTOR_AND_ELEMENTS(allocator, env->sigs, - interpreter_func_signature); - WABT_DESTROY_VECTOR_AND_ELEMENTS(allocator, env->funcs, interpreter_func); - WABT_DESTROY_VECTOR_AND_ELEMENTS(allocator, env->memories, - interpreter_memory); - WABT_DESTROY_VECTOR_AND_ELEMENTS(allocator, env->tables, interpreter_table); - wabt_destroy_interpreter_global_vector(allocator, &env->globals); +void wabt_destroy_interpreter_environment(WabtInterpreterEnvironment* env) { + WABT_DESTROY_VECTOR_AND_ELEMENTS(env->modules, interpreter_module); + WABT_DESTROY_VECTOR_AND_ELEMENTS(env->sigs, interpreter_func_signature); + WABT_DESTROY_VECTOR_AND_ELEMENTS(env->funcs, interpreter_func); + WABT_DESTROY_VECTOR_AND_ELEMENTS(env->memories, interpreter_memory); + WABT_DESTROY_VECTOR_AND_ELEMENTS(env->tables, interpreter_table); + wabt_destroy_interpreter_global_vector(&env->globals); wabt_destroy_output_buffer(&env->istream); - wabt_destroy_binding_hash(allocator, &env->module_bindings); - wabt_destroy_binding_hash(allocator, &env->registered_module_bindings); + wabt_destroy_binding_hash(&env->module_bindings); + wabt_destroy_binding_hash(&env->registered_module_bindings); } WabtInterpreterEnvironmentMark wabt_mark_interpreter_environment( @@ -128,24 +112,23 @@ WabtInterpreterEnvironmentMark wabt_mark_interpreter_environment( } void wabt_reset_interpreter_environment_to_mark( - WabtAllocator* allocator, WabtInterpreterEnvironment* env, WabtInterpreterEnvironmentMark mark) { size_t i; -#define DESTROY_PAST_MARK(destroy_name, names) \ - do { \ - assert(mark.names##_size <= env->names.size); \ - for (i = mark.names##_size; i < env->names.size; ++i) \ - wabt_destroy_interpreter_##destroy_name(allocator, &env->names.data[i]); \ - env->names.size = mark.names##_size; \ +#define DESTROY_PAST_MARK(destroy_name, names) \ + do { \ + assert(mark.names##_size <= env->names.size); \ + for (i = mark.names##_size; i < env->names.size; ++i) \ + wabt_destroy_interpreter_##destroy_name(&env->names.data[i]); \ + env->names.size = mark.names##_size; \ } while (0) /* Destroy entries in the binding hash. */ for (i = mark.modules_size; i < env->modules.size; ++i) { const WabtStringSlice* name = &env->modules.data[i].name; if (!wabt_string_slice_is_empty(name)) - wabt_remove_binding(allocator, &env->module_bindings, name); + wabt_remove_binding(&env->module_bindings, name); } /* registered_module_bindings maps from an arbitrary name to a module index, @@ -156,7 +139,7 @@ void wabt_reset_interpreter_environment_to_mark( &env->registered_module_bindings.entries.data[i]; if (!wabt_hash_entry_is_free(entry) && entry->binding.index >= (int)mark.modules_size) { - wabt_remove_binding(allocator, &env->registered_module_bindings, + wabt_remove_binding(&env->registered_module_bindings, &entry->binding.name); } } @@ -172,33 +155,28 @@ void wabt_reset_interpreter_environment_to_mark( #undef DESTROY_PAST_MARK } -WabtInterpreterModule* wabt_append_host_module(WabtAllocator* allocator, - WabtInterpreterEnvironment* env, +WabtInterpreterModule* wabt_append_host_module(WabtInterpreterEnvironment* env, WabtStringSlice name) { - WabtInterpreterModule* module = - wabt_append_interpreter_module(allocator, &env->modules); - module->name = wabt_dup_string_slice(allocator, name); + WabtInterpreterModule* module = wabt_append_interpreter_module(&env->modules); + module->name = wabt_dup_string_slice(name); module->memory_index = WABT_INVALID_INDEX; module->table_index = WABT_INVALID_INDEX; module->is_host = WABT_TRUE; - WabtStringSlice dup_name = wabt_dup_string_slice(allocator, name); - WabtBinding* binding = wabt_insert_binding( - allocator, &env->registered_module_bindings, &dup_name); + WabtStringSlice dup_name = wabt_dup_string_slice(name); + WabtBinding* binding = + wabt_insert_binding(&env->registered_module_bindings, &dup_name); binding->index = env->modules.size - 1; return module; } -void wabt_init_interpreter_thread(WabtAllocator* allocator, - WabtInterpreterEnvironment* env, +void wabt_init_interpreter_thread(WabtInterpreterEnvironment* env, WabtInterpreterThread* thread, WabtInterpreterThreadOptions* options) { WABT_ZERO_MEMORY(*thread); - wabt_new_interpreter_value_array(allocator, &thread->value_stack, + wabt_new_interpreter_value_array(&thread->value_stack, options->value_stack_size); - wabt_new_uint32_array(allocator, &thread->call_stack, - options->call_stack_size); - thread->allocator = allocator; + wabt_new_uint32_array(&thread->call_stack, options->call_stack_size); thread->env = env; thread->value_stack_top = thread->value_stack.data; thread->value_stack_end = thread->value_stack.data + thread->value_stack.size; @@ -226,11 +204,10 @@ WabtInterpreterExport* wabt_get_interpreter_export_by_name( return &module->exports.data[field_index]; } -void wabt_destroy_interpreter_thread(WabtAllocator* allocator, - WabtInterpreterThread* thread) { - wabt_destroy_interpreter_value_array(allocator, &thread->value_stack); - wabt_destroy_uint32_array(allocator, &thread->call_stack); - wabt_destroy_interpreter_typed_value_vector(allocator, &thread->host_args); +void wabt_destroy_interpreter_thread(WabtInterpreterThread* thread) { + wabt_destroy_interpreter_value_array(&thread->value_stack); + wabt_destroy_uint32_array(&thread->call_stack); + wabt_destroy_interpreter_typed_value_vector(&thread->host_args); } /* 3 32222222 222...00 @@ -756,8 +733,7 @@ WabtInterpreterResult wabt_call_host(WabtInterpreterThread* thread, uint32_t num_args = sig->param_types.size; if (thread->host_args.size < num_args) { - wabt_resize_interpreter_typed_value_vector(thread->allocator, - &thread->host_args, num_args); + wabt_resize_interpreter_typed_value_vector(&thread->host_args, num_args); } uint32_t i; @@ -1042,9 +1018,7 @@ WabtInterpreterResult wabt_run_interpreter(WabtInterpreterThread* thread, PUSH_NEG_1_AND_BREAK_IF((uint64_t)new_page_size * WABT_PAGE_SIZE > UINT32_MAX); uint32_t new_byte_size = new_page_size * WABT_PAGE_SIZE; - WabtAllocator* allocator = memory->allocator; - void* new_data = wabt_realloc(allocator, memory->data, new_byte_size, - WABT_DEFAULT_ALIGN); + void* new_data = wabt_realloc(memory->data, new_byte_size); PUSH_NEG_1_AND_BREAK_IF(new_data == NULL); memset((void*)((intptr_t)new_data + old_byte_size), 0, new_byte_size - old_byte_size); diff --git a/src/interpreter.h b/src/interpreter.h index 0c0dde2a..71c2cec3 100644 --- a/src/interpreter.h +++ b/src/interpreter.h @@ -105,7 +105,6 @@ typedef struct WabtInterpreterTable { WABT_DEFINE_VECTOR(interpreter_table, WabtInterpreterTable); typedef struct WabtInterpreterMemory { - WabtAllocator* allocator; void* data; WabtLimits page_limits; uint32_t byte_size; /* Cached from page_limits. */ @@ -261,7 +260,6 @@ typedef struct WabtInterpreterEnvironment { } WabtInterpreterEnvironment; typedef struct WabtInterpreterThread { - WabtAllocator* allocator; WabtInterpreterEnvironment* env; WabtInterpreterValueArray value_stack; WabtUint32Array call_stack; @@ -291,27 +289,21 @@ WabtBool wabt_func_signatures_are_equal(WabtInterpreterEnvironment* env, uint32_t sig_index_0, uint32_t sig_index_1); -void wabt_init_interpreter_environment(WabtAllocator* allocator, - WabtInterpreterEnvironment* env); -void wabt_destroy_interpreter_environment(WabtAllocator* allocator, - WabtInterpreterEnvironment* env); +void wabt_init_interpreter_environment(WabtInterpreterEnvironment* env); +void wabt_destroy_interpreter_environment(WabtInterpreterEnvironment* env); WabtInterpreterEnvironmentMark wabt_mark_interpreter_environment( WabtInterpreterEnvironment* env); void wabt_reset_interpreter_environment_to_mark( - WabtAllocator* allocator, WabtInterpreterEnvironment* env, WabtInterpreterEnvironmentMark mark); -WabtInterpreterModule* wabt_append_host_module(WabtAllocator* allocator, - WabtInterpreterEnvironment* env, +WabtInterpreterModule* wabt_append_host_module(WabtInterpreterEnvironment* env, WabtStringSlice name); -void wabt_init_interpreter_thread(WabtAllocator* allocator, - WabtInterpreterEnvironment* env, +void wabt_init_interpreter_thread(WabtInterpreterEnvironment* env, WabtInterpreterThread* thread, WabtInterpreterThreadOptions* options); WabtInterpreterResult wabt_push_thread_value(WabtInterpreterThread* thread, WabtInterpreterValue value); -void wabt_destroy_interpreter_thread(WabtAllocator* allocator, - WabtInterpreterThread* thread); +void wabt_destroy_interpreter_thread(WabtInterpreterThread* thread); WabtInterpreterResult wabt_call_host(WabtInterpreterThread* thread, WabtInterpreterFunc* func); WabtInterpreterResult wabt_run_interpreter(WabtInterpreterThread* thread, diff --git a/src/prebuilt/ast-lexer-gen.c b/src/prebuilt/ast-lexer-gen.c index 7fa80aa3..e6e20c8e 100644 --- a/src/prebuilt/ast-lexer-gen.c +++ b/src/prebuilt/ast-lexer-gen.c @@ -23,7 +23,6 @@ #include "config.h" -#include "allocator.h" #include "ast-parser.h" #include "ast-parser-lexer-shared.h" #include "vector.h" @@ -116,8 +115,7 @@ static WabtResult fill(WabtLocation* loc, /* TODO(binji): could just alloc instead, because we know we'll need to * memmove below */ - char* new_buffer = wabt_realloc(lexer->allocator, lexer->buffer, - new_buffer_size, WABT_DEFAULT_ALIGN); + char* new_buffer = wabt_realloc(lexer->buffer, new_buffer_size); if (new_buffer == NULL) { wabt_ast_parser_error(loc, lexer, parser, "unable to reallocate lexer buffer."); @@ -183,7 +181,7 @@ int wabt_ast_lexer_lex(WABT_AST_PARSER_STYPE* lval, for (;;) { lexer->token = lexer->cursor; -#line 187 "src/prebuilt/ast-lexer-gen.c" +#line 185 "src/prebuilt/ast-lexer-gen.c" { unsigned char yych; if (cond < 2) { @@ -222,32 +220,32 @@ YYCOND_BAD_TEXT: } } ++lexer->cursor; -#line 235 "src/ast-lexer.c" +#line 233 "src/ast-lexer.c" { ERROR("unexpected EOF"); RETURN(EOF); } -#line 228 "src/prebuilt/ast-lexer-gen.c" +#line 226 "src/prebuilt/ast-lexer-gen.c" yy5: ++lexer->cursor; yy6: -#line 236 "src/ast-lexer.c" +#line 234 "src/ast-lexer.c" { ERROR("illegal character in string"); continue; } -#line 234 "src/prebuilt/ast-lexer-gen.c" +#line 232 "src/prebuilt/ast-lexer-gen.c" yy7: ++lexer->cursor; BEGIN(YYCOND_i); -#line 231 "src/ast-lexer.c" +#line 229 "src/ast-lexer.c" { ERROR("newline in string"); NEWLINE; continue; } -#line 240 "src/prebuilt/ast-lexer-gen.c" +#line 238 "src/prebuilt/ast-lexer-gen.c" yy9: ++lexer->cursor; -#line 230 "src/ast-lexer.c" +#line 228 "src/ast-lexer.c" { continue; } -#line 245 "src/prebuilt/ast-lexer-gen.c" +#line 243 "src/prebuilt/ast-lexer-gen.c" yy11: ++lexer->cursor; BEGIN(YYCOND_i); -#line 234 "src/ast-lexer.c" +#line 232 "src/ast-lexer.c" { TEXT; RETURN(TEXT); } -#line 251 "src/prebuilt/ast-lexer-gen.c" +#line 249 "src/prebuilt/ast-lexer-gen.c" yy13: yych = *++lexer->cursor; if (yych <= '@') { @@ -281,10 +279,10 @@ yy13: yy14: ++lexer->cursor; yy15: -#line 232 "src/ast-lexer.c" +#line 230 "src/ast-lexer.c" { ERROR("bad escape \"%.*s\"", (int)yyleng, yytext); continue; } -#line 288 "src/prebuilt/ast-lexer-gen.c" +#line 286 "src/prebuilt/ast-lexer-gen.c" yy16: ++lexer->cursor; if ((yych = *lexer->cursor) <= '@') { @@ -312,20 +310,20 @@ YYCOND_BLOCK_COMMENT: } yy19: ++lexer->cursor; -#line 458 "src/ast-lexer.c" +#line 456 "src/ast-lexer.c" { ERROR("unexpected EOF"); RETURN(EOF); } -#line 318 "src/prebuilt/ast-lexer-gen.c" +#line 316 "src/prebuilt/ast-lexer-gen.c" yy21: ++lexer->cursor; yy22: -#line 459 "src/ast-lexer.c" +#line 457 "src/ast-lexer.c" { continue; } -#line 324 "src/prebuilt/ast-lexer-gen.c" +#line 322 "src/prebuilt/ast-lexer-gen.c" yy23: ++lexer->cursor; -#line 457 "src/ast-lexer.c" +#line 455 "src/ast-lexer.c" { NEWLINE; continue; } -#line 329 "src/prebuilt/ast-lexer-gen.c" +#line 327 "src/prebuilt/ast-lexer-gen.c" yy25: yych = *++lexer->cursor; if (yych == ';') goto yy27; @@ -336,16 +334,16 @@ yy26: goto yy22; yy27: ++lexer->cursor; -#line 453 "src/ast-lexer.c" +#line 451 "src/ast-lexer.c" { COMMENT_NESTING++; continue; } -#line 342 "src/prebuilt/ast-lexer-gen.c" +#line 340 "src/prebuilt/ast-lexer-gen.c" yy29: ++lexer->cursor; -#line 454 "src/ast-lexer.c" +#line 452 "src/ast-lexer.c" { if (--COMMENT_NESTING == 0) BEGIN(YYCOND_INIT); continue; } -#line 349 "src/prebuilt/ast-lexer-gen.c" +#line 347 "src/prebuilt/ast-lexer-gen.c" /* *********************************** */ YYCOND_LINE_COMMENT: { @@ -390,9 +388,9 @@ YYCOND_LINE_COMMENT: } goto yy36; yy33: -#line 451 "src/ast-lexer.c" +#line 449 "src/ast-lexer.c" { continue; } -#line 396 "src/prebuilt/ast-lexer-gen.c" +#line 394 "src/prebuilt/ast-lexer-gen.c" yy34: ++lexer->cursor; if (lexer->limit <= lexer->cursor) FILL(1); @@ -404,9 +402,9 @@ yy34: yy36: ++lexer->cursor; BEGIN(YYCOND_i); -#line 450 "src/ast-lexer.c" +#line 448 "src/ast-lexer.c" { NEWLINE; continue; } -#line 410 "src/prebuilt/ast-lexer-gen.c" +#line 408 "src/prebuilt/ast-lexer-gen.c" } /* *********************************** */ YYCOND_i: @@ -548,15 +546,15 @@ YYCOND_i: } yy40: ++lexer->cursor; -#line 465 "src/ast-lexer.c" +#line 463 "src/ast-lexer.c" { RETURN(EOF); } -#line 554 "src/prebuilt/ast-lexer-gen.c" +#line 552 "src/prebuilt/ast-lexer-gen.c" yy42: ++lexer->cursor; yy43: -#line 466 "src/ast-lexer.c" +#line 464 "src/ast-lexer.c" { ERROR("unexpected char"); continue; } -#line 560 "src/prebuilt/ast-lexer-gen.c" +#line 558 "src/prebuilt/ast-lexer-gen.c" yy44: ++lexer->cursor; if (lexer->limit <= lexer->cursor) FILL(1); @@ -564,14 +562,14 @@ yy44: if (yybm[0+yych] & 8) { goto yy44; } -#line 461 "src/ast-lexer.c" +#line 459 "src/ast-lexer.c" { continue; } -#line 570 "src/prebuilt/ast-lexer-gen.c" +#line 568 "src/prebuilt/ast-lexer-gen.c" yy47: ++lexer->cursor; -#line 460 "src/ast-lexer.c" +#line 458 "src/ast-lexer.c" { NEWLINE; continue; } -#line 575 "src/prebuilt/ast-lexer-gen.c" +#line 573 "src/prebuilt/ast-lexer-gen.c" yy49: ++lexer->cursor; if (lexer->limit <= lexer->cursor) FILL(1); @@ -581,20 +579,20 @@ yy50: goto yy49; } yy51: -#line 462 "src/ast-lexer.c" +#line 460 "src/ast-lexer.c" { ERROR("unexpected token \"%.*s\"", (int)yyleng, yytext); continue; } -#line 589 "src/prebuilt/ast-lexer-gen.c" +#line 587 "src/prebuilt/ast-lexer-gen.c" yy52: yych = *(lexer->marker = ++lexer->cursor); if (yych <= 0x1F) goto yy53; if (yych != 0x7F) goto yy83; yy53: BEGIN(YYCOND_BAD_TEXT); -#line 229 "src/ast-lexer.c" +#line 227 "src/ast-lexer.c" { continue; } -#line 598 "src/prebuilt/ast-lexer-gen.c" +#line 596 "src/prebuilt/ast-lexer-gen.c" yy54: yych = *++lexer->cursor; if (yych <= ';') { @@ -634,14 +632,14 @@ yy54: yy55: ++lexer->cursor; if ((yych = *lexer->cursor) == ';') goto yy91; -#line 220 "src/ast-lexer.c" +#line 218 "src/ast-lexer.c" { RETURN(LPAR); } -#line 640 "src/prebuilt/ast-lexer-gen.c" +#line 638 "src/prebuilt/ast-lexer-gen.c" yy57: ++lexer->cursor; -#line 221 "src/ast-lexer.c" +#line 219 "src/ast-lexer.c" { RETURN(RPAR); } -#line 645 "src/prebuilt/ast-lexer-gen.c" +#line 643 "src/prebuilt/ast-lexer-gen.c" yy59: yych = *++lexer->cursor; if (yych <= 'h') { @@ -698,9 +696,9 @@ yy60: } } yy61: -#line 222 "src/ast-lexer.c" +#line 220 "src/ast-lexer.c" { LITERAL(INT); RETURN(NAT); } -#line 704 "src/prebuilt/ast-lexer-gen.c" +#line 702 "src/prebuilt/ast-lexer-gen.c" yy62: ++lexer->cursor; if ((lexer->limit - lexer->cursor) < 3) FILL(3); @@ -901,9 +899,9 @@ yy84: goto yy53; yy85: ++lexer->cursor; -#line 228 "src/ast-lexer.c" +#line 226 "src/ast-lexer.c" { TEXT; RETURN(TEXT); } -#line 907 "src/prebuilt/ast-lexer-gen.c" +#line 905 "src/prebuilt/ast-lexer-gen.c" yy87: ++lexer->cursor; if (lexer->limit <= lexer->cursor) FILL(1); @@ -966,15 +964,15 @@ yy88: } } yy90: -#line 447 "src/ast-lexer.c" +#line 445 "src/ast-lexer.c" { TEXT; RETURN(VAR); } -#line 972 "src/prebuilt/ast-lexer-gen.c" +#line 970 "src/prebuilt/ast-lexer-gen.c" yy91: ++lexer->cursor; BEGIN(YYCOND_BLOCK_COMMENT); -#line 452 "src/ast-lexer.c" +#line 450 "src/ast-lexer.c" { COMMENT_NESTING = 1; continue; } -#line 978 "src/prebuilt/ast-lexer-gen.c" +#line 976 "src/prebuilt/ast-lexer-gen.c" yy93: ++lexer->cursor; if ((yych = *lexer->cursor) <= 'D') { @@ -1016,9 +1014,9 @@ yy93: } } yy94: -#line 223 "src/ast-lexer.c" +#line 221 "src/ast-lexer.c" { LITERAL(INT); RETURN(INT); } -#line 1022 "src/prebuilt/ast-lexer-gen.c" +#line 1020 "src/prebuilt/ast-lexer-gen.c" yy95: ++lexer->cursor; if ((lexer->limit - lexer->cursor) < 3) FILL(3); @@ -1115,9 +1113,9 @@ yy99: } } yy101: -#line 224 "src/ast-lexer.c" +#line 222 "src/ast-lexer.c" { LITERAL(FLOAT); RETURN(FLOAT); } -#line 1121 "src/prebuilt/ast-lexer-gen.c" +#line 1119 "src/prebuilt/ast-lexer-gen.c" yy102: yych = *++lexer->cursor; if (yych <= ',') { @@ -1138,9 +1136,9 @@ yy103: yy104: ++lexer->cursor; BEGIN(YYCOND_LINE_COMMENT); -#line 449 "src/ast-lexer.c" +#line 447 "src/ast-lexer.c" { continue; } -#line 1144 "src/prebuilt/ast-lexer-gen.c" +#line 1142 "src/prebuilt/ast-lexer-gen.c" yy106: yych = *++lexer->cursor; if (yych == 'i') goto yy156; @@ -1192,9 +1190,9 @@ yy110: } } yy111: -#line 250 "src/ast-lexer.c" +#line 248 "src/ast-lexer.c" { RETURN(BR); } -#line 1198 "src/prebuilt/ast-lexer-gen.c" +#line 1196 "src/prebuilt/ast-lexer-gen.c" yy112: yych = *++lexer->cursor; if (yych == 'l') goto yy161; @@ -1291,9 +1289,9 @@ yy127: } } yy128: -#line 245 "src/ast-lexer.c" +#line 243 "src/ast-lexer.c" { RETURN(IF); } -#line 1297 "src/prebuilt/ast-lexer-gen.c" +#line 1295 "src/prebuilt/ast-lexer-gen.c" yy129: yych = *++lexer->cursor; if (yych == 'p') goto yy184; @@ -1558,9 +1556,9 @@ yy167: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 257 "src/ast-lexer.c" +#line 255 "src/ast-lexer.c" { RETURN(END); } -#line 1564 "src/prebuilt/ast-lexer-gen.c" +#line 1562 "src/prebuilt/ast-lexer-gen.c" yy169: yych = *++lexer->cursor; if (yych == 'o') goto yy235; @@ -1599,9 +1597,9 @@ yy170: } } yy171: -#line 239 "src/ast-lexer.c" +#line 237 "src/ast-lexer.c" { TYPE(F32); RETURN(VALUE_TYPE); } -#line 1605 "src/prebuilt/ast-lexer-gen.c" +#line 1603 "src/prebuilt/ast-lexer-gen.c" yy172: ++lexer->cursor; if ((yych = *lexer->cursor) <= ':') { @@ -1636,9 +1634,9 @@ yy172: } } yy173: -#line 240 "src/ast-lexer.c" +#line 238 "src/ast-lexer.c" { TYPE(F64); RETURN(VALUE_TYPE); } -#line 1642 "src/prebuilt/ast-lexer-gen.c" +#line 1640 "src/prebuilt/ast-lexer-gen.c" yy174: yych = *++lexer->cursor; if (yych == 'c') goto yy238; @@ -1678,9 +1676,9 @@ yy175: } } yy176: -#line 437 "src/ast-lexer.c" +#line 435 "src/ast-lexer.c" { RETURN(GET); } -#line 1684 "src/prebuilt/ast-lexer-gen.c" +#line 1682 "src/prebuilt/ast-lexer-gen.c" yy177: yych = *++lexer->cursor; if (yych == 'b') goto yy241; @@ -1723,9 +1721,9 @@ yy179: } } yy180: -#line 237 "src/ast-lexer.c" +#line 235 "src/ast-lexer.c" { TYPE(I32); RETURN(VALUE_TYPE); } -#line 1729 "src/prebuilt/ast-lexer-gen.c" +#line 1727 "src/prebuilt/ast-lexer-gen.c" yy181: ++lexer->cursor; if ((yych = *lexer->cursor) <= ':') { @@ -1760,9 +1758,9 @@ yy181: } } yy182: -#line 238 "src/ast-lexer.c" +#line 236 "src/ast-lexer.c" { TYPE(I64); RETURN(VALUE_TYPE); } -#line 1766 "src/prebuilt/ast-lexer-gen.c" +#line 1764 "src/prebuilt/ast-lexer-gen.c" yy183: yych = *++lexer->cursor; if (yych == 'e') goto yy245; @@ -1806,9 +1804,9 @@ yy185: } } yy186: -#line 226 "src/ast-lexer.c" +#line 224 "src/ast-lexer.c" { LITERAL(INFINITY); RETURN(FLOAT); } -#line 1812 "src/prebuilt/ast-lexer-gen.c" +#line 1810 "src/prebuilt/ast-lexer-gen.c" yy187: yych = *++lexer->cursor; if (yych == 'u') goto yy248; @@ -1838,9 +1836,9 @@ yy193: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 242 "src/ast-lexer.c" +#line 240 "src/ast-lexer.c" { RETURN(MUT); } -#line 1844 "src/prebuilt/ast-lexer-gen.c" +#line 1842 "src/prebuilt/ast-lexer-gen.c" yy195: ++lexer->cursor; if ((yych = *lexer->cursor) <= ';') { @@ -1875,17 +1873,17 @@ yy195: } } yy196: -#line 227 "src/ast-lexer.c" +#line 225 "src/ast-lexer.c" { LITERAL(NAN); RETURN(FLOAT); } -#line 1881 "src/prebuilt/ast-lexer-gen.c" +#line 1879 "src/prebuilt/ast-lexer-gen.c" yy197: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 243 "src/ast-lexer.c" +#line 241 "src/ast-lexer.c" { RETURN(NOP); } -#line 1889 "src/prebuilt/ast-lexer-gen.c" +#line 1887 "src/prebuilt/ast-lexer-gen.c" yy199: yych = *++lexer->cursor; if (yych == 's') goto yy256; @@ -2107,9 +2105,9 @@ yy224: } } yy225: -#line 253 "src/ast-lexer.c" +#line 251 "src/ast-lexer.c" { RETURN(CALL); } -#line 2113 "src/prebuilt/ast-lexer-gen.c" +#line 2111 "src/prebuilt/ast-lexer-gen.c" yy226: yych = *++lexer->cursor; if (yych == 'e') goto yy285; @@ -2119,33 +2117,33 @@ yy227: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 431 "src/ast-lexer.c" +#line 429 "src/ast-lexer.c" { RETURN(DATA); } -#line 2125 "src/prebuilt/ast-lexer-gen.c" +#line 2123 "src/prebuilt/ast-lexer-gen.c" yy229: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 256 "src/ast-lexer.c" +#line 254 "src/ast-lexer.c" { RETURN(DROP); } -#line 2133 "src/prebuilt/ast-lexer-gen.c" +#line 2131 "src/prebuilt/ast-lexer-gen.c" yy231: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 430 "src/ast-lexer.c" +#line 428 "src/ast-lexer.c" { RETURN(ELEM); } -#line 2141 "src/prebuilt/ast-lexer-gen.c" +#line 2139 "src/prebuilt/ast-lexer-gen.c" yy233: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 248 "src/ast-lexer.c" +#line 246 "src/ast-lexer.c" { RETURN(ELSE); } -#line 2149 "src/prebuilt/ast-lexer-gen.c" +#line 2147 "src/prebuilt/ast-lexer-gen.c" yy235: yych = *++lexer->cursor; if (yych == 'r') goto yy286; @@ -2190,9 +2188,9 @@ yy238: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 421 "src/ast-lexer.c" +#line 419 "src/ast-lexer.c" { RETURN(FUNC); } -#line 2196 "src/prebuilt/ast-lexer-gen.c" +#line 2194 "src/prebuilt/ast-lexer-gen.c" yy240: yych = *++lexer->cursor; if (yych == 'g') goto yy312; @@ -2274,9 +2272,9 @@ yy251: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 249 "src/ast-lexer.c" +#line 247 "src/ast-lexer.c" { RETURN(LOOP); } -#line 2280 "src/prebuilt/ast-lexer-gen.c" +#line 2278 "src/prebuilt/ast-lexer-gen.c" yy253: yych = *++lexer->cursor; if (yych == 'r') goto yy353; @@ -2339,17 +2337,17 @@ yy267: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 247 "src/ast-lexer.c" +#line 245 "src/ast-lexer.c" { RETURN(THEN); } -#line 2345 "src/prebuilt/ast-lexer-gen.c" +#line 2343 "src/prebuilt/ast-lexer-gen.c" yy269: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 420 "src/ast-lexer.c" +#line 418 "src/ast-lexer.c" { RETURN(TYPE); } -#line 2353 "src/prebuilt/ast-lexer-gen.c" +#line 2351 "src/prebuilt/ast-lexer-gen.c" yy271: yych = *++lexer->cursor; if (yych == 'a') goto yy371; @@ -2395,9 +2393,9 @@ yy273: } } yy275: -#line 225 "src/ast-lexer.c" +#line 223 "src/ast-lexer.c" { LITERAL(HEXFLOAT); RETURN(FLOAT); } -#line 2401 "src/prebuilt/ast-lexer-gen.c" +#line 2399 "src/prebuilt/ast-lexer-gen.c" yy276: yych = *++lexer->cursor; if (yych == '=') goto yy372; @@ -2415,17 +2413,17 @@ yy279: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 244 "src/ast-lexer.c" +#line 242 "src/ast-lexer.c" { RETURN(BLOCK); } -#line 2421 "src/prebuilt/ast-lexer-gen.c" +#line 2419 "src/prebuilt/ast-lexer-gen.c" yy281: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 251 "src/ast-lexer.c" +#line 249 "src/ast-lexer.c" { RETURN(BR_IF); } -#line 2429 "src/prebuilt/ast-lexer-gen.c" +#line 2427 "src/prebuilt/ast-lexer-gen.c" yy283: yych = *++lexer->cursor; if (yych == 'b') goto yy375; @@ -2777,9 +2775,9 @@ yy348: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 445 "src/ast-lexer.c" +#line 443 "src/ast-lexer.c" { RETURN(INPUT); } -#line 2783 "src/prebuilt/ast-lexer-gen.c" +#line 2781 "src/prebuilt/ast-lexer-gen.c" yy350: yych = *++lexer->cursor; if (yych == 'e') goto yy499; @@ -2789,9 +2787,9 @@ yy351: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 424 "src/ast-lexer.c" +#line 422 "src/ast-lexer.c" { RETURN(LOCAL); } -#line 2795 "src/prebuilt/ast-lexer-gen.c" +#line 2793 "src/prebuilt/ast-lexer-gen.c" yy353: yych = *++lexer->cursor; if (yych == 'y') goto yy501; @@ -2817,9 +2815,9 @@ yy358: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 422 "src/ast-lexer.c" +#line 420 "src/ast-lexer.c" { RETURN(PARAM); } -#line 2823 "src/prebuilt/ast-lexer-gen.c" +#line 2821 "src/prebuilt/ast-lexer-gen.c" yy360: yych = *++lexer->cursor; if (yych == 't') goto yy510; @@ -2849,17 +2847,17 @@ yy366: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 429 "src/ast-lexer.c" +#line 427 "src/ast-lexer.c" { RETURN(START); } -#line 2855 "src/prebuilt/ast-lexer-gen.c" +#line 2853 "src/prebuilt/ast-lexer-gen.c" yy368: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 427 "src/ast-lexer.c" +#line 425 "src/ast-lexer.c" { RETURN(TABLE); } -#line 2863 "src/prebuilt/ast-lexer-gen.c" +#line 2861 "src/prebuilt/ast-lexer-gen.c" yy370: yych = *++lexer->cursor; if (yych == 'o') goto yy519; @@ -2901,9 +2899,9 @@ yy378: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 434 "src/ast-lexer.c" +#line 432 "src/ast-lexer.c" { RETURN(EXPORT); } -#line 2907 "src/prebuilt/ast-lexer-gen.c" +#line 2905 "src/prebuilt/ast-lexer-gen.c" yy380: yych = *++lexer->cursor; if (yych == 's') goto yy532; @@ -2934,9 +2932,9 @@ yy386: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 379 "src/ast-lexer.c" +#line 377 "src/ast-lexer.c" { OPCODE(F32_EQ); RETURN(COMPARE); } -#line 2940 "src/prebuilt/ast-lexer-gen.c" +#line 2938 "src/prebuilt/ast-lexer-gen.c" yy388: yych = *++lexer->cursor; if (yych == 'o') goto yy542; @@ -2946,25 +2944,25 @@ yy389: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 389 "src/ast-lexer.c" +#line 387 "src/ast-lexer.c" { OPCODE(F32_GE); RETURN(COMPARE); } -#line 2952 "src/prebuilt/ast-lexer-gen.c" +#line 2950 "src/prebuilt/ast-lexer-gen.c" yy391: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 387 "src/ast-lexer.c" +#line 385 "src/ast-lexer.c" { OPCODE(F32_GT); RETURN(COMPARE); } -#line 2960 "src/prebuilt/ast-lexer-gen.c" +#line 2958 "src/prebuilt/ast-lexer-gen.c" yy393: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 385 "src/ast-lexer.c" +#line 383 "src/ast-lexer.c" { OPCODE(F32_LE); RETURN(COMPARE); } -#line 2968 "src/prebuilt/ast-lexer-gen.c" +#line 2966 "src/prebuilt/ast-lexer-gen.c" yy395: yych = *++lexer->cursor; if (yych == 'a') goto yy543; @@ -2974,9 +2972,9 @@ yy396: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 383 "src/ast-lexer.c" +#line 381 "src/ast-lexer.c" { OPCODE(F32_LT); RETURN(COMPARE); } -#line 2980 "src/prebuilt/ast-lexer-gen.c" +#line 2978 "src/prebuilt/ast-lexer-gen.c" yy398: yych = *++lexer->cursor; if (yych == 'x') goto yy544; @@ -3025,9 +3023,9 @@ yy401: } } yy402: -#line 381 "src/ast-lexer.c" +#line 379 "src/ast-lexer.c" { OPCODE(F32_NE); RETURN(COMPARE); } -#line 3031 "src/prebuilt/ast-lexer-gen.c" +#line 3029 "src/prebuilt/ast-lexer-gen.c" yy403: yych = *++lexer->cursor; if (yych == 'i') goto yy553; @@ -3074,9 +3072,9 @@ yy413: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 380 "src/ast-lexer.c" +#line 378 "src/ast-lexer.c" { OPCODE(F64_EQ); RETURN(COMPARE); } -#line 3080 "src/prebuilt/ast-lexer-gen.c" +#line 3078 "src/prebuilt/ast-lexer-gen.c" yy415: yych = *++lexer->cursor; if (yych == 'o') goto yy568; @@ -3086,25 +3084,25 @@ yy416: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 390 "src/ast-lexer.c" +#line 388 "src/ast-lexer.c" { OPCODE(F64_GE); RETURN(COMPARE); } -#line 3092 "src/prebuilt/ast-lexer-gen.c" +#line 3090 "src/prebuilt/ast-lexer-gen.c" yy418: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 388 "src/ast-lexer.c" +#line 386 "src/ast-lexer.c" { OPCODE(F64_GT); RETURN(COMPARE); } -#line 3100 "src/prebuilt/ast-lexer-gen.c" +#line 3098 "src/prebuilt/ast-lexer-gen.c" yy420: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 386 "src/ast-lexer.c" +#line 384 "src/ast-lexer.c" { OPCODE(F64_LE); RETURN(COMPARE); } -#line 3108 "src/prebuilt/ast-lexer-gen.c" +#line 3106 "src/prebuilt/ast-lexer-gen.c" yy422: yych = *++lexer->cursor; if (yych == 'a') goto yy569; @@ -3114,9 +3112,9 @@ yy423: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 384 "src/ast-lexer.c" +#line 382 "src/ast-lexer.c" { OPCODE(F64_LT); RETURN(COMPARE); } -#line 3120 "src/prebuilt/ast-lexer-gen.c" +#line 3118 "src/prebuilt/ast-lexer-gen.c" yy425: yych = *++lexer->cursor; if (yych == 'x') goto yy570; @@ -3165,9 +3163,9 @@ yy428: } } yy429: -#line 382 "src/ast-lexer.c" +#line 380 "src/ast-lexer.c" { OPCODE(F64_NE); RETURN(COMPARE); } -#line 3171 "src/prebuilt/ast-lexer-gen.c" +#line 3169 "src/prebuilt/ast-lexer-gen.c" yy430: yych = *++lexer->cursor; if (yych == 'o') goto yy579; @@ -3205,9 +3203,9 @@ yy438: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 425 "src/ast-lexer.c" +#line 423 "src/ast-lexer.c" { RETURN(GLOBAL); } -#line 3211 "src/prebuilt/ast-lexer-gen.c" +#line 3209 "src/prebuilt/ast-lexer-gen.c" yy440: yych = *++lexer->cursor; if (yych == 'e') goto yy588; @@ -3271,9 +3269,9 @@ yy447: } } yy448: -#line 359 "src/ast-lexer.c" +#line 357 "src/ast-lexer.c" { OPCODE(I32_EQ); RETURN(COMPARE); } -#line 3277 "src/prebuilt/ast-lexer-gen.c" +#line 3275 "src/prebuilt/ast-lexer-gen.c" yy449: yych = *++lexer->cursor; if (yych == '_') goto yy601; @@ -3303,17 +3301,17 @@ yy455: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 361 "src/ast-lexer.c" +#line 359 "src/ast-lexer.c" { OPCODE(I32_NE); RETURN(COMPARE); } -#line 3309 "src/prebuilt/ast-lexer-gen.c" +#line 3307 "src/prebuilt/ast-lexer-gen.c" yy457: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 331 "src/ast-lexer.c" +#line 329 "src/ast-lexer.c" { OPCODE(I32_OR); RETURN(BINARY); } -#line 3317 "src/prebuilt/ast-lexer-gen.c" +#line 3315 "src/prebuilt/ast-lexer-gen.c" yy459: yych = *++lexer->cursor; if (yych == 'p') goto yy608; @@ -3411,9 +3409,9 @@ yy474: } } yy475: -#line 360 "src/ast-lexer.c" +#line 358 "src/ast-lexer.c" { OPCODE(I64_EQ); RETURN(COMPARE); } -#line 3417 "src/prebuilt/ast-lexer-gen.c" +#line 3415 "src/prebuilt/ast-lexer-gen.c" yy476: yych = *++lexer->cursor; if (yych == 't') goto yy634; @@ -3447,17 +3445,17 @@ yy483: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 362 "src/ast-lexer.c" +#line 360 "src/ast-lexer.c" { OPCODE(I64_NE); RETURN(COMPARE); } -#line 3453 "src/prebuilt/ast-lexer-gen.c" +#line 3451 "src/prebuilt/ast-lexer-gen.c" yy485: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 332 "src/ast-lexer.c" +#line 330 "src/ast-lexer.c" { OPCODE(I64_OR); RETURN(BINARY); } -#line 3461 "src/prebuilt/ast-lexer-gen.c" +#line 3459 "src/prebuilt/ast-lexer-gen.c" yy487: yych = *++lexer->cursor; if (yych == 'p') goto yy642; @@ -3501,9 +3499,9 @@ yy496: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 433 "src/ast-lexer.c" +#line 431 "src/ast-lexer.c" { RETURN(IMPORT); } -#line 3507 "src/prebuilt/ast-lexer-gen.c" +#line 3505 "src/prebuilt/ast-lexer-gen.c" yy498: yych = *++lexer->cursor; if (yych == 't') goto yy657; @@ -3513,25 +3511,25 @@ yy499: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 436 "src/ast-lexer.c" +#line 434 "src/ast-lexer.c" { RETURN(INVOKE); } -#line 3519 "src/prebuilt/ast-lexer-gen.c" +#line 3517 "src/prebuilt/ast-lexer-gen.c" yy501: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 428 "src/ast-lexer.c" +#line 426 "src/ast-lexer.c" { RETURN(MEMORY); } -#line 3527 "src/prebuilt/ast-lexer-gen.c" +#line 3525 "src/prebuilt/ast-lexer-gen.c" yy503: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 426 "src/ast-lexer.c" +#line 424 "src/ast-lexer.c" { RETURN(MODULE); } -#line 3535 "src/prebuilt/ast-lexer-gen.c" +#line 3533 "src/prebuilt/ast-lexer-gen.c" yy505: yych = *++lexer->cursor; if (yych <= '@') { @@ -3578,17 +3576,17 @@ yy506: } } yy507: -#line 432 "src/ast-lexer.c" +#line 430 "src/ast-lexer.c" { RETURN(OFFSET); } -#line 3584 "src/prebuilt/ast-lexer-gen.c" +#line 3582 "src/prebuilt/ast-lexer-gen.c" yy508: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 446 "src/ast-lexer.c" +#line 444 "src/ast-lexer.c" { RETURN(OUTPUT); } -#line 3592 "src/prebuilt/ast-lexer-gen.c" +#line 3590 "src/prebuilt/ast-lexer-gen.c" yy510: yych = *++lexer->cursor; if (yych == 'e') goto yy661; @@ -3598,25 +3596,25 @@ yy511: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 423 "src/ast-lexer.c" +#line 421 "src/ast-lexer.c" { RETURN(RESULT); } -#line 3604 "src/prebuilt/ast-lexer-gen.c" +#line 3602 "src/prebuilt/ast-lexer-gen.c" yy513: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 258 "src/ast-lexer.c" +#line 256 "src/ast-lexer.c" { RETURN(RETURN); } -#line 3612 "src/prebuilt/ast-lexer-gen.c" +#line 3610 "src/prebuilt/ast-lexer-gen.c" yy515: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 416 "src/ast-lexer.c" +#line 414 "src/ast-lexer.c" { RETURN(SELECT); } -#line 3620 "src/prebuilt/ast-lexer-gen.c" +#line 3618 "src/prebuilt/ast-lexer-gen.c" yy517: yych = *++lexer->cursor; if (yych == 'o') goto yy662; @@ -3669,9 +3667,9 @@ yy521: } } yy522: -#line 288 "src/ast-lexer.c" +#line 286 "src/ast-lexer.c" { TEXT_AT(6); RETURN(ALIGN_EQ_NAT); } -#line 3675 "src/prebuilt/ast-lexer-gen.c" +#line 3673 "src/prebuilt/ast-lexer-gen.c" yy523: ++lexer->cursor; if (lexer->limit <= lexer->cursor) FILL(1); @@ -3720,9 +3718,9 @@ yy525: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 241 "src/ast-lexer.c" +#line 239 "src/ast-lexer.c" { RETURN(ANYFUNC); } -#line 3726 "src/prebuilt/ast-lexer-gen.c" +#line 3724 "src/prebuilt/ast-lexer-gen.c" yy527: yych = *++lexer->cursor; switch (yych) { @@ -3755,17 +3753,17 @@ yy532: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 303 "src/ast-lexer.c" +#line 301 "src/ast-lexer.c" { OPCODE(F32_ABS); RETURN(UNARY); } -#line 3761 "src/prebuilt/ast-lexer-gen.c" +#line 3759 "src/prebuilt/ast-lexer-gen.c" yy534: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 345 "src/ast-lexer.c" +#line 343 "src/ast-lexer.c" { OPCODE(F32_ADD); RETURN(BINARY); } -#line 3769 "src/prebuilt/ast-lexer-gen.c" +#line 3767 "src/prebuilt/ast-lexer-gen.c" yy536: yych = *++lexer->cursor; if (yych == 'l') goto yy678; @@ -3788,9 +3786,9 @@ yy540: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 351 "src/ast-lexer.c" +#line 349 "src/ast-lexer.c" { OPCODE(F32_DIV); RETURN(BINARY); } -#line 3794 "src/prebuilt/ast-lexer-gen.c" +#line 3792 "src/prebuilt/ast-lexer-gen.c" yy542: yych = *++lexer->cursor; if (yych == 'o') goto yy684; @@ -3804,25 +3802,25 @@ yy544: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 355 "src/ast-lexer.c" +#line 353 "src/ast-lexer.c" { OPCODE(F32_MAX); RETURN(BINARY); } -#line 3810 "src/prebuilt/ast-lexer-gen.c" +#line 3808 "src/prebuilt/ast-lexer-gen.c" yy546: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 353 "src/ast-lexer.c" +#line 351 "src/ast-lexer.c" { OPCODE(F32_MIN); RETURN(BINARY); } -#line 3818 "src/prebuilt/ast-lexer-gen.c" +#line 3816 "src/prebuilt/ast-lexer-gen.c" yy548: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 349 "src/ast-lexer.c" +#line 347 "src/ast-lexer.c" { OPCODE(F32_MUL); RETURN(BINARY); } -#line 3826 "src/prebuilt/ast-lexer-gen.c" +#line 3824 "src/prebuilt/ast-lexer-gen.c" yy550: yych = *++lexer->cursor; if (yych == 'r') goto yy687; @@ -3832,9 +3830,9 @@ yy551: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 301 "src/ast-lexer.c" +#line 299 "src/ast-lexer.c" { OPCODE(F32_NEG); RETURN(UNARY); } -#line 3838 "src/prebuilt/ast-lexer-gen.c" +#line 3836 "src/prebuilt/ast-lexer-gen.c" yy553: yych = *++lexer->cursor; if (yych == 'n') goto yy688; @@ -3852,9 +3850,9 @@ yy556: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 347 "src/ast-lexer.c" +#line 345 "src/ast-lexer.c" { OPCODE(F32_SUB); RETURN(BINARY); } -#line 3858 "src/prebuilt/ast-lexer-gen.c" +#line 3856 "src/prebuilt/ast-lexer-gen.c" yy558: yych = *++lexer->cursor; if (yych == 'n') goto yy692; @@ -3864,17 +3862,17 @@ yy559: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 304 "src/ast-lexer.c" +#line 302 "src/ast-lexer.c" { OPCODE(F64_ABS); RETURN(UNARY); } -#line 3870 "src/prebuilt/ast-lexer-gen.c" +#line 3868 "src/prebuilt/ast-lexer-gen.c" yy561: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 346 "src/ast-lexer.c" +#line 344 "src/ast-lexer.c" { OPCODE(F64_ADD); RETURN(BINARY); } -#line 3878 "src/prebuilt/ast-lexer-gen.c" +#line 3876 "src/prebuilt/ast-lexer-gen.c" yy563: yych = *++lexer->cursor; if (yych == 'l') goto yy693; @@ -3893,9 +3891,9 @@ yy566: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 352 "src/ast-lexer.c" +#line 350 "src/ast-lexer.c" { OPCODE(F64_DIV); RETURN(BINARY); } -#line 3899 "src/prebuilt/ast-lexer-gen.c" +#line 3897 "src/prebuilt/ast-lexer-gen.c" yy568: yych = *++lexer->cursor; if (yych == 'o') goto yy698; @@ -3909,25 +3907,25 @@ yy570: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 356 "src/ast-lexer.c" +#line 354 "src/ast-lexer.c" { OPCODE(F64_MAX); RETURN(BINARY); } -#line 3915 "src/prebuilt/ast-lexer-gen.c" +#line 3913 "src/prebuilt/ast-lexer-gen.c" yy572: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 354 "src/ast-lexer.c" +#line 352 "src/ast-lexer.c" { OPCODE(F64_MIN); RETURN(BINARY); } -#line 3923 "src/prebuilt/ast-lexer-gen.c" +#line 3921 "src/prebuilt/ast-lexer-gen.c" yy574: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 350 "src/ast-lexer.c" +#line 348 "src/ast-lexer.c" { OPCODE(F64_MUL); RETURN(BINARY); } -#line 3931 "src/prebuilt/ast-lexer-gen.c" +#line 3929 "src/prebuilt/ast-lexer-gen.c" yy576: yych = *++lexer->cursor; if (yych == 'r') goto yy701; @@ -3937,9 +3935,9 @@ yy577: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 302 "src/ast-lexer.c" +#line 300 "src/ast-lexer.c" { OPCODE(F64_NEG); RETURN(UNARY); } -#line 3943 "src/prebuilt/ast-lexer-gen.c" +#line 3941 "src/prebuilt/ast-lexer-gen.c" yy579: yych = *++lexer->cursor; if (yych == 'm') goto yy702; @@ -3961,9 +3959,9 @@ yy583: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 348 "src/ast-lexer.c" +#line 346 "src/ast-lexer.c" { OPCODE(F64_SUB); RETURN(BINARY); } -#line 3967 "src/prebuilt/ast-lexer-gen.c" +#line 3965 "src/prebuilt/ast-lexer-gen.c" yy585: yych = *++lexer->cursor; if (yych == 'n') goto yy707; @@ -3985,25 +3983,25 @@ yy589: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 315 "src/ast-lexer.c" +#line 313 "src/ast-lexer.c" { OPCODE(I32_ADD); RETURN(BINARY); } -#line 3991 "src/prebuilt/ast-lexer-gen.c" +#line 3989 "src/prebuilt/ast-lexer-gen.c" yy591: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 329 "src/ast-lexer.c" +#line 327 "src/ast-lexer.c" { OPCODE(I32_AND); RETURN(BINARY); } -#line 3999 "src/prebuilt/ast-lexer-gen.c" +#line 3997 "src/prebuilt/ast-lexer-gen.c" yy593: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 295 "src/ast-lexer.c" +#line 293 "src/ast-lexer.c" { OPCODE(I32_CLZ); RETURN(UNARY); } -#line 4007 "src/prebuilt/ast-lexer-gen.c" +#line 4005 "src/prebuilt/ast-lexer-gen.c" yy595: yych = *++lexer->cursor; if (yych == 's') goto yy711; @@ -4013,9 +4011,9 @@ yy596: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 297 "src/ast-lexer.c" +#line 295 "src/ast-lexer.c" { OPCODE(I32_CTZ); RETURN(UNARY); } -#line 4019 "src/prebuilt/ast-lexer-gen.c" +#line 4017 "src/prebuilt/ast-lexer-gen.c" yy598: yych = *++lexer->cursor; if (yych == '_') goto yy712; @@ -4025,9 +4023,9 @@ yy599: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 293 "src/ast-lexer.c" +#line 291 "src/ast-lexer.c" { OPCODE(I32_EQZ); RETURN(CONVERT); } -#line 4031 "src/prebuilt/ast-lexer-gen.c" +#line 4029 "src/prebuilt/ast-lexer-gen.c" yy601: yych = *++lexer->cursor; if (yych == 's') goto yy713; @@ -4057,9 +4055,9 @@ yy606: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 319 "src/ast-lexer.c" +#line 317 "src/ast-lexer.c" { OPCODE(I32_MUL); RETURN(BINARY); } -#line 4063 "src/prebuilt/ast-lexer-gen.c" +#line 4061 "src/prebuilt/ast-lexer-gen.c" yy608: yych = *++lexer->cursor; if (yych == 'c') goto yy731; @@ -4082,9 +4080,9 @@ yy612: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 335 "src/ast-lexer.c" +#line 333 "src/ast-lexer.c" { OPCODE(I32_SHL); RETURN(BINARY); } -#line 4088 "src/prebuilt/ast-lexer-gen.c" +#line 4086 "src/prebuilt/ast-lexer-gen.c" yy614: yych = *++lexer->cursor; if (yych == '_') goto yy738; @@ -4098,9 +4096,9 @@ yy616: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 317 "src/ast-lexer.c" +#line 315 "src/ast-lexer.c" { OPCODE(I32_SUB); RETURN(BINARY); } -#line 4104 "src/prebuilt/ast-lexer-gen.c" +#line 4102 "src/prebuilt/ast-lexer-gen.c" yy618: yych = *++lexer->cursor; if (yych == 'n') goto yy740; @@ -4114,33 +4112,33 @@ yy620: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 333 "src/ast-lexer.c" +#line 331 "src/ast-lexer.c" { OPCODE(I32_XOR); RETURN(BINARY); } -#line 4120 "src/prebuilt/ast-lexer-gen.c" +#line 4118 "src/prebuilt/ast-lexer-gen.c" yy622: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 316 "src/ast-lexer.c" +#line 314 "src/ast-lexer.c" { OPCODE(I64_ADD); RETURN(BINARY); } -#line 4128 "src/prebuilt/ast-lexer-gen.c" +#line 4126 "src/prebuilt/ast-lexer-gen.c" yy624: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 330 "src/ast-lexer.c" +#line 328 "src/ast-lexer.c" { OPCODE(I64_AND); RETURN(BINARY); } -#line 4136 "src/prebuilt/ast-lexer-gen.c" +#line 4134 "src/prebuilt/ast-lexer-gen.c" yy626: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 296 "src/ast-lexer.c" +#line 294 "src/ast-lexer.c" { OPCODE(I64_CLZ); RETURN(UNARY); } -#line 4144 "src/prebuilt/ast-lexer-gen.c" +#line 4142 "src/prebuilt/ast-lexer-gen.c" yy628: yych = *++lexer->cursor; if (yych == 's') goto yy742; @@ -4150,9 +4148,9 @@ yy629: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 298 "src/ast-lexer.c" +#line 296 "src/ast-lexer.c" { OPCODE(I64_CTZ); RETURN(UNARY); } -#line 4156 "src/prebuilt/ast-lexer-gen.c" +#line 4154 "src/prebuilt/ast-lexer-gen.c" yy631: yych = *++lexer->cursor; if (yych == '_') goto yy743; @@ -4162,9 +4160,9 @@ yy632: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 294 "src/ast-lexer.c" +#line 292 "src/ast-lexer.c" { OPCODE(I64_EQZ); RETURN(CONVERT); } -#line 4168 "src/prebuilt/ast-lexer-gen.c" +#line 4166 "src/prebuilt/ast-lexer-gen.c" yy634: yych = *++lexer->cursor; if (yych == 'e') goto yy744; @@ -4198,9 +4196,9 @@ yy640: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 320 "src/ast-lexer.c" +#line 318 "src/ast-lexer.c" { OPCODE(I64_MUL); RETURN(BINARY); } -#line 4204 "src/prebuilt/ast-lexer-gen.c" +#line 4202 "src/prebuilt/ast-lexer-gen.c" yy642: yych = *++lexer->cursor; if (yych == 'c') goto yy763; @@ -4223,9 +4221,9 @@ yy646: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 336 "src/ast-lexer.c" +#line 334 "src/ast-lexer.c" { OPCODE(I64_SHL); RETURN(BINARY); } -#line 4229 "src/prebuilt/ast-lexer-gen.c" +#line 4227 "src/prebuilt/ast-lexer-gen.c" yy648: yych = *++lexer->cursor; if (yych == '_') goto yy770; @@ -4239,9 +4237,9 @@ yy650: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 318 "src/ast-lexer.c" +#line 316 "src/ast-lexer.c" { OPCODE(I64_SUB); RETURN(BINARY); } -#line 4245 "src/prebuilt/ast-lexer-gen.c" +#line 4243 "src/prebuilt/ast-lexer-gen.c" yy652: yych = *++lexer->cursor; if (yych == 'n') goto yy772; @@ -4251,17 +4249,17 @@ yy653: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 334 "src/ast-lexer.c" +#line 332 "src/ast-lexer.c" { OPCODE(I64_XOR); RETURN(BINARY); } -#line 4257 "src/prebuilt/ast-lexer-gen.c" +#line 4255 "src/prebuilt/ast-lexer-gen.c" yy655: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 246 "src/ast-lexer.c" +#line 244 "src/ast-lexer.c" { RETURN(IF); } -#line 4265 "src/prebuilt/ast-lexer-gen.c" +#line 4263 "src/prebuilt/ast-lexer-gen.c" yy657: yych = *++lexer->cursor; if (yych == 'y') goto yy773; @@ -4379,9 +4377,9 @@ yy673: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 252 "src/ast-lexer.c" +#line 250 "src/ast-lexer.c" { RETURN(BR_TABLE); } -#line 4385 "src/prebuilt/ast-lexer-gen.c" +#line 4383 "src/prebuilt/ast-lexer-gen.c" yy675: yych = *++lexer->cursor; if (yych == 'o') goto yy792; @@ -4399,9 +4397,9 @@ yy678: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 307 "src/ast-lexer.c" +#line 305 "src/ast-lexer.c" { OPCODE(F32_CEIL); RETURN(UNARY); } -#line 4405 "src/prebuilt/ast-lexer-gen.c" +#line 4403 "src/prebuilt/ast-lexer-gen.c" yy680: yych = *++lexer->cursor; if (yych == 't') goto yy795; @@ -4427,9 +4425,9 @@ yy685: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 266 "src/ast-lexer.c" +#line 264 "src/ast-lexer.c" { OPCODE(F32_LOAD); RETURN(LOAD); } -#line 4433 "src/prebuilt/ast-lexer-gen.c" +#line 4431 "src/prebuilt/ast-lexer-gen.c" yy687: yych = *++lexer->cursor; if (yych == 'e') goto yy802; @@ -4443,9 +4441,9 @@ yy689: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 305 "src/ast-lexer.c" +#line 303 "src/ast-lexer.c" { OPCODE(F32_SQRT); RETURN(UNARY); } -#line 4449 "src/prebuilt/ast-lexer-gen.c" +#line 4447 "src/prebuilt/ast-lexer-gen.c" yy691: yych = *++lexer->cursor; if (yych == 'e') goto yy804; @@ -4459,9 +4457,9 @@ yy693: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 308 "src/ast-lexer.c" +#line 306 "src/ast-lexer.c" { OPCODE(F64_CEIL); RETURN(UNARY); } -#line 4465 "src/prebuilt/ast-lexer-gen.c" +#line 4463 "src/prebuilt/ast-lexer-gen.c" yy695: yych = *++lexer->cursor; if (yych == 't') goto yy808; @@ -4483,9 +4481,9 @@ yy699: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 267 "src/ast-lexer.c" +#line 265 "src/ast-lexer.c" { OPCODE(F64_LOAD); RETURN(LOAD); } -#line 4489 "src/prebuilt/ast-lexer-gen.c" +#line 4487 "src/prebuilt/ast-lexer-gen.c" yy701: yych = *++lexer->cursor; if (yych == 'e') goto yy814; @@ -4503,9 +4501,9 @@ yy704: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 306 "src/ast-lexer.c" +#line 304 "src/ast-lexer.c" { OPCODE(F64_SQRT); RETURN(UNARY); } -#line 4509 "src/prebuilt/ast-lexer-gen.c" +#line 4507 "src/prebuilt/ast-lexer-gen.c" yy706: yych = *++lexer->cursor; if (yych == 'e') goto yy817; @@ -4540,49 +4538,49 @@ yy713: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 375 "src/ast-lexer.c" +#line 373 "src/ast-lexer.c" { OPCODE(I32_GE_S); RETURN(COMPARE); } -#line 4546 "src/prebuilt/ast-lexer-gen.c" +#line 4544 "src/prebuilt/ast-lexer-gen.c" yy715: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 377 "src/ast-lexer.c" +#line 375 "src/ast-lexer.c" { OPCODE(I32_GE_U); RETURN(COMPARE); } -#line 4554 "src/prebuilt/ast-lexer-gen.c" +#line 4552 "src/prebuilt/ast-lexer-gen.c" yy717: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 371 "src/ast-lexer.c" +#line 369 "src/ast-lexer.c" { OPCODE(I32_GT_S); RETURN(COMPARE); } -#line 4562 "src/prebuilt/ast-lexer-gen.c" +#line 4560 "src/prebuilt/ast-lexer-gen.c" yy719: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 373 "src/ast-lexer.c" +#line 371 "src/ast-lexer.c" { OPCODE(I32_GT_U); RETURN(COMPARE); } -#line 4570 "src/prebuilt/ast-lexer-gen.c" +#line 4568 "src/prebuilt/ast-lexer-gen.c" yy721: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 367 "src/ast-lexer.c" +#line 365 "src/ast-lexer.c" { OPCODE(I32_LE_S); RETURN(COMPARE); } -#line 4578 "src/prebuilt/ast-lexer-gen.c" +#line 4576 "src/prebuilt/ast-lexer-gen.c" yy723: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 369 "src/ast-lexer.c" +#line 367 "src/ast-lexer.c" { OPCODE(I32_LE_U); RETURN(COMPARE); } -#line 4586 "src/prebuilt/ast-lexer-gen.c" +#line 4584 "src/prebuilt/ast-lexer-gen.c" yy725: ++lexer->cursor; if ((yych = *lexer->cursor) <= '8') { @@ -4618,25 +4616,25 @@ yy725: } } yy726: -#line 264 "src/ast-lexer.c" +#line 262 "src/ast-lexer.c" { OPCODE(I32_LOAD); RETURN(LOAD); } -#line 4624 "src/prebuilt/ast-lexer-gen.c" +#line 4622 "src/prebuilt/ast-lexer-gen.c" yy727: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 363 "src/ast-lexer.c" +#line 361 "src/ast-lexer.c" { OPCODE(I32_LT_S); RETURN(COMPARE); } -#line 4632 "src/prebuilt/ast-lexer-gen.c" +#line 4630 "src/prebuilt/ast-lexer-gen.c" yy729: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 365 "src/ast-lexer.c" +#line 363 "src/ast-lexer.c" { OPCODE(I32_LT_U); RETURN(COMPARE); } -#line 4640 "src/prebuilt/ast-lexer-gen.c" +#line 4638 "src/prebuilt/ast-lexer-gen.c" yy731: yych = *++lexer->cursor; if (yych == 'n') goto yy833; @@ -4655,17 +4653,17 @@ yy734: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 341 "src/ast-lexer.c" +#line 339 "src/ast-lexer.c" { OPCODE(I32_ROTL); RETURN(BINARY); } -#line 4661 "src/prebuilt/ast-lexer-gen.c" +#line 4659 "src/prebuilt/ast-lexer-gen.c" yy736: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 343 "src/ast-lexer.c" +#line 341 "src/ast-lexer.c" { OPCODE(I32_ROTR); RETURN(BINARY); } -#line 4669 "src/prebuilt/ast-lexer-gen.c" +#line 4667 "src/prebuilt/ast-lexer-gen.c" yy738: yych = *++lexer->cursor; if (yych == 's') goto yy839; @@ -4701,49 +4699,49 @@ yy745: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 376 "src/ast-lexer.c" +#line 374 "src/ast-lexer.c" { OPCODE(I64_GE_S); RETURN(COMPARE); } -#line 4707 "src/prebuilt/ast-lexer-gen.c" +#line 4705 "src/prebuilt/ast-lexer-gen.c" yy747: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 378 "src/ast-lexer.c" +#line 376 "src/ast-lexer.c" { OPCODE(I64_GE_U); RETURN(COMPARE); } -#line 4715 "src/prebuilt/ast-lexer-gen.c" +#line 4713 "src/prebuilt/ast-lexer-gen.c" yy749: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 372 "src/ast-lexer.c" +#line 370 "src/ast-lexer.c" { OPCODE(I64_GT_S); RETURN(COMPARE); } -#line 4723 "src/prebuilt/ast-lexer-gen.c" +#line 4721 "src/prebuilt/ast-lexer-gen.c" yy751: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 374 "src/ast-lexer.c" +#line 372 "src/ast-lexer.c" { OPCODE(I64_GT_U); RETURN(COMPARE); } -#line 4731 "src/prebuilt/ast-lexer-gen.c" +#line 4729 "src/prebuilt/ast-lexer-gen.c" yy753: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 368 "src/ast-lexer.c" +#line 366 "src/ast-lexer.c" { OPCODE(I64_LE_S); RETURN(COMPARE); } -#line 4739 "src/prebuilt/ast-lexer-gen.c" +#line 4737 "src/prebuilt/ast-lexer-gen.c" yy755: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 370 "src/ast-lexer.c" +#line 368 "src/ast-lexer.c" { OPCODE(I64_LE_U); RETURN(COMPARE); } -#line 4747 "src/prebuilt/ast-lexer-gen.c" +#line 4745 "src/prebuilt/ast-lexer-gen.c" yy757: ++lexer->cursor; if ((yych = *lexer->cursor) <= '7') { @@ -4783,25 +4781,25 @@ yy757: } } yy758: -#line 265 "src/ast-lexer.c" +#line 263 "src/ast-lexer.c" { OPCODE(I64_LOAD); RETURN(LOAD); } -#line 4789 "src/prebuilt/ast-lexer-gen.c" +#line 4787 "src/prebuilt/ast-lexer-gen.c" yy759: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 364 "src/ast-lexer.c" +#line 362 "src/ast-lexer.c" { OPCODE(I64_LT_S); RETURN(COMPARE); } -#line 4797 "src/prebuilt/ast-lexer-gen.c" +#line 4795 "src/prebuilt/ast-lexer-gen.c" yy761: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 366 "src/ast-lexer.c" +#line 364 "src/ast-lexer.c" { OPCODE(I64_LT_U); RETURN(COMPARE); } -#line 4805 "src/prebuilt/ast-lexer-gen.c" +#line 4803 "src/prebuilt/ast-lexer-gen.c" yy763: yych = *++lexer->cursor; if (yych == 'n') goto yy857; @@ -4820,17 +4818,17 @@ yy766: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 342 "src/ast-lexer.c" +#line 340 "src/ast-lexer.c" { OPCODE(I64_ROTL); RETURN(BINARY); } -#line 4826 "src/prebuilt/ast-lexer-gen.c" +#line 4824 "src/prebuilt/ast-lexer-gen.c" yy768: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 344 "src/ast-lexer.c" +#line 342 "src/ast-lexer.c" { OPCODE(I64_ROTR); RETURN(BINARY); } -#line 4834 "src/prebuilt/ast-lexer-gen.c" +#line 4832 "src/prebuilt/ast-lexer-gen.c" yy770: yych = *++lexer->cursor; if (yych == 's') goto yy863; @@ -4886,9 +4884,9 @@ yy774: } } yy775: -#line 287 "src/ast-lexer.c" +#line 285 "src/ast-lexer.c" { TEXT_AT(7); RETURN(OFFSET_EQ_NAT); } -#line 4892 "src/prebuilt/ast-lexer-gen.c" +#line 4890 "src/prebuilt/ast-lexer-gen.c" yy776: ++lexer->cursor; if (lexer->limit <= lexer->cursor) FILL(1); @@ -4937,9 +4935,9 @@ yy778: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 435 "src/ast-lexer.c" +#line 433 "src/ast-lexer.c" { RETURN(REGISTER); } -#line 4943 "src/prebuilt/ast-lexer-gen.c" +#line 4941 "src/prebuilt/ast-lexer-gen.c" yy780: yych = *++lexer->cursor; if (yych == 'a') goto yy871; @@ -5043,9 +5041,9 @@ yy795: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 291 "src/ast-lexer.c" +#line 289 "src/ast-lexer.c" { TYPE(F32); RETURN(CONST); } -#line 5049 "src/prebuilt/ast-lexer-gen.c" +#line 5047 "src/prebuilt/ast-lexer-gen.c" yy797: yych = *++lexer->cursor; if (yych == 'r') goto yy886; @@ -5063,9 +5061,9 @@ yy800: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 309 "src/ast-lexer.c" +#line 307 "src/ast-lexer.c" { OPCODE(F32_FLOOR); RETURN(UNARY); } -#line 5069 "src/prebuilt/ast-lexer-gen.c" +#line 5067 "src/prebuilt/ast-lexer-gen.c" yy802: yych = *++lexer->cursor; if (yych == 's') goto yy889; @@ -5079,25 +5077,25 @@ yy804: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 270 "src/ast-lexer.c" +#line 268 "src/ast-lexer.c" { OPCODE(F32_STORE); RETURN(STORE); } -#line 5085 "src/prebuilt/ast-lexer-gen.c" +#line 5083 "src/prebuilt/ast-lexer-gen.c" yy806: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 311 "src/ast-lexer.c" +#line 309 "src/ast-lexer.c" { OPCODE(F32_TRUNC); RETURN(UNARY); } -#line 5093 "src/prebuilt/ast-lexer-gen.c" +#line 5091 "src/prebuilt/ast-lexer-gen.c" yy808: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 292 "src/ast-lexer.c" +#line 290 "src/ast-lexer.c" { TYPE(F64); RETURN(CONST); } -#line 5101 "src/prebuilt/ast-lexer-gen.c" +#line 5099 "src/prebuilt/ast-lexer-gen.c" yy810: yych = *++lexer->cursor; if (yych == 'r') goto yy891; @@ -5111,9 +5109,9 @@ yy812: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 310 "src/ast-lexer.c" +#line 308 "src/ast-lexer.c" { OPCODE(F64_FLOOR); RETURN(UNARY); } -#line 5117 "src/prebuilt/ast-lexer-gen.c" +#line 5115 "src/prebuilt/ast-lexer-gen.c" yy814: yych = *++lexer->cursor; if (yych == 's') goto yy893; @@ -5131,17 +5129,17 @@ yy817: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 271 "src/ast-lexer.c" +#line 269 "src/ast-lexer.c" { OPCODE(F64_STORE); RETURN(STORE); } -#line 5137 "src/prebuilt/ast-lexer-gen.c" +#line 5135 "src/prebuilt/ast-lexer-gen.c" yy819: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 312 "src/ast-lexer.c" +#line 310 "src/ast-lexer.c" { OPCODE(F64_TRUNC); RETURN(UNARY); } -#line 5145 "src/prebuilt/ast-lexer-gen.c" +#line 5143 "src/prebuilt/ast-lexer-gen.c" yy821: yych = *++lexer->cursor; if (yych == 'l') goto yy896; @@ -5151,9 +5149,9 @@ yy822: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 259 "src/ast-lexer.c" +#line 257 "src/ast-lexer.c" { RETURN(GET_LOCAL); } -#line 5157 "src/prebuilt/ast-lexer-gen.c" +#line 5155 "src/prebuilt/ast-lexer-gen.c" yy824: yych = *++lexer->cursor; if (yych == 'r') goto yy898; @@ -5163,25 +5161,25 @@ yy825: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 289 "src/ast-lexer.c" +#line 287 "src/ast-lexer.c" { TYPE(I32); RETURN(CONST); } -#line 5169 "src/prebuilt/ast-lexer-gen.c" +#line 5167 "src/prebuilt/ast-lexer-gen.c" yy827: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 321 "src/ast-lexer.c" +#line 319 "src/ast-lexer.c" { OPCODE(I32_DIV_S); RETURN(BINARY); } -#line 5177 "src/prebuilt/ast-lexer-gen.c" +#line 5175 "src/prebuilt/ast-lexer-gen.c" yy829: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 323 "src/ast-lexer.c" +#line 321 "src/ast-lexer.c" { OPCODE(I32_DIV_U); RETURN(BINARY); } -#line 5185 "src/prebuilt/ast-lexer-gen.c" +#line 5183 "src/prebuilt/ast-lexer-gen.c" yy831: yych = *++lexer->cursor; if (yych == '6') goto yy899; @@ -5203,33 +5201,33 @@ yy835: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 325 "src/ast-lexer.c" +#line 323 "src/ast-lexer.c" { OPCODE(I32_REM_S); RETURN(BINARY); } -#line 5209 "src/prebuilt/ast-lexer-gen.c" +#line 5207 "src/prebuilt/ast-lexer-gen.c" yy837: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 327 "src/ast-lexer.c" +#line 325 "src/ast-lexer.c" { OPCODE(I32_REM_U); RETURN(BINARY); } -#line 5217 "src/prebuilt/ast-lexer-gen.c" +#line 5215 "src/prebuilt/ast-lexer-gen.c" yy839: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 337 "src/ast-lexer.c" +#line 335 "src/ast-lexer.c" { OPCODE(I32_SHR_S); RETURN(BINARY); } -#line 5225 "src/prebuilt/ast-lexer-gen.c" +#line 5223 "src/prebuilt/ast-lexer-gen.c" yy841: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 339 "src/ast-lexer.c" +#line 337 "src/ast-lexer.c" { OPCODE(I32_SHR_U); RETURN(BINARY); } -#line 5233 "src/prebuilt/ast-lexer-gen.c" +#line 5231 "src/prebuilt/ast-lexer-gen.c" yy843: ++lexer->cursor; if ((yych = *lexer->cursor) <= '8') { @@ -5265,9 +5263,9 @@ yy843: } } yy844: -#line 268 "src/ast-lexer.c" +#line 266 "src/ast-lexer.c" { OPCODE(I32_STORE); RETURN(STORE); } -#line 5271 "src/prebuilt/ast-lexer-gen.c" +#line 5269 "src/prebuilt/ast-lexer-gen.c" yy845: yych = *++lexer->cursor; if (yych == '_') goto yy907; @@ -5281,25 +5279,25 @@ yy847: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 290 "src/ast-lexer.c" +#line 288 "src/ast-lexer.c" { TYPE(I64); RETURN(CONST); } -#line 5287 "src/prebuilt/ast-lexer-gen.c" +#line 5285 "src/prebuilt/ast-lexer-gen.c" yy849: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 322 "src/ast-lexer.c" +#line 320 "src/ast-lexer.c" { OPCODE(I64_DIV_S); RETURN(BINARY); } -#line 5295 "src/prebuilt/ast-lexer-gen.c" +#line 5293 "src/prebuilt/ast-lexer-gen.c" yy851: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 324 "src/ast-lexer.c" +#line 322 "src/ast-lexer.c" { OPCODE(I64_DIV_U); RETURN(BINARY); } -#line 5303 "src/prebuilt/ast-lexer-gen.c" +#line 5301 "src/prebuilt/ast-lexer-gen.c" yy853: yych = *++lexer->cursor; if (yych == 'd') goto yy909; @@ -5329,33 +5327,33 @@ yy859: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 326 "src/ast-lexer.c" +#line 324 "src/ast-lexer.c" { OPCODE(I64_REM_S); RETURN(BINARY); } -#line 5335 "src/prebuilt/ast-lexer-gen.c" +#line 5333 "src/prebuilt/ast-lexer-gen.c" yy861: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 328 "src/ast-lexer.c" +#line 326 "src/ast-lexer.c" { OPCODE(I64_REM_U); RETURN(BINARY); } -#line 5343 "src/prebuilt/ast-lexer-gen.c" +#line 5341 "src/prebuilt/ast-lexer-gen.c" yy863: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 338 "src/ast-lexer.c" +#line 336 "src/ast-lexer.c" { OPCODE(I64_SHR_S); RETURN(BINARY); } -#line 5351 "src/prebuilt/ast-lexer-gen.c" +#line 5349 "src/prebuilt/ast-lexer-gen.c" yy865: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 340 "src/ast-lexer.c" +#line 338 "src/ast-lexer.c" { OPCODE(I64_SHR_U); RETURN(BINARY); } -#line 5359 "src/prebuilt/ast-lexer-gen.c" +#line 5357 "src/prebuilt/ast-lexer-gen.c" yy867: ++lexer->cursor; if ((yych = *lexer->cursor) <= '7') { @@ -5395,9 +5393,9 @@ yy867: } } yy868: -#line 269 "src/ast-lexer.c" +#line 267 "src/ast-lexer.c" { OPCODE(I64_STORE); RETURN(STORE); } -#line 5401 "src/prebuilt/ast-lexer-gen.c" +#line 5399 "src/prebuilt/ast-lexer-gen.c" yy869: yych = *++lexer->cursor; if (yych == '_') goto yy920; @@ -5423,17 +5421,17 @@ yy872: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 260 "src/ast-lexer.c" +#line 258 "src/ast-lexer.c" { RETURN(SET_LOCAL); } -#line 5429 "src/prebuilt/ast-lexer-gen.c" +#line 5427 "src/prebuilt/ast-lexer-gen.c" yy874: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 261 "src/ast-lexer.c" +#line 259 "src/ast-lexer.c" { RETURN(TEE_LOCAL); } -#line 5437 "src/prebuilt/ast-lexer-gen.c" +#line 5435 "src/prebuilt/ast-lexer-gen.c" yy876: yych = *++lexer->cursor; if (yych == 'l') goto yy925; @@ -5519,9 +5517,9 @@ yy896: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 262 "src/ast-lexer.c" +#line 260 "src/ast-lexer.c" { RETURN(GET_GLOBAL); } -#line 5525 "src/prebuilt/ast-lexer-gen.c" +#line 5523 "src/prebuilt/ast-lexer-gen.c" yy898: yych = *++lexer->cursor; if (yych == 'y') goto yy949; @@ -5540,9 +5538,9 @@ yy901: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 299 "src/ast-lexer.c" +#line 297 "src/ast-lexer.c" { OPCODE(I32_POPCNT); RETURN(UNARY); } -#line 5546 "src/prebuilt/ast-lexer-gen.c" +#line 5544 "src/prebuilt/ast-lexer-gen.c" yy903: yych = *++lexer->cursor; if (yych == 'r') goto yy956; @@ -5556,9 +5554,9 @@ yy905: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 282 "src/ast-lexer.c" +#line 280 "src/ast-lexer.c" { OPCODE(I32_STORE8); RETURN(STORE); } -#line 5562 "src/prebuilt/ast-lexer-gen.c" +#line 5560 "src/prebuilt/ast-lexer-gen.c" yy907: yych = *++lexer->cursor; if (yych == 's') goto yy959; @@ -5590,9 +5588,9 @@ yy913: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 300 "src/ast-lexer.c" +#line 298 "src/ast-lexer.c" { OPCODE(I64_POPCNT); RETURN(UNARY); } -#line 5596 "src/prebuilt/ast-lexer-gen.c" +#line 5594 "src/prebuilt/ast-lexer-gen.c" yy915: yych = *++lexer->cursor; if (yych == 'r') goto yy969; @@ -5610,9 +5608,9 @@ yy918: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 283 "src/ast-lexer.c" +#line 281 "src/ast-lexer.c" { OPCODE(I64_STORE8); RETURN(STORE); } -#line 5616 "src/prebuilt/ast-lexer-gen.c" +#line 5614 "src/prebuilt/ast-lexer-gen.c" yy920: yych = *++lexer->cursor; if (yych == 's') goto yy974; @@ -5669,9 +5667,9 @@ yy923: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 263 "src/ast-lexer.c" +#line 261 "src/ast-lexer.c" { RETURN(SET_GLOBAL); } -#line 5675 "src/prebuilt/ast-lexer-gen.c" +#line 5673 "src/prebuilt/ast-lexer-gen.c" yy925: yych = *++lexer->cursor; if (yych == 'e') goto yy976; @@ -5697,9 +5695,9 @@ yy930: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 443 "src/ast-lexer.c" +#line 441 "src/ast-lexer.c" { RETURN(ASSERT_TRAP); } -#line 5703 "src/prebuilt/ast-lexer-gen.c" +#line 5701 "src/prebuilt/ast-lexer-gen.c" yy932: yych = *++lexer->cursor; if (yych == 'n') goto yy982; @@ -5709,9 +5707,9 @@ yy933: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 254 "src/ast-lexer.c" +#line 252 "src/ast-lexer.c" { RETURN(CALL_IMPORT); } -#line 5715 "src/prebuilt/ast-lexer-gen.c" +#line 5713 "src/prebuilt/ast-lexer-gen.c" yy935: yych = *++lexer->cursor; if (yych == 'c') goto yy983; @@ -5737,9 +5735,9 @@ yy940: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 313 "src/ast-lexer.c" +#line 311 "src/ast-lexer.c" { OPCODE(F32_NEAREST); RETURN(UNARY); } -#line 5743 "src/prebuilt/ast-lexer-gen.c" +#line 5741 "src/prebuilt/ast-lexer-gen.c" yy942: yych = *++lexer->cursor; if (yych == 'p') goto yy989; @@ -5757,9 +5755,9 @@ yy945: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 314 "src/ast-lexer.c" +#line 312 "src/ast-lexer.c" { OPCODE(F64_NEAREST); RETURN(UNARY); } -#line 5763 "src/prebuilt/ast-lexer-gen.c" +#line 5761 "src/prebuilt/ast-lexer-gen.c" yy947: yych = *++lexer->cursor; if (yych == '/') goto yy993; @@ -5773,9 +5771,9 @@ yy949: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 419 "src/ast-lexer.c" +#line 417 "src/ast-lexer.c" { RETURN(GROW_MEMORY); } -#line 5779 "src/prebuilt/ast-lexer-gen.c" +#line 5777 "src/prebuilt/ast-lexer-gen.c" yy951: yych = *++lexer->cursor; if (yych == 's') goto yy995; @@ -5786,17 +5784,17 @@ yy952: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 272 "src/ast-lexer.c" +#line 270 "src/ast-lexer.c" { OPCODE(I32_LOAD8_S); RETURN(LOAD); } -#line 5792 "src/prebuilt/ast-lexer-gen.c" +#line 5790 "src/prebuilt/ast-lexer-gen.c" yy954: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 274 "src/ast-lexer.c" +#line 272 "src/ast-lexer.c" { OPCODE(I32_LOAD8_U); RETURN(LOAD); } -#line 5800 "src/prebuilt/ast-lexer-gen.c" +#line 5798 "src/prebuilt/ast-lexer-gen.c" yy956: yych = *++lexer->cursor; if (yych == 'p') goto yy999; @@ -5806,9 +5804,9 @@ yy957: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 284 "src/ast-lexer.c" +#line 282 "src/ast-lexer.c" { OPCODE(I32_STORE16); RETURN(STORE); } -#line 5812 "src/prebuilt/ast-lexer-gen.c" +#line 5810 "src/prebuilt/ast-lexer-gen.c" yy959: yych = *++lexer->cursor; if (yych == '/') goto yy1000; @@ -5841,17 +5839,17 @@ yy965: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 273 "src/ast-lexer.c" +#line 271 "src/ast-lexer.c" { OPCODE(I64_LOAD8_S); RETURN(LOAD); } -#line 5847 "src/prebuilt/ast-lexer-gen.c" +#line 5845 "src/prebuilt/ast-lexer-gen.c" yy967: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 275 "src/ast-lexer.c" +#line 273 "src/ast-lexer.c" { OPCODE(I64_LOAD8_U); RETURN(LOAD); } -#line 5855 "src/prebuilt/ast-lexer-gen.c" +#line 5853 "src/prebuilt/ast-lexer-gen.c" yy969: yych = *++lexer->cursor; if (yych == 'p') goto yy1014; @@ -5861,17 +5859,17 @@ yy970: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 285 "src/ast-lexer.c" +#line 283 "src/ast-lexer.c" { OPCODE(I64_STORE16); RETURN(STORE); } -#line 5867 "src/prebuilt/ast-lexer-gen.c" +#line 5865 "src/prebuilt/ast-lexer-gen.c" yy972: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 286 "src/ast-lexer.c" +#line 284 "src/ast-lexer.c" { OPCODE(I64_STORE32); RETURN(STORE); } -#line 5875 "src/prebuilt/ast-lexer-gen.c" +#line 5873 "src/prebuilt/ast-lexer-gen.c" yy974: yych = *++lexer->cursor; if (yych == '/') goto yy1015; @@ -5885,9 +5883,9 @@ yy976: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 417 "src/ast-lexer.c" +#line 415 "src/ast-lexer.c" { RETURN(UNREACHABLE); } -#line 5891 "src/prebuilt/ast-lexer-gen.c" +#line 5889 "src/prebuilt/ast-lexer-gen.c" yy978: yych = *++lexer->cursor; if (yych == 's') goto yy1017; @@ -5926,9 +5924,9 @@ yy986: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 357 "src/ast-lexer.c" +#line 355 "src/ast-lexer.c" { OPCODE(F32_COPYSIGN); RETURN(BINARY); } -#line 5932 "src/prebuilt/ast-lexer-gen.c" +#line 5930 "src/prebuilt/ast-lexer-gen.c" yy988: yych = *++lexer->cursor; if (yych == '6') goto yy1028; @@ -5947,9 +5945,9 @@ yy991: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 358 "src/ast-lexer.c" +#line 356 "src/ast-lexer.c" { OPCODE(F64_COPYSIGN); RETURN(BINARY); } -#line 5953 "src/prebuilt/ast-lexer-gen.c" +#line 5951 "src/prebuilt/ast-lexer-gen.c" yy993: yych = *++lexer->cursor; if (yych == 'f') goto yy1032; @@ -5963,17 +5961,17 @@ yy995: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 276 "src/ast-lexer.c" +#line 274 "src/ast-lexer.c" { OPCODE(I32_LOAD16_S); RETURN(LOAD); } -#line 5969 "src/prebuilt/ast-lexer-gen.c" +#line 5967 "src/prebuilt/ast-lexer-gen.c" yy997: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 278 "src/ast-lexer.c" +#line 276 "src/ast-lexer.c" { OPCODE(I32_LOAD16_U); RETURN(LOAD); } -#line 5977 "src/prebuilt/ast-lexer-gen.c" +#line 5975 "src/prebuilt/ast-lexer-gen.c" yy999: yych = *++lexer->cursor; if (yych == 'r') goto yy1034; @@ -5991,9 +5989,9 @@ yy1002: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 393 "src/ast-lexer.c" +#line 391 "src/ast-lexer.c" { OPCODE(I32_WRAP_I64); RETURN(CONVERT); } -#line 5997 "src/prebuilt/ast-lexer-gen.c" +#line 5995 "src/prebuilt/ast-lexer-gen.c" yy1004: yych = *++lexer->cursor; if (yych == '/') goto yy1037; @@ -6007,33 +6005,33 @@ yy1006: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 277 "src/ast-lexer.c" +#line 275 "src/ast-lexer.c" { OPCODE(I64_LOAD16_S); RETURN(LOAD); } -#line 6013 "src/prebuilt/ast-lexer-gen.c" +#line 6011 "src/prebuilt/ast-lexer-gen.c" yy1008: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 279 "src/ast-lexer.c" +#line 277 "src/ast-lexer.c" { OPCODE(I64_LOAD16_U); RETURN(LOAD); } -#line 6021 "src/prebuilt/ast-lexer-gen.c" +#line 6019 "src/prebuilt/ast-lexer-gen.c" yy1010: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 280 "src/ast-lexer.c" +#line 278 "src/ast-lexer.c" { OPCODE(I64_LOAD32_S); RETURN(LOAD); } -#line 6029 "src/prebuilt/ast-lexer-gen.c" +#line 6027 "src/prebuilt/ast-lexer-gen.c" yy1012: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 281 "src/ast-lexer.c" +#line 279 "src/ast-lexer.c" { OPCODE(I64_LOAD32_U); RETURN(LOAD); } -#line 6037 "src/prebuilt/ast-lexer-gen.c" +#line 6035 "src/prebuilt/ast-lexer-gen.c" yy1014: yych = *++lexer->cursor; if (yych == 'r') goto yy1039; @@ -6093,9 +6091,9 @@ yy1020: } } yy1021: -#line 441 "src/ast-lexer.c" +#line 439 "src/ast-lexer.c" { RETURN(ASSERT_RETURN); } -#line 6099 "src/prebuilt/ast-lexer-gen.c" +#line 6097 "src/prebuilt/ast-lexer-gen.c" yy1022: yych = *++lexer->cursor; if (yych == 'a') goto yy1047; @@ -6105,9 +6103,9 @@ yy1023: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 255 "src/ast-lexer.c" +#line 253 "src/ast-lexer.c" { RETURN(CALL_INDIRECT); } -#line 6111 "src/prebuilt/ast-lexer-gen.c" +#line 6109 "src/prebuilt/ast-lexer-gen.c" yy1025: yych = *++lexer->cursor; if (yych == 'y') goto yy1048; @@ -6189,9 +6187,9 @@ yy1043: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 439 "src/ast-lexer.c" +#line 437 "src/ast-lexer.c" { RETURN(ASSERT_INVALID); } -#line 6195 "src/prebuilt/ast-lexer-gen.c" +#line 6193 "src/prebuilt/ast-lexer-gen.c" yy1045: yych = *++lexer->cursor; if (yych == 'e') goto yy1072; @@ -6209,9 +6207,9 @@ yy1048: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 418 "src/ast-lexer.c" +#line 416 "src/ast-lexer.c" { RETURN(CURRENT_MEMORY); } -#line 6215 "src/prebuilt/ast-lexer-gen.c" +#line 6213 "src/prebuilt/ast-lexer-gen.c" yy1050: yych = *++lexer->cursor; if (yych == 'i') goto yy1075; @@ -6225,9 +6223,9 @@ yy1052: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 411 "src/ast-lexer.c" +#line 409 "src/ast-lexer.c" { OPCODE(F32_DEMOTE_F64); RETURN(CONVERT); } -#line 6231 "src/prebuilt/ast-lexer-gen.c" +#line 6229 "src/prebuilt/ast-lexer-gen.c" yy1054: yych = *++lexer->cursor; if (yych == 't') goto yy1077; @@ -6341,9 +6339,9 @@ yy1080: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 410 "src/ast-lexer.c" +#line 408 "src/ast-lexer.c" { OPCODE(F64_PROMOTE_F32); RETURN(CONVERT); } -#line 6347 "src/prebuilt/ast-lexer-gen.c" +#line 6345 "src/prebuilt/ast-lexer-gen.c" yy1082: yych = *++lexer->cursor; if (yych == '/') goto yy1117; @@ -6357,33 +6355,33 @@ yy1084: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 394 "src/ast-lexer.c" +#line 392 "src/ast-lexer.c" { OPCODE(I32_TRUNC_S_F32); RETURN(CONVERT); } -#line 6363 "src/prebuilt/ast-lexer-gen.c" +#line 6361 "src/prebuilt/ast-lexer-gen.c" yy1086: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 396 "src/ast-lexer.c" +#line 394 "src/ast-lexer.c" { OPCODE(I32_TRUNC_S_F64); RETURN(CONVERT); } -#line 6371 "src/prebuilt/ast-lexer-gen.c" +#line 6369 "src/prebuilt/ast-lexer-gen.c" yy1088: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 398 "src/ast-lexer.c" +#line 396 "src/ast-lexer.c" { OPCODE(I32_TRUNC_U_F32); RETURN(CONVERT); } -#line 6379 "src/prebuilt/ast-lexer-gen.c" +#line 6377 "src/prebuilt/ast-lexer-gen.c" yy1090: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 400 "src/ast-lexer.c" +#line 398 "src/ast-lexer.c" { OPCODE(I32_TRUNC_U_F64); RETURN(CONVERT); } -#line 6387 "src/prebuilt/ast-lexer-gen.c" +#line 6385 "src/prebuilt/ast-lexer-gen.c" yy1092: yych = *++lexer->cursor; if (yych == '2') goto yy1119; @@ -6401,33 +6399,33 @@ yy1095: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 395 "src/ast-lexer.c" +#line 393 "src/ast-lexer.c" { OPCODE(I64_TRUNC_S_F32); RETURN(CONVERT); } -#line 6407 "src/prebuilt/ast-lexer-gen.c" +#line 6405 "src/prebuilt/ast-lexer-gen.c" yy1097: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 397 "src/ast-lexer.c" +#line 395 "src/ast-lexer.c" { OPCODE(I64_TRUNC_S_F64); RETURN(CONVERT); } -#line 6415 "src/prebuilt/ast-lexer-gen.c" +#line 6413 "src/prebuilt/ast-lexer-gen.c" yy1099: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 399 "src/ast-lexer.c" +#line 397 "src/ast-lexer.c" { OPCODE(I64_TRUNC_U_F32); RETURN(CONVERT); } -#line 6423 "src/prebuilt/ast-lexer-gen.c" +#line 6421 "src/prebuilt/ast-lexer-gen.c" yy1101: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 401 "src/ast-lexer.c" +#line 399 "src/ast-lexer.c" { OPCODE(I64_TRUNC_U_F64); RETURN(CONVERT); } -#line 6431 "src/prebuilt/ast-lexer-gen.c" +#line 6429 "src/prebuilt/ast-lexer-gen.c" yy1103: yych = *++lexer->cursor; if (yych == 'n') goto yy1124; @@ -6437,9 +6435,9 @@ yy1104: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 438 "src/ast-lexer.c" +#line 436 "src/ast-lexer.c" { RETURN(ASSERT_MALFORMED); } -#line 6443 "src/prebuilt/ast-lexer-gen.c" +#line 6441 "src/prebuilt/ast-lexer-gen.c" yy1106: yych = *++lexer->cursor; if (yych == 'n') goto yy1126; @@ -6497,17 +6495,17 @@ yy1119: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 391 "src/ast-lexer.c" +#line 389 "src/ast-lexer.c" { OPCODE(I64_EXTEND_S_I32); RETURN(CONVERT); } -#line 6503 "src/prebuilt/ast-lexer-gen.c" +#line 6501 "src/prebuilt/ast-lexer-gen.c" yy1121: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 392 "src/ast-lexer.c" +#line 390 "src/ast-lexer.c" { OPCODE(I64_EXTEND_U_I32); RETURN(CONVERT); } -#line 6511 "src/prebuilt/ast-lexer-gen.c" +#line 6509 "src/prebuilt/ast-lexer-gen.c" yy1123: yych = *++lexer->cursor; if (yych == 'f') goto yy1149; @@ -6517,57 +6515,57 @@ yy1124: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 444 "src/ast-lexer.c" +#line 442 "src/ast-lexer.c" { RETURN(ASSERT_EXHAUSTION); } -#line 6523 "src/prebuilt/ast-lexer-gen.c" +#line 6521 "src/prebuilt/ast-lexer-gen.c" yy1126: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 442 "src/ast-lexer.c" +#line 440 "src/ast-lexer.c" { RETURN(ASSERT_RETURN_NAN); } -#line 6531 "src/prebuilt/ast-lexer-gen.c" +#line 6529 "src/prebuilt/ast-lexer-gen.c" yy1128: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 440 "src/ast-lexer.c" +#line 438 "src/ast-lexer.c" { RETURN(ASSERT_UNLINKABLE); } -#line 6539 "src/prebuilt/ast-lexer-gen.c" +#line 6537 "src/prebuilt/ast-lexer-gen.c" yy1130: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 402 "src/ast-lexer.c" +#line 400 "src/ast-lexer.c" { OPCODE(F32_CONVERT_S_I32); RETURN(CONVERT); } -#line 6547 "src/prebuilt/ast-lexer-gen.c" +#line 6545 "src/prebuilt/ast-lexer-gen.c" yy1132: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 404 "src/ast-lexer.c" +#line 402 "src/ast-lexer.c" { OPCODE(F32_CONVERT_S_I64); RETURN(CONVERT); } -#line 6555 "src/prebuilt/ast-lexer-gen.c" +#line 6553 "src/prebuilt/ast-lexer-gen.c" yy1134: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 406 "src/ast-lexer.c" +#line 404 "src/ast-lexer.c" { OPCODE(F32_CONVERT_U_I32); RETURN(CONVERT); } -#line 6563 "src/prebuilt/ast-lexer-gen.c" +#line 6561 "src/prebuilt/ast-lexer-gen.c" yy1136: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 408 "src/ast-lexer.c" +#line 406 "src/ast-lexer.c" { OPCODE(F32_CONVERT_U_I64); RETURN(CONVERT); } -#line 6571 "src/prebuilt/ast-lexer-gen.c" +#line 6569 "src/prebuilt/ast-lexer-gen.c" yy1138: yych = *++lexer->cursor; if (yych == '3') goto yy1150; @@ -6577,33 +6575,33 @@ yy1139: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 403 "src/ast-lexer.c" +#line 401 "src/ast-lexer.c" { OPCODE(F64_CONVERT_S_I32); RETURN(CONVERT); } -#line 6583 "src/prebuilt/ast-lexer-gen.c" +#line 6581 "src/prebuilt/ast-lexer-gen.c" yy1141: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 405 "src/ast-lexer.c" +#line 403 "src/ast-lexer.c" { OPCODE(F64_CONVERT_S_I64); RETURN(CONVERT); } -#line 6591 "src/prebuilt/ast-lexer-gen.c" +#line 6589 "src/prebuilt/ast-lexer-gen.c" yy1143: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 407 "src/ast-lexer.c" +#line 405 "src/ast-lexer.c" { OPCODE(F64_CONVERT_U_I32); RETURN(CONVERT); } -#line 6599 "src/prebuilt/ast-lexer-gen.c" +#line 6597 "src/prebuilt/ast-lexer-gen.c" yy1145: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 409 "src/ast-lexer.c" +#line 407 "src/ast-lexer.c" { OPCODE(F64_CONVERT_U_I64); RETURN(CONVERT); } -#line 6607 "src/prebuilt/ast-lexer-gen.c" +#line 6605 "src/prebuilt/ast-lexer-gen.c" yy1147: yych = *++lexer->cursor; if (yych == '6') goto yy1151; @@ -6637,56 +6635,51 @@ yy1154: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 412 "src/ast-lexer.c" +#line 410 "src/ast-lexer.c" { OPCODE(F32_REINTERPRET_I32); RETURN(CONVERT); } -#line 6643 "src/prebuilt/ast-lexer-gen.c" +#line 6641 "src/prebuilt/ast-lexer-gen.c" yy1156: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 414 "src/ast-lexer.c" +#line 412 "src/ast-lexer.c" { OPCODE(F64_REINTERPRET_I64); RETURN(CONVERT); } -#line 6651 "src/prebuilt/ast-lexer-gen.c" +#line 6649 "src/prebuilt/ast-lexer-gen.c" yy1158: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 413 "src/ast-lexer.c" +#line 411 "src/ast-lexer.c" { OPCODE(I32_REINTERPRET_F32); RETURN(CONVERT); } -#line 6659 "src/prebuilt/ast-lexer-gen.c" +#line 6657 "src/prebuilt/ast-lexer-gen.c" yy1160: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 415 "src/ast-lexer.c" +#line 413 "src/ast-lexer.c" { OPCODE(I64_REINTERPRET_F64); RETURN(CONVERT); } -#line 6667 "src/prebuilt/ast-lexer-gen.c" +#line 6665 "src/prebuilt/ast-lexer-gen.c" } } -#line 467 "src/ast-lexer.c" +#line 465 "src/ast-lexer.c" } } -static WabtAstLexer* wabt_new_lexer(WabtAllocator* allocator, - WabtAstLexerSourceType type, +static WabtAstLexer* wabt_new_lexer(WabtAstLexerSourceType type, const char* filename) { - WabtAstLexer* lexer = - wabt_alloc_zero(allocator, sizeof(WabtAstLexer), WABT_DEFAULT_ALIGN); - lexer->allocator = allocator; + WabtAstLexer* lexer = wabt_alloc_zero(sizeof(WabtAstLexer)); lexer->line = 1; lexer->filename = filename; lexer->source.type = type; return lexer; } -WabtAstLexer* wabt_new_ast_file_lexer(WabtAllocator* allocator, - const char* filename) { - WabtAstLexer* lexer = - wabt_new_lexer(allocator, WABT_LEXER_SOURCE_TYPE_FILE, filename); +WabtAstLexer* wabt_new_ast_file_lexer(const char* filename) { + WabtAstLexer* lexer = wabt_new_lexer(WABT_LEXER_SOURCE_TYPE_FILE, filename); lexer->source.file = fopen(filename, "rb"); if (!lexer->source.file) { wabt_destroy_ast_lexer(lexer); @@ -6695,12 +6688,10 @@ WabtAstLexer* wabt_new_ast_file_lexer(WabtAllocator* allocator, return lexer; } -WabtAstLexer* wabt_new_ast_buffer_lexer(WabtAllocator* allocator, - const char* filename, +WabtAstLexer* wabt_new_ast_buffer_lexer(const char* filename, const void* data, size_t size) { - WabtAstLexer* lexer = - wabt_new_lexer(allocator, WABT_LEXER_SOURCE_TYPE_BUFFER, filename); + WabtAstLexer* lexer = wabt_new_lexer(WABT_LEXER_SOURCE_TYPE_BUFFER, filename); lexer->source.buffer.data = data; lexer->source.buffer.size = size; lexer->source.buffer.read_offset = 0; @@ -6710,12 +6701,8 @@ WabtAstLexer* wabt_new_ast_buffer_lexer(WabtAllocator* allocator, void wabt_destroy_ast_lexer(WabtAstLexer* lexer) { if (lexer->source.type == WABT_LEXER_SOURCE_TYPE_FILE && lexer->source.file) fclose(lexer->source.file); - wabt_free(lexer->allocator, lexer->buffer); - wabt_free(lexer->allocator, lexer); -} - -WabtAllocator* wabt_ast_lexer_get_allocator(WabtAstLexer* lexer) { - return lexer->allocator; + wabt_free(lexer->buffer); + wabt_free(lexer); } typedef enum WabtLineOffsetPosition { diff --git a/src/prebuilt/ast-parser-gen.c b/src/prebuilt/ast-parser-gen.c index 0a1dcbc2..be963467 100644 --- a/src/prebuilt/ast-parser-gen.c +++ b/src/prebuilt/ast-parser-gen.c @@ -77,7 +77,6 @@ #include <stdio.h> #include <stdlib.h> -#include "allocator.h" #include "ast-parser.h" #include "ast-parser-lexer-shared.h" #include "binary-reader-ast.h" @@ -97,8 +96,8 @@ defines are available. */ #define YYMAXDEPTH 10000000 -#define DUPTEXT(dst, src) \ - (dst).start = wabt_strndup(parser->allocator, (src).start, (src).length); \ +#define DUPTEXT(dst, src) \ + (dst).start = wabt_strndup((src).start, (src).length); \ (dst).length = (src).length #define YYLLOC_DEFAULT(Current, Rhs, N) \ @@ -118,27 +117,26 @@ #define APPEND_FIELD_TO_LIST(module, field, KIND, kind, loc_, item) \ do { \ - field = wabt_append_module_field(parser->allocator, module); \ + field = wabt_append_module_field(module); \ field->loc = loc_; \ field->type = WABT_MODULE_FIELD_TYPE_##KIND; \ field->kind = item; \ } while (0) -#define APPEND_ITEM_TO_VECTOR(module, Kind, kind, kinds, item_ptr) \ - do { \ - Wabt##Kind* dummy = item_ptr; \ - wabt_append_##kind##_ptr_value(parser->allocator, &(module)->kinds, \ - &dummy); \ +#define APPEND_ITEM_TO_VECTOR(module, Kind, kind, kinds, item_ptr) \ + do { \ + Wabt##Kind* dummy = item_ptr; \ + wabt_append_##kind##_ptr_value(&(module)->kinds, &dummy); \ } while (0) -#define INSERT_BINDING(module, kind, kinds, loc_, name) \ - do \ - if ((name).start) { \ - WabtBinding* binding = wabt_insert_binding( \ - parser->allocator, &(module)->kind##_bindings, &(name)); \ - binding->loc = loc_; \ - binding->index = (module)->kinds.size - 1; \ - } \ +#define INSERT_BINDING(module, kind, kinds, loc_, name) \ + do \ + if ((name).start) { \ + WabtBinding* binding = \ + wabt_insert_binding(&(module)->kind##_bindings, &(name)); \ + binding->loc = loc_; \ + binding->index = (module)->kinds.size - 1; \ + } \ while (0) #define APPEND_INLINE_EXPORT(module, KIND, loc_, value, index_) \ @@ -181,12 +179,12 @@ WABT_PRINTF_STRING_SLICE_ARG(begin_label), \ WABT_PRINTF_STRING_SLICE_ARG(end_label)); \ } \ - wabt_destroy_string_slice(parser->allocator, &(end_label)); \ + wabt_destroy_string_slice(&(end_label)); \ } \ } while (0) -#define YYMALLOC(size) wabt_alloc(parser->allocator, size, WABT_DEFAULT_ALIGN) -#define YYFREE(p) wabt_free(parser->allocator, p) +#define YYMALLOC(size) wabt_alloc(size) +#define YYFREE(p) wabt_free(p) #define USE_NATURAL_ALIGNMENT (~0) @@ -194,40 +192,39 @@ static WabtExprList join_exprs1(WabtLocation* loc, WabtExpr* expr1); static WabtExprList join_exprs2(WabtLocation* loc, WabtExprList* expr1, WabtExpr* expr2); -static WabtFuncField* new_func_field(WabtAllocator* allocator) { - return wabt_alloc_zero(allocator, sizeof(WabtFuncField), WABT_DEFAULT_ALIGN); +static WabtFuncField* new_func_field(void) { + return wabt_alloc_zero(sizeof(WabtFuncField)); } -static WabtFunc* new_func(WabtAllocator* allocator) { - return wabt_alloc_zero(allocator, sizeof(WabtFunc), WABT_DEFAULT_ALIGN); +static WabtFunc* new_func(void) { + return wabt_alloc_zero(sizeof(WabtFunc)); } -static WabtCommand* new_command(WabtAllocator* allocator) { - return wabt_alloc_zero(allocator, sizeof(WabtCommand), WABT_DEFAULT_ALIGN); +static WabtCommand* new_command(void) { + return wabt_alloc_zero(sizeof(WabtCommand)); } -static WabtModule* new_module(WabtAllocator* allocator) { - return wabt_alloc_zero(allocator, sizeof(WabtModule), WABT_DEFAULT_ALIGN); +static WabtModule* new_module(void) { + return wabt_alloc_zero(sizeof(WabtModule)); } -static WabtImport* new_import(WabtAllocator* allocator) { - return wabt_alloc_zero(allocator, sizeof(WabtImport), WABT_DEFAULT_ALIGN); +static WabtImport* new_import(void) { + return wabt_alloc_zero(sizeof(WabtImport)); } -static WabtTextListNode* new_text_list_node(WabtAllocator* allocator) { - return wabt_alloc_zero(allocator, sizeof(WabtTextListNode), - WABT_DEFAULT_ALIGN); +static WabtTextListNode* new_text_list_node(void) { + return wabt_alloc_zero(sizeof(WabtTextListNode)); } static WabtResult parse_const(WabtType type, WabtLiteralType literal_type, const char* s, const char* end, WabtConst* out); -static void dup_text_list(WabtAllocator*, WabtTextList* text_list, - void** out_data, size_t* out_size); +static void dup_text_list(WabtTextList * text_list, void** out_data, + size_t* out_size); static WabtBool is_empty_signature(WabtFuncSignature* sig); -static void append_implicit_func_declaration(WabtAllocator*, WabtLocation*, - WabtModule*, WabtFuncDeclaration*); +static void append_implicit_func_declaration(WabtLocation*, WabtModule*, + WabtFuncDeclaration*); typedef struct BinaryErrorCallbackData { WabtLocation* loc; @@ -241,7 +238,7 @@ static void on_read_binary_error(uint32_t offset, const char* error, #define wabt_ast_parser_lex wabt_ast_lexer_lex -#line 245 "src/prebuilt/ast-parser-gen.c" /* yacc.c:339 */ +#line 242 "src/prebuilt/ast-parser-gen.c" /* yacc.c:339 */ # ifndef YY_NULLPTR # if defined __cplusplus && 201103L <= __cplusplus @@ -388,7 +385,7 @@ int wabt_ast_parser_parse (WabtAstLexer* lexer, WabtAstParser* parser); /* Copy the second part of user declarations. */ -#line 392 "src/prebuilt/ast-parser-gen.c" /* yacc.c:358 */ +#line 389 "src/prebuilt/ast-parser-gen.c" /* yacc.c:358 */ #ifdef short # undef short @@ -694,24 +691,24 @@ static const yytype_uint8 yytranslate[] = /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ static const yytype_uint16 yyrline[] = { - 0, 298, 298, 304, 314, 315, 319, 337, 338, 344, - 347, 352, 359, 362, 363, 367, 372, 379, 382, 385, - 390, 397, 403, 414, 418, 422, 429, 434, 441, 442, - 448, 449, 452, 456, 457, 461, 462, 472, 473, 484, - 485, 486, 489, 492, 495, 498, 501, 505, 509, 514, - 517, 521, 525, 529, 533, 537, 541, 545, 551, 557, - 569, 573, 577, 581, 585, 588, 593, 599, 605, 611, - 621, 629, 633, 636, 642, 648, 657, 663, 668, 674, - 679, 685, 693, 694, 702, 703, 711, 716, 717, 723, - 729, 739, 745, 751, 761, 816, 825, 832, 839, 849, - 852, 856, 862, 873, 879, 899, 906, 918, 925, 946, - 969, 976, 989, 996, 1002, 1008, 1014, 1022, 1027, 1034, - 1040, 1046, 1052, 1061, 1069, 1074, 1079, 1084, 1091, 1098, - 1102, 1105, 1116, 1120, 1127, 1131, 1134, 1142, 1150, 1167, - 1183, 1194, 1201, 1208, 1214, 1254, 1264, 1286, 1296, 1322, - 1327, 1335, 1343, 1353, 1359, 1365, 1371, 1377, 1383, 1388, - 1394, 1403, 1408, 1409, 1415, 1424, 1425, 1433, 1445, 1446, - 1453, 1519 + 0, 295, 295, 301, 311, 312, 316, 334, 335, 341, + 344, 349, 356, 359, 360, 364, 369, 376, 379, 382, + 387, 394, 400, 411, 415, 419, 426, 431, 438, 439, + 445, 446, 449, 453, 454, 458, 459, 469, 470, 481, + 482, 483, 486, 489, 492, 495, 498, 502, 506, 511, + 514, 518, 522, 526, 530, 534, 538, 542, 548, 554, + 566, 570, 574, 578, 582, 585, 590, 596, 602, 608, + 618, 626, 630, 633, 639, 645, 654, 660, 665, 671, + 676, 682, 690, 691, 699, 700, 708, 713, 714, 720, + 726, 736, 742, 748, 758, 812, 821, 828, 835, 845, + 848, 852, 858, 869, 875, 895, 902, 914, 921, 941, + 963, 970, 983, 990, 996, 1002, 1008, 1016, 1021, 1028, + 1034, 1040, 1046, 1055, 1063, 1068, 1073, 1078, 1085, 1092, + 1096, 1099, 1110, 1114, 1121, 1125, 1128, 1136, 1144, 1161, + 1177, 1187, 1194, 1201, 1207, 1246, 1256, 1278, 1288, 1314, + 1319, 1327, 1335, 1345, 1351, 1357, 1363, 1369, 1375, 1380, + 1386, 1395, 1400, 1401, 1407, 1416, 1417, 1425, 1437, 1438, + 1445, 1509 }; #endif @@ -1650,333 +1647,333 @@ yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocatio switch (yytype) { case 5: /* NAT */ -#line 259 "src/ast-parser.y" /* yacc.c:1257 */ +#line 256 "src/ast-parser.y" /* yacc.c:1257 */ {} -#line 1656 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 1653 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 6: /* INT */ -#line 259 "src/ast-parser.y" /* yacc.c:1257 */ +#line 256 "src/ast-parser.y" /* yacc.c:1257 */ {} -#line 1662 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 1659 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 7: /* FLOAT */ -#line 259 "src/ast-parser.y" /* yacc.c:1257 */ +#line 256 "src/ast-parser.y" /* yacc.c:1257 */ {} -#line 1668 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 1665 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 8: /* TEXT */ -#line 259 "src/ast-parser.y" /* yacc.c:1257 */ +#line 256 "src/ast-parser.y" /* yacc.c:1257 */ {} -#line 1674 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 1671 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 9: /* VAR */ -#line 259 "src/ast-parser.y" /* yacc.c:1257 */ +#line 256 "src/ast-parser.y" /* yacc.c:1257 */ {} -#line 1680 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 1677 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 35: /* OFFSET_EQ_NAT */ -#line 259 "src/ast-parser.y" /* yacc.c:1257 */ +#line 256 "src/ast-parser.y" /* yacc.c:1257 */ {} -#line 1686 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 1683 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 36: /* ALIGN_EQ_NAT */ -#line 259 "src/ast-parser.y" /* yacc.c:1257 */ +#line 256 "src/ast-parser.y" /* yacc.c:1257 */ {} -#line 1692 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 1689 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 75: /* non_empty_text_list */ -#line 282 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_text_list(parser->allocator, &((*yyvaluep).text_list)); } -#line 1698 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 279 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_text_list(&((*yyvaluep).text_list)); } +#line 1695 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 76: /* text_list */ -#line 282 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_text_list(parser->allocator, &((*yyvaluep).text_list)); } -#line 1704 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 279 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_text_list(&((*yyvaluep).text_list)); } +#line 1701 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 77: /* quoted_text */ -#line 281 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_string_slice(parser->allocator, &((*yyvaluep).text)); } -#line 1710 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 278 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_string_slice(&((*yyvaluep).text)); } +#line 1707 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 78: /* value_type_list */ -#line 283 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_type_vector(parser->allocator, &((*yyvaluep).types)); } -#line 1716 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 280 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_type_vector(&((*yyvaluep).types)); } +#line 1713 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 81: /* func_type */ -#line 273 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_func_signature(parser->allocator, &((*yyvaluep).func_sig)); } -#line 1722 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 270 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_func_signature(&((*yyvaluep).func_sig)); } +#line 1719 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 82: /* func_sig */ -#line 273 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_func_signature(parser->allocator, &((*yyvaluep).func_sig)); } -#line 1728 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 270 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_func_signature(&((*yyvaluep).func_sig)); } +#line 1725 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 86: /* type_use */ -#line 285 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_var(parser->allocator, &((*yyvaluep).var)); } -#line 1734 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 282 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_var(&((*yyvaluep).var)); } +#line 1731 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 88: /* literal */ -#line 279 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_string_slice(parser->allocator, &((*yyvaluep).literal).text); } -#line 1740 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 276 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_string_slice(&((*yyvaluep).literal).text); } +#line 1737 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 89: /* var */ -#line 285 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_var(parser->allocator, &((*yyvaluep).var)); } -#line 1746 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 282 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_var(&((*yyvaluep).var)); } +#line 1743 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 90: /* var_list */ -#line 284 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_var_vector_and_elements(parser->allocator, &((*yyvaluep).vars)); } -#line 1752 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 281 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_var_vector_and_elements(&((*yyvaluep).vars)); } +#line 1749 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 91: /* bind_var_opt */ -#line 281 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_string_slice(parser->allocator, &((*yyvaluep).text)); } -#line 1758 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 278 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_string_slice(&((*yyvaluep).text)); } +#line 1755 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 92: /* bind_var */ -#line 281 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_string_slice(parser->allocator, &((*yyvaluep).text)); } -#line 1764 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 278 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_string_slice(&((*yyvaluep).text)); } +#line 1761 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 93: /* labeling_opt */ -#line 281 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_string_slice(parser->allocator, &((*yyvaluep).text)); } -#line 1770 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 278 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_string_slice(&((*yyvaluep).text)); } +#line 1767 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 96: /* instr */ -#line 270 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_expr_list(parser->allocator, ((*yyvaluep).expr_list).first); } -#line 1776 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 267 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_expr_list(((*yyvaluep).expr_list).first); } +#line 1773 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 97: /* plain_instr */ -#line 269 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_expr(parser->allocator, ((*yyvaluep).expr)); } -#line 1782 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 266 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_expr(((*yyvaluep).expr)); } +#line 1779 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 98: /* block_instr */ -#line 269 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_expr(parser->allocator, ((*yyvaluep).expr)); } -#line 1788 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 266 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_expr(((*yyvaluep).expr)); } +#line 1785 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 99: /* block */ -#line 260 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_block(parser->allocator, &((*yyvaluep).block)); } -#line 1794 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 257 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_block(&((*yyvaluep).block)); } +#line 1791 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 100: /* expr */ -#line 270 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_expr_list(parser->allocator, ((*yyvaluep).expr_list).first); } -#line 1800 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 267 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_expr_list(((*yyvaluep).expr_list).first); } +#line 1797 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 101: /* expr1 */ -#line 270 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_expr_list(parser->allocator, ((*yyvaluep).expr_list).first); } -#line 1806 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 267 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_expr_list(((*yyvaluep).expr_list).first); } +#line 1803 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 102: /* if_ */ -#line 270 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_expr_list(parser->allocator, ((*yyvaluep).expr_list).first); } -#line 1812 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 267 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_expr_list(((*yyvaluep).expr_list).first); } +#line 1809 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 103: /* instr_list */ -#line 270 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_expr_list(parser->allocator, ((*yyvaluep).expr_list).first); } -#line 1818 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 267 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_expr_list(((*yyvaluep).expr_list).first); } +#line 1815 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 104: /* expr_list */ -#line 270 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_expr_list(parser->allocator, ((*yyvaluep).expr_list).first); } -#line 1824 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 267 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_expr_list(((*yyvaluep).expr_list).first); } +#line 1821 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 105: /* const_expr */ -#line 270 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_expr_list(parser->allocator, ((*yyvaluep).expr_list).first); } -#line 1830 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 267 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_expr_list(((*yyvaluep).expr_list).first); } +#line 1827 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 106: /* func_fields */ -#line 271 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_func_fields(parser->allocator, ((*yyvaluep).func_fields)); } -#line 1836 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 268 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_func_fields(((*yyvaluep).func_fields)); } +#line 1833 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 107: /* func_body */ -#line 271 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_func_fields(parser->allocator, ((*yyvaluep).func_fields)); } -#line 1842 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 268 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_func_fields(((*yyvaluep).func_fields)); } +#line 1839 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 108: /* func_info */ -#line 272 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_func(parser->allocator, ((*yyvaluep).func)); wabt_free(parser->allocator, ((*yyvaluep).func)); } -#line 1848 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 269 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_func(((*yyvaluep).func)); wabt_free(((*yyvaluep).func)); } +#line 1845 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 109: /* func */ -#line 266 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_exported_func(parser->allocator, &((*yyvaluep).exported_func)); } -#line 1854 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 263 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_exported_func(&((*yyvaluep).exported_func)); } +#line 1851 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 110: /* offset */ -#line 270 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_expr_list(parser->allocator, ((*yyvaluep).expr_list).first); } -#line 1860 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 267 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_expr_list(((*yyvaluep).expr_list).first); } +#line 1857 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 111: /* elem */ -#line 264 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_elem_segment(parser->allocator, &((*yyvaluep).elem_segment)); } -#line 1866 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 261 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_elem_segment(&((*yyvaluep).elem_segment)); } +#line 1863 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 112: /* table */ -#line 268 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_exported_table(parser->allocator, &((*yyvaluep).exported_table)); } -#line 1872 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 265 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_exported_table(&((*yyvaluep).exported_table)); } +#line 1869 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 113: /* data */ -#line 276 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_data_segment(parser->allocator, &((*yyvaluep).data_segment)); } -#line 1878 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 273 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_data_segment(&((*yyvaluep).data_segment)); } +#line 1875 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 114: /* memory */ -#line 267 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_exported_memory(parser->allocator, &((*yyvaluep).exported_memory)); } -#line 1884 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 264 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_exported_memory(&((*yyvaluep).exported_memory)); } +#line 1881 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 116: /* import_kind */ -#line 275 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_import(parser->allocator, ((*yyvaluep).import)); wabt_free(parser->allocator, ((*yyvaluep).import)); } -#line 1890 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 272 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_import(((*yyvaluep).import)); wabt_free(((*yyvaluep).import)); } +#line 1887 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 117: /* import */ -#line 275 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_import(parser->allocator, ((*yyvaluep).import)); wabt_free(parser->allocator, ((*yyvaluep).import)); } -#line 1896 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 272 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_import(((*yyvaluep).import)); wabt_free(((*yyvaluep).import)); } +#line 1893 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 118: /* inline_import */ -#line 275 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_import(parser->allocator, ((*yyvaluep).import)); wabt_free(parser->allocator, ((*yyvaluep).import)); } -#line 1902 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 272 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_import(((*yyvaluep).import)); wabt_free(((*yyvaluep).import)); } +#line 1899 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 119: /* export_kind */ -#line 265 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_export(parser->allocator, &((*yyvaluep).export_)); } -#line 1908 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 262 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_export(&((*yyvaluep).export_)); } +#line 1905 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 120: /* export */ -#line 265 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_export(parser->allocator, &((*yyvaluep).export_)); } -#line 1914 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 262 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_export(&((*yyvaluep).export_)); } +#line 1911 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 123: /* type_def */ -#line 274 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_func_type(parser->allocator, &((*yyvaluep).func_type)); } -#line 1920 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 271 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_func_type(&((*yyvaluep).func_type)); } +#line 1917 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 124: /* start */ -#line 285 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_var(parser->allocator, &((*yyvaluep).var)); } -#line 1926 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 282 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_var(&((*yyvaluep).var)); } +#line 1923 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 125: /* module_fields */ -#line 277 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_module(parser->allocator, ((*yyvaluep).module)); wabt_free(parser->allocator, ((*yyvaluep).module)); } -#line 1932 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 274 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_module(((*yyvaluep).module)); wabt_free(((*yyvaluep).module)); } +#line 1929 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 126: /* raw_module */ -#line 278 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_raw_module(parser->allocator, &((*yyvaluep).raw_module)); } -#line 1938 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 275 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_raw_module(&((*yyvaluep).raw_module)); } +#line 1935 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 127: /* module */ -#line 277 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_module(parser->allocator, ((*yyvaluep).module)); wabt_free(parser->allocator, ((*yyvaluep).module)); } -#line 1944 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 274 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_module(((*yyvaluep).module)); wabt_free(((*yyvaluep).module)); } +#line 1941 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 128: /* script_var_opt */ -#line 285 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_var(parser->allocator, &((*yyvaluep).var)); } -#line 1950 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 282 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_var(&((*yyvaluep).var)); } +#line 1947 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 130: /* assertion */ -#line 261 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_command(parser->allocator, ((*yyvaluep).command)); wabt_free(parser->allocator, ((*yyvaluep).command)); } -#line 1956 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 258 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_command(((*yyvaluep).command)); wabt_free(((*yyvaluep).command)); } +#line 1953 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 131: /* cmd */ -#line 261 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_command(parser->allocator, ((*yyvaluep).command)); wabt_free(parser->allocator, ((*yyvaluep).command)); } -#line 1962 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 258 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_command(((*yyvaluep).command)); wabt_free(((*yyvaluep).command)); } +#line 1959 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 132: /* cmd_list */ -#line 262 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_command_vector_and_elements(parser->allocator, &((*yyvaluep).commands)); } -#line 1968 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 259 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_command_vector_and_elements(&((*yyvaluep).commands)); } +#line 1965 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 134: /* const_list */ -#line 263 "src/ast-parser.y" /* yacc.c:1257 */ - { wabt_destroy_const_vector(parser->allocator, &((*yyvaluep).consts)); } -#line 1974 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 260 "src/ast-parser.y" /* yacc.c:1257 */ + { wabt_destroy_const_vector(&((*yyvaluep).consts)); } +#line 1971 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; case 135: /* script */ -#line 280 "src/ast-parser.y" /* yacc.c:1257 */ +#line 277 "src/ast-parser.y" /* yacc.c:1257 */ { wabt_destroy_script(&((*yyvaluep).script)); } -#line 1980 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ +#line 1977 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1257 */ break; @@ -2268,37 +2265,37 @@ yyreduce: switch (yyn) { case 2: -#line 298 "src/ast-parser.y" /* yacc.c:1646 */ +#line 295 "src/ast-parser.y" /* yacc.c:1646 */ { - WabtTextListNode* node = new_text_list_node(parser->allocator); + WabtTextListNode* node = new_text_list_node(); DUPTEXT(node->text, (yyvsp[0].text)); node->next = NULL; (yyval.text_list).first = (yyval.text_list).last = node; } -#line 2279 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2276 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 3: -#line 304 "src/ast-parser.y" /* yacc.c:1646 */ +#line 301 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.text_list) = (yyvsp[-1].text_list); - WabtTextListNode* node = new_text_list_node(parser->allocator); + WabtTextListNode* node = new_text_list_node(); DUPTEXT(node->text, (yyvsp[0].text)); node->next = NULL; (yyval.text_list).last->next = node; (yyval.text_list).last = node; } -#line 2292 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2289 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 4: -#line 314 "src/ast-parser.y" /* yacc.c:1646 */ +#line 311 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.text_list).first = (yyval.text_list).last = NULL; } -#line 2298 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2295 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 6: -#line 319 "src/ast-parser.y" /* yacc.c:1646 */ +#line 316 "src/ast-parser.y" /* yacc.c:1646 */ { WabtTextListNode node; node.text = (yyvsp[0].text); @@ -2308,134 +2305,134 @@ yyreduce: text_list.last = &node; void* data; size_t size; - dup_text_list(parser->allocator, &text_list, &data, &size); + dup_text_list(&text_list, &data, &size); (yyval.text).start = data; (yyval.text).length = size; } -#line 2316 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2313 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 7: -#line 337 "src/ast-parser.y" /* yacc.c:1646 */ +#line 334 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.types)); } -#line 2322 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2319 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 8: -#line 338 "src/ast-parser.y" /* yacc.c:1646 */ +#line 335 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.types) = (yyvsp[-1].types); - wabt_append_type_value(parser->allocator, &(yyval.types), &(yyvsp[0].type)); + wabt_append_type_value(&(yyval.types), &(yyvsp[0].type)); } -#line 2331 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2328 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 9: -#line 344 "src/ast-parser.y" /* yacc.c:1646 */ +#line 341 "src/ast-parser.y" /* yacc.c:1646 */ {} -#line 2337 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2334 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 10: -#line 347 "src/ast-parser.y" /* yacc.c:1646 */ +#line 344 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.global)); (yyval.global).type = (yyvsp[0].type); (yyval.global).mutable_ = WABT_FALSE; } -#line 2347 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2344 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 11: -#line 352 "src/ast-parser.y" /* yacc.c:1646 */ +#line 349 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.global)); (yyval.global).type = (yyvsp[-1].type); (yyval.global).mutable_ = WABT_TRUE; } -#line 2357 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2354 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 12: -#line 359 "src/ast-parser.y" /* yacc.c:1646 */ +#line 356 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.func_sig) = (yyvsp[-1].func_sig); } -#line 2363 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2360 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 13: -#line 362 "src/ast-parser.y" /* yacc.c:1646 */ +#line 359 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.func_sig)); } -#line 2369 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2366 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 14: -#line 363 "src/ast-parser.y" /* yacc.c:1646 */ +#line 360 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.func_sig)); (yyval.func_sig).param_types = (yyvsp[-1].types); } -#line 2378 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2375 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 15: -#line 367 "src/ast-parser.y" /* yacc.c:1646 */ +#line 364 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.func_sig)); (yyval.func_sig).param_types = (yyvsp[-5].types); (yyval.func_sig).result_types = (yyvsp[-1].types); } -#line 2388 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2385 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 16: -#line 372 "src/ast-parser.y" /* yacc.c:1646 */ +#line 369 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.func_sig)); (yyval.func_sig).result_types = (yyvsp[-1].types); } -#line 2397 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2394 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 17: -#line 379 "src/ast-parser.y" /* yacc.c:1646 */ +#line 376 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.table).elem_limits = (yyvsp[-1].limits); } -#line 2403 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2400 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 18: -#line 382 "src/ast-parser.y" /* yacc.c:1646 */ +#line 379 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.memory).page_limits = (yyvsp[0].limits); } -#line 2409 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2406 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 19: -#line 385 "src/ast-parser.y" /* yacc.c:1646 */ +#line 382 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.limits).has_max = WABT_FALSE; (yyval.limits).initial = (yyvsp[0].u64); (yyval.limits).max = 0; } -#line 2419 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2416 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 20: -#line 390 "src/ast-parser.y" /* yacc.c:1646 */ +#line 387 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.limits).has_max = WABT_TRUE; (yyval.limits).initial = (yyvsp[-1].u64); (yyval.limits).max = (yyvsp[0].u64); } -#line 2429 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2426 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 21: -#line 397 "src/ast-parser.y" /* yacc.c:1646 */ +#line 394 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.var) = (yyvsp[-1].var); } -#line 2435 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2432 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 22: -#line 403 "src/ast-parser.y" /* yacc.c:1646 */ +#line 400 "src/ast-parser.y" /* yacc.c:1646 */ { if (WABT_FAILED(wabt_parse_uint64((yyvsp[0].literal).text.start, (yyvsp[0].literal).text.start + (yyvsp[0].literal).text.length, &(yyval.u64)))) { @@ -2444,97 +2441,97 @@ yyreduce: WABT_PRINTF_STRING_SLICE_ARG((yyvsp[0].literal).text)); } } -#line 2448 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2445 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 23: -#line 414 "src/ast-parser.y" /* yacc.c:1646 */ +#line 411 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.literal).type = (yyvsp[0].literal).type; DUPTEXT((yyval.literal).text, (yyvsp[0].literal).text); } -#line 2457 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2454 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 24: -#line 418 "src/ast-parser.y" /* yacc.c:1646 */ +#line 415 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.literal).type = (yyvsp[0].literal).type; DUPTEXT((yyval.literal).text, (yyvsp[0].literal).text); } -#line 2466 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2463 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 25: -#line 422 "src/ast-parser.y" /* yacc.c:1646 */ +#line 419 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.literal).type = (yyvsp[0].literal).type; DUPTEXT((yyval.literal).text, (yyvsp[0].literal).text); } -#line 2475 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2472 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 26: -#line 429 "src/ast-parser.y" /* yacc.c:1646 */ +#line 426 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.var).loc = (yylsp[0]); (yyval.var).type = WABT_VAR_TYPE_INDEX; (yyval.var).index = (yyvsp[0].u64); } -#line 2485 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2482 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 27: -#line 434 "src/ast-parser.y" /* yacc.c:1646 */ +#line 431 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.var).loc = (yylsp[0]); (yyval.var).type = WABT_VAR_TYPE_NAME; DUPTEXT((yyval.var).name, (yyvsp[0].text)); } -#line 2495 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2492 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 28: -#line 441 "src/ast-parser.y" /* yacc.c:1646 */ +#line 438 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.vars)); } -#line 2501 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2498 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 29: -#line 442 "src/ast-parser.y" /* yacc.c:1646 */ +#line 439 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.vars) = (yyvsp[-1].vars); - wabt_append_var_value(parser->allocator, &(yyval.vars), &(yyvsp[0].var)); + wabt_append_var_value(&(yyval.vars), &(yyvsp[0].var)); } -#line 2510 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2507 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 30: -#line 448 "src/ast-parser.y" /* yacc.c:1646 */ +#line 445 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.text)); } -#line 2516 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2513 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 32: -#line 452 "src/ast-parser.y" /* yacc.c:1646 */ +#line 449 "src/ast-parser.y" /* yacc.c:1646 */ { DUPTEXT((yyval.text), (yyvsp[0].text)); } -#line 2522 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2519 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 33: -#line 456 "src/ast-parser.y" /* yacc.c:1646 */ +#line 453 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.text)); } -#line 2528 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2525 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 35: -#line 461 "src/ast-parser.y" /* yacc.c:1646 */ +#line 458 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.u64) = 0; } -#line 2534 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2531 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 36: -#line 462 "src/ast-parser.y" /* yacc.c:1646 */ +#line 459 "src/ast-parser.y" /* yacc.c:1646 */ { if (WABT_FAILED(wabt_parse_int64((yyvsp[0].text).start, (yyvsp[0].text).start + (yyvsp[0].text).length, &(yyval.u64), WABT_PARSE_SIGNED_AND_UNSIGNED))) { @@ -2543,17 +2540,17 @@ yyreduce: WABT_PRINTF_STRING_SLICE_ARG((yyvsp[0].text))); } } -#line 2547 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2544 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 37: -#line 472 "src/ast-parser.y" /* yacc.c:1646 */ +#line 469 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.u32) = USE_NATURAL_ALIGNMENT; } -#line 2553 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2550 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 38: -#line 473 "src/ast-parser.y" /* yacc.c:1646 */ +#line 470 "src/ast-parser.y" /* yacc.c:1646 */ { if (WABT_FAILED(wabt_parse_int32((yyvsp[0].text).start, (yyvsp[0].text).start + (yyvsp[0].text).length, &(yyval.u32), WABT_PARSE_UNSIGNED_ONLY))) { @@ -2562,184 +2559,184 @@ yyreduce: WABT_PRINTF_STRING_SLICE_ARG((yyvsp[0].text))); } } -#line 2566 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2563 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 39: -#line 484 "src/ast-parser.y" /* yacc.c:1646 */ +#line 481 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.expr_list) = join_exprs1(&(yylsp[0]), (yyvsp[0].expr)); } -#line 2572 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2569 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 40: -#line 485 "src/ast-parser.y" /* yacc.c:1646 */ +#line 482 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.expr_list) = join_exprs1(&(yylsp[0]), (yyvsp[0].expr)); } -#line 2578 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2575 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 41: -#line 486 "src/ast-parser.y" /* yacc.c:1646 */ +#line 483 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.expr_list) = (yyvsp[0].expr_list); } -#line 2584 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2581 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 42: -#line 489 "src/ast-parser.y" /* yacc.c:1646 */ +#line 486 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = wabt_new_unreachable_expr(parser->allocator); + (yyval.expr) = wabt_new_unreachable_expr(); } -#line 2592 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2589 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 43: -#line 492 "src/ast-parser.y" /* yacc.c:1646 */ +#line 489 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = wabt_new_nop_expr(parser->allocator); + (yyval.expr) = wabt_new_nop_expr(); } -#line 2600 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2597 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 44: -#line 495 "src/ast-parser.y" /* yacc.c:1646 */ +#line 492 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = wabt_new_drop_expr(parser->allocator); + (yyval.expr) = wabt_new_drop_expr(); } -#line 2608 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2605 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 45: -#line 498 "src/ast-parser.y" /* yacc.c:1646 */ +#line 495 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = wabt_new_select_expr(parser->allocator); + (yyval.expr) = wabt_new_select_expr(); } -#line 2616 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2613 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 46: -#line 501 "src/ast-parser.y" /* yacc.c:1646 */ +#line 498 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = wabt_new_br_expr(parser->allocator); + (yyval.expr) = wabt_new_br_expr(); (yyval.expr)->br.var = (yyvsp[0].var); } -#line 2625 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2622 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 47: -#line 505 "src/ast-parser.y" /* yacc.c:1646 */ +#line 502 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = wabt_new_br_if_expr(parser->allocator); + (yyval.expr) = wabt_new_br_if_expr(); (yyval.expr)->br_if.var = (yyvsp[0].var); } -#line 2634 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2631 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 48: -#line 509 "src/ast-parser.y" /* yacc.c:1646 */ +#line 506 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = wabt_new_br_table_expr(parser->allocator); + (yyval.expr) = wabt_new_br_table_expr(); (yyval.expr)->br_table.targets = (yyvsp[-1].vars); (yyval.expr)->br_table.default_target = (yyvsp[0].var); } -#line 2644 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2641 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 49: -#line 514 "src/ast-parser.y" /* yacc.c:1646 */ +#line 511 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = wabt_new_return_expr(parser->allocator); + (yyval.expr) = wabt_new_return_expr(); } -#line 2652 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2649 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 50: -#line 517 "src/ast-parser.y" /* yacc.c:1646 */ +#line 514 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = wabt_new_call_expr(parser->allocator); + (yyval.expr) = wabt_new_call_expr(); (yyval.expr)->call.var = (yyvsp[0].var); } -#line 2661 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2658 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 51: -#line 521 "src/ast-parser.y" /* yacc.c:1646 */ +#line 518 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = wabt_new_call_indirect_expr(parser->allocator); + (yyval.expr) = wabt_new_call_indirect_expr(); (yyval.expr)->call_indirect.var = (yyvsp[0].var); } -#line 2670 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2667 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 52: -#line 525 "src/ast-parser.y" /* yacc.c:1646 */ +#line 522 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = wabt_new_get_local_expr(parser->allocator); + (yyval.expr) = wabt_new_get_local_expr(); (yyval.expr)->get_local.var = (yyvsp[0].var); } -#line 2679 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2676 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 53: -#line 529 "src/ast-parser.y" /* yacc.c:1646 */ +#line 526 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = wabt_new_set_local_expr(parser->allocator); + (yyval.expr) = wabt_new_set_local_expr(); (yyval.expr)->set_local.var = (yyvsp[0].var); } -#line 2688 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2685 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 54: -#line 533 "src/ast-parser.y" /* yacc.c:1646 */ +#line 530 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = wabt_new_tee_local_expr(parser->allocator); + (yyval.expr) = wabt_new_tee_local_expr(); (yyval.expr)->tee_local.var = (yyvsp[0].var); } -#line 2697 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2694 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 55: -#line 537 "src/ast-parser.y" /* yacc.c:1646 */ +#line 534 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = wabt_new_get_global_expr(parser->allocator); + (yyval.expr) = wabt_new_get_global_expr(); (yyval.expr)->get_global.var = (yyvsp[0].var); } -#line 2706 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2703 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 56: -#line 541 "src/ast-parser.y" /* yacc.c:1646 */ +#line 538 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = wabt_new_set_global_expr(parser->allocator); + (yyval.expr) = wabt_new_set_global_expr(); (yyval.expr)->set_global.var = (yyvsp[0].var); } -#line 2715 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2712 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 57: -#line 545 "src/ast-parser.y" /* yacc.c:1646 */ +#line 542 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = wabt_new_load_expr(parser->allocator); + (yyval.expr) = wabt_new_load_expr(); (yyval.expr)->load.opcode = (yyvsp[-2].opcode); (yyval.expr)->load.offset = (yyvsp[-1].u64); (yyval.expr)->load.align = (yyvsp[0].u32); } -#line 2726 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2723 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 58: -#line 551 "src/ast-parser.y" /* yacc.c:1646 */ +#line 548 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = wabt_new_store_expr(parser->allocator); + (yyval.expr) = wabt_new_store_expr(); (yyval.expr)->store.opcode = (yyvsp[-2].opcode); (yyval.expr)->store.offset = (yyvsp[-1].u64); (yyval.expr)->store.align = (yyvsp[0].u32); } -#line 2737 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2734 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 59: -#line 557 "src/ast-parser.y" /* yacc.c:1646 */ +#line 554 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = wabt_new_const_expr(parser->allocator); + (yyval.expr) = wabt_new_const_expr(); (yyval.expr)->const_.loc = (yylsp[-1]); if (WABT_FAILED(parse_const((yyvsp[-1].type), (yyvsp[0].literal).type, (yyvsp[0].literal).text.start, (yyvsp[0].literal).text.start + (yyvsp[0].literal).text.length, @@ -2748,157 +2745,157 @@ yyreduce: "invalid literal \"" PRIstringslice "\"", WABT_PRINTF_STRING_SLICE_ARG((yyvsp[0].literal).text)); } - wabt_free(parser->allocator, (char*)(yyvsp[0].literal).text.start); + wabt_free((char*)(yyvsp[0].literal).text.start); } -#line 2754 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2751 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 60: -#line 569 "src/ast-parser.y" /* yacc.c:1646 */ +#line 566 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = wabt_new_unary_expr(parser->allocator); + (yyval.expr) = wabt_new_unary_expr(); (yyval.expr)->unary.opcode = (yyvsp[0].opcode); } -#line 2763 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2760 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 61: -#line 573 "src/ast-parser.y" /* yacc.c:1646 */ +#line 570 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = wabt_new_binary_expr(parser->allocator); + (yyval.expr) = wabt_new_binary_expr(); (yyval.expr)->binary.opcode = (yyvsp[0].opcode); } -#line 2772 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2769 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 62: -#line 577 "src/ast-parser.y" /* yacc.c:1646 */ +#line 574 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = wabt_new_compare_expr(parser->allocator); + (yyval.expr) = wabt_new_compare_expr(); (yyval.expr)->compare.opcode = (yyvsp[0].opcode); } -#line 2781 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2778 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 63: -#line 581 "src/ast-parser.y" /* yacc.c:1646 */ +#line 578 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = wabt_new_convert_expr(parser->allocator); + (yyval.expr) = wabt_new_convert_expr(); (yyval.expr)->convert.opcode = (yyvsp[0].opcode); } -#line 2790 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2787 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 64: -#line 585 "src/ast-parser.y" /* yacc.c:1646 */ +#line 582 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = wabt_new_current_memory_expr(parser->allocator); + (yyval.expr) = wabt_new_current_memory_expr(); } -#line 2798 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2795 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 65: -#line 588 "src/ast-parser.y" /* yacc.c:1646 */ +#line 585 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = wabt_new_grow_memory_expr(parser->allocator); + (yyval.expr) = wabt_new_grow_memory_expr(); } -#line 2806 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2803 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 66: -#line 593 "src/ast-parser.y" /* yacc.c:1646 */ +#line 590 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = wabt_new_block_expr(parser->allocator); + (yyval.expr) = wabt_new_block_expr(); (yyval.expr)->block = (yyvsp[-2].block); (yyval.expr)->block.label = (yyvsp[-3].text); CHECK_END_LABEL((yylsp[0]), (yyval.expr)->block.label, (yyvsp[0].text)); } -#line 2817 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2814 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 67: -#line 599 "src/ast-parser.y" /* yacc.c:1646 */ +#line 596 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = wabt_new_loop_expr(parser->allocator); + (yyval.expr) = wabt_new_loop_expr(); (yyval.expr)->loop = (yyvsp[-2].block); (yyval.expr)->loop.label = (yyvsp[-3].text); CHECK_END_LABEL((yylsp[0]), (yyval.expr)->block.label, (yyvsp[0].text)); } -#line 2828 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2825 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 68: -#line 605 "src/ast-parser.y" /* yacc.c:1646 */ +#line 602 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = wabt_new_if_expr(parser->allocator); + (yyval.expr) = wabt_new_if_expr(); (yyval.expr)->if_.true_ = (yyvsp[-2].block); (yyval.expr)->if_.true_.label = (yyvsp[-3].text); CHECK_END_LABEL((yylsp[0]), (yyval.expr)->block.label, (yyvsp[0].text)); } -#line 2839 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2836 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 69: -#line 611 "src/ast-parser.y" /* yacc.c:1646 */ +#line 608 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = wabt_new_if_expr(parser->allocator); + (yyval.expr) = wabt_new_if_expr(); (yyval.expr)->if_.true_ = (yyvsp[-5].block); (yyval.expr)->if_.true_.label = (yyvsp[-6].text); (yyval.expr)->if_.false_ = (yyvsp[-2].expr_list).first; CHECK_END_LABEL((yylsp[-3]), (yyval.expr)->block.label, (yyvsp[-3].text)); CHECK_END_LABEL((yylsp[0]), (yyval.expr)->block.label, (yyvsp[0].text)); } -#line 2852 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2849 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 70: -#line 621 "src/ast-parser.y" /* yacc.c:1646 */ +#line 618 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.block)); (yyval.block).sig = (yyvsp[-1].types); (yyval.block).first = (yyvsp[0].expr_list).first; } -#line 2862 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2859 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 71: -#line 629 "src/ast-parser.y" /* yacc.c:1646 */ +#line 626 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.expr_list) = (yyvsp[-1].expr_list); } -#line 2868 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2865 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 72: -#line 633 "src/ast-parser.y" /* yacc.c:1646 */ +#line 630 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.expr_list) = join_exprs2(&(yylsp[-1]), &(yyvsp[0].expr_list), (yyvsp[-1].expr)); } -#line 2876 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2873 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 73: -#line 636 "src/ast-parser.y" /* yacc.c:1646 */ +#line 633 "src/ast-parser.y" /* yacc.c:1646 */ { - WabtExpr* expr = wabt_new_block_expr(parser->allocator); + WabtExpr* expr = wabt_new_block_expr(); expr->block = (yyvsp[0].block); expr->block.label = (yyvsp[-1].text); (yyval.expr_list) = join_exprs1(&(yylsp[-2]), expr); } -#line 2887 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2884 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 74: -#line 642 "src/ast-parser.y" /* yacc.c:1646 */ +#line 639 "src/ast-parser.y" /* yacc.c:1646 */ { - WabtExpr* expr = wabt_new_loop_expr(parser->allocator); + WabtExpr* expr = wabt_new_loop_expr(); expr->loop = (yyvsp[0].block); expr->loop.label = (yyvsp[-1].text); (yyval.expr_list) = join_exprs1(&(yylsp[-2]), expr); } -#line 2898 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2895 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 75: -#line 648 "src/ast-parser.y" /* yacc.c:1646 */ +#line 645 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.expr_list) = (yyvsp[0].expr_list); WabtExpr* if_ = (yyvsp[0].expr_list).last; @@ -2906,180 +2903,180 @@ yyreduce: if_->if_.true_.label = (yyvsp[-2].text); if_->if_.true_.sig = (yyvsp[-1].types); } -#line 2910 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2907 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 76: -#line 657 "src/ast-parser.y" /* yacc.c:1646 */ +#line 654 "src/ast-parser.y" /* yacc.c:1646 */ { - WabtExpr* expr = wabt_new_if_expr(parser->allocator); + WabtExpr* expr = wabt_new_if_expr(); expr->if_.true_.first = (yyvsp[-5].expr_list).first; expr->if_.false_ = (yyvsp[-1].expr_list).first; (yyval.expr_list) = join_exprs1(&(yylsp[-7]), expr); } -#line 2921 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2918 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 77: -#line 663 "src/ast-parser.y" /* yacc.c:1646 */ +#line 660 "src/ast-parser.y" /* yacc.c:1646 */ { - WabtExpr* expr = wabt_new_if_expr(parser->allocator); + WabtExpr* expr = wabt_new_if_expr(); expr->if_.true_.first = (yyvsp[-1].expr_list).first; (yyval.expr_list) = join_exprs1(&(yylsp[-3]), expr); } -#line 2931 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2928 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 78: -#line 668 "src/ast-parser.y" /* yacc.c:1646 */ +#line 665 "src/ast-parser.y" /* yacc.c:1646 */ { - WabtExpr* expr = wabt_new_if_expr(parser->allocator); + WabtExpr* expr = wabt_new_if_expr(); expr->if_.true_.first = (yyvsp[-5].expr_list).first; expr->if_.false_ = (yyvsp[-1].expr_list).first; (yyval.expr_list) = join_exprs2(&(yylsp[-8]), &(yyvsp[-8].expr_list), expr); } -#line 2942 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2939 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 79: -#line 674 "src/ast-parser.y" /* yacc.c:1646 */ +#line 671 "src/ast-parser.y" /* yacc.c:1646 */ { - WabtExpr* expr = wabt_new_if_expr(parser->allocator); + WabtExpr* expr = wabt_new_if_expr(); expr->if_.true_.first = (yyvsp[-1].expr_list).first; (yyval.expr_list) = join_exprs2(&(yylsp[-4]), &(yyvsp[-4].expr_list), expr); } -#line 2952 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2949 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 80: -#line 679 "src/ast-parser.y" /* yacc.c:1646 */ +#line 676 "src/ast-parser.y" /* yacc.c:1646 */ { - WabtExpr* expr = wabt_new_if_expr(parser->allocator); + WabtExpr* expr = wabt_new_if_expr(); expr->if_.true_.first = (yyvsp[-1].expr_list).first; expr->if_.false_ = (yyvsp[0].expr_list).first; (yyval.expr_list) = join_exprs2(&(yylsp[-2]), &(yyvsp[-2].expr_list), expr); } -#line 2963 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2960 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 81: -#line 685 "src/ast-parser.y" /* yacc.c:1646 */ +#line 682 "src/ast-parser.y" /* yacc.c:1646 */ { - WabtExpr* expr = wabt_new_if_expr(parser->allocator); + WabtExpr* expr = wabt_new_if_expr(); expr->if_.true_.first = (yyvsp[0].expr_list).first; (yyval.expr_list) = join_exprs2(&(yylsp[-1]), &(yyvsp[-1].expr_list), expr); } -#line 2973 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2970 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 82: -#line 693 "src/ast-parser.y" /* yacc.c:1646 */ +#line 690 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.expr_list)); } -#line 2979 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2976 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 83: -#line 694 "src/ast-parser.y" /* yacc.c:1646 */ +#line 691 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.expr_list).first = (yyvsp[-1].expr_list).first; (yyvsp[-1].expr_list).last->next = (yyvsp[0].expr_list).first; (yyval.expr_list).last = (yyvsp[0].expr_list).last ? (yyvsp[0].expr_list).last : (yyvsp[-1].expr_list).last; (yyval.expr_list).size = (yyvsp[-1].expr_list).size + (yyvsp[0].expr_list).size; } -#line 2990 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2987 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 84: -#line 702 "src/ast-parser.y" /* yacc.c:1646 */ +#line 699 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.expr_list)); } -#line 2996 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 2993 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 85: -#line 703 "src/ast-parser.y" /* yacc.c:1646 */ +#line 700 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.expr_list).first = (yyvsp[-1].expr_list).first; (yyvsp[-1].expr_list).last->next = (yyvsp[0].expr_list).first; (yyval.expr_list).last = (yyvsp[0].expr_list).last ? (yyvsp[0].expr_list).last : (yyvsp[-1].expr_list).last; (yyval.expr_list).size = (yyvsp[-1].expr_list).size + (yyvsp[0].expr_list).size; } -#line 3007 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3004 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 88: -#line 717 "src/ast-parser.y" /* yacc.c:1646 */ +#line 714 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.func_fields) = new_func_field(parser->allocator); + (yyval.func_fields) = new_func_field(); (yyval.func_fields)->type = WABT_FUNC_FIELD_TYPE_RESULT_TYPES; (yyval.func_fields)->types = (yyvsp[-2].types); (yyval.func_fields)->next = (yyvsp[0].func_fields); } -#line 3018 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3015 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 89: -#line 723 "src/ast-parser.y" /* yacc.c:1646 */ +#line 720 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.func_fields) = new_func_field(parser->allocator); + (yyval.func_fields) = new_func_field(); (yyval.func_fields)->type = WABT_FUNC_FIELD_TYPE_PARAM_TYPES; (yyval.func_fields)->types = (yyvsp[-2].types); (yyval.func_fields)->next = (yyvsp[0].func_fields); } -#line 3029 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3026 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 90: -#line 729 "src/ast-parser.y" /* yacc.c:1646 */ +#line 726 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.func_fields) = new_func_field(parser->allocator); + (yyval.func_fields) = new_func_field(); (yyval.func_fields)->type = WABT_FUNC_FIELD_TYPE_BOUND_PARAM; (yyval.func_fields)->bound_type.loc = (yylsp[-4]); (yyval.func_fields)->bound_type.name = (yyvsp[-3].text); (yyval.func_fields)->bound_type.type = (yyvsp[-2].type); (yyval.func_fields)->next = (yyvsp[0].func_fields); } -#line 3042 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3039 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 91: -#line 739 "src/ast-parser.y" /* yacc.c:1646 */ +#line 736 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.func_fields) = new_func_field(parser->allocator); + (yyval.func_fields) = new_func_field(); (yyval.func_fields)->type = WABT_FUNC_FIELD_TYPE_EXPRS; (yyval.func_fields)->first_expr = (yyvsp[0].expr_list).first; (yyval.func_fields)->next = NULL; } -#line 3053 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3050 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 92: -#line 745 "src/ast-parser.y" /* yacc.c:1646 */ +#line 742 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.func_fields) = new_func_field(parser->allocator); + (yyval.func_fields) = new_func_field(); (yyval.func_fields)->type = WABT_FUNC_FIELD_TYPE_LOCAL_TYPES; (yyval.func_fields)->types = (yyvsp[-2].types); (yyval.func_fields)->next = (yyvsp[0].func_fields); } -#line 3064 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3061 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 93: -#line 751 "src/ast-parser.y" /* yacc.c:1646 */ +#line 748 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.func_fields) = new_func_field(parser->allocator); + (yyval.func_fields) = new_func_field(); (yyval.func_fields)->type = WABT_FUNC_FIELD_TYPE_BOUND_LOCAL; (yyval.func_fields)->bound_type.loc = (yylsp[-4]); (yyval.func_fields)->bound_type.name = (yyvsp[-3].text); (yyval.func_fields)->bound_type.type = (yyvsp[-2].type); (yyval.func_fields)->next = (yyvsp[0].func_fields); } -#line 3077 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3074 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 94: -#line 761 "src/ast-parser.y" /* yacc.c:1646 */ +#line 758 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.func) = new_func(parser->allocator); + (yyval.func) = new_func(); WabtFuncField* field = (yyvsp[0].func_fields); while (field) { @@ -3095,8 +3092,8 @@ yyreduce: field->type == WABT_FUNC_FIELD_TYPE_PARAM_TYPES ? &(yyval.func)->decl.sig.param_types : &(yyval.func)->local_types; - wabt_extend_types(parser->allocator, types, &field->types); - wabt_destroy_type_vector(parser->allocator, &field->types); + wabt_extend_types(types, &field->types); + wabt_destroy_type_vector(&field->types); break; } @@ -3112,10 +3109,9 @@ yyreduce: bindings = &(yyval.func)->local_bindings; } - wabt_append_type_value(parser->allocator, types, - &field->bound_type.type); - WabtBinding* binding = wabt_insert_binding( - parser->allocator, bindings, &field->bound_type.name); + wabt_append_type_value(types, &field->bound_type.type); + WabtBinding* binding = + wabt_insert_binding(bindings, &field->bound_type.name); binding->loc = field->bound_type.loc; binding->index = types->size - 1; break; @@ -3127,15 +3123,15 @@ yyreduce: } /* we steal memory from the func field, but not the linked list nodes */ - wabt_free(parser->allocator, field); + wabt_free(field); field = next; } } -#line 3135 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3131 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 95: -#line 816 "src/ast-parser.y" /* yacc.c:1646 */ +#line 812 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.exported_func)); (yyval.exported_func).func = (yyvsp[-1].func); @@ -3144,11 +3140,11 @@ yyreduce: (yyval.exported_func).func->name = (yyvsp[-4].text); (yyval.exported_func).export_ = (yyvsp[-3].optional_export); } -#line 3148 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3144 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 96: -#line 825 "src/ast-parser.y" /* yacc.c:1646 */ +#line 821 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.exported_func)); (yyval.exported_func).func = (yyvsp[-1].func); @@ -3156,51 +3152,51 @@ yyreduce: (yyval.exported_func).func->decl.type_var = (yyvsp[-2].var); (yyval.exported_func).func->name = (yyvsp[-3].text); } -#line 3160 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3156 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 97: -#line 832 "src/ast-parser.y" /* yacc.c:1646 */ +#line 828 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.exported_func)); (yyval.exported_func).func = (yyvsp[-1].func); (yyval.exported_func).func->name = (yyvsp[-3].text); (yyval.exported_func).export_ = (yyvsp[-2].optional_export); } -#line 3171 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3167 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 98: -#line 839 "src/ast-parser.y" /* yacc.c:1646 */ +#line 835 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.exported_func)); (yyval.exported_func).func = (yyvsp[-1].func); (yyval.exported_func).func->name = (yyvsp[-2].text); } -#line 3181 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3177 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 99: -#line 849 "src/ast-parser.y" /* yacc.c:1646 */ +#line 845 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.expr_list) = (yyvsp[-1].expr_list); } -#line 3189 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3185 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 101: -#line 856 "src/ast-parser.y" /* yacc.c:1646 */ +#line 852 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.elem_segment)); (yyval.elem_segment).table_var = (yyvsp[-3].var); (yyval.elem_segment).offset = (yyvsp[-2].expr_list).first; (yyval.elem_segment).vars = (yyvsp[-1].vars); } -#line 3200 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3196 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 102: -#line 862 "src/ast-parser.y" /* yacc.c:1646 */ +#line 858 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.elem_segment)); (yyval.elem_segment).table_var.loc = (yylsp[-3]); @@ -3209,24 +3205,24 @@ yyreduce: (yyval.elem_segment).offset = (yyvsp[-2].expr_list).first; (yyval.elem_segment).vars = (yyvsp[-1].vars); } -#line 3213 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3209 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 103: -#line 873 "src/ast-parser.y" /* yacc.c:1646 */ +#line 869 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.exported_table).table = (yyvsp[-1].table); (yyval.exported_table).table.name = (yyvsp[-3].text); (yyval.exported_table).has_elem_segment = WABT_FALSE; (yyval.exported_table).export_ = (yyvsp[-2].optional_export); } -#line 3224 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3220 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 104: -#line 880 "src/ast-parser.y" /* yacc.c:1646 */ +#line 876 "src/ast-parser.y" /* yacc.c:1646 */ { - WabtExpr* expr = wabt_new_const_expr(parser->allocator); + WabtExpr* expr = wabt_new_const_expr(); expr->loc = (yylsp[-8]); expr->const_.type = WABT_TYPE_I32; expr->const_.u32 = 0; @@ -3241,37 +3237,37 @@ yyreduce: (yyval.exported_table).elem_segment.vars = (yyvsp[-2].vars); (yyval.exported_table).export_ = (yyvsp[-6].optional_export); } -#line 3245 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3241 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 105: -#line 899 "src/ast-parser.y" /* yacc.c:1646 */ +#line 895 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.data_segment)); (yyval.data_segment).memory_var = (yyvsp[-3].var); (yyval.data_segment).offset = (yyvsp[-2].expr_list).first; - dup_text_list(parser->allocator, &(yyvsp[-1].text_list), &(yyval.data_segment).data, &(yyval.data_segment).size); - wabt_destroy_text_list(parser->allocator, &(yyvsp[-1].text_list)); + dup_text_list(&(yyvsp[-1].text_list), &(yyval.data_segment).data, &(yyval.data_segment).size); + wabt_destroy_text_list(&(yyvsp[-1].text_list)); } -#line 3257 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3253 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 106: -#line 906 "src/ast-parser.y" /* yacc.c:1646 */ +#line 902 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.data_segment)); (yyval.data_segment).memory_var.loc = (yylsp[-3]); (yyval.data_segment).memory_var.type = WABT_VAR_TYPE_INDEX; (yyval.data_segment).memory_var.index = 0; (yyval.data_segment).offset = (yyvsp[-2].expr_list).first; - dup_text_list(parser->allocator, &(yyvsp[-1].text_list), &(yyval.data_segment).data, &(yyval.data_segment).size); - wabt_destroy_text_list(parser->allocator, &(yyvsp[-1].text_list)); + dup_text_list(&(yyvsp[-1].text_list), &(yyval.data_segment).data, &(yyval.data_segment).size); + wabt_destroy_text_list(&(yyvsp[-1].text_list)); } -#line 3271 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3267 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 107: -#line 918 "src/ast-parser.y" /* yacc.c:1646 */ +#line 914 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.exported_memory)); (yyval.exported_memory).memory = (yyvsp[-1].memory); @@ -3279,13 +3275,13 @@ yyreduce: (yyval.exported_memory).has_data_segment = WABT_FALSE; (yyval.exported_memory).export_ = (yyvsp[-2].optional_export); } -#line 3283 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3279 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 108: -#line 925 "src/ast-parser.y" /* yacc.c:1646 */ +#line 921 "src/ast-parser.y" /* yacc.c:1646 */ { - WabtExpr* expr = wabt_new_const_expr(parser->allocator); + WabtExpr* expr = wabt_new_const_expr(); expr->loc = (yylsp[-7]); expr->const_.type = WABT_TYPE_I32; expr->const_.u32 = 0; @@ -3293,9 +3289,8 @@ yyreduce: WABT_ZERO_MEMORY((yyval.exported_memory)); (yyval.exported_memory).has_data_segment = WABT_TRUE; (yyval.exported_memory).data_segment.offset = expr; - dup_text_list(parser->allocator, &(yyvsp[-2].text_list), &(yyval.exported_memory).data_segment.data, - &(yyval.exported_memory).data_segment.size); - wabt_destroy_text_list(parser->allocator, &(yyvsp[-2].text_list)); + dup_text_list(&(yyvsp[-2].text_list), &(yyval.exported_memory).data_segment.data, &(yyval.exported_memory).data_segment.size); + wabt_destroy_text_list(&(yyvsp[-2].text_list)); uint32_t byte_size = WABT_ALIGN_UP_TO_PAGE((yyval.exported_memory).data_segment.size); uint32_t page_size = WABT_BYTES_TO_PAGES(byte_size); (yyval.exported_memory).memory.name = (yyvsp[-6].text); @@ -3304,13 +3299,13 @@ yyreduce: (yyval.exported_memory).memory.page_limits.has_max = WABT_TRUE; (yyval.exported_memory).export_ = (yyvsp[-5].optional_export); } -#line 3308 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3303 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 109: -#line 946 "src/ast-parser.y" /* yacc.c:1646 */ +#line 941 "src/ast-parser.y" /* yacc.c:1646 */ { - WabtExpr* expr = wabt_new_const_expr(parser->allocator); + WabtExpr* expr = wabt_new_const_expr(); expr->loc = (yylsp[-6]); expr->const_.type = WABT_TYPE_I32; expr->const_.u32 = 0; @@ -3318,9 +3313,8 @@ yyreduce: WABT_ZERO_MEMORY((yyval.exported_memory)); (yyval.exported_memory).has_data_segment = WABT_TRUE; (yyval.exported_memory).data_segment.offset = expr; - dup_text_list(parser->allocator, &(yyvsp[-2].text_list), &(yyval.exported_memory).data_segment.data, - &(yyval.exported_memory).data_segment.size); - wabt_destroy_text_list(parser->allocator, &(yyvsp[-2].text_list)); + dup_text_list(&(yyvsp[-2].text_list), &(yyval.exported_memory).data_segment.data, &(yyval.exported_memory).data_segment.size); + wabt_destroy_text_list(&(yyvsp[-2].text_list)); uint32_t byte_size = WABT_ALIGN_UP_TO_PAGE((yyval.exported_memory).data_segment.size); uint32_t page_size = WABT_BYTES_TO_PAGES(byte_size); (yyval.exported_memory).memory.name = (yyvsp[-5].text); @@ -3329,11 +3323,11 @@ yyreduce: (yyval.exported_memory).memory.page_limits.has_max = WABT_TRUE; (yyval.exported_memory).export_.has_export = WABT_FALSE; } -#line 3333 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3327 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 110: -#line 969 "src/ast-parser.y" /* yacc.c:1646 */ +#line 963 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.exported_global)); (yyval.exported_global).global = (yyvsp[-2].global); @@ -3341,11 +3335,11 @@ yyreduce: (yyval.exported_global).global.init_expr = (yyvsp[-1].expr_list).first; (yyval.exported_global).export_ = (yyvsp[-3].optional_export); } -#line 3345 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3339 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 111: -#line 976 "src/ast-parser.y" /* yacc.c:1646 */ +#line 970 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.exported_global)); (yyval.exported_global).global = (yyvsp[-2].global); @@ -3353,77 +3347,77 @@ yyreduce: (yyval.exported_global).global.init_expr = (yyvsp[-1].expr_list).first; (yyval.exported_global).export_.has_export = WABT_FALSE; } -#line 3357 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3351 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 112: -#line 989 "src/ast-parser.y" /* yacc.c:1646 */ +#line 983 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.import) = new_import(parser->allocator); + (yyval.import) = new_import(); (yyval.import)->kind = WABT_EXTERNAL_KIND_FUNC; (yyval.import)->func.name = (yyvsp[-2].text); (yyval.import)->func.decl.flags = WABT_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; (yyval.import)->func.decl.type_var = (yyvsp[-1].var); } -#line 3369 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3363 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 113: -#line 996 "src/ast-parser.y" /* yacc.c:1646 */ +#line 990 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.import) = new_import(parser->allocator); + (yyval.import) = new_import(); (yyval.import)->kind = WABT_EXTERNAL_KIND_FUNC; (yyval.import)->func.name = (yyvsp[-2].text); (yyval.import)->func.decl.sig = (yyvsp[-1].func_sig); } -#line 3380 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3374 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 114: -#line 1002 "src/ast-parser.y" /* yacc.c:1646 */ +#line 996 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.import) = new_import(parser->allocator); + (yyval.import) = new_import(); (yyval.import)->kind = WABT_EXTERNAL_KIND_TABLE; (yyval.import)->table = (yyvsp[-1].table); (yyval.import)->table.name = (yyvsp[-2].text); } -#line 3391 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3385 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 115: -#line 1008 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1002 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.import) = new_import(parser->allocator); + (yyval.import) = new_import(); (yyval.import)->kind = WABT_EXTERNAL_KIND_MEMORY; (yyval.import)->memory = (yyvsp[-1].memory); (yyval.import)->memory.name = (yyvsp[-2].text); } -#line 3402 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3396 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 116: -#line 1014 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1008 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.import) = new_import(parser->allocator); + (yyval.import) = new_import(); (yyval.import)->kind = WABT_EXTERNAL_KIND_GLOBAL; (yyval.import)->global = (yyvsp[-1].global); (yyval.import)->global.name = (yyvsp[-2].text); } -#line 3413 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3407 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 117: -#line 1022 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1016 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.import) = (yyvsp[-1].import); (yyval.import)->module_name = (yyvsp[-3].text); (yyval.import)->field_name = (yyvsp[-2].text); } -#line 3423 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3417 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 118: -#line 1027 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1021 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.import) = (yyvsp[-2].import); (yyval.import)->kind = WABT_EXTERNAL_KIND_FUNC; @@ -3431,165 +3425,165 @@ yyreduce: (yyval.import)->func.decl.flags = WABT_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; (yyval.import)->func.decl.type_var = (yyvsp[-1].var); } -#line 3435 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3429 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 119: -#line 1034 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1028 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.import) = (yyvsp[-2].import); (yyval.import)->kind = WABT_EXTERNAL_KIND_FUNC; (yyval.import)->func.name = (yyvsp[-3].text); (yyval.import)->func.decl.sig = (yyvsp[-1].func_sig); } -#line 3446 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3440 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 120: -#line 1040 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1034 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.import) = (yyvsp[-2].import); (yyval.import)->kind = WABT_EXTERNAL_KIND_TABLE; (yyval.import)->table = (yyvsp[-1].table); (yyval.import)->table.name = (yyvsp[-3].text); } -#line 3457 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3451 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 121: -#line 1046 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1040 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.import) = (yyvsp[-2].import); (yyval.import)->kind = WABT_EXTERNAL_KIND_MEMORY; (yyval.import)->memory = (yyvsp[-1].memory); (yyval.import)->memory.name = (yyvsp[-3].text); } -#line 3468 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3462 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 122: -#line 1052 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1046 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.import) = (yyvsp[-2].import); (yyval.import)->kind = WABT_EXTERNAL_KIND_GLOBAL; (yyval.import)->global = (yyvsp[-1].global); (yyval.import)->global.name = (yyvsp[-3].text); } -#line 3479 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3473 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 123: -#line 1061 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1055 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.import) = new_import(parser->allocator); + (yyval.import) = new_import(); (yyval.import)->module_name = (yyvsp[-2].text); (yyval.import)->field_name = (yyvsp[-1].text); } -#line 3489 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3483 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 124: -#line 1069 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1063 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.export_)); (yyval.export_).kind = WABT_EXTERNAL_KIND_FUNC; (yyval.export_).var = (yyvsp[-1].var); } -#line 3499 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3493 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 125: -#line 1074 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1068 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.export_)); (yyval.export_).kind = WABT_EXTERNAL_KIND_TABLE; (yyval.export_).var = (yyvsp[-1].var); } -#line 3509 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3503 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 126: -#line 1079 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1073 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.export_)); (yyval.export_).kind = WABT_EXTERNAL_KIND_MEMORY; (yyval.export_).var = (yyvsp[-1].var); } -#line 3519 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3513 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 127: -#line 1084 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1078 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.export_)); (yyval.export_).kind = WABT_EXTERNAL_KIND_GLOBAL; (yyval.export_).var = (yyvsp[-1].var); } -#line 3529 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3523 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 128: -#line 1091 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1085 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.export_) = (yyvsp[-1].export_); (yyval.export_).name = (yyvsp[-2].text); } -#line 3538 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3532 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 129: -#line 1098 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1092 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.optional_export)); (yyval.optional_export).has_export = WABT_FALSE; } -#line 3547 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3541 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 131: -#line 1105 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1099 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.optional_export)); (yyval.optional_export).has_export = WABT_TRUE; (yyval.optional_export).export_.name = (yyvsp[-1].text); } -#line 3557 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3551 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 132: -#line 1116 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1110 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.func_type)); (yyval.func_type).sig = (yyvsp[-1].func_sig); } -#line 3566 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3560 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 133: -#line 1120 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1114 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.func_type).name = (yyvsp[-2].text); (yyval.func_type).sig = (yyvsp[-1].func_sig); } -#line 3575 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3569 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 134: -#line 1127 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1121 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.var) = (yyvsp[-1].var); } -#line 3581 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3575 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 135: -#line 1131 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1125 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.module) = new_module(parser->allocator); + (yyval.module) = new_module(); } -#line 3589 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3583 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 136: -#line 1134 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1128 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); WabtModuleField* field; @@ -3598,11 +3592,11 @@ yyreduce: &field->func_type); INSERT_BINDING((yyval.module), func_type, func_types, (yylsp[0]), (yyvsp[0].func_type).name); } -#line 3602 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3596 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 137: -#line 1142 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1136 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); WabtModuleField* field; @@ -3611,11 +3605,11 @@ yyreduce: INSERT_BINDING((yyval.module), global, globals, (yylsp[0]), (yyvsp[0].exported_global).global.name); APPEND_INLINE_EXPORT((yyval.module), GLOBAL, (yylsp[0]), (yyvsp[0].exported_global), (yyval.module)->globals.size - 1); } -#line 3615 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3609 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 138: -#line 1150 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1144 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); WabtModuleField* field; @@ -3633,11 +3627,11 @@ yyreduce: } } -#line 3637 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3631 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 139: -#line 1167 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1161 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); WabtModuleField* field; @@ -3654,27 +3648,26 @@ yyreduce: &data_segment_field->data_segment); } } -#line 3658 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3652 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 140: -#line 1183 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1177 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); WabtModuleField* field; APPEND_FIELD_TO_LIST((yyval.module), field, FUNC, func, (yylsp[0]), *(yyvsp[0].exported_func).func); - append_implicit_func_declaration(parser->allocator, &(yylsp[0]), (yyval.module), - &field->func.decl); + append_implicit_func_declaration(&(yylsp[0]), (yyval.module), &field->func.decl); APPEND_ITEM_TO_VECTOR((yyval.module), Func, func, funcs, &field->func); INSERT_BINDING((yyval.module), func, funcs, (yylsp[0]), (yyvsp[0].exported_func).func->name); APPEND_INLINE_EXPORT((yyval.module), FUNC, (yylsp[0]), (yyvsp[0].exported_func), (yyval.module)->funcs.size - 1); - wabt_free(parser->allocator, (yyvsp[0].exported_func).func); + wabt_free((yyvsp[0].exported_func).func); } -#line 3674 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3667 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 141: -#line 1194 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1187 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); WabtModuleField* field; @@ -3682,11 +3675,11 @@ yyreduce: APPEND_ITEM_TO_VECTOR((yyval.module), ElemSegment, elem_segment, elem_segments, &field->elem_segment); } -#line 3686 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3679 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 142: -#line 1201 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1194 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); WabtModuleField* field; @@ -3694,22 +3687,22 @@ yyreduce: APPEND_ITEM_TO_VECTOR((yyval.module), DataSegment, data_segment, data_segments, &field->data_segment); } -#line 3698 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3691 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 143: -#line 1208 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1201 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); WabtModuleField* field; APPEND_FIELD_TO_LIST((yyval.module), field, START, start, (yylsp[0]), (yyvsp[0].var)); (yyval.module)->start = &field->start; } -#line 3709 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3702 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 144: -#line 1214 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1207 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); WabtModuleField* field; @@ -3720,8 +3713,7 @@ yyreduce: CHECK_IMPORT_ORDERING((yyval.module), global, globals, (yylsp[0])); switch ((yyvsp[0].import)->kind) { case WABT_EXTERNAL_KIND_FUNC: - append_implicit_func_declaration(parser->allocator, &(yylsp[0]), (yyval.module), - &field->import.func.decl); + append_implicit_func_declaration(&(yylsp[0]), (yyval.module), &field->import.func.decl); APPEND_ITEM_TO_VECTOR((yyval.module), Func, func, funcs, &field->import.func); INSERT_BINDING((yyval.module), func, funcs, (yylsp[0]), field->import.func.name); (yyval.module)->num_func_imports++; @@ -3747,26 +3739,26 @@ yyreduce: assert(0); break; } - wabt_free(parser->allocator, (yyvsp[0].import)); + wabt_free((yyvsp[0].import)); APPEND_ITEM_TO_VECTOR((yyval.module), Import, import, imports, &field->import); } -#line 3754 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3746 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 145: -#line 1254 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1246 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); - WabtModuleField* field = wabt_append_module_field(parser->allocator, (yyval.module)); + WabtModuleField* field = wabt_append_module_field((yyval.module)); APPEND_FIELD_TO_LIST((yyval.module), field, EXPORT, export_, (yylsp[0]), (yyvsp[0].export_)); APPEND_ITEM_TO_VECTOR((yyval.module), Export, export, exports, &field->export_); INSERT_BINDING((yyval.module), export, exports, (yylsp[0]), (yyvsp[0].export_).name); } -#line 3766 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3758 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 146: -#line 1264 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1256 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.raw_module).type = WABT_RAW_MODULE_TYPE_TEXT; (yyval.raw_module).text = (yyvsp[-1].module); @@ -3789,29 +3781,29 @@ yyreduce: } } } -#line 3793 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3785 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 147: -#line 1286 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1278 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.raw_module).type = WABT_RAW_MODULE_TYPE_BINARY; (yyval.raw_module).binary.name = (yyvsp[-2].text); (yyval.raw_module).binary.loc = (yylsp[-3]); - dup_text_list(parser->allocator, &(yyvsp[-1].text_list), &(yyval.raw_module).binary.data, &(yyval.raw_module).binary.size); - wabt_destroy_text_list(parser->allocator, &(yyvsp[-1].text_list)); + dup_text_list(&(yyvsp[-1].text_list), &(yyval.raw_module).binary.data, &(yyval.raw_module).binary.size); + wabt_destroy_text_list(&(yyvsp[-1].text_list)); } -#line 3805 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3797 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 148: -#line 1296 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1288 "src/ast-parser.y" /* yacc.c:1646 */ { if ((yyvsp[0].raw_module).type == WABT_RAW_MODULE_TYPE_TEXT) { (yyval.module) = (yyvsp[0].raw_module).text; } else { assert((yyvsp[0].raw_module).type == WABT_RAW_MODULE_TYPE_BINARY); - (yyval.module) = new_module(parser->allocator); + (yyval.module) = new_module(); WabtReadBinaryOptions options = WABT_READ_BINARY_OPTIONS_DEFAULT; BinaryErrorCallbackData user_data; user_data.loc = &(yyvsp[0].raw_module).binary.loc; @@ -3820,38 +3812,38 @@ yyreduce: WabtBinaryErrorHandler error_handler; error_handler.on_error = on_read_binary_error; error_handler.user_data = &user_data; - wabt_read_binary_ast(parser->allocator, (yyvsp[0].raw_module).binary.data, (yyvsp[0].raw_module).binary.size, - &options, &error_handler, (yyval.module)); - wabt_free(parser->allocator, (yyvsp[0].raw_module).binary.data); + wabt_read_binary_ast((yyvsp[0].raw_module).binary.data, (yyvsp[0].raw_module).binary.size, &options, + &error_handler, (yyval.module)); + wabt_free((yyvsp[0].raw_module).binary.data); (yyval.module)->name = (yyvsp[0].raw_module).binary.name; (yyval.module)->loc = (yyvsp[0].raw_module).binary.loc; } } -#line 3831 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3823 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 149: -#line 1322 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1314 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.var)); (yyval.var).type = WABT_VAR_TYPE_INDEX; (yyval.var).index = INVALID_VAR_INDEX; } -#line 3841 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3833 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 150: -#line 1327 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1319 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.var)); (yyval.var).type = WABT_VAR_TYPE_NAME; DUPTEXT((yyval.var).name, (yyvsp[0].text)); } -#line 3851 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3843 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 151: -#line 1335 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1327 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.action)); (yyval.action).loc = (yylsp[-4]); @@ -3860,11 +3852,11 @@ yyreduce: (yyval.action).invoke.name = (yyvsp[-2].text); (yyval.action).invoke.args = (yyvsp[-1].consts); } -#line 3864 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3856 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 152: -#line 1343 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1335 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.action)); (yyval.action).loc = (yylsp[-3]); @@ -3872,147 +3864,147 @@ yyreduce: (yyval.action).type = WABT_ACTION_TYPE_GET; (yyval.action).invoke.name = (yyvsp[-1].text); } -#line 3876 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3868 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 153: -#line 1353 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1345 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.command) = new_command(parser->allocator); + (yyval.command) = new_command(); (yyval.command)->type = WABT_COMMAND_TYPE_ASSERT_MALFORMED; (yyval.command)->assert_malformed.module = (yyvsp[-2].raw_module); (yyval.command)->assert_malformed.text = (yyvsp[-1].text); } -#line 3887 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3879 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 154: -#line 1359 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1351 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.command) = new_command(parser->allocator); + (yyval.command) = new_command(); (yyval.command)->type = WABT_COMMAND_TYPE_ASSERT_INVALID; (yyval.command)->assert_invalid.module = (yyvsp[-2].raw_module); (yyval.command)->assert_invalid.text = (yyvsp[-1].text); } -#line 3898 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3890 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 155: -#line 1365 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1357 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.command) = new_command(parser->allocator); + (yyval.command) = new_command(); (yyval.command)->type = WABT_COMMAND_TYPE_ASSERT_UNLINKABLE; (yyval.command)->assert_unlinkable.module = (yyvsp[-2].raw_module); (yyval.command)->assert_unlinkable.text = (yyvsp[-1].text); } -#line 3909 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3901 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 156: -#line 1371 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1363 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.command) = new_command(parser->allocator); + (yyval.command) = new_command(); (yyval.command)->type = WABT_COMMAND_TYPE_ASSERT_UNINSTANTIABLE; (yyval.command)->assert_uninstantiable.module = (yyvsp[-2].raw_module); (yyval.command)->assert_uninstantiable.text = (yyvsp[-1].text); } -#line 3920 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3912 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 157: -#line 1377 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1369 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.command) = new_command(parser->allocator); + (yyval.command) = new_command(); (yyval.command)->type = WABT_COMMAND_TYPE_ASSERT_RETURN; (yyval.command)->assert_return.action = (yyvsp[-2].action); (yyval.command)->assert_return.expected = (yyvsp[-1].consts); } -#line 3931 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3923 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 158: -#line 1383 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1375 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.command) = new_command(parser->allocator); + (yyval.command) = new_command(); (yyval.command)->type = WABT_COMMAND_TYPE_ASSERT_RETURN_NAN; (yyval.command)->assert_return_nan.action = (yyvsp[-1].action); } -#line 3941 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3933 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 159: -#line 1388 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1380 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.command) = new_command(parser->allocator); + (yyval.command) = new_command(); (yyval.command)->type = WABT_COMMAND_TYPE_ASSERT_TRAP; (yyval.command)->assert_trap.action = (yyvsp[-2].action); (yyval.command)->assert_trap.text = (yyvsp[-1].text); } -#line 3952 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3944 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 160: -#line 1394 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1386 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.command) = new_command(parser->allocator); + (yyval.command) = new_command(); (yyval.command)->type = WABT_COMMAND_TYPE_ASSERT_EXHAUSTION; (yyval.command)->assert_trap.action = (yyvsp[-2].action); (yyval.command)->assert_trap.text = (yyvsp[-1].text); } -#line 3963 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3955 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 161: -#line 1403 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1395 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.command) = new_command(parser->allocator); + (yyval.command) = new_command(); (yyval.command)->type = WABT_COMMAND_TYPE_ACTION; (yyval.command)->action = (yyvsp[0].action); } -#line 3973 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3965 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 163: -#line 1409 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1401 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.command) = new_command(parser->allocator); + (yyval.command) = new_command(); (yyval.command)->type = WABT_COMMAND_TYPE_MODULE; (yyval.command)->module = *(yyvsp[0].module); - wabt_free(parser->allocator, (yyvsp[0].module)); + wabt_free((yyvsp[0].module)); } -#line 3984 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3976 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 164: -#line 1415 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1407 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.command) = new_command(parser->allocator); + (yyval.command) = new_command(); (yyval.command)->type = WABT_COMMAND_TYPE_REGISTER; (yyval.command)->register_.module_name = (yyvsp[-2].text); (yyval.command)->register_.var = (yyvsp[-1].var); (yyval.command)->register_.var.loc = (yylsp[-1]); } -#line 3996 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3988 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 165: -#line 1424 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1416 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.commands)); } -#line 4002 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 3994 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 166: -#line 1425 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1417 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.commands) = (yyvsp[-1].commands); - wabt_append_command_value(parser->allocator, &(yyval.commands), (yyvsp[0].command)); - wabt_free(parser->allocator, (yyvsp[0].command)); + wabt_append_command_value(&(yyval.commands), (yyvsp[0].command)); + wabt_free((yyvsp[0].command)); } -#line 4012 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 4004 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 167: -#line 1433 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1425 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.const_).loc = (yylsp[-2]); if (WABT_FAILED(parse_const((yyvsp[-2].type), (yyvsp[-1].literal).type, (yyvsp[-1].literal).text.start, @@ -4021,31 +4013,30 @@ yyreduce: "invalid literal \"" PRIstringslice "\"", WABT_PRINTF_STRING_SLICE_ARG((yyvsp[-1].literal).text)); } - wabt_free(parser->allocator, (char*)(yyvsp[-1].literal).text.start); + wabt_free((char*)(yyvsp[-1].literal).text.start); } -#line 4027 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 4019 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 168: -#line 1445 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1437 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.consts)); } -#line 4033 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 4025 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 169: -#line 1446 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1438 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.consts) = (yyvsp[-1].consts); - wabt_append_const_value(parser->allocator, &(yyval.consts), &(yyvsp[0].const_)); + wabt_append_const_value(&(yyval.consts), &(yyvsp[0].const_)); } -#line 4042 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 4034 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; case 170: -#line 1453 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1445 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.script)); - (yyval.script).allocator = parser->allocator; (yyval.script).commands = (yyvsp[0].commands); int last_module_index = -1; @@ -4062,10 +4053,9 @@ yyreduce: if (module->name.length == 0) continue; - WabtStringSlice module_name = - wabt_dup_string_slice(parser->allocator, module->name); - WabtBinding* binding = wabt_insert_binding( - parser->allocator, &(yyval.script).module_bindings, &module_name); + WabtStringSlice module_name = wabt_dup_string_slice(module->name); + WabtBinding* binding = + wabt_insert_binding(&(yyval.script).module_bindings, &module_name); binding->loc = module->loc; binding->index = i; break; @@ -4104,11 +4094,11 @@ yyreduce: } parser->script = (yyval.script); } -#line 4108 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 4098 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ break; -#line 4112 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ +#line 4102 "src/prebuilt/ast-parser-gen.c" /* yacc.c:1646 */ default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -4343,7 +4333,7 @@ yyreturn: #endif return yyresult; } -#line 1522 "src/ast-parser.y" /* yacc.c:1906 */ +#line 1512 "src/ast-parser.y" /* yacc.c:1906 */ static void append_expr_list(WabtExprList* expr_list, WabtExprList* expr) { @@ -4457,8 +4447,7 @@ static size_t copy_string_contents(WabtStringSlice* text, char* dest) { return dest - dest_start; } -static void dup_text_list(WabtAllocator* allocator, - WabtTextList* text_list, +static void dup_text_list(WabtTextList* text_list, void** out_data, size_t* out_size) { /* walk the linked list to see how much total space is needed */ @@ -4473,7 +4462,7 @@ static void dup_text_list(WabtAllocator* allocator, size_t size = (end > src) ? (end - src) : 0; total_size += size; } - char* result = wabt_alloc(allocator, total_size, 1); + char* result = wabt_alloc(total_size); char* dest = result; for (node = text_list->first; node; node = node->next) { size_t actual_size = copy_string_contents(&node->text, dest); @@ -4487,8 +4476,7 @@ static WabtBool is_empty_signature(WabtFuncSignature* sig) { return sig->result_types.size == 0 && sig->param_types.size == 0; } -static void append_implicit_func_declaration(WabtAllocator* allocator, - WabtLocation* loc, +static void append_implicit_func_declaration(WabtLocation* loc, WabtModule* module, WabtFuncDeclaration* decl) { if (wabt_decl_has_func_type(decl)) @@ -4496,10 +4484,10 @@ static void append_implicit_func_declaration(WabtAllocator* allocator, int sig_index = wabt_get_func_type_index_by_decl(module, decl); if (sig_index == -1) { - wabt_append_implicit_func_type(allocator, loc, module, &decl->sig); + wabt_append_implicit_func_type(loc, module, &decl->sig); } else { /* signature already exists, share that one and destroy this one */ - wabt_destroy_func_signature(allocator, &decl->sig); + wabt_destroy_func_signature(&decl->sig); WabtFuncSignature* sig = &module->func_types.data[sig_index]->sig; decl->sig = *sig; } @@ -4512,9 +4500,6 @@ WabtResult wabt_parse_ast(WabtAstLexer* lexer, WabtSourceErrorHandler* error_handler) { WabtAstParser parser; WABT_ZERO_MEMORY(parser); - WabtAllocator* allocator = wabt_ast_lexer_get_allocator(lexer); - parser.allocator = allocator; - parser.script.allocator = allocator; parser.error_handler = error_handler; int result = wabt_ast_parser_parse(lexer, &parser); *out_script = parser.script; diff --git a/src/resolve-names.c b/src/resolve-names.c index 1442575d..14de1016 100644 --- a/src/resolve-names.c +++ b/src/resolve-names.c @@ -19,7 +19,6 @@ #include <assert.h> #include <stdio.h> -#include "allocator.h" #include "ast.h" #include "ast-parser-lexer-shared.h" @@ -27,7 +26,6 @@ typedef WabtLabel* LabelPtr; WABT_DEFINE_VECTOR(label_ptr, LabelPtr); typedef struct Context { - WabtAllocator* allocator; WabtSourceErrorHandler* error_handler; WabtAstLexer* lexer; WabtScript* script; @@ -48,7 +46,7 @@ static void WABT_PRINTF_FORMAT(3, 4) } static void push_label(Context* ctx, WabtLabel* label) { - wabt_append_label_ptr_value(ctx->allocator, &ctx->labels, &label); + wabt_append_label_ptr_value(&ctx->labels, &label); } static void pop_label(Context* ctx) { @@ -88,7 +86,7 @@ static void resolve_label_var(Context* ctx, WabtVar* var) { for (i = ctx->labels.size - 1; i >= 0; --i) { WabtLabel* label = ctx->labels.data[i]; if (wabt_string_slices_are_equal(label, &var->name)) { - wabt_destroy_string_slice(ctx->allocator, &var->name); + wabt_destroy_string_slice(&var->name); var->type = WABT_VAR_TYPE_INDEX; var->index = ctx->labels.size - i - 1; return; @@ -113,7 +111,7 @@ static void resolve_var(Context* ctx, return; } - wabt_destroy_string_slice(ctx->allocator, &var->name); + wabt_destroy_string_slice(&var->name); var->index = index; var->type = WABT_VAR_TYPE_INDEX; } @@ -150,7 +148,7 @@ static void resolve_local_var(Context* ctx, WabtVar* var) { return; } - wabt_destroy_string_slice(ctx->allocator, &var->name); + wabt_destroy_string_slice(&var->name); var->index = index; var->type = WABT_VAR_TYPE_INDEX; } @@ -380,7 +378,6 @@ static void visit_command(Context* ctx, WabtCommand* command) { Context new_ctx; WABT_ZERO_MEMORY(new_ctx); - new_ctx.allocator = ctx->allocator; new_ctx.error_handler = &new_error_handler; new_ctx.lexer = ctx->lexer; new_ctx.visitor = ctx->visitor; @@ -388,7 +385,7 @@ static void visit_command(Context* ctx, WabtCommand* command) { new_ctx.result = WABT_OK; visit_raw_module(&new_ctx, &command->assert_invalid.module); - wabt_destroy_label_ptr_vector(new_ctx.allocator, &new_ctx.labels); + wabt_destroy_label_ptr_vector(&new_ctx.labels); if (WABT_FAILED(new_ctx.result)) { command->type = WABT_COMMAND_TYPE_ASSERT_INVALID_NON_BINARY; } @@ -422,12 +419,10 @@ static void visit_script(Context* ctx, WabtScript* script) { } static void init_context(Context* ctx, - WabtAllocator* allocator, WabtAstLexer* lexer, WabtScript* script, WabtSourceErrorHandler* error_handler) { WABT_ZERO_MEMORY(*ctx); - ctx->allocator = allocator; ctx->lexer = lexer; ctx->error_handler = error_handler; ctx->result = WABT_OK; @@ -451,24 +446,22 @@ static void init_context(Context* ctx, ctx->visitor.on_tee_local_expr = on_tee_local_expr; } -WabtResult wabt_resolve_names_module(WabtAllocator* allocator, - WabtAstLexer* lexer, +WabtResult wabt_resolve_names_module(WabtAstLexer* lexer, WabtModule* module, WabtSourceErrorHandler* error_handler) { Context ctx; - init_context(&ctx, allocator, lexer, NULL, error_handler); + init_context(&ctx, lexer, NULL, error_handler); visit_module(&ctx, module); - wabt_destroy_label_ptr_vector(allocator, &ctx.labels); + wabt_destroy_label_ptr_vector(&ctx.labels); return ctx.result; } -WabtResult wabt_resolve_names_script(WabtAllocator* allocator, - WabtAstLexer* lexer, +WabtResult wabt_resolve_names_script(WabtAstLexer* lexer, WabtScript* script, WabtSourceErrorHandler* error_handler) { Context ctx; - init_context(&ctx, allocator, lexer, script, error_handler); + init_context(&ctx, lexer, script, error_handler); visit_script(&ctx, script); - wabt_destroy_label_ptr_vector(allocator, &ctx.labels); + wabt_destroy_label_ptr_vector(&ctx.labels); return ctx.result; } diff --git a/src/resolve-names.h b/src/resolve-names.h index 781454c6..2779d462 100644 --- a/src/resolve-names.h +++ b/src/resolve-names.h @@ -19,20 +19,17 @@ #include "common.h" -struct WabtAllocator; struct WabtAstLexer; struct WabtModule; struct WabtScript; struct WabtSourceErrorHandler; WABT_EXTERN_C_BEGIN -WabtResult wabt_resolve_names_module(struct WabtAllocator*, - struct WabtAstLexer*, +WabtResult wabt_resolve_names_module(struct WabtAstLexer*, struct WabtModule*, struct WabtSourceErrorHandler*); -WabtResult wabt_resolve_names_script(struct WabtAllocator*, - struct WabtAstLexer*, +WabtResult wabt_resolve_names_script(struct WabtAstLexer*, struct WabtScript*, struct WabtSourceErrorHandler*); WABT_EXTERN_C_END diff --git a/src/stack-allocator.c b/src/stack-allocator.c deleted file mode 100644 index 55aeda9a..00000000 --- a/src/stack-allocator.c +++ /dev/null @@ -1,354 +0,0 @@ -/* - * Copyright 2016 WebAssembly Community Group participants - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "stack-allocator.h" - -#include <assert.h> -#include <stdint.h> -#include <stdio.h> -#include <string.h> - -#define TRACE_ALLOCATOR 0 - -#if TRACE_ALLOCATOR -#define TRACEF(...) fprintf(stderr, __VA_ARGS__) -#else -#define TRACEF(...) -#endif - -#if WABT_STACK_ALLOCATOR_STATS -#include <stdio.h> -#endif /* WABT_STACK_ALLOCATOR_STATS */ - -#define CHUNK_ALIGN 8 -#define CHUNK_SIZE (1024 * 1024) -#define CHUNK_MAX_AVAIL (CHUNK_SIZE - sizeof(WabtStackAllocatorChunk)) - -typedef struct StackAllocatorMark { - WabtStackAllocatorChunk* chunk; - void* chunk_current; - void* last_allocation; -} StackAllocatorMark; - -#ifndef NDEBUG -static WabtBool is_power_of_two(uint32_t x) { - return x && ((x & (x - 1)) == 0); -} -#endif /* NDEBUG */ - -static void* align_up(void* p, size_t align) { - return (void*)(((intptr_t)p + align - 1) & ~(align - 1)); -} - -static WabtBool allocation_in_chunk(WabtStackAllocatorChunk* chunk, void* p) { - return p >= (void*)chunk && p < chunk->end; -} - -static WabtStackAllocatorChunk* allocate_chunk( - WabtStackAllocator* stack_allocator, - size_t max_avail, - const char* file, - int line) { - assert(max_avail < SIZE_MAX - sizeof(WabtStackAllocatorChunk)); - size_t real_size = max_avail + sizeof(WabtStackAllocatorChunk); - /* common case of allocating a chunk of exactly CHUNK_SIZE */ - if (real_size == CHUNK_SIZE) { - if (stack_allocator->next_free) { - WabtStackAllocatorChunk* chunk = stack_allocator->next_free; - stack_allocator->next_free = stack_allocator->next_free->next_free; - return chunk; - } - } - - WabtStackAllocatorChunk* chunk = - wabt_alloc(stack_allocator->fallback, real_size, CHUNK_ALIGN); - if (!chunk) { - if (stack_allocator->has_jmpbuf) - longjmp(stack_allocator->jmpbuf, 1); - WABT_FATAL("%s:%d: memory allocation failed\n", file, line); - } - /* use the same allocation for the WabtStackAllocatorChunk and its data. + 1 - * skips over the WabtStackAllocatorChunk */ - chunk->start = chunk + 1; - chunk->current = chunk->start; - chunk->end = (void*)((intptr_t)chunk->start + max_avail); - chunk->prev = NULL; -#if WABT_STACK_ALLOCATOR_STATS - stack_allocator->chunk_alloc_count++; - stack_allocator->total_chunk_bytes += CHUNK_SIZE; -#endif /* WABT_STACK_ALLOCATOR_STATS */ - return chunk; -} - -static void* stack_alloc(WabtAllocator* allocator, - size_t size, - size_t align, - const char* file, - int line) { - WabtStackAllocator* stack_allocator = (WabtStackAllocator*)allocator; - assert(is_power_of_two(align)); - WabtStackAllocatorChunk* chunk = stack_allocator->last; - assert(size < SIZE_MAX - align + 1); - size_t alloc_size = size + align - 1; - void* result; - if (alloc_size >= CHUNK_MAX_AVAIL) { - chunk = allocate_chunk(stack_allocator, alloc_size, file, line); - result = align_up(chunk->current, align); - assert((void*)((intptr_t)result + size) <= chunk->end); - chunk->current = chunk->end; - /* thread this chunk before first. There's no available space, so it's not - worth considering. */ - stack_allocator->first->prev = chunk; - stack_allocator->first = chunk; - } else { - assert(chunk); - - chunk->current = align_up(chunk->current, align); - void* new_current = (void*)((intptr_t)chunk->current + size); - if (new_current < chunk->end) { - result = chunk->current; - chunk->current = new_current; - } else { - chunk = allocate_chunk(stack_allocator, CHUNK_MAX_AVAIL, file, line); - chunk->prev = stack_allocator->last; - stack_allocator->last = chunk; - chunk->current = align_up(chunk->current, align); - result = chunk->current; - chunk->current = (void*)((intptr_t)chunk->current + size); - assert(chunk->current <= chunk->end); - } - - stack_allocator->last_allocation = result; - } - -#if TRACE_ALLOCATOR - if (file) { - TRACEF("%s:%d: stack_alloc(%" PRIzd ", align=%" PRIzd ") => %p\n", file, - line, size, align, result); - } -#endif /* TRACE_ALLOCATOR */ - -#if WABT_STACK_ALLOCATOR_STATS - stack_allocator->alloc_count++; - stack_allocator->total_alloc_bytes += size; -#endif /* WABT_STACK_ALLOCATOR_STATS */ - return result; -} - -static void* stack_realloc(WabtAllocator* allocator, - void* p, - size_t size, - size_t align, - const char* file, - int line) { - if (!p) - return stack_alloc(allocator, size, align, file, line); - - WabtStackAllocator* stack_allocator = (WabtStackAllocator*)allocator; - /* TODO(binji): optimize */ - WabtStackAllocatorChunk* chunk = stack_allocator->last; - while (chunk) { - if (allocation_in_chunk(chunk, p)) - break; - chunk = chunk->prev; - } - - assert(chunk); - void* result = stack_alloc(allocator, size, align, NULL, 0); - -#if TRACE_ALLOCATOR - if (file) { - TRACEF("%s:%d: stack_realloc(%p, %" PRIzd ", align=%" PRIzd ") => %p\n", - file, line, p, size, align, result); - } -#endif /* TRACE_ALLOCATOR */ - - /* We know that the previously allocated data was at most extending from |p| - to the end of the chunk. So we can copy at most that many bytes, or the - new size, whichever is less. Use memmove because the regions may be - overlapping. */ - size_t old_max_size = (size_t)chunk->end - (size_t)p; - size_t copy_size = size > old_max_size ? old_max_size : size; - memmove(result, p, copy_size); -#if WABT_STACK_ALLOCATOR_STATS - /* count this is as a realloc, not an alloc */ - stack_allocator->alloc_count--; - stack_allocator->realloc_count++; - stack_allocator->total_alloc_bytes -= size; - stack_allocator->total_realloc_bytes += size; -#endif /* WABT_STACK_ALLOCATOR_STATS */ - return result; -} - -static void stack_free(WabtAllocator* allocator, - void* p, - const char* file, - int line) { - if (!p) - return; - - TRACEF("%s:%d: stack_free(%p)\n", file, line, p); - WabtStackAllocator* stack_allocator = (WabtStackAllocator*)allocator; - -#if WABT_STACK_ALLOCATOR_STATS - stack_allocator->free_count++; -#endif /* WABT_STACK_ALLOCATOR_STATS */ - - if (p != stack_allocator->last_allocation) - return; - - WabtStackAllocatorChunk* chunk = stack_allocator->last; - assert(allocation_in_chunk(chunk, p)); - chunk->current = p; -} - -static void stack_destroy(WabtAllocator* allocator) { - WabtStackAllocator* stack_allocator = (WabtStackAllocator*)allocator; - /* destroy the free chunks */ - WabtStackAllocatorChunk* chunk = stack_allocator->next_free; - while (chunk) { - WabtStackAllocatorChunk* next_free = chunk->next_free; - wabt_free(stack_allocator->fallback, chunk); - chunk = next_free; - } - - /* destroy the used chunks */ - chunk = stack_allocator->last; - while (chunk) { - WabtStackAllocatorChunk* prev = chunk->prev; - wabt_free(stack_allocator->fallback, chunk); - chunk = prev; - } -} - -static WabtAllocatorMark stack_mark(WabtAllocator* allocator) { - WabtStackAllocator* stack_allocator = (WabtStackAllocator*)allocator; - - /* allocate the space for the mark, but copy the current stack state now, so - * when we reset we reset before the mark was allocated */ - StackAllocatorMark mark; - mark.chunk = stack_allocator->last; - mark.chunk_current = mark.chunk->current; - mark.last_allocation = stack_allocator->last_allocation; - - StackAllocatorMark* allocated_mark = stack_alloc( - allocator, sizeof(StackAllocatorMark), WABT_DEFAULT_ALIGN, NULL, 0); -#if WABT_STACK_ALLOCATOR_STATS - /* don't count this allocation */ - stack_allocator->alloc_count--; - stack_allocator->total_alloc_bytes -= sizeof(StackAllocatorMark); -#endif /* WABT_STACK_ALLOCATOR_STATS */ - - *allocated_mark = mark; - return allocated_mark; -} - -static void stack_reset_to_mark(WabtAllocator* allocator, - WabtAllocatorMark mark) { - WabtStackAllocator* stack_allocator = (WabtStackAllocator*)allocator; - StackAllocatorMark* stack_mark = (StackAllocatorMark*)mark; - WabtStackAllocatorChunk* chunk = stack_allocator->last; - while (chunk && chunk != stack_mark->chunk) { - WabtStackAllocatorChunk* prev = chunk->prev; - /* reset this chunk for future use, and thread it into the free list */ - chunk->current = chunk->start; - chunk->next_free = stack_allocator->next_free; - stack_allocator->next_free = chunk; - chunk = prev; - } - - assert(chunk == stack_mark->chunk); - stack_allocator->last = chunk; - chunk->current = stack_mark->chunk_current; - stack_allocator->last_allocation = stack_mark->last_allocation; -} - -#if WABT_STACK_ALLOCATOR_STATS -static const char* human_readable(size_t count) { - /* printing a size_t in decimal requires ceil(sizeof(size_t) * 8 / log2(10)) - * characters. We want to add one comma for each group of three digits, so - * the total number of characters needed is 4/3 multiplied by that value. For - * a 64-bit size_t, this comes out to 27 (including the null-terminator). */ - static char buffer[27]; - int next_comma_in = 3; - memset(buffer, ' ', sizeof(buffer)); - char* p = &buffer[sizeof(buffer) - 1]; - *p-- = '\0'; - if (count) { - while (count) { - if (next_comma_in == 0) { - *p-- = ','; - next_comma_in = 3; - } - assert(p >= buffer); - size_t digit = count % 10; - *p-- = '0' + digit; - count /= 10; - next_comma_in--; - } - } else { - *p-- = '0'; - } - return buffer; -} -#endif /* WABT_STACK_ALLOCATOR_STATS */ - -static void stack_print_stats(WabtAllocator* allocator) { -#if WABT_STACK_ALLOCATOR_STATS -#define VALUE(name) human_readable(stack_allocator->name) - WabtStackAllocator* stack_allocator = (WabtStackAllocator*)allocator; - printf("STACK ALLOCATOR STATS:\n"); - printf("===============================================\n"); - printf("chunk_alloc_count: %s\n", VALUE(chunk_alloc_count)); - printf("alloc_count: %s\n", VALUE(alloc_count)); - printf("realloc_count: %s\n", VALUE(realloc_count)); - printf("free_count: %s\n", VALUE(free_count)); - printf("total_chunk_bytes: %s\n", VALUE(total_chunk_bytes)); - printf("total_alloc_bytes: %s\n", VALUE(total_alloc_bytes)); - printf("total_realloc_bytes: %s\n", VALUE(total_realloc_bytes)); -#undef VALUE -#endif /* WABT_STACK_ALLOCATOR_STATS */ -} - -static int stack_setjmp_handler(WabtAllocator* allocator) { - WabtStackAllocator* stack_allocator = (WabtStackAllocator*)allocator; - stack_allocator->has_jmpbuf = WABT_TRUE; - return setjmp(stack_allocator->jmpbuf); -} - -WabtResult wabt_init_stack_allocator(WabtStackAllocator* stack_allocator, - WabtAllocator* fallback) { - WABT_ZERO_MEMORY(*stack_allocator); - stack_allocator->allocator.alloc = stack_alloc; - stack_allocator->allocator.realloc = stack_realloc; - stack_allocator->allocator.free = stack_free; - stack_allocator->allocator.destroy = stack_destroy; - stack_allocator->allocator.mark = stack_mark; - stack_allocator->allocator.reset_to_mark = stack_reset_to_mark; - stack_allocator->allocator.print_stats = stack_print_stats; - stack_allocator->allocator.setjmp_handler = stack_setjmp_handler; - stack_allocator->fallback = fallback; - - WabtStackAllocatorChunk* chunk = - allocate_chunk(stack_allocator, CHUNK_MAX_AVAIL, __FILE__, __LINE__); - chunk->prev = NULL; - stack_allocator->first = stack_allocator->last = chunk; - return WABT_OK; -} - -void wabt_destroy_stack_allocator(WabtStackAllocator* stack_allocator) { - stack_destroy((WabtAllocator*)stack_allocator); -} diff --git a/src/stack-allocator.h b/src/stack-allocator.h deleted file mode 100644 index 1da8de4e..00000000 --- a/src/stack-allocator.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2016 WebAssembly Community Group participants - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef WABT_STACK_ALLOCATOR_H_ -#define WABT_STACK_ALLOCATOR_H_ - -#include "allocator.h" -#include "common.h" - -#include <setjmp.h> - -#define WABT_STACK_ALLOCATOR_STATS 0 - -typedef struct WabtStackAllocatorChunk { - void* start; - void* current; - void* end; - union { - struct WabtStackAllocatorChunk* prev; - struct WabtStackAllocatorChunk* next_free; - }; -} WabtStackAllocatorChunk; - -typedef struct WabtStackAllocator { - WabtAllocator allocator; - WabtStackAllocatorChunk* first; - WabtStackAllocatorChunk* last; - WabtAllocator* fallback; - void* last_allocation; - WabtStackAllocatorChunk* next_free; - WabtBool has_jmpbuf; - jmp_buf jmpbuf; - -#if WABT_STACK_ALLOCATOR_STATS - /* some random stats */ - size_t chunk_alloc_count; - size_t alloc_count; - size_t realloc_count; - size_t free_count; - size_t total_chunk_bytes; - size_t total_alloc_bytes; - size_t total_realloc_bytes; -#endif /* WABT_STACK_ALLOCATOR_STATS */ -} WabtStackAllocator; - -WABT_EXTERN_C_BEGIN -WabtResult wabt_init_stack_allocator(WabtStackAllocator*, - WabtAllocator* fallback); -void wabt_destroy_stack_allocator(WabtStackAllocator*); -WABT_EXTERN_C_END - -#endif /* WABT_STACK_ALLOCATOR_H_ */ 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, §ion->relocations); +void wabt_destroy_section(WabtSection* section) { + wabt_destroy_reloc_vector(§ion->relocations); switch (section->section_code) { case WABT_BINARY_SECTION_DATA: - wabt_destroy_data_segment_vector(allocator, §ion->data_segments); + wabt_destroy_data_segment_vector(§ion->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 = §ions[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, §ions[i]); + wabt_destroy_section_ptr_vector(§ions[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; } diff --git a/src/type-checker.c b/src/type-checker.c index 5ac7ed31..134669a2 100644 --- a/src/type-checker.c +++ b/src/type-checker.c @@ -78,22 +78,21 @@ static void push_label(WabtTypeChecker* tc, WabtLabelType label_type, const WabtTypeVector* sig) { WabtTypeCheckerLabel* label = - wabt_append_type_checker_label(tc->allocator, &tc->label_stack); + wabt_append_type_checker_label(&tc->label_stack); label->label_type = label_type; - wabt_extend_types(tc->allocator, &label->sig, sig); + wabt_extend_types(&label->sig, sig); label->type_stack_limit = tc->type_stack.size; label->unreachable = WABT_FALSE; } -static void wabt_destroy_type_checker_label(WabtAllocator* allocator, - WabtTypeCheckerLabel* label) { - wabt_destroy_type_vector(allocator, &label->sig); +static void wabt_destroy_type_checker_label(WabtTypeCheckerLabel* label) { + wabt_destroy_type_vector(&label->sig); } static WabtResult pop_label(WabtTypeChecker* tc) { WabtTypeCheckerLabel* label; CHECK_RESULT(top_label(tc, &label)); - wabt_destroy_type_checker_label(tc->allocator, label); + wabt_destroy_type_checker_label(label); tc->label_stack.size--; return WABT_OK; } @@ -146,7 +145,7 @@ static WabtResult drop_types(WabtTypeChecker* tc, size_t drop_count) { static void push_type(WabtTypeChecker* tc, WabtType type) { if (type != WABT_TYPE_VOID) - wabt_append_type_value(tc->allocator, &tc->type_stack, &type); + wabt_append_type_value(&tc->type_stack, &type); } static void push_types(WabtTypeChecker* tc, const WabtTypeVector* types) { @@ -290,9 +289,8 @@ static WabtResult check_opcode2(WabtTypeChecker* tc, WabtOpcode opcode) { } void wabt_destroy_typechecker(WabtTypeChecker* tc) { - wabt_destroy_type_vector(tc->allocator, &tc->type_stack); - WABT_DESTROY_VECTOR_AND_ELEMENTS(tc->allocator, tc->label_stack, - type_checker_label); + wabt_destroy_type_vector(&tc->type_stack); + WABT_DESTROY_VECTOR_AND_ELEMENTS(tc->label_stack, type_checker_label); } WabtResult wabt_typechecker_begin_function(WabtTypeChecker* tc, diff --git a/src/type-checker.h b/src/type-checker.h index e4fd74e1..978fc728 100644 --- a/src/type-checker.h +++ b/src/type-checker.h @@ -40,7 +40,6 @@ WABT_DEFINE_VECTOR(type_checker_label, WabtTypeCheckerLabel); typedef struct WabtTypeChecker { WabtTypeCheckerErrorHandler* error_handler; - WabtAllocator* allocator; WabtTypeVector type_stack; WabtTypeCheckerLabelVector label_stack; } WabtTypeChecker; diff --git a/src/validator.c b/src/validator.c index 0827ae02..8b76afa8 100644 --- a/src/validator.c +++ b/src/validator.c @@ -23,7 +23,6 @@ #include <stdarg.h> #include <stdio.h> -#include "allocator.h" #include "ast-parser-lexer-shared.h" #include "binary-reader-ast.h" #include "binary-reader.h" @@ -45,7 +44,6 @@ typedef struct ActionResult { typedef struct Context { WabtSourceErrorHandler* error_handler; - WabtAllocator* allocator; WabtAstLexer* lexer; const WabtScript* script; const WabtModule* current_module; @@ -1031,13 +1029,11 @@ static void wabt_destroy_context(Context* ctx) { wabt_destroy_typechecker(&ctx->typechecker); } -WabtResult wabt_validate_script(WabtAllocator* allocator, - WabtAstLexer* lexer, +WabtResult wabt_validate_script(WabtAstLexer* lexer, const struct WabtScript* script, WabtSourceErrorHandler* error_handler) { Context ctx; WABT_ZERO_MEMORY(ctx); - ctx.allocator = allocator; ctx.lexer = lexer; ctx.error_handler = error_handler; ctx.result = WABT_OK; @@ -1046,7 +1042,6 @@ WabtResult wabt_validate_script(WabtAllocator* allocator, WabtTypeCheckerErrorHandler tc_error_handler; tc_error_handler.on_error = on_typechecker_error; tc_error_handler.user_data = &ctx; - ctx.typechecker.allocator = allocator; ctx.typechecker.error_handler = &tc_error_handler; size_t i; diff --git a/src/validator.h b/src/validator.h index a6f76377..2371349c 100644 --- a/src/validator.h +++ b/src/validator.h @@ -20,15 +20,13 @@ #include "ast-lexer.h" #include "common.h" -struct WabtAllocator; struct WabtModule; struct WabtScript; WABT_EXTERN_C_BEGIN /* perform all checks on the AST; the module is valid if and only if this * function succeeds. */ -WabtResult wabt_validate_script(struct WabtAllocator*, - WabtAstLexer*, +WabtResult wabt_validate_script(WabtAstLexer*, const struct WabtScript*, WabtSourceErrorHandler*); WABT_EXTERN_C_END diff --git a/src/vector-sort.h b/src/vector-sort.h index 78ca5f13..97b166c4 100644 --- a/src/vector-sort.h +++ b/src/vector-sort.h @@ -24,29 +24,27 @@ * */ -#define WABT_DEFINE_VECTOR_SORT(name, type) \ - static void wabt_sort_##name##_vector( \ - struct WabtAllocator* allocator, \ - type##Vector* in_vec, \ - type##Vector* out_vec, \ - void (*swap_fcn)(type* v1, type*v2), \ - int (*lt_fcn)(type* v1, type* v2)) { \ - /* TODO(karlschimpf) Use a faster sort. */ \ - size_t i; \ - size_t j; \ - if (in_vec->size == 0) \ - return; \ - for (i = 0; i < in_vec->size; ++i) { \ - wabt_append_##name##_value(allocator, out_vec, &in_vec->data[i]); \ - if (out_vec->size < 2) \ - continue; \ - for (j = out_vec->size; j >= 2; --j) { \ - type *v1 = &out_vec->data[j-1]; \ - type *v2 = &out_vec->data[j-2]; \ - if (lt_fcn(v1, v2)) \ - swap_fcn(v1, v2); \ - } \ - } \ +#define WABT_DEFINE_VECTOR_SORT(name, type) \ + static void wabt_sort_##name##_vector( \ + type##Vector* in_vec, type##Vector* out_vec, \ + void (*swap_fcn)(type * v1, type * v2), \ + int (*lt_fcn)(type * v1, type * v2)) { \ + /* TODO(karlschimpf) Use a faster sort. */ \ + size_t i; \ + size_t j; \ + if (in_vec->size == 0) \ + return; \ + for (i = 0; i < in_vec->size; ++i) { \ + wabt_append_##name##_value(out_vec, &in_vec->data[i]); \ + if (out_vec->size < 2) \ + continue; \ + for (j = out_vec->size; j >= 2; --j) { \ + type* v1 = &out_vec->data[j - 1]; \ + type* v2 = &out_vec->data[j - 2]; \ + if (lt_fcn(v1, v2)) \ + swap_fcn(v1, v2); \ + } \ + } \ } #endif // WABT_VECTOR_SORT_H_ diff --git a/src/vector.c b/src/vector.c index 82dba65a..b7135e67 100644 --- a/src/vector.c +++ b/src/vector.c @@ -16,33 +16,29 @@ #include "vector.h" -#include "allocator.h" - #define INITIAL_VECTOR_CAPACITY 8 -void wabt_ensure_capacity(WabtAllocator* allocator, - void** data, - size_t* capacity, - size_t desired_size, - size_t elt_byte_size) { +void wabt_ensure_capacity(void** data, + size_t* capacity, + size_t desired_size, + size_t elt_byte_size) { if (desired_size > *capacity) { size_t new_capacity = *capacity ? *capacity * 2 : INITIAL_VECTOR_CAPACITY; while (new_capacity < desired_size) new_capacity *= 2; size_t new_byte_size = new_capacity * elt_byte_size; - *data = wabt_realloc(allocator, *data, new_byte_size, WABT_DEFAULT_ALIGN); + *data = wabt_realloc(*data, new_byte_size); *capacity = new_capacity; } } -void wabt_resize_vector(struct WabtAllocator* allocator, - void** data, - size_t* size, - size_t* capacity, - size_t desired_size, - size_t elt_byte_size) { +void wabt_resize_vector(void** data, + size_t* size, + size_t* capacity, + size_t desired_size, + size_t elt_byte_size) { size_t old_size = *size; - wabt_ensure_capacity(allocator, data, capacity, desired_size, elt_byte_size); + wabt_ensure_capacity(data, capacity, desired_size, elt_byte_size); if (desired_size > old_size) { memset((void*)((size_t)*data + old_size * elt_byte_size), 0, (desired_size - old_size) * elt_byte_size); @@ -50,26 +46,23 @@ void wabt_resize_vector(struct WabtAllocator* allocator, *size = desired_size; } -void* wabt_append_element(WabtAllocator* allocator, - void** data, +void* wabt_append_element(void** data, size_t* size, size_t* capacity, size_t elt_byte_size) { - wabt_ensure_capacity(allocator, data, capacity, *size + 1, elt_byte_size); + wabt_ensure_capacity(data, capacity, *size + 1, elt_byte_size); void* p = (void*)((size_t)*data + (*size)++ * elt_byte_size); memset(p, 0, elt_byte_size); return p; } -void wabt_extend_elements(WabtAllocator* allocator, - void** dst, - size_t* dst_size, - size_t* dst_capacity, - const void** src, - size_t src_size, - size_t elt_byte_size) { - wabt_ensure_capacity(allocator, dst, dst_capacity, *dst_size + src_size, - elt_byte_size); +void wabt_extend_elements(void** dst, + size_t* dst_size, + size_t* dst_capacity, + const void** src, + size_t src_size, + size_t elt_byte_size) { + wabt_ensure_capacity(dst, dst_capacity, *dst_size + src_size, elt_byte_size); memcpy((void*)((size_t)*dst + (*dst_size * elt_byte_size)), *src, src_size * elt_byte_size); *dst_size += src_size; diff --git a/src/vector.h b/src/vector.h index 2b58d946..500ebb96 100644 --- a/src/vector.h +++ b/src/vector.h @@ -19,7 +19,6 @@ #include <stddef.h> -#include "allocator.h" #include "common.h" #include "config.h" @@ -33,109 +32,89 @@ * size_t capacity; * } WabtWidgetVector; * - * void wabt_destroy_widget_vector(WabtAllocator*, WabtWidgetVector* vec); - * WabtWidget* wabt_append_widget(WabtAllocator*, WabtWidgetVector* vec); - * void wabt_resize_widget_vector(WabtAllocator*, WabtWidgetVector* vec, - * size_t size); - * void wabt_reserve_widgets(WabtAllocator*, WabtWidgetVector* vec, - * size_t desired); - * void wabt_append_widget_value(WabtAllocator*, WabtWidgetVector* vec, + * void wabt_destroy_widget_vector(WabtWidgetVector* vec); + * WabtWidget* wabt_append_widget(WabtWidgetVector* vec); + * void wabt_resize_widget_vector(WabtWidgetVector* vec, size_t size); + * void wabt_reserve_widgets(WabtWidgetVector* vec, size_t desired); + * void wabt_append_widget_value(WabtWidgetVector* vec, * const WabtWidget* value); - * void wabt_extend_widgets(WabtAllocator*, WabtWidgetVector* dst, - * const WabtWidgetVector* src); + * void wabt_extend_widgets(WabtWidgetVector* dst, const WabtWidgetVector* src); */ -#define WABT_DEFINE_VECTOR(name, type) \ - typedef struct type##Vector { \ - type* data; \ - size_t size; \ - size_t capacity; \ - } type##Vector; \ - \ - WABT_EXTERN_C_BEGIN \ - static WABT_INLINE void wabt_destroy_##name##_vector( \ - struct WabtAllocator* allocator, type##Vector* vec) WABT_UNUSED; \ - static WABT_INLINE void wabt_resize_##name##_vector( \ - struct WabtAllocator* allocator, type##Vector* vec, size_t desired) \ - WABT_UNUSED; \ - static WABT_INLINE void wabt_reserve_##name##s( \ - struct WabtAllocator* allocator, type##Vector* vec, size_t desired) \ - WABT_UNUSED; \ - static WABT_INLINE type* wabt_append_##name(struct WabtAllocator* allocator, \ - type##Vector* vec) WABT_UNUSED; \ - static WABT_INLINE void wabt_append_##name##_value( \ - struct WabtAllocator* allocator, type##Vector* vec, const type* value) \ - WABT_UNUSED; \ - static WABT_INLINE void wabt_extend_##name##s( \ - struct WabtAllocator* allocator, type##Vector* dst, \ - const type##Vector* src) WABT_UNUSED; \ - WABT_EXTERN_C_END \ - \ - void wabt_destroy_##name##_vector(struct WabtAllocator* allocator, \ - type##Vector* vec) { \ - wabt_free(allocator, vec->data); \ - vec->data = NULL; \ - vec->size = 0; \ - vec->capacity = 0; \ - } \ - void wabt_resize_##name##_vector(struct WabtAllocator* allocator, \ - type##Vector* vec, size_t size) { \ - wabt_resize_vector(allocator, (void**)&vec->data, &vec->size, \ - &vec->capacity, size, sizeof(type)); \ - } \ - void wabt_reserve_##name##s(struct WabtAllocator* allocator, \ - type##Vector* vec, size_t desired) { \ - wabt_ensure_capacity(allocator, (void**)&vec->data, &vec->capacity, \ - desired, sizeof(type)); \ - } \ - type* wabt_append_##name(struct WabtAllocator* allocator, \ - type##Vector* vec) { \ - return (type*)wabt_append_element(allocator, (void**)&vec->data, \ - &vec->size, &vec->capacity, \ - sizeof(type)); \ - } \ - void wabt_append_##name##_value(struct WabtAllocator* allocator, \ - type##Vector* vec, const type* value) { \ - type* slot = wabt_append_##name(allocator, vec); \ - *slot = *value; \ - } \ - void wabt_extend_##name##s(struct WabtAllocator* allocator, \ - type##Vector* dst, const type##Vector* src) { \ - wabt_extend_elements(allocator, (void**)&dst->data, &dst->size, \ - &dst->capacity, (const void**)&src->data, src->size, \ - sizeof(type)); \ +#define WABT_DEFINE_VECTOR(name, type) \ + typedef struct type##Vector { \ + type* data; \ + size_t size; \ + size_t capacity; \ + } type##Vector; \ + \ + WABT_EXTERN_C_BEGIN \ + static WABT_INLINE void wabt_destroy_##name##_vector(type##Vector* vec) \ + WABT_UNUSED; \ + static WABT_INLINE void wabt_resize_##name##_vector( \ + type##Vector* vec, size_t desired) WABT_UNUSED; \ + static WABT_INLINE void wabt_reserve_##name##s(type##Vector* vec, \ + size_t desired) WABT_UNUSED; \ + static WABT_INLINE type* wabt_append_##name(type##Vector* vec) WABT_UNUSED; \ + static WABT_INLINE void wabt_append_##name##_value( \ + type##Vector* vec, const type* value) WABT_UNUSED; \ + static WABT_INLINE void wabt_extend_##name##s( \ + type##Vector* dst, const type##Vector* src) WABT_UNUSED; \ + WABT_EXTERN_C_END \ + \ + void wabt_destroy_##name##_vector(type##Vector* vec) { \ + wabt_free(vec->data); \ + vec->data = NULL; \ + vec->size = 0; \ + vec->capacity = 0; \ + } \ + void wabt_resize_##name##_vector(type##Vector* vec, size_t size) { \ + wabt_resize_vector((void**)&vec->data, &vec->size, &vec->capacity, size, \ + sizeof(type)); \ + } \ + void wabt_reserve_##name##s(type##Vector* vec, size_t desired) { \ + wabt_ensure_capacity((void**)&vec->data, &vec->capacity, desired, \ + sizeof(type)); \ + } \ + type* wabt_append_##name(type##Vector* vec) { \ + return (type*)wabt_append_element((void**)&vec->data, &vec->size, \ + &vec->capacity, sizeof(type)); \ + } \ + void wabt_append_##name##_value(type##Vector* vec, const type* value) { \ + type* slot = wabt_append_##name(vec); \ + *slot = *value; \ + } \ + void wabt_extend_##name##s(type##Vector* dst, const type##Vector* src) { \ + wabt_extend_elements((void**)&dst->data, &dst->size, &dst->capacity, \ + (const void**)&src->data, src->size, sizeof(type)); \ } -#define WABT_DESTROY_VECTOR_AND_ELEMENTS(allocator, v, name) \ - { \ - size_t i; \ - for (i = 0; i < (v).size; ++i) \ - wabt_destroy_##name(allocator, &((v).data[i])); \ - wabt_destroy_##name##_vector(allocator, &(v)); \ +#define WABT_DESTROY_VECTOR_AND_ELEMENTS(v, name) \ + { \ + size_t i; \ + for (i = 0; i < (v).size; ++i) \ + wabt_destroy_##name(&((v).data[i])); \ + wabt_destroy_##name##_vector(&(v)); \ } WABT_EXTERN_C_BEGIN -void wabt_ensure_capacity(struct WabtAllocator*, - void** data, +void wabt_ensure_capacity(void** data, size_t* capacity, size_t desired_size, size_t elt_byte_size); -void wabt_resize_vector(struct WabtAllocator*, - void** data, +void wabt_resize_vector(void** data, size_t* size, size_t* capacity, size_t desired_size, size_t elt_byte_size); -void* wabt_append_element(struct WabtAllocator*, - void** data, +void* wabt_append_element(void** data, size_t* size, size_t* capacity, size_t elt_byte_size); -void wabt_extend_elements(struct WabtAllocator*, - void** dst, +void wabt_extend_elements(void** dst, size_t* dst_size, size_t* dst_capacity, const void** src, diff --git a/src/wabt.js b/src/wabt.js index fff5505c..483d3ffc 100644 --- a/src/wabt.js +++ b/src/wabt.js @@ -541,7 +541,6 @@ var ERROR = 1; var I = (function() { -var Allocator = Struct('Allocator'); var AstLexer = Struct('AstLexer'); var BinaryErrorHandler = Struct('BinaryErrorHandler'); var Location = Struct('Location'); @@ -551,7 +550,6 @@ var OutputBuffer = Struct('OutputBuffer'); var ReadBinaryOptions = Struct('ReadBinaryOptions'); var Script = Struct('Script'); var SourceErrorHandler = Struct('SourceErrorHandler'); -var StackAllocator = Struct('StackAllocator'); var Stream = Struct('Stream'); var StrSlice = Struct('StrSlice'); var WriteBinaryOptions = Struct('WriteBinaryOptions'); @@ -561,16 +559,6 @@ var BinaryErrorHandlerCallback = Fn(Void, [U32, Str, UserData]); var SourceErrorHandlerCallback = Fn(Void, [Ptr(Location), Str, StrPtr, StrLen, U32, UserData]); -Allocator.define('allocator', { - alloc: Fn(VoidPtr, [Ptr(Allocator), U32, U32, Str, I32]), - realloc: Fn(VoidPtr, [Ptr(Allocator), VoidPtr, U32, U32, Str, I32]), - free: Fn(VoidPtr, [Ptr(Allocator), VoidPtr, Str, I32]), - destroy: Fn(Void, [Ptr(Allocator)]), - mark: Fn(I32, [Ptr(Allocator)]), - reset_to_mark: Fn(Void, [Ptr(Allocator), I32]), - print_stats: Fn(Void, [Ptr(Allocator)]), -}); - BinaryErrorHandler.define('binary_error_handler', { on_error: BinaryErrorHandlerCallback, user_data: UserData, @@ -591,7 +579,6 @@ MemoryWriter.define('memory_writer', { Module.define('module'); OutputBuffer.define('output_buffer', { - allocator: Allocator, start: BufPtr, size: BufLen, capacity: U32, @@ -609,10 +596,6 @@ SourceErrorHandler.define('source_error_handler', { user_data: UserData, }); -StackAllocator.define('stack_allocator', { - allocator: Allocator, -}); - Stream.define('stream', { writer: Ptr(Writer), result: U32, @@ -644,21 +627,17 @@ var defaultSourceErrorCallback = SourceErrorHandlerCallback.define('_wabt_defaul var destroyAstLexer = Fn(Void, [Ptr(AstLexer)]).define('_wabt_destroy_ast_lexer'); var destroyOutputBuffer = Fn(Void, [Ptr(OutputBuffer)]).define('_wabt_destroy_output_buffer'); var destroyScript = Fn(Void, [Ptr(Script)]).define('_wabt_destroy_script'); -var destroyStackAllocator = Fn(Void, [Ptr(StackAllocator)]).define('_wabt_destroy_stack_allocator'); var getFirstModule = Fn(Ptr(Module), [Ptr(Script)]).define('_wabt_get_first_module'); -var getLibcAllocator = Fn(Ptr(Allocator), []).define('_wabt_get_libc_allocator'); -var initMemWriter = Fn(I32, [Ptr(Allocator), Ptr(MemoryWriter)]).define('_wabt_init_mem_writer'); -var initStackAllocator = Fn(Void, [Ptr(StackAllocator), Ptr(Allocator)]).define('_wabt_init_stack_allocator'); +var initMemWriter = Fn(I32, [Ptr(MemoryWriter)]).define('_wabt_init_mem_writer'); var initStream = Fn(Void, [Ptr(Stream), Ptr(Writer), Ptr(Stream)]).define('_wabt_init_stream'); -var newAstBufferLexer = Fn(Ptr(AstLexer), [Ptr(Allocator), Str, BufPtr, BufLen]).define('_wabt_new_ast_buffer_lexer'); +var newAstBufferLexer = Fn(Ptr(AstLexer), [Str, BufPtr, BufLen]).define('_wabt_new_ast_buffer_lexer'); var parseAst = Fn(I32, [Ptr(AstLexer), Ptr(Script), Ptr(SourceErrorHandler)]).define('_wabt_parse_ast'); -var resolveNamesScript = Fn(I32, [Ptr(Allocator), Ptr(AstLexer), Ptr(Script), Ptr(SourceErrorHandler)]).define('_wabt_resolve_names_script'); -var validateScript = Fn(I32, [Ptr(Allocator), Ptr(AstLexer), Ptr(Script), Ptr(SourceErrorHandler)]).define('_wabt_validate_script'); -var writeBinaryModule = Fn(I32, [Ptr(Allocator), Ptr(Writer), Ptr(Module), Ptr(WriteBinaryOptions)]).define('_wabt_write_binary_module'); +var resolveNamesScript = Fn(I32, [Ptr(AstLexer), Ptr(Script), Ptr(SourceErrorHandler)]).define('_wabt_resolve_names_script'); +var validateScript = Fn(I32, [Ptr(AstLexer), Ptr(Script), Ptr(SourceErrorHandler)]).define('_wabt_validate_script'); +var writeBinaryModule = Fn(I32, [Ptr(Writer), Ptr(Module), Ptr(WriteBinaryOptions)]).define('_wabt_write_binary_module'); return { // Types - Allocator: Allocator, AstLexer: AstLexer, BinaryErrorHandler: BinaryErrorHandler, Location: Location, @@ -668,7 +647,6 @@ return { ReadBinaryOptions: ReadBinaryOptions, Script: Script, SourceErrorHandler: SourceErrorHandler, - StackAllocator: StackAllocator, Stream: Stream, StrSlice: StrSlice, WriteBinaryOptions: WriteBinaryOptions, @@ -681,11 +659,8 @@ return { destroyAstLexer: destroyAstLexer, destroyOutputBuffer: destroyOutputBuffer, destroyScript: destroyScript, - destroyStackAllocator: destroyStackAllocator, getFirstModule: getFirstModule, - getLibcAllocator: getLibcAllocator, initMemWriter: initMemWriter, - initStackAllocator: initStackAllocator, initStream: initStream, newAstBufferLexer: newAstBufferLexer, parseAst: parseAst, @@ -765,28 +740,6 @@ function defineBufferGetter(proto, name, ptrName, lenName) { // Friendly objects //////////////////////////////////////////////////////////// -// Allocator -function Allocator() { - this.$ = null; -} -define$From(Allocator); -Allocator.prototype = Object.create(Object.prototype); - -// StackAllocator -function StackAllocator(fallbackAllocator) { - this.$ = Value.$malloc(I.StackAllocator); - I.initStackAllocator(this.$, fallbackAllocator.$); - this.allocator = Allocator.$from(this.$.allocator); -} -StackAllocator.prototype = Object.create(Object.prototype); -StackAllocator.prototype.$destroy = function() { - I.destroyStackAllocator(this.$); - this.$.$free(); -}; - -// LibcAllocator -LibcAllocator = Allocator.$from(I.getLibcAllocator()); - // Writer function Writer(writeData, moveData) { this.$ = Value.$malloc(I.Writer); @@ -804,9 +757,9 @@ Writer.prototype.$destroy = function() { }; // MemoryWriter -function MemoryWriter(allocator) { +function MemoryWriter() { this.$ = Value.$malloc(I.MemoryWriter); - var result = I.initMemWriter(allocator.$, this.$); + var result = I.initMemWriter(this.$); if (result != OK) { throw new Error('unable to initialize MemoryWriter'); } @@ -848,7 +801,7 @@ Stream.prototype.$destroy = function() { // StringStream function StringStream() { - this.$writer = new MemoryWriter(LibcAllocator); + this.$writer = new MemoryWriter(); Stream.call(this, this.$writer.writer, null); } StringStream.prototype = Object.create(Object.prototype); @@ -863,13 +816,12 @@ StringStream.prototype.$destroy = function() { }; // parseAst -function parseAst(allocator, filename, buffer) { +function parseAst(filename, buffer) { var sourceLineMaxLength = 80; - var astLexer = new AstLexer(allocator, filename, buffer); + var astLexer = new AstLexer(filename, buffer); var errorHandler = new SourceErrorHandler(sourceLineMaxLength); var script = new Script(); var result = I.parseAst(astLexer.$, script.$, errorHandler.$); - script.$allocator = allocator; script.$astLexer = astLexer; script.$errorHandler = errorHandler; if (result != OK) { @@ -880,11 +832,10 @@ function parseAst(allocator, filename, buffer) { } // AstLexer -function AstLexer(allocator, filename, buffer) { +function AstLexer(filename, buffer) { this.$filename = StrValue.$mallocCStr(filename); this.$buffer = BufferValue.$malloc(buffer); - this.$ = I.newAstBufferLexer(allocator.$, this.$filename, this.$buffer, - this.$buffer.size); + this.$ = I.newAstBufferLexer(this.$filename, this.$buffer, this.$buffer.size); if (this.$ === null) { this.$buffer.$free(); this.$filename.$free(); @@ -949,35 +900,32 @@ Location.prototype.$destroy = function() { // Script function Script() { this.$ = Value.$malloc(I.Script); - this.$allocator = null; this.$astLexer = null; this.$errorHandler = null; } Script.prototype = Object.create(Object.prototype); Script.prototype.resolveNames = function() { - var result = I.resolveNamesScript( - this.$allocator.$, this.$astLexer.$, this.$, this.$errorHandler.$); + var result = + I.resolveNamesScript(this.$astLexer.$, this.$, this.$errorHandler.$); if (result != OK) { throw new Error('resolveNames failed:\n' + this.$errorHandler.errorMessage); } }; Script.prototype.validate = function() { - var result = I.validateScript( - this.$allocator.$, this.$astLexer.$, this.$, this.$errorHandler.$); + var result = I.validateScript(this.$astLexer.$, this.$, this.$errorHandler.$); if (result != OK) { throw new Error('validate failed:\n' + this.$errorHandler.errorMessage); } }; Script.prototype.toBinary = function(options) { - var mw = new MemoryWriter(this.$allocator); - options = new WriteBinaryOptions(this.$allocator, options || {}); + var mw = new MemoryWriter(); + options = new WriteBinaryOptions(options || {}); try { var module = I.getFirstModule(this.$); if (module.$addr === 0) { throw new Error('Script has no module.'); } - var result = - I.writeBinaryModule(this.$allocator.$, mw.writer.$, module, options.$); + var result = I.writeBinaryModule(mw.writer.$, module, options.$); if (result != OK) { throw new Error('writeBinaryModule failed'); } @@ -995,7 +943,7 @@ Script.prototype.$destroy = function() { }; // WriteBinaryOptions -function WriteBinaryOptions(allocator, options) { +function WriteBinaryOptions(options) { this.$ = Value.$malloc(I.WriteBinaryOptions); if (options.log) { this.$logStream = new StringStream(); @@ -1057,10 +1005,6 @@ var resolve = wabt.$resolve; wabt = { ready: wabt.ready, - // Types - LibcAllocator: LibcAllocator, - StackAllocator: StackAllocator, - // Functions parseAst: parseAst, }; diff --git a/src/writer.c b/src/writer.c index b76f6768..2833b207 100644 --- a/src/writer.c +++ b/src/writer.c @@ -85,12 +85,9 @@ void wabt_close_file_writer(WabtFileWriter* writer) { fclose(writer->file); } -void wabt_init_output_buffer(WabtAllocator* allocator, - WabtOutputBuffer* buf, - size_t initial_capacity) { +void wabt_init_output_buffer(WabtOutputBuffer* buf, size_t initial_capacity) { assert(initial_capacity != 0); - buf->allocator = allocator; - buf->start = wabt_alloc(allocator, initial_capacity, WABT_DEFAULT_ALIGN); + buf->start = wabt_alloc(initial_capacity); buf->size = 0; buf->capacity = initial_capacity; } @@ -102,8 +99,7 @@ static void ensure_output_buffer_capacity(WabtOutputBuffer* buf, size_t new_capacity = buf->capacity * 2; while (new_capacity < ensure_capacity) new_capacity *= 2; - buf->start = wabt_realloc(buf->allocator, buf->start, new_capacity, - WABT_DEFAULT_ALIGN); + buf->start = wabt_realloc(buf->start, new_capacity); buf->capacity = new_capacity; } } @@ -138,14 +134,12 @@ static WabtResult move_data_in_output_buffer(size_t dst_offset, return WABT_OK; } -WabtResult wabt_init_mem_writer(WabtAllocator* allocator, - WabtMemoryWriter* writer) { +WabtResult wabt_init_mem_writer(WabtMemoryWriter* writer) { WABT_ZERO_MEMORY(*writer); writer->base.user_data = writer; writer->base.write_data = write_data_to_output_buffer; writer->base.move_data = move_data_in_output_buffer; - wabt_init_output_buffer(allocator, &writer->buf, - INITIAL_OUTPUT_BUFFER_CAPACITY); + wabt_init_output_buffer(&writer->buf, INITIAL_OUTPUT_BUFFER_CAPACITY); return WABT_OK; } @@ -192,6 +186,5 @@ WabtResult wabt_write_output_buffer_to_file(WabtOutputBuffer* buf, } void wabt_destroy_output_buffer(WabtOutputBuffer* buf) { - if (buf->allocator) - wabt_free(buf->allocator, buf->start); + wabt_free(buf->start); } diff --git a/src/writer.h b/src/writer.h index 42e4e37d..6626eb8e 100644 --- a/src/writer.h +++ b/src/writer.h @@ -19,7 +19,6 @@ #include <stdio.h> -#include "allocator.h" #include "common.h" typedef struct WabtWriter { @@ -35,7 +34,6 @@ typedef struct WabtWriter { } WabtWriter; typedef struct WabtOutputBuffer { - WabtAllocator* allocator; void* start; size_t size; size_t capacity; @@ -60,8 +58,7 @@ void wabt_init_file_writer_existing(WabtFileWriter* writer, FILE* file); void wabt_close_file_writer(WabtFileWriter* writer); /* WabtMemoryWriter */ -WabtResult wabt_init_mem_writer(WabtAllocator* allocator, - WabtMemoryWriter* writer); +WabtResult wabt_init_mem_writer(WabtMemoryWriter* writer); /* Passes ownership of the buffer to writer */ WabtResult wabt_init_mem_writer_existing(WabtMemoryWriter* writer, WabtOutputBuffer* buf); @@ -70,9 +67,7 @@ void wabt_steal_mem_writer_output_buffer(WabtMemoryWriter* writer, void wabt_close_mem_writer(WabtMemoryWriter* writer); /* WabtOutputBuffer */ -void wabt_init_output_buffer(WabtAllocator* allocator, - WabtOutputBuffer* buf, - size_t initial_capacity); +void wabt_init_output_buffer(WabtOutputBuffer* buf, size_t initial_capacity); WabtResult wabt_write_output_buffer_to_file(WabtOutputBuffer* buf, const char* filename); void wabt_destroy_output_buffer(WabtOutputBuffer* buf); |