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(...@@ -4029,18 +4029,11 @@ fn genInlineMemsetCode(
4029 // end:4029 // end:
4030}4030}
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 {
4033 const mcv = self.args[arg_index];4033 const mcv = self.args[arg_index];
4034 const ty = self.air.instructions.items(.data)[inst].ty;4034 const ty = self.air.instructions.items(.data)[inst].ty;
4035 const name = self.mod_fn.getParamName(self.bin_file.options.module.?, arg_index);4035 const name = self.mod_fn.getParamName(self.bin_file.options.module.?, arg_index);
40364036 const atom = self.getDbgInfoAtom();
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 };
40444037
4045 switch (self.debug_output) {4038 switch (self.debug_output) {
4046 .dwarf => |dw| switch (mcv) {4039 .dwarf => |dw| switch (mcv) {
...@@ -4069,6 +4062,17 @@ fn genArgDbgInfo(self: *Self, inst: Air.Inst.Index, arg_index: u32) error{OutOfM...@@ -4069,6 +4062,17 @@ fn genArgDbgInfo(self: *Self, inst: Air.Inst.Index, arg_index: u32) error{OutOfM
4069 }4062 }
4070}4063}
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
4072fn airArg(self: *Self, inst: Air.Inst.Index) !void {4076fn airArg(self: *Self, inst: Air.Inst.Index) !void {
4073 const arg_index = self.arg_index;4077 const arg_index = self.arg_index;
4074 self.arg_index += 1;4078 self.arg_index += 1;
src/arch/sparc64/CodeGen.zig+18-46
...@@ -2460,26 +2460,6 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {...@@ -2460,26 +2460,6 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
24602460
2461// Common helper functions2461// 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
2483fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {2463fn addInst(self: *Self, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {
2484 const gpa = self.gpa;2464 const gpa = self.gpa;
2485 try self.mir_instructions.ensureUnusedCapacity(gpa, 1);2465 try self.mir_instructions.ensureUnusedCapacity(gpa, 1);
...@@ -3272,40 +3252,32 @@ fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Live...@@ -3272,40 +3252,32 @@ fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Live
3272 self.finishAirBookkeeping();3252 self.finishAirBookkeeping();
3273}3253}
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 {
3276 const ty = self.air.instructions.items(.data)[inst].ty;3256 const ty = self.air.instructions.items(.data)[inst].ty;
3277 const name = self.mod_fn.getParamName(self.bin_file.options.module.?, arg_index);3257 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) {3260 switch (self.debug_output) {
3281 .register => |reg| {3261 .dwarf => |dw| switch (mcv) {
3282 switch (self.debug_output) {3262 .register => |reg| try dw.genArgDbgInfo(name, ty, atom, .{
3283 .dwarf => |dw| {3263 .register = reg.dwarfLocOp(),
3284 const dbg_info = &dw.dbg_info;3264 }),
3285 try dbg_info.ensureUnusedCapacity(3);3265 else => {},
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 }
3304 },3266 },
3305 else => {},3267 else => {},
3306 }3268 }
3307}3269}
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
3309// TODO replace this to call to extern memcpy3281// TODO replace this to call to extern memcpy
3310fn genInlineMemcpy(3282fn genInlineMemcpy(
3311 self: *Self,3283 self: *Self,