aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-04-30 23:11:20 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-04-30 23:11:20 -0700
commit351b57497b1cf2ea6ee72a3c7cfdb84b924bb368 (patch)
tree5c5d8c4185edbc6453daa80aa19f307fda0a99d7 /src/Module.zig
parent077b8d3def537b9a36330c14c39bfa77b2e122bc (diff)
downloadzig-351b57497b1cf2ea6ee72a3c7cfdb84b924bb368.tar.gz
zig-351b57497b1cf2ea6ee72a3c7cfdb84b924bb368.zip
stage2: implement function body analysis
now with whole-file-astgen
Diffstat (limited to 'src/Module.zig')
-rw-r--r--src/Module.zig80
1 files changed, 38 insertions, 42 deletions
diff --git a/src/Module.zig b/src/Module.zig
index a64fb491e1..7bf117b875 100644
--- a/src/Module.zig
+++ b/src/Module.zig
@@ -3986,48 +3986,44 @@ pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn) !void {
param_inst.* = &arg_inst.base;
}
- var f = false;
- if (f) {
- return error.AnalysisFail;
- }
- @panic("TODO reimplement analyzeFnBody now that ZIR is whole-file");
-
- //var sema: Sema = .{
- // .mod = mod,
- // .gpa = mod.gpa,
- // .arena = &arena.allocator,
- // .code = func.zir,
- // .inst_map = try mod.gpa.alloc(*ir.Inst, func.zir.instructions.len),
- // .owner_decl = decl,
- // .namespace = decl.namespace,
- // .func = func,
- // .owner_func = func,
- // .param_inst_list = param_inst_list,
- //};
- //defer mod.gpa.free(sema.inst_map);
-
- //var inner_block: Scope.Block = .{
- // .parent = null,
- // .sema = &sema,
- // .src_decl = decl,
- // .instructions = .{},
- // .inlining = null,
- // .is_comptime = false,
- //};
- //defer inner_block.instructions.deinit(mod.gpa);
-
- //// AIR 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});
-
- //_ = try sema.root(&inner_block);
-
- //const instructions = try arena.allocator.dupe(*ir.Inst, inner_block.instructions.items);
- //func.state = .success;
- //func.body = .{ .instructions = instructions };
- //log.debug("set {s} to success", .{decl.name});
+ const zir = decl.namespace.file_scope.zir;
+
+ var sema: Sema = .{
+ .mod = mod,
+ .gpa = mod.gpa,
+ .arena = &arena.allocator,
+ .code = zir,
+ .inst_map = try mod.gpa.alloc(*ir.Inst, zir.instructions.len),
+ .owner_decl = decl,
+ .namespace = decl.namespace,
+ .func = func,
+ .owner_func = func,
+ .param_inst_list = param_inst_list,
+ };
+ defer mod.gpa.free(sema.inst_map);
+
+ var inner_block: Scope.Block = .{
+ .parent = null,
+ .sema = &sema,
+ .src_decl = decl,
+ .instructions = .{},
+ .inlining = null,
+ .is_comptime = false,
+ };
+ defer inner_block.instructions.deinit(mod.gpa);
+
+ // AIR 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});
+
+ try sema.analyzeFnBody(&inner_block, func.zir_body_inst);
+
+ const instructions = try arena.allocator.dupe(*ir.Inst, inner_block.instructions.items);
+ func.state = .success;
+ func.body = .{ .instructions = instructions };
+ log.debug("set {s} to success", .{decl.name});
}
fn markOutdatedDecl(mod: *Module, decl: *Decl) !void {