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; | |
jvoung (off chromium)
2015/05/08 17:55:01
I know Header.Read(x, ...) actually modifies x, bu
Karl
2015/05/08 21:09:00
I changed this a while back. The problem is that t
jvoung (off chromium)
2015/05/11 17:51:39
Thanks, that's easier to follow.
| |
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( |
424 getNonStreamedMemoryObject(BufPtr, EndBufPtr), Header); | |
423 NaClBitstreamCursor Stream(StreamFile); | 425 NaClBitstreamCursor Stream(StreamFile); |
424 | 426 |
425 unsigned NumTopBlocks = 0; | 427 unsigned NumTopBlocks = 0; |
426 | 428 |
427 // Print out header information. | 429 // Print out header information. |
428 for (size_t i = 0, limit = Header.NumberFields(); i < limit; ++i) { | 430 for (size_t i = 0, limit = Header.NumberFields(); i < limit; ++i) { |
429 OS << Header.GetField(i)->Contents() << "\n"; | 431 OS << Header.GetField(i)->Contents() << "\n"; |
430 } | 432 } |
431 if (Header.NumberFields()) OS << "\n"; | 433 if (Header.NumberFields()) OS << "\n"; |
432 | 434 |
(...skipping 27 matching lines...) Expand all Loading... | |
460 ErrorOr<std::unique_ptr<MemoryBuffer>> ErrOrFile = | 462 ErrorOr<std::unique_ptr<MemoryBuffer>> ErrOrFile = |
461 MemoryBuffer::getFileOrSTDIN(InputFilename); | 463 MemoryBuffer::getFileOrSTDIN(InputFilename); |
462 if (std::error_code EC = ErrOrFile.getError()) | 464 if (std::error_code EC = ErrOrFile.getError()) |
463 return Error(Twine("Error reading '") + InputFilename + "': " + | 465 return Error(Twine("Error reading '") + InputFilename + "': " + |
464 EC.message()); | 466 EC.message()); |
465 | 467 |
466 return AnalyzeBitcodeInBuffer(ErrOrFile.get(), OS, DumpOptions); | 468 return AnalyzeBitcodeInBuffer(ErrOrFile.get(), OS, DumpOptions); |
467 } | 469 } |
468 | 470 |
469 } // namespace llvm | 471 } // namespace llvm |
OLD | NEW |