llvm.org GIT mirror llvm / c77a774
Revert "Convert a few std::strings to StringRef." This reverts commit r212342. We can get a StringRef into the current Record, but not one in the bitcode itself since the string is compressed in it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@212356 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 6 years ago
4 changed file(s) with 17 addition(s) and 29 deletion(s). Raw diff Collapse all Expand all
1313 #ifndef LLVM_BITCODE_READERWRITER_H
1414 #define LLVM_BITCODE_READERWRITER_H
1515
16 #include "llvm/ADT/StringRef.h"
1716 #include "llvm/Support/ErrorOr.h"
1817 #include
1918
4443 /// Read the header of the specified bitcode buffer and extract just the
4544 /// triple information. If successful, this returns a string and *does not*
4645 /// take ownership of 'buffer'. On error, this returns "".
47 StringRef getBitcodeTargetTriple(MemoryBuffer *Buffer, LLVMContext &Context);
46 std::string getBitcodeTargetTriple(MemoryBuffer *Buffer,
47 LLVMContext &Context);
4848
4949 /// Read the specified bitcode file, returning the module.
5050 /// This method *never* takes ownership of Buffer.
6969 Result += (char)Record[i];
7070 return false;
7171 }
72
73 ErrorOr BitcodeReader::convertToStringRef(ArrayRef Record,
74 unsigned Idx) {
75 if (Idx > Record.size())
76 return Error(InvalidRecord);
77
78 return StringRef((char*)&Record[Idx], Record.size() - Idx);
79 }
80
8172
8273 static GlobalValue::LinkageTypes GetDecodedLinkage(unsigned Val) {
8374 switch (Val) {
21242115 }
21252116 }
21262117
2127 ErrorOr<StringRef> BitcodeReader::parseModuleTriple() {
2118 ErrorOr<std::string> BitcodeReader::parseModuleTriple() {
21282119 if (Stream.EnterSubBlock(bitc::MODULE_BLOCK_ID))
21292120 return Error(InvalidRecord);
21302121
21312122 SmallVector Record;
21322123
2133 StringRef Triple;
2124 std::string Triple;
21342125 // Read all the records for this module.
21352126 while (1) {
21362127 BitstreamEntry Entry = Stream.advanceSkippingSubblocks();
21502141 switch (Stream.readRecord(Entry.ID, Record)) {
21512142 default: break; // Default behavior, ignore unknown content.
21522143 case bitc::MODULE_CODE_TRIPLE: { // TRIPLE: [strchr x N]
2153 ErrorOr S = convertToStringRef(Record, 0);
2154 if (std::error_code EC = S.getError())
2155 return EC;
2156 Triple = S.get();
2144 std::string S;
2145 if (ConvertToString(Record, 0, S))
2146 return Error(InvalidRecord);
2147 Triple = S;
21572148 break;
21582149 }
21592150 }
21622153 return Triple;
21632154 }
21642155
2165 ErrorOr<StringRef> BitcodeReader::parseTriple() {
2156 ErrorOr<std::string> BitcodeReader::parseTriple() {
21662157 if (std::error_code EC = InitStream())
21672158 return EC;
21682159
34773468 return M;
34783469 }
34793470
3480 StringRef llvm::getBitcodeTargetTriple(MemoryBuffer *Buffer,
3481 LLVMContext &Context) {
3471 std::string llvm::getBitcodeTargetTriple(MemoryBuffer *Buffer,
3472 LLVMContext &Context) {
34823473 BitcodeReader *R = new BitcodeReader(Buffer, Context);
3483 ErrorOr<StringRef> Triple = R->parseTriple();
3474 ErrorOr<std::string> Triple = R->parseTriple();
34843475 R->releaseBuffer();
34853476 delete R;
34863477 if (Triple.getError())
194194 bool UseRelativeIDs;
195195
196196 static const std::error_category &BitcodeErrorCategory();
197
198 static ErrorOr convertToStringRef(ArrayRef Record,
199 unsigned Idx);
200197
201198 public:
202199 enum ErrorType {
222219 InvalidValue // Invalid version, inst number, attr number, etc
223220 };
224221
225 static std::error_code Error(ErrorType E) {
222 std::error_code Error(ErrorType E) {
226223 return std::error_code(E, BitcodeErrorCategory());
227224 }
228225
254251
255252 /// @brief Cheap mechanism to just extract module triple
256253 /// @returns true if an error occurred.
257 ErrorOr<StringRef> parseTriple();
254 ErrorOr<std::string> parseTriple();
258255
259256 static uint64_t decodeSignRotatedValue(uint64_t V);
260257
356353 std::error_code ResolveGlobalAndAliasInits();
357354 std::error_code ParseMetadata();
358355 std::error_code ParseMetadataAttachment();
359 ErrorOr<StringRef> parseModuleTriple();
356 ErrorOr<std::string> parseModuleTriple();
360357 std::error_code ParseUseLists();
361358 std::error_code InitStream();
362359 std::error_code InitStreamFromBuffer();
6262
6363 bool LTOModule::isBitcodeForTarget(MemoryBuffer *buffer,
6464 StringRef triplePrefix) {
65 StringRef Triple = getBitcodeTargetTriple(buffer, getGlobalContext());
66 return Triple.startswith(triplePrefix);
65 std::string Triple = getBitcodeTargetTriple(buffer, getGlobalContext());
66 return StringRef(Triple).startswith(triplePrefix);
6767 }
6868
6969 LTOModule *LTOModule::createFromFile(const char *path, TargetOptions options,