authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-12-01 20:06:11+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-12-01 20:06:11+01:00
log17ab40f755a038bd9c06c7817354f9ce2eb4353f
tree70576ff913053ebfa441503232ebb0b1ade3bafa
parent41203325770e87920e797a7113da626ce2cf1b06

dwarf: refactor arm and riscv64 to the new scheme


2 files changed, 31 insertions(+), 55 deletions(-)

src/arch/arm/CodeGen.zig+13-9
......@@ -4029,18 +4029,11 @@ fn genInlineMemsetCode(
40294029 // end:
40304030}
40314031
4032fn genArgDbgInfo(self: *Self, inst: Air.Inst.Index, arg_index: u32) error{OutOfMemory}!void {
4032fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, arg_index: u32) error{OutOfMemory}!void {
40334033 const mcv = self.args[arg_index];
40344034 const ty = self.air.instructions.items(.data)[inst].ty;
40354035 const name = self.mod_fn.getParamName(self.bin_file.options.module.?, arg_index);
4036
4037 const mod = self.bin_file.options.module.?;
4038 const fn_owner_decl = mod.declPtr(self.mod_fn.owner_decl);
4039 const atom = switch (self.bin_file.tag) {
4040 .elf => &fn_owner_decl.link.elf.dbg_info_atom,
4041 .macho => &fn_owner_decl.link.macho.dbg_info_atom,
4042 else => unreachable,
4043 };
4036 const atom = self.getDbgInfoAtom();
40444037
40454038 switch (self.debug_output) {
40464039 .dwarf => |dw| switch (mcv) {
......@@ -4069,6 +4062,17 @@ fn genArgDbgInfo(self: *Self, inst: Air.Inst.Index, arg_index: u32) error{OutOfM
40694062 }
40704063}
40714064
4065fn getDbgInfoAtom(self: Self) *link.File.Dwarf.Atom {
4066 const mod = self.bin_file.options.module.?;
4067 const fn_owner_decl = mod.declPtr(self.mod_fn.owner_decl);
4068 const atom = switch (self.bin_file.tag) {
4069 .elf => &fn_owner_decl.link.elf.dbg_info_atom,
4070 .macho => &fn_owner_decl.link.macho.dbg_info_atom,
4071 else => unreachable,
4072 };
4073 return atom;
4074}
4075
40724076fn airArg(self: *Self, inst: Air.Inst.Index) !void {
40734077 const arg_index = self.arg_index;
40744078 self.arg_index += 1;
src/arch/sparc64/CodeGen.zig+18-46
......@@ -2460,26 +2460,6 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
24602460
24612461// Common helper functions
24622462
2463/// Adds a Type to the .debug_info at the current position. The bytes will be populated later,
2464/// after codegen for this symbol is done.
2465fn addDbgInfoTypeReloc(self: *Self, ty: Type) !void {
2466 switch (self.debug_output) {
2467 .dwarf => |dw| {
2468 assert(ty.hasRuntimeBits());
2469 const dbg_info = &dw.dbg_info;
2470 const index = dbg_info.items.len;
2471 try dbg_info.resize(index + 4); // DW.AT.type, DW.FORM.ref4
2472 const mod = self.bin_file.options.module.?;
2473 const atom = switch (self.bin_file.tag) {
2474 .elf => &mod.declPtr(self.mod_fn.owner_decl).link.elf.dbg_info_atom,
2475 else => unreachable,
2476 };
2477 try dw.addTypeRelocGlobal(atom, ty, @intCast(u32, index));
2478 },
2479 else => {},
2480 }
2481}
2482
24832463fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {
24842464 const gpa = self.gpa;
24852465 try self.mir_instructions.ensureUnusedCapacity(gpa, 1);
......@@ -3272,40 +3252,32 @@ fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Live
32723252 self.finishAirBookkeeping();
32733253}
32743254
3275fn genArgDbgInfo(self: *Self, inst: Air.Inst.Index, mcv: MCValue, arg_index: u32) !void {
3255fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, mcv: MCValue, arg_index: u32) !void {
32763256 const ty = self.air.instructions.items(.data)[inst].ty;
32773257 const name = self.mod_fn.getParamName(self.bin_file.options.module.?, arg_index);
3278 const name_with_null = name.ptr[0 .. name.len + 1];
3258 const atom = self.getDbgInfoAtomPtr();
32793259
3280 switch (mcv) {
3281 .register => |reg| {
3282 switch (self.debug_output) {
3283 .dwarf => |dw| {
3284 const dbg_info = &dw.dbg_info;
3285 try dbg_info.ensureUnusedCapacity(3);
3286 dbg_info.appendAssumeCapacity(@enumToInt(link.File.Dwarf.AbbrevKind.parameter));
3287 dbg_info.appendSliceAssumeCapacity(&[2]u8{ // DW.AT.location, DW.FORM.exprloc
3288 1, // ULEB128 dwarf expression length
3289 reg.dwarfLocOp(),
3290 });
3291 try dbg_info.ensureUnusedCapacity(5 + name_with_null.len);
3292 try self.addDbgInfoTypeReloc(ty); // DW.AT.type, DW.FORM.ref4
3293 dbg_info.appendSliceAssumeCapacity(name_with_null); // DW.AT.name, DW.FORM.string
3294 },
3295 else => {},
3296 }
3297 },
3298 .stack_offset => |offset| {
3299 _ = offset;
3300 switch (self.debug_output) {
3301 .dwarf => {},
3302 else => {},
3303 }
3260 switch (self.debug_output) {
3261 .dwarf => |dw| switch (mcv) {
3262 .register => |reg| try dw.genArgDbgInfo(name, ty, atom, .{
3263 .register = reg.dwarfLocOp(),
3264 }),
3265 else => {},
33043266 },
33053267 else => {},
33063268 }
33073269}
33083270
3271fn getDbgInfoAtomPtr(self: Self) *link.File.Dwarf.Atom {
3272 const mod = self.bin_file.options.module.?;
3273 const fn_owner_decl = mod.declPtr(self.mod_fn.owner_decl);
3274 const atom = switch (self.bin_file.tag) {
3275 .elf => &fn_owner_decl.link.elf.dbg_info_atom,
3276 else => unreachable,
3277 };
3278 return atom;
3279}
3280
33093281// TODO replace this to call to extern memcpy
33103282fn genInlineMemcpy(
33113283 self: *Self,