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 1826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1837 } | 1837 } |
1838 | 1838 |
1839 std::error_code NaClBitcodeReader::InitStreamFromBuffer() { | 1839 std::error_code NaClBitcodeReader::InitStreamFromBuffer() { |
1840 const unsigned char *BufPtr = (const unsigned char*)Buffer->getBufferStart(); | 1840 const unsigned char *BufPtr = (const unsigned char*)Buffer->getBufferStart(); |
1841 const unsigned char *BufEnd = BufPtr+Buffer->getBufferSize(); | 1841 const unsigned char *BufEnd = BufPtr+Buffer->getBufferSize(); |
1842 | 1842 |
1843 if (Buffer->getBufferSize() & 3) | 1843 if (Buffer->getBufferSize() & 3) |
1844 return Error(InvalidBitstream, | 1844 return Error(InvalidBitstream, |
1845 "Bitcode stream should be a multiple of 4 bytes in length"); | 1845 "Bitcode stream should be a multiple of 4 bytes in length"); |
1846 | 1846 |
1847 const unsigned char *HeaderPtr = BufPtr; | 1847 if (Header.Read(BufPtr, BufEnd)) |
1848 if (Header.Read(HeaderPtr, BufEnd)) | |
1849 return Error(InvalidBitstream, Header.Unsupported()); | 1848 return Error(InvalidBitstream, Header.Unsupported()); |
1850 | 1849 |
1851 StreamFile.reset(new NaClBitstreamReader(BufPtr, BufEnd, | |
1852 Header.getHeaderSize())); | |
1853 Stream.init(StreamFile.get()); | |
1854 | |
1855 if (AcceptHeader()) | 1850 if (AcceptHeader()) |
1856 return Error(InvalidBitstream, Header.Unsupported()); | 1851 return Error(InvalidBitstream, Header.Unsupported()); |
| 1852 |
| 1853 StreamFile.reset(new NaClBitstreamReader(BufPtr, BufEnd, Header)); |
| 1854 Stream.init(StreamFile.get()); |
| 1855 |
1857 return std::error_code(); | 1856 return std::error_code(); |
1858 } | 1857 } |
1859 | 1858 |
1860 std::error_code NaClBitcodeReader::InitLazyStream() { | 1859 std::error_code NaClBitcodeReader::InitLazyStream() { |
1861 if (Header.Read(LazyStreamer)) | 1860 if (Header.Read(LazyStreamer)) |
1862 return Error(InvalidBitstream, Header.Unsupported()); | 1861 return Error(InvalidBitstream, Header.Unsupported()); |
1863 | 1862 |
1864 StreamFile.reset(new NaClBitstreamReader(LazyStreamer, | |
1865 Header.getHeaderSize())); | |
1866 Stream.init(StreamFile.get()); | |
1867 if (AcceptHeader()) | 1863 if (AcceptHeader()) |
1868 return Error(InvalidBitstream, Header.Unsupported()); | 1864 return Error(InvalidBitstream, Header.Unsupported()); |
| 1865 |
| 1866 StreamFile.reset(new NaClBitstreamReader(LazyStreamer, Header)); |
| 1867 Stream.init(StreamFile.get()); |
1869 return std::error_code(); | 1868 return std::error_code(); |
1870 } | 1869 } |
1871 | 1870 |
1872 //===----------------------------------------------------------------------===// | 1871 //===----------------------------------------------------------------------===// |
1873 // External interface | 1872 // External interface |
1874 //===----------------------------------------------------------------------===// | 1873 //===----------------------------------------------------------------------===// |
1875 | 1874 |
1876 /// \brief Get a lazy one-at-time loading module from bitcode. | 1875 /// \brief Get a lazy one-at-time loading module from bitcode. |
1877 /// | 1876 /// |
1878 /// This isn't always used in a lazy context. In particular, it's also used by | 1877 /// This isn't always used in a lazy context. In particular, it's also used by |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1935 if (std::error_code EC = M->materializeAllPermanently()) { | 1934 if (std::error_code EC = M->materializeAllPermanently()) { |
1936 delete M; | 1935 delete M; |
1937 return EC; | 1936 return EC; |
1938 } | 1937 } |
1939 | 1938 |
1940 // TODO: Restore the use-lists to the in-memory state when the bitcode was | 1939 // TODO: Restore the use-lists to the in-memory state when the bitcode was |
1941 // written. We must defer until the Module has been fully materialized. | 1940 // written. We must defer until the Module has been fully materialized. |
1942 | 1941 |
1943 return M; | 1942 return M; |
1944 } | 1943 } |
OLD | NEW |