|
23 | 23 |
|
24 | 24 | #include "wabt/binary.h" |
25 | 25 | #include "wabt/common.h" |
| 26 | +#include "wabt/component.h" |
26 | 27 | #include "wabt/error.h" |
27 | 28 | #include "wabt/feature.h" |
28 | 29 | #include "wabt/opcode.h" |
@@ -558,11 +559,112 @@ class BinaryReaderDelegate { |
558 | 559 | const State* state = nullptr; |
559 | 560 | }; |
560 | 561 |
|
| 562 | +class ComponentBinaryReaderDelegate { |
| 563 | + public: |
| 564 | + virtual ~ComponentBinaryReaderDelegate() {} |
| 565 | + |
| 566 | + virtual bool OnError(const Error&) = 0; |
| 567 | + virtual void OnSetState(const BinaryReaderDelegate::State* s) { state = s; } |
| 568 | + |
| 569 | + virtual Result OnCoreModule(const void* data, |
| 570 | + size_t size, |
| 571 | + const ReadBinaryOptions& options) = 0; |
| 572 | + virtual Result BeginComponent(uint32_t version, size_t depth) = 0; |
| 573 | + virtual Result EndComponent() = 0; |
| 574 | + |
| 575 | + virtual Result BeginCoreInstanceSection(uint32_t count) = 0; |
| 576 | + virtual Result EndCoreInstanceSection() = 0; |
| 577 | + virtual Result OnCoreInstance(uint32_t module_index, |
| 578 | + uint32_t argument_count, |
| 579 | + ComponentNamedSort* arguments) = 0; |
| 580 | + virtual Result OnInlineCoreInstance(uint32_t argument_count, |
| 581 | + ComponentNamedSort* arguments) = 0; |
| 582 | + |
| 583 | + virtual Result BeginInstanceSection(uint32_t count) = 0; |
| 584 | + virtual Result EndInstanceSection() = 0; |
| 585 | + virtual Result OnInstance(uint32_t module_index, |
| 586 | + uint32_t argument_count, |
| 587 | + ComponentNamedSort* arguments) = 0; |
| 588 | + virtual Result OnInlineInstance(uint32_t argument_count, |
| 589 | + ComponentNamedExportInfo* arguments) = 0; |
| 590 | + |
| 591 | + virtual Result BeginAliasSection(uint32_t count) = 0; |
| 592 | + virtual Result EndAliasSection() = 0; |
| 593 | + virtual Result OnAliasExport(ComponentSort sort, |
| 594 | + uint32_t instance_index, |
| 595 | + std::string_view name) = 0; |
| 596 | + virtual Result OnAliasCoreExport(ComponentSort sort, |
| 597 | + uint32_t core_instance_index, |
| 598 | + std::string_view name) = 0; |
| 599 | + virtual Result OnAliasOuter(ComponentSort sort, |
| 600 | + uint32_t counter, |
| 601 | + uint32_t index) = 0; |
| 602 | + |
| 603 | + virtual Result BeginTypeSection(uint32_t count) = 0; |
| 604 | + virtual Result EndTypeSection() = 0; |
| 605 | + virtual Result OnPrimitiveType(ComponentType type) = 0; |
| 606 | + virtual Result OnRecordType(uint32_t field_count, |
| 607 | + ComponentNamedType* fields) = 0; |
| 608 | + virtual Result OnVariantType(uint32_t case_count, |
| 609 | + ComponentNamedType* cases) = 0; |
| 610 | + virtual Result OnListType(ComponentType type) = 0; |
| 611 | + virtual Result OnListFixedType(ComponentType type, uint32_t size) = 0; |
| 612 | + virtual Result OnTupleType(uint32_t type_count, ComponentType* types) = 0; |
| 613 | + virtual Result OnFlagsType(uint32_t flag_count, std::string_view* flags) = 0; |
| 614 | + virtual Result OnEnumType(uint32_t enum_count, std::string_view* enums) = 0; |
| 615 | + virtual Result OnOptionType(ComponentType type) = 0; |
| 616 | + virtual Result OnResultType(ComponentType result, ComponentType error) = 0; |
| 617 | + virtual Result OnOwnType(Index index) = 0; |
| 618 | + virtual Result OnBorrowType(Index index) = 0; |
| 619 | + virtual Result OnStreamType(ComponentType type) = 0; |
| 620 | + virtual Result OnFutureType(ComponentType type) = 0; |
| 621 | + virtual Result OnFuncType(ComponentTypeDef type, |
| 622 | + uint32_t param_count, |
| 623 | + ComponentNamedType* params, |
| 624 | + ComponentType result) = 0; |
| 625 | + virtual Result BeginInstanceType(uint32_t count) = 0; |
| 626 | + virtual Result EndInstanceType() = 0; |
| 627 | + virtual Result BeginComponentType(uint32_t count) = 0; |
| 628 | + virtual Result EndComponentType() = 0; |
| 629 | + |
| 630 | + virtual Result BeginCanonSection(uint32_t count) = 0; |
| 631 | + virtual Result EndCanonSection() = 0; |
| 632 | + virtual Result OnCanonLift(Index core_func_index, |
| 633 | + uint32_t option_count, |
| 634 | + ComponentCanonOption* options, |
| 635 | + Index type_index) = 0; |
| 636 | + virtual Result OnCanonLower(Index func_index, |
| 637 | + uint32_t option_count, |
| 638 | + ComponentCanonOption* options) = 0; |
| 639 | + virtual Result OnCanonType(ComponentBinaryCanon canon, Index type_index) = 0; |
| 640 | + |
| 641 | + virtual Result BeginImportSection(uint32_t count) = 0; |
| 642 | + virtual Result EndImportSection() = 0; |
| 643 | + virtual Result OnImport(std::string_view external_name, |
| 644 | + std::string_view* version_suffix, |
| 645 | + ComponentExternalInfo* external_info) = 0; |
| 646 | + |
| 647 | + virtual Result BeginExportSection(uint32_t count) = 0; |
| 648 | + virtual Result EndExportSection() = 0; |
| 649 | + virtual Result OnExport(std::string_view external_name, |
| 650 | + std::string_view* version_suffix, |
| 651 | + ComponentExternalInfo* external_info, |
| 652 | + ComponentExportInfo* export_info) = 0; |
| 653 | + const BinaryReaderDelegate::State* state = nullptr; |
| 654 | +}; |
| 655 | + |
561 | 656 | Result ReadBinary(const void* data, |
562 | 657 | size_t size, |
563 | 658 | BinaryReaderDelegate* reader, |
564 | 659 | const ReadBinaryOptions& options); |
565 | 660 |
|
| 661 | +Result ReadBinaryComponent(const void* data, |
| 662 | + size_t size, |
| 663 | + ComponentBinaryReaderDelegate* component_delegate, |
| 664 | + const ReadBinaryOptions& options); |
| 665 | + |
| 666 | +bool ReadBinaryIsComponent(const void* data, size_t size); |
| 667 | + |
566 | 668 | size_t ReadU32Leb128(const uint8_t* ptr, |
567 | 669 | const uint8_t* end, |
568 | 670 | uint32_t* out_value); |
|
0 commit comments