#ifndef LLVM_BITCODE_READERWRITER_H
#define LLVM_BITCODE_READERWRITER_H
-#include "llvm/ADT/StringRef.h"
#include "llvm/Support/ErrorOr.h"
#include <string>
/// Read the header of the specified bitcode buffer and extract just the
/// triple information. If successful, this returns a string and *does not*
/// take ownership of 'buffer'. On error, this returns "".
- StringRef getBitcodeTargetTriple(MemoryBuffer *Buffer, LLVMContext &Context);
+ std::string getBitcodeTargetTriple(MemoryBuffer *Buffer,
+ LLVMContext &Context);
/// Read the specified bitcode file, returning the module.
/// This method *never* takes ownership of Buffer.
return false;
}
-ErrorOr<StringRef> BitcodeReader::convertToStringRef(ArrayRef<uint64_t> Record,
- unsigned Idx) {
- if (Idx > Record.size())
- return Error(InvalidRecord);
-
- return StringRef((char*)&Record[Idx], Record.size() - Idx);
-}
-
-
static GlobalValue::LinkageTypes GetDecodedLinkage(unsigned Val) {
switch (Val) {
default: // Map unknown/new linkages to external
}
}
-ErrorOr<StringRef> BitcodeReader::parseModuleTriple() {
+ErrorOr<std::string> BitcodeReader::parseModuleTriple() {
if (Stream.EnterSubBlock(bitc::MODULE_BLOCK_ID))
return Error(InvalidRecord);
SmallVector<uint64_t, 64> Record;
- StringRef Triple;
+ std::string Triple;
// Read all the records for this module.
while (1) {
BitstreamEntry Entry = Stream.advanceSkippingSubblocks();
switch (Stream.readRecord(Entry.ID, Record)) {
default: break; // Default behavior, ignore unknown content.
case bitc::MODULE_CODE_TRIPLE: { // TRIPLE: [strchr x N]
- ErrorOr<StringRef> S = convertToStringRef(Record, 0);
- if (std::error_code EC = S.getError())
- return EC;
- Triple = S.get();
+ std::string S;
+ if (ConvertToString(Record, 0, S))
+ return Error(InvalidRecord);
+ Triple = S;
break;
}
}
return Triple;
}
-ErrorOr<StringRef> BitcodeReader::parseTriple() {
+ErrorOr<std::string> BitcodeReader::parseTriple() {
if (std::error_code EC = InitStream())
return EC;
return M;
}
-StringRef llvm::getBitcodeTargetTriple(MemoryBuffer *Buffer,
- LLVMContext &Context) {
+std::string llvm::getBitcodeTargetTriple(MemoryBuffer *Buffer,
+ LLVMContext &Context) {
BitcodeReader *R = new BitcodeReader(Buffer, Context);
- ErrorOr<StringRef> Triple = R->parseTriple();
+ ErrorOr<std::string> Triple = R->parseTriple();
R->releaseBuffer();
delete R;
if (Triple.getError())
static const std::error_category &BitcodeErrorCategory();
- static ErrorOr<StringRef> convertToStringRef(ArrayRef<uint64_t> Record,
- unsigned Idx);
-
public:
enum ErrorType {
BitcodeStreamInvalidSize,
InvalidValue // Invalid version, inst number, attr number, etc
};
- static std::error_code Error(ErrorType E) {
+ std::error_code Error(ErrorType E) {
return std::error_code(E, BitcodeErrorCategory());
}
/// @brief Cheap mechanism to just extract module triple
/// @returns true if an error occurred.
- ErrorOr<StringRef> parseTriple();
+ ErrorOr<std::string> parseTriple();
static uint64_t decodeSignRotatedValue(uint64_t V);
std::error_code ResolveGlobalAndAliasInits();
std::error_code ParseMetadata();
std::error_code ParseMetadataAttachment();
- ErrorOr<StringRef> parseModuleTriple();
+ ErrorOr<std::string> parseModuleTriple();
std::error_code ParseUseLists();
std::error_code InitStream();
std::error_code InitStreamFromBuffer();
bool LTOModule::isBitcodeForTarget(MemoryBuffer *buffer,
StringRef triplePrefix) {
- StringRef Triple = getBitcodeTargetTriple(buffer, getGlobalContext());
- return Triple.startswith(triplePrefix);
+ std::string Triple = getBitcodeTargetTriple(buffer, getGlobalContext());
+ return StringRef(Triple).startswith(triplePrefix);
}
LTOModule *LTOModule::createFromFile(const char *path, TargetOptions options,