aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatt Knight <mattnite@protonmail.com>2023-02-18 14:10:27 -0500
committerGitHub <noreply@github.com>2023-02-18 21:10:27 +0200
commit07630eb696a4c7097fadf9e0261411d591a82038 (patch)
tree3ab641d04111e157d1f6d2b7c5fe53a0e1b0d24f /src
parentc993af62347faf124e97b16801356d34322a216e (diff)
downloadzig-07630eb696a4c7097fadf9e0261411d591a82038.tar.gz
zig-07630eb696a4c7097fadf9e0261411d591a82038.zip
Value: implement writeToMemory for packed unions
Diffstat (limited to 'src')
-rw-r--r--src/value.zig19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/value.zig b/src/value.zig
index 306e31c0a7..98842a4ca7 100644
--- a/src/value.zig
+++ b/src/value.zig
@@ -1340,6 +1340,14 @@ pub const Value = extern union {
const int = mod.global_error_set.get(val.castTag(.@"error").?.data.name).?;
std.mem.writeInt(Int, buffer[0..@sizeOf(Int)], @intCast(Int, int), endian);
},
+ .Union => switch (ty.containerLayout()) {
+ .Auto => unreachable,
+ .Extern => @panic("TODO implement writeToMemory for extern unions"),
+ .Packed => {
+ const byte_count = (@intCast(usize, ty.bitSize(target)) + 7) / 8;
+ writeToPackedMemory(val, ty, mod, buffer[0..byte_count], 0);
+ },
+ },
else => @panic("TODO implement writeToMemory for more types"),
}
}
@@ -1430,6 +1438,17 @@ pub const Value = extern union {
}
},
},
+ .Union => switch (ty.containerLayout()) {
+ .Auto => unreachable, // Sema is supposed to have emitted a compile error already
+ .Extern => unreachable, // Handled in non-packed writeToMemory
+ .Packed => {
+ const field_index = ty.unionTagFieldIndex(val.unionTag(), mod);
+ const field_type = ty.unionFields().values()[field_index.?].ty;
+ const field_val = val.fieldValue(field_type, field_index.?);
+
+ field_val.writeToPackedMemory(field_type, mod, buffer, bit_offset);
+ },
+ },
else => @panic("TODO implement writeToPackedMemory for more types"),
}
}