| ... | @@ -373,15 +373,16 @@ pub const DeclGen = struct { | ... | @@ -373,15 +373,16 @@ pub const DeclGen = struct { |
| 373 | const ty = self.spv.typeRefType(ty_ref); | 373 | const ty = self.spv.typeRefType(ty_ref); |
| 374 | const ty_id = self.typeId(ty_ref); | 374 | const ty_id = self.typeId(ty_ref); |
| 375 | | 375 | |
| 376 | const literal: spec.LiteralContextDependentNumber = switch (ty.intSignedness()) { | 376 | const Lit = spec.LiteralContextDependentNumber; |
| | 377 | const literal = switch (ty.intSignedness()) { |
| 377 | .signed => switch (ty.intFloatBits()) { | 378 | .signed => switch (ty.intFloatBits()) { |
| 378 | 1...32 => .{ .int32 = @intCast(i32, value) }, | 379 | 1...32 => Lit{ .int32 = @intCast(i32, value) }, |
| 379 | 33...64 => .{ .int64 = @intCast(i64, value) }, | 380 | 33...64 => Lit{ .int64 = @intCast(i64, value) }, |
| 380 | else => unreachable, // TODO: composite integer literals | 381 | else => unreachable, // TODO: composite integer literals |
| 381 | }, | 382 | }, |
| 382 | .unsigned => switch (ty.intFloatBits()) { | 383 | .unsigned => switch (ty.intFloatBits()) { |
| 383 | 1...32 => .{ .uint32 = @intCast(u32, value) }, | 384 | 1...32 => Lit{ .uint32 = @intCast(u32, value) }, |
| 384 | 33...64 => .{ .uint64 = @intCast(u64, value) }, | 385 | 33...64 => Lit{ .uint64 = @intCast(u64, value) }, |
| 385 | else => unreachable, | 386 | else => unreachable, |
| 386 | }, | 387 | }, |
| 387 | }; | 388 | }; |
| ... | @@ -552,6 +553,19 @@ pub const DeclGen = struct { | ... | @@ -552,6 +553,19 @@ pub const DeclGen = struct { |
| 552 | .constituents = constituents, | 553 | .constituents = constituents, |
| 553 | }); | 554 | }); |
| 554 | }, | 555 | }, |
| | 556 | .Pointer => switch (val.tag()) { |
| | 557 | .decl_ref => { |
| | 558 | const decl_index = val.castTag(.decl_ref).?.data; |
| | 559 | const decl_result_id = self.spv.allocId(); |
| | 560 | try self.genDeclRef(decl_result_id, decl_index); |
| | 561 | try section.emit(self.spv.gpa, .OpVariable, .{ |
| | 562 | .id_result_type = result_ty_id, |
| | 563 | .id_result = result_id, |
| | 564 | .storage_class = spirvStorageClass(ty.ptrAddressSpace()), |
| | 565 | }); |
| | 566 | }, |
| | 567 | else => return self.todo("constant pointer of value type {s}", .{@tagName(val.tag())}), |
| | 568 | }, |
| 555 | .Fn => switch (repr) { | 569 | .Fn => switch (repr) { |
| 556 | .direct => unreachable, | 570 | .direct => unreachable, |
| 557 | .indirect => return self.todo("function pointers", .{}), | 571 | .indirect => return self.todo("function pointers", .{}), |
| ... | @@ -561,6 +575,12 @@ pub const DeclGen = struct { | ... | @@ -561,6 +575,12 @@ pub const DeclGen = struct { |
| 561 | } | 575 | } |
| 562 | } | 576 | } |
| 563 | | 577 | |
| | 578 | fn genDeclRef(self: *DeclGen, result_id: IdRef, decl_index: Decl.Index) Error!void { |
| | 579 | const decl = self.module.declPtr(decl_index); |
| | 580 | self.module.markDeclAlive(decl); |
| | 581 | try self.genConstant(result_id, decl.ty, decl.val, .indirect); |
| | 582 | } |
| | 583 | |
| 564 | /// Turn a Zig type into a SPIR-V Type, and return its type result-id. | 584 | /// Turn a Zig type into a SPIR-V Type, and return its type result-id. |
| 565 | fn resolveTypeId(self: *DeclGen, ty: Type) !IdResultType { | 585 | fn resolveTypeId(self: *DeclGen, ty: Type) !IdResultType { |
| 566 | const type_ref = try self.resolveType(ty, .direct); | 586 | const type_ref = try self.resolveType(ty, .direct); |