From 2e65244cae7e4365ecf3aa6857b84451272316a1 Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Sat, 20 Jul 2024 07:43:40 -0400 Subject: [PATCH] dev: fix llvm backend checks --- src/Compilation.zig | 3 +-- src/Zcu.zig | 2 +- src/codegen/llvm.zig | 6 +++++- src/link.zig | 2 +- src/link/Coff.zig | 3 ++- src/link/Elf.zig | 2 +- src/link/MachO.zig | 4 ++-- src/link/NvPtx.zig | 2 +- src/link/Wasm.zig | 2 +- 9 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Compilation.zig b/src/Compilation.zig index b1c1851a6c..a05e54ee17 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -1729,7 +1729,6 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil comp.emit_llvm_ir != null or comp.emit_llvm_bc != null)) { - dev.check(.llvm_backend); if (opt_zcu) |zcu| zcu.llvm_object = try LlvmObject.create(arena, comp); } @@ -2704,7 +2703,7 @@ pub fn emitLlvmObject( arena: Allocator, default_emit: Emit, bin_emit_loc: ?EmitLoc, - llvm_object: *LlvmObject, + llvm_object: LlvmObject.Ptr, prog_node: std.Progress.Node, ) !void { const sub_prog_node = prog_node.start("LLVM Emit Object", 0); diff --git a/src/Zcu.zig b/src/Zcu.zig index 41311234d2..92baca90f2 100644 --- a/src/Zcu.zig +++ b/src/Zcu.zig @@ -58,7 +58,7 @@ comp: *Compilation, /// Usually, the LlvmObject is managed by linker code, however, in the case /// that -fno-emit-bin is specified, the linker code never executes, so we /// store the LlvmObject here. -llvm_object: if (dev.env.supports(.llvm_backend)) ?*LlvmObject else ?noreturn, +llvm_object: ?LlvmObject.Ptr, /// Pointer to externally managed resource. root_mod: *Package.Module, diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 4ed652a36d..13153c9bd5 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -26,6 +26,7 @@ const wasm_c_abi = @import("../arch/wasm/abi.zig"); const aarch64_c_abi = @import("../arch/aarch64/abi.zig"); const arm_c_abi = @import("../arch/arm/abi.zig"); const riscv_c_abi = @import("../arch/riscv64/abi.zig"); +const dev = @import("../dev.zig"); const target_util = @import("../target.zig"); const libcFloatPrefix = target_util.libcFloatPrefix; @@ -865,9 +866,12 @@ pub const Object = struct { field_index: u32, }; + pub const Ptr = if (dev.env.supports(.llvm_backend)) *Object else noreturn; + pub const TypeMap = std.AutoHashMapUnmanaged(InternPool.Index, Builder.Type); - pub fn create(arena: Allocator, comp: *Compilation) !*Object { + pub fn create(arena: Allocator, comp: *Compilation) !Ptr { + dev.check(.llvm_backend); const gpa = comp.gpa; const target = comp.root_mod.resolved_target.result; const llvm_target_triple = try targetTriple(arena, target); diff --git a/src/link.zig b/src/link.zig index cf780c76fa..f35c3e740f 100644 --- a/src/link.zig +++ b/src/link.zig @@ -968,7 +968,7 @@ pub const File = struct { pub fn emitLlvmObject( base: File, arena: Allocator, - llvm_object: *LlvmObject, + llvm_object: LlvmObject.Ptr, prog_node: std.Progress.Node, ) !void { return base.comp.emitLlvmObject(arena, base.emit, .{ diff --git a/src/link/Coff.zig b/src/link/Coff.zig index 732ceb85a6..96142efca3 100644 --- a/src/link/Coff.zig +++ b/src/link/Coff.zig @@ -4,7 +4,7 @@ //! LLD is also the default linker for LLVM. /// If this is not null, an object file is created by LLVM and emitted to zcu_object_sub_path. -llvm_object: ?*LlvmObject = null, +llvm_object: ?LlvmObject.Ptr = null, base: link.File, image_base: u64, @@ -2765,6 +2765,7 @@ const StringTable = @import("StringTable.zig"); const Type = @import("../Type.zig"); const Value = @import("../Value.zig"); const AnalUnit = InternPool.AnalUnit; +const dev = @import("../dev.zig"); pub const base_tag: link.File.Tag = .coff; diff --git a/src/link/Elf.zig b/src/link/Elf.zig index d09fea144c..7b44403c8a 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -30,7 +30,7 @@ entry_name: ?[]const u8, ptr_width: PtrWidth, /// If this is not null, an object file is created by LLVM and emitted to zcu_object_sub_path. -llvm_object: ?*LlvmObject = null, +llvm_object: ?LlvmObject.Ptr = null, /// A list of all input files. /// Index of each input file also encodes the priority or precedence of one input file diff --git a/src/link/MachO.zig b/src/link/MachO.zig index b9641ee76c..3e5b18e76f 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -1,7 +1,7 @@ base: link.File, /// If this is not null, an object file is created by LLVM and emitted to zcu_object_sub_path. -llvm_object: ?*LlvmObject = null, +llvm_object: ?LlvmObject.Ptr = null, /// Debug symbols bundle (or dSym). d_sym: ?DebugSymbols = null, @@ -4510,7 +4510,6 @@ const dead_strip = @import("MachO/dead_strip.zig"); const eh_frame = @import("MachO/eh_frame.zig"); const fat = @import("MachO/fat.zig"); const link = @import("../link.zig"); -const llvm_backend = @import("../codegen/llvm.zig"); const load_commands = @import("MachO/load_commands.zig"); const relocatable = @import("MachO/relocatable.zig"); const tapi = @import("tapi.zig"); @@ -4562,6 +4561,7 @@ const UnwindInfo = @import("MachO/UnwindInfo.zig"); const WeakBind = bind.WeakBind; const ZigGotSection = synthetic.ZigGotSection; const ZigObject = @import("MachO/ZigObject.zig"); +const dev = @import("../dev.zig"); pub const MachError = error{ /// Not enough permissions held to perform the requested kernel diff --git a/src/link/NvPtx.zig b/src/link/NvPtx.zig index 6d6179642d..8caaed05da 100644 --- a/src/link/NvPtx.zig +++ b/src/link/NvPtx.zig @@ -23,7 +23,7 @@ const Liveness = @import("../Liveness.zig"); const LlvmObject = @import("../codegen/llvm.zig").Object; base: link.File, -llvm_object: *LlvmObject, +llvm_object: LlvmObject.Ptr, pub fn createEmpty( arena: Allocator, diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig index 6239425614..c9651b24bb 100644 --- a/src/link/Wasm.zig +++ b/src/link/Wasm.zig @@ -61,7 +61,7 @@ export_table: bool, /// Output name of the file name: []const u8, /// If this is not null, an object file is created by LLVM and linked with LLD afterwards. -llvm_object: ?*LlvmObject = null, +llvm_object: ?LlvmObject.Ptr = null, /// The file index of a `ZigObject`. This will only contain a valid index when a zcu exists, /// and the chosen backend is the Wasm backend. zig_object_index: File.Index = .null,