| OLD | NEW |
| 1 //===- NaClBitcodeTextReader.cpp - Read texual bitcode record list --------===// | 1 //===- NaClBitcodeTextReader.cpp - Read texual bitcode record list --------===// |
| 2 // | 2 // |
| 3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 // | 9 // |
| 10 // Implements bitcode reader from textual form. | 10 // Implements bitcode reader from textual form. |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 break; | 218 break; |
| 219 } | 219 } |
| 220 Records.push_back(make_unique<NaClBitcodeAbbrevRecord>( | 220 Records.push_back(make_unique<NaClBitcodeAbbrevRecord>( |
| 221 Abbrev, Code, Values)); | 221 Abbrev, Code, Values)); |
| 222 return std::error_code(); | 222 return std::error_code(); |
| 223 } | 223 } |
| 224 } | 224 } |
| 225 } | 225 } |
| 226 } | 226 } |
| 227 | 227 |
| 228 // Read textual bitcode records from Filename, and fill Buffer with | 228 } // end of anonymous namespace |
| 229 // corresponding bitcode. Return error_code describing success of | 229 |
| 230 // read. Verbose (if not nullptr) is used to generate more human | 230 std::error_code llvm::readNaClRecordTextAndBuildBitcode( |
| 231 // readable error messages than the text in the returned error | 231 StringRef Filename, SmallVectorImpl<char> &Buffer, raw_ostream *Verbose) { |
| 232 // message. | |
| 233 static std::error_code ReadRecordTextAndBuildBitcode( | |
| 234 StringRef Filename, SmallVectorImpl<char> &Buffer, | |
| 235 raw_ostream *Verbose = nullptr) { | |
| 236 // Open the input file with text records. | 232 // Open the input file with text records. |
| 237 ErrorOr<std::unique_ptr<MemoryBuffer>> | 233 ErrorOr<std::unique_ptr<MemoryBuffer>> |
| 238 MemBuf(MemoryBuffer::getFileOrSTDIN(Filename)); | 234 MemBuf(MemoryBuffer::getFileOrSTDIN(Filename)); |
| 239 if (!MemBuf) | 235 if (!MemBuf) |
| 240 return MemBuf.getError(); | 236 return MemBuf.getError(); |
| 241 | 237 |
| 242 // Read in the bitcode text records. | 238 // Read in the bitcode text records. |
| 243 std::unique_ptr<NaClBitcodeRecordList> Records(new NaClBitcodeRecordList()); | 239 std::unique_ptr<NaClBitcodeRecordList> Records(new NaClBitcodeRecordList()); |
| 244 if (std::error_code EC = | 240 if (std::error_code EC = |
| 245 readNaClTextBcRecordList(*Records, std::move(MemBuf.get()))) | 241 readNaClTextBcRecordList(*Records, std::move(MemBuf.get()))) |
| 246 return EC; | 242 return EC; |
| 247 | 243 |
| 248 // Write out the records into Buffer. | 244 // Write out the records into Buffer. |
| 249 NaClMungedBitcode Bitcode(std::move(Records)); | 245 NaClMungedBitcode Bitcode(std::move(Records)); |
| 250 NaClMungedBitcode::WriteFlags Flags; | 246 NaClMungedBitcode::WriteFlags Flags; |
| 251 if (Verbose) | 247 if (Verbose) |
| 252 Flags.setErrStream(*Verbose); | 248 Flags.setErrStream(*Verbose); |
| 253 bool AddHeader = true; | 249 bool AddHeader = true; |
| 254 if (!Bitcode.write(Buffer, AddHeader)) { | 250 if (!Bitcode.write(Buffer, AddHeader)) { |
| 255 return std::error_code(UnableToWriteBitcode, | 251 return std::error_code(UnableToWriteBitcode, |
| 256 ReaderErrorCategoryType()); | 252 ReaderErrorCategoryType()); |
| 257 } | 253 } |
| 258 return std::error_code(); | 254 return std::error_code(); |
| 259 } | 255 } |
| 260 | 256 |
| 261 } // end of anonymous namespace | |
| 262 | |
| 263 std::error_code llvm::readNaClTextBcRecordList( | 257 std::error_code llvm::readNaClTextBcRecordList( |
| 264 NaClBitcodeRecordList &RecordList, | 258 NaClBitcodeRecordList &RecordList, |
| 265 std::unique_ptr<MemoryBuffer> InputBuffer) { | 259 std::unique_ptr<MemoryBuffer> InputBuffer) { |
| 266 TextRecordParser Parser(RecordList, InputBuffer.get()); | 260 TextRecordParser Parser(RecordList, InputBuffer.get()); |
| 267 return Parser.read(); | 261 return Parser.read(); |
| 268 } | 262 } |
| 269 | 263 |
| 270 llvm::ErrorOr<llvm::Module *> | 264 llvm::ErrorOr<llvm::Module *> |
| 271 llvm::parseNaClBitcodeText(const std::string &Filename, LLVMContext &Context, | 265 llvm::parseNaClBitcodeText(const std::string &Filename, LLVMContext &Context, |
| 272 raw_ostream *Verbose) { | 266 raw_ostream *Verbose) { |
| 273 SmallVector<char, 1024> Buffer; | 267 SmallVector<char, 1024> Buffer; |
| 274 | 268 |
| 275 // Fill Buffer with corresponding bitcode records from Filename. | 269 // Fill Buffer with corresponding bitcode records from Filename. |
| 276 if (std::error_code EC = | 270 if (std::error_code EC = |
| 277 ReadRecordTextAndBuildBitcode(Filename, Buffer, Verbose)) | 271 readNaClRecordTextAndBuildBitcode(Filename, Buffer, Verbose)) |
| 278 return EC; | 272 return EC; |
| 279 | 273 |
| 280 // Parse buffer as ordinary binary bitcode file. | 274 // Parse buffer as ordinary binary bitcode file. |
| 281 StringRef BitcodeBuffer(Buffer.data(), Buffer.size()); | 275 StringRef BitcodeBuffer(Buffer.data(), Buffer.size()); |
| 282 MemoryBufferRef MemBufRef(BitcodeBuffer, Filename); | 276 MemoryBufferRef MemBufRef(BitcodeBuffer, Filename); |
| 283 return NaClParseBitcodeFile(MemBufRef, Context, Verbose); | 277 return NaClParseBitcodeFile(MemBufRef, Context, Verbose); |
| 284 } | 278 } |
| OLD | NEW |