}
}
-std::error_code BitcodeReader::ParseModuleTriple(std::string &Triple) {
+ErrorOr<std::string> BitcodeReader::parseModuleTriple() {
if (Stream.EnterSubBlock(bitc::MODULE_BLOCK_ID))
return Error(InvalidRecord);
SmallVector<uint64_t, 64> Record;
+ std::string Triple;
// Read all the records for this module.
while (1) {
BitstreamEntry Entry = Stream.advanceSkippingSubblocks();
}
Record.clear();
}
+ return Triple;
}
-std::error_code BitcodeReader::ParseTriple(std::string &Triple) {
+ErrorOr<std::string> BitcodeReader::parseTriple() {
if (std::error_code EC = InitStream())
return EC;
case BitstreamEntry::SubBlock:
if (Entry.ID == bitc::MODULE_BLOCK_ID)
- return ParseModuleTriple(Triple);
+ return parseModuleTriple();
// Ignore other sub-blocks.
if (Stream.SkipBlock())
std::string llvm::getBitcodeTargetTriple(MemoryBuffer *Buffer,
LLVMContext &Context) {
BitcodeReader *R = new BitcodeReader(Buffer, Context);
-
- std::string Triple("");
- R->ParseTriple(Triple);
-
+ ErrorOr<std::string> Triple = R->parseTriple();
R->releaseBuffer();
delete R;
- return Triple;
+ if (Triple.getError())
+ return "";
+ return Triple.get();
}
/// @brief Cheap mechanism to just extract module triple
/// @returns true if an error occurred.
- std::error_code ParseTriple(std::string &Triple);
+ ErrorOr<std::string> parseTriple();
static uint64_t decodeSignRotatedValue(uint64_t V);
std::error_code ResolveGlobalAndAliasInits();
std::error_code ParseMetadata();
std::error_code ParseMetadataAttachment();
- std::error_code ParseModuleTriple(std::string &Triple);
+ ErrorOr<std::string> parseModuleTriple();
std::error_code ParseUseLists();
std::error_code InitStream();
std::error_code InitStreamFromBuffer();