Read the "IDENTIFICATION_BLOCK_ID" block, do some basic enforcement on the "epoch" encoded in the bitcode, and return the producer name if any.
| 165 | /// Read the "IDENTIFICATION_BLOCK_ID" block, do some basic enforcement on the |
| 166 | /// "epoch" encoded in the bitcode, and return the producer name if any. |
| 167 | static Expected<std::string> readIdentificationBlock(BitstreamCursor &Stream) { |
| 168 | if (Stream.EnterSubBlock(bitc::IDENTIFICATION_BLOCK_ID)) |
| 169 | return error("Invalid record"); |
| 170 | |
| 171 | // Read all the records. |
| 172 | SmallVector<uint64_t, 64> Record; |
| 173 | |
| 174 | std::string ProducerIdentification; |
| 175 | |
| 176 | while (true) { |
| 177 | BitstreamEntry Entry = Stream.advance(); |
| 178 | |
| 179 | switch (Entry.Kind) { |
| 180 | default: |
| 181 | case BitstreamEntry::Error: |
| 182 | return error("Malformed block"); |
| 183 | case BitstreamEntry::EndBlock: |
| 184 | return ProducerIdentification; |
| 185 | case BitstreamEntry::Record: |
| 186 | // The interesting case. |
| 187 | break; |
| 188 | } |
| 189 | |
| 190 | // Read a record. |
| 191 | Record.clear(); |
| 192 | unsigned BitCode = Stream.readRecord(Entry.ID, Record); |
| 193 | switch (BitCode) { |
| 194 | default: // Default behavior: reject |
| 195 | return error("Invalid value"); |
| 196 | case bitc::IDENTIFICATION_CODE_STRING: // IDENTIFICATION: [strchr x N] |
| 197 | convertToString(Record, 0, ProducerIdentification); |
| 198 | break; |
| 199 | case bitc::IDENTIFICATION_CODE_EPOCH: { // EPOCH: [epoch#] |
| 200 | unsigned epoch = (unsigned)Record[0]; |
| 201 | if (epoch != bitc::BITCODE_CURRENT_EPOCH) { |
| 202 | return error( |
| 203 | Twine("Incompatible epoch: Bitcode '") + Twine(epoch) + |
| 204 | "' vs current: '" + Twine(bitc::BITCODE_CURRENT_EPOCH) + "'"); |
| 205 | } |
| 206 | } |
| 207 | } |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | static Expected<std::string> readIdentificationCode(BitstreamCursor &Stream) { |
| 212 | // We expect a number of well-defined blocks, though we don't necessarily |
no test coverage detected