authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2021-05-15 03:27:59+02:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2021-05-16 14:13:23+02:00
logda0cc732ea899d2284200faf54c3c12e8c798b7f
tree186620f16603ad01ad74b1fff0928054e0c332cf
parent074cb9f1daff0f9d8c3bc5736b8990aa53eb8226

SPIR-V: Function parameter generation


2 files changed, 16 insertions(+), 2 deletions(-)

src/codegen/spirv.zig+12-1
...@@ -57,6 +57,7 @@ pub const DeclGen = struct {...@@ -57,6 +57,7 @@ pub const DeclGen = struct {
57 module: *Module,57 module: *Module,
58 spv: *SPIRVModule,58 spv: *SPIRVModule,
5959
60 args: std.ArrayList(u32),
60 types: TypeMap,61 types: TypeMap,
6162
62 decl: *Decl,63 decl: *Decl,
...@@ -213,7 +214,17 @@ pub const DeclGen = struct {...@@ -213,7 +214,17 @@ pub const DeclGen = struct {
213 prototype_id,214 prototype_id,
214 });215 });
215216
216 // TODO: Parameters217 const params = tv.ty.fnParamLen();
218 var i: usize = 0;
219
220 try self.args.ensureCapacity(params);
221 while (i < params) : (i += 1) {
222 const param_type_id = self.types.get(tv.ty.fnParamType(i)).?;
223 const arg_result_id = self.spv.allocResultId();
224 try writeInstruction(&self.spv.fn_decls, .OpFunctionParameter, &[_]u32{ param_type_id, arg_result_id });
225 self.args.appendAssumeCapacity(arg_result_id);
226 }
227
217 // TODO: Body228 // TODO: Body
218229
219 try writeInstruction(&self.spv.fn_decls, .OpFunctionEnd, &[_]u32{});230 try writeInstruction(&self.spv.fn_decls, .OpFunctionEnd, &[_]u32{});
src/link/SpirV.zig+4-1
...@@ -140,23 +140,26 @@ pub fn flushModule(self: *SpirV, comp: *Compilation) !void {...@@ -140,23 +140,26 @@ pub fn flushModule(self: *SpirV, comp: *Compilation) !void {
140 // Now, actually generate the code for all declarations.140 // Now, actually generate the code for all declarations.
141 {141 {
142 // We are just going to re-use this same DeclGen for every Decl, and we are just going to142 // We are just going to re-use this same DeclGen for every Decl, and we are just going to
143 // change the decl. Otherwise, we would have to keep a separate `types`, and re-construct this143 // change the decl. Otherwise, we would have to keep a separate `args` and `types`, and re-construct this
144 // structure every time.144 // structure every time.
145 var decl_gen = codegen.DeclGen{145 var decl_gen = codegen.DeclGen{
146 .module = module,146 .module = module,
147 .spv = &spv,147 .spv = &spv,
148 .args = std.ArrayList(u32).init(self.base.allocator),
148 .types = codegen.TypeMap.init(self.base.allocator),149 .types = codegen.TypeMap.init(self.base.allocator),
149 .decl = undefined,150 .decl = undefined,
150 .error_msg = undefined,151 .error_msg = undefined,
151 };152 };
152153
153 defer decl_gen.types.deinit();154 defer decl_gen.types.deinit();
155 defer decl_gen.args.deinit();
154156
155 for (module.decl_table.items()) |entry| {157 for (module.decl_table.items()) |entry| {
156 const decl = entry.value;158 const decl = entry.value;
157 if (decl.typed_value != .most_recent)159 if (decl.typed_value != .most_recent)
158 continue;160 continue;
159161
162 decl_gen.args.items.len = 0;
160 decl_gen.decl = decl;163 decl_gen.decl = decl;
161 decl_gen.error_msg = null;164 decl_gen.error_msg = null;
162165