|
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,135 @@ 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(const ComponentIndexLoc& module_index, |
| 578 | + uint32_t argument_count) = 0; |
| 579 | + virtual Result OnCoreInstanceArg(const ComponentStringLoc& name, |
| 580 | + ComponentSort sort, |
| 581 | + const ComponentIndexLoc& index) = 0; |
| 582 | + virtual Result OnInlineCoreInstance(uint32_t argument_count) = 0; |
| 583 | + virtual Result OnInlineCoreInstanceArg(const ComponentStringLoc& name, |
| 584 | + ComponentSort sort, |
| 585 | + const ComponentIndexLoc& index) = 0; |
| 586 | + |
| 587 | + virtual Result BeginInstanceSection(uint32_t count) = 0; |
| 588 | + virtual Result EndInstanceSection() = 0; |
| 589 | + virtual Result OnInstance(const ComponentIndexLoc& component_index, |
| 590 | + uint32_t argument_count) = 0; |
| 591 | + virtual Result OnInstanceArg(const ComponentStringLoc& name, |
| 592 | + ComponentSort sort, |
| 593 | + const ComponentIndexLoc& index) = 0; |
| 594 | + virtual Result OnInlineInstance(uint32_t argument_count) = 0; |
| 595 | + virtual Result OnInlineInstanceArg(const ComponentStringLoc& name, |
| 596 | + std::string_view* version_suffix, |
| 597 | + ComponentSort sort, |
| 598 | + const ComponentIndexLoc& index) = 0; |
| 599 | + |
| 600 | + virtual Result BeginAliasSection(uint32_t count) = 0; |
| 601 | + virtual Result EndAliasSection() = 0; |
| 602 | + virtual Result OnAliasExport(ComponentSort sort, |
| 603 | + const ComponentIndexLoc& instance_index, |
| 604 | + const ComponentStringLoc& name) = 0; |
| 605 | + virtual Result OnAliasCoreExport(ComponentSort sort, |
| 606 | + const ComponentIndexLoc& core_instance_index, |
| 607 | + const ComponentStringLoc& name) = 0; |
| 608 | + virtual Result OnAliasOuter(ComponentSort sort, |
| 609 | + uint32_t counter, |
| 610 | + uint32_t index) = 0; |
| 611 | + |
| 612 | + virtual Result BeginTypeSection(uint32_t count) = 0; |
| 613 | + virtual Result EndTypeSection() = 0; |
| 614 | + virtual Result OnPrimitiveType(const ComponentType& type) = 0; |
| 615 | + virtual Result OnRecordType(uint32_t field_count) = 0; |
| 616 | + virtual Result OnRecordField(const ComponentStringLoc& field_name, |
| 617 | + const ComponentTypeLoc& field_type) = 0; |
| 618 | + virtual Result OnVariantType(uint32_t case_count) = 0; |
| 619 | + virtual Result OnVariantCase(const ComponentStringLoc& case_name, |
| 620 | + const ComponentTypeLoc& case_type) = 0; |
| 621 | + virtual Result OnListType(const ComponentTypeLoc& type) = 0; |
| 622 | + virtual Result OnListFixedType(const ComponentTypeLoc& type, |
| 623 | + uint32_t size) = 0; |
| 624 | + virtual Result OnTupleType(uint32_t item_count) = 0; |
| 625 | + virtual Result OnTupleItem(const ComponentTypeLoc& item) = 0; |
| 626 | + virtual Result OnFlagsType(uint32_t label_count) = 0; |
| 627 | + virtual Result OnFlagsLabel(const ComponentStringLoc& label) = 0; |
| 628 | + virtual Result OnEnumType(uint32_t label_count) = 0; |
| 629 | + virtual Result OnEnumLabel(const ComponentStringLoc& label) = 0; |
| 630 | + virtual Result OnOptionType(const ComponentTypeLoc& type) = 0; |
| 631 | + virtual Result OnResultType(const ComponentTypeLoc& result_type, |
| 632 | + const ComponentTypeLoc& error_type) = 0; |
| 633 | + virtual Result OnOwnType(const ComponentIndexLoc& index) = 0; |
| 634 | + virtual Result OnBorrowType(const ComponentIndexLoc& index) = 0; |
| 635 | + virtual Result OnStreamType(const ComponentTypeLoc& type) = 0; |
| 636 | + virtual Result OnFutureType(const ComponentTypeLoc& type) = 0; |
| 637 | + virtual Result OnFuncType(ComponentTypeDef type, |
| 638 | + uint32_t param_count) = 0; |
| 639 | + virtual Result OnFuncParam(ComponentStringLoc name, |
| 640 | + ComponentTypeLoc type) = 0; |
| 641 | + virtual Result OnFuncResult(const ComponentTypeLoc& type) = 0; |
| 642 | + virtual Result OnResourceType(ComponentResourceRep rep, |
| 643 | + const ComponentIndexLoc& dtor) = 0; |
| 644 | + virtual Result OnResourceAsyncType(ComponentResourceRep rep, |
| 645 | + const ComponentIndexLoc& dtor, |
| 646 | + const ComponentIndexLoc& callback) = 0; |
| 647 | + virtual Result BeginInstanceType(uint32_t count) = 0; |
| 648 | + virtual Result EndInstanceType() = 0; |
| 649 | + virtual Result BeginComponentType(uint32_t count) = 0; |
| 650 | + virtual Result EndComponentType() = 0; |
| 651 | + |
| 652 | + virtual Result BeginCanonSection(uint32_t count) = 0; |
| 653 | + virtual Result EndCanonSection() = 0; |
| 654 | + virtual Result OnCanonLift(const ComponentIndexLoc& core_func_index, |
| 655 | + uint32_t option_count, |
| 656 | + ComponentCanonOption* options, |
| 657 | + const ComponentIndexLoc& type_index) = 0; |
| 658 | + virtual Result OnCanonLower(const ComponentIndexLoc& func_index, |
| 659 | + uint32_t option_count, |
| 660 | + ComponentCanonOption* options) = 0; |
| 661 | + virtual Result OnCanonType(ComponentCanon canon, |
| 662 | + const ComponentIndexLoc& type_index) = 0; |
| 663 | + |
| 664 | + virtual Result BeginImportSection(uint32_t count) = 0; |
| 665 | + virtual Result EndImportSection() = 0; |
| 666 | + virtual Result OnImport(const ComponentStringLoc& name, |
| 667 | + std::string_view* version_suffix, |
| 668 | + const ComponentExternalInfo& external_info) = 0; |
| 669 | + |
| 670 | + virtual Result BeginExportSection(uint32_t count) = 0; |
| 671 | + virtual Result EndExportSection() = 0; |
| 672 | + virtual Result OnExport(const ComponentStringLoc& name, |
| 673 | + std::string_view* version_suffix, |
| 674 | + ComponentExternalInfo* external_info, |
| 675 | + ComponentExportInfo* export_info) = 0; |
| 676 | + const BinaryReaderDelegate::State* state = nullptr; |
| 677 | +}; |
| 678 | + |
561 | 679 | Result ReadBinary(const void* data, |
562 | 680 | size_t size, |
563 | 681 | BinaryReaderDelegate* reader, |
564 | 682 | const ReadBinaryOptions& options); |
565 | 683 |
|
| 684 | +Result ReadBinaryComponent(const void* data, |
| 685 | + size_t size, |
| 686 | + ComponentBinaryReaderDelegate* component_delegate, |
| 687 | + const ReadBinaryOptions& options); |
| 688 | + |
| 689 | +bool ReadBinaryIsComponent(const void* data, size_t size); |
| 690 | + |
566 | 691 | size_t ReadU32Leb128(const uint8_t* ptr, |
567 | 692 | const uint8_t* end, |
568 | 693 | uint32_t* out_value); |
|
0 commit comments