diff options
40 files changed, 3477 insertions, 3819 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index a0b9f95b..82d960b3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -241,7 +241,6 @@ add_library(libwabt STATIC src/literal.cc src/option-parser.cc src/stream.cc - src/vector.cc src/writer.cc ) set_target_properties(libwabt PROPERTIES OUTPUT_NAME wabt) diff --git a/src/apply-names.cc b/src/apply-names.cc index c2dabe40..e3bfc964 100644 --- a/src/apply-names.cc +++ b/src/apply-names.cc @@ -19,6 +19,8 @@ #include <assert.h> #include <stdio.h> +#include <vector> + #include "ast.h" #define CHECK_RESULT(expr) \ @@ -31,9 +33,6 @@ namespace wabt { namespace { -typedef Label* LabelPtr; -WABT_DEFINE_VECTOR(label_ptr, LabelPtr); - struct Context { Context(); @@ -43,35 +42,33 @@ struct Context { /* mapping from param index to its name, if any, for the current func */ std::vector<std::string> param_index_to_name; std::vector<std::string> local_index_to_name; - LabelPtrVector labels; + std::vector<Label*> labels; }; Context::Context() { WABT_ZERO_MEMORY(visitor); - WABT_ZERO_MEMORY(labels); } void push_label(Context* ctx, Label* label) { - append_label_ptr_value(&ctx->labels, &label); + ctx->labels.push_back(label); } void pop_label(Context* ctx) { - assert(ctx->labels.size > 0); - ctx->labels.size--; + ctx->labels.pop_back(); } Label* find_label_by_var(Context* ctx, Var* var) { if (var->type == VarType::Name) { - for (int i = ctx->labels.size - 1; i >= 0; --i) { - Label* label = ctx->labels.data[i]; + for (int i = ctx->labels.size() - 1; i >= 0; --i) { + Label* label = ctx->labels[i]; if (string_slices_are_equal(label, &var->name)) return label; } return nullptr; } else { - if (var->index < 0 || static_cast<size_t>(var->index) >= ctx->labels.size) + if (var->index < 0 || static_cast<size_t>(var->index) >= ctx->labels.size()) return nullptr; - return ctx->labels.data[ctx->labels.size - 1 - var->index]; + return ctx->labels[ctx->labels.size() - 1 - var->index]; } } @@ -160,7 +157,7 @@ Result use_name_for_param_and_local_var(Context* ctx, Func* func, Var* var) { Result begin_block_expr(Expr* expr, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - push_label(ctx, &expr->block.label); + push_label(ctx, &expr->block->label); return Result::Ok; } @@ -172,7 +169,7 @@ Result end_block_expr(Expr* expr, void* user_data) { Result begin_loop_expr(Expr* expr, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - push_label(ctx, &expr->loop.label); + push_label(ctx, &expr->loop->label); return Result::Ok; } @@ -198,11 +195,10 @@ Result on_br_if_expr(Expr* expr, void* user_data) { Result on_br_table_expr(Expr* expr, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - VarVector* targets = &expr->br_table.targets; - for (size_t i = 0; i < targets->size; ++i) { - Var* target = &targets->data[i]; - Label* label = find_label_by_var(ctx, target); - use_name_for_var(label, target); + VarVector& targets = *expr->br_table.targets; + for (Var& target : targets) { + Label* label = find_label_by_var(ctx, &target); + use_name_for_var(label, &target); } Label* label = find_label_by_var(ctx, &expr->br_table.default_target); @@ -238,7 +234,7 @@ Result on_get_local_expr(Expr* expr, void* user_data) { Result begin_if_expr(Expr* expr, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - push_label(ctx, &expr->if_.true_.label); + push_label(ctx, &expr->if_.true_->label); return Result::Ok; } @@ -297,8 +293,8 @@ Result visit_elem_segment(Context* ctx, uint32_t elem_segment_index, ElemSegment* segment) { CHECK_RESULT(use_name_for_table_var(ctx->module, &segment->table_var)); - for (size_t i = 0; i < segment->vars.size; ++i) { - CHECK_RESULT(use_name_for_func_var(ctx->module, &segment->vars.data[i])); + for (Var& var : segment->vars) { + CHECK_RESULT(use_name_for_func_var(ctx->module, &var)); } return Result::Ok; } @@ -311,14 +307,14 @@ Result visit_data_segment(Context* ctx, } Result visit_module(Context* ctx, Module* module) { - for (size_t i = 0; i < module->funcs.size; ++i) - CHECK_RESULT(visit_func(ctx, i, module->funcs.data[i])); - for (size_t i = 0; i < module->exports.size; ++i) - CHECK_RESULT(visit_export(ctx, i, module->exports.data[i])); - for (size_t i = 0; i < module->elem_segments.size; ++i) - CHECK_RESULT(visit_elem_segment(ctx, i, module->elem_segments.data[i])); - for (size_t i = 0; i < module->data_segments.size; ++i) - CHECK_RESULT(visit_data_segment(ctx, i, module->data_segments.data[i])); + for (size_t i = 0; i < module->funcs.size(); ++i) + CHECK_RESULT(visit_func(ctx, i, module->funcs[i])); + for (size_t i = 0; i < module->exports.size(); ++i) + CHECK_RESULT(visit_export(ctx, i, module->exports[i])); + for (size_t i = 0; i < module->elem_segments.size(); ++i) + CHECK_RESULT(visit_elem_segment(ctx, i, module->elem_segments[i])); + for (size_t i = 0; i < module->data_segments.size(); ++i) + CHECK_RESULT(visit_data_segment(ctx, i, module->data_segments[i])); return Result::Ok; } @@ -345,7 +341,6 @@ Result apply_names(Module* module) { ctx.visitor.on_set_local_expr = on_set_local_expr; ctx.visitor.on_tee_local_expr = on_tee_local_expr; Result result = visit_module(&ctx, module); - destroy_label_ptr_vector(&ctx.labels); return result; } diff --git a/src/ast-lexer.cc b/src/ast-lexer.cc index 30e57af1..76af1a1b 100644 --- a/src/ast-lexer.cc +++ b/src/ast-lexer.cc @@ -23,7 +23,6 @@ #include "ast-parser.h" #include "ast-parser-lexer-shared.h" -#include "vector.h" /* must be included after so some typedefs will be defined */ #include "ast-parser-gen.hh" diff --git a/src/ast-lexer.h b/src/ast-lexer.h index 3e36a67a..f2325a30 100644 --- a/src/ast-lexer.h +++ b/src/ast-lexer.h @@ -21,7 +21,6 @@ #include <stdio.h> #include "common.h" -#include "vector.h" namespace wabt { diff --git a/src/ast-parser-lexer-shared.cc b/src/ast-parser-lexer-shared.cc index e35d1e35..eab46b36 100644 --- a/src/ast-parser-lexer-shared.cc +++ b/src/ast-parser-lexer-shared.cc @@ -73,16 +73,6 @@ void ast_format_error(SourceErrorHandler* error_handler, va_end(args_copy); } -void destroy_optional_export(OptionalExport* export_) { - if (export_->has_export) - destroy_export(&export_->export_); -} - -void destroy_exported_func(ExportedFunc* exported_func) { - destroy_optional_export(&exported_func->export_); - delete exported_func->func; -} - void destroy_text_list(TextList* text_list) { TextListNode* node = text_list->first; while (node) { @@ -93,45 +83,35 @@ void destroy_text_list(TextList* text_list) { } } +FuncField::FuncField() + : type(FuncFieldType::Exprs), first_expr(nullptr), next(nullptr) {} + +FuncField::~FuncField() { + switch (type) { + case FuncFieldType::Exprs: + destroy_expr_list(first_expr); + break; + + case FuncFieldType::ParamTypes: + case FuncFieldType::LocalTypes: + case FuncFieldType::ResultTypes: + delete types; + break; + + case FuncFieldType::BoundParam: + case FuncFieldType::BoundLocal: + destroy_string_slice(&bound_type.name); + break; + } +} + void destroy_func_fields(FuncField* func_field) { /* destroy the entire linked-list */ while (func_field) { FuncField* next_func_field = func_field->next; - - switch (func_field->type) { - case FuncFieldType::Exprs: - destroy_expr_list(func_field->first_expr); - break; - - case FuncFieldType::ParamTypes: - case FuncFieldType::LocalTypes: - case FuncFieldType::ResultTypes: - destroy_type_vector(&func_field->types); - break; - - case FuncFieldType::BoundParam: - case FuncFieldType::BoundLocal: - destroy_string_slice(&func_field->bound_type.name); - break; - } - delete func_field; func_field = next_func_field; } } -void destroy_exported_memory(ExportedMemory* memory) { - destroy_memory(&memory->memory); - destroy_optional_export(&memory->export_); - if (memory->has_data_segment) - destroy_data_segment(&memory->data_segment); -} - -void destroy_exported_table(ExportedTable* table) { - destroy_table(&table->table); - destroy_optional_export(&table->export_); - if (table->has_elem_segment) - destroy_elem_segment(&table->elem_segment); -} - } // namespace wabt diff --git a/src/ast-parser-lexer-shared.h b/src/ast-parser-lexer-shared.h index cb0f7bd8..b06da3c2 100644 --- a/src/ast-parser-lexer-shared.h +++ b/src/ast-parser-lexer-shared.h @@ -19,6 +19,8 @@ #include <stdarg.h> +#include <memory> + #include "ast.h" #include "ast-lexer.h" #include "common.h" @@ -49,30 +51,30 @@ struct TextList { }; struct OptionalExport { - Export export_; + std::unique_ptr<Export> export_; bool has_export; }; struct ExportedFunc { - Func* func; + std::unique_ptr<Func> func; OptionalExport export_; }; struct ExportedGlobal { - Global global; + std::unique_ptr<Global> global; OptionalExport export_; }; struct ExportedTable { - Table table; - ElemSegment elem_segment; + std::unique_ptr<Table> table; + std::unique_ptr<ElemSegment> elem_segment; OptionalExport export_; bool has_elem_segment; }; struct ExportedMemory { - Memory memory; - DataSegment data_segment; + std::unique_ptr<Memory> memory; + std::unique_ptr<DataSegment> data_segment; OptionalExport export_; bool has_data_segment; }; @@ -87,16 +89,24 @@ enum class FuncFieldType { }; struct BoundType { + WABT_DISALLOW_COPY_AND_ASSIGN(BoundType); + BoundType(); + ~BoundType(); + Location loc; StringSlice name; Type type; }; struct FuncField { + WABT_DISALLOW_COPY_AND_ASSIGN(FuncField); + FuncField(); + ~FuncField(); + FuncFieldType type; union { Expr* first_expr; /* WABT_FUNC_FIELD_TYPE_EXPRS */ - TypeVector types; /* WABT_FUNC_FIELD_TYPE_*_TYPES */ + TypeVector* types; /* WABT_FUNC_FIELD_TYPE_*_TYPES */ BoundType bound_type; /* WABT_FUNC_FIELD_TYPE_BOUND_{LOCAL, PARAM} */ }; struct FuncField* next; @@ -112,40 +122,40 @@ union Token { /* non-terminals */ /* some of these use pointers to keep the size of Token down; copying the tokens is a hotspot when parsing large files. */ - Action action; - Block block; + Action* action; + Block* block; Command* command; - CommandVector commands; + CommandPtrVector* commands; Const const_; - ConstVector consts; - DataSegment data_segment; - ElemSegment elem_segment; - Export export_; - ExportedFunc exported_func; - ExportedGlobal exported_global; - ExportedMemory exported_memory; - ExportedTable exported_table; + ConstVector* consts; + DataSegment* data_segment; + ElemSegment* elem_segment; + Export* export_; + ExportedFunc* exported_func; + ExportedGlobal* exported_global; + ExportedMemory* exported_memory; + ExportedTable* exported_table; Expr* expr; ExprList expr_list; FuncField* func_fields; Func* func; - FuncSignature func_sig; - FuncType func_type; - Global global; + FuncSignature* func_sig; + FuncType* func_type; + Global* global; Import* import; Limits limits; - OptionalExport optional_export; - Memory memory; + OptionalExport* optional_export; + Memory* memory; Module* module; - RawModule raw_module; + RawModule* raw_module; Script* script; - Table table; + Table* table; TextList text_list; - TypeVector types; + TypeVector* types; uint32_t u32; uint64_t u64; Var var; - VarVector vars; + VarVector* vars; }; struct AstParser { @@ -175,11 +185,6 @@ void ast_format_error(SourceErrorHandler*, AstLexer*, const char* format, va_list); -void destroy_optional_export(OptionalExport*); -void destroy_exported_func(ExportedFunc*); -void destroy_exported_global(ExportedFunc*); -void destroy_exported_memory(ExportedMemory*); -void destroy_exported_table(ExportedTable*); void destroy_func_fields(FuncField*); void destroy_text_list(TextList*); diff --git a/src/ast-parser.y b/src/ast-parser.y index 9c5d4eb0..7977586a 100644 --- a/src/ast-parser.y +++ b/src/ast-parser.y @@ -21,6 +21,7 @@ #include <stdlib.h> #include <algorithm> +#include <utility> #include "ast-parser.h" #include "ast-parser-lexer-shared.h" @@ -81,44 +82,40 @@ field->kind = item; \ } while (0) -#define APPEND_ITEM_TO_VECTOR(module, Kind, kind, kinds, item_ptr) \ - do { \ - Kind* dummy = item_ptr; \ - append_##kind##_ptr_value(&(module)->kinds, &dummy); \ - } while (0) +#define APPEND_ITEM_TO_VECTOR(module, kinds, item_ptr) \ + (module)->kinds.push_back(item_ptr) #define INSERT_BINDING(module, kind, kinds, loc_, name) \ do \ if ((name).start) { \ (module)->kind##_bindings.emplace( \ string_slice_to_string(name), \ - Binding(loc_, (module)->kinds.size - 1)); \ + Binding(loc_, (module)->kinds.size() - 1)); \ } \ while (0) #define APPEND_INLINE_EXPORT(module, Kind, loc_, value, index_) \ do \ - if ((value).export_.has_export) { \ + if ((value)->export_.has_export) { \ ModuleField* export_field; \ APPEND_FIELD_TO_LIST(module, export_field, Export, export_, loc_, \ - (value).export_.export_); \ - export_field->export_.kind = ExternalKind::Kind; \ - export_field->export_.var.loc = loc_; \ - export_field->export_.var.index = index_; \ - APPEND_ITEM_TO_VECTOR(module, Export, export, exports, \ - &export_field->export_); \ + (value)->export_.export_.release()); \ + export_field->export_->kind = ExternalKind::Kind; \ + export_field->export_->var.loc = loc_; \ + export_field->export_->var.index = index_; \ + APPEND_ITEM_TO_VECTOR(module, exports, export_field->export_); \ INSERT_BINDING(module, export, exports, export_field->loc, \ - export_field->export_.name); \ + export_field->export_->name); \ } \ while (0) -#define CHECK_IMPORT_ORDERING(module, kind, kinds, loc_) \ - do { \ - if ((module)->kinds.size != (module)->num_##kind##_imports) { \ - ast_parser_error( \ - &loc_, lexer, parser, \ - "imports must occur before all non-import definitions"); \ - } \ +#define CHECK_IMPORT_ORDERING(module, kind, kinds, loc_) \ + do { \ + if ((module)->kinds.size() != (module)->num_##kind##_imports) { \ + ast_parser_error( \ + &loc_, lexer, parser, \ + "imports must occur before all non-import definitions"); \ + } \ } while (0) #define CHECK_END_LABEL(loc, begin_label, end_label) \ @@ -151,12 +148,6 @@ ExprList join_exprs2(Location* loc, ExprList* expr1, Expr* expr2); -FuncField* new_func_field(void) { return new FuncField(); } -Command* new_command(void) { return new Command(); } -Module* new_module(void) { return new Module(); } -Import* new_import(void) { return new Import(); } -TextListNode* new_text_list_node(void) { return new TextListNode(); } - Result parse_const(Type type, LiteralType literal_type, const char* s, @@ -164,7 +155,7 @@ Result parse_const(Type type, Const* out); void dup_text_list(TextList* text_list, char** out_data, size_t* out_size); -bool is_empty_signature(FuncSignature* sig); +bool is_empty_signature(const FuncSignature* sig); void append_implicit_func_declaration(Location*, Module*, @@ -256,32 +247,36 @@ static bool 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 { destroy_block(&$$); } <block> -%destructor { destroy_command($$); delete $$; } <command> -%destructor { destroy_command_vector_and_elements(&$$); } <commands> -%destructor { destroy_const_vector(&$$); } <consts> -%destructor { destroy_elem_segment(&$$); } <elem_segment> -%destructor { destroy_export(&$$); } <export_> -%destructor { destroy_exported_func(&$$); } <exported_func> -%destructor { destroy_exported_memory(&$$); } <exported_memory> -%destructor { destroy_exported_table(&$$); } <exported_table> -%destructor { destroy_expr($$); } <expr> +%destructor { destroy_string_slice(&$$); } <text> +%destructor { destroy_string_slice(&$$.text); } <literal> +%destructor { delete $$; } <action> +%destructor { delete $$; } <block> +%destructor { delete $$; } <command> +%destructor { delete $$; } <commands> +%destructor { delete $$; } <consts> +%destructor { delete $$; } <data_segment> +%destructor { delete $$; } <elem_segment> +%destructor { delete $$; } <export_> +%destructor { delete $$; } <exported_func> +%destructor { delete $$; } <exported_memory> +%destructor { delete $$; } <exported_table> +%destructor { delete $$; } <expr> %destructor { destroy_expr_list($$.first); } <expr_list> %destructor { destroy_func_fields($$); } <func_fields> %destructor { delete $$; } <func> -%destructor { destroy_func_signature(&$$); } <func_sig> -%destructor { destroy_func_type(&$$); } <func_type> -%destructor { destroy_import($$); delete $$; } <import> -%destructor { destroy_data_segment(&$$); } <data_segment> +%destructor { delete $$; } <func_sig> +%destructor { delete $$; } <func_type> +%destructor { delete $$; } <global> +%destructor { delete $$; } <import> +%destructor { delete $$; } <optional_export> +%destructor { delete $$; } <memory> %destructor { delete $$; } <module> -%destructor { destroy_raw_module(&$$); } <raw_module> -%destructor { destroy_string_slice(&$$.text); } <literal> +%destructor { delete $$; } <raw_module> %destructor { delete $$; } <script> -%destructor { destroy_string_slice(&$$); } <text> %destructor { destroy_text_list(&$$); } <text_list> -%destructor { destroy_type_vector(&$$); } <types> -%destructor { destroy_var_vector_and_elements(&$$); } <vars> +%destructor { delete $$; } <types> %destructor { destroy_var(&$$); } <var> +%destructor { delete $$; } <vars> %nonassoc LOW @@ -295,14 +290,14 @@ static bool on_read_binary_error(uint32_t offset, const char* error, non_empty_text_list : TEXT { - TextListNode* node = new_text_list_node(); + TextListNode* node = new TextListNode(); DUPTEXT(node->text, $1); node->next = nullptr; $$.first = $$.last = node; } | non_empty_text_list TEXT { $$ = $1; - TextListNode* node = new_text_list_node(); + TextListNode* node = new TextListNode(); DUPTEXT(node->text, $2); node->next = nullptr; $$.last->next = node; @@ -333,10 +328,10 @@ quoted_text : /* Types */ value_type_list : - /* empty */ { WABT_ZERO_MEMORY($$); } + /* empty */ { $$ = new TypeVector(); } | value_type_list VALUE_TYPE { $$ = $1; - append_type_value(&$$, &$2); + $$->push_back($2); } ; elem_type : @@ -344,41 +339,51 @@ elem_type : ; global_type : VALUE_TYPE { - WABT_ZERO_MEMORY($$); - $$.type = $1; - $$.mutable_ = false; + $$ = new Global(); + $$->type = $1; + $$->mutable_ = false; } | LPAR MUT VALUE_TYPE RPAR { - WABT_ZERO_MEMORY($$); - $$.type = $3; - $$.mutable_ = true; + $$ = new Global(); + $$->type = $3; + $$->mutable_ = true; } ; func_type : LPAR FUNC func_sig RPAR { $$ = $3; } ; func_sig : - /* empty */ { WABT_ZERO_MEMORY($$); } + /* empty */ { $$ = new FuncSignature(); } | LPAR PARAM value_type_list RPAR { - WABT_ZERO_MEMORY($$); - $$.param_types = $3; + $$ = new FuncSignature(); + $$->param_types = std::move(*$3); + delete $3; } | LPAR PARAM value_type_list RPAR LPAR RESULT value_type_list RPAR { - WABT_ZERO_MEMORY($$); - $$.param_types = $3; - $$.result_types = $7; + $$ = new FuncSignature(); + $$->param_types = std::move(*$3); + delete $3; + $$->result_types = std::move(*$7); + delete $7; } | LPAR RESULT value_type_list RPAR { - WABT_ZERO_MEMORY($$); - $$.result_types = $3; + $$ = new FuncSignature(); + $$->result_types = std::move(*$3); + delete $3; } ; table_sig : - limits elem_type { $$.elem_limits = $1; } + limits elem_type { + $$ = new Table(); + $$->elem_limits = $1; + } ; memory_sig : - limits { $$.page_limits = $1; } + limits { + $$ = new Memory(); + $$->page_limits = $1; + } ; limits : nat { @@ -437,10 +442,10 @@ var : } ; var_list : - /* empty */ { WABT_ZERO_MEMORY($$); } + /* empty */ { $$ = new VarVector(); } | var_list var { $$ = $1; - append_var_value(&$$, &$2); + $$->push_back($2); } ; bind_var_opt : @@ -486,141 +491,117 @@ instr : ; plain_instr : UNREACHABLE { - $$ = new_unreachable_expr(); + $$ = Expr::CreateUnreachable(); } | NOP { - $$ = new_nop_expr(); + $$ = Expr::CreateNop(); } | DROP { - $$ = new_drop_expr(); + $$ = Expr::CreateDrop(); } | SELECT { - $$ = new_select_expr(); + $$ = Expr::CreateSelect(); } | BR var { - $$ = new_br_expr(); - $$->br.var = $2; + $$ = Expr::CreateBr($2); } | BR_IF var { - $$ = new_br_if_expr(); - $$->br_if.var = $2; + $$ = Expr::CreateBrIf($2); } | BR_TABLE var_list var { - $$ = new_br_table_expr(); - $$->br_table.targets = $2; - $$->br_table.default_target = $3; + $$ = Expr::CreateBrTable($2, $3); } | RETURN { - $$ = new_return_expr(); + $$ = Expr::CreateReturn(); } | CALL var { - $$ = new_call_expr(); - $$->call.var = $2; + $$ = Expr::CreateCall($2); } | CALL_INDIRECT var { - $$ = new_call_indirect_expr(); - $$->call_indirect.var = $2; + $$ = Expr::CreateCallIndirect($2); } | GET_LOCAL var { - $$ = new_get_local_expr(); - $$->get_local.var = $2; + $$ = Expr::CreateGetLocal($2); } | SET_LOCAL var { - $$ = new_set_local_expr(); - $$->set_local.var = $2; + $$ = Expr::CreateSetLocal($2); } | TEE_LOCAL var { - $$ = new_tee_local_expr(); - $$->tee_local.var = $2; + $$ = Expr::CreateTeeLocal($2); } | GET_GLOBAL var { - $$ = new_get_global_expr(); - $$->get_global.var = $2; + $$ = Expr::CreateGetGlobal($2); } | SET_GLOBAL var { - $$ = new_set_global_expr(); - $$->set_global.var = $2; + $$ = Expr::CreateSetGlobal($2); } | LOAD offset_opt align_opt { - $$ = new_load_expr(); - $$->load.opcode = $1; - $$->load.offset = $2; - $$->load.align = $3; + $$ = Expr::CreateLoad($1, $3, $2); } | STORE offset_opt align_opt { - $$ = new_store_expr(); - $$->store.opcode = $1; - $$->store.offset = $2; - $$->store.align = $3; + $$ = Expr::CreateStore($1, $3, $2); } | CONST literal { - $$ = new_const_expr(); - $$->const_.loc = @1; + Const const_; + WABT_ZERO_MEMORY(const_); + const_.loc = @1; if (WABT_FAILED(parse_const($1, $2.type, $2.text.start, - $2.text.start + $2.text.length, - &$$->const_))) { + $2.text.start + $2.text.length, &const_))) { ast_parser_error(&@2, lexer, parser, "invalid literal \"" PRIstringslice "\"", WABT_PRINTF_STRING_SLICE_ARG($2.text)); } delete [] $2.text.start; + $$ = Expr::CreateConst(const_); } | UNARY { - $$ = new_unary_expr(); - $$->unary.opcode = $1; + $$ = Expr::CreateUnary($1); } | BINARY { - $$ = new_binary_expr(); - $$->binary.opcode = $1; + $$ = Expr::CreateBinary($1); } | COMPARE { - $$ = new_compare_expr(); - $$->compare.opcode = $1; + $$ = Expr::CreateCompare($1); } | CONVERT { - $$ = new_convert_expr(); - $$->convert.opcode = $1; + $$ = Expr::CreateConvert($1); } | CURRENT_MEMORY { - $$ = new_current_memory_expr(); + $$ = Expr::CreateCurrentMemory(); } | GROW_MEMORY { - $$ = new_grow_memory_expr(); + $$ = Expr::CreateGrowMemory(); } ; block_instr : BLOCK labeling_opt block END labeling_opt { - $$ = new_block_expr(); - $$->block = $3; - $$->block.label = $2; - CHECK_END_LABEL(@5, $$->block.label, $5); + $$ = Expr::CreateBlock($3); + $$->block->label = $2; + CHECK_END_LABEL(@5, $$->block->label, $5); } | LOOP labeling_opt block END labeling_opt { - $$ = new_loop_expr(); - $$->loop = $3; - $$->loop.label = $2; - CHECK_END_LABEL(@5, $$->block.label, $5); + $$ = Expr::CreateLoop($3); + $$->loop->label = $2; + CHECK_END_LABEL(@5, $$->loop->label, $5); } | IF labeling_opt block END labeling_opt { - $$ = new_if_expr(); - $$->if_.true_ = $3; - $$->if_.true_.label = $2; - CHECK_END_LABEL(@5, $$->block.label, $5); + $$ = Expr::CreateIf($3, nullptr); + $$->if_.true_->label = $2; + CHECK_END_LABEL(@5, $$->if_.true_->label, $5); } | IF labeling_opt block ELSE labeling_opt instr_list END labeling_opt { - $$ = new_if_expr(); - $$->if_.true_ = $3; - $$->if_.true_.label = $2; - $$->if_.false_ = $6.first; - CHECK_END_LABEL(@5, $$->block.label, $5); - CHECK_END_LABEL(@8, $$->block.label, $8); + $$ = Expr::CreateIf($3, $6.first); + $$->if_.true_->label = $2; + CHECK_END_LABEL(@5, $$->if_.true_->label, $5); + CHECK_END_LABEL(@8, $$->if_.true_->label, $8); } ; block : value_type_list instr_list { - WABT_ZERO_MEMORY($$); - $$.sig = $1; - $$.first = $2.first; + $$ = new Block(); + $$->sig = std::move(*$1); + delete $1; + $$->first = $2.first; } ; @@ -633,57 +614,47 @@ expr1 : $$ = join_exprs2(&@1, &$2, $1); } | BLOCK labeling_opt block { - Expr* expr = new_block_expr(); - expr->block = $3; - expr->block.label = $2; + Expr* expr = Expr::CreateBlock($3); + expr->block->label = $2; $$ = join_exprs1(&@1, expr); } | LOOP labeling_opt block { - Expr* expr = new_loop_expr(); - expr->loop = $3; - expr->loop.label = $2; + Expr* expr = Expr::CreateLoop($3); + expr->loop->label = $2; $$ = join_exprs1(&@1, expr); } | IF labeling_opt value_type_list if_ { $$ = $4; Expr* if_ = $4.last; assert(if_->type == ExprType::If); - if_->if_.true_.label = $2; - if_->if_.true_.sig = $3; + if_->if_.true_->label = $2; + if_->if_.true_->sig = std::move(*$3); + delete $3; } ; if_ : LPAR THEN instr_list RPAR LPAR ELSE instr_list RPAR { - Expr* expr = new_if_expr(); - expr->if_.true_.first = $3.first; - expr->if_.false_ = $7.first; + Expr* expr = Expr::CreateIf(new Block($3.first), $7.first); $$ = join_exprs1(&@1, expr); } | LPAR THEN instr_list RPAR { - Expr* expr = new_if_expr(); - expr->if_.true_.first = $3.first; + Expr* expr = Expr::CreateIf(new Block($3.first), nullptr); $$ = join_exprs1(&@1, expr); } | expr LPAR THEN instr_list RPAR LPAR ELSE instr_list RPAR { - Expr* expr = new_if_expr(); - expr->if_.true_.first = $4.first; - expr->if_.false_ = $8.first; + Expr* expr = Expr::CreateIf(new Block($4.first), $8.first); $$ = join_exprs2(&@1, &$1, expr); } | expr LPAR THEN instr_list RPAR { - Expr* expr = new_if_expr(); - expr->if_.true_.first = $4.first; + Expr* expr = Expr::CreateIf(new Block($4.first), nullptr); $$ = join_exprs2(&@1, &$1, expr); } | expr expr expr { - Expr* expr = new_if_expr(); - expr->if_.true_.first = $2.first; - expr->if_.false_ = $3.first; + Expr* expr = Expr::CreateIf(new Block($2.first), $3.first); $$ = join_exprs2(&@1, &$1, expr); } | expr expr { - Expr* expr = new_if_expr(); - expr->if_.true_.first = $2.first; + Expr* expr = Expr::CreateIf(new Block($2.first), nullptr); $$ = join_exprs2(&@1, &$1, expr); } ; @@ -714,19 +685,19 @@ const_expr : func_fields : func_body | LPAR RESULT value_type_list RPAR func_body { - $$ = new_func_field(); + $$ = new FuncField(); $$->type = FuncFieldType::ResultTypes; $$->types = $3; $$->next = $5; } | LPAR PARAM value_type_list RPAR func_fields { - $$ = new_func_field(); + $$ = new FuncField(); $$->type = FuncFieldType::ParamTypes; $$->types = $3; $$->next = $5; } | LPAR PARAM bind_var VALUE_TYPE RPAR func_fields { - $$ = new_func_field(); + $$ = new FuncField(); $$->type = FuncFieldType::BoundParam; $$->bound_type.loc = @2; $$->bound_type.name = $3; @@ -736,19 +707,19 @@ func_fields : ; func_body : instr_list { - $$ = new_func_field(); + $$ = new FuncField(); $$->type = FuncFieldType::Exprs; $$->first_expr = $1.first; $$->next = nullptr; } | LPAR LOCAL value_type_list RPAR func_body { - $$ = new_func_field(); + $$ = new FuncField(); $$->type = FuncFieldType::LocalTypes; $$->types = $3; $$->next = $5; } | LPAR LOCAL bind_var VALUE_TYPE RPAR func_body { - $$ = new_func_field(); + $$ = new FuncField(); $$->type = FuncFieldType::BoundLocal; $$->bound_type.loc = @2; $$->bound_type.name = $3; @@ -766,15 +737,16 @@ func_info : switch (field->type) { case FuncFieldType::Exprs: $$->first_expr = field->first_expr; + field->first_expr = nullptr; break; case FuncFieldType::ParamTypes: case FuncFieldType::LocalTypes: { - TypeVector* types = field->type == FuncFieldType::ParamTypes - ? &$$->decl.sig.param_types - : &$$->local_types; - extend_types(types, &field->types); - destroy_type_vector(&field->types); + TypeVector& types = field->type == FuncFieldType::ParamTypes + ? $$->decl.sig.param_types + : $$->local_types; + types.insert(types.end(), field->types->begin(), + field->types->end()); break; } @@ -790,19 +762,18 @@ func_info : bindings = &$$->local_bindings; } - append_type_value(types, &field->bound_type.type); - bindings->emplace(string_slice_to_string(field->bound_type.name), - Binding(field->bound_type.loc, types->size - 1)); - destroy_string_slice(&field->bound_type.name); + types->push_back(field->bound_type.type); + bindings->emplace( + string_slice_to_string(field->bound_type.name), + Binding(field->bound_type.loc, types->size() - 1)); break; } case FuncFieldType::ResultTypes: - $$->decl.sig.result_types = field->types; + $$->decl.sig.result_types = std::move(*field->types); break; } - /* we steal memory from the func field, but not the linked list nodes */ delete field; field = next; } @@ -810,32 +781,34 @@ func_info : ; func : LPAR FUNC bind_var_opt inline_export type_use func_info RPAR { - WABT_ZERO_MEMORY($$); - $$.func = $6; - $$.func->decl.flags |= WABT_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; - $$.func->decl.type_var = $5; - $$.func->name = $3; - $$.export_ = $4; + $$ = new ExportedFunc(); + $$->func.reset($6); + $$->func->decl.has_func_type = true; + $$->func->decl.type_var = $5; + $$->func->name = $3; + $$->export_ = std::move(*$4); + delete $4; } /* Duplicate above for empty inline_export_opt to avoid LR(1) conflict. */ | LPAR FUNC bind_var_opt type_use func_info RPAR { - WABT_ZERO_MEMORY($$); - $$.func = $5; - $$.func->decl.flags |= WABT_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; - $$.func->decl.type_var = $4; - $$.func->name = $3; + $$ = new ExportedFunc(); + $$->func.reset($5); + $$->func->decl.has_func_type = true; + $$->func->decl.type_var = $4; + $$->func->name = $3; } | LPAR FUNC bind_var_opt inline_export func_info RPAR { - WABT_ZERO_MEMORY($$); - $$.func = $5; - $$.func->name = $3; - $$.export_ = $4; + $$ = new ExportedFunc(); + $$->func.reset($5); + $$->func->name = $3; + $$->export_ = std::move(*$4); + delete $4; } /* Duplicate above for empty inline_export_opt to avoid LR(1) conflict. */ | LPAR FUNC bind_var_opt func_info RPAR { - WABT_ZERO_MEMORY($$); - $$.func = $4; - $$.func->name = $3; + $$ = new ExportedFunc(); + $$->func.reset($4); + $$->func->name = $3; } ; @@ -850,129 +823,138 @@ offset : elem : LPAR ELEM var offset var_list RPAR { - WABT_ZERO_MEMORY($$); - $$.table_var = $3; - $$.offset = $4.first; - $$.vars = $5; + $$ = new ElemSegment(); + $$->table_var = $3; + $$->offset = $4.first; + $$->vars = std::move(*$5); + delete $5; } | LPAR ELEM offset var_list RPAR { - WABT_ZERO_MEMORY($$); - $$.table_var.loc = @2; - $$.table_var.type = VarType::Index; - $$.table_var.index = 0; - $$.offset = $3.first; - $$.vars = $4; + $$ = new ElemSegment(); + $$->table_var.loc = @2; + $$->table_var.type = VarType::Index; + $$->table_var.index = 0; + $$->offset = $3.first; + $$->vars = std::move(*$4); + delete $4; } ; table : LPAR TABLE bind_var_opt inline_export_opt table_sig RPAR { - $$.table = $5; - $$.table.name = $3; - $$.has_elem_segment = false; - $$.export_ = $4; + $$ = new ExportedTable(); + $$->table.reset($5); + $$->table->name = $3; + $$->has_elem_segment = false; + $$->export_ = std::move(*$4); + delete $4; } | LPAR TABLE bind_var_opt inline_export_opt elem_type LPAR ELEM var_list RPAR RPAR { - Expr* expr = new_const_expr(); + Expr* expr = Expr::CreateConst(Const(Const::I32(), 0)); expr->loc = @2; - expr->const_.type = Type::I32; - expr->const_.u32 = 0; - WABT_ZERO_MEMORY($$); - $$.table.name = $3; - $$.table.elem_limits.initial = $8.size; - $$.table.elem_limits.max = $8.size; - $$.table.elem_limits.has_max = true; - $$.has_elem_segment = true; - $$.elem_segment.offset = expr; - $$.elem_segment.vars = $8; - $$.export_ = $4; + $$ = new ExportedTable(); + $$->table.reset(new Table()); + $$->table->name = $3; + $$->table->elem_limits.initial = $8->size(); + $$->table->elem_limits.max = $8->size(); + $$->table->elem_limits.has_max = true; + $$->has_elem_segment = true; + $$->elem_segment.reset(new ElemSegment()); + $$->elem_segment->offset = expr; + $$->elem_segment->vars = std::move(*$8); + delete $8; + $$->export_ = std::move(*$4); + delete $4; } ; data : LPAR DATA var offset text_list RPAR { - WABT_ZERO_MEMORY($$); - $$.memory_var = $3; - $$.offset = $4.first; - dup_text_list(&$5, &$$.data, &$$.size); + $$ = new DataSegment(); + $$->memory_var = $3; + $$->offset = $4.first; + dup_text_list(&$5, &$$->data, &$$->size); destroy_text_list(&$5); } | LPAR DATA offset text_list RPAR { - WABT_ZERO_MEMORY($$); - $$.memory_var.loc = @2; - $$.memory_var.type = VarType::Index; - $$.memory_var.index = 0; - $$.offset = $3.first; - dup_text_list(&$4, &$$.data, &$$.size); + $$ = new DataSegment(); + $$->memory_var.loc = @2; + $$->memory_var.type = VarType::Index; + $$->memory_var.index = 0; + $$->offset = $3.first; + dup_text_list(&$4, &$$->data, &$$->size); destroy_text_list(&$4); } ; memory : LPAR MEMORY bind_var_opt inline_export_opt memory_sig RPAR { - WABT_ZERO_MEMORY($$); - $$.memory = $5; - $$.memory.name = $3; - $$.has_data_segment = false; - $$.export_ = $4; + $$ = new ExportedMemory(); + $$->memory.reset($5); + $$->memory->name = $3; + $$->has_data_segment = false; + $$->export_ = std::move(*$4); + delete $4; } | LPAR MEMORY bind_var_opt inline_export LPAR DATA text_list RPAR RPAR { - Expr* expr = new_const_expr(); + Expr* expr = Expr::CreateConst(Const(Const::I32(), 0)); expr->loc = @2; - expr->const_.type = Type::I32; - expr->const_.u32 = 0; - WABT_ZERO_MEMORY($$); - $$.has_data_segment = true; - $$.data_segment.offset = expr; - dup_text_list(&$7, &$$.data_segment.data, &$$.data_segment.size); + $$ = new ExportedMemory(); + $$->has_data_segment = true; + $$->data_segment.reset(new DataSegment()); + $$->data_segment->offset = expr; + dup_text_list(&$7, &$$->data_segment->data, &$$->data_segment->size); destroy_text_list(&$7); - uint32_t byte_size = WABT_ALIGN_UP_TO_PAGE($$.data_segment.size); + 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; - $$.memory.page_limits.initial = page_size; - $$.memory.page_limits.max = page_size; - $$.memory.page_limits.has_max = true; - $$.export_ = $4; + $$->memory.reset(new Memory()); + $$->memory->name = $3; + $$->memory->page_limits.initial = page_size; + $$->memory->page_limits.max = page_size; + $$->memory->page_limits.has_max = true; + $$->export_ = std::move(*$4); + delete $4; } /* Duplicate above for empty inline_export_opt to avoid LR(1) conflict. */ | LPAR MEMORY bind_var_opt LPAR DATA text_list RPAR RPAR { - Expr* expr = new_const_expr(); + Expr* expr = Expr::CreateConst(Const(Const::I32(), 0)); expr->loc = @2; - expr->const_.type = Type::I32; - expr->const_.u32 = 0; - WABT_ZERO_MEMORY($$); - $$.has_data_segment = true; - $$.data_segment.offset = expr; - dup_text_list(&$6, &$$.data_segment.data, &$$.data_segment.size); + $$ = new ExportedMemory(); + $$->has_data_segment = true; + $$->data_segment.reset(new DataSegment()); + $$->data_segment->offset = expr; + dup_text_list(&$6, &$$->data_segment->data, &$$->data_segment->size); destroy_text_list(&$6); - uint32_t byte_size = WABT_ALIGN_UP_TO_PAGE($$.data_segment.size); + 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; - $$.memory.page_limits.initial = page_size; - $$.memory.page_limits.max = page_size; - $$.memory.page_limits.has_max = true; - $$.export_.has_export = false; + $$->memory.reset(new Memory()); + $$->memory->name = $3; + $$->memory->page_limits.initial = page_size; + $$->memory->page_limits.max = page_size; + $$->memory->page_limits.has_max = true; + $$->export_.has_export = false; } ; global : LPAR GLOBAL bind_var_opt inline_export global_type const_expr RPAR { - WABT_ZERO_MEMORY($$); - $$.global = $5; - $$.global.name = $3; - $$.global.init_expr = $6.first; - $$.export_ = $4; + $$ = new ExportedGlobal(); + $$->global.reset($5); + $$->global->name = $3; + $$->global->init_expr = $6.first; + $$->export_ = std::move(*$4); + delete $4; } | LPAR GLOBAL bind_var_opt global_type const_expr RPAR { - WABT_ZERO_MEMORY($$); - $$.global = $4; - $$.global.name = $3; - $$.global.init_expr = $5.first; - $$.export_.has_export = false; + $$ = new ExportedGlobal(); + $$->global.reset($4); + $$->global->name = $3; + $$->global->init_expr = $5.first; + $$->export_.has_export = false; } ; @@ -981,37 +963,38 @@ global : import_kind : LPAR FUNC bind_var_opt type_use RPAR { - $$ = new_import(); + $$ = new Import(); $$->kind = ExternalKind::Func; $$->func = new Func(); $$->func->name = $3; - $$->func->decl.flags = WABT_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; + $$->func->decl.has_func_type = true; $$->func->decl.type_var = $4; } | LPAR FUNC bind_var_opt func_sig RPAR { - $$ = new_import(); + $$ = new Import(); $$->kind = ExternalKind::Func; $$->func = new Func(); $$->func->name = $3; - $$->func->decl.sig = $4; + $$->func->decl.sig = std::move(*$4); + delete $4; } | LPAR TABLE bind_var_opt table_sig RPAR { - $$ = new_import(); + $$ = new Import(); $$->kind = ExternalKind::Table; $$->table = $4; - $$->table.name = $3; + $$->table->name = $3; } | LPAR MEMORY bind_var_opt memory_sig RPAR { - $$ = new_import(); + $$ = new Import(); $$->kind = ExternalKind::Memory; $$->memory = $4; - $$->memory.name = $3; + $$->memory->name = $3; } | LPAR GLOBAL bind_var_opt global_type RPAR { - $$ = new_import(); + $$ = new Import(); $$->kind = ExternalKind::Global; $$->global = $4; - $$->global.name = $3; + $$->global->name = $3; } ; import : @@ -1025,7 +1008,7 @@ import : $$->kind = ExternalKind::Func; $$->func = new Func(); $$->func->name = $3; - $$->func->decl.flags = WABT_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; + $$->func->decl.has_func_type = true; $$->func->decl.type_var = $5; } | LPAR FUNC bind_var_opt inline_import func_sig RPAR { @@ -1033,31 +1016,32 @@ import : $$->kind = ExternalKind::Func; $$->func = new Func(); $$->func->name = $3; - $$->func->decl.sig = $5; + $$->func->decl.sig = std::move(*$5); + delete $5; } | LPAR TABLE bind_var_opt inline_import table_sig RPAR { $$ = $4; $$->kind = ExternalKind::Table; $$->table = $5; - $$->table.name = $3; + $$->table->name = $3; } | LPAR MEMORY bind_var_opt inline_import memory_sig RPAR { $$ = $4; $$->kind = ExternalKind::Memory; $$->memory = $5; - $$->memory.name = $3; + $$->memory->name = $3; } | LPAR GLOBAL bind_var_opt inline_import global_type RPAR { $$ = $4; $$->kind = ExternalKind::Global; $$->global = $5; - $$->global.name = $3; + $$->global->name = $3; } ; inline_import : LPAR IMPORT quoted_text quoted_text RPAR { - $$ = new_import(); + $$ = new Import(); $$->module_name = $3; $$->field_name = $4; } @@ -1065,45 +1049,46 @@ inline_import : export_kind : LPAR FUNC var RPAR { - WABT_ZERO_MEMORY($$); - $$.kind = ExternalKind::Func; - $$.var = $3; + $$ = new Export(); + $$->kind = ExternalKind::Func; + $$->var = $3; } | LPAR TABLE var RPAR { - WABT_ZERO_MEMORY($$); - $$.kind = ExternalKind::Table; - $$.var = $3; + $$ = new Export(); + $$->kind = ExternalKind::Table; + $$->var = $3; } | LPAR MEMORY var RPAR { - WABT_ZERO_MEMORY($$); - $$.kind = ExternalKind::Memory; - $$.var = $3; + $$ = new Export(); + $$->kind = ExternalKind::Memory; + $$->var = $3; } | LPAR GLOBAL var RPAR { - WABT_ZERO_MEMORY($$); - $$.kind = ExternalKind::Global; - $$.var = $3; + $$ = new Export(); + $$->kind = ExternalKind::Global; + $$->var = $3; } ; export : LPAR EXPORT quoted_text export_kind RPAR { $$ = $4; - $$.name = $3; + $$->name = $3; } ; inline_export_opt : /* empty */ { - WABT_ZERO_MEMORY($$); - $$.has_export = false; + $$ = new OptionalExport(); + $$->has_export = false; } | inline_export ; inline_export : LPAR EXPORT quoted_text RPAR { - WABT_ZERO_MEMORY($$); - $$.has_export = true; - $$.export_.name = $3; + $$ = new OptionalExport(); + $$->has_export = true; + $$->export_.reset(new Export()); + $$->export_->name = $3; } ; @@ -1112,12 +1097,15 @@ inline_export : type_def : LPAR TYPE func_type RPAR { - WABT_ZERO_MEMORY($$); - $$.sig = $3; + $$ = new FuncType(); + $$->sig = std::move(*$3); + delete $3; } | LPAR TYPE bind_var func_type RPAR { - $$.name = $3; - $$.sig = $4; + $$ = new FuncType(); + $$->name = $3; + $$->sig = std::move(*$4); + delete $4; } ; @@ -1127,79 +1115,79 @@ start : module_fields : /* empty */ { - $$ = new_module(); + $$ = new Module(); } | module_fields type_def { $$ = $1; ModuleField* field; APPEND_FIELD_TO_LIST($$, field, FuncType, func_type, @2, $2); - APPEND_ITEM_TO_VECTOR($$, FuncType, func_type, func_types, - &field->func_type); - INSERT_BINDING($$, func_type, func_types, @2, $2.name); + APPEND_ITEM_TO_VECTOR($$, func_types, field->func_type); + INSERT_BINDING($$, func_type, func_types, @2, $2->name); } | module_fields global { $$ = $1; ModuleField* field; - APPEND_FIELD_TO_LIST($$, field, Global, global, @2, $2.global); - APPEND_ITEM_TO_VECTOR($$, Global, global, globals, &field->global); - INSERT_BINDING($$, global, globals, @2, $2.global.name); - APPEND_INLINE_EXPORT($$, Global, @2, $2, $$->globals.size - 1); + APPEND_FIELD_TO_LIST($$, field, Global, global, @2, $2->global.release()); + APPEND_ITEM_TO_VECTOR($$, globals, field->global); + INSERT_BINDING($$, global, globals, @2, field->global->name); + APPEND_INLINE_EXPORT($$, Global, @2, $2, $$->globals.size() - 1); + delete $2; } | module_fields table { $$ = $1; ModuleField* field; - APPEND_FIELD_TO_LIST($$, field, Table, table, @2, $2.table); - APPEND_ITEM_TO_VECTOR($$, Table, table, tables, &field->table); - INSERT_BINDING($$, table, tables, @2, $2.table.name); - APPEND_INLINE_EXPORT($$, Table, @2, $2, $$->tables.size - 1); + APPEND_FIELD_TO_LIST($$, field, Table, table, @2, $2->table.release()); + APPEND_ITEM_TO_VECTOR($$, tables, field->table); + INSERT_BINDING($$, table, tables, @2, field->table->name); + APPEND_INLINE_EXPORT($$, Table, @2, $2, $$->tables.size() - 1); - if ($2.has_elem_segment) { + if ($2->has_elem_segment) { ModuleField* elem_segment_field; APPEND_FIELD_TO_LIST($$, elem_segment_field, ElemSegment, elem_segment, - @2, $2.elem_segment); - APPEND_ITEM_TO_VECTOR($$, ElemSegment, elem_segment, elem_segments, - &elem_segment_field->elem_segment); + @2, $2->elem_segment.release()); + APPEND_ITEM_TO_VECTOR($$, elem_segments, + elem_segment_field->elem_segment); } - + delete $2; } | module_fields memory { $$ = $1; ModuleField* field; - APPEND_FIELD_TO_LIST($$, field, Memory, memory, @2, $2.memory); - APPEND_ITEM_TO_VECTOR($$, Memory, memory, memories, &field->memory); - INSERT_BINDING($$, memory, memories, @2, $2.memory.name); - APPEND_INLINE_EXPORT($$, Memory, @2, $2, $$->memories.size - 1); + APPEND_FIELD_TO_LIST($$, field, Memory, memory, @2, $2->memory.release()); + APPEND_ITEM_TO_VECTOR($$, memories, field->memory); + INSERT_BINDING($$, memory, memories, @2, field->memory->name); + APPEND_INLINE_EXPORT($$, Memory, @2, $2, $$->memories.size() - 1); - if ($2.has_data_segment) { + if ($2->has_data_segment) { ModuleField* data_segment_field; APPEND_FIELD_TO_LIST($$, data_segment_field, DataSegment, data_segment, - @2, $2.data_segment); - APPEND_ITEM_TO_VECTOR($$, DataSegment, data_segment, data_segments, - &data_segment_field->data_segment); + @2, $2->data_segment.release()); + APPEND_ITEM_TO_VECTOR($$, data_segments, + data_segment_field->data_segment); } + delete $2; } | module_fields func { $$ = $1; ModuleField* field; - APPEND_FIELD_TO_LIST($$, field, Func, func, @2, $2.func); + APPEND_FIELD_TO_LIST($$, field, Func, func, @2, $2->func.release()); 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); + APPEND_ITEM_TO_VECTOR($$, funcs, field->func); + INSERT_BINDING($$, func, funcs, @2, field->func->name); + APPEND_INLINE_EXPORT($$, Func, @2, $2, $$->funcs.size() - 1); + delete $2; } | module_fields elem { $$ = $1; ModuleField* field; APPEND_FIELD_TO_LIST($$, field, ElemSegment, elem_segment, @2, $2); - APPEND_ITEM_TO_VECTOR($$, ElemSegment, elem_segment, elem_segments, - &field->elem_segment); + APPEND_ITEM_TO_VECTOR($$, elem_segments, field->elem_segment); } | module_fields data { $$ = $1; ModuleField* field; APPEND_FIELD_TO_LIST($$, field, DataSegment, data_segment, @2, $2); - APPEND_ITEM_TO_VECTOR($$, DataSegment, data_segment, data_segments, - &field->data_segment); + APPEND_ITEM_TO_VECTOR($$, data_segments, field->data_segment); } | module_fields start { $$ = $1; @@ -1218,92 +1206,91 @@ module_fields : switch ($2->kind) { case ExternalKind::Func: append_implicit_func_declaration(&@2, $$, &field->import->func->decl); - APPEND_ITEM_TO_VECTOR($$, Func, func, funcs, field->import->func); + APPEND_ITEM_TO_VECTOR($$, funcs, field->import->func); INSERT_BINDING($$, func, funcs, @2, field->import->func->name); $$->num_func_imports++; break; case ExternalKind::Table: - APPEND_ITEM_TO_VECTOR($$, Table, table, tables, - &field->import->table); - INSERT_BINDING($$, table, tables, @2, field->import->table.name); + APPEND_ITEM_TO_VECTOR($$, tables, field->import->table); + INSERT_BINDING($$, table, tables, @2, field->import->table->name); $$->num_table_imports++; break; case ExternalKind::Memory: - APPEND_ITEM_TO_VECTOR($$, Memory, memory, memories, - &field->import->memory); - INSERT_BINDING($$, memory, memories, @2, field->import->memory.name); + APPEND_ITEM_TO_VECTOR($$, memories, field->import->memory); + INSERT_BINDING($$, memory, memories, @2, field->import->memory->name); $$->num_memory_imports++; break; case ExternalKind::Global: - APPEND_ITEM_TO_VECTOR($$, Global, global, globals, - &field->import->global); - INSERT_BINDING($$, global, globals, @2, field->import->global.name); + APPEND_ITEM_TO_VECTOR($$, globals, field->import->global); + INSERT_BINDING($$, global, globals, @2, field->import->global->name); $$->num_global_imports++; break; } - APPEND_ITEM_TO_VECTOR($$, Import, import, imports, field->import); + APPEND_ITEM_TO_VECTOR($$, imports, field->import); } | module_fields export { $$ = $1; ModuleField* 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); + APPEND_ITEM_TO_VECTOR($$, exports, field->export_); + INSERT_BINDING($$, export, exports, @2, field->export_->name); } ; raw_module : LPAR MODULE bind_var_opt module_fields RPAR { - $$.type = RawModuleType::Text; - $$.text = $4; - $$.text->name = $3; - $$.text->loc = @2; + $$ = new RawModule(); + $$->type = RawModuleType::Text; + $$->text = $4; + $$->text->name = $3; + $$->text->loc = @2; /* resolve func type variables where the signature was not specified * explicitly */ - for (size_t i = 0; i < $4->funcs.size; ++i) { - Func* func = $4->funcs.data[i]; + for (Func* func: $4->funcs) { if (decl_has_func_type(&func->decl) && is_empty_signature(&func->decl.sig)) { FuncType* func_type = get_func_type_by_var($4, &func->decl.type_var); if (func_type) { func->decl.sig = func_type->sig; - func->decl.flags |= WABT_FUNC_DECLARATION_FLAG_SHARED_SIGNATURE; } } } } | LPAR MODULE bind_var_opt non_empty_text_list RPAR { - $$.type = RawModuleType::Binary; - $$.binary.name = $3; - $$.binary.loc = @2; - dup_text_list(&$4, &$$.binary.data, &$$.binary.size); + $$ = new RawModule(); + $$->type = RawModuleType::Binary; + $$->binary.name = $3; + $$->binary.loc = @2; + dup_text_list(&$4, &$$->binary.data, &$$->binary.size); destroy_text_list(&$4); } ; module : raw_module { - if ($1.type == RawModuleType::Text) { - $$ = $1.text; + if ($1->type == RawModuleType::Text) { + $$ = $1->text; + $1->text = nullptr; } else { - assert($1.type == RawModuleType::Binary); - $$ = new_module(); + assert($1->type == RawModuleType::Binary); + $$ = new Module(); ReadBinaryOptions options = WABT_READ_BINARY_OPTIONS_DEFAULT; BinaryErrorCallbackData user_data; - user_data.loc = &$1.binary.loc; + user_data.loc = &$1->binary.loc; user_data.lexer = lexer; user_data.parser = parser; BinaryErrorHandler error_handler; error_handler.on_error = on_read_binary_error; error_handler.user_data = &user_data; - read_binary_ast($1.binary.data, $1.binary.size, &options, - &error_handler, $$); - delete [] $1.binary.data; - $$->name = $1.binary.name; - $$->loc = $1.binary.loc; + read_binary_ast($1->binary.data, $1->binary.size, &options, + &error_handler, $$); + $$->name = $1->binary.name; + $$->loc = $1->binary.loc; + WABT_ZERO_MEMORY($1->binary.name); } + delete $1; } ; @@ -1324,66 +1311,68 @@ script_var_opt : action : LPAR INVOKE script_var_opt quoted_text const_list RPAR { - WABT_ZERO_MEMORY($$); - $$.loc = @2; - $$.module_var = $3; - $$.type = ActionType::Invoke; - $$.invoke.name = $4; - $$.invoke.args = $5; + $$ = new Action(); + $$->loc = @2; + $$->module_var = $3; + $$->type = ActionType::Invoke; + $$->name = $4; + $$->invoke = new ActionInvoke(); + $$->invoke->args = std::move(*$5); + delete $5; } | LPAR GET script_var_opt quoted_text RPAR { - WABT_ZERO_MEMORY($$); - $$.loc = @2; - $$.module_var = $3; - $$.type = ActionType::Get; - $$.invoke.name = $4; + $$ = new Action(); + $$->loc = @2; + $$->module_var = $3; + $$->type = ActionType::Get; + $$->name = $4; } ; assertion : LPAR ASSERT_MALFORMED raw_module quoted_text RPAR { - $$ = new_command(); + $$ = new Command(); $$->type = CommandType::AssertMalformed; $$->assert_malformed.module = $3; $$->assert_malformed.text = $4; } | LPAR ASSERT_INVALID raw_module quoted_text RPAR { - $$ = new_command(); + $$ = new Command(); $$->type = CommandType::AssertInvalid; $$->assert_invalid.module = $3; $$->assert_invalid.text = $4; } | LPAR ASSERT_UNLINKABLE raw_module quoted_text RPAR { - $$ = new_command(); + $$ = new Command(); $$->type = CommandType::AssertUnlinkable; $$->assert_unlinkable.module = $3; $$->assert_unlinkable.text = $4; } | LPAR ASSERT_TRAP raw_module quoted_text RPAR { - $$ = new_command(); + $$ = new Command(); $$->type = CommandType::AssertUninstantiable; $$->assert_uninstantiable.module = $3; $$->assert_uninstantiable.text = $4; } | LPAR ASSERT_RETURN action const_list RPAR { - $$ = new_command(); + $$ = new Command(); $$->type = CommandType::AssertReturn; $$->assert_return.action = $3; $$->assert_return.expected = $4; } | LPAR ASSERT_RETURN_NAN action RPAR { - $$ = new_command(); + $$ = new Command(); $$->type = CommandType::AssertReturnNan; $$->assert_return_nan.action = $3; } | LPAR ASSERT_TRAP action quoted_text RPAR { - $$ = new_command(); + $$ = new Command(); $$->type = CommandType::AssertTrap; $$->assert_trap.action = $3; $$->assert_trap.text = $4; } | LPAR ASSERT_EXHAUSTION action quoted_text RPAR { - $$ = new_command(); + $$ = new Command(); $$->type = CommandType::AssertExhaustion; $$->assert_trap.action = $3; $$->assert_trap.text = $4; @@ -1392,18 +1381,18 @@ assertion : cmd : action { - $$ = new_command(); + $$ = new Command(); $$->type = CommandType::Action; $$->action = $1; } | assertion | module { - $$ = new_command(); + $$ = new Command(); $$->type = CommandType::Module; $$->module = $1; } | LPAR REGISTER quoted_text script_var_opt RPAR { - $$ = new_command(); + $$ = new Command(); $$->type = CommandType::Register; $$->register_.module_name = $3; $$->register_.var = $4; @@ -1411,11 +1400,10 @@ cmd : } ; cmd_list : - /* empty */ { WABT_ZERO_MEMORY($$); } + /* empty */ { $$ = new CommandPtrVector(); } | cmd_list cmd { $$ = $1; - append_command_value(&$$, $2); - delete $2; + $$->emplace_back($2); } ; @@ -1432,28 +1420,29 @@ const : } ; const_list : - /* empty */ { WABT_ZERO_MEMORY($$); } + /* empty */ { $$ = new ConstVector(); } | const_list const { $$ = $1; - append_const_value(&$$, &$2); + $$->push_back($2); } ; script : cmd_list { $$ = new Script(); - $$->commands = $1; + $$->commands = std::move(*$1); + delete $1; int last_module_index = -1; - for (size_t i = 0; i < $$->commands.size; ++i) { - Command* command = &$$->commands.data[i]; + for (size_t i = 0; i < $$->commands.size(); ++i) { + Command& command = *$$->commands[i].get(); Var* module_var = nullptr; - switch (command->type) { + switch (command.type) { case CommandType::Module: { last_module_index = i; /* Wire up module name bindings. */ - Module* module = command->module; + Module* module = command.module; if (module->name.length == 0) continue; @@ -1463,20 +1452,20 @@ script : } case CommandType::AssertReturn: - module_var = &command->assert_return.action.module_var; + module_var = &command.assert_return.action->module_var; goto has_module_var; case CommandType::AssertReturnNan: - module_var = &command->assert_return_nan.action.module_var; + module_var = &command.assert_return_nan.action->module_var; goto has_module_var; case CommandType::AssertTrap: case CommandType::AssertExhaustion: - module_var = &command->assert_trap.action.module_var; + module_var = &command.assert_trap.action->module_var; goto has_module_var; case CommandType::Action: - module_var = &command->action.module_var; + module_var = &command.action->module_var; goto has_module_var; case CommandType::Register: - module_var = &command->register_.var; + module_var = &command.register_.var; goto has_module_var; has_module_var: { @@ -1635,8 +1624,8 @@ void dup_text_list(TextList* text_list, char** out_data, size_t* out_size) { *out_size = dest - result; } -bool is_empty_signature(FuncSignature* sig) { - return sig->result_types.size == 0 && sig->param_types.size == 0; +bool is_empty_signature(const FuncSignature* sig) { + return sig->result_types.empty() && sig->param_types.empty(); } void append_implicit_func_declaration(Location* loc, @@ -1649,13 +1638,8 @@ void append_implicit_func_declaration(Location* loc, if (sig_index == -1) { append_implicit_func_type(loc, module, &decl->sig); } else { - /* signature already exists, share that one and destroy this one */ - destroy_func_signature(&decl->sig); - FuncSignature* sig = &module->func_types.data[sig_index]->sig; - decl->sig = *sig; + decl->sig = module->func_types[sig_index]->sig; } - - decl->flags |= WABT_FUNC_DECLARATION_FLAG_SHARED_SIGNATURE; } Result parse_ast(AstLexer* lexer, Script** out_script, diff --git a/src/ast-writer.cc b/src/ast-writer.cc index 1410c062..a688d004 100644 --- a/src/ast-writer.cc +++ b/src/ast-writer.cc @@ -21,6 +21,9 @@ #include <stdarg.h> #include <stdio.h> +#include <string> +#include <vector> + #include "ast.h" #include "common.h" #include "literal.h" @@ -268,21 +271,21 @@ static void write_type(Context* ctx, Type type, NextChar next_char) { } static void write_types(Context* ctx, - const TypeVector* types, + const TypeVector& types, const char* name) { - if (types->size) { + if (types.size()) { if (name) write_open_space(ctx, name); - for (size_t i = 0; i < types->size; ++i) - write_type(ctx, types->data[i], NextChar::Space); + for (Type type: types) + write_type(ctx, type, NextChar::Space); if (name) write_close_space(ctx); } } static void write_func_sig_space(Context* ctx, const FuncSignature* func_sig) { - write_types(ctx, &func_sig->param_types, "param"); - write_types(ctx, &func_sig->result_types, "result"); + write_types(ctx, func_sig->param_types, "param"); + write_types(ctx, func_sig->result_types, "result"); } static void write_expr_list(Context* ctx, const Expr* first); @@ -294,7 +297,7 @@ static void write_begin_block(Context* ctx, const char* text) { write_puts_space(ctx, text); bool has_label = write_string_slice_opt(ctx, &block->label, NextChar::Space); - write_types(ctx, &block->sig, nullptr); + write_types(ctx, block->sig, nullptr); if (!has_label) writef(ctx, " ;; label = @%d", ctx->depth); write_newline(ctx, FORCE_NEWLINE); @@ -367,7 +370,7 @@ static void write_expr(Context* ctx, const Expr* expr) { break; case ExprType::Block: - write_block(ctx, &expr->block, get_opcode_name(Opcode::Block)); + write_block(ctx, expr->block, get_opcode_name(Opcode::Block)); break; case ExprType::Br: @@ -382,8 +385,8 @@ static void write_expr(Context* ctx, const Expr* expr) { case ExprType::BrTable: { write_puts_space(ctx, get_opcode_name(Opcode::BrTable)); - for (size_t i = 0; i < expr->br_table.targets.size; ++i) - write_br_var(ctx, &expr->br_table.targets.data[i], NextChar::Space); + for (const Var& var : *expr->br_table.targets) + write_br_var(ctx, &var, NextChar::Space); write_br_var(ctx, &expr->br_table.default_target, NextChar::Newline); break; } @@ -429,8 +432,8 @@ static void write_expr(Context* ctx, const Expr* expr) { break; case ExprType::If: - write_begin_block(ctx, &expr->if_.true_, get_opcode_name(Opcode::If)); - write_expr_list(ctx, expr->if_.true_.first); + write_begin_block(ctx, expr->if_.true_, get_opcode_name(Opcode::If)); + write_expr_list(ctx, expr->if_.true_->first); if (expr->if_.false_) { dedent(ctx); write_puts_space(ctx, get_opcode_name(Opcode::Else)); @@ -451,7 +454,7 @@ static void write_expr(Context* ctx, const Expr* expr) { break; case ExprType::Loop: - write_block(ctx, &expr->loop, get_opcode_name(Opcode::Loop)); + write_block(ctx, expr->loop, get_opcode_name(Opcode::Loop)); break; case ExprType::CurrentMemory: @@ -527,9 +530,9 @@ static void write_init_expr(Context* ctx, const Expr* expr) { static void write_type_bindings(Context* ctx, const char* prefix, const Func* func, - const TypeVector* types, - const BindingHash* bindings) { - make_type_binding_reverse_mapping(*types, *bindings, &ctx->index_to_name); + const TypeVector& types, + const BindingHash& bindings) { + 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.: @@ -537,7 +540,7 @@ static void write_type_bindings(Context* ctx, * (param i32 i64 f32) */ bool is_open = false; - for (size_t i = 0; i < types->size; ++i) { + for (size_t i = 0; i < types.size(); ++i) { if (!is_open) { write_open_space(ctx, prefix); is_open = true; @@ -546,7 +549,7 @@ static void write_type_bindings(Context* ctx, const std::string& name = ctx->index_to_name[i]; if (!name.empty()) write_string(ctx, name, NextChar::Space); - write_type(ctx, types->data[i], NextChar::Space); + write_type(ctx, types[i], NextChar::Space); if (!name.empty()) { write_close_space(ctx); is_open = false; @@ -565,13 +568,13 @@ static void write_func(Context* ctx, const Module* module, const Func* func) { write_var(ctx, &func->decl.type_var, NextChar::None); write_close_space(ctx); } - write_type_bindings(ctx, "param", func, &func->decl.sig.param_types, - &func->param_bindings); - write_types(ctx, &func->decl.sig.result_types, "result"); + write_type_bindings(ctx, "param", func, func->decl.sig.param_types, + func->param_bindings); + write_types(ctx, func->decl.sig.result_types, "result"); write_newline(ctx, NO_FORCE_NEWLINE); - if (func->local_types.size) { - write_type_bindings(ctx, "local", func, &func->local_types, - &func->local_bindings); + if (func->local_types.size()) { + write_type_bindings(ctx, "local", func, func->local_types, + func->local_bindings); } write_newline(ctx, NO_FORCE_NEWLINE); ctx->depth = 1; /* for the implicit "return" label */ @@ -616,8 +619,8 @@ static void write_table(Context* ctx, const Table* table) { static void write_elem_segment(Context* ctx, const ElemSegment* segment) { write_open_space(ctx, "elem"); write_init_expr(ctx, segment->offset); - for (size_t i = 0; i < segment->vars.size; ++i) - write_var(ctx, &segment->vars.data[i], NextChar::Space); + for (const Var& var : segment->vars) + write_var(ctx, &var, NextChar::Space); write_close_newline(ctx); } @@ -656,15 +659,15 @@ static void write_import(Context* ctx, const Import* import) { break; case ExternalKind::Table: - write_table(ctx, &import->table); + write_table(ctx, import->table); break; case ExternalKind::Memory: - write_memory(ctx, &import->memory); + write_memory(ctx, import->memory); break; case ExternalKind::Global: - write_begin_global(ctx, &import->global); + write_begin_global(ctx, import->global); write_close_space(ctx); break; } @@ -708,28 +711,28 @@ static void write_module(Context* ctx, const Module* module) { write_func(ctx, module, field->func); break; case ModuleFieldType::Global: - write_global(ctx, &field->global); + write_global(ctx, field->global); break; case ModuleFieldType::Import: write_import(ctx, field->import); break; case ModuleFieldType::Export: - write_export(ctx, &field->export_); + write_export(ctx, field->export_); break; case ModuleFieldType::Table: - write_table(ctx, &field->table); + write_table(ctx, field->table); break; case ModuleFieldType::ElemSegment: - write_elem_segment(ctx, &field->elem_segment); + write_elem_segment(ctx, field->elem_segment); break; case ModuleFieldType::Memory: - write_memory(ctx, &field->memory); + write_memory(ctx, field->memory); break; case ModuleFieldType::DataSegment: - write_data_segment(ctx, &field->data_segment); + write_data_segment(ctx, field->data_segment); break; case ModuleFieldType::FuncType: - write_func_type(ctx, &field->func_type); + write_func_type(ctx, field->func_type); break; case ModuleFieldType::Start: write_start_function(ctx, &field->start); @@ -27,11 +27,11 @@ int get_index_from_var(const BindingHash* hash, const Var* var) { return static_cast<int>(var->index); } -ExportPtr get_export_by_name(const Module* module, const StringSlice* name) { +Export* get_export_by_name(const Module* module, const StringSlice* name) { int index = module->export_bindings.find_index(*name); if (index == -1) return nullptr; - return module->exports.data[index]; + return module->exports[index]; } int get_func_index_by_var(const Module* module, const Var* var) { @@ -67,51 +67,51 @@ int get_local_index_by_var(const Func* func, const Var* var) { return result; /* the locals start after all the params */ - return func->decl.sig.param_types.size + result; + return func->decl.sig.param_types.size() + result; } int get_module_index_by_var(const Script* script, const Var* var) { return get_index_from_var(&script->module_bindings, var); } -FuncPtr get_func_by_var(const Module* module, const Var* var) { +Func* get_func_by_var(const Module* module, const Var* var) { int index = get_index_from_var(&module->func_bindings, var); - if (index < 0 || static_cast<size_t>(index) >= module->funcs.size) + if (index < 0 || static_cast<size_t>(index) >= module->funcs.size()) return nullptr; - return module->funcs.data[index]; + return module->funcs[index]; } -GlobalPtr get_global_by_var(const Module* module, const Var* var) { +Global* get_global_by_var(const Module* module, const Var* var) { int index = get_index_from_var(&module->global_bindings, var); - if (index < 0 || static_cast<size_t>(index) >= module->globals.size) + if (index < 0 || static_cast<size_t>(index) >= module->globals.size()) return nullptr; - return module->globals.data[index]; + return module->globals[index]; } -TablePtr get_table_by_var(const Module* module, const Var* var) { +Table* get_table_by_var(const Module* module, const Var* var) { int index = get_index_from_var(&module->table_bindings, var); - if (index < 0 || static_cast<size_t>(index) >= module->tables.size) + if (index < 0 || static_cast<size_t>(index) >= module->tables.size()) return nullptr; - return module->tables.data[index]; + return module->tables[index]; } -MemoryPtr get_memory_by_var(const Module* module, const Var* var) { +Memory* get_memory_by_var(const Module* module, const Var* var) { int index = get_index_from_var(&module->memory_bindings, var); - if (index < 0 || static_cast<size_t>(index) >= module->memories.size) + if (index < 0 || static_cast<size_t>(index) >= module->memories.size()) return nullptr; - return module->memories.data[index]; + return module->memories[index]; } -FuncTypePtr get_func_type_by_var(const Module* module, const Var* var) { +FuncType* get_func_type_by_var(const Module* module, const Var* var) { int index = get_index_from_var(&module->func_type_bindings, var); - if (index < 0 || static_cast<size_t>(index) >= module->func_types.size) + if (index < 0 || static_cast<size_t>(index) >= module->func_types.size()) return nullptr; - return module->func_types.data[index]; + return module->func_types[index]; } int get_func_type_index_by_sig(const Module* module, const FuncSignature* sig) { - for (size_t i = 0; i < module->func_types.size; ++i) - if (signatures_are_equal(&module->func_types.data[i]->sig, sig)) + for (size_t i = 0; i < module->func_types.size(); ++i) + if (signatures_are_equal(&module->func_types[i]->sig, sig)) return i; return -1; } @@ -126,8 +126,7 @@ int get_func_type_index_by_decl(const Module* module, } Module* get_first_module(const Script* script) { - for (size_t i = 0; i < script->commands.size; ++i) { - Command* command = &script->commands.data[i]; + for (const std::unique_ptr<Command>& command : script->commands) { if (command->type == CommandType::Module) return command->module; } @@ -136,11 +135,11 @@ Module* get_first_module(const Script* script) { Module* get_module_by_var(const Script* script, const Var* var) { int index = get_index_from_var(&script->module_bindings, var); - if (index < 0 || static_cast<size_t>(index) >= script->commands.size) + if (index < 0 || static_cast<size_t>(index) >= script->commands.size()) return nullptr; - Command* command = &script->commands.data[index]; - assert(command->type == CommandType::Module); - return command->module; + const Command& command = *script->commands[index].get(); + assert(command.type == CommandType::Module); + return command.module; } void make_type_binding_reverse_mapping( @@ -148,11 +147,11 @@ void make_type_binding_reverse_mapping( const BindingHash& bindings, std::vector<std::string>* out_reverse_mapping) { out_reverse_mapping->clear(); - out_reverse_mapping->resize(types.size); - for (auto iter: bindings) { - assert(static_cast<size_t>(iter.second.index) < + out_reverse_mapping->resize(types.size()); + for (const auto& pair : bindings) { + assert(static_cast<size_t>(pair.second.index) < out_reverse_mapping->size()); - (*out_reverse_mapping)[iter.second.index] = iter.first; + (*out_reverse_mapping)[pair.second.index] = pair.first; } } @@ -172,122 +171,117 @@ FuncType* append_implicit_func_type(Location* loc, ModuleField* field = append_module_field(module); field->loc = *loc; field->type = ModuleFieldType::FuncType; - field->func_type.sig = *sig; - - FuncType* func_type_ptr = &field->func_type; - append_func_type_ptr_value(&module->func_types, &func_type_ptr); - return func_type_ptr; -} - -#define FOREACH_EXPR_TYPE(V) \ - V(ExprType::Binary, binary) \ - V(ExprType::Block, block) \ - V(ExprType::Br, br) \ - V(ExprType::BrIf, br_if) \ - V(ExprType::BrTable, br_table) \ - V(ExprType::Call, call) \ - V(ExprType::CallIndirect, call_indirect) \ - V(ExprType::Compare, compare) \ - V(ExprType::Const, const) \ - V(ExprType::Convert, convert) \ - V(ExprType::GetGlobal, get_global) \ - V(ExprType::GetLocal, get_local) \ - V(ExprType::If, if) \ - V(ExprType::Load, load) \ - V(ExprType::Loop, loop) \ - V(ExprType::SetGlobal, set_global) \ - V(ExprType::SetLocal, set_local) \ - V(ExprType::Store, store) \ - V(ExprType::TeeLocal, tee_local) \ - V(ExprType::Unary, unary) \ - V(ExprType::CurrentMemory, current_memory) \ - V(ExprType::Drop, drop) \ - V(ExprType::GrowMemory, grow_memory) \ - V(ExprType::Nop, nop) \ - V(ExprType::Return, return ) \ - V(ExprType::Select, select) \ - V(ExprType::Unreachable, unreachable) - -#define DEFINE_NEW_EXPR(type_, name) \ - Expr* new_##name##_expr(void) { \ - Expr* result = new Expr(); \ - result->type = type_; \ - return result; \ - } -FOREACH_EXPR_TYPE(DEFINE_NEW_EXPR) -#undef DEFINE_NEW_EXPR + field->func_type = new FuncType(); + field->func_type->sig = *sig; + + module->func_types.push_back(field->func_type); + return field->func_type; +} void destroy_var(Var* var) { if (var->type == VarType::Name) destroy_string_slice(&var->name); } -void destroy_var_vector_and_elements(VarVector* vars) { - WABT_DESTROY_VECTOR_AND_ELEMENTS(*vars, var); -} - -void destroy_func_signature(FuncSignature* sig) { - destroy_type_vector(&sig->param_types); - destroy_type_vector(&sig->result_types); -} - void destroy_expr_list(Expr* first) { Expr* expr = first; while (expr) { Expr* next = expr->next; - destroy_expr(expr); + delete expr; expr = next; } } -void destroy_block(Block* block) { - destroy_string_slice(&block->label); - destroy_type_vector(&block->sig); - destroy_expr_list(block->first); +Var::Var(int64_t index) : type(VarType::Index), index(index) { + WABT_ZERO_MEMORY(loc); } -void destroy_expr(Expr* expr) { - switch (expr->type) { +Var::Var(const StringSlice& name) : type(VarType::Name), name(name) { + WABT_ZERO_MEMORY(loc); +} + +Const::Const(I32, uint32_t value) : type(Type::I32), u32(value) { + WABT_ZERO_MEMORY(loc); +} + +Const::Const(I64, uint64_t value) : type(Type::I64), u64(value) { + WABT_ZERO_MEMORY(loc); +} + +Const::Const(F32, uint32_t value) : type(Type::F32), f32_bits(value) { + WABT_ZERO_MEMORY(loc); +} + +Const::Const(F64, uint64_t value) : type(Type::F64), f64_bits(value) { + WABT_ZERO_MEMORY(loc); +} + +Block::Block(): first(nullptr) { + WABT_ZERO_MEMORY(label); +} + +Block::Block(Expr* first) : first(first) { + WABT_ZERO_MEMORY(label); +} + +Block::~Block() { + destroy_string_slice(&label); + destroy_expr_list(first); +} + +Expr::Expr() : type(ExprType::Binary), next(nullptr) { + WABT_ZERO_MEMORY(loc); + binary.opcode = Opcode::Nop; +} + +Expr::Expr(ExprType type) : type(type), next(nullptr) { + WABT_ZERO_MEMORY(loc); +} + +Expr::~Expr() { + switch (type) { case ExprType::Block: - destroy_block(&expr->block); + delete block; break; case ExprType::Br: - destroy_var(&expr->br.var); + destroy_var(&br.var); break; case ExprType::BrIf: - destroy_var(&expr->br_if.var); + destroy_var(&br_if.var); break; case ExprType::BrTable: - WABT_DESTROY_VECTOR_AND_ELEMENTS(expr->br_table.targets, var); - destroy_var(&expr->br_table.default_target); + for (Var& var : *br_table.targets) + destroy_var(&var); + delete br_table.targets; + destroy_var(&br_table.default_target); break; case ExprType::Call: - destroy_var(&expr->call.var); + destroy_var(&call.var); break; case ExprType::CallIndirect: - destroy_var(&expr->call_indirect.var); + destroy_var(&call_indirect.var); break; case ExprType::GetGlobal: - destroy_var(&expr->get_global.var); + destroy_var(&get_global.var); break; case ExprType::GetLocal: - destroy_var(&expr->get_local.var); + destroy_var(&get_local.var); break; case ExprType::If: - destroy_block(&expr->if_.true_); - destroy_expr_list(expr->if_.false_); + delete if_.true_; + destroy_expr_list(if_.false_); break; case ExprType::Loop: - destroy_block(&expr->loop); + delete loop; break; case ExprType::SetGlobal: - destroy_var(&expr->set_global.var); + destroy_var(&set_global.var); break; case ExprType::SetLocal: - destroy_var(&expr->set_local.var); + destroy_var(&set_local.var); break; case ExprType::TeeLocal: - destroy_var(&expr->tee_local.var); + destroy_var(&tee_local.var); break; case ExprType::Binary: @@ -306,66 +300,294 @@ void destroy_expr(Expr* expr) { case ExprType::Unreachable: break; } - delete expr; } -void destroy_func_declaration(FuncDeclaration* decl) { - destroy_var(&decl->type_var); - if (!(decl->flags & WABT_FUNC_DECLARATION_FLAG_SHARED_SIGNATURE)) - destroy_func_signature(&decl->sig); +// static +Expr* Expr::CreateBinary(Opcode opcode) { + Expr* expr = new Expr(ExprType::Binary); + expr->binary.opcode = opcode; + return expr; +} + +// static +Expr* Expr::CreateBlock(Block* block) { + Expr* expr = new Expr(ExprType::Block); + expr->block = block; + return expr; +} + +// static +Expr* Expr::CreateBr(Var var) { + Expr* expr = new Expr(ExprType::Br); + expr->br.var = var; + return expr; +} + +// static +Expr* Expr::CreateBrIf(Var var) { + Expr* expr = new Expr(ExprType::BrIf); + expr->br_if.var = var; + return expr; +} + +// static +Expr* Expr::CreateBrTable(VarVector* targets, Var default_target) { + Expr* expr = new Expr(ExprType::BrTable); + expr->br_table.targets = targets; + expr->br_table.default_target = default_target; + return expr; +} + +// static +Expr* Expr::CreateCall(Var var) { + Expr* expr = new Expr(ExprType::Call); + expr->call.var = var; + return expr; +} + +// static +Expr* Expr::CreateCallIndirect(Var var) { + Expr* expr = new Expr(ExprType::CallIndirect); + expr->call_indirect.var = var; + return expr; +} + +// static +Expr* Expr::CreateCompare(Opcode opcode) { + Expr* expr = new Expr(ExprType::Compare); + expr->compare.opcode = opcode; + return expr; +} + +// static +Expr* Expr::CreateConst(const Const& const_) { + Expr* expr = new Expr(ExprType::Const); + expr->const_ = const_; + return expr; +} + +// static +Expr* Expr::CreateConvert(Opcode opcode) { + Expr* expr = new Expr(ExprType::Convert); + expr->convert.opcode = opcode; + return expr; +} + +// static +Expr* Expr::CreateCurrentMemory() { + return new Expr(ExprType::CurrentMemory); +} + +// static +Expr* Expr::CreateDrop() { + return new Expr(ExprType::Drop); +} + +// static +Expr* Expr::CreateGetGlobal(Var var) { + Expr* expr = new Expr(ExprType::GetGlobal); + expr->get_global.var = var; + return expr; +} + +// static +Expr* Expr::CreateGetLocal(Var var) { + Expr* expr = new Expr(ExprType::GetLocal); + expr->get_local.var = var; + return expr; +} + +// static +Expr* Expr::CreateGrowMemory() { + return new Expr(ExprType::GrowMemory); +} + +// static +Expr* Expr::CreateIf(Block* true_, Expr* false_) { + Expr* expr = new Expr(ExprType::If); + expr->if_.true_ = true_; + expr->if_.false_ = false_; + return expr; +} + +// static +Expr* Expr::CreateLoad(Opcode opcode, uint32_t align, uint64_t offset) { + Expr* expr = new Expr(ExprType::Load); + expr->load.opcode = opcode; + expr->load.align = align; + expr->load.offset = offset; + return expr; +} + +// static +Expr* Expr::CreateLoop(Block* block) { + Expr* expr = new Expr(ExprType::Loop); + expr->loop = block; + return expr; +} + +// static +Expr* Expr::CreateNop() { + return new Expr(ExprType::Nop); +} + +// static +Expr* Expr::CreateReturn() { + return new Expr(ExprType::Return); +} + +// static +Expr* Expr::CreateSelect() { + return new Expr(ExprType::Select); +} + +// static +Expr* Expr::CreateSetGlobal(Var var) { + Expr* expr = new Expr(ExprType::SetGlobal); + expr->set_global.var = var; + return expr; +} + +// static +Expr* Expr::CreateSetLocal(Var var) { + Expr* expr = new Expr(ExprType::SetLocal); + expr->set_local.var = var; + return expr; +} + +// static +Expr* Expr::CreateStore(Opcode opcode, uint32_t align, uint64_t offset) { + Expr* expr = new Expr(ExprType::Store); + expr->store.opcode = opcode; + expr->store.align = align; + expr->store.offset = offset; + return expr; +} + +// static +Expr* Expr::CreateTeeLocal(Var var) { + Expr* expr = new Expr(ExprType::TeeLocal); + expr->tee_local.var = var; + return expr; +} + +// static +Expr* Expr::CreateUnary(Opcode opcode) { + Expr* expr = new Expr(ExprType::Unary); + expr->unary.opcode = opcode; + return expr; +} + +// static +Expr* Expr::CreateUnreachable() { + return new Expr(ExprType::Unreachable); +} + +FuncType::FuncType() { + WABT_ZERO_MEMORY(name); +} + +FuncType::~FuncType() { + destroy_string_slice(&name); +} + +FuncDeclaration::FuncDeclaration() : has_func_type(false) { + WABT_ZERO_MEMORY(type_var); +} + +FuncDeclaration::~FuncDeclaration() { + destroy_var(&type_var); } Func::Func() : first_expr(nullptr) { WABT_ZERO_MEMORY(name); - WABT_ZERO_MEMORY(decl); - WABT_ZERO_MEMORY(local_types); } Func::~Func() { destroy_string_slice(&name); - destroy_func_declaration(&decl); - destroy_type_vector(&local_types); destroy_expr_list(first_expr); } -void destroy_global(Global* global) { - destroy_string_slice(&global->name); - destroy_expr_list(global->init_expr); +Global::Global() : type(Type::Void), mutable_(false), init_expr(nullptr) { + WABT_ZERO_MEMORY(name); +} + +Global::~Global() { + destroy_string_slice(&name); + destroy_expr_list(init_expr); +} + +Table::Table() { + WABT_ZERO_MEMORY(name); + WABT_ZERO_MEMORY(elem_limits); } -void destroy_import(Import* import) { - destroy_string_slice(&import->module_name); - destroy_string_slice(&import->field_name); - switch (import->kind) { +Table::~Table() { + destroy_string_slice(&name); +} + +ElemSegment::ElemSegment() : offset(nullptr) { + WABT_ZERO_MEMORY(table_var); +} + +ElemSegment::~ElemSegment() { + destroy_var(&table_var); + destroy_expr_list(offset); + for (Var& var : vars) + destroy_var(&var); +} + +DataSegment::DataSegment() : offset(nullptr), data(nullptr), size(0) { + WABT_ZERO_MEMORY(memory_var); +} + +DataSegment::~DataSegment() { + destroy_var(&memory_var); + destroy_expr_list(offset); + delete [] data; +} + +Memory::Memory() { + WABT_ZERO_MEMORY(name); + WABT_ZERO_MEMORY(page_limits); +} + +Memory::~Memory() { + destroy_string_slice(&name); +} + +Import::Import() : kind(ExternalKind::Func), func(nullptr) { + WABT_ZERO_MEMORY(module_name); + WABT_ZERO_MEMORY(field_name); +} + +Import::~Import() { + destroy_string_slice(&module_name); + destroy_string_slice(&field_name); + switch (kind) { case ExternalKind::Func: - delete import->func; + delete func; break; case ExternalKind::Table: - destroy_table(&import->table); + delete table; break; case ExternalKind::Memory: - destroy_memory(&import->memory); + delete memory; break; case ExternalKind::Global: - destroy_global(&import->global); + delete global; break; } } -void destroy_export(Export* export_) { - destroy_string_slice(&export_->name); - destroy_var(&export_->var); -} - -void destroy_func_type(FuncType* func_type) { - destroy_string_slice(&func_type->name); - destroy_func_signature(&func_type->sig); +Export::Export() { + WABT_ZERO_MEMORY(name); + WABT_ZERO_MEMORY(var); } -void destroy_data_segment(DataSegment* data) { - destroy_var(&data->memory_var); - destroy_expr_list(data->offset); - delete [] data->data; +Export::~Export() { + destroy_string_slice(&name); + destroy_var(&var); } void destroy_memory(Memory* memory) { @@ -376,38 +598,42 @@ void destroy_table(Table* table) { destroy_string_slice(&table->name); } -static void destroy_module_field(ModuleField* field) { - switch (field->type) { +ModuleField::ModuleField() : type(ModuleFieldType::Start), next(nullptr) { + WABT_ZERO_MEMORY(loc); + WABT_ZERO_MEMORY(start); +} + +ModuleField::~ModuleField() { + switch (type) { case ModuleFieldType::Func: - delete field->func; + delete func; break; case ModuleFieldType::Global: - destroy_global(&field->global); + delete global; break; case ModuleFieldType::Import: - destroy_import(field->import); - delete field->import; + delete import; break; case ModuleFieldType::Export: - destroy_export(&field->export_); + delete export_; break; case ModuleFieldType::FuncType: - destroy_func_type(&field->func_type); + delete func_type; break; case ModuleFieldType::Table: - destroy_table(&field->table); + delete table; break; case ModuleFieldType::ElemSegment: - destroy_elem_segment(&field->elem_segment); + delete elem_segment; break; case ModuleFieldType::Memory: - destroy_memory(&field->memory); + delete memory; break; case ModuleFieldType::DataSegment: - destroy_data_segment(&field->data_segment); + delete data_segment; break; case ModuleFieldType::Start: - destroy_var(&field->start); + destroy_var(&start); break; } } @@ -422,15 +648,6 @@ Module::Module() start(0) { WABT_ZERO_MEMORY(loc); WABT_ZERO_MEMORY(name); - WABT_ZERO_MEMORY(funcs); - WABT_ZERO_MEMORY(globals); - WABT_ZERO_MEMORY(imports); - WABT_ZERO_MEMORY(exports); - WABT_ZERO_MEMORY(func_types); - WABT_ZERO_MEMORY(tables); - WABT_ZERO_MEMORY(elem_segments); - WABT_ZERO_MEMORY(memories); - WABT_ZERO_MEMORY(data_segments); } Module::~Module() { @@ -439,107 +656,89 @@ Module::~Module() { ModuleField* field = first_field; while (field) { ModuleField* next_field = field->next; - destroy_module_field(field); delete field; field = next_field; } +} - /* everything that follows shares data with the module fields above, so we - only need to destroy the containing vectors */ - destroy_func_ptr_vector(&funcs); - destroy_global_ptr_vector(&globals); - destroy_import_ptr_vector(&imports); - destroy_export_ptr_vector(&exports); - destroy_func_type_ptr_vector(&func_types); - destroy_table_ptr_vector(&tables); - destroy_elem_segment_ptr_vector(&elem_segments); - destroy_memory_ptr_vector(&memories); - destroy_data_segment_ptr_vector(&data_segments); -} - -void destroy_raw_module(RawModule* raw) { - if (raw->type == RawModuleType::Text) { - delete raw->text; +RawModule::RawModule() : type(RawModuleType::Text), text(nullptr) {} + +RawModule::~RawModule() { + if (type == RawModuleType::Text) { + delete text; } else { - destroy_string_slice(&raw->binary.name); - delete [] raw->binary.data; + destroy_string_slice(&binary.name); + delete [] binary.data; } } -void destroy_action(Action* action) { - destroy_var(&action->module_var); - switch (action->type) { +ActionInvoke::ActionInvoke() {} + +Action::Action() : type(ActionType::Get) { + WABT_ZERO_MEMORY(loc); + WABT_ZERO_MEMORY(module_var); + WABT_ZERO_MEMORY(name); +} + +Action::~Action() { + destroy_var(&module_var); + destroy_string_slice(&name); + switch (type) { case ActionType::Invoke: - destroy_string_slice(&action->invoke.name); - destroy_const_vector(&action->invoke.args); + delete invoke; break; case ActionType::Get: - destroy_string_slice(&action->get.name); break; } } -void destroy_command(Command* command) { - switch (command->type) { +Command::Command() : type(CommandType::Module), module(nullptr) {} + +Command::~Command() { + switch (type) { case CommandType::Module: - delete command->module; + delete module; break; case CommandType::Action: - destroy_action(&command->action); + delete action; break; case CommandType::Register: - destroy_string_slice(&command->register_.module_name); - destroy_var(&command->register_.var); + destroy_string_slice(®ister_.module_name); + destroy_var(®ister_.var); break; case CommandType::AssertMalformed: - destroy_raw_module(&command->assert_malformed.module); - destroy_string_slice(&command->assert_malformed.text); + delete assert_malformed.module; + destroy_string_slice(&assert_malformed.text); break; case CommandType::AssertInvalid: case CommandType::AssertInvalidNonBinary: - destroy_raw_module(&command->assert_invalid.module); - destroy_string_slice(&command->assert_invalid.text); + delete assert_invalid.module; + destroy_string_slice(&assert_invalid.text); break; case CommandType::AssertUnlinkable: - destroy_raw_module(&command->assert_unlinkable.module); - destroy_string_slice(&command->assert_unlinkable.text); + delete assert_unlinkable.module; + destroy_string_slice(&assert_unlinkable.text); break; case CommandType::AssertUninstantiable: - destroy_raw_module(&command->assert_uninstantiable.module); - destroy_string_slice(&command->assert_uninstantiable.text); + delete assert_uninstantiable.module; + destroy_string_slice(&assert_uninstantiable.text); break; case CommandType::AssertReturn: - destroy_action(&command->assert_return.action); - destroy_const_vector(&command->assert_return.expected); + delete assert_return.action; + delete assert_return.expected; break; case CommandType::AssertReturnNan: - destroy_action(&command->assert_return_nan.action); + delete assert_return_nan.action; break; case CommandType::AssertTrap: case CommandType::AssertExhaustion: - destroy_action(&command->assert_trap.action); - destroy_string_slice(&command->assert_trap.text); + delete assert_trap.action; + destroy_string_slice(&assert_trap.text); break; } } -void destroy_command_vector_and_elements(CommandVector* commands) { - WABT_DESTROY_VECTOR_AND_ELEMENTS(*commands, command); -} - -void destroy_elem_segment(ElemSegment* elem) { - destroy_var(&elem->table_var); - destroy_expr_list(elem->offset); - WABT_DESTROY_VECTOR_AND_ELEMENTS(elem->vars, var); -} - -Script::Script() { - WABT_ZERO_MEMORY(commands); -} - -Script::~Script() { - WABT_DESTROY_VECTOR_AND_ELEMENTS(commands, command); -} +Script::Script() {} #define CHECK_RESULT(expr) \ do { \ @@ -568,7 +767,7 @@ static Result visit_expr(Expr* expr, ExprVisitor* visitor) { case ExprType::Block: CALLBACK(begin_block_expr); - CHECK_RESULT(visit_expr_list(expr->block.first, visitor)); + CHECK_RESULT(visit_expr_list(expr->block->first, visitor)); CALLBACK(end_block_expr); break; @@ -626,7 +825,7 @@ static Result visit_expr(Expr* expr, ExprVisitor* visitor) { case ExprType::If: CALLBACK(begin_if_expr); - CHECK_RESULT(visit_expr_list(expr->if_.true_.first, visitor)); + CHECK_RESULT(visit_expr_list(expr->if_.true_->first, visitor)); CALLBACK(after_if_true_expr); CHECK_RESULT(visit_expr_list(expr->if_.false_, visitor)); CALLBACK(end_if_expr); @@ -638,7 +837,7 @@ static Result visit_expr(Expr* expr, ExprVisitor* visitor) { case ExprType::Loop: CALLBACK(begin_loop_expr); - CHECK_RESULT(visit_expr_list(expr->loop.first, visitor)); + CHECK_RESULT(visit_expr_list(expr->loop->first, visitor)); CALLBACK(end_loop_expr); break; @@ -27,8 +27,6 @@ #include "binding-hash.h" #include "common.h" -#include "type-vector.h" -#include "vector.h" namespace wabt { @@ -38,6 +36,11 @@ enum class VarType { }; struct Var { + // Keep the default constructor trivial so it can be used as a union member. + Var() = default; + explicit Var(int64_t index); + explicit Var(const StringSlice& name); + Location loc; VarType type; union { @@ -45,12 +48,24 @@ struct Var { StringSlice name; }; }; -WABT_DEFINE_VECTOR(var, Var); +typedef std::vector<Var> VarVector; typedef StringSlice Label; -WABT_DEFINE_VECTOR(string_slice, StringSlice); struct Const { + // Struct tags to differentiate constructors. + struct I32 {}; + struct I64 {}; + struct F32 {}; + struct F64 {}; + + // Keep the default constructor trivial so it can be used as a union member. + Const() = default; + Const(I32, uint32_t); + Const(I64, uint64_t); + Const(F32, uint32_t); + Const(F64, uint64_t); + Location loc; Type type; union { @@ -60,7 +75,7 @@ struct Const { uint64_t f64_bits; }; }; -WABT_DEFINE_VECTOR(const, Const); +typedef std::vector<Const> ConstVector; enum class ExprType { Binary, @@ -95,25 +110,63 @@ enum class ExprType { typedef TypeVector BlockSignature; struct Block { + WABT_DISALLOW_COPY_AND_ASSIGN(Block); + Block(); + explicit Block(struct Expr* first); + ~Block(); + Label label; BlockSignature sig; struct Expr* first; }; struct Expr { + WABT_DISALLOW_COPY_AND_ASSIGN(Expr); + Expr(); + explicit Expr(ExprType); + ~Expr(); + + static Expr* CreateBinary(Opcode); + static Expr* CreateBlock(Block*); + static Expr* CreateBr(Var); + static Expr* CreateBrIf(Var); + static Expr* CreateBrTable(VarVector* targets, Var default_target); + static Expr* CreateCall(Var); + static Expr* CreateCallIndirect(Var); + static Expr* CreateCompare(Opcode); + static Expr* CreateConst(const Const&); + static Expr* CreateConvert(Opcode); + static Expr* CreateCurrentMemory(); + static Expr* CreateDrop(); + static Expr* CreateGetGlobal(Var); + static Expr* CreateGetLocal(Var); + static Expr* CreateGrowMemory(); + static Expr* CreateIf(struct Block* true_, struct Expr* false_ = nullptr); + static Expr* CreateLoad(Opcode, uint32_t align, uint64_t offset); + static Expr* CreateLoop(struct Block*); + static Expr* CreateNop(); + static Expr* CreateReturn(); + static Expr* CreateSelect(); + static Expr* CreateSetGlobal(Var); + static Expr* CreateSetLocal(Var); + static Expr* CreateStore(Opcode, uint32_t align, uint64_t offset); + static Expr* CreateTeeLocal(Var); + static Expr* CreateUnary(Opcode); + static Expr* CreateUnreachable(); + Location loc; ExprType type; Expr* next; union { struct { Opcode opcode; } binary, compare, convert, unary; - Block block, loop; + struct Block *block, *loop; struct { Var var; } br, br_if; - struct { VarVector targets; Var default_target; } br_table; + struct { VarVector* targets; Var default_target; } br_table; struct { Var var; } call, call_indirect; - Const const_; + struct Const const_; struct { Var var; } get_global, set_global; struct { Var var; } get_local, set_local, tee_local; - struct { Block true_; struct Expr* false_; } if_; + struct { struct Block* true_; struct Expr* false_; } if_; struct { Opcode opcode; uint32_t align; uint64_t offset; } load, store; }; }; @@ -124,21 +177,20 @@ struct FuncSignature { }; struct FuncType { + WABT_DISALLOW_COPY_AND_ASSIGN(FuncType); + FuncType(); + ~FuncType(); + StringSlice name; FuncSignature sig; }; -typedef FuncType* FuncTypePtr; -WABT_DEFINE_VECTOR(func_type_ptr, FuncTypePtr); - -enum { - WABT_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE = 1, - /* set if the signature is owned by module */ - WABT_FUNC_DECLARATION_FLAG_SHARED_SIGNATURE = 2, -}; -typedef uint32_t FuncDeclarationFlags; struct FuncDeclaration { - FuncDeclarationFlags flags; + WABT_DISALLOW_COPY_AND_ASSIGN(FuncDeclaration); + FuncDeclaration(); + ~FuncDeclaration(); + + bool has_func_type; Var type_var; FuncSignature sig; }; @@ -155,50 +207,62 @@ struct Func { BindingHash local_bindings; Expr* first_expr; }; -typedef Func* FuncPtr; -WABT_DEFINE_VECTOR(func_ptr, FuncPtr); struct Global { + WABT_DISALLOW_COPY_AND_ASSIGN(Global); + Global(); + ~Global(); + StringSlice name; Type type; bool mutable_; Expr* init_expr; }; -typedef Global* GlobalPtr; -WABT_DEFINE_VECTOR(global_ptr, GlobalPtr); struct Table { + WABT_DISALLOW_COPY_AND_ASSIGN(Table); + Table(); + ~Table(); + StringSlice name; Limits elem_limits; }; -typedef Table* TablePtr; -WABT_DEFINE_VECTOR(table_ptr, TablePtr); struct ElemSegment { + WABT_DISALLOW_COPY_AND_ASSIGN(ElemSegment); + ElemSegment(); + ~ElemSegment(); + Var table_var; Expr* offset; VarVector vars; }; -typedef ElemSegment* ElemSegmentPtr; -WABT_DEFINE_VECTOR(elem_segment_ptr, ElemSegmentPtr); struct Memory { + WABT_DISALLOW_COPY_AND_ASSIGN(Memory); + Memory(); + ~Memory(); + StringSlice name; Limits page_limits; }; -typedef Memory* MemoryPtr; -WABT_DEFINE_VECTOR(memory_ptr, MemoryPtr); struct DataSegment { + WABT_DISALLOW_COPY_AND_ASSIGN(DataSegment); + DataSegment(); + ~DataSegment(); + Var memory_var; Expr* offset; char* data; size_t size; }; -typedef DataSegment* DataSegmentPtr; -WABT_DEFINE_VECTOR(data_segment_ptr, DataSegmentPtr); struct Import { + WABT_DISALLOW_COPY_AND_ASSIGN(Import); + Import(); + ~Import(); + StringSlice module_name; StringSlice field_name; ExternalKind kind; @@ -207,21 +271,21 @@ struct Import { * included in the Module's vector of funcs; but only the * FuncDeclaration will have any useful information */ Func* func; - Table table; - Memory memory; - Global global; + Table* table; + Memory* memory; + Global* global; }; }; -typedef Import* ImportPtr; -WABT_DEFINE_VECTOR(import_ptr, ImportPtr); struct Export { + WABT_DISALLOW_COPY_AND_ASSIGN(Export); + Export(); + ~Export(); + StringSlice name; ExternalKind kind; Var var; }; -typedef Export* ExportPtr; -WABT_DEFINE_VECTOR(export_ptr, ExportPtr); enum class ModuleFieldType { Func, @@ -237,19 +301,23 @@ enum class ModuleFieldType { }; struct ModuleField { + WABT_DISALLOW_COPY_AND_ASSIGN(ModuleField); + ModuleField(); + ~ModuleField(); + Location loc; ModuleFieldType type; struct ModuleField* next; union { Func* func; - Global global; + Global* global; Import* import; - Export export_; - FuncType func_type; - Table table; - ElemSegment elem_segment; - Memory memory; - DataSegment data_segment; + Export* export_; + FuncType* func_type; + Table* table; + ElemSegment* elem_segment; + Memory* memory; + DataSegment* data_segment; Var start; }; }; @@ -271,15 +339,15 @@ struct Module { /* cached for convenience; the pointers are shared with values that are * stored in either ModuleField or Import. */ - FuncPtrVector funcs; - GlobalPtrVector globals; - ImportPtrVector imports; - ExportPtrVector exports; - FuncTypePtrVector func_types; - TablePtrVector tables; - ElemSegmentPtrVector elem_segments; - MemoryPtrVector memories; - DataSegmentPtrVector data_segments; + std::vector<Func*> funcs; + std::vector<Global*> globals; + std::vector<Import*> imports; + std::vector<Export*> exports; + std::vector<FuncType*> func_types; + std::vector<Table*> tables; + std::vector<ElemSegment*> elem_segments; + std::vector<Memory*> memories; + std::vector<DataSegment*> data_segments; Var* start; BindingHash func_bindings; @@ -301,6 +369,10 @@ enum class RawModuleType { * when parsing text, as assert_invalid always assumes that text parsing * succeeds. */ struct RawModule { + WABT_DISALLOW_COPY_AND_ASSIGN(RawModule); + RawModule(); + ~RawModule(); + RawModuleType type; union { Module* text; @@ -319,21 +391,24 @@ enum class ActionType { }; struct ActionInvoke { - StringSlice name; - ConstVector args; -}; + WABT_DISALLOW_COPY_AND_ASSIGN(ActionInvoke); + ActionInvoke(); -struct ActionGet { - StringSlice name; + ConstVector args; }; struct Action { + WABT_DISALLOW_COPY_AND_ASSIGN(Action); + Action(); + ~Action(); + Location loc; ActionType type; Var module_var; + StringSlice name; union { - ActionInvoke invoke; - ActionGet get; + ActionInvoke* invoke; + struct {} get; }; }; @@ -359,29 +434,32 @@ enum class CommandType { static const int kCommandTypeCount = WABT_ENUM_COUNT(CommandType); struct Command { + WABT_DISALLOW_COPY_AND_ASSIGN(Command); + Command(); + ~Command(); + CommandType type; union { Module* module; - Action action; + Action* action; struct { StringSlice module_name; Var var; } register_; - struct { Action action; ConstVector expected; } assert_return; - struct { Action action; } assert_return_nan; - struct { Action action; StringSlice text; } assert_trap; + struct { Action* action; ConstVector* expected; } assert_return; + struct { Action* action; } assert_return_nan; + struct { Action* action; StringSlice text; } assert_trap; struct { - RawModule module; + RawModule* module; StringSlice text; } assert_malformed, assert_invalid, assert_unlinkable, assert_uninstantiable; }; }; -WABT_DEFINE_VECTOR(command, Command); +typedef std::vector<std::unique_ptr<Command>> CommandPtrVector; struct Script { WABT_DISALLOW_COPY_AND_ASSIGN(Script); Script(); - ~Script(); - CommandVector commands; + CommandPtrVector commands; BindingHash module_bindings; }; @@ -424,54 +502,9 @@ ModuleField* append_module_field(Module*); /* ownership of the function signature is passed to the module */ FuncType* append_implicit_func_type(Location*, Module*, FuncSignature*); -/* Expr creation functions */ -Expr* new_binary_expr(void); -Expr* new_block_expr(void); -Expr* new_br_expr(void); -Expr* new_br_if_expr(void); -Expr* new_br_table_expr(void); -Expr* new_call_expr(void); -Expr* new_call_indirect_expr(void); -Expr* new_compare_expr(void); -Expr* new_const_expr(void); -Expr* new_convert_expr(void); -Expr* new_current_memory_expr(void); -Expr* new_drop_expr(void); -Expr* new_get_global_expr(void); -Expr* new_get_local_expr(void); -Expr* new_grow_memory_expr(void); -Expr* new_if_expr(void); -Expr* new_load_expr(void); -Expr* new_loop_expr(void); -Expr* new_nop_expr(void); -Expr* new_return_expr(void); -Expr* new_select_expr(void); -Expr* new_set_global_expr(void); -Expr* new_set_local_expr(void); -Expr* new_store_expr(void); -Expr* new_tee_local_expr(void); -Expr* new_unary_expr(void); -Expr* new_unreachable_expr(void); - /* destruction functions. not needed unless you're creating your own AST elements */ -void destroy_action(struct Action*); -void destroy_block(struct Block*); -void destroy_command_vector_and_elements(CommandVector*); -void destroy_command(Command*); -void destroy_data_segment(DataSegment*); -void destroy_elem_segment(ElemSegment*); -void destroy_export(Export*); -void destroy_expr(Expr*); void destroy_expr_list(Expr*); -void destroy_func_declaration(FuncDeclaration*); -void destroy_func_signature(FuncSignature*); -void destroy_func_type(FuncType*); -void destroy_import(Import*); -void destroy_memory(Memory*); -void destroy_raw_module(RawModule*); -void destroy_table(Table*); -void destroy_var_vector_and_elements(VarVector*); void destroy_var(Var*); /* traversal functions */ @@ -492,13 +525,13 @@ int get_import_index_by_var(const Module* module, const Var* var); int get_local_index_by_var(const Func* func, const Var* var); int get_module_index_by_var(const Script* script, const Var* var); -FuncPtr get_func_by_var(const Module* module, const Var* var); -GlobalPtr get_global_by_var(const Module* func, const Var* var); -FuncTypePtr get_func_type_by_var(const Module* module, const Var* var); -TablePtr get_table_by_var(const Module* module, const Var* var); -MemoryPtr get_memory_by_var(const Module* module, const Var* var); -ImportPtr get_import_by_var(const Module* module, const Var* var); -ExportPtr get_export_by_name(const Module* module, const StringSlice* name); +Func* get_func_by_var(const Module* module, const Var* var); +Global* get_global_by_var(const Module* func, const Var* var); +FuncType* get_func_type_by_var(const Module* module, const Var* var); +Table* get_table_by_var(const Module* module, const Var* var); +Memory* get_memory_by_var(const Module* module, const Var* var); +Import* get_import_by_var(const Module* module, const Var* var); +Export* get_export_by_name(const Module* module, const StringSlice* name); Module* get_first_module(const Script* script); Module* get_module_by_var(const Script* script, const Var* var); @@ -508,27 +541,25 @@ void make_type_binding_reverse_mapping( std::vector<std::string>* out_reverse_mapping); static WABT_INLINE bool decl_has_func_type(const FuncDeclaration* decl) { - return static_cast<bool>( - (decl->flags & WABT_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE) != 0); + return decl->has_func_type; } static WABT_INLINE bool signatures_are_equal(const FuncSignature* sig1, const FuncSignature* sig2) { - return static_cast<bool>( - type_vectors_are_equal(&sig1->param_types, &sig2->param_types) && - type_vectors_are_equal(&sig1->result_types, &sig2->result_types)); + return sig1->param_types == sig2->param_types && + sig1->result_types == sig2->result_types; } static WABT_INLINE size_t get_num_params(const Func* func) { - return func->decl.sig.param_types.size; + return func->decl.sig.param_types.size(); } static WABT_INLINE size_t get_num_results(const Func* func) { - return func->decl.sig.result_types.size; + return func->decl.sig.result_types.size(); } static WABT_INLINE size_t get_num_locals(const Func* func) { - return func->local_types.size; + return func->local_types.size(); } static WABT_INLINE size_t get_num_params_and_locals(const Func* func) { @@ -536,36 +567,36 @@ static WABT_INLINE size_t get_num_params_and_locals(const Func* func) { } static WABT_INLINE Type get_param_type(const Func* func, int index) { - assert(static_cast<size_t>(index) < func->decl.sig.param_types.size); - return func->decl.sig.param_types.data[index]; + assert(static_cast<size_t>(index) < func->decl.sig.param_types.size()); + return func->decl.sig.param_types[index]; } static WABT_INLINE Type get_local_type(const Func* func, int index) { assert(static_cast<size_t>(index) < get_num_locals(func)); - return func->local_types.data[index]; + return func->local_types[index]; } static WABT_INLINE Type get_result_type(const Func* func, int index) { - assert(static_cast<size_t>(index) < func->decl.sig.result_types.size); - return func->decl.sig.result_types.data[index]; + assert(static_cast<size_t>(index) < func->decl.sig.result_types.size()); + return func->decl.sig.result_types[index]; } static WABT_INLINE Type get_func_type_param_type(const FuncType* func_type, int index) { - return func_type->sig.param_types.data[index]; + return func_type->sig.param_types[index]; } static WABT_INLINE size_t get_func_type_num_params(const FuncType* func_type) { - return func_type->sig.param_types.size; + return func_type->sig.param_types.size(); } static WABT_INLINE Type get_func_type_result_type(const FuncType* func_type, int index) { - return func_type->sig.result_types.data[index]; + return func_type->sig.result_types[index]; } static WABT_INLINE size_t get_func_type_num_results(const FuncType* func_type) { - return func_type->sig.result_types.size; + return func_type->sig.result_types.size(); } static WABT_INLINE const Location* get_raw_module_location( diff --git a/src/binary-reader-ast.cc b/src/binary-reader-ast.cc index 68185eb9..39c9e8fa 100644 --- a/src/binary-reader-ast.cc +++ b/src/binary-reader-ast.cc @@ -22,6 +22,8 @@ #include <stdint.h> #include <stdio.h> +#include <vector> + #include "ast.h" #include "binary-reader.h" #include "common.h" @@ -37,20 +39,24 @@ namespace wabt { namespace { struct LabelNode { + LabelNode(LabelType, Expr** first); + LabelType label_type; Expr** first; Expr* last; }; -WABT_DEFINE_VECTOR(label_node, LabelNode); + +LabelNode::LabelNode(LabelType label_type, Expr** first) + : label_type(label_type), first(first), last(nullptr) {} struct Context { - BinaryErrorHandler* error_handler; - Module* module; + BinaryErrorHandler* error_handler = nullptr; + Module* module = nullptr; - Func* current_func; - LabelNodeVector label_stack; - uint32_t max_depth; - Expr** current_init_expr; + Func* current_func = nullptr; + std::vector<LabelNode> label_stack; + uint32_t max_depth = 0; + Expr** current_init_expr = nullptr; }; } // namespace @@ -64,33 +70,29 @@ static void WABT_PRINTF_FORMAT(2, 3) } static void push_label(Context* ctx, LabelType label_type, Expr** first) { - LabelNode label; - label.label_type = label_type; - label.first = first; - label.last = nullptr; ctx->max_depth++; - append_label_node_value(&ctx->label_stack, &label); + ctx->label_stack.emplace_back(label_type, first); } static Result pop_label(Context* ctx) { - if (ctx->label_stack.size == 0) { + if (ctx->label_stack.size() == 0) { print_error(ctx, "popping empty label stack"); return Result::Error; } ctx->max_depth--; - ctx->label_stack.size--; + ctx->label_stack.pop_back(); return Result::Ok; } static Result get_label_at(Context* ctx, LabelNode** label, uint32_t depth) { - if (depth >= ctx->label_stack.size) { + if (depth >= ctx->label_stack.size()) { print_error(ctx, "accessing stack depth: %u >= max: %" PRIzd, depth, - ctx->label_stack.size); + ctx->label_stack.size()); return Result::Error; } - *label = &ctx->label_stack.data[ctx->label_stack.size - depth - 1]; + *label = &ctx->label_stack[ctx->label_stack.size() - depth - 1]; return Result::Ok; } @@ -128,7 +130,7 @@ static bool on_error(BinaryReaderContext* reader_context, const char* message) { static Result on_signature_count(uint32_t count, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - reserve_func_type_ptrs(&ctx->module->func_types, count); + ctx->module->func_types.reserve(count); return Result::Ok; } @@ -141,29 +143,18 @@ static Result on_signature(uint32_t index, Context* ctx = static_cast<Context*>(user_data); ModuleField* field = append_module_field(ctx->module); field->type = ModuleFieldType::FuncType; + field->func_type = new FuncType(); - FuncType* func_type = &field->func_type; - WABT_ZERO_MEMORY(*func_type); - - 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(Type)); - - 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(Type)); - - assert(index < ctx->module->func_types.capacity); - FuncTypePtr* func_type_ptr = append_func_type_ptr(&ctx->module->func_types); - *func_type_ptr = func_type; + FuncType* func_type = field->func_type; + func_type->sig.param_types.assign(param_types, param_types + param_count); + func_type->sig.result_types.assign(result_types, result_types + result_count); + ctx->module->func_types.push_back(func_type); return Result::Ok; } static Result on_import_count(uint32_t count, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - reserve_import_ptrs(&ctx->module->imports, count); + ctx->module->imports.reserve(count); return Result::Ok; } @@ -172,7 +163,6 @@ static Result on_import(uint32_t index, StringSlice field_name, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - assert(index < ctx->module->imports.capacity); ModuleField* field = append_module_field(ctx->module); field->type = ModuleFieldType::Import; @@ -181,9 +171,7 @@ static Result on_import(uint32_t index, Import* import = field->import; import->module_name = dup_string_slice(module_name); import->field_name = dup_string_slice(field_name); - - ImportPtr* import_ptr = append_import_ptr(&ctx->module->imports); - *import_ptr = import; + ctx->module->imports.push_back(import); return Result::Ok; } @@ -194,20 +182,17 @@ static Result on_import_func(uint32_t import_index, uint32_t sig_index, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - assert(import_index == ctx->module->imports.size - 1); - assert(sig_index < ctx->module->func_types.size); - Import* import = ctx->module->imports.data[import_index]; + assert(import_index == ctx->module->imports.size() - 1); + Import* import = ctx->module->imports[import_index]; import->kind = ExternalKind::Func; import->func = new Func(); - import->func->decl.flags = WABT_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE | - WABT_FUNC_DECLARATION_FLAG_SHARED_SIGNATURE; + import->func->decl.has_func_type = true; import->func->decl.type_var.type = VarType::Index; import->func->decl.type_var.index = sig_index; - import->func->decl.sig = ctx->module->func_types.data[sig_index]->sig; + import->func->decl.sig = ctx->module->func_types[sig_index]->sig; - FuncPtr func_ptr = import->func; - append_func_ptr_value(&ctx->module->funcs, &func_ptr); + ctx->module->funcs.push_back(import->func); ctx->module->num_func_imports++; return Result::Ok; } @@ -220,13 +205,12 @@ static Result on_import_table(uint32_t import_index, const Limits* elem_limits, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - assert(import_index == ctx->module->imports.size - 1); - Import* import = ctx->module->imports.data[import_index]; + assert(import_index == ctx->module->imports.size() - 1); + Import* import = ctx->module->imports[import_index]; import->kind = ExternalKind::Table; - import->table.elem_limits = *elem_limits; - - TablePtr table_ptr = &import->table; - append_table_ptr_value(&ctx->module->tables, &table_ptr); + import->table = new Table(); + import->table->elem_limits = *elem_limits; + ctx->module->tables.push_back(import->table); ctx->module->num_table_imports++; return Result::Ok; } @@ -238,13 +222,12 @@ static Result on_import_memory(uint32_t import_index, const Limits* page_limits, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - assert(import_index == ctx->module->imports.size - 1); - Import* import = ctx->module->imports.data[import_index]; + assert(import_index == ctx->module->imports.size() - 1); + Import* import = ctx->module->imports[import_index]; import->kind = ExternalKind::Memory; - import->memory.page_limits = *page_limits; - - MemoryPtr memory_ptr = &import->memory; - append_memory_ptr_value(&ctx->module->memories, &memory_ptr); + import->memory = new Memory(); + import->memory->page_limits = *page_limits; + ctx->module->memories.push_back(import->memory); ctx->module->num_memory_imports++; return Result::Ok; } @@ -257,21 +240,20 @@ static Result on_import_global(uint32_t import_index, bool mutable_, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - assert(import_index == ctx->module->imports.size - 1); - Import* import = ctx->module->imports.data[import_index]; + assert(import_index == ctx->module->imports.size() - 1); + Import* import = ctx->module->imports[import_index]; import->kind = ExternalKind::Global; - import->global.type = type; - import->global.mutable_ = mutable_; - - GlobalPtr global_ptr = &import->global; - append_global_ptr_value(&ctx->module->globals, &global_ptr); + import->global = new Global(); + import->global->type = type; + import->global->mutable_ = mutable_; + ctx->module->globals.push_back(import->global); ctx->module->num_global_imports++; return Result::Ok; } static Result on_function_signatures_count(uint32_t count, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - reserve_func_ptrs(&ctx->module->funcs, ctx->module->num_func_imports + count); + ctx->module->funcs.reserve(ctx->module->num_func_imports + count); return Result::Ok; } @@ -279,29 +261,24 @@ static Result on_function_signature(uint32_t index, uint32_t sig_index, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - assert(index < ctx->module->funcs.capacity); - assert(sig_index < ctx->module->func_types.size); ModuleField* field = append_module_field(ctx->module); field->type = ModuleFieldType::Func; field->func = new Func(); Func* func = field->func; - func->decl.flags = WABT_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE | - WABT_FUNC_DECLARATION_FLAG_SHARED_SIGNATURE; + func->decl.has_func_type = true; func->decl.type_var.type = VarType::Index; func->decl.type_var.index = sig_index; - func->decl.sig = ctx->module->func_types.data[sig_index]->sig; + func->decl.sig = ctx->module->func_types[sig_index]->sig; - FuncPtr* func_ptr = append_func_ptr(&ctx->module->funcs); - *func_ptr = func; + ctx->module->funcs.push_back(func); return Result::Ok; } static Result on_table_count(uint32_t count, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - reserve_table_ptrs(&ctx->module->tables, - ctx->module->num_table_imports + count); + ctx->module->tables.reserve(ctx->module->num_table_imports + count); return Result::Ok; } @@ -310,24 +287,18 @@ static Result on_table(uint32_t index, const Limits* elem_limits, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - assert(index < ctx->module->tables.capacity); ModuleField* field = append_module_field(ctx->module); field->type = ModuleFieldType::Table; - - Table* table = &field->table; - WABT_ZERO_MEMORY(*table); - table->elem_limits = *elem_limits; - - TablePtr* table_ptr = append_table_ptr(&ctx->module->tables); - *table_ptr = table; + field->table = new Table(); + field->table->elem_limits = *elem_limits; + ctx->module->tables.push_back(field->table); return Result::Ok; } static Result on_memory_count(uint32_t count, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - reserve_memory_ptrs(&ctx->module->memories, - ctx->module->num_memory_imports + count); + ctx->module->memories.reserve(ctx->module->num_memory_imports + count); return Result::Ok; } @@ -335,24 +306,18 @@ static Result on_memory(uint32_t index, const Limits* page_limits, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - assert(index < ctx->module->memories.capacity); ModuleField* field = append_module_field(ctx->module); field->type = ModuleFieldType::Memory; - - Memory* memory = &field->memory; - WABT_ZERO_MEMORY(*memory); - memory->page_limits = *page_limits; - - MemoryPtr* memory_ptr = append_memory_ptr(&ctx->module->memories); - *memory_ptr = memory; + field->memory = new Memory(); + field->memory->page_limits = *page_limits; + ctx->module->memories.push_back(field->memory); return Result::Ok; } static Result on_global_count(uint32_t count, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - reserve_global_ptrs(&ctx->module->globals, - ctx->module->num_global_imports + count); + ctx->module->globals.reserve(ctx->module->num_global_imports + count); return Result::Ok; } @@ -361,25 +326,20 @@ static Result begin_global(uint32_t index, bool mutable_, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - assert(index < ctx->module->globals.capacity); ModuleField* field = append_module_field(ctx->module); field->type = ModuleFieldType::Global; - - Global* global = &field->global; - WABT_ZERO_MEMORY(*global); - global->type = type; - global->mutable_ = mutable_; - - GlobalPtr* global_ptr = append_global_ptr(&ctx->module->globals); - *global_ptr = global; + field->global = new Global(); + field->global->type = type; + field->global->mutable_ = mutable_; + ctx->module->globals.push_back(field->global); return Result::Ok; } static Result begin_global_init_expr(uint32_t index, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - assert(index == ctx->module->globals.size - 1); - Global* global = ctx->module->globals.data[index]; + assert(index == ctx->module->globals.size() - 1); + Global* global = ctx->module->globals[index]; ctx->current_init_expr = &global->init_expr; return Result::Ok; } @@ -392,7 +352,7 @@ static Result end_global_init_expr(uint32_t index, void* user_data) { static Result on_export_count(uint32_t count, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - reserve_export_ptrs(&ctx->module->exports, count); + ctx->module->exports.reserve(count); return Result::Ok; } @@ -404,31 +364,28 @@ static Result on_export(uint32_t index, Context* ctx = static_cast<Context*>(user_data); ModuleField* field = append_module_field(ctx->module); field->type = ModuleFieldType::Export; + field->export_ = new Export(); - Export* export_ = &field->export_; - WABT_ZERO_MEMORY(*export_); + Export* export_ = field->export_; export_->name = dup_string_slice(name); switch (kind) { case ExternalKind::Func: - assert(item_index < ctx->module->funcs.size); + assert(item_index < ctx->module->funcs.size()); break; case ExternalKind::Table: - assert(item_index < ctx->module->tables.size); + assert(item_index < ctx->module->tables.size()); break; case ExternalKind::Memory: - assert(item_index < ctx->module->memories.size); + assert(item_index < ctx->module->memories.size()); break; case ExternalKind::Global: - assert(item_index < ctx->module->globals.size); + assert(item_index < ctx->module->globals.size()); break; } export_->var.type = VarType::Index; export_->var.index = item_index; export_->kind = kind; - - assert(index < ctx->module->exports.capacity); - ExportPtr* export_ptr = append_export_ptr(&ctx->module->exports); - *export_ptr = export_; + ctx->module->exports.push_back(export_); return Result::Ok; } @@ -438,7 +395,7 @@ static Result on_start_function(uint32_t func_index, void* user_data) { field->type = ModuleFieldType::Start; field->start.type = VarType::Index; - assert(func_index < ctx->module->funcs.size); + assert(func_index < ctx->module->funcs.size()); field->start.index = func_index; ctx->module->start = &field->start; @@ -447,7 +404,7 @@ static Result on_start_function(uint32_t func_index, void* user_data) { static Result on_function_bodies_count(uint32_t count, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - assert(ctx->module->num_func_imports + count == ctx->module->funcs.size); + assert(ctx->module->num_func_imports + count == ctx->module->funcs.size()); WABT_USE(ctx); return Result::Ok; } @@ -455,8 +412,7 @@ static Result on_function_bodies_count(uint32_t count, void* user_data) { static Result begin_function_body(BinaryReaderContext* context, uint32_t index) { Context* ctx = static_cast<Context*>(context->user_data); - assert(index < ctx->module->funcs.size); - ctx->current_func = ctx->module->funcs.data[index]; + ctx->current_func = ctx->module->funcs[index]; push_label(ctx, LabelType::Func, &ctx->current_func->first_expr); return Result::Ok; } @@ -466,20 +422,16 @@ static Result on_local_decl(uint32_t decl_index, Type type, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - size_t old_local_count = ctx->current_func->local_types.size; - size_t new_local_count = old_local_count + count; - reserve_types(&ctx->current_func->local_types, new_local_count); - TypeVector* types = &ctx->current_func->local_types; + TypeVector& types = ctx->current_func->local_types; + types.reserve(types.size() + count); for (size_t i = 0; i < count; ++i) - types->data[old_local_count + i] = type; - types->size = new_local_count; + types.push_back(type); return Result::Ok; } static Result on_binary_expr(Opcode opcode, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - Expr* expr = new_binary_expr(); - expr->binary.opcode = opcode; + Expr* expr = Expr::CreateBinary(opcode); return append_expr(ctx, expr); } @@ -487,30 +439,22 @@ static Result on_block_expr(uint32_t num_types, Type* sig_types, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - Expr* expr = new_block_expr(); - TypeVector src; - WABT_ZERO_MEMORY(src); - src.size = num_types; - src.data = sig_types; - extend_types(&expr->block.sig, &src); + Expr* expr = Expr::CreateBlock(new Block()); + expr->block->sig.assign(sig_types, sig_types + num_types); append_expr(ctx, expr); - push_label(ctx, LabelType::Block, &expr->block.first); + push_label(ctx, LabelType::Block, &expr->block->first); return Result::Ok; } static Result on_br_expr(uint32_t depth, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - Expr* expr = new_br_expr(); - expr->br.var.type = VarType::Index; - expr->br.var.index = depth; + Expr* expr = Expr::CreateBr(Var(depth)); return append_expr(ctx, expr); } static Result on_br_if_expr(uint32_t depth, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - Expr* expr = new_br_if_expr(); - expr->br_if.var.type = VarType::Index; - expr->br_if.var.index = depth; + Expr* expr = Expr::CreateBrIf(Var(depth)); return append_expr(ctx, expr); } @@ -519,60 +463,50 @@ static Result on_br_table_expr(BinaryReaderContext* context, uint32_t* target_depths, uint32_t default_target_depth) { Context* ctx = static_cast<Context*>(context->user_data); - Expr* expr = new_br_table_expr(); - reserve_vars(&expr->br_table.targets, num_targets); - expr->br_table.targets.size = num_targets; + VarVector* targets = new VarVector(); + targets->resize(num_targets); for (uint32_t i = 0; i < num_targets; ++i) { - Var* var = &expr->br_table.targets.data[i]; - var->type = VarType::Index; - var->index = target_depths[i]; + (*targets)[i] = Var(target_depths[i]); } - expr->br_table.default_target.type = VarType::Index; - expr->br_table.default_target.index = default_target_depth; + Expr* expr = Expr::CreateBrTable(targets, Var(default_target_depth)); return append_expr(ctx, expr); } static Result on_call_expr(uint32_t func_index, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - assert(func_index < ctx->module->funcs.size); - Expr* expr = new_call_expr(); - expr->call.var.type = VarType::Index; - expr->call.var.index = func_index; + assert(func_index < ctx->module->funcs.size()); + Expr* expr = Expr::CreateCall(Var(func_index)); return append_expr(ctx, expr); } static Result on_call_indirect_expr(uint32_t sig_index, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - assert(sig_index < ctx->module->func_types.size); - Expr* expr = new_call_indirect_expr(); - expr->call_indirect.var.type = VarType::Index; - expr->call_indirect.var.index = sig_index; + assert(sig_index < ctx->module->func_types.size()); + Expr* expr = Expr::CreateCallIndirect(Var(sig_index)); return append_expr(ctx, expr); } static Result on_compare_expr(Opcode opcode, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - Expr* expr = new_compare_expr(); - expr->compare.opcode = opcode; + Expr* expr = Expr::CreateCompare(opcode); return append_expr(ctx, expr); } static Result on_convert_expr(Opcode opcode, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - Expr* expr = new_convert_expr(); - expr->convert.opcode = opcode; + Expr* expr = Expr::CreateConvert(opcode); return append_expr(ctx, expr); } static Result on_current_memory_expr(void* user_data) { Context* ctx = static_cast<Context*>(user_data); - Expr* expr = new_current_memory_expr(); + Expr* expr = Expr::CreateCurrentMemory(); return append_expr(ctx, expr); } static Result on_drop_expr(void* user_data) { Context* ctx = static_cast<Context*>(user_data); - Expr* expr = new_drop_expr(); + Expr* expr = Expr::CreateDrop(); return append_expr(ctx, expr); } @@ -602,68 +536,53 @@ static Result on_end_expr(void* user_data) { static Result on_f32_const_expr(uint32_t value_bits, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - Expr* expr = new_const_expr(); - expr->const_.type = Type::F32; - expr->const_.f32_bits = value_bits; + Expr* expr = Expr::CreateConst(Const(Const::F32(), value_bits)); return append_expr(ctx, expr); } static Result on_f64_const_expr(uint64_t value_bits, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - Expr* expr = new_const_expr(); - expr->const_.type = Type::F64; - expr->const_.f64_bits = value_bits; + Expr* expr = Expr::CreateConst(Const(Const::F64(), value_bits)); return append_expr(ctx, expr); } static Result on_get_global_expr(uint32_t global_index, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - Expr* expr = new_get_global_expr(); - expr->get_global.var.type = VarType::Index; - expr->get_global.var.index = global_index; + Expr* expr = Expr::CreateGetGlobal(Var(global_index)); return append_expr(ctx, expr); } static Result on_get_local_expr(uint32_t local_index, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - Expr* expr = new_get_local_expr(); - expr->get_local.var.type = VarType::Index; - expr->get_local.var.index = local_index; + Expr* expr = Expr::CreateGetLocal(Var(local_index)); return append_expr(ctx, expr); } static Result on_grow_memory_expr(void* user_data) { Context* ctx = static_cast<Context*>(user_data); - Expr* expr = new_grow_memory_expr(); + Expr* expr = Expr::CreateGrowMemory(); return append_expr(ctx, expr); } static Result on_i32_const_expr(uint32_t value, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - Expr* expr = new_const_expr(); - expr->const_.type = Type::I32; - expr->const_.u32 = value; + Expr* expr = Expr::CreateConst(Const(Const::I32(), value)); return append_expr(ctx, expr); } static Result on_i64_const_expr(uint64_t value, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - Expr* expr = new_const_expr(); - expr->const_.type = Type::I64; - expr->const_.u64 = value; + Expr* expr = Expr::CreateConst(Const(Const::I64(), value)); return append_expr(ctx, expr); } static Result on_if_expr(uint32_t num_types, Type* sig_types, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - Expr* expr = new_if_expr(); - TypeVector src; - WABT_ZERO_MEMORY(src); - src.size = num_types; - src.data = sig_types; - extend_types(&expr->if_.true_.sig, &src); + Expr* expr = Expr::CreateIf(new Block()); + expr->if_.true_->sig.assign(sig_types, sig_types + num_types); + expr->if_.false_ = nullptr; append_expr(ctx, expr); - push_label(ctx, LabelType::If, &expr->if_.true_.first); + push_label(ctx, LabelType::If, &expr->if_.true_->first); return Result::Ok; } @@ -672,10 +591,7 @@ static Result on_load_expr(Opcode opcode, uint32_t offset, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - Expr* expr = new_load_expr(); - expr->load.opcode = opcode; - expr->load.align = 1 << alignment_log2; - expr->load.offset = offset; + Expr* expr = Expr::CreateLoad(opcode, 1 << alignment_log2, offset); return append_expr(ctx, expr); } @@ -683,48 +599,40 @@ static Result on_loop_expr(uint32_t num_types, Type* sig_types, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - Expr* expr = new_loop_expr(); - TypeVector src; - WABT_ZERO_MEMORY(src); - src.size = num_types; - src.data = sig_types; - extend_types(&expr->loop.sig, &src); + Expr* expr = Expr::CreateLoop(new Block()); + expr->loop->sig.assign(sig_types, sig_types + num_types); append_expr(ctx, expr); - push_label(ctx, LabelType::Loop, &expr->loop.first); + push_label(ctx, LabelType::Loop, &expr->loop->first); return Result::Ok; } static Result on_nop_expr(void* user_data) { Context* ctx = static_cast<Context*>(user_data); - Expr* expr = new_nop_expr(); + Expr* expr = Expr::CreateNop(); return append_expr(ctx, expr); } static Result on_return_expr(void* user_data) { Context* ctx = static_cast<Context*>(user_data); - Expr* expr = new_return_expr(); + Expr* expr = Expr::CreateReturn(); return append_expr(ctx, expr); } static Result on_select_expr(void* user_data) { Context* ctx = static_cast<Context*>(user_data); - Expr* expr = new_select_expr(); + Expr* expr = Expr::CreateSelect(); return append_expr(ctx, expr); } static Result on_set_global_expr(uint32_t global_index, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - Expr* expr = new_set_global_expr(); - expr->set_global.var.type = VarType::Index; - expr->set_global.var.index = global_index; + Expr* expr = Expr::CreateSetGlobal(Var(global_index)); return append_expr(ctx, expr); } static Result on_set_local_expr(uint32_t local_index, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - Expr* expr = new_set_local_expr(); - expr->set_local.var.type = VarType::Index; - expr->set_local.var.index = local_index; + Expr* expr = Expr::CreateSetLocal(Var(local_index)); return append_expr(ctx, expr); } @@ -733,31 +641,25 @@ static Result on_store_expr(Opcode opcode, uint32_t offset, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - Expr* expr = new_store_expr(); - expr->store.opcode = opcode; - expr->store.align = 1 << alignment_log2; - expr->store.offset = offset; + Expr* expr = Expr::CreateStore(opcode, 1 << alignment_log2, offset); return append_expr(ctx, expr); } static Result on_tee_local_expr(uint32_t local_index, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - Expr* expr = new_tee_local_expr(); - expr->tee_local.var.type = VarType::Index; - expr->tee_local.var.index = local_index; + Expr* expr = Expr::CreateTeeLocal(Var(local_index)); return append_expr(ctx, expr); } static Result on_unary_expr(Opcode opcode, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - Expr* expr = new_unary_expr(); - expr->unary.opcode = opcode; + Expr* expr = Expr::CreateUnary(opcode); return append_expr(ctx, expr); } static Result on_unreachable_expr(void* user_data) { Context* ctx = static_cast<Context*>(user_data); - Expr* expr = new_unreachable_expr(); + Expr* expr = Expr::CreateUnreachable(); return append_expr(ctx, expr); } @@ -770,7 +672,7 @@ static Result end_function_body(uint32_t index, void* user_data) { static Result on_elem_segment_count(uint32_t count, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - reserve_elem_segment_ptrs(&ctx->module->elem_segments, count); + ctx->module->elem_segments.reserve(count); return Result::Ok; } @@ -780,24 +682,17 @@ static Result begin_elem_segment(uint32_t index, Context* ctx = static_cast<Context*>(user_data); ModuleField* field = append_module_field(ctx->module); field->type = ModuleFieldType::ElemSegment; - - ElemSegment* segment = &field->elem_segment; - WABT_ZERO_MEMORY(*segment); - segment->table_var.type = VarType::Index; - segment->table_var.index = table_index; - - assert(index == ctx->module->elem_segments.size); - assert(index < ctx->module->elem_segments.capacity); - ElemSegmentPtr* segment_ptr = - append_elem_segment_ptr(&ctx->module->elem_segments); - *segment_ptr = segment; + field->elem_segment = new ElemSegment(); + field->elem_segment->table_var.type = VarType::Index; + field->elem_segment->table_var.index = table_index; + ctx->module->elem_segments.push_back(field->elem_segment); return Result::Ok; } static Result begin_elem_segment_init_expr(uint32_t index, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - assert(index == ctx->module->elem_segments.size - 1); - ElemSegment* segment = ctx->module->elem_segments.data[index]; + assert(index == ctx->module->elem_segments.size() - 1); + ElemSegment* segment = ctx->module->elem_segments[index]; ctx->current_init_expr = &segment->offset; return Result::Ok; } @@ -812,9 +707,9 @@ static Result on_elem_segment_function_index_count(BinaryReaderContext* context, uint32_t index, uint32_t count) { Context* ctx = static_cast<Context*>(context->user_data); - assert(index == ctx->module->elem_segments.size - 1); - ElemSegment* segment = ctx->module->elem_segments.data[index]; - reserve_vars(&segment->vars, count); + assert(index == ctx->module->elem_segments.size() - 1); + ElemSegment* segment = ctx->module->elem_segments[index]; + segment->vars.reserve(count); return Result::Ok; } @@ -822,9 +717,10 @@ static Result on_elem_segment_function_index(uint32_t index, uint32_t func_index, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - assert(index == ctx->module->elem_segments.size - 1); - ElemSegment* segment = ctx->module->elem_segments.data[index]; - Var* var = append_var(&segment->vars); + assert(index == ctx->module->elem_segments.size() - 1); + ElemSegment* segment = ctx->module->elem_segments[index]; + segment->vars.emplace_back(); + Var* var = &segment->vars.back(); var->type = VarType::Index; var->index = func_index; return Result::Ok; @@ -832,7 +728,7 @@ static Result on_elem_segment_function_index(uint32_t index, static Result on_data_segment_count(uint32_t count, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - reserve_data_segment_ptrs(&ctx->module->data_segments, count); + ctx->module->data_segments.reserve(count); return Result::Ok; } @@ -842,24 +738,17 @@ static Result begin_data_segment(uint32_t index, Context* ctx = static_cast<Context*>(user_data); ModuleField* field = append_module_field(ctx->module); field->type = ModuleFieldType::DataSegment; - - DataSegment* segment = &field->data_segment; - WABT_ZERO_MEMORY(*segment); - segment->memory_var.type = VarType::Index; - segment->memory_var.index = memory_index; - - assert(index == ctx->module->data_segments.size); - assert(index < ctx->module->data_segments.capacity); - DataSegmentPtr* segment_ptr = - append_data_segment_ptr(&ctx->module->data_segments); - *segment_ptr = segment; + field->data_segment = new DataSegment(); + field->data_segment->memory_var.type = VarType::Index; + field->data_segment->memory_var.index = memory_index; + ctx->module->data_segments.push_back(field->data_segment); return Result::Ok; } static Result begin_data_segment_init_expr(uint32_t index, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - assert(index == ctx->module->data_segments.size - 1); - DataSegment* segment = ctx->module->data_segments.data[index]; + assert(index == ctx->module->data_segments.size() - 1); + DataSegment* segment = ctx->module->data_segments[index]; ctx->current_init_expr = &segment->offset; return Result::Ok; } @@ -875,8 +764,8 @@ static Result on_data_segment_data(uint32_t index, uint32_t size, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - assert(index == ctx->module->data_segments.size - 1); - DataSegment* segment = ctx->module->data_segments.data[index]; + assert(index == ctx->module->data_segments.size() - 1); + DataSegment* segment = ctx->module->data_segments[index]; segment->data = new char[size]; segment->size = size; memcpy(segment->data, data, size); @@ -885,10 +774,10 @@ static Result on_data_segment_data(uint32_t index, static Result on_function_names_count(uint32_t count, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - if (count > ctx->module->funcs.size) { + if (count > ctx->module->funcs.size()) { print_error( ctx, "expected function name count (%u) <= function count (%" PRIzd ")", - count, ctx->module->funcs.size); + count, ctx->module->funcs.size()); return Result::Error; } return Result::Ok; @@ -903,7 +792,7 @@ static Result on_function_name(uint32_t index, Context* ctx = static_cast<Context*>(user_data); ctx->module->func_bindings.emplace(string_slice_to_string(name), Binding(index)); - Func* func = ctx->module->funcs.data[index]; + Func* func = ctx->module->funcs[index]; func->name = dup_string_slice(name); return Result::Ok; } @@ -913,8 +802,8 @@ static Result on_local_name_local_count(uint32_t index, void* user_data) { Context* ctx = static_cast<Context*>(user_data); Module* module = ctx->module; - assert(index < module->funcs.size); - Func* func = module->funcs.data[index]; + assert(index < module->funcs.size()); + Func* func = module->funcs[index]; uint32_t num_params_and_locals = get_num_params_and_locals(func); if (count > num_params_and_locals) { print_error(ctx, "expected local name count (%d) <= local count (%d)", @@ -928,10 +817,7 @@ static Result on_init_expr_f32_const_expr(uint32_t index, uint32_t value, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - Expr* expr = new_const_expr(); - expr->const_.type = Type::F32; - expr->const_.f32_bits = value; - *ctx->current_init_expr = expr; + *ctx->current_init_expr = Expr::CreateConst(Const(Const::F32(), value)); return Result::Ok; } @@ -939,10 +825,7 @@ static Result on_init_expr_f64_const_expr(uint32_t index, uint64_t value, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - Expr* expr = new_const_expr(); - expr->const_.type = Type::F64; - expr->const_.f64_bits = value; - *ctx->current_init_expr = expr; + *ctx->current_init_expr = Expr::CreateConst(Const(Const::F64(), value)); return Result::Ok; } @@ -950,10 +833,7 @@ static Result on_init_expr_get_global_expr(uint32_t index, uint32_t global_index, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - Expr* expr = new_get_global_expr(); - expr->get_global.var.type = VarType::Index; - expr->get_global.var.index = global_index; - *ctx->current_init_expr = expr; + *ctx->current_init_expr = Expr::CreateGetGlobal(Var(global_index)); return Result::Ok; } @@ -961,10 +841,7 @@ static Result on_init_expr_i32_const_expr(uint32_t index, uint32_t value, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - Expr* expr = new_const_expr(); - expr->const_.type = Type::I32; - expr->const_.u32 = value; - *ctx->current_init_expr = expr; + *ctx->current_init_expr = Expr::CreateConst(Const(Const::I32(), value)); return Result::Ok; } @@ -972,10 +849,7 @@ static Result on_init_expr_i64_const_expr(uint32_t index, uint64_t value, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - Expr* expr = new_const_expr(); - expr->const_.type = Type::I64; - expr->const_.u64 = value; - *ctx->current_init_expr = expr; + *ctx->current_init_expr = Expr::CreateConst(Const(Const::I64(), value)); return Result::Ok; } @@ -988,7 +862,7 @@ static Result on_local_name(uint32_t func_index, Context* ctx = static_cast<Context*>(user_data); Module* module = ctx->module; - Func* func = module->funcs.data[func_index]; + Func* func = module->funcs[func_index]; uint32_t num_params = get_num_params(func); BindingHash* bindings; uint32_t index; @@ -1005,18 +879,12 @@ static Result on_local_name(uint32_t func_index, return Result::Ok; } -static void destroy_label_node(LabelNode* node) { - if (*node->first) - destroy_expr_list(*node->first); -} - Result read_binary_ast(const void* data, size_t size, const ReadBinaryOptions* options, BinaryErrorHandler* error_handler, struct Module* out_module) { Context ctx; - WABT_ZERO_MEMORY(ctx); ctx.error_handler = error_handler; ctx.module = out_module; @@ -1117,7 +985,6 @@ Result read_binary_ast(const void* data, reader.on_init_expr_i64_const_expr = on_init_expr_i64_const_expr; Result result = read_binary(data, size, &reader, 1, options); - WABT_DESTROY_VECTOR_AND_ELEMENTS(ctx.label_stack, label_node); return result; } diff --git a/src/binary-reader-interpreter.cc b/src/binary-reader-interpreter.cc index e69acd1c..b8948c0a 100644 --- a/src/binary-reader-interpreter.cc +++ b/src/binary-reader-interpreter.cc @@ -21,6 +21,8 @@ #include <stdarg.h> #include <stdio.h> +#include <vector> + #include "binary-reader.h" #include "interpreter.h" #include "type-checker.h" @@ -45,7 +47,7 @@ #define CHECK_GLOBAL(ctx, global_index) \ do { \ - uint32_t max_global_index = (ctx)->global_index_mapping.size; \ + uint32_t max_global_index = (ctx)->global_index_mapping.size(); \ if ((global_index) >= max_global_index) { \ print_error((ctx), "invalid global_index: %d (max %d)", (global_index), \ max_global_index); \ @@ -57,27 +59,21 @@ namespace wabt { namespace { -typedef uint32_t Uint32; -WABT_DEFINE_VECTOR(uint32, Uint32); -WABT_DEFINE_VECTOR(uint32_vector, Uint32Vector); +typedef std::vector<uint32_t> Uint32Vector; +typedef std::vector<Uint32Vector> Uint32VectorVector; struct Label { + Label(uint32_t offset, uint32_t fixup_offset); + uint32_t offset; /* branch location in the istream */ uint32_t fixup_offset; }; -WABT_DEFINE_VECTOR(label, Label); + +Label::Label(uint32_t offset, uint32_t fixup_offset) + : offset(offset), fixup_offset(fixup_offset) {} struct Context { - Context() { - WABT_ZERO_MEMORY(typechecker); - WABT_ZERO_MEMORY(label_stack); - WABT_ZERO_MEMORY(func_fixups); - WABT_ZERO_MEMORY(depth_fixups); - WABT_ZERO_MEMORY(istream_writer); - WABT_ZERO_MEMORY(sig_index_mapping); - WABT_ZERO_MEMORY(func_index_mapping); - WABT_ZERO_MEMORY(global_index_mapping); - } + Context(); BinaryReader* reader = nullptr; BinaryErrorHandler* error_handler = nullptr; @@ -85,7 +81,7 @@ struct Context { DefinedInterpreterModule* module = nullptr; DefinedInterpreterFunc* current_func = nullptr; TypeChecker typechecker; - LabelVector label_stack; + std::vector<Label> label_stack; Uint32VectorVector func_fixups; Uint32VectorVector depth_fixups; MemoryWriter istream_writer; @@ -107,11 +103,15 @@ struct Context { uint32_t import_env_index = 0; }; +Context::Context() { + WABT_ZERO_MEMORY(istream_writer); +} + } // namespace static Label* get_label(Context* ctx, uint32_t depth) { - assert(depth < ctx->label_stack.size); - return &ctx->label_stack.data[ctx->label_stack.size - depth - 1]; + assert(depth < ctx->label_stack.size()); + return &ctx->label_stack[ctx->label_stack.size() - depth - 1]; } static Label* top_label(Context* ctx) { @@ -138,8 +138,8 @@ static void on_typechecker_error(const char* msg, void* user_data) { } static uint32_t translate_sig_index_to_env(Context* ctx, uint32_t sig_index) { - assert(sig_index < ctx->sig_index_mapping.size); - return ctx->sig_index_mapping.data[sig_index]; + assert(sig_index < ctx->sig_index_mapping.size()); + return ctx->sig_index_mapping[sig_index]; } static InterpreterFuncSignature* get_signature_by_env_index( @@ -156,8 +156,8 @@ static InterpreterFuncSignature* get_signature_by_module_index( } static uint32_t translate_func_index_to_env(Context* ctx, uint32_t func_index) { - assert(func_index < ctx->func_index_mapping.size); - return ctx->func_index_mapping.data[func_index]; + assert(func_index < ctx->func_index_mapping.size()); + return ctx->func_index_mapping[func_index]; } static uint32_t translate_module_func_index_to_defined(Context* ctx, @@ -179,7 +179,7 @@ static InterpreterFunc* get_func_by_module_index(Context* ctx, static uint32_t translate_global_index_to_env(Context* ctx, uint32_t global_index) { - return ctx->global_index_mapping.data[global_index]; + return ctx->global_index_mapping[global_index]; } static InterpreterGlobal* get_global_by_env_index(Context* ctx, @@ -264,11 +264,9 @@ static Result emit_drop_keep(Context* ctx, uint32_t drop, uint8_t keep) { static Result append_fixup(Context* ctx, Uint32VectorVector* fixups_vector, uint32_t index) { - if (index >= fixups_vector->size) - resize_uint32_vector_vector(fixups_vector, index + 1); - Uint32Vector* fixups = &fixups_vector->data[index]; - uint32_t offset = get_istream_offset(ctx); - append_uint32_value(fixups, &offset); + if (index >= fixups_vector->size()) + fixups_vector->resize(index + 1); + (*fixups_vector)[index].push_back(get_istream_offset(ctx)); return Result::Ok; } @@ -276,7 +274,7 @@ static Result emit_br_offset(Context* ctx, uint32_t depth, uint32_t offset) { if (offset == WABT_INVALID_OFFSET) { /* depth_fixups stores the depth counting up from zero, where zero is the * top-level function scope. */ - depth = ctx->label_stack.size - 1 - depth; + depth = ctx->label_stack.size() - 1 - depth; CHECK_RESULT(append_fixup(ctx, &ctx->depth_fixups, depth)); } CHECK_RESULT(emit_i32(ctx, offset)); @@ -289,12 +287,13 @@ static Result get_br_drop_keep_count(Context* ctx, uint32_t* out_keep_count) { TypeCheckerLabel* label; CHECK_RESULT(typechecker_get_label(&ctx->typechecker, depth, &label)); - *out_keep_count = label->label_type != LabelType::Loop ? label->sig.size : 0; + *out_keep_count = + label->label_type != LabelType::Loop ? label->sig.size() : 0; if (typechecker_is_unreachable(&ctx->typechecker)) { *out_drop_count = 0; } else { *out_drop_count = - (ctx->typechecker.type_stack.size - label->type_stack_limit) - + (ctx->typechecker.type_stack.size() - label->type_stack_limit) - *out_keep_count; } return Result::Ok; @@ -303,7 +302,7 @@ static Result get_br_drop_keep_count(Context* ctx, static Result get_return_drop_keep_count(Context* ctx, uint32_t* out_drop_count, uint32_t* out_keep_count) { - if (WABT_FAILED(get_br_drop_keep_count(ctx, ctx->label_stack.size - 1, + if (WABT_FAILED(get_br_drop_keep_count(ctx, ctx->label_stack.size() - 1, out_drop_count, out_keep_count))) { return Result::Error; } @@ -333,18 +332,16 @@ static Result emit_br_table_offset(Context* ctx, uint32_t depth) { static Result fixup_top_label(Context* ctx) { uint32_t offset = get_istream_offset(ctx); - uint32_t top = ctx->label_stack.size - 1; - if (top >= ctx->depth_fixups.size) { + uint32_t top = ctx->label_stack.size() - 1; + if (top >= ctx->depth_fixups.size()) { /* nothing to fixup */ return Result::Ok; } - Uint32Vector* fixups = &ctx->depth_fixups.data[top]; - for (uint32_t i = 0; i < fixups->size; ++i) - CHECK_RESULT(emit_i32_at(ctx, fixups->data[i], offset)); - /* reduce the size to 0 in case this gets reused. Keep the allocations for - * later use */ - fixups->size = 0; + Uint32Vector& fixups = ctx->depth_fixups[top]; + for (uint32_t fixup: fixups) + CHECK_RESULT(emit_i32_at(ctx, fixup, offset)); + fixups.clear(); return Result::Ok; } @@ -367,9 +364,9 @@ static bool on_error(BinaryReaderContext* ctx, const char* message) { static Result on_signature_count(uint32_t count, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - resize_uint32_vector(&ctx->sig_index_mapping, count); + ctx->sig_index_mapping.resize(count); for (uint32_t i = 0; i < count; ++i) - ctx->sig_index_mapping.data[i] = ctx->env->sigs.size() + i; + ctx->sig_index_mapping[i] = ctx->env->sigs.size() + i; ctx->env->sigs.resize(ctx->env->sigs.size() + count); return Result::Ok; } @@ -545,7 +542,7 @@ static Result on_import_func(uint32_t import_index, func_env_index = ctx->import_env_index; } - append_uint32_value(&ctx->func_index_mapping, &func_env_index); + ctx->func_index_mapping.push_back(func_env_index); ctx->num_func_imports++; return Result::Ok; } @@ -662,19 +659,17 @@ static Result on_import_global(uint32_t import_index, import->global.mutable_ = mutable_; global_env_index = ctx->import_env_index; } - append_uint32_value(&ctx->global_index_mapping, &global_env_index); + ctx->global_index_mapping.push_back(global_env_index); ctx->num_global_imports++; return Result::Ok; } static Result on_function_signatures_count(uint32_t count, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - size_t old_size = ctx->func_index_mapping.size; - resize_uint32_vector(&ctx->func_index_mapping, old_size + count); for (uint32_t i = 0; i < count; ++i) - ctx->func_index_mapping.data[old_size + i] = ctx->env->funcs.size() + i; + ctx->func_index_mapping.push_back(ctx->env->funcs.size() + i); ctx->env->funcs.reserve(ctx->env->funcs.size() + count); - resize_uint32_vector_vector(&ctx->func_fixups, count); + ctx->func_fixups.resize(count); return Result::Ok; } @@ -717,10 +712,8 @@ static Result on_memory(uint32_t index, static Result on_global_count(uint32_t count, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - size_t old_size = ctx->global_index_mapping.size; - resize_uint32_vector(&ctx->global_index_mapping, old_size + count); for (uint32_t i = 0; i < count; ++i) - ctx->global_index_mapping.data[old_size + i] = ctx->env->globals.size() + i; + ctx->global_index_mapping.push_back(ctx->env->globals.size() + i); ctx->env->globals.resize(ctx->env->globals.size() + count); return Result::Ok; } @@ -878,7 +871,7 @@ static Result on_elem_segment_function_index_check(uint32_t index, return Result::Error; } - uint32_t max_func_index = ctx->func_index_mapping.size; + uint32_t max_func_index = ctx->func_index_mapping.size(); if (func_index >= max_func_index) { print_error(ctx, "invalid func_index: %d (max %d)", func_index, max_func_index); @@ -939,21 +932,16 @@ static Result on_data_segment_data(uint32_t index, } static void push_label(Context* ctx, uint32_t offset, uint32_t fixup_offset) { - Label* label = append_label(&ctx->label_stack); - label->offset = offset; - label->fixup_offset = fixup_offset; + ctx->label_stack.emplace_back(offset, fixup_offset); } static void pop_label(Context* ctx) { - ctx->label_stack.size--; + ctx->label_stack.pop_back(); /* reduce the depth_fixups stack as well, but it may be smaller than * label_stack so only do it conditionally. */ - if (ctx->depth_fixups.size > ctx->label_stack.size) { - uint32_t from = ctx->label_stack.size; - uint32_t to = ctx->depth_fixups.size; - for (uint32_t i = from; i < to; ++i) - destroy_uint32_vector(&ctx->depth_fixups.data[i]); - ctx->depth_fixups.size = ctx->label_stack.size; + if (ctx->depth_fixups.size() > ctx->label_stack.size()) { + ctx->depth_fixups.erase(ctx->depth_fixups.begin() + ctx->label_stack.size(), + ctx->depth_fixups.end()); } } @@ -982,21 +970,21 @@ static Result begin_function_body(BinaryReaderContext* context, func->local_count = 0; ctx->current_func = func; - ctx->depth_fixups.size = 0; - ctx->label_stack.size = 0; + ctx->depth_fixups.clear(); + ctx->label_stack.clear(); /* fixup function references */ uint32_t defined_index = translate_module_func_index_to_defined(ctx, index); - Uint32Vector* fixups = &ctx->func_fixups.data[defined_index]; - for (uint32_t i = 0; i < fixups->size; ++i) - CHECK_RESULT(emit_i32_at(ctx, fixups->data[i], func->offset)); + Uint32Vector& fixups = ctx->func_fixups[defined_index]; + for (uint32_t fixup: fixups) + CHECK_RESULT(emit_i32_at(ctx, fixup, func->offset)); /* append param types */ - for (uint32_t i = 0; i < sig->param_types.size(); ++i) - func->param_and_local_types.push_back(sig->param_types[i]); + for (Type param_type: sig->param_types) + func->param_and_local_types.push_back(param_type); - INTERPRETER_TYPE_VECTOR_TO_TYPE_VECTOR(result_types, sig->result_types); - CHECK_RESULT(typechecker_begin_function(&ctx->typechecker, &result_types)); + CHECK_RESULT( + typechecker_begin_function(&ctx->typechecker, &sig->result_types)); /* push implicit func label (equivalent to return) */ push_label(ctx, WABT_INVALID_OFFSET, WABT_INVALID_OFFSET); @@ -1078,9 +1066,7 @@ static Result on_block_expr(uint32_t num_types, Type* sig_types, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - TypeVector sig; - sig.size = num_types; - sig.data = sig_types; + TypeVector sig(sig_types, sig_types + num_types); CHECK_RESULT(typechecker_on_block(&ctx->typechecker, &sig)); push_label(ctx, WABT_INVALID_OFFSET, WABT_INVALID_OFFSET); return Result::Ok; @@ -1090,9 +1076,7 @@ static Result on_loop_expr(uint32_t num_types, Type* sig_types, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - TypeVector sig; - sig.size = num_types; - sig.data = sig_types; + TypeVector sig(sig_types, sig_types + num_types); CHECK_RESULT(typechecker_on_loop(&ctx->typechecker, &sig)); push_label(ctx, get_istream_offset(ctx), WABT_INVALID_OFFSET); return Result::Ok; @@ -1100,9 +1084,7 @@ static Result on_loop_expr(uint32_t num_types, static Result on_if_expr(uint32_t num_types, Type* sig_types, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - TypeVector sig; - sig.size = num_types; - sig.data = sig_types; + TypeVector sig(sig_types, sig_types + num_types); CHECK_RESULT(typechecker_on_if(&ctx->typechecker, &sig)); CHECK_RESULT(emit_opcode(ctx, InterpreterOpcode::BrUnless)); uint32_t fixup_offset = get_istream_offset(ctx); @@ -1192,10 +1174,8 @@ static Result on_call_expr(uint32_t func_index, void* user_data) { InterpreterFunc* func = get_func_by_module_index(ctx, func_index); InterpreterFuncSignature* sig = get_signature_by_env_index(ctx, func->sig_index); - INTERPRETER_TYPE_VECTOR_TO_TYPE_VECTOR(param_types, sig->param_types); - INTERPRETER_TYPE_VECTOR_TO_TYPE_VECTOR(result_types, sig->result_types); - CHECK_RESULT( - typechecker_on_call(&ctx->typechecker, ¶m_types, &result_types)); + CHECK_RESULT(typechecker_on_call(&ctx->typechecker, &sig->param_types, + &sig->result_types)); if (func->is_host) { CHECK_RESULT(emit_opcode(ctx, InterpreterOpcode::CallHost)); @@ -1215,10 +1195,8 @@ static Result on_call_indirect_expr(uint32_t sig_index, void* user_data) { return Result::Error; } InterpreterFuncSignature* sig = get_signature_by_module_index(ctx, sig_index); - INTERPRETER_TYPE_VECTOR_TO_TYPE_VECTOR(param_types, sig->param_types); - INTERPRETER_TYPE_VECTOR_TO_TYPE_VECTOR(result_types, sig->result_types); - CHECK_RESULT(typechecker_on_call_indirect(&ctx->typechecker, ¶m_types, - &result_types)); + CHECK_RESULT(typechecker_on_call_indirect( + &ctx->typechecker, &sig->param_types, &sig->result_types)); CHECK_RESULT(emit_opcode(ctx, InterpreterOpcode::CallIndirect)); CHECK_RESULT(emit_i32(ctx, ctx->module->table_index)); @@ -1292,7 +1270,7 @@ static Result on_set_global_expr(uint32_t global_index, void* user_data) { } static uint32_t translate_local_index(Context* ctx, uint32_t local_index) { - return ctx->typechecker.type_stack.size + + return ctx->typechecker.type_stack.size() + ctx->current_func->param_and_local_types.size() - local_index; } @@ -1406,16 +1384,6 @@ static Result on_unreachable_expr(void* user_data) { return Result::Ok; } -static void destroy_context(Context* ctx) { - 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); - destroy_uint32_vector(&ctx->sig_index_mapping); - destroy_uint32_vector(&ctx->func_index_mapping); - destroy_uint32_vector(&ctx->global_index_mapping); - destroy_typechecker(&ctx->typechecker); -} - Result read_binary_interpreter(InterpreterEnvironment* env, const void* data, size_t size, @@ -1538,7 +1506,6 @@ Result read_binary_interpreter(InterpreterEnvironment* env, reset_interpreter_environment_to_mark(env, mark); *out_module = nullptr; } - destroy_context(&ctx); return result; } diff --git a/src/binary-reader-linker.cc b/src/binary-reader-linker.cc index 5b3d36f8..026c2f9d 100644 --- a/src/binary-reader-linker.cc +++ b/src/binary-reader-linker.cc @@ -16,6 +16,8 @@ #include "binary-reader-linker.h" +#include <vector> + #include "binary-reader.h" #include "wasm-link.h" @@ -45,11 +47,10 @@ static Result on_reloc_count(uint32_t count, WABT_FATAL("relocation for custom sections not yet supported\n"); } - for (uint32_t i = 0; i < binary->sections.size; i++) { - Section* sec = &binary->sections.data[i]; - if (sec->section_code != section_code) + for (const std::unique_ptr<Section>& section : binary->sections) { + if (section->section_code != section_code) continue; - ctx->reloc_section = sec; + ctx->reloc_section = section.get(); return Result::Ok; } @@ -68,11 +69,7 @@ static Result on_reloc(RelocType type, WABT_FATAL("invalid relocation offset: %#x\n", offset); } - Reloc* reloc = append_reloc(&ctx->reloc_section->relocations); - reloc->type = type; - reloc->offset = offset; - reloc->index = index; - reloc->addend = addend; + ctx->reloc_section->relocations.emplace_back(type, offset, index, addend); return Result::Ok; } @@ -95,8 +92,8 @@ static Result on_import_func(uint32_t import_index, uint32_t sig_index, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - FunctionImport* import = - append_function_import(&ctx->binary->function_imports); + ctx->binary->function_imports.emplace_back(); + FunctionImport* import = &ctx->binary->function_imports.back(); import->name = field_name; import->sig_index = sig_index; import->active = true; @@ -112,7 +109,8 @@ static Result on_import_global(uint32_t import_index, bool mutable_, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - GlobalImport* import = append_global_import(&ctx->binary->global_imports); + ctx->binary->global_imports.emplace_back(); + GlobalImport* import = &ctx->binary->global_imports.back(); import->name = field_name; import->type = type; import->mutable_ = mutable_; @@ -125,7 +123,8 @@ static Result begin_section(BinaryReaderContext* ctx, uint32_t size) { Context* context = static_cast<Context*>(ctx->user_data); LinkerInputBinary* binary = context->binary; - Section* sec = append_section(&binary->sections); + Section* sec = new Section(); + binary->sections.emplace_back(sec); context->current_section = sec; sec->section_code = section_code; sec->size = size; @@ -186,10 +185,10 @@ static Result begin_custom_section(BinaryReaderContext* ctx, /* We don't currently support merging name sections unless they contain * a name for every function. */ - uint32_t total_funcs = binary->function_imports.size; - for (size_t i = 0; i < binary->sections.size; i++) { - if (binary->sections.data[i].section_code == BinarySection::Function) { - total_funcs += binary->sections.data[i].count; + uint32_t total_funcs = binary->function_imports.size(); + for (const std::unique_ptr<Section>& section : binary->sections) { + if (section->section_code == BinarySection::Function) { + total_funcs += section->count; break; } } @@ -242,8 +241,12 @@ static Result begin_data_segment(uint32_t index, void* user_data) { Context* ctx = static_cast<Context*>(user_data); Section* sec = ctx->current_section; - DataSegment* segment = append_data_segment(&sec->data_segments); - segment->memory_index = memory_index; + if (!sec->data_segments) { + sec->data_segments = new std::vector<DataSegment>(); + } + sec->data_segments->emplace_back(); + DataSegment& segment = sec->data_segments->back(); + segment.memory_index = memory_index; return Result::Ok; } @@ -254,8 +257,8 @@ static Result on_init_expr_i32_const_expr(uint32_t index, Section* sec = ctx->current_section; if (sec->section_code != BinarySection::Data) return Result::Ok; - DataSegment* segment = &sec->data_segments.data[sec->data_segments.size - 1]; - segment->offset = value; + DataSegment& segment = sec->data_segments->back(); + segment.offset = value; return Result::Ok; } @@ -265,9 +268,9 @@ static Result on_data_segment_data(uint32_t index, void* user_data) { Context* ctx = static_cast<Context*>(user_data); Section* sec = ctx->current_section; - DataSegment* segment = &sec->data_segments.data[sec->data_segments.size - 1]; - segment->data = static_cast<const uint8_t*>(src_data); - segment->size = size; + DataSegment& segment = sec->data_segments->back(); + segment.data = static_cast<const uint8_t*>(src_data); + segment.size = size; return Result::Ok; } @@ -277,7 +280,8 @@ static Result on_export(uint32_t index, StringSlice name, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - Export* export_ = append_export(&ctx->binary->exports); + ctx->binary->exports.emplace_back(); + Export* export_ = &ctx->binary->exports.back(); export_->name = name; export_->kind = kind; export_->index = item_index; @@ -288,12 +292,11 @@ static Result on_function_name(uint32_t index, StringSlice name, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - while (ctx->binary->debug_names.size < index) { - StringSlice empty = empty_string_slice(); - append_string_slice_value(&ctx->binary->debug_names, &empty); + while (ctx->binary->debug_names.size() < index) { + ctx->binary->debug_names.emplace_back(); } - if (ctx->binary->debug_names.size == index) { - append_string_slice_value(&ctx->binary->debug_names, &name); + if (ctx->binary->debug_names.size() == index) { + ctx->binary->debug_names.push_back(string_slice_to_string(name)); } return Result::Ok; } diff --git a/src/binary-reader-objdump.cc b/src/binary-reader-objdump.cc index 95130643..47f05770 100644 --- a/src/binary-reader-objdump.cc +++ b/src/binary-reader-objdump.cc @@ -21,16 +21,16 @@ #include <string.h> #include <stdio.h> +#include <vector> + #include "binary-reader.h" #include "literal.h" -#include "vector.h" namespace wabt { namespace { -typedef uint32_t Uint32; -WABT_DEFINE_VECTOR(uint32, Uint32); +typedef std::vector<uint32_t> Uint32Vector; struct Context { ObjdumpOptions* options; @@ -247,8 +247,8 @@ static void log_opcode(Context* ctx, ctx->last_opcode_end = ctx->current_opcode_offset + data_size; if (ctx->options->relocs) { - if (ctx->next_reloc < ctx->options->code_relocations.size) { - Reloc* reloc = &ctx->options->code_relocations.data[ctx->next_reloc]; + if (ctx->next_reloc < ctx->options->code_relocations.size()) { + Reloc* reloc = &ctx->options->code_relocations[ctx->next_reloc]; size_t code_start = ctx->section_starts[static_cast<size_t>(BinarySection::Code)]; size_t abs_offset = code_start + reloc->offset; @@ -414,11 +414,10 @@ static Result begin_function_body(BinaryReaderContext* context, Context* ctx = static_cast<Context*>(context->user_data); if (ctx->options->mode == ObjdumpMode::Disassemble) { - if (index < ctx->options->function_names.size && - !string_slice_is_empty(&ctx->options->function_names.data[index])) - printf("%06" PRIzx " <" PRIstringslice ">:\n", context->offset, - WABT_PRINTF_STRING_SLICE_ARG( - ctx->options->function_names.data[index])); + if (index < ctx->options->function_names.size() && + !ctx->options->function_names[index].empty()) + printf("%06" PRIzx " <%s>:\n", context->offset, + ctx->options->function_names[index].c_str()); else printf("%06" PRIzx " func[%d]:\n", context->offset, index); } @@ -602,12 +601,11 @@ static Result on_function_name(uint32_t index, print_details(ctx, " - func[%d] " PRIstringslice "\n", index, WABT_PRINTF_STRING_SLICE_ARG(name)); if (ctx->options->mode == ObjdumpMode::Prepass) { - while (ctx->options->function_names.size < index) { - StringSlice empty = empty_string_slice(); - append_string_slice_value(&ctx->options->function_names, &empty); + while (ctx->options->function_names.size() < index) { + ctx->options->function_names.emplace_back(); } - if (ctx->options->function_names.size == index) { - append_string_slice_value(&ctx->options->function_names, &name); + if (ctx->options->function_names.size() == index) { + ctx->options->function_names.push_back(string_slice_to_string(name)); } } return Result::Ok; @@ -647,12 +645,7 @@ Result on_reloc(RelocType type, get_reloc_type_name(type), index, addend, offset, total_offset); if (ctx->options->mode == ObjdumpMode::Prepass && ctx->reloc_section == BinarySection::Code) { - Reloc reloc; - reloc.offset = offset; - reloc.type = type; - reloc.index = index; - reloc.addend = addend; - append_reloc_value(&ctx->options->code_relocations, &reloc); + ctx->options->code_relocations.emplace_back(type, offset, index, addend); } return Result::Ok; } diff --git a/src/binary-reader-objdump.h b/src/binary-reader-objdump.h index e3880484..b2fb75b3 100644 --- a/src/binary-reader-objdump.h +++ b/src/binary-reader-objdump.h @@ -17,19 +17,17 @@ #ifndef WABT_BINARY_READER_OBJDUMP_H_ #define WABT_BINARY_READER_OBJDUMP_H_ +#include <string> +#include <vector> + #include "common.h" #include "stream.h" -#include "vector.h" namespace wabt { struct Module; struct ReadBinaryOptions; -WABT_DEFINE_VECTOR(reloc, Reloc); - -WABT_DEFINE_VECTOR(string_slice, StringSlice); - enum class ObjdumpMode { Prepass, Headers, @@ -50,8 +48,8 @@ struct ObjdumpOptions { const char* infile; const char* section_name; bool print_header; - StringSliceVector function_names; - RelocVector code_relocations; + std::vector<std::string> function_names; + std::vector<Reloc> code_relocations; }; Result read_binary_objdump(const uint8_t* data, diff --git a/src/binary-reader-opcnt.cc b/src/binary-reader-opcnt.cc index edf2f0b3..8e428e1f 100644 --- a/src/binary-reader-opcnt.cc +++ b/src/binary-reader-opcnt.cc @@ -35,49 +35,37 @@ struct Context { } // namespace -static Result add_int_counter_value(IntCounterVector* vec, - intmax_t value) { - for (size_t i = 0; i < vec->size; ++i) { - if (vec->data[i].value == value) { - ++vec->data[i].count; +static Result add_int_counter_value(IntCounterVector* vec, intmax_t value) { + for (IntCounter& counter : *vec) { + if (counter.value == value) { + ++counter.count; return Result::Ok; } } - IntCounter counter; - counter.value = value; - counter.count = 1; - append_int_counter_value(vec, &counter); + vec->emplace_back(value, 1); return Result::Ok; } static Result add_int_pair_counter_value(IntPairCounterVector* vec, - intmax_t first, - intmax_t second) { - for (size_t i = 0; i < vec->size; ++i) { - if (vec->data[i].first == first && vec->data[i].second == second) { - ++vec->data[i].count; + intmax_t first, + intmax_t second) { + for (IntPairCounter& pair : *vec) { + if (pair.first == first && pair.second == second) { + ++pair.count; return Result::Ok; } } - IntPairCounter counter; - counter.first = first; - counter.second = second; - counter.count = 1; - append_int_pair_counter_value(vec, &counter); + vec->emplace_back(first, second, 1); return Result::Ok; } -static Result on_opcode(BinaryReaderContext* context, - Opcode opcode) { +static Result on_opcode(BinaryReaderContext* context, Opcode opcode) { Context* ctx = static_cast<Context*>(context->user_data); - IntCounterVector* opcnt_vec = &ctx->opcnt_data->opcode_vec; - while (static_cast<size_t>(opcode) >= opcnt_vec->size) { - IntCounter Counter; - Counter.value = opcnt_vec->size; - Counter.count = 0; - append_int_counter_value(opcnt_vec, &Counter); + IntCounterVector& opcnt_vec = ctx->opcnt_data->opcode_vec; + while (static_cast<size_t>(opcode) >= opcnt_vec.size()) { + opcnt_vec.emplace_back(opcnt_vec.size(), 0); } - ++opcnt_vec->data[static_cast<size_t>(opcode)].count; + ++opcnt_vec[static_cast<size_t>(opcode)].count; return Result::Ok; } @@ -124,17 +112,6 @@ static Result on_store_expr(Opcode opcode, return Result::Ok; } -void init_opcnt_data(OpcntData* data) { - WABT_ZERO_MEMORY(*data); -} - -void destroy_opcnt_data(OpcntData* data) { - destroy_int_counter_vector(&data->opcode_vec); - destroy_int_counter_vector(&data->i32_const_vec); - destroy_int_counter_vector(&data->get_local_vec); - destroy_int_pair_counter_vector(&data->i32_load_vec); -} - Result read_binary_opcnt(const void* data, size_t size, const struct ReadBinaryOptions* options, diff --git a/src/binary-reader-opcnt.h b/src/binary-reader-opcnt.h index 4c520ae5..5404622a 100644 --- a/src/binary-reader-opcnt.h +++ b/src/binary-reader-opcnt.h @@ -18,7 +18,8 @@ #define WABT_BINARY_READER_OPCNT_H_ #include "common.h" -#include "vector.h" + +#include <vector> namespace wabt { @@ -26,19 +27,22 @@ struct Module; struct ReadBinaryOptions; struct IntCounter { + IntCounter(intmax_t value, size_t count) : value(value), count(count) {} + intmax_t value; size_t count; }; - -WABT_DEFINE_VECTOR(int_counter, IntCounter) +typedef std::vector<IntCounter> IntCounterVector; struct IntPairCounter { + IntPairCounter(intmax_t first, intmax_t second, size_t count) + : first(first), second(second), count(count) {} + intmax_t first; intmax_t second; size_t count; }; - -WABT_DEFINE_VECTOR(int_pair_counter, IntPairCounter); +typedef std::vector<IntPairCounter> IntPairCounterVector; struct OpcntData { IntCounterVector opcode_vec; diff --git a/src/binary-reader.cc b/src/binary-reader.cc index 27c54157..f36ab0b8 100644 --- a/src/binary-reader.cc +++ b/src/binary-reader.cc @@ -24,10 +24,11 @@ #include <stdio.h> #include <string.h> +#include <vector> + #include "binary.h" #include "config.h" #include "stream.h" -#include "vector.h" #if HAVE_ALLOCA #include <alloca.h> @@ -42,10 +43,6 @@ namespace wabt { namespace { -typedef uint32_t Uint32; -WABT_DEFINE_VECTOR(type, Type) -WABT_DEFINE_VECTOR(uint32, Uint32); - #define CALLBACK_CTX(member, ...) \ RAISE_ERROR_UNLESS( \ WABT_SUCCEEDED( \ @@ -109,29 +106,29 @@ WABT_DEFINE_VECTOR(uint32, Uint32); RAISE_ERROR(__VA_ARGS__); struct Context { - const uint8_t* data; - size_t data_size; - size_t offset; - size_t read_end; /* Either the section end or data_size. */ + const uint8_t* data = nullptr; + size_t data_size = 0; + size_t offset = 0; + size_t read_end = 0; /* Either the section end or data_size. */ BinaryReaderContext user_ctx; - BinaryReader* reader; + BinaryReader* reader = nullptr; jmp_buf error_jmp_buf; TypeVector param_types; - Uint32Vector target_depths; - const ReadBinaryOptions* options; - BinarySection last_known_section; - uint32_t num_signatures; - uint32_t num_imports; - uint32_t num_func_imports; - uint32_t num_table_imports; - uint32_t num_memory_imports; - uint32_t num_global_imports; - uint32_t num_function_signatures; - uint32_t num_tables; - uint32_t num_memories; - uint32_t num_globals; - uint32_t num_exports; - uint32_t num_function_bodies; + std::vector<uint32_t> target_depths; + const ReadBinaryOptions* options = nullptr; + BinarySection last_known_section = BinarySection::Invalid; + uint32_t num_signatures = 0; + uint32_t num_imports = 0; + uint32_t num_func_imports = 0; + uint32_t num_table_imports = 0; + uint32_t num_memory_imports = 0; + uint32_t num_global_imports = 0; + uint32_t num_function_signatures = 0; + uint32_t num_tables = 0; + uint32_t num_memories = 0; + uint32_t num_globals = 0; + uint32_t num_exports = 0; + uint32_t num_function_bodies = 0; }; struct LoggingContext { @@ -434,11 +431,6 @@ static uint32_t num_total_globals(Context* ctx) { return ctx->num_global_imports + ctx->num_globals; } -static void destroy_context(Context* ctx) { - destroy_type_vector(&ctx->param_types); - destroy_uint32_vector(&ctx->target_depths); -} - /* Logging */ static void indent(LoggingContext* ctx) { @@ -1245,22 +1237,22 @@ static void read_function_body(Context* ctx, uint32_t end_offset) { case Opcode::BrTable: { uint32_t num_targets; in_u32_leb128(ctx, &num_targets, "br_table target count"); - if (num_targets > ctx->target_depths.capacity) { - reserve_uint32s(&ctx->target_depths, num_targets); - ctx->target_depths.size = num_targets; - } + ctx->target_depths.resize(num_targets); for (uint32_t i = 0; i < num_targets; ++i) { uint32_t target_depth; in_u32_leb128(ctx, &target_depth, "br_table target depth"); - ctx->target_depths.data[i] = target_depth; + ctx->target_depths[i] = target_depth; } uint32_t default_target_depth; in_u32_leb128(ctx, &default_target_depth, "br_table default target depth"); - CALLBACK_CTX(on_br_table_expr, num_targets, ctx->target_depths.data, + uint32_t* target_depths = + num_targets ? ctx->target_depths.data() : nullptr; + + CALLBACK_CTX(on_br_table_expr, num_targets, target_depths, default_target_depth); break; } @@ -1713,8 +1705,7 @@ static void read_type_section(Context* ctx, uint32_t section_size) { uint32_t num_params; in_u32_leb128(ctx, &num_params, "function param count"); - if (num_params > ctx->param_types.capacity) - reserve_types(&ctx->param_types, num_params); + ctx->param_types.resize(num_params); for (uint32_t j = 0; j < num_params; ++j) { Type param_type; @@ -1722,7 +1713,7 @@ static void read_type_section(Context* ctx, uint32_t section_size) { RAISE_ERROR_UNLESS(is_concrete_type(param_type), "expected valid param type (got %d)", static_cast<int>(param_type)); - ctx->param_types.data[j] = param_type; + ctx->param_types[j] = param_type; } uint32_t num_results; @@ -1737,7 +1728,9 @@ static void read_type_section(Context* ctx, uint32_t section_size) { static_cast<int>(result_type)); } - CALLBACK(on_signature, i, num_params, ctx->param_types.data, num_results, + Type* param_types = num_params ? ctx->param_types.data() : nullptr; + + CALLBACK(on_signature, i, num_params, param_types, num_results, &result_type); } CALLBACK_CTX0(end_signature_section); @@ -2230,7 +2223,6 @@ Result read_binary(const void* data, logging_on_init_expr_i64_const_expr; Context context; - WABT_ZERO_MEMORY(context); /* all the macros assume a Context* named ctx */ Context* ctx = &context; ctx->data = static_cast<const uint8_t*>(data); @@ -2240,13 +2232,9 @@ Result read_binary(const void* data, ctx->last_known_section = BinarySection::Invalid; if (setjmp(ctx->error_jmp_buf) == 1) { - destroy_context(ctx); return Result::Error; } - reserve_types(&ctx->param_types, INITIAL_PARAM_TYPES_CAPACITY); - reserve_uint32s(&ctx->target_depths, INITIAL_BR_TABLE_TARGET_CAPACITY); - uint32_t magic; in_u32(ctx, &magic, "magic"); RAISE_ERROR_UNLESS(magic == WABT_BINARY_MAGIC, "bad magic value"); @@ -2259,7 +2247,6 @@ Result read_binary(const void* data, CALLBACK(begin_module, version); read_sections(ctx); CALLBACK0(end_module); - destroy_context(ctx); return Result::Ok; } diff --git a/src/binary-writer-spec.cc b/src/binary-writer-spec.cc index 252ff99d..dac091a3 100644 --- a/src/binary-writer-spec.cc +++ b/src/binary-writer-spec.cc @@ -135,7 +135,7 @@ static void write_escaped_string_slice(Context* ctx, StringSlice ss) { write_char(&ctx->json_stream, '"'); } -static void write_command_type(Context* ctx, const Command* command) { +static void write_command_type(Context* ctx, const Command& command) { static const char* s_command_names[] = { "module", "action", "register", "assert_malformed", "assert_invalid", nullptr, /* ASSERT_INVALID_NON_BINARY, this command will never be @@ -146,8 +146,8 @@ static void write_command_type(Context* ctx, const Command* command) { WABT_STATIC_ASSERT(WABT_ARRAY_SIZE(s_command_names) == kCommandTypeCount); write_key(ctx, "type"); - assert(s_command_names[static_cast<size_t>(command->type)]); - write_string(ctx, s_command_names[static_cast<size_t>(command->type)]); + assert(s_command_names[static_cast<size_t>(command.type)]); + write_string(ctx, s_command_names[static_cast<size_t>(command.type)]); } static void write_location(Context* ctx, const Location* loc) { @@ -215,12 +215,12 @@ static void write_const(Context* ctx, const Const* const_) { writef(&ctx->json_stream, "}"); } -static void write_const_vector(Context* ctx, const ConstVector* consts) { +static void write_const_vector(Context* ctx, const ConstVector& consts) { writef(&ctx->json_stream, "["); - for (size_t i = 0; i < consts->size; ++i) { - const Const* const_ = &consts->data[i]; + for (size_t i = 0; i < consts.size(); ++i) { + const Const* const_ = &consts[i]; write_const(ctx, const_); - if (i != consts->size - 1) + if (i != consts.size() - 1) write_separator(ctx); } writef(&ctx->json_stream, "]"); @@ -244,13 +244,13 @@ static void write_action(Context* ctx, const Action* action) { } if (action->type == ActionType::Invoke) { write_key(ctx, "field"); - write_escaped_string_slice(ctx, action->invoke.name); + write_escaped_string_slice(ctx, action->name); write_separator(ctx); write_key(ctx, "args"); - write_const_vector(ctx, &action->invoke.args); + write_const_vector(ctx, action->invoke->args); } else { write_key(ctx, "field"); - write_escaped_string_slice(ctx, action->get.name); + write_escaped_string_slice(ctx, action->name); } writef(&ctx->json_stream, "}"); } @@ -263,7 +263,7 @@ static void write_action_result_type(Context* ctx, writef(&ctx->json_stream, "["); switch (action->type) { case ActionType::Invoke: { - export_ = get_export_by_name(module, &action->invoke.name); + export_ = get_export_by_name(module, &action->name); assert(export_->kind == ExternalKind::Func); Func* func = get_func_by_var(module, &export_->var); size_t num_results = get_num_results(func); @@ -273,7 +273,7 @@ static void write_action_result_type(Context* ctx, } case ActionType::Get: { - export_ = get_export_by_name(module, &action->get.name); + export_ = get_export_by_name(module, &action->name); assert(export_->kind == ExternalKind::Global); Global* global = get_global_by_var(module, &export_->var); write_type_object(ctx, global->type); @@ -335,10 +335,10 @@ static void write_commands(Context* ctx, Script* script) { write_escaped_string_slice(ctx, ctx->source_filename); writef(&ctx->json_stream, ",\n \"commands\": [\n"); int last_module_index = -1; - for (size_t i = 0; i < script->commands.size; ++i) { - Command* command = &script->commands.data[i]; + for (size_t i = 0; i < script->commands.size(); ++i) { + const Command& command = *script->commands[i].get(); - if (command->type == CommandType::AssertInvalidNonBinary) + if (command.type == CommandType::AssertInvalidNonBinary) continue; if (i != 0) @@ -349,9 +349,9 @@ static void write_commands(Context* ctx, Script* script) { write_command_type(ctx, command); write_separator(ctx); - switch (command->type) { + switch (command.type) { case CommandType::Module: { - Module* module = command->module; + Module* module = command.module; char* filename = get_module_filename(ctx); write_location(ctx, &module->loc); write_separator(ctx); @@ -370,84 +370,84 @@ static void write_commands(Context* ctx, Script* script) { } case CommandType::Action: - write_location(ctx, &command->action.loc); + write_location(ctx, &command.action->loc); write_separator(ctx); - write_action(ctx, &command->action); + write_action(ctx, command.action); break; case CommandType::Register: - write_location(ctx, &command->register_.var.loc); + write_location(ctx, &command.register_.var.loc); write_separator(ctx); - if (command->register_.var.type == VarType::Name) { + if (command.register_.var.type == VarType::Name) { write_key(ctx, "name"); - write_var(ctx, &command->register_.var); + write_var(ctx, &command.register_.var); write_separator(ctx); } else { /* If we're not registering by name, then we should only be * registering the last module. */ WABT_USE(last_module_index); - assert(command->register_.var.index == last_module_index); + assert(command.register_.var.index == last_module_index); } write_key(ctx, "as"); - write_escaped_string_slice(ctx, command->register_.module_name); + write_escaped_string_slice(ctx, command.register_.module_name); break; case CommandType::AssertMalformed: - write_invalid_module(ctx, &command->assert_malformed.module, - command->assert_malformed.text); + write_invalid_module(ctx, command.assert_malformed.module, + command.assert_malformed.text); ctx->num_modules++; break; case CommandType::AssertInvalid: - write_invalid_module(ctx, &command->assert_invalid.module, - command->assert_invalid.text); + write_invalid_module(ctx, command.assert_invalid.module, + command.assert_invalid.text); ctx->num_modules++; break; case CommandType::AssertUnlinkable: - write_invalid_module(ctx, &command->assert_unlinkable.module, - command->assert_unlinkable.text); + write_invalid_module(ctx, command.assert_unlinkable.module, + command.assert_unlinkable.text); ctx->num_modules++; break; case CommandType::AssertUninstantiable: - write_invalid_module(ctx, &command->assert_uninstantiable.module, - command->assert_uninstantiable.text); + write_invalid_module(ctx, command.assert_uninstantiable.module, + command.assert_uninstantiable.text); ctx->num_modules++; break; case CommandType::AssertReturn: - write_location(ctx, &command->assert_return.action.loc); + write_location(ctx, &command.assert_return.action->loc); write_separator(ctx); - write_action(ctx, &command->assert_return.action); + write_action(ctx, command.assert_return.action); write_separator(ctx); write_key(ctx, "expected"); - write_const_vector(ctx, &command->assert_return.expected); + write_const_vector(ctx, *command.assert_return.expected); break; case CommandType::AssertReturnNan: - write_location(ctx, &command->assert_return_nan.action.loc); + write_location(ctx, &command.assert_return_nan.action->loc); write_separator(ctx); - write_action(ctx, &command->assert_return_nan.action); + write_action(ctx, command.assert_return_nan.action); write_separator(ctx); write_key(ctx, "expected"); write_action_result_type(ctx, script, - &command->assert_return_nan.action); + command.assert_return_nan.action); break; case CommandType::AssertTrap: - write_location(ctx, &command->assert_trap.action.loc); + write_location(ctx, &command.assert_trap.action->loc); write_separator(ctx); - write_action(ctx, &command->assert_trap.action); + write_action(ctx, command.assert_trap.action); write_separator(ctx); write_key(ctx, "text"); - write_escaped_string_slice(ctx, command->assert_trap.text); + write_escaped_string_slice(ctx, command.assert_trap.text); break; case CommandType::AssertExhaustion: - write_location(ctx, &command->assert_trap.action.loc); + write_location(ctx, &command.assert_trap.action->loc); write_separator(ctx); - write_action(ctx, &command->assert_trap.action); + write_action(ctx, command.assert_trap.action); break; case CommandType::AssertInvalidNonBinary: diff --git a/src/binary-writer.cc b/src/binary-writer.cc index e5ab82b1..839752d7 100644 --- a/src/binary-writer.cc +++ b/src/binary-writer.cc @@ -24,6 +24,8 @@ #include <stdint.h> #include <stdio.h> +#include <vector> + #include "ast.h" #include "binary.h" #include "stream.h" @@ -44,39 +46,44 @@ static const size_t LEB_SECTION_SIZE_GUESS = 1; #define ALLOC_FAILURE \ fprintf(stderr, "%s:%d: allocation failed\n", __FILE__, __LINE__) -WABT_DEFINE_VECTOR(reloc, Reloc); - struct RelocSection { + RelocSection(const char* name, BinarySection code); + const char* name; BinarySection section_code; - RelocVector relocations; + std::vector<Reloc> relocations; }; -WABT_DEFINE_VECTOR(reloc_section, RelocSection); + +RelocSection::RelocSection(const char* name, BinarySection code) + : name(name), section_code(code) {} struct Context { + WABT_DISALLOW_COPY_AND_ASSIGN(Context); + Context(); + Stream stream; - Stream* log_stream; - const WriteBinaryOptions* options; + Stream* log_stream = nullptr; + const WriteBinaryOptions* options = nullptr; - RelocSectionVector reloc_sections; - RelocSection* current_reloc_section; + std::vector<RelocSection> reloc_sections; + RelocSection* current_reloc_section = nullptr; - size_t last_section_offset; - size_t last_section_leb_size_guess; - BinarySection last_section_type; - size_t last_section_payload_offset; + size_t last_section_offset = 0; + size_t last_section_leb_size_guess = 0; + BinarySection last_section_type = BinarySection::Invalid; + size_t last_section_payload_offset = 0; - size_t last_subsection_offset; - size_t last_subsection_leb_size_guess; - size_t last_subsection_payload_offset; + size_t last_subsection_offset = 0; + size_t last_subsection_leb_size_guess = 0; + size_t last_subsection_payload_offset = 0; }; -} // namespace - -void destroy_reloc_section(RelocSection* reloc_section) { - destroy_reloc_vector(&reloc_section->relocations); +Context::Context() { + WABT_ZERO_MEMORY(stream); } +} // namespace + static uint8_t log2_u32(uint32_t x) { uint8_t result = 0; while (x > 1) { @@ -252,11 +259,11 @@ void write_type(Stream* stream, Type type) { } static void write_inline_signature_type(Stream* stream, - const BlockSignature* sig) { - if (sig->size == 0) { + const BlockSignature& sig) { + if (sig.size() == 0) { write_type(stream, Type::Void); - } else if (sig->size == 1) { - write_type(stream, sig->data[0]); + } else if (sig.size() == 1) { + write_type(stream, sig[0]); } else { /* this is currently unrepresentable */ write_u8(stream, 0xff, "INVALID INLINE SIGNATURE"); @@ -338,17 +345,15 @@ static void add_reloc(Context* ctx, RelocType reloc_type, uint32_t index) { // Add a new reloc section if needed if (!ctx->current_reloc_section || ctx->current_reloc_section->section_code != ctx->last_section_type) { - ctx->current_reloc_section = append_reloc_section(&ctx->reloc_sections); - ctx->current_reloc_section->name = get_section_name(ctx->last_section_type); - ctx->current_reloc_section->section_code = ctx->last_section_type; + ctx->reloc_sections.emplace_back(get_section_name(ctx->last_section_type), + ctx->last_section_type); + ctx->current_reloc_section = &ctx->reloc_sections.back(); } // Add a new relocation to the curent reloc section - Reloc* r = append_reloc(&ctx->current_reloc_section->relocations); - r->type = reloc_type; - r->offset = ctx->stream.offset - ctx->last_section_payload_offset; - r->index = index; - r->addend = 0; + size_t offset = ctx->stream.offset - ctx->last_section_payload_offset; + ctx->current_reloc_section->relocations.emplace_back(reloc_type, offset, + index); } static void write_u32_leb128_with_reloc(Context* ctx, @@ -373,8 +378,8 @@ static void write_expr(Context* ctx, break; case ExprType::Block: write_opcode(&ctx->stream, Opcode::Block); - write_inline_signature_type(&ctx->stream, &expr->block.sig); - write_expr_list(ctx, module, func, expr->block.first); + write_inline_signature_type(&ctx->stream, expr->block->sig); + write_expr_list(ctx, module, func, expr->block->first); write_opcode(&ctx->stream, Opcode::End); break; case ExprType::Br: @@ -389,11 +394,11 @@ static void write_expr(Context* ctx, break; case ExprType::BrTable: { write_opcode(&ctx->stream, Opcode::BrTable); - write_u32_leb128(&ctx->stream, expr->br_table.targets.size, + write_u32_leb128(&ctx->stream, expr->br_table.targets->size(), "num targets"); uint32_t depth; - for (size_t i = 0; i < expr->br_table.targets.size; ++i) { - depth = get_label_var_depth(ctx, &expr->br_table.targets.data[i]); + for (const Var& var: *expr->br_table.targets) { + depth = get_label_var_depth(ctx, &var); write_u32_leb128(&ctx->stream, depth, "break depth"); } depth = get_label_var_depth(ctx, &expr->br_table.default_target); @@ -469,8 +474,8 @@ static void write_expr(Context* ctx, break; case ExprType::If: write_opcode(&ctx->stream, Opcode::If); - write_inline_signature_type(&ctx->stream, &expr->if_.true_.sig); - write_expr_list(ctx, module, func, expr->if_.true_.first); + write_inline_signature_type(&ctx->stream, expr->if_.true_->sig); + write_expr_list(ctx, module, func, expr->if_.true_->first); if (expr->if_.false_) { write_opcode(&ctx->stream, Opcode::Else); write_expr_list(ctx, module, func, expr->if_.false_); @@ -487,8 +492,8 @@ static void write_expr(Context* ctx, } case ExprType::Loop: write_opcode(&ctx->stream, Opcode::Loop); - write_inline_signature_type(&ctx->stream, &expr->loop.sig); - write_expr_list(ctx, module, func, expr->loop.first); + write_inline_signature_type(&ctx->stream, expr->loop->sig); + write_expr_list(ctx, module, func, expr->loop->first); write_opcode(&ctx->stream, Opcode::End); break; case ExprType::Nop: @@ -555,8 +560,8 @@ static void write_init_expr(Context* ctx, static void write_func_locals(Context* ctx, const Module* module, const Func* func, - const TypeVector* local_types) { - if (local_types->size == 0) { + const TypeVector& local_types) { + if (local_types.size() == 0) { write_u32_leb128(&ctx->stream, 0, "local decl count"); return; } @@ -564,8 +569,8 @@ static void write_func_locals(Context* ctx, uint32_t num_params = get_num_params(func); #define FIRST_LOCAL_INDEX (num_params) -#define LAST_LOCAL_INDEX (num_params + local_types->size) -#define GET_LOCAL_TYPE(x) (local_types->data[x - num_params]) +#define LAST_LOCAL_INDEX (num_params + local_types.size()) +#define GET_LOCAL_TYPE(x) (local_types[x - num_params]) /* loop through once to count the number of local declaration runs */ Type current_type = GET_LOCAL_TYPE(FIRST_LOCAL_INDEX); @@ -597,7 +602,7 @@ static void write_func_locals(Context* ctx, } static void write_func(Context* ctx, const Module* module, const Func* func) { - write_func_locals(ctx, module, func, &func->local_types); + write_func_locals(ctx, module, func, func->local_types); write_expr_list(ctx, module, func, func->first_expr); write_opcode(&ctx->stream, Opcode::End); } @@ -631,18 +636,18 @@ static void write_reloc_section(Context* ctx, RelocSection* reloc_section) { begin_custom_section(ctx, section_name, LEB_SECTION_SIZE_GUESS); write_u32_leb128_enum(&ctx->stream, reloc_section->section_code, "reloc section type"); - RelocVector* relocs = &reloc_section->relocations; - write_u32_leb128(&ctx->stream, relocs->size, "num relocs"); - - for (size_t i = 0; i < relocs->size; i++) { - write_u32_leb128_enum(&ctx->stream, relocs->data[i].type, "reloc type"); - write_u32_leb128(&ctx->stream, relocs->data[i].offset, "reloc offset"); - write_u32_leb128(&ctx->stream, relocs->data[i].index, "reloc index"); - switch (relocs->data[i].type) { + std::vector<Reloc>& relocs = reloc_section->relocations; + write_u32_leb128(&ctx->stream, relocs.size(), "num relocs"); + + for (const Reloc& reloc: relocs) { + write_u32_leb128_enum(&ctx->stream, reloc.type, "reloc type"); + write_u32_leb128(&ctx->stream, reloc.offset, "reloc offset"); + write_u32_leb128(&ctx->stream, reloc.index, "reloc index"); + switch (reloc.type) { case RelocType::MemoryAddressLEB: case RelocType::MemoryAddressSLEB: case RelocType::MemoryAddressI32: - write_u32_leb128(&ctx->stream, relocs->data[i].addend, "reloc addend"); + write_u32_leb128(&ctx->stream, reloc.addend, "reloc addend"); break; default: break; @@ -656,34 +661,34 @@ static Result write_module(Context* ctx, const Module* module) { write_u32(&ctx->stream, WABT_BINARY_MAGIC, "WASM_BINARY_MAGIC"); write_u32(&ctx->stream, WABT_BINARY_VERSION, "WASM_BINARY_VERSION"); - if (module->func_types.size) { + if (module->func_types.size()) { begin_known_section(ctx, BinarySection::Type, LEB_SECTION_SIZE_GUESS); - write_u32_leb128(&ctx->stream, module->func_types.size, "num types"); - for (size_t i = 0; i < module->func_types.size; ++i) { - const FuncType* func_type = module->func_types.data[i]; + write_u32_leb128(&ctx->stream, module->func_types.size(), "num types"); + for (size_t i = 0; i < module->func_types.size(); ++i) { + const FuncType* func_type = module->func_types[i]; const FuncSignature* sig = &func_type->sig; write_header(ctx, "type", i); write_type(&ctx->stream, Type::Func); - uint32_t num_params = sig->param_types.size; - uint32_t num_results = sig->result_types.size; + uint32_t num_params = sig->param_types.size(); + uint32_t num_results = sig->result_types.size(); write_u32_leb128(&ctx->stream, num_params, "num params"); for (size_t j = 0; j < num_params; ++j) - write_type(&ctx->stream, sig->param_types.data[j]); + write_type(&ctx->stream, sig->param_types[j]); write_u32_leb128(&ctx->stream, num_results, "num results"); for (size_t j = 0; j < num_results; ++j) - write_type(&ctx->stream, sig->result_types.data[j]); + write_type(&ctx->stream, sig->result_types[j]); } end_section(ctx); } - if (module->imports.size) { + if (module->imports.size()) { begin_known_section(ctx, BinarySection::Import, LEB_SECTION_SIZE_GUESS); - write_u32_leb128(&ctx->stream, module->imports.size, "num imports"); + write_u32_leb128(&ctx->stream, module->imports.size(), "num imports"); - for (size_t i = 0; i < module->imports.size; ++i) { - const Import* import = module->imports.data[i]; + for (size_t i = 0; i < module->imports.size(); ++i) { + const Import* import = module->imports[i]; write_header(ctx, "import header", i); write_str(&ctx->stream, import->module_name.start, import->module_name.length, PrintChars::Yes, @@ -699,27 +704,27 @@ static Result write_module(Context* ctx, const Module* module) { "import signature index"); break; case ExternalKind::Table: - write_table(ctx, &import->table); + write_table(ctx, import->table); break; case ExternalKind::Memory: - write_memory(ctx, &import->memory); + write_memory(ctx, import->memory); break; case ExternalKind::Global: - write_global_header(ctx, &import->global); + write_global_header(ctx, import->global); break; } } end_section(ctx); } - assert(module->funcs.size >= module->num_func_imports); - uint32_t num_funcs = module->funcs.size - module->num_func_imports; + assert(module->funcs.size() >= module->num_func_imports); + uint32_t num_funcs = module->funcs.size() - module->num_func_imports; if (num_funcs) { begin_known_section(ctx, BinarySection::Function, LEB_SECTION_SIZE_GUESS); write_u32_leb128(&ctx->stream, num_funcs, "num functions"); for (size_t i = 0; i < num_funcs; ++i) { - const Func* func = module->funcs.data[i + module->num_func_imports]; + const Func* func = module->funcs[i + module->num_func_imports]; char desc[100]; wabt_snprintf(desc, sizeof(desc), "function %" PRIzd " signature index", i); @@ -729,54 +734,51 @@ static Result write_module(Context* ctx, const Module* module) { end_section(ctx); } - assert(module->tables.size >= module->num_table_imports); - uint32_t num_tables = module->tables.size - module->num_table_imports; + assert(module->tables.size() >= module->num_table_imports); + uint32_t num_tables = module->tables.size() - module->num_table_imports; if (num_tables) { begin_known_section(ctx, BinarySection::Table, LEB_SECTION_SIZE_GUESS); write_u32_leb128(&ctx->stream, num_tables, "num tables"); for (size_t i = 0; i < num_tables; ++i) { - const Table* table = module->tables.data[i + module->num_table_imports]; + const Table* table = module->tables[i + module->num_table_imports]; write_header(ctx, "table", i); write_table(ctx, table); } end_section(ctx); } - assert(module->memories.size >= module->num_memory_imports); - uint32_t num_memories = module->memories.size - module->num_memory_imports; + assert(module->memories.size() >= module->num_memory_imports); + uint32_t num_memories = module->memories.size() - module->num_memory_imports; if (num_memories) { begin_known_section(ctx, BinarySection::Memory, LEB_SECTION_SIZE_GUESS); write_u32_leb128(&ctx->stream, num_memories, "num memories"); for (size_t i = 0; i < num_memories; ++i) { - const Memory* memory = - module->memories.data[i + module->num_memory_imports]; + const Memory* memory = module->memories[i + module->num_memory_imports]; write_header(ctx, "memory", i); write_memory(ctx, memory); } end_section(ctx); } - assert(module->globals.size >= module->num_global_imports); - uint32_t num_globals = module->globals.size - module->num_global_imports; + assert(module->globals.size() >= module->num_global_imports); + uint32_t num_globals = module->globals.size() - module->num_global_imports; if (num_globals) { begin_known_section(ctx, BinarySection::Global, LEB_SECTION_SIZE_GUESS); write_u32_leb128(&ctx->stream, num_globals, "num globals"); for (size_t i = 0; i < num_globals; ++i) { - const Global* global = - module->globals.data[i + module->num_global_imports]; + const Global* global = module->globals[i + module->num_global_imports]; write_global_header(ctx, global); write_init_expr(ctx, module, global->init_expr); } end_section(ctx); } - if (module->exports.size) { + if (module->exports.size()) { begin_known_section(ctx, BinarySection::Export, LEB_SECTION_SIZE_GUESS); - write_u32_leb128(&ctx->stream, module->exports.size, "num exports"); + write_u32_leb128(&ctx->stream, module->exports.size(), "num exports"); - for (size_t i = 0; i < module->exports.size; ++i) { - const Export* export_ = module->exports.data[i]; + for (const Export* export_ : module->exports) { write_str(&ctx->stream, export_->name.start, export_->name.length, PrintChars::Yes, "export name"); write_u8_enum(&ctx->stream, export_->kind, "export kind"); @@ -815,20 +817,20 @@ static Result write_module(Context* ctx, const Module* module) { } } - if (module->elem_segments.size) { + if (module->elem_segments.size()) { begin_known_section(ctx, BinarySection::Elem, LEB_SECTION_SIZE_GUESS); - write_u32_leb128(&ctx->stream, module->elem_segments.size, + write_u32_leb128(&ctx->stream, module->elem_segments.size(), "num elem segments"); - for (size_t i = 0; i < module->elem_segments.size; ++i) { - ElemSegment* segment = module->elem_segments.data[i]; + for (size_t i = 0; i < module->elem_segments.size(); ++i) { + ElemSegment* segment = module->elem_segments[i]; int table_index = get_table_index_by_var(module, &segment->table_var); write_header(ctx, "elem segment header", i); write_u32_leb128(&ctx->stream, table_index, "table index"); write_init_expr(ctx, module, segment->offset); - write_u32_leb128(&ctx->stream, segment->vars.size, + write_u32_leb128(&ctx->stream, segment->vars.size(), "num function indices"); - for (size_t j = 0; j < segment->vars.size; ++j) { - int index = get_func_index_by_var(module, &segment->vars.data[j]); + for (const Var& var: segment->vars) { + int index = get_func_index_by_var(module, &var); write_u32_leb128_with_reloc(ctx, index, "function index", RelocType::FuncIndexLEB); } @@ -842,7 +844,7 @@ static Result write_module(Context* ctx, const Module* module) { for (size_t i = 0; i < num_funcs; ++i) { write_header(ctx, "function body", i); - const Func* func = module->funcs.data[i + module->num_func_imports]; + const Func* func = module->funcs[i + module->num_func_imports]; /* TODO(binji): better guess of the size of the function body section */ const uint32_t leb_size_guess = 1; @@ -855,12 +857,12 @@ static Result write_module(Context* ctx, const Module* module) { end_section(ctx); } - if (module->data_segments.size) { + if (module->data_segments.size()) { begin_known_section(ctx, BinarySection::Data, LEB_SECTION_SIZE_GUESS); - write_u32_leb128(&ctx->stream, module->data_segments.size, + write_u32_leb128(&ctx->stream, module->data_segments.size(), "num data segments"); - for (size_t i = 0; i < module->data_segments.size; ++i) { - const DataSegment* segment = module->data_segments.data[i]; + for (size_t i = 0; i < module->data_segments.size(); ++i) { + const DataSegment* segment = module->data_segments[i]; write_header(ctx, "data segment header", i); int memory_index = get_memory_index_by_var(module, &segment->memory_var); write_u32_leb128(&ctx->stream, memory_index, "memory index"); @@ -880,9 +882,9 @@ static Result write_module(Context* ctx, const Module* module) { begin_custom_section(ctx, WABT_BINARY_SECTION_NAME, LEB_SECTION_SIZE_GUESS); write_u32_leb128(&ctx->stream, 1, "function name type"); begin_subsection(ctx, "function name subsection", LEB_SECTION_SIZE_GUESS); - write_u32_leb128(&ctx->stream, module->funcs.size, "num functions"); - for (size_t i = 0; i < module->funcs.size; ++i) { - const Func* func = module->funcs.data[i]; + write_u32_leb128(&ctx->stream, module->funcs.size(), "num functions"); + for (size_t i = 0; i < module->funcs.size(); ++i) { + const Func* func = module->funcs[i]; write_u32_leb128(&ctx->stream, i, "function index"); wabt_snprintf(desc, sizeof(desc), "func name %" PRIzd, i); write_str(&ctx->stream, func->name.start, func->name.length, @@ -893,11 +895,11 @@ static Result write_module(Context* ctx, const Module* module) { write_u32_leb128(&ctx->stream, 2, "local name type"); begin_subsection(ctx, "local name subsection", LEB_SECTION_SIZE_GUESS); - write_u32_leb128(&ctx->stream, module->funcs.size, "num functions"); - for (size_t i = 0; i < module->funcs.size; ++i) { - const Func* func = module->funcs.data[i]; + write_u32_leb128(&ctx->stream, module->funcs.size(), "num functions"); + for (size_t i = 0; i < module->funcs.size(); ++i) { + const Func* func = module->funcs[i]; uint32_t num_params = get_num_params(func); - uint32_t num_locals = func->local_types.size; + uint32_t num_locals = func->local_types.size(); uint32_t num_params_and_locals = get_num_params_and_locals(func); write_u32_leb128(&ctx->stream, i, "function index"); @@ -928,10 +930,9 @@ static Result write_module(Context* ctx, const Module* module) { } if (ctx->options->relocatable) { - for (size_t i = 0; i < ctx->reloc_sections.size; i++) { - write_reloc_section(ctx, &ctx->reloc_sections.data[i]); + for (size_t i = 0; i < ctx->reloc_sections.size(); i++) { + write_reloc_section(ctx, &ctx->reloc_sections[i]); } - WABT_DESTROY_VECTOR_AND_ELEMENTS(ctx->reloc_sections, reloc_section); } return ctx->stream.result; @@ -941,7 +942,6 @@ Result write_binary_module(Writer* writer, const Module* module, const WriteBinaryOptions* options) { Context ctx; - WABT_ZERO_MEMORY(ctx); ctx.options = options; ctx.log_stream = options->log_stream; init_stream(&ctx.stream, writer, ctx.log_stream); diff --git a/src/binding-hash.h b/src/binding-hash.h index 92d43d86..4aa8c168 100644 --- a/src/binding-hash.h +++ b/src/binding-hash.h @@ -17,12 +17,12 @@ #ifndef WABT_BINDING_HASH_H_ #define WABT_BINDING_HASH_H_ -#include "common.h" - #include <string> #include <vector> #include <unordered_map> +#include "common.h" + namespace wabt { struct Binding { diff --git a/src/common.cc b/src/common.cc index 411ed201..aca5b78d 100644 --- a/src/common.cc +++ b/src/common.cc @@ -31,6 +31,9 @@ namespace wabt { +Reloc::Reloc(RelocType type, size_t offset, uint32_t index, int32_t addend) + : type(type), offset(offset), index(index), addend(addend) {} + OpcodeInfo g_opcode_info[kOpcodeCount]; /* TODO(binji): It's annoying to have to have an initializer function, but it diff --git a/src/common.h b/src/common.h index a2bafda2..35e84355 100644 --- a/src/common.h +++ b/src/common.h @@ -27,6 +27,7 @@ #include <string> #include <type_traits> +#include <vector> #include "config.h" @@ -167,6 +168,7 @@ enum class Type { ___ = Void, /* convenient for the opcode table below */ Any = 0, /* Not actually specified, but useful for type-checking */ }; +typedef std::vector<Type> TypeVector; enum class RelocType { FuncIndexLEB = 0, /* e.g. immediate of call instruction */ @@ -184,6 +186,8 @@ enum class RelocType { static const int kRelocTypeCount = WABT_ENUM_COUNT(RelocType); struct Reloc { + Reloc(RelocType, size_t offset, uint32_t index, int32_t addend = 0); + RelocType type; size_t offset; uint32_t index; diff --git a/src/generate-names.cc b/src/generate-names.cc index 130fd855..e3ccfe6b 100644 --- a/src/generate-names.cc +++ b/src/generate-names.cc @@ -19,6 +19,9 @@ #include <assert.h> #include <stdio.h> +#include <string> +#include <vector> + #include "ast.h" #define CHECK_RESULT(expr) \ @@ -101,19 +104,19 @@ static void generate_and_bind_local_names( static Result begin_block_expr(Expr* expr, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - maybe_generate_name("$B", ctx->label_count++, &expr->block.label); + maybe_generate_name("$B", ctx->label_count++, &expr->block->label); return Result::Ok; } static Result begin_loop_expr(Expr* expr, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - maybe_generate_name("$L", ctx->label_count++, &expr->loop.label); + maybe_generate_name("$L", ctx->label_count++, &expr->loop->label); return Result::Ok; } static Result begin_if_expr(Expr* expr, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - maybe_generate_name("$L", ctx->label_count++, &expr->if_.true_.label); + maybe_generate_name("$L", ctx->label_count++, &expr->if_.true_->label); return Result::Ok; } @@ -165,16 +168,16 @@ static Result visit_memory(Context* ctx, } static Result visit_module(Context* ctx, Module* module) { - for (size_t i = 0; i < module->globals.size; ++i) - CHECK_RESULT(visit_global(ctx, i, module->globals.data[i])); - for (size_t i = 0; i < module->func_types.size; ++i) - CHECK_RESULT(visit_func_type(ctx, i, module->func_types.data[i])); - for (size_t i = 0; i < module->funcs.size; ++i) - CHECK_RESULT(visit_func(ctx, i, module->funcs.data[i])); - for (size_t i = 0; i < module->tables.size; ++i) - CHECK_RESULT(visit_table(ctx, i, module->tables.data[i])); - for (size_t i = 0; i < module->memories.size; ++i) - CHECK_RESULT(visit_memory(ctx, i, module->memories.data[i])); + for (size_t i = 0; i < module->globals.size(); ++i) + CHECK_RESULT(visit_global(ctx, i, module->globals[i])); + for (size_t i = 0; i < module->func_types.size(); ++i) + CHECK_RESULT(visit_func_type(ctx, i, module->func_types[i])); + for (size_t i = 0; i < module->funcs.size(); ++i) + CHECK_RESULT(visit_func(ctx, i, module->funcs[i])); + for (size_t i = 0; i < module->tables.size(); ++i) + CHECK_RESULT(visit_table(ctx, i, module->tables[i])); + for (size_t i = 0; i < module->memories.size(); ++i) + CHECK_RESULT(visit_memory(ctx, i, module->memories[i])); return Result::Ok; } diff --git a/src/interpreter.cc b/src/interpreter.cc index a8b7b054..f60854ea 100644 --- a/src/interpreter.cc +++ b/src/interpreter.cc @@ -20,6 +20,9 @@ #include <inttypes.h> #include <math.h> +#include <algorithm> +#include <vector> + #include "stream.h" #define INITIAL_ISTREAM_CAPACITY (64 * 1024) diff --git a/src/interpreter.h b/src/interpreter.h index 9f5d548b..94125005 100644 --- a/src/interpreter.h +++ b/src/interpreter.h @@ -24,8 +24,6 @@ #include "common.h" #include "binding-hash.h" -#include "type-vector.h" -#include "vector.h" #include "writer.h" namespace wabt { diff --git a/src/prebuilt/ast-lexer-gen.cc b/src/prebuilt/ast-lexer-gen.cc index 8c9b129c..6a4f3a08 100644 --- a/src/prebuilt/ast-lexer-gen.cc +++ b/src/prebuilt/ast-lexer-gen.cc @@ -25,7 +25,6 @@ #include "ast-parser.h" #include "ast-parser-lexer-shared.h" -#include "vector.h" /* must be included after so some typedefs will be defined */ #include "ast-parser-gen.hh" @@ -183,7 +182,7 @@ int ast_lexer_lex(WABT_AST_PARSER_STYPE* lval, for (;;) { lexer->token = lexer->cursor; -#line 187 "src/prebuilt/ast-lexer-gen.cc" +#line 186 "src/prebuilt/ast-lexer-gen.cc" { unsigned char yych; if (cond < 2) { @@ -222,34 +221,34 @@ YYCOND_BAD_TEXT: } } ++lexer->cursor; -#line 237 "src/ast-lexer.cc" +#line 236 "src/ast-lexer.cc" { ERROR("unexpected EOF"); RETURN(EOF); } -#line 228 "src/prebuilt/ast-lexer-gen.cc" +#line 227 "src/prebuilt/ast-lexer-gen.cc" yy5: ++lexer->cursor; yy6: -#line 238 "src/ast-lexer.cc" +#line 237 "src/ast-lexer.cc" { ERROR("illegal character in string"); continue; } -#line 235 "src/prebuilt/ast-lexer-gen.cc" +#line 234 "src/prebuilt/ast-lexer-gen.cc" yy7: ++lexer->cursor; BEGIN(YYCOND_i); -#line 231 "src/ast-lexer.cc" +#line 230 "src/ast-lexer.cc" { ERROR("newline in string"); NEWLINE; continue; } -#line 242 "src/prebuilt/ast-lexer-gen.cc" +#line 241 "src/prebuilt/ast-lexer-gen.cc" yy9: ++lexer->cursor; -#line 230 "src/ast-lexer.cc" +#line 229 "src/ast-lexer.cc" { continue; } -#line 247 "src/prebuilt/ast-lexer-gen.cc" +#line 246 "src/prebuilt/ast-lexer-gen.cc" yy11: ++lexer->cursor; BEGIN(YYCOND_i); -#line 236 "src/ast-lexer.cc" +#line 235 "src/ast-lexer.cc" { TEXT; RETURN(TEXT); } -#line 253 "src/prebuilt/ast-lexer-gen.cc" +#line 252 "src/prebuilt/ast-lexer-gen.cc" yy13: yych = *++lexer->cursor; if (yych <= '@') { @@ -283,11 +282,11 @@ yy13: yy14: ++lexer->cursor; yy15: -#line 233 "src/ast-lexer.cc" +#line 232 "src/ast-lexer.cc" { ERROR("bad escape \"%.*s\"", static_cast<int>(yyleng), yytext); continue; } -#line 291 "src/prebuilt/ast-lexer-gen.cc" +#line 290 "src/prebuilt/ast-lexer-gen.cc" yy16: ++lexer->cursor; if ((yych = *lexer->cursor) <= '@') { @@ -315,20 +314,20 @@ YYCOND_BLOCK_COMMENT: } yy19: ++lexer->cursor; -#line 465 "src/ast-lexer.cc" +#line 464 "src/ast-lexer.cc" { ERROR("unexpected EOF"); RETURN(EOF); } -#line 321 "src/prebuilt/ast-lexer-gen.cc" +#line 320 "src/prebuilt/ast-lexer-gen.cc" yy21: ++lexer->cursor; yy22: -#line 466 "src/ast-lexer.cc" +#line 465 "src/ast-lexer.cc" { continue; } -#line 327 "src/prebuilt/ast-lexer-gen.cc" +#line 326 "src/prebuilt/ast-lexer-gen.cc" yy23: ++lexer->cursor; -#line 464 "src/ast-lexer.cc" +#line 463 "src/ast-lexer.cc" { NEWLINE; continue; } -#line 332 "src/prebuilt/ast-lexer-gen.cc" +#line 331 "src/prebuilt/ast-lexer-gen.cc" yy25: yych = *++lexer->cursor; if (yych == ';') goto yy27; @@ -339,16 +338,16 @@ yy26: goto yy22; yy27: ++lexer->cursor; -#line 460 "src/ast-lexer.cc" +#line 459 "src/ast-lexer.cc" { COMMENT_NESTING++; continue; } -#line 345 "src/prebuilt/ast-lexer-gen.cc" +#line 344 "src/prebuilt/ast-lexer-gen.cc" yy29: ++lexer->cursor; -#line 461 "src/ast-lexer.cc" +#line 460 "src/ast-lexer.cc" { if (--COMMENT_NESTING == 0) BEGIN(YYCOND_INIT); continue; } -#line 352 "src/prebuilt/ast-lexer-gen.cc" +#line 351 "src/prebuilt/ast-lexer-gen.cc" /* *********************************** */ YYCOND_LINE_COMMENT: { @@ -393,9 +392,9 @@ YYCOND_LINE_COMMENT: } goto yy36; yy33: -#line 458 "src/ast-lexer.cc" +#line 457 "src/ast-lexer.cc" { continue; } -#line 399 "src/prebuilt/ast-lexer-gen.cc" +#line 398 "src/prebuilt/ast-lexer-gen.cc" yy34: ++lexer->cursor; if (lexer->limit <= lexer->cursor) FILL(1); @@ -407,9 +406,9 @@ yy34: yy36: ++lexer->cursor; BEGIN(YYCOND_i); -#line 457 "src/ast-lexer.cc" +#line 456 "src/ast-lexer.cc" { NEWLINE; continue; } -#line 413 "src/prebuilt/ast-lexer-gen.cc" +#line 412 "src/prebuilt/ast-lexer-gen.cc" } /* *********************************** */ YYCOND_i: @@ -551,15 +550,15 @@ YYCOND_i: } yy40: ++lexer->cursor; -#line 472 "src/ast-lexer.cc" +#line 471 "src/ast-lexer.cc" { RETURN(EOF); } -#line 557 "src/prebuilt/ast-lexer-gen.cc" +#line 556 "src/prebuilt/ast-lexer-gen.cc" yy42: ++lexer->cursor; yy43: -#line 473 "src/ast-lexer.cc" +#line 472 "src/ast-lexer.cc" { ERROR("unexpected char"); continue; } -#line 563 "src/prebuilt/ast-lexer-gen.cc" +#line 562 "src/prebuilt/ast-lexer-gen.cc" yy44: ++lexer->cursor; if (lexer->limit <= lexer->cursor) FILL(1); @@ -567,14 +566,14 @@ yy44: if (yybm[0+yych] & 8) { goto yy44; } -#line 468 "src/ast-lexer.cc" +#line 467 "src/ast-lexer.cc" { continue; } -#line 573 "src/prebuilt/ast-lexer-gen.cc" +#line 572 "src/prebuilt/ast-lexer-gen.cc" yy47: ++lexer->cursor; -#line 467 "src/ast-lexer.cc" +#line 466 "src/ast-lexer.cc" { NEWLINE; continue; } -#line 578 "src/prebuilt/ast-lexer-gen.cc" +#line 577 "src/prebuilt/ast-lexer-gen.cc" yy49: ++lexer->cursor; if (lexer->limit <= lexer->cursor) FILL(1); @@ -584,20 +583,20 @@ yy50: goto yy49; } yy51: -#line 469 "src/ast-lexer.cc" +#line 468 "src/ast-lexer.cc" { ERROR("unexpected token \"%.*s\"", static_cast<int>(yyleng), yytext); continue; } -#line 592 "src/prebuilt/ast-lexer-gen.cc" +#line 591 "src/prebuilt/ast-lexer-gen.cc" 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.cc" +#line 228 "src/ast-lexer.cc" { continue; } -#line 601 "src/prebuilt/ast-lexer-gen.cc" +#line 600 "src/prebuilt/ast-lexer-gen.cc" yy54: yych = *++lexer->cursor; if (yych <= ';') { @@ -637,14 +636,14 @@ yy54: yy55: ++lexer->cursor; if ((yych = *lexer->cursor) == ';') goto yy91; -#line 220 "src/ast-lexer.cc" +#line 219 "src/ast-lexer.cc" { RETURN(LPAR); } -#line 643 "src/prebuilt/ast-lexer-gen.cc" +#line 642 "src/prebuilt/ast-lexer-gen.cc" yy57: ++lexer->cursor; -#line 221 "src/ast-lexer.cc" +#line 220 "src/ast-lexer.cc" { RETURN(RPAR); } -#line 648 "src/prebuilt/ast-lexer-gen.cc" +#line 647 "src/prebuilt/ast-lexer-gen.cc" yy59: yych = *++lexer->cursor; if (yych <= 'h') { @@ -701,9 +700,9 @@ yy60: } } yy61: -#line 222 "src/ast-lexer.cc" +#line 221 "src/ast-lexer.cc" { LITERAL(Int); RETURN(NAT); } -#line 707 "src/prebuilt/ast-lexer-gen.cc" +#line 706 "src/prebuilt/ast-lexer-gen.cc" yy62: ++lexer->cursor; if ((lexer->limit - lexer->cursor) < 3) FILL(3); @@ -904,9 +903,9 @@ yy84: goto yy53; yy85: ++lexer->cursor; -#line 228 "src/ast-lexer.cc" +#line 227 "src/ast-lexer.cc" { TEXT; RETURN(TEXT); } -#line 910 "src/prebuilt/ast-lexer-gen.cc" +#line 909 "src/prebuilt/ast-lexer-gen.cc" yy87: ++lexer->cursor; if (lexer->limit <= lexer->cursor) FILL(1); @@ -969,15 +968,15 @@ yy88: } } yy90: -#line 454 "src/ast-lexer.cc" +#line 453 "src/ast-lexer.cc" { TEXT; RETURN(VAR); } -#line 975 "src/prebuilt/ast-lexer-gen.cc" +#line 974 "src/prebuilt/ast-lexer-gen.cc" yy91: ++lexer->cursor; BEGIN(YYCOND_BLOCK_COMMENT); -#line 459 "src/ast-lexer.cc" +#line 458 "src/ast-lexer.cc" { COMMENT_NESTING = 1; continue; } -#line 981 "src/prebuilt/ast-lexer-gen.cc" +#line 980 "src/prebuilt/ast-lexer-gen.cc" yy93: ++lexer->cursor; if ((yych = *lexer->cursor) <= 'D') { @@ -1019,9 +1018,9 @@ yy93: } } yy94: -#line 223 "src/ast-lexer.cc" +#line 222 "src/ast-lexer.cc" { LITERAL(Int); RETURN(INT); } -#line 1025 "src/prebuilt/ast-lexer-gen.cc" +#line 1024 "src/prebuilt/ast-lexer-gen.cc" yy95: ++lexer->cursor; if ((lexer->limit - lexer->cursor) < 3) FILL(3); @@ -1118,9 +1117,9 @@ yy99: } } yy101: -#line 224 "src/ast-lexer.cc" +#line 223 "src/ast-lexer.cc" { LITERAL(Float); RETURN(FLOAT); } -#line 1124 "src/prebuilt/ast-lexer-gen.cc" +#line 1123 "src/prebuilt/ast-lexer-gen.cc" yy102: yych = *++lexer->cursor; if (yych <= ',') { @@ -1141,9 +1140,9 @@ yy103: yy104: ++lexer->cursor; BEGIN(YYCOND_LINE_COMMENT); -#line 456 "src/ast-lexer.cc" +#line 455 "src/ast-lexer.cc" { continue; } -#line 1147 "src/prebuilt/ast-lexer-gen.cc" +#line 1146 "src/prebuilt/ast-lexer-gen.cc" yy106: yych = *++lexer->cursor; if (yych == 'i') goto yy156; @@ -1195,9 +1194,9 @@ yy110: } } yy111: -#line 253 "src/ast-lexer.cc" +#line 252 "src/ast-lexer.cc" { RETURN(BR); } -#line 1201 "src/prebuilt/ast-lexer-gen.cc" +#line 1200 "src/prebuilt/ast-lexer-gen.cc" yy112: yych = *++lexer->cursor; if (yych == 'l') goto yy161; @@ -1294,9 +1293,9 @@ yy127: } } yy128: -#line 248 "src/ast-lexer.cc" +#line 247 "src/ast-lexer.cc" { RETURN(IF); } -#line 1300 "src/prebuilt/ast-lexer-gen.cc" +#line 1299 "src/prebuilt/ast-lexer-gen.cc" yy129: yych = *++lexer->cursor; if (yych == 'p') goto yy184; @@ -1561,9 +1560,9 @@ yy167: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 260 "src/ast-lexer.cc" +#line 259 "src/ast-lexer.cc" { RETURN(END); } -#line 1567 "src/prebuilt/ast-lexer-gen.cc" +#line 1566 "src/prebuilt/ast-lexer-gen.cc" yy169: yych = *++lexer->cursor; if (yych == 'o') goto yy235; @@ -1602,9 +1601,9 @@ yy170: } } yy171: -#line 242 "src/ast-lexer.cc" +#line 241 "src/ast-lexer.cc" { TYPE(F32); RETURN(VALUE_TYPE); } -#line 1608 "src/prebuilt/ast-lexer-gen.cc" +#line 1607 "src/prebuilt/ast-lexer-gen.cc" yy172: ++lexer->cursor; if ((yych = *lexer->cursor) <= ':') { @@ -1639,9 +1638,9 @@ yy172: } } yy173: -#line 243 "src/ast-lexer.cc" +#line 242 "src/ast-lexer.cc" { TYPE(F64); RETURN(VALUE_TYPE); } -#line 1645 "src/prebuilt/ast-lexer-gen.cc" +#line 1644 "src/prebuilt/ast-lexer-gen.cc" yy174: yych = *++lexer->cursor; if (yych == 'c') goto yy238; @@ -1681,9 +1680,9 @@ yy175: } } yy176: -#line 444 "src/ast-lexer.cc" +#line 443 "src/ast-lexer.cc" { RETURN(GET); } -#line 1687 "src/prebuilt/ast-lexer-gen.cc" +#line 1686 "src/prebuilt/ast-lexer-gen.cc" yy177: yych = *++lexer->cursor; if (yych == 'b') goto yy241; @@ -1726,9 +1725,9 @@ yy179: } } yy180: -#line 240 "src/ast-lexer.cc" +#line 239 "src/ast-lexer.cc" { TYPE(I32); RETURN(VALUE_TYPE); } -#line 1732 "src/prebuilt/ast-lexer-gen.cc" +#line 1731 "src/prebuilt/ast-lexer-gen.cc" yy181: ++lexer->cursor; if ((yych = *lexer->cursor) <= ':') { @@ -1763,9 +1762,9 @@ yy181: } } yy182: -#line 241 "src/ast-lexer.cc" +#line 240 "src/ast-lexer.cc" { TYPE(I64); RETURN(VALUE_TYPE); } -#line 1769 "src/prebuilt/ast-lexer-gen.cc" +#line 1768 "src/prebuilt/ast-lexer-gen.cc" yy183: yych = *++lexer->cursor; if (yych == 'e') goto yy245; @@ -1809,9 +1808,9 @@ yy185: } } yy186: -#line 226 "src/ast-lexer.cc" +#line 225 "src/ast-lexer.cc" { LITERAL(Infinity); RETURN(FLOAT); } -#line 1815 "src/prebuilt/ast-lexer-gen.cc" +#line 1814 "src/prebuilt/ast-lexer-gen.cc" yy187: yych = *++lexer->cursor; if (yych == 'u') goto yy248; @@ -1841,9 +1840,9 @@ yy193: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 245 "src/ast-lexer.cc" +#line 244 "src/ast-lexer.cc" { RETURN(MUT); } -#line 1847 "src/prebuilt/ast-lexer-gen.cc" +#line 1846 "src/prebuilt/ast-lexer-gen.cc" yy195: ++lexer->cursor; if ((yych = *lexer->cursor) <= ';') { @@ -1878,17 +1877,17 @@ yy195: } } yy196: -#line 227 "src/ast-lexer.cc" +#line 226 "src/ast-lexer.cc" { LITERAL(Nan); RETURN(FLOAT); } -#line 1884 "src/prebuilt/ast-lexer-gen.cc" +#line 1883 "src/prebuilt/ast-lexer-gen.cc" yy197: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 246 "src/ast-lexer.cc" +#line 245 "src/ast-lexer.cc" { RETURN(NOP); } -#line 1892 "src/prebuilt/ast-lexer-gen.cc" +#line 1891 "src/prebuilt/ast-lexer-gen.cc" yy199: yych = *++lexer->cursor; if (yych == 's') goto yy256; @@ -2110,9 +2109,9 @@ yy224: } } yy225: -#line 256 "src/ast-lexer.cc" +#line 255 "src/ast-lexer.cc" { RETURN(CALL); } -#line 2116 "src/prebuilt/ast-lexer-gen.cc" +#line 2115 "src/prebuilt/ast-lexer-gen.cc" yy226: yych = *++lexer->cursor; if (yych == 'e') goto yy285; @@ -2122,33 +2121,33 @@ yy227: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 438 "src/ast-lexer.cc" +#line 437 "src/ast-lexer.cc" { RETURN(DATA); } -#line 2128 "src/prebuilt/ast-lexer-gen.cc" +#line 2127 "src/prebuilt/ast-lexer-gen.cc" yy229: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 259 "src/ast-lexer.cc" +#line 258 "src/ast-lexer.cc" { RETURN(DROP); } -#line 2136 "src/prebuilt/ast-lexer-gen.cc" +#line 2135 "src/prebuilt/ast-lexer-gen.cc" yy231: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 437 "src/ast-lexer.cc" +#line 436 "src/ast-lexer.cc" { RETURN(ELEM); } -#line 2144 "src/prebuilt/ast-lexer-gen.cc" +#line 2143 "src/prebuilt/ast-lexer-gen.cc" yy233: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 251 "src/ast-lexer.cc" +#line 250 "src/ast-lexer.cc" { RETURN(ELSE); } -#line 2152 "src/prebuilt/ast-lexer-gen.cc" +#line 2151 "src/prebuilt/ast-lexer-gen.cc" yy235: yych = *++lexer->cursor; if (yych == 'r') goto yy286; @@ -2193,9 +2192,9 @@ yy238: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 428 "src/ast-lexer.cc" +#line 427 "src/ast-lexer.cc" { RETURN(FUNC); } -#line 2199 "src/prebuilt/ast-lexer-gen.cc" +#line 2198 "src/prebuilt/ast-lexer-gen.cc" yy240: yych = *++lexer->cursor; if (yych == 'g') goto yy312; @@ -2277,9 +2276,9 @@ yy251: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 252 "src/ast-lexer.cc" +#line 251 "src/ast-lexer.cc" { RETURN(LOOP); } -#line 2283 "src/prebuilt/ast-lexer-gen.cc" +#line 2282 "src/prebuilt/ast-lexer-gen.cc" yy253: yych = *++lexer->cursor; if (yych == 'r') goto yy353; @@ -2342,17 +2341,17 @@ yy267: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 250 "src/ast-lexer.cc" +#line 249 "src/ast-lexer.cc" { RETURN(THEN); } -#line 2348 "src/prebuilt/ast-lexer-gen.cc" +#line 2347 "src/prebuilt/ast-lexer-gen.cc" yy269: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 427 "src/ast-lexer.cc" +#line 426 "src/ast-lexer.cc" { RETURN(TYPE); } -#line 2356 "src/prebuilt/ast-lexer-gen.cc" +#line 2355 "src/prebuilt/ast-lexer-gen.cc" yy271: yych = *++lexer->cursor; if (yych == 'a') goto yy371; @@ -2398,9 +2397,9 @@ yy273: } } yy275: -#line 225 "src/ast-lexer.cc" +#line 224 "src/ast-lexer.cc" { LITERAL(Hexfloat); RETURN(FLOAT); } -#line 2404 "src/prebuilt/ast-lexer-gen.cc" +#line 2403 "src/prebuilt/ast-lexer-gen.cc" yy276: yych = *++lexer->cursor; if (yych == '=') goto yy372; @@ -2418,17 +2417,17 @@ yy279: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 247 "src/ast-lexer.cc" +#line 246 "src/ast-lexer.cc" { RETURN(BLOCK); } -#line 2424 "src/prebuilt/ast-lexer-gen.cc" +#line 2423 "src/prebuilt/ast-lexer-gen.cc" yy281: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 254 "src/ast-lexer.cc" +#line 253 "src/ast-lexer.cc" { RETURN(BR_IF); } -#line 2432 "src/prebuilt/ast-lexer-gen.cc" +#line 2431 "src/prebuilt/ast-lexer-gen.cc" yy283: yych = *++lexer->cursor; if (yych == 'b') goto yy375; @@ -2780,9 +2779,9 @@ yy348: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 452 "src/ast-lexer.cc" +#line 451 "src/ast-lexer.cc" { RETURN(INPUT); } -#line 2786 "src/prebuilt/ast-lexer-gen.cc" +#line 2785 "src/prebuilt/ast-lexer-gen.cc" yy350: yych = *++lexer->cursor; if (yych == 'e') goto yy499; @@ -2792,9 +2791,9 @@ yy351: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 431 "src/ast-lexer.cc" +#line 430 "src/ast-lexer.cc" { RETURN(LOCAL); } -#line 2798 "src/prebuilt/ast-lexer-gen.cc" +#line 2797 "src/prebuilt/ast-lexer-gen.cc" yy353: yych = *++lexer->cursor; if (yych == 'y') goto yy501; @@ -2820,9 +2819,9 @@ yy358: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 429 "src/ast-lexer.cc" +#line 428 "src/ast-lexer.cc" { RETURN(PARAM); } -#line 2826 "src/prebuilt/ast-lexer-gen.cc" +#line 2825 "src/prebuilt/ast-lexer-gen.cc" yy360: yych = *++lexer->cursor; if (yych == 't') goto yy510; @@ -2852,17 +2851,17 @@ yy366: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 436 "src/ast-lexer.cc" +#line 435 "src/ast-lexer.cc" { RETURN(START); } -#line 2858 "src/prebuilt/ast-lexer-gen.cc" +#line 2857 "src/prebuilt/ast-lexer-gen.cc" yy368: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 434 "src/ast-lexer.cc" +#line 433 "src/ast-lexer.cc" { RETURN(TABLE); } -#line 2866 "src/prebuilt/ast-lexer-gen.cc" +#line 2865 "src/prebuilt/ast-lexer-gen.cc" yy370: yych = *++lexer->cursor; if (yych == 'o') goto yy519; @@ -2904,9 +2903,9 @@ yy378: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 441 "src/ast-lexer.cc" +#line 440 "src/ast-lexer.cc" { RETURN(EXPORT); } -#line 2910 "src/prebuilt/ast-lexer-gen.cc" +#line 2909 "src/prebuilt/ast-lexer-gen.cc" yy380: yych = *++lexer->cursor; if (yych == 's') goto yy532; @@ -2937,9 +2936,9 @@ yy386: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 382 "src/ast-lexer.cc" +#line 381 "src/ast-lexer.cc" { OPCODE(F32Eq); RETURN(COMPARE); } -#line 2943 "src/prebuilt/ast-lexer-gen.cc" +#line 2942 "src/prebuilt/ast-lexer-gen.cc" yy388: yych = *++lexer->cursor; if (yych == 'o') goto yy542; @@ -2949,25 +2948,25 @@ yy389: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 392 "src/ast-lexer.cc" +#line 391 "src/ast-lexer.cc" { OPCODE(F32Ge); RETURN(COMPARE); } -#line 2955 "src/prebuilt/ast-lexer-gen.cc" +#line 2954 "src/prebuilt/ast-lexer-gen.cc" yy391: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 390 "src/ast-lexer.cc" +#line 389 "src/ast-lexer.cc" { OPCODE(F32Gt); RETURN(COMPARE); } -#line 2963 "src/prebuilt/ast-lexer-gen.cc" +#line 2962 "src/prebuilt/ast-lexer-gen.cc" yy393: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 388 "src/ast-lexer.cc" +#line 387 "src/ast-lexer.cc" { OPCODE(F32Le); RETURN(COMPARE); } -#line 2971 "src/prebuilt/ast-lexer-gen.cc" +#line 2970 "src/prebuilt/ast-lexer-gen.cc" yy395: yych = *++lexer->cursor; if (yych == 'a') goto yy543; @@ -2977,9 +2976,9 @@ yy396: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 386 "src/ast-lexer.cc" +#line 385 "src/ast-lexer.cc" { OPCODE(F32Lt); RETURN(COMPARE); } -#line 2983 "src/prebuilt/ast-lexer-gen.cc" +#line 2982 "src/prebuilt/ast-lexer-gen.cc" yy398: yych = *++lexer->cursor; if (yych == 'x') goto yy544; @@ -3028,9 +3027,9 @@ yy401: } } yy402: -#line 384 "src/ast-lexer.cc" +#line 383 "src/ast-lexer.cc" { OPCODE(F32Ne); RETURN(COMPARE); } -#line 3034 "src/prebuilt/ast-lexer-gen.cc" +#line 3033 "src/prebuilt/ast-lexer-gen.cc" yy403: yych = *++lexer->cursor; if (yych == 'i') goto yy553; @@ -3077,9 +3076,9 @@ yy413: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 383 "src/ast-lexer.cc" +#line 382 "src/ast-lexer.cc" { OPCODE(F64Eq); RETURN(COMPARE); } -#line 3083 "src/prebuilt/ast-lexer-gen.cc" +#line 3082 "src/prebuilt/ast-lexer-gen.cc" yy415: yych = *++lexer->cursor; if (yych == 'o') goto yy568; @@ -3089,25 +3088,25 @@ yy416: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 393 "src/ast-lexer.cc" +#line 392 "src/ast-lexer.cc" { OPCODE(F64Ge); RETURN(COMPARE); } -#line 3095 "src/prebuilt/ast-lexer-gen.cc" +#line 3094 "src/prebuilt/ast-lexer-gen.cc" yy418: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 391 "src/ast-lexer.cc" +#line 390 "src/ast-lexer.cc" { OPCODE(F64Gt); RETURN(COMPARE); } -#line 3103 "src/prebuilt/ast-lexer-gen.cc" +#line 3102 "src/prebuilt/ast-lexer-gen.cc" yy420: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 389 "src/ast-lexer.cc" +#line 388 "src/ast-lexer.cc" { OPCODE(F64Le); RETURN(COMPARE); } -#line 3111 "src/prebuilt/ast-lexer-gen.cc" +#line 3110 "src/prebuilt/ast-lexer-gen.cc" yy422: yych = *++lexer->cursor; if (yych == 'a') goto yy569; @@ -3117,9 +3116,9 @@ yy423: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 387 "src/ast-lexer.cc" +#line 386 "src/ast-lexer.cc" { OPCODE(F64Lt); RETURN(COMPARE); } -#line 3123 "src/prebuilt/ast-lexer-gen.cc" +#line 3122 "src/prebuilt/ast-lexer-gen.cc" yy425: yych = *++lexer->cursor; if (yych == 'x') goto yy570; @@ -3168,9 +3167,9 @@ yy428: } } yy429: -#line 385 "src/ast-lexer.cc" +#line 384 "src/ast-lexer.cc" { OPCODE(F64Ne); RETURN(COMPARE); } -#line 3174 "src/prebuilt/ast-lexer-gen.cc" +#line 3173 "src/prebuilt/ast-lexer-gen.cc" yy430: yych = *++lexer->cursor; if (yych == 'o') goto yy579; @@ -3208,9 +3207,9 @@ yy438: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 432 "src/ast-lexer.cc" +#line 431 "src/ast-lexer.cc" { RETURN(GLOBAL); } -#line 3214 "src/prebuilt/ast-lexer-gen.cc" +#line 3213 "src/prebuilt/ast-lexer-gen.cc" yy440: yych = *++lexer->cursor; if (yych == 'e') goto yy588; @@ -3274,9 +3273,9 @@ yy447: } } yy448: -#line 362 "src/ast-lexer.cc" +#line 361 "src/ast-lexer.cc" { OPCODE(I32Eq); RETURN(COMPARE); } -#line 3280 "src/prebuilt/ast-lexer-gen.cc" +#line 3279 "src/prebuilt/ast-lexer-gen.cc" yy449: yych = *++lexer->cursor; if (yych == '_') goto yy601; @@ -3306,17 +3305,17 @@ yy455: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 364 "src/ast-lexer.cc" +#line 363 "src/ast-lexer.cc" { OPCODE(I32Ne); RETURN(COMPARE); } -#line 3312 "src/prebuilt/ast-lexer-gen.cc" +#line 3311 "src/prebuilt/ast-lexer-gen.cc" yy457: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 334 "src/ast-lexer.cc" +#line 333 "src/ast-lexer.cc" { OPCODE(I32Or); RETURN(BINARY); } -#line 3320 "src/prebuilt/ast-lexer-gen.cc" +#line 3319 "src/prebuilt/ast-lexer-gen.cc" yy459: yych = *++lexer->cursor; if (yych == 'p') goto yy608; @@ -3414,9 +3413,9 @@ yy474: } } yy475: -#line 363 "src/ast-lexer.cc" +#line 362 "src/ast-lexer.cc" { OPCODE(I64Eq); RETURN(COMPARE); } -#line 3420 "src/prebuilt/ast-lexer-gen.cc" +#line 3419 "src/prebuilt/ast-lexer-gen.cc" yy476: yych = *++lexer->cursor; if (yych == 't') goto yy634; @@ -3450,17 +3449,17 @@ yy483: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 365 "src/ast-lexer.cc" +#line 364 "src/ast-lexer.cc" { OPCODE(I64Ne); RETURN(COMPARE); } -#line 3456 "src/prebuilt/ast-lexer-gen.cc" +#line 3455 "src/prebuilt/ast-lexer-gen.cc" yy485: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 335 "src/ast-lexer.cc" +#line 334 "src/ast-lexer.cc" { OPCODE(I64Or); RETURN(BINARY); } -#line 3464 "src/prebuilt/ast-lexer-gen.cc" +#line 3463 "src/prebuilt/ast-lexer-gen.cc" yy487: yych = *++lexer->cursor; if (yych == 'p') goto yy642; @@ -3504,9 +3503,9 @@ yy496: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 440 "src/ast-lexer.cc" +#line 439 "src/ast-lexer.cc" { RETURN(IMPORT); } -#line 3510 "src/prebuilt/ast-lexer-gen.cc" +#line 3509 "src/prebuilt/ast-lexer-gen.cc" yy498: yych = *++lexer->cursor; if (yych == 't') goto yy657; @@ -3516,25 +3515,25 @@ yy499: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 443 "src/ast-lexer.cc" +#line 442 "src/ast-lexer.cc" { RETURN(INVOKE); } -#line 3522 "src/prebuilt/ast-lexer-gen.cc" +#line 3521 "src/prebuilt/ast-lexer-gen.cc" yy501: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 435 "src/ast-lexer.cc" +#line 434 "src/ast-lexer.cc" { RETURN(MEMORY); } -#line 3530 "src/prebuilt/ast-lexer-gen.cc" +#line 3529 "src/prebuilt/ast-lexer-gen.cc" yy503: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 433 "src/ast-lexer.cc" +#line 432 "src/ast-lexer.cc" { RETURN(MODULE); } -#line 3538 "src/prebuilt/ast-lexer-gen.cc" +#line 3537 "src/prebuilt/ast-lexer-gen.cc" yy505: yych = *++lexer->cursor; if (yych <= '@') { @@ -3581,17 +3580,17 @@ yy506: } } yy507: -#line 439 "src/ast-lexer.cc" +#line 438 "src/ast-lexer.cc" { RETURN(OFFSET); } -#line 3587 "src/prebuilt/ast-lexer-gen.cc" +#line 3586 "src/prebuilt/ast-lexer-gen.cc" yy508: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 453 "src/ast-lexer.cc" +#line 452 "src/ast-lexer.cc" { RETURN(OUTPUT); } -#line 3595 "src/prebuilt/ast-lexer-gen.cc" +#line 3594 "src/prebuilt/ast-lexer-gen.cc" yy510: yych = *++lexer->cursor; if (yych == 'e') goto yy661; @@ -3601,25 +3600,25 @@ yy511: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 430 "src/ast-lexer.cc" +#line 429 "src/ast-lexer.cc" { RETURN(RESULT); } -#line 3607 "src/prebuilt/ast-lexer-gen.cc" +#line 3606 "src/prebuilt/ast-lexer-gen.cc" yy513: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 261 "src/ast-lexer.cc" +#line 260 "src/ast-lexer.cc" { RETURN(RETURN); } -#line 3615 "src/prebuilt/ast-lexer-gen.cc" +#line 3614 "src/prebuilt/ast-lexer-gen.cc" yy515: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 423 "src/ast-lexer.cc" +#line 422 "src/ast-lexer.cc" { RETURN(SELECT); } -#line 3623 "src/prebuilt/ast-lexer-gen.cc" +#line 3622 "src/prebuilt/ast-lexer-gen.cc" yy517: yych = *++lexer->cursor; if (yych == 'o') goto yy662; @@ -3672,9 +3671,9 @@ yy521: } } yy522: -#line 291 "src/ast-lexer.cc" +#line 290 "src/ast-lexer.cc" { TEXT_AT(6); RETURN(ALIGN_EQ_NAT); } -#line 3678 "src/prebuilt/ast-lexer-gen.cc" +#line 3677 "src/prebuilt/ast-lexer-gen.cc" yy523: ++lexer->cursor; if (lexer->limit <= lexer->cursor) FILL(1); @@ -3723,9 +3722,9 @@ yy525: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 244 "src/ast-lexer.cc" +#line 243 "src/ast-lexer.cc" { RETURN(ANYFUNC); } -#line 3729 "src/prebuilt/ast-lexer-gen.cc" +#line 3728 "src/prebuilt/ast-lexer-gen.cc" yy527: yych = *++lexer->cursor; switch (yych) { @@ -3758,17 +3757,17 @@ yy532: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 306 "src/ast-lexer.cc" +#line 305 "src/ast-lexer.cc" { OPCODE(F32Abs); RETURN(UNARY); } -#line 3764 "src/prebuilt/ast-lexer-gen.cc" +#line 3763 "src/prebuilt/ast-lexer-gen.cc" yy534: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 348 "src/ast-lexer.cc" +#line 347 "src/ast-lexer.cc" { OPCODE(F32Add); RETURN(BINARY); } -#line 3772 "src/prebuilt/ast-lexer-gen.cc" +#line 3771 "src/prebuilt/ast-lexer-gen.cc" yy536: yych = *++lexer->cursor; if (yych == 'l') goto yy678; @@ -3791,9 +3790,9 @@ yy540: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 354 "src/ast-lexer.cc" +#line 353 "src/ast-lexer.cc" { OPCODE(F32Div); RETURN(BINARY); } -#line 3797 "src/prebuilt/ast-lexer-gen.cc" +#line 3796 "src/prebuilt/ast-lexer-gen.cc" yy542: yych = *++lexer->cursor; if (yych == 'o') goto yy684; @@ -3807,25 +3806,25 @@ yy544: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 358 "src/ast-lexer.cc" +#line 357 "src/ast-lexer.cc" { OPCODE(F32Max); RETURN(BINARY); } -#line 3813 "src/prebuilt/ast-lexer-gen.cc" +#line 3812 "src/prebuilt/ast-lexer-gen.cc" yy546: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 356 "src/ast-lexer.cc" +#line 355 "src/ast-lexer.cc" { OPCODE(F32Min); RETURN(BINARY); } -#line 3821 "src/prebuilt/ast-lexer-gen.cc" +#line 3820 "src/prebuilt/ast-lexer-gen.cc" yy548: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 352 "src/ast-lexer.cc" +#line 351 "src/ast-lexer.cc" { OPCODE(F32Mul); RETURN(BINARY); } -#line 3829 "src/prebuilt/ast-lexer-gen.cc" +#line 3828 "src/prebuilt/ast-lexer-gen.cc" yy550: yych = *++lexer->cursor; if (yych == 'r') goto yy687; @@ -3835,9 +3834,9 @@ yy551: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 304 "src/ast-lexer.cc" +#line 303 "src/ast-lexer.cc" { OPCODE(F32Neg); RETURN(UNARY); } -#line 3841 "src/prebuilt/ast-lexer-gen.cc" +#line 3840 "src/prebuilt/ast-lexer-gen.cc" yy553: yych = *++lexer->cursor; if (yych == 'n') goto yy688; @@ -3855,9 +3854,9 @@ yy556: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 350 "src/ast-lexer.cc" +#line 349 "src/ast-lexer.cc" { OPCODE(F32Sub); RETURN(BINARY); } -#line 3861 "src/prebuilt/ast-lexer-gen.cc" +#line 3860 "src/prebuilt/ast-lexer-gen.cc" yy558: yych = *++lexer->cursor; if (yych == 'n') goto yy692; @@ -3867,17 +3866,17 @@ yy559: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 307 "src/ast-lexer.cc" +#line 306 "src/ast-lexer.cc" { OPCODE(F64Abs); RETURN(UNARY); } -#line 3873 "src/prebuilt/ast-lexer-gen.cc" +#line 3872 "src/prebuilt/ast-lexer-gen.cc" yy561: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 349 "src/ast-lexer.cc" +#line 348 "src/ast-lexer.cc" { OPCODE(F64Add); RETURN(BINARY); } -#line 3881 "src/prebuilt/ast-lexer-gen.cc" +#line 3880 "src/prebuilt/ast-lexer-gen.cc" yy563: yych = *++lexer->cursor; if (yych == 'l') goto yy693; @@ -3896,9 +3895,9 @@ yy566: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 355 "src/ast-lexer.cc" +#line 354 "src/ast-lexer.cc" { OPCODE(F64Div); RETURN(BINARY); } -#line 3902 "src/prebuilt/ast-lexer-gen.cc" +#line 3901 "src/prebuilt/ast-lexer-gen.cc" yy568: yych = *++lexer->cursor; if (yych == 'o') goto yy698; @@ -3912,25 +3911,25 @@ yy570: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 359 "src/ast-lexer.cc" +#line 358 "src/ast-lexer.cc" { OPCODE(F64Max); RETURN(BINARY); } -#line 3918 "src/prebuilt/ast-lexer-gen.cc" +#line 3917 "src/prebuilt/ast-lexer-gen.cc" yy572: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 357 "src/ast-lexer.cc" +#line 356 "src/ast-lexer.cc" { OPCODE(F64Min); RETURN(BINARY); } -#line 3926 "src/prebuilt/ast-lexer-gen.cc" +#line 3925 "src/prebuilt/ast-lexer-gen.cc" yy574: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 353 "src/ast-lexer.cc" +#line 352 "src/ast-lexer.cc" { OPCODE(F64Mul); RETURN(BINARY); } -#line 3934 "src/prebuilt/ast-lexer-gen.cc" +#line 3933 "src/prebuilt/ast-lexer-gen.cc" yy576: yych = *++lexer->cursor; if (yych == 'r') goto yy701; @@ -3940,9 +3939,9 @@ yy577: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 305 "src/ast-lexer.cc" +#line 304 "src/ast-lexer.cc" { OPCODE(F64Neg); RETURN(UNARY); } -#line 3946 "src/prebuilt/ast-lexer-gen.cc" +#line 3945 "src/prebuilt/ast-lexer-gen.cc" yy579: yych = *++lexer->cursor; if (yych == 'm') goto yy702; @@ -3964,9 +3963,9 @@ yy583: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 351 "src/ast-lexer.cc" +#line 350 "src/ast-lexer.cc" { OPCODE(F64Sub); RETURN(BINARY); } -#line 3970 "src/prebuilt/ast-lexer-gen.cc" +#line 3969 "src/prebuilt/ast-lexer-gen.cc" yy585: yych = *++lexer->cursor; if (yych == 'n') goto yy707; @@ -3988,25 +3987,25 @@ yy589: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 318 "src/ast-lexer.cc" +#line 317 "src/ast-lexer.cc" { OPCODE(I32Add); RETURN(BINARY); } -#line 3994 "src/prebuilt/ast-lexer-gen.cc" +#line 3993 "src/prebuilt/ast-lexer-gen.cc" yy591: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 332 "src/ast-lexer.cc" +#line 331 "src/ast-lexer.cc" { OPCODE(I32And); RETURN(BINARY); } -#line 4002 "src/prebuilt/ast-lexer-gen.cc" +#line 4001 "src/prebuilt/ast-lexer-gen.cc" yy593: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 298 "src/ast-lexer.cc" +#line 297 "src/ast-lexer.cc" { OPCODE(I32Clz); RETURN(UNARY); } -#line 4010 "src/prebuilt/ast-lexer-gen.cc" +#line 4009 "src/prebuilt/ast-lexer-gen.cc" yy595: yych = *++lexer->cursor; if (yych == 's') goto yy711; @@ -4016,9 +4015,9 @@ yy596: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 300 "src/ast-lexer.cc" +#line 299 "src/ast-lexer.cc" { OPCODE(I32Ctz); RETURN(UNARY); } -#line 4022 "src/prebuilt/ast-lexer-gen.cc" +#line 4021 "src/prebuilt/ast-lexer-gen.cc" yy598: yych = *++lexer->cursor; if (yych == '_') goto yy712; @@ -4028,9 +4027,9 @@ yy599: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 296 "src/ast-lexer.cc" +#line 295 "src/ast-lexer.cc" { OPCODE(I32Eqz); RETURN(CONVERT); } -#line 4034 "src/prebuilt/ast-lexer-gen.cc" +#line 4033 "src/prebuilt/ast-lexer-gen.cc" yy601: yych = *++lexer->cursor; if (yych == 's') goto yy713; @@ -4060,9 +4059,9 @@ yy606: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 322 "src/ast-lexer.cc" +#line 321 "src/ast-lexer.cc" { OPCODE(I32Mul); RETURN(BINARY); } -#line 4066 "src/prebuilt/ast-lexer-gen.cc" +#line 4065 "src/prebuilt/ast-lexer-gen.cc" yy608: yych = *++lexer->cursor; if (yych == 'c') goto yy731; @@ -4085,9 +4084,9 @@ yy612: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 338 "src/ast-lexer.cc" +#line 337 "src/ast-lexer.cc" { OPCODE(I32Shl); RETURN(BINARY); } -#line 4091 "src/prebuilt/ast-lexer-gen.cc" +#line 4090 "src/prebuilt/ast-lexer-gen.cc" yy614: yych = *++lexer->cursor; if (yych == '_') goto yy738; @@ -4101,9 +4100,9 @@ yy616: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 320 "src/ast-lexer.cc" +#line 319 "src/ast-lexer.cc" { OPCODE(I32Sub); RETURN(BINARY); } -#line 4107 "src/prebuilt/ast-lexer-gen.cc" +#line 4106 "src/prebuilt/ast-lexer-gen.cc" yy618: yych = *++lexer->cursor; if (yych == 'n') goto yy740; @@ -4117,33 +4116,33 @@ yy620: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 336 "src/ast-lexer.cc" +#line 335 "src/ast-lexer.cc" { OPCODE(I32Xor); RETURN(BINARY); } -#line 4123 "src/prebuilt/ast-lexer-gen.cc" +#line 4122 "src/prebuilt/ast-lexer-gen.cc" yy622: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 319 "src/ast-lexer.cc" +#line 318 "src/ast-lexer.cc" { OPCODE(I64Add); RETURN(BINARY); } -#line 4131 "src/prebuilt/ast-lexer-gen.cc" +#line 4130 "src/prebuilt/ast-lexer-gen.cc" yy624: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 333 "src/ast-lexer.cc" +#line 332 "src/ast-lexer.cc" { OPCODE(I64And); RETURN(BINARY); } -#line 4139 "src/prebuilt/ast-lexer-gen.cc" +#line 4138 "src/prebuilt/ast-lexer-gen.cc" yy626: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 299 "src/ast-lexer.cc" +#line 298 "src/ast-lexer.cc" { OPCODE(I64Clz); RETURN(UNARY); } -#line 4147 "src/prebuilt/ast-lexer-gen.cc" +#line 4146 "src/prebuilt/ast-lexer-gen.cc" yy628: yych = *++lexer->cursor; if (yych == 's') goto yy742; @@ -4153,9 +4152,9 @@ yy629: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 301 "src/ast-lexer.cc" +#line 300 "src/ast-lexer.cc" { OPCODE(I64Ctz); RETURN(UNARY); } -#line 4159 "src/prebuilt/ast-lexer-gen.cc" +#line 4158 "src/prebuilt/ast-lexer-gen.cc" yy631: yych = *++lexer->cursor; if (yych == '_') goto yy743; @@ -4165,9 +4164,9 @@ yy632: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 297 "src/ast-lexer.cc" +#line 296 "src/ast-lexer.cc" { OPCODE(I64Eqz); RETURN(CONVERT); } -#line 4171 "src/prebuilt/ast-lexer-gen.cc" +#line 4170 "src/prebuilt/ast-lexer-gen.cc" yy634: yych = *++lexer->cursor; if (yych == 'e') goto yy744; @@ -4201,9 +4200,9 @@ yy640: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 323 "src/ast-lexer.cc" +#line 322 "src/ast-lexer.cc" { OPCODE(I64Mul); RETURN(BINARY); } -#line 4207 "src/prebuilt/ast-lexer-gen.cc" +#line 4206 "src/prebuilt/ast-lexer-gen.cc" yy642: yych = *++lexer->cursor; if (yych == 'c') goto yy763; @@ -4226,9 +4225,9 @@ yy646: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 339 "src/ast-lexer.cc" +#line 338 "src/ast-lexer.cc" { OPCODE(I64Shl); RETURN(BINARY); } -#line 4232 "src/prebuilt/ast-lexer-gen.cc" +#line 4231 "src/prebuilt/ast-lexer-gen.cc" yy648: yych = *++lexer->cursor; if (yych == '_') goto yy770; @@ -4242,9 +4241,9 @@ yy650: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 321 "src/ast-lexer.cc" +#line 320 "src/ast-lexer.cc" { OPCODE(I64Sub); RETURN(BINARY); } -#line 4248 "src/prebuilt/ast-lexer-gen.cc" +#line 4247 "src/prebuilt/ast-lexer-gen.cc" yy652: yych = *++lexer->cursor; if (yych == 'n') goto yy772; @@ -4254,17 +4253,17 @@ yy653: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 337 "src/ast-lexer.cc" +#line 336 "src/ast-lexer.cc" { OPCODE(I64Xor); RETURN(BINARY); } -#line 4260 "src/prebuilt/ast-lexer-gen.cc" +#line 4259 "src/prebuilt/ast-lexer-gen.cc" yy655: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 249 "src/ast-lexer.cc" +#line 248 "src/ast-lexer.cc" { RETURN(IF); } -#line 4268 "src/prebuilt/ast-lexer-gen.cc" +#line 4267 "src/prebuilt/ast-lexer-gen.cc" yy657: yych = *++lexer->cursor; if (yych == 'y') goto yy773; @@ -4382,9 +4381,9 @@ yy673: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 255 "src/ast-lexer.cc" +#line 254 "src/ast-lexer.cc" { RETURN(BR_TABLE); } -#line 4388 "src/prebuilt/ast-lexer-gen.cc" +#line 4387 "src/prebuilt/ast-lexer-gen.cc" yy675: yych = *++lexer->cursor; if (yych == 'o') goto yy792; @@ -4402,9 +4401,9 @@ yy678: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 310 "src/ast-lexer.cc" +#line 309 "src/ast-lexer.cc" { OPCODE(F32Ceil); RETURN(UNARY); } -#line 4408 "src/prebuilt/ast-lexer-gen.cc" +#line 4407 "src/prebuilt/ast-lexer-gen.cc" yy680: yych = *++lexer->cursor; if (yych == 't') goto yy795; @@ -4430,9 +4429,9 @@ yy685: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 269 "src/ast-lexer.cc" +#line 268 "src/ast-lexer.cc" { OPCODE(F32Load); RETURN(LOAD); } -#line 4436 "src/prebuilt/ast-lexer-gen.cc" +#line 4435 "src/prebuilt/ast-lexer-gen.cc" yy687: yych = *++lexer->cursor; if (yych == 'e') goto yy802; @@ -4446,9 +4445,9 @@ yy689: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 308 "src/ast-lexer.cc" +#line 307 "src/ast-lexer.cc" { OPCODE(F32Sqrt); RETURN(UNARY); } -#line 4452 "src/prebuilt/ast-lexer-gen.cc" +#line 4451 "src/prebuilt/ast-lexer-gen.cc" yy691: yych = *++lexer->cursor; if (yych == 'e') goto yy804; @@ -4462,9 +4461,9 @@ yy693: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 311 "src/ast-lexer.cc" +#line 310 "src/ast-lexer.cc" { OPCODE(F64Ceil); RETURN(UNARY); } -#line 4468 "src/prebuilt/ast-lexer-gen.cc" +#line 4467 "src/prebuilt/ast-lexer-gen.cc" yy695: yych = *++lexer->cursor; if (yych == 't') goto yy808; @@ -4486,9 +4485,9 @@ yy699: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 270 "src/ast-lexer.cc" +#line 269 "src/ast-lexer.cc" { OPCODE(F64Load); RETURN(LOAD); } -#line 4492 "src/prebuilt/ast-lexer-gen.cc" +#line 4491 "src/prebuilt/ast-lexer-gen.cc" yy701: yych = *++lexer->cursor; if (yych == 'e') goto yy814; @@ -4506,9 +4505,9 @@ yy704: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 309 "src/ast-lexer.cc" +#line 308 "src/ast-lexer.cc" { OPCODE(F64Sqrt); RETURN(UNARY); } -#line 4512 "src/prebuilt/ast-lexer-gen.cc" +#line 4511 "src/prebuilt/ast-lexer-gen.cc" yy706: yych = *++lexer->cursor; if (yych == 'e') goto yy817; @@ -4543,49 +4542,49 @@ yy713: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 378 "src/ast-lexer.cc" +#line 377 "src/ast-lexer.cc" { OPCODE(I32GeS); RETURN(COMPARE); } -#line 4549 "src/prebuilt/ast-lexer-gen.cc" +#line 4548 "src/prebuilt/ast-lexer-gen.cc" yy715: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 380 "src/ast-lexer.cc" +#line 379 "src/ast-lexer.cc" { OPCODE(I32GeU); RETURN(COMPARE); } -#line 4557 "src/prebuilt/ast-lexer-gen.cc" +#line 4556 "src/prebuilt/ast-lexer-gen.cc" yy717: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 374 "src/ast-lexer.cc" +#line 373 "src/ast-lexer.cc" { OPCODE(I32GtS); RETURN(COMPARE); } -#line 4565 "src/prebuilt/ast-lexer-gen.cc" +#line 4564 "src/prebuilt/ast-lexer-gen.cc" yy719: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 376 "src/ast-lexer.cc" +#line 375 "src/ast-lexer.cc" { OPCODE(I32GtU); RETURN(COMPARE); } -#line 4573 "src/prebuilt/ast-lexer-gen.cc" +#line 4572 "src/prebuilt/ast-lexer-gen.cc" yy721: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 370 "src/ast-lexer.cc" +#line 369 "src/ast-lexer.cc" { OPCODE(I32LeS); RETURN(COMPARE); } -#line 4581 "src/prebuilt/ast-lexer-gen.cc" +#line 4580 "src/prebuilt/ast-lexer-gen.cc" yy723: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 372 "src/ast-lexer.cc" +#line 371 "src/ast-lexer.cc" { OPCODE(I32LeU); RETURN(COMPARE); } -#line 4589 "src/prebuilt/ast-lexer-gen.cc" +#line 4588 "src/prebuilt/ast-lexer-gen.cc" yy725: ++lexer->cursor; if ((yych = *lexer->cursor) <= '8') { @@ -4621,25 +4620,25 @@ yy725: } } yy726: -#line 267 "src/ast-lexer.cc" +#line 266 "src/ast-lexer.cc" { OPCODE(I32Load); RETURN(LOAD); } -#line 4627 "src/prebuilt/ast-lexer-gen.cc" +#line 4626 "src/prebuilt/ast-lexer-gen.cc" yy727: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 366 "src/ast-lexer.cc" +#line 365 "src/ast-lexer.cc" { OPCODE(I32LtS); RETURN(COMPARE); } -#line 4635 "src/prebuilt/ast-lexer-gen.cc" +#line 4634 "src/prebuilt/ast-lexer-gen.cc" yy729: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 368 "src/ast-lexer.cc" +#line 367 "src/ast-lexer.cc" { OPCODE(I32LtU); RETURN(COMPARE); } -#line 4643 "src/prebuilt/ast-lexer-gen.cc" +#line 4642 "src/prebuilt/ast-lexer-gen.cc" yy731: yych = *++lexer->cursor; if (yych == 'n') goto yy833; @@ -4658,17 +4657,17 @@ yy734: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 344 "src/ast-lexer.cc" +#line 343 "src/ast-lexer.cc" { OPCODE(I32Rotl); RETURN(BINARY); } -#line 4664 "src/prebuilt/ast-lexer-gen.cc" +#line 4663 "src/prebuilt/ast-lexer-gen.cc" yy736: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 346 "src/ast-lexer.cc" +#line 345 "src/ast-lexer.cc" { OPCODE(I32Rotr); RETURN(BINARY); } -#line 4672 "src/prebuilt/ast-lexer-gen.cc" +#line 4671 "src/prebuilt/ast-lexer-gen.cc" yy738: yych = *++lexer->cursor; if (yych == 's') goto yy839; @@ -4704,49 +4703,49 @@ yy745: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 379 "src/ast-lexer.cc" +#line 378 "src/ast-lexer.cc" { OPCODE(I64GeS); RETURN(COMPARE); } -#line 4710 "src/prebuilt/ast-lexer-gen.cc" +#line 4709 "src/prebuilt/ast-lexer-gen.cc" yy747: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 381 "src/ast-lexer.cc" +#line 380 "src/ast-lexer.cc" { OPCODE(I64GeU); RETURN(COMPARE); } -#line 4718 "src/prebuilt/ast-lexer-gen.cc" +#line 4717 "src/prebuilt/ast-lexer-gen.cc" yy749: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 375 "src/ast-lexer.cc" +#line 374 "src/ast-lexer.cc" { OPCODE(I64GtS); RETURN(COMPARE); } -#line 4726 "src/prebuilt/ast-lexer-gen.cc" +#line 4725 "src/prebuilt/ast-lexer-gen.cc" yy751: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 377 "src/ast-lexer.cc" +#line 376 "src/ast-lexer.cc" { OPCODE(I64GtU); RETURN(COMPARE); } -#line 4734 "src/prebuilt/ast-lexer-gen.cc" +#line 4733 "src/prebuilt/ast-lexer-gen.cc" yy753: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 371 "src/ast-lexer.cc" +#line 370 "src/ast-lexer.cc" { OPCODE(I64LeS); RETURN(COMPARE); } -#line 4742 "src/prebuilt/ast-lexer-gen.cc" +#line 4741 "src/prebuilt/ast-lexer-gen.cc" yy755: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 373 "src/ast-lexer.cc" +#line 372 "src/ast-lexer.cc" { OPCODE(I64LeU); RETURN(COMPARE); } -#line 4750 "src/prebuilt/ast-lexer-gen.cc" +#line 4749 "src/prebuilt/ast-lexer-gen.cc" yy757: ++lexer->cursor; if ((yych = *lexer->cursor) <= '7') { @@ -4786,25 +4785,25 @@ yy757: } } yy758: -#line 268 "src/ast-lexer.cc" +#line 267 "src/ast-lexer.cc" { OPCODE(I64Load); RETURN(LOAD); } -#line 4792 "src/prebuilt/ast-lexer-gen.cc" +#line 4791 "src/prebuilt/ast-lexer-gen.cc" yy759: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 367 "src/ast-lexer.cc" +#line 366 "src/ast-lexer.cc" { OPCODE(I64LtS); RETURN(COMPARE); } -#line 4800 "src/prebuilt/ast-lexer-gen.cc" +#line 4799 "src/prebuilt/ast-lexer-gen.cc" yy761: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 369 "src/ast-lexer.cc" +#line 368 "src/ast-lexer.cc" { OPCODE(I64LtU); RETURN(COMPARE); } -#line 4808 "src/prebuilt/ast-lexer-gen.cc" +#line 4807 "src/prebuilt/ast-lexer-gen.cc" yy763: yych = *++lexer->cursor; if (yych == 'n') goto yy857; @@ -4823,17 +4822,17 @@ yy766: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 345 "src/ast-lexer.cc" +#line 344 "src/ast-lexer.cc" { OPCODE(I64Rotl); RETURN(BINARY); } -#line 4829 "src/prebuilt/ast-lexer-gen.cc" +#line 4828 "src/prebuilt/ast-lexer-gen.cc" yy768: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 347 "src/ast-lexer.cc" +#line 346 "src/ast-lexer.cc" { OPCODE(I64Rotr); RETURN(BINARY); } -#line 4837 "src/prebuilt/ast-lexer-gen.cc" +#line 4836 "src/prebuilt/ast-lexer-gen.cc" yy770: yych = *++lexer->cursor; if (yych == 's') goto yy863; @@ -4889,9 +4888,9 @@ yy774: } } yy775: -#line 290 "src/ast-lexer.cc" +#line 289 "src/ast-lexer.cc" { TEXT_AT(7); RETURN(OFFSET_EQ_NAT); } -#line 4895 "src/prebuilt/ast-lexer-gen.cc" +#line 4894 "src/prebuilt/ast-lexer-gen.cc" yy776: ++lexer->cursor; if (lexer->limit <= lexer->cursor) FILL(1); @@ -4940,9 +4939,9 @@ yy778: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 442 "src/ast-lexer.cc" +#line 441 "src/ast-lexer.cc" { RETURN(REGISTER); } -#line 4946 "src/prebuilt/ast-lexer-gen.cc" +#line 4945 "src/prebuilt/ast-lexer-gen.cc" yy780: yych = *++lexer->cursor; if (yych == 'a') goto yy871; @@ -5046,9 +5045,9 @@ yy795: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 294 "src/ast-lexer.cc" +#line 293 "src/ast-lexer.cc" { TYPE(F32); RETURN(CONST); } -#line 5052 "src/prebuilt/ast-lexer-gen.cc" +#line 5051 "src/prebuilt/ast-lexer-gen.cc" yy797: yych = *++lexer->cursor; if (yych == 'r') goto yy886; @@ -5066,9 +5065,9 @@ yy800: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 312 "src/ast-lexer.cc" +#line 311 "src/ast-lexer.cc" { OPCODE(F32Floor); RETURN(UNARY); } -#line 5072 "src/prebuilt/ast-lexer-gen.cc" +#line 5071 "src/prebuilt/ast-lexer-gen.cc" yy802: yych = *++lexer->cursor; if (yych == 's') goto yy889; @@ -5082,25 +5081,25 @@ yy804: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 273 "src/ast-lexer.cc" +#line 272 "src/ast-lexer.cc" { OPCODE(F32Store); RETURN(STORE); } -#line 5088 "src/prebuilt/ast-lexer-gen.cc" +#line 5087 "src/prebuilt/ast-lexer-gen.cc" yy806: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 314 "src/ast-lexer.cc" +#line 313 "src/ast-lexer.cc" { OPCODE(F32Trunc); RETURN(UNARY); } -#line 5096 "src/prebuilt/ast-lexer-gen.cc" +#line 5095 "src/prebuilt/ast-lexer-gen.cc" yy808: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 295 "src/ast-lexer.cc" +#line 294 "src/ast-lexer.cc" { TYPE(F64); RETURN(CONST); } -#line 5104 "src/prebuilt/ast-lexer-gen.cc" +#line 5103 "src/prebuilt/ast-lexer-gen.cc" yy810: yych = *++lexer->cursor; if (yych == 'r') goto yy891; @@ -5114,9 +5113,9 @@ yy812: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 313 "src/ast-lexer.cc" +#line 312 "src/ast-lexer.cc" { OPCODE(F64Floor); RETURN(UNARY); } -#line 5120 "src/prebuilt/ast-lexer-gen.cc" +#line 5119 "src/prebuilt/ast-lexer-gen.cc" yy814: yych = *++lexer->cursor; if (yych == 's') goto yy893; @@ -5134,17 +5133,17 @@ yy817: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 274 "src/ast-lexer.cc" +#line 273 "src/ast-lexer.cc" { OPCODE(F64Store); RETURN(STORE); } -#line 5140 "src/prebuilt/ast-lexer-gen.cc" +#line 5139 "src/prebuilt/ast-lexer-gen.cc" yy819: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 315 "src/ast-lexer.cc" +#line 314 "src/ast-lexer.cc" { OPCODE(F64Trunc); RETURN(UNARY); } -#line 5148 "src/prebuilt/ast-lexer-gen.cc" +#line 5147 "src/prebuilt/ast-lexer-gen.cc" yy821: yych = *++lexer->cursor; if (yych == 'l') goto yy896; @@ -5154,9 +5153,9 @@ yy822: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 262 "src/ast-lexer.cc" +#line 261 "src/ast-lexer.cc" { RETURN(GET_LOCAL); } -#line 5160 "src/prebuilt/ast-lexer-gen.cc" +#line 5159 "src/prebuilt/ast-lexer-gen.cc" yy824: yych = *++lexer->cursor; if (yych == 'r') goto yy898; @@ -5166,25 +5165,25 @@ yy825: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 292 "src/ast-lexer.cc" +#line 291 "src/ast-lexer.cc" { TYPE(I32); RETURN(CONST); } -#line 5172 "src/prebuilt/ast-lexer-gen.cc" +#line 5171 "src/prebuilt/ast-lexer-gen.cc" yy827: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 324 "src/ast-lexer.cc" +#line 323 "src/ast-lexer.cc" { OPCODE(I32DivS); RETURN(BINARY); } -#line 5180 "src/prebuilt/ast-lexer-gen.cc" +#line 5179 "src/prebuilt/ast-lexer-gen.cc" yy829: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 326 "src/ast-lexer.cc" +#line 325 "src/ast-lexer.cc" { OPCODE(I32DivU); RETURN(BINARY); } -#line 5188 "src/prebuilt/ast-lexer-gen.cc" +#line 5187 "src/prebuilt/ast-lexer-gen.cc" yy831: yych = *++lexer->cursor; if (yych == '6') goto yy899; @@ -5206,33 +5205,33 @@ yy835: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 328 "src/ast-lexer.cc" +#line 327 "src/ast-lexer.cc" { OPCODE(I32RemS); RETURN(BINARY); } -#line 5212 "src/prebuilt/ast-lexer-gen.cc" +#line 5211 "src/prebuilt/ast-lexer-gen.cc" yy837: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 330 "src/ast-lexer.cc" +#line 329 "src/ast-lexer.cc" { OPCODE(I32RemU); RETURN(BINARY); } -#line 5220 "src/prebuilt/ast-lexer-gen.cc" +#line 5219 "src/prebuilt/ast-lexer-gen.cc" yy839: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 340 "src/ast-lexer.cc" +#line 339 "src/ast-lexer.cc" { OPCODE(I32ShrS); RETURN(BINARY); } -#line 5228 "src/prebuilt/ast-lexer-gen.cc" +#line 5227 "src/prebuilt/ast-lexer-gen.cc" yy841: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 342 "src/ast-lexer.cc" +#line 341 "src/ast-lexer.cc" { OPCODE(I32ShrU); RETURN(BINARY); } -#line 5236 "src/prebuilt/ast-lexer-gen.cc" +#line 5235 "src/prebuilt/ast-lexer-gen.cc" yy843: ++lexer->cursor; if ((yych = *lexer->cursor) <= '8') { @@ -5268,9 +5267,9 @@ yy843: } } yy844: -#line 271 "src/ast-lexer.cc" +#line 270 "src/ast-lexer.cc" { OPCODE(I32Store); RETURN(STORE); } -#line 5274 "src/prebuilt/ast-lexer-gen.cc" +#line 5273 "src/prebuilt/ast-lexer-gen.cc" yy845: yych = *++lexer->cursor; if (yych == '_') goto yy907; @@ -5284,25 +5283,25 @@ yy847: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 293 "src/ast-lexer.cc" +#line 292 "src/ast-lexer.cc" { TYPE(I64); RETURN(CONST); } -#line 5290 "src/prebuilt/ast-lexer-gen.cc" +#line 5289 "src/prebuilt/ast-lexer-gen.cc" yy849: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 325 "src/ast-lexer.cc" +#line 324 "src/ast-lexer.cc" { OPCODE(I64DivS); RETURN(BINARY); } -#line 5298 "src/prebuilt/ast-lexer-gen.cc" +#line 5297 "src/prebuilt/ast-lexer-gen.cc" yy851: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 327 "src/ast-lexer.cc" +#line 326 "src/ast-lexer.cc" { OPCODE(I64DivU); RETURN(BINARY); } -#line 5306 "src/prebuilt/ast-lexer-gen.cc" +#line 5305 "src/prebuilt/ast-lexer-gen.cc" yy853: yych = *++lexer->cursor; if (yych == 'd') goto yy909; @@ -5332,33 +5331,33 @@ yy859: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 329 "src/ast-lexer.cc" +#line 328 "src/ast-lexer.cc" { OPCODE(I64RemS); RETURN(BINARY); } -#line 5338 "src/prebuilt/ast-lexer-gen.cc" +#line 5337 "src/prebuilt/ast-lexer-gen.cc" yy861: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 331 "src/ast-lexer.cc" +#line 330 "src/ast-lexer.cc" { OPCODE(I64RemU); RETURN(BINARY); } -#line 5346 "src/prebuilt/ast-lexer-gen.cc" +#line 5345 "src/prebuilt/ast-lexer-gen.cc" yy863: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 341 "src/ast-lexer.cc" +#line 340 "src/ast-lexer.cc" { OPCODE(I64ShrS); RETURN(BINARY); } -#line 5354 "src/prebuilt/ast-lexer-gen.cc" +#line 5353 "src/prebuilt/ast-lexer-gen.cc" yy865: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 343 "src/ast-lexer.cc" +#line 342 "src/ast-lexer.cc" { OPCODE(I64ShrU); RETURN(BINARY); } -#line 5362 "src/prebuilt/ast-lexer-gen.cc" +#line 5361 "src/prebuilt/ast-lexer-gen.cc" yy867: ++lexer->cursor; if ((yych = *lexer->cursor) <= '7') { @@ -5398,9 +5397,9 @@ yy867: } } yy868: -#line 272 "src/ast-lexer.cc" +#line 271 "src/ast-lexer.cc" { OPCODE(I64Store); RETURN(STORE); } -#line 5404 "src/prebuilt/ast-lexer-gen.cc" +#line 5403 "src/prebuilt/ast-lexer-gen.cc" yy869: yych = *++lexer->cursor; if (yych == '_') goto yy920; @@ -5426,17 +5425,17 @@ yy872: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 263 "src/ast-lexer.cc" +#line 262 "src/ast-lexer.cc" { RETURN(SET_LOCAL); } -#line 5432 "src/prebuilt/ast-lexer-gen.cc" +#line 5431 "src/prebuilt/ast-lexer-gen.cc" yy874: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 264 "src/ast-lexer.cc" +#line 263 "src/ast-lexer.cc" { RETURN(TEE_LOCAL); } -#line 5440 "src/prebuilt/ast-lexer-gen.cc" +#line 5439 "src/prebuilt/ast-lexer-gen.cc" yy876: yych = *++lexer->cursor; if (yych == 'l') goto yy925; @@ -5522,9 +5521,9 @@ yy896: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 265 "src/ast-lexer.cc" +#line 264 "src/ast-lexer.cc" { RETURN(GET_GLOBAL); } -#line 5528 "src/prebuilt/ast-lexer-gen.cc" +#line 5527 "src/prebuilt/ast-lexer-gen.cc" yy898: yych = *++lexer->cursor; if (yych == 'y') goto yy949; @@ -5543,9 +5542,9 @@ yy901: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 302 "src/ast-lexer.cc" +#line 301 "src/ast-lexer.cc" { OPCODE(I32Popcnt); RETURN(UNARY); } -#line 5549 "src/prebuilt/ast-lexer-gen.cc" +#line 5548 "src/prebuilt/ast-lexer-gen.cc" yy903: yych = *++lexer->cursor; if (yych == 'r') goto yy956; @@ -5559,9 +5558,9 @@ yy905: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 285 "src/ast-lexer.cc" +#line 284 "src/ast-lexer.cc" { OPCODE(I32Store8); RETURN(STORE); } -#line 5565 "src/prebuilt/ast-lexer-gen.cc" +#line 5564 "src/prebuilt/ast-lexer-gen.cc" yy907: yych = *++lexer->cursor; if (yych == 's') goto yy959; @@ -5593,9 +5592,9 @@ yy913: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 303 "src/ast-lexer.cc" +#line 302 "src/ast-lexer.cc" { OPCODE(I64Popcnt); RETURN(UNARY); } -#line 5599 "src/prebuilt/ast-lexer-gen.cc" +#line 5598 "src/prebuilt/ast-lexer-gen.cc" yy915: yych = *++lexer->cursor; if (yych == 'r') goto yy969; @@ -5613,9 +5612,9 @@ yy918: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 286 "src/ast-lexer.cc" +#line 285 "src/ast-lexer.cc" { OPCODE(I64Store8); RETURN(STORE); } -#line 5619 "src/prebuilt/ast-lexer-gen.cc" +#line 5618 "src/prebuilt/ast-lexer-gen.cc" yy920: yych = *++lexer->cursor; if (yych == 's') goto yy974; @@ -5672,9 +5671,9 @@ yy923: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 266 "src/ast-lexer.cc" +#line 265 "src/ast-lexer.cc" { RETURN(SET_GLOBAL); } -#line 5678 "src/prebuilt/ast-lexer-gen.cc" +#line 5677 "src/prebuilt/ast-lexer-gen.cc" yy925: yych = *++lexer->cursor; if (yych == 'e') goto yy976; @@ -5700,9 +5699,9 @@ yy930: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 450 "src/ast-lexer.cc" +#line 449 "src/ast-lexer.cc" { RETURN(ASSERT_TRAP); } -#line 5706 "src/prebuilt/ast-lexer-gen.cc" +#line 5705 "src/prebuilt/ast-lexer-gen.cc" yy932: yych = *++lexer->cursor; if (yych == 'n') goto yy982; @@ -5712,9 +5711,9 @@ yy933: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 257 "src/ast-lexer.cc" +#line 256 "src/ast-lexer.cc" { RETURN(CALL_IMPORT); } -#line 5718 "src/prebuilt/ast-lexer-gen.cc" +#line 5717 "src/prebuilt/ast-lexer-gen.cc" yy935: yych = *++lexer->cursor; if (yych == 'c') goto yy983; @@ -5740,9 +5739,9 @@ yy940: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 316 "src/ast-lexer.cc" +#line 315 "src/ast-lexer.cc" { OPCODE(F32Nearest); RETURN(UNARY); } -#line 5746 "src/prebuilt/ast-lexer-gen.cc" +#line 5745 "src/prebuilt/ast-lexer-gen.cc" yy942: yych = *++lexer->cursor; if (yych == 'p') goto yy989; @@ -5760,9 +5759,9 @@ yy945: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 317 "src/ast-lexer.cc" +#line 316 "src/ast-lexer.cc" { OPCODE(F64Nearest); RETURN(UNARY); } -#line 5766 "src/prebuilt/ast-lexer-gen.cc" +#line 5765 "src/prebuilt/ast-lexer-gen.cc" yy947: yych = *++lexer->cursor; if (yych == '/') goto yy993; @@ -5776,9 +5775,9 @@ yy949: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 426 "src/ast-lexer.cc" +#line 425 "src/ast-lexer.cc" { RETURN(GROW_MEMORY); } -#line 5782 "src/prebuilt/ast-lexer-gen.cc" +#line 5781 "src/prebuilt/ast-lexer-gen.cc" yy951: yych = *++lexer->cursor; if (yych == 's') goto yy995; @@ -5789,17 +5788,17 @@ yy952: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 275 "src/ast-lexer.cc" +#line 274 "src/ast-lexer.cc" { OPCODE(I32Load8S); RETURN(LOAD); } -#line 5795 "src/prebuilt/ast-lexer-gen.cc" +#line 5794 "src/prebuilt/ast-lexer-gen.cc" yy954: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 277 "src/ast-lexer.cc" +#line 276 "src/ast-lexer.cc" { OPCODE(I32Load8U); RETURN(LOAD); } -#line 5803 "src/prebuilt/ast-lexer-gen.cc" +#line 5802 "src/prebuilt/ast-lexer-gen.cc" yy956: yych = *++lexer->cursor; if (yych == 'p') goto yy999; @@ -5809,9 +5808,9 @@ yy957: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 287 "src/ast-lexer.cc" +#line 286 "src/ast-lexer.cc" { OPCODE(I32Store16); RETURN(STORE); } -#line 5815 "src/prebuilt/ast-lexer-gen.cc" +#line 5814 "src/prebuilt/ast-lexer-gen.cc" yy959: yych = *++lexer->cursor; if (yych == '/') goto yy1000; @@ -5844,17 +5843,17 @@ yy965: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 276 "src/ast-lexer.cc" +#line 275 "src/ast-lexer.cc" { OPCODE(I64Load8S); RETURN(LOAD); } -#line 5850 "src/prebuilt/ast-lexer-gen.cc" +#line 5849 "src/prebuilt/ast-lexer-gen.cc" yy967: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 278 "src/ast-lexer.cc" +#line 277 "src/ast-lexer.cc" { OPCODE(I64Load8U); RETURN(LOAD); } -#line 5858 "src/prebuilt/ast-lexer-gen.cc" +#line 5857 "src/prebuilt/ast-lexer-gen.cc" yy969: yych = *++lexer->cursor; if (yych == 'p') goto yy1014; @@ -5864,17 +5863,17 @@ yy970: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 288 "src/ast-lexer.cc" +#line 287 "src/ast-lexer.cc" { OPCODE(I64Store16); RETURN(STORE); } -#line 5870 "src/prebuilt/ast-lexer-gen.cc" +#line 5869 "src/prebuilt/ast-lexer-gen.cc" yy972: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 289 "src/ast-lexer.cc" +#line 288 "src/ast-lexer.cc" { OPCODE(I64Store32); RETURN(STORE); } -#line 5878 "src/prebuilt/ast-lexer-gen.cc" +#line 5877 "src/prebuilt/ast-lexer-gen.cc" yy974: yych = *++lexer->cursor; if (yych == '/') goto yy1015; @@ -5888,9 +5887,9 @@ yy976: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 424 "src/ast-lexer.cc" +#line 423 "src/ast-lexer.cc" { RETURN(UNREACHABLE); } -#line 5894 "src/prebuilt/ast-lexer-gen.cc" +#line 5893 "src/prebuilt/ast-lexer-gen.cc" yy978: yych = *++lexer->cursor; if (yych == 's') goto yy1017; @@ -5929,9 +5928,9 @@ yy986: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 360 "src/ast-lexer.cc" +#line 359 "src/ast-lexer.cc" { OPCODE(F32Copysign); RETURN(BINARY); } -#line 5935 "src/prebuilt/ast-lexer-gen.cc" +#line 5934 "src/prebuilt/ast-lexer-gen.cc" yy988: yych = *++lexer->cursor; if (yych == '6') goto yy1028; @@ -5950,9 +5949,9 @@ yy991: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 361 "src/ast-lexer.cc" +#line 360 "src/ast-lexer.cc" { OPCODE(F64Copysign); RETURN(BINARY); } -#line 5956 "src/prebuilt/ast-lexer-gen.cc" +#line 5955 "src/prebuilt/ast-lexer-gen.cc" yy993: yych = *++lexer->cursor; if (yych == 'f') goto yy1032; @@ -5966,17 +5965,17 @@ yy995: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 279 "src/ast-lexer.cc" +#line 278 "src/ast-lexer.cc" { OPCODE(I32Load16S); RETURN(LOAD); } -#line 5972 "src/prebuilt/ast-lexer-gen.cc" +#line 5971 "src/prebuilt/ast-lexer-gen.cc" yy997: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 281 "src/ast-lexer.cc" +#line 280 "src/ast-lexer.cc" { OPCODE(I32Load16U); RETURN(LOAD); } -#line 5980 "src/prebuilt/ast-lexer-gen.cc" +#line 5979 "src/prebuilt/ast-lexer-gen.cc" yy999: yych = *++lexer->cursor; if (yych == 'r') goto yy1034; @@ -5994,9 +5993,9 @@ yy1002: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 396 "src/ast-lexer.cc" +#line 395 "src/ast-lexer.cc" { OPCODE(I32WrapI64); RETURN(CONVERT); } -#line 6000 "src/prebuilt/ast-lexer-gen.cc" +#line 5999 "src/prebuilt/ast-lexer-gen.cc" yy1004: yych = *++lexer->cursor; if (yych == '/') goto yy1037; @@ -6010,33 +6009,33 @@ yy1006: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 280 "src/ast-lexer.cc" +#line 279 "src/ast-lexer.cc" { OPCODE(I64Load16S); RETURN(LOAD); } -#line 6016 "src/prebuilt/ast-lexer-gen.cc" +#line 6015 "src/prebuilt/ast-lexer-gen.cc" yy1008: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 282 "src/ast-lexer.cc" +#line 281 "src/ast-lexer.cc" { OPCODE(I64Load16U); RETURN(LOAD); } -#line 6024 "src/prebuilt/ast-lexer-gen.cc" +#line 6023 "src/prebuilt/ast-lexer-gen.cc" yy1010: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 283 "src/ast-lexer.cc" +#line 282 "src/ast-lexer.cc" { OPCODE(I64Load32S); RETURN(LOAD); } -#line 6032 "src/prebuilt/ast-lexer-gen.cc" +#line 6031 "src/prebuilt/ast-lexer-gen.cc" yy1012: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 284 "src/ast-lexer.cc" +#line 283 "src/ast-lexer.cc" { OPCODE(I64Load32U); RETURN(LOAD); } -#line 6040 "src/prebuilt/ast-lexer-gen.cc" +#line 6039 "src/prebuilt/ast-lexer-gen.cc" yy1014: yych = *++lexer->cursor; if (yych == 'r') goto yy1039; @@ -6096,9 +6095,9 @@ yy1020: } } yy1021: -#line 448 "src/ast-lexer.cc" +#line 447 "src/ast-lexer.cc" { RETURN(ASSERT_RETURN); } -#line 6102 "src/prebuilt/ast-lexer-gen.cc" +#line 6101 "src/prebuilt/ast-lexer-gen.cc" yy1022: yych = *++lexer->cursor; if (yych == 'a') goto yy1047; @@ -6108,9 +6107,9 @@ yy1023: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 258 "src/ast-lexer.cc" +#line 257 "src/ast-lexer.cc" { RETURN(CALL_INDIRECT); } -#line 6114 "src/prebuilt/ast-lexer-gen.cc" +#line 6113 "src/prebuilt/ast-lexer-gen.cc" yy1025: yych = *++lexer->cursor; if (yych == 'y') goto yy1048; @@ -6192,9 +6191,9 @@ yy1043: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 446 "src/ast-lexer.cc" +#line 445 "src/ast-lexer.cc" { RETURN(ASSERT_INVALID); } -#line 6198 "src/prebuilt/ast-lexer-gen.cc" +#line 6197 "src/prebuilt/ast-lexer-gen.cc" yy1045: yych = *++lexer->cursor; if (yych == 'e') goto yy1072; @@ -6212,9 +6211,9 @@ yy1048: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 425 "src/ast-lexer.cc" +#line 424 "src/ast-lexer.cc" { RETURN(CURRENT_MEMORY); } -#line 6218 "src/prebuilt/ast-lexer-gen.cc" +#line 6217 "src/prebuilt/ast-lexer-gen.cc" yy1050: yych = *++lexer->cursor; if (yych == 'i') goto yy1075; @@ -6228,9 +6227,9 @@ yy1052: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 414 "src/ast-lexer.cc" +#line 413 "src/ast-lexer.cc" { OPCODE(F32DemoteF64); RETURN(CONVERT); } -#line 6234 "src/prebuilt/ast-lexer-gen.cc" +#line 6233 "src/prebuilt/ast-lexer-gen.cc" yy1054: yych = *++lexer->cursor; if (yych == 't') goto yy1077; @@ -6344,9 +6343,9 @@ yy1080: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 413 "src/ast-lexer.cc" +#line 412 "src/ast-lexer.cc" { OPCODE(F64PromoteF32); RETURN(CONVERT); } -#line 6350 "src/prebuilt/ast-lexer-gen.cc" +#line 6349 "src/prebuilt/ast-lexer-gen.cc" yy1082: yych = *++lexer->cursor; if (yych == '/') goto yy1117; @@ -6360,33 +6359,33 @@ yy1084: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 397 "src/ast-lexer.cc" +#line 396 "src/ast-lexer.cc" { OPCODE(I32TruncSF32); RETURN(CONVERT); } -#line 6366 "src/prebuilt/ast-lexer-gen.cc" +#line 6365 "src/prebuilt/ast-lexer-gen.cc" yy1086: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 399 "src/ast-lexer.cc" +#line 398 "src/ast-lexer.cc" { OPCODE(I32TruncSF64); RETURN(CONVERT); } -#line 6374 "src/prebuilt/ast-lexer-gen.cc" +#line 6373 "src/prebuilt/ast-lexer-gen.cc" yy1088: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 401 "src/ast-lexer.cc" +#line 400 "src/ast-lexer.cc" { OPCODE(I32TruncUF32); RETURN(CONVERT); } -#line 6382 "src/prebuilt/ast-lexer-gen.cc" +#line 6381 "src/prebuilt/ast-lexer-gen.cc" yy1090: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 403 "src/ast-lexer.cc" +#line 402 "src/ast-lexer.cc" { OPCODE(I32TruncUF64); RETURN(CONVERT); } -#line 6390 "src/prebuilt/ast-lexer-gen.cc" +#line 6389 "src/prebuilt/ast-lexer-gen.cc" yy1092: yych = *++lexer->cursor; if (yych == '2') goto yy1119; @@ -6404,33 +6403,33 @@ yy1095: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 398 "src/ast-lexer.cc" +#line 397 "src/ast-lexer.cc" { OPCODE(I64TruncSF32); RETURN(CONVERT); } -#line 6410 "src/prebuilt/ast-lexer-gen.cc" +#line 6409 "src/prebuilt/ast-lexer-gen.cc" yy1097: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 400 "src/ast-lexer.cc" +#line 399 "src/ast-lexer.cc" { OPCODE(I64TruncSF64); RETURN(CONVERT); } -#line 6418 "src/prebuilt/ast-lexer-gen.cc" +#line 6417 "src/prebuilt/ast-lexer-gen.cc" yy1099: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 402 "src/ast-lexer.cc" +#line 401 "src/ast-lexer.cc" { OPCODE(I64TruncUF32); RETURN(CONVERT); } -#line 6426 "src/prebuilt/ast-lexer-gen.cc" +#line 6425 "src/prebuilt/ast-lexer-gen.cc" yy1101: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 404 "src/ast-lexer.cc" +#line 403 "src/ast-lexer.cc" { OPCODE(I64TruncUF64); RETURN(CONVERT); } -#line 6434 "src/prebuilt/ast-lexer-gen.cc" +#line 6433 "src/prebuilt/ast-lexer-gen.cc" yy1103: yych = *++lexer->cursor; if (yych == 'n') goto yy1124; @@ -6440,9 +6439,9 @@ yy1104: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 445 "src/ast-lexer.cc" +#line 444 "src/ast-lexer.cc" { RETURN(ASSERT_MALFORMED); } -#line 6446 "src/prebuilt/ast-lexer-gen.cc" +#line 6445 "src/prebuilt/ast-lexer-gen.cc" yy1106: yych = *++lexer->cursor; if (yych == 'n') goto yy1126; @@ -6500,17 +6499,17 @@ yy1119: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 394 "src/ast-lexer.cc" +#line 393 "src/ast-lexer.cc" { OPCODE(I64ExtendSI32); RETURN(CONVERT); } -#line 6506 "src/prebuilt/ast-lexer-gen.cc" +#line 6505 "src/prebuilt/ast-lexer-gen.cc" yy1121: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 395 "src/ast-lexer.cc" +#line 394 "src/ast-lexer.cc" { OPCODE(I64ExtendUI32); RETURN(CONVERT); } -#line 6514 "src/prebuilt/ast-lexer-gen.cc" +#line 6513 "src/prebuilt/ast-lexer-gen.cc" yy1123: yych = *++lexer->cursor; if (yych == 'f') goto yy1149; @@ -6520,57 +6519,57 @@ yy1124: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 451 "src/ast-lexer.cc" +#line 450 "src/ast-lexer.cc" { RETURN(ASSERT_EXHAUSTION); } -#line 6526 "src/prebuilt/ast-lexer-gen.cc" +#line 6525 "src/prebuilt/ast-lexer-gen.cc" yy1126: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 449 "src/ast-lexer.cc" +#line 448 "src/ast-lexer.cc" { RETURN(ASSERT_RETURN_NAN); } -#line 6534 "src/prebuilt/ast-lexer-gen.cc" +#line 6533 "src/prebuilt/ast-lexer-gen.cc" yy1128: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 447 "src/ast-lexer.cc" +#line 446 "src/ast-lexer.cc" { RETURN(ASSERT_UNLINKABLE); } -#line 6542 "src/prebuilt/ast-lexer-gen.cc" +#line 6541 "src/prebuilt/ast-lexer-gen.cc" yy1130: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 405 "src/ast-lexer.cc" +#line 404 "src/ast-lexer.cc" { OPCODE(F32ConvertSI32); RETURN(CONVERT); } -#line 6550 "src/prebuilt/ast-lexer-gen.cc" +#line 6549 "src/prebuilt/ast-lexer-gen.cc" yy1132: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 407 "src/ast-lexer.cc" +#line 406 "src/ast-lexer.cc" { OPCODE(F32ConvertSI64); RETURN(CONVERT); } -#line 6558 "src/prebuilt/ast-lexer-gen.cc" +#line 6557 "src/prebuilt/ast-lexer-gen.cc" yy1134: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 409 "src/ast-lexer.cc" +#line 408 "src/ast-lexer.cc" { OPCODE(F32ConvertUI32); RETURN(CONVERT); } -#line 6566 "src/prebuilt/ast-lexer-gen.cc" +#line 6565 "src/prebuilt/ast-lexer-gen.cc" yy1136: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 411 "src/ast-lexer.cc" +#line 410 "src/ast-lexer.cc" { OPCODE(F32ConvertUI64); RETURN(CONVERT); } -#line 6574 "src/prebuilt/ast-lexer-gen.cc" +#line 6573 "src/prebuilt/ast-lexer-gen.cc" yy1138: yych = *++lexer->cursor; if (yych == '3') goto yy1150; @@ -6580,33 +6579,33 @@ yy1139: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 406 "src/ast-lexer.cc" +#line 405 "src/ast-lexer.cc" { OPCODE(F64ConvertSI32); RETURN(CONVERT); } -#line 6586 "src/prebuilt/ast-lexer-gen.cc" +#line 6585 "src/prebuilt/ast-lexer-gen.cc" yy1141: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 408 "src/ast-lexer.cc" +#line 407 "src/ast-lexer.cc" { OPCODE(F64ConvertSI64); RETURN(CONVERT); } -#line 6594 "src/prebuilt/ast-lexer-gen.cc" +#line 6593 "src/prebuilt/ast-lexer-gen.cc" yy1143: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 410 "src/ast-lexer.cc" +#line 409 "src/ast-lexer.cc" { OPCODE(F64ConvertUI32); RETURN(CONVERT); } -#line 6602 "src/prebuilt/ast-lexer-gen.cc" +#line 6601 "src/prebuilt/ast-lexer-gen.cc" yy1145: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 412 "src/ast-lexer.cc" +#line 411 "src/ast-lexer.cc" { OPCODE(F64ConvertUI64); RETURN(CONVERT); } -#line 6610 "src/prebuilt/ast-lexer-gen.cc" +#line 6609 "src/prebuilt/ast-lexer-gen.cc" yy1147: yych = *++lexer->cursor; if (yych == '6') goto yy1151; @@ -6640,40 +6639,40 @@ yy1154: if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 415 "src/ast-lexer.cc" +#line 414 "src/ast-lexer.cc" { OPCODE(F32ReinterpretI32); RETURN(CONVERT); } -#line 6647 "src/prebuilt/ast-lexer-gen.cc" +#line 6646 "src/prebuilt/ast-lexer-gen.cc" yy1156: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 419 "src/ast-lexer.cc" +#line 418 "src/ast-lexer.cc" { OPCODE(F64ReinterpretI64); RETURN(CONVERT); } -#line 6656 "src/prebuilt/ast-lexer-gen.cc" +#line 6655 "src/prebuilt/ast-lexer-gen.cc" yy1158: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 417 "src/ast-lexer.cc" +#line 416 "src/ast-lexer.cc" { OPCODE(I32ReinterpretF32); RETURN(CONVERT); } -#line 6665 "src/prebuilt/ast-lexer-gen.cc" +#line 6664 "src/prebuilt/ast-lexer-gen.cc" yy1160: ++lexer->cursor; if (yybm[0+(yych = *lexer->cursor)] & 16) { goto yy49; } -#line 421 "src/ast-lexer.cc" +#line 420 "src/ast-lexer.cc" { OPCODE(I64ReinterpretF64); RETURN(CONVERT); } -#line 6674 "src/prebuilt/ast-lexer-gen.cc" +#line 6673 "src/prebuilt/ast-lexer-gen.cc" } } -#line 474 "src/ast-lexer.cc" +#line 473 "src/ast-lexer.cc" } } diff --git a/src/prebuilt/ast-parser-gen.cc b/src/prebuilt/ast-parser-gen.cc index 0bd083fd..c5765eab 100644 --- a/src/prebuilt/ast-parser-gen.cc +++ b/src/prebuilt/ast-parser-gen.cc @@ -78,6 +78,7 @@ #include <stdlib.h> #include <algorithm> +#include <utility> #include "ast-parser.h" #include "ast-parser-lexer-shared.h" @@ -138,44 +139,40 @@ field->kind = item; \ } while (0) -#define APPEND_ITEM_TO_VECTOR(module, Kind, kind, kinds, item_ptr) \ - do { \ - Kind* dummy = item_ptr; \ - append_##kind##_ptr_value(&(module)->kinds, &dummy); \ - } while (0) +#define APPEND_ITEM_TO_VECTOR(module, kinds, item_ptr) \ + (module)->kinds.push_back(item_ptr) #define INSERT_BINDING(module, kind, kinds, loc_, name) \ do \ if ((name).start) { \ (module)->kind##_bindings.emplace( \ string_slice_to_string(name), \ - Binding(loc_, (module)->kinds.size - 1)); \ + Binding(loc_, (module)->kinds.size() - 1)); \ } \ while (0) #define APPEND_INLINE_EXPORT(module, Kind, loc_, value, index_) \ do \ - if ((value).export_.has_export) { \ + if ((value)->export_.has_export) { \ ModuleField* export_field; \ APPEND_FIELD_TO_LIST(module, export_field, Export, export_, loc_, \ - (value).export_.export_); \ - export_field->export_.kind = ExternalKind::Kind; \ - export_field->export_.var.loc = loc_; \ - export_field->export_.var.index = index_; \ - APPEND_ITEM_TO_VECTOR(module, Export, export, exports, \ - &export_field->export_); \ + (value)->export_.export_.release()); \ + export_field->export_->kind = ExternalKind::Kind; \ + export_field->export_->var.loc = loc_; \ + export_field->export_->var.index = index_; \ + APPEND_ITEM_TO_VECTOR(module, exports, export_field->export_); \ INSERT_BINDING(module, export, exports, export_field->loc, \ - export_field->export_.name); \ + export_field->export_->name); \ } \ while (0) -#define CHECK_IMPORT_ORDERING(module, kind, kinds, loc_) \ - do { \ - if ((module)->kinds.size != (module)->num_##kind##_imports) { \ - ast_parser_error( \ - &loc_, lexer, parser, \ - "imports must occur before all non-import definitions"); \ - } \ +#define CHECK_IMPORT_ORDERING(module, kind, kinds, loc_) \ + do { \ + if ((module)->kinds.size() != (module)->num_##kind##_imports) { \ + ast_parser_error( \ + &loc_, lexer, parser, \ + "imports must occur before all non-import definitions"); \ + } \ } while (0) #define CHECK_END_LABEL(loc, begin_label, end_label) \ @@ -208,12 +205,6 @@ ExprList join_exprs2(Location* loc, ExprList* expr1, Expr* expr2); -FuncField* new_func_field(void) { return new FuncField(); } -Command* new_command(void) { return new Command(); } -Module* new_module(void) { return new Module(); } -Import* new_import(void) { return new Import(); } -TextListNode* new_text_list_node(void) { return new TextListNode(); } - Result parse_const(Type type, LiteralType literal_type, const char* s, @@ -221,7 +212,7 @@ Result parse_const(Type type, Const* out); void dup_text_list(TextList* text_list, char** out_data, size_t* out_size); -bool is_empty_signature(FuncSignature* sig); +bool is_empty_signature(const FuncSignature* sig); void append_implicit_func_declaration(Location*, Module*, @@ -240,7 +231,7 @@ static bool on_read_binary_error(uint32_t offset, const char* error, #define wabt_ast_parser_error ast_parser_error -#line 244 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:339 */ +#line 235 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:339 */ # ifndef YY_NULLPTR # if defined __cplusplus && 201103L <= __cplusplus @@ -387,7 +378,7 @@ int wabt_ast_parser_parse (::wabt::AstLexer* lexer, ::wabt::AstParser* parser); /* Copy the second part of user declarations. */ -#line 391 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:358 */ +#line 382 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:358 */ #ifdef short # undef short @@ -693,24 +684,24 @@ static const yytype_uint8 yytranslate[] = /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ static const yytype_uint16 yyrline[] = { - 0, 297, 297, 303, 313, 314, 318, 336, 337, 343, - 346, 351, 358, 361, 362, 366, 371, 378, 381, 384, - 389, 396, 402, 413, 417, 421, 428, 433, 440, 441, - 447, 448, 451, 455, 456, 460, 461, 471, 472, 483, - 484, 485, 488, 491, 494, 497, 500, 504, 508, 513, - 516, 520, 524, 528, 532, 536, 540, 544, 550, 556, - 568, 572, 576, 580, 584, 587, 592, 598, 604, 610, - 620, 628, 632, 635, 641, 647, 656, 662, 667, 673, - 678, 684, 692, 693, 701, 702, 710, 715, 716, 722, - 728, 738, 744, 750, 760, 812, 821, 828, 835, 845, - 848, 852, 858, 869, 875, 895, 902, 914, 921, 941, - 963, 970, 983, 991, 998, 1004, 1010, 1018, 1023, 1031, - 1038, 1044, 1050, 1059, 1067, 1072, 1077, 1082, 1089, 1096, - 1100, 1103, 1114, 1118, 1125, 1129, 1132, 1140, 1148, 1165, - 1181, 1190, 1197, 1204, 1210, 1246, 1256, 1277, 1287, 1313, - 1318, 1326, 1334, 1344, 1350, 1356, 1362, 1368, 1374, 1379, - 1385, 1394, 1399, 1400, 1405, 1414, 1415, 1423, 1435, 1436, - 1443, 1503 + 0, 292, 292, 298, 308, 309, 313, 331, 332, 338, + 341, 346, 353, 356, 357, 362, 369, 377, 383, 389, + 394, 401, 407, 418, 422, 426, 433, 438, 445, 446, + 452, 453, 456, 460, 461, 465, 466, 476, 477, 488, + 489, 490, 493, 496, 499, 502, 505, 508, 511, 514, + 517, 520, 523, 526, 529, 532, 535, 538, 541, 544, + 557, 560, 563, 566, 569, 572, 577, 582, 587, 592, + 600, 609, 613, 616, 621, 626, 636, 640, 644, 648, + 652, 656, 663, 664, 672, 673, 681, 686, 687, 693, + 699, 709, 715, 721, 731, 783, 793, 800, 808, 818, + 821, 825, 832, 844, 852, 874, 881, 893, 901, 922, + 944, 952, 965, 973, 981, 987, 993, 1001, 1006, 1014, + 1022, 1028, 1034, 1043, 1051, 1056, 1061, 1066, 1073, 1080, + 1084, 1087, 1099, 1104, 1113, 1117, 1120, 1127, 1136, 1153, + 1170, 1180, 1186, 1192, 1198, 1231, 1241, 1261, 1272, 1300, + 1305, 1313, 1323, 1333, 1339, 1345, 1351, 1357, 1363, 1368, + 1374, 1383, 1388, 1389, 1394, 1403, 1404, 1411, 1423, 1424, + 1431, 1492 }; #endif @@ -1649,333 +1640,363 @@ yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocatio switch (yytype) { case 5: /* NAT */ -#line 258 "src/ast-parser.y" /* yacc.c:1257 */ +#line 249 "src/ast-parser.y" /* yacc.c:1257 */ {} -#line 1655 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 1646 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 6: /* INT */ -#line 258 "src/ast-parser.y" /* yacc.c:1257 */ +#line 249 "src/ast-parser.y" /* yacc.c:1257 */ {} -#line 1661 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 1652 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 7: /* FLOAT */ -#line 258 "src/ast-parser.y" /* yacc.c:1257 */ +#line 249 "src/ast-parser.y" /* yacc.c:1257 */ {} -#line 1667 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 1658 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 8: /* TEXT */ -#line 258 "src/ast-parser.y" /* yacc.c:1257 */ +#line 249 "src/ast-parser.y" /* yacc.c:1257 */ {} -#line 1673 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 1664 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 9: /* VAR */ -#line 258 "src/ast-parser.y" /* yacc.c:1257 */ +#line 249 "src/ast-parser.y" /* yacc.c:1257 */ {} -#line 1679 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 1670 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 35: /* OFFSET_EQ_NAT */ -#line 258 "src/ast-parser.y" /* yacc.c:1257 */ +#line 249 "src/ast-parser.y" /* yacc.c:1257 */ {} -#line 1685 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 1676 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 36: /* ALIGN_EQ_NAT */ -#line 258 "src/ast-parser.y" /* yacc.c:1257 */ +#line 249 "src/ast-parser.y" /* yacc.c:1257 */ {} -#line 1691 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 1682 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 75: /* non_empty_text_list */ -#line 281 "src/ast-parser.y" /* yacc.c:1257 */ +#line 276 "src/ast-parser.y" /* yacc.c:1257 */ { destroy_text_list(&((*yyvaluep).text_list)); } -#line 1697 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 1688 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 76: /* text_list */ -#line 281 "src/ast-parser.y" /* yacc.c:1257 */ +#line 276 "src/ast-parser.y" /* yacc.c:1257 */ { destroy_text_list(&((*yyvaluep).text_list)); } -#line 1703 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 1694 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 77: /* quoted_text */ -#line 280 "src/ast-parser.y" /* yacc.c:1257 */ +#line 250 "src/ast-parser.y" /* yacc.c:1257 */ { destroy_string_slice(&((*yyvaluep).text)); } -#line 1709 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 1700 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 78: /* value_type_list */ -#line 282 "src/ast-parser.y" /* yacc.c:1257 */ - { destroy_type_vector(&((*yyvaluep).types)); } -#line 1715 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 277 "src/ast-parser.y" /* yacc.c:1257 */ + { delete ((*yyvaluep).types); } +#line 1706 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ + break; + + case 80: /* global_type */ +#line 269 "src/ast-parser.y" /* yacc.c:1257 */ + { delete ((*yyvaluep).global); } +#line 1712 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 81: /* func_type */ -#line 272 "src/ast-parser.y" /* yacc.c:1257 */ - { destroy_func_signature(&((*yyvaluep).func_sig)); } -#line 1721 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 267 "src/ast-parser.y" /* yacc.c:1257 */ + { delete ((*yyvaluep).func_sig); } +#line 1718 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 82: /* func_sig */ +#line 267 "src/ast-parser.y" /* yacc.c:1257 */ + { delete ((*yyvaluep).func_sig); } +#line 1724 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ + break; + + case 84: /* memory_sig */ #line 272 "src/ast-parser.y" /* yacc.c:1257 */ - { destroy_func_signature(&((*yyvaluep).func_sig)); } -#line 1727 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ + { delete ((*yyvaluep).memory); } +#line 1730 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 86: /* type_use */ -#line 284 "src/ast-parser.y" /* yacc.c:1257 */ +#line 278 "src/ast-parser.y" /* yacc.c:1257 */ { destroy_var(&((*yyvaluep).var)); } -#line 1733 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 1736 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 88: /* literal */ -#line 278 "src/ast-parser.y" /* yacc.c:1257 */ +#line 251 "src/ast-parser.y" /* yacc.c:1257 */ { destroy_string_slice(&((*yyvaluep).literal).text); } -#line 1739 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 1742 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 89: /* var */ -#line 284 "src/ast-parser.y" /* yacc.c:1257 */ +#line 278 "src/ast-parser.y" /* yacc.c:1257 */ { destroy_var(&((*yyvaluep).var)); } -#line 1745 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 1748 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 90: /* var_list */ -#line 283 "src/ast-parser.y" /* yacc.c:1257 */ - { destroy_var_vector_and_elements(&((*yyvaluep).vars)); } -#line 1751 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 279 "src/ast-parser.y" /* yacc.c:1257 */ + { delete ((*yyvaluep).vars); } +#line 1754 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 91: /* bind_var_opt */ -#line 280 "src/ast-parser.y" /* yacc.c:1257 */ +#line 250 "src/ast-parser.y" /* yacc.c:1257 */ { destroy_string_slice(&((*yyvaluep).text)); } -#line 1757 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 1760 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 92: /* bind_var */ -#line 280 "src/ast-parser.y" /* yacc.c:1257 */ +#line 250 "src/ast-parser.y" /* yacc.c:1257 */ { destroy_string_slice(&((*yyvaluep).text)); } -#line 1763 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 1766 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 93: /* labeling_opt */ -#line 280 "src/ast-parser.y" /* yacc.c:1257 */ +#line 250 "src/ast-parser.y" /* yacc.c:1257 */ { destroy_string_slice(&((*yyvaluep).text)); } -#line 1769 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 1772 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 96: /* instr */ -#line 269 "src/ast-parser.y" /* yacc.c:1257 */ +#line 264 "src/ast-parser.y" /* yacc.c:1257 */ { destroy_expr_list(((*yyvaluep).expr_list).first); } -#line 1775 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 1778 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 97: /* plain_instr */ -#line 268 "src/ast-parser.y" /* yacc.c:1257 */ - { destroy_expr(((*yyvaluep).expr)); } -#line 1781 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 263 "src/ast-parser.y" /* yacc.c:1257 */ + { delete ((*yyvaluep).expr); } +#line 1784 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 98: /* block_instr */ -#line 268 "src/ast-parser.y" /* yacc.c:1257 */ - { destroy_expr(((*yyvaluep).expr)); } -#line 1787 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 263 "src/ast-parser.y" /* yacc.c:1257 */ + { delete ((*yyvaluep).expr); } +#line 1790 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 99: /* block */ -#line 259 "src/ast-parser.y" /* yacc.c:1257 */ - { destroy_block(&((*yyvaluep).block)); } -#line 1793 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 253 "src/ast-parser.y" /* yacc.c:1257 */ + { delete ((*yyvaluep).block); } +#line 1796 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 100: /* expr */ -#line 269 "src/ast-parser.y" /* yacc.c:1257 */ +#line 264 "src/ast-parser.y" /* yacc.c:1257 */ { destroy_expr_list(((*yyvaluep).expr_list).first); } -#line 1799 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 1802 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 101: /* expr1 */ -#line 269 "src/ast-parser.y" /* yacc.c:1257 */ +#line 264 "src/ast-parser.y" /* yacc.c:1257 */ { destroy_expr_list(((*yyvaluep).expr_list).first); } -#line 1805 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 1808 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 102: /* if_ */ -#line 269 "src/ast-parser.y" /* yacc.c:1257 */ +#line 264 "src/ast-parser.y" /* yacc.c:1257 */ { destroy_expr_list(((*yyvaluep).expr_list).first); } -#line 1811 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 1814 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 103: /* instr_list */ -#line 269 "src/ast-parser.y" /* yacc.c:1257 */ +#line 264 "src/ast-parser.y" /* yacc.c:1257 */ { destroy_expr_list(((*yyvaluep).expr_list).first); } -#line 1817 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 1820 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 104: /* expr_list */ -#line 269 "src/ast-parser.y" /* yacc.c:1257 */ +#line 264 "src/ast-parser.y" /* yacc.c:1257 */ { destroy_expr_list(((*yyvaluep).expr_list).first); } -#line 1823 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 1826 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 105: /* const_expr */ -#line 269 "src/ast-parser.y" /* yacc.c:1257 */ +#line 264 "src/ast-parser.y" /* yacc.c:1257 */ { destroy_expr_list(((*yyvaluep).expr_list).first); } -#line 1829 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 1832 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 106: /* func_fields */ -#line 270 "src/ast-parser.y" /* yacc.c:1257 */ +#line 265 "src/ast-parser.y" /* yacc.c:1257 */ { destroy_func_fields(((*yyvaluep).func_fields)); } -#line 1835 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 1838 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 107: /* func_body */ -#line 270 "src/ast-parser.y" /* yacc.c:1257 */ +#line 265 "src/ast-parser.y" /* yacc.c:1257 */ { destroy_func_fields(((*yyvaluep).func_fields)); } -#line 1841 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 1844 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 108: /* func_info */ -#line 271 "src/ast-parser.y" /* yacc.c:1257 */ +#line 266 "src/ast-parser.y" /* yacc.c:1257 */ { delete ((*yyvaluep).func); } -#line 1847 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 1850 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 109: /* func */ -#line 265 "src/ast-parser.y" /* yacc.c:1257 */ - { destroy_exported_func(&((*yyvaluep).exported_func)); } -#line 1853 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 260 "src/ast-parser.y" /* yacc.c:1257 */ + { delete ((*yyvaluep).exported_func); } +#line 1856 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 110: /* offset */ -#line 269 "src/ast-parser.y" /* yacc.c:1257 */ +#line 264 "src/ast-parser.y" /* yacc.c:1257 */ { destroy_expr_list(((*yyvaluep).expr_list).first); } -#line 1859 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 1862 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 111: /* elem */ -#line 263 "src/ast-parser.y" /* yacc.c:1257 */ - { destroy_elem_segment(&((*yyvaluep).elem_segment)); } -#line 1865 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 258 "src/ast-parser.y" /* yacc.c:1257 */ + { delete ((*yyvaluep).elem_segment); } +#line 1868 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 112: /* table */ -#line 267 "src/ast-parser.y" /* yacc.c:1257 */ - { destroy_exported_table(&((*yyvaluep).exported_table)); } -#line 1871 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 262 "src/ast-parser.y" /* yacc.c:1257 */ + { delete ((*yyvaluep).exported_table); } +#line 1874 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 113: /* data */ -#line 275 "src/ast-parser.y" /* yacc.c:1257 */ - { destroy_data_segment(&((*yyvaluep).data_segment)); } -#line 1877 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 257 "src/ast-parser.y" /* yacc.c:1257 */ + { delete ((*yyvaluep).data_segment); } +#line 1880 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 114: /* memory */ -#line 266 "src/ast-parser.y" /* yacc.c:1257 */ - { destroy_exported_memory(&((*yyvaluep).exported_memory)); } -#line 1883 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 261 "src/ast-parser.y" /* yacc.c:1257 */ + { delete ((*yyvaluep).exported_memory); } +#line 1886 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 116: /* import_kind */ -#line 274 "src/ast-parser.y" /* yacc.c:1257 */ - { destroy_import(((*yyvaluep).import)); delete ((*yyvaluep).import); } -#line 1889 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 270 "src/ast-parser.y" /* yacc.c:1257 */ + { delete ((*yyvaluep).import); } +#line 1892 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 117: /* import */ -#line 274 "src/ast-parser.y" /* yacc.c:1257 */ - { destroy_import(((*yyvaluep).import)); delete ((*yyvaluep).import); } -#line 1895 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 270 "src/ast-parser.y" /* yacc.c:1257 */ + { delete ((*yyvaluep).import); } +#line 1898 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 118: /* inline_import */ -#line 274 "src/ast-parser.y" /* yacc.c:1257 */ - { destroy_import(((*yyvaluep).import)); delete ((*yyvaluep).import); } -#line 1901 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 270 "src/ast-parser.y" /* yacc.c:1257 */ + { delete ((*yyvaluep).import); } +#line 1904 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 119: /* export_kind */ -#line 264 "src/ast-parser.y" /* yacc.c:1257 */ - { destroy_export(&((*yyvaluep).export_)); } -#line 1907 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 259 "src/ast-parser.y" /* yacc.c:1257 */ + { delete ((*yyvaluep).export_); } +#line 1910 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 120: /* export */ -#line 264 "src/ast-parser.y" /* yacc.c:1257 */ - { destroy_export(&((*yyvaluep).export_)); } -#line 1913 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 259 "src/ast-parser.y" /* yacc.c:1257 */ + { delete ((*yyvaluep).export_); } +#line 1916 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ + break; + + case 121: /* inline_export_opt */ +#line 271 "src/ast-parser.y" /* yacc.c:1257 */ + { delete ((*yyvaluep).optional_export); } +#line 1922 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ + break; + + case 122: /* inline_export */ +#line 271 "src/ast-parser.y" /* yacc.c:1257 */ + { delete ((*yyvaluep).optional_export); } +#line 1928 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 123: /* type_def */ -#line 273 "src/ast-parser.y" /* yacc.c:1257 */ - { destroy_func_type(&((*yyvaluep).func_type)); } -#line 1919 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 268 "src/ast-parser.y" /* yacc.c:1257 */ + { delete ((*yyvaluep).func_type); } +#line 1934 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 124: /* start */ -#line 284 "src/ast-parser.y" /* yacc.c:1257 */ +#line 278 "src/ast-parser.y" /* yacc.c:1257 */ { destroy_var(&((*yyvaluep).var)); } -#line 1925 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 1940 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 125: /* module_fields */ -#line 276 "src/ast-parser.y" /* yacc.c:1257 */ +#line 273 "src/ast-parser.y" /* yacc.c:1257 */ { delete ((*yyvaluep).module); } -#line 1931 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 1946 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 126: /* raw_module */ -#line 277 "src/ast-parser.y" /* yacc.c:1257 */ - { destroy_raw_module(&((*yyvaluep).raw_module)); } -#line 1937 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 274 "src/ast-parser.y" /* yacc.c:1257 */ + { delete ((*yyvaluep).raw_module); } +#line 1952 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 127: /* module */ -#line 276 "src/ast-parser.y" /* yacc.c:1257 */ +#line 273 "src/ast-parser.y" /* yacc.c:1257 */ { delete ((*yyvaluep).module); } -#line 1943 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 1958 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 128: /* script_var_opt */ -#line 284 "src/ast-parser.y" /* yacc.c:1257 */ +#line 278 "src/ast-parser.y" /* yacc.c:1257 */ { destroy_var(&((*yyvaluep).var)); } -#line 1949 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 1964 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ + break; + + case 129: /* action */ +#line 252 "src/ast-parser.y" /* yacc.c:1257 */ + { delete ((*yyvaluep).action); } +#line 1970 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 130: /* assertion */ -#line 260 "src/ast-parser.y" /* yacc.c:1257 */ - { destroy_command(((*yyvaluep).command)); delete ((*yyvaluep).command); } -#line 1955 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 254 "src/ast-parser.y" /* yacc.c:1257 */ + { delete ((*yyvaluep).command); } +#line 1976 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 131: /* cmd */ -#line 260 "src/ast-parser.y" /* yacc.c:1257 */ - { destroy_command(((*yyvaluep).command)); delete ((*yyvaluep).command); } -#line 1961 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 254 "src/ast-parser.y" /* yacc.c:1257 */ + { delete ((*yyvaluep).command); } +#line 1982 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 132: /* cmd_list */ -#line 261 "src/ast-parser.y" /* yacc.c:1257 */ - { destroy_command_vector_and_elements(&((*yyvaluep).commands)); } -#line 1967 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 255 "src/ast-parser.y" /* yacc.c:1257 */ + { delete ((*yyvaluep).commands); } +#line 1988 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 134: /* const_list */ -#line 262 "src/ast-parser.y" /* yacc.c:1257 */ - { destroy_const_vector(&((*yyvaluep).consts)); } -#line 1973 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 256 "src/ast-parser.y" /* yacc.c:1257 */ + { delete ((*yyvaluep).consts); } +#line 1994 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; case 135: /* script */ -#line 279 "src/ast-parser.y" /* yacc.c:1257 */ +#line 275 "src/ast-parser.y" /* yacc.c:1257 */ { delete ((*yyvaluep).script); } -#line 1979 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ +#line 2000 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1257 */ break; @@ -2267,37 +2288,37 @@ yyreduce: switch (yyn) { case 2: -#line 297 "src/ast-parser.y" /* yacc.c:1646 */ +#line 292 "src/ast-parser.y" /* yacc.c:1646 */ { - TextListNode* node = new_text_list_node(); + TextListNode* node = new TextListNode(); DUPTEXT(node->text, (yyvsp[0].text)); node->next = nullptr; (yyval.text_list).first = (yyval.text_list).last = node; } -#line 2278 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2299 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 3: -#line 303 "src/ast-parser.y" /* yacc.c:1646 */ +#line 298 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.text_list) = (yyvsp[-1].text_list); - TextListNode* node = new_text_list_node(); + TextListNode* node = new TextListNode(); DUPTEXT(node->text, (yyvsp[0].text)); node->next = nullptr; (yyval.text_list).last->next = node; (yyval.text_list).last = node; } -#line 2291 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2312 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 4: -#line 313 "src/ast-parser.y" /* yacc.c:1646 */ +#line 308 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.text_list).first = (yyval.text_list).last = nullptr; } -#line 2297 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2318 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 6: -#line 318 "src/ast-parser.y" /* yacc.c:1646 */ +#line 313 "src/ast-parser.y" /* yacc.c:1646 */ { TextListNode node; node.text = (yyvsp[0].text); @@ -2311,130 +2332,140 @@ yyreduce: (yyval.text).start = data; (yyval.text).length = size; } -#line 2315 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2336 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 7: -#line 336 "src/ast-parser.y" /* yacc.c:1646 */ - { WABT_ZERO_MEMORY((yyval.types)); } -#line 2321 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 331 "src/ast-parser.y" /* yacc.c:1646 */ + { (yyval.types) = new TypeVector(); } +#line 2342 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 8: -#line 337 "src/ast-parser.y" /* yacc.c:1646 */ +#line 332 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.types) = (yyvsp[-1].types); - append_type_value(&(yyval.types), &(yyvsp[0].type)); + (yyval.types)->push_back((yyvsp[0].type)); } -#line 2330 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2351 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 9: -#line 343 "src/ast-parser.y" /* yacc.c:1646 */ +#line 338 "src/ast-parser.y" /* yacc.c:1646 */ {} -#line 2336 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2357 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 10: -#line 346 "src/ast-parser.y" /* yacc.c:1646 */ +#line 341 "src/ast-parser.y" /* yacc.c:1646 */ { - WABT_ZERO_MEMORY((yyval.global)); - (yyval.global).type = (yyvsp[0].type); - (yyval.global).mutable_ = false; + (yyval.global) = new Global(); + (yyval.global)->type = (yyvsp[0].type); + (yyval.global)->mutable_ = false; } -#line 2346 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2367 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 11: -#line 351 "src/ast-parser.y" /* yacc.c:1646 */ +#line 346 "src/ast-parser.y" /* yacc.c:1646 */ { - WABT_ZERO_MEMORY((yyval.global)); - (yyval.global).type = (yyvsp[-1].type); - (yyval.global).mutable_ = true; + (yyval.global) = new Global(); + (yyval.global)->type = (yyvsp[-1].type); + (yyval.global)->mutable_ = true; } -#line 2356 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2377 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 12: -#line 358 "src/ast-parser.y" /* yacc.c:1646 */ +#line 353 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.func_sig) = (yyvsp[-1].func_sig); } -#line 2362 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2383 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 13: -#line 361 "src/ast-parser.y" /* yacc.c:1646 */ - { WABT_ZERO_MEMORY((yyval.func_sig)); } -#line 2368 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 356 "src/ast-parser.y" /* yacc.c:1646 */ + { (yyval.func_sig) = new FuncSignature(); } +#line 2389 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 14: -#line 362 "src/ast-parser.y" /* yacc.c:1646 */ +#line 357 "src/ast-parser.y" /* yacc.c:1646 */ { - WABT_ZERO_MEMORY((yyval.func_sig)); - (yyval.func_sig).param_types = (yyvsp[-1].types); + (yyval.func_sig) = new FuncSignature(); + (yyval.func_sig)->param_types = std::move(*(yyvsp[-1].types)); + delete (yyvsp[-1].types); } -#line 2377 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2399 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 15: -#line 366 "src/ast-parser.y" /* yacc.c:1646 */ +#line 362 "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); + (yyval.func_sig) = new FuncSignature(); + (yyval.func_sig)->param_types = std::move(*(yyvsp[-5].types)); + delete (yyvsp[-5].types); + (yyval.func_sig)->result_types = std::move(*(yyvsp[-1].types)); + delete (yyvsp[-1].types); } -#line 2387 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2411 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 16: -#line 371 "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); + (yyval.func_sig) = new FuncSignature(); + (yyval.func_sig)->result_types = std::move(*(yyvsp[-1].types)); + delete (yyvsp[-1].types); } -#line 2396 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2421 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 17: -#line 378 "src/ast-parser.y" /* yacc.c:1646 */ - { (yyval.table).elem_limits = (yyvsp[-1].limits); } -#line 2402 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 377 "src/ast-parser.y" /* yacc.c:1646 */ + { + (yyval.table) = new Table(); + (yyval.table)->elem_limits = (yyvsp[-1].limits); + } +#line 2430 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 18: -#line 381 "src/ast-parser.y" /* yacc.c:1646 */ - { (yyval.memory).page_limits = (yyvsp[0].limits); } -#line 2408 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 383 "src/ast-parser.y" /* yacc.c:1646 */ + { + (yyval.memory) = new Memory(); + (yyval.memory)->page_limits = (yyvsp[0].limits); + } +#line 2439 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 19: -#line 384 "src/ast-parser.y" /* yacc.c:1646 */ +#line 389 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.limits).has_max = false; (yyval.limits).initial = (yyvsp[0].u64); (yyval.limits).max = 0; } -#line 2418 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2449 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 20: -#line 389 "src/ast-parser.y" /* yacc.c:1646 */ +#line 394 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.limits).has_max = true; (yyval.limits).initial = (yyvsp[-1].u64); (yyval.limits).max = (yyvsp[0].u64); } -#line 2428 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2459 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 21: -#line 396 "src/ast-parser.y" /* yacc.c:1646 */ +#line 401 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.var) = (yyvsp[-1].var); } -#line 2434 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2465 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 22: -#line 402 "src/ast-parser.y" /* yacc.c:1646 */ +#line 407 "src/ast-parser.y" /* yacc.c:1646 */ { if (WABT_FAILED(parse_uint64((yyvsp[0].literal).text.start, (yyvsp[0].literal).text.start + (yyvsp[0].literal).text.length, &(yyval.u64)))) { @@ -2443,97 +2474,97 @@ yyreduce: WABT_PRINTF_STRING_SLICE_ARG((yyvsp[0].literal).text)); } } -#line 2447 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2478 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 23: -#line 413 "src/ast-parser.y" /* yacc.c:1646 */ +#line 418 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.literal).type = (yyvsp[0].literal).type; DUPTEXT((yyval.literal).text, (yyvsp[0].literal).text); } -#line 2456 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2487 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 24: -#line 417 "src/ast-parser.y" /* yacc.c:1646 */ +#line 422 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.literal).type = (yyvsp[0].literal).type; DUPTEXT((yyval.literal).text, (yyvsp[0].literal).text); } -#line 2465 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2496 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 25: -#line 421 "src/ast-parser.y" /* yacc.c:1646 */ +#line 426 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.literal).type = (yyvsp[0].literal).type; DUPTEXT((yyval.literal).text, (yyvsp[0].literal).text); } -#line 2474 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2505 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 26: -#line 428 "src/ast-parser.y" /* yacc.c:1646 */ +#line 433 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.var).loc = (yylsp[0]); (yyval.var).type = VarType::Index; (yyval.var).index = (yyvsp[0].u64); } -#line 2484 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2515 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 27: -#line 433 "src/ast-parser.y" /* yacc.c:1646 */ +#line 438 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.var).loc = (yylsp[0]); (yyval.var).type = VarType::Name; DUPTEXT((yyval.var).name, (yyvsp[0].text)); } -#line 2494 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2525 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 28: -#line 440 "src/ast-parser.y" /* yacc.c:1646 */ - { WABT_ZERO_MEMORY((yyval.vars)); } -#line 2500 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 445 "src/ast-parser.y" /* yacc.c:1646 */ + { (yyval.vars) = new VarVector(); } +#line 2531 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 29: -#line 441 "src/ast-parser.y" /* yacc.c:1646 */ +#line 446 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.vars) = (yyvsp[-1].vars); - append_var_value(&(yyval.vars), &(yyvsp[0].var)); + (yyval.vars)->push_back((yyvsp[0].var)); } -#line 2509 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2540 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 30: -#line 447 "src/ast-parser.y" /* yacc.c:1646 */ +#line 452 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.text)); } -#line 2515 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2546 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 32: -#line 451 "src/ast-parser.y" /* yacc.c:1646 */ +#line 456 "src/ast-parser.y" /* yacc.c:1646 */ { DUPTEXT((yyval.text), (yyvsp[0].text)); } -#line 2521 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2552 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 33: -#line 455 "src/ast-parser.y" /* yacc.c:1646 */ +#line 460 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.text)); } -#line 2527 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2558 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 35: -#line 460 "src/ast-parser.y" /* yacc.c:1646 */ +#line 465 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.u64) = 0; } -#line 2533 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2564 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 36: -#line 461 "src/ast-parser.y" /* yacc.c:1646 */ +#line 466 "src/ast-parser.y" /* yacc.c:1646 */ { if (WABT_FAILED(parse_int64((yyvsp[0].text).start, (yyvsp[0].text).start + (yyvsp[0].text).length, &(yyval.u64), ParseIntType::SignedAndUnsigned))) { @@ -2542,17 +2573,17 @@ yyreduce: WABT_PRINTF_STRING_SLICE_ARG((yyvsp[0].text))); } } -#line 2546 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2577 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 37: -#line 471 "src/ast-parser.y" /* yacc.c:1646 */ +#line 476 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.u32) = USE_NATURAL_ALIGNMENT; } -#line 2552 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2583 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 38: -#line 472 "src/ast-parser.y" /* yacc.c:1646 */ +#line 477 "src/ast-parser.y" /* yacc.c:1646 */ { if (WABT_FAILED(parse_int32((yyvsp[0].text).start, (yyvsp[0].text).start + (yyvsp[0].text).length, &(yyval.u32), ParseIntType::UnsignedOnly))) { @@ -2561,522 +2592,488 @@ yyreduce: WABT_PRINTF_STRING_SLICE_ARG((yyvsp[0].text))); } } -#line 2565 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2596 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 39: -#line 483 "src/ast-parser.y" /* yacc.c:1646 */ +#line 488 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.expr_list) = join_exprs1(&(yylsp[0]), (yyvsp[0].expr)); } -#line 2571 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2602 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 40: -#line 484 "src/ast-parser.y" /* yacc.c:1646 */ +#line 489 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.expr_list) = join_exprs1(&(yylsp[0]), (yyvsp[0].expr)); } -#line 2577 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2608 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 41: -#line 485 "src/ast-parser.y" /* yacc.c:1646 */ +#line 490 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.expr_list) = (yyvsp[0].expr_list); } -#line 2583 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2614 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 42: -#line 488 "src/ast-parser.y" /* yacc.c:1646 */ +#line 493 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = new_unreachable_expr(); + (yyval.expr) = Expr::CreateUnreachable(); } -#line 2591 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2622 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 43: -#line 491 "src/ast-parser.y" /* yacc.c:1646 */ +#line 496 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = new_nop_expr(); + (yyval.expr) = Expr::CreateNop(); } -#line 2599 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2630 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 44: -#line 494 "src/ast-parser.y" /* yacc.c:1646 */ +#line 499 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = new_drop_expr(); + (yyval.expr) = Expr::CreateDrop(); } -#line 2607 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2638 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 45: -#line 497 "src/ast-parser.y" /* yacc.c:1646 */ +#line 502 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = new_select_expr(); + (yyval.expr) = Expr::CreateSelect(); } -#line 2615 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2646 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 46: -#line 500 "src/ast-parser.y" /* yacc.c:1646 */ +#line 505 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = new_br_expr(); - (yyval.expr)->br.var = (yyvsp[0].var); + (yyval.expr) = Expr::CreateBr((yyvsp[0].var)); } -#line 2624 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2654 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 47: -#line 504 "src/ast-parser.y" /* yacc.c:1646 */ +#line 508 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = new_br_if_expr(); - (yyval.expr)->br_if.var = (yyvsp[0].var); + (yyval.expr) = Expr::CreateBrIf((yyvsp[0].var)); } -#line 2633 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2662 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 48: -#line 508 "src/ast-parser.y" /* yacc.c:1646 */ +#line 511 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = new_br_table_expr(); - (yyval.expr)->br_table.targets = (yyvsp[-1].vars); - (yyval.expr)->br_table.default_target = (yyvsp[0].var); + (yyval.expr) = Expr::CreateBrTable((yyvsp[-1].vars), (yyvsp[0].var)); } -#line 2643 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2670 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 49: -#line 513 "src/ast-parser.y" /* yacc.c:1646 */ +#line 514 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = new_return_expr(); + (yyval.expr) = Expr::CreateReturn(); } -#line 2651 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2678 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 50: -#line 516 "src/ast-parser.y" /* yacc.c:1646 */ +#line 517 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = new_call_expr(); - (yyval.expr)->call.var = (yyvsp[0].var); + (yyval.expr) = Expr::CreateCall((yyvsp[0].var)); } -#line 2660 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2686 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 51: #line 520 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = new_call_indirect_expr(); - (yyval.expr)->call_indirect.var = (yyvsp[0].var); + (yyval.expr) = Expr::CreateCallIndirect((yyvsp[0].var)); } -#line 2669 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2694 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 52: -#line 524 "src/ast-parser.y" /* yacc.c:1646 */ +#line 523 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = new_get_local_expr(); - (yyval.expr)->get_local.var = (yyvsp[0].var); + (yyval.expr) = Expr::CreateGetLocal((yyvsp[0].var)); } -#line 2678 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2702 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 53: -#line 528 "src/ast-parser.y" /* yacc.c:1646 */ +#line 526 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = new_set_local_expr(); - (yyval.expr)->set_local.var = (yyvsp[0].var); + (yyval.expr) = Expr::CreateSetLocal((yyvsp[0].var)); } -#line 2687 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2710 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 54: -#line 532 "src/ast-parser.y" /* yacc.c:1646 */ +#line 529 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = new_tee_local_expr(); - (yyval.expr)->tee_local.var = (yyvsp[0].var); + (yyval.expr) = Expr::CreateTeeLocal((yyvsp[0].var)); } -#line 2696 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2718 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 55: -#line 536 "src/ast-parser.y" /* yacc.c:1646 */ +#line 532 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = new_get_global_expr(); - (yyval.expr)->get_global.var = (yyvsp[0].var); + (yyval.expr) = Expr::CreateGetGlobal((yyvsp[0].var)); } -#line 2705 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2726 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 56: -#line 540 "src/ast-parser.y" /* yacc.c:1646 */ +#line 535 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = new_set_global_expr(); - (yyval.expr)->set_global.var = (yyvsp[0].var); + (yyval.expr) = Expr::CreateSetGlobal((yyvsp[0].var)); } -#line 2714 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2734 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 57: -#line 544 "src/ast-parser.y" /* yacc.c:1646 */ +#line 538 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = new_load_expr(); - (yyval.expr)->load.opcode = (yyvsp[-2].opcode); - (yyval.expr)->load.offset = (yyvsp[-1].u64); - (yyval.expr)->load.align = (yyvsp[0].u32); + (yyval.expr) = Expr::CreateLoad((yyvsp[-2].opcode), (yyvsp[0].u32), (yyvsp[-1].u64)); } -#line 2725 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2742 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 58: -#line 550 "src/ast-parser.y" /* yacc.c:1646 */ +#line 541 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = new_store_expr(); - (yyval.expr)->store.opcode = (yyvsp[-2].opcode); - (yyval.expr)->store.offset = (yyvsp[-1].u64); - (yyval.expr)->store.align = (yyvsp[0].u32); + (yyval.expr) = Expr::CreateStore((yyvsp[-2].opcode), (yyvsp[0].u32), (yyvsp[-1].u64)); } -#line 2736 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2750 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 59: -#line 556 "src/ast-parser.y" /* yacc.c:1646 */ +#line 544 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = new_const_expr(); - (yyval.expr)->const_.loc = (yylsp[-1]); + Const const_; + WABT_ZERO_MEMORY(const_); + 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, - &(yyval.expr)->const_))) { + (yyvsp[0].literal).text.start + (yyvsp[0].literal).text.length, &const_))) { ast_parser_error(&(yylsp[0]), lexer, parser, "invalid literal \"" PRIstringslice "\"", WABT_PRINTF_STRING_SLICE_ARG((yyvsp[0].literal).text)); } delete [] (yyvsp[0].literal).text.start; + (yyval.expr) = Expr::CreateConst(const_); } -#line 2753 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2768 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 60: -#line 568 "src/ast-parser.y" /* yacc.c:1646 */ +#line 557 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = new_unary_expr(); - (yyval.expr)->unary.opcode = (yyvsp[0].opcode); + (yyval.expr) = Expr::CreateUnary((yyvsp[0].opcode)); } -#line 2762 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2776 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 61: -#line 572 "src/ast-parser.y" /* yacc.c:1646 */ +#line 560 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = new_binary_expr(); - (yyval.expr)->binary.opcode = (yyvsp[0].opcode); + (yyval.expr) = Expr::CreateBinary((yyvsp[0].opcode)); } -#line 2771 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2784 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 62: -#line 576 "src/ast-parser.y" /* yacc.c:1646 */ +#line 563 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = new_compare_expr(); - (yyval.expr)->compare.opcode = (yyvsp[0].opcode); + (yyval.expr) = Expr::CreateCompare((yyvsp[0].opcode)); } -#line 2780 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2792 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 63: -#line 580 "src/ast-parser.y" /* yacc.c:1646 */ +#line 566 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = new_convert_expr(); - (yyval.expr)->convert.opcode = (yyvsp[0].opcode); + (yyval.expr) = Expr::CreateConvert((yyvsp[0].opcode)); } -#line 2789 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2800 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 64: -#line 584 "src/ast-parser.y" /* yacc.c:1646 */ +#line 569 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = new_current_memory_expr(); + (yyval.expr) = Expr::CreateCurrentMemory(); } -#line 2797 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2808 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 65: -#line 587 "src/ast-parser.y" /* yacc.c:1646 */ +#line 572 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = new_grow_memory_expr(); + (yyval.expr) = Expr::CreateGrowMemory(); } -#line 2805 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2816 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 66: -#line 592 "src/ast-parser.y" /* yacc.c:1646 */ +#line 577 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = 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)); + (yyval.expr) = Expr::CreateBlock((yyvsp[-2].block)); + (yyval.expr)->block->label = (yyvsp[-3].text); + CHECK_END_LABEL((yylsp[0]), (yyval.expr)->block->label, (yyvsp[0].text)); } -#line 2816 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2826 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 67: -#line 598 "src/ast-parser.y" /* yacc.c:1646 */ +#line 582 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = 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)); + (yyval.expr) = Expr::CreateLoop((yyvsp[-2].block)); + (yyval.expr)->loop->label = (yyvsp[-3].text); + CHECK_END_LABEL((yylsp[0]), (yyval.expr)->loop->label, (yyvsp[0].text)); } -#line 2827 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2836 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 68: -#line 604 "src/ast-parser.y" /* yacc.c:1646 */ +#line 587 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = 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)); + (yyval.expr) = Expr::CreateIf((yyvsp[-2].block), nullptr); + (yyval.expr)->if_.true_->label = (yyvsp[-3].text); + CHECK_END_LABEL((yylsp[0]), (yyval.expr)->if_.true_->label, (yyvsp[0].text)); } -#line 2838 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2846 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 69: -#line 610 "src/ast-parser.y" /* yacc.c:1646 */ +#line 592 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = 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)); + (yyval.expr) = Expr::CreateIf((yyvsp[-5].block), (yyvsp[-2].expr_list).first); + (yyval.expr)->if_.true_->label = (yyvsp[-6].text); + CHECK_END_LABEL((yylsp[-3]), (yyval.expr)->if_.true_->label, (yyvsp[-3].text)); + CHECK_END_LABEL((yylsp[0]), (yyval.expr)->if_.true_->label, (yyvsp[0].text)); } -#line 2851 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2857 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 70: -#line 620 "src/ast-parser.y" /* yacc.c:1646 */ +#line 600 "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; + (yyval.block) = new Block(); + (yyval.block)->sig = std::move(*(yyvsp[-1].types)); + delete (yyvsp[-1].types); + (yyval.block)->first = (yyvsp[0].expr_list).first; } -#line 2861 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2868 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 71: -#line 628 "src/ast-parser.y" /* yacc.c:1646 */ +#line 609 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.expr_list) = (yyvsp[-1].expr_list); } -#line 2867 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2874 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 72: -#line 632 "src/ast-parser.y" /* yacc.c:1646 */ +#line 613 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.expr_list) = join_exprs2(&(yylsp[-1]), &(yyvsp[0].expr_list), (yyvsp[-1].expr)); } -#line 2875 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2882 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 73: -#line 635 "src/ast-parser.y" /* yacc.c:1646 */ +#line 616 "src/ast-parser.y" /* yacc.c:1646 */ { - Expr* expr = new_block_expr(); - expr->block = (yyvsp[0].block); - expr->block.label = (yyvsp[-1].text); + Expr* expr = Expr::CreateBlock((yyvsp[0].block)); + expr->block->label = (yyvsp[-1].text); (yyval.expr_list) = join_exprs1(&(yylsp[-2]), expr); } -#line 2886 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2892 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 74: -#line 641 "src/ast-parser.y" /* yacc.c:1646 */ +#line 621 "src/ast-parser.y" /* yacc.c:1646 */ { - Expr* expr = new_loop_expr(); - expr->loop = (yyvsp[0].block); - expr->loop.label = (yyvsp[-1].text); + Expr* expr = Expr::CreateLoop((yyvsp[0].block)); + expr->loop->label = (yyvsp[-1].text); (yyval.expr_list) = join_exprs1(&(yylsp[-2]), expr); } -#line 2897 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2902 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 75: -#line 647 "src/ast-parser.y" /* yacc.c:1646 */ +#line 626 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.expr_list) = (yyvsp[0].expr_list); Expr* if_ = (yyvsp[0].expr_list).last; assert(if_->type == ExprType::If); - if_->if_.true_.label = (yyvsp[-2].text); - if_->if_.true_.sig = (yyvsp[-1].types); + if_->if_.true_->label = (yyvsp[-2].text); + if_->if_.true_->sig = std::move(*(yyvsp[-1].types)); + delete (yyvsp[-1].types); } -#line 2909 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2915 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 76: -#line 656 "src/ast-parser.y" /* yacc.c:1646 */ +#line 636 "src/ast-parser.y" /* yacc.c:1646 */ { - Expr* expr = new_if_expr(); - expr->if_.true_.first = (yyvsp[-5].expr_list).first; - expr->if_.false_ = (yyvsp[-1].expr_list).first; + Expr* expr = Expr::CreateIf(new Block((yyvsp[-5].expr_list).first), (yyvsp[-1].expr_list).first); (yyval.expr_list) = join_exprs1(&(yylsp[-7]), expr); } -#line 2920 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2924 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 77: -#line 662 "src/ast-parser.y" /* yacc.c:1646 */ +#line 640 "src/ast-parser.y" /* yacc.c:1646 */ { - Expr* expr = new_if_expr(); - expr->if_.true_.first = (yyvsp[-1].expr_list).first; + Expr* expr = Expr::CreateIf(new Block((yyvsp[-1].expr_list).first), nullptr); (yyval.expr_list) = join_exprs1(&(yylsp[-3]), expr); } -#line 2930 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2933 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 78: -#line 667 "src/ast-parser.y" /* yacc.c:1646 */ +#line 644 "src/ast-parser.y" /* yacc.c:1646 */ { - Expr* expr = new_if_expr(); - expr->if_.true_.first = (yyvsp[-5].expr_list).first; - expr->if_.false_ = (yyvsp[-1].expr_list).first; + Expr* expr = Expr::CreateIf(new Block((yyvsp[-5].expr_list).first), (yyvsp[-1].expr_list).first); (yyval.expr_list) = join_exprs2(&(yylsp[-8]), &(yyvsp[-8].expr_list), expr); } -#line 2941 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2942 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 79: -#line 673 "src/ast-parser.y" /* yacc.c:1646 */ +#line 648 "src/ast-parser.y" /* yacc.c:1646 */ { - Expr* expr = new_if_expr(); - expr->if_.true_.first = (yyvsp[-1].expr_list).first; + Expr* expr = Expr::CreateIf(new Block((yyvsp[-1].expr_list).first), nullptr); (yyval.expr_list) = join_exprs2(&(yylsp[-4]), &(yyvsp[-4].expr_list), expr); } #line 2951 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 80: -#line 678 "src/ast-parser.y" /* yacc.c:1646 */ +#line 652 "src/ast-parser.y" /* yacc.c:1646 */ { - Expr* expr = new_if_expr(); - expr->if_.true_.first = (yyvsp[-1].expr_list).first; - expr->if_.false_ = (yyvsp[0].expr_list).first; + Expr* expr = Expr::CreateIf(new Block((yyvsp[-1].expr_list).first), (yyvsp[0].expr_list).first); (yyval.expr_list) = join_exprs2(&(yylsp[-2]), &(yyvsp[-2].expr_list), expr); } -#line 2962 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2960 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 81: -#line 684 "src/ast-parser.y" /* yacc.c:1646 */ +#line 656 "src/ast-parser.y" /* yacc.c:1646 */ { - Expr* expr = new_if_expr(); - expr->if_.true_.first = (yyvsp[0].expr_list).first; + Expr* expr = Expr::CreateIf(new Block((yyvsp[0].expr_list).first), nullptr); (yyval.expr_list) = join_exprs2(&(yylsp[-1]), &(yyvsp[-1].expr_list), expr); } -#line 2972 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2969 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 82: -#line 692 "src/ast-parser.y" /* yacc.c:1646 */ +#line 663 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.expr_list)); } -#line 2978 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2975 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 83: -#line 693 "src/ast-parser.y" /* yacc.c:1646 */ +#line 664 "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 2989 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2986 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 84: -#line 701 "src/ast-parser.y" /* yacc.c:1646 */ +#line 672 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.expr_list)); } -#line 2995 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 2992 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 85: -#line 702 "src/ast-parser.y" /* yacc.c:1646 */ +#line 673 "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 3006 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3003 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 88: -#line 716 "src/ast-parser.y" /* yacc.c:1646 */ +#line 687 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.func_fields) = new_func_field(); + (yyval.func_fields) = new FuncField(); (yyval.func_fields)->type = FuncFieldType::ResultTypes; (yyval.func_fields)->types = (yyvsp[-2].types); (yyval.func_fields)->next = (yyvsp[0].func_fields); } -#line 3017 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3014 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 89: -#line 722 "src/ast-parser.y" /* yacc.c:1646 */ +#line 693 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.func_fields) = new_func_field(); + (yyval.func_fields) = new FuncField(); (yyval.func_fields)->type = FuncFieldType::ParamTypes; (yyval.func_fields)->types = (yyvsp[-2].types); (yyval.func_fields)->next = (yyvsp[0].func_fields); } -#line 3028 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3025 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 90: -#line 728 "src/ast-parser.y" /* yacc.c:1646 */ +#line 699 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.func_fields) = new_func_field(); + (yyval.func_fields) = new FuncField(); (yyval.func_fields)->type = FuncFieldType::BoundParam; (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 3041 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3038 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 91: -#line 738 "src/ast-parser.y" /* yacc.c:1646 */ +#line 709 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.func_fields) = new_func_field(); + (yyval.func_fields) = new FuncField(); (yyval.func_fields)->type = FuncFieldType::Exprs; (yyval.func_fields)->first_expr = (yyvsp[0].expr_list).first; (yyval.func_fields)->next = nullptr; } -#line 3052 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3049 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 92: -#line 744 "src/ast-parser.y" /* yacc.c:1646 */ +#line 715 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.func_fields) = new_func_field(); + (yyval.func_fields) = new FuncField(); (yyval.func_fields)->type = FuncFieldType::LocalTypes; (yyval.func_fields)->types = (yyvsp[-2].types); (yyval.func_fields)->next = (yyvsp[0].func_fields); } -#line 3063 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3060 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 93: -#line 750 "src/ast-parser.y" /* yacc.c:1646 */ +#line 721 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.func_fields) = new_func_field(); + (yyval.func_fields) = new FuncField(); (yyval.func_fields)->type = FuncFieldType::BoundLocal; (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 3076 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3073 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 94: -#line 760 "src/ast-parser.y" /* yacc.c:1646 */ +#line 731 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.func) = new Func(); FuncField* field = (yyvsp[0].func_fields); @@ -3086,15 +3083,16 @@ yyreduce: switch (field->type) { case FuncFieldType::Exprs: (yyval.func)->first_expr = field->first_expr; + field->first_expr = nullptr; break; case FuncFieldType::ParamTypes: case FuncFieldType::LocalTypes: { - TypeVector* types = field->type == FuncFieldType::ParamTypes - ? &(yyval.func)->decl.sig.param_types - : &(yyval.func)->local_types; - extend_types(types, &field->types); - destroy_type_vector(&field->types); + TypeVector& types = field->type == FuncFieldType::ParamTypes + ? (yyval.func)->decl.sig.param_types + : (yyval.func)->local_types; + types.insert(types.end(), field->types->begin(), + field->types->end()); break; } @@ -3110,602 +3108,618 @@ yyreduce: bindings = &(yyval.func)->local_bindings; } - append_type_value(types, &field->bound_type.type); - bindings->emplace(string_slice_to_string(field->bound_type.name), - Binding(field->bound_type.loc, types->size - 1)); - destroy_string_slice(&field->bound_type.name); + types->push_back(field->bound_type.type); + bindings->emplace( + string_slice_to_string(field->bound_type.name), + Binding(field->bound_type.loc, types->size() - 1)); break; } case FuncFieldType::ResultTypes: - (yyval.func)->decl.sig.result_types = field->types; + (yyval.func)->decl.sig.result_types = std::move(*field->types); break; } - /* we steal memory from the func field, but not the linked list nodes */ delete field; field = next; } } -#line 3131 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3128 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 95: -#line 812 "src/ast-parser.y" /* yacc.c:1646 */ +#line 783 "src/ast-parser.y" /* yacc.c:1646 */ { - WABT_ZERO_MEMORY((yyval.exported_func)); - (yyval.exported_func).func = (yyvsp[-1].func); - (yyval.exported_func).func->decl.flags |= WABT_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; - (yyval.exported_func).func->decl.type_var = (yyvsp[-2].var); - (yyval.exported_func).func->name = (yyvsp[-4].text); - (yyval.exported_func).export_ = (yyvsp[-3].optional_export); + (yyval.exported_func) = new ExportedFunc(); + (yyval.exported_func)->func.reset((yyvsp[-1].func)); + (yyval.exported_func)->func->decl.has_func_type = true; + (yyval.exported_func)->func->decl.type_var = (yyvsp[-2].var); + (yyval.exported_func)->func->name = (yyvsp[-4].text); + (yyval.exported_func)->export_ = std::move(*(yyvsp[-3].optional_export)); + delete (yyvsp[-3].optional_export); } -#line 3144 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3142 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 96: -#line 821 "src/ast-parser.y" /* yacc.c:1646 */ +#line 793 "src/ast-parser.y" /* yacc.c:1646 */ { - WABT_ZERO_MEMORY((yyval.exported_func)); - (yyval.exported_func).func = (yyvsp[-1].func); - (yyval.exported_func).func->decl.flags |= WABT_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; - (yyval.exported_func).func->decl.type_var = (yyvsp[-2].var); - (yyval.exported_func).func->name = (yyvsp[-3].text); + (yyval.exported_func) = new ExportedFunc(); + (yyval.exported_func)->func.reset((yyvsp[-1].func)); + (yyval.exported_func)->func->decl.has_func_type = true; + (yyval.exported_func)->func->decl.type_var = (yyvsp[-2].var); + (yyval.exported_func)->func->name = (yyvsp[-3].text); } -#line 3156 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3154 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 97: -#line 828 "src/ast-parser.y" /* yacc.c:1646 */ +#line 800 "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); + (yyval.exported_func) = new ExportedFunc(); + (yyval.exported_func)->func.reset((yyvsp[-1].func)); + (yyval.exported_func)->func->name = (yyvsp[-3].text); + (yyval.exported_func)->export_ = std::move(*(yyvsp[-2].optional_export)); + delete (yyvsp[-2].optional_export); } -#line 3167 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3166 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 98: -#line 835 "src/ast-parser.y" /* yacc.c:1646 */ +#line 808 "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); + (yyval.exported_func) = new ExportedFunc(); + (yyval.exported_func)->func.reset((yyvsp[-1].func)); + (yyval.exported_func)->func->name = (yyvsp[-2].text); } -#line 3177 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3176 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 99: -#line 845 "src/ast-parser.y" /* yacc.c:1646 */ +#line 818 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.expr_list) = (yyvsp[-1].expr_list); } -#line 3185 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3184 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 101: -#line 852 "src/ast-parser.y" /* yacc.c:1646 */ +#line 825 "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); + (yyval.elem_segment) = new ElemSegment(); + (yyval.elem_segment)->table_var = (yyvsp[-3].var); + (yyval.elem_segment)->offset = (yyvsp[-2].expr_list).first; + (yyval.elem_segment)->vars = std::move(*(yyvsp[-1].vars)); + delete (yyvsp[-1].vars); } #line 3196 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 102: -#line 858 "src/ast-parser.y" /* yacc.c:1646 */ +#line 832 "src/ast-parser.y" /* yacc.c:1646 */ { - WABT_ZERO_MEMORY((yyval.elem_segment)); - (yyval.elem_segment).table_var.loc = (yylsp[-3]); - (yyval.elem_segment).table_var.type = VarType::Index; - (yyval.elem_segment).table_var.index = 0; - (yyval.elem_segment).offset = (yyvsp[-2].expr_list).first; - (yyval.elem_segment).vars = (yyvsp[-1].vars); + (yyval.elem_segment) = new ElemSegment(); + (yyval.elem_segment)->table_var.loc = (yylsp[-3]); + (yyval.elem_segment)->table_var.type = VarType::Index; + (yyval.elem_segment)->table_var.index = 0; + (yyval.elem_segment)->offset = (yyvsp[-2].expr_list).first; + (yyval.elem_segment)->vars = std::move(*(yyvsp[-1].vars)); + delete (yyvsp[-1].vars); } -#line 3209 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3210 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 103: -#line 869 "src/ast-parser.y" /* yacc.c:1646 */ +#line 844 "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 = false; - (yyval.exported_table).export_ = (yyvsp[-2].optional_export); + (yyval.exported_table) = new ExportedTable(); + (yyval.exported_table)->table.reset((yyvsp[-1].table)); + (yyval.exported_table)->table->name = (yyvsp[-3].text); + (yyval.exported_table)->has_elem_segment = false; + (yyval.exported_table)->export_ = std::move(*(yyvsp[-2].optional_export)); + delete (yyvsp[-2].optional_export); } -#line 3220 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3223 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 104: -#line 876 "src/ast-parser.y" /* yacc.c:1646 */ +#line 853 "src/ast-parser.y" /* yacc.c:1646 */ { - Expr* expr = new_const_expr(); + Expr* expr = Expr::CreateConst(Const(Const::I32(), 0)); expr->loc = (yylsp[-8]); - expr->const_.type = Type::I32; - expr->const_.u32 = 0; - WABT_ZERO_MEMORY((yyval.exported_table)); - (yyval.exported_table).table.name = (yyvsp[-7].text); - (yyval.exported_table).table.elem_limits.initial = (yyvsp[-2].vars).size; - (yyval.exported_table).table.elem_limits.max = (yyvsp[-2].vars).size; - (yyval.exported_table).table.elem_limits.has_max = true; - (yyval.exported_table).has_elem_segment = true; - (yyval.exported_table).elem_segment.offset = expr; - (yyval.exported_table).elem_segment.vars = (yyvsp[-2].vars); - (yyval.exported_table).export_ = (yyvsp[-6].optional_export); + (yyval.exported_table) = new ExportedTable(); + (yyval.exported_table)->table.reset(new Table()); + (yyval.exported_table)->table->name = (yyvsp[-7].text); + (yyval.exported_table)->table->elem_limits.initial = (yyvsp[-2].vars)->size(); + (yyval.exported_table)->table->elem_limits.max = (yyvsp[-2].vars)->size(); + (yyval.exported_table)->table->elem_limits.has_max = true; + (yyval.exported_table)->has_elem_segment = true; + (yyval.exported_table)->elem_segment.reset(new ElemSegment()); + (yyval.exported_table)->elem_segment->offset = expr; + (yyval.exported_table)->elem_segment->vars = std::move(*(yyvsp[-2].vars)); + delete (yyvsp[-2].vars); + (yyval.exported_table)->export_ = std::move(*(yyvsp[-6].optional_export)); + delete (yyvsp[-6].optional_export); } -#line 3241 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3246 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 105: -#line 895 "src/ast-parser.y" /* yacc.c:1646 */ +#line 874 "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(&(yyvsp[-1].text_list), &(yyval.data_segment).data, &(yyval.data_segment).size); + (yyval.data_segment) = new DataSegment(); + (yyval.data_segment)->memory_var = (yyvsp[-3].var); + (yyval.data_segment)->offset = (yyvsp[-2].expr_list).first; + dup_text_list(&(yyvsp[-1].text_list), &(yyval.data_segment)->data, &(yyval.data_segment)->size); destroy_text_list(&(yyvsp[-1].text_list)); } -#line 3253 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3258 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 106: -#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 = VarType::Index; - (yyval.data_segment).memory_var.index = 0; - (yyval.data_segment).offset = (yyvsp[-2].expr_list).first; - dup_text_list(&(yyvsp[-1].text_list), &(yyval.data_segment).data, &(yyval.data_segment).size); +#line 881 "src/ast-parser.y" /* yacc.c:1646 */ + { + (yyval.data_segment) = new DataSegment(); + (yyval.data_segment)->memory_var.loc = (yylsp[-3]); + (yyval.data_segment)->memory_var.type = VarType::Index; + (yyval.data_segment)->memory_var.index = 0; + (yyval.data_segment)->offset = (yyvsp[-2].expr_list).first; + dup_text_list(&(yyvsp[-1].text_list), &(yyval.data_segment)->data, &(yyval.data_segment)->size); destroy_text_list(&(yyvsp[-1].text_list)); } -#line 3267 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3272 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 107: -#line 914 "src/ast-parser.y" /* yacc.c:1646 */ +#line 893 "src/ast-parser.y" /* yacc.c:1646 */ { - WABT_ZERO_MEMORY((yyval.exported_memory)); - (yyval.exported_memory).memory = (yyvsp[-1].memory); - (yyval.exported_memory).memory.name = (yyvsp[-3].text); - (yyval.exported_memory).has_data_segment = false; - (yyval.exported_memory).export_ = (yyvsp[-2].optional_export); + (yyval.exported_memory) = new ExportedMemory(); + (yyval.exported_memory)->memory.reset((yyvsp[-1].memory)); + (yyval.exported_memory)->memory->name = (yyvsp[-3].text); + (yyval.exported_memory)->has_data_segment = false; + (yyval.exported_memory)->export_ = std::move(*(yyvsp[-2].optional_export)); + delete (yyvsp[-2].optional_export); } -#line 3279 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3285 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 108: -#line 921 "src/ast-parser.y" /* yacc.c:1646 */ +#line 901 "src/ast-parser.y" /* yacc.c:1646 */ { - Expr* expr = new_const_expr(); + Expr* expr = Expr::CreateConst(Const(Const::I32(), 0)); expr->loc = (yylsp[-7]); - expr->const_.type = Type::I32; - expr->const_.u32 = 0; - WABT_ZERO_MEMORY((yyval.exported_memory)); - (yyval.exported_memory).has_data_segment = true; - (yyval.exported_memory).data_segment.offset = expr; - dup_text_list(&(yyvsp[-2].text_list), &(yyval.exported_memory).data_segment.data, &(yyval.exported_memory).data_segment.size); + (yyval.exported_memory) = new ExportedMemory(); + (yyval.exported_memory)->has_data_segment = true; + (yyval.exported_memory)->data_segment.reset(new DataSegment()); + (yyval.exported_memory)->data_segment->offset = expr; + dup_text_list(&(yyvsp[-2].text_list), &(yyval.exported_memory)->data_segment->data, &(yyval.exported_memory)->data_segment->size); destroy_text_list(&(yyvsp[-2].text_list)); - uint32_t byte_size = WABT_ALIGN_UP_TO_PAGE((yyval.exported_memory).data_segment.size); + 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); - (yyval.exported_memory).memory.page_limits.initial = page_size; - (yyval.exported_memory).memory.page_limits.max = page_size; - (yyval.exported_memory).memory.page_limits.has_max = true; - (yyval.exported_memory).export_ = (yyvsp[-5].optional_export); + (yyval.exported_memory)->memory.reset(new Memory()); + (yyval.exported_memory)->memory->name = (yyvsp[-6].text); + (yyval.exported_memory)->memory->page_limits.initial = page_size; + (yyval.exported_memory)->memory->page_limits.max = page_size; + (yyval.exported_memory)->memory->page_limits.has_max = true; + (yyval.exported_memory)->export_ = std::move(*(yyvsp[-5].optional_export)); + delete (yyvsp[-5].optional_export); } -#line 3303 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3310 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 109: -#line 941 "src/ast-parser.y" /* yacc.c:1646 */ +#line 922 "src/ast-parser.y" /* yacc.c:1646 */ { - Expr* expr = new_const_expr(); + Expr* expr = Expr::CreateConst(Const(Const::I32(), 0)); expr->loc = (yylsp[-6]); - expr->const_.type = Type::I32; - expr->const_.u32 = 0; - WABT_ZERO_MEMORY((yyval.exported_memory)); - (yyval.exported_memory).has_data_segment = true; - (yyval.exported_memory).data_segment.offset = expr; - dup_text_list(&(yyvsp[-2].text_list), &(yyval.exported_memory).data_segment.data, &(yyval.exported_memory).data_segment.size); + (yyval.exported_memory) = new ExportedMemory(); + (yyval.exported_memory)->has_data_segment = true; + (yyval.exported_memory)->data_segment.reset(new DataSegment()); + (yyval.exported_memory)->data_segment->offset = expr; + dup_text_list(&(yyvsp[-2].text_list), &(yyval.exported_memory)->data_segment->data, &(yyval.exported_memory)->data_segment->size); destroy_text_list(&(yyvsp[-2].text_list)); - uint32_t byte_size = WABT_ALIGN_UP_TO_PAGE((yyval.exported_memory).data_segment.size); + 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); - (yyval.exported_memory).memory.page_limits.initial = page_size; - (yyval.exported_memory).memory.page_limits.max = page_size; - (yyval.exported_memory).memory.page_limits.has_max = true; - (yyval.exported_memory).export_.has_export = false; + (yyval.exported_memory)->memory.reset(new Memory()); + (yyval.exported_memory)->memory->name = (yyvsp[-5].text); + (yyval.exported_memory)->memory->page_limits.initial = page_size; + (yyval.exported_memory)->memory->page_limits.max = page_size; + (yyval.exported_memory)->memory->page_limits.has_max = true; + (yyval.exported_memory)->export_.has_export = false; } -#line 3327 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3334 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 110: -#line 963 "src/ast-parser.y" /* yacc.c:1646 */ +#line 944 "src/ast-parser.y" /* yacc.c:1646 */ { - WABT_ZERO_MEMORY((yyval.exported_global)); - (yyval.exported_global).global = (yyvsp[-2].global); - (yyval.exported_global).global.name = (yyvsp[-4].text); - (yyval.exported_global).global.init_expr = (yyvsp[-1].expr_list).first; - (yyval.exported_global).export_ = (yyvsp[-3].optional_export); + (yyval.exported_global) = new ExportedGlobal(); + (yyval.exported_global)->global.reset((yyvsp[-2].global)); + (yyval.exported_global)->global->name = (yyvsp[-4].text); + (yyval.exported_global)->global->init_expr = (yyvsp[-1].expr_list).first; + (yyval.exported_global)->export_ = std::move(*(yyvsp[-3].optional_export)); + delete (yyvsp[-3].optional_export); } -#line 3339 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3347 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 111: -#line 970 "src/ast-parser.y" /* yacc.c:1646 */ +#line 952 "src/ast-parser.y" /* yacc.c:1646 */ { - WABT_ZERO_MEMORY((yyval.exported_global)); - (yyval.exported_global).global = (yyvsp[-2].global); - (yyval.exported_global).global.name = (yyvsp[-3].text); - (yyval.exported_global).global.init_expr = (yyvsp[-1].expr_list).first; - (yyval.exported_global).export_.has_export = false; + (yyval.exported_global) = new ExportedGlobal(); + (yyval.exported_global)->global.reset((yyvsp[-2].global)); + (yyval.exported_global)->global->name = (yyvsp[-3].text); + (yyval.exported_global)->global->init_expr = (yyvsp[-1].expr_list).first; + (yyval.exported_global)->export_.has_export = false; } -#line 3351 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3359 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 112: -#line 983 "src/ast-parser.y" /* yacc.c:1646 */ +#line 965 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.import) = new_import(); + (yyval.import) = new Import(); (yyval.import)->kind = ExternalKind::Func; (yyval.import)->func = new Func(); (yyval.import)->func->name = (yyvsp[-2].text); - (yyval.import)->func->decl.flags = WABT_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; + (yyval.import)->func->decl.has_func_type = true; (yyval.import)->func->decl.type_var = (yyvsp[-1].var); } -#line 3364 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3372 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 113: -#line 991 "src/ast-parser.y" /* yacc.c:1646 */ +#line 973 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.import) = new_import(); + (yyval.import) = new Import(); (yyval.import)->kind = ExternalKind::Func; (yyval.import)->func = new Func(); (yyval.import)->func->name = (yyvsp[-2].text); - (yyval.import)->func->decl.sig = (yyvsp[-1].func_sig); + (yyval.import)->func->decl.sig = std::move(*(yyvsp[-1].func_sig)); + delete (yyvsp[-1].func_sig); } -#line 3376 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3385 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 114: -#line 998 "src/ast-parser.y" /* yacc.c:1646 */ +#line 981 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.import) = new_import(); + (yyval.import) = new Import(); (yyval.import)->kind = ExternalKind::Table; (yyval.import)->table = (yyvsp[-1].table); - (yyval.import)->table.name = (yyvsp[-2].text); + (yyval.import)->table->name = (yyvsp[-2].text); } -#line 3387 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3396 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 115: -#line 1004 "src/ast-parser.y" /* yacc.c:1646 */ +#line 987 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.import) = new_import(); + (yyval.import) = new Import(); (yyval.import)->kind = ExternalKind::Memory; (yyval.import)->memory = (yyvsp[-1].memory); - (yyval.import)->memory.name = (yyvsp[-2].text); + (yyval.import)->memory->name = (yyvsp[-2].text); } -#line 3398 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3407 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 116: -#line 1010 "src/ast-parser.y" /* yacc.c:1646 */ +#line 993 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.import) = new_import(); + (yyval.import) = new Import(); (yyval.import)->kind = ExternalKind::Global; (yyval.import)->global = (yyvsp[-1].global); - (yyval.import)->global.name = (yyvsp[-2].text); + (yyval.import)->global->name = (yyvsp[-2].text); } -#line 3409 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3418 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 117: -#line 1018 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1001 "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 3419 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3428 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 118: -#line 1023 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1006 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.import) = (yyvsp[-2].import); (yyval.import)->kind = ExternalKind::Func; (yyval.import)->func = new Func(); (yyval.import)->func->name = (yyvsp[-3].text); - (yyval.import)->func->decl.flags = WABT_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; + (yyval.import)->func->decl.has_func_type = true; (yyval.import)->func->decl.type_var = (yyvsp[-1].var); } -#line 3432 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3441 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 119: -#line 1031 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1014 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.import) = (yyvsp[-2].import); (yyval.import)->kind = ExternalKind::Func; (yyval.import)->func = new Func(); (yyval.import)->func->name = (yyvsp[-3].text); - (yyval.import)->func->decl.sig = (yyvsp[-1].func_sig); + (yyval.import)->func->decl.sig = std::move(*(yyvsp[-1].func_sig)); + delete (yyvsp[-1].func_sig); } -#line 3444 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3454 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 120: -#line 1038 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1022 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.import) = (yyvsp[-2].import); (yyval.import)->kind = ExternalKind::Table; (yyval.import)->table = (yyvsp[-1].table); - (yyval.import)->table.name = (yyvsp[-3].text); + (yyval.import)->table->name = (yyvsp[-3].text); } -#line 3455 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3465 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 121: -#line 1044 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1028 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.import) = (yyvsp[-2].import); (yyval.import)->kind = ExternalKind::Memory; (yyval.import)->memory = (yyvsp[-1].memory); - (yyval.import)->memory.name = (yyvsp[-3].text); + (yyval.import)->memory->name = (yyvsp[-3].text); } -#line 3466 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3476 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 122: -#line 1050 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1034 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.import) = (yyvsp[-2].import); (yyval.import)->kind = ExternalKind::Global; (yyval.import)->global = (yyvsp[-1].global); - (yyval.import)->global.name = (yyvsp[-3].text); + (yyval.import)->global->name = (yyvsp[-3].text); } -#line 3477 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3487 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 123: -#line 1059 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1043 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.import) = new_import(); + (yyval.import) = new Import(); (yyval.import)->module_name = (yyvsp[-2].text); (yyval.import)->field_name = (yyvsp[-1].text); } -#line 3487 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3497 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 124: -#line 1067 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1051 "src/ast-parser.y" /* yacc.c:1646 */ { - WABT_ZERO_MEMORY((yyval.export_)); - (yyval.export_).kind = ExternalKind::Func; - (yyval.export_).var = (yyvsp[-1].var); + (yyval.export_) = new Export(); + (yyval.export_)->kind = ExternalKind::Func; + (yyval.export_)->var = (yyvsp[-1].var); } -#line 3497 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3507 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 125: -#line 1072 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1056 "src/ast-parser.y" /* yacc.c:1646 */ { - WABT_ZERO_MEMORY((yyval.export_)); - (yyval.export_).kind = ExternalKind::Table; - (yyval.export_).var = (yyvsp[-1].var); + (yyval.export_) = new Export(); + (yyval.export_)->kind = ExternalKind::Table; + (yyval.export_)->var = (yyvsp[-1].var); } -#line 3507 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3517 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 126: -#line 1077 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1061 "src/ast-parser.y" /* yacc.c:1646 */ { - WABT_ZERO_MEMORY((yyval.export_)); - (yyval.export_).kind = ExternalKind::Memory; - (yyval.export_).var = (yyvsp[-1].var); + (yyval.export_) = new Export(); + (yyval.export_)->kind = ExternalKind::Memory; + (yyval.export_)->var = (yyvsp[-1].var); } -#line 3517 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3527 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 127: -#line 1082 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1066 "src/ast-parser.y" /* yacc.c:1646 */ { - WABT_ZERO_MEMORY((yyval.export_)); - (yyval.export_).kind = ExternalKind::Global; - (yyval.export_).var = (yyvsp[-1].var); + (yyval.export_) = new Export(); + (yyval.export_)->kind = ExternalKind::Global; + (yyval.export_)->var = (yyvsp[-1].var); } -#line 3527 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3537 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 128: -#line 1089 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1073 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.export_) = (yyvsp[-1].export_); - (yyval.export_).name = (yyvsp[-2].text); + (yyval.export_)->name = (yyvsp[-2].text); } -#line 3536 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3546 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 129: -#line 1096 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1080 "src/ast-parser.y" /* yacc.c:1646 */ { - WABT_ZERO_MEMORY((yyval.optional_export)); - (yyval.optional_export).has_export = false; + (yyval.optional_export) = new OptionalExport(); + (yyval.optional_export)->has_export = false; } -#line 3545 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3555 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 131: -#line 1103 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1087 "src/ast-parser.y" /* yacc.c:1646 */ { - WABT_ZERO_MEMORY((yyval.optional_export)); - (yyval.optional_export).has_export = true; - (yyval.optional_export).export_.name = (yyvsp[-1].text); + (yyval.optional_export) = new OptionalExport(); + (yyval.optional_export)->has_export = true; + (yyval.optional_export)->export_.reset(new Export()); + (yyval.optional_export)->export_->name = (yyvsp[-1].text); } -#line 3555 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3566 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 132: -#line 1114 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1099 "src/ast-parser.y" /* yacc.c:1646 */ { - WABT_ZERO_MEMORY((yyval.func_type)); - (yyval.func_type).sig = (yyvsp[-1].func_sig); + (yyval.func_type) = new FuncType(); + (yyval.func_type)->sig = std::move(*(yyvsp[-1].func_sig)); + delete (yyvsp[-1].func_sig); } -#line 3564 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3576 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 133: -#line 1118 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1104 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.func_type).name = (yyvsp[-2].text); - (yyval.func_type).sig = (yyvsp[-1].func_sig); + (yyval.func_type) = new FuncType(); + (yyval.func_type)->name = (yyvsp[-2].text); + (yyval.func_type)->sig = std::move(*(yyvsp[-1].func_sig)); + delete (yyvsp[-1].func_sig); } -#line 3573 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3587 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 134: -#line 1125 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1113 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.var) = (yyvsp[-1].var); } -#line 3579 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3593 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 135: -#line 1129 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1117 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.module) = new_module(); + (yyval.module) = new Module(); } -#line 3587 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3601 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 136: -#line 1132 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1120 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); ModuleField* field; APPEND_FIELD_TO_LIST((yyval.module), field, FuncType, func_type, (yylsp[0]), (yyvsp[0].func_type)); - APPEND_ITEM_TO_VECTOR((yyval.module), FuncType, func_type, func_types, - &field->func_type); - INSERT_BINDING((yyval.module), func_type, func_types, (yylsp[0]), (yyvsp[0].func_type).name); + APPEND_ITEM_TO_VECTOR((yyval.module), func_types, field->func_type); + INSERT_BINDING((yyval.module), func_type, func_types, (yylsp[0]), (yyvsp[0].func_type)->name); } -#line 3600 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3613 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 137: -#line 1140 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1127 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); ModuleField* field; - APPEND_FIELD_TO_LIST((yyval.module), field, Global, global, (yylsp[0]), (yyvsp[0].exported_global).global); - APPEND_ITEM_TO_VECTOR((yyval.module), Global, global, globals, &field->global); - 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); + APPEND_FIELD_TO_LIST((yyval.module), field, Global, global, (yylsp[0]), (yyvsp[0].exported_global)->global.release()); + APPEND_ITEM_TO_VECTOR((yyval.module), globals, field->global); + INSERT_BINDING((yyval.module), global, globals, (yylsp[0]), field->global->name); + APPEND_INLINE_EXPORT((yyval.module), Global, (yylsp[0]), (yyvsp[0].exported_global), (yyval.module)->globals.size() - 1); + delete (yyvsp[0].exported_global); } -#line 3613 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3627 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 138: -#line 1148 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1136 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); ModuleField* field; - APPEND_FIELD_TO_LIST((yyval.module), field, Table, table, (yylsp[0]), (yyvsp[0].exported_table).table); - APPEND_ITEM_TO_VECTOR((yyval.module), Table, table, tables, &field->table); - INSERT_BINDING((yyval.module), table, tables, (yylsp[0]), (yyvsp[0].exported_table).table.name); - APPEND_INLINE_EXPORT((yyval.module), Table, (yylsp[0]), (yyvsp[0].exported_table), (yyval.module)->tables.size - 1); + APPEND_FIELD_TO_LIST((yyval.module), field, Table, table, (yylsp[0]), (yyvsp[0].exported_table)->table.release()); + APPEND_ITEM_TO_VECTOR((yyval.module), tables, field->table); + INSERT_BINDING((yyval.module), table, tables, (yylsp[0]), field->table->name); + APPEND_INLINE_EXPORT((yyval.module), Table, (yylsp[0]), (yyvsp[0].exported_table), (yyval.module)->tables.size() - 1); - if ((yyvsp[0].exported_table).has_elem_segment) { + if ((yyvsp[0].exported_table)->has_elem_segment) { ModuleField* elem_segment_field; APPEND_FIELD_TO_LIST((yyval.module), elem_segment_field, ElemSegment, elem_segment, - (yylsp[0]), (yyvsp[0].exported_table).elem_segment); - APPEND_ITEM_TO_VECTOR((yyval.module), ElemSegment, elem_segment, elem_segments, - &elem_segment_field->elem_segment); + (yylsp[0]), (yyvsp[0].exported_table)->elem_segment.release()); + APPEND_ITEM_TO_VECTOR((yyval.module), elem_segments, + elem_segment_field->elem_segment); } - + delete (yyvsp[0].exported_table); } -#line 3635 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3649 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 139: -#line 1165 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1153 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); ModuleField* field; - APPEND_FIELD_TO_LIST((yyval.module), field, Memory, memory, (yylsp[0]), (yyvsp[0].exported_memory).memory); - APPEND_ITEM_TO_VECTOR((yyval.module), Memory, memory, memories, &field->memory); - INSERT_BINDING((yyval.module), memory, memories, (yylsp[0]), (yyvsp[0].exported_memory).memory.name); - APPEND_INLINE_EXPORT((yyval.module), Memory, (yylsp[0]), (yyvsp[0].exported_memory), (yyval.module)->memories.size - 1); + APPEND_FIELD_TO_LIST((yyval.module), field, Memory, memory, (yylsp[0]), (yyvsp[0].exported_memory)->memory.release()); + APPEND_ITEM_TO_VECTOR((yyval.module), memories, field->memory); + INSERT_BINDING((yyval.module), memory, memories, (yylsp[0]), field->memory->name); + APPEND_INLINE_EXPORT((yyval.module), Memory, (yylsp[0]), (yyvsp[0].exported_memory), (yyval.module)->memories.size() - 1); - if ((yyvsp[0].exported_memory).has_data_segment) { + if ((yyvsp[0].exported_memory)->has_data_segment) { ModuleField* data_segment_field; APPEND_FIELD_TO_LIST((yyval.module), data_segment_field, DataSegment, data_segment, - (yylsp[0]), (yyvsp[0].exported_memory).data_segment); - APPEND_ITEM_TO_VECTOR((yyval.module), DataSegment, data_segment, data_segments, - &data_segment_field->data_segment); + (yylsp[0]), (yyvsp[0].exported_memory)->data_segment.release()); + APPEND_ITEM_TO_VECTOR((yyval.module), data_segments, + data_segment_field->data_segment); } + delete (yyvsp[0].exported_memory); } -#line 3656 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3671 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 140: -#line 1181 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1170 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); ModuleField* field; - APPEND_FIELD_TO_LIST((yyval.module), field, Func, func, (yylsp[0]), (yyvsp[0].exported_func).func); + APPEND_FIELD_TO_LIST((yyval.module), field, Func, func, (yylsp[0]), (yyvsp[0].exported_func)->func.release()); 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); + APPEND_ITEM_TO_VECTOR((yyval.module), funcs, field->func); + INSERT_BINDING((yyval.module), func, funcs, (yylsp[0]), field->func->name); + APPEND_INLINE_EXPORT((yyval.module), Func, (yylsp[0]), (yyvsp[0].exported_func), (yyval.module)->funcs.size() - 1); + delete (yyvsp[0].exported_func); } -#line 3670 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3686 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 141: -#line 1190 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1180 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); ModuleField* field; APPEND_FIELD_TO_LIST((yyval.module), field, ElemSegment, elem_segment, (yylsp[0]), (yyvsp[0].elem_segment)); - APPEND_ITEM_TO_VECTOR((yyval.module), ElemSegment, elem_segment, elem_segments, - &field->elem_segment); + APPEND_ITEM_TO_VECTOR((yyval.module), elem_segments, field->elem_segment); } -#line 3682 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3697 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 142: -#line 1197 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1186 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); ModuleField* field; APPEND_FIELD_TO_LIST((yyval.module), field, DataSegment, data_segment, (yylsp[0]), (yyvsp[0].data_segment)); - APPEND_ITEM_TO_VECTOR((yyval.module), DataSegment, data_segment, data_segments, - &field->data_segment); + APPEND_ITEM_TO_VECTOR((yyval.module), data_segments, field->data_segment); } -#line 3694 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3708 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 143: -#line 1204 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1192 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); ModuleField* field; APPEND_FIELD_TO_LIST((yyval.module), field, Start, start, (yylsp[0]), (yyvsp[0].var)); (yyval.module)->start = &field->start; } -#line 3705 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3719 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 144: -#line 1210 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1198 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); ModuleField* field; @@ -3717,292 +3731,292 @@ yyreduce: switch ((yyvsp[0].import)->kind) { case ExternalKind::Func: append_implicit_func_declaration(&(yylsp[0]), (yyval.module), &field->import->func->decl); - APPEND_ITEM_TO_VECTOR((yyval.module), Func, func, funcs, field->import->func); + APPEND_ITEM_TO_VECTOR((yyval.module), funcs, field->import->func); INSERT_BINDING((yyval.module), func, funcs, (yylsp[0]), field->import->func->name); (yyval.module)->num_func_imports++; break; case ExternalKind::Table: - APPEND_ITEM_TO_VECTOR((yyval.module), Table, table, tables, - &field->import->table); - INSERT_BINDING((yyval.module), table, tables, (yylsp[0]), field->import->table.name); + APPEND_ITEM_TO_VECTOR((yyval.module), tables, field->import->table); + INSERT_BINDING((yyval.module), table, tables, (yylsp[0]), field->import->table->name); (yyval.module)->num_table_imports++; break; case ExternalKind::Memory: - APPEND_ITEM_TO_VECTOR((yyval.module), Memory, memory, memories, - &field->import->memory); - INSERT_BINDING((yyval.module), memory, memories, (yylsp[0]), field->import->memory.name); + APPEND_ITEM_TO_VECTOR((yyval.module), memories, field->import->memory); + INSERT_BINDING((yyval.module), memory, memories, (yylsp[0]), field->import->memory->name); (yyval.module)->num_memory_imports++; break; case ExternalKind::Global: - APPEND_ITEM_TO_VECTOR((yyval.module), Global, global, globals, - &field->import->global); - INSERT_BINDING((yyval.module), global, globals, (yylsp[0]), field->import->global.name); + APPEND_ITEM_TO_VECTOR((yyval.module), globals, field->import->global); + INSERT_BINDING((yyval.module), global, globals, (yylsp[0]), field->import->global->name); (yyval.module)->num_global_imports++; break; } - APPEND_ITEM_TO_VECTOR((yyval.module), Import, import, imports, field->import); + APPEND_ITEM_TO_VECTOR((yyval.module), imports, field->import); } -#line 3746 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3757 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 145: -#line 1246 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1231 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); ModuleField* field; 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); + APPEND_ITEM_TO_VECTOR((yyval.module), exports, field->export_); + INSERT_BINDING((yyval.module), export, exports, (yylsp[0]), field->export_->name); } -#line 3758 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3769 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 146: -#line 1256 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1241 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.raw_module).type = RawModuleType::Text; - (yyval.raw_module).text = (yyvsp[-1].module); - (yyval.raw_module).text->name = (yyvsp[-2].text); - (yyval.raw_module).text->loc = (yylsp[-3]); + (yyval.raw_module) = new RawModule(); + (yyval.raw_module)->type = RawModuleType::Text; + (yyval.raw_module)->text = (yyvsp[-1].module); + (yyval.raw_module)->text->name = (yyvsp[-2].text); + (yyval.raw_module)->text->loc = (yylsp[-3]); /* resolve func type variables where the signature was not specified * explicitly */ - for (size_t i = 0; i < (yyvsp[-1].module)->funcs.size; ++i) { - Func* func = (yyvsp[-1].module)->funcs.data[i]; + for (Func* func: (yyvsp[-1].module)->funcs) { if (decl_has_func_type(&func->decl) && is_empty_signature(&func->decl.sig)) { FuncType* func_type = get_func_type_by_var((yyvsp[-1].module), &func->decl.type_var); if (func_type) { func->decl.sig = func_type->sig; - func->decl.flags |= WABT_FUNC_DECLARATION_FLAG_SHARED_SIGNATURE; } } } } -#line 3784 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3794 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 147: -#line 1277 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1261 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.raw_module).type = RawModuleType::Binary; - (yyval.raw_module).binary.name = (yyvsp[-2].text); - (yyval.raw_module).binary.loc = (yylsp[-3]); - dup_text_list(&(yyvsp[-1].text_list), &(yyval.raw_module).binary.data, &(yyval.raw_module).binary.size); + (yyval.raw_module) = new RawModule(); + (yyval.raw_module)->type = RawModuleType::Binary; + (yyval.raw_module)->binary.name = (yyvsp[-2].text); + (yyval.raw_module)->binary.loc = (yylsp[-3]); + dup_text_list(&(yyvsp[-1].text_list), &(yyval.raw_module)->binary.data, &(yyval.raw_module)->binary.size); destroy_text_list(&(yyvsp[-1].text_list)); } -#line 3796 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3807 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 148: -#line 1287 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1272 "src/ast-parser.y" /* yacc.c:1646 */ { - if ((yyvsp[0].raw_module).type == RawModuleType::Text) { - (yyval.module) = (yyvsp[0].raw_module).text; + if ((yyvsp[0].raw_module)->type == RawModuleType::Text) { + (yyval.module) = (yyvsp[0].raw_module)->text; + (yyvsp[0].raw_module)->text = nullptr; } else { - assert((yyvsp[0].raw_module).type == RawModuleType::Binary); - (yyval.module) = new_module(); + assert((yyvsp[0].raw_module)->type == RawModuleType::Binary); + (yyval.module) = new Module(); ReadBinaryOptions options = WABT_READ_BINARY_OPTIONS_DEFAULT; BinaryErrorCallbackData user_data; - user_data.loc = &(yyvsp[0].raw_module).binary.loc; + user_data.loc = &(yyvsp[0].raw_module)->binary.loc; user_data.lexer = lexer; user_data.parser = parser; BinaryErrorHandler error_handler; error_handler.on_error = on_read_binary_error; error_handler.user_data = &user_data; - read_binary_ast((yyvsp[0].raw_module).binary.data, (yyvsp[0].raw_module).binary.size, &options, - &error_handler, (yyval.module)); - delete [] (yyvsp[0].raw_module).binary.data; - (yyval.module)->name = (yyvsp[0].raw_module).binary.name; - (yyval.module)->loc = (yyvsp[0].raw_module).binary.loc; + read_binary_ast((yyvsp[0].raw_module)->binary.data, (yyvsp[0].raw_module)->binary.size, &options, + &error_handler, (yyval.module)); + (yyval.module)->name = (yyvsp[0].raw_module)->binary.name; + (yyval.module)->loc = (yyvsp[0].raw_module)->binary.loc; + WABT_ZERO_MEMORY((yyvsp[0].raw_module)->binary.name); } + delete (yyvsp[0].raw_module); } -#line 3822 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3835 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 149: -#line 1313 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1300 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.var)); (yyval.var).type = VarType::Index; (yyval.var).index = INVALID_VAR_INDEX; } -#line 3832 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3845 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 150: -#line 1318 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1305 "src/ast-parser.y" /* yacc.c:1646 */ { WABT_ZERO_MEMORY((yyval.var)); (yyval.var).type = VarType::Name; DUPTEXT((yyval.var).name, (yyvsp[0].text)); } -#line 3842 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3855 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 151: -#line 1326 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1313 "src/ast-parser.y" /* yacc.c:1646 */ { - WABT_ZERO_MEMORY((yyval.action)); - (yyval.action).loc = (yylsp[-4]); - (yyval.action).module_var = (yyvsp[-3].var); - (yyval.action).type = ActionType::Invoke; - (yyval.action).invoke.name = (yyvsp[-2].text); - (yyval.action).invoke.args = (yyvsp[-1].consts); + (yyval.action) = new Action(); + (yyval.action)->loc = (yylsp[-4]); + (yyval.action)->module_var = (yyvsp[-3].var); + (yyval.action)->type = ActionType::Invoke; + (yyval.action)->name = (yyvsp[-2].text); + (yyval.action)->invoke = new ActionInvoke(); + (yyval.action)->invoke->args = std::move(*(yyvsp[-1].consts)); + delete (yyvsp[-1].consts); } -#line 3855 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3870 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 152: -#line 1334 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1323 "src/ast-parser.y" /* yacc.c:1646 */ { - WABT_ZERO_MEMORY((yyval.action)); - (yyval.action).loc = (yylsp[-3]); - (yyval.action).module_var = (yyvsp[-2].var); - (yyval.action).type = ActionType::Get; - (yyval.action).invoke.name = (yyvsp[-1].text); + (yyval.action) = new Action(); + (yyval.action)->loc = (yylsp[-3]); + (yyval.action)->module_var = (yyvsp[-2].var); + (yyval.action)->type = ActionType::Get; + (yyval.action)->name = (yyvsp[-1].text); } -#line 3867 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3882 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 153: -#line 1344 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1333 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.command) = new_command(); + (yyval.command) = new Command(); (yyval.command)->type = CommandType::AssertMalformed; (yyval.command)->assert_malformed.module = (yyvsp[-2].raw_module); (yyval.command)->assert_malformed.text = (yyvsp[-1].text); } -#line 3878 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3893 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 154: -#line 1350 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1339 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.command) = new_command(); + (yyval.command) = new Command(); (yyval.command)->type = CommandType::AssertInvalid; (yyval.command)->assert_invalid.module = (yyvsp[-2].raw_module); (yyval.command)->assert_invalid.text = (yyvsp[-1].text); } -#line 3889 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3904 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 155: -#line 1356 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1345 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.command) = new_command(); + (yyval.command) = new Command(); (yyval.command)->type = CommandType::AssertUnlinkable; (yyval.command)->assert_unlinkable.module = (yyvsp[-2].raw_module); (yyval.command)->assert_unlinkable.text = (yyvsp[-1].text); } -#line 3900 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3915 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 156: -#line 1362 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1351 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.command) = new_command(); + (yyval.command) = new Command(); (yyval.command)->type = CommandType::AssertUninstantiable; (yyval.command)->assert_uninstantiable.module = (yyvsp[-2].raw_module); (yyval.command)->assert_uninstantiable.text = (yyvsp[-1].text); } -#line 3911 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3926 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 157: -#line 1368 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1357 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.command) = new_command(); + (yyval.command) = new Command(); (yyval.command)->type = CommandType::AssertReturn; (yyval.command)->assert_return.action = (yyvsp[-2].action); (yyval.command)->assert_return.expected = (yyvsp[-1].consts); } -#line 3922 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3937 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 158: -#line 1374 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1363 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.command) = new_command(); + (yyval.command) = new Command(); (yyval.command)->type = CommandType::AssertReturnNan; (yyval.command)->assert_return_nan.action = (yyvsp[-1].action); } -#line 3932 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3947 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 159: -#line 1379 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1368 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.command) = new_command(); + (yyval.command) = new Command(); (yyval.command)->type = CommandType::AssertTrap; (yyval.command)->assert_trap.action = (yyvsp[-2].action); (yyval.command)->assert_trap.text = (yyvsp[-1].text); } -#line 3943 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3958 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 160: -#line 1385 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1374 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.command) = new_command(); + (yyval.command) = new Command(); (yyval.command)->type = CommandType::AssertExhaustion; (yyval.command)->assert_trap.action = (yyvsp[-2].action); (yyval.command)->assert_trap.text = (yyvsp[-1].text); } -#line 3954 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3969 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 161: -#line 1394 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1383 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.command) = new_command(); + (yyval.command) = new Command(); (yyval.command)->type = CommandType::Action; (yyval.command)->action = (yyvsp[0].action); } -#line 3964 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3979 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 163: -#line 1400 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1389 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.command) = new_command(); + (yyval.command) = new Command(); (yyval.command)->type = CommandType::Module; (yyval.command)->module = (yyvsp[0].module); } -#line 3974 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 3989 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 164: -#line 1405 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1394 "src/ast-parser.y" /* yacc.c:1646 */ { - (yyval.command) = new_command(); + (yyval.command) = new Command(); (yyval.command)->type = CommandType::Register; (yyval.command)->register_.module_name = (yyvsp[-2].text); (yyval.command)->register_.var = (yyvsp[-1].var); (yyval.command)->register_.var.loc = (yylsp[-1]); } -#line 3986 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 4001 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 165: -#line 1414 "src/ast-parser.y" /* yacc.c:1646 */ - { WABT_ZERO_MEMORY((yyval.commands)); } -#line 3992 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 1403 "src/ast-parser.y" /* yacc.c:1646 */ + { (yyval.commands) = new CommandPtrVector(); } +#line 4007 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 166: -#line 1415 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1404 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.commands) = (yyvsp[-1].commands); - append_command_value(&(yyval.commands), (yyvsp[0].command)); - delete (yyvsp[0].command); + (yyval.commands)->emplace_back((yyvsp[0].command)); } -#line 4002 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 4016 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 167: -#line 1423 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1411 "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, @@ -4013,40 +4027,41 @@ yyreduce: } delete [] (yyvsp[-1].literal).text.start; } -#line 4017 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 4031 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 168: -#line 1435 "src/ast-parser.y" /* yacc.c:1646 */ - { WABT_ZERO_MEMORY((yyval.consts)); } -#line 4023 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 1423 "src/ast-parser.y" /* yacc.c:1646 */ + { (yyval.consts) = new ConstVector(); } +#line 4037 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 169: -#line 1436 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1424 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.consts) = (yyvsp[-1].consts); - append_const_value(&(yyval.consts), &(yyvsp[0].const_)); + (yyval.consts)->push_back((yyvsp[0].const_)); } -#line 4032 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 4046 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; case 170: -#line 1443 "src/ast-parser.y" /* yacc.c:1646 */ +#line 1431 "src/ast-parser.y" /* yacc.c:1646 */ { (yyval.script) = new Script(); - (yyval.script)->commands = (yyvsp[0].commands); + (yyval.script)->commands = std::move(*(yyvsp[0].commands)); + delete (yyvsp[0].commands); int last_module_index = -1; - for (size_t i = 0; i < (yyval.script)->commands.size; ++i) { - Command* command = &(yyval.script)->commands.data[i]; + for (size_t i = 0; i < (yyval.script)->commands.size(); ++i) { + Command& command = *(yyval.script)->commands[i].get(); Var* module_var = nullptr; - switch (command->type) { + switch (command.type) { case CommandType::Module: { last_module_index = i; /* Wire up module name bindings. */ - Module* module = command->module; + Module* module = command.module; if (module->name.length == 0) continue; @@ -4056,20 +4071,20 @@ yyreduce: } case CommandType::AssertReturn: - module_var = &command->assert_return.action.module_var; + module_var = &command.assert_return.action->module_var; goto has_module_var; case CommandType::AssertReturnNan: - module_var = &command->assert_return_nan.action.module_var; + module_var = &command.assert_return_nan.action->module_var; goto has_module_var; case CommandType::AssertTrap: case CommandType::AssertExhaustion: - module_var = &command->assert_trap.action.module_var; + module_var = &command.assert_trap.action->module_var; goto has_module_var; case CommandType::Action: - module_var = &command->action.module_var; + module_var = &command.action->module_var; goto has_module_var; case CommandType::Register: - module_var = &command->register_.var; + module_var = &command.register_.var; goto has_module_var; has_module_var: { @@ -4088,11 +4103,11 @@ yyreduce: } parser->script = (yyval.script); } -#line 4092 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 4107 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; -#line 4096 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ +#line 4111 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -4327,7 +4342,7 @@ yyreturn: #endif return yyresult; } -#line 1506 "src/ast-parser.y" /* yacc.c:1906 */ +#line 1495 "src/ast-parser.y" /* yacc.c:1906 */ void append_expr_list(ExprList* expr_list, ExprList* expr) { @@ -4460,8 +4475,8 @@ void dup_text_list(TextList* text_list, char** out_data, size_t* out_size) { *out_size = dest - result; } -bool is_empty_signature(FuncSignature* sig) { - return sig->result_types.size == 0 && sig->param_types.size == 0; +bool is_empty_signature(const FuncSignature* sig) { + return sig->result_types.empty() && sig->param_types.empty(); } void append_implicit_func_declaration(Location* loc, @@ -4474,13 +4489,8 @@ void append_implicit_func_declaration(Location* loc, if (sig_index == -1) { append_implicit_func_type(loc, module, &decl->sig); } else { - /* signature already exists, share that one and destroy this one */ - destroy_func_signature(&decl->sig); - FuncSignature* sig = &module->func_types.data[sig_index]->sig; - decl->sig = *sig; + decl->sig = module->func_types[sig_index]->sig; } - - decl->flags |= WABT_FUNC_DECLARATION_FLAG_SHARED_SIGNATURE; } Result parse_ast(AstLexer* lexer, Script** out_script, diff --git a/src/resolve-names.cc b/src/resolve-names.cc index 98f1646c..045505eb 100644 --- a/src/resolve-names.cc +++ b/src/resolve-names.cc @@ -27,19 +27,24 @@ namespace wabt { namespace { typedef Label* LabelPtr; -WABT_DEFINE_VECTOR(label_ptr, LabelPtr); struct Context { - SourceErrorHandler* error_handler; - AstLexer* lexer; - Script* script; - Module* current_module; - Func* current_func; + Context(); + + SourceErrorHandler* error_handler = nullptr; + AstLexer* lexer = nullptr; + Script* script = nullptr; + Module* current_module = nullptr; + Func* current_func = nullptr; ExprVisitor visitor; - LabelPtrVector labels; - Result result; + std::vector<Label*> labels; + Result result = Result::Ok; }; +Context::Context() { + WABT_ZERO_MEMORY(visitor); +} + } // namespace static void WABT_PRINTF_FORMAT(3, 4) @@ -52,12 +57,11 @@ static void WABT_PRINTF_FORMAT(3, 4) } static void push_label(Context* ctx, Label* label) { - append_label_ptr_value(&ctx->labels, &label); + ctx->labels.push_back(label); } static void pop_label(Context* ctx) { - assert(ctx->labels.size > 0); - ctx->labels.size--; + ctx->labels.pop_back(); } struct FindDuplicateBindingContext { @@ -89,12 +93,12 @@ static void check_duplicate_bindings(Context* ctx, static void resolve_label_var(Context* ctx, Var* var) { if (var->type == VarType::Name) { - for (int i = ctx->labels.size - 1; i >= 0; --i) { - Label* label = ctx->labels.data[i]; + for (int i = ctx->labels.size() - 1; i >= 0; --i) { + Label* label = ctx->labels[i]; if (string_slices_are_equal(label, &var->name)) { destroy_string_slice(&var->name); var->type = VarType::Index; - var->index = ctx->labels.size - i - 1; + var->index = ctx->labels.size() - i - 1; return; } } @@ -162,7 +166,7 @@ static void resolve_local_var(Context* ctx, Var* var) { static Result begin_block_expr(Expr* expr, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - push_label(ctx, &expr->block.label); + push_label(ctx, &expr->block->label); return Result::Ok; } @@ -174,7 +178,7 @@ static Result end_block_expr(Expr* expr, void* user_data) { static Result begin_loop_expr(Expr* expr, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - push_label(ctx, &expr->loop.label); + push_label(ctx, &expr->loop->label); return Result::Ok; } @@ -198,12 +202,8 @@ static Result on_br_if_expr(Expr* expr, void* user_data) { static Result on_br_table_expr(Expr* expr, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - VarVector* targets = &expr->br_table.targets; - for (size_t i = 0; i < targets->size; ++i) { - Var* target = &targets->data[i]; - resolve_label_var(ctx, target); - } - + for (Var& target: *expr->br_table.targets) + resolve_label_var(ctx, &target); resolve_label_var(ctx, &expr->br_table.default_target); return Result::Ok; } @@ -234,7 +234,7 @@ static Result on_get_local_expr(Expr* expr, void* user_data) { static Result begin_if_expr(Expr* expr, void* user_data) { Context* ctx = static_cast<Context*>(user_data); - push_label(ctx, &expr->if_.true_.label); + push_label(ctx, &expr->if_.true_->label); return Result::Ok; } @@ -301,8 +301,8 @@ static void visit_global(Context* ctx, Global* global) { static void visit_elem_segment(Context* ctx, ElemSegment* segment) { resolve_table_var(ctx, &segment->table_var); visit_expr_list(segment->offset, &ctx->visitor); - for (size_t i = 0; i < segment->vars.size; ++i) - resolve_func_var(ctx, &segment->vars.data[i]); + for (Var& var: segment->vars) + resolve_func_var(ctx, &var); } static void visit_data_segment(Context* ctx, DataSegment* segment) { @@ -318,16 +318,16 @@ static void visit_module(Context* ctx, Module* module) { check_duplicate_bindings(ctx, &module->table_bindings, "table"); check_duplicate_bindings(ctx, &module->memory_bindings, "memory"); - for (size_t i = 0; i < module->funcs.size; ++i) - visit_func(ctx, module->funcs.data[i]); - for (size_t i = 0; i < module->exports.size; ++i) - visit_export(ctx, module->exports.data[i]); - for (size_t i = 0; i < module->globals.size; ++i) - visit_global(ctx, module->globals.data[i]); - for (size_t i = 0; i < module->elem_segments.size; ++i) - visit_elem_segment(ctx, module->elem_segments.data[i]); - for (size_t i = 0; i < module->data_segments.size; ++i) - visit_data_segment(ctx, module->data_segments.data[i]); + for (Func* func : module->funcs) + visit_func(ctx, func); + for (Export* export_ : module->exports) + visit_export(ctx, export_); + for (Global* global : module->globals) + visit_global(ctx, global); + for (ElemSegment* elem_segment : module->elem_segments) + visit_elem_segment(ctx, elem_segment); + for (DataSegment* data_segment : module->data_segments) + visit_data_segment(ctx, data_segment); if (module->start) resolve_func_var(ctx, module->start); ctx->current_module = nullptr; @@ -378,15 +378,13 @@ static void visit_command(Context* ctx, Command* command) { ctx->error_handler->source_line_max_length; Context new_ctx; - WABT_ZERO_MEMORY(new_ctx); new_ctx.error_handler = &new_error_handler; new_ctx.lexer = ctx->lexer; new_ctx.visitor = ctx->visitor; new_ctx.visitor.user_data = &new_ctx; new_ctx.result = Result::Ok; - visit_raw_module(&new_ctx, &command->assert_invalid.module); - destroy_label_ptr_vector(&new_ctx.labels); + visit_raw_module(&new_ctx, command->assert_invalid.module); if (WABT_FAILED(new_ctx.result)) { command->type = CommandType::AssertInvalidNonBinary; } @@ -400,25 +398,24 @@ static void visit_command(Context* ctx, Command* command) { break; case CommandType::AssertUnlinkable: - visit_raw_module(ctx, &command->assert_unlinkable.module); + visit_raw_module(ctx, command->assert_unlinkable.module); break; case CommandType::AssertUninstantiable: - visit_raw_module(ctx, &command->assert_uninstantiable.module); + visit_raw_module(ctx, command->assert_uninstantiable.module); break; } } static void visit_script(Context* ctx, Script* script) { - for (size_t i = 0; i < script->commands.size; ++i) - visit_command(ctx, &script->commands.data[i]); + for (const std::unique_ptr<Command>& command: script->commands) + visit_command(ctx, command.get()); } static void init_context(Context* ctx, AstLexer* lexer, Script* script, SourceErrorHandler* error_handler) { - WABT_ZERO_MEMORY(*ctx); ctx->lexer = lexer; ctx->error_handler = error_handler; ctx->result = Result::Ok; @@ -448,7 +445,6 @@ Result resolve_names_module(AstLexer* lexer, Context ctx; init_context(&ctx, lexer, nullptr, error_handler); visit_module(&ctx, module); - destroy_label_ptr_vector(&ctx.labels); return ctx.result; } @@ -458,7 +454,6 @@ Result resolve_names_script(AstLexer* lexer, Context ctx; init_context(&ctx, lexer, script, error_handler); visit_script(&ctx, script); - destroy_label_ptr_vector(&ctx.labels); return ctx.result; } diff --git a/src/tools/wasm-interp.cc b/src/tools/wasm-interp.cc index 2c667ae4..f006f7ba 100644 --- a/src/tools/wasm-interp.cc +++ b/src/tools/wasm-interp.cc @@ -19,6 +19,8 @@ #include <stdio.h> #include <stdlib.h> +#include <vector> + #include "binary-reader.h" #include "binary-reader-interpreter.h" #include "interpreter.h" @@ -412,11 +414,10 @@ static void run_all_exports(InterpreterModule* module, RunVerbosity verbose) { std::vector<InterpreterTypedValue> args; std::vector<InterpreterTypedValue> results; - for (uint32_t i = 0; i < module->exports.size(); ++i) { - InterpreterExport* export_ = &module->exports[i]; - InterpreterResult iresult = run_export(thread, export_, args, &results); + for (const InterpreterExport& export_: module->exports) { + InterpreterResult iresult = run_export(thread, &export_, args, &results); if (verbose == RunVerbosity::Verbose) { - print_call(empty_string_slice(), export_->name, args, results, iresult); + print_call(empty_string_slice(), export_.name, args, results, iresult); } } } @@ -596,8 +597,6 @@ static Result read_and_run_module(const char* module_filename) { return result; } -WABT_DEFINE_VECTOR(interpreter_thread, InterpreterThread); - /* An extremely simple JSON parser that only knows how to parse the expected * format from wast2wabt. */ struct Context { @@ -882,7 +881,7 @@ static Result parse_type_object(Context* ctx, Type* out_type) { } static Result parse_type_vector(Context* ctx, TypeVector* out_types) { - WABT_ZERO_MEMORY(*out_types); + out_types->clear(); EXPECT("["); bool first = true; while (!match(ctx, "]")) { @@ -891,7 +890,7 @@ static Result parse_type_vector(Context* ctx, TypeVector* out_types) { Type type; CHECK_RESULT(parse_type_object(ctx, &type)); first = false; - append_type_value(out_types, &type); + out_types->push_back(type); } return Result::Ok; } @@ -1540,7 +1539,6 @@ static Result parse_command(Context* ctx) { EXPECT_KEY("expected"); CHECK_RESULT(parse_type_vector(ctx, &expected)); on_assert_return_nan_command(ctx, &action); - destroy_type_vector(&expected); } else if (match(ctx, "\"assert_trap\"")) { Action action; StringSlice text; diff --git a/src/tools/wasm-link.cc b/src/tools/wasm-link.cc index 95506459..577dff45 100644 --- a/src/tools/wasm-link.cc +++ b/src/tools/wasm-link.cc @@ -21,10 +21,12 @@ #include "binary-writer.h" #include "option-parser.h" #include "stream.h" -#include "vector.h" #include "writer.h" #include "binary-reader-linker.h" +#include <memory> +#include <vector> + #define PROGRAM_NAME "wasm-link" #define NOPE HasArgument::No #define YEP HasArgument::Yes @@ -50,20 +52,22 @@ static Option s_options[] = { }; WABT_STATIC_ASSERT(NUM_FLAGS == WABT_ARRAY_SIZE(s_options)); -typedef const char* String; -WABT_DEFINE_VECTOR(string, String); - static bool s_debug; static bool s_relocatable; static const char* s_outfile = "a.wasm"; -static StringVector s_infiles; +static std::vector<std::string> s_infiles; static FileWriter s_log_stream_writer; static Stream s_log_stream; struct Context { + WABT_DISALLOW_COPY_AND_ASSIGN(Context); + Context() { + WABT_ZERO_MEMORY(stream); + } + Stream stream; - LinkerInputBinaryVector inputs; - ssize_t current_section_payload_offset; + std::vector<std::unique_ptr<LinkerInputBinary>> inputs; + ssize_t current_section_payload_offset = 0; }; static void on_option(struct OptionParser* parser, @@ -92,7 +96,7 @@ static void on_option(struct OptionParser* parser, } static void on_argument(struct OptionParser* parser, const char* argument) { - append_string_value(&s_infiles, &argument); + s_infiles.emplace_back(argument); } static void on_option_error(struct OptionParser* parser, const char* message) { @@ -110,43 +114,59 @@ static void parse_options(int argc, char** argv) { parser.on_error = on_option_error; parse_options(&parser, argc, argv); - if (!s_infiles.size) { + if (!s_infiles.size()) { print_help(&parser, PROGRAM_NAME); WABT_FATAL("No inputs files specified.\n"); } } -void destroy_section(Section* section) { - destroy_reloc_vector(§ion->relocations); - switch (section->section_code) { - case BinarySection::Data: - destroy_data_segment_vector(§ion->data_segments); - break; - default: - break; +Section::Section() + : binary(nullptr), + section_code(BinarySection::Invalid), + size(0), + offset(0), + payload_size(0), + payload_offset(0), + count(0), + output_payload_offset(0) {} + +Section::~Section() { + if (section_code == BinarySection::Data) { + delete data_segments; } } -void destroy_binary(LinkerInputBinary* binary) { - WABT_DESTROY_VECTOR_AND_ELEMENTS(binary->sections, section); - destroy_function_import_vector(&binary->function_imports); - destroy_global_import_vector(&binary->global_imports); - destroy_string_slice_vector(&binary->debug_names); - destroy_export_vector(&binary->exports); - delete[] binary->data; +LinkerInputBinary::LinkerInputBinary(const char* filename, + uint8_t* data, + size_t size) + : filename(filename), + data(data), + size(size), + active_function_imports(0), + active_global_imports(0), + type_index_offset(0), + function_index_offset(0), + imported_function_index_offset(0), + table_index_offset(0), + memory_page_count(0), + memory_page_offset(0), + table_elem_count(0) {} + +LinkerInputBinary::~LinkerInputBinary() { + delete[] data; } static uint32_t relocate_func_index(LinkerInputBinary* binary, uint32_t function_index) { uint32_t offset; - if (function_index >= binary->function_imports.size) { + if (function_index >= binary->function_imports.size()) { /* locally declared function call */ offset = binary->function_index_offset; if (s_debug) writef(&s_log_stream, "func reloc %d + %d\n", function_index, offset); } else { /* imported function call */ - FunctionImport* import = &binary->function_imports.data[function_index]; + FunctionImport* import = &binary->function_imports[function_index]; offset = binary->imported_function_index_offset; if (!import->active) { function_index = import->foreign_index; @@ -181,7 +201,7 @@ static void apply_relocation(Section* section, Reloc* r) { new_value = cur_value + offset; break; case RelocType::GlobalIndexLEB: - if (cur_value >= binary->global_imports.size) { + if (cur_value >= binary->global_imports.size()) { offset = binary->global_index_offset; } else { offset = binary->imported_global_index_offset; @@ -199,7 +219,7 @@ static void apply_relocation(Section* section, Reloc* r) { } static void apply_relocations(Section* section) { - if (!section->relocations.size) + if (!section->relocations.size()) return; if (s_debug) @@ -207,9 +227,8 @@ static void apply_relocations(Section* section) { get_section_name(section->section_code)); /* Perform relocations in-place */ - for (size_t i = 0; i < section->relocations.size; i++) { - Reloc* reloc = §ion->relocations.data[i]; - apply_relocation(section, reloc); + for (Reloc& reloc: section->relocations) { + apply_relocation(section, &reloc); } } @@ -231,6 +250,12 @@ static void write_slice(Stream* stream, StringSlice str, const char* desc) { write_str(stream, str.start, str.length, PrintChars::Yes, desc); } +static void write_string(Stream* stream, + const std::string& str, + const char* desc) { + write_str(stream, str.data(), str.length(), PrintChars::Yes, desc); +} + #define WRITE_UNKNOWN_SIZE(STREAM) \ { \ uint32_t fixup_offset = (STREAM)->offset; \ @@ -244,16 +269,15 @@ static void write_slice(Stream* stream, StringSlice str, const char* desc) { } static void write_table_section(Context* ctx, - const SectionPtrVector* sections) { + const SectionPtrVector& sections) { /* Total section size includes the element count leb128 which is * always 1 in the current spec */ uint32_t table_count = 1; uint32_t flags = WABT_BINARY_LIMITS_HAS_MAX_FLAG; uint32_t elem_count = 0; - for (size_t i = 0; i < sections->size; i++) { - Section* sec = sections->data[i]; - elem_count += sec->binary->table_elem_count; + for (Section* section: sections) { + elem_count += section->binary->table_elem_count; } Stream* stream = &ctx->stream; @@ -268,29 +292,26 @@ static void write_table_section(Context* ctx, static void write_export_section(Context* ctx) { uint32_t total_exports = 0; - for (size_t i = 0; i < ctx->inputs.size; i++) { - LinkerInputBinary* binary = &ctx->inputs.data[i]; - total_exports += binary->exports.size; + for (const std::unique_ptr<LinkerInputBinary>& binary: ctx->inputs) { + total_exports += binary->exports.size(); } Stream* stream = &ctx->stream; WRITE_UNKNOWN_SIZE(stream); write_u32_leb128(stream, total_exports, "export count"); - for (size_t i = 0; i < ctx->inputs.size; i++) { - LinkerInputBinary* binary = &ctx->inputs.data[i]; - for (size_t j = 0; j < binary->exports.size; j++) { - Export* export_ = &binary->exports.data[j]; - write_slice(stream, export_->name, "export name"); - write_u8_enum(stream, export_->kind, "export kind"); - uint32_t index = export_->index; - switch (export_->kind) { + for (const std::unique_ptr<LinkerInputBinary>& binary : ctx->inputs) { + for (const Export& export_ : binary->exports) { + write_slice(stream, export_.name, "export name"); + write_u8_enum(stream, export_.kind, "export kind"); + uint32_t index = export_.index; + switch (export_.kind) { case ExternalKind::Func: - index = relocate_func_index(binary, index); + index = relocate_func_index(binary.get(), index); break; default: WABT_FATAL("unsupport export type: %d\n", - static_cast<int>(export_->kind)); + static_cast<int>(export_.kind)); break; } write_u32_leb128(stream, index, "export index"); @@ -299,14 +320,14 @@ static void write_export_section(Context* ctx) { FIXUP_SIZE(stream); } -static void write_elem_section(Context* ctx, const SectionPtrVector* sections) { +static void write_elem_section(Context* ctx, + const SectionPtrVector& sections) { Stream* stream = &ctx->stream; WRITE_UNKNOWN_SIZE(stream); uint32_t total_elem_count = 0; - for (size_t i = 0; i < sections->size; i++) { - Section* sec = sections->data[i]; - total_elem_count += sec->binary->table_elem_count; + for (Section* section : sections) { + total_elem_count += section->binary->table_elem_count; } write_u32_leb128(stream, 1, "segment count"); @@ -318,17 +339,16 @@ static void write_elem_section(Context* ctx, const SectionPtrVector* sections) { ctx->current_section_payload_offset = stream->offset; - for (size_t i = 0; i < sections->size; i++) { - Section* sec = sections->data[i]; - apply_relocations(sec); - write_section_payload(ctx, sec); + for (Section* section : sections) { + apply_relocations(section); + write_section_payload(ctx, section); } FIXUP_SIZE(stream); } static void write_memory_section(Context* ctx, - const SectionPtrVector* sections) { + const SectionPtrVector& sections) { Stream* stream = &ctx->stream; WRITE_UNKNOWN_SIZE(stream); @@ -337,8 +357,8 @@ static void write_memory_section(Context* ctx, Limits limits; WABT_ZERO_MEMORY(limits); limits.has_max = true; - for (size_t i = 0; i < sections->size; i++) { - Section* sec = sections->data[i]; + for (size_t i = 0; i < sections.size(); i++) { + Section* sec = sections[i]; limits.initial += sec->memory_limits.initial; } limits.max = limits.initial; @@ -367,32 +387,32 @@ static void write_global_import(Context* ctx, GlobalImport* import) { static void write_import_section(Context* ctx) { uint32_t num_imports = 0; - for (size_t i = 0; i < ctx->inputs.size; i++) { - LinkerInputBinary* binary = &ctx->inputs.data[i]; - FunctionImportVector* imports = &binary->function_imports; - for (size_t j = 0; j < imports->size; j++) { - FunctionImport* import = &imports->data[j]; + for (size_t i = 0; i < ctx->inputs.size(); i++) { + LinkerInputBinary* binary = ctx->inputs[i].get(); + std::vector<FunctionImport>& imports = binary->function_imports; + for (size_t j = 0; j < imports.size(); j++) { + FunctionImport* import = &imports[j]; if (import->active) num_imports++; } - num_imports += binary->global_imports.size; + num_imports += binary->global_imports.size(); } WRITE_UNKNOWN_SIZE(&ctx->stream); write_u32_leb128(&ctx->stream, num_imports, "num imports"); - for (size_t i = 0; i < ctx->inputs.size; i++) { - LinkerInputBinary* binary = &ctx->inputs.data[i]; - FunctionImportVector* imports = &binary->function_imports; - for (size_t j = 0; j < imports->size; j++) { - FunctionImport* import = &imports->data[j]; + for (size_t i = 0; i < ctx->inputs.size(); i++) { + LinkerInputBinary* binary = ctx->inputs[i].get(); + std::vector<FunctionImport>& imports = binary->function_imports; + for (size_t j = 0; j < imports.size(); j++) { + FunctionImport* import = &imports[j]; if (import->active) write_function_import(ctx, import, binary->type_index_offset); } - GlobalImportVector* globals = &binary->global_imports; - for (size_t j = 0; j < globals->size; j++) { - write_global_import(ctx, &globals->data[j]); + std::vector<GlobalImport>& globals = binary->global_imports; + for (size_t j = 0; j < globals.size(); j++) { + write_global_import(ctx, &globals[j]); } } @@ -400,15 +420,15 @@ static void write_import_section(Context* ctx) { } static void write_function_section(Context* ctx, - const SectionPtrVector* sections, + const SectionPtrVector& sections, uint32_t total_count) { Stream* stream = &ctx->stream; WRITE_UNKNOWN_SIZE(stream); write_u32_leb128(stream, total_count, "function count"); - for (size_t i = 0; i < sections->size; i++) { - Section* sec = sections->data[i]; + for (size_t i = 0; i < sections.size(); i++) { + Section* sec = sections[i]; uint32_t count = sec->count; uint32_t input_offset = 0; uint32_t sig_index = 0; @@ -426,28 +446,28 @@ static void write_function_section(Context* ctx, } static void write_data_segment(Stream* stream, - DataSegment* segment, + const DataSegment& segment, uint32_t offset) { - assert(segment->memory_index == 0); - write_u32_leb128(stream, segment->memory_index, "memory index"); + assert(segment.memory_index == 0); + write_u32_leb128(stream, segment.memory_index, "memory index"); write_opcode(stream, Opcode::I32Const); - write_u32_leb128(stream, segment->offset + offset, "offset"); + write_u32_leb128(stream, segment.offset + offset, "offset"); write_opcode(stream, Opcode::End); - write_u32_leb128(stream, segment->size, "segment size"); - write_data(stream, segment->data, segment->size, "segment data"); + write_u32_leb128(stream, segment.size, "segment size"); + write_data(stream, segment.data, segment.size, "segment data"); } static void write_data_section(Context* ctx, - SectionPtrVector* sections, + const SectionPtrVector& sections, uint32_t total_count) { Stream* stream = &ctx->stream; WRITE_UNKNOWN_SIZE(stream); write_u32_leb128(stream, total_count, "data segment count"); - for (size_t i = 0; i < sections->size; i++) { - Section* sec = sections->data[i]; - for (size_t j = 0; j < sec->data_segments.size; j++) { - DataSegment* segment = &sec->data_segments.data[j]; + for (size_t i = 0; i < sections.size(); i++) { + Section* sec = sections[i]; + for (size_t j = 0; j < sec->data_segments->size(); j++) { + const DataSegment& segment = (*sec->data_segments)[j]; write_data_segment(stream, segment, sec->binary->memory_page_offset * WABT_PAGE_SIZE); } @@ -459,11 +479,11 @@ static void write_data_section(Context* ctx, static void write_names_section(Context* ctx) { uint32_t total_count = 0; size_t k; - for (size_t i = 0; i < ctx->inputs.size; i++) { - LinkerInputBinary* binary = &ctx->inputs.data[i]; - for (size_t j = 0; j < binary->debug_names.size; j++) { - if (j < binary->function_imports.size) { - if (!binary->function_imports.data[j].active) + for (size_t i = 0; i < ctx->inputs.size(); i++) { + LinkerInputBinary* binary = ctx->inputs[i].get(); + for (size_t j = 0; j < binary->debug_names.size(); j++) { + if (j < binary->function_imports.size()) { + if (!binary->function_imports[j].active) continue; } total_count++; @@ -482,15 +502,15 @@ static void write_names_section(Context* ctx) { write_u32_leb128(stream, total_count, "element count"); k = 0; - for (size_t i = 0; i < ctx->inputs.size; i++) { - LinkerInputBinary* binary = &ctx->inputs.data[i]; - for (size_t j = 0; j < binary->debug_names.size; j++) { - if (j < binary->function_imports.size) { - if (!binary->function_imports.data[j].active) + for (size_t i = 0; i < ctx->inputs.size(); i++) { + LinkerInputBinary* binary = ctx->inputs[i].get(); + for (size_t j = 0; j < binary->debug_names.size(); j++) { + if (j < binary->function_imports.size()) { + if (!binary->function_imports[j].active) continue; } write_u32_leb128(stream, k++, "function index"); - write_slice(stream, binary->debug_names.data[j], "function name"); + write_string(stream, binary->debug_names[j], "function name"); } } @@ -500,13 +520,13 @@ static void write_names_section(Context* ctx) { static void write_reloc_section(Context* ctx, BinarySection section_code, - SectionPtrVector* sections) { + const SectionPtrVector& sections) { uint32_t total_relocs = 0; /* First pass to know total reloc count */ - for (size_t i = 0; i < sections->size; i++) { - Section* sec = sections->data[i]; - total_relocs += sec->relocations.size; + for (size_t i = 0; i < sections.size(); i++) { + Section* sec = sections[i]; + total_relocs += sec->relocations.size(); } if (!total_relocs) @@ -523,14 +543,14 @@ static void write_reloc_section(Context* ctx, write_u32_leb128_enum(&ctx->stream, section_code, "reloc section"); write_u32_leb128(&ctx->stream, total_relocs, "num relocs"); - for (size_t i = 0; i < sections->size; i++) { - Section* sec = sections->data[i]; - RelocVector* relocs = &sec->relocations; - for (size_t j = 0; j < relocs->size; j++) { - write_u32_leb128_enum(&ctx->stream, relocs->data[j].type, "reloc type"); - uint32_t new_offset = relocs->data[j].offset + sec->output_payload_offset; + for (size_t i = 0; i < sections.size(); i++) { + Section* sec = sections[i]; + const std::vector<Reloc>& relocs = sec->relocations; + for (size_t j = 0; j < relocs.size(); j++) { + write_u32_leb128_enum(&ctx->stream, relocs[j].type, "reloc type"); + uint32_t new_offset = relocs[j].offset + sec->output_payload_offset; write_u32_leb128(&ctx->stream, new_offset, "reloc offset"); - write_u32_leb128(&ctx->stream, relocs->data[j].index, "reloc index"); + write_u32_leb128(&ctx->stream, relocs[j].index, "reloc index"); } } @@ -539,11 +559,11 @@ static void write_reloc_section(Context* ctx, static bool write_combined_section(Context* ctx, BinarySection section_code, - SectionPtrVector* sections) { - if (!sections->size) + const SectionPtrVector& sections) { + if (!sections.size()) return false; - if (section_code == BinarySection::Start && sections->size > 1) { + if (section_code == BinarySection::Start && sections.size() > 1) { WABT_FATAL("Don't know how to combine sections of type: %s\n", get_section_name(section_code)); } @@ -552,8 +572,8 @@ static bool write_combined_section(Context* ctx, uint32_t total_size = 0; /* Sum section size and element count */ - for (size_t i = 0; i < sections->size; i++) { - Section* sec = sections->data[i]; + for (size_t i = 0; i < sections.size(); i++) { + Section* sec = sections[i]; total_size += sec->payload_size; total_count += sec->count; } @@ -592,8 +612,8 @@ static bool write_combined_section(Context* ctx, write_u32_leb128(stream, total_size, "section size"); write_u32_leb128(stream, total_count, "element count"); ctx->current_section_payload_offset = ctx->stream.offset; - for (size_t i = 0; i < sections->size; i++) { - Section* sec = sections->data[i]; + for (size_t i = 0; i < sections.size(); i++) { + Section* sec = sections[i]; apply_relocations(sec); write_section_payload(ctx, sec); } @@ -604,28 +624,27 @@ static bool write_combined_section(Context* ctx, } struct ExportInfo { + ExportInfo(Export* export_, LinkerInputBinary* binary) + : export_(export_), binary(binary) {} + Export* export_; LinkerInputBinary* binary; }; -WABT_DEFINE_VECTOR(export_info, ExportInfo); static void resolve_symbols(Context* ctx) { /* Create hashmap of all exported symbols from all inputs */ BindingHash export_map; - ExportInfoVector export_list; - WABT_ZERO_MEMORY(export_list); + std::vector<ExportInfo> export_list; - for (size_t i = 0; i < ctx->inputs.size; i++) { - LinkerInputBinary* binary = &ctx->inputs.data[i]; - for (size_t j = 0; j < binary->exports.size; j++) { - Export* export_ = &binary->exports.data[j]; - ExportInfo* info = append_export_info(&export_list); - info->export_ = export_; - info->binary = binary; + for (size_t i = 0; i < ctx->inputs.size(); i++) { + LinkerInputBinary* binary = ctx->inputs[i].get(); + for (size_t j = 0; j < binary->exports.size(); j++) { + Export* export_ = &binary->exports[j]; + export_list.emplace_back(export_, binary); /* TODO(sbc): Handle duplicate names */ export_map.emplace(string_slice_to_string(export_->name), - Binding(export_list.size - 1)); + Binding(export_list.size() - 1)); } } @@ -633,10 +652,10 @@ static void resolve_symbols(Context* ctx) { * Iterate through all imported functions resolving them against exported * ones. */ - for (size_t i = 0; i < ctx->inputs.size; i++) { - LinkerInputBinary* binary = &ctx->inputs.data[i]; - for (size_t j = 0; j < binary->function_imports.size; j++) { - FunctionImport* import = &binary->function_imports.data[j]; + for (size_t i = 0; i < ctx->inputs.size(); i++) { + LinkerInputBinary* binary = ctx->inputs[i].get(); + for (size_t j = 0; j < binary->function_imports.size(); j++) { + FunctionImport* import = &binary->function_imports[j]; int export_index = export_map.find_index(import->name); if (export_index == -1) { if (!s_relocatable) @@ -646,7 +665,7 @@ static void resolve_symbols(Context* ctx) { } /* We found the symbol exported by another module */ - ExportInfo* export_info = &export_list.data[export_index]; + ExportInfo* export_info = &export_list[export_index]; /* TODO(sbc): verify the foriegn function has the correct signature */ import->active = false; @@ -655,8 +674,6 @@ static void resolve_symbols(Context* ctx) { binary->active_function_imports--; } } - - destroy_export_info_vector(&export_list); } static void calculate_reloc_offsets(Context* ctx) { @@ -667,8 +684,8 @@ static void calculate_reloc_offsets(Context* ctx) { uint32_t table_elem_count = 0; uint32_t total_function_imports = 0; uint32_t total_global_imports = 0; - for (size_t i = 0; i < ctx->inputs.size; i++) { - LinkerInputBinary* binary = &ctx->inputs.data[i]; + for (size_t i = 0; i < ctx->inputs.size(); i++) { + LinkerInputBinary* binary = ctx->inputs[i].get(); /* The imported_function_index_offset is the sum of all the function * imports from objects that precede this one. i.e. the current running * total */ @@ -677,15 +694,15 @@ static void calculate_reloc_offsets(Context* ctx) { binary->memory_page_offset = memory_page_offset; memory_page_offset += binary->memory_page_count; total_function_imports += binary->active_function_imports; - total_global_imports += binary->global_imports.size; + total_global_imports += binary->global_imports.size(); } - for (size_t i = 0; i < ctx->inputs.size; i++) { - LinkerInputBinary* binary = &ctx->inputs.data[i]; + for (size_t i = 0; i < ctx->inputs.size(); i++) { + LinkerInputBinary* binary = ctx->inputs[i].get(); binary->table_index_offset = table_elem_count; table_elem_count += binary->table_elem_count; - for (size_t j = 0; j < binary->sections.size; j++) { - Section* sec = &binary->sections.data[j]; + for (size_t j = 0; j < binary->sections.size(); j++) { + Section* sec = binary->sections[j].get(); switch (sec->section_code) { case BinarySection::Type: binary->type_index_offset = type_count; @@ -693,13 +710,13 @@ static void calculate_reloc_offsets(Context* ctx) { break; case BinarySection::Global: binary->global_index_offset = total_global_imports - - sec->binary->global_imports.size + + sec->binary->global_imports.size() + global_count; global_count += sec->count; break; case BinarySection::Function: binary->function_index_offset = total_function_imports - - sec->binary->function_imports.size + + sec->binary->function_imports.size() + function_count; function_count += sec->count; break; @@ -713,14 +730,13 @@ static void calculate_reloc_offsets(Context* ctx) { static void write_binary(Context* ctx) { /* Find all the sections of each type */ SectionPtrVector sections[kBinarySectionCount]; - WABT_ZERO_MEMORY(sections); - - for (size_t j = 0; j < ctx->inputs.size; j++) { - LinkerInputBinary* binary = &ctx->inputs.data[j]; - for (size_t i = 0; i < binary->sections.size; i++) { - Section* s = &binary->sections.data[i]; - SectionPtrVector* sec_list = §ions[static_cast<int>(s->section_code)]; - append_section_ptr_value(sec_list, &s); + + for (size_t j = 0; j < ctx->inputs.size(); j++) { + LinkerInputBinary* binary = ctx->inputs[j].get(); + for (size_t i = 0; i < binary->sections.size(); i++) { + Section* s = binary->sections[i].get(); + SectionPtrVector& sec_list = sections[static_cast<int>(s->section_code)]; + sec_list.push_back(s); } } @@ -730,25 +746,21 @@ static void write_binary(Context* ctx) { /* Write known sections first */ for (size_t i = FIRST_KNOWN_SECTION; i < kBinarySectionCount; i++) { - write_combined_section(ctx, static_cast<BinarySection>(i), §ions[i]); + write_combined_section(ctx, static_cast<BinarySection>(i), sections[i]); } write_names_section(ctx); /* Generate a new set of reloction sections */ for (size_t i = FIRST_KNOWN_SECTION; i < kBinarySectionCount; i++) { - write_reloc_section(ctx, static_cast<BinarySection>(i), §ions[i]); - } - - for (size_t i = 0; i < kBinarySectionCount; i++) { - destroy_section_ptr_vector(§ions[i]); + write_reloc_section(ctx, static_cast<BinarySection>(i), sections[i]); } } static void dump_reloc_offsets(Context* ctx) { if (s_debug) { - for (uint32_t i = 0; i < ctx->inputs.size; i++) { - LinkerInputBinary* binary = &ctx->inputs.data[i]; + for (uint32_t i = 0; i < ctx->inputs.size(); i++) { + LinkerInputBinary* binary = ctx->inputs[i].get(); writef(&s_log_stream, "Relocation info for: %s\n", binary->filename); writef(&s_log_stream, " - type index offset : %d\n", binary->type_index_offset); @@ -797,38 +809,30 @@ int main(int argc, char** argv) { init_stdio(); Context context; - WABT_ZERO_MEMORY(context); parse_options(argc, argv); Result result = Result::Ok; - for (size_t i = 0; i < s_infiles.size; i++) { - const char* input_filename = s_infiles.data[i]; + for (size_t i = 0; i < s_infiles.size(); i++) { + const std::string& input_filename = s_infiles[i]; if (s_debug) - writef(&s_log_stream, "reading file: %s\n", input_filename); + writef(&s_log_stream, "reading file: %s\n", input_filename.c_str()); char* data; size_t size; - result = read_file(input_filename, &data, &size); + result = read_file(input_filename.c_str(), &data, &size); if (WABT_FAILED(result)) return result != Result::Ok; - LinkerInputBinary* b = append_binary(&context.inputs); - b->data = reinterpret_cast<uint8_t*>(data); - b->size = size; - b->filename = input_filename; + LinkerInputBinary* b = new LinkerInputBinary( + input_filename.c_str(), reinterpret_cast<uint8_t*>(data), size); + context.inputs.emplace_back(b); LinkOptions options = { NULL }; if (s_debug) options.log_stream = &s_log_stream; result = read_binary_linker(b, &options); if (WABT_FAILED(result)) - WABT_FATAL("error parsing file: %s\n", input_filename); + WABT_FATAL("error parsing file: %s\n", input_filename.c_str()); } result = perform_link(&context); - if (WABT_FAILED(result)) - return result != Result::Ok; - - /* Cleanup */ - WABT_DESTROY_VECTOR_AND_ELEMENTS(context.inputs, binary); - destroy_string_vector(&s_infiles); return result != Result::Ok; } diff --git a/src/tools/wasmopcodecnt.cc b/src/tools/wasmopcodecnt.cc index 15bb6b3c..89009aca 100644 --- a/src/tools/wasmopcodecnt.cc +++ b/src/tools/wasmopcodecnt.cc @@ -20,11 +20,12 @@ #include <stdio.h> #include <stdlib.h> +#include <algorithm> + #include "binary-reader.h" #include "binary-reader-opcnt.h" #include "option-parser.h" #include "stream.h" -#include "vector-sort.h" #define PROGRAM_NAME "wasmopcodecnt" @@ -133,13 +134,10 @@ static void parse_options(int argc, char** argv) { } } -WABT_DEFINE_VECTOR_SORT(int_counter, IntCounter); - -typedef int(int_counter_lt_fcn)(IntCounter*, IntCounter*); - -WABT_DEFINE_VECTOR_SORT(int_pair_counter, IntPairCounter); +typedef int(int_counter_lt_fcn)(const IntCounter&, const IntCounter&); -typedef int(int_pair_counter_lt_fcn)(IntPairCounter*, IntPairCounter*); +typedef int(int_pair_counter_lt_fcn)(const IntPairCounter&, + const IntPairCounter&); typedef void (*display_name_fcn)(FILE* out, intmax_t value); @@ -155,68 +153,57 @@ static void display_intmax(FILE* out, intmax_t value) { } static void display_int_counter_vector(FILE* out, - IntCounterVector* vec, + const IntCounterVector& vec, display_name_fcn display_fcn, const char* opcode_name) { - for (size_t i = 0; i < vec->size; ++i) { - if (vec->data[i].count == 0) + for (const IntCounter& counter : vec) { + if (counter.count == 0) continue; if (opcode_name) fprintf(out, "(%s ", opcode_name); - display_fcn(out, vec->data[i].value); + display_fcn(out, counter.value); if (opcode_name) fprintf(out, ")"); - fprintf(out, "%s%" PRIzd "\n", s_separator, vec->data[i].count); + fprintf(out, "%s%" PRIzd "\n", s_separator, counter.count); } } static void display_int_pair_counter_vector(FILE* out, - IntPairCounterVector* vec, + const IntPairCounterVector& vec, display_name_fcn display_first_fcn, display_name_fcn display_second_fcn, const char* opcode_name) { - for (size_t i = 0; i < vec->size; ++i) { - if (vec->data[i].count == 0) + for (const IntPairCounter& pair : vec) { + if (pair.count == 0) continue; if (opcode_name) fprintf(out, "(%s ", opcode_name); - display_first_fcn(out, vec->data[i].first); + display_first_fcn(out, pair.first); fputc(' ', out); - display_second_fcn(out, vec->data[i].second); + display_second_fcn(out, pair.second); if (opcode_name) fprintf(out, ")"); - fprintf(out, "%s%" PRIzd "\n", s_separator, vec->data[i].count); + fprintf(out, "%s%" PRIzd "\n", s_separator, pair.count); } } -static void swap_int_counters(IntCounter* v1, IntCounter* v2) { - IntCounter tmp; - tmp.value = v1->value; - tmp.count = v1->count; - - v1->value = v2->value; - v1->count = v2->count; - - v2->value = tmp.value; - v2->count = tmp.count; -} - -static int opcode_counter_gt(IntCounter* counter_1, IntCounter* counter_2) { - if (counter_1->count > counter_2->count) +static int opcode_counter_gt(const IntCounter& counter_1, + const IntCounter& counter_2) { + if (counter_1.count > counter_2.count) return 1; - if (counter_1->count < counter_2->count) + if (counter_1.count < counter_2.count) return 0; const char* name_1 = "?1"; const char* name_2 = "?2"; - if (counter_1->value < kOpcodeCount) { + if (counter_1.value < kOpcodeCount) { const char* opcode_name = - get_opcode_name(static_cast<Opcode>(counter_1->value)); + get_opcode_name(static_cast<Opcode>(counter_1.value)); if (opcode_name) name_1 = opcode_name; } - if (counter_2->value < kOpcodeCount) { + if (counter_2.value < kOpcodeCount) { const char* opcode_name = - get_opcode_name(static_cast<Opcode>(counter_2->value)); + get_opcode_name(static_cast<Opcode>(counter_2.value)); if (opcode_name) name_2 = opcode_name; } @@ -226,104 +213,78 @@ static int opcode_counter_gt(IntCounter* counter_1, IntCounter* counter_2) { return 0; } -static int int_counter_gt(IntCounter* counter_1, IntCounter* counter_2) { - if (counter_1->count < counter_2->count) +static int int_counter_gt(const IntCounter& counter_1, + const IntCounter& counter_2) { + if (counter_1.count < counter_2.count) return 0; - if (counter_1->count > counter_2->count) + if (counter_1.count > counter_2.count) return 1; - if (counter_1->value < counter_2->value) + if (counter_1.value < counter_2.value) return 0; - if (counter_1->value > counter_2->value) + if (counter_1.value > counter_2.value) return 1; return 0; } -static void swap_int_pair_counters(IntPairCounter* v1, IntPairCounter* v2) { - IntPairCounter tmp; - tmp.first = v1->first; - tmp.second = v1->second; - tmp.count = v1->count; - - v1->first = v2->first; - v1->second = v2->second; - v1->count = v2->count; - - v2->first = tmp.first; - v2->second = tmp.second; - v2->count = tmp.count; -} - -static int int_pair_counter_gt(IntPairCounter* counter_1, - IntPairCounter* counter_2) { - if (counter_1->count < counter_2->count) +static int int_pair_counter_gt(const IntPairCounter& counter_1, + const IntPairCounter& counter_2) { + if (counter_1.count < counter_2.count) return 0; - if (counter_1->count > counter_2->count) + if (counter_1.count > counter_2.count) return 1; - if (counter_1->first < counter_2->first) + if (counter_1.first < counter_2.first) return 0; - if (counter_1->first > counter_2->first) + if (counter_1.first > counter_2.first) return 1; - if (counter_1->second < counter_2->second) + if (counter_1.second < counter_2.second) return 0; - if (counter_1->second > counter_2->second) + if (counter_1.second > counter_2.second) return 1; return 0; } static void display_sorted_int_counter_vector(FILE* out, const char* title, - IntCounterVector* vec, + const IntCounterVector& vec, int_counter_lt_fcn lt_fcn, display_name_fcn display_fcn, const char* opcode_name) { - if (vec->size == 0) + if (vec.size() == 0) return; /* First filter out values less than cutoff. This speeds up sorting. */ IntCounterVector filtered_vec; - WABT_ZERO_MEMORY(filtered_vec); - for (size_t i = 0; i < vec->size; ++i) { - if (vec->data[i].count < s_cutoff) + for (const IntCounter& counter: vec) { + if (counter.count < s_cutoff) continue; - append_int_counter_value(&filtered_vec, &vec->data[i]); + filtered_vec.push_back(counter); } - IntCounterVector sorted_vec; - WABT_ZERO_MEMORY(sorted_vec); - sort_int_counter_vector(&filtered_vec, &sorted_vec, swap_int_counters, - lt_fcn); + std::sort(filtered_vec.begin(), filtered_vec.end(), lt_fcn); fprintf(out, "%s\n", title); - display_int_counter_vector(out, &sorted_vec, display_fcn, opcode_name); - destroy_int_counter_vector(&filtered_vec); - destroy_int_counter_vector(&sorted_vec); + display_int_counter_vector(out, filtered_vec, display_fcn, opcode_name); } static void display_sorted_int_pair_counter_vector( FILE* out, const char* title, - IntPairCounterVector* vec, + const IntPairCounterVector& 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) + if (vec.size() == 0) return; IntPairCounterVector filtered_vec; - WABT_ZERO_MEMORY(filtered_vec); - IntPairCounterVector sorted_vec; - for (size_t i = 0; i < vec->size; ++i) { - if (vec->data[i].count < s_cutoff) + for (const IntPairCounter& pair : vec) { + if (pair.count < s_cutoff) continue; - append_int_pair_counter_value(&filtered_vec, &vec->data[i]); + filtered_vec.push_back(pair); } - WABT_ZERO_MEMORY(sorted_vec); - sort_int_pair_counter_vector(&filtered_vec, &sorted_vec, - swap_int_pair_counters, lt_fcn); + std::sort(filtered_vec.begin(), filtered_vec.end(), lt_fcn); fprintf(out, "%s\n", title); - display_int_pair_counter_vector(out, &sorted_vec, display_first_fcn, + display_int_pair_counter_vector(out, filtered_vec, display_first_fcn, display_second_fcn, opcode_name); - destroy_int_pair_counter_vector(&filtered_vec); - destroy_int_pair_counter_vector(&sorted_vec); } int main(int argc, char** argv) { @@ -347,32 +308,30 @@ int main(int argc, char** argv) { } if (WABT_SUCCEEDED(result)) { OpcntData opcnt_data; - init_opcnt_data(&opcnt_data); result = read_binary_opcnt(data, size, &s_read_binary_options, &opcnt_data); if (WABT_SUCCEEDED(result)) { display_sorted_int_counter_vector( - out, "Opcode counts:", &opcnt_data.opcode_vec, opcode_counter_gt, + out, "Opcode counts:", opcnt_data.opcode_vec, opcode_counter_gt, display_opcode_name, nullptr); display_sorted_int_counter_vector( - out, "\ni32.const:", &opcnt_data.i32_const_vec, int_counter_gt, + out, "\ni32.const:", opcnt_data.i32_const_vec, int_counter_gt, display_intmax, get_opcode_name(Opcode::I32Const)); display_sorted_int_counter_vector( - out, "\nget_local:", &opcnt_data.get_local_vec, int_counter_gt, + out, "\nget_local:", opcnt_data.get_local_vec, int_counter_gt, display_intmax, get_opcode_name(Opcode::GetLocal)); display_sorted_int_counter_vector( - out, "\nset_local:", &opcnt_data.set_local_vec, int_counter_gt, + out, "\nset_local:", opcnt_data.set_local_vec, int_counter_gt, display_intmax, get_opcode_name(Opcode::SetLocal)); display_sorted_int_counter_vector( - out, "\ntee_local:", &opcnt_data.tee_local_vec, int_counter_gt, + out, "\ntee_local:", opcnt_data.tee_local_vec, int_counter_gt, display_intmax, get_opcode_name(Opcode::TeeLocal)); display_sorted_int_pair_counter_vector( - out, "\ni32.load:", &opcnt_data.i32_load_vec, int_pair_counter_gt, + out, "\ni32.load:", opcnt_data.i32_load_vec, int_pair_counter_gt, display_intmax, display_intmax, get_opcode_name(Opcode::I32Load)); display_sorted_int_pair_counter_vector( - out, "\ni32.store:", &opcnt_data.i32_store_vec, int_pair_counter_gt, + out, "\ni32.store:", opcnt_data.i32_store_vec, int_pair_counter_gt, display_intmax, display_intmax, get_opcode_name(Opcode::I32Store)); } - destroy_opcnt_data(&opcnt_data); } delete[] data; return result != Result::Ok; diff --git a/src/type-checker.cc b/src/type-checker.cc index 5d91665d..6a998da6 100644 --- a/src/type-checker.cc +++ b/src/type-checker.cc @@ -30,6 +30,14 @@ namespace wabt { +TypeCheckerLabel::TypeCheckerLabel(LabelType label_type, + const TypeVector& sig, + size_t limit) + : label_type(label_type), + sig(sig), + type_stack_limit(limit), + unreachable(false) {} + static void WABT_PRINTF_FORMAT(2, 3) print_error(TypeChecker* tc, const char* fmt, ...) { if (tc->error_handler->on_error) { @@ -41,14 +49,14 @@ static void WABT_PRINTF_FORMAT(2, 3) Result typechecker_get_label(TypeChecker* tc, size_t depth, TypeCheckerLabel** out_label) { - if (depth >= tc->label_stack.size) { - assert(tc->label_stack.size > 0); + if (depth >= tc->label_stack.size()) { + assert(tc->label_stack.size() > 0); print_error(tc, "invalid depth: %" PRIzd " (max %" PRIzd ")", depth, - tc->label_stack.size - 1); + tc->label_stack.size() - 1); *out_label = nullptr; return Result::Error; } - *out_label = &tc->label_stack.data[tc->label_stack.size - depth - 1]; + *out_label = &tc->label_stack[tc->label_stack.size() - depth - 1]; return Result::Ok; } @@ -65,7 +73,7 @@ bool typechecker_is_unreachable(TypeChecker* tc) { static void reset_type_stack_to_label(TypeChecker* tc, TypeCheckerLabel* label) { - tc->type_stack.size = label->type_stack_limit; + tc->type_stack.resize(label->type_stack_limit); } static Result set_unreachable(TypeChecker* tc) { @@ -78,23 +86,12 @@ static Result set_unreachable(TypeChecker* tc) { static void push_label(TypeChecker* tc, LabelType label_type, - const TypeVector* sig) { - TypeCheckerLabel* label = append_type_checker_label(&tc->label_stack); - label->label_type = label_type; - extend_types(&label->sig, sig); - label->type_stack_limit = tc->type_stack.size; - label->unreachable = false; -} - -static void destroy_type_checker_label(TypeCheckerLabel* label) { - destroy_type_vector(&label->sig); + const TypeVector& sig) { + tc->label_stack.emplace_back(label_type, sig, tc->type_stack.size()); } static Result pop_label(TypeChecker* tc) { - TypeCheckerLabel* label; - CHECK_RESULT(top_label(tc, &label)); - destroy_type_checker_label(label); - tc->label_stack.size--; + tc->label_stack.pop_back(); return Result::Ok; } @@ -106,11 +103,11 @@ static Result peek_type(TypeChecker* tc, uint32_t depth, Type* out_type) { TypeCheckerLabel* label; CHECK_RESULT(top_label(tc, &label)); - if (label->type_stack_limit + depth >= tc->type_stack.size) { + if (label->type_stack_limit + depth >= tc->type_stack.size()) { *out_type = Type::Any; return label->unreachable ? Result::Ok : Result::Error; } - *out_type = tc->type_stack.data[tc->type_stack.size - depth - 1]; + *out_type = tc->type_stack[tc->type_stack.size() - depth - 1]; return Result::Ok; } @@ -122,33 +119,33 @@ static Result pop_type(TypeChecker* tc, Type* out_type) { TypeCheckerLabel* label; CHECK_RESULT(top_label(tc, &label)); Result result = top_type(tc, out_type); - if (tc->type_stack.size > label->type_stack_limit) - tc->type_stack.size--; + if (tc->type_stack.size() > label->type_stack_limit) + tc->type_stack.pop_back(); return result; } static Result drop_types(TypeChecker* tc, size_t drop_count) { TypeCheckerLabel* label; CHECK_RESULT(top_label(tc, &label)); - if (label->type_stack_limit + drop_count > tc->type_stack.size) { + if (label->type_stack_limit + drop_count > tc->type_stack.size()) { if (label->unreachable) { reset_type_stack_to_label(tc, label); return Result::Ok; } return Result::Error; } - tc->type_stack.size -= drop_count; + tc->type_stack.erase(tc->type_stack.end() - drop_count, tc->type_stack.end()); return Result::Ok; } static void push_type(TypeChecker* tc, Type type) { if (type != Type::Void) - append_type_value(&tc->type_stack, &type); + tc->type_stack.push_back(type); } -static void push_types(TypeChecker* tc, const TypeVector* types) { - for (size_t i = 0; i < types->size; ++i) - push_type(tc, types->data[i]); +static void push_types(TypeChecker* tc, const TypeVector& types) { + for (Type type: types) + push_type(tc, type); } static Result check_type_stack_limit(TypeChecker* tc, @@ -156,7 +153,7 @@ static Result check_type_stack_limit(TypeChecker* tc, const char* desc) { TypeCheckerLabel* label; CHECK_RESULT(top_label(tc, &label)); - size_t avail = tc->type_stack.size - label->type_stack_limit; + size_t avail = tc->type_stack.size() - label->type_stack_limit; if (!label->unreachable && expected > avail) { print_error(tc, "type stack size too small at %s. got %" PRIzd ", expected at least %" PRIzd, @@ -169,9 +166,9 @@ static Result check_type_stack_limit(TypeChecker* tc, static Result check_type_stack_end(TypeChecker* tc, const char* desc) { TypeCheckerLabel* label; CHECK_RESULT(top_label(tc, &label)); - if (tc->type_stack.size != label->type_stack_limit) { + if (tc->type_stack.size() != label->type_stack_limit) { print_error(tc, "type stack at end of %s is %" PRIzd ", expected %" PRIzd, - desc, tc->type_stack.size, label->type_stack_limit); + desc, tc->type_stack.size(), label->type_stack_limit); return Result::Error; } return Result::Ok; @@ -190,39 +187,39 @@ static Result check_type(TypeChecker* tc, } static Result check_signature(TypeChecker* tc, - const TypeVector* sig, + const TypeVector& sig, const char* desc) { Result result = Result::Ok; - COMBINE_RESULT(result, check_type_stack_limit(tc, sig->size, desc)); - for (size_t i = 0; i < sig->size; ++i) { + COMBINE_RESULT(result, check_type_stack_limit(tc, sig.size(), desc)); + for (size_t i = 0; i < sig.size(); ++i) { Type actual = Type::Any; - COMBINE_RESULT(result, peek_type(tc, sig->size - i - 1, &actual)); - COMBINE_RESULT(result, check_type(tc, actual, sig->data[i], desc)); + COMBINE_RESULT(result, peek_type(tc, sig.size() - i - 1, &actual)); + COMBINE_RESULT(result, check_type(tc, actual, sig[i], desc)); } return result; } static Result pop_and_check_signature(TypeChecker* tc, - const TypeVector* sig, + const TypeVector& sig, const char* desc) { Result result = Result::Ok; COMBINE_RESULT(result, check_signature(tc, sig, desc)); - COMBINE_RESULT(result, drop_types(tc, sig->size)); + COMBINE_RESULT(result, drop_types(tc, sig.size())); return result; } static Result pop_and_check_call(TypeChecker* tc, - const TypeVector* param_types, - const TypeVector* result_types, + const TypeVector& param_types, + const TypeVector& result_types, const char* desc) { Result result = Result::Ok; - COMBINE_RESULT(result, check_type_stack_limit(tc, param_types->size, desc)); - for (size_t i = 0; i < param_types->size; ++i) { + COMBINE_RESULT(result, check_type_stack_limit(tc, param_types.size(), desc)); + for (size_t i = 0; i < param_types.size(); ++i) { Type actual = Type::Any; - COMBINE_RESULT(result, peek_type(tc, param_types->size - i - 1, &actual)); - COMBINE_RESULT(result, check_type(tc, actual, param_types->data[i], desc)); + COMBINE_RESULT(result, peek_type(tc, param_types.size() - i - 1, &actual)); + COMBINE_RESULT(result, check_type(tc, actual, param_types[i], desc)); } - COMBINE_RESULT(result, drop_types(tc, param_types->size)); + COMBINE_RESULT(result, drop_types(tc, param_types.size())); push_types(tc, result_types); return result; } @@ -282,15 +279,10 @@ static Result check_opcode2(TypeChecker* tc, Opcode opcode) { return result; } -void destroy_typechecker(TypeChecker* tc) { - destroy_type_vector(&tc->type_stack); - WABT_DESTROY_VECTOR_AND_ELEMENTS(tc->label_stack, type_checker_label); -} - Result typechecker_begin_function(TypeChecker* tc, const TypeVector* sig) { - tc->type_stack.size = 0; - tc->label_stack.size = 0; - push_label(tc, LabelType::Func, sig); + tc->type_stack.clear(); + tc->label_stack.clear(); + push_label(tc, LabelType::Func, *sig); return Result::Ok; } @@ -299,7 +291,7 @@ Result typechecker_on_binary(TypeChecker* tc, Opcode opcode) { } Result typechecker_on_block(TypeChecker* tc, const TypeVector* sig) { - push_label(tc, LabelType::Block, sig); + push_label(tc, LabelType::Block, *sig); return Result::Ok; } @@ -308,7 +300,7 @@ Result typechecker_on_br(TypeChecker* tc, size_t depth) { TypeCheckerLabel* label; CHECK_RESULT(typechecker_get_label(tc, depth, &label)); if (label->label_type != LabelType::Loop) - COMBINE_RESULT(result, check_signature(tc, &label->sig, "br")); + COMBINE_RESULT(result, check_signature(tc, label->sig, "br")); CHECK_RESULT(set_unreachable(tc)); return result; } @@ -319,7 +311,7 @@ Result typechecker_on_br_if(TypeChecker* tc, size_t depth) { TypeCheckerLabel* label; CHECK_RESULT(typechecker_get_label(tc, depth, &label)); if (label->label_type != LabelType::Loop) - COMBINE_RESULT(result, check_signature(tc, &label->sig, "br_if")); + COMBINE_RESULT(result, check_signature(tc, label->sig, "br_if")); return result; } @@ -332,14 +324,14 @@ Result typechecker_on_br_table_target(TypeChecker* tc, size_t depth) { Result result = Result::Ok; TypeCheckerLabel* label; CHECK_RESULT(typechecker_get_label(tc, depth, &label)); - assert(label->sig.size <= 1); - Type label_sig = label->sig.size == 0 ? Type::Void : label->sig.data[0]; + assert(label->sig.size() <= 1); + Type label_sig = label->sig.size() == 0 ? Type::Void : label->sig[0]; COMBINE_RESULT(result, check_type(tc, tc->br_table_sig, label_sig, "br_table")); tc->br_table_sig = label_sig; if (label->label_type != LabelType::Loop) - COMBINE_RESULT(result, check_signature(tc, &label->sig, "br_table")); + COMBINE_RESULT(result, check_signature(tc, label->sig, "br_table")); return result; } @@ -350,7 +342,7 @@ Result typechecker_end_br_table(TypeChecker* tc) { Result typechecker_on_call(TypeChecker* tc, const TypeVector* param_types, const TypeVector* result_types) { - return pop_and_check_call(tc, param_types, result_types, "call"); + return pop_and_check_call(tc, *param_types, *result_types, "call"); } Result typechecker_on_call_indirect(TypeChecker* tc, @@ -358,7 +350,7 @@ Result typechecker_on_call_indirect(TypeChecker* tc, const TypeVector* result_types) { Result result = Result::Ok; COMBINE_RESULT(result, pop_and_check_1_type(tc, Type::I32, "call_indirect")); - COMBINE_RESULT(result, pop_and_check_call(tc, param_types, result_types, + COMBINE_RESULT(result, pop_and_check_call(tc, *param_types, *result_types, "call_indirect")); return result; } @@ -395,7 +387,7 @@ Result typechecker_on_else(TypeChecker* tc) { CHECK_RESULT(top_label(tc, &label)); COMBINE_RESULT(result, check_label_type(label, LabelType::If)); COMBINE_RESULT(result, - pop_and_check_signature(tc, &label->sig, "if true branch")); + pop_and_check_signature(tc, label->sig, "if true branch")); COMBINE_RESULT(result, check_type_stack_end(tc, "if true branch")); reset_type_stack_to_label(tc, label); label->label_type = LabelType::Else; @@ -408,10 +400,10 @@ static Result on_end(TypeChecker* tc, const char* sig_desc, const char* end_desc) { Result result = Result::Ok; - COMBINE_RESULT(result, pop_and_check_signature(tc, &label->sig, sig_desc)); + COMBINE_RESULT(result, pop_and_check_signature(tc, label->sig, sig_desc)); COMBINE_RESULT(result, check_type_stack_end(tc, end_desc)); reset_type_stack_to_label(tc, label); - push_types(tc, &label->sig); + push_types(tc, label->sig); pop_label(tc); return result; } @@ -425,7 +417,7 @@ Result typechecker_on_end(TypeChecker* tc) { CHECK_RESULT(top_label(tc, &label)); assert(static_cast<int>(label->label_type) < kLabelTypeCount); if (label->label_type == LabelType::If) { - if (label->sig.size != 0) { + if (label->sig.size() != 0) { print_error(tc, "if without else cannot have type signature."); result = Result::Error; } @@ -441,7 +433,7 @@ Result typechecker_on_grow_memory(TypeChecker* tc) { Result typechecker_on_if(TypeChecker* tc, const TypeVector* sig) { Result result = pop_and_check_1_type(tc, Type::I32, "if"); - push_label(tc, LabelType::If, sig); + push_label(tc, LabelType::If, *sig); return result; } @@ -460,7 +452,7 @@ Result typechecker_on_load(TypeChecker* tc, Opcode opcode) { } Result typechecker_on_loop(TypeChecker* tc, const TypeVector* sig) { - push_label(tc, LabelType::Loop, sig); + push_label(tc, LabelType::Loop, *sig); return Result::Ok; } @@ -468,9 +460,9 @@ Result typechecker_on_return(TypeChecker* tc) { Result result = Result::Ok; TypeCheckerLabel* func_label; CHECK_RESULT( - typechecker_get_label(tc, tc->label_stack.size - 1, &func_label)); + typechecker_get_label(tc, tc->label_stack.size() - 1, &func_label)); COMBINE_RESULT(result, - pop_and_check_signature(tc, &func_label->sig, "return")); + pop_and_check_signature(tc, func_label->sig, "return")); CHECK_RESULT(set_unreachable(tc)); return result; } diff --git a/src/type-checker.h b/src/type-checker.h index 17819848..b3135d15 100644 --- a/src/type-checker.h +++ b/src/type-checker.h @@ -17,9 +17,9 @@ #ifndef WABT_TYPE_CHECKER_H_ #define WABT_TYPE_CHECKER_H_ +#include <vector> + #include "common.h" -#include "type-vector.h" -#include "vector.h" namespace wabt { @@ -31,24 +31,23 @@ struct TypeCheckerErrorHandler { }; struct TypeCheckerLabel { + TypeCheckerLabel(LabelType, const TypeVector& sig, size_t limit); + LabelType label_type; TypeVector sig; size_t type_stack_limit; bool unreachable; }; -WABT_DEFINE_VECTOR(type_checker_label, TypeCheckerLabel); struct TypeChecker { - TypeCheckerErrorHandler* error_handler; + TypeCheckerErrorHandler* error_handler = nullptr; TypeVector type_stack; - TypeCheckerLabelVector label_stack; + std::vector<TypeCheckerLabel> label_stack; /* TODO(binji): will need to be complete signature when signatures with * multiple types are allowed. */ Type br_table_sig; }; -void destroy_typechecker(TypeChecker*); - bool typechecker_is_unreachable(TypeChecker* tc); Result typechecker_get_label(TypeChecker* tc, size_t depth, diff --git a/src/type-vector.h b/src/type-vector.h deleted file mode 100644 index 9d0da319..00000000 --- a/src/type-vector.h +++ /dev/null @@ -1,41 +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_TYPE_VECTOR_H_ -#define WABT_TYPE_VECTOR_H_ - -#include "common.h" -#include "vector.h" - -namespace wabt { - -WABT_DEFINE_VECTOR(type, Type) - -static WABT_INLINE bool type_vectors_are_equal(const TypeVector* types1, - const TypeVector* types2) { - if (types1->size != types2->size) - return false; - size_t i; - for (i = 0; i < types1->size; ++i) { - if (types1->data[i] != types2->data[i]) - return false; - } - return true; -} - -} // namespace wabt - -#endif /* WABT_TYPE_VECTOR_H_ */ diff --git a/src/validator.cc b/src/validator.cc index d2062f8e..02c83e4d 100644 --- a/src/validator.cc +++ b/src/validator.cc @@ -47,20 +47,29 @@ struct ActionResult { }; struct Context { - SourceErrorHandler* error_handler; - AstLexer* lexer; - const Script* script; - const Module* current_module; - const Func* current_func; - int current_table_index; - int current_memory_index; - int current_global_index; - int num_imported_globals; + WABT_DISALLOW_COPY_AND_ASSIGN(Context); + Context(SourceErrorHandler*, AstLexer*, const Script*); + + SourceErrorHandler* error_handler = nullptr; + AstLexer* lexer = nullptr; + const Script* script = nullptr; + const Module* current_module = nullptr; + const Func* current_func = nullptr; + int current_table_index = 0; + int current_memory_index = 0; + int current_global_index = 0; + int num_imported_globals = 0; TypeChecker typechecker; - const Location* expr_loc; /* Cached for access by on_typechecker_error */ - Result result; + /* Cached for access by on_typechecker_error */ + const Location* expr_loc = nullptr; + Result result = Result::Ok; }; +Context::Context(SourceErrorHandler* error_handler, + AstLexer* lexer, + const Script* script) + : error_handler(error_handler), lexer(lexer), script(script) {} + } // namespace static void WABT_PRINTF_FORMAT(3, 4) @@ -107,13 +116,13 @@ static Result check_func_var(Context* ctx, const Var* var, const Func** out_func) { int index; - if (WABT_FAILED(check_var(ctx, ctx->current_module->funcs.size, var, + if (WABT_FAILED(check_var(ctx, ctx->current_module->funcs.size(), var, "function", &index))) { return Result::Error; } if (out_func) - *out_func = ctx->current_module->funcs.data[index]; + *out_func = ctx->current_module->funcs[index]; return Result::Ok; } @@ -122,13 +131,13 @@ static Result check_global_var(Context* ctx, const Global** out_global, int* out_global_index) { int index; - if (WABT_FAILED(check_var(ctx, ctx->current_module->globals.size, var, + if (WABT_FAILED(check_var(ctx, ctx->current_module->globals.size(), var, "global", &index))) { return Result::Error; } if (out_global) - *out_global = ctx->current_module->globals.data[index]; + *out_global = ctx->current_module->globals[index]; if (out_global_index) *out_global_index = index; return Result::Ok; @@ -145,13 +154,13 @@ static Result check_func_type_var(Context* ctx, const Var* var, const FuncType** out_func_type) { int index; - if (WABT_FAILED(check_var(ctx, ctx->current_module->func_types.size, var, + if (WABT_FAILED(check_var(ctx, ctx->current_module->func_types.size(), var, "function type", &index))) { return Result::Error; } if (out_func_type) - *out_func_type = ctx->current_module->func_types.data[index]; + *out_func_type = ctx->current_module->func_types[index]; return Result::Ok; } @@ -159,13 +168,13 @@ static Result check_table_var(Context* ctx, const Var* var, const Table** out_table) { int index; - if (WABT_FAILED(check_var(ctx, ctx->current_module->tables.size, var, "table", - &index))) { + if (WABT_FAILED(check_var(ctx, ctx->current_module->tables.size(), var, + "table", &index))) { return Result::Error; } if (out_table) - *out_table = ctx->current_module->tables.data[index]; + *out_table = ctx->current_module->tables[index]; return Result::Ok; } @@ -173,13 +182,13 @@ static Result check_memory_var(Context* ctx, const Var* var, const Memory** out_memory) { int index; - if (WABT_FAILED(check_var(ctx, ctx->current_module->memories.size, var, + if (WABT_FAILED(check_var(ctx, ctx->current_module->memories.size(), var, "memory", &index))) { return Result::Error; } if (out_memory) - *out_memory = ctx->current_module->memories.data[index]; + *out_memory = ctx->current_module->memories[index]; return Result::Ok; } @@ -193,7 +202,7 @@ static Result check_local_var(Context* ctx, const Var* var, Type* out_type) { if (index < num_params) { *out_type = get_param_type(func, index); } else { - *out_type = ctx->current_func->local_types.data[index - num_params]; + *out_type = ctx->current_func->local_types[index - num_params]; } } return Result::Ok; @@ -264,47 +273,45 @@ static void check_type_index(Context* ctx, static void check_types(Context* ctx, const Location* loc, - const TypeVector* actual, - const TypeVector* expected, + const TypeVector& actual, + const TypeVector& expected, const char* desc, const char* index_kind) { - if (actual->size == expected->size) { - for (size_t i = 0; i < actual->size; ++i) { - check_type_index(ctx, loc, actual->data[i], expected->data[i], desc, i, - index_kind); + if (actual.size() == expected.size()) { + for (size_t i = 0; i < actual.size(); ++i) { + check_type_index(ctx, loc, actual[i], expected[i], desc, i, index_kind); } } else { print_error(ctx, loc, "expected %" PRIzd " %ss, got %" PRIzd, - expected->size, index_kind, actual->size); + expected.size(), index_kind, actual.size()); } } static void check_const_types(Context* ctx, const Location* loc, - const TypeVector* actual, - const ConstVector* expected, + const TypeVector& actual, + const ConstVector& expected, const char* desc) { - if (actual->size == expected->size) { - for (size_t i = 0; i < actual->size; ++i) { - check_type_index(ctx, loc, actual->data[i], expected->data[i].type, desc, - i, "result"); + if (actual.size() == expected.size()) { + for (size_t i = 0; i < actual.size(); ++i) { + check_type_index(ctx, loc, actual[i], expected[i].type, desc, i, + "result"); } } else { print_error(ctx, loc, "expected %" PRIzd " results, got %" PRIzd, - expected->size, actual->size); + expected.size(), actual.size()); } } static void check_const_type(Context* ctx, const Location* loc, Type actual, - const ConstVector* expected, + const ConstVector& expected, const char* desc) { TypeVector actual_types; - WABT_ZERO_MEMORY(actual_types); - actual_types.size = actual == Type::Void ? 0 : 1; - actual_types.data = &actual; - check_const_types(ctx, loc, &actual_types, expected, desc); + if (actual != Type::Void) + actual_types.push_back(actual); + check_const_types(ctx, loc, actual_types, expected, desc); } static void check_assert_return_nan_type(Context* ctx, @@ -331,7 +338,7 @@ static void check_expr_list(Context* ctx, } static void check_has_memory(Context* ctx, const Location* loc, Opcode opcode) { - if (ctx->current_module->memories.size == 0) { + if (ctx->current_module->memories.size() == 0) { print_error(ctx, loc, "%s requires an imported or defined memory.", get_opcode_name(opcode)); } @@ -346,8 +353,8 @@ static void check_expr(Context* ctx, const Expr* expr) { break; case ExprType::Block: - typechecker_on_block(&ctx->typechecker, &expr->block.sig); - check_expr_list(ctx, &expr->loc, expr->block.first); + typechecker_on_block(&ctx->typechecker, &expr->block->sig); + check_expr_list(ctx, &expr->loc, expr->block->first); typechecker_on_end(&ctx->typechecker); break; @@ -361,9 +368,8 @@ static void check_expr(Context* ctx, const Expr* expr) { case ExprType::BrTable: { typechecker_begin_br_table(&ctx->typechecker); - for (size_t i = 0; i < expr->br_table.targets.size; ++i) { - typechecker_on_br_table_target(&ctx->typechecker, - expr->br_table.targets.data[i].index); + for (Var& var: *expr->br_table.targets) { + typechecker_on_br_table_target(&ctx->typechecker, var.index); } typechecker_on_br_table_target(&ctx->typechecker, expr->br_table.default_target.index); @@ -382,7 +388,7 @@ static void check_expr(Context* ctx, const Expr* expr) { case ExprType::CallIndirect: { const FuncType* func_type; - if (ctx->current_module->tables.size == 0) { + if (ctx->current_module->tables.size() == 0) { print_error(ctx, &expr->loc, "found call_indirect operator, but no table"); } @@ -429,8 +435,8 @@ static void check_expr(Context* ctx, const Expr* expr) { break; case ExprType::If: - typechecker_on_if(&ctx->typechecker, &expr->if_.true_.sig); - check_expr_list(ctx, &expr->loc, expr->if_.true_.first); + typechecker_on_if(&ctx->typechecker, &expr->if_.true_->sig); + check_expr_list(ctx, &expr->loc, expr->if_.true_->first); if (expr->if_.false_) { typechecker_on_else(&ctx->typechecker); check_expr_list(ctx, &expr->loc, expr->if_.false_); @@ -447,8 +453,8 @@ static void check_expr(Context* ctx, const Expr* expr) { break; case ExprType::Loop: - typechecker_on_loop(&ctx->typechecker, &expr->loop.sig); - check_expr_list(ctx, &expr->loc, expr->loop.first); + typechecker_on_loop(&ctx->typechecker, &expr->loop->sig); + check_expr_list(ctx, &expr->loc, expr->loop->first); typechecker_on_end(&ctx->typechecker); break; @@ -506,12 +512,12 @@ static void check_expr(Context* ctx, const Expr* expr) { static void check_func_signature_matches_func_type(Context* ctx, const Location* loc, - const FuncSignature* sig, + const FuncSignature& sig, const FuncType* func_type) { - check_types(ctx, loc, &sig->result_types, &func_type->sig.result_types, + check_types(ctx, loc, sig.result_types, func_type->sig.result_types, "function", "result"); - check_types(ctx, loc, &sig->param_types, &func_type->sig.param_types, - "function", "argument"); + check_types(ctx, loc, sig.param_types, func_type->sig.param_types, "function", + "argument"); } static void check_func(Context* ctx, const Location* loc, const Func* func) { @@ -525,7 +531,7 @@ static void check_func(Context* ctx, const Location* loc, const Func* func) { const FuncType* func_type; if (WABT_SUCCEEDED( check_func_type_var(ctx, &func->decl.type_var, &func_type))) { - check_func_signature_matches_func_type(ctx, loc, &func->decl.sig, + check_func_signature_matches_func_type(ctx, loc, func->decl.sig, func_type); } } @@ -642,14 +648,13 @@ static void check_elem_segments(Context* ctx, const Module* module) { if (field->type != ModuleFieldType::ElemSegment) continue; - ElemSegment* elem_segment = &field->elem_segment; + ElemSegment* elem_segment = field->elem_segment; const Table* table; if (!WABT_SUCCEEDED(check_table_var(ctx, &elem_segment->table_var, &table))) continue; - for (size_t i = 0; i < elem_segment->vars.size; ++i) { - if (!WABT_SUCCEEDED( - check_func_var(ctx, &elem_segment->vars.data[i], nullptr))) + for (const Var& var: elem_segment->vars) { + if (!WABT_SUCCEEDED(check_func_var(ctx, &var, nullptr))) continue; } @@ -671,7 +676,7 @@ static void check_data_segments(Context* ctx, const Module* module) { if (field->type != ModuleFieldType::DataSegment) continue; - DataSegment* data_segment = &field->data_segment; + DataSegment* data_segment = field->data_segment; const Memory* memory; if (!WABT_SUCCEEDED( check_memory_var(ctx, &data_segment->memory_var, &memory))) @@ -691,15 +696,15 @@ static void check_import(Context* ctx, check_func_type_var(ctx, &import->func->decl.type_var, nullptr); break; case ExternalKind::Table: - check_table(ctx, loc, &import->table); + check_table(ctx, loc, import->table); ctx->current_table_index++; break; case ExternalKind::Memory: - check_memory(ctx, loc, &import->memory); + check_memory(ctx, loc, import->memory); ctx->current_memory_index++; break; case ExternalKind::Global: - if (import->global.mutable_) { + if (import->global->mutable_) { print_error(ctx, loc, "mutable globals cannot be imported"); } ctx->num_imported_globals++; @@ -765,7 +770,7 @@ static void check_module(Context* ctx, const Module* module) { break; case ModuleFieldType::Global: - check_global(ctx, &field->loc, &field->global); + check_global(ctx, &field->loc, field->global); ctx->current_global_index++; break; @@ -774,11 +779,11 @@ static void check_module(Context* ctx, const Module* module) { break; case ModuleFieldType::Export: - check_export(ctx, &field->export_); + check_export(ctx, field->export_); break; case ModuleFieldType::Table: - check_table(ctx, &field->loc, &field->table); + check_table(ctx, &field->loc, field->table); ctx->current_table_index++; break; @@ -787,7 +792,7 @@ static void check_module(Context* ctx, const Module* module) { break; case ModuleFieldType::Memory: - check_memory(ctx, &field->loc, &field->memory); + check_memory(ctx, &field->loc, field->memory); ctx->current_memory_index++; break; @@ -830,18 +835,18 @@ static void check_module(Context* ctx, const Module* module) { * returning nullptr means that another error occured first, so the result type * should be ignored. */ static const TypeVector* check_invoke(Context* ctx, const Action* action) { - const ActionInvoke* invoke = &action->invoke; + const ActionInvoke* invoke = action->invoke; const Module* module = get_module_by_var(ctx->script, &action->module_var); if (!module) { print_error(ctx, &action->loc, "unknown module"); return nullptr; } - Export* export_ = get_export_by_name(module, &invoke->name); + Export* export_ = get_export_by_name(module, &action->name); if (!export_) { print_error(ctx, &action->loc, "unknown function export \"" PRIstringslice "\"", - WABT_PRINTF_STRING_SLICE_ARG(invoke->name)); + WABT_PRINTF_STRING_SLICE_ARG(action->name)); return nullptr; } @@ -851,7 +856,7 @@ static const TypeVector* check_invoke(Context* ctx, const Action* action) { return nullptr; } - size_t actual_args = invoke->args.size; + size_t actual_args = invoke->args.size(); size_t expected_args = get_num_params(func); if (expected_args != actual_args) { print_error(ctx, &action->loc, "too %s parameters to function. got %" PRIzd @@ -861,7 +866,7 @@ static const TypeVector* check_invoke(Context* ctx, const Action* action) { return nullptr; } for (size_t i = 0; i < actual_args; ++i) { - Const* const_ = &invoke->args.data[i]; + const Const* const_ = &invoke->args[i]; check_type_index(ctx, &const_->loc, const_->type, get_param_type(func, i), "invoke", i, "argument"); } @@ -870,18 +875,17 @@ static const TypeVector* check_invoke(Context* ctx, const Action* action) { } static Result check_get(Context* ctx, const Action* action, Type* out_type) { - const ActionGet* get = &action->get; const Module* module = get_module_by_var(ctx->script, &action->module_var); if (!module) { print_error(ctx, &action->loc, "unknown module"); return Result::Error; } - Export* export_ = get_export_by_name(module, &get->name); + Export* export_ = get_export_by_name(module, &action->name); if (!export_) { print_error(ctx, &action->loc, "unknown global export \"" PRIstringslice "\"", - WABT_PRINTF_STRING_SLICE_ARG(get->name)); + WABT_PRINTF_STRING_SLICE_ARG(action->name)); return Result::Error; } @@ -925,7 +929,7 @@ static void check_command(Context* ctx, const Command* command) { case CommandType::Action: /* ignore result type */ - check_action(ctx, &command->action); + check_action(ctx, command->action); break; case CommandType::Register: @@ -938,17 +942,17 @@ static void check_command(Context* ctx, const Command* command) { break; case CommandType::AssertReturn: { - const Action* action = &command->assert_return.action; + const Action* action = command->assert_return.action; ActionResult result = check_action(ctx, action); switch (result.kind) { case ActionResultKind::Types: - check_const_types(ctx, &action->loc, result.types, - &command->assert_return.expected, "action"); + check_const_types(ctx, &action->loc, *result.types, + *command->assert_return.expected, "action"); break; case ActionResultKind::Type: check_const_type(ctx, &action->loc, result.type, - &command->assert_return.expected, "action"); + *command->assert_return.expected, "action"); break; case ActionResultKind::Error: @@ -959,7 +963,7 @@ static void check_command(Context* ctx, const Command* command) { } case CommandType::AssertReturnNan: { - const Action* action = &command->assert_return_nan.action; + const Action* action = command->assert_return_nan.action; ActionResult result = check_action(ctx, action); /* a valid result type will either be f32 or f64; convert a TYPES result @@ -967,12 +971,12 @@ static void check_command(Context* ctx, const Command* command) { * used to specify a type that should not be checked (because an earlier * error occurred). */ if (result.kind == ActionResultKind::Types) { - if (result.types->size == 1) { + if (result.types->size() == 1) { result.kind = ActionResultKind::Type; - result.type = result.types->data[0]; + result.type = (*result.types)[0]; } else { print_error(ctx, &action->loc, "expected 1 result, got %" PRIzd, - result.types->size); + result.types->size()); result.type = Type::Any; } } @@ -985,33 +989,23 @@ static void check_command(Context* ctx, const Command* command) { case CommandType::AssertTrap: case CommandType::AssertExhaustion: /* ignore result type */ - check_action(ctx, &command->assert_trap.action); + check_action(ctx, command->assert_trap.action); break; } } -static void destroy_context(Context* ctx) { - destroy_typechecker(&ctx->typechecker); -} - Result validate_script(AstLexer* lexer, const struct Script* script, SourceErrorHandler* error_handler) { - Context ctx; - WABT_ZERO_MEMORY(ctx); - ctx.lexer = lexer; - ctx.error_handler = error_handler; - ctx.result = Result::Ok; - ctx.script = script; + Context ctx(error_handler, lexer, script); TypeCheckerErrorHandler tc_error_handler; tc_error_handler.on_error = on_typechecker_error; tc_error_handler.user_data = &ctx; ctx.typechecker.error_handler = &tc_error_handler; - for (size_t i = 0; i < script->commands.size; ++i) - check_command(&ctx, &script->commands.data[i]); - destroy_context(&ctx); + for (const std::unique_ptr<Command>& command : script->commands) + check_command(&ctx, command.get()); return ctx.result; } diff --git a/src/vector-sort.h b/src/vector-sort.h deleted file mode 100644 index 64171363..00000000 --- a/src/vector-sort.h +++ /dev/null @@ -1,48 +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_VECTOR_SORT_H_ -#define WABT_VECTOR_SORT_H_ - -#include "vector.h" - -/* - * Define algorithm to sort wabt vectors (defined by macro WABT_VECTOR). - * - */ - -#define WABT_DEFINE_VECTOR_SORT(name, type) \ - static void 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. */ \ - if (in_vec->size == 0) \ - return; \ - for (size_t i = 0; i < in_vec->size; ++i) { \ - append_##name##_value(out_vec, &in_vec->data[i]); \ - if (out_vec->size < 2) \ - continue; \ - for (size_t 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.cc b/src/vector.cc deleted file mode 100644 index 4e119268..00000000 --- a/src/vector.cc +++ /dev/null @@ -1,77 +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 "vector.h" - -#define INITIAL_VECTOR_CAPACITY 8 - -namespace wabt { - -void ensure_capacity(char** 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; - size_t old_byte_capacity = *capacity * elt_byte_size; - char* new_data = new char [new_byte_size]; - memcpy(new_data, *data, old_byte_capacity); - memset(new_data + old_byte_capacity, 0, new_byte_size - old_byte_capacity); - delete[] *data; - *data = new_data; - *capacity = new_capacity; - } -} - -void resize_vector(char** data, - size_t* size, - size_t* capacity, - size_t desired_size, - size_t elt_byte_size) { - size_t old_size = *size; - ensure_capacity(data, capacity, desired_size, elt_byte_size); - if (desired_size > old_size) { - memset(*data + old_size * elt_byte_size, 0, - (desired_size - old_size) * elt_byte_size); - } - *size = desired_size; -} - -void* append_element(char** data, - size_t* size, - size_t* capacity, - size_t elt_byte_size) { - ensure_capacity(data, capacity, *size + 1, elt_byte_size); - char* p = *data + (*size)++ * elt_byte_size; - memset(p, 0, elt_byte_size); - return p; -} - -void extend_elements(char** dst, - size_t* dst_size, - size_t* dst_capacity, - char* const* src, - size_t src_size, - size_t elt_byte_size) { - ensure_capacity(dst, dst_capacity, *dst_size + src_size, elt_byte_size); - memcpy(*dst + (*dst_size * elt_byte_size), *src, src_size * elt_byte_size); - *dst_size += src_size; -} - -} // namespace wabt diff --git a/src/vector.h b/src/vector.h deleted file mode 100644 index 6a3d0ad9..00000000 --- a/src/vector.h +++ /dev/null @@ -1,125 +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_VECTOR_H_ -#define WABT_VECTOR_H_ - -#include <stddef.h> - -#include "common.h" -#include "config.h" - -/* - * WABT_DEFINE_VECTOR(widget, Widget) defines struct and functions like the - * following: - * - * struct WidgetVector { - * Widget* data; - * size_t size; - * size_t capacity; - * }; - * - * void destroy_widget_vector(WidgetVector* vec); - * Widget* append_widget(WidgetVector* vec); - * void resize_widget_vector(WidgetVector* vec, size_t size); - * void reserve_widgets(WidgetVector* vec, size_t desired); - * void append_widget_value(WidgetVector* vec, const Widget* value); - * void extend_widgets(WidgetVector* dst, const WidgetVector* src); - */ - -#define WABT_DEFINE_VECTOR(name, type) \ - struct type##Vector { \ - type* data; \ - size_t size; \ - size_t capacity; \ - }; \ - \ - static WABT_INLINE void destroy_##name##_vector(type##Vector* vec) \ - WABT_UNUSED; \ - static WABT_INLINE void resize_##name##_vector(type##Vector* vec, \ - size_t desired) WABT_UNUSED; \ - static WABT_INLINE void reserve_##name##s(type##Vector* vec, size_t desired) \ - WABT_UNUSED; \ - static WABT_INLINE type* append_##name(type##Vector* vec) WABT_UNUSED; \ - static WABT_INLINE void append_##name##_value( \ - type##Vector* vec, const type* value) WABT_UNUSED; \ - static WABT_INLINE void extend_##name##s( \ - type##Vector* dst, const type##Vector* src) WABT_UNUSED; \ - \ - void destroy_##name##_vector(type##Vector* vec) { \ - delete[] vec->data; \ - vec->data = nullptr; \ - vec->size = 0; \ - vec->capacity = 0; \ - } \ - void resize_##name##_vector(type##Vector* vec, size_t size) { \ - resize_vector(reinterpret_cast<char**>(&vec->data), &vec->size, \ - &vec->capacity, size, sizeof(type)); \ - } \ - void reserve_##name##s(type##Vector* vec, size_t desired) { \ - ensure_capacity(reinterpret_cast<char**>(&vec->data), &vec->capacity, \ - desired, sizeof(type)); \ - } \ - type* append_##name(type##Vector* vec) { \ - return static_cast<type*>( \ - append_element(reinterpret_cast<char**>(&vec->data), &vec->size, \ - &vec->capacity, sizeof(type))); \ - } \ - void append_##name##_value(type##Vector* vec, const type* value) { \ - type* slot = append_##name(vec); \ - *slot = *value; \ - } \ - void extend_##name##s(type##Vector* dst, const type##Vector* src) { \ - extend_elements( \ - reinterpret_cast<char**>(&dst->data), &dst->size, &dst->capacity, \ - reinterpret_cast<char* const*>(&src->data), src->size, sizeof(type)); \ - } - -#define WABT_DESTROY_VECTOR_AND_ELEMENTS(v, name) \ - { \ - for (size_t i = 0; i < (v).size; ++i) \ - destroy_##name(&((v).data[i])); \ - destroy_##name##_vector(&(v)); \ - } - -namespace wabt { - -void ensure_capacity(char** data, - size_t* capacity, - size_t desired_size, - size_t elt_byte_size); - -void resize_vector(char** data, - size_t* size, - size_t* capacity, - size_t desired_size, - size_t elt_byte_size); - -void* append_element(char** data, - size_t* size, - size_t* capacity, - size_t elt_byte_size); - -void extend_elements(char** dst, - size_t* dst_size, - size_t* dst_capacity, - char* const* src, - size_t src_size, - size_t elt_byte_size); - -} // namespace wabt - -#endif /* WABT_VECTOR_H_ */ diff --git a/src/wasm-link.h b/src/wasm-link.h index 8b7f8b2f..6ddbe148 100644 --- a/src/wasm-link.h +++ b/src/wasm-link.h @@ -17,9 +17,11 @@ #ifndef WABT_LINK_H_ #define WABT_LINK_H_ +#include <memory> +#include <vector> + #include "binary.h" #include "common.h" -#include "vector.h" #define WABT_LINK_MODULE_NAME "__extern" @@ -35,14 +37,12 @@ struct FunctionImport { struct LinkerInputBinary* foreign_binary; uint32_t foreign_index; }; -WABT_DEFINE_VECTOR(function_import, FunctionImport); struct GlobalImport { StringSlice name; Type type; bool mutable_; }; -WABT_DEFINE_VECTOR(global_import, GlobalImport); struct DataSegment { uint32_t memory_index; @@ -50,16 +50,12 @@ struct DataSegment { const uint8_t* data; size_t size; }; -WABT_DEFINE_VECTOR(data_segment, DataSegment); - -WABT_DEFINE_VECTOR(reloc, Reloc); struct Export { ExternalKind kind; StringSlice name; uint32_t index; }; -WABT_DEFINE_VECTOR(export, Export); struct SectionDataCustom { /* Reference to string data stored in the containing InputBinary */ @@ -67,9 +63,13 @@ struct SectionDataCustom { }; struct Section { + WABT_DISALLOW_COPY_AND_ASSIGN(Section); + Section(); + ~Section(); + /* The binary to which this section belongs */ struct LinkerInputBinary* binary; - RelocVector relocations; /* The relocations for this section */ + std::vector<Reloc> relocations; /* The relocations for this section */ BinarySection section_code; size_t size; @@ -85,7 +85,7 @@ struct Section { /* CUSTOM section data */ SectionDataCustom data_custom; /* DATA section data */ - DataSegmentVector data_segments; + std::vector<DataSegment>* data_segments; /* MEMORY section data */ Limits memory_limits; }; @@ -94,24 +94,23 @@ struct Section { * section. */ size_t output_payload_offset; }; -WABT_DEFINE_VECTOR(section, Section); -typedef Section* SectionPtr; -WABT_DEFINE_VECTOR(section_ptr, SectionPtr); - -WABT_DEFINE_VECTOR(string_slice, StringSlice); +typedef std::vector<Section*> SectionPtrVector; struct LinkerInputBinary { + WABT_DISALLOW_COPY_AND_ASSIGN(LinkerInputBinary); + LinkerInputBinary(const char* filename, uint8_t* data, size_t size); + ~LinkerInputBinary(); + const char* filename; uint8_t* data; size_t size; - SectionVector sections; - - ExportVector exports; + std::vector<std::unique_ptr<Section>> sections; + std::vector<Export> exports; - FunctionImportVector function_imports; + std::vector<FunctionImport> function_imports; uint32_t active_function_imports; - GlobalImportVector global_imports; + std::vector<GlobalImport> global_imports; uint32_t active_global_imports; uint32_t type_index_offset; @@ -125,9 +124,8 @@ struct LinkerInputBinary { uint32_t table_elem_count; - StringSliceVector debug_names; + std::vector<std::string> debug_names; }; -WABT_DEFINE_VECTOR(binary, LinkerInputBinary); } // namespace link } // namespace wabt |