diff options
author | Mathias Magnusson <mathias@magnusson.space> | 2025-08-01 17:11:06 +0200 |
---|---|---|
committer | Mathias Magnusson <mathias@magnusson.space> | 2025-08-01 17:11:06 +0200 |
commit | b3bc7f6e644972e94964e155bdc9a1463ed1a6a0 (patch) | |
tree | 5b540448711b5e407ec97df49d4aa0c762b27be0 | |
parent | 71995702df08e91ae2aea7c23def5ffee0835cd1 (diff) | |
download | huginn-b3bc7f6e644972e94964e155bdc9a1463ed1a6a0.tar.gz |
assert that block ending instructions happen only & exactly at the end of each block
-rw-r--r-- | src/compile.zig | 13 |
1 files 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; |