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 979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
990 // PNaCl does not support different DataLayouts in pexes, so we | 990 // PNaCl does not support different DataLayouts in pexes, so we |
991 // implicitly set the DataLayout to the following default. | 991 // implicitly set the DataLayout to the following default. |
992 // | 992 // |
993 // This is not usually needed by the backend, but it might be used | 993 // This is not usually needed by the backend, but it might be used |
994 // by IR passes that the PNaCl translator runs. We set this in the | 994 // by IR passes that the PNaCl translator runs. We set this in the |
995 // reader rather than in pnacl-llc so that 'opt' will also use the | 995 // reader rather than in pnacl-llc so that 'opt' will also use the |
996 // correct DataLayout if it is run on a pexe. | 996 // correct DataLayout if it is run on a pexe. |
997 M->setDataLayout("e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-" | 997 M->setDataLayout("e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-" |
998 "f32:32:32-f64:64:64-p:32:32:32-v128:32:32"); | 998 "f32:32:32-f64:64:64-p:32:32:32-v128:32:32"); |
999 | 999 |
1000 if (InitStream()) return Error(Header.Unsupported()); | 1000 if (InitStream()) return true; // InitSream will set the error string. |
1001 | 1001 |
1002 // We expect a number of well-defined blocks, though we don't necessarily | 1002 // We expect a number of well-defined blocks, though we don't necessarily |
1003 // need to understand them all. | 1003 // need to understand them all. |
1004 while (1) { | 1004 while (1) { |
1005 if (Stream.AtEndOfStream()) | 1005 if (Stream.AtEndOfStream()) |
1006 return false; | 1006 return false; |
1007 | 1007 |
1008 NaClBitstreamEntry Entry = | 1008 NaClBitstreamEntry Entry = |
1009 Stream.advance(NaClBitstreamCursor::AF_DontAutoprocessAbbrevs); | 1009 Stream.advance(NaClBitstreamCursor::AF_DontAutoprocessAbbrevs); |
1010 | 1010 |
(...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1765 } | 1765 } |
1766 | 1766 |
1767 bool NaClBitcodeReader::InitStreamFromBuffer() { | 1767 bool NaClBitcodeReader::InitStreamFromBuffer() { |
1768 const unsigned char *BufPtr = (const unsigned char*)Buffer->getBufferStart(); | 1768 const unsigned char *BufPtr = (const unsigned char*)Buffer->getBufferStart(); |
1769 const unsigned char *BufEnd = BufPtr+Buffer->getBufferSize(); | 1769 const unsigned char *BufEnd = BufPtr+Buffer->getBufferSize(); |
1770 | 1770 |
1771 if (Buffer->getBufferSize() & 3) | 1771 if (Buffer->getBufferSize() & 3) |
1772 return Error("Bitcode stream should be a multiple of 4 bytes in length"); | 1772 return Error("Bitcode stream should be a multiple of 4 bytes in length"); |
1773 | 1773 |
1774 if (Header.Read(BufPtr, BufEnd)) | 1774 if (Header.Read(BufPtr, BufEnd)) |
1775 return Error("Invalid PNaCl bitcode header"); | 1775 return Error(Header.Unsupported()); |
1776 | 1776 |
1777 StreamFile.reset(new NaClBitstreamReader(BufPtr, BufEnd)); | 1777 StreamFile.reset(new NaClBitstreamReader(BufPtr, BufEnd)); |
1778 Stream.init(*StreamFile); | 1778 Stream.init(*StreamFile); |
1779 | 1779 |
1780 return AcceptHeader(); | 1780 if (AcceptHeader()) |
| 1781 return Error(Header.Unsupported()); |
| 1782 return false; |
1781 } | 1783 } |
1782 | 1784 |
1783 bool NaClBitcodeReader::InitLazyStream() { | 1785 bool NaClBitcodeReader::InitLazyStream() { |
1784 StreamingMemoryObject *Bytes = new StreamingMemoryObject(LazyStreamer); | 1786 StreamingMemoryObject *Bytes = new StreamingMemoryObject(LazyStreamer); |
1785 if (Header.Read(Bytes)) | 1787 if (Header.Read(Bytes)) |
1786 return Error("Invalid PNaCl bitcode header"); | 1788 return Error(Header.Unsupported()); |
1787 | 1789 |
1788 StreamFile.reset(new NaClBitstreamReader(Bytes, Header.getHeaderSize())); | 1790 StreamFile.reset(new NaClBitstreamReader(Bytes, Header.getHeaderSize())); |
1789 Stream.init(*StreamFile); | 1791 Stream.init(*StreamFile); |
1790 return AcceptHeader(); | 1792 if (AcceptHeader()) |
| 1793 return Error(Header.Unsupported()); |
| 1794 return false; |
1791 } | 1795 } |
1792 | 1796 |
1793 //===----------------------------------------------------------------------===// | 1797 //===----------------------------------------------------------------------===// |
1794 // External interface | 1798 // External interface |
1795 //===----------------------------------------------------------------------===// | 1799 //===----------------------------------------------------------------------===// |
1796 | 1800 |
1797 /// getNaClLazyBitcodeModule - lazy function-at-a-time loading from a file. | 1801 /// getNaClLazyBitcodeModule - lazy function-at-a-time loading from a file. |
1798 /// | 1802 /// |
1799 Module *llvm::getNaClLazyBitcodeModule(MemoryBuffer *Buffer, | 1803 Module *llvm::getNaClLazyBitcodeModule(MemoryBuffer *Buffer, |
1800 LLVMContext& Context, | 1804 LLVMContext& Context, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1855 if (M->MaterializeAllPermanently(ErrMsg)) { | 1859 if (M->MaterializeAllPermanently(ErrMsg)) { |
1856 delete M; | 1860 delete M; |
1857 return 0; | 1861 return 0; |
1858 } | 1862 } |
1859 | 1863 |
1860 // TODO: Restore the use-lists to the in-memory state when the bitcode was | 1864 // TODO: Restore the use-lists to the in-memory state when the bitcode was |
1861 // written. We must defer until the Module has been fully materialized. | 1865 // written. We must defer until the Module has been fully materialized. |
1862 | 1866 |
1863 return M; | 1867 return M; |
1864 } | 1868 } |
OLD | NEW |