| author | |
| committer | |
| log | bd2154da3d90daa4520ee7ef69dac42f9049ed92 |
| tree | 2b541e218121779de830b7d372975c790b469014 |
| parent | b2682237dbe90306b569cb36914f8823cd7b0431 |
(with a lot of things commented out)5 files changed, 46 insertions(+), 14 deletions(-)
src/Module.zig+18-6| ... | @@ -923,6 +923,20 @@ pub const Scope = struct { | ... | @@ -923,6 +923,20 @@ pub const Scope = struct { |
| 923 | try block.instructions.append(block.sema.gpa, &inst.base); | 923 | try block.instructions.append(block.sema.gpa, &inst.base); |
| 924 | return &inst.base; | 924 | return &inst.base; |
| 925 | } | 925 | } |
| 926 | |||
| 927 | pub fn addDbgStmt(block: *Scope.Block, src: LazySrcLoc, abs_byte_off: u32) !*ir.Inst { | ||
| 928 | const inst = try block.sema.arena.create(ir.Inst.DbgStmt); | ||
| 929 | inst.* = .{ | ||
| 930 | .base = .{ | ||
| 931 | .tag = .dbg_stmt, | ||
| 932 | .ty = Type.initTag(.void), | ||
| 933 | .src = src, | ||
| 934 | }, | ||
| 935 | .byte_offset = abs_byte_off, | ||
| 936 | }; | ||
| 937 | try block.instructions.append(block.sema.gpa, &inst.base); | ||
| 938 | return &inst.base; | ||
| 939 | } | ||
| 926 | }; | 940 | }; |
| 927 | 941 | ||
| 928 | /// This is a temporary structure; references to it are valid only | 942 | /// This is a temporary structure; references to it are valid only |
| ... | @@ -1330,14 +1344,12 @@ pub const SrcLoc = struct { | ... | @@ -1330,14 +1344,12 @@ pub const SrcLoc = struct { |
| 1330 | .byte_abs => |byte_index| return byte_index, | 1344 | .byte_abs => |byte_index| return byte_index, |
| 1331 | 1345 | ||
| 1332 | .token_abs => |tok_index| { | 1346 | .token_abs => |tok_index| { |
| 1333 | const file_scope = src_loc.container.file_scope; | 1347 | const tree = src_loc.container.file_scope.base.tree(); |
| 1334 | const tree = try mod.getAstTree(file_scope); | ||
| 1335 | const token_starts = tree.tokens.items(.start); | 1348 | const token_starts = tree.tokens.items(.start); |
| 1336 | return token_starts[tok_index]; | 1349 | return token_starts[tok_index]; |
| 1337 | }, | 1350 | }, |
| 1338 | .node_abs => |node_index| { | 1351 | .node_abs => |node_index| { |
| 1339 | const file_scope = src_loc.container.file_scope; | 1352 | const tree = src_loc.container.file_scope.base.tree(); |
| 1340 | const tree = try mod.getAstTree(file_scope); | ||
| 1341 | const token_starts = tree.tokens.items(.start); | 1353 | const token_starts = tree.tokens.items(.start); |
| 1342 | const tok_index = tree.firstToken(node_index); | 1354 | const tok_index = tree.firstToken(node_index); |
| 1343 | return token_starts[tok_index]; | 1355 | return token_starts[tok_index]; |
| ... | @@ -1349,14 +1361,14 @@ pub const SrcLoc = struct { | ... | @@ -1349,14 +1361,14 @@ pub const SrcLoc = struct { |
| 1349 | .token_offset => |tok_off| { | 1361 | .token_offset => |tok_off| { |
| 1350 | const decl = src_loc.container.decl; | 1362 | const decl = src_loc.container.decl; |
| 1351 | const tok_index = decl.srcToken() + tok_off; | 1363 | const tok_index = decl.srcToken() + tok_off; |
| 1352 | const tree = try mod.getAstTree(decl.container.file_scope); | 1364 | const tree = src_loc.container.file_scope.base.tree(); |
| 1353 | const token_starts = tree.tokens.items(.start); | 1365 | const token_starts = tree.tokens.items(.start); |
| 1354 | return token_starts[tok_index]; | 1366 | return token_starts[tok_index]; |
| 1355 | }, | 1367 | }, |
| 1356 | .node_offset => |node_off| { | 1368 | .node_offset => |node_off| { |
| 1357 | const decl = src_loc.container.decl; | 1369 | const decl = src_loc.container.decl; |
| 1358 | const node_index = decl.srcNode() + node_off; | 1370 | const node_index = decl.srcNode() + node_off; |
| 1359 | const tree = try mod.getAstTree(decl.container.file_scope); | 1371 | const tree = src_loc.container.file_scope.base.tree(); |
| 1360 | const tok_index = tree.firstToken(node_index); | 1372 | const tok_index = tree.firstToken(node_index); |
| 1361 | const token_starts = tree.tokens.items(.start); | 1373 | const token_starts = tree.tokens.items(.start); |
| 1362 | return token_starts[tok_index]; | 1374 | return token_starts[tok_index]; |
src/Sema.zig+3-1| ... | @@ -1003,7 +1003,9 @@ fn zirDbgStmtNode(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerE | ... | @@ -1003,7 +1003,9 @@ fn zirDbgStmtNode(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerE |
| 1003 | 1003 | ||
| 1004 | const src_node = sema.code.instructions.items(.data)[inst].node; | 1004 | const src_node = sema.code.instructions.items(.data)[inst].node; |
| 1005 | const src: LazySrcLoc = .{ .node_offset = src_node }; | 1005 | const src: LazySrcLoc = .{ .node_offset = src_node }; |
| 1006 | return block.addNoOp(src, Type.initTag(.void), .dbg_stmt); | 1006 | const src_loc = src.toSrcLoc(&block.base); |
| 1007 | const abs_byte_off = try src_loc.byteOffset(sema.mod); | ||
| 1008 | return block.addDbgStmt(src, abs_byte_off); | ||
| 1007 | } | 1009 | } |
| 1008 | 1010 | ||
| 1009 | fn zirDeclRef(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { | 1011 | fn zirDeclRef(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { |
src/codegen.zig+9-5| ... | @@ -792,8 +792,8 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { | ... | @@ -792,8 +792,8 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 792 | } | 792 | } |
| 793 | } | 793 | } |
| 794 | 794 | ||
| 795 | fn dbgAdvancePCAndLine(self: *Self, src: usize) InnerError!void { | 795 | fn dbgAdvancePCAndLine(self: *Self, abs_byte_off: usize) InnerError!void { |
| 796 | self.prev_di_src = src; | 796 | self.prev_di_src = abs_byte_off; |
| 797 | self.prev_di_pc = self.code.items.len; | 797 | self.prev_di_pc = self.code.items.len; |
| 798 | switch (self.debug_output) { | 798 | switch (self.debug_output) { |
| 799 | .dwarf => |dbg_out| { | 799 | .dwarf => |dbg_out| { |
| ... | @@ -801,7 +801,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { | ... | @@ -801,7 +801,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 801 | // lookup table, and changing ir.Inst from storing byte offset to token. Currently | 801 | // lookup table, and changing ir.Inst from storing byte offset to token. Currently |
| 802 | // this involves scanning over the source code for newlines | 802 | // this involves scanning over the source code for newlines |
| 803 | // (but only from the previous byte offset to the new one). | 803 | // (but only from the previous byte offset to the new one). |
| 804 | const delta_line = std.zig.lineDelta(self.source, self.prev_di_src, src); | 804 | const delta_line = std.zig.lineDelta(self.source, self.prev_di_src, abs_byte_off); |
| 805 | const delta_pc = self.code.items.len - self.prev_di_pc; | 805 | const delta_pc = self.code.items.len - self.prev_di_pc; |
| 806 | // TODO Look into using the DWARF special opcodes to compress this data. It lets you emit | 806 | // TODO Look into using the DWARF special opcodes to compress this data. It lets you emit |
| 807 | // single-byte opcodes that add different numbers to both the PC and the line number | 807 | // single-byte opcodes that add different numbers to both the PC and the line number |
| ... | @@ -2315,8 +2315,12 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { | ... | @@ -2315,8 +2315,12 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 2315 | } | 2315 | } |
| 2316 | } | 2316 | } |
| 2317 | 2317 | ||
| 2318 | fn genDbgStmt(self: *Self, inst: *ir.Inst.NoOp) !MCValue { | 2318 | fn genDbgStmt(self: *Self, inst: *ir.Inst.DbgStmt) !MCValue { |
| 2319 | try self.dbgAdvancePCAndLine(inst.base.src); | 2319 | // TODO when reworking tzir memory layout, rework source locations here as |
| 2320 | // well to be more efficient, as well as support inlined function calls correctly. | ||
| 2321 | // For now we convert LazySrcLoc to absolute byte offset, to match what the | ||
| 2322 | // existing codegen code expects. | ||
| 2323 | try self.dbgAdvancePCAndLine(inst.byte_offset); | ||
| 2320 | assert(inst.base.isUnused()); | 2324 | assert(inst.base.isUnused()); |
| 2321 | return MCValue.dead; | 2325 | return MCValue.dead; |
| 2322 | } | 2326 | } |
src/codegen/c.zig+1-1| ... | @@ -760,7 +760,7 @@ fn genCall(o: *Object, inst: *Inst.Call) !CValue { | ... | @@ -760,7 +760,7 @@ fn genCall(o: *Object, inst: *Inst.Call) !CValue { |
| 760 | } | 760 | } |
| 761 | } | 761 | } |
| 762 | 762 | ||
| 763 | fn genDbgStmt(o: *Object, inst: *Inst.NoOp) !CValue { | 763 | fn genDbgStmt(o: *Object, inst: *Inst.DbgStmt) !CValue { |
| 764 | // TODO emit #line directive here with line number and filename | 764 | // TODO emit #line directive here with line number and filename |
| 765 | return CValue.none; | 765 | return CValue.none; |
| 766 | } | 766 | } |
src/ir.zig+15-1| ... | @@ -138,7 +138,6 @@ pub const Inst = struct { | ... | @@ -138,7 +138,6 @@ pub const Inst = struct { |
| 138 | .retvoid, | 138 | .retvoid, |
| 139 | .unreach, | 139 | .unreach, |
| 140 | .breakpoint, | 140 | .breakpoint, |
| 141 | .dbg_stmt, | ||
| 142 | => NoOp, | 141 | => NoOp, |
| 143 | 142 | ||
| 144 | .ref, | 143 | .ref, |
| ... | @@ -198,6 +197,7 @@ pub const Inst = struct { | ... | @@ -198,6 +197,7 @@ pub const Inst = struct { |
| 198 | .loop => Loop, | 197 | .loop => Loop, |
| 199 | .varptr => VarPtr, | 198 | .varptr => VarPtr, |
| 200 | .switchbr => SwitchBr, | 199 | .switchbr => SwitchBr, |
| 200 | .dbg_stmt => DbgStmt, | ||
| 201 | }; | 201 | }; |
| 202 | } | 202 | } |
| 203 | 203 | ||
| ... | @@ -584,6 +584,20 @@ pub const Inst = struct { | ... | @@ -584,6 +584,20 @@ pub const Inst = struct { |
| 584 | return (self.deaths + self.else_index)[0..self.else_deaths]; | 584 | return (self.deaths + self.else_index)[0..self.else_deaths]; |
| 585 | } | 585 | } |
| 586 | }; | 586 | }; |
| 587 | |||
| 588 | pub const DbgStmt = struct { | ||
| 589 | pub const base_tag = Tag.dbg_stmt; | ||
| 590 | |||
| 591 | base: Inst, | ||
| 592 | byte_offset: u32, | ||
| 593 | |||
| 594 | pub fn operandCount(self: *const DbgStmt) usize { | ||
| 595 | return 0; | ||
| 596 | } | ||
| 597 | pub fn getOperand(self: *const DbgStmt, index: usize) ?*Inst { | ||
| 598 | return null; | ||
| 599 | } | ||
| 600 | }; | ||
| 587 | }; | 601 | }; |
| 588 | 602 | ||
| 589 | pub const Body = struct { | 603 | pub const Body = struct { |