From 8c9a56311ac2774bf83eda4ea0aa9bde0aec125f Mon Sep 17 00:00:00 2001 From: Mathias Magnusson Date: Fri, 6 Jun 2025 19:49:42 +0200 Subject: assert that each block ends with an instruction which may do so --- src/compile.zig | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/compile.zig') diff --git a/src/compile.zig b/src/compile.zig index 0918d30..8cf61ca 100644 --- a/src/compile.zig +++ b/src/compile.zig @@ -66,6 +66,8 @@ pub const Instr = struct { true: BlockRef, false: BlockRef, + pub const may_end_block = {}; + pub fn sources(self: Branch) Sources { return Sources.fromSlice(&.{self.cond}) catch unreachable; } @@ -74,12 +76,16 @@ pub const Instr = struct { pub const Jump = struct { to: BlockRef, + pub const may_end_block = {}; + pub fn sources(_: Jump) Sources { return Sources.init(0) catch unreachable; } }; pub const Exit = struct { + pub const may_end_block = {}; + pub fn sources(_: Exit) Sources { return Sources.init(0) catch unreachable; } @@ -164,6 +170,9 @@ pub const BasicBlock = struct { if (instr.dest()) |dest| try self.vreg_last_use.put(allocator, dest, i); } + std.debug.assert(switch (self.instrs.items[self.instrs.items.len - 1].type) { + inline else => |ty| @hasDecl(@TypeOf(ty), "may_end_block"), + }); } }; -- cgit v1.2.3