diff options
Diffstat (limited to 'src')
56 files changed, 1417 insertions, 1441 deletions
diff --git a/src/apply-names.cc b/src/apply-names.cc index 06647d0d..1616ea2d 100644 --- a/src/apply-names.cc +++ b/src/apply-names.cc @@ -373,7 +373,7 @@ Result NameApplier::VisitModule(Module* module) { } // end anonymous namespace -Result apply_names(Module* module) { +Result ApplyNames(Module* module) { NameApplier applier; return applier.VisitModule(module); } diff --git a/src/apply-names.h b/src/apply-names.h index eeb0f0ee..3088608c 100644 --- a/src/apply-names.h +++ b/src/apply-names.h @@ -38,7 +38,7 @@ struct Module; * ... * (call $foo ...) */ -Result apply_names(struct Module*); +Result ApplyNames(struct Module*); } // namespace wabt diff --git a/src/binary-reader-interpreter.cc b/src/binary-reader-interpreter.cc index 74724439..b369b2f8 100644 --- a/src/binary-reader-interpreter.cc +++ b/src/binary-reader-interpreter.cc @@ -615,7 +615,7 @@ wabt::Result BinaryReaderInterpreter::CheckImportKind( "\" to have kind %s, not %s", WABT_PRINTF_STRING_VIEW_ARG(import->module_name), WABT_PRINTF_STRING_VIEW_ARG(import->field_name), - get_kind_name(expected_kind), get_kind_name(import->kind)); + GetKindName(expected_kind), GetKindName(import->kind)); return wabt::Result::Error; } return wabt::Result::Ok; @@ -859,8 +859,8 @@ wabt::Result BinaryReaderInterpreter::EndGlobalInitExpr(Index index) { Global* global = GetGlobalByModuleIndex(index); if (init_expr_value.type != global->typed_value.type) { PrintError("type mismatch in global, expected %s but got %s.", - get_type_name(global->typed_value.type), - get_type_name(init_expr_value.type)); + GetTypeName(global->typed_value.type), + GetTypeName(init_expr_value.type)); return wabt::Result::Error; } global->typed_value = init_expr_value; @@ -967,7 +967,7 @@ wabt::Result BinaryReaderInterpreter::OnStartFunction(Index func_index) { wabt::Result BinaryReaderInterpreter::EndElemSegmentInitExpr(Index index) { if (init_expr_value.type != Type::I32) { PrintError("type mismatch in elem segment, expected i32 but got %s", - get_type_name(init_expr_value.type)); + GetTypeName(init_expr_value.type)); return wabt::Result::Error; } table_offset = init_expr_value.value.i32; @@ -1004,7 +1004,7 @@ wabt::Result BinaryReaderInterpreter::OnDataSegmentData(Index index, Memory* memory = env->GetMemory(module->memory_index); if (init_expr_value.type != Type::I32) { PrintError("type mismatch in data segment, expected i32 but got %s", - get_type_name(init_expr_value.type)); + GetTypeName(init_expr_value.type)); return wabt::Result::Error; } Address address = init_expr_value.value.i32; @@ -1438,12 +1438,12 @@ wabt::Result BinaryReaderInterpreter::EndModule() { } // end anonymous namespace -wabt::Result read_binary_interpreter(Environment* env, - const void* data, - size_t size, - const ReadBinaryOptions* options, - ErrorHandler* error_handler, - DefinedModule** out_module) { +wabt::Result ReadBinaryInterpreter(Environment* env, + const void* data, + size_t size, + const ReadBinaryOptions* options, + ErrorHandler* error_handler, + DefinedModule** out_module) { // Need to mark before taking ownership of env->istream. Environment::MarkPoint mark = env->Mark(); @@ -1455,7 +1455,7 @@ wabt::Result read_binary_interpreter(Environment* env, error_handler); env->EmplaceBackModule(module); - wabt::Result result = read_binary(data, size, &reader, options); + wabt::Result result = ReadBinary(data, size, &reader, options); env->SetIstream(reader.ReleaseOutputBuffer()); if (Succeeded(result)) { diff --git a/src/binary-reader-interpreter.h b/src/binary-reader-interpreter.h index 0cd08d83..bf2013a9 100644 --- a/src/binary-reader-interpreter.h +++ b/src/binary-reader-interpreter.h @@ -31,12 +31,12 @@ class Environment; class ErrorHandler; struct ReadBinaryOptions; -Result read_binary_interpreter(interpreter::Environment* env, - const void* data, - size_t size, - const ReadBinaryOptions* options, - ErrorHandler*, - interpreter::DefinedModule** out_module); +Result ReadBinaryInterpreter(interpreter::Environment* env, + const void* data, + size_t size, + const ReadBinaryOptions* options, + ErrorHandler*, + interpreter::DefinedModule** out_module); } // namespace wabt diff --git a/src/binary-reader-ir.cc b/src/binary-reader-ir.cc index c8bf4cbc..96e228f1 100644 --- a/src/binary-reader-ir.cc +++ b/src/binary-reader-ir.cc @@ -981,14 +981,14 @@ Result BinaryReaderIR::OnExceptionType(Index index, TypeVector& sig) { } // end anonymous namespace -Result read_binary_ir(const char* filename, - const void* data, - size_t size, - const ReadBinaryOptions* options, - ErrorHandler* error_handler, - struct Module* out_module) { +Result ReadBinaryIr(const char* filename, + const void* data, + size_t size, + const ReadBinaryOptions* options, + ErrorHandler* error_handler, + struct Module* out_module) { BinaryReaderIR reader(out_module, filename, error_handler); - Result result = read_binary(data, size, &reader, options); + Result result = ReadBinary(data, size, &reader, options); return result; } diff --git a/src/binary-reader-ir.h b/src/binary-reader-ir.h index b5d730fa..227663b7 100644 --- a/src/binary-reader-ir.h +++ b/src/binary-reader-ir.h @@ -25,12 +25,12 @@ class ErrorHandler; struct Module; struct ReadBinaryOptions; -Result read_binary_ir(const char* filename, - const void* data, - size_t size, - const ReadBinaryOptions* options, - ErrorHandler*, - Module* out_module); +Result ReadBinaryIr(const char* filename, + const void* data, + size_t size, + const ReadBinaryOptions* options, + ErrorHandler*, + Module* out_module); } // namespace wabt diff --git a/src/binary-reader-linker.cc b/src/binary-reader-linker.cc index 7ad89526..065569db 100644 --- a/src/binary-reader-linker.cc +++ b/src/binary-reader-linker.cc @@ -188,7 +188,7 @@ Result BinaryReaderLinker::BeginSection(BinarySection section_code, const uint8_t* start = &binary_->data[sec->offset]; // Must point to one-past-the-end, but we can't dereference end(). const uint8_t* end = &binary_->data.back() + 1; - size_t bytes_read = read_u32_leb128(start, end, &sec->count); + size_t bytes_read = ReadU32Leb128(start, end, &sec->count); if (bytes_read == 0) WABT_FATAL("error reading section element count\n"); sec->payload_offset = sec->offset + bytes_read; @@ -283,14 +283,14 @@ Result BinaryReaderLinker::OnFunctionName(Index index, string_view name) { } // end anonymous namespace -Result read_binary_linker(LinkerInputBinary* input_info, LinkOptions* options) { +Result ReadBinaryLinker(LinkerInputBinary* input_info, LinkOptions* options) { BinaryReaderLinker reader(input_info); ReadBinaryOptions read_options; read_options.read_debug_names = true; read_options.log_stream = options->log_stream; - return read_binary(DataOrNull(input_info->data), input_info->data.size(), - &reader, &read_options); + return ReadBinary(DataOrNull(input_info->data), input_info->data.size(), + &reader, &read_options); } } // namespace link diff --git a/src/binary-reader-linker.h b/src/binary-reader-linker.h index 84b0f3c9..73ae2f22 100644 --- a/src/binary-reader-linker.h +++ b/src/binary-reader-linker.h @@ -32,8 +32,7 @@ struct LinkOptions { Stream* log_stream; }; -Result read_binary_linker(LinkerInputBinary* input_info, - LinkOptions* options); +Result ReadBinaryLinker(LinkerInputBinary* input_info, LinkOptions* options); } // namespace link } // namespace wabt diff --git a/src/binary-reader-logging.cc b/src/binary-reader-logging.cc index 6a9afbdd..8af52125 100644 --- a/src/binary-reader-logging.cc +++ b/src/binary-reader-logging.cc @@ -34,7 +34,7 @@ namespace wabt { namespace { -void sprint_limits(char* dst, size_t size, const Limits* limits) { +void SPrintLimits(char* dst, size_t size, const Limits* limits) { int result; if (limits->has_max) { result = wabt_snprintf(dst, size, "initial: %" PRIu64 ", max: %" PRIu64, @@ -79,7 +79,7 @@ void BinaryReaderLogging::WriteIndent() { void BinaryReaderLogging::LogTypes(Index type_count, Type* types) { LOGF_NOINDENT("["); for (Index i = 0; i < type_count; ++i) { - LOGF_NOINDENT("%s", get_type_name(types[i])); + LOGF_NOINDENT("%s", GetTypeName(types[i])); if (i != type_count - 1) LOGF_NOINDENT(", "); } @@ -161,10 +161,10 @@ Result BinaryReaderLogging::OnImportTable(Index import_index, Type elem_type, const Limits* elem_limits) { char buf[100]; - sprint_limits(buf, sizeof(buf), elem_limits); + SPrintLimits(buf, sizeof(buf), elem_limits); LOGF("OnImportTable(import_index: %" PRIindex ", table_index: %" PRIindex ", elem_type: %s, %s)\n", - import_index, table_index, get_type_name(elem_type), buf); + import_index, table_index, GetTypeName(elem_type), buf); return reader->OnImportTable(import_index, module_name, field_name, table_index, elem_type, elem_limits); } @@ -175,7 +175,7 @@ Result BinaryReaderLogging::OnImportMemory(Index import_index, Index memory_index, const Limits* page_limits) { char buf[100]; - sprint_limits(buf, sizeof(buf), page_limits); + SPrintLimits(buf, sizeof(buf), page_limits); LOGF("OnImportMemory(import_index: %" PRIindex ", memory_index: %" PRIindex ", %s)\n", import_index, memory_index, buf); @@ -192,7 +192,7 @@ Result BinaryReaderLogging::OnImportGlobal(Index import_index, LOGF("OnImportGlobal(import_index: %" PRIindex ", global_index: %" PRIindex ", type: %s, mutable: " "%s)\n", - import_index, global_index, get_type_name(type), + import_index, global_index, GetTypeName(type), mutable_ ? "true" : "false"); return reader->OnImportGlobal(import_index, module_name, field_name, global_index, type, mutable_); @@ -216,22 +216,22 @@ Result BinaryReaderLogging::OnTable(Index index, Type elem_type, const Limits* elem_limits) { char buf[100]; - sprint_limits(buf, sizeof(buf), elem_limits); + SPrintLimits(buf, sizeof(buf), elem_limits); LOGF("OnTable(index: %" PRIindex ", elem_type: %s, %s)\n", index, - get_type_name(elem_type), buf); + GetTypeName(elem_type), buf); return reader->OnTable(index, elem_type, elem_limits); } Result BinaryReaderLogging::OnMemory(Index index, const Limits* page_limits) { char buf[100]; - sprint_limits(buf, sizeof(buf), page_limits); + SPrintLimits(buf, sizeof(buf), page_limits); LOGF("OnMemory(index: %" PRIindex ", %s)\n", index, buf); return reader->OnMemory(index, page_limits); } Result BinaryReaderLogging::BeginGlobal(Index index, Type type, bool mutable_) { LOGF("BeginGlobal(index: %" PRIindex ", type: %s, mutable: %s)\n", index, - get_type_name(type), mutable_ ? "true" : "false"); + GetTypeName(type), mutable_ ? "true" : "false"); return reader->BeginGlobal(index, type, mutable_); } @@ -241,8 +241,7 @@ Result BinaryReaderLogging::OnExport(Index index, string_view name) { LOGF("OnExport(index: %" PRIindex ", kind: %s, item_index: %" PRIindex ", name: \"" PRIstringview "\")\n", - index, get_kind_name(kind), item_index, - WABT_PRINTF_STRING_VIEW_ARG(name)); + index, GetKindName(kind), item_index, WABT_PRINTF_STRING_VIEW_ARG(name)); return reader->OnExport(index, kind, item_index, name); } @@ -250,7 +249,7 @@ Result BinaryReaderLogging::OnLocalDecl(Index decl_index, Index count, Type type) { LOGF("OnLocalDecl(index: %" PRIindex ", count: %" PRIindex ", type: %s)\n", - decl_index, count, get_type_name(type)); + decl_index, count, GetTypeName(type)); return reader->OnLocalDecl(decl_index, count, type); } @@ -434,7 +433,7 @@ Result BinaryReaderLogging::OnRelocCount(Index count, string_view section_name) { LOGF("OnRelocCount(count: %" PRIindex ", section: %s, section_name: " PRIstringview ")\n", - count, get_section_name(section_code), + count, GetSectionName(section_code), WABT_PRINTF_STRING_VIEW_ARG(section_name)); return reader->OnRelocCount(count, section_code, section_name); } @@ -446,7 +445,7 @@ Result BinaryReaderLogging::OnReloc(RelocType type, int32_t signed_addend = static_cast<int32_t>(addend); LOGF("OnReloc(type: %s, offset: %" PRIzd ", index: %" PRIindex ", addend: %d)\n", - get_reloc_type_name(type), offset, index, signed_addend); + GetRelocTypeName(type), offset, index, signed_addend); return reader->OnReloc(type, offset, index, addend); } diff --git a/src/binary-reader-objdump.cc b/src/binary-reader-objdump.cc index 5f097917..f295a020 100644 --- a/src/binary-reader-objdump.cc +++ b/src/binary-reader-objdump.cc @@ -128,7 +128,7 @@ const char* BinaryReaderObjdumpBase::GetFunctionName(Index index) const { void BinaryReaderObjdumpBase::PrintRelocation(const Reloc& reloc, Offset offset) const { printf(" %06" PRIzx ": %-18s %" PRIindex "", offset, - get_reloc_type_name(reloc.type), reloc.index); + GetRelocTypeName(reloc.type), reloc.index); switch (reloc.type) { case RelocType::GlobalAddressLEB: case RelocType::GlobalAddressSLEB: @@ -335,7 +335,7 @@ Result BinaryReaderObjdumpDisassemble::OnOpcodeUint64(uint64_t value) { Result BinaryReaderObjdumpDisassemble::OnOpcodeF32(uint32_t value) { Offset immediate_len = state->offset - current_opcode_offset; char buffer[WABT_MAX_FLOAT_HEX]; - write_float_hex(buffer, sizeof(buffer), value); + WriteFloatHex(buffer, sizeof(buffer), value); LogOpcode(data, immediate_len, buffer); return Result::Ok; } @@ -343,7 +343,7 @@ Result BinaryReaderObjdumpDisassemble::OnOpcodeF32(uint32_t value) { Result BinaryReaderObjdumpDisassemble::OnOpcodeF64(uint64_t value) { Offset immediate_len = state->offset - current_opcode_offset; char buffer[WABT_MAX_DOUBLE_HEX]; - write_double_hex(buffer, sizeof(buffer), value); + WriteDoubleHex(buffer, sizeof(buffer), value); LogOpcode(data, immediate_len, buffer); return Result::Ok; } @@ -583,7 +583,7 @@ Result BinaryReaderObjdump::BeginSection(BinarySection section_code, Offset size) { BinaryReaderObjdumpBase::BeginSection(section_code, size); - const char* name = get_section_name(section_code); + const char* name = GetSectionName(section_code); bool section_match = !options->section_name || !strcasecmp(options->section_name, name); @@ -737,9 +737,8 @@ Result BinaryReaderObjdump::OnImportTable(Index import_index, PrintDetails(" - " PRIstringview "." PRIstringview " -> table elem_type=%s init=%" PRId64 " max=%" PRId64 "\n", WABT_PRINTF_STRING_VIEW_ARG(module_name), - WABT_PRINTF_STRING_VIEW_ARG(field_name), - get_type_name(elem_type), elem_limits->initial, - elem_limits->max); + WABT_PRINTF_STRING_VIEW_ARG(field_name), GetTypeName(elem_type), + elem_limits->initial, elem_limits->max); return Result::Ok; } @@ -762,7 +761,7 @@ Result BinaryReaderObjdump::OnImportGlobal(Index import_index, bool mutable_) { PrintDetails(" - global[%" PRIindex "] %s mutable=%d <- " PRIstringview "." PRIstringview "\n", - global_index, get_type_name(type), mutable_, + global_index, GetTypeName(type), mutable_, WABT_PRINTF_STRING_VIEW_ARG(module_name), WABT_PRINTF_STRING_VIEW_ARG(field_name)); return Result::Ok; @@ -807,7 +806,7 @@ Result BinaryReaderObjdump::OnTable(Index index, Type elem_type, const Limits* elem_limits) { PrintDetails(" - table[%" PRIindex "] type=%s initial=%" PRId64, index, - get_type_name(elem_type), elem_limits->initial); + GetTypeName(elem_type), elem_limits->initial); if (elem_limits->has_max) PrintDetails(" max=%" PRId64, elem_limits->max); PrintDetails("\n"); @@ -822,7 +821,7 @@ Result BinaryReaderObjdump::OnExport(Index index, ExternalKind kind, Index item_index, string_view name) { - PrintDetails(" - %s[%" PRIindex "]", get_kind_name(kind), item_index); + PrintDetails(" - %s[%" PRIindex "]", GetKindName(kind), item_index); if (kind == ExternalKind::Func) { if (const char* name = GetFunctionName(item_index)) PrintDetails(" <%s>", name); @@ -861,7 +860,7 @@ Result BinaryReaderObjdump::OnGlobalCount(Index count) { Result BinaryReaderObjdump::BeginGlobal(Index index, Type type, bool mutable_) { PrintDetails(" - global[%" PRIindex "] %s mutable=%d", index, - get_type_name(type), mutable_); + GetTypeName(type), mutable_); return Result::Ok; } @@ -875,13 +874,13 @@ void BinaryReaderObjdump::PrintInitExpr(const InitExpr& expr) { break; case InitExprType::F64: { char buffer[WABT_MAX_DOUBLE_HEX]; - write_float_hex(buffer, sizeof(buffer), expr.value.f64); + WriteFloatHex(buffer, sizeof(buffer), expr.value.f64); PrintDetails(" - init f64=%s\n", buffer); break; } case InitExprType::F32: { char buffer[WABT_MAX_FLOAT_HEX]; - write_float_hex(buffer, sizeof(buffer), expr.value.f32); + WriteFloatHex(buffer, sizeof(buffer), expr.value.f32); PrintDetails(" - init f32=%s\n", buffer); break; } @@ -1033,7 +1032,7 @@ Result BinaryReaderObjdump::OnRelocCount(Index count, BinarySection section_code, string_view section_name) { BinaryReaderObjdumpBase::OnRelocCount(count, section_code, section_name); - PrintDetails(" - section: %s\n", get_section_name(section_code)); + PrintDetails(" - section: %s\n", GetSectionName(section_code)); return Result::Ok; } @@ -1044,7 +1043,7 @@ Result BinaryReaderObjdump::OnReloc(RelocType type, Offset total_offset = GetSectionStart(reloc_section) + offset; PrintDetails(" - %-18s offset=%#08" PRIoffset "(file=%#08" PRIoffset ") index=%" PRIindex, - get_reloc_type_name(type), offset, total_offset, index); + GetRelocTypeName(type), offset, total_offset, index); if (addend) { int32_t signed_addend = static_cast<int32_t>(addend); if (signed_addend < 0) { @@ -1096,10 +1095,10 @@ Result BinaryReaderObjdump::OnExceptionType( } // end anonymous namespace -Result read_binary_objdump(const uint8_t* data, - size_t size, - ObjdumpOptions* options, - ObjdumpState* state) { +Result ReadBinaryObjdump(const uint8_t* data, + size_t size, + ObjdumpOptions* options, + ObjdumpState* state) { ReadBinaryOptions read_options; read_options.read_debug_names = true; read_options.log_stream = options->log_stream; @@ -1108,15 +1107,15 @@ Result read_binary_objdump(const uint8_t* data, switch (options->mode) { case ObjdumpMode::Prepass: { BinaryReaderObjdumpPrepass reader(data, size, options, state); - return read_binary(data, size, &reader, &read_options); + return ReadBinary(data, size, &reader, &read_options); } case ObjdumpMode::Disassemble: { BinaryReaderObjdumpDisassemble reader(data, size, options, state); - return read_binary(data, size, &reader, &read_options); + return ReadBinary(data, size, &reader, &read_options); } default: { BinaryReaderObjdump reader(data, size, options, state); - return read_binary(data, size, &reader, &read_options); + return ReadBinary(data, size, &reader, &read_options); } } } diff --git a/src/binary-reader-objdump.h b/src/binary-reader-objdump.h index c6ecfdc3..fbda3ffb 100644 --- a/src/binary-reader-objdump.h +++ b/src/binary-reader-objdump.h @@ -58,10 +58,10 @@ struct ObjdumpState { std::vector<std::string> function_names; }; -Result read_binary_objdump(const uint8_t* data, - size_t size, - ObjdumpOptions* options, - ObjdumpState* state); +Result ReadBinaryObjdump(const uint8_t* data, + size_t size, + ObjdumpOptions* options, + ObjdumpState* state); } // namespace wabt diff --git a/src/binary-reader-opcnt.cc b/src/binary-reader-opcnt.cc index 739149e5..704bed64 100644 --- a/src/binary-reader-opcnt.cc +++ b/src/binary-reader-opcnt.cc @@ -123,12 +123,12 @@ Result BinaryReaderOpcnt::OnStoreExpr(Opcode opcode, } // end anonymous namespace -Result read_binary_opcnt(const void* data, - size_t size, - const struct ReadBinaryOptions* options, - OpcntData* opcnt_data) { +Result ReadBinaryOpcnt(const void* data, + size_t size, + const struct ReadBinaryOptions* options, + OpcntData* opcnt_data) { BinaryReaderOpcnt reader(opcnt_data); - return read_binary(data, size, &reader, options); + return ReadBinary(data, size, &reader, options); } } // namespace wabt diff --git a/src/binary-reader-opcnt.h b/src/binary-reader-opcnt.h index 5404622a..1f1207dc 100644 --- a/src/binary-reader-opcnt.h +++ b/src/binary-reader-opcnt.h @@ -57,10 +57,10 @@ struct OpcntData { void init_opcnt_data(OpcntData* data); void destroy_opcnt_data(OpcntData* data); -Result read_binary_opcnt(const void* data, - size_t size, - const struct ReadBinaryOptions* options, - OpcntData* opcnt_data); +Result ReadBinaryOpcnt(const void* data, + size_t size, + const struct ReadBinaryOptions* options, + OpcntData* opcnt_data); } // namespace wabt diff --git a/src/binary-reader.cc b/src/binary-reader.cc index fcdf40d9..9bdbf153 100644 --- a/src/binary-reader.cc +++ b/src/binary-reader.cc @@ -83,9 +83,9 @@ namespace wabt { SHIFT_AMOUNT(type, sign_bit)) // TODO(binji): move LEB functions elsewhere -size_t read_u32_leb128(const uint8_t* p, - const uint8_t* end, - uint32_t* out_value) { +size_t ReadU32Leb128(const uint8_t* p, + const uint8_t* end, + uint32_t* out_value) { if (p < end && (p[0] & 0x80) == 0) { *out_value = LEB128_1(uint32_t); return 1; @@ -111,9 +111,9 @@ size_t read_u32_leb128(const uint8_t* p, } } -size_t read_i32_leb128(const uint8_t* p, - const uint8_t* end, - uint32_t* out_value) { +size_t ReadI32Leb128(const uint8_t* p, + const uint8_t* end, + uint32_t* out_value) { if (p < end && (p[0] & 0x80) == 0) { uint32_t result = LEB128_1(uint32_t); *out_value = SIGN_EXTEND(int32_t, result, 6); @@ -304,7 +304,7 @@ Result BinaryReader::ReadF64(uint64_t* out_value, const char* desc) { Result BinaryReader::ReadU32Leb128(uint32_t* out_value, const char* desc) { const uint8_t* p = state_.data + state_.offset; const uint8_t* end = state_.data + read_end_; - size_t bytes_read = read_u32_leb128(p, end, out_value); + size_t bytes_read = wabt::ReadU32Leb128(p, end, out_value); ERROR_UNLESS(bytes_read > 0, "unable to read u32 leb128: %s", desc); state_.offset += bytes_read; return Result::Ok; @@ -313,7 +313,7 @@ Result BinaryReader::ReadU32Leb128(uint32_t* out_value, const char* desc) { Result BinaryReader::ReadI32Leb128(uint32_t* out_value, const char* desc) { const uint8_t* p = state_.data + state_.offset; const uint8_t* end = state_.data + read_end_; - size_t bytes_read = read_i32_leb128(p, end, out_value); + size_t bytes_read = wabt::ReadI32Leb128(p, end, out_value); ERROR_UNLESS(bytes_read > 0, "unable to read i32 leb128: %s", desc); state_.offset += bytes_read; return Result::Ok; @@ -415,7 +415,7 @@ Result BinaryReader::ReadStr(string_view* out_str, const char* desc) { reinterpret_cast<const char*>(state_.data) + state_.offset, str_len); state_.offset += str_len; - ERROR_UNLESS(is_valid_utf8(out_str->data(), out_str->length()), + ERROR_UNLESS(IsValidUtf8(out_str->data(), out_str->length()), "invalid utf-8 encoding: %s", desc); return Result::Ok; } @@ -1665,7 +1665,7 @@ Result BinaryReader::ReadSections() { ERROR_UNLESS(last_known_section_ == BinarySection::Invalid || section == BinarySection::Custom || section > last_known_section_, - "section %s out of order", get_section_name(section)); + "section %s out of order", GetSectionName(section)); CALLBACK(BeginSection, section, section_size); @@ -1712,10 +1712,10 @@ Result BinaryReader::ReadModule() { } // end anonymous namespace -Result read_binary(const void* data, - size_t size, - BinaryReaderDelegate* delegate, - const ReadBinaryOptions* options) { +Result ReadBinary(const void* data, + size_t size, + BinaryReaderDelegate* delegate, + const ReadBinaryOptions* options) { BinaryReader reader(data, size, delegate, options); return reader.ReadModule(); } diff --git a/src/binary-reader.h b/src/binary-reader.h index 79066de1..cc653197 100644 --- a/src/binary-reader.h +++ b/src/binary-reader.h @@ -297,18 +297,18 @@ class BinaryReaderDelegate { const State* state = nullptr; }; -Result read_binary(const void* data, - size_t size, - BinaryReaderDelegate* reader, - const ReadBinaryOptions* options); - -size_t read_u32_leb128(const uint8_t* ptr, - const uint8_t* end, - uint32_t* out_value); - -size_t read_i32_leb128(const uint8_t* ptr, - const uint8_t* end, - uint32_t* out_value); +Result ReadBinary(const void* data, + size_t size, + BinaryReaderDelegate* reader, + const ReadBinaryOptions* options); + +size_t ReadU32Leb128(const uint8_t* ptr, + const uint8_t* end, + uint32_t* out_value); + +size_t ReadI32Leb128(const uint8_t* ptr, + const uint8_t* end, + uint32_t* out_value); } // namespace wabt diff --git a/src/binary-writer-spec.cc b/src/binary-writer-spec.cc index 15def4a2..08887852 100644 --- a/src/binary-writer-spec.cc +++ b/src/binary-writer-spec.cc @@ -185,7 +185,7 @@ void BinaryWriterSpec::WriteVar(const Var* var) { void BinaryWriterSpec::WriteTypeObject(Type type) { json_stream_.Writef("{"); WriteKey("type"); - WriteString(get_type_name(type)); + WriteString(GetTypeName(type)); json_stream_.Writef("}"); } @@ -304,8 +304,8 @@ void BinaryWriterSpec::WriteActionResultType(Script* script, void BinaryWriterSpec::WriteModule(string_view filename, const Module* module) { MemoryStream memory_stream; - result_ = write_binary_module(&memory_stream.writer(), module, - &spec_options_->write_binary_options); + result_ = WriteBinaryModule(&memory_stream.writer(), module, + &spec_options_->write_binary_options); if (Succeeded(result_) && write_modules_) result_ = memory_stream.WriteToFile(filename); } @@ -549,9 +549,9 @@ Result BinaryWriterSpec::WriteScript(Script* script) { } // end anonymous namespace -Result write_binary_spec_script(Script* script, - const char* source_filename, - const WriteBinarySpecOptions* spec_options) { +Result WriteBinarySpecScript(Script* script, + const char* source_filename, + const WriteBinarySpecOptions* spec_options) { assert(source_filename); BinaryWriterSpec binary_writer_spec(source_filename, spec_options); return binary_writer_spec.WriteScript(script); diff --git a/src/binary-writer-spec.h b/src/binary-writer-spec.h index d30de7db..e0efb768 100644 --- a/src/binary-writer-spec.h +++ b/src/binary-writer-spec.h @@ -28,9 +28,9 @@ struct WriteBinarySpecOptions { WriteBinaryOptions write_binary_options; }; -Result write_binary_spec_script(struct Script*, - const char* source_filename, - const WriteBinarySpecOptions*); +Result WriteBinarySpecScript(struct Script*, + const char* source_filename, + const WriteBinarySpecOptions*); } // namespace wabt diff --git a/src/binary-writer.cc b/src/binary-writer.cc index b28d09ca..5705fc1f 100644 --- a/src/binary-writer.cc +++ b/src/binary-writer.cc @@ -39,7 +39,7 @@ namespace wabt { // TODO(binji): move the LEB128 functions somewhere else. -Offset u32_leb128_length(uint32_t value) { +Offset U32Leb128Length(uint32_t value) { uint32_t size = 0; do { value >>= 7; @@ -60,36 +60,36 @@ Offset u32_leb128_length(uint32_t value) { } \ } while (1) -Offset write_fixed_u32_leb128_at(Stream* stream, - Offset offset, - uint32_t value, - const char* desc) { +Offset WriteFixedU32Leb128At(Stream* stream, + Offset offset, + uint32_t value, + const char* desc) { uint8_t data[MAX_U32_LEB128_BYTES]; Offset length = - write_fixed_u32_leb128_raw(data, data + MAX_U32_LEB128_BYTES, value); + WriteFixedU32Leb128Raw(data, data + MAX_U32_LEB128_BYTES, value); stream->WriteDataAt(offset, data, length, desc); return length; } -void write_u32_leb128(Stream* stream, uint32_t value, const char* desc) { +void WriteU32Leb128(Stream* stream, uint32_t value, const char* desc) { uint8_t data[MAX_U32_LEB128_BYTES]; Offset length = 0; LEB128_LOOP_UNTIL(value == 0); stream->WriteData(data, length, desc); } -void write_fixed_u32_leb128(Stream* stream, uint32_t value, const char* desc) { +void WriteFixedU32Leb128(Stream* stream, uint32_t value, const char* desc) { uint8_t data[MAX_U32_LEB128_BYTES]; Offset length = - write_fixed_u32_leb128_raw(data, data + MAX_U32_LEB128_BYTES, value); + WriteFixedU32Leb128Raw(data, data + MAX_U32_LEB128_BYTES, value); stream->WriteData(data, length, desc); } /* returns the length of the leb128 */ -Offset write_u32_leb128_at(Stream* stream, - Offset offset, - uint32_t value, - const char* desc) { +Offset WriteU32Leb128At(Stream* stream, + Offset offset, + uint32_t value, + const char* desc) { uint8_t data[MAX_U32_LEB128_BYTES]; Offset length = 0; LEB128_LOOP_UNTIL(value == 0); @@ -97,7 +97,7 @@ Offset write_u32_leb128_at(Stream* stream, return length; } -Offset write_fixed_u32_leb128_raw(uint8_t* data, uint8_t* end, uint32_t value) { +Offset WriteFixedU32Leb128Raw(uint8_t* data, uint8_t* end, uint32_t value) { if (end - data < MAX_U32_LEB128_BYTES) return 0; data[0] = (value & 0x7f) | 0x80; @@ -108,7 +108,7 @@ Offset write_fixed_u32_leb128_raw(uint8_t* data, uint8_t* end, uint32_t value) { return MAX_U32_LEB128_BYTES; } -void write_i32_leb128(Stream* stream, int32_t value, const char* desc) { +void WriteI32Leb128(Stream* stream, int32_t value, const char* desc) { uint8_t data[MAX_U32_LEB128_BYTES]; Offset length = 0; if (value < 0) @@ -119,7 +119,7 @@ void write_i32_leb128(Stream* stream, int32_t value, const char* desc) { stream->WriteData(data, length, desc); } -static void write_i64_leb128(Stream* stream, int64_t value, const char* desc) { +static void WriteI64Leb128(Stream* stream, int64_t value, const char* desc) { uint8_t data[MAX_U64_LEB128_BYTES]; Offset length = 0; if (value < 0) @@ -133,38 +133,38 @@ static void write_i64_leb128(Stream* stream, int64_t value, const char* desc) { #undef LEB128_LOOP_UNTIL -void write_str(Stream* stream, - string_view s, - const char* desc, - PrintChars print_chars) { - write_u32_leb128(stream, s.length(), "string length"); +void WriteStr(Stream* stream, + string_view s, + const char* desc, + PrintChars print_chars) { + WriteU32Leb128(stream, s.length(), "string length"); stream->WriteData(s.data(), s.length(), desc, print_chars); } -void write_opcode(Stream* stream, Opcode opcode) { +void WriteOpcode(Stream* stream, Opcode opcode) { stream->WriteU8Enum(opcode.GetCode(), opcode.GetName()); } -void write_type(Stream* stream, Type type) { - write_i32_leb128_enum(stream, type, get_type_name(type)); +void WriteType(Stream* stream, Type type) { + WriteI32Leb128Enum(stream, type, GetTypeName(type)); } -void write_limits(Stream* stream, const Limits* limits) { +void WriteLimits(Stream* stream, const Limits* limits) { uint32_t flags = limits->has_max ? WABT_BINARY_LIMITS_HAS_MAX_FLAG : 0; - write_u32_leb128(stream, flags, "limits: flags"); - write_u32_leb128(stream, limits->initial, "limits: initial"); + WriteU32Leb128(stream, flags, "limits: flags"); + WriteU32Leb128(stream, limits->initial, "limits: initial"); if (limits->has_max) - write_u32_leb128(stream, limits->max, "limits: max"); + WriteU32Leb128(stream, limits->max, "limits: max"); } -void write_debug_name(Stream* stream, string_view name, const char* desc) { +void WriteDebugName(Stream* stream, string_view name, const char* desc) { string_view stripped_name = name; if (!stripped_name.empty()) { // Strip leading $ from name assert(stripped_name.front() == '$'); stripped_name.remove_prefix(1); } - write_str(stream, stripped_name, desc, PrintChars::Yes); + WriteStr(stream, stripped_name, desc, PrintChars::Yes); } namespace { @@ -283,19 +283,19 @@ Offset BinaryWriter::WriteFixupU32Leb128Size(Offset offset, const char* desc) { if (options_->canonicalize_lebs) { Offset size = stream_.offset() - offset - leb_size_guess; - Offset leb_size = u32_leb128_length(size); + Offset leb_size = U32Leb128Length(size); Offset delta = leb_size - leb_size_guess; if (delta != 0) { Offset src_offset = offset + leb_size_guess; Offset dst_offset = offset + leb_size; stream_.MoveData(dst_offset, src_offset, size); } - write_u32_leb128_at(&stream_, offset, size, desc); + WriteU32Leb128At(&stream_, offset, size, desc); stream_.AddOffset(delta); return delta; } else { Offset size = stream_.offset() - offset - MAX_U32_LEB128_BYTES; - write_fixed_u32_leb128_at(&stream_, offset, size, desc); + WriteFixedU32Leb128At(&stream_, offset, size, desc); return 0; } } @@ -303,9 +303,9 @@ Offset BinaryWriter::WriteFixupU32Leb128Size(Offset offset, static void write_inline_signature_type(Stream* stream, const BlockSignature& sig) { if (sig.size() == 0) { - write_type(stream, Type::Void); + WriteType(stream, Type::Void); } else if (sig.size() == 1) { - write_type(stream, sig[0]); + WriteType(stream, sig[0]); } else { /* this is currently unrepresentable */ stream->WriteU8(0xff, "INVALID INLINE SIGNATURE"); @@ -317,7 +317,7 @@ void BinaryWriter::BeginKnownSection(BinarySection section_code, assert(last_section_leb_size_guess_ == 0); char desc[100]; wabt_snprintf(desc, sizeof(desc), "section \"%s\" (%u)", - get_section_name(section_code), + GetSectionName(section_code), static_cast<unsigned>(section_code)); WriteHeader(desc, PRINT_HEADER_NO_INDEX); stream_.WriteU8Enum(section_code, "section code"); @@ -339,7 +339,7 @@ void BinaryWriter::BeginCustomSection(const char* name, size_t leb_size_guess) { last_section_offset_ = WriteU32Leb128Space(leb_size_guess, "section size (guess)"); last_section_payload_offset_ = stream_.offset(); - write_str(&stream_, name, "custom section name", PrintChars::Yes); + WriteStr(&stream_, name, "custom section name", PrintChars::Yes); } void BinaryWriter::EndSection() { @@ -381,7 +381,7 @@ void BinaryWriter::AddReloc(RelocType reloc_type, Index index) { // Add a new reloc section if needed if (!current_reloc_section_ || current_reloc_section_->section_code != last_section_type_) { - reloc_sections_.emplace_back(get_section_name(last_section_type_), + reloc_sections_.emplace_back(GetSectionName(last_section_type_), last_section_type_); current_reloc_section_ = &reloc_sections_.back(); } @@ -396,9 +396,9 @@ void BinaryWriter::WriteU32Leb128WithReloc(Index index, RelocType reloc_type) { if (options_->relocatable) { AddReloc(reloc_type, index); - write_fixed_u32_leb128(&stream_, index, desc); + WriteFixedU32Leb128(&stream_, index, desc); } else { - write_u32_leb128(&stream_, index, desc); + WriteU32Leb128(&stream_, index, desc); } } @@ -419,72 +419,72 @@ void BinaryWriter::WriteExpr(const Module* module, const Expr* expr) { switch (expr->type) { case ExprType::Binary: - write_opcode(&stream_, cast<BinaryExpr>(expr)->opcode); + WriteOpcode(&stream_, cast<BinaryExpr>(expr)->opcode); break; case ExprType::Block: - write_opcode(&stream_, Opcode::Block); + WriteOpcode(&stream_, Opcode::Block); write_inline_signature_type(&stream_, cast<BlockExpr>(expr)->block->sig); WriteExprList(module, func, cast<BlockExpr>(expr)->block->exprs); - write_opcode(&stream_, Opcode::End); + WriteOpcode(&stream_, Opcode::End); break; case ExprType::Br: - write_opcode(&stream_, Opcode::Br); - write_u32_leb128(&stream_, GetLabelVarDepth(&cast<BrExpr>(expr)->var), - "break depth"); + WriteOpcode(&stream_, Opcode::Br); + WriteU32Leb128(&stream_, GetLabelVarDepth(&cast<BrExpr>(expr)->var), + "break depth"); break; case ExprType::BrIf: - write_opcode(&stream_, Opcode::BrIf); - write_u32_leb128(&stream_, GetLabelVarDepth(&cast<BrIfExpr>(expr)->var), - "break depth"); + WriteOpcode(&stream_, Opcode::BrIf); + WriteU32Leb128(&stream_, GetLabelVarDepth(&cast<BrIfExpr>(expr)->var), + "break depth"); break; case ExprType::BrTable: { auto br_table_expr = cast<BrTableExpr>(expr); - write_opcode(&stream_, Opcode::BrTable); - write_u32_leb128(&stream_, br_table_expr->targets->size(), "num targets"); + WriteOpcode(&stream_, Opcode::BrTable); + WriteU32Leb128(&stream_, br_table_expr->targets->size(), "num targets"); Index depth; for (const Var& var : *br_table_expr->targets) { depth = GetLabelVarDepth(&var); - write_u32_leb128(&stream_, depth, "break depth"); + WriteU32Leb128(&stream_, depth, "break depth"); } depth = GetLabelVarDepth(&br_table_expr->default_target); - write_u32_leb128(&stream_, depth, "break depth for default"); + WriteU32Leb128(&stream_, depth, "break depth for default"); break; } case ExprType::Call: { Index index = module->GetFuncIndex(cast<CallExpr>(expr)->var); - write_opcode(&stream_, Opcode::Call); + WriteOpcode(&stream_, Opcode::Call); WriteU32Leb128WithReloc(index, "function index", RelocType::FuncIndexLEB); break; } case ExprType::CallIndirect: { Index index = module->GetFuncTypeIndex(cast<CallIndirectExpr>(expr)->var); - write_opcode(&stream_, Opcode::CallIndirect); + WriteOpcode(&stream_, Opcode::CallIndirect); WriteU32Leb128WithReloc(index, "signature index", RelocType::TypeIndexLEB); - write_u32_leb128(&stream_, 0, "call_indirect reserved"); + WriteU32Leb128(&stream_, 0, "call_indirect reserved"); break; } case ExprType::Compare: - write_opcode(&stream_, cast<CompareExpr>(expr)->opcode); + WriteOpcode(&stream_, cast<CompareExpr>(expr)->opcode); break; case ExprType::Const: { const Const& const_ = cast<ConstExpr>(expr)->const_; switch (const_.type) { case Type::I32: { - write_opcode(&stream_, Opcode::I32Const); - write_i32_leb128(&stream_, const_.u32, "i32 literal"); + WriteOpcode(&stream_, Opcode::I32Const); + WriteI32Leb128(&stream_, const_.u32, "i32 literal"); break; } case Type::I64: - write_opcode(&stream_, Opcode::I64Const); - write_i64_leb128(&stream_, const_.u64, "i64 literal"); + WriteOpcode(&stream_, Opcode::I64Const); + WriteI64Leb128(&stream_, const_.u64, "i64 literal"); break; case Type::F32: - write_opcode(&stream_, Opcode::F32Const); + WriteOpcode(&stream_, Opcode::F32Const); stream_.WriteU32(const_.f32_bits, "f32 literal"); break; case Type::F64: - write_opcode(&stream_, Opcode::F64Const); + WriteOpcode(&stream_, Opcode::F64Const); stream_.WriteU64(const_.f64_bits, "f64 literal"); break; default: @@ -493,126 +493,125 @@ void BinaryWriter::WriteExpr(const Module* module, break; } case ExprType::Convert: - write_opcode(&stream_, cast<ConvertExpr>(expr)->opcode); + WriteOpcode(&stream_, cast<ConvertExpr>(expr)->opcode); break; case ExprType::CurrentMemory: - write_opcode(&stream_, Opcode::CurrentMemory); - write_u32_leb128(&stream_, 0, "current_memory reserved"); + WriteOpcode(&stream_, Opcode::CurrentMemory); + WriteU32Leb128(&stream_, 0, "current_memory reserved"); break; case ExprType::Drop: - write_opcode(&stream_, Opcode::Drop); + WriteOpcode(&stream_, Opcode::Drop); break; case ExprType::GetGlobal: { Index index = module->GetGlobalIndex(cast<GetGlobalExpr>(expr)->var); - write_opcode(&stream_, Opcode::GetGlobal); + WriteOpcode(&stream_, Opcode::GetGlobal); WriteU32Leb128WithReloc(index, "global index", RelocType::GlobalIndexLEB); break; } case ExprType::GetLocal: { Index index = GetLocalIndex(func, cast<GetLocalExpr>(expr)->var); - write_opcode(&stream_, Opcode::GetLocal); - write_u32_leb128(&stream_, index, "local index"); + WriteOpcode(&stream_, Opcode::GetLocal); + WriteU32Leb128(&stream_, index, "local index"); break; } case ExprType::GrowMemory: - write_opcode(&stream_, Opcode::GrowMemory); - write_u32_leb128(&stream_, 0, "grow_memory reserved"); + WriteOpcode(&stream_, Opcode::GrowMemory); + WriteU32Leb128(&stream_, 0, "grow_memory reserved"); break; case ExprType::If: { auto if_expr = cast<IfExpr>(expr); - write_opcode(&stream_, Opcode::If); + WriteOpcode(&stream_, Opcode::If); write_inline_signature_type(&stream_, if_expr->true_->sig); WriteExprList(module, func, if_expr->true_->exprs); if (!if_expr->false_.empty()) { - write_opcode(&stream_, Opcode::Else); + WriteOpcode(&stream_, Opcode::Else); WriteExprList(module, func, if_expr->false_); } - write_opcode(&stream_, Opcode::End); + WriteOpcode(&stream_, Opcode::End); break; } case ExprType::Load: { auto load_expr = cast<LoadExpr>(expr); - write_opcode(&stream_, load_expr->opcode); + WriteOpcode(&stream_, load_expr->opcode); Address align = load_expr->opcode.GetAlignment(load_expr->align); stream_.WriteU8(log2_u32(align), "alignment"); - write_u32_leb128(&stream_, load_expr->offset, "load offset"); + WriteU32Leb128(&stream_, load_expr->offset, "load offset"); break; } case ExprType::Loop: - write_opcode(&stream_, Opcode::Loop); + WriteOpcode(&stream_, Opcode::Loop); write_inline_signature_type(&stream_, cast<LoopExpr>(expr)->block->sig); WriteExprList(module, func, cast<LoopExpr>(expr)->block->exprs); - write_opcode(&stream_, Opcode::End); + WriteOpcode(&stream_, Opcode::End); break; case ExprType::Nop: - write_opcode(&stream_, Opcode::Nop); + WriteOpcode(&stream_, Opcode::Nop); break; case ExprType::Rethrow: - write_opcode(&stream_, Opcode::Rethrow); - write_u32_leb128(&stream_, - GetLabelVarDepth(&cast<RethrowExpr>(expr)->var), - "rethrow depth"); + WriteOpcode(&stream_, Opcode::Rethrow); + WriteU32Leb128(&stream_, GetLabelVarDepth(&cast<RethrowExpr>(expr)->var), + "rethrow depth"); break; case ExprType::Return: - write_opcode(&stream_, Opcode::Return); + WriteOpcode(&stream_, Opcode::Return); break; case ExprType::Select: - write_opcode(&stream_, Opcode::Select); + WriteOpcode(&stream_, Opcode::Select); break; case ExprType::SetGlobal: { Index index = module->GetGlobalIndex(cast<SetGlobalExpr>(expr)->var); - write_opcode(&stream_, Opcode::SetGlobal); + WriteOpcode(&stream_, Opcode::SetGlobal); WriteU32Leb128WithReloc(index, "global index", RelocType::GlobalIndexLEB); break; } case ExprType::SetLocal: { Index index = GetLocalIndex(func, cast<SetLocalExpr>(expr)->var); - write_opcode(&stream_, Opcode::SetLocal); - write_u32_leb128(&stream_, index, "local index"); + WriteOpcode(&stream_, Opcode::SetLocal); + WriteU32Leb128(&stream_, index, "local index"); break; } case ExprType::Store: { auto store_expr = cast<StoreExpr>(expr); - write_opcode(&stream_, store_expr->opcode); + WriteOpcode(&stream_, store_expr->opcode); Address align = store_expr->opcode.GetAlignment(store_expr->align); stream_.WriteU8(log2_u32(align), "alignment"); - write_u32_leb128(&stream_, store_expr->offset, "store offset"); + WriteU32Leb128(&stream_, store_expr->offset, "store offset"); break; } case ExprType::TeeLocal: { Index index = GetLocalIndex(func, cast<TeeLocalExpr>(expr)->var); - write_opcode(&stream_, Opcode::TeeLocal); - write_u32_leb128(&stream_, index, "local index"); + WriteOpcode(&stream_, Opcode::TeeLocal); + WriteU32Leb128(&stream_, index, "local index"); break; } case ExprType::Throw: - write_opcode(&stream_, Opcode::Throw); - write_u32_leb128(&stream_, GetExceptVarDepth(&cast<ThrowExpr>(expr)->var), - "throw exception"); + WriteOpcode(&stream_, Opcode::Throw); + WriteU32Leb128(&stream_, GetExceptVarDepth(&cast<ThrowExpr>(expr)->var), + "throw exception"); break; case ExprType::TryBlock: { auto try_expr = cast<TryExpr>(expr); - write_opcode(&stream_, Opcode::Try); + WriteOpcode(&stream_, Opcode::Try); write_inline_signature_type(&stream_, try_expr->block->sig); WriteExprList(module, func, try_expr->block->exprs); for (Catch* catch_ : try_expr->catches) { if (catch_->IsCatchAll()) { - write_opcode(&stream_, Opcode::CatchAll); + WriteOpcode(&stream_, Opcode::CatchAll); } else { - write_opcode(&stream_, Opcode::Catch); - write_u32_leb128(&stream_, GetExceptVarDepth(&catch_->var), - "catch exception"); + WriteOpcode(&stream_, Opcode::Catch); + WriteU32Leb128(&stream_, GetExceptVarDepth(&catch_->var), + "catch exception"); } WriteExprList(module, func, catch_->exprs); } - write_opcode(&stream_, Opcode::End); + WriteOpcode(&stream_, Opcode::End); break; } case ExprType::Unary: - write_opcode(&stream_, cast<UnaryExpr>(expr)->opcode); + WriteOpcode(&stream_, cast<UnaryExpr>(expr)->opcode); break; case ExprType::Unreachable: - write_opcode(&stream_, Opcode::Unreachable); + WriteOpcode(&stream_, Opcode::Unreachable); break; } } @@ -626,14 +625,14 @@ void BinaryWriter::WriteExprList(const Module* module, void BinaryWriter::WriteInitExpr(const Module* module, const ExprList& expr) { WriteExprList(module, nullptr, expr); - write_opcode(&stream_, Opcode::End); + WriteOpcode(&stream_, Opcode::End); } void BinaryWriter::WriteFuncLocals(const Module* module, const Func* func, const TypeVector& local_types) { if (local_types.size() == 0) { - write_u32_leb128(&stream_, 0, "local decl count"); + WriteU32Leb128(&stream_, 0, "local decl count"); return; } @@ -655,7 +654,7 @@ void BinaryWriter::WriteFuncLocals(const Module* module, } /* loop through again to write everything out */ - write_u32_leb128(&stream_, local_decl_count, "local decl count"); + WriteU32Leb128(&stream_, local_decl_count, "local decl count"); current_type = GET_LOCAL_TYPE(FIRST_LOCAL_INDEX); Index local_type_count = 1; for (Index i = FIRST_LOCAL_INDEX + 1; i <= LAST_LOCAL_INDEX; ++i) { @@ -664,8 +663,8 @@ void BinaryWriter::WriteFuncLocals(const Module* module, if (current_type == type) { local_type_count++; } else { - write_u32_leb128(&stream_, local_type_count, "local type count"); - write_type(&stream_, current_type); + WriteU32Leb128(&stream_, local_type_count, "local type count"); + WriteType(&stream_, current_type); local_type_count = 1; current_type = type; } @@ -675,27 +674,27 @@ void BinaryWriter::WriteFuncLocals(const Module* module, void BinaryWriter::WriteFunc(const Module* module, const Func* func) { WriteFuncLocals(module, func, func->local_types); WriteExprList(module, func, func->exprs); - write_opcode(&stream_, Opcode::End); + WriteOpcode(&stream_, Opcode::End); } void BinaryWriter::WriteTable(const Table* table) { - write_type(&stream_, Type::Anyfunc); - write_limits(&stream_, &table->elem_limits); + WriteType(&stream_, Type::Anyfunc); + WriteLimits(&stream_, &table->elem_limits); } void BinaryWriter::WriteMemory(const Memory* memory) { - write_limits(&stream_, &memory->page_limits); + WriteLimits(&stream_, &memory->page_limits); } void BinaryWriter::WriteGlobalHeader(const Global* global) { - write_type(&stream_, global->type); + WriteType(&stream_, global->type); stream_.WriteU8(global->mutable_, "global mutability"); } void BinaryWriter::WriteExceptType(const TypeVector* except_types) { - write_u32_leb128(&stream_, except_types->size(), "exception type count"); + WriteU32Leb128(&stream_, except_types->size(), "exception type count"); for (Type ty : *except_types) - write_type(&stream_, ty); + WriteType(&stream_, ty); } void BinaryWriter::WriteRelocSection(const RelocSection* reloc_section) { @@ -703,20 +702,20 @@ void BinaryWriter::WriteRelocSection(const RelocSection* reloc_section) { wabt_snprintf(section_name, sizeof(section_name), "%s.%s", WABT_BINARY_SECTION_RELOC, reloc_section->name); BeginCustomSection(section_name, LEB_SECTION_SIZE_GUESS); - write_u32_leb128_enum(&stream_, reloc_section->section_code, - "reloc section type"); + WriteU32Leb128Enum(&stream_, reloc_section->section_code, + "reloc section type"); const std::vector<Reloc>& relocs = reloc_section->relocations; - write_u32_leb128(&stream_, relocs.size(), "num relocs"); + WriteU32Leb128(&stream_, relocs.size(), "num relocs"); for (const Reloc& reloc : relocs) { - write_u32_leb128_enum(&stream_, reloc.type, "reloc type"); - write_u32_leb128(&stream_, reloc.offset, "reloc offset"); - write_u32_leb128(&stream_, reloc.index, "reloc index"); + WriteU32Leb128Enum(&stream_, reloc.type, "reloc type"); + WriteU32Leb128(&stream_, reloc.offset, "reloc offset"); + WriteU32Leb128(&stream_, reloc.index, "reloc index"); switch (reloc.type) { case RelocType::GlobalAddressLEB: case RelocType::GlobalAddressSLEB: case RelocType::GlobalAddressI32: - write_u32_leb128(&stream_, reloc.addend, "reloc addend"); + WriteU32Leb128(&stream_, reloc.addend, "reloc addend"); break; default: break; @@ -732,43 +731,42 @@ Result BinaryWriter::WriteModule(const Module* module) { if (module->func_types.size()) { BeginKnownSection(BinarySection::Type, LEB_SECTION_SIZE_GUESS); - write_u32_leb128(&stream_, module->func_types.size(), "num types"); + WriteU32Leb128(&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; WriteHeader("type", i); - write_type(&stream_, Type::Func); + WriteType(&stream_, Type::Func); Index num_params = sig->param_types.size(); Index num_results = sig->result_types.size(); - write_u32_leb128(&stream_, num_params, "num params"); + WriteU32Leb128(&stream_, num_params, "num params"); for (size_t j = 0; j < num_params; ++j) - write_type(&stream_, sig->param_types[j]); + WriteType(&stream_, sig->param_types[j]); - write_u32_leb128(&stream_, num_results, "num results"); + WriteU32Leb128(&stream_, num_results, "num results"); for (size_t j = 0; j < num_results; ++j) - write_type(&stream_, sig->result_types[j]); + WriteType(&stream_, sig->result_types[j]); } EndSection(); } if (module->imports.size()) { BeginKnownSection(BinarySection::Import, LEB_SECTION_SIZE_GUESS); - write_u32_leb128(&stream_, module->imports.size(), "num imports"); + WriteU32Leb128(&stream_, module->imports.size(), "num imports"); for (size_t i = 0; i < module->imports.size(); ++i) { const Import* import = module->imports[i]; WriteHeader("import header", i); - write_str(&stream_, import->module_name, "import module name", - PrintChars::Yes); - write_str(&stream_, import->field_name, "import field name", - PrintChars::Yes); + WriteStr(&stream_, import->module_name, "import module name", + PrintChars::Yes); + WriteStr(&stream_, import->field_name, "import field name", + PrintChars::Yes); stream_.WriteU8Enum(import->kind, "import kind"); switch (import->kind) { case ExternalKind::Func: - write_u32_leb128(&stream_, - module->GetFuncTypeIndex(import->func->decl), - "import signature index"); + WriteU32Leb128(&stream_, module->GetFuncTypeIndex(import->func->decl), + "import signature index"); break; case ExternalKind::Table: WriteTable(import->table); @@ -791,14 +789,14 @@ Result BinaryWriter::WriteModule(const Module* module) { Index num_funcs = module->funcs.size() - module->num_func_imports; if (num_funcs) { BeginKnownSection(BinarySection::Function, LEB_SECTION_SIZE_GUESS); - write_u32_leb128(&stream_, num_funcs, "num functions"); + WriteU32Leb128(&stream_, num_funcs, "num functions"); for (size_t i = 0; i < num_funcs; ++i) { const Func* func = module->funcs[i + module->num_func_imports]; char desc[100]; wabt_snprintf(desc, sizeof(desc), "function %" PRIzd " signature index", i); - write_u32_leb128(&stream_, module->GetFuncTypeIndex(func->decl), desc); + WriteU32Leb128(&stream_, module->GetFuncTypeIndex(func->decl), desc); } EndSection(); } @@ -807,7 +805,7 @@ Result BinaryWriter::WriteModule(const Module* module) { Index num_tables = module->tables.size() - module->num_table_imports; if (num_tables) { BeginKnownSection(BinarySection::Table, LEB_SECTION_SIZE_GUESS); - write_u32_leb128(&stream_, num_tables, "num tables"); + WriteU32Leb128(&stream_, num_tables, "num tables"); for (size_t i = 0; i < num_tables; ++i) { const Table* table = module->tables[i + module->num_table_imports]; WriteHeader("table", i); @@ -820,7 +818,7 @@ Result BinaryWriter::WriteModule(const Module* module) { Index num_memories = module->memories.size() - module->num_memory_imports; if (num_memories) { BeginKnownSection(BinarySection::Memory, LEB_SECTION_SIZE_GUESS); - write_u32_leb128(&stream_, num_memories, "num memories"); + WriteU32Leb128(&stream_, num_memories, "num memories"); for (size_t i = 0; i < num_memories; ++i) { const Memory* memory = module->memories[i + module->num_memory_imports]; WriteHeader("memory", i); @@ -833,7 +831,7 @@ Result BinaryWriter::WriteModule(const Module* module) { Index num_globals = module->globals.size() - module->num_global_imports; if (num_globals) { BeginKnownSection(BinarySection::Global, LEB_SECTION_SIZE_GUESS); - write_u32_leb128(&stream_, num_globals, "num globals"); + WriteU32Leb128(&stream_, num_globals, "num globals"); for (size_t i = 0; i < num_globals; ++i) { const Global* global = module->globals[i + module->num_global_imports]; @@ -845,35 +843,35 @@ Result BinaryWriter::WriteModule(const Module* module) { if (module->exports.size()) { BeginKnownSection(BinarySection::Export, LEB_SECTION_SIZE_GUESS); - write_u32_leb128(&stream_, module->exports.size(), "num exports"); + WriteU32Leb128(&stream_, module->exports.size(), "num exports"); for (const Export* export_ : module->exports) { - write_str(&stream_, export_->name, "export name", PrintChars::Yes); + WriteStr(&stream_, export_->name, "export name", PrintChars::Yes); stream_.WriteU8Enum(export_->kind, "export kind"); switch (export_->kind) { case ExternalKind::Func: { Index index = module->GetFuncIndex(export_->var); - write_u32_leb128(&stream_, index, "export func index"); + WriteU32Leb128(&stream_, index, "export func index"); break; } case ExternalKind::Table: { Index index = module->GetTableIndex(export_->var); - write_u32_leb128(&stream_, index, "export table index"); + WriteU32Leb128(&stream_, index, "export table index"); break; } case ExternalKind::Memory: { Index index = module->GetMemoryIndex(export_->var); - write_u32_leb128(&stream_, index, "export memory index"); + WriteU32Leb128(&stream_, index, "export memory index"); break; } case ExternalKind::Global: { Index index = module->GetGlobalIndex(export_->var); - write_u32_leb128(&stream_, index, "export global index"); + WriteU32Leb128(&stream_, index, "export global index"); break; } case ExternalKind::Except: { Index index = module->GetExceptIndex(export_->var); - write_u32_leb128(&stream_, index, "export exception index"); + WriteU32Leb128(&stream_, index, "export exception index"); break; } } @@ -885,22 +883,21 @@ Result BinaryWriter::WriteModule(const Module* module) { Index start_func_index = module->GetFuncIndex(*module->start); if (start_func_index != kInvalidIndex) { BeginKnownSection(BinarySection::Start, LEB_SECTION_SIZE_GUESS); - write_u32_leb128(&stream_, start_func_index, "start func index"); + WriteU32Leb128(&stream_, start_func_index, "start func index"); EndSection(); } } if (module->elem_segments.size()) { BeginKnownSection(BinarySection::Elem, LEB_SECTION_SIZE_GUESS); - write_u32_leb128(&stream_, module->elem_segments.size(), - "num elem segments"); + WriteU32Leb128(&stream_, module->elem_segments.size(), "num elem segments"); for (size_t i = 0; i < module->elem_segments.size(); ++i) { ElemSegment* segment = module->elem_segments[i]; Index table_index = module->GetTableIndex(segment->table_var); WriteHeader("elem segment header", i); - write_u32_leb128(&stream_, table_index, "table index"); + WriteU32Leb128(&stream_, table_index, "table index"); WriteInitExpr(module, segment->offset); - write_u32_leb128(&stream_, segment->vars.size(), "num function indices"); + WriteU32Leb128(&stream_, segment->vars.size(), "num function indices"); for (const Var& var : segment->vars) { Index index = module->GetFuncIndex(var); WriteU32Leb128WithReloc(index, "function index", @@ -914,7 +911,7 @@ Result BinaryWriter::WriteModule(const Module* module) { Index num_exceptions = module->excepts.size() - module->num_except_imports; if (num_exceptions) { BeginCustomSection("exception", LEB_SECTION_SIZE_GUESS); - write_u32_leb128(&stream_, num_exceptions, "exception count"); + WriteU32Leb128(&stream_, num_exceptions, "exception count"); for (Index i = module->num_except_imports; i < num_exceptions; ++i) { WriteExceptType(&module->excepts[i]->sig); } @@ -923,7 +920,7 @@ Result BinaryWriter::WriteModule(const Module* module) { if (num_funcs) { BeginKnownSection(BinarySection::Code, LEB_SECTION_SIZE_GUESS); - write_u32_leb128(&stream_, num_funcs, "num functions"); + WriteU32Leb128(&stream_, num_funcs, "num functions"); for (size_t i = 0; i < num_funcs; ++i) { WriteHeader("function body", i); @@ -942,15 +939,14 @@ Result BinaryWriter::WriteModule(const Module* module) { if (module->data_segments.size()) { BeginKnownSection(BinarySection::Data, LEB_SECTION_SIZE_GUESS); - write_u32_leb128(&stream_, module->data_segments.size(), - "num data segments"); + WriteU32Leb128(&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[i]; WriteHeader("data segment header", i); Index memory_index = module->GetMemoryIndex(segment->memory_var); - write_u32_leb128(&stream_, memory_index, "memory index"); + WriteU32Leb128(&stream_, memory_index, "memory index"); WriteInitExpr(module, segment->offset); - write_u32_leb128(&stream_, segment->data.size(), "data segment size"); + WriteU32Leb128(&stream_, segment->data.size(), "data segment size"); WriteHeader("data segment data", i); stream_.WriteData(segment->data, "data segment data"); } @@ -970,41 +966,41 @@ Result BinaryWriter::WriteModule(const Module* module) { } if (named_functions > 0) { - write_u32_leb128(&stream_, 1, "function name type"); + WriteU32Leb128(&stream_, 1, "function name type"); BeginSubsection("function name subsection", LEB_SECTION_SIZE_GUESS); - write_u32_leb128(&stream_, named_functions, "num functions"); + WriteU32Leb128(&stream_, named_functions, "num functions"); for (size_t i = 0; i < module->funcs.size(); ++i) { const Func* func = module->funcs[i]; if (func->name.empty()) continue; - write_u32_leb128(&stream_, i, "function index"); + WriteU32Leb128(&stream_, i, "function index"); wabt_snprintf(desc, sizeof(desc), "func name %" PRIzd, i); - write_debug_name(&stream_, func->name, desc); + WriteDebugName(&stream_, func->name, desc); } EndSubsection(); } - write_u32_leb128(&stream_, 2, "local name type"); + WriteU32Leb128(&stream_, 2, "local name type"); BeginSubsection("local name subsection", LEB_SECTION_SIZE_GUESS); - write_u32_leb128(&stream_, module->funcs.size(), "num functions"); + WriteU32Leb128(&stream_, module->funcs.size(), "num functions"); for (size_t i = 0; i < module->funcs.size(); ++i) { const Func* func = module->funcs[i]; Index num_params = func->GetNumParams(); Index num_locals = func->local_types.size(); Index num_params_and_locals = func->GetNumParamsAndLocals(); - write_u32_leb128(&stream_, i, "function index"); - write_u32_leb128(&stream_, num_params_and_locals, "num locals"); + WriteU32Leb128(&stream_, i, "function index"); + WriteU32Leb128(&stream_, num_params_and_locals, "num locals"); MakeTypeBindingReverseMapping(func->decl.sig.param_types, func->param_bindings, &index_to_name); for (size_t j = 0; j < num_params; ++j) { const std::string& name = index_to_name[j]; wabt_snprintf(desc, sizeof(desc), "local name %" PRIzd, j); - write_u32_leb128(&stream_, j, "local index"); - write_debug_name(&stream_, name, desc); + WriteU32Leb128(&stream_, j, "local index"); + WriteDebugName(&stream_, name, desc); } MakeTypeBindingReverseMapping(func->local_types, func->local_bindings, @@ -1012,8 +1008,8 @@ Result BinaryWriter::WriteModule(const Module* module) { for (size_t j = 0; j < num_locals; ++j) { const std::string& name = index_to_name[j]; wabt_snprintf(desc, sizeof(desc), "local name %" PRIzd, num_params + j); - write_u32_leb128(&stream_, num_params + j, "local index"); - write_debug_name(&stream_, name, desc); + WriteU32Leb128(&stream_, num_params + j, "local index"); + WriteDebugName(&stream_, name, desc); } } EndSubsection(); @@ -1032,9 +1028,9 @@ Result BinaryWriter::WriteModule(const Module* module) { } // end anonymous namespace -Result write_binary_module(Writer* writer, - const Module* module, - const WriteBinaryOptions* options) { +Result WriteBinaryModule(Writer* writer, + const Module* module, + const WriteBinaryOptions* options) { BinaryWriter binary_writer(writer, options); return binary_writer.WriteModule(module); } diff --git a/src/binary-writer.h b/src/binary-writer.h index 5500a67f..2ddb0178 100644 --- a/src/binary-writer.h +++ b/src/binary-writer.h @@ -34,44 +34,44 @@ struct WriteBinaryOptions { bool write_debug_names = false; }; -Result write_binary_module(Writer*, const Module*, const WriteBinaryOptions*); +Result WriteBinaryModule(Writer*, const Module*, const WriteBinaryOptions*); /* returns the length of the leb128 */ -Offset u32_leb128_length(uint32_t value); +Offset U32Leb128Length(uint32_t value); -void write_u32_leb128(Stream* stream, uint32_t value, const char* desc); +void WriteU32Leb128(Stream* stream, uint32_t value, const char* desc); -void write_i32_leb128(Stream* stream, int32_t value, const char* desc); +void WriteI32Leb128(Stream* stream, int32_t value, const char* desc); -void write_fixed_u32_leb128(Stream* stream, uint32_t value, const char* desc); +void WriteFixedU32Leb128(Stream* stream, uint32_t value, const char* desc); -Offset write_fixed_u32_leb128_at(Stream* stream, - Offset offset, - uint32_t value, - const char* desc); +Offset WriteFixedU32Leb128At(Stream* stream, + Offset offset, + uint32_t value, + const char* desc); -Offset write_fixed_u32_leb128_raw(uint8_t* data, uint8_t* end, uint32_t value); +Offset WriteFixedU32Leb128Raw(uint8_t* data, uint8_t* end, uint32_t value); -void write_type(Stream* stream, Type type); +void WriteType(Stream* stream, Type type); -void write_str(Stream* stream, - string_view s, - const char* desc, - PrintChars print_chars = PrintChars::No); +void WriteStr(Stream* stream, + string_view s, + const char* desc, + PrintChars print_chars = PrintChars::No); -void write_opcode(Stream* stream, Opcode opcode); +void WriteOpcode(Stream* stream, Opcode opcode); -void write_limits(Stream* stream, const Limits* limits); +void WriteLimits(Stream* stream, const Limits* limits); /* Convenience functions for writing enums as LEB128s. */ template <typename T> -void write_u32_leb128_enum(Stream* stream, T value, const char* desc) { - write_u32_leb128(stream, static_cast<uint32_t>(value), desc); +void WriteU32Leb128Enum(Stream* stream, T value, const char* desc) { + WriteU32Leb128(stream, static_cast<uint32_t>(value), desc); } template <typename T> -void write_i32_leb128_enum(Stream* stream, T value, const char* desc) { - write_i32_leb128(stream, static_cast<int32_t>(value), desc); +void WriteI32Leb128Enum(Stream* stream, T value, const char* desc) { + WriteI32Leb128(stream, static_cast<int32_t>(value), desc); } } // namespace wabt diff --git a/src/binary.h b/src/binary.h index 84b9447a..d784fff1 100644 --- a/src/binary.h +++ b/src/binary.h @@ -59,7 +59,7 @@ static const int kBinarySectionCount = WABT_ENUM_COUNT(BinarySection); extern const char* g_section_name[]; -static WABT_INLINE const char* get_section_name(BinarySection sec) { +static WABT_INLINE const char* GetSectionName(BinarySection sec) { assert(static_cast<int>(sec) < kBinarySectionCount); return g_section_name[static_cast<size_t>(sec)]; } diff --git a/src/common.cc b/src/common.cc index 73881cd8..2187c715 100644 --- a/src/common.cc +++ b/src/common.cc @@ -88,7 +88,7 @@ Result ReadFile(const char* filename, std::vector<uint8_t>* out_data) { return Result::Ok; } -void init_stdio() { +void InitStdio() { #if COMPILER_IS_MSVC int result = _setmode(_fileno(stdout), _O_BINARY); if (result == -1) diff --git a/src/common.h b/src/common.h index a057f0bc..58f7070e 100644 --- a/src/common.h +++ b/src/common.h @@ -132,7 +132,7 @@ inline bool Succeeded(Result result) { return result == Result::Ok; } inline bool Failed(Result result) { return result == Result::Error; } inline std::string WABT_PRINTF_FORMAT(1, 2) - string_printf(const char* format, ...) { + StringPrintf(const char* format, ...) { va_list args; va_list args_copy; va_start(args, format); @@ -254,13 +254,13 @@ enum class NameSectionSubsection { Result ReadFile(const char* filename, std::vector<uint8_t>* out_data); -void init_stdio(); +void InitStdio(); /* external kind */ extern const char* g_kind_name[]; -static WABT_INLINE const char* get_kind_name(ExternalKind kind) { +static WABT_INLINE const char* GetKindName(ExternalKind kind) { assert(static_cast<int>(kind) < kExternalKindCount); return g_kind_name[static_cast<size_t>(kind)]; } @@ -269,14 +269,14 @@ static WABT_INLINE const char* get_kind_name(ExternalKind kind) { extern const char* g_reloc_type_name[]; -static WABT_INLINE const char* get_reloc_type_name(RelocType reloc) { +static WABT_INLINE const char* GetRelocTypeName(RelocType reloc) { assert(static_cast<int>(reloc) < kRelocTypeCount); return g_reloc_type_name[static_cast<size_t>(reloc)]; } /* type */ -static WABT_INLINE const char* get_type_name(Type type) { +static WABT_INLINE const char* GetTypeName(Type type) { switch (type) { case Type::I32: return "i32"; diff --git a/src/emscripten-exported.json b/src/emscripten-exported.json index fff5e305..4e1e481f 100644 --- a/src/emscripten-exported.json +++ b/src/emscripten-exported.json @@ -11,7 +11,6 @@ "_wabt_destroy_write_module_result", "_wabt_generate_names_module", "_wabt_get_first_module", -"_wabt_new_error_handler_buffer", "_wabt_new_wast_buffer_lexer", "_wabt_output_buffer_get_data", "_wabt_output_buffer_get_size", diff --git a/src/emscripten-helpers.cc b/src/emscripten-helpers.cc index 5090528e..d1e53f5d 100644 --- a/src/emscripten-helpers.cc +++ b/src/emscripten-helpers.cc @@ -67,7 +67,7 @@ WabtParseWastResult* wabt_parse_wast(wabt::WastLexer* lexer, wabt::ErrorHandlerBuffer* error_handler) { WabtParseWastResult* result = new WabtParseWastResult(); wabt::Script* script = nullptr; - result->result = wabt::parse_wast(lexer, &script, error_handler); + result->result = wabt::ParseWast(lexer, &script, error_handler); result->script.reset(script); return result; } @@ -85,8 +85,8 @@ WabtReadBinaryResult* wabt_read_binary( wabt::Module* module = new wabt::Module(); // TODO(binji): Pass through from wabt_read_binary parameter. const char* filename = "<binary>"; - result->result = wabt::read_binary_ir(filename, data, size, &options, - error_handler, module); + result->result = + wabt::ReadBinaryIr(filename, data, size, &options, error_handler, module); result->module.reset(module); return result; } @@ -95,28 +95,28 @@ wabt::Result wabt_resolve_names_script( wabt::WastLexer* lexer, wabt::Script* script, wabt::ErrorHandlerBuffer* error_handler) { - return resolve_names_script(lexer, script, error_handler); + return ResolveNamesScript(lexer, script, error_handler); } wabt::Result wabt_resolve_names_module( wabt::WastLexer* lexer, wabt::Module* module, wabt::ErrorHandlerBuffer* error_handler) { - return resolve_names_module(lexer, module, error_handler); + return ResolveNamesModule(lexer, module, error_handler); } wabt::Result wabt_validate_script(wabt::WastLexer* lexer, wabt::Script* script, wabt::ErrorHandlerBuffer* error_handler) { - return validate_script(lexer, script, error_handler); + return ValidateScript(lexer, script, error_handler); } wabt::Result wabt_apply_names_module(wabt::Module* module) { - return apply_names(module); + return ApplyNames(module); } wabt::Result wabt_generate_names_module(wabt::Module* module) { - return generate_names(module); + return GenerateNames(module); } wabt::Module* wabt_get_first_module(wabt::Script* script) { @@ -137,7 +137,7 @@ WabtWriteModuleResult* wabt_write_binary_module(wabt::Module* module, wabt::MemoryWriter writer; WabtWriteModuleResult* result = new WabtWriteModuleResult(); - result->result = write_binary_module(&writer, module, &options); + result->result = WriteBinaryModule(&writer, module, &options); if (result->result == wabt::Result::Ok) { result->buffer = writer.ReleaseOutputBuffer(); result->log_buffer = log ? stream.ReleaseOutputBuffer() : nullptr; @@ -155,7 +155,7 @@ WabtWriteModuleResult* wabt_write_text_module(wabt::Module* module, wabt::MemoryWriter writer; WabtWriteModuleResult* result = new WabtWriteModuleResult(); - result->result = write_wat(&writer, module, &options); + result->result = WriteWat(&writer, module, &options); if (result->result == wabt::Result::Ok) { result->buffer = writer.ReleaseOutputBuffer(); } diff --git a/src/error-handler.cc b/src/error-handler.cc index d6328870..86d42b9a 100644 --- a/src/error-handler.cc +++ b/src/error-handler.cc @@ -40,9 +40,9 @@ std::string ErrorHandler::DefaultErrorMessage(const Color& color, } if (location_type_ == Location::Type::Text) { - result += string_printf("%d:%d: ", loc.line, loc.first_column); + result += StringPrintf("%d:%d: ", loc.line, loc.first_column); } else if (loc.offset != kInvalidOffset) { - result += string_printf("%07" PRIzx ": ", loc.offset); + result += StringPrintf("%07" PRIzx ": ", loc.offset); } result += color.MaybeRedCode(); diff --git a/src/generate-names.cc b/src/generate-names.cc index 112e2d16..c495e565 100644 --- a/src/generate-names.cc +++ b/src/generate-names.cc @@ -215,7 +215,7 @@ Result NameGenerator::VisitModule(Module* module) { } // end anonymous namespace -Result generate_names(Module* module) { +Result GenerateNames(Module* module) { NameGenerator generator; return generator.VisitModule(module); } diff --git a/src/generate-names.h b/src/generate-names.h index e2013c07..9a956284 100644 --- a/src/generate-names.h +++ b/src/generate-names.h @@ -23,7 +23,7 @@ namespace wabt { struct Module; -Result generate_names(struct Module*); +Result GenerateNames(struct Module*); } // namespace wabt diff --git a/src/hash-util.cc b/src/hash-util.cc index c0c55a21..ab22bd05 100644 --- a/src/hash-util.cc +++ b/src/hash-util.cc @@ -23,7 +23,7 @@ namespace wabt { // Hash combiner from: // http://stackoverflow.com/questions/4948780/magic-number-in-boosthash-combine -hash_code hash_combine(hash_code seed, hash_code y) { +hash_code HashCombine(hash_code seed, hash_code y) { #if SIZEOF_SIZE_T == 4 constexpr hash_code magic = 0x9e3779b9; #elif SIZEOF_SIZE_T == 8 diff --git a/src/hash-util.h b/src/hash-util.h index 0cf68758..21d96562 100644 --- a/src/hash-util.h +++ b/src/hash-util.h @@ -24,20 +24,20 @@ namespace wabt { typedef std::size_t hash_code; -inline hash_code hash_combine() { return 0; } -inline hash_code hash_combine(hash_code seed) { return seed; } -hash_code hash_combine(hash_code x, hash_code y); +inline hash_code HashCombine() { return 0; } +inline hash_code HashCombine(hash_code seed) { return seed; } +hash_code HashCombine(hash_code x, hash_code y); template <typename T, typename... U> -inline hash_code hash_combine(const T& first, const U&... rest) { - return hash_combine(hash_combine(rest...), std::hash<T>()(first)); +inline hash_code HashCombine(const T& first, const U&... rest) { + return HashCombine(HashCombine(rest...), std::hash<T>()(first)); } template <typename It> -inline hash_code hash_range(It first, It last) { +inline hash_code HashRange(It first, It last) { hash_code result = 0; for (auto iter = first; iter != last; ++iter) { - result = hash_combine(result, *iter); + result = HashCombine(result, *iter); } return result; } diff --git a/src/literal.cc b/src/literal.cc index 50ec443d..5df09b29 100644 --- a/src/literal.cc +++ b/src/literal.cc @@ -214,7 +214,7 @@ Result FloatParser<T>::ParseNan(const char* s, for (; s < end; ++s) { uint32_t digit; - if (Failed(parse_hexdigit(*s, &digit))) + if (Failed(ParseHexdigit(*s, &digit))) return Result::Error; tag = tag * 16 + digit; // Check for overflow. @@ -262,7 +262,7 @@ Result FloatParser<T>::ParseHex(const char* s, uint32_t digit; if (*s == '.') { seen_dot = true; - } else if (Succeeded(parse_hexdigit(*s, &digit))) { + } else if (Succeeded(ParseHexdigit(*s, &digit))) { if (Traits::kBits - Clz(significand) <= Traits::kSigPlusOneBits) { significand = (significand << 4) + digit; if (seen_dot) @@ -510,7 +510,7 @@ void FloatWriter<T>::WriteHex(char* out, size_t size, Uint bits) { } // end anonymous namespace -Result parse_hexdigit(char c, uint32_t* out) { +Result ParseHexdigit(char c, uint32_t* out) { if (static_cast<unsigned int>(c - '0') <= 9) { *out = c - '0'; return Result::Ok; @@ -524,7 +524,7 @@ Result parse_hexdigit(char c, uint32_t* out) { return Result::Error; } -Result parse_uint64(const char* s, const char* end, uint64_t* out) { +Result ParseUint64(const char* s, const char* end, uint64_t* out) { if (s == end) return Result::Error; uint64_t value = 0; @@ -534,7 +534,7 @@ Result parse_uint64(const char* s, const char* end, uint64_t* out) { return Result::Error; for (; s < end; ++s) { uint32_t digit; - if (Failed(parse_hexdigit(*s, &digit))) + if (Failed(ParseHexdigit(*s, &digit))) return Result::Error; uint64_t old_value = value; value = value * 16 + digit; @@ -560,10 +560,10 @@ Result parse_uint64(const char* s, const char* end, uint64_t* out) { return Result::Ok; } -Result parse_int64(const char* s, - const char* end, - uint64_t* out, - ParseIntType parse_type) { +Result ParseInt64(const char* s, + const char* end, + uint64_t* out, + ParseIntType parse_type) { bool has_sign = false; if (*s == '-' || *s == '+') { if (parse_type == ParseIntType::UnsignedOnly) @@ -573,7 +573,7 @@ Result parse_int64(const char* s, s++; } uint64_t value = 0; - Result result = parse_uint64(s, end, &value); + Result result = ParseUint64(s, end, &value); if (has_sign) { // abs(INT64_MIN) == INT64_MAX + 1. if (value > static_cast<uint64_t>(INT64_MAX) + 1) @@ -584,10 +584,10 @@ Result parse_int64(const char* s, return result; } -Result parse_int32(const char* s, - const char* end, - uint32_t* out, - ParseIntType parse_type) { +Result ParseInt32(const char* s, + const char* end, + uint32_t* out, + ParseIntType parse_type) { uint64_t value; bool has_sign = false; if (*s == '-' || *s == '+') { @@ -597,7 +597,7 @@ Result parse_int32(const char* s, has_sign = true; s++; } - if (Failed(parse_uint64(s, end, &value))) + if (Failed(ParseUint64(s, end, &value))) return Result::Error; if (has_sign) { @@ -613,26 +613,25 @@ Result parse_int32(const char* s, return Result::Ok; } - -Result parse_float(LiteralType literal_type, - const char* s, - const char* end, - uint32_t* out_bits) { +Result ParseFloat(LiteralType literal_type, + const char* s, + const char* end, + uint32_t* out_bits) { return FloatParser<float>::Parse(literal_type, s, end, out_bits); } -Result parse_double(LiteralType literal_type, - const char* s, - const char* end, - uint64_t* out_bits) { +Result ParseDouble(LiteralType literal_type, + const char* s, + const char* end, + uint64_t* out_bits) { return FloatParser<double>::Parse(literal_type, s, end, out_bits); } -void write_float_hex(char* buffer, size_t size, uint32_t bits) { +void WriteFloatHex(char* buffer, size_t size, uint32_t bits) { return FloatWriter<float>::WriteHex(buffer, size, bits); } -void write_double_hex(char* buffer, size_t size, uint64_t bits) { +void WriteDoubleHex(char* buffer, size_t size, uint64_t bits) { return FloatWriter<double>::WriteHex(buffer, size, bits); } diff --git a/src/literal.h b/src/literal.h index 42c369a8..f100d080 100644 --- a/src/literal.h +++ b/src/literal.h @@ -47,27 +47,27 @@ enum class ParseIntType { #define WABT_MAX_FLOAT_HEX 20 #define WABT_MAX_DOUBLE_HEX 40 -Result parse_hexdigit(char c, uint32_t* out); -Result parse_int32(const char* s, - const char* end, - uint32_t* out, - ParseIntType parse_type); -Result parse_int64(const char* s, - const char* end, - uint64_t* out, - ParseIntType parse_type); -Result parse_uint64(const char* s, const char* end, uint64_t* out); -Result parse_float(LiteralType literal_type, +Result ParseHexdigit(char c, uint32_t* out); +Result ParseInt32(const char* s, + const char* end, + uint32_t* out, + ParseIntType parse_type); +Result ParseInt64(const char* s, + const char* end, + uint64_t* out, + ParseIntType parse_type); +Result ParseUint64(const char* s, const char* end, uint64_t* out); +Result ParseFloat(LiteralType literal_type, + const char* s, + const char* end, + uint32_t* out_bits); +Result ParseDouble(LiteralType literal_type, const char* s, const char* end, - uint32_t* out_bits); -Result parse_double(LiteralType literal_type, - const char* s, - const char* end, - uint64_t* out_bits); + uint64_t* out_bits); -void write_float_hex(char* buffer, size_t size, uint32_t bits); -void write_double_hex(char* buffer, size_t size, uint64_t bits); +void WriteFloatHex(char* buffer, size_t size, uint32_t bits); +void WriteDoubleHex(char* buffer, size_t size, uint64_t bits); } // namespace wabt diff --git a/src/prebuilt/wast-lexer-gen.cc b/src/prebuilt/wast-lexer-gen.cc index 87786901..85bbb427 100644 --- a/src/prebuilt/wast-lexer-gen.cc +++ b/src/prebuilt/wast-lexer-gen.cc @@ -56,7 +56,7 @@ #define ERROR(...) \ SetLocation(loc); \ - wast_parser_error(loc, this, parser, __VA_ARGS__) + WastParserError(loc, this, parser, __VA_ARGS__) #define BEGIN(c) cond = (c) #define FILL(n) \ diff --git a/src/prebuilt/wast-parser-gen.cc b/src/prebuilt/wast-parser-gen.cc index 5b9bd880..f268dc60 100644 --- a/src/prebuilt/wast-parser-gen.cc +++ b/src/prebuilt/wast-parser-gen.cc @@ -133,28 +133,28 @@ } \ while (0) -#define CHECK_END_LABEL(loc, begin_label, end_label) \ - do { \ - if (!end_label->empty()) { \ - if (begin_label.empty()) { \ - wast_parser_error(&loc, lexer, parser, "unexpected label \"%s\"", \ - end_label->c_str()); \ - } else if (begin_label != *end_label) { \ - wast_parser_error(&loc, lexer, parser, \ - "mismatching label \"%s\" != \"%s\"", \ - begin_label.c_str(), end_label->c_str()); \ - } \ - } \ - delete (end_label); \ +#define CHECK_END_LABEL(loc, begin_label, end_label) \ + do { \ + if (!end_label->empty()) { \ + if (begin_label.empty()) { \ + WastParserError(&loc, lexer, parser, "unexpected label \"%s\"", \ + end_label->c_str()); \ + } else if (begin_label != *end_label) { \ + WastParserError(&loc, lexer, parser, \ + "mismatching label \"%s\" != \"%s\"", \ + begin_label.c_str(), end_label->c_str()); \ + } \ + } \ + delete (end_label); \ } while (0) -#define CHECK_ALLOW_EXCEPTIONS(loc, opcode_name) \ - do { \ - if (!parser->options->allow_future_exceptions) { \ - wast_parser_error(loc, lexer, parser, "opcode not allowed: %s", \ - opcode_name); \ - } \ - } while (0) +#define CHECK_ALLOW_EXCEPTIONS(loc, opcode_name) \ + do { \ + if (!parser->options->allow_future_exceptions) { \ + WastParserError(loc, lexer, parser, "opcode not allowed: %s", \ + opcode_name); \ + } \ + } while (0) #define YYMALLOC(size) new char [size] #define YYFREE(p) delete [] (p) @@ -236,8 +236,8 @@ void RemoveEscapes(string_view text, OutputIter dest) { // sequence. uint32_t hi; uint32_t lo; - if (Succeeded(parse_hexdigit(src[0], &hi)) && - Succeeded(parse_hexdigit(src[1], &lo))) { + if (Succeeded(ParseHexdigit(src[0], &hi)) && + Succeeded(ParseHexdigit(src[1], &lo))) { *dest++ = (hi << 4) | lo; } else { assert(0); @@ -279,7 +279,7 @@ void AppendAndDelete(T& dest, U* source) { } #define wabt_wast_parser_lex(...) lexer->GetToken(__VA_ARGS__, parser) -#define wabt_wast_parser_error wast_parser_error +#define wabt_wast_parser_error WastParserError #line 286 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:339 */ @@ -746,26 +746,26 @@ static const yytype_uint16 yyrline[] = { 0, 331, 331, 335, 341, 342, 346, 355, 356, 362, 365, 370, 378, 382, 383, 387, 396, 397, 404, 410, - 416, 421, 428, 434, 445, 448, 451, 457, 460, 465, - 466, 472, 473, 476, 480, 481, 485, 486, 503, 504, - 520, 524, 528, 532, 535, 538, 541, 544, 547, 550, - 553, 556, 559, 562, 565, 568, 571, 574, 577, 580, - 583, 593, 596, 599, 602, 605, 608, 611, 614, 620, - 626, 632, 638, 645, 654, 657, 661, 667, 673, 680, - 681, 685, 690, 697, 701, 706, 712, 718, 723, 732, - 737, 746, 749, 755, 760, 768, 774, 777, 782, 787, - 793, 799, 805, 814, 819, 825, 831, 832, 838, 839, - 845, 850, 855, 862, 876, 882, 885, 893, 899, 908, - 915, 916, 920, 929, 930, 937, 944, 945, 949, 958, - 959, 966, 973, 977, 981, 992, 995, 999, 1006, 1016, - 1030, 1033, 1039, 1045, 1064, 1071, 1081, 1095, 1098, 1104, - 1110, 1132, 1146, 1151, 1157, 1168, 1176, 1183, 1189, 1195, - 1201, 1209, 1218, 1226, 1231, 1236, 1241, 1246, 1253, 1261, - 1271, 1276, 1285, 1291, 1292, 1293, 1294, 1295, 1296, 1297, - 1298, 1299, 1300, 1301, 1305, 1306, 1310, 1315, 1323, 1343, - 1350, 1353, 1359, 1376, 1382, 1391, 1400, 1410, 1413, 1416, - 1419, 1422, 1425, 1428, 1431, 1434, 1440, 1443, 1444, 1447, - 1454, 1458, 1465, 1475, 1476, 1483, 1486, 1548, 1557 + 416, 421, 428, 434, 444, 447, 450, 456, 459, 464, + 465, 471, 472, 475, 479, 480, 484, 485, 502, 503, + 519, 523, 527, 531, 534, 537, 540, 543, 546, 549, + 552, 555, 558, 561, 564, 567, 570, 573, 576, 579, + 582, 592, 595, 598, 601, 604, 607, 610, 613, 619, + 625, 631, 637, 644, 653, 656, 660, 666, 672, 679, + 680, 684, 689, 696, 700, 705, 711, 717, 722, 731, + 736, 745, 748, 754, 759, 767, 773, 776, 781, 786, + 792, 798, 804, 813, 818, 824, 830, 831, 837, 838, + 844, 849, 854, 861, 875, 881, 884, 892, 898, 907, + 914, 915, 919, 928, 929, 936, 943, 944, 948, 957, + 958, 965, 972, 976, 980, 991, 994, 998, 1005, 1015, + 1029, 1032, 1038, 1044, 1063, 1070, 1080, 1094, 1097, 1103, + 1109, 1131, 1145, 1150, 1156, 1167, 1175, 1182, 1188, 1194, + 1200, 1208, 1217, 1225, 1230, 1235, 1240, 1245, 1252, 1260, + 1270, 1275, 1284, 1290, 1291, 1292, 1293, 1294, 1295, 1296, + 1297, 1298, 1299, 1300, 1304, 1305, 1309, 1314, 1322, 1342, + 1349, 1352, 1358, 1375, 1381, 1390, 1399, 1409, 1412, 1415, + 1418, 1421, 1424, 1427, 1430, 1433, 1439, 1442, 1443, 1446, + 1453, 1457, 1464, 1474, 1475, 1482, 1485, 1547, 1556 }; #endif @@ -2612,406 +2612,405 @@ yyreduce: #line 434 "src/wast-parser.y" /* yacc.c:1646 */ { string_view sv = (yyvsp[0].t_literal).text.to_string_view(); - if (Failed(parse_uint64(sv.begin(), sv.end(), &(yyval.u64)))) { - wast_parser_error(&(yylsp[0]), lexer, parser, - "invalid int \"" PRIstringview "\"", - WABT_PRINTF_STRING_VIEW_ARG(sv)); + if (Failed(ParseUint64(sv.begin(), sv.end(), &(yyval.u64)))) { + WastParserError(&(yylsp[0]), lexer, parser, "invalid int \"" PRIstringview "\"", + WABT_PRINTF_STRING_VIEW_ARG(sv)); } } -#line 2622 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2621 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 24: -#line 445 "src/wast-parser.y" /* yacc.c:1646 */ +#line 444 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.literal) = new Literal((yyvsp[0].t_literal)); } -#line 2630 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2629 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 25: -#line 448 "src/wast-parser.y" /* yacc.c:1646 */ +#line 447 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.literal) = new Literal((yyvsp[0].t_literal)); } -#line 2638 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2637 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 26: -#line 451 "src/wast-parser.y" /* yacc.c:1646 */ +#line 450 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.literal) = new Literal((yyvsp[0].t_literal)); } -#line 2646 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2645 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 27: -#line 457 "src/wast-parser.y" /* yacc.c:1646 */ +#line 456 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.var) = new Var((yyvsp[0].u64), (yylsp[0])); } -#line 2654 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2653 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 28: -#line 460 "src/wast-parser.y" /* yacc.c:1646 */ +#line 459 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.var) = new Var((yyvsp[0].t_text).to_string_view(), (yylsp[0])); } -#line 2662 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2661 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 29: -#line 465 "src/wast-parser.y" /* yacc.c:1646 */ +#line 464 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.vars) = new VarVector(); } -#line 2668 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2667 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 30: -#line 466 "src/wast-parser.y" /* yacc.c:1646 */ +#line 465 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.vars) = (yyvsp[-1].vars); (yyval.vars)->emplace_back(MoveAndDelete((yyvsp[0].var))); } -#line 2677 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2676 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 31: -#line 472 "src/wast-parser.y" /* yacc.c:1646 */ +#line 471 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.string) = new std::string(); } -#line 2683 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2682 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 33: -#line 476 "src/wast-parser.y" /* yacc.c:1646 */ +#line 475 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.string) = new std::string((yyvsp[0].t_text).to_string()); } -#line 2689 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2688 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 34: -#line 480 "src/wast-parser.y" /* yacc.c:1646 */ +#line 479 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.string) = new std::string(); } -#line 2695 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2694 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 36: -#line 485 "src/wast-parser.y" /* yacc.c:1646 */ +#line 484 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.u64) = 0; } -#line 2701 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2700 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 37: -#line 486 "src/wast-parser.y" /* yacc.c:1646 */ +#line 485 "src/wast-parser.y" /* yacc.c:1646 */ { uint64_t offset64; string_view sv = (yyvsp[0].t_text).to_string_view(); - if (Failed(parse_int64(sv.begin(), sv.end(), &offset64, - ParseIntType::SignedAndUnsigned))) { - wast_parser_error(&(yylsp[0]), lexer, parser, - "invalid offset \"" PRIstringview "\"", - WABT_PRINTF_STRING_VIEW_ARG(sv)); + if (Failed(ParseInt64(sv.begin(), sv.end(), &offset64, + ParseIntType::SignedAndUnsigned))) { + WastParserError(&(yylsp[0]), lexer, parser, + "invalid offset \"" PRIstringview "\"", + WABT_PRINTF_STRING_VIEW_ARG(sv)); } if (offset64 > UINT32_MAX) { - wast_parser_error(&(yylsp[0]), lexer, parser, - "offset must be less than or equal to 0xffffffff"); + WastParserError(&(yylsp[0]), lexer, parser, + "offset must be less than or equal to 0xffffffff"); } (yyval.u64) = static_cast<uint32_t>(offset64); } -#line 2721 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2720 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 38: -#line 503 "src/wast-parser.y" /* yacc.c:1646 */ +#line 502 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.u32) = USE_NATURAL_ALIGNMENT; } -#line 2727 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2726 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 39: -#line 504 "src/wast-parser.y" /* yacc.c:1646 */ +#line 503 "src/wast-parser.y" /* yacc.c:1646 */ { string_view sv = (yyvsp[0].t_text).to_string_view(); - if (Failed(parse_int32(sv.begin(), sv.end(), &(yyval.u32), - ParseIntType::UnsignedOnly))) { - wast_parser_error(&(yylsp[0]), lexer, parser, - "invalid alignment \"" PRIstringview "\"", - WABT_PRINTF_STRING_VIEW_ARG(sv)); + if (Failed(ParseInt32(sv.begin(), sv.end(), &(yyval.u32), + ParseIntType::UnsignedOnly))) { + WastParserError(&(yylsp[0]), lexer, parser, + "invalid alignment \"" PRIstringview "\"", + WABT_PRINTF_STRING_VIEW_ARG(sv)); } if ((yyval.u32) != WABT_USE_NATURAL_ALIGNMENT && !IsPowerOfTwo((yyval.u32))) { - wast_parser_error(&(yylsp[0]), lexer, parser, "alignment must be power-of-two"); + WastParserError(&(yylsp[0]), lexer, parser, "alignment must be power-of-two"); } } -#line 2745 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2744 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 40: -#line 520 "src/wast-parser.y" /* yacc.c:1646 */ +#line 519 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.expr_list) = new ExprList((yyvsp[0].expr)); (yyval.expr_list)->back().loc = (yylsp[0]); } -#line 2754 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2753 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 41: -#line 524 "src/wast-parser.y" /* yacc.c:1646 */ +#line 523 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.expr_list) = new ExprList((yyvsp[0].expr)); (yyval.expr_list)->back().loc = (yylsp[0]); } -#line 2763 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2762 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 43: -#line 532 "src/wast-parser.y" /* yacc.c:1646 */ +#line 531 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = new UnreachableExpr(); } -#line 2771 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2770 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 44: -#line 535 "src/wast-parser.y" /* yacc.c:1646 */ +#line 534 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = new NopExpr(); } -#line 2779 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2778 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 45: -#line 538 "src/wast-parser.y" /* yacc.c:1646 */ +#line 537 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = new DropExpr(); } -#line 2787 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2786 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 46: -#line 541 "src/wast-parser.y" /* yacc.c:1646 */ +#line 540 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = new SelectExpr(); } -#line 2795 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2794 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 47: -#line 544 "src/wast-parser.y" /* yacc.c:1646 */ +#line 543 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = new BrExpr(MoveAndDelete((yyvsp[0].var))); } -#line 2803 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2802 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 48: -#line 547 "src/wast-parser.y" /* yacc.c:1646 */ +#line 546 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = new BrIfExpr(MoveAndDelete((yyvsp[0].var))); } -#line 2811 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2810 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 49: -#line 550 "src/wast-parser.y" /* yacc.c:1646 */ +#line 549 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = new BrTableExpr((yyvsp[-1].vars), MoveAndDelete((yyvsp[0].var))); } -#line 2819 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2818 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 50: -#line 553 "src/wast-parser.y" /* yacc.c:1646 */ +#line 552 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = new ReturnExpr(); } -#line 2827 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2826 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 51: -#line 556 "src/wast-parser.y" /* yacc.c:1646 */ +#line 555 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = new CallExpr(MoveAndDelete((yyvsp[0].var))); } -#line 2835 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2834 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 52: -#line 559 "src/wast-parser.y" /* yacc.c:1646 */ +#line 558 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = new CallIndirectExpr(MoveAndDelete((yyvsp[0].var))); } -#line 2843 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2842 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 53: -#line 562 "src/wast-parser.y" /* yacc.c:1646 */ +#line 561 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = new GetLocalExpr(MoveAndDelete((yyvsp[0].var))); } -#line 2851 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2850 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 54: -#line 565 "src/wast-parser.y" /* yacc.c:1646 */ +#line 564 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = new SetLocalExpr(MoveAndDelete((yyvsp[0].var))); } -#line 2859 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2858 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 55: -#line 568 "src/wast-parser.y" /* yacc.c:1646 */ +#line 567 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = new TeeLocalExpr(MoveAndDelete((yyvsp[0].var))); } -#line 2867 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2866 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 56: -#line 571 "src/wast-parser.y" /* yacc.c:1646 */ +#line 570 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = new GetGlobalExpr(MoveAndDelete((yyvsp[0].var))); } -#line 2875 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2874 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 57: -#line 574 "src/wast-parser.y" /* yacc.c:1646 */ +#line 573 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = new SetGlobalExpr(MoveAndDelete((yyvsp[0].var))); } -#line 2883 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2882 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 58: -#line 577 "src/wast-parser.y" /* yacc.c:1646 */ +#line 576 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = new LoadExpr((yyvsp[-2].t_opcode), (yyvsp[0].u32), (yyvsp[-1].u64)); } -#line 2891 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2890 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 59: -#line 580 "src/wast-parser.y" /* yacc.c:1646 */ +#line 579 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = new StoreExpr((yyvsp[-2].t_opcode), (yyvsp[0].u32), (yyvsp[-1].u64)); } -#line 2899 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2898 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 60: -#line 583 "src/wast-parser.y" /* yacc.c:1646 */ +#line 582 "src/wast-parser.y" /* yacc.c:1646 */ { Const const_; const_.loc = (yylsp[-1]); auto literal = MoveAndDelete((yyvsp[0].literal)); if (Failed(ParseConst((yyvsp[-1].t_type), literal, &const_))) { - wast_parser_error(&(yylsp[0]), lexer, parser, "invalid literal \"%s\"", - literal.text.c_str()); + WastParserError(&(yylsp[0]), lexer, parser, "invalid literal \"%s\"", + literal.text.c_str()); } (yyval.expr) = new ConstExpr(const_); } -#line 2914 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2913 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 61: -#line 593 "src/wast-parser.y" /* yacc.c:1646 */ +#line 592 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = new UnaryExpr((yyvsp[0].t_opcode)); } -#line 2922 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2921 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 62: -#line 596 "src/wast-parser.y" /* yacc.c:1646 */ +#line 595 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = new BinaryExpr((yyvsp[0].t_opcode)); } -#line 2930 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2929 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 63: -#line 599 "src/wast-parser.y" /* yacc.c:1646 */ +#line 598 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = new CompareExpr((yyvsp[0].t_opcode)); } -#line 2938 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2937 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 64: -#line 602 "src/wast-parser.y" /* yacc.c:1646 */ +#line 601 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = new ConvertExpr((yyvsp[0].t_opcode)); } -#line 2946 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2945 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 65: -#line 605 "src/wast-parser.y" /* yacc.c:1646 */ +#line 604 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = new CurrentMemoryExpr(); } -#line 2954 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2953 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 66: -#line 608 "src/wast-parser.y" /* yacc.c:1646 */ +#line 607 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = new GrowMemoryExpr(); } -#line 2962 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2961 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 67: -#line 611 "src/wast-parser.y" /* yacc.c:1646 */ +#line 610 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = new ThrowExpr(MoveAndDelete((yyvsp[0].var))); } -#line 2970 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2969 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 68: -#line 614 "src/wast-parser.y" /* yacc.c:1646 */ +#line 613 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = new RethrowExpr(MoveAndDelete((yyvsp[0].var))); } -#line 2978 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2977 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 69: -#line 620 "src/wast-parser.y" /* yacc.c:1646 */ +#line 619 "src/wast-parser.y" /* yacc.c:1646 */ { auto expr = new BlockExpr((yyvsp[-2].block)); expr->block->label = MoveAndDelete((yyvsp[-3].string)); CHECK_END_LABEL((yylsp[0]), expr->block->label, (yyvsp[0].string)); (yyval.expr) = expr; } -#line 2989 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2988 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 70: -#line 626 "src/wast-parser.y" /* yacc.c:1646 */ +#line 625 "src/wast-parser.y" /* yacc.c:1646 */ { auto expr = new LoopExpr((yyvsp[-2].block)); expr->block->label = MoveAndDelete((yyvsp[-3].string)); CHECK_END_LABEL((yylsp[0]), expr->block->label, (yyvsp[0].string)); (yyval.expr) = expr; } -#line 3000 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 2999 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 71: -#line 632 "src/wast-parser.y" /* yacc.c:1646 */ +#line 631 "src/wast-parser.y" /* yacc.c:1646 */ { auto expr = new IfExpr((yyvsp[-2].block)); expr->true_->label = MoveAndDelete((yyvsp[-3].string)); CHECK_END_LABEL((yylsp[0]), expr->true_->label, (yyvsp[0].string)); (yyval.expr) = expr; } -#line 3011 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3010 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 72: -#line 638 "src/wast-parser.y" /* yacc.c:1646 */ +#line 637 "src/wast-parser.y" /* yacc.c:1646 */ { auto expr = new IfExpr((yyvsp[-5].block), MoveAndDelete((yyvsp[-2].expr_list))); expr->true_->label = MoveAndDelete((yyvsp[-6].string)); @@ -3019,342 +3018,342 @@ yyreduce: CHECK_END_LABEL((yylsp[0]), expr->true_->label, (yyvsp[0].string)); (yyval.expr) = expr; } -#line 3023 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3022 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 73: -#line 645 "src/wast-parser.y" /* yacc.c:1646 */ +#line 644 "src/wast-parser.y" /* yacc.c:1646 */ { (yyvsp[-3].block)->label = MoveAndDelete((yyvsp[-4].string)); (yyval.expr) = (yyvsp[-2].try_expr); cast<TryExpr>((yyval.expr))->block = (yyvsp[-3].block); CHECK_END_LABEL((yylsp[0]), (yyvsp[-3].block)->label, (yyvsp[0].string)); } -#line 3034 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3033 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 74: -#line 654 "src/wast-parser.y" /* yacc.c:1646 */ +#line 653 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.types) = (yyvsp[-1].types); } -#line 3040 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3039 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 75: -#line 657 "src/wast-parser.y" /* yacc.c:1646 */ +#line 656 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.block) = (yyvsp[0].block); AppendAndDelete((yyval.block)->sig, (yyvsp[-1].types)); } -#line 3049 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3048 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 76: -#line 661 "src/wast-parser.y" /* yacc.c:1646 */ +#line 660 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.block) = new Block(MoveAndDelete((yyvsp[0].expr_list))); } -#line 3057 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3056 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 77: -#line 667 "src/wast-parser.y" /* yacc.c:1646 */ +#line 666 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.catch_) = new Catch(MoveAndDelete((yyvsp[-1].var)), MoveAndDelete((yyvsp[0].expr_list))); (yyval.catch_)->loc = (yylsp[-2]); } -#line 3066 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3065 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 78: -#line 673 "src/wast-parser.y" /* yacc.c:1646 */ +#line 672 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.catch_) = new Catch(MoveAndDelete((yyvsp[0].expr_list))); (yyval.catch_)->loc = (yylsp[-1]); } -#line 3075 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3074 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 81: -#line 685 "src/wast-parser.y" /* yacc.c:1646 */ +#line 684 "src/wast-parser.y" /* yacc.c:1646 */ { auto expr = new TryExpr(); expr->catches.push_back((yyvsp[0].catch_)); (yyval.try_expr) = expr; } -#line 3085 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3084 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 82: -#line 690 "src/wast-parser.y" /* yacc.c:1646 */ +#line 689 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.try_expr) = (yyvsp[-1].try_expr); cast<TryExpr>((yyval.try_expr))->catches.push_back((yyvsp[0].catch_)); } -#line 3094 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3093 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 83: -#line 697 "src/wast-parser.y" /* yacc.c:1646 */ +#line 696 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.expr_list) = (yyvsp[-1].expr_list); } -#line 3100 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3099 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 84: -#line 701 "src/wast-parser.y" /* yacc.c:1646 */ +#line 700 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.expr_list) = (yyvsp[0].expr_list); (yyval.expr_list)->push_back((yyvsp[-1].expr)); (yyvsp[-1].expr)->loc = (yylsp[-1]); } -#line 3110 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3109 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 85: -#line 706 "src/wast-parser.y" /* yacc.c:1646 */ +#line 705 "src/wast-parser.y" /* yacc.c:1646 */ { auto expr = new BlockExpr((yyvsp[0].block)); expr->block->label = MoveAndDelete((yyvsp[-1].string)); expr->loc = (yylsp[-2]); (yyval.expr_list) = new ExprList(expr); } -#line 3121 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3120 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 86: -#line 712 "src/wast-parser.y" /* yacc.c:1646 */ +#line 711 "src/wast-parser.y" /* yacc.c:1646 */ { auto expr = new LoopExpr((yyvsp[0].block)); expr->block->label = MoveAndDelete((yyvsp[-1].string)); expr->loc = (yylsp[-2]); (yyval.expr_list) = new ExprList(expr); } -#line 3132 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3131 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 87: -#line 718 "src/wast-parser.y" /* yacc.c:1646 */ +#line 717 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.expr_list) = (yyvsp[0].expr_list); IfExpr* if_ = cast<IfExpr>(&(yyvsp[0].expr_list)->back()); if_->true_->label = MoveAndDelete((yyvsp[-1].string)); } -#line 3142 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3141 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 88: -#line 723 "src/wast-parser.y" /* yacc.c:1646 */ +#line 722 "src/wast-parser.y" /* yacc.c:1646 */ { Block* block = (yyvsp[0].try_expr)->block; block->label = MoveAndDelete((yyvsp[-1].string)); (yyvsp[0].try_expr)->loc = (yylsp[-2]); (yyval.expr_list) = new ExprList((yyvsp[0].try_expr)); } -#line 3153 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3152 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 89: -#line 732 "src/wast-parser.y" /* yacc.c:1646 */ +#line 731 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.try_expr) = (yyvsp[0].try_expr); Block* block = (yyval.try_expr)->block; AppendAndDelete(block->sig, (yyvsp[-1].types)); } -#line 3163 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3162 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 90: -#line 737 "src/wast-parser.y" /* yacc.c:1646 */ +#line 736 "src/wast-parser.y" /* yacc.c:1646 */ { Block* block = new Block(); block->exprs = MoveAndDelete((yyvsp[-1].expr_list)); (yyval.try_expr) = (yyvsp[0].try_expr); (yyval.try_expr)->block = block; } -#line 3174 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3173 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 91: -#line 746 "src/wast-parser.y" /* yacc.c:1646 */ +#line 745 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.catch_) = (yyvsp[-1].catch_); } -#line 3182 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3181 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 92: -#line 749 "src/wast-parser.y" /* yacc.c:1646 */ +#line 748 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.catch_) = (yyvsp[-1].catch_); } -#line 3190 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3189 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 93: -#line 755 "src/wast-parser.y" /* yacc.c:1646 */ +#line 754 "src/wast-parser.y" /* yacc.c:1646 */ { auto expr = new TryExpr(); expr->catches.push_back((yyvsp[0].catch_)); (yyval.try_expr) = expr; } -#line 3200 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3199 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 94: -#line 760 "src/wast-parser.y" /* yacc.c:1646 */ +#line 759 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.try_expr) = (yyvsp[-1].try_expr); cast<TryExpr>((yyval.try_expr))->catches.push_back((yyvsp[0].catch_)); } -#line 3209 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3208 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 95: -#line 768 "src/wast-parser.y" /* yacc.c:1646 */ +#line 767 "src/wast-parser.y" /* yacc.c:1646 */ { IfExpr* if_ = cast<IfExpr>(&(yyvsp[0].expr_list)->back()); (yyval.expr_list) = (yyvsp[0].expr_list); Block* true_ = if_->true_; AppendAndDelete(true_->sig, (yyvsp[-1].types)); } -#line 3220 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3219 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 97: -#line 777 "src/wast-parser.y" /* yacc.c:1646 */ +#line 776 "src/wast-parser.y" /* yacc.c:1646 */ { Expr* expr = new IfExpr(new Block(MoveAndDelete((yyvsp[-5].expr_list))), MoveAndDelete((yyvsp[-1].expr_list))); expr->loc = (yylsp[-7]); (yyval.expr_list) = new ExprList(expr); } -#line 3230 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3229 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 98: -#line 782 "src/wast-parser.y" /* yacc.c:1646 */ +#line 781 "src/wast-parser.y" /* yacc.c:1646 */ { Expr* expr = new IfExpr(new Block(MoveAndDelete((yyvsp[-1].expr_list)))); expr->loc = (yylsp[-3]); (yyval.expr_list) = new ExprList(expr); } -#line 3240 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3239 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 99: -#line 787 "src/wast-parser.y" /* yacc.c:1646 */ +#line 786 "src/wast-parser.y" /* yacc.c:1646 */ { Expr* expr = new IfExpr(new Block(MoveAndDelete((yyvsp[-5].expr_list))), MoveAndDelete((yyvsp[-1].expr_list))); expr->loc = (yylsp[-8]); (yyval.expr_list) = (yyvsp[-8].expr_list); (yyval.expr_list)->push_back(expr); } -#line 3251 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3250 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 100: -#line 793 "src/wast-parser.y" /* yacc.c:1646 */ +#line 792 "src/wast-parser.y" /* yacc.c:1646 */ { Expr* expr = new IfExpr(new Block(MoveAndDelete((yyvsp[-1].expr_list)))); expr->loc = (yylsp[-4]); (yyval.expr_list) = (yyvsp[-4].expr_list); (yyval.expr_list)->push_back(expr); } -#line 3262 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3261 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 101: -#line 799 "src/wast-parser.y" /* yacc.c:1646 */ +#line 798 "src/wast-parser.y" /* yacc.c:1646 */ { Expr* expr = new IfExpr(new Block(MoveAndDelete((yyvsp[-1].expr_list))), MoveAndDelete((yyvsp[0].expr_list))); expr->loc = (yylsp[-2]); (yyval.expr_list) = (yyvsp[-2].expr_list); (yyval.expr_list)->push_back(expr); } -#line 3273 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3272 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 102: -#line 805 "src/wast-parser.y" /* yacc.c:1646 */ +#line 804 "src/wast-parser.y" /* yacc.c:1646 */ { Expr* expr = new IfExpr(new Block(MoveAndDelete((yyvsp[0].expr_list)))); expr->loc = (yylsp[-1]); (yyval.expr_list) = (yyvsp[-1].expr_list); (yyval.expr_list)->push_back(expr); } -#line 3284 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3283 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 103: -#line 814 "src/wast-parser.y" /* yacc.c:1646 */ +#line 813 "src/wast-parser.y" /* yacc.c:1646 */ { CHECK_ALLOW_EXCEPTIONS(&(yylsp[0]), "rethrow"); } -#line 3292 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3291 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 104: -#line 819 "src/wast-parser.y" /* yacc.c:1646 */ +#line 818 "src/wast-parser.y" /* yacc.c:1646 */ { CHECK_ALLOW_EXCEPTIONS(&(yylsp[0]), "throw"); } -#line 3300 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3299 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 105: -#line 825 "src/wast-parser.y" /* yacc.c:1646 */ +#line 824 "src/wast-parser.y" /* yacc.c:1646 */ { CHECK_ALLOW_EXCEPTIONS(&(yylsp[0]), "try"); } -#line 3308 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3307 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 106: -#line 831 "src/wast-parser.y" /* yacc.c:1646 */ +#line 830 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.expr_list) = new ExprList(); } -#line 3314 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3313 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 107: -#line 832 "src/wast-parser.y" /* yacc.c:1646 */ +#line 831 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.expr_list) = (yyvsp[0].expr_list); (yyval.expr_list)->splice((yyval.expr_list)->begin(), MoveAndDelete((yyvsp[-1].expr_list))); } -#line 3323 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3322 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 108: -#line 838 "src/wast-parser.y" /* yacc.c:1646 */ +#line 837 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.expr_list) = new ExprList(); } -#line 3329 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3328 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 109: -#line 839 "src/wast-parser.y" /* yacc.c:1646 */ +#line 838 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.expr_list) = (yyvsp[0].expr_list); (yyval.expr_list)->splice((yyval.expr_list)->begin(), MoveAndDelete((yyvsp[-1].expr_list))); } -#line 3338 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3337 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 111: -#line 850 "src/wast-parser.y" /* yacc.c:1646 */ +#line 849 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.exception) = new Exception(MoveAndDelete((yyvsp[-2].string)), MoveAndDelete((yyvsp[-1].types))); } -#line 3346 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3345 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 112: -#line 855 "src/wast-parser.y" /* yacc.c:1646 */ +#line 854 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.module_field) = new ExceptionModuleField((yyvsp[0].exception)); } -#line 3354 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3353 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 113: -#line 862 "src/wast-parser.y" /* yacc.c:1646 */ +#line 861 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.module_fields) = (yyvsp[-1].module_fields); ModuleField* main_field = &(yyval.module_fields)->front(); @@ -3366,30 +3365,30 @@ yyreduce: MoveAndDelete((yyvsp[-2].string)); } } -#line 3370 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3369 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 114: -#line 876 "src/wast-parser.y" /* yacc.c:1646 */ +#line 875 "src/wast-parser.y" /* yacc.c:1646 */ { auto field = new FuncModuleField((yyvsp[0].func)); field->func->decl.has_func_type = true; field->func->decl.type_var = MoveAndDelete((yyvsp[-1].var)); (yyval.module_fields) = new ModuleFieldList(field); } -#line 3381 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3380 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 115: -#line 882 "src/wast-parser.y" /* yacc.c:1646 */ +#line 881 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.module_fields) = new ModuleFieldList(new FuncModuleField((yyvsp[0].func))); } -#line 3389 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3388 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 116: -#line 885 "src/wast-parser.y" /* yacc.c:1646 */ +#line 884 "src/wast-parser.y" /* yacc.c:1646 */ { auto field = new ImportModuleField((yyvsp[-2].import), (yylsp[-2])); field->import->kind = ExternalKind::Func; @@ -3398,161 +3397,161 @@ yyreduce: field->import->func->decl.type_var = MoveAndDelete((yyvsp[-1].var)); (yyval.module_fields) = new ModuleFieldList(field); } -#line 3402 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3401 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 117: -#line 893 "src/wast-parser.y" /* yacc.c:1646 */ +#line 892 "src/wast-parser.y" /* yacc.c:1646 */ { auto field = new ImportModuleField((yyvsp[-1].import), (yylsp[-1])); field->import->kind = ExternalKind::Func; field->import->func = (yyvsp[0].func); (yyval.module_fields) = new ModuleFieldList(field); } -#line 3413 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3412 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 118: -#line 899 "src/wast-parser.y" /* yacc.c:1646 */ +#line 898 "src/wast-parser.y" /* yacc.c:1646 */ { auto field = new ExportModuleField((yyvsp[-1].export_), (yylsp[-1])); field->export_->kind = ExternalKind::Func; (yyval.module_fields) = (yyvsp[0].module_fields); (yyval.module_fields)->push_back(field); } -#line 3424 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3423 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 119: -#line 908 "src/wast-parser.y" /* yacc.c:1646 */ +#line 907 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.func) = (yyvsp[0].func); ReverseBindings(&(yyval.func)->decl.sig.param_types, &(yyval.func)->param_bindings); } -#line 3433 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3432 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 121: -#line 916 "src/wast-parser.y" /* yacc.c:1646 */ +#line 915 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.func) = (yyvsp[0].func); PrependAndDelete((yyval.func)->decl.sig.param_types, (yyvsp[-2].types)); } -#line 3442 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3441 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 122: -#line 920 "src/wast-parser.y" /* yacc.c:1646 */ +#line 919 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.func) = (yyvsp[0].func); (yyval.func)->param_bindings.emplace(MoveAndDelete((yyvsp[-3].string)), Binding((yylsp[-3]), (yyval.func)->decl.sig.param_types.size())); (yyval.func)->decl.sig.param_types.insert((yyval.func)->decl.sig.param_types.begin(), (yyvsp[-2].t_type)); } -#line 3453 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3452 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 123: -#line 929 "src/wast-parser.y" /* yacc.c:1646 */ +#line 928 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.func) = new Func(); } -#line 3459 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3458 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 124: -#line 930 "src/wast-parser.y" /* yacc.c:1646 */ +#line 929 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.func) = (yyvsp[0].func); PrependAndDelete((yyval.func)->decl.sig.result_types, (yyvsp[-2].types)); } -#line 3468 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3467 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 125: -#line 937 "src/wast-parser.y" /* yacc.c:1646 */ +#line 936 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.func) = (yyvsp[0].func); ReverseBindings(&(yyval.func)->decl.sig.param_types, &(yyval.func)->param_bindings); } -#line 3477 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3476 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 127: -#line 945 "src/wast-parser.y" /* yacc.c:1646 */ +#line 944 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.func) = (yyvsp[0].func); PrependAndDelete((yyval.func)->decl.sig.param_types, (yyvsp[-2].types)); } -#line 3486 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3485 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 128: -#line 949 "src/wast-parser.y" /* yacc.c:1646 */ +#line 948 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.func) = (yyvsp[0].func); (yyval.func)->param_bindings.emplace(MoveAndDelete((yyvsp[-3].string)), Binding((yylsp[-3]), (yyval.func)->decl.sig.param_types.size())); (yyval.func)->decl.sig.param_types.insert((yyval.func)->decl.sig.param_types.begin(), (yyvsp[-2].t_type)); } -#line 3497 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3496 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 130: -#line 959 "src/wast-parser.y" /* yacc.c:1646 */ +#line 958 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.func) = (yyvsp[0].func); PrependAndDelete((yyval.func)->decl.sig.result_types, (yyvsp[-2].types)); } -#line 3506 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3505 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 131: -#line 966 "src/wast-parser.y" /* yacc.c:1646 */ +#line 965 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.func) = (yyvsp[0].func); ReverseBindings(&(yyval.func)->local_types, &(yyval.func)->local_bindings); } -#line 3515 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3514 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 132: -#line 973 "src/wast-parser.y" /* yacc.c:1646 */ +#line 972 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.func) = new Func(); (yyval.func)->exprs = MoveAndDelete((yyvsp[0].expr_list)); } -#line 3524 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3523 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 133: -#line 977 "src/wast-parser.y" /* yacc.c:1646 */ +#line 976 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.func) = (yyvsp[0].func); PrependAndDelete((yyval.func)->local_types, (yyvsp[-2].types)); } -#line 3533 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3532 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 134: -#line 981 "src/wast-parser.y" /* yacc.c:1646 */ +#line 980 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.func) = (yyvsp[0].func); (yyval.func)->local_bindings.emplace(MoveAndDelete((yyvsp[-3].string)), Binding((yylsp[-3]), (yyval.func)->local_types.size())); (yyval.func)->local_types.insert((yyval.func)->local_types.begin(), (yyvsp[-2].t_type)); } -#line 3544 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3543 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 135: -#line 992 "src/wast-parser.y" /* yacc.c:1646 */ +#line 991 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.expr_list) = (yyvsp[-1].expr_list); } -#line 3552 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3551 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 137: -#line 999 "src/wast-parser.y" /* yacc.c:1646 */ +#line 998 "src/wast-parser.y" /* yacc.c:1646 */ { auto elem_segment = new ElemSegment(); elem_segment->table_var = MoveAndDelete((yyvsp[-3].var)); @@ -3560,11 +3559,11 @@ yyreduce: elem_segment->vars = MoveAndDelete((yyvsp[-1].vars)); (yyval.module_field) = new ElemSegmentModuleField(elem_segment, (yylsp[-4])); } -#line 3564 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3563 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 138: -#line 1006 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1005 "src/wast-parser.y" /* yacc.c:1646 */ { auto elem_segment = new ElemSegment(); elem_segment->table_var = Var(0, (yylsp[-3])); @@ -3572,11 +3571,11 @@ yyreduce: elem_segment->vars = MoveAndDelete((yyvsp[-1].vars)); (yyval.module_field) = new ElemSegmentModuleField(elem_segment, (yylsp[-3])); } -#line 3576 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3575 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 139: -#line 1016 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1015 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.module_fields) = (yyvsp[-1].module_fields); ModuleField* main_field = &(yyval.module_fields)->front(); @@ -3588,41 +3587,41 @@ yyreduce: MoveAndDelete((yyvsp[-2].string)); } } -#line 3592 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3591 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 140: -#line 1030 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1029 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.module_fields) = new ModuleFieldList(new TableModuleField((yyvsp[0].table))); } -#line 3600 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3599 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 141: -#line 1033 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1032 "src/wast-parser.y" /* yacc.c:1646 */ { auto field = new ImportModuleField((yyvsp[-1].import)); field->import->kind = ExternalKind::Table; field->import->table = (yyvsp[0].table); (yyval.module_fields) = new ModuleFieldList(field); } -#line 3611 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3610 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 142: -#line 1039 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1038 "src/wast-parser.y" /* yacc.c:1646 */ { auto field = new ExportModuleField((yyvsp[-1].export_), (yylsp[-1])); field->export_->kind = ExternalKind::Table; (yyval.module_fields) = (yyvsp[0].module_fields); (yyval.module_fields)->push_back(field); } -#line 3622 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3621 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 143: -#line 1045 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1044 "src/wast-parser.y" /* yacc.c:1646 */ { auto table = new Table(); table->elem_limits.initial = (yyvsp[-1].vars)->size(); @@ -3639,11 +3638,11 @@ yyreduce: (yyval.module_fields)->push_back(new TableModuleField(table)); (yyval.module_fields)->push_back(new ElemSegmentModuleField(elem_segment, (yylsp[-2]))); } -#line 3643 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3642 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 144: -#line 1064 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1063 "src/wast-parser.y" /* yacc.c:1646 */ { auto data_segment = new DataSegment(); data_segment->memory_var = MoveAndDelete((yyvsp[-3].var)); @@ -3651,11 +3650,11 @@ yyreduce: RemoveEscapes(MoveAndDelete((yyvsp[-1].texts)), std::back_inserter(data_segment->data)); (yyval.module_field) = new DataSegmentModuleField(data_segment, (yylsp[-4])); } -#line 3655 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3654 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 145: -#line 1071 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1070 "src/wast-parser.y" /* yacc.c:1646 */ { auto data_segment = new DataSegment(); data_segment->memory_var = Var(0, (yylsp[-3])); @@ -3663,11 +3662,11 @@ yyreduce: RemoveEscapes(MoveAndDelete((yyvsp[-1].texts)), std::back_inserter(data_segment->data)); (yyval.module_field) = new DataSegmentModuleField(data_segment, (yylsp[-3])); } -#line 3667 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3666 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 146: -#line 1081 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1080 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.module_fields) = (yyvsp[-1].module_fields); ModuleField* main_field = &(yyval.module_fields)->front(); @@ -3679,41 +3678,41 @@ yyreduce: MoveAndDelete((yyvsp[-2].string)); } } -#line 3683 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3682 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 147: -#line 1095 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1094 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.module_fields) = new ModuleFieldList(new MemoryModuleField((yyvsp[0].memory))); } -#line 3691 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3690 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 148: -#line 1098 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1097 "src/wast-parser.y" /* yacc.c:1646 */ { auto field = new ImportModuleField((yyvsp[-1].import)); field->import->kind = ExternalKind::Memory; field->import->memory = (yyvsp[0].memory); (yyval.module_fields) = new ModuleFieldList(field); } -#line 3702 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3701 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 149: -#line 1104 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1103 "src/wast-parser.y" /* yacc.c:1646 */ { auto field = new ExportModuleField((yyvsp[-1].export_), (yylsp[-1])); field->export_->kind = ExternalKind::Memory; (yyval.module_fields) = (yyvsp[0].module_fields); (yyval.module_fields)->push_back(field); } -#line 3713 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3712 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 150: -#line 1110 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1109 "src/wast-parser.y" /* yacc.c:1646 */ { auto data_segment = new DataSegment(); data_segment->memory_var = Var(kInvalidIndex); @@ -3733,11 +3732,11 @@ yyreduce: (yyval.module_fields)->push_back(new MemoryModuleField(memory)); (yyval.module_fields)->push_back(new DataSegmentModuleField(data_segment, (yylsp[-2]))); } -#line 3737 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3736 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 151: -#line 1132 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1131 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.module_fields) = (yyvsp[-1].module_fields); ModuleField* main_field = &(yyval.module_fields)->front(); @@ -3749,43 +3748,43 @@ yyreduce: MoveAndDelete((yyvsp[-2].string)); } } -#line 3753 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3752 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 152: -#line 1146 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1145 "src/wast-parser.y" /* yacc.c:1646 */ { auto field = new GlobalModuleField((yyvsp[-1].global)); field->global->init_expr = MoveAndDelete((yyvsp[0].expr_list)); (yyval.module_fields) = new ModuleFieldList(field); } -#line 3763 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3762 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 153: -#line 1151 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1150 "src/wast-parser.y" /* yacc.c:1646 */ { auto field = new ImportModuleField((yyvsp[-1].import)); field->import->kind = ExternalKind::Global; field->import->global = (yyvsp[0].global); (yyval.module_fields) = new ModuleFieldList(field); } -#line 3774 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3773 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 154: -#line 1157 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1156 "src/wast-parser.y" /* yacc.c:1646 */ { auto field = new ExportModuleField((yyvsp[-1].export_), (yylsp[-1])); field->export_->kind = ExternalKind::Global; (yyval.module_fields) = (yyvsp[0].module_fields); (yyval.module_fields)->push_back(field); } -#line 3785 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3784 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 155: -#line 1168 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1167 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.import) = new Import(); (yyval.import)->kind = ExternalKind::Func; @@ -3794,11 +3793,11 @@ yyreduce: (yyval.import)->func->decl.has_func_type = true; (yyval.import)->func->decl.type_var = MoveAndDelete((yyvsp[-1].var)); } -#line 3798 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3797 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 156: -#line 1176 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1175 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.import) = new Import(); (yyval.import)->kind = ExternalKind::Func; @@ -3806,241 +3805,241 @@ yyreduce: (yyval.import)->func->name = MoveAndDelete((yyvsp[-2].string)); (yyval.import)->func->decl.sig = MoveAndDelete((yyvsp[-1].func_sig)); } -#line 3810 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3809 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 157: -#line 1183 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1182 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.import) = new Import(); (yyval.import)->kind = ExternalKind::Table; (yyval.import)->table = (yyvsp[-1].table); (yyval.import)->table->name = MoveAndDelete((yyvsp[-2].string)); } -#line 3821 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3820 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 158: -#line 1189 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1188 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.import) = new Import(); (yyval.import)->kind = ExternalKind::Memory; (yyval.import)->memory = (yyvsp[-1].memory); (yyval.import)->memory->name = MoveAndDelete((yyvsp[-2].string)); } -#line 3832 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3831 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 159: -#line 1195 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1194 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.import) = new Import(); (yyval.import)->kind = ExternalKind::Global; (yyval.import)->global = (yyvsp[-1].global); (yyval.import)->global->name = MoveAndDelete((yyvsp[-2].string)); } -#line 3843 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3842 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 160: -#line 1201 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1200 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.import) = new Import(); (yyval.import)->kind = ExternalKind::Except; (yyval.import)->except = (yyvsp[0].exception); } -#line 3853 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3852 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 161: -#line 1209 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1208 "src/wast-parser.y" /* yacc.c:1646 */ { auto field = new ImportModuleField((yyvsp[-1].import), (yylsp[-4])); field->import->module_name = MoveAndDelete((yyvsp[-3].string)); field->import->field_name = MoveAndDelete((yyvsp[-2].string)); (yyval.module_field) = field; } -#line 3864 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3863 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 162: -#line 1218 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1217 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.import) = new Import(); (yyval.import)->module_name = MoveAndDelete((yyvsp[-2].string)); (yyval.import)->field_name = MoveAndDelete((yyvsp[-1].string)); } -#line 3874 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3873 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 163: -#line 1226 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1225 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.export_) = new Export(); (yyval.export_)->kind = ExternalKind::Func; (yyval.export_)->var = MoveAndDelete((yyvsp[-1].var)); } -#line 3884 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3883 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 164: -#line 1231 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1230 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.export_) = new Export(); (yyval.export_)->kind = ExternalKind::Table; (yyval.export_)->var = MoveAndDelete((yyvsp[-1].var)); } -#line 3894 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3893 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 165: -#line 1236 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1235 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.export_) = new Export(); (yyval.export_)->kind = ExternalKind::Memory; (yyval.export_)->var = MoveAndDelete((yyvsp[-1].var)); } -#line 3904 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3903 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 166: -#line 1241 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1240 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.export_) = new Export(); (yyval.export_)->kind = ExternalKind::Global; (yyval.export_)->var = MoveAndDelete((yyvsp[-1].var)); } -#line 3914 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3913 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 167: -#line 1246 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1245 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.export_) = new Export(); (yyval.export_)->kind = ExternalKind::Except; (yyval.export_)->var = MoveAndDelete((yyvsp[-1].var)); } -#line 3924 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3923 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 168: -#line 1253 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1252 "src/wast-parser.y" /* yacc.c:1646 */ { auto field = new ExportModuleField((yyvsp[-1].export_), (yylsp[-3])); field->export_->name = MoveAndDelete((yyvsp[-2].string)); (yyval.module_field) = field; } -#line 3934 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3933 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 169: -#line 1261 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1260 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.export_) = new Export(); (yyval.export_)->name = MoveAndDelete((yyvsp[-1].string)); } -#line 3943 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3942 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 170: -#line 1271 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1270 "src/wast-parser.y" /* yacc.c:1646 */ { auto func_type = new FuncType(); func_type->sig = MoveAndDelete((yyvsp[-1].func_sig)); (yyval.module_field) = new FuncTypeModuleField(func_type, (yylsp[-2])); } -#line 3953 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3952 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 171: -#line 1276 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1275 "src/wast-parser.y" /* yacc.c:1646 */ { auto func_type = new FuncType(); func_type->name = MoveAndDelete((yyvsp[-2].string)); func_type->sig = MoveAndDelete((yyvsp[-1].func_sig)); (yyval.module_field) = new FuncTypeModuleField(func_type, (yylsp[-3])); } -#line 3964 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3963 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 172: -#line 1285 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1284 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.module_field) = new StartModuleField(MoveAndDelete((yyvsp[-1].var)), (yylsp[-2])); } -#line 3972 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3971 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 173: -#line 1291 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1290 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.module_fields) = new ModuleFieldList((yyvsp[0].module_field)); } -#line 3978 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3977 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 178: -#line 1296 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1295 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.module_fields) = new ModuleFieldList((yyvsp[0].module_field)); } -#line 3984 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3983 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 179: -#line 1297 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1296 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.module_fields) = new ModuleFieldList((yyvsp[0].module_field)); } -#line 3990 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3989 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 180: -#line 1298 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1297 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.module_fields) = new ModuleFieldList((yyvsp[0].module_field)); } -#line 3996 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 3995 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 181: -#line 1299 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1298 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.module_fields) = new ModuleFieldList((yyvsp[0].module_field)); } -#line 4002 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4001 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 182: -#line 1300 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1299 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.module_fields) = new ModuleFieldList((yyvsp[0].module_field)); } -#line 4008 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4007 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 183: -#line 1301 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1300 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.module_fields) = new ModuleFieldList((yyvsp[0].module_field)); } -#line 4014 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4013 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 184: -#line 1305 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1304 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.module) = new Module(); } -#line 4020 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4019 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 186: -#line 1310 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1309 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.module) = new Module(); CheckImportOrdering(&(yylsp[0]), lexer, parser, (yyval.module), *(yyvsp[0].module_fields)); AppendModuleFields((yyval.module), MoveAndDelete((yyvsp[0].module_fields))); } -#line 4030 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4029 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 187: -#line 1315 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1314 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); CheckImportOrdering(&(yylsp[0]), lexer, parser, (yyval.module), *(yyvsp[0].module_fields)); AppendModuleFields((yyval.module), MoveAndDelete((yyvsp[0].module_fields))); } -#line 4040 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4039 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 188: -#line 1323 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1322 "src/wast-parser.y" /* yacc.c:1646 */ { if ((yyvsp[0].script_module)->type == ScriptModule::Type::Text) { (yyval.module) = (yyvsp[0].script_module)->text; @@ -4051,34 +4050,34 @@ yyreduce: ReadBinaryOptions options; BinaryErrorHandlerModule error_handler(&(yyvsp[0].script_module)->binary.loc, lexer, parser); const char* filename = "<text>"; - read_binary_ir(filename, (yyvsp[0].script_module)->binary.data.data(), (yyvsp[0].script_module)->binary.data.size(), - &options, &error_handler, (yyval.module)); + ReadBinaryIr(filename, (yyvsp[0].script_module)->binary.data.data(), (yyvsp[0].script_module)->binary.data.size(), + &options, &error_handler, (yyval.module)); (yyval.module)->name = (yyvsp[0].script_module)->binary.name; (yyval.module)->loc = (yyvsp[0].script_module)->binary.loc; } delete (yyvsp[0].script_module); } -#line 4062 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4061 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 190: -#line 1350 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1349 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.var) = new Var(kInvalidIndex); } -#line 4070 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4069 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 191: -#line 1353 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1352 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.var) = new Var((yyvsp[0].t_text).to_string_view(), (yylsp[0])); } -#line 4078 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4077 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 192: -#line 1359 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1358 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.script_module) = new ScriptModule(ScriptModule::Type::Text); (yyval.script_module)->text = (yyvsp[-1].module); @@ -4096,33 +4095,33 @@ yyreduce: } } } -#line 4100 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4099 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 193: -#line 1376 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1375 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.script_module) = new ScriptModule(ScriptModule::Type::Binary); (yyval.script_module)->binary.name = MoveAndDelete((yyvsp[-3].string)); (yyval.script_module)->binary.loc = (yylsp[-4]); RemoveEscapes(MoveAndDelete((yyvsp[-1].texts)), std::back_inserter((yyval.script_module)->binary.data)); } -#line 4111 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4110 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 194: -#line 1382 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1381 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.script_module) = new ScriptModule(ScriptModule::Type::Quoted); (yyval.script_module)->quoted.name = MoveAndDelete((yyvsp[-3].string)); (yyval.script_module)->quoted.loc = (yylsp[-4]); RemoveEscapes(MoveAndDelete((yyvsp[-1].texts)), std::back_inserter((yyval.script_module)->quoted.data)); } -#line 4122 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4121 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 195: -#line 1391 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1390 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.action) = new Action(); (yyval.action)->loc = (yylsp[-4]); @@ -4132,11 +4131,11 @@ yyreduce: (yyval.action)->invoke = new ActionInvoke(); (yyval.action)->invoke->args = MoveAndDelete((yyvsp[-1].consts)); } -#line 4136 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4135 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 196: -#line 1400 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1399 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.action) = new Action(); (yyval.action)->loc = (yylsp[-3]); @@ -4144,163 +4143,163 @@ yyreduce: (yyval.action)->type = ActionType::Get; (yyval.action)->name = MoveAndDelete((yyvsp[-1].string)); } -#line 4148 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4147 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 197: -#line 1410 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1409 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.command) = new AssertMalformedCommand((yyvsp[-2].script_module), MoveAndDelete((yyvsp[-1].string))); } -#line 4156 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4155 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 198: -#line 1413 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1412 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.command) = new AssertInvalidCommand((yyvsp[-2].script_module), MoveAndDelete((yyvsp[-1].string))); } -#line 4164 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4163 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 199: -#line 1416 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1415 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.command) = new AssertUnlinkableCommand((yyvsp[-2].script_module), MoveAndDelete((yyvsp[-1].string))); } -#line 4172 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4171 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 200: -#line 1419 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1418 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.command) = new AssertUninstantiableCommand((yyvsp[-2].script_module), MoveAndDelete((yyvsp[-1].string))); } -#line 4180 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4179 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 201: -#line 1422 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1421 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.command) = new AssertReturnCommand((yyvsp[-2].action), (yyvsp[-1].consts)); } -#line 4188 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4187 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 202: -#line 1425 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1424 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.command) = new AssertReturnCanonicalNanCommand((yyvsp[-1].action)); } -#line 4196 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4195 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 203: -#line 1428 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1427 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.command) = new AssertReturnArithmeticNanCommand((yyvsp[-1].action)); } -#line 4204 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4203 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 204: -#line 1431 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1430 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.command) = new AssertTrapCommand((yyvsp[-2].action), MoveAndDelete((yyvsp[-1].string))); } -#line 4212 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4211 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 205: -#line 1434 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1433 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.command) = new AssertExhaustionCommand((yyvsp[-2].action), MoveAndDelete((yyvsp[-1].string))); } -#line 4220 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4219 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 206: -#line 1440 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1439 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.command) = new ActionCommand((yyvsp[0].action)); } -#line 4228 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4227 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 208: -#line 1444 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1443 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.command) = new ModuleCommand((yyvsp[0].module)); } -#line 4236 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4235 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 209: -#line 1447 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1446 "src/wast-parser.y" /* yacc.c:1646 */ { auto* command = new RegisterCommand(MoveAndDelete((yyvsp[-2].string)), MoveAndDelete((yyvsp[-1].var))); command->var.loc = (yylsp[-1]); (yyval.command) = command; } -#line 4246 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4245 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 210: -#line 1454 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1453 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.commands) = new CommandPtrVector(); (yyval.commands)->emplace_back((yyvsp[0].command)); } -#line 4255 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4254 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 211: -#line 1458 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1457 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.commands) = (yyvsp[-1].commands); (yyval.commands)->emplace_back((yyvsp[0].command)); } -#line 4264 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4263 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 212: -#line 1465 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1464 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.const_).loc = (yylsp[-2]); auto literal = MoveAndDelete((yyvsp[-1].literal)); if (Failed(ParseConst((yyvsp[-2].t_type), literal, &(yyval.const_)))) { - wast_parser_error(&(yylsp[-1]), lexer, parser, "invalid literal \"%s\"", - literal.text.c_str()); + WastParserError(&(yylsp[-1]), lexer, parser, "invalid literal \"%s\"", + literal.text.c_str()); } } -#line 4277 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4276 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 213: -#line 1475 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1474 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.consts) = new ConstVector(); } -#line 4283 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4282 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 214: -#line 1476 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1475 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.consts) = (yyvsp[-1].consts); (yyval.consts)->push_back((yyvsp[0].const_)); } -#line 4292 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4291 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 215: -#line 1483 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1482 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.script) = new Script(); } -#line 4300 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4299 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 216: -#line 1486 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1485 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.script) = new Script(); (yyval.script)->commands = MoveAndDelete((yyvsp[0].commands)); @@ -4363,26 +4362,26 @@ yyreduce: } } } -#line 4367 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4366 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 217: -#line 1548 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1547 "src/wast-parser.y" /* yacc.c:1646 */ { (yyval.script) = new Script(); (yyval.script)->commands.emplace_back(new ModuleCommand((yyvsp[0].module))); } -#line 4376 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4375 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; case 218: -#line 1557 "src/wast-parser.y" /* yacc.c:1646 */ +#line 1556 "src/wast-parser.y" /* yacc.c:1646 */ { parser->script = (yyvsp[0].script); } -#line 4382 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4381 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ break; -#line 4386 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ +#line 4385 "src/prebuilt/wast-parser-gen.cc" /* yacc.c:1646 */ default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -4617,7 +4616,7 @@ yyreturn: #endif return yyresult; } -#line 1560 "src/wast-parser.y" /* yacc.c:1906 */ +#line 1559 "src/wast-parser.y" /* yacc.c:1906 */ Result ParseConst(Type type, const Literal& literal, Const* out) { @@ -4628,13 +4627,13 @@ Result ParseConst(Type type, const Literal& literal, Const* out) { out->type = type; switch (type) { case Type::I32: - return parse_int32(s, end, &out->u32, ParseIntType::SignedAndUnsigned); + return ParseInt32(s, end, &out->u32, ParseIntType::SignedAndUnsigned); case Type::I64: - return parse_int64(s, end, &out->u64, ParseIntType::SignedAndUnsigned); + return ParseInt64(s, end, &out->u64, ParseIntType::SignedAndUnsigned); case Type::F32: - return parse_float(literal.type, s, end, &out->f32_bits); + return ParseFloat(literal.type, s, end, &out->f32_bits); case Type::F64: - return parse_double(literal.type, s, end, &out->f64_bits); + return ParseDouble(literal.type, s, end, &out->f64_bits); default: assert(0); break; @@ -4675,9 +4674,8 @@ void CheckImportOrdering(Location* loc, WastLexer* lexer, WastParser* parser, module->memories.size() != module->num_memory_imports || module->globals.size() != module->num_global_imports || module->excepts.size() != module->num_except_imports) { - wast_parser_error( - loc, lexer, parser, - "imports must occur before all non-import definitions"); + WastParserError(loc, lexer, parser, + "imports must occur before all non-import definitions"); } } } @@ -4848,9 +4846,8 @@ void AppendModuleFields(Module* module, ModuleFieldList&& fields) { module->fields.splice(module->fields.end(), fields); } -Result parse_wast(WastLexer* lexer, Script** out_script, - ErrorHandler* error_handler, - WastParseOptions* options) { +Result ParseWast(WastLexer * lexer, Script * *out_script, + ErrorHandler * error_handler, WastParseOptions * options) { WastParser parser; ZeroMemory(parser); static WastParseOptions default_options; @@ -4882,12 +4879,12 @@ bool BinaryErrorHandlerModule::OnError( const Location& binary_loc, const std::string& error, const std::string& source_line, size_t source_line_column_offset) { if (binary_loc.offset == kInvalidOffset) { - wast_parser_error(loc_, lexer_, parser_, "error in binary module: %s", - error.c_str()); + WastParserError(loc_, lexer_, parser_, "error in binary module: %s", + error.c_str()); } else { - wast_parser_error(loc_, lexer_, parser_, - "error in binary module: @0x%08" PRIzx ": %s", - binary_loc.offset, error.c_str()); + WastParserError(loc_, lexer_, parser_, + "error in binary module: @0x%08" PRIzx ": %s", + binary_loc.offset, error.c_str()); } return true; } diff --git a/src/resolve-names.cc b/src/resolve-names.cc index 09ba449e..e10bb4ae 100644 --- a/src/resolve-names.cc +++ b/src/resolve-names.cc @@ -106,7 +106,7 @@ void WABT_PRINTF_FORMAT(3, 4) NameResolver::PrintError(const Location* loc, result_ = Result::Error; va_list args; va_start(args, fmt); - wast_format_error(error_handler_, loc, lexer_, fmt, args); + WastFormatError(error_handler_, loc, lexer_, fmt, args); va_end(args); } @@ -441,16 +441,16 @@ Result NameResolver::VisitScript(Script* script) { return result_; } -Result resolve_names_module(WastLexer* lexer, - Module* module, - ErrorHandler* error_handler) { +Result ResolveNamesModule(WastLexer* lexer, + Module* module, + ErrorHandler* error_handler) { NameResolver resolver(lexer, nullptr, error_handler); return resolver.VisitModule(module); } -Result resolve_names_script(WastLexer* lexer, - Script* script, - ErrorHandler* error_handler) { +Result ResolveNamesScript(WastLexer* lexer, + Script* script, + ErrorHandler* error_handler) { NameResolver resolver(lexer, script, error_handler); return resolver.VisitScript(script); } diff --git a/src/resolve-names.h b/src/resolve-names.h index c14526d1..b064775b 100644 --- a/src/resolve-names.h +++ b/src/resolve-names.h @@ -26,8 +26,8 @@ struct Module; struct Script; class ErrorHandler; -Result resolve_names_module(WastLexer*, Module*, ErrorHandler*); -Result resolve_names_script(WastLexer*, Script*, ErrorHandler*); +Result ResolveNamesModule(WastLexer*, Module*, ErrorHandler*); +Result ResolveNamesScript(WastLexer*, Script*, ErrorHandler*); } // namespace wabt diff --git a/src/string-view.h b/src/string-view.h index bc90130f..e6823b37 100644 --- a/src/string-view.h +++ b/src/string-view.h @@ -279,7 +279,7 @@ namespace std { template <> struct hash<::wabt::string_view> { ::wabt::hash_code operator()(const ::wabt::string_view& sv) { - return ::wabt::hash_range(sv.begin(), sv.end()); + return ::wabt::HashRange(sv.begin(), sv.end()); } }; diff --git a/src/test-utf8.cc b/src/test-utf8.cc index 066fa134..61bbfabf 100644 --- a/src/test-utf8.cc +++ b/src/test-utf8.cc @@ -35,12 +35,12 @@ void assert_is_valid_utf8(bool expected, // Make sure it fails if there are continuation bytes past the end of the // string. for (int bad_length = 1; bad_length < length; ++bad_length) { - ASSERT_FALSE(is_valid_utf8(buf, bad_length)) << cu0 << ", " << cu1 << ", " - << cu2 << ", " << cu3; + ASSERT_FALSE(IsValidUtf8(buf, bad_length)) + << cu0 << ", " << cu1 << ", " << cu2 << ", " << cu3; } } - ASSERT_TRUE(expected == is_valid_utf8(buf, length)) + ASSERT_TRUE(expected == IsValidUtf8(buf, length)) << cu0 << ", " << cu1 << ", " << cu2 << ", " << cu3; } diff --git a/src/tools/wasm-interp.cc b/src/tools/wasm-interp.cc index a451acf4..8fb92353 100644 --- a/src/tools/wasm-interp.cc +++ b/src/tools/wasm-interp.cc @@ -78,7 +78,7 @@ examples: $ wasm-interp test.wasm -V 100 --run-all-exports )"; -static void parse_options(int argc, char** argv) { +static void ParseOptions(int argc, char** argv) { OptionParser parser("wasm-interp", s_description); parser.AddOption('v', "verbose", "Use multiple times for more info", []() { @@ -120,7 +120,7 @@ enum class ModuleType { Binary, }; -static string_view get_dirname(string_view path) { +static string_view GetDirname(string_view path) { // Strip everything after and including the last slash (or backslash), e.g.: // // s = "foo/bar/baz", => "foo/bar" @@ -140,9 +140,7 @@ static string_view get_dirname(string_view path) { /* Not sure, but 100 chars is probably safe */ #define MAX_TYPED_VALUE_CHARS 100 -static void sprint_typed_value(char* buffer, - size_t size, - const TypedValue* tv) { +static void SPrintTypedValue(char* buffer, size_t size, const TypedValue* tv) { switch (tv->type) { case Type::I32: snprintf(buffer, size, "i32:%u", tv->value.i32); @@ -172,57 +170,57 @@ static void sprint_typed_value(char* buffer, } } -static void print_typed_value(const TypedValue* tv) { +static void PrintTypedValue(const TypedValue* tv) { char buffer[MAX_TYPED_VALUE_CHARS]; - sprint_typed_value(buffer, sizeof(buffer), tv); + SPrintTypedValue(buffer, sizeof(buffer), tv); printf("%s", buffer); } -static void print_typed_value_vector(const std::vector<TypedValue>& values) { +static void PrintTypedValueVector(const std::vector<TypedValue>& values) { for (size_t i = 0; i < values.size(); ++i) { - print_typed_value(&values[i]); + PrintTypedValue(&values[i]); if (i != values.size() - 1) printf(", "); } } -static void print_interpreter_result(const char* desc, - interpreter::Result iresult) { +static void PrintInterpreterResult(const char* desc, + interpreter::Result iresult) { printf("%s: %s\n", desc, s_trap_strings[static_cast<size_t>(iresult)]); } -static void print_call(string_view module_name, - string_view func_name, - const std::vector<TypedValue>& args, - const std::vector<TypedValue>& results, - interpreter::Result iresult) { +static void PrintCall(string_view module_name, + string_view func_name, + const std::vector<TypedValue>& args, + const std::vector<TypedValue>& results, + interpreter::Result iresult) { if (!module_name.empty()) printf(PRIstringview ".", WABT_PRINTF_STRING_VIEW_ARG(module_name)); printf(PRIstringview "(", WABT_PRINTF_STRING_VIEW_ARG(func_name)); - print_typed_value_vector(args); + PrintTypedValueVector(args); printf(") =>"); if (iresult == interpreter::Result::Ok) { if (results.size() > 0) { printf(" "); - print_typed_value_vector(results); + PrintTypedValueVector(results); } printf("\n"); } else { - print_interpreter_result(" error", iresult); + PrintInterpreterResult(" error", iresult); } } -static interpreter::Result run_function(Thread* thread, - Index func_index, - const std::vector<TypedValue>& args, - std::vector<TypedValue>* out_results) { +static interpreter::Result RunFunction(Thread* thread, + Index func_index, + const std::vector<TypedValue>& args, + std::vector<TypedValue>* out_results) { return s_trace ? thread->TraceFunction(func_index, s_stdout_stream.get(), args, out_results) : thread->RunFunction(func_index, args, out_results); } -static interpreter::Result run_start_function(Thread* thread, - DefinedModule* module) { +static interpreter::Result RunStartFunction(Thread* thread, + DefinedModule* module) { if (module->start_func_index == kInvalidIndex) return interpreter::Result::Ok; @@ -231,40 +229,39 @@ static interpreter::Result run_start_function(Thread* thread, std::vector<TypedValue> args; std::vector<TypedValue> results; interpreter::Result iresult = - run_function(thread, module->start_func_index, args, &results); + RunFunction(thread, module->start_func_index, args, &results); assert(results.size() == 0); return iresult; } -static interpreter::Result run_export(Thread* thread, - const Export* export_, - const std::vector<TypedValue>& args, - std::vector<TypedValue>* out_results) { +static interpreter::Result RunExport(Thread* thread, + const Export* export_, + const std::vector<TypedValue>& args, + std::vector<TypedValue>* out_results) { if (s_trace) { printf(">>> running export \"" PRIstringview "\":\n", WABT_PRINTF_STRING_VIEW_ARG(export_->name)); } assert(export_->kind == ExternalKind::Func); - return run_function(thread, export_->index, args, out_results); + return RunFunction(thread, export_->index, args, out_results); } -static interpreter::Result run_export_by_name( - Thread* thread, - Module* module, - string_view name, - const std::vector<TypedValue>& args, - std::vector<TypedValue>* out_results, - RunVerbosity verbose) { +static interpreter::Result RunExportByName(Thread* thread, + Module* module, + string_view name, + const std::vector<TypedValue>& args, + std::vector<TypedValue>* out_results, + RunVerbosity verbose) { Export* export_ = module->GetExport(name); if (!export_) return interpreter::Result::UnknownExport; if (export_->kind != ExternalKind::Func) return interpreter::Result::ExportKindMismatch; - return run_export(thread, export_, args, out_results); + return RunExport(thread, export_, args, out_results); } -static interpreter::Result get_global_export_by_name( +static interpreter::Result GetGlobalExportByName( Thread* thread, Module* module, string_view name, @@ -281,23 +278,23 @@ static interpreter::Result get_global_export_by_name( return interpreter::Result::Ok; } -static void run_all_exports(Module* module, - Thread* thread, - RunVerbosity verbose) { +static void RunAllExports(Module* module, + Thread* thread, + RunVerbosity verbose) { std::vector<TypedValue> args; std::vector<TypedValue> results; for (const Export& export_ : module->exports) { - interpreter::Result iresult = run_export(thread, &export_, args, &results); + interpreter::Result iresult = RunExport(thread, &export_, args, &results); if (verbose == RunVerbosity::Verbose) { - print_call(string_view(), export_.name, args, results, iresult); + PrintCall(string_view(), export_.name, args, results, iresult); } } } -static wabt::Result read_module(const char* module_filename, - Environment* env, - ErrorHandler* error_handler, - DefinedModule** out_module) { +static wabt::Result ReadModule(const char* module_filename, + Environment* env, + ErrorHandler* error_handler, + DefinedModule** out_module) { wabt::Result result; std::vector<uint8_t> file_data; @@ -305,9 +302,9 @@ static wabt::Result read_module(const char* module_filename, result = ReadFile(module_filename, &file_data); if (Succeeded(result)) { - result = read_binary_interpreter(env, DataOrNull(file_data), - file_data.size(), &s_read_binary_options, - error_handler, out_module); + result = ReadBinaryInterpreter(env, DataOrNull(file_data), file_data.size(), + &s_read_binary_options, error_handler, + out_module); if (Succeeded(result)) { if (s_verbose) @@ -332,8 +329,8 @@ static interpreter::Result default_host_callback(const HostFunc* func, std::vector<TypedValue> vec_results(out_results, out_results + num_results); printf("called host "); - print_call(func->module_name, func->field_name, vec_args, vec_results, - interpreter::Result::Ok); + PrintCall(func->module_name, func->field_name, vec_args, vec_results, + interpreter::Result::Ok); return interpreter::Result::Ok; } @@ -435,27 +432,27 @@ class SpectestHostImportDelegate : public HostImportDelegate { } }; -static void init_environment(Environment* env) { +static void InitEnvironment(Environment* env) { HostModule* host_module = env->AppendHostModule("spectest"); host_module->import_delegate.reset(new SpectestHostImportDelegate()); } -static wabt::Result read_and_run_module(const char* module_filename) { +static wabt::Result ReadAndRunModule(const char* module_filename) { wabt::Result result; Environment env; - init_environment(&env); + InitEnvironment(&env); ErrorHandlerFile error_handler(Location::Type::Binary); DefinedModule* module = nullptr; - result = read_module(module_filename, &env, &error_handler, &module); + result = ReadModule(module_filename, &env, &error_handler, &module); if (Succeeded(result)) { Thread thread(&env, s_thread_options); - interpreter::Result iresult = run_start_function(&thread, module); + interpreter::Result iresult = RunStartFunction(&thread, module); if (iresult == interpreter::Result::Ok) { if (s_run_all_exports) - run_all_exports(module, &thread, RunVerbosity::Verbose); + RunAllExports(module, &thread, RunVerbosity::Verbose); } else { - print_interpreter_result("error running start function", iresult); + PrintInterpreterResult("error running start function", iresult); } } return result; @@ -509,34 +506,34 @@ struct Action { return wabt::Result::Error; \ } while (0) -#define EXPECT(x) CHECK_RESULT(expect(ctx, x)) -#define EXPECT_KEY(x) CHECK_RESULT(expect_key(ctx, x)) +#define EXPECT(x) CHECK_RESULT(Expect(ctx, x)) +#define EXPECT_KEY(x) CHECK_RESULT(ExpectKey(ctx, x)) #define PARSE_KEY_STRING_VALUE(key, value) \ - CHECK_RESULT(parse_key_string_value(ctx, key, value)) + CHECK_RESULT(ParseKeyStringValue(ctx, key, value)) static void WABT_PRINTF_FORMAT(2, 3) - print_parse_error(Context* ctx, const char* format, ...) { + PrintParseError(Context* ctx, const char* format, ...) { WABT_SNPRINTF_ALLOCA(buffer, length, format); fprintf(stderr, "%s:%d:%d: %s\n", ctx->loc.filename, ctx->loc.line, ctx->loc.first_column, buffer); } static void WABT_PRINTF_FORMAT(2, 3) - print_command_error(Context* ctx, const char* format, ...) { + PrintCommandError(Context* ctx, const char* format, ...) { WABT_SNPRINTF_ALLOCA(buffer, length, format); printf(PRIstringview ":%u: %s\n", WABT_PRINTF_STRING_VIEW_ARG(ctx->source_filename), ctx->command_line_number, buffer); } -static void putback_char(Context* ctx) { +static void PutbackChar(Context* ctx) { assert(ctx->has_prev_loc); ctx->json_offset--; ctx->loc = ctx->prev_loc; ctx->has_prev_loc = false; } -static int read_char(Context* ctx) { +static int ReadChar(Context* ctx) { if (ctx->json_offset >= ctx->json_data.size()) return -1; ctx->prev_loc = ctx->loc; @@ -551,9 +548,9 @@ static int read_char(Context* ctx) { return c; } -static void skip_whitespace(Context* ctx) { +static void SkipWhitespace(Context* ctx) { while (1) { - switch (read_char(ctx)) { + switch (ReadChar(ctx)) { case -1: return; @@ -564,17 +561,17 @@ static void skip_whitespace(Context* ctx) { break; default: - putback_char(ctx); + PutbackChar(ctx); return; } } } -static bool match(Context* ctx, const char* s) { - skip_whitespace(ctx); +static bool Match(Context* ctx, const char* s) { + SkipWhitespace(ctx); Location start_loc = ctx->loc; size_t start_offset = ctx->json_offset; - while (*s && *s == read_char(ctx)) + while (*s && *s == ReadChar(ctx)) s++; if (*s == 0) { @@ -586,16 +583,16 @@ static bool match(Context* ctx, const char* s) { } } -static wabt::Result expect(Context* ctx, const char* s) { - if (match(ctx, s)) { +static wabt::Result Expect(Context* ctx, const char* s) { + if (Match(ctx, s)) { return wabt::Result::Ok; } else { - print_parse_error(ctx, "expected %s", s); + PrintParseError(ctx, "expected %s", s); return wabt::Result::Error; } } -static wabt::Result expect_key(Context* ctx, const char* key) { +static wabt::Result ExpectKey(Context* ctx, const char* key) { size_t keylen = strlen(key); size_t quoted_len = keylen + 2 + 1; char* quoted = static_cast<char*>(alloca(quoted_len)); @@ -605,20 +602,20 @@ static wabt::Result expect_key(Context* ctx, const char* key) { return wabt::Result::Ok; } -static wabt::Result parse_uint32(Context* ctx, uint32_t* out_int) { +static wabt::Result ParseUint32(Context* ctx, uint32_t* out_int) { uint32_t result = 0; - skip_whitespace(ctx); + SkipWhitespace(ctx); while (1) { - int c = read_char(ctx); + int c = ReadChar(ctx); if (c >= '0' && c <= '9') { uint32_t last_result = result; result = result * 10 + static_cast<uint32_t>(c - '0'); if (result < last_result) { - print_parse_error(ctx, "uint32 overflow"); + PrintParseError(ctx, "uint32 overflow"); return wabt::Result::Error; } } else { - putback_char(ctx); + PutbackChar(ctx); break; } } @@ -626,29 +623,29 @@ static wabt::Result parse_uint32(Context* ctx, uint32_t* out_int) { return wabt::Result::Ok; } -static wabt::Result parse_string(Context* ctx, std::string* out_string) { +static wabt::Result ParseString(Context* ctx, std::string* out_string) { out_string->clear(); - skip_whitespace(ctx); - if (read_char(ctx) != '"') { - print_parse_error(ctx, "expected string"); + SkipWhitespace(ctx); + if (ReadChar(ctx) != '"') { + PrintParseError(ctx, "expected string"); return wabt::Result::Error; } while (1) { - int c = read_char(ctx); + int c = ReadChar(ctx); if (c == '"') { break; } else if (c == '\\') { /* The only escape supported is \uxxxx. */ - c = read_char(ctx); + c = ReadChar(ctx); if (c != 'u') { - print_parse_error(ctx, "expected escape: \\uxxxx"); + PrintParseError(ctx, "expected escape: \\uxxxx"); return wabt::Result::Error; } uint16_t code = 0; for (int i = 0; i < 4; ++i) { - c = read_char(ctx); + c = ReadChar(ctx); int cval; if (c >= '0' && c <= '9') { cval = c - '0'; @@ -657,7 +654,7 @@ static wabt::Result parse_string(Context* ctx, std::string* out_string) { } else if (c >= 'A' && c <= 'F') { cval = c - 'A' + 10; } else { - print_parse_error(ctx, "expected hex char"); + PrintParseError(ctx, "expected hex char"); return wabt::Result::Error; } code = (code << 4) + cval; @@ -666,8 +663,7 @@ static wabt::Result parse_string(Context* ctx, std::string* out_string) { if (code < 256) { *out_string += code; } else { - print_parse_error(ctx, "only escape codes < 256 allowed, got %u\n", - code); + PrintParseError(ctx, "only escape codes < 256 allowed, got %u\n", code); } } else { *out_string += c; @@ -676,32 +672,32 @@ static wabt::Result parse_string(Context* ctx, std::string* out_string) { return wabt::Result::Ok; } -static wabt::Result parse_key_string_value(Context* ctx, - const char* key, - std::string* out_string) { +static wabt::Result ParseKeyStringValue(Context* ctx, + const char* key, + std::string* out_string) { out_string->clear(); EXPECT_KEY(key); - return parse_string(ctx, out_string); + return ParseString(ctx, out_string); } -static wabt::Result parse_opt_name_string_value(Context* ctx, - std::string* out_string) { +static wabt::Result ParseOptNameStringValue(Context* ctx, + std::string* out_string) { out_string->clear(); - if (match(ctx, "\"name\"")) { + if (Match(ctx, "\"name\"")) { EXPECT(":"); - CHECK_RESULT(parse_string(ctx, out_string)); + CHECK_RESULT(ParseString(ctx, out_string)); EXPECT(","); } return wabt::Result::Ok; } -static wabt::Result parse_line(Context* ctx) { +static wabt::Result ParseLine(Context* ctx) { EXPECT_KEY("line"); - CHECK_RESULT(parse_uint32(ctx, &ctx->command_line_number)); + CHECK_RESULT(ParseUint32(ctx, &ctx->command_line_number)); return wabt::Result::Ok; } -static wabt::Result parse_type_object(Context* ctx, Type* out_type) { +static wabt::Result ParseTypeObject(Context* ctx, Type* out_type) { std::string type_str; EXPECT("{"); PARSE_KEY_STRING_VALUE("type", &type_str); @@ -720,28 +716,28 @@ static wabt::Result parse_type_object(Context* ctx, Type* out_type) { *out_type = Type::F64; return wabt::Result::Ok; } else { - print_parse_error(ctx, "unknown type: \"" PRIstringview "\"", - WABT_PRINTF_STRING_VIEW_ARG(type_str)); + PrintParseError(ctx, "unknown type: \"" PRIstringview "\"", + WABT_PRINTF_STRING_VIEW_ARG(type_str)); return wabt::Result::Error; } } -static wabt::Result parse_type_vector(Context* ctx, TypeVector* out_types) { +static wabt::Result ParseTypeVector(Context* ctx, TypeVector* out_types) { out_types->clear(); EXPECT("["); bool first = true; - while (!match(ctx, "]")) { + while (!Match(ctx, "]")) { if (!first) EXPECT(","); Type type; - CHECK_RESULT(parse_type_object(ctx, &type)); + CHECK_RESULT(ParseTypeObject(ctx, &type)); first = false; out_types->push_back(type); } return wabt::Result::Ok; } -static wabt::Result parse_const(Context* ctx, TypedValue* out_value) { +static wabt::Result ParseConst(Context* ctx, TypedValue* out_value) { std::string type_str; std::string value_str; EXPECT("{"); @@ -755,82 +751,82 @@ static wabt::Result parse_const(Context* ctx, TypedValue* out_value) { if (type_str == "i32") { uint32_t value; - CHECK_RESULT(parse_int32(value_start, value_end, &value, - ParseIntType::UnsignedOnly)); + CHECK_RESULT( + ParseInt32(value_start, value_end, &value, ParseIntType::UnsignedOnly)); out_value->type = Type::I32; out_value->value.i32 = value; return wabt::Result::Ok; } else if (type_str == "f32") { uint32_t value_bits; - CHECK_RESULT(parse_int32(value_start, value_end, &value_bits, - ParseIntType::UnsignedOnly)); + CHECK_RESULT(ParseInt32(value_start, value_end, &value_bits, + ParseIntType::UnsignedOnly)); out_value->type = Type::F32; out_value->value.f32_bits = value_bits; return wabt::Result::Ok; } else if (type_str == "i64") { uint64_t value; - CHECK_RESULT(parse_int64(value_start, value_end, &value, - ParseIntType::UnsignedOnly)); + CHECK_RESULT( + ParseInt64(value_start, value_end, &value, ParseIntType::UnsignedOnly)); out_value->type = Type::I64; out_value->value.i64 = value; return wabt::Result::Ok; } else if (type_str == "f64") { uint64_t value_bits; - CHECK_RESULT(parse_int64(value_start, value_end, &value_bits, - ParseIntType::UnsignedOnly)); + CHECK_RESULT(ParseInt64(value_start, value_end, &value_bits, + ParseIntType::UnsignedOnly)); out_value->type = Type::F64; out_value->value.f64_bits = value_bits; return wabt::Result::Ok; } else { - print_parse_error(ctx, "unknown type: \"" PRIstringview "\"", - WABT_PRINTF_STRING_VIEW_ARG(type_str)); + PrintParseError(ctx, "unknown type: \"" PRIstringview "\"", + WABT_PRINTF_STRING_VIEW_ARG(type_str)); return wabt::Result::Error; } } -static wabt::Result parse_const_vector(Context* ctx, - std::vector<TypedValue>* out_values) { +static wabt::Result ParseConstVector(Context* ctx, + std::vector<TypedValue>* out_values) { out_values->clear(); EXPECT("["); bool first = true; - while (!match(ctx, "]")) { + while (!Match(ctx, "]")) { if (!first) EXPECT(","); TypedValue value; - CHECK_RESULT(parse_const(ctx, &value)); + CHECK_RESULT(ParseConst(ctx, &value)); out_values->push_back(value); first = false; } return wabt::Result::Ok; } -static wabt::Result parse_action(Context* ctx, Action* out_action) { +static wabt::Result ParseAction(Context* ctx, Action* out_action) { EXPECT_KEY("action"); EXPECT("{"); EXPECT_KEY("type"); - if (match(ctx, "\"invoke\"")) { + if (Match(ctx, "\"invoke\"")) { out_action->type = ActionType::Invoke; } else { EXPECT("\"get\""); out_action->type = ActionType::Get; } EXPECT(","); - if (match(ctx, "\"module\"")) { + if (Match(ctx, "\"module\"")) { EXPECT(":"); - CHECK_RESULT(parse_string(ctx, &out_action->module_name)); + CHECK_RESULT(ParseString(ctx, &out_action->module_name)); EXPECT(","); } PARSE_KEY_STRING_VALUE("field", &out_action->field_name); if (out_action->type == ActionType::Invoke) { EXPECT(","); EXPECT_KEY("args"); - CHECK_RESULT(parse_const_vector(ctx, &out_action->args)); + CHECK_RESULT(ParseConstVector(ctx, &out_action->args)); } EXPECT("}"); return wabt::Result::Ok; } -static wabt::Result parse_module_type(Context* ctx, ModuleType* out_type) { +static wabt::Result ParseModuleType(Context* ctx, ModuleType* out_type) { std::string module_type_str; PARSE_KEY_STRING_VALUE("module_type", &module_type_str); @@ -841,15 +837,15 @@ static wabt::Result parse_module_type(Context* ctx, ModuleType* out_type) { *out_type = ModuleType::Binary; return wabt::Result::Ok; } else { - print_parse_error(ctx, "unknown module type: \"" PRIstringview "\"", - WABT_PRINTF_STRING_VIEW_ARG(module_type_str)); + PrintParseError(ctx, "unknown module type: \"" PRIstringview "\"", + WABT_PRINTF_STRING_VIEW_ARG(module_type_str)); return wabt::Result::Error; } } static std::string CreateModulePath(Context* ctx, string_view filename) { const char* spec_json_filename = ctx->loc.filename; - string_view dirname = get_dirname(spec_json_filename); + string_view dirname = GetDirname(spec_json_filename); std::string path; if (dirname.size() == 0) { @@ -864,26 +860,26 @@ static std::string CreateModulePath(Context* ctx, string_view filename) { return path; } -static wabt::Result on_module_command(Context* ctx, - string_view filename, - string_view name) { +static wabt::Result OnModuleCommand(Context* ctx, + string_view filename, + string_view name) { std::string path = CreateModulePath(ctx, filename); Environment::MarkPoint mark = ctx->env.Mark(); ErrorHandlerFile error_handler(Location::Type::Binary); wabt::Result result = - read_module(path.c_str(), &ctx->env, &error_handler, &ctx->last_module); + ReadModule(path.c_str(), &ctx->env, &error_handler, &ctx->last_module); if (Failed(result)) { ctx->env.ResetToMarkPoint(mark); - print_command_error(ctx, "error reading module: \"%s\"", path.c_str()); + PrintCommandError(ctx, "error reading module: \"%s\"", path.c_str()); return wabt::Result::Error; } interpreter::Result iresult = - run_start_function(&ctx->thread, ctx->last_module); + RunStartFunction(&ctx->thread, ctx->last_module); if (iresult != interpreter::Result::Ok) { ctx->env.ResetToMarkPoint(mark); - print_interpreter_result("error running start function", iresult); + PrintInterpreterResult("error running start function", iresult); return wabt::Result::Error; } @@ -895,11 +891,11 @@ static wabt::Result on_module_command(Context* ctx, return wabt::Result::Ok; } -static wabt::Result run_action(Context* ctx, - Action* action, - interpreter::Result* out_iresult, - std::vector<TypedValue>* out_results, - RunVerbosity verbose) { +static wabt::Result RunAction(Context* ctx, + Action* action, + interpreter::Result* out_iresult, + std::vector<TypedValue>* out_results, + RunVerbosity verbose) { out_results->clear(); Module* module; @@ -912,41 +908,40 @@ static wabt::Result run_action(Context* ctx, switch (action->type) { case ActionType::Invoke: - *out_iresult = - run_export_by_name(&ctx->thread, module, action->field_name, - action->args, out_results, verbose); + *out_iresult = RunExportByName(&ctx->thread, module, action->field_name, + action->args, out_results, verbose); if (verbose == RunVerbosity::Verbose) { - print_call(string_view(), action->field_name, action->args, - *out_results, *out_iresult); + PrintCall(string_view(), action->field_name, action->args, *out_results, + *out_iresult); } return wabt::Result::Ok; case ActionType::Get: { - *out_iresult = get_global_export_by_name(&ctx->thread, module, - action->field_name, out_results); + *out_iresult = GetGlobalExportByName(&ctx->thread, module, + action->field_name, out_results); return wabt::Result::Ok; } default: - print_command_error(ctx, "invalid action type %d", - static_cast<int>(action->type)); + PrintCommandError(ctx, "invalid action type %d", + static_cast<int>(action->type)); return wabt::Result::Error; } } -static wabt::Result on_action_command(Context* ctx, Action* action) { +static wabt::Result OnActionCommand(Context* ctx, Action* action) { std::vector<TypedValue> results; interpreter::Result iresult; ctx->total++; wabt::Result result = - run_action(ctx, action, &iresult, &results, RunVerbosity::Verbose); + RunAction(ctx, action, &iresult, &results, RunVerbosity::Verbose); if (Succeeded(result)) { if (iresult == interpreter::Result::Ok) { ctx->passed++; } else { - print_command_error(ctx, "unexpected trap: %s", - s_trap_strings[static_cast<size_t>(iresult)]); + PrintCommandError(ctx, "unexpected trap: %s", + s_trap_strings[static_cast<size_t>(iresult)]); result = wabt::Result::Error; } } @@ -954,37 +949,37 @@ static wabt::Result on_action_command(Context* ctx, Action* action) { return result; } -static wabt::Result read_invalid_text_module(const char* module_filename, - Environment* env, - ErrorHandler* error_handler) { +static wabt::Result ReadInvalidTextModule(const char* module_filename, + Environment* env, + ErrorHandler* error_handler) { std::unique_ptr<WastLexer> lexer = WastLexer::CreateFileLexer(module_filename); - wabt::Result result = parse_wast(lexer.get(), nullptr, error_handler); + wabt::Result result = ParseWast(lexer.get(), nullptr, error_handler); return result; } -static wabt::Result read_invalid_module(Context* ctx, - const char* module_filename, - Environment* env, - ModuleType module_type, - const char* desc) { +static wabt::Result ReadInvalidModule(Context* ctx, + const char* module_filename, + Environment* env, + ModuleType module_type, + const char* desc) { std::string header = - string_printf(PRIstringview ":%d: %s passed", - WABT_PRINTF_STRING_VIEW_ARG(ctx->source_filename), - ctx->command_line_number, desc); + StringPrintf(PRIstringview ":%d: %s passed", + WABT_PRINTF_STRING_VIEW_ARG(ctx->source_filename), + ctx->command_line_number, desc); switch (module_type) { case ModuleType::Text: { ErrorHandlerFile error_handler(Location::Type::Text, stdout, header, ErrorHandlerFile::PrintHeader::Once); - return read_invalid_text_module(module_filename, env, &error_handler); + return ReadInvalidTextModule(module_filename, env, &error_handler); } case ModuleType::Binary: { DefinedModule* module; ErrorHandlerFile error_handler(Location::Type::Binary, stdout, header, ErrorHandlerFile::PrintHeader::Once); - return read_module(module_filename, env, &error_handler, &module); + return ReadModule(module_filename, env, &error_handler, &module); } default: @@ -992,32 +987,32 @@ static wabt::Result read_invalid_module(Context* ctx, } } -static wabt::Result on_assert_malformed_command(Context* ctx, - string_view filename, - string_view text, - ModuleType module_type) { +static wabt::Result OnAssertMalformedCommand(Context* ctx, + string_view filename, + string_view text, + ModuleType module_type) { Environment env; - init_environment(&env); + InitEnvironment(&env); ctx->total++; std::string path = CreateModulePath(ctx, filename); - wabt::Result result = read_invalid_module(ctx, path.c_str(), &env, - module_type, "assert_malformed"); + wabt::Result result = ReadInvalidModule(ctx, path.c_str(), &env, module_type, + "assert_malformed"); if (Failed(result)) { ctx->passed++; result = wabt::Result::Ok; } else { - print_command_error(ctx, "expected module to be malformed: \"%s\"", - path.c_str()); + PrintCommandError(ctx, "expected module to be malformed: \"%s\"", + path.c_str()); result = wabt::Result::Error; } return result; } -static wabt::Result on_register_command(Context* ctx, - string_view name, - string_view as) { +static wabt::Result OnRegisterCommand(Context* ctx, + string_view name, + string_view as) { Index module_index; if (!name.empty()) { module_index = ctx->env.FindModuleIndex(name); @@ -1026,7 +1021,7 @@ static wabt::Result on_register_command(Context* ctx, } if (module_index == kInvalidIndex) { - print_command_error(ctx, "unknown module in register"); + PrintCommandError(ctx, "unknown module in register"); return wabt::Result::Error; } @@ -1035,76 +1030,76 @@ static wabt::Result on_register_command(Context* ctx, return wabt::Result::Ok; } -static wabt::Result on_assert_unlinkable_command(Context* ctx, - string_view filename, - string_view text, - ModuleType module_type) { +static wabt::Result OnAssertUnlinkableCommand(Context* ctx, + string_view filename, + string_view text, + ModuleType module_type) { ctx->total++; std::string path = CreateModulePath(ctx, filename); Environment::MarkPoint mark = ctx->env.Mark(); - wabt::Result result = read_invalid_module(ctx, path.c_str(), &ctx->env, - module_type, "assert_unlinkable"); + wabt::Result result = ReadInvalidModule(ctx, path.c_str(), &ctx->env, + module_type, "assert_unlinkable"); ctx->env.ResetToMarkPoint(mark); if (Failed(result)) { ctx->passed++; result = wabt::Result::Ok; } else { - print_command_error(ctx, "expected module to be unlinkable: \"%s\"", - path.c_str()); + PrintCommandError(ctx, "expected module to be unlinkable: \"%s\"", + path.c_str()); result = wabt::Result::Error; } return result; } -static wabt::Result on_assert_invalid_command(Context* ctx, - string_view filename, - string_view text, - ModuleType module_type) { +static wabt::Result OnAssertInvalidCommand(Context* ctx, + string_view filename, + string_view text, + ModuleType module_type) { Environment env; - init_environment(&env); + InitEnvironment(&env); ctx->total++; std::string path = CreateModulePath(ctx, filename); - wabt::Result result = read_invalid_module(ctx, path.c_str(), &env, - module_type, "assert_invalid"); + wabt::Result result = + ReadInvalidModule(ctx, path.c_str(), &env, module_type, "assert_invalid"); if (Failed(result)) { ctx->passed++; result = wabt::Result::Ok; } else { - print_command_error(ctx, "expected module to be invalid: \"%s\"", - path.c_str()); + PrintCommandError(ctx, "expected module to be invalid: \"%s\"", + path.c_str()); result = wabt::Result::Error; } return result; } -static wabt::Result on_assert_uninstantiable_command(Context* ctx, - string_view filename, - string_view text, - ModuleType module_type) { +static wabt::Result OnAssertUninstantiableCommand(Context* ctx, + string_view filename, + string_view text, + ModuleType module_type) { ErrorHandlerFile error_handler(Location::Type::Binary); ctx->total++; std::string path = CreateModulePath(ctx, filename); DefinedModule* module; Environment::MarkPoint mark = ctx->env.Mark(); wabt::Result result = - read_module(path.c_str(), &ctx->env, &error_handler, &module); + ReadModule(path.c_str(), &ctx->env, &error_handler, &module); if (Succeeded(result)) { - interpreter::Result iresult = run_start_function(&ctx->thread, module); + interpreter::Result iresult = RunStartFunction(&ctx->thread, module); if (iresult == interpreter::Result::Ok) { - print_command_error(ctx, "expected error running start function: \"%s\"", - path.c_str()); + PrintCommandError(ctx, "expected error running start function: \"%s\"", + path.c_str()); result = wabt::Result::Error; } else { ctx->passed++; result = wabt::Result::Ok; } } else { - print_command_error(ctx, "error reading module: \"%s\"", path.c_str()); + PrintCommandError(ctx, "error reading module: \"%s\"", path.c_str()); result = wabt::Result::Error; } @@ -1112,8 +1107,7 @@ static wabt::Result on_assert_uninstantiable_command(Context* ctx, return result; } -static bool typed_values_are_equal(const TypedValue* tv1, - const TypedValue* tv2) { +static bool TypedValuesAreEqual(const TypedValue* tv1, const TypedValue* tv2) { if (tv1->type != tv2->type) return false; @@ -1132,7 +1126,7 @@ static bool typed_values_are_equal(const TypedValue* tv1, } } -static wabt::Result on_assert_return_command( +static wabt::Result OnAssertReturnCommand( Context* ctx, Action* action, const std::vector<TypedValue>& expected) { @@ -1141,7 +1135,7 @@ static wabt::Result on_assert_return_command( ctx->total++; wabt::Result result = - run_action(ctx, action, &iresult, &results, RunVerbosity::Quiet); + RunAction(ctx, action, &iresult, &results, RunVerbosity::Quiet); if (Succeeded(result)) { if (iresult == interpreter::Result::Ok) { @@ -1149,20 +1143,20 @@ static wabt::Result on_assert_return_command( for (size_t i = 0; i < results.size(); ++i) { const TypedValue* expected_tv = &expected[i]; const TypedValue* actual_tv = &results[i]; - if (!typed_values_are_equal(expected_tv, actual_tv)) { + if (!TypedValuesAreEqual(expected_tv, actual_tv)) { char expected_str[MAX_TYPED_VALUE_CHARS]; char actual_str[MAX_TYPED_VALUE_CHARS]; - sprint_typed_value(expected_str, sizeof(expected_str), expected_tv); - sprint_typed_value(actual_str, sizeof(actual_str), actual_tv); - print_command_error(ctx, - "mismatch in result %" PRIzd - " of assert_return: expected %s, got %s", - i, expected_str, actual_str); + SPrintTypedValue(expected_str, sizeof(expected_str), expected_tv); + SPrintTypedValue(actual_str, sizeof(actual_str), actual_tv); + PrintCommandError(ctx, + "mismatch in result %" PRIzd + " of assert_return: expected %s, got %s", + i, expected_str, actual_str); result = wabt::Result::Error; } } } else { - print_command_error( + PrintCommandError( ctx, "result length mismatch in assert_return: expected %" PRIzd ", got %" PRIzd, @@ -1170,8 +1164,8 @@ static wabt::Result on_assert_return_command( result = wabt::Result::Error; } } else { - print_command_error(ctx, "unexpected trap: %s", - s_trap_strings[static_cast<size_t>(iresult)]); + PrintCommandError(ctx, "unexpected trap: %s", + s_trap_strings[static_cast<size_t>(iresult)]); result = wabt::Result::Error; } } @@ -1182,20 +1176,20 @@ static wabt::Result on_assert_return_command( return result; } -static wabt::Result on_assert_return_nan_command(Context* ctx, - Action* action, - bool canonical) { +static wabt::Result OnAssertReturnNanCommand(Context* ctx, + Action* action, + bool canonical) { std::vector<TypedValue> results; interpreter::Result iresult; ctx->total++; wabt::Result result = - run_action(ctx, action, &iresult, &results, RunVerbosity::Quiet); + RunAction(ctx, action, &iresult, &results, RunVerbosity::Quiet); if (Succeeded(result)) { if (iresult == interpreter::Result::Ok) { if (results.size() != 1) { - print_command_error(ctx, "expected one result, got %" PRIzd, - results.size()); + PrintCommandError(ctx, "expected one result, got %" PRIzd, + results.size()); result = wabt::Result::Error; } @@ -1206,9 +1200,9 @@ static wabt::Result on_assert_return_nan_command(Context* ctx, : IsArithmeticNan(actual.value.f32_bits); if (!is_nan) { char actual_str[MAX_TYPED_VALUE_CHARS]; - sprint_typed_value(actual_str, sizeof(actual_str), &actual); - print_command_error(ctx, "expected result to be nan, got %s", - actual_str); + SPrintTypedValue(actual_str, sizeof(actual_str), &actual); + PrintCommandError(ctx, "expected result to be nan, got %s", + actual_str); result = wabt::Result::Error; } break; @@ -1219,24 +1213,24 @@ static wabt::Result on_assert_return_nan_command(Context* ctx, : IsArithmeticNan(actual.value.f64_bits); if (!is_nan) { char actual_str[MAX_TYPED_VALUE_CHARS]; - sprint_typed_value(actual_str, sizeof(actual_str), &actual); - print_command_error(ctx, "expected result to be nan, got %s", - actual_str); + SPrintTypedValue(actual_str, sizeof(actual_str), &actual); + PrintCommandError(ctx, "expected result to be nan, got %s", + actual_str); result = wabt::Result::Error; } break; } default: - print_command_error(ctx, - "expected result type to be f32 or f64, got %s", - get_type_name(actual.type)); + PrintCommandError(ctx, + "expected result type to be f32 or f64, got %s", + GetTypeName(actual.type)); result = wabt::Result::Error; break; } } else { - print_command_error(ctx, "unexpected trap: %s", - s_trap_strings[static_cast<int>(iresult)]); + PrintCommandError(ctx, "unexpected trap: %s", + s_trap_strings[static_cast<int>(iresult)]); result = wabt::Result::Error; } } @@ -1247,21 +1241,21 @@ static wabt::Result on_assert_return_nan_command(Context* ctx, return wabt::Result::Ok; } -static wabt::Result on_assert_trap_command(Context* ctx, - Action* action, - string_view text) { +static wabt::Result OnAssertTrapCommand(Context* ctx, + Action* action, + string_view text) { std::vector<TypedValue> results; interpreter::Result iresult; ctx->total++; wabt::Result result = - run_action(ctx, action, &iresult, &results, RunVerbosity::Quiet); + RunAction(ctx, action, &iresult, &results, RunVerbosity::Quiet); if (Succeeded(result)) { if (iresult != interpreter::Result::Ok) { ctx->passed++; } else { - print_command_error(ctx, "expected trap: \"" PRIstringview "\"", - WABT_PRINTF_STRING_VIEW_ARG(text)); + PrintCommandError(ctx, "expected trap: \"" PRIstringview "\"", + WABT_PRINTF_STRING_VIEW_ARG(text)); result = wabt::Result::Error; } } @@ -1269,19 +1263,19 @@ static wabt::Result on_assert_trap_command(Context* ctx, return result; } -static wabt::Result on_assert_exhaustion_command(Context* ctx, Action* action) { +static wabt::Result OnAssertExhaustionCommand(Context* ctx, Action* action) { std::vector<TypedValue> results; interpreter::Result iresult; ctx->total++; wabt::Result result = - run_action(ctx, action, &iresult, &results, RunVerbosity::Quiet); + RunAction(ctx, action, &iresult, &results, RunVerbosity::Quiet); if (Succeeded(result)) { if (iresult == interpreter::Result::TrapCallStackExhausted || iresult == interpreter::Result::TrapValueStackExhausted) { ctx->passed++; } else { - print_command_error(ctx, "expected call stack exhaustion"); + PrintCommandError(ctx, "expected call stack exhaustion"); result = wabt::Result::Error; } } @@ -1289,203 +1283,203 @@ static wabt::Result on_assert_exhaustion_command(Context* ctx, Action* action) { return result; } -static wabt::Result parse_command(Context* ctx) { +static wabt::Result ParseCommand(Context* ctx) { EXPECT("{"); EXPECT_KEY("type"); - if (match(ctx, "\"module\"")) { + if (Match(ctx, "\"module\"")) { std::string name; std::string filename; EXPECT(","); - CHECK_RESULT(parse_line(ctx)); + CHECK_RESULT(ParseLine(ctx)); EXPECT(","); - CHECK_RESULT(parse_opt_name_string_value(ctx, &name)); + CHECK_RESULT(ParseOptNameStringValue(ctx, &name)); PARSE_KEY_STRING_VALUE("filename", &filename); - on_module_command(ctx, filename, name); - } else if (match(ctx, "\"action\"")) { + OnModuleCommand(ctx, filename, name); + } else if (Match(ctx, "\"action\"")) { Action action; EXPECT(","); - CHECK_RESULT(parse_line(ctx)); + CHECK_RESULT(ParseLine(ctx)); EXPECT(","); - CHECK_RESULT(parse_action(ctx, &action)); - on_action_command(ctx, &action); - } else if (match(ctx, "\"register\"")) { + CHECK_RESULT(ParseAction(ctx, &action)); + OnActionCommand(ctx, &action); + } else if (Match(ctx, "\"register\"")) { std::string as; std::string name; EXPECT(","); - CHECK_RESULT(parse_line(ctx)); + CHECK_RESULT(ParseLine(ctx)); EXPECT(","); - CHECK_RESULT(parse_opt_name_string_value(ctx, &name)); + CHECK_RESULT(ParseOptNameStringValue(ctx, &name)); PARSE_KEY_STRING_VALUE("as", &as); - on_register_command(ctx, name, as); - } else if (match(ctx, "\"assert_malformed\"")) { + OnRegisterCommand(ctx, name, as); + } else if (Match(ctx, "\"assert_malformed\"")) { std::string filename; std::string text; ModuleType module_type; EXPECT(","); - CHECK_RESULT(parse_line(ctx)); + CHECK_RESULT(ParseLine(ctx)); EXPECT(","); PARSE_KEY_STRING_VALUE("filename", &filename); EXPECT(","); PARSE_KEY_STRING_VALUE("text", &text); EXPECT(","); - CHECK_RESULT(parse_module_type(ctx, &module_type)); - on_assert_malformed_command(ctx, filename, text, module_type); - } else if (match(ctx, "\"assert_invalid\"")) { + CHECK_RESULT(ParseModuleType(ctx, &module_type)); + OnAssertMalformedCommand(ctx, filename, text, module_type); + } else if (Match(ctx, "\"assert_invalid\"")) { std::string filename; std::string text; ModuleType module_type; EXPECT(","); - CHECK_RESULT(parse_line(ctx)); + CHECK_RESULT(ParseLine(ctx)); EXPECT(","); PARSE_KEY_STRING_VALUE("filename", &filename); EXPECT(","); PARSE_KEY_STRING_VALUE("text", &text); EXPECT(","); - CHECK_RESULT(parse_module_type(ctx, &module_type)); - on_assert_invalid_command(ctx, filename, text, module_type); - } else if (match(ctx, "\"assert_unlinkable\"")) { + CHECK_RESULT(ParseModuleType(ctx, &module_type)); + OnAssertInvalidCommand(ctx, filename, text, module_type); + } else if (Match(ctx, "\"assert_unlinkable\"")) { std::string filename; std::string text; ModuleType module_type; EXPECT(","); - CHECK_RESULT(parse_line(ctx)); + CHECK_RESULT(ParseLine(ctx)); EXPECT(","); PARSE_KEY_STRING_VALUE("filename", &filename); EXPECT(","); PARSE_KEY_STRING_VALUE("text", &text); EXPECT(","); - CHECK_RESULT(parse_module_type(ctx, &module_type)); - on_assert_unlinkable_command(ctx, filename, text, module_type); - } else if (match(ctx, "\"assert_uninstantiable\"")) { + CHECK_RESULT(ParseModuleType(ctx, &module_type)); + OnAssertUnlinkableCommand(ctx, filename, text, module_type); + } else if (Match(ctx, "\"assert_uninstantiable\"")) { std::string filename; std::string text; ModuleType module_type; EXPECT(","); - CHECK_RESULT(parse_line(ctx)); + CHECK_RESULT(ParseLine(ctx)); EXPECT(","); PARSE_KEY_STRING_VALUE("filename", &filename); EXPECT(","); PARSE_KEY_STRING_VALUE("text", &text); EXPECT(","); - CHECK_RESULT(parse_module_type(ctx, &module_type)); - on_assert_uninstantiable_command(ctx, filename, text, module_type); - } else if (match(ctx, "\"assert_return\"")) { + CHECK_RESULT(ParseModuleType(ctx, &module_type)); + OnAssertUninstantiableCommand(ctx, filename, text, module_type); + } else if (Match(ctx, "\"assert_return\"")) { Action action; std::vector<TypedValue> expected; EXPECT(","); - CHECK_RESULT(parse_line(ctx)); + CHECK_RESULT(ParseLine(ctx)); EXPECT(","); - CHECK_RESULT(parse_action(ctx, &action)); + CHECK_RESULT(ParseAction(ctx, &action)); EXPECT(","); EXPECT_KEY("expected"); - CHECK_RESULT(parse_const_vector(ctx, &expected)); - on_assert_return_command(ctx, &action, expected); - } else if (match(ctx, "\"assert_return_canonical_nan\"")) { + CHECK_RESULT(ParseConstVector(ctx, &expected)); + OnAssertReturnCommand(ctx, &action, expected); + } else if (Match(ctx, "\"assert_return_canonical_nan\"")) { Action action; TypeVector expected; EXPECT(","); - CHECK_RESULT(parse_line(ctx)); + CHECK_RESULT(ParseLine(ctx)); EXPECT(","); - CHECK_RESULT(parse_action(ctx, &action)); + CHECK_RESULT(ParseAction(ctx, &action)); EXPECT(","); /* Not needed for wabt-interp, but useful for other parsers. */ EXPECT_KEY("expected"); - CHECK_RESULT(parse_type_vector(ctx, &expected)); - on_assert_return_nan_command(ctx, &action, true); - } else if (match(ctx, "\"assert_return_arithmetic_nan\"")) { + CHECK_RESULT(ParseTypeVector(ctx, &expected)); + OnAssertReturnNanCommand(ctx, &action, true); + } else if (Match(ctx, "\"assert_return_arithmetic_nan\"")) { Action action; TypeVector expected; EXPECT(","); - CHECK_RESULT(parse_line(ctx)); + CHECK_RESULT(ParseLine(ctx)); EXPECT(","); - CHECK_RESULT(parse_action(ctx, &action)); + CHECK_RESULT(ParseAction(ctx, &action)); EXPECT(","); /* Not needed for wabt-interp, but useful for other parsers. */ EXPECT_KEY("expected"); - CHECK_RESULT(parse_type_vector(ctx, &expected)); - on_assert_return_nan_command(ctx, &action, false); - } else if (match(ctx, "\"assert_trap\"")) { + CHECK_RESULT(ParseTypeVector(ctx, &expected)); + OnAssertReturnNanCommand(ctx, &action, false); + } else if (Match(ctx, "\"assert_trap\"")) { Action action; std::string text; EXPECT(","); - CHECK_RESULT(parse_line(ctx)); + CHECK_RESULT(ParseLine(ctx)); EXPECT(","); - CHECK_RESULT(parse_action(ctx, &action)); + CHECK_RESULT(ParseAction(ctx, &action)); EXPECT(","); PARSE_KEY_STRING_VALUE("text", &text); - on_assert_trap_command(ctx, &action, text); - } else if (match(ctx, "\"assert_exhaustion\"")) { + OnAssertTrapCommand(ctx, &action, text); + } else if (Match(ctx, "\"assert_exhaustion\"")) { Action action; std::string text; EXPECT(","); - CHECK_RESULT(parse_line(ctx)); + CHECK_RESULT(ParseLine(ctx)); EXPECT(","); - CHECK_RESULT(parse_action(ctx, &action)); - on_assert_exhaustion_command(ctx, &action); + CHECK_RESULT(ParseAction(ctx, &action)); + OnAssertExhaustionCommand(ctx, &action); } else { - print_command_error(ctx, "unknown command type"); + PrintCommandError(ctx, "unknown command type"); return wabt::Result::Error; } EXPECT("}"); return wabt::Result::Ok; } -static wabt::Result parse_commands(Context* ctx) { +static wabt::Result ParseCommands(Context* ctx) { EXPECT("{"); PARSE_KEY_STRING_VALUE("source_filename", &ctx->source_filename); EXPECT(","); EXPECT_KEY("commands"); EXPECT("["); bool first = true; - while (!match(ctx, "]")) { + while (!Match(ctx, "]")) { if (!first) EXPECT(","); - CHECK_RESULT(parse_command(ctx)); + CHECK_RESULT(ParseCommand(ctx)); first = false; } EXPECT("}"); return wabt::Result::Ok; } -static wabt::Result read_and_run_spec_json(const char* spec_json_filename) { +static wabt::Result ReadAndRunSpecJson(const char* spec_json_filename) { Context ctx; ctx.loc.filename = spec_json_filename; ctx.loc.line = 1; ctx.loc.first_column = 1; - init_environment(&ctx.env); + InitEnvironment(&ctx.env); wabt::Result result = ReadFile(spec_json_filename, &ctx.json_data); if (Failed(result)) return wabt::Result::Error; - result = parse_commands(&ctx); + result = ParseCommands(&ctx); printf("%d/%d tests passed.\n", ctx.passed, ctx.total); return result; } int ProgramMain(int argc, char** argv) { - init_stdio(); - parse_options(argc, argv); + InitStdio(); + ParseOptions(argc, argv); s_stdout_stream = FileStream::CreateStdout(); wabt::Result result; if (s_spec) { - result = read_and_run_spec_json(s_infile); + result = ReadAndRunSpecJson(s_infile); } else { - result = read_and_run_module(s_infile); + result = ReadAndRunModule(s_infile); } return result != wabt::Result::Ok; } diff --git a/src/tools/wasm-link.cc b/src/tools/wasm-link.cc index 89cc73ad..471b90c5 100644 --- a/src/tools/wasm-link.cc +++ b/src/tools/wasm-link.cc @@ -53,7 +53,7 @@ struct Context { ssize_t current_section_payload_offset = 0; }; -static void parse_options(int argc, char** argv) { +static void ParseOptions(int argc, char** argv) { OptionParser parser("wasm-link", s_description); parser.AddOption("debug", @@ -164,8 +164,8 @@ static void apply_relocation(Section* section, Reloc* r) { size_t section_size = section->size; Index cur_value = 0, new_value = 0; - read_u32_leb128(section_data + r->offset, section_data + section_size, - &cur_value); + ReadU32Leb128(section_data + r->offset, section_data + section_size, + &cur_value); switch (r->type) { case RelocType::FuncIndexLEB: @@ -181,20 +181,19 @@ static void apply_relocation(Section* section, Reloc* r) { new_value = binary->RelocateGlobalIndex(cur_value); break; default: - WABT_FATAL("unhandled relocation type: %s\n", - get_reloc_type_name(r->type)); + WABT_FATAL("unhandled relocation type: %s\n", GetRelocTypeName(r->type)); break; } - write_fixed_u32_leb128_raw(section_data + r->offset, - section_data + section_size, new_value); + WriteFixedU32Leb128Raw(section_data + r->offset, section_data + section_size, + new_value); } static void apply_relocations(Section* section) { if (!section->relocations.size()) return; - LOG_DEBUG("apply_relocations: %s\n", get_section_name(section->section_code)); + LOG_DEBUG("apply_relocations: %s\n", GetSectionName(section->section_code)); /* Perform relocations in-place */ for (Reloc& reloc: section->relocations) { @@ -215,13 +214,13 @@ static void write_section_payload(Context* ctx, Section* sec) { #define WRITE_UNKNOWN_SIZE(STREAM) \ { \ Offset fixup_offset = (STREAM)->offset(); \ - write_fixed_u32_leb128(STREAM, 0, "unknown size"); \ + WriteFixedU32Leb128(STREAM, 0, "unknown size"); \ ctx->current_section_payload_offset = (STREAM)->offset(); \ Offset start = (STREAM)->offset(); -#define FIXUP_SIZE(STREAM) \ - write_fixed_u32_leb128_at(STREAM, fixup_offset, (STREAM)->offset() - start, \ - "fixup size"); \ +#define FIXUP_SIZE(STREAM) \ + WriteFixedU32Leb128At(STREAM, fixup_offset, (STREAM)->offset() - start, \ + "fixup size"); \ } static void write_table_section(Context* ctx, @@ -238,11 +237,11 @@ static void write_table_section(Context* ctx, Stream* stream = &ctx->stream; WRITE_UNKNOWN_SIZE(stream); - write_u32_leb128(stream, table_count, "table count"); - write_type(stream, Type::Anyfunc); - write_u32_leb128(stream, flags, "table elem flags"); - write_u32_leb128(stream, elem_count, "table initial length"); - write_u32_leb128(stream, elem_count, "table max length"); + WriteU32Leb128(stream, table_count, "table count"); + WriteType(stream, Type::Anyfunc); + WriteU32Leb128(stream, flags, "table elem flags"); + WriteU32Leb128(stream, elem_count, "table initial length"); + WriteU32Leb128(stream, elem_count, "table max length"); FIXUP_SIZE(stream); } @@ -254,11 +253,11 @@ static void write_export_section(Context* ctx) { Stream* stream = &ctx->stream; WRITE_UNKNOWN_SIZE(stream); - write_u32_leb128(stream, total_exports, "export count"); + WriteU32Leb128(stream, total_exports, "export count"); for (const std::unique_ptr<LinkerInputBinary>& binary : ctx->inputs) { for (const Export& export_ : binary->exports) { - write_str(stream, export_.name, "export name"); + WriteStr(stream, export_.name, "export name"); stream->WriteU8Enum(export_.kind, "export kind"); Index index = export_.index; switch (export_.kind) { @@ -270,7 +269,7 @@ static void write_export_section(Context* ctx) { static_cast<int>(export_.kind)); break; } - write_u32_leb128(stream, index, "export index"); + WriteU32Leb128(stream, index, "export index"); } } FIXUP_SIZE(stream); @@ -286,12 +285,12 @@ static void write_elem_section(Context* ctx, total_elem_count += section->binary->table_elem_count; } - write_u32_leb128(stream, 1, "segment count"); - write_u32_leb128(stream, 0, "table index"); - write_opcode(&ctx->stream, Opcode::I32Const); - write_i32_leb128(&ctx->stream, 0, "elem init literal"); - write_opcode(&ctx->stream, Opcode::End); - write_u32_leb128(stream, total_elem_count, "num elements"); + WriteU32Leb128(stream, 1, "segment count"); + WriteU32Leb128(stream, 0, "table index"); + WriteOpcode(&ctx->stream, Opcode::I32Const); + WriteI32Leb128(&ctx->stream, 0, "elem init literal"); + WriteOpcode(&ctx->stream, Opcode::End); + WriteU32Leb128(stream, total_elem_count, "num elements"); ctx->current_section_payload_offset = stream->offset(); @@ -308,7 +307,7 @@ static void write_memory_section(Context* ctx, Stream* stream = &ctx->stream; WRITE_UNKNOWN_SIZE(stream); - write_u32_leb128(stream, 1, "memory count"); + WriteU32Leb128(stream, 1, "memory count"); Limits limits; ZeroMemory(limits); @@ -318,7 +317,7 @@ static void write_memory_section(Context* ctx, limits.initial += sec->data.memory_limits.initial; } limits.max = limits.initial; - write_limits(stream, &limits); + WriteLimits(stream, &limits); FIXUP_SIZE(stream); } @@ -326,18 +325,18 @@ static void write_memory_section(Context* ctx, static void write_function_import(Context* ctx, FunctionImport* import, Index offset) { - write_str(&ctx->stream, import->module_name, "import module name"); - write_str(&ctx->stream, import->name, "import field name"); + WriteStr(&ctx->stream, import->module_name, "import module name"); + WriteStr(&ctx->stream, import->name, "import field name"); ctx->stream.WriteU8Enum(ExternalKind::Func, "import kind"); - write_u32_leb128(&ctx->stream, import->sig_index + offset, - "import signature index"); + WriteU32Leb128(&ctx->stream, import->sig_index + offset, + "import signature index"); } static void write_global_import(Context* ctx, GlobalImport* import) { - write_str(&ctx->stream, import->module_name, "import module name"); - write_str(&ctx->stream, import->name, "import field name"); + WriteStr(&ctx->stream, import->module_name, "import module name"); + WriteStr(&ctx->stream, import->name, "import field name"); ctx->stream.WriteU8Enum(ExternalKind::Global, "import kind"); - write_type(&ctx->stream, import->type); + WriteType(&ctx->stream, import->type); ctx->stream.WriteU8(import->mutable_, "global mutability"); } @@ -355,7 +354,7 @@ static void write_import_section(Context* ctx) { } WRITE_UNKNOWN_SIZE(&ctx->stream); - write_u32_leb128(&ctx->stream, num_imports, "num imports"); + WriteU32Leb128(&ctx->stream, num_imports, "num imports"); for (size_t i = 0; i < ctx->inputs.size(); i++) { LinkerInputBinary* binary = ctx->inputs[i].get(); @@ -381,7 +380,7 @@ static void write_function_section(Context* ctx, Stream* stream = &ctx->stream; WRITE_UNKNOWN_SIZE(stream); - write_u32_leb128(stream, total_count, "function count"); + WriteU32Leb128(stream, total_count, "function count"); for (size_t i = 0; i < sections.size(); i++) { Section* sec = sections[i]; @@ -392,9 +391,8 @@ static void write_function_section(Context* ctx, const uint8_t* end = &sec->binary->data[sec->payload_offset + sec->payload_size]; while (count--) { - input_offset += read_u32_leb128(start + input_offset, end, &sig_index); - write_u32_leb128(stream, sec->binary->RelocateTypeIndex(sig_index), - "sig"); + input_offset += ReadU32Leb128(start + input_offset, end, &sig_index); + WriteU32Leb128(stream, sec->binary->RelocateTypeIndex(sig_index), "sig"); } } @@ -405,11 +403,11 @@ static void write_data_segment(Stream* stream, const DataSegment& segment, Address offset) { 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_opcode(stream, Opcode::End); - write_u32_leb128(stream, segment.size, "segment size"); + WriteU32Leb128(stream, segment.memory_index, "memory index"); + WriteOpcode(stream, Opcode::I32Const); + WriteU32Leb128(stream, segment.offset + offset, "offset"); + WriteOpcode(stream, Opcode::End); + WriteU32Leb128(stream, segment.size, "segment size"); stream->WriteData(segment.data, segment.size, "segment data"); } @@ -419,7 +417,7 @@ static void write_data_section(Context* ctx, Stream* stream = &ctx->stream; WRITE_UNKNOWN_SIZE(stream); - write_u32_leb128(stream, total_count, "data segment count"); + WriteU32Leb128(stream, total_count, "data segment count"); for (size_t i = 0; i < sections.size(); i++) { Section* sec = sections[i]; for (size_t j = 0; j < sec->data.data_segments->size(); j++) { @@ -450,11 +448,11 @@ static void write_names_section(Context* ctx) { Stream* stream = &ctx->stream; stream->WriteU8Enum(BinarySection::Custom, "section code"); WRITE_UNKNOWN_SIZE(stream); - write_str(stream, "name", "custom section name"); + WriteStr(stream, "name", "custom section name"); stream->WriteU8Enum(NameSectionSubsection::Function, "subsection code"); WRITE_UNKNOWN_SIZE(stream); - write_u32_leb128(stream, total_count, "element count"); + WriteU32Leb128(stream, total_count, "element count"); // Write import names for (const std::unique_ptr<LinkerInputBinary>& binary: ctx->inputs) { @@ -463,8 +461,8 @@ static void write_names_section(Context* ctx) { continue; if (binary->IsInactiveFunctionImport(i)) continue; - write_u32_leb128(stream, binary->RelocateFuncIndex(i), "function index"); - write_str(stream, binary->debug_names[i], "function name"); + WriteU32Leb128(stream, binary->RelocateFuncIndex(i), "function index"); + WriteStr(stream, binary->debug_names[i], "function name"); } } @@ -473,8 +471,8 @@ static void write_names_section(Context* ctx) { for (size_t i = 0; i < binary->debug_names.size(); i++) { if (binary->debug_names[i].empty() || binary->IsFunctionImport(i)) continue; - write_u32_leb128(stream, binary->RelocateFuncIndex(i), "function index"); - write_str(stream, binary->debug_names[i], "function name"); + WriteU32Leb128(stream, binary->RelocateFuncIndex(i), "function index"); + WriteStr(stream, binary->debug_names[i], "function name"); } } @@ -497,20 +495,20 @@ static void write_reloc_section(Context* ctx, char section_name[128]; snprintf(section_name, sizeof(section_name), "%s.%s", - WABT_BINARY_SECTION_RELOC, get_section_name(section_code)); + WABT_BINARY_SECTION_RELOC, GetSectionName(section_code)); Stream* stream = &ctx->stream; stream->WriteU8Enum(BinarySection::Custom, "section code"); WRITE_UNKNOWN_SIZE(stream); - write_str(stream, section_name, "reloc section name"); - write_u32_leb128_enum(&ctx->stream, section_code, "reloc section"); - write_u32_leb128(&ctx->stream, total_relocs, "num relocs"); + WriteStr(stream, section_name, "reloc section name"); + WriteU32Leb128Enum(&ctx->stream, section_code, "reloc section"); + WriteU32Leb128(&ctx->stream, total_relocs, "num relocs"); for (Section* sec: sections) { for (const Reloc& reloc: sec->relocations) { - write_u32_leb128_enum(&ctx->stream, reloc.type, "reloc type"); + WriteU32Leb128Enum(&ctx->stream, reloc.type, "reloc type"); Offset new_offset = reloc.offset + sec->output_payload_offset; - write_u32_leb128(&ctx->stream, new_offset, "reloc offset"); + WriteU32Leb128(&ctx->stream, new_offset, "reloc offset"); Index relocated_index; switch (reloc.type) { case RelocType::FuncIndexLEB: @@ -524,10 +522,11 @@ static void write_reloc_section(Context* ctx, break; // TODO(sbc): Handle other relocation types. default: - WABT_FATAL("Unhandled reloc type: %s\n", get_reloc_type_name(reloc.type)); + WABT_FATAL("Unhandled reloc type: %s\n", + GetRelocTypeName(reloc.type)); break; } - write_u32_leb128(&ctx->stream, relocated_index, "reloc index"); + WriteU32Leb128(&ctx->stream, relocated_index, "reloc index"); } } @@ -542,7 +541,7 @@ static bool write_combined_section(Context* ctx, 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)); + GetSectionName(section_code)); } Index total_count = 0; @@ -581,12 +580,12 @@ static bool write_combined_section(Context* ctx, break; default: { /* Total section size includes the element count leb128. */ - total_size += u32_leb128_length(total_count); + total_size += U32Leb128Length(total_count); /* Write section to stream */ Stream* stream = &ctx->stream; - write_u32_leb128(stream, total_size, "section size"); - write_u32_leb128(stream, total_count, "element count"); + WriteU32Leb128(stream, total_size, "section size"); + WriteU32Leb128(stream, total_count, "element count"); ctx->current_section_payload_offset = ctx->stream.offset(); for (Section* sec: sections) { apply_relocations(sec); @@ -781,11 +780,11 @@ static Result perform_link(Context* ctx) { } int ProgramMain(int argc, char** argv) { - init_stdio(); + InitStdio(); Context context; - parse_options(argc, argv); + ParseOptions(argc, argv); Result result = Result::Ok; for (size_t i = 0; i < s_infiles.size(); i++) { @@ -801,7 +800,7 @@ int ProgramMain(int argc, char** argv) { LinkOptions options = { NULL }; if (s_debug) options.log_stream = s_log_stream.get(); - result = read_binary_linker(b, &options); + result = ReadBinaryLinker(b, &options); if (Failed(result)) WABT_FATAL("error parsing file: %s\n", input_filename.c_str()); } diff --git a/src/tools/wasm-objdump.cc b/src/tools/wasm-objdump.cc index 94d80a79..bb08cf88 100644 --- a/src/tools/wasm-objdump.cc +++ b/src/tools/wasm-objdump.cc @@ -40,7 +40,7 @@ static std::vector<const char*> s_infiles; static std::unique_ptr<FileStream> s_log_stream; -static void parse_options(int argc, char** argv) { +static void ParseOptions(int argc, char** argv) { OptionParser parser("wasm-objdump", s_description); parser.AddOption('h', "headers", "Print headers", @@ -91,7 +91,7 @@ Result dump_file(const char* filename) { // Pass 0: Prepass s_objdump_options.mode = ObjdumpMode::Prepass; - result = read_binary_objdump(data, size, &s_objdump_options, &state); + result = ReadBinaryObjdump(data, size, &s_objdump_options, &state); if (Failed(result)) return result; s_objdump_options.log_stream = nullptr; @@ -99,7 +99,7 @@ Result dump_file(const char* filename) { // Pass 1: Print the section headers if (s_objdump_options.headers) { s_objdump_options.mode = ObjdumpMode::Headers; - result = read_binary_objdump(data, size, &s_objdump_options, &state); + result = ReadBinaryObjdump(data, size, &s_objdump_options, &state); if (Failed(result)) return result; } @@ -107,7 +107,7 @@ Result dump_file(const char* filename) { // Pass 2: Print extra information based on section type if (s_objdump_options.details) { s_objdump_options.mode = ObjdumpMode::Details; - result = read_binary_objdump(data, size, &s_objdump_options, &state); + result = ReadBinaryObjdump(data, size, &s_objdump_options, &state); if (Failed(result)) return result; } @@ -115,7 +115,7 @@ Result dump_file(const char* filename) { // Pass 3: Disassemble code section if (s_objdump_options.disassemble) { s_objdump_options.mode = ObjdumpMode::Disassemble; - result = read_binary_objdump(data, size, &s_objdump_options, &state); + result = ReadBinaryObjdump(data, size, &s_objdump_options, &state); if (Failed(result)) return result; } @@ -123,16 +123,16 @@ Result dump_file(const char* filename) { // Pass 4: Dump to raw contents of the sections if (s_objdump_options.raw) { s_objdump_options.mode = ObjdumpMode::RawData; - result = read_binary_objdump(data, size, &s_objdump_options, &state); + result = ReadBinaryObjdump(data, size, &s_objdump_options, &state); } return result; } int ProgramMain(int argc, char** argv) { - init_stdio(); + InitStdio(); - parse_options(argc, argv); + ParseOptions(argc, argv); if (!s_objdump_options.headers && !s_objdump_options.details && !s_objdump_options.disassemble && !s_objdump_options.raw) { fprintf(stderr, "At least one of the following switches must be given:\n"); diff --git a/src/tools/wasm-opcodecnt.cc b/src/tools/wasm-opcodecnt.cc index 9e09ac35..417429b2 100644 --- a/src/tools/wasm-opcodecnt.cc +++ b/src/tools/wasm-opcodecnt.cc @@ -49,7 +49,7 @@ examples: $ wasm-opcodecnt test.wasm -o test.dist )"; -static void parse_options(int argc, char** argv) { +static void ParseOptions(int argc, char** argv) { OptionParser parser("wasm-opcodecnt", s_description); parser.AddOption('v', "verbose", "Use multiple times for more info", []() { @@ -83,18 +83,18 @@ typedef int(int_pair_counter_lt_fcn)(const IntPairCounter&, typedef void (*display_name_fcn)(FILE* out, intmax_t value); -static void display_opcode_name(FILE* out, intmax_t opcode) { +static void DisplayOpcodeName(FILE* out, intmax_t opcode) { fprintf(out, "%s", Opcode(Opcode::Enum(opcode)).GetName()); } -static void display_intmax(FILE* out, intmax_t value) { +static void DisplayIntmax(FILE* out, intmax_t value) { fprintf(out, "%" PRIdMAX, value); } -static void display_int_counter_vector(FILE* out, - const IntCounterVector& vec, - display_name_fcn display_fcn, - const char* opcode_name) { +static void DisplayIntCounterVector(FILE* out, + const IntCounterVector& vec, + display_name_fcn display_fcn, + const char* opcode_name) { for (const IntCounter& counter : vec) { if (counter.count == 0) continue; @@ -107,11 +107,11 @@ static void display_int_counter_vector(FILE* out, } } -static void display_int_pair_counter_vector(FILE* out, - const IntPairCounterVector& vec, - display_name_fcn display_first_fcn, - display_name_fcn display_second_fcn, - const char* opcode_name) { +static void DisplayIntPairCounterVector(FILE* out, + const IntPairCounterVector& vec, + display_name_fcn display_first_fcn, + display_name_fcn display_second_fcn, + const char* opcode_name) { for (const IntPairCounter& pair : vec) { if (pair.count == 0) continue; @@ -126,8 +126,8 @@ static void display_int_pair_counter_vector(FILE* out, } } -static int opcode_counter_gt(const IntCounter& counter_1, - const IntCounter& counter_2) { +static int OpcodeCounterGt(const IntCounter& counter_1, + const IntCounter& counter_2) { if (counter_1.count > counter_2.count) return 1; if (counter_1.count < counter_2.count) @@ -140,8 +140,8 @@ static int opcode_counter_gt(const IntCounter& counter_1, return 0; } -static int int_counter_gt(const IntCounter& counter_1, - const IntCounter& counter_2) { +static int IntCounterGt(const IntCounter& counter_1, + const IntCounter& counter_2) { if (counter_1.count < counter_2.count) return 0; if (counter_1.count > counter_2.count) @@ -153,8 +153,8 @@ static int int_counter_gt(const IntCounter& counter_1, return 0; } -static int int_pair_counter_gt(const IntPairCounter& counter_1, - const IntPairCounter& counter_2) { +static int IntPairCounterGt(const IntPairCounter& counter_1, + const IntPairCounter& counter_2) { if (counter_1.count < counter_2.count) return 0; if (counter_1.count > counter_2.count) @@ -170,12 +170,12 @@ static int int_pair_counter_gt(const IntPairCounter& counter_1, return 0; } -static void display_sorted_int_counter_vector(FILE* out, - const char* title, - const IntCounterVector& vec, - int_counter_lt_fcn lt_fcn, - display_name_fcn display_fcn, - const char* opcode_name) { +static void DisplaySortedIntCounterVector(FILE* out, + const char* title, + const IntCounterVector& vec, + int_counter_lt_fcn lt_fcn, + display_name_fcn display_fcn, + const char* opcode_name) { if (vec.size() == 0) return; @@ -188,10 +188,10 @@ static void display_sorted_int_counter_vector(FILE* out, } std::sort(filtered_vec.begin(), filtered_vec.end(), lt_fcn); fprintf(out, "%s\n", title); - display_int_counter_vector(out, filtered_vec, display_fcn, opcode_name); + DisplayIntCounterVector(out, filtered_vec, display_fcn, opcode_name); } -static void display_sorted_int_pair_counter_vector( +static void DisplaySortedIntPairCounterVector( FILE* out, const char* title, const IntPairCounterVector& vec, @@ -210,13 +210,13 @@ static void display_sorted_int_pair_counter_vector( } std::sort(filtered_vec.begin(), filtered_vec.end(), lt_fcn); fprintf(out, "%s\n", title); - display_int_pair_counter_vector(out, filtered_vec, display_first_fcn, - display_second_fcn, opcode_name); + DisplayIntPairCounterVector(out, filtered_vec, display_first_fcn, + display_second_fcn, opcode_name); } int ProgramMain(int argc, char** argv) { - init_stdio(); - parse_options(argc, argv); + InitStdio(); + ParseOptions(argc, argv); std::vector<uint8_t> file_data; Result result = ReadFile(s_infile, &file_data); @@ -233,30 +233,30 @@ int ProgramMain(int argc, char** argv) { } if (Succeeded(result)) { OpcntData opcnt_data; - result = read_binary_opcnt(DataOrNull(file_data), file_data.size(), - &s_read_binary_options, &opcnt_data); + result = ReadBinaryOpcnt(DataOrNull(file_data), file_data.size(), + &s_read_binary_options, &opcnt_data); if (Succeeded(result)) { - display_sorted_int_counter_vector( - 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, - display_intmax, Opcode::I32Const_Opcode.GetName()); - display_sorted_int_counter_vector( - out, "\nget_local:", opcnt_data.get_local_vec, int_counter_gt, - display_intmax, Opcode::GetLocal_Opcode.GetName()); - display_sorted_int_counter_vector( - out, "\nset_local:", opcnt_data.set_local_vec, int_counter_gt, - display_intmax, Opcode::SetLocal_Opcode.GetName()); - display_sorted_int_counter_vector( - out, "\ntee_local:", opcnt_data.tee_local_vec, int_counter_gt, - display_intmax, Opcode::TeeLocal_Opcode.GetName()); - display_sorted_int_pair_counter_vector( - out, "\ni32.load:", opcnt_data.i32_load_vec, int_pair_counter_gt, - display_intmax, display_intmax, Opcode::I32Load_Opcode.GetName()); - display_sorted_int_pair_counter_vector( - out, "\ni32.store:", opcnt_data.i32_store_vec, int_pair_counter_gt, - display_intmax, display_intmax, Opcode::I32Store_Opcode.GetName()); + DisplaySortedIntCounterVector( + out, "Opcode counts:", opcnt_data.opcode_vec, OpcodeCounterGt, + DisplayOpcodeName, nullptr); + DisplaySortedIntCounterVector( + out, "\ni32.const:", opcnt_data.i32_const_vec, IntCounterGt, + DisplayIntmax, Opcode::I32Const_Opcode.GetName()); + DisplaySortedIntCounterVector( + out, "\nget_local:", opcnt_data.get_local_vec, IntCounterGt, + DisplayIntmax, Opcode::GetLocal_Opcode.GetName()); + DisplaySortedIntCounterVector( + out, "\nset_local:", opcnt_data.set_local_vec, IntCounterGt, + DisplayIntmax, Opcode::SetLocal_Opcode.GetName()); + DisplaySortedIntCounterVector( + out, "\ntee_local:", opcnt_data.tee_local_vec, IntCounterGt, + DisplayIntmax, Opcode::TeeLocal_Opcode.GetName()); + DisplaySortedIntPairCounterVector( + out, "\ni32.load:", opcnt_data.i32_load_vec, IntPairCounterGt, + DisplayIntmax, DisplayIntmax, Opcode::I32Load_Opcode.GetName()); + DisplaySortedIntPairCounterVector( + out, "\ni32.store:", opcnt_data.i32_store_vec, IntPairCounterGt, + DisplayIntmax, DisplayIntmax, Opcode::I32Store_Opcode.GetName()); } } return result != Result::Ok; diff --git a/src/tools/wasm2wast.cc b/src/tools/wasm2wast.cc index 90d9cbee..27409fb1 100644 --- a/src/tools/wasm2wast.cc +++ b/src/tools/wasm2wast.cc @@ -55,7 +55,7 @@ examples: $ wasm2wast test.wasm --no-debug-names -o test.wast )"; -static void parse_options(int argc, char** argv) { +static void ParseOptions(int argc, char** argv) { OptionParser parser("wasm2wast", s_description); parser.AddOption('v', "verbose", "Use multiple times for more info", []() { @@ -98,37 +98,37 @@ static void parse_options(int argc, char** argv) { int ProgramMain(int argc, char** argv) { Result result; - init_stdio(); - parse_options(argc, argv); + InitStdio(); + ParseOptions(argc, argv); std::vector<uint8_t> file_data; result = ReadFile(s_infile.c_str(), &file_data); if (Succeeded(result)) { ErrorHandlerFile error_handler(Location::Type::Binary); Module module; - result = read_binary_ir(s_infile.c_str(), DataOrNull(file_data), - file_data.size(), &s_read_binary_options, - &error_handler, &module); + result = + ReadBinaryIr(s_infile.c_str(), DataOrNull(file_data), file_data.size(), + &s_read_binary_options, &error_handler, &module); if (Succeeded(result)) { if (Succeeded(result) && s_validate) { WastLexer* lexer = nullptr; - result = validate_module(lexer, &module, &error_handler); + result = ValidateModule(lexer, &module, &error_handler); } if (s_generate_names) - result = generate_names(&module); + result = GenerateNames(&module); if (Succeeded(result)) { /* TODO(binji): This shouldn't fail; if a name can't be applied * (because the index is invalid, say) it should just be skipped. */ - Result dummy_result = apply_names(&module); + Result dummy_result = ApplyNames(&module); WABT_USE(dummy_result); } if (Succeeded(result)) { FileWriter writer(!s_outfile.empty() ? FileWriter(s_outfile.c_str()) : FileWriter(stdout)); - result = write_wat(&writer, &module, &s_write_wat_options); + result = WriteWat(&writer, &module, &s_write_wat_options); } } } diff --git a/src/tools/wast-desugar.cc b/src/tools/wast-desugar.cc index eb9aa42d..e388ea6b 100644 --- a/src/tools/wast-desugar.cc +++ b/src/tools/wast-desugar.cc @@ -54,7 +54,7 @@ examples: $ wast-desugar --generate-names test.wast )"; -static void parse_options(int argc, char** argv) { +static void ParseOptions(int argc, char** argv) { OptionParser parser("wast-desugar", s_description); parser.AddHelpOption(); @@ -78,8 +78,8 @@ static void parse_options(int argc, char** argv) { } int ProgramMain(int argc, char** argv) { - init_stdio(); - parse_options(argc, argv); + InitStdio(); + ParseOptions(argc, argv); std::unique_ptr<WastLexer> lexer(WastLexer::CreateFileLexer(s_infile)); if (!lexer) @@ -88,7 +88,7 @@ int ProgramMain(int argc, char** argv) { ErrorHandlerFile error_handler(Location::Type::Text); Script* script; Result result = - parse_wast(lexer.get(), &script, &error_handler, &s_parse_options); + ParseWast(lexer.get(), &script, &error_handler, &s_parse_options); if (Succeeded(result)) { Module* module = script->GetFirstModule(); @@ -96,14 +96,14 @@ int ProgramMain(int argc, char** argv) { WABT_FATAL("no module in file.\n"); if (s_generate_names) - result = generate_names(module); + result = GenerateNames(module); if (Succeeded(result)) - result = apply_names(module); + result = ApplyNames(module); if (Succeeded(result)) { FileWriter writer(s_outfile ? FileWriter(s_outfile) : FileWriter(stdout)); - result = write_wat(&writer, module, &s_write_wat_options); + result = WriteWat(&writer, module, &s_write_wat_options); } } diff --git a/src/tools/wast2wasm.cc b/src/tools/wast2wasm.cc index f2863551..c9b23083 100644 --- a/src/tools/wast2wasm.cc +++ b/src/tools/wast2wasm.cc @@ -69,7 +69,7 @@ examples: $ wast2wasm spec-test.wast --spec -o spec-test.json )"; -static void parse_options(int argc, char* argv[]) { +static void ParseOptions(int argc, char* argv[]) { OptionParser parser("wast2wasm", s_description); parser.AddOption('v', "verbose", "Use multiple times for more info", []() { @@ -111,8 +111,8 @@ static void parse_options(int argc, char* argv[]) { parser.Parse(argc, argv); } -static void write_buffer_to_file(const char* filename, - const OutputBuffer& buffer) { +static void WriteBufferToFile(const char* filename, + const OutputBuffer& buffer) { if (s_dump_module) { if (s_verbose) s_log_stream->Writef(";; dump\n"); @@ -127,9 +127,9 @@ static void write_buffer_to_file(const char* filename, } int ProgramMain(int argc, char** argv) { - init_stdio(); + InitStdio(); - parse_options(argc, argv); + ParseOptions(argc, argv); std::unique_ptr<WastLexer> lexer = WastLexer::CreateFileLexer(s_infile); if (!lexer) @@ -138,33 +138,32 @@ int ProgramMain(int argc, char** argv) { ErrorHandlerFile error_handler(Location::Type::Text); Script* script; Result result = - parse_wast(lexer.get(), &script, &error_handler, &s_parse_options); + ParseWast(lexer.get(), &script, &error_handler, &s_parse_options); if (Succeeded(result)) { - result = resolve_names_script(lexer.get(), script, &error_handler); + result = ResolveNamesScript(lexer.get(), script, &error_handler); if (Succeeded(result) && s_validate) - result = validate_script(lexer.get(), script, &error_handler); + result = ValidateScript(lexer.get(), script, &error_handler); if (Succeeded(result)) { if (s_spec) { s_write_binary_spec_options.json_filename = s_outfile; s_write_binary_spec_options.write_binary_options = s_write_binary_options; - result = write_binary_spec_script(script, s_infile, - &s_write_binary_spec_options); + result = WriteBinarySpecScript(script, s_infile, + &s_write_binary_spec_options); } else { MemoryWriter writer; const Module* module = script->GetFirstModule(); if (module) { - result = - write_binary_module(&writer, module, &s_write_binary_options); + result = WriteBinaryModule(&writer, module, &s_write_binary_options); } else { WABT_FATAL("no module found\n"); } if (Succeeded(result)) - write_buffer_to_file(s_outfile, writer.output_buffer()); + WriteBufferToFile(s_outfile, writer.output_buffer()); } } } diff --git a/src/type-checker.cc b/src/type-checker.cc index 867ab098..72b86cb4 100644 --- a/src/type-checker.cc +++ b/src/type-checker.cc @@ -172,7 +172,7 @@ Result TypeChecker::CheckTypeStackEnd(const char* desc) { Result TypeChecker::CheckType(Type actual, Type expected, const char* desc) { if (expected != actual && expected != Type::Any && actual != Type::Any) { PrintError("type mismatch in %s, expected %s but got %s.", desc, - get_type_name(expected), get_type_name(actual)); + GetTypeName(expected), GetTypeName(actual)); return Result::Error; } return Result::Ok; diff --git a/src/utf8.cc b/src/utf8.cc index 23422983..3855fb71 100644 --- a/src/utf8.cc +++ b/src/utf8.cc @@ -43,13 +43,13 @@ const int s_utf8_length[256] = { }; // Returns true if this is a valid continuation byte. -bool is_cont(uint8_t c) { +bool IsCont(uint8_t c) { return (c & 0xc0) == 0x80; } } // end anonymous namespace -bool is_valid_utf8(const char* s, size_t s_length) { +bool IsValidUtf8(const char* s, size_t s_length) { const uint8_t* p = reinterpret_cast<const uint8_t*>(s); const uint8_t* end = p + s_length; while (p < end) { @@ -68,7 +68,7 @@ bool is_valid_utf8(const char* s, size_t s_length) { case 2: p++; - if (!is_cont(*p++)) + if (!IsCont(*p++)) return false; break; @@ -76,7 +76,7 @@ bool is_valid_utf8(const char* s, size_t s_length) { p++; uint8_t cu1 = *p++; uint8_t cu2 = *p++; - if (!(is_cont(cu1) && is_cont(cu2)) || + if (!(IsCont(cu1) && IsCont(cu2)) || (cu0 == 0xe0 && cu1 < 0xa0) || // Overlong encoding. (cu0 == 0xed && cu1 >= 0xa0)) // UTF-16 surrogate halves. return false; @@ -88,7 +88,7 @@ bool is_valid_utf8(const char* s, size_t s_length) { uint8_t cu1 = *p++; uint8_t cu2 = *p++; uint8_t cu3 = *p++; - if (!(is_cont(cu1) && is_cont(cu2) && is_cont(cu3)) || + if (!(IsCont(cu1) && IsCont(cu2) && IsCont(cu3)) || (cu0 == 0xf0 && cu1 < 0x90) || // Overlong encoding. (cu0 == 0xf4 && cu1 >= 0x90)) // Code point >= 0x11000. return false; @@ -21,7 +21,7 @@ namespace wabt { -bool is_valid_utf8(const char* s, size_t length); +bool IsValidUtf8(const char* s, size_t length); } // namespace wabt diff --git a/src/validator.cc b/src/validator.cc index d8fc09d4..8cf10be8 100644 --- a/src/validator.cc +++ b/src/validator.cc @@ -171,7 +171,7 @@ void Validator::PrintError(const Location* loc, const char* fmt, ...) { result_ = Result::Error; va_list args; va_start(args, fmt); - wast_format_error(error_handler_, loc, lexer_, fmt, args); + WastFormatError(error_handler_, loc, lexer_, fmt, args); va_end(args); } @@ -326,7 +326,7 @@ void Validator::CheckType(const Location* loc, const char* desc) { if (expected != actual) { PrintError(loc, "type mismatch at %s. got %s, expected %s", desc, - get_type_name(actual), get_type_name(expected)); + GetTypeName(actual), GetTypeName(expected)); } } @@ -337,10 +337,9 @@ void Validator::CheckTypeIndex(const Location* loc, Index index, const char* index_kind) { if (expected != actual && expected != Type::Any && actual != Type::Any) { - PrintError(loc, - "type mismatch for %s %" PRIindex " of %s. got %s, expected %s", - index_kind, index, desc, get_type_name(actual), - get_type_name(expected)); + PrintError( + loc, "type mismatch for %s %" PRIindex " of %s. got %s, expected %s", + index_kind, index, desc, GetTypeName(actual), GetTypeName(expected)); } } @@ -390,7 +389,7 @@ void Validator::CheckAssertReturnNanType(const Location* loc, // so we special case it here. if (actual != Type::F32 && actual != Type::F64) { PrintError(loc, "type mismatch at %s. got %s, expected f32 or f64", desc, - get_type_name(actual)); + GetTypeName(actual)); } } @@ -1025,7 +1024,7 @@ void Validator::CheckExcept(const Location* loc, const Exception* except) { case Type::F64: break; default: - PrintError(loc, "Invalid exception type: %s", get_type_name(ty)); + PrintError(loc, "Invalid exception type: %s", GetTypeName(ty)); break; } } @@ -1145,17 +1144,17 @@ Result Validator::CheckScript(const Script* script) { } // end anonymous namespace -Result validate_script(WastLexer* lexer, - const Script* script, - ErrorHandler* error_handler) { +Result ValidateScript(WastLexer* lexer, + const Script* script, + ErrorHandler* error_handler) { Validator validator(error_handler, lexer, script); return validator.CheckScript(script); } -Result validate_module(WastLexer* lexer, - const Module* module, - ErrorHandler* error_handler) { +Result ValidateModule(WastLexer* lexer, + const Module* module, + ErrorHandler* error_handler) { Validator validator(error_handler, lexer, nullptr); return validator.CheckModule(module); diff --git a/src/validator.h b/src/validator.h index 94fc5ace..bcb5b10f 100644 --- a/src/validator.h +++ b/src/validator.h @@ -27,8 +27,8 @@ class ErrorHandler; // Perform all checks on the script. It is valid if and only if this function // succeeds. -Result validate_script(WastLexer*, const Script*, ErrorHandler*); -Result validate_module(WastLexer*, const Module*, ErrorHandler*); +Result ValidateScript(WastLexer*, const Script*, ErrorHandler*); +Result ValidateModule(WastLexer*, const Module*, ErrorHandler*); } // namespace wabt diff --git a/src/wast-lexer.cc b/src/wast-lexer.cc index d0c536ff..342a31b2 100644 --- a/src/wast-lexer.cc +++ b/src/wast-lexer.cc @@ -54,7 +54,7 @@ #define ERROR(...) \ SetLocation(loc); \ - wast_parser_error(loc, this, parser, __VA_ARGS__) + WastParserError(loc, this, parser, __VA_ARGS__) #define BEGIN(c) cond = (c) #define FILL(n) \ diff --git a/src/wast-parser-lexer-shared.cc b/src/wast-parser-lexer-shared.cc index 73161693..c9ad9b61 100644 --- a/src/wast-parser-lexer-shared.cc +++ b/src/wast-parser-lexer-shared.cc @@ -23,23 +23,23 @@ namespace wabt { -void wast_parser_error(Location* loc, - WastLexer* lexer, - WastParser* parser, - const char* format, - ...) { +void WastParserError(Location* loc, + WastLexer* lexer, + WastParser* parser, + const char* format, + ...) { parser->errors++; va_list args; va_start(args, format); - wast_format_error(parser->error_handler, loc, lexer, format, args); + WastFormatError(parser->error_handler, loc, lexer, format, args); va_end(args); } -void wast_format_error(ErrorHandler* error_handler, - const struct Location* loc, - WastLexer* lexer, - const char* format, - va_list args) { +void WastFormatError(ErrorHandler* error_handler, + const struct Location* loc, + WastLexer* lexer, + const char* format, + va_list args) { va_list args_copy; va_copy(args_copy, args); char fixed_buf[WABT_DEFAULT_SNPRINTF_ALLOCA_BUFSIZE]; diff --git a/src/wast-parser-lexer-shared.h b/src/wast-parser-lexer-shared.h index 75385891..b5774d58 100644 --- a/src/wast-parser-lexer-shared.h +++ b/src/wast-parser-lexer-shared.h @@ -121,20 +121,20 @@ struct WastParser { WastParseOptions* options; }; -int wast_lexer_lex(union Token*, - struct Location*, - WastLexer*, - struct WastParser*); -void WABT_PRINTF_FORMAT(4, 5) wast_parser_error(struct Location*, - WastLexer*, - struct WastParser*, - const char*, - ...); -void wast_format_error(ErrorHandler*, - const struct Location*, - WastLexer*, - const char* format, - va_list); +int WastLexerLex(union Token*, + struct Location*, + WastLexer*, + struct WastParser*); +void WABT_PRINTF_FORMAT(4, 5) WastParserError(struct Location*, + WastLexer*, + struct WastParser*, + const char*, + ...); +void WastFormatError(ErrorHandler*, + const struct Location*, + WastLexer*, + const char* format, + va_list); } // namespace wabt diff --git a/src/wast-parser.h b/src/wast-parser.h index 07a927a9..a2c06e34 100644 --- a/src/wast-parser.h +++ b/src/wast-parser.h @@ -29,10 +29,10 @@ struct WastParseOptions { bool debug_parsing = false; }; -Result parse_wast(WastLexer* lexer, - Script** out_script, - ErrorHandler*, - WastParseOptions* options = nullptr); +Result ParseWast(WastLexer* lexer, + Script** out_script, + ErrorHandler*, + WastParseOptions* options = nullptr); } // namespace wabt diff --git a/src/wast-parser.y b/src/wast-parser.y index 4b29d781..4541da97 100644 --- a/src/wast-parser.y +++ b/src/wast-parser.y @@ -76,28 +76,28 @@ } \ while (0) -#define CHECK_END_LABEL(loc, begin_label, end_label) \ - do { \ - if (!end_label->empty()) { \ - if (begin_label.empty()) { \ - wast_parser_error(&loc, lexer, parser, "unexpected label \"%s\"", \ - end_label->c_str()); \ - } else if (begin_label != *end_label) { \ - wast_parser_error(&loc, lexer, parser, \ - "mismatching label \"%s\" != \"%s\"", \ - begin_label.c_str(), end_label->c_str()); \ - } \ - } \ - delete (end_label); \ +#define CHECK_END_LABEL(loc, begin_label, end_label) \ + do { \ + if (!end_label->empty()) { \ + if (begin_label.empty()) { \ + WastParserError(&loc, lexer, parser, "unexpected label \"%s\"", \ + end_label->c_str()); \ + } else if (begin_label != *end_label) { \ + WastParserError(&loc, lexer, parser, \ + "mismatching label \"%s\" != \"%s\"", \ + begin_label.c_str(), end_label->c_str()); \ + } \ + } \ + delete (end_label); \ } while (0) -#define CHECK_ALLOW_EXCEPTIONS(loc, opcode_name) \ - do { \ - if (!parser->options->allow_future_exceptions) { \ - wast_parser_error(loc, lexer, parser, "opcode not allowed: %s", \ - opcode_name); \ - } \ - } while (0) +#define CHECK_ALLOW_EXCEPTIONS(loc, opcode_name) \ + do { \ + if (!parser->options->allow_future_exceptions) { \ + WastParserError(loc, lexer, parser, "opcode not allowed: %s", \ + opcode_name); \ + } \ + } while (0) #define YYMALLOC(size) new char [size] #define YYFREE(p) delete [] (p) @@ -179,8 +179,8 @@ void RemoveEscapes(string_view text, OutputIter dest) { // sequence. uint32_t hi; uint32_t lo; - if (Succeeded(parse_hexdigit(src[0], &hi)) && - Succeeded(parse_hexdigit(src[1], &lo))) { + if (Succeeded(ParseHexdigit(src[0], &hi)) && + Succeeded(ParseHexdigit(src[1], &lo))) { *dest++ = (hi << 4) | lo; } else { assert(0); @@ -222,7 +222,7 @@ void AppendAndDelete(T& dest, U* source) { } #define wabt_wast_parser_lex(...) lexer->GetToken(__VA_ARGS__, parser) -#define wabt_wast_parser_error wast_parser_error +#define wabt_wast_parser_error WastParserError %} @@ -433,10 +433,9 @@ type_use : nat : NAT { string_view sv = $1.text.to_string_view(); - if (Failed(parse_uint64(sv.begin(), sv.end(), &$$))) { - wast_parser_error(&@1, lexer, parser, - "invalid int \"" PRIstringview "\"", - WABT_PRINTF_STRING_VIEW_ARG(sv)); + if (Failed(ParseUint64(sv.begin(), sv.end(), &$$))) { + WastParserError(&@1, lexer, parser, "invalid int \"" PRIstringview "\"", + WABT_PRINTF_STRING_VIEW_ARG(sv)); } } ; @@ -486,15 +485,15 @@ offset_opt : | OFFSET_EQ_NAT { uint64_t offset64; string_view sv = $1.to_string_view(); - if (Failed(parse_int64(sv.begin(), sv.end(), &offset64, - ParseIntType::SignedAndUnsigned))) { - wast_parser_error(&@1, lexer, parser, - "invalid offset \"" PRIstringview "\"", - WABT_PRINTF_STRING_VIEW_ARG(sv)); + if (Failed(ParseInt64(sv.begin(), sv.end(), &offset64, + ParseIntType::SignedAndUnsigned))) { + WastParserError(&@1, lexer, parser, + "invalid offset \"" PRIstringview "\"", + WABT_PRINTF_STRING_VIEW_ARG(sv)); } if (offset64 > UINT32_MAX) { - wast_parser_error(&@1, lexer, parser, - "offset must be less than or equal to 0xffffffff"); + WastParserError(&@1, lexer, parser, + "offset must be less than or equal to 0xffffffff"); } $$ = static_cast<uint32_t>(offset64); } @@ -503,15 +502,15 @@ align_opt : /* empty */ { $$ = USE_NATURAL_ALIGNMENT; } | ALIGN_EQ_NAT { string_view sv = $1.to_string_view(); - if (Failed(parse_int32(sv.begin(), sv.end(), &$$, - ParseIntType::UnsignedOnly))) { - wast_parser_error(&@1, lexer, parser, - "invalid alignment \"" PRIstringview "\"", - WABT_PRINTF_STRING_VIEW_ARG(sv)); + if (Failed(ParseInt32(sv.begin(), sv.end(), &$$, + ParseIntType::UnsignedOnly))) { + WastParserError(&@1, lexer, parser, + "invalid alignment \"" PRIstringview "\"", + WABT_PRINTF_STRING_VIEW_ARG(sv)); } if ($$ != WABT_USE_NATURAL_ALIGNMENT && !IsPowerOfTwo($$)) { - wast_parser_error(&@1, lexer, parser, "alignment must be power-of-two"); + WastParserError(&@1, lexer, parser, "alignment must be power-of-two"); } } ; @@ -585,8 +584,8 @@ plain_instr : const_.loc = @1; auto literal = MoveAndDelete($2); if (Failed(ParseConst($1, literal, &const_))) { - wast_parser_error(&@2, lexer, parser, "invalid literal \"%s\"", - literal.text.c_str()); + WastParserError(&@2, lexer, parser, "invalid literal \"%s\"", + literal.text.c_str()); } $$ = new ConstExpr(const_); } @@ -1330,8 +1329,8 @@ module : ReadBinaryOptions options; BinaryErrorHandlerModule error_handler(&$1->binary.loc, lexer, parser); const char* filename = "<text>"; - read_binary_ir(filename, $1->binary.data.data(), $1->binary.data.size(), - &options, &error_handler, $$); + ReadBinaryIr(filename, $1->binary.data.data(), $1->binary.data.size(), + &options, &error_handler, $$); $$->name = $1->binary.name; $$->loc = $1->binary.loc; } @@ -1466,8 +1465,8 @@ const : $$.loc = @2; auto literal = MoveAndDelete($3); if (Failed(ParseConst($2, literal, &$$))) { - wast_parser_error(&@3, lexer, parser, "invalid literal \"%s\"", - literal.text.c_str()); + WastParserError(&@3, lexer, parser, "invalid literal \"%s\"", + literal.text.c_str()); } } ; @@ -1567,13 +1566,13 @@ Result ParseConst(Type type, const Literal& literal, Const* out) { out->type = type; switch (type) { case Type::I32: - return parse_int32(s, end, &out->u32, ParseIntType::SignedAndUnsigned); + return ParseInt32(s, end, &out->u32, ParseIntType::SignedAndUnsigned); case Type::I64: - return parse_int64(s, end, &out->u64, ParseIntType::SignedAndUnsigned); + return ParseInt64(s, end, &out->u64, ParseIntType::SignedAndUnsigned); case Type::F32: - return parse_float(literal.type, s, end, &out->f32_bits); + return ParseFloat(literal.type, s, end, &out->f32_bits); case Type::F64: - return parse_double(literal.type, s, end, &out->f64_bits); + return ParseDouble(literal.type, s, end, &out->f64_bits); default: assert(0); break; @@ -1614,9 +1613,8 @@ void CheckImportOrdering(Location* loc, WastLexer* lexer, WastParser* parser, module->memories.size() != module->num_memory_imports || module->globals.size() != module->num_global_imports || module->excepts.size() != module->num_except_imports) { - wast_parser_error( - loc, lexer, parser, - "imports must occur before all non-import definitions"); + WastParserError(loc, lexer, parser, + "imports must occur before all non-import definitions"); } } } @@ -1787,9 +1785,8 @@ void AppendModuleFields(Module* module, ModuleFieldList&& fields) { module->fields.splice(module->fields.end(), fields); } -Result parse_wast(WastLexer* lexer, Script** out_script, - ErrorHandler* error_handler, - WastParseOptions* options) { +Result ParseWast(WastLexer * lexer, Script * *out_script, + ErrorHandler * error_handler, WastParseOptions * options) { WastParser parser; ZeroMemory(parser); static WastParseOptions default_options; @@ -1821,12 +1818,12 @@ bool BinaryErrorHandlerModule::OnError( const Location& binary_loc, const std::string& error, const std::string& source_line, size_t source_line_column_offset) { if (binary_loc.offset == kInvalidOffset) { - wast_parser_error(loc_, lexer_, parser_, "error in binary module: %s", - error.c_str()); + WastParserError(loc_, lexer_, parser_, "error in binary module: %s", + error.c_str()); } else { - wast_parser_error(loc_, lexer_, parser_, - "error in binary module: @0x%08" PRIzx ": %s", - binary_loc.offset, error.c_str()); + WastParserError(loc_, lexer_, parser_, + "error in binary module: @0x%08" PRIzx ": %s", + binary_loc.offset, error.c_str()); } return true; } diff --git a/src/wat-writer.cc b/src/wat-writer.cc index e46ae9d9..e1ae580d 100644 --- a/src/wat-writer.cc +++ b/src/wat-writer.cc @@ -367,7 +367,7 @@ void WatWriter::WriteBrVar(const Var* var, NextChar next_char) { } void WatWriter::WriteType(Type type, NextChar next_char) { - const char* type_name = get_type_name(type); + const char* type_name = GetTypeName(type); assert(type_name); WritePuts(type_name, next_char); } @@ -434,7 +434,7 @@ void WatWriter::WriteConst(const Const* const_) { case Type::F32: { WritePutsSpace(Opcode::F32Const_Opcode.GetName()); char buffer[128]; - write_float_hex(buffer, 128, const_->f32_bits); + WriteFloatHex(buffer, 128, const_->f32_bits); WritePutsSpace(buffer); float f32; memcpy(&f32, &const_->f32_bits, sizeof(f32)); @@ -446,7 +446,7 @@ void WatWriter::WriteConst(const Const* const_) { case Type::F64: { WritePutsSpace(Opcode::F64Const_Opcode.GetName()); char buffer[128]; - write_double_hex(buffer, 128, const_->f64_bits); + WriteDoubleHex(buffer, 128, const_->f64_bits); WritePutsSpace(buffer); double f64; memcpy(&f64, &const_->f64_bits, sizeof(f64)); @@ -1110,7 +1110,7 @@ void WatWriter::WriteExport(const Export* export_) { return; WriteOpenSpace("export"); WriteQuotedString(export_->name, NextChar::Space); - WriteOpenSpace(get_kind_name(export_->kind)); + WriteOpenSpace(GetKindName(export_->kind)); WriteVar(&export_->var, NextChar::Space); WriteCloseSpace(); WriteCloseNewline(); @@ -1231,9 +1231,9 @@ void WatWriter::WriteInlineExport(const Export* export_) { } // end anonymous namespace -Result write_wat(Writer* writer, - const Module* module, - const WriteWatOptions* options) { +Result WriteWat(Writer* writer, + const Module* module, + const WriteWatOptions* options) { WatWriter wat_writer(writer, options); return wat_writer.WriteModule(module); } diff --git a/src/wat-writer.h b/src/wat-writer.h index ec685fb6..56b65029 100644 --- a/src/wat-writer.h +++ b/src/wat-writer.h @@ -29,7 +29,7 @@ struct WriteWatOptions { bool inline_export = false; }; -Result write_wat(Writer*, const Module*, const WriteWatOptions*); +Result WriteWat(Writer*, const Module*, const WriteWatOptions*); } // namespace wabt |