in Sources/SIL/BitcodeParser.swift [134:178]
func parseInfoBlock(abbrLen: Int) throws {
var currentInfo: BitcodeBlockInfo?
while true {
let abbrev = try stream.next(bits: abbrLen)
switch (abbrev) {
case endBlock:
stream.align(toMultipleOf: 32)
return
case unabbrevRecord:
let record = try parseUnabbrevRecord()
// Unabbreviated records have no structure, so the cast to bits is safe
let ops = record.ops.map { $0.bits! }
switch (record.code) {
case setbid:
assert(ops.count == 1)
let blockId: Bits = ops[0]
if blockInfoTemplates[blockId] == nil {
blockInfoTemplates[blockId] = BitcodeBlockInfo(id: blockId)
}
currentInfo = blockInfoTemplates[blockId]
case blockName:
let nameBytes = ops.map { $0.uint8 }
guard let name = String(bytes: nameBytes, encoding: .utf8) else {
// The name was incorrect, so we skip it.
continue
}
currentInfo?.name = name
break
case setRecordName:
let recordId = ops[0]
let nameBytes = ops.suffix(from: 1).map { $0.uint8 }
guard let name = String(bytes: nameBytes, encoding: .utf8) else {
// The name was incorrect, so we skip it.
continue
}
currentInfo?.recordNames[recordId] = name
break
default:
throw Error.unsupportedBlockInfoRecord(record.code)
}
default:
throw Error.unsupportedBlockInfoAbbrev(abbrev)
}
}
}