diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-02-12 23:47:17 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-02-12 23:47:17 -0700 |
| commit | 7630a5c566b106b6325a55f29eb1ed9e584d0949 (patch) | |
| tree | bacdef35e7f63bc6e9ce3fcedcd05e29ed01b453 /src/codegen.zig | |
| parent | a9db40e8704bd4f87b0770e2d72ba05b94afad1e (diff) | |
| download | zig-7630a5c566b106b6325a55f29eb1ed9e584d0949.tar.gz zig-7630a5c566b106b6325a55f29eb1ed9e584d0949.zip | |
stage2: more progress towards Module/astgen building with new mem layout
Diffstat (limited to 'src/codegen.zig')
| -rw-r--r-- | src/codegen.zig | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/codegen.zig b/src/codegen.zig index 9771386403..095bb123ba 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -451,11 +451,16 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { const src_data: struct { lbrace_src: usize, rbrace_src: usize, source: []const u8 } = blk: { const container_scope = module_fn.owner_decl.container; - const tree = container_scope.file_scope.contents.tree; - const fn_proto = tree.root_node.decls()[module_fn.owner_decl.src_index].castTag(.FnProto).?; - const block = fn_proto.getBodyNode().?.castTag(.Block).?; - const lbrace_src = tree.token_locs[block.lbrace].start; - const rbrace_src = tree.token_locs[block.rbrace].start; + const tree = container_scope.file_scope.tree; + const node_tags = tree.nodes.items(.tag); + const node_datas = tree.nodes.items(.data); + const token_starts = tree.tokens.items(.start); + + const fn_decl = tree.rootDecls()[module_fn.owner_decl.src_index]; + assert(node_tags[fn_decl] == .fn_decl); + const block = node_datas[fn_decl].rhs; + const lbrace_src = token_starts[tree.firstToken(block)]; + const rbrace_src = token_starts[tree.lastToken(block)]; break :blk .{ .lbrace_src = lbrace_src, .rbrace_src = rbrace_src, |
