diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-03-22 23:46:51 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-03-22 23:47:13 -0700 |
| commit | d24be85be88737db8399b492931647056c547614 (patch) | |
| tree | e6079e363a2b5bcdc1b100b1149c313b13197f41 /src/Module.zig | |
| parent | 568f333681e6ecf8c60c5bbe04ea1e494d966d48 (diff) | |
| download | zig-d24be85be88737db8399b492931647056c547614.tar.gz zig-d24be85be88737db8399b492931647056c547614.zip | |
stage2: fix `if` expressions
Diffstat (limited to 'src/Module.zig')
| -rw-r--r-- | src/Module.zig | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/Module.zig b/src/Module.zig index 960f2175d8..33422ae011 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -1307,6 +1307,7 @@ pub const Scope = struct { /// Note that this returns a `zir.Inst.Index` not a ref. /// Leaves the `payload_index` field undefined. pub fn addCondBr(gz: *GenZir, node: ast.Node.Index) !zir.Inst.Index { + try gz.instructions.ensureCapacity(gz.zir_code.gpa, gz.instructions.items.len + 1); const new_index = @intCast(zir.Inst.Index, gz.zir_code.instructions.len); try gz.zir_code.instructions.append(gz.zir_code.gpa, .{ .tag = .condbr, @@ -1315,6 +1316,7 @@ pub const Scope = struct { .payload_index = undefined, } }, }); + gz.instructions.appendAssumeCapacity(new_index); return new_index; } @@ -1398,6 +1400,14 @@ pub const WipZirCode = struct { return result; } + pub fn refIsNoReturn(wzc: WipZirCode, zir_inst_ref: zir.Inst.Ref) bool { + if (zir_inst_ref >= wzc.ref_start_index) { + const zir_inst = zir_inst_ref - wzc.ref_start_index; + return wzc.instructions.items(.tag)[zir_inst].isNoReturn(); + } + return false; + } + pub fn deinit(wzc: *WipZirCode) void { wzc.instructions.deinit(wzc.gpa); wzc.extra.deinit(wzc.gpa); @@ -2290,6 +2300,7 @@ fn astgenAndSemaFn( .decl = decl, .arena = &decl_arena.allocator, .gpa = mod.gpa, + .ref_start_index = @intCast(u32, zir.const_inst_list.len + param_count), }; defer wip_zir_code.deinit(); @@ -3199,6 +3210,9 @@ pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn) !void { }; defer inner_block.instructions.deinit(mod.gpa); + // TZIR currently requires the arg parameters to be the first N instructions + try inner_block.instructions.appendSlice(mod.gpa, param_inst_list); + func.state = .in_progress; log.debug("set {s} to in_progress", .{decl.name}); |
