| author | |
| committer | |
| log | da0cc732ea899d2284200faf54c3c12e8c798b7f |
| tree | 186620f16603ad01ad74b1fff0928054e0c332cf |
| parent | 074cb9f1daff0f9d8c3bc5736b8990aa53eb8226 |
2 files changed, 16 insertions(+), 2 deletions(-)
src/codegen/spirv.zig+12-1| ... | ... | @@ -57,6 +57,7 @@ pub const DeclGen = struct { |
| 57 | 57 | module: *Module, |
| 58 | 58 | spv: *SPIRVModule, |
| 59 | 59 | |
| 60 | args: std.ArrayList(u32), | |
| 60 | 61 | types: TypeMap, |
| 61 | 62 | |
| 62 | 63 | decl: *Decl, |
| ... | ... | @@ -213,7 +214,17 @@ pub const DeclGen = struct { |
| 213 | 214 | prototype_id, |
| 214 | 215 | }); |
| 215 | 216 | |
| 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 | ||
| 217 | 228 | // TODO: Body |
| 218 | 229 | |
| 219 | 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 | 140 | // Now, actually generate the code for all declarations. |
| 141 | 141 | { |
| 142 | 142 | // 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 | |
| 144 | 144 | // structure every time. |
| 145 | 145 | var decl_gen = codegen.DeclGen{ |
| 146 | 146 | .module = module, |
| 147 | 147 | .spv = &spv, |
| 148 | .args = std.ArrayList(u32).init(self.base.allocator), | |
| 148 | 149 | .types = codegen.TypeMap.init(self.base.allocator), |
| 149 | 150 | .decl = undefined, |
| 150 | 151 | .error_msg = undefined, |
| 151 | 152 | }; |
| 152 | 153 | |
| 153 | 154 | defer decl_gen.types.deinit(); |
| 155 | defer decl_gen.args.deinit(); | |
| 154 | 156 | |
| 155 | 157 | for (module.decl_table.items()) |entry| { |
| 156 | 158 | const decl = entry.value; |
| 157 | 159 | if (decl.typed_value != .most_recent) |
| 158 | 160 | continue; |
| 159 | 161 | |
| 162 | decl_gen.args.items.len = 0; | |
| 160 | 163 | decl_gen.decl = decl; |
| 161 | 164 | decl_gen.error_msg = null; |
| 162 | 165 |