aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-07-19 17:35:14 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-07-20 12:19:17 -0700
commitea902ffe8f5f337b04f25b4efc69599db74d99ce (patch)
tree7c0f184759b9ca8ebf9db49aa04ac91042eff705 /src/Module.zig
parentcaa0de545e2f45a96ac3136178f478dab1c89ebd (diff)
downloadzig-ea902ffe8f5f337b04f25b4efc69599db74d99ce.tar.gz
zig-ea902ffe8f5f337b04f25b4efc69599db74d99ce.zip
Sema: reimplement runtime switch
Now supports multiple items pointing to the same body. This is a common pattern even when using a jump table, with multiple cases pointing to the same block of code. In the case of a range specified, the items are moved to branches in the else body. A future improvement may make it possible to have jump table items as well as ranges pointing to the same block of code.
Diffstat (limited to 'src/Module.zig')
-rw-r--r--src/Module.zig6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/Module.zig b/src/Module.zig
index c101221f2e..9fadf67c6f 100644
--- a/src/Module.zig
+++ b/src/Module.zig
@@ -1300,6 +1300,10 @@ pub const Scope = struct {
}
pub fn addInst(block: *Block, inst: Air.Inst) error{OutOfMemory}!Air.Inst.Ref {
+ return Air.indexToRef(try block.addInstAsIndex(inst));
+ }
+
+ pub fn addInstAsIndex(block: *Block, inst: Air.Inst) error{OutOfMemory}!Air.Inst.Index {
const sema = block.sema;
const gpa = sema.gpa;
@@ -1309,7 +1313,7 @@ pub const Scope = struct {
const result_index = @intCast(Air.Inst.Index, sema.air_instructions.len);
sema.air_instructions.appendAssumeCapacity(inst);
block.instructions.appendAssumeCapacity(result_index);
- return Air.indexToRef(result_index);
+ return result_index;
}
};
};