| ... | @@ -38,7 +38,7 @@ pub const FnData = struct { | ... | @@ -38,7 +38,7 @@ pub const FnData = struct { |
| 38 | base: link.File, | 38 | base: link.File, |
| 39 | | 39 | |
| 40 | // TODO: Does this file need to support multiple independent modules? | 40 | // TODO: Does this file need to support multiple independent modules? |
| 41 | spirv_module: codegen.SPIRVModule = .{}, | 41 | spirv_module: codegen.SPIRVModule, |
| 42 | | 42 | |
| 43 | pub fn createEmpty(gpa: *Allocator, options: link.Options) !*SpirV { | 43 | pub fn createEmpty(gpa: *Allocator, options: link.Options) !*SpirV { |
| 44 | const spirv = try gpa.create(SpirV); | 44 | const spirv = try gpa.create(SpirV); |
| ... | @@ -49,6 +49,7 @@ pub fn createEmpty(gpa: *Allocator, options: link.Options) !*SpirV { | ... | @@ -49,6 +49,7 @@ pub fn createEmpty(gpa: *Allocator, options: link.Options) !*SpirV { |
| 49 | .file = null, | 49 | .file = null, |
| 50 | .allocator = gpa, | 50 | .allocator = gpa, |
| 51 | }, | 51 | }, |
| | 52 | .spirv_module = codegen.SPIRVModule.init(gpa), |
| 52 | }; | 53 | }; |
| 53 | | 54 | |
| 54 | // TODO: Figure out where to put all of these | 55 | // TODO: Figure out where to put all of these |
| ... | @@ -87,6 +88,7 @@ pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Optio | ... | @@ -87,6 +88,7 @@ pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Optio |
| 87 | } | 88 | } |
| 88 | | 89 | |
| 89 | pub fn deinit(self: *SpirV) void { | 90 | pub fn deinit(self: *SpirV) void { |
| | 91 | self.spirv_module.deinit(); |
| 90 | } | 92 | } |
| 91 | | 93 | |
| 92 | pub fn updateDecl(self: *SpirV, module: *Module, decl: *Module.Decl) !void { | 94 | pub fn updateDecl(self: *SpirV, module: *Module, decl: *Module.Decl) !void { |
| ... | @@ -116,9 +118,12 @@ pub fn updateDeclExports( | ... | @@ -116,9 +118,12 @@ pub fn updateDeclExports( |
| 116 | ) !void {} | 118 | ) !void {} |
| 117 | | 119 | |
| 118 | pub fn freeDecl(self: *SpirV, decl: *Module.Decl) void { | 120 | pub fn freeDecl(self: *SpirV, decl: *Module.Decl) void { |
| 119 | decl.fn_link.spirv.code.deinit(self.base.allocator); | 121 | var fn_data = decl.fn_link.spirv; |
| | 122 | fn_data.code.deinit(self.base.allocator); |
| | 123 | if (fn_data.id) |id| self.spirv_module.freeId(id); |
| 120 | decl.fn_link.spirv = undefined; | 124 | decl.fn_link.spirv = undefined; |
| 121 | } | 125 | } |
| | 126 | |
| 122 | pub fn flush(self: *SpirV, comp: *Compilation) !void { | 127 | pub fn flush(self: *SpirV, comp: *Compilation) !void { |
| 123 | if (build_options.have_llvm and self.base.options.use_lld) { | 128 | if (build_options.have_llvm and self.base.options.use_lld) { |
| 124 | return error.LLD_LinkingIsTODO_ForSpirV; // TODO: LLD Doesn't support SpirV at all. | 129 | return error.LLD_LinkingIsTODO_ForSpirV; // TODO: LLD Doesn't support SpirV at all. |
| ... | @@ -137,8 +142,8 @@ pub fn flushModule(self: *SpirV, comp: *Compilation) !void { | ... | @@ -137,8 +142,8 @@ pub fn flushModule(self: *SpirV, comp: *Compilation) !void { |
| 137 | var binary = std.ArrayList(u32).init(self.base.allocator); | 142 | var binary = std.ArrayList(u32).init(self.base.allocator); |
| 138 | defer binary.deinit(); | 143 | defer binary.deinit(); |
| 139 | | 144 | |
| 140 | // Note: The order of adding functions to the final binary | 145 | // Note: The order of adding sections to the final binary |
| 141 | // follows the SPIR-V logical moduel format! | 146 | // follows the SPIR-V logical module format! |
| 142 | | 147 | |
| 143 | try binary.appendSlice(&[_]u32{ | 148 | try binary.appendSlice(&[_]u32{ |
| 144 | spec.magic_number, | 149 | spec.magic_number, |