aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-12-23 23:57:02 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-12-23 23:57:02 -0700
commit5b171f446f46c97de111bce0575452be0334a05e (patch)
treec3ce543696892a846f21241863c07c62f2fcf7f2 /src/Module.zig
parent3763580e1e734b558499df5512f6a165f6db988b (diff)
downloadzig-5b171f446f46c97de111bce0575452be0334a05e.tar.gz
zig-5b171f446f46c97de111bce0575452be0334a05e.zip
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.
Diffstat (limited to 'src/Module.zig')
-rw-r--r--src/Module.zig18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/Module.zig b/src/Module.zig
index 4f9f8307db..25e262855c 100644
--- a/src/Module.zig
+++ b/src/Module.zig
@@ -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 {