From 9088d40e838b62c8f8ea0e6e68616b72e7704b27 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 13 Apr 2021 12:38:06 -0700 Subject: stage2: rename zir to Zir since it now uses top level fields --- src/test.zig | 1 - 1 file changed, 1 deletion(-) (limited to 'src/test.zig') diff --git a/src/test.zig b/src/test.zig index ca3f073e14..e08f9da37d 100644 --- a/src/test.zig +++ b/src/test.zig @@ -2,7 +2,6 @@ const std = @import("std"); const link = @import("link.zig"); const Compilation = @import("Compilation.zig"); const Allocator = std.mem.Allocator; -const zir = @import("zir.zig"); const Package = @import("Package.zig"); const introspect = @import("introspect.zig"); const build_options = @import("build_options"); -- cgit v1.2.3 From 7dd33d431612cd8511eaea8dcabdca44b354e14b Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 6 May 2021 17:48:38 -0700 Subject: stage2: fix compile errors in test harness --- BRANCH_TODO | 8 ++-- lib/std/elf.zig | 14 +++---- src/test.zig | 2 +- test/stage2/test.zig | 114 +++++++++++++++++++++++++-------------------------- 4 files changed, 69 insertions(+), 69 deletions(-) (limited to 'src/test.zig') diff --git a/BRANCH_TODO b/BRANCH_TODO index e6b0d8ec83..3508a66f42 100644 --- a/BRANCH_TODO +++ b/BRANCH_TODO @@ -1,7 +1,7 @@ - * namespace decls table can't reference ZIR memory because it can get modified on updates - - change it for astgen worker to compare old and new ZIR, updating existing - namespaces & decls, and creating a changelist. - * reimplement semaDecl + * get stage2 tests passing + * modify stage2 tests so that only 1 uses _start and the rest use + pub fn main + * use a hash map for instructions because the array is too big - no, actually modify the Zir.Inst.Ref strategy so that each decl gets their indexes starting at 0 so that we can use an array to store Sema diff --git a/lib/std/elf.zig b/lib/std/elf.zig index c37cc74223..147045e720 100644 --- a/lib/std/elf.zig +++ b/lib/std/elf.zig @@ -4,13 +4,13 @@ // The MIT license requires this copyright notice to be included in all copies // and substantial portions of the software. const std = @import("std.zig"); -const builtin = std.builtin; const io = std.io; const os = std.os; const math = std.math; const mem = std.mem; const debug = std.debug; const File = std.fs.File; +const native_endian = @import("builtin").target.cpu.arch.endian(); pub const AT_NULL = 0; pub const AT_IGNORE = 1; @@ -336,7 +336,7 @@ pub const ET = enum(u16) { /// All integers are native endian. pub const Header = struct { - endian: builtin.Endian, + endian: std.builtin.Endian, machine: EM, is_64: bool, entry: u64, @@ -380,7 +380,7 @@ pub const Header = struct { ELFDATA2MSB => .Big, else => return error.InvalidElfEndian, }; - const need_bswap = endian != std.builtin.endian; + const need_bswap = endian != native_endian; const is_64 = switch (hdr32.e_ident[EI_CLASS]) { ELFCLASS32 => false, @@ -426,7 +426,7 @@ pub fn ProgramHeaderIterator(ParseSource: anytype) type { try self.parse_source.reader().readNoEof(mem.asBytes(&phdr)); // ELF endianness matches native endianness. - if (self.elf_header.endian == std.builtin.endian) return phdr; + if (self.elf_header.endian == native_endian) return phdr; // Convert fields to native endianness. bswapAllFields(Elf64_Phdr, &phdr); @@ -439,7 +439,7 @@ pub fn ProgramHeaderIterator(ParseSource: anytype) type { try self.parse_source.reader().readNoEof(mem.asBytes(&phdr)); // ELF endianness does NOT match native endianness. - if (self.elf_header.endian != std.builtin.endian) { + if (self.elf_header.endian != native_endian) { // Convert fields to native endianness. bswapAllFields(Elf32_Phdr, &phdr); } @@ -476,7 +476,7 @@ pub fn SectionHeaderIterator(ParseSource: anytype) type { try self.parse_source.reader().readNoEof(mem.asBytes(&shdr)); // ELF endianness matches native endianness. - if (self.elf_header.endian == std.builtin.endian) return shdr; + if (self.elf_header.endian == native_endian) return shdr; // Convert fields to native endianness. return Elf64_Shdr{ @@ -499,7 +499,7 @@ pub fn SectionHeaderIterator(ParseSource: anytype) type { try self.parse_source.reader().readNoEof(mem.asBytes(&shdr)); // ELF endianness does NOT match native endianness. - if (self.elf_header.endian != std.builtin.endian) { + if (self.elf_header.endian != native_endian) { // Convert fields to native endianness. shdr = .{ .sh_name = @byteSwap(@TypeOf(shdr.sh_name), shdr.sh_name), diff --git a/src/test.zig b/src/test.zig index e08f9da37d..03c1ee0dcd 100644 --- a/src/test.zig +++ b/src/test.zig @@ -135,7 +135,7 @@ pub const TestContext = struct { /// to Executable. output_mode: std.builtin.OutputMode, updates: std.ArrayList(Update), - object_format: ?std.builtin.ObjectFormat = null, + object_format: ?std.Target.ObjectFormat = null, emit_h: bool = false, llvm_backend: bool = false, diff --git a/test/stage2/test.zig b/test/stage2/test.zig index 09a6c37fe2..440042798f 100644 --- a/test/stage2/test.zig +++ b/test/stage2/test.zig @@ -66,7 +66,7 @@ pub fn addCases(ctx: *TestContext) !void { ); // Now change the message only case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ print(); \\ \\ exit(); @@ -98,7 +98,7 @@ pub fn addCases(ctx: *TestContext) !void { ); // Now we print it twice. case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ print(); \\ print(); \\ @@ -136,7 +136,7 @@ pub fn addCases(ctx: *TestContext) !void { { var case = ctx.exe("adding numbers at comptime", linux_x64); case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ asm volatile ("syscall" \\ : \\ : [number] "{rax}" (1), @@ -161,7 +161,7 @@ pub fn addCases(ctx: *TestContext) !void { { var case = ctx.exe("adding numbers at runtime and comptime", linux_x64); case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ add(3, 4); \\ \\ exit(); @@ -185,7 +185,7 @@ pub fn addCases(ctx: *TestContext) !void { ); // comptime function call case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ exit(); \\} \\ @@ -209,7 +209,7 @@ pub fn addCases(ctx: *TestContext) !void { ); // Inline function call case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ var x: usize = 3; \\ const y = add(1, 2, x); \\ exit(y - 6); @@ -236,7 +236,7 @@ pub fn addCases(ctx: *TestContext) !void { { var case = ctx.exe("subtracting numbers at runtime", linux_x64); case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ sub(7, 4); \\ \\ exit(); @@ -262,7 +262,7 @@ pub fn addCases(ctx: *TestContext) !void { { var case = ctx.exe("@TypeOf", linux_x64); case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ var x: usize = 0; \\ const z = @TypeOf(x, @as(u128, 5)); \\ assert(z == u128); @@ -287,7 +287,7 @@ pub fn addCases(ctx: *TestContext) !void { "", ); case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ const z = @TypeOf(true); \\ assert(z == bool); \\ @@ -311,7 +311,7 @@ pub fn addCases(ctx: *TestContext) !void { "", ); case.addError( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ const z = @TypeOf(true, 1); \\ unreachable; \\} @@ -321,7 +321,7 @@ pub fn addCases(ctx: *TestContext) !void { { var case = ctx.exe("assert function", linux_x64); case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ add(3, 4); \\ \\ exit(); @@ -351,7 +351,7 @@ pub fn addCases(ctx: *TestContext) !void { // Tests copying a register. For the `c = a + b`, it has to // preserve both a and b, because they are both used later. case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ add(3, 4); \\ \\ exit(); @@ -383,7 +383,7 @@ pub fn addCases(ctx: *TestContext) !void { // More stress on the liveness detection. case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ add(3, 4); \\ \\ exit(); @@ -419,7 +419,7 @@ pub fn addCases(ctx: *TestContext) !void { // Requires a second move. The register allocator should figure out to re-use rax. case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ add(3, 4); \\ \\ exit(); @@ -456,7 +456,7 @@ pub fn addCases(ctx: *TestContext) !void { // Now we test integer return values. case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ assert(add(3, 4) == 7); \\ assert(add(20, 10) == 30); \\ @@ -486,7 +486,7 @@ pub fn addCases(ctx: *TestContext) !void { // Local mutable variables. case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ assert(add(3, 4) == 7); \\ assert(add(20, 10) == 30); \\ @@ -520,7 +520,7 @@ pub fn addCases(ctx: *TestContext) !void { // Optionals case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ const a: u32 = 2; \\ const b: ?u32 = a; \\ const c = b.?; @@ -544,7 +544,7 @@ pub fn addCases(ctx: *TestContext) !void { // While loops case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ var i: u32 = 0; \\ while (i < 4) : (i += 1) print(); \\ assert(i == 4); @@ -583,7 +583,7 @@ pub fn addCases(ctx: *TestContext) !void { // inline while requires the condition to be comptime known. case.addError( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ var i: u32 = 0; \\ inline while (i < 4) : (i += 1) print(); \\ assert(i == 4); @@ -620,7 +620,7 @@ pub fn addCases(ctx: *TestContext) !void { // Labeled blocks (no conditional branch) case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ assert(add(3, 4) == 20); \\ \\ exit(); @@ -657,7 +657,7 @@ pub fn addCases(ctx: *TestContext) !void { // This catches a possible bug in the logic for re-using dying operands. case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ assert(add(3, 4) == 116); \\ \\ exit(); @@ -699,7 +699,7 @@ pub fn addCases(ctx: *TestContext) !void { // Spilling registers to the stack. case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ assert(add(3, 4) == 791); \\ \\ exit(); @@ -751,7 +751,7 @@ pub fn addCases(ctx: *TestContext) !void { // Reusing the registers of dead operands playing nicely with conditional branching. case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ assert(add(3, 4) == 791); \\ assert(add(4, 3) == 79); \\ @@ -813,7 +813,7 @@ pub fn addCases(ctx: *TestContext) !void { // Character literals and multiline strings. case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ const ignore = \\ \\ cool thx \\ \\ @@ -846,7 +846,7 @@ pub fn addCases(ctx: *TestContext) !void { // Global const. case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ add(aa, bb); \\ \\ exit(); @@ -878,7 +878,7 @@ pub fn addCases(ctx: *TestContext) !void { // Array access. case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ assert("hello"[0] == 'h'); \\ \\ exit(); @@ -904,7 +904,7 @@ pub fn addCases(ctx: *TestContext) !void { // Array access to a global array. case.addCompareOutput( \\const hello = "hello".*; - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ assert(hello[1] == 'e'); \\ \\ exit(); @@ -929,7 +929,7 @@ pub fn addCases(ctx: *TestContext) !void { // 64bit set stack case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ var i: u64 = 0xFFEEDDCCBBAA9988; \\ assert(i == 0xFFEEDDCCBBAA9988); \\ @@ -955,7 +955,7 @@ pub fn addCases(ctx: *TestContext) !void { // Basic for loop case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ for ("hello") |_| print(); \\ \\ exit(); @@ -990,7 +990,7 @@ pub fn addCases(ctx: *TestContext) !void { { var case = ctx.exe("basic import", linux_x64); case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ @import("print.zig").print(); \\ exit(); \\} @@ -1027,14 +1027,14 @@ pub fn addCases(ctx: *TestContext) !void { { var case = ctx.exe("redundant comptime", linux_x64); case.addError( - \\export fn _start() void { + \\pub export fn _start() void { \\ var a: comptime u32 = 0; \\} , &.{":2:21: error: redundant comptime keyword in already comptime scope"}, ); case.addError( - \\export fn _start() void { + \\pub export fn _start() void { \\ comptime { \\ var a: u32 = comptime 0; \\ } @@ -1046,7 +1046,7 @@ pub fn addCases(ctx: *TestContext) !void { { var case = ctx.exe("import private", linux_x64); case.addError( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ @import("print.zig").print(); \\ exit(); \\} @@ -1104,7 +1104,7 @@ pub fn addCases(ctx: *TestContext) !void { }); ctx.compileError("compileError", linux_x64, - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ @compileError("this is an error"); \\ unreachable; \\} @@ -1113,7 +1113,7 @@ pub fn addCases(ctx: *TestContext) !void { { var case = ctx.obj("variable shadowing", linux_x64); case.addError( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ var i: u32 = 10; \\ var i: u32 = 10; \\ unreachable; @@ -1124,7 +1124,7 @@ pub fn addCases(ctx: *TestContext) !void { }); case.addError( \\var testing: i64 = 10; - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ var testing: i64 = 20; \\ unreachable; \\} @@ -1136,7 +1136,7 @@ pub fn addCases(ctx: *TestContext) !void { var case = ctx.obj("@compileLog", linux_x64); // The other compile error prevents emission of a "found compile log" statement. case.addError( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ const b = true; \\ var f: u32 = 1; \\ @compileLog(b, 20, f, x); @@ -1154,7 +1154,7 @@ pub fn addCases(ctx: *TestContext) !void { // Now only compile log statements remain. One per Decl. case.addError( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ const b = true; \\ var f: u32 = 1; \\ @compileLog(b, 20, f, x); @@ -1192,7 +1192,7 @@ pub fn addCases(ctx: *TestContext) !void { // Break out of loop case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ while (true) { \\ break; \\ } @@ -1213,7 +1213,7 @@ pub fn addCases(ctx: *TestContext) !void { "", ); case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ foo: while (true) { \\ break :foo; \\ } @@ -1236,7 +1236,7 @@ pub fn addCases(ctx: *TestContext) !void { // Continue in loop case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ var i: u64 = 0; \\ while (true) : (i+=1) { \\ if (i == 4) exit(); @@ -1257,7 +1257,7 @@ pub fn addCases(ctx: *TestContext) !void { "", ); case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ var i: u64 = 0; \\ foo: while (true) : (i+=1) { \\ if (i == 4) exit(); @@ -1318,7 +1318,7 @@ pub fn addCases(ctx: *TestContext) !void { { var case = ctx.exe("compile error in inline fn call fixed", linux_x64); case.addError( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ var x: usize = 3; \\ const y = add(10, 2, x); \\ exit(y - 6); @@ -1341,7 +1341,7 @@ pub fn addCases(ctx: *TestContext) !void { , &[_][]const u8{":8:18: error: bad"}); case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ var x: usize = 3; \\ const y = add(1, 2, x); \\ exit(y - 6); @@ -1368,7 +1368,7 @@ pub fn addCases(ctx: *TestContext) !void { { var case = ctx.exe("recursive inline function", linux_x64); case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ const y = fibonacci(7); \\ exit(y - 21); \\} @@ -1394,7 +1394,7 @@ pub fn addCases(ctx: *TestContext) !void { // Without storing source locations relative to the owner decl, the compile error // here would be off by 2 bytes (from the "7" -> "999"). case.addError( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ const y = fibonacci(999); \\ exit(y - 21); \\} @@ -1418,7 +1418,7 @@ pub fn addCases(ctx: *TestContext) !void { { var case = ctx.exe("orelse at comptime", linux_x64); case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ const i: ?u64 = 0; \\ const orelsed = i orelse 5; \\ assert(orelsed == 0); @@ -1440,7 +1440,7 @@ pub fn addCases(ctx: *TestContext) !void { "", ); case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ const i: ?u64 = null; \\ const orelsed = i orelse 5; \\ assert(orelsed == 5); @@ -1466,7 +1466,7 @@ pub fn addCases(ctx: *TestContext) !void { { var case = ctx.exe("only 1 function and it gets updated", linux_x64); case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ asm volatile ("syscall" \\ : \\ : [number] "{rax}" (60), // exit @@ -1479,7 +1479,7 @@ pub fn addCases(ctx: *TestContext) !void { "", ); case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ asm volatile ("syscall" \\ : \\ : [number] "{rax}" (231), // exit_group @@ -1495,7 +1495,7 @@ pub fn addCases(ctx: *TestContext) !void { { var case = ctx.exe("passing u0 to function", linux_x64); case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ doNothing(0); \\ exit(); \\} @@ -1516,7 +1516,7 @@ pub fn addCases(ctx: *TestContext) !void { { var case = ctx.exe("catch at comptime", linux_x64); case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ const i: anyerror!u64 = 0; \\ const caught = i catch 5; \\ assert(caught == 0); @@ -1539,7 +1539,7 @@ pub fn addCases(ctx: *TestContext) !void { ); case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ const i: anyerror!u64 = error.B; \\ const caught = i catch 5; \\ assert(caught == 5); @@ -1562,7 +1562,7 @@ pub fn addCases(ctx: *TestContext) !void { ); case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ const a: anyerror!comptime_int = 42; \\ const b: *const comptime_int = &(a catch unreachable); \\ assert(b.* == 42); @@ -1584,7 +1584,7 @@ pub fn addCases(ctx: *TestContext) !void { , ""); case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ const a: anyerror!u32 = error.B; \\ _ = &(a catch |err| assert(err == error.B)); \\ exit(); @@ -1604,7 +1604,7 @@ pub fn addCases(ctx: *TestContext) !void { , ""); case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ const a: anyerror!u32 = error.Bar; \\ a catch |err| assert(err == error.Bar); \\ @@ -1628,7 +1628,7 @@ pub fn addCases(ctx: *TestContext) !void { var case = ctx.exe("merge error sets", linux_x64); case.addCompareOutput( - \\export fn _start() noreturn { + \\pub export fn _start() noreturn { \\ const E = error{ A, B, D } || error { A, B, C }; \\ const a = E.A; \\ const b = E.B; -- cgit v1.2.3 From 6361d7a92824ff2b883625d133fec4fccfb3eef7 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 8 May 2021 16:11:07 -0700 Subject: stage2 test harness: report multiple failures so you can debug more than one thing at a time --- src/test.zig | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) (limited to 'src/test.zig') diff --git a/src/test.zig b/src/test.zig index 7dfd163f4b..d578c3aa22 100644 --- a/src/test.zig +++ b/src/test.zig @@ -14,7 +14,7 @@ const CrossTarget = std.zig.CrossTarget; const zig_h = link.File.C.zig_h; -const hr = "=" ** 40; +const hr = "=" ** 80; test "self-hosted" { var ctx = TestContext.init(); @@ -541,6 +541,8 @@ pub const TestContext = struct { }; defer std.testing.allocator.free(global_cache_directory.path.?); + var fail_count: usize = 0; + for (self.cases.items) |case| { if (build_options.skip_non_native and case.target.getCpuArch() != std.Target.current.cpu.arch) continue; @@ -558,14 +560,21 @@ pub const TestContext = struct { progress.initial_delay_ns = 0; progress.refresh_rate_ns = 0; - try self.runOneCase( + self.runOneCase( std.testing.allocator, &prg_node, case, zig_lib_directory, &thread_pool, global_cache_directory, - ); + ) catch |err| { + fail_count += 1; + std.debug.print("test '{s}' failed: {s}\n\n", .{ case.name, @errorName(err) }); + }; + } + if (fail_count != 0) { + std.debug.print("{d} tests failed\n", .{fail_count}); + return error.TestFailed; } } @@ -693,8 +702,7 @@ pub const TestContext = struct { } } // TODO print generated C code - std.debug.print("Test failed.\n", .{}); - std.process.exit(1); + return error.UnexpectedCompileErrors; } } @@ -817,10 +825,8 @@ pub const TestContext = struct { } if (any_failed) { - std.debug.print("\nTest case '{s}' failed, update_index={d}.\n", .{ - case.name, update_index, - }); - std.process.exit(1); + std.debug.print("\nupdate_index={d} ", .{update_index}); + return error.WrongCompileErrors; } }, .Execution => |expected_stdout| { @@ -908,11 +914,11 @@ pub const TestContext = struct { .cwd_dir = tmp.dir, .cwd = tmp_dir_path, }) catch |err| { - std.debug.print("\nThe following command failed with {s}:\n", .{ - @errorName(err), + std.debug.print("\nupdate_index={d} The following command failed with {s}:\n", .{ + update_index, @errorName(err), }); dumpArgs(argv.items); - return error.ZigTestFailed; + return error.ChildProcessExecution; }; }; var test_node = update_node.start("test", 0); @@ -927,7 +933,7 @@ pub const TestContext = struct { exec_result.stderr, case.name, code, }); dumpArgs(argv.items); - return error.ZigTestFailed; + return error.ChildProcessExecution; } }, else => { @@ -935,7 +941,7 @@ pub const TestContext = struct { exec_result.stderr, case.name, }); dumpArgs(argv.items); - return error.ZigTestFailed; + return error.ChildProcessExecution; }, } try std.testing.expectEqualStrings(expected_stdout, exec_result.stdout); @@ -1016,26 +1022,26 @@ pub const TestContext = struct { while (try iterator.next()) |phdr| { if (phdr.p_type != std.elf.PT_LOAD) { std.debug.print("Encountered unexpected ELF program header: type {}\n", .{phdr.p_type}); - std.process.exit(1); + return error.UnexpectedElfProgramHeader; } if (phdr.p_paddr != phdr.p_vaddr) { std.debug.print("Physical address does not match virtual address in ELF header!\n", .{}); - std.process.exit(1); + return error.PhysicalAddressMismatchVirt; } if (phdr.p_filesz != phdr.p_memsz) { std.debug.print("Physical size does not match virtual size in ELF header!\n", .{}); - std.process.exit(1); + return error.PhysicalSizeMismatchVirt; } if ((try file.pread(interpreter.bus.RAM[phdr.p_paddr .. phdr.p_paddr + phdr.p_filesz], phdr.p_offset)) != phdr.p_filesz) { std.debug.print("Read less than expected from ELF file!", .{}); - std.process.exit(1); + return error.ElfFileEof; } std.log.scoped(.spu2_test).debug("Loaded 0x{x} bytes to 0x{x:0<4}\n", .{ phdr.p_filesz, phdr.p_paddr }); none_loaded = false; } if (none_loaded) { std.debug.print("No data found in ELF file!\n", .{}); - std.process.exit(1); + return error.EmptyElfFile; } } @@ -1052,7 +1058,7 @@ pub const TestContext = struct { try interpreter.ExecuteBlock(block_size); if (pre_ip == interpreter.ip) { std.debug.print("Infinite loop detected in SPU II test!\n", .{}); - std.process.exit(1); + return error.InfiniteLoop; } } } -- cgit v1.2.3 From 07606d12daabe8c201dba3d5b27e702ce58d0ffb Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 15 May 2021 21:25:42 -0700 Subject: stage2: remove SPU Mark II backend As it stands, the backend is incomplete, and there is no active contributor, making it dead weight. However, anyone is free to resurrect this backend at any time. --- BRANCH_TODO | 2 - src/codegen.zig | 67 -------------- src/codegen/spu-mk2.zig | 170 ------------------------------------ src/codegen/spu-mk2/interpreter.zig | 166 ----------------------------------- src/test.zig | 115 +----------------------- test/stage2/spu-ii.zig | 23 ----- test/stage2/test.zig | 1 - 7 files changed, 1 insertion(+), 543 deletions(-) delete mode 100644 src/codegen/spu-mk2.zig delete mode 100644 src/codegen/spu-mk2/interpreter.zig delete mode 100644 test/stage2/spu-ii.zig (limited to 'src/test.zig') diff --git a/BRANCH_TODO b/BRANCH_TODO index fcd3ecbec6..50a0246989 100644 --- a/BRANCH_TODO +++ b/BRANCH_TODO @@ -1,5 +1,3 @@ - * get stage2 tests passing - - spu-ii test is saying "unimplemented" for some reason * modify stage2 tests so that only 1 uses _start and the rest use pub fn main * modify stage2 CBE tests so that only 1 uses pub export main and the diff --git a/src/codegen.zig b/src/codegen.zig index 6e37692093..374361ebce 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -117,7 +117,6 @@ pub fn generateSymbol( //.sparcv9 => return Function(.sparcv9).generateSymbol(bin_file, src_loc, typed_value, code, debug_output), //.sparcel => return Function(.sparcel).generateSymbol(bin_file, src_loc, typed_value, code, debug_output), //.s390x => return Function(.s390x).generateSymbol(bin_file, src_loc, typed_value, code, debug_output), - .spu_2 => return Function(.spu_2).generateSymbol(bin_file, src_loc, typed_value, code, debug_output), //.tce => return Function(.tce).generateSymbol(bin_file, src_loc, typed_value, code, debug_output), //.tcele => return Function(.tcele).generateSymbol(bin_file, src_loc, typed_value, code, debug_output), //.thumb => return Function(.thumb).generateSymbol(bin_file, src_loc, typed_value, code, debug_output), @@ -2204,11 +2203,6 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { .riscv64 => { mem.writeIntLittle(u32, try self.code.addManyAsArray(4), Instruction.ebreak.toU32()); }, - .spu_2 => { - try self.code.resize(self.code.items.len + 2); - var instr = Instruction{ .condition = .always, .input0 = .zero, .input1 = .zero, .modify_flags = false, .output = .discard, .command = .undefined1 }; - mem.writeIntLittle(u16, self.code.items[self.code.items.len - 2 ..][0..2], @bitCast(u16, instr)); - }, .arm, .armeb => { writeInt(u32, try self.code.addManyAsArray(4), Instruction.bkpt(0).toU32()); }, @@ -2317,53 +2311,6 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { return self.fail(inst.base.src, "TODO implement calling runtime known function pointer", .{}); } }, - .spu_2 => { - if (inst.func.value()) |func_value| { - if (info.args.len != 0) { - return self.fail(inst.base.src, "TODO implement call with more than 0 parameters", .{}); - } - if (func_value.castTag(.function)) |func_payload| { - const func = func_payload.data; - const got_addr = if (self.bin_file.cast(link.File.Elf)) |elf_file| blk: { - const got = &elf_file.program_headers.items[elf_file.phdr_got_index.?]; - break :blk @intCast(u16, got.p_vaddr + func.owner_decl.link.elf.offset_table_index * 2); - } else if (self.bin_file.cast(link.File.Coff)) |coff_file| - @intCast(u16, coff_file.offset_table_virtual_address + func.owner_decl.link.coff.offset_table_index * 2) - else - unreachable; - - assert(func.owner_decl.has_tv); - const return_type = func.owner_decl.ty.fnReturnType(); - // First, push the return address, then jump; if noreturn, don't bother with the first step - // TODO: implement packed struct -> u16 at comptime and move the bitcast here - var instr = Instruction{ .condition = .always, .input0 = .immediate, .input1 = .zero, .modify_flags = false, .output = .jump, .command = .load16 }; - if (return_type.zigTypeTag() == .NoReturn) { - try self.code.resize(self.code.items.len + 4); - mem.writeIntLittle(u16, self.code.items[self.code.items.len - 4 ..][0..2], @bitCast(u16, instr)); - mem.writeIntLittle(u16, self.code.items[self.code.items.len - 2 ..][0..2], got_addr); - return MCValue.unreach; - } else { - try self.code.resize(self.code.items.len + 8); - var push = Instruction{ .condition = .always, .input0 = .immediate, .input1 = .zero, .modify_flags = false, .output = .push, .command = .ipget }; - mem.writeIntLittle(u16, self.code.items[self.code.items.len - 8 ..][0..2], @bitCast(u16, push)); - mem.writeIntLittle(u16, self.code.items[self.code.items.len - 6 ..][0..2], @as(u16, 4)); - mem.writeIntLittle(u16, self.code.items[self.code.items.len - 4 ..][0..2], @bitCast(u16, instr)); - mem.writeIntLittle(u16, self.code.items[self.code.items.len - 2 ..][0..2], got_addr); - switch (return_type.zigTypeTag()) { - .Void => return MCValue{ .none = {} }, - .NoReturn => unreachable, - else => return self.fail(inst.base.src, "TODO implement fn call with non-void return value", .{}), - } - } - } else if (func_value.castTag(.extern_fn)) |_| { - return self.fail(inst.base.src, "TODO implement calling extern functions", .{}); - } else { - return self.fail(inst.base.src, "TODO implement calling bitcasted functions", .{}); - } - } else { - return self.fail(inst.base.src, "TODO implement calling runtime known function pointer", .{}); - } - }, .arm, .armeb => { for (info.args) |mc_arg, arg_i| { const arg = inst.args[arg_i]; @@ -3176,19 +3123,6 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { if (!inst.is_volatile and inst.base.isUnused()) return MCValue.dead; switch (arch) { - .spu_2 => { - if (inst.inputs.len > 0 or inst.output_constraint != null) { - return self.fail(inst.base.src, "TODO implement inline asm inputs / outputs for SPU Mark II", .{}); - } - if (mem.eql(u8, inst.asm_source, "undefined0")) { - try self.code.resize(self.code.items.len + 2); - var instr = Instruction{ .condition = .always, .input0 = .zero, .input1 = .zero, .modify_flags = false, .output = .discard, .command = .undefined0 }; - mem.writeIntLittle(u16, self.code.items[self.code.items.len - 2 ..][0..2], @bitCast(u16, instr)); - return MCValue.none; - } else { - return self.fail(inst.base.src, "TODO implement support for more SPU II assembly instructions", .{}); - } - }, .arm, .armeb => { for (inst.inputs) |input, i| { if (input.len < 3 or input[0] != '{' or input[input.len - 1] != '}') { @@ -4503,7 +4437,6 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { .i386 => @import("codegen/x86.zig"), .x86_64 => @import("codegen/x86_64.zig"), .riscv64 => @import("codegen/riscv64.zig"), - .spu_2 => @import("codegen/spu-mk2.zig"), .arm, .armeb => @import("codegen/arm.zig"), .aarch64, .aarch64_be, .aarch64_32 => @import("codegen/aarch64.zig"), else => struct { diff --git a/src/codegen/spu-mk2.zig b/src/codegen/spu-mk2.zig deleted file mode 100644 index 542862caca..0000000000 --- a/src/codegen/spu-mk2.zig +++ /dev/null @@ -1,170 +0,0 @@ -const std = @import("std"); - -pub const Interpreter = @import("spu-mk2/interpreter.zig").Interpreter; - -pub const ExecutionCondition = enum(u3) { - always = 0, - when_zero = 1, - not_zero = 2, - greater_zero = 3, - less_than_zero = 4, - greater_or_equal_zero = 5, - less_or_equal_zero = 6, - overflow = 7, -}; - -pub const InputBehaviour = enum(u2) { - zero = 0, - immediate = 1, - peek = 2, - pop = 3, -}; - -pub const OutputBehaviour = enum(u2) { - discard = 0, - push = 1, - jump = 2, - jump_relative = 3, -}; - -pub const Command = enum(u5) { - copy = 0, - ipget = 1, - get = 2, - set = 3, - store8 = 4, - store16 = 5, - load8 = 6, - load16 = 7, - undefined0 = 8, - undefined1 = 9, - frget = 10, - frset = 11, - bpget = 12, - bpset = 13, - spget = 14, - spset = 15, - add = 16, - sub = 17, - mul = 18, - div = 19, - mod = 20, - @"and" = 21, - @"or" = 22, - xor = 23, - not = 24, - signext = 25, - rol = 26, - ror = 27, - bswap = 28, - asr = 29, - lsl = 30, - lsr = 31, -}; - -pub const Instruction = packed struct { - condition: ExecutionCondition, - input0: InputBehaviour, - input1: InputBehaviour, - modify_flags: bool, - output: OutputBehaviour, - command: Command, - reserved: u1 = 0, - - pub fn format(instr: Instruction, comptime fmt: []const u8, options: std.fmt.FormatOptions, out: anytype) !void { - try std.fmt.format(out, "0x{x:0<4} ", .{@bitCast(u16, instr)}); - try out.writeAll(switch (instr.condition) { - .always => " ", - .when_zero => "== 0", - .not_zero => "!= 0", - .greater_zero => " > 0", - .less_than_zero => " < 0", - .greater_or_equal_zero => ">= 0", - .less_or_equal_zero => "<= 0", - .overflow => "ovfl", - }); - try out.writeAll(" "); - try out.writeAll(switch (instr.input0) { - .zero => "zero", - .immediate => "imm ", - .peek => "peek", - .pop => "pop ", - }); - try out.writeAll(" "); - try out.writeAll(switch (instr.input1) { - .zero => "zero", - .immediate => "imm ", - .peek => "peek", - .pop => "pop ", - }); - try out.writeAll(" "); - try out.writeAll(switch (instr.command) { - .copy => "copy ", - .ipget => "ipget ", - .get => "get ", - .set => "set ", - .store8 => "store8 ", - .store16 => "store16 ", - .load8 => "load8 ", - .load16 => "load16 ", - .undefined0 => "undefined", - .undefined1 => "undefined", - .frget => "frget ", - .frset => "frset ", - .bpget => "bpget ", - .bpset => "bpset ", - .spget => "spget ", - .spset => "spset ", - .add => "add ", - .sub => "sub ", - .mul => "mul ", - .div => "div ", - .mod => "mod ", - .@"and" => "and ", - .@"or" => "or ", - .xor => "xor ", - .not => "not ", - .signext => "signext ", - .rol => "rol ", - .ror => "ror ", - .bswap => "bswap ", - .asr => "asr ", - .lsl => "lsl ", - .lsr => "lsr ", - }); - try out.writeAll(" "); - try out.writeAll(switch (instr.output) { - .discard => "discard", - .push => "push ", - .jump => "jmp ", - .jump_relative => "rjmp ", - }); - try out.writeAll(" "); - try out.writeAll(if (instr.modify_flags) - "+ flags" - else - " "); - } -}; - -pub const FlagRegister = packed struct { - zero: bool, - negative: bool, - carry: bool, - carry_enabled: bool, - interrupt0_enabled: bool, - interrupt1_enabled: bool, - interrupt2_enabled: bool, - interrupt3_enabled: bool, - reserved: u8 = 0, -}; - -pub const Register = enum { - dummy, - - pub fn allocIndex(self: Register) ?u4 { - return null; - } -}; - -pub const callee_preserved_regs = [_]Register{}; diff --git a/src/codegen/spu-mk2/interpreter.zig b/src/codegen/spu-mk2/interpreter.zig deleted file mode 100644 index 1ec99546c6..0000000000 --- a/src/codegen/spu-mk2/interpreter.zig +++ /dev/null @@ -1,166 +0,0 @@ -const std = @import("std"); -const log = std.log.scoped(.SPU_2_Interpreter); -const spu = @import("../spu-mk2.zig"); -const FlagRegister = spu.FlagRegister; -const Instruction = spu.Instruction; -const ExecutionCondition = spu.ExecutionCondition; - -pub fn Interpreter(comptime Bus: type) type { - return struct { - ip: u16 = 0, - sp: u16 = undefined, - bp: u16 = undefined, - fr: FlagRegister = @bitCast(FlagRegister, @as(u16, 0)), - /// This is set to true when we hit an undefined0 instruction, allowing it to - /// be used as a trap for testing purposes - undefined0: bool = false, - /// This is set to true when we hit an undefined1 instruction, allowing it to - /// be used as a trap for testing purposes. undefined1 is used as a breakpoint. - undefined1: bool = false, - bus: Bus, - - pub fn ExecuteBlock(self: *@This(), comptime size: ?u32) !void { - var count: usize = 0; - while (size == null or count < size.?) { - count += 1; - var instruction = @bitCast(Instruction, self.bus.read16(self.ip)); - - log.debug("Executing {}\n", .{instruction}); - - self.ip +%= 2; - - const execute = switch (instruction.condition) { - .always => true, - .not_zero => !self.fr.zero, - .when_zero => self.fr.zero, - .overflow => self.fr.carry, - ExecutionCondition.greater_or_equal_zero => !self.fr.negative, - else => return error.Unimplemented, - }; - - if (execute) { - const val0 = switch (instruction.input0) { - .zero => @as(u16, 0), - .immediate => i: { - const val = self.bus.read16(@intCast(u16, self.ip)); - self.ip +%= 2; - break :i val; - }, - else => |e| e: { - // peek or pop; show value at current SP, and if pop, increment sp - const val = self.bus.read16(self.sp); - if (e == .pop) { - self.sp +%= 2; - } - break :e val; - }, - }; - const val1 = switch (instruction.input1) { - .zero => @as(u16, 0), - .immediate => i: { - const val = self.bus.read16(@intCast(u16, self.ip)); - self.ip +%= 2; - break :i val; - }, - else => |e| e: { - // peek or pop; show value at current SP, and if pop, increment sp - const val = self.bus.read16(self.sp); - if (e == .pop) { - self.sp +%= 2; - } - break :e val; - }, - }; - - const output: u16 = switch (instruction.command) { - .get => self.bus.read16(self.bp +% (2 *% val0)), - .set => a: { - self.bus.write16(self.bp +% 2 *% val0, val1); - break :a val1; - }, - .load8 => self.bus.read8(val0), - .load16 => self.bus.read16(val0), - .store8 => a: { - const val = @truncate(u8, val1); - self.bus.write8(val0, val); - break :a val; - }, - .store16 => a: { - self.bus.write16(val0, val1); - break :a val1; - }, - .copy => val0, - .add => a: { - var val: u16 = undefined; - self.fr.carry = @addWithOverflow(u16, val0, val1, &val); - break :a val; - }, - .sub => a: { - var val: u16 = undefined; - self.fr.carry = @subWithOverflow(u16, val0, val1, &val); - break :a val; - }, - .spset => a: { - self.sp = val0; - break :a val0; - }, - .bpset => a: { - self.bp = val0; - break :a val0; - }, - .frset => a: { - const val = (@bitCast(u16, self.fr) & val1) | (val0 & ~val1); - self.fr = @bitCast(FlagRegister, val); - break :a val; - }, - .bswap => (val0 >> 8) | (val0 << 8), - .bpget => self.bp, - .spget => self.sp, - .ipget => self.ip +% (2 *% val0), - .lsl => val0 << 1, - .lsr => val0 >> 1, - .@"and" => val0 & val1, - .@"or" => val0 | val1, - .xor => val0 ^ val1, - .not => ~val0, - .undefined0 => { - self.undefined0 = true; - // Break out of the loop, and let the caller decide what to do - return; - }, - .undefined1 => { - self.undefined1 = true; - // Break out of the loop, and let the caller decide what to do - return; - }, - .signext => if ((val0 & 0x80) != 0) - (val0 & 0xFF) | 0xFF00 - else - (val0 & 0xFF), - else => return error.Unimplemented, - }; - - switch (instruction.output) { - .discard => {}, - .push => { - self.sp -%= 2; - self.bus.write16(self.sp, output); - }, - .jump => { - self.ip = output; - }, - else => return error.Unimplemented, - } - if (instruction.modify_flags) { - self.fr.negative = (output & 0x8000) != 0; - self.fr.zero = (output == 0x0000); - } - } else { - if (instruction.input0 == .immediate) self.ip +%= 2; - if (instruction.input1 == .immediate) self.ip +%= 2; - break; - } - } - } - }; -} diff --git a/src/test.zig b/src/test.zig index d578c3aa22..8410aa398e 100644 --- a/src/test.zig +++ b/src/test.zig @@ -862,10 +862,7 @@ pub const TestContext = struct { }); } else switch (case.target.getExternalExecutor()) { .native => try argv.append(exe_path), - .unavailable => { - try self.runInterpreterIfAvailable(allocator, &exec_node, case, tmp.dir, bin_name); - return; // Pass test. - }, + .unavailable => return, // Pass test. .qemu => |qemu_bin_name| if (enable_qemu) { // TODO Ability for test cases to specify whether to link libc. @@ -953,116 +950,6 @@ pub const TestContext = struct { } } - fn runInterpreterIfAvailable( - self: *TestContext, - gpa: *Allocator, - node: *std.Progress.Node, - case: Case, - tmp_dir: std.fs.Dir, - bin_name: []const u8, - ) !void { - const arch = case.target.cpu_arch orelse return; - switch (arch) { - .spu_2 => return self.runSpu2Interpreter(gpa, node, case, tmp_dir, bin_name), - else => return, - } - } - - fn runSpu2Interpreter( - self: *TestContext, - gpa: *Allocator, - update_node: *std.Progress.Node, - case: Case, - tmp_dir: std.fs.Dir, - bin_name: []const u8, - ) !void { - const spu = @import("codegen/spu-mk2.zig"); - if (case.target.os_tag) |os| { - if (os != .freestanding) { - std.debug.panic("Only freestanding makes sense for SPU-II tests!", .{}); - } - } else { - std.debug.panic("SPU_2 has no native OS, check the test!", .{}); - } - - var interpreter = spu.Interpreter(struct { - RAM: [0x10000]u8 = undefined, - - pub fn read8(bus: @This(), addr: u16) u8 { - return bus.RAM[addr]; - } - pub fn read16(bus: @This(), addr: u16) u16 { - return std.mem.readIntLittle(u16, bus.RAM[addr..][0..2]); - } - - pub fn write8(bus: *@This(), addr: u16, val: u8) void { - bus.RAM[addr] = val; - } - - pub fn write16(bus: *@This(), addr: u16, val: u16) void { - std.mem.writeIntLittle(u16, bus.RAM[addr..][0..2], val); - } - }){ - .bus = .{}, - }; - - { - var load_node = update_node.start("load", 0); - load_node.activate(); - defer load_node.end(); - - var file = try tmp_dir.openFile(bin_name, .{ .read = true }); - defer file.close(); - - const header = try std.elf.Header.read(&file); - var iterator = header.program_header_iterator(&file); - - var none_loaded = true; - - while (try iterator.next()) |phdr| { - if (phdr.p_type != std.elf.PT_LOAD) { - std.debug.print("Encountered unexpected ELF program header: type {}\n", .{phdr.p_type}); - return error.UnexpectedElfProgramHeader; - } - if (phdr.p_paddr != phdr.p_vaddr) { - std.debug.print("Physical address does not match virtual address in ELF header!\n", .{}); - return error.PhysicalAddressMismatchVirt; - } - if (phdr.p_filesz != phdr.p_memsz) { - std.debug.print("Physical size does not match virtual size in ELF header!\n", .{}); - return error.PhysicalSizeMismatchVirt; - } - if ((try file.pread(interpreter.bus.RAM[phdr.p_paddr .. phdr.p_paddr + phdr.p_filesz], phdr.p_offset)) != phdr.p_filesz) { - std.debug.print("Read less than expected from ELF file!", .{}); - return error.ElfFileEof; - } - std.log.scoped(.spu2_test).debug("Loaded 0x{x} bytes to 0x{x:0<4}\n", .{ phdr.p_filesz, phdr.p_paddr }); - none_loaded = false; - } - if (none_loaded) { - std.debug.print("No data found in ELF file!\n", .{}); - return error.EmptyElfFile; - } - } - - var exec_node = update_node.start("execute", 0); - exec_node.activate(); - defer exec_node.end(); - - var blocks: u16 = 1000; - const block_size = 1000; - while (!interpreter.undefined0) { - const pre_ip = interpreter.ip; - if (blocks > 0) { - blocks -= 1; - try interpreter.ExecuteBlock(block_size); - if (pre_ip == interpreter.ip) { - std.debug.print("Infinite loop detected in SPU II test!\n", .{}); - return error.InfiniteLoop; - } - } - } - } }; fn dumpArgs(argv: []const []const u8) void { diff --git a/test/stage2/spu-ii.zig b/test/stage2/spu-ii.zig deleted file mode 100644 index 11e6714b75..0000000000 --- a/test/stage2/spu-ii.zig +++ /dev/null @@ -1,23 +0,0 @@ -const std = @import("std"); -const TestContext = @import("../../src/test.zig").TestContext; - -const spu = std.zig.CrossTarget{ - .cpu_arch = .spu_2, - .os_tag = .freestanding, -}; - -pub fn addCases(ctx: *TestContext) !void { - { - var case = ctx.exe("SPU-II Basic Test", spu); - case.addCompareOutput( - \\fn killEmulator() noreturn { - \\ asm volatile ("undefined0"); - \\ unreachable; - \\} - \\ - \\pub export fn _start() noreturn { - \\ killEmulator(); - \\} - , ""); - } -} diff --git a/test/stage2/test.zig b/test/stage2/test.zig index dfe3e7cbdf..03bdf73475 100644 --- a/test/stage2/test.zig +++ b/test/stage2/test.zig @@ -13,7 +13,6 @@ const linux_x64 = std.zig.CrossTarget{ pub fn addCases(ctx: *TestContext) !void { try @import("cbe.zig").addCases(ctx); - try @import("spu-ii.zig").addCases(ctx); try @import("arm.zig").addCases(ctx); try @import("aarch64.zig").addCases(ctx); try @import("llvm.zig").addCases(ctx); -- cgit v1.2.3 From 731c35f15a1469c9523b71476f1e069d5bcfd979 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 17 May 2021 15:35:24 -0700 Subject: stage2: get rid of NameHash Previously, stage2 used a global decl_table for all Decl objects, keyed by a 16-byte name hash that was hopefully unique. Now, there is a tree of Namespace objects that own their named Decl objects. --- BRANCH_TODO | 25 ------------------------- src/Compilation.zig | 1 - src/Module.zig | 7 ------- src/Package.zig | 11 ----------- src/main.zig | 4 ---- src/test.zig | 1 - 6 files changed, 49 deletions(-) (limited to 'src/test.zig') diff --git a/BRANCH_TODO b/BRANCH_TODO index e9d2e26a9f..9860335c48 100644 --- a/BRANCH_TODO +++ b/BRANCH_TODO @@ -3,21 +3,6 @@ their indexes starting at 0 so that we can use an array to store Sema results rather than a map. - * get rid of NameHash - * handle decl collision with usingnamespace - * the decl doing the looking up needs to create a decl dependency - on each usingnamespace decl - * handle usingnamespace cycles - - * compile error for return inside defer expression - - * when block has noreturn statement - - avoid emitting defers - - compile error for unreachable code - - * detect `return error.Foo` and emit ZIR that unconditionally generates errdefers - * `return`: check return operand and generate errdefers if necessary - * have failed_trees and just put the file in there - this way we can emit all the parse errors not just the first one - but maybe we want just the first one? @@ -58,13 +43,3 @@ * repl: if you try `run` with -ofmt=c you get an access denied error because it tries to execute the .c file as a child process instead of executing `zig run` on it. - -=== file issues: === - - * C backend: honor the exported symbol name. Right now if you do `pub fn main` - it generates bogus C code because the `@export` name is not honored, and it allows - the `main` which should be not exported, to clobber the exported symbol name. - - * get the test runner and `zig test` working - - get behavior tests passing for stage2 - diff --git a/src/Compilation.zig b/src/Compilation.zig index ff50ce8d6c..a5c365fa40 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -3563,7 +3563,6 @@ fn buildOutputFromZig( .handle = special_dir, }, .root_src_path = src_basename, - .namespace_hash = Package.root_namespace_hash, }; const root_name = src_basename[0 .. src_basename.len - std.fs.path.extension(src_basename).len]; const target = comp.getTarget(); diff --git a/src/Module.zig b/src/Module.zig index afa29d65fd..54a3c86aed 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -798,8 +798,6 @@ pub const Var = struct { pub const Scope = struct { tag: Tag, - pub const NameHash = [16]u8; - pub fn cast(base: *Scope, comptime T: type) ?*T { if (base.tag != T.base_tag) return null; @@ -839,7 +837,6 @@ pub const Scope = struct { .namespace => return @fieldParentPtr(Namespace, "base", base).file_scope.sub_file_path, .file => return @fieldParentPtr(File, "base", base).sub_file_path, .block => unreachable, - .decl_ref => unreachable, } } @@ -861,10 +858,6 @@ pub const Scope = struct { /// Namespace owned by structs, enums, unions, and opaques for decls. namespace, block, - /// Used for simple error reporting. Only contains a reference to a - /// `Decl` for use with `srcDecl` and `ownerDecl`. - /// Has no parents or children. - decl_ref, }; /// The container that structs, enums, unions, and opaques have. diff --git a/src/Package.zig b/src/Package.zig index 25a9f55d63..5fec4be3d2 100644 --- a/src/Package.zig +++ b/src/Package.zig @@ -11,22 +11,15 @@ const Module = @import("Module.zig"); pub const Table = std.StringHashMapUnmanaged(*Package); -pub const root_namespace_hash: Module.Scope.NameHash = .{ - 0, 0, 6, 6, 6, 0, 0, 0, - 6, 9, 0, 0, 0, 4, 2, 0, -}; - root_src_directory: Compilation.Directory, /// Relative to `root_src_directory`. May contain path separators. root_src_path: []const u8, table: Table = .{}, parent: ?*Package = null, -namespace_hash: Module.Scope.NameHash, /// Whether to free `root_src_directory` on `destroy`. root_src_directory_owned: bool = false, /// Allocate a Package. No references to the slices passed are kept. -/// Don't forget to set `namespace_hash` later. pub fn create( gpa: *Allocator, /// Null indicates the current working directory @@ -50,7 +43,6 @@ pub fn create( }, .root_src_path = owned_src_path, .root_src_directory_owned = true, - .namespace_hash = undefined, }; return ptr; @@ -82,14 +74,12 @@ pub fn createWithDir( }, .root_src_directory_owned = true, .root_src_path = owned_src_path, - .namespace_hash = undefined, }; } else { ptr.* = .{ .root_src_directory = directory, .root_src_directory_owned = false, .root_src_path = owned_src_path, - .namespace_hash = undefined, }; } return ptr; @@ -129,6 +119,5 @@ pub fn add(pkg: *Package, gpa: *Allocator, name: []const u8, package: *Package) pub fn addAndAdopt(parent: *Package, gpa: *Allocator, name: []const u8, child: *Package) !void { assert(child.parent == null); // make up your mind, who is the parent?? child.parent = parent; - child.namespace_hash = std.zig.hashName(parent.namespace_hash, ":", name); return parent.add(gpa, name, child); } diff --git a/src/main.zig b/src/main.zig index e6cfc5f1a9..5b0b62a886 100644 --- a/src/main.zig +++ b/src/main.zig @@ -630,7 +630,6 @@ fn buildOutputType( var pkg_tree_root: Package = .{ .root_src_directory = .{ .path = null, .handle = fs.cwd() }, .root_src_path = &[0]u8{}, - .namespace_hash = Package.root_namespace_hash, }; defer freePkgTree(gpa, &pkg_tree_root, false); var cur_pkg: *Package = &pkg_tree_root; @@ -1768,7 +1767,6 @@ fn buildOutputType( if (root_pkg) |pkg| { pkg.table = pkg_tree_root.table; pkg_tree_root.table = .{}; - pkg.namespace_hash = pkg_tree_root.namespace_hash; } const self_exe_path = try fs.selfExePathAlloc(arena); @@ -2657,7 +2655,6 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v .handle = try zig_lib_directory.handle.openDir(std_special, .{}), }, .root_src_path = "build_runner.zig", - .namespace_hash = Package.root_namespace_hash, }; defer root_pkg.root_src_directory.handle.close(); @@ -2703,7 +2700,6 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v var build_pkg: Package = .{ .root_src_directory = build_directory, .root_src_path = build_zig_basename, - .namespace_hash = undefined, }; try root_pkg.addAndAdopt(arena, "@build", &build_pkg); diff --git a/src/test.zig b/src/test.zig index 33dd57003a..a5f5b8c2b0 100644 --- a/src/test.zig +++ b/src/test.zig @@ -611,7 +611,6 @@ pub const TestContext = struct { var root_pkg: Package = .{ .root_src_directory = .{ .path = tmp_dir_path, .handle = tmp.dir }, .root_src_path = tmp_src_path, - .namespace_hash = Package.root_namespace_hash, }; defer root_pkg.table.deinit(allocator); -- cgit v1.2.3