MCPcopy Create free account
hub / github.com/GANGE666/xVMP / readIdentificationBlock

Function readIdentificationBlock

src/lib/Bitcode/Reader/BitcodeReader.cpp:167–209  ·  view source on GitHub ↗

Read the "IDENTIFICATION_BLOCK_ID" block, do some basic enforcement on the "epoch" encoded in the bitcode, and return the producer name if any.

Source from the content-addressed store, hash-verified

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.
167static 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
211static Expected<std::string> readIdentificationCode(BitstreamCursor &Stream) {
212 // We expect a number of well-defined blocks, though we don't necessarily

Callers 2

readIdentificationCodeFunction · 0.85
getModuleImplMethod · 0.85

Calls 7

EnterSubBlockMethod · 0.80
errorFunction · 0.70
convertToStringFunction · 0.70
TwineClass · 0.50
advanceMethod · 0.45
clearMethod · 0.45
readRecordMethod · 0.45

Tested by

no test coverage detected