aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/spirv/Module.zig
diff options
context:
space:
mode:
authorRobin Voetter <robin@voetter.nl>2022-11-26 16:51:53 +0100
committerRobin Voetter <robin@voetter.nl>2023-04-09 01:51:49 +0200
commit3f92eaceb61796254d0465ba5689378f15155791 (patch)
tree6ac76e438e7ef8823aa40b06cd7f793ddecee4ff /src/codegen/spirv/Module.zig
parentdae8b4c11f6a59dc6ccd3e4fe327c43eb73c44cb (diff)
downloadzig-3f92eaceb61796254d0465ba5689378f15155791.tar.gz
zig-3f92eaceb61796254d0465ba5689378f15155791.zip
spirv: array, structs, bitcast, call
Implements type lowering for arrays and structs, and implements instruction lowering for bitcast and call. Bitcast currently naively maps to the OpBitcast instruction - this is only valid for some primitive types, and should be improved to work with composites.
Diffstat (limited to 'src/codegen/spirv/Module.zig')
-rw-r--r--src/codegen/spirv/Module.zig17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/codegen/spirv/Module.zig b/src/codegen/spirv/Module.zig
index a6e0783bf4..f6c4cd735e 100644
--- a/src/codegen/spirv/Module.zig
+++ b/src/codegen/spirv/Module.zig
@@ -222,7 +222,7 @@ pub fn resolveType(self: *Module, ty: Type) !Type.Ref {
return @intToEnum(Type.Ref, result.index);
}
-pub fn resolveTypeId(self: *Module, ty: Type) !IdRef {
+pub fn resolveTypeId(self: *Module, ty: Type) !IdResultType {
const type_ref = try self.resolveType(ty);
return self.typeResultId(type_ref);
}
@@ -243,7 +243,7 @@ pub fn typeRefId(self: Module, type_ref: Type.Ref) IdRef {
/// Note: This function does not attempt to perform any validation on the type.
/// The type is emitted in a shallow fashion; any child types should already
/// be emitted at this point.
-pub fn emitType(self: *Module, ty: Type) !IdResultType {
+pub fn emitType(self: *Module, ty: Type) error{OutOfMemory}!IdResultType {
const result_id = self.allocId();
const ref_id = result_id.toRef();
const types = &self.sections.types_globals_constants;
@@ -347,10 +347,21 @@ pub fn emitType(self: *Module, ty: Type) !IdResultType {
.array => {
const info = ty.payload(.array);
assert(info.length != 0);
+
+ const size_type = Type.initTag(.u32);
+ const size_type_id = try self.resolveTypeId(size_type);
+
+ const length_id = self.allocId();
+ try types.emit(self.gpa, .OpConstant, .{
+ .id_result_type = size_type_id,
+ .id_result = length_id,
+ .value = .{ .uint32 = info.length },
+ });
+
try types.emit(self.gpa, .OpTypeArray, .{
.id_result = result_id,
.element_type = self.typeResultId(ty.childType()).toRef(),
- .length = .{ .id = 0 }, // TODO: info.length must be emitted as constant!
+ .length = length_id.toRef(),
});
if (info.array_stride != 0) {
try annotations.decorate(self.gpa, ref_id, .{ .ArrayStride = .{ .array_stride = info.array_stride } });