diff --git a/src/parser/WASMComponentParser.cpp b/src/parser/WASMComponentParser.cpp new file mode 100644 index 000000000..21aed7549 --- /dev/null +++ b/src/parser/WASMComponentParser.cpp @@ -0,0 +1,321 @@ +/* + * Copyright (c) 2022-present Samsung Electronics Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "Walrus.h" + +#include "parser/WASMComponentParser.h" +#include "runtime/Store.h" +#include "runtime/TypeStore.h" + +#include "wabt/binary-reader.h" +#include "wabt/walrus/binary-reader-walrus.h" + +namespace wabt { + +class WASMComponentBinaryReader : public wabt::WASMComponentBinaryReaderDelegate { +private: + Walrus::TypeStore& m_typeStore; + +public: + WASMComponentBinaryReader(Walrus::TypeStore& typeStore) + : m_typeStore(typeStore) + { + } + + void OnCoreModule(const void* data, + size_t size, + const ReadBinaryOptions& options) + { + } + + void BeginComponent(uint32_t version, size_t depth) + { + } + + void EndComponent() + { + } + + void BeginCoreInstance(Index module_index, + uint32_t argument_count) + { + } + + void OnCoreInstanceArg(const ComponentStringLoc& name, + ComponentSort sort, + Index index) + { + } + + void EndCoreInstance() + { + } + + void BeginInlineCoreInstance(uint32_t argument_count) + { + } + + void OnInlineCoreInstanceArg(const ComponentStringLoc& name, + ComponentSort sort, + Index index) + { + } + + void EndInlineCoreInstance() + { + } + + void BeginInstance(Index component_index, + uint32_t argument_count) + { + } + + void OnInstanceArg(const ComponentStringLoc& name, + ComponentSort sort, + Index index) + { + } + + void EndInstance() + { + } + + void BeginInlineInstance(uint32_t argument_count) + { + } + + void OnInlineInstanceArg(const ComponentStringLoc& name, + nonstd::string_view* version_suffix, + ComponentSort sort, + Index index) + { + } + + void EndInlineInstance() + { + } + + void OnAliasExport(ComponentSort sort, + Index instance_index, + const ComponentStringLoc& name) + { + } + + void OnAliasCoreExport(ComponentSort sort, + Index core_instance_index, + const ComponentStringLoc& name) + { + } + + void OnAliasOuter(ComponentSort sort, + uint32_t counter, + uint32_t index) + { + } + + void OnPrimitiveType(const ComponentType& type) + { + } + + void BeginRecordType(uint32_t field_count) + { + } + + void OnRecordField(const ComponentStringLoc& field_name, + const ComponentType& field_type) + { + } + + void EndRecordType() + { + } + + void BeginVariantType(uint32_t case_count) + { + } + + void OnVariantCase(const ComponentStringLoc& case_name, + const ComponentType& case_type) + { + } + + void EndVariantType() + { + } + + void OnListType(const ComponentType& type) + { + } + + void OnListFixedType(const ComponentType& type, + uint32_t size) + { + } + + void BeginTupleType(uint32_t item_count) + { + } + + void OnTupleItem(const ComponentType& item) + { + } + + void EndTupleType() + { + } + + void BeginFlagsType(uint32_t label_count) + { + } + + void OnFlagsLabel(const ComponentStringLoc& label) + { + } + + void EndFlagsType() + { + } + + void BeginEnumType(uint32_t label_count) + { + } + + void OnEnumLabel(const ComponentStringLoc& label) + { + } + + void EndEnumType() + { + } + + void OnOptionType(const ComponentType& type) + { + } + + void OnResultType(const ComponentType& result_type, + const ComponentType& error_type) + { + } + + void OnOwnType(Index index) + { + } + + void OnBorrowType(Index index) + { + } + + void OnStreamType(const ComponentType& type) + { + } + + void OnFutureType(const ComponentType& type) + { + } + + void BeginFuncType(ComponentTypeDef type, + uint32_t param_count) + { + } + + void OnFuncParam(ComponentStringLoc name, + const ComponentType& type) + { + } + + void OnFuncResult(const ComponentType& type) + { + } + + void EndFuncType() + { + } + + void OnResourceType(ComponentResourceRep rep, + Index dtor) + { + } + + void OnResourceAsyncType(ComponentResourceRep rep, + Index dtor, + Index callback) + { + } + + void BeginInstanceType(uint32_t count) + { + } + + void EndInstanceType() + { + } + + void BeginComponentType(uint32_t count) + { + } + + void EndComponentType() + { + } + + void OnCanonLift(Index core_func_index, + uint32_t option_count, + ComponentCanonOption* options, + Index type_index) + { + } + + void OnCanonLower(Index func_index, + uint32_t option_count, + ComponentCanonOption* options) + { + } + + void OnCanonType(ComponentCanon canon, + Index type_index) + { + } + + void OnImport(const ComponentStringLoc& name, + nonstd::string_view* version_suffix, + const ComponentExternalInfo& external_info) + { + } + + void OnExport(const ComponentStringLoc& name, + nonstd::string_view* version_suffix, + ComponentExternalInfo* external_info, + ComponentExportInfo* export_info) + { + } +}; + +} // namespace wabt + +namespace Walrus { + +std::pair, std::string> WASMComponentParser::parseBinary(Store* store, const std::string& filename, const uint8_t* data, size_t len, const uint32_t JITFlags, const uint32_t featureFlags) +{ + wabt::WASMComponentBinaryReader delegate(store->getTypeStore()); + + std::string error = ReadWasmComponentBinary(filename, data, len, &delegate, featureFlags); + if (error.length()) { + return std::make_pair(nullptr, error); + } + + return std::make_pair(nullptr, std::string()); +} + +} // namespace Walrus diff --git a/src/parser/WASMComponentParser.h b/src/parser/WASMComponentParser.h new file mode 100644 index 000000000..11210de50 --- /dev/null +++ b/src/parser/WASMComponentParser.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2022-present Samsung Electronics Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __WalrusWASMComponentParser__ +#define __WalrusWASMComponentParser__ + +#include "runtime/Component.h" + +namespace Walrus { + +class WASMComponentParser { +public: + // returns + static std::pair, std::string> parseBinary(Store* store, const std::string& filename, const uint8_t* data, size_t len, const uint32_t JITFlags = 0, const uint32_t featureFlags = 0); +}; + +} // namespace Walrus + +#endif // __WalrusParser__ diff --git a/src/parser/WASMParser.cpp b/src/parser/WASMParser.cpp index 28cafbe6b..792bd5e01 100644 --- a/src/parser/WASMParser.cpp +++ b/src/parser/WASMParser.cpp @@ -442,7 +442,7 @@ class WASMBinaryReader : public wabt::WASMBinaryReaderDelegate { size_t* m_readerOffsetPointer; const uint8_t* m_readerDataPointer; size_t m_codeEndOffset; - Walrus::TypeStore& typeStore; + Walrus::TypeStore& m_typeStore; struct PreprocessData { struct LocalVariableInfo { @@ -864,7 +864,7 @@ class WASMBinaryReader : public wabt::WASMBinaryReaderDelegate { : m_readerOffsetPointer(nullptr) , m_readerDataPointer(nullptr) , m_codeEndOffset(0) - , typeStore(typeStore) + , m_typeStore(typeStore) , m_inInitExpr(false) , m_currentFunction(nullptr) , m_currentFunctionType(nullptr) @@ -1013,7 +1013,7 @@ class WASMBinaryReader : public wabt::WASMBinaryReaderDelegate { virtual void EndTypeSection() override { m_result.m_typesAddedToStore = true; - typeStore.updateTypes(m_result.m_compositeTypes); + m_typeStore.updateTypes(m_result.m_compositeTypes); } virtual void OnImportCount(Index count) override diff --git a/src/parser/WASMParser.h b/src/parser/WASMParser.h index 440c48442..1ea931db7 100644 --- a/src/parser/WASMParser.h +++ b/src/parser/WASMParser.h @@ -60,4 +60,4 @@ class WASMParser { } // namespace Walrus -#endif // __WalrusParser__ +#endif // __WalrusWASMParser__ diff --git a/src/runtime/Component.h b/src/runtime/Component.h new file mode 100644 index 000000000..ef814ae2b --- /dev/null +++ b/src/runtime/Component.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2022-present Samsung Electronics Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __WalrusComponent__ +#define __WalrusComponent__ + +#include "runtime/Module.h" + +namespace wabt { +class WASMComponentBinaryReader; +} + +namespace Walrus { + +class Component { + friend class wabt::WASMComponentBinaryReader; + +public: + virtual ~Component() {} +}; + +} // namespace Walrus + +#endif // __WalrusComponent__ diff --git a/src/shell/Shell.cpp b/src/shell/Shell.cpp index 8b02876f7..a817db9fd 100644 --- a/src/shell/Shell.cpp +++ b/src/shell/Shell.cpp @@ -12,6 +12,7 @@ #include "runtime/Engine.h" #include "runtime/Store.h" #include "runtime/Module.h" +#include "runtime/Component.h" #include "runtime/Instance.h" #include "runtime/Function.h" #include "runtime/Table.h" @@ -21,6 +22,7 @@ #include "runtime/Trap.h" #include "runtime/DefinedFunctionTypes.h" #include "parser/WASMParser.h" +#include "parser/WASMComponentParser.h" #include "wabt/wast-lexer.h" #include "wabt/wast-parser.h" @@ -368,6 +370,17 @@ static Trap::TrapResult executeWASM(Store* store, const std::string& filename, c &data); } +static wabt::Result executeWASMComponent(Store* store, const std::string& filename, const std::vector& src) +{ + std::pair, std::string> parseResult = WASMComponentParser::parseBinary(store, filename, src.data(), src.size()); + if (!parseResult.second.empty()) { + printf("Cannot run module: %s\n", parseResult.second.c_str()); + return wabt::Result::Error; + } + + return wabt::Result::Ok; +} + static bool endsWith(const std::string& str, const std::string& suffix) { return str.size() >= suffix.size() && str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; @@ -801,14 +814,40 @@ static Instance* fetchInstance(wabt::Var& moduleVar, std::map static void executeWAST(Store* store, const std::string& filename, const std::vector& src, DefinedFunctionTypes& functionTypes) { wabt::Errors errors; + wabt::Features features; + features.EnableAll(); + wabt::WastParseOptions parseWastOptions(features); auto lexer = wabt::WastLexer::CreateBufferLexer("test.wabt", src.data(), src.size(), &errors); ASSERT(lexer); + if (lexer->IsComponent()) { + std::unique_ptr component; + auto result = ParseWatComponent(lexer.get(), &component, &errors, &parseWastOptions); + + if (wabt::Succeeded(result)) { + wabt::WriteBinaryOptions writeBinaryOptions; + writeBinaryOptions.features = features; + wabt::MemoryStream stream; + result = WriteBinaryComponent(&stream, component.get(), writeBinaryOptions); + + if (wabt::Succeeded(result)) { + result = executeWASMComponent(store, filename, stream.output_buffer().data); + } + } + + if (!wabt::Succeeded(result)) { + printf("Syntax error(s):\n"); + for (auto& e : errors) { + printf(" %s\n", e.message.c_str()); + } + printf("\n"); + RELEASE_ASSERT_NOT_REACHED(); + } + return; + } + std::unique_ptr script; - wabt::Features features; - features.EnableAll(); - wabt::WastParseOptions parse_wast_options(features); - auto result = wabt::ParseWastScript(lexer.get(), &script, &errors, &parse_wast_options); + auto result = wabt::ParseWastScript(lexer.get(), &script, &errors, &parseWastOptions); if (!wabt::Succeeded(result)) { printf("Syntax error(s):\n"); for (auto& e : errors) { @@ -1233,7 +1272,6 @@ int main(int argc, const char* argv[]) parseArguments(argc, argv, options); - #ifdef ENABLE_WASI // initialize WASI uvwasi_t uvwasi; @@ -1288,6 +1326,8 @@ int main(int argc, const char* argv[]) if (endsWith(filePath, "wasm")) { if (!options.exportToRun.empty()) { runExports(store, filePath, buf, options.exportToRun, functionTypes); + } else if (wabt::ReadBinaryIsComponent(buf.data(), buf.size())) { + executeWASMComponent(store, filePath, buf); } else { auto trapResult = executeWASM(store, filePath, buf, functionTypes); if (trapResult.exception) { diff --git a/third_party/wabt/include/wabt/binary-reader.h b/third_party/wabt/include/wabt/binary-reader.h index 275d3f595..1b5ff7047 100644 --- a/third_party/wabt/include/wabt/binary-reader.h +++ b/third_party/wabt/include/wabt/binary-reader.h @@ -581,28 +581,32 @@ class ComponentBinaryReaderDelegate { virtual Result BeginCoreInstanceSection(uint32_t count) = 0; virtual Result EndCoreInstanceSection() = 0; - virtual Result OnCoreInstance(const ComponentIndexLoc& module_index, - uint32_t argument_count) = 0; + virtual Result BeginCoreInstance(const ComponentIndexLoc& module_index, + uint32_t argument_count) = 0; virtual Result OnCoreInstanceArg(const ComponentStringLoc& name, ComponentSort sort, const ComponentIndexLoc& index) = 0; - virtual Result OnInlineCoreInstance(uint32_t argument_count) = 0; + virtual Result EndCoreInstance() = 0; + virtual Result BeginInlineCoreInstance(uint32_t argument_count) = 0; virtual Result OnInlineCoreInstanceArg(const ComponentStringLoc& name, ComponentSort sort, const ComponentIndexLoc& index) = 0; + virtual Result EndInlineCoreInstance() = 0; virtual Result BeginInstanceSection(uint32_t count) = 0; virtual Result EndInstanceSection() = 0; - virtual Result OnInstance(const ComponentIndexLoc& component_index, - uint32_t argument_count) = 0; + virtual Result BeginInstance(const ComponentIndexLoc& component_index, + uint32_t argument_count) = 0; virtual Result OnInstanceArg(const ComponentStringLoc& name, ComponentSort sort, const ComponentIndexLoc& index) = 0; - virtual Result OnInlineInstance(uint32_t argument_count) = 0; + virtual Result EndInstance() = 0; + virtual Result BeginInlineInstance(uint32_t argument_count) = 0; virtual Result OnInlineInstanceArg(const ComponentStringLoc& name, nonstd::string_view* version_suffix, ComponentSort sort, const ComponentIndexLoc& index) = 0; + virtual Result EndInlineInstance() = 0; virtual Result BeginAliasSection(uint32_t count) = 0; virtual Result EndAliasSection() = 0; @@ -619,21 +623,26 @@ class ComponentBinaryReaderDelegate { virtual Result BeginTypeSection(uint32_t count) = 0; virtual Result EndTypeSection() = 0; virtual Result OnPrimitiveType(const ComponentType& type) = 0; - virtual Result OnRecordType(uint32_t field_count) = 0; + virtual Result BeginRecordType(uint32_t field_count) = 0; virtual Result OnRecordField(const ComponentStringLoc& field_name, const ComponentTypeLoc& field_type) = 0; - virtual Result OnVariantType(uint32_t case_count) = 0; + virtual Result EndRecordType() = 0; + virtual Result BeginVariantType(uint32_t case_count) = 0; virtual Result OnVariantCase(const ComponentStringLoc& case_name, const ComponentTypeLoc& case_type) = 0; + virtual Result EndVariantType() = 0; virtual Result OnListType(const ComponentTypeLoc& type) = 0; virtual Result OnListFixedType(const ComponentTypeLoc& type, uint32_t size) = 0; - virtual Result OnTupleType(uint32_t item_count) = 0; + virtual Result BeginTupleType(uint32_t item_count) = 0; virtual Result OnTupleItem(const ComponentTypeLoc& item) = 0; - virtual Result OnFlagsType(uint32_t label_count) = 0; + virtual Result EndTupleType() = 0; + virtual Result BeginFlagsType(uint32_t label_count) = 0; virtual Result OnFlagsLabel(const ComponentStringLoc& label) = 0; - virtual Result OnEnumType(uint32_t label_count) = 0; + virtual Result EndFlagsType() = 0; + virtual Result BeginEnumType(uint32_t label_count) = 0; virtual Result OnEnumLabel(const ComponentStringLoc& label) = 0; + virtual Result EndEnumType() = 0; virtual Result OnOptionType(const ComponentTypeLoc& type) = 0; virtual Result OnResultType(const ComponentTypeLoc& result_type, const ComponentTypeLoc& error_type) = 0; @@ -641,11 +650,12 @@ class ComponentBinaryReaderDelegate { virtual Result OnBorrowType(const ComponentIndexLoc& index) = 0; virtual Result OnStreamType(const ComponentTypeLoc& type) = 0; virtual Result OnFutureType(const ComponentTypeLoc& type) = 0; - virtual Result OnFuncType(ComponentTypeDef type, - uint32_t param_count) = 0; - virtual Result OnFuncParam(ComponentStringLoc name, - ComponentTypeLoc type) = 0; + virtual Result BeginFuncType(ComponentTypeDef type, + uint32_t param_count) = 0; + virtual Result OnFuncParam(const ComponentStringLoc& name, + const ComponentTypeLoc& type) = 0; virtual Result OnFuncResult(const ComponentTypeLoc& type) = 0; + virtual Result EndFuncType() = 0; virtual Result OnResourceType(ComponentResourceRep rep, const ComponentIndexLoc& dtor) = 0; virtual Result OnResourceAsyncType(ComponentResourceRep rep, diff --git a/third_party/wabt/include/wabt/shared-validator.h b/third_party/wabt/include/wabt/shared-validator.h index 89ad69732..812120af3 100644 --- a/third_party/wabt/include/wabt/shared-validator.h +++ b/third_party/wabt/include/wabt/shared-validator.h @@ -444,10 +444,9 @@ class SharedComponentValidator { Result OnInstanceArg(const ComponentStringLoc& name, ComponentSort sort, const ComponentIndexLoc& index); - Result OnInlineInstance(); + Result OnInlineInstance(uint32_t argument_count); Result OnInlineInstanceArg(const ComponentStringLoc& name, - bool has_version_suffix, - nonstd::string_view version_suffix, + nonstd::string_view* version_suffix, ComponentSort sort, const ComponentIndexLoc& index); @@ -490,8 +489,8 @@ class SharedComponentValidator { Result OnFutureType(const ComponentTypeLoc& type); Result OnFuncType(ComponentTypeDef type, uint32_t param_count); - Result OnFuncParam(ComponentStringLoc name, - ComponentTypeLoc type); + Result OnFuncParam(const ComponentStringLoc& name, + const ComponentTypeLoc& type); Result OnFuncResult(const ComponentTypeLoc& type); Result OnResourceType(const Location& loc, ComponentResourceRep rep, @@ -780,6 +779,7 @@ class SharedComponentValidator { // Sorts. TypeBaseVector types; + TypeBaseVector instances; }; struct Component : public TypeDefList { @@ -792,7 +792,6 @@ class SharedComponentValidator { TypeBaseVector core_modules; TypeBaseVector funcs; TypeBaseVector components; - TypeBaseVector instances; }; struct CoreModule : public TypeBase { diff --git a/third_party/wabt/include/wabt/walrus/binary-reader-walrus.h b/third_party/wabt/include/wabt/walrus/binary-reader-walrus.h index 716334129..f0e6200e1 100644 --- a/third_party/wabt/include/wabt/walrus/binary-reader-walrus.h +++ b/third_party/wabt/include/wabt/walrus/binary-reader-walrus.h @@ -239,11 +239,129 @@ class WASMBinaryReaderDelegate { size_t m_skipValidationUntil; }; +class WASMComponentBinaryReaderDelegate { +public: + virtual ~WASMComponentBinaryReaderDelegate() {} + + virtual void OnCoreModule(const void* data, + size_t size, + const ReadBinaryOptions& options) = 0; + virtual void BeginComponent(uint32_t version, size_t depth) = 0; + virtual void EndComponent() = 0; + + virtual void BeginCoreInstance(Index module_index, + uint32_t argument_count) = 0; + virtual void OnCoreInstanceArg(const ComponentStringLoc& name, + ComponentSort sort, + Index index) = 0; + virtual void EndCoreInstance() = 0; + virtual void BeginInlineCoreInstance(uint32_t argument_count) = 0; + virtual void OnInlineCoreInstanceArg(const ComponentStringLoc& name, + ComponentSort sort, + Index index) = 0; + virtual void EndInlineCoreInstance() = 0; + + virtual void BeginInstance(Index component_index, + uint32_t argument_count) = 0; + virtual void OnInstanceArg(const ComponentStringLoc& name, + ComponentSort sort, + Index index) = 0; + virtual void EndInstance() = 0; + virtual void BeginInlineInstance(uint32_t argument_count) = 0; + virtual void OnInlineInstanceArg(const ComponentStringLoc& name, + nonstd::string_view* version_suffix, + ComponentSort sort, + Index index) = 0; + virtual void EndInlineInstance() = 0; + + virtual void OnAliasExport(ComponentSort sort, + Index instance_index, + const ComponentStringLoc& name) = 0; + virtual void OnAliasCoreExport(ComponentSort sort, + Index core_instance_index, + const ComponentStringLoc& name) = 0; + virtual void OnAliasOuter(ComponentSort sort, + uint32_t counter, + uint32_t index) = 0; + + virtual void OnPrimitiveType(const ComponentType& type) = 0; + virtual void BeginRecordType(uint32_t field_count) = 0; + virtual void OnRecordField(const ComponentStringLoc& field_name, + const ComponentType& field_type) = 0; + virtual void EndRecordType() = 0; + virtual void BeginVariantType(uint32_t case_count) = 0; + virtual void OnVariantCase(const ComponentStringLoc& case_name, + const ComponentType& case_type) = 0; + virtual void EndVariantType() = 0; + virtual void OnListType(const ComponentType& type) = 0; + virtual void OnListFixedType(const ComponentType& type, + uint32_t size) = 0; + virtual void BeginTupleType(uint32_t item_count) = 0; + virtual void OnTupleItem(const ComponentType& item) = 0; + virtual void EndTupleType() = 0; + virtual void BeginFlagsType(uint32_t label_count) = 0; + virtual void OnFlagsLabel(const ComponentStringLoc& label) = 0; + virtual void EndFlagsType() = 0; + virtual void BeginEnumType(uint32_t label_count) = 0; + virtual void OnEnumLabel(const ComponentStringLoc& label) = 0; + virtual void EndEnumType() = 0; + virtual void OnOptionType(const ComponentType& type) = 0; + virtual void OnResultType(const ComponentType& result_type, + const ComponentType& error_type) = 0; + virtual void OnOwnType(Index index) = 0; + virtual void OnBorrowType(Index index) = 0; + virtual void OnStreamType(const ComponentType& type) = 0; + virtual void OnFutureType(const ComponentType& type) = 0; + virtual void BeginFuncType(ComponentTypeDef type, + uint32_t param_count) = 0; + virtual void OnFuncParam(ComponentStringLoc name, + const ComponentType& type) = 0; + virtual void OnFuncResult(const ComponentType& type) = 0; + virtual void EndFuncType() = 0; + virtual void OnResourceType(ComponentResourceRep rep, + Index dtor) = 0; + virtual void OnResourceAsyncType(ComponentResourceRep rep, + Index dtor, + Index callback) = 0; + virtual void BeginInstanceType(uint32_t count) = 0; + virtual void EndInstanceType() = 0; + virtual void BeginComponentType(uint32_t count) = 0; + virtual void EndComponentType() = 0; + + virtual void OnCanonLift(Index core_func_index, + uint32_t option_count, + ComponentCanonOption* options, + Index type_index) = 0; + virtual void OnCanonLower(Index func_index, + uint32_t option_count, + ComponentCanonOption* options) = 0; + virtual void OnCanonType(ComponentCanon canon, + Index type_index) = 0; + + virtual void OnImport(const ComponentStringLoc& name, + nonstd::string_view* version_suffix, + const ComponentExternalInfo& external_info) = 0; + + virtual void OnExport(const ComponentStringLoc& name, + nonstd::string_view* version_suffix, + ComponentExternalInfo* external_info, + ComponentExportInfo* export_info) = 0; + + const std::string& WalrusParseError() + { + return m_walrusParseError; + } + +protected: + std::string m_walrusParseError; +}; + enum FeatureFlagValue : uint32_t { enableWebAssembly3 = 1 << 0, }; std::string ReadWasmBinary(const std::string& filename, const uint8_t *data, size_t size, WASMBinaryReaderDelegate* delegate, const uint32_t featureFlags); +std::string ReadWasmComponentBinary(const std::string& filename, const uint8_t *data, size_t size, WASMComponentBinaryReaderDelegate* delegate, const uint32_t featureFlags); } // namespace wabt diff --git a/third_party/wabt/include/wabt/wast-lexer.h b/third_party/wabt/include/wabt/wast-lexer.h index ef82aec1a..1399ce18d 100644 --- a/third_party/wabt/include/wabt/wast-lexer.h +++ b/third_party/wabt/include/wabt/wast-lexer.h @@ -48,6 +48,7 @@ class WastLexer { Errors*); Token GetToken(); + bool IsComponent(); nonstd::string_view Filename() const { return filename_; } diff --git a/third_party/wabt/include/wabt/wast-parser.h b/third_party/wabt/include/wabt/wast-parser.h index 6489fb046..a269e114a 100644 --- a/third_party/wabt/include/wabt/wast-parser.h +++ b/third_party/wabt/include/wabt/wast-parser.h @@ -50,7 +50,6 @@ class WastParser { Result ParseModule(std::unique_ptr* out_module); Result ParseScript(std::unique_ptr