OLD | NEW |
1 //===-- NaClObjDump.cpp - Dump PNaCl bitcode contents ---------------------===// | 1 //===-- NaClObjDump.cpp - Dump PNaCl bitcode contents ---------------------===// |
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 #include "llvm/ADT/STLExtras.h" | 10 #include "llvm/ADT/STLExtras.h" |
(...skipping 3513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3524 naclbitc::ObjDumpStream ObjDump(Output, !NoRecords, !NoAssembly); | 3524 naclbitc::ObjDumpStream ObjDump(Output, !NoRecords, !NoAssembly); |
3525 | 3525 |
3526 if (MemBuf.getBufferSize() % 4 != 0) { | 3526 if (MemBuf.getBufferSize() % 4 != 0) { |
3527 ObjDump.Error() | 3527 ObjDump.Error() |
3528 << "Bitcode stream should be a multiple of 4 bytes in length.\n"; | 3528 << "Bitcode stream should be a multiple of 4 bytes in length.\n"; |
3529 return true; | 3529 return true; |
3530 } | 3530 } |
3531 | 3531 |
3532 const unsigned char *BufPtr = (const unsigned char *)MemBuf.getBufferStart(); | 3532 const unsigned char *BufPtr = (const unsigned char *)MemBuf.getBufferStart(); |
3533 const unsigned char *EndBufPtr = BufPtr+MemBuf.getBufferSize(); | 3533 const unsigned char *EndBufPtr = BufPtr+MemBuf.getBufferSize(); |
3534 const unsigned char *HeaderPtr = BufPtr; | |
3535 | 3534 |
3536 // Read header and verify it is good. | 3535 // Read header and verify it is good. |
3537 NaClBitcodeHeader Header; | 3536 NaClBitcodeHeader Header; |
3538 if (Header.Read(HeaderPtr, EndBufPtr) || !Header.IsSupported()) { | 3537 if (Header.Read(BufPtr, EndBufPtr)) { |
3539 ObjDump.Error() << "Invalid PNaCl bitcode header.\n"; | 3538 ObjDump.Error() << "Invalid PNaCl bitcode header.\n"; |
3540 return true; | 3539 return true; |
3541 } | 3540 } |
| 3541 if (!Header.IsSupported()) { |
| 3542 ObjDump.Warning() << Header.Unsupported(); |
| 3543 if (!Header.IsReadable()) { |
| 3544 ObjDump.Error() << "Invalid PNaCl bitcode header.\n"; |
| 3545 return true; |
| 3546 } |
| 3547 } |
3542 | 3548 |
3543 // Create a bitstream reader to read the bitcode file. | 3549 // Create a bitstream reader to read the bitcode file. |
3544 NaClBitstreamReader InputStreamFile(BufPtr, EndBufPtr, | 3550 NaClBitstreamReader InputStreamFile(BufPtr, EndBufPtr, Header); |
3545 Header.getHeaderSize()); | |
3546 NaClBitstreamCursor InputStream(InputStreamFile); | 3551 NaClBitstreamCursor InputStream(InputStreamFile); |
3547 | 3552 |
3548 // Parse the the bitcode file. | 3553 // Parse the the bitcode file. |
3549 ::NaClDisTopLevelParser Parser(Header, InputStream, ObjDump); | 3554 ::NaClDisTopLevelParser Parser(Header, InputStream, ObjDump); |
3550 int NumBlocksRead = 0; | 3555 int NumBlocksRead = 0; |
3551 bool ErrorsFound = false; | 3556 bool ErrorsFound = false; |
3552 while (!InputStream.AtEndOfStream()) { | 3557 while (!InputStream.AtEndOfStream()) { |
3553 ++NumBlocksRead; | 3558 ++NumBlocksRead; |
3554 if (Parser.Parse()) ErrorsFound = true; | 3559 if (Parser.Parse()) ErrorsFound = true; |
3555 } | 3560 } |
3556 | 3561 |
3557 if (NumBlocksRead != 1) { | 3562 if (NumBlocksRead != 1) { |
3558 ObjDump.Error() << "Expected 1 top level block in bitcode: Found:" | 3563 ObjDump.Error() << "Expected 1 top level block in bitcode: Found:" |
3559 << NumBlocksRead << "\n"; | 3564 << NumBlocksRead << "\n"; |
3560 ErrorsFound = true; | 3565 ErrorsFound = true; |
3561 } | 3566 } |
3562 | 3567 |
3563 ObjDump.Flush(); | 3568 ObjDump.Flush(); |
3564 return ErrorsFound || Parser.GetNumErrors() > 0; | 3569 return ErrorsFound || Parser.GetNumErrors() > 0; |
3565 } | 3570 } |
3566 | 3571 |
3567 } | 3572 } |
OLD | NEW |