aboutsummaryrefslogtreecommitdiff
path: root/src/arch/sparc64/CodeGen.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/arch/sparc64/CodeGen.zig')
-rw-r--r--src/arch/sparc64/CodeGen.zig75
1 files changed, 29 insertions, 46 deletions
diff --git a/src/arch/sparc64/CodeGen.zig b/src/arch/sparc64/CodeGen.zig
index ad9884dcdb..b35f45dd64 100644
--- a/src/arch/sparc64/CodeGen.zig
+++ b/src/arch/sparc64/CodeGen.zig
@@ -57,8 +57,6 @@ liveness: Air.Liveness,
bin_file: *link.File,
target: *const std.Target,
func_index: InternPool.Index,
-code: *std.ArrayListUnmanaged(u8),
-debug_output: link.File.DebugInfoOutput,
err_msg: ?*ErrorMsg,
args: []MCValue,
ret_mcv: MCValue,
@@ -268,11 +266,9 @@ pub fn generate(
pt: Zcu.PerThread,
src_loc: Zcu.LazySrcLoc,
func_index: InternPool.Index,
- air: Air,
- liveness: Air.Liveness,
- code: *std.ArrayListUnmanaged(u8),
- debug_output: link.File.DebugInfoOutput,
-) CodeGenError!void {
+ air: *const Air,
+ liveness: *const Air.Liveness,
+) CodeGenError!Mir {
const zcu = pt.zcu;
const gpa = zcu.gpa;
const func = zcu.funcInfo(func_index);
@@ -291,13 +287,11 @@ pub fn generate(
var function: Self = .{
.gpa = gpa,
.pt = pt,
- .air = air,
- .liveness = liveness,
+ .air = air.*,
+ .liveness = liveness.*,
.target = target,
.bin_file = lf,
.func_index = func_index,
- .code = code,
- .debug_output = debug_output,
.err_msg = null,
.args = undefined, // populated after `resolveCallingConventionValues`
.ret_mcv = undefined, // populated after `resolveCallingConventionValues`
@@ -330,29 +324,13 @@ pub fn generate(
else => |e| return e,
};
- var mir = Mir{
+ var mir: Mir = .{
.instructions = function.mir_instructions.toOwnedSlice(),
- .extra = try function.mir_extra.toOwnedSlice(gpa),
- };
- defer mir.deinit(gpa);
-
- var emit: Emit = .{
- .mir = mir,
- .bin_file = lf,
- .debug_output = debug_output,
- .target = target,
- .src_loc = src_loc,
- .code = code,
- .prev_di_pc = 0,
- .prev_di_line = func.lbrace_line,
- .prev_di_column = func.lbrace_column,
- };
- defer emit.deinit();
-
- emit.emitMir() catch |err| switch (err) {
- error.EmitFail => return function.failMsg(emit.err_msg.?),
- else => |e| return e,
+ .extra = &.{}, // fallible, so populated after errdefer
};
+ errdefer mir.deinit(gpa);
+ mir.extra = try function.mir_extra.toOwnedSlice(gpa);
+ return mir;
}
fn gen(self: *Self) !void {
@@ -1017,23 +995,29 @@ fn airArg(self: *Self, inst: Air.Inst.Index) InnerError!void {
self.arg_index += 1;
const ty = self.typeOfIndex(inst);
-
- const arg = self.args[arg_index];
- const mcv = blk: {
- switch (arg) {
+ const mcv: MCValue = blk: {
+ switch (self.args[arg_index]) {
.stack_offset => |off| {
const abi_size = math.cast(u32, ty.abiSize(zcu)) orelse {
return self.fail("type '{}' too big to fit into stack frame", .{ty.fmt(pt)});
};
const offset = off + abi_size;
- break :blk MCValue{ .stack_offset = offset };
+ break :blk .{ .stack_offset = offset };
},
- else => break :blk arg,
+ else => |mcv| break :blk mcv,
}
};
- self.genArgDbgInfo(inst, mcv) catch |err|
- return self.fail("failed to generate debug info for parameter: {s}", .{@errorName(err)});
+ const func_zir = zcu.funcInfo(self.func_index).zir_body_inst.resolveFull(&zcu.intern_pool).?;
+ const file = zcu.fileByIndex(func_zir.file);
+ if (!file.mod.?.strip) {
+ const arg = self.air.instructions.items(.data)[@intFromEnum(inst)].arg;
+ const zir = &file.zir.?;
+ const name = zir.nullTerminatedString(zir.getParamName(zir.getParamBody(func_zir.inst)[arg.zir_param_index]).?);
+
+ self.genArgDbgInfo(name, ty, mcv) catch |err|
+ return self.fail("failed to generate debug info for parameter: {s}", .{@errorName(err)});
+ }
if (self.liveness.isUnused(inst))
return self.finishAirBookkeeping();
@@ -3561,16 +3545,15 @@ fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Air.
self.finishAirBookkeeping();
}
-fn genArgDbgInfo(self: Self, inst: Air.Inst.Index, mcv: MCValue) !void {
- const arg = self.air.instructions.items(.data)[@intFromEnum(inst)].arg;
- const ty = arg.ty.toType();
- if (arg.name == .none) return;
-
+fn genArgDbgInfo(self: Self, name: []const u8, ty: Type, mcv: MCValue) !void {
+ // TODO: Add a pseudo-instruction or something to defer this work until Emit.
+ // We aren't allowed to interact with linker state here.
+ if (true) return;
switch (self.debug_output) {
.dwarf => |dw| switch (mcv) {
.register => |reg| try dw.genLocalDebugInfo(
.local_arg,
- arg.name.toSlice(self.air),
+ name,
ty,
.{ .reg = reg.dwarfNum() },
),