aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
diff options
context:
space:
mode:
authorTimon Kruiper <timonkruiper@gmail.com>2021-03-24 15:26:09 +0100
committerAndrew Kelley <andrew@ziglang.org>2021-03-24 19:54:03 -0700
commit522707622e95ef17b94c7a3d78ca81cadde5274d (patch)
treef7518af54081f2e46b43ee5b324f1e7e303a25fe /src/Module.zig
parentd73a4940e0d907e017ce60d0a7183cd1618b3b39 (diff)
downloadzig-522707622e95ef17b94c7a3d78ca81cadde5274d.tar.gz
zig-522707622e95ef17b94c7a3d78ca81cadde5274d.zip
astgen: implement breaking from a block
Diffstat (limited to 'src/Module.zig')
-rw-r--r--src/Module.zig33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/Module.zig b/src/Module.zig
index a97ba364ab..e3e8fa813b 100644
--- a/src/Module.zig
+++ b/src/Module.zig
@@ -935,11 +935,11 @@ pub const Scope = struct {
break_count: usize = 0,
/// Tracks `break :foo bar` instructions so they can possibly be elided later if
/// the labeled block ends up not needing a result location pointer.
- labeled_breaks: std.ArrayListUnmanaged(zir.Inst.Index) = .{},
+ labeled_breaks: std.ArrayListUnmanaged(zir.Inst.Ref) = .{},
/// Tracks `store_to_block_ptr` instructions that correspond to break instructions
/// so they can possibly be elided later if the labeled block ends up not needing
/// a result location pointer.
- labeled_store_to_block_ptr_list: std.ArrayListUnmanaged(zir.Inst.Index) = .{},
+ labeled_store_to_block_ptr_list: std.ArrayListUnmanaged(zir.Inst.Ref) = .{},
pub const Label = struct {
token: ast.TokenIndex,
@@ -1222,6 +1222,35 @@ pub const Scope = struct {
});
}
+ pub fn addBreak(
+ gz: *GenZir,
+ break_block: zir.Inst.Index,
+ operand: zir.Inst.Ref,
+ ) !zir.Inst.Ref {
+ return try gz.add(.{
+ .tag = .@"break",
+ .data = .{ .@"break" = .{
+ .block_inst = break_block,
+ .operand = operand,
+ } },
+ });
+ }
+
+ pub fn addBreakVoid(
+ inner_gz: *GenZir,
+ block_gz: *GenZir,
+ break_block: zir.Inst.Index,
+ node_index: ast.Node.Index,
+ ) !zir.Inst.Ref {
+ return try inner_gz.add(.{
+ .tag = .break_void_node,
+ .data = .{ .break_void_node = .{
+ .src_node = block_gz.zir_code.decl.nodeIndexToRelative(node_index),
+ .block_inst = break_block,
+ } },
+ });
+ }
+
pub fn addBin(
gz: *GenZir,
tag: zir.Inst.Tag,