authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-02-26 15:51:32-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-02-26 15:58:10-05:00
logade10387a583351fe597b58c4c9ceb97d959adf5
tree5e508bc243ec6e65c1d2a11908d7e28bcf0b8c48
parent1ec1097bd389b9af1b3e40d9edbc4c1c0b65f6a1
signaturelock-open Commit is signed but in an unrecognized format.

breaking changes to the way targets work in zig

* CLI: `-target [name]` instead of `--target-*` args. This matches clang's API. * `builtin.Environ` renamed to `builtin.Abi` - likewise `builtin.environ` renamed to `builtin.abi` * stop hiding the concept of sub-arch. closes #1526 * `zig targets` only shows available targets. closes #438 * include all targets in readme, even those that don't print with `zig targets` but note they are Tier 4 * refactor target.cpp and make the naming conventions more consistent * introduce the concept of a "default C ABI" for a given OS/Arch combo. As a rule of thumb, if the system compiler is clang or gcc then the default C ABI is the gnu ABI.

25 files changed, 874 insertions(+), 739 deletions(-)

README.md+36-21
...@@ -77,39 +77,54 @@ clarity....@@ -77,39 +77,54 @@ clarity.
77 - what sizes are the C integer types77 - what sizes are the C integer types
78 - C ABI calling convention for this target78 - C ABI calling convention for this target
79 - bootstrap code and default panic handler79 - bootstrap code and default panic handler
80 * `zig targets` is guaranteed to include this target.
8081
81#### Tier 4 Support82#### Tier 4 Support
8283
83 * Support for these targets is entirely experimental.84 * Support for these targets is entirely experimental.
84 * LLVM may have the target as an experimental target, which means that you85 * LLVM may have the target as an experimental target, which means that you
85 need to use Zig-provided binaries for the target to be available, or86 need to use Zig-provided binaries for the target to be available, or
86 build LLVM from source with special configure flags.87 build LLVM from source with special configure flags. `zig targets` will
88 display the target if it is available.
87 * This target may be considered deprecated by an official party,89 * This target may be considered deprecated by an official party,
88 [such as macosx/i386](https://support.apple.com/en-us/HT208436) in which90 [such as macosx/i386](https://support.apple.com/en-us/HT208436) in which
89 case this target will remain forever stuck in Tier 4.91 case this target will remain forever stuck in Tier 4.
92 * This target may only support `--emit asm` and cannot emit object files.
9093
91#### Support Table94#### Support Table
9295
93| | freestanding | linux | macosx | windows | freebsd | netbsd | UEFI | other |96| | freestanding | linux | macosx | windows | freebsd | netbsd | UEFI | other |
94|--------|--------------|--------|--------|---------|---------|------- | -------|--------|97|-------------|--------------|--------|--------|---------|---------|------- | -------|--------|
95|x86_64 | Tier 2 | Tier 1 | Tier 1 | Tier 1 | Tier 2 | Tier 2 | Tier 2 | Tier 3 |98|x86_64 | Tier 2 | Tier 1 | Tier 1 | Tier 1 | Tier 2 | Tier 2 | Tier 2 | Tier 3 |
96|i386 | Tier 2 | Tier 2 | Tier 4 | Tier 2 | Tier 3 | Tier 3 | Tier 3 | Tier 3 |99|i386 | Tier 2 | Tier 2 | Tier 4 | Tier 2 | Tier 3 | Tier 3 | Tier 3 | Tier 3 |
97|arm | Tier 2 | Tier 3 | Tier 3 | Tier 3 | Tier 3 | Tier 3 | Tier 3 | Tier 3 |100|arm | Tier 2 | Tier 3 | Tier 3 | Tier 3 | Tier 3 | Tier 3 | Tier 3 | Tier 3 |
98|arm64 | Tier 2 | Tier 2 | Tier 3 | Tier 3 | Tier 3 | Tier 3 | Tier 3 | Tier 3 |101|arm64 | Tier 2 | Tier 2 | Tier 3 | Tier 3 | Tier 3 | Tier 3 | Tier 3 | Tier 3 |
99|bpf | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 | Tier 3 | Tier 3 |102|avr | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 | N/A | Tier 3 |
100|hexagon | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 | Tier 3 | Tier 3 |103|bpf | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 | N/A | Tier 3 |
101|mips | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 | Tier 3 | Tier 3 |104|hexagon | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 | N/A | Tier 3 |
102|powerpc | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 | Tier 3 | Tier 3 |105|mips | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 | N/A | Tier 3 |
103|r600 | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 | Tier 3 | Tier 3 |106|powerpc | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 | N/A | Tier 3 |
104|amdgcn | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 | Tier 3 | Tier 3 |107|amdgcn | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 | N/A | Tier 3 |
105|sparc | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 | Tier 3 | Tier 3 |108|sparc | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 | N/A | Tier 3 |
106|s390x | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 | Tier 3 | Tier 3 |109|s390x | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 | N/A | Tier 3 |
107|spir | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 | Tier 3 | Tier 3 |110|lanai | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 | N/A | Tier 3 |
108|lanai | Tier 3 | Tier 3 | N/A | N/A | Tier 3 | Tier 3 | Tier 3 | Tier 3 |111|wasm32 | Tier 4 | N/A | N/A | N/A | N/A | N/A | N/A | N/A |
109|wasm32 | Tier 4 | N/A | N/A | N/A | N/A | N/A | N/A | N/A |112|wasm64 | Tier 4 | N/A | N/A | N/A | N/A | N/A | N/A | N/A |
110|wasm64 | Tier 4 | N/A | N/A | N/A | N/A | N/A | N/A | N/A |113|riscv32 | Tier 4 | Tier 4 | N/A | N/A | Tier 4 | Tier 4 | Tier 4 | Tier 4 |
111|riscv32 | Tier 4 | Tier 4 | N/A | N/A | Tier 4 | Tier 4 | Tier 4 | Tier 4 |114|riscv64 | Tier 4 | Tier 4 | N/A | N/A | Tier 4 | Tier 4 | Tier 4 | Tier 4 |
112|riscv64 | Tier 4 | Tier 4 | N/A | N/A | Tier 4 | Tier 4 | Tier 4 | Tier 4 |115|xcore | Tier 4 | Tier 4 | N/A | N/A | Tier 4 | Tier 4 | N/A | Tier 4 |
116|nvptx | Tier 4 | Tier 4 | N/A | N/A | Tier 4 | Tier 4 | N/A | Tier 4 |
117|msp430 | Tier 4 | Tier 4 | N/A | N/A | Tier 4 | Tier 4 | N/A | Tier 4 |
118|r600 | Tier 4 | Tier 4 | N/A | N/A | Tier 4 | Tier 4 | N/A | Tier 4 |
119|arc | Tier 4 | Tier 4 | N/A | N/A | Tier 4 | Tier 4 | N/A | Tier 4 |
120|tce | Tier 4 | Tier 4 | N/A | N/A | Tier 4 | Tier 4 | N/A | Tier 4 |
121|le | Tier 4 | Tier 4 | N/A | N/A | Tier 4 | Tier 4 | N/A | Tier 4 |
122|amdil | Tier 4 | Tier 4 | N/A | N/A | Tier 4 | Tier 4 | N/A | Tier 4 |
123|hsail | Tier 4 | Tier 4 | N/A | N/A | Tier 4 | Tier 4 | N/A | Tier 4 |
124|spir | Tier 4 | Tier 4 | N/A | N/A | Tier 4 | Tier 4 | N/A | Tier 4 |
125|kalimba | Tier 4 | Tier 4 | N/A | N/A | Tier 4 | Tier 4 | N/A | Tier 4 |
126|shave | Tier 4 | Tier 4 | N/A | N/A | Tier 4 | Tier 4 | N/A | Tier 4 |
127|renderscript | Tier 4 | Tier 4 | N/A | N/A | Tier 4 | Tier 4 | N/A | Tier 4 |
113128
114## Community129## Community
115130
doc/docgen.zig+1-8
...@@ -1105,14 +1105,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1105,14 +1105,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1105 },1105 },
1106 }1106 }
1107 if (code.target_windows) {1107 if (code.target_windows) {
1108 try test_args.appendSlice([][]const u8{1108 try test_args.appendSlice([][]const u8{ "-target", "x86_64-windows" });
1109 "--target-os",
1110 "windows",
1111 "--target-arch",
1112 "x86_64",
1113 "--target-environ",
1114 "msvc",
1115 });
1116 }1109 }
1117 const result = exec(allocator, &env_map, test_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "test failed");1110 const result = exec(allocator, &env_map, test_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "test failed");
1118 const escaped_stderr = try escapeHtml(allocator, result.stderr);1111 const escaped_stderr = try escapeHtml(allocator, result.stderr);
src-self-hosted/link.zig+2-2
...@@ -326,7 +326,7 @@ fn constructLinkerArgsCoff(ctx: *Context) !void {...@@ -326,7 +326,7 @@ fn constructLinkerArgsCoff(ctx: *Context) !void {
326 switch (ctx.comp.target.getArch()) {326 switch (ctx.comp.target.getArch()) {
327 builtin.Arch.i386 => try ctx.args.append(c"-MACHINE:X86"),327 builtin.Arch.i386 => try ctx.args.append(c"-MACHINE:X86"),
328 builtin.Arch.x86_64 => try ctx.args.append(c"-MACHINE:X64"),328 builtin.Arch.x86_64 => try ctx.args.append(c"-MACHINE:X64"),
329 builtin.Arch.aarch64v8 => try ctx.args.append(c"-MACHINE:ARM"),329 builtin.Arch.aarch64 => try ctx.args.append(c"-MACHINE:ARM"),
330 else => return error.UnsupportedLinkArchitecture,330 else => return error.UnsupportedLinkArchitecture,
331 }331 }
332332
...@@ -552,7 +552,7 @@ fn constructLinkerArgsMachO(ctx: *Context) !void {...@@ -552,7 +552,7 @@ fn constructLinkerArgsMachO(ctx: *Context) !void {
552 }552 }
553 },553 },
554 DarwinPlatform.Kind.IPhoneOS => {554 DarwinPlatform.Kind.IPhoneOS => {
555 if (ctx.comp.target.getArch() == builtin.Arch.aarch64v8) {555 if (ctx.comp.target.getArch() == builtin.Arch.aarch64) {
556 // iOS does not need any crt1 files for arm64556 // iOS does not need any crt1 files for arm64
557 } else if (platform.versionLessThan(3, 1)) {557 } else if (platform.versionLessThan(3, 1)) {
558 try ctx.args.append(c"-lcrt1.o");558 try ctx.args.append(c"-lcrt1.o");
src-self-hosted/main.zig+7-11
...@@ -154,9 +154,7 @@ const usage_build_generic =...@@ -154,9 +154,7 @@ const usage_build_generic =
154 \\ release-small optimize for small binary, safety off154 \\ release-small optimize for small binary, safety off
155 \\ --static Output will be statically linked155 \\ --static Output will be statically linked
156 \\ --strip Exclude debug symbols156 \\ --strip Exclude debug symbols
157 \\ --target-arch [name] Specify target architecture157 \\ -target [name] <arch><sub>-<os>-<abi> see the targets command
158 \\ --target-environ [name] Specify target environment
159 \\ --target-os [name] Specify target operating system
160 \\ --verbose-tokenize Turn on compiler debug output for tokenization158 \\ --verbose-tokenize Turn on compiler debug output for tokenization
161 \\ --verbose-ast-tree Turn on compiler debug output for parsing into an AST (tree view)159 \\ --verbose-ast-tree Turn on compiler debug output for parsing into an AST (tree view)
162 \\ --verbose-ast-fmt Turn on compiler debug output for parsing into an AST (render source)160 \\ --verbose-ast-fmt Turn on compiler debug output for parsing into an AST (render source)
...@@ -220,9 +218,7 @@ const args_build_generic = []Flag{...@@ -220,9 +218,7 @@ const args_build_generic = []Flag{
220 Flag.Bool("--pkg-end"),218 Flag.Bool("--pkg-end"),
221 Flag.Bool("--static"),219 Flag.Bool("--static"),
222 Flag.Bool("--strip"),220 Flag.Bool("--strip"),
223 Flag.Arg1("--target-arch"),221 Flag.Arg1("-target"),
224 Flag.Arg1("--target-environ"),
225 Flag.Arg1("--target-os"),
226 Flag.Bool("--verbose-tokenize"),222 Flag.Bool("--verbose-tokenize"),
227 Flag.Bool("--verbose-ast-tree"),223 Flag.Bool("--verbose-ast-tree"),
228 Flag.Bool("--verbose-ast-fmt"),224 Flag.Bool("--verbose-ast-fmt"),
...@@ -839,15 +835,15 @@ fn cmdTargets(allocator: *Allocator, args: []const []const u8) !void {...@@ -839,15 +835,15 @@ fn cmdTargets(allocator: *Allocator, args: []const []const u8) !void {
839 }835 }
840 try stdout.write("\n");836 try stdout.write("\n");
841837
842 try stdout.write("Environments:\n");838 try stdout.write("C ABIs:\n");
843 {839 {
844 comptime var i: usize = 0;840 comptime var i: usize = 0;
845 inline while (i < @memberCount(builtin.Environ)) : (i += 1) {841 inline while (i < @memberCount(builtin.Abi)) : (i += 1) {
846 comptime const environ_tag = @memberName(builtin.Environ, i);842 comptime const abi_tag = @memberName(builtin.Abi, i);
847 // NOTE: Cannot use empty string, see #918.843 // NOTE: Cannot use empty string, see #918.
848 comptime const native_str = if (comptime mem.eql(u8, environ_tag, @tagName(builtin.environ))) " (native)\n" else "\n";844 comptime const native_str = if (comptime mem.eql(u8, abi_tag, @tagName(builtin.abi))) " (native)\n" else "\n";
849845
850 try stdout.print(" {}{}", environ_tag, native_str);846 try stdout.print(" {}{}", abi_tag, native_str);
851 }847 }
852 }848 }
853}849}
src-self-hosted/target.zig+38-206
...@@ -16,7 +16,7 @@ pub const Target = union(enum) {...@@ -16,7 +16,7 @@ pub const Target = union(enum) {
16 pub const Cross = struct {16 pub const Cross = struct {
17 arch: builtin.Arch,17 arch: builtin.Arch,
18 os: builtin.Os,18 os: builtin.Os,
19 environ: builtin.Environ,19 abi: builtin.Abi,
20 object_format: builtin.ObjectFormat,20 object_format: builtin.ObjectFormat,
21 };21 };
2222
...@@ -49,16 +49,16 @@ pub const Target = union(enum) {...@@ -49,16 +49,16 @@ pub const Target = union(enum) {
49 }49 }
5050
51 pub fn getArch(self: Target) builtin.Arch {51 pub fn getArch(self: Target) builtin.Arch {
52 return switch (self) {52 switch (self) {
53 Target.Native => builtin.arch,53 Target.Native => return builtin.arch,
54 @TagType(Target).Cross => |t| t.arch,54 @TagType(Target).Cross => |t| return t.arch,
55 };55 }
56 }56 }
5757
58 pub fn getEnviron(self: Target) builtin.Environ {58 pub fn getAbi(self: Target) builtin.Abi {
59 return switch (self) {59 return switch (self) {
60 Target.Native => builtin.environ,60 Target.Native => builtin.abi,
61 @TagType(Target).Cross => |t| t.environ,61 @TagType(Target).Cross => |t| t.abi,
62 };62 };
63 }63 }
6464
...@@ -93,46 +93,10 @@ pub const Target = union(enum) {...@@ -93,46 +93,10 @@ pub const Target = union(enum) {
93 /// TODO expose the arch and subarch separately93 /// TODO expose the arch and subarch separately
94 pub fn isArmOrThumb(self: Target) bool {94 pub fn isArmOrThumb(self: Target) bool {
95 return switch (self.getArch()) {95 return switch (self.getArch()) {
96 builtin.Arch.armv8_3a,96 builtin.Arch.arm,
97 builtin.Arch.armv8_2a,97 builtin.Arch.armeb,
98 builtin.Arch.armv8_1a,98 builtin.Arch.aarch64,
99 builtin.Arch.armv8,99 builtin.Arch.aarch64_be,
100 builtin.Arch.armv8r,
101 builtin.Arch.armv8m_baseline,
102 builtin.Arch.armv8m_mainline,
103 builtin.Arch.armv7,
104 builtin.Arch.armv7em,
105 builtin.Arch.armv7m,
106 builtin.Arch.armv7s,
107 builtin.Arch.armv7k,
108 builtin.Arch.armv7ve,
109 builtin.Arch.armv6,
110 builtin.Arch.armv6m,
111 builtin.Arch.armv6k,
112 builtin.Arch.armv6t2,
113 builtin.Arch.armv5,
114 builtin.Arch.armv5te,
115 builtin.Arch.armv4t,
116 builtin.Arch.armebv8_3a,
117 builtin.Arch.armebv8_2a,
118 builtin.Arch.armebv8_1a,
119 builtin.Arch.armebv8,
120 builtin.Arch.armebv8r,
121 builtin.Arch.armebv8m_baseline,
122 builtin.Arch.armebv8m_mainline,
123 builtin.Arch.armebv7,
124 builtin.Arch.armebv7em,
125 builtin.Arch.armebv7m,
126 builtin.Arch.armebv7s,
127 builtin.Arch.armebv7k,
128 builtin.Arch.armebv7ve,
129 builtin.Arch.armebv6,
130 builtin.Arch.armebv6m,
131 builtin.Arch.armebv6k,
132 builtin.Arch.armebv6t2,
133 builtin.Arch.armebv5,
134 builtin.Arch.armebv5te,
135 builtin.Arch.armebv4t,
136 builtin.Arch.thumb,100 builtin.Arch.thumb,
137 builtin.Arch.thumbeb,101 builtin.Arch.thumbeb,
138 => true,102 => true,
...@@ -155,14 +119,14 @@ pub const Target = union(enum) {...@@ -155,14 +119,14 @@ pub const Target = union(enum) {
155 // LLVM WebAssembly output support requires the target to be activated at119 // LLVM WebAssembly output support requires the target to be activated at
156 // build type with -DCMAKE_LLVM_EXPIERMENTAL_TARGETS_TO_BUILD=WebAssembly.120 // build type with -DCMAKE_LLVM_EXPIERMENTAL_TARGETS_TO_BUILD=WebAssembly.
157 //121 //
158 // LLVM determines the output format based on the environment suffix,122 // LLVM determines the output format based on the abi suffix,
159 // defaulting to an object based on the architecture. The default format in123 // defaulting to an object based on the architecture. The default format in
160 // LLVM 6 sets the wasm arch output incorrectly to ELF. We need to124 // LLVM 6 sets the wasm arch output incorrectly to ELF. We need to
161 // explicitly set this ourself in order for it to work.125 // explicitly set this ourself in order for it to work.
162 //126 //
163 // This is fixed in LLVM 7 and you will be able to get wasm output by127 // This is fixed in LLVM 7 and you will be able to get wasm output by
164 // using the target triple `wasm32-unknown-unknown-unknown`.128 // using the target triple `wasm32-unknown-unknown-unknown`.
165 const env_name = if (self.isWasm()) "wasm" else @tagName(self.getEnviron());129 const env_name = if (self.isWasm()) "wasm" else @tagName(self.getAbi());
166130
167 var out = &std.io.BufferOutStream.init(&result).stream;131 var out = &std.io.BufferOutStream.init(&result).stream;
168 try out.print("{}-unknown-{}-{}", @tagName(self.getArch()), @tagName(self.getOs()), env_name);132 try out.print("{}-unknown-{}-{}", @tagName(self.getArch()), @tagName(self.getOs()), env_name);
...@@ -181,46 +145,8 @@ pub const Target = union(enum) {...@@ -181,46 +145,8 @@ pub const Target = union(enum) {
181 => return 16,145 => return 16,
182146
183 builtin.Arch.arc,147 builtin.Arch.arc,
184 builtin.Arch.armv8_3a,148 builtin.Arch.arm,
185 builtin.Arch.armv8_2a,149 builtin.Arch.armeb,
186 builtin.Arch.armv8_1a,
187 builtin.Arch.armv8,
188 builtin.Arch.armv8r,
189 builtin.Arch.armv8m_baseline,
190 builtin.Arch.armv8m_mainline,
191 builtin.Arch.armv7,
192 builtin.Arch.armv7em,
193 builtin.Arch.armv7m,
194 builtin.Arch.armv7s,
195 builtin.Arch.armv7k,
196 builtin.Arch.armv7ve,
197 builtin.Arch.armv6,
198 builtin.Arch.armv6m,
199 builtin.Arch.armv6k,
200 builtin.Arch.armv6t2,
201 builtin.Arch.armv5,
202 builtin.Arch.armv5te,
203 builtin.Arch.armv4t,
204 builtin.Arch.armebv8_3a,
205 builtin.Arch.armebv8_2a,
206 builtin.Arch.armebv8_1a,
207 builtin.Arch.armebv8,
208 builtin.Arch.armebv8r,
209 builtin.Arch.armebv8m_baseline,
210 builtin.Arch.armebv8m_mainline,
211 builtin.Arch.armebv7,
212 builtin.Arch.armebv7em,
213 builtin.Arch.armebv7m,
214 builtin.Arch.armebv7s,
215 builtin.Arch.armebv7k,
216 builtin.Arch.armebv7ve,
217 builtin.Arch.armebv6,
218 builtin.Arch.armebv6m,
219 builtin.Arch.armebv6k,
220 builtin.Arch.armebv6t2,
221 builtin.Arch.armebv5,
222 builtin.Arch.armebv5te,
223 builtin.Arch.armebv4t,
224 builtin.Arch.hexagon,150 builtin.Arch.hexagon,
225 builtin.Arch.le32,151 builtin.Arch.le32,
226 builtin.Arch.mips,152 builtin.Arch.mips,
...@@ -241,29 +167,15 @@ pub const Target = union(enum) {...@@ -241,29 +167,15 @@ pub const Target = union(enum) {
241 builtin.Arch.amdil,167 builtin.Arch.amdil,
242 builtin.Arch.hsail,168 builtin.Arch.hsail,
243 builtin.Arch.spir,169 builtin.Arch.spir,
244 builtin.Arch.kalimbav3,170 builtin.Arch.kalimba,
245 builtin.Arch.kalimbav4,
246 builtin.Arch.kalimbav5,
247 builtin.Arch.shave,171 builtin.Arch.shave,
248 builtin.Arch.lanai,172 builtin.Arch.lanai,
249 builtin.Arch.wasm32,173 builtin.Arch.wasm32,
250 builtin.Arch.renderscript32,174 builtin.Arch.renderscript32,
251 => return 32,175 => return 32,
252176
253 builtin.Arch.aarch64v8_3a,177 builtin.Arch.aarch64,
254 builtin.Arch.aarch64v8_2a,178 builtin.Arch.aarch64_be,
255 builtin.Arch.aarch64v8_1a,
256 builtin.Arch.aarch64v8,
257 builtin.Arch.aarch64v8r,
258 builtin.Arch.aarch64v8m_baseline,
259 builtin.Arch.aarch64v8m_mainline,
260 builtin.Arch.aarch64_bev8_3a,
261 builtin.Arch.aarch64_bev8_2a,
262 builtin.Arch.aarch64_bev8_1a,
263 builtin.Arch.aarch64_bev8,
264 builtin.Arch.aarch64_bev8r,
265 builtin.Arch.aarch64_bev8m_baseline,
266 builtin.Arch.aarch64_bev8m_mainline,
267 builtin.Arch.mips64,179 builtin.Arch.mips64,
268 builtin.Arch.mips64el,180 builtin.Arch.mips64el,
269 builtin.Arch.powerpc64,181 builtin.Arch.powerpc64,
...@@ -287,17 +199,17 @@ pub const Target = union(enum) {...@@ -287,17 +199,17 @@ pub const Target = union(enum) {
287 }199 }
288200
289 pub fn getFloatAbi(self: Target) FloatAbi {201 pub fn getFloatAbi(self: Target) FloatAbi {
290 return switch (self.getEnviron()) {202 return switch (self.getAbi()) {
291 builtin.Environ.gnueabihf,203 builtin.Abi.gnueabihf,
292 builtin.Environ.eabihf,204 builtin.Abi.eabihf,
293 builtin.Environ.musleabihf,205 builtin.Abi.musleabihf,
294 => FloatAbi.Hard,206 => FloatAbi.Hard,
295 else => FloatAbi.Soft,207 else => FloatAbi.Soft,
296 };208 };
297 }209 }
298210
299 pub fn getDynamicLinkerPath(self: Target) ?[]const u8 {211 pub fn getDynamicLinkerPath(self: Target) ?[]const u8 {
300 const env = self.getEnviron();212 const env = self.getAbi();
301 const arch = self.getArch();213 const arch = self.getArch();
302 const os = self.getOs();214 const os = self.getOs();
303 switch (os) {215 switch (os) {
...@@ -306,21 +218,21 @@ pub const Target = union(enum) {...@@ -306,21 +218,21 @@ pub const Target = union(enum) {
306 },218 },
307 builtin.Os.linux => {219 builtin.Os.linux => {
308 switch (env) {220 switch (env) {
309 builtin.Environ.android => {221 builtin.Abi.android => {
310 if (self.is64bit()) {222 if (self.is64bit()) {
311 return "/system/bin/linker64";223 return "/system/bin/linker64";
312 } else {224 } else {
313 return "/system/bin/linker";225 return "/system/bin/linker";
314 }226 }
315 },227 },
316 builtin.Environ.gnux32 => {228 builtin.Abi.gnux32 => {
317 if (arch == builtin.Arch.x86_64) {229 if (arch == builtin.Arch.x86_64) {
318 return "/libx32/ld-linux-x32.so.2";230 return "/libx32/ld-linux-x32.so.2";
319 }231 }
320 },232 },
321 builtin.Environ.musl,233 builtin.Abi.musl,
322 builtin.Environ.musleabi,234 builtin.Abi.musleabi,
323 builtin.Environ.musleabihf,235 builtin.Abi.musleabihf,
324 => {236 => {
325 if (arch == builtin.Arch.x86_64) {237 if (arch == builtin.Arch.x86_64) {
326 return "/lib/ld-musl-x86_64.so.1";238 return "/lib/ld-musl-x86_64.so.1";
...@@ -334,70 +246,18 @@ pub const Target = union(enum) {...@@ -334,70 +246,18 @@ pub const Target = union(enum) {
334 builtin.Arch.sparcel,246 builtin.Arch.sparcel,
335 => return "/lib/ld-linux.so.2",247 => return "/lib/ld-linux.so.2",
336248
337 builtin.Arch.aarch64v8_3a,249 builtin.Arch.aarch64 => return "/lib/ld-linux-aarch64.so.1",
338 builtin.Arch.aarch64v8_2a,250
339 builtin.Arch.aarch64v8_1a,251 builtin.Arch.aarch64_be => return "/lib/ld-linux-aarch64_be.so.1",
340 builtin.Arch.aarch64v8,252
341 builtin.Arch.aarch64v8r,253 builtin.Arch.arm,
342 builtin.Arch.aarch64v8m_baseline,
343 builtin.Arch.aarch64v8m_mainline,
344 => return "/lib/ld-linux-aarch64.so.1",
345
346 builtin.Arch.aarch64_bev8_3a,
347 builtin.Arch.aarch64_bev8_2a,
348 builtin.Arch.aarch64_bev8_1a,
349 builtin.Arch.aarch64_bev8,
350 builtin.Arch.aarch64_bev8r,
351 builtin.Arch.aarch64_bev8m_baseline,
352 builtin.Arch.aarch64_bev8m_mainline,
353 => return "/lib/ld-linux-aarch64_be.so.1",
354
355 builtin.Arch.armv8_3a,
356 builtin.Arch.armv8_2a,
357 builtin.Arch.armv8_1a,
358 builtin.Arch.armv8,
359 builtin.Arch.armv8r,
360 builtin.Arch.armv8m_baseline,
361 builtin.Arch.armv8m_mainline,
362 builtin.Arch.armv7,
363 builtin.Arch.armv7em,
364 builtin.Arch.armv7m,
365 builtin.Arch.armv7s,
366 builtin.Arch.armv7k,
367 builtin.Arch.armv7ve,
368 builtin.Arch.armv6,
369 builtin.Arch.armv6m,
370 builtin.Arch.armv6k,
371 builtin.Arch.armv6t2,
372 builtin.Arch.armv5,
373 builtin.Arch.armv5te,
374 builtin.Arch.armv4t,
375 builtin.Arch.thumb,254 builtin.Arch.thumb,
376 => return switch (self.getFloatAbi()) {255 => return switch (self.getFloatAbi()) {
377 FloatAbi.Hard => return "/lib/ld-linux-armhf.so.3",256 FloatAbi.Hard => return "/lib/ld-linux-armhf.so.3",
378 else => return "/lib/ld-linux.so.3",257 else => return "/lib/ld-linux.so.3",
379 },258 },
380259
381 builtin.Arch.armebv8_3a,260 builtin.Arch.armeb,
382 builtin.Arch.armebv8_2a,
383 builtin.Arch.armebv8_1a,
384 builtin.Arch.armebv8,
385 builtin.Arch.armebv8r,
386 builtin.Arch.armebv8m_baseline,
387 builtin.Arch.armebv8m_mainline,
388 builtin.Arch.armebv7,
389 builtin.Arch.armebv7em,
390 builtin.Arch.armebv7m,
391 builtin.Arch.armebv7s,
392 builtin.Arch.armebv7k,
393 builtin.Arch.armebv7ve,
394 builtin.Arch.armebv6,
395 builtin.Arch.armebv6m,
396 builtin.Arch.armebv6k,
397 builtin.Arch.armebv6t2,
398 builtin.Arch.armebv5,
399 builtin.Arch.armebv5te,
400 builtin.Arch.armebv4t,
401 builtin.Arch.thumbeb,261 builtin.Arch.thumbeb,
402 => return switch (self.getFloatAbi()) {262 => return switch (self.getFloatAbi()) {
403 FloatAbi.Hard => return "/lib/ld-linux-armhf.so.3",263 FloatAbi.Hard => return "/lib/ld-linux-armhf.so.3",
...@@ -441,9 +301,7 @@ pub const Target = union(enum) {...@@ -441,9 +301,7 @@ pub const Target = union(enum) {
441 builtin.Arch.hsail64,301 builtin.Arch.hsail64,
442 builtin.Arch.spir,302 builtin.Arch.spir,
443 builtin.Arch.spir64,303 builtin.Arch.spir64,
444 builtin.Arch.kalimbav3,304 builtin.Arch.kalimba,
445 builtin.Arch.kalimbav4,
446 builtin.Arch.kalimbav5,
447 builtin.Arch.shave,305 builtin.Arch.shave,
448 builtin.Arch.lanai,306 builtin.Arch.lanai,
449 builtin.Arch.wasm32,307 builtin.Arch.wasm32,
...@@ -566,35 +424,9 @@ pub const Target = union(enum) {...@@ -566,35 +424,9 @@ pub const Target = union(enum) {
566 pub fn getDarwinArchString(self: Target) []const u8 {424 pub fn getDarwinArchString(self: Target) []const u8 {
567 const arch = self.getArch();425 const arch = self.getArch();
568 switch (arch) {426 switch (arch) {
569 builtin.Arch.aarch64v8_3a,427 builtin.Arch.aarch64 => return "arm64",
570 builtin.Arch.aarch64v8_2a,
571 builtin.Arch.aarch64v8_1a,
572 builtin.Arch.aarch64v8,
573 builtin.Arch.aarch64v8r,
574 builtin.Arch.aarch64v8m_baseline,
575 builtin.Arch.aarch64v8m_mainline,
576 => return "arm64",
577 builtin.Arch.thumb,428 builtin.Arch.thumb,
578 builtin.Arch.armv8_3a,429 builtin.Arch.arm,
579 builtin.Arch.armv8_2a,
580 builtin.Arch.armv8_1a,
581 builtin.Arch.armv8,
582 builtin.Arch.armv8r,
583 builtin.Arch.armv8m_baseline,
584 builtin.Arch.armv8m_mainline,
585 builtin.Arch.armv7,
586 builtin.Arch.armv7em,
587 builtin.Arch.armv7m,
588 builtin.Arch.armv7s,
589 builtin.Arch.armv7k,
590 builtin.Arch.armv7ve,
591 builtin.Arch.armv6,
592 builtin.Arch.armv6m,
593 builtin.Arch.armv6k,
594 builtin.Arch.armv6t2,
595 builtin.Arch.armv5,
596 builtin.Arch.armv5te,
597 builtin.Arch.armv4t,
598 => return "arm",430 => return "arm",
599 builtin.Arch.powerpc => return "ppc",431 builtin.Arch.powerpc => return "ppc",
600 builtin.Arch.powerpc64 => return "ppc64",432 builtin.Arch.powerpc64 => return "ppc64",
src/all_types.hpp+2-1
...@@ -1784,7 +1784,8 @@ struct CodeGen {...@@ -1784,7 +1784,8 @@ struct CodeGen {
1784 unsigned pointer_size_bytes;1784 unsigned pointer_size_bytes;
1785 uint32_t target_os_index;1785 uint32_t target_os_index;
1786 uint32_t target_arch_index;1786 uint32_t target_arch_index;
1787 uint32_t target_environ_index;1787 uint32_t target_sub_arch_index;
1788 uint32_t target_abi_index;
1788 uint32_t target_oformat_index;1789 uint32_t target_oformat_index;
1789 bool is_big_endian;1790 bool is_big_endian;
1790 bool have_pub_main;1791 bool have_pub_main;
src/analyze.cpp+1-1
...@@ -1102,7 +1102,7 @@ bool want_first_arg_sret(CodeGen *g, FnTypeId *fn_type_id) {...@@ -1102,7 +1102,7 @@ bool want_first_arg_sret(CodeGen *g, FnTypeId *fn_type_id) {
1102 if (type_is_c_abi_int(g, fn_type_id->return_type)) {1102 if (type_is_c_abi_int(g, fn_type_id->return_type)) {
1103 return false;1103 return false;
1104 }1104 }
1105 if (g->zig_target->arch.arch == ZigLLVM_x86_64) {1105 if (g->zig_target->arch == ZigLLVM_x86_64) {
1106 X64CABIClass abi_class = type_c_abi_x86_64_class(g, fn_type_id->return_type);1106 X64CABIClass abi_class = type_c_abi_x86_64_class(g, fn_type_id->return_type);
1107 return abi_class == X64CABIClass_MEMORY;1107 return abi_class == X64CABIClass_MEMORY;
1108 } else if (target_is_arm(g->zig_target)) {1108 } else if (target_is_arm(g->zig_target)) {
src/buffer.hpp+1-3
...@@ -132,9 +132,7 @@ void buf_appendf(Buf *buf, const char *format, ...)...@@ -132,9 +132,7 @@ void buf_appendf(Buf *buf, const char *format, ...)
132132
133static inline bool buf_eql_mem(Buf *buf, const char *mem, size_t mem_len) {133static inline bool buf_eql_mem(Buf *buf, const char *mem, size_t mem_len) {
134 assert(buf->list.length);134 assert(buf->list.length);
135 if (buf_len(buf) != mem_len)135 return mem_eql_mem(buf_ptr(buf), buf_len(buf), mem, mem_len);
136 return false;
137 return memcmp(buf_ptr(buf), mem, mem_len) == 0;
138}136}
139137
140static inline bool buf_eql_str(Buf *buf, const char *str) {138static inline bool buf_eql_str(Buf *buf, const char *str) {
src/codegen.cpp+71-47
...@@ -29,9 +29,9 @@ static void init_darwin_native(CodeGen *g) {...@@ -29,9 +29,9 @@ static void init_darwin_native(CodeGen *g) {
2929
30 // Allow conflicts among OSX and iOS, but choose the default platform.30 // Allow conflicts among OSX and iOS, but choose the default platform.
31 if (osx_target && ios_target) {31 if (osx_target && ios_target) {
32 if (g->zig_target->arch.arch == ZigLLVM_arm ||32 if (g->zig_target->arch == ZigLLVM_arm ||
33 g->zig_target->arch.arch == ZigLLVM_aarch64 ||33 g->zig_target->arch == ZigLLVM_aarch64 ||
34 g->zig_target->arch.arch == ZigLLVM_thumb)34 g->zig_target->arch == ZigLLVM_thumb)
35 {35 {
36 osx_target = nullptr;36 osx_target = nullptr;
37 } else {37 } else {
...@@ -347,8 +347,8 @@ static LLVMCallConv get_llvm_cc(CodeGen *g, CallingConvention cc) {...@@ -347,8 +347,8 @@ static LLVMCallConv get_llvm_cc(CodeGen *g, CallingConvention cc) {
347 case CallingConventionC: return LLVMCCallConv;347 case CallingConventionC: return LLVMCCallConv;
348 case CallingConventionCold:348 case CallingConventionCold:
349 // cold calling convention only works on x86.349 // cold calling convention only works on x86.
350 if (g->zig_target->arch.arch == ZigLLVM_x86 ||350 if (g->zig_target->arch == ZigLLVM_x86 ||
351 g->zig_target->arch.arch == ZigLLVM_x86_64)351 g->zig_target->arch == ZigLLVM_x86_64)
352 {352 {
353 // cold calling convention is not supported on windows353 // cold calling convention is not supported on windows
354 if (g->zig_target->os == OsWindows) {354 if (g->zig_target->os == OsWindows) {
...@@ -364,7 +364,7 @@ static LLVMCallConv get_llvm_cc(CodeGen *g, CallingConvention cc) {...@@ -364,7 +364,7 @@ static LLVMCallConv get_llvm_cc(CodeGen *g, CallingConvention cc) {
364 zig_unreachable();364 zig_unreachable();
365 case CallingConventionStdcall:365 case CallingConventionStdcall:
366 // stdcall calling convention only works on x86.366 // stdcall calling convention only works on x86.
367 if (g->zig_target->arch.arch == ZigLLVM_x86) {367 if (g->zig_target->arch == ZigLLVM_x86) {
368 return LLVMX86StdcallCallConv;368 return LLVMX86StdcallCallConv;
369 } else {369 } else {
370 return LLVMCCallConv;370 return LLVMCCallConv;
...@@ -463,7 +463,7 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, ZigFn *fn_table_entry) {...@@ -463,7 +463,7 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, ZigFn *fn_table_entry) {
463 bool external_linkage = linkage != GlobalLinkageIdInternal;463 bool external_linkage = linkage != GlobalLinkageIdInternal;
464 CallingConvention cc = fn_table_entry->type_entry->data.fn.fn_type_id.cc;464 CallingConvention cc = fn_table_entry->type_entry->data.fn.fn_type_id.cc;
465 if (cc == CallingConventionStdcall && external_linkage &&465 if (cc == CallingConventionStdcall && external_linkage &&
466 g->zig_target->arch.arch == ZigLLVM_x86)466 g->zig_target->arch == ZigLLVM_x86)
467 {467 {
468 // prevent llvm name mangling468 // prevent llvm name mangling
469 symbol_name = buf_sprintf("\x01_%s", buf_ptr(symbol_name));469 symbol_name = buf_sprintf("\x01_%s", buf_ptr(symbol_name));
...@@ -2095,7 +2095,7 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_...@@ -2095,7 +2095,7 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_
2095 return true;2095 return true;
2096 }2096 }
20972097
2098 if (g->zig_target->arch.arch == ZigLLVM_x86_64) {2098 if (g->zig_target->arch == ZigLLVM_x86_64) {
2099 X64CABIClass abi_class = type_c_abi_x86_64_class(g, ty);2099 X64CABIClass abi_class = type_c_abi_x86_64_class(g, ty);
2100 size_t ty_size = type_size(g, ty);2100 size_t ty_size = type_size(g, ty);
2101 if (abi_class == X64CABIClass_MEMORY) {2101 if (abi_class == X64CABIClass_MEMORY) {
...@@ -3344,9 +3344,9 @@ static LLVMValueRef gen_valgrind_client_request(CodeGen *g, LLVMValueRef default...@@ -3344,9 +3344,9 @@ static LLVMValueRef gen_valgrind_client_request(CodeGen *g, LLVMValueRef default
3344 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->type_ref;3344 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->type_ref;
3345 bool asm_has_side_effects = true;3345 bool asm_has_side_effects = true;
3346 bool asm_is_alignstack = false;3346 bool asm_is_alignstack = false;
3347 if (g->zig_target->arch.arch == ZigLLVM_x86_64) {3347 if (g->zig_target->arch == ZigLLVM_x86_64) {
3348 if (g->zig_target->os == OsLinux || target_is_darwin(g->zig_target) || g->zig_target->os == OsSolaris ||3348 if (g->zig_target->os == OsLinux || target_is_darwin(g->zig_target) || g->zig_target->os == OsSolaris ||
3349 (g->zig_target->os == OsWindows && g->zig_target->env_type != ZigLLVM_MSVC))3349 (g->zig_target->os == OsWindows && g->zig_target->abi != ZigLLVM_MSVC))
3350 {3350 {
3351 if (g->cur_fn->valgrind_client_request_array == nullptr) {3351 if (g->cur_fn->valgrind_client_request_array == nullptr) {
3352 LLVMBasicBlockRef prev_block = LLVMGetInsertBlock(g->builder);3352 LLVMBasicBlockRef prev_block = LLVMGetInsertBlock(g->builder);
...@@ -3586,7 +3586,7 @@ static void gen_set_stack_pointer(CodeGen *g, LLVMValueRef aligned_end_addr) {...@@ -3586,7 +3586,7 @@ static void gen_set_stack_pointer(CodeGen *g, LLVMValueRef aligned_end_addr) {
3586 LLVMValueRef write_register_fn_val = get_write_register_fn_val(g);3586 LLVMValueRef write_register_fn_val = get_write_register_fn_val(g);
35873587
3588 if (g->sp_md_node == nullptr) {3588 if (g->sp_md_node == nullptr) {
3589 Buf *sp_reg_name = buf_create_from_str(arch_stack_pointer_register_name(&g->zig_target->arch));3589 Buf *sp_reg_name = buf_create_from_str(arch_stack_pointer_register_name(g->zig_target->arch));
3590 LLVMValueRef str_node = LLVMMDString(buf_ptr(sp_reg_name), buf_len(sp_reg_name) + 1);3590 LLVMValueRef str_node = LLVMMDString(buf_ptr(sp_reg_name), buf_len(sp_reg_name) + 1);
3591 g->sp_md_node = LLVMMDNode(&str_node, 1);3591 g->sp_md_node = LLVMMDNode(&str_node, 1);
3592 }3592 }
...@@ -7284,8 +7284,8 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {...@@ -7284,8 +7284,8 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
7284 buf_appendf(contents, "pub const Os = enum {\n");7284 buf_appendf(contents, "pub const Os = enum {\n");
7285 uint32_t field_count = (uint32_t)target_os_count();7285 uint32_t field_count = (uint32_t)target_os_count();
7286 for (uint32_t i = 0; i < field_count; i += 1) {7286 for (uint32_t i = 0; i < field_count; i += 1) {
7287 Os os_type = get_target_os(i);7287 Os os_type = target_os_enum(i);
7288 const char *name = get_target_os_name(os_type);7288 const char *name = target_os_name(os_type);
7289 buf_appendf(contents, " %s,\n", name);7289 buf_appendf(contents, " %s,\n", name);
72907290
7291 if (os_type == g->zig_target->os) {7291 if (os_type == g->zig_target->os) {
...@@ -7299,53 +7299,77 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {...@@ -7299,53 +7299,77 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
72997299
7300 const char *cur_arch = nullptr;7300 const char *cur_arch = nullptr;
7301 {7301 {
7302 buf_appendf(contents, "pub const Arch = enum {\n");7302 buf_appendf(contents, "pub const Arch = union(enum) {\n");
7303 uint32_t field_count = (uint32_t)target_arch_count();7303 uint32_t field_count = (uint32_t)target_arch_count();
7304 for (uint32_t i = 0; i < field_count; i += 1) {7304 for (uint32_t arch_i = 0; arch_i < field_count; arch_i += 1) {
7305 const ArchType *arch_type = get_target_arch(i);7305 ZigLLVM_ArchType arch = target_arch_enum(arch_i);
7306 Buf *arch_name = buf_alloc();7306 const char *arch_name = target_arch_name(arch);
7307 buf_resize(arch_name, 50);7307 SubArchList sub_arch_list = target_subarch_list(arch);
7308 get_arch_name(buf_ptr(arch_name), arch_type);7308 if (sub_arch_list == SubArchListNone) {
7309 buf_resize(arch_name, strlen(buf_ptr(arch_name)));7309 buf_appendf(contents, " %s,\n", arch_name);
73107310 if (arch == g->zig_target->arch) {
7311 buf_appendf(contents, " %s,\n", buf_ptr(arch_name));7311 g->target_arch_index = arch_i;
7312 cur_arch = buf_ptr(buf_sprintf("Arch.%s", arch_name));
7313 }
7314 } else {
7315 const char *sub_arch_list_name = target_subarch_list_name(sub_arch_list);
7316 buf_appendf(contents, " %s: %s,\n", arch_name, sub_arch_list_name);
7317 if (arch == g->zig_target->arch) {
7318 size_t sub_count = target_subarch_count(sub_arch_list);
7319 for (size_t sub_i = 0; sub_i < sub_count; sub_i += 1) {
7320 ZigLLVM_SubArchType sub = target_subarch_enum(sub_arch_list, sub_i);
7321 if (sub == g->zig_target->sub_arch) {
7322 g->target_sub_arch_index = sub_i;
7323 cur_arch = buf_ptr(buf_sprintf("Arch{ .%s = Arch.%s.%s }",
7324 arch_name, sub_arch_list_name, target_subarch_name(sub)));
7325 }
7326 }
7327 }
7328 }
7329 }
73127330
7313 if (arch_type->arch == g->zig_target->arch.arch &&7331 uint32_t list_count = target_subarch_list_count();
7314 arch_type->sub_arch == g->zig_target->arch.sub_arch)7332 // start at index 1 to skip None
7315 {7333 for (uint32_t list_i = 1; list_i < list_count; list_i += 1) {
7316 g->target_arch_index = i;7334 SubArchList sub_arch_list = target_subarch_list_enum(list_i);
7317 cur_arch = buf_ptr(arch_name);7335 const char *subarch_list_name = target_subarch_list_name(sub_arch_list);
7336 buf_appendf(contents, " pub const %s = enum {\n", subarch_list_name);
7337 size_t sub_count = target_subarch_count(sub_arch_list);
7338 for (size_t sub_i = 0; sub_i < sub_count; sub_i += 1) {
7339 ZigLLVM_SubArchType sub = target_subarch_enum(sub_arch_list, sub_i);
7340 buf_appendf(contents, " %s,\n", target_subarch_name(sub));
7318 }7341 }
7342 buf_appendf(contents, " };\n");
7319 }7343 }
7320 buf_appendf(contents, "};\n\n");7344 buf_appendf(contents, "};\n\n");
7321 }7345 }
7322 assert(cur_arch != nullptr);7346 assert(cur_arch != nullptr);
73237347
7324 const char *cur_environ = nullptr;7348 const char *cur_abi = nullptr;
7325 {7349 {
7326 buf_appendf(contents, "pub const Environ = enum {\n");7350 buf_appendf(contents, "pub const Abi = enum {\n");
7327 uint32_t field_count = (uint32_t)target_environ_count();7351 uint32_t field_count = (uint32_t)target_abi_count();
7328 for (uint32_t i = 0; i < field_count; i += 1) {7352 for (uint32_t i = 0; i < field_count; i += 1) {
7329 ZigLLVM_EnvironmentType environ_type = get_target_environ(i);7353 ZigLLVM_EnvironmentType abi = target_abi_enum(i);
7330 const char *name = ZigLLVMGetEnvironmentTypeName(environ_type);7354 const char *name = target_abi_name(abi);
7331 buf_appendf(contents, " %s,\n", name);7355 buf_appendf(contents, " %s,\n", name);
73327356
7333 if (environ_type == g->zig_target->env_type) {7357 if (abi == g->zig_target->abi) {
7334 g->target_environ_index = i;7358 g->target_abi_index = i;
7335 cur_environ = name;7359 cur_abi = name;
7336 }7360 }
7337 }7361 }
7338 buf_appendf(contents, "};\n\n");7362 buf_appendf(contents, "};\n\n");
7339 }7363 }
7340 assert(cur_environ != nullptr);7364 assert(cur_abi != nullptr);
73417365
7342 const char *cur_obj_fmt = nullptr;7366 const char *cur_obj_fmt = nullptr;
7343 {7367 {
7344 buf_appendf(contents, "pub const ObjectFormat = enum {\n");7368 buf_appendf(contents, "pub const ObjectFormat = enum {\n");
7345 uint32_t field_count = (uint32_t)target_oformat_count();7369 uint32_t field_count = (uint32_t)target_oformat_count();
7346 for (uint32_t i = 0; i < field_count; i += 1) {7370 for (uint32_t i = 0; i < field_count; i += 1) {
7347 ZigLLVM_ObjectFormatType oformat = get_target_oformat(i);7371 ZigLLVM_ObjectFormatType oformat = target_oformat_enum(i);
7348 const char *name = get_target_oformat_name(oformat);7372 const char *name = target_oformat_name(oformat);
7349 buf_appendf(contents, " %s,\n", name);7373 buf_appendf(contents, " %s,\n", name);
73507374
7351 ZigLLVM_ObjectFormatType target_oformat = target_object_format(g->zig_target);7375 ZigLLVM_ObjectFormatType target_oformat = target_object_format(g->zig_target);
...@@ -7633,8 +7657,8 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {...@@ -7633,8 +7657,8 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
7633 buf_appendf(contents, "pub const is_test = %s;\n", bool_to_str(g->is_test_build));7657 buf_appendf(contents, "pub const is_test = %s;\n", bool_to_str(g->is_test_build));
7634 buf_appendf(contents, "pub const single_threaded = %s;\n", bool_to_str(g->is_single_threaded));7658 buf_appendf(contents, "pub const single_threaded = %s;\n", bool_to_str(g->is_single_threaded));
7635 buf_appendf(contents, "pub const os = Os.%s;\n", cur_os);7659 buf_appendf(contents, "pub const os = Os.%s;\n", cur_os);
7636 buf_appendf(contents, "pub const arch = Arch.%s;\n", cur_arch);7660 buf_appendf(contents, "pub const arch = %s;\n", cur_arch);
7637 buf_appendf(contents, "pub const environ = Environ.%s;\n", cur_environ);7661 buf_appendf(contents, "pub const abi = Abi.%s;\n", cur_abi);
7638 buf_appendf(contents, "pub const object_format = ObjectFormat.%s;\n", cur_obj_fmt);7662 buf_appendf(contents, "pub const object_format = ObjectFormat.%s;\n", cur_obj_fmt);
7639 buf_appendf(contents, "pub const mode = %s;\n", build_mode_to_str(g->build_mode));7663 buf_appendf(contents, "pub const mode = %s;\n", build_mode_to_str(g->build_mode));
7640 buf_appendf(contents, "pub const link_libc = %s;\n", bool_to_str(g->libc_link_lib != nullptr));7664 buf_appendf(contents, "pub const link_libc = %s;\n", bool_to_str(g->libc_link_lib != nullptr));
...@@ -7669,11 +7693,11 @@ static Error define_builtin_compile_vars(CodeGen *g) {...@@ -7669,11 +7693,11 @@ static Error define_builtin_compile_vars(CodeGen *g) {
7669 cache_bool(&cache_hash, g->is_test_build);7693 cache_bool(&cache_hash, g->is_test_build);
7670 cache_bool(&cache_hash, g->is_single_threaded);7694 cache_bool(&cache_hash, g->is_single_threaded);
7671 cache_int(&cache_hash, g->zig_target->is_native);7695 cache_int(&cache_hash, g->zig_target->is_native);
7672 cache_int(&cache_hash, g->zig_target->arch.arch);7696 cache_int(&cache_hash, g->zig_target->arch);
7673 cache_int(&cache_hash, g->zig_target->arch.sub_arch);7697 cache_int(&cache_hash, g->zig_target->sub_arch);
7674 cache_int(&cache_hash, g->zig_target->vendor);7698 cache_int(&cache_hash, g->zig_target->vendor);
7675 cache_int(&cache_hash, g->zig_target->os);7699 cache_int(&cache_hash, g->zig_target->os);
7676 cache_int(&cache_hash, g->zig_target->env_type);7700 cache_int(&cache_hash, g->zig_target->abi);
7677 cache_bool(&cache_hash, g->have_err_ret_tracing);7701 cache_bool(&cache_hash, g->have_err_ret_tracing);
7678 cache_bool(&cache_hash, g->libc_link_lib != nullptr);7702 cache_bool(&cache_hash, g->libc_link_lib != nullptr);
7679 cache_bool(&cache_hash, g->valgrind_support);7703 cache_bool(&cache_hash, g->valgrind_support);
...@@ -7901,7 +7925,7 @@ static void detect_libc(CodeGen *g) {...@@ -7901,7 +7925,7 @@ static void detect_libc(CodeGen *g) {
7901 // without a cross compiling libc kit.7925 // without a cross compiling libc kit.
7902 fprintf(stderr,7926 fprintf(stderr,
7903 "Cannot link against libc for non-native OS '%s' without providing a libc installation file.\n"7927 "Cannot link against libc for non-native OS '%s' without providing a libc installation file.\n"
7904 "See `zig libc --help` for more details.\n", get_target_os_name(g->zig_target->os));7928 "See `zig libc --help` for more details.\n", target_os_name(g->zig_target->os));
7905 exit(1);7929 exit(1);
7906 }7930 }
7907}7931}
...@@ -8799,11 +8823,11 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {...@@ -8799,11 +8823,11 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {
8799 cache_int(ch, g->build_mode);8823 cache_int(ch, g->build_mode);
8800 cache_int(ch, g->out_type);8824 cache_int(ch, g->out_type);
8801 cache_bool(ch, g->zig_target->is_native);8825 cache_bool(ch, g->zig_target->is_native);
8802 cache_int(ch, g->zig_target->arch.arch);8826 cache_int(ch, g->zig_target->arch);
8803 cache_int(ch, g->zig_target->arch.sub_arch);8827 cache_int(ch, g->zig_target->sub_arch);
8804 cache_int(ch, g->zig_target->vendor);8828 cache_int(ch, g->zig_target->vendor);
8805 cache_int(ch, g->zig_target->os);8829 cache_int(ch, g->zig_target->os);
8806 cache_int(ch, g->zig_target->env_type);8830 cache_int(ch, g->zig_target->abi);
8807 cache_int(ch, g->subsystem);8831 cache_int(ch, g->subsystem);
8808 cache_bool(ch, g->is_static);8832 cache_bool(ch, g->is_static);
8809 cache_bool(ch, g->strip_debug_symbols);8833 cache_bool(ch, g->strip_debug_symbols);
src/error.cpp+5
...@@ -37,6 +37,11 @@ const char *err_str(Error err) {...@@ -37,6 +37,11 @@ const char *err_str(Error err) {
37 case ErrorPathTooLong: return "path too long";37 case ErrorPathTooLong: return "path too long";
38 case ErrorCCompilerCannotFindFile: return "C compiler cannot find file";38 case ErrorCCompilerCannotFindFile: return "C compiler cannot find file";
39 case ErrorReadingDepFile: return "failed to read .d file";39 case ErrorReadingDepFile: return "failed to read .d file";
40 case ErrorMissingArchitecture: return "missing architecture";
41 case ErrorMissingOperatingSystem: return "missing operating system";
42 case ErrorUnknownArchitecture: return "unrecognized architecture";
43 case ErrorUnknownOperatingSystem: return "unrecognized operating system";
44 case ErrorUnknownABI: return "unrecognized C ABI";
40 }45 }
41 return "(invalid error)";46 return "(invalid error)";
42}47}
src/error.hpp+5
...@@ -39,6 +39,11 @@ enum Error {...@@ -39,6 +39,11 @@ enum Error {
39 ErrorPathTooLong,39 ErrorPathTooLong,
40 ErrorCCompilerCannotFindFile,40 ErrorCCompilerCannotFindFile,
41 ErrorReadingDepFile,41 ErrorReadingDepFile,
42 ErrorMissingArchitecture,
43 ErrorMissingOperatingSystem,
44 ErrorUnknownArchitecture,
45 ErrorUnknownOperatingSystem,
46 ErrorUnknownABI,
42};47};
4348
44const char *err_str(Error err);49const char *err_str(Error err);
src/libc_installation.cpp+10-8
...@@ -103,7 +103,7 @@ Error zig_libc_parse(ZigLibCInstallation *libc, Buf *libc_file, const ZigTarget...@@ -103,7 +103,7 @@ Error zig_libc_parse(ZigLibCInstallation *libc, Buf *libc_file, const ZigTarget
103 if (buf_len(&libc->crt_dir) == 0) {103 if (buf_len(&libc->crt_dir) == 0) {
104 if (!target_is_darwin(target)) {104 if (!target_is_darwin(target)) {
105 if (verbose) {105 if (verbose) {
106 fprintf(stderr, "crt_dir may not be empty for %s\n", get_target_os_name(target->os));106 fprintf(stderr, "crt_dir may not be empty for %s\n", target_os_name(target->os));
107 }107 }
108 return ErrorSemanticAnalyzeFail;108 return ErrorSemanticAnalyzeFail;
109 }109 }
...@@ -112,7 +112,7 @@ Error zig_libc_parse(ZigLibCInstallation *libc, Buf *libc_file, const ZigTarget...@@ -112,7 +112,7 @@ Error zig_libc_parse(ZigLibCInstallation *libc, Buf *libc_file, const ZigTarget
112 if (buf_len(&libc->lib_dir) == 0) {112 if (buf_len(&libc->lib_dir) == 0) {
113 if (!target_is_darwin(target) && target->os != OsWindows) {113 if (!target_is_darwin(target) && target->os != OsWindows) {
114 if (verbose) {114 if (verbose) {
115 fprintf(stderr, "lib_dir may not be empty for %s\n", get_target_os_name(target->os));115 fprintf(stderr, "lib_dir may not be empty for %s\n", target_os_name(target->os));
116 }116 }
117 return ErrorSemanticAnalyzeFail;117 return ErrorSemanticAnalyzeFail;
118 }118 }
...@@ -121,7 +121,7 @@ Error zig_libc_parse(ZigLibCInstallation *libc, Buf *libc_file, const ZigTarget...@@ -121,7 +121,7 @@ Error zig_libc_parse(ZigLibCInstallation *libc, Buf *libc_file, const ZigTarget
121 if (buf_len(&libc->static_lib_dir) == 0) {121 if (buf_len(&libc->static_lib_dir) == 0) {
122 if (!target_is_darwin(target) && target->os != OsWindows) {122 if (!target_is_darwin(target) && target->os != OsWindows) {
123 if (verbose) {123 if (verbose) {
124 fprintf(stderr, "static_lib_dir may not be empty for %s\n", get_target_os_name(target->os));124 fprintf(stderr, "static_lib_dir may not be empty for %s\n", target_os_name(target->os));
125 }125 }
126 return ErrorSemanticAnalyzeFail;126 return ErrorSemanticAnalyzeFail;
127 }127 }
...@@ -130,7 +130,7 @@ Error zig_libc_parse(ZigLibCInstallation *libc, Buf *libc_file, const ZigTarget...@@ -130,7 +130,7 @@ Error zig_libc_parse(ZigLibCInstallation *libc, Buf *libc_file, const ZigTarget
130 if (buf_len(&libc->msvc_lib_dir) == 0) {130 if (buf_len(&libc->msvc_lib_dir) == 0) {
131 if (target->os == OsWindows) {131 if (target->os == OsWindows) {
132 if (verbose) {132 if (verbose) {
133 fprintf(stderr, "msvc_lib_dir may not be empty for %s\n", get_target_os_name(target->os));133 fprintf(stderr, "msvc_lib_dir may not be empty for %s\n", target_os_name(target->os));
134 }134 }
135 return ErrorSemanticAnalyzeFail;135 return ErrorSemanticAnalyzeFail;
136 }136 }
...@@ -139,7 +139,7 @@ Error zig_libc_parse(ZigLibCInstallation *libc, Buf *libc_file, const ZigTarget...@@ -139,7 +139,7 @@ Error zig_libc_parse(ZigLibCInstallation *libc, Buf *libc_file, const ZigTarget
139 if (buf_len(&libc->kernel32_lib_dir) == 0) {139 if (buf_len(&libc->kernel32_lib_dir) == 0) {
140 if (target->os == OsWindows) {140 if (target->os == OsWindows) {
141 if (verbose) {141 if (verbose) {
142 fprintf(stderr, "kernel32_lib_dir may not be empty for %s\n", get_target_os_name(target->os));142 fprintf(stderr, "kernel32_lib_dir may not be empty for %s\n", target_os_name(target->os));
143 }143 }
144 return ErrorSemanticAnalyzeFail;144 return ErrorSemanticAnalyzeFail;
145 }145 }
...@@ -148,7 +148,7 @@ Error zig_libc_parse(ZigLibCInstallation *libc, Buf *libc_file, const ZigTarget...@@ -148,7 +148,7 @@ Error zig_libc_parse(ZigLibCInstallation *libc, Buf *libc_file, const ZigTarget
148 if (buf_len(&libc->dynamic_linker_path) == 0) {148 if (buf_len(&libc->dynamic_linker_path) == 0) {
149 if (!target_is_darwin(target) && target->os != OsWindows) {149 if (!target_is_darwin(target) && target->os != OsWindows) {
150 if (verbose) {150 if (verbose) {
151 fprintf(stderr, "dynamic_linker_path may not be empty for %s\n", get_target_os_name(target->os));151 fprintf(stderr, "dynamic_linker_path may not be empty for %s\n", target_os_name(target->os));
152 }152 }
153 return ErrorSemanticAnalyzeFail;153 return ErrorSemanticAnalyzeFail;
154 }154 }
...@@ -334,8 +334,10 @@ static Error zig_libc_find_native_dynamic_linker_posix(ZigLibCInstallation *self...@@ -334,8 +334,10 @@ static Error zig_libc_find_native_dynamic_linker_posix(ZigLibCInstallation *self
334#endif334#endif
335 ZigTarget native_target;335 ZigTarget native_target;
336 get_native_target(&native_target);336 get_native_target(&native_target);
337 Buf *dynamic_linker_path = target_dynamic_linker(&native_target);337 const char *dynamic_linker_path = target_dynamic_linker(&native_target);
338 buf_init_from_buf(&self->dynamic_linker_path, dynamic_linker_path);338 if (dynamic_linker_path != nullptr) {
339 buf_init_from_str(&self->dynamic_linker_path, dynamic_linker_path);
340 }
339 return ErrorNone;341 return ErrorNone;
340}342}
341#endif343#endif
src/link.cpp+17-17
...@@ -96,7 +96,7 @@ static Buf *build_compiler_rt(CodeGen *parent_gen) {...@@ -96,7 +96,7 @@ static Buf *build_compiler_rt(CodeGen *parent_gen) {
96}96}
9797
98static const char *get_darwin_arch_string(const ZigTarget *t) {98static const char *get_darwin_arch_string(const ZigTarget *t) {
99 switch (t->arch.arch) {99 switch (t->arch) {
100 case ZigLLVM_aarch64:100 case ZigLLVM_aarch64:
101 return "arm64";101 return "arm64";
102 case ZigLLVM_thumb:102 case ZigLLVM_thumb:
...@@ -109,13 +109,13 @@ static const char *get_darwin_arch_string(const ZigTarget *t) {...@@ -109,13 +109,13 @@ static const char *get_darwin_arch_string(const ZigTarget *t) {
109 case ZigLLVM_ppc64le:109 case ZigLLVM_ppc64le:
110 return "ppc64le";110 return "ppc64le";
111 default:111 default:
112 return ZigLLVMGetArchTypeName(t->arch.arch);112 return ZigLLVMGetArchTypeName(t->arch);
113 }113 }
114}114}
115115
116116
117static const char *getLDMOption(const ZigTarget *t) {117static const char *getLDMOption(const ZigTarget *t) {
118 switch (t->arch.arch) {118 switch (t->arch) {
119 case ZigLLVM_x86:119 case ZigLLVM_x86:
120 return "elf_i386";120 return "elf_i386";
121 case ZigLLVM_aarch64:121 case ZigLLVM_aarch64:
...@@ -149,7 +149,7 @@ static const char *getLDMOption(const ZigTarget *t) {...@@ -149,7 +149,7 @@ static const char *getLDMOption(const ZigTarget *t) {
149 case ZigLLVM_systemz:149 case ZigLLVM_systemz:
150 return "elf64_s390";150 return "elf64_s390";
151 case ZigLLVM_x86_64:151 case ZigLLVM_x86_64:
152 if (t->env_type == ZigLLVM_GNUX32) {152 if (t->abi == ZigLLVM_GNUX32) {
153 return "elf32_x86_64";153 return "elf32_x86_64";
154 }154 }
155 // Any target elf will use the freebsd osabi if suffixed with "_fbsd".155 // Any target elf will use the freebsd osabi if suffixed with "_fbsd".
...@@ -191,8 +191,8 @@ static void construct_linker_job_elf(LinkJob *lj) {...@@ -191,8 +191,8 @@ static void construct_linker_job_elf(LinkJob *lj) {
191 bool shared = !g->is_static && is_lib;191 bool shared = !g->is_static && is_lib;
192 Buf *soname = nullptr;192 Buf *soname = nullptr;
193 if (g->is_static) {193 if (g->is_static) {
194 if (g->zig_target->arch.arch == ZigLLVM_arm || g->zig_target->arch.arch == ZigLLVM_armeb ||194 if (g->zig_target->arch == ZigLLVM_arm || g->zig_target->arch == ZigLLVM_armeb ||
195 g->zig_target->arch.arch == ZigLLVM_thumb || g->zig_target->arch.arch == ZigLLVM_thumbeb)195 g->zig_target->arch == ZigLLVM_thumb || g->zig_target->arch == ZigLLVM_thumbeb)
196 {196 {
197 lj->args.append("-Bstatic");197 lj->args.append("-Bstatic");
198 } else {198 } else {
...@@ -375,16 +375,16 @@ static void construct_linker_job_wasm(LinkJob *lj) {...@@ -375,16 +375,16 @@ static void construct_linker_job_wasm(LinkJob *lj) {
375}375}
376376
377//static bool is_target_cyg_mingw(const ZigTarget *target) {377//static bool is_target_cyg_mingw(const ZigTarget *target) {
378// return (target->os == ZigLLVM_Win32 && target->env_type == ZigLLVM_Cygnus) ||378// return (target->os == ZigLLVM_Win32 && target->abi == ZigLLVM_Cygnus) ||
379// (target->os == ZigLLVM_Win32 && target->env_type == ZigLLVM_GNU);379// (target->os == ZigLLVM_Win32 && target->abi == ZigLLVM_GNU);
380//}380//}
381381
382static void coff_append_machine_arg(CodeGen *g, ZigList<const char *> *list) {382static void coff_append_machine_arg(CodeGen *g, ZigList<const char *> *list) {
383 if (g->zig_target->arch.arch == ZigLLVM_x86) {383 if (g->zig_target->arch == ZigLLVM_x86) {
384 list->append("-MACHINE:X86");384 list->append("-MACHINE:X86");
385 } else if (g->zig_target->arch.arch == ZigLLVM_x86_64) {385 } else if (g->zig_target->arch == ZigLLVM_x86_64) {
386 list->append("-MACHINE:X64");386 list->append("-MACHINE:X64");
387 } else if (g->zig_target->arch.arch == ZigLLVM_arm) {387 } else if (g->zig_target->arch == ZigLLVM_arm) {
388 list->append("-MACHINE:ARM");388 list->append("-MACHINE:ARM");
389 }389 }
390}390}
...@@ -470,7 +470,7 @@ static void add_nt_link_args(LinkJob *lj, bool is_library) {...@@ -470,7 +470,7 @@ static void add_nt_link_args(LinkJob *lj, bool is_library) {
470// lj->args.append("-Bdynamic");470// lj->args.append("-Bdynamic");
471// if (dll || shared) {471// if (dll || shared) {
472// lj->args.append("-e");472// lj->args.append("-e");
473// if (g->zig_target.arch.arch == ZigLLVM_x86) {473// if (g->zig_target.arch == ZigLLVM_x86) {
474// lj->args.append("_DllMainCRTStartup@12");474// lj->args.append("_DllMainCRTStartup@12");
475// } else {475// } else {
476// lj->args.append("DllMainCRTStartup");476// lj->args.append("DllMainCRTStartup");
...@@ -496,7 +496,7 @@ static void add_nt_link_args(LinkJob *lj, bool is_library) {...@@ -496,7 +496,7 @@ static void add_nt_link_args(LinkJob *lj, bool is_library) {
496//lj->args.append("-lmingw32");496//lj->args.append("-lmingw32");
497497
498//lj->args.append("-lgcc");498//lj->args.append("-lgcc");
499//bool is_android = (g->zig_target.env_type == ZigLLVM_Android);499//bool is_android = (g->zig_target.abi == ZigLLVM_Android);
500//bool is_cyg_ming = is_target_cyg_mingw(&g->zig_target);500//bool is_cyg_ming = is_target_cyg_mingw(&g->zig_target);
501//if (!g->is_static && !is_android) {501//if (!g->is_static && !is_android) {
502// if (!is_cyg_ming) {502// if (!is_cyg_ming) {
...@@ -637,7 +637,7 @@ static void construct_linker_job_coff(LinkJob *lj) {...@@ -637,7 +637,7 @@ static void construct_linker_job_coff(LinkJob *lj) {
637 continue;637 continue;
638 }638 }
639 if (link_lib->provided_explicitly) {639 if (link_lib->provided_explicitly) {
640 if (lj->codegen->zig_target->env_type == ZigLLVM_GNU) {640 if (lj->codegen->zig_target->abi == ZigLLVM_GNU) {
641 Buf *arg = buf_sprintf("-l%s", buf_ptr(link_lib->name));641 Buf *arg = buf_sprintf("-l%s", buf_ptr(link_lib->name));
642 lj->args.append(buf_ptr(arg));642 lj->args.append(buf_ptr(arg));
643 }643 }
...@@ -764,8 +764,8 @@ static void get_darwin_platform(LinkJob *lj, DarwinPlatform *platform) {...@@ -764,8 +764,8 @@ static void get_darwin_platform(LinkJob *lj, DarwinPlatform *platform) {
764 }764 }
765765
766 if (platform->kind == IPhoneOS &&766 if (platform->kind == IPhoneOS &&
767 (g->zig_target->arch.arch == ZigLLVM_x86 ||767 (g->zig_target->arch == ZigLLVM_x86 ||
768 g->zig_target->arch.arch == ZigLLVM_x86_64))768 g->zig_target->arch == ZigLLVM_x86_64))
769 {769 {
770 platform->kind = IPhoneOSSimulator;770 platform->kind = IPhoneOSSimulator;
771 }771 }
...@@ -886,7 +886,7 @@ static void construct_linker_job_macho(LinkJob *lj) {...@@ -886,7 +886,7 @@ static void construct_linker_job_macho(LinkJob *lj) {
886 }886 }
887 break;887 break;
888 case IPhoneOS:888 case IPhoneOS:
889 if (g->zig_target->arch.arch == ZigLLVM_aarch64) {889 if (g->zig_target->arch == ZigLLVM_aarch64) {
890 // iOS does not need any crt1 files for arm64890 // iOS does not need any crt1 files for arm64
891 } else if (darwin_version_lt(&platform, 3, 1)) {891 } else if (darwin_version_lt(&platform, 3, 1)) {
892 lj->args.append("-lcrt1.o");892 lj->args.append("-lcrt1.o");
src/main.cpp+38-45
...@@ -69,9 +69,7 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) {...@@ -69,9 +69,7 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) {
69 " --single-threaded source may assume it is only used single-threaded\n"69 " --single-threaded source may assume it is only used single-threaded\n"
70 " --static output will be statically linked\n"70 " --static output will be statically linked\n"
71 " --strip exclude debug symbols\n"71 " --strip exclude debug symbols\n"
72 " --target-arch [name] specify target architecture\n"72 " -target [name] <arch><sub>-<os>-<abi> see the targets command\n"
73 " --target-environ [name] specify target environment\n"
74 " --target-os [name] specify target operating system\n"
75 " --verbose-tokenize enable compiler debug output for tokenization\n"73 " --verbose-tokenize enable compiler debug output for tokenization\n"
76 " --verbose-ast enable compiler debug output for AST parsing\n"74 " --verbose-ast enable compiler debug output for AST parsing\n"
77 " --verbose-link enable compiler debug output for linking\n"75 " --verbose-link enable compiler debug output for linking\n"
...@@ -145,6 +143,14 @@ static const char *ZIG_ZEN = "\n"...@@ -145,6 +143,14 @@ static const char *ZIG_ZEN = "\n"
145" * Minimize energy spent on coding style.\n"143" * Minimize energy spent on coding style.\n"
146" * Together we serve end users.\n";144" * Together we serve end users.\n";
147145
146static bool arch_available_in_llvm(ZigLLVM_ArchType arch) {
147 LLVMTargetRef target_ref;
148 char *err_msg = nullptr;
149 char triple_string[128];
150 sprintf(triple_string, "%s-unknown-unknown-unknown", ZigLLVMGetArchTypeName(arch));
151 return !LLVMGetTargetFromTriple(triple_string, &target_ref, &err_msg);
152}
153
148static int print_target_list(FILE *f) {154static int print_target_list(FILE *f) {
149 ZigTarget native;155 ZigTarget native;
150 get_native_target(&native);156 get_native_target(&native);
...@@ -152,28 +158,36 @@ static int print_target_list(FILE *f) {...@@ -152,28 +158,36 @@ static int print_target_list(FILE *f) {
152 fprintf(f, "Architectures:\n");158 fprintf(f, "Architectures:\n");
153 size_t arch_count = target_arch_count();159 size_t arch_count = target_arch_count();
154 for (size_t arch_i = 0; arch_i < arch_count; arch_i += 1) {160 for (size_t arch_i = 0; arch_i < arch_count; arch_i += 1) {
155 const ArchType *arch = get_target_arch(arch_i);161 ZigLLVM_ArchType arch = target_arch_enum(arch_i);
156 char arch_name[50];162 if (!arch_available_in_llvm(arch))
157 get_arch_name(arch_name, arch);163 continue;
158 const char *native_str = (native.arch.arch == arch->arch && native.arch.sub_arch == arch->sub_arch) ?164 const char *arch_name = target_arch_name(arch);
159 " (native)" : "";165 SubArchList sub_arch_list = target_subarch_list(arch);
160 fprintf(f, " %s%s\n", arch_name, native_str);166 size_t sub_count = target_subarch_count(sub_arch_list);
167 const char *arch_native_str = (native.arch == arch) ? " (native)" : "";
168 fprintf(stderr, " %s%s\n", arch_name, arch_native_str);
169 for (size_t sub_i = 0; sub_i < sub_count; sub_i += 1) {
170 ZigLLVM_SubArchType sub = target_subarch_enum(sub_arch_list, sub_i);
171 const char *sub_name = target_subarch_name(sub);
172 const char *sub_native_str = (native.arch == arch && native.sub_arch == sub) ? " (native)" : "";
173 fprintf(f, " %s%s\n", sub_name, sub_native_str);
174 }
161 }175 }
162176
163 fprintf(f, "\nOperating Systems:\n");177 fprintf(f, "\nOperating Systems:\n");
164 size_t os_count = target_os_count();178 size_t os_count = target_os_count();
165 for (size_t i = 0; i < os_count; i += 1) {179 for (size_t i = 0; i < os_count; i += 1) {
166 Os os_type = get_target_os(i);180 Os os_type = target_os_enum(i);
167 const char *native_str = (native.os == os_type) ? " (native)" : "";181 const char *native_str = (native.os == os_type) ? " (native)" : "";
168 fprintf(f, " %s%s\n", get_target_os_name(os_type), native_str);182 fprintf(f, " %s%s\n", target_os_name(os_type), native_str);
169 }183 }
170184
171 fprintf(f, "\nEnvironments:\n");185 fprintf(f, "\nC ABIs:\n");
172 size_t environ_count = target_environ_count();186 size_t abi_count = target_abi_count();
173 for (size_t i = 0; i < environ_count; i += 1) {187 for (size_t i = 0; i < abi_count; i += 1) {
174 ZigLLVM_EnvironmentType environ_type = get_target_environ(i);188 ZigLLVM_EnvironmentType abi = target_abi_enum(i);
175 const char *native_str = (native.env_type == environ_type) ? " (native)" : "";189 const char *native_str = (native.abi == abi) ? " (native)" : "";
176 fprintf(f, " %s%s\n", ZigLLVMGetEnvironmentTypeName(environ_type), native_str);190 fprintf(f, " %s%s\n", target_abi_name(abi), native_str);
177 }191 }
178192
179 return EXIT_SUCCESS;193 return EXIT_SUCCESS;
...@@ -397,9 +411,7 @@ int main(int argc, char **argv) {...@@ -397,9 +411,7 @@ int main(int argc, char **argv) {
397 ZigList<const char *> link_libs = {0};411 ZigList<const char *> link_libs = {0};
398 ZigList<const char *> forbidden_link_libs = {0};412 ZigList<const char *> forbidden_link_libs = {0};
399 ZigList<const char *> frameworks = {0};413 ZigList<const char *> frameworks = {0};
400 const char *target_arch = nullptr;414 const char *target_string = nullptr;
401 const char *target_os = nullptr;
402 const char *target_environ = nullptr;
403 bool rdynamic = false;415 bool rdynamic = false;
404 const char *mmacosx_version_min = nullptr;416 const char *mmacosx_version_min = nullptr;
405 const char *mios_version_min = nullptr;417 const char *mios_version_min = nullptr;
...@@ -740,12 +752,8 @@ int main(int argc, char **argv) {...@@ -740,12 +752,8 @@ int main(int argc, char **argv) {
740 asm_files.append(argv[i]);752 asm_files.append(argv[i]);
741 } else if (strcmp(arg, "--cache-dir") == 0) {753 } else if (strcmp(arg, "--cache-dir") == 0) {
742 cache_dir = argv[i];754 cache_dir = argv[i];
743 } else if (strcmp(arg, "--target-arch") == 0) {755 } else if (strcmp(arg, "-target") == 0) {
744 target_arch = argv[i];756 target_string = argv[i];
745 } else if (strcmp(arg, "--target-os") == 0) {
746 target_os = argv[i];
747 } else if (strcmp(arg, "--target-environ") == 0) {
748 target_environ = argv[i];
749 } else if (strcmp(arg, "-mmacosx-version-min") == 0) {757 } else if (strcmp(arg, "-mmacosx-version-min") == 0) {
750 mmacosx_version_min = argv[i];758 mmacosx_version_min = argv[i];
751 } else if (strcmp(arg, "-mios-version-min") == 0) {759 } else if (strcmp(arg, "-mios-version-min") == 0) {
...@@ -874,27 +882,12 @@ int main(int argc, char **argv) {...@@ -874,27 +882,12 @@ int main(int argc, char **argv) {
874 init_all_targets();882 init_all_targets();
875883
876 ZigTarget target;884 ZigTarget target;
877 if (!target_arch && !target_os && !target_environ) {885 if (target_string == nullptr) {
878 get_native_target(&target);886 get_native_target(&target);
879 } else {887 } else {
880 get_unknown_target(&target);888 if ((err = target_parse_triple(&target, target_string))) {
881 if (target_arch) {889 fprintf(stderr, "invalid target: %s\n", err_str(err));
882 if (parse_target_arch(target_arch, &target.arch)) {890 return print_error_usage(arg0);
883 fprintf(stderr, "invalid --target-arch argument\n");
884 return print_error_usage(arg0);
885 }
886 }
887 if (target_os) {
888 if (parse_target_os(target_os, &target.os)) {
889 fprintf(stderr, "invalid --target-os argument\n");
890 return print_error_usage(arg0);
891 }
892 }
893 if (target_environ) {
894 if (parse_target_environ(target_environ, &target.env_type)) {
895 fprintf(stderr, "invalid --target-environ argument\n");
896 return print_error_usage(arg0);
897 }
898 }891 }
899 }892 }
900893
src/target.cpp+534-259
...@@ -13,115 +13,105 @@...@@ -13,115 +13,105 @@
1313
14#include <stdio.h>14#include <stdio.h>
1515
16static const ArchType arch_list[] = {16static const SubArchList subarch_list_list[] = {
17 {ZigLLVM_arm, ZigLLVM_ARMSubArch_v8_3a},17 SubArchListNone,
18 {ZigLLVM_arm, ZigLLVM_ARMSubArch_v8_2a},18 SubArchListArm32,
19 {ZigLLVM_arm, ZigLLVM_ARMSubArch_v8_1a},19 SubArchListArm64,
20 {ZigLLVM_arm, ZigLLVM_ARMSubArch_v8},20 SubArchListKalimba,
21 {ZigLLVM_arm, ZigLLVM_ARMSubArch_v8r},21};
22 {ZigLLVM_arm, ZigLLVM_ARMSubArch_v8m_baseline},22
23 {ZigLLVM_arm, ZigLLVM_ARMSubArch_v8m_mainline},23static const ZigLLVM_SubArchType subarch_list_arm32[] = {
24 {ZigLLVM_arm, ZigLLVM_ARMSubArch_v7},24 ZigLLVM_ARMSubArch_v8_4a,
25 {ZigLLVM_arm, ZigLLVM_ARMSubArch_v7em},25 ZigLLVM_ARMSubArch_v8_3a,
26 {ZigLLVM_arm, ZigLLVM_ARMSubArch_v7m},26 ZigLLVM_ARMSubArch_v8_2a,
27 {ZigLLVM_arm, ZigLLVM_ARMSubArch_v7s},27 ZigLLVM_ARMSubArch_v8_1a,
28 {ZigLLVM_arm, ZigLLVM_ARMSubArch_v7k},28 ZigLLVM_ARMSubArch_v8,
29 {ZigLLVM_arm, ZigLLVM_ARMSubArch_v7ve},29 ZigLLVM_ARMSubArch_v8r,
30 {ZigLLVM_arm, ZigLLVM_ARMSubArch_v6},30 ZigLLVM_ARMSubArch_v8m_baseline,
31 {ZigLLVM_arm, ZigLLVM_ARMSubArch_v6m},31 ZigLLVM_ARMSubArch_v8m_mainline,
32 {ZigLLVM_arm, ZigLLVM_ARMSubArch_v6k},32 ZigLLVM_ARMSubArch_v7,
33 {ZigLLVM_arm, ZigLLVM_ARMSubArch_v6t2},33 ZigLLVM_ARMSubArch_v7em,
34 {ZigLLVM_arm, ZigLLVM_ARMSubArch_v5},34 ZigLLVM_ARMSubArch_v7m,
35 {ZigLLVM_arm, ZigLLVM_ARMSubArch_v5te},35 ZigLLVM_ARMSubArch_v7s,
36 {ZigLLVM_arm, ZigLLVM_ARMSubArch_v4t},36 ZigLLVM_ARMSubArch_v7k,
3737 ZigLLVM_ARMSubArch_v7ve,
38 {ZigLLVM_armeb, ZigLLVM_ARMSubArch_v8_3a},38 ZigLLVM_ARMSubArch_v6,
39 {ZigLLVM_armeb, ZigLLVM_ARMSubArch_v8_2a},39 ZigLLVM_ARMSubArch_v6m,
40 {ZigLLVM_armeb, ZigLLVM_ARMSubArch_v8_1a},40 ZigLLVM_ARMSubArch_v6k,
41 {ZigLLVM_armeb, ZigLLVM_ARMSubArch_v8},41 ZigLLVM_ARMSubArch_v6t2,
42 {ZigLLVM_armeb, ZigLLVM_ARMSubArch_v8r},42 ZigLLVM_ARMSubArch_v5,
43 {ZigLLVM_armeb, ZigLLVM_ARMSubArch_v8m_baseline},43 ZigLLVM_ARMSubArch_v5te,
44 {ZigLLVM_armeb, ZigLLVM_ARMSubArch_v8m_mainline},44 ZigLLVM_ARMSubArch_v4t,
45 {ZigLLVM_armeb, ZigLLVM_ARMSubArch_v7},45};
46 {ZigLLVM_armeb, ZigLLVM_ARMSubArch_v7em},46
47 {ZigLLVM_armeb, ZigLLVM_ARMSubArch_v7m},47static const ZigLLVM_SubArchType subarch_list_arm64[] = {
48 {ZigLLVM_armeb, ZigLLVM_ARMSubArch_v7s},48 ZigLLVM_ARMSubArch_v8_4a,
49 {ZigLLVM_armeb, ZigLLVM_ARMSubArch_v7k},49 ZigLLVM_ARMSubArch_v8_3a,
50 {ZigLLVM_armeb, ZigLLVM_ARMSubArch_v7ve},50 ZigLLVM_ARMSubArch_v8_2a,
51 {ZigLLVM_armeb, ZigLLVM_ARMSubArch_v6},51 ZigLLVM_ARMSubArch_v8_1a,
52 {ZigLLVM_armeb, ZigLLVM_ARMSubArch_v6m},52 ZigLLVM_ARMSubArch_v8,
53 {ZigLLVM_armeb, ZigLLVM_ARMSubArch_v6k},53 ZigLLVM_ARMSubArch_v8r,
54 {ZigLLVM_armeb, ZigLLVM_ARMSubArch_v6t2},54 ZigLLVM_ARMSubArch_v8m_baseline,
55 {ZigLLVM_armeb, ZigLLVM_ARMSubArch_v5},55 ZigLLVM_ARMSubArch_v8m_mainline,
56 {ZigLLVM_armeb, ZigLLVM_ARMSubArch_v5te},56};
57 {ZigLLVM_armeb, ZigLLVM_ARMSubArch_v4t},57
5858static const ZigLLVM_SubArchType subarch_list_kalimba[] = {
59 {ZigLLVM_aarch64, ZigLLVM_ARMSubArch_v8_3a},59 ZigLLVM_KalimbaSubArch_v5,
60 {ZigLLVM_aarch64, ZigLLVM_ARMSubArch_v8_2a},60 ZigLLVM_KalimbaSubArch_v4,
61 {ZigLLVM_aarch64, ZigLLVM_ARMSubArch_v8_1a},61 ZigLLVM_KalimbaSubArch_v3,
62 {ZigLLVM_aarch64, ZigLLVM_ARMSubArch_v8},62};
63 {ZigLLVM_aarch64, ZigLLVM_ARMSubArch_v8r},63
64 {ZigLLVM_aarch64, ZigLLVM_ARMSubArch_v8m_baseline},64static const ZigLLVM_ArchType arch_list[] = {
65 {ZigLLVM_aarch64, ZigLLVM_ARMSubArch_v8m_mainline},65 ZigLLVM_arm,
6666 ZigLLVM_armeb,
67 {ZigLLVM_aarch64_be, ZigLLVM_ARMSubArch_v8_3a},67 ZigLLVM_aarch64,
68 {ZigLLVM_aarch64_be, ZigLLVM_ARMSubArch_v8_2a},68 ZigLLVM_aarch64_be,
69 {ZigLLVM_aarch64_be, ZigLLVM_ARMSubArch_v8_1a},69 ZigLLVM_arc,
70 {ZigLLVM_aarch64_be, ZigLLVM_ARMSubArch_v8},70 ZigLLVM_avr,
71 {ZigLLVM_aarch64_be, ZigLLVM_ARMSubArch_v8r},71 ZigLLVM_bpfel,
72 {ZigLLVM_aarch64_be, ZigLLVM_ARMSubArch_v8m_baseline},72 ZigLLVM_bpfeb,
73 {ZigLLVM_aarch64_be, ZigLLVM_ARMSubArch_v8m_mainline},73 ZigLLVM_hexagon,
7474 ZigLLVM_mips,
75 {ZigLLVM_arc, ZigLLVM_NoSubArch},75 ZigLLVM_mipsel,
76 {ZigLLVM_avr, ZigLLVM_NoSubArch},76 ZigLLVM_mips64,
77 {ZigLLVM_bpfel, ZigLLVM_NoSubArch},77 ZigLLVM_mips64el,
78 {ZigLLVM_bpfeb, ZigLLVM_NoSubArch},78 ZigLLVM_msp430,
79 {ZigLLVM_hexagon, ZigLLVM_NoSubArch},79 ZigLLVM_nios2,
80 {ZigLLVM_mips, ZigLLVM_NoSubArch},80 ZigLLVM_ppc,
81 {ZigLLVM_mipsel, ZigLLVM_NoSubArch},81 ZigLLVM_ppc64,
82 {ZigLLVM_mips64, ZigLLVM_NoSubArch},82 ZigLLVM_ppc64le,
83 {ZigLLVM_mips64el, ZigLLVM_NoSubArch},83 ZigLLVM_r600,
84 {ZigLLVM_msp430, ZigLLVM_NoSubArch},84 ZigLLVM_amdgcn,
85 {ZigLLVM_nios2, ZigLLVM_NoSubArch},85 ZigLLVM_riscv32,
86 {ZigLLVM_ppc, ZigLLVM_NoSubArch},86 ZigLLVM_riscv64,
87 {ZigLLVM_ppc64, ZigLLVM_NoSubArch},87 ZigLLVM_sparc,
88 {ZigLLVM_ppc64le, ZigLLVM_NoSubArch},88 ZigLLVM_sparcv9,
89 {ZigLLVM_r600, ZigLLVM_NoSubArch},89 ZigLLVM_sparcel,
90 {ZigLLVM_amdgcn, ZigLLVM_NoSubArch},90 ZigLLVM_systemz,
91 {ZigLLVM_riscv32, ZigLLVM_NoSubArch},91 ZigLLVM_tce,
92 {ZigLLVM_riscv64, ZigLLVM_NoSubArch},92 ZigLLVM_tcele,
93 {ZigLLVM_sparc, ZigLLVM_NoSubArch},93 ZigLLVM_thumb,
94 {ZigLLVM_sparcv9, ZigLLVM_NoSubArch},94 ZigLLVM_thumbeb,
95 {ZigLLVM_sparcel, ZigLLVM_NoSubArch},95 ZigLLVM_x86,
96 {ZigLLVM_systemz, ZigLLVM_NoSubArch},96 ZigLLVM_x86_64,
97 {ZigLLVM_tce, ZigLLVM_NoSubArch},97 ZigLLVM_xcore,
98 {ZigLLVM_tcele, ZigLLVM_NoSubArch},98 ZigLLVM_nvptx,
99 {ZigLLVM_thumb, ZigLLVM_NoSubArch},99 ZigLLVM_nvptx64,
100 {ZigLLVM_thumbeb, ZigLLVM_NoSubArch},100 ZigLLVM_le32,
101 {ZigLLVM_x86, ZigLLVM_NoSubArch},101 ZigLLVM_le64,
102 {ZigLLVM_x86_64, ZigLLVM_NoSubArch},102 ZigLLVM_amdil,
103 {ZigLLVM_xcore, ZigLLVM_NoSubArch},103 ZigLLVM_amdil64,
104 {ZigLLVM_nvptx, ZigLLVM_NoSubArch},104 ZigLLVM_hsail,
105 {ZigLLVM_nvptx64, ZigLLVM_NoSubArch},105 ZigLLVM_hsail64,
106 {ZigLLVM_le32, ZigLLVM_NoSubArch},106 ZigLLVM_spir,
107 {ZigLLVM_le64, ZigLLVM_NoSubArch},107 ZigLLVM_spir64,
108 {ZigLLVM_amdil, ZigLLVM_NoSubArch},108 ZigLLVM_kalimba,
109 {ZigLLVM_amdil64, ZigLLVM_NoSubArch},109 ZigLLVM_shave,
110 {ZigLLVM_hsail, ZigLLVM_NoSubArch},110 ZigLLVM_lanai,
111 {ZigLLVM_hsail64, ZigLLVM_NoSubArch},111 ZigLLVM_wasm32,
112 {ZigLLVM_spir, ZigLLVM_NoSubArch},112 ZigLLVM_wasm64,
113 {ZigLLVM_spir64, ZigLLVM_NoSubArch},113 ZigLLVM_renderscript32,
114114 ZigLLVM_renderscript64,
115 {ZigLLVM_kalimba, ZigLLVM_KalimbaSubArch_v3},
116 {ZigLLVM_kalimba, ZigLLVM_KalimbaSubArch_v4},
117 {ZigLLVM_kalimba, ZigLLVM_KalimbaSubArch_v5},
118
119 {ZigLLVM_shave, ZigLLVM_NoSubArch},
120 {ZigLLVM_lanai, ZigLLVM_NoSubArch},
121 {ZigLLVM_wasm32, ZigLLVM_NoSubArch},
122 {ZigLLVM_wasm64, ZigLLVM_NoSubArch},
123 {ZigLLVM_renderscript32, ZigLLVM_NoSubArch},
124 {ZigLLVM_renderscript64, ZigLLVM_NoSubArch},
125};115};
126116
127static const ZigLLVM_VendorType vendor_list[] = {117static const ZigLLVM_VendorType vendor_list[] = {
...@@ -179,7 +169,7 @@ static const Os os_list[] = {...@@ -179,7 +169,7 @@ static const Os os_list[] = {
179};169};
180170
181// Coordinate with zig_llvm.h171// Coordinate with zig_llvm.h
182static const ZigLLVM_EnvironmentType environ_list[] = {172static const ZigLLVM_EnvironmentType abi_list[] = {
183 ZigLLVM_UnknownEnvironment,173 ZigLLVM_UnknownEnvironment,
184174
185 ZigLLVM_GNU,175 ZigLLVM_GNU,
...@@ -214,11 +204,12 @@ size_t target_oformat_count(void) {...@@ -214,11 +204,12 @@ size_t target_oformat_count(void) {
214 return array_length(oformat_list);204 return array_length(oformat_list);
215}205}
216206
217ZigLLVM_ObjectFormatType get_target_oformat(size_t index) {207ZigLLVM_ObjectFormatType target_oformat_enum(size_t index) {
208 assert(index < array_length(oformat_list));
218 return oformat_list[index];209 return oformat_list[index];
219}210}
220211
221const char *get_target_oformat_name(ZigLLVM_ObjectFormatType oformat) {212const char *target_oformat_name(ZigLLVM_ObjectFormatType oformat) {
222 switch (oformat) {213 switch (oformat) {
223 case ZigLLVM_UnknownObjectFormat: return "unknown";214 case ZigLLVM_UnknownObjectFormat: return "unknown";
224 case ZigLLVM_COFF: return "coff";215 case ZigLLVM_COFF: return "coff";
...@@ -233,22 +224,25 @@ size_t target_arch_count(void) {...@@ -233,22 +224,25 @@ size_t target_arch_count(void) {
233 return array_length(arch_list);224 return array_length(arch_list);
234}225}
235226
236const ArchType *get_target_arch(size_t index) {227ZigLLVM_ArchType target_arch_enum(size_t index) {
237 return &arch_list[index];228 assert(index < array_length(arch_list));
229 return arch_list[index];
238}230}
239231
240size_t target_vendor_count(void) {232size_t target_vendor_count(void) {
241 return array_length(vendor_list);233 return array_length(vendor_list);
242}234}
243235
244ZigLLVM_VendorType get_target_vendor(size_t index) {236ZigLLVM_VendorType target_vendor_enum(size_t index) {
237 assert(index < array_length(vendor_list));
245 return vendor_list[index];238 return vendor_list[index];
246}239}
247240
248size_t target_os_count(void) {241size_t target_os_count(void) {
249 return array_length(os_list);242 return array_length(os_list);
250}243}
251Os get_target_os(size_t index) {244Os target_os_enum(size_t index) {
245 assert(index < array_length(os_list));
252 return os_list[index];246 return os_list[index];
253}247}
254248
...@@ -391,7 +385,7 @@ static Os get_zig_os_type(ZigLLVM_OSType os_type) {...@@ -391,7 +385,7 @@ static Os get_zig_os_type(ZigLLVM_OSType os_type) {
391 zig_unreachable();385 zig_unreachable();
392}386}
393387
394const char *get_target_os_name(Os os_type) {388const char *target_os_name(Os os_type) {
395 switch (os_type) {389 switch (os_type) {
396 case OsFreestanding:390 case OsFreestanding:
397 return "freestanding";391 return "freestanding";
...@@ -434,80 +428,251 @@ const char *get_target_os_name(Os os_type) {...@@ -434,80 +428,251 @@ const char *get_target_os_name(Os os_type) {
434 zig_unreachable();428 zig_unreachable();
435}429}
436430
437size_t target_environ_count(void) {431size_t target_abi_count(void) {
438 return array_length(environ_list);432 return array_length(abi_list);
433}
434ZigLLVM_EnvironmentType target_abi_enum(size_t index) {
435 assert(index < array_length(abi_list));
436 return abi_list[index];
439}437}
440ZigLLVM_EnvironmentType get_target_environ(size_t index) {438const char *target_abi_name(ZigLLVM_EnvironmentType abi) {
441 return environ_list[index];439 if (abi == ZigLLVM_UnknownEnvironment)
440 return "none";
441 return ZigLLVMGetEnvironmentTypeName(abi);
442}442}
443443
444void get_native_target(ZigTarget *target) {444void get_native_target(ZigTarget *target) {
445 ZigLLVM_OSType os_type;445 ZigLLVM_OSType os_type;
446 ZigLLVM_ObjectFormatType oformat; // ignored; based on arch/os446 ZigLLVM_ObjectFormatType oformat; // ignored; based on arch/os
447 ZigLLVMGetNativeTarget(447 ZigLLVMGetNativeTarget(
448 &target->arch.arch,448 &target->arch,
449 &target->arch.sub_arch,449 &target->sub_arch,
450 &target->vendor,450 &target->vendor,
451 &os_type,451 &os_type,
452 &target->env_type,452 &target->abi,
453 &oformat);453 &oformat);
454 target->os = get_zig_os_type(os_type);454 target->os = get_zig_os_type(os_type);
455 target->is_native = true;455 target->is_native = true;
456 if (target->abi == ZigLLVM_UnknownEnvironment) {
457 target->abi = target_default_abi(target->arch, target->os);
458 }
456}459}
457460
458void get_unknown_target(ZigTarget *target) {461Error target_parse_archsub(ZigLLVM_ArchType *out_arch, ZigLLVM_SubArchType *out_sub,
459 target->arch.arch = ZigLLVM_UnknownArch;462 const char *archsub_ptr, size_t archsub_len)
460 target->arch.sub_arch = ZigLLVM_NoSubArch;463{
461 target->vendor = ZigLLVM_UnknownVendor;464 for (size_t arch_i = 0; arch_i < array_length(arch_list); arch_i += 1) {
462 target->os = OsFreestanding;465 ZigLLVM_ArchType arch = arch_list[arch_i];
463 target->env_type = ZigLLVM_UnknownEnvironment;466 SubArchList sub_arch_list = target_subarch_list(arch);
464 target->is_native = false;467 size_t subarch_count = target_subarch_count(sub_arch_list);
468 if (subarch_count == 0) {
469 if (mem_eql_str(archsub_ptr, archsub_len, target_arch_name(arch))) {
470 *out_arch = arch;
471 *out_sub = ZigLLVM_NoSubArch;
472 return ErrorNone;
473 }
474 continue;
475 }
476 for (size_t sub_i = 0; sub_i < subarch_count; sub_i += 1) {
477 ZigLLVM_SubArchType sub = target_subarch_enum(sub_arch_list, sub_i);
478 char arch_name[64];
479 int n = sprintf(arch_name, "%s%s", target_arch_name(arch), target_subarch_name(sub));
480 if (mem_eql_mem(arch_name, n, archsub_ptr, archsub_len)) {
481 *out_arch = arch;
482 *out_sub = sub;
483 return ErrorNone;
484 }
485 }
486 }
487 return ErrorUnknownArchitecture;
465}488}
466489
467static void get_arch_name_raw(char *out_str, ZigLLVM_ArchType arch, ZigLLVM_SubArchType sub_arch) {490SubArchList target_subarch_list(ZigLLVM_ArchType arch) {
468 const char *sub_str = (sub_arch == ZigLLVM_NoSubArch) ? "" : ZigLLVMGetSubArchTypeName(sub_arch);491 switch (arch) {
469 sprintf(out_str, "%s%s", ZigLLVMGetArchTypeName(arch), sub_str);492 case ZigLLVM_UnknownArch:
470}493 zig_unreachable();
494 case ZigLLVM_arm:
495 case ZigLLVM_armeb:
496 case ZigLLVM_thumb:
497 case ZigLLVM_thumbeb:
498 return SubArchListArm32;
499
500 case ZigLLVM_aarch64:
501 case ZigLLVM_aarch64_be:
502 return SubArchListArm64;
503
504 case ZigLLVM_kalimba:
505 return SubArchListKalimba;
471506
472void get_arch_name(char *out_str, const ArchType *arch) {507 case ZigLLVM_arc:
473 return get_arch_name_raw(out_str, arch->arch, arch->sub_arch);508 case ZigLLVM_avr:
509 case ZigLLVM_bpfel:
510 case ZigLLVM_bpfeb:
511 case ZigLLVM_hexagon:
512 case ZigLLVM_mips:
513 case ZigLLVM_mipsel:
514 case ZigLLVM_mips64:
515 case ZigLLVM_mips64el:
516 case ZigLLVM_msp430:
517 case ZigLLVM_nios2:
518 case ZigLLVM_ppc:
519 case ZigLLVM_ppc64:
520 case ZigLLVM_ppc64le:
521 case ZigLLVM_r600:
522 case ZigLLVM_amdgcn:
523 case ZigLLVM_riscv32:
524 case ZigLLVM_riscv64:
525 case ZigLLVM_sparc:
526 case ZigLLVM_sparcv9:
527 case ZigLLVM_sparcel:
528 case ZigLLVM_systemz:
529 case ZigLLVM_tce:
530 case ZigLLVM_tcele:
531 case ZigLLVM_x86:
532 case ZigLLVM_x86_64:
533 case ZigLLVM_xcore:
534 case ZigLLVM_nvptx:
535 case ZigLLVM_nvptx64:
536 case ZigLLVM_le32:
537 case ZigLLVM_le64:
538 case ZigLLVM_amdil:
539 case ZigLLVM_amdil64:
540 case ZigLLVM_hsail:
541 case ZigLLVM_hsail64:
542 case ZigLLVM_spir:
543 case ZigLLVM_spir64:
544 case ZigLLVM_shave:
545 case ZigLLVM_lanai:
546 case ZigLLVM_wasm32:
547 case ZigLLVM_wasm64:
548 case ZigLLVM_renderscript32:
549 case ZigLLVM_renderscript64:
550 return SubArchListNone;
551 }
552 zig_unreachable();
474}553}
475554
476int parse_target_arch(const char *str, ArchType *out_arch) {555size_t target_subarch_count(SubArchList sub_arch_list) {
477 for (size_t i = 0; i < array_length(arch_list); i += 1) {556 switch (sub_arch_list) {
478 const ArchType *arch = &arch_list[i];557 case SubArchListNone:
479 char arch_name[50];
480 get_arch_name_raw(arch_name, arch->arch, arch->sub_arch);
481 if (strcmp(arch_name, str) == 0) {
482 *out_arch = *arch;
483 return 0;558 return 0;
484 }559 case SubArchListArm32:
560 return array_length(subarch_list_arm32);
561 case SubArchListArm64:
562 return array_length(subarch_list_arm64);
563 case SubArchListKalimba:
564 return array_length(subarch_list_kalimba);
565 }
566 zig_unreachable();
567}
568
569ZigLLVM_SubArchType target_subarch_enum(SubArchList sub_arch_list, size_t i) {
570 switch (sub_arch_list) {
571 case SubArchListNone:
572 zig_unreachable();
573 case SubArchListArm32:
574 assert(i < array_length(subarch_list_arm32));
575 return subarch_list_arm32[i];
576 case SubArchListArm64:
577 assert(i < array_length(subarch_list_arm64));
578 return subarch_list_arm64[i];
579 case SubArchListKalimba:
580 assert(i < array_length(subarch_list_kalimba));
581 return subarch_list_kalimba[i];
582 }
583 zig_unreachable();
584}
585
586const char *target_subarch_name(ZigLLVM_SubArchType subarch) {
587 return ZigLLVMGetSubArchTypeName(subarch);
588}
589
590size_t target_subarch_list_count(void) {
591 return array_length(subarch_list_list);
592}
593
594SubArchList target_subarch_list_enum(size_t index) {
595 assert(index < array_length(subarch_list_list));
596 return subarch_list_list[index];
597}
598
599const char *target_subarch_list_name(SubArchList sub_arch_list) {
600 switch (sub_arch_list) {
601 case SubArchListNone:
602 return "None";
603 case SubArchListArm32:
604 return "Arm32";
605 case SubArchListArm64:
606 return "Arm64";
607 case SubArchListKalimba:
608 return "Kalimba";
485 }609 }
486 return ErrorFileNotFound;610 zig_unreachable();
487}611}
488612
489int parse_target_os(const char *str, Os *out_os) {613Error target_parse_os(Os *out_os, const char *os_ptr, size_t os_len) {
490 for (size_t i = 0; i < array_length(os_list); i += 1) {614 for (size_t i = 0; i < array_length(os_list); i += 1) {
491 Os os = os_list[i];615 Os os = os_list[i];
492 const char *os_name = get_target_os_name(os);616 const char *os_name = target_os_name(os);
493 if (strcmp(os_name, str) == 0) {617 if (mem_eql_str(os_ptr, os_len, os_name)) {
494 *out_os = os;618 *out_os = os;
495 return 0;619 return ErrorNone;
496 }620 }
497 }621 }
498 return ErrorFileNotFound;622 return ErrorUnknownOperatingSystem;
499}623}
500624
501int parse_target_environ(const char *str, ZigLLVM_EnvironmentType *out_environ) {625Error target_parse_abi(ZigLLVM_EnvironmentType *out_abi, const char *abi_ptr, size_t abi_len) {
502 for (size_t i = 0; i < array_length(environ_list); i += 1) {626 for (size_t i = 0; i < array_length(abi_list); i += 1) {
503 ZigLLVM_EnvironmentType env_type = environ_list[i];627 ZigLLVM_EnvironmentType abi = abi_list[i];
504 const char *environ_name = ZigLLVMGetEnvironmentTypeName(env_type);628 const char *abi_name = target_abi_name(abi);
505 if (strcmp(environ_name, str) == 0) {629 if (mem_eql_str(abi_ptr, abi_len, abi_name)) {
506 *out_environ = env_type;630 *out_abi = abi;
507 return 0;631 return ErrorNone;
632 }
633 }
634 return ErrorUnknownABI;
635}
636
637Error target_parse_triple(ZigTarget *target, const char *triple) {
638 Error err;
639 SplitIterator it = memSplit(str(triple), str("-"));
640
641 Optional<Slice<uint8_t>> opt_archsub = SplitIterator_next(&it);
642 Optional<Slice<uint8_t>> opt_os = SplitIterator_next(&it);
643 Optional<Slice<uint8_t>> opt_abi = SplitIterator_next(&it);
644
645 if (!opt_archsub.is_some)
646 return ErrorMissingArchitecture;
647
648 if (!opt_os.is_some)
649 return ErrorMissingOperatingSystem;
650
651 if ((err = target_parse_archsub(&target->arch, &target->sub_arch,
652 (char*)opt_archsub.value.ptr, opt_archsub.value.len)))
653 {
654 return err;
655 }
656
657 if ((err = target_parse_os(&target->os, (char*)opt_os.value.ptr, opt_os.value.len))) {
658 return err;
659 }
660
661 if (opt_abi.is_some) {
662 if ((err = target_parse_abi(&target->abi, (char*)opt_abi.value.ptr, opt_abi.value.len))) {
663 return err;
508 }664 }
665 } else {
666 target->abi = target_default_abi(target->arch, target->os);
509 }667 }
510 return ErrorFileNotFound;668
669 target->vendor = ZigLLVM_UnknownVendor;
670 target->is_native = false;
671 return ErrorNone;
672}
673
674const char *target_arch_name(ZigLLVM_ArchType arch) {
675 return ZigLLVMGetArchTypeName(arch);
511}676}
512677
513void init_all_targets(void) {678void init_all_targets(void) {
...@@ -519,37 +684,21 @@ void init_all_targets(void) {...@@ -519,37 +684,21 @@ void init_all_targets(void) {
519}684}
520685
521void get_target_triple(Buf *triple, const ZigTarget *target) {686void get_target_triple(Buf *triple, const ZigTarget *target) {
522 char arch_name[50];
523 get_arch_name(arch_name, &target->arch);
524
525 buf_resize(triple, 0);687 buf_resize(triple, 0);
526688 buf_appendf(triple, "%s%s-%s-%s-%s",
527 // LLVM WebAssembly output support requires the target to be activated at689 ZigLLVMGetArchTypeName(target->arch),
528 // build type with -DCMAKE_LLVM_EXPIERMENTAL_TARGETS_TO_BUILD=WebAssembly.690 ZigLLVMGetSubArchTypeName(target->sub_arch),
529 //691 ZigLLVMGetVendorTypeName(target->vendor),
530 // LLVM determines the output format based on the environment suffix,692 ZigLLVMGetOSTypeName(get_llvm_os_type(target->os)),
531 // defaulting to an object based on the architecture. The default format in693 ZigLLVMGetEnvironmentTypeName(target->abi));
532 // LLVM 6 sets the wasm arch output incorrectly to ELF. We need to
533 // explicitly set this ourself in order for it to work.
534 //
535 // This is fixed in LLVM 7 and you will be able to get wasm output by
536 // using the target triple `wasm32-unknown-unknown-unknown`.
537 if (!strncmp(arch_name, "wasm", 4)) {
538 buf_appendf(triple, "%s-%s-%s-wasm", arch_name,
539 ZigLLVMGetVendorTypeName(target->vendor),
540 ZigLLVMGetOSTypeName(get_llvm_os_type(target->os)));
541 } else {
542 buf_appendf(triple, "%s-%s-%s-%s", arch_name,
543 ZigLLVMGetVendorTypeName(target->vendor),
544 ZigLLVMGetOSTypeName(get_llvm_os_type(target->os)),
545 ZigLLVMGetEnvironmentTypeName(target->env_type));
546 }
547}694}
548695
549bool target_is_darwin(const ZigTarget *target) {696bool target_is_darwin(const ZigTarget *target) {
550 switch (target->os) {697 switch (target->os) {
551 case OsMacOSX:698 case OsMacOSX:
552 case OsIOS:699 case OsIOS:
700 case OsWatchOS:
701 case OsTvOS:
553 return true;702 return true;
554 default:703 default:
555 return false;704 return false;
...@@ -562,8 +711,8 @@ ZigLLVM_ObjectFormatType target_object_format(const ZigTarget *target) {...@@ -562,8 +711,8 @@ ZigLLVM_ObjectFormatType target_object_format(const ZigTarget *target) {
562 } else if (target_is_darwin(target)) {711 } else if (target_is_darwin(target)) {
563 return ZigLLVM_MachO;712 return ZigLLVM_MachO;
564 }713 }
565 if (target->arch.arch == ZigLLVM_wasm32 ||714 if (target->arch == ZigLLVM_wasm32 ||
566 target->arch.arch == ZigLLVM_wasm64)715 target->arch == ZigLLVM_wasm64)
567 {716 {
568 return ZigLLVM_Wasm;717 return ZigLLVM_Wasm;
569 }718 }
...@@ -639,7 +788,7 @@ static int get_arch_pointer_bit_width(ZigLLVM_ArchType arch) {...@@ -639,7 +788,7 @@ static int get_arch_pointer_bit_width(ZigLLVM_ArchType arch) {
639uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {788uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
640 switch (target->os) {789 switch (target->os) {
641 case OsFreestanding:790 case OsFreestanding:
642 switch (target->arch.arch) {791 switch (target->arch) {
643 case ZigLLVM_msp430:792 case ZigLLVM_msp430:
644 switch (id) {793 switch (id) {
645 case CIntTypeShort:794 case CIntTypeShort:
...@@ -667,7 +816,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {...@@ -667,7 +816,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
667 return 32;816 return 32;
668 case CIntTypeLong:817 case CIntTypeLong:
669 case CIntTypeULong:818 case CIntTypeULong:
670 return get_arch_pointer_bit_width(target->arch.arch);819 return get_arch_pointer_bit_width(target->arch);
671 case CIntTypeLongLong:820 case CIntTypeLongLong:
672 case CIntTypeULongLong:821 case CIntTypeULongLong:
673 return 64;822 return 64;
...@@ -690,7 +839,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {...@@ -690,7 +839,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
690 return 32;839 return 32;
691 case CIntTypeLong:840 case CIntTypeLong:
692 case CIntTypeULong:841 case CIntTypeULong:
693 return get_arch_pointer_bit_width(target->arch.arch);842 return get_arch_pointer_bit_width(target->arch);
694 case CIntTypeLongLong:843 case CIntTypeLongLong:
695 case CIntTypeULongLong:844 case CIntTypeULongLong:
696 return 64;845 return 64;
...@@ -748,7 +897,7 @@ bool target_allows_addr_zero(const ZigTarget *target) {...@@ -748,7 +897,7 @@ bool target_allows_addr_zero(const ZigTarget *target) {
748}897}
749898
750const char *target_o_file_ext(const ZigTarget *target) {899const char *target_o_file_ext(const ZigTarget *target) {
751 if (target->env_type == ZigLLVM_MSVC || target->os == OsWindows || target->os == OsUefi) {900 if (target->abi == ZigLLVM_MSVC || target->os == OsWindows || target->os == OsUefi) {
752 return ".obj";901 return ".obj";
753 } else {902 } else {
754 return ".o";903 return ".o";
...@@ -798,7 +947,7 @@ enum FloatAbi {...@@ -798,7 +947,7 @@ enum FloatAbi {
798};947};
799948
800static FloatAbi get_float_abi(const ZigTarget *target) {949static FloatAbi get_float_abi(const ZigTarget *target) {
801 const ZigLLVM_EnvironmentType env = target->env_type;950 const ZigLLVM_EnvironmentType env = target->abi;
802 if (env == ZigLLVM_GNUEABIHF ||951 if (env == ZigLLVM_GNUEABIHF ||
803 env == ZigLLVM_EABIHF ||952 env == ZigLLVM_EABIHF ||
804 env == ZigLLVM_MuslEABIHF)953 env == ZigLLVM_MuslEABIHF)
...@@ -813,71 +962,154 @@ static bool is_64_bit(ZigLLVM_ArchType arch) {...@@ -813,71 +962,154 @@ static bool is_64_bit(ZigLLVM_ArchType arch) {
813 return get_arch_pointer_bit_width(arch) == 64;962 return get_arch_pointer_bit_width(arch) == 64;
814}963}
815964
816Buf *target_dynamic_linker(const ZigTarget *target) {965const char *target_dynamic_linker(const ZigTarget *target) {
817 if (target->os == OsFreeBSD) {966 switch (target->os) {
818 return buf_create_from_str("/libexec/ld-elf.so.1");967 case OsFreeBSD:
819 }968 return "/libexec/ld-elf.so.1";
820 if (target->os == OsNetBSD) {969 case OsNetBSD:
821 return buf_create_from_str("/libexec/ld.elf_so");970 return "/libexec/ld.elf_so";
822 }971 case OsLinux: {
972 const ZigLLVM_EnvironmentType abi = target->abi;
973 if (abi == ZigLLVM_Android) {
974 if (is_64_bit(target->arch)) {
975 return "/system/bin/linker64";
976 } else {
977 return "/system/bin/linker";
978 }
979 }
823980
824 const ZigLLVM_ArchType arch = target->arch.arch;981 switch (target->arch) {
825 const ZigLLVM_EnvironmentType env = target->env_type;982 case ZigLLVM_UnknownArch:
983 zig_unreachable();
984 case ZigLLVM_x86:
985 case ZigLLVM_sparc:
986 case ZigLLVM_sparcel:
987 return "/lib/ld-linux.so.2";
988
989 case ZigLLVM_aarch64:
990 return "/lib/ld-linux-aarch64.so.1";
991
992 case ZigLLVM_aarch64_be:
993 return "/lib/ld-linux-aarch64_be.so.1";
994
995 case ZigLLVM_arm:
996 case ZigLLVM_thumb:
997 if (get_float_abi(target) == FloatAbiHard) {
998 return "/lib/ld-linux-armhf.so.3";
999 } else {
1000 return "/lib/ld-linux.so.3";
1001 }
8261002
827 if (env == ZigLLVM_Android) {1003 case ZigLLVM_armeb:
828 if (is_64_bit(arch)) {1004 case ZigLLVM_thumbeb:
829 return buf_create_from_str("/system/bin/linker64");1005 if (get_float_abi(target) == FloatAbiHard) {
830 } else {1006 return "/lib/ld-linux-armhf.so.3";
831 return buf_create_from_str("/system/bin/linker");1007 } else {
832 }1008 return "/lib/ld-linux.so.3";
833 } else if (arch == ZigLLVM_x86 ||1009 }
834 arch == ZigLLVM_sparc ||1010
835 arch == ZigLLVM_sparcel)1011 case ZigLLVM_mips:
836 {1012 case ZigLLVM_mipsel:
837 return buf_create_from_str("/lib/ld-linux.so.2");1013 case ZigLLVM_mips64:
838 } else if (arch == ZigLLVM_aarch64) {1014 case ZigLLVM_mips64el:
839 return buf_create_from_str("/lib/ld-linux-aarch64.so.1");1015 zig_panic("TODO implement target_dynamic_linker for mips");
840 } else if (arch == ZigLLVM_aarch64_be) {1016
841 return buf_create_from_str("/lib/ld-linux-aarch64_be.so.1");1017 case ZigLLVM_ppc:
842 } else if (arch == ZigLLVM_arm || arch == ZigLLVM_thumb) {1018 return "/lib/ld.so.1";
843 if (get_float_abi(target) == FloatAbiHard) {1019
844 return buf_create_from_str("/lib/ld-linux-armhf.so.3");1020 case ZigLLVM_ppc64:
845 } else {1021 return "/lib64/ld64.so.2";
846 return buf_create_from_str("/lib/ld-linux.so.3");1022
847 }1023 case ZigLLVM_ppc64le:
848 } else if (arch == ZigLLVM_armeb || arch == ZigLLVM_thumbeb) {1024 return "/lib64/ld64.so.2";
849 if (get_float_abi(target) == FloatAbiHard) {1025
850 return buf_create_from_str("/lib/ld-linux-armhf.so.3");1026 case ZigLLVM_systemz:
851 } else {1027 return "/lib64/ld64.so.1";
852 return buf_create_from_str("/lib/ld-linux.so.3");1028
1029 case ZigLLVM_sparcv9:
1030 return "/lib64/ld-linux.so.2";
1031
1032 case ZigLLVM_x86_64:
1033 if (abi == ZigLLVM_GNUX32) {
1034 return "/libx32/ld-linux-x32.so.2";
1035 }
1036 if (abi == ZigLLVM_Musl || abi == ZigLLVM_MuslEABI || abi == ZigLLVM_MuslEABIHF) {
1037 return "/lib/ld-musl-x86_64.so.1";
1038 }
1039 return "/lib64/ld-linux-x86-64.so.2";
1040
1041 case ZigLLVM_wasm32:
1042 case ZigLLVM_wasm64:
1043 return nullptr;
1044
1045 case ZigLLVM_arc:
1046 case ZigLLVM_avr:
1047 case ZigLLVM_bpfel:
1048 case ZigLLVM_bpfeb:
1049 case ZigLLVM_hexagon:
1050 case ZigLLVM_msp430:
1051 case ZigLLVM_nios2:
1052 case ZigLLVM_r600:
1053 case ZigLLVM_amdgcn:
1054 case ZigLLVM_riscv32:
1055 case ZigLLVM_riscv64:
1056 case ZigLLVM_tce:
1057 case ZigLLVM_tcele:
1058 case ZigLLVM_xcore:
1059 case ZigLLVM_nvptx:
1060 case ZigLLVM_nvptx64:
1061 case ZigLLVM_le32:
1062 case ZigLLVM_le64:
1063 case ZigLLVM_amdil:
1064 case ZigLLVM_amdil64:
1065 case ZigLLVM_hsail:
1066 case ZigLLVM_hsail64:
1067 case ZigLLVM_spir:
1068 case ZigLLVM_spir64:
1069 case ZigLLVM_kalimba:
1070 case ZigLLVM_shave:
1071 case ZigLLVM_lanai:
1072 case ZigLLVM_renderscript32:
1073 case ZigLLVM_renderscript64:
1074 zig_panic("TODO implement target_dynamic_linker for this arch");
1075 }
1076 zig_unreachable();
853 }1077 }
854 } else if (arch == ZigLLVM_mips || arch == ZigLLVM_mipsel ||1078 case OsFreestanding:
855 arch == ZigLLVM_mips64 || arch == ZigLLVM_mips64el)1079 case OsIOS:
856 {1080 case OsTvOS:
857 // when you want to solve this TODO, grep clang codebase for1081 case OsWatchOS:
858 // getLinuxDynamicLinker1082 case OsMacOSX:
859 zig_panic("TODO figure out MIPS dynamic linker name");1083 return nullptr;
860 } else if (arch == ZigLLVM_ppc) {1084
861 return buf_create_from_str("/lib/ld.so.1");1085 case OsAnanas:
862 } else if (arch == ZigLLVM_ppc64) {1086 case OsCloudABI:
863 return buf_create_from_str("/lib64/ld64.so.2");1087 case OsDragonFly:
864 } else if (arch == ZigLLVM_ppc64le) {1088 case OsFuchsia:
865 return buf_create_from_str("/lib64/ld64.so.2");1089 case OsKFreeBSD:
866 } else if (arch == ZigLLVM_systemz) {1090 case OsLv2:
867 return buf_create_from_str("/lib64/ld64.so.1");1091 case OsOpenBSD:
868 } else if (arch == ZigLLVM_sparcv9) {1092 case OsSolaris:
869 return buf_create_from_str("/lib64/ld-linux.so.2");1093 case OsWindows:
870 } else if (arch == ZigLLVM_x86_64 &&1094 case OsHaiku:
871 env == ZigLLVM_GNUX32)1095 case OsMinix:
872 {1096 case OsRTEMS:
873 return buf_create_from_str("/libx32/ld-linux-x32.so.2");1097 case OsNaCl:
874 } else if (arch == ZigLLVM_x86_64 &&1098 case OsCNK:
875 (env == ZigLLVM_Musl || env == ZigLLVM_MuslEABI || env == ZigLLVM_MuslEABIHF))1099 case OsAIX:
876 {1100 case OsCUDA:
877 return buf_create_from_str("/lib/ld-musl-x86_64.so.1");1101 case OsNVCL:
878 } else {1102 case OsAMDHSA:
879 return buf_create_from_str("/lib64/ld-linux-x86-64.so.2");1103 case OsPS4:
1104 case OsELFIAMCU:
1105 case OsMesa3D:
1106 case OsContiki:
1107 case OsAMDPAL:
1108 case OsZen:
1109 case OsUefi:
1110 zig_panic("TODO implement target_dynamic_linker for this OS");
880 }1111 }
1112 zig_unreachable();
881}1113}
8821114
883bool target_can_exec(const ZigTarget *host_target, const ZigTarget *guest_target) {1115bool target_can_exec(const ZigTarget *host_target, const ZigTarget *guest_target) {
...@@ -888,15 +1120,15 @@ bool target_can_exec(const ZigTarget *host_target, const ZigTarget *guest_target...@@ -888,15 +1120,15 @@ bool target_can_exec(const ZigTarget *host_target, const ZigTarget *guest_target
888 return true;1120 return true;
889 }1121 }
8901122
891 if (guest_target->os == host_target->os && guest_target->arch.arch == host_target->arch.arch &&1123 if (guest_target->os == host_target->os && guest_target->arch == host_target->arch &&
892 guest_target->arch.sub_arch == host_target->arch.sub_arch)1124 guest_target->sub_arch == host_target->sub_arch)
893 {1125 {
894 // OS, arch, and sub-arch match1126 // OS, arch, and sub-arch match
895 return true;1127 return true;
896 }1128 }
8971129
898 if (guest_target->os == OsWindows && host_target->os == OsWindows &&1130 if (guest_target->os == OsWindows && host_target->os == OsWindows &&
899 host_target->arch.arch == ZigLLVM_x86_64 && guest_target->arch.arch == ZigLLVM_x86)1131 host_target->arch == ZigLLVM_x86_64 && guest_target->arch == ZigLLVM_x86)
900 {1132 {
901 // 64-bit windows can run 32-bit programs1133 // 64-bit windows can run 32-bit programs
902 return true;1134 return true;
...@@ -905,8 +1137,8 @@ bool target_can_exec(const ZigTarget *host_target, const ZigTarget *guest_target...@@ -905,8 +1137,8 @@ bool target_can_exec(const ZigTarget *host_target, const ZigTarget *guest_target
905 return false;1137 return false;
906}1138}
9071139
908const char *arch_stack_pointer_register_name(const ArchType *arch) {1140const char *arch_stack_pointer_register_name(ZigLLVM_ArchType arch) {
909 switch (arch->arch) {1141 switch (arch) {
910 case ZigLLVM_UnknownArch:1142 case ZigLLVM_UnknownArch:
911 zig_unreachable();1143 zig_unreachable();
912 case ZigLLVM_x86:1144 case ZigLLVM_x86:
...@@ -969,7 +1201,7 @@ const char *arch_stack_pointer_register_name(const ArchType *arch) {...@@ -969,7 +1201,7 @@ const char *arch_stack_pointer_register_name(const ArchType *arch) {
969}1201}
9701202
971bool target_is_arm(const ZigTarget *target) {1203bool target_is_arm(const ZigTarget *target) {
972 switch (target->arch.arch) {1204 switch (target->arch) {
973 case ZigLLVM_UnknownArch:1205 case ZigLLVM_UnknownArch:
974 zig_unreachable();1206 zig_unreachable();
975 case ZigLLVM_aarch64:1207 case ZigLLVM_aarch64:
...@@ -1031,12 +1263,12 @@ bool target_is_arm(const ZigTarget *target) {...@@ -1031,12 +1263,12 @@ bool target_is_arm(const ZigTarget *target) {
10311263
1032// Valgrind supports more, but Zig does not support them yet.1264// Valgrind supports more, but Zig does not support them yet.
1033bool target_has_valgrind_support(const ZigTarget *target) {1265bool target_has_valgrind_support(const ZigTarget *target) {
1034 switch (target->arch.arch) {1266 switch (target->arch) {
1035 case ZigLLVM_UnknownArch:1267 case ZigLLVM_UnknownArch:
1036 zig_unreachable();1268 zig_unreachable();
1037 case ZigLLVM_x86_64:1269 case ZigLLVM_x86_64:
1038 return (target->os == OsLinux || target_is_darwin(target) || target->os == OsSolaris ||1270 return (target->os == OsLinux || target_is_darwin(target) || target->os == OsSolaris ||
1039 (target->os == OsWindows && target->env_type != ZigLLVM_MSVC));1271 (target->os == OsWindows && target->abi != ZigLLVM_MSVC));
1040 default:1272 default:
1041 return false;1273 return false;
1042 }1274 }
...@@ -1055,3 +1287,46 @@ bool target_supports_fpic(const ZigTarget *target) {...@@ -1055,3 +1287,46 @@ bool target_supports_fpic(const ZigTarget *target) {
1055 // C compiler argument is valid.1287 // C compiler argument is valid.
1056 return target->os != OsWindows;1288 return target->os != OsWindows;
1057}1289}
1290
1291ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) {
1292 switch (os) {
1293 case OsFreestanding:
1294 case OsAnanas:
1295 case OsCloudABI:
1296 case OsDragonFly:
1297 case OsLv2:
1298 case OsSolaris:
1299 case OsHaiku:
1300 case OsMinix:
1301 case OsRTEMS:
1302 case OsNaCl:
1303 case OsCNK:
1304 case OsAIX:
1305 case OsCUDA:
1306 case OsNVCL:
1307 case OsAMDHSA:
1308 case OsPS4:
1309 case OsELFIAMCU:
1310 case OsMesa3D:
1311 case OsContiki:
1312 case OsAMDPAL:
1313 case OsZen:
1314 return ZigLLVM_EABI;
1315 case OsOpenBSD:
1316 case OsMacOSX:
1317 case OsFreeBSD:
1318 case OsIOS:
1319 case OsTvOS:
1320 case OsWatchOS:
1321 case OsFuchsia:
1322 case OsKFreeBSD:
1323 case OsNetBSD:
1324 return ZigLLVM_GNU;
1325 case OsWindows:
1326 case OsUefi:
1327 return ZigLLVM_MSVC;
1328 case OsLinux:
1329 return ZigLLVM_Musl;
1330 }
1331 zig_unreachable();
1332}
src/target.hpp+40-25
...@@ -12,11 +12,6 @@...@@ -12,11 +12,6 @@
1212
13struct Buf;13struct Buf;
1414
15struct ArchType {
16 ZigLLVM_ArchType arch;
17 ZigLLVM_SubArchType sub_arch;
18};
19
20// Synchronize with target.cpp::os_list15// Synchronize with target.cpp::os_list
21enum Os {16enum Os {
22 OsFreestanding,17 OsFreestanding,
...@@ -54,6 +49,14 @@ enum Os {...@@ -54,6 +49,14 @@ enum Os {
54 OsUefi,49 OsUefi,
55};50};
5651
52// Synchronize with target.cpp::subarch_list_list
53enum SubArchList {
54 SubArchListNone,
55 SubArchListArm32,
56 SubArchListArm64,
57 SubArchListKalimba,
58};
59
57enum TargetSubsystem {60enum TargetSubsystem {
58 TargetSubsystemAuto, // Zig should infer the subsystem61 TargetSubsystemAuto, // Zig should infer the subsystem
59 TargetSubsystemConsole,62 TargetSubsystemConsole,
...@@ -67,10 +70,11 @@ enum TargetSubsystem {...@@ -67,10 +70,11 @@ enum TargetSubsystem {
67};70};
6871
69struct ZigTarget {72struct ZigTarget {
70 ArchType arch;73 ZigLLVM_ArchType arch;
74 ZigLLVM_SubArchType sub_arch;
71 ZigLLVM_VendorType vendor;75 ZigLLVM_VendorType vendor;
72 Os os;76 Os os;
73 ZigLLVM_EnvironmentType env_type;77 ZigLLVM_EnvironmentType abi;
74 bool is_native;78 bool is_native;
75};79};
7680
...@@ -87,39 +91,50 @@ enum CIntType {...@@ -87,39 +91,50 @@ enum CIntType {
87 CIntTypeCount,91 CIntTypeCount,
88};92};
8993
94Error target_parse_triple(ZigTarget *target, const char *triple);
95Error target_parse_archsub(ZigLLVM_ArchType *arch, ZigLLVM_SubArchType *sub,
96 const char *archsub_ptr, size_t archsub_len);
97Error target_parse_os(Os *os, const char *os_ptr, size_t os_len);
98Error target_parse_abi(ZigLLVM_EnvironmentType *abi, const char *abi_ptr, size_t abi_len);
99
90size_t target_arch_count(void);100size_t target_arch_count(void);
91const ArchType *get_target_arch(size_t index);101ZigLLVM_ArchType target_arch_enum(size_t index);
92void get_arch_name(char *out_str, const ArchType *arch);102const char *target_arch_name(ZigLLVM_ArchType arch);
103
104SubArchList target_subarch_list(ZigLLVM_ArchType arch);
105size_t target_subarch_count(SubArchList sub_arch_list);
106ZigLLVM_SubArchType target_subarch_enum(SubArchList subarch_list, size_t index);
107const char *target_subarch_name(ZigLLVM_SubArchType subarch);
93108
94const char *arch_stack_pointer_register_name(const ArchType *arch);109size_t target_subarch_list_count(void);
110SubArchList target_subarch_list_enum(size_t index);
111const char *target_subarch_list_name(SubArchList sub_arch_list);
112
113const char *arch_stack_pointer_register_name(ZigLLVM_ArchType arch);
95114
96size_t target_vendor_count(void);115size_t target_vendor_count(void);
97ZigLLVM_VendorType get_target_vendor(size_t index);116ZigLLVM_VendorType target_vendor_enum(size_t index);
98117
99size_t target_os_count(void);118size_t target_os_count(void);
100Os get_target_os(size_t index);119Os target_os_enum(size_t index);
101const char *get_target_os_name(Os os_type);120const char *target_os_name(Os os_type);
102121
103size_t target_environ_count(void);122size_t target_abi_count(void);
104ZigLLVM_EnvironmentType get_target_environ(size_t index);123ZigLLVM_EnvironmentType target_abi_enum(size_t index);
124const char *target_abi_name(ZigLLVM_EnvironmentType abi);
125ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os);
105126
106127
107size_t target_oformat_count(void);128size_t target_oformat_count(void);
108ZigLLVM_ObjectFormatType get_target_oformat(size_t index);129ZigLLVM_ObjectFormatType target_oformat_enum(size_t index);
109const char *get_target_oformat_name(ZigLLVM_ObjectFormatType oformat);130const char *target_oformat_name(ZigLLVM_ObjectFormatType oformat);
110ZigLLVM_ObjectFormatType target_object_format(const ZigTarget *target);131ZigLLVM_ObjectFormatType target_object_format(const ZigTarget *target);
111132
112void get_native_target(ZigTarget *target);133void get_native_target(ZigTarget *target);
113void get_unknown_target(ZigTarget *target);134void get_target_triple(Buf *triple, const ZigTarget *target);
114
115int parse_target_arch(const char *str, ArchType *arch);
116int parse_target_os(const char *str, Os *os);
117int parse_target_environ(const char *str, ZigLLVM_EnvironmentType *env_type);
118135
119void init_all_targets(void);136void init_all_targets(void);
120137
121void get_target_triple(Buf *triple, const ZigTarget *target);
122
123void resolve_target_object_format(ZigTarget *target);138void resolve_target_object_format(ZigTarget *target);
124139
125uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id);140uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id);
...@@ -131,7 +146,7 @@ const char *target_exe_file_ext(const ZigTarget *target);...@@ -131,7 +146,7 @@ const char *target_exe_file_ext(const ZigTarget *target);
131const char *target_lib_file_ext(const ZigTarget *target, bool is_static,146const char *target_lib_file_ext(const ZigTarget *target, bool is_static,
132 size_t version_major, size_t version_minor, size_t version_patch);147 size_t version_major, size_t version_minor, size_t version_patch);
133148
134Buf *target_dynamic_linker(const ZigTarget *target);149const char *target_dynamic_linker(const ZigTarget *target);
135150
136bool target_can_exec(const ZigTarget *host_target, const ZigTarget *guest_target);151bool target_can_exec(const ZigTarget *host_target, const ZigTarget *guest_target);
137ZigLLVM_OSType get_llvm_os_type(Os os_type);152ZigLLVM_OSType get_llvm_os_type(Os os_type);
src/util.hpp+7-4
...@@ -147,11 +147,14 @@ static inline T clamp(T min_value, T value, T max_value) {...@@ -147,11 +147,14 @@ static inline T clamp(T min_value, T value, T max_value) {
147 return max(min(value, max_value), min_value);147 return max(min(value, max_value), min_value);
148}148}
149149
150static inline bool mem_eql_str(const char *mem, size_t mem_len, const char *str) {150static inline bool mem_eql_mem(const char *a_ptr, size_t a_len, const char *b_ptr, size_t b_len) {
151 size_t str_len = strlen(str);151 if (a_len != b_len)
152 if (str_len != mem_len)
153 return false;152 return false;
154 return memcmp(mem, str, mem_len) == 0;153 return memcmp(a_ptr, b_ptr, a_len) == 0;
154}
155
156static inline bool mem_eql_str(const char *mem, size_t mem_len, const char *str) {
157 return mem_eql_mem(mem, mem_len, str, strlen(str));
155}158}
156159
157static inline bool is_power_of_2(uint64_t x) {160static inline bool is_power_of_2(uint64_t x) {
src/zig_llvm.cpp+1-1
...@@ -730,7 +730,7 @@ void ZigLLVMGetNativeTarget(ZigLLVM_ArchType *arch_type, ZigLLVM_SubArchType *su...@@ -730,7 +730,7 @@ void ZigLLVMGetNativeTarget(ZigLLVM_ArchType *arch_type, ZigLLVM_SubArchType *su
730const char *ZigLLVMGetSubArchTypeName(ZigLLVM_SubArchType sub_arch) {730const char *ZigLLVMGetSubArchTypeName(ZigLLVM_SubArchType sub_arch) {
731 switch (sub_arch) {731 switch (sub_arch) {
732 case ZigLLVM_NoSubArch:732 case ZigLLVM_NoSubArch:
733 return "(none)";733 return "";
734 case ZigLLVM_ARMSubArch_v8_4a:734 case ZigLLVM_ARMSubArch_v8_4a:
735 return "v8_4a";735 return "v8_4a";
736 case ZigLLVM_ARMSubArch_v8_3a:736 case ZigLLVM_ARMSubArch_v8_3a:
src/zig_llvm.h+3-2
...@@ -215,7 +215,7 @@ ZIG_EXTERN_C void ZigLLVMParseCommandLineOptions(size_t argc, const char *const...@@ -215,7 +215,7 @@ ZIG_EXTERN_C void ZigLLVMParseCommandLineOptions(size_t argc, const char *const
215215
216216
217// copied from include/llvm/ADT/Triple.h217// copied from include/llvm/ADT/Triple.h
218218// synchronize with target.cpp::arch_list
219enum ZigLLVM_ArchType {219enum ZigLLVM_ArchType {
220 ZigLLVM_UnknownArch,220 ZigLLVM_UnknownArch,
221221
...@@ -273,6 +273,7 @@ enum ZigLLVM_ArchType {...@@ -273,6 +273,7 @@ enum ZigLLVM_ArchType {
273 ZigLLVM_LastArchType = ZigLLVM_renderscript64273 ZigLLVM_LastArchType = ZigLLVM_renderscript64
274};274};
275275
276// synchronize with lists in target.cpp
276enum ZigLLVM_SubArchType {277enum ZigLLVM_SubArchType {
277 ZigLLVM_NoSubArch,278 ZigLLVM_NoSubArch,
278279
...@@ -404,7 +405,7 @@ ZIG_EXTERN_C const char *ZigLLVMGetArchTypeName(enum ZigLLVM_ArchType arch);...@@ -404,7 +405,7 @@ ZIG_EXTERN_C const char *ZigLLVMGetArchTypeName(enum ZigLLVM_ArchType arch);
404ZIG_EXTERN_C const char *ZigLLVMGetSubArchTypeName(enum ZigLLVM_SubArchType sub_arch);405ZIG_EXTERN_C const char *ZigLLVMGetSubArchTypeName(enum ZigLLVM_SubArchType sub_arch);
405ZIG_EXTERN_C const char *ZigLLVMGetVendorTypeName(enum ZigLLVM_VendorType vendor);406ZIG_EXTERN_C const char *ZigLLVMGetVendorTypeName(enum ZigLLVM_VendorType vendor);
406ZIG_EXTERN_C const char *ZigLLVMGetOSTypeName(enum ZigLLVM_OSType os);407ZIG_EXTERN_C const char *ZigLLVMGetOSTypeName(enum ZigLLVM_OSType os);
407ZIG_EXTERN_C const char *ZigLLVMGetEnvironmentTypeName(enum ZigLLVM_EnvironmentType env_type);408ZIG_EXTERN_C const char *ZigLLVMGetEnvironmentTypeName(enum ZigLLVM_EnvironmentType abi);
408409
409ZIG_EXTERN_C bool ZigLLDLink(enum ZigLLVM_ObjectFormatType oformat, const char **args, size_t arg_count,410ZIG_EXTERN_C bool ZigLLDLink(enum ZigLLVM_ObjectFormatType oformat, const char **args, size_t arg_count,
410 void (*append_diagnostic)(void *, const char *, size_t), void *context);411 void (*append_diagnostic)(void *, const char *, size_t), void *context);
std/build.zig+43-16
...@@ -731,20 +731,40 @@ const Version = struct {...@@ -731,20 +731,40 @@ const Version = struct {
731const CrossTarget = struct {731const CrossTarget = struct {
732 arch: builtin.Arch,732 arch: builtin.Arch,
733 os: builtin.Os,733 os: builtin.Os,
734 environ: builtin.Environ,734 abi: builtin.Abi,
735};735};
736736
737pub const Target = union(enum) {737pub const Target = union(enum) {
738 Native: void,738 Native: void,
739 Cross: CrossTarget,739 Cross: CrossTarget,
740740
741 fn archSubArchName(arch: builtin.Arch) []const u8 {
742 return switch (arch) {
743 builtin.Arch.arm => |sub| @tagName(sub),
744 builtin.Arch.armeb => |sub| @tagName(sub),
745 builtin.Arch.thumb => |sub| @tagName(sub),
746 builtin.Arch.thumbeb => |sub| @tagName(sub),
747 builtin.Arch.aarch64 => |sub| @tagName(sub),
748 builtin.Arch.aarch64_be => |sub| @tagName(sub),
749 builtin.Arch.kalimba => |sub| @tagName(sub),
750 else => "",
751 };
752 }
753
754 pub fn subArchName(self: Target) []const u8 {
755 switch (self) {
756 Target.Native => return archSubArchName(builtin.arch),
757 Target.Cross => |cross| return archSubArchName(cross.arch),
758 }
759 }
760
741 pub fn oFileExt(self: *const Target) []const u8 {761 pub fn oFileExt(self: *const Target) []const u8 {
742 const environ = switch (self.*) {762 const abi = switch (self.*) {
743 Target.Native => builtin.environ,763 Target.Native => builtin.abi,
744 Target.Cross => |t| t.environ,764 Target.Cross => |t| t.abi,
745 };765 };
746 return switch (environ) {766 return switch (abi) {
747 builtin.Environ.msvc => ".obj",767 builtin.Abi.msvc => ".obj",
748 else => ".o",768 else => ".o",
749 };769 };
750 }770 }
...@@ -978,12 +998,17 @@ pub const LibExeObjStep = struct {...@@ -978,12 +998,17 @@ pub const LibExeObjStep = struct {
978 }998 }
979 }999 }
9801000
981 pub fn setTarget(self: *LibExeObjStep, target_arch: builtin.Arch, target_os: builtin.Os, target_environ: builtin.Environ) void {1001 pub fn setTarget(
1002 self: *LibExeObjStep,
1003 target_arch: builtin.Arch,
1004 target_os: builtin.Os,
1005 target_abi: builtin.Abi,
1006 ) void {
982 self.target = Target{1007 self.target = Target{
983 .Cross = CrossTarget{1008 .Cross = CrossTarget{
984 .arch = target_arch,1009 .arch = target_arch,
985 .os = target_os,1010 .os = target_os,
986 .environ = target_environ,1011 .abi = target_abi,
987 },1012 },
988 };1013 };
989 self.computeOutFileNames();1014 self.computeOutFileNames();
...@@ -1296,14 +1321,16 @@ pub const LibExeObjStep = struct {...@@ -1296,14 +1321,16 @@ pub const LibExeObjStep = struct {
1296 switch (self.target) {1321 switch (self.target) {
1297 Target.Native => {},1322 Target.Native => {},
1298 Target.Cross => |cross_target| {1323 Target.Cross => |cross_target| {
1299 zig_args.append("--target-arch") catch unreachable;1324 const triple = builder.fmt(
1300 zig_args.append(@tagName(cross_target.arch)) catch unreachable;1325 "{}{}-{}-{}",
13011326 @tagName(cross_target.arch),
1302 zig_args.append("--target-os") catch unreachable;1327 Target.archSubArchName(cross_target.arch),
1303 zig_args.append(@tagName(cross_target.os)) catch unreachable;1328 @tagName(cross_target.os),
13041329 @tagName(cross_target.abi),
1305 zig_args.append("--target-environ") catch unreachable;1330 );
1306 zig_args.append(@tagName(cross_target.environ)) catch unreachable;1331
1332 try zig_args.append("-target");
1333 try zig_args.append(triple);
1307 },1334 },
1308 }1335 }
13091336
std/fmt/index.zig+1-1
...@@ -1118,7 +1118,7 @@ test "fmt.format" {...@@ -1118,7 +1118,7 @@ test "fmt.format" {
1118 const result = try bufPrint(buf1[0..], "f64: {}\n", math.nan_f64);1118 const result = try bufPrint(buf1[0..], "f64: {}\n", math.nan_f64);
1119 testing.expect(mem.eql(u8, result, "f64: nan\n"));1119 testing.expect(mem.eql(u8, result, "f64: nan\n"));
1120 }1120 }
1121 if (builtin.arch != builtin.Arch.armv8) {1121 if (builtin.arch != builtin.Arch.arm) {
1122 // negative nan is not defined by IEE 754,1122 // negative nan is not defined by IEE 754,
1123 // and ARM thus normalizes it to positive nan1123 // and ARM thus normalizes it to positive nan
1124 var buf1: [32]u8 = undefined;1124 var buf1: [32]u8 = undefined;
std/os/linux/index.zig+1-1
...@@ -6,7 +6,7 @@ const vdso = @import("vdso.zig");...@@ -6,7 +6,7 @@ const vdso = @import("vdso.zig");
6pub use switch (builtin.arch) {6pub use switch (builtin.arch) {
7 builtin.Arch.x86_64 => @import("x86_64.zig"),7 builtin.Arch.x86_64 => @import("x86_64.zig"),
8 builtin.Arch.i386 => @import("i386.zig"),8 builtin.Arch.i386 => @import("i386.zig"),
9 builtin.Arch.aarch64v8 => @import("arm64.zig"),9 builtin.Arch.aarch64 => @import("arm64.zig"),
10 else => @compileError("unsupported arch"),10 else => @compileError("unsupported arch"),
11};11};
12pub use @import("errno.zig");12pub use @import("errno.zig");
std/special/bootstrap.zig+1-1
...@@ -31,7 +31,7 @@ nakedcc fn _start() noreturn {...@@ -31,7 +31,7 @@ nakedcc fn _start() noreturn {
31 : [argc] "=r" (-> [*]usize)31 : [argc] "=r" (-> [*]usize)
32 );32 );
33 },33 },
34 builtin.Arch.aarch64v8 => {34 builtin.Arch.aarch64, builtin.Arch.aarch64_be => {
35 argc_ptr = asm ("mov %[argc], sp"35 argc_ptr = asm ("mov %[argc], sp"
36 : [argc] "=r" (-> [*]usize)36 : [argc] "=r" (-> [*]usize)
37 );37 );
std/special/compiler_rt/index.zig+4-54
...@@ -184,60 +184,10 @@ const is_arm_64 = switch (builtin.arch) {...@@ -184,60 +184,10 @@ const is_arm_64 = switch (builtin.arch) {
184};184};
185185
186const is_arm_arch = switch (builtin.arch) {186const is_arm_arch = switch (builtin.arch) {
187 builtin.Arch.armv8_3a,187 builtin.Arch.arm,
188 builtin.Arch.armv8_2a,188 builtin.Arch.armeb,
189 builtin.Arch.armv8_1a,189 builtin.Arch.aarch64,
190 builtin.Arch.armv8,190 builtin.Arch.aarch64_be,
191 builtin.Arch.armv8r,
192 builtin.Arch.armv8m_baseline,
193 builtin.Arch.armv8m_mainline,
194 builtin.Arch.armv7,
195 builtin.Arch.armv7em,
196 builtin.Arch.armv7m,
197 builtin.Arch.armv7s,
198 builtin.Arch.armv7k,
199 builtin.Arch.armv7ve,
200 builtin.Arch.armv6,
201 builtin.Arch.armv6m,
202 builtin.Arch.armv6k,
203 builtin.Arch.armv6t2,
204 builtin.Arch.armv5,
205 builtin.Arch.armv5te,
206 builtin.Arch.armv4t,
207 builtin.Arch.armebv8_3a,
208 builtin.Arch.armebv8_2a,
209 builtin.Arch.armebv8_1a,
210 builtin.Arch.armebv8,
211 builtin.Arch.armebv8r,
212 builtin.Arch.armebv8m_baseline,
213 builtin.Arch.armebv8m_mainline,
214 builtin.Arch.armebv7,
215 builtin.Arch.armebv7em,
216 builtin.Arch.armebv7m,
217 builtin.Arch.armebv7s,
218 builtin.Arch.armebv7k,
219 builtin.Arch.armebv7ve,
220 builtin.Arch.armebv6,
221 builtin.Arch.armebv6m,
222 builtin.Arch.armebv6k,
223 builtin.Arch.armebv6t2,
224 builtin.Arch.armebv5,
225 builtin.Arch.armebv5te,
226 builtin.Arch.armebv4t,
227 builtin.Arch.aarch64v8_3a,
228 builtin.Arch.aarch64v8_2a,
229 builtin.Arch.aarch64v8_1a,
230 builtin.Arch.aarch64v8,
231 builtin.Arch.aarch64v8r,
232 builtin.Arch.aarch64v8m_baseline,
233 builtin.Arch.aarch64v8m_mainline,
234 builtin.Arch.aarch64_bev8_3a,
235 builtin.Arch.aarch64_bev8_2a,
236 builtin.Arch.aarch64_bev8_1a,
237 builtin.Arch.aarch64_bev8,
238 builtin.Arch.aarch64_bev8r,
239 builtin.Arch.aarch64_bev8m_baseline,
240 builtin.Arch.aarch64_bev8m_mainline,
241 builtin.Arch.thumb,191 builtin.Arch.thumb,
242 builtin.Arch.thumbeb,192 builtin.Arch.thumbeb,
243 => true,193 => true,
test/tests.zig+5-5
...@@ -24,24 +24,24 @@ const gen_h = @import("gen_h.zig");...@@ -24,24 +24,24 @@ const gen_h = @import("gen_h.zig");
24const TestTarget = struct {24const TestTarget = struct {
25 os: builtin.Os,25 os: builtin.Os,
26 arch: builtin.Arch,26 arch: builtin.Arch,
27 environ: builtin.Environ,27 abi: builtin.Abi,
28};28};
2929
30const test_targets = []TestTarget{30const test_targets = []TestTarget{
31 TestTarget{31 TestTarget{
32 .os = builtin.Os.linux,32 .os = builtin.Os.linux,
33 .arch = builtin.Arch.x86_64,33 .arch = builtin.Arch.x86_64,
34 .environ = builtin.Environ.gnu,34 .abi = builtin.Abi.gnu,
35 },35 },
36 TestTarget{36 TestTarget{
37 .os = builtin.Os.macosx,37 .os = builtin.Os.macosx,
38 .arch = builtin.Arch.x86_64,38 .arch = builtin.Arch.x86_64,
39 .environ = builtin.Environ.unknown,39 .abi = builtin.Abi.gnu,
40 },40 },
41 TestTarget{41 TestTarget{
42 .os = builtin.Os.windows,42 .os = builtin.Os.windows,
43 .arch = builtin.Arch.x86_64,43 .arch = builtin.Arch.x86_64,
44 .environ = builtin.Environ.msvc,44 .abi = builtin.Abi.msvc,
45 },45 },
46};46};
4747
...@@ -189,7 +189,7 @@ pub fn addPkgTests(b: *build.Builder, test_filter: ?[]const u8, root_src: []cons...@@ -189,7 +189,7 @@ pub fn addPkgTests(b: *build.Builder, test_filter: ?[]const u8, root_src: []cons
189 these_tests.setFilter(test_filter);189 these_tests.setFilter(test_filter);
190 these_tests.setBuildMode(mode);190 these_tests.setBuildMode(mode);
191 if (!is_native) {191 if (!is_native) {
192 these_tests.setTarget(test_target.arch, test_target.os, test_target.environ);192 these_tests.setTarget(test_target.arch, test_target.os, test_target.abi);
193 }193 }
194 if (link_libc) {194 if (link_libc) {
195 these_tests.linkSystemLibrary("c");195 these_tests.linkSystemLibrary("c");