authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-05-04 20:39:32-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:42:28-07:00
log773fabf3610629c8974b59ed6fbd27050b7e505b
tree483008e1e8536df478253558aa0c73b79d9edb45
parent5e636643d2a36c777a607b65cfd1abbb1822ad1e

InternPool: add the missing pointer data


1 files changed, 20 insertions(+), 1 deletions(-)

src/InternPool.zig+20-1
......@@ -653,7 +653,6 @@ pub const Tag = enum(u8) {
653653 /// data is payload to Vector.
654654 type_vector,
655655 /// A fully explicitly specified pointer type.
656 /// TODO actually this is missing some stuff like bit_offset
657656 /// data is payload to Pointer.
658657 type_pointer,
659658 /// An optional type.
......@@ -793,6 +792,8 @@ pub const Pointer = struct {
793792 child: Index,
794793 sentinel: Index,
795794 flags: Flags,
795 packed_offset: PackedOffset,
796 vector_index: VectorIndex,
796797
797798 pub const Flags = packed struct(u32) {
798799 alignment: u16,
......@@ -804,8 +805,14 @@ pub const Pointer = struct {
804805 _: u7 = undefined,
805806 };
806807
808 pub const PackedOffset = packed struct(u32) {
809 host_size: u16,
810 bit_offset: u16,
811 };
812
807813 pub const Size = std.builtin.Type.Pointer.Size;
808814 pub const AddressSpace = std.builtin.AddressSpace;
815 pub const VectorIndex = Key.PtrType.VectorIndex;
809816};
810817
811818/// Used for non-sentineled arrays that have length fitting in u32, as well as
......@@ -914,6 +921,9 @@ pub fn indexToKey(ip: InternPool, index: Index) Key {
914921 .is_volatile = ptr_info.flags.is_volatile,
915922 .is_allowzero = ptr_info.flags.is_allowzero,
916923 .address_space = ptr_info.flags.address_space,
924 .vector_index = ptr_info.vector_index,
925 .host_size = ptr_info.packed_offset.host_size,
926 .bit_offset = ptr_info.packed_offset.bit_offset,
917927 } };
918928 },
919929
......@@ -972,6 +982,11 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
972982 .size = ptr_type.size,
973983 .address_space = ptr_type.address_space,
974984 },
985 .packed_offset = .{
986 .host_size = ptr_type.host_size,
987 .bit_offset = ptr_type.bit_offset,
988 },
989 .vector_index = ptr_type.vector_index,
975990 }),
976991 });
977992 },
......@@ -1126,6 +1141,8 @@ fn addExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 {
11261141 Index => @enumToInt(@field(extra, field.name)),
11271142 i32 => @bitCast(u32, @field(extra, field.name)),
11281143 Pointer.Flags => @bitCast(u32, @field(extra, field.name)),
1144 Pointer.PackedOffset => @bitCast(u32, @field(extra, field.name)),
1145 Pointer.VectorIndex => @enumToInt(@field(extra, field.name)),
11291146 else => @compileError("bad field type: " ++ @typeName(field.type)),
11301147 });
11311148 }
......@@ -1180,6 +1197,8 @@ fn extraData(ip: InternPool, comptime T: type, index: usize) T {
11801197 Index => @intToEnum(Index, ip.extra.items[i]),
11811198 i32 => @bitCast(i32, ip.extra.items[i]),
11821199 Pointer.Flags => @bitCast(Pointer.Flags, ip.extra.items[i]),
1200 Pointer.PackedOffset => @bitCast(Pointer.PackedOffset, ip.extra.items[i]),
1201 Pointer.VectorIndex => @intToEnum(Pointer.VectorIndex, ip.extra.items[i]),
11831202 else => @compileError("bad field type: " ++ @typeName(field.type)),
11841203 };
11851204 i += 1;