authorgravatar for koachan@protonmail.comKoakuma <koachan@protonmail.com> 2022-04-01 22:32:56+07:00
committergravatar for koachan@protonmail.comKoakuma <koachan@protonmail.com> 2022-04-14 22:18:06+07:00
log5ab6b5a77723d203644a7112cf37f3122c738986
treed1009d880a575fd57dca9ddbc528f3d2c3e29ebe
parent71cd3466ec129404a9cc6679f25b0dde8623b094

stage2: sparcv9: implement dbgAdvancePCAndLine


1 files changed, 49 insertions(+), 5 deletions(-)

src/arch/sparcv9/Emit.zig+49-5
...@@ -9,6 +9,7 @@ const ErrorMsg = Module.ErrorMsg;...@@ -9,6 +9,7 @@ const ErrorMsg = Module.ErrorMsg;
9const Liveness = @import("../../Liveness.zig");9const Liveness = @import("../../Liveness.zig");
10const DebugInfoOutput = @import("../../codegen.zig").DebugInfoOutput;10const DebugInfoOutput = @import("../../codegen.zig").DebugInfoOutput;
11const DW = std.dwarf;11const DW = std.dwarf;
12const leb128 = std.leb;
1213
13const Emit = @This();14const Emit = @This();
14const Mir = @import("Mir.zig");15const Mir = @import("Mir.zig");
...@@ -60,11 +61,54 @@ pub fn deinit(emit: *Emit) void {...@@ -60,11 +61,54 @@ pub fn deinit(emit: *Emit) void {
60}61}
6162
62fn dbgAdvancePCAndLine(self: *Emit, line: u32, column: u32) !void {63fn dbgAdvancePCAndLine(self: *Emit, line: u32, column: u32) !void {
63 _ = self;64 const delta_line = @intCast(i32, line) - @intCast(i32, self.prev_di_line);
64 _ = line;65 const delta_pc: usize = self.code.items.len - self.prev_di_pc;
65 _ = column;66 switch (self.debug_output) {
6667 .dwarf => |dbg_out| {
67 @panic("TODO implement dbgAdvancePCAndLine");68 // TODO Look into using the DWARF special opcodes to compress this data.
69 // It lets you emit single-byte opcodes that add different numbers to
70 // both the PC and the line number at the same time.
71 try dbg_out.dbg_line.ensureUnusedCapacity(11);
72 dbg_out.dbg_line.appendAssumeCapacity(DW.LNS.advance_pc);
73 leb128.writeULEB128(dbg_out.dbg_line.writer(), delta_pc) catch unreachable;
74 if (delta_line != 0) {
75 dbg_out.dbg_line.appendAssumeCapacity(DW.LNS.advance_line);
76 leb128.writeILEB128(dbg_out.dbg_line.writer(), delta_line) catch unreachable;
77 }
78 dbg_out.dbg_line.appendAssumeCapacity(DW.LNS.copy);
79 self.prev_di_pc = self.code.items.len;
80 self.prev_di_line = line;
81 self.prev_di_column = column;
82 self.prev_di_pc = self.code.items.len;
83 },
84 .plan9 => |dbg_out| {
85 if (delta_pc <= 0) return; // only do this when the pc changes
86 // we have already checked the target in the linker to make sure it is compatable
87 const quant = @import("../../link/Plan9/aout.zig").getPCQuant(self.target.cpu.arch) catch unreachable;
88
89 // increasing the line number
90 try @import("../../link/Plan9.zig").changeLine(dbg_out.dbg_line, delta_line);
91 // increasing the pc
92 const d_pc_p9 = @intCast(i64, delta_pc) - quant;
93 if (d_pc_p9 > 0) {
94 // minus one because if its the last one, we want to leave space to change the line which is one quanta
95 try dbg_out.dbg_line.append(@intCast(u8, @divExact(d_pc_p9, quant) + 128) - quant);
96 if (dbg_out.pcop_change_index.*) |pci|
97 dbg_out.dbg_line.items[pci] += 1;
98 dbg_out.pcop_change_index.* = @intCast(u32, dbg_out.dbg_line.items.len - 1);
99 } else if (d_pc_p9 == 0) {
100 // we don't need to do anything, because adding the quant does it for us
101 } else unreachable;
102 if (dbg_out.start_line.* == null)
103 dbg_out.start_line.* = self.prev_di_line;
104 dbg_out.end_line.* = line;
105 // only do this if the pc changed
106 self.prev_di_line = line;
107 self.prev_di_column = column;
108 self.prev_di_pc = self.code.items.len;
109 },
110 .none => {},
111 }
68}112}
69113
70fn mirDbgLine(emit: *Emit, inst: Mir.Inst.Index) !void {114fn mirDbgLine(emit: *Emit, inst: Mir.Inst.Index) !void {