summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff options
context:
space:
mode:
authorMehdi Amini <mehdi.amini@apple.com>2015-11-09 02:46:41 +0000
committerMehdi Amini <mehdi.amini@apple.com>2015-11-09 02:46:41 +0000
commit3383ccc4003a685476be4eb5786539648c33ba90 (patch)
tree648d0da37148e341872d478e657c2800c0929bf1 /llvm/lib/Bitcode/Reader/BitcodeReader.cpp
parent247662b766bb7c60d5cc6ab12eeb30055e5caef4 (diff)
downloadbcm5719-llvm-3383ccc4003a685476be4eb5786539648c33ba90.tar.gz
bcm5719-llvm-3383ccc4003a685476be4eb5786539648c33ba90.zip
Add a method to the BitcodeReader to parse only the identification block
Summary: Mimic parseTriple(); and exposes it to LTOModule.cpp Reviewers: dexonsmith, rafael Subscribers: llvm-commits From: Mehdi Amini <mehdi.amini@apple.com> llvm-svn: 252442
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 8920b6ed460..7e760e25784 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -271,6 +271,9 @@ public:
/// \returns true if an error occurred.
ErrorOr<std::string> parseTriple();
+ /// Cheap mechanism to just extract the identification block out of bitcode.
+ ErrorOr<std::string> parseIdentificationBlock();
+
static uint64_t decodeSignRotatedValue(uint64_t V);
/// Materialize any deferred Metadata block.
@@ -3729,6 +3732,41 @@ ErrorOr<std::string> BitcodeReader::parseTriple() {
}
}
+ErrorOr<std::string> BitcodeReader::parseIdentificationBlock() {
+ if (std::error_code EC = initStream(nullptr))
+ return EC;
+
+ // Sniff for the signature.
+ if (!hasValidBitcodeHeader(Stream))
+ return error("Invalid bitcode signature");
+
+ // We expect a number of well-defined blocks, though we don't necessarily
+ // need to understand them all.
+ while (1) {
+ BitstreamEntry Entry = Stream.advance();
+ switch (Entry.Kind) {
+ case BitstreamEntry::Error:
+ return error("Malformed block");
+ case BitstreamEntry::EndBlock:
+ return std::error_code();
+
+ case BitstreamEntry::SubBlock:
+ if (Entry.ID == bitc::IDENTIFICATION_BLOCK_ID) {
+ if (std::error_code EC = parseBitcodeVersion())
+ return EC;
+ return ProducerIdentification;
+ }
+ // Ignore other sub-blocks.
+ if (Stream.SkipBlock())
+ return error("Malformed block");
+ continue;
+ case BitstreamEntry::Record:
+ Stream.skipRecord(Entry.ID);
+ continue;
+ }
+ }
+}
+
/// Parse metadata attachments.
std::error_code BitcodeReader::parseMetadataAttachment(Function &F) {
if (Stream.EnterSubBlock(bitc::METADATA_ATTACHMENT_ID))
@@ -5835,6 +5873,17 @@ llvm::getBitcodeTargetTriple(MemoryBufferRef Buffer, LLVMContext &Context,
return Triple.get();
}
+std::string
+llvm::getBitcodeProducerString(MemoryBufferRef Buffer, LLVMContext &Context,
+ DiagnosticHandlerFunction DiagnosticHandler) {
+ std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(Buffer, false);
+ BitcodeReader R(Buf.release(), Context, DiagnosticHandler);
+ ErrorOr<std::string> ProducerString = R.parseIdentificationBlock();
+ if (ProducerString.getError())
+ return "";
+ return ProducerString.get();
+}
+
// Parse the specified bitcode buffer, returning the function info index.
// If IsLazy is false, parse the entire function summary into
// the index. Otherwise skip the function summary section, and only create
OpenPOWER on IntegriCloud