stage2: initial implementation of packed structs

Layout algorithm: all `align(0)` fields are squished together as if they
were a single integer with a number of bits equal to `@bitSizeOf` each
field added together. Then the natural ABI alignment of that integer is
used for that pseudo-field.
This commit is contained in:
Andrew Kelley
2021-12-23 23:57:02 -07:00
parent 3763580e1e
commit 5b171f446f
7 changed files with 736 additions and 291 deletions

View File

@@ -849,6 +849,24 @@ pub const Struct = struct {
/// undefined until `status` is `have_layout`.
offset: u32,
is_comptime: bool,
/// Returns the field alignment, assuming the struct is packed.
pub fn packedAlignment(field: Field) u32 {
if (field.abi_align.tag() == .abi_align_default) {
return 0;
} else {
return @intCast(u32, field.abi_align.toUnsignedInt());
}
}
/// Returns the field alignment, assuming the struct is not packed.
pub fn normalAlignment(field: Field, target: Target) u32 {
if (field.abi_align.tag() == .abi_align_default) {
return field.ty.abiAlignment(target);
} else {
return @intCast(u32, field.abi_align.toUnsignedInt());
}
}
};
pub fn getFullyQualifiedName(s: *Struct, gpa: Allocator) ![:0]u8 {