From b3bc7f6e644972e94964e155bdc9a1463ed1a6a0 Mon Sep 17 00:00:00 2001 From: Mathias Magnusson Date: Fri, 1 Aug 2025 17:11:06 +0200 Subject: assert that block ending instructions happen only & exactly at the end of each block --- src/compile.zig | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/compile.zig b/src/compile.zig index 3ee3eb0..80279fb 100644 --- a/src/compile.zig +++ b/src/compile.zig @@ -98,8 +98,13 @@ pub const BasicBlock = struct { fn finalize(self: *BasicBlock, allocator: Allocator) !void { std.debug.assert(self.instrs.items.len > 0); + for (self.instrs.items[0 .. self.instrs.items.len - 1]) |instr| { + std.debug.assert(switch (instr.type) { + inline else => |ty| !@hasDecl(@TypeOf(ty), "ends_block"), + }); + } std.debug.assert(switch (self.instrs.getLast().type) { - inline else => |ty| @hasDecl(@TypeOf(ty), "may_end_block"), + inline else => |ty| @hasDecl(@TypeOf(ty), "ends_block"), }); self.vreg_last_use = .empty; @@ -195,7 +200,7 @@ pub const Instr = struct { true: BlockRef, false: BlockRef, - pub const may_end_block = {}; + pub const ends_block = {}; pub fn sources(_: Branch) Sources { return Sources.init(0) catch unreachable; @@ -205,7 +210,7 @@ pub const Instr = struct { pub const Jump = struct { to: BlockRef, - pub const may_end_block = {}; + pub const ends_block = {}; pub fn sources(_: Jump) Sources { return Sources.init(0) catch unreachable; @@ -233,7 +238,7 @@ pub const Instr = struct { pub const Return = struct { val: VReg, - pub const may_end_block = {}; + pub const ends_block = {}; pub fn sources(self: Return) Sources { return Sources.fromSlice(&.{self.val}) catch unreachable; -- cgit v1.2.3