Skip to content

Commit

Permalink
fix Nvptx backend outputing files at the top level of zig-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
gwenzek committed Nov 16, 2022
1 parent a93fa29 commit 1bea4f3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/std/zig.zig
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ pub fn binNameAlloc(allocator: std.mem.Allocator, options: BinNameOptions) error
target.libPrefix(), root_name,
}),
},
.nvptx => return std.fmt.allocPrint(allocator, "{s}", .{root_name}),
.nvptx => return std.fmt.allocPrint(allocator, "{s}.ptx", .{root_name}),
.dxcontainer => @panic("TODO what's the file extension for these?"),
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/link/NvPtx.zig
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const LlvmObject = @import("../codegen/llvm.zig").Object;

base: link.File,
llvm_object: *LlvmObject,
ptx_file_name: []const u8,

pub fn createEmpty(gpa: Allocator, options: link.Options) !*NvPtx {
if (!build_options.have_llvm) return error.PtxArchNotSupported;
Expand All @@ -46,6 +47,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*NvPtx {
.allocator = gpa,
},
.llvm_object = llvm_object,
.ptx_file_name = try std.mem.join(gpa, "", &[_][]const u8{ options.root_name, ".ptx" }),
};

return nvptx;
Expand All @@ -63,6 +65,7 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option
pub fn deinit(self: *NvPtx) void {
if (!build_options.have_llvm) return;
self.llvm_object.destroy(self.base.allocator);
self.base.allocator.free(self.ptx_file_name);
}

pub fn updateFunc(self: *NvPtx, module: *Module, func: *Module.Fn, air: Air, liveness: Liveness) !void {
Expand Down Expand Up @@ -111,8 +114,9 @@ pub fn flushModule(self: *NvPtx, comp: *Compilation, prog_node: *std.Progress.No
// This is required by the LLVM PTX backend.
comp.bin_file.options.emit = null;
comp.emit_asm = .{
.directory = outfile.directory,
.basename = comp.bin_file.intermediary_basename.?,
// 'null' means using the default cache dir: zig-cache/o/...
.directory = null,
.basename = self.ptx_file_name,
};
defer {
comp.bin_file.options.emit = outfile;
Expand Down

0 comments on commit 1bea4f3

Please sign in to comment.