diff --git a/CMakeLists.txt b/CMakeLists.txt index d51f753ac08d77e93e62190f3b03240bc205d637..3e002ca5c10f0a9c2cfeedc8412cba636d84c2d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -549,7 +549,7 @@ set(ZIG_STAGE2_SOURCES "${CMAKE_SOURCE_DIR}/src/link/cbe.h" "${CMAKE_SOURCE_DIR}/src/link/msdos-stub.bin" "${CMAKE_SOURCE_DIR}/src/liveness.zig" - "${CMAKE_SOURCE_DIR}/src/llvm.zig" + "${CMAKE_SOURCE_DIR}/src/llvm_bindings.zig" "${CMAKE_SOURCE_DIR}/src/main.zig" "${CMAKE_SOURCE_DIR}/src/mingw.zig" "${CMAKE_SOURCE_DIR}/src/musl.zig" diff --git a/src/link.zig b/src/link.zig index 530bcd0b259280677d3e2d6bad18b7e12521aaa1..468f23bffd7ea4f79292cb290732790f4deefcbf 100644 --- a/src/link.zig +++ b/src/link.zig @@ -567,7 +567,7 @@ pub const File = struct { std.debug.print("\n", .{}); } - const llvm = @import("llvm.zig"); + const llvm = @import("llvm_bindings.zig"); const os_type = @import("target.zig").osToLLVM(base.options.target.os.tag); const bad = llvm.WriteArchive(full_out_path_z, object_files.items.ptr, object_files.items.len, os_type); if (bad) return error.UnableToWriteArchive; diff --git a/src/llvm.zig b/src/llvm.zig deleted file mode 100644 index 865e989c89d1751bbea1ad83d7a64650b8be0d6a..0000000000000000000000000000000000000000 --- a/src/llvm.zig +++ /dev/null @@ -1,140 +0,0 @@ -//! We do this instead of @cImport because the self-hosted compiler is easier -//! to bootstrap if it does not depend on translate-c. - -extern fn ZigLLDLinkCOFF(argc: c_int, argv: [*:null]const ?[*:0]const u8, can_exit_early: bool) c_int; -extern fn ZigLLDLinkELF(argc: c_int, argv: [*:null]const ?[*:0]const u8, can_exit_early: bool) c_int; -extern fn ZigLLDLinkMachO(argc: c_int, argv: [*:null]const ?[*:0]const u8, can_exit_early: bool) c_int; -extern fn ZigLLDLinkWasm(argc: c_int, argv: [*:null]const ?[*:0]const u8, can_exit_early: bool) c_int; - -pub const LinkCOFF = ZigLLDLinkCOFF; -pub const LinkELF = ZigLLDLinkELF; -pub const LinkMachO = ZigLLDLinkMachO; -pub const LinkWasm = ZigLLDLinkWasm; - -pub const ObjectFormatType = extern enum(c_int) { - Unknown, - COFF, - ELF, - MachO, - Wasm, - XCOFF, -}; - -pub const GetHostCPUName = LLVMGetHostCPUName; -extern fn LLVMGetHostCPUName() ?[*:0]u8; - -pub const GetNativeFeatures = ZigLLVMGetNativeFeatures; -extern fn ZigLLVMGetNativeFeatures() ?[*:0]u8; - -pub const WriteArchive = ZigLLVMWriteArchive; -extern fn ZigLLVMWriteArchive( - archive_name: [*:0]const u8, - file_names_ptr: [*]const [*:0]const u8, - file_names_len: usize, - os_type: OSType, -) bool; - -pub const OSType = extern enum(c_int) { - UnknownOS = 0, - Ananas = 1, - CloudABI = 2, - Darwin = 3, - DragonFly = 4, - FreeBSD = 5, - Fuchsia = 6, - IOS = 7, - KFreeBSD = 8, - Linux = 9, - Lv2 = 10, - MacOSX = 11, - NetBSD = 12, - OpenBSD = 13, - Solaris = 14, - Win32 = 15, - Haiku = 16, - Minix = 17, - RTEMS = 18, - NaCl = 19, - CNK = 20, - AIX = 21, - CUDA = 22, - NVCL = 23, - AMDHSA = 24, - PS4 = 25, - ELFIAMCU = 26, - TvOS = 27, - WatchOS = 28, - Mesa3D = 29, - Contiki = 30, - AMDPAL = 31, - HermitCore = 32, - Hurd = 33, - WASI = 34, - Emscripten = 35, -}; - -pub const ArchType = extern enum(c_int) { - UnknownArch = 0, - arm = 1, - armeb = 2, - aarch64 = 3, - aarch64_be = 4, - aarch64_32 = 5, - arc = 6, - avr = 7, - bpfel = 8, - bpfeb = 9, - hexagon = 10, - mips = 11, - mipsel = 12, - mips64 = 13, - mips64el = 14, - msp430 = 15, - ppc = 16, - ppc64 = 17, - ppc64le = 18, - r600 = 19, - amdgcn = 20, - riscv32 = 21, - riscv64 = 22, - sparc = 23, - sparcv9 = 24, - sparcel = 25, - systemz = 26, - tce = 27, - tcele = 28, - thumb = 29, - thumbeb = 30, - x86 = 31, - x86_64 = 32, - xcore = 33, - nvptx = 34, - nvptx64 = 35, - le32 = 36, - le64 = 37, - amdil = 38, - amdil64 = 39, - hsail = 40, - hsail64 = 41, - spir = 42, - spir64 = 43, - kalimba = 44, - shave = 45, - lanai = 46, - wasm32 = 47, - wasm64 = 48, - renderscript32 = 49, - renderscript64 = 50, - ve = 51, -}; - -pub const ParseCommandLineOptions = ZigLLVMParseCommandLineOptions; -extern fn ZigLLVMParseCommandLineOptions(argc: usize, argv: [*]const [*:0]const u8) void; - -pub const WriteImportLibrary = ZigLLVMWriteImportLibrary; -extern fn ZigLLVMWriteImportLibrary( - def_path: [*:0]const u8, - arch: ArchType, - output_lib_path: [*c]const u8, - kill_at: bool, -) bool; diff --git a/src/llvm_bindings.zig b/src/llvm_bindings.zig new file mode 100644 index 0000000000000000000000000000000000000000..865e989c89d1751bbea1ad83d7a64650b8be0d6a --- /dev/null +++ b/src/llvm_bindings.zig @@ -0,0 +1,140 @@ +//! We do this instead of @cImport because the self-hosted compiler is easier +//! to bootstrap if it does not depend on translate-c. + +extern fn ZigLLDLinkCOFF(argc: c_int, argv: [*:null]const ?[*:0]const u8, can_exit_early: bool) c_int; +extern fn ZigLLDLinkELF(argc: c_int, argv: [*:null]const ?[*:0]const u8, can_exit_early: bool) c_int; +extern fn ZigLLDLinkMachO(argc: c_int, argv: [*:null]const ?[*:0]const u8, can_exit_early: bool) c_int; +extern fn ZigLLDLinkWasm(argc: c_int, argv: [*:null]const ?[*:0]const u8, can_exit_early: bool) c_int; + +pub const LinkCOFF = ZigLLDLinkCOFF; +pub const LinkELF = ZigLLDLinkELF; +pub const LinkMachO = ZigLLDLinkMachO; +pub const LinkWasm = ZigLLDLinkWasm; + +pub const ObjectFormatType = extern enum(c_int) { + Unknown, + COFF, + ELF, + MachO, + Wasm, + XCOFF, +}; + +pub const GetHostCPUName = LLVMGetHostCPUName; +extern fn LLVMGetHostCPUName() ?[*:0]u8; + +pub const GetNativeFeatures = ZigLLVMGetNativeFeatures; +extern fn ZigLLVMGetNativeFeatures() ?[*:0]u8; + +pub const WriteArchive = ZigLLVMWriteArchive; +extern fn ZigLLVMWriteArchive( + archive_name: [*:0]const u8, + file_names_ptr: [*]const [*:0]const u8, + file_names_len: usize, + os_type: OSType, +) bool; + +pub const OSType = extern enum(c_int) { + UnknownOS = 0, + Ananas = 1, + CloudABI = 2, + Darwin = 3, + DragonFly = 4, + FreeBSD = 5, + Fuchsia = 6, + IOS = 7, + KFreeBSD = 8, + Linux = 9, + Lv2 = 10, + MacOSX = 11, + NetBSD = 12, + OpenBSD = 13, + Solaris = 14, + Win32 = 15, + Haiku = 16, + Minix = 17, + RTEMS = 18, + NaCl = 19, + CNK = 20, + AIX = 21, + CUDA = 22, + NVCL = 23, + AMDHSA = 24, + PS4 = 25, + ELFIAMCU = 26, + TvOS = 27, + WatchOS = 28, + Mesa3D = 29, + Contiki = 30, + AMDPAL = 31, + HermitCore = 32, + Hurd = 33, + WASI = 34, + Emscripten = 35, +}; + +pub const ArchType = extern enum(c_int) { + UnknownArch = 0, + arm = 1, + armeb = 2, + aarch64 = 3, + aarch64_be = 4, + aarch64_32 = 5, + arc = 6, + avr = 7, + bpfel = 8, + bpfeb = 9, + hexagon = 10, + mips = 11, + mipsel = 12, + mips64 = 13, + mips64el = 14, + msp430 = 15, + ppc = 16, + ppc64 = 17, + ppc64le = 18, + r600 = 19, + amdgcn = 20, + riscv32 = 21, + riscv64 = 22, + sparc = 23, + sparcv9 = 24, + sparcel = 25, + systemz = 26, + tce = 27, + tcele = 28, + thumb = 29, + thumbeb = 30, + x86 = 31, + x86_64 = 32, + xcore = 33, + nvptx = 34, + nvptx64 = 35, + le32 = 36, + le64 = 37, + amdil = 38, + amdil64 = 39, + hsail = 40, + hsail64 = 41, + spir = 42, + spir64 = 43, + kalimba = 44, + shave = 45, + lanai = 46, + wasm32 = 47, + wasm64 = 48, + renderscript32 = 49, + renderscript64 = 50, + ve = 51, +}; + +pub const ParseCommandLineOptions = ZigLLVMParseCommandLineOptions; +extern fn ZigLLVMParseCommandLineOptions(argc: usize, argv: [*]const [*:0]const u8) void; + +pub const WriteImportLibrary = ZigLLVMWriteImportLibrary; +extern fn ZigLLVMWriteImportLibrary( + def_path: [*:0]const u8, + arch: ArchType, + output_lib_path: [*c]const u8, + kill_at: bool, +) bool; diff --git a/src/main.zig b/src/main.zig index c23cba98d802ec8eeff551c72d743897ebb5262f..15bb3be60236209a31c0ddd452671fa9456baae4 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1676,7 +1676,7 @@ fn buildOutputType( if (build_options.have_llvm and emit_asm != .no) { // LLVM has no way to set this non-globally. const argv = [_][*:0]const u8{ "zig (LLVM option parsing)", "--x86-asm-syntax=intel" }; - @import("llvm.zig").ParseCommandLineOptions(argv.len, &argv); + @import("llvm_bindings.zig").ParseCommandLineOptions(argv.len, &argv); } gimmeMoreOfThoseSweetSweetFileDescriptors(); @@ -2839,7 +2839,7 @@ pub fn punt_to_lld(arena: *Allocator, args: []const []const u8) error{OutOfMemor argv[i] = try arena.dupeZ(u8, arg); // TODO If there was an argsAllocZ we could avoid this allocation. } const exit_code = rc: { - const llvm = @import("llvm.zig"); + const llvm = @import("llvm_bindings.zig"); const argc = @intCast(c_int, argv.len); if (mem.eql(u8, args[1], "ld.lld")) { break :rc llvm.LinkELF(argc, argv.ptr, true); @@ -3224,7 +3224,7 @@ fn detectNativeTargetInfo(gpa: *Allocator, cross_target: std.zig.CrossTarget) !s if (!build_options.have_llvm) fatal("CPU features detection is not yet available for {} without LLVM extensions", .{@tagName(arch)}); - const llvm = @import("llvm.zig"); + const llvm = @import("llvm_bindings.zig"); const llvm_cpu_name = llvm.GetHostCPUName(); const llvm_cpu_features = llvm.GetNativeFeatures(); info.target.cpu = try detectNativeCpuWithLLVM(arch, llvm_cpu_name, llvm_cpu_features); diff --git a/src/mingw.zig b/src/mingw.zig index a9e275434f31882bf9bd17d61759ab7e43d0e1e9..246b0f33dcf8258cb6de16d681ebcd3622e69bb7 100644 --- a/src/mingw.zig +++ b/src/mingw.zig @@ -405,7 +405,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void { }); errdefer comp.gpa.free(lib_final_path); - const llvm = @import("llvm.zig"); + const llvm = @import("llvm_bindings.zig"); const arch_type = @import("target.zig").archToLLVM(target.cpu.arch); const def_final_path_z = try arena.dupeZ(u8, def_final_path); const lib_final_path_z = try arena.dupeZ(u8, lib_final_path); diff --git a/src/target.zig b/src/target.zig index b3c83c76d8f507f12e4e1e1d77c79e84f759fd2f..cfe16f3fe63ffc78f135fa1fe8367b85f38a73e5 100644 --- a/src/target.zig +++ b/src/target.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const llvm = @import("llvm.zig"); +const llvm = @import("llvm_bindings.zig"); pub const ArchOsAbi = struct { arch: std.Target.Cpu.Arch,