OLD | NEW |
1 //===-- NaClBitcodeAnalyzer.cpp - Bitcode Analyzer ------------------------===// | 1 //===-- NaClBitcodeAnalyzer.cpp - Bitcode Analyzer ------------------------===// |
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 #define DEBUG_TYPE "nacl-bitcode-analyzer" | 10 #define DEBUG_TYPE "nacl-bitcode-analyzer" |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 int AnalyzeBitcodeInBuffer(const std::unique_ptr<MemoryBuffer> &Buf, | 401 int AnalyzeBitcodeInBuffer(const std::unique_ptr<MemoryBuffer> &Buf, |
402 raw_ostream &OS, | 402 raw_ostream &OS, |
403 const AnalysisDumpOptions &DumpOptions) { | 403 const AnalysisDumpOptions &DumpOptions) { |
404 DEBUG(dbgs() << "-> AnalyzeBitcodeInBuffer\n"); | 404 DEBUG(dbgs() << "-> AnalyzeBitcodeInBuffer\n"); |
405 | 405 |
406 if (Buf->getBufferSize() & 3) | 406 if (Buf->getBufferSize() & 3) |
407 return Error("Bitcode stream should be a multiple of 4 bytes in length"); | 407 return Error("Bitcode stream should be a multiple of 4 bytes in length"); |
408 | 408 |
409 const unsigned char *BufPtr = (const unsigned char *)Buf->getBufferStart(); | 409 const unsigned char *BufPtr = (const unsigned char *)Buf->getBufferStart(); |
410 const unsigned char *EndBufPtr = BufPtr + Buf->getBufferSize(); | 410 const unsigned char *EndBufPtr = BufPtr + Buf->getBufferSize(); |
| 411 const unsigned char *HeaderPtr = BufPtr; |
411 | 412 |
412 NaClBitcodeHeader Header; | 413 NaClBitcodeHeader Header; |
413 if (Header.Read(BufPtr, EndBufPtr)) | 414 if (Header.Read(HeaderPtr, EndBufPtr)) |
414 return Error("Invalid PNaCl bitcode header"); | 415 return Error("Invalid PNaCl bitcode header"); |
415 | 416 |
416 if (!Header.IsSupported()) | 417 if (!Header.IsSupported()) |
417 errs() << "Warning: " << Header.Unsupported() << "\n"; | 418 errs() << "Warning: " << Header.Unsupported() << "\n"; |
418 | 419 |
419 if (!Header.IsReadable()) | 420 if (!Header.IsReadable()) |
420 Error("Bitcode file is not readable"); | 421 Error("Bitcode file is not readable"); |
421 | 422 |
422 NaClBitstreamReader StreamFile(BufPtr, EndBufPtr); | 423 NaClBitstreamReader StreamFile(BufPtr, EndBufPtr, Header); |
423 NaClBitstreamCursor Stream(StreamFile); | 424 NaClBitstreamCursor Stream(StreamFile); |
424 | 425 |
425 unsigned NumTopBlocks = 0; | 426 unsigned NumTopBlocks = 0; |
426 | 427 |
427 // Print out header information. | 428 // Print out header information. |
428 for (size_t i = 0, limit = Header.NumberFields(); i < limit; ++i) { | 429 for (size_t i = 0, limit = Header.NumberFields(); i < limit; ++i) { |
429 OS << Header.GetField(i)->Contents() << "\n"; | 430 OS << Header.GetField(i)->Contents() << "\n"; |
430 } | 431 } |
431 if (Header.NumberFields()) OS << "\n"; | 432 if (Header.NumberFields()) OS << "\n"; |
432 | 433 |
(...skipping 27 matching lines...) Expand all Loading... |
460 ErrorOr<std::unique_ptr<MemoryBuffer>> ErrOrFile = | 461 ErrorOr<std::unique_ptr<MemoryBuffer>> ErrOrFile = |
461 MemoryBuffer::getFileOrSTDIN(InputFilename); | 462 MemoryBuffer::getFileOrSTDIN(InputFilename); |
462 if (std::error_code EC = ErrOrFile.getError()) | 463 if (std::error_code EC = ErrOrFile.getError()) |
463 return Error(Twine("Error reading '") + InputFilename + "': " + | 464 return Error(Twine("Error reading '") + InputFilename + "': " + |
464 EC.message()); | 465 EC.message()); |
465 | 466 |
466 return AnalyzeBitcodeInBuffer(ErrOrFile.get(), OS, DumpOptions); | 467 return AnalyzeBitcodeInBuffer(ErrOrFile.get(), OS, DumpOptions); |
467 } | 468 } |
468 | 469 |
469 } // namespace llvm | 470 } // namespace llvm |
OLD | NEW |