authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-01 19:48:34-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-07 22:43:52-07:00
log941bc3719382a4f6245ad42175d911964f1bc9a4
treef17c7a8b9afb241b7de4f43973bea882cb06bf2d
parent49be02e6d75acd996d9b2a573714552ba081ea13

compiler: update all instances of std.fmt.Formatter


29 files changed, 699 insertions(+), 1137 deletions(-)

lib/compiler/aro/aro/Diagnostics.zig+3-3
......@@ -542,15 +542,15 @@ const MsgWriter = struct {
542542 }
543543
544544 pub fn print(m: *MsgWriter, comptime fmt: []const u8, args: anytype) void {
545 m.w.writer().print(fmt, args) catch {};
545 m.w.interface.print(fmt, args) catch {};
546546 }
547547
548548 fn write(m: *MsgWriter, msg: []const u8) void {
549 m.w.writer().writeAll(msg) catch {};
549 m.w.interface.writeAll(msg) catch {};
550550 }
551551
552552 fn setColor(m: *MsgWriter, color: std.io.tty.Color) void {
553 m.config.setColor(m.w.writer(), color) catch {};
553 m.config.setColor(m.w.interface, color) catch {};
554554 }
555555
556556 fn location(m: *MsgWriter, path: []const u8, line: u32, col: u32) void {
src/Compilation.zig+2-4
......@@ -6012,9 +6012,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
60126012
60136013 // In .rc files, a " within a quoted string is escaped as ""
60146014 const fmtRcEscape = struct {
6015 fn formatRcEscape(bytes: []const u8, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
6016 _ = fmt;
6017 _ = options;
6015 fn formatRcEscape(bytes: []const u8, writer: *std.io.Writer) std.io.Writer.Error!void {
60186016 for (bytes) |byte| switch (byte) {
60196017 '"' => try writer.writeAll("\"\""),
60206018 '\\' => try writer.writeAll("\\\\"),
......@@ -6022,7 +6020,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
60226020 };
60236021 }
60246022
6025 pub fn fmtRcEscape(bytes: []const u8) std.fmt.Formatter(formatRcEscape) {
6023 pub fn fmtRcEscape(bytes: []const u8) std.fmt.Formatter([]const u8, formatRcEscape) {
60266024 return .{ .data = bytes };
60276025 }
60286026 }.fmtRcEscape;
src/Type.zig+10-25
......@@ -121,15 +121,14 @@ pub fn eql(a: Type, b: Type, zcu: *const Zcu) bool {
121121 return a.toIntern() == b.toIntern();
122122}
123123
124pub fn format(ty: Type, comptime unused_fmt_string: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
124pub fn format(ty: Type, writer: *std.io.Writer, comptime unused_fmt_string: []const u8) !void {
125125 _ = ty;
126126 _ = unused_fmt_string;
127 _ = options;
128127 _ = writer;
129128 @compileError("do not format types directly; use either ty.fmtDebug() or ty.fmt()");
130129}
131130
132pub const Formatter = std.fmt.Formatter(format2);
131pub const Formatter = std.fmt.Formatter(Format, Format.default);
133132
134133pub fn fmt(ty: Type, pt: Zcu.PerThread) Formatter {
135134 return .{ .data = .{
......@@ -138,42 +137,28 @@ pub fn fmt(ty: Type, pt: Zcu.PerThread) Formatter {
138137 } };
139138}
140139
141const FormatContext = struct {
140const Format = struct {
142141 ty: Type,
143142 pt: Zcu.PerThread,
144};
145143
146fn format2(
147 ctx: FormatContext,
148 comptime unused_format_string: []const u8,
149 options: std.fmt.FormatOptions,
150 writer: anytype,
151) !void {
152 comptime assert(unused_format_string.len == 0);
153 _ = options;
154 return print(ctx.ty, writer, ctx.pt);
155}
144 fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
145 return print(f.ty, writer, f.pt);
146 }
147};
156148
157pub fn fmtDebug(ty: Type) std.fmt.Formatter(dump) {
149pub fn fmtDebug(ty: Type) std.fmt.Formatter(Type, dump) {
158150 return .{ .data = ty };
159151}
160152
161153/// This is a debug function. In order to print types in a meaningful way
162154/// we also need access to the module.
163pub fn dump(
164 start_type: Type,
165 comptime unused_format_string: []const u8,
166 options: std.fmt.FormatOptions,
167 writer: anytype,
168) @TypeOf(writer).Error!void {
169 _ = options;
170 comptime assert(unused_format_string.len == 0);
155pub fn dump(start_type: Type, writer: *std.io.Writer) std.io.Writer.Error!void {
171156 return writer.print("{any}", .{start_type.ip_index});
172157}
173158
174159/// Prints a name suitable for `@typeName`.
175160/// TODO: take an `opt_sema` to pass to `fmtValue` when printing sentinels.
176pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error!void {
161pub fn print(ty: Type, writer: *std.io.Writer, pt: Zcu.PerThread) std.io.Writer.Error!void {
177162 const zcu = pt.zcu;
178163 const ip = &zcu.intern_pool;
179164 switch (ip.indexToKey(ty.toIntern())) {
src/Value.zig+8-15
......@@ -15,31 +15,24 @@ const Value = @This();
1515
1616ip_index: InternPool.Index,
1717
18pub fn format(val: Value, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
18pub fn format(val: Value, writer: *std.io.Writer, comptime fmt: []const u8) !void {
1919 _ = val;
20 _ = fmt;
21 _ = options;
2220 _ = writer;
21 _ = fmt;
2322 @compileError("do not use format values directly; use either fmtDebug or fmtValue");
2423}
2524
2625/// This is a debug function. In order to print values in a meaningful way
2726/// we also need access to the type.
28pub fn dump(
29 start_val: Value,
30 comptime fmt: []const u8,
31 _: std.fmt.FormatOptions,
32 out_stream: anytype,
33) !void {
34 comptime assert(fmt.len == 0);
35 try out_stream.print("(interned: {})", .{start_val.toIntern()});
27pub fn dump(start_val: Value, w: std.io.Writer) std.io.Writer.Error!void {
28 try w.print("(interned: {})", .{start_val.toIntern()});
3629}
3730
38pub fn fmtDebug(val: Value) std.fmt.Formatter(dump) {
31pub fn fmtDebug(val: Value) std.fmt.Formatter(Value, dump) {
3932 return .{ .data = val };
4033}
4134
42pub fn fmtValue(val: Value, pt: Zcu.PerThread) std.fmt.Formatter(print_value.format) {
35pub fn fmtValue(val: Value, pt: Zcu.PerThread) std.fmt.Formatter(print_value.FormatContext, print_value.format) {
4336 return .{ .data = .{
4437 .val = val,
4538 .pt = pt,
......@@ -48,7 +41,7 @@ pub fn fmtValue(val: Value, pt: Zcu.PerThread) std.fmt.Formatter(print_value.for
4841 } };
4942}
5043
51pub fn fmtValueSema(val: Value, pt: Zcu.PerThread, sema: *Sema) std.fmt.Formatter(print_value.formatSema) {
44pub fn fmtValueSema(val: Value, pt: Zcu.PerThread, sema: *Sema) std.fmt.Formatter(print_value.FormatContext, print_value.formatSema) {
5245 return .{ .data = .{
5346 .val = val,
5447 .pt = pt,
......@@ -57,7 +50,7 @@ pub fn fmtValueSema(val: Value, pt: Zcu.PerThread, sema: *Sema) std.fmt.Formatte
5750 } };
5851}
5952
60pub fn fmtValueSemaFull(ctx: print_value.FormatContext) std.fmt.Formatter(print_value.formatSema) {
53pub fn fmtValueSemaFull(ctx: print_value.FormatContext) std.fmt.Formatter(print_value.FormatContext, print_value.formatSema) {
6154 return .{ .data = ctx };
6255}
6356
src/arch/riscv64/CodeGen.zig+16-32
......@@ -937,12 +937,7 @@ const FormatWipMirData = struct {
937937 func: *Func,
938938 inst: Mir.Inst.Index,
939939};
940fn formatWipMir(
941 data: FormatWipMirData,
942 comptime _: []const u8,
943 _: std.fmt.FormatOptions,
944 writer: anytype,
945) @TypeOf(writer).Error!void {
940fn formatWipMir(data: FormatWipMirData, writer: *std.io.Writer) std.io.Writer.Error!void {
946941 const pt = data.func.pt;
947942 const comp = pt.zcu.comp;
948943 var lower: Lower = .{
......@@ -982,7 +977,7 @@ fn formatWipMir(
982977 first = false;
983978 }
984979}
985fn fmtWipMir(func: *Func, inst: Mir.Inst.Index) std.fmt.Formatter(formatWipMir) {
980fn fmtWipMir(func: *Func, inst: Mir.Inst.Index) std.fmt.Formatter(FormatWipMirData, formatWipMir) {
986981 return .{ .data = .{ .func = func, .inst = inst } };
987982}
988983
......@@ -990,15 +985,10 @@ const FormatNavData = struct {
990985 ip: *const InternPool,
991986 nav_index: InternPool.Nav.Index,
992987};
993fn formatNav(
994 data: FormatNavData,
995 comptime _: []const u8,
996 _: std.fmt.FormatOptions,
997 writer: anytype,
998) @TypeOf(writer).Error!void {
999 try writer.print("{}", .{data.ip.getNav(data.nav_index).fqn.fmt(data.ip)});
1000}
1001fn fmtNav(nav_index: InternPool.Nav.Index, ip: *const InternPool) std.fmt.Formatter(formatNav) {
988fn formatNav(data: FormatNavData, writer: *std.io.Writer) std.io.Writer.Error!void {
989 try writer.print("{f}", .{data.ip.getNav(data.nav_index).fqn.fmt(data.ip)});
990}
991fn fmtNav(nav_index: InternPool.Nav.Index, ip: *const InternPool) std.fmt.Formatter(FormatNavData, formatNav) {
1002992 return .{ .data = .{
1003993 .ip = ip,
1004994 .nav_index = nav_index,
......@@ -1009,31 +999,25 @@ const FormatAirData = struct {
1009999 func: *Func,
10101000 inst: Air.Inst.Index,
10111001};
1012fn formatAir(
1013 data: FormatAirData,
1014 comptime _: []const u8,
1015 _: std.fmt.FormatOptions,
1016 writer: anytype,
1017) @TypeOf(writer).Error!void {
1018 data.func.air.dumpInst(data.inst, data.func.pt, data.func.liveness);
1019}
1020fn fmtAir(func: *Func, inst: Air.Inst.Index) std.fmt.Formatter(formatAir) {
1002fn formatAir(data: FormatAirData, writer: *std.io.Writer) std.io.Writer.Error!void {
1003 // Not acceptable implementation because it ignores `writer`:
1004 //data.func.air.dumpInst(data.inst, data.func.pt, data.func.liveness);
1005 _ = data;
1006 _ = writer;
1007 @panic("unimplemented");
1008}
1009fn fmtAir(func: *Func, inst: Air.Inst.Index) std.fmt.Formatter(FormatAirData, formatAir) {
10211010 return .{ .data = .{ .func = func, .inst = inst } };
10221011}
10231012
10241013const FormatTrackingData = struct {
10251014 func: *Func,
10261015};
1027fn formatTracking(
1028 data: FormatTrackingData,
1029 comptime _: []const u8,
1030 _: std.fmt.FormatOptions,
1031 writer: anytype,
1032) @TypeOf(writer).Error!void {
1016fn formatTracking(data: FormatTrackingData, writer: *std.io.Writer) std.io.Writer.Error!void {
10331017 var it = data.func.inst_tracking.iterator();
10341018 while (it.next()) |entry| try writer.print("\n%{d} = {}", .{ entry.key_ptr.*, entry.value_ptr.* });
10351019}
1036fn fmtTracking(func: *Func) std.fmt.Formatter(formatTracking) {
1020fn fmtTracking(func: *Func) std.fmt.Formatter(FormatTrackingData, formatTracking) {
10371021 return .{ .data = .{ .func = func } };
10381022}
10391023
src/arch/x86_64/CodeGen.zig+208-233
......@@ -6,6 +6,7 @@ const log = std.log.scoped(.codegen);
66const tracking_log = std.log.scoped(.tracking);
77const verbose_tracking_log = std.log.scoped(.verbose_tracking);
88const wip_mir_log = std.log.scoped(.wip_mir);
9const Writer = std.io.Writer;
910
1011const Air = @import("../../Air.zig");
1112const Allocator = std.mem.Allocator;
......@@ -524,52 +525,47 @@ pub const MCValue = union(enum) {
524525 };
525526 }
526527
527 pub fn format(
528 mcv: MCValue,
529 comptime _: []const u8,
530 _: std.fmt.FormatOptions,
531 writer: anytype,
532 ) @TypeOf(writer).Error!void {
528 pub fn format(mcv: MCValue, bw: *Writer, comptime _: []const u8) Writer.Error!void {
533529 switch (mcv) {
534 .none, .unreach, .dead, .undef => try writer.print("({s})", .{@tagName(mcv)}),
535 .immediate => |pl| try writer.print("0x{x}", .{pl}),
536 .memory => |pl| try writer.print("[ds:0x{x}]", .{pl}),
537 inline .eflags, .register => |pl| try writer.print("{s}", .{@tagName(pl)}),
538 .register_pair => |pl| try writer.print("{s}:{s}", .{ @tagName(pl[1]), @tagName(pl[0]) }),
539 .register_triple => |pl| try writer.print("{s}:{s}:{s}", .{
530 .none, .unreach, .dead, .undef => try bw.print("({s})", .{@tagName(mcv)}),
531 .immediate => |pl| try bw.print("0x{x}", .{pl}),
532 .memory => |pl| try bw.print("[ds:0x{x}]", .{pl}),
533 inline .eflags, .register => |pl| try bw.print("{s}", .{@tagName(pl)}),
534 .register_pair => |pl| try bw.print("{s}:{s}", .{ @tagName(pl[1]), @tagName(pl[0]) }),
535 .register_triple => |pl| try bw.print("{s}:{s}:{s}", .{
540536 @tagName(pl[2]), @tagName(pl[1]), @tagName(pl[0]),
541537 }),
542 .register_quadruple => |pl| try writer.print("{s}:{s}:{s}:{s}", .{
538 .register_quadruple => |pl| try bw.print("{s}:{s}:{s}:{s}", .{
543539 @tagName(pl[3]), @tagName(pl[2]), @tagName(pl[1]), @tagName(pl[0]),
544540 }),
545 .register_offset => |pl| try writer.print("{s} + 0x{x}", .{ @tagName(pl.reg), pl.off }),
546 .register_overflow => |pl| try writer.print("{s}:{s}", .{
541 .register_offset => |pl| try bw.print("{s} + 0x{x}", .{ @tagName(pl.reg), pl.off }),
542 .register_overflow => |pl| try bw.print("{s}:{s}", .{
547543 @tagName(pl.eflags),
548544 @tagName(pl.reg),
549545 }),
550 .register_mask => |pl| try writer.print("mask({s},{}):{c}{s}", .{
546 .register_mask => |pl| try bw.print("mask({s},{f}):{c}{s}", .{
551547 @tagName(pl.info.kind),
552548 pl.info.scalar,
553549 @as(u8, if (pl.info.inverted) '!' else ' '),
554550 @tagName(pl.reg),
555551 }),
556 .indirect => |pl| try writer.print("[{s} + 0x{x}]", .{ @tagName(pl.reg), pl.off }),
557 .indirect_load_frame => |pl| try writer.print("[[{} + 0x{x}]]", .{ pl.index, pl.off }),
558 .load_frame => |pl| try writer.print("[{} + 0x{x}]", .{ pl.index, pl.off }),
559 .lea_frame => |pl| try writer.print("{} + 0x{x}", .{ pl.index, pl.off }),
560 .load_nav => |pl| try writer.print("[nav:{d}]", .{@intFromEnum(pl)}),
561 .lea_nav => |pl| try writer.print("nav:{d}", .{@intFromEnum(pl)}),
562 .load_uav => |pl| try writer.print("[uav:{d}]", .{@intFromEnum(pl.val)}),
563 .lea_uav => |pl| try writer.print("uav:{d}", .{@intFromEnum(pl.val)}),
564 .load_lazy_sym => |pl| try writer.print("[lazy:{s}:{d}]", .{ @tagName(pl.kind), @intFromEnum(pl.ty) }),
565 .lea_lazy_sym => |pl| try writer.print("lazy:{s}:{d}", .{ @tagName(pl.kind), @intFromEnum(pl.ty) }),
566 .load_extern_func => |pl| try writer.print("[extern:{d}]", .{@intFromEnum(pl)}),
567 .lea_extern_func => |pl| try writer.print("extern:{d}", .{@intFromEnum(pl)}),
568 .elementwise_args => |pl| try writer.print("elementwise:{d}:[{} + 0x{x}]", .{
552 .indirect => |pl| try bw.print("[{s} + 0x{x}]", .{ @tagName(pl.reg), pl.off }),
553 .indirect_load_frame => |pl| try bw.print("[[{} + 0x{x}]]", .{ pl.index, pl.off }),
554 .load_frame => |pl| try bw.print("[{} + 0x{x}]", .{ pl.index, pl.off }),
555 .lea_frame => |pl| try bw.print("{} + 0x{x}", .{ pl.index, pl.off }),
556 .load_nav => |pl| try bw.print("[nav:{d}]", .{@intFromEnum(pl)}),
557 .lea_nav => |pl| try bw.print("nav:{d}", .{@intFromEnum(pl)}),
558 .load_uav => |pl| try bw.print("[uav:{d}]", .{@intFromEnum(pl.val)}),
559 .lea_uav => |pl| try bw.print("uav:{d}", .{@intFromEnum(pl.val)}),
560 .load_lazy_sym => |pl| try bw.print("[lazy:{s}:{d}]", .{ @tagName(pl.kind), @intFromEnum(pl.ty) }),
561 .lea_lazy_sym => |pl| try bw.print("lazy:{s}:{d}", .{ @tagName(pl.kind), @intFromEnum(pl.ty) }),
562 .load_extern_func => |pl| try bw.print("[extern:{d}]", .{@intFromEnum(pl)}),
563 .lea_extern_func => |pl| try bw.print("extern:{d}", .{@intFromEnum(pl)}),
564 .elementwise_args => |pl| try bw.print("elementwise:{d}:[{} + 0x{x}]", .{
569565 pl.regs, pl.frame_index, pl.frame_off,
570566 }),
571 .reserved_frame => |pl| try writer.print("(dead:{})", .{pl}),
572 .air_ref => |pl| try writer.print("(air:0x{x})", .{@intFromEnum(pl)}),
567 .reserved_frame => |pl| try bw.print("(dead:{})", .{pl}),
568 .air_ref => |pl| try bw.print("(air:0x{x})", .{@intFromEnum(pl)}),
573569 }
574570 }
575571};
......@@ -639,7 +635,7 @@ const InstTracking = struct {
639635 .reserved_frame => |index| self.long = .{ .load_frame = .{ .index = index } },
640636 else => unreachable,
641637 }
642 tracking_log.debug("spill {} from {} to {}", .{ inst, self.short, self.long });
638 tracking_log.debug("spill {f} from {f} to {f}", .{ inst, self.short, self.long });
643639 try cg.genCopy(cg.typeOfIndex(inst), self.long, self.short, .{});
644640 for (self.short.getRegs()) |reg| if (reg.isClass(.x87)) try cg.asmRegister(.{ .f_, .free }, reg);
645641 }
......@@ -672,7 +668,7 @@ const InstTracking = struct {
672668 else => {}, // TODO process stack allocation death
673669 }
674670 self.reuseFrame();
675 tracking_log.debug("{} => {} (spilled)", .{ inst, self.* });
671 tracking_log.debug("{f} => {f} (spilled)", .{ inst, self.* });
676672 }
677673
678674 fn verifyMaterialize(self: InstTracking, target: InstTracking) void {
......@@ -749,7 +745,7 @@ const InstTracking = struct {
749745 else => target.long,
750746 } else target.long;
751747 self.short = target.short;
752 tracking_log.debug("{} => {} (materialize)", .{ inst, self.* });
748 tracking_log.debug("{f} => {f} (materialize)", .{ inst, self.* });
753749 }
754750
755751 fn resurrect(self: *InstTracking, function: *CodeGen, inst: Air.Inst.Index, scope_generation: u32) !void {
......@@ -757,7 +753,7 @@ const InstTracking = struct {
757753 .dead => |die_generation| if (die_generation >= scope_generation) {
758754 self.reuseFrame();
759755 try function.getValue(self.short, inst);
760 tracking_log.debug("{} => {} (resurrect)", .{ inst, self.* });
756 tracking_log.debug("{f} => {f} (resurrect)", .{ inst, self.* });
761757 },
762758 else => {},
763759 }
......@@ -768,7 +764,7 @@ const InstTracking = struct {
768764 try function.freeValue(self.short, opts);
769765 if (self.long == .none) self.long = self.short;
770766 self.short = .{ .dead = function.scope_generation };
771 tracking_log.debug("{} => {} (death)", .{ inst, self.* });
767 tracking_log.debug("{f} => {f} (death)", .{ inst, self.* });
772768 }
773769
774770 fn reuse(
......@@ -778,13 +774,13 @@ const InstTracking = struct {
778774 old_inst: Air.Inst.Index,
779775 ) void {
780776 self.short = .{ .dead = function.scope_generation };
781 tracking_log.debug("{?} => {} (reuse {})", .{ new_inst, self.*, old_inst });
777 tracking_log.debug("{?f} => {f} (reuse {f})", .{ new_inst, self.*, old_inst });
782778 }
783779
784780 fn liveOut(self: *InstTracking, function: *CodeGen, inst: Air.Inst.Index) void {
785781 for (self.getRegs()) |reg| {
786782 if (function.register_manager.isRegFree(reg)) {
787 tracking_log.debug("{} => {} (live-out)", .{ inst, self.* });
783 tracking_log.debug("{f} => {f} (live-out)", .{ inst, self.* });
788784 continue;
789785 }
790786
......@@ -812,18 +808,13 @@ const InstTracking = struct {
812808 // Perform side-effects of freeValue manually.
813809 function.register_manager.freeReg(reg);
814810
815 tracking_log.debug("{} => {} (live-out {})", .{ inst, self.*, tracked_inst });
811 tracking_log.debug("{f} => {f} (live-out {f})", .{ inst, self.*, tracked_inst });
816812 }
817813 }
818814
819 pub fn format(
820 tracking: InstTracking,
821 comptime _: []const u8,
822 _: std.fmt.FormatOptions,
823 writer: anytype,
824 ) @TypeOf(writer).Error!void {
825 if (!std.meta.eql(tracking.long, tracking.short)) try writer.print("|{}| ", .{tracking.long});
826 try writer.print("{}", .{tracking.short});
815 pub fn format(tracking: InstTracking, bw: *Writer, comptime _: []const u8) Writer.Error!void {
816 if (!std.meta.eql(tracking.long, tracking.short)) try bw.print("|{f}| ", .{tracking.long});
817 try bw.print("{f}", .{tracking.short});
827818 }
828819};
829820
......@@ -939,7 +930,7 @@ pub fn generate(
939930 function.inst_tracking.putAssumeCapacityNoClobber(temp.toIndex(), .init(.none));
940931 }
941932
942 wip_mir_log.debug("{}:", .{fmtNav(func.owner_nav, ip)});
933 wip_mir_log.debug("{f}:", .{fmtNav(func.owner_nav, ip)});
943934
944935 try function.frame_allocs.resize(gpa, FrameIndex.named_count);
945936 function.frame_allocs.set(
......@@ -1097,15 +1088,10 @@ const FormatNavData = struct {
10971088 ip: *const InternPool,
10981089 nav_index: InternPool.Nav.Index,
10991090};
1100fn formatNav(
1101 data: FormatNavData,
1102 comptime _: []const u8,
1103 _: std.fmt.FormatOptions,
1104 writer: anytype,
1105) @TypeOf(writer).Error!void {
1106 try writer.print("{}", .{data.ip.getNav(data.nav_index).fqn.fmt(data.ip)});
1091fn formatNav(data: FormatNavData, w: *Writer) Writer.Error!void {
1092 try w.print("{f}", .{data.ip.getNav(data.nav_index).fqn.fmt(data.ip)});
11071093}
1108fn fmtNav(nav_index: InternPool.Nav.Index, ip: *const InternPool) std.fmt.Formatter(formatNav) {
1094fn fmtNav(nav_index: InternPool.Nav.Index, ip: *const InternPool) std.fmt.Formatter(FormatNavData, formatNav) {
11091095 return .{ .data = .{
11101096 .ip = ip,
11111097 .nav_index = nav_index,
......@@ -1116,15 +1102,14 @@ const FormatAirData = struct {
11161102 self: *CodeGen,
11171103 inst: Air.Inst.Index,
11181104};
1119fn formatAir(
1120 data: FormatAirData,
1121 comptime _: []const u8,
1122 _: std.fmt.FormatOptions,
1123 writer: anytype,
1124) @TypeOf(writer).Error!void {
1125 data.self.air.dumpInst(data.inst, data.self.pt, data.self.liveness);
1105fn formatAir(data: FormatAirData, w: *std.io.Writer) Writer.Error!void {
1106 // not acceptable implementation because it ignores `w`:
1107 //data.self.air.dumpInst(data.inst, data.self.pt, data.self.liveness);
1108 _ = data;
1109 _ = w;
1110 @panic("TODO: unimplemented");
11261111}
1127fn fmtAir(self: *CodeGen, inst: Air.Inst.Index) std.fmt.Formatter(formatAir) {
1112fn fmtAir(self: *CodeGen, inst: Air.Inst.Index) std.fmt.Formatter(FormatAirData, formatAir) {
11281113 return .{ .data = .{ .self = self, .inst = inst } };
11291114}
11301115
......@@ -1132,12 +1117,7 @@ const FormatWipMirData = struct {
11321117 self: *CodeGen,
11331118 inst: Mir.Inst.Index,
11341119};
1135fn formatWipMir(
1136 data: FormatWipMirData,
1137 comptime _: []const u8,
1138 _: std.fmt.FormatOptions,
1139 writer: anytype,
1140) @TypeOf(writer).Error!void {
1120fn formatWipMir(data: FormatWipMirData, w: *Writer) Writer.Error!void {
11411121 var lower: Lower = .{
11421122 .target = data.self.target,
11431123 .allocator = data.self.gpa,
......@@ -1152,11 +1132,11 @@ fn formatWipMir(
11521132 lower.err_msg.?.deinit(data.self.gpa);
11531133 lower.err_msg = null;
11541134 }
1155 try writer.writeAll(lower.err_msg.?.msg);
1135 try w.writeAll(lower.err_msg.?.msg);
11561136 return;
11571137 },
11581138 error.OutOfMemory, error.InvalidInstruction, error.CannotEncode => |e| {
1159 try writer.writeAll(switch (e) {
1139 try w.writeAll(switch (e) {
11601140 error.OutOfMemory => "Out of memory",
11611141 error.InvalidInstruction => "CodeGen failed to find a viable instruction.",
11621142 error.CannotEncode => "CodeGen failed to encode the instruction.",
......@@ -1165,14 +1145,14 @@ fn formatWipMir(
11651145 },
11661146 else => |e| return e,
11671147 }).insts) |lowered_inst| {
1168 if (!first) try writer.writeAll("\ndebug(wip_mir): ");
1169 try writer.print(" | {}", .{lowered_inst});
1148 if (!first) try w.writeAll("\ndebug(wip_mir): ");
1149 try w.print(" | {f}", .{lowered_inst});
11701150 first = false;
11711151 }
11721152 if (first) {
11731153 const ip = &data.self.pt.zcu.intern_pool;
11741154 const mir_inst = lower.mir.instructions.get(data.inst);
1175 try writer.print(" | .{s}", .{@tagName(mir_inst.ops)});
1155 try w.print(" | .{s}", .{@tagName(mir_inst.ops)});
11761156 switch (mir_inst.ops) {
11771157 else => unreachable,
11781158 .pseudo_dbg_prologue_end_none,
......@@ -1184,20 +1164,20 @@ fn formatWipMir(
11841164 .pseudo_dbg_var_none,
11851165 .pseudo_dead_none,
11861166 => {},
1187 .pseudo_dbg_line_stmt_line_column, .pseudo_dbg_line_line_column => try writer.print(
1167 .pseudo_dbg_line_stmt_line_column, .pseudo_dbg_line_line_column => try w.print(
11881168 " {[line]d}, {[column]d}",
11891169 mir_inst.data.line_column,
11901170 ),
1191 .pseudo_dbg_enter_inline_func, .pseudo_dbg_leave_inline_func => try writer.print(" {}", .{
1171 .pseudo_dbg_enter_inline_func, .pseudo_dbg_leave_inline_func => try w.print(" {f}", .{
11921172 ip.getNav(ip.indexToKey(mir_inst.data.ip_index).func.owner_nav).name.fmt(ip),
11931173 }),
1194 .pseudo_dbg_arg_i_s, .pseudo_dbg_var_i_s => try writer.print(" {d}", .{
1174 .pseudo_dbg_arg_i_s, .pseudo_dbg_var_i_s => try w.print(" {d}", .{
11951175 @as(i32, @bitCast(mir_inst.data.i.i)),
11961176 }),
1197 .pseudo_dbg_arg_i_u, .pseudo_dbg_var_i_u => try writer.print(" {d}", .{
1177 .pseudo_dbg_arg_i_u, .pseudo_dbg_var_i_u => try w.print(" {d}", .{
11981178 mir_inst.data.i.i,
11991179 }),
1200 .pseudo_dbg_arg_i_64, .pseudo_dbg_var_i_64 => try writer.print(" {d}", .{
1180 .pseudo_dbg_arg_i_64, .pseudo_dbg_var_i_64 => try w.print(" {d}", .{
12011181 mir_inst.data.i64,
12021182 }),
12031183 .pseudo_dbg_arg_ro, .pseudo_dbg_var_ro => {
......@@ -1205,44 +1185,39 @@ fn formatWipMir(
12051185 .base = .{ .reg = mir_inst.data.ro.reg },
12061186 .disp = mir_inst.data.ro.off,
12071187 }) };
1208 try writer.print(" {}", .{mem_op.fmt(.m)});
1188 try w.print(" {f}", .{mem_op.fmt(.m)});
12091189 },
12101190 .pseudo_dbg_arg_fa, .pseudo_dbg_var_fa => {
12111191 const mem_op: encoder.Instruction.Operand = .{ .mem = .initSib(.qword, .{
12121192 .base = .{ .frame = mir_inst.data.fa.index },
12131193 .disp = mir_inst.data.fa.off,
12141194 }) };
1215 try writer.print(" {}", .{mem_op.fmt(.m)});
1195 try w.print(" {f}", .{mem_op.fmt(.m)});
12161196 },
12171197 .pseudo_dbg_arg_m, .pseudo_dbg_var_m => {
12181198 const mem_op: encoder.Instruction.Operand = .{
12191199 .mem = lower.mir.extraData(Mir.Memory, mir_inst.data.x.payload).data.decode(),
12201200 };
1221 try writer.print(" {}", .{mem_op.fmt(.m)});
1201 try w.print(" {f}", .{mem_op.fmt(.m)});
12221202 },
1223 .pseudo_dbg_arg_val, .pseudo_dbg_var_val => try writer.print(" {}", .{
1203 .pseudo_dbg_arg_val, .pseudo_dbg_var_val => try w.print(" {}", .{
12241204 Value.fromInterned(mir_inst.data.ip_index).fmtValue(data.self.pt),
12251205 }),
12261206 }
12271207 }
12281208}
1229fn fmtWipMir(self: *CodeGen, inst: Mir.Inst.Index) std.fmt.Formatter(formatWipMir) {
1209fn fmtWipMir(self: *CodeGen, inst: Mir.Inst.Index) std.fmt.Formatter(FormatWipMirData, formatWipMir) {
12301210 return .{ .data = .{ .self = self, .inst = inst } };
12311211}
12321212
12331213const FormatTrackingData = struct {
12341214 self: *CodeGen,
12351215};
1236fn formatTracking(
1237 data: FormatTrackingData,
1238 comptime _: []const u8,
1239 _: std.fmt.FormatOptions,
1240 writer: anytype,
1241) @TypeOf(writer).Error!void {
1216fn formatTracking(data: FormatTrackingData, w: *Writer) Writer.Error!void {
12421217 var it = data.self.inst_tracking.iterator();
1243 while (it.next()) |entry| try writer.print("\n{} = {}", .{ entry.key_ptr.*, entry.value_ptr.* });
1218 while (it.next()) |entry| try w.print("\n{f} = {f}", .{ entry.key_ptr.*, entry.value_ptr.* });
12441219}
1245fn fmtTracking(self: *CodeGen) std.fmt.Formatter(formatTracking) {
1220fn fmtTracking(self: *CodeGen) std.fmt.Formatter(FormatTrackingData, formatTracking) {
12461221 return .{ .data = .{ .self = self } };
12471222}
12481223
......@@ -1251,7 +1226,7 @@ fn addInst(self: *CodeGen, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {
12511226 try self.mir_instructions.ensureUnusedCapacity(gpa, 1);
12521227 const result_index: Mir.Inst.Index = @intCast(self.mir_instructions.len);
12531228 self.mir_instructions.appendAssumeCapacity(inst);
1254 if (inst.ops != .pseudo_dead_none) wip_mir_log.debug("{}", .{self.fmtWipMir(result_index)});
1229 if (inst.ops != .pseudo_dead_none) wip_mir_log.debug("{f}", .{self.fmtWipMir(result_index)});
12551230 return result_index;
12561231}
12571232
......@@ -2056,7 +2031,7 @@ fn gen(
20562031 .{},
20572032 );
20582033 self.ret_mcv.long = .{ .load_frame = .{ .index = frame_index } };
2059 tracking_log.debug("spill {} to {}", .{ self.ret_mcv.long, frame_index });
2034 tracking_log.debug("spill {f} to {f}", .{ self.ret_mcv.long, frame_index });
20602035 },
20612036 else => unreachable,
20622037 }
......@@ -2334,8 +2309,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
23342309
23352310 for (body) |inst| {
23362311 if (cg.liveness.isUnused(inst) and !cg.air.mustLower(inst, ip)) continue;
2337 wip_mir_log.debug("{}", .{cg.fmtAir(inst)});
2338 verbose_tracking_log.debug("{}", .{cg.fmtTracking()});
2312 wip_mir_log.debug("{f}", .{cg.fmtAir(inst)});
2313 verbose_tracking_log.debug("{f}", .{cg.fmtTracking()});
23392314
23402315 cg.reused_operands = .initEmpty();
23412316 try cg.inst_tracking.ensureUnusedCapacity(cg.gpa, 1);
......@@ -4339,7 +4314,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
43394314 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },
43404315 } },
43414316 } }) catch |err| switch (err) {
4342 error.SelectFailed => return cg.fail("failed to select {s} {} {} {}", .{
4317 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
43434318 @tagName(air_tag),
43444319 cg.typeOf(bin_op.lhs).fmt(pt),
43454320 ops[0].tracking(cg),
......@@ -4351,7 +4326,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
43514326 else => unreachable,
43524327 .add, .add_optimized => {},
43534328 .add_wrap => res[0].wrapInt(cg) catch |err| switch (err) {
4354 error.SelectFailed => return cg.fail("failed to select {s} wrap {} {}", .{
4329 error.SelectFailed => return cg.fail("failed to select {s} wrap {f} {f}", .{
43554330 @tagName(air_tag),
43564331 cg.typeOf(bin_op.lhs).fmt(pt),
43574332 res[0].tracking(cg),
......@@ -14947,7 +14922,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
1494714922 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },
1494814923 } },
1494914924 } }) catch |err| switch (err) {
14950 error.SelectFailed => return cg.fail("failed to select {s} {} {} {}", .{
14925 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
1495114926 @tagName(air_tag),
1495214927 cg.typeOf(bin_op.lhs).fmt(pt),
1495314928 ops[0].tracking(cg),
......@@ -14959,7 +14934,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
1495914934 else => unreachable,
1496014935 .sub, .sub_optimized => {},
1496114936 .sub_wrap => res[0].wrapInt(cg) catch |err| switch (err) {
14962 error.SelectFailed => return cg.fail("failed to select {s} wrap {} {}", .{
14937 error.SelectFailed => return cg.fail("failed to select {s} wrap {f} {f}", .{
1496314938 @tagName(air_tag),
1496414939 cg.typeOf(bin_op.lhs).fmt(pt),
1496514940 res[0].tracking(cg),
......@@ -24587,7 +24562,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
2458724562 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },
2458824563 } },
2458924564 } }) catch |err| switch (err) {
24590 error.SelectFailed => return cg.fail("failed to select {s} {} {} {}", .{
24565 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
2459124566 @tagName(air_tag),
2459224567 ty.fmt(pt),
2459324568 ops[0].tracking(cg),
......@@ -27287,7 +27262,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
2728727262 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },
2728827263 } },
2728927264 } }) catch |err| switch (err) {
27290 error.SelectFailed => return cg.fail("failed to select {s} {} {} {}", .{
27265 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
2729127266 @tagName(air_tag),
2729227267 ty.fmt(pt),
2729327268 ops[0].tracking(cg),
......@@ -27296,7 +27271,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
2729627271 else => |e| return e,
2729727272 };
2729827273 res[0].wrapInt(cg) catch |err| switch (err) {
27299 error.SelectFailed => return cg.fail("failed to select {s} wrap {} {}", .{
27274 error.SelectFailed => return cg.fail("failed to select {s} wrap {f} {f}", .{
2730027275 @tagName(air_tag),
2730127276 cg.typeOf(bin_op.lhs).fmt(pt),
2730227277 res[0].tracking(cg),
......@@ -33606,7 +33581,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
3360633581 assert(air_tag == .div_exact);
3360733582 res[0] = ops[0].divTruncInts(&ops[1], cg) catch |err| break :err err;
3360833583 }) catch |err| switch (err) {
33609 error.SelectFailed => return cg.fail("failed to select {s} {} {} {}", .{
33584 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
3361033585 @tagName(air_tag),
3361133586 ty.fmt(pt),
3361233587 ops[0].tracking(cg),
......@@ -34837,7 +34812,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
3483734812 } }) else err: {
3483834813 res[0] = ops[0].divTruncInts(&ops[1], cg) catch |err| break :err err;
3483934814 }) catch |err| switch (err) {
34840 error.SelectFailed => return cg.fail("failed to select {s} {} {} {}", .{
34815 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
3484134816 @tagName(air_tag),
3484234817 ty.fmt(pt),
3484334818 ops[0].tracking(cg),
......@@ -36148,7 +36123,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
3614836123 } },
3614936124 } },
3615036125 }) catch |err| switch (err) {
36151 error.SelectFailed => return cg.fail("failed to select {s} {} {} {}", .{
36126 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
3615236127 @tagName(air_tag),
3615336128 cg.typeOf(bin_op.lhs).fmt(pt),
3615436129 ops[0].tracking(cg),
......@@ -37614,7 +37589,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
3761437589 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },
3761537590 } },
3761637591 } })) catch |err| switch (err) {
37617 error.SelectFailed => return cg.fail("failed to select {s} {} {} {}", .{
37592 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
3761837593 @tagName(air_tag),
3761937594 ty.fmt(pt),
3762037595 ops[0].tracking(cg),
......@@ -39248,7 +39223,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
3924839223 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },
3924939224 } },
3925039225 } }) catch |err| switch (err) {
39251 error.SelectFailed => return cg.fail("failed to select {s} {} {} {}", .{
39226 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
3925239227 @tagName(air_tag),
3925339228 cg.typeOf(bin_op.lhs).fmt(pt),
3925439229 ops[0].tracking(cg),
......@@ -42077,7 +42052,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
4207742052 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },
4207842053 } },
4207942054 } }) catch |err| switch (err) {
42080 error.SelectFailed => return cg.fail("failed to select {s} {} {} {}", .{
42055 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
4208142056 @tagName(air_tag),
4208242057 cg.typeOf(bin_op.lhs).fmt(pt),
4208342058 ops[0].tracking(cg),
......@@ -42191,7 +42166,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
4219142166 .{ ._, ._, .lea, .dst0p, .leai(.src0, .dst0), ._, ._ },
4219242167 } },
4219342168 } }) catch |err| switch (err) {
42194 error.SelectFailed => return cg.fail("failed to select {s} {} {} {}", .{
42169 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
4219542170 @tagName(air_tag),
4219642171 cg.typeOf(bin_op.lhs).fmt(pt),
4219742172 ops[0].tracking(cg),
......@@ -42320,7 +42295,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
4232042295 .{ ._, ._, .lea, .dst0p, .leai(.src0, .dst0), ._, ._ },
4232142296 } },
4232242297 } }) catch |err| switch (err) {
42323 error.SelectFailed => return cg.fail("failed to select {s} {} {} {}", .{
42298 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
4232442299 @tagName(air_tag),
4232542300 cg.typeOf(bin_op.lhs).fmt(pt),
4232642301 ops[0].tracking(cg),
......@@ -46485,7 +46460,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
4648546460 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },
4648646461 } },
4648746462 } }) catch |err| switch (err) {
46488 error.SelectFailed => return cg.fail("failed to select {s} {} {} {}", .{
46463 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
4648946464 @tagName(air_tag),
4649046465 cg.typeOf(bin_op.lhs).fmt(pt),
4649146466 ops[0].tracking(cg),
......@@ -50644,7 +50619,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
5064450619 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },
5064550620 } },
5064650621 } }) catch |err| switch (err) {
50647 error.SelectFailed => return cg.fail("failed to select {s} {} {} {}", .{
50622 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
5064850623 @tagName(air_tag),
5064950624 cg.typeOf(bin_op.lhs).fmt(pt),
5065050625 ops[0].tracking(cg),
......@@ -51493,7 +51468,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
5149351468 .{ ._, ._, .mov, .memad(.dst0q, .add_src0_size, -8), .tmp0q, ._, ._ },
5149451469 } },
5149551470 } }) catch |err| switch (err) {
51496 error.SelectFailed => return cg.fail("failed to select {s} {} {} {}", .{
51471 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
5149751472 @tagName(air_tag),
5149851473 ty_pl.ty.toType().fmt(pt),
5149951474 ops[0].tracking(cg),
......@@ -52398,7 +52373,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
5239852373 .{ ._, ._, .mov, .memad(.dst0q, .add_src0_size, -8), .tmp0q, ._, ._ },
5239952374 } },
5240052375 } }) catch |err| switch (err) {
52401 error.SelectFailed => return cg.fail("failed to select {s} {} {} {}", .{
52376 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
5240252377 @tagName(air_tag),
5240352378 ty_pl.ty.toType().fmt(pt),
5240452379 ops[0].tracking(cg),
......@@ -55995,7 +55970,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
5599555970 .{ ._, ._, .@"or", .tmp2q, .tmp1q, ._, ._ },
5599655971 } },
5599755972 } }) catch |err| switch (err) {
55998 error.SelectFailed => return cg.fail("failed to select {s} {} {} {}", .{
55973 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
5599955974 @tagName(air_tag),
5600055975 ty_pl.ty.toType().fmt(pt),
5600155976 ops[0].tracking(cg),
......@@ -59735,7 +59710,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
5973559710 } },
5973659711 } },
5973759712 }) catch |err| switch (err) {
59738 error.SelectFailed => return cg.fail("failed to select {s} {} {} {}", .{
59713 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
5973959714 @tagName(air_tag),
5974059715 cg.typeOf(bin_op.lhs).fmt(pt),
5974159716 ops[0].tracking(cg),
......@@ -60298,7 +60273,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
6029860273 .{ ._, ._nz, .j, .@"0b", ._, ._, ._ },
6029960274 } },
6030060275 } }) catch |err| switch (err) {
60301 error.SelectFailed => return cg.fail("failed to select {s} {} {} {} {}", .{
60276 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f} {f}", .{
6030260277 @tagName(air_tag),
6030360278 cg.typeOf(bin_op.lhs).fmt(pt),
6030460279 cg.typeOf(bin_op.rhs).fmt(pt),
......@@ -60660,7 +60635,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
6066060635 .{ ._, ._ns, .j, .@"0b", ._, ._, ._ },
6066160636 } },
6066260637 } }) catch |err| switch (err) {
60663 error.SelectFailed => return cg.fail("failed to select {s} {} {} {} {}", .{
60638 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f} {f}", .{
6066460639 @tagName(air_tag),
6066560640 cg.typeOf(bin_op.lhs).fmt(pt),
6066660641 cg.typeOf(bin_op.rhs).fmt(pt),
......@@ -60672,7 +60647,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
6067260647 switch (air_tag) {
6067360648 else => unreachable,
6067460649 .shl => res[0].wrapInt(cg) catch |err| switch (err) {
60675 error.SelectFailed => return cg.fail("failed to select {s} wrap {} {}", .{
60650 error.SelectFailed => return cg.fail("failed to select {s} wrap {f} {f}", .{
6067660651 @tagName(air_tag),
6067760652 cg.typeOf(bin_op.lhs).fmt(pt),
6067860653 res[0].tracking(cg),
......@@ -65329,7 +65304,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
6532965304 .{ ._, ._b, .j, .@"0b", ._, ._, ._ },
6533065305 } },
6533165306 } }) catch |err| switch (err) {
65332 error.SelectFailed => return cg.fail("failed to select {s} {} {}", .{
65307 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
6533365308 @tagName(air_tag),
6533465309 ty_op.ty.toType().fmt(pt),
6533565310 ops[0].tracking(cg),
......@@ -68483,7 +68458,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
6848368458 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },
6848468459 } },
6848568460 } }) catch |err| switch (err) {
68486 error.SelectFailed => return cg.fail("failed to select {s} {} {}", .{
68461 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
6848768462 @tagName(air_tag),
6848868463 cg.typeOf(ty_op.operand).fmt(pt),
6848968464 ops[0].tracking(cg),
......@@ -68880,7 +68855,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
6888068855 .{ .@"0:", ._, .lea, .dst0d, .leasia(.dst0, .@"8", .tmp0, .add_8_src0_size), ._, ._ },
6888168856 } },
6888268857 } }) catch |err| switch (err) {
68883 error.SelectFailed => return cg.fail("failed to select {s} {} {}", .{
68858 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
6888468859 @tagName(air_tag),
6888568860 cg.typeOf(ty_op.operand).fmt(pt),
6888668861 ops[0].tracking(cg),
......@@ -69768,7 +69743,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
6976869743 .{ ._, ._ae, .j, .@"0b", ._, ._, ._ },
6976969744 } },
6977069745 } }) catch |err| switch (err) {
69771 error.SelectFailed => return cg.fail("failed to select {s} {} {}", .{
69746 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
6977269747 @tagName(air_tag),
6977369748 cg.typeOf(ty_op.operand).fmt(pt),
6977469749 ops[0].tracking(cg),
......@@ -70417,7 +70392,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
7041770392 .{ ._, ._ae, .j, .@"0b", ._, ._, ._ },
7041870393 } },
7041970394 } }) catch |err| switch (err) {
70420 error.SelectFailed => return cg.fail("failed to select {s} {} {}", .{
70395 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
7042170396 @tagName(air_tag),
7042270397 ty_op.ty.toType().fmt(pt),
7042370398 ops[0].tracking(cg),
......@@ -73519,7 +73494,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
7351973494 .{ ._, ._ae, .j, .@"0b", ._, ._, ._ },
7352073495 } },
7352173496 } }) catch |err| switch (err) {
73522 error.SelectFailed => return cg.fail("failed to select {s} {} {}", .{
73497 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
7352373498 @tagName(air_tag),
7352473499 ty_op.ty.toType().fmt(pt),
7352573500 ops[0].tracking(cg),
......@@ -74457,7 +74432,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
7445774432 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },
7445874433 } },
7445974434 } }) catch |err| switch (err) {
74460 error.SelectFailed => return cg.fail("failed to select {s} {} {}", .{
74435 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
7446174436 @tagName(air_tag),
7446274437 cg.typeOf(un_op).fmt(pt),
7446374438 ops[0].tracking(cg),
......@@ -75183,7 +75158,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
7518375158 } },
7518475159 } },
7518575160 }) catch |err| switch (err) {
75186 error.SelectFailed => return cg.fail("failed to select {s} {} {}", .{
75161 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
7518775162 @tagName(air_tag),
7518875163 cg.typeOf(un_op).fmt(pt),
7518975164 ops[0].tracking(cg),
......@@ -76734,7 +76709,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
7673476709 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },
7673576710 } },
7673676711 } }) catch |err| switch (err) {
76737 error.SelectFailed => return cg.fail("failed to select {s} {} {}", .{
76712 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
7673876713 @tagName(air_tag),
7673976714 cg.typeOf(ty_op.operand).fmt(pt),
7674076715 ops[0].tracking(cg),
......@@ -77926,7 +77901,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
7792677901 } },
7792777902 } },
7792877903 }) catch |err| switch (err) {
77929 error.SelectFailed => return cg.fail("failed to select {s} {} {}", .{
77904 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
7793077905 @tagName(air_tag),
7793177906 cg.typeOf(un_op).fmt(pt),
7793277907 ops[0].tracking(cg),
......@@ -78466,7 +78441,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
7846678441 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },
7846778442 } },
7846878443 } }) catch |err| switch (err) {
78469 error.SelectFailed => return cg.fail("failed to select {s} {} {}", .{
78444 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
7847078445 @tagName(air_tag),
7847178446 cg.typeOf(un_op).fmt(pt),
7847278447 ops[0].tracking(cg),
......@@ -78913,7 +78888,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
7891378888 } else err: {
7891478889 res[0] = ops[0].cmpInts(cmp_op, &ops[1], cg) catch |err| break :err err;
7891578890 }) catch |err| switch (err) {
78916 error.SelectFailed => return cg.fail("failed to select {s} {} {} {}", .{
78891 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
7891778892 @tagName(air_tag),
7891878893 cg.typeOf(bin_op.lhs).fmt(pt),
7891978894 ops[0].tracking(cg),
......@@ -79470,7 +79445,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
7947079445 res[0] = ops[0].cmpInts(cmp_op, &ops[1], cg) catch |err| break :err err;
7947179446 },
7947279447 }) catch |err| switch (err) {
79473 error.SelectFailed => return cg.fail("failed to select {s} {} {} {}", .{
79448 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
7947479449 @tagName(air_tag),
7947579450 ty.fmt(pt),
7947679451 ops[0].tracking(cg),
......@@ -88546,7 +88521,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
8854688521 .{ ._, ._ae, .j, .@"0b", ._, ._, ._ },
8854788522 } },
8854888523 } }) catch |err| switch (err) {
88549 error.SelectFailed => return cg.fail("failed to select {s} {} {} {}", .{
88524 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
8855088525 @tagName(air_tag),
8855188526 ty_op.ty.toType().fmt(pt),
8855288527 cg.typeOf(ty_op.operand).fmt(pt),
......@@ -90221,7 +90196,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
9022190196 .{ ._, ._ae, .j, .@"0b", ._, ._, ._ },
9022290197 } },
9022390198 } }) catch |err| switch (err) {
90224 error.SelectFailed => return cg.fail("failed to select {s} {} {} {}", .{
90199 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
9022590200 @tagName(air_tag),
9022690201 ty_op.ty.toType().fmt(pt),
9022790202 cg.typeOf(ty_op.operand).fmt(pt),
......@@ -94899,7 +94874,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
9489994874 .{ ._, ._nz, .j, .@"0b", ._, ._, ._ },
9490094875 } },
9490194876 } }) catch |err| switch (err) {
94902 error.SelectFailed => return cg.fail("failed to select {s} {} {} {}", .{
94877 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
9490394878 @tagName(air_tag),
9490494879 dst_ty.fmt(pt),
9490594880 src_ty.fmt(pt),
......@@ -100565,7 +100540,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
100565100540 .{ ._, ._nz, .j, .@"0b", ._, ._, ._ },
100566100541 } },
100567100542 } }) catch |err| switch (err) {
100568 error.SelectFailed => return cg.fail("failed to select {s} {} {} {}", .{
100543 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
100569100544 @tagName(air_tag),
100570100545 ty_op.ty.toType().fmt(pt),
100571100546 cg.typeOf(ty_op.operand).fmt(pt),
......@@ -111427,7 +111402,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
111427111402 .{ ._, ._ae, .j, .@"0b", ._, ._, ._ },
111428111403 } },
111429111404 } }) catch |err| switch (err) {
111430 error.SelectFailed => return cg.fail("failed to select {s} {} {} {}", .{
111405 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
111431111406 @tagName(air_tag),
111432111407 ty_op.ty.toType().fmt(pt),
111433111408 cg.typeOf(ty_op.operand).fmt(pt),
......@@ -123446,7 +123421,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
123446123421 .{ ._, ._ae, .j, .@"0b", ._, ._, ._ },
123447123422 } },
123448123423 } }) catch |err| switch (err) {
123449 error.SelectFailed => return cg.fail("failed to select {s} {} {} {}", .{
123424 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
123450123425 @tagName(air_tag),
123451123426 ty_op.ty.toType().fmt(pt),
123452123427 cg.typeOf(ty_op.operand).fmt(pt),
......@@ -166464,7 +166439,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
166464166439 .{ ._, ._, .@"test", .src0p, .src0p, ._, ._ },
166465166440 } },
166466166441 } }) catch |err| switch (err) {
166467 error.SelectFailed => return cg.fail("failed to select {s} {} {}", .{
166442 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
166468166443 @tagName(air_tag),
166469166444 cg.typeOf(un_op).fmt(pt),
166470166445 ops[0].tracking(cg),
......@@ -166552,7 +166527,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
166552166527 .{ ._, ._, .call, .tmp0d, ._, ._, ._ },
166553166528 } },
166554166529 } }) catch |err| switch (err) {
166555 error.SelectFailed => return cg.fail("failed to select {s} {} {}", .{
166530 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
166556166531 @tagName(air_tag),
166557166532 cg.typeOf(un_op).fmt(pt),
166558166533 ops[0].tracking(cg),
......@@ -166654,7 +166629,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
166654166629 .{ ._, ._, .lea, .dst1d, .leai(.dst1, .tmp1), ._, ._ },
166655166630 } },
166656166631 } }) catch |err| switch (err) {
166657 error.SelectFailed => return cg.fail("failed to select {s} {} {}", .{
166632 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
166658166633 @tagName(air_tag),
166659166634 cg.typeOf(un_op).fmt(pt),
166660166635 ops[0].tracking(cg),
......@@ -166752,7 +166727,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
166752166727 .{ ._, ._, .@"test", .src0d, .src0d, ._, ._ },
166753166728 } },
166754166729 } }) catch |err| switch (err) {
166755 error.SelectFailed => return cg.fail("failed to select {s} {} {}", .{
166730 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
166756166731 @tagName(air_tag),
166757166732 ty_op.ty.toType().fmt(pt),
166758166733 ops[0].tracking(cg),
......@@ -166804,7 +166779,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
166804166779 }
166805166780 }
166806166781 },
166807 .@"packed" => return cg.fail("failed to select {s} {}", .{
166782 .@"packed" => return cg.fail("failed to select {s} {f}", .{
166808166783 @tagName(air_tag),
166809166784 agg_ty.fmt(pt),
166810166785 }),
......@@ -166825,7 +166800,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
166825166800 elem_disp += @intCast(field_type.abiSize(zcu));
166826166801 }
166827166802 },
166828 else => return cg.fail("failed to select {s} {}", .{
166803 else => return cg.fail("failed to select {s} {f}", .{
166829166804 @tagName(air_tag),
166830166805 agg_ty.fmt(pt),
166831166806 }),
......@@ -168123,7 +168098,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
168123168098 .{ ._, ._ae, .j, .@"0b", ._, ._, ._ },
168124168099 } },
168125168100 } }) catch |err| switch (err) {
168126 error.SelectFailed => return cg.fail("failed to select {s} {} {} {} {}", .{
168101 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f} {f}", .{
168127168102 @tagName(air_tag),
168128168103 cg.typeOf(bin_op.lhs).fmt(pt),
168129168104 ops[0].tracking(cg),
......@@ -168223,7 +168198,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
168223168198 .{ ._, ._, .cmp, .src0d, .lea(.tmp1d), ._, ._ },
168224168199 } },
168225168200 } }) catch |err| switch (err) {
168226 error.SelectFailed => return cg.fail("failed to select {s} {}", .{
168201 error.SelectFailed => return cg.fail("failed to select {s} {f}", .{
168227168202 @tagName(air_tag),
168228168203 ops[0].tracking(cg),
168229168204 }),
......@@ -168242,12 +168217,12 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
168242168217 .ref => {
168243168218 const result = try cg.allocRegOrMem(err_ret_trace_index, true);
168244168219 try cg.genCopy(.usize, result, ops[0].tracking(cg).short, .{});
168245 tracking_log.debug("{} => {} (birth)", .{ err_ret_trace_index, result });
168220 tracking_log.debug("{f} => {f} (birth)", .{ err_ret_trace_index, result });
168246168221 cg.inst_tracking.putAssumeCapacityNoClobber(err_ret_trace_index, .init(result));
168247168222 },
168248168223 .temp => |temp_index| {
168249168224 const temp_tracking = temp_index.tracking(cg);
168250 tracking_log.debug("{} => {} (birth)", .{ err_ret_trace_index, temp_tracking.short });
168225 tracking_log.debug("{f} => {f} (birth)", .{ err_ret_trace_index, temp_tracking.short });
168251168226 cg.inst_tracking.putAssumeCapacityNoClobber(err_ret_trace_index, temp_tracking.*);
168252168227 assert(cg.reuseTemp(err_ret_trace_index, temp_index.toIndex(), temp_tracking));
168253168228 },
......@@ -168917,7 +168892,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
168917168892 try cg.resetTemps(@enumFromInt(0));
168918168893 cg.checkInvariantsAfterAirInst();
168919168894 }
168920 verbose_tracking_log.debug("{}", .{cg.fmtTracking()});
168895 verbose_tracking_log.debug("{f}", .{cg.fmtTracking()});
168921168896}
168922168897
168923168898fn genLazy(cg: *CodeGen, lazy_sym: link.File.LazySymbol) InnerError!void {
......@@ -168927,7 +168902,7 @@ fn genLazy(cg: *CodeGen, lazy_sym: link.File.LazySymbol) InnerError!void {
168927168902 switch (ip.indexToKey(lazy_sym.ty)) {
168928168903 .enum_type => {
168929168904 const enum_ty: Type = .fromInterned(lazy_sym.ty);
168930 wip_mir_log.debug("{}.@tagName:", .{enum_ty.fmt(pt)});
168905 wip_mir_log.debug("{f}.@tagName:", .{enum_ty.fmt(pt)});
168931168906
168932168907 const param_regs = abi.getCAbiIntParamRegs(.auto);
168933168908 const param_locks = cg.register_manager.lockRegsAssumeUnused(2, param_regs[0..2].*);
......@@ -168976,7 +168951,7 @@ fn genLazy(cg: *CodeGen, lazy_sym: link.File.LazySymbol) InnerError!void {
168976168951 },
168977168952 .error_set_type => |error_set_type| {
168978168953 const err_ty: Type = .fromInterned(lazy_sym.ty);
168979 wip_mir_log.debug("{}.@errorCast:", .{err_ty.fmt(pt)});
168954 wip_mir_log.debug("{f}.@errorCast:", .{err_ty.fmt(pt)});
168980168955
168981168956 const param_regs = abi.getCAbiIntParamRegs(.auto);
168982168957 const param_locks = cg.register_manager.lockRegsAssumeUnused(2, param_regs[0..2].*);
......@@ -169016,7 +168991,7 @@ fn genLazy(cg: *CodeGen, lazy_sym: link.File.LazySymbol) InnerError!void {
169016168991 try cg.asmOpOnly(.{ ._, .ret });
169017168992 },
169018168993 else => return cg.fail(
169019 "TODO implement {s} for {}",
168994 "TODO implement {s} for {f}",
169020168995 .{ @tagName(lazy_sym.kind), Type.fromInterned(lazy_sym.ty).fmt(pt) },
169021168996 ),
169022168997 }
......@@ -169076,7 +169051,7 @@ fn finishAirResult(self: *CodeGen, inst: Air.Inst.Index, result: MCValue) void {
169076169051 .none, .dead, .unreach => {},
169077169052 else => unreachable, // Why didn't the result die?
169078169053 } else {
169079 tracking_log.debug("{} => {} (birth)", .{ inst, result });
169054 tracking_log.debug("{f} => {f} (birth)", .{ inst, result });
169080169055 self.inst_tracking.putAssumeCapacityNoClobber(inst, .init(result));
169081169056 // In some cases, an operand may be reused as the result.
169082169057 // If that operand died and was a register, it was freed by
......@@ -169226,7 +169201,7 @@ fn allocMemPtr(self: *CodeGen, inst: Air.Inst.Index) !FrameIndex {
169226169201 const val_ty = ptr_ty.childType(zcu);
169227169202 return self.allocFrameIndex(.init(.{
169228169203 .size = std.math.cast(u32, val_ty.abiSize(zcu)) orelse {
169229 return self.fail("type '{}' too big to fit into stack frame", .{val_ty.fmt(pt)});
169204 return self.fail("type '{f}' too big to fit into stack frame", .{val_ty.fmt(pt)});
169230169205 },
169231169206 .alignment = ptr_ty.ptrAlignment(zcu).max(.@"1"),
169232169207 }));
......@@ -169244,7 +169219,7 @@ fn allocRegOrMemAdvanced(self: *CodeGen, ty: Type, inst: ?Air.Inst.Index, reg_ok
169244169219 const pt = self.pt;
169245169220 const zcu = pt.zcu;
169246169221 const abi_size = std.math.cast(u32, ty.abiSize(zcu)) orelse {
169247 return self.fail("type '{}' too big to fit into stack frame", .{ty.fmt(pt)});
169222 return self.fail("type '{f}' too big to fit into stack frame", .{ty.fmt(pt)});
169248169223 };
169249169224
169250169225 if (reg_ok) need_mem: {
......@@ -169749,7 +169724,7 @@ fn airFpext(self: *CodeGen, inst: Air.Inst.Index) !void {
169749169724 );
169750169725 }
169751169726 break :result dst_mcv;
169752 } orelse return self.fail("TODO implement airFpext from {} to {}", .{
169727 } orelse return self.fail("TODO implement airFpext from {f} to {f}", .{
169753169728 src_ty.fmt(pt), dst_ty.fmt(pt),
169754169729 });
169755169730 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
......@@ -170004,7 +169979,7 @@ fn airIntCast(self: *CodeGen, inst: Air.Inst.Index) !void {
170004169979 );
170005169980
170006169981 break :result dst_mcv;
170007 }) orelse return self.fail("TODO implement airIntCast from {} to {}", .{
169982 }) orelse return self.fail("TODO implement airIntCast from {f} to {f}", .{
170008169983 src_ty.fmt(pt), dst_ty.fmt(pt),
170009169984 });
170010169985 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
......@@ -170076,7 +170051,7 @@ fn airTrunc(self: *CodeGen, inst: Air.Inst.Index) !void {
170076170051 else => null,
170077170052 },
170078170053 else => null,
170079 }) orelse return self.fail("TODO implement airTrunc for {}", .{dst_ty.fmt(pt)});
170054 }) orelse return self.fail("TODO implement airTrunc for {f}", .{dst_ty.fmt(pt)});
170080170055
170081170056 const dst_info = dst_elem_ty.intInfo(zcu);
170082170057 const src_info = src_elem_ty.intInfo(zcu);
......@@ -170497,7 +170472,7 @@ fn airAddSat(self: *CodeGen, inst: Air.Inst.Index) !void {
170497170472 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
170498170473 const ty = self.typeOf(bin_op.lhs);
170499170474 if (ty.zigTypeTag(zcu) == .vector or ty.abiSize(zcu) > 8) return self.fail(
170500 "TODO implement airAddSat for {}",
170475 "TODO implement airAddSat for {f}",
170501170476 .{ty.fmt(pt)},
170502170477 );
170503170478
......@@ -170575,7 +170550,7 @@ fn airSubSat(self: *CodeGen, inst: Air.Inst.Index) !void {
170575170550 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
170576170551 const ty = self.typeOf(bin_op.lhs);
170577170552 if (ty.zigTypeTag(zcu) == .vector or ty.abiSize(zcu) > 8) return self.fail(
170578 "TODO implement airSubSat for {}",
170553 "TODO implement airSubSat for {f}",
170579170554 .{ty.fmt(pt)},
170580170555 );
170581170556
......@@ -170726,7 +170701,7 @@ fn airMulSat(self: *CodeGen, inst: Air.Inst.Index) !void {
170726170701 }
170727170702
170728170703 if (ty.zigTypeTag(zcu) == .vector or ty.abiSize(zcu) > 8) return self.fail(
170729 "TODO implement airMulSat for {}",
170704 "TODO implement airMulSat for {f}",
170730170705 .{ty.fmt(pt)},
170731170706 );
170732170707
......@@ -171020,7 +170995,7 @@ fn airMulWithOverflow(self: *CodeGen, inst: Air.Inst.Index) !void {
171020170995 const tuple_ty = self.typeOfIndex(inst);
171021170996 const dst_ty = self.typeOf(bin_op.lhs);
171022170997 const result: MCValue = switch (dst_ty.zigTypeTag(zcu)) {
171023 .vector => return self.fail("TODO implement airMulWithOverflow for {}", .{dst_ty.fmt(pt)}),
170998 .vector => return self.fail("TODO implement airMulWithOverflow for {f}", .{dst_ty.fmt(pt)}),
171024170999 .int => result: {
171025171000 const dst_info = dst_ty.intInfo(zcu);
171026171001 if (dst_info.bits > 128 and dst_info.signedness == .unsigned) {
......@@ -171373,7 +171348,7 @@ fn airMulWithOverflow(self: *CodeGen, inst: Air.Inst.Index) !void {
171373171348 else => {
171374171349 // For now, this is the only supported multiply that doesn't fit in a register.
171375171350 if (dst_info.bits > 128 or src_bits != 64)
171376 return self.fail("TODO implement airWithOverflow from {} to {}", .{
171351 return self.fail("TODO implement airWithOverflow from {f} to {f}", .{
171377171352 src_ty.fmt(pt), dst_ty.fmt(pt),
171378171353 });
171379171354
......@@ -171774,7 +171749,7 @@ fn airShlShrBinOp(self: *CodeGen, inst: Air.Inst.Index) !void {
171774171749 },
171775171750 else => {},
171776171751 }
171777 return self.fail("TODO implement airShlShrBinOp for {}", .{lhs_ty.fmt(pt)});
171752 return self.fail("TODO implement airShlShrBinOp for {f}", .{lhs_ty.fmt(pt)});
171778171753 };
171779171754 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
171780171755}
......@@ -172034,7 +172009,7 @@ fn airUnwrapErrUnionErr(self: *CodeGen, inst: Air.Inst.Index) !void {
172034172009 .index = frame_addr.index,
172035172010 .off = frame_addr.off + @as(i32, @intCast(err_off)),
172036172011 } },
172037 else => return self.fail("TODO implement unwrap_err_err for {}", .{operand}),
172012 else => return self.fail("TODO implement unwrap_err_err for {f}", .{operand}),
172038172013 }
172039172014 };
172040172015 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
......@@ -172196,7 +172171,7 @@ fn genUnwrapErrUnionPayloadMir(
172196172171 else
172197172172 .{ .register = try self.copyToTmpRegister(payload_ty, result_mcv) };
172198172173 },
172199 else => return self.fail("TODO implement genUnwrapErrUnionPayloadMir for {}", .{err_union}),
172174 else => return self.fail("TODO implement genUnwrapErrUnionPayloadMir for {f}", .{err_union}),
172200172175 }
172201172176 };
172202172177
......@@ -172362,7 +172337,7 @@ fn airSliceLen(self: *CodeGen, inst: Air.Inst.Index) !void {
172362172337 .index = frame_addr.index,
172363172338 .off = frame_addr.off + 8,
172364172339 } },
172365 else => return self.fail("TODO implement slice_len for {}", .{src_mcv}),
172340 else => return self.fail("TODO implement slice_len for {f}", .{src_mcv}),
172366172341 };
172367172342 if (self.reuseOperand(inst, ty_op.operand, 0, src_mcv)) {
172368172343 switch (src_mcv) {
......@@ -172645,7 +172620,7 @@ fn airArrayElemVal(self: *CodeGen, inst: Air.Inst.Index) !void {
172645172620 }.to64(),
172646172621 ),
172647172622 },
172648 else => return self.fail("TODO airArrayElemVal for {s} of {}", .{
172623 else => return self.fail("TODO airArrayElemVal for {s} of {f}", .{
172649172624 @tagName(array_mat_mcv), array_ty.fmt(pt),
172650172625 }),
172651172626 }
......@@ -172688,7 +172663,7 @@ fn airArrayElemVal(self: *CodeGen, inst: Air.Inst.Index) !void {
172688172663 .load_extern_func,
172689172664 .lea_extern_func,
172690172665 => try self.genSetReg(addr_reg, .usize, array_mcv.address(), .{}),
172691 else => return self.fail("TODO airArrayElemVal_val for {s} of {}", .{
172666 else => return self.fail("TODO airArrayElemVal_val for {s} of {f}", .{
172692172667 @tagName(array_mcv), array_ty.fmt(pt),
172693172668 }),
172694172669 }
......@@ -172881,7 +172856,7 @@ fn airGetUnionTag(self: *CodeGen, inst: Air.Inst.Index) !void {
172881172856 }
172882172857
172883172858 return self.fail(
172884 "TODO implement get_union_tag for ABI larger than 8 bytes and operand {}",
172859 "TODO implement get_union_tag for ABI larger than 8 bytes and operand {f}",
172885172860 .{operand},
172886172861 );
172887172862 },
......@@ -172893,7 +172868,7 @@ fn airGetUnionTag(self: *CodeGen, inst: Air.Inst.Index) !void {
172893172868 .register = registerAlias(result.register, @intCast(layout.tag_size)),
172894172869 };
172895172870 },
172896 else => return self.fail("TODO implement get_union_tag for {}", .{operand}),
172871 else => return self.fail("TODO implement get_union_tag for {f}", .{operand}),
172897172872 }
172898172873 };
172899172874
......@@ -172909,7 +172884,7 @@ fn airClz(self: *CodeGen, inst: Air.Inst.Index) !void {
172909172884
172910172885 const dst_ty = self.typeOfIndex(inst);
172911172886 const src_ty = self.typeOf(ty_op.operand);
172912 if (src_ty.zigTypeTag(zcu) == .vector) return self.fail("TODO implement airClz for {}", .{
172887 if (src_ty.zigTypeTag(zcu) == .vector) return self.fail("TODO implement airClz for {f}", .{
172913172888 src_ty.fmt(pt),
172914172889 });
172915172890
......@@ -173105,7 +173080,7 @@ fn airCtz(self: *CodeGen, inst: Air.Inst.Index) !void {
173105173080
173106173081 const dst_ty = self.typeOfIndex(inst);
173107173082 const src_ty = self.typeOf(ty_op.operand);
173108 if (src_ty.zigTypeTag(zcu) == .vector) return self.fail("TODO implement airCtz for {}", .{
173083 if (src_ty.zigTypeTag(zcu) == .vector) return self.fail("TODO implement airCtz for {f}", .{
173109173084 src_ty.fmt(pt),
173110173085 });
173111173086
......@@ -173277,7 +173252,7 @@ fn airPopCount(self: *CodeGen, inst: Air.Inst.Index) !void {
173277173252 const src_ty = self.typeOf(ty_op.operand);
173278173253 const src_abi_size: u32 = @intCast(src_ty.abiSize(zcu));
173279173254 if (src_ty.zigTypeTag(zcu) == .vector or src_abi_size > 16)
173280 return self.fail("TODO implement airPopCount for {}", .{src_ty.fmt(pt)});
173255 return self.fail("TODO implement airPopCount for {f}", .{src_ty.fmt(pt)});
173281173256 const src_mcv = try self.resolveInst(ty_op.operand);
173282173257
173283173258 const mat_src_mcv = switch (src_mcv) {
......@@ -173430,7 +173405,7 @@ fn genByteSwap(
173430173405 const has_movbe = self.hasFeature(.movbe);
173431173406
173432173407 if (src_ty.zigTypeTag(zcu) == .vector) return self.fail(
173433 "TODO implement genByteSwap for {}",
173408 "TODO implement genByteSwap for {f}",
173434173409 .{src_ty.fmt(pt)},
173435173410 );
173436173411
......@@ -173739,7 +173714,7 @@ fn floatSign(self: *CodeGen, inst: Air.Inst.Index, tag: Air.Inst.Tag, operand: A
173739173714 const result = result: {
173740173715 const scalar_bits = ty.scalarType(zcu).floatBits(self.target);
173741173716 if (scalar_bits == 80) {
173742 if (ty.zigTypeTag(zcu) != .float) return self.fail("TODO implement floatSign for {}", .{
173717 if (ty.zigTypeTag(zcu) != .float) return self.fail("TODO implement floatSign for {f}", .{
173743173718 ty.fmt(pt),
173744173719 });
173745173720
......@@ -173763,7 +173738,7 @@ fn floatSign(self: *CodeGen, inst: Air.Inst.Index, tag: Air.Inst.Tag, operand: A
173763173738 const abi_size: u32 = switch (ty.abiSize(zcu)) {
173764173739 1...16 => 16,
173765173740 17...32 => 32,
173766 else => return self.fail("TODO implement floatSign for {}", .{
173741 else => return self.fail("TODO implement floatSign for {f}", .{
173767173742 ty.fmt(pt),
173768173743 }),
173769173744 };
......@@ -173822,7 +173797,7 @@ fn floatSign(self: *CodeGen, inst: Air.Inst.Index, tag: Air.Inst.Tag, operand: A
173822173797 .abs => .{ .v_pd, .@"and" },
173823173798 else => unreachable,
173824173799 },
173825 80 => return self.fail("TODO implement floatSign for {}", .{ty.fmt(pt)}),
173800 80 => return self.fail("TODO implement floatSign for {f}", .{ty.fmt(pt)}),
173826173801 else => unreachable,
173827173802 },
173828173803 registerAlias(dst_reg, abi_size),
......@@ -173848,7 +173823,7 @@ fn floatSign(self: *CodeGen, inst: Air.Inst.Index, tag: Air.Inst.Tag, operand: A
173848173823 .abs => .{ ._pd, .@"and" },
173849173824 else => unreachable,
173850173825 },
173851 80 => return self.fail("TODO implement floatSign for {}", .{ty.fmt(pt)}),
173826 80 => return self.fail("TODO implement floatSign for {f}", .{ty.fmt(pt)}),
173852173827 else => unreachable,
173853173828 },
173854173829 registerAlias(dst_reg, abi_size),
......@@ -173928,7 +173903,7 @@ fn genRoundLibcall(self: *CodeGen, ty: Type, src_mcv: MCValue, mode: bits.RoundM
173928173903 if (self.getRoundTag(ty)) |_| return .none;
173929173904
173930173905 if (ty.zigTypeTag(zcu) != .float)
173931 return self.fail("TODO implement genRound for {}", .{ty.fmt(pt)});
173906 return self.fail("TODO implement genRound for {f}", .{ty.fmt(pt)});
173932173907
173933173908 var sym_buf: ["__trunc?".len]u8 = undefined;
173934173909 return try self.genCall(.{ .extern_func = .{
......@@ -174164,7 +174139,7 @@ fn airAbs(self: *CodeGen, inst: Air.Inst.Index) !void {
174164174139 },
174165174140 .float => return self.floatSign(inst, .abs, ty_op.operand, ty),
174166174141 },
174167 }) orelse return self.fail("TODO implement airAbs for {}", .{ty.fmt(pt)});
174142 }) orelse return self.fail("TODO implement airAbs for {f}", .{ty.fmt(pt)});
174168174143
174169174144 const abi_size: u32 = @intCast(ty.abiSize(zcu));
174170174145 const src_mcv = try self.resolveInst(ty_op.operand);
......@@ -174323,7 +174298,7 @@ fn airSqrt(self: *CodeGen, inst: Air.Inst.Index) !void {
174323174298 else => unreachable,
174324174299 },
174325174300 else => unreachable,
174326 }) orelse return self.fail("TODO implement airSqrt for {}", .{ty.fmt(pt)});
174301 }) orelse return self.fail("TODO implement airSqrt for {f}", .{ty.fmt(pt)});
174327174302 switch (mir_tag[0]) {
174328174303 .v_ss, .v_sd => if (src_mcv.isBase()) try self.asmRegisterRegisterMemory(
174329174304 mir_tag,
......@@ -174481,7 +174456,7 @@ fn packedLoad(self: *CodeGen, dst_mcv: MCValue, ptr_ty: Type, ptr_mcv: MCValue)
174481174456 return;
174482174457 }
174483174458
174484 if (val_abi_size > 8) return self.fail("TODO implement packed load of {}", .{val_ty.fmt(pt)});
174459 if (val_abi_size > 8) return self.fail("TODO implement packed load of {f}", .{val_ty.fmt(pt)});
174485174460
174486174461 const limb_abi_size: u31 = @min(val_abi_size, 8);
174487174462 const limb_abi_bits = limb_abi_size * 8;
......@@ -174753,7 +174728,7 @@ fn packedStore(self: *CodeGen, ptr_ty: Type, ptr_mcv: MCValue, src_mcv: MCValue)
174753174728 limb_mem,
174754174729 registerAlias(tmp_reg, limb_abi_size),
174755174730 );
174756 } else return self.fail("TODO: implement packed store of {}", .{src_ty.fmt(pt)});
174731 } else return self.fail("TODO: implement packed store of {f}", .{src_ty.fmt(pt)});
174757174732 }
174758174733}
174759174734
......@@ -174856,7 +174831,7 @@ fn genUnOp(self: *CodeGen, maybe_inst: ?Air.Inst.Index, tag: Air.Inst.Tag, src_a
174856174831 const zcu = pt.zcu;
174857174832 const src_ty = self.typeOf(src_air);
174858174833 if (src_ty.zigTypeTag(zcu) == .vector)
174859 return self.fail("TODO implement genUnOp for {}", .{src_ty.fmt(pt)});
174834 return self.fail("TODO implement genUnOp for {f}", .{src_ty.fmt(pt)});
174860174835
174861174836 var src_mcv = try self.resolveInst(src_air);
174862174837 switch (src_mcv) {
......@@ -174943,7 +174918,7 @@ fn genUnOp(self: *CodeGen, maybe_inst: ?Air.Inst.Index, tag: Air.Inst.Tag, src_a
174943174918fn genUnOpMir(self: *CodeGen, mir_tag: Mir.Inst.FixedTag, dst_ty: Type, dst_mcv: MCValue) !void {
174944174919 const pt = self.pt;
174945174920 const abi_size: u32 = @intCast(dst_ty.abiSize(pt.zcu));
174946 if (abi_size > 8) return self.fail("TODO implement {} for {}", .{ mir_tag, dst_ty.fmt(pt) });
174921 if (abi_size > 8) return self.fail("TODO implement {} for {f}", .{ mir_tag, dst_ty.fmt(pt) });
174947174922 switch (dst_mcv) {
174948174923 .none,
174949174924 .unreach,
......@@ -175672,7 +175647,7 @@ fn genBinOp(
175672175647 },
175673175648 floatLibcAbiSuffix(lhs_ty),
175674175649 }),
175675 else => return self.fail("TODO implement genBinOp for {s} {}", .{
175650 else => return self.fail("TODO implement genBinOp for {s} {f}", .{
175676175651 @tagName(air_tag), lhs_ty.fmt(pt),
175677175652 }),
175678175653 } catch unreachable;
......@@ -175785,7 +175760,7 @@ fn genBinOp(
175785175760 );
175786175761 break :adjusted .{ .register = dst_reg };
175787175762 },
175788 80, 128 => return self.fail("TODO implement genBinOp for {s} of {}", .{
175763 80, 128 => return self.fail("TODO implement genBinOp for {s} of {f}", .{
175789175764 @tagName(air_tag), lhs_ty.fmt(pt),
175790175765 }),
175791175766 else => unreachable,
......@@ -175819,7 +175794,7 @@ fn genBinOp(
175819175794 if (sse_op and ((lhs_ty.scalarType(zcu).isRuntimeFloat() and
175820175795 lhs_ty.scalarType(zcu).floatBits(self.target) == 80) or
175821175796 lhs_ty.abiSize(zcu) > self.vectorSize(.float)))
175822 return self.fail("TODO implement genBinOp for {s} {}", .{ @tagName(air_tag), lhs_ty.fmt(pt) });
175797 return self.fail("TODO implement genBinOp for {s} {f}", .{ @tagName(air_tag), lhs_ty.fmt(pt) });
175823175798
175824175799 const maybe_mask_reg = switch (air_tag) {
175825175800 else => null,
......@@ -176199,7 +176174,7 @@ fn genBinOp(
176199176174 }
176200176175 },
176201176176
176202 else => return self.fail("TODO implement genBinOp for {s} {}", .{
176177 else => return self.fail("TODO implement genBinOp for {s} {f}", .{
176203176178 @tagName(air_tag), lhs_ty.fmt(pt),
176204176179 }),
176205176180 }
......@@ -176953,7 +176928,7 @@ fn genBinOp(
176953176928 else => unreachable,
176954176929 },
176955176930 },
176956 }) orelse return self.fail("TODO implement genBinOp for {s} {}", .{
176931 }) orelse return self.fail("TODO implement genBinOp for {s} {f}", .{
176957176932 @tagName(air_tag), lhs_ty.fmt(pt),
176958176933 });
176959176934
......@@ -177086,7 +177061,7 @@ fn genBinOp(
177086177061 else => unreachable,
177087177062 },
177088177063 else => unreachable,
177089 }) orelse return self.fail("TODO implement genBinOp for {s} {}", .{
177064 }) orelse return self.fail("TODO implement genBinOp for {s} {f}", .{
177090177065 @tagName(air_tag), lhs_ty.fmt(pt),
177091177066 }),
177092177067 mask_reg,
......@@ -177118,7 +177093,7 @@ fn genBinOp(
177118177093 else => unreachable,
177119177094 },
177120177095 else => unreachable,
177121 }) orelse return self.fail("TODO implement genBinOp for {s} {}", .{
177096 }) orelse return self.fail("TODO implement genBinOp for {s} {f}", .{
177122177097 @tagName(air_tag), lhs_ty.fmt(pt),
177123177098 }),
177124177099 dst_reg,
......@@ -177154,7 +177129,7 @@ fn genBinOp(
177154177129 else => unreachable,
177155177130 },
177156177131 else => unreachable,
177157 }) orelse return self.fail("TODO implement genBinOp for {s} {}", .{
177132 }) orelse return self.fail("TODO implement genBinOp for {s} {f}", .{
177158177133 @tagName(air_tag), lhs_ty.fmt(pt),
177159177134 }),
177160177135 mask_reg,
......@@ -177185,7 +177160,7 @@ fn genBinOp(
177185177160 else => unreachable,
177186177161 },
177187177162 else => unreachable,
177188 }) orelse return self.fail("TODO implement genBinOp for {s} {}", .{
177163 }) orelse return self.fail("TODO implement genBinOp for {s} {f}", .{
177189177164 @tagName(air_tag), lhs_ty.fmt(pt),
177190177165 }),
177191177166 dst_reg,
......@@ -177215,7 +177190,7 @@ fn genBinOp(
177215177190 else => unreachable,
177216177191 },
177217177192 else => unreachable,
177218 }) orelse return self.fail("TODO implement genBinOp for {s} {}", .{
177193 }) orelse return self.fail("TODO implement genBinOp for {s} {f}", .{
177219177194 @tagName(air_tag), lhs_ty.fmt(pt),
177220177195 });
177221177196 try self.asmRegisterRegister(.{ mir_fixes, .@"and" }, dst_reg, mask_reg);
......@@ -178022,7 +177997,7 @@ fn airArg(self: *CodeGen, inst: Air.Inst.Index) !void {
178022177997
178023177998 break :result dst_mcv;
178024177999 },
178025 else => return self.fail("TODO implement arg for {}", .{src_mcv}),
178000 else => return self.fail("TODO implement arg for {f}", .{src_mcv}),
178026178001 }
178027178002 };
178028178003 return self.finishAir(inst, result, .{ .none, .none, .none });
......@@ -179079,7 +179054,7 @@ fn genCondBrMir(self: *CodeGen, ty: Type, mcv: MCValue) !Mir.Inst.Index {
179079179054 const reg = try self.copyToTmpRegister(ty, mcv);
179080179055 return self.genCondBrMir(ty, .{ .register = reg });
179081179056 }
179082 return self.fail("TODO implement condbr when condition is {} with abi larger than 8 bytes", .{mcv});
179057 return self.fail("TODO implement condbr when condition is {f} with abi larger than 8 bytes", .{mcv});
179083179058 },
179084179059 else => return self.fail("TODO implement condbr when condition is {s}", .{@tagName(mcv)}),
179085179060 }
......@@ -179166,7 +179141,7 @@ fn isErr(self: *CodeGen, maybe_inst: ?Air.Inst.Index, eu_ty: Type, eu_mcv: MCVal
179166179141 } },
179167179142 .{ .immediate = 0 },
179168179143 ),
179169 else => return self.fail("TODO implement isErr for {}", .{eu_mcv}),
179144 else => return self.fail("TODO implement isErr for {f}", .{eu_mcv}),
179170179145 }
179171179146
179172179147 if (maybe_inst) |inst| self.eflags_inst = inst;
......@@ -180916,7 +180891,7 @@ fn moveStrategy(cg: *CodeGen, ty: Type, class: Register.Class, aligned: bool) !M
180916180891 },
180917180892 .ip, .cr, .dr => {},
180918180893 }
180919 return cg.fail("TODO moveStrategy for {}", .{ty.fmt(pt)});
180894 return cg.fail("TODO moveStrategy for {f}", .{ty.fmt(pt)});
180920180895}
180921180896
180922180897const CopyOptions = struct {
......@@ -181048,7 +181023,7 @@ fn genCopy(self: *CodeGen, ty: Type, dst_mcv: MCValue, src_mcv: MCValue, opts: C
181048181023 break :src_info .{ .addr_reg = src_addr_reg, .addr_lock = src_addr_lock };
181049181024 },
181050181025 .air_ref => |src_ref| return self.genCopy(ty, dst_mcv, try self.resolveInst(src_ref), opts),
181051 else => return self.fail("TODO implement genCopy for {s} of {}", .{
181026 else => return self.fail("TODO implement genCopy for {s} of {f}", .{
181052181027 @tagName(src_mcv), ty.fmt(pt),
181053181028 }),
181054181029 };
......@@ -181424,7 +181399,7 @@ fn genSetReg(
181424181399 80 => null,
181425181400 else => unreachable,
181426181401 },
181427 }) orelse return self.fail("TODO implement genSetReg for {}", .{ty.fmt(pt)}),
181402 }) orelse return self.fail("TODO implement genSetReg for {f}", .{ty.fmt(pt)}),
181428181403 dst_alias,
181429181404 registerAlias(src_reg, abi_size),
181430181405 ),
......@@ -181854,7 +181829,7 @@ fn genSetMem(
181854181829 opts,
181855181830 );
181856181831 },
181857 else => return self.fail("TODO implement genSetMem for {s} of {}", .{
181832 else => return self.fail("TODO implement genSetMem for {s} of {f}", .{
181858181833 @tagName(src_mcv), ty.fmt(pt),
181859181834 }),
181860181835 },
......@@ -182167,7 +182142,7 @@ fn airFloatFromInt(self: *CodeGen, inst: Air.Inst.Index) !void {
182167182142 32, 64 => src_size > 8,
182168182143 else => unreachable,
182169182144 }) {
182170 if (src_bits > 128) return self.fail("TODO implement airFloatFromInt from {} to {}", .{
182145 if (src_bits > 128) return self.fail("TODO implement airFloatFromInt from {f} to {f}", .{
182171182146 src_ty.fmt(pt), dst_ty.fmt(pt),
182172182147 });
182173182148
......@@ -182209,7 +182184,7 @@ fn airFloatFromInt(self: *CodeGen, inst: Air.Inst.Index) !void {
182209182184 else => unreachable,
182210182185 },
182211182186 else => null,
182212 }) orelse return self.fail("TODO implement airFloatFromInt from {} to {}", .{
182187 }) orelse return self.fail("TODO implement airFloatFromInt from {f} to {f}", .{
182213182188 src_ty.fmt(pt), dst_ty.fmt(pt),
182214182189 });
182215182190 const dst_alias = dst_reg.to128();
......@@ -182247,7 +182222,7 @@ fn airIntFromFloat(self: *CodeGen, inst: Air.Inst.Index) !void {
182247182222 32, 64 => dst_size > 8,
182248182223 else => unreachable,
182249182224 }) {
182250 if (dst_bits > 128) return self.fail("TODO implement airIntFromFloat from {} to {}", .{
182225 if (dst_bits > 128) return self.fail("TODO implement airIntFromFloat from {f} to {f}", .{
182251182226 src_ty.fmt(pt), dst_ty.fmt(pt),
182252182227 });
182253182228
......@@ -182531,7 +182506,7 @@ fn atomicOp(
182531182506 else => null,
182532182507 },
182533182508 else => unreachable,
182534 }) orelse return self.fail("TODO implement atomicOp of {s} for {}", .{
182509 }) orelse return self.fail("TODO implement atomicOp of {s} for {f}", .{
182535182510 @tagName(op), val_ty.fmt(pt),
182536182511 });
182537182512 try self.genSetReg(sse_reg, val_ty, .{ .register = .rax }, .{});
......@@ -183286,7 +183261,7 @@ fn airSplat(self: *CodeGen, inst: Air.Inst.Index) !void {
183286183261 else => unreachable,
183287183262 },
183288183263 }
183289 return self.fail("TODO implement airSplat for {}", .{vector_ty.fmt(pt)});
183264 return self.fail("TODO implement airSplat for {f}", .{vector_ty.fmt(pt)});
183290183265 };
183291183266 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
183292183267}
......@@ -183322,12 +183297,12 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void {
183322183297 else
183323183298 try self.copyToTmpRegister(pred_ty, pred_mcv)
183324183299 else
183325 return self.fail("TODO implement airSelect for {}", .{ty.fmt(pt)}),
183300 return self.fail("TODO implement airSelect for {f}", .{ty.fmt(pt)}),
183326183301 else => unreachable,
183327183302 },
183328183303 .register_mask => |pred_reg_mask| {
183329183304 if (pred_reg_mask.info.scalar.bitSize(self.target) != 8 * elem_abi_size)
183330 return self.fail("TODO implement airSelect for {}", .{ty.fmt(pt)});
183305 return self.fail("TODO implement airSelect for {f}", .{ty.fmt(pt)});
183331183306
183332183307 const mask_reg: Register = if (need_xmm0 and pred_reg_mask.reg.id() != comptime Register.xmm0.id()) mask_reg: {
183333183308 try self.register_manager.getKnownReg(.xmm0, null);
......@@ -183401,7 +183376,7 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void {
183401183376 else
183402183377 null
183403183378 else
183404 null) orelse return self.fail("TODO implement airSelect for {}", .{ty.fmt(pt)});
183379 null) orelse return self.fail("TODO implement airSelect for {f}", .{ty.fmt(pt)});
183405183380 if (has_avx) {
183406183381 const rhs_alias = if (reuse_mcv.isRegister())
183407183382 registerAlias(reuse_mcv.getReg().?, abi_size)
......@@ -183554,7 +183529,7 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void {
183554183529 else => unreachable,
183555183530 }),
183556183531 );
183557 } else return self.fail("TODO implement airSelect for {}", .{ty.fmt(pt)});
183532 } else return self.fail("TODO implement airSelect for {f}", .{ty.fmt(pt)});
183558183533 const elem_bits: u16 = @intCast(elem_abi_size * 8);
183559183534 if (!pred_fits_in_elem) if (self.hasFeature(.ssse3)) {
183560183535 const mask_len = elem_abi_size * vec_len;
......@@ -183583,7 +183558,7 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void {
183583183558 mask_alias,
183584183559 mask_mem,
183585183560 );
183586 } else return self.fail("TODO implement airSelect for {}", .{ty.fmt(pt)});
183561 } else return self.fail("TODO implement airSelect for {f}", .{ty.fmt(pt)});
183587183562 {
183588183563 const mask_elem_ty = try pt.intType(.unsigned, elem_bits);
183589183564 const mask_ty = try pt.vectorType(.{ .len = vec_len, .child = mask_elem_ty.toIntern() });
......@@ -183706,7 +183681,7 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void {
183706183681 else => null,
183707183682 },
183708183683 },
183709 }) orelse return self.fail("TODO implement airSelect for {}", .{ty.fmt(pt)});
183684 }) orelse return self.fail("TODO implement airSelect for {f}", .{ty.fmt(pt)});
183710183685 if (has_avx) {
183711183686 const rhs_alias = if (rhs_mcv.isRegister())
183712183687 registerAlias(rhs_mcv.getReg().?, abi_size)
......@@ -184551,7 +184526,7 @@ fn airShuffle(self: *CodeGen, inst: Air.Inst.Index) !void {
184551184526 }
184552184527
184553184528 break :result null;
184554 }) orelse return self.fail("TODO implement airShuffle from {} and {} to {} with {}", .{
184529 }) orelse return self.fail("TODO implement airShuffle from {f} and {f} to {f} with {f}", .{
184555184530 lhs_ty.fmt(pt),
184556184531 rhs_ty.fmt(pt),
184557184532 dst_ty.fmt(pt),
......@@ -184800,7 +184775,7 @@ fn airMulAdd(self: *CodeGen, inst: Air.Inst.Index) !void {
184800184775 32, 64 => !self.hasFeature(.fma),
184801184776 else => unreachable,
184802184777 }) {
184803 if (ty.zigTypeTag(zcu) != .float) return self.fail("TODO implement airMulAdd for {}", .{
184778 if (ty.zigTypeTag(zcu) != .float) return self.fail("TODO implement airMulAdd for {f}", .{
184804184779 ty.fmt(pt),
184805184780 });
184806184781
......@@ -184930,7 +184905,7 @@ fn airMulAdd(self: *CodeGen, inst: Air.Inst.Index) !void {
184930184905 else => unreachable,
184931184906 }
184932184907 else
184933 unreachable) orelse return self.fail("TODO implement airMulAdd for {}", .{ty.fmt(pt)});
184908 unreachable) orelse return self.fail("TODO implement airMulAdd for {f}", .{ty.fmt(pt)});
184934184909
184935184910 var mops: [3]MCValue = undefined;
184936184911 for (order, mcvs) |mop_index, mcv| mops[mop_index - 1] = mcv;
......@@ -185130,7 +185105,7 @@ fn airVaArg(self: *CodeGen, inst: Air.Inst.Index) !void {
185130185105 assert(classes.len == 1);
185131185106 unreachable;
185132185107 },
185133 else => return self.fail("TODO implement c_va_arg for {} on SysV", .{promote_ty.fmt(pt)}),
185108 else => return self.fail("TODO implement c_va_arg for {f} on SysV", .{promote_ty.fmt(pt)}),
185134185109 }
185135185110
185136185111 if (unused) break :result .unreach;
......@@ -185779,7 +185754,7 @@ fn splitType(self: *CodeGen, comptime parts_len: usize, ty: Type) ![parts_len]Ty
185779185754 for (parts) |part| part_sizes += part.abiSize(zcu);
185780185755 if (part_sizes == ty.abiSize(zcu)) return parts;
185781185756 };
185782 return self.fail("TODO implement splitType({d}, {})", .{ parts_len, ty.fmt(pt) });
185757 return self.fail("TODO implement splitType({d}, {f})", .{ parts_len, ty.fmt(pt) });
185783185758}
185784185759
185785185760/// Truncates the value in the register in place.
......@@ -186153,7 +186128,7 @@ const Temp = struct {
186153186128 cg.next_temp_index = @enumFromInt(@intFromEnum(new_temp_index) + 1);
186154186129 const mcv = temp.tracking(cg).short;
186155186130 switch (mcv) {
186156 else => std.debug.panic("{s}: {}\n", .{ @src().fn_name, mcv }),
186131 else => std.debug.panic("{s}: {f}\n", .{ @src().fn_name, mcv }),
186157186132 .register => |reg| {
186158186133 const new_reg = try cg.register_manager.allocReg(new_temp_index.toIndex(), abi.RegisterClass.gp);
186159186134 new_temp_index.tracking(cg).* = .init(.{ .register = new_reg });
......@@ -186227,7 +186202,7 @@ const Temp = struct {
186227186202 const new_temp_index = cg.next_temp_index;
186228186203 cg.temp_type[@intFromEnum(new_temp_index)] = limb_ty;
186229186204 switch (temp.tracking(cg).short) {
186230 else => |mcv| std.debug.panic("{s}: {}\n", .{ @src().fn_name, mcv }),
186205 else => |mcv| std.debug.panic("{s}: {f}\n", .{ @src().fn_name, mcv }),
186231186206 .immediate => |imm| {
186232186207 assert(limb_index == 0);
186233186208 new_temp_index.tracking(cg).* = .init(.{ .immediate = imm });
......@@ -186568,7 +186543,7 @@ const Temp = struct {
186568186543 },
186569186544 else => {},
186570186545 }
186571 std.debug.panic("{s}: {} {}\n", .{ @src().fn_name, temp_tracking, overflow_temp_tracking });
186546 std.debug.panic("{s}: {f} {f}\n", .{ @src().fn_name, temp_tracking, overflow_temp_tracking });
186572186547 }
186573186548
186574186549 fn asMask(temp: Temp, info: MaskInfo, cg: *CodeGen) void {
......@@ -186658,7 +186633,7 @@ const Temp = struct {
186658186633 while (try ptr.toLea(cg)) {}
186659186634 const val_mcv = val.tracking(cg).short;
186660186635 switch (val_mcv) {
186661 else => |mcv| std.debug.panic("{s}: {}\n", .{ @src().fn_name, mcv }),
186636 else => |mcv| std.debug.panic("{s}: {f}\n", .{ @src().fn_name, mcv }),
186662186637 .register => |val_reg| try ptr.loadReg(val_ty, registerAlias(
186663186638 val_reg,
186664186639 @intCast(val_ty.abiSize(cg.pt.zcu)),
......@@ -186698,7 +186673,7 @@ const Temp = struct {
186698186673 {}) {
186699186674 const val_mcv = val.tracking(cg).short;
186700186675 switch (val_mcv) {
186701 else => |mcv| std.debug.panic("{s}: {}\n", .{ @src().fn_name, mcv }),
186676 else => |mcv| std.debug.panic("{s}: {f}\n", .{ @src().fn_name, mcv }),
186702186677 .undef => if (opts.safe) {
186703186678 var pat = try cg.tempInit(.u8, .{ .immediate = 0xaa });
186704186679 var len = try cg.tempInit(.usize, .{ .immediate = val_ty.abiSize(cg.pt.zcu) });
......@@ -186772,7 +186747,7 @@ const Temp = struct {
186772186747 assert(!val_ty.optionalReprIsPayload(cg.pt.zcu));
186773186748 break :first_ty opt_child;
186774186749 },
186775 else => std.debug.panic("{s}: {}\n", .{ @src().fn_name, val_ty.fmt(cg.pt) }),
186750 else => std.debug.panic("{s}: {f}\n", .{ @src().fn_name, val_ty.fmt(cg.pt) }),
186776186751 });
186777186752 const first_size: u31 = @intCast(first_ty.abiSize(cg.pt.zcu));
186778186753 try ptr.storeRegs(first_ty, &.{registerAlias(val_reg_ov.reg, first_size)}, cg);
......@@ -186804,7 +186779,7 @@ const Temp = struct {
186804186779
186805186780 fn readTo(src: *Temp, val_ty: Type, val_mcv: MCValue, opts: AccessOptions, cg: *CodeGen) InnerError!void {
186806186781 switch (val_mcv) {
186807 else => |mcv| std.debug.panic("{s}: {}\n", .{ @src().fn_name, mcv }),
186782 else => |mcv| std.debug.panic("{s}: {f}\n", .{ @src().fn_name, mcv }),
186808186783 .register => |val_reg| try src.readReg(opts.disp, val_ty, registerAlias(
186809186784 val_reg,
186810186785 @intCast(cg.unalignedSize(val_ty)),
......@@ -186844,7 +186819,7 @@ const Temp = struct {
186844186819 {}) {
186845186820 const val_mcv = val.tracking(cg).short;
186846186821 switch (val_mcv) {
186847 else => |mcv| std.debug.panic("{s}: {}\n", .{ @src().fn_name, mcv }),
186822 else => |mcv| std.debug.panic("{s}: {f}\n", .{ @src().fn_name, mcv }),
186848186823 .none => {},
186849186824 .undef => if (opts.safe) {
186850186825 var dst_ptr = try cg.tempInit(.usize, dst.tracking(cg).short.address().offset(opts.disp));
......@@ -186905,7 +186880,7 @@ const Temp = struct {
186905186880 assert(!val_ty.optionalReprIsPayload(cg.pt.zcu));
186906186881 break :first_ty opt_child;
186907186882 },
186908 else => std.debug.panic("{s}: {}\n", .{ @src().fn_name, val_ty.fmt(cg.pt) }),
186883 else => std.debug.panic("{s}: {f}\n", .{ @src().fn_name, val_ty.fmt(cg.pt) }),
186909186884 });
186910186885 const first_size: u31 = @intCast(first_ty.abiSize(cg.pt.zcu));
186911186886 try dst.writeReg(opts.disp, first_ty, registerAlias(val_reg_ov.reg, first_size), cg);
......@@ -191677,12 +191652,12 @@ const Temp = struct {
191677191652 break :result result;
191678191653 },
191679191654 };
191680 tracking_log.debug("{} => {} (birth)", .{ inst, result });
191655 tracking_log.debug("{f} => {f} (birth)", .{ inst, result });
191681191656 cg.inst_tracking.putAssumeCapacityNoClobber(inst, .init(result));
191682191657 },
191683191658 .temp => |temp_index| {
191684191659 const temp_tracking = temp_index.tracking(cg);
191685 tracking_log.debug("{} => {} (birth)", .{ inst, temp_tracking.short });
191660 tracking_log.debug("{f} => {f} (birth)", .{ inst, temp_tracking.short });
191686191661 cg.inst_tracking.putAssumeCapacityNoClobber(inst, .init(temp_tracking.short));
191687191662 assert(cg.reuseTemp(inst, temp_index.toIndex(), temp_tracking));
191688191663 },
......@@ -191757,7 +191732,7 @@ fn resetTemps(cg: *CodeGen, from_index: Temp.Index) InnerError!void {
191757191732 const temp: Temp.Index = @enumFromInt(temp_index);
191758191733 if (temp.isValid(cg)) {
191759191734 any_valid = true;
191760 tracking_log.err("failed to kill {}: {}", .{
191735 tracking_log.err("failed to kill {f}: {f}", .{
191761191736 temp.toIndex(),
191762191737 cg.temp_type[temp_index].fmt(cg.pt),
191763191738 });
src/codegen/c.zig+62-56
......@@ -340,13 +340,15 @@ fn isReservedIdent(ident: []const u8) bool {
340340 } else return reserved_idents.has(ident);
341341}
342342
343fn formatIdent(
344 ident: []const u8,
345 comptime fmt_str: []const u8,
346 _: std.fmt.FormatOptions,
347 writer: anytype,
348) @TypeOf(writer).Error!void {
349 const solo = fmt_str.len != 0 and fmt_str[0] == ' '; // space means solo; not part of a bigger ident.
343fn formatIdentSolo(ident: []const u8, writer: *std.io.Writer) std.io.Writer.Error!void {
344 return formatIdentOptions(ident, writer, true);
345}
346
347fn formatIdentUnsolo(ident: []const u8, writer: *std.io.Writer) std.io.Writer.Error!void {
348 return formatIdentOptions(ident, writer, false);
349}
350
351fn formatIdentOptions(ident: []const u8, writer: *std.io.Writer, solo: bool) std.io.Writer.Error!void {
350352 if (solo and isReservedIdent(ident)) {
351353 try writer.writeAll("zig_e_");
352354 }
......@@ -363,30 +365,36 @@ fn formatIdent(
363365 }
364366 }
365367}
366pub fn fmtIdent(ident: []const u8) std.fmt.Formatter(formatIdent) {
368
369pub fn fmtIdentSolo(ident: []const u8) std.fmt.Formatter([]const u8, formatIdentSolo) {
370 return .{ .data = ident };
371}
372
373pub fn fmtIdentUnsolo(ident: []const u8) std.fmt.Formatter([]const u8, formatIdentUnsolo) {
367374 return .{ .data = ident };
368375}
369376
370377const CTypePoolStringFormatData = struct {
371378 ctype_pool_string: CType.Pool.String,
372379 ctype_pool: *const CType.Pool,
380 solo: bool,
373381};
374fn formatCTypePoolString(
375 data: CTypePoolStringFormatData,
376 comptime fmt_str: []const u8,
377 fmt_opts: std.fmt.FormatOptions,
378 writer: anytype,
379) @TypeOf(writer).Error!void {
382fn formatCTypePoolString(data: CTypePoolStringFormatData, writer: *std.io.Writer) std.io.Writer.Error!void {
380383 if (data.ctype_pool_string.toSlice(data.ctype_pool)) |slice|
381 try formatIdent(slice, fmt_str, fmt_opts, writer)
384 try formatIdentOptions(slice, writer, data.solo)
382385 else
383386 try writer.print("{}", .{data.ctype_pool_string.fmt(data.ctype_pool)});
384387}
385388pub fn fmtCTypePoolString(
386389 ctype_pool_string: CType.Pool.String,
387390 ctype_pool: *const CType.Pool,
388) std.fmt.Formatter(formatCTypePoolString) {
389 return .{ .data = .{ .ctype_pool_string = ctype_pool_string, .ctype_pool = ctype_pool } };
391 solo: bool,
392) std.fmt.Formatter(CTypePoolStringFormatData, formatCTypePoolString) {
393 return .{ .data = .{
394 .ctype_pool_string = ctype_pool_string,
395 .ctype_pool = ctype_pool,
396 .solo = solo,
397 } };
390398}
391399
392400// Returns true if `formatIdent` would make any edits to ident.
......@@ -596,7 +604,7 @@ pub const Function = struct {
596604 return f.object.dg.renderIntCast(w, dest_ty, .{ .c_value = .{ .f = f, .value = src, .v = v } }, src_ty, location);
597605 }
598606
599 fn fmtIntLiteral(f: *Function, val: Value) !std.fmt.Formatter(formatIntLiteral) {
607 fn fmtIntLiteral(f: *Function, val: Value) !std.fmt.Formatter(FormatIntLiteralContext, formatIntLiteral) {
600608 return f.object.dg.fmtIntLiteral(val, .Other);
601609 }
602610
......@@ -614,16 +622,16 @@ pub const Function = struct {
614622 gop.value_ptr.* = .{
615623 .fn_name = switch (key) {
616624 .tag_name,
617 => |enum_ty| try ctype_pool.fmt(gpa, "zig_{s}_{}__{d}", .{
625 => |enum_ty| try ctype_pool.fmt(gpa, "zig_{s}_{f}__{d}", .{
618626 @tagName(key),
619 fmtIdent(ip.loadEnumType(enum_ty).name.toSlice(ip)),
627 fmtIdentUnsolo(ip.loadEnumType(enum_ty).name.toSlice(ip)),
620628 @intFromEnum(enum_ty),
621629 }),
622630 .never_tail,
623631 .never_inline,
624632 => |owner_nav| try ctype_pool.fmt(gpa, "zig_{s}_{}__{d}", .{
625633 @tagName(key),
626 fmtIdent(ip.getNav(owner_nav).name.toSlice(ip)),
634 fmtIdentUnsolo(ip.getNav(owner_nav).name.toSlice(ip)),
627635 @intFromEnum(owner_nav),
628636 }),
629637 },
......@@ -965,7 +973,7 @@ pub const DeclGen = struct {
965973
966974 fn renderErrorName(dg: *DeclGen, writer: anytype, err_name: InternPool.NullTerminatedString) !void {
967975 const ip = &dg.pt.zcu.intern_pool;
968 try writer.print("zig_error_{}", .{fmtIdent(err_name.toSlice(ip))});
976 try writer.print("zig_error_{}", .{fmtIdentUnsolo(err_name.toSlice(ip))});
969977 }
970978
971979 fn renderValue(
......@@ -1551,7 +1559,7 @@ pub const DeclGen = struct {
15511559 .payload => {
15521560 try writer.writeByte('{');
15531561 if (field_ty.hasRuntimeBits(zcu)) {
1554 try writer.print(" .{ } = ", .{fmtIdent(field_name.toSlice(ip))});
1562 try writer.print(" .{ } = ", .{fmtIdentSolo(field_name.toSlice(ip))});
15551563 try dg.renderValue(
15561564 writer,
15571565 Value.fromInterned(un.val),
......@@ -1888,7 +1896,7 @@ pub const DeclGen = struct {
18881896 kind: CType.Kind,
18891897 name: union(enum) {
18901898 nav: InternPool.Nav.Index,
1891 fmt_ctype_pool_string: std.fmt.Formatter(formatCTypePoolString),
1899 fmt_ctype_pool_string: std.fmt.Formatter(CTypePoolStringFormatData, formatCTypePoolString),
18921900 @"export": struct {
18931901 main_name: InternPool.NullTerminatedString,
18941902 extern_name: InternPool.NullTerminatedString,
......@@ -1933,7 +1941,7 @@ pub const DeclGen = struct {
19331941 switch (name) {
19341942 .nav => |nav| try dg.renderNavName(w, nav),
19351943 .fmt_ctype_pool_string => |fmt| try w.print("{ }", .{fmt}),
1936 .@"export" => |@"export"| try w.print("{ }", .{fmtIdent(@"export".extern_name.toSlice(ip))}),
1944 .@"export" => |@"export"| try w.print("{ }", .{fmtIdentSolo(@"export".extern_name.toSlice(ip))}),
19371945 }
19381946
19391947 try renderTypeSuffix(
......@@ -1961,13 +1969,13 @@ pub const DeclGen = struct {
19611969 const is_export = @"export".extern_name != @"export".main_name;
19621970 if (is_mangled and is_export) {
19631971 try w.print(" zig_mangled_export({ }, {s}, {s})", .{
1964 fmtIdent(extern_name),
1972 fmtIdentSolo(extern_name),
19651973 fmtStringLiteral(extern_name, null),
19661974 fmtStringLiteral(@"export".main_name.toSlice(ip), null),
19671975 });
19681976 } else if (is_mangled) {
19691977 try w.print(" zig_mangled({ }, {s})", .{
1970 fmtIdent(extern_name), fmtStringLiteral(extern_name, null),
1978 fmtIdentSolo(extern_name), fmtStringLiteral(extern_name, null),
19711979 });
19721980 } else if (is_export) {
19731981 try w.print(" zig_export({s}, {s})", .{
......@@ -2198,7 +2206,7 @@ pub const DeclGen = struct {
21982206 .new_local, .local => |i| try w.print("t{d}", .{i}),
21992207 .constant => |uav| try renderUavName(w, uav),
22002208 .nav => |nav| try dg.renderNavName(w, nav),
2201 .identifier => |ident| try w.print("{ }", .{fmtIdent(ident)}),
2209 .identifier => |ident| try w.print("{ }", .{fmtIdentSolo(ident)}),
22022210 else => unreachable,
22032211 }
22042212 }
......@@ -2215,13 +2223,13 @@ pub const DeclGen = struct {
22152223 try dg.renderNavName(w, nav);
22162224 },
22172225 .undef => |ty| try dg.renderUndefValue(w, ty, .Other),
2218 .identifier => |ident| try w.print("{ }", .{fmtIdent(ident)}),
2226 .identifier => |ident| try w.print("{ }", .{fmtIdentSolo(ident)}),
22192227 .payload_identifier => |ident| try w.print("{ }.{ }", .{
2220 fmtIdent("payload"),
2221 fmtIdent(ident),
2228 fmtIdentSolo("payload"),
2229 fmtIdentSolo(ident),
22222230 }),
2223 .ctype_pool_string => |string| try w.print("{ }", .{
2224 fmtCTypePoolString(string, &dg.ctype_pool),
2231 .ctype_pool_string => |string| try w.print("{f}", .{
2232 fmtCTypePoolString(string, &dg.ctype_pool, true),
22252233 }),
22262234 }
22272235 }
......@@ -2245,10 +2253,10 @@ pub const DeclGen = struct {
22452253 },
22462254 .nav_ref => |nav| try dg.renderNavName(w, nav),
22472255 .undef => unreachable,
2248 .identifier => |ident| try w.print("(*{ })", .{fmtIdent(ident)}),
2256 .identifier => |ident| try w.print("(*{ })", .{fmtIdentSolo(ident)}),
22492257 .payload_identifier => |ident| try w.print("(*{ }.{ })", .{
2250 fmtIdent("payload"),
2251 fmtIdent(ident),
2258 fmtIdentSolo("payload"),
2259 fmtIdentSolo(ident),
22522260 }),
22532261 }
22542262 }
......@@ -2334,14 +2342,14 @@ pub const DeclGen = struct {
23342342 const nav = ip.getNav(nav_index);
23352343 if (nav.getExtern(ip)) |@"extern"| {
23362344 try writer.print("{ }", .{
2337 fmtIdent(ip.getNav(@"extern".owner_nav).name.toSlice(ip)),
2345 fmtIdentSolo(ip.getNav(@"extern".owner_nav).name.toSlice(ip)),
23382346 });
23392347 } else {
23402348 // MSVC has a limit of 4095 character token length limit, and fmtIdent can (worst case),
23412349 // expand to 3x the length of its input, but let's cut it off at a much shorter limit.
23422350 const fqn_slice = ip.getNav(nav_index).fqn.toSlice(ip);
23432351 try writer.print("{}__{d}", .{
2344 fmtIdent(fqn_slice[0..@min(fqn_slice.len, 100)]),
2352 fmtIdentUnsolo(fqn_slice[0..@min(fqn_slice.len, 100)]),
23452353 @intFromEnum(nav_index),
23462354 });
23472355 }
......@@ -2452,7 +2460,7 @@ fn renderFwdDeclTypeName(
24522460 switch (fwd_decl.name) {
24532461 .anon => try w.print("anon__lazy_{d}", .{@intFromEnum(ctype.index)}),
24542462 .index => |index| try w.print("{}__{d}", .{
2455 fmtIdent(Type.fromInterned(index).containerTypeName(ip).toSlice(&zcu.intern_pool)),
2463 fmtIdentUnsolo(Type.fromInterned(index).containerTypeName(ip).toSlice(&zcu.intern_pool)),
24562464 @intFromEnum(index),
24572465 }),
24582466 }
......@@ -2666,7 +2674,7 @@ fn renderFields(
26662674 .suffix,
26672675 .{},
26682676 );
2669 try writer.print("{}{ }", .{ trailing, fmtCTypePoolString(field_info.name, ctype_pool) });
2677 try writer.print("{}{f}", .{ trailing, fmtCTypePoolString(field_info.name, ctype_pool, true) });
26702678 try renderTypeSuffix(.flush, ctype_pool, zcu, writer, field_info.ctype, .suffix, .{});
26712679 try writer.writeAll(";\n");
26722680 }
......@@ -2841,7 +2849,7 @@ pub fn genErrDecls(o: *Object) !void {
28412849 const name = name_nts.toSlice(ip);
28422850 if (val > 1) try writer.writeAll(", ");
28432851 try writer.print("{{" ++ name_prefix ++ "{}, {}}}", .{
2844 fmtIdent(name),
2852 fmtIdentUnsolo(name),
28452853 try o.dg.fmtIntLiteral(try pt.intValue(.usize, name.len), .StaticInitializer),
28462854 });
28472855 }
......@@ -2891,7 +2899,7 @@ pub fn genLazyFn(o: *Object, lazy_ctype_pool: *const CType.Pool, lazy_fn: LazyFn
28912899 try w.writeAll(";\n return (");
28922900 try o.dg.renderType(w, name_slice_ty);
28932901 try w.print("){{{}, {}}};\n", .{
2894 fmtIdent("name"),
2902 fmtIdentUnsolo("name"),
28952903 try o.dg.fmtIntLiteral(try pt.intValue(.usize, tag_name_len), .Other),
28962904 });
28972905
......@@ -3204,7 +3212,7 @@ pub fn genExports(dg: *DeclGen, exported: Zcu.Exported, export_indices: []const
32043212 .uav => |uav| try DeclGen.renderUavName(fwd, Value.fromInterned(uav)),
32053213 }
32063214 try fwd.writeByte(' ');
3207 try fwd.print("{ }", .{fmtIdent(main_name.toSlice(ip))});
3215 try fwd.print("{ }", .{fmtIdentSolo(main_name.toSlice(ip))});
32083216 try fwd.writeByte('\n');
32093217
32103218 const exported_val = exported.getValue(zcu);
......@@ -3250,13 +3258,13 @@ pub fn genExports(dg: *DeclGen, exported: Zcu.Exported, export_indices: []const
32503258 );
32513259 if (is_mangled and is_export) {
32523260 try fwd.print(" zig_mangled_export({ }, {s}, {s})", .{
3253 fmtIdent(extern_name),
3261 fmtIdentSolo(extern_name),
32543262 fmtStringLiteral(extern_name, null),
32553263 fmtStringLiteral(main_name.toSlice(ip), null),
32563264 });
32573265 } else if (is_mangled) {
32583266 try fwd.print(" zig_mangled({ }, {s})", .{
3259 fmtIdent(extern_name), fmtStringLiteral(extern_name, null),
3267 fmtIdentSolo(extern_name), fmtStringLiteral(extern_name, null),
32603268 });
32613269 } else if (is_export) {
32623270 try fwd.print(" zig_export({s}, {s})", .{
......@@ -4538,7 +4546,7 @@ fn airCmpLtErrorsLen(f: *Function, inst: Air.Inst.Index) !CValue {
45384546 try f.writeCValue(writer, local, .Other);
45394547 try writer.writeAll(" = ");
45404548 try f.writeCValue(writer, operand, .Other);
4541 try writer.print(" < sizeof({ }) / sizeof(*{0 });\n", .{fmtIdent("zig_errorName")});
4549 try writer.print(" < sizeof({ }) / sizeof(*{0 });\n", .{fmtIdentSolo("zig_errorName")});
45424550 return local;
45434551}
45444552
......@@ -8202,10 +8210,9 @@ fn stringLiteral(
82028210const FormatStringContext = struct { str: []const u8, sentinel: ?u8 };
82038211fn formatStringLiteral(
82048212 data: FormatStringContext,
8205 comptime fmt: []const u8,
8206 _: std.fmt.FormatOptions,
8207 writer: anytype,
8208) @TypeOf(writer).Error!void {
8213 writer: *std.io.Writer,
8214 comptime fmt: []const u8, // TODO move this state to FormatStringContext
8215) std.io.Writer.Error!void {
82098216 if (fmt.len != 1 or fmt[0] != 's') @compileError("Invalid fmt: " ++ fmt);
82108217
82118218 var literal = stringLiteral(writer, data.str.len + @intFromBool(data.sentinel != null));
......@@ -8215,7 +8222,7 @@ fn formatStringLiteral(
82158222 try literal.end();
82168223}
82178224
8218fn fmtStringLiteral(str: []const u8, sentinel: ?u8) std.fmt.Formatter(formatStringLiteral) {
8225fn fmtStringLiteral(str: []const u8, sentinel: ?u8) std.fmt.Formatter(FormatStringContext, formatStringLiteral) {
82198226 return .{ .data = .{ .str = str, .sentinel = sentinel } };
82208227}
82218228
......@@ -8234,10 +8241,9 @@ const FormatIntLiteralContext = struct {
82348241};
82358242fn formatIntLiteral(
82368243 data: FormatIntLiteralContext,
8237 comptime fmt: []const u8,
8238 options: std.fmt.FormatOptions,
8239 writer: anytype,
8240) @TypeOf(writer).Error!void {
8244 writer: *std.io.Writer,
8245 comptime fmt: []const u8, // TODO move this state to FormatIntLiteralContext
8246) std.io.Writer.Error!void {
82418247 const pt = data.dg.pt;
82428248 const zcu = pt.zcu;
82438249 const target = &data.dg.mod.resolved_target.result;
......@@ -8406,7 +8412,7 @@ fn formatIntLiteral(
84068412 .kind = data.kind,
84078413 .ctype = c_limb_ctype,
84088414 .val = try pt.intValue_big(.comptime_int, c_limb_mut.toConst()),
8409 }, fmt, options, writer);
8415 }, fmt, writer);
84108416 }
84118417 }
84128418 try data.ctype.renderLiteralSuffix(writer, ctype_pool);
src/codegen/c/Type.zig+2-8
......@@ -938,19 +938,13 @@ pub const Pool = struct {
938938 index: String.Index,
939939
940940 const FormatData = struct { string: String, pool: *const Pool };
941 fn format(
942 data: FormatData,
943 comptime fmt_str: []const u8,
944 _: std.fmt.FormatOptions,
945 writer: anytype,
946 ) @TypeOf(writer).Error!void {
947 if (fmt_str.len > 0) @compileError("invalid format string '" ++ fmt_str ++ "'");
941 fn format(data: FormatData, writer: *std.io.Writer) std.io.Writer.Error!void {
948942 if (data.string.toSlice(data.pool)) |slice|
949943 try writer.writeAll(slice)
950944 else
951945 try writer.print("f{d}", .{@intFromEnum(data.string.index)});
952946 }
953 pub fn fmt(str: String, pool: *const Pool) std.fmt.Formatter(format) {
947 pub fn fmt(str: String, pool: *const Pool) std.fmt.Formatter(FormatData, format) {
954948 return .{ .data = .{ .string = str, .pool = pool } };
955949 }
956950
src/link/Coff.zig+14-29
......@@ -3061,40 +3061,25 @@ const ImportTable = struct {
30613061 return base_vaddr + index * @sizeOf(u64);
30623062 }
30633063
3064 const FormatContext = struct {
3064 const Format = struct {
30653065 itab: ImportTable,
30663066 ctx: Context,
3067 };
30683067
3069 fn format(itab: ImportTable, comptime unused_format_string: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
3070 _ = itab;
3071 _ = unused_format_string;
3072 _ = options;
3073 _ = writer;
3074 @compileError("do not format ImportTable directly; use itab.fmtDebug()");
3075 }
3076
3077 fn format2(
3078 fmt_ctx: FormatContext,
3079 comptime unused_format_string: []const u8,
3080 options: fmt.FormatOptions,
3081 writer: anytype,
3082 ) @TypeOf(writer).Error!void {
3083 _ = options;
3084 comptime assert(unused_format_string.len == 0);
3085 const lib_name = fmt_ctx.ctx.coff.temp_strtab.getAssumeExists(fmt_ctx.ctx.name_off);
3086 const base_vaddr = getBaseAddress(fmt_ctx.ctx);
3087 try writer.print("IAT({s}.dll) @{x}:", .{ lib_name, base_vaddr });
3088 for (fmt_ctx.itab.entries.items, 0..) |entry, i| {
3089 try writer.print("\n {d}@{?x} => {s}", .{
3090 i,
3091 fmt_ctx.itab.getImportAddress(entry, fmt_ctx.ctx),
3092 fmt_ctx.ctx.coff.getSymbolName(entry),
3093 });
3068 fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
3069 const lib_name = f.ctx.coff.temp_strtab.getAssumeExists(f.ctx.name_off);
3070 const base_vaddr = getBaseAddress(f.ctx);
3071 try writer.print("IAT({s}.dll) @{x}:", .{ lib_name, base_vaddr });
3072 for (f.itab.entries.items, 0..) |entry, i| {
3073 try writer.print("\n {d}@{?x} => {s}", .{
3074 i,
3075 f.itab.getImportAddress(entry, f.ctx),
3076 f.ctx.coff.getSymbolName(entry),
3077 });
3078 }
30943079 }
3095 }
3080 };
30963081
3097 fn fmtDebug(itab: ImportTable, ctx: Context) fmt.Formatter(format2) {
3082 fn fmtDebug(itab: ImportTable, ctx: Context) fmt.Formatter(Format, Format.default) {
30983083 return .{ .data = .{ .itab = itab, .ctx = ctx } };
30993084 }
31003085
src/link/Elf.zig+10-39
......@@ -3860,26 +3860,19 @@ pub fn failFile(
38603860 return error.LinkFailure;
38613861}
38623862
3863const FormatShdrCtx = struct {
3863const FormatShdr = struct {
38643864 elf_file: *Elf,
38653865 shdr: elf.Elf64_Shdr,
38663866};
38673867
3868fn fmtShdr(self: *Elf, shdr: elf.Elf64_Shdr) std.fmt.Formatter(formatShdr) {
3868fn fmtShdr(self: *Elf, shdr: elf.Elf64_Shdr) std.fmt.Formatter(FormatShdr, formatShdr) {
38693869 return .{ .data = .{
38703870 .shdr = shdr,
38713871 .elf_file = self,
38723872 } };
38733873}
38743874
3875fn formatShdr(
3876 ctx: FormatShdrCtx,
3877 comptime unused_fmt_string: []const u8,
3878 options: std.fmt.FormatOptions,
3879 writer: anytype,
3880) !void {
3881 _ = options;
3882 _ = unused_fmt_string;
3875fn formatShdr(ctx: FormatShdr, writer: *std.io.Writer) std.io.Writer.Error!void {
38833876 const shdr = ctx.shdr;
38843877 try writer.print("{s} : @{x} ({x}) : align({x}) : size({x}) : entsize({x}) : flags({})", .{
38853878 ctx.elf_file.getShString(shdr.sh_name), shdr.sh_offset,
......@@ -3889,18 +3882,11 @@ fn formatShdr(
38893882 });
38903883}
38913884
3892pub fn fmtShdrFlags(sh_flags: u64) std.fmt.Formatter(formatShdrFlags) {
3885pub fn fmtShdrFlags(sh_flags: u64) std.fmt.Formatter(u64, formatShdrFlags) {
38933886 return .{ .data = sh_flags };
38943887}
38953888
3896fn formatShdrFlags(
3897 sh_flags: u64,
3898 comptime unused_fmt_string: []const u8,
3899 options: std.fmt.FormatOptions,
3900 writer: anytype,
3901) !void {
3902 _ = unused_fmt_string;
3903 _ = options;
3889fn formatShdrFlags(sh_flags: u64, writer: *std.io.Writer) std.io.Writer.Error!void {
39043890 if (elf.SHF_WRITE & sh_flags != 0) {
39053891 try writer.writeAll("W");
39063892 }
......@@ -3945,26 +3931,19 @@ fn formatShdrFlags(
39453931 }
39463932}
39473933
3948const FormatPhdrCtx = struct {
3934const FormatPhdr = struct {
39493935 elf_file: *Elf,
39503936 phdr: elf.Elf64_Phdr,
39513937};
39523938
3953fn fmtPhdr(self: *Elf, phdr: elf.Elf64_Phdr) std.fmt.Formatter(formatPhdr) {
3939fn fmtPhdr(self: *Elf, phdr: elf.Elf64_Phdr) std.fmt.Formatter(FormatPhdr, formatPhdr) {
39543940 return .{ .data = .{
39553941 .phdr = phdr,
39563942 .elf_file = self,
39573943 } };
39583944}
39593945
3960fn formatPhdr(
3961 ctx: FormatPhdrCtx,
3962 comptime unused_fmt_string: []const u8,
3963 options: std.fmt.FormatOptions,
3964 writer: anytype,
3965) !void {
3966 _ = options;
3967 _ = unused_fmt_string;
3946fn formatPhdr(ctx: FormatPhdr, writer: *std.io.Writer) std.io.Writer.Error!void {
39683947 const phdr = ctx.phdr;
39693948 const write = phdr.p_flags & elf.PF_W != 0;
39703949 const read = phdr.p_flags & elf.PF_R != 0;
......@@ -3991,19 +3970,11 @@ fn formatPhdr(
39913970 });
39923971}
39933972
3994pub fn dumpState(self: *Elf) std.fmt.Formatter(fmtDumpState) {
3973pub fn dumpState(self: *Elf) std.fmt.Formatter(*Elf, fmtDumpState) {
39953974 return .{ .data = self };
39963975}
39973976
3998fn fmtDumpState(
3999 self: *Elf,
4000 comptime unused_fmt_string: []const u8,
4001 options: std.fmt.FormatOptions,
4002 writer: anytype,
4003) !void {
4004 _ = unused_fmt_string;
4005 _ = options;
4006
3977fn fmtDumpState(self: *Elf, writer: *std.io.Writer) std.io.Writer.Error!void {
40073978 const shared_objects = self.shared_objects.values();
40083979
40093980 if (self.zigObjectPtr()) |zig_object| {
src/link/Elf/Archive.zig+12-19
......@@ -214,35 +214,28 @@ pub const ArSymtab = struct {
214214 @compileError("do not format ar symtab directly; use fmt instead");
215215 }
216216
217 const FormatContext = struct {
217 const Format = struct {
218218 ar: ArSymtab,
219219 elf_file: *Elf,
220
221 fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
222 const ar = f.ar;
223 const elf_file = f.elf_file;
224 for (ar.symtab.items, 0..) |entry, i| {
225 const name = ar.strtab.getAssumeExists(entry.off);
226 const file = elf_file.file(entry.file_index).?;
227 try writer.print(" {d}: {s} in file({d})({})\n", .{ i, name, entry.file_index, file.fmtPath() });
228 }
229 }
220230 };
221231
222 pub fn fmt(ar: ArSymtab, elf_file: *Elf) std.fmt.Formatter(format2) {
232 pub fn fmt(ar: ArSymtab, elf_file: *Elf) std.fmt.Formatter(Format, Format.default) {
223233 return .{ .data = .{
224234 .ar = ar,
225235 .elf_file = elf_file,
226236 } };
227237 }
228238
229 fn format2(
230 ctx: FormatContext,
231 comptime unused_fmt_string: []const u8,
232 options: std.fmt.FormatOptions,
233 writer: anytype,
234 ) !void {
235 _ = unused_fmt_string;
236 _ = options;
237 const ar = ctx.ar;
238 const elf_file = ctx.elf_file;
239 for (ar.symtab.items, 0..) |entry, i| {
240 const name = ar.strtab.getAssumeExists(entry.off);
241 const file = elf_file.file(entry.file_index).?;
242 try writer.print(" {d}: {s} in file({d})({})\n", .{ i, name, entry.file_index, file.fmtPath() });
243 }
244 }
245
246239 const Entry = struct {
247240 /// Offset into the string table.
248241 off: u32,
src/link/Elf/Atom.zig+28-48
......@@ -904,65 +904,45 @@ pub fn setExtra(atom: Atom, extras: Extra, elf_file: *Elf) void {
904904 atom.file(elf_file).?.setAtomExtra(atom.extra_index, extras);
905905}
906906
907pub fn format(
908 atom: Atom,
909 comptime unused_fmt_string: []const u8,
910 options: std.fmt.FormatOptions,
911 writer: anytype,
912) !void {
913 _ = atom;
914 _ = unused_fmt_string;
915 _ = options;
916 _ = writer;
917 @compileError("do not format Atom directly");
918}
919
920pub fn fmt(atom: Atom, elf_file: *Elf) std.fmt.Formatter(format2) {
907pub fn fmt(atom: Atom, elf_file: *Elf) std.fmt.Formatter(Format, Format.default) {
921908 return .{ .data = .{
922909 .atom = atom,
923910 .elf_file = elf_file,
924911 } };
925912}
926913
927const FormatContext = struct {
914const Format = struct {
928915 atom: Atom,
929916 elf_file: *Elf,
930};
931917
932fn format2(
933 ctx: FormatContext,
934 comptime unused_fmt_string: []const u8,
935 options: std.fmt.FormatOptions,
936 writer: anytype,
937) !void {
938 _ = options;
939 _ = unused_fmt_string;
940 const atom = ctx.atom;
941 const elf_file = ctx.elf_file;
942 try writer.print("atom({d}) : {s} : @{x} : shdr({d}) : align({x}) : size({x}) : prev({}) : next({})", .{
943 atom.atom_index, atom.name(elf_file), atom.address(elf_file),
944 atom.output_section_index, atom.alignment.toByteUnits() orelse 0, atom.size,
945 atom.prev_atom_ref, atom.next_atom_ref,
946 });
947 if (atom.file(elf_file)) |atom_file| switch (atom_file) {
948 .object => |object| {
949 if (atom.fdes(object).len > 0) {
950 try writer.writeAll(" : fdes{ ");
951 const extras = atom.extra(elf_file);
952 for (atom.fdes(object), extras.fde_start..) |fde, i| {
953 try writer.print("{d}", .{i});
954 if (!fde.alive) try writer.writeAll("([*])");
955 if (i - extras.fde_start < extras.fde_count - 1) try writer.writeAll(", ");
918 fn default(f: Format, w: *std.io.Writer) std.io.Writer.Error!void {
919 const atom = f.atom;
920 const elf_file = f.elf_file;
921 try w.print("atom({d}) : {s} : @{x} : shdr({d}) : align({x}) : size({x}) : prev({}) : next({})", .{
922 atom.atom_index, atom.name(elf_file), atom.address(elf_file),
923 atom.output_section_index, atom.alignment.toByteUnits() orelse 0, atom.size,
924 atom.prev_atom_ref, atom.next_atom_ref,
925 });
926 if (atom.file(elf_file)) |atom_file| switch (atom_file) {
927 .object => |object| {
928 if (atom.fdes(object).len > 0) {
929 try w.writeAll(" : fdes{ ");
930 const extras = atom.extra(elf_file);
931 for (atom.fdes(object), extras.fde_start..) |fde, i| {
932 try w.print("{d}", .{i});
933 if (!fde.alive) try w.writeAll("([*])");
934 if (i - extras.fde_start < extras.fde_count - 1) try w.writeAll(", ");
935 }
936 try w.writeAll(" }");
956937 }
957 try writer.writeAll(" }");
958 }
959 },
960 else => {},
961 };
962 if (!atom.alive) {
963 try writer.writeAll(" : [*]");
938 },
939 else => {},
940 };
941 if (!atom.alive) {
942 try w.writeAll(" : [*]");
943 }
964944 }
965}
945};
966946
967947pub const Index = u32;
968948
src/link/Elf/AtomList.zig+19-36
......@@ -167,46 +167,29 @@ pub fn lastAtom(list: AtomList, elf_file: *Elf) *Atom {
167167 return elf_file.atom(list.atoms.keys()[list.atoms.keys().len - 1]).?;
168168}
169169
170pub fn format(
171 list: AtomList,
172 comptime unused_fmt_string: []const u8,
173 options: std.fmt.FormatOptions,
174 writer: anytype,
175) !void {
176 _ = list;
177 _ = unused_fmt_string;
178 _ = options;
179 _ = writer;
180 @compileError("do not format AtomList directly");
181}
182
183const FormatCtx = struct { AtomList, *Elf };
170const Format = struct {
171 atom_list: AtomList,
172 elf_file: *Elf,
173
174 fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
175 const list, const elf_file = f;
176 try writer.print("list : @{x} : shdr({d}) : align({x}) : size({x})", .{
177 list.address(elf_file), list.output_section_index,
178 list.alignment.toByteUnits() orelse 0, list.size,
179 });
180 try writer.writeAll(" : atoms{ ");
181 for (list.atoms.keys(), 0..) |ref, i| {
182 try writer.print("{}", .{ref});
183 if (i < list.atoms.keys().len - 1) try writer.writeAll(", ");
184 }
185 try writer.writeAll(" }");
186 }
187};
184188
185pub fn fmt(list: AtomList, elf_file: *Elf) std.fmt.Formatter(format2) {
189pub fn fmt(list: AtomList, elf_file: *Elf) std.fmt.Formatter(Format, Format.default) {
186190 return .{ .data = .{ list, elf_file } };
187191}
188192
189fn format2(
190 ctx: FormatCtx,
191 comptime unused_fmt_string: []const u8,
192 options: std.fmt.FormatOptions,
193 writer: anytype,
194) !void {
195 _ = unused_fmt_string;
196 _ = options;
197 const list, const elf_file = ctx;
198 try writer.print("list : @{x} : shdr({d}) : align({x}) : size({x})", .{
199 list.address(elf_file), list.output_section_index,
200 list.alignment.toByteUnits() orelse 0, list.size,
201 });
202 try writer.writeAll(" : atoms{ ");
203 for (list.atoms.keys(), 0..) |ref, i| {
204 try writer.print("{}", .{ref});
205 if (i < list.atoms.keys().len - 1) try writer.writeAll(", ");
206 }
207 try writer.writeAll(" }");
208}
209
210193const assert = std.debug.assert;
211194const elf = std.elf;
212195const log = std.log.scoped(.link);
src/link/Elf/LinkerDefined.zig+14-21
......@@ -437,38 +437,31 @@ pub fn setSymbolExtra(self: *LinkerDefined, index: u32, extra: Symbol.Extra) voi
437437 }
438438}
439439
440pub fn fmtSymtab(self: *LinkerDefined, elf_file: *Elf) std.fmt.Formatter(formatSymtab) {
440pub fn fmtSymtab(self: *LinkerDefined, elf_file: *Elf) std.fmt.Formatter(Format, Format.symtab) {
441441 return .{ .data = .{
442442 .self = self,
443443 .elf_file = elf_file,
444444 } };
445445}
446446
447const FormatContext = struct {
447const Format = struct {
448448 self: *LinkerDefined,
449449 elf_file: *Elf,
450};
451450
452fn formatSymtab(
453 ctx: FormatContext,
454 comptime unused_fmt_string: []const u8,
455 options: std.fmt.FormatOptions,
456 writer: anytype,
457) !void {
458 _ = unused_fmt_string;
459 _ = options;
460 const self = ctx.self;
461 const elf_file = ctx.elf_file;
462 try writer.writeAll(" globals\n");
463 for (self.symbols.items, 0..) |sym, i| {
464 const ref = self.resolveSymbol(@intCast(i), elf_file);
465 if (elf_file.symbol(ref)) |ref_sym| {
466 try writer.print(" {}\n", .{ref_sym.fmt(elf_file)});
467 } else {
468 try writer.print(" {s} : unclaimed\n", .{sym.name(elf_file)});
451 fn symtab(ctx: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
452 const self = ctx.self;
453 const elf_file = ctx.elf_file;
454 try writer.writeAll(" globals\n");
455 for (self.symbols.items, 0..) |sym, i| {
456 const ref = self.resolveSymbol(@intCast(i), elf_file);
457 if (elf_file.symbol(ref)) |ref_sym| {
458 try writer.print(" {f}\n", .{ref_sym.fmt(elf_file)});
459 } else {
460 try writer.print(" {s} : unclaimed\n", .{sym.name(elf_file)});
461 }
469462 }
470463 }
471}
464};
472465
473466const assert = std.debug.assert;
474467const elf = std.elf;
src/link/Elf/Merge.zig+31-71
......@@ -157,54 +157,34 @@ pub const Section = struct {
157157 }
158158 };
159159
160 pub fn format(
161 msec: Section,
162 comptime unused_fmt_string: []const u8,
163 options: std.fmt.FormatOptions,
164 writer: anytype,
165 ) !void {
166 _ = msec;
167 _ = unused_fmt_string;
168 _ = options;
169 _ = writer;
170 @compileError("do not format directly");
171 }
172
173 pub fn fmt(msec: Section, elf_file: *Elf) std.fmt.Formatter(format2) {
160 pub fn fmt(msec: Section, elf_file: *Elf) std.fmt.Formatter(Format, Format.default) {
174161 return .{ .data = .{
175162 .msec = msec,
176163 .elf_file = elf_file,
177164 } };
178165 }
179166
180 const FormatContext = struct {
167 const Format = struct {
181168 msec: Section,
182169 elf_file: *Elf,
183 };
184170
185 pub fn format2(
186 ctx: FormatContext,
187 comptime unused_fmt_string: []const u8,
188 options: std.fmt.FormatOptions,
189 writer: anytype,
190 ) !void {
191 _ = options;
192 _ = unused_fmt_string;
193 const msec = ctx.msec;
194 const elf_file = ctx.elf_file;
195 try writer.print("{s} : @{x} : size({x}) : align({x}) : entsize({x}) : type({x}) : flags({x})\n", .{
196 msec.name(elf_file),
197 msec.address(elf_file),
198 msec.size,
199 msec.alignment.toByteUnits() orelse 0,
200 msec.entsize,
201 msec.type,
202 msec.flags,
203 });
204 for (msec.subsections.items) |msub| {
205 try writer.print(" {}\n", .{msub.fmt(elf_file)});
171 pub fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
172 const msec = f.msec;
173 const elf_file = f.elf_file;
174 try writer.print("{s} : @{x} : size({x}) : align({x}) : entsize({x}) : type({x}) : flags({x})\n", .{
175 msec.name(elf_file),
176 msec.address(elf_file),
177 msec.size,
178 msec.alignment.toByteUnits() orelse 0,
179 msec.entsize,
180 msec.type,
181 msec.flags,
182 });
183 for (msec.subsections.items) |msub| {
184 try writer.print(" {f}\n", .{msub.fmt(elf_file)});
185 }
206186 }
207 }
187 };
208188
209189 pub const Index = u32;
210190};
......@@ -231,48 +211,28 @@ pub const Subsection = struct {
231211 return msec.bytes.items[msub.string_index..][0..msub.size];
232212 }
233213
234 pub fn format(
235 msub: Subsection,
236 comptime unused_fmt_string: []const u8,
237 options: std.fmt.FormatOptions,
238 writer: anytype,
239 ) !void {
240 _ = msub;
241 _ = unused_fmt_string;
242 _ = options;
243 _ = writer;
244 @compileError("do not format directly");
245 }
246
247 pub fn fmt(msub: Subsection, elf_file: *Elf) std.fmt.Formatter(format2) {
214 pub fn fmt(msub: Subsection, elf_file: *Elf) std.fmt.Formatter(Format, Format.default) {
248215 return .{ .data = .{
249216 .msub = msub,
250217 .elf_file = elf_file,
251218 } };
252219 }
253220
254 const FormatContext = struct {
221 const Format = struct {
255222 msub: Subsection,
256223 elf_file: *Elf,
257 };
258224
259 pub fn format2(
260 ctx: FormatContext,
261 comptime unused_fmt_string: []const u8,
262 options: std.fmt.FormatOptions,
263 writer: anytype,
264 ) !void {
265 _ = options;
266 _ = unused_fmt_string;
267 const msub = ctx.msub;
268 const elf_file = ctx.elf_file;
269 try writer.print("@{x} : align({x}) : size({x})", .{
270 msub.address(elf_file),
271 msub.alignment,
272 msub.size,
273 });
274 if (!msub.alive) try writer.writeAll(" : [*]");
275 }
225 pub fn default(ctx: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
226 const msub = ctx.msub;
227 const elf_file = ctx.elf_file;
228 try writer.print("@{x} : align({x}) : size({x})", .{
229 msub.address(elf_file),
230 msub.alignment,
231 msub.size,
232 });
233 if (!msub.alive) try writer.writeAll(" : [*]");
234 }
235 };
276236
277237 pub const Index = u32;
278238};
src/link/Elf/Object.zig+66-121
......@@ -1432,167 +1432,112 @@ pub fn group(self: *Object, index: Elf.Group.Index) *Elf.Group {
14321432 return &self.groups.items[index];
14331433}
14341434
1435pub fn format(
1436 self: *Object,
1437 comptime unused_fmt_string: []const u8,
1438 options: std.fmt.FormatOptions,
1439 writer: anytype,
1440) !void {
1441 _ = self;
1442 _ = unused_fmt_string;
1443 _ = options;
1444 _ = writer;
1445 @compileError("do not format objects directly");
1446}
1447
1448pub fn fmtSymtab(self: *Object, elf_file: *Elf) std.fmt.Formatter(formatSymtab) {
1435pub fn fmtSymtab(self: *Object, elf_file: *Elf) std.fmt.Formatter(Format, Format.symtab) {
14491436 return .{ .data = .{
14501437 .object = self,
14511438 .elf_file = elf_file,
14521439 } };
14531440}
14541441
1455const FormatContext = struct {
1442const Format = struct {
14561443 object: *Object,
14571444 elf_file: *Elf,
1458};
14591445
1460fn formatSymtab(
1461 ctx: FormatContext,
1462 comptime unused_fmt_string: []const u8,
1463 options: std.fmt.FormatOptions,
1464 writer: anytype,
1465) !void {
1466 _ = unused_fmt_string;
1467 _ = options;
1468 const object = ctx.object;
1469 const elf_file = ctx.elf_file;
1470 try writer.writeAll(" locals\n");
1471 for (object.locals()) |sym| {
1472 try writer.print(" {}\n", .{sym.fmt(elf_file)});
1446 fn symtab(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
1447 const object = f.object;
1448 const elf_file = f.elf_file;
1449 try writer.writeAll(" locals\n");
1450 for (object.locals()) |sym| {
1451 try writer.print(" {}\n", .{sym.fmt(elf_file)});
1452 }
1453 try writer.writeAll(" globals\n");
1454 for (object.globals(), 0..) |sym, i| {
1455 const first_global = object.first_global.?;
1456 const ref = object.resolveSymbol(@intCast(i + first_global), elf_file);
1457 if (elf_file.symbol(ref)) |ref_sym| {
1458 try writer.print(" {}\n", .{ref_sym.fmt(elf_file)});
1459 } else {
1460 try writer.print(" {s} : unclaimed\n", .{sym.name(elf_file)});
1461 }
1462 }
14731463 }
1474 try writer.writeAll(" globals\n");
1475 for (object.globals(), 0..) |sym, i| {
1476 const first_global = object.first_global.?;
1477 const ref = object.resolveSymbol(@intCast(i + first_global), elf_file);
1478 if (elf_file.symbol(ref)) |ref_sym| {
1479 try writer.print(" {}\n", .{ref_sym.fmt(elf_file)});
1480 } else {
1481 try writer.print(" {s} : unclaimed\n", .{sym.name(elf_file)});
1464
1465 fn atoms(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
1466 const object = f.object;
1467 try writer.writeAll(" atoms\n");
1468 for (object.atoms_indexes.items) |atom_index| {
1469 const atom_ptr = object.atom(atom_index) orelse continue;
1470 try writer.print(" {}\n", .{atom_ptr.fmt(f.elf_file)});
1471 }
1472 }
1473
1474 fn cies(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
1475 const object = f.object;
1476 try writer.writeAll(" cies\n");
1477 for (object.cies.items, 0..) |cie, i| {
1478 try writer.print(" cie({d}) : {}\n", .{ i, cie.fmt(f.elf_file) });
14821479 }
14831480 }
1484}
14851481
1486pub fn fmtAtoms(self: *Object, elf_file: *Elf) std.fmt.Formatter(formatAtoms) {
1482 fn fdes(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
1483 const object = f.object;
1484 try writer.writeAll(" fdes\n");
1485 for (object.fdes.items, 0..) |fde, i| {
1486 try writer.print(" fde({d}) : {}\n", .{ i, fde.fmt(f.elf_file) });
1487 }
1488 }
1489
1490 fn groups(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
1491 const object = f.object;
1492 const elf_file = f.elf_file;
1493 try writer.writeAll(" groups\n");
1494 for (object.groups.items, 0..) |g, g_index| {
1495 try writer.print(" {s}({d})", .{ if (g.is_comdat) "COMDAT" else "GROUP", g_index });
1496 if (!g.alive) try writer.writeAll(" : [*]");
1497 try writer.writeByte('\n');
1498 const g_members = g.members(elf_file);
1499 for (g_members) |shndx| {
1500 const atom_index = object.atoms_indexes.items[shndx];
1501 const atom_ptr = object.atom(atom_index) orelse continue;
1502 try writer.print(" atom({d}) : {s}\n", .{ atom_index, atom_ptr.name(elf_file) });
1503 }
1504 }
1505 }
1506};
1507
1508pub fn fmtAtoms(self: *Object, elf_file: *Elf) std.fmt.Formatter(Format, Format.atoms) {
14871509 return .{ .data = .{
14881510 .object = self,
14891511 .elf_file = elf_file,
14901512 } };
14911513}
14921514
1493fn formatAtoms(
1494 ctx: FormatContext,
1495 comptime unused_fmt_string: []const u8,
1496 options: std.fmt.FormatOptions,
1497 writer: anytype,
1498) !void {
1499 _ = unused_fmt_string;
1500 _ = options;
1501 const object = ctx.object;
1502 try writer.writeAll(" atoms\n");
1503 for (object.atoms_indexes.items) |atom_index| {
1504 const atom_ptr = object.atom(atom_index) orelse continue;
1505 try writer.print(" {}\n", .{atom_ptr.fmt(ctx.elf_file)});
1506 }
1507}
1508
1509pub fn fmtCies(self: *Object, elf_file: *Elf) std.fmt.Formatter(formatCies) {
1515pub fn fmtCies(self: *Object, elf_file: *Elf) std.fmt.Formatter(Format, Format.cies) {
15101516 return .{ .data = .{
15111517 .object = self,
15121518 .elf_file = elf_file,
15131519 } };
15141520}
15151521
1516fn formatCies(
1517 ctx: FormatContext,
1518 comptime unused_fmt_string: []const u8,
1519 options: std.fmt.FormatOptions,
1520 writer: anytype,
1521) !void {
1522 _ = unused_fmt_string;
1523 _ = options;
1524 const object = ctx.object;
1525 try writer.writeAll(" cies\n");
1526 for (object.cies.items, 0..) |cie, i| {
1527 try writer.print(" cie({d}) : {}\n", .{ i, cie.fmt(ctx.elf_file) });
1528 }
1529}
1530
1531pub fn fmtFdes(self: *Object, elf_file: *Elf) std.fmt.Formatter(formatFdes) {
1522pub fn fmtFdes(self: *Object, elf_file: *Elf) std.fmt.Formatter(Format, Format.fdes) {
15321523 return .{ .data = .{
15331524 .object = self,
15341525 .elf_file = elf_file,
15351526 } };
15361527}
15371528
1538fn formatFdes(
1539 ctx: FormatContext,
1540 comptime unused_fmt_string: []const u8,
1541 options: std.fmt.FormatOptions,
1542 writer: anytype,
1543) !void {
1544 _ = unused_fmt_string;
1545 _ = options;
1546 const object = ctx.object;
1547 try writer.writeAll(" fdes\n");
1548 for (object.fdes.items, 0..) |fde, i| {
1549 try writer.print(" fde({d}) : {}\n", .{ i, fde.fmt(ctx.elf_file) });
1550 }
1551}
1552
1553pub fn fmtGroups(self: *Object, elf_file: *Elf) std.fmt.Formatter(formatGroups) {
1529pub fn fmtGroups(self: *Object, elf_file: *Elf) std.fmt.Formatter(Format, Format.groups) {
15541530 return .{ .data = .{
15551531 .object = self,
15561532 .elf_file = elf_file,
15571533 } };
15581534}
15591535
1560fn formatGroups(
1561 ctx: FormatContext,
1562 comptime unused_fmt_string: []const u8,
1563 options: std.fmt.FormatOptions,
1564 writer: anytype,
1565) !void {
1566 _ = unused_fmt_string;
1567 _ = options;
1568 const object = ctx.object;
1569 const elf_file = ctx.elf_file;
1570 try writer.writeAll(" groups\n");
1571 for (object.groups.items, 0..) |g, g_index| {
1572 try writer.print(" {s}({d})", .{ if (g.is_comdat) "COMDAT" else "GROUP", g_index });
1573 if (!g.alive) try writer.writeAll(" : [*]");
1574 try writer.writeByte('\n');
1575 const g_members = g.members(elf_file);
1576 for (g_members) |shndx| {
1577 const atom_index = object.atoms_indexes.items[shndx];
1578 const atom_ptr = object.atom(atom_index) orelse continue;
1579 try writer.print(" atom({d}) : {s}\n", .{ atom_index, atom_ptr.name(elf_file) });
1580 }
1581 }
1582}
1583
1584pub fn fmtPath(self: Object) std.fmt.Formatter(formatPath) {
1536pub fn fmtPath(self: Object) std.fmt.Formatter(Object, formatPath) {
15851537 return .{ .data = self };
15861538}
15871539
1588fn formatPath(
1589 object: Object,
1590 comptime unused_fmt_string: []const u8,
1591 options: std.fmt.FormatOptions,
1592 writer: anytype,
1593) !void {
1594 _ = unused_fmt_string;
1595 _ = options;
1540fn formatPath(object: Object, writer: *std.io.Writer) std.io.Writer.Error!void {
15961541 if (object.archive) |ar| {
15971542 try writer.print("{}({})", .{ ar.path, object.path });
15981543 } else {
src/link/Elf/SharedObject.zig+5-25
......@@ -509,41 +509,21 @@ pub fn setSymbolExtra(self: *SharedObject, index: u32, extra: Symbol.Extra) void
509509 }
510510}
511511
512pub fn format(
513 self: SharedObject,
514 comptime unused_fmt_string: []const u8,
515 options: std.fmt.FormatOptions,
516 writer: anytype,
517) !void {
518 _ = self;
519 _ = unused_fmt_string;
520 _ = options;
521 _ = writer;
522 @compileError("unreachable");
523}
524
525pub fn fmtSymtab(self: SharedObject, elf_file: *Elf) std.fmt.Formatter(formatSymtab) {
512pub fn fmtSymtab(self: SharedObject, elf_file: *Elf) std.fmt.Formatter(Format, Format.symtab) {
526513 return .{ .data = .{
527514 .shared = self,
528515 .elf_file = elf_file,
529516 } };
530517}
531518
532const FormatContext = struct {
519const Format = struct {
533520 shared: SharedObject,
534521 elf_file: *Elf,
535522};
536523
537fn formatSymtab(
538 ctx: FormatContext,
539 comptime unused_fmt_string: []const u8,
540 options: std.fmt.FormatOptions,
541 writer: anytype,
542) !void {
543 _ = unused_fmt_string;
544 _ = options;
545 const shared = ctx.shared;
546 const elf_file = ctx.elf_file;
524fn formatSymtab(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
525 const shared = f.shared;
526 const elf_file = f.elf_file;
547527 try writer.writeAll(" globals\n");
548528 for (shared.symbols.items, 0..) |sym, i| {
549529 const ref = shared.resolveSymbol(@intCast(i), elf_file);
src/link/Elf/Symbol.zig+50-77
......@@ -316,99 +316,72 @@ pub fn setOutputSym(symbol: Symbol, elf_file: *Elf, out: *elf.Elf64_Sym) void {
316316 out.st_size = esym.st_size;
317317}
318318
319pub fn format(
320 symbol: Symbol,
321 comptime unused_fmt_string: []const u8,
322 options: std.fmt.FormatOptions,
323 writer: anytype,
324) !void {
325 _ = symbol;
326 _ = unused_fmt_string;
327 _ = options;
328 _ = writer;
329 @compileError("do not format Symbol directly");
330}
331
332const FormatContext = struct {
319const Format = struct {
333320 symbol: Symbol,
334321 elf_file: *Elf,
322
323 fn name(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
324 const elf_file = f.elf_file;
325 const symbol = f.symbol;
326 try writer.writeAll(symbol.name(elf_file));
327 switch (symbol.version_index.VERSION) {
328 @intFromEnum(elf.VER_NDX.LOCAL), @intFromEnum(elf.VER_NDX.GLOBAL) => {},
329 else => {
330 const file_ptr = symbol.file(elf_file).?;
331 assert(file_ptr == .shared_object);
332 const shared_object = file_ptr.shared_object;
333 try writer.print("@{s}", .{shared_object.versionString(symbol.version_index)});
334 },
335 }
336 }
337
338 fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
339 const symbol = f.symbol;
340 const elf_file = f.elf_file;
341 try writer.print("%{d} : {s} : @{x}", .{
342 symbol.esym_index,
343 symbol.fmtName(elf_file),
344 symbol.address(.{ .plt = false, .trampoline = false }, elf_file),
345 });
346 if (symbol.file(elf_file)) |file_ptr| {
347 if (symbol.isAbs(elf_file)) {
348 if (symbol.elfSym(elf_file).st_shndx == elf.SHN_UNDEF) {
349 try writer.writeAll(" : undef");
350 } else {
351 try writer.writeAll(" : absolute");
352 }
353 } else if (symbol.outputShndx(elf_file)) |shndx| {
354 try writer.print(" : shdr({d})", .{shndx});
355 }
356 if (symbol.atom(elf_file)) |atom_ptr| {
357 try writer.print(" : atom({d})", .{atom_ptr.atom_index});
358 }
359 var buf: [2]u8 = .{'_'} ** 2;
360 if (symbol.flags.@"export") buf[0] = 'E';
361 if (symbol.flags.import) buf[1] = 'I';
362 try writer.print(" : {s}", .{&buf});
363 if (symbol.flags.weak) try writer.writeAll(" : weak");
364 switch (file_ptr) {
365 inline else => |x| try writer.print(" : {s}({d})", .{ @tagName(file_ptr), x.index }),
366 }
367 } else try writer.writeAll(" : unresolved");
368 }
335369};
336370
337pub fn fmtName(symbol: Symbol, elf_file: *Elf) std.fmt.Formatter(formatName) {
371pub fn fmtName(symbol: Symbol, elf_file: *Elf) std.fmt.Formatter(Format, Format.name) {
338372 return .{ .data = .{
339373 .symbol = symbol,
340374 .elf_file = elf_file,
341375 } };
342376}
343377
344fn formatName(
345 ctx: FormatContext,
346 comptime unused_fmt_string: []const u8,
347 options: std.fmt.FormatOptions,
348 writer: anytype,
349) !void {
350 _ = options;
351 _ = unused_fmt_string;
352 const elf_file = ctx.elf_file;
353 const symbol = ctx.symbol;
354 try writer.writeAll(symbol.name(elf_file));
355 switch (symbol.version_index.VERSION) {
356 @intFromEnum(elf.VER_NDX.LOCAL), @intFromEnum(elf.VER_NDX.GLOBAL) => {},
357 else => {
358 const file_ptr = symbol.file(elf_file).?;
359 assert(file_ptr == .shared_object);
360 const shared_object = file_ptr.shared_object;
361 try writer.print("@{s}", .{shared_object.versionString(symbol.version_index)});
362 },
363 }
364}
365
366pub fn fmt(symbol: Symbol, elf_file: *Elf) std.fmt.Formatter(format2) {
378pub fn fmt(symbol: Symbol, elf_file: *Elf) std.fmt.Formatter(Format, Format.default) {
367379 return .{ .data = .{
368380 .symbol = symbol,
369381 .elf_file = elf_file,
370382 } };
371383}
372384
373fn format2(
374 ctx: FormatContext,
375 comptime unused_fmt_string: []const u8,
376 options: std.fmt.FormatOptions,
377 writer: anytype,
378) !void {
379 _ = options;
380 _ = unused_fmt_string;
381 const symbol = ctx.symbol;
382 const elf_file = ctx.elf_file;
383 try writer.print("%{d} : {s} : @{x}", .{
384 symbol.esym_index,
385 symbol.fmtName(elf_file),
386 symbol.address(.{ .plt = false, .trampoline = false }, elf_file),
387 });
388 if (symbol.file(elf_file)) |file_ptr| {
389 if (symbol.isAbs(elf_file)) {
390 if (symbol.elfSym(elf_file).st_shndx == elf.SHN_UNDEF) {
391 try writer.writeAll(" : undef");
392 } else {
393 try writer.writeAll(" : absolute");
394 }
395 } else if (symbol.outputShndx(elf_file)) |shndx| {
396 try writer.print(" : shdr({d})", .{shndx});
397 }
398 if (symbol.atom(elf_file)) |atom_ptr| {
399 try writer.print(" : atom({d})", .{atom_ptr.atom_index});
400 }
401 var buf: [2]u8 = .{'_'} ** 2;
402 if (symbol.flags.@"export") buf[0] = 'E';
403 if (symbol.flags.import) buf[1] = 'I';
404 try writer.print(" : {s}", .{&buf});
405 if (symbol.flags.weak) try writer.writeAll(" : weak");
406 switch (file_ptr) {
407 inline else => |x| try writer.print(" : {s}({d})", .{ @tagName(file_ptr), x.index }),
408 }
409 } else try writer.writeAll(" : unresolved");
410}
411
412385pub const Flags = packed struct {
413386 /// Whether the symbol is imported at runtime.
414387 import: bool = false,
src/link/Elf/Thunk.zig+11-31
......@@ -65,47 +65,27 @@ fn trampolineSize(cpu_arch: std.Target.Cpu.Arch) usize {
6565 };
6666}
6767
68pub fn format(
69 thunk: Thunk,
70 comptime unused_fmt_string: []const u8,
71 options: std.fmt.FormatOptions,
72 writer: anytype,
73) !void {
74 _ = thunk;
75 _ = unused_fmt_string;
76 _ = options;
77 _ = writer;
78 @compileError("do not format Thunk directly");
79}
80
81pub fn fmt(thunk: Thunk, elf_file: *Elf) std.fmt.Formatter(format2) {
68pub fn fmt(thunk: Thunk, elf_file: *Elf) std.fmt.Formatter(Format, Format.default) {
8269 return .{ .data = .{
8370 .thunk = thunk,
8471 .elf_file = elf_file,
8572 } };
8673}
8774
88const FormatContext = struct {
75const Format = struct {
8976 thunk: Thunk,
9077 elf_file: *Elf,
91};
9278
93fn format2(
94 ctx: FormatContext,
95 comptime unused_fmt_string: []const u8,
96 options: std.fmt.FormatOptions,
97 writer: anytype,
98) !void {
99 _ = options;
100 _ = unused_fmt_string;
101 const thunk = ctx.thunk;
102 const elf_file = ctx.elf_file;
103 try writer.print("@{x} : size({x})\n", .{ thunk.value, thunk.size(elf_file) });
104 for (thunk.symbols.keys()) |ref| {
105 const sym = elf_file.symbol(ref).?;
106 try writer.print(" {} : {s} : @{x}\n", .{ ref, sym.name(elf_file), sym.value });
79 fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
80 const thunk = f.thunk;
81 const elf_file = f.elf_file;
82 try writer.print("@{x} : size({x})\n", .{ thunk.value, thunk.size(elf_file) });
83 for (thunk.symbols.keys()) |ref| {
84 const sym = elf_file.symbol(ref).?;
85 try writer.print(" {} : {s} : @{x}\n", .{ ref, sym.name(elf_file), sym.value });
86 }
10787 }
108}
88};
10989
11090pub const Index = u32;
11191
src/link/Elf/ZigObject.zig+28-42
......@@ -2195,60 +2195,46 @@ pub fn setSymbolExtra(self: *ZigObject, index: u32, extra: Symbol.Extra) void {
21952195 }
21962196}
21972197
2198pub fn fmtSymtab(self: *ZigObject, elf_file: *Elf) std.fmt.Formatter(formatSymtab) {
2199 return .{ .data = .{
2200 .self = self,
2201 .elf_file = elf_file,
2202 } };
2203}
2204
2205const FormatContext = struct {
2198const Format = struct {
22062199 self: *ZigObject,
22072200 elf_file: *Elf,
2208};
22092201
2210fn formatSymtab(
2211 ctx: FormatContext,
2212 comptime unused_fmt_string: []const u8,
2213 options: std.fmt.FormatOptions,
2214 writer: anytype,
2215) !void {
2216 _ = unused_fmt_string;
2217 _ = options;
2218 const self = ctx.self;
2219 const elf_file = ctx.elf_file;
2220 try writer.writeAll(" locals\n");
2221 for (self.local_symbols.items) |index| {
2222 const local = self.symbols.items[index];
2223 try writer.print(" {}\n", .{local.fmt(elf_file)});
2202 fn symtab(f: Format, writer: *std.io.Writer.Error) std.io.Writer.Error!void {
2203 const self = f.self;
2204 const elf_file = f.elf_file;
2205 try writer.writeAll(" locals\n");
2206 for (self.local_symbols.items) |index| {
2207 const local = self.symbols.items[index];
2208 try writer.print(" {f}\n", .{local.fmt(elf_file)});
2209 }
2210 try writer.writeAll(" globals\n");
2211 for (f.self.global_symbols.items) |index| {
2212 const global = self.symbols.items[index];
2213 try writer.print(" {f}\n", .{global.fmt(elf_file)});
2214 }
22242215 }
2225 try writer.writeAll(" globals\n");
2226 for (ctx.self.global_symbols.items) |index| {
2227 const global = self.symbols.items[index];
2228 try writer.print(" {}\n", .{global.fmt(elf_file)});
2216
2217 fn atoms(f: Format, writer: *std.io.Writer.Error) std.io.Writer.Error!void {
2218 try writer.writeAll(" atoms\n");
2219 for (f.self.atoms_indexes.items) |atom_index| {
2220 const atom_ptr = f.self.atom(atom_index) orelse continue;
2221 try writer.print(" {f}\n", .{atom_ptr.fmt(f.elf_file)});
2222 }
22292223 }
2230}
2224};
22312225
2232pub fn fmtAtoms(self: *ZigObject, elf_file: *Elf) std.fmt.Formatter(formatAtoms) {
2226pub fn fmtSymtab(self: *ZigObject, elf_file: *Elf) std.fmt.Formatter(Format, Format.symtab) {
22332227 return .{ .data = .{
22342228 .self = self,
22352229 .elf_file = elf_file,
22362230 } };
22372231}
22382232
2239fn formatAtoms(
2240 ctx: FormatContext,
2241 comptime unused_fmt_string: []const u8,
2242 options: std.fmt.FormatOptions,
2243 writer: anytype,
2244) !void {
2245 _ = unused_fmt_string;
2246 _ = options;
2247 try writer.writeAll(" atoms\n");
2248 for (ctx.self.atoms_indexes.items) |atom_index| {
2249 const atom_ptr = ctx.self.atom(atom_index) orelse continue;
2250 try writer.print(" {}\n", .{atom_ptr.fmt(ctx.elf_file)});
2251 }
2233pub fn fmtAtoms(self: *ZigObject, elf_file: *Elf) std.fmt.Formatter(Format, Format.atoms) {
2234 return .{ .data = .{
2235 .self = self,
2236 .elf_file = elf_file,
2237 } };
22522238}
22532239
22542240const ElfSym = struct {
src/link/Elf/eh_frame.zig+30-70
......@@ -47,52 +47,32 @@ pub const Fde = struct {
4747 return object.relocs.items[fde.rel_index..][0..fde.rel_num];
4848 }
4949
50 pub fn format(
51 fde: Fde,
52 comptime unused_fmt_string: []const u8,
53 options: std.fmt.FormatOptions,
54 writer: anytype,
55 ) !void {
56 _ = fde;
57 _ = unused_fmt_string;
58 _ = options;
59 _ = writer;
60 @compileError("do not format FDEs directly");
61 }
62
63 pub fn fmt(fde: Fde, elf_file: *Elf) std.fmt.Formatter(format2) {
50 pub fn fmt(fde: Fde, elf_file: *Elf) std.fmt.Formatter(Format, Format.default) {
6451 return .{ .data = .{
6552 .fde = fde,
6653 .elf_file = elf_file,
6754 } };
6855 }
6956
70 const FdeFormatContext = struct {
57 const Format = struct {
7158 fde: Fde,
7259 elf_file: *Elf,
73 };
7460
75 fn format2(
76 ctx: FdeFormatContext,
77 comptime unused_fmt_string: []const u8,
78 options: std.fmt.FormatOptions,
79 writer: anytype,
80 ) !void {
81 _ = unused_fmt_string;
82 _ = options;
83 const fde = ctx.fde;
84 const elf_file = ctx.elf_file;
85 const base_addr = fde.address(elf_file);
86 const object = elf_file.file(fde.file_index).?.object;
87 const atom_name = fde.atom(object).name(elf_file);
88 try writer.print("@{x} : size({x}) : cie({d}) : {s}", .{
89 base_addr + fde.out_offset,
90 fde.calcSize(),
91 fde.cie_index,
92 atom_name,
93 });
94 if (!fde.alive) try writer.writeAll(" : [*]");
95 }
61 fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
62 const fde = f.fde;
63 const elf_file = f.elf_file;
64 const base_addr = fde.address(elf_file);
65 const object = elf_file.file(fde.file_index).?.object;
66 const atom_name = fde.atom(object).name(elf_file);
67 try writer.print("@{x} : size({x}) : cie({d}) : {s}", .{
68 base_addr + fde.out_offset,
69 fde.calcSize(),
70 fde.cie_index,
71 atom_name,
72 });
73 if (!fde.alive) try writer.writeAll(" : [*]");
74 }
75 };
9676};
9777
9878pub const Cie = struct {
......@@ -150,48 +130,28 @@ pub const Cie = struct {
150130 return true;
151131 }
152132
153 pub fn format(
154 cie: Cie,
155 comptime unused_fmt_string: []const u8,
156 options: std.fmt.FormatOptions,
157 writer: anytype,
158 ) !void {
159 _ = cie;
160 _ = unused_fmt_string;
161 _ = options;
162 _ = writer;
163 @compileError("do not format CIEs directly");
164 }
165
166 pub fn fmt(cie: Cie, elf_file: *Elf) std.fmt.Formatter(format2) {
133 pub fn fmt(cie: Cie, elf_file: *Elf) std.fmt.Formatter(Format, Format.default) {
167134 return .{ .data = .{
168135 .cie = cie,
169136 .elf_file = elf_file,
170137 } };
171138 }
172139
173 const CieFormatContext = struct {
140 const Format = struct {
174141 cie: Cie,
175142 elf_file: *Elf,
176 };
177143
178 fn format2(
179 ctx: CieFormatContext,
180 comptime unused_fmt_string: []const u8,
181 options: std.fmt.FormatOptions,
182 writer: anytype,
183 ) !void {
184 _ = unused_fmt_string;
185 _ = options;
186 const cie = ctx.cie;
187 const elf_file = ctx.elf_file;
188 const base_addr = cie.address(elf_file);
189 try writer.print("@{x} : size({x})", .{
190 base_addr + cie.out_offset,
191 cie.calcSize(),
192 });
193 if (!cie.alive) try writer.writeAll(" : [*]");
194 }
144 fn format2(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
145 const cie = f.cie;
146 const elf_file = f.elf_file;
147 const base_addr = cie.address(elf_file);
148 try writer.print("@{x} : size({x})", .{
149 base_addr + cie.out_offset,
150 cie.calcSize(),
151 });
152 if (!cie.alive) try writer.writeAll(" : [*]");
153 }
154 };
195155};
196156
197157pub const Iterator = struct {
src/link/Elf/file.zig+4-11
......@@ -10,23 +10,16 @@ pub const File = union(enum) {
1010 };
1111 }
1212
13 pub fn fmtPath(file: File) std.fmt.Formatter(formatPath) {
13 pub fn fmtPath(file: File) std.fmt.Formatter(File, formatPath) {
1414 return .{ .data = file };
1515 }
1616
17 fn formatPath(
18 file: File,
19 comptime unused_fmt_string: []const u8,
20 options: std.fmt.FormatOptions,
21 writer: anytype,
22 ) !void {
23 _ = unused_fmt_string;
24 _ = options;
17 fn formatPath(file: File, writer: *std.io.Writer) std.io.Writer.Error!void {
2518 switch (file) {
2619 .zig_object => |zo| try writer.writeAll(zo.basename),
2720 .linker_defined => try writer.writeAll("(linker defined)"),
28 .object => |x| try writer.print("{}", .{x.fmtPath()}),
29 .shared_object => |x| try writer.print("{}", .{@as(Path, x.path)}),
21 .object => |x| try writer.print("{f}", .{x.fmtPath()}),
22 .shared_object => |x| try writer.print("{f}", .{@as(Path, x.path)}),
3023 }
3124 }
3225
src/link/Elf/relocation.zig+2-9
......@@ -141,21 +141,14 @@ const FormatRelocTypeCtx = struct {
141141 cpu_arch: std.Target.Cpu.Arch,
142142};
143143
144pub fn fmtRelocType(r_type: u32, cpu_arch: std.Target.Cpu.Arch) std.fmt.Formatter(formatRelocType) {
144pub fn fmtRelocType(r_type: u32, cpu_arch: std.Target.Cpu.Arch) std.fmt.Formatter(FormatRelocTypeCtx, formatRelocType) {
145145 return .{ .data = .{
146146 .r_type = r_type,
147147 .cpu_arch = cpu_arch,
148148 } };
149149}
150150
151fn formatRelocType(
152 ctx: FormatRelocTypeCtx,
153 comptime unused_fmt_string: []const u8,
154 options: std.fmt.FormatOptions,
155 writer: anytype,
156) !void {
157 _ = unused_fmt_string;
158 _ = options;
151fn formatRelocType(ctx: FormatRelocTypeCtx, writer: *std.io.Writer) std.io.Writer.Error!void {
159152 const r_type = ctx.r_type;
160153 switch (ctx.cpu_arch) {
161154 .x86_64 => try writer.print("R_X86_64_{s}", .{@tagName(@as(elf.R_X86_64, @enumFromInt(r_type)))}),
src/link/Elf/synthetic_sections.zig+36-50
......@@ -606,37 +606,30 @@ pub const GotSection = struct {
606606 }
607607 }
608608
609 const FormatCtx = struct {
609 const Format = struct {
610610 got: GotSection,
611611 elf_file: *Elf,
612
613 pub fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
614 const got = f.got;
615 const elf_file = f.elf_file;
616 try writer.writeAll("GOT\n");
617 for (got.entries.items) |entry| {
618 const symbol = elf_file.symbol(entry.ref).?;
619 try writer.print(" {d}@0x{x} => {}@0x{x} ({s})\n", .{
620 entry.cell_index,
621 entry.address(elf_file),
622 entry.ref,
623 symbol.address(.{}, elf_file),
624 symbol.name(elf_file),
625 });
626 }
627 }
612628 };
613629
614 pub fn fmt(got: GotSection, elf_file: *Elf) std.fmt.Formatter(format2) {
630 pub fn fmt(got: GotSection, elf_file: *Elf) std.fmt.Formatter(Format, Format.default) {
615631 return .{ .data = .{ .got = got, .elf_file = elf_file } };
616632 }
617
618 pub fn format2(
619 ctx: FormatCtx,
620 comptime unused_fmt_string: []const u8,
621 options: std.fmt.FormatOptions,
622 writer: anytype,
623 ) !void {
624 _ = options;
625 _ = unused_fmt_string;
626 const got = ctx.got;
627 const elf_file = ctx.elf_file;
628 try writer.writeAll("GOT\n");
629 for (got.entries.items) |entry| {
630 const symbol = elf_file.symbol(entry.ref).?;
631 try writer.print(" {d}@0x{x} => {}@0x{x} ({s})\n", .{
632 entry.cell_index,
633 entry.address(elf_file),
634 entry.ref,
635 symbol.address(.{}, elf_file),
636 symbol.name(elf_file),
637 });
638 }
639 }
640633};
641634
642635pub const PltSection = struct {
......@@ -749,38 +742,31 @@ pub const PltSection = struct {
749742 }
750743 }
751744
752 const FormatCtx = struct {
745 const Format = struct {
753746 plt: PltSection,
754747 elf_file: *Elf,
748
749 pub fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
750 const plt = f.plt;
751 const elf_file = f.elf_file;
752 try writer.writeAll("PLT\n");
753 for (plt.symbols.items, 0..) |ref, i| {
754 const symbol = elf_file.symbol(ref).?;
755 try writer.print(" {d}@0x{x} => {}@0x{x} ({s})\n", .{
756 i,
757 symbol.pltAddress(elf_file),
758 ref,
759 symbol.address(.{}, elf_file),
760 symbol.name(elf_file),
761 });
762 }
763 }
755764 };
756765
757 pub fn fmt(plt: PltSection, elf_file: *Elf) std.fmt.Formatter(format2) {
766 pub fn fmt(plt: PltSection, elf_file: *Elf) std.fmt.Formatter(Format, Format.default) {
758767 return .{ .data = .{ .plt = plt, .elf_file = elf_file } };
759768 }
760769
761 pub fn format2(
762 ctx: FormatCtx,
763 comptime unused_fmt_string: []const u8,
764 options: std.fmt.FormatOptions,
765 writer: anytype,
766 ) !void {
767 _ = options;
768 _ = unused_fmt_string;
769 const plt = ctx.plt;
770 const elf_file = ctx.elf_file;
771 try writer.writeAll("PLT\n");
772 for (plt.symbols.items, 0..) |ref, i| {
773 const symbol = elf_file.symbol(ref).?;
774 try writer.print(" {d}@0x{x} => {}@0x{x} ({s})\n", .{
775 i,
776 symbol.pltAddress(elf_file),
777 ref,
778 symbol.address(.{}, elf_file),
779 symbol.name(elf_file),
780 });
781 }
782 }
783
784770 const x86_64 = struct {
785771 fn write(plt: PltSection, elf_file: *Elf, writer: anytype) !void {
786772 const shdrs = elf_file.sections.items(.shdr);
src/link/Lld.zig+2-2
......@@ -1649,7 +1649,7 @@ fn spawnLld(
16491649 child.stderr_behavior = .Pipe;
16501650
16511651 child.spawn() catch |err| break :term err;
1652 stderr = try child.stderr.?.reader().readAllAlloc(comp.gpa, std.math.maxInt(usize));
1652 stderr = try child.stderr.?.deprecatedReader().readAllAlloc(comp.gpa, std.math.maxInt(usize));
16531653 break :term child.wait();
16541654 }) catch |first_err| term: {
16551655 const err = switch (first_err) {
......@@ -1697,7 +1697,7 @@ fn spawnLld(
16971697 rsp_child.stderr_behavior = .Pipe;
16981698
16991699 rsp_child.spawn() catch |err| break :err err;
1700 stderr = try rsp_child.stderr.?.reader().readAllAlloc(comp.gpa, std.math.maxInt(usize));
1700 stderr = try rsp_child.stderr.?.deprecatedReader().readAllAlloc(comp.gpa, std.math.maxInt(usize));
17011701 break :term rsp_child.wait() catch |err| break :err err;
17021702 }
17031703 },
src/link/MachO/Object.zig+2-2
......@@ -2552,7 +2552,7 @@ const Format = struct {
25522552 }
25532553 }
25542554
2555 fn formatSymtab(f: Format, w: *Writer) Writer.Error!void {
2555 fn symtab(f: Format, w: *Writer) Writer.Error!void {
25562556 const object = f.object;
25572557 const macho_file = f.macho_file;
25582558 try w.writeAll(" symbols\n");
......@@ -2695,7 +2695,7 @@ const StabFile = struct {
26952695 };
26962696
26972697 pub fn fmt(stab: Stab, object: Object) std.fmt.Formatter(Stab.Format, Stab.Format.default) {
2698 return .{ .data = .{ stab, object } };
2698 return .{ .data = .{ .stab = stab, .object = object } };
26992699 }
27002700 };
27012701};
src/link/MachO/Relocation.zig+1-1
......@@ -71,7 +71,7 @@ pub fn lessThan(ctx: void, lhs: Relocation, rhs: Relocation) bool {
7171}
7272
7373pub fn fmtPretty(rel: Relocation, cpu_arch: std.Target.Cpu.Arch) std.fmt.Formatter(Format, Format.pretty) {
74 return .{ .data = .{ rel, cpu_arch } };
74 return .{ .data = .{ .relocation = rel, .arch = cpu_arch } };
7575}
7676
7777const Format = struct {
src/link/MachO/eh_frame.zig+14-34
......@@ -211,49 +211,29 @@ pub const Fde = struct {
211211 return fde.getObject(macho_file).getAtom(fde.lsda);
212212 }
213213
214 pub fn format(
215 fde: Fde,
216 comptime unused_fmt_string: []const u8,
217 options: std.fmt.FormatOptions,
218 writer: anytype,
219 ) !void {
220 _ = fde;
221 _ = unused_fmt_string;
222 _ = options;
223 _ = writer;
224 @compileError("do not format FDEs directly");
225 }
226
227 pub fn fmt(fde: Fde, macho_file: *MachO) std.fmt.Formatter(format2) {
214 pub fn fmt(fde: Fde, macho_file: *MachO) std.fmt.Formatter(Format, Format.default) {
228215 return .{ .data = .{
229216 .fde = fde,
230217 .macho_file = macho_file,
231218 } };
232219 }
233220
234 const FormatContext = struct {
221 const Format = struct {
235222 fde: Fde,
236223 macho_file: *MachO,
237 };
238224
239 fn format2(
240 ctx: FormatContext,
241 comptime unused_fmt_string: []const u8,
242 options: std.fmt.FormatOptions,
243 writer: anytype,
244 ) !void {
245 _ = unused_fmt_string;
246 _ = options;
247 const fde = ctx.fde;
248 const macho_file = ctx.macho_file;
249 try writer.print("@{x} : size({x}) : cie({d}) : {s}", .{
250 fde.offset,
251 fde.getSize(),
252 fde.cie,
253 fde.getAtom(macho_file).getName(macho_file),
254 });
255 if (!fde.alive) try writer.writeAll(" : [*]");
256 }
225 fn default(f: Format, writer: *Writer) Writer.Error!void {
226 const fde = f.fde;
227 const macho_file = f.macho_file;
228 try writer.print("@{x} : size({x}) : cie({d}) : {s}", .{
229 fde.offset,
230 fde.getSize(),
231 fde.cie,
232 fde.getAtom(macho_file).getName(macho_file),
233 });
234 if (!fde.alive) try writer.writeAll(" : [*]");
235 }
236 };
257237
258238 pub const Index = u32;
259239};
src/print_value.zig+9-23
......@@ -20,15 +20,8 @@ pub const FormatContext = struct {
2020 depth: u8,
2121};
2222
23pub fn formatSema(
24 ctx: FormatContext,
25 comptime fmt: []const u8,
26 options: std.fmt.FormatOptions,
27 writer: anytype,
28) !void {
29 _ = options;
23pub fn formatSema(ctx: FormatContext, writer: *std.io.Writer) std.io.Writer.Error!void {
3024 const sema = ctx.opt_sema.?;
31 comptime std.debug.assert(fmt.len == 0);
3225 return print(ctx.val, writer, ctx.depth, ctx.pt, sema) catch |err| switch (err) {
3326 error.OutOfMemory => @panic("OOM"), // We're not allowed to return this from a format function
3427 error.ComptimeBreak, error.ComptimeReturn => unreachable,
......@@ -37,15 +30,8 @@ pub fn formatSema(
3730 };
3831}
3932
40pub fn format(
41 ctx: FormatContext,
42 comptime fmt: []const u8,
43 options: std.fmt.FormatOptions,
44 writer: anytype,
45) !void {
46 _ = options;
33pub fn format(ctx: FormatContext, writer: *std.io.Writer) std.io.Writer.Error!void {
4734 std.debug.assert(ctx.opt_sema == null);
48 comptime std.debug.assert(fmt.len == 0);
4935 return print(ctx.val, writer, ctx.depth, ctx.pt, null) catch |err| switch (err) {
5036 error.OutOfMemory => @panic("OOM"), // We're not allowed to return this from a format function
5137 error.ComptimeBreak, error.ComptimeReturn, error.AnalysisFail => unreachable,
......@@ -55,11 +41,11 @@ pub fn format(
5541
5642pub fn print(
5743 val: Value,
58 writer: anytype,
44 writer: *std.io.Writer,
5945 level: u8,
6046 pt: Zcu.PerThread,
6147 opt_sema: ?*Sema,
62) (@TypeOf(writer).Error || Zcu.CompileError)!void {
48) (std.io.Writer.Error || Zcu.CompileError)!void {
6349 const zcu = pt.zcu;
6450 const ip = &zcu.intern_pool;
6551 switch (ip.indexToKey(val.toIntern())) {
......@@ -197,11 +183,11 @@ fn printAggregate(
197183 val: Value,
198184 aggregate: InternPool.Key.Aggregate,
199185 is_ref: bool,
200 writer: anytype,
186 writer: *std.io.Writer,
201187 level: u8,
202188 pt: Zcu.PerThread,
203189 opt_sema: ?*Sema,
204) (@TypeOf(writer).Error || Zcu.CompileError)!void {
190) (std.io.Writer.Error || Zcu.CompileError)!void {
205191 if (level == 0) {
206192 if (is_ref) try writer.writeByte('&');
207193 return writer.writeAll(".{ ... }");
......@@ -283,11 +269,11 @@ fn printPtr(
283269 ptr_val: Value,
284270 /// Whether to print `derivation` as an lvalue or rvalue. If `null`, the more concise option is chosen.
285271 want_kind: ?PrintPtrKind,
286 writer: anytype,
272 writer: *std.io.Writer,
287273 level: u8,
288274 pt: Zcu.PerThread,
289275 opt_sema: ?*Sema,
290) (@TypeOf(writer).Error || Zcu.CompileError)!void {
276) (std.io.Writer.Error || Zcu.CompileError)!void {
291277 const ptr = switch (pt.zcu.intern_pool.indexToKey(ptr_val.toIntern())) {
292278 .undef => return writer.writeAll("undefined"),
293279 .ptr => |ptr| ptr,
......@@ -329,7 +315,7 @@ const PrintPtrKind = enum { lvalue, rvalue };
329315/// Returns the root derivation, which may be ignored.
330316pub fn printPtrDerivation(
331317 derivation: Value.PointerDeriveStep,
332 writer: anytype,
318 writer: *std.io.Writer,
333319 pt: Zcu.PerThread,
334320 /// Whether to print `derivation` as an lvalue or rvalue. If `null`, the more concise option is chosen.
335321 /// If this is `.rvalue`, the result may look like `&foo`, so it's not necessarily valid to treat it as