OLD | NEW |
---|---|
1 //===- NaClBitcodeReader.cpp ----------------------------------------------===// | 1 //===- NaClBitcodeReader.cpp ----------------------------------------------===// |
2 // Internal NaClBitcodeReader implementation | 2 // Internal NaClBitcodeReader implementation |
3 // | 3 // |
4 // The LLVM Compiler Infrastructure | 4 // The LLVM Compiler Infrastructure |
5 // | 5 // |
6 // This file is distributed under the University of Illinois Open Source | 6 // This file is distributed under the University of Illinois Open Source |
7 // License. See LICENSE.TXT for details. | 7 // License. See LICENSE.TXT for details. |
8 // | 8 // |
9 //===----------------------------------------------------------------------===// | 9 //===----------------------------------------------------------------------===// |
10 | 10 |
(...skipping 968 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
979 // PNaCl does not support different DataLayouts in pexes, so we | 979 // PNaCl does not support different DataLayouts in pexes, so we |
980 // implicitly set the DataLayout to the following default. | 980 // implicitly set the DataLayout to the following default. |
981 // | 981 // |
982 // This is not usually needed by the backend, but it might be used | 982 // This is not usually needed by the backend, but it might be used |
983 // by IR passes that the PNaCl translator runs. We set this in the | 983 // by IR passes that the PNaCl translator runs. We set this in the |
984 // reader rather than in pnacl-llc so that 'opt' will also use the | 984 // reader rather than in pnacl-llc so that 'opt' will also use the |
985 // correct DataLayout if it is run on a pexe. | 985 // correct DataLayout if it is run on a pexe. |
986 M->setDataLayout("e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-" | 986 M->setDataLayout("e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-" |
987 "f32:32:32-f64:64:64-p:32:32:32-v128:32:32"); | 987 "f32:32:32-f64:64:64-p:32:32:32-v128:32:32"); |
988 | 988 |
989 if (InitStream()) return Error(Header.Unsupported()); | 989 if (InitStream()) return true; // InitSream will set the error string. |
990 | 990 |
991 // We expect a number of well-defined blocks, though we don't necessarily | 991 // We expect a number of well-defined blocks, though we don't necessarily |
992 // need to understand them all. | 992 // need to understand them all. |
993 while (1) { | 993 while (1) { |
994 if (Stream.AtEndOfStream()) | 994 if (Stream.AtEndOfStream()) |
995 return false; | 995 return false; |
996 | 996 |
997 NaClBitstreamEntry Entry = | 997 NaClBitstreamEntry Entry = |
998 Stream.advance(NaClBitstreamCursor::AF_DontAutoprocessAbbrevs); | 998 Stream.advance(NaClBitstreamCursor::AF_DontAutoprocessAbbrevs); |
999 | 999 |
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1746 } | 1746 } |
1747 | 1747 |
1748 bool NaClBitcodeReader::InitStreamFromBuffer() { | 1748 bool NaClBitcodeReader::InitStreamFromBuffer() { |
1749 const unsigned char *BufPtr = (const unsigned char*)Buffer->getBufferStart(); | 1749 const unsigned char *BufPtr = (const unsigned char*)Buffer->getBufferStart(); |
1750 const unsigned char *BufEnd = BufPtr+Buffer->getBufferSize(); | 1750 const unsigned char *BufEnd = BufPtr+Buffer->getBufferSize(); |
1751 | 1751 |
1752 if (Buffer->getBufferSize() & 3) | 1752 if (Buffer->getBufferSize() & 3) |
1753 return Error("Bitcode stream should be a multiple of 4 bytes in length"); | 1753 return Error("Bitcode stream should be a multiple of 4 bytes in length"); |
1754 | 1754 |
1755 if (Header.Read(BufPtr, BufEnd)) | 1755 if (Header.Read(BufPtr, BufEnd)) |
1756 return Error("Invalid PNaCl bitcode header"); | 1756 return Error("Invalid PNaCl bitcode header"); |
jvoung (off chromium)
2013/09/10 20:39:56
A bit difficult to figure out which error message
Derek Schuff
2013/09/13 19:53:36
Agreed.
I added some comments and made the error h
| |
1757 | 1757 |
1758 StreamFile.reset(new NaClBitstreamReader(BufPtr, BufEnd)); | 1758 StreamFile.reset(new NaClBitstreamReader(BufPtr, BufEnd)); |
1759 Stream.init(*StreamFile); | 1759 Stream.init(*StreamFile); |
1760 | 1760 |
1761 return AcceptHeader(); | 1761 if (AcceptHeader()) |
1762 return Error(Header.Unsupported()); | |
1763 return false; | |
1762 } | 1764 } |
1763 | 1765 |
1764 bool NaClBitcodeReader::InitLazyStream() { | 1766 bool NaClBitcodeReader::InitLazyStream() { |
1765 StreamingMemoryObject *Bytes = new StreamingMemoryObject(LazyStreamer); | 1767 StreamingMemoryObject *Bytes = new StreamingMemoryObject(LazyStreamer); |
1766 if (Header.Read(Bytes)) | 1768 if (Header.Read(Bytes)) |
1767 return Error("Invalid PNaCl bitcode header"); | 1769 return Error("Invalid PNaCl bitcode header"); |
1768 | 1770 |
1769 StreamFile.reset(new NaClBitstreamReader(Bytes, Header.getHeaderSize())); | 1771 StreamFile.reset(new NaClBitstreamReader(Bytes, Header.getHeaderSize())); |
1770 Stream.init(*StreamFile); | 1772 Stream.init(*StreamFile); |
1771 return AcceptHeader(); | 1773 if (AcceptHeader()) |
1774 return Error(Header.Unsupported()); | |
1775 return false; | |
1772 } | 1776 } |
1773 | 1777 |
1774 //===----------------------------------------------------------------------===// | 1778 //===----------------------------------------------------------------------===// |
1775 // External interface | 1779 // External interface |
1776 //===----------------------------------------------------------------------===// | 1780 //===----------------------------------------------------------------------===// |
1777 | 1781 |
1778 /// getNaClLazyBitcodeModule - lazy function-at-a-time loading from a file. | 1782 /// getNaClLazyBitcodeModule - lazy function-at-a-time loading from a file. |
1779 /// | 1783 /// |
1780 Module *llvm::getNaClLazyBitcodeModule(MemoryBuffer *Buffer, | 1784 Module *llvm::getNaClLazyBitcodeModule(MemoryBuffer *Buffer, |
1781 LLVMContext& Context, | 1785 LLVMContext& Context, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1836 if (M->MaterializeAllPermanently(ErrMsg)) { | 1840 if (M->MaterializeAllPermanently(ErrMsg)) { |
1837 delete M; | 1841 delete M; |
1838 return 0; | 1842 return 0; |
1839 } | 1843 } |
1840 | 1844 |
1841 // TODO: Restore the use-lists to the in-memory state when the bitcode was | 1845 // TODO: Restore the use-lists to the in-memory state when the bitcode was |
1842 // written. We must defer until the Module has been fully materialized. | 1846 // written. We must defer until the Module has been fully materialized. |
1843 | 1847 |
1844 return M; | 1848 return M; |
1845 } | 1849 } |
OLD | NEW |