authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2019-11-07 00:14:15+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2019-11-07 10:30:47+02:00
log9394d14815d1a3105f8ea9b3a1a73ea4bc834e7a
tree34c7fb129d27fba2195d8fe129afe9d962d9542e
parent6dd4a276de7ea7c283d1d1ef6361a718225022d3
signaturelock-open Commit is signed but in an unrecognized format.

self hosted compiler: unify Target and std.Target


8 files changed, 309 insertions(+), 439 deletions(-)

src-self-hosted/c_int.zig+102
......@@ -1,3 +1,5 @@
1const Target = @import("std").Target;
2
13pub const CInt = struct {
24 id: Id,
35 zig_name: []const u8,
......@@ -65,4 +67,104 @@ pub const CInt = struct {
6567 .is_signed = false,
6668 },
6769 };
70
71 pub fn sizeInBits(id: CInt.Id, self: Target) u32 {
72 const arch = self.getArch();
73 switch (self.getOs()) {
74 .freestanding => switch (self.getArch()) {
75 .msp430 => switch (id) {
76 .Short,
77 .UShort,
78 .Int,
79 .UInt,
80 => return 16,
81 .Long,
82 .ULong,
83 => return 32,
84 .LongLong,
85 .ULongLong,
86 => return 64,
87 },
88 else => switch (id) {
89 .Short,
90 .UShort,
91 => return 16,
92 .Int,
93 .UInt,
94 => return 32,
95 .Long,
96 .ULong,
97 => return self.getArchPtrBitWidth(),
98 .LongLong,
99 .ULongLong,
100 => return 64,
101 },
102 },
103
104 .linux,
105 .macosx,
106 .freebsd,
107 .openbsd,
108 .zen,
109 => switch (id) {
110 .Short,
111 .UShort,
112 => return 16,
113 .Int,
114 .UInt,
115 => return 32,
116 .Long,
117 .ULong,
118 => return self.getArchPtrBitWidth(),
119 .LongLong,
120 .ULongLong,
121 => return 64,
122 },
123
124 .windows, .uefi => switch (id) {
125 .Short,
126 .UShort,
127 => return 16,
128 .Int,
129 .UInt,
130 => return 32,
131 .Long,
132 .ULong,
133 .LongLong,
134 .ULongLong,
135 => return 64,
136 },
137
138 .ananas,
139 .cloudabi,
140 .dragonfly,
141 .fuchsia,
142 .ios,
143 .kfreebsd,
144 .lv2,
145 .netbsd,
146 .solaris,
147 .haiku,
148 .minix,
149 .rtems,
150 .nacl,
151 .cnk,
152 .aix,
153 .cuda,
154 .nvcl,
155 .amdhsa,
156 .ps4,
157 .elfiamcu,
158 .tvos,
159 .watchos,
160 .mesa3d,
161 .contiki,
162 .amdpal,
163 .hermit,
164 .hurd,
165 .wasi,
166 .emscripten,
167 => @panic("TODO specify the C integer type sizes for this OS"),
168 }
169 }
68170};
src-self-hosted/compilation.zig+5-5
......@@ -6,7 +6,7 @@ const Buffer = std.Buffer;
66const llvm = @import("llvm.zig");
77const c = @import("c.zig");
88const builtin = @import("builtin");
9const Target = @import("target.zig").Target;
9const Target = std.Target;
1010const warn = std.debug.warn;
1111const Token = std.zig.Token;
1212const ArrayList = std.ArrayList;
......@@ -48,7 +48,7 @@ pub const ZigCompiler = struct {
4848
4949 pub fn init(allocator: *Allocator) !ZigCompiler {
5050 lazy_init_targets.get() orelse {
51 Target.initializeAll();
51 llvm.initializeAllTargets();
5252 lazy_init_targets.resolve();
5353 };
5454
......@@ -476,8 +476,8 @@ pub const Compilation = struct {
476476 }
477477
478478 comp.name = try Buffer.init(comp.arena(), name);
479 comp.llvm_triple = try target.getTriple(comp.arena());
480 comp.llvm_target = try Target.llvmTargetFromTriple(comp.llvm_triple);
479 comp.llvm_triple = try llvm.getTriple(comp.arena(), target);
480 comp.llvm_target = try llvm.targetFromTriple(comp.llvm_triple);
481481 comp.zig_std_dir = try std.fs.path.join(comp.arena(), [_][]const u8{ zig_lib_dir, "std" });
482482
483483 const opt_level = switch (build_mode) {
......@@ -720,7 +720,7 @@ pub const Compilation = struct {
720720 },
721721 .key = Type.Int.Key{
722722 .is_signed = cint.is_signed,
723 .bit_count = comp.target.cIntTypeSizeInBits(cint.id),
723 .bit_count = cint.sizeInBits(comp.target),
724724 },
725725 .garbage_node = undefined,
726726 };
src-self-hosted/libc_installation.zig+3-2
......@@ -1,7 +1,8 @@
11const std = @import("std");
22const builtin = @import("builtin");
33const event = std.event;
4const Target = @import("target.zig").Target;
4const target = @import("target.zig");
5const Target = target.Target;
56const c = @import("c.zig");
67const fs = std.fs;
78const Allocator = std.mem.Allocator;
......@@ -137,7 +138,7 @@ pub const LibCInstallation = struct {
137138 self.static_lib_dir orelse "",
138139 self.msvc_lib_dir orelse "",
139140 self.kernel32_lib_dir orelse "",
140 self.dynamic_linker_path orelse Target(Target.Native).getDynamicLinkerPath(),
141 self.dynamic_linker_path orelse target.getDynamicLinkerPath(Target(Target.Native)),
141142 );
142143 }
143144
src-self-hosted/link.zig+1-1
......@@ -4,7 +4,7 @@ const c = @import("c.zig");
44const builtin = @import("builtin");
55const ObjectFormat = builtin.ObjectFormat;
66const Compilation = @import("compilation.zig").Compilation;
7const Target = @import("target.zig").Target;
7const Target = std.Target;
88const LibCInstallation = @import("libc_installation.zig").LibCInstallation;
99const assert = std.debug.assert;
1010
src-self-hosted/llvm.zig+42-1
......@@ -1,6 +1,7 @@
11const builtin = @import("builtin");
22const c = @import("c.zig");
3const assert = @import("std").debug.assert;
3const std = @import("std");
4const assert = std.debug.assert;
45
56// we wrap the c module for 3 reasons:
67// 1. to avoid accidentally calling the non-thread-safe functions
......@@ -290,3 +291,43 @@ pub const BuildCall = ZigLLVMBuildCall;
290291extern fn ZigLLVMBuildCall(B: *Builder, Fn: *Value, Args: [*]*Value, NumArgs: c_uint, CC: c_uint, fn_inline: FnInline, Name: [*]const u8) ?*Value;
291292
292293pub const PrivateLinkage = c.LLVMLinkage.LLVMPrivateLinkage;
294
295pub fn targetFromTriple(triple: std.Buffer) !*Target {
296 var result: *Target = undefined;
297 var err_msg: [*]u8 = undefined;
298 if (GetTargetFromTriple(triple.ptr(), &result, &err_msg) != 0) {
299 std.debug.warn("triple: {s} error: {s}\n", triple.ptr(), err_msg);
300 return error.UnsupportedTarget;
301 }
302 return result;
303}
304
305pub fn initializeAllTargets() void {
306 InitializeAllTargets();
307 InitializeAllTargetInfos();
308 InitializeAllTargetMCs();
309 InitializeAllAsmPrinters();
310 InitializeAllAsmParsers();
311}
312
313pub fn getTriple(allocator: *std.mem.Allocator, self: Target) !std.Buffer {
314 var result = try std.Buffer.initSize(allocator, 0);
315 errdefer result.deinit();
316
317 // LLVM WebAssembly output support requires the target to be activated at
318 // build type with -DCMAKE_LLVM_EXPIERMENTAL_TARGETS_TO_BUILD=WebAssembly.
319 //
320 // LLVM determines the output format based on the abi suffix,
321 // defaulting to an object based on the architecture. The default format in
322 // LLVM 6 sets the wasm arch output incorrectly to ELF. We need to
323 // explicitly set this ourself in order for it to work.
324 //
325 // This is fixed in LLVM 7 and you will be able to get wasm output by
326 // using the target triple `wasm32-unknown-unknown-unknown`.
327 const env_name = if (self.isWasm()) "wasm" else @tagName(self.getAbi());
328
329 var out = &std.io.BufferOutStream.init(&result).stream;
330 try out.print("{}-unknown-{}-{}", @tagName(self.getArch()), @tagName(self.getOs()), env_name);
331
332 return result;
333}
\ No newline at end of file
src-self-hosted/main.zig+1-1
......@@ -18,7 +18,7 @@ const Args = arg.Args;
1818const Flag = arg.Flag;
1919const ZigCompiler = @import("compilation.zig").ZigCompiler;
2020const Compilation = @import("compilation.zig").Compilation;
21const Target = @import("target.zig").Target;
21const Target = std.Target;
2222const errmsg = @import("errmsg.zig");
2323const LibCInstallation = @import("libc_installation.zig").LibCInstallation;
2424
src-self-hosted/target.zig+154-428
......@@ -1,9 +1,4 @@
1const std = @import("std");
2const builtin = @import("builtin");
3const llvm = @import("llvm.zig");
4const CInt = @import("c_int.zig").CInt;
5
6// TODO delete this file and use std.Target
1// const builtin = @import("builtin");
72
83pub const FloatAbi = enum {
94 Hard,
......@@ -11,430 +6,161 @@ pub const FloatAbi = enum {
116 SoftFp,
127};
138
14pub const Target = union(enum) {
15 Native,
16 Cross: Cross,
17
18 pub const Cross = struct {
19 arch: builtin.Arch,
20 os: builtin.Os,
21 abi: builtin.Abi,
22 object_format: builtin.ObjectFormat,
9// pub const Cross = struct {
10// arch: Target.Arch,
11// os: Target.Os,
12// abi: Target.Abi,
13// object_format: builtin.ObjectFormat,
14// };
15
16// pub fn getObjectFormat(self: Target) builtin.ObjectFormat {
17// return switch (self) {
18// .Native => builtin.object_format,
19// .Cross => |t| t.object_format,
20// };
21// }
22
23/// TODO expose the arch and subarch separately
24pub fn isArmOrThumb(self: Target) bool {
25 return switch (self.getArch()) {
26 .arm,
27 .armeb,
28 .aarch64,
29 .aarch64_be,
30 .thumb,
31 .thumbeb,
32 => true,
33 else => false,
2334 };
24
25 pub fn objFileExt(self: Target) []const u8 {
26 return switch (self.getObjectFormat()) {
27 builtin.ObjectFormat.coff => ".obj",
28 else => ".o",
29 };
30 }
31
32 pub fn exeFileExt(self: Target) []const u8 {
33 return switch (self.getOs()) {
34 builtin.Os.windows => ".exe",
35 else => "",
36 };
37 }
38
39 pub fn libFileExt(self: Target, is_static: bool) []const u8 {
40 return switch (self.getOs()) {
41 builtin.Os.windows => if (is_static) ".lib" else ".dll",
42 else => if (is_static) ".a" else ".so",
43 };
44 }
45
46 pub fn getOs(self: Target) builtin.Os {
47 return switch (self) {
48 Target.Native => builtin.os,
49 @TagType(Target).Cross => |t| t.os,
50 };
51 }
52
53 pub fn getArch(self: Target) builtin.Arch {
54 switch (self) {
55 Target.Native => return builtin.arch,
56 @TagType(Target).Cross => |t| return t.arch,
57 }
58 }
59
60 pub fn getAbi(self: Target) builtin.Abi {
61 return switch (self) {
62 Target.Native => builtin.abi,
63 @TagType(Target).Cross => |t| t.abi,
64 };
65 }
66
67 pub fn getObjectFormat(self: Target) builtin.ObjectFormat {
68 return switch (self) {
69 Target.Native => builtin.object_format,
70 @TagType(Target).Cross => |t| t.object_format,
71 };
72 }
73
74 pub fn isWasm(self: Target) bool {
75 return switch (self.getArch()) {
76 builtin.Arch.wasm32, builtin.Arch.wasm64 => true,
77 else => false,
78 };
79 }
80
81 pub fn isDarwin(self: Target) bool {
82 return switch (self.getOs()) {
83 builtin.Os.ios, builtin.Os.macosx => true,
84 else => false,
85 };
86 }
87
88 pub fn isWindows(self: Target) bool {
89 return switch (self.getOs()) {
90 builtin.Os.windows => true,
91 else => false,
92 };
93 }
94
95 /// TODO expose the arch and subarch separately
96 pub fn isArmOrThumb(self: Target) bool {
97 return switch (self.getArch()) {
98 builtin.Arch.arm,
99 builtin.Arch.armeb,
100 builtin.Arch.aarch64,
101 builtin.Arch.aarch64_be,
102 builtin.Arch.thumb,
103 builtin.Arch.thumbeb,
104 => true,
105 else => false,
106 };
107 }
108
109 pub fn initializeAll() void {
110 llvm.InitializeAllTargets();
111 llvm.InitializeAllTargetInfos();
112 llvm.InitializeAllTargetMCs();
113 llvm.InitializeAllAsmPrinters();
114 llvm.InitializeAllAsmParsers();
115 }
116
117 pub fn getTriple(self: Target, allocator: *std.mem.Allocator) !std.Buffer {
118 var result = try std.Buffer.initSize(allocator, 0);
119 errdefer result.deinit();
120
121 // LLVM WebAssembly output support requires the target to be activated at
122 // build type with -DCMAKE_LLVM_EXPIERMENTAL_TARGETS_TO_BUILD=WebAssembly.
123 //
124 // LLVM determines the output format based on the abi suffix,
125 // defaulting to an object based on the architecture. The default format in
126 // LLVM 6 sets the wasm arch output incorrectly to ELF. We need to
127 // explicitly set this ourself in order for it to work.
128 //
129 // This is fixed in LLVM 7 and you will be able to get wasm output by
130 // using the target triple `wasm32-unknown-unknown-unknown`.
131 const env_name = if (self.isWasm()) "wasm" else @tagName(self.getAbi());
132
133 var out = &std.io.BufferOutStream.init(&result).stream;
134 try out.print("{}-unknown-{}-{}", @tagName(self.getArch()), @tagName(self.getOs()), env_name);
135
136 return result;
137 }
138
139 pub fn is64bit(self: Target) bool {
140 return self.getArchPtrBitWidth() == 64;
141 }
142
143 pub fn getArchPtrBitWidth(self: Target) u32 {
144 switch (self.getArch()) {
145 builtin.Arch.avr,
146 builtin.Arch.msp430,
147 => return 16,
148
149 builtin.Arch.arc,
150 builtin.Arch.arm,
151 builtin.Arch.armeb,
152 builtin.Arch.hexagon,
153 builtin.Arch.le32,
154 builtin.Arch.mips,
155 builtin.Arch.mipsel,
156 builtin.Arch.powerpc,
157 builtin.Arch.r600,
158 builtin.Arch.riscv32,
159 builtin.Arch.sparc,
160 builtin.Arch.sparcel,
161 builtin.Arch.tce,
162 builtin.Arch.tcele,
163 builtin.Arch.thumb,
164 builtin.Arch.thumbeb,
165 builtin.Arch.i386,
166 builtin.Arch.xcore,
167 builtin.Arch.nvptx,
168 builtin.Arch.amdil,
169 builtin.Arch.hsail,
170 builtin.Arch.spir,
171 builtin.Arch.kalimba,
172 builtin.Arch.shave,
173 builtin.Arch.lanai,
174 builtin.Arch.wasm32,
175 builtin.Arch.renderscript32,
176 => return 32,
177
178 builtin.Arch.aarch64,
179 builtin.Arch.aarch64_be,
180 builtin.Arch.mips64,
181 builtin.Arch.mips64el,
182 builtin.Arch.powerpc64,
183 builtin.Arch.powerpc64le,
184 builtin.Arch.riscv64,
185 builtin.Arch.x86_64,
186 builtin.Arch.nvptx64,
187 builtin.Arch.le64,
188 builtin.Arch.amdil64,
189 builtin.Arch.hsail64,
190 builtin.Arch.spir64,
191 builtin.Arch.wasm64,
192 builtin.Arch.renderscript64,
193 builtin.Arch.amdgcn,
194 builtin.Arch.bpfel,
195 builtin.Arch.bpfeb,
196 builtin.Arch.sparcv9,
197 builtin.Arch.s390x,
198 => return 64,
199 }
200 }
201
202 pub fn getFloatAbi(self: Target) FloatAbi {
203 return switch (self.getAbi()) {
204 builtin.Abi.gnueabihf,
205 builtin.Abi.eabihf,
206 builtin.Abi.musleabihf,
207 => FloatAbi.Hard,
208 else => FloatAbi.Soft,
209 };
210 }
211
212 pub fn getDynamicLinkerPath(self: Target) ?[]const u8 {
213 const env = self.getAbi();
214 const arch = self.getArch();
215 const os = self.getOs();
216 switch (os) {
217 builtin.Os.freebsd => {
218 return "/libexec/ld-elf.so.1";
219 },
220 builtin.Os.linux => {
221 switch (env) {
222 builtin.Abi.android => {
223 if (self.is64bit()) {
224 return "/system/bin/linker64";
225 } else {
226 return "/system/bin/linker";
227 }
228 },
229 builtin.Abi.gnux32 => {
230 if (arch == builtin.Arch.x86_64) {
231 return "/libx32/ld-linux-x32.so.2";
232 }
233 },
234 builtin.Abi.musl,
235 builtin.Abi.musleabi,
236 builtin.Abi.musleabihf,
237 => {
238 if (arch == builtin.Arch.x86_64) {
239 return "/lib/ld-musl-x86_64.so.1";
240 }
241 },
242 else => {},
243 }
244 switch (arch) {
245 builtin.Arch.i386,
246 builtin.Arch.sparc,
247 builtin.Arch.sparcel,
248 => return "/lib/ld-linux.so.2",
249
250 builtin.Arch.aarch64 => return "/lib/ld-linux-aarch64.so.1",
251
252 builtin.Arch.aarch64_be => return "/lib/ld-linux-aarch64_be.so.1",
253
254 builtin.Arch.arm,
255 builtin.Arch.thumb,
256 => return switch (self.getFloatAbi()) {
257 FloatAbi.Hard => return "/lib/ld-linux-armhf.so.3",
258 else => return "/lib/ld-linux.so.3",
259 },
260
261 builtin.Arch.armeb,
262 builtin.Arch.thumbeb,
263 => return switch (self.getFloatAbi()) {
264 FloatAbi.Hard => return "/lib/ld-linux-armhf.so.3",
265 else => return "/lib/ld-linux.so.3",
266 },
267
268 builtin.Arch.mips,
269 builtin.Arch.mipsel,
270 builtin.Arch.mips64,
271 builtin.Arch.mips64el,
272 => return null,
273
274 builtin.Arch.powerpc => return "/lib/ld.so.1",
275 builtin.Arch.powerpc64 => return "/lib64/ld64.so.2",
276 builtin.Arch.powerpc64le => return "/lib64/ld64.so.2",
277 builtin.Arch.s390x => return "/lib64/ld64.so.1",
278 builtin.Arch.sparcv9 => return "/lib64/ld-linux.so.2",
279 builtin.Arch.x86_64 => return "/lib64/ld-linux-x86-64.so.2",
280
281 builtin.Arch.arc,
282 builtin.Arch.avr,
283 builtin.Arch.bpfel,
284 builtin.Arch.bpfeb,
285 builtin.Arch.hexagon,
286 builtin.Arch.msp430,
287 builtin.Arch.r600,
288 builtin.Arch.amdgcn,
289 builtin.Arch.riscv32,
290 builtin.Arch.riscv64,
291 builtin.Arch.tce,
292 builtin.Arch.tcele,
293 builtin.Arch.xcore,
294 builtin.Arch.nvptx,
295 builtin.Arch.nvptx64,
296 builtin.Arch.le32,
297 builtin.Arch.le64,
298 builtin.Arch.amdil,
299 builtin.Arch.amdil64,
300 builtin.Arch.hsail,
301 builtin.Arch.hsail64,
302 builtin.Arch.spir,
303 builtin.Arch.spir64,
304 builtin.Arch.kalimba,
305 builtin.Arch.shave,
306 builtin.Arch.lanai,
307 builtin.Arch.wasm32,
308 builtin.Arch.wasm64,
309 builtin.Arch.renderscript32,
310 builtin.Arch.renderscript64,
311 => return null,
312 }
313 },
314 else => return null,
315 }
316 }
317
318 pub fn llvmTargetFromTriple(triple: std.Buffer) !*llvm.Target {
319 var result: *llvm.Target = undefined;
320 var err_msg: [*]u8 = undefined;
321 if (llvm.GetTargetFromTriple(triple.ptr(), &result, &err_msg) != 0) {
322 std.debug.warn("triple: {s} error: {s}\n", triple.ptr(), err_msg);
323 return error.UnsupportedTarget;
324 }
325 return result;
326 }
327
328 pub fn cIntTypeSizeInBits(self: Target, id: CInt.Id) u32 {
329 const arch = self.getArch();
330 switch (self.getOs()) {
331 builtin.Os.freestanding => switch (self.getArch()) {
332 builtin.Arch.msp430 => switch (id) {
333 CInt.Id.Short,
334 CInt.Id.UShort,
335 CInt.Id.Int,
336 CInt.Id.UInt,
337 => return 16,
338 CInt.Id.Long,
339 CInt.Id.ULong,
340 => return 32,
341 CInt.Id.LongLong,
342 CInt.Id.ULongLong,
343 => return 64,
35}
36
37pub fn getFloatAbi(self: Target) FloatAbi {
38 return switch (self.getAbi()) {
39 .gnueabihf,
40 .eabihf,
41 .musleabihf,
42 => .Hard,
43 else => .Soft,
44 };
45}
46
47pub fn getDynamicLinkerPath(self: Target) ?[]const u8 {
48 const env = self.getAbi();
49 const arch = self.getArch();
50 const os = self.getOs();
51 switch (os) {
52 .freebsd => {
53 return "/libexec/ld-elf.so.1";
54 },
55 .linux => {
56 switch (env) {
57 .android => {
58 if (is64bit(self)) {
59 return "/system/bin/linker64";
60 } else {
61 return "/system/bin/linker";
62 }
34463 },
345 else => switch (id) {
346 CInt.Id.Short,
347 CInt.Id.UShort,
348 => return 16,
349 CInt.Id.Int,
350 CInt.Id.UInt,
351 => return 32,
352 CInt.Id.Long,
353 CInt.Id.ULong,
354 => return self.getArchPtrBitWidth(),
355 CInt.Id.LongLong,
356 CInt.Id.ULongLong,
357 => return 64,
64 .gnux32 => {
65 if (arch == .x86_64) {
66 return "/libx32/ld-linux-x32.so.2";
67 }
68 },
69 .musl,
70 .musleabi,
71 .musleabihf,
72 => {
73 if (arch == .x86_64) {
74 return "/lib/ld-musl-x86_64.so.1";
75 }
76 },
77 else => {},
78 }
79 switch (arch) {
80 .i386,
81 .sparc,
82 .sparcel,
83 => return "/lib/ld-linux.so.2",
84
85 .aarch64 => return "/lib/ld-linux-aarch64.so.1",
86
87 .aarch64_be => return "/lib/ld-linux-aarch64_be.so.1",
88
89 .arm,
90 .thumb,
91 => return switch (getFloatAbi(self)) {
92 .Hard => return "/lib/ld-linux-armhf.so.3",
93 else => return "/lib/ld-linux.so.3",
35894 },
359 },
360
361 builtin.Os.linux,
362 builtin.Os.macosx,
363 builtin.Os.freebsd,
364 builtin.Os.openbsd,
365 builtin.Os.zen,
366 => switch (id) {
367 CInt.Id.Short,
368 CInt.Id.UShort,
369 => return 16,
370 CInt.Id.Int,
371 CInt.Id.UInt,
372 => return 32,
373 CInt.Id.Long,
374 CInt.Id.ULong,
375 => return self.getArchPtrBitWidth(),
376 CInt.Id.LongLong,
377 CInt.Id.ULongLong,
378 => return 64,
379 },
380
381 builtin.Os.windows, builtin.Os.uefi => switch (id) {
382 CInt.Id.Short,
383 CInt.Id.UShort,
384 => return 16,
385 CInt.Id.Int,
386 CInt.Id.UInt,
387 => return 32,
388 CInt.Id.Long,
389 CInt.Id.ULong,
390 CInt.Id.LongLong,
391 CInt.Id.ULongLong,
392 => return 64,
393 },
39495
395 builtin.Os.ananas,
396 builtin.Os.cloudabi,
397 builtin.Os.dragonfly,
398 builtin.Os.fuchsia,
399 builtin.Os.ios,
400 builtin.Os.kfreebsd,
401 builtin.Os.lv2,
402 builtin.Os.netbsd,
403 builtin.Os.solaris,
404 builtin.Os.haiku,
405 builtin.Os.minix,
406 builtin.Os.rtems,
407 builtin.Os.nacl,
408 builtin.Os.cnk,
409 builtin.Os.aix,
410 builtin.Os.cuda,
411 builtin.Os.nvcl,
412 builtin.Os.amdhsa,
413 builtin.Os.ps4,
414 builtin.Os.elfiamcu,
415 builtin.Os.tvos,
416 builtin.Os.watchos,
417 builtin.Os.mesa3d,
418 builtin.Os.contiki,
419 builtin.Os.amdpal,
420 builtin.Os.hermit,
421 builtin.Os.hurd,
422 builtin.Os.wasi,
423 => @panic("TODO specify the C integer type sizes for this OS"),
424 }
425 }
96 .armeb,
97 .thumbeb,
98 => return switch (getFloatAbi(self)) {
99 .Hard => return "/lib/ld-linux-armhf.so.3",
100 else => return "/lib/ld-linux.so.3",
101 },
426102
427 pub fn getDarwinArchString(self: Target) []const u8 {
428 const arch = self.getArch();
429 switch (arch) {
430 builtin.Arch.aarch64 => return "arm64",
431 builtin.Arch.thumb,
432 builtin.Arch.arm,
433 => return "arm",
434 builtin.Arch.powerpc => return "ppc",
435 builtin.Arch.powerpc64 => return "ppc64",
436 builtin.Arch.powerpc64le => return "ppc64le",
437 else => return @tagName(arch),
438 }
439 }
440};
103 .mips,
104 .mipsel,
105 .mips64,
106 .mips64el,
107 => return null,
108
109 .powerpc => return "/lib/ld.so.1",
110 .powerpc64 => return "/lib64/ld64.so.2",
111 .powerpc64le => return "/lib64/ld64.so.2",
112 .s390x => return "/lib64/ld64.so.1",
113 .sparcv9 => return "/lib64/ld-linux.so.2",
114 .x86_64 => return "/lib64/ld-linux-x86-64.so.2",
115
116 .arc,
117 .avr,
118 .bpfel,
119 .bpfeb,
120 .hexagon,
121 .msp430,
122 .r600,
123 .amdgcn,
124 .riscv32,
125 .riscv64,
126 .tce,
127 .tcele,
128 .xcore,
129 .nvptx,
130 .nvptx64,
131 .le32,
132 .le64,
133 .amdil,
134 .amdil64,
135 .hsail,
136 .hsail64,
137 .spir,
138 .spir64,
139 .kalimba,
140 .shave,
141 .lanai,
142 .wasm32,
143 .wasm64,
144 .renderscript32,
145 .renderscript64,
146 .aarch64_32,
147 => return null,
148 }
149 },
150 else => return null,
151 }
152}
153
154pub fn getDarwinArchString(self: Target) []const u8 {
155 const arch = self.getArch();
156 switch (arch) {
157 .aarch64 => return "arm64",
158 .thumb,
159 .arm,
160 => return "arm",
161 .powerpc => return "ppc",
162 .powerpc64 => return "ppc64",
163 .powerpc64le => return "ppc64le",
164 else => return @tagName(arch),
165 }
166}
src-self-hosted/test.zig+1-1
......@@ -1,7 +1,7 @@
11const std = @import("std");
22const mem = std.mem;
33const builtin = @import("builtin");
4const Target = @import("target.zig").Target;
4const Target = std.Target;
55const Compilation = @import("compilation.zig").Compilation;
66const introspect = @import("introspect.zig");
77const testing = std.testing;