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 {
5757 module: *Module,
5858 spv: *SPIRVModule,
5959
60 args: std.ArrayList(u32),
6061 types: TypeMap,
6162
6263 decl: *Decl,
......@@ -213,7 +214,17 @@ pub const DeclGen = struct {
213214 prototype_id,
214215 });
215216
216 // TODO: Parameters
217 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
217228 // TODO: Body
218229
219230 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 {
140140 // Now, actually generate the code for all declarations.
141141 {
142142 // 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 this
143 // change the decl. Otherwise, we would have to keep a separate `args` and `types`, and re-construct this
144144 // structure every time.
145145 var decl_gen = codegen.DeclGen{
146146 .module = module,
147147 .spv = &spv,
148 .args = std.ArrayList(u32).init(self.base.allocator),
148149 .types = codegen.TypeMap.init(self.base.allocator),
149150 .decl = undefined,
150151 .error_msg = undefined,
151152 };
152153
153154 defer decl_gen.types.deinit();
155 defer decl_gen.args.deinit();
154156
155157 for (module.decl_table.items()) |entry| {
156158 const decl = entry.value;
157159 if (decl.typed_value != .most_recent)
158160 continue;
159161
162 decl_gen.args.items.len = 0;
160163 decl_gen.decl = decl;
161164 decl_gen.error_msg = null;
162165