Skip to content

Commit 1b3d0bb

Browse files
committed
add guards
1 parent 86664fb commit 1b3d0bb

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/link/NvPtx.zig

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ base: link.File,
2525
llvm_object: *LlvmObject,
2626

2727
pub fn createEmpty(gpa: Allocator, options: link.Options) !*NvPtx {
28+
if (!build_options.have_llvm) return error.TODOArchNotSupported;
29+
2830
const nvptx = try gpa.create(NvPtx);
2931
nvptx.* = .{
3032
.base = .{
@@ -36,8 +38,6 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*NvPtx {
3638
.llvm_object = undefined,
3739
};
3840

39-
if (!build_options.have_llvm) return error.TODOArchNotSupported;
40-
4141
switch (options.target.cpu.arch) {
4242
.nvptx, .nvptx64 => {},
4343
else => return error.TODOArchNotSupported,
@@ -53,8 +53,9 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*NvPtx {
5353
}
5454

5555
pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Options) !*NvPtx {
56+
if (!build_options.have_llvm) @panic("nvptx target requires a zig compiler with llvm enabled.");
57+
if (!options.use_llvm) return error.TODOArchNotSupported;
5658
assert(options.object_format == .nvptx);
57-
if (!build_options.have_llvm or !options.use_llvm) return error.NvptxRequiresLlvm;
5859

5960
const nvptx = try createEmpty(allocator, options);
6061
errdefer nvptx.base.destroy();
@@ -64,14 +65,17 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option
6465
}
6566

6667
pub fn deinit(self: *NvPtx) void {
68+
if (!build_options.have_llvm) return;
6769
self.llvm_object.destroy(self.base.allocator);
6870
}
6971

7072
pub fn updateFunc(self: *NvPtx, module: *Module, func: *Module.Fn, air: Air, liveness: Liveness) !void {
73+
if (!build_options.have_llvm) return;
7174
try self.llvm_object.updateFunc(module, func, air, liveness);
7275
}
7376

7477
pub fn updateDecl(self: *NvPtx, module: *Module, decl: *Module.Decl) !void {
78+
if (!build_options.have_llvm) return;
7579
return self.llvm_object.updateDecl(module, decl);
7680
}
7781

@@ -81,13 +85,15 @@ pub fn updateDeclExports(
8185
decl: *const Module.Decl,
8286
exports: []const *Module.Export,
8387
) !void {
88+
if (!build_options.have_llvm) return;
8489
if (build_options.skip_non_native and builtin.object_format != .nvptx) {
8590
@panic("Attempted to compile for object format that was disabled by build configuration");
8691
}
8792
return self.llvm_object.updateDeclExports(module, decl, exports);
8893
}
8994

9095
pub fn freeDecl(self: *NvPtx, decl: *Module.Decl) void {
96+
if (!build_options.have_llvm) return;
9197
return self.llvm_object.freeDecl(decl);
9298
}
9399

@@ -96,7 +102,8 @@ pub fn flush(self: *NvPtx, comp: *Compilation) !void {
96102
}
97103

98104
pub fn flushModule(self: *NvPtx, comp: *Compilation) !void {
99-
if (build_options.skip_non_native or !build_options.have_llvm) {
105+
if (!build_options.have_llvm) return;
106+
if (build_options.skip_non_native) {
100107
@panic("Attempted to compile for architecture that was disabled by build configuration");
101108
}
102109
const tracy = trace(@src());

0 commit comments

Comments
 (0)