diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-07-23 02:22:23 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-23 02:22:23 -0400 |
| commit | e3fe3acce0fc65a7f0c7227085456e8d167ed2a7 (patch) | |
| tree | 17b5feeab6232ed6bbeff5f5ea7026c6b1ec2235 /lib/std | |
| parent | a38a6914875ab3bda02fb1732467228ef876074e (diff) | |
| parent | 80ba9f060d81e8c5674acb4eb07c833d26121462 (diff) | |
| download | zig-e3fe3acce0fc65a7f0c7227085456e8d167ed2a7.tar.gz zig-e3fe3acce0fc65a7f0c7227085456e8d167ed2a7.zip | |
Merge pull request #9440 from ziglang/emit-bc
add -femit-llvm-bc CLI option and implement it, and improve -fcompiler-rt support
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/target.zig | 100 | ||||
| -rw-r--r-- | lib/std/zig.zig | 40 | ||||
| -rw-r--r-- | lib/std/zig/cross_target.zig | 4 |
3 files changed, 73 insertions, 71 deletions
diff --git a/lib/std/target.zig b/lib/std/target.zig index 70626f5051..1b9f0084c8 100644 --- a/lib/std/target.zig +++ b/lib/std/target.zig @@ -549,16 +549,36 @@ pub const Target = struct { }; pub const ObjectFormat = enum { + /// Common Object File Format (Windows) coff, - pe, + /// Executable and Linking Format elf, + /// macOS relocatables macho, + /// WebAssembly wasm, + /// C source code c, + /// Standard, Portable Intermediate Representation V spirv, + /// Intel IHEX hex, + /// Machine code with no metadata. raw, + /// Plan 9 from Bell Labs plan9, + + pub fn fileExt(of: ObjectFormat, cpu_arch: Cpu.Arch) [:0]const u8 { + return switch (of) { + .coff => ".obj", + .elf, .macho, .wasm => ".o", + .c => ".c", + .spirv => ".spv", + .hex => ".ihex", + .raw => ".bin", + .plan9 => plan9Ext(cpu_arch), + }; + } }; pub const SubSystem = enum { @@ -1290,30 +1310,16 @@ pub const Target = struct { return linuxTripleSimple(allocator, self.cpu.arch, self.os.tag, self.abi); } - pub fn oFileExt_os_abi(os_tag: Os.Tag, abi: Abi) [:0]const u8 { - if (abi == .msvc) { - return ".obj"; - } - switch (os_tag) { - .windows, .uefi => return ".obj", - else => return ".o", - } - } - - pub fn oFileExt(self: Target) [:0]const u8 { - return oFileExt_os_abi(self.os.tag, self.abi); - } - pub fn exeFileExtSimple(cpu_arch: Cpu.Arch, os_tag: Os.Tag) [:0]const u8 { - switch (os_tag) { - .windows => return ".exe", - .uefi => return ".efi", - else => if (cpu_arch.isWasm()) { - return ".wasm"; - } else { - return ""; + return switch (os_tag) { + .windows => ".exe", + .uefi => ".efi", + .plan9 => plan9Ext(cpu_arch), + else => switch (cpu_arch) { + .wasm32, .wasm64 => ".wasm", + else => "", }, - } + }; } pub fn exeFileExt(self: Target) [:0]const u8 { @@ -1353,20 +1359,16 @@ pub const Target = struct { } pub fn getObjectFormatSimple(os_tag: Os.Tag, cpu_arch: Cpu.Arch) ObjectFormat { - if (os_tag == .windows or os_tag == .uefi) { - return .coff; - } else if (os_tag.isDarwin()) { - return .macho; - } - if (cpu_arch.isWasm()) { - return .wasm; - } - if (cpu_arch.isSPIRV()) { - return .spirv; - } - if (os_tag == .plan9) - return .plan9; - return .elf; + return switch (os_tag) { + .windows, .uefi => .coff, + .ios, .macos, .watchos, .tvos => .macho, + .plan9 => .plan9, + else => return switch (cpu_arch) { + .wasm32, .wasm64 => .wasm, + .spirv32, .spirv64 => .spirv, + else => .elf, + }, + }; } pub fn getObjectFormat(self: Target) ObjectFormat { @@ -1677,6 +1679,30 @@ pub const Target = struct { return false; } + + /// 0c spim little-endian MIPS 3000 family + /// 1c 68000 Motorola MC68000 + /// 2c 68020 Motorola MC68020 + /// 5c arm little-endian ARM + /// 6c amd64 AMD64 and compatibles (e.g., Intel EM64T) + /// 7c arm64 ARM64 (ARMv8) + /// 8c 386 Intel i386, i486, Pentium, etc. + /// kc sparc Sun SPARC + /// qc power Power PC + /// vc mips big-endian MIPS 3000 family + pub fn plan9Ext(cpu_arch: Cpu.Arch) [:0]const u8 { + return switch (cpu_arch) { + .arm => ".5", + .x86_64 => ".6", + .aarch64 => ".7", + .i386 => ".8", + .sparc => ".k", + .powerpc, .powerpcle => ".q", + .mips, .mipsel => ".v", + // ISAs without designated characters get 'X' for lack of a better option. + else => ".X", + }; + } }; test { diff --git a/lib/std/zig.zig b/lib/std/zig.zig index 595dce77c2..303c930b93 100644 --- a/lib/std/zig.zig +++ b/lib/std/zig.zig @@ -108,8 +108,9 @@ pub const BinNameOptions = struct { pub fn binNameAlloc(allocator: *std.mem.Allocator, options: BinNameOptions) error{OutOfMemory}![]u8 { const root_name = options.root_name; const target = options.target; - switch (options.object_format orelse target.getObjectFormat()) { - .coff, .pe => switch (options.output_mode) { + const ofmt = options.object_format orelse target.getObjectFormat(); + switch (ofmt) { + .coff => switch (options.output_mode) { .Exe => return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, target.exeFileExt() }), .Lib => { const suffix = switch (options.link_mode orelse .Static) { @@ -118,7 +119,7 @@ pub fn binNameAlloc(allocator: *std.mem.Allocator, options: BinNameOptions) erro }; return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, suffix }); }, - .Obj => return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, target.oFileExt() }), + .Obj => return std.fmt.allocPrint(allocator, "{s}.obj", .{root_name}), }, .elf => switch (options.output_mode) { .Exe => return allocator.dupe(u8, root_name), @@ -140,7 +141,7 @@ pub fn binNameAlloc(allocator: *std.mem.Allocator, options: BinNameOptions) erro }, } }, - .Obj => return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, target.oFileExt() }), + .Obj => return std.fmt.allocPrint(allocator, "{s}.o", .{root_name}), }, .macho => switch (options.output_mode) { .Exe => return allocator.dupe(u8, root_name), @@ -163,7 +164,7 @@ pub fn binNameAlloc(allocator: *std.mem.Allocator, options: BinNameOptions) erro } return std.fmt.allocPrint(allocator, "{s}{s}{s}", .{ target.libPrefix(), root_name, suffix }); }, - .Obj => return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, target.oFileExt() }), + .Obj => return std.fmt.allocPrint(allocator, "{s}.o", .{root_name}), }, .wasm => switch (options.output_mode) { .Exe => return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, target.exeFileExt() }), @@ -175,36 +176,15 @@ pub fn binNameAlloc(allocator: *std.mem.Allocator, options: BinNameOptions) erro .Dynamic => return std.fmt.allocPrint(allocator, "{s}.wasm", .{root_name}), } }, - .Obj => return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, target.oFileExt() }), + .Obj => return std.fmt.allocPrint(allocator, "{s}.o", .{root_name}), }, .c => return std.fmt.allocPrint(allocator, "{s}.c", .{root_name}), .spirv => return std.fmt.allocPrint(allocator, "{s}.spv", .{root_name}), .hex => return std.fmt.allocPrint(allocator, "{s}.ihex", .{root_name}), .raw => return std.fmt.allocPrint(allocator, "{s}.bin", .{root_name}), - .plan9 => { - // copied from 2c(1) - // 0c spim little-endian MIPS 3000 family - // 1c 68000 Motorola MC68000 - // 2c 68020 Motorola MC68020 - // 5c arm little-endian ARM - // 6c amd64 AMD64 and compatibles (e.g., Intel EM64T) - // 7c arm64 ARM64 (ARMv8) - // 8c 386 Intel i386, i486, Pentium, etc. - // kc sparc Sun SPARC - // qc power Power PC - // vc mips big-endian MIPS 3000 family - const char: u8 = switch (target.cpu.arch) { - .arm => '5', - .x86_64 => '6', - .aarch64 => '7', - .i386 => '8', - .sparc => 'k', - .powerpc, .powerpcle => 'q', - .mips, .mipsel => 'v', - else => 'X', // this arch does not have a char or maybe was not ported to plan9 so we just use X - }; - return std.fmt.allocPrint(allocator, "{s}.{c}", .{ root_name, char }); - }, + .plan9 => return std.fmt.allocPrint(allocator, "{s}{s}", .{ + root_name, ofmt.fileExt(target.cpu.arch), + }), } } diff --git a/lib/std/zig/cross_target.zig b/lib/std/zig/cross_target.zig index e6ca0a2baa..1058628633 100644 --- a/lib/std/zig/cross_target.zig +++ b/lib/std/zig/cross_target.zig @@ -473,10 +473,6 @@ pub const CrossTarget = struct { return self.getOsTag() == .windows; } - pub fn oFileExt(self: CrossTarget) [:0]const u8 { - return Target.oFileExt_os_abi(self.getOsTag(), self.getAbi()); - } - pub fn exeFileExt(self: CrossTarget) [:0]const u8 { return Target.exeFileExtSimple(self.getCpuArch(), self.getOsTag()); } |
