| author | |
| committer | |
| log | 999777e73aa1bd06b05cbe53f8c2488877e18874 |
| tree | 2a12be70cf488ace84478c9f9f583dc50bfa9717 |
| parent | d000e53b291afc40da7d676553f1c9685a38f169 |
Nothing interesting here; literally just the bare minimum so I can work on this
on and off in a branch without worrying about merge conflicts in the non-backend
code.19 files changed, 172 insertions(+), 41 deletions(-)
CMakeLists.txt+1| ... | ... | @@ -543,6 +543,7 @@ set(ZIG_STAGE2_SOURCES |
| 543 | 543 | src/arch/arm/Mir.zig |
| 544 | 544 | src/arch/arm/abi.zig |
| 545 | 545 | src/arch/arm/bits.zig |
| 546 | src/arch/powerpc/CodeGen.zig | |
| 546 | 547 | src/arch/riscv64/abi.zig |
| 547 | 548 | src/arch/riscv64/bits.zig |
| 548 | 549 | src/arch/riscv64/CodeGen.zig |
lib/compiler/test_runner.zig+3-1| ... | ... | @@ -15,7 +15,9 @@ var fba_buffer: [8192]u8 = undefined; |
| 15 | 15 | var fba = std.heap.FixedBufferAllocator.init(&fba_buffer); |
| 16 | 16 | |
| 17 | 17 | const crippled = switch (builtin.zig_backend) { |
| 18 | .stage2_riscv64 => true, | |
| 18 | .stage2_powerpc, | |
| 19 | .stage2_riscv64, | |
| 20 | => true, | |
| 19 | 21 | else => false, |
| 20 | 22 | }; |
| 21 | 23 |
lib/std/builtin.zig+9-4| ... | ... | @@ -1110,6 +1110,9 @@ pub const CompilerBackend = enum(u64) { |
| 1110 | 1110 | /// The reference implementation self-hosted compiler of Zig, using the |
| 1111 | 1111 | /// spirv backend. |
| 1112 | 1112 | stage2_spirv64 = 11, |
| 1113 | /// The reference implementation self-hosted compiler of Zig, using the | |
| 1114 | /// powerpc backend. | |
| 1115 | stage2_powerpc = 12, | |
| 1113 | 1116 | |
| 1114 | 1117 | _, |
| 1115 | 1118 | }; |
| ... | ... | @@ -1143,10 +1146,12 @@ pub const panic: type = p: { |
| 1143 | 1146 | if (@hasDecl(root, "Panic")) { |
| 1144 | 1147 | break :p root.Panic; // Deprecated; use `panic` instead. |
| 1145 | 1148 | } |
| 1146 | if (builtin.zig_backend == .stage2_riscv64) { | |
| 1147 | break :p std.debug.simple_panic; | |
| 1148 | } | |
| 1149 | break :p std.debug.FullPanic(std.debug.defaultPanic); | |
| 1149 | break :p switch (builtin.zig_backend) { | |
| 1150 | .stage2_powerpc, | |
| 1151 | .stage2_riscv64, | |
| 1152 | => std.debug.simple_panic, | |
| 1153 | else => std.debug.FullPanic(std.debug.defaultPanic), | |
| 1154 | }; | |
| 1150 | 1155 | }; |
| 1151 | 1156 | |
| 1152 | 1157 | pub noinline fn returnError() void { |
lib/std/debug.zig+14-9| ... | ... | @@ -608,15 +608,20 @@ pub fn defaultPanic( |
| 608 | 608 | |
| 609 | 609 | // For backends that cannot handle the language features depended on by the |
| 610 | 610 | // default panic handler, we have a simpler panic handler: |
| 611 | if (builtin.zig_backend == .stage2_wasm or | |
| 612 | builtin.zig_backend == .stage2_arm or | |
| 613 | builtin.zig_backend == .stage2_aarch64 or | |
| 614 | builtin.zig_backend == .stage2_x86 or | |
| 615 | (builtin.zig_backend == .stage2_x86_64 and (builtin.target.ofmt != .elf and builtin.target.ofmt != .macho)) or | |
| 616 | builtin.zig_backend == .stage2_sparc64 or | |
| 617 | builtin.zig_backend == .stage2_spirv64) | |
| 618 | { | |
| 619 | @trap(); | |
| 611 | switch (builtin.zig_backend) { | |
| 612 | .stage2_aarch64, | |
| 613 | .stage2_arm, | |
| 614 | .stage2_powerpc, | |
| 615 | .stage2_riscv64, | |
| 616 | .stage2_spirv64, | |
| 617 | .stage2_wasm, | |
| 618 | .stage2_x86, | |
| 619 | => @trap(), | |
| 620 | .stage2_x86_64 => switch (builtin.target.ofmt) { | |
| 621 | .elf, .macho => {}, | |
| 622 | else => @trap(), | |
| 623 | }, | |
| 624 | else => {}, | |
| 620 | 625 | } |
| 621 | 626 | |
| 622 | 627 | switch (builtin.os.tag) { |
lib/std/mem.zig+4-2| ... | ... | @@ -675,10 +675,12 @@ test lessThan { |
| 675 | 675 | } |
| 676 | 676 | |
| 677 | 677 | const eqlBytes_allowed = switch (builtin.zig_backend) { |
| 678 | // These backends don't support vectors yet. | |
| 679 | .stage2_powerpc, | |
| 680 | .stage2_riscv64, | |
| 681 | => false, | |
| 678 | 682 | // The SPIR-V backend does not support the optimized path yet. |
| 679 | 683 | .stage2_spirv64 => false, |
| 680 | // The RISC-V does not support vectors. | |
| 681 | .stage2_riscv64 => false, | |
| 682 | 684 | // The naive memory comparison implementation is more useful for fuzzers to |
| 683 | 685 | // find interesting inputs. |
| 684 | 686 | else => !builtin.fuzz, |
lib/std/os/linux.zig+6-1| ... | ... | @@ -505,7 +505,12 @@ pub var elf_aux_maybe: ?[*]std.elf.Auxv = null; |
| 505 | 505 | /// Whether an external or internal getauxval implementation is used. |
| 506 | 506 | const extern_getauxval = switch (builtin.zig_backend) { |
| 507 | 507 | // Calling extern functions is not yet supported with these backends |
| 508 | .stage2_aarch64, .stage2_arm, .stage2_riscv64, .stage2_sparc64 => false, | |
| 508 | .stage2_aarch64, | |
| 509 | .stage2_arm, | |
| 510 | .stage2_powerpc, | |
| 511 | .stage2_riscv64, | |
| 512 | .stage2_sparc64, | |
| 513 | => false, | |
| 509 | 514 | else => !builtin.link_libc, |
| 510 | 515 | }; |
| 511 | 516 |
lib/std/start.zig+18-9| ... | ... | @@ -14,12 +14,16 @@ const start_sym_name = if (native_arch.isMIPS()) "__start" else "_start"; |
| 14 | 14 | // The self-hosted compiler is not fully capable of handling all of this start.zig file. |
| 15 | 15 | // Until then, we have simplified logic here for self-hosted. TODO remove this once |
| 16 | 16 | // self-hosted is capable enough to handle all of the real start.zig logic. |
| 17 | pub const simplified_logic = | |
| 18 | builtin.zig_backend == .stage2_x86 or | |
| 19 | builtin.zig_backend == .stage2_aarch64 or | |
| 20 | builtin.zig_backend == .stage2_arm or | |
| 21 | builtin.zig_backend == .stage2_sparc64 or | |
| 22 | builtin.zig_backend == .stage2_spirv64; | |
| 17 | pub const simplified_logic = switch (builtin.zig_backend) { | |
| 18 | .stage2_aarch64, | |
| 19 | .stage2_arm, | |
| 20 | .stage2_powerpc, | |
| 21 | .stage2_sparc64, | |
| 22 | .stage2_spirv64, | |
| 23 | .stage2_x86, | |
| 24 | => true, | |
| 25 | else => false, | |
| 26 | }; | |
| 23 | 27 | |
| 24 | 28 | comptime { |
| 25 | 29 | // No matter what, we import the root file, so that any export, test, comptime |
| ... | ... | @@ -669,9 +673,14 @@ pub inline fn callMain() u8 { |
| 669 | 673 | if (@typeInfo(ReturnType) != .error_union) @compileError(bad_main_ret); |
| 670 | 674 | |
| 671 | 675 | const result = root.main() catch |err| { |
| 672 | if (builtin.zig_backend == .stage2_riscv64) { | |
| 673 | std.debug.print("error: failed with error\n", .{}); | |
| 674 | return 1; | |
| 676 | switch (builtin.zig_backend) { | |
| 677 | .stage2_powerpc, | |
| 678 | .stage2_riscv64, | |
| 679 | => { | |
| 680 | std.debug.print("error: failed with error\n", .{}); | |
| 681 | return 1; | |
| 682 | }, | |
| 683 | else => {}, | |
| 675 | 684 | } |
| 676 | 685 | std.log.err("{s}", .{@errorName(err)}); |
| 677 | 686 | if (@errorReturnTrace()) |trace| { |
lib/std/testing.zig+7-1| ... | ... | @@ -32,7 +32,13 @@ pub var allocator_instance: std.heap.GeneralPurposeAllocator(.{ |
| 32 | 32 | pub var log_level = std.log.Level.warn; |
| 33 | 33 | |
| 34 | 34 | // Disable printing in tests for simple backends. |
| 35 | pub const backend_can_print = !(builtin.zig_backend == .stage2_spirv64 or builtin.zig_backend == .stage2_riscv64); | |
| 35 | pub const backend_can_print = switch (builtin.zig_backend) { | |
| 36 | .stage2_powerpc, | |
| 37 | .stage2_riscv64, | |
| 38 | .stage2_spirv64, | |
| 39 | => false, | |
| 40 | else => true, | |
| 41 | }; | |
| 36 | 42 | |
| 37 | 43 | fn print(comptime fmt: []const u8, args: anytype) void { |
| 38 | 44 | if (@inComptime()) { |
lib/ubsan_rt.zig+3-1| ... | ... | @@ -671,7 +671,9 @@ fn exportHandlerWithAbort( |
| 671 | 671 | } |
| 672 | 672 | |
| 673 | 673 | const can_build_ubsan = switch (builtin.zig_backend) { |
| 674 | .stage2_riscv64 => false, | |
| 674 | .stage2_powerpc, | |
| 675 | .stage2_riscv64, | |
| 676 | => false, | |
| 675 | 677 | else => true, |
| 676 | 678 | }; |
| 677 | 679 |
src/Zcu.zig+20| ... | ... | @@ -4500,6 +4500,26 @@ pub fn callconvSupported(zcu: *Zcu, cc: std.builtin.CallingConvention) union(enu |
| 4500 | 4500 | .naked => true, |
| 4501 | 4501 | else => false, |
| 4502 | 4502 | }, |
| 4503 | .stage2_powerpc => switch (target.cpu.arch) { | |
| 4504 | .powerpc, .powerpcle => switch (cc) { | |
| 4505 | .powerpc_sysv, | |
| 4506 | .powerpc_sysv_altivec, | |
| 4507 | .powerpc_aix, | |
| 4508 | .powerpc_aix_altivec, | |
| 4509 | .naked, | |
| 4510 | => true, | |
| 4511 | else => false, | |
| 4512 | }, | |
| 4513 | .powerpc64, .powerpc64le => switch (cc) { | |
| 4514 | .powerpc64_elf, | |
| 4515 | .powerpc64_elf_altivec, | |
| 4516 | .powerpc64_elf_v2, | |
| 4517 | .naked, | |
| 4518 | => true, | |
| 4519 | else => false, | |
| 4520 | }, | |
| 4521 | else => unreachable, | |
| 4522 | }, | |
| 4503 | 4523 | .stage2_riscv64 => switch (cc) { |
| 4504 | 4524 | .riscv64_lp64 => |opts| opts.incoming_stack_alignment == null, |
| 4505 | 4525 | .naked => true, |
src/arch/powerpc/CodeGen.zig created+52| ... | ... | @@ -0,0 +1,52 @@ |
| 1 | const builtin = @import("builtin"); | |
| 2 | const std = @import("std"); | |
| 3 | ||
| 4 | const Air = @import("../../Air.zig"); | |
| 5 | const codegen = @import("../../codegen.zig"); | |
| 6 | const InternPool = @import("../../InternPool.zig"); | |
| 7 | const link = @import("../../link.zig"); | |
| 8 | const Liveness = @import("../../Liveness.zig"); | |
| 9 | const Zcu = @import("../../Zcu.zig"); | |
| 10 | ||
| 11 | const assert = std.debug.assert; | |
| 12 | const log = std.log.scoped(.codegen); | |
| 13 | ||
| 14 | pub fn generate( | |
| 15 | bin_file: *link.File, | |
| 16 | pt: Zcu.PerThread, | |
| 17 | src_loc: Zcu.LazySrcLoc, | |
| 18 | func_index: InternPool.Index, | |
| 19 | air: Air, | |
| 20 | liveness: Liveness, | |
| 21 | code: *std.ArrayListUnmanaged(u8), | |
| 22 | debug_output: link.File.DebugInfoOutput, | |
| 23 | ) codegen.CodeGenError!void { | |
| 24 | _ = bin_file; | |
| 25 | _ = pt; | |
| 26 | _ = src_loc; | |
| 27 | _ = func_index; | |
| 28 | _ = air; | |
| 29 | _ = liveness; | |
| 30 | _ = code; | |
| 31 | _ = debug_output; | |
| 32 | ||
| 33 | unreachable; | |
| 34 | } | |
| 35 | ||
| 36 | pub fn generateLazy( | |
| 37 | bin_file: *link.File, | |
| 38 | pt: Zcu.PerThread, | |
| 39 | src_loc: Zcu.LazySrcLoc, | |
| 40 | lazy_sym: link.File.LazySymbol, | |
| 41 | code: *std.ArrayListUnmanaged(u8), | |
| 42 | debug_output: link.File.DebugInfoOutput, | |
| 43 | ) codegen.CodeGenError!void { | |
| 44 | _ = bin_file; | |
| 45 | _ = pt; | |
| 46 | _ = src_loc; | |
| 47 | _ = lazy_sym; | |
| 48 | _ = code; | |
| 49 | _ = debug_output; | |
| 50 | ||
| 51 | unreachable; | |
| 52 | } |
src/codegen.zig+6-1| ... | ... | @@ -37,6 +37,7 @@ fn importBackend(comptime backend: std.builtin.CompilerBackend) type { |
| 37 | 37 | return switch (backend) { |
| 38 | 38 | .stage2_aarch64 => @import("arch/aarch64/CodeGen.zig"), |
| 39 | 39 | .stage2_arm => @import("arch/arm/CodeGen.zig"), |
| 40 | .stage2_powerpc => @import("arch/powerpc/CodeGen.zig"), | |
| 40 | 41 | .stage2_riscv64 => @import("arch/riscv64/CodeGen.zig"), |
| 41 | 42 | .stage2_sparc64 => @import("arch/sparc64/CodeGen.zig"), |
| 42 | 43 | .stage2_x86_64 => @import("arch/x86_64/CodeGen.zig"), |
| ... | ... | @@ -61,6 +62,7 @@ pub fn generateFunction( |
| 61 | 62 | else => unreachable, |
| 62 | 63 | inline .stage2_aarch64, |
| 63 | 64 | .stage2_arm, |
| 65 | .stage2_powerpc, | |
| 64 | 66 | .stage2_riscv64, |
| 65 | 67 | .stage2_sparc64, |
| 66 | 68 | .stage2_x86_64, |
| ... | ... | @@ -86,7 +88,10 @@ pub fn generateLazyFunction( |
| 86 | 88 | zcu.getTarget(); |
| 87 | 89 | switch (target_util.zigBackend(target, false)) { |
| 88 | 90 | else => unreachable, |
| 89 | inline .stage2_x86_64, .stage2_riscv64 => |backend| { | |
| 91 | inline .stage2_powerpc, | |
| 92 | .stage2_riscv64, | |
| 93 | .stage2_x86_64, | |
| 94 | => |backend| { | |
| 90 | 95 | dev.check(devFeatureForBackend(backend)); |
| 91 | 96 | return importBackend(backend).generateLazy(lf, pt, src_loc, lazy_sym, code, debug_output); |
| 92 | 97 | }, |
src/dev.zig+15| ... | ... | @@ -26,6 +26,10 @@ pub const Env = enum { |
| 26 | 26 | /// - `zig build-* -fincremental -fno-llvm -fno-lld -target x86_64-linux --listen=-` |
| 27 | 27 | @"x86_64-linux", |
| 28 | 28 | |
| 29 | /// - sema | |
| 30 | /// - `zig build-* -fincremental -fno-llvm -fno-lld -target powerpc(64)(le)-linux --listen=-` | |
| 31 | @"powerpc-linux", | |
| 32 | ||
| 29 | 33 | /// - sema |
| 30 | 34 | /// - `zig build-* -fno-llvm -fno-lld -target riscv64-linux` |
| 31 | 35 | @"riscv64-linux", |
| ... | ... | @@ -70,6 +74,7 @@ pub const Env = enum { |
| 70 | 74 | .x86_64_backend, |
| 71 | 75 | .aarch64_backend, |
| 72 | 76 | .x86_backend, |
| 77 | .powerpc_backend, | |
| 73 | 78 | .riscv64_backend, |
| 74 | 79 | .sparc64_backend, |
| 75 | 80 | .spirv64_backend, |
| ... | ... | @@ -144,6 +149,15 @@ pub const Env = enum { |
| 144 | 149 | => true, |
| 145 | 150 | else => Env.sema.supports(feature), |
| 146 | 151 | }, |
| 152 | .@"powerpc-linux" => switch (feature) { | |
| 153 | .build_command, | |
| 154 | .stdio_listen, | |
| 155 | .incremental, | |
| 156 | .x86_64_backend, | |
| 157 | .elf_linker, | |
| 158 | => true, | |
| 159 | else => Env.sema.supports(feature), | |
| 160 | }, | |
| 147 | 161 | .@"riscv64-linux" => switch (feature) { |
| 148 | 162 | .riscv64_backend, |
| 149 | 163 | .elf_linker, |
| ... | ... | @@ -216,6 +230,7 @@ pub const Feature = enum { |
| 216 | 230 | x86_64_backend, |
| 217 | 231 | aarch64_backend, |
| 218 | 232 | x86_backend, |
| 233 | powerpc_backend, | |
| 219 | 234 | riscv64_backend, |
| 220 | 235 | sparc64_backend, |
| 221 | 236 | spirv64_backend, |
src/target.zig+6-4| ... | ... | @@ -736,6 +736,7 @@ pub fn supportsTailCall(target: std.Target, backend: std.builtin.CompilerBackend |
| 736 | 736 | |
| 737 | 737 | pub fn supportsThreads(target: std.Target, backend: std.builtin.CompilerBackend) bool { |
| 738 | 738 | return switch (backend) { |
| 739 | .stage2_powerpc => true, | |
| 739 | 740 | .stage2_x86_64 => target.ofmt == .macho or target.ofmt == .elf, |
| 740 | 741 | else => true, |
| 741 | 742 | }; |
| ... | ... | @@ -796,14 +797,15 @@ pub fn zigBackend(target: std.Target, use_llvm: bool) std.builtin.CompilerBacken |
| 796 | 797 | if (use_llvm) return .stage2_llvm; |
| 797 | 798 | if (target.ofmt == .c) return .stage2_c; |
| 798 | 799 | return switch (target.cpu.arch) { |
| 799 | .wasm32, .wasm64 => .stage2_wasm, | |
| 800 | .arm, .armeb, .thumb, .thumbeb => .stage2_arm, | |
| 801 | .x86_64 => .stage2_x86_64, | |
| 802 | .x86 => .stage2_x86, | |
| 803 | 800 | .aarch64, .aarch64_be => .stage2_aarch64, |
| 801 | .arm, .armeb, .thumb, .thumbeb => .stage2_arm, | |
| 802 | .powerpc, .powerpcle, .powerpc64, .powerpc64le => .stage2_powerpc, | |
| 804 | 803 | .riscv64 => .stage2_riscv64, |
| 805 | 804 | .sparc64 => .stage2_sparc64, |
| 806 | 805 | .spirv64 => .stage2_spirv64, |
| 806 | .wasm32, .wasm64 => .stage2_wasm, | |
| 807 | .x86 => .stage2_x86, | |
| 808 | .x86_64 => .stage2_x86_64, | |
| 807 | 809 | else => .other, |
| 808 | 810 | }; |
| 809 | 811 | } |
test/cases/compile_errors/@import_zon_bad_type.zig+3-3| ... | ... | @@ -117,9 +117,9 @@ export fn testMutablePointer() void { |
| 117 | 117 | // tmp.zig:37:38: note: imported here |
| 118 | 118 | // neg_inf.zon:1:1: error: expected type '?u8' |
| 119 | 119 | // tmp.zig:57:28: note: imported here |
| 120 | // neg_inf.zon:1:1: error: expected type 'tmp.testNonExhaustiveEnum__enum_496' | |
| 120 | // neg_inf.zon:1:1: error: expected type 'tmp.testNonExhaustiveEnum__enum_499' | |
| 121 | 121 | // tmp.zig:62:39: note: imported here |
| 122 | // neg_inf.zon:1:1: error: expected type 'tmp.testUntaggedUnion__union_498' | |
| 122 | // neg_inf.zon:1:1: error: expected type 'tmp.testUntaggedUnion__union_501' | |
| 123 | 123 | // tmp.zig:67:44: note: imported here |
| 124 | // neg_inf.zon:1:1: error: expected type 'tmp.testTaggedUnionVoid__union_501' | |
| 124 | // neg_inf.zon:1:1: error: expected type 'tmp.testTaggedUnionVoid__union_504' | |
| 125 | 125 | // tmp.zig:72:50: note: imported here |
test/cases/compile_errors/anytype_param_requires_comptime.zig+1-1| ... | ... | @@ -15,6 +15,6 @@ pub export fn entry() void { |
| 15 | 15 | // error |
| 16 | 16 | // |
| 17 | 17 | // :7:25: error: unable to resolve comptime value |
| 18 | // :7:25: note: initializer of comptime-only struct 'tmp.S.foo__anon_470.C' must be comptime-known | |
| 18 | // :7:25: note: initializer of comptime-only struct 'tmp.S.foo__anon_473.C' must be comptime-known | |
| 19 | 19 | // :4:16: note: struct requires comptime because of this field |
| 20 | 20 | // :4:16: note: types are not available at runtime |
test/cases/compile_errors/bogus_method_call_on_slice.zig+1-1| ... | ... | @@ -16,5 +16,5 @@ pub export fn entry2() void { |
| 16 | 16 | // |
| 17 | 17 | // :3:6: error: no field or member function named 'copy' in '[]const u8' |
| 18 | 18 | // :9:8: error: no field or member function named 'bar' in '@TypeOf(.{})' |
| 19 | // :12:18: error: no field or member function named 'bar' in 'tmp.entry2__struct_474' | |
| 19 | // :12:18: error: no field or member function named 'bar' in 'tmp.entry2__struct_477' | |
| 20 | 20 | // :12:6: note: struct declared here |
test/cases/compile_errors/coerce_anon_struct.zig+1-1| ... | ... | @@ -6,6 +6,6 @@ export fn foo() void { |
| 6 | 6 | |
| 7 | 7 | // error |
| 8 | 8 | // |
| 9 | // :4:16: error: expected type 'tmp.T', found 'tmp.foo__struct_463' | |
| 9 | // :4:16: error: expected type 'tmp.T', found 'tmp.foo__struct_466' | |
| 10 | 10 | // :3:16: note: struct declared here |
| 11 | 11 | // :1:11: note: struct declared here |
test/cases/compile_errors/redundant_try.zig+2-2| ... | ... | @@ -44,9 +44,9 @@ comptime { |
| 44 | 44 | // |
| 45 | 45 | // :5:23: error: expected error union type, found 'comptime_int' |
| 46 | 46 | // :10:23: error: expected error union type, found '@TypeOf(.{})' |
| 47 | // :15:23: error: expected error union type, found 'tmp.test2__struct_500' | |
| 47 | // :15:23: error: expected error union type, found 'tmp.test2__struct_503' | |
| 48 | 48 | // :15:23: note: struct declared here |
| 49 | // :20:27: error: expected error union type, found 'tmp.test3__struct_502' | |
| 49 | // :20:27: error: expected error union type, found 'tmp.test3__struct_505' | |
| 50 | 50 | // :20:27: note: struct declared here |
| 51 | 51 | // :25:23: error: expected error union type, found 'struct { comptime *const [5:0]u8 = "hello" }' |
| 52 | 52 | // :31:13: error: expected error union type, found 'u32' |