authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-09-15 20:36:11-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-10-09 07:48:10-04:00
logd748cfc2b778f87f97b86001634cff66120f21a5
tree108509bfba5587a5e930f48d9f5d6fa5483dda44
parentc127c06fd73689987db6c336090d6432d9ee40a6

x86_64: print pseudo instructions in wip_mir log


2 files changed, 73 insertions(+), 4 deletions(-)

src/arch/x86_64/CodeGen.zig+69
...@@ -36,6 +36,7 @@ const abi = @import("abi.zig");...@@ -36,6 +36,7 @@ const abi = @import("abi.zig");
36const bits = @import("bits.zig");36const bits = @import("bits.zig");
37const errUnionErrorOffset = codegen.errUnionErrorOffset;37const errUnionErrorOffset = codegen.errUnionErrorOffset;
38const errUnionPayloadOffset = codegen.errUnionPayloadOffset;38const errUnionPayloadOffset = codegen.errUnionPayloadOffset;
39const encoder = @import("encoder.zig");
3940
40const Condition = bits.Condition;41const Condition = bits.Condition;
41const Immediate = bits.Immediate;42const Immediate = bits.Immediate;
...@@ -1188,6 +1189,74 @@ fn formatWipMir(...@@ -1188,6 +1189,74 @@ fn formatWipMir(
1188 try writer.print(" | {}", .{lowered_inst});1189 try writer.print(" | {}", .{lowered_inst});
1189 first = false;1190 first = false;
1190 }1191 }
1192 if (first) {
1193 const ip = &data.self.pt.zcu.intern_pool;
1194 const mir_inst = lower.mir.instructions.get(data.inst);
1195 try writer.print(" | .{s}", .{@tagName(mir_inst.ops)});
1196 switch (mir_inst.ops) {
1197 else => unreachable,
1198 .pseudo_dbg_prologue_end_none,
1199 .pseudo_dbg_line_line_column,
1200 .pseudo_dbg_epilogue_begin_none,
1201 .pseudo_dbg_enter_block_none,
1202 .pseudo_dbg_leave_block_none,
1203 .pseudo_dbg_var_args_none,
1204 .pseudo_dead_none,
1205 => {},
1206 .pseudo_dbg_enter_inline_func, .pseudo_dbg_leave_inline_func => try writer.print(" {}", .{
1207 ip.getNav(ip.indexToKey(mir_inst.data.func).func.owner_nav).name.fmt(ip),
1208 }),
1209 .pseudo_dbg_local_a => try writer.print(" {}", .{mir_inst.data.a.air_inst}),
1210 .pseudo_dbg_local_ai_s => try writer.print(" {}, {d}", .{
1211 mir_inst.data.ai.air_inst,
1212 @as(i32, @bitCast(mir_inst.data.ai.i)),
1213 }),
1214 .pseudo_dbg_local_ai_u => try writer.print(" {}, {d}", .{
1215 mir_inst.data.ai.air_inst,
1216 mir_inst.data.ai.i,
1217 }),
1218 .pseudo_dbg_local_ai_64 => try writer.print(" {}, {d}", .{
1219 mir_inst.data.ai.air_inst,
1220 lower.mir.extraData(Mir.Imm64, mir_inst.data.ai.i).data.decode(),
1221 }),
1222 .pseudo_dbg_local_as => {
1223 const mem_op: Instruction.Operand = .{ .mem = .initSib(.qword, .{
1224 .base = .{ .reloc = mir_inst.data.as.sym_index },
1225 }) };
1226 try writer.print(" {}, {}", .{ mir_inst.data.as.air_inst, mem_op.fmt(.m) });
1227 },
1228 .pseudo_dbg_local_aso => {
1229 const sym_off = lower.mir.extraData(bits.SymbolOffset, mir_inst.data.ax.payload).data;
1230 const mem_op: Instruction.Operand = .{ .mem = .initSib(.qword, .{
1231 .base = .{ .reloc = sym_off.sym_index },
1232 .disp = sym_off.off,
1233 }) };
1234 try writer.print(" {}, {}", .{ mir_inst.data.ax.air_inst, mem_op.fmt(.m) });
1235 },
1236 .pseudo_dbg_local_aro => {
1237 const air_off = lower.mir.extraData(Mir.AirOffset, mir_inst.data.rx.payload).data;
1238 const mem_op: Instruction.Operand = .{ .mem = .initSib(.qword, .{
1239 .base = .{ .reg = mir_inst.data.rx.r1 },
1240 .disp = air_off.off,
1241 }) };
1242 try writer.print(" {}, {}", .{ air_off.air_inst, mem_op.fmt(.m) });
1243 },
1244 .pseudo_dbg_local_af => {
1245 const frame_addr = lower.mir.extraData(bits.FrameAddr, mir_inst.data.ax.payload).data;
1246 const mem_op: Instruction.Operand = .{ .mem = .initSib(.qword, .{
1247 .base = .{ .frame = frame_addr.index },
1248 .disp = frame_addr.off,
1249 }) };
1250 try writer.print(" {}, {d}", .{ mir_inst.data.ax.air_inst, mem_op.fmt(.m) });
1251 },
1252 .pseudo_dbg_local_am => {
1253 const mem_op: Instruction.Operand = .{
1254 .mem = lower.mir.extraData(Mir.Memory, mir_inst.data.ax.payload).data.decode(),
1255 };
1256 try writer.print(" {}, {}", .{ mir_inst.data.ax.air_inst, mem_op.fmt(.m) });
1257 },
1258 }
1259 }
1191}1260}
1192fn fmtWipMir(self: *Self, inst: Mir.Inst.Index) std.fmt.Formatter(formatWipMir) {1261fn fmtWipMir(self: *Self, inst: Mir.Inst.Index) std.fmt.Formatter(formatWipMir) {
1193 return .{ .data = .{ .self = self, .inst = inst } };1262 return .{ .data = .{ .self = self, .inst = inst } };
src/arch/x86_64/encoder.zig+4-4
...@@ -233,7 +233,7 @@ pub const Instruction = struct {...@@ -233,7 +233,7 @@ pub const Instruction = struct {
233 _ = unused_format_string;233 _ = unused_format_string;
234 _ = options;234 _ = options;
235 _ = writer;235 _ = writer;
236 @compileError("do not format Operand directly; use fmtPrint() instead");236 @compileError("do not format Operand directly; use fmt() instead");
237 }237 }
238238
239 const FormatContext = struct {239 const FormatContext = struct {
...@@ -241,7 +241,7 @@ pub const Instruction = struct {...@@ -241,7 +241,7 @@ pub const Instruction = struct {
241 enc_op: Encoding.Op,241 enc_op: Encoding.Op,
242 };242 };
243243
244 fn fmt(244 fn fmtContext(
245 ctx: FormatContext,245 ctx: FormatContext,
246 comptime unused_format_string: []const u8,246 comptime unused_format_string: []const u8,
247 options: std.fmt.FormatOptions,247 options: std.fmt.FormatOptions,
...@@ -309,7 +309,7 @@ pub const Instruction = struct {...@@ -309,7 +309,7 @@ pub const Instruction = struct {
309 }309 }
310 }310 }
311311
312 pub fn fmtPrint(op: Operand, enc_op: Encoding.Op) std.fmt.Formatter(fmt) {312 pub fn fmt(op: Operand, enc_op: Encoding.Op) std.fmt.Formatter(fmtContext) {
313 return .{ .data = .{ .op = op, .enc_op = enc_op } };313 return .{ .data = .{ .op = op, .enc_op = enc_op } };
314 }314 }
315 };315 };
...@@ -373,7 +373,7 @@ pub const Instruction = struct {...@@ -373,7 +373,7 @@ pub const Instruction = struct {
373 if (op == .none) break;373 if (op == .none) break;
374 if (i > 0) try writer.writeByte(',');374 if (i > 0) try writer.writeByte(',');
375 try writer.writeByte(' ');375 try writer.writeByte(' ');
376 try writer.print("{}", .{op.fmtPrint(enc)});376 try writer.print("{}", .{op.fmt(enc)});
377 }377 }
378 }378 }
379379