Builder: implement opaque structs in bitcode

This commit is contained in:
Jacob Young 2024-02-23 07:51:02 +01:00
parent 43daed64fe
commit 6abb432598
2 changed files with 24 additions and 11 deletions

View File

@ -13015,18 +13015,23 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
.string = extra.id.slice(self).?,
});
const real_struct = self.type_items.items[@intFromEnum(extra.body)];
const is_packed: bool = switch (real_struct.tag) {
.structure => false,
.packed_structure => true,
else => unreachable,
};
switch (extra.body) {
.none => try type_block.writeAbbrev(ir.Type.Opaque{}),
else => {
const real_struct = self.type_items.items[@intFromEnum(extra.body)];
const is_packed: bool = switch (real_struct.tag) {
.structure => false,
.packed_structure => true,
else => unreachable,
};
var real_extra = self.typeExtraDataTrail(Type.Structure, real_struct.data);
try type_block.writeAbbrev(ir.Type.StructNamed{
.is_packed = is_packed,
.types = real_extra.trail.next(real_extra.data.fields_len, Type, self),
});
var real_extra = self.typeExtraDataTrail(Type.Structure, real_struct.data);
try type_block.writeAbbrev(ir.Type.StructNamed{
.is_packed = is_packed,
.types = real_extra.trail.next(real_extra.data.fields_len, Type, self),
});
},
}
},
.array,
.small_array,

View File

@ -188,6 +188,7 @@ pub const Type = struct {
pub const abbrevs = [_]type{
NumEntry,
Simple,
Opaque,
Integer,
StructAnon,
StructNamed,
@ -214,6 +215,13 @@ pub const Type = struct {
code: u5,
};
pub const Opaque = struct {
pub const ops = [_]AbbrevOp{
.{ .literal = 6 },
.{ .literal = 0 },
};
};
pub const Integer = struct {
pub const ops = [_]AbbrevOp{
.{ .literal = 7 },