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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user