diff options
| author | Robin Voetter <robin@voetter.nl> | 2022-12-03 00:13:25 +0100 |
|---|---|---|
| committer | Robin Voetter <robin@voetter.nl> | 2023-04-09 01:51:52 +0200 |
| commit | fbe5f0c3459484babcf3d4ba6fe4901612a409bb (patch) | |
| tree | 4e3f1c4b21e50ed3d7b7d0e3f27f4ad6069aee8a /src/codegen | |
| parent | c9db6e43af366215cd8bf494ea54ad14e4b97cc0 (diff) | |
| download | zig-fbe5f0c3459484babcf3d4ba6fe4901612a409bb.tar.gz zig-fbe5f0c3459484babcf3d4ba6fe4901612a409bb.zip | |
spirv: initial decl_ref pointer generation
Starts lowering decl_ref Pointer constants.
Diffstat (limited to 'src/codegen')
| -rw-r--r-- | src/codegen/spirv.zig | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/src/codegen/spirv.zig b/src/codegen/spirv.zig index f44e894a29..d96377a29c 100644 --- a/src/codegen/spirv.zig +++ b/src/codegen/spirv.zig @@ -373,15 +373,16 @@ pub const DeclGen = struct { const ty = self.spv.typeRefType(ty_ref); const ty_id = self.typeId(ty_ref); - const literal: spec.LiteralContextDependentNumber = switch (ty.intSignedness()) { + const Lit = spec.LiteralContextDependentNumber; + const literal = switch (ty.intSignedness()) { .signed => switch (ty.intFloatBits()) { - 1...32 => .{ .int32 = @intCast(i32, value) }, - 33...64 => .{ .int64 = @intCast(i64, value) }, + 1...32 => Lit{ .int32 = @intCast(i32, value) }, + 33...64 => Lit{ .int64 = @intCast(i64, value) }, else => unreachable, // TODO: composite integer literals }, .unsigned => switch (ty.intFloatBits()) { - 1...32 => .{ .uint32 = @intCast(u32, value) }, - 33...64 => .{ .uint64 = @intCast(u64, value) }, + 1...32 => Lit{ .uint32 = @intCast(u32, value) }, + 33...64 => Lit{ .uint64 = @intCast(u64, value) }, else => unreachable, }, }; @@ -552,6 +553,19 @@ pub const DeclGen = struct { .constituents = constituents, }); }, + .Pointer => switch (val.tag()) { + .decl_ref => { + const decl_index = val.castTag(.decl_ref).?.data; + const decl_result_id = self.spv.allocId(); + try self.genDeclRef(decl_result_id, decl_index); + try section.emit(self.spv.gpa, .OpVariable, .{ + .id_result_type = result_ty_id, + .id_result = result_id, + .storage_class = spirvStorageClass(ty.ptrAddressSpace()), + }); + }, + else => return self.todo("constant pointer of value type {s}", .{@tagName(val.tag())}), + }, .Fn => switch (repr) { .direct => unreachable, .indirect => return self.todo("function pointers", .{}), @@ -561,6 +575,12 @@ pub const DeclGen = struct { } } + fn genDeclRef(self: *DeclGen, result_id: IdRef, decl_index: Decl.Index) Error!void { + const decl = self.module.declPtr(decl_index); + self.module.markDeclAlive(decl); + try self.genConstant(result_id, decl.ty, decl.val, .indirect); + } + /// Turn a Zig type into a SPIR-V Type, and return its type result-id. fn resolveTypeId(self: *DeclGen, ty: Type) !IdResultType { const type_ref = try self.resolveType(ty, .direct); |
