Parse a METADATA_BLOCK. If ModuleLevel is true then we are parsing module level metadata.
| 838 | /// Parse a METADATA_BLOCK. If ModuleLevel is true then we are parsing |
| 839 | /// module level metadata. |
| 840 | Error MetadataLoader::MetadataLoaderImpl::parseMetadata(bool ModuleLevel) { |
| 841 | if (!ModuleLevel && MetadataList.hasFwdRefs()) |
| 842 | return error("Invalid metadata: fwd refs into function blocks"); |
| 843 | |
| 844 | // Record the entry position so that we can jump back here and efficiently |
| 845 | // skip the whole block in case we lazy-load. |
| 846 | auto EntryPos = Stream.GetCurrentBitNo(); |
| 847 | |
| 848 | if (Stream.EnterSubBlock(bitc::METADATA_BLOCK_ID)) |
| 849 | return error("Invalid record"); |
| 850 | |
| 851 | SmallVector<uint64_t, 64> Record; |
| 852 | PlaceholderQueue Placeholders; |
| 853 | |
| 854 | // We lazy-load module-level metadata: we build an index for each record, and |
| 855 | // then load individual record as needed, starting with the named metadata. |
| 856 | if (ModuleLevel && IsImporting && MetadataList.empty() && |
| 857 | !DisableLazyLoading) { |
| 858 | auto SuccessOrErr = lazyLoadModuleMetadataBlock(); |
| 859 | if (!SuccessOrErr) |
| 860 | return SuccessOrErr.takeError(); |
| 861 | if (SuccessOrErr.get()) { |
| 862 | // An index was successfully created and we will be able to load metadata |
| 863 | // on-demand. |
| 864 | MetadataList.resize(MDStringRef.size() + |
| 865 | GlobalMetadataBitPosIndex.size()); |
| 866 | |
| 867 | // Reading the named metadata created forward references and/or |
| 868 | // placeholders, that we flush here. |
| 869 | resolveForwardRefsAndPlaceholders(Placeholders); |
| 870 | upgradeDebugInfo(); |
| 871 | // Return at the beginning of the block, since it is easy to skip it |
| 872 | // entirely from there. |
| 873 | Stream.ReadBlockEnd(); // Pop the abbrev block context. |
| 874 | Stream.JumpToBit(EntryPos); |
| 875 | if (Stream.SkipBlock()) |
| 876 | return error("Invalid record"); |
| 877 | return Error::success(); |
| 878 | } |
| 879 | // Couldn't load an index, fallback to loading all the block "old-style". |
| 880 | } |
| 881 | |
| 882 | unsigned NextMetadataNo = MetadataList.size(); |
| 883 | |
| 884 | // Read all the records. |
| 885 | while (true) { |
| 886 | BitstreamEntry Entry = Stream.advanceSkippingSubblocks(); |
| 887 | |
| 888 | switch (Entry.Kind) { |
| 889 | case BitstreamEntry::SubBlock: // Handled for us already. |
| 890 | case BitstreamEntry::Error: |
| 891 | return error("Malformed block"); |
| 892 | case BitstreamEntry::EndBlock: |
| 893 | resolveForwardRefsAndPlaceholders(Placeholders); |
| 894 | upgradeDebugInfo(); |
| 895 | return Error::success(); |
| 896 | case BitstreamEntry::Record: |
| 897 | // The interesting case. |
nothing calls this directly
no test coverage detected