feature. See also
. The project being documented here (as the example) is the Zig library itself.
BitcodeReader.parseBlockInfoBlock
fn parseBlockInfoBlock(bc: *BitcodeReader) !void
File
Code
fn parseBlockInfoBlock(bc: *BitcodeReader) !void {
var block_id: ?u32 = null;
while (true) {
const record = (try bc.nextRecord()) orelse return error.EndOfStream;
switch (record.id) {
Abbrev.Builtin.end_block.toRecordId() => break,
Abbrev.Builtin.define_abbrev.toRecordId() => {
const gop = try bc.block_info.getOrPut(bc.allocator, block_id orelse
return error.UnspecifiedBlockId);
if (!gop.found_existing) gop.value_ptr.* = Block.Info.default;
try gop.value_ptr.abbrevs.addOwnedAbbrev(
bc.allocator,
try record.toOwnedAbbrev(bc.allocator),
);
},
Block.Info.set_bid_id => block_id = std.math.cast(u32, record.operands[0]) orelse
return error.Overflow,
Block.Info.block_name_id => if (bc.keep_names) {
const gop = try bc.block_info.getOrPut(bc.allocator, block_id orelse
return error.UnspecifiedBlockId);
if (!gop.found_existing) gop.value_ptr.* = Block.Info.default;
const name = try bc.allocator.alloc(u8, record.operands.len);
errdefer bc.allocator.free(name);
for (name, record.operands) |*byte, operand|
byte.* = std.math.cast(u8, operand) orelse return error.InvalidName;
gop.value_ptr.block_name = name;
},
Block.Info.set_record_name_id => if (bc.keep_names) {
const gop = try bc.block_info.getOrPut(bc.allocator, block_id orelse
return error.UnspecifiedBlockId);
if (!gop.found_existing) gop.value_ptr.* = Block.Info.default;
const name = try bc.allocator.alloc(u8, record.operands.len - 1);
errdefer bc.allocator.free(name);
for (name, record.operands[1..]) |*byte, operand|
byte.* = std.math.cast(u8, operand) orelse return error.InvalidName;
try gop.value_ptr.record_names.put(
bc.allocator,
std.math.cast(u32, record.operands[0]) orelse return error.Overflow,
name,
);
},
else => return error.UnsupportedBlockInfoRecord,
}
}
}