OLD | NEW |
1 //===- NaClBitcodeMungeReader.cpp - Read bitcode record list ----*- C++ -*-===// | 1 //===- NaClBitcodeMungeReader.cpp - Read bitcode record list ----*- C++ -*-===// |
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 // Implements bitcode reader for NaClBitcodeRecordList and NaClMungedBitcode. | 10 // Implements bitcode reader for NaClBitcodeRecordList and NaClMungedBitcode. |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 void llvm::readNaClBitcodeRecordList( | 124 void llvm::readNaClBitcodeRecordList( |
125 NaClBitcodeRecordList &RecordList, | 125 NaClBitcodeRecordList &RecordList, |
126 std::unique_ptr<MemoryBuffer> InputBuffer) { | 126 std::unique_ptr<MemoryBuffer> InputBuffer) { |
127 if (InputBuffer->getBufferSize() % 4 != 0) | 127 if (InputBuffer->getBufferSize() % 4 != 0) |
128 report_fatal_error( | 128 report_fatal_error( |
129 "Bitcode stream must be a multiple of 4 bytes in length"); | 129 "Bitcode stream must be a multiple of 4 bytes in length"); |
130 | 130 |
131 const unsigned char *BufPtr = | 131 const unsigned char *BufPtr = |
132 (const unsigned char *) InputBuffer->getBufferStart(); | 132 (const unsigned char *) InputBuffer->getBufferStart(); |
133 const unsigned char *EndBufPtr = BufPtr + InputBuffer->getBufferSize(); | 133 const unsigned char *EndBufPtr = BufPtr + InputBuffer->getBufferSize(); |
134 const unsigned char *HeaderPtr = BufPtr; | |
135 | 134 |
136 // Read header and verify it is good. | 135 // Read header and verify it is good. |
137 NaClBitcodeHeader Header; | 136 NaClBitcodeHeader Header; |
138 if (Header.Read(HeaderPtr, EndBufPtr) || !Header.IsSupported()) | 137 if (Header.Read(BufPtr, EndBufPtr)) |
| 138 report_fatal_error("Invalid PNaCl bitcode header.\n"); |
| 139 if (!Header.IsSupported()) |
| 140 errs() << Header.Unsupported(); |
| 141 if (!Header.IsReadable()) |
139 report_fatal_error("Invalid PNaCl bitcode header.\n"); | 142 report_fatal_error("Invalid PNaCl bitcode header.\n"); |
140 | 143 |
141 NaClBitstreamReader Reader(BufPtr, EndBufPtr, Header.getHeaderSize()); | 144 NaClBitstreamReader Reader(BufPtr, EndBufPtr, Header); |
142 NaClBitstreamCursor Cursor(Reader); | 145 NaClBitstreamCursor Cursor(Reader); |
143 | 146 |
144 // Parse the bitcode buffer. | 147 // Parse the bitcode buffer. |
145 BitcodeParser Parser(Cursor, RecordList); | 148 BitcodeParser Parser(Cursor, RecordList); |
146 | 149 |
147 while (!Cursor.AtEndOfStream()) { | 150 while (!Cursor.AtEndOfStream()) { |
148 if (Parser.Parse()) | 151 if (Parser.Parse()) |
149 report_fatal_error("Malformed records founds, unable to continue"); | 152 report_fatal_error("Malformed records founds, unable to continue"); |
150 } | 153 } |
151 } | 154 } |
152 | 155 |
153 | 156 |
154 NaClMungedBitcode::NaClMungedBitcode(std::unique_ptr<MemoryBuffer> InputBuffer) | 157 NaClMungedBitcode::NaClMungedBitcode(std::unique_ptr<MemoryBuffer> InputBuffer) |
155 : BaseRecords(new NaClBitcodeRecordList()) { | 158 : BaseRecords(new NaClBitcodeRecordList()) { |
156 readNaClBitcodeRecordList(*BaseRecords, std::move(InputBuffer)); | 159 readNaClBitcodeRecordList(*BaseRecords, std::move(InputBuffer)); |
157 } | 160 } |
OLD | NEW |