From 8f29d1407350190e1e641ca55f870f00b53d0246 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 20 Jan 2020 01:42:31 -0500 Subject: [PATCH] stage1 is building. `zig targets` now self-hosted --- BRANCH_TODO | 2 + lib/std/builtin.zig | 3 + lib/std/target.zig | 62 +++--- lib/std/target/x86.zig | 392 ++++++++++++++++++------------------- src-self-hosted/main.zig | 2 +- src-self-hosted/stage1.zig | 164 +++++----------- src/error.cpp | 5 + src/main.cpp | 113 +---------- src/userland.cpp | 15 +- src/userland.h | 15 +- 10 files changed, 307 insertions(+), 466 deletions(-) diff --git a/BRANCH_TODO b/BRANCH_TODO index 50efbe89f6..4dfc95f706 100644 --- a/BRANCH_TODO +++ b/BRANCH_TODO @@ -1,5 +1,7 @@ Finish these thigns before merging teh branch + * it gets the wrong answers with `-target-feature -sse,-avx` + * finish refactoring target/arch/* * `zig builtin` integration * move target details to better location diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index 712d98b25c..b5c137c2e1 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -1,5 +1,8 @@ pub usingnamespace @import("builtin"); +/// Deprecated: use `std.Target.Os`. +pub const Target = std.Target; + /// Deprecated: use `std.Target.Os`. pub const Os = std.Target.Os; diff --git a/lib/std/target.zig b/lib/std/target.zig index 350387bd8a..2f3e740c90 100644 --- a/lib/std/target.zig +++ b/lib/std/target.zig @@ -49,6 +49,22 @@ pub const Target = union(enum) { other, }; + pub const aarch64 = @import("target/aarch64.zig"); + pub const amdgpu = @import("target/amdgpu.zig"); + pub const arm = @import("target/arm.zig"); + pub const avr = @import("target/avr.zig"); + pub const bpf = @import("target/bpf.zig"); + pub const hexagon = @import("target/hexagon.zig"); + pub const mips = @import("target/mips.zig"); + pub const msp430 = @import("target/msp430.zig"); + pub const nvptx = @import("target/nvptx.zig"); + pub const powerpc = @import("target/powerpc.zig"); + pub const riscv = @import("target/riscv.zig"); + pub const sparc = @import("target/sparc.zig"); + pub const systemz = @import("target/systemz.zig"); + pub const wasm = @import("target/wasm.zig"); + pub const x86 = @import("target/x86.zig"); + pub const Arch = union(enum) { arm: Arm32, armeb: Arm32, @@ -101,22 +117,6 @@ pub const Target = union(enum) { renderscript32, renderscript64, - pub const aarch64 = @import("target/aarch64.zig"); - pub const amdgpu = @import("target/amdgpu.zig"); - pub const arm = @import("target/arm.zig"); - pub const avr = @import("target/avr.zig"); - pub const bpf = @import("target/bpf.zig"); - pub const hexagon = @import("target/hexagon.zig"); - pub const mips = @import("target/mips.zig"); - pub const msp430 = @import("target/msp430.zig"); - pub const nvptx = @import("target/nvptx.zig"); - pub const powerpc = @import("target/powerpc.zig"); - pub const riscv = @import("target/riscv.zig"); - pub const sparc = @import("target/sparc.zig"); - pub const systemz = @import("target/systemz.zig"); - pub const wasm = @import("target/wasm.zig"); - pub const x86 = @import("target/x86.zig"); - pub const Arm32 = enum { v8_5a, v8_4a, @@ -251,7 +251,7 @@ pub const Target = union(enum) { }; for (arch.allFeaturesList()) |feature, index| { if (mem.eql(u8, feature_name, feature.name)) { - set |= @splat(2, 1 << index); + set |= @splat(2, @as(Cpu.Feature.Set, 1) << @intCast(u7, index)); break; } } else { @@ -440,7 +440,7 @@ pub const Target = union(enum) { // TODO .sparc, .sparcv9, .sparcel => sparc.baseline_features, // TODO .s390x => systemz.baseline_features, .i386 => x86.cpu.pentium4.features, - .x86_64 => x86.cpu.x8664.features, + .x86_64 => x86.cpu.x86_64.features, // TODO .nvptx, .nvptx64 => nvptx.baseline_features, // TODO .wasm32, .wasm64 => wasm.baseline_features, @@ -451,21 +451,21 @@ pub const Target = union(enum) { /// All CPUs Zig is aware of, sorted lexicographically by name. pub fn allCpus(arch: Arch) []const *const Cpu { return switch (arch) { - .arm, .armeb, .thumb, .thumbeb => arm.all_cpus, + // TODO .arm, .armeb, .thumb, .thumbeb => arm.all_cpus, .aarch64, .aarch64_be, .aarch64_32 => aarch64.all_cpus, - .avr => avr.all_cpus, - .bpfel, .bpfeb => bpf.all_cpus, - .hexagon => hexagon.all_cpus, - .mips, .mipsel, .mips64, .mips64el => mips.all_cpus, - .msp430 => msp430.all_cpus, - .powerpc, .powerpc64, .powerpc64le => powerpc.all_cpus, - .amdgcn => amdgpu.all_cpus, - .riscv32, .riscv64 => riscv.all_cpus, - .sparc, .sparcv9, .sparcel => sparc.all_cpus, - .s390x => systemz.all_cpus, + // TODO .avr => avr.all_cpus, + // TODO .bpfel, .bpfeb => bpf.all_cpus, + // TODO .hexagon => hexagon.all_cpus, + // TODO .mips, .mipsel, .mips64, .mips64el => mips.all_cpus, + // TODO .msp430 => msp430.all_cpus, + // TODO .powerpc, .powerpc64, .powerpc64le => powerpc.all_cpus, + // TODO .amdgcn => amdgpu.all_cpus, + // TODO .riscv32, .riscv64 => riscv.all_cpus, + // TODO .sparc, .sparcv9, .sparcel => sparc.all_cpus, + // TODO .s390x => systemz.all_cpus, .i386, .x86_64 => x86.all_cpus, - .nvptx, .nvptx64 => nvptx.all_cpus, - .wasm32, .wasm64 => wasm.all_cpus, + // TODO .nvptx, .nvptx64 => nvptx.all_cpus, + // TODO .wasm32, .wasm64 => wasm.all_cpus, else => &[0]*const Cpu{}, }; diff --git a/lib/std/target/x86.zig b/lib/std/target/x86.zig index 021c940dbd..50b332f5e1 100644 --- a/lib/std/target/x86.zig +++ b/lib/std/target/x86.zig @@ -1213,10 +1213,10 @@ pub const cpu = struct { pub const amdfam10 = Cpu{ .name = "amdfam10", .llvm_name = "amdfam10", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .mmx, - .dnowa3, - .bit64, + .@"3dnowa", + .@"64bit", .cmov, .cx8, .cx16, @@ -1236,9 +1236,9 @@ pub const cpu = struct { pub const athlon = Cpu{ .name = "athlon", .llvm_name = "athlon", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .mmx, - .dnowa3, + .@"3dnowa", .cmov, .cx8, .nopl, @@ -1251,9 +1251,9 @@ pub const cpu = struct { pub const athlon4 = Cpu{ .name = "athlon_4", .llvm_name = "athlon-4", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .mmx, - .dnowa3, + .@"3dnowa", .cmov, .cx8, .fxsr, @@ -1268,10 +1268,10 @@ pub const cpu = struct { pub const athlon_fx = Cpu{ .name = "athlon_fx", .llvm_name = "athlon-fx", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .mmx, - .dnowa3, - .bit64, + .@"3dnowa", + .@"64bit", .cmov, .cx8, .fxsr, @@ -1288,9 +1288,9 @@ pub const cpu = struct { pub const athlon_mp = Cpu{ .name = "athlon_mp", .llvm_name = "athlon-mp", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .mmx, - .dnowa3, + .@"3dnowa", .cmov, .cx8, .fxsr, @@ -1305,9 +1305,9 @@ pub const cpu = struct { pub const athlon_tbird = Cpu{ .name = "athlon_tbird", .llvm_name = "athlon-tbird", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .mmx, - .dnowa3, + .@"3dnowa", .cmov, .cx8, .nopl, @@ -1320,9 +1320,9 @@ pub const cpu = struct { pub const athlon_xp = Cpu{ .name = "athlon_xp", .llvm_name = "athlon-xp", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .mmx, - .dnowa3, + .@"3dnowa", .cmov, .cx8, .fxsr, @@ -1337,10 +1337,10 @@ pub const cpu = struct { pub const athlon64 = Cpu{ .name = "athlon64", .llvm_name = "athlon64", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .mmx, - .dnowa3, - .bit64, + .@"3dnowa", + .@"64bit", .cmov, .cx8, .fxsr, @@ -1357,10 +1357,10 @@ pub const cpu = struct { pub const athlon64_sse3 = Cpu{ .name = "athlon64_sse3", .llvm_name = "athlon64-sse3", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .mmx, - .dnowa3, - .bit64, + .@"3dnowa", + .@"64bit", .cmov, .cx8, .cx16, @@ -1378,8 +1378,8 @@ pub const cpu = struct { pub const atom = Cpu{ .name = "atom", .llvm_name = "atom", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .cmov, .cx8, .cx16, @@ -1404,10 +1404,10 @@ pub const cpu = struct { pub const barcelona = Cpu{ .name = "barcelona", .llvm_name = "barcelona", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .mmx, - .dnowa3, - .bit64, + .@"3dnowa", + .@"64bit", .cmov, .cx8, .cx16, @@ -1427,8 +1427,8 @@ pub const cpu = struct { pub const bdver1 = Cpu{ .name = "bdver1", .llvm_name = "bdver1", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .sse, .aes, .branchfusion, @@ -1436,7 +1436,7 @@ pub const cpu = struct { .cx8, .cx16, .fxsr, - .fast11bytenop, + .fast_11bytenop, .fast_scalar_shift_masks, .sahf, .lwp, @@ -1456,8 +1456,8 @@ pub const cpu = struct { pub const bdver2 = Cpu{ .name = "bdver2", .llvm_name = "bdver2", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .sse, .aes, .bmi, @@ -1468,7 +1468,7 @@ pub const cpu = struct { .f16c, .fma, .fxsr, - .fast11bytenop, + .fast_11bytenop, .fast_bextr, .fast_scalar_shift_masks, .sahf, @@ -1490,8 +1490,8 @@ pub const cpu = struct { pub const bdver3 = Cpu{ .name = "bdver3", .llvm_name = "bdver3", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .sse, .aes, .bmi, @@ -1503,7 +1503,7 @@ pub const cpu = struct { .fma, .fsgsbase, .fxsr, - .fast11bytenop, + .fast_11bytenop, .fast_bextr, .fast_scalar_shift_masks, .sahf, @@ -1526,8 +1526,8 @@ pub const cpu = struct { pub const bdver4 = Cpu{ .name = "bdver4", .llvm_name = "bdver4", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .sse, .aes, .avx2, @@ -1541,7 +1541,7 @@ pub const cpu = struct { .fma, .fsgsbase, .fxsr, - .fast11bytenop, + .fast_11bytenop, .fast_bextr, .fast_scalar_shift_masks, .sahf, @@ -1565,8 +1565,8 @@ pub const cpu = struct { pub const bonnell = Cpu{ .name = "bonnell", .llvm_name = "bonnell", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .cmov, .cx8, .cx16, @@ -1591,8 +1591,8 @@ pub const cpu = struct { pub const broadwell = Cpu{ .name = "broadwell", .llvm_name = "broadwell", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .adx, .sse, .avx, @@ -1625,7 +1625,7 @@ pub const cpu = struct { .prfchw, .rdrnd, .rdseed, - .sse42, + .sse4_2, .slow_3ops_lea, .idivq_to_divl, .x87, @@ -1637,13 +1637,13 @@ pub const cpu = struct { pub const btver1 = Cpu{ .name = "btver1", .llvm_name = "btver1", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .cmov, .cx8, .cx16, .fxsr, - .fast15bytenop, + .fast_15bytenop, .fast_scalar_shift_masks, .fast_vector_shift_masks, .sahf, @@ -1663,8 +1663,8 @@ pub const cpu = struct { pub const btver2 = Cpu{ .name = "btver2", .llvm_name = "btver2", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .sse, .aes, .avx, @@ -1674,7 +1674,7 @@ pub const cpu = struct { .cx16, .f16c, .fxsr, - .fast15bytenop, + .fast_15bytenop, .fast_bextr, .fast_hops, .fast_lzcnt, @@ -1701,9 +1701,9 @@ pub const cpu = struct { pub const c3 = Cpu{ .name = "c3", .llvm_name = "c3", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .mmx, - .dnow3, + .@"3dnow", .slow_unaligned_mem_16, .x87, }), @@ -1712,7 +1712,7 @@ pub const cpu = struct { pub const c32 = Cpu{ .name = "c3_2", .llvm_name = "c3-2", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .cmov, .cx8, .fxsr, @@ -1726,8 +1726,8 @@ pub const cpu = struct { pub const cannonlake = Cpu{ .name = "cannonlake", .llvm_name = "cannonlake", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .adx, .sse, .aes, @@ -1771,7 +1771,7 @@ pub const cpu = struct { .rdseed, .sgx, .sha, - .sse42, + .sse4_2, .slow_3ops_lea, .idivq_to_divl, .avx512vbmi, @@ -1787,8 +1787,8 @@ pub const cpu = struct { pub const cascadelake = Cpu{ .name = "cascadelake", .llvm_name = "cascadelake", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .adx, .sse, .aes, @@ -1831,7 +1831,7 @@ pub const cpu = struct { .prfchw, .rdrnd, .rdseed, - .sse42, + .sse4_2, .slow_3ops_lea, .idivq_to_divl, .avx512vl, @@ -1847,8 +1847,8 @@ pub const cpu = struct { pub const cooperlake = Cpu{ .name = "cooperlake", .llvm_name = "cooperlake", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .adx, .sse, .aes, @@ -1892,7 +1892,7 @@ pub const cpu = struct { .prfchw, .rdrnd, .rdseed, - .sse42, + .sse4_2, .slow_3ops_lea, .idivq_to_divl, .avx512vl, @@ -1908,8 +1908,8 @@ pub const cpu = struct { pub const core_avx_i = Cpu{ .name = "core_avx_i", .llvm_name = "core-avx-i", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .sse, .avx, .cmov, @@ -1929,7 +1929,7 @@ pub const cpu = struct { .popcnt, .false_deps_popcnt, .rdrnd, - .sse42, + .sse4_2, .slow_3ops_lea, .idivq_to_divl, .slow_unaligned_mem_32, @@ -1942,8 +1942,8 @@ pub const cpu = struct { pub const core_avx2 = Cpu{ .name = "core_avx2", .llvm_name = "core-avx2", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .sse, .avx, .avx2, @@ -1973,7 +1973,7 @@ pub const cpu = struct { .popcnt, .false_deps_popcnt, .rdrnd, - .sse42, + .sse4_2, .slow_3ops_lea, .idivq_to_divl, .x87, @@ -1985,8 +1985,8 @@ pub const cpu = struct { pub const core2 = Cpu{ .name = "core2", .llvm_name = "core2", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .cmov, .cx8, .cx16, @@ -2005,8 +2005,8 @@ pub const cpu = struct { pub const corei7 = Cpu{ .name = "corei7", .llvm_name = "corei7", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .cmov, .cx8, .cx16, @@ -2017,7 +2017,7 @@ pub const cpu = struct { .nopl, .popcnt, .sse, - .sse42, + .sse4_2, .x87, }), }; @@ -2025,8 +2025,8 @@ pub const cpu = struct { pub const corei7_avx = Cpu{ .name = "corei7_avx", .llvm_name = "corei7-avx", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .sse, .avx, .cmov, @@ -2043,7 +2043,7 @@ pub const cpu = struct { .pclmul, .popcnt, .false_deps_popcnt, - .sse42, + .sse4_2, .slow_3ops_lea, .idivq_to_divl, .slow_unaligned_mem_32, @@ -2056,7 +2056,7 @@ pub const cpu = struct { pub const generic = Cpu{ .name = "generic", .llvm_name = "generic", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .cx8, .slow_unaligned_mem_16, .x87, @@ -2066,9 +2066,9 @@ pub const cpu = struct { pub const geode = Cpu{ .name = "geode", .llvm_name = "geode", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .mmx, - .dnowa3, + .@"3dnowa", .cx8, .slow_unaligned_mem_16, .x87, @@ -2078,8 +2078,8 @@ pub const cpu = struct { pub const goldmont = Cpu{ .name = "goldmont", .llvm_name = "goldmont", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .sse, .aes, .clflushopt, @@ -2100,10 +2100,10 @@ pub const cpu = struct { .rdrnd, .rdseed, .sha, - .sse42, + .sse4_2, .ssse3, .slow_incdec, - .slowLea, + .slow_lea, .slow_two_mem_ops, .x87, .xsave, @@ -2116,8 +2116,8 @@ pub const cpu = struct { pub const goldmont_plus = Cpu{ .name = "goldmont_plus", .llvm_name = "goldmont-plus", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .sse, .aes, .clflushopt, @@ -2140,10 +2140,10 @@ pub const cpu = struct { .rdseed, .sgx, .sha, - .sse42, + .sse4_2, .ssse3, .slow_incdec, - .slowLea, + .slow_lea, .slow_two_mem_ops, .x87, .xsave, @@ -2156,8 +2156,8 @@ pub const cpu = struct { pub const haswell = Cpu{ .name = "haswell", .llvm_name = "haswell", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .sse, .avx, .avx2, @@ -2187,7 +2187,7 @@ pub const cpu = struct { .popcnt, .false_deps_popcnt, .rdrnd, - .sse42, + .sse4_2, .slow_3ops_lea, .idivq_to_divl, .x87, @@ -2196,38 +2196,38 @@ pub const cpu = struct { }), }; - pub const i386 = Cpu{ - .name = "i386", + pub const _i386 = Cpu{ + .name = "_i386", .llvm_name = "i386", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .slow_unaligned_mem_16, .x87, }), }; - pub const i486 = Cpu{ - .name = "i486", + pub const _i486 = Cpu{ + .name = "_i486", .llvm_name = "i486", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .slow_unaligned_mem_16, .x87, }), }; - pub const i586 = Cpu{ - .name = "i586", + pub const _i586 = Cpu{ + .name = "_i586", .llvm_name = "i586", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .cx8, .slow_unaligned_mem_16, .x87, }), }; - pub const i686 = Cpu{ - .name = "i686", + pub const _i686 = Cpu{ + .name = "_i686", .llvm_name = "i686", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .cmov, .cx8, .slow_unaligned_mem_16, @@ -2238,8 +2238,8 @@ pub const cpu = struct { pub const icelake_client = Cpu{ .name = "icelake_client", .llvm_name = "icelake-client", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .adx, .sse, .aes, @@ -2287,7 +2287,7 @@ pub const cpu = struct { .rdseed, .sgx, .sha, - .sse42, + .sse4_2, .slow_3ops_lea, .idivq_to_divl, .vaes, @@ -2308,8 +2308,8 @@ pub const cpu = struct { pub const icelake_server = Cpu{ .name = "icelake_server", .llvm_name = "icelake-server", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .adx, .sse, .aes, @@ -2358,7 +2358,7 @@ pub const cpu = struct { .rdseed, .sgx, .sha, - .sse42, + .sse4_2, .slow_3ops_lea, .idivq_to_divl, .vaes, @@ -2380,8 +2380,8 @@ pub const cpu = struct { pub const ivybridge = Cpu{ .name = "ivybridge", .llvm_name = "ivybridge", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .sse, .avx, .cmov, @@ -2401,7 +2401,7 @@ pub const cpu = struct { .popcnt, .false_deps_popcnt, .rdrnd, - .sse42, + .sse4_2, .slow_3ops_lea, .idivq_to_divl, .slow_unaligned_mem_32, @@ -2414,7 +2414,7 @@ pub const cpu = struct { pub const k6 = Cpu{ .name = "k6", .llvm_name = "k6", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .cx8, .mmx, .slow_unaligned_mem_16, @@ -2425,9 +2425,9 @@ pub const cpu = struct { pub const k62 = Cpu{ .name = "k6_2", .llvm_name = "k6-2", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .mmx, - .dnow3, + .@"3dnow", .cx8, .slow_unaligned_mem_16, .x87, @@ -2437,9 +2437,9 @@ pub const cpu = struct { pub const k63 = Cpu{ .name = "k6_3", .llvm_name = "k6-3", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .mmx, - .dnow3, + .@"3dnow", .cx8, .slow_unaligned_mem_16, .x87, @@ -2449,10 +2449,10 @@ pub const cpu = struct { pub const k8 = Cpu{ .name = "k8", .llvm_name = "k8", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .mmx, - .dnowa3, - .bit64, + .@"3dnowa", + .@"64bit", .cmov, .cx8, .fxsr, @@ -2469,10 +2469,10 @@ pub const cpu = struct { pub const k8_sse3 = Cpu{ .name = "k8_sse3", .llvm_name = "k8-sse3", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .mmx, - .dnowa3, - .bit64, + .@"3dnowa", + .@"64bit", .cmov, .cx8, .cx16, @@ -2490,8 +2490,8 @@ pub const cpu = struct { pub const knl = Cpu{ .name = "knl", .llvm_name = "knl", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .adx, .sse, .aes, @@ -2535,8 +2535,8 @@ pub const cpu = struct { pub const knm = Cpu{ .name = "knm", .llvm_name = "knm", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .adx, .sse, .aes, @@ -2581,14 +2581,14 @@ pub const cpu = struct { pub const lakemont = Cpu{ .name = "lakemont", .llvm_name = "lakemont", - .dependencies = 0, + .features = 0, }; pub const nehalem = Cpu{ .name = "nehalem", .llvm_name = "nehalem", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .cmov, .cx8, .cx16, @@ -2599,7 +2599,7 @@ pub const cpu = struct { .nopl, .popcnt, .sse, - .sse42, + .sse4_2, .x87, }), }; @@ -2607,8 +2607,8 @@ pub const cpu = struct { pub const nocona = Cpu{ .name = "nocona", .llvm_name = "nocona", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .cmov, .cx8, .cx16, @@ -2625,10 +2625,10 @@ pub const cpu = struct { pub const opteron = Cpu{ .name = "opteron", .llvm_name = "opteron", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .mmx, - .dnowa3, - .bit64, + .@"3dnowa", + .@"64bit", .cmov, .cx8, .fxsr, @@ -2645,10 +2645,10 @@ pub const cpu = struct { pub const opteron_sse3 = Cpu{ .name = "opteron_sse3", .llvm_name = "opteron-sse3", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .mmx, - .dnowa3, - .bit64, + .@"3dnowa", + .@"64bit", .cmov, .cx8, .cx16, @@ -2666,8 +2666,8 @@ pub const cpu = struct { pub const penryn = Cpu{ .name = "penryn", .llvm_name = "penryn", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .cmov, .cx8, .cx16, @@ -2677,7 +2677,7 @@ pub const cpu = struct { .macrofusion, .nopl, .sse, - .sse41, + .sse4_1, .slow_unaligned_mem_16, .x87, }), @@ -2686,7 +2686,7 @@ pub const cpu = struct { pub const pentium = Cpu{ .name = "pentium", .llvm_name = "pentium", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .cx8, .slow_unaligned_mem_16, .x87, @@ -2696,7 +2696,7 @@ pub const cpu = struct { pub const pentium_m = Cpu{ .name = "pentium_m", .llvm_name = "pentium-m", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .cmov, .cx8, .fxsr, @@ -2712,7 +2712,7 @@ pub const cpu = struct { pub const pentium_mmx = Cpu{ .name = "pentium_mmx", .llvm_name = "pentium-mmx", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .cx8, .mmx, .slow_unaligned_mem_16, @@ -2723,7 +2723,7 @@ pub const cpu = struct { pub const pentium2 = Cpu{ .name = "pentium2", .llvm_name = "pentium2", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .cmov, .cx8, .fxsr, @@ -2737,7 +2737,7 @@ pub const cpu = struct { pub const pentium3 = Cpu{ .name = "pentium3", .llvm_name = "pentium3", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .cmov, .cx8, .fxsr, @@ -2752,7 +2752,7 @@ pub const cpu = struct { pub const pentium3m = Cpu{ .name = "pentium3m", .llvm_name = "pentium3m", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .cmov, .cx8, .fxsr, @@ -2767,7 +2767,7 @@ pub const cpu = struct { pub const pentium4 = Cpu{ .name = "pentium4", .llvm_name = "pentium4", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .cmov, .cx8, .fxsr, @@ -2783,7 +2783,7 @@ pub const cpu = struct { pub const pentium4m = Cpu{ .name = "pentium4m", .llvm_name = "pentium4m", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .cmov, .cx8, .fxsr, @@ -2799,7 +2799,7 @@ pub const cpu = struct { pub const pentiumpro = Cpu{ .name = "pentiumpro", .llvm_name = "pentiumpro", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .cmov, .cx8, .nopl, @@ -2811,7 +2811,7 @@ pub const cpu = struct { pub const prescott = Cpu{ .name = "prescott", .llvm_name = "prescott", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .cmov, .cx8, .fxsr, @@ -2827,8 +2827,8 @@ pub const cpu = struct { pub const sandybridge = Cpu{ .name = "sandybridge", .llvm_name = "sandybridge", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .sse, .avx, .cmov, @@ -2845,7 +2845,7 @@ pub const cpu = struct { .pclmul, .popcnt, .false_deps_popcnt, - .sse42, + .sse4_2, .slow_3ops_lea, .idivq_to_divl, .slow_unaligned_mem_32, @@ -2858,8 +2858,8 @@ pub const cpu = struct { pub const silvermont = Cpu{ .name = "silvermont", .llvm_name = "silvermont", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .cmov, .cx8, .cx16, @@ -2874,12 +2874,12 @@ pub const cpu = struct { .false_deps_popcnt, .prfchw, .rdrnd, - .sse42, + .sse4_2, .ssse3, .idivq_to_divl, .slow_incdec, - .slowLea, - .slowPmulld, + .slow_lea, + .slow_pmulld, .slow_two_mem_ops, .x87, }), @@ -2888,8 +2888,8 @@ pub const cpu = struct { pub const skx = Cpu{ .name = "skx", .llvm_name = "skx", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .adx, .sse, .aes, @@ -2932,7 +2932,7 @@ pub const cpu = struct { .prfchw, .rdrnd, .rdseed, - .sse42, + .sse4_2, .slow_3ops_lea, .idivq_to_divl, .avx512vl, @@ -2947,8 +2947,8 @@ pub const cpu = struct { pub const skylake = Cpu{ .name = "skylake", .llvm_name = "skylake", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .adx, .sse, .aes, @@ -2986,7 +2986,7 @@ pub const cpu = struct { .rdrnd, .rdseed, .sgx, - .sse42, + .sse4_2, .slow_3ops_lea, .idivq_to_divl, .x87, @@ -3000,8 +3000,8 @@ pub const cpu = struct { pub const skylake_avx512 = Cpu{ .name = "skylake_avx512", .llvm_name = "skylake-avx512", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .adx, .sse, .aes, @@ -3044,7 +3044,7 @@ pub const cpu = struct { .prfchw, .rdrnd, .rdseed, - .sse42, + .sse4_2, .slow_3ops_lea, .idivq_to_divl, .avx512vl, @@ -3059,8 +3059,8 @@ pub const cpu = struct { pub const slm = Cpu{ .name = "slm", .llvm_name = "slm", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .cmov, .cx8, .cx16, @@ -3075,12 +3075,12 @@ pub const cpu = struct { .false_deps_popcnt, .prfchw, .rdrnd, - .sse42, + .sse4_2, .ssse3, .idivq_to_divl, .slow_incdec, - .slowLea, - .slowPmulld, + .slow_lea, + .slow_pmulld, .slow_two_mem_ops, .x87, }), @@ -3089,8 +3089,8 @@ pub const cpu = struct { pub const tremont = Cpu{ .name = "tremont", .llvm_name = "tremont", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .sse, .aes, .cldemote, @@ -3117,10 +3117,10 @@ pub const cpu = struct { .rdseed, .sgx, .sha, - .sse42, + .sse4_2, .ssse3, .slow_incdec, - .slowLea, + .slow_lea, .slow_two_mem_ops, .waitpkg, .x87, @@ -3134,8 +3134,8 @@ pub const cpu = struct { pub const westmere = Cpu{ .name = "westmere", .llvm_name = "westmere", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .cmov, .cx8, .cx16, @@ -3147,7 +3147,7 @@ pub const cpu = struct { .sse, .pclmul, .popcnt, - .sse42, + .sse4_2, .x87, }), }; @@ -3155,7 +3155,7 @@ pub const cpu = struct { pub const winchip_c6 = Cpu{ .name = "winchip_c6", .llvm_name = "winchip-c6", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .mmx, .slow_unaligned_mem_16, .x87, @@ -3165,9 +3165,9 @@ pub const cpu = struct { pub const winchip2 = Cpu{ .name = "winchip2", .llvm_name = "winchip2", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .mmx, - .dnow3, + .@"3dnow", .slow_unaligned_mem_16, .x87, }), @@ -3176,8 +3176,8 @@ pub const cpu = struct { pub const x86_64 = Cpu{ .name = "x86_64", .llvm_name = "x86-64", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .cmov, .cx8, .fxsr, @@ -3195,7 +3195,7 @@ pub const cpu = struct { pub const yonah = Cpu{ .name = "yonah", .llvm_name = "yonah", - .dependencies = featureSet(&[_]Feature{ + .features = featureSet(&[_]Feature{ .cmov, .cx8, .fxsr, @@ -3211,8 +3211,8 @@ pub const cpu = struct { pub const znver1 = Cpu{ .name = "znver1", .llvm_name = "znver1", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .adx, .sse, .aes, @@ -3229,7 +3229,7 @@ pub const cpu = struct { .fma, .fsgsbase, .fxsr, - .fast15bytenop, + .fast_15bytenop, .fast_bextr, .fast_lzcnt, .fast_scalar_shift_masks, @@ -3258,8 +3258,8 @@ pub const cpu = struct { pub const znver2 = Cpu{ .name = "znver2", .llvm_name = "znver2", - .dependencies = featureSet(&[_]Feature{ - .bit64, + .features = featureSet(&[_]Feature{ + .@"64bit", .adx, .sse, .aes, @@ -3277,7 +3277,7 @@ pub const cpu = struct { .fma, .fsgsbase, .fxsr, - .fast15bytenop, + .fast_15bytenop, .fast_bextr, .fast_lzcnt, .fast_scalar_shift_masks, @@ -3341,10 +3341,10 @@ pub const all_cpus = &[_]*const Cpu{ &cpu.goldmont, &cpu.goldmont_plus, &cpu.haswell, - &cpu.i386, - &cpu.i486, - &cpu.i586, - &cpu.i686, + &cpu._i386, + &cpu._i486, + &cpu._i586, + &cpu._i686, &cpu.icelake_client, &cpu.icelake_server, &cpu.ivybridge, diff --git a/src-self-hosted/main.zig b/src-self-hosted/main.zig index af3fd3a015..e3faf853ea 100644 --- a/src-self-hosted/main.zig +++ b/src-self-hosted/main.zig @@ -791,7 +791,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro // cmd:targets ///////////////////////////////////////////////////////////////////////////////////// -fn cmdTargets(allocator: *Allocator, args: []const []const u8) !void { +pub fn cmdTargets(allocator: *Allocator, args: []const []const u8) !void { try stdout.write("Architectures:\n"); { comptime var i: usize = 0; diff --git a/src-self-hosted/stage1.zig b/src-self-hosted/stage1.zig index 85a6951827..9ce4746950 100644 --- a/src-self-hosted/stage1.zig +++ b/src-self-hosted/stage1.zig @@ -84,6 +84,11 @@ const Error = extern enum { NotLazy, IsAsync, ImportOutsidePkgPath, + UnknownCpu, + UnknownSubArchitecture, + UnknownCpuFeature, + InvalidCpuFeatures, + InvalidLlvmCpuFeaturesFormat, }; const FILE = std.c.FILE; @@ -533,99 +538,20 @@ export fn stage2_progress_update_node(node: *std.Progress.Node, done_count: usiz } // ABI warning -export fn stage2_list_features_for_arch(arch_name_ptr: [*]const u8, arch_name_len: usize, show_dependencies: bool) void { - printFeaturesForArch(arch_name_ptr[0..arch_name_len], show_dependencies) catch |err| { - std.debug.warn("Failed to list features: {}\n", .{@errorName(err)}); +export fn stage2_cmd_targets() c_int { + self_hosted_main.cmdTargets(std.heap.c_allocator, &[0][]u8{}) catch |err| { + std.debug.warn("unable to list targets: {}\n", .{@errorName(err)}); + return -1; }; -} - -fn printFeaturesForArch(arch_name: []const u8, show_dependencies: bool) !void { - const stdout_stream = &std.io.getStdOut().outStream().stream; - - const arch = Target.parseArchSub(arch_name) catch { - std.debug.warn("Failed to parse arch '{}'\nInvoke 'zig targets' for a list of valid architectures\n", .{arch_name}); - return; - }; - - try stdout_stream.print("Available features for {}:\n", .{@tagName(arch)}); - - const features = arch.allFeaturesList(); - - var longest_len: usize = 0; - for (features) |feature| { - if (feature.name.len > longest_len) { - longest_len = feature.name.len; - } - } - - for (features) |feature| { - try stdout_stream.print(" {}", .{feature.name}); - - var i: usize = 0; - while (i < longest_len - feature.name.len) : (i += 1) { - try stdout_stream.write(" "); - } - - try stdout_stream.print(" - {}\n", .{feature.description}); - - if (show_dependencies and feature.dependencies != 0) { - for (feature.dependencies) |dependency| { - try stdout_stream.print(" {}\n", .{dependency.name}); - } - } - } -} - -// ABI warning -export fn stage2_list_cpus_for_arch(arch_name_ptr: [*]const u8, arch_name_len: usize, show_dependencies: bool) void { - printCpusForArch(arch_name_ptr[0..arch_name_len], show_dependencies) catch |err| { - std.debug.warn("Failed to list features: {}\n", .{@errorName(err)}); - }; -} - -fn printCpusForArch(arch_name: []const u8, show_dependencies: bool) !void { - const stdout_stream = &std.io.getStdOut().outStream().stream; - - const arch = Target.parseArchTag(arch_name) catch { - std.debug.warn("Failed to parse arch '{}'\nInvoke 'zig targets' for a list of valid architectures\n", .{arch_name}); - return; - }; - - const cpus = std.target.getCpusForArch(arch); - - try stdout_stream.print("Available cpus for {}:\n", .{@tagName(arch)}); - - var longest_len: usize = 0; - for (cpus) |cpu| { - if (cpu.name.len > longest_len) { - longest_len = cpu.name.len; - } - } - - for (cpus) |cpu| { - try stdout_stream.print(" {}", .{cpu.name}); - - var i: usize = 0; - while (i < longest_len - cpu.name.len) : (i += 1) { - try stdout_stream.write(" "); - } - - try stdout_stream.write("\n"); - - if (show_dependencies and cpu.dependencies.len > 0) { - for (cpu.dependencies) |dependency| { - try stdout_stream.print(" {}\n", .{dependency.name}); - } - } - } + return 0; } const Stage2CpuFeatures = struct { allocator: *mem.Allocator, cpu_features: Target.Cross.CpuFeatures, - llvm_cpu_name: ?[:0]const u8, - llvm_features_str: ?[:0]const u8, + llvm_cpu_name: ?[*:0]const u8, + llvm_features_str: ?[*:0]const u8, builtin_str: [:0]const u8, cache_hash: [:0]const u8, @@ -636,10 +562,10 @@ const Stage2CpuFeatures = struct { const self = try allocator.create(Self); errdefer allocator.destroy(self); - const builtin_str = try std.fmt.allocPrint0(allocator, ".baseline;\n"); + const builtin_str = try std.fmt.allocPrint0(allocator, ".baseline;\n", .{}); errdefer allocator.free(builtin_str); - const cache_hash = try std.fmt.allocPrint0(allocator, "\n\n"); + const cache_hash = try std.fmt.allocPrint0(allocator, "\n\n", .{}); errdefer allocator.free(cache_hash); self.* = Self{ @@ -655,7 +581,7 @@ const Stage2CpuFeatures = struct { fn createFromLLVM( allocator: *mem.Allocator, - arch: [*:0]const u8, + arch_name: [*:0]const u8, llvm_cpu_name_z: [*:0]const u8, llvm_cpu_features: [*:0]const u8, ) !*Self { @@ -687,10 +613,11 @@ const Stage2CpuFeatures = struct { return error.InvalidLlvmCpuFeaturesFormat; } for (arch.allFeaturesList()) |feature, index| { - if (mem.eql(u8, feature_name, feature.name)) { + const this_llvm_name = feature.llvm_name orelse continue; + if (mem.eql(u8, llvm_feat, this_llvm_name)) { switch (op) { - .add => set |= 1 << index, - .sub => set &= ~@as(Target.Cpu.Feature.Set, 1 << index), + .add => set |= @as(Target.Cpu.Feature.Set, 1) << @intCast(u7, index), + .sub => set &= ~@as(Target.Cpu.Feature.Set, 1) << @intCast(u7, index), } break; } @@ -703,21 +630,19 @@ const Stage2CpuFeatures = struct { const self = try allocator.create(Self); errdefer allocator.destroy(self); - const builtin_str = try std.fmt.allocPrint0( - allocator, - "CpuFeatures{{ .cpu = &Arch.{}.cpu.{} }};\n", + const builtin_str = try std.fmt.allocPrint0(allocator, "CpuFeatures{{ .cpu = &Target.{}.cpu.{} }};\n", .{ arch.genericName(), cpu.name, - ); + }); errdefer allocator.free(builtin_str); - const cache_hash = try std.fmt.allocPrint0(allocator, "{}\n{x}", cpu.name, cpu.features); + const cache_hash = try std.fmt.allocPrint0(allocator, "{}\n{x}", .{ cpu.name, cpu.features }); errdefer allocator.free(cache_hash); self.* = Self{ .allocator = allocator, .cpu_features = .{ .cpu = cpu }, - .llvm_cpu_name = cpu.llvm_name, + .llvm_cpu_name = if (cpu.llvm_name) |n| n.ptr else null, .llvm_features_str = null, .builtin_str = builtin_str, .cache_hash = cache_hash, @@ -728,20 +653,22 @@ const Stage2CpuFeatures = struct { fn createFromCpuFeatures( allocator: *mem.Allocator, arch: Target.Arch, - features: Target.Cpu.Feature.Set, + feature_set: Target.Cpu.Feature.Set, ) !*Self { const self = try allocator.create(Self); errdefer allocator.destroy(self); - const cache_hash = try std.fmt.allocPrint0(allocator, "\n{x}", features); + const cache_hash = try std.fmt.allocPrint0(allocator, "\n{x}", .{feature_set}); errdefer allocator.free(cache_hash); const generic_arch_name = arch.genericName(); var builtin_str_buffer = try std.Buffer.allocPrint( allocator, - "CpuFeatures{{ .features = Arch.{}.featureSet(&[_]Arch.{}.Feature{{\n", - generic_arch_name, - generic_arch_name, + \\CpuFeatures{{ + \\ .features = Target.{}.featureSet(&[_]Target.{}.Feature{{ + \\ + , + .{ generic_arch_name, generic_arch_name }, ); defer builtin_str_buffer.deinit(); @@ -750,7 +677,8 @@ const Stage2CpuFeatures = struct { // First, disable all features. // This way, we only get the ones the user requests. - for (arch.allFeatures()) |feature| { + const all_features = arch.allFeaturesList(); + for (all_features) |feature| { if (feature.llvm_name) |llvm_name| { try llvm_features_buffer.append("-"); try llvm_features_buffer.append(llvm_name); @@ -758,14 +686,16 @@ const Stage2CpuFeatures = struct { } } - for (features) |feature| { + for (all_features) |feature, index| { + if (!Target.Cpu.Feature.isEnabled(feature_set, @intCast(u7, index))) continue; + if (feature.llvm_name) |llvm_name| { try llvm_features_buffer.append("+"); try llvm_features_buffer.append(llvm_name); try llvm_features_buffer.append(","); } - try builtin_str_buffer.append(" ."); + try builtin_str_buffer.append(" ."); try builtin_str_buffer.append(feature.name); try builtin_str_buffer.append(",\n"); } @@ -774,13 +704,17 @@ const Stage2CpuFeatures = struct { llvm_features_buffer.shrink(llvm_features_buffer.len() - 1); } - try builtin_str_buffer.append("})};\n"); + try builtin_str_buffer.append( + \\ }), + \\}; + \\ + ); self.* = Self{ .allocator = allocator, - .cpu_features = .{ .features = features }, + .cpu_features = .{ .features = feature_set }, .llvm_cpu_name = null, - .llvm_features_str = llvm_features_buffer.toOwnedSlice(), + .llvm_features_str = llvm_features_buffer.toOwnedSlice().ptr, .builtin_str = builtin_str_buffer.toOwnedSlice(), .cache_hash = cache_hash, }; @@ -790,7 +724,7 @@ const Stage2CpuFeatures = struct { fn destroy(self: *Self) void { self.allocator.free(self.cache_hash); self.allocator.free(self.builtin_str); - if (self.llvm_features_str) |llvm_features_str| self.allocator.free(llvm_features_str); + // TODO if (self.llvm_features_str) |llvm_features_str| self.allocator.free(llvm_features_str); self.allocator.destroy(self); } }; @@ -803,6 +737,9 @@ export fn stage2_cpu_features_parse_cpu( ) Error { result.* = parseCpu(arch_name, cpu_name) catch |err| switch (err) { error.OutOfMemory => return .OutOfMemory, + error.UnknownCpu => return .UnknownCpu, + error.UnknownArchitecture => return .UnknownArchitecture, + error.UnknownSubArchitecture => return .UnknownSubArchitecture, }; return .None; } @@ -821,6 +758,10 @@ export fn stage2_cpu_features_parse_features( ) Error { result.* = parseFeatures(arch_name, features_text) catch |err| switch (err) { error.OutOfMemory => return .OutOfMemory, + error.UnknownCpuFeature => return .UnknownCpuFeature, + error.InvalidCpuFeatures => return .InvalidCpuFeatures, + error.UnknownArchitecture => return .UnknownArchitecture, + error.UnknownSubArchitecture => return .UnknownSubArchitecture, }; return .None; } @@ -853,6 +794,9 @@ export fn stage2_cpu_features_llvm( llvm_cpu_features, ) catch |err| switch (err) { error.OutOfMemory => return .OutOfMemory, + error.UnknownArchitecture => return .UnknownArchitecture, + error.UnknownSubArchitecture => return .UnknownSubArchitecture, + error.InvalidLlvmCpuFeaturesFormat => return .InvalidLlvmCpuFeaturesFormat, }; return .None; } diff --git a/src/error.cpp b/src/error.cpp index 9fc0383b1b..6c6abfcd22 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -58,6 +58,11 @@ const char *err_str(Error err) { case ErrorNotLazy: return "not lazy"; case ErrorIsAsync: return "is async"; case ErrorImportOutsidePkgPath: return "import of file outside package path"; + case ErrorUnknownCpu: return "unknown CPU"; + case ErrorUnknownSubArchitecture: return "unknown sub-architecture"; + case ErrorUnknownCpuFeature: return "unknown CPU feature"; + case ErrorInvalidCpuFeatures: return "invalid CPU features"; + case ErrorInvalidLlvmCpuFeaturesFormat: return "invalid LLVM CPU features format"; } return "(invalid error)"; } diff --git a/src/main.cpp b/src/main.cpp index d5804e795c..8e331461f8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -131,11 +131,6 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) { " --test-name-prefix [text] add prefix to all tests\n" " --test-cmd [arg] specify test execution command one arg at a time\n" " --test-cmd-bin appends test binary path to test cmd args\n" - "\n" - "Targets Options:\n" - " --list-features [arch] list available features for the given architecture\n" - " --list-cpus [arch] list available cpus for the given architecture\n" - " --show-dependencies list feature dependencies for each entry from --list-{features,cpus}\n" , arg0); return return_code; } @@ -160,88 +155,6 @@ static int print_libc_usage(const char *arg0, FILE *file, int return_code) { return return_code; } -static bool arch_available_in_llvm(ZigLLVM_ArchType arch) { - LLVMTargetRef target_ref; - char *err_msg = nullptr; - char triple_string[128]; - sprintf(triple_string, "%s-unknown-unknown-unknown", ZigLLVMGetArchTypeName(arch)); - return !LLVMGetTargetFromTriple(triple_string, &target_ref, &err_msg); -} - -static int print_target_list(FILE *f) { - ZigTarget native; - get_native_target(&native); - - fprintf(f, "Architectures:\n"); - size_t arch_count = target_arch_count(); - for (size_t arch_i = 0; arch_i < arch_count; arch_i += 1) { - ZigLLVM_ArchType arch = target_arch_enum(arch_i); - if (!arch_available_in_llvm(arch)) - continue; - const char *arch_name = target_arch_name(arch); - SubArchList sub_arch_list = target_subarch_list(arch); - size_t sub_count = target_subarch_count(sub_arch_list); - const char *arch_native_str = (native.arch == arch) ? " (native)" : ""; - fprintf(f, " %s%s\n", arch_name, arch_native_str); - for (size_t sub_i = 0; sub_i < sub_count; sub_i += 1) { - ZigLLVM_SubArchType sub = target_subarch_enum(sub_arch_list, sub_i); - const char *sub_name = target_subarch_name(sub); - const char *sub_native_str = (native.arch == arch && native.sub_arch == sub) ? " (native)" : ""; - fprintf(f, " %s%s\n", sub_name, sub_native_str); - } - } - - fprintf(f, "\nOperating Systems:\n"); - size_t os_count = target_os_count(); - for (size_t i = 0; i < os_count; i += 1) { - Os os_type = target_os_enum(i); - const char *native_str = (native.os == os_type) ? " (native)" : ""; - fprintf(f, " %s%s\n", target_os_name(os_type), native_str); - } - - fprintf(f, "\nC ABIs:\n"); - size_t abi_count = target_abi_count(); - for (size_t i = 0; i < abi_count; i += 1) { - ZigLLVM_EnvironmentType abi = target_abi_enum(i); - const char *native_str = (native.abi == abi) ? " (native)" : ""; - fprintf(f, " %s%s\n", target_abi_name(abi), native_str); - } - - fprintf(f, "\nAvailable libcs:\n"); - size_t libc_count = target_libc_count(); - for (size_t i = 0; i < libc_count; i += 1) { - ZigTarget libc_target; - target_libc_enum(i, &libc_target); - bool is_native = native.arch == libc_target.arch && - native.os == libc_target.os && - native.abi == libc_target.abi; - const char *native_str = is_native ? " (native)" : ""; - fprintf(f, " %s-%s-%s%s\n", target_arch_name(libc_target.arch), - target_os_name(libc_target.os), target_abi_name(libc_target.abi), native_str); - } - - fprintf(f, "\nAvailable glibc versions:\n"); - ZigGLibCAbi *glibc_abi; - Error err; - if ((err = glibc_load_metadata(&glibc_abi, get_zig_lib_dir(), true))) { - return EXIT_FAILURE; - } - for (size_t i = 0; i < glibc_abi->all_versions.length; i += 1) { - ZigGLibCVersion *this_ver = &glibc_abi->all_versions.at(i); - bool is_native = native.glibc_version != nullptr && - native.glibc_version->major == this_ver->major && - native.glibc_version->minor == this_ver->minor && - native.glibc_version->patch == this_ver->patch; - const char *native_str = is_native ? " (native)" : ""; - if (this_ver->patch == 0) { - fprintf(f, " %d.%d%s\n", this_ver->major, this_ver->minor, native_str); - } else { - fprintf(f, " %d.%d.%d%s\n", this_ver->major, this_ver->minor, this_ver->patch, native_str); - } - } - return EXIT_SUCCESS; -} - enum Cmd { CmdNone, CmdBuild, @@ -538,10 +451,6 @@ int main(int argc, char **argv) { const char *cpu = nullptr; const char *features = nullptr; - const char *targets_list_features_arch = nullptr; - const char *targets_list_cpus_arch = nullptr; - bool targets_show_dependencies = false; - ZigList llvm_argv = {0}; llvm_argv.append("zig (LLVM option parsing)"); @@ -792,8 +701,6 @@ int main(int argc, char **argv) { cur_pkg = cur_pkg->parent; } else if (strcmp(arg, "-ffunction-sections") == 0) { function_sections = true; - } else if (strcmp(arg, "--show-dependencies") == 0) { - targets_show_dependencies = true; } else if (i + 1 >= argc) { fprintf(stderr, "Expected another argument after %s\n", arg); return print_error_usage(arg0); @@ -951,10 +858,6 @@ int main(int argc, char **argv) { , argv[i]); return EXIT_FAILURE; } - } else if (strcmp(arg, "--list-features") == 0) { - targets_list_features_arch = argv[i]; - } else if (strcmp(arg, "--list-cpus") == 0) { - targets_list_cpus_arch = argv[i]; } else if (strcmp(arg, "-target-cpu") == 0) { cpu = argv[i]; } else if (strcmp(arg, "-target-feature") == 0) { @@ -1468,21 +1371,7 @@ int main(int argc, char **argv) { return main_exit(root_progress_node, EXIT_SUCCESS); } case CmdTargets: - if (targets_list_features_arch != nullptr) { - stage2_list_features_for_arch( - targets_list_features_arch, - strlen(targets_list_features_arch), - targets_show_dependencies); - return 0; - } else if (targets_list_cpus_arch != nullptr) { - stage2_list_cpus_for_arch( - targets_list_cpus_arch, - strlen(targets_list_cpus_arch), - targets_show_dependencies); - return 0; - } else { - return print_target_list(stdout); - } + return stage2_cmd_targets(); case CmdNone: return print_full_usage(arg0, stderr, EXIT_FAILURE); } diff --git a/src/userland.cpp b/src/userland.cpp index 93944f0089..22d2daa8e4 100644 --- a/src/userland.cpp +++ b/src/userland.cpp @@ -89,16 +89,6 @@ void stage2_progress_complete_one(Stage2ProgressNode *node) {} void stage2_progress_disable_tty(Stage2Progress *progress) {} void stage2_progress_update_node(Stage2ProgressNode *node, size_t completed_count, size_t estimated_total_items){} -void stage2_list_features_for_arch(const char *arch_name_ptr, size_t arch_name_len, bool show_subfeatures) { - const char *msg = "stage0 called stage2_list_features_for_arch"; - stage2_panic(msg, strlen(msg)); -} - -void stage2_list_cpus_for_arch(const char *arch_name_ptr, size_t arch_name_len, bool show_subfeatures) { - const char *msg = "stage0 called stage2_list_cpus_for_arch"; - stage2_panic(msg, strlen(msg)); -} - struct Stage2CpuFeatures { const char *llvm_cpu_name; const char *llvm_cpu_features; @@ -150,3 +140,8 @@ void stage2_cpu_features_get_builtin_str(const Stage2CpuFeatures *cpu_features, *ptr = cpu_features->builtin_str; *len = strlen(cpu_features->builtin_str); } + +int stage2_cmd_targets(void) { + const char *msg = "stage0 called stage2_cmd_targets"; + stage2_panic(msg, strlen(msg)); +} diff --git a/src/userland.h b/src/userland.h index 1fd40039a6..052321a718 100644 --- a/src/userland.h +++ b/src/userland.h @@ -78,6 +78,11 @@ enum Error { ErrorNotLazy, ErrorIsAsync, ErrorImportOutsidePkgPath, + ErrorUnknownCpu, + ErrorUnknownSubArchitecture, + ErrorUnknownCpuFeature, + ErrorInvalidCpuFeatures, + ErrorInvalidLlvmCpuFeaturesFormat, }; // ABI warning @@ -174,12 +179,6 @@ ZIG_EXTERN_C void stage2_progress_complete_one(Stage2ProgressNode *node); ZIG_EXTERN_C void stage2_progress_update_node(Stage2ProgressNode *node, size_t completed_count, size_t estimated_total_items); -// ABI warning -ZIG_EXTERN_C void stage2_list_features_for_arch(const char *arch_name_ptr, size_t arch_name_len, bool show_subfeatures); - -// ABI warning -ZIG_EXTERN_C void stage2_list_cpus_for_arch(const char *arch_name_ptr, size_t arch_name_len, bool show_subfeatures); - // ABI warning struct Stage2CpuFeatures; @@ -212,4 +211,8 @@ ZIG_EXTERN_C void stage2_cpu_features_get_builtin_str(const struct Stage2CpuFeat ZIG_EXTERN_C void stage2_cpu_features_get_cache_hash(const struct Stage2CpuFeatures *cpu_features, const char **ptr, size_t *len); +// ABI warning +ZIG_EXTERN_C int stage2_cmd_targets(void); + + #endif