aboutsummaryrefslogtreecommitdiff
path: root/src/Sema.zig
diff options
context:
space:
mode:
authorRobin Voetter <robin@voetter.nl>2022-01-03 01:56:59 +0100
committerRobin Voetter <robin@voetter.nl>2022-01-03 01:56:59 +0100
commit7f77d3d671dbfec11592d28cd51454aeefd07930 (patch)
tree56dba819edd4f810cdadb8e2a21dee2580aa2442 /src/Sema.zig
parent41e52bd5ccaccc0191c9f3434098d27ed07f62b7 (diff)
downloadzig-7f77d3d671dbfec11592d28cd51454aeefd07930.tar.gz
zig-7f77d3d671dbfec11592d28cd51454aeefd07930.zip
stage2: pointer reify
Diffstat (limited to 'src/Sema.zig')
-rw-r--r--src/Sema.zig34
1 files changed, 32 insertions, 2 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index 9ef3d9d425..5ba1e555a7 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -10269,11 +10269,41 @@ fn zirReify(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
var buffer: Value.ToTypeBuffer = undefined;
const child_ty = child_val.toType(&buffer);
- const ty = try Type.vector(sema.arena, len, child_ty);
+ const ty = try Type.vector(sema.arena, len, try child_ty.copy(sema.arena));
return sema.addType(ty);
},
.Float => return sema.fail(block, src, "TODO: Sema.zirReify for Float", .{}),
- .Pointer => return sema.fail(block, src, "TODO: Sema.zirReify for Pointer", .{}),
+ .Pointer => {
+ const struct_val = union_val.val.castTag(.@"struct").?.data;
+ // TODO use reflection instead of magic numbers here
+ const size_val = struct_val[0];
+ const is_const_val = struct_val[1];
+ const is_volatile_val = struct_val[2];
+ const alignment_val = struct_val[3];
+ const address_space_val = struct_val[4];
+ const child_val = struct_val[5];
+ const is_allowzero_val = struct_val[6];
+ const sentinel_val = struct_val[7];
+
+ var buffer: Value.ToTypeBuffer = undefined;
+ const child_ty = child_val.toType(&buffer);
+
+ if (!sentinel_val.isNull()) {
+ return sema.fail(block, src, "TODO: implement zirReify for pointer with non-null sentinel", .{});
+ }
+
+ const ty = try Type.ptr(sema.arena, .{
+ .size = size_val.toEnum(std.builtin.TypeInfo.Pointer.Size),
+ .mutable = !is_const_val.toBool(),
+ .@"volatile" = is_volatile_val.toBool(),
+ .@"align" = @intCast(u8, alignment_val.toUnsignedInt()), // TODO: Validate this value.
+ .@"addrspace" = address_space_val.toEnum(std.builtin.AddressSpace),
+ .pointee_type = try child_ty.copy(sema.arena),
+ .@"allowzero" = is_allowzero_val.toBool(),
+ .sentinel = null,
+ });
+ return sema.addType(ty);
+ },
.Array => return sema.fail(block, src, "TODO: Sema.zirReify for Array", .{}),
.Struct => return sema.fail(block, src, "TODO: Sema.zirReify for Struct", .{}),
.Optional => return sema.fail(block, src, "TODO: Sema.zirReify for Optional", .{}),