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 3517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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; | 3534 const unsigned char *HeaderPtr = BufPtr; |
3535 | 3535 |
3536 // Read header and verify it is good. | 3536 // Read header and verify it is good. |
3537 NaClBitcodeHeader Header; | 3537 NaClBitcodeHeader Header; |
3538 if (Header.Read(HeaderPtr, EndBufPtr) || !Header.IsSupported()) { | 3538 if (Header.Read(HeaderPtr, EndBufPtr)) { |
3539 ObjDump.Error() << "Invalid PNaCl bitcode header.\n"; | 3539 ObjDump.Error() << "Invalid PNaCl bitcode header.\n"; |
3540 return true; | 3540 return true; |
3541 } | 3541 } |
| 3542 if (!Header.IsSupported()) { |
| 3543 ObjDump.Warning() << Header.Unsupported(); |
| 3544 if (!Header.IsReadable()) { |
| 3545 ObjDump.Error() << "Invalid PNaCl bitcode header.\n"; |
| 3546 return true; |
| 3547 } |
| 3548 } |
3542 | 3549 |
3543 // Create a bitstream reader to read the bitcode file. | 3550 // Create a bitstream reader to read the bitcode file. |
3544 NaClBitstreamReader InputStreamFile(BufPtr, EndBufPtr, | 3551 NaClBitstreamReader InputStreamFile( |
3545 Header.getHeaderSize()); | 3552 getNonStreamedMemoryObject(BufPtr, EndBufPtr), Header); |
3546 NaClBitstreamCursor InputStream(InputStreamFile); | 3553 NaClBitstreamCursor InputStream(InputStreamFile); |
3547 | 3554 |
3548 // Parse the the bitcode file. | 3555 // Parse the the bitcode file. |
3549 ::NaClDisTopLevelParser Parser(Header, InputStream, ObjDump); | 3556 ::NaClDisTopLevelParser Parser(Header, InputStream, ObjDump); |
3550 int NumBlocksRead = 0; | 3557 int NumBlocksRead = 0; |
3551 bool ErrorsFound = false; | 3558 bool ErrorsFound = false; |
3552 while (!InputStream.AtEndOfStream()) { | 3559 while (!InputStream.AtEndOfStream()) { |
3553 ++NumBlocksRead; | 3560 ++NumBlocksRead; |
3554 if (Parser.Parse()) ErrorsFound = true; | 3561 if (Parser.Parse()) ErrorsFound = true; |
3555 } | 3562 } |
3556 | 3563 |
3557 if (NumBlocksRead != 1) { | 3564 if (NumBlocksRead != 1) { |
3558 ObjDump.Error() << "Expected 1 top level block in bitcode: Found:" | 3565 ObjDump.Error() << "Expected 1 top level block in bitcode: Found:" |
3559 << NumBlocksRead << "\n"; | 3566 << NumBlocksRead << "\n"; |
3560 ErrorsFound = true; | 3567 ErrorsFound = true; |
3561 } | 3568 } |
3562 | 3569 |
3563 ObjDump.Flush(); | 3570 ObjDump.Flush(); |
3564 return ErrorsFound || Parser.GetNumErrors() > 0; | 3571 return ErrorsFound || Parser.GetNumErrors() > 0; |
3565 } | 3572 } |
3566 | 3573 |
3567 } | 3574 } |
OLD | NEW |