| author | |
| committer | |
| log | f3dd9bbdaca5ba3735feb405a890a4646905533a |
| tree | e9fb7bec1a4323375dde4a205d1b71b322c719bc |
| parent | bf82929557f0b116979261c522c62cf6393a08f2 |
| signature |
7 files changed, 135 insertions(+), 67 deletions(-)
BRANCH_TODO+2-8| ... | ... | @@ -1,12 +1,8 @@ |
| 1 | 1 | Finish these thigns before merging teh branch |
| 2 | 2 | |
| 3 | * it gets the wrong answers with `-target-feature -sse,-avx` | |
| 4 | ||
| 3 | * zig targets | |
| 4 | - use non-reflection based cpu detection? | |
| 5 | 5 | * finish refactoring target/arch/* |
| 6 | * `zig builtin` integration | |
| 7 | * move target details to better location | |
| 8 | * +foo,-bar vs foo,bar | |
| 9 | * baseline features | |
| 10 | 6 | |
| 11 | 7 | |
| 12 | 8 | const riscv32_default_features: []*const std.target.Feature = &[_]*const std.target.Feature{ |
| ... | ... | @@ -38,5 +34,3 @@ const i386_default_features_freestanding: []*const std.target.Feature = &[_]*con |
| 38 | 34 | &std.target.x86.feature_slowUnalignedMem16, |
| 39 | 35 | &std.target.x86.feature_x87, |
| 40 | 36 | }; |
| 41 | ||
| 42 |
lib/std/builtin.zig+2-2| ... | ... | @@ -18,8 +18,8 @@ pub const ObjectFormat = std.Target.ObjectFormat; |
| 18 | 18 | /// Deprecated: use `std.Target.SubSystem`. |
| 19 | 19 | pub const SubSystem = std.Target.SubSystem; |
| 20 | 20 | |
| 21 | /// Deprecated: use `std.Target.Cross.CpuFeatures`. | |
| 22 | pub const CpuFeatures = std.Target.Cross.CpuFeatures; | |
| 21 | /// Deprecated: use `std.Target.CpuFeatures`. | |
| 22 | pub const CpuFeatures = std.Target.CpuFeatures; | |
| 23 | 23 | |
| 24 | 24 | /// Deprecated: use `std.Target.Cpu`. |
| 25 | 25 | pub const Cpu = std.Target.Cpu; |
lib/std/target.zig+18-11| ... | ... | @@ -569,18 +569,18 @@ pub const Target = union(enum) { |
| 569 | 569 | os: Os, |
| 570 | 570 | abi: Abi, |
| 571 | 571 | cpu_features: CpuFeatures = .baseline, |
| 572 | }; | |
| 572 | 573 | |
| 573 | pub const CpuFeatures = union(enum) { | |
| 574 | /// The "default" set of CPU features for cross-compiling. A conservative set | |
| 575 | /// of features that is expected to be supported on most available hardware. | |
| 576 | baseline, | |
| 574 | pub const CpuFeatures = union(enum) { | |
| 575 | /// The "default" set of CPU features for cross-compiling. A conservative set | |
| 576 | /// of features that is expected to be supported on most available hardware. | |
| 577 | baseline, | |
| 577 | 578 | |
| 578 | /// Target one specific CPU. | |
| 579 | cpu: *const Cpu, | |
| 579 | /// Target one specific CPU. | |
| 580 | cpu: *const Cpu, | |
| 580 | 581 | |
| 581 | /// Explicitly provide the entire CPU feature set. | |
| 582 | features: Cpu.Feature.Set, | |
| 583 | }; | |
| 582 | /// Explicitly provide the entire CPU feature set. | |
| 583 | features: Cpu.Feature.Set, | |
| 584 | 584 | }; |
| 585 | 585 | |
| 586 | 586 | pub const current = Target{ |
| ... | ... | @@ -594,8 +594,15 @@ pub const Target = union(enum) { |
| 594 | 594 | |
| 595 | 595 | pub const stack_align = 16; |
| 596 | 596 | |
| 597 | pub fn cpuFeatures(self: Target) []const *const Cpu.Feature { | |
| 598 | return switch (self.cpu_features) { | |
| 597 | pub fn getCpuFeatures(self: Target) CpuFeatures { | |
| 598 | return switch (self) { | |
| 599 | .Native => builtin.cpu_features, | |
| 600 | .Cross => |cross| cross.cpu_features, | |
| 601 | }; | |
| 602 | } | |
| 603 | ||
| 604 | pub fn cpuFeaturesList(self: Target) []const *const Cpu.Feature { | |
| 605 | return switch (self.getCpuFeatures()) { | |
| 599 | 606 | .baseline => self.arch.baselineFeatures(), |
| 600 | 607 | .cpu => |cpu| cpu.features, |
| 601 | 608 | .features => |features| features, |
src-self-hosted/main.zig+1-43| ... | ... | @@ -79,7 +79,7 @@ pub fn main() !void { |
| 79 | 79 | } else if (mem.eql(u8, cmd, "libc")) { |
| 80 | 80 | return cmdLibC(allocator, cmd_args); |
| 81 | 81 | } else if (mem.eql(u8, cmd, "targets")) { |
| 82 | return cmdTargets(allocator, cmd_args); | |
| 82 | return @import("print_targets.zig").cmdTargets(allocator, cmd_args, stdout); | |
| 83 | 83 | } else if (mem.eql(u8, cmd, "version")) { |
| 84 | 84 | return cmdVersion(allocator, cmd_args); |
| 85 | 85 | } else if (mem.eql(u8, cmd, "zen")) { |
| ... | ... | @@ -789,48 +789,6 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro |
| 789 | 789 | } |
| 790 | 790 | } |
| 791 | 791 | |
| 792 | // cmd:targets ///////////////////////////////////////////////////////////////////////////////////// | |
| 793 | ||
| 794 | pub fn cmdTargets(allocator: *Allocator, args: []const []const u8) !void { | |
| 795 | try stdout.write("Architectures:\n"); | |
| 796 | { | |
| 797 | comptime var i: usize = 0; | |
| 798 | inline while (i < @memberCount(builtin.Arch)) : (i += 1) { | |
| 799 | comptime const arch_tag = @memberName(builtin.Arch, i); | |
| 800 | // NOTE: Cannot use empty string, see #918. | |
| 801 | comptime const native_str = if (comptime mem.eql(u8, arch_tag, @tagName(builtin.arch))) " (native)\n" else "\n"; | |
| 802 | ||
| 803 | try stdout.print(" {}{}", .{ arch_tag, native_str }); | |
| 804 | } | |
| 805 | } | |
| 806 | try stdout.write("\n"); | |
| 807 | ||
| 808 | try stdout.write("Operating Systems:\n"); | |
| 809 | { | |
| 810 | comptime var i: usize = 0; | |
| 811 | inline while (i < @memberCount(Target.Os)) : (i += 1) { | |
| 812 | comptime const os_tag = @memberName(Target.Os, i); | |
| 813 | // NOTE: Cannot use empty string, see #918. | |
| 814 | comptime const native_str = if (comptime mem.eql(u8, os_tag, @tagName(builtin.os))) " (native)\n" else "\n"; | |
| 815 | ||
| 816 | try stdout.print(" {}{}", .{ os_tag, native_str }); | |
| 817 | } | |
| 818 | } | |
| 819 | try stdout.write("\n"); | |
| 820 | ||
| 821 | try stdout.write("C ABIs:\n"); | |
| 822 | { | |
| 823 | comptime var i: usize = 0; | |
| 824 | inline while (i < @memberCount(Target.Abi)) : (i += 1) { | |
| 825 | comptime const abi_tag = @memberName(Target.Abi, i); | |
| 826 | // NOTE: Cannot use empty string, see #918. | |
| 827 | comptime const native_str = if (comptime mem.eql(u8, abi_tag, @tagName(builtin.abi))) " (native)\n" else "\n"; | |
| 828 | ||
| 829 | try stdout.print(" {}{}", .{ abi_tag, native_str }); | |
| 830 | } | |
| 831 | } | |
| 832 | } | |
| 833 | ||
| 834 | 792 | fn cmdVersion(allocator: *Allocator, args: []const []const u8) !void { |
| 835 | 793 | try stdout.print("{}\n", .{std.mem.toSliceConst(u8, c.ZIG_VERSION_STRING)}); |
| 836 | 794 | } |
src-self-hosted/print_targets.zig created+101| ... | ... | @@ -0,0 +1,101 @@ |
| 1 | const std = @import("std"); | |
| 2 | const fs = std.fs; | |
| 3 | const io = std.io; | |
| 4 | const mem = std.mem; | |
| 5 | const Allocator = mem.Allocator; | |
| 6 | const Target = std.Target; | |
| 7 | ||
| 8 | pub fn cmdTargets( | |
| 9 | allocator: *Allocator, | |
| 10 | args: []const []const u8, | |
| 11 | stdout: *io.OutStream(fs.File.WriteError), | |
| 12 | ) !void { | |
| 13 | const BOS = io.BufferedOutStream(fs.File.WriteError); | |
| 14 | var bos = BOS.init(stdout); | |
| 15 | var jws = std.json.WriteStream(BOS.Stream, 6).init(&bos.stream); | |
| 16 | ||
| 17 | try jws.beginObject(); | |
| 18 | ||
| 19 | try jws.objectField("arch"); | |
| 20 | try jws.beginObject(); | |
| 21 | { | |
| 22 | inline for (@typeInfo(Target.Arch).Union.fields) |field| { | |
| 23 | try jws.objectField(field.name); | |
| 24 | if (field.field_type == void) { | |
| 25 | try jws.emitNull(); | |
| 26 | } else { | |
| 27 | try jws.emitString(@typeName(field.field_type)); | |
| 28 | } | |
| 29 | } | |
| 30 | } | |
| 31 | try jws.endObject(); | |
| 32 | ||
| 33 | try jws.objectField("subArch"); | |
| 34 | try jws.beginObject(); | |
| 35 | const sub_arch_list = [_]type{ | |
| 36 | Target.Arch.Arm32, | |
| 37 | Target.Arch.Arm64, | |
| 38 | Target.Arch.Kalimba, | |
| 39 | Target.Arch.Mips, | |
| 40 | }; | |
| 41 | inline for (sub_arch_list) |SubArch| { | |
| 42 | try jws.objectField(@typeName(SubArch)); | |
| 43 | try jws.beginArray(); | |
| 44 | inline for (@typeInfo(SubArch).Enum.fields) |field| { | |
| 45 | try jws.arrayElem(); | |
| 46 | try jws.emitString(field.name); | |
| 47 | } | |
| 48 | try jws.endArray(); | |
| 49 | } | |
| 50 | try jws.endObject(); | |
| 51 | ||
| 52 | try jws.objectField("os"); | |
| 53 | try jws.beginArray(); | |
| 54 | { | |
| 55 | comptime var i: usize = 0; | |
| 56 | inline while (i < @memberCount(Target.Os)) : (i += 1) { | |
| 57 | const os_tag = @memberName(Target.Os, i); | |
| 58 | try jws.arrayElem(); | |
| 59 | try jws.emitString(os_tag); | |
| 60 | } | |
| 61 | } | |
| 62 | try jws.endArray(); | |
| 63 | ||
| 64 | try jws.objectField("abi"); | |
| 65 | try jws.beginArray(); | |
| 66 | { | |
| 67 | comptime var i: usize = 0; | |
| 68 | inline while (i < @memberCount(Target.Abi)) : (i += 1) { | |
| 69 | const abi_tag = @memberName(Target.Abi, i); | |
| 70 | try jws.arrayElem(); | |
| 71 | try jws.emitString(abi_tag); | |
| 72 | } | |
| 73 | } | |
| 74 | try jws.endArray(); | |
| 75 | ||
| 76 | try jws.objectField("native"); | |
| 77 | try jws.beginObject(); | |
| 78 | { | |
| 79 | const triple = try Target.current.zigTriple(allocator); | |
| 80 | defer allocator.free(triple); | |
| 81 | try jws.objectField("triple"); | |
| 82 | try jws.emitString(triple); | |
| 83 | } | |
| 84 | try jws.objectField("arch"); | |
| 85 | try jws.emitString(@tagName(Target.current.getArch())); | |
| 86 | try jws.objectField("os"); | |
| 87 | try jws.emitString(@tagName(Target.current.getOs())); | |
| 88 | try jws.objectField("abi"); | |
| 89 | try jws.emitString(@tagName(Target.current.getAbi())); | |
| 90 | try jws.objectField("cpuName"); | |
| 91 | switch (Target.current.getCpuFeatures()) { | |
| 92 | .baseline, .features => try jws.emitNull(), | |
| 93 | .cpu => |cpu| try jws.emitString(cpu.name), | |
| 94 | } | |
| 95 | try jws.endObject(); | |
| 96 | ||
| 97 | try jws.endObject(); | |
| 98 | ||
| 99 | try bos.stream.writeByte('\n'); | |
| 100 | return bos.flush(); | |
| 101 | } |
src-self-hosted/stage1.zig+6-2| ... | ... | @@ -539,7 +539,11 @@ export fn stage2_progress_update_node(node: *std.Progress.Node, done_count: usiz |
| 539 | 539 | |
| 540 | 540 | // ABI warning |
| 541 | 541 | export fn stage2_cmd_targets() c_int { |
| 542 | self_hosted_main.cmdTargets(std.heap.c_allocator, &[0][]u8{}) catch |err| { | |
| 542 | @import("print_targets.zig").cmdTargets( | |
| 543 | std.heap.c_allocator, | |
| 544 | &[0][]u8{}, | |
| 545 | &std.io.getStdOut().outStream().stream, | |
| 546 | ) catch |err| { | |
| 543 | 547 | std.debug.warn("unable to list targets: {}\n", .{@errorName(err)}); |
| 544 | 548 | return -1; |
| 545 | 549 | }; |
| ... | ... | @@ -548,7 +552,7 @@ export fn stage2_cmd_targets() c_int { |
| 548 | 552 | |
| 549 | 553 | const Stage2CpuFeatures = struct { |
| 550 | 554 | allocator: *mem.Allocator, |
| 551 | cpu_features: Target.Cross.CpuFeatures, | |
| 555 | cpu_features: Target.CpuFeatures, | |
| 552 | 556 | |
| 553 | 557 | llvm_cpu_name: ?[*:0]const u8, |
| 554 | 558 | llvm_features_str: ?[*:0]const u8, |
src/ir.cpp+5-1| ... | ... | @@ -22349,7 +22349,11 @@ static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIns |
| 22349 | 22349 | return ira->codegen->invalid_instruction; |
| 22350 | 22350 | } |
| 22351 | 22351 | |
| 22352 | assert(target->value->type->id == ZigTypeIdEnum); | |
| 22352 | if (target->value->type->id != ZigTypeIdEnum) { | |
| 22353 | ir_add_error(ira, target, | |
| 22354 | buf_sprintf("expected enum tag, found '%s'", buf_ptr(&target->value->type->name))); | |
| 22355 | return ira->codegen->invalid_instruction; | |
| 22356 | } | |
| 22353 | 22357 | |
| 22354 | 22358 | if (target->value->type->data.enumeration.src_field_count == 1 && |
| 22355 | 22359 | !target->value->type->data.enumeration.non_exhaustive) { |