aboutsummaryrefslogtreecommitdiff
path: root/src/link/Elf.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-05-01 21:57:52 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-05-01 21:57:52 -0700
commiteadcefc124b4ee61c99c8ed97434ed26e24c5f83 (patch)
treee76e08b8c4411a8ef609efdef020e9731e43de4b /src/link/Elf.zig
parent6248e2a5609cb9e30588f8bcd0000f5d5aa5fdee (diff)
downloadzig-eadcefc124b4ee61c99c8ed97434ed26e24c5f83.tar.gz
zig-eadcefc124b4ee61c99c8ed97434ed26e24c5f83.zip
stage2: dbg_stmt ZIR instructions have line/col
instead of node indexes. * AstGen: dbg_stmt instructions now have line and column indexes, relative to the parent declaration. This allows codegen to emit debug info without having the source bytes, tokens, or AST nodes loaded in memory. * ZIR: each decl has the absolute line number. This allows computing line numbers from offsets without consulting source code bytes. Memory management: creating a function definition does not prematurely set the Decl arena. Instead the function is allocated with the general purpose allocator. Codegen no longer looks at source code bytes for any reason. They can remain unloaded from disk.
Diffstat (limited to 'src/link/Elf.zig')
-rw-r--r--src/link/Elf.zig32
1 files changed, 4 insertions, 28 deletions
diff --git a/src/link/Elf.zig b/src/link/Elf.zig
index 7fbf17015e..3f87fd390b 100644
--- a/src/link/Elf.zig
+++ b/src/link/Elf.zig
@@ -2221,21 +2221,8 @@ pub fn updateDecl(self: *Elf, module: *Module, decl: *Module.Decl) !void {
// For functions we need to add a prologue to the debug line program.
try dbg_line_buffer.ensureCapacity(26);
- const line_off: u28 = blk: {
- const tree = decl.namespace.file_scope.tree;
- const node_tags = tree.nodes.items(.tag);
- const node_datas = tree.nodes.items(.data);
- const token_starts = tree.tokens.items(.start);
-
- // TODO Look into improving the performance here by adding a token-index-to-line
- // lookup table. Currently this involves scanning over the source code for newlines.
- const fn_decl = decl.src_node;
- assert(node_tags[fn_decl] == .fn_decl);
- const block = node_datas[fn_decl].rhs;
- const lbrace = tree.firstToken(block);
- const line_delta = std.zig.lineDelta(tree.source, 0, token_starts[lbrace]);
- break :blk @intCast(u28, line_delta);
- };
+ const func = decl.val.castTag(.function).?.data;
+ const line_off = @intCast(u28, decl.src_line + func.lbrace_line);
const ptr_width_bytes = self.ptrWidthBytes();
dbg_line_buffer.appendSliceAssumeCapacity(&[_]u8{
@@ -2750,19 +2737,8 @@ pub fn updateDeclLineNumber(self: *Elf, module: *Module, decl: *const Module.Dec
if (self.llvm_object) |_| return;
- const tree = decl.namespace.file_scope.tree;
- const node_tags = tree.nodes.items(.tag);
- const node_datas = tree.nodes.items(.data);
- const token_starts = tree.tokens.items(.start);
-
- // TODO Look into improving the performance here by adding a token-index-to-line
- // lookup table. Currently this involves scanning over the source code for newlines.
- const fn_decl = decl.src_node;
- assert(node_tags[fn_decl] == .fn_decl);
- const block = node_datas[fn_decl].rhs;
- const lbrace = tree.firstToken(block);
- const line_delta = std.zig.lineDelta(tree.source, 0, token_starts[lbrace]);
- const casted_line_off = @intCast(u28, line_delta);
+ const func = decl.val.castTag(.function).?.data;
+ const casted_line_off = @intCast(u28, decl.src_line + func.lbrace_line);
const shdr = &self.sections.items[self.debug_line_section_index.?];
const file_pos = shdr.sh_offset + decl.fn_link.elf.off + self.getRelocDbgLineOff();