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 {...@@ -542,15 +542,15 @@ const MsgWriter = struct {
542 }542 }
543543
544 pub fn print(m: *MsgWriter, comptime fmt: []const u8, args: anytype) void {544 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 {};
546 }546 }
547547
548 fn write(m: *MsgWriter, msg: []const u8) void {548 fn write(m: *MsgWriter, msg: []const u8) void {
549 m.w.writer().writeAll(msg) catch {};549 m.w.interface.writeAll(msg) catch {};
550 }550 }
551551
552 fn setColor(m: *MsgWriter, color: std.io.tty.Color) void {552 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 {};
554 }554 }
555555
556 fn location(m: *MsgWriter, path: []const u8, line: u32, col: u32) void {556 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...@@ -6012,9 +6012,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
60126012
6013 // In .rc files, a " within a quoted string is escaped as ""6013 // In .rc files, a " within a quoted string is escaped as ""
6014 const fmtRcEscape = struct {6014 const fmtRcEscape = struct {
6015 fn formatRcEscape(bytes: []const u8, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {6015 fn formatRcEscape(bytes: []const u8, writer: *std.io.Writer) std.io.Writer.Error!void {
6016 _ = fmt;
6017 _ = options;
6018 for (bytes) |byte| switch (byte) {6016 for (bytes) |byte| switch (byte) {
6019 '"' => try writer.writeAll("\"\""),6017 '"' => try writer.writeAll("\"\""),
6020 '\\' => try writer.writeAll("\\\\"),6018 '\\' => try writer.writeAll("\\\\"),
...@@ -6022,7 +6020,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32...@@ -6022,7 +6020,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
6022 };6020 };
6023 }6021 }
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) {
6026 return .{ .data = bytes };6024 return .{ .data = bytes };
6027 }6025 }
6028 }.fmtRcEscape;6026 }.fmtRcEscape;
src/Type.zig+10-25
...@@ -121,15 +121,14 @@ pub fn eql(a: Type, b: Type, zcu: *const Zcu) bool {...@@ -121,15 +121,14 @@ pub fn eql(a: Type, b: Type, zcu: *const Zcu) bool {
121 return a.toIntern() == b.toIntern();121 return a.toIntern() == b.toIntern();
122}122}
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 {
125 _ = ty;125 _ = ty;
126 _ = unused_fmt_string;126 _ = unused_fmt_string;
127 _ = options;
128 _ = writer;127 _ = writer;
129 @compileError("do not format types directly; use either ty.fmtDebug() or ty.fmt()");128 @compileError("do not format types directly; use either ty.fmtDebug() or ty.fmt()");
130}129}
131130
132pub const Formatter = std.fmt.Formatter(format2);131pub const Formatter = std.fmt.Formatter(Format, Format.default);
133132
134pub fn fmt(ty: Type, pt: Zcu.PerThread) Formatter {133pub fn fmt(ty: Type, pt: Zcu.PerThread) Formatter {
135 return .{ .data = .{134 return .{ .data = .{
...@@ -138,42 +137,28 @@ pub fn fmt(ty: Type, pt: Zcu.PerThread) Formatter {...@@ -138,42 +137,28 @@ pub fn fmt(ty: Type, pt: Zcu.PerThread) Formatter {
138 } };137 } };
139}138}
140139
141const FormatContext = struct {140const Format = struct {
142 ty: Type,141 ty: Type,
143 pt: Zcu.PerThread,142 pt: Zcu.PerThread,
144};
145143
146fn format2(144 fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
147 ctx: FormatContext,145 return print(f.ty, writer, f.pt);
148 comptime unused_format_string: []const u8,146 }
149 options: std.fmt.FormatOptions,147};
150 writer: anytype,
151) !void {
152 comptime assert(unused_format_string.len == 0);
153 _ = options;
154 return print(ctx.ty, writer, ctx.pt);
155}
156148
157pub fn fmtDebug(ty: Type) std.fmt.Formatter(dump) {149pub fn fmtDebug(ty: Type) std.fmt.Formatter(Type, dump) {
158 return .{ .data = ty };150 return .{ .data = ty };
159}151}
160152
161/// This is a debug function. In order to print types in a meaningful way153/// This is a debug function. In order to print types in a meaningful way
162/// we also need access to the module.154/// we also need access to the module.
163pub fn dump(155pub fn dump(start_type: Type, writer: *std.io.Writer) std.io.Writer.Error!void {
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);
171 return writer.print("{any}", .{start_type.ip_index});156 return writer.print("{any}", .{start_type.ip_index});
172}157}
173158
174/// Prints a name suitable for `@typeName`.159/// Prints a name suitable for `@typeName`.
175/// TODO: take an `opt_sema` to pass to `fmtValue` when printing sentinels.160/// 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 {
177 const zcu = pt.zcu;162 const zcu = pt.zcu;
178 const ip = &zcu.intern_pool;163 const ip = &zcu.intern_pool;
179 switch (ip.indexToKey(ty.toIntern())) {164 switch (ip.indexToKey(ty.toIntern())) {
src/Value.zig+8-15
...@@ -15,31 +15,24 @@ const Value = @This();...@@ -15,31 +15,24 @@ const Value = @This();
1515
16ip_index: InternPool.Index,16ip_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 {
19 _ = val;19 _ = val;
20 _ = fmt;
21 _ = options;
22 _ = writer;20 _ = writer;
21 _ = fmt;
23 @compileError("do not use format values directly; use either fmtDebug or fmtValue");22 @compileError("do not use format values directly; use either fmtDebug or fmtValue");
24}23}
2524
26/// This is a debug function. In order to print values in a meaningful way25/// This is a debug function. In order to print values in a meaningful way
27/// we also need access to the type.26/// we also need access to the type.
28pub fn dump(27pub fn dump(start_val: Value, w: std.io.Writer) std.io.Writer.Error!void {
29 start_val: Value,28 try w.print("(interned: {})", .{start_val.toIntern()});
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()});
36}29}
3730
38pub fn fmtDebug(val: Value) std.fmt.Formatter(dump) {31pub fn fmtDebug(val: Value) std.fmt.Formatter(Value, dump) {
39 return .{ .data = val };32 return .{ .data = val };
40}33}
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) {
43 return .{ .data = .{36 return .{ .data = .{
44 .val = val,37 .val = val,
45 .pt = pt,38 .pt = pt,
...@@ -48,7 +41,7 @@ pub fn fmtValue(val: Value, pt: Zcu.PerThread) std.fmt.Formatter(print_value.for...@@ -48,7 +41,7 @@ pub fn fmtValue(val: Value, pt: Zcu.PerThread) std.fmt.Formatter(print_value.for
48 } };41 } };
49}42}
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) {
52 return .{ .data = .{45 return .{ .data = .{
53 .val = val,46 .val = val,
54 .pt = pt,47 .pt = pt,
...@@ -57,7 +50,7 @@ pub fn fmtValueSema(val: Value, pt: Zcu.PerThread, sema: *Sema) std.fmt.Formatte...@@ -57,7 +50,7 @@ pub fn fmtValueSema(val: Value, pt: Zcu.PerThread, sema: *Sema) std.fmt.Formatte
57 } };50 } };
58}51}
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) {
61 return .{ .data = ctx };54 return .{ .data = ctx };
62}55}
6356
src/arch/riscv64/CodeGen.zig+16-32
...@@ -937,12 +937,7 @@ const FormatWipMirData = struct {...@@ -937,12 +937,7 @@ const FormatWipMirData = struct {
937 func: *Func,937 func: *Func,
938 inst: Mir.Inst.Index,938 inst: Mir.Inst.Index,
939};939};
940fn formatWipMir(940fn formatWipMir(data: FormatWipMirData, writer: *std.io.Writer) std.io.Writer.Error!void {
941 data: FormatWipMirData,
942 comptime _: []const u8,
943 _: std.fmt.FormatOptions,
944 writer: anytype,
945) @TypeOf(writer).Error!void {
946 const pt = data.func.pt;941 const pt = data.func.pt;
947 const comp = pt.zcu.comp;942 const comp = pt.zcu.comp;
948 var lower: Lower = .{943 var lower: Lower = .{
...@@ -982,7 +977,7 @@ fn formatWipMir(...@@ -982,7 +977,7 @@ fn formatWipMir(
982 first = false;977 first = false;
983 }978 }
984}979}
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) {
986 return .{ .data = .{ .func = func, .inst = inst } };981 return .{ .data = .{ .func = func, .inst = inst } };
987}982}
988983
...@@ -990,15 +985,10 @@ const FormatNavData = struct {...@@ -990,15 +985,10 @@ const FormatNavData = struct {
990 ip: *const InternPool,985 ip: *const InternPool,
991 nav_index: InternPool.Nav.Index,986 nav_index: InternPool.Nav.Index,
992};987};
993fn formatNav(988fn formatNav(data: FormatNavData, writer: *std.io.Writer) std.io.Writer.Error!void {
994 data: FormatNavData,989 try writer.print("{f}", .{data.ip.getNav(data.nav_index).fqn.fmt(data.ip)});
995 comptime _: []const u8,990}
996 _: std.fmt.FormatOptions,991fn fmtNav(nav_index: InternPool.Nav.Index, ip: *const InternPool) std.fmt.Formatter(FormatNavData, formatNav) {
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) {
1002 return .{ .data = .{992 return .{ .data = .{
1003 .ip = ip,993 .ip = ip,
1004 .nav_index = nav_index,994 .nav_index = nav_index,
...@@ -1009,31 +999,25 @@ const FormatAirData = struct {...@@ -1009,31 +999,25 @@ const FormatAirData = struct {
1009 func: *Func,999 func: *Func,
1010 inst: Air.Inst.Index,1000 inst: Air.Inst.Index,
1011};1001};
1012fn formatAir(1002fn formatAir(data: FormatAirData, writer: *std.io.Writer) std.io.Writer.Error!void {
1013 data: FormatAirData,1003 // Not acceptable implementation because it ignores `writer`:
1014 comptime _: []const u8,1004 //data.func.air.dumpInst(data.inst, data.func.pt, data.func.liveness);
1015 _: std.fmt.FormatOptions,1005 _ = data;
1016 writer: anytype,1006 _ = writer;
1017) @TypeOf(writer).Error!void {1007 @panic("unimplemented");
1018 data.func.air.dumpInst(data.inst, data.func.pt, data.func.liveness);1008}
1019}1009fn fmtAir(func: *Func, inst: Air.Inst.Index) std.fmt.Formatter(FormatAirData, formatAir) {
1020fn fmtAir(func: *Func, inst: Air.Inst.Index) std.fmt.Formatter(formatAir) {
1021 return .{ .data = .{ .func = func, .inst = inst } };1010 return .{ .data = .{ .func = func, .inst = inst } };
1022}1011}
10231012
1024const FormatTrackingData = struct {1013const FormatTrackingData = struct {
1025 func: *Func,1014 func: *Func,
1026};1015};
1027fn formatTracking(1016fn formatTracking(data: FormatTrackingData, writer: *std.io.Writer) std.io.Writer.Error!void {
1028 data: FormatTrackingData,
1029 comptime _: []const u8,
1030 _: std.fmt.FormatOptions,
1031 writer: anytype,
1032) @TypeOf(writer).Error!void {
1033 var it = data.func.inst_tracking.iterator();1017 var it = data.func.inst_tracking.iterator();
1034 while (it.next()) |entry| try writer.print("\n%{d} = {}", .{ entry.key_ptr.*, entry.value_ptr.* });1018 while (it.next()) |entry| try writer.print("\n%{d} = {}", .{ entry.key_ptr.*, entry.value_ptr.* });
1035}1019}
1036fn fmtTracking(func: *Func) std.fmt.Formatter(formatTracking) {1020fn fmtTracking(func: *Func) std.fmt.Formatter(FormatTrackingData, formatTracking) {
1037 return .{ .data = .{ .func = func } };1021 return .{ .data = .{ .func = func } };
1038}1022}
10391023
src/arch/x86_64/CodeGen.zig+208-233
...@@ -6,6 +6,7 @@ const log = std.log.scoped(.codegen);...@@ -6,6 +6,7 @@ const log = std.log.scoped(.codegen);
6const tracking_log = std.log.scoped(.tracking);6const tracking_log = std.log.scoped(.tracking);
7const verbose_tracking_log = std.log.scoped(.verbose_tracking);7const verbose_tracking_log = std.log.scoped(.verbose_tracking);
8const wip_mir_log = std.log.scoped(.wip_mir);8const wip_mir_log = std.log.scoped(.wip_mir);
9const Writer = std.io.Writer;
910
10const Air = @import("../../Air.zig");11const Air = @import("../../Air.zig");
11const Allocator = std.mem.Allocator;12const Allocator = std.mem.Allocator;
...@@ -524,52 +525,47 @@ pub const MCValue = union(enum) {...@@ -524,52 +525,47 @@ pub const MCValue = union(enum) {
524 };525 };
525 }526 }
526527
527 pub fn format(528 pub fn format(mcv: MCValue, bw: *Writer, comptime _: []const u8) Writer.Error!void {
528 mcv: MCValue,
529 comptime _: []const u8,
530 _: std.fmt.FormatOptions,
531 writer: anytype,
532 ) @TypeOf(writer).Error!void {
533 switch (mcv) {529 switch (mcv) {
534 .none, .unreach, .dead, .undef => try writer.print("({s})", .{@tagName(mcv)}),530 .none, .unreach, .dead, .undef => try bw.print("({s})", .{@tagName(mcv)}),
535 .immediate => |pl| try writer.print("0x{x}", .{pl}),531 .immediate => |pl| try bw.print("0x{x}", .{pl}),
536 .memory => |pl| try writer.print("[ds:0x{x}]", .{pl}),532 .memory => |pl| try bw.print("[ds:0x{x}]", .{pl}),
537 inline .eflags, .register => |pl| try writer.print("{s}", .{@tagName(pl)}),533 inline .eflags, .register => |pl| try bw.print("{s}", .{@tagName(pl)}),
538 .register_pair => |pl| try writer.print("{s}:{s}", .{ @tagName(pl[1]), @tagName(pl[0]) }),534 .register_pair => |pl| try bw.print("{s}:{s}", .{ @tagName(pl[1]), @tagName(pl[0]) }),
539 .register_triple => |pl| try writer.print("{s}:{s}:{s}", .{535 .register_triple => |pl| try bw.print("{s}:{s}:{s}", .{
540 @tagName(pl[2]), @tagName(pl[1]), @tagName(pl[0]),536 @tagName(pl[2]), @tagName(pl[1]), @tagName(pl[0]),
541 }),537 }),
542 .register_quadruple => |pl| try writer.print("{s}:{s}:{s}:{s}", .{538 .register_quadruple => |pl| try bw.print("{s}:{s}:{s}:{s}", .{
543 @tagName(pl[3]), @tagName(pl[2]), @tagName(pl[1]), @tagName(pl[0]),539 @tagName(pl[3]), @tagName(pl[2]), @tagName(pl[1]), @tagName(pl[0]),
544 }),540 }),
545 .register_offset => |pl| try writer.print("{s} + 0x{x}", .{ @tagName(pl.reg), pl.off }),541 .register_offset => |pl| try bw.print("{s} + 0x{x}", .{ @tagName(pl.reg), pl.off }),
546 .register_overflow => |pl| try writer.print("{s}:{s}", .{542 .register_overflow => |pl| try bw.print("{s}:{s}", .{
547 @tagName(pl.eflags),543 @tagName(pl.eflags),
548 @tagName(pl.reg),544 @tagName(pl.reg),
549 }),545 }),
550 .register_mask => |pl| try writer.print("mask({s},{}):{c}{s}", .{546 .register_mask => |pl| try bw.print("mask({s},{f}):{c}{s}", .{
551 @tagName(pl.info.kind),547 @tagName(pl.info.kind),
552 pl.info.scalar,548 pl.info.scalar,
553 @as(u8, if (pl.info.inverted) '!' else ' '),549 @as(u8, if (pl.info.inverted) '!' else ' '),
554 @tagName(pl.reg),550 @tagName(pl.reg),
555 }),551 }),
556 .indirect => |pl| try writer.print("[{s} + 0x{x}]", .{ @tagName(pl.reg), pl.off }),552 .indirect => |pl| try bw.print("[{s} + 0x{x}]", .{ @tagName(pl.reg), pl.off }),
557 .indirect_load_frame => |pl| try writer.print("[[{} + 0x{x}]]", .{ pl.index, pl.off }),553 .indirect_load_frame => |pl| try bw.print("[[{} + 0x{x}]]", .{ pl.index, pl.off }),
558 .load_frame => |pl| try writer.print("[{} + 0x{x}]", .{ pl.index, pl.off }),554 .load_frame => |pl| try bw.print("[{} + 0x{x}]", .{ pl.index, pl.off }),
559 .lea_frame => |pl| try writer.print("{} + 0x{x}", .{ pl.index, pl.off }),555 .lea_frame => |pl| try bw.print("{} + 0x{x}", .{ pl.index, pl.off }),
560 .load_nav => |pl| try writer.print("[nav:{d}]", .{@intFromEnum(pl)}),556 .load_nav => |pl| try bw.print("[nav:{d}]", .{@intFromEnum(pl)}),
561 .lea_nav => |pl| try writer.print("nav:{d}", .{@intFromEnum(pl)}),557 .lea_nav => |pl| try bw.print("nav:{d}", .{@intFromEnum(pl)}),
562 .load_uav => |pl| try writer.print("[uav:{d}]", .{@intFromEnum(pl.val)}),558 .load_uav => |pl| try bw.print("[uav:{d}]", .{@intFromEnum(pl.val)}),
563 .lea_uav => |pl| try writer.print("uav:{d}", .{@intFromEnum(pl.val)}),559 .lea_uav => |pl| try bw.print("uav:{d}", .{@intFromEnum(pl.val)}),
564 .load_lazy_sym => |pl| try writer.print("[lazy:{s}:{d}]", .{ @tagName(pl.kind), @intFromEnum(pl.ty) }),560 .load_lazy_sym => |pl| try bw.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) }),561 .lea_lazy_sym => |pl| try bw.print("lazy:{s}:{d}", .{ @tagName(pl.kind), @intFromEnum(pl.ty) }),
566 .load_extern_func => |pl| try writer.print("[extern:{d}]", .{@intFromEnum(pl)}),562 .load_extern_func => |pl| try bw.print("[extern:{d}]", .{@intFromEnum(pl)}),
567 .lea_extern_func => |pl| try writer.print("extern:{d}", .{@intFromEnum(pl)}),563 .lea_extern_func => |pl| try bw.print("extern:{d}", .{@intFromEnum(pl)}),
568 .elementwise_args => |pl| try writer.print("elementwise:{d}:[{} + 0x{x}]", .{564 .elementwise_args => |pl| try bw.print("elementwise:{d}:[{} + 0x{x}]", .{
569 pl.regs, pl.frame_index, pl.frame_off,565 pl.regs, pl.frame_index, pl.frame_off,
570 }),566 }),
571 .reserved_frame => |pl| try writer.print("(dead:{})", .{pl}),567 .reserved_frame => |pl| try bw.print("(dead:{})", .{pl}),
572 .air_ref => |pl| try writer.print("(air:0x{x})", .{@intFromEnum(pl)}),568 .air_ref => |pl| try bw.print("(air:0x{x})", .{@intFromEnum(pl)}),
573 }569 }
574 }570 }
575};571};
...@@ -639,7 +635,7 @@ const InstTracking = struct {...@@ -639,7 +635,7 @@ const InstTracking = struct {
639 .reserved_frame => |index| self.long = .{ .load_frame = .{ .index = index } },635 .reserved_frame => |index| self.long = .{ .load_frame = .{ .index = index } },
640 else => unreachable,636 else => unreachable,
641 }637 }
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 });
643 try cg.genCopy(cg.typeOfIndex(inst), self.long, self.short, .{});639 try cg.genCopy(cg.typeOfIndex(inst), self.long, self.short, .{});
644 for (self.short.getRegs()) |reg| if (reg.isClass(.x87)) try cg.asmRegister(.{ .f_, .free }, reg);640 for (self.short.getRegs()) |reg| if (reg.isClass(.x87)) try cg.asmRegister(.{ .f_, .free }, reg);
645 }641 }
...@@ -672,7 +668,7 @@ const InstTracking = struct {...@@ -672,7 +668,7 @@ const InstTracking = struct {
672 else => {}, // TODO process stack allocation death668 else => {}, // TODO process stack allocation death
673 }669 }
674 self.reuseFrame();670 self.reuseFrame();
675 tracking_log.debug("{} => {} (spilled)", .{ inst, self.* });671 tracking_log.debug("{f} => {f} (spilled)", .{ inst, self.* });
676 }672 }
677673
678 fn verifyMaterialize(self: InstTracking, target: InstTracking) void {674 fn verifyMaterialize(self: InstTracking, target: InstTracking) void {
...@@ -749,7 +745,7 @@ const InstTracking = struct {...@@ -749,7 +745,7 @@ const InstTracking = struct {
749 else => target.long,745 else => target.long,
750 } else target.long;746 } else target.long;
751 self.short = target.short;747 self.short = target.short;
752 tracking_log.debug("{} => {} (materialize)", .{ inst, self.* });748 tracking_log.debug("{f} => {f} (materialize)", .{ inst, self.* });
753 }749 }
754750
755 fn resurrect(self: *InstTracking, function: *CodeGen, inst: Air.Inst.Index, scope_generation: u32) !void {751 fn resurrect(self: *InstTracking, function: *CodeGen, inst: Air.Inst.Index, scope_generation: u32) !void {
...@@ -757,7 +753,7 @@ const InstTracking = struct {...@@ -757,7 +753,7 @@ const InstTracking = struct {
757 .dead => |die_generation| if (die_generation >= scope_generation) {753 .dead => |die_generation| if (die_generation >= scope_generation) {
758 self.reuseFrame();754 self.reuseFrame();
759 try function.getValue(self.short, inst);755 try function.getValue(self.short, inst);
760 tracking_log.debug("{} => {} (resurrect)", .{ inst, self.* });756 tracking_log.debug("{f} => {f} (resurrect)", .{ inst, self.* });
761 },757 },
762 else => {},758 else => {},
763 }759 }
...@@ -768,7 +764,7 @@ const InstTracking = struct {...@@ -768,7 +764,7 @@ const InstTracking = struct {
768 try function.freeValue(self.short, opts);764 try function.freeValue(self.short, opts);
769 if (self.long == .none) self.long = self.short;765 if (self.long == .none) self.long = self.short;
770 self.short = .{ .dead = function.scope_generation };766 self.short = .{ .dead = function.scope_generation };
771 tracking_log.debug("{} => {} (death)", .{ inst, self.* });767 tracking_log.debug("{f} => {f} (death)", .{ inst, self.* });
772 }768 }
773769
774 fn reuse(770 fn reuse(
...@@ -778,13 +774,13 @@ const InstTracking = struct {...@@ -778,13 +774,13 @@ const InstTracking = struct {
778 old_inst: Air.Inst.Index,774 old_inst: Air.Inst.Index,
779 ) void {775 ) void {
780 self.short = .{ .dead = function.scope_generation };776 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 });
782 }778 }
783779
784 fn liveOut(self: *InstTracking, function: *CodeGen, inst: Air.Inst.Index) void {780 fn liveOut(self: *InstTracking, function: *CodeGen, inst: Air.Inst.Index) void {
785 for (self.getRegs()) |reg| {781 for (self.getRegs()) |reg| {
786 if (function.register_manager.isRegFree(reg)) {782 if (function.register_manager.isRegFree(reg)) {
787 tracking_log.debug("{} => {} (live-out)", .{ inst, self.* });783 tracking_log.debug("{f} => {f} (live-out)", .{ inst, self.* });
788 continue;784 continue;
789 }785 }
790786
...@@ -812,18 +808,13 @@ const InstTracking = struct {...@@ -812,18 +808,13 @@ const InstTracking = struct {
812 // Perform side-effects of freeValue manually.808 // Perform side-effects of freeValue manually.
813 function.register_manager.freeReg(reg);809 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 });
816 }812 }
817 }813 }
818814
819 pub fn format(815 pub fn format(tracking: InstTracking, bw: *Writer, comptime _: []const u8) Writer.Error!void {
820 tracking: InstTracking,816 if (!std.meta.eql(tracking.long, tracking.short)) try bw.print("|{f}| ", .{tracking.long});
821 comptime _: []const u8,817 try bw.print("{f}", .{tracking.short});
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});
827 }818 }
828};819};
829820
...@@ -939,7 +930,7 @@ pub fn generate(...@@ -939,7 +930,7 @@ pub fn generate(
939 function.inst_tracking.putAssumeCapacityNoClobber(temp.toIndex(), .init(.none));930 function.inst_tracking.putAssumeCapacityNoClobber(temp.toIndex(), .init(.none));
940 }931 }
941932
942 wip_mir_log.debug("{}:", .{fmtNav(func.owner_nav, ip)});933 wip_mir_log.debug("{f}:", .{fmtNav(func.owner_nav, ip)});
943934
944 try function.frame_allocs.resize(gpa, FrameIndex.named_count);935 try function.frame_allocs.resize(gpa, FrameIndex.named_count);
945 function.frame_allocs.set(936 function.frame_allocs.set(
...@@ -1097,15 +1088,10 @@ const FormatNavData = struct {...@@ -1097,15 +1088,10 @@ const FormatNavData = struct {
1097 ip: *const InternPool,1088 ip: *const InternPool,
1098 nav_index: InternPool.Nav.Index,1089 nav_index: InternPool.Nav.Index,
1099};1090};
1100fn formatNav(1091fn formatNav(data: FormatNavData, w: *Writer) Writer.Error!void {
1101 data: FormatNavData,1092 try w.print("{f}", .{data.ip.getNav(data.nav_index).fqn.fmt(data.ip)});
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)});
1107}1093}
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) {
1109 return .{ .data = .{1095 return .{ .data = .{
1110 .ip = ip,1096 .ip = ip,
1111 .nav_index = nav_index,1097 .nav_index = nav_index,
...@@ -1116,15 +1102,14 @@ const FormatAirData = struct {...@@ -1116,15 +1102,14 @@ const FormatAirData = struct {
1116 self: *CodeGen,1102 self: *CodeGen,
1117 inst: Air.Inst.Index,1103 inst: Air.Inst.Index,
1118};1104};
1119fn formatAir(1105fn formatAir(data: FormatAirData, w: *std.io.Writer) Writer.Error!void {
1120 data: FormatAirData,1106 // not acceptable implementation because it ignores `w`:
1121 comptime _: []const u8,1107 //data.self.air.dumpInst(data.inst, data.self.pt, data.self.liveness);
1122 _: std.fmt.FormatOptions,1108 _ = data;
1123 writer: anytype,1109 _ = w;
1124) @TypeOf(writer).Error!void {1110 @panic("TODO: unimplemented");
1125 data.self.air.dumpInst(data.inst, data.self.pt, data.self.liveness);
1126}1111}
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) {
1128 return .{ .data = .{ .self = self, .inst = inst } };1113 return .{ .data = .{ .self = self, .inst = inst } };
1129}1114}
11301115
...@@ -1132,12 +1117,7 @@ const FormatWipMirData = struct {...@@ -1132,12 +1117,7 @@ const FormatWipMirData = struct {
1132 self: *CodeGen,1117 self: *CodeGen,
1133 inst: Mir.Inst.Index,1118 inst: Mir.Inst.Index,
1134};1119};
1135fn formatWipMir(1120fn formatWipMir(data: FormatWipMirData, w: *Writer) Writer.Error!void {
1136 data: FormatWipMirData,
1137 comptime _: []const u8,
1138 _: std.fmt.FormatOptions,
1139 writer: anytype,
1140) @TypeOf(writer).Error!void {
1141 var lower: Lower = .{1121 var lower: Lower = .{
1142 .target = data.self.target,1122 .target = data.self.target,
1143 .allocator = data.self.gpa,1123 .allocator = data.self.gpa,
...@@ -1152,11 +1132,11 @@ fn formatWipMir(...@@ -1152,11 +1132,11 @@ fn formatWipMir(
1152 lower.err_msg.?.deinit(data.self.gpa);1132 lower.err_msg.?.deinit(data.self.gpa);
1153 lower.err_msg = null;1133 lower.err_msg = null;
1154 }1134 }
1155 try writer.writeAll(lower.err_msg.?.msg);1135 try w.writeAll(lower.err_msg.?.msg);
1156 return;1136 return;
1157 },1137 },
1158 error.OutOfMemory, error.InvalidInstruction, error.CannotEncode => |e| {1138 error.OutOfMemory, error.InvalidInstruction, error.CannotEncode => |e| {
1159 try writer.writeAll(switch (e) {1139 try w.writeAll(switch (e) {
1160 error.OutOfMemory => "Out of memory",1140 error.OutOfMemory => "Out of memory",
1161 error.InvalidInstruction => "CodeGen failed to find a viable instruction.",1141 error.InvalidInstruction => "CodeGen failed to find a viable instruction.",
1162 error.CannotEncode => "CodeGen failed to encode the instruction.",1142 error.CannotEncode => "CodeGen failed to encode the instruction.",
...@@ -1165,14 +1145,14 @@ fn formatWipMir(...@@ -1165,14 +1145,14 @@ fn formatWipMir(
1165 },1145 },
1166 else => |e| return e,1146 else => |e| return e,
1167 }).insts) |lowered_inst| {1147 }).insts) |lowered_inst| {
1168 if (!first) try writer.writeAll("\ndebug(wip_mir): ");1148 if (!first) try w.writeAll("\ndebug(wip_mir): ");
1169 try writer.print(" | {}", .{lowered_inst});1149 try w.print(" | {f}", .{lowered_inst});
1170 first = false;1150 first = false;
1171 }1151 }
1172 if (first) {1152 if (first) {
1173 const ip = &data.self.pt.zcu.intern_pool;1153 const ip = &data.self.pt.zcu.intern_pool;
1174 const mir_inst = lower.mir.instructions.get(data.inst);1154 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)});
1176 switch (mir_inst.ops) {1156 switch (mir_inst.ops) {
1177 else => unreachable,1157 else => unreachable,
1178 .pseudo_dbg_prologue_end_none,1158 .pseudo_dbg_prologue_end_none,
...@@ -1184,20 +1164,20 @@ fn formatWipMir(...@@ -1184,20 +1164,20 @@ fn formatWipMir(
1184 .pseudo_dbg_var_none,1164 .pseudo_dbg_var_none,
1185 .pseudo_dead_none,1165 .pseudo_dead_none,
1186 => {},1166 => {},
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(
1188 " {[line]d}, {[column]d}",1168 " {[line]d}, {[column]d}",
1189 mir_inst.data.line_column,1169 mir_inst.data.line_column,
1190 ),1170 ),
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}", .{
1192 ip.getNav(ip.indexToKey(mir_inst.data.ip_index).func.owner_nav).name.fmt(ip),1172 ip.getNav(ip.indexToKey(mir_inst.data.ip_index).func.owner_nav).name.fmt(ip),
1193 }),1173 }),
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}", .{
1195 @as(i32, @bitCast(mir_inst.data.i.i)),1175 @as(i32, @bitCast(mir_inst.data.i.i)),
1196 }),1176 }),
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}", .{
1198 mir_inst.data.i.i,1178 mir_inst.data.i.i,
1199 }),1179 }),
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}", .{
1201 mir_inst.data.i64,1181 mir_inst.data.i64,
1202 }),1182 }),
1203 .pseudo_dbg_arg_ro, .pseudo_dbg_var_ro => {1183 .pseudo_dbg_arg_ro, .pseudo_dbg_var_ro => {
...@@ -1205,44 +1185,39 @@ fn formatWipMir(...@@ -1205,44 +1185,39 @@ fn formatWipMir(
1205 .base = .{ .reg = mir_inst.data.ro.reg },1185 .base = .{ .reg = mir_inst.data.ro.reg },
1206 .disp = mir_inst.data.ro.off,1186 .disp = mir_inst.data.ro.off,
1207 }) };1187 }) };
1208 try writer.print(" {}", .{mem_op.fmt(.m)});1188 try w.print(" {f}", .{mem_op.fmt(.m)});
1209 },1189 },
1210 .pseudo_dbg_arg_fa, .pseudo_dbg_var_fa => {1190 .pseudo_dbg_arg_fa, .pseudo_dbg_var_fa => {
1211 const mem_op: encoder.Instruction.Operand = .{ .mem = .initSib(.qword, .{1191 const mem_op: encoder.Instruction.Operand = .{ .mem = .initSib(.qword, .{
1212 .base = .{ .frame = mir_inst.data.fa.index },1192 .base = .{ .frame = mir_inst.data.fa.index },
1213 .disp = mir_inst.data.fa.off,1193 .disp = mir_inst.data.fa.off,
1214 }) };1194 }) };
1215 try writer.print(" {}", .{mem_op.fmt(.m)});1195 try w.print(" {f}", .{mem_op.fmt(.m)});
1216 },1196 },
1217 .pseudo_dbg_arg_m, .pseudo_dbg_var_m => {1197 .pseudo_dbg_arg_m, .pseudo_dbg_var_m => {
1218 const mem_op: encoder.Instruction.Operand = .{1198 const mem_op: encoder.Instruction.Operand = .{
1219 .mem = lower.mir.extraData(Mir.Memory, mir_inst.data.x.payload).data.decode(),1199 .mem = lower.mir.extraData(Mir.Memory, mir_inst.data.x.payload).data.decode(),
1220 };1200 };
1221 try writer.print(" {}", .{mem_op.fmt(.m)});1201 try w.print(" {f}", .{mem_op.fmt(.m)});
1222 },1202 },
1223 .pseudo_dbg_arg_val, .pseudo_dbg_var_val => try writer.print(" {}", .{1203 .pseudo_dbg_arg_val, .pseudo_dbg_var_val => try w.print(" {}", .{
1224 Value.fromInterned(mir_inst.data.ip_index).fmtValue(data.self.pt),1204 Value.fromInterned(mir_inst.data.ip_index).fmtValue(data.self.pt),
1225 }),1205 }),
1226 }1206 }
1227 }1207 }
1228}1208}
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) {
1230 return .{ .data = .{ .self = self, .inst = inst } };1210 return .{ .data = .{ .self = self, .inst = inst } };
1231}1211}
12321212
1233const FormatTrackingData = struct {1213const FormatTrackingData = struct {
1234 self: *CodeGen,1214 self: *CodeGen,
1235};1215};
1236fn formatTracking(1216fn formatTracking(data: FormatTrackingData, w: *Writer) Writer.Error!void {
1237 data: FormatTrackingData,
1238 comptime _: []const u8,
1239 _: std.fmt.FormatOptions,
1240 writer: anytype,
1241) @TypeOf(writer).Error!void {
1242 var it = data.self.inst_tracking.iterator();1217 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.* });
1244}1219}
1245fn fmtTracking(self: *CodeGen) std.fmt.Formatter(formatTracking) {1220fn fmtTracking(self: *CodeGen) std.fmt.Formatter(FormatTrackingData, formatTracking) {
1246 return .{ .data = .{ .self = self } };1221 return .{ .data = .{ .self = self } };
1247}1222}
12481223
...@@ -1251,7 +1226,7 @@ fn addInst(self: *CodeGen, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {...@@ -1251,7 +1226,7 @@ fn addInst(self: *CodeGen, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {
1251 try self.mir_instructions.ensureUnusedCapacity(gpa, 1);1226 try self.mir_instructions.ensureUnusedCapacity(gpa, 1);
1252 const result_index: Mir.Inst.Index = @intCast(self.mir_instructions.len);1227 const result_index: Mir.Inst.Index = @intCast(self.mir_instructions.len);
1253 self.mir_instructions.appendAssumeCapacity(inst);1228 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)});
1255 return result_index;1230 return result_index;
1256}1231}
12571232
...@@ -2056,7 +2031,7 @@ fn gen(...@@ -2056,7 +2031,7 @@ fn gen(
2056 .{},2031 .{},
2057 );2032 );
2058 self.ret_mcv.long = .{ .load_frame = .{ .index = frame_index } };2033 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 });
2060 },2035 },
2061 else => unreachable,2036 else => unreachable,
2062 }2037 }
...@@ -2334,8 +2309,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -2334,8 +2309,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
23342309
2335 for (body) |inst| {2310 for (body) |inst| {
2336 if (cg.liveness.isUnused(inst) and !cg.air.mustLower(inst, ip)) continue;2311 if (cg.liveness.isUnused(inst) and !cg.air.mustLower(inst, ip)) continue;
2337 wip_mir_log.debug("{}", .{cg.fmtAir(inst)});2312 wip_mir_log.debug("{f}", .{cg.fmtAir(inst)});
2338 verbose_tracking_log.debug("{}", .{cg.fmtTracking()});2313 verbose_tracking_log.debug("{f}", .{cg.fmtTracking()});
23392314
2340 cg.reused_operands = .initEmpty();2315 cg.reused_operands = .initEmpty();
2341 try cg.inst_tracking.ensureUnusedCapacity(cg.gpa, 1);2316 try cg.inst_tracking.ensureUnusedCapacity(cg.gpa, 1);
...@@ -4339,7 +4314,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -4339,7 +4314,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
4339 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },4314 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },
4340 } },4315 } },
4341 } }) catch |err| switch (err) {4316 } }) 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}", .{
4343 @tagName(air_tag),4318 @tagName(air_tag),
4344 cg.typeOf(bin_op.lhs).fmt(pt),4319 cg.typeOf(bin_op.lhs).fmt(pt),
4345 ops[0].tracking(cg),4320 ops[0].tracking(cg),
...@@ -4351,7 +4326,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -4351,7 +4326,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
4351 else => unreachable,4326 else => unreachable,
4352 .add, .add_optimized => {},4327 .add, .add_optimized => {},
4353 .add_wrap => res[0].wrapInt(cg) catch |err| switch (err) {4328 .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}", .{
4355 @tagName(air_tag),4330 @tagName(air_tag),
4356 cg.typeOf(bin_op.lhs).fmt(pt),4331 cg.typeOf(bin_op.lhs).fmt(pt),
4357 res[0].tracking(cg),4332 res[0].tracking(cg),
...@@ -14947,7 +14922,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -14947,7 +14922,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
14947 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },14922 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },
14948 } },14923 } },
14949 } }) catch |err| switch (err) {14924 } }) 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}", .{
14951 @tagName(air_tag),14926 @tagName(air_tag),
14952 cg.typeOf(bin_op.lhs).fmt(pt),14927 cg.typeOf(bin_op.lhs).fmt(pt),
14953 ops[0].tracking(cg),14928 ops[0].tracking(cg),
...@@ -14959,7 +14934,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -14959,7 +14934,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
14959 else => unreachable,14934 else => unreachable,
14960 .sub, .sub_optimized => {},14935 .sub, .sub_optimized => {},
14961 .sub_wrap => res[0].wrapInt(cg) catch |err| switch (err) {14936 .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}", .{
14963 @tagName(air_tag),14938 @tagName(air_tag),
14964 cg.typeOf(bin_op.lhs).fmt(pt),14939 cg.typeOf(bin_op.lhs).fmt(pt),
14965 res[0].tracking(cg),14940 res[0].tracking(cg),
...@@ -24587,7 +24562,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -24587,7 +24562,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
24587 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },24562 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },
24588 } },24563 } },
24589 } }) catch |err| switch (err) {24564 } }) 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}", .{
24591 @tagName(air_tag),24566 @tagName(air_tag),
24592 ty.fmt(pt),24567 ty.fmt(pt),
24593 ops[0].tracking(cg),24568 ops[0].tracking(cg),
...@@ -27287,7 +27262,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -27287,7 +27262,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
27287 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },27262 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },
27288 } },27263 } },
27289 } }) catch |err| switch (err) {27264 } }) 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}", .{
27291 @tagName(air_tag),27266 @tagName(air_tag),
27292 ty.fmt(pt),27267 ty.fmt(pt),
27293 ops[0].tracking(cg),27268 ops[0].tracking(cg),
...@@ -27296,7 +27271,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -27296,7 +27271,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
27296 else => |e| return e,27271 else => |e| return e,
27297 };27272 };
27298 res[0].wrapInt(cg) catch |err| switch (err) {27273 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}", .{
27300 @tagName(air_tag),27275 @tagName(air_tag),
27301 cg.typeOf(bin_op.lhs).fmt(pt),27276 cg.typeOf(bin_op.lhs).fmt(pt),
27302 res[0].tracking(cg),27277 res[0].tracking(cg),
...@@ -33606,7 +33581,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -33606,7 +33581,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
33606 assert(air_tag == .div_exact);33581 assert(air_tag == .div_exact);
33607 res[0] = ops[0].divTruncInts(&ops[1], cg) catch |err| break :err err;33582 res[0] = ops[0].divTruncInts(&ops[1], cg) catch |err| break :err err;
33608 }) catch |err| switch (err) {33583 }) 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}", .{
33610 @tagName(air_tag),33585 @tagName(air_tag),
33611 ty.fmt(pt),33586 ty.fmt(pt),
33612 ops[0].tracking(cg),33587 ops[0].tracking(cg),
...@@ -34837,7 +34812,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -34837,7 +34812,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
34837 } }) else err: {34812 } }) else err: {
34838 res[0] = ops[0].divTruncInts(&ops[1], cg) catch |err| break :err err;34813 res[0] = ops[0].divTruncInts(&ops[1], cg) catch |err| break :err err;
34839 }) catch |err| switch (err) {34814 }) 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}", .{
34841 @tagName(air_tag),34816 @tagName(air_tag),
34842 ty.fmt(pt),34817 ty.fmt(pt),
34843 ops[0].tracking(cg),34818 ops[0].tracking(cg),
...@@ -36148,7 +36123,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -36148,7 +36123,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
36148 } },36123 } },
36149 } },36124 } },
36150 }) catch |err| switch (err) {36125 }) 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}", .{
36152 @tagName(air_tag),36127 @tagName(air_tag),
36153 cg.typeOf(bin_op.lhs).fmt(pt),36128 cg.typeOf(bin_op.lhs).fmt(pt),
36154 ops[0].tracking(cg),36129 ops[0].tracking(cg),
...@@ -37614,7 +37589,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -37614,7 +37589,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
37614 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },37589 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },
37615 } },37590 } },
37616 } })) catch |err| switch (err) {37591 } })) 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}", .{
37618 @tagName(air_tag),37593 @tagName(air_tag),
37619 ty.fmt(pt),37594 ty.fmt(pt),
37620 ops[0].tracking(cg),37595 ops[0].tracking(cg),
...@@ -39248,7 +39223,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -39248,7 +39223,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
39248 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },39223 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },
39249 } },39224 } },
39250 } }) catch |err| switch (err) {39225 } }) 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}", .{
39252 @tagName(air_tag),39227 @tagName(air_tag),
39253 cg.typeOf(bin_op.lhs).fmt(pt),39228 cg.typeOf(bin_op.lhs).fmt(pt),
39254 ops[0].tracking(cg),39229 ops[0].tracking(cg),
...@@ -42077,7 +42052,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -42077,7 +42052,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
42077 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },42052 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },
42078 } },42053 } },
42079 } }) catch |err| switch (err) {42054 } }) 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}", .{
42081 @tagName(air_tag),42056 @tagName(air_tag),
42082 cg.typeOf(bin_op.lhs).fmt(pt),42057 cg.typeOf(bin_op.lhs).fmt(pt),
42083 ops[0].tracking(cg),42058 ops[0].tracking(cg),
...@@ -42191,7 +42166,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -42191,7 +42166,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
42191 .{ ._, ._, .lea, .dst0p, .leai(.src0, .dst0), ._, ._ },42166 .{ ._, ._, .lea, .dst0p, .leai(.src0, .dst0), ._, ._ },
42192 } },42167 } },
42193 } }) catch |err| switch (err) {42168 } }) 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}", .{
42195 @tagName(air_tag),42170 @tagName(air_tag),
42196 cg.typeOf(bin_op.lhs).fmt(pt),42171 cg.typeOf(bin_op.lhs).fmt(pt),
42197 ops[0].tracking(cg),42172 ops[0].tracking(cg),
...@@ -42320,7 +42295,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -42320,7 +42295,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
42320 .{ ._, ._, .lea, .dst0p, .leai(.src0, .dst0), ._, ._ },42295 .{ ._, ._, .lea, .dst0p, .leai(.src0, .dst0), ._, ._ },
42321 } },42296 } },
42322 } }) catch |err| switch (err) {42297 } }) 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}", .{
42324 @tagName(air_tag),42299 @tagName(air_tag),
42325 cg.typeOf(bin_op.lhs).fmt(pt),42300 cg.typeOf(bin_op.lhs).fmt(pt),
42326 ops[0].tracking(cg),42301 ops[0].tracking(cg),
...@@ -46485,7 +46460,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -46485,7 +46460,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
46485 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },46460 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },
46486 } },46461 } },
46487 } }) catch |err| switch (err) {46462 } }) 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}", .{
46489 @tagName(air_tag),46464 @tagName(air_tag),
46490 cg.typeOf(bin_op.lhs).fmt(pt),46465 cg.typeOf(bin_op.lhs).fmt(pt),
46491 ops[0].tracking(cg),46466 ops[0].tracking(cg),
...@@ -50644,7 +50619,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -50644,7 +50619,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
50644 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },50619 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },
50645 } },50620 } },
50646 } }) catch |err| switch (err) {50621 } }) 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}", .{
50648 @tagName(air_tag),50623 @tagName(air_tag),
50649 cg.typeOf(bin_op.lhs).fmt(pt),50624 cg.typeOf(bin_op.lhs).fmt(pt),
50650 ops[0].tracking(cg),50625 ops[0].tracking(cg),
...@@ -51493,7 +51468,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -51493,7 +51468,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
51493 .{ ._, ._, .mov, .memad(.dst0q, .add_src0_size, -8), .tmp0q, ._, ._ },51468 .{ ._, ._, .mov, .memad(.dst0q, .add_src0_size, -8), .tmp0q, ._, ._ },
51494 } },51469 } },
51495 } }) catch |err| switch (err) {51470 } }) 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}", .{
51497 @tagName(air_tag),51472 @tagName(air_tag),
51498 ty_pl.ty.toType().fmt(pt),51473 ty_pl.ty.toType().fmt(pt),
51499 ops[0].tracking(cg),51474 ops[0].tracking(cg),
...@@ -52398,7 +52373,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -52398,7 +52373,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
52398 .{ ._, ._, .mov, .memad(.dst0q, .add_src0_size, -8), .tmp0q, ._, ._ },52373 .{ ._, ._, .mov, .memad(.dst0q, .add_src0_size, -8), .tmp0q, ._, ._ },
52399 } },52374 } },
52400 } }) catch |err| switch (err) {52375 } }) 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}", .{
52402 @tagName(air_tag),52377 @tagName(air_tag),
52403 ty_pl.ty.toType().fmt(pt),52378 ty_pl.ty.toType().fmt(pt),
52404 ops[0].tracking(cg),52379 ops[0].tracking(cg),
...@@ -55995,7 +55970,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -55995,7 +55970,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
55995 .{ ._, ._, .@"or", .tmp2q, .tmp1q, ._, ._ },55970 .{ ._, ._, .@"or", .tmp2q, .tmp1q, ._, ._ },
55996 } },55971 } },
55997 } }) catch |err| switch (err) {55972 } }) 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}", .{
55999 @tagName(air_tag),55974 @tagName(air_tag),
56000 ty_pl.ty.toType().fmt(pt),55975 ty_pl.ty.toType().fmt(pt),
56001 ops[0].tracking(cg),55976 ops[0].tracking(cg),
...@@ -59735,7 +59710,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -59735,7 +59710,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
59735 } },59710 } },
59736 } },59711 } },
59737 }) catch |err| switch (err) {59712 }) 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}", .{
59739 @tagName(air_tag),59714 @tagName(air_tag),
59740 cg.typeOf(bin_op.lhs).fmt(pt),59715 cg.typeOf(bin_op.lhs).fmt(pt),
59741 ops[0].tracking(cg),59716 ops[0].tracking(cg),
...@@ -60298,7 +60273,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -60298,7 +60273,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
60298 .{ ._, ._nz, .j, .@"0b", ._, ._, ._ },60273 .{ ._, ._nz, .j, .@"0b", ._, ._, ._ },
60299 } },60274 } },
60300 } }) catch |err| switch (err) {60275 } }) 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}", .{
60302 @tagName(air_tag),60277 @tagName(air_tag),
60303 cg.typeOf(bin_op.lhs).fmt(pt),60278 cg.typeOf(bin_op.lhs).fmt(pt),
60304 cg.typeOf(bin_op.rhs).fmt(pt),60279 cg.typeOf(bin_op.rhs).fmt(pt),
...@@ -60660,7 +60635,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -60660,7 +60635,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
60660 .{ ._, ._ns, .j, .@"0b", ._, ._, ._ },60635 .{ ._, ._ns, .j, .@"0b", ._, ._, ._ },
60661 } },60636 } },
60662 } }) catch |err| switch (err) {60637 } }) 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}", .{
60664 @tagName(air_tag),60639 @tagName(air_tag),
60665 cg.typeOf(bin_op.lhs).fmt(pt),60640 cg.typeOf(bin_op.lhs).fmt(pt),
60666 cg.typeOf(bin_op.rhs).fmt(pt),60641 cg.typeOf(bin_op.rhs).fmt(pt),
...@@ -60672,7 +60647,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -60672,7 +60647,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
60672 switch (air_tag) {60647 switch (air_tag) {
60673 else => unreachable,60648 else => unreachable,
60674 .shl => res[0].wrapInt(cg) catch |err| switch (err) {60649 .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}", .{
60676 @tagName(air_tag),60651 @tagName(air_tag),
60677 cg.typeOf(bin_op.lhs).fmt(pt),60652 cg.typeOf(bin_op.lhs).fmt(pt),
60678 res[0].tracking(cg),60653 res[0].tracking(cg),
...@@ -65329,7 +65304,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -65329,7 +65304,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
65329 .{ ._, ._b, .j, .@"0b", ._, ._, ._ },65304 .{ ._, ._b, .j, .@"0b", ._, ._, ._ },
65330 } },65305 } },
65331 } }) catch |err| switch (err) {65306 } }) 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}", .{
65333 @tagName(air_tag),65308 @tagName(air_tag),
65334 ty_op.ty.toType().fmt(pt),65309 ty_op.ty.toType().fmt(pt),
65335 ops[0].tracking(cg),65310 ops[0].tracking(cg),
...@@ -68483,7 +68458,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -68483,7 +68458,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
68483 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },68458 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },
68484 } },68459 } },
68485 } }) catch |err| switch (err) {68460 } }) 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}", .{
68487 @tagName(air_tag),68462 @tagName(air_tag),
68488 cg.typeOf(ty_op.operand).fmt(pt),68463 cg.typeOf(ty_op.operand).fmt(pt),
68489 ops[0].tracking(cg),68464 ops[0].tracking(cg),
...@@ -68880,7 +68855,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -68880,7 +68855,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
68880 .{ .@"0:", ._, .lea, .dst0d, .leasia(.dst0, .@"8", .tmp0, .add_8_src0_size), ._, ._ },68855 .{ .@"0:", ._, .lea, .dst0d, .leasia(.dst0, .@"8", .tmp0, .add_8_src0_size), ._, ._ },
68881 } },68856 } },
68882 } }) catch |err| switch (err) {68857 } }) 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}", .{
68884 @tagName(air_tag),68859 @tagName(air_tag),
68885 cg.typeOf(ty_op.operand).fmt(pt),68860 cg.typeOf(ty_op.operand).fmt(pt),
68886 ops[0].tracking(cg),68861 ops[0].tracking(cg),
...@@ -69768,7 +69743,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -69768,7 +69743,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
69768 .{ ._, ._ae, .j, .@"0b", ._, ._, ._ },69743 .{ ._, ._ae, .j, .@"0b", ._, ._, ._ },
69769 } },69744 } },
69770 } }) catch |err| switch (err) {69745 } }) 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}", .{
69772 @tagName(air_tag),69747 @tagName(air_tag),
69773 cg.typeOf(ty_op.operand).fmt(pt),69748 cg.typeOf(ty_op.operand).fmt(pt),
69774 ops[0].tracking(cg),69749 ops[0].tracking(cg),
...@@ -70417,7 +70392,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -70417,7 +70392,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
70417 .{ ._, ._ae, .j, .@"0b", ._, ._, ._ },70392 .{ ._, ._ae, .j, .@"0b", ._, ._, ._ },
70418 } },70393 } },
70419 } }) catch |err| switch (err) {70394 } }) 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}", .{
70421 @tagName(air_tag),70396 @tagName(air_tag),
70422 ty_op.ty.toType().fmt(pt),70397 ty_op.ty.toType().fmt(pt),
70423 ops[0].tracking(cg),70398 ops[0].tracking(cg),
...@@ -73519,7 +73494,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -73519,7 +73494,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
73519 .{ ._, ._ae, .j, .@"0b", ._, ._, ._ },73494 .{ ._, ._ae, .j, .@"0b", ._, ._, ._ },
73520 } },73495 } },
73521 } }) catch |err| switch (err) {73496 } }) 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}", .{
73523 @tagName(air_tag),73498 @tagName(air_tag),
73524 ty_op.ty.toType().fmt(pt),73499 ty_op.ty.toType().fmt(pt),
73525 ops[0].tracking(cg),73500 ops[0].tracking(cg),
...@@ -74457,7 +74432,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -74457,7 +74432,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
74457 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },74432 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },
74458 } },74433 } },
74459 } }) catch |err| switch (err) {74434 } }) 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}", .{
74461 @tagName(air_tag),74436 @tagName(air_tag),
74462 cg.typeOf(un_op).fmt(pt),74437 cg.typeOf(un_op).fmt(pt),
74463 ops[0].tracking(cg),74438 ops[0].tracking(cg),
...@@ -75183,7 +75158,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -75183,7 +75158,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
75183 } },75158 } },
75184 } },75159 } },
75185 }) catch |err| switch (err) {75160 }) 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}", .{
75187 @tagName(air_tag),75162 @tagName(air_tag),
75188 cg.typeOf(un_op).fmt(pt),75163 cg.typeOf(un_op).fmt(pt),
75189 ops[0].tracking(cg),75164 ops[0].tracking(cg),
...@@ -76734,7 +76709,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -76734,7 +76709,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
76734 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },76709 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },
76735 } },76710 } },
76736 } }) catch |err| switch (err) {76711 } }) 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}", .{
76738 @tagName(air_tag),76713 @tagName(air_tag),
76739 cg.typeOf(ty_op.operand).fmt(pt),76714 cg.typeOf(ty_op.operand).fmt(pt),
76740 ops[0].tracking(cg),76715 ops[0].tracking(cg),
...@@ -77926,7 +77901,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -77926,7 +77901,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
77926 } },77901 } },
77927 } },77902 } },
77928 }) catch |err| switch (err) {77903 }) 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}", .{
77930 @tagName(air_tag),77905 @tagName(air_tag),
77931 cg.typeOf(un_op).fmt(pt),77906 cg.typeOf(un_op).fmt(pt),
77932 ops[0].tracking(cg),77907 ops[0].tracking(cg),
...@@ -78466,7 +78441,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -78466,7 +78441,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
78466 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },78441 .{ ._, ._nc, .j, .@"0b", ._, ._, ._ },
78467 } },78442 } },
78468 } }) catch |err| switch (err) {78443 } }) 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}", .{
78470 @tagName(air_tag),78445 @tagName(air_tag),
78471 cg.typeOf(un_op).fmt(pt),78446 cg.typeOf(un_op).fmt(pt),
78472 ops[0].tracking(cg),78447 ops[0].tracking(cg),
...@@ -78913,7 +78888,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -78913,7 +78888,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
78913 } else err: {78888 } else err: {
78914 res[0] = ops[0].cmpInts(cmp_op, &ops[1], cg) catch |err| break :err err;78889 res[0] = ops[0].cmpInts(cmp_op, &ops[1], cg) catch |err| break :err err;
78915 }) catch |err| switch (err) {78890 }) 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}", .{
78917 @tagName(air_tag),78892 @tagName(air_tag),
78918 cg.typeOf(bin_op.lhs).fmt(pt),78893 cg.typeOf(bin_op.lhs).fmt(pt),
78919 ops[0].tracking(cg),78894 ops[0].tracking(cg),
...@@ -79470,7 +79445,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -79470,7 +79445,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
79470 res[0] = ops[0].cmpInts(cmp_op, &ops[1], cg) catch |err| break :err err;79445 res[0] = ops[0].cmpInts(cmp_op, &ops[1], cg) catch |err| break :err err;
79471 },79446 },
79472 }) catch |err| switch (err) {79447 }) 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}", .{
79474 @tagName(air_tag),79449 @tagName(air_tag),
79475 ty.fmt(pt),79450 ty.fmt(pt),
79476 ops[0].tracking(cg),79451 ops[0].tracking(cg),
...@@ -88546,7 +88521,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -88546,7 +88521,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
88546 .{ ._, ._ae, .j, .@"0b", ._, ._, ._ },88521 .{ ._, ._ae, .j, .@"0b", ._, ._, ._ },
88547 } },88522 } },
88548 } }) catch |err| switch (err) {88523 } }) 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}", .{
88550 @tagName(air_tag),88525 @tagName(air_tag),
88551 ty_op.ty.toType().fmt(pt),88526 ty_op.ty.toType().fmt(pt),
88552 cg.typeOf(ty_op.operand).fmt(pt),88527 cg.typeOf(ty_op.operand).fmt(pt),
...@@ -90221,7 +90196,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -90221,7 +90196,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
90221 .{ ._, ._ae, .j, .@"0b", ._, ._, ._ },90196 .{ ._, ._ae, .j, .@"0b", ._, ._, ._ },
90222 } },90197 } },
90223 } }) catch |err| switch (err) {90198 } }) 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}", .{
90225 @tagName(air_tag),90200 @tagName(air_tag),
90226 ty_op.ty.toType().fmt(pt),90201 ty_op.ty.toType().fmt(pt),
90227 cg.typeOf(ty_op.operand).fmt(pt),90202 cg.typeOf(ty_op.operand).fmt(pt),
...@@ -94899,7 +94874,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -94899,7 +94874,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
94899 .{ ._, ._nz, .j, .@"0b", ._, ._, ._ },94874 .{ ._, ._nz, .j, .@"0b", ._, ._, ._ },
94900 } },94875 } },
94901 } }) catch |err| switch (err) {94876 } }) 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}", .{
94903 @tagName(air_tag),94878 @tagName(air_tag),
94904 dst_ty.fmt(pt),94879 dst_ty.fmt(pt),
94905 src_ty.fmt(pt),94880 src_ty.fmt(pt),
...@@ -100565,7 +100540,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -100565,7 +100540,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
100565 .{ ._, ._nz, .j, .@"0b", ._, ._, ._ },100540 .{ ._, ._nz, .j, .@"0b", ._, ._, ._ },
100566 } },100541 } },
100567 } }) catch |err| switch (err) {100542 } }) 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}", .{
100569 @tagName(air_tag),100544 @tagName(air_tag),
100570 ty_op.ty.toType().fmt(pt),100545 ty_op.ty.toType().fmt(pt),
100571 cg.typeOf(ty_op.operand).fmt(pt),100546 cg.typeOf(ty_op.operand).fmt(pt),
...@@ -111427,7 +111402,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -111427,7 +111402,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
111427 .{ ._, ._ae, .j, .@"0b", ._, ._, ._ },111402 .{ ._, ._ae, .j, .@"0b", ._, ._, ._ },
111428 } },111403 } },
111429 } }) catch |err| switch (err) {111404 } }) 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}", .{
111431 @tagName(air_tag),111406 @tagName(air_tag),
111432 ty_op.ty.toType().fmt(pt),111407 ty_op.ty.toType().fmt(pt),
111433 cg.typeOf(ty_op.operand).fmt(pt),111408 cg.typeOf(ty_op.operand).fmt(pt),
...@@ -123446,7 +123421,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -123446,7 +123421,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
123446 .{ ._, ._ae, .j, .@"0b", ._, ._, ._ },123421 .{ ._, ._ae, .j, .@"0b", ._, ._, ._ },
123447 } },123422 } },
123448 } }) catch |err| switch (err) {123423 } }) 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}", .{
123450 @tagName(air_tag),123425 @tagName(air_tag),
123451 ty_op.ty.toType().fmt(pt),123426 ty_op.ty.toType().fmt(pt),
123452 cg.typeOf(ty_op.operand).fmt(pt),123427 cg.typeOf(ty_op.operand).fmt(pt),
...@@ -166464,7 +166439,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -166464,7 +166439,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
166464 .{ ._, ._, .@"test", .src0p, .src0p, ._, ._ },166439 .{ ._, ._, .@"test", .src0p, .src0p, ._, ._ },
166465 } },166440 } },
166466 } }) catch |err| switch (err) {166441 } }) 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}", .{
166468 @tagName(air_tag),166443 @tagName(air_tag),
166469 cg.typeOf(un_op).fmt(pt),166444 cg.typeOf(un_op).fmt(pt),
166470 ops[0].tracking(cg),166445 ops[0].tracking(cg),
...@@ -166552,7 +166527,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -166552,7 +166527,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
166552 .{ ._, ._, .call, .tmp0d, ._, ._, ._ },166527 .{ ._, ._, .call, .tmp0d, ._, ._, ._ },
166553 } },166528 } },
166554 } }) catch |err| switch (err) {166529 } }) 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}", .{
166556 @tagName(air_tag),166531 @tagName(air_tag),
166557 cg.typeOf(un_op).fmt(pt),166532 cg.typeOf(un_op).fmt(pt),
166558 ops[0].tracking(cg),166533 ops[0].tracking(cg),
...@@ -166654,7 +166629,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -166654,7 +166629,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
166654 .{ ._, ._, .lea, .dst1d, .leai(.dst1, .tmp1), ._, ._ },166629 .{ ._, ._, .lea, .dst1d, .leai(.dst1, .tmp1), ._, ._ },
166655 } },166630 } },
166656 } }) catch |err| switch (err) {166631 } }) 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}", .{
166658 @tagName(air_tag),166633 @tagName(air_tag),
166659 cg.typeOf(un_op).fmt(pt),166634 cg.typeOf(un_op).fmt(pt),
166660 ops[0].tracking(cg),166635 ops[0].tracking(cg),
...@@ -166752,7 +166727,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -166752,7 +166727,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
166752 .{ ._, ._, .@"test", .src0d, .src0d, ._, ._ },166727 .{ ._, ._, .@"test", .src0d, .src0d, ._, ._ },
166753 } },166728 } },
166754 } }) catch |err| switch (err) {166729 } }) 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}", .{
166756 @tagName(air_tag),166731 @tagName(air_tag),
166757 ty_op.ty.toType().fmt(pt),166732 ty_op.ty.toType().fmt(pt),
166758 ops[0].tracking(cg),166733 ops[0].tracking(cg),
...@@ -166804,7 +166779,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -166804,7 +166779,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
166804 }166779 }
166805 }166780 }
166806 },166781 },
166807 .@"packed" => return cg.fail("failed to select {s} {}", .{166782 .@"packed" => return cg.fail("failed to select {s} {f}", .{
166808 @tagName(air_tag),166783 @tagName(air_tag),
166809 agg_ty.fmt(pt),166784 agg_ty.fmt(pt),
166810 }),166785 }),
...@@ -166825,7 +166800,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -166825,7 +166800,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
166825 elem_disp += @intCast(field_type.abiSize(zcu));166800 elem_disp += @intCast(field_type.abiSize(zcu));
166826 }166801 }
166827 },166802 },
166828 else => return cg.fail("failed to select {s} {}", .{166803 else => return cg.fail("failed to select {s} {f}", .{
166829 @tagName(air_tag),166804 @tagName(air_tag),
166830 agg_ty.fmt(pt),166805 agg_ty.fmt(pt),
166831 }),166806 }),
...@@ -168123,7 +168098,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -168123,7 +168098,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
168123 .{ ._, ._ae, .j, .@"0b", ._, ._, ._ },168098 .{ ._, ._ae, .j, .@"0b", ._, ._, ._ },
168124 } },168099 } },
168125 } }) catch |err| switch (err) {168100 } }) 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}", .{
168127 @tagName(air_tag),168102 @tagName(air_tag),
168128 cg.typeOf(bin_op.lhs).fmt(pt),168103 cg.typeOf(bin_op.lhs).fmt(pt),
168129 ops[0].tracking(cg),168104 ops[0].tracking(cg),
...@@ -168223,7 +168198,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -168223,7 +168198,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
168223 .{ ._, ._, .cmp, .src0d, .lea(.tmp1d), ._, ._ },168198 .{ ._, ._, .cmp, .src0d, .lea(.tmp1d), ._, ._ },
168224 } },168199 } },
168225 } }) catch |err| switch (err) {168200 } }) 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}", .{
168227 @tagName(air_tag),168202 @tagName(air_tag),
168228 ops[0].tracking(cg),168203 ops[0].tracking(cg),
168229 }),168204 }),
...@@ -168242,12 +168217,12 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -168242,12 +168217,12 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
168242 .ref => {168217 .ref => {
168243 const result = try cg.allocRegOrMem(err_ret_trace_index, true);168218 const result = try cg.allocRegOrMem(err_ret_trace_index, true);
168244 try cg.genCopy(.usize, result, ops[0].tracking(cg).short, .{});168219 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 });
168246 cg.inst_tracking.putAssumeCapacityNoClobber(err_ret_trace_index, .init(result));168221 cg.inst_tracking.putAssumeCapacityNoClobber(err_ret_trace_index, .init(result));
168247 },168222 },
168248 .temp => |temp_index| {168223 .temp => |temp_index| {
168249 const temp_tracking = temp_index.tracking(cg);168224 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 });
168251 cg.inst_tracking.putAssumeCapacityNoClobber(err_ret_trace_index, temp_tracking.*);168226 cg.inst_tracking.putAssumeCapacityNoClobber(err_ret_trace_index, temp_tracking.*);
168252 assert(cg.reuseTemp(err_ret_trace_index, temp_index.toIndex(), temp_tracking));168227 assert(cg.reuseTemp(err_ret_trace_index, temp_index.toIndex(), temp_tracking));
168253 },168228 },
...@@ -168917,7 +168892,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -168917,7 +168892,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
168917 try cg.resetTemps(@enumFromInt(0));168892 try cg.resetTemps(@enumFromInt(0));
168918 cg.checkInvariantsAfterAirInst();168893 cg.checkInvariantsAfterAirInst();
168919 }168894 }
168920 verbose_tracking_log.debug("{}", .{cg.fmtTracking()});168895 verbose_tracking_log.debug("{f}", .{cg.fmtTracking()});
168921}168896}
168922168897
168923fn genLazy(cg: *CodeGen, lazy_sym: link.File.LazySymbol) InnerError!void {168898fn 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 {...@@ -168927,7 +168902,7 @@ fn genLazy(cg: *CodeGen, lazy_sym: link.File.LazySymbol) InnerError!void {
168927 switch (ip.indexToKey(lazy_sym.ty)) {168902 switch (ip.indexToKey(lazy_sym.ty)) {
168928 .enum_type => {168903 .enum_type => {
168929 const enum_ty: Type = .fromInterned(lazy_sym.ty);168904 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
168932 const param_regs = abi.getCAbiIntParamRegs(.auto);168907 const param_regs = abi.getCAbiIntParamRegs(.auto);
168933 const param_locks = cg.register_manager.lockRegsAssumeUnused(2, param_regs[0..2].*);168908 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 {...@@ -168976,7 +168951,7 @@ fn genLazy(cg: *CodeGen, lazy_sym: link.File.LazySymbol) InnerError!void {
168976 },168951 },
168977 .error_set_type => |error_set_type| {168952 .error_set_type => |error_set_type| {
168978 const err_ty: Type = .fromInterned(lazy_sym.ty);168953 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
168981 const param_regs = abi.getCAbiIntParamRegs(.auto);168956 const param_regs = abi.getCAbiIntParamRegs(.auto);
168982 const param_locks = cg.register_manager.lockRegsAssumeUnused(2, param_regs[0..2].*);168957 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 {...@@ -169016,7 +168991,7 @@ fn genLazy(cg: *CodeGen, lazy_sym: link.File.LazySymbol) InnerError!void {
169016 try cg.asmOpOnly(.{ ._, .ret });168991 try cg.asmOpOnly(.{ ._, .ret });
169017 },168992 },
169018 else => return cg.fail(168993 else => return cg.fail(
169019 "TODO implement {s} for {}",168994 "TODO implement {s} for {f}",
169020 .{ @tagName(lazy_sym.kind), Type.fromInterned(lazy_sym.ty).fmt(pt) },168995 .{ @tagName(lazy_sym.kind), Type.fromInterned(lazy_sym.ty).fmt(pt) },
169021 ),168996 ),
169022 }168997 }
...@@ -169076,7 +169051,7 @@ fn finishAirResult(self: *CodeGen, inst: Air.Inst.Index, result: MCValue) void {...@@ -169076,7 +169051,7 @@ fn finishAirResult(self: *CodeGen, inst: Air.Inst.Index, result: MCValue) void {
169076 .none, .dead, .unreach => {},169051 .none, .dead, .unreach => {},
169077 else => unreachable, // Why didn't the result die?169052 else => unreachable, // Why didn't the result die?
169078 } else {169053 } else {
169079 tracking_log.debug("{} => {} (birth)", .{ inst, result });169054 tracking_log.debug("{f} => {f} (birth)", .{ inst, result });
169080 self.inst_tracking.putAssumeCapacityNoClobber(inst, .init(result));169055 self.inst_tracking.putAssumeCapacityNoClobber(inst, .init(result));
169081 // In some cases, an operand may be reused as the result.169056 // In some cases, an operand may be reused as the result.
169082 // If that operand died and was a register, it was freed by169057 // 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 {...@@ -169226,7 +169201,7 @@ fn allocMemPtr(self: *CodeGen, inst: Air.Inst.Index) !FrameIndex {
169226 const val_ty = ptr_ty.childType(zcu);169201 const val_ty = ptr_ty.childType(zcu);
169227 return self.allocFrameIndex(.init(.{169202 return self.allocFrameIndex(.init(.{
169228 .size = std.math.cast(u32, val_ty.abiSize(zcu)) orelse {169203 .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)});
169230 },169205 },
169231 .alignment = ptr_ty.ptrAlignment(zcu).max(.@"1"),169206 .alignment = ptr_ty.ptrAlignment(zcu).max(.@"1"),
169232 }));169207 }));
...@@ -169244,7 +169219,7 @@ fn allocRegOrMemAdvanced(self: *CodeGen, ty: Type, inst: ?Air.Inst.Index, reg_ok...@@ -169244,7 +169219,7 @@ fn allocRegOrMemAdvanced(self: *CodeGen, ty: Type, inst: ?Air.Inst.Index, reg_ok
169244 const pt = self.pt;169219 const pt = self.pt;
169245 const zcu = pt.zcu;169220 const zcu = pt.zcu;
169246 const abi_size = std.math.cast(u32, ty.abiSize(zcu)) orelse {169221 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)});
169248 };169223 };
169249169224
169250 if (reg_ok) need_mem: {169225 if (reg_ok) need_mem: {
...@@ -169749,7 +169724,7 @@ fn airFpext(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -169749,7 +169724,7 @@ fn airFpext(self: *CodeGen, inst: Air.Inst.Index) !void {
169749 );169724 );
169750 }169725 }
169751 break :result dst_mcv;169726 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}", .{
169753 src_ty.fmt(pt), dst_ty.fmt(pt),169728 src_ty.fmt(pt), dst_ty.fmt(pt),
169754 });169729 });
169755 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });169730 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
...@@ -170004,7 +169979,7 @@ fn airIntCast(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -170004,7 +169979,7 @@ fn airIntCast(self: *CodeGen, inst: Air.Inst.Index) !void {
170004 );169979 );
170005169980
170006 break :result dst_mcv;169981 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}", .{
170008 src_ty.fmt(pt), dst_ty.fmt(pt),169983 src_ty.fmt(pt), dst_ty.fmt(pt),
170009 });169984 });
170010 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });169985 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
...@@ -170076,7 +170051,7 @@ fn airTrunc(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -170076,7 +170051,7 @@ fn airTrunc(self: *CodeGen, inst: Air.Inst.Index) !void {
170076 else => null,170051 else => null,
170077 },170052 },
170078 else => null,170053 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
170081 const dst_info = dst_elem_ty.intInfo(zcu);170056 const dst_info = dst_elem_ty.intInfo(zcu);
170082 const src_info = src_elem_ty.intInfo(zcu);170057 const src_info = src_elem_ty.intInfo(zcu);
...@@ -170497,7 +170472,7 @@ fn airAddSat(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -170497,7 +170472,7 @@ fn airAddSat(self: *CodeGen, inst: Air.Inst.Index) !void {
170497 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;170472 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
170498 const ty = self.typeOf(bin_op.lhs);170473 const ty = self.typeOf(bin_op.lhs);
170499 if (ty.zigTypeTag(zcu) == .vector or ty.abiSize(zcu) > 8) return self.fail(170474 if (ty.zigTypeTag(zcu) == .vector or ty.abiSize(zcu) > 8) return self.fail(
170500 "TODO implement airAddSat for {}",170475 "TODO implement airAddSat for {f}",
170501 .{ty.fmt(pt)},170476 .{ty.fmt(pt)},
170502 );170477 );
170503170478
...@@ -170575,7 +170550,7 @@ fn airSubSat(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -170575,7 +170550,7 @@ fn airSubSat(self: *CodeGen, inst: Air.Inst.Index) !void {
170575 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;170550 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
170576 const ty = self.typeOf(bin_op.lhs);170551 const ty = self.typeOf(bin_op.lhs);
170577 if (ty.zigTypeTag(zcu) == .vector or ty.abiSize(zcu) > 8) return self.fail(170552 if (ty.zigTypeTag(zcu) == .vector or ty.abiSize(zcu) > 8) return self.fail(
170578 "TODO implement airSubSat for {}",170553 "TODO implement airSubSat for {f}",
170579 .{ty.fmt(pt)},170554 .{ty.fmt(pt)},
170580 );170555 );
170581170556
...@@ -170726,7 +170701,7 @@ fn airMulSat(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -170726,7 +170701,7 @@ fn airMulSat(self: *CodeGen, inst: Air.Inst.Index) !void {
170726 }170701 }
170727170702
170728 if (ty.zigTypeTag(zcu) == .vector or ty.abiSize(zcu) > 8) return self.fail(170703 if (ty.zigTypeTag(zcu) == .vector or ty.abiSize(zcu) > 8) return self.fail(
170729 "TODO implement airMulSat for {}",170704 "TODO implement airMulSat for {f}",
170730 .{ty.fmt(pt)},170705 .{ty.fmt(pt)},
170731 );170706 );
170732170707
...@@ -171020,7 +170995,7 @@ fn airMulWithOverflow(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -171020,7 +170995,7 @@ fn airMulWithOverflow(self: *CodeGen, inst: Air.Inst.Index) !void {
171020 const tuple_ty = self.typeOfIndex(inst);170995 const tuple_ty = self.typeOfIndex(inst);
171021 const dst_ty = self.typeOf(bin_op.lhs);170996 const dst_ty = self.typeOf(bin_op.lhs);
171022 const result: MCValue = switch (dst_ty.zigTypeTag(zcu)) {170997 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)}),
171024 .int => result: {170999 .int => result: {
171025 const dst_info = dst_ty.intInfo(zcu);171000 const dst_info = dst_ty.intInfo(zcu);
171026 if (dst_info.bits > 128 and dst_info.signedness == .unsigned) {171001 if (dst_info.bits > 128 and dst_info.signedness == .unsigned) {
...@@ -171373,7 +171348,7 @@ fn airMulWithOverflow(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -171373,7 +171348,7 @@ fn airMulWithOverflow(self: *CodeGen, inst: Air.Inst.Index) !void {
171373 else => {171348 else => {
171374 // For now, this is the only supported multiply that doesn't fit in a register.171349 // For now, this is the only supported multiply that doesn't fit in a register.
171375 if (dst_info.bits > 128 or src_bits != 64)171350 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}", .{
171377 src_ty.fmt(pt), dst_ty.fmt(pt),171352 src_ty.fmt(pt), dst_ty.fmt(pt),
171378 });171353 });
171379171354
...@@ -171774,7 +171749,7 @@ fn airShlShrBinOp(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -171774,7 +171749,7 @@ fn airShlShrBinOp(self: *CodeGen, inst: Air.Inst.Index) !void {
171774 },171749 },
171775 else => {},171750 else => {},
171776 }171751 }
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)});
171778 };171753 };
171779 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });171754 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
171780}171755}
...@@ -172034,7 +172009,7 @@ fn airUnwrapErrUnionErr(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -172034,7 +172009,7 @@ fn airUnwrapErrUnionErr(self: *CodeGen, inst: Air.Inst.Index) !void {
172034 .index = frame_addr.index,172009 .index = frame_addr.index,
172035 .off = frame_addr.off + @as(i32, @intCast(err_off)),172010 .off = frame_addr.off + @as(i32, @intCast(err_off)),
172036 } },172011 } },
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}),
172038 }172013 }
172039 };172014 };
172040 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });172015 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
...@@ -172196,7 +172171,7 @@ fn genUnwrapErrUnionPayloadMir(...@@ -172196,7 +172171,7 @@ fn genUnwrapErrUnionPayloadMir(
172196 else172171 else
172197 .{ .register = try self.copyToTmpRegister(payload_ty, result_mcv) };172172 .{ .register = try self.copyToTmpRegister(payload_ty, result_mcv) };
172198 },172173 },
172199 else => return self.fail("TODO implement genUnwrapErrUnionPayloadMir for {}", .{err_union}),172174 else => return self.fail("TODO implement genUnwrapErrUnionPayloadMir for {f}", .{err_union}),
172200 }172175 }
172201 };172176 };
172202172177
...@@ -172362,7 +172337,7 @@ fn airSliceLen(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -172362,7 +172337,7 @@ fn airSliceLen(self: *CodeGen, inst: Air.Inst.Index) !void {
172362 .index = frame_addr.index,172337 .index = frame_addr.index,
172363 .off = frame_addr.off + 8,172338 .off = frame_addr.off + 8,
172364 } },172339 } },
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}),
172366 };172341 };
172367 if (self.reuseOperand(inst, ty_op.operand, 0, src_mcv)) {172342 if (self.reuseOperand(inst, ty_op.operand, 0, src_mcv)) {
172368 switch (src_mcv) {172343 switch (src_mcv) {
...@@ -172645,7 +172620,7 @@ fn airArrayElemVal(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -172645,7 +172620,7 @@ fn airArrayElemVal(self: *CodeGen, inst: Air.Inst.Index) !void {
172645 }.to64(),172620 }.to64(),
172646 ),172621 ),
172647 },172622 },
172648 else => return self.fail("TODO airArrayElemVal for {s} of {}", .{172623 else => return self.fail("TODO airArrayElemVal for {s} of {f}", .{
172649 @tagName(array_mat_mcv), array_ty.fmt(pt),172624 @tagName(array_mat_mcv), array_ty.fmt(pt),
172650 }),172625 }),
172651 }172626 }
...@@ -172688,7 +172663,7 @@ fn airArrayElemVal(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -172688,7 +172663,7 @@ fn airArrayElemVal(self: *CodeGen, inst: Air.Inst.Index) !void {
172688 .load_extern_func,172663 .load_extern_func,
172689 .lea_extern_func,172664 .lea_extern_func,
172690 => try self.genSetReg(addr_reg, .usize, array_mcv.address(), .{}),172665 => 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}", .{
172692 @tagName(array_mcv), array_ty.fmt(pt),172667 @tagName(array_mcv), array_ty.fmt(pt),
172693 }),172668 }),
172694 }172669 }
...@@ -172881,7 +172856,7 @@ fn airGetUnionTag(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -172881,7 +172856,7 @@ fn airGetUnionTag(self: *CodeGen, inst: Air.Inst.Index) !void {
172881 }172856 }
172882172857
172883 return self.fail(172858 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}",
172885 .{operand},172860 .{operand},
172886 );172861 );
172887 },172862 },
...@@ -172893,7 +172868,7 @@ fn airGetUnionTag(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -172893,7 +172868,7 @@ fn airGetUnionTag(self: *CodeGen, inst: Air.Inst.Index) !void {
172893 .register = registerAlias(result.register, @intCast(layout.tag_size)),172868 .register = registerAlias(result.register, @intCast(layout.tag_size)),
172894 };172869 };
172895 },172870 },
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}),
172897 }172872 }
172898 };172873 };
172899172874
...@@ -172909,7 +172884,7 @@ fn airClz(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -172909,7 +172884,7 @@ fn airClz(self: *CodeGen, inst: Air.Inst.Index) !void {
172909172884
172910 const dst_ty = self.typeOfIndex(inst);172885 const dst_ty = self.typeOfIndex(inst);
172911 const src_ty = self.typeOf(ty_op.operand);172886 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}", .{
172913 src_ty.fmt(pt),172888 src_ty.fmt(pt),
172914 });172889 });
172915172890
...@@ -173105,7 +173080,7 @@ fn airCtz(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -173105,7 +173080,7 @@ fn airCtz(self: *CodeGen, inst: Air.Inst.Index) !void {
173105173080
173106 const dst_ty = self.typeOfIndex(inst);173081 const dst_ty = self.typeOfIndex(inst);
173107 const src_ty = self.typeOf(ty_op.operand);173082 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}", .{
173109 src_ty.fmt(pt),173084 src_ty.fmt(pt),
173110 });173085 });
173111173086
...@@ -173277,7 +173252,7 @@ fn airPopCount(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -173277,7 +173252,7 @@ fn airPopCount(self: *CodeGen, inst: Air.Inst.Index) !void {
173277 const src_ty = self.typeOf(ty_op.operand);173252 const src_ty = self.typeOf(ty_op.operand);
173278 const src_abi_size: u32 = @intCast(src_ty.abiSize(zcu));173253 const src_abi_size: u32 = @intCast(src_ty.abiSize(zcu));
173279 if (src_ty.zigTypeTag(zcu) == .vector or src_abi_size > 16)173254 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)});
173281 const src_mcv = try self.resolveInst(ty_op.operand);173256 const src_mcv = try self.resolveInst(ty_op.operand);
173282173257
173283 const mat_src_mcv = switch (src_mcv) {173258 const mat_src_mcv = switch (src_mcv) {
...@@ -173430,7 +173405,7 @@ fn genByteSwap(...@@ -173430,7 +173405,7 @@ fn genByteSwap(
173430 const has_movbe = self.hasFeature(.movbe);173405 const has_movbe = self.hasFeature(.movbe);
173431173406
173432 if (src_ty.zigTypeTag(zcu) == .vector) return self.fail(173407 if (src_ty.zigTypeTag(zcu) == .vector) return self.fail(
173433 "TODO implement genByteSwap for {}",173408 "TODO implement genByteSwap for {f}",
173434 .{src_ty.fmt(pt)},173409 .{src_ty.fmt(pt)},
173435 );173410 );
173436173411
...@@ -173739,7 +173714,7 @@ fn floatSign(self: *CodeGen, inst: Air.Inst.Index, tag: Air.Inst.Tag, operand: A...@@ -173739,7 +173714,7 @@ fn floatSign(self: *CodeGen, inst: Air.Inst.Index, tag: Air.Inst.Tag, operand: A
173739 const result = result: {173714 const result = result: {
173740 const scalar_bits = ty.scalarType(zcu).floatBits(self.target);173715 const scalar_bits = ty.scalarType(zcu).floatBits(self.target);
173741 if (scalar_bits == 80) {173716 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}", .{
173743 ty.fmt(pt),173718 ty.fmt(pt),
173744 });173719 });
173745173720
...@@ -173763,7 +173738,7 @@ fn floatSign(self: *CodeGen, inst: Air.Inst.Index, tag: Air.Inst.Tag, operand: A...@@ -173763,7 +173738,7 @@ fn floatSign(self: *CodeGen, inst: Air.Inst.Index, tag: Air.Inst.Tag, operand: A
173763 const abi_size: u32 = switch (ty.abiSize(zcu)) {173738 const abi_size: u32 = switch (ty.abiSize(zcu)) {
173764 1...16 => 16,173739 1...16 => 16,
173765 17...32 => 32,173740 17...32 => 32,
173766 else => return self.fail("TODO implement floatSign for {}", .{173741 else => return self.fail("TODO implement floatSign for {f}", .{
173767 ty.fmt(pt),173742 ty.fmt(pt),
173768 }),173743 }),
173769 };173744 };
...@@ -173822,7 +173797,7 @@ fn floatSign(self: *CodeGen, inst: Air.Inst.Index, tag: Air.Inst.Tag, operand: A...@@ -173822,7 +173797,7 @@ fn floatSign(self: *CodeGen, inst: Air.Inst.Index, tag: Air.Inst.Tag, operand: A
173822 .abs => .{ .v_pd, .@"and" },173797 .abs => .{ .v_pd, .@"and" },
173823 else => unreachable,173798 else => unreachable,
173824 },173799 },
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)}),
173826 else => unreachable,173801 else => unreachable,
173827 },173802 },
173828 registerAlias(dst_reg, abi_size),173803 registerAlias(dst_reg, abi_size),
...@@ -173848,7 +173823,7 @@ fn floatSign(self: *CodeGen, inst: Air.Inst.Index, tag: Air.Inst.Tag, operand: A...@@ -173848,7 +173823,7 @@ fn floatSign(self: *CodeGen, inst: Air.Inst.Index, tag: Air.Inst.Tag, operand: A
173848 .abs => .{ ._pd, .@"and" },173823 .abs => .{ ._pd, .@"and" },
173849 else => unreachable,173824 else => unreachable,
173850 },173825 },
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)}),
173852 else => unreachable,173827 else => unreachable,
173853 },173828 },
173854 registerAlias(dst_reg, abi_size),173829 registerAlias(dst_reg, abi_size),
...@@ -173928,7 +173903,7 @@ fn genRoundLibcall(self: *CodeGen, ty: Type, src_mcv: MCValue, mode: bits.RoundM...@@ -173928,7 +173903,7 @@ fn genRoundLibcall(self: *CodeGen, ty: Type, src_mcv: MCValue, mode: bits.RoundM
173928 if (self.getRoundTag(ty)) |_| return .none;173903 if (self.getRoundTag(ty)) |_| return .none;
173929173904
173930 if (ty.zigTypeTag(zcu) != .float)173905 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
173933 var sym_buf: ["__trunc?".len]u8 = undefined;173908 var sym_buf: ["__trunc?".len]u8 = undefined;
173934 return try self.genCall(.{ .extern_func = .{173909 return try self.genCall(.{ .extern_func = .{
...@@ -174164,7 +174139,7 @@ fn airAbs(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -174164,7 +174139,7 @@ fn airAbs(self: *CodeGen, inst: Air.Inst.Index) !void {
174164 },174139 },
174165 .float => return self.floatSign(inst, .abs, ty_op.operand, ty),174140 .float => return self.floatSign(inst, .abs, ty_op.operand, ty),
174166 },174141 },
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
174169 const abi_size: u32 = @intCast(ty.abiSize(zcu));174144 const abi_size: u32 = @intCast(ty.abiSize(zcu));
174170 const src_mcv = try self.resolveInst(ty_op.operand);174145 const src_mcv = try self.resolveInst(ty_op.operand);
...@@ -174323,7 +174298,7 @@ fn airSqrt(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -174323,7 +174298,7 @@ fn airSqrt(self: *CodeGen, inst: Air.Inst.Index) !void {
174323 else => unreachable,174298 else => unreachable,
174324 },174299 },
174325 else => unreachable,174300 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)});
174327 switch (mir_tag[0]) {174302 switch (mir_tag[0]) {
174328 .v_ss, .v_sd => if (src_mcv.isBase()) try self.asmRegisterRegisterMemory(174303 .v_ss, .v_sd => if (src_mcv.isBase()) try self.asmRegisterRegisterMemory(
174329 mir_tag,174304 mir_tag,
...@@ -174481,7 +174456,7 @@ fn packedLoad(self: *CodeGen, dst_mcv: MCValue, ptr_ty: Type, ptr_mcv: MCValue)...@@ -174481,7 +174456,7 @@ fn packedLoad(self: *CodeGen, dst_mcv: MCValue, ptr_ty: Type, ptr_mcv: MCValue)
174481 return;174456 return;
174482 }174457 }
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
174486 const limb_abi_size: u31 = @min(val_abi_size, 8);174461 const limb_abi_size: u31 = @min(val_abi_size, 8);
174487 const limb_abi_bits = limb_abi_size * 8;174462 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)...@@ -174753,7 +174728,7 @@ fn packedStore(self: *CodeGen, ptr_ty: Type, ptr_mcv: MCValue, src_mcv: MCValue)
174753 limb_mem,174728 limb_mem,
174754 registerAlias(tmp_reg, limb_abi_size),174729 registerAlias(tmp_reg, limb_abi_size),
174755 );174730 );
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)});
174757 }174732 }
174758}174733}
174759174734
...@@ -174856,7 +174831,7 @@ fn genUnOp(self: *CodeGen, maybe_inst: ?Air.Inst.Index, tag: Air.Inst.Tag, src_a...@@ -174856,7 +174831,7 @@ fn genUnOp(self: *CodeGen, maybe_inst: ?Air.Inst.Index, tag: Air.Inst.Tag, src_a
174856 const zcu = pt.zcu;174831 const zcu = pt.zcu;
174857 const src_ty = self.typeOf(src_air);174832 const src_ty = self.typeOf(src_air);
174858 if (src_ty.zigTypeTag(zcu) == .vector)174833 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
174861 var src_mcv = try self.resolveInst(src_air);174836 var src_mcv = try self.resolveInst(src_air);
174862 switch (src_mcv) {174837 switch (src_mcv) {
...@@ -174943,7 +174918,7 @@ fn genUnOp(self: *CodeGen, maybe_inst: ?Air.Inst.Index, tag: Air.Inst.Tag, src_a...@@ -174943,7 +174918,7 @@ fn genUnOp(self: *CodeGen, maybe_inst: ?Air.Inst.Index, tag: Air.Inst.Tag, src_a
174943fn genUnOpMir(self: *CodeGen, mir_tag: Mir.Inst.FixedTag, dst_ty: Type, dst_mcv: MCValue) !void {174918fn genUnOpMir(self: *CodeGen, mir_tag: Mir.Inst.FixedTag, dst_ty: Type, dst_mcv: MCValue) !void {
174944 const pt = self.pt;174919 const pt = self.pt;
174945 const abi_size: u32 = @intCast(dst_ty.abiSize(pt.zcu));174920 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) });
174947 switch (dst_mcv) {174922 switch (dst_mcv) {
174948 .none,174923 .none,
174949 .unreach,174924 .unreach,
...@@ -175672,7 +175647,7 @@ fn genBinOp(...@@ -175672,7 +175647,7 @@ fn genBinOp(
175672 },175647 },
175673 floatLibcAbiSuffix(lhs_ty),175648 floatLibcAbiSuffix(lhs_ty),
175674 }),175649 }),
175675 else => return self.fail("TODO implement genBinOp for {s} {}", .{175650 else => return self.fail("TODO implement genBinOp for {s} {f}", .{
175676 @tagName(air_tag), lhs_ty.fmt(pt),175651 @tagName(air_tag), lhs_ty.fmt(pt),
175677 }),175652 }),
175678 } catch unreachable;175653 } catch unreachable;
...@@ -175785,7 +175760,7 @@ fn genBinOp(...@@ -175785,7 +175760,7 @@ fn genBinOp(
175785 );175760 );
175786 break :adjusted .{ .register = dst_reg };175761 break :adjusted .{ .register = dst_reg };
175787 },175762 },
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}", .{
175789 @tagName(air_tag), lhs_ty.fmt(pt),175764 @tagName(air_tag), lhs_ty.fmt(pt),
175790 }),175765 }),
175791 else => unreachable,175766 else => unreachable,
...@@ -175819,7 +175794,7 @@ fn genBinOp(...@@ -175819,7 +175794,7 @@ fn genBinOp(
175819 if (sse_op and ((lhs_ty.scalarType(zcu).isRuntimeFloat() and175794 if (sse_op and ((lhs_ty.scalarType(zcu).isRuntimeFloat() and
175820 lhs_ty.scalarType(zcu).floatBits(self.target) == 80) or175795 lhs_ty.scalarType(zcu).floatBits(self.target) == 80) or
175821 lhs_ty.abiSize(zcu) > self.vectorSize(.float)))175796 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
175824 const maybe_mask_reg = switch (air_tag) {175799 const maybe_mask_reg = switch (air_tag) {
175825 else => null,175800 else => null,
...@@ -176199,7 +176174,7 @@ fn genBinOp(...@@ -176199,7 +176174,7 @@ fn genBinOp(
176199 }176174 }
176200 },176175 },
176201176176
176202 else => return self.fail("TODO implement genBinOp for {s} {}", .{176177 else => return self.fail("TODO implement genBinOp for {s} {f}", .{
176203 @tagName(air_tag), lhs_ty.fmt(pt),176178 @tagName(air_tag), lhs_ty.fmt(pt),
176204 }),176179 }),
176205 }176180 }
...@@ -176953,7 +176928,7 @@ fn genBinOp(...@@ -176953,7 +176928,7 @@ fn genBinOp(
176953 else => unreachable,176928 else => unreachable,
176954 },176929 },
176955 },176930 },
176956 }) orelse return self.fail("TODO implement genBinOp for {s} {}", .{176931 }) orelse return self.fail("TODO implement genBinOp for {s} {f}", .{
176957 @tagName(air_tag), lhs_ty.fmt(pt),176932 @tagName(air_tag), lhs_ty.fmt(pt),
176958 });176933 });
176959176934
...@@ -177086,7 +177061,7 @@ fn genBinOp(...@@ -177086,7 +177061,7 @@ fn genBinOp(
177086 else => unreachable,177061 else => unreachable,
177087 },177062 },
177088 else => unreachable,177063 else => unreachable,
177089 }) orelse return self.fail("TODO implement genBinOp for {s} {}", .{177064 }) orelse return self.fail("TODO implement genBinOp for {s} {f}", .{
177090 @tagName(air_tag), lhs_ty.fmt(pt),177065 @tagName(air_tag), lhs_ty.fmt(pt),
177091 }),177066 }),
177092 mask_reg,177067 mask_reg,
...@@ -177118,7 +177093,7 @@ fn genBinOp(...@@ -177118,7 +177093,7 @@ fn genBinOp(
177118 else => unreachable,177093 else => unreachable,
177119 },177094 },
177120 else => unreachable,177095 else => unreachable,
177121 }) orelse return self.fail("TODO implement genBinOp for {s} {}", .{177096 }) orelse return self.fail("TODO implement genBinOp for {s} {f}", .{
177122 @tagName(air_tag), lhs_ty.fmt(pt),177097 @tagName(air_tag), lhs_ty.fmt(pt),
177123 }),177098 }),
177124 dst_reg,177099 dst_reg,
...@@ -177154,7 +177129,7 @@ fn genBinOp(...@@ -177154,7 +177129,7 @@ fn genBinOp(
177154 else => unreachable,177129 else => unreachable,
177155 },177130 },
177156 else => unreachable,177131 else => unreachable,
177157 }) orelse return self.fail("TODO implement genBinOp for {s} {}", .{177132 }) orelse return self.fail("TODO implement genBinOp for {s} {f}", .{
177158 @tagName(air_tag), lhs_ty.fmt(pt),177133 @tagName(air_tag), lhs_ty.fmt(pt),
177159 }),177134 }),
177160 mask_reg,177135 mask_reg,
...@@ -177185,7 +177160,7 @@ fn genBinOp(...@@ -177185,7 +177160,7 @@ fn genBinOp(
177185 else => unreachable,177160 else => unreachable,
177186 },177161 },
177187 else => unreachable,177162 else => unreachable,
177188 }) orelse return self.fail("TODO implement genBinOp for {s} {}", .{177163 }) orelse return self.fail("TODO implement genBinOp for {s} {f}", .{
177189 @tagName(air_tag), lhs_ty.fmt(pt),177164 @tagName(air_tag), lhs_ty.fmt(pt),
177190 }),177165 }),
177191 dst_reg,177166 dst_reg,
...@@ -177215,7 +177190,7 @@ fn genBinOp(...@@ -177215,7 +177190,7 @@ fn genBinOp(
177215 else => unreachable,177190 else => unreachable,
177216 },177191 },
177217 else => unreachable,177192 else => unreachable,
177218 }) orelse return self.fail("TODO implement genBinOp for {s} {}", .{177193 }) orelse return self.fail("TODO implement genBinOp for {s} {f}", .{
177219 @tagName(air_tag), lhs_ty.fmt(pt),177194 @tagName(air_tag), lhs_ty.fmt(pt),
177220 });177195 });
177221 try self.asmRegisterRegister(.{ mir_fixes, .@"and" }, dst_reg, mask_reg);177196 try self.asmRegisterRegister(.{ mir_fixes, .@"and" }, dst_reg, mask_reg);
...@@ -178022,7 +177997,7 @@ fn airArg(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -178022,7 +177997,7 @@ fn airArg(self: *CodeGen, inst: Air.Inst.Index) !void {
178022177997
178023 break :result dst_mcv;177998 break :result dst_mcv;
178024 },177999 },
178025 else => return self.fail("TODO implement arg for {}", .{src_mcv}),178000 else => return self.fail("TODO implement arg for {f}", .{src_mcv}),
178026 }178001 }
178027 };178002 };
178028 return self.finishAir(inst, result, .{ .none, .none, .none });178003 return self.finishAir(inst, result, .{ .none, .none, .none });
...@@ -179079,7 +179054,7 @@ fn genCondBrMir(self: *CodeGen, ty: Type, mcv: MCValue) !Mir.Inst.Index {...@@ -179079,7 +179054,7 @@ fn genCondBrMir(self: *CodeGen, ty: Type, mcv: MCValue) !Mir.Inst.Index {
179079 const reg = try self.copyToTmpRegister(ty, mcv);179054 const reg = try self.copyToTmpRegister(ty, mcv);
179080 return self.genCondBrMir(ty, .{ .register = reg });179055 return self.genCondBrMir(ty, .{ .register = reg });
179081 }179056 }
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});
179083 },179058 },
179084 else => return self.fail("TODO implement condbr when condition is {s}", .{@tagName(mcv)}),179059 else => return self.fail("TODO implement condbr when condition is {s}", .{@tagName(mcv)}),
179085 }179060 }
...@@ -179166,7 +179141,7 @@ fn isErr(self: *CodeGen, maybe_inst: ?Air.Inst.Index, eu_ty: Type, eu_mcv: MCVal...@@ -179166,7 +179141,7 @@ fn isErr(self: *CodeGen, maybe_inst: ?Air.Inst.Index, eu_ty: Type, eu_mcv: MCVal
179166 } },179141 } },
179167 .{ .immediate = 0 },179142 .{ .immediate = 0 },
179168 ),179143 ),
179169 else => return self.fail("TODO implement isErr for {}", .{eu_mcv}),179144 else => return self.fail("TODO implement isErr for {f}", .{eu_mcv}),
179170 }179145 }
179171179146
179172 if (maybe_inst) |inst| self.eflags_inst = inst;179147 if (maybe_inst) |inst| self.eflags_inst = inst;
...@@ -180916,7 +180891,7 @@ fn moveStrategy(cg: *CodeGen, ty: Type, class: Register.Class, aligned: bool) !M...@@ -180916,7 +180891,7 @@ fn moveStrategy(cg: *CodeGen, ty: Type, class: Register.Class, aligned: bool) !M
180916 },180891 },
180917 .ip, .cr, .dr => {},180892 .ip, .cr, .dr => {},
180918 }180893 }
180919 return cg.fail("TODO moveStrategy for {}", .{ty.fmt(pt)});180894 return cg.fail("TODO moveStrategy for {f}", .{ty.fmt(pt)});
180920}180895}
180921180896
180922const CopyOptions = struct {180897const CopyOptions = struct {
...@@ -181048,7 +181023,7 @@ fn genCopy(self: *CodeGen, ty: Type, dst_mcv: MCValue, src_mcv: MCValue, opts: C...@@ -181048,7 +181023,7 @@ fn genCopy(self: *CodeGen, ty: Type, dst_mcv: MCValue, src_mcv: MCValue, opts: C
181048 break :src_info .{ .addr_reg = src_addr_reg, .addr_lock = src_addr_lock };181023 break :src_info .{ .addr_reg = src_addr_reg, .addr_lock = src_addr_lock };
181049 },181024 },
181050 .air_ref => |src_ref| return self.genCopy(ty, dst_mcv, try self.resolveInst(src_ref), opts),181025 .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}", .{
181052 @tagName(src_mcv), ty.fmt(pt),181027 @tagName(src_mcv), ty.fmt(pt),
181053 }),181028 }),
181054 };181029 };
...@@ -181424,7 +181399,7 @@ fn genSetReg(...@@ -181424,7 +181399,7 @@ fn genSetReg(
181424 80 => null,181399 80 => null,
181425 else => unreachable,181400 else => unreachable,
181426 },181401 },
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)}),
181428 dst_alias,181403 dst_alias,
181429 registerAlias(src_reg, abi_size),181404 registerAlias(src_reg, abi_size),
181430 ),181405 ),
...@@ -181854,7 +181829,7 @@ fn genSetMem(...@@ -181854,7 +181829,7 @@ fn genSetMem(
181854 opts,181829 opts,
181855 );181830 );
181856 },181831 },
181857 else => return self.fail("TODO implement genSetMem for {s} of {}", .{181832 else => return self.fail("TODO implement genSetMem for {s} of {f}", .{
181858 @tagName(src_mcv), ty.fmt(pt),181833 @tagName(src_mcv), ty.fmt(pt),
181859 }),181834 }),
181860 },181835 },
...@@ -182167,7 +182142,7 @@ fn airFloatFromInt(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -182167,7 +182142,7 @@ fn airFloatFromInt(self: *CodeGen, inst: Air.Inst.Index) !void {
182167 32, 64 => src_size > 8,182142 32, 64 => src_size > 8,
182168 else => unreachable,182143 else => unreachable,
182169 }) {182144 }) {
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}", .{
182171 src_ty.fmt(pt), dst_ty.fmt(pt),182146 src_ty.fmt(pt), dst_ty.fmt(pt),
182172 });182147 });
182173182148
...@@ -182209,7 +182184,7 @@ fn airFloatFromInt(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -182209,7 +182184,7 @@ fn airFloatFromInt(self: *CodeGen, inst: Air.Inst.Index) !void {
182209 else => unreachable,182184 else => unreachable,
182210 },182185 },
182211 else => null,182186 else => null,
182212 }) orelse return self.fail("TODO implement airFloatFromInt from {} to {}", .{182187 }) orelse return self.fail("TODO implement airFloatFromInt from {f} to {f}", .{
182213 src_ty.fmt(pt), dst_ty.fmt(pt),182188 src_ty.fmt(pt), dst_ty.fmt(pt),
182214 });182189 });
182215 const dst_alias = dst_reg.to128();182190 const dst_alias = dst_reg.to128();
...@@ -182247,7 +182222,7 @@ fn airIntFromFloat(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -182247,7 +182222,7 @@ fn airIntFromFloat(self: *CodeGen, inst: Air.Inst.Index) !void {
182247 32, 64 => dst_size > 8,182222 32, 64 => dst_size > 8,
182248 else => unreachable,182223 else => unreachable,
182249 }) {182224 }) {
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}", .{
182251 src_ty.fmt(pt), dst_ty.fmt(pt),182226 src_ty.fmt(pt), dst_ty.fmt(pt),
182252 });182227 });
182253182228
...@@ -182531,7 +182506,7 @@ fn atomicOp(...@@ -182531,7 +182506,7 @@ fn atomicOp(
182531 else => null,182506 else => null,
182532 },182507 },
182533 else => unreachable,182508 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}", .{
182535 @tagName(op), val_ty.fmt(pt),182510 @tagName(op), val_ty.fmt(pt),
182536 });182511 });
182537 try self.genSetReg(sse_reg, val_ty, .{ .register = .rax }, .{});182512 try self.genSetReg(sse_reg, val_ty, .{ .register = .rax }, .{});
...@@ -183286,7 +183261,7 @@ fn airSplat(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -183286,7 +183261,7 @@ fn airSplat(self: *CodeGen, inst: Air.Inst.Index) !void {
183286 else => unreachable,183261 else => unreachable,
183287 },183262 },
183288 }183263 }
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)});
183290 };183265 };
183291 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });183266 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
183292}183267}
...@@ -183322,12 +183297,12 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -183322,12 +183297,12 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void {
183322 else183297 else
183323 try self.copyToTmpRegister(pred_ty, pred_mcv)183298 try self.copyToTmpRegister(pred_ty, pred_mcv)
183324 else183299 else
183325 return self.fail("TODO implement airSelect for {}", .{ty.fmt(pt)}),183300 return self.fail("TODO implement airSelect for {f}", .{ty.fmt(pt)}),
183326 else => unreachable,183301 else => unreachable,
183327 },183302 },
183328 .register_mask => |pred_reg_mask| {183303 .register_mask => |pred_reg_mask| {
183329 if (pred_reg_mask.info.scalar.bitSize(self.target) != 8 * elem_abi_size)183304 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
183332 const mask_reg: Register = if (need_xmm0 and pred_reg_mask.reg.id() != comptime Register.xmm0.id()) mask_reg: {183307 const mask_reg: Register = if (need_xmm0 and pred_reg_mask.reg.id() != comptime Register.xmm0.id()) mask_reg: {
183333 try self.register_manager.getKnownReg(.xmm0, null);183308 try self.register_manager.getKnownReg(.xmm0, null);
...@@ -183401,7 +183376,7 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -183401,7 +183376,7 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void {
183401 else183376 else
183402 null183377 null
183403 else183378 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)});
183405 if (has_avx) {183380 if (has_avx) {
183406 const rhs_alias = if (reuse_mcv.isRegister())183381 const rhs_alias = if (reuse_mcv.isRegister())
183407 registerAlias(reuse_mcv.getReg().?, abi_size)183382 registerAlias(reuse_mcv.getReg().?, abi_size)
...@@ -183554,7 +183529,7 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -183554,7 +183529,7 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void {
183554 else => unreachable,183529 else => unreachable,
183555 }),183530 }),
183556 );183531 );
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)});
183558 const elem_bits: u16 = @intCast(elem_abi_size * 8);183533 const elem_bits: u16 = @intCast(elem_abi_size * 8);
183559 if (!pred_fits_in_elem) if (self.hasFeature(.ssse3)) {183534 if (!pred_fits_in_elem) if (self.hasFeature(.ssse3)) {
183560 const mask_len = elem_abi_size * vec_len;183535 const mask_len = elem_abi_size * vec_len;
...@@ -183583,7 +183558,7 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -183583,7 +183558,7 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void {
183583 mask_alias,183558 mask_alias,
183584 mask_mem,183559 mask_mem,
183585 );183560 );
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)});
183587 {183562 {
183588 const mask_elem_ty = try pt.intType(.unsigned, elem_bits);183563 const mask_elem_ty = try pt.intType(.unsigned, elem_bits);
183589 const mask_ty = try pt.vectorType(.{ .len = vec_len, .child = mask_elem_ty.toIntern() });183564 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 {...@@ -183706,7 +183681,7 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void {
183706 else => null,183681 else => null,
183707 },183682 },
183708 },183683 },
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)});
183710 if (has_avx) {183685 if (has_avx) {
183711 const rhs_alias = if (rhs_mcv.isRegister())183686 const rhs_alias = if (rhs_mcv.isRegister())
183712 registerAlias(rhs_mcv.getReg().?, abi_size)183687 registerAlias(rhs_mcv.getReg().?, abi_size)
...@@ -184551,7 +184526,7 @@ fn airShuffle(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -184551,7 +184526,7 @@ fn airShuffle(self: *CodeGen, inst: Air.Inst.Index) !void {
184551 }184526 }
184552184527
184553 break :result null;184528 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}", .{
184555 lhs_ty.fmt(pt),184530 lhs_ty.fmt(pt),
184556 rhs_ty.fmt(pt),184531 rhs_ty.fmt(pt),
184557 dst_ty.fmt(pt),184532 dst_ty.fmt(pt),
...@@ -184800,7 +184775,7 @@ fn airMulAdd(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -184800,7 +184775,7 @@ fn airMulAdd(self: *CodeGen, inst: Air.Inst.Index) !void {
184800 32, 64 => !self.hasFeature(.fma),184775 32, 64 => !self.hasFeature(.fma),
184801 else => unreachable,184776 else => unreachable,
184802 }) {184777 }) {
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}", .{
184804 ty.fmt(pt),184779 ty.fmt(pt),
184805 });184780 });
184806184781
...@@ -184930,7 +184905,7 @@ fn airMulAdd(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -184930,7 +184905,7 @@ fn airMulAdd(self: *CodeGen, inst: Air.Inst.Index) !void {
184930 else => unreachable,184905 else => unreachable,
184931 }184906 }
184932 else184907 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
184935 var mops: [3]MCValue = undefined;184910 var mops: [3]MCValue = undefined;
184936 for (order, mcvs) |mop_index, mcv| mops[mop_index - 1] = mcv;184911 for (order, mcvs) |mop_index, mcv| mops[mop_index - 1] = mcv;
...@@ -185130,7 +185105,7 @@ fn airVaArg(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -185130,7 +185105,7 @@ fn airVaArg(self: *CodeGen, inst: Air.Inst.Index) !void {
185130 assert(classes.len == 1);185105 assert(classes.len == 1);
185131 unreachable;185106 unreachable;
185132 },185107 },
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)}),
185134 }185109 }
185135185110
185136 if (unused) break :result .unreach;185111 if (unused) break :result .unreach;
...@@ -185779,7 +185754,7 @@ fn splitType(self: *CodeGen, comptime parts_len: usize, ty: Type) ![parts_len]Ty...@@ -185779,7 +185754,7 @@ fn splitType(self: *CodeGen, comptime parts_len: usize, ty: Type) ![parts_len]Ty
185779 for (parts) |part| part_sizes += part.abiSize(zcu);185754 for (parts) |part| part_sizes += part.abiSize(zcu);
185780 if (part_sizes == ty.abiSize(zcu)) return parts;185755 if (part_sizes == ty.abiSize(zcu)) return parts;
185781 };185756 };
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) });
185783}185758}
185784185759
185785/// Truncates the value in the register in place.185760/// Truncates the value in the register in place.
...@@ -186153,7 +186128,7 @@ const Temp = struct {...@@ -186153,7 +186128,7 @@ const Temp = struct {
186153 cg.next_temp_index = @enumFromInt(@intFromEnum(new_temp_index) + 1);186128 cg.next_temp_index = @enumFromInt(@intFromEnum(new_temp_index) + 1);
186154 const mcv = temp.tracking(cg).short;186129 const mcv = temp.tracking(cg).short;
186155 switch (mcv) {186130 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 }),
186157 .register => |reg| {186132 .register => |reg| {
186158 const new_reg = try cg.register_manager.allocReg(new_temp_index.toIndex(), abi.RegisterClass.gp);186133 const new_reg = try cg.register_manager.allocReg(new_temp_index.toIndex(), abi.RegisterClass.gp);
186159 new_temp_index.tracking(cg).* = .init(.{ .register = new_reg });186134 new_temp_index.tracking(cg).* = .init(.{ .register = new_reg });
...@@ -186227,7 +186202,7 @@ const Temp = struct {...@@ -186227,7 +186202,7 @@ const Temp = struct {
186227 const new_temp_index = cg.next_temp_index;186202 const new_temp_index = cg.next_temp_index;
186228 cg.temp_type[@intFromEnum(new_temp_index)] = limb_ty;186203 cg.temp_type[@intFromEnum(new_temp_index)] = limb_ty;
186229 switch (temp.tracking(cg).short) {186204 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 }),
186231 .immediate => |imm| {186206 .immediate => |imm| {
186232 assert(limb_index == 0);186207 assert(limb_index == 0);
186233 new_temp_index.tracking(cg).* = .init(.{ .immediate = imm });186208 new_temp_index.tracking(cg).* = .init(.{ .immediate = imm });
...@@ -186568,7 +186543,7 @@ const Temp = struct {...@@ -186568,7 +186543,7 @@ const Temp = struct {
186568 },186543 },
186569 else => {},186544 else => {},
186570 }186545 }
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 });
186572 }186547 }
186573186548
186574 fn asMask(temp: Temp, info: MaskInfo, cg: *CodeGen) void {186549 fn asMask(temp: Temp, info: MaskInfo, cg: *CodeGen) void {
...@@ -186658,7 +186633,7 @@ const Temp = struct {...@@ -186658,7 +186633,7 @@ const Temp = struct {
186658 while (try ptr.toLea(cg)) {}186633 while (try ptr.toLea(cg)) {}
186659 const val_mcv = val.tracking(cg).short;186634 const val_mcv = val.tracking(cg).short;
186660 switch (val_mcv) {186635 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 }),
186662 .register => |val_reg| try ptr.loadReg(val_ty, registerAlias(186637 .register => |val_reg| try ptr.loadReg(val_ty, registerAlias(
186663 val_reg,186638 val_reg,
186664 @intCast(val_ty.abiSize(cg.pt.zcu)),186639 @intCast(val_ty.abiSize(cg.pt.zcu)),
...@@ -186698,7 +186673,7 @@ const Temp = struct {...@@ -186698,7 +186673,7 @@ const Temp = struct {
186698 {}) {186673 {}) {
186699 const val_mcv = val.tracking(cg).short;186674 const val_mcv = val.tracking(cg).short;
186700 switch (val_mcv) {186675 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 }),
186702 .undef => if (opts.safe) {186677 .undef => if (opts.safe) {
186703 var pat = try cg.tempInit(.u8, .{ .immediate = 0xaa });186678 var pat = try cg.tempInit(.u8, .{ .immediate = 0xaa });
186704 var len = try cg.tempInit(.usize, .{ .immediate = val_ty.abiSize(cg.pt.zcu) });186679 var len = try cg.tempInit(.usize, .{ .immediate = val_ty.abiSize(cg.pt.zcu) });
...@@ -186772,7 +186747,7 @@ const Temp = struct {...@@ -186772,7 +186747,7 @@ const Temp = struct {
186772 assert(!val_ty.optionalReprIsPayload(cg.pt.zcu));186747 assert(!val_ty.optionalReprIsPayload(cg.pt.zcu));
186773 break :first_ty opt_child;186748 break :first_ty opt_child;
186774 },186749 },
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) }),
186776 });186751 });
186777 const first_size: u31 = @intCast(first_ty.abiSize(cg.pt.zcu));186752 const first_size: u31 = @intCast(first_ty.abiSize(cg.pt.zcu));
186778 try ptr.storeRegs(first_ty, &.{registerAlias(val_reg_ov.reg, first_size)}, cg);186753 try ptr.storeRegs(first_ty, &.{registerAlias(val_reg_ov.reg, first_size)}, cg);
...@@ -186804,7 +186779,7 @@ const Temp = struct {...@@ -186804,7 +186779,7 @@ const Temp = struct {
186804186779
186805 fn readTo(src: *Temp, val_ty: Type, val_mcv: MCValue, opts: AccessOptions, cg: *CodeGen) InnerError!void {186780 fn readTo(src: *Temp, val_ty: Type, val_mcv: MCValue, opts: AccessOptions, cg: *CodeGen) InnerError!void {
186806 switch (val_mcv) {186781 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 }),
186808 .register => |val_reg| try src.readReg(opts.disp, val_ty, registerAlias(186783 .register => |val_reg| try src.readReg(opts.disp, val_ty, registerAlias(
186809 val_reg,186784 val_reg,
186810 @intCast(cg.unalignedSize(val_ty)),186785 @intCast(cg.unalignedSize(val_ty)),
...@@ -186844,7 +186819,7 @@ const Temp = struct {...@@ -186844,7 +186819,7 @@ const Temp = struct {
186844 {}) {186819 {}) {
186845 const val_mcv = val.tracking(cg).short;186820 const val_mcv = val.tracking(cg).short;
186846 switch (val_mcv) {186821 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 }),
186848 .none => {},186823 .none => {},
186849 .undef => if (opts.safe) {186824 .undef => if (opts.safe) {
186850 var dst_ptr = try cg.tempInit(.usize, dst.tracking(cg).short.address().offset(opts.disp));186825 var dst_ptr = try cg.tempInit(.usize, dst.tracking(cg).short.address().offset(opts.disp));
...@@ -186905,7 +186880,7 @@ const Temp = struct {...@@ -186905,7 +186880,7 @@ const Temp = struct {
186905 assert(!val_ty.optionalReprIsPayload(cg.pt.zcu));186880 assert(!val_ty.optionalReprIsPayload(cg.pt.zcu));
186906 break :first_ty opt_child;186881 break :first_ty opt_child;
186907 },186882 },
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) }),
186909 });186884 });
186910 const first_size: u31 = @intCast(first_ty.abiSize(cg.pt.zcu));186885 const first_size: u31 = @intCast(first_ty.abiSize(cg.pt.zcu));
186911 try dst.writeReg(opts.disp, first_ty, registerAlias(val_reg_ov.reg, first_size), cg);186886 try dst.writeReg(opts.disp, first_ty, registerAlias(val_reg_ov.reg, first_size), cg);
...@@ -191677,12 +191652,12 @@ const Temp = struct {...@@ -191677,12 +191652,12 @@ const Temp = struct {
191677 break :result result;191652 break :result result;
191678 },191653 },
191679 };191654 };
191680 tracking_log.debug("{} => {} (birth)", .{ inst, result });191655 tracking_log.debug("{f} => {f} (birth)", .{ inst, result });
191681 cg.inst_tracking.putAssumeCapacityNoClobber(inst, .init(result));191656 cg.inst_tracking.putAssumeCapacityNoClobber(inst, .init(result));
191682 },191657 },
191683 .temp => |temp_index| {191658 .temp => |temp_index| {
191684 const temp_tracking = temp_index.tracking(cg);191659 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 });
191686 cg.inst_tracking.putAssumeCapacityNoClobber(inst, .init(temp_tracking.short));191661 cg.inst_tracking.putAssumeCapacityNoClobber(inst, .init(temp_tracking.short));
191687 assert(cg.reuseTemp(inst, temp_index.toIndex(), temp_tracking));191662 assert(cg.reuseTemp(inst, temp_index.toIndex(), temp_tracking));
191688 },191663 },
...@@ -191757,7 +191732,7 @@ fn resetTemps(cg: *CodeGen, from_index: Temp.Index) InnerError!void {...@@ -191757,7 +191732,7 @@ fn resetTemps(cg: *CodeGen, from_index: Temp.Index) InnerError!void {
191757 const temp: Temp.Index = @enumFromInt(temp_index);191732 const temp: Temp.Index = @enumFromInt(temp_index);
191758 if (temp.isValid(cg)) {191733 if (temp.isValid(cg)) {
191759 any_valid = true;191734 any_valid = true;
191760 tracking_log.err("failed to kill {}: {}", .{191735 tracking_log.err("failed to kill {f}: {f}", .{
191761 temp.toIndex(),191736 temp.toIndex(),
191762 cg.temp_type[temp_index].fmt(cg.pt),191737 cg.temp_type[temp_index].fmt(cg.pt),
191763 });191738 });
src/codegen/c.zig+62-56
...@@ -340,13 +340,15 @@ fn isReservedIdent(ident: []const u8) bool {...@@ -340,13 +340,15 @@ fn isReservedIdent(ident: []const u8) bool {
340 } else return reserved_idents.has(ident);340 } else return reserved_idents.has(ident);
341}341}
342342
343fn formatIdent(343fn formatIdentSolo(ident: []const u8, writer: *std.io.Writer) std.io.Writer.Error!void {
344 ident: []const u8,344 return formatIdentOptions(ident, writer, true);
345 comptime fmt_str: []const u8,345}
346 _: std.fmt.FormatOptions,346
347 writer: anytype,347fn formatIdentUnsolo(ident: []const u8, writer: *std.io.Writer) std.io.Writer.Error!void {
348) @TypeOf(writer).Error!void {348 return formatIdentOptions(ident, writer, false);
349 const solo = fmt_str.len != 0 and fmt_str[0] == ' '; // space means solo; not part of a bigger ident.349}
350
351fn formatIdentOptions(ident: []const u8, writer: *std.io.Writer, solo: bool) std.io.Writer.Error!void {
350 if (solo and isReservedIdent(ident)) {352 if (solo and isReservedIdent(ident)) {
351 try writer.writeAll("zig_e_");353 try writer.writeAll("zig_e_");
352 }354 }
...@@ -363,30 +365,36 @@ fn formatIdent(...@@ -363,30 +365,36 @@ fn formatIdent(
363 }365 }
364 }366 }
365}367}
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) {
367 return .{ .data = ident };374 return .{ .data = ident };
368}375}
369376
370const CTypePoolStringFormatData = struct {377const CTypePoolStringFormatData = struct {
371 ctype_pool_string: CType.Pool.String,378 ctype_pool_string: CType.Pool.String,
372 ctype_pool: *const CType.Pool,379 ctype_pool: *const CType.Pool,
380 solo: bool,
373};381};
374fn formatCTypePoolString(382fn formatCTypePoolString(data: CTypePoolStringFormatData, writer: *std.io.Writer) std.io.Writer.Error!void {
375 data: CTypePoolStringFormatData,
376 comptime fmt_str: []const u8,
377 fmt_opts: std.fmt.FormatOptions,
378 writer: anytype,
379) @TypeOf(writer).Error!void {
380 if (data.ctype_pool_string.toSlice(data.ctype_pool)) |slice|383 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)
382 else385 else
383 try writer.print("{}", .{data.ctype_pool_string.fmt(data.ctype_pool)});386 try writer.print("{}", .{data.ctype_pool_string.fmt(data.ctype_pool)});
384}387}
385pub fn fmtCTypePoolString(388pub fn fmtCTypePoolString(
386 ctype_pool_string: CType.Pool.String,389 ctype_pool_string: CType.Pool.String,
387 ctype_pool: *const CType.Pool,390 ctype_pool: *const CType.Pool,
388) std.fmt.Formatter(formatCTypePoolString) {391 solo: bool,
389 return .{ .data = .{ .ctype_pool_string = ctype_pool_string, .ctype_pool = ctype_pool } };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 } };
390}398}
391399
392// Returns true if `formatIdent` would make any edits to ident.400// Returns true if `formatIdent` would make any edits to ident.
...@@ -596,7 +604,7 @@ pub const Function = struct {...@@ -596,7 +604,7 @@ pub const Function = struct {
596 return f.object.dg.renderIntCast(w, dest_ty, .{ .c_value = .{ .f = f, .value = src, .v = v } }, src_ty, location);604 return f.object.dg.renderIntCast(w, dest_ty, .{ .c_value = .{ .f = f, .value = src, .v = v } }, src_ty, location);
597 }605 }
598606
599 fn fmtIntLiteral(f: *Function, val: Value) !std.fmt.Formatter(formatIntLiteral) {607 fn fmtIntLiteral(f: *Function, val: Value) !std.fmt.Formatter(FormatIntLiteralContext, formatIntLiteral) {
600 return f.object.dg.fmtIntLiteral(val, .Other);608 return f.object.dg.fmtIntLiteral(val, .Other);
601 }609 }
602610
...@@ -614,16 +622,16 @@ pub const Function = struct {...@@ -614,16 +622,16 @@ pub const Function = struct {
614 gop.value_ptr.* = .{622 gop.value_ptr.* = .{
615 .fn_name = switch (key) {623 .fn_name = switch (key) {
616 .tag_name,624 .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}", .{
618 @tagName(key),626 @tagName(key),
619 fmtIdent(ip.loadEnumType(enum_ty).name.toSlice(ip)),627 fmtIdentUnsolo(ip.loadEnumType(enum_ty).name.toSlice(ip)),
620 @intFromEnum(enum_ty),628 @intFromEnum(enum_ty),
621 }),629 }),
622 .never_tail,630 .never_tail,
623 .never_inline,631 .never_inline,
624 => |owner_nav| try ctype_pool.fmt(gpa, "zig_{s}_{}__{d}", .{632 => |owner_nav| try ctype_pool.fmt(gpa, "zig_{s}_{}__{d}", .{
625 @tagName(key),633 @tagName(key),
626 fmtIdent(ip.getNav(owner_nav).name.toSlice(ip)),634 fmtIdentUnsolo(ip.getNav(owner_nav).name.toSlice(ip)),
627 @intFromEnum(owner_nav),635 @intFromEnum(owner_nav),
628 }),636 }),
629 },637 },
...@@ -965,7 +973,7 @@ pub const DeclGen = struct {...@@ -965,7 +973,7 @@ pub const DeclGen = struct {
965973
966 fn renderErrorName(dg: *DeclGen, writer: anytype, err_name: InternPool.NullTerminatedString) !void {974 fn renderErrorName(dg: *DeclGen, writer: anytype, err_name: InternPool.NullTerminatedString) !void {
967 const ip = &dg.pt.zcu.intern_pool;975 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))});
969 }977 }
970978
971 fn renderValue(979 fn renderValue(
...@@ -1551,7 +1559,7 @@ pub const DeclGen = struct {...@@ -1551,7 +1559,7 @@ pub const DeclGen = struct {
1551 .payload => {1559 .payload => {
1552 try writer.writeByte('{');1560 try writer.writeByte('{');
1553 if (field_ty.hasRuntimeBits(zcu)) {1561 if (field_ty.hasRuntimeBits(zcu)) {
1554 try writer.print(" .{ } = ", .{fmtIdent(field_name.toSlice(ip))});1562 try writer.print(" .{ } = ", .{fmtIdentSolo(field_name.toSlice(ip))});
1555 try dg.renderValue(1563 try dg.renderValue(
1556 writer,1564 writer,
1557 Value.fromInterned(un.val),1565 Value.fromInterned(un.val),
...@@ -1888,7 +1896,7 @@ pub const DeclGen = struct {...@@ -1888,7 +1896,7 @@ pub const DeclGen = struct {
1888 kind: CType.Kind,1896 kind: CType.Kind,
1889 name: union(enum) {1897 name: union(enum) {
1890 nav: InternPool.Nav.Index,1898 nav: InternPool.Nav.Index,
1891 fmt_ctype_pool_string: std.fmt.Formatter(formatCTypePoolString),1899 fmt_ctype_pool_string: std.fmt.Formatter(CTypePoolStringFormatData, formatCTypePoolString),
1892 @"export": struct {1900 @"export": struct {
1893 main_name: InternPool.NullTerminatedString,1901 main_name: InternPool.NullTerminatedString,
1894 extern_name: InternPool.NullTerminatedString,1902 extern_name: InternPool.NullTerminatedString,
...@@ -1933,7 +1941,7 @@ pub const DeclGen = struct {...@@ -1933,7 +1941,7 @@ pub const DeclGen = struct {
1933 switch (name) {1941 switch (name) {
1934 .nav => |nav| try dg.renderNavName(w, nav),1942 .nav => |nav| try dg.renderNavName(w, nav),
1935 .fmt_ctype_pool_string => |fmt| try w.print("{ }", .{fmt}),1943 .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))}),
1937 }1945 }
19381946
1939 try renderTypeSuffix(1947 try renderTypeSuffix(
...@@ -1961,13 +1969,13 @@ pub const DeclGen = struct {...@@ -1961,13 +1969,13 @@ pub const DeclGen = struct {
1961 const is_export = @"export".extern_name != @"export".main_name;1969 const is_export = @"export".extern_name != @"export".main_name;
1962 if (is_mangled and is_export) {1970 if (is_mangled and is_export) {
1963 try w.print(" zig_mangled_export({ }, {s}, {s})", .{1971 try w.print(" zig_mangled_export({ }, {s}, {s})", .{
1964 fmtIdent(extern_name),1972 fmtIdentSolo(extern_name),
1965 fmtStringLiteral(extern_name, null),1973 fmtStringLiteral(extern_name, null),
1966 fmtStringLiteral(@"export".main_name.toSlice(ip), null),1974 fmtStringLiteral(@"export".main_name.toSlice(ip), null),
1967 });1975 });
1968 } else if (is_mangled) {1976 } else if (is_mangled) {
1969 try w.print(" zig_mangled({ }, {s})", .{1977 try w.print(" zig_mangled({ }, {s})", .{
1970 fmtIdent(extern_name), fmtStringLiteral(extern_name, null),1978 fmtIdentSolo(extern_name), fmtStringLiteral(extern_name, null),
1971 });1979 });
1972 } else if (is_export) {1980 } else if (is_export) {
1973 try w.print(" zig_export({s}, {s})", .{1981 try w.print(" zig_export({s}, {s})", .{
...@@ -2198,7 +2206,7 @@ pub const DeclGen = struct {...@@ -2198,7 +2206,7 @@ pub const DeclGen = struct {
2198 .new_local, .local => |i| try w.print("t{d}", .{i}),2206 .new_local, .local => |i| try w.print("t{d}", .{i}),
2199 .constant => |uav| try renderUavName(w, uav),2207 .constant => |uav| try renderUavName(w, uav),
2200 .nav => |nav| try dg.renderNavName(w, nav),2208 .nav => |nav| try dg.renderNavName(w, nav),
2201 .identifier => |ident| try w.print("{ }", .{fmtIdent(ident)}),2209 .identifier => |ident| try w.print("{ }", .{fmtIdentSolo(ident)}),
2202 else => unreachable,2210 else => unreachable,
2203 }2211 }
2204 }2212 }
...@@ -2215,13 +2223,13 @@ pub const DeclGen = struct {...@@ -2215,13 +2223,13 @@ pub const DeclGen = struct {
2215 try dg.renderNavName(w, nav);2223 try dg.renderNavName(w, nav);
2216 },2224 },
2217 .undef => |ty| try dg.renderUndefValue(w, ty, .Other),2225 .undef => |ty| try dg.renderUndefValue(w, ty, .Other),
2218 .identifier => |ident| try w.print("{ }", .{fmtIdent(ident)}),2226 .identifier => |ident| try w.print("{ }", .{fmtIdentSolo(ident)}),
2219 .payload_identifier => |ident| try w.print("{ }.{ }", .{2227 .payload_identifier => |ident| try w.print("{ }.{ }", .{
2220 fmtIdent("payload"),2228 fmtIdentSolo("payload"),
2221 fmtIdent(ident),2229 fmtIdentSolo(ident),
2222 }),2230 }),
2223 .ctype_pool_string => |string| try w.print("{ }", .{2231 .ctype_pool_string => |string| try w.print("{f}", .{
2224 fmtCTypePoolString(string, &dg.ctype_pool),2232 fmtCTypePoolString(string, &dg.ctype_pool, true),
2225 }),2233 }),
2226 }2234 }
2227 }2235 }
...@@ -2245,10 +2253,10 @@ pub const DeclGen = struct {...@@ -2245,10 +2253,10 @@ pub const DeclGen = struct {
2245 },2253 },
2246 .nav_ref => |nav| try dg.renderNavName(w, nav),2254 .nav_ref => |nav| try dg.renderNavName(w, nav),
2247 .undef => unreachable,2255 .undef => unreachable,
2248 .identifier => |ident| try w.print("(*{ })", .{fmtIdent(ident)}),2256 .identifier => |ident| try w.print("(*{ })", .{fmtIdentSolo(ident)}),
2249 .payload_identifier => |ident| try w.print("(*{ }.{ })", .{2257 .payload_identifier => |ident| try w.print("(*{ }.{ })", .{
2250 fmtIdent("payload"),2258 fmtIdentSolo("payload"),
2251 fmtIdent(ident),2259 fmtIdentSolo(ident),
2252 }),2260 }),
2253 }2261 }
2254 }2262 }
...@@ -2334,14 +2342,14 @@ pub const DeclGen = struct {...@@ -2334,14 +2342,14 @@ pub const DeclGen = struct {
2334 const nav = ip.getNav(nav_index);2342 const nav = ip.getNav(nav_index);
2335 if (nav.getExtern(ip)) |@"extern"| {2343 if (nav.getExtern(ip)) |@"extern"| {
2336 try writer.print("{ }", .{2344 try writer.print("{ }", .{
2337 fmtIdent(ip.getNav(@"extern".owner_nav).name.toSlice(ip)),2345 fmtIdentSolo(ip.getNav(@"extern".owner_nav).name.toSlice(ip)),
2338 });2346 });
2339 } else {2347 } else {
2340 // MSVC has a limit of 4095 character token length limit, and fmtIdent can (worst case),2348 // MSVC has a limit of 4095 character token length limit, and fmtIdent can (worst case),
2341 // expand to 3x the length of its input, but let's cut it off at a much shorter limit.2349 // expand to 3x the length of its input, but let's cut it off at a much shorter limit.
2342 const fqn_slice = ip.getNav(nav_index).fqn.toSlice(ip);2350 const fqn_slice = ip.getNav(nav_index).fqn.toSlice(ip);
2343 try writer.print("{}__{d}", .{2351 try writer.print("{}__{d}", .{
2344 fmtIdent(fqn_slice[0..@min(fqn_slice.len, 100)]),2352 fmtIdentUnsolo(fqn_slice[0..@min(fqn_slice.len, 100)]),
2345 @intFromEnum(nav_index),2353 @intFromEnum(nav_index),
2346 });2354 });
2347 }2355 }
...@@ -2452,7 +2460,7 @@ fn renderFwdDeclTypeName(...@@ -2452,7 +2460,7 @@ fn renderFwdDeclTypeName(
2452 switch (fwd_decl.name) {2460 switch (fwd_decl.name) {
2453 .anon => try w.print("anon__lazy_{d}", .{@intFromEnum(ctype.index)}),2461 .anon => try w.print("anon__lazy_{d}", .{@intFromEnum(ctype.index)}),
2454 .index => |index| try w.print("{}__{d}", .{2462 .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)),
2456 @intFromEnum(index),2464 @intFromEnum(index),
2457 }),2465 }),
2458 }2466 }
...@@ -2666,7 +2674,7 @@ fn renderFields(...@@ -2666,7 +2674,7 @@ fn renderFields(
2666 .suffix,2674 .suffix,
2667 .{},2675 .{},
2668 );2676 );
2669 try writer.print("{}{ }", .{ trailing, fmtCTypePoolString(field_info.name, ctype_pool) });2677 try writer.print("{}{f}", .{ trailing, fmtCTypePoolString(field_info.name, ctype_pool, true) });
2670 try renderTypeSuffix(.flush, ctype_pool, zcu, writer, field_info.ctype, .suffix, .{});2678 try renderTypeSuffix(.flush, ctype_pool, zcu, writer, field_info.ctype, .suffix, .{});
2671 try writer.writeAll(";\n");2679 try writer.writeAll(";\n");
2672 }2680 }
...@@ -2841,7 +2849,7 @@ pub fn genErrDecls(o: *Object) !void {...@@ -2841,7 +2849,7 @@ pub fn genErrDecls(o: *Object) !void {
2841 const name = name_nts.toSlice(ip);2849 const name = name_nts.toSlice(ip);
2842 if (val > 1) try writer.writeAll(", ");2850 if (val > 1) try writer.writeAll(", ");
2843 try writer.print("{{" ++ name_prefix ++ "{}, {}}}", .{2851 try writer.print("{{" ++ name_prefix ++ "{}, {}}}", .{
2844 fmtIdent(name),2852 fmtIdentUnsolo(name),
2845 try o.dg.fmtIntLiteral(try pt.intValue(.usize, name.len), .StaticInitializer),2853 try o.dg.fmtIntLiteral(try pt.intValue(.usize, name.len), .StaticInitializer),
2846 });2854 });
2847 }2855 }
...@@ -2891,7 +2899,7 @@ pub fn genLazyFn(o: *Object, lazy_ctype_pool: *const CType.Pool, lazy_fn: LazyFn...@@ -2891,7 +2899,7 @@ pub fn genLazyFn(o: *Object, lazy_ctype_pool: *const CType.Pool, lazy_fn: LazyFn
2891 try w.writeAll(";\n return (");2899 try w.writeAll(";\n return (");
2892 try o.dg.renderType(w, name_slice_ty);2900 try o.dg.renderType(w, name_slice_ty);
2893 try w.print("){{{}, {}}};\n", .{2901 try w.print("){{{}, {}}};\n", .{
2894 fmtIdent("name"),2902 fmtIdentUnsolo("name"),
2895 try o.dg.fmtIntLiteral(try pt.intValue(.usize, tag_name_len), .Other),2903 try o.dg.fmtIntLiteral(try pt.intValue(.usize, tag_name_len), .Other),
2896 });2904 });
28972905
...@@ -3204,7 +3212,7 @@ pub fn genExports(dg: *DeclGen, exported: Zcu.Exported, export_indices: []const...@@ -3204,7 +3212,7 @@ pub fn genExports(dg: *DeclGen, exported: Zcu.Exported, export_indices: []const
3204 .uav => |uav| try DeclGen.renderUavName(fwd, Value.fromInterned(uav)),3212 .uav => |uav| try DeclGen.renderUavName(fwd, Value.fromInterned(uav)),
3205 }3213 }
3206 try fwd.writeByte(' ');3214 try fwd.writeByte(' ');
3207 try fwd.print("{ }", .{fmtIdent(main_name.toSlice(ip))});3215 try fwd.print("{ }", .{fmtIdentSolo(main_name.toSlice(ip))});
3208 try fwd.writeByte('\n');3216 try fwd.writeByte('\n');
32093217
3210 const exported_val = exported.getValue(zcu);3218 const exported_val = exported.getValue(zcu);
...@@ -3250,13 +3258,13 @@ pub fn genExports(dg: *DeclGen, exported: Zcu.Exported, export_indices: []const...@@ -3250,13 +3258,13 @@ pub fn genExports(dg: *DeclGen, exported: Zcu.Exported, export_indices: []const
3250 );3258 );
3251 if (is_mangled and is_export) {3259 if (is_mangled and is_export) {
3252 try fwd.print(" zig_mangled_export({ }, {s}, {s})", .{3260 try fwd.print(" zig_mangled_export({ }, {s}, {s})", .{
3253 fmtIdent(extern_name),3261 fmtIdentSolo(extern_name),
3254 fmtStringLiteral(extern_name, null),3262 fmtStringLiteral(extern_name, null),
3255 fmtStringLiteral(main_name.toSlice(ip), null),3263 fmtStringLiteral(main_name.toSlice(ip), null),
3256 });3264 });
3257 } else if (is_mangled) {3265 } else if (is_mangled) {
3258 try fwd.print(" zig_mangled({ }, {s})", .{3266 try fwd.print(" zig_mangled({ }, {s})", .{
3259 fmtIdent(extern_name), fmtStringLiteral(extern_name, null),3267 fmtIdentSolo(extern_name), fmtStringLiteral(extern_name, null),
3260 });3268 });
3261 } else if (is_export) {3269 } else if (is_export) {
3262 try fwd.print(" zig_export({s}, {s})", .{3270 try fwd.print(" zig_export({s}, {s})", .{
...@@ -4538,7 +4546,7 @@ fn airCmpLtErrorsLen(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -4538,7 +4546,7 @@ fn airCmpLtErrorsLen(f: *Function, inst: Air.Inst.Index) !CValue {
4538 try f.writeCValue(writer, local, .Other);4546 try f.writeCValue(writer, local, .Other);
4539 try writer.writeAll(" = ");4547 try writer.writeAll(" = ");
4540 try f.writeCValue(writer, operand, .Other);4548 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")});
4542 return local;4550 return local;
4543}4551}
45444552
...@@ -8202,10 +8210,9 @@ fn stringLiteral(...@@ -8202,10 +8210,9 @@ fn stringLiteral(
8202const FormatStringContext = struct { str: []const u8, sentinel: ?u8 };8210const FormatStringContext = struct { str: []const u8, sentinel: ?u8 };
8203fn formatStringLiteral(8211fn formatStringLiteral(
8204 data: FormatStringContext,8212 data: FormatStringContext,
8205 comptime fmt: []const u8,8213 writer: *std.io.Writer,
8206 _: std.fmt.FormatOptions,8214 comptime fmt: []const u8, // TODO move this state to FormatStringContext
8207 writer: anytype,8215) std.io.Writer.Error!void {
8208) @TypeOf(writer).Error!void {
8209 if (fmt.len != 1 or fmt[0] != 's') @compileError("Invalid fmt: " ++ fmt);8216 if (fmt.len != 1 or fmt[0] != 's') @compileError("Invalid fmt: " ++ fmt);
82108217
8211 var literal = stringLiteral(writer, data.str.len + @intFromBool(data.sentinel != null));8218 var literal = stringLiteral(writer, data.str.len + @intFromBool(data.sentinel != null));
...@@ -8215,7 +8222,7 @@ fn formatStringLiteral(...@@ -8215,7 +8222,7 @@ fn formatStringLiteral(
8215 try literal.end();8222 try literal.end();
8216}8223}
82178224
8218fn fmtStringLiteral(str: []const u8, sentinel: ?u8) std.fmt.Formatter(formatStringLiteral) {8225fn fmtStringLiteral(str: []const u8, sentinel: ?u8) std.fmt.Formatter(FormatStringContext, formatStringLiteral) {
8219 return .{ .data = .{ .str = str, .sentinel = sentinel } };8226 return .{ .data = .{ .str = str, .sentinel = sentinel } };
8220}8227}
82218228
...@@ -8234,10 +8241,9 @@ const FormatIntLiteralContext = struct {...@@ -8234,10 +8241,9 @@ const FormatIntLiteralContext = struct {
8234};8241};
8235fn formatIntLiteral(8242fn formatIntLiteral(
8236 data: FormatIntLiteralContext,8243 data: FormatIntLiteralContext,
8237 comptime fmt: []const u8,8244 writer: *std.io.Writer,
8238 options: std.fmt.FormatOptions,8245 comptime fmt: []const u8, // TODO move this state to FormatIntLiteralContext
8239 writer: anytype,8246) std.io.Writer.Error!void {
8240) @TypeOf(writer).Error!void {
8241 const pt = data.dg.pt;8247 const pt = data.dg.pt;
8242 const zcu = pt.zcu;8248 const zcu = pt.zcu;
8243 const target = &data.dg.mod.resolved_target.result;8249 const target = &data.dg.mod.resolved_target.result;
...@@ -8406,7 +8412,7 @@ fn formatIntLiteral(...@@ -8406,7 +8412,7 @@ fn formatIntLiteral(
8406 .kind = data.kind,8412 .kind = data.kind,
8407 .ctype = c_limb_ctype,8413 .ctype = c_limb_ctype,
8408 .val = try pt.intValue_big(.comptime_int, c_limb_mut.toConst()),8414 .val = try pt.intValue_big(.comptime_int, c_limb_mut.toConst()),
8409 }, fmt, options, writer);8415 }, fmt, writer);
8410 }8416 }
8411 }8417 }
8412 try data.ctype.renderLiteralSuffix(writer, ctype_pool);8418 try data.ctype.renderLiteralSuffix(writer, ctype_pool);
src/codegen/c/Type.zig+2-8
...@@ -938,19 +938,13 @@ pub const Pool = struct {...@@ -938,19 +938,13 @@ pub const Pool = struct {
938 index: String.Index,938 index: String.Index,
939939
940 const FormatData = struct { string: String, pool: *const Pool };940 const FormatData = struct { string: String, pool: *const Pool };
941 fn format(941 fn format(data: FormatData, writer: *std.io.Writer) std.io.Writer.Error!void {
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 ++ "'");
948 if (data.string.toSlice(data.pool)) |slice|942 if (data.string.toSlice(data.pool)) |slice|
949 try writer.writeAll(slice)943 try writer.writeAll(slice)
950 else944 else
951 try writer.print("f{d}", .{@intFromEnum(data.string.index)});945 try writer.print("f{d}", .{@intFromEnum(data.string.index)});
952 }946 }
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) {
954 return .{ .data = .{ .string = str, .pool = pool } };948 return .{ .data = .{ .string = str, .pool = pool } };
955 }949 }
956950
src/link/Coff.zig+14-29
...@@ -3061,40 +3061,25 @@ const ImportTable = struct {...@@ -3061,40 +3061,25 @@ const ImportTable = struct {
3061 return base_vaddr + index * @sizeOf(u64);3061 return base_vaddr + index * @sizeOf(u64);
3062 }3062 }
30633063
3064 const FormatContext = struct {3064 const Format = struct {
3065 itab: ImportTable,3065 itab: ImportTable,
3066 ctx: Context,3066 ctx: Context,
3067 };
30683067
3069 fn format(itab: ImportTable, comptime unused_format_string: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {3068 fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
3070 _ = itab;3069 const lib_name = f.ctx.coff.temp_strtab.getAssumeExists(f.ctx.name_off);
3071 _ = unused_format_string;3070 const base_vaddr = getBaseAddress(f.ctx);
3072 _ = options;3071 try writer.print("IAT({s}.dll) @{x}:", .{ lib_name, base_vaddr });
3073 _ = writer;3072 for (f.itab.entries.items, 0..) |entry, i| {
3074 @compileError("do not format ImportTable directly; use itab.fmtDebug()");3073 try writer.print("\n {d}@{?x} => {s}", .{
3075 }3074 i,
30763075 f.itab.getImportAddress(entry, f.ctx),
3077 fn format2(3076 f.ctx.coff.getSymbolName(entry),
3078 fmt_ctx: FormatContext,3077 });
3079 comptime unused_format_string: []const u8,3078 }
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 });
3094 }3079 }
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) {
3098 return .{ .data = .{ .itab = itab, .ctx = ctx } };3083 return .{ .data = .{ .itab = itab, .ctx = ctx } };
3099 }3084 }
31003085
src/link/Elf.zig+10-39
...@@ -3860,26 +3860,19 @@ pub fn failFile(...@@ -3860,26 +3860,19 @@ pub fn failFile(
3860 return error.LinkFailure;3860 return error.LinkFailure;
3861}3861}
38623862
3863const FormatShdrCtx = struct {3863const FormatShdr = struct {
3864 elf_file: *Elf,3864 elf_file: *Elf,
3865 shdr: elf.Elf64_Shdr,3865 shdr: elf.Elf64_Shdr,
3866};3866};
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) {
3869 return .{ .data = .{3869 return .{ .data = .{
3870 .shdr = shdr,3870 .shdr = shdr,
3871 .elf_file = self,3871 .elf_file = self,
3872 } };3872 } };
3873}3873}
38743874
3875fn formatShdr(3875fn formatShdr(ctx: FormatShdr, writer: *std.io.Writer) std.io.Writer.Error!void {
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;
3883 const shdr = ctx.shdr;3876 const shdr = ctx.shdr;
3884 try writer.print("{s} : @{x} ({x}) : align({x}) : size({x}) : entsize({x}) : flags({})", .{3877 try writer.print("{s} : @{x} ({x}) : align({x}) : size({x}) : entsize({x}) : flags({})", .{
3885 ctx.elf_file.getShString(shdr.sh_name), shdr.sh_offset,3878 ctx.elf_file.getShString(shdr.sh_name), shdr.sh_offset,
...@@ -3889,18 +3882,11 @@ fn formatShdr(...@@ -3889,18 +3882,11 @@ fn formatShdr(
3889 });3882 });
3890}3883}
38913884
3892pub fn fmtShdrFlags(sh_flags: u64) std.fmt.Formatter(formatShdrFlags) {3885pub fn fmtShdrFlags(sh_flags: u64) std.fmt.Formatter(u64, formatShdrFlags) {
3893 return .{ .data = sh_flags };3886 return .{ .data = sh_flags };
3894}3887}
38953888
3896fn formatShdrFlags(3889fn formatShdrFlags(sh_flags: u64, writer: *std.io.Writer) std.io.Writer.Error!void {
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;
3904 if (elf.SHF_WRITE & sh_flags != 0) {3890 if (elf.SHF_WRITE & sh_flags != 0) {
3905 try writer.writeAll("W");3891 try writer.writeAll("W");
3906 }3892 }
...@@ -3945,26 +3931,19 @@ fn formatShdrFlags(...@@ -3945,26 +3931,19 @@ fn formatShdrFlags(
3945 }3931 }
3946}3932}
39473933
3948const FormatPhdrCtx = struct {3934const FormatPhdr = struct {
3949 elf_file: *Elf,3935 elf_file: *Elf,
3950 phdr: elf.Elf64_Phdr,3936 phdr: elf.Elf64_Phdr,
3951};3937};
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) {
3954 return .{ .data = .{3940 return .{ .data = .{
3955 .phdr = phdr,3941 .phdr = phdr,
3956 .elf_file = self,3942 .elf_file = self,
3957 } };3943 } };
3958}3944}
39593945
3960fn formatPhdr(3946fn formatPhdr(ctx: FormatPhdr, writer: *std.io.Writer) std.io.Writer.Error!void {
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;
3968 const phdr = ctx.phdr;3947 const phdr = ctx.phdr;
3969 const write = phdr.p_flags & elf.PF_W != 0;3948 const write = phdr.p_flags & elf.PF_W != 0;
3970 const read = phdr.p_flags & elf.PF_R != 0;3949 const read = phdr.p_flags & elf.PF_R != 0;
...@@ -3991,19 +3970,11 @@ fn formatPhdr(...@@ -3991,19 +3970,11 @@ fn formatPhdr(
3991 });3970 });
3992}3971}
39933972
3994pub fn dumpState(self: *Elf) std.fmt.Formatter(fmtDumpState) {3973pub fn dumpState(self: *Elf) std.fmt.Formatter(*Elf, fmtDumpState) {
3995 return .{ .data = self };3974 return .{ .data = self };
3996}3975}
39973976
3998fn fmtDumpState(3977fn fmtDumpState(self: *Elf, writer: *std.io.Writer) std.io.Writer.Error!void {
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
4007 const shared_objects = self.shared_objects.values();3978 const shared_objects = self.shared_objects.values();
40083979
4009 if (self.zigObjectPtr()) |zig_object| {3980 if (self.zigObjectPtr()) |zig_object| {
src/link/Elf/Archive.zig+12-19
...@@ -214,35 +214,28 @@ pub const ArSymtab = struct {...@@ -214,35 +214,28 @@ pub const ArSymtab = struct {
214 @compileError("do not format ar symtab directly; use fmt instead");214 @compileError("do not format ar symtab directly; use fmt instead");
215 }215 }
216216
217 const FormatContext = struct {217 const Format = struct {
218 ar: ArSymtab,218 ar: ArSymtab,
219 elf_file: *Elf,219 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 }
220 };230 };
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) {
223 return .{ .data = .{233 return .{ .data = .{
224 .ar = ar,234 .ar = ar,
225 .elf_file = elf_file,235 .elf_file = elf_file,
226 } };236 } };
227 }237 }
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
246 const Entry = struct {239 const Entry = struct {
247 /// Offset into the string table.240 /// Offset into the string table.
248 off: u32,241 off: u32,
src/link/Elf/Atom.zig+28-48
...@@ -904,65 +904,45 @@ pub fn setExtra(atom: Atom, extras: Extra, elf_file: *Elf) void {...@@ -904,65 +904,45 @@ pub fn setExtra(atom: Atom, extras: Extra, elf_file: *Elf) void {
904 atom.file(elf_file).?.setAtomExtra(atom.extra_index, extras);904 atom.file(elf_file).?.setAtomExtra(atom.extra_index, extras);
905}905}
906906
907pub fn format(907pub fn fmt(atom: Atom, elf_file: *Elf) std.fmt.Formatter(Format, Format.default) {
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) {
921 return .{ .data = .{908 return .{ .data = .{
922 .atom = atom,909 .atom = atom,
923 .elf_file = elf_file,910 .elf_file = elf_file,
924 } };911 } };
925}912}
926913
927const FormatContext = struct {914const Format = struct {
928 atom: Atom,915 atom: Atom,
929 elf_file: *Elf,916 elf_file: *Elf,
930};
931917
932fn format2(918 fn default(f: Format, w: *std.io.Writer) std.io.Writer.Error!void {
933 ctx: FormatContext,919 const atom = f.atom;
934 comptime unused_fmt_string: []const u8,920 const elf_file = f.elf_file;
935 options: std.fmt.FormatOptions,921 try w.print("atom({d}) : {s} : @{x} : shdr({d}) : align({x}) : size({x}) : prev({}) : next({})", .{
936 writer: anytype,922 atom.atom_index, atom.name(elf_file), atom.address(elf_file),
937) !void {923 atom.output_section_index, atom.alignment.toByteUnits() orelse 0, atom.size,
938 _ = options;924 atom.prev_atom_ref, atom.next_atom_ref,
939 _ = unused_fmt_string;925 });
940 const atom = ctx.atom;926 if (atom.file(elf_file)) |atom_file| switch (atom_file) {
941 const elf_file = ctx.elf_file;927 .object => |object| {
942 try writer.print("atom({d}) : {s} : @{x} : shdr({d}) : align({x}) : size({x}) : prev({}) : next({})", .{928 if (atom.fdes(object).len > 0) {
943 atom.atom_index, atom.name(elf_file), atom.address(elf_file),929 try w.writeAll(" : fdes{ ");
944 atom.output_section_index, atom.alignment.toByteUnits() orelse 0, atom.size,930 const extras = atom.extra(elf_file);
945 atom.prev_atom_ref, atom.next_atom_ref,931 for (atom.fdes(object), extras.fde_start..) |fde, i| {
946 });932 try w.print("{d}", .{i});
947 if (atom.file(elf_file)) |atom_file| switch (atom_file) {933 if (!fde.alive) try w.writeAll("([*])");
948 .object => |object| {934 if (i - extras.fde_start < extras.fde_count - 1) try w.writeAll(", ");
949 if (atom.fdes(object).len > 0) {935 }
950 try writer.writeAll(" : fdes{ ");936 try w.writeAll(" }");
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(", ");
956 }937 }
957 try writer.writeAll(" }");938 },
958 }939 else => {},
959 },940 };
960 else => {},941 if (!atom.alive) {
961 };942 try w.writeAll(" : [*]");
962 if (!atom.alive) {943 }
963 try writer.writeAll(" : [*]");
964 }944 }
965}945};
966946
967pub const Index = u32;947pub const Index = u32;
968948
src/link/Elf/AtomList.zig+19-36
...@@ -167,46 +167,29 @@ pub fn lastAtom(list: AtomList, elf_file: *Elf) *Atom {...@@ -167,46 +167,29 @@ pub fn lastAtom(list: AtomList, elf_file: *Elf) *Atom {
167 return elf_file.atom(list.atoms.keys()[list.atoms.keys().len - 1]).?;167 return elf_file.atom(list.atoms.keys()[list.atoms.keys().len - 1]).?;
168}168}
169169
170pub fn format(170const Format = struct {
171 list: AtomList,171 atom_list: AtomList,
172 comptime unused_fmt_string: []const u8,172 elf_file: *Elf,
173 options: std.fmt.FormatOptions,173
174 writer: anytype,174 fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
175) !void {175 const list, const elf_file = f;
176 _ = list;176 try writer.print("list : @{x} : shdr({d}) : align({x}) : size({x})", .{
177 _ = unused_fmt_string;177 list.address(elf_file), list.output_section_index,
178 _ = options;178 list.alignment.toByteUnits() orelse 0, list.size,
179 _ = writer;179 });
180 @compileError("do not format AtomList directly");180 try writer.writeAll(" : atoms{ ");
181}181 for (list.atoms.keys(), 0..) |ref, i| {
182182 try writer.print("{}", .{ref});
183const FormatCtx = struct { AtomList, *Elf };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) {
186 return .{ .data = .{ list, elf_file } };190 return .{ .data = .{ list, elf_file } };
187}191}
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
210const assert = std.debug.assert;193const assert = std.debug.assert;
211const elf = std.elf;194const elf = std.elf;
212const log = std.log.scoped(.link);195const 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...@@ -437,38 +437,31 @@ pub fn setSymbolExtra(self: *LinkerDefined, index: u32, extra: Symbol.Extra) voi
437 }437 }
438}438}
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) {
441 return .{ .data = .{441 return .{ .data = .{
442 .self = self,442 .self = self,
443 .elf_file = elf_file,443 .elf_file = elf_file,
444 } };444 } };
445}445}
446446
447const FormatContext = struct {447const Format = struct {
448 self: *LinkerDefined,448 self: *LinkerDefined,
449 elf_file: *Elf,449 elf_file: *Elf,
450};
451450
452fn formatSymtab(451 fn symtab(ctx: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
453 ctx: FormatContext,452 const self = ctx.self;
454 comptime unused_fmt_string: []const u8,453 const elf_file = ctx.elf_file;
455 options: std.fmt.FormatOptions,454 try writer.writeAll(" globals\n");
456 writer: anytype,455 for (self.symbols.items, 0..) |sym, i| {
457) !void {456 const ref = self.resolveSymbol(@intCast(i), elf_file);
458 _ = unused_fmt_string;457 if (elf_file.symbol(ref)) |ref_sym| {
459 _ = options;458 try writer.print(" {f}\n", .{ref_sym.fmt(elf_file)});
460 const self = ctx.self;459 } else {
461 const elf_file = ctx.elf_file;460 try writer.print(" {s} : unclaimed\n", .{sym.name(elf_file)});
462 try writer.writeAll(" globals\n");461 }
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)});
469 }462 }
470 }463 }
471}464};
472465
473const assert = std.debug.assert;466const assert = std.debug.assert;
474const elf = std.elf;467const elf = std.elf;
src/link/Elf/Merge.zig+31-71
...@@ -157,54 +157,34 @@ pub const Section = struct {...@@ -157,54 +157,34 @@ pub const Section = struct {
157 }157 }
158 };158 };
159159
160 pub fn format(160 pub fn fmt(msec: Section, elf_file: *Elf) std.fmt.Formatter(Format, Format.default) {
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) {
174 return .{ .data = .{161 return .{ .data = .{
175 .msec = msec,162 .msec = msec,
176 .elf_file = elf_file,163 .elf_file = elf_file,
177 } };164 } };
178 }165 }
179166
180 const FormatContext = struct {167 const Format = struct {
181 msec: Section,168 msec: Section,
182 elf_file: *Elf,169 elf_file: *Elf,
183 };
184170
185 pub fn format2(171 pub fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
186 ctx: FormatContext,172 const msec = f.msec;
187 comptime unused_fmt_string: []const u8,173 const elf_file = f.elf_file;
188 options: std.fmt.FormatOptions,174 try writer.print("{s} : @{x} : size({x}) : align({x}) : entsize({x}) : type({x}) : flags({x})\n", .{
189 writer: anytype,175 msec.name(elf_file),
190 ) !void {176 msec.address(elf_file),
191 _ = options;177 msec.size,
192 _ = unused_fmt_string;178 msec.alignment.toByteUnits() orelse 0,
193 const msec = ctx.msec;179 msec.entsize,
194 const elf_file = ctx.elf_file;180 msec.type,
195 try writer.print("{s} : @{x} : size({x}) : align({x}) : entsize({x}) : type({x}) : flags({x})\n", .{181 msec.flags,
196 msec.name(elf_file),182 });
197 msec.address(elf_file),183 for (msec.subsections.items) |msub| {
198 msec.size,184 try writer.print(" {f}\n", .{msub.fmt(elf_file)});
199 msec.alignment.toByteUnits() orelse 0,185 }
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)});
206 }186 }
207 }187 };
208188
209 pub const Index = u32;189 pub const Index = u32;
210};190};
...@@ -231,48 +211,28 @@ pub const Subsection = struct {...@@ -231,48 +211,28 @@ pub const Subsection = struct {
231 return msec.bytes.items[msub.string_index..][0..msub.size];211 return msec.bytes.items[msub.string_index..][0..msub.size];
232 }212 }
233213
234 pub fn format(214 pub fn fmt(msub: Subsection, elf_file: *Elf) std.fmt.Formatter(Format, Format.default) {
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) {
248 return .{ .data = .{215 return .{ .data = .{
249 .msub = msub,216 .msub = msub,
250 .elf_file = elf_file,217 .elf_file = elf_file,
251 } };218 } };
252 }219 }
253220
254 const FormatContext = struct {221 const Format = struct {
255 msub: Subsection,222 msub: Subsection,
256 elf_file: *Elf,223 elf_file: *Elf,
257 };
258224
259 pub fn format2(225 pub fn default(ctx: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
260 ctx: FormatContext,226 const msub = ctx.msub;
261 comptime unused_fmt_string: []const u8,227 const elf_file = ctx.elf_file;
262 options: std.fmt.FormatOptions,228 try writer.print("@{x} : align({x}) : size({x})", .{
263 writer: anytype,229 msub.address(elf_file),
264 ) !void {230 msub.alignment,
265 _ = options;231 msub.size,
266 _ = unused_fmt_string;232 });
267 const msub = ctx.msub;233 if (!msub.alive) try writer.writeAll(" : [*]");
268 const elf_file = ctx.elf_file;234 }
269 try writer.print("@{x} : align({x}) : size({x})", .{235 };
270 msub.address(elf_file),
271 msub.alignment,
272 msub.size,
273 });
274 if (!msub.alive) try writer.writeAll(" : [*]");
275 }
276236
277 pub const Index = u32;237 pub const Index = u32;
278};238};
src/link/Elf/Object.zig+66-121
...@@ -1432,167 +1432,112 @@ pub fn group(self: *Object, index: Elf.Group.Index) *Elf.Group {...@@ -1432,167 +1432,112 @@ pub fn group(self: *Object, index: Elf.Group.Index) *Elf.Group {
1432 return &self.groups.items[index];1432 return &self.groups.items[index];
1433}1433}
14341434
1435pub fn format(1435pub fn fmtSymtab(self: *Object, elf_file: *Elf) std.fmt.Formatter(Format, Format.symtab) {
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) {
1449 return .{ .data = .{1436 return .{ .data = .{
1450 .object = self,1437 .object = self,
1451 .elf_file = elf_file,1438 .elf_file = elf_file,
1452 } };1439 } };
1453}1440}
14541441
1455const FormatContext = struct {1442const Format = struct {
1456 object: *Object,1443 object: *Object,
1457 elf_file: *Elf,1444 elf_file: *Elf,
1458};
14591445
1460fn formatSymtab(1446 fn symtab(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
1461 ctx: FormatContext,1447 const object = f.object;
1462 comptime unused_fmt_string: []const u8,1448 const elf_file = f.elf_file;
1463 options: std.fmt.FormatOptions,1449 try writer.writeAll(" locals\n");
1464 writer: anytype,1450 for (object.locals()) |sym| {
1465) !void {1451 try writer.print(" {}\n", .{sym.fmt(elf_file)});
1466 _ = unused_fmt_string;1452 }
1467 _ = options;1453 try writer.writeAll(" globals\n");
1468 const object = ctx.object;1454 for (object.globals(), 0..) |sym, i| {
1469 const elf_file = ctx.elf_file;1455 const first_global = object.first_global.?;
1470 try writer.writeAll(" locals\n");1456 const ref = object.resolveSymbol(@intCast(i + first_global), elf_file);
1471 for (object.locals()) |sym| {1457 if (elf_file.symbol(ref)) |ref_sym| {
1472 try writer.print(" {}\n", .{sym.fmt(elf_file)});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 }
1473 }1463 }
1474 try writer.writeAll(" globals\n");1464
1475 for (object.globals(), 0..) |sym, i| {1465 fn atoms(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
1476 const first_global = object.first_global.?;1466 const object = f.object;
1477 const ref = object.resolveSymbol(@intCast(i + first_global), elf_file);1467 try writer.writeAll(" atoms\n");
1478 if (elf_file.symbol(ref)) |ref_sym| {1468 for (object.atoms_indexes.items) |atom_index| {
1479 try writer.print(" {}\n", .{ref_sym.fmt(elf_file)});1469 const atom_ptr = object.atom(atom_index) orelse continue;
1480 } else {1470 try writer.print(" {}\n", .{atom_ptr.fmt(f.elf_file)});
1481 try writer.print(" {s} : unclaimed\n", .{sym.name(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) });
1482 }1479 }
1483 }1480 }
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) {
1487 return .{ .data = .{1509 return .{ .data = .{
1488 .object = self,1510 .object = self,
1489 .elf_file = elf_file,1511 .elf_file = elf_file,
1490 } };1512 } };
1491}1513}
14921514
1493fn formatAtoms(1515pub fn fmtCies(self: *Object, elf_file: *Elf) std.fmt.Formatter(Format, Format.cies) {
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) {
1510 return .{ .data = .{1516 return .{ .data = .{
1511 .object = self,1517 .object = self,
1512 .elf_file = elf_file,1518 .elf_file = elf_file,
1513 } };1519 } };
1514}1520}
15151521
1516fn formatCies(1522pub fn fmtFdes(self: *Object, elf_file: *Elf) std.fmt.Formatter(Format, Format.fdes) {
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) {
1532 return .{ .data = .{1523 return .{ .data = .{
1533 .object = self,1524 .object = self,
1534 .elf_file = elf_file,1525 .elf_file = elf_file,
1535 } };1526 } };
1536}1527}
15371528
1538fn formatFdes(1529pub fn fmtGroups(self: *Object, elf_file: *Elf) std.fmt.Formatter(Format, Format.groups) {
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) {
1554 return .{ .data = .{1530 return .{ .data = .{
1555 .object = self,1531 .object = self,
1556 .elf_file = elf_file,1532 .elf_file = elf_file,
1557 } };1533 } };
1558}1534}
15591535
1560fn formatGroups(1536pub fn fmtPath(self: Object) std.fmt.Formatter(Object, formatPath) {
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) {
1585 return .{ .data = self };1537 return .{ .data = self };
1586}1538}
15871539
1588fn formatPath(1540fn formatPath(object: Object, writer: *std.io.Writer) std.io.Writer.Error!void {
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;
1596 if (object.archive) |ar| {1541 if (object.archive) |ar| {
1597 try writer.print("{}({})", .{ ar.path, object.path });1542 try writer.print("{}({})", .{ ar.path, object.path });
1598 } else {1543 } else {
src/link/Elf/SharedObject.zig+5-25
...@@ -509,41 +509,21 @@ pub fn setSymbolExtra(self: *SharedObject, index: u32, extra: Symbol.Extra) void...@@ -509,41 +509,21 @@ pub fn setSymbolExtra(self: *SharedObject, index: u32, extra: Symbol.Extra) void
509 }509 }
510}510}
511511
512pub fn format(512pub fn fmtSymtab(self: SharedObject, elf_file: *Elf) std.fmt.Formatter(Format, Format.symtab) {
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) {
526 return .{ .data = .{513 return .{ .data = .{
527 .shared = self,514 .shared = self,
528 .elf_file = elf_file,515 .elf_file = elf_file,
529 } };516 } };
530}517}
531518
532const FormatContext = struct {519const Format = struct {
533 shared: SharedObject,520 shared: SharedObject,
534 elf_file: *Elf,521 elf_file: *Elf,
535};522};
536523
537fn formatSymtab(524fn formatSymtab(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
538 ctx: FormatContext,525 const shared = f.shared;
539 comptime unused_fmt_string: []const u8,526 const elf_file = f.elf_file;
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;
547 try writer.writeAll(" globals\n");527 try writer.writeAll(" globals\n");
548 for (shared.symbols.items, 0..) |sym, i| {528 for (shared.symbols.items, 0..) |sym, i| {
549 const ref = shared.resolveSymbol(@intCast(i), elf_file);529 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 {...@@ -316,99 +316,72 @@ pub fn setOutputSym(symbol: Symbol, elf_file: *Elf, out: *elf.Elf64_Sym) void {
316 out.st_size = esym.st_size;316 out.st_size = esym.st_size;
317}317}
318318
319pub fn format(319const Format = struct {
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 {
333 symbol: Symbol,320 symbol: Symbol,
334 elf_file: *Elf,321 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 }
335};369};
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) {
338 return .{ .data = .{372 return .{ .data = .{
339 .symbol = symbol,373 .symbol = symbol,
340 .elf_file = elf_file,374 .elf_file = elf_file,
341 } };375 } };
342}376}
343377
344fn formatName(378pub fn fmt(symbol: Symbol, elf_file: *Elf) std.fmt.Formatter(Format, Format.default) {
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) {
367 return .{ .data = .{379 return .{ .data = .{
368 .symbol = symbol,380 .symbol = symbol,
369 .elf_file = elf_file,381 .elf_file = elf_file,
370 } };382 } };
371}383}
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
412pub const Flags = packed struct {385pub const Flags = packed struct {
413 /// Whether the symbol is imported at runtime.386 /// Whether the symbol is imported at runtime.
414 import: bool = false,387 import: bool = false,
src/link/Elf/Thunk.zig+11-31
...@@ -65,47 +65,27 @@ fn trampolineSize(cpu_arch: std.Target.Cpu.Arch) usize {...@@ -65,47 +65,27 @@ fn trampolineSize(cpu_arch: std.Target.Cpu.Arch) usize {
65 };65 };
66}66}
6767
68pub fn format(68pub fn fmt(thunk: Thunk, elf_file: *Elf) std.fmt.Formatter(Format, Format.default) {
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) {
82 return .{ .data = .{69 return .{ .data = .{
83 .thunk = thunk,70 .thunk = thunk,
84 .elf_file = elf_file,71 .elf_file = elf_file,
85 } };72 } };
86}73}
8774
88const FormatContext = struct {75const Format = struct {
89 thunk: Thunk,76 thunk: Thunk,
90 elf_file: *Elf,77 elf_file: *Elf,
91};
9278
93fn format2(79 fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
94 ctx: FormatContext,80 const thunk = f.thunk;
95 comptime unused_fmt_string: []const u8,81 const elf_file = f.elf_file;
96 options: std.fmt.FormatOptions,82 try writer.print("@{x} : size({x})\n", .{ thunk.value, thunk.size(elf_file) });
97 writer: anytype,83 for (thunk.symbols.keys()) |ref| {
98) !void {84 const sym = elf_file.symbol(ref).?;
99 _ = options;85 try writer.print(" {} : {s} : @{x}\n", .{ ref, sym.name(elf_file), sym.value });
100 _ = unused_fmt_string;86 }
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 });
107 }87 }
108}88};
10989
110pub const Index = u32;90pub 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 {...@@ -2195,60 +2195,46 @@ pub fn setSymbolExtra(self: *ZigObject, index: u32, extra: Symbol.Extra) void {
2195 }2195 }
2196}2196}
21972197
2198pub fn fmtSymtab(self: *ZigObject, elf_file: *Elf) std.fmt.Formatter(formatSymtab) {2198const Format = struct {
2199 return .{ .data = .{
2200 .self = self,
2201 .elf_file = elf_file,
2202 } };
2203}
2204
2205const FormatContext = struct {
2206 self: *ZigObject,2199 self: *ZigObject,
2207 elf_file: *Elf,2200 elf_file: *Elf,
2208};
22092201
2210fn formatSymtab(2202 fn symtab(f: Format, writer: *std.io.Writer.Error) std.io.Writer.Error!void {
2211 ctx: FormatContext,2203 const self = f.self;
2212 comptime unused_fmt_string: []const u8,2204 const elf_file = f.elf_file;
2213 options: std.fmt.FormatOptions,2205 try writer.writeAll(" locals\n");
2214 writer: anytype,2206 for (self.local_symbols.items) |index| {
2215) !void {2207 const local = self.symbols.items[index];
2216 _ = unused_fmt_string;2208 try writer.print(" {f}\n", .{local.fmt(elf_file)});
2217 _ = options;2209 }
2218 const self = ctx.self;2210 try writer.writeAll(" globals\n");
2219 const elf_file = ctx.elf_file;2211 for (f.self.global_symbols.items) |index| {
2220 try writer.writeAll(" locals\n");2212 const global = self.symbols.items[index];
2221 for (self.local_symbols.items) |index| {2213 try writer.print(" {f}\n", .{global.fmt(elf_file)});
2222 const local = self.symbols.items[index];2214 }
2223 try writer.print(" {}\n", .{local.fmt(elf_file)});
2224 }2215 }
2225 try writer.writeAll(" globals\n");2216
2226 for (ctx.self.global_symbols.items) |index| {2217 fn atoms(f: Format, writer: *std.io.Writer.Error) std.io.Writer.Error!void {
2227 const global = self.symbols.items[index];2218 try writer.writeAll(" atoms\n");
2228 try writer.print(" {}\n", .{global.fmt(elf_file)});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 }
2229 }2223 }
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) {
2233 return .{ .data = .{2227 return .{ .data = .{
2234 .self = self,2228 .self = self,
2235 .elf_file = elf_file,2229 .elf_file = elf_file,
2236 } };2230 } };
2237}2231}
22382232
2239fn formatAtoms(2233pub fn fmtAtoms(self: *ZigObject, elf_file: *Elf) std.fmt.Formatter(Format, Format.atoms) {
2240 ctx: FormatContext,2234 return .{ .data = .{
2241 comptime unused_fmt_string: []const u8,2235 .self = self,
2242 options: std.fmt.FormatOptions,2236 .elf_file = elf_file,
2243 writer: anytype,2237 } };
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 }
2252}2238}
22532239
2254const ElfSym = struct {2240const ElfSym = struct {
src/link/Elf/eh_frame.zig+30-70
...@@ -47,52 +47,32 @@ pub const Fde = struct {...@@ -47,52 +47,32 @@ pub const Fde = struct {
47 return object.relocs.items[fde.rel_index..][0..fde.rel_num];47 return object.relocs.items[fde.rel_index..][0..fde.rel_num];
48 }48 }
4949
50 pub fn format(50 pub fn fmt(fde: Fde, elf_file: *Elf) std.fmt.Formatter(Format, Format.default) {
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) {
64 return .{ .data = .{51 return .{ .data = .{
65 .fde = fde,52 .fde = fde,
66 .elf_file = elf_file,53 .elf_file = elf_file,
67 } };54 } };
68 }55 }
6956
70 const FdeFormatContext = struct {57 const Format = struct {
71 fde: Fde,58 fde: Fde,
72 elf_file: *Elf,59 elf_file: *Elf,
73 };
7460
75 fn format2(61 fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
76 ctx: FdeFormatContext,62 const fde = f.fde;
77 comptime unused_fmt_string: []const u8,63 const elf_file = f.elf_file;
78 options: std.fmt.FormatOptions,64 const base_addr = fde.address(elf_file);
79 writer: anytype,65 const object = elf_file.file(fde.file_index).?.object;
80 ) !void {66 const atom_name = fde.atom(object).name(elf_file);
81 _ = unused_fmt_string;67 try writer.print("@{x} : size({x}) : cie({d}) : {s}", .{
82 _ = options;68 base_addr + fde.out_offset,
83 const fde = ctx.fde;69 fde.calcSize(),
84 const elf_file = ctx.elf_file;70 fde.cie_index,
85 const base_addr = fde.address(elf_file);71 atom_name,
86 const object = elf_file.file(fde.file_index).?.object;72 });
87 const atom_name = fde.atom(object).name(elf_file);73 if (!fde.alive) try writer.writeAll(" : [*]");
88 try writer.print("@{x} : size({x}) : cie({d}) : {s}", .{74 }
89 base_addr + fde.out_offset,75 };
90 fde.calcSize(),
91 fde.cie_index,
92 atom_name,
93 });
94 if (!fde.alive) try writer.writeAll(" : [*]");
95 }
96};76};
9777
98pub const Cie = struct {78pub const Cie = struct {
...@@ -150,48 +130,28 @@ pub const Cie = struct {...@@ -150,48 +130,28 @@ pub const Cie = struct {
150 return true;130 return true;
151 }131 }
152132
153 pub fn format(133 pub fn fmt(cie: Cie, elf_file: *Elf) std.fmt.Formatter(Format, Format.default) {
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) {
167 return .{ .data = .{134 return .{ .data = .{
168 .cie = cie,135 .cie = cie,
169 .elf_file = elf_file,136 .elf_file = elf_file,
170 } };137 } };
171 }138 }
172139
173 const CieFormatContext = struct {140 const Format = struct {
174 cie: Cie,141 cie: Cie,
175 elf_file: *Elf,142 elf_file: *Elf,
176 };
177143
178 fn format2(144 fn format2(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
179 ctx: CieFormatContext,145 const cie = f.cie;
180 comptime unused_fmt_string: []const u8,146 const elf_file = f.elf_file;
181 options: std.fmt.FormatOptions,147 const base_addr = cie.address(elf_file);
182 writer: anytype,148 try writer.print("@{x} : size({x})", .{
183 ) !void {149 base_addr + cie.out_offset,
184 _ = unused_fmt_string;150 cie.calcSize(),
185 _ = options;151 });
186 const cie = ctx.cie;152 if (!cie.alive) try writer.writeAll(" : [*]");
187 const elf_file = ctx.elf_file;153 }
188 const base_addr = cie.address(elf_file);154 };
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 }
195};155};
196156
197pub const Iterator = struct {157pub const Iterator = struct {
src/link/Elf/file.zig+4-11
...@@ -10,23 +10,16 @@ pub const File = union(enum) {...@@ -10,23 +10,16 @@ pub const File = union(enum) {
10 };10 };
11 }11 }
1212
13 pub fn fmtPath(file: File) std.fmt.Formatter(formatPath) {13 pub fn fmtPath(file: File) std.fmt.Formatter(File, formatPath) {
14 return .{ .data = file };14 return .{ .data = file };
15 }15 }
1616
17 fn formatPath(17 fn formatPath(file: File, writer: *std.io.Writer) std.io.Writer.Error!void {
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;
25 switch (file) {18 switch (file) {
26 .zig_object => |zo| try writer.writeAll(zo.basename),19 .zig_object => |zo| try writer.writeAll(zo.basename),
27 .linker_defined => try writer.writeAll("(linker defined)"),20 .linker_defined => try writer.writeAll("(linker defined)"),
28 .object => |x| try writer.print("{}", .{x.fmtPath()}),21 .object => |x| try writer.print("{f}", .{x.fmtPath()}),
29 .shared_object => |x| try writer.print("{}", .{@as(Path, x.path)}),22 .shared_object => |x| try writer.print("{f}", .{@as(Path, x.path)}),
30 }23 }
31 }24 }
3225
src/link/Elf/relocation.zig+2-9
...@@ -141,21 +141,14 @@ const FormatRelocTypeCtx = struct {...@@ -141,21 +141,14 @@ const FormatRelocTypeCtx = struct {
141 cpu_arch: std.Target.Cpu.Arch,141 cpu_arch: std.Target.Cpu.Arch,
142};142};
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) {
145 return .{ .data = .{145 return .{ .data = .{
146 .r_type = r_type,146 .r_type = r_type,
147 .cpu_arch = cpu_arch,147 .cpu_arch = cpu_arch,
148 } };148 } };
149}149}
150150
151fn formatRelocType(151fn formatRelocType(ctx: FormatRelocTypeCtx, writer: *std.io.Writer) std.io.Writer.Error!void {
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;
159 const r_type = ctx.r_type;152 const r_type = ctx.r_type;
160 switch (ctx.cpu_arch) {153 switch (ctx.cpu_arch) {
161 .x86_64 => try writer.print("R_X86_64_{s}", .{@tagName(@as(elf.R_X86_64, @enumFromInt(r_type)))}),154 .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 {...@@ -606,37 +606,30 @@ pub const GotSection = struct {
606 }606 }
607 }607 }
608608
609 const FormatCtx = struct {609 const Format = struct {
610 got: GotSection,610 got: GotSection,
611 elf_file: *Elf,611 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 }
612 };628 };
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) {
615 return .{ .data = .{ .got = got, .elf_file = elf_file } };631 return .{ .data = .{ .got = got, .elf_file = elf_file } };
616 }632 }
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 }
640};633};
641634
642pub const PltSection = struct {635pub const PltSection = struct {
...@@ -749,38 +742,31 @@ pub const PltSection = struct {...@@ -749,38 +742,31 @@ pub const PltSection = struct {
749 }742 }
750 }743 }
751744
752 const FormatCtx = struct {745 const Format = struct {
753 plt: PltSection,746 plt: PltSection,
754 elf_file: *Elf,747 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 }
755 };764 };
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) {
758 return .{ .data = .{ .plt = plt, .elf_file = elf_file } };767 return .{ .data = .{ .plt = plt, .elf_file = elf_file } };
759 }768 }
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
784 const x86_64 = struct {770 const x86_64 = struct {
785 fn write(plt: PltSection, elf_file: *Elf, writer: anytype) !void {771 fn write(plt: PltSection, elf_file: *Elf, writer: anytype) !void {
786 const shdrs = elf_file.sections.items(.shdr);772 const shdrs = elf_file.sections.items(.shdr);
src/link/Lld.zig+2-2
...@@ -1649,7 +1649,7 @@ fn spawnLld(...@@ -1649,7 +1649,7 @@ fn spawnLld(
1649 child.stderr_behavior = .Pipe;1649 child.stderr_behavior = .Pipe;
16501650
1651 child.spawn() catch |err| break :term err;1651 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));
1653 break :term child.wait();1653 break :term child.wait();
1654 }) catch |first_err| term: {1654 }) catch |first_err| term: {
1655 const err = switch (first_err) {1655 const err = switch (first_err) {
...@@ -1697,7 +1697,7 @@ fn spawnLld(...@@ -1697,7 +1697,7 @@ fn spawnLld(
1697 rsp_child.stderr_behavior = .Pipe;1697 rsp_child.stderr_behavior = .Pipe;
16981698
1699 rsp_child.spawn() catch |err| break :err err;1699 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));
1701 break :term rsp_child.wait() catch |err| break :err err;1701 break :term rsp_child.wait() catch |err| break :err err;
1702 }1702 }
1703 },1703 },
src/link/MachO/Object.zig+2-2
...@@ -2552,7 +2552,7 @@ const Format = struct {...@@ -2552,7 +2552,7 @@ const Format = struct {
2552 }2552 }
2553 }2553 }
25542554
2555 fn formatSymtab(f: Format, w: *Writer) Writer.Error!void {2555 fn symtab(f: Format, w: *Writer) Writer.Error!void {
2556 const object = f.object;2556 const object = f.object;
2557 const macho_file = f.macho_file;2557 const macho_file = f.macho_file;
2558 try w.writeAll(" symbols\n");2558 try w.writeAll(" symbols\n");
...@@ -2695,7 +2695,7 @@ const StabFile = struct {...@@ -2695,7 +2695,7 @@ const StabFile = struct {
2695 };2695 };
26962696
2697 pub fn fmt(stab: Stab, object: Object) std.fmt.Formatter(Stab.Format, Stab.Format.default) {2697 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 } };
2699 }2699 }
2700 };2700 };
2701};2701};
src/link/MachO/Relocation.zig+1-1
...@@ -71,7 +71,7 @@ pub fn lessThan(ctx: void, lhs: Relocation, rhs: Relocation) bool {...@@ -71,7 +71,7 @@ pub fn lessThan(ctx: void, lhs: Relocation, rhs: Relocation) bool {
71}71}
7272
73pub fn fmtPretty(rel: Relocation, cpu_arch: std.Target.Cpu.Arch) std.fmt.Formatter(Format, Format.pretty) {73pub 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 } };
75}75}
7676
77const Format = struct {77const Format = struct {
src/link/MachO/eh_frame.zig+14-34
...@@ -211,49 +211,29 @@ pub const Fde = struct {...@@ -211,49 +211,29 @@ pub const Fde = struct {
211 return fde.getObject(macho_file).getAtom(fde.lsda);211 return fde.getObject(macho_file).getAtom(fde.lsda);
212 }212 }
213213
214 pub fn format(214 pub fn fmt(fde: Fde, macho_file: *MachO) std.fmt.Formatter(Format, Format.default) {
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) {
228 return .{ .data = .{215 return .{ .data = .{
229 .fde = fde,216 .fde = fde,
230 .macho_file = macho_file,217 .macho_file = macho_file,
231 } };218 } };
232 }219 }
233220
234 const FormatContext = struct {221 const Format = struct {
235 fde: Fde,222 fde: Fde,
236 macho_file: *MachO,223 macho_file: *MachO,
237 };
238224
239 fn format2(225 fn default(f: Format, writer: *Writer) Writer.Error!void {
240 ctx: FormatContext,226 const fde = f.fde;
241 comptime unused_fmt_string: []const u8,227 const macho_file = f.macho_file;
242 options: std.fmt.FormatOptions,228 try writer.print("@{x} : size({x}) : cie({d}) : {s}", .{
243 writer: anytype,229 fde.offset,
244 ) !void {230 fde.getSize(),
245 _ = unused_fmt_string;231 fde.cie,
246 _ = options;232 fde.getAtom(macho_file).getName(macho_file),
247 const fde = ctx.fde;233 });
248 const macho_file = ctx.macho_file;234 if (!fde.alive) try writer.writeAll(" : [*]");
249 try writer.print("@{x} : size({x}) : cie({d}) : {s}", .{235 }
250 fde.offset,236 };
251 fde.getSize(),
252 fde.cie,
253 fde.getAtom(macho_file).getName(macho_file),
254 });
255 if (!fde.alive) try writer.writeAll(" : [*]");
256 }
257237
258 pub const Index = u32;238 pub const Index = u32;
259};239};
src/print_value.zig+9-23
...@@ -20,15 +20,8 @@ pub const FormatContext = struct {...@@ -20,15 +20,8 @@ pub const FormatContext = struct {
20 depth: u8,20 depth: u8,
21};21};
2222
23pub fn formatSema(23pub fn formatSema(ctx: FormatContext, writer: *std.io.Writer) std.io.Writer.Error!void {
24 ctx: FormatContext,
25 comptime fmt: []const u8,
26 options: std.fmt.FormatOptions,
27 writer: anytype,
28) !void {
29 _ = options;
30 const sema = ctx.opt_sema.?;24 const sema = ctx.opt_sema.?;
31 comptime std.debug.assert(fmt.len == 0);
32 return print(ctx.val, writer, ctx.depth, ctx.pt, sema) catch |err| switch (err) {25 return print(ctx.val, writer, ctx.depth, ctx.pt, sema) catch |err| switch (err) {
33 error.OutOfMemory => @panic("OOM"), // We're not allowed to return this from a format function26 error.OutOfMemory => @panic("OOM"), // We're not allowed to return this from a format function
34 error.ComptimeBreak, error.ComptimeReturn => unreachable,27 error.ComptimeBreak, error.ComptimeReturn => unreachable,
...@@ -37,15 +30,8 @@ pub fn formatSema(...@@ -37,15 +30,8 @@ pub fn formatSema(
37 };30 };
38}31}
3932
40pub fn format(33pub fn format(ctx: FormatContext, writer: *std.io.Writer) std.io.Writer.Error!void {
41 ctx: FormatContext,
42 comptime fmt: []const u8,
43 options: std.fmt.FormatOptions,
44 writer: anytype,
45) !void {
46 _ = options;
47 std.debug.assert(ctx.opt_sema == null);34 std.debug.assert(ctx.opt_sema == null);
48 comptime std.debug.assert(fmt.len == 0);
49 return print(ctx.val, writer, ctx.depth, ctx.pt, null) catch |err| switch (err) {35 return print(ctx.val, writer, ctx.depth, ctx.pt, null) catch |err| switch (err) {
50 error.OutOfMemory => @panic("OOM"), // We're not allowed to return this from a format function36 error.OutOfMemory => @panic("OOM"), // We're not allowed to return this from a format function
51 error.ComptimeBreak, error.ComptimeReturn, error.AnalysisFail => unreachable,37 error.ComptimeBreak, error.ComptimeReturn, error.AnalysisFail => unreachable,
...@@ -55,11 +41,11 @@ pub fn format(...@@ -55,11 +41,11 @@ pub fn format(
5541
56pub fn print(42pub fn print(
57 val: Value,43 val: Value,
58 writer: anytype,44 writer: *std.io.Writer,
59 level: u8,45 level: u8,
60 pt: Zcu.PerThread,46 pt: Zcu.PerThread,
61 opt_sema: ?*Sema,47 opt_sema: ?*Sema,
62) (@TypeOf(writer).Error || Zcu.CompileError)!void {48) (std.io.Writer.Error || Zcu.CompileError)!void {
63 const zcu = pt.zcu;49 const zcu = pt.zcu;
64 const ip = &zcu.intern_pool;50 const ip = &zcu.intern_pool;
65 switch (ip.indexToKey(val.toIntern())) {51 switch (ip.indexToKey(val.toIntern())) {
...@@ -197,11 +183,11 @@ fn printAggregate(...@@ -197,11 +183,11 @@ fn printAggregate(
197 val: Value,183 val: Value,
198 aggregate: InternPool.Key.Aggregate,184 aggregate: InternPool.Key.Aggregate,
199 is_ref: bool,185 is_ref: bool,
200 writer: anytype,186 writer: *std.io.Writer,
201 level: u8,187 level: u8,
202 pt: Zcu.PerThread,188 pt: Zcu.PerThread,
203 opt_sema: ?*Sema,189 opt_sema: ?*Sema,
204) (@TypeOf(writer).Error || Zcu.CompileError)!void {190) (std.io.Writer.Error || Zcu.CompileError)!void {
205 if (level == 0) {191 if (level == 0) {
206 if (is_ref) try writer.writeByte('&');192 if (is_ref) try writer.writeByte('&');
207 return writer.writeAll(".{ ... }");193 return writer.writeAll(".{ ... }");
...@@ -283,11 +269,11 @@ fn printPtr(...@@ -283,11 +269,11 @@ fn printPtr(
283 ptr_val: Value,269 ptr_val: Value,
284 /// Whether to print `derivation` as an lvalue or rvalue. If `null`, the more concise option is chosen.270 /// Whether to print `derivation` as an lvalue or rvalue. If `null`, the more concise option is chosen.
285 want_kind: ?PrintPtrKind,271 want_kind: ?PrintPtrKind,
286 writer: anytype,272 writer: *std.io.Writer,
287 level: u8,273 level: u8,
288 pt: Zcu.PerThread,274 pt: Zcu.PerThread,
289 opt_sema: ?*Sema,275 opt_sema: ?*Sema,
290) (@TypeOf(writer).Error || Zcu.CompileError)!void {276) (std.io.Writer.Error || Zcu.CompileError)!void {
291 const ptr = switch (pt.zcu.intern_pool.indexToKey(ptr_val.toIntern())) {277 const ptr = switch (pt.zcu.intern_pool.indexToKey(ptr_val.toIntern())) {
292 .undef => return writer.writeAll("undefined"),278 .undef => return writer.writeAll("undefined"),
293 .ptr => |ptr| ptr,279 .ptr => |ptr| ptr,
...@@ -329,7 +315,7 @@ const PrintPtrKind = enum { lvalue, rvalue };...@@ -329,7 +315,7 @@ const PrintPtrKind = enum { lvalue, rvalue };
329/// Returns the root derivation, which may be ignored.315/// Returns the root derivation, which may be ignored.
330pub fn printPtrDerivation(316pub fn printPtrDerivation(
331 derivation: Value.PointerDeriveStep,317 derivation: Value.PointerDeriveStep,
332 writer: anytype,318 writer: *std.io.Writer,
333 pt: Zcu.PerThread,319 pt: Zcu.PerThread,
334 /// Whether to print `derivation` as an lvalue or rvalue. If `null`, the more concise option is chosen.320 /// Whether to print `derivation` as an lvalue or rvalue. If `null`, the more concise option is chosen.
335 /// If this is `.rvalue`, the result may look like `&foo`, so it's not necessarily valid to treat it as321 /// If this is `.rvalue`, the result may look like `&foo`, so it's not necessarily valid to treat it as