@@ -78,6 +78,40 @@ enum class TableInitExprStatus {
7878 TableWithoutInitExpression,
7979};
8080
81+ struct ComponentNamedType {
82+ std::string_view name;
83+ ComponentType type;
84+ };
85+
86+ struct ComponentNamedSort {
87+ std::string_view name;
88+ ComponentBinarySort sort;
89+ ComponentBinaryCoreSort core_sort;
90+ Index index;
91+ };
92+
93+ struct ComponentExternalInfo {
94+ ComponentBinarySort sort;
95+ ComponentBinaryCoreSort core_sort;
96+ ComponentBinaryExternal external;
97+ Index index;
98+ };
99+
100+ struct ComponentExportInfo {
101+ ComponentBinarySort sort;
102+ ComponentBinaryCoreSort core_sort;
103+ Index index;
104+ };
105+
106+ struct ComponentNamedExportInfo {
107+ std::string_view name;
108+ std::string_view version_suffix;
109+ ComponentBinarySort sort;
110+ ComponentBinaryCoreSort core_sort;
111+ bool has_version_suffix;
112+ Index index;
113+ };
114+
81115class BinaryReaderDelegate {
82116 public:
83117 struct State {
@@ -558,11 +592,92 @@ class BinaryReaderDelegate {
558592 const State* state = nullptr ;
559593};
560594
595+ class ComponentBinaryReaderDelegate {
596+ public:
597+ virtual ~ComponentBinaryReaderDelegate () {}
598+
599+ virtual bool OnError (const Error&) = 0;
600+ virtual void OnSetState (const BinaryReaderDelegate::State* s) { state = s; }
601+
602+ virtual Result OnCoreModule (const void * data,
603+ size_t size,
604+ const ReadBinaryOptions& options) = 0;
605+ virtual Result BeginComponent (uint32_t version, size_t depth) = 0;
606+ virtual Result EndComponent () = 0;
607+
608+ virtual Result BeginCoreInstanceSection (uint32_t count) = 0;
609+ virtual Result EndCoreInstanceSection () = 0;
610+ virtual Result OnCoreInstance (uint32_t module_index,
611+ uint32_t argument_count,
612+ ComponentNamedSort* arguments) = 0;
613+ virtual Result OnInlineCoreInstance (uint32_t argument_count,
614+ ComponentNamedSort* arguments) = 0;
615+
616+ virtual Result BeginInstanceSection (uint32_t count) = 0;
617+ virtual Result EndInstanceSection () = 0;
618+ virtual Result OnInstance (uint32_t module_index,
619+ uint32_t argument_count,
620+ ComponentNamedSort* arguments) = 0;
621+ virtual Result OnInlineInstance (uint32_t argument_count,
622+ ComponentNamedExportInfo* arguments) = 0;
623+
624+ virtual Result BeginAliasSection (uint32_t count) = 0;
625+ virtual Result EndAliasSection () = 0;
626+ virtual Result OnAliasExport (ComponentBinarySort sort,
627+ ComponentBinaryCoreSort core_sort,
628+ uint32_t instance_index,
629+ std::string_view export_name) = 0;
630+ virtual Result OnAliasOuter (ComponentBinarySort sort,
631+ ComponentBinaryCoreSort core_sort,
632+ uint32_t counter,
633+ uint32_t index) = 0;
634+
635+ virtual Result BeginTypeSection (uint32_t count) = 0;
636+ virtual Result EndTypeSection () = 0;
637+ virtual Result OnPrimitiveType (ComponentType type) = 0;
638+ virtual Result OnRecordType (uint32_t field_count,
639+ ComponentNamedType* fields) = 0;
640+ virtual Result OnVariantType (uint32_t case_count,
641+ ComponentNamedType* cases) = 0;
642+ virtual Result OnListType (ComponentType type) = 0;
643+ virtual Result OnListFixedType (ComponentType type, uint32_t size) = 0;
644+ virtual Result OnOptionType (ComponentType type) = 0;
645+ virtual Result OnResultType (ComponentType result, ComponentType error) = 0;
646+ virtual Result OnOwnType (Index index) = 0;
647+ virtual Result OnBorrowType (Index index) = 0;
648+ virtual Result OnFuncType (ComponentBinaryType type,
649+ uint32_t param_count,
650+ ComponentNamedType* params,
651+ ComponentType result) = 0;
652+ virtual Result BeginInstanceType (uint32_t count) = 0;
653+ virtual Result EndInstanceType () = 0;
654+ virtual Result BeginComponentType (uint32_t count) = 0;
655+ virtual Result EndComponentType () = 0;
656+
657+ virtual Result BeginImportSection (uint32_t count) = 0;
658+ virtual Result EndImportSection () = 0;
659+ virtual Result BeginExportSection (uint32_t count) = 0;
660+ virtual Result EndExportSection () = 0;
661+ virtual Result OnImport (std::string_view external_name,
662+ std::string_view* version_suffix,
663+ ComponentExternalInfo* external_info) = 0;
664+ virtual Result OnExport (std::string_view external_name,
665+ std::string_view* version_suffix,
666+ ComponentExternalInfo* external_info,
667+ ComponentExportInfo* export_info) = 0;
668+ const BinaryReaderDelegate::State* state = nullptr ;
669+ };
670+
561671Result ReadBinary (const void * data,
562672 size_t size,
563673 BinaryReaderDelegate* reader,
564674 const ReadBinaryOptions& options);
565675
676+ Result ReadBinaryComponent (const void * data,
677+ size_t size,
678+ ComponentBinaryReaderDelegate* component_delegate,
679+ const ReadBinaryOptions& options);
680+
566681size_t ReadU32Leb128 (const uint8_t * ptr,
567682 const uint8_t * end,
568683 uint32_t * out_value);
0 commit comments