| ... | @@ -142,7 +142,7 @@ pub const LLVMIRModule = struct { | ... | @@ -142,7 +142,7 @@ pub const LLVMIRModule = struct { |
| 142 | target_machine: *const llvm.TargetMachineRef, | 142 | target_machine: *const llvm.TargetMachineRef, |
| 143 | builder: *const llvm.BuilderRef, | 143 | builder: *const llvm.BuilderRef, |
| 144 | | 144 | |
| 145 | output_path: []const u8, | 145 | object_path: []const u8, |
| 146 | | 146 | |
| 147 | gpa: *Allocator, | 147 | gpa: *Allocator, |
| 148 | err_msg: ?*Compilation.ErrorMsg = null, | 148 | err_msg: ?*Compilation.ErrorMsg = null, |
| ... | @@ -161,6 +161,17 @@ pub const LLVMIRModule = struct { | ... | @@ -161,6 +161,17 @@ pub const LLVMIRModule = struct { |
| 161 | | 161 | |
| 162 | const gpa = options.module.?.gpa; | 162 | const gpa = options.module.?.gpa; |
| 163 | | 163 | |
| | 164 | const obj_basename = try std.zig.binNameAlloc(gpa, .{ |
| | 165 | .root_name = options.root_name, |
| | 166 | .target = options.target, |
| | 167 | .output_mode = .Obj, |
| | 168 | }); |
| | 169 | defer gpa.free(obj_basename); |
| | 170 | |
| | 171 | const o_directory = options.module.?.zig_cache_artifact_directory; |
| | 172 | const object_path = try o_directory.join(gpa, &[_][]const u8{obj_basename}); |
| | 173 | errdefer gpa.free(object_path); |
| | 174 | |
| 164 | initializeLLVMTargets(); | 175 | initializeLLVMTargets(); |
| 165 | | 176 | |
| 166 | const root_nameZ = try gpa.dupeZ(u8, options.root_name); | 177 | const root_nameZ = try gpa.dupeZ(u8, options.root_name); |
| ... | @@ -212,7 +223,7 @@ pub const LLVMIRModule = struct { | ... | @@ -212,7 +223,7 @@ pub const LLVMIRModule = struct { |
| 212 | .llvm_module = llvm_module, | 223 | .llvm_module = llvm_module, |
| 213 | .target_machine = target_machine, | 224 | .target_machine = target_machine, |
| 214 | .builder = builder, | 225 | .builder = builder, |
| 215 | .output_path = sub_path, | 226 | .object_path = object_path, |
| 216 | .gpa = gpa, | 227 | .gpa = gpa, |
| 217 | }; | 228 | }; |
| 218 | return self; | 229 | return self; |
| ... | @@ -222,6 +233,10 @@ pub const LLVMIRModule = struct { | ... | @@ -222,6 +233,10 @@ pub const LLVMIRModule = struct { |
| 222 | self.builder.disposeBuilder(); | 233 | self.builder.disposeBuilder(); |
| 223 | self.target_machine.disposeTargetMachine(); | 234 | self.target_machine.disposeTargetMachine(); |
| 224 | self.llvm_module.disposeModule(); | 235 | self.llvm_module.disposeModule(); |
| | 236 | |
| | 237 | self.func_inst_table.deinit(self.gpa); |
| | 238 | self.gpa.free(self.object_path); |
| | 239 | |
| 225 | allocator.destroy(self); | 240 | allocator.destroy(self); |
| 226 | } | 241 | } |
| 227 | | 242 | |
| ... | @@ -254,15 +269,13 @@ pub const LLVMIRModule = struct { | ... | @@ -254,15 +269,13 @@ pub const LLVMIRModule = struct { |
| 254 | } | 269 | } |
| 255 | } | 270 | } |
| 256 | | 271 | |
| 257 | const output_pathZ = try self.gpa.dupeZ(u8, self.output_path); | 272 | const object_pathZ = try self.gpa.dupeZ(u8, self.object_path); |
| 258 | defer self.gpa.free(output_pathZ); | 273 | defer self.gpa.free(object_pathZ); |
| 259 | | 274 | |
| 260 | var error_message: [*:0]const u8 = undefined; | 275 | var error_message: [*:0]const u8 = undefined; |
| 261 | // TODO: where to put the output object, zig-cache something? | | |
| 262 | // TODO: caching? | | |
| 263 | if (self.target_machine.emitToFile( | 276 | if (self.target_machine.emitToFile( |
| 264 | self.llvm_module, | 277 | self.llvm_module, |
| 265 | output_pathZ.ptr, | 278 | object_pathZ.ptr, |
| 266 | .ObjectFile, | 279 | .ObjectFile, |
| 267 | &error_message, | 280 | &error_message, |
| 268 | )) { | 281 | )) { |