authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-25 23:25:29-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-25 23:25:29-05:00
log9dffc369f1720fabb0a996b5af3c67fe3e4fd830
tree409a609e55426c864bfe8a336fc0fa7e06e8f35a
parentfbfda7f00edbbf4eb623898d53c3faf43ab874ce
parent4e9b1f5479e3b7ce47d059e0e6f3d62cd4ee7254
signature Commit is signed but in an unrecognized format.

Merge remote-tracking branch 'origin/master' into layneson-cpus_and_features


22 files changed, 11501 insertions(+), 9297 deletions(-)

lib/std/build.zig+3-1
......@@ -1689,7 +1689,9 @@ pub const LibExeObjStep = struct {
16891689 }
16901690
16911691 pub fn addAssemblyFile(self: *LibExeObjStep, path: []const u8) void {
1692 self.link_objects.append(LinkObject{ .AssemblyFile = self.builder.dupe(path) }) catch unreachable;
1692 self.link_objects.append(LinkObject{
1693 .AssemblyFile = .{ .path = self.builder.dupe(path) },
1694 }) catch unreachable;
16931695 }
16941696
16951697 pub fn addAssemblyFileFromWriteFileStep(self: *LibExeObjStep, wfs: *WriteFileStep, basename: []const u8) void {
lib/std/debug.zig+119-169
......@@ -379,16 +379,7 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres
379379 }
380380 } else {
381381 // we have no information to add to the address
382 if (tty_color) {
383 try out_stream.print("???:?:?: ", .{});
384 setTtyColor(TtyColor.Dim);
385 try out_stream.print("0x{x} in ??? (???)", .{relocated_address});
386 setTtyColor(TtyColor.Reset);
387 try out_stream.print("\n\n\n", .{});
388 } else {
389 try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", .{relocated_address});
390 }
391 return;
382 return printLineInfo(out_stream, null, relocated_address, "???", "???", tty_color, printLineFromFileAnyOs);
392383 };
393384
394385 const mod = &di.modules[mod_index];
......@@ -510,66 +501,15 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres
510501 }
511502 };
512503
513 if (tty_color) {
514 setTtyColor(TtyColor.White);
515 if (opt_line_info) |li| {
516 try out_stream.print("{}:{}:{}", .{ li.file_name, li.line, li.column });
517 } else {
518 try out_stream.print("???:?:?", .{});
519 }
520 setTtyColor(TtyColor.Reset);
521 try out_stream.print(": ", .{});
522 setTtyColor(TtyColor.Dim);
523 try out_stream.print("0x{x} in {} ({})", .{ relocated_address, symbol_name, obj_basename });
524 setTtyColor(TtyColor.Reset);
525
526 if (opt_line_info) |line_info| {
527 try out_stream.print("\n", .{});
528 if (printLineFromFileAnyOs(out_stream, line_info)) {
529 if (line_info.column == 0) {
530 try out_stream.write("\n");
531 } else {
532 {
533 var col_i: usize = 1;
534 while (col_i < line_info.column) : (col_i += 1) {
535 try out_stream.writeByte(' ');
536 }
537 }
538 setTtyColor(TtyColor.Green);
539 try out_stream.write("^");
540 setTtyColor(TtyColor.Reset);
541 try out_stream.write("\n");
542 }
543 } else |err| switch (err) {
544 error.EndOfFile => {},
545 error.FileNotFound => {
546 setTtyColor(TtyColor.Dim);
547 try out_stream.write("file not found\n\n");
548 setTtyColor(TtyColor.White);
549 },
550 else => return err,
551 }
552 } else {
553 try out_stream.print("\n\n\n", .{});
554 }
555 } else {
556 if (opt_line_info) |li| {
557 try out_stream.print("{}:{}:{}: 0x{x} in {} ({})\n\n\n", .{
558 li.file_name,
559 li.line,
560 li.column,
561 relocated_address,
562 symbol_name,
563 obj_basename,
564 });
565 } else {
566 try out_stream.print("???:?:?: 0x{x} in {} ({})\n\n\n", .{
567 relocated_address,
568 symbol_name,
569 obj_basename,
570 });
571 }
572 }
504 try printLineInfo(
505 out_stream,
506 opt_line_info,
507 relocated_address,
508 symbol_name,
509 obj_basename,
510 tty_color,
511 printLineFromFileAnyOs,
512 );
573513}
574514
575515const TtyColor = enum {
......@@ -605,7 +545,11 @@ fn setTtyColor(tty_color: TtyColor) void {
605545 stderr_file.write(RESET) catch return;
606546 },
607547 }
608 } else {
548
549 return;
550 }
551
552 if (builtin.os == .windows) {
609553 const S = struct {
610554 var attrs: windows.WORD = undefined;
611555 var init_attrs = false;
......@@ -711,12 +655,7 @@ fn printSourceAtAddressMacOs(di: *DebugInfo, out_stream: var, address: usize, tt
711655 const adjusted_addr = 0x100000000 + (address - base_addr);
712656
713657 const symbol = machoSearchSymbols(di.symbols, adjusted_addr) orelse {
714 if (tty_color) {
715 try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? (???)" ++ RESET ++ "\n\n\n", .{address});
716 } else {
717 try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", .{address});
718 }
719 return;
658 return printLineInfo(out_stream, null, address, "???", "???", tty_color, printLineFromFileAnyOs);
720659 };
721660
722661 const symbol_name = mem.toSliceConst(u8, @ptrCast([*:0]const u8, di.strings.ptr + symbol.nlist.n_strx));
......@@ -724,29 +663,22 @@ fn printSourceAtAddressMacOs(di: *DebugInfo, out_stream: var, address: usize, tt
724663 const ofile_path = mem.toSliceConst(u8, @ptrCast([*:0]const u8, di.strings.ptr + ofile.n_strx));
725664 break :blk fs.path.basename(ofile_path);
726665 } else "???";
727 if (getLineNumberInfoMacOs(di, symbol.*, adjusted_addr)) |line_info| {
728 defer line_info.deinit();
729 try printLineInfo(
730 out_stream,
731 line_info,
732 address,
733 symbol_name,
734 compile_unit_name,
735 tty_color,
736 printLineFromFileAnyOs,
737 );
738 } else |err| switch (err) {
739 error.MissingDebugInfo, error.InvalidDebugInfo => {
740 if (tty_color) {
741 try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in {} ({})" ++ RESET ++ "\n\n\n", .{
742 address, symbol_name, compile_unit_name,
743 });
744 } else {
745 try out_stream.print("???:?:?: 0x{x} in {} ({})\n\n\n", .{ address, symbol_name, compile_unit_name });
746 }
747 },
666
667 const line_info = getLineNumberInfoMacOs(di, symbol.*, adjusted_addr) catch |err| switch (err) {
668 error.MissingDebugInfo, error.InvalidDebugInfo => null,
748669 else => return err,
749 }
670 };
671 defer if (line_info) |li| li.deinit();
672
673 try printLineInfo(
674 out_stream,
675 line_info,
676 address,
677 symbol_name,
678 compile_unit_name,
679 tty_color,
680 printLineFromFileAnyOs,
681 );
750682}
751683
752684pub fn printSourceAtAddressPosix(debug_info: *DebugInfo, out_stream: var, address: usize, tty_color: bool) !void {
......@@ -755,47 +687,46 @@ pub fn printSourceAtAddressPosix(debug_info: *DebugInfo, out_stream: var, addres
755687
756688fn printLineInfo(
757689 out_stream: var,
758 line_info: LineInfo,
690 line_info: ?LineInfo,
759691 address: usize,
760692 symbol_name: []const u8,
761693 compile_unit_name: []const u8,
762694 tty_color: bool,
763695 comptime printLineFromFile: var,
764696) !void {
765 if (tty_color) {
766 try out_stream.print(WHITE ++ "{}:{}:{}" ++ RESET ++ ": " ++ DIM ++ "0x{x} in {} ({})" ++ RESET ++ "\n", .{
767 line_info.file_name,
768 line_info.line,
769 line_info.column,
770 address,
771 symbol_name,
772 compile_unit_name,
773 });
774 if (printLineFromFile(out_stream, line_info)) {
775 if (line_info.column == 0) {
776 try out_stream.write("\n");
777 } else {
778 {
779 var col_i: usize = 1;
780 while (col_i < line_info.column) : (col_i += 1) {
781 try out_stream.writeByte(' ');
782 }
783 }
784 try out_stream.write(GREEN ++ "^" ++ RESET ++ "\n");
697 if (tty_color) setTtyColor(.White);
698
699 if (line_info) |*li| {
700 try out_stream.print("{}:{}:{}", .{ li.file_name, li.line, li.column });
701 } else {
702 try out_stream.print("???:?:?", .{});
703 }
704
705 if (tty_color) setTtyColor(.Reset);
706 try out_stream.write(": ");
707 if (tty_color) setTtyColor(.Dim);
708 try out_stream.print("0x{x} in {} ({})", .{ address, symbol_name, compile_unit_name });
709 if (tty_color) setTtyColor(.Reset);
710 try out_stream.write("\n");
711
712 // Show the matching source code line if possible
713 if (line_info) |li| {
714 if (noasync printLineFromFile(out_stream, li)) {
715 if (li.column > 0) {
716 // The caret already takes one char
717 const space_needed = @intCast(usize, li.column - 1);
718
719 try out_stream.writeByteNTimes(' ', space_needed);
720 if (tty_color) setTtyColor(.Green);
721 try out_stream.write("^");
722 if (tty_color) setTtyColor(.Reset);
785723 }
724 try out_stream.write("\n");
786725 } else |err| switch (err) {
787726 error.EndOfFile, error.FileNotFound => {},
727 error.BadPathName => {},
788728 else => return err,
789729 }
790 } else {
791 try out_stream.print("{}:{}:{}: 0x{x} in {} ({})\n", .{
792 line_info.file_name,
793 line_info.line,
794 line_info.column,
795 address,
796 symbol_name,
797 compile_unit_name,
798 });
799730 }
800731}
801732
......@@ -1240,38 +1171,26 @@ pub const DwarfInfo = struct {
12401171 comptime printLineFromFile: var,
12411172 ) !void {
12421173 const compile_unit = self.findCompileUnit(address) catch {
1243 if (tty_color) {
1244 try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? (???)" ++ RESET ++ "\n\n\n", .{address});
1245 } else {
1246 try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", .{address});
1247 }
1248 return;
1174 return printLineInfo(out_stream, null, address, "???", "???", tty_color, printLineFromFile);
12491175 };
1176
12501177 const compile_unit_name = try compile_unit.die.getAttrString(self, DW.AT_name);
1251 if (self.getLineNumberInfo(compile_unit.*, address)) |line_info| {
1252 defer line_info.deinit();
1253 const symbol_name = self.getSymbolName(address) orelse "???";
1254 try printLineInfo(
1255 out_stream,
1256 line_info,
1257 address,
1258 symbol_name,
1259 compile_unit_name,
1260 tty_color,
1261 printLineFromFile,
1262 );
1263 } else |err| switch (err) {
1264 error.MissingDebugInfo, error.InvalidDebugInfo => {
1265 if (tty_color) {
1266 try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? ({})" ++ RESET ++ "\n\n\n", .{
1267 address, compile_unit_name,
1268 });
1269 } else {
1270 try out_stream.print("???:?:?: 0x{x} in ??? ({})\n\n\n", .{ address, compile_unit_name });
1271 }
1272 },
1178 const symbol_name = self.getSymbolName(address) orelse "???";
1179 const line_info = self.getLineNumberInfo(compile_unit.*, address) catch |err| switch (err) {
1180 error.MissingDebugInfo, error.InvalidDebugInfo => null,
12731181 else => return err,
1274 }
1182 };
1183 defer if (line_info) |li| li.deinit();
1184
1185 try printLineInfo(
1186 out_stream,
1187 line_info,
1188 address,
1189 symbol_name,
1190 compile_unit_name,
1191 tty_color,
1192 printLineFromFile,
1193 );
12751194 }
12761195
12771196 fn getSymbolName(di: *DwarfInfo, address: u64) ?[]const u8 {
......@@ -1458,9 +1377,13 @@ pub const DwarfInfo = struct {
14581377 if (compile_unit.pc_range) |range| {
14591378 if (target_address >= range.start and target_address < range.end) return compile_unit;
14601379 }
1461 if (compile_unit.die.getAttrSecOffset(DW.AT_ranges)) |ranges_offset| {
1462 var base_address: usize = 0;
1463 if (di.debug_ranges) |debug_ranges| {
1380 if (di.debug_ranges) |debug_ranges| {
1381 if (compile_unit.die.getAttrSecOffset(DW.AT_ranges)) |ranges_offset| {
1382 // All the addresses in the list are relative to the value
1383 // specified by DW_AT_low_pc or to some other value encoded
1384 // in the list itself
1385 var base_address = try compile_unit.die.getAttrAddr(DW.AT_low_pc);
1386
14641387 try di.dwarf_seekable_stream.seekTo(debug_ranges.offset + ranges_offset);
14651388 while (true) {
14661389 const begin_addr = try di.dwarf_in_stream.readIntLittle(usize);
......@@ -1468,18 +1391,21 @@ pub const DwarfInfo = struct {
14681391 if (begin_addr == 0 and end_addr == 0) {
14691392 break;
14701393 }
1394 // This entry selects a new value for the base address
14711395 if (begin_addr == maxInt(usize)) {
1472 base_address = begin_addr;
1396 base_address = end_addr;
14731397 continue;
14741398 }
1475 if (target_address >= begin_addr and target_address < end_addr) {
1399 if (target_address >= base_address + begin_addr and target_address < base_address + end_addr) {
14761400 return compile_unit;
14771401 }
14781402 }
1403
1404 return error.InvalidDebugInfo;
1405 } else |err| {
1406 if (err != error.MissingDebugInfo) return err;
1407 continue;
14791408 }
1480 } else |err| {
1481 if (err != error.MissingDebugInfo) return err;
1482 continue;
14831409 }
14841410 }
14851411 return error.MissingDebugInfo;
......@@ -1552,7 +1478,8 @@ pub const DwarfInfo = struct {
15521478
15531479 assert(line_info_offset < di.debug_line.size);
15541480
1555 try di.dwarf_seekable_stream.seekTo(di.debug_line.offset + line_info_offset);
1481 const this_unit_offset = di.debug_line.offset + line_info_offset;
1482 try di.dwarf_seekable_stream.seekTo(this_unit_offset);
15561483
15571484 var is_64: bool = undefined;
15581485 const unit_length = try readInitialLength(@TypeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64);
......@@ -1620,7 +1547,9 @@ pub const DwarfInfo = struct {
16201547
16211548 try di.dwarf_seekable_stream.seekTo(prog_start_offset);
16221549
1623 while (true) {
1550 const next_unit_pos = this_unit_offset + next_offset;
1551
1552 while ((try di.dwarf_seekable_stream.getPos()) < next_unit_pos) {
16241553 const opcode = try di.dwarf_in_stream.readByte();
16251554
16261555 if (opcode == DW.LNS_extended_op) {
......@@ -1631,7 +1560,7 @@ pub const DwarfInfo = struct {
16311560 DW.LNE_end_sequence => {
16321561 prog.end_sequence = true;
16331562 if (try prog.checkLineMatch()) |info| return info;
1634 return error.MissingDebugInfo;
1563 prog.reset();
16351564 },
16361565 DW.LNE_set_address => {
16371566 const addr = try di.dwarf_in_stream.readInt(usize, di.endian);
......@@ -1888,6 +1817,7 @@ const LineNumberProgram = struct {
18881817 basic_block: bool,
18891818 end_sequence: bool,
18901819
1820 default_is_stmt: bool,
18911821 target_address: usize,
18921822 include_dirs: []const []const u8,
18931823 file_entries: *ArrayList(FileEntry),
......@@ -1900,6 +1830,25 @@ const LineNumberProgram = struct {
19001830 prev_basic_block: bool,
19011831 prev_end_sequence: bool,
19021832
1833 // Reset the state machine following the DWARF specification
1834 pub fn reset(self: *LineNumberProgram) void {
1835 self.address = 0;
1836 self.file = 1;
1837 self.line = 1;
1838 self.column = 0;
1839 self.is_stmt = self.default_is_stmt;
1840 self.basic_block = false;
1841 self.end_sequence = false;
1842 // Invalidate all the remaining fields
1843 self.prev_address = 0;
1844 self.prev_file = undefined;
1845 self.prev_line = undefined;
1846 self.prev_column = undefined;
1847 self.prev_is_stmt = undefined;
1848 self.prev_basic_block = undefined;
1849 self.prev_end_sequence = undefined;
1850 }
1851
19031852 pub fn init(is_stmt: bool, include_dirs: []const []const u8, file_entries: *ArrayList(FileEntry), target_address: usize) LineNumberProgram {
19041853 return LineNumberProgram{
19051854 .address = 0,
......@@ -1911,6 +1860,7 @@ const LineNumberProgram = struct {
19111860 .end_sequence = false,
19121861 .include_dirs = include_dirs,
19131862 .file_entries = file_entries,
1863 .default_is_stmt = is_stmt,
19141864 .target_address = target_address,
19151865 .prev_address = 0,
19161866 .prev_file = undefined,
lib/std/fmt.zig+11-6
......@@ -431,7 +431,7 @@ pub fn formatType(
431431 },
432432 else => return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) }),
433433 },
434 .Many => {
434 .Many, .C => {
435435 if (ptr_info.child == u8) {
436436 if (fmt.len > 0 and fmt[0] == 's') {
437437 const len = mem.len(u8, value);
......@@ -449,9 +449,6 @@ pub fn formatType(
449449 }
450450 return format(context, Errors, output, "{}@{x}", .{ @typeName(ptr_info.child), @ptrToInt(value.ptr) });
451451 },
452 .C => {
453 return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) });
454 },
455452 },
456453 .Array => |info| {
457454 const Slice = @Type(builtin.TypeInfo{
......@@ -1290,8 +1287,16 @@ test "pointer" {
12901287}
12911288
12921289test "cstr" {
1293 try testFmt("cstr: Test C\n", "cstr: {s}\n", .{"Test C"});
1294 try testFmt("cstr: Test C \n", "cstr: {s:10}\n", .{"Test C"});
1290 try testFmt(
1291 "cstr: Test C\n",
1292 "cstr: {s}\n",
1293 .{@ptrCast([*c]const u8, "Test C")},
1294 );
1295 try testFmt(
1296 "cstr: Test C \n",
1297 "cstr: {s:10}\n",
1298 .{@ptrCast([*c]const u8, "Test C")},
1299 );
12951300}
12961301
12971302test "filesize" {
lib/std/io/out_stream.zig+8-4
......@@ -45,10 +45,14 @@ pub fn OutStream(comptime WriteError: type) type {
4545 }
4646
4747 pub fn writeByteNTimes(self: *Self, byte: u8, n: usize) Error!void {
48 const slice = @as(*const [1]u8, &byte)[0..];
49 var i: usize = 0;
50 while (i < n) : (i += 1) {
51 try self.writeFn(self, slice);
48 var bytes: [256]u8 = undefined;
49 mem.set(u8, bytes[0..], byte);
50
51 var remaining: usize = n;
52 while (remaining > 0) {
53 const to_write = std.math.min(remaining, bytes.len);
54 try self.writeFn(self, bytes[0..to_write]);
55 remaining -= to_write;
5256 }
5357 }
5458
lib/std/special/compiler_rt.zig+1
......@@ -130,6 +130,7 @@ comptime {
130130 @export(@import("compiler_rt/int.zig").__udivmoddi4, .{ .name = "__udivmoddi4", .linkage = linkage });
131131 @export(@import("compiler_rt/popcountdi2.zig").__popcountdi2, .{ .name = "__popcountdi2", .linkage = linkage });
132132
133 @export(@import("compiler_rt/int.zig").__mulsi3, .{ .name = "__mulsi3", .linkage = linkage });
133134 @export(@import("compiler_rt/muldi3.zig").__muldi3, .{ .name = "__muldi3", .linkage = linkage });
134135 @export(@import("compiler_rt/int.zig").__divmoddi4, .{ .name = "__divmoddi4", .linkage = linkage });
135136 @export(@import("compiler_rt/int.zig").__divsi3, .{ .name = "__divsi3", .linkage = linkage });
lib/std/special/compiler_rt/int.zig+60
......@@ -1,6 +1,8 @@
11// Builtin functions that operate on integer types
22const builtin = @import("builtin");
33const testing = @import("std").testing;
4const maxInt = @import("std").math.maxInt;
5const minInt = @import("std").math.minInt;
46
57const udivmod = @import("udivmod.zig").udivmod;
68
......@@ -578,3 +580,61 @@ fn test_one_umodsi3(a: u32, b: u32, expected_r: u32) void {
578580 const r: u32 = __umodsi3(a, b);
579581 testing.expect(r == expected_r);
580582}
583
584pub fn __mulsi3(a: i32, b: i32) callconv(.C) i32 {
585 @setRuntimeSafety(builtin.is_test);
586
587 var ua = @bitCast(u32, a);
588 var ub = @bitCast(u32, b);
589 var r: u32 = 0;
590
591 while (ua > 0) {
592 if ((ua & 1) != 0) r +%= ub;
593 ua >>= 1;
594 ub <<= 1;
595 }
596
597 return @bitCast(i32, r);
598}
599
600fn test_one_mulsi3(a: i32, b: i32, result: i32) void {
601 testing.expectEqual(result, __mulsi3(a, b));
602}
603
604test "mulsi3" {
605 test_one_mulsi3(0, 0, 0);
606 test_one_mulsi3(0, 1, 0);
607 test_one_mulsi3(1, 0, 0);
608 test_one_mulsi3(0, 10, 0);
609 test_one_mulsi3(10, 0, 0);
610 test_one_mulsi3(0, maxInt(i32), 0);
611 test_one_mulsi3(maxInt(i32), 0, 0);
612 test_one_mulsi3(0, -1, 0);
613 test_one_mulsi3(-1, 0, 0);
614 test_one_mulsi3(0, -10, 0);
615 test_one_mulsi3(-10, 0, 0);
616 test_one_mulsi3(0, minInt(i32), 0);
617 test_one_mulsi3(minInt(i32), 0, 0);
618 test_one_mulsi3(1, 1, 1);
619 test_one_mulsi3(1, 10, 10);
620 test_one_mulsi3(10, 1, 10);
621 test_one_mulsi3(1, maxInt(i32), maxInt(i32));
622 test_one_mulsi3(maxInt(i32), 1, maxInt(i32));
623 test_one_mulsi3(1, -1, -1);
624 test_one_mulsi3(1, -10, -10);
625 test_one_mulsi3(-10, 1, -10);
626 test_one_mulsi3(1, minInt(i32), minInt(i32));
627 test_one_mulsi3(minInt(i32), 1, minInt(i32));
628 test_one_mulsi3(46340, 46340, 2147395600);
629 test_one_mulsi3(-46340, 46340, -2147395600);
630 test_one_mulsi3(46340, -46340, -2147395600);
631 test_one_mulsi3(-46340, -46340, 2147395600);
632 test_one_mulsi3(4194303, 8192, @truncate(i32, 34359730176));
633 test_one_mulsi3(-4194303, 8192, @truncate(i32, -34359730176));
634 test_one_mulsi3(4194303, -8192, @truncate(i32, -34359730176));
635 test_one_mulsi3(-4194303, -8192, @truncate(i32, 34359730176));
636 test_one_mulsi3(8192, 4194303, @truncate(i32, 34359730176));
637 test_one_mulsi3(-8192, 4194303, @truncate(i32, -34359730176));
638 test_one_mulsi3(8192, -4194303, @truncate(i32, -34359730176));
639 test_one_mulsi3(-8192, -4194303, @truncate(i32, 34359730176));
640}
src-self-hosted/clang.zig+2
......@@ -768,6 +768,7 @@ pub extern fn ZigClangFieldDecl_getCanonicalDecl(field_decl: ?*const struct_ZigC
768768pub extern fn ZigClangEnumDecl_getCanonicalDecl(self: ?*const struct_ZigClangEnumDecl) ?*const struct_ZigClangTagDecl;
769769pub extern fn ZigClangTypedefNameDecl_getCanonicalDecl(self: ?*const struct_ZigClangTypedefNameDecl) ?*const struct_ZigClangTypedefNameDecl;
770770pub extern fn ZigClangFunctionDecl_getCanonicalDecl(self: ?*const struct_ZigClangFunctionDecl) ?*const struct_ZigClangFunctionDecl;
771pub extern fn ZigClangParmVarDecl_getOriginalType(self: ?*const struct_ZigClangParmVarDecl) struct_ZigClangQualType;
771772pub extern fn ZigClangVarDecl_getCanonicalDecl(self: ?*const struct_ZigClangVarDecl) ?*const struct_ZigClangVarDecl;
772773pub extern fn ZigClangVarDecl_getSectionAttribute(self: *const ZigClangVarDecl, len: *usize) ?[*]const u8;
773774pub extern fn ZigClangFunctionDecl_getAlignedAttribute(self: *const ZigClangFunctionDecl, *const ZigClangASTContext) c_uint;
......@@ -809,6 +810,7 @@ pub extern fn ZigClangQualType_isRestrictQualified(self: struct_ZigClangQualType
809810pub extern fn ZigClangType_getTypeClass(self: ?*const struct_ZigClangType) ZigClangTypeClass;
810811pub extern fn ZigClangType_getPointeeType(self: ?*const struct_ZigClangType) struct_ZigClangQualType;
811812pub extern fn ZigClangType_isVoidType(self: ?*const struct_ZigClangType) bool;
813pub extern fn ZigClangType_isConstantArrayType(self: ?*const struct_ZigClangType) bool;
812814pub extern fn ZigClangType_isRecordType(self: ?*const struct_ZigClangType) bool;
813815pub extern fn ZigClangType_isArrayType(self: ?*const struct_ZigClangType) bool;
814816pub extern fn ZigClangType_isBooleanType(self: ?*const struct_ZigClangType) bool;
src-self-hosted/translate_c.zig+20-9
......@@ -485,6 +485,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {
485485 block_scope.block_node = block_node;
486486
487487 var it = proto_node.params.iterator(0);
488 var param_id: c_uint = 0;
488489 while (it.next()) |p| {
489490 const param = @fieldParentPtr(ast.Node.ParamDecl, "base", p.*);
490491 const param_name = if (param.name_token) |name_tok|
......@@ -498,18 +499,27 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {
498499
499500 const mangled_param_name = try block_scope.makeMangledName(c, param_name);
500501
502 const c_param = ZigClangFunctionDecl_getParamDecl(fn_decl, param_id);
503 const qual_type = ZigClangParmVarDecl_getOriginalType(c_param);
504 const is_const = ZigClangQualType_isConstQualified(qual_type);
505
501506 const arg_name = blk: {
502 const bare_arg_name = try std.fmt.allocPrint(c.a(), "arg_{}", .{mangled_param_name});
507 const param_prefix = if (is_const) "" else "arg_";
508 const bare_arg_name = try std.fmt.allocPrint(c.a(), "{}{}", .{param_prefix, mangled_param_name});
503509 break :blk try block_scope.makeMangledName(c, bare_arg_name);
504510 };
505511
506 const node = try transCreateNodeVarDecl(c, false, false, mangled_param_name);
507 node.eq_token = try appendToken(c, .Equal, "=");
508 node.init_node = try transCreateNodeIdentifier(c, arg_name);
509 node.semicolon_token = try appendToken(c, .Semicolon, ";");
510 try block_node.statements.push(&node.base);
511 param.name_token = try appendIdentifier(c, arg_name);
512 _ = try appendToken(c, .Colon, ":");
512 if (!is_const) {
513 const node = try transCreateNodeVarDecl(c, false, false, mangled_param_name);
514 node.eq_token = try appendToken(c, .Equal, "=");
515 node.init_node = try transCreateNodeIdentifier(c, arg_name);
516 node.semicolon_token = try appendToken(c, .Semicolon, ";");
517 try block_node.statements.push(&node.base);
518 param.name_token = try appendIdentifier(c, arg_name);
519 _ = try appendToken(c, .Colon, ":");
520 }
521
522 param_id += 1;
513523 }
514524
515525 transCompoundStmtInline(rp, &block_scope.base, @ptrCast(*const ZigClangCompoundStmt, body_stmt), block_node) catch |err| switch (err) {
......@@ -1982,7 +1992,8 @@ fn transInitListExprArray(
19821992 const arr_type = ZigClangType_getAsArrayTypeUnsafe(ty);
19831993 const child_qt = ZigClangArrayType_getElementType(arr_type);
19841994 const init_count = ZigClangInitListExpr_getNumInits(expr);
1985 const const_arr_ty = @ptrCast(*const ZigClangConstantArrayType, ty);
1995 assert(ZigClangType_isConstantArrayType(@ptrCast(*const ZigClangType, arr_type)));
1996 const const_arr_ty = @ptrCast(*const ZigClangConstantArrayType, arr_type);
19861997 const size_ap_int = ZigClangConstantArrayType_getSize(const_arr_ty);
19871998 const all_count = ZigClangAPInt_getLimitedValue(size_ap_int, math.maxInt(usize));
19881999 const leftover_count = all_count - init_count;
src/all_types.hpp+1380-908
......@@ -33,12 +33,15 @@ struct BuiltinFnEntry;
3333struct TypeStructField;
3434struct CodeGen;
3535struct ZigValue;
36struct IrInstruction;
37struct IrInstructionCast;
38struct IrInstructionAllocaGen;
39struct IrInstructionCallGen;
40struct IrInstructionAwaitGen;
41struct IrBasicBlock;
36struct IrInst;
37struct IrInstSrc;
38struct IrInstGen;
39struct IrInstGenCast;
40struct IrInstGenAlloca;
41struct IrInstGenCall;
42struct IrInstGenAwait;
43struct IrBasicBlockSrc;
44struct IrBasicBlockGen;
4245struct ScopeDecls;
4346struct ZigWindowsSDK;
4447struct Tld;
......@@ -50,6 +53,7 @@ struct ResultLocPeerParent;
5053struct ResultLocBitCast;
5154struct ResultLocCast;
5255struct ResultLocReturn;
56struct IrExecutableGen;
5357
5458enum PtrLen {
5559 PtrLenUnknown,
......@@ -97,8 +101,8 @@ enum X64CABIClass {
97101 X64CABIClass_SSE,
98102};
99103
100struct IrExecutable {
101 ZigList<IrBasicBlock *> basic_block_list;
104struct IrExecutableSrc {
105 ZigList<IrBasicBlockSrc *> basic_block_list;
102106 Buf *name;
103107 ZigFn *name_fn;
104108 size_t mem_slot_count;
......@@ -108,8 +112,7 @@ struct IrExecutable {
108112 ZigFn *fn_entry;
109113 Buf *c_import_buf;
110114 AstNode *source_node;
111 IrExecutable *parent_exec;
112 IrExecutable *source_exec;
115 IrExecutableGen *parent_exec;
113116 IrAnalyze *analysis;
114117 Scope *begin_scope;
115118 ErrorMsg *first_err_trace_msg;
......@@ -124,6 +127,32 @@ struct IrExecutable {
124127 void src();
125128};
126129
130struct IrExecutableGen {
131 ZigList<IrBasicBlockGen *> basic_block_list;
132 Buf *name;
133 ZigFn *name_fn;
134 size_t mem_slot_count;
135 size_t next_debug_id;
136 size_t *backward_branch_count;
137 size_t *backward_branch_quota;
138 ZigFn *fn_entry;
139 Buf *c_import_buf;
140 AstNode *source_node;
141 IrExecutableGen *parent_exec;
142 IrExecutableSrc *source_exec;
143 Scope *begin_scope;
144 ErrorMsg *first_err_trace_msg;
145 ZigList<Tld *> tld_list;
146
147 bool is_inline;
148 bool is_generic_instantiation;
149 bool need_err_code_spill;
150
151 // This is a function for use in the debugger to print
152 // the source location.
153 void src();
154};
155
127156enum OutType {
128157 OutTypeUnknown,
129158 OutTypeExe,
......@@ -287,7 +316,7 @@ struct ConstErrValue {
287316
288317struct ConstBoundFnValue {
289318 ZigFn *fn;
290 IrInstruction *first_arg;
319 IrInstGen *first_arg;
291320};
292321
293322struct ConstArgTuple {
......@@ -350,14 +379,14 @@ struct LazyValueAlignOf {
350379 LazyValue base;
351380
352381 IrAnalyze *ira;
353 IrInstruction *target_type;
382 IrInstGen *target_type;
354383};
355384
356385struct LazyValueSizeOf {
357386 LazyValue base;
358387
359388 IrAnalyze *ira;
360 IrInstruction *target_type;
389 IrInstGen *target_type;
361390
362391 bool bit_size;
363392};
......@@ -366,9 +395,9 @@ struct LazyValueSliceType {
366395 LazyValue base;
367396
368397 IrAnalyze *ira;
369 IrInstruction *sentinel; // can be null
370 IrInstruction *elem_type;
371 IrInstruction *align_inst; // can be null
398 IrInstGen *sentinel; // can be null
399 IrInstGen *elem_type;
400 IrInstGen *align_inst; // can be null
372401
373402 bool is_const;
374403 bool is_volatile;
......@@ -379,8 +408,8 @@ struct LazyValueArrayType {
379408 LazyValue base;
380409
381410 IrAnalyze *ira;
382 IrInstruction *sentinel; // can be null
383 IrInstruction *elem_type;
411 IrInstGen *sentinel; // can be null
412 IrInstGen *elem_type;
384413 uint64_t length;
385414};
386415
......@@ -388,9 +417,9 @@ struct LazyValuePtrType {
388417 LazyValue base;
389418
390419 IrAnalyze *ira;
391 IrInstruction *sentinel; // can be null
392 IrInstruction *elem_type;
393 IrInstruction *align_inst; // can be null
420 IrInstGen *sentinel; // can be null
421 IrInstGen *elem_type;
422 IrInstGen *align_inst; // can be null
394423
395424 PtrLen ptr_len;
396425 uint32_t bit_offset_in_host;
......@@ -405,7 +434,7 @@ struct LazyValueOptType {
405434 LazyValue base;
406435
407436 IrAnalyze *ira;
408 IrInstruction *payload_type;
437 IrInstGen *payload_type;
409438};
410439
411440struct LazyValueFnType {
......@@ -413,9 +442,9 @@ struct LazyValueFnType {
413442
414443 IrAnalyze *ira;
415444 AstNode *proto_node;
416 IrInstruction **param_types;
417 IrInstruction *align_inst; // can be null
418 IrInstruction *return_type;
445 IrInstGen **param_types;
446 IrInstGen *align_inst; // can be null
447 IrInstGen *return_type;
419448
420449 CallingConvention cc;
421450 bool is_generic;
......@@ -425,8 +454,8 @@ struct LazyValueErrUnionType {
425454 LazyValue base;
426455
427456 IrAnalyze *ira;
428 IrInstruction *err_set_type;
429 IrInstruction *payload_type;
457 IrInstGen *err_set_type;
458 IrInstGen *payload_type;
430459 Buf *type_name;
431460};
432461
......@@ -1602,19 +1631,19 @@ struct ZigFn {
16021631 // in the case of async functions this is the implicit return type according to the
16031632 // zig source code, not according to zig ir
16041633 ZigType *src_implicit_return_type;
1605 IrExecutable *ir_executable;
1606 IrExecutable analyzed_executable;
1634 IrExecutableSrc *ir_executable;
1635 IrExecutableGen analyzed_executable;
16071636 size_t prealloc_bbc;
16081637 size_t prealloc_backward_branch_quota;
16091638 AstNode **param_source_nodes;
16101639 Buf **param_names;
1611 IrInstruction *err_code_spill;
1640 IrInstGen *err_code_spill;
16121641 AstNode *assumed_non_async;
16131642
16141643 AstNode *fn_no_inline_set_node;
16151644 AstNode *fn_static_eval_set_node;
16161645
1617 ZigList<IrInstructionAllocaGen *> alloca_gen_list;
1646 ZigList<IrInstGenAlloca *> alloca_gen_list;
16181647 ZigList<ZigVar *> variable_list;
16191648
16201649 Buf *section_name;
......@@ -1626,8 +1655,8 @@ struct ZigFn {
16261655 AstNode *non_async_node;
16271656
16281657 ZigList<GlobalExport> export_list;
1629 ZigList<IrInstructionCallGen *> call_list;
1630 ZigList<IrInstructionAwaitGen *> await_list;
1658 ZigList<IrInstGenCall *> call_list;
1659 ZigList<IrInstGenAwait *> await_list;
16311660
16321661 LLVMValueRef valgrind_client_request_array;
16331662
......@@ -2098,8 +2127,9 @@ struct CodeGen {
20982127 Buf *zig_c_headers_dir; // Cannot be overridden; derived from zig_lib_dir.
20992128 Buf *zig_std_special_dir; // Cannot be overridden; derived from zig_lib_dir.
21002129
2101 IrInstruction *invalid_instruction;
2102 IrInstruction *unreach_instruction;
2130 IrInstSrc *invalid_inst_src;
2131 IrInstGen *invalid_inst_gen;
2132 IrInstGen *unreach_instruction;
21032133
21042134 ZigValue panic_msg_vals[PanicMsgIdCount];
21052135
......@@ -2223,8 +2253,8 @@ struct ZigVar {
22232253 ZigValue *const_value;
22242254 ZigType *var_type;
22252255 LLVMValueRef value_ref;
2226 IrInstruction *is_comptime;
2227 IrInstruction *ptr_instruction;
2256 IrInstSrc *is_comptime;
2257 IrInstGen *ptr_instruction;
22282258 // which node is the declaration of the variable
22292259 AstNode *decl_node;
22302260 ZigLLVMDILocalVariable *di_loc_var;
......@@ -2233,7 +2263,7 @@ struct ZigVar {
22332263 Scope *child_scope;
22342264 LLVMValueRef param_value_ref;
22352265 size_t mem_slot_index;
2236 IrExecutable *owner_exec;
2266 IrExecutableSrc *owner_exec;
22372267
22382268 Buf *section_name;
22392269
......@@ -2324,11 +2354,11 @@ struct ScopeBlock {
23242354 Scope base;
23252355
23262356 Buf *name;
2327 IrBasicBlock *end_block;
2328 IrInstruction *is_comptime;
2357 IrBasicBlockSrc *end_block;
2358 IrInstSrc *is_comptime;
23292359 ResultLocPeerParent *peer_parent;
2330 ZigList<IrInstruction *> *incoming_values;
2331 ZigList<IrBasicBlock *> *incoming_blocks;
2360 ZigList<IrInstSrc *> *incoming_values;
2361 ZigList<IrBasicBlockSrc *> *incoming_blocks;
23322362
23332363 AstNode *safety_set_node;
23342364 AstNode *fast_math_set_node;
......@@ -2379,11 +2409,11 @@ struct ScopeLoop {
23792409
23802410 LVal lval;
23812411 Buf *name;
2382 IrBasicBlock *break_block;
2383 IrBasicBlock *continue_block;
2384 IrInstruction *is_comptime;
2385 ZigList<IrInstruction *> *incoming_values;
2386 ZigList<IrBasicBlock *> *incoming_blocks;
2412 IrBasicBlockSrc *break_block;
2413 IrBasicBlockSrc *continue_block;
2414 IrInstSrc *is_comptime;
2415 ZigList<IrInstSrc *> *incoming_values;
2416 ZigList<IrBasicBlockSrc *> *incoming_blocks;
23872417 ResultLocPeerParent *peer_parent;
23882418 ScopeExpr *spill_scope;
23892419};
......@@ -2394,7 +2424,7 @@ struct ScopeLoop {
23942424struct ScopeRuntime {
23952425 Scope base;
23962426
2397 IrInstruction *is_comptime;
2427 IrInstSrc *is_comptime;
23982428};
23992429
24002430// This scope is created for a suspend block in order to have labeled
......@@ -2473,319 +2503,450 @@ enum AtomicRmwOp {
24732503// to another basic block.
24742504// Phi instructions must be first in a basic block.
24752505// The last instruction in a basic block must be of type unreachable.
2476struct IrBasicBlock {
2477 ZigList<IrInstruction *> instruction_list;
2478 IrBasicBlock *other;
2506struct IrBasicBlockSrc {
2507 ZigList<IrInstSrc *> instruction_list;
2508 IrBasicBlockGen *child;
2509 Scope *scope;
2510 const char *name_hint;
2511 IrInst *suspend_instruction_ref;
2512
2513 uint32_t ref_count;
2514 uint32_t index; // index into the basic block list
2515
2516 uint32_t debug_id;
2517 bool suspended;
2518 bool in_resume_stack;
2519};
2520
2521struct IrBasicBlockGen {
2522 ZigList<IrInstGen *> instruction_list;
2523 IrBasicBlockSrc *parent;
24792524 Scope *scope;
24802525 const char *name_hint;
2481 size_t debug_id;
2482 size_t ref_count;
2483 // index into the basic block list
2484 size_t index;
2526 uint32_t index; // index into the basic block list
2527 uint32_t ref_count;
24852528 LLVMBasicBlockRef llvm_block;
24862529 LLVMBasicBlockRef llvm_exit_block;
24872530 // The instruction that referenced this basic block and caused us to
24882531 // analyze the basic block. If the same instruction wants us to emit
24892532 // the same basic block, then we re-generate it instead of saving it.
2490 IrInstruction *ref_instruction;
2533 IrInst *ref_instruction;
24912534 // When this is non-null, a branch to this basic block is only allowed
24922535 // if the branch is comptime. The instruction points to the reason
24932536 // the basic block must be comptime.
2494 IrInstruction *must_be_comptime_source_instr;
2495 IrInstruction *suspend_instruction_ref;
2537 IrInst *must_be_comptime_source_instr;
2538
2539 uint32_t debug_id;
24962540 bool already_appended;
2497 bool suspended;
2498 bool in_resume_stack;
24992541};
25002542
2501// These instructions are in transition to having "pass 1" instructions
2502// and "pass 2" instructions. The pass 1 instructions are suffixed with Src
2503// and pass 2 are suffixed with Gen.
2504// Once all instructions are separated in this way, they'll have different
2505// base types for better type safety.
25062543// Src instructions are generated by ir_gen_* functions in ir.cpp from AST.
25072544// ir_analyze_* functions consume Src instructions and produce Gen instructions.
2545// Src instructions do not have type information; Gen instructions do.
2546enum IrInstSrcId {
2547 IrInstSrcIdInvalid,
2548 IrInstSrcIdDeclVar,
2549 IrInstSrcIdBr,
2550 IrInstSrcIdCondBr,
2551 IrInstSrcIdSwitchBr,
2552 IrInstSrcIdSwitchVar,
2553 IrInstSrcIdSwitchElseVar,
2554 IrInstSrcIdSwitchTarget,
2555 IrInstSrcIdPhi,
2556 IrInstSrcIdUnOp,
2557 IrInstSrcIdBinOp,
2558 IrInstSrcIdMergeErrSets,
2559 IrInstSrcIdLoadPtr,
2560 IrInstSrcIdStorePtr,
2561 IrInstSrcIdFieldPtr,
2562 IrInstSrcIdElemPtr,
2563 IrInstSrcIdVarPtr,
2564 IrInstSrcIdCall,
2565 IrInstSrcIdCallArgs,
2566 IrInstSrcIdCallExtra,
2567 IrInstSrcIdConst,
2568 IrInstSrcIdReturn,
2569 IrInstSrcIdContainerInitList,
2570 IrInstSrcIdContainerInitFields,
2571 IrInstSrcIdUnreachable,
2572 IrInstSrcIdTypeOf,
2573 IrInstSrcIdSetCold,
2574 IrInstSrcIdSetRuntimeSafety,
2575 IrInstSrcIdSetFloatMode,
2576 IrInstSrcIdArrayType,
2577 IrInstSrcIdAnyFrameType,
2578 IrInstSrcIdSliceType,
2579 IrInstSrcIdAsm,
2580 IrInstSrcIdSizeOf,
2581 IrInstSrcIdTestNonNull,
2582 IrInstSrcIdOptionalUnwrapPtr,
2583 IrInstSrcIdClz,
2584 IrInstSrcIdCtz,
2585 IrInstSrcIdPopCount,
2586 IrInstSrcIdBswap,
2587 IrInstSrcIdBitReverse,
2588 IrInstSrcIdImport,
2589 IrInstSrcIdCImport,
2590 IrInstSrcIdCInclude,
2591 IrInstSrcIdCDefine,
2592 IrInstSrcIdCUndef,
2593 IrInstSrcIdRef,
2594 IrInstSrcIdCompileErr,
2595 IrInstSrcIdCompileLog,
2596 IrInstSrcIdErrName,
2597 IrInstSrcIdEmbedFile,
2598 IrInstSrcIdCmpxchg,
2599 IrInstSrcIdFence,
2600 IrInstSrcIdTruncate,
2601 IrInstSrcIdIntCast,
2602 IrInstSrcIdFloatCast,
2603 IrInstSrcIdIntToFloat,
2604 IrInstSrcIdFloatToInt,
2605 IrInstSrcIdBoolToInt,
2606 IrInstSrcIdIntType,
2607 IrInstSrcIdVectorType,
2608 IrInstSrcIdShuffleVector,
2609 IrInstSrcIdSplat,
2610 IrInstSrcIdBoolNot,
2611 IrInstSrcIdMemset,
2612 IrInstSrcIdMemcpy,
2613 IrInstSrcIdSlice,
2614 IrInstSrcIdMemberCount,
2615 IrInstSrcIdMemberType,
2616 IrInstSrcIdMemberName,
2617 IrInstSrcIdBreakpoint,
2618 IrInstSrcIdReturnAddress,
2619 IrInstSrcIdFrameAddress,
2620 IrInstSrcIdFrameHandle,
2621 IrInstSrcIdFrameType,
2622 IrInstSrcIdFrameSize,
2623 IrInstSrcIdAlignOf,
2624 IrInstSrcIdOverflowOp,
2625 IrInstSrcIdTestErr,
2626 IrInstSrcIdMulAdd,
2627 IrInstSrcIdFloatOp,
2628 IrInstSrcIdUnwrapErrCode,
2629 IrInstSrcIdUnwrapErrPayload,
2630 IrInstSrcIdFnProto,
2631 IrInstSrcIdTestComptime,
2632 IrInstSrcIdPtrCast,
2633 IrInstSrcIdBitCast,
2634 IrInstSrcIdIntToPtr,
2635 IrInstSrcIdPtrToInt,
2636 IrInstSrcIdIntToEnum,
2637 IrInstSrcIdEnumToInt,
2638 IrInstSrcIdIntToErr,
2639 IrInstSrcIdErrToInt,
2640 IrInstSrcIdCheckSwitchProngs,
2641 IrInstSrcIdCheckStatementIsVoid,
2642 IrInstSrcIdTypeName,
2643 IrInstSrcIdDeclRef,
2644 IrInstSrcIdPanic,
2645 IrInstSrcIdTagName,
2646 IrInstSrcIdTagType,
2647 IrInstSrcIdFieldParentPtr,
2648 IrInstSrcIdByteOffsetOf,
2649 IrInstSrcIdBitOffsetOf,
2650 IrInstSrcIdTypeInfo,
2651 IrInstSrcIdType,
2652 IrInstSrcIdHasField,
2653 IrInstSrcIdTypeId,
2654 IrInstSrcIdSetEvalBranchQuota,
2655 IrInstSrcIdPtrType,
2656 IrInstSrcIdAlignCast,
2657 IrInstSrcIdImplicitCast,
2658 IrInstSrcIdResolveResult,
2659 IrInstSrcIdResetResult,
2660 IrInstSrcIdOpaqueType,
2661 IrInstSrcIdSetAlignStack,
2662 IrInstSrcIdArgType,
2663 IrInstSrcIdExport,
2664 IrInstSrcIdErrorReturnTrace,
2665 IrInstSrcIdErrorUnion,
2666 IrInstSrcIdAtomicRmw,
2667 IrInstSrcIdAtomicLoad,
2668 IrInstSrcIdAtomicStore,
2669 IrInstSrcIdSaveErrRetAddr,
2670 IrInstSrcIdAddImplicitReturnType,
2671 IrInstSrcIdErrSetCast,
2672 IrInstSrcIdToBytes,
2673 IrInstSrcIdFromBytes,
2674 IrInstSrcIdCheckRuntimeScope,
2675 IrInstSrcIdHasDecl,
2676 IrInstSrcIdUndeclaredIdent,
2677 IrInstSrcIdAlloca,
2678 IrInstSrcIdEndExpr,
2679 IrInstSrcIdUnionInitNamedField,
2680 IrInstSrcIdSuspendBegin,
2681 IrInstSrcIdSuspendFinish,
2682 IrInstSrcIdAwait,
2683 IrInstSrcIdResume,
2684 IrInstSrcIdSpillBegin,
2685 IrInstSrcIdSpillEnd,
2686};
2687
25082688// ir_render_* functions in codegen.cpp consume Gen instructions and produce LLVM IR.
25092689// Src instructions do not have type information; Gen instructions do.
2510enum IrInstructionId {
2511 IrInstructionIdInvalid,
2512 IrInstructionIdDeclVarSrc,
2513 IrInstructionIdDeclVarGen,
2514 IrInstructionIdBr,
2515 IrInstructionIdCondBr,
2516 IrInstructionIdSwitchBr,
2517 IrInstructionIdSwitchVar,
2518 IrInstructionIdSwitchElseVar,
2519 IrInstructionIdSwitchTarget,
2520 IrInstructionIdPhi,
2521 IrInstructionIdUnOp,
2522 IrInstructionIdBinOp,
2523 IrInstructionIdMergeErrSets,
2524 IrInstructionIdLoadPtr,
2525 IrInstructionIdLoadPtrGen,
2526 IrInstructionIdStorePtr,
2527 IrInstructionIdVectorStoreElem,
2528 IrInstructionIdFieldPtr,
2529 IrInstructionIdStructFieldPtr,
2530 IrInstructionIdUnionFieldPtr,
2531 IrInstructionIdElemPtr,
2532 IrInstructionIdVarPtr,
2533 IrInstructionIdReturnPtr,
2534 IrInstructionIdCallSrc,
2535 IrInstructionIdCallSrcArgs,
2536 IrInstructionIdCallExtra,
2537 IrInstructionIdCallGen,
2538 IrInstructionIdConst,
2539 IrInstructionIdReturn,
2540 IrInstructionIdCast,
2541 IrInstructionIdResizeSlice,
2542 IrInstructionIdContainerInitList,
2543 IrInstructionIdContainerInitFields,
2544 IrInstructionIdUnreachable,
2545 IrInstructionIdTypeOf,
2546 IrInstructionIdSetCold,
2547 IrInstructionIdSetRuntimeSafety,
2548 IrInstructionIdSetFloatMode,
2549 IrInstructionIdArrayType,
2550 IrInstructionIdAnyFrameType,
2551 IrInstructionIdSliceType,
2552 IrInstructionIdAsmSrc,
2553 IrInstructionIdAsmGen,
2554 IrInstructionIdSizeOf,
2555 IrInstructionIdTestNonNull,
2556 IrInstructionIdOptionalUnwrapPtr,
2557 IrInstructionIdOptionalWrap,
2558 IrInstructionIdUnionTag,
2559 IrInstructionIdClz,
2560 IrInstructionIdCtz,
2561 IrInstructionIdPopCount,
2562 IrInstructionIdBswap,
2563 IrInstructionIdBitReverse,
2564 IrInstructionIdImport,
2565 IrInstructionIdCImport,
2566 IrInstructionIdCInclude,
2567 IrInstructionIdCDefine,
2568 IrInstructionIdCUndef,
2569 IrInstructionIdRef,
2570 IrInstructionIdRefGen,
2571 IrInstructionIdCompileErr,
2572 IrInstructionIdCompileLog,
2573 IrInstructionIdErrName,
2574 IrInstructionIdEmbedFile,
2575 IrInstructionIdCmpxchgSrc,
2576 IrInstructionIdCmpxchgGen,
2577 IrInstructionIdFence,
2578 IrInstructionIdTruncate,
2579 IrInstructionIdIntCast,
2580 IrInstructionIdFloatCast,
2581 IrInstructionIdIntToFloat,
2582 IrInstructionIdFloatToInt,
2583 IrInstructionIdBoolToInt,
2584 IrInstructionIdIntType,
2585 IrInstructionIdVectorType,
2586 IrInstructionIdShuffleVector,
2587 IrInstructionIdSplatSrc,
2588 IrInstructionIdSplatGen,
2589 IrInstructionIdBoolNot,
2590 IrInstructionIdMemset,
2591 IrInstructionIdMemcpy,
2592 IrInstructionIdSliceSrc,
2593 IrInstructionIdSliceGen,
2594 IrInstructionIdMemberCount,
2595 IrInstructionIdMemberType,
2596 IrInstructionIdMemberName,
2597 IrInstructionIdBreakpoint,
2598 IrInstructionIdReturnAddress,
2599 IrInstructionIdFrameAddress,
2600 IrInstructionIdFrameHandle,
2601 IrInstructionIdFrameType,
2602 IrInstructionIdFrameSizeSrc,
2603 IrInstructionIdFrameSizeGen,
2604 IrInstructionIdAlignOf,
2605 IrInstructionIdOverflowOp,
2606 IrInstructionIdTestErrSrc,
2607 IrInstructionIdTestErrGen,
2608 IrInstructionIdMulAdd,
2609 IrInstructionIdFloatOp,
2610 IrInstructionIdUnwrapErrCode,
2611 IrInstructionIdUnwrapErrPayload,
2612 IrInstructionIdErrWrapCode,
2613 IrInstructionIdErrWrapPayload,
2614 IrInstructionIdFnProto,
2615 IrInstructionIdTestComptime,
2616 IrInstructionIdPtrCastSrc,
2617 IrInstructionIdPtrCastGen,
2618 IrInstructionIdBitCastSrc,
2619 IrInstructionIdBitCastGen,
2620 IrInstructionIdWidenOrShorten,
2621 IrInstructionIdIntToPtr,
2622 IrInstructionIdPtrToInt,
2623 IrInstructionIdIntToEnum,
2624 IrInstructionIdEnumToInt,
2625 IrInstructionIdIntToErr,
2626 IrInstructionIdErrToInt,
2627 IrInstructionIdCheckSwitchProngs,
2628 IrInstructionIdCheckStatementIsVoid,
2629 IrInstructionIdTypeName,
2630 IrInstructionIdDeclRef,
2631 IrInstructionIdPanic,
2632 IrInstructionIdTagName,
2633 IrInstructionIdTagType,
2634 IrInstructionIdFieldParentPtr,
2635 IrInstructionIdByteOffsetOf,
2636 IrInstructionIdBitOffsetOf,
2637 IrInstructionIdTypeInfo,
2638 IrInstructionIdType,
2639 IrInstructionIdHasField,
2640 IrInstructionIdTypeId,
2641 IrInstructionIdSetEvalBranchQuota,
2642 IrInstructionIdPtrType,
2643 IrInstructionIdAlignCast,
2644 IrInstructionIdImplicitCast,
2645 IrInstructionIdResolveResult,
2646 IrInstructionIdResetResult,
2647 IrInstructionIdOpaqueType,
2648 IrInstructionIdSetAlignStack,
2649 IrInstructionIdArgType,
2650 IrInstructionIdExport,
2651 IrInstructionIdErrorReturnTrace,
2652 IrInstructionIdErrorUnion,
2653 IrInstructionIdAtomicRmw,
2654 IrInstructionIdAtomicLoad,
2655 IrInstructionIdAtomicStore,
2656 IrInstructionIdSaveErrRetAddr,
2657 IrInstructionIdAddImplicitReturnType,
2658 IrInstructionIdErrSetCast,
2659 IrInstructionIdToBytes,
2660 IrInstructionIdFromBytes,
2661 IrInstructionIdCheckRuntimeScope,
2662 IrInstructionIdVectorToArray,
2663 IrInstructionIdArrayToVector,
2664 IrInstructionIdAssertZero,
2665 IrInstructionIdAssertNonNull,
2666 IrInstructionIdHasDecl,
2667 IrInstructionIdUndeclaredIdent,
2668 IrInstructionIdAllocaSrc,
2669 IrInstructionIdAllocaGen,
2670 IrInstructionIdEndExpr,
2671 IrInstructionIdPtrOfArrayToSlice,
2672 IrInstructionIdUnionInitNamedField,
2673 IrInstructionIdSuspendBegin,
2674 IrInstructionIdSuspendFinish,
2675 IrInstructionIdAwaitSrc,
2676 IrInstructionIdAwaitGen,
2677 IrInstructionIdResume,
2678 IrInstructionIdSpillBegin,
2679 IrInstructionIdSpillEnd,
2680 IrInstructionIdVectorExtractElem,
2681};
2682
2683struct IrInstruction {
2684 Scope *scope;
2685 AstNode *source_node;
2686 LLVMValueRef llvm_value;
2687 ZigValue *value;
2688 uint32_t debug_id;
2690enum IrInstGenId {
2691 IrInstGenIdInvalid,
2692 IrInstGenIdDeclVar,
2693 IrInstGenIdBr,
2694 IrInstGenIdCondBr,
2695 IrInstGenIdSwitchBr,
2696 IrInstGenIdPhi,
2697 IrInstGenIdBinaryNot,
2698 IrInstGenIdNegation,
2699 IrInstGenIdNegationWrapping,
2700 IrInstGenIdBinOp,
2701 IrInstGenIdLoadPtr,
2702 IrInstGenIdStorePtr,
2703 IrInstGenIdVectorStoreElem,
2704 IrInstGenIdStructFieldPtr,
2705 IrInstGenIdUnionFieldPtr,
2706 IrInstGenIdElemPtr,
2707 IrInstGenIdVarPtr,
2708 IrInstGenIdReturnPtr,
2709 IrInstGenIdCall,
2710 IrInstGenIdReturn,
2711 IrInstGenIdCast,
2712 IrInstGenIdResizeSlice,
2713 IrInstGenIdUnreachable,
2714 IrInstGenIdAsm,
2715 IrInstGenIdTestNonNull,
2716 IrInstGenIdOptionalUnwrapPtr,
2717 IrInstGenIdOptionalWrap,
2718 IrInstGenIdUnionTag,
2719 IrInstGenIdClz,
2720 IrInstGenIdCtz,
2721 IrInstGenIdPopCount,
2722 IrInstGenIdBswap,
2723 IrInstGenIdBitReverse,
2724 IrInstGenIdRef,
2725 IrInstGenIdErrName,
2726 IrInstGenIdCmpxchg,
2727 IrInstGenIdFence,
2728 IrInstGenIdTruncate,
2729 IrInstGenIdShuffleVector,
2730 IrInstGenIdSplat,
2731 IrInstGenIdBoolNot,
2732 IrInstGenIdMemset,
2733 IrInstGenIdMemcpy,
2734 IrInstGenIdSlice,
2735 IrInstGenIdBreakpoint,
2736 IrInstGenIdReturnAddress,
2737 IrInstGenIdFrameAddress,
2738 IrInstGenIdFrameHandle,
2739 IrInstGenIdFrameSize,
2740 IrInstGenIdOverflowOp,
2741 IrInstGenIdTestErr,
2742 IrInstGenIdMulAdd,
2743 IrInstGenIdFloatOp,
2744 IrInstGenIdUnwrapErrCode,
2745 IrInstGenIdUnwrapErrPayload,
2746 IrInstGenIdErrWrapCode,
2747 IrInstGenIdErrWrapPayload,
2748 IrInstGenIdPtrCast,
2749 IrInstGenIdBitCast,
2750 IrInstGenIdWidenOrShorten,
2751 IrInstGenIdIntToPtr,
2752 IrInstGenIdPtrToInt,
2753 IrInstGenIdIntToEnum,
2754 IrInstGenIdIntToErr,
2755 IrInstGenIdErrToInt,
2756 IrInstGenIdPanic,
2757 IrInstGenIdTagName,
2758 IrInstGenIdFieldParentPtr,
2759 IrInstGenIdAlignCast,
2760 IrInstGenIdErrorReturnTrace,
2761 IrInstGenIdAtomicRmw,
2762 IrInstGenIdAtomicLoad,
2763 IrInstGenIdAtomicStore,
2764 IrInstGenIdSaveErrRetAddr,
2765 IrInstGenIdVectorToArray,
2766 IrInstGenIdArrayToVector,
2767 IrInstGenIdAssertZero,
2768 IrInstGenIdAssertNonNull,
2769 IrInstGenIdPtrOfArrayToSlice,
2770 IrInstGenIdSuspendBegin,
2771 IrInstGenIdSuspendFinish,
2772 IrInstGenIdAwait,
2773 IrInstGenIdResume,
2774 IrInstGenIdSpillBegin,
2775 IrInstGenIdSpillEnd,
2776 IrInstGenIdVectorExtractElem,
2777 IrInstGenIdAlloca,
2778 IrInstGenIdConst,
2779};
2780
2781// Common fields between IrInstSrc and IrInstGen. This allows future passes
2782// after pass2 to be added to zig.
2783struct IrInst {
26892784 // if ref_count is zero and the instruction has no side effects,
26902785 // the instruction can be omitted in codegen
26912786 uint32_t ref_count;
2787 uint32_t debug_id;
2788
2789 Scope *scope;
2790 AstNode *source_node;
2791
2792 // for debugging purposes, these are useful to call to inspect the instruction
2793 void dump();
2794 void src();
2795};
2796
2797struct IrInstSrc {
2798 IrInst base;
2799
2800 IrInstSrcId id;
2801 // true if this instruction was generated by zig and not from user code
2802 // this matters for the "unreachable code" compile error
2803 bool is_gen;
2804 bool is_noreturn;
2805
26922806 // When analyzing IR, instructions that point to this instruction in the "old ir"
26932807 // can find the instruction that corresponds to this value in the "new ir"
26942808 // with this child field.
2695 IrInstruction *child;
2696 IrBasicBlock *owner_bb;
2809 IrInstGen *child;
2810 IrBasicBlockSrc *owner_bb;
2811
2812 // for debugging purposes, these are useful to call to inspect the instruction
2813 void dump();
2814 void src();
2815};
2816
2817struct IrInstGen {
2818 IrInst base;
2819
2820 IrInstGenId id;
2821
2822 LLVMValueRef llvm_value;
2823 ZigValue *value;
2824 IrBasicBlockGen *owner_bb;
26972825 // Nearly any instruction can have to be stored as a local variable before suspending
26982826 // and then loaded after resuming, in case there is an expression with a suspend point
26992827 // in it, such as: x + await y
2700 IrInstruction *spill;
2701 IrInstructionId id;
2702 // true if this instruction was generated by zig and not from user code
2703 bool is_gen;
2828 IrInstGen *spill;
27042829
27052830 // for debugging purposes, these are useful to call to inspect the instruction
27062831 void dump();
27072832 void src();
27082833};
27092834
2710struct IrInstructionDeclVarSrc {
2711 IrInstruction base;
2835struct IrInstSrcDeclVar {
2836 IrInstSrc base;
27122837
27132838 ZigVar *var;
2714 IrInstruction *var_type;
2715 IrInstruction *align_value;
2716 IrInstruction *ptr;
2839 IrInstSrc *var_type;
2840 IrInstSrc *align_value;
2841 IrInstSrc *ptr;
27172842};
27182843
2719struct IrInstructionDeclVarGen {
2720 IrInstruction base;
2844struct IrInstGenDeclVar {
2845 IrInstGen base;
27212846
27222847 ZigVar *var;
2723 IrInstruction *var_ptr;
2848 IrInstGen *var_ptr;
27242849};
27252850
2726struct IrInstructionCondBr {
2727 IrInstruction base;
2851struct IrInstSrcCondBr {
2852 IrInstSrc base;
27282853
2729 IrInstruction *condition;
2730 IrBasicBlock *then_block;
2731 IrBasicBlock *else_block;
2732 IrInstruction *is_comptime;
2854 IrInstSrc *condition;
2855 IrBasicBlockSrc *then_block;
2856 IrBasicBlockSrc *else_block;
2857 IrInstSrc *is_comptime;
27332858 ResultLoc *result_loc;
27342859};
27352860
2736struct IrInstructionBr {
2737 IrInstruction base;
2861struct IrInstGenCondBr {
2862 IrInstGen base;
2863
2864 IrInstGen *condition;
2865 IrBasicBlockGen *then_block;
2866 IrBasicBlockGen *else_block;
2867};
2868
2869struct IrInstSrcBr {
2870 IrInstSrc base;
2871
2872 IrBasicBlockSrc *dest_block;
2873 IrInstSrc *is_comptime;
2874};
2875
2876struct IrInstGenBr {
2877 IrInstGen base;
2878
2879 IrBasicBlockGen *dest_block;
2880};
2881
2882struct IrInstSrcSwitchBrCase {
2883 IrInstSrc *value;
2884 IrBasicBlockSrc *block;
2885};
2886
2887struct IrInstSrcSwitchBr {
2888 IrInstSrc base;
27382889
2739 IrBasicBlock *dest_block;
2740 IrInstruction *is_comptime;
2890 IrInstSrc *target_value;
2891 IrBasicBlockSrc *else_block;
2892 size_t case_count;
2893 IrInstSrcSwitchBrCase *cases;
2894 IrInstSrc *is_comptime;
2895 IrInstSrc *switch_prongs_void;
27412896};
27422897
2743struct IrInstructionSwitchBrCase {
2744 IrInstruction *value;
2745 IrBasicBlock *block;
2898struct IrInstGenSwitchBrCase {
2899 IrInstGen *value;
2900 IrBasicBlockGen *block;
27462901};
27472902
2748struct IrInstructionSwitchBr {
2749 IrInstruction base;
2903struct IrInstGenSwitchBr {
2904 IrInstGen base;
27502905
2751 IrInstruction *target_value;
2752 IrBasicBlock *else_block;
2906 IrInstGen *target_value;
2907 IrBasicBlockGen *else_block;
27532908 size_t case_count;
2754 IrInstructionSwitchBrCase *cases;
2755 IrInstruction *is_comptime;
2756 IrInstruction *switch_prongs_void;
2909 IrInstGenSwitchBrCase *cases;
27572910};
27582911
2759struct IrInstructionSwitchVar {
2760 IrInstruction base;
2912struct IrInstSrcSwitchVar {
2913 IrInstSrc base;
27612914
2762 IrInstruction *target_value_ptr;
2763 IrInstruction **prongs_ptr;
2915 IrInstSrc *target_value_ptr;
2916 IrInstSrc **prongs_ptr;
27642917 size_t prongs_len;
27652918};
27662919
2767struct IrInstructionSwitchElseVar {
2768 IrInstruction base;
2920struct IrInstSrcSwitchElseVar {
2921 IrInstSrc base;
27692922
2770 IrInstruction *target_value_ptr;
2771 IrInstructionSwitchBr *switch_br;
2923 IrInstSrc *target_value_ptr;
2924 IrInstSrcSwitchBr *switch_br;
27722925};
27732926
2774struct IrInstructionSwitchTarget {
2775 IrInstruction base;
2927struct IrInstSrcSwitchTarget {
2928 IrInstSrc base;
27762929
2777 IrInstruction *target_value_ptr;
2930 IrInstSrc *target_value_ptr;
27782931};
27792932
2780struct IrInstructionPhi {
2781 IrInstruction base;
2933struct IrInstSrcPhi {
2934 IrInstSrc base;
27822935
27832936 size_t incoming_count;
2784 IrBasicBlock **incoming_blocks;
2785 IrInstruction **incoming_values;
2937 IrBasicBlockSrc **incoming_blocks;
2938 IrInstSrc **incoming_values;
27862939 ResultLocPeerParent *peer_parent;
27872940};
27882941
2942struct IrInstGenPhi {
2943 IrInstGen base;
2944
2945 size_t incoming_count;
2946 IrBasicBlockGen **incoming_blocks;
2947 IrInstGen **incoming_values;
2948};
2949
27892950enum IrUnOp {
27902951 IrUnOpInvalid,
27912952 IrUnOpBinNot,
......@@ -2795,15 +2956,30 @@ enum IrUnOp {
27952956 IrUnOpOptional,
27962957};
27972958
2798struct IrInstructionUnOp {
2799 IrInstruction base;
2959struct IrInstSrcUnOp {
2960 IrInstSrc base;
28002961
28012962 IrUnOp op_id;
28022963 LVal lval;
2803 IrInstruction *value;
2964 IrInstSrc *value;
28042965 ResultLoc *result_loc;
28052966};
28062967
2968struct IrInstGenBinaryNot {
2969 IrInstGen base;
2970 IrInstGen *operand;
2971};
2972
2973struct IrInstGenNegation {
2974 IrInstGen base;
2975 IrInstGen *operand;
2976};
2977
2978struct IrInstGenNegationWrapping {
2979 IrInstGen base;
2980 IrInstGen *operand;
2981};
2982
28072983enum IrBinOp {
28082984 IrBinOpInvalid,
28092985 IrBinOpBoolOr,
......@@ -2838,113 +3014,144 @@ enum IrBinOp {
28383014 IrBinOpArrayMult,
28393015};
28403016
2841struct IrInstructionBinOp {
2842 IrInstruction base;
3017struct IrInstSrcBinOp {
3018 IrInstSrc base;
3019
3020 IrInstSrc *op1;
3021 IrInstSrc *op2;
3022 IrBinOp op_id;
3023 bool safety_check_on;
3024};
3025
3026struct IrInstGenBinOp {
3027 IrInstGen base;
28433028
2844 IrInstruction *op1;
2845 IrInstruction *op2;
3029 IrInstGen *op1;
3030 IrInstGen *op2;
28463031 IrBinOp op_id;
28473032 bool safety_check_on;
28483033};
28493034
2850struct IrInstructionMergeErrSets {
2851 IrInstruction base;
3035struct IrInstSrcMergeErrSets {
3036 IrInstSrc base;
28523037
2853 IrInstruction *op1;
2854 IrInstruction *op2;
3038 IrInstSrc *op1;
3039 IrInstSrc *op2;
28553040 Buf *type_name;
28563041};
28573042
2858struct IrInstructionLoadPtr {
2859 IrInstruction base;
3043struct IrInstSrcLoadPtr {
3044 IrInstSrc base;
28603045
2861 IrInstruction *ptr;
3046 IrInstSrc *ptr;
28623047};
28633048
2864struct IrInstructionLoadPtrGen {
2865 IrInstruction base;
3049struct IrInstGenLoadPtr {
3050 IrInstGen base;
28663051
2867 IrInstruction *ptr;
2868 IrInstruction *result_loc;
3052 IrInstGen *ptr;
3053 IrInstGen *result_loc;
28693054};
28703055
2871struct IrInstructionStorePtr {
2872 IrInstruction base;
3056struct IrInstSrcStorePtr {
3057 IrInstSrc base;
3058
3059 IrInstSrc *ptr;
3060 IrInstSrc *value;
28733061
28743062 bool allow_write_through_const;
2875 IrInstruction *ptr;
2876 IrInstruction *value;
28773063};
28783064
2879struct IrInstructionVectorStoreElem {
2880 IrInstruction base;
3065struct IrInstGenStorePtr {
3066 IrInstGen base;
28813067
2882 IrInstruction *vector_ptr;
2883 IrInstruction *index;
2884 IrInstruction *value;
3068 IrInstGen *ptr;
3069 IrInstGen *value;
28853070};
28863071
2887struct IrInstructionFieldPtr {
2888 IrInstruction base;
3072struct IrInstGenVectorStoreElem {
3073 IrInstGen base;
28893074
2890 bool initializing;
2891 IrInstruction *container_ptr;
3075 IrInstGen *vector_ptr;
3076 IrInstGen *index;
3077 IrInstGen *value;
3078};
3079
3080struct IrInstSrcFieldPtr {
3081 IrInstSrc base;
3082
3083 IrInstSrc *container_ptr;
28923084 Buf *field_name_buffer;
2893 IrInstruction *field_name_expr;
3085 IrInstSrc *field_name_expr;
3086 bool initializing;
28943087};
28953088
2896struct IrInstructionStructFieldPtr {
2897 IrInstruction base;
3089struct IrInstGenStructFieldPtr {
3090 IrInstGen base;
28983091
2899 IrInstruction *struct_ptr;
3092 IrInstGen *struct_ptr;
29003093 TypeStructField *field;
29013094 bool is_const;
29023095};
29033096
2904struct IrInstructionUnionFieldPtr {
2905 IrInstruction base;
3097struct IrInstGenUnionFieldPtr {
3098 IrInstGen base;
29063099
3100 IrInstGen *union_ptr;
3101 TypeUnionField *field;
29073102 bool safety_check_on;
29083103 bool initializing;
2909 IrInstruction *union_ptr;
2910 TypeUnionField *field;
29113104};
29123105
2913struct IrInstructionElemPtr {
2914 IrInstruction base;
3106struct IrInstSrcElemPtr {
3107 IrInstSrc base;
29153108
2916 IrInstruction *array_ptr;
2917 IrInstruction *elem_index;
3109 IrInstSrc *array_ptr;
3110 IrInstSrc *elem_index;
29183111 AstNode *init_array_type_source_node;
29193112 PtrLen ptr_len;
29203113 bool safety_check_on;
29213114};
29223115
2923struct IrInstructionVarPtr {
2924 IrInstruction base;
3116struct IrInstGenElemPtr {
3117 IrInstGen base;
3118
3119 IrInstGen *array_ptr;
3120 IrInstGen *elem_index;
3121 bool safety_check_on;
3122};
3123
3124struct IrInstSrcVarPtr {
3125 IrInstSrc base;
29253126
29263127 ZigVar *var;
29273128 ScopeFnDef *crossed_fndef_scope;
29283129};
29293130
3131struct IrInstGenVarPtr {
3132 IrInstGen base;
3133
3134 ZigVar *var;
3135};
3136
29303137// For functions that have a return type for which handle_is_ptr is true, a
29313138// result location pointer is the secret first parameter ("sret"). This
29323139// instruction returns that pointer.
2933struct IrInstructionReturnPtr {
2934 IrInstruction base;
3140struct IrInstGenReturnPtr {
3141 IrInstGen base;
29353142};
29363143
2937struct IrInstructionCallSrc {
2938 IrInstruction base;
3144struct IrInstSrcCall {
3145 IrInstSrc base;
29393146
2940 IrInstruction *fn_ref;
3147 IrInstSrc *fn_ref;
29413148 ZigFn *fn_entry;
29423149 size_t arg_count;
2943 IrInstruction **args;
2944 IrInstruction *ret_ptr;
3150 IrInstSrc **args;
3151 IrInstSrc *ret_ptr;
29453152 ResultLoc *result_loc;
29463153
2947 IrInstruction *new_stack;
3154 IrInstSrc *new_stack;
29483155
29493156 CallModifier modifier;
29503157 bool is_async_call_builtin;
......@@ -2952,12 +3159,12 @@ struct IrInstructionCallSrc {
29523159
29533160// This is a pass1 instruction, used by @call when the args node is
29543161// a tuple or struct literal.
2955struct IrInstructionCallSrcArgs {
2956 IrInstruction base;
3162struct IrInstSrcCallArgs {
3163 IrInstSrc base;
29573164
2958 IrInstruction *options;
2959 IrInstruction *fn_ref;
2960 IrInstruction **args_ptr;
3165 IrInstSrc *options;
3166 IrInstSrc *fn_ref;
3167 IrInstSrc **args_ptr;
29613168 size_t args_len;
29623169 ResultLoc *result_loc;
29633170};
......@@ -2965,42 +3172,54 @@ struct IrInstructionCallSrcArgs {
29653172// This is a pass1 instruction, used by @call, when the args node
29663173// is not a literal.
29673174// `args` is expected to be either a struct or a tuple.
2968struct IrInstructionCallExtra {
2969 IrInstruction base;
3175struct IrInstSrcCallExtra {
3176 IrInstSrc base;
29703177
2971 IrInstruction *options;
2972 IrInstruction *fn_ref;
2973 IrInstruction *args;
3178 IrInstSrc *options;
3179 IrInstSrc *fn_ref;
3180 IrInstSrc *args;
29743181 ResultLoc *result_loc;
29753182};
29763183
2977struct IrInstructionCallGen {
2978 IrInstruction base;
3184struct IrInstGenCall {
3185 IrInstGen base;
29793186
2980 IrInstruction *fn_ref;
3187 IrInstGen *fn_ref;
29813188 ZigFn *fn_entry;
29823189 size_t arg_count;
2983 IrInstruction **args;
2984 IrInstruction *result_loc;
2985 IrInstruction *frame_result_loc;
2986 IrInstruction *new_stack;
3190 IrInstGen **args;
3191 IrInstGen *result_loc;
3192 IrInstGen *frame_result_loc;
3193 IrInstGen *new_stack;
29873194
29883195 CallModifier modifier;
29893196
29903197 bool is_async_call_builtin;
29913198};
29923199
2993struct IrInstructionConst {
2994 IrInstruction base;
3200struct IrInstSrcConst {
3201 IrInstSrc base;
3202
3203 ZigValue *value;
3204};
3205
3206struct IrInstGenConst {
3207 IrInstGen base;
3208};
3209
3210struct IrInstSrcReturn {
3211 IrInstSrc base;
3212
3213 IrInstSrc *operand;
29953214};
29963215
29973216// When an IrExecutable is not in a function, a return instruction means that
29983217// the expression returns with that value, even though a return statement from
29993218// an AST perspective is invalid.
3000struct IrInstructionReturn {
3001 IrInstruction base;
3219struct IrInstGenReturn {
3220 IrInstGen base;
30023221
3003 IrInstruction *operand;
3222 IrInstGen *operand;
30043223};
30053224
30063225enum CastOp {
......@@ -3015,89 +3234,92 @@ enum CastOp {
30153234};
30163235
30173236// TODO get rid of this instruction, replace with instructions for each op code
3018struct IrInstructionCast {
3019 IrInstruction base;
3237struct IrInstGenCast {
3238 IrInstGen base;
30203239
3021 IrInstruction *value;
3022 ZigType *dest_type;
3240 IrInstGen *value;
30233241 CastOp cast_op;
30243242};
30253243
3026struct IrInstructionResizeSlice {
3027 IrInstruction base;
3244struct IrInstGenResizeSlice {
3245 IrInstGen base;
30283246
3029 IrInstruction *operand;
3030 IrInstruction *result_loc;
3247 IrInstGen *operand;
3248 IrInstGen *result_loc;
30313249};
30323250
3033struct IrInstructionContainerInitList {
3034 IrInstruction base;
3251struct IrInstSrcContainerInitList {
3252 IrInstSrc base;
30353253
3036 IrInstruction *elem_type;
3254 IrInstSrc *elem_type;
30373255 size_t item_count;
3038 IrInstruction **elem_result_loc_list;
3039 IrInstruction *result_loc;
3256 IrInstSrc **elem_result_loc_list;
3257 IrInstSrc *result_loc;
30403258 AstNode *init_array_type_source_node;
30413259};
30423260
3043struct IrInstructionContainerInitFieldsField {
3261struct IrInstSrcContainerInitFieldsField {
30443262 Buf *name;
30453263 AstNode *source_node;
30463264 TypeStructField *type_struct_field;
3047 IrInstruction *result_loc;
3265 IrInstSrc *result_loc;
30483266};
30493267
3050struct IrInstructionContainerInitFields {
3051 IrInstruction base;
3268struct IrInstSrcContainerInitFields {
3269 IrInstSrc base;
30523270
30533271 size_t field_count;
3054 IrInstructionContainerInitFieldsField *fields;
3055 IrInstruction *result_loc;
3272 IrInstSrcContainerInitFieldsField *fields;
3273 IrInstSrc *result_loc;
3274};
3275
3276struct IrInstSrcUnreachable {
3277 IrInstSrc base;
30563278};
30573279
3058struct IrInstructionUnreachable {
3059 IrInstruction base;
3280struct IrInstGenUnreachable {
3281 IrInstGen base;
30603282};
30613283
3062struct IrInstructionTypeOf {
3063 IrInstruction base;
3284struct IrInstSrcTypeOf {
3285 IrInstSrc base;
30643286
3065 IrInstruction *value;
3287 IrInstSrc *value;
30663288};
30673289
3068struct IrInstructionSetCold {
3069 IrInstruction base;
3290struct IrInstSrcSetCold {
3291 IrInstSrc base;
30703292
3071 IrInstruction *is_cold;
3293 IrInstSrc *is_cold;
30723294};
30733295
3074struct IrInstructionSetRuntimeSafety {
3075 IrInstruction base;
3296struct IrInstSrcSetRuntimeSafety {
3297 IrInstSrc base;
30763298
3077 IrInstruction *safety_on;
3299 IrInstSrc *safety_on;
30783300};
30793301
3080struct IrInstructionSetFloatMode {
3081 IrInstruction base;
3302struct IrInstSrcSetFloatMode {
3303 IrInstSrc base;
30823304
3083 IrInstruction *scope_value;
3084 IrInstruction *mode_value;
3305 IrInstSrc *scope_value;
3306 IrInstSrc *mode_value;
30853307};
30863308
3087struct IrInstructionArrayType {
3088 IrInstruction base;
3309struct IrInstSrcArrayType {
3310 IrInstSrc base;
30893311
3090 IrInstruction *size;
3091 IrInstruction *sentinel;
3092 IrInstruction *child_type;
3312 IrInstSrc *size;
3313 IrInstSrc *sentinel;
3314 IrInstSrc *child_type;
30933315};
30943316
3095struct IrInstructionPtrType {
3096 IrInstruction base;
3317struct IrInstSrcPtrType {
3318 IrInstSrc base;
30973319
3098 IrInstruction *sentinel;
3099 IrInstruction *align_value;
3100 IrInstruction *child_type;
3320 IrInstSrc *sentinel;
3321 IrInstSrc *align_value;
3322 IrInstSrc *child_type;
31013323 uint32_t bit_offset_start;
31023324 uint32_t host_int_bytes;
31033325 PtrLen ptr_len;
......@@ -3106,375 +3328,459 @@ struct IrInstructionPtrType {
31063328 bool is_allow_zero;
31073329};
31083330
3109struct IrInstructionAnyFrameType {
3110 IrInstruction base;
3331struct IrInstSrcAnyFrameType {
3332 IrInstSrc base;
31113333
3112 IrInstruction *payload_type;
3334 IrInstSrc *payload_type;
31133335};
31143336
3115struct IrInstructionSliceType {
3116 IrInstruction base;
3337struct IrInstSrcSliceType {
3338 IrInstSrc base;
31173339
3118 IrInstruction *sentinel;
3119 IrInstruction *align_value;
3120 IrInstruction *child_type;
3340 IrInstSrc *sentinel;
3341 IrInstSrc *align_value;
3342 IrInstSrc *child_type;
31213343 bool is_const;
31223344 bool is_volatile;
31233345 bool is_allow_zero;
31243346};
31253347
3126struct IrInstructionAsmSrc {
3127 IrInstruction base;
3348struct IrInstSrcAsm {
3349 IrInstSrc base;
31283350
3129 IrInstruction *asm_template;
3130 IrInstruction **input_list;
3131 IrInstruction **output_types;
3351 IrInstSrc *asm_template;
3352 IrInstSrc **input_list;
3353 IrInstSrc **output_types;
31323354 ZigVar **output_vars;
31333355 size_t return_count;
31343356 bool has_side_effects;
31353357 bool is_global;
31363358};
31373359
3138struct IrInstructionAsmGen {
3139 IrInstruction base;
3360struct IrInstGenAsm {
3361 IrInstGen base;
31403362
31413363 Buf *asm_template;
31423364 AsmToken *token_list;
31433365 size_t token_list_len;
3144 IrInstruction **input_list;
3145 IrInstruction **output_types;
3366 IrInstGen **input_list;
3367 IrInstGen **output_types;
31463368 ZigVar **output_vars;
31473369 size_t return_count;
31483370 bool has_side_effects;
31493371};
31503372
3151struct IrInstructionSizeOf {
3152 IrInstruction base;
3373struct IrInstSrcSizeOf {
3374 IrInstSrc base;
31533375
3376 IrInstSrc *type_value;
31543377 bool bit_size;
3155 IrInstruction *type_value;
31563378};
31573379
31583380// returns true if nonnull, returns false if null
3159// this is so that `zeroes` sets maybe values to null
3160struct IrInstructionTestNonNull {
3161 IrInstruction base;
3381struct IrInstSrcTestNonNull {
3382 IrInstSrc base;
3383
3384 IrInstSrc *value;
3385};
3386
3387struct IrInstGenTestNonNull {
3388 IrInstGen base;
31623389
3163 IrInstruction *value;
3390 IrInstGen *value;
31643391};
31653392
31663393// Takes a pointer to an optional value, returns a pointer
31673394// to the payload.
3168struct IrInstructionOptionalUnwrapPtr {
3169 IrInstruction base;
3395struct IrInstSrcOptionalUnwrapPtr {
3396 IrInstSrc base;
3397
3398 IrInstSrc *base_ptr;
3399 bool safety_check_on;
3400 bool initializing;
3401};
31703402
3403struct IrInstGenOptionalUnwrapPtr {
3404 IrInstGen base;
3405
3406 IrInstGen *base_ptr;
31713407 bool safety_check_on;
31723408 bool initializing;
3173 IrInstruction *base_ptr;
31743409};
31753410
3176struct IrInstructionCtz {
3177 IrInstruction base;
3411struct IrInstSrcCtz {
3412 IrInstSrc base;
3413
3414 IrInstSrc *type;
3415 IrInstSrc *op;
3416};
3417
3418struct IrInstGenCtz {
3419 IrInstGen base;
3420
3421 IrInstGen *op;
3422};
3423
3424struct IrInstSrcClz {
3425 IrInstSrc base;
3426
3427 IrInstSrc *type;
3428 IrInstSrc *op;
3429};
3430
3431struct IrInstGenClz {
3432 IrInstGen base;
31783433
3179 IrInstruction *type;
3180 IrInstruction *op;
3434 IrInstGen *op;
31813435};
31823436
3183struct IrInstructionClz {
3184 IrInstruction base;
3437struct IrInstSrcPopCount {
3438 IrInstSrc base;
31853439
3186 IrInstruction *type;
3187 IrInstruction *op;
3440 IrInstSrc *type;
3441 IrInstSrc *op;
31883442};
31893443
3190struct IrInstructionPopCount {
3191 IrInstruction base;
3444struct IrInstGenPopCount {
3445 IrInstGen base;
31923446
3193 IrInstruction *type;
3194 IrInstruction *op;
3447 IrInstGen *op;
31953448};
31963449
3197struct IrInstructionUnionTag {
3198 IrInstruction base;
3450struct IrInstGenUnionTag {
3451 IrInstGen base;
31993452
3200 IrInstruction *value;
3453 IrInstGen *value;
32013454};
32023455
3203struct IrInstructionImport {
3204 IrInstruction base;
3456struct IrInstSrcImport {
3457 IrInstSrc base;
32053458
3206 IrInstruction *name;
3459 IrInstSrc *name;
32073460};
32083461
3209struct IrInstructionRef {
3210 IrInstruction base;
3462struct IrInstSrcRef {
3463 IrInstSrc base;
32113464
3212 IrInstruction *value;
3465 IrInstSrc *value;
32133466 bool is_const;
32143467 bool is_volatile;
32153468};
32163469
3217struct IrInstructionRefGen {
3218 IrInstruction base;
3470struct IrInstGenRef {
3471 IrInstGen base;
32193472
3220 IrInstruction *operand;
3221 IrInstruction *result_loc;
3473 IrInstGen *operand;
3474 IrInstGen *result_loc;
32223475};
32233476
3224struct IrInstructionCompileErr {
3225 IrInstruction base;
3477struct IrInstSrcCompileErr {
3478 IrInstSrc base;
32263479
3227 IrInstruction *msg;
3480 IrInstSrc *msg;
32283481};
32293482
3230struct IrInstructionCompileLog {
3231 IrInstruction base;
3483struct IrInstSrcCompileLog {
3484 IrInstSrc base;
32323485
32333486 size_t msg_count;
3234 IrInstruction **msg_list;
3487 IrInstSrc **msg_list;
32353488};
32363489
3237struct IrInstructionErrName {
3238 IrInstruction base;
3490struct IrInstSrcErrName {
3491 IrInstSrc base;
32393492
3240 IrInstruction *value;
3493 IrInstSrc *value;
32413494};
32423495
3243struct IrInstructionCImport {
3244 IrInstruction base;
3496struct IrInstGenErrName {
3497 IrInstGen base;
3498
3499 IrInstGen *value;
3500};
3501
3502struct IrInstSrcCImport {
3503 IrInstSrc base;
32453504};
32463505
3247struct IrInstructionCInclude {
3248 IrInstruction base;
3506struct IrInstSrcCInclude {
3507 IrInstSrc base;
32493508
3250 IrInstruction *name;
3509 IrInstSrc *name;
32513510};
32523511
3253struct IrInstructionCDefine {
3254 IrInstruction base;
3512struct IrInstSrcCDefine {
3513 IrInstSrc base;
32553514
3256 IrInstruction *name;
3257 IrInstruction *value;
3515 IrInstSrc *name;
3516 IrInstSrc *value;
32583517};
32593518
3260struct IrInstructionCUndef {
3261 IrInstruction base;
3519struct IrInstSrcCUndef {
3520 IrInstSrc base;
32623521
3263 IrInstruction *name;
3522 IrInstSrc *name;
32643523};
32653524
3266struct IrInstructionEmbedFile {
3267 IrInstruction base;
3525struct IrInstSrcEmbedFile {
3526 IrInstSrc base;
32683527
3269 IrInstruction *name;
3528 IrInstSrc *name;
32703529};
32713530
3272struct IrInstructionCmpxchgSrc {
3273 IrInstruction base;
3531struct IrInstSrcCmpxchg {
3532 IrInstSrc base;
32743533
32753534 bool is_weak;
3276 IrInstruction *type_value;
3277 IrInstruction *ptr;
3278 IrInstruction *cmp_value;
3279 IrInstruction *new_value;
3280 IrInstruction *success_order_value;
3281 IrInstruction *failure_order_value;
3535 IrInstSrc *type_value;
3536 IrInstSrc *ptr;
3537 IrInstSrc *cmp_value;
3538 IrInstSrc *new_value;
3539 IrInstSrc *success_order_value;
3540 IrInstSrc *failure_order_value;
32823541 ResultLoc *result_loc;
32833542};
32843543
3285struct IrInstructionCmpxchgGen {
3286 IrInstruction base;
3544struct IrInstGenCmpxchg {
3545 IrInstGen base;
32873546
3288 bool is_weak;
32893547 AtomicOrder success_order;
32903548 AtomicOrder failure_order;
3291 IrInstruction *ptr;
3292 IrInstruction *cmp_value;
3293 IrInstruction *new_value;
3294 IrInstruction *result_loc;
3549 IrInstGen *ptr;
3550 IrInstGen *cmp_value;
3551 IrInstGen *new_value;
3552 IrInstGen *result_loc;
3553 bool is_weak;
32953554};
32963555
3297struct IrInstructionFence {
3298 IrInstruction base;
3556struct IrInstSrcFence {
3557 IrInstSrc base;
3558
3559 IrInstSrc *order;
3560};
32993561
3300 IrInstruction *order_value;
3562struct IrInstGenFence {
3563 IrInstGen base;
33013564
3302 // if this instruction gets to runtime then we know these values:
33033565 AtomicOrder order;
33043566};
33053567
3306struct IrInstructionTruncate {
3307 IrInstruction base;
3568struct IrInstSrcTruncate {
3569 IrInstSrc base;
3570
3571 IrInstSrc *dest_type;
3572 IrInstSrc *target;
3573};
3574
3575struct IrInstGenTruncate {
3576 IrInstGen base;
33083577
3309 IrInstruction *dest_type;
3310 IrInstruction *target;
3578 IrInstGen *target;
33113579};
33123580
3313struct IrInstructionIntCast {
3314 IrInstruction base;
3581struct IrInstSrcIntCast {
3582 IrInstSrc base;
33153583
3316 IrInstruction *dest_type;
3317 IrInstruction *target;
3584 IrInstSrc *dest_type;
3585 IrInstSrc *target;
33183586};
33193587
3320struct IrInstructionFloatCast {
3321 IrInstruction base;
3588struct IrInstSrcFloatCast {
3589 IrInstSrc base;
33223590
3323 IrInstruction *dest_type;
3324 IrInstruction *target;
3591 IrInstSrc *dest_type;
3592 IrInstSrc *target;
33253593};
33263594
3327struct IrInstructionErrSetCast {
3328 IrInstruction base;
3595struct IrInstSrcErrSetCast {
3596 IrInstSrc base;
33293597
3330 IrInstruction *dest_type;
3331 IrInstruction *target;
3598 IrInstSrc *dest_type;
3599 IrInstSrc *target;
33323600};
33333601
3334struct IrInstructionToBytes {
3335 IrInstruction base;
3602struct IrInstSrcToBytes {
3603 IrInstSrc base;
33363604
3337 IrInstruction *target;
3605 IrInstSrc *target;
33383606 ResultLoc *result_loc;
33393607};
33403608
3341struct IrInstructionFromBytes {
3342 IrInstruction base;
3609struct IrInstSrcFromBytes {
3610 IrInstSrc base;
33433611
3344 IrInstruction *dest_child_type;
3345 IrInstruction *target;
3612 IrInstSrc *dest_child_type;
3613 IrInstSrc *target;
33463614 ResultLoc *result_loc;
33473615};
33483616
3349struct IrInstructionIntToFloat {
3350 IrInstruction base;
3617struct IrInstSrcIntToFloat {
3618 IrInstSrc base;
33513619
3352 IrInstruction *dest_type;
3353 IrInstruction *target;
3620 IrInstSrc *dest_type;
3621 IrInstSrc *target;
33543622};
33553623
3356struct IrInstructionFloatToInt {
3357 IrInstruction base;
3624struct IrInstSrcFloatToInt {
3625 IrInstSrc base;
33583626
3359 IrInstruction *dest_type;
3360 IrInstruction *target;
3627 IrInstSrc *dest_type;
3628 IrInstSrc *target;
33613629};
33623630
3363struct IrInstructionBoolToInt {
3364 IrInstruction base;
3631struct IrInstSrcBoolToInt {
3632 IrInstSrc base;
33653633
3366 IrInstruction *target;
3634 IrInstSrc *target;
33673635};
33683636
3369struct IrInstructionIntType {
3370 IrInstruction base;
3637struct IrInstSrcIntType {
3638 IrInstSrc base;
33713639
3372 IrInstruction *is_signed;
3373 IrInstruction *bit_count;
3640 IrInstSrc *is_signed;
3641 IrInstSrc *bit_count;
33743642};
33753643
3376struct IrInstructionVectorType {
3377 IrInstruction base;
3644struct IrInstSrcVectorType {
3645 IrInstSrc base;
33783646
3379 IrInstruction *len;
3380 IrInstruction *elem_type;
3647 IrInstSrc *len;
3648 IrInstSrc *elem_type;
33813649};
33823650
3383struct IrInstructionBoolNot {
3384 IrInstruction base;
3651struct IrInstSrcBoolNot {
3652 IrInstSrc base;
33853653
3386 IrInstruction *value;
3654 IrInstSrc *value;
33873655};
33883656
3389struct IrInstructionMemset {
3390 IrInstruction base;
3657struct IrInstGenBoolNot {
3658 IrInstGen base;
33913659
3392 IrInstruction *dest_ptr;
3393 IrInstruction *byte;
3394 IrInstruction *count;
3660 IrInstGen *value;
33953661};
33963662
3397struct IrInstructionMemcpy {
3398 IrInstruction base;
3663struct IrInstSrcMemset {
3664 IrInstSrc base;
33993665
3400 IrInstruction *dest_ptr;
3401 IrInstruction *src_ptr;
3402 IrInstruction *count;
3666 IrInstSrc *dest_ptr;
3667 IrInstSrc *byte;
3668 IrInstSrc *count;
34033669};
34043670
3405struct IrInstructionSliceSrc {
3406 IrInstruction base;
3671struct IrInstGenMemset {
3672 IrInstGen base;
34073673
3408 bool safety_check_on;
3409 IrInstruction *ptr;
3410 IrInstruction *start;
3411 IrInstruction *end;
3412 IrInstruction *sentinel;
3674 IrInstGen *dest_ptr;
3675 IrInstGen *byte;
3676 IrInstGen *count;
3677};
3678
3679struct IrInstSrcMemcpy {
3680 IrInstSrc base;
3681
3682 IrInstSrc *dest_ptr;
3683 IrInstSrc *src_ptr;
3684 IrInstSrc *count;
3685};
3686
3687struct IrInstGenMemcpy {
3688 IrInstGen base;
3689
3690 IrInstGen *dest_ptr;
3691 IrInstGen *src_ptr;
3692 IrInstGen *count;
3693};
3694
3695struct IrInstSrcSlice {
3696 IrInstSrc base;
3697
3698 IrInstSrc *ptr;
3699 IrInstSrc *start;
3700 IrInstSrc *end;
3701 IrInstSrc *sentinel;
34133702 ResultLoc *result_loc;
3703 bool safety_check_on;
34143704};
34153705
3416struct IrInstructionSliceGen {
3417 IrInstruction base;
3706struct IrInstGenSlice {
3707 IrInstGen base;
34183708
3709 IrInstGen *ptr;
3710 IrInstGen *start;
3711 IrInstGen *end;
3712 IrInstGen *result_loc;
34193713 bool safety_check_on;
3420 IrInstruction *ptr;
3421 IrInstruction *start;
3422 IrInstruction *end;
3423 IrInstruction *result_loc;
34243714};
34253715
3426struct IrInstructionMemberCount {
3427 IrInstruction base;
3716struct IrInstSrcMemberCount {
3717 IrInstSrc base;
3718
3719 IrInstSrc *container;
3720};
3721
3722struct IrInstSrcMemberType {
3723 IrInstSrc base;
34283724
3429 IrInstruction *container;
3725 IrInstSrc *container_type;
3726 IrInstSrc *member_index;
34303727};
34313728
3432struct IrInstructionMemberType {
3433 IrInstruction base;
3729struct IrInstSrcMemberName {
3730 IrInstSrc base;
3731
3732 IrInstSrc *container_type;
3733 IrInstSrc *member_index;
3734};
3735
3736struct IrInstSrcBreakpoint {
3737 IrInstSrc base;
3738};
34343739
3435 IrInstruction *container_type;
3436 IrInstruction *member_index;
3740struct IrInstGenBreakpoint {
3741 IrInstGen base;
34373742};
34383743
3439struct IrInstructionMemberName {
3440 IrInstruction base;
3744struct IrInstSrcReturnAddress {
3745 IrInstSrc base;
3746};
34413747
3442 IrInstruction *container_type;
3443 IrInstruction *member_index;
3748struct IrInstGenReturnAddress {
3749 IrInstGen base;
34443750};
34453751
3446struct IrInstructionBreakpoint {
3447 IrInstruction base;
3752struct IrInstSrcFrameAddress {
3753 IrInstSrc base;
34483754};
34493755
3450struct IrInstructionReturnAddress {
3451 IrInstruction base;
3756struct IrInstGenFrameAddress {
3757 IrInstGen base;
34523758};
34533759
3454struct IrInstructionFrameAddress {
3455 IrInstruction base;
3760struct IrInstSrcFrameHandle {
3761 IrInstSrc base;
34563762};
34573763
3458struct IrInstructionFrameHandle {
3459 IrInstruction base;
3764struct IrInstGenFrameHandle {
3765 IrInstGen base;
34603766};
34613767
3462struct IrInstructionFrameType {
3463 IrInstruction base;
3768struct IrInstSrcFrameType {
3769 IrInstSrc base;
34643770
3465 IrInstruction *fn;
3771 IrInstSrc *fn;
34663772};
34673773
3468struct IrInstructionFrameSizeSrc {
3469 IrInstruction base;
3774struct IrInstSrcFrameSize {
3775 IrInstSrc base;
34703776
3471 IrInstruction *fn;
3777 IrInstSrc *fn;
34723778};
34733779
3474struct IrInstructionFrameSizeGen {
3475 IrInstruction base;
3780struct IrInstGenFrameSize {
3781 IrInstGen base;
34763782
3477 IrInstruction *fn;
3783 IrInstGen *fn;
34783784};
34793785
34803786enum IrOverflowOp {
......@@ -3484,560 +3790,713 @@ enum IrOverflowOp {
34843790 IrOverflowOpShl,
34853791};
34863792
3487struct IrInstructionOverflowOp {
3488 IrInstruction base;
3793struct IrInstSrcOverflowOp {
3794 IrInstSrc base;
3795
3796 IrOverflowOp op;
3797 IrInstSrc *type_value;
3798 IrInstSrc *op1;
3799 IrInstSrc *op2;
3800 IrInstSrc *result_ptr;
3801};
3802
3803struct IrInstGenOverflowOp {
3804 IrInstGen base;
34893805
34903806 IrOverflowOp op;
3491 IrInstruction *type_value;
3492 IrInstruction *op1;
3493 IrInstruction *op2;
3494 IrInstruction *result_ptr;
3807 IrInstGen *op1;
3808 IrInstGen *op2;
3809 IrInstGen *result_ptr;
34953810
3811 // TODO can this field be removed?
34963812 ZigType *result_ptr_type;
34973813};
34983814
3499struct IrInstructionMulAdd {
3500 IrInstruction base;
3815struct IrInstSrcMulAdd {
3816 IrInstSrc base;
3817
3818 IrInstSrc *type_value;
3819 IrInstSrc *op1;
3820 IrInstSrc *op2;
3821 IrInstSrc *op3;
3822};
3823
3824struct IrInstGenMulAdd {
3825 IrInstGen base;
35013826
3502 IrInstruction *type_value;
3503 IrInstruction *op1;
3504 IrInstruction *op2;
3505 IrInstruction *op3;
3827 IrInstGen *op1;
3828 IrInstGen *op2;
3829 IrInstGen *op3;
35063830};
35073831
3508struct IrInstructionAlignOf {
3509 IrInstruction base;
3832struct IrInstSrcAlignOf {
3833 IrInstSrc base;
35103834
3511 IrInstruction *type_value;
3835 IrInstSrc *type_value;
35123836};
35133837
35143838// returns true if error, returns false if not error
3515struct IrInstructionTestErrSrc {
3516 IrInstruction base;
3839struct IrInstSrcTestErr {
3840 IrInstSrc base;
35173841
3842 IrInstSrc *base_ptr;
35183843 bool resolve_err_set;
35193844 bool base_ptr_is_payload;
3520 IrInstruction *base_ptr;
35213845};
35223846
3523struct IrInstructionTestErrGen {
3524 IrInstruction base;
3847struct IrInstGenTestErr {
3848 IrInstGen base;
35253849
3526 IrInstruction *err_union;
3850 IrInstGen *err_union;
35273851};
35283852
35293853// Takes an error union pointer, returns a pointer to the error code.
3530struct IrInstructionUnwrapErrCode {
3531 IrInstruction base;
3854struct IrInstSrcUnwrapErrCode {
3855 IrInstSrc base;
35323856
3857 IrInstSrc *err_union_ptr;
35333858 bool initializing;
3534 IrInstruction *err_union_ptr;
35353859};
35363860
3537struct IrInstructionUnwrapErrPayload {
3538 IrInstruction base;
3861struct IrInstGenUnwrapErrCode {
3862 IrInstGen base;
35393863
3864 IrInstGen *err_union_ptr;
3865 bool initializing;
3866};
3867
3868struct IrInstSrcUnwrapErrPayload {
3869 IrInstSrc base;
3870
3871 IrInstSrc *value;
3872 bool safety_check_on;
3873 bool initializing;
3874};
3875
3876struct IrInstGenUnwrapErrPayload {
3877 IrInstGen base;
3878
3879 IrInstGen *value;
35403880 bool safety_check_on;
35413881 bool initializing;
3542 IrInstruction *value;
35433882};
35443883
3545struct IrInstructionOptionalWrap {
3546 IrInstruction base;
3884struct IrInstGenOptionalWrap {
3885 IrInstGen base;
35473886
3548 IrInstruction *operand;
3549 IrInstruction *result_loc;
3887 IrInstGen *operand;
3888 IrInstGen *result_loc;
35503889};
35513890
3552struct IrInstructionErrWrapPayload {
3553 IrInstruction base;
3891struct IrInstGenErrWrapPayload {
3892 IrInstGen base;
35543893
3555 IrInstruction *operand;
3556 IrInstruction *result_loc;
3894 IrInstGen *operand;
3895 IrInstGen *result_loc;
35573896};
35583897
3559struct IrInstructionErrWrapCode {
3560 IrInstruction base;
3898struct IrInstGenErrWrapCode {
3899 IrInstGen base;
35613900
3562 IrInstruction *operand;
3563 IrInstruction *result_loc;
3901 IrInstGen *operand;
3902 IrInstGen *result_loc;
35643903};
35653904
3566struct IrInstructionFnProto {
3567 IrInstruction base;
3905struct IrInstSrcFnProto {
3906 IrInstSrc base;
35683907
3569 IrInstruction **param_types;
3570 IrInstruction *align_value;
3571 IrInstruction *callconv_value;
3572 IrInstruction *return_type;
3908 IrInstSrc **param_types;
3909 IrInstSrc *align_value;
3910 IrInstSrc *callconv_value;
3911 IrInstSrc *return_type;
35733912 bool is_var_args;
35743913};
35753914
35763915// true if the target value is compile time known, false otherwise
3577struct IrInstructionTestComptime {
3578 IrInstruction base;
3916struct IrInstSrcTestComptime {
3917 IrInstSrc base;
35793918
3580 IrInstruction *value;
3919 IrInstSrc *value;
35813920};
35823921
3583struct IrInstructionPtrCastSrc {
3584 IrInstruction base;
3922struct IrInstSrcPtrCast {
3923 IrInstSrc base;
35853924
3586 IrInstruction *dest_type;
3587 IrInstruction *ptr;
3925 IrInstSrc *dest_type;
3926 IrInstSrc *ptr;
35883927 bool safety_check_on;
35893928};
35903929
3591struct IrInstructionPtrCastGen {
3592 IrInstruction base;
3930struct IrInstGenPtrCast {
3931 IrInstGen base;
35933932
3594 IrInstruction *ptr;
3933 IrInstGen *ptr;
35953934 bool safety_check_on;
35963935};
35973936
3598struct IrInstructionImplicitCast {
3599 IrInstruction base;
3937struct IrInstSrcImplicitCast {
3938 IrInstSrc base;
36003939
3601 IrInstruction *operand;
3940 IrInstSrc *operand;
36023941 ResultLocCast *result_loc_cast;
36033942};
36043943
3605struct IrInstructionBitCastSrc {
3606 IrInstruction base;
3944struct IrInstSrcBitCast {
3945 IrInstSrc base;
36073946
3608 IrInstruction *operand;
3947 IrInstSrc *operand;
36093948 ResultLocBitCast *result_loc_bit_cast;
36103949};
36113950
3612struct IrInstructionBitCastGen {
3613 IrInstruction base;
3951struct IrInstGenBitCast {
3952 IrInstGen base;
3953
3954 IrInstGen *operand;
3955};
3956
3957struct IrInstGenWidenOrShorten {
3958 IrInstGen base;
3959
3960 IrInstGen *target;
3961};
3962
3963struct IrInstSrcPtrToInt {
3964 IrInstSrc base;
3965
3966 IrInstSrc *target;
3967};
3968
3969struct IrInstGenPtrToInt {
3970 IrInstGen base;
3971
3972 IrInstGen *target;
3973};
3974
3975struct IrInstSrcIntToPtr {
3976 IrInstSrc base;
3977
3978 IrInstSrc *dest_type;
3979 IrInstSrc *target;
3980};
3981
3982struct IrInstGenIntToPtr {
3983 IrInstGen base;
36143984
3615 IrInstruction *operand;
3985 IrInstGen *target;
36163986};
36173987
3618struct IrInstructionWidenOrShorten {
3619 IrInstruction base;
3988struct IrInstSrcIntToEnum {
3989 IrInstSrc base;
36203990
3621 IrInstruction *target;
3991 IrInstSrc *dest_type;
3992 IrInstSrc *target;
36223993};
36233994
3624struct IrInstructionPtrToInt {
3625 IrInstruction base;
3995struct IrInstGenIntToEnum {
3996 IrInstGen base;
36263997
3627 IrInstruction *target;
3998 IrInstGen *target;
36283999};
36294000
3630struct IrInstructionIntToPtr {
3631 IrInstruction base;
4001struct IrInstSrcEnumToInt {
4002 IrInstSrc base;
36324003
3633 IrInstruction *dest_type;
3634 IrInstruction *target;
4004 IrInstSrc *target;
36354005};
36364006
3637struct IrInstructionIntToEnum {
3638 IrInstruction base;
4007struct IrInstSrcIntToErr {
4008 IrInstSrc base;
36394009
3640 IrInstruction *dest_type;
3641 IrInstruction *target;
4010 IrInstSrc *target;
36424011};
36434012
3644struct IrInstructionEnumToInt {
3645 IrInstruction base;
4013struct IrInstGenIntToErr {
4014 IrInstGen base;
36464015
3647 IrInstruction *target;
4016 IrInstGen *target;
36484017};
36494018
3650struct IrInstructionIntToErr {
3651 IrInstruction base;
4019struct IrInstSrcErrToInt {
4020 IrInstSrc base;
36524021
3653 IrInstruction *target;
4022 IrInstSrc *target;
36544023};
36554024
3656struct IrInstructionErrToInt {
3657 IrInstruction base;
4025struct IrInstGenErrToInt {
4026 IrInstGen base;
36584027
3659 IrInstruction *target;
4028 IrInstGen *target;
36604029};
36614030
3662struct IrInstructionCheckSwitchProngsRange {
3663 IrInstruction *start;
3664 IrInstruction *end;
4031struct IrInstSrcCheckSwitchProngsRange {
4032 IrInstSrc *start;
4033 IrInstSrc *end;
36654034};
36664035
3667struct IrInstructionCheckSwitchProngs {
3668 IrInstruction base;
4036struct IrInstSrcCheckSwitchProngs {
4037 IrInstSrc base;
36694038
3670 IrInstruction *target_value;
3671 IrInstructionCheckSwitchProngsRange *ranges;
4039 IrInstSrc *target_value;
4040 IrInstSrcCheckSwitchProngsRange *ranges;
36724041 size_t range_count;
36734042 bool have_else_prong;
36744043 bool have_underscore_prong;
36754044};
36764045
3677struct IrInstructionCheckStatementIsVoid {
3678 IrInstruction base;
4046struct IrInstSrcCheckStatementIsVoid {
4047 IrInstSrc base;
36794048
3680 IrInstruction *statement_value;
4049 IrInstSrc *statement_value;
36814050};
36824051
3683struct IrInstructionTypeName {
3684 IrInstruction base;
4052struct IrInstSrcTypeName {
4053 IrInstSrc base;
36854054
3686 IrInstruction *type_value;
4055 IrInstSrc *type_value;
36874056};
36884057
3689struct IrInstructionDeclRef {
3690 IrInstruction base;
4058struct IrInstSrcDeclRef {
4059 IrInstSrc base;
36914060
36924061 LVal lval;
36934062 Tld *tld;
36944063};
36954064
3696struct IrInstructionPanic {
3697 IrInstruction base;
4065struct IrInstSrcPanic {
4066 IrInstSrc base;
4067
4068 IrInstSrc *msg;
4069};
4070
4071struct IrInstGenPanic {
4072 IrInstGen base;
4073
4074 IrInstGen *msg;
4075};
4076
4077struct IrInstSrcTagName {
4078 IrInstSrc base;
4079
4080 IrInstSrc *target;
4081};
4082
4083struct IrInstGenTagName {
4084 IrInstGen base;
36984085
3699 IrInstruction *msg;
4086 IrInstGen *target;
37004087};
37014088
3702struct IrInstructionTagName {
3703 IrInstruction base;
4089struct IrInstSrcTagType {
4090 IrInstSrc base;
37044091
3705 IrInstruction *target;
4092 IrInstSrc *target;
37064093};
37074094
3708struct IrInstructionTagType {
3709 IrInstruction base;
4095struct IrInstSrcFieldParentPtr {
4096 IrInstSrc base;
37104097
3711 IrInstruction *target;
4098 IrInstSrc *type_value;
4099 IrInstSrc *field_name;
4100 IrInstSrc *field_ptr;
37124101};
37134102
3714struct IrInstructionFieldParentPtr {
3715 IrInstruction base;
4103struct IrInstGenFieldParentPtr {
4104 IrInstGen base;
37164105
3717 IrInstruction *type_value;
3718 IrInstruction *field_name;
3719 IrInstruction *field_ptr;
4106 IrInstGen *field_ptr;
37204107 TypeStructField *field;
37214108};
37224109
3723struct IrInstructionByteOffsetOf {
3724 IrInstruction base;
4110struct IrInstSrcByteOffsetOf {
4111 IrInstSrc base;
4112
4113 IrInstSrc *type_value;
4114 IrInstSrc *field_name;
4115};
4116
4117struct IrInstSrcBitOffsetOf {
4118 IrInstSrc base;
37254119
3726 IrInstruction *type_value;
3727 IrInstruction *field_name;
4120 IrInstSrc *type_value;
4121 IrInstSrc *field_name;
37284122};
37294123
3730struct IrInstructionBitOffsetOf {
3731 IrInstruction base;
4124struct IrInstSrcTypeInfo {
4125 IrInstSrc base;
37324126
3733 IrInstruction *type_value;
3734 IrInstruction *field_name;
4127 IrInstSrc *type_value;
37354128};
37364129
3737struct IrInstructionTypeInfo {
3738 IrInstruction base;
4130struct IrInstSrcType {
4131 IrInstSrc base;
37394132
3740 IrInstruction *type_value;
4133 IrInstSrc *type_info;
37414134};
37424135
3743struct IrInstructionType {
3744 IrInstruction base;
4136struct IrInstSrcHasField {
4137 IrInstSrc base;
37454138
3746 IrInstruction *type_info;
4139 IrInstSrc *container_type;
4140 IrInstSrc *field_name;
37474141};
37484142
3749struct IrInstructionHasField {
3750 IrInstruction base;
4143struct IrInstSrcTypeId {
4144 IrInstSrc base;
37514145
3752 IrInstruction *container_type;
3753 IrInstruction *field_name;
4146 IrInstSrc *type_value;
37544147};
37554148
3756struct IrInstructionTypeId {
3757 IrInstruction base;
4149struct IrInstSrcSetEvalBranchQuota {
4150 IrInstSrc base;
37584151
3759 IrInstruction *type_value;
4152 IrInstSrc *new_quota;
37604153};
37614154
3762struct IrInstructionSetEvalBranchQuota {
3763 IrInstruction base;
4155struct IrInstSrcAlignCast {
4156 IrInstSrc base;
37644157
3765 IrInstruction *new_quota;
4158 IrInstSrc *align_bytes;
4159 IrInstSrc *target;
37664160};
37674161
3768struct IrInstructionAlignCast {
3769 IrInstruction base;
4162struct IrInstGenAlignCast {
4163 IrInstGen base;
37704164
3771 IrInstruction *align_bytes;
3772 IrInstruction *target;
4165 IrInstGen *target;
37734166};
37744167
3775struct IrInstructionOpaqueType {
3776 IrInstruction base;
4168struct IrInstSrcOpaqueType {
4169 IrInstSrc base;
37774170};
37784171
3779struct IrInstructionSetAlignStack {
3780 IrInstruction base;
4172struct IrInstSrcSetAlignStack {
4173 IrInstSrc base;
37814174
3782 IrInstruction *align_bytes;
4175 IrInstSrc *align_bytes;
37834176};
37844177
3785struct IrInstructionArgType {
3786 IrInstruction base;
4178struct IrInstSrcArgType {
4179 IrInstSrc base;
37874180
3788 IrInstruction *fn_type;
3789 IrInstruction *arg_index;
4181 IrInstSrc *fn_type;
4182 IrInstSrc *arg_index;
37904183 bool allow_var;
37914184};
37924185
3793struct IrInstructionExport {
3794 IrInstruction base;
4186struct IrInstSrcExport {
4187 IrInstSrc base;
4188
4189 IrInstSrc *target;
4190 IrInstSrc *options;
4191};
4192
4193enum IrInstErrorReturnTraceOptional {
4194 IrInstErrorReturnTraceNull,
4195 IrInstErrorReturnTraceNonNull,
4196};
4197
4198struct IrInstSrcErrorReturnTrace {
4199 IrInstSrc base;
37954200
3796 IrInstruction *target;
3797 IrInstruction *options;
4201 IrInstErrorReturnTraceOptional optional;
37984202};
37994203
3800struct IrInstructionErrorReturnTrace {
3801 IrInstruction base;
4204struct IrInstGenErrorReturnTrace {
4205 IrInstGen base;
38024206
3803 enum Optional {
3804 Null,
3805 NonNull,
3806 } optional;
4207 IrInstErrorReturnTraceOptional optional;
38074208};
38084209
3809struct IrInstructionErrorUnion {
3810 IrInstruction base;
4210struct IrInstSrcErrorUnion {
4211 IrInstSrc base;
38114212
3812 IrInstruction *err_set;
3813 IrInstruction *payload;
4213 IrInstSrc *err_set;
4214 IrInstSrc *payload;
38144215 Buf *type_name;
38154216};
38164217
3817struct IrInstructionAtomicRmw {
3818 IrInstruction base;
4218struct IrInstSrcAtomicRmw {
4219 IrInstSrc base;
4220
4221 IrInstSrc *operand_type;
4222 IrInstSrc *ptr;
4223 IrInstSrc *op;
4224 IrInstSrc *operand;
4225 IrInstSrc *ordering;
4226};
4227
4228struct IrInstGenAtomicRmw {
4229 IrInstGen base;
4230
4231 IrInstGen *ptr;
4232 IrInstGen *operand;
4233 AtomicRmwOp op;
4234 AtomicOrder ordering;
4235};
4236
4237struct IrInstSrcAtomicLoad {
4238 IrInstSrc base;
4239
4240 IrInstSrc *operand_type;
4241 IrInstSrc *ptr;
4242 IrInstSrc *ordering;
4243};
4244
4245struct IrInstGenAtomicLoad {
4246 IrInstGen base;
38194247
3820 IrInstruction *operand_type;
3821 IrInstruction *ptr;
3822 IrInstruction *op;
3823 AtomicRmwOp resolved_op;
3824 IrInstruction *operand;
3825 IrInstruction *ordering;
3826 AtomicOrder resolved_ordering;
4248 IrInstGen *ptr;
4249 AtomicOrder ordering;
38274250};
38284251
3829struct IrInstructionAtomicLoad {
3830 IrInstruction base;
4252struct IrInstSrcAtomicStore {
4253 IrInstSrc base;
38314254
3832 IrInstruction *operand_type;
3833 IrInstruction *ptr;
3834 IrInstruction *ordering;
3835 AtomicOrder resolved_ordering;
4255 IrInstSrc *operand_type;
4256 IrInstSrc *ptr;
4257 IrInstSrc *value;
4258 IrInstSrc *ordering;
38364259};
38374260
3838struct IrInstructionAtomicStore {
3839 IrInstruction base;
4261struct IrInstGenAtomicStore {
4262 IrInstGen base;
4263
4264 IrInstGen *ptr;
4265 IrInstGen *value;
4266 AtomicOrder ordering;
4267};
38404268
3841 IrInstruction *operand_type;
3842 IrInstruction *ptr;
3843 IrInstruction *value;
3844 IrInstruction *ordering;
3845 AtomicOrder resolved_ordering;
4269struct IrInstSrcSaveErrRetAddr {
4270 IrInstSrc base;
38464271};
38474272
3848struct IrInstructionSaveErrRetAddr {
3849 IrInstruction base;
4273struct IrInstGenSaveErrRetAddr {
4274 IrInstGen base;
38504275};
38514276
3852struct IrInstructionAddImplicitReturnType {
3853 IrInstruction base;
4277struct IrInstSrcAddImplicitReturnType {
4278 IrInstSrc base;
38544279
3855 IrInstruction *value;
4280 IrInstSrc *value;
38564281 ResultLocReturn *result_loc_ret;
38574282};
38584283
3859// For float ops which take a single argument
3860struct IrInstructionFloatOp {
3861 IrInstruction base;
4284// For float ops that take a single argument
4285struct IrInstSrcFloatOp {
4286 IrInstSrc base;
4287
4288 IrInstSrc *operand;
4289 BuiltinFnId fn_id;
4290};
4291
4292struct IrInstGenFloatOp {
4293 IrInstGen base;
38624294
4295 IrInstGen *operand;
38634296 BuiltinFnId fn_id;
3864 IrInstruction *operand;
38654297};
38664298
3867struct IrInstructionCheckRuntimeScope {
3868 IrInstruction base;
4299struct IrInstSrcCheckRuntimeScope {
4300 IrInstSrc base;
4301
4302 IrInstSrc *scope_is_comptime;
4303 IrInstSrc *is_comptime;
4304};
4305
4306struct IrInstSrcBswap {
4307 IrInstSrc base;
4308
4309 IrInstSrc *type;
4310 IrInstSrc *op;
4311};
4312
4313struct IrInstGenBswap {
4314 IrInstGen base;
4315
4316 IrInstGen *op;
4317};
4318
4319struct IrInstSrcBitReverse {
4320 IrInstSrc base;
38694321
3870 IrInstruction *scope_is_comptime;
3871 IrInstruction *is_comptime;
4322 IrInstSrc *type;
4323 IrInstSrc *op;
38724324};
38734325
3874struct IrInstructionBswap {
3875 IrInstruction base;
4326struct IrInstGenBitReverse {
4327 IrInstGen base;
38764328
3877 IrInstruction *type;
3878 IrInstruction *op;
4329 IrInstGen *op;
38794330};
38804331
3881struct IrInstructionBitReverse {
3882 IrInstruction base;
4332struct IrInstGenArrayToVector {
4333 IrInstGen base;
38834334
3884 IrInstruction *type;
3885 IrInstruction *op;
4335 IrInstGen *array;
38864336};
38874337
3888struct IrInstructionArrayToVector {
3889 IrInstruction base;
4338struct IrInstGenVectorToArray {
4339 IrInstGen base;
38904340
3891 IrInstruction *array;
4341 IrInstGen *vector;
4342 IrInstGen *result_loc;
38924343};
38934344
3894struct IrInstructionVectorToArray {
3895 IrInstruction base;
4345struct IrInstSrcShuffleVector {
4346 IrInstSrc base;
38964347
3897 IrInstruction *vector;
3898 IrInstruction *result_loc;
4348 IrInstSrc *scalar_type;
4349 IrInstSrc *a;
4350 IrInstSrc *b;
4351 IrInstSrc *mask; // This is in zig-format, not llvm format
38994352};
39004353
3901struct IrInstructionShuffleVector {
3902 IrInstruction base;
4354struct IrInstGenShuffleVector {
4355 IrInstGen base;
39034356
3904 IrInstruction *scalar_type;
3905 IrInstruction *a;
3906 IrInstruction *b;
3907 IrInstruction *mask; // This is in zig-format, not llvm format
4357 IrInstGen *a;
4358 IrInstGen *b;
4359 IrInstGen *mask; // This is in zig-format, not llvm format
39084360};
39094361
3910struct IrInstructionSplatSrc {
3911 IrInstruction base;
4362struct IrInstSrcSplat {
4363 IrInstSrc base;
39124364
3913 IrInstruction *len;
3914 IrInstruction *scalar;
4365 IrInstSrc *len;
4366 IrInstSrc *scalar;
39154367};
39164368
3917struct IrInstructionSplatGen {
3918 IrInstruction base;
4369struct IrInstGenSplat {
4370 IrInstGen base;
39194371
3920 IrInstruction *scalar;
4372 IrInstGen *scalar;
39214373};
39224374
3923struct IrInstructionAssertZero {
3924 IrInstruction base;
4375struct IrInstGenAssertZero {
4376 IrInstGen base;
39254377
3926 IrInstruction *target;
4378 IrInstGen *target;
39274379};
39284380
3929struct IrInstructionAssertNonNull {
3930 IrInstruction base;
4381struct IrInstGenAssertNonNull {
4382 IrInstGen base;
39314383
3932 IrInstruction *target;
4384 IrInstGen *target;
39334385};
39344386
3935struct IrInstructionUnionInitNamedField {
3936 IrInstruction base;
4387struct IrInstSrcUnionInitNamedField {
4388 IrInstSrc base;
39374389
3938 IrInstruction *union_type;
3939 IrInstruction *field_name;
3940 IrInstruction *field_result_loc;
3941 IrInstruction *result_loc;
4390 IrInstSrc *union_type;
4391 IrInstSrc *field_name;
4392 IrInstSrc *field_result_loc;
4393 IrInstSrc *result_loc;
39424394};
39434395
3944struct IrInstructionHasDecl {
3945 IrInstruction base;
4396struct IrInstSrcHasDecl {
4397 IrInstSrc base;
39464398
3947 IrInstruction *container;
3948 IrInstruction *name;
4399 IrInstSrc *container;
4400 IrInstSrc *name;
39494401};
39504402
3951struct IrInstructionUndeclaredIdent {
3952 IrInstruction base;
4403struct IrInstSrcUndeclaredIdent {
4404 IrInstSrc base;
39534405
39544406 Buf *name;
39554407};
39564408
3957struct IrInstructionAllocaSrc {
3958 IrInstruction base;
4409struct IrInstSrcAlloca {
4410 IrInstSrc base;
39594411
3960 IrInstruction *align;
3961 IrInstruction *is_comptime;
4412 IrInstSrc *align;
4413 IrInstSrc *is_comptime;
39624414 const char *name_hint;
39634415};
39644416
3965struct IrInstructionAllocaGen {
3966 IrInstruction base;
4417struct IrInstGenAlloca {
4418 IrInstGen base;
39674419
39684420 uint32_t align;
39694421 const char *name_hint;
39704422 size_t field_index;
39714423};
39724424
3973struct IrInstructionEndExpr {
3974 IrInstruction base;
4425struct IrInstSrcEndExpr {
4426 IrInstSrc base;
39754427
3976 IrInstruction *value;
4428 IrInstSrc *value;
39774429 ResultLoc *result_loc;
39784430};
39794431
39804432// This one is for writing through the result pointer.
3981struct IrInstructionResolveResult {
3982 IrInstruction base;
4433struct IrInstSrcResolveResult {
4434 IrInstSrc base;
39834435
39844436 ResultLoc *result_loc;
3985 IrInstruction *ty;
4437 IrInstSrc *ty;
39864438};
39874439
3988// This one is when you want to read the value of the result.
3989// You have to give the value in case it is comptime.
3990struct IrInstructionResultPtr {
3991 IrInstruction base;
4440struct IrInstSrcResetResult {
4441 IrInstSrc base;
39924442
39934443 ResultLoc *result_loc;
3994 IrInstruction *result;
39954444};
39964445
3997struct IrInstructionResetResult {
3998 IrInstruction base;
4446struct IrInstGenPtrOfArrayToSlice {
4447 IrInstGen base;
39994448
4000 ResultLoc *result_loc;
4449 IrInstGen *operand;
4450 IrInstGen *result_loc;
40014451};
40024452
4003struct IrInstructionPtrOfArrayToSlice {
4004 IrInstruction base;
4005
4006 IrInstruction *operand;
4007 IrInstruction *result_loc;
4453struct IrInstSrcSuspendBegin {
4454 IrInstSrc base;
40084455};
40094456
4010struct IrInstructionSuspendBegin {
4011 IrInstruction base;
4457struct IrInstGenSuspendBegin {
4458 IrInstGen base;
40124459
40134460 LLVMBasicBlockRef resume_bb;
40144461};
40154462
4016struct IrInstructionSuspendFinish {
4017 IrInstruction base;
4463struct IrInstSrcSuspendFinish {
4464 IrInstSrc base;
4465
4466 IrInstSrcSuspendBegin *begin;
4467};
4468
4469struct IrInstGenSuspendFinish {
4470 IrInstGen base;
40184471
4019 IrInstructionSuspendBegin *begin;
4472 IrInstGenSuspendBegin *begin;
40204473};
40214474
4022struct IrInstructionAwaitSrc {
4023 IrInstruction base;
4475struct IrInstSrcAwait {
4476 IrInstSrc base;
40244477
4025 IrInstruction *frame;
4478 IrInstSrc *frame;
40264479 ResultLoc *result_loc;
40274480};
40284481
4029struct IrInstructionAwaitGen {
4030 IrInstruction base;
4482struct IrInstGenAwait {
4483 IrInstGen base;
40314484
4032 IrInstruction *frame;
4033 IrInstruction *result_loc;
4485 IrInstGen *frame;
4486 IrInstGen *result_loc;
40344487 ZigFn *target_fn;
40354488};
40364489
4037struct IrInstructionResume {
4038 IrInstruction base;
4490struct IrInstSrcResume {
4491 IrInstSrc base;
4492
4493 IrInstSrc *frame;
4494};
4495
4496struct IrInstGenResume {
4497 IrInstGen base;
40394498
4040 IrInstruction *frame;
4499 IrInstGen *frame;
40414500};
40424501
40434502enum SpillId {
......@@ -4045,24 +4504,37 @@ enum SpillId {
40454504 SpillIdRetErrCode,
40464505};
40474506
4048struct IrInstructionSpillBegin {
4049 IrInstruction base;
4507struct IrInstSrcSpillBegin {
4508 IrInstSrc base;
4509
4510 IrInstSrc *operand;
4511 SpillId spill_id;
4512};
4513
4514struct IrInstGenSpillBegin {
4515 IrInstGen base;
40504516
40514517 SpillId spill_id;
4052 IrInstruction *operand;
4518 IrInstGen *operand;
4519};
4520
4521struct IrInstSrcSpillEnd {
4522 IrInstSrc base;
4523
4524 IrInstSrcSpillBegin *begin;
40534525};
40544526
4055struct IrInstructionSpillEnd {
4056 IrInstruction base;
4527struct IrInstGenSpillEnd {
4528 IrInstGen base;
40574529
4058 IrInstructionSpillBegin *begin;
4530 IrInstGenSpillBegin *begin;
40594531};
40604532
4061struct IrInstructionVectorExtractElem {
4062 IrInstruction base;
4533struct IrInstGenVectorExtractElem {
4534 IrInstGen base;
40634535
4064 IrInstruction *vector;
4065 IrInstruction *index;
4536 IrInstGen *vector;
4537 IrInstGen *index;
40664538};
40674539
40684540enum ResultLocId {
......@@ -4083,9 +4555,9 @@ struct ResultLoc {
40834555 ResultLocId id;
40844556 bool written;
40854557 bool allow_write_through_const;
4086 IrInstruction *resolved_loc; // result ptr
4087 IrInstruction *source_instruction;
4088 IrInstruction *gen_instruction; // value to store to the result loc
4558 IrInstGen *resolved_loc; // result ptr
4559 IrInstSrc *source_instruction;
4560 IrInstGen *gen_instruction; // value to store to the result loc
40894561 ZigType *implicit_elem_type;
40904562};
40914563
......@@ -4115,18 +4587,18 @@ struct ResultLocPeerParent {
41154587
41164588 bool skipped;
41174589 bool done_resuming;
4118 IrBasicBlock *end_bb;
4590 IrBasicBlockSrc *end_bb;
41194591 ResultLoc *parent;
41204592 ZigList<ResultLocPeer *> peers;
41214593 ZigType *resolved_type;
4122 IrInstruction *is_comptime;
4594 IrInstSrc *is_comptime;
41234595};
41244596
41254597struct ResultLocPeer {
41264598 ResultLoc base;
41274599
41284600 ResultLocPeerParent *parent;
4129 IrBasicBlock *next_bb;
4601 IrBasicBlockSrc *next_bb;
41304602 IrSuspendPosition suspend_pos;
41314603};
41324604
......@@ -4197,7 +4669,7 @@ struct FnWalkAttrs {
41974669struct FnWalkCall {
41984670 ZigList<LLVMValueRef> *gen_param_values;
41994671 ZigList<ZigType *> *gen_param_types;
4200 IrInstructionCallGen *inst;
4672 IrInstGenCall *inst;
42014673 bool is_var_args;
42024674};
42034675
src/analyze.cpp+94-61
......@@ -199,7 +199,7 @@ ScopeLoop *create_loop_scope(CodeGen *g, AstNode *node, Scope *parent) {
199199 return scope;
200200}
201201
202Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstruction *is_comptime) {
202Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstSrc *is_comptime) {
203203 ScopeRuntime *scope = allocate<ScopeRuntime>(1);
204204 scope->is_comptime = is_comptime;
205205 init_scope(g, &scope->base, ScopeIdRuntime, node, parent);
......@@ -3350,7 +3350,7 @@ static void get_fully_qualified_decl_name(CodeGen *g, Buf *buf, Tld *tld, bool i
33503350
33513351ZigFn *create_fn_raw(CodeGen *g, FnInline inline_value) {
33523352 ZigFn *fn_entry = allocate<ZigFn>(1, "ZigFn");
3353 fn_entry->ir_executable = allocate<IrExecutable>(1, "IrExecutablePass1");
3353 fn_entry->ir_executable = allocate<IrExecutableSrc>(1, "IrExecutableSrc");
33543354
33553355 fn_entry->prealloc_backward_branch_quota = default_backward_branch_quota;
33563356
......@@ -4097,7 +4097,7 @@ static void preview_use_decl(CodeGen *g, TldUsingNamespace *using_namespace, Sco
40974097 if (type_is_invalid(result->type)) {
40984098 dest_decls_scope->any_imports_failed = true;
40994099 using_namespace->base.resolution = TldResolutionInvalid;
4100 using_namespace->using_namespace_value = g->invalid_instruction->value;
4100 using_namespace->using_namespace_value = g->invalid_inst_gen->value;
41014101 return;
41024102 }
41034103
......@@ -4106,7 +4106,7 @@ static void preview_use_decl(CodeGen *g, TldUsingNamespace *using_namespace, Sco
41064106 buf_sprintf("expected struct, enum, or union; found '%s'", buf_ptr(&result->data.x_type->name)));
41074107 dest_decls_scope->any_imports_failed = true;
41084108 using_namespace->base.resolution = TldResolutionInvalid;
4109 using_namespace->using_namespace_value = g->invalid_instruction->value;
4109 using_namespace->using_namespace_value = g->invalid_inst_gen->value;
41104110 return;
41114111 }
41124112}
......@@ -4667,12 +4667,12 @@ static void analyze_fn_async(CodeGen *g, ZigFn *fn, bool resolve_frame) {
46674667 }
46684668
46694669 for (size_t i = 0; i < fn->call_list.length; i += 1) {
4670 IrInstructionCallGen *call = fn->call_list.at(i);
4670 IrInstGenCall *call = fn->call_list.at(i);
46714671 if (call->fn_entry == nullptr) {
46724672 // TODO function pointer call here, could be anything
46734673 continue;
46744674 }
4675 switch (analyze_callee_async(g, fn, call->fn_entry, call->base.source_node, must_not_be_async,
4675 switch (analyze_callee_async(g, fn, call->fn_entry, call->base.base.source_node, must_not_be_async,
46764676 call->modifier))
46774677 {
46784678 case ErrorSemanticAnalyzeFail:
......@@ -4690,10 +4690,10 @@ static void analyze_fn_async(CodeGen *g, ZigFn *fn, bool resolve_frame) {
46904690 }
46914691 }
46924692 for (size_t i = 0; i < fn->await_list.length; i += 1) {
4693 IrInstructionAwaitGen *await = fn->await_list.at(i);
4693 IrInstGenAwait *await = fn->await_list.at(i);
46944694 // TODO If this is a noasync await, it doesn't count
46954695 // https://github.com/ziglang/zig/issues/3157
4696 switch (analyze_callee_async(g, fn, await->target_fn, await->base.source_node, must_not_be_async,
4696 switch (analyze_callee_async(g, fn, await->target_fn, await->base.base.source_node, must_not_be_async,
46974697 CallModifierNone))
46984698 {
46994699 case ErrorSemanticAnalyzeFail:
......@@ -4784,7 +4784,7 @@ static void analyze_fn_ir(CodeGen *g, ZigFn *fn, AstNode *return_type_node) {
47844784
47854785 if (g->verbose_ir) {
47864786 fprintf(stderr, "fn %s() { // (analyzed)\n", buf_ptr(&fn->symbol_name));
4787 ir_print(g, stderr, &fn->analyzed_executable, 4, IrPassGen);
4787 ir_print_gen(g, stderr, &fn->analyzed_executable, 4);
47884788 fprintf(stderr, "}\n");
47894789 }
47904790 fn->anal_state = FnAnalStateComplete;
......@@ -4827,7 +4827,7 @@ static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry) {
48274827 fprintf(stderr, "\n");
48284828 ast_render(stderr, fn_table_entry->body_node, 4);
48294829 fprintf(stderr, "\nfn %s() { // (IR)\n", buf_ptr(&fn_table_entry->symbol_name));
4830 ir_print(g, stderr, fn_table_entry->ir_executable, 4, IrPassSrc);
4830 ir_print_src(g, stderr, fn_table_entry->ir_executable, 4);
48314831 fprintf(stderr, "}\n");
48324832 }
48334833
......@@ -6191,13 +6191,13 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
61916191 ZigType *fn_type = get_async_fn_type(g, fn->type_entry);
61926192
61936193 if (fn->analyzed_executable.need_err_code_spill) {
6194 IrInstructionAllocaGen *alloca_gen = allocate<IrInstructionAllocaGen>(1);
6195 alloca_gen->base.id = IrInstructionIdAllocaGen;
6196 alloca_gen->base.source_node = fn->proto_node;
6197 alloca_gen->base.scope = fn->child_scope;
6194 IrInstGenAlloca *alloca_gen = allocate<IrInstGenAlloca>(1);
6195 alloca_gen->base.id = IrInstGenIdAlloca;
6196 alloca_gen->base.base.source_node = fn->proto_node;
6197 alloca_gen->base.base.scope = fn->child_scope;
61986198 alloca_gen->base.value = allocate<ZigValue>(1, "ZigValue");
61996199 alloca_gen->base.value->type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false);
6200 alloca_gen->base.ref_count = 1;
6200 alloca_gen->base.base.ref_count = 1;
62016201 alloca_gen->name_hint = "";
62026202 fn->alloca_gen_list.append(alloca_gen);
62036203 fn->err_code_spill = &alloca_gen->base;
......@@ -6205,18 +6205,18 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
62056205
62066206 ZigType *largest_call_frame_type = nullptr;
62076207 // Later we'll change this to be largest_call_frame_type instead of void.
6208 IrInstruction *all_calls_alloca = ir_create_alloca(g, &fn->fndef_scope->base, fn->body_node,
6208 IrInstGen *all_calls_alloca = ir_create_alloca(g, &fn->fndef_scope->base, fn->body_node,
62096209 fn, g->builtin_types.entry_void, "@async_call_frame");
62106210
62116211 for (size_t i = 0; i < fn->call_list.length; i += 1) {
6212 IrInstructionCallGen *call = fn->call_list.at(i);
6212 IrInstGenCall *call = fn->call_list.at(i);
62136213 if (call->new_stack != nullptr) {
62146214 // don't need to allocate a frame for this
62156215 continue;
62166216 }
62176217 ZigFn *callee = call->fn_entry;
62186218 if (callee == nullptr) {
6219 add_node_error(g, call->base.source_node,
6219 add_node_error(g, call->base.base.source_node,
62206220 buf_sprintf("function is not comptime-known; @asyncCall required"));
62216221 return ErrorSemanticAnalyzeFail;
62226222 }
......@@ -6226,14 +6226,14 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
62266226 if (callee->anal_state == FnAnalStateProbing) {
62276227 ErrorMsg *msg = add_node_error(g, fn->proto_node,
62286228 buf_sprintf("unable to determine async function frame of '%s'", buf_ptr(&fn->symbol_name)));
6229 g->trace_err = add_error_note(g, msg, call->base.source_node,
6229 g->trace_err = add_error_note(g, msg, call->base.base.source_node,
62306230 buf_sprintf("analysis of function '%s' depends on the frame", buf_ptr(&callee->symbol_name)));
62316231 return ErrorSemanticAnalyzeFail;
62326232 }
62336233
62346234 ZigType *callee_frame_type = get_fn_frame_type(g, callee);
62356235 frame_type->data.frame.resolve_loop_type = callee_frame_type;
6236 frame_type->data.frame.resolve_loop_src_node = call->base.source_node;
6236 frame_type->data.frame.resolve_loop_src_node = call->base.base.source_node;
62376237
62386238 analyze_fn_body(g, callee);
62396239 if (callee->anal_state == FnAnalStateInvalid) {
......@@ -6249,7 +6249,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
62496249 if (!fn_is_async(callee))
62506250 continue;
62516251
6252 mark_suspension_point(call->base.scope);
6252 mark_suspension_point(call->base.base.scope);
62536253
62546254 if ((err = type_resolve(g, callee_frame_type, ResolveStatusSizeKnown))) {
62556255 return err;
......@@ -6271,7 +6271,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
62716271 // For example: foo() + await z
62726272 // The funtion call result of foo() must be spilled.
62736273 for (size_t i = 0; i < fn->await_list.length; i += 1) {
6274 IrInstructionAwaitGen *await = fn->await_list.at(i);
6274 IrInstGenAwait *await = fn->await_list.at(i);
62756275 // TODO If this is a noasync await, it doesn't suspend
62766276 // https://github.com/ziglang/zig/issues/3157
62776277 if (await->base.value->special != ConstValSpecialRuntime) {
......@@ -6293,52 +6293,51 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
62936293 }
62946294 // This await is a suspend point, but it might not need a spill.
62956295 // We do need to mark the ExprScope as having a suspend point in it.
6296 mark_suspension_point(await->base.scope);
6296 mark_suspension_point(await->base.base.scope);
62976297
62986298 if (await->result_loc != nullptr) {
62996299 // If there's a result location, that is the spill
63006300 continue;
63016301 }
6302 if (await->base.ref_count == 0)
6302 if (await->base.base.ref_count == 0)
63036303 continue;
63046304 if (!type_has_bits(await->base.value->type))
63056305 continue;
6306 await->result_loc = ir_create_alloca(g, await->base.scope, await->base.source_node, fn,
6306 await->result_loc = ir_create_alloca(g, await->base.base.scope, await->base.base.source_node, fn,
63076307 await->base.value->type, "");
63086308 }
63096309 for (size_t block_i = 0; block_i < fn->analyzed_executable.basic_block_list.length; block_i += 1) {
6310 IrBasicBlock *block = fn->analyzed_executable.basic_block_list.at(block_i);
6310 IrBasicBlockGen *block = fn->analyzed_executable.basic_block_list.at(block_i);
63116311 for (size_t instr_i = 0; instr_i < block->instruction_list.length; instr_i += 1) {
6312 IrInstruction *instruction = block->instruction_list.at(instr_i);
6313 if (instruction->id == IrInstructionIdSuspendFinish) {
6314 mark_suspension_point(instruction->scope);
6312 IrInstGen *instruction = block->instruction_list.at(instr_i);
6313 if (instruction->id == IrInstGenIdSuspendFinish) {
6314 mark_suspension_point(instruction->base.scope);
63156315 }
63166316 }
63176317 }
63186318 // Now that we've marked all the expr scopes that have to spill, we go over the instructions
63196319 // and spill the relevant ones.
63206320 for (size_t block_i = 0; block_i < fn->analyzed_executable.basic_block_list.length; block_i += 1) {
6321 IrBasicBlock *block = fn->analyzed_executable.basic_block_list.at(block_i);
6321 IrBasicBlockGen *block = fn->analyzed_executable.basic_block_list.at(block_i);
63226322 for (size_t instr_i = 0; instr_i < block->instruction_list.length; instr_i += 1) {
6323 IrInstruction *instruction = block->instruction_list.at(instr_i);
6324 if (instruction->id == IrInstructionIdAwaitGen ||
6325 instruction->id == IrInstructionIdVarPtr ||
6326 instruction->id == IrInstructionIdDeclRef ||
6327 instruction->id == IrInstructionIdAllocaGen)
6323 IrInstGen *instruction = block->instruction_list.at(instr_i);
6324 if (instruction->id == IrInstGenIdAwait ||
6325 instruction->id == IrInstGenIdVarPtr ||
6326 instruction->id == IrInstGenIdAlloca)
63286327 {
63296328 // This instruction does its own spilling specially, or otherwise doesn't need it.
63306329 continue;
63316330 }
63326331 if (instruction->value->special != ConstValSpecialRuntime)
63336332 continue;
6334 if (instruction->ref_count == 0)
6333 if (instruction->base.ref_count == 0)
63356334 continue;
63366335 if ((err = type_resolve(g, instruction->value->type, ResolveStatusZeroBitsKnown)))
63376336 return ErrorSemanticAnalyzeFail;
63386337 if (!type_has_bits(instruction->value->type))
63396338 continue;
6340 if (scope_needs_spill(instruction->scope)) {
6341 instruction->spill = ir_create_alloca(g, instruction->scope, instruction->source_node,
6339 if (scope_needs_spill(instruction->base.scope)) {
6340 instruction->spill = ir_create_alloca(g, instruction->base.scope, instruction->base.source_node,
63426341 fn, instruction->value->type, "");
63436342 }
63446343 }
......@@ -6389,14 +6388,14 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
63896388 }
63906389
63916390 for (size_t alloca_i = 0; alloca_i < fn->alloca_gen_list.length; alloca_i += 1) {
6392 IrInstructionAllocaGen *instruction = fn->alloca_gen_list.at(alloca_i);
6391 IrInstGenAlloca *instruction = fn->alloca_gen_list.at(alloca_i);
63936392 instruction->field_index = SIZE_MAX;
63946393 ZigType *ptr_type = instruction->base.value->type;
63956394 assert(ptr_type->id == ZigTypeIdPointer);
63966395 ZigType *child_type = ptr_type->data.pointer.child_type;
63976396 if (!type_has_bits(child_type))
63986397 continue;
6399 if (instruction->base.ref_count == 0)
6398 if (instruction->base.base.ref_count == 0)
64006399 continue;
64016400 if (instruction->base.value->special != ConstValSpecialRuntime) {
64026401 if (const_ptr_pointee(nullptr, g, instruction->base.value, nullptr)->special !=
......@@ -6407,7 +6406,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
64076406 }
64086407
64096408 frame_type->data.frame.resolve_loop_type = child_type;
6410 frame_type->data.frame.resolve_loop_src_node = instruction->base.source_node;
6409 frame_type->data.frame.resolve_loop_src_node = instruction->base.base.source_node;
64116410 if ((err = type_resolve(g, child_type, ResolveStatusSizeKnown))) {
64126411 return err;
64136412 }
......@@ -6421,7 +6420,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
64216420 instruction->field_index = fields.length;
64226421
64236422 src_assert(child_type->id != ZigTypeIdPointer || child_type->data.pointer.inferred_struct_field == nullptr,
6424 instruction->base.source_node);
6423 instruction->base.base.source_node);
64256424 fields.append({name, child_type, instruction->align});
64266425 }
64276426
......@@ -6554,8 +6553,10 @@ bool ir_get_var_is_comptime(ZigVar *var) {
65546553 // As an optimization, is_comptime values which are constant are allowed
65556554 // to be omitted from analysis. In this case, there is no child instruction
65566555 // and we simply look at the unanalyzed const parent instruction.
6557 assert(var->is_comptime->value->type->id == ZigTypeIdBool);
6558 var->is_comptime_memoized_value = var->is_comptime->value->data.x_bool;
6556 assert(var->is_comptime->id == IrInstSrcIdConst);
6557 IrInstSrcConst *const_inst = reinterpret_cast<IrInstSrcConst *>(var->is_comptime);
6558 assert(const_inst->value->type->id == ZigTypeIdBool);
6559 var->is_comptime_memoized_value = const_inst->value->data.x_bool;
65596560 var->is_comptime = nullptr;
65606561 return var->is_comptime_memoized_value;
65616562}
......@@ -9193,21 +9194,6 @@ void src_assert(bool ok, AstNode *source_node) {
91939194 stage2_panic(msg, strlen(msg));
91949195}
91959196
9196IrInstruction *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node, ZigFn *fn,
9197 ZigType *var_type, const char *name_hint)
9198{
9199 IrInstructionAllocaGen *alloca_gen = allocate<IrInstructionAllocaGen>(1);
9200 alloca_gen->base.id = IrInstructionIdAllocaGen;
9201 alloca_gen->base.source_node = source_node;
9202 alloca_gen->base.scope = scope;
9203 alloca_gen->base.value = allocate<ZigValue>(1, "ZigValue");
9204 alloca_gen->base.value->type = get_pointer_to_type(g, var_type, false);
9205 alloca_gen->base.ref_count = 1;
9206 alloca_gen->name_hint = name_hint;
9207 fn->alloca_gen_list.append(alloca_gen);
9208 return &alloca_gen->base;
9209}
9210
92119197Error analyze_import(CodeGen *g, ZigType *source_import, Buf *import_target_str,
92129198 ZigType **out_import, Buf **out_import_target_path, Buf *out_full_path)
92139199{
......@@ -9268,8 +9254,17 @@ Error analyze_import(CodeGen *g, ZigType *source_import, Buf *import_target_str,
92689254}
92699255
92709256
9271void IrExecutable::src() {
9272 IrExecutable *it;
9257void IrExecutableSrc::src() {
9258 if (this->source_node != nullptr) {
9259 this->source_node->src();
9260 }
9261 if (this->parent_exec != nullptr) {
9262 this->parent_exec->src();
9263 }
9264}
9265
9266void IrExecutableGen::src() {
9267 IrExecutableGen *it;
92739268 for (it = this; it != nullptr && it->source_node != nullptr; it = it->parent_exec) {
92749269 it->source_node->src();
92759270 }
......@@ -9357,3 +9352,41 @@ bool type_is_numeric(ZigType *ty) {
93579352 }
93589353 zig_unreachable();
93599354}
9355
9356// float ops that take a single argument
9357//TODO Powi, Pow, minnum, maxnum, maximum, minimum, copysign, lround, llround, lrint, llrint
9358const char *float_op_to_name(BuiltinFnId op) {
9359 switch (op) {
9360 case BuiltinFnIdSqrt:
9361 return "sqrt";
9362 case BuiltinFnIdSin:
9363 return "sin";
9364 case BuiltinFnIdCos:
9365 return "cos";
9366 case BuiltinFnIdExp:
9367 return "exp";
9368 case BuiltinFnIdExp2:
9369 return "exp2";
9370 case BuiltinFnIdLog:
9371 return "log";
9372 case BuiltinFnIdLog10:
9373 return "log10";
9374 case BuiltinFnIdLog2:
9375 return "log2";
9376 case BuiltinFnIdFabs:
9377 return "fabs";
9378 case BuiltinFnIdFloor:
9379 return "floor";
9380 case BuiltinFnIdCeil:
9381 return "ceil";
9382 case BuiltinFnIdTrunc:
9383 return "trunc";
9384 case BuiltinFnIdNearbyInt:
9385 return "nearbyint";
9386 case BuiltinFnIdRound:
9387 return "round";
9388 default:
9389 zig_unreachable();
9390 }
9391}
9392
src/analyze.hpp+2-3
......@@ -120,7 +120,7 @@ ScopeLoop *create_loop_scope(CodeGen *g, AstNode *node, Scope *parent);
120120ScopeSuspend *create_suspend_scope(CodeGen *g, AstNode *node, Scope *parent);
121121ScopeFnDef *create_fndef_scope(CodeGen *g, AstNode *node, Scope *parent, ZigFn *fn_entry);
122122Scope *create_comptime_scope(CodeGen *g, AstNode *node, Scope *parent);
123Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstruction *is_comptime);
123Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstSrc *is_comptime);
124124Scope *create_typeof_scope(CodeGen *g, AstNode *node, Scope *parent);
125125ScopeExpr *create_expr_scope(CodeGen *g, AstNode *node, Scope *parent);
126126
......@@ -271,8 +271,6 @@ ZigType *resolve_struct_field_type(CodeGen *g, TypeStructField *struct_field);
271271
272272void add_async_error_notes(CodeGen *g, ErrorMsg *msg, ZigFn *fn);
273273
274IrInstruction *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node, ZigFn *fn,
275 ZigType *var_type, const char *name_hint);
276274Error analyze_import(CodeGen *codegen, ZigType *source_import, Buf *import_target_str,
277275 ZigType **out_import, Buf **out_import_target_path, Buf *out_full_path);
278276ZigValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry);
......@@ -281,4 +279,5 @@ void copy_const_val(ZigValue *dest, ZigValue *src);
281279bool type_has_optional_repr(ZigType *ty);
282280bool is_opt_err_set(ZigType *ty);
283281bool type_is_numeric(ZigType *ty);
282const char *float_op_to_name(BuiltinFnId op);
284283#endif
src/codegen.cpp+413-476
......@@ -186,7 +186,7 @@ static void generate_error_name_table(CodeGen *g);
186186static bool value_is_all_undef(CodeGen *g, ZigValue *const_val);
187187static void gen_undef_init(CodeGen *g, uint32_t ptr_align_bytes, ZigType *value_type, LLVMValueRef ptr);
188188static LLVMValueRef build_alloca(CodeGen *g, ZigType *type_entry, const char *name, uint32_t alignment);
189static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstruction *source_instr,
189static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstGen *source_instr,
190190 LLVMValueRef target_frame_ptr, ZigType *result_type, ZigType *ptr_result_type,
191191 LLVMValueRef result_loc, bool non_async);
192192static Error get_tmp_filename(CodeGen *g, Buf *out, Buf *suffix);
......@@ -872,14 +872,14 @@ static LLVMValueRef get_handle_value(CodeGen *g, LLVMValueRef ptr, ZigType *type
872872 }
873873}
874874
875static void ir_assert(bool ok, IrInstruction *source_instruction) {
875static void ir_assert(bool ok, IrInstGen *source_instruction) {
876876 if (ok) return;
877 src_assert(ok, source_instruction->source_node);
877 src_assert(ok, source_instruction->base.source_node);
878878}
879879
880static bool ir_want_fast_math(CodeGen *g, IrInstruction *instruction) {
880static bool ir_want_fast_math(CodeGen *g, IrInstGen *instruction) {
881881 // TODO memoize
882 Scope *scope = instruction->scope;
882 Scope *scope = instruction->base.scope;
883883 while (scope) {
884884 if (scope->id == ScopeIdBlock) {
885885 ScopeBlock *block_scope = (ScopeBlock *)scope;
......@@ -914,8 +914,8 @@ static bool ir_want_runtime_safety_scope(CodeGen *g, Scope *scope) {
914914 g->build_mode != BuildModeSmallRelease);
915915}
916916
917static bool ir_want_runtime_safety(CodeGen *g, IrInstruction *instruction) {
918 return ir_want_runtime_safety_scope(g, instruction->scope);
917static bool ir_want_runtime_safety(CodeGen *g, IrInstGen *instruction) {
918 return ir_want_runtime_safety_scope(g, instruction->base.scope);
919919}
920920
921921static Buf *panic_msg_buf(PanicMsgId msg_id) {
......@@ -1041,8 +1041,8 @@ static void gen_assertion_scope(CodeGen *g, PanicMsgId msg_id, Scope *source_sco
10411041 }
10421042}
10431043
1044static void gen_assertion(CodeGen *g, PanicMsgId msg_id, IrInstruction *source_instruction) {
1045 return gen_assertion_scope(g, msg_id, source_instruction->scope);
1044static void gen_assertion(CodeGen *g, PanicMsgId msg_id, IrInstGen *source_instruction) {
1045 return gen_assertion_scope(g, msg_id, source_instruction->base.scope);
10461046}
10471047
10481048static LLVMValueRef get_stacksave_fn_val(CodeGen *g) {
......@@ -1756,7 +1756,7 @@ static void gen_var_debug_decl(CodeGen *g, ZigVar *var) {
17561756 LLVMGetInsertBlock(g->builder));
17571757}
17581758
1759static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {
1759static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstGen *instruction) {
17601760 Error err;
17611761
17621762 bool value_has_bits;
......@@ -1767,8 +1767,8 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {
17671767 return nullptr;
17681768
17691769 if (!instruction->llvm_value) {
1770 if (instruction->id == IrInstructionIdAwaitGen) {
1771 IrInstructionAwaitGen *await = reinterpret_cast<IrInstructionAwaitGen*>(instruction);
1770 if (instruction->id == IrInstGenIdAwait) {
1771 IrInstGenAwait *await = reinterpret_cast<IrInstGenAwait*>(instruction);
17721772 if (await->result_loc != nullptr) {
17731773 return get_handle_value(g, ir_llvm_value(g, await->result_loc),
17741774 await->result_loc->value->type->data.pointer.child_type, await->result_loc->value->type);
......@@ -1851,9 +1851,9 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_
18511851 case FnWalkIdCall: {
18521852 if (src_i >= fn_walk->data.call.inst->arg_count)
18531853 return false;
1854 IrInstruction *arg = fn_walk->data.call.inst->args[src_i];
1854 IrInstGen *arg = fn_walk->data.call.inst->args[src_i];
18551855 ty = arg->value->type;
1856 source_node = arg->source_node;
1856 source_node = arg->base.source_node;
18571857 val = ir_llvm_value(g, arg);
18581858 break;
18591859 }
......@@ -2086,10 +2086,10 @@ void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk) {
20862086 return;
20872087 }
20882088 if (fn_walk->id == FnWalkIdCall) {
2089 IrInstructionCallGen *instruction = fn_walk->data.call.inst;
2089 IrInstGenCall *instruction = fn_walk->data.call.inst;
20902090 bool is_var_args = fn_walk->data.call.is_var_args;
20912091 for (size_t call_i = 0; call_i < instruction->arg_count; call_i += 1) {
2092 IrInstruction *param_instruction = instruction->args[call_i];
2092 IrInstGen *param_instruction = instruction->args[call_i];
20932093 ZigType *param_type = param_instruction->value->type;
20942094 if (is_var_args || type_has_bits(param_type)) {
20952095 LLVMValueRef param_value = ir_llvm_value(g, param_instruction);
......@@ -2304,14 +2304,14 @@ static LLVMValueRef get_merge_err_ret_traces_fn_val(CodeGen *g) {
23042304 return fn_val;
23052305
23062306}
2307static LLVMValueRef ir_render_save_err_ret_addr(CodeGen *g, IrExecutable *executable,
2308 IrInstructionSaveErrRetAddr *save_err_ret_addr_instruction)
2307static LLVMValueRef ir_render_save_err_ret_addr(CodeGen *g, IrExecutableGen *executable,
2308 IrInstGenSaveErrRetAddr *save_err_ret_addr_instruction)
23092309{
23102310 assert(g->have_err_ret_tracing);
23112311
23122312 LLVMValueRef return_err_fn = get_return_err_fn(g);
23132313 bool is_llvm_alloca;
2314 LLVMValueRef my_err_trace_val = get_cur_err_ret_trace_val(g, save_err_ret_addr_instruction->base.scope,
2314 LLVMValueRef my_err_trace_val = get_cur_err_ret_trace_val(g, save_err_ret_addr_instruction->base.base.scope,
23152315 &is_llvm_alloca);
23162316 ZigLLVMBuildCall(g->builder, return_err_fn, &my_err_trace_val, 1,
23172317 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");
......@@ -2326,7 +2326,7 @@ static LLVMValueRef ir_render_save_err_ret_addr(CodeGen *g, IrExecutable *execut
23262326 return nullptr;
23272327}
23282328
2329static void gen_assert_resume_id(CodeGen *g, IrInstruction *source_instr, ResumeId resume_id, PanicMsgId msg_id,
2329static void gen_assert_resume_id(CodeGen *g, IrInstGen *source_instr, ResumeId resume_id, PanicMsgId msg_id,
23302330 LLVMBasicBlockRef end_bb)
23312331{
23322332 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;
......@@ -2403,7 +2403,7 @@ static LLVMValueRef gen_maybe_atomic_op(CodeGen *g, LLVMAtomicRMWBinOp op, LLVMV
24032403 }
24042404}
24052405
2406static void gen_async_return(CodeGen *g, IrInstructionReturn *instruction) {
2406static void gen_async_return(CodeGen *g, IrInstGenReturn *instruction) {
24072407 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;
24082408
24092409 ZigType *operand_type = (instruction->operand != nullptr) ? instruction->operand->value->type : nullptr;
......@@ -2482,7 +2482,7 @@ static void gen_async_return(CodeGen *g, IrInstructionReturn *instruction) {
24822482 frame_index_trace_arg(g, ret_type) + 1, "");
24832483 LLVMValueRef dest_trace_ptr = LLVMBuildLoad(g->builder, awaiter_trace_ptr_ptr, "");
24842484 bool is_llvm_alloca;
2485 LLVMValueRef my_err_trace_val = get_cur_err_ret_trace_val(g, instruction->base.scope, &is_llvm_alloca);
2485 LLVMValueRef my_err_trace_val = get_cur_err_ret_trace_val(g, instruction->base.base.scope, &is_llvm_alloca);
24862486 LLVMValueRef args[] = { dest_trace_ptr, my_err_trace_val };
24872487 ZigLLVMBuildCall(g->builder, get_merge_err_ret_traces_fn_val(g), args, 2,
24882488 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");
......@@ -2497,7 +2497,7 @@ static void gen_async_return(CodeGen *g, IrInstructionReturn *instruction) {
24972497 LLVMBuildRetVoid(g->builder);
24982498}
24992499
2500static LLVMValueRef ir_render_return(CodeGen *g, IrExecutable *executable, IrInstructionReturn *instruction) {
2500static LLVMValueRef ir_render_return(CodeGen *g, IrExecutableGen *executable, IrInstGenReturn *instruction) {
25012501 if (fn_is_async(g->cur_fn)) {
25022502 gen_async_return(g, instruction);
25032503 return nullptr;
......@@ -2838,12 +2838,12 @@ static LLVMValueRef gen_rem(CodeGen *g, bool want_runtime_safety, bool want_fast
28382838
28392839}
28402840
2841static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
2842 IrInstructionBinOp *bin_op_instruction)
2841static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutableGen *executable,
2842 IrInstGenBinOp *bin_op_instruction)
28432843{
28442844 IrBinOp op_id = bin_op_instruction->op_id;
2845 IrInstruction *op1 = bin_op_instruction->op1;
2846 IrInstruction *op2 = bin_op_instruction->op2;
2845 IrInstGen *op1 = bin_op_instruction->op1;
2846 IrInstGen *op2 = bin_op_instruction->op2;
28472847
28482848 ZigType *operand_type = op1->value->type;
28492849 ZigType *scalar_type = (operand_type->id == ZigTypeIdVector) ? operand_type->data.vector.elem_type : operand_type;
......@@ -3048,8 +3048,8 @@ static void add_error_range_check(CodeGen *g, ZigType *err_set_type, ZigType *in
30483048 }
30493049}
30503050
3051static LLVMValueRef ir_render_resize_slice(CodeGen *g, IrExecutable *executable,
3052 IrInstructionResizeSlice *instruction)
3051static LLVMValueRef ir_render_resize_slice(CodeGen *g, IrExecutableGen *executable,
3052 IrInstGenResizeSlice *instruction)
30533053{
30543054 ZigType *actual_type = instruction->operand->value->type;
30553055 ZigType *wanted_type = instruction->base.value->type;
......@@ -3116,8 +3116,8 @@ static LLVMValueRef ir_render_resize_slice(CodeGen *g, IrExecutable *executable,
31163116 return result_loc;
31173117}
31183118
3119static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
3120 IrInstructionCast *cast_instruction)
3119static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutableGen *executable,
3120 IrInstGenCast *cast_instruction)
31213121{
31223122 ZigType *actual_type = cast_instruction->value->value->type;
31233123 ZigType *wanted_type = cast_instruction->base.value->type;
......@@ -3194,8 +3194,8 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
31943194 zig_unreachable();
31953195}
31963196
3197static LLVMValueRef ir_render_ptr_of_array_to_slice(CodeGen *g, IrExecutable *executable,
3198 IrInstructionPtrOfArrayToSlice *instruction)
3197static LLVMValueRef ir_render_ptr_of_array_to_slice(CodeGen *g, IrExecutableGen *executable,
3198 IrInstGenPtrOfArrayToSlice *instruction)
31993199{
32003200 ZigType *actual_type = instruction->operand->value->type;
32013201 ZigType *slice_type = instruction->base.value->type;
......@@ -3231,8 +3231,8 @@ static LLVMValueRef ir_render_ptr_of_array_to_slice(CodeGen *g, IrExecutable *ex
32313231 return result_loc;
32323232}
32333233
3234static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutable *executable,
3235 IrInstructionPtrCastGen *instruction)
3234static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutableGen *executable,
3235 IrInstGenPtrCast *instruction)
32363236{
32373237 ZigType *wanted_type = instruction->base.value->type;
32383238 if (!type_has_bits(wanted_type)) {
......@@ -3257,8 +3257,8 @@ static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutable *executable,
32573257 return result_ptr;
32583258}
32593259
3260static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutable *executable,
3261 IrInstructionBitCastGen *instruction)
3260static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutableGen *executable,
3261 IrInstGenBitCast *instruction)
32623262{
32633263 ZigType *wanted_type = instruction->base.value->type;
32643264 ZigType *actual_type = instruction->operand->value->type;
......@@ -3281,8 +3281,8 @@ static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutable *executable,
32813281 }
32823282}
32833283
3284static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executable,
3285 IrInstructionWidenOrShorten *instruction)
3284static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutableGen *executable,
3285 IrInstGenWidenOrShorten *instruction)
32863286{
32873287 ZigType *actual_type = instruction->target->value->type;
32883288 // TODO instead of this logic, use the Noop instruction to change the type from
......@@ -3298,7 +3298,7 @@ static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executa
32983298 instruction->base.value->type, target_val);
32993299}
33003300
3301static LLVMValueRef ir_render_int_to_ptr(CodeGen *g, IrExecutable *executable, IrInstructionIntToPtr *instruction) {
3301static LLVMValueRef ir_render_int_to_ptr(CodeGen *g, IrExecutableGen *executable, IrInstGenIntToPtr *instruction) {
33023302 ZigType *wanted_type = instruction->base.value->type;
33033303 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
33043304
......@@ -3336,13 +3336,13 @@ static LLVMValueRef ir_render_int_to_ptr(CodeGen *g, IrExecutable *executable, I
33363336 return LLVMBuildIntToPtr(g->builder, target_val, get_llvm_type(g, wanted_type), "");
33373337}
33383338
3339static LLVMValueRef ir_render_ptr_to_int(CodeGen *g, IrExecutable *executable, IrInstructionPtrToInt *instruction) {
3339static LLVMValueRef ir_render_ptr_to_int(CodeGen *g, IrExecutableGen *executable, IrInstGenPtrToInt *instruction) {
33403340 ZigType *wanted_type = instruction->base.value->type;
33413341 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
33423342 return LLVMBuildPtrToInt(g->builder, target_val, get_llvm_type(g, wanted_type), "");
33433343}
33443344
3345static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutable *executable, IrInstructionIntToEnum *instruction) {
3345static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutableGen *executable, IrInstGenIntToEnum *instruction) {
33463346 ZigType *wanted_type = instruction->base.value->type;
33473347 assert(wanted_type->id == ZigTypeIdEnum);
33483348 ZigType *tag_int_type = wanted_type->data.enumeration.tag_int_type;
......@@ -3369,7 +3369,7 @@ static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutable *executable,
33693369 return tag_int_value;
33703370}
33713371
3372static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, IrInstructionIntToErr *instruction) {
3372static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutableGen *executable, IrInstGenIntToErr *instruction) {
33733373 ZigType *wanted_type = instruction->base.value->type;
33743374 assert(wanted_type->id == ZigTypeIdErrorSet);
33753375
......@@ -3386,7 +3386,7 @@ static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, I
33863386 return gen_widen_or_shorten(g, false, actual_type, g->err_tag_type, target_val);
33873387}
33883388
3389static LLVMValueRef ir_render_err_to_int(CodeGen *g, IrExecutable *executable, IrInstructionErrToInt *instruction) {
3389static LLVMValueRef ir_render_err_to_int(CodeGen *g, IrExecutableGen *executable, IrInstGenErrToInt *instruction) {
33903390 ZigType *wanted_type = instruction->base.value->type;
33913391 assert(wanted_type->id == ZigTypeIdInt);
33923392 assert(!wanted_type->data.integral.is_signed);
......@@ -3412,8 +3412,8 @@ static LLVMValueRef ir_render_err_to_int(CodeGen *g, IrExecutable *executable, I
34123412 }
34133413}
34143414
3415static LLVMValueRef ir_render_unreachable(CodeGen *g, IrExecutable *executable,
3416 IrInstructionUnreachable *unreachable_instruction)
3415static LLVMValueRef ir_render_unreachable(CodeGen *g, IrExecutableGen *executable,
3416 IrInstGenUnreachable *unreachable_instruction)
34173417{
34183418 if (ir_want_runtime_safety(g, &unreachable_instruction->base)) {
34193419 gen_safety_crash(g, PanicMsgIdUnreachable);
......@@ -3423,8 +3423,8 @@ static LLVMValueRef ir_render_unreachable(CodeGen *g, IrExecutable *executable,
34233423 return nullptr;
34243424}
34253425
3426static LLVMValueRef ir_render_cond_br(CodeGen *g, IrExecutable *executable,
3427 IrInstructionCondBr *cond_br_instruction)
3426static LLVMValueRef ir_render_cond_br(CodeGen *g, IrExecutableGen *executable,
3427 IrInstGenCondBr *cond_br_instruction)
34283428{
34293429 LLVMBuildCondBr(g->builder,
34303430 ir_llvm_value(g, cond_br_instruction->condition),
......@@ -3433,51 +3433,56 @@ static LLVMValueRef ir_render_cond_br(CodeGen *g, IrExecutable *executable,
34333433 return nullptr;
34343434}
34353435
3436static LLVMValueRef ir_render_br(CodeGen *g, IrExecutable *executable, IrInstructionBr *br_instruction) {
3436static LLVMValueRef ir_render_br(CodeGen *g, IrExecutableGen *executable, IrInstGenBr *br_instruction) {
34373437 LLVMBuildBr(g->builder, br_instruction->dest_block->llvm_block);
34383438 return nullptr;
34393439}
34403440
3441static LLVMValueRef ir_render_un_op(CodeGen *g, IrExecutable *executable, IrInstructionUnOp *un_op_instruction) {
3442 IrUnOp op_id = un_op_instruction->op_id;
3443 LLVMValueRef expr = ir_llvm_value(g, un_op_instruction->value);
3444 ZigType *operand_type = un_op_instruction->value->value->type;
3445 ZigType *scalar_type = (operand_type->id == ZigTypeIdVector) ? operand_type->data.vector.elem_type : operand_type;
3446
3447 switch (op_id) {
3448 case IrUnOpInvalid:
3449 case IrUnOpOptional:
3450 case IrUnOpDereference:
3451 zig_unreachable();
3452 case IrUnOpNegation:
3453 case IrUnOpNegationWrap:
3454 {
3455 if (scalar_type->id == ZigTypeIdFloat) {
3456 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &un_op_instruction->base));
3457 return LLVMBuildFNeg(g->builder, expr, "");
3458 } else if (scalar_type->id == ZigTypeIdInt) {
3459 if (op_id == IrUnOpNegationWrap) {
3460 return LLVMBuildNeg(g->builder, expr, "");
3461 } else if (ir_want_runtime_safety(g, &un_op_instruction->base)) {
3462 LLVMValueRef zero = LLVMConstNull(LLVMTypeOf(expr));
3463 return gen_overflow_op(g, operand_type, AddSubMulSub, zero, expr);
3464 } else if (scalar_type->data.integral.is_signed) {
3465 return LLVMBuildNSWNeg(g->builder, expr, "");
3466 } else {
3467 return LLVMBuildNUWNeg(g->builder, expr, "");
3468 }
3469 } else {
3470 zig_unreachable();
3471 }
3472 }
3473 case IrUnOpBinNot:
3474 return LLVMBuildNot(g->builder, expr, "");
3441static LLVMValueRef ir_render_binary_not(CodeGen *g, IrExecutableGen *executable,
3442 IrInstGenBinaryNot *inst)
3443{
3444 LLVMValueRef operand = ir_llvm_value(g, inst->operand);
3445 return LLVMBuildNot(g->builder, operand, "");
3446}
3447
3448static LLVMValueRef ir_gen_negation(CodeGen *g, IrInstGen *inst, IrInstGen *operand, bool wrapping) {
3449 LLVMValueRef llvm_operand = ir_llvm_value(g, operand);
3450 ZigType *operand_type = operand->value->type;
3451 ZigType *scalar_type = (operand_type->id == ZigTypeIdVector) ?
3452 operand_type->data.vector.elem_type : operand_type;
3453
3454 if (scalar_type->id == ZigTypeIdFloat) {
3455 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, inst));
3456 return LLVMBuildFNeg(g->builder, llvm_operand, "");
3457 } else if (scalar_type->id == ZigTypeIdInt) {
3458 if (wrapping) {
3459 return LLVMBuildNeg(g->builder, llvm_operand, "");
3460 } else if (ir_want_runtime_safety(g, inst)) {
3461 LLVMValueRef zero = LLVMConstNull(LLVMTypeOf(llvm_operand));
3462 return gen_overflow_op(g, operand_type, AddSubMulSub, zero, llvm_operand);
3463 } else if (scalar_type->data.integral.is_signed) {
3464 return LLVMBuildNSWNeg(g->builder, llvm_operand, "");
3465 } else {
3466 return LLVMBuildNUWNeg(g->builder, llvm_operand, "");
3467 }
3468 } else {
3469 zig_unreachable();
34753470 }
3471}
34763472
3477 zig_unreachable();
3473static LLVMValueRef ir_render_negation(CodeGen *g, IrExecutableGen *executable,
3474 IrInstGenNegation *inst)
3475{
3476 return ir_gen_negation(g, &inst->base, inst->operand, false);
3477}
3478
3479static LLVMValueRef ir_render_negation_wrapping(CodeGen *g, IrExecutableGen *executable,
3480 IrInstGenNegationWrapping *inst)
3481{
3482 return ir_gen_negation(g, &inst->base, inst->operand, true);
34783483}
34793484
3480static LLVMValueRef ir_render_bool_not(CodeGen *g, IrExecutable *executable, IrInstructionBoolNot *instruction) {
3485static LLVMValueRef ir_render_bool_not(CodeGen *g, IrExecutableGen *executable, IrInstGenBoolNot *instruction) {
34813486 LLVMValueRef value = ir_llvm_value(g, instruction->value);
34823487 LLVMValueRef zero = LLVMConstNull(LLVMTypeOf(value));
34833488 return LLVMBuildICmp(g->builder, LLVMIntEQ, value, zero, "");
......@@ -3491,14 +3496,14 @@ static void render_decl_var(CodeGen *g, ZigVar *var) {
34913496 gen_var_debug_decl(g, var);
34923497}
34933498
3494static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable, IrInstructionDeclVarGen *instruction) {
3499static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutableGen *executable, IrInstGenDeclVar *instruction) {
34953500 instruction->var->ptr_instruction = instruction->var_ptr;
34963501 render_decl_var(g, instruction->var);
34973502 return nullptr;
34983503}
34993504
3500static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutable *executable,
3501 IrInstructionLoadPtrGen *instruction)
3505static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutableGen *executable,
3506 IrInstGenLoadPtr *instruction)
35023507{
35033508 ZigType *child_type = instruction->base.value->type;
35043509 if (!type_has_bits(child_type))
......@@ -3700,7 +3705,7 @@ static void gen_undef_init(CodeGen *g, uint32_t ptr_align_bytes, ZigType *value_
37003705 }
37013706}
37023707
3703static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, IrInstructionStorePtr *instruction) {
3708static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutableGen *executable, IrInstGenStorePtr *instruction) {
37043709 Error err;
37053710
37063711 ZigType *ptr_type = instruction->ptr->value->type;
......@@ -3710,7 +3715,7 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir
37103715 codegen_report_errors_and_exit(g);
37113716 if (!ptr_type_has_bits)
37123717 return nullptr;
3713 if (instruction->ptr->ref_count == 0) {
3718 if (instruction->ptr->base.ref_count == 0) {
37143719 // In this case, this StorePtr instruction should be elided. Something happened like this:
37153720 // var t = true;
37163721 // const x = if (t) Num.Two else unreachable;
......@@ -3732,8 +3737,8 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir
37323737 return nullptr;
37333738}
37343739
3735static LLVMValueRef ir_render_vector_store_elem(CodeGen *g, IrExecutable *executable,
3736 IrInstructionVectorStoreElem *instruction)
3740static LLVMValueRef ir_render_vector_store_elem(CodeGen *g, IrExecutableGen *executable,
3741 IrInstGenVectorStoreElem *instruction)
37373742{
37383743 LLVMValueRef vector_ptr = ir_llvm_value(g, instruction->vector_ptr);
37393744 LLVMValueRef index = ir_llvm_value(g, instruction->index);
......@@ -3745,7 +3750,7 @@ static LLVMValueRef ir_render_vector_store_elem(CodeGen *g, IrExecutable *execut
37453750 return nullptr;
37463751}
37473752
3748static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrInstructionVarPtr *instruction) {
3753static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutableGen *executable, IrInstGenVarPtr *instruction) {
37493754 if (instruction->base.value->special != ConstValSpecialRuntime)
37503755 return ir_llvm_value(g, &instruction->base);
37513756 ZigVar *var = instruction->var;
......@@ -3757,8 +3762,8 @@ static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrIn
37573762 }
37583763}
37593764
3760static LLVMValueRef ir_render_return_ptr(CodeGen *g, IrExecutable *executable,
3761 IrInstructionReturnPtr *instruction)
3765static LLVMValueRef ir_render_return_ptr(CodeGen *g, IrExecutableGen *executable,
3766 IrInstGenReturnPtr *instruction)
37623767{
37633768 if (!type_has_bits(instruction->base.value->type))
37643769 return nullptr;
......@@ -3766,7 +3771,7 @@ static LLVMValueRef ir_render_return_ptr(CodeGen *g, IrExecutable *executable,
37663771 return g->cur_ret_ptr;
37673772}
37683773
3769static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrInstructionElemPtr *instruction) {
3774static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutableGen *executable, IrInstGenElemPtr *instruction) {
37703775 LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->array_ptr);
37713776 ZigType *array_ptr_type = instruction->array_ptr->value->type;
37723777 assert(array_ptr_type->id == ZigTypeIdPointer);
......@@ -3942,7 +3947,7 @@ static void render_async_spills(CodeGen *g) {
39423947 ZigType *frame_type = g->cur_fn->frame_type->data.frame.locals_struct;
39433948
39443949 for (size_t alloca_i = 0; alloca_i < g->cur_fn->alloca_gen_list.length; alloca_i += 1) {
3945 IrInstructionAllocaGen *instruction = g->cur_fn->alloca_gen_list.at(alloca_i);
3950 IrInstGenAlloca *instruction = g->cur_fn->alloca_gen_list.at(alloca_i);
39463951 if (instruction->field_index == SIZE_MAX)
39473952 continue;
39483953
......@@ -4009,7 +4014,7 @@ static void gen_init_stack_trace(CodeGen *g, LLVMValueRef trace_field_ptr, LLVMV
40094014 LLVMBuildStore(g->builder, LLVMConstInt(usize_type_ref, stack_trace_ptr_count, false), addrs_len_ptr);
40104015}
40114016
4012static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstructionCallGen *instruction) {
4017static LLVMValueRef ir_render_call(CodeGen *g, IrExecutableGen *executable, IrInstGenCall *instruction) {
40134018 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;
40144019
40154020 LLVMValueRef fn_val;
......@@ -4144,7 +4149,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
41444149 LLVMValueRef err_ret_trace_ptr_ptr = LLVMBuildStructGEP(g->builder, frame_result_loc,
41454150 frame_index_trace_arg(g, src_return_type) + 1, "");
41464151 bool is_llvm_alloca;
4147 LLVMValueRef my_err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.scope,
4152 LLVMValueRef my_err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.base.scope,
41484153 &is_llvm_alloca);
41494154 LLVMBuildStore(g->builder, my_err_ret_trace_val, err_ret_trace_ptr_ptr);
41504155 }
......@@ -4203,7 +4208,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
42034208 gen_init_stack_trace(g, trace_field_ptr, addrs_field_ptr);
42044209
42054210 bool is_llvm_alloca;
4206 gen_param_values.append(get_cur_err_ret_trace_val(g, instruction->base.scope, &is_llvm_alloca));
4211 gen_param_values.append(get_cur_err_ret_trace_val(g, instruction->base.base.scope, &is_llvm_alloca));
42074212 }
42084213 }
42094214 } else {
......@@ -4212,7 +4217,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
42124217 }
42134218 if (prefix_arg_err_ret_stack) {
42144219 bool is_llvm_alloca;
4215 gen_param_values.append(get_cur_err_ret_trace_val(g, instruction->base.scope, &is_llvm_alloca));
4220 gen_param_values.append(get_cur_err_ret_trace_val(g, instruction->base.base.scope, &is_llvm_alloca));
42164221 }
42174222 }
42184223 FnWalk fn_walk = {};
......@@ -4322,13 +4327,13 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
43224327
43234328 LLVMPositionBuilderAtEnd(g->builder, call_bb);
43244329 gen_assert_resume_id(g, &instruction->base, ResumeIdReturn, PanicMsgIdResumedAnAwaitingFn, nullptr);
4325 render_async_var_decls(g, instruction->base.scope);
4330 render_async_var_decls(g, instruction->base.base.scope);
43264331
43274332 if (!type_has_bits(src_return_type))
43284333 return nullptr;
43294334
43304335 if (result_loc != nullptr) {
4331 if (instruction->result_loc->id == IrInstructionIdReturnPtr) {
4336 if (instruction->result_loc->id == IrInstGenIdReturnPtr) {
43324337 instruction->base.spill = nullptr;
43334338 return g->cur_ret_ptr;
43344339 } else {
......@@ -4388,8 +4393,8 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
43884393 }
43894394}
43904395
4391static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executable,
4392 IrInstructionStructFieldPtr *instruction)
4396static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutableGen *executable,
4397 IrInstGenStructFieldPtr *instruction)
43934398{
43944399 Error err;
43954400
......@@ -4439,8 +4444,8 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executa
44394444 return field_ptr_val;
44404445}
44414446
4442static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutable *executable,
4443 IrInstructionUnionFieldPtr *instruction)
4447static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutableGen *executable,
4448 IrInstGenUnionFieldPtr *instruction)
44444449{
44454450 if (instruction->base.value->special != ConstValSpecialRuntime)
44464451 return nullptr;
......@@ -4539,8 +4544,8 @@ static size_t find_asm_index(CodeGen *g, AstNode *node, AsmToken *tok, Buf *src_
45394544 return SIZE_MAX;
45404545}
45414546
4542static LLVMValueRef ir_render_asm_gen(CodeGen *g, IrExecutable *executable, IrInstructionAsmGen *instruction) {
4543 AstNode *asm_node = instruction->base.source_node;
4547static LLVMValueRef ir_render_asm_gen(CodeGen *g, IrExecutableGen *executable, IrInstGenAsm *instruction) {
4548 AstNode *asm_node = instruction->base.base.source_node;
45444549 assert(asm_node->type == NodeTypeAsmExpr);
45454550 AstNodeAsmExpr *asm_expr = &asm_node->data.asm_expr;
45464551
......@@ -4624,7 +4629,7 @@ static LLVMValueRef ir_render_asm_gen(CodeGen *g, IrExecutable *executable, IrIn
46244629 for (size_t i = 0; i < asm_expr->input_list.length; i += 1, total_index += 1, param_index += 1) {
46254630 AsmInput *asm_input = asm_expr->input_list.at(i);
46264631 buf_replace(asm_input->constraint, ',', '|');
4627 IrInstruction *ir_input = instruction->input_list[i];
4632 IrInstGen *ir_input = instruction->input_list[i];
46284633 buf_append_buf(&constraint_buf, asm_input->constraint);
46294634 if (total_index + 1 < total_constraint_count) {
46304635 buf_append_char(&constraint_buf, ',');
......@@ -4687,14 +4692,14 @@ static LLVMValueRef gen_non_null_bit(CodeGen *g, ZigType *maybe_type, LLVMValueR
46874692 return gen_load_untyped(g, maybe_field_ptr, 0, false, "");
46884693}
46894694
4690static LLVMValueRef ir_render_test_non_null(CodeGen *g, IrExecutable *executable,
4691 IrInstructionTestNonNull *instruction)
4695static LLVMValueRef ir_render_test_non_null(CodeGen *g, IrExecutableGen *executable,
4696 IrInstGenTestNonNull *instruction)
46924697{
46934698 return gen_non_null_bit(g, instruction->value->value->type, ir_llvm_value(g, instruction->value));
46944699}
46954700
4696static LLVMValueRef ir_render_optional_unwrap_ptr(CodeGen *g, IrExecutable *executable,
4697 IrInstructionOptionalUnwrapPtr *instruction)
4701static LLVMValueRef ir_render_optional_unwrap_ptr(CodeGen *g, IrExecutableGen *executable,
4702 IrInstGenOptionalUnwrapPtr *instruction)
46984703{
46994704 if (instruction->base.value->special != ConstValSpecialRuntime)
47004705 return nullptr;
......@@ -4796,7 +4801,7 @@ static LLVMValueRef get_int_builtin_fn(CodeGen *g, ZigType *expr_type, BuiltinFn
47964801 return fn_val;
47974802}
47984803
4799static LLVMValueRef ir_render_clz(CodeGen *g, IrExecutable *executable, IrInstructionClz *instruction) {
4804static LLVMValueRef ir_render_clz(CodeGen *g, IrExecutableGen *executable, IrInstGenClz *instruction) {
48004805 ZigType *int_type = instruction->op->value->type;
48014806 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdClz);
48024807 LLVMValueRef operand = ir_llvm_value(g, instruction->op);
......@@ -4808,7 +4813,7 @@ static LLVMValueRef ir_render_clz(CodeGen *g, IrExecutable *executable, IrInstru
48084813 return gen_widen_or_shorten(g, false, int_type, instruction->base.value->type, wrong_size_int);
48094814}
48104815
4811static LLVMValueRef ir_render_ctz(CodeGen *g, IrExecutable *executable, IrInstructionCtz *instruction) {
4816static LLVMValueRef ir_render_ctz(CodeGen *g, IrExecutableGen *executable, IrInstGenCtz *instruction) {
48124817 ZigType *int_type = instruction->op->value->type;
48134818 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdCtz);
48144819 LLVMValueRef operand = ir_llvm_value(g, instruction->op);
......@@ -4820,7 +4825,7 @@ static LLVMValueRef ir_render_ctz(CodeGen *g, IrExecutable *executable, IrInstru
48204825 return gen_widen_or_shorten(g, false, int_type, instruction->base.value->type, wrong_size_int);
48214826}
48224827
4823static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutable *executable, IrInstructionShuffleVector *instruction) {
4828static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutableGen *executable, IrInstGenShuffleVector *instruction) {
48244829 uint64_t len_a = instruction->a->value->type->data.vector.len;
48254830 uint64_t len_mask = instruction->mask->value->type->data.vector.len;
48264831
......@@ -4829,7 +4834,7 @@ static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutable *executabl
48294834 // when changing code, so Zig uses negative numbers to index the
48304835 // second vector. These start at -1 and go down, and are easiest to use
48314836 // with the ~ operator. Here we convert between the two formats.
4832 IrInstruction *mask = instruction->mask;
4837 IrInstGen *mask = instruction->mask;
48334838 LLVMValueRef *values = allocate<LLVMValueRef>(len_mask);
48344839 for (uint64_t i = 0; i < len_mask; i++) {
48354840 if (mask->value->data.x_array.data.s_none.elements[i].special == ConstValSpecialUndef) {
......@@ -4850,7 +4855,7 @@ static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutable *executabl
48504855 llvm_mask_value, "");
48514856}
48524857
4853static LLVMValueRef ir_render_splat(CodeGen *g, IrExecutable *executable, IrInstructionSplatGen *instruction) {
4858static LLVMValueRef ir_render_splat(CodeGen *g, IrExecutableGen *executable, IrInstGenSplat *instruction) {
48544859 ZigType *result_type = instruction->base.value->type;
48554860 ir_assert(result_type->id == ZigTypeIdVector, &instruction->base);
48564861 uint32_t len = result_type->data.vector.len;
......@@ -4862,7 +4867,7 @@ static LLVMValueRef ir_render_splat(CodeGen *g, IrExecutable *executable, IrInst
48624867 return LLVMBuildShuffleVector(g->builder, op_vector, undef_vector, LLVMConstNull(mask_llvm_type), "");
48634868}
48644869
4865static LLVMValueRef ir_render_pop_count(CodeGen *g, IrExecutable *executable, IrInstructionPopCount *instruction) {
4870static LLVMValueRef ir_render_pop_count(CodeGen *g, IrExecutableGen *executable, IrInstGenPopCount *instruction) {
48664871 ZigType *int_type = instruction->op->value->type;
48674872 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdPopCount);
48684873 LLVMValueRef operand = ir_llvm_value(g, instruction->op);
......@@ -4870,7 +4875,7 @@ static LLVMValueRef ir_render_pop_count(CodeGen *g, IrExecutable *executable, Ir
48704875 return gen_widen_or_shorten(g, false, int_type, instruction->base.value->type, wrong_size_int);
48714876}
48724877
4873static LLVMValueRef ir_render_switch_br(CodeGen *g, IrExecutable *executable, IrInstructionSwitchBr *instruction) {
4878static LLVMValueRef ir_render_switch_br(CodeGen *g, IrExecutableGen *executable, IrInstGenSwitchBr *instruction) {
48744879 ZigType *target_type = instruction->target_value->value->type;
48754880 LLVMBasicBlockRef else_block = instruction->else_block->llvm_block;
48764881
......@@ -4884,7 +4889,7 @@ static LLVMValueRef ir_render_switch_br(CodeGen *g, IrExecutable *executable, Ir
48844889 (unsigned)instruction->case_count);
48854890
48864891 for (size_t i = 0; i < instruction->case_count; i += 1) {
4887 IrInstructionSwitchBrCase *this_case = &instruction->cases[i];
4892 IrInstGenSwitchBrCase *this_case = &instruction->cases[i];
48884893
48894894 LLVMValueRef case_value = ir_llvm_value(g, this_case->value);
48904895 if (target_type->id == ZigTypeIdPointer) {
......@@ -4898,7 +4903,7 @@ static LLVMValueRef ir_render_switch_br(CodeGen *g, IrExecutable *executable, Ir
48984903 return nullptr;
48994904}
49004905
4901static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutable *executable, IrInstructionPhi *instruction) {
4906static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutableGen *executable, IrInstGenPhi *instruction) {
49024907 if (!type_has_bits(instruction->base.value->type))
49034908 return nullptr;
49044909
......@@ -4920,7 +4925,7 @@ static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutable *executable, IrInstru
49204925 return phi;
49214926}
49224927
4923static LLVMValueRef ir_render_ref(CodeGen *g, IrExecutable *executable, IrInstructionRefGen *instruction) {
4928static LLVMValueRef ir_render_ref(CodeGen *g, IrExecutableGen *executable, IrInstGenRef *instruction) {
49244929 if (!type_has_bits(instruction->base.value->type)) {
49254930 return nullptr;
49264931 }
......@@ -4934,7 +4939,7 @@ static LLVMValueRef ir_render_ref(CodeGen *g, IrExecutable *executable, IrInstru
49344939 }
49354940}
49364941
4937static LLVMValueRef ir_render_err_name(CodeGen *g, IrExecutable *executable, IrInstructionErrName *instruction) {
4942static LLVMValueRef ir_render_err_name(CodeGen *g, IrExecutableGen *executable, IrInstGenErrName *instruction) {
49384943 assert(g->generate_error_name_table);
49394944
49404945 if (g->errors_by_index.length == 1) {
......@@ -5055,13 +5060,13 @@ static LLVMValueRef get_enum_tag_name_function(CodeGen *g, ZigType *enum_type) {
50555060 return fn_val;
50565061}
50575062
5058static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutable *executable,
5059 IrInstructionTagName *instruction)
5063static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutableGen *executable,
5064 IrInstGenTagName *instruction)
50605065{
50615066 ZigType *enum_type = instruction->target->value->type;
50625067 assert(enum_type->id == ZigTypeIdEnum);
50635068 if (enum_type->data.enumeration.non_exhaustive) {
5064 add_node_error(g, instruction->base.source_node,
5069 add_node_error(g, instruction->base.base.source_node,
50655070 buf_sprintf("TODO @tagName on non-exhaustive enum https://github.com/ziglang/zig/issues/3991"));
50665071 codegen_report_errors_and_exit(g);
50675072 }
......@@ -5073,8 +5078,8 @@ static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutable *executable
50735078 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");
50745079}
50755080
5076static LLVMValueRef ir_render_field_parent_ptr(CodeGen *g, IrExecutable *executable,
5077 IrInstructionFieldParentPtr *instruction)
5081static LLVMValueRef ir_render_field_parent_ptr(CodeGen *g, IrExecutableGen *executable,
5082 IrInstGenFieldParentPtr *instruction)
50785083{
50795084 ZigType *container_ptr_type = instruction->base.value->type;
50805085 assert(container_ptr_type->id == ZigTypeIdPointer);
......@@ -5100,7 +5105,7 @@ static LLVMValueRef ir_render_field_parent_ptr(CodeGen *g, IrExecutable *executa
51005105 }
51015106}
51025107
5103static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, IrInstructionAlignCast *instruction) {
5108static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutableGen *executable, IrInstGenAlignCast *instruction) {
51045109 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
51055110 assert(target_val);
51065111
......@@ -5163,11 +5168,11 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I
51635168 return target_val;
51645169}
51655170
5166static LLVMValueRef ir_render_error_return_trace(CodeGen *g, IrExecutable *executable,
5167 IrInstructionErrorReturnTrace *instruction)
5171static LLVMValueRef ir_render_error_return_trace(CodeGen *g, IrExecutableGen *executable,
5172 IrInstGenErrorReturnTrace *instruction)
51685173{
51695174 bool is_llvm_alloca;
5170 LLVMValueRef cur_err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.scope, &is_llvm_alloca);
5175 LLVMValueRef cur_err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.base.scope, &is_llvm_alloca);
51715176 if (cur_err_ret_trace_val == nullptr) {
51725177 return LLVMConstNull(get_llvm_type(g, ptr_to_stack_trace_type(g)));
51735178 }
......@@ -5205,7 +5210,7 @@ static enum ZigLLVM_AtomicRMWBinOp to_ZigLLVMAtomicRMWBinOp(AtomicRmwOp op, bool
52055210 zig_unreachable();
52065211}
52075212
5208static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutable *executable, IrInstructionCmpxchgGen *instruction) {
5213static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutableGen *executable, IrInstGenCmpxchg *instruction) {
52095214 LLVMValueRef ptr_val = ir_llvm_value(g, instruction->ptr);
52105215 LLVMValueRef cmp_val = ir_llvm_value(g, instruction->cmp_value);
52115216 LLVMValueRef new_val = ir_llvm_value(g, instruction->new_value);
......@@ -5246,13 +5251,13 @@ static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutable *executable, IrIn
52465251 return result_loc;
52475252}
52485253
5249static LLVMValueRef ir_render_fence(CodeGen *g, IrExecutable *executable, IrInstructionFence *instruction) {
5254static LLVMValueRef ir_render_fence(CodeGen *g, IrExecutableGen *executable, IrInstGenFence *instruction) {
52505255 LLVMAtomicOrdering atomic_order = to_LLVMAtomicOrdering(instruction->order);
52515256 LLVMBuildFence(g->builder, atomic_order, false, "");
52525257 return nullptr;
52535258}
52545259
5255static LLVMValueRef ir_render_truncate(CodeGen *g, IrExecutable *executable, IrInstructionTruncate *instruction) {
5260static LLVMValueRef ir_render_truncate(CodeGen *g, IrExecutableGen *executable, IrInstGenTruncate *instruction) {
52565261 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
52575262 ZigType *dest_type = instruction->base.value->type;
52585263 ZigType *src_type = instruction->target->value->type;
......@@ -5267,7 +5272,7 @@ static LLVMValueRef ir_render_truncate(CodeGen *g, IrExecutable *executable, IrI
52675272 }
52685273}
52695274
5270static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutable *executable, IrInstructionMemset *instruction) {
5275static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutableGen *executable, IrInstGenMemset *instruction) {
52715276 LLVMValueRef dest_ptr = ir_llvm_value(g, instruction->dest_ptr);
52725277 LLVMValueRef len_val = ir_llvm_value(g, instruction->count);
52735278
......@@ -5279,7 +5284,7 @@ static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutable *executable, IrIns
52795284
52805285 bool val_is_undef = value_is_all_undef(g, instruction->byte->value);
52815286 LLVMValueRef fill_char;
5282 if (val_is_undef && ir_want_runtime_safety_scope(g, instruction->base.scope)) {
5287 if (val_is_undef && ir_want_runtime_safety_scope(g, instruction->base.base.scope)) {
52835288 fill_char = LLVMConstInt(LLVMInt8Type(), 0xaa, false);
52845289 } else {
52855290 fill_char = ir_llvm_value(g, instruction->byte);
......@@ -5293,7 +5298,7 @@ static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutable *executable, IrIns
52935298 return nullptr;
52945299}
52955300
5296static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutable *executable, IrInstructionMemcpy *instruction) {
5301static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutableGen *executable, IrInstGenMemcpy *instruction) {
52975302 LLVMValueRef dest_ptr = ir_llvm_value(g, instruction->dest_ptr);
52985303 LLVMValueRef src_ptr = ir_llvm_value(g, instruction->src_ptr);
52995304 LLVMValueRef len_val = ir_llvm_value(g, instruction->count);
......@@ -5315,7 +5320,7 @@ static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutable *executable, IrIns
53155320 return nullptr;
53165321}
53175322
5318static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInstructionSliceGen *instruction) {
5323static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutableGen *executable, IrInstGenSlice *instruction) {
53195324 LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->ptr);
53205325 ZigType *array_ptr_type = instruction->ptr->value->type;
53215326 assert(array_ptr_type->id == ZigTypeIdPointer);
......@@ -5477,13 +5482,13 @@ static LLVMValueRef get_trap_fn_val(CodeGen *g) {
54775482}
54785483
54795484
5480static LLVMValueRef ir_render_breakpoint(CodeGen *g, IrExecutable *executable, IrInstructionBreakpoint *instruction) {
5485static LLVMValueRef ir_render_breakpoint(CodeGen *g, IrExecutableGen *executable, IrInstGenBreakpoint *instruction) {
54815486 LLVMBuildCall(g->builder, get_trap_fn_val(g), nullptr, 0, "");
54825487 return nullptr;
54835488}
54845489
5485static LLVMValueRef ir_render_return_address(CodeGen *g, IrExecutable *executable,
5486 IrInstructionReturnAddress *instruction)
5490static LLVMValueRef ir_render_return_address(CodeGen *g, IrExecutableGen *executable,
5491 IrInstGenReturnAddress *instruction)
54875492{
54885493 LLVMValueRef zero = LLVMConstNull(g->builtin_types.entry_i32->llvm_type);
54895494 LLVMValueRef ptr_val = LLVMBuildCall(g->builder, get_return_address_fn_val(g), &zero, 1, "");
......@@ -5504,19 +5509,19 @@ static LLVMValueRef get_frame_address_fn_val(CodeGen *g) {
55045509 return g->frame_address_fn_val;
55055510}
55065511
5507static LLVMValueRef ir_render_frame_address(CodeGen *g, IrExecutable *executable,
5508 IrInstructionFrameAddress *instruction)
5512static LLVMValueRef ir_render_frame_address(CodeGen *g, IrExecutableGen *executable,
5513 IrInstGenFrameAddress *instruction)
55095514{
55105515 LLVMValueRef zero = LLVMConstNull(g->builtin_types.entry_i32->llvm_type);
55115516 LLVMValueRef ptr_val = LLVMBuildCall(g->builder, get_frame_address_fn_val(g), &zero, 1, "");
55125517 return LLVMBuildPtrToInt(g->builder, ptr_val, g->builtin_types.entry_usize->llvm_type, "");
55135518}
55145519
5515static LLVMValueRef ir_render_handle(CodeGen *g, IrExecutable *executable, IrInstructionFrameHandle *instruction) {
5520static LLVMValueRef ir_render_handle(CodeGen *g, IrExecutableGen *executable, IrInstGenFrameHandle *instruction) {
55165521 return g->cur_frame_ptr;
55175522}
55185523
5519static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstructionOverflowOp *instruction) {
5524static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstGenOverflowOp *instruction) {
55205525 ZigType *int_type = instruction->result_ptr_type;
55215526 assert(int_type->id == ZigTypeIdInt);
55225527
......@@ -5541,7 +5546,7 @@ static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstructionOverflowOp
55415546 return overflow_bit;
55425547}
55435548
5544static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutable *executable, IrInstructionOverflowOp *instruction) {
5549static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutableGen *executable, IrInstGenOverflowOp *instruction) {
55455550 AddSubMul add_sub_mul;
55465551 switch (instruction->op) {
55475552 case IrOverflowOpAdd:
......@@ -5579,7 +5584,7 @@ static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutable *executable,
55795584 return overflow_bit;
55805585}
55815586
5582static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrInstructionTestErrGen *instruction) {
5587static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutableGen *executable, IrInstGenTestErr *instruction) {
55835588 ZigType *err_union_type = instruction->err_union->value->type;
55845589 ZigType *payload_type = err_union_type->data.error_union.payload_type;
55855590 LLVMValueRef err_union_handle = ir_llvm_value(g, instruction->err_union);
......@@ -5596,8 +5601,8 @@ static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrI
55965601 return LLVMBuildICmp(g->builder, LLVMIntNE, err_val, zero, "");
55975602}
55985603
5599static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executable,
5600 IrInstructionUnwrapErrCode *instruction)
5604static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutableGen *executable,
5605 IrInstGenUnwrapErrCode *instruction)
56015606{
56025607 if (instruction->base.value->special != ConstValSpecialRuntime)
56035608 return nullptr;
......@@ -5616,8 +5621,8 @@ static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executab
56165621 }
56175622}
56185623
5619static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *executable,
5620 IrInstructionUnwrapErrPayload *instruction)
5624static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutableGen *executable,
5625 IrInstGenUnwrapErrPayload *instruction)
56215626{
56225627 Error err;
56235628
......@@ -5660,7 +5665,7 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *execu
56605665 LLVMBuildCondBr(g->builder, cond_val, ok_block, err_block);
56615666
56625667 LLVMPositionBuilderAtEnd(g->builder, err_block);
5663 gen_safety_crash_for_err(g, err_val, instruction->base.scope);
5668 gen_safety_crash_for_err(g, err_val, instruction->base.base.scope);
56645669
56655670 LLVMPositionBuilderAtEnd(g->builder, ok_block);
56665671 }
......@@ -5677,7 +5682,7 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *execu
56775682 }
56785683}
56795684
5680static LLVMValueRef ir_render_optional_wrap(CodeGen *g, IrExecutable *executable, IrInstructionOptionalWrap *instruction) {
5685static LLVMValueRef ir_render_optional_wrap(CodeGen *g, IrExecutableGen *executable, IrInstGenOptionalWrap *instruction) {
56815686 ZigType *wanted_type = instruction->base.value->type;
56825687
56835688 assert(wanted_type->id == ZigTypeIdOptional);
......@@ -5713,7 +5718,7 @@ static LLVMValueRef ir_render_optional_wrap(CodeGen *g, IrExecutable *executable
57135718 return result_loc;
57145719}
57155720
5716static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutable *executable, IrInstructionErrWrapCode *instruction) {
5721static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutableGen *executable, IrInstGenErrWrapCode *instruction) {
57175722 ZigType *wanted_type = instruction->base.value->type;
57185723
57195724 assert(wanted_type->id == ZigTypeIdErrorUnion);
......@@ -5733,7 +5738,7 @@ static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutable *executable
57335738 return result_loc;
57345739}
57355740
5736static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutable *executable, IrInstructionErrWrapPayload *instruction) {
5741static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutableGen *executable, IrInstGenErrWrapPayload *instruction) {
57375742 ZigType *wanted_type = instruction->base.value->type;
57385743
57395744 assert(wanted_type->id == ZigTypeIdErrorUnion);
......@@ -5764,7 +5769,7 @@ static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutable *executa
57645769 return result_loc;
57655770}
57665771
5767static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutable *executable, IrInstructionUnionTag *instruction) {
5772static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutableGen *executable, IrInstGenUnionTag *instruction) {
57685773 ZigType *union_type = instruction->value->value->type;
57695774
57705775 ZigType *tag_type = union_type->data.unionation.tag_type;
......@@ -5782,15 +5787,15 @@ static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutable *executable, Ir
57825787 return get_handle_value(g, tag_field_ptr, tag_type, ptr_type);
57835788}
57845789
5785static LLVMValueRef ir_render_panic(CodeGen *g, IrExecutable *executable, IrInstructionPanic *instruction) {
5790static LLVMValueRef ir_render_panic(CodeGen *g, IrExecutableGen *executable, IrInstGenPanic *instruction) {
57865791 bool is_llvm_alloca;
5787 LLVMValueRef err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.scope, &is_llvm_alloca);
5792 LLVMValueRef err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.base.scope, &is_llvm_alloca);
57885793 gen_panic(g, ir_llvm_value(g, instruction->msg), err_ret_trace_val, is_llvm_alloca);
57895794 return nullptr;
57905795}
57915796
5792static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutable *executable,
5793 IrInstructionAtomicRmw *instruction)
5797static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutableGen *executable,
5798 IrInstGenAtomicRmw *instruction)
57945799{
57955800 bool is_signed;
57965801 ZigType *operand_type = instruction->operand->value->type;
......@@ -5800,8 +5805,8 @@ static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutable *executable,
58005805 } else {
58015806 is_signed = false;
58025807 }
5803 enum ZigLLVM_AtomicRMWBinOp op = to_ZigLLVMAtomicRMWBinOp(instruction->resolved_op, is_signed, is_float);
5804 LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->resolved_ordering);
5808 enum ZigLLVM_AtomicRMWBinOp op = to_ZigLLVMAtomicRMWBinOp(instruction->op, is_signed, is_float);
5809 LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->ordering);
58055810 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
58065811 LLVMValueRef operand = ir_llvm_value(g, instruction->operand);
58075812
......@@ -5818,20 +5823,20 @@ static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutable *executable,
58185823 return LLVMBuildIntToPtr(g->builder, uncasted_result, get_llvm_type(g, operand_type), "");
58195824}
58205825
5821static LLVMValueRef ir_render_atomic_load(CodeGen *g, IrExecutable *executable,
5822 IrInstructionAtomicLoad *instruction)
5826static LLVMValueRef ir_render_atomic_load(CodeGen *g, IrExecutableGen *executable,
5827 IrInstGenAtomicLoad *instruction)
58235828{
5824 LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->resolved_ordering);
5829 LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->ordering);
58255830 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
58265831 LLVMValueRef load_inst = gen_load(g, ptr, instruction->ptr->value->type, "");
58275832 LLVMSetOrdering(load_inst, ordering);
58285833 return load_inst;
58295834}
58305835
5831static LLVMValueRef ir_render_atomic_store(CodeGen *g, IrExecutable *executable,
5832 IrInstructionAtomicStore *instruction)
5836static LLVMValueRef ir_render_atomic_store(CodeGen *g, IrExecutableGen *executable,
5837 IrInstGenAtomicStore *instruction)
58335838{
5834 LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->resolved_ordering);
5839 LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->ordering);
58355840 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
58365841 LLVMValueRef value = ir_llvm_value(g, instruction->value);
58375842 LLVMValueRef store_inst = gen_store(g, value, ptr, instruction->ptr->value->type);
......@@ -5839,13 +5844,13 @@ static LLVMValueRef ir_render_atomic_store(CodeGen *g, IrExecutable *executable,
58395844 return nullptr;
58405845}
58415846
5842static LLVMValueRef ir_render_float_op(CodeGen *g, IrExecutable *executable, IrInstructionFloatOp *instruction) {
5847static LLVMValueRef ir_render_float_op(CodeGen *g, IrExecutableGen *executable, IrInstGenFloatOp *instruction) {
58435848 LLVMValueRef operand = ir_llvm_value(g, instruction->operand);
58445849 LLVMValueRef fn_val = get_float_fn(g, instruction->base.value->type, ZigLLVMFnIdFloatOp, instruction->fn_id);
58455850 return LLVMBuildCall(g->builder, fn_val, &operand, 1, "");
58465851}
58475852
5848static LLVMValueRef ir_render_mul_add(CodeGen *g, IrExecutable *executable, IrInstructionMulAdd *instruction) {
5853static LLVMValueRef ir_render_mul_add(CodeGen *g, IrExecutableGen *executable, IrInstGenMulAdd *instruction) {
58495854 LLVMValueRef op1 = ir_llvm_value(g, instruction->op1);
58505855 LLVMValueRef op2 = ir_llvm_value(g, instruction->op2);
58515856 LLVMValueRef op3 = ir_llvm_value(g, instruction->op3);
......@@ -5860,7 +5865,7 @@ static LLVMValueRef ir_render_mul_add(CodeGen *g, IrExecutable *executable, IrIn
58605865 return LLVMBuildCall(g->builder, fn_val, args, 3, "");
58615866}
58625867
5863static LLVMValueRef ir_render_bswap(CodeGen *g, IrExecutable *executable, IrInstructionBswap *instruction) {
5868static LLVMValueRef ir_render_bswap(CodeGen *g, IrExecutableGen *executable, IrInstGenBswap *instruction) {
58645869 LLVMValueRef op = ir_llvm_value(g, instruction->op);
58655870 ZigType *expr_type = instruction->base.value->type;
58665871 bool is_vector = expr_type->id == ZigTypeIdVector;
......@@ -5894,7 +5899,7 @@ static LLVMValueRef ir_render_bswap(CodeGen *g, IrExecutable *executable, IrInst
58945899 return LLVMBuildTrunc(g->builder, shifted, get_llvm_type(g, expr_type), "");
58955900}
58965901
5897static LLVMValueRef ir_render_bit_reverse(CodeGen *g, IrExecutable *executable, IrInstructionBitReverse *instruction) {
5902static LLVMValueRef ir_render_bit_reverse(CodeGen *g, IrExecutableGen *executable, IrInstGenBitReverse *instruction) {
58985903 LLVMValueRef op = ir_llvm_value(g, instruction->op);
58995904 ZigType *int_type = instruction->base.value->type;
59005905 assert(int_type->id == ZigTypeIdInt);
......@@ -5902,8 +5907,8 @@ static LLVMValueRef ir_render_bit_reverse(CodeGen *g, IrExecutable *executable,
59025907 return LLVMBuildCall(g->builder, fn_val, &op, 1, "");
59035908}
59045909
5905static LLVMValueRef ir_render_vector_to_array(CodeGen *g, IrExecutable *executable,
5906 IrInstructionVectorToArray *instruction)
5910static LLVMValueRef ir_render_vector_to_array(CodeGen *g, IrExecutableGen *executable,
5911 IrInstGenVectorToArray *instruction)
59075912{
59085913 ZigType *array_type = instruction->base.value->type;
59095914 assert(array_type->id == ZigTypeIdArray);
......@@ -5936,8 +5941,8 @@ static LLVMValueRef ir_render_vector_to_array(CodeGen *g, IrExecutable *executab
59365941 return result_loc;
59375942}
59385943
5939static LLVMValueRef ir_render_array_to_vector(CodeGen *g, IrExecutable *executable,
5940 IrInstructionArrayToVector *instruction)
5944static LLVMValueRef ir_render_array_to_vector(CodeGen *g, IrExecutableGen *executable,
5945 IrInstGenArrayToVector *instruction)
59415946{
59425947 ZigType *vector_type = instruction->base.value->type;
59435948 assert(vector_type->id == ZigTypeIdVector);
......@@ -5973,8 +5978,8 @@ static LLVMValueRef ir_render_array_to_vector(CodeGen *g, IrExecutable *executab
59735978 }
59745979}
59755980
5976static LLVMValueRef ir_render_assert_zero(CodeGen *g, IrExecutable *executable,
5977 IrInstructionAssertZero *instruction)
5981static LLVMValueRef ir_render_assert_zero(CodeGen *g, IrExecutableGen *executable,
5982 IrInstGenAssertZero *instruction)
59785983{
59795984 LLVMValueRef target = ir_llvm_value(g, instruction->target);
59805985 ZigType *int_type = instruction->target->value->type;
......@@ -5984,8 +5989,8 @@ static LLVMValueRef ir_render_assert_zero(CodeGen *g, IrExecutable *executable,
59845989 return nullptr;
59855990}
59865991
5987static LLVMValueRef ir_render_assert_non_null(CodeGen *g, IrExecutable *executable,
5988 IrInstructionAssertNonNull *instruction)
5992static LLVMValueRef ir_render_assert_non_null(CodeGen *g, IrExecutableGen *executable,
5993 IrInstGenAssertNonNull *instruction)
59895994{
59905995 LLVMValueRef target = ir_llvm_value(g, instruction->target);
59915996 ZigType *target_type = instruction->target->value->type;
......@@ -6009,8 +6014,8 @@ static LLVMValueRef ir_render_assert_non_null(CodeGen *g, IrExecutable *executab
60096014 return nullptr;
60106015}
60116016
6012static LLVMValueRef ir_render_suspend_begin(CodeGen *g, IrExecutable *executable,
6013 IrInstructionSuspendBegin *instruction)
6017static LLVMValueRef ir_render_suspend_begin(CodeGen *g, IrExecutableGen *executable,
6018 IrInstGenSuspendBegin *instruction)
60146019{
60156020 if (fn_is_async(g->cur_fn)) {
60166021 instruction->resume_bb = gen_suspend_begin(g, "SuspendResume");
......@@ -6018,8 +6023,8 @@ static LLVMValueRef ir_render_suspend_begin(CodeGen *g, IrExecutable *executable
60186023 return nullptr;
60196024}
60206025
6021static LLVMValueRef ir_render_suspend_finish(CodeGen *g, IrExecutable *executable,
6022 IrInstructionSuspendFinish *instruction)
6026static LLVMValueRef ir_render_suspend_finish(CodeGen *g, IrExecutableGen *executable,
6027 IrInstGenSuspendFinish *instruction)
60236028{
60246029 LLVMBuildRetVoid(g->builder);
60256030
......@@ -6027,11 +6032,11 @@ static LLVMValueRef ir_render_suspend_finish(CodeGen *g, IrExecutable *executabl
60276032 if (ir_want_runtime_safety(g, &instruction->base)) {
60286033 LLVMBuildStore(g->builder, g->cur_bad_not_suspended_index, g->cur_async_resume_index_ptr);
60296034 }
6030 render_async_var_decls(g, instruction->base.scope);
6035 render_async_var_decls(g, instruction->base.base.scope);
60316036 return nullptr;
60326037}
60336038
6034static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstruction *source_instr,
6039static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstGen *source_instr,
60356040 LLVMValueRef target_frame_ptr, ZigType *result_type, ZigType *ptr_result_type,
60366041 LLVMValueRef result_loc, bool non_async)
60376042{
......@@ -6057,7 +6062,7 @@ static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstruction *source_ins
60576062 frame_index_trace_arg(g, result_type), "");
60586063 LLVMValueRef src_trace_ptr = LLVMBuildLoad(g->builder, their_trace_ptr_ptr, "");
60596064 bool is_llvm_alloca;
6060 LLVMValueRef dest_trace_ptr = get_cur_err_ret_trace_val(g, source_instr->scope, &is_llvm_alloca);
6065 LLVMValueRef dest_trace_ptr = get_cur_err_ret_trace_val(g, source_instr->base.scope, &is_llvm_alloca);
60616066 LLVMValueRef args[] = { dest_trace_ptr, src_trace_ptr };
60626067 ZigLLVMBuildCall(g->builder, get_merge_err_ret_traces_fn_val(g), args, 2,
60636068 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");
......@@ -6070,7 +6075,7 @@ static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstruction *source_ins
60706075 }
60716076}
60726077
6073static LLVMValueRef ir_render_await(CodeGen *g, IrExecutable *executable, IrInstructionAwaitGen *instruction) {
6078static LLVMValueRef ir_render_await(CodeGen *g, IrExecutableGen *executable, IrInstGenAwait *instruction) {
60746079 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;
60756080 LLVMValueRef zero = LLVMConstNull(usize_type_ref);
60766081 LLVMValueRef target_frame_ptr = ir_llvm_value(g, instruction->frame);
......@@ -6107,7 +6112,7 @@ static LLVMValueRef ir_render_await(CodeGen *g, IrExecutable *executable, IrInst
61076112 // supply the error return trace pointer
61086113 if (codegen_fn_has_err_ret_tracing_arg(g, result_type)) {
61096114 bool is_llvm_alloca;
6110 LLVMValueRef my_err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.scope, &is_llvm_alloca);
6115 LLVMValueRef my_err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.base.scope, &is_llvm_alloca);
61116116 assert(my_err_ret_trace_val != nullptr);
61126117 LLVMValueRef err_ret_trace_ptr_ptr = LLVMBuildStructGEP(g->builder, target_frame_ptr,
61136118 frame_index_trace_arg(g, result_type) + 1, "");
......@@ -6155,7 +6160,7 @@ static LLVMValueRef ir_render_await(CodeGen *g, IrExecutable *executable, IrInst
61556160 return nullptr;
61566161}
61576162
6158static LLVMValueRef ir_render_resume(CodeGen *g, IrExecutable *executable, IrInstructionResume *instruction) {
6163static LLVMValueRef ir_render_resume(CodeGen *g, IrExecutableGen *executable, IrInstGenResume *instruction) {
61596164 LLVMValueRef frame = ir_llvm_value(g, instruction->frame);
61606165 ZigType *frame_type = instruction->frame->value->type;
61616166 assert(frame_type->id == ZigTypeIdAnyFrame);
......@@ -6164,15 +6169,15 @@ static LLVMValueRef ir_render_resume(CodeGen *g, IrExecutable *executable, IrIns
61646169 return nullptr;
61656170}
61666171
6167static LLVMValueRef ir_render_frame_size(CodeGen *g, IrExecutable *executable,
6168 IrInstructionFrameSizeGen *instruction)
6172static LLVMValueRef ir_render_frame_size(CodeGen *g, IrExecutableGen *executable,
6173 IrInstGenFrameSize *instruction)
61696174{
61706175 LLVMValueRef fn_val = ir_llvm_value(g, instruction->fn);
61716176 return gen_frame_size(g, fn_val);
61726177}
61736178
6174static LLVMValueRef ir_render_spill_begin(CodeGen *g, IrExecutable *executable,
6175 IrInstructionSpillBegin *instruction)
6179static LLVMValueRef ir_render_spill_begin(CodeGen *g, IrExecutableGen *executable,
6180 IrInstGenSpillBegin *instruction)
61766181{
61776182 if (!fn_is_async(g->cur_fn))
61786183 return nullptr;
......@@ -6191,7 +6196,7 @@ static LLVMValueRef ir_render_spill_begin(CodeGen *g, IrExecutable *executable,
61916196 zig_unreachable();
61926197}
61936198
6194static LLVMValueRef ir_render_spill_end(CodeGen *g, IrExecutable *executable, IrInstructionSpillEnd *instruction) {
6199static LLVMValueRef ir_render_spill_end(CodeGen *g, IrExecutableGen *executable, IrInstGenSpillEnd *instruction) {
61956200 if (!fn_is_async(g->cur_fn))
61966201 return ir_llvm_value(g, instruction->begin->operand);
61976202
......@@ -6207,17 +6212,17 @@ static LLVMValueRef ir_render_spill_end(CodeGen *g, IrExecutable *executable, Ir
62076212 zig_unreachable();
62086213}
62096214
6210static LLVMValueRef ir_render_vector_extract_elem(CodeGen *g, IrExecutable *executable,
6211 IrInstructionVectorExtractElem *instruction)
6215static LLVMValueRef ir_render_vector_extract_elem(CodeGen *g, IrExecutableGen *executable,
6216 IrInstGenVectorExtractElem *instruction)
62126217{
62136218 LLVMValueRef vector = ir_llvm_value(g, instruction->vector);
62146219 LLVMValueRef index = ir_llvm_value(g, instruction->index);
62156220 return LLVMBuildExtractElement(g->builder, vector, index, "");
62166221}
62176222
6218static void set_debug_location(CodeGen *g, IrInstruction *instruction) {
6219 AstNode *source_node = instruction->source_node;
6220 Scope *scope = instruction->scope;
6223static void set_debug_location(CodeGen *g, IrInstGen *instruction) {
6224 AstNode *source_node = instruction->base.source_node;
6225 Scope *scope = instruction->base.scope;
62216226
62226227 assert(source_node);
62236228 assert(scope);
......@@ -6226,263 +6231,183 @@ static void set_debug_location(CodeGen *g, IrInstruction *instruction) {
62266231 (int)source_node->column + 1, get_di_scope(g, scope));
62276232}
62286233
6229static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable, IrInstruction *instruction) {
6234static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutableGen *executable, IrInstGen *instruction) {
62306235 switch (instruction->id) {
6231 case IrInstructionIdInvalid:
6232 case IrInstructionIdConst:
6233 case IrInstructionIdTypeOf:
6234 case IrInstructionIdFieldPtr:
6235 case IrInstructionIdSetCold:
6236 case IrInstructionIdSetRuntimeSafety:
6237 case IrInstructionIdSetFloatMode:
6238 case IrInstructionIdArrayType:
6239 case IrInstructionIdAnyFrameType:
6240 case IrInstructionIdSliceType:
6241 case IrInstructionIdSizeOf:
6242 case IrInstructionIdSwitchTarget:
6243 case IrInstructionIdContainerInitFields:
6244 case IrInstructionIdCompileErr:
6245 case IrInstructionIdCompileLog:
6246 case IrInstructionIdImport:
6247 case IrInstructionIdCImport:
6248 case IrInstructionIdCInclude:
6249 case IrInstructionIdCDefine:
6250 case IrInstructionIdCUndef:
6251 case IrInstructionIdEmbedFile:
6252 case IrInstructionIdIntType:
6253 case IrInstructionIdVectorType:
6254 case IrInstructionIdMemberCount:
6255 case IrInstructionIdMemberType:
6256 case IrInstructionIdMemberName:
6257 case IrInstructionIdAlignOf:
6258 case IrInstructionIdFnProto:
6259 case IrInstructionIdTestComptime:
6260 case IrInstructionIdCheckSwitchProngs:
6261 case IrInstructionIdCheckStatementIsVoid:
6262 case IrInstructionIdTypeName:
6263 case IrInstructionIdDeclRef:
6264 case IrInstructionIdSwitchVar:
6265 case IrInstructionIdSwitchElseVar:
6266 case IrInstructionIdByteOffsetOf:
6267 case IrInstructionIdBitOffsetOf:
6268 case IrInstructionIdTypeInfo:
6269 case IrInstructionIdType:
6270 case IrInstructionIdHasField:
6271 case IrInstructionIdTypeId:
6272 case IrInstructionIdSetEvalBranchQuota:
6273 case IrInstructionIdPtrType:
6274 case IrInstructionIdOpaqueType:
6275 case IrInstructionIdSetAlignStack:
6276 case IrInstructionIdArgType:
6277 case IrInstructionIdTagType:
6278 case IrInstructionIdExport:
6279 case IrInstructionIdErrorUnion:
6280 case IrInstructionIdAddImplicitReturnType:
6281 case IrInstructionIdIntCast:
6282 case IrInstructionIdFloatCast:
6283 case IrInstructionIdIntToFloat:
6284 case IrInstructionIdFloatToInt:
6285 case IrInstructionIdBoolToInt:
6286 case IrInstructionIdErrSetCast:
6287 case IrInstructionIdFromBytes:
6288 case IrInstructionIdToBytes:
6289 case IrInstructionIdEnumToInt:
6290 case IrInstructionIdCheckRuntimeScope:
6291 case IrInstructionIdDeclVarSrc:
6292 case IrInstructionIdPtrCastSrc:
6293 case IrInstructionIdCmpxchgSrc:
6294 case IrInstructionIdLoadPtr:
6295 case IrInstructionIdHasDecl:
6296 case IrInstructionIdUndeclaredIdent:
6297 case IrInstructionIdCallExtra:
6298 case IrInstructionIdCallSrc:
6299 case IrInstructionIdCallSrcArgs:
6300 case IrInstructionIdAllocaSrc:
6301 case IrInstructionIdEndExpr:
6302 case IrInstructionIdImplicitCast:
6303 case IrInstructionIdResolveResult:
6304 case IrInstructionIdResetResult:
6305 case IrInstructionIdContainerInitList:
6306 case IrInstructionIdSliceSrc:
6307 case IrInstructionIdRef:
6308 case IrInstructionIdBitCastSrc:
6309 case IrInstructionIdTestErrSrc:
6310 case IrInstructionIdUnionInitNamedField:
6311 case IrInstructionIdFrameType:
6312 case IrInstructionIdFrameSizeSrc:
6313 case IrInstructionIdAllocaGen:
6314 case IrInstructionIdAwaitSrc:
6315 case IrInstructionIdSplatSrc:
6316 case IrInstructionIdMergeErrSets:
6317 case IrInstructionIdAsmSrc:
6236 case IrInstGenIdInvalid:
6237 case IrInstGenIdConst:
6238 case IrInstGenIdAlloca:
63186239 zig_unreachable();
63196240
6320 case IrInstructionIdDeclVarGen:
6321 return ir_render_decl_var(g, executable, (IrInstructionDeclVarGen *)instruction);
6322 case IrInstructionIdReturn:
6323 return ir_render_return(g, executable, (IrInstructionReturn *)instruction);
6324 case IrInstructionIdBinOp:
6325 return ir_render_bin_op(g, executable, (IrInstructionBinOp *)instruction);
6326 case IrInstructionIdCast:
6327 return ir_render_cast(g, executable, (IrInstructionCast *)instruction);
6328 case IrInstructionIdUnreachable:
6329 return ir_render_unreachable(g, executable, (IrInstructionUnreachable *)instruction);
6330 case IrInstructionIdCondBr:
6331 return ir_render_cond_br(g, executable, (IrInstructionCondBr *)instruction);
6332 case IrInstructionIdBr:
6333 return ir_render_br(g, executable, (IrInstructionBr *)instruction);
6334 case IrInstructionIdUnOp:
6335 return ir_render_un_op(g, executable, (IrInstructionUnOp *)instruction);
6336 case IrInstructionIdLoadPtrGen:
6337 return ir_render_load_ptr(g, executable, (IrInstructionLoadPtrGen *)instruction);
6338 case IrInstructionIdStorePtr:
6339 return ir_render_store_ptr(g, executable, (IrInstructionStorePtr *)instruction);
6340 case IrInstructionIdVectorStoreElem:
6341 return ir_render_vector_store_elem(g, executable, (IrInstructionVectorStoreElem *)instruction);
6342 case IrInstructionIdVarPtr:
6343 return ir_render_var_ptr(g, executable, (IrInstructionVarPtr *)instruction);
6344 case IrInstructionIdReturnPtr:
6345 return ir_render_return_ptr(g, executable, (IrInstructionReturnPtr *)instruction);
6346 case IrInstructionIdElemPtr:
6347 return ir_render_elem_ptr(g, executable, (IrInstructionElemPtr *)instruction);
6348 case IrInstructionIdCallGen:
6349 return ir_render_call(g, executable, (IrInstructionCallGen *)instruction);
6350 case IrInstructionIdStructFieldPtr:
6351 return ir_render_struct_field_ptr(g, executable, (IrInstructionStructFieldPtr *)instruction);
6352 case IrInstructionIdUnionFieldPtr:
6353 return ir_render_union_field_ptr(g, executable, (IrInstructionUnionFieldPtr *)instruction);
6354 case IrInstructionIdAsmGen:
6355 return ir_render_asm_gen(g, executable, (IrInstructionAsmGen *)instruction);
6356 case IrInstructionIdTestNonNull:
6357 return ir_render_test_non_null(g, executable, (IrInstructionTestNonNull *)instruction);
6358 case IrInstructionIdOptionalUnwrapPtr:
6359 return ir_render_optional_unwrap_ptr(g, executable, (IrInstructionOptionalUnwrapPtr *)instruction);
6360 case IrInstructionIdClz:
6361 return ir_render_clz(g, executable, (IrInstructionClz *)instruction);
6362 case IrInstructionIdCtz:
6363 return ir_render_ctz(g, executable, (IrInstructionCtz *)instruction);
6364 case IrInstructionIdPopCount:
6365 return ir_render_pop_count(g, executable, (IrInstructionPopCount *)instruction);
6366 case IrInstructionIdSwitchBr:
6367 return ir_render_switch_br(g, executable, (IrInstructionSwitchBr *)instruction);
6368 case IrInstructionIdBswap:
6369 return ir_render_bswap(g, executable, (IrInstructionBswap *)instruction);
6370 case IrInstructionIdBitReverse:
6371 return ir_render_bit_reverse(g, executable, (IrInstructionBitReverse *)instruction);
6372 case IrInstructionIdPhi:
6373 return ir_render_phi(g, executable, (IrInstructionPhi *)instruction);
6374 case IrInstructionIdRefGen:
6375 return ir_render_ref(g, executable, (IrInstructionRefGen *)instruction);
6376 case IrInstructionIdErrName:
6377 return ir_render_err_name(g, executable, (IrInstructionErrName *)instruction);
6378 case IrInstructionIdCmpxchgGen:
6379 return ir_render_cmpxchg(g, executable, (IrInstructionCmpxchgGen *)instruction);
6380 case IrInstructionIdFence:
6381 return ir_render_fence(g, executable, (IrInstructionFence *)instruction);
6382 case IrInstructionIdTruncate:
6383 return ir_render_truncate(g, executable, (IrInstructionTruncate *)instruction);
6384 case IrInstructionIdBoolNot:
6385 return ir_render_bool_not(g, executable, (IrInstructionBoolNot *)instruction);
6386 case IrInstructionIdMemset:
6387 return ir_render_memset(g, executable, (IrInstructionMemset *)instruction);
6388 case IrInstructionIdMemcpy:
6389 return ir_render_memcpy(g, executable, (IrInstructionMemcpy *)instruction);
6390 case IrInstructionIdSliceGen:
6391 return ir_render_slice(g, executable, (IrInstructionSliceGen *)instruction);
6392 case IrInstructionIdBreakpoint:
6393 return ir_render_breakpoint(g, executable, (IrInstructionBreakpoint *)instruction);
6394 case IrInstructionIdReturnAddress:
6395 return ir_render_return_address(g, executable, (IrInstructionReturnAddress *)instruction);
6396 case IrInstructionIdFrameAddress:
6397 return ir_render_frame_address(g, executable, (IrInstructionFrameAddress *)instruction);
6398 case IrInstructionIdFrameHandle:
6399 return ir_render_handle(g, executable, (IrInstructionFrameHandle *)instruction);
6400 case IrInstructionIdOverflowOp:
6401 return ir_render_overflow_op(g, executable, (IrInstructionOverflowOp *)instruction);
6402 case IrInstructionIdTestErrGen:
6403 return ir_render_test_err(g, executable, (IrInstructionTestErrGen *)instruction);
6404 case IrInstructionIdUnwrapErrCode:
6405 return ir_render_unwrap_err_code(g, executable, (IrInstructionUnwrapErrCode *)instruction);
6406 case IrInstructionIdUnwrapErrPayload:
6407 return ir_render_unwrap_err_payload(g, executable, (IrInstructionUnwrapErrPayload *)instruction);
6408 case IrInstructionIdOptionalWrap:
6409 return ir_render_optional_wrap(g, executable, (IrInstructionOptionalWrap *)instruction);
6410 case IrInstructionIdErrWrapCode:
6411 return ir_render_err_wrap_code(g, executable, (IrInstructionErrWrapCode *)instruction);
6412 case IrInstructionIdErrWrapPayload:
6413 return ir_render_err_wrap_payload(g, executable, (IrInstructionErrWrapPayload *)instruction);
6414 case IrInstructionIdUnionTag:
6415 return ir_render_union_tag(g, executable, (IrInstructionUnionTag *)instruction);
6416 case IrInstructionIdPtrCastGen:
6417 return ir_render_ptr_cast(g, executable, (IrInstructionPtrCastGen *)instruction);
6418 case IrInstructionIdBitCastGen:
6419 return ir_render_bit_cast(g, executable, (IrInstructionBitCastGen *)instruction);
6420 case IrInstructionIdWidenOrShorten:
6421 return ir_render_widen_or_shorten(g, executable, (IrInstructionWidenOrShorten *)instruction);
6422 case IrInstructionIdPtrToInt:
6423 return ir_render_ptr_to_int(g, executable, (IrInstructionPtrToInt *)instruction);
6424 case IrInstructionIdIntToPtr:
6425 return ir_render_int_to_ptr(g, executable, (IrInstructionIntToPtr *)instruction);
6426 case IrInstructionIdIntToEnum:
6427 return ir_render_int_to_enum(g, executable, (IrInstructionIntToEnum *)instruction);
6428 case IrInstructionIdIntToErr:
6429 return ir_render_int_to_err(g, executable, (IrInstructionIntToErr *)instruction);
6430 case IrInstructionIdErrToInt:
6431 return ir_render_err_to_int(g, executable, (IrInstructionErrToInt *)instruction);
6432 case IrInstructionIdPanic:
6433 return ir_render_panic(g, executable, (IrInstructionPanic *)instruction);
6434 case IrInstructionIdTagName:
6435 return ir_render_enum_tag_name(g, executable, (IrInstructionTagName *)instruction);
6436 case IrInstructionIdFieldParentPtr:
6437 return ir_render_field_parent_ptr(g, executable, (IrInstructionFieldParentPtr *)instruction);
6438 case IrInstructionIdAlignCast:
6439 return ir_render_align_cast(g, executable, (IrInstructionAlignCast *)instruction);
6440 case IrInstructionIdErrorReturnTrace:
6441 return ir_render_error_return_trace(g, executable, (IrInstructionErrorReturnTrace *)instruction);
6442 case IrInstructionIdAtomicRmw:
6443 return ir_render_atomic_rmw(g, executable, (IrInstructionAtomicRmw *)instruction);
6444 case IrInstructionIdAtomicLoad:
6445 return ir_render_atomic_load(g, executable, (IrInstructionAtomicLoad *)instruction);
6446 case IrInstructionIdAtomicStore:
6447 return ir_render_atomic_store(g, executable, (IrInstructionAtomicStore *)instruction);
6448 case IrInstructionIdSaveErrRetAddr:
6449 return ir_render_save_err_ret_addr(g, executable, (IrInstructionSaveErrRetAddr *)instruction);
6450 case IrInstructionIdFloatOp:
6451 return ir_render_float_op(g, executable, (IrInstructionFloatOp *)instruction);
6452 case IrInstructionIdMulAdd:
6453 return ir_render_mul_add(g, executable, (IrInstructionMulAdd *)instruction);
6454 case IrInstructionIdArrayToVector:
6455 return ir_render_array_to_vector(g, executable, (IrInstructionArrayToVector *)instruction);
6456 case IrInstructionIdVectorToArray:
6457 return ir_render_vector_to_array(g, executable, (IrInstructionVectorToArray *)instruction);
6458 case IrInstructionIdAssertZero:
6459 return ir_render_assert_zero(g, executable, (IrInstructionAssertZero *)instruction);
6460 case IrInstructionIdAssertNonNull:
6461 return ir_render_assert_non_null(g, executable, (IrInstructionAssertNonNull *)instruction);
6462 case IrInstructionIdResizeSlice:
6463 return ir_render_resize_slice(g, executable, (IrInstructionResizeSlice *)instruction);
6464 case IrInstructionIdPtrOfArrayToSlice:
6465 return ir_render_ptr_of_array_to_slice(g, executable, (IrInstructionPtrOfArrayToSlice *)instruction);
6466 case IrInstructionIdSuspendBegin:
6467 return ir_render_suspend_begin(g, executable, (IrInstructionSuspendBegin *)instruction);
6468 case IrInstructionIdSuspendFinish:
6469 return ir_render_suspend_finish(g, executable, (IrInstructionSuspendFinish *)instruction);
6470 case IrInstructionIdResume:
6471 return ir_render_resume(g, executable, (IrInstructionResume *)instruction);
6472 case IrInstructionIdFrameSizeGen:
6473 return ir_render_frame_size(g, executable, (IrInstructionFrameSizeGen *)instruction);
6474 case IrInstructionIdAwaitGen:
6475 return ir_render_await(g, executable, (IrInstructionAwaitGen *)instruction);
6476 case IrInstructionIdSpillBegin:
6477 return ir_render_spill_begin(g, executable, (IrInstructionSpillBegin *)instruction);
6478 case IrInstructionIdSpillEnd:
6479 return ir_render_spill_end(g, executable, (IrInstructionSpillEnd *)instruction);
6480 case IrInstructionIdShuffleVector:
6481 return ir_render_shuffle_vector(g, executable, (IrInstructionShuffleVector *) instruction);
6482 case IrInstructionIdSplatGen:
6483 return ir_render_splat(g, executable, (IrInstructionSplatGen *) instruction);
6484 case IrInstructionIdVectorExtractElem:
6485 return ir_render_vector_extract_elem(g, executable, (IrInstructionVectorExtractElem *) instruction);
6241 case IrInstGenIdDeclVar:
6242 return ir_render_decl_var(g, executable, (IrInstGenDeclVar *)instruction);
6243 case IrInstGenIdReturn:
6244 return ir_render_return(g, executable, (IrInstGenReturn *)instruction);
6245 case IrInstGenIdBinOp:
6246 return ir_render_bin_op(g, executable, (IrInstGenBinOp *)instruction);
6247 case IrInstGenIdCast:
6248 return ir_render_cast(g, executable, (IrInstGenCast *)instruction);
6249 case IrInstGenIdUnreachable:
6250 return ir_render_unreachable(g, executable, (IrInstGenUnreachable *)instruction);
6251 case IrInstGenIdCondBr:
6252 return ir_render_cond_br(g, executable, (IrInstGenCondBr *)instruction);
6253 case IrInstGenIdBr:
6254 return ir_render_br(g, executable, (IrInstGenBr *)instruction);
6255 case IrInstGenIdBinaryNot:
6256 return ir_render_binary_not(g, executable, (IrInstGenBinaryNot *)instruction);
6257 case IrInstGenIdNegation:
6258 return ir_render_negation(g, executable, (IrInstGenNegation *)instruction);
6259 case IrInstGenIdNegationWrapping:
6260 return ir_render_negation_wrapping(g, executable, (IrInstGenNegationWrapping *)instruction);
6261 case IrInstGenIdLoadPtr:
6262 return ir_render_load_ptr(g, executable, (IrInstGenLoadPtr *)instruction);
6263 case IrInstGenIdStorePtr:
6264 return ir_render_store_ptr(g, executable, (IrInstGenStorePtr *)instruction);
6265 case IrInstGenIdVectorStoreElem:
6266 return ir_render_vector_store_elem(g, executable, (IrInstGenVectorStoreElem *)instruction);
6267 case IrInstGenIdVarPtr:
6268 return ir_render_var_ptr(g, executable, (IrInstGenVarPtr *)instruction);
6269 case IrInstGenIdReturnPtr:
6270 return ir_render_return_ptr(g, executable, (IrInstGenReturnPtr *)instruction);
6271 case IrInstGenIdElemPtr:
6272 return ir_render_elem_ptr(g, executable, (IrInstGenElemPtr *)instruction);
6273 case IrInstGenIdCall:
6274 return ir_render_call(g, executable, (IrInstGenCall *)instruction);
6275 case IrInstGenIdStructFieldPtr:
6276 return ir_render_struct_field_ptr(g, executable, (IrInstGenStructFieldPtr *)instruction);
6277 case IrInstGenIdUnionFieldPtr:
6278 return ir_render_union_field_ptr(g, executable, (IrInstGenUnionFieldPtr *)instruction);
6279 case IrInstGenIdAsm:
6280 return ir_render_asm_gen(g, executable, (IrInstGenAsm *)instruction);
6281 case IrInstGenIdTestNonNull:
6282 return ir_render_test_non_null(g, executable, (IrInstGenTestNonNull *)instruction);
6283 case IrInstGenIdOptionalUnwrapPtr:
6284 return ir_render_optional_unwrap_ptr(g, executable, (IrInstGenOptionalUnwrapPtr *)instruction);
6285 case IrInstGenIdClz:
6286 return ir_render_clz(g, executable, (IrInstGenClz *)instruction);
6287 case IrInstGenIdCtz:
6288 return ir_render_ctz(g, executable, (IrInstGenCtz *)instruction);
6289 case IrInstGenIdPopCount:
6290 return ir_render_pop_count(g, executable, (IrInstGenPopCount *)instruction);
6291 case IrInstGenIdSwitchBr:
6292 return ir_render_switch_br(g, executable, (IrInstGenSwitchBr *)instruction);
6293 case IrInstGenIdBswap:
6294 return ir_render_bswap(g, executable, (IrInstGenBswap *)instruction);
6295 case IrInstGenIdBitReverse:
6296 return ir_render_bit_reverse(g, executable, (IrInstGenBitReverse *)instruction);
6297 case IrInstGenIdPhi:
6298 return ir_render_phi(g, executable, (IrInstGenPhi *)instruction);
6299 case IrInstGenIdRef:
6300 return ir_render_ref(g, executable, (IrInstGenRef *)instruction);
6301 case IrInstGenIdErrName:
6302 return ir_render_err_name(g, executable, (IrInstGenErrName *)instruction);
6303 case IrInstGenIdCmpxchg:
6304 return ir_render_cmpxchg(g, executable, (IrInstGenCmpxchg *)instruction);
6305 case IrInstGenIdFence:
6306 return ir_render_fence(g, executable, (IrInstGenFence *)instruction);
6307 case IrInstGenIdTruncate:
6308 return ir_render_truncate(g, executable, (IrInstGenTruncate *)instruction);
6309 case IrInstGenIdBoolNot:
6310 return ir_render_bool_not(g, executable, (IrInstGenBoolNot *)instruction);
6311 case IrInstGenIdMemset:
6312 return ir_render_memset(g, executable, (IrInstGenMemset *)instruction);
6313 case IrInstGenIdMemcpy:
6314 return ir_render_memcpy(g, executable, (IrInstGenMemcpy *)instruction);
6315 case IrInstGenIdSlice:
6316 return ir_render_slice(g, executable, (IrInstGenSlice *)instruction);
6317 case IrInstGenIdBreakpoint:
6318 return ir_render_breakpoint(g, executable, (IrInstGenBreakpoint *)instruction);
6319 case IrInstGenIdReturnAddress:
6320 return ir_render_return_address(g, executable, (IrInstGenReturnAddress *)instruction);
6321 case IrInstGenIdFrameAddress:
6322 return ir_render_frame_address(g, executable, (IrInstGenFrameAddress *)instruction);
6323 case IrInstGenIdFrameHandle:
6324 return ir_render_handle(g, executable, (IrInstGenFrameHandle *)instruction);
6325 case IrInstGenIdOverflowOp:
6326 return ir_render_overflow_op(g, executable, (IrInstGenOverflowOp *)instruction);
6327 case IrInstGenIdTestErr:
6328 return ir_render_test_err(g, executable, (IrInstGenTestErr *)instruction);
6329 case IrInstGenIdUnwrapErrCode:
6330 return ir_render_unwrap_err_code(g, executable, (IrInstGenUnwrapErrCode *)instruction);
6331 case IrInstGenIdUnwrapErrPayload:
6332 return ir_render_unwrap_err_payload(g, executable, (IrInstGenUnwrapErrPayload *)instruction);
6333 case IrInstGenIdOptionalWrap:
6334 return ir_render_optional_wrap(g, executable, (IrInstGenOptionalWrap *)instruction);
6335 case IrInstGenIdErrWrapCode:
6336 return ir_render_err_wrap_code(g, executable, (IrInstGenErrWrapCode *)instruction);
6337 case IrInstGenIdErrWrapPayload:
6338 return ir_render_err_wrap_payload(g, executable, (IrInstGenErrWrapPayload *)instruction);
6339 case IrInstGenIdUnionTag:
6340 return ir_render_union_tag(g, executable, (IrInstGenUnionTag *)instruction);
6341 case IrInstGenIdPtrCast:
6342 return ir_render_ptr_cast(g, executable, (IrInstGenPtrCast *)instruction);
6343 case IrInstGenIdBitCast:
6344 return ir_render_bit_cast(g, executable, (IrInstGenBitCast *)instruction);
6345 case IrInstGenIdWidenOrShorten:
6346 return ir_render_widen_or_shorten(g, executable, (IrInstGenWidenOrShorten *)instruction);
6347 case IrInstGenIdPtrToInt:
6348 return ir_render_ptr_to_int(g, executable, (IrInstGenPtrToInt *)instruction);
6349 case IrInstGenIdIntToPtr:
6350 return ir_render_int_to_ptr(g, executable, (IrInstGenIntToPtr *)instruction);
6351 case IrInstGenIdIntToEnum:
6352 return ir_render_int_to_enum(g, executable, (IrInstGenIntToEnum *)instruction);
6353 case IrInstGenIdIntToErr:
6354 return ir_render_int_to_err(g, executable, (IrInstGenIntToErr *)instruction);
6355 case IrInstGenIdErrToInt:
6356 return ir_render_err_to_int(g, executable, (IrInstGenErrToInt *)instruction);
6357 case IrInstGenIdPanic:
6358 return ir_render_panic(g, executable, (IrInstGenPanic *)instruction);
6359 case IrInstGenIdTagName:
6360 return ir_render_enum_tag_name(g, executable, (IrInstGenTagName *)instruction);
6361 case IrInstGenIdFieldParentPtr:
6362 return ir_render_field_parent_ptr(g, executable, (IrInstGenFieldParentPtr *)instruction);
6363 case IrInstGenIdAlignCast:
6364 return ir_render_align_cast(g, executable, (IrInstGenAlignCast *)instruction);
6365 case IrInstGenIdErrorReturnTrace:
6366 return ir_render_error_return_trace(g, executable, (IrInstGenErrorReturnTrace *)instruction);
6367 case IrInstGenIdAtomicRmw:
6368 return ir_render_atomic_rmw(g, executable, (IrInstGenAtomicRmw *)instruction);
6369 case IrInstGenIdAtomicLoad:
6370 return ir_render_atomic_load(g, executable, (IrInstGenAtomicLoad *)instruction);
6371 case IrInstGenIdAtomicStore:
6372 return ir_render_atomic_store(g, executable, (IrInstGenAtomicStore *)instruction);
6373 case IrInstGenIdSaveErrRetAddr:
6374 return ir_render_save_err_ret_addr(g, executable, (IrInstGenSaveErrRetAddr *)instruction);
6375 case IrInstGenIdFloatOp:
6376 return ir_render_float_op(g, executable, (IrInstGenFloatOp *)instruction);
6377 case IrInstGenIdMulAdd:
6378 return ir_render_mul_add(g, executable, (IrInstGenMulAdd *)instruction);
6379 case IrInstGenIdArrayToVector:
6380 return ir_render_array_to_vector(g, executable, (IrInstGenArrayToVector *)instruction);
6381 case IrInstGenIdVectorToArray:
6382 return ir_render_vector_to_array(g, executable, (IrInstGenVectorToArray *)instruction);
6383 case IrInstGenIdAssertZero:
6384 return ir_render_assert_zero(g, executable, (IrInstGenAssertZero *)instruction);
6385 case IrInstGenIdAssertNonNull:
6386 return ir_render_assert_non_null(g, executable, (IrInstGenAssertNonNull *)instruction);
6387 case IrInstGenIdResizeSlice:
6388 return ir_render_resize_slice(g, executable, (IrInstGenResizeSlice *)instruction);
6389 case IrInstGenIdPtrOfArrayToSlice:
6390 return ir_render_ptr_of_array_to_slice(g, executable, (IrInstGenPtrOfArrayToSlice *)instruction);
6391 case IrInstGenIdSuspendBegin:
6392 return ir_render_suspend_begin(g, executable, (IrInstGenSuspendBegin *)instruction);
6393 case IrInstGenIdSuspendFinish:
6394 return ir_render_suspend_finish(g, executable, (IrInstGenSuspendFinish *)instruction);
6395 case IrInstGenIdResume:
6396 return ir_render_resume(g, executable, (IrInstGenResume *)instruction);
6397 case IrInstGenIdFrameSize:
6398 return ir_render_frame_size(g, executable, (IrInstGenFrameSize *)instruction);
6399 case IrInstGenIdAwait:
6400 return ir_render_await(g, executable, (IrInstGenAwait *)instruction);
6401 case IrInstGenIdSpillBegin:
6402 return ir_render_spill_begin(g, executable, (IrInstGenSpillBegin *)instruction);
6403 case IrInstGenIdSpillEnd:
6404 return ir_render_spill_end(g, executable, (IrInstGenSpillEnd *)instruction);
6405 case IrInstGenIdShuffleVector:
6406 return ir_render_shuffle_vector(g, executable, (IrInstGenShuffleVector *) instruction);
6407 case IrInstGenIdSplat:
6408 return ir_render_splat(g, executable, (IrInstGenSplat *) instruction);
6409 case IrInstGenIdVectorExtractElem:
6410 return ir_render_vector_extract_elem(g, executable, (IrInstGenVectorExtractElem *) instruction);
64866411 }
64876412 zig_unreachable();
64886413}
......@@ -6490,21 +6415,21 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
64906415static void ir_render(CodeGen *g, ZigFn *fn_entry) {
64916416 assert(fn_entry);
64926417
6493 IrExecutable *executable = &fn_entry->analyzed_executable;
6418 IrExecutableGen *executable = &fn_entry->analyzed_executable;
64946419 assert(executable->basic_block_list.length > 0);
64956420
64966421 for (size_t block_i = 0; block_i < executable->basic_block_list.length; block_i += 1) {
6497 IrBasicBlock *current_block = executable->basic_block_list.at(block_i);
6422 IrBasicBlockGen *current_block = executable->basic_block_list.at(block_i);
64986423 if (get_scope_typeof(current_block->scope) != nullptr) {
64996424 LLVMBuildBr(g->builder, current_block->llvm_block);
65006425 }
65016426 assert(current_block->llvm_block);
65026427 LLVMPositionBuilderAtEnd(g->builder, current_block->llvm_block);
65036428 for (size_t instr_i = 0; instr_i < current_block->instruction_list.length; instr_i += 1) {
6504 IrInstruction *instruction = current_block->instruction_list.at(instr_i);
6505 if (instruction->ref_count == 0 && !ir_has_side_effects(instruction))
6429 IrInstGen *instruction = current_block->instruction_list.at(instr_i);
6430 if (instruction->base.ref_count == 0 && !ir_inst_gen_has_side_effects(instruction))
65066431 continue;
6507 if (get_scope_typeof(instruction->scope) != nullptr)
6432 if (get_scope_typeof(instruction->base.scope) != nullptr)
65086433 continue;
65096434
65106435 if (!g->strip_debug_symbols) {
......@@ -7396,7 +7321,7 @@ static void generate_error_name_table(CodeGen *g) {
73967321}
73977322
73987323static void build_all_basic_blocks(CodeGen *g, ZigFn *fn) {
7399 IrExecutable *executable = &fn->analyzed_executable;
7324 IrExecutableGen *executable = &fn->analyzed_executable;
74007325 assert(executable->basic_block_list.length > 0);
74017326 LLVMValueRef fn_val = fn_llvm_value(g, fn);
74027327 LLVMBasicBlockRef first_bb = nullptr;
......@@ -7405,7 +7330,7 @@ static void build_all_basic_blocks(CodeGen *g, ZigFn *fn) {
74057330 g->cur_preamble_llvm_block = first_bb;
74067331 }
74077332 for (size_t block_i = 0; block_i < executable->basic_block_list.length; block_i += 1) {
7408 IrBasicBlock *bb = executable->basic_block_list.at(block_i);
7333 IrBasicBlockGen *bb = executable->basic_block_list.at(block_i);
74097334 bb->llvm_block = LLVMAppendBasicBlock(fn_val, bb->name_hint);
74107335 }
74117336 if (first_bb == nullptr) {
......@@ -7638,10 +7563,10 @@ static void do_code_gen(CodeGen *g) {
76387563 if (!is_async) {
76397564 // allocate async frames for noasync calls & awaits to async functions
76407565 ZigType *largest_call_frame_type = nullptr;
7641 IrInstruction *all_calls_alloca = ir_create_alloca(g, &fn_table_entry->fndef_scope->base,
7566 IrInstGen *all_calls_alloca = ir_create_alloca(g, &fn_table_entry->fndef_scope->base,
76427567 fn_table_entry->body_node, fn_table_entry, g->builtin_types.entry_void, "@async_call_frame");
76437568 for (size_t i = 0; i < fn_table_entry->call_list.length; i += 1) {
7644 IrInstructionCallGen *call = fn_table_entry->call_list.at(i);
7569 IrInstGenCall *call = fn_table_entry->call_list.at(i);
76457570 if (call->fn_entry == nullptr)
76467571 continue;
76477572 if (!fn_is_async(call->fn_entry))
......@@ -7663,7 +7588,7 @@ static void do_code_gen(CodeGen *g) {
76637588 }
76647589 // allocate temporary stack data
76657590 for (size_t alloca_i = 0; alloca_i < fn_table_entry->alloca_gen_list.length; alloca_i += 1) {
7666 IrInstructionAllocaGen *instruction = fn_table_entry->alloca_gen_list.at(alloca_i);
7591 IrInstGenAlloca *instruction = fn_table_entry->alloca_gen_list.at(alloca_i);
76677592 ZigType *ptr_type = instruction->base.value->type;
76687593 assert(ptr_type->id == ZigTypeIdPointer);
76697594 ZigType *child_type = ptr_type->data.pointer.child_type;
......@@ -7671,7 +7596,7 @@ static void do_code_gen(CodeGen *g) {
76717596 zig_unreachable();
76727597 if (!type_has_bits(child_type))
76737598 continue;
7674 if (instruction->base.ref_count == 0)
7599 if (instruction->base.base.ref_count == 0)
76757600 continue;
76767601 if (instruction->base.value->special != ConstValSpecialRuntime) {
76777602 if (const_ptr_pointee(nullptr, g, instruction->base.value, nullptr)->special !=
......@@ -7788,7 +7713,7 @@ static void do_code_gen(CodeGen *g) {
77887713 ZigLLVMSetCurrentDebugLocation(g->builder, (int)source_node->line + 1,
77897714 (int)source_node->column + 1, get_di_scope(g, fn_table_entry->child_scope));
77907715 }
7791 IrExecutable *executable = &fn_table_entry->analyzed_executable;
7716 IrExecutableGen *executable = &fn_table_entry->analyzed_executable;
77927717 LLVMBasicBlockRef bad_resume_block = LLVMAppendBasicBlock(g->cur_fn_val, "BadResume");
77937718 LLVMPositionBuilderAtEnd(g->builder, bad_resume_block);
77947719 gen_assertion_scope(g, PanicMsgIdBadResume, fn_table_entry->child_scope);
......@@ -7815,7 +7740,7 @@ static void do_code_gen(CodeGen *g) {
78157740 g->cur_async_switch_instr = switch_instr;
78167741
78177742 LLVMValueRef zero = LLVMConstNull(usize_type_ref);
7818 IrBasicBlock *entry_block = executable->basic_block_list.at(0);
7743 IrBasicBlockGen *entry_block = executable->basic_block_list.at(0);
78197744 LLVMAddCase(switch_instr, zero, entry_block->llvm_block);
78207745 g->cur_resume_block_count += 1;
78217746
......@@ -7847,7 +7772,7 @@ static void do_code_gen(CodeGen *g) {
78477772
78487773 gen_init_stack_trace(g, trace_field_ptr, addrs_field_ptr);
78497774 }
7850 render_async_var_decls(g, entry_block->instruction_list.at(0)->scope);
7775 render_async_var_decls(g, entry_block->instruction_list.at(0)->base.scope);
78517776 } else {
78527777 // create debug variable declarations for parameters
78537778 // rely on the first variables in the variable_list being parameters.
......@@ -7936,6 +7861,12 @@ static void zig_llvm_emit_output(CodeGen *g) {
79367861 default:
79377862 zig_unreachable();
79387863 }
7864 LLVMDisposeModule(g->module);
7865 g->module = nullptr;
7866 LLVMDisposeTargetData(g->target_data_ref);
7867 g->target_data_ref = nullptr;
7868 LLVMDisposeTargetMachine(g->target_machine);
7869 g->target_machine = nullptr;
79397870}
79407871
79417872struct CIntTypeInfo {
......@@ -8846,15 +8777,17 @@ static void init(CodeGen *g) {
88468777 define_builtin_types(g);
88478778 define_intern_values(g);
88488779
8849 IrInstruction *sentinel_instructions = allocate<IrInstruction>(2);
8850 g->invalid_instruction = &sentinel_instructions[0];
8851 g->invalid_instruction->value = allocate<ZigValue>(1, "ZigValue");
8852 g->invalid_instruction->value->type = g->builtin_types.entry_invalid;
8780 IrInstGen *sentinel_instructions = allocate<IrInstGen>(2);
8781 g->invalid_inst_gen = &sentinel_instructions[0];
8782 g->invalid_inst_gen->value = allocate<ZigValue>(1, "ZigValue");
8783 g->invalid_inst_gen->value->type = g->builtin_types.entry_invalid;
88538784
88548785 g->unreach_instruction = &sentinel_instructions[1];
88558786 g->unreach_instruction->value = allocate<ZigValue>(1, "ZigValue");
88568787 g->unreach_instruction->value->type = g->builtin_types.entry_unreachable;
88578788
8789 g->invalid_inst_src = allocate<IrInstSrc>(1);
8790
88588791 define_builtin_fns(g);
88598792 Error err;
88608793 if ((err = define_builtin_compile_vars(g))) {
......@@ -8996,7 +8929,10 @@ static void detect_libc(CodeGen *g) {
89968929 "See `zig libc --help` for more details.\n", err_str(err));
89978930 exit(1);
89988931 }
8999 if ((err = os_make_path(g->cache_dir))) {
8932 Buf libc_txt_dir = BUF_INIT;
8933 os_path_dirname(libc_txt, &libc_txt_dir);
8934 buf_deinit(&libc_txt_dir);
8935 if ((err = os_make_path(&libc_txt_dir))) {
90008936 fprintf(stderr, "Unable to create %s directory: %s\n",
90018937 buf_ptr(g->cache_dir), err_str(err));
90028938 exit(1);
......@@ -9788,6 +9724,7 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, ZigType *type_e
97889724 zig_unreachable();
97899725 case ZigTypeIdVoid:
97909726 case ZigTypeIdUnreachable:
9727 return;
97919728 case ZigTypeIdBool:
97929729 g->c_want_stdbool = true;
97939730 return;
src/ir.cpp+7219-6358
......@@ -21,25 +21,31 @@ struct IrExecContext {
2121 ZigList<ZigValue *> mem_slot_list;
2222};
2323
24struct IrBuilder {
24struct IrBuilderSrc {
2525 CodeGen *codegen;
26 IrExecutable *exec;
27 IrBasicBlock *current_basic_block;
26 IrExecutableSrc *exec;
27 IrBasicBlockSrc *current_basic_block;
2828 AstNode *main_block_node;
2929};
3030
31struct IrBuilderGen {
32 CodeGen *codegen;
33 IrExecutableGen *exec;
34 IrBasicBlockGen *current_basic_block;
35};
36
3137struct IrAnalyze {
3238 CodeGen *codegen;
33 IrBuilder old_irb;
34 IrBuilder new_irb;
39 IrBuilderSrc old_irb;
40 IrBuilderGen new_irb;
3541 IrExecContext exec_context;
3642 size_t old_bb_index;
3743 size_t instruction_index;
3844 ZigType *explicit_return_type;
3945 AstNode *explicit_return_type_source_node;
40 ZigList<IrInstruction *> src_implicit_return_type_list;
46 ZigList<IrInstGen *> src_implicit_return_type_list;
4147 ZigList<IrSuspendPosition> resume_stack;
42 IrBasicBlock *const_predecessor_bb;
48 IrBasicBlockSrc *const_predecessor_bb;
4349 size_t ref_count;
4450 size_t break_debug_id; // for debugging purposes
4551
......@@ -206,412 +212,538 @@ struct DbgIrBreakPoint {
206212DbgIrBreakPoint dbg_ir_breakpoints_buf[20];
207213size_t dbg_ir_breakpoints_count = 0;
208214
209static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope);
210static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval,
215static IrInstSrc *ir_gen_node(IrBuilderSrc *irb, AstNode *node, Scope *scope);
216static IrInstSrc *ir_gen_node_extra(IrBuilderSrc *irb, AstNode *node, Scope *scope, LVal lval,
211217 ResultLoc *result_loc);
212static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type);
213static IrInstruction *ir_implicit_cast2(IrAnalyze *ira, IrInstruction *value_source_instr,
214 IrInstruction *value, ZigType *expected_type);
215static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr,
218static IrInstGen *ir_implicit_cast(IrAnalyze *ira, IrInstGen *value, ZigType *expected_type);
219static IrInstGen *ir_implicit_cast2(IrAnalyze *ira, IrInst *value_source_instr,
220 IrInstGen *value, ZigType *expected_type);
221static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst *source_instr, IrInstGen *ptr,
216222 ResultLoc *result_loc);
217static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg);
218static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,
219 IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type, bool initializing);
220static void ir_assert(bool ok, IrInstruction *source_instruction);
221static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, ZigVar *var);
222static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op);
223static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval, ResultLoc *result_loc);
224static IrInstruction *ir_expr_wrap(IrBuilder *irb, Scope *scope, IrInstruction *inst, ResultLoc *result_loc);
223static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutableSrc *exec, AstNode *source_node, Buf *msg);
224static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,
225 IrInst* source_instr, IrInstGen *container_ptr, ZigType *container_type, bool initializing);
226static void ir_assert(bool ok, IrInst* source_instruction);
227static void ir_assert_gen(bool ok, IrInstGen *source_instruction);
228static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, IrInst *source_instr, ZigVar *var);
229static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op);
230static IrInstSrc *ir_lval_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *value, LVal lval, ResultLoc *result_loc);
231static IrInstSrc *ir_expr_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *inst, ResultLoc *result_loc);
225232static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align);
226233static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new_align);
227234static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf, ZigValue *val);
228235static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ZigValue *val);
229236static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,
230237 ZigValue *out_val, ZigValue *ptr_val);
231static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *ptr,
232 ZigType *dest_type, IrInstruction *dest_type_src, bool safety_check_on);
233static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed);
238static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *ptr,
239 ZigType *dest_type, IrInst *dest_type_src, bool safety_check_on);
240static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstGen *value, UndefAllowed undef_allowed);
234241static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align);
235static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
242static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target,
236243 ZigType *ptr_type);
237static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
244static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value,
238245 ZigType *dest_type);
239static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr,
240 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime,
246static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_instr,
247 ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime,
241248 bool non_null_comptime, bool allow_discard);
242static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_source_instr,
243 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime,
249static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr,
250 ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime,
244251 bool non_null_comptime, bool allow_discard);
245static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstruction *source_instr,
246 IrInstruction *base_ptr, bool safety_check_on, bool initializing);
247static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruction *source_instr,
248 IrInstruction *base_ptr, bool safety_check_on, bool initializing);
249static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *source_instr,
250 IrInstruction *base_ptr, bool initializing);
251static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source_instr,
252 IrInstruction *ptr, IrInstruction *uncasted_value, bool allow_write_through_const);
253static IrInstruction *ir_gen_union_init_expr(IrBuilder *irb, Scope *scope, AstNode *source_node,
254 IrInstruction *union_type, IrInstruction *field_name, AstNode *expr_node,
252static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* source_instr,
253 IrInstGen *base_ptr, bool safety_check_on, bool initializing);
254static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source_instr,
255 IrInstGen *base_ptr, bool safety_check_on, bool initializing);
256static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_instr,
257 IrInstGen *base_ptr, bool initializing);
258static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr,
259 IrInstGen *ptr, IrInstGen *uncasted_value, bool allow_write_through_const);
260static IrInstSrc *ir_gen_union_init_expr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
261 IrInstSrc *union_type, IrInstSrc *field_name, AstNode *expr_node,
255262 LVal lval, ResultLoc *parent_result_loc);
256263static void ir_reset_result(ResultLoc *result_loc);
257static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char *kind_name,
264static Buf *get_anon_type_name(CodeGen *codegen, IrExecutableSrc *exec, const char *kind_name,
258265 Scope *scope, AstNode *source_node, Buf *out_bare_name);
259static ResultLocCast *ir_build_cast_result_loc(IrBuilder *irb, IrInstruction *dest_type,
266static ResultLocCast *ir_build_cast_result_loc(IrBuilderSrc *irb, IrInstSrc *dest_type,
260267 ResultLoc *parent_result_loc);
261static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction *source_instr,
262 TypeStructField *field, IrInstruction *struct_ptr, ZigType *struct_type, bool initializing);
263static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,
264 IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type);
268static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_instr,
269 TypeStructField *field, IrInstGen *struct_ptr, ZigType *struct_type, bool initializing);
270static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,
271 IrInst* source_instr, IrInstGen *container_ptr, ZigType *container_type);
265272static ResultLoc *no_result_loc(void);
266static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *source_inst, IrInstruction *value);
273static IrInstGen *ir_analyze_test_non_null(IrAnalyze *ira, IrInst *source_inst, IrInstGen *value);
274
275static void destroy_instruction_src(IrInstSrc *inst) {
276#ifdef ZIG_ENABLE_MEM_PROFILE
277 const char *name = ir_inst_src_type_str(inst->id);
278#else
279 const char *name = nullptr;
280#endif
281 switch (inst->id) {
282 case IrInstSrcIdInvalid:
283 zig_unreachable();
284 case IrInstSrcIdReturn:
285 return destroy(reinterpret_cast<IrInstSrcReturn *>(inst), name);
286 case IrInstSrcIdConst:
287 return destroy(reinterpret_cast<IrInstSrcConst *>(inst), name);
288 case IrInstSrcIdBinOp:
289 return destroy(reinterpret_cast<IrInstSrcBinOp *>(inst), name);
290 case IrInstSrcIdMergeErrSets:
291 return destroy(reinterpret_cast<IrInstSrcMergeErrSets *>(inst), name);
292 case IrInstSrcIdDeclVar:
293 return destroy(reinterpret_cast<IrInstSrcDeclVar *>(inst), name);
294 case IrInstSrcIdCall:
295 return destroy(reinterpret_cast<IrInstSrcCall *>(inst), name);
296 case IrInstSrcIdCallExtra:
297 return destroy(reinterpret_cast<IrInstSrcCallExtra *>(inst), name);
298 case IrInstSrcIdUnOp:
299 return destroy(reinterpret_cast<IrInstSrcUnOp *>(inst), name);
300 case IrInstSrcIdCondBr:
301 return destroy(reinterpret_cast<IrInstSrcCondBr *>(inst), name);
302 case IrInstSrcIdBr:
303 return destroy(reinterpret_cast<IrInstSrcBr *>(inst), name);
304 case IrInstSrcIdPhi:
305 return destroy(reinterpret_cast<IrInstSrcPhi *>(inst), name);
306 case IrInstSrcIdContainerInitList:
307 return destroy(reinterpret_cast<IrInstSrcContainerInitList *>(inst), name);
308 case IrInstSrcIdContainerInitFields:
309 return destroy(reinterpret_cast<IrInstSrcContainerInitFields *>(inst), name);
310 case IrInstSrcIdUnreachable:
311 return destroy(reinterpret_cast<IrInstSrcUnreachable *>(inst), name);
312 case IrInstSrcIdElemPtr:
313 return destroy(reinterpret_cast<IrInstSrcElemPtr *>(inst), name);
314 case IrInstSrcIdVarPtr:
315 return destroy(reinterpret_cast<IrInstSrcVarPtr *>(inst), name);
316 case IrInstSrcIdLoadPtr:
317 return destroy(reinterpret_cast<IrInstSrcLoadPtr *>(inst), name);
318 case IrInstSrcIdStorePtr:
319 return destroy(reinterpret_cast<IrInstSrcStorePtr *>(inst), name);
320 case IrInstSrcIdTypeOf:
321 return destroy(reinterpret_cast<IrInstSrcTypeOf *>(inst), name);
322 case IrInstSrcIdFieldPtr:
323 return destroy(reinterpret_cast<IrInstSrcFieldPtr *>(inst), name);
324 case IrInstSrcIdSetCold:
325 return destroy(reinterpret_cast<IrInstSrcSetCold *>(inst), name);
326 case IrInstSrcIdSetRuntimeSafety:
327 return destroy(reinterpret_cast<IrInstSrcSetRuntimeSafety *>(inst), name);
328 case IrInstSrcIdSetFloatMode:
329 return destroy(reinterpret_cast<IrInstSrcSetFloatMode *>(inst), name);
330 case IrInstSrcIdArrayType:
331 return destroy(reinterpret_cast<IrInstSrcArrayType *>(inst), name);
332 case IrInstSrcIdSliceType:
333 return destroy(reinterpret_cast<IrInstSrcSliceType *>(inst), name);
334 case IrInstSrcIdAnyFrameType:
335 return destroy(reinterpret_cast<IrInstSrcAnyFrameType *>(inst), name);
336 case IrInstSrcIdAsm:
337 return destroy(reinterpret_cast<IrInstSrcAsm *>(inst), name);
338 case IrInstSrcIdSizeOf:
339 return destroy(reinterpret_cast<IrInstSrcSizeOf *>(inst), name);
340 case IrInstSrcIdTestNonNull:
341 return destroy(reinterpret_cast<IrInstSrcTestNonNull *>(inst), name);
342 case IrInstSrcIdOptionalUnwrapPtr:
343 return destroy(reinterpret_cast<IrInstSrcOptionalUnwrapPtr *>(inst), name);
344 case IrInstSrcIdPopCount:
345 return destroy(reinterpret_cast<IrInstSrcPopCount *>(inst), name);
346 case IrInstSrcIdClz:
347 return destroy(reinterpret_cast<IrInstSrcClz *>(inst), name);
348 case IrInstSrcIdCtz:
349 return destroy(reinterpret_cast<IrInstSrcCtz *>(inst), name);
350 case IrInstSrcIdBswap:
351 return destroy(reinterpret_cast<IrInstSrcBswap *>(inst), name);
352 case IrInstSrcIdBitReverse:
353 return destroy(reinterpret_cast<IrInstSrcBitReverse *>(inst), name);
354 case IrInstSrcIdSwitchBr:
355 return destroy(reinterpret_cast<IrInstSrcSwitchBr *>(inst), name);
356 case IrInstSrcIdSwitchVar:
357 return destroy(reinterpret_cast<IrInstSrcSwitchVar *>(inst), name);
358 case IrInstSrcIdSwitchElseVar:
359 return destroy(reinterpret_cast<IrInstSrcSwitchElseVar *>(inst), name);
360 case IrInstSrcIdSwitchTarget:
361 return destroy(reinterpret_cast<IrInstSrcSwitchTarget *>(inst), name);
362 case IrInstSrcIdImport:
363 return destroy(reinterpret_cast<IrInstSrcImport *>(inst), name);
364 case IrInstSrcIdRef:
365 return destroy(reinterpret_cast<IrInstSrcRef *>(inst), name);
366 case IrInstSrcIdCompileErr:
367 return destroy(reinterpret_cast<IrInstSrcCompileErr *>(inst), name);
368 case IrInstSrcIdCompileLog:
369 return destroy(reinterpret_cast<IrInstSrcCompileLog *>(inst), name);
370 case IrInstSrcIdErrName:
371 return destroy(reinterpret_cast<IrInstSrcErrName *>(inst), name);
372 case IrInstSrcIdCImport:
373 return destroy(reinterpret_cast<IrInstSrcCImport *>(inst), name);
374 case IrInstSrcIdCInclude:
375 return destroy(reinterpret_cast<IrInstSrcCInclude *>(inst), name);
376 case IrInstSrcIdCDefine:
377 return destroy(reinterpret_cast<IrInstSrcCDefine *>(inst), name);
378 case IrInstSrcIdCUndef:
379 return destroy(reinterpret_cast<IrInstSrcCUndef *>(inst), name);
380 case IrInstSrcIdEmbedFile:
381 return destroy(reinterpret_cast<IrInstSrcEmbedFile *>(inst), name);
382 case IrInstSrcIdCmpxchg:
383 return destroy(reinterpret_cast<IrInstSrcCmpxchg *>(inst), name);
384 case IrInstSrcIdFence:
385 return destroy(reinterpret_cast<IrInstSrcFence *>(inst), name);
386 case IrInstSrcIdTruncate:
387 return destroy(reinterpret_cast<IrInstSrcTruncate *>(inst), name);
388 case IrInstSrcIdIntCast:
389 return destroy(reinterpret_cast<IrInstSrcIntCast *>(inst), name);
390 case IrInstSrcIdFloatCast:
391 return destroy(reinterpret_cast<IrInstSrcFloatCast *>(inst), name);
392 case IrInstSrcIdErrSetCast:
393 return destroy(reinterpret_cast<IrInstSrcErrSetCast *>(inst), name);
394 case IrInstSrcIdFromBytes:
395 return destroy(reinterpret_cast<IrInstSrcFromBytes *>(inst), name);
396 case IrInstSrcIdToBytes:
397 return destroy(reinterpret_cast<IrInstSrcToBytes *>(inst), name);
398 case IrInstSrcIdIntToFloat:
399 return destroy(reinterpret_cast<IrInstSrcIntToFloat *>(inst), name);
400 case IrInstSrcIdFloatToInt:
401 return destroy(reinterpret_cast<IrInstSrcFloatToInt *>(inst), name);
402 case IrInstSrcIdBoolToInt:
403 return destroy(reinterpret_cast<IrInstSrcBoolToInt *>(inst), name);
404 case IrInstSrcIdIntType:
405 return destroy(reinterpret_cast<IrInstSrcIntType *>(inst), name);
406 case IrInstSrcIdVectorType:
407 return destroy(reinterpret_cast<IrInstSrcVectorType *>(inst), name);
408 case IrInstSrcIdShuffleVector:
409 return destroy(reinterpret_cast<IrInstSrcShuffleVector *>(inst), name);
410 case IrInstSrcIdSplat:
411 return destroy(reinterpret_cast<IrInstSrcSplat *>(inst), name);
412 case IrInstSrcIdBoolNot:
413 return destroy(reinterpret_cast<IrInstSrcBoolNot *>(inst), name);
414 case IrInstSrcIdMemset:
415 return destroy(reinterpret_cast<IrInstSrcMemset *>(inst), name);
416 case IrInstSrcIdMemcpy:
417 return destroy(reinterpret_cast<IrInstSrcMemcpy *>(inst), name);
418 case IrInstSrcIdSlice:
419 return destroy(reinterpret_cast<IrInstSrcSlice *>(inst), name);
420 case IrInstSrcIdMemberCount:
421 return destroy(reinterpret_cast<IrInstSrcMemberCount *>(inst), name);
422 case IrInstSrcIdMemberType:
423 return destroy(reinterpret_cast<IrInstSrcMemberType *>(inst), name);
424 case IrInstSrcIdMemberName:
425 return destroy(reinterpret_cast<IrInstSrcMemberName *>(inst), name);
426 case IrInstSrcIdBreakpoint:
427 return destroy(reinterpret_cast<IrInstSrcBreakpoint *>(inst), name);
428 case IrInstSrcIdReturnAddress:
429 return destroy(reinterpret_cast<IrInstSrcReturnAddress *>(inst), name);
430 case IrInstSrcIdFrameAddress:
431 return destroy(reinterpret_cast<IrInstSrcFrameAddress *>(inst), name);
432 case IrInstSrcIdFrameHandle:
433 return destroy(reinterpret_cast<IrInstSrcFrameHandle *>(inst), name);
434 case IrInstSrcIdFrameType:
435 return destroy(reinterpret_cast<IrInstSrcFrameType *>(inst), name);
436 case IrInstSrcIdFrameSize:
437 return destroy(reinterpret_cast<IrInstSrcFrameSize *>(inst), name);
438 case IrInstSrcIdAlignOf:
439 return destroy(reinterpret_cast<IrInstSrcAlignOf *>(inst), name);
440 case IrInstSrcIdOverflowOp:
441 return destroy(reinterpret_cast<IrInstSrcOverflowOp *>(inst), name);
442 case IrInstSrcIdTestErr:
443 return destroy(reinterpret_cast<IrInstSrcTestErr *>(inst), name);
444 case IrInstSrcIdUnwrapErrCode:
445 return destroy(reinterpret_cast<IrInstSrcUnwrapErrCode *>(inst), name);
446 case IrInstSrcIdUnwrapErrPayload:
447 return destroy(reinterpret_cast<IrInstSrcUnwrapErrPayload *>(inst), name);
448 case IrInstSrcIdFnProto:
449 return destroy(reinterpret_cast<IrInstSrcFnProto *>(inst), name);
450 case IrInstSrcIdTestComptime:
451 return destroy(reinterpret_cast<IrInstSrcTestComptime *>(inst), name);
452 case IrInstSrcIdPtrCast:
453 return destroy(reinterpret_cast<IrInstSrcPtrCast *>(inst), name);
454 case IrInstSrcIdBitCast:
455 return destroy(reinterpret_cast<IrInstSrcBitCast *>(inst), name);
456 case IrInstSrcIdPtrToInt:
457 return destroy(reinterpret_cast<IrInstSrcPtrToInt *>(inst), name);
458 case IrInstSrcIdIntToPtr:
459 return destroy(reinterpret_cast<IrInstSrcIntToPtr *>(inst), name);
460 case IrInstSrcIdIntToEnum:
461 return destroy(reinterpret_cast<IrInstSrcIntToEnum *>(inst), name);
462 case IrInstSrcIdIntToErr:
463 return destroy(reinterpret_cast<IrInstSrcIntToErr *>(inst), name);
464 case IrInstSrcIdErrToInt:
465 return destroy(reinterpret_cast<IrInstSrcErrToInt *>(inst), name);
466 case IrInstSrcIdCheckSwitchProngs:
467 return destroy(reinterpret_cast<IrInstSrcCheckSwitchProngs *>(inst), name);
468 case IrInstSrcIdCheckStatementIsVoid:
469 return destroy(reinterpret_cast<IrInstSrcCheckStatementIsVoid *>(inst), name);
470 case IrInstSrcIdTypeName:
471 return destroy(reinterpret_cast<IrInstSrcTypeName *>(inst), name);
472 case IrInstSrcIdTagName:
473 return destroy(reinterpret_cast<IrInstSrcTagName *>(inst), name);
474 case IrInstSrcIdPtrType:
475 return destroy(reinterpret_cast<IrInstSrcPtrType *>(inst), name);
476 case IrInstSrcIdDeclRef:
477 return destroy(reinterpret_cast<IrInstSrcDeclRef *>(inst), name);
478 case IrInstSrcIdPanic:
479 return destroy(reinterpret_cast<IrInstSrcPanic *>(inst), name);
480 case IrInstSrcIdFieldParentPtr:
481 return destroy(reinterpret_cast<IrInstSrcFieldParentPtr *>(inst), name);
482 case IrInstSrcIdByteOffsetOf:
483 return destroy(reinterpret_cast<IrInstSrcByteOffsetOf *>(inst), name);
484 case IrInstSrcIdBitOffsetOf:
485 return destroy(reinterpret_cast<IrInstSrcBitOffsetOf *>(inst), name);
486 case IrInstSrcIdTypeInfo:
487 return destroy(reinterpret_cast<IrInstSrcTypeInfo *>(inst), name);
488 case IrInstSrcIdType:
489 return destroy(reinterpret_cast<IrInstSrcType *>(inst), name);
490 case IrInstSrcIdHasField:
491 return destroy(reinterpret_cast<IrInstSrcHasField *>(inst), name);
492 case IrInstSrcIdTypeId:
493 return destroy(reinterpret_cast<IrInstSrcTypeId *>(inst), name);
494 case IrInstSrcIdSetEvalBranchQuota:
495 return destroy(reinterpret_cast<IrInstSrcSetEvalBranchQuota *>(inst), name);
496 case IrInstSrcIdAlignCast:
497 return destroy(reinterpret_cast<IrInstSrcAlignCast *>(inst), name);
498 case IrInstSrcIdImplicitCast:
499 return destroy(reinterpret_cast<IrInstSrcImplicitCast *>(inst), name);
500 case IrInstSrcIdResolveResult:
501 return destroy(reinterpret_cast<IrInstSrcResolveResult *>(inst), name);
502 case IrInstSrcIdResetResult:
503 return destroy(reinterpret_cast<IrInstSrcResetResult *>(inst), name);
504 case IrInstSrcIdOpaqueType:
505 return destroy(reinterpret_cast<IrInstSrcOpaqueType *>(inst), name);
506 case IrInstSrcIdSetAlignStack:
507 return destroy(reinterpret_cast<IrInstSrcSetAlignStack *>(inst), name);
508 case IrInstSrcIdArgType:
509 return destroy(reinterpret_cast<IrInstSrcArgType *>(inst), name);
510 case IrInstSrcIdTagType:
511 return destroy(reinterpret_cast<IrInstSrcTagType *>(inst), name);
512 case IrInstSrcIdExport:
513 return destroy(reinterpret_cast<IrInstSrcExport *>(inst), name);
514 case IrInstSrcIdErrorReturnTrace:
515 return destroy(reinterpret_cast<IrInstSrcErrorReturnTrace *>(inst), name);
516 case IrInstSrcIdErrorUnion:
517 return destroy(reinterpret_cast<IrInstSrcErrorUnion *>(inst), name);
518 case IrInstSrcIdAtomicRmw:
519 return destroy(reinterpret_cast<IrInstSrcAtomicRmw *>(inst), name);
520 case IrInstSrcIdSaveErrRetAddr:
521 return destroy(reinterpret_cast<IrInstSrcSaveErrRetAddr *>(inst), name);
522 case IrInstSrcIdAddImplicitReturnType:
523 return destroy(reinterpret_cast<IrInstSrcAddImplicitReturnType *>(inst), name);
524 case IrInstSrcIdFloatOp:
525 return destroy(reinterpret_cast<IrInstSrcFloatOp *>(inst), name);
526 case IrInstSrcIdMulAdd:
527 return destroy(reinterpret_cast<IrInstSrcMulAdd *>(inst), name);
528 case IrInstSrcIdAtomicLoad:
529 return destroy(reinterpret_cast<IrInstSrcAtomicLoad *>(inst), name);
530 case IrInstSrcIdAtomicStore:
531 return destroy(reinterpret_cast<IrInstSrcAtomicStore *>(inst), name);
532 case IrInstSrcIdEnumToInt:
533 return destroy(reinterpret_cast<IrInstSrcEnumToInt *>(inst), name);
534 case IrInstSrcIdCheckRuntimeScope:
535 return destroy(reinterpret_cast<IrInstSrcCheckRuntimeScope *>(inst), name);
536 case IrInstSrcIdHasDecl:
537 return destroy(reinterpret_cast<IrInstSrcHasDecl *>(inst), name);
538 case IrInstSrcIdUndeclaredIdent:
539 return destroy(reinterpret_cast<IrInstSrcUndeclaredIdent *>(inst), name);
540 case IrInstSrcIdAlloca:
541 return destroy(reinterpret_cast<IrInstSrcAlloca *>(inst), name);
542 case IrInstSrcIdEndExpr:
543 return destroy(reinterpret_cast<IrInstSrcEndExpr *>(inst), name);
544 case IrInstSrcIdUnionInitNamedField:
545 return destroy(reinterpret_cast<IrInstSrcUnionInitNamedField *>(inst), name);
546 case IrInstSrcIdSuspendBegin:
547 return destroy(reinterpret_cast<IrInstSrcSuspendBegin *>(inst), name);
548 case IrInstSrcIdSuspendFinish:
549 return destroy(reinterpret_cast<IrInstSrcSuspendFinish *>(inst), name);
550 case IrInstSrcIdResume:
551 return destroy(reinterpret_cast<IrInstSrcResume *>(inst), name);
552 case IrInstSrcIdAwait:
553 return destroy(reinterpret_cast<IrInstSrcAwait *>(inst), name);
554 case IrInstSrcIdSpillBegin:
555 return destroy(reinterpret_cast<IrInstSrcSpillBegin *>(inst), name);
556 case IrInstSrcIdSpillEnd:
557 return destroy(reinterpret_cast<IrInstSrcSpillEnd *>(inst), name);
558 case IrInstSrcIdCallArgs:
559 return destroy(reinterpret_cast<IrInstSrcCallArgs *>(inst), name);
560 }
561 zig_unreachable();
562}
267563
268static void destroy_instruction(IrInstruction *inst) {
564void destroy_instruction_gen(IrInstGen *inst) {
269565#ifdef ZIG_ENABLE_MEM_PROFILE
270 const char *name = ir_instruction_type_str(inst->id);
566 const char *name = ir_inst_gen_type_str(inst->id);
271567#else
272568 const char *name = nullptr;
273569#endif
274570 switch (inst->id) {
275 case IrInstructionIdInvalid:
571 case IrInstGenIdInvalid:
276572 zig_unreachable();
277 case IrInstructionIdReturn:
278 return destroy(reinterpret_cast<IrInstructionReturn *>(inst), name);
279 case IrInstructionIdConst:
280 return destroy(reinterpret_cast<IrInstructionConst *>(inst), name);
281 case IrInstructionIdBinOp:
282 return destroy(reinterpret_cast<IrInstructionBinOp *>(inst), name);
283 case IrInstructionIdMergeErrSets:
284 return destroy(reinterpret_cast<IrInstructionMergeErrSets *>(inst), name);
285 case IrInstructionIdDeclVarSrc:
286 return destroy(reinterpret_cast<IrInstructionDeclVarSrc *>(inst), name);
287 case IrInstructionIdCast:
288 return destroy(reinterpret_cast<IrInstructionCast *>(inst), name);
289 case IrInstructionIdCallSrc:
290 return destroy(reinterpret_cast<IrInstructionCallSrc *>(inst), name);
291 case IrInstructionIdCallSrcArgs:
292 return destroy(reinterpret_cast<IrInstructionCallSrcArgs *>(inst), name);
293 case IrInstructionIdCallExtra:
294 return destroy(reinterpret_cast<IrInstructionCallExtra *>(inst), name);
295 case IrInstructionIdCallGen:
296 return destroy(reinterpret_cast<IrInstructionCallGen *>(inst), name);
297 case IrInstructionIdUnOp:
298 return destroy(reinterpret_cast<IrInstructionUnOp *>(inst), name);
299 case IrInstructionIdCondBr:
300 return destroy(reinterpret_cast<IrInstructionCondBr *>(inst), name);
301 case IrInstructionIdBr:
302 return destroy(reinterpret_cast<IrInstructionBr *>(inst), name);
303 case IrInstructionIdPhi:
304 return destroy(reinterpret_cast<IrInstructionPhi *>(inst), name);
305 case IrInstructionIdContainerInitList:
306 return destroy(reinterpret_cast<IrInstructionContainerInitList *>(inst), name);
307 case IrInstructionIdContainerInitFields:
308 return destroy(reinterpret_cast<IrInstructionContainerInitFields *>(inst), name);
309 case IrInstructionIdUnreachable:
310 return destroy(reinterpret_cast<IrInstructionUnreachable *>(inst), name);
311 case IrInstructionIdElemPtr:
312 return destroy(reinterpret_cast<IrInstructionElemPtr *>(inst), name);
313 case IrInstructionIdVarPtr:
314 return destroy(reinterpret_cast<IrInstructionVarPtr *>(inst), name);
315 case IrInstructionIdReturnPtr:
316 return destroy(reinterpret_cast<IrInstructionReturnPtr *>(inst), name);
317 case IrInstructionIdLoadPtr:
318 return destroy(reinterpret_cast<IrInstructionLoadPtr *>(inst), name);
319 case IrInstructionIdLoadPtrGen:
320 return destroy(reinterpret_cast<IrInstructionLoadPtrGen *>(inst), name);
321 case IrInstructionIdStorePtr:
322 return destroy(reinterpret_cast<IrInstructionStorePtr *>(inst), name);
323 case IrInstructionIdVectorStoreElem:
324 return destroy(reinterpret_cast<IrInstructionVectorStoreElem *>(inst), name);
325 case IrInstructionIdTypeOf:
326 return destroy(reinterpret_cast<IrInstructionTypeOf *>(inst), name);
327 case IrInstructionIdFieldPtr:
328 return destroy(reinterpret_cast<IrInstructionFieldPtr *>(inst), name);
329 case IrInstructionIdStructFieldPtr:
330 return destroy(reinterpret_cast<IrInstructionStructFieldPtr *>(inst), name);
331 case IrInstructionIdUnionFieldPtr:
332 return destroy(reinterpret_cast<IrInstructionUnionFieldPtr *>(inst), name);
333 case IrInstructionIdSetCold:
334 return destroy(reinterpret_cast<IrInstructionSetCold *>(inst), name);
335 case IrInstructionIdSetRuntimeSafety:
336 return destroy(reinterpret_cast<IrInstructionSetRuntimeSafety *>(inst), name);
337 case IrInstructionIdSetFloatMode:
338 return destroy(reinterpret_cast<IrInstructionSetFloatMode *>(inst), name);
339 case IrInstructionIdArrayType:
340 return destroy(reinterpret_cast<IrInstructionArrayType *>(inst), name);
341 case IrInstructionIdSliceType:
342 return destroy(reinterpret_cast<IrInstructionSliceType *>(inst), name);
343 case IrInstructionIdAnyFrameType:
344 return destroy(reinterpret_cast<IrInstructionAnyFrameType *>(inst), name);
345 case IrInstructionIdAsmSrc:
346 return destroy(reinterpret_cast<IrInstructionAsmSrc *>(inst), name);
347 case IrInstructionIdAsmGen:
348 return destroy(reinterpret_cast<IrInstructionAsmGen *>(inst), name);
349 case IrInstructionIdSizeOf:
350 return destroy(reinterpret_cast<IrInstructionSizeOf *>(inst), name);
351 case IrInstructionIdTestNonNull:
352 return destroy(reinterpret_cast<IrInstructionTestNonNull *>(inst), name);
353 case IrInstructionIdOptionalUnwrapPtr:
354 return destroy(reinterpret_cast<IrInstructionOptionalUnwrapPtr *>(inst), name);
355 case IrInstructionIdPopCount:
356 return destroy(reinterpret_cast<IrInstructionPopCount *>(inst), name);
357 case IrInstructionIdClz:
358 return destroy(reinterpret_cast<IrInstructionClz *>(inst), name);
359 case IrInstructionIdCtz:
360 return destroy(reinterpret_cast<IrInstructionCtz *>(inst), name);
361 case IrInstructionIdBswap:
362 return destroy(reinterpret_cast<IrInstructionBswap *>(inst), name);
363 case IrInstructionIdBitReverse:
364 return destroy(reinterpret_cast<IrInstructionBitReverse *>(inst), name);
365 case IrInstructionIdSwitchBr:
366 return destroy(reinterpret_cast<IrInstructionSwitchBr *>(inst), name);
367 case IrInstructionIdSwitchVar:
368 return destroy(reinterpret_cast<IrInstructionSwitchVar *>(inst), name);
369 case IrInstructionIdSwitchElseVar:
370 return destroy(reinterpret_cast<IrInstructionSwitchElseVar *>(inst), name);
371 case IrInstructionIdSwitchTarget:
372 return destroy(reinterpret_cast<IrInstructionSwitchTarget *>(inst), name);
373 case IrInstructionIdUnionTag:
374 return destroy(reinterpret_cast<IrInstructionUnionTag *>(inst), name);
375 case IrInstructionIdImport:
376 return destroy(reinterpret_cast<IrInstructionImport *>(inst), name);
377 case IrInstructionIdRef:
378 return destroy(reinterpret_cast<IrInstructionRef *>(inst), name);
379 case IrInstructionIdRefGen:
380 return destroy(reinterpret_cast<IrInstructionRefGen *>(inst), name);
381 case IrInstructionIdCompileErr:
382 return destroy(reinterpret_cast<IrInstructionCompileErr *>(inst), name);
383 case IrInstructionIdCompileLog:
384 return destroy(reinterpret_cast<IrInstructionCompileLog *>(inst), name);
385 case IrInstructionIdErrName:
386 return destroy(reinterpret_cast<IrInstructionErrName *>(inst), name);
387 case IrInstructionIdCImport:
388 return destroy(reinterpret_cast<IrInstructionCImport *>(inst), name);
389 case IrInstructionIdCInclude:
390 return destroy(reinterpret_cast<IrInstructionCInclude *>(inst), name);
391 case IrInstructionIdCDefine:
392 return destroy(reinterpret_cast<IrInstructionCDefine *>(inst), name);
393 case IrInstructionIdCUndef:
394 return destroy(reinterpret_cast<IrInstructionCUndef *>(inst), name);
395 case IrInstructionIdEmbedFile:
396 return destroy(reinterpret_cast<IrInstructionEmbedFile *>(inst), name);
397 case IrInstructionIdCmpxchgSrc:
398 return destroy(reinterpret_cast<IrInstructionCmpxchgSrc *>(inst), name);
399 case IrInstructionIdCmpxchgGen:
400 return destroy(reinterpret_cast<IrInstructionCmpxchgGen *>(inst), name);
401 case IrInstructionIdFence:
402 return destroy(reinterpret_cast<IrInstructionFence *>(inst), name);
403 case IrInstructionIdTruncate:
404 return destroy(reinterpret_cast<IrInstructionTruncate *>(inst), name);
405 case IrInstructionIdIntCast:
406 return destroy(reinterpret_cast<IrInstructionIntCast *>(inst), name);
407 case IrInstructionIdFloatCast:
408 return destroy(reinterpret_cast<IrInstructionFloatCast *>(inst), name);
409 case IrInstructionIdErrSetCast:
410 return destroy(reinterpret_cast<IrInstructionErrSetCast *>(inst), name);
411 case IrInstructionIdFromBytes:
412 return destroy(reinterpret_cast<IrInstructionFromBytes *>(inst), name);
413 case IrInstructionIdToBytes:
414 return destroy(reinterpret_cast<IrInstructionToBytes *>(inst), name);
415 case IrInstructionIdIntToFloat:
416 return destroy(reinterpret_cast<IrInstructionIntToFloat *>(inst), name);
417 case IrInstructionIdFloatToInt:
418 return destroy(reinterpret_cast<IrInstructionFloatToInt *>(inst), name);
419 case IrInstructionIdBoolToInt:
420 return destroy(reinterpret_cast<IrInstructionBoolToInt *>(inst), name);
421 case IrInstructionIdIntType:
422 return destroy(reinterpret_cast<IrInstructionIntType *>(inst), name);
423 case IrInstructionIdVectorType:
424 return destroy(reinterpret_cast<IrInstructionVectorType *>(inst), name);
425 case IrInstructionIdShuffleVector:
426 return destroy(reinterpret_cast<IrInstructionShuffleVector *>(inst), name);
427 case IrInstructionIdSplatSrc:
428 return destroy(reinterpret_cast<IrInstructionSplatSrc *>(inst), name);
429 case IrInstructionIdSplatGen:
430 return destroy(reinterpret_cast<IrInstructionSplatGen *>(inst), name);
431 case IrInstructionIdBoolNot:
432 return destroy(reinterpret_cast<IrInstructionBoolNot *>(inst), name);
433 case IrInstructionIdMemset:
434 return destroy(reinterpret_cast<IrInstructionMemset *>(inst), name);
435 case IrInstructionIdMemcpy:
436 return destroy(reinterpret_cast<IrInstructionMemcpy *>(inst), name);
437 case IrInstructionIdSliceSrc:
438 return destroy(reinterpret_cast<IrInstructionSliceSrc *>(inst), name);
439 case IrInstructionIdSliceGen:
440 return destroy(reinterpret_cast<IrInstructionSliceGen *>(inst), name);
441 case IrInstructionIdMemberCount:
442 return destroy(reinterpret_cast<IrInstructionMemberCount *>(inst), name);
443 case IrInstructionIdMemberType:
444 return destroy(reinterpret_cast<IrInstructionMemberType *>(inst), name);
445 case IrInstructionIdMemberName:
446 return destroy(reinterpret_cast<IrInstructionMemberName *>(inst), name);
447 case IrInstructionIdBreakpoint:
448 return destroy(reinterpret_cast<IrInstructionBreakpoint *>(inst), name);
449 case IrInstructionIdReturnAddress:
450 return destroy(reinterpret_cast<IrInstructionReturnAddress *>(inst), name);
451 case IrInstructionIdFrameAddress:
452 return destroy(reinterpret_cast<IrInstructionFrameAddress *>(inst), name);
453 case IrInstructionIdFrameHandle:
454 return destroy(reinterpret_cast<IrInstructionFrameHandle *>(inst), name);
455 case IrInstructionIdFrameType:
456 return destroy(reinterpret_cast<IrInstructionFrameType *>(inst), name);
457 case IrInstructionIdFrameSizeSrc:
458 return destroy(reinterpret_cast<IrInstructionFrameSizeSrc *>(inst), name);
459 case IrInstructionIdFrameSizeGen:
460 return destroy(reinterpret_cast<IrInstructionFrameSizeGen *>(inst), name);
461 case IrInstructionIdAlignOf:
462 return destroy(reinterpret_cast<IrInstructionAlignOf *>(inst), name);
463 case IrInstructionIdOverflowOp:
464 return destroy(reinterpret_cast<IrInstructionOverflowOp *>(inst), name);
465 case IrInstructionIdTestErrSrc:
466 return destroy(reinterpret_cast<IrInstructionTestErrSrc *>(inst), name);
467 case IrInstructionIdTestErrGen:
468 return destroy(reinterpret_cast<IrInstructionTestErrGen *>(inst), name);
469 case IrInstructionIdUnwrapErrCode:
470 return destroy(reinterpret_cast<IrInstructionUnwrapErrCode *>(inst), name);
471 case IrInstructionIdUnwrapErrPayload:
472 return destroy(reinterpret_cast<IrInstructionUnwrapErrPayload *>(inst), name);
473 case IrInstructionIdOptionalWrap:
474 return destroy(reinterpret_cast<IrInstructionOptionalWrap *>(inst), name);
475 case IrInstructionIdErrWrapCode:
476 return destroy(reinterpret_cast<IrInstructionErrWrapCode *>(inst), name);
477 case IrInstructionIdErrWrapPayload:
478 return destroy(reinterpret_cast<IrInstructionErrWrapPayload *>(inst), name);
479 case IrInstructionIdFnProto:
480 return destroy(reinterpret_cast<IrInstructionFnProto *>(inst), name);
481 case IrInstructionIdTestComptime:
482 return destroy(reinterpret_cast<IrInstructionTestComptime *>(inst), name);
483 case IrInstructionIdPtrCastSrc:
484 return destroy(reinterpret_cast<IrInstructionPtrCastSrc *>(inst), name);
485 case IrInstructionIdPtrCastGen:
486 return destroy(reinterpret_cast<IrInstructionPtrCastGen *>(inst), name);
487 case IrInstructionIdBitCastSrc:
488 return destroy(reinterpret_cast<IrInstructionBitCastSrc *>(inst), name);
489 case IrInstructionIdBitCastGen:
490 return destroy(reinterpret_cast<IrInstructionBitCastGen *>(inst), name);
491 case IrInstructionIdWidenOrShorten:
492 return destroy(reinterpret_cast<IrInstructionWidenOrShorten *>(inst), name);
493 case IrInstructionIdPtrToInt:
494 return destroy(reinterpret_cast<IrInstructionPtrToInt *>(inst), name);
495 case IrInstructionIdIntToPtr:
496 return destroy(reinterpret_cast<IrInstructionIntToPtr *>(inst), name);
497 case IrInstructionIdIntToEnum:
498 return destroy(reinterpret_cast<IrInstructionIntToEnum *>(inst), name);
499 case IrInstructionIdIntToErr:
500 return destroy(reinterpret_cast<IrInstructionIntToErr *>(inst), name);
501 case IrInstructionIdErrToInt:
502 return destroy(reinterpret_cast<IrInstructionErrToInt *>(inst), name);
503 case IrInstructionIdCheckSwitchProngs:
504 return destroy(reinterpret_cast<IrInstructionCheckSwitchProngs *>(inst), name);
505 case IrInstructionIdCheckStatementIsVoid:
506 return destroy(reinterpret_cast<IrInstructionCheckStatementIsVoid *>(inst), name);
507 case IrInstructionIdTypeName:
508 return destroy(reinterpret_cast<IrInstructionTypeName *>(inst), name);
509 case IrInstructionIdTagName:
510 return destroy(reinterpret_cast<IrInstructionTagName *>(inst), name);
511 case IrInstructionIdPtrType:
512 return destroy(reinterpret_cast<IrInstructionPtrType *>(inst), name);
513 case IrInstructionIdDeclRef:
514 return destroy(reinterpret_cast<IrInstructionDeclRef *>(inst), name);
515 case IrInstructionIdPanic:
516 return destroy(reinterpret_cast<IrInstructionPanic *>(inst), name);
517 case IrInstructionIdFieldParentPtr:
518 return destroy(reinterpret_cast<IrInstructionFieldParentPtr *>(inst), name);
519 case IrInstructionIdByteOffsetOf:
520 return destroy(reinterpret_cast<IrInstructionByteOffsetOf *>(inst), name);
521 case IrInstructionIdBitOffsetOf:
522 return destroy(reinterpret_cast<IrInstructionBitOffsetOf *>(inst), name);
523 case IrInstructionIdTypeInfo:
524 return destroy(reinterpret_cast<IrInstructionTypeInfo *>(inst), name);
525 case IrInstructionIdType:
526 return destroy(reinterpret_cast<IrInstructionType *>(inst), name);
527 case IrInstructionIdHasField:
528 return destroy(reinterpret_cast<IrInstructionHasField *>(inst), name);
529 case IrInstructionIdTypeId:
530 return destroy(reinterpret_cast<IrInstructionTypeId *>(inst), name);
531 case IrInstructionIdSetEvalBranchQuota:
532 return destroy(reinterpret_cast<IrInstructionSetEvalBranchQuota *>(inst), name);
533 case IrInstructionIdAlignCast:
534 return destroy(reinterpret_cast<IrInstructionAlignCast *>(inst), name);
535 case IrInstructionIdImplicitCast:
536 return destroy(reinterpret_cast<IrInstructionImplicitCast *>(inst), name);
537 case IrInstructionIdResolveResult:
538 return destroy(reinterpret_cast<IrInstructionResolveResult *>(inst), name);
539 case IrInstructionIdResetResult:
540 return destroy(reinterpret_cast<IrInstructionResetResult *>(inst), name);
541 case IrInstructionIdOpaqueType:
542 return destroy(reinterpret_cast<IrInstructionOpaqueType *>(inst), name);
543 case IrInstructionIdSetAlignStack:
544 return destroy(reinterpret_cast<IrInstructionSetAlignStack *>(inst), name);
545 case IrInstructionIdArgType:
546 return destroy(reinterpret_cast<IrInstructionArgType *>(inst), name);
547 case IrInstructionIdTagType:
548 return destroy(reinterpret_cast<IrInstructionTagType *>(inst), name);
549 case IrInstructionIdExport:
550 return destroy(reinterpret_cast<IrInstructionExport *>(inst), name);
551 case IrInstructionIdErrorReturnTrace:
552 return destroy(reinterpret_cast<IrInstructionErrorReturnTrace *>(inst), name);
553 case IrInstructionIdErrorUnion:
554 return destroy(reinterpret_cast<IrInstructionErrorUnion *>(inst), name);
555 case IrInstructionIdAtomicRmw:
556 return destroy(reinterpret_cast<IrInstructionAtomicRmw *>(inst), name);
557 case IrInstructionIdSaveErrRetAddr:
558 return destroy(reinterpret_cast<IrInstructionSaveErrRetAddr *>(inst), name);
559 case IrInstructionIdAddImplicitReturnType:
560 return destroy(reinterpret_cast<IrInstructionAddImplicitReturnType *>(inst), name);
561 case IrInstructionIdFloatOp:
562 return destroy(reinterpret_cast<IrInstructionFloatOp *>(inst), name);
563 case IrInstructionIdMulAdd:
564 return destroy(reinterpret_cast<IrInstructionMulAdd *>(inst), name);
565 case IrInstructionIdAtomicLoad:
566 return destroy(reinterpret_cast<IrInstructionAtomicLoad *>(inst), name);
567 case IrInstructionIdAtomicStore:
568 return destroy(reinterpret_cast<IrInstructionAtomicStore *>(inst), name);
569 case IrInstructionIdEnumToInt:
570 return destroy(reinterpret_cast<IrInstructionEnumToInt *>(inst), name);
571 case IrInstructionIdCheckRuntimeScope:
572 return destroy(reinterpret_cast<IrInstructionCheckRuntimeScope *>(inst), name);
573 case IrInstructionIdDeclVarGen:
574 return destroy(reinterpret_cast<IrInstructionDeclVarGen *>(inst), name);
575 case IrInstructionIdArrayToVector:
576 return destroy(reinterpret_cast<IrInstructionArrayToVector *>(inst), name);
577 case IrInstructionIdVectorToArray:
578 return destroy(reinterpret_cast<IrInstructionVectorToArray *>(inst), name);
579 case IrInstructionIdPtrOfArrayToSlice:
580 return destroy(reinterpret_cast<IrInstructionPtrOfArrayToSlice *>(inst), name);
581 case IrInstructionIdAssertZero:
582 return destroy(reinterpret_cast<IrInstructionAssertZero *>(inst), name);
583 case IrInstructionIdAssertNonNull:
584 return destroy(reinterpret_cast<IrInstructionAssertNonNull *>(inst), name);
585 case IrInstructionIdResizeSlice:
586 return destroy(reinterpret_cast<IrInstructionResizeSlice *>(inst), name);
587 case IrInstructionIdHasDecl:
588 return destroy(reinterpret_cast<IrInstructionHasDecl *>(inst), name);
589 case IrInstructionIdUndeclaredIdent:
590 return destroy(reinterpret_cast<IrInstructionUndeclaredIdent *>(inst), name);
591 case IrInstructionIdAllocaSrc:
592 return destroy(reinterpret_cast<IrInstructionAllocaSrc *>(inst), name);
593 case IrInstructionIdAllocaGen:
594 return destroy(reinterpret_cast<IrInstructionAllocaGen *>(inst), name);
595 case IrInstructionIdEndExpr:
596 return destroy(reinterpret_cast<IrInstructionEndExpr *>(inst), name);
597 case IrInstructionIdUnionInitNamedField:
598 return destroy(reinterpret_cast<IrInstructionUnionInitNamedField *>(inst), name);
599 case IrInstructionIdSuspendBegin:
600 return destroy(reinterpret_cast<IrInstructionSuspendBegin *>(inst), name);
601 case IrInstructionIdSuspendFinish:
602 return destroy(reinterpret_cast<IrInstructionSuspendFinish *>(inst), name);
603 case IrInstructionIdResume:
604 return destroy(reinterpret_cast<IrInstructionResume *>(inst), name);
605 case IrInstructionIdAwaitSrc:
606 return destroy(reinterpret_cast<IrInstructionAwaitSrc *>(inst), name);
607 case IrInstructionIdAwaitGen:
608 return destroy(reinterpret_cast<IrInstructionAwaitGen *>(inst), name);
609 case IrInstructionIdSpillBegin:
610 return destroy(reinterpret_cast<IrInstructionSpillBegin *>(inst), name);
611 case IrInstructionIdSpillEnd:
612 return destroy(reinterpret_cast<IrInstructionSpillEnd *>(inst), name);
613 case IrInstructionIdVectorExtractElem:
614 return destroy(reinterpret_cast<IrInstructionVectorExtractElem *>(inst), name);
573 case IrInstGenIdReturn:
574 return destroy(reinterpret_cast<IrInstGenReturn *>(inst), name);
575 case IrInstGenIdConst:
576 return destroy(reinterpret_cast<IrInstGenConst *>(inst), name);
577 case IrInstGenIdBinOp:
578 return destroy(reinterpret_cast<IrInstGenBinOp *>(inst), name);
579 case IrInstGenIdCast:
580 return destroy(reinterpret_cast<IrInstGenCast *>(inst), name);
581 case IrInstGenIdCall:
582 return destroy(reinterpret_cast<IrInstGenCall *>(inst), name);
583 case IrInstGenIdCondBr:
584 return destroy(reinterpret_cast<IrInstGenCondBr *>(inst), name);
585 case IrInstGenIdBr:
586 return destroy(reinterpret_cast<IrInstGenBr *>(inst), name);
587 case IrInstGenIdPhi:
588 return destroy(reinterpret_cast<IrInstGenPhi *>(inst), name);
589 case IrInstGenIdUnreachable:
590 return destroy(reinterpret_cast<IrInstGenUnreachable *>(inst), name);
591 case IrInstGenIdElemPtr:
592 return destroy(reinterpret_cast<IrInstGenElemPtr *>(inst), name);
593 case IrInstGenIdVarPtr:
594 return destroy(reinterpret_cast<IrInstGenVarPtr *>(inst), name);
595 case IrInstGenIdReturnPtr:
596 return destroy(reinterpret_cast<IrInstGenReturnPtr *>(inst), name);
597 case IrInstGenIdLoadPtr:
598 return destroy(reinterpret_cast<IrInstGenLoadPtr *>(inst), name);
599 case IrInstGenIdStorePtr:
600 return destroy(reinterpret_cast<IrInstGenStorePtr *>(inst), name);
601 case IrInstGenIdVectorStoreElem:
602 return destroy(reinterpret_cast<IrInstGenVectorStoreElem *>(inst), name);
603 case IrInstGenIdStructFieldPtr:
604 return destroy(reinterpret_cast<IrInstGenStructFieldPtr *>(inst), name);
605 case IrInstGenIdUnionFieldPtr:
606 return destroy(reinterpret_cast<IrInstGenUnionFieldPtr *>(inst), name);
607 case IrInstGenIdAsm:
608 return destroy(reinterpret_cast<IrInstGenAsm *>(inst), name);
609 case IrInstGenIdTestNonNull:
610 return destroy(reinterpret_cast<IrInstGenTestNonNull *>(inst), name);
611 case IrInstGenIdOptionalUnwrapPtr:
612 return destroy(reinterpret_cast<IrInstGenOptionalUnwrapPtr *>(inst), name);
613 case IrInstGenIdPopCount:
614 return destroy(reinterpret_cast<IrInstGenPopCount *>(inst), name);
615 case IrInstGenIdClz:
616 return destroy(reinterpret_cast<IrInstGenClz *>(inst), name);
617 case IrInstGenIdCtz:
618 return destroy(reinterpret_cast<IrInstGenCtz *>(inst), name);
619 case IrInstGenIdBswap:
620 return destroy(reinterpret_cast<IrInstGenBswap *>(inst), name);
621 case IrInstGenIdBitReverse:
622 return destroy(reinterpret_cast<IrInstGenBitReverse *>(inst), name);
623 case IrInstGenIdSwitchBr:
624 return destroy(reinterpret_cast<IrInstGenSwitchBr *>(inst), name);
625 case IrInstGenIdUnionTag:
626 return destroy(reinterpret_cast<IrInstGenUnionTag *>(inst), name);
627 case IrInstGenIdRef:
628 return destroy(reinterpret_cast<IrInstGenRef *>(inst), name);
629 case IrInstGenIdErrName:
630 return destroy(reinterpret_cast<IrInstGenErrName *>(inst), name);
631 case IrInstGenIdCmpxchg:
632 return destroy(reinterpret_cast<IrInstGenCmpxchg *>(inst), name);
633 case IrInstGenIdFence:
634 return destroy(reinterpret_cast<IrInstGenFence *>(inst), name);
635 case IrInstGenIdTruncate:
636 return destroy(reinterpret_cast<IrInstGenTruncate *>(inst), name);
637 case IrInstGenIdShuffleVector:
638 return destroy(reinterpret_cast<IrInstGenShuffleVector *>(inst), name);
639 case IrInstGenIdSplat:
640 return destroy(reinterpret_cast<IrInstGenSplat *>(inst), name);
641 case IrInstGenIdBoolNot:
642 return destroy(reinterpret_cast<IrInstGenBoolNot *>(inst), name);
643 case IrInstGenIdMemset:
644 return destroy(reinterpret_cast<IrInstGenMemset *>(inst), name);
645 case IrInstGenIdMemcpy:
646 return destroy(reinterpret_cast<IrInstGenMemcpy *>(inst), name);
647 case IrInstGenIdSlice:
648 return destroy(reinterpret_cast<IrInstGenSlice *>(inst), name);
649 case IrInstGenIdBreakpoint:
650 return destroy(reinterpret_cast<IrInstGenBreakpoint *>(inst), name);
651 case IrInstGenIdReturnAddress:
652 return destroy(reinterpret_cast<IrInstGenReturnAddress *>(inst), name);
653 case IrInstGenIdFrameAddress:
654 return destroy(reinterpret_cast<IrInstGenFrameAddress *>(inst), name);
655 case IrInstGenIdFrameHandle:
656 return destroy(reinterpret_cast<IrInstGenFrameHandle *>(inst), name);
657 case IrInstGenIdFrameSize:
658 return destroy(reinterpret_cast<IrInstGenFrameSize *>(inst), name);
659 case IrInstGenIdOverflowOp:
660 return destroy(reinterpret_cast<IrInstGenOverflowOp *>(inst), name);
661 case IrInstGenIdTestErr:
662 return destroy(reinterpret_cast<IrInstGenTestErr *>(inst), name);
663 case IrInstGenIdUnwrapErrCode:
664 return destroy(reinterpret_cast<IrInstGenUnwrapErrCode *>(inst), name);
665 case IrInstGenIdUnwrapErrPayload:
666 return destroy(reinterpret_cast<IrInstGenUnwrapErrPayload *>(inst), name);
667 case IrInstGenIdOptionalWrap:
668 return destroy(reinterpret_cast<IrInstGenOptionalWrap *>(inst), name);
669 case IrInstGenIdErrWrapCode:
670 return destroy(reinterpret_cast<IrInstGenErrWrapCode *>(inst), name);
671 case IrInstGenIdErrWrapPayload:
672 return destroy(reinterpret_cast<IrInstGenErrWrapPayload *>(inst), name);
673 case IrInstGenIdPtrCast:
674 return destroy(reinterpret_cast<IrInstGenPtrCast *>(inst), name);
675 case IrInstGenIdBitCast:
676 return destroy(reinterpret_cast<IrInstGenBitCast *>(inst), name);
677 case IrInstGenIdWidenOrShorten:
678 return destroy(reinterpret_cast<IrInstGenWidenOrShorten *>(inst), name);
679 case IrInstGenIdPtrToInt:
680 return destroy(reinterpret_cast<IrInstGenPtrToInt *>(inst), name);
681 case IrInstGenIdIntToPtr:
682 return destroy(reinterpret_cast<IrInstGenIntToPtr *>(inst), name);
683 case IrInstGenIdIntToEnum:
684 return destroy(reinterpret_cast<IrInstGenIntToEnum *>(inst), name);
685 case IrInstGenIdIntToErr:
686 return destroy(reinterpret_cast<IrInstGenIntToErr *>(inst), name);
687 case IrInstGenIdErrToInt:
688 return destroy(reinterpret_cast<IrInstGenErrToInt *>(inst), name);
689 case IrInstGenIdTagName:
690 return destroy(reinterpret_cast<IrInstGenTagName *>(inst), name);
691 case IrInstGenIdPanic:
692 return destroy(reinterpret_cast<IrInstGenPanic *>(inst), name);
693 case IrInstGenIdFieldParentPtr:
694 return destroy(reinterpret_cast<IrInstGenFieldParentPtr *>(inst), name);
695 case IrInstGenIdAlignCast:
696 return destroy(reinterpret_cast<IrInstGenAlignCast *>(inst), name);
697 case IrInstGenIdErrorReturnTrace:
698 return destroy(reinterpret_cast<IrInstGenErrorReturnTrace *>(inst), name);
699 case IrInstGenIdAtomicRmw:
700 return destroy(reinterpret_cast<IrInstGenAtomicRmw *>(inst), name);
701 case IrInstGenIdSaveErrRetAddr:
702 return destroy(reinterpret_cast<IrInstGenSaveErrRetAddr *>(inst), name);
703 case IrInstGenIdFloatOp:
704 return destroy(reinterpret_cast<IrInstGenFloatOp *>(inst), name);
705 case IrInstGenIdMulAdd:
706 return destroy(reinterpret_cast<IrInstGenMulAdd *>(inst), name);
707 case IrInstGenIdAtomicLoad:
708 return destroy(reinterpret_cast<IrInstGenAtomicLoad *>(inst), name);
709 case IrInstGenIdAtomicStore:
710 return destroy(reinterpret_cast<IrInstGenAtomicStore *>(inst), name);
711 case IrInstGenIdDeclVar:
712 return destroy(reinterpret_cast<IrInstGenDeclVar *>(inst), name);
713 case IrInstGenIdArrayToVector:
714 return destroy(reinterpret_cast<IrInstGenArrayToVector *>(inst), name);
715 case IrInstGenIdVectorToArray:
716 return destroy(reinterpret_cast<IrInstGenVectorToArray *>(inst), name);
717 case IrInstGenIdPtrOfArrayToSlice:
718 return destroy(reinterpret_cast<IrInstGenPtrOfArrayToSlice *>(inst), name);
719 case IrInstGenIdAssertZero:
720 return destroy(reinterpret_cast<IrInstGenAssertZero *>(inst), name);
721 case IrInstGenIdAssertNonNull:
722 return destroy(reinterpret_cast<IrInstGenAssertNonNull *>(inst), name);
723 case IrInstGenIdResizeSlice:
724 return destroy(reinterpret_cast<IrInstGenResizeSlice *>(inst), name);
725 case IrInstGenIdAlloca:
726 return destroy(reinterpret_cast<IrInstGenAlloca *>(inst), name);
727 case IrInstGenIdSuspendBegin:
728 return destroy(reinterpret_cast<IrInstGenSuspendBegin *>(inst), name);
729 case IrInstGenIdSuspendFinish:
730 return destroy(reinterpret_cast<IrInstGenSuspendFinish *>(inst), name);
731 case IrInstGenIdResume:
732 return destroy(reinterpret_cast<IrInstGenResume *>(inst), name);
733 case IrInstGenIdAwait:
734 return destroy(reinterpret_cast<IrInstGenAwait *>(inst), name);
735 case IrInstGenIdSpillBegin:
736 return destroy(reinterpret_cast<IrInstGenSpillBegin *>(inst), name);
737 case IrInstGenIdSpillEnd:
738 return destroy(reinterpret_cast<IrInstGenSpillEnd *>(inst), name);
739 case IrInstGenIdVectorExtractElem:
740 return destroy(reinterpret_cast<IrInstGenVectorExtractElem *>(inst), name);
741 case IrInstGenIdBinaryNot:
742 return destroy(reinterpret_cast<IrInstGenBinaryNot *>(inst), name);
743 case IrInstGenIdNegation:
744 return destroy(reinterpret_cast<IrInstGenNegation *>(inst), name);
745 case IrInstGenIdNegationWrapping:
746 return destroy(reinterpret_cast<IrInstGenNegationWrapping *>(inst), name);
615747 }
616748 zig_unreachable();
617749}
......@@ -627,17 +759,17 @@ static void ira_deref(IrAnalyze *ira) {
627759 assert(ira->ref_count != 0);
628760
629761 for (size_t bb_i = 0; bb_i < ira->old_irb.exec->basic_block_list.length; bb_i += 1) {
630 IrBasicBlock *pass1_bb = ira->old_irb.exec->basic_block_list.items[bb_i];
762 IrBasicBlockSrc *pass1_bb = ira->old_irb.exec->basic_block_list.items[bb_i];
631763 for (size_t inst_i = 0; inst_i < pass1_bb->instruction_list.length; inst_i += 1) {
632 IrInstruction *pass1_inst = pass1_bb->instruction_list.items[inst_i];
633 destroy_instruction(pass1_inst);
764 IrInstSrc *pass1_inst = pass1_bb->instruction_list.items[inst_i];
765 destroy_instruction_src(pass1_inst);
634766 }
635 destroy(pass1_bb, "IrBasicBlock");
767 destroy(pass1_bb, "IrBasicBlockSrc");
636768 }
637769 ira->old_irb.exec->basic_block_list.deinit();
638770 ira->old_irb.exec->tld_list.deinit();
639771 // cannot destroy here because of var->owner_exec
640 //destroy(ira->old_irb.exec, "IrExecutablePass1");
772 //destroy(ira->old_irb.exec, "IrExecutableSrc");
641773 ira->src_implicit_return_type_list.deinit();
642774 ira->resume_stack.deinit();
643775 ira->exec_context.mem_slot_list.deinit();
......@@ -785,7 +917,7 @@ static bool types_have_same_zig_comptime_repr(CodeGen *codegen, ZigType *expecte
785917 zig_unreachable();
786918}
787919
788static bool ir_should_inline(IrExecutable *exec, Scope *scope) {
920static bool ir_should_inline(IrExecutableSrc *exec, Scope *scope) {
789921 if (exec->is_inline)
790922 return true;
791923
......@@ -801,29 +933,41 @@ static bool ir_should_inline(IrExecutable *exec, Scope *scope) {
801933 return false;
802934}
803935
804static void ir_instruction_append(IrBasicBlock *basic_block, IrInstruction *instruction) {
936static void ir_instruction_append(IrBasicBlockSrc *basic_block, IrInstSrc *instruction) {
937 assert(basic_block);
938 assert(instruction);
939 basic_block->instruction_list.append(instruction);
940}
941
942static void ir_inst_gen_append(IrBasicBlockGen *basic_block, IrInstGen *instruction) {
805943 assert(basic_block);
806944 assert(instruction);
807945 basic_block->instruction_list.append(instruction);
808946}
809947
810static size_t exec_next_debug_id(IrExecutable *exec) {
948static size_t exec_next_debug_id(IrExecutableSrc *exec) {
949 size_t result = exec->next_debug_id;
950 exec->next_debug_id += 1;
951 return result;
952}
953
954static size_t exec_next_debug_id_gen(IrExecutableGen *exec) {
811955 size_t result = exec->next_debug_id;
812956 exec->next_debug_id += 1;
813957 return result;
814958}
815959
816static size_t exec_next_mem_slot(IrExecutable *exec) {
960static size_t exec_next_mem_slot(IrExecutableSrc *exec) {
817961 size_t result = exec->mem_slot_count;
818962 exec->mem_slot_count += 1;
819963 return result;
820964}
821965
822static ZigFn *exec_fn_entry(IrExecutable *exec) {
966static ZigFn *exec_fn_entry(IrExecutableSrc *exec) {
823967 return exec->fn_entry;
824968}
825969
826static Buf *exec_c_import_buf(IrExecutable *exec) {
970static Buf *exec_c_import_buf(IrExecutableSrc *exec) {
827971 return exec->c_import_buf;
828972}
829973
......@@ -831,28 +975,42 @@ static bool value_is_comptime(ZigValue *const_val) {
831975 return const_val->special != ConstValSpecialRuntime;
832976}
833977
834static bool instr_is_comptime(IrInstruction *instruction) {
978static bool instr_is_comptime(IrInstGen *instruction) {
835979 return value_is_comptime(instruction->value);
836980}
837981
838static bool instr_is_unreachable(IrInstruction *instruction) {
839 return instruction->value->type && instruction->value->type->id == ZigTypeIdUnreachable;
982static bool instr_is_unreachable(IrInstSrc *instruction) {
983 return instruction->is_noreturn;
840984}
841985
842static void ir_link_new_bb(IrBasicBlock *new_bb, IrBasicBlock *old_bb) {
843 new_bb->other = old_bb;
844 old_bb->other = new_bb;
986static void ir_link_new_bb(IrBasicBlockGen *new_bb, IrBasicBlockSrc *old_bb) {
987 new_bb->parent = old_bb;
988 old_bb->child = new_bb;
845989}
846990
847static void ir_ref_bb(IrBasicBlock *bb) {
991static void ir_ref_bb(IrBasicBlockSrc *bb) {
848992 bb->ref_count += 1;
849993}
850994
851static void ir_ref_instruction(IrInstruction *instruction, IrBasicBlock *cur_bb) {
852 assert(instruction->id != IrInstructionIdInvalid);
853 instruction->ref_count += 1;
854 if (instruction->owner_bb != cur_bb && !instr_is_comptime(instruction))
995static void ir_ref_bb_gen(IrBasicBlockGen *bb) {
996 bb->ref_count += 1;
997}
998
999static void ir_ref_instruction(IrInstSrc *instruction, IrBasicBlockSrc *cur_bb) {
1000 assert(instruction->id != IrInstSrcIdInvalid);
1001 instruction->base.ref_count += 1;
1002 if (instruction->owner_bb != cur_bb && !instr_is_unreachable(instruction)
1003 && instruction->id != IrInstSrcIdConst)
1004 {
8551005 ir_ref_bb(instruction->owner_bb);
1006 }
1007}
1008
1009static void ir_ref_inst_gen(IrInstGen *instruction, IrBasicBlockGen *cur_bb) {
1010 assert(instruction->id != IrInstGenIdInvalid);
1011 instruction->base.ref_count += 1;
1012 if (instruction->owner_bb != cur_bb && !instr_is_comptime(instruction))
1013 ir_ref_bb_gen(instruction->owner_bb);
8561014}
8571015
8581016static void ir_ref_var(ZigVar *var) {
......@@ -871,962 +1029,1259 @@ ZigType *ir_analyze_type_expr(IrAnalyze *ira, Scope *scope, AstNode *node) {
8711029 return result->data.x_type;
8721030}
8731031
874static IrBasicBlock *ir_create_basic_block(IrBuilder *irb, Scope *scope, const char *name_hint) {
875 IrBasicBlock *result = allocate<IrBasicBlock>(1, "IrBasicBlock");
1032static IrBasicBlockSrc *ir_create_basic_block(IrBuilderSrc *irb, Scope *scope, const char *name_hint) {
1033 IrBasicBlockSrc *result = allocate<IrBasicBlockSrc>(1, "IrBasicBlockSrc");
8761034 result->scope = scope;
8771035 result->name_hint = name_hint;
8781036 result->debug_id = exec_next_debug_id(irb->exec);
879 result->index = SIZE_MAX; // set later
1037 result->index = UINT32_MAX; // set later
8801038 return result;
8811039}
8821040
883static IrBasicBlock *ir_build_bb_from(IrBuilder *irb, IrBasicBlock *other_bb) {
884 IrBasicBlock *new_bb = ir_create_basic_block(irb, other_bb->scope, other_bb->name_hint);
1041static IrBasicBlockGen *ir_create_basic_block_gen(IrAnalyze *ira, Scope *scope, const char *name_hint) {
1042 IrBasicBlockGen *result = allocate<IrBasicBlockGen>(1, "IrBasicBlockGen");
1043 result->scope = scope;
1044 result->name_hint = name_hint;
1045 result->debug_id = exec_next_debug_id_gen(ira->new_irb.exec);
1046 result->index = UINT32_MAX; // set later
1047 return result;
1048}
1049
1050static IrBasicBlockGen *ir_build_bb_from(IrAnalyze *ira, IrBasicBlockSrc *other_bb) {
1051 IrBasicBlockGen *new_bb = ir_create_basic_block_gen(ira, other_bb->scope, other_bb->name_hint);
8851052 ir_link_new_bb(new_bb, other_bb);
8861053 return new_bb;
8871054}
8881055
889static constexpr IrInstructionId ir_instruction_id(IrInstructionDeclVarSrc *) {
890 return IrInstructionIdDeclVarSrc;
1056static constexpr IrInstSrcId ir_inst_id(IrInstSrcDeclVar *) {
1057 return IrInstSrcIdDeclVar;
1058}
1059
1060static constexpr IrInstSrcId ir_inst_id(IrInstSrcBr *) {
1061 return IrInstSrcIdBr;
1062}
1063
1064static constexpr IrInstSrcId ir_inst_id(IrInstSrcCondBr *) {
1065 return IrInstSrcIdCondBr;
1066}
1067
1068static constexpr IrInstSrcId ir_inst_id(IrInstSrcSwitchBr *) {
1069 return IrInstSrcIdSwitchBr;
1070}
1071
1072static constexpr IrInstSrcId ir_inst_id(IrInstSrcSwitchVar *) {
1073 return IrInstSrcIdSwitchVar;
1074}
1075
1076static constexpr IrInstSrcId ir_inst_id(IrInstSrcSwitchElseVar *) {
1077 return IrInstSrcIdSwitchElseVar;
1078}
1079
1080static constexpr IrInstSrcId ir_inst_id(IrInstSrcSwitchTarget *) {
1081 return IrInstSrcIdSwitchTarget;
1082}
1083
1084static constexpr IrInstSrcId ir_inst_id(IrInstSrcPhi *) {
1085 return IrInstSrcIdPhi;
1086}
1087
1088static constexpr IrInstSrcId ir_inst_id(IrInstSrcUnOp *) {
1089 return IrInstSrcIdUnOp;
1090}
1091
1092static constexpr IrInstSrcId ir_inst_id(IrInstSrcBinOp *) {
1093 return IrInstSrcIdBinOp;
1094}
1095
1096static constexpr IrInstSrcId ir_inst_id(IrInstSrcMergeErrSets *) {
1097 return IrInstSrcIdMergeErrSets;
1098}
1099
1100static constexpr IrInstSrcId ir_inst_id(IrInstSrcLoadPtr *) {
1101 return IrInstSrcIdLoadPtr;
1102}
1103
1104static constexpr IrInstSrcId ir_inst_id(IrInstSrcStorePtr *) {
1105 return IrInstSrcIdStorePtr;
1106}
1107
1108static constexpr IrInstSrcId ir_inst_id(IrInstSrcFieldPtr *) {
1109 return IrInstSrcIdFieldPtr;
1110}
1111
1112static constexpr IrInstSrcId ir_inst_id(IrInstSrcElemPtr *) {
1113 return IrInstSrcIdElemPtr;
1114}
1115
1116static constexpr IrInstSrcId ir_inst_id(IrInstSrcVarPtr *) {
1117 return IrInstSrcIdVarPtr;
1118}
1119
1120static constexpr IrInstSrcId ir_inst_id(IrInstSrcCall *) {
1121 return IrInstSrcIdCall;
1122}
1123
1124static constexpr IrInstSrcId ir_inst_id(IrInstSrcCallArgs *) {
1125 return IrInstSrcIdCallArgs;
1126}
1127
1128static constexpr IrInstSrcId ir_inst_id(IrInstSrcCallExtra *) {
1129 return IrInstSrcIdCallExtra;
1130}
1131
1132static constexpr IrInstSrcId ir_inst_id(IrInstSrcConst *) {
1133 return IrInstSrcIdConst;
1134}
1135
1136static constexpr IrInstSrcId ir_inst_id(IrInstSrcReturn *) {
1137 return IrInstSrcIdReturn;
1138}
1139
1140static constexpr IrInstSrcId ir_inst_id(IrInstSrcContainerInitList *) {
1141 return IrInstSrcIdContainerInitList;
1142}
1143
1144static constexpr IrInstSrcId ir_inst_id(IrInstSrcContainerInitFields *) {
1145 return IrInstSrcIdContainerInitFields;
1146}
1147
1148static constexpr IrInstSrcId ir_inst_id(IrInstSrcUnreachable *) {
1149 return IrInstSrcIdUnreachable;
1150}
1151
1152static constexpr IrInstSrcId ir_inst_id(IrInstSrcTypeOf *) {
1153 return IrInstSrcIdTypeOf;
1154}
1155
1156static constexpr IrInstSrcId ir_inst_id(IrInstSrcSetCold *) {
1157 return IrInstSrcIdSetCold;
1158}
1159
1160static constexpr IrInstSrcId ir_inst_id(IrInstSrcSetRuntimeSafety *) {
1161 return IrInstSrcIdSetRuntimeSafety;
1162}
1163
1164static constexpr IrInstSrcId ir_inst_id(IrInstSrcSetFloatMode *) {
1165 return IrInstSrcIdSetFloatMode;
1166}
1167
1168static constexpr IrInstSrcId ir_inst_id(IrInstSrcArrayType *) {
1169 return IrInstSrcIdArrayType;
1170}
1171
1172static constexpr IrInstSrcId ir_inst_id(IrInstSrcAnyFrameType *) {
1173 return IrInstSrcIdAnyFrameType;
1174}
1175
1176static constexpr IrInstSrcId ir_inst_id(IrInstSrcSliceType *) {
1177 return IrInstSrcIdSliceType;
1178}
1179
1180static constexpr IrInstSrcId ir_inst_id(IrInstSrcAsm *) {
1181 return IrInstSrcIdAsm;
1182}
1183
1184static constexpr IrInstSrcId ir_inst_id(IrInstSrcSizeOf *) {
1185 return IrInstSrcIdSizeOf;
1186}
1187
1188static constexpr IrInstSrcId ir_inst_id(IrInstSrcTestNonNull *) {
1189 return IrInstSrcIdTestNonNull;
1190}
1191
1192static constexpr IrInstSrcId ir_inst_id(IrInstSrcOptionalUnwrapPtr *) {
1193 return IrInstSrcIdOptionalUnwrapPtr;
1194}
1195
1196static constexpr IrInstSrcId ir_inst_id(IrInstSrcClz *) {
1197 return IrInstSrcIdClz;
1198}
1199
1200static constexpr IrInstSrcId ir_inst_id(IrInstSrcCtz *) {
1201 return IrInstSrcIdCtz;
1202}
1203
1204static constexpr IrInstSrcId ir_inst_id(IrInstSrcPopCount *) {
1205 return IrInstSrcIdPopCount;
1206}
1207
1208static constexpr IrInstSrcId ir_inst_id(IrInstSrcBswap *) {
1209 return IrInstSrcIdBswap;
1210}
1211
1212static constexpr IrInstSrcId ir_inst_id(IrInstSrcBitReverse *) {
1213 return IrInstSrcIdBitReverse;
1214}
1215
1216static constexpr IrInstSrcId ir_inst_id(IrInstSrcImport *) {
1217 return IrInstSrcIdImport;
1218}
1219
1220static constexpr IrInstSrcId ir_inst_id(IrInstSrcCImport *) {
1221 return IrInstSrcIdCImport;
1222}
1223
1224static constexpr IrInstSrcId ir_inst_id(IrInstSrcCInclude *) {
1225 return IrInstSrcIdCInclude;
1226}
1227
1228static constexpr IrInstSrcId ir_inst_id(IrInstSrcCDefine *) {
1229 return IrInstSrcIdCDefine;
1230}
1231
1232static constexpr IrInstSrcId ir_inst_id(IrInstSrcCUndef *) {
1233 return IrInstSrcIdCUndef;
1234}
1235
1236static constexpr IrInstSrcId ir_inst_id(IrInstSrcRef *) {
1237 return IrInstSrcIdRef;
1238}
1239
1240static constexpr IrInstSrcId ir_inst_id(IrInstSrcCompileErr *) {
1241 return IrInstSrcIdCompileErr;
1242}
1243
1244static constexpr IrInstSrcId ir_inst_id(IrInstSrcCompileLog *) {
1245 return IrInstSrcIdCompileLog;
1246}
1247
1248static constexpr IrInstSrcId ir_inst_id(IrInstSrcErrName *) {
1249 return IrInstSrcIdErrName;
1250}
1251
1252static constexpr IrInstSrcId ir_inst_id(IrInstSrcEmbedFile *) {
1253 return IrInstSrcIdEmbedFile;
1254}
1255
1256static constexpr IrInstSrcId ir_inst_id(IrInstSrcCmpxchg *) {
1257 return IrInstSrcIdCmpxchg;
1258}
1259
1260static constexpr IrInstSrcId ir_inst_id(IrInstSrcFence *) {
1261 return IrInstSrcIdFence;
1262}
1263
1264static constexpr IrInstSrcId ir_inst_id(IrInstSrcTruncate *) {
1265 return IrInstSrcIdTruncate;
1266}
1267
1268static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntCast *) {
1269 return IrInstSrcIdIntCast;
1270}
1271
1272static constexpr IrInstSrcId ir_inst_id(IrInstSrcFloatCast *) {
1273 return IrInstSrcIdFloatCast;
1274}
1275
1276static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntToFloat *) {
1277 return IrInstSrcIdIntToFloat;
1278}
1279
1280static constexpr IrInstSrcId ir_inst_id(IrInstSrcFloatToInt *) {
1281 return IrInstSrcIdFloatToInt;
1282}
1283
1284static constexpr IrInstSrcId ir_inst_id(IrInstSrcBoolToInt *) {
1285 return IrInstSrcIdBoolToInt;
8911286}
8921287
893static constexpr IrInstructionId ir_instruction_id(IrInstructionDeclVarGen *) {
894 return IrInstructionIdDeclVarGen;
1288static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntType *) {
1289 return IrInstSrcIdIntType;
8951290}
8961291
897static constexpr IrInstructionId ir_instruction_id(IrInstructionCondBr *) {
898 return IrInstructionIdCondBr;
1292static constexpr IrInstSrcId ir_inst_id(IrInstSrcVectorType *) {
1293 return IrInstSrcIdVectorType;
8991294}
9001295
901static constexpr IrInstructionId ir_instruction_id(IrInstructionBr *) {
902 return IrInstructionIdBr;
1296static constexpr IrInstSrcId ir_inst_id(IrInstSrcShuffleVector *) {
1297 return IrInstSrcIdShuffleVector;
9031298}
9041299
905static constexpr IrInstructionId ir_instruction_id(IrInstructionSwitchBr *) {
906 return IrInstructionIdSwitchBr;
1300static constexpr IrInstSrcId ir_inst_id(IrInstSrcSplat *) {
1301 return IrInstSrcIdSplat;
9071302}
9081303
909static constexpr IrInstructionId ir_instruction_id(IrInstructionSwitchVar *) {
910 return IrInstructionIdSwitchVar;
1304static constexpr IrInstSrcId ir_inst_id(IrInstSrcBoolNot *) {
1305 return IrInstSrcIdBoolNot;
9111306}
9121307
913static constexpr IrInstructionId ir_instruction_id(IrInstructionSwitchElseVar *) {
914 return IrInstructionIdSwitchElseVar;
1308static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemset *) {
1309 return IrInstSrcIdMemset;
9151310}
9161311
917static constexpr IrInstructionId ir_instruction_id(IrInstructionSwitchTarget *) {
918 return IrInstructionIdSwitchTarget;
1312static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemcpy *) {
1313 return IrInstSrcIdMemcpy;
9191314}
9201315
921static constexpr IrInstructionId ir_instruction_id(IrInstructionPhi *) {
922 return IrInstructionIdPhi;
1316static constexpr IrInstSrcId ir_inst_id(IrInstSrcSlice *) {
1317 return IrInstSrcIdSlice;
9231318}
9241319
925static constexpr IrInstructionId ir_instruction_id(IrInstructionUnOp *) {
926 return IrInstructionIdUnOp;
1320static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemberCount *) {
1321 return IrInstSrcIdMemberCount;
9271322}
9281323
929static constexpr IrInstructionId ir_instruction_id(IrInstructionBinOp *) {
930 return IrInstructionIdBinOp;
1324static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemberType *) {
1325 return IrInstSrcIdMemberType;
9311326}
9321327
933static constexpr IrInstructionId ir_instruction_id(IrInstructionMergeErrSets *) {
934 return IrInstructionIdMergeErrSets;
1328static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemberName *) {
1329 return IrInstSrcIdMemberName;
9351330}
9361331
937static constexpr IrInstructionId ir_instruction_id(IrInstructionExport *) {
938 return IrInstructionIdExport;
1332static constexpr IrInstSrcId ir_inst_id(IrInstSrcBreakpoint *) {
1333 return IrInstSrcIdBreakpoint;
9391334}
9401335
941static constexpr IrInstructionId ir_instruction_id(IrInstructionLoadPtr *) {
942 return IrInstructionIdLoadPtr;
1336static constexpr IrInstSrcId ir_inst_id(IrInstSrcReturnAddress *) {
1337 return IrInstSrcIdReturnAddress;
9431338}
9441339
945static constexpr IrInstructionId ir_instruction_id(IrInstructionLoadPtrGen *) {
946 return IrInstructionIdLoadPtrGen;
1340static constexpr IrInstSrcId ir_inst_id(IrInstSrcFrameAddress *) {
1341 return IrInstSrcIdFrameAddress;
9471342}
9481343
949static constexpr IrInstructionId ir_instruction_id(IrInstructionStorePtr *) {
950 return IrInstructionIdStorePtr;
1344static constexpr IrInstSrcId ir_inst_id(IrInstSrcFrameHandle *) {
1345 return IrInstSrcIdFrameHandle;
9511346}
9521347
953static constexpr IrInstructionId ir_instruction_id(IrInstructionVectorStoreElem *) {
954 return IrInstructionIdVectorStoreElem;
1348static constexpr IrInstSrcId ir_inst_id(IrInstSrcFrameType *) {
1349 return IrInstSrcIdFrameType;
9551350}
9561351
957static constexpr IrInstructionId ir_instruction_id(IrInstructionFieldPtr *) {
958 return IrInstructionIdFieldPtr;
1352static constexpr IrInstSrcId ir_inst_id(IrInstSrcFrameSize *) {
1353 return IrInstSrcIdFrameSize;
9591354}
9601355
961static constexpr IrInstructionId ir_instruction_id(IrInstructionStructFieldPtr *) {
962 return IrInstructionIdStructFieldPtr;
1356static constexpr IrInstSrcId ir_inst_id(IrInstSrcAlignOf *) {
1357 return IrInstSrcIdAlignOf;
9631358}
9641359
965static constexpr IrInstructionId ir_instruction_id(IrInstructionUnionFieldPtr *) {
966 return IrInstructionIdUnionFieldPtr;
1360static constexpr IrInstSrcId ir_inst_id(IrInstSrcOverflowOp *) {
1361 return IrInstSrcIdOverflowOp;
9671362}
9681363
969static constexpr IrInstructionId ir_instruction_id(IrInstructionElemPtr *) {
970 return IrInstructionIdElemPtr;
1364static constexpr IrInstSrcId ir_inst_id(IrInstSrcTestErr *) {
1365 return IrInstSrcIdTestErr;
9711366}
9721367
973static constexpr IrInstructionId ir_instruction_id(IrInstructionVarPtr *) {
974 return IrInstructionIdVarPtr;
1368static constexpr IrInstSrcId ir_inst_id(IrInstSrcMulAdd *) {
1369 return IrInstSrcIdMulAdd;
9751370}
9761371
977static constexpr IrInstructionId ir_instruction_id(IrInstructionReturnPtr *) {
978 return IrInstructionIdReturnPtr;
1372static constexpr IrInstSrcId ir_inst_id(IrInstSrcFloatOp *) {
1373 return IrInstSrcIdFloatOp;
9791374}
9801375
981static constexpr IrInstructionId ir_instruction_id(IrInstructionCallSrc *) {
982 return IrInstructionIdCallSrc;
1376static constexpr IrInstSrcId ir_inst_id(IrInstSrcUnwrapErrCode *) {
1377 return IrInstSrcIdUnwrapErrCode;
9831378}
9841379
985static constexpr IrInstructionId ir_instruction_id(IrInstructionCallSrcArgs *) {
986 return IrInstructionIdCallSrcArgs;
1380static constexpr IrInstSrcId ir_inst_id(IrInstSrcUnwrapErrPayload *) {
1381 return IrInstSrcIdUnwrapErrPayload;
9871382}
9881383
989static constexpr IrInstructionId ir_instruction_id(IrInstructionCallExtra *) {
990 return IrInstructionIdCallExtra;
1384static constexpr IrInstSrcId ir_inst_id(IrInstSrcFnProto *) {
1385 return IrInstSrcIdFnProto;
9911386}
9921387
993static constexpr IrInstructionId ir_instruction_id(IrInstructionCallGen *) {
994 return IrInstructionIdCallGen;
1388static constexpr IrInstSrcId ir_inst_id(IrInstSrcTestComptime *) {
1389 return IrInstSrcIdTestComptime;
9951390}
9961391
997static constexpr IrInstructionId ir_instruction_id(IrInstructionConst *) {
998 return IrInstructionIdConst;
1392static constexpr IrInstSrcId ir_inst_id(IrInstSrcPtrCast *) {
1393 return IrInstSrcIdPtrCast;
9991394}
10001395
1001static constexpr IrInstructionId ir_instruction_id(IrInstructionReturn *) {
1002 return IrInstructionIdReturn;
1396static constexpr IrInstSrcId ir_inst_id(IrInstSrcBitCast *) {
1397 return IrInstSrcIdBitCast;
10031398}
10041399
1005static constexpr IrInstructionId ir_instruction_id(IrInstructionCast *) {
1006 return IrInstructionIdCast;
1400static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntToPtr *) {
1401 return IrInstSrcIdIntToPtr;
10071402}
10081403
1009static constexpr IrInstructionId ir_instruction_id(IrInstructionResizeSlice *) {
1010 return IrInstructionIdResizeSlice;
1404static constexpr IrInstSrcId ir_inst_id(IrInstSrcPtrToInt *) {
1405 return IrInstSrcIdPtrToInt;
10111406}
10121407
1013static constexpr IrInstructionId ir_instruction_id(IrInstructionContainerInitList *) {
1014 return IrInstructionIdContainerInitList;
1408static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntToEnum *) {
1409 return IrInstSrcIdIntToEnum;
10151410}
10161411
1017static constexpr IrInstructionId ir_instruction_id(IrInstructionContainerInitFields *) {
1018 return IrInstructionIdContainerInitFields;
1412static constexpr IrInstSrcId ir_inst_id(IrInstSrcEnumToInt *) {
1413 return IrInstSrcIdEnumToInt;
10191414}
10201415
1021static constexpr IrInstructionId ir_instruction_id(IrInstructionUnreachable *) {
1022 return IrInstructionIdUnreachable;
1416static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntToErr *) {
1417 return IrInstSrcIdIntToErr;
10231418}
10241419
1025static constexpr IrInstructionId ir_instruction_id(IrInstructionTypeOf *) {
1026 return IrInstructionIdTypeOf;
1420static constexpr IrInstSrcId ir_inst_id(IrInstSrcErrToInt *) {
1421 return IrInstSrcIdErrToInt;
10271422}
10281423
1029static constexpr IrInstructionId ir_instruction_id(IrInstructionSetCold *) {
1030 return IrInstructionIdSetCold;
1424static constexpr IrInstSrcId ir_inst_id(IrInstSrcCheckSwitchProngs *) {
1425 return IrInstSrcIdCheckSwitchProngs;
10311426}
10321427
1033static constexpr IrInstructionId ir_instruction_id(IrInstructionSetRuntimeSafety *) {
1034 return IrInstructionIdSetRuntimeSafety;
1428static constexpr IrInstSrcId ir_inst_id(IrInstSrcCheckStatementIsVoid *) {
1429 return IrInstSrcIdCheckStatementIsVoid;
10351430}
10361431
1037static constexpr IrInstructionId ir_instruction_id(IrInstructionSetFloatMode *) {
1038 return IrInstructionIdSetFloatMode;
1432static constexpr IrInstSrcId ir_inst_id(IrInstSrcTypeName *) {
1433 return IrInstSrcIdTypeName;
10391434}
10401435
1041static constexpr IrInstructionId ir_instruction_id(IrInstructionArrayType *) {
1042 return IrInstructionIdArrayType;
1436static constexpr IrInstSrcId ir_inst_id(IrInstSrcDeclRef *) {
1437 return IrInstSrcIdDeclRef;
10431438}
10441439
1045static constexpr IrInstructionId ir_instruction_id(IrInstructionAnyFrameType *) {
1046 return IrInstructionIdAnyFrameType;
1440static constexpr IrInstSrcId ir_inst_id(IrInstSrcPanic *) {
1441 return IrInstSrcIdPanic;
10471442}
10481443
1049static constexpr IrInstructionId ir_instruction_id(IrInstructionSliceType *) {
1050 return IrInstructionIdSliceType;
1444static constexpr IrInstSrcId ir_inst_id(IrInstSrcTagName *) {
1445 return IrInstSrcIdTagName;
10511446}
10521447
1053static constexpr IrInstructionId ir_instruction_id(IrInstructionAsmSrc *) {
1054 return IrInstructionIdAsmSrc;
1448static constexpr IrInstSrcId ir_inst_id(IrInstSrcTagType *) {
1449 return IrInstSrcIdTagType;
10551450}
10561451
1057static constexpr IrInstructionId ir_instruction_id(IrInstructionAsmGen *) {
1058 return IrInstructionIdAsmGen;
1452static constexpr IrInstSrcId ir_inst_id(IrInstSrcFieldParentPtr *) {
1453 return IrInstSrcIdFieldParentPtr;
10591454}
10601455
1061static constexpr IrInstructionId ir_instruction_id(IrInstructionSizeOf *) {
1062 return IrInstructionIdSizeOf;
1456static constexpr IrInstSrcId ir_inst_id(IrInstSrcByteOffsetOf *) {
1457 return IrInstSrcIdByteOffsetOf;
10631458}
10641459
1065static constexpr IrInstructionId ir_instruction_id(IrInstructionTestNonNull *) {
1066 return IrInstructionIdTestNonNull;
1460static constexpr IrInstSrcId ir_inst_id(IrInstSrcBitOffsetOf *) {
1461 return IrInstSrcIdBitOffsetOf;
10671462}
10681463
1069static constexpr IrInstructionId ir_instruction_id(IrInstructionOptionalUnwrapPtr *) {
1070 return IrInstructionIdOptionalUnwrapPtr;
1464static constexpr IrInstSrcId ir_inst_id(IrInstSrcTypeInfo *) {
1465 return IrInstSrcIdTypeInfo;
10711466}
10721467
1073static constexpr IrInstructionId ir_instruction_id(IrInstructionClz *) {
1074 return IrInstructionIdClz;
1468static constexpr IrInstSrcId ir_inst_id(IrInstSrcType *) {
1469 return IrInstSrcIdType;
10751470}
10761471
1077static constexpr IrInstructionId ir_instruction_id(IrInstructionCtz *) {
1078 return IrInstructionIdCtz;
1472static constexpr IrInstSrcId ir_inst_id(IrInstSrcHasField *) {
1473 return IrInstSrcIdHasField;
10791474}
10801475
1081static constexpr IrInstructionId ir_instruction_id(IrInstructionPopCount *) {
1082 return IrInstructionIdPopCount;
1476static constexpr IrInstSrcId ir_inst_id(IrInstSrcTypeId *) {
1477 return IrInstSrcIdTypeId;
10831478}
10841479
1085static constexpr IrInstructionId ir_instruction_id(IrInstructionBswap *) {
1086 return IrInstructionIdBswap;
1480static constexpr IrInstSrcId ir_inst_id(IrInstSrcSetEvalBranchQuota *) {
1481 return IrInstSrcIdSetEvalBranchQuota;
10871482}
10881483
1089static constexpr IrInstructionId ir_instruction_id(IrInstructionBitReverse *) {
1090 return IrInstructionIdBitReverse;
1484static constexpr IrInstSrcId ir_inst_id(IrInstSrcPtrType *) {
1485 return IrInstSrcIdPtrType;
10911486}
10921487
1093static constexpr IrInstructionId ir_instruction_id(IrInstructionUnionTag *) {
1094 return IrInstructionIdUnionTag;
1488static constexpr IrInstSrcId ir_inst_id(IrInstSrcAlignCast *) {
1489 return IrInstSrcIdAlignCast;
10951490}
10961491
1097static constexpr IrInstructionId ir_instruction_id(IrInstructionImport *) {
1098 return IrInstructionIdImport;
1492static constexpr IrInstSrcId ir_inst_id(IrInstSrcImplicitCast *) {
1493 return IrInstSrcIdImplicitCast;
10991494}
11001495
1101static constexpr IrInstructionId ir_instruction_id(IrInstructionCImport *) {
1102 return IrInstructionIdCImport;
1496static constexpr IrInstSrcId ir_inst_id(IrInstSrcResolveResult *) {
1497 return IrInstSrcIdResolveResult;
11031498}
11041499
1105static constexpr IrInstructionId ir_instruction_id(IrInstructionCInclude *) {
1106 return IrInstructionIdCInclude;
1500static constexpr IrInstSrcId ir_inst_id(IrInstSrcResetResult *) {
1501 return IrInstSrcIdResetResult;
11071502}
11081503
1109static constexpr IrInstructionId ir_instruction_id(IrInstructionCDefine *) {
1110 return IrInstructionIdCDefine;
1504static constexpr IrInstSrcId ir_inst_id(IrInstSrcOpaqueType *) {
1505 return IrInstSrcIdOpaqueType;
11111506}
11121507
1113static constexpr IrInstructionId ir_instruction_id(IrInstructionCUndef *) {
1114 return IrInstructionIdCUndef;
1508static constexpr IrInstSrcId ir_inst_id(IrInstSrcSetAlignStack *) {
1509 return IrInstSrcIdSetAlignStack;
11151510}
11161511
1117static constexpr IrInstructionId ir_instruction_id(IrInstructionRef *) {
1118 return IrInstructionIdRef;
1512static constexpr IrInstSrcId ir_inst_id(IrInstSrcArgType *) {
1513 return IrInstSrcIdArgType;
11191514}
11201515
1121static constexpr IrInstructionId ir_instruction_id(IrInstructionRefGen *) {
1122 return IrInstructionIdRefGen;
1516static constexpr IrInstSrcId ir_inst_id(IrInstSrcExport *) {
1517 return IrInstSrcIdExport;
11231518}
11241519
1125static constexpr IrInstructionId ir_instruction_id(IrInstructionCompileErr *) {
1126 return IrInstructionIdCompileErr;
1520static constexpr IrInstSrcId ir_inst_id(IrInstSrcErrorReturnTrace *) {
1521 return IrInstSrcIdErrorReturnTrace;
11271522}
11281523
1129static constexpr IrInstructionId ir_instruction_id(IrInstructionCompileLog *) {
1130 return IrInstructionIdCompileLog;
1524static constexpr IrInstSrcId ir_inst_id(IrInstSrcErrorUnion *) {
1525 return IrInstSrcIdErrorUnion;
11311526}
11321527
1133static constexpr IrInstructionId ir_instruction_id(IrInstructionErrName *) {
1134 return IrInstructionIdErrName;
1528static constexpr IrInstSrcId ir_inst_id(IrInstSrcAtomicRmw *) {
1529 return IrInstSrcIdAtomicRmw;
11351530}
11361531
1137static constexpr IrInstructionId ir_instruction_id(IrInstructionEmbedFile *) {
1138 return IrInstructionIdEmbedFile;
1532static constexpr IrInstSrcId ir_inst_id(IrInstSrcAtomicLoad *) {
1533 return IrInstSrcIdAtomicLoad;
11391534}
11401535
1141static constexpr IrInstructionId ir_instruction_id(IrInstructionCmpxchgSrc *) {
1142 return IrInstructionIdCmpxchgSrc;
1536static constexpr IrInstSrcId ir_inst_id(IrInstSrcAtomicStore *) {
1537 return IrInstSrcIdAtomicStore;
11431538}
11441539
1145static constexpr IrInstructionId ir_instruction_id(IrInstructionCmpxchgGen *) {
1146 return IrInstructionIdCmpxchgGen;
1540static constexpr IrInstSrcId ir_inst_id(IrInstSrcSaveErrRetAddr *) {
1541 return IrInstSrcIdSaveErrRetAddr;
11471542}
11481543
1149static constexpr IrInstructionId ir_instruction_id(IrInstructionFence *) {
1150 return IrInstructionIdFence;
1544static constexpr IrInstSrcId ir_inst_id(IrInstSrcAddImplicitReturnType *) {
1545 return IrInstSrcIdAddImplicitReturnType;
11511546}
11521547
1153static constexpr IrInstructionId ir_instruction_id(IrInstructionTruncate *) {
1154 return IrInstructionIdTruncate;
1548static constexpr IrInstSrcId ir_inst_id(IrInstSrcErrSetCast *) {
1549 return IrInstSrcIdErrSetCast;
11551550}
11561551
1157static constexpr IrInstructionId ir_instruction_id(IrInstructionIntCast *) {
1158 return IrInstructionIdIntCast;
1552static constexpr IrInstSrcId ir_inst_id(IrInstSrcToBytes *) {
1553 return IrInstSrcIdToBytes;
11591554}
11601555
1161static constexpr IrInstructionId ir_instruction_id(IrInstructionFloatCast *) {
1162 return IrInstructionIdFloatCast;
1556static constexpr IrInstSrcId ir_inst_id(IrInstSrcFromBytes *) {
1557 return IrInstSrcIdFromBytes;
11631558}
11641559
1165static constexpr IrInstructionId ir_instruction_id(IrInstructionErrSetCast *) {
1166 return IrInstructionIdErrSetCast;
1560static constexpr IrInstSrcId ir_inst_id(IrInstSrcCheckRuntimeScope *) {
1561 return IrInstSrcIdCheckRuntimeScope;
11671562}
11681563
1169static constexpr IrInstructionId ir_instruction_id(IrInstructionToBytes *) {
1170 return IrInstructionIdToBytes;
1564static constexpr IrInstSrcId ir_inst_id(IrInstSrcHasDecl *) {
1565 return IrInstSrcIdHasDecl;
11711566}
11721567
1173static constexpr IrInstructionId ir_instruction_id(IrInstructionFromBytes *) {
1174 return IrInstructionIdFromBytes;
1568static constexpr IrInstSrcId ir_inst_id(IrInstSrcUndeclaredIdent *) {
1569 return IrInstSrcIdUndeclaredIdent;
11751570}
11761571
1177static constexpr IrInstructionId ir_instruction_id(IrInstructionIntToFloat *) {
1178 return IrInstructionIdIntToFloat;
1572static constexpr IrInstSrcId ir_inst_id(IrInstSrcAlloca *) {
1573 return IrInstSrcIdAlloca;
11791574}
11801575
1181static constexpr IrInstructionId ir_instruction_id(IrInstructionFloatToInt *) {
1182 return IrInstructionIdFloatToInt;
1576static constexpr IrInstSrcId ir_inst_id(IrInstSrcEndExpr *) {
1577 return IrInstSrcIdEndExpr;
11831578}
11841579
1185static constexpr IrInstructionId ir_instruction_id(IrInstructionBoolToInt *) {
1186 return IrInstructionIdBoolToInt;
1580static constexpr IrInstSrcId ir_inst_id(IrInstSrcUnionInitNamedField *) {
1581 return IrInstSrcIdUnionInitNamedField;
11871582}
11881583
1189static constexpr IrInstructionId ir_instruction_id(IrInstructionIntType *) {
1190 return IrInstructionIdIntType;
1584static constexpr IrInstSrcId ir_inst_id(IrInstSrcSuspendBegin *) {
1585 return IrInstSrcIdSuspendBegin;
11911586}
11921587
1193static constexpr IrInstructionId ir_instruction_id(IrInstructionVectorType *) {
1194 return IrInstructionIdVectorType;
1588static constexpr IrInstSrcId ir_inst_id(IrInstSrcSuspendFinish *) {
1589 return IrInstSrcIdSuspendFinish;
11951590}
11961591
1197static constexpr IrInstructionId ir_instruction_id(IrInstructionShuffleVector *) {
1198 return IrInstructionIdShuffleVector;
1592static constexpr IrInstSrcId ir_inst_id(IrInstSrcAwait *) {
1593 return IrInstSrcIdAwait;
11991594}
12001595
1201static constexpr IrInstructionId ir_instruction_id(IrInstructionSplatSrc *) {
1202 return IrInstructionIdSplatSrc;
1596static constexpr IrInstSrcId ir_inst_id(IrInstSrcResume *) {
1597 return IrInstSrcIdResume;
12031598}
12041599
1205static constexpr IrInstructionId ir_instruction_id(IrInstructionSplatGen *) {
1206 return IrInstructionIdSplatGen;
1600static constexpr IrInstSrcId ir_inst_id(IrInstSrcSpillBegin *) {
1601 return IrInstSrcIdSpillBegin;
12071602}
12081603
1209static constexpr IrInstructionId ir_instruction_id(IrInstructionBoolNot *) {
1210 return IrInstructionIdBoolNot;
1604static constexpr IrInstSrcId ir_inst_id(IrInstSrcSpillEnd *) {
1605 return IrInstSrcIdSpillEnd;
12111606}
12121607
1213static constexpr IrInstructionId ir_instruction_id(IrInstructionMemset *) {
1214 return IrInstructionIdMemset;
1608
1609static constexpr IrInstGenId ir_inst_id(IrInstGenDeclVar *) {
1610 return IrInstGenIdDeclVar;
12151611}
12161612
1217static constexpr IrInstructionId ir_instruction_id(IrInstructionMemcpy *) {
1218 return IrInstructionIdMemcpy;
1613static constexpr IrInstGenId ir_inst_id(IrInstGenBr *) {
1614 return IrInstGenIdBr;
12191615}
12201616
1221static constexpr IrInstructionId ir_instruction_id(IrInstructionSliceSrc *) {
1222 return IrInstructionIdSliceSrc;
1617static constexpr IrInstGenId ir_inst_id(IrInstGenCondBr *) {
1618 return IrInstGenIdCondBr;
12231619}
12241620
1225static constexpr IrInstructionId ir_instruction_id(IrInstructionSliceGen *) {
1226 return IrInstructionIdSliceGen;
1621static constexpr IrInstGenId ir_inst_id(IrInstGenSwitchBr *) {
1622 return IrInstGenIdSwitchBr;
12271623}
12281624
1229static constexpr IrInstructionId ir_instruction_id(IrInstructionMemberCount *) {
1230 return IrInstructionIdMemberCount;
1625static constexpr IrInstGenId ir_inst_id(IrInstGenPhi *) {
1626 return IrInstGenIdPhi;
12311627}
12321628
1233static constexpr IrInstructionId ir_instruction_id(IrInstructionMemberType *) {
1234 return IrInstructionIdMemberType;
1629static constexpr IrInstGenId ir_inst_id(IrInstGenBinaryNot *) {
1630 return IrInstGenIdBinaryNot;
12351631}
12361632
1237static constexpr IrInstructionId ir_instruction_id(IrInstructionMemberName *) {
1238 return IrInstructionIdMemberName;
1633static constexpr IrInstGenId ir_inst_id(IrInstGenNegation *) {
1634 return IrInstGenIdNegation;
12391635}
12401636
1241static constexpr IrInstructionId ir_instruction_id(IrInstructionBreakpoint *) {
1242 return IrInstructionIdBreakpoint;
1637static constexpr IrInstGenId ir_inst_id(IrInstGenNegationWrapping *) {
1638 return IrInstGenIdNegationWrapping;
12431639}
12441640
1245static constexpr IrInstructionId ir_instruction_id(IrInstructionReturnAddress *) {
1246 return IrInstructionIdReturnAddress;
1641static constexpr IrInstGenId ir_inst_id(IrInstGenBinOp *) {
1642 return IrInstGenIdBinOp;
12471643}
12481644
1249static constexpr IrInstructionId ir_instruction_id(IrInstructionFrameAddress *) {
1250 return IrInstructionIdFrameAddress;
1645static constexpr IrInstGenId ir_inst_id(IrInstGenLoadPtr *) {
1646 return IrInstGenIdLoadPtr;
12511647}
12521648
1253static constexpr IrInstructionId ir_instruction_id(IrInstructionFrameHandle *) {
1254 return IrInstructionIdFrameHandle;
1649static constexpr IrInstGenId ir_inst_id(IrInstGenStorePtr *) {
1650 return IrInstGenIdStorePtr;
12551651}
12561652
1257static constexpr IrInstructionId ir_instruction_id(IrInstructionFrameType *) {
1258 return IrInstructionIdFrameType;
1653static constexpr IrInstGenId ir_inst_id(IrInstGenVectorStoreElem *) {
1654 return IrInstGenIdVectorStoreElem;
12591655}
12601656
1261static constexpr IrInstructionId ir_instruction_id(IrInstructionFrameSizeSrc *) {
1262 return IrInstructionIdFrameSizeSrc;
1657static constexpr IrInstGenId ir_inst_id(IrInstGenStructFieldPtr *) {
1658 return IrInstGenIdStructFieldPtr;
12631659}
12641660
1265static constexpr IrInstructionId ir_instruction_id(IrInstructionFrameSizeGen *) {
1266 return IrInstructionIdFrameSizeGen;
1661static constexpr IrInstGenId ir_inst_id(IrInstGenUnionFieldPtr *) {
1662 return IrInstGenIdUnionFieldPtr;
12671663}
12681664
1269static constexpr IrInstructionId ir_instruction_id(IrInstructionAlignOf *) {
1270 return IrInstructionIdAlignOf;
1665static constexpr IrInstGenId ir_inst_id(IrInstGenElemPtr *) {
1666 return IrInstGenIdElemPtr;
12711667}
12721668
1273static constexpr IrInstructionId ir_instruction_id(IrInstructionOverflowOp *) {
1274 return IrInstructionIdOverflowOp;
1669static constexpr IrInstGenId ir_inst_id(IrInstGenVarPtr *) {
1670 return IrInstGenIdVarPtr;
12751671}
12761672
1277static constexpr IrInstructionId ir_instruction_id(IrInstructionTestErrSrc *) {
1278 return IrInstructionIdTestErrSrc;
1673static constexpr IrInstGenId ir_inst_id(IrInstGenReturnPtr *) {
1674 return IrInstGenIdReturnPtr;
12791675}
12801676
1281static constexpr IrInstructionId ir_instruction_id(IrInstructionTestErrGen *) {
1282 return IrInstructionIdTestErrGen;
1677static constexpr IrInstGenId ir_inst_id(IrInstGenCall *) {
1678 return IrInstGenIdCall;
12831679}
12841680
1285static constexpr IrInstructionId ir_instruction_id(IrInstructionMulAdd *) {
1286 return IrInstructionIdMulAdd;
1681static constexpr IrInstGenId ir_inst_id(IrInstGenReturn *) {
1682 return IrInstGenIdReturn;
12871683}
12881684
1289static constexpr IrInstructionId ir_instruction_id(IrInstructionUnwrapErrCode *) {
1290 return IrInstructionIdUnwrapErrCode;
1685static constexpr IrInstGenId ir_inst_id(IrInstGenCast *) {
1686 return IrInstGenIdCast;
12911687}
12921688
1293static constexpr IrInstructionId ir_instruction_id(IrInstructionUnwrapErrPayload *) {
1294 return IrInstructionIdUnwrapErrPayload;
1689static constexpr IrInstGenId ir_inst_id(IrInstGenResizeSlice *) {
1690 return IrInstGenIdResizeSlice;
12951691}
12961692
1297static constexpr IrInstructionId ir_instruction_id(IrInstructionOptionalWrap *) {
1298 return IrInstructionIdOptionalWrap;
1693static constexpr IrInstGenId ir_inst_id(IrInstGenUnreachable *) {
1694 return IrInstGenIdUnreachable;
12991695}
13001696
1301static constexpr IrInstructionId ir_instruction_id(IrInstructionErrWrapPayload *) {
1302 return IrInstructionIdErrWrapPayload;
1697static constexpr IrInstGenId ir_inst_id(IrInstGenAsm *) {
1698 return IrInstGenIdAsm;
13031699}
13041700
1305static constexpr IrInstructionId ir_instruction_id(IrInstructionErrWrapCode *) {
1306 return IrInstructionIdErrWrapCode;
1701static constexpr IrInstGenId ir_inst_id(IrInstGenTestNonNull *) {
1702 return IrInstGenIdTestNonNull;
13071703}
13081704
1309static constexpr IrInstructionId ir_instruction_id(IrInstructionFnProto *) {
1310 return IrInstructionIdFnProto;
1705static constexpr IrInstGenId ir_inst_id(IrInstGenOptionalUnwrapPtr *) {
1706 return IrInstGenIdOptionalUnwrapPtr;
13111707}
13121708
1313static constexpr IrInstructionId ir_instruction_id(IrInstructionTestComptime *) {
1314 return IrInstructionIdTestComptime;
1709static constexpr IrInstGenId ir_inst_id(IrInstGenOptionalWrap *) {
1710 return IrInstGenIdOptionalWrap;
13151711}
13161712
1317static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrCastSrc *) {
1318 return IrInstructionIdPtrCastSrc;
1713static constexpr IrInstGenId ir_inst_id(IrInstGenUnionTag *) {
1714 return IrInstGenIdUnionTag;
13191715}
13201716
1321static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrCastGen *) {
1322 return IrInstructionIdPtrCastGen;
1717static constexpr IrInstGenId ir_inst_id(IrInstGenClz *) {
1718 return IrInstGenIdClz;
13231719}
13241720
1325static constexpr IrInstructionId ir_instruction_id(IrInstructionBitCastSrc *) {
1326 return IrInstructionIdBitCastSrc;
1721static constexpr IrInstGenId ir_inst_id(IrInstGenCtz *) {
1722 return IrInstGenIdCtz;
13271723}
13281724
1329static constexpr IrInstructionId ir_instruction_id(IrInstructionBitCastGen *) {
1330 return IrInstructionIdBitCastGen;
1725static constexpr IrInstGenId ir_inst_id(IrInstGenPopCount *) {
1726 return IrInstGenIdPopCount;
13311727}
13321728
1333static constexpr IrInstructionId ir_instruction_id(IrInstructionWidenOrShorten *) {
1334 return IrInstructionIdWidenOrShorten;
1729static constexpr IrInstGenId ir_inst_id(IrInstGenBswap *) {
1730 return IrInstGenIdBswap;
13351731}
13361732
1337static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrToInt *) {
1338 return IrInstructionIdPtrToInt;
1733static constexpr IrInstGenId ir_inst_id(IrInstGenBitReverse *) {
1734 return IrInstGenIdBitReverse;
13391735}
13401736
1341static constexpr IrInstructionId ir_instruction_id(IrInstructionIntToPtr *) {
1342 return IrInstructionIdIntToPtr;
1737static constexpr IrInstGenId ir_inst_id(IrInstGenRef *) {
1738 return IrInstGenIdRef;
13431739}
13441740
1345static constexpr IrInstructionId ir_instruction_id(IrInstructionIntToEnum *) {
1346 return IrInstructionIdIntToEnum;
1741static constexpr IrInstGenId ir_inst_id(IrInstGenErrName *) {
1742 return IrInstGenIdErrName;
13471743}
13481744
1349static constexpr IrInstructionId ir_instruction_id(IrInstructionEnumToInt *) {
1350 return IrInstructionIdEnumToInt;
1745static constexpr IrInstGenId ir_inst_id(IrInstGenCmpxchg *) {
1746 return IrInstGenIdCmpxchg;
13511747}
13521748
1353static constexpr IrInstructionId ir_instruction_id(IrInstructionIntToErr *) {
1354 return IrInstructionIdIntToErr;
1749static constexpr IrInstGenId ir_inst_id(IrInstGenFence *) {
1750 return IrInstGenIdFence;
13551751}
13561752
1357static constexpr IrInstructionId ir_instruction_id(IrInstructionErrToInt *) {
1358 return IrInstructionIdErrToInt;
1753static constexpr IrInstGenId ir_inst_id(IrInstGenTruncate *) {
1754 return IrInstGenIdTruncate;
13591755}
13601756
1361static constexpr IrInstructionId ir_instruction_id(IrInstructionCheckSwitchProngs *) {
1362 return IrInstructionIdCheckSwitchProngs;
1757static constexpr IrInstGenId ir_inst_id(IrInstGenShuffleVector *) {
1758 return IrInstGenIdShuffleVector;
13631759}
13641760
1365static constexpr IrInstructionId ir_instruction_id(IrInstructionCheckStatementIsVoid *) {
1366 return IrInstructionIdCheckStatementIsVoid;
1761static constexpr IrInstGenId ir_inst_id(IrInstGenSplat *) {
1762 return IrInstGenIdSplat;
13671763}
13681764
1369static constexpr IrInstructionId ir_instruction_id(IrInstructionTypeName *) {
1370 return IrInstructionIdTypeName;
1765static constexpr IrInstGenId ir_inst_id(IrInstGenBoolNot *) {
1766 return IrInstGenIdBoolNot;
13711767}
13721768
1373static constexpr IrInstructionId ir_instruction_id(IrInstructionDeclRef *) {
1374 return IrInstructionIdDeclRef;
1769static constexpr IrInstGenId ir_inst_id(IrInstGenMemset *) {
1770 return IrInstGenIdMemset;
13751771}
13761772
1377static constexpr IrInstructionId ir_instruction_id(IrInstructionPanic *) {
1378 return IrInstructionIdPanic;
1773static constexpr IrInstGenId ir_inst_id(IrInstGenMemcpy *) {
1774 return IrInstGenIdMemcpy;
13791775}
13801776
1381static constexpr IrInstructionId ir_instruction_id(IrInstructionTagName *) {
1382 return IrInstructionIdTagName;
1777static constexpr IrInstGenId ir_inst_id(IrInstGenSlice *) {
1778 return IrInstGenIdSlice;
13831779}
13841780
1385static constexpr IrInstructionId ir_instruction_id(IrInstructionTagType *) {
1386 return IrInstructionIdTagType;
1781static constexpr IrInstGenId ir_inst_id(IrInstGenBreakpoint *) {
1782 return IrInstGenIdBreakpoint;
13871783}
13881784
1389static constexpr IrInstructionId ir_instruction_id(IrInstructionFieldParentPtr *) {
1390 return IrInstructionIdFieldParentPtr;
1785static constexpr IrInstGenId ir_inst_id(IrInstGenReturnAddress *) {
1786 return IrInstGenIdReturnAddress;
13911787}
13921788
1393static constexpr IrInstructionId ir_instruction_id(IrInstructionByteOffsetOf *) {
1394 return IrInstructionIdByteOffsetOf;
1789static constexpr IrInstGenId ir_inst_id(IrInstGenFrameAddress *) {
1790 return IrInstGenIdFrameAddress;
13951791}
13961792
1397static constexpr IrInstructionId ir_instruction_id(IrInstructionBitOffsetOf *) {
1398 return IrInstructionIdBitOffsetOf;
1793static constexpr IrInstGenId ir_inst_id(IrInstGenFrameHandle *) {
1794 return IrInstGenIdFrameHandle;
13991795}
14001796
1401static constexpr IrInstructionId ir_instruction_id(IrInstructionTypeInfo *) {
1402 return IrInstructionIdTypeInfo;
1797static constexpr IrInstGenId ir_inst_id(IrInstGenFrameSize *) {
1798 return IrInstGenIdFrameSize;
14031799}
14041800
1405static constexpr IrInstructionId ir_instruction_id(IrInstructionType *) {
1406 return IrInstructionIdType;
1801static constexpr IrInstGenId ir_inst_id(IrInstGenOverflowOp *) {
1802 return IrInstGenIdOverflowOp;
14071803}
14081804
1409static constexpr IrInstructionId ir_instruction_id(IrInstructionHasField *) {
1410 return IrInstructionIdHasField;
1805static constexpr IrInstGenId ir_inst_id(IrInstGenTestErr *) {
1806 return IrInstGenIdTestErr;
14111807}
14121808
1413static constexpr IrInstructionId ir_instruction_id(IrInstructionTypeId *) {
1414 return IrInstructionIdTypeId;
1809static constexpr IrInstGenId ir_inst_id(IrInstGenMulAdd *) {
1810 return IrInstGenIdMulAdd;
14151811}
14161812
1417static constexpr IrInstructionId ir_instruction_id(IrInstructionSetEvalBranchQuota *) {
1418 return IrInstructionIdSetEvalBranchQuota;
1813static constexpr IrInstGenId ir_inst_id(IrInstGenFloatOp *) {
1814 return IrInstGenIdFloatOp;
14191815}
14201816
1421static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrType *) {
1422 return IrInstructionIdPtrType;
1817static constexpr IrInstGenId ir_inst_id(IrInstGenUnwrapErrCode *) {
1818 return IrInstGenIdUnwrapErrCode;
14231819}
14241820
1425static constexpr IrInstructionId ir_instruction_id(IrInstructionAlignCast *) {
1426 return IrInstructionIdAlignCast;
1821static constexpr IrInstGenId ir_inst_id(IrInstGenUnwrapErrPayload *) {
1822 return IrInstGenIdUnwrapErrPayload;
14271823}
14281824
1429static constexpr IrInstructionId ir_instruction_id(IrInstructionImplicitCast *) {
1430 return IrInstructionIdImplicitCast;
1825static constexpr IrInstGenId ir_inst_id(IrInstGenErrWrapCode *) {
1826 return IrInstGenIdErrWrapCode;
14311827}
14321828
1433static constexpr IrInstructionId ir_instruction_id(IrInstructionResolveResult *) {
1434 return IrInstructionIdResolveResult;
1829static constexpr IrInstGenId ir_inst_id(IrInstGenErrWrapPayload *) {
1830 return IrInstGenIdErrWrapPayload;
14351831}
14361832
1437static constexpr IrInstructionId ir_instruction_id(IrInstructionResetResult *) {
1438 return IrInstructionIdResetResult;
1833static constexpr IrInstGenId ir_inst_id(IrInstGenPtrCast *) {
1834 return IrInstGenIdPtrCast;
14391835}
14401836
1441static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrOfArrayToSlice *) {
1442 return IrInstructionIdPtrOfArrayToSlice;
1837static constexpr IrInstGenId ir_inst_id(IrInstGenBitCast *) {
1838 return IrInstGenIdBitCast;
14431839}
14441840
1445static constexpr IrInstructionId ir_instruction_id(IrInstructionOpaqueType *) {
1446 return IrInstructionIdOpaqueType;
1841static constexpr IrInstGenId ir_inst_id(IrInstGenWidenOrShorten *) {
1842 return IrInstGenIdWidenOrShorten;
14471843}
14481844
1449static constexpr IrInstructionId ir_instruction_id(IrInstructionSetAlignStack *) {
1450 return IrInstructionIdSetAlignStack;
1845static constexpr IrInstGenId ir_inst_id(IrInstGenIntToPtr *) {
1846 return IrInstGenIdIntToPtr;
14511847}
14521848
1453static constexpr IrInstructionId ir_instruction_id(IrInstructionArgType *) {
1454 return IrInstructionIdArgType;
1849static constexpr IrInstGenId ir_inst_id(IrInstGenPtrToInt *) {
1850 return IrInstGenIdPtrToInt;
14551851}
14561852
1457static constexpr IrInstructionId ir_instruction_id(IrInstructionErrorReturnTrace *) {
1458 return IrInstructionIdErrorReturnTrace;
1853static constexpr IrInstGenId ir_inst_id(IrInstGenIntToEnum *) {
1854 return IrInstGenIdIntToEnum;
14591855}
14601856
1461static constexpr IrInstructionId ir_instruction_id(IrInstructionErrorUnion *) {
1462 return IrInstructionIdErrorUnion;
1857static constexpr IrInstGenId ir_inst_id(IrInstGenIntToErr *) {
1858 return IrInstGenIdIntToErr;
14631859}
14641860
1465static constexpr IrInstructionId ir_instruction_id(IrInstructionAtomicRmw *) {
1466 return IrInstructionIdAtomicRmw;
1861static constexpr IrInstGenId ir_inst_id(IrInstGenErrToInt *) {
1862 return IrInstGenIdErrToInt;
14671863}
14681864
1469static constexpr IrInstructionId ir_instruction_id(IrInstructionAtomicLoad *) {
1470 return IrInstructionIdAtomicLoad;
1865static constexpr IrInstGenId ir_inst_id(IrInstGenPanic *) {
1866 return IrInstGenIdPanic;
14711867}
14721868
1473static constexpr IrInstructionId ir_instruction_id(IrInstructionAtomicStore *) {
1474 return IrInstructionIdAtomicStore;
1869static constexpr IrInstGenId ir_inst_id(IrInstGenTagName *) {
1870 return IrInstGenIdTagName;
14751871}
14761872
1477static constexpr IrInstructionId ir_instruction_id(IrInstructionSaveErrRetAddr *) {
1478 return IrInstructionIdSaveErrRetAddr;
1873static constexpr IrInstGenId ir_inst_id(IrInstGenFieldParentPtr *) {
1874 return IrInstGenIdFieldParentPtr;
14791875}
14801876
1481static constexpr IrInstructionId ir_instruction_id(IrInstructionAddImplicitReturnType *) {
1482 return IrInstructionIdAddImplicitReturnType;
1877static constexpr IrInstGenId ir_inst_id(IrInstGenAlignCast *) {
1878 return IrInstGenIdAlignCast;
14831879}
14841880
1485static constexpr IrInstructionId ir_instruction_id(IrInstructionFloatOp *) {
1486 return IrInstructionIdFloatOp;
1881static constexpr IrInstGenId ir_inst_id(IrInstGenErrorReturnTrace *) {
1882 return IrInstGenIdErrorReturnTrace;
14871883}
14881884
1489static constexpr IrInstructionId ir_instruction_id(IrInstructionCheckRuntimeScope *) {
1490 return IrInstructionIdCheckRuntimeScope;
1885static constexpr IrInstGenId ir_inst_id(IrInstGenAtomicRmw *) {
1886 return IrInstGenIdAtomicRmw;
14911887}
14921888
1493static constexpr IrInstructionId ir_instruction_id(IrInstructionVectorToArray *) {
1494 return IrInstructionIdVectorToArray;
1889static constexpr IrInstGenId ir_inst_id(IrInstGenAtomicLoad *) {
1890 return IrInstGenIdAtomicLoad;
14951891}
14961892
1497static constexpr IrInstructionId ir_instruction_id(IrInstructionArrayToVector *) {
1498 return IrInstructionIdArrayToVector;
1893static constexpr IrInstGenId ir_inst_id(IrInstGenAtomicStore *) {
1894 return IrInstGenIdAtomicStore;
14991895}
15001896
1501static constexpr IrInstructionId ir_instruction_id(IrInstructionAssertZero *) {
1502 return IrInstructionIdAssertZero;
1897static constexpr IrInstGenId ir_inst_id(IrInstGenSaveErrRetAddr *) {
1898 return IrInstGenIdSaveErrRetAddr;
15031899}
15041900
1505static constexpr IrInstructionId ir_instruction_id(IrInstructionAssertNonNull *) {
1506 return IrInstructionIdAssertNonNull;
1901static constexpr IrInstGenId ir_inst_id(IrInstGenVectorToArray *) {
1902 return IrInstGenIdVectorToArray;
15071903}
15081904
1509static constexpr IrInstructionId ir_instruction_id(IrInstructionHasDecl *) {
1510 return IrInstructionIdHasDecl;
1905static constexpr IrInstGenId ir_inst_id(IrInstGenArrayToVector *) {
1906 return IrInstGenIdArrayToVector;
15111907}
15121908
1513static constexpr IrInstructionId ir_instruction_id(IrInstructionUndeclaredIdent *) {
1514 return IrInstructionIdUndeclaredIdent;
1909static constexpr IrInstGenId ir_inst_id(IrInstGenAssertZero *) {
1910 return IrInstGenIdAssertZero;
15151911}
15161912
1517static constexpr IrInstructionId ir_instruction_id(IrInstructionAllocaSrc *) {
1518 return IrInstructionIdAllocaSrc;
1913static constexpr IrInstGenId ir_inst_id(IrInstGenAssertNonNull *) {
1914 return IrInstGenIdAssertNonNull;
15191915}
15201916
1521static constexpr IrInstructionId ir_instruction_id(IrInstructionAllocaGen *) {
1522 return IrInstructionIdAllocaGen;
1917static constexpr IrInstGenId ir_inst_id(IrInstGenPtrOfArrayToSlice *) {
1918 return IrInstGenIdPtrOfArrayToSlice;
15231919}
15241920
1525static constexpr IrInstructionId ir_instruction_id(IrInstructionEndExpr *) {
1526 return IrInstructionIdEndExpr;
1921static constexpr IrInstGenId ir_inst_id(IrInstGenSuspendBegin *) {
1922 return IrInstGenIdSuspendBegin;
15271923}
15281924
1529static constexpr IrInstructionId ir_instruction_id(IrInstructionUnionInitNamedField *) {
1530 return IrInstructionIdUnionInitNamedField;
1925static constexpr IrInstGenId ir_inst_id(IrInstGenSuspendFinish *) {
1926 return IrInstGenIdSuspendFinish;
15311927}
15321928
1533static constexpr IrInstructionId ir_instruction_id(IrInstructionSuspendBegin *) {
1534 return IrInstructionIdSuspendBegin;
1929static constexpr IrInstGenId ir_inst_id(IrInstGenAwait *) {
1930 return IrInstGenIdAwait;
15351931}
15361932
1537static constexpr IrInstructionId ir_instruction_id(IrInstructionSuspendFinish *) {
1538 return IrInstructionIdSuspendFinish;
1933static constexpr IrInstGenId ir_inst_id(IrInstGenResume *) {
1934 return IrInstGenIdResume;
15391935}
15401936
1541static constexpr IrInstructionId ir_instruction_id(IrInstructionAwaitSrc *) {
1542 return IrInstructionIdAwaitSrc;
1937static constexpr IrInstGenId ir_inst_id(IrInstGenSpillBegin *) {
1938 return IrInstGenIdSpillBegin;
15431939}
15441940
1545static constexpr IrInstructionId ir_instruction_id(IrInstructionAwaitGen *) {
1546 return IrInstructionIdAwaitGen;
1941static constexpr IrInstGenId ir_inst_id(IrInstGenSpillEnd *) {
1942 return IrInstGenIdSpillEnd;
15471943}
15481944
1549static constexpr IrInstructionId ir_instruction_id(IrInstructionResume *) {
1550 return IrInstructionIdResume;
1945static constexpr IrInstGenId ir_inst_id(IrInstGenVectorExtractElem *) {
1946 return IrInstGenIdVectorExtractElem;
15511947}
15521948
1553static constexpr IrInstructionId ir_instruction_id(IrInstructionSpillBegin *) {
1554 return IrInstructionIdSpillBegin;
1949static constexpr IrInstGenId ir_inst_id(IrInstGenAlloca *) {
1950 return IrInstGenIdAlloca;
15551951}
15561952
1557static constexpr IrInstructionId ir_instruction_id(IrInstructionSpillEnd *) {
1558 return IrInstructionIdSpillEnd;
1953static constexpr IrInstGenId ir_inst_id(IrInstGenConst *) {
1954 return IrInstGenIdConst;
15591955}
15601956
1561static constexpr IrInstructionId ir_instruction_id(IrInstructionVectorExtractElem *) {
1562 return IrInstructionIdVectorExtractElem;
1957template<typename T>
1958static T *ir_create_instruction(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
1959 const char *name = nullptr;
1960#ifdef ZIG_ENABLE_MEM_PROFILE
1961 T *dummy = nullptr;
1962 name = ir_inst_src_type_str(ir_inst_id(dummy));
1963#endif
1964 T *special_instruction = allocate<T>(1, name);
1965 special_instruction->base.id = ir_inst_id(special_instruction);
1966 special_instruction->base.base.scope = scope;
1967 special_instruction->base.base.source_node = source_node;
1968 special_instruction->base.base.debug_id = exec_next_debug_id(irb->exec);
1969 special_instruction->base.owner_bb = irb->current_basic_block;
1970 return special_instruction;
15631971}
15641972
15651973template<typename T>
1566static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node) {
1974static T *ir_create_inst_gen(IrBuilderGen *irb, Scope *scope, AstNode *source_node) {
15671975 const char *name = nullptr;
15681976#ifdef ZIG_ENABLE_MEM_PROFILE
15691977 T *dummy = nullptr;
1570 name = ir_instruction_type_str(ir_instruction_id(dummy));
1978 name = ir_inst_gen_type_str(ir_inst_id(dummy));
15711979#endif
15721980 T *special_instruction = allocate<T>(1, name);
1573 special_instruction->base.id = ir_instruction_id(special_instruction);
1574 special_instruction->base.scope = scope;
1575 special_instruction->base.source_node = source_node;
1576 special_instruction->base.debug_id = exec_next_debug_id(irb->exec);
1981 special_instruction->base.id = ir_inst_id(special_instruction);
1982 special_instruction->base.base.scope = scope;
1983 special_instruction->base.base.source_node = source_node;
1984 special_instruction->base.base.debug_id = exec_next_debug_id_gen(irb->exec);
15771985 special_instruction->base.owner_bb = irb->current_basic_block;
15781986 special_instruction->base.value = allocate<ZigValue>(1, "ZigValue");
15791987 return special_instruction;
15801988}
15811989
15821990template<typename T>
1583static T *ir_create_instruction_noval(IrBuilder *irb, Scope *scope, AstNode *source_node) {
1991static T *ir_create_inst_noval(IrBuilderGen *irb, Scope *scope, AstNode *source_node) {
15841992 const char *name = nullptr;
15851993#ifdef ZIG_ENABLE_MEM_PROFILE
15861994 T *dummy = nullptr;
1587 name = ir_instruction_type_str(ir_instruction_id(dummy));
1995 name = ir_inst_gen_type_str(ir_inst_id(dummy));
15881996#endif
15891997 T *special_instruction = allocate<T>(1, name);
1590 special_instruction->base.id = ir_instruction_id(special_instruction);
1591 special_instruction->base.scope = scope;
1592 special_instruction->base.source_node = source_node;
1593 special_instruction->base.debug_id = exec_next_debug_id(irb->exec);
1998 special_instruction->base.id = ir_inst_id(special_instruction);
1999 special_instruction->base.base.scope = scope;
2000 special_instruction->base.base.source_node = source_node;
2001 special_instruction->base.base.debug_id = exec_next_debug_id_gen(irb->exec);
15942002 special_instruction->base.owner_bb = irb->current_basic_block;
15952003 return special_instruction;
15962004}
15972005
15982006template<typename T>
1599static T *ir_build_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node) {
2007static T *ir_build_instruction(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
16002008 T *special_instruction = ir_create_instruction<T>(irb, scope, source_node);
16012009 ir_instruction_append(irb->current_basic_block, &special_instruction->base);
16022010 return special_instruction;
16032011}
16042012
1605static IrInstruction *ir_build_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigType *dest_type,
1606 IrInstruction *value, CastOp cast_op)
2013template<typename T>
2014static T *ir_build_inst_gen(IrBuilderGen *irb, Scope *scope, AstNode *source_node) {
2015 T *special_instruction = ir_create_inst_gen<T>(irb, scope, source_node);
2016 ir_inst_gen_append(irb->current_basic_block, &special_instruction->base);
2017 return special_instruction;
2018}
2019
2020template<typename T>
2021static T *ir_build_inst_noreturn(IrBuilderGen *irb, Scope *scope, AstNode *source_node) {
2022 T *special_instruction = ir_create_inst_noval<T>(irb, scope, source_node);
2023 special_instruction->base.value = irb->codegen->intern.for_unreachable();
2024 ir_inst_gen_append(irb->current_basic_block, &special_instruction->base);
2025 return special_instruction;
2026}
2027
2028template<typename T>
2029static T *ir_build_inst_void(IrBuilderGen *irb, Scope *scope, AstNode *source_node) {
2030 T *special_instruction = ir_create_inst_noval<T>(irb, scope, source_node);
2031 special_instruction->base.value = irb->codegen->intern.for_void();
2032 ir_inst_gen_append(irb->current_basic_block, &special_instruction->base);
2033 return special_instruction;
2034}
2035
2036IrInstGen *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node, ZigFn *fn,
2037 ZigType *var_type, const char *name_hint)
16072038{
1608 IrInstructionCast *cast_instruction = ir_build_instruction<IrInstructionCast>(irb, scope, source_node);
1609 cast_instruction->dest_type = dest_type;
1610 cast_instruction->value = value;
1611 cast_instruction->cast_op = cast_op;
2039 IrInstGenAlloca *alloca_gen = allocate<IrInstGenAlloca>(1);
2040 alloca_gen->base.id = IrInstGenIdAlloca;
2041 alloca_gen->base.base.source_node = source_node;
2042 alloca_gen->base.base.scope = scope;
2043 alloca_gen->base.value = allocate<ZigValue>(1, "ZigValue");
2044 alloca_gen->base.value->type = get_pointer_to_type(g, var_type, false);
2045 alloca_gen->base.base.ref_count = 1;
2046 alloca_gen->name_hint = name_hint;
2047 fn->alloca_gen_list.append(alloca_gen);
2048 return &alloca_gen->base;
2049}
16122050
1613 ir_ref_instruction(value, irb->current_basic_block);
2051static IrInstGen *ir_build_cast(IrAnalyze *ira, IrInst *source_instr,ZigType *dest_type,
2052 IrInstGen *value, CastOp cast_op)
2053{
2054 IrInstGenCast *inst = ir_build_inst_gen<IrInstGenCast>(&ira->new_irb, source_instr->scope, source_instr->source_node);
2055 inst->base.value->type = dest_type;
2056 inst->value = value;
2057 inst->cast_op = cast_op;
16142058
1615 return &cast_instruction->base;
2059 ir_ref_inst_gen(value, ira->new_irb.current_basic_block);
2060
2061 return &inst->base;
16162062}
16172063
1618static IrInstruction *ir_build_cond_br(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *condition,
1619 IrBasicBlock *then_block, IrBasicBlock *else_block, IrInstruction *is_comptime)
2064static IrInstSrc *ir_build_cond_br(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *condition,
2065 IrBasicBlockSrc *then_block, IrBasicBlockSrc *else_block, IrInstSrc *is_comptime)
16202066{
1621 IrInstructionCondBr *cond_br_instruction = ir_build_instruction<IrInstructionCondBr>(irb, scope, source_node);
1622 cond_br_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;
1623 cond_br_instruction->base.value->special = ConstValSpecialStatic;
1624 cond_br_instruction->condition = condition;
1625 cond_br_instruction->then_block = then_block;
1626 cond_br_instruction->else_block = else_block;
1627 cond_br_instruction->is_comptime = is_comptime;
2067 IrInstSrcCondBr *inst = ir_build_instruction<IrInstSrcCondBr>(irb, scope, source_node);
2068 inst->base.is_noreturn = true;
2069 inst->condition = condition;
2070 inst->then_block = then_block;
2071 inst->else_block = else_block;
2072 inst->is_comptime = is_comptime;
16282073
16292074 ir_ref_instruction(condition, irb->current_basic_block);
16302075 ir_ref_bb(then_block);
16312076 ir_ref_bb(else_block);
16322077 if (is_comptime != nullptr) ir_ref_instruction(is_comptime, irb->current_basic_block);
16332078
1634 return &cond_br_instruction->base;
2079 return &inst->base;
16352080}
16362081
1637static IrInstruction *ir_build_return(IrBuilder *irb, Scope *scope, AstNode *source_node,
1638 IrInstruction *operand)
2082static IrInstGen *ir_build_cond_br_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *condition,
2083 IrBasicBlockGen *then_block, IrBasicBlockGen *else_block)
16392084{
1640 IrInstructionReturn *return_instruction = ir_build_instruction<IrInstructionReturn>(irb, scope, source_node);
1641 return_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;
1642 return_instruction->base.value->special = ConstValSpecialStatic;
1643 return_instruction->operand = operand;
2085 IrInstGenCondBr *inst = ir_build_inst_noreturn<IrInstGenCondBr>(&ira->new_irb, source_instr->scope, source_instr->source_node);
2086 inst->condition = condition;
2087 inst->then_block = then_block;
2088 inst->else_block = else_block;
2089
2090 ir_ref_inst_gen(condition, ira->new_irb.current_basic_block);
2091 ir_ref_bb_gen(then_block);
2092 ir_ref_bb_gen(else_block);
2093
2094 return &inst->base;
2095}
2096
2097static IrInstSrc *ir_build_return_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *operand) {
2098 IrInstSrcReturn *inst = ir_build_instruction<IrInstSrcReturn>(irb, scope, source_node);
2099 inst->base.is_noreturn = true;
2100 inst->operand = operand;
16442101
16452102 if (operand != nullptr) ir_ref_instruction(operand, irb->current_basic_block);
16462103
1647 return &return_instruction->base;
2104 return &inst->base;
2105}
2106
2107static IrInstGen *ir_build_return_gen(IrAnalyze *ira, IrInst *source_inst, IrInstGen *operand) {
2108 IrInstGenReturn *inst = ir_build_inst_noreturn<IrInstGenReturn>(&ira->new_irb,
2109 source_inst->scope, source_inst->source_node);
2110 inst->operand = operand;
2111
2112 if (operand != nullptr) ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
2113
2114 return &inst->base;
16482115}
16492116
1650static IrInstruction *ir_build_const_void(IrBuilder *irb, Scope *scope, AstNode *source_node) {
1651 IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(irb, scope, source_node);
2117static IrInstSrc *ir_build_const_void(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
2118 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node);
16522119 ir_instruction_append(irb->current_basic_block, &const_instruction->base);
1653 const_instruction->base.value = irb->codegen->intern.for_void();
2120 const_instruction->value = irb->codegen->intern.for_void();
16542121 return &const_instruction->base;
16552122}
16562123
1657static IrInstruction *ir_build_const_undefined(IrBuilder *irb, Scope *scope, AstNode *source_node) {
1658 IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(irb, scope, source_node);
2124static IrInstSrc *ir_build_const_undefined(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
2125 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node);
16592126 ir_instruction_append(irb->current_basic_block, &const_instruction->base);
1660 const_instruction->base.value = irb->codegen->intern.for_undefined();
2127 const_instruction->value = irb->codegen->intern.for_undefined();
16612128 return &const_instruction->base;
16622129}
16632130
1664static IrInstruction *ir_build_const_uint(IrBuilder *irb, Scope *scope, AstNode *source_node, uint64_t value) {
1665 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1666 const_instruction->base.value->type = irb->codegen->builtin_types.entry_num_lit_int;
1667 const_instruction->base.value->special = ConstValSpecialStatic;
1668 bigint_init_unsigned(&const_instruction->base.value->data.x_bigint, value);
2131static IrInstSrc *ir_build_const_uint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, uint64_t value) {
2132 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
2133 const_instruction->value = create_const_vals(1);
2134 const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_int;
2135 const_instruction->value->special = ConstValSpecialStatic;
2136 bigint_init_unsigned(&const_instruction->value->data.x_bigint, value);
16692137 return &const_instruction->base;
16702138}
16712139
1672static IrInstruction *ir_build_const_bigint(IrBuilder *irb, Scope *scope, AstNode *source_node, BigInt *bigint) {
1673 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1674 const_instruction->base.value->type = irb->codegen->builtin_types.entry_num_lit_int;
1675 const_instruction->base.value->special = ConstValSpecialStatic;
1676 bigint_init_bigint(&const_instruction->base.value->data.x_bigint, bigint);
2140static IrInstSrc *ir_build_const_bigint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, BigInt *bigint) {
2141 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
2142 const_instruction->value = create_const_vals(1);
2143 const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_int;
2144 const_instruction->value->special = ConstValSpecialStatic;
2145 bigint_init_bigint(&const_instruction->value->data.x_bigint, bigint);
16772146 return &const_instruction->base;
16782147}
16792148
1680static IrInstruction *ir_build_const_bigfloat(IrBuilder *irb, Scope *scope, AstNode *source_node, BigFloat *bigfloat) {
1681 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1682 const_instruction->base.value->type = irb->codegen->builtin_types.entry_num_lit_float;
1683 const_instruction->base.value->special = ConstValSpecialStatic;
1684 bigfloat_init_bigfloat(&const_instruction->base.value->data.x_bigfloat, bigfloat);
2149static IrInstSrc *ir_build_const_bigfloat(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, BigFloat *bigfloat) {
2150 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
2151 const_instruction->value = create_const_vals(1);
2152 const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_float;
2153 const_instruction->value->special = ConstValSpecialStatic;
2154 bigfloat_init_bigfloat(&const_instruction->value->data.x_bigfloat, bigfloat);
16852155 return &const_instruction->base;
16862156}
16872157
1688static IrInstruction *ir_build_const_null(IrBuilder *irb, Scope *scope, AstNode *source_node) {
1689 IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(irb, scope, source_node);
2158static IrInstSrc *ir_build_const_null(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
2159 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node);
16902160 ir_instruction_append(irb->current_basic_block, &const_instruction->base);
1691 const_instruction->base.value = irb->codegen->intern.for_null();
2161 const_instruction->value = irb->codegen->intern.for_null();
16922162 return &const_instruction->base;
16932163}
16942164
1695static IrInstruction *ir_build_const_usize(IrBuilder *irb, Scope *scope, AstNode *source_node, uint64_t value) {
1696 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1697 const_instruction->base.value->type = irb->codegen->builtin_types.entry_usize;
1698 const_instruction->base.value->special = ConstValSpecialStatic;
1699 bigint_init_unsigned(&const_instruction->base.value->data.x_bigint, value);
2165static IrInstSrc *ir_build_const_usize(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, uint64_t value) {
2166 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
2167 const_instruction->value = create_const_vals(1);
2168 const_instruction->value->type = irb->codegen->builtin_types.entry_usize;
2169 const_instruction->value->special = ConstValSpecialStatic;
2170 bigint_init_unsigned(&const_instruction->value->data.x_bigint, value);
17002171 return &const_instruction->base;
17012172}
17022173
1703static IrInstruction *ir_create_const_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
2174static IrInstSrc *ir_create_const_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
17042175 ZigType *type_entry)
17052176{
1706 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);
1707 const_instruction->base.value->type = irb->codegen->builtin_types.entry_type;
1708 const_instruction->base.value->special = ConstValSpecialStatic;
1709 const_instruction->base.value->data.x_type = type_entry;
2177 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node);
2178 const_instruction->value = create_const_vals(1);
2179 const_instruction->value->type = irb->codegen->builtin_types.entry_type;
2180 const_instruction->value->special = ConstValSpecialStatic;
2181 const_instruction->value->data.x_type = type_entry;
17102182 return &const_instruction->base;
17112183}
17122184
1713static IrInstruction *ir_build_const_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
2185static IrInstSrc *ir_build_const_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
17142186 ZigType *type_entry)
17152187{
1716 IrInstruction *instruction = ir_create_const_type(irb, scope, source_node, type_entry);
2188 IrInstSrc *instruction = ir_create_const_type(irb, scope, source_node, type_entry);
17172189 ir_instruction_append(irb->current_basic_block, instruction);
17182190 return instruction;
17192191}
17202192
1721static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigFn *fn_entry) {
1722 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);
1723 const_instruction->base.value->type = fn_entry->type_entry;
1724 const_instruction->base.value->special = ConstValSpecialStatic;
1725 const_instruction->base.value->data.x_ptr.data.fn.fn_entry = fn_entry;
1726 const_instruction->base.value->data.x_ptr.mut = ConstPtrMutComptimeConst;
1727 const_instruction->base.value->data.x_ptr.special = ConstPtrSpecialFunction;
1728 return &const_instruction->base;
1729}
1730
1731static IrInstruction *ir_build_const_import(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigType *import) {
1732 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1733 const_instruction->base.value->type = irb->codegen->builtin_types.entry_type;
1734 const_instruction->base.value->special = ConstValSpecialStatic;
1735 const_instruction->base.value->data.x_type = import;
1736 return &const_instruction->base;
1737}
1738
1739static IrInstruction *ir_build_const_bool(IrBuilder *irb, Scope *scope, AstNode *source_node, bool value) {
1740 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1741 const_instruction->base.value->type = irb->codegen->builtin_types.entry_bool;
1742 const_instruction->base.value->special = ConstValSpecialStatic;
1743 const_instruction->base.value->data.x_bool = value;
2193static IrInstSrc *ir_build_const_import(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, ZigType *import) {
2194 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
2195 const_instruction->value = create_const_vals(1);
2196 const_instruction->value->type = irb->codegen->builtin_types.entry_type;
2197 const_instruction->value->special = ConstValSpecialStatic;
2198 const_instruction->value->data.x_type = import;
17442199 return &const_instruction->base;
17452200}
17462201
1747static IrInstruction *ir_build_const_enum_literal(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *name) {
1748 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1749 const_instruction->base.value->type = irb->codegen->builtin_types.entry_enum_literal;
1750 const_instruction->base.value->special = ConstValSpecialStatic;
1751 const_instruction->base.value->data.x_enum_literal = name;
2202static IrInstSrc *ir_build_const_bool(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, bool value) {
2203 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
2204 const_instruction->value = create_const_vals(1);
2205 const_instruction->value->type = irb->codegen->builtin_types.entry_bool;
2206 const_instruction->value->special = ConstValSpecialStatic;
2207 const_instruction->value->data.x_bool = value;
17522208 return &const_instruction->base;
17532209}
17542210
1755static IrInstruction *ir_build_const_bound_fn(IrBuilder *irb, Scope *scope, AstNode *source_node,
1756 ZigFn *fn_entry, IrInstruction *first_arg)
1757{
1758 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1759 const_instruction->base.value->type = get_bound_fn_type(irb->codegen, fn_entry);
1760 const_instruction->base.value->special = ConstValSpecialStatic;
1761 const_instruction->base.value->data.x_bound_fn.fn = fn_entry;
1762 const_instruction->base.value->data.x_bound_fn.first_arg = first_arg;
2211static IrInstSrc *ir_build_const_enum_literal(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *name) {
2212 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
2213 const_instruction->value = create_const_vals(1);
2214 const_instruction->value->type = irb->codegen->builtin_types.entry_enum_literal;
2215 const_instruction->value->special = ConstValSpecialStatic;
2216 const_instruction->value->data.x_enum_literal = name;
17632217 return &const_instruction->base;
17642218}
17652219
1766static IrInstruction *ir_create_const_str_lit(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *str) {
1767 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);
1768 init_const_str_lit(irb->codegen, const_instruction->base.value, str);
2220static IrInstSrc *ir_create_const_str_lit(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *str) {
2221 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node);
2222 const_instruction->value = create_const_vals(1);
2223 init_const_str_lit(irb->codegen, const_instruction->value, str);
17692224
17702225 return &const_instruction->base;
17712226}
17722227
1773static IrInstruction *ir_build_const_str_lit(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *str) {
1774 IrInstruction *instruction = ir_create_const_str_lit(irb, scope, source_node, str);
2228static IrInstSrc *ir_build_const_str_lit(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *str) {
2229 IrInstSrc *instruction = ir_create_const_str_lit(irb, scope, source_node, str);
17752230 ir_instruction_append(irb->current_basic_block, instruction);
17762231 return instruction;
17772232}
17782233
1779static IrInstruction *ir_build_bin_op(IrBuilder *irb, Scope *scope, AstNode *source_node, IrBinOp op_id,
1780 IrInstruction *op1, IrInstruction *op2, bool safety_check_on)
2234static IrInstSrc *ir_build_bin_op(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrBinOp op_id,
2235 IrInstSrc *op1, IrInstSrc *op2, bool safety_check_on)
17812236{
1782 IrInstructionBinOp *bin_op_instruction = ir_build_instruction<IrInstructionBinOp>(irb, scope, source_node);
1783 bin_op_instruction->op_id = op_id;
1784 bin_op_instruction->op1 = op1;
1785 bin_op_instruction->op2 = op2;
1786 bin_op_instruction->safety_check_on = safety_check_on;
2237 IrInstSrcBinOp *inst = ir_build_instruction<IrInstSrcBinOp>(irb, scope, source_node);
2238 inst->op_id = op_id;
2239 inst->op1 = op1;
2240 inst->op2 = op2;
2241 inst->safety_check_on = safety_check_on;
17872242
17882243 ir_ref_instruction(op1, irb->current_basic_block);
17892244 ir_ref_instruction(op2, irb->current_basic_block);
17902245
1791 return &bin_op_instruction->base;
2246 return &inst->base;
17922247}
17932248
1794static IrInstruction *ir_build_bin_op_gen(IrAnalyze *ira, IrInstruction *source_instr, ZigType *res_type,
1795 IrBinOp op_id, IrInstruction *op1, IrInstruction *op2, bool safety_check_on)
2249static IrInstGen *ir_build_bin_op_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *res_type,
2250 IrBinOp op_id, IrInstGen *op1, IrInstGen *op2, bool safety_check_on)
17962251{
1797 IrInstructionBinOp *bin_op_instruction = ir_build_instruction<IrInstructionBinOp>(&ira->new_irb,
2252 IrInstGenBinOp *inst = ir_build_inst_gen<IrInstGenBinOp>(&ira->new_irb,
17982253 source_instr->scope, source_instr->source_node);
1799 bin_op_instruction->base.value->type = res_type;
1800 bin_op_instruction->op_id = op_id;
1801 bin_op_instruction->op1 = op1;
1802 bin_op_instruction->op2 = op2;
1803 bin_op_instruction->safety_check_on = safety_check_on;
2254 inst->base.value->type = res_type;
2255 inst->op_id = op_id;
2256 inst->op1 = op1;
2257 inst->op2 = op2;
2258 inst->safety_check_on = safety_check_on;
18042259
1805 ir_ref_instruction(op1, ira->new_irb.current_basic_block);
1806 ir_ref_instruction(op2, ira->new_irb.current_basic_block);
2260 ir_ref_inst_gen(op1, ira->new_irb.current_basic_block);
2261 ir_ref_inst_gen(op2, ira->new_irb.current_basic_block);
18072262
1808 return &bin_op_instruction->base;
2263 return &inst->base;
18092264}
18102265
18112266
1812static IrInstruction *ir_build_merge_err_sets(IrBuilder *irb, Scope *scope, AstNode *source_node,
1813 IrInstruction *op1, IrInstruction *op2, Buf *type_name)
2267static IrInstSrc *ir_build_merge_err_sets(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2268 IrInstSrc *op1, IrInstSrc *op2, Buf *type_name)
18142269{
1815 IrInstructionMergeErrSets *merge_err_sets_instruction = ir_build_instruction<IrInstructionMergeErrSets>(irb, scope, source_node);
1816 merge_err_sets_instruction->op1 = op1;
1817 merge_err_sets_instruction->op2 = op2;
1818 merge_err_sets_instruction->type_name = type_name;
2270 IrInstSrcMergeErrSets *inst = ir_build_instruction<IrInstSrcMergeErrSets>(irb, scope, source_node);
2271 inst->op1 = op1;
2272 inst->op2 = op2;
2273 inst->type_name = type_name;
18192274
18202275 ir_ref_instruction(op1, irb->current_basic_block);
18212276 ir_ref_instruction(op2, irb->current_basic_block);
18222277
1823 return &merge_err_sets_instruction->base;
2278 return &inst->base;
18242279}
18252280
1826static IrInstruction *ir_build_var_ptr_x(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigVar *var,
2281static IrInstSrc *ir_build_var_ptr_x(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, ZigVar *var,
18272282 ScopeFnDef *crossed_fndef_scope)
18282283{
1829 IrInstructionVarPtr *instruction = ir_build_instruction<IrInstructionVarPtr>(irb, scope, source_node);
2284 IrInstSrcVarPtr *instruction = ir_build_instruction<IrInstSrcVarPtr>(irb, scope, source_node);
18302285 instruction->var = var;
18312286 instruction->crossed_fndef_scope = crossed_fndef_scope;
18322287
......@@ -1835,22 +2290,31 @@ static IrInstruction *ir_build_var_ptr_x(IrBuilder *irb, Scope *scope, AstNode *
18352290 return &instruction->base;
18362291}
18372292
1838static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigVar *var) {
2293static IrInstSrc *ir_build_var_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, ZigVar *var) {
18392294 return ir_build_var_ptr_x(irb, scope, source_node, var, nullptr);
18402295}
18412296
1842static IrInstruction *ir_build_return_ptr(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) {
1843 IrInstructionReturnPtr *instruction = ir_build_instruction<IrInstructionReturnPtr>(&ira->new_irb,
2297static IrInstGen *ir_build_var_ptr_gen(IrAnalyze *ira, IrInst *source_instr, ZigVar *var) {
2298 IrInstGenVarPtr *instruction = ir_build_inst_gen<IrInstGenVarPtr>(&ira->new_irb, source_instr->scope, source_instr->source_node);
2299 instruction->var = var;
2300
2301 ir_ref_var(var);
2302
2303 return &instruction->base;
2304}
2305
2306static IrInstGen *ir_build_return_ptr(IrAnalyze *ira, IrInst *source_instruction, ZigType *ty) {
2307 IrInstGenReturnPtr *instruction = ir_build_inst_gen<IrInstGenReturnPtr>(&ira->new_irb,
18442308 source_instruction->scope, source_instruction->source_node);
18452309 instruction->base.value->type = ty;
18462310 return &instruction->base;
18472311}
18482312
1849static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,
1850 IrInstruction *array_ptr, IrInstruction *elem_index, bool safety_check_on, PtrLen ptr_len,
2313static IrInstSrc *ir_build_elem_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2314 IrInstSrc *array_ptr, IrInstSrc *elem_index, bool safety_check_on, PtrLen ptr_len,
18512315 AstNode *init_array_type_source_node)
18522316{
1853 IrInstructionElemPtr *instruction = ir_build_instruction<IrInstructionElemPtr>(irb, scope, source_node);
2317 IrInstSrcElemPtr *instruction = ir_build_instruction<IrInstSrcElemPtr>(irb, scope, source_node);
18542318 instruction->array_ptr = array_ptr;
18552319 instruction->elem_index = elem_index;
18562320 instruction->safety_check_on = safety_check_on;
......@@ -1863,10 +2327,25 @@ static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, Scope *scope, AstNode *s
18632327 return &instruction->base;
18642328}
18652329
1866static IrInstruction *ir_build_field_ptr_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node,
1867 IrInstruction *container_ptr, IrInstruction *field_name_expr, bool initializing)
2330static IrInstGen *ir_build_elem_ptr_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
2331 IrInstGen *array_ptr, IrInstGen *elem_index, bool safety_check_on, ZigType *return_type)
2332{
2333 IrInstGenElemPtr *instruction = ir_build_inst_gen<IrInstGenElemPtr>(&ira->new_irb, scope, source_node);
2334 instruction->base.value->type = return_type;
2335 instruction->array_ptr = array_ptr;
2336 instruction->elem_index = elem_index;
2337 instruction->safety_check_on = safety_check_on;
2338
2339 ir_ref_inst_gen(array_ptr, ira->new_irb.current_basic_block);
2340 ir_ref_inst_gen(elem_index, ira->new_irb.current_basic_block);
2341
2342 return &instruction->base;
2343}
2344
2345static IrInstSrc *ir_build_field_ptr_instruction(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2346 IrInstSrc *container_ptr, IrInstSrc *field_name_expr, bool initializing)
18682347{
1869 IrInstructionFieldPtr *instruction = ir_build_instruction<IrInstructionFieldPtr>(irb, scope, source_node);
2348 IrInstSrcFieldPtr *instruction = ir_build_instruction<IrInstSrcFieldPtr>(irb, scope, source_node);
18702349 instruction->container_ptr = container_ptr;
18712350 instruction->field_name_buffer = nullptr;
18722351 instruction->field_name_expr = field_name_expr;
......@@ -1878,10 +2357,10 @@ static IrInstruction *ir_build_field_ptr_instruction(IrBuilder *irb, Scope *scop
18782357 return &instruction->base;
18792358}
18802359
1881static IrInstruction *ir_build_field_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,
1882 IrInstruction *container_ptr, Buf *field_name, bool initializing)
2360static IrInstSrc *ir_build_field_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2361 IrInstSrc *container_ptr, Buf *field_name, bool initializing)
18832362{
1884 IrInstructionFieldPtr *instruction = ir_build_instruction<IrInstructionFieldPtr>(irb, scope, source_node);
2363 IrInstSrcFieldPtr *instruction = ir_build_instruction<IrInstSrcFieldPtr>(irb, scope, source_node);
18852364 instruction->container_ptr = container_ptr;
18862365 instruction->field_name_buffer = field_name;
18872366 instruction->field_name_expr = nullptr;
......@@ -1892,10 +2371,10 @@ static IrInstruction *ir_build_field_ptr(IrBuilder *irb, Scope *scope, AstNode *
18922371 return &instruction->base;
18932372}
18942373
1895static IrInstruction *ir_build_has_field(IrBuilder *irb, Scope *scope, AstNode *source_node,
1896 IrInstruction *container_type, IrInstruction *field_name)
2374static IrInstSrc *ir_build_has_field(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2375 IrInstSrc *container_type, IrInstSrc *field_name)
18972376{
1898 IrInstructionHasField *instruction = ir_build_instruction<IrInstructionHasField>(irb, scope, source_node);
2377 IrInstSrcHasField *instruction = ir_build_instruction<IrInstSrcHasField>(irb, scope, source_node);
18992378 instruction->container_type = container_type;
19002379 instruction->field_name = field_name;
19012380
......@@ -1905,36 +2384,39 @@ static IrInstruction *ir_build_has_field(IrBuilder *irb, Scope *scope, AstNode *
19052384 return &instruction->base;
19062385}
19072386
1908static IrInstruction *ir_build_struct_field_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,
1909 IrInstruction *struct_ptr, TypeStructField *field)
2387static IrInstGen *ir_build_struct_field_ptr(IrAnalyze *ira, IrInst *source_instr,
2388 IrInstGen *struct_ptr, TypeStructField *field, ZigType *ptr_type)
19102389{
1911 IrInstructionStructFieldPtr *instruction = ir_build_instruction<IrInstructionStructFieldPtr>(irb, scope, source_node);
1912 instruction->struct_ptr = struct_ptr;
1913 instruction->field = field;
2390 IrInstGenStructFieldPtr *inst = ir_build_inst_gen<IrInstGenStructFieldPtr>(&ira->new_irb, source_instr->scope, source_instr->source_node);
2391 inst->base.value->type = ptr_type;
2392 inst->struct_ptr = struct_ptr;
2393 inst->field = field;
19142394
1915 ir_ref_instruction(struct_ptr, irb->current_basic_block);
2395 ir_ref_inst_gen(struct_ptr, ira->new_irb.current_basic_block);
19162396
1917 return &instruction->base;
2397 return &inst->base;
19182398}
19192399
1920static IrInstruction *ir_build_union_field_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,
1921 IrInstruction *union_ptr, TypeUnionField *field, bool safety_check_on, bool initializing)
2400static IrInstGen *ir_build_union_field_ptr(IrAnalyze *ira, IrInst *source_instr,
2401 IrInstGen *union_ptr, TypeUnionField *field, bool safety_check_on, bool initializing, ZigType *ptr_type)
19222402{
1923 IrInstructionUnionFieldPtr *instruction = ir_build_instruction<IrInstructionUnionFieldPtr>(irb, scope, source_node);
1924 instruction->initializing = initializing;
1925 instruction->safety_check_on = safety_check_on;
1926 instruction->union_ptr = union_ptr;
1927 instruction->field = field;
2403 IrInstGenUnionFieldPtr *inst = ir_build_inst_gen<IrInstGenUnionFieldPtr>(&ira->new_irb,
2404 source_instr->scope, source_instr->source_node);
2405 inst->base.value->type = ptr_type;
2406 inst->initializing = initializing;
2407 inst->safety_check_on = safety_check_on;
2408 inst->union_ptr = union_ptr;
2409 inst->field = field;
19282410
1929 ir_ref_instruction(union_ptr, irb->current_basic_block);
2411 ir_ref_inst_gen(union_ptr, ira->new_irb.current_basic_block);
19302412
1931 return &instruction->base;
2413 return &inst->base;
19322414}
19332415
1934static IrInstruction *ir_build_call_extra(IrBuilder *irb, Scope *scope, AstNode *source_node,
1935 IrInstruction *options, IrInstruction *fn_ref, IrInstruction *args, ResultLoc *result_loc)
2416static IrInstSrc *ir_build_call_extra(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2417 IrInstSrc *options, IrInstSrc *fn_ref, IrInstSrc *args, ResultLoc *result_loc)
19362418{
1937 IrInstructionCallExtra *call_instruction = ir_build_instruction<IrInstructionCallExtra>(irb, scope, source_node);
2419 IrInstSrcCallExtra *call_instruction = ir_build_instruction<IrInstSrcCallExtra>(irb, scope, source_node);
19382420 call_instruction->options = options;
19392421 call_instruction->fn_ref = fn_ref;
19402422 call_instruction->args = args;
......@@ -1947,11 +2429,11 @@ static IrInstruction *ir_build_call_extra(IrBuilder *irb, Scope *scope, AstNode
19472429 return &call_instruction->base;
19482430}
19492431
1950static IrInstruction *ir_build_call_src_args(IrBuilder *irb, Scope *scope, AstNode *source_node,
1951 IrInstruction *options, IrInstruction *fn_ref, IrInstruction **args_ptr, size_t args_len,
2432static IrInstSrc *ir_build_call_args(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2433 IrInstSrc *options, IrInstSrc *fn_ref, IrInstSrc **args_ptr, size_t args_len,
19522434 ResultLoc *result_loc)
19532435{
1954 IrInstructionCallSrcArgs *call_instruction = ir_build_instruction<IrInstructionCallSrcArgs>(irb, scope, source_node);
2436 IrInstSrcCallArgs *call_instruction = ir_build_instruction<IrInstSrcCallArgs>(irb, scope, source_node);
19552437 call_instruction->options = options;
19562438 call_instruction->fn_ref = fn_ref;
19572439 call_instruction->args_ptr = args_ptr;
......@@ -1966,12 +2448,12 @@ static IrInstruction *ir_build_call_src_args(IrBuilder *irb, Scope *scope, AstNo
19662448 return &call_instruction->base;
19672449}
19682450
1969static IrInstruction *ir_build_call_src(IrBuilder *irb, Scope *scope, AstNode *source_node,
1970 ZigFn *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args,
1971 IrInstruction *ret_ptr, CallModifier modifier, bool is_async_call_builtin,
1972 IrInstruction *new_stack, ResultLoc *result_loc)
2451static IrInstSrc *ir_build_call_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2452 ZigFn *fn_entry, IrInstSrc *fn_ref, size_t arg_count, IrInstSrc **args,
2453 IrInstSrc *ret_ptr, CallModifier modifier, bool is_async_call_builtin,
2454 IrInstSrc *new_stack, ResultLoc *result_loc)
19732455{
1974 IrInstructionCallSrc *call_instruction = ir_build_instruction<IrInstructionCallSrc>(irb, scope, source_node);
2456 IrInstSrcCall *call_instruction = ir_build_instruction<IrInstSrcCall>(irb, scope, source_node);
19752457 call_instruction->fn_entry = fn_entry;
19762458 call_instruction->fn_ref = fn_ref;
19772459 call_instruction->args = args;
......@@ -1991,12 +2473,12 @@ static IrInstruction *ir_build_call_src(IrBuilder *irb, Scope *scope, AstNode *s
19912473 return &call_instruction->base;
19922474}
19932475
1994static IrInstructionCallGen *ir_build_call_gen(IrAnalyze *ira, IrInstruction *source_instruction,
1995 ZigFn *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args,
1996 CallModifier modifier, IrInstruction *new_stack, bool is_async_call_builtin,
1997 IrInstruction *result_loc, ZigType *return_type)
2476static IrInstGenCall *ir_build_call_gen(IrAnalyze *ira, IrInst *source_instruction,
2477 ZigFn *fn_entry, IrInstGen *fn_ref, size_t arg_count, IrInstGen **args,
2478 CallModifier modifier, IrInstGen *new_stack, bool is_async_call_builtin,
2479 IrInstGen *result_loc, ZigType *return_type)
19982480{
1999 IrInstructionCallGen *call_instruction = ir_build_instruction<IrInstructionCallGen>(&ira->new_irb,
2481 IrInstGenCall *call_instruction = ir_build_inst_gen<IrInstGenCall>(&ira->new_irb,
20002482 source_instruction->scope, source_instruction->source_node);
20012483 call_instruction->base.value->type = return_type;
20022484 call_instruction->fn_entry = fn_entry;
......@@ -2008,23 +2490,23 @@ static IrInstructionCallGen *ir_build_call_gen(IrAnalyze *ira, IrInstruction *so
20082490 call_instruction->new_stack = new_stack;
20092491 call_instruction->result_loc = result_loc;
20102492
2011 if (fn_ref != nullptr) ir_ref_instruction(fn_ref, ira->new_irb.current_basic_block);
2493 if (fn_ref != nullptr) ir_ref_inst_gen(fn_ref, ira->new_irb.current_basic_block);
20122494 for (size_t i = 0; i < arg_count; i += 1)
2013 ir_ref_instruction(args[i], ira->new_irb.current_basic_block);
2014 if (new_stack != nullptr) ir_ref_instruction(new_stack, ira->new_irb.current_basic_block);
2015 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);
2495 ir_ref_inst_gen(args[i], ira->new_irb.current_basic_block);
2496 if (new_stack != nullptr) ir_ref_inst_gen(new_stack, ira->new_irb.current_basic_block);
2497 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
20162498
20172499 return call_instruction;
20182500}
20192501
2020static IrInstruction *ir_build_phi(IrBuilder *irb, Scope *scope, AstNode *source_node,
2021 size_t incoming_count, IrBasicBlock **incoming_blocks, IrInstruction **incoming_values,
2502static IrInstSrc *ir_build_phi(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2503 size_t incoming_count, IrBasicBlockSrc **incoming_blocks, IrInstSrc **incoming_values,
20222504 ResultLocPeerParent *peer_parent)
20232505{
20242506 assert(incoming_count != 0);
20252507 assert(incoming_count != SIZE_MAX);
20262508
2027 IrInstructionPhi *phi_instruction = ir_build_instruction<IrInstructionPhi>(irb, scope, source_node);
2509 IrInstSrcPhi *phi_instruction = ir_build_instruction<IrInstSrcPhi>(irb, scope, source_node);
20282510 phi_instruction->incoming_count = incoming_count;
20292511 phi_instruction->incoming_blocks = incoming_blocks;
20302512 phi_instruction->incoming_values = incoming_values;
......@@ -2038,56 +2520,77 @@ static IrInstruction *ir_build_phi(IrBuilder *irb, Scope *scope, AstNode *source
20382520 return &phi_instruction->base;
20392521}
20402522
2041static IrInstruction *ir_create_br(IrBuilder *irb, Scope *scope, AstNode *source_node,
2042 IrBasicBlock *dest_block, IrInstruction *is_comptime)
2523static IrInstGen *ir_build_phi_gen(IrAnalyze *ira, IrInst *source_instr, size_t incoming_count,
2524 IrBasicBlockGen **incoming_blocks, IrInstGen **incoming_values, ZigType *result_type)
2525{
2526 assert(incoming_count != 0);
2527 assert(incoming_count != SIZE_MAX);
2528
2529 IrInstGenPhi *phi_instruction = ir_build_inst_gen<IrInstGenPhi>(&ira->new_irb,
2530 source_instr->scope, source_instr->source_node);
2531 phi_instruction->base.value->type = result_type;
2532 phi_instruction->incoming_count = incoming_count;
2533 phi_instruction->incoming_blocks = incoming_blocks;
2534 phi_instruction->incoming_values = incoming_values;
2535
2536 for (size_t i = 0; i < incoming_count; i += 1) {
2537 ir_ref_bb_gen(incoming_blocks[i]);
2538 ir_ref_inst_gen(incoming_values[i], ira->new_irb.current_basic_block);
2539 }
2540
2541 return &phi_instruction->base;
2542}
2543
2544static IrInstSrc *ir_build_br(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2545 IrBasicBlockSrc *dest_block, IrInstSrc *is_comptime)
20432546{
2044 IrInstructionBr *br_instruction = ir_create_instruction<IrInstructionBr>(irb, scope, source_node);
2045 br_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;
2046 br_instruction->base.value->special = ConstValSpecialStatic;
2047 br_instruction->dest_block = dest_block;
2048 br_instruction->is_comptime = is_comptime;
2547 IrInstSrcBr *inst = ir_build_instruction<IrInstSrcBr>(irb, scope, source_node);
2548 inst->base.is_noreturn = true;
2549 inst->dest_block = dest_block;
2550 inst->is_comptime = is_comptime;
20492551
20502552 ir_ref_bb(dest_block);
20512553 if (is_comptime) ir_ref_instruction(is_comptime, irb->current_basic_block);
20522554
2053 return &br_instruction->base;
2555 return &inst->base;
20542556}
20552557
2056static IrInstruction *ir_build_br(IrBuilder *irb, Scope *scope, AstNode *source_node,
2057 IrBasicBlock *dest_block, IrInstruction *is_comptime)
2058{
2059 IrInstruction *instruction = ir_create_br(irb, scope, source_node, dest_block, is_comptime);
2060 ir_instruction_append(irb->current_basic_block, instruction);
2061 return instruction;
2558static IrInstGen *ir_build_br_gen(IrAnalyze *ira, IrInst *source_instr, IrBasicBlockGen *dest_block) {
2559 IrInstGenBr *inst = ir_build_inst_noreturn<IrInstGenBr>(&ira->new_irb, source_instr->scope, source_instr->source_node);
2560 inst->dest_block = dest_block;
2561
2562 ir_ref_bb_gen(dest_block);
2563
2564 return &inst->base;
20622565}
20632566
2064static IrInstruction *ir_build_ptr_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
2065 IrInstruction *child_type, bool is_const, bool is_volatile, PtrLen ptr_len,
2066 IrInstruction *sentinel, IrInstruction *align_value,
2567static IrInstSrc *ir_build_ptr_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2568 IrInstSrc *child_type, bool is_const, bool is_volatile, PtrLen ptr_len,
2569 IrInstSrc *sentinel, IrInstSrc *align_value,
20672570 uint32_t bit_offset_start, uint32_t host_int_bytes, bool is_allow_zero)
20682571{
2069 IrInstructionPtrType *ptr_type_of_instruction = ir_build_instruction<IrInstructionPtrType>(irb, scope, source_node);
2070 ptr_type_of_instruction->sentinel = sentinel;
2071 ptr_type_of_instruction->align_value = align_value;
2072 ptr_type_of_instruction->child_type = child_type;
2073 ptr_type_of_instruction->is_const = is_const;
2074 ptr_type_of_instruction->is_volatile = is_volatile;
2075 ptr_type_of_instruction->ptr_len = ptr_len;
2076 ptr_type_of_instruction->bit_offset_start = bit_offset_start;
2077 ptr_type_of_instruction->host_int_bytes = host_int_bytes;
2078 ptr_type_of_instruction->is_allow_zero = is_allow_zero;
2572 IrInstSrcPtrType *inst = ir_build_instruction<IrInstSrcPtrType>(irb, scope, source_node);
2573 inst->sentinel = sentinel;
2574 inst->align_value = align_value;
2575 inst->child_type = child_type;
2576 inst->is_const = is_const;
2577 inst->is_volatile = is_volatile;
2578 inst->ptr_len = ptr_len;
2579 inst->bit_offset_start = bit_offset_start;
2580 inst->host_int_bytes = host_int_bytes;
2581 inst->is_allow_zero = is_allow_zero;
20792582
20802583 if (sentinel) ir_ref_instruction(sentinel, irb->current_basic_block);
20812584 if (align_value) ir_ref_instruction(align_value, irb->current_basic_block);
20822585 ir_ref_instruction(child_type, irb->current_basic_block);
20832586
2084 return &ptr_type_of_instruction->base;
2587 return &inst->base;
20852588}
20862589
2087static IrInstruction *ir_build_un_op_lval(IrBuilder *irb, Scope *scope, AstNode *source_node, IrUnOp op_id,
2088 IrInstruction *value, LVal lval, ResultLoc *result_loc)
2590static IrInstSrc *ir_build_un_op_lval(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrUnOp op_id,
2591 IrInstSrc *value, LVal lval, ResultLoc *result_loc)
20892592{
2090 IrInstructionUnOp *instruction = ir_build_instruction<IrInstructionUnOp>(irb, scope, source_node);
2593 IrInstSrcUnOp *instruction = ir_build_instruction<IrInstSrcUnOp>(irb, scope, source_node);
20912594 instruction->op_id = op_id;
20922595 instruction->value = value;
20932596 instruction->lval = lval;
......@@ -2098,36 +2601,73 @@ static IrInstruction *ir_build_un_op_lval(IrBuilder *irb, Scope *scope, AstNode
20982601 return &instruction->base;
20992602}
21002603
2101static IrInstruction *ir_build_un_op(IrBuilder *irb, Scope *scope, AstNode *source_node, IrUnOp op_id,
2102 IrInstruction *value)
2604static IrInstSrc *ir_build_un_op(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrUnOp op_id,
2605 IrInstSrc *value)
21032606{
21042607 return ir_build_un_op_lval(irb, scope, source_node, op_id, value, LValNone, nullptr);
21052608}
21062609
2107static IrInstruction *ir_build_container_init_list(IrBuilder *irb, Scope *scope, AstNode *source_node,
2108 size_t item_count, IrInstruction **elem_result_loc_list, IrInstruction *result_loc,
2109 AstNode *init_array_type_source_node)
2110{
2111 IrInstructionContainerInitList *container_init_list_instruction =
2112 ir_build_instruction<IrInstructionContainerInitList>(irb, scope, source_node);
2113 container_init_list_instruction->item_count = item_count;
2114 container_init_list_instruction->elem_result_loc_list = elem_result_loc_list;
2115 container_init_list_instruction->result_loc = result_loc;
2116 container_init_list_instruction->init_array_type_source_node = init_array_type_source_node;
2610static IrInstGen *ir_build_negation(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand, ZigType *expr_type) {
2611 IrInstGenNegation *instruction = ir_build_inst_gen<IrInstGenNegation>(&ira->new_irb,
2612 source_instr->scope, source_instr->source_node);
2613 instruction->base.value->type = expr_type;
2614 instruction->operand = operand;
21172615
2118 for (size_t i = 0; i < item_count; i += 1) {
2119 ir_ref_instruction(elem_result_loc_list[i], irb->current_basic_block);
2616 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
2617
2618 return &instruction->base;
2619}
2620
2621static IrInstGen *ir_build_negation_wrapping(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand,
2622 ZigType *expr_type)
2623{
2624 IrInstGenNegationWrapping *instruction = ir_build_inst_gen<IrInstGenNegationWrapping>(&ira->new_irb,
2625 source_instr->scope, source_instr->source_node);
2626 instruction->base.value->type = expr_type;
2627 instruction->operand = operand;
2628
2629 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
2630
2631 return &instruction->base;
2632}
2633
2634static IrInstGen *ir_build_binary_not(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand,
2635 ZigType *expr_type)
2636{
2637 IrInstGenBinaryNot *instruction = ir_build_inst_gen<IrInstGenBinaryNot>(&ira->new_irb,
2638 source_instr->scope, source_instr->source_node);
2639 instruction->base.value->type = expr_type;
2640 instruction->operand = operand;
2641
2642 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
2643
2644 return &instruction->base;
2645}
2646
2647static IrInstSrc *ir_build_container_init_list(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2648 size_t item_count, IrInstSrc **elem_result_loc_list, IrInstSrc *result_loc,
2649 AstNode *init_array_type_source_node)
2650{
2651 IrInstSrcContainerInitList *container_init_list_instruction =
2652 ir_build_instruction<IrInstSrcContainerInitList>(irb, scope, source_node);
2653 container_init_list_instruction->item_count = item_count;
2654 container_init_list_instruction->elem_result_loc_list = elem_result_loc_list;
2655 container_init_list_instruction->result_loc = result_loc;
2656 container_init_list_instruction->init_array_type_source_node = init_array_type_source_node;
2657
2658 for (size_t i = 0; i < item_count; i += 1) {
2659 ir_ref_instruction(elem_result_loc_list[i], irb->current_basic_block);
21202660 }
21212661 if (result_loc != nullptr) ir_ref_instruction(result_loc, irb->current_basic_block);
21222662
21232663 return &container_init_list_instruction->base;
21242664}
21252665
2126static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scope, AstNode *source_node,
2127 size_t field_count, IrInstructionContainerInitFieldsField *fields, IrInstruction *result_loc)
2666static IrInstSrc *ir_build_container_init_fields(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2667 size_t field_count, IrInstSrcContainerInitFieldsField *fields, IrInstSrc *result_loc)
21282668{
2129 IrInstructionContainerInitFields *container_init_fields_instruction =
2130 ir_build_instruction<IrInstructionContainerInitFields>(irb, scope, source_node);
2669 IrInstSrcContainerInitFields *container_init_fields_instruction =
2670 ir_build_instruction<IrInstSrcContainerInitFields>(irb, scope, source_node);
21312671 container_init_fields_instruction->field_count = field_count;
21322672 container_init_fields_instruction->fields = fields;
21332673 container_init_fields_instruction->result_loc = result_loc;
......@@ -2140,20 +2680,21 @@ static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scop
21402680 return &container_init_fields_instruction->base;
21412681}
21422682
2143static IrInstruction *ir_build_unreachable(IrBuilder *irb, Scope *scope, AstNode *source_node) {
2144 IrInstructionUnreachable *unreachable_instruction =
2145 ir_build_instruction<IrInstructionUnreachable>(irb, scope, source_node);
2146 unreachable_instruction->base.value->special = ConstValSpecialStatic;
2147 unreachable_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;
2148 return &unreachable_instruction->base;
2683static IrInstSrc *ir_build_unreachable(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
2684 IrInstSrcUnreachable *inst = ir_build_instruction<IrInstSrcUnreachable>(irb, scope, source_node);
2685 inst->base.is_noreturn = true;
2686 return &inst->base;
2687}
2688
2689static IrInstGen *ir_build_unreachable_gen(IrAnalyze *ira, IrInst *source_instr) {
2690 IrInstGenUnreachable *inst = ir_build_inst_noreturn<IrInstGenUnreachable>(&ira->new_irb, source_instr->scope, source_instr->source_node);
2691 return &inst->base;
21492692}
21502693
2151static IrInstructionStorePtr *ir_build_store_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,
2152 IrInstruction *ptr, IrInstruction *value)
2694static IrInstSrcStorePtr *ir_build_store_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2695 IrInstSrc *ptr, IrInstSrc *value)
21532696{
2154 IrInstructionStorePtr *instruction = ir_build_instruction<IrInstructionStorePtr>(irb, scope, source_node);
2155 instruction->base.value->special = ConstValSpecialStatic;
2156 instruction->base.value->type = irb->codegen->builtin_types.entry_void;
2697 IrInstSrcStorePtr *instruction = ir_build_instruction<IrInstSrcStorePtr>(irb, scope, source_node);
21572698 instruction->ptr = ptr;
21582699 instruction->value = value;
21592700
......@@ -2163,76 +2704,83 @@ static IrInstructionStorePtr *ir_build_store_ptr(IrBuilder *irb, Scope *scope, A
21632704 return instruction;
21642705}
21652706
2166static IrInstruction *ir_build_vector_store_elem(IrAnalyze *ira, IrInstruction *source_instruction,
2167 IrInstruction *vector_ptr, IrInstruction *index, IrInstruction *value)
2707static IrInstGen *ir_build_store_ptr_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *ptr, IrInstGen *value) {
2708 IrInstGenStorePtr *instruction = ir_build_inst_void<IrInstGenStorePtr>(&ira->new_irb,
2709 source_instr->scope, source_instr->source_node);
2710 instruction->ptr = ptr;
2711 instruction->value = value;
2712
2713 ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block);
2714 ir_ref_inst_gen(value, ira->new_irb.current_basic_block);
2715
2716 return &instruction->base;
2717}
2718
2719static IrInstGen *ir_build_vector_store_elem(IrAnalyze *ira, IrInst *src_inst,
2720 IrInstGen *vector_ptr, IrInstGen *index, IrInstGen *value)
21682721{
2169 IrInstructionVectorStoreElem *inst = ir_build_instruction<IrInstructionVectorStoreElem>(
2170 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
2171 inst->base.value->type = ira->codegen->builtin_types.entry_void;
2722 IrInstGenVectorStoreElem *inst = ir_build_inst_void<IrInstGenVectorStoreElem>(
2723 &ira->new_irb, src_inst->scope, src_inst->source_node);
21722724 inst->vector_ptr = vector_ptr;
21732725 inst->index = index;
21742726 inst->value = value;
21752727
2176 ir_ref_instruction(vector_ptr, ira->new_irb.current_basic_block);
2177 ir_ref_instruction(index, ira->new_irb.current_basic_block);
2178 ir_ref_instruction(value, ira->new_irb.current_basic_block);
2728 ir_ref_inst_gen(vector_ptr, ira->new_irb.current_basic_block);
2729 ir_ref_inst_gen(index, ira->new_irb.current_basic_block);
2730 ir_ref_inst_gen(value, ira->new_irb.current_basic_block);
21792731
21802732 return &inst->base;
21812733}
21822734
2183static IrInstruction *ir_build_var_decl_src(IrBuilder *irb, Scope *scope, AstNode *source_node,
2184 ZigVar *var, IrInstruction *align_value, IrInstruction *ptr)
2735static IrInstSrc *ir_build_var_decl_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2736 ZigVar *var, IrInstSrc *align_value, IrInstSrc *ptr)
21852737{
2186 IrInstructionDeclVarSrc *decl_var_instruction = ir_build_instruction<IrInstructionDeclVarSrc>(irb, scope, source_node);
2187 decl_var_instruction->base.value->special = ConstValSpecialStatic;
2188 decl_var_instruction->base.value->type = irb->codegen->builtin_types.entry_void;
2189 decl_var_instruction->var = var;
2190 decl_var_instruction->align_value = align_value;
2191 decl_var_instruction->ptr = ptr;
2738 IrInstSrcDeclVar *inst = ir_build_instruction<IrInstSrcDeclVar>(irb, scope, source_node);
2739 inst->var = var;
2740 inst->align_value = align_value;
2741 inst->ptr = ptr;
21922742
21932743 if (align_value != nullptr) ir_ref_instruction(align_value, irb->current_basic_block);
21942744 ir_ref_instruction(ptr, irb->current_basic_block);
21952745
2196 return &decl_var_instruction->base;
2746 return &inst->base;
21972747}
21982748
2199static IrInstruction *ir_build_var_decl_gen(IrAnalyze *ira, IrInstruction *source_instruction,
2200 ZigVar *var, IrInstruction *var_ptr)
2749static IrInstGen *ir_build_var_decl_gen(IrAnalyze *ira, IrInst *source_instruction,
2750 ZigVar *var, IrInstGen *var_ptr)
22012751{
2202 IrInstructionDeclVarGen *decl_var_instruction = ir_build_instruction<IrInstructionDeclVarGen>(&ira->new_irb,
2752 IrInstGenDeclVar *inst = ir_build_inst_gen<IrInstGenDeclVar>(&ira->new_irb,
22032753 source_instruction->scope, source_instruction->source_node);
2204 decl_var_instruction->base.value->special = ConstValSpecialStatic;
2205 decl_var_instruction->base.value->type = ira->codegen->builtin_types.entry_void;
2206 decl_var_instruction->var = var;
2207 decl_var_instruction->var_ptr = var_ptr;
2754 inst->base.value->special = ConstValSpecialStatic;
2755 inst->base.value->type = ira->codegen->builtin_types.entry_void;
2756 inst->var = var;
2757 inst->var_ptr = var_ptr;
22082758
2209 ir_ref_instruction(var_ptr, ira->new_irb.current_basic_block);
2759 ir_ref_inst_gen(var_ptr, ira->new_irb.current_basic_block);
22102760
2211 return &decl_var_instruction->base;
2761 return &inst->base;
22122762}
22132763
2214static IrInstruction *ir_build_resize_slice(IrAnalyze *ira, IrInstruction *source_instruction,
2215 IrInstruction *operand, ZigType *ty, IrInstruction *result_loc)
2764static IrInstGen *ir_build_resize_slice(IrAnalyze *ira, IrInst *source_instruction,
2765 IrInstGen *operand, ZigType *ty, IrInstGen *result_loc)
22162766{
2217 IrInstructionResizeSlice *instruction = ir_build_instruction<IrInstructionResizeSlice>(&ira->new_irb,
2767 IrInstGenResizeSlice *instruction = ir_build_inst_gen<IrInstGenResizeSlice>(&ira->new_irb,
22182768 source_instruction->scope, source_instruction->source_node);
22192769 instruction->base.value->type = ty;
22202770 instruction->operand = operand;
22212771 instruction->result_loc = result_loc;
22222772
2223 ir_ref_instruction(operand, ira->new_irb.current_basic_block);
2224 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);
2773 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
2774 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
22252775
22262776 return &instruction->base;
22272777}
22282778
2229static IrInstruction *ir_build_export(IrBuilder *irb, Scope *scope, AstNode *source_node,
2230 IrInstruction *target, IrInstruction *options)
2779static IrInstSrc *ir_build_export(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2780 IrInstSrc *target, IrInstSrc *options)
22312781{
2232 IrInstructionExport *export_instruction = ir_build_instruction<IrInstructionExport>(
2782 IrInstSrcExport *export_instruction = ir_build_instruction<IrInstSrcExport>(
22332783 irb, scope, source_node);
2234 export_instruction->base.value->special = ConstValSpecialStatic;
2235 export_instruction->base.value->type = irb->codegen->builtin_types.entry_void;
22362784 export_instruction->target = target;
22372785 export_instruction->options = options;
22382786
......@@ -2242,8 +2790,8 @@ static IrInstruction *ir_build_export(IrBuilder *irb, Scope *scope, AstNode *sou
22422790 return &export_instruction->base;
22432791}
22442792
2245static IrInstruction *ir_build_load_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *ptr) {
2246 IrInstructionLoadPtr *instruction = ir_build_instruction<IrInstructionLoadPtr>(irb, scope, source_node);
2793static IrInstSrc *ir_build_load_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *ptr) {
2794 IrInstSrcLoadPtr *instruction = ir_build_instruction<IrInstSrcLoadPtr>(irb, scope, source_node);
22472795 instruction->ptr = ptr;
22482796
22492797 ir_ref_instruction(ptr, irb->current_basic_block);
......@@ -2251,8 +2799,23 @@ static IrInstruction *ir_build_load_ptr(IrBuilder *irb, Scope *scope, AstNode *s
22512799 return &instruction->base;
22522800}
22532801
2254static IrInstruction *ir_build_typeof(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) {
2255 IrInstructionTypeOf *instruction = ir_build_instruction<IrInstructionTypeOf>(irb, scope, source_node);
2802static IrInstGen *ir_build_load_ptr_gen(IrAnalyze *ira, IrInst *source_instruction,
2803 IrInstGen *ptr, ZigType *ty, IrInstGen *result_loc)
2804{
2805 IrInstGenLoadPtr *instruction = ir_build_inst_gen<IrInstGenLoadPtr>(
2806 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
2807 instruction->base.value->type = ty;
2808 instruction->ptr = ptr;
2809 instruction->result_loc = result_loc;
2810
2811 ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block);
2812 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
2813
2814 return &instruction->base;
2815}
2816
2817static IrInstSrc *ir_build_typeof(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value) {
2818 IrInstSrcTypeOf *instruction = ir_build_instruction<IrInstSrcTypeOf>(irb, scope, source_node);
22562819 instruction->value = value;
22572820
22582821 ir_ref_instruction(value, irb->current_basic_block);
......@@ -2260,8 +2823,8 @@ static IrInstruction *ir_build_typeof(IrBuilder *irb, Scope *scope, AstNode *sou
22602823 return &instruction->base;
22612824}
22622825
2263static IrInstruction *ir_build_set_cold(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *is_cold) {
2264 IrInstructionSetCold *instruction = ir_build_instruction<IrInstructionSetCold>(irb, scope, source_node);
2826static IrInstSrc *ir_build_set_cold(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *is_cold) {
2827 IrInstSrcSetCold *instruction = ir_build_instruction<IrInstSrcSetCold>(irb, scope, source_node);
22652828 instruction->is_cold = is_cold;
22662829
22672830 ir_ref_instruction(is_cold, irb->current_basic_block);
......@@ -2269,21 +2832,21 @@ static IrInstruction *ir_build_set_cold(IrBuilder *irb, Scope *scope, AstNode *s
22692832 return &instruction->base;
22702833}
22712834
2272static IrInstruction *ir_build_set_runtime_safety(IrBuilder *irb, Scope *scope, AstNode *source_node,
2273 IrInstruction *safety_on)
2835static IrInstSrc *ir_build_set_runtime_safety(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2836 IrInstSrc *safety_on)
22742837{
2275 IrInstructionSetRuntimeSafety *instruction = ir_build_instruction<IrInstructionSetRuntimeSafety>(irb, scope, source_node);
2276 instruction->safety_on = safety_on;
2838 IrInstSrcSetRuntimeSafety *inst = ir_build_instruction<IrInstSrcSetRuntimeSafety>(irb, scope, source_node);
2839 inst->safety_on = safety_on;
22772840
22782841 ir_ref_instruction(safety_on, irb->current_basic_block);
22792842
2280 return &instruction->base;
2843 return &inst->base;
22812844}
22822845
2283static IrInstruction *ir_build_set_float_mode(IrBuilder *irb, Scope *scope, AstNode *source_node,
2284 IrInstruction *mode_value)
2846static IrInstSrc *ir_build_set_float_mode(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2847 IrInstSrc *mode_value)
22852848{
2286 IrInstructionSetFloatMode *instruction = ir_build_instruction<IrInstructionSetFloatMode>(irb, scope, source_node);
2849 IrInstSrcSetFloatMode *instruction = ir_build_instruction<IrInstSrcSetFloatMode>(irb, scope, source_node);
22872850 instruction->mode_value = mode_value;
22882851
22892852 ir_ref_instruction(mode_value, irb->current_basic_block);
......@@ -2291,10 +2854,10 @@ static IrInstruction *ir_build_set_float_mode(IrBuilder *irb, Scope *scope, AstN
22912854 return &instruction->base;
22922855}
22932856
2294static IrInstruction *ir_build_array_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *size,
2295 IrInstruction *sentinel, IrInstruction *child_type)
2857static IrInstSrc *ir_build_array_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *size,
2858 IrInstSrc *sentinel, IrInstSrc *child_type)
22962859{
2297 IrInstructionArrayType *instruction = ir_build_instruction<IrInstructionArrayType>(irb, scope, source_node);
2860 IrInstSrcArrayType *instruction = ir_build_instruction<IrInstSrcArrayType>(irb, scope, source_node);
22982861 instruction->size = size;
22992862 instruction->sentinel = sentinel;
23002863 instruction->child_type = child_type;
......@@ -2306,10 +2869,10 @@ static IrInstruction *ir_build_array_type(IrBuilder *irb, Scope *scope, AstNode
23062869 return &instruction->base;
23072870}
23082871
2309static IrInstruction *ir_build_anyframe_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
2310 IrInstruction *payload_type)
2872static IrInstSrc *ir_build_anyframe_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2873 IrInstSrc *payload_type)
23112874{
2312 IrInstructionAnyFrameType *instruction = ir_build_instruction<IrInstructionAnyFrameType>(irb, scope, source_node);
2875 IrInstSrcAnyFrameType *instruction = ir_build_instruction<IrInstSrcAnyFrameType>(irb, scope, source_node);
23132876 instruction->payload_type = payload_type;
23142877
23152878 if (payload_type != nullptr) ir_ref_instruction(payload_type, irb->current_basic_block);
......@@ -2317,11 +2880,11 @@ static IrInstruction *ir_build_anyframe_type(IrBuilder *irb, Scope *scope, AstNo
23172880 return &instruction->base;
23182881}
23192882
2320static IrInstruction *ir_build_slice_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
2321 IrInstruction *child_type, bool is_const, bool is_volatile,
2322 IrInstruction *sentinel, IrInstruction *align_value, bool is_allow_zero)
2883static IrInstSrc *ir_build_slice_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2884 IrInstSrc *child_type, bool is_const, bool is_volatile,
2885 IrInstSrc *sentinel, IrInstSrc *align_value, bool is_allow_zero)
23232886{
2324 IrInstructionSliceType *instruction = ir_build_instruction<IrInstructionSliceType>(irb, scope, source_node);
2887 IrInstSrcSliceType *instruction = ir_build_instruction<IrInstSrcSliceType>(irb, scope, source_node);
23252888 instruction->is_const = is_const;
23262889 instruction->is_volatile = is_volatile;
23272890 instruction->child_type = child_type;
......@@ -2336,11 +2899,11 @@ static IrInstruction *ir_build_slice_type(IrBuilder *irb, Scope *scope, AstNode
23362899 return &instruction->base;
23372900}
23382901
2339static IrInstruction *ir_build_asm_src(IrBuilder *irb, Scope *scope, AstNode *source_node,
2340 IrInstruction *asm_template, IrInstruction **input_list, IrInstruction **output_types,
2902static IrInstSrc *ir_build_asm_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2903 IrInstSrc *asm_template, IrInstSrc **input_list, IrInstSrc **output_types,
23412904 ZigVar **output_vars, size_t return_count, bool has_side_effects, bool is_global)
23422905{
2343 IrInstructionAsmSrc *instruction = ir_build_instruction<IrInstructionAsmSrc>(irb, scope, source_node);
2906 IrInstSrcAsm *instruction = ir_build_instruction<IrInstSrcAsm>(irb, scope, source_node);
23442907 instruction->asm_template = asm_template;
23452908 instruction->input_list = input_list;
23462909 instruction->output_types = output_types;
......@@ -2351,24 +2914,25 @@ static IrInstruction *ir_build_asm_src(IrBuilder *irb, Scope *scope, AstNode *so
23512914
23522915 assert(source_node->type == NodeTypeAsmExpr);
23532916 for (size_t i = 0; i < source_node->data.asm_expr.output_list.length; i += 1) {
2354 IrInstruction *output_type = output_types[i];
2917 IrInstSrc *output_type = output_types[i];
23552918 if (output_type) ir_ref_instruction(output_type, irb->current_basic_block);
23562919 }
23572920
23582921 for (size_t i = 0; i < source_node->data.asm_expr.input_list.length; i += 1) {
2359 IrInstruction *input_value = input_list[i];
2922 IrInstSrc *input_value = input_list[i];
23602923 ir_ref_instruction(input_value, irb->current_basic_block);
23612924 }
23622925
23632926 return &instruction->base;
23642927}
23652928
2366static IrInstruction *ir_build_asm_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
2929static IrInstGen *ir_build_asm_gen(IrAnalyze *ira, IrInst *source_instr,
23672930 Buf *asm_template, AsmToken *token_list, size_t token_list_len,
2368 IrInstruction **input_list, IrInstruction **output_types, ZigVar **output_vars, size_t return_count,
2369 bool has_side_effects)
2931 IrInstGen **input_list, IrInstGen **output_types, ZigVar **output_vars, size_t return_count,
2932 bool has_side_effects, ZigType *return_type)
23702933{
2371 IrInstructionAsmGen *instruction = ir_build_instruction<IrInstructionAsmGen>(&ira->new_irb, scope, source_node);
2934 IrInstGenAsm *instruction = ir_build_inst_gen<IrInstGenAsm>(&ira->new_irb, source_instr->scope, source_instr->source_node);
2935 instruction->base.value->type = return_type;
23722936 instruction->asm_template = asm_template;
23732937 instruction->token_list = token_list;
23742938 instruction->token_list_len = token_list_len;
......@@ -2378,22 +2942,24 @@ static IrInstruction *ir_build_asm_gen(IrAnalyze *ira, Scope *scope, AstNode *so
23782942 instruction->return_count = return_count;
23792943 instruction->has_side_effects = has_side_effects;
23802944
2381 assert(source_node->type == NodeTypeAsmExpr);
2382 for (size_t i = 0; i < source_node->data.asm_expr.output_list.length; i += 1) {
2383 IrInstruction *output_type = output_types[i];
2384 if (output_type) ir_ref_instruction(output_type, ira->new_irb.current_basic_block);
2945 assert(source_instr->source_node->type == NodeTypeAsmExpr);
2946 for (size_t i = 0; i < source_instr->source_node->data.asm_expr.output_list.length; i += 1) {
2947 IrInstGen *output_type = output_types[i];
2948 if (output_type) ir_ref_inst_gen(output_type, ira->new_irb.current_basic_block);
23852949 }
23862950
2387 for (size_t i = 0; i < source_node->data.asm_expr.input_list.length; i += 1) {
2388 IrInstruction *input_value = input_list[i];
2389 ir_ref_instruction(input_value, ira->new_irb.current_basic_block);
2951 for (size_t i = 0; i < source_instr->source_node->data.asm_expr.input_list.length; i += 1) {
2952 IrInstGen *input_value = input_list[i];
2953 ir_ref_inst_gen(input_value, ira->new_irb.current_basic_block);
23902954 }
23912955
23922956 return &instruction->base;
23932957}
23942958
2395static IrInstruction *ir_build_size_of(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type_value, bool bit_size) {
2396 IrInstructionSizeOf *instruction = ir_build_instruction<IrInstructionSizeOf>(irb, scope, source_node);
2959static IrInstSrc *ir_build_size_of(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_value,
2960 bool bit_size)
2961{
2962 IrInstSrcSizeOf *instruction = ir_build_instruction<IrInstSrcSizeOf>(irb, scope, source_node);
23972963 instruction->type_value = type_value;
23982964 instruction->bit_size = bit_size;
23992965
......@@ -2402,8 +2968,10 @@ static IrInstruction *ir_build_size_of(IrBuilder *irb, Scope *scope, AstNode *so
24022968 return &instruction->base;
24032969}
24042970
2405static IrInstruction *ir_build_test_nonnull(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) {
2406 IrInstructionTestNonNull *instruction = ir_build_instruction<IrInstructionTestNonNull>(irb, scope, source_node);
2971static IrInstSrc *ir_build_test_non_null_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2972 IrInstSrc *value)
2973{
2974 IrInstSrcTestNonNull *instruction = ir_build_instruction<IrInstSrcTestNonNull>(irb, scope, source_node);
24072975 instruction->value = value;
24082976
24092977 ir_ref_instruction(value, irb->current_basic_block);
......@@ -2411,10 +2979,21 @@ static IrInstruction *ir_build_test_nonnull(IrBuilder *irb, Scope *scope, AstNod
24112979 return &instruction->base;
24122980}
24132981
2414static IrInstruction *ir_build_optional_unwrap_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,
2415 IrInstruction *base_ptr, bool safety_check_on, bool initializing)
2982static IrInstGen *ir_build_test_non_null_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value) {
2983 IrInstGenTestNonNull *inst = ir_build_inst_gen<IrInstGenTestNonNull>(&ira->new_irb,
2984 source_instr->scope, source_instr->source_node);
2985 inst->base.value->type = ira->codegen->builtin_types.entry_bool;
2986 inst->value = value;
2987
2988 ir_ref_inst_gen(value, ira->new_irb.current_basic_block);
2989
2990 return &inst->base;
2991}
2992
2993static IrInstSrc *ir_build_optional_unwrap_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2994 IrInstSrc *base_ptr, bool safety_check_on, bool initializing)
24162995{
2417 IrInstructionOptionalUnwrapPtr *instruction = ir_build_instruction<IrInstructionOptionalUnwrapPtr>(irb, scope, source_node);
2996 IrInstSrcOptionalUnwrapPtr *instruction = ir_build_instruction<IrInstSrcOptionalUnwrapPtr>(irb, scope, source_node);
24182997 instruction->base_ptr = base_ptr;
24192998 instruction->safety_check_on = safety_check_on;
24202999 instruction->initializing = initializing;
......@@ -2424,113 +3003,198 @@ static IrInstruction *ir_build_optional_unwrap_ptr(IrBuilder *irb, Scope *scope,
24243003 return &instruction->base;
24253004}
24263005
2427static IrInstruction *ir_build_optional_wrap(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *result_ty,
2428 IrInstruction *operand, IrInstruction *result_loc)
3006static IrInstGen *ir_build_optional_unwrap_ptr_gen(IrAnalyze *ira, IrInst *source_instr,
3007 IrInstGen *base_ptr, bool safety_check_on, bool initializing, ZigType *result_type)
24293008{
2430 IrInstructionOptionalWrap *instruction = ir_build_instruction<IrInstructionOptionalWrap>(
3009 IrInstGenOptionalUnwrapPtr *inst = ir_build_inst_gen<IrInstGenOptionalUnwrapPtr>(&ira->new_irb,
3010 source_instr->scope, source_instr->source_node);
3011 inst->base.value->type = result_type;
3012 inst->base_ptr = base_ptr;
3013 inst->safety_check_on = safety_check_on;
3014 inst->initializing = initializing;
3015
3016 ir_ref_inst_gen(base_ptr, ira->new_irb.current_basic_block);
3017
3018 return &inst->base;
3019}
3020
3021static IrInstGen *ir_build_optional_wrap(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_ty,
3022 IrInstGen *operand, IrInstGen *result_loc)
3023{
3024 IrInstGenOptionalWrap *instruction = ir_build_inst_gen<IrInstGenOptionalWrap>(
24313025 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
24323026 instruction->base.value->type = result_ty;
24333027 instruction->operand = operand;
24343028 instruction->result_loc = result_loc;
24353029
2436 ir_ref_instruction(operand, ira->new_irb.current_basic_block);
2437 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);
3030 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
3031 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
24383032
24393033 return &instruction->base;
24403034}
24413035
2442static IrInstruction *ir_build_err_wrap_payload(IrAnalyze *ira, IrInstruction *source_instruction,
2443 ZigType *result_type, IrInstruction *operand, IrInstruction *result_loc)
3036static IrInstGen *ir_build_err_wrap_payload(IrAnalyze *ira, IrInst *source_instruction,
3037 ZigType *result_type, IrInstGen *operand, IrInstGen *result_loc)
24443038{
2445 IrInstructionErrWrapPayload *instruction = ir_build_instruction<IrInstructionErrWrapPayload>(
3039 IrInstGenErrWrapPayload *instruction = ir_build_inst_gen<IrInstGenErrWrapPayload>(
24463040 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
24473041 instruction->base.value->type = result_type;
24483042 instruction->operand = operand;
24493043 instruction->result_loc = result_loc;
24503044
2451 ir_ref_instruction(operand, ira->new_irb.current_basic_block);
2452 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);
3045 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
3046 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
24533047
24543048 return &instruction->base;
24553049}
24563050
2457static IrInstruction *ir_build_err_wrap_code(IrAnalyze *ira, IrInstruction *source_instruction,
2458 ZigType *result_type, IrInstruction *operand, IrInstruction *result_loc)
3051static IrInstGen *ir_build_err_wrap_code(IrAnalyze *ira, IrInst *source_instruction,
3052 ZigType *result_type, IrInstGen *operand, IrInstGen *result_loc)
24593053{
2460 IrInstructionErrWrapCode *instruction = ir_build_instruction<IrInstructionErrWrapCode>(
3054 IrInstGenErrWrapCode *instruction = ir_build_inst_gen<IrInstGenErrWrapCode>(
24613055 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
24623056 instruction->base.value->type = result_type;
24633057 instruction->operand = operand;
24643058 instruction->result_loc = result_loc;
24653059
2466 ir_ref_instruction(operand, ira->new_irb.current_basic_block);
2467 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);
3060 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
3061 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
24683062
24693063 return &instruction->base;
24703064}
24713065
2472static IrInstruction *ir_build_clz(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type, IrInstruction *op) {
2473 IrInstructionClz *instruction = ir_build_instruction<IrInstructionClz>(irb, scope, source_node);
3066static IrInstSrc *ir_build_clz(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type,
3067 IrInstSrc *op)
3068{
3069 IrInstSrcClz *instruction = ir_build_instruction<IrInstSrcClz>(irb, scope, source_node);
24743070 instruction->type = type;
24753071 instruction->op = op;
24763072
2477 if (type != nullptr) ir_ref_instruction(type, irb->current_basic_block);
3073 ir_ref_instruction(type, irb->current_basic_block);
24783074 ir_ref_instruction(op, irb->current_basic_block);
24793075
24803076 return &instruction->base;
24813077}
24823078
2483static IrInstruction *ir_build_ctz(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type, IrInstruction *op) {
2484 IrInstructionCtz *instruction = ir_build_instruction<IrInstructionCtz>(irb, scope, source_node);
3079static IrInstGen *ir_build_clz_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *result_type, IrInstGen *op) {
3080 IrInstGenClz *instruction = ir_build_inst_gen<IrInstGenClz>(&ira->new_irb,
3081 source_instr->scope, source_instr->source_node);
3082 instruction->base.value->type = result_type;
3083 instruction->op = op;
3084
3085 ir_ref_inst_gen(op, ira->new_irb.current_basic_block);
3086
3087 return &instruction->base;
3088}
3089
3090static IrInstSrc *ir_build_ctz(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type,
3091 IrInstSrc *op)
3092{
3093 IrInstSrcCtz *instruction = ir_build_instruction<IrInstSrcCtz>(irb, scope, source_node);
24853094 instruction->type = type;
24863095 instruction->op = op;
24873096
2488 if (type != nullptr) ir_ref_instruction(type, irb->current_basic_block);
3097 ir_ref_instruction(type, irb->current_basic_block);
24893098 ir_ref_instruction(op, irb->current_basic_block);
24903099
24913100 return &instruction->base;
24923101}
24933102
2494static IrInstruction *ir_build_pop_count(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type, IrInstruction *op) {
2495 IrInstructionPopCount *instruction = ir_build_instruction<IrInstructionPopCount>(irb, scope, source_node);
3103static IrInstGen *ir_build_ctz_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *result_type, IrInstGen *op) {
3104 IrInstGenCtz *instruction = ir_build_inst_gen<IrInstGenCtz>(&ira->new_irb,
3105 source_instr->scope, source_instr->source_node);
3106 instruction->base.value->type = result_type;
3107 instruction->op = op;
3108
3109 ir_ref_inst_gen(op, ira->new_irb.current_basic_block);
3110
3111 return &instruction->base;
3112}
3113
3114static IrInstSrc *ir_build_pop_count(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type,
3115 IrInstSrc *op)
3116{
3117 IrInstSrcPopCount *instruction = ir_build_instruction<IrInstSrcPopCount>(irb, scope, source_node);
24963118 instruction->type = type;
24973119 instruction->op = op;
24983120
2499 if (type != nullptr) ir_ref_instruction(type, irb->current_basic_block);
3121 ir_ref_instruction(type, irb->current_basic_block);
25003122 ir_ref_instruction(op, irb->current_basic_block);
25013123
25023124 return &instruction->base;
25033125}
25043126
2505static IrInstruction *ir_build_bswap(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type, IrInstruction *op) {
2506 IrInstructionBswap *instruction = ir_build_instruction<IrInstructionBswap>(irb, scope, source_node);
3127static IrInstGen *ir_build_pop_count_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *result_type,
3128 IrInstGen *op)
3129{
3130 IrInstGenPopCount *instruction = ir_build_inst_gen<IrInstGenPopCount>(&ira->new_irb,
3131 source_instr->scope, source_instr->source_node);
3132 instruction->base.value->type = result_type;
3133 instruction->op = op;
3134
3135 ir_ref_inst_gen(op, ira->new_irb.current_basic_block);
3136
3137 return &instruction->base;
3138}
3139
3140static IrInstSrc *ir_build_bswap(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type,
3141 IrInstSrc *op)
3142{
3143 IrInstSrcBswap *instruction = ir_build_instruction<IrInstSrcBswap>(irb, scope, source_node);
25073144 instruction->type = type;
25083145 instruction->op = op;
25093146
2510 if (type != nullptr) ir_ref_instruction(type, irb->current_basic_block);
3147 ir_ref_instruction(type, irb->current_basic_block);
25113148 ir_ref_instruction(op, irb->current_basic_block);
25123149
25133150 return &instruction->base;
25143151}
25153152
2516static IrInstruction *ir_build_bit_reverse(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type, IrInstruction *op) {
2517 IrInstructionBitReverse *instruction = ir_build_instruction<IrInstructionBitReverse>(irb, scope, source_node);
3153static IrInstGen *ir_build_bswap_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *op_type,
3154 IrInstGen *op)
3155{
3156 IrInstGenBswap *instruction = ir_build_inst_gen<IrInstGenBswap>(&ira->new_irb,
3157 source_instr->scope, source_instr->source_node);
3158 instruction->base.value->type = op_type;
3159 instruction->op = op;
3160
3161 ir_ref_inst_gen(op, ira->new_irb.current_basic_block);
3162
3163 return &instruction->base;
3164}
3165
3166static IrInstSrc *ir_build_bit_reverse(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type,
3167 IrInstSrc *op)
3168{
3169 IrInstSrcBitReverse *instruction = ir_build_instruction<IrInstSrcBitReverse>(irb, scope, source_node);
25183170 instruction->type = type;
25193171 instruction->op = op;
25203172
2521 if (type != nullptr) ir_ref_instruction(type, irb->current_basic_block);
3173 ir_ref_instruction(type, irb->current_basic_block);
25223174 ir_ref_instruction(op, irb->current_basic_block);
25233175
25243176 return &instruction->base;
25253177}
25263178
2527static IrInstructionSwitchBr *ir_build_switch_br(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *target_value,
2528 IrBasicBlock *else_block, size_t case_count, IrInstructionSwitchBrCase *cases, IrInstruction *is_comptime,
2529 IrInstruction *switch_prongs_void)
3179static IrInstGen *ir_build_bit_reverse_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *int_type,
3180 IrInstGen *op)
25303181{
2531 IrInstructionSwitchBr *instruction = ir_build_instruction<IrInstructionSwitchBr>(irb, scope, source_node);
2532 instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;
2533 instruction->base.value->special = ConstValSpecialStatic;
3182 IrInstGenBitReverse *instruction = ir_build_inst_gen<IrInstGenBitReverse>(&ira->new_irb,
3183 source_instr->scope, source_instr->source_node);
3184 instruction->base.value->type = int_type;
3185 instruction->op = op;
3186
3187 ir_ref_inst_gen(op, ira->new_irb.current_basic_block);
3188
3189 return &instruction->base;
3190}
3191
3192static IrInstSrcSwitchBr *ir_build_switch_br_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3193 IrInstSrc *target_value, IrBasicBlockSrc *else_block, size_t case_count, IrInstSrcSwitchBrCase *cases,
3194 IrInstSrc *is_comptime, IrInstSrc *switch_prongs_void)
3195{
3196 IrInstSrcSwitchBr *instruction = ir_build_instruction<IrInstSrcSwitchBr>(irb, scope, source_node);
3197 instruction->base.is_noreturn = true;
25343198 instruction->target_value = target_value;
25353199 instruction->else_block = else_block;
25363200 instruction->case_count = case_count;
......@@ -2539,9 +3203,9 @@ static IrInstructionSwitchBr *ir_build_switch_br(IrBuilder *irb, Scope *scope, A
25393203 instruction->switch_prongs_void = switch_prongs_void;
25403204
25413205 ir_ref_instruction(target_value, irb->current_basic_block);
2542 if (is_comptime) ir_ref_instruction(is_comptime, irb->current_basic_block);
3206 ir_ref_instruction(is_comptime, irb->current_basic_block);
25433207 ir_ref_bb(else_block);
2544 if (switch_prongs_void) ir_ref_instruction(switch_prongs_void, irb->current_basic_block);
3208 ir_ref_instruction(switch_prongs_void, irb->current_basic_block);
25453209
25463210 for (size_t i = 0; i < case_count; i += 1) {
25473211 ir_ref_instruction(cases[i].value, irb->current_basic_block);
......@@ -2551,10 +3215,31 @@ static IrInstructionSwitchBr *ir_build_switch_br(IrBuilder *irb, Scope *scope, A
25513215 return instruction;
25523216}
25533217
2554static IrInstruction *ir_build_switch_target(IrBuilder *irb, Scope *scope, AstNode *source_node,
2555 IrInstruction *target_value_ptr)
3218static IrInstGenSwitchBr *ir_build_switch_br_gen(IrAnalyze *ira, IrInst *source_instr,
3219 IrInstGen *target_value, IrBasicBlockGen *else_block, size_t case_count, IrInstGenSwitchBrCase *cases)
25563220{
2557 IrInstructionSwitchTarget *instruction = ir_build_instruction<IrInstructionSwitchTarget>(irb, scope, source_node);
3221 IrInstGenSwitchBr *instruction = ir_build_inst_noreturn<IrInstGenSwitchBr>(&ira->new_irb,
3222 source_instr->scope, source_instr->source_node);
3223 instruction->target_value = target_value;
3224 instruction->else_block = else_block;
3225 instruction->case_count = case_count;
3226 instruction->cases = cases;
3227
3228 ir_ref_inst_gen(target_value, ira->new_irb.current_basic_block);
3229 ir_ref_bb_gen(else_block);
3230
3231 for (size_t i = 0; i < case_count; i += 1) {
3232 ir_ref_inst_gen(cases[i].value, ira->new_irb.current_basic_block);
3233 ir_ref_bb_gen(cases[i].block);
3234 }
3235
3236 return instruction;
3237}
3238
3239static IrInstSrc *ir_build_switch_target(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3240 IrInstSrc *target_value_ptr)
3241{
3242 IrInstSrcSwitchTarget *instruction = ir_build_instruction<IrInstSrcSwitchTarget>(irb, scope, source_node);
25583243 instruction->target_value_ptr = target_value_ptr;
25593244
25603245 ir_ref_instruction(target_value_ptr, irb->current_basic_block);
......@@ -2562,10 +3247,10 @@ static IrInstruction *ir_build_switch_target(IrBuilder *irb, Scope *scope, AstNo
25623247 return &instruction->base;
25633248}
25643249
2565static IrInstruction *ir_build_switch_var(IrBuilder *irb, Scope *scope, AstNode *source_node,
2566 IrInstruction *target_value_ptr, IrInstruction **prongs_ptr, size_t prongs_len)
3250static IrInstSrc *ir_build_switch_var(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3251 IrInstSrc *target_value_ptr, IrInstSrc **prongs_ptr, size_t prongs_len)
25673252{
2568 IrInstructionSwitchVar *instruction = ir_build_instruction<IrInstructionSwitchVar>(irb, scope, source_node);
3253 IrInstSrcSwitchVar *instruction = ir_build_instruction<IrInstSrcSwitchVar>(irb, scope, source_node);
25693254 instruction->target_value_ptr = target_value_ptr;
25703255 instruction->prongs_ptr = prongs_ptr;
25713256 instruction->prongs_len = prongs_len;
......@@ -2579,10 +3264,10 @@ static IrInstruction *ir_build_switch_var(IrBuilder *irb, Scope *scope, AstNode
25793264}
25803265
25813266// For this instruction the switch_br must be set later.
2582static IrInstructionSwitchElseVar *ir_build_switch_else_var(IrBuilder *irb, Scope *scope, AstNode *source_node,
2583 IrInstruction *target_value_ptr)
3267static IrInstSrcSwitchElseVar *ir_build_switch_else_var(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3268 IrInstSrc *target_value_ptr)
25843269{
2585 IrInstructionSwitchElseVar *instruction = ir_build_instruction<IrInstructionSwitchElseVar>(irb, scope, source_node);
3270 IrInstSrcSwitchElseVar *instruction = ir_build_instruction<IrInstSrcSwitchElseVar>(irb, scope, source_node);
25863271 instruction->target_value_ptr = target_value_ptr;
25873272
25883273 ir_ref_instruction(target_value_ptr, irb->current_basic_block);
......@@ -2590,17 +3275,21 @@ static IrInstructionSwitchElseVar *ir_build_switch_else_var(IrBuilder *irb, Scop
25903275 return instruction;
25913276}
25923277
2593static IrInstruction *ir_build_union_tag(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) {
2594 IrInstructionUnionTag *instruction = ir_build_instruction<IrInstructionUnionTag>(irb, scope, source_node);
3278static IrInstGen *ir_build_union_tag(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value,
3279 ZigType *tag_type)
3280{
3281 IrInstGenUnionTag *instruction = ir_build_inst_gen<IrInstGenUnionTag>(&ira->new_irb,
3282 source_instr->scope, source_instr->source_node);
25953283 instruction->value = value;
3284 instruction->base.value->type = tag_type;
25963285
2597 ir_ref_instruction(value, irb->current_basic_block);
3286 ir_ref_inst_gen(value, ira->new_irb.current_basic_block);
25983287
25993288 return &instruction->base;
26003289}
26013290
2602static IrInstruction *ir_build_import(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *name) {
2603 IrInstructionImport *instruction = ir_build_instruction<IrInstructionImport>(irb, scope, source_node);
3291static IrInstSrc *ir_build_import(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name) {
3292 IrInstSrcImport *instruction = ir_build_instruction<IrInstSrcImport>(irb, scope, source_node);
26043293 instruction->name = name;
26053294
26063295 ir_ref_instruction(name, irb->current_basic_block);
......@@ -2608,10 +3297,10 @@ static IrInstruction *ir_build_import(IrBuilder *irb, Scope *scope, AstNode *sou
26083297 return &instruction->base;
26093298}
26103299
2611static IrInstruction *ir_build_ref(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value,
3300static IrInstSrc *ir_build_ref_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value,
26123301 bool is_const, bool is_volatile)
26133302{
2614 IrInstructionRef *instruction = ir_build_instruction<IrInstructionRef>(irb, scope, source_node);
3303 IrInstSrcRef *instruction = ir_build_instruction<IrInstSrcRef>(irb, scope, source_node);
26153304 instruction->value = value;
26163305 instruction->is_const = is_const;
26173306 instruction->is_volatile = is_volatile;
......@@ -2621,23 +3310,23 @@ static IrInstruction *ir_build_ref(IrBuilder *irb, Scope *scope, AstNode *source
26213310 return &instruction->base;
26223311}
26233312
2624static IrInstruction *ir_build_ref_gen(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *result_type,
2625 IrInstruction *operand, IrInstruction *result_loc)
3313static IrInstGen *ir_build_ref_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_type,
3314 IrInstGen *operand, IrInstGen *result_loc)
26263315{
2627 IrInstructionRefGen *instruction = ir_build_instruction<IrInstructionRefGen>(&ira->new_irb,
3316 IrInstGenRef *instruction = ir_build_inst_gen<IrInstGenRef>(&ira->new_irb,
26283317 source_instruction->scope, source_instruction->source_node);
26293318 instruction->base.value->type = result_type;
26303319 instruction->operand = operand;
26313320 instruction->result_loc = result_loc;
26323321
2633 ir_ref_instruction(operand, ira->new_irb.current_basic_block);
2634 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);
3322 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
3323 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
26353324
26363325 return &instruction->base;
26373326}
26383327
2639static IrInstruction *ir_build_compile_err(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *msg) {
2640 IrInstructionCompileErr *instruction = ir_build_instruction<IrInstructionCompileErr>(irb, scope, source_node);
3328static IrInstSrc *ir_build_compile_err(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *msg) {
3329 IrInstSrcCompileErr *instruction = ir_build_instruction<IrInstSrcCompileErr>(irb, scope, source_node);
26413330 instruction->msg = msg;
26423331
26433332 ir_ref_instruction(msg, irb->current_basic_block);
......@@ -2645,10 +3334,10 @@ static IrInstruction *ir_build_compile_err(IrBuilder *irb, Scope *scope, AstNode
26453334 return &instruction->base;
26463335}
26473336
2648static IrInstruction *ir_build_compile_log(IrBuilder *irb, Scope *scope, AstNode *source_node,
2649 size_t msg_count, IrInstruction **msg_list)
3337static IrInstSrc *ir_build_compile_log(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3338 size_t msg_count, IrInstSrc **msg_list)
26503339{
2651 IrInstructionCompileLog *instruction = ir_build_instruction<IrInstructionCompileLog>(irb, scope, source_node);
3340 IrInstSrcCompileLog *instruction = ir_build_instruction<IrInstSrcCompileLog>(irb, scope, source_node);
26523341 instruction->msg_count = msg_count;
26533342 instruction->msg_list = msg_list;
26543343
......@@ -2659,8 +3348,8 @@ static IrInstruction *ir_build_compile_log(IrBuilder *irb, Scope *scope, AstNode
26593348 return &instruction->base;
26603349}
26613350
2662static IrInstruction *ir_build_err_name(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) {
2663 IrInstructionErrName *instruction = ir_build_instruction<IrInstructionErrName>(irb, scope, source_node);
3351static IrInstSrc *ir_build_err_name(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value) {
3352 IrInstSrcErrName *instruction = ir_build_instruction<IrInstSrcErrName>(irb, scope, source_node);
26643353 instruction->value = value;
26653354
26663355 ir_ref_instruction(value, irb->current_basic_block);
......@@ -2668,13 +3357,26 @@ static IrInstruction *ir_build_err_name(IrBuilder *irb, Scope *scope, AstNode *s
26683357 return &instruction->base;
26693358}
26703359
2671static IrInstruction *ir_build_c_import(IrBuilder *irb, Scope *scope, AstNode *source_node) {
2672 IrInstructionCImport *instruction = ir_build_instruction<IrInstructionCImport>(irb, scope, source_node);
3360static IrInstGen *ir_build_err_name_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value,
3361 ZigType *str_type)
3362{
3363 IrInstGenErrName *instruction = ir_build_inst_gen<IrInstGenErrName>(&ira->new_irb,
3364 source_instr->scope, source_instr->source_node);
3365 instruction->base.value->type = str_type;
3366 instruction->value = value;
3367
3368 ir_ref_inst_gen(value, ira->new_irb.current_basic_block);
3369
3370 return &instruction->base;
3371}
3372
3373static IrInstSrc *ir_build_c_import(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
3374 IrInstSrcCImport *instruction = ir_build_instruction<IrInstSrcCImport>(irb, scope, source_node);
26733375 return &instruction->base;
26743376}
26753377
2676static IrInstruction *ir_build_c_include(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *name) {
2677 IrInstructionCInclude *instruction = ir_build_instruction<IrInstructionCInclude>(irb, scope, source_node);
3378static IrInstSrc *ir_build_c_include(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name) {
3379 IrInstSrcCInclude *instruction = ir_build_instruction<IrInstSrcCInclude>(irb, scope, source_node);
26783380 instruction->name = name;
26793381
26803382 ir_ref_instruction(name, irb->current_basic_block);
......@@ -2682,8 +3384,8 @@ static IrInstruction *ir_build_c_include(IrBuilder *irb, Scope *scope, AstNode *
26823384 return &instruction->base;
26833385}
26843386
2685static IrInstruction *ir_build_c_define(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *name, IrInstruction *value) {
2686 IrInstructionCDefine *instruction = ir_build_instruction<IrInstructionCDefine>(irb, scope, source_node);
3387static IrInstSrc *ir_build_c_define(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name, IrInstSrc *value) {
3388 IrInstSrcCDefine *instruction = ir_build_instruction<IrInstSrcCDefine>(irb, scope, source_node);
26873389 instruction->name = name;
26883390 instruction->value = value;
26893391
......@@ -2693,8 +3395,8 @@ static IrInstruction *ir_build_c_define(IrBuilder *irb, Scope *scope, AstNode *s
26933395 return &instruction->base;
26943396}
26953397
2696static IrInstruction *ir_build_c_undef(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *name) {
2697 IrInstructionCUndef *instruction = ir_build_instruction<IrInstructionCUndef>(irb, scope, source_node);
3398static IrInstSrc *ir_build_c_undef(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name) {
3399 IrInstSrcCUndef *instruction = ir_build_instruction<IrInstSrcCUndef>(irb, scope, source_node);
26983400 instruction->name = name;
26993401
27003402 ir_ref_instruction(name, irb->current_basic_block);
......@@ -2702,8 +3404,8 @@ static IrInstruction *ir_build_c_undef(IrBuilder *irb, Scope *scope, AstNode *so
27023404 return &instruction->base;
27033405}
27043406
2705static IrInstruction *ir_build_embed_file(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *name) {
2706 IrInstructionEmbedFile *instruction = ir_build_instruction<IrInstructionEmbedFile>(irb, scope, source_node);
3407static IrInstSrc *ir_build_embed_file(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name) {
3408 IrInstSrcEmbedFile *instruction = ir_build_instruction<IrInstSrcEmbedFile>(irb, scope, source_node);
27073409 instruction->name = name;
27083410
27093411 ir_ref_instruction(name, irb->current_basic_block);
......@@ -2711,11 +3413,11 @@ static IrInstruction *ir_build_embed_file(IrBuilder *irb, Scope *scope, AstNode
27113413 return &instruction->base;
27123414}
27133415
2714static IrInstruction *ir_build_cmpxchg_src(IrBuilder *irb, Scope *scope, AstNode *source_node,
2715 IrInstruction *type_value, IrInstruction *ptr, IrInstruction *cmp_value, IrInstruction *new_value,
2716 IrInstruction *success_order_value, IrInstruction *failure_order_value, bool is_weak, ResultLoc *result_loc)
3416static IrInstSrc *ir_build_cmpxchg_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3417 IrInstSrc *type_value, IrInstSrc *ptr, IrInstSrc *cmp_value, IrInstSrc *new_value,
3418 IrInstSrc *success_order_value, IrInstSrc *failure_order_value, bool is_weak, ResultLoc *result_loc)
27173419{
2718 IrInstructionCmpxchgSrc *instruction = ir_build_instruction<IrInstructionCmpxchgSrc>(irb, scope, source_node);
3420 IrInstSrcCmpxchg *instruction = ir_build_instruction<IrInstSrcCmpxchg>(irb, scope, source_node);
27193421 instruction->type_value = type_value;
27203422 instruction->ptr = ptr;
27213423 instruction->cmp_value = cmp_value;
......@@ -2735,11 +3437,11 @@ static IrInstruction *ir_build_cmpxchg_src(IrBuilder *irb, Scope *scope, AstNode
27353437 return &instruction->base;
27363438}
27373439
2738static IrInstruction *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *result_type,
2739 IrInstruction *ptr, IrInstruction *cmp_value, IrInstruction *new_value,
2740 AtomicOrder success_order, AtomicOrder failure_order, bool is_weak, IrInstruction *result_loc)
3440static IrInstGen *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_type,
3441 IrInstGen *ptr, IrInstGen *cmp_value, IrInstGen *new_value,
3442 AtomicOrder success_order, AtomicOrder failure_order, bool is_weak, IrInstGen *result_loc)
27413443{
2742 IrInstructionCmpxchgGen *instruction = ir_build_instruction<IrInstructionCmpxchgGen>(&ira->new_irb,
3444 IrInstGenCmpxchg *instruction = ir_build_inst_gen<IrInstGenCmpxchg>(&ira->new_irb,
27433445 source_instruction->scope, source_instruction->source_node);
27443446 instruction->base.value->type = result_type;
27453447 instruction->ptr = ptr;
......@@ -2750,26 +3452,35 @@ static IrInstruction *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInstruction *source
27503452 instruction->is_weak = is_weak;
27513453 instruction->result_loc = result_loc;
27523454
2753 ir_ref_instruction(ptr, ira->new_irb.current_basic_block);
2754 ir_ref_instruction(cmp_value, ira->new_irb.current_basic_block);
2755 ir_ref_instruction(new_value, ira->new_irb.current_basic_block);
2756 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);
3455 ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block);
3456 ir_ref_inst_gen(cmp_value, ira->new_irb.current_basic_block);
3457 ir_ref_inst_gen(new_value, ira->new_irb.current_basic_block);
3458 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
27573459
27583460 return &instruction->base;
27593461}
27603462
2761static IrInstruction *ir_build_fence(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *order_value, AtomicOrder order) {
2762 IrInstructionFence *instruction = ir_build_instruction<IrInstructionFence>(irb, scope, source_node);
2763 instruction->order_value = order_value;
3463static IrInstSrc *ir_build_fence(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *order) {
3464 IrInstSrcFence *instruction = ir_build_instruction<IrInstSrcFence>(irb, scope, source_node);
27643465 instruction->order = order;
27653466
2766 ir_ref_instruction(order_value, irb->current_basic_block);
3467 ir_ref_instruction(order, irb->current_basic_block);
3468
3469 return &instruction->base;
3470}
3471
3472static IrInstGen *ir_build_fence_gen(IrAnalyze *ira, IrInst *source_instr, AtomicOrder order) {
3473 IrInstGenFence *instruction = ir_build_inst_void<IrInstGenFence>(&ira->new_irb,
3474 source_instr->scope, source_instr->source_node);
3475 instruction->order = order;
27673476
27683477 return &instruction->base;
27693478}
27703479
2771static IrInstruction *ir_build_truncate(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_type, IrInstruction *target) {
2772 IrInstructionTruncate *instruction = ir_build_instruction<IrInstructionTruncate>(irb, scope, source_node);
3480static IrInstSrc *ir_build_truncate(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3481 IrInstSrc *dest_type, IrInstSrc *target)
3482{
3483 IrInstSrcTruncate *instruction = ir_build_instruction<IrInstSrcTruncate>(irb, scope, source_node);
27733484 instruction->dest_type = dest_type;
27743485 instruction->target = target;
27753486
......@@ -2779,8 +3490,23 @@ static IrInstruction *ir_build_truncate(IrBuilder *irb, Scope *scope, AstNode *s
27793490 return &instruction->base;
27803491}
27813492
2782static IrInstruction *ir_build_int_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_type, IrInstruction *target) {
2783 IrInstructionIntCast *instruction = ir_build_instruction<IrInstructionIntCast>(irb, scope, source_node);
3493static IrInstGen *ir_build_truncate_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *dest_type,
3494 IrInstGen *target)
3495{
3496 IrInstGenTruncate *instruction = ir_build_inst_gen<IrInstGenTruncate>(&ira->new_irb,
3497 source_instr->scope, source_instr->source_node);
3498 instruction->base.value->type = dest_type;
3499 instruction->target = target;
3500
3501 ir_ref_inst_gen(target, ira->new_irb.current_basic_block);
3502
3503 return &instruction->base;
3504}
3505
3506static IrInstSrc *ir_build_int_cast(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *dest_type,
3507 IrInstSrc *target)
3508{
3509 IrInstSrcIntCast *instruction = ir_build_instruction<IrInstSrcIntCast>(irb, scope, source_node);
27843510 instruction->dest_type = dest_type;
27853511 instruction->target = target;
27863512
......@@ -2790,8 +3516,10 @@ static IrInstruction *ir_build_int_cast(IrBuilder *irb, Scope *scope, AstNode *s
27903516 return &instruction->base;
27913517}
27923518
2793static IrInstruction *ir_build_float_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_type, IrInstruction *target) {
2794 IrInstructionFloatCast *instruction = ir_build_instruction<IrInstructionFloatCast>(irb, scope, source_node);
3519static IrInstSrc *ir_build_float_cast(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *dest_type,
3520 IrInstSrc *target)
3521{
3522 IrInstSrcFloatCast *instruction = ir_build_instruction<IrInstSrcFloatCast>(irb, scope, source_node);
27953523 instruction->dest_type = dest_type;
27963524 instruction->target = target;
27973525
......@@ -2801,8 +3529,10 @@ static IrInstruction *ir_build_float_cast(IrBuilder *irb, Scope *scope, AstNode
28013529 return &instruction->base;
28023530}
28033531
2804static IrInstruction *ir_build_err_set_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_type, IrInstruction *target) {
2805 IrInstructionErrSetCast *instruction = ir_build_instruction<IrInstructionErrSetCast>(irb, scope, source_node);
3532static IrInstSrc *ir_build_err_set_cast(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3533 IrInstSrc *dest_type, IrInstSrc *target)
3534{
3535 IrInstSrcErrSetCast *instruction = ir_build_instruction<IrInstSrcErrSetCast>(irb, scope, source_node);
28063536 instruction->dest_type = dest_type;
28073537 instruction->target = target;
28083538
......@@ -2812,10 +3542,10 @@ static IrInstruction *ir_build_err_set_cast(IrBuilder *irb, Scope *scope, AstNod
28123542 return &instruction->base;
28133543}
28143544
2815static IrInstruction *ir_build_to_bytes(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *target,
3545static IrInstSrc *ir_build_to_bytes(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *target,
28163546 ResultLoc *result_loc)
28173547{
2818 IrInstructionToBytes *instruction = ir_build_instruction<IrInstructionToBytes>(irb, scope, source_node);
3548 IrInstSrcToBytes *instruction = ir_build_instruction<IrInstSrcToBytes>(irb, scope, source_node);
28193549 instruction->target = target;
28203550 instruction->result_loc = result_loc;
28213551
......@@ -2824,10 +3554,10 @@ static IrInstruction *ir_build_to_bytes(IrBuilder *irb, Scope *scope, AstNode *s
28243554 return &instruction->base;
28253555}
28263556
2827static IrInstruction *ir_build_from_bytes(IrBuilder *irb, Scope *scope, AstNode *source_node,
2828 IrInstruction *dest_child_type, IrInstruction *target, ResultLoc *result_loc)
3557static IrInstSrc *ir_build_from_bytes(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3558 IrInstSrc *dest_child_type, IrInstSrc *target, ResultLoc *result_loc)
28293559{
2830 IrInstructionFromBytes *instruction = ir_build_instruction<IrInstructionFromBytes>(irb, scope, source_node);
3560 IrInstSrcFromBytes *instruction = ir_build_instruction<IrInstSrcFromBytes>(irb, scope, source_node);
28313561 instruction->dest_child_type = dest_child_type;
28323562 instruction->target = target;
28333563 instruction->result_loc = result_loc;
......@@ -2838,8 +3568,10 @@ static IrInstruction *ir_build_from_bytes(IrBuilder *irb, Scope *scope, AstNode
28383568 return &instruction->base;
28393569}
28403570
2841static IrInstruction *ir_build_int_to_float(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_type, IrInstruction *target) {
2842 IrInstructionIntToFloat *instruction = ir_build_instruction<IrInstructionIntToFloat>(irb, scope, source_node);
3571static IrInstSrc *ir_build_int_to_float(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3572 IrInstSrc *dest_type, IrInstSrc *target)
3573{
3574 IrInstSrcIntToFloat *instruction = ir_build_instruction<IrInstSrcIntToFloat>(irb, scope, source_node);
28433575 instruction->dest_type = dest_type;
28443576 instruction->target = target;
28453577
......@@ -2849,8 +3581,10 @@ static IrInstruction *ir_build_int_to_float(IrBuilder *irb, Scope *scope, AstNod
28493581 return &instruction->base;
28503582}
28513583
2852static IrInstruction *ir_build_float_to_int(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_type, IrInstruction *target) {
2853 IrInstructionFloatToInt *instruction = ir_build_instruction<IrInstructionFloatToInt>(irb, scope, source_node);
3584static IrInstSrc *ir_build_float_to_int(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3585 IrInstSrc *dest_type, IrInstSrc *target)
3586{
3587 IrInstSrcFloatToInt *instruction = ir_build_instruction<IrInstSrcFloatToInt>(irb, scope, source_node);
28543588 instruction->dest_type = dest_type;
28553589 instruction->target = target;
28563590
......@@ -2860,8 +3594,8 @@ static IrInstruction *ir_build_float_to_int(IrBuilder *irb, Scope *scope, AstNod
28603594 return &instruction->base;
28613595}
28623596
2863static IrInstruction *ir_build_bool_to_int(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *target) {
2864 IrInstructionBoolToInt *instruction = ir_build_instruction<IrInstructionBoolToInt>(irb, scope, source_node);
3597static IrInstSrc *ir_build_bool_to_int(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *target) {
3598 IrInstSrcBoolToInt *instruction = ir_build_instruction<IrInstSrcBoolToInt>(irb, scope, source_node);
28653599 instruction->target = target;
28663600
28673601 ir_ref_instruction(target, irb->current_basic_block);
......@@ -2869,8 +3603,10 @@ static IrInstruction *ir_build_bool_to_int(IrBuilder *irb, Scope *scope, AstNode
28693603 return &instruction->base;
28703604}
28713605
2872static IrInstruction *ir_build_int_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *is_signed, IrInstruction *bit_count) {
2873 IrInstructionIntType *instruction = ir_build_instruction<IrInstructionIntType>(irb, scope, source_node);
3606static IrInstSrc *ir_build_int_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *is_signed,
3607 IrInstSrc *bit_count)
3608{
3609 IrInstSrcIntType *instruction = ir_build_instruction<IrInstSrcIntType>(irb, scope, source_node);
28743610 instruction->is_signed = is_signed;
28753611 instruction->bit_count = bit_count;
28763612
......@@ -2880,10 +3616,10 @@ static IrInstruction *ir_build_int_type(IrBuilder *irb, Scope *scope, AstNode *s
28803616 return &instruction->base;
28813617}
28823618
2883static IrInstruction *ir_build_vector_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *len,
2884 IrInstruction *elem_type)
3619static IrInstSrc *ir_build_vector_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *len,
3620 IrInstSrc *elem_type)
28853621{
2886 IrInstructionVectorType *instruction = ir_build_instruction<IrInstructionVectorType>(irb, scope, source_node);
3622 IrInstSrcVectorType *instruction = ir_build_instruction<IrInstSrcVectorType>(irb, scope, source_node);
28873623 instruction->len = len;
28883624 instruction->elem_type = elem_type;
28893625
......@@ -2893,18 +3629,16 @@ static IrInstruction *ir_build_vector_type(IrBuilder *irb, Scope *scope, AstNode
28933629 return &instruction->base;
28943630}
28953631
2896static IrInstruction *ir_build_shuffle_vector(IrBuilder *irb, Scope *scope, AstNode *source_node,
2897 IrInstruction *scalar_type, IrInstruction *a, IrInstruction *b, IrInstruction *mask)
3632static IrInstSrc *ir_build_shuffle_vector(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3633 IrInstSrc *scalar_type, IrInstSrc *a, IrInstSrc *b, IrInstSrc *mask)
28983634{
2899 IrInstructionShuffleVector *instruction = ir_build_instruction<IrInstructionShuffleVector>(irb, scope, source_node);
3635 IrInstSrcShuffleVector *instruction = ir_build_instruction<IrInstSrcShuffleVector>(irb, scope, source_node);
29003636 instruction->scalar_type = scalar_type;
29013637 instruction->a = a;
29023638 instruction->b = b;
29033639 instruction->mask = mask;
29043640
2905 if (scalar_type != nullptr) {
2906 ir_ref_instruction(scalar_type, irb->current_basic_block);
2907 }
3641 if (scalar_type != nullptr) ir_ref_instruction(scalar_type, irb->current_basic_block);
29083642 ir_ref_instruction(a, irb->current_basic_block);
29093643 ir_ref_instruction(b, irb->current_basic_block);
29103644 ir_ref_instruction(mask, irb->current_basic_block);
......@@ -2912,10 +3646,26 @@ static IrInstruction *ir_build_shuffle_vector(IrBuilder *irb, Scope *scope, AstN
29123646 return &instruction->base;
29133647}
29143648
2915static IrInstruction *ir_build_splat_src(IrBuilder *irb, Scope *scope, AstNode *source_node,
2916 IrInstruction *len, IrInstruction *scalar)
3649static IrInstGen *ir_build_shuffle_vector_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
3650 ZigType *result_type, IrInstGen *a, IrInstGen *b, IrInstGen *mask)
29173651{
2918 IrInstructionSplatSrc *instruction = ir_build_instruction<IrInstructionSplatSrc>(irb, scope, source_node);
3652 IrInstGenShuffleVector *inst = ir_build_inst_gen<IrInstGenShuffleVector>(&ira->new_irb, scope, source_node);
3653 inst->base.value->type = result_type;
3654 inst->a = a;
3655 inst->b = b;
3656 inst->mask = mask;
3657
3658 ir_ref_inst_gen(a, ira->new_irb.current_basic_block);
3659 ir_ref_inst_gen(b, ira->new_irb.current_basic_block);
3660 ir_ref_inst_gen(mask, ira->new_irb.current_basic_block);
3661
3662 return &inst->base;
3663}
3664
3665static IrInstSrc *ir_build_splat_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3666 IrInstSrc *len, IrInstSrc *scalar)
3667{
3668 IrInstSrcSplat *instruction = ir_build_instruction<IrInstSrcSplat>(irb, scope, source_node);
29193669 instruction->len = len;
29203670 instruction->scalar = scalar;
29213671
......@@ -2925,8 +3675,21 @@ static IrInstruction *ir_build_splat_src(IrBuilder *irb, Scope *scope, AstNode *
29253675 return &instruction->base;
29263676}
29273677
2928static IrInstruction *ir_build_bool_not(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) {
2929 IrInstructionBoolNot *instruction = ir_build_instruction<IrInstructionBoolNot>(irb, scope, source_node);
3678static IrInstGen *ir_build_splat_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_type,
3679 IrInstGen *scalar)
3680{
3681 IrInstGenSplat *instruction = ir_build_inst_gen<IrInstGenSplat>(
3682 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
3683 instruction->base.value->type = result_type;
3684 instruction->scalar = scalar;
3685
3686 ir_ref_inst_gen(scalar, ira->new_irb.current_basic_block);
3687
3688 return &instruction->base;
3689}
3690
3691static IrInstSrc *ir_build_bool_not(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value) {
3692 IrInstSrcBoolNot *instruction = ir_build_instruction<IrInstSrcBoolNot>(irb, scope, source_node);
29303693 instruction->value = value;
29313694
29323695 ir_ref_instruction(value, irb->current_basic_block);
......@@ -2934,10 +3697,21 @@ static IrInstruction *ir_build_bool_not(IrBuilder *irb, Scope *scope, AstNode *s
29343697 return &instruction->base;
29353698}
29363699
2937static IrInstruction *ir_build_memset(IrBuilder *irb, Scope *scope, AstNode *source_node,
2938 IrInstruction *dest_ptr, IrInstruction *byte, IrInstruction *count)
3700static IrInstGen *ir_build_bool_not_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value) {
3701 IrInstGenBoolNot *instruction = ir_build_inst_gen<IrInstGenBoolNot>(&ira->new_irb,
3702 source_instr->scope, source_instr->source_node);
3703 instruction->base.value->type = ira->codegen->builtin_types.entry_bool;
3704 instruction->value = value;
3705
3706 ir_ref_inst_gen(value, ira->new_irb.current_basic_block);
3707
3708 return &instruction->base;
3709}
3710
3711static IrInstSrc *ir_build_memset_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3712 IrInstSrc *dest_ptr, IrInstSrc *byte, IrInstSrc *count)
29393713{
2940 IrInstructionMemset *instruction = ir_build_instruction<IrInstructionMemset>(irb, scope, source_node);
3714 IrInstSrcMemset *instruction = ir_build_instruction<IrInstSrcMemset>(irb, scope, source_node);
29413715 instruction->dest_ptr = dest_ptr;
29423716 instruction->byte = byte;
29433717 instruction->count = count;
......@@ -2949,10 +3723,26 @@ static IrInstruction *ir_build_memset(IrBuilder *irb, Scope *scope, AstNode *sou
29493723 return &instruction->base;
29503724}
29513725
2952static IrInstruction *ir_build_memcpy(IrBuilder *irb, Scope *scope, AstNode *source_node,
2953 IrInstruction *dest_ptr, IrInstruction *src_ptr, IrInstruction *count)
3726static IrInstGen *ir_build_memset_gen(IrAnalyze *ira, IrInst *source_instr,
3727 IrInstGen *dest_ptr, IrInstGen *byte, IrInstGen *count)
3728{
3729 IrInstGenMemset *instruction = ir_build_inst_void<IrInstGenMemset>(&ira->new_irb,
3730 source_instr->scope, source_instr->source_node);
3731 instruction->dest_ptr = dest_ptr;
3732 instruction->byte = byte;
3733 instruction->count = count;
3734
3735 ir_ref_inst_gen(dest_ptr, ira->new_irb.current_basic_block);
3736 ir_ref_inst_gen(byte, ira->new_irb.current_basic_block);
3737 ir_ref_inst_gen(count, ira->new_irb.current_basic_block);
3738
3739 return &instruction->base;
3740}
3741
3742static IrInstSrc *ir_build_memcpy_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3743 IrInstSrc *dest_ptr, IrInstSrc *src_ptr, IrInstSrc *count)
29543744{
2955 IrInstructionMemcpy *instruction = ir_build_instruction<IrInstructionMemcpy>(irb, scope, source_node);
3745 IrInstSrcMemcpy *instruction = ir_build_instruction<IrInstSrcMemcpy>(irb, scope, source_node);
29563746 instruction->dest_ptr = dest_ptr;
29573747 instruction->src_ptr = src_ptr;
29583748 instruction->count = count;
......@@ -2964,11 +3754,27 @@ static IrInstruction *ir_build_memcpy(IrBuilder *irb, Scope *scope, AstNode *sou
29643754 return &instruction->base;
29653755}
29663756
2967static IrInstruction *ir_build_slice_src(IrBuilder *irb, Scope *scope, AstNode *source_node,
2968 IrInstruction *ptr, IrInstruction *start, IrInstruction *end, IrInstruction *sentinel,
3757static IrInstGen *ir_build_memcpy_gen(IrAnalyze *ira, IrInst *source_instr,
3758 IrInstGen *dest_ptr, IrInstGen *src_ptr, IrInstGen *count)
3759{
3760 IrInstGenMemcpy *instruction = ir_build_inst_void<IrInstGenMemcpy>(&ira->new_irb,
3761 source_instr->scope, source_instr->source_node);
3762 instruction->dest_ptr = dest_ptr;
3763 instruction->src_ptr = src_ptr;
3764 instruction->count = count;
3765
3766 ir_ref_inst_gen(dest_ptr, ira->new_irb.current_basic_block);
3767 ir_ref_inst_gen(src_ptr, ira->new_irb.current_basic_block);
3768 ir_ref_inst_gen(count, ira->new_irb.current_basic_block);
3769
3770 return &instruction->base;
3771}
3772
3773static IrInstSrc *ir_build_slice_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3774 IrInstSrc *ptr, IrInstSrc *start, IrInstSrc *end, IrInstSrc *sentinel,
29693775 bool safety_check_on, ResultLoc *result_loc)
29703776{
2971 IrInstructionSliceSrc *instruction = ir_build_instruction<IrInstructionSliceSrc>(irb, scope, source_node);
3777 IrInstSrcSlice *instruction = ir_build_instruction<IrInstSrcSlice>(irb, scope, source_node);
29723778 instruction->ptr = ptr;
29733779 instruction->start = start;
29743780 instruction->end = end;
......@@ -2984,23 +3790,10 @@ static IrInstruction *ir_build_slice_src(IrBuilder *irb, Scope *scope, AstNode *
29843790 return &instruction->base;
29853791}
29863792
2987static IrInstruction *ir_build_splat_gen(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *result_type,
2988 IrInstruction *scalar)
2989{
2990 IrInstructionSplatGen *instruction = ir_build_instruction<IrInstructionSplatGen>(
2991 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
2992 instruction->base.value->type = result_type;
2993 instruction->scalar = scalar;
2994
2995 ir_ref_instruction(scalar, ira->new_irb.current_basic_block);
2996
2997 return &instruction->base;
2998}
2999
3000static IrInstruction *ir_build_slice_gen(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *slice_type,
3001 IrInstruction *ptr, IrInstruction *start, IrInstruction *end, bool safety_check_on, IrInstruction *result_loc)
3793static IrInstGen *ir_build_slice_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *slice_type,
3794 IrInstGen *ptr, IrInstGen *start, IrInstGen *end, bool safety_check_on, IrInstGen *result_loc)
30023795{
3003 IrInstructionSliceGen *instruction = ir_build_instruction<IrInstructionSliceGen>(
3796 IrInstGenSlice *instruction = ir_build_inst_gen<IrInstGenSlice>(
30043797 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
30053798 instruction->base.value->type = slice_type;
30063799 instruction->ptr = ptr;
......@@ -3009,16 +3802,16 @@ static IrInstruction *ir_build_slice_gen(IrAnalyze *ira, IrInstruction *source_i
30093802 instruction->safety_check_on = safety_check_on;
30103803 instruction->result_loc = result_loc;
30113804
3012 ir_ref_instruction(ptr, ira->new_irb.current_basic_block);
3013 ir_ref_instruction(start, ira->new_irb.current_basic_block);
3014 if (end) ir_ref_instruction(end, ira->new_irb.current_basic_block);
3015 ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);
3805 ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block);
3806 ir_ref_inst_gen(start, ira->new_irb.current_basic_block);
3807 if (end) ir_ref_inst_gen(end, ira->new_irb.current_basic_block);
3808 ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
30163809
30173810 return &instruction->base;
30183811}
30193812
3020static IrInstruction *ir_build_member_count(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *container) {
3021 IrInstructionMemberCount *instruction = ir_build_instruction<IrInstructionMemberCount>(irb, scope, source_node);
3813static IrInstSrc *ir_build_member_count(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *container) {
3814 IrInstSrcMemberCount *instruction = ir_build_instruction<IrInstSrcMemberCount>(irb, scope, source_node);
30223815 instruction->container = container;
30233816
30243817 ir_ref_instruction(container, irb->current_basic_block);
......@@ -3026,10 +3819,10 @@ static IrInstruction *ir_build_member_count(IrBuilder *irb, Scope *scope, AstNod
30263819 return &instruction->base;
30273820}
30283821
3029static IrInstruction *ir_build_member_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
3030 IrInstruction *container_type, IrInstruction *member_index)
3822static IrInstSrc *ir_build_member_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3823 IrInstSrc *container_type, IrInstSrc *member_index)
30313824{
3032 IrInstructionMemberType *instruction = ir_build_instruction<IrInstructionMemberType>(irb, scope, source_node);
3825 IrInstSrcMemberType *instruction = ir_build_instruction<IrInstSrcMemberType>(irb, scope, source_node);
30333826 instruction->container_type = container_type;
30343827 instruction->member_index = member_index;
30353828
......@@ -3039,10 +3832,10 @@ static IrInstruction *ir_build_member_type(IrBuilder *irb, Scope *scope, AstNode
30393832 return &instruction->base;
30403833}
30413834
3042static IrInstruction *ir_build_member_name(IrBuilder *irb, Scope *scope, AstNode *source_node,
3043 IrInstruction *container_type, IrInstruction *member_index)
3835static IrInstSrc *ir_build_member_name(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3836 IrInstSrc *container_type, IrInstSrc *member_index)
30443837{
3045 IrInstructionMemberName *instruction = ir_build_instruction<IrInstructionMemberName>(irb, scope, source_node);
3838 IrInstSrcMemberName *instruction = ir_build_instruction<IrInstSrcMemberName>(irb, scope, source_node);
30463839 instruction->container_type = container_type;
30473840 instruction->member_index = member_index;
30483841
......@@ -3052,65 +3845,88 @@ static IrInstruction *ir_build_member_name(IrBuilder *irb, Scope *scope, AstNode
30523845 return &instruction->base;
30533846}
30543847
3055static IrInstruction *ir_build_breakpoint(IrBuilder *irb, Scope *scope, AstNode *source_node) {
3056 IrInstructionBreakpoint *instruction = ir_build_instruction<IrInstructionBreakpoint>(irb, scope, source_node);
3848static IrInstSrc *ir_build_breakpoint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
3849 IrInstSrcBreakpoint *instruction = ir_build_instruction<IrInstSrcBreakpoint>(irb, scope, source_node);
30573850 return &instruction->base;
30583851}
30593852
3060static IrInstruction *ir_build_return_address(IrBuilder *irb, Scope *scope, AstNode *source_node) {
3061 IrInstructionReturnAddress *instruction = ir_build_instruction<IrInstructionReturnAddress>(irb, scope, source_node);
3853static IrInstGen *ir_build_breakpoint_gen(IrAnalyze *ira, IrInst *source_instr) {
3854 IrInstGenBreakpoint *instruction = ir_build_inst_void<IrInstGenBreakpoint>(&ira->new_irb,
3855 source_instr->scope, source_instr->source_node);
30623856 return &instruction->base;
30633857}
30643858
3065static IrInstruction *ir_build_frame_address(IrBuilder *irb, Scope *scope, AstNode *source_node) {
3066 IrInstructionFrameAddress *instruction = ir_build_instruction<IrInstructionFrameAddress>(irb, scope, source_node);
3859static IrInstSrc *ir_build_return_address_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
3860 IrInstSrcReturnAddress *instruction = ir_build_instruction<IrInstSrcReturnAddress>(irb, scope, source_node);
30673861 return &instruction->base;
30683862}
30693863
3070static IrInstruction *ir_build_handle(IrBuilder *irb, Scope *scope, AstNode *source_node) {
3071 IrInstructionFrameHandle *instruction = ir_build_instruction<IrInstructionFrameHandle>(irb, scope, source_node);
3072 return &instruction->base;
3864static IrInstGen *ir_build_return_address_gen(IrAnalyze *ira, IrInst *source_instr) {
3865 IrInstGenReturnAddress *inst = ir_build_inst_gen<IrInstGenReturnAddress>(&ira->new_irb, source_instr->scope, source_instr->source_node);
3866 inst->base.value->type = ira->codegen->builtin_types.entry_usize;
3867 return &inst->base;
3868}
3869
3870static IrInstSrc *ir_build_frame_address_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
3871 IrInstSrcFrameAddress *inst = ir_build_instruction<IrInstSrcFrameAddress>(irb, scope, source_node);
3872 return &inst->base;
3873}
3874
3875static IrInstGen *ir_build_frame_address_gen(IrAnalyze *ira, IrInst *source_instr) {
3876 IrInstGenFrameAddress *inst = ir_build_inst_gen<IrInstGenFrameAddress>(&ira->new_irb, source_instr->scope, source_instr->source_node);
3877 inst->base.value->type = ira->codegen->builtin_types.entry_usize;
3878 return &inst->base;
3879}
3880
3881static IrInstSrc *ir_build_handle_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
3882 IrInstSrcFrameHandle *inst = ir_build_instruction<IrInstSrcFrameHandle>(irb, scope, source_node);
3883 return &inst->base;
3884}
3885
3886static IrInstGen *ir_build_handle_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *ty) {
3887 IrInstGenFrameHandle *inst = ir_build_inst_gen<IrInstGenFrameHandle>(&ira->new_irb, source_instr->scope, source_instr->source_node);
3888 inst->base.value->type = ty;
3889 return &inst->base;
30733890}
30743891
3075static IrInstruction *ir_build_frame_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *fn) {
3076 IrInstructionFrameType *instruction = ir_build_instruction<IrInstructionFrameType>(irb, scope, source_node);
3077 instruction->fn = fn;
3892static IrInstSrc *ir_build_frame_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *fn) {
3893 IrInstSrcFrameType *inst = ir_build_instruction<IrInstSrcFrameType>(irb, scope, source_node);
3894 inst->fn = fn;
30783895
30793896 ir_ref_instruction(fn, irb->current_basic_block);
30803897
3081 return &instruction->base;
3898 return &inst->base;
30823899}
30833900
3084static IrInstruction *ir_build_frame_size_src(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *fn) {
3085 IrInstructionFrameSizeSrc *instruction = ir_build_instruction<IrInstructionFrameSizeSrc>(irb, scope, source_node);
3086 instruction->fn = fn;
3901static IrInstSrc *ir_build_frame_size_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *fn) {
3902 IrInstSrcFrameSize *inst = ir_build_instruction<IrInstSrcFrameSize>(irb, scope, source_node);
3903 inst->fn = fn;
30873904
30883905 ir_ref_instruction(fn, irb->current_basic_block);
30893906
3090 return &instruction->base;
3907 return &inst->base;
30913908}
30923909
3093static IrInstruction *ir_build_frame_size_gen(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *fn)
3910static IrInstGen *ir_build_frame_size_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *fn)
30943911{
3095 IrInstructionFrameSizeGen *instruction = ir_build_instruction<IrInstructionFrameSizeGen>(irb, scope, source_node);
3096 instruction->fn = fn;
3912 IrInstGenFrameSize *inst = ir_build_inst_gen<IrInstGenFrameSize>(&ira->new_irb, source_instr->scope, source_instr->source_node);
3913 inst->base.value->type = ira->codegen->builtin_types.entry_usize;
3914 inst->fn = fn;
30973915
3098 ir_ref_instruction(fn, irb->current_basic_block);
3916 ir_ref_inst_gen(fn, ira->new_irb.current_basic_block);
30993917
3100 return &instruction->base;
3918 return &inst->base;
31013919}
31023920
3103static IrInstruction *ir_build_overflow_op(IrBuilder *irb, Scope *scope, AstNode *source_node,
3104 IrOverflowOp op, IrInstruction *type_value, IrInstruction *op1, IrInstruction *op2,
3105 IrInstruction *result_ptr, ZigType *result_ptr_type)
3921static IrInstSrc *ir_build_overflow_op_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3922 IrOverflowOp op, IrInstSrc *type_value, IrInstSrc *op1, IrInstSrc *op2, IrInstSrc *result_ptr)
31063923{
3107 IrInstructionOverflowOp *instruction = ir_build_instruction<IrInstructionOverflowOp>(irb, scope, source_node);
3924 IrInstSrcOverflowOp *instruction = ir_build_instruction<IrInstSrcOverflowOp>(irb, scope, source_node);
31083925 instruction->op = op;
31093926 instruction->type_value = type_value;
31103927 instruction->op1 = op1;
31113928 instruction->op2 = op2;
31123929 instruction->result_ptr = result_ptr;
3113 instruction->result_ptr_type = result_ptr_type;
31143930
31153931 ir_ref_instruction(type_value, irb->current_basic_block);
31163932 ir_ref_instruction(op1, irb->current_basic_block);
......@@ -3120,49 +3936,30 @@ static IrInstruction *ir_build_overflow_op(IrBuilder *irb, Scope *scope, AstNode
31203936 return &instruction->base;
31213937}
31223938
3939static IrInstGen *ir_build_overflow_op_gen(IrAnalyze *ira, IrInst *source_instr,
3940 IrOverflowOp op, IrInstGen *op1, IrInstGen *op2, IrInstGen *result_ptr,
3941 ZigType *result_ptr_type)
3942{
3943 IrInstGenOverflowOp *instruction = ir_build_inst_gen<IrInstGenOverflowOp>(&ira->new_irb,
3944 source_instr->scope, source_instr->source_node);
3945 instruction->base.value->type = ira->codegen->builtin_types.entry_bool;
3946 instruction->op = op;
3947 instruction->op1 = op1;
3948 instruction->op2 = op2;
3949 instruction->result_ptr = result_ptr;
3950 instruction->result_ptr_type = result_ptr_type;
31233951
3124//TODO Powi, Pow, minnum, maxnum, maximum, minimum, copysign,
3125// lround, llround, lrint, llrint
3126// So far this is only non-complicated type functions.
3127const char *float_op_to_name(BuiltinFnId op) {
3128 switch (op) {
3129 case BuiltinFnIdSqrt:
3130 return "sqrt";
3131 case BuiltinFnIdSin:
3132 return "sin";
3133 case BuiltinFnIdCos:
3134 return "cos";
3135 case BuiltinFnIdExp:
3136 return "exp";
3137 case BuiltinFnIdExp2:
3138 return "exp2";
3139 case BuiltinFnIdLog:
3140 return "log";
3141 case BuiltinFnIdLog10:
3142 return "log10";
3143 case BuiltinFnIdLog2:
3144 return "log2";
3145 case BuiltinFnIdFabs:
3146 return "fabs";
3147 case BuiltinFnIdFloor:
3148 return "floor";
3149 case BuiltinFnIdCeil:
3150 return "ceil";
3151 case BuiltinFnIdTrunc:
3152 return "trunc";
3153 case BuiltinFnIdNearbyInt:
3154 return "nearbyint";
3155 case BuiltinFnIdRound:
3156 return "round";
3157 default:
3158 zig_unreachable();
3159 }
3952 ir_ref_inst_gen(op1, ira->new_irb.current_basic_block);
3953 ir_ref_inst_gen(op2, ira->new_irb.current_basic_block);
3954 ir_ref_inst_gen(result_ptr, ira->new_irb.current_basic_block);
3955
3956 return &instruction->base;
31603957}
31613958
3162static IrInstruction *ir_build_float_op(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *operand,
3959static IrInstSrc *ir_build_float_op_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *operand,
31633960 BuiltinFnId fn_id)
31643961{
3165 IrInstructionFloatOp *instruction = ir_build_instruction<IrInstructionFloatOp>(irb, scope, source_node);
3962 IrInstSrcFloatOp *instruction = ir_build_instruction<IrInstSrcFloatOp>(irb, scope, source_node);
31663963 instruction->operand = operand;
31673964 instruction->fn_id = fn_id;
31683965
......@@ -3171,9 +3968,24 @@ static IrInstruction *ir_build_float_op(IrBuilder *irb, Scope *scope, AstNode *s
31713968 return &instruction->base;
31723969}
31733970
3174static IrInstruction *ir_build_mul_add(IrBuilder *irb, Scope *scope, AstNode *source_node,
3175 IrInstruction *type_value, IrInstruction *op1, IrInstruction *op2, IrInstruction *op3) {
3176 IrInstructionMulAdd *instruction = ir_build_instruction<IrInstructionMulAdd>(irb, scope, source_node);
3971static IrInstGen *ir_build_float_op_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand,
3972 BuiltinFnId fn_id, ZigType *operand_type)
3973{
3974 IrInstGenFloatOp *instruction = ir_build_inst_gen<IrInstGenFloatOp>(&ira->new_irb,
3975 source_instr->scope, source_instr->source_node);
3976 instruction->base.value->type = operand_type;
3977 instruction->operand = operand;
3978 instruction->fn_id = fn_id;
3979
3980 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
3981
3982 return &instruction->base;
3983}
3984
3985static IrInstSrc *ir_build_mul_add_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3986 IrInstSrc *type_value, IrInstSrc *op1, IrInstSrc *op2, IrInstSrc *op3)
3987{
3988 IrInstSrcMulAdd *instruction = ir_build_instruction<IrInstSrcMulAdd>(irb, scope, source_node);
31773989 instruction->type_value = type_value;
31783990 instruction->op1 = op1;
31793991 instruction->op2 = op2;
......@@ -3187,8 +3999,25 @@ static IrInstruction *ir_build_mul_add(IrBuilder *irb, Scope *scope, AstNode *so
31873999 return &instruction->base;
31884000}
31894001
3190static IrInstruction *ir_build_align_of(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type_value) {
3191 IrInstructionAlignOf *instruction = ir_build_instruction<IrInstructionAlignOf>(irb, scope, source_node);
4002static IrInstGen *ir_build_mul_add_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *op1, IrInstGen *op2,
4003 IrInstGen *op3, ZigType *expr_type)
4004{
4005 IrInstGenMulAdd *instruction = ir_build_inst_gen<IrInstGenMulAdd>(&ira->new_irb,
4006 source_instr->scope, source_instr->source_node);
4007 instruction->base.value->type = expr_type;
4008 instruction->op1 = op1;
4009 instruction->op2 = op2;
4010 instruction->op3 = op3;
4011
4012 ir_ref_inst_gen(op1, ira->new_irb.current_basic_block);
4013 ir_ref_inst_gen(op2, ira->new_irb.current_basic_block);
4014 ir_ref_inst_gen(op3, ira->new_irb.current_basic_block);
4015
4016 return &instruction->base;
4017}
4018
4019static IrInstSrc *ir_build_align_of(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_value) {
4020 IrInstSrcAlignOf *instruction = ir_build_instruction<IrInstSrcAlignOf>(irb, scope, source_node);
31924021 instruction->type_value = type_value;
31934022
31944023 ir_ref_instruction(type_value, irb->current_basic_block);
......@@ -3196,10 +4025,10 @@ static IrInstruction *ir_build_align_of(IrBuilder *irb, Scope *scope, AstNode *s
31964025 return &instruction->base;
31974026}
31984027
3199static IrInstruction *ir_build_test_err_src(IrBuilder *irb, Scope *scope, AstNode *source_node,
3200 IrInstruction *base_ptr, bool resolve_err_set, bool base_ptr_is_payload)
4028static IrInstSrc *ir_build_test_err_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4029 IrInstSrc *base_ptr, bool resolve_err_set, bool base_ptr_is_payload)
32014030{
3202 IrInstructionTestErrSrc *instruction = ir_build_instruction<IrInstructionTestErrSrc>(irb, scope, source_node);
4031 IrInstSrcTestErr *instruction = ir_build_instruction<IrInstSrcTestErr>(irb, scope, source_node);
32034032 instruction->base_ptr = base_ptr;
32044033 instruction->resolve_err_set = resolve_err_set;
32054034 instruction->base_ptr_is_payload = base_ptr_is_payload;
......@@ -3209,48 +4038,72 @@ static IrInstruction *ir_build_test_err_src(IrBuilder *irb, Scope *scope, AstNod
32094038 return &instruction->base;
32104039}
32114040
3212static IrInstruction *ir_build_test_err_gen(IrAnalyze *ira, IrInstruction *source_instruction,
3213 IrInstruction *err_union)
3214{
3215 IrInstructionTestErrGen *instruction = ir_build_instruction<IrInstructionTestErrGen>(
4041static IrInstGen *ir_build_test_err_gen(IrAnalyze *ira, IrInst *source_instruction, IrInstGen *err_union) {
4042 IrInstGenTestErr *instruction = ir_build_inst_gen<IrInstGenTestErr>(
32164043 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
32174044 instruction->base.value->type = ira->codegen->builtin_types.entry_bool;
32184045 instruction->err_union = err_union;
32194046
3220 ir_ref_instruction(err_union, ira->new_irb.current_basic_block);
4047 ir_ref_inst_gen(err_union, ira->new_irb.current_basic_block);
32214048
32224049 return &instruction->base;
32234050}
32244051
3225static IrInstruction *ir_build_unwrap_err_code(IrBuilder *irb, Scope *scope, AstNode *source_node,
3226 IrInstruction *err_union_ptr)
4052static IrInstSrc *ir_build_unwrap_err_code_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4053 IrInstSrc *err_union_ptr)
32274054{
3228 IrInstructionUnwrapErrCode *instruction = ir_build_instruction<IrInstructionUnwrapErrCode>(irb, scope, source_node);
3229 instruction->err_union_ptr = err_union_ptr;
4055 IrInstSrcUnwrapErrCode *inst = ir_build_instruction<IrInstSrcUnwrapErrCode>(irb, scope, source_node);
4056 inst->err_union_ptr = err_union_ptr;
32304057
32314058 ir_ref_instruction(err_union_ptr, irb->current_basic_block);
32324059
3233 return &instruction->base;
4060 return &inst->base;
32344061}
32354062
3236static IrInstruction *ir_build_unwrap_err_payload(IrBuilder *irb, Scope *scope, AstNode *source_node,
3237 IrInstruction *value, bool safety_check_on, bool initializing)
4063static IrInstGen *ir_build_unwrap_err_code_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
4064 IrInstGen *err_union_ptr, ZigType *result_type)
32384065{
3239 IrInstructionUnwrapErrPayload *instruction = ir_build_instruction<IrInstructionUnwrapErrPayload>(irb, scope, source_node);
3240 instruction->value = value;
3241 instruction->safety_check_on = safety_check_on;
3242 instruction->initializing = initializing;
4066 IrInstGenUnwrapErrCode *inst = ir_build_inst_gen<IrInstGenUnwrapErrCode>(&ira->new_irb, scope, source_node);
4067 inst->base.value->type = result_type;
4068 inst->err_union_ptr = err_union_ptr;
4069
4070 ir_ref_inst_gen(err_union_ptr, ira->new_irb.current_basic_block);
4071
4072 return &inst->base;
4073}
4074
4075static IrInstSrc *ir_build_unwrap_err_payload_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4076 IrInstSrc *value, bool safety_check_on, bool initializing)
4077{
4078 IrInstSrcUnwrapErrPayload *inst = ir_build_instruction<IrInstSrcUnwrapErrPayload>(irb, scope, source_node);
4079 inst->value = value;
4080 inst->safety_check_on = safety_check_on;
4081 inst->initializing = initializing;
32434082
32444083 ir_ref_instruction(value, irb->current_basic_block);
32454084
3246 return &instruction->base;
4085 return &inst->base;
4086}
4087
4088static IrInstGen *ir_build_unwrap_err_payload_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
4089 IrInstGen *value, bool safety_check_on, bool initializing, ZigType *result_type)
4090{
4091 IrInstGenUnwrapErrPayload *inst = ir_build_inst_gen<IrInstGenUnwrapErrPayload>(&ira->new_irb, scope, source_node);
4092 inst->base.value->type = result_type;
4093 inst->value = value;
4094 inst->safety_check_on = safety_check_on;
4095 inst->initializing = initializing;
4096
4097 ir_ref_inst_gen(value, ira->new_irb.current_basic_block);
4098
4099 return &inst->base;
32474100}
32484101
3249static IrInstruction *ir_build_fn_proto(IrBuilder *irb, Scope *scope, AstNode *source_node,
3250 IrInstruction **param_types, IrInstruction *align_value, IrInstruction *callconv_value,
3251 IrInstruction *return_type, bool is_var_args)
4102static IrInstSrc *ir_build_fn_proto(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4103 IrInstSrc **param_types, IrInstSrc *align_value, IrInstSrc *callconv_value,
4104 IrInstSrc *return_type, bool is_var_args)
32524105{
3253 IrInstructionFnProto *instruction = ir_build_instruction<IrInstructionFnProto>(irb, scope, source_node);
4106 IrInstSrcFnProto *instruction = ir_build_instruction<IrInstSrcFnProto>(irb, scope, source_node);
32544107 instruction->param_types = param_types;
32554108 instruction->align_value = align_value;
32564109 instruction->callconv_value = callconv_value;
......@@ -3270,8 +4123,8 @@ static IrInstruction *ir_build_fn_proto(IrBuilder *irb, Scope *scope, AstNode *s
32704123 return &instruction->base;
32714124}
32724125
3273static IrInstruction *ir_build_test_comptime(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) {
3274 IrInstructionTestComptime *instruction = ir_build_instruction<IrInstructionTestComptime>(irb, scope, source_node);
4126static IrInstSrc *ir_build_test_comptime(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value) {
4127 IrInstSrcTestComptime *instruction = ir_build_instruction<IrInstSrcTestComptime>(irb, scope, source_node);
32754128 instruction->value = value;
32764129
32774130 ir_ref_instruction(value, irb->current_basic_block);
......@@ -3279,10 +4132,10 @@ static IrInstruction *ir_build_test_comptime(IrBuilder *irb, Scope *scope, AstNo
32794132 return &instruction->base;
32804133}
32814134
3282static IrInstruction *ir_build_ptr_cast_src(IrBuilder *irb, Scope *scope, AstNode *source_node,
3283 IrInstruction *dest_type, IrInstruction *ptr, bool safety_check_on)
4135static IrInstSrc *ir_build_ptr_cast_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4136 IrInstSrc *dest_type, IrInstSrc *ptr, bool safety_check_on)
32844137{
3285 IrInstructionPtrCastSrc *instruction = ir_build_instruction<IrInstructionPtrCastSrc>(
4138 IrInstSrcPtrCast *instruction = ir_build_instruction<IrInstSrcPtrCast>(
32864139 irb, scope, source_node);
32874140 instruction->dest_type = dest_type;
32884141 instruction->ptr = ptr;
......@@ -3294,39 +4147,24 @@ static IrInstruction *ir_build_ptr_cast_src(IrBuilder *irb, Scope *scope, AstNod
32944147 return &instruction->base;
32954148}
32964149
3297static IrInstruction *ir_build_ptr_cast_gen(IrAnalyze *ira, IrInstruction *source_instruction,
3298 ZigType *ptr_type, IrInstruction *ptr, bool safety_check_on)
4150static IrInstGen *ir_build_ptr_cast_gen(IrAnalyze *ira, IrInst *source_instruction,
4151 ZigType *ptr_type, IrInstGen *ptr, bool safety_check_on)
32994152{
3300 IrInstructionPtrCastGen *instruction = ir_build_instruction<IrInstructionPtrCastGen>(
4153 IrInstGenPtrCast *instruction = ir_build_inst_gen<IrInstGenPtrCast>(
33014154 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
33024155 instruction->base.value->type = ptr_type;
33034156 instruction->ptr = ptr;
33044157 instruction->safety_check_on = safety_check_on;
33054158
3306 ir_ref_instruction(ptr, ira->new_irb.current_basic_block);
4159 ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block);
33074160
33084161 return &instruction->base;
33094162}
33104163
3311static IrInstruction *ir_build_load_ptr_gen(IrAnalyze *ira, IrInstruction *source_instruction,
3312 IrInstruction *ptr, ZigType *ty, IrInstruction *result_loc)
4164static IrInstSrc *ir_build_implicit_cast(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4165 IrInstSrc *operand, ResultLocCast *result_loc_cast)
33134166{
3314 IrInstructionLoadPtrGen *instruction = ir_build_instruction<IrInstructionLoadPtrGen>(
3315 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
3316 instruction->base.value->type = ty;
3317 instruction->ptr = ptr;
3318 instruction->result_loc = result_loc;
3319
3320 ir_ref_instruction(ptr, ira->new_irb.current_basic_block);
3321 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);
3322
3323 return &instruction->base;
3324}
3325
3326static IrInstruction *ir_build_implicit_cast(IrBuilder *irb, Scope *scope, AstNode *source_node,
3327 IrInstruction *operand, ResultLocCast *result_loc_cast)
3328{
3329 IrInstructionImplicitCast *instruction = ir_build_instruction<IrInstructionImplicitCast>(irb, scope, source_node);
4167 IrInstSrcImplicitCast *instruction = ir_build_instruction<IrInstSrcImplicitCast>(irb, scope, source_node);
33304168 instruction->operand = operand;
33314169 instruction->result_loc_cast = result_loc_cast;
33324170
......@@ -3335,10 +4173,10 @@ static IrInstruction *ir_build_implicit_cast(IrBuilder *irb, Scope *scope, AstNo
33354173 return &instruction->base;
33364174}
33374175
3338static IrInstruction *ir_build_bit_cast_src(IrBuilder *irb, Scope *scope, AstNode *source_node,
3339 IrInstruction *operand, ResultLocBitCast *result_loc_bit_cast)
4176static IrInstSrc *ir_build_bit_cast_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4177 IrInstSrc *operand, ResultLocBitCast *result_loc_bit_cast)
33404178{
3341 IrInstructionBitCastSrc *instruction = ir_build_instruction<IrInstructionBitCastSrc>(irb, scope, source_node);
4179 IrInstSrcBitCast *instruction = ir_build_instruction<IrInstSrcBitCast>(irb, scope, source_node);
33424180 instruction->operand = operand;
33434181 instruction->result_loc_bit_cast = result_loc_bit_cast;
33444182
......@@ -3347,62 +4185,81 @@ static IrInstruction *ir_build_bit_cast_src(IrBuilder *irb, Scope *scope, AstNod
33474185 return &instruction->base;
33484186}
33494187
3350static IrInstruction *ir_build_bit_cast_gen(IrAnalyze *ira, IrInstruction *source_instruction,
3351 IrInstruction *operand, ZigType *ty)
4188static IrInstGen *ir_build_bit_cast_gen(IrAnalyze *ira, IrInst *source_instruction,
4189 IrInstGen *operand, ZigType *ty)
33524190{
3353 IrInstructionBitCastGen *instruction = ir_build_instruction<IrInstructionBitCastGen>(
4191 IrInstGenBitCast *instruction = ir_build_inst_gen<IrInstGenBitCast>(
33544192 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
33554193 instruction->base.value->type = ty;
33564194 instruction->operand = operand;
33574195
3358 ir_ref_instruction(operand, ira->new_irb.current_basic_block);
4196 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
33594197
33604198 return &instruction->base;
33614199}
33624200
3363static IrInstruction *ir_build_widen_or_shorten(IrBuilder *irb, Scope *scope, AstNode *source_node,
3364 IrInstruction *target)
4201static IrInstGen *ir_build_widen_or_shorten(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target,
4202 ZigType *result_type)
33654203{
3366 IrInstructionWidenOrShorten *instruction = ir_build_instruction<IrInstructionWidenOrShorten>(
3367 irb, scope, source_node);
3368 instruction->target = target;
4204 IrInstGenWidenOrShorten *inst = ir_build_inst_gen<IrInstGenWidenOrShorten>(&ira->new_irb, scope, source_node);
4205 inst->base.value->type = result_type;
4206 inst->target = target;
33694207
3370 ir_ref_instruction(target, irb->current_basic_block);
4208 ir_ref_inst_gen(target, ira->new_irb.current_basic_block);
33714209
3372 return &instruction->base;
4210 return &inst->base;
33734211}
33744212
3375static IrInstruction *ir_build_int_to_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,
3376 IrInstruction *dest_type, IrInstruction *target)
4213static IrInstSrc *ir_build_int_to_ptr_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4214 IrInstSrc *dest_type, IrInstSrc *target)
33774215{
3378 IrInstructionIntToPtr *instruction = ir_build_instruction<IrInstructionIntToPtr>(
3379 irb, scope, source_node);
4216 IrInstSrcIntToPtr *instruction = ir_build_instruction<IrInstSrcIntToPtr>(irb, scope, source_node);
33804217 instruction->dest_type = dest_type;
33814218 instruction->target = target;
33824219
3383 if (dest_type) ir_ref_instruction(dest_type, irb->current_basic_block);
4220 ir_ref_instruction(dest_type, irb->current_basic_block);
33844221 ir_ref_instruction(target, irb->current_basic_block);
33854222
33864223 return &instruction->base;
33874224}
33884225
3389static IrInstruction *ir_build_ptr_to_int(IrBuilder *irb, Scope *scope, AstNode *source_node,
3390 IrInstruction *target)
4226static IrInstGen *ir_build_int_to_ptr_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
4227 IrInstGen *target, ZigType *ptr_type)
33914228{
3392 IrInstructionPtrToInt *instruction = ir_build_instruction<IrInstructionPtrToInt>(
3393 irb, scope, source_node);
4229 IrInstGenIntToPtr *instruction = ir_build_inst_gen<IrInstGenIntToPtr>(&ira->new_irb, scope, source_node);
4230 instruction->base.value->type = ptr_type;
33944231 instruction->target = target;
33954232
3396 ir_ref_instruction(target, irb->current_basic_block);
4233 ir_ref_inst_gen(target, ira->new_irb.current_basic_block);
33974234
33984235 return &instruction->base;
33994236}
34004237
3401static IrInstruction *ir_build_int_to_enum(IrBuilder *irb, Scope *scope, AstNode *source_node,
3402 IrInstruction *dest_type, IrInstruction *target)
4238static IrInstSrc *ir_build_ptr_to_int_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4239 IrInstSrc *target)
34034240{
3404 IrInstructionIntToEnum *instruction = ir_build_instruction<IrInstructionIntToEnum>(
3405 irb, scope, source_node);
4241 IrInstSrcPtrToInt *inst = ir_build_instruction<IrInstSrcPtrToInt>(irb, scope, source_node);
4242 inst->target = target;
4243
4244 ir_ref_instruction(target, irb->current_basic_block);
4245
4246 return &inst->base;
4247}
4248
4249static IrInstGen *ir_build_ptr_to_int_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *target) {
4250 IrInstGenPtrToInt *inst = ir_build_inst_gen<IrInstGenPtrToInt>(&ira->new_irb, source_instr->scope, source_instr->source_node);
4251 inst->base.value->type = ira->codegen->builtin_types.entry_usize;
4252 inst->target = target;
4253
4254 ir_ref_inst_gen(target, ira->new_irb.current_basic_block);
4255
4256 return &inst->base;
4257}
4258
4259static IrInstSrc *ir_build_int_to_enum_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4260 IrInstSrc *dest_type, IrInstSrc *target)
4261{
4262 IrInstSrcIntToEnum *instruction = ir_build_instruction<IrInstSrcIntToEnum>(irb, scope, source_node);
34064263 instruction->dest_type = dest_type;
34074264 instruction->target = target;
34084265
......@@ -3412,12 +4269,22 @@ static IrInstruction *ir_build_int_to_enum(IrBuilder *irb, Scope *scope, AstNode
34124269 return &instruction->base;
34134270}
34144271
4272static IrInstGen *ir_build_int_to_enum_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
4273 ZigType *dest_type, IrInstGen *target)
4274{
4275 IrInstGenIntToEnum *instruction = ir_build_inst_gen<IrInstGenIntToEnum>(&ira->new_irb, scope, source_node);
4276 instruction->base.value->type = dest_type;
4277 instruction->target = target;
4278
4279 ir_ref_inst_gen(target, ira->new_irb.current_basic_block);
34154280
4281 return &instruction->base;
4282}
34164283
3417static IrInstruction *ir_build_enum_to_int(IrBuilder *irb, Scope *scope, AstNode *source_node,
3418 IrInstruction *target)
4284static IrInstSrc *ir_build_enum_to_int(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4285 IrInstSrc *target)
34194286{
3420 IrInstructionEnumToInt *instruction = ir_build_instruction<IrInstructionEnumToInt>(
4287 IrInstSrcEnumToInt *instruction = ir_build_instruction<IrInstSrcEnumToInt>(
34214288 irb, scope, source_node);
34224289 instruction->target = target;
34234290
......@@ -3426,11 +4293,10 @@ static IrInstruction *ir_build_enum_to_int(IrBuilder *irb, Scope *scope, AstNode
34264293 return &instruction->base;
34274294}
34284295
3429static IrInstruction *ir_build_int_to_err(IrBuilder *irb, Scope *scope, AstNode *source_node,
3430 IrInstruction *target)
4296static IrInstSrc *ir_build_int_to_err_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4297 IrInstSrc *target)
34314298{
3432 IrInstructionIntToErr *instruction = ir_build_instruction<IrInstructionIntToErr>(
3433 irb, scope, source_node);
4299 IrInstSrcIntToErr *instruction = ir_build_instruction<IrInstSrcIntToErr>(irb, scope, source_node);
34344300 instruction->target = target;
34354301
34364302 ir_ref_instruction(target, irb->current_basic_block);
......@@ -3438,10 +4304,22 @@ static IrInstruction *ir_build_int_to_err(IrBuilder *irb, Scope *scope, AstNode
34384304 return &instruction->base;
34394305}
34404306
3441static IrInstruction *ir_build_err_to_int(IrBuilder *irb, Scope *scope, AstNode *source_node,
3442 IrInstruction *target)
4307static IrInstGen *ir_build_int_to_err_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target,
4308 ZigType *wanted_type)
4309{
4310 IrInstGenIntToErr *instruction = ir_build_inst_gen<IrInstGenIntToErr>(&ira->new_irb, scope, source_node);
4311 instruction->base.value->type = wanted_type;
4312 instruction->target = target;
4313
4314 ir_ref_inst_gen(target, ira->new_irb.current_basic_block);
4315
4316 return &instruction->base;
4317}
4318
4319static IrInstSrc *ir_build_err_to_int_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4320 IrInstSrc *target)
34434321{
3444 IrInstructionErrToInt *instruction = ir_build_instruction<IrInstructionErrToInt>(
4322 IrInstSrcErrToInt *instruction = ir_build_instruction<IrInstSrcErrToInt>(
34454323 irb, scope, source_node);
34464324 instruction->target = target;
34474325
......@@ -3450,11 +4328,23 @@ static IrInstruction *ir_build_err_to_int(IrBuilder *irb, Scope *scope, AstNode
34504328 return &instruction->base;
34514329}
34524330
3453static IrInstruction *ir_build_check_switch_prongs(IrBuilder *irb, Scope *scope, AstNode *source_node,
3454 IrInstruction *target_value, IrInstructionCheckSwitchProngsRange *ranges, size_t range_count,
4331static IrInstGen *ir_build_err_to_int_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target,
4332 ZigType *wanted_type)
4333{
4334 IrInstGenErrToInt *instruction = ir_build_inst_gen<IrInstGenErrToInt>(&ira->new_irb, scope, source_node);
4335 instruction->base.value->type = wanted_type;
4336 instruction->target = target;
4337
4338 ir_ref_inst_gen(target, ira->new_irb.current_basic_block);
4339
4340 return &instruction->base;
4341}
4342
4343static IrInstSrc *ir_build_check_switch_prongs(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4344 IrInstSrc *target_value, IrInstSrcCheckSwitchProngsRange *ranges, size_t range_count,
34554345 bool have_else_prong, bool have_underscore_prong)
34564346{
3457 IrInstructionCheckSwitchProngs *instruction = ir_build_instruction<IrInstructionCheckSwitchProngs>(
4347 IrInstSrcCheckSwitchProngs *instruction = ir_build_instruction<IrInstSrcCheckSwitchProngs>(
34584348 irb, scope, source_node);
34594349 instruction->target_value = target_value;
34604350 instruction->ranges = ranges;
......@@ -3471,10 +4361,10 @@ static IrInstruction *ir_build_check_switch_prongs(IrBuilder *irb, Scope *scope,
34714361 return &instruction->base;
34724362}
34734363
3474static IrInstruction *ir_build_check_statement_is_void(IrBuilder *irb, Scope *scope, AstNode *source_node,
3475 IrInstruction* statement_value)
4364static IrInstSrc *ir_build_check_statement_is_void(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4365 IrInstSrc* statement_value)
34764366{
3477 IrInstructionCheckStatementIsVoid *instruction = ir_build_instruction<IrInstructionCheckStatementIsVoid>(
4367 IrInstSrcCheckStatementIsVoid *instruction = ir_build_instruction<IrInstSrcCheckStatementIsVoid>(
34784368 irb, scope, source_node);
34794369 instruction->statement_value = statement_value;
34804370
......@@ -3483,11 +4373,10 @@ static IrInstruction *ir_build_check_statement_is_void(IrBuilder *irb, Scope *sc
34834373 return &instruction->base;
34844374}
34854375
3486static IrInstruction *ir_build_type_name(IrBuilder *irb, Scope *scope, AstNode *source_node,
3487 IrInstruction *type_value)
4376static IrInstSrc *ir_build_type_name(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4377 IrInstSrc *type_value)
34884378{
3489 IrInstructionTypeName *instruction = ir_build_instruction<IrInstructionTypeName>(
3490 irb, scope, source_node);
4379 IrInstSrcTypeName *instruction = ir_build_instruction<IrInstSrcTypeName>(irb, scope, source_node);
34914380 instruction->type_value = type_value;
34924381
34934382 ir_ref_instruction(type_value, irb->current_basic_block);
......@@ -3495,40 +4384,60 @@ static IrInstruction *ir_build_type_name(IrBuilder *irb, Scope *scope, AstNode *
34954384 return &instruction->base;
34964385}
34974386
3498static IrInstruction *ir_build_decl_ref(IrBuilder *irb, Scope *scope, AstNode *source_node, Tld *tld, LVal lval) {
3499 IrInstructionDeclRef *instruction = ir_build_instruction<IrInstructionDeclRef>(irb, scope, source_node);
3500 instruction->tld = tld;
3501 instruction->lval = lval;
4387static IrInstSrc *ir_build_decl_ref(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Tld *tld, LVal lval) {
4388 IrInstSrcDeclRef *instruction = ir_build_instruction<IrInstSrcDeclRef>(irb, scope, source_node);
4389 instruction->tld = tld;
4390 instruction->lval = lval;
4391
4392 return &instruction->base;
4393}
4394
4395static IrInstSrc *ir_build_panic_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *msg) {
4396 IrInstSrcPanic *instruction = ir_build_instruction<IrInstSrcPanic>(irb, scope, source_node);
4397 instruction->base.is_noreturn = true;
4398 instruction->msg = msg;
4399
4400 ir_ref_instruction(msg, irb->current_basic_block);
4401
4402 return &instruction->base;
4403}
4404
4405static IrInstGen *ir_build_panic_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *msg) {
4406 IrInstGenPanic *instruction = ir_build_inst_noreturn<IrInstGenPanic>(&ira->new_irb,
4407 source_instr->scope, source_instr->source_node);
4408 instruction->msg = msg;
4409
4410 ir_ref_inst_gen(msg, ira->new_irb.current_basic_block);
35024411
35034412 return &instruction->base;
35044413}
35054414
3506static IrInstruction *ir_build_panic(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *msg) {
3507 IrInstructionPanic *instruction = ir_build_instruction<IrInstructionPanic>(irb, scope, source_node);
3508 instruction->base.value->special = ConstValSpecialStatic;
3509 instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;
3510 instruction->msg = msg;
4415static IrInstSrc *ir_build_tag_name_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *target) {
4416 IrInstSrcTagName *instruction = ir_build_instruction<IrInstSrcTagName>(irb, scope, source_node);
4417 instruction->target = target;
35114418
3512 ir_ref_instruction(msg, irb->current_basic_block);
4419 ir_ref_instruction(target, irb->current_basic_block);
35134420
35144421 return &instruction->base;
35154422}
35164423
3517static IrInstruction *ir_build_tag_name(IrBuilder *irb, Scope *scope, AstNode *source_node,
3518 IrInstruction *target)
4424static IrInstGen *ir_build_tag_name_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *target,
4425 ZigType *result_type)
35194426{
3520 IrInstructionTagName *instruction = ir_build_instruction<IrInstructionTagName>(irb, scope, source_node);
4427 IrInstGenTagName *instruction = ir_build_inst_gen<IrInstGenTagName>(&ira->new_irb,
4428 source_instr->scope, source_instr->source_node);
4429 instruction->base.value->type = result_type;
35214430 instruction->target = target;
35224431
3523 ir_ref_instruction(target, irb->current_basic_block);
4432 ir_ref_inst_gen(target, ira->new_irb.current_basic_block);
35244433
35254434 return &instruction->base;
35264435}
35274436
3528static IrInstruction *ir_build_tag_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
3529 IrInstruction *target)
4437static IrInstSrc *ir_build_tag_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4438 IrInstSrc *target)
35304439{
3531 IrInstructionTagType *instruction = ir_build_instruction<IrInstructionTagType>(irb, scope, source_node);
4440 IrInstSrcTagType *instruction = ir_build_instruction<IrInstSrcTagType>(irb, scope, source_node);
35324441 instruction->target = target;
35334442
35344443 ir_ref_instruction(target, irb->current_basic_block);
......@@ -3536,27 +4445,40 @@ static IrInstruction *ir_build_tag_type(IrBuilder *irb, Scope *scope, AstNode *s
35364445 return &instruction->base;
35374446}
35384447
3539static IrInstruction *ir_build_field_parent_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,
3540 IrInstruction *type_value, IrInstruction *field_name, IrInstruction *field_ptr, TypeStructField *field)
4448static IrInstSrc *ir_build_field_parent_ptr_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4449 IrInstSrc *type_value, IrInstSrc *field_name, IrInstSrc *field_ptr)
35414450{
3542 IrInstructionFieldParentPtr *instruction = ir_build_instruction<IrInstructionFieldParentPtr>(
4451 IrInstSrcFieldParentPtr *inst = ir_build_instruction<IrInstSrcFieldParentPtr>(
35434452 irb, scope, source_node);
3544 instruction->type_value = type_value;
3545 instruction->field_name = field_name;
3546 instruction->field_ptr = field_ptr;
3547 instruction->field = field;
4453 inst->type_value = type_value;
4454 inst->field_name = field_name;
4455 inst->field_ptr = field_ptr;
35484456
35494457 ir_ref_instruction(type_value, irb->current_basic_block);
35504458 ir_ref_instruction(field_name, irb->current_basic_block);
35514459 ir_ref_instruction(field_ptr, irb->current_basic_block);
35524460
3553 return &instruction->base;
4461 return &inst->base;
4462}
4463
4464static IrInstGen *ir_build_field_parent_ptr_gen(IrAnalyze *ira, IrInst *source_instr,
4465 IrInstGen *field_ptr, TypeStructField *field, ZigType *result_type)
4466{
4467 IrInstGenFieldParentPtr *inst = ir_build_inst_gen<IrInstGenFieldParentPtr>(&ira->new_irb,
4468 source_instr->scope, source_instr->source_node);
4469 inst->base.value->type = result_type;
4470 inst->field_ptr = field_ptr;
4471 inst->field = field;
4472
4473 ir_ref_inst_gen(field_ptr, ira->new_irb.current_basic_block);
4474
4475 return &inst->base;
35544476}
35554477
3556static IrInstruction *ir_build_byte_offset_of(IrBuilder *irb, Scope *scope, AstNode *source_node,
3557 IrInstruction *type_value, IrInstruction *field_name)
4478static IrInstSrc *ir_build_byte_offset_of(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4479 IrInstSrc *type_value, IrInstSrc *field_name)
35584480{
3559 IrInstructionByteOffsetOf *instruction = ir_build_instruction<IrInstructionByteOffsetOf>(irb, scope, source_node);
4481 IrInstSrcByteOffsetOf *instruction = ir_build_instruction<IrInstSrcByteOffsetOf>(irb, scope, source_node);
35604482 instruction->type_value = type_value;
35614483 instruction->field_name = field_name;
35624484
......@@ -3566,10 +4488,10 @@ static IrInstruction *ir_build_byte_offset_of(IrBuilder *irb, Scope *scope, AstN
35664488 return &instruction->base;
35674489}
35684490
3569static IrInstruction *ir_build_bit_offset_of(IrBuilder *irb, Scope *scope, AstNode *source_node,
3570 IrInstruction *type_value, IrInstruction *field_name)
4491static IrInstSrc *ir_build_bit_offset_of(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4492 IrInstSrc *type_value, IrInstSrc *field_name)
35714493{
3572 IrInstructionBitOffsetOf *instruction = ir_build_instruction<IrInstructionBitOffsetOf>(irb, scope, source_node);
4494 IrInstSrcBitOffsetOf *instruction = ir_build_instruction<IrInstSrcBitOffsetOf>(irb, scope, source_node);
35734495 instruction->type_value = type_value;
35744496 instruction->field_name = field_name;
35754497
......@@ -3579,9 +4501,8 @@ static IrInstruction *ir_build_bit_offset_of(IrBuilder *irb, Scope *scope, AstNo
35794501 return &instruction->base;
35804502}
35814503
3582static IrInstruction *ir_build_type_info(IrBuilder *irb, Scope *scope, AstNode *source_node,
3583 IrInstruction *type_value) {
3584 IrInstructionTypeInfo *instruction = ir_build_instruction<IrInstructionTypeInfo>(irb, scope, source_node);
4504static IrInstSrc *ir_build_type_info(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_value) {
4505 IrInstSrcTypeInfo *instruction = ir_build_instruction<IrInstSrcTypeInfo>(irb, scope, source_node);
35854506 instruction->type_value = type_value;
35864507
35874508 ir_ref_instruction(type_value, irb->current_basic_block);
......@@ -3589,8 +4510,8 @@ static IrInstruction *ir_build_type_info(IrBuilder *irb, Scope *scope, AstNode *
35894510 return &instruction->base;
35904511}
35914512
3592static IrInstruction *ir_build_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type_info) {
3593 IrInstructionType *instruction = ir_build_instruction<IrInstructionType>(irb, scope, source_node);
4513static IrInstSrc *ir_build_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_info) {
4514 IrInstSrcType *instruction = ir_build_instruction<IrInstSrcType>(irb, scope, source_node);
35944515 instruction->type_info = type_info;
35954516
35964517 ir_ref_instruction(type_info, irb->current_basic_block);
......@@ -3598,10 +4519,8 @@ static IrInstruction *ir_build_type(IrBuilder *irb, Scope *scope, AstNode *sourc
35984519 return &instruction->base;
35994520}
36004521
3601static IrInstruction *ir_build_type_id(IrBuilder *irb, Scope *scope, AstNode *source_node,
3602 IrInstruction *type_value)
3603{
3604 IrInstructionTypeId *instruction = ir_build_instruction<IrInstructionTypeId>(irb, scope, source_node);
4522static IrInstSrc *ir_build_type_id(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_value) {
4523 IrInstSrcTypeId *instruction = ir_build_instruction<IrInstSrcTypeId>(irb, scope, source_node);
36054524 instruction->type_value = type_value;
36064525
36074526 ir_ref_instruction(type_value, irb->current_basic_block);
......@@ -3609,10 +4528,10 @@ static IrInstruction *ir_build_type_id(IrBuilder *irb, Scope *scope, AstNode *so
36094528 return &instruction->base;
36104529}
36114530
3612static IrInstruction *ir_build_set_eval_branch_quota(IrBuilder *irb, Scope *scope, AstNode *source_node,
3613 IrInstruction *new_quota)
4531static IrInstSrc *ir_build_set_eval_branch_quota(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4532 IrInstSrc *new_quota)
36144533{
3615 IrInstructionSetEvalBranchQuota *instruction = ir_build_instruction<IrInstructionSetEvalBranchQuota>(irb, scope, source_node);
4534 IrInstSrcSetEvalBranchQuota *instruction = ir_build_instruction<IrInstSrcSetEvalBranchQuota>(irb, scope, source_node);
36164535 instruction->new_quota = new_quota;
36174536
36184537 ir_ref_instruction(new_quota, irb->current_basic_block);
......@@ -3620,23 +4539,35 @@ static IrInstruction *ir_build_set_eval_branch_quota(IrBuilder *irb, Scope *scop
36204539 return &instruction->base;
36214540}
36224541
3623static IrInstruction *ir_build_align_cast(IrBuilder *irb, Scope *scope, AstNode *source_node,
3624 IrInstruction *align_bytes, IrInstruction *target)
4542static IrInstSrc *ir_build_align_cast_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4543 IrInstSrc *align_bytes, IrInstSrc *target)
36254544{
3626 IrInstructionAlignCast *instruction = ir_build_instruction<IrInstructionAlignCast>(irb, scope, source_node);
4545 IrInstSrcAlignCast *instruction = ir_build_instruction<IrInstSrcAlignCast>(irb, scope, source_node);
36274546 instruction->align_bytes = align_bytes;
36284547 instruction->target = target;
36294548
3630 if (align_bytes) ir_ref_instruction(align_bytes, irb->current_basic_block);
4549 ir_ref_instruction(align_bytes, irb->current_basic_block);
36314550 ir_ref_instruction(target, irb->current_basic_block);
36324551
36334552 return &instruction->base;
36344553}
36354554
3636static IrInstruction *ir_build_resolve_result(IrBuilder *irb, Scope *scope, AstNode *source_node,
3637 ResultLoc *result_loc, IrInstruction *ty)
4555static IrInstGen *ir_build_align_cast_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target,
4556 ZigType *result_type)
4557{
4558 IrInstGenAlignCast *instruction = ir_build_inst_gen<IrInstGenAlignCast>(&ira->new_irb, scope, source_node);
4559 instruction->base.value->type = result_type;
4560 instruction->target = target;
4561
4562 ir_ref_inst_gen(target, ira->new_irb.current_basic_block);
4563
4564 return &instruction->base;
4565}
4566
4567static IrInstSrc *ir_build_resolve_result(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4568 ResultLoc *result_loc, IrInstSrc *ty)
36384569{
3639 IrInstructionResolveResult *instruction = ir_build_instruction<IrInstructionResolveResult>(irb, scope, source_node);
4570 IrInstSrcResolveResult *instruction = ir_build_instruction<IrInstSrcResolveResult>(irb, scope, source_node);
36404571 instruction->result_loc = result_loc;
36414572 instruction->ty = ty;
36424573
......@@ -3645,25 +4576,25 @@ static IrInstruction *ir_build_resolve_result(IrBuilder *irb, Scope *scope, AstN
36454576 return &instruction->base;
36464577}
36474578
3648static IrInstruction *ir_build_reset_result(IrBuilder *irb, Scope *scope, AstNode *source_node,
4579static IrInstSrc *ir_build_reset_result(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
36494580 ResultLoc *result_loc)
36504581{
3651 IrInstructionResetResult *instruction = ir_build_instruction<IrInstructionResetResult>(irb, scope, source_node);
4582 IrInstSrcResetResult *instruction = ir_build_instruction<IrInstSrcResetResult>(irb, scope, source_node);
36524583 instruction->result_loc = result_loc;
36534584
36544585 return &instruction->base;
36554586}
36564587
3657static IrInstruction *ir_build_opaque_type(IrBuilder *irb, Scope *scope, AstNode *source_node) {
3658 IrInstructionOpaqueType *instruction = ir_build_instruction<IrInstructionOpaqueType>(irb, scope, source_node);
4588static IrInstSrc *ir_build_opaque_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
4589 IrInstSrcOpaqueType *instruction = ir_build_instruction<IrInstSrcOpaqueType>(irb, scope, source_node);
36594590
36604591 return &instruction->base;
36614592}
36624593
3663static IrInstruction *ir_build_set_align_stack(IrBuilder *irb, Scope *scope, AstNode *source_node,
3664 IrInstruction *align_bytes)
4594static IrInstSrc *ir_build_set_align_stack(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4595 IrInstSrc *align_bytes)
36654596{
3666 IrInstructionSetAlignStack *instruction = ir_build_instruction<IrInstructionSetAlignStack>(irb, scope, source_node);
4597 IrInstSrcSetAlignStack *instruction = ir_build_instruction<IrInstSrcSetAlignStack>(irb, scope, source_node);
36674598 instruction->align_bytes = align_bytes;
36684599
36694600 ir_ref_instruction(align_bytes, irb->current_basic_block);
......@@ -3671,10 +4602,10 @@ static IrInstruction *ir_build_set_align_stack(IrBuilder *irb, Scope *scope, Ast
36714602 return &instruction->base;
36724603}
36734604
3674static IrInstruction *ir_build_arg_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
3675 IrInstruction *fn_type, IrInstruction *arg_index, bool allow_var)
4605static IrInstSrc *ir_build_arg_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4606 IrInstSrc *fn_type, IrInstSrc *arg_index, bool allow_var)
36764607{
3677 IrInstructionArgType *instruction = ir_build_instruction<IrInstructionArgType>(irb, scope, source_node);
4608 IrInstSrcArgType *instruction = ir_build_instruction<IrInstSrcArgType>(irb, scope, source_node);
36784609 instruction->fn_type = fn_type;
36794610 instruction->arg_index = arg_index;
36804611 instruction->allow_var = allow_var;
......@@ -3685,17 +4616,29 @@ static IrInstruction *ir_build_arg_type(IrBuilder *irb, Scope *scope, AstNode *s
36854616 return &instruction->base;
36864617}
36874618
3688static IrInstruction *ir_build_error_return_trace(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstructionErrorReturnTrace::Optional optional) {
3689 IrInstructionErrorReturnTrace *instruction = ir_build_instruction<IrInstructionErrorReturnTrace>(irb, scope, source_node);
3690 instruction->optional = optional;
4619static IrInstSrc *ir_build_error_return_trace_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4620 IrInstErrorReturnTraceOptional optional)
4621{
4622 IrInstSrcErrorReturnTrace *inst = ir_build_instruction<IrInstSrcErrorReturnTrace>(irb, scope, source_node);
4623 inst->optional = optional;
36914624
3692 return &instruction->base;
4625 return &inst->base;
4626}
4627
4628static IrInstGen *ir_build_error_return_trace_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
4629 IrInstErrorReturnTraceOptional optional, ZigType *result_type)
4630{
4631 IrInstGenErrorReturnTrace *inst = ir_build_inst_gen<IrInstGenErrorReturnTrace>(&ira->new_irb, scope, source_node);
4632 inst->base.value->type = result_type;
4633 inst->optional = optional;
4634
4635 return &inst->base;
36934636}
36944637
3695static IrInstruction *ir_build_error_union(IrBuilder *irb, Scope *scope, AstNode *source_node,
3696 IrInstruction *err_set, IrInstruction *payload)
4638static IrInstSrc *ir_build_error_union(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4639 IrInstSrc *err_set, IrInstSrc *payload)
36974640{
3698 IrInstructionErrorUnion *instruction = ir_build_instruction<IrInstructionErrorUnion>(irb, scope, source_node);
4641 IrInstSrcErrorUnion *instruction = ir_build_instruction<IrInstSrcErrorUnion>(irb, scope, source_node);
36994642 instruction->err_set = err_set;
37004643 instruction->payload = payload;
37014644
......@@ -3705,85 +4648,130 @@ static IrInstruction *ir_build_error_union(IrBuilder *irb, Scope *scope, AstNode
37054648 return &instruction->base;
37064649}
37074650
3708static IrInstruction *ir_build_atomic_rmw(IrBuilder *irb, Scope *scope, AstNode *source_node,
3709 IrInstruction *operand_type, IrInstruction *ptr, IrInstruction *op, IrInstruction *operand,
3710 IrInstruction *ordering, AtomicRmwOp resolved_op, AtomicOrder resolved_ordering)
4651static IrInstSrc *ir_build_atomic_rmw_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4652 IrInstSrc *operand_type, IrInstSrc *ptr, IrInstSrc *op, IrInstSrc *operand,
4653 IrInstSrc *ordering)
37114654{
3712 IrInstructionAtomicRmw *instruction = ir_build_instruction<IrInstructionAtomicRmw>(irb, scope, source_node);
4655 IrInstSrcAtomicRmw *instruction = ir_build_instruction<IrInstSrcAtomicRmw>(irb, scope, source_node);
37134656 instruction->operand_type = operand_type;
37144657 instruction->ptr = ptr;
37154658 instruction->op = op;
37164659 instruction->operand = operand;
37174660 instruction->ordering = ordering;
3718 instruction->resolved_op = resolved_op;
3719 instruction->resolved_ordering = resolved_ordering;
37204661
3721 if (operand_type != nullptr) ir_ref_instruction(operand_type, irb->current_basic_block);
4662 ir_ref_instruction(operand_type, irb->current_basic_block);
37224663 ir_ref_instruction(ptr, irb->current_basic_block);
3723 if (op != nullptr) ir_ref_instruction(op, irb->current_basic_block);
4664 ir_ref_instruction(op, irb->current_basic_block);
37244665 ir_ref_instruction(operand, irb->current_basic_block);
3725 if (ordering != nullptr) ir_ref_instruction(ordering, irb->current_basic_block);
4666 ir_ref_instruction(ordering, irb->current_basic_block);
4667
4668 return &instruction->base;
4669}
4670
4671static IrInstGen *ir_build_atomic_rmw_gen(IrAnalyze *ira, IrInst *source_instr,
4672 IrInstGen *ptr, IrInstGen *operand, AtomicRmwOp op, AtomicOrder ordering, ZigType *operand_type)
4673{
4674 IrInstGenAtomicRmw *instruction = ir_build_inst_gen<IrInstGenAtomicRmw>(&ira->new_irb, source_instr->scope, source_instr->source_node);
4675 instruction->base.value->type = operand_type;
4676 instruction->ptr = ptr;
4677 instruction->op = op;
4678 instruction->operand = operand;
4679 instruction->ordering = ordering;
4680
4681 ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block);
4682 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
37264683
37274684 return &instruction->base;
37284685}
37294686
3730static IrInstruction *ir_build_atomic_load(IrBuilder *irb, Scope *scope, AstNode *source_node,
3731 IrInstruction *operand_type, IrInstruction *ptr,
3732 IrInstruction *ordering, AtomicOrder resolved_ordering)
4687static IrInstSrc *ir_build_atomic_load_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4688 IrInstSrc *operand_type, IrInstSrc *ptr, IrInstSrc *ordering)
37334689{
3734 IrInstructionAtomicLoad *instruction = ir_build_instruction<IrInstructionAtomicLoad>(irb, scope, source_node);
4690 IrInstSrcAtomicLoad *instruction = ir_build_instruction<IrInstSrcAtomicLoad>(irb, scope, source_node);
37354691 instruction->operand_type = operand_type;
37364692 instruction->ptr = ptr;
37374693 instruction->ordering = ordering;
3738 instruction->resolved_ordering = resolved_ordering;
37394694
3740 if (operand_type != nullptr) ir_ref_instruction(operand_type, irb->current_basic_block);
4695 ir_ref_instruction(operand_type, irb->current_basic_block);
37414696 ir_ref_instruction(ptr, irb->current_basic_block);
3742 if (ordering != nullptr) ir_ref_instruction(ordering, irb->current_basic_block);
4697 ir_ref_instruction(ordering, irb->current_basic_block);
4698
4699 return &instruction->base;
4700}
4701
4702static IrInstGen *ir_build_atomic_load_gen(IrAnalyze *ira, IrInst *source_instr,
4703 IrInstGen *ptr, AtomicOrder ordering, ZigType *operand_type)
4704{
4705 IrInstGenAtomicLoad *instruction = ir_build_inst_gen<IrInstGenAtomicLoad>(&ira->new_irb,
4706 source_instr->scope, source_instr->source_node);
4707 instruction->base.value->type = operand_type;
4708 instruction->ptr = ptr;
4709 instruction->ordering = ordering;
4710
4711 ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block);
37434712
37444713 return &instruction->base;
37454714}
37464715
3747static IrInstruction *ir_build_atomic_store(IrBuilder *irb, Scope *scope, AstNode *source_node,
3748 IrInstruction *operand_type, IrInstruction *ptr, IrInstruction *value,
3749 IrInstruction *ordering, AtomicOrder resolved_ordering)
4716static IrInstSrc *ir_build_atomic_store_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4717 IrInstSrc *operand_type, IrInstSrc *ptr, IrInstSrc *value, IrInstSrc *ordering)
37504718{
3751 IrInstructionAtomicStore *instruction = ir_build_instruction<IrInstructionAtomicStore>(irb, scope, source_node);
4719 IrInstSrcAtomicStore *instruction = ir_build_instruction<IrInstSrcAtomicStore>(irb, scope, source_node);
37524720 instruction->operand_type = operand_type;
37534721 instruction->ptr = ptr;
37544722 instruction->value = value;
37554723 instruction->ordering = ordering;
3756 instruction->resolved_ordering = resolved_ordering;
37574724
3758 if (operand_type != nullptr) ir_ref_instruction(operand_type, irb->current_basic_block);
4725 ir_ref_instruction(operand_type, irb->current_basic_block);
37594726 ir_ref_instruction(ptr, irb->current_basic_block);
37604727 ir_ref_instruction(value, irb->current_basic_block);
3761 if (ordering != nullptr) ir_ref_instruction(ordering, irb->current_basic_block);
4728 ir_ref_instruction(ordering, irb->current_basic_block);
37624729
37634730 return &instruction->base;
37644731}
37654732
3766static IrInstruction *ir_build_save_err_ret_addr(IrBuilder *irb, Scope *scope, AstNode *source_node) {
3767 IrInstructionSaveErrRetAddr *instruction = ir_build_instruction<IrInstructionSaveErrRetAddr>(irb, scope, source_node);
4733static IrInstGen *ir_build_atomic_store_gen(IrAnalyze *ira, IrInst *source_instr,
4734 IrInstGen *ptr, IrInstGen *value, AtomicOrder ordering)
4735{
4736 IrInstGenAtomicStore *instruction = ir_build_inst_void<IrInstGenAtomicStore>(&ira->new_irb,
4737 source_instr->scope, source_instr->source_node);
4738 instruction->ptr = ptr;
4739 instruction->value = value;
4740 instruction->ordering = ordering;
4741
4742 ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block);
4743 ir_ref_inst_gen(value, ira->new_irb.current_basic_block);
4744
37684745 return &instruction->base;
37694746}
37704747
3771static IrInstruction *ir_build_add_implicit_return_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
3772 IrInstruction *value, ResultLocReturn *result_loc_ret)
4748static IrInstSrc *ir_build_save_err_ret_addr_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
4749 IrInstSrcSaveErrRetAddr *inst = ir_build_instruction<IrInstSrcSaveErrRetAddr>(irb, scope, source_node);
4750 return &inst->base;
4751}
4752
4753static IrInstGen *ir_build_save_err_ret_addr_gen(IrAnalyze *ira, IrInst *source_instr) {
4754 IrInstGenSaveErrRetAddr *inst = ir_build_inst_void<IrInstGenSaveErrRetAddr>(&ira->new_irb,
4755 source_instr->scope, source_instr->source_node);
4756 return &inst->base;
4757}
4758
4759static IrInstSrc *ir_build_add_implicit_return_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4760 IrInstSrc *value, ResultLocReturn *result_loc_ret)
37734761{
3774 IrInstructionAddImplicitReturnType *instruction = ir_build_instruction<IrInstructionAddImplicitReturnType>(irb, scope, source_node);
3775 instruction->value = value;
3776 instruction->result_loc_ret = result_loc_ret;
4762 IrInstSrcAddImplicitReturnType *inst = ir_build_instruction<IrInstSrcAddImplicitReturnType>(irb, scope, source_node);
4763 inst->value = value;
4764 inst->result_loc_ret = result_loc_ret;
37774765
37784766 ir_ref_instruction(value, irb->current_basic_block);
37794767
3780 return &instruction->base;
4768 return &inst->base;
37814769}
37824770
3783static IrInstruction *ir_build_has_decl(IrBuilder *irb, Scope *scope, AstNode *source_node,
3784 IrInstruction *container, IrInstruction *name)
4771static IrInstSrc *ir_build_has_decl(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4772 IrInstSrc *container, IrInstSrc *name)
37854773{
3786 IrInstructionHasDecl *instruction = ir_build_instruction<IrInstructionHasDecl>(irb, scope, source_node);
4774 IrInstSrcHasDecl *instruction = ir_build_instruction<IrInstSrcHasDecl>(irb, scope, source_node);
37874775 instruction->container = container;
37884776 instruction->name = name;
37894777
......@@ -3793,17 +4781,15 @@ static IrInstruction *ir_build_has_decl(IrBuilder *irb, Scope *scope, AstNode *s
37934781 return &instruction->base;
37944782}
37954783
3796static IrInstruction *ir_build_undeclared_identifier(IrBuilder *irb, Scope *scope, AstNode *source_node,
3797 Buf *name)
3798{
3799 IrInstructionUndeclaredIdent *instruction = ir_build_instruction<IrInstructionUndeclaredIdent>(irb, scope, source_node);
4784static IrInstSrc *ir_build_undeclared_identifier(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *name) {
4785 IrInstSrcUndeclaredIdent *instruction = ir_build_instruction<IrInstSrcUndeclaredIdent>(irb, scope, source_node);
38004786 instruction->name = name;
38014787
38024788 return &instruction->base;
38034789}
38044790
3805static IrInstruction *ir_build_check_runtime_scope(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *scope_is_comptime, IrInstruction *is_comptime) {
3806 IrInstructionCheckRuntimeScope *instruction = ir_build_instruction<IrInstructionCheckRuntimeScope>(irb, scope, source_node);
4791static IrInstSrc *ir_build_check_runtime_scope(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *scope_is_comptime, IrInstSrc *is_comptime) {
4792 IrInstSrcCheckRuntimeScope *instruction = ir_build_instruction<IrInstSrcCheckRuntimeScope>(irb, scope, source_node);
38074793 instruction->scope_is_comptime = scope_is_comptime;
38084794 instruction->is_comptime = is_comptime;
38094795
......@@ -3813,10 +4799,10 @@ static IrInstruction *ir_build_check_runtime_scope(IrBuilder *irb, Scope *scope,
38134799 return &instruction->base;
38144800}
38154801
3816static IrInstruction *ir_build_union_init_named_field(IrBuilder *irb, Scope *scope, AstNode *source_node,
3817 IrInstruction *union_type, IrInstruction *field_name, IrInstruction *field_result_loc, IrInstruction *result_loc)
4802static IrInstSrc *ir_build_union_init_named_field(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4803 IrInstSrc *union_type, IrInstSrc *field_name, IrInstSrc *field_result_loc, IrInstSrc *result_loc)
38184804{
3819 IrInstructionUnionInitNamedField *instruction = ir_build_instruction<IrInstructionUnionInitNamedField>(irb, scope, source_node);
4805 IrInstSrcUnionInitNamedField *instruction = ir_build_instruction<IrInstSrcUnionInitNamedField>(irb, scope, source_node);
38204806 instruction->union_type = union_type;
38214807 instruction->field_name = field_name;
38224808 instruction->field_result_loc = field_result_loc;
......@@ -3831,79 +4817,79 @@ static IrInstruction *ir_build_union_init_named_field(IrBuilder *irb, Scope *sco
38314817}
38324818
38334819
3834static IrInstruction *ir_build_vector_to_array(IrAnalyze *ira, IrInstruction *source_instruction,
3835 ZigType *result_type, IrInstruction *vector, IrInstruction *result_loc)
4820static IrInstGen *ir_build_vector_to_array(IrAnalyze *ira, IrInst *source_instruction,
4821 ZigType *result_type, IrInstGen *vector, IrInstGen *result_loc)
38364822{
3837 IrInstructionVectorToArray *instruction = ir_build_instruction<IrInstructionVectorToArray>(&ira->new_irb,
4823 IrInstGenVectorToArray *instruction = ir_build_inst_gen<IrInstGenVectorToArray>(&ira->new_irb,
38384824 source_instruction->scope, source_instruction->source_node);
38394825 instruction->base.value->type = result_type;
38404826 instruction->vector = vector;
38414827 instruction->result_loc = result_loc;
38424828
3843 ir_ref_instruction(vector, ira->new_irb.current_basic_block);
3844 ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);
4829 ir_ref_inst_gen(vector, ira->new_irb.current_basic_block);
4830 ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
38454831
38464832 return &instruction->base;
38474833}
38484834
3849static IrInstruction *ir_build_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruction *source_instruction,
3850 ZigType *result_type, IrInstruction *operand, IrInstruction *result_loc)
4835static IrInstGen *ir_build_ptr_of_array_to_slice(IrAnalyze *ira, IrInst *source_instruction,
4836 ZigType *result_type, IrInstGen *operand, IrInstGen *result_loc)
38514837{
3852 IrInstructionPtrOfArrayToSlice *instruction = ir_build_instruction<IrInstructionPtrOfArrayToSlice>(&ira->new_irb,
4838 IrInstGenPtrOfArrayToSlice *instruction = ir_build_inst_gen<IrInstGenPtrOfArrayToSlice>(&ira->new_irb,
38534839 source_instruction->scope, source_instruction->source_node);
38544840 instruction->base.value->type = result_type;
38554841 instruction->operand = operand;
38564842 instruction->result_loc = result_loc;
38574843
3858 ir_ref_instruction(operand, ira->new_irb.current_basic_block);
3859 ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);
4844 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
4845 ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
38604846
38614847 return &instruction->base;
38624848}
38634849
3864static IrInstruction *ir_build_array_to_vector(IrAnalyze *ira, IrInstruction *source_instruction,
3865 IrInstruction *array, ZigType *result_type)
4850static IrInstGen *ir_build_array_to_vector(IrAnalyze *ira, IrInst *source_instruction,
4851 IrInstGen *array, ZigType *result_type)
38664852{
3867 IrInstructionArrayToVector *instruction = ir_build_instruction<IrInstructionArrayToVector>(&ira->new_irb,
4853 IrInstGenArrayToVector *instruction = ir_build_inst_gen<IrInstGenArrayToVector>(&ira->new_irb,
38684854 source_instruction->scope, source_instruction->source_node);
38694855 instruction->base.value->type = result_type;
38704856 instruction->array = array;
38714857
3872 ir_ref_instruction(array, ira->new_irb.current_basic_block);
4858 ir_ref_inst_gen(array, ira->new_irb.current_basic_block);
38734859
38744860 return &instruction->base;
38754861}
38764862
3877static IrInstruction *ir_build_assert_zero(IrAnalyze *ira, IrInstruction *source_instruction,
3878 IrInstruction *target)
4863static IrInstGen *ir_build_assert_zero(IrAnalyze *ira, IrInst *source_instruction,
4864 IrInstGen *target)
38794865{
3880 IrInstructionAssertZero *instruction = ir_build_instruction<IrInstructionAssertZero>(&ira->new_irb,
4866 IrInstGenAssertZero *instruction = ir_build_inst_gen<IrInstGenAssertZero>(&ira->new_irb,
38814867 source_instruction->scope, source_instruction->source_node);
38824868 instruction->base.value->type = ira->codegen->builtin_types.entry_void;
38834869 instruction->target = target;
38844870
3885 ir_ref_instruction(target, ira->new_irb.current_basic_block);
4871 ir_ref_inst_gen(target, ira->new_irb.current_basic_block);
38864872
38874873 return &instruction->base;
38884874}
38894875
3890static IrInstruction *ir_build_assert_non_null(IrAnalyze *ira, IrInstruction *source_instruction,
3891 IrInstruction *target)
4876static IrInstGen *ir_build_assert_non_null(IrAnalyze *ira, IrInst *source_instruction,
4877 IrInstGen *target)
38924878{
3893 IrInstructionAssertNonNull *instruction = ir_build_instruction<IrInstructionAssertNonNull>(&ira->new_irb,
4879 IrInstGenAssertNonNull *instruction = ir_build_inst_gen<IrInstGenAssertNonNull>(&ira->new_irb,
38944880 source_instruction->scope, source_instruction->source_node);
38954881 instruction->base.value->type = ira->codegen->builtin_types.entry_void;
38964882 instruction->target = target;
38974883
3898 ir_ref_instruction(target, ira->new_irb.current_basic_block);
4884 ir_ref_inst_gen(target, ira->new_irb.current_basic_block);
38994885
39004886 return &instruction->base;
39014887}
39024888
3903static IrInstruction *ir_build_alloca_src(IrBuilder *irb, Scope *scope, AstNode *source_node,
3904 IrInstruction *align, const char *name_hint, IrInstruction *is_comptime)
4889static IrInstSrc *ir_build_alloca_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4890 IrInstSrc *align, const char *name_hint, IrInstSrc *is_comptime)
39054891{
3906 IrInstructionAllocaSrc *instruction = ir_build_instruction<IrInstructionAllocaSrc>(irb, scope, source_node);
4892 IrInstSrcAlloca *instruction = ir_build_instruction<IrInstSrcAlloca>(irb, scope, source_node);
39074893 instruction->base.is_gen = true;
39084894 instruction->align = align;
39094895 instruction->name_hint = name_hint;
......@@ -3915,10 +4901,10 @@ static IrInstruction *ir_build_alloca_src(IrBuilder *irb, Scope *scope, AstNode
39154901 return &instruction->base;
39164902}
39174903
3918static IrInstructionAllocaGen *ir_build_alloca_gen(IrAnalyze *ira, IrInstruction *source_instruction,
4904static IrInstGenAlloca *ir_build_alloca_gen(IrAnalyze *ira, IrInst *source_instruction,
39194905 uint32_t align, const char *name_hint)
39204906{
3921 IrInstructionAllocaGen *instruction = ir_create_instruction<IrInstructionAllocaGen>(&ira->new_irb,
4907 IrInstGenAlloca *instruction = ir_create_inst_gen<IrInstGenAlloca>(&ira->new_irb,
39224908 source_instruction->scope, source_instruction->source_node);
39234909 instruction->align = align;
39244910 instruction->name_hint = name_hint;
......@@ -3926,10 +4912,10 @@ static IrInstructionAllocaGen *ir_build_alloca_gen(IrAnalyze *ira, IrInstruction
39264912 return instruction;
39274913}
39284914
3929static IrInstruction *ir_build_end_expr(IrBuilder *irb, Scope *scope, AstNode *source_node,
3930 IrInstruction *value, ResultLoc *result_loc)
4915static IrInstSrc *ir_build_end_expr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4916 IrInstSrc *value, ResultLoc *result_loc)
39314917{
3932 IrInstructionEndExpr *instruction = ir_build_instruction<IrInstructionEndExpr>(irb, scope, source_node);
4918 IrInstSrcEndExpr *instruction = ir_build_instruction<IrInstSrcEndExpr>(irb, scope, source_node);
39334919 instruction->base.is_gen = true;
39344920 instruction->value = value;
39354921 instruction->result_loc = result_loc;
......@@ -3939,29 +4925,41 @@ static IrInstruction *ir_build_end_expr(IrBuilder *irb, Scope *scope, AstNode *s
39394925 return &instruction->base;
39404926}
39414927
3942static IrInstructionSuspendBegin *ir_build_suspend_begin(IrBuilder *irb, Scope *scope, AstNode *source_node) {
3943 IrInstructionSuspendBegin *instruction = ir_build_instruction<IrInstructionSuspendBegin>(irb, scope, source_node);
3944 instruction->base.value->type = irb->codegen->builtin_types.entry_void;
4928static IrInstSrcSuspendBegin *ir_build_suspend_begin_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
4929 return ir_build_instruction<IrInstSrcSuspendBegin>(irb, scope, source_node);
4930}
39454931
3946 return instruction;
4932static IrInstGen *ir_build_suspend_begin_gen(IrAnalyze *ira, IrInst *source_instr) {
4933 IrInstGenSuspendBegin *inst = ir_build_inst_void<IrInstGenSuspendBegin>(&ira->new_irb,
4934 source_instr->scope, source_instr->source_node);
4935 return &inst->base;
39474936}
39484937
3949static IrInstruction *ir_build_suspend_finish(IrBuilder *irb, Scope *scope, AstNode *source_node,
3950 IrInstructionSuspendBegin *begin)
4938static IrInstSrc *ir_build_suspend_finish_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4939 IrInstSrcSuspendBegin *begin)
39514940{
3952 IrInstructionSuspendFinish *instruction = ir_build_instruction<IrInstructionSuspendFinish>(irb, scope, source_node);
3953 instruction->base.value->type = irb->codegen->builtin_types.entry_void;
3954 instruction->begin = begin;
4941 IrInstSrcSuspendFinish *inst = ir_build_instruction<IrInstSrcSuspendFinish>(irb, scope, source_node);
4942 inst->begin = begin;
39554943
39564944 ir_ref_instruction(&begin->base, irb->current_basic_block);
39574945
3958 return &instruction->base;
4946 return &inst->base;
4947}
4948
4949static IrInstGen *ir_build_suspend_finish_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGenSuspendBegin *begin) {
4950 IrInstGenSuspendFinish *inst = ir_build_inst_void<IrInstGenSuspendFinish>(&ira->new_irb,
4951 source_instr->scope, source_instr->source_node);
4952 inst->begin = begin;
4953
4954 ir_ref_inst_gen(&begin->base, ira->new_irb.current_basic_block);
4955
4956 return &inst->base;
39594957}
39604958
3961static IrInstruction *ir_build_await_src(IrBuilder *irb, Scope *scope, AstNode *source_node,
3962 IrInstruction *frame, ResultLoc *result_loc)
4959static IrInstSrc *ir_build_await_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4960 IrInstSrc *frame, ResultLoc *result_loc)
39634961{
3964 IrInstructionAwaitSrc *instruction = ir_build_instruction<IrInstructionAwaitSrc>(irb, scope, source_node);
4962 IrInstSrcAwait *instruction = ir_build_instruction<IrInstSrcAwait>(irb, scope, source_node);
39654963 instruction->frame = frame;
39664964 instruction->result_loc = result_loc;
39674965
......@@ -3970,24 +4968,23 @@ static IrInstruction *ir_build_await_src(IrBuilder *irb, Scope *scope, AstNode *
39704968 return &instruction->base;
39714969}
39724970
3973static IrInstructionAwaitGen *ir_build_await_gen(IrAnalyze *ira, IrInstruction *source_instruction,
3974 IrInstruction *frame, ZigType *result_type, IrInstruction *result_loc)
4971static IrInstGenAwait *ir_build_await_gen(IrAnalyze *ira, IrInst *source_instruction,
4972 IrInstGen *frame, ZigType *result_type, IrInstGen *result_loc)
39754973{
3976 IrInstructionAwaitGen *instruction = ir_build_instruction<IrInstructionAwaitGen>(&ira->new_irb,
4974 IrInstGenAwait *instruction = ir_build_inst_gen<IrInstGenAwait>(&ira->new_irb,
39774975 source_instruction->scope, source_instruction->source_node);
39784976 instruction->base.value->type = result_type;
39794977 instruction->frame = frame;
39804978 instruction->result_loc = result_loc;
39814979
3982 ir_ref_instruction(frame, ira->new_irb.current_basic_block);
3983 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);
4980 ir_ref_inst_gen(frame, ira->new_irb.current_basic_block);
4981 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
39844982
39854983 return instruction;
39864984}
39874985
3988static IrInstruction *ir_build_resume(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *frame) {
3989 IrInstructionResume *instruction = ir_build_instruction<IrInstructionResume>(irb, scope, source_node);
3990 instruction->base.value->type = irb->codegen->builtin_types.entry_void;
4986static IrInstSrc *ir_build_resume_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *frame) {
4987 IrInstSrcResume *instruction = ir_build_instruction<IrInstSrcResume>(irb, scope, source_node);
39914988 instruction->frame = frame;
39924989
39934990 ir_ref_instruction(frame, irb->current_basic_block);
......@@ -3995,12 +4992,20 @@ static IrInstruction *ir_build_resume(IrBuilder *irb, Scope *scope, AstNode *sou
39954992 return &instruction->base;
39964993}
39974994
3998static IrInstructionSpillBegin *ir_build_spill_begin(IrBuilder *irb, Scope *scope, AstNode *source_node,
3999 IrInstruction *operand, SpillId spill_id)
4995static IrInstGen *ir_build_resume_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *frame) {
4996 IrInstGenResume *instruction = ir_build_inst_void<IrInstGenResume>(&ira->new_irb,
4997 source_instr->scope, source_instr->source_node);
4998 instruction->frame = frame;
4999
5000 ir_ref_inst_gen(frame, ira->new_irb.current_basic_block);
5001
5002 return &instruction->base;
5003}
5004
5005static IrInstSrcSpillBegin *ir_build_spill_begin_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
5006 IrInstSrc *operand, SpillId spill_id)
40005007{
4001 IrInstructionSpillBegin *instruction = ir_build_instruction<IrInstructionSpillBegin>(irb, scope, source_node);
4002 instruction->base.value->special = ConstValSpecialStatic;
4003 instruction->base.value->type = irb->codegen->builtin_types.entry_void;
5008 IrInstSrcSpillBegin *instruction = ir_build_instruction<IrInstSrcSpillBegin>(irb, scope, source_node);
40045009 instruction->operand = operand;
40055010 instruction->spill_id = spill_id;
40065011
......@@ -4009,10 +5014,23 @@ static IrInstructionSpillBegin *ir_build_spill_begin(IrBuilder *irb, Scope *scop
40095014 return instruction;
40105015}
40115016
4012static IrInstruction *ir_build_spill_end(IrBuilder *irb, Scope *scope, AstNode *source_node,
4013 IrInstructionSpillBegin *begin)
5017static IrInstGen *ir_build_spill_begin_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand,
5018 SpillId spill_id)
5019{
5020 IrInstGenSpillBegin *instruction = ir_build_inst_void<IrInstGenSpillBegin>(&ira->new_irb,
5021 source_instr->scope, source_instr->source_node);
5022 instruction->operand = operand;
5023 instruction->spill_id = spill_id;
5024
5025 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
5026
5027 return &instruction->base;
5028}
5029
5030static IrInstSrc *ir_build_spill_end_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
5031 IrInstSrcSpillBegin *begin)
40145032{
4015 IrInstructionSpillEnd *instruction = ir_build_instruction<IrInstructionSpillEnd>(irb, scope, source_node);
5033 IrInstSrcSpillEnd *instruction = ir_build_instruction<IrInstSrcSpillEnd>(irb, scope, source_node);
40165034 instruction->begin = begin;
40175035
40185036 ir_ref_instruction(&begin->base, irb->current_basic_block);
......@@ -4020,22 +5038,35 @@ static IrInstruction *ir_build_spill_end(IrBuilder *irb, Scope *scope, AstNode *
40205038 return &instruction->base;
40215039}
40225040
4023static IrInstruction *ir_build_vector_extract_elem(IrAnalyze *ira, IrInstruction *source_instruction,
4024 IrInstruction *vector, IrInstruction *index)
5041static IrInstGen *ir_build_spill_end_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGenSpillBegin *begin,
5042 ZigType *result_type)
5043{
5044 IrInstGenSpillEnd *instruction = ir_build_inst_gen<IrInstGenSpillEnd>(&ira->new_irb,
5045 source_instr->scope, source_instr->source_node);
5046 instruction->base.value->type = result_type;
5047 instruction->begin = begin;
5048
5049 ir_ref_inst_gen(&begin->base, ira->new_irb.current_basic_block);
5050
5051 return &instruction->base;
5052}
5053
5054static IrInstGen *ir_build_vector_extract_elem(IrAnalyze *ira, IrInst *source_instruction,
5055 IrInstGen *vector, IrInstGen *index)
40255056{
4026 IrInstructionVectorExtractElem *instruction = ir_build_instruction<IrInstructionVectorExtractElem>(
5057 IrInstGenVectorExtractElem *instruction = ir_build_inst_gen<IrInstGenVectorExtractElem>(
40275058 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
40285059 instruction->base.value->type = vector->value->type->data.vector.elem_type;
40295060 instruction->vector = vector;
40305061 instruction->index = index;
40315062
4032 ir_ref_instruction(vector, ira->new_irb.current_basic_block);
4033 ir_ref_instruction(index, ira->new_irb.current_basic_block);
5063 ir_ref_inst_gen(vector, ira->new_irb.current_basic_block);
5064 ir_ref_inst_gen(index, ira->new_irb.current_basic_block);
40345065
40355066 return &instruction->base;
40365067}
40375068
4038static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_scope, size_t *results) {
5069static void ir_count_defers(IrBuilderSrc *irb, Scope *inner_scope, Scope *outer_scope, size_t *results) {
40395070 results[ReturnKindUnconditional] = 0;
40405071 results[ReturnKindError] = 0;
40415072
......@@ -4072,12 +5103,12 @@ static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_sco
40725103 }
40735104}
40745105
4075static IrInstruction *ir_mark_gen(IrInstruction *instruction) {
5106static IrInstSrc *ir_mark_gen(IrInstSrc *instruction) {
40765107 instruction->is_gen = true;
40775108 return instruction;
40785109}
40795110
4080static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *outer_scope, bool gen_error_defers) {
5111static bool ir_gen_defers_for_block(IrBuilderSrc *irb, Scope *inner_scope, Scope *outer_scope, bool gen_error_defers) {
40815112 Scope *scope = inner_scope;
40825113 bool is_noreturn = false;
40835114 while (scope != outer_scope) {
......@@ -4094,11 +5125,9 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o
40945125 {
40955126 AstNode *defer_expr_node = defer_node->data.defer.expr;
40965127 Scope *defer_expr_scope = defer_node->data.defer.expr_scope;
4097 IrInstruction *defer_expr_value = ir_gen_node(irb, defer_expr_node, defer_expr_scope);
4098 if (defer_expr_value != irb->codegen->invalid_instruction) {
4099 if (defer_expr_value->value->type != nullptr &&
4100 defer_expr_value->value->type->id == ZigTypeIdUnreachable)
4101 {
5128 IrInstSrc *defer_expr_value = ir_gen_node(irb, defer_expr_node, defer_expr_scope);
5129 if (defer_expr_value != irb->codegen->invalid_inst_src) {
5130 if (defer_expr_value->is_noreturn) {
41025131 is_noreturn = true;
41035132 } else {
41045133 ir_mark_gen(ir_build_check_statement_is_void(irb, defer_expr_scope, defer_expr_node,
......@@ -4130,13 +5159,17 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o
41305159 return is_noreturn;
41315160}
41325161
4133static void ir_set_cursor_at_end(IrBuilder *irb, IrBasicBlock *basic_block) {
5162static void ir_set_cursor_at_end_gen(IrBuilderGen *irb, IrBasicBlockGen *basic_block) {
41345163 assert(basic_block);
5164 irb->current_basic_block = basic_block;
5165}
41355166
5167static void ir_set_cursor_at_end(IrBuilderSrc *irb, IrBasicBlockSrc *basic_block) {
5168 assert(basic_block);
41365169 irb->current_basic_block = basic_block;
41375170}
41385171
4139static void ir_set_cursor_at_end_and_append_block(IrBuilder *irb, IrBasicBlock *basic_block) {
5172static void ir_set_cursor_at_end_and_append_block(IrBuilderSrc *irb, IrBasicBlockSrc *basic_block) {
41405173 basic_block->index = irb->exec->basic_block_list.length;
41415174 irb->exec->basic_block_list.append(basic_block);
41425175 ir_set_cursor_at_end(irb, basic_block);
......@@ -4166,13 +5199,13 @@ static ScopeDeferExpr *get_scope_defer_expr(Scope *scope) {
41665199 return nullptr;
41675200}
41685201
4169static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) {
5202static IrInstSrc *ir_gen_return(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) {
41705203 assert(node->type == NodeTypeReturnExpr);
41715204
41725205 ZigFn *fn_entry = exec_fn_entry(irb->exec);
41735206 if (!fn_entry) {
41745207 add_node_error(irb->codegen, node, buf_sprintf("return expression outside function definition"));
4175 return irb->codegen->invalid_instruction;
5208 return irb->codegen->invalid_inst_src;
41765209 }
41775210
41785211 ScopeDeferExpr *scope_defer_expr = get_scope_defer_expr(scope);
......@@ -4181,7 +5214,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
41815214 add_node_error(irb->codegen, node, buf_sprintf("cannot return from defer expression"));
41825215 scope_defer_expr->reported_err = true;
41835216 }
4184 return irb->codegen->invalid_instruction;
5217 return irb->codegen->invalid_inst_src;
41855218 }
41865219
41875220 Scope *outer_scope = irb->exec->begin_scope;
......@@ -4194,15 +5227,15 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
41945227 result_loc_ret->base.id = ResultLocIdReturn;
41955228 ir_build_reset_result(irb, scope, node, &result_loc_ret->base);
41965229
4197 IrInstruction *return_value;
5230 IrInstSrc *return_value;
41985231 if (expr_node) {
41995232 // Temporarily set this so that if we return a type it gets the name of the function
42005233 ZigFn *prev_name_fn = irb->exec->name_fn;
42015234 irb->exec->name_fn = exec_fn_entry(irb->exec);
42025235 return_value = ir_gen_node_extra(irb, expr_node, scope, LValNone, &result_loc_ret->base);
42035236 irb->exec->name_fn = prev_name_fn;
4204 if (return_value == irb->codegen->invalid_instruction)
4205 return irb->codegen->invalid_instruction;
5237 if (return_value == irb->codegen->invalid_inst_src)
5238 return irb->codegen->invalid_inst_src;
42065239 } else {
42075240 return_value = ir_build_const_void(irb, scope, node);
42085241 }
......@@ -4215,22 +5248,22 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
42155248 if (!have_err_defers && !irb->codegen->have_err_ret_tracing) {
42165249 // only generate unconditional defers
42175250 ir_gen_defers_for_block(irb, scope, outer_scope, false);
4218 IrInstruction *result = ir_build_return(irb, scope, node, return_value);
5251 IrInstSrc *result = ir_build_return_src(irb, scope, node, return_value);
42195252 result_loc_ret->base.source_instruction = result;
42205253 return result;
42215254 }
42225255 bool should_inline = ir_should_inline(irb->exec, scope);
42235256
4224 IrBasicBlock *err_block = ir_create_basic_block(irb, scope, "ErrRetErr");
4225 IrBasicBlock *ok_block = ir_create_basic_block(irb, scope, "ErrRetOk");
5257 IrBasicBlockSrc *err_block = ir_create_basic_block(irb, scope, "ErrRetErr");
5258 IrBasicBlockSrc *ok_block = ir_create_basic_block(irb, scope, "ErrRetOk");
42265259
42275260 if (!have_err_defers) {
42285261 ir_gen_defers_for_block(irb, scope, outer_scope, false);
42295262 }
42305263
4231 IrInstruction *is_err = ir_build_test_err_src(irb, scope, node, return_value, false, true);
5264 IrInstSrc *is_err = ir_build_test_err_src(irb, scope, node, return_value, false, true);
42325265
4233 IrInstruction *is_comptime;
5266 IrInstSrc *is_comptime;
42345267 if (should_inline) {
42355268 is_comptime = ir_build_const_bool(irb, scope, node, should_inline);
42365269 } else {
......@@ -4238,14 +5271,14 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
42385271 }
42395272
42405273 ir_mark_gen(ir_build_cond_br(irb, scope, node, is_err, err_block, ok_block, is_comptime));
4241 IrBasicBlock *ret_stmt_block = ir_create_basic_block(irb, scope, "RetStmt");
5274 IrBasicBlockSrc *ret_stmt_block = ir_create_basic_block(irb, scope, "RetStmt");
42425275
42435276 ir_set_cursor_at_end_and_append_block(irb, err_block);
42445277 if (have_err_defers) {
42455278 ir_gen_defers_for_block(irb, scope, outer_scope, true);
42465279 }
42475280 if (irb->codegen->have_err_ret_tracing && !should_inline) {
4248 ir_build_save_err_ret_addr(irb, scope, node);
5281 ir_build_save_err_ret_addr_src(irb, scope, node);
42495282 }
42505283 ir_build_br(irb, scope, node, ret_stmt_block, is_comptime);
42515284
......@@ -4256,21 +5289,21 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
42565289 ir_build_br(irb, scope, node, ret_stmt_block, is_comptime);
42575290
42585291 ir_set_cursor_at_end_and_append_block(irb, ret_stmt_block);
4259 IrInstruction *result = ir_build_return(irb, scope, node, return_value);
5292 IrInstSrc *result = ir_build_return_src(irb, scope, node, return_value);
42605293 result_loc_ret->base.source_instruction = result;
42615294 return result;
42625295 }
42635296 case ReturnKindError:
42645297 {
42655298 assert(expr_node);
4266 IrInstruction *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
4267 if (err_union_ptr == irb->codegen->invalid_instruction)
4268 return irb->codegen->invalid_instruction;
4269 IrInstruction *is_err_val = ir_build_test_err_src(irb, scope, node, err_union_ptr, true, false);
4270
4271 IrBasicBlock *return_block = ir_create_basic_block(irb, scope, "ErrRetReturn");
4272 IrBasicBlock *continue_block = ir_create_basic_block(irb, scope, "ErrRetContinue");
4273 IrInstruction *is_comptime;
5299 IrInstSrc *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
5300 if (err_union_ptr == irb->codegen->invalid_inst_src)
5301 return irb->codegen->invalid_inst_src;
5302 IrInstSrc *is_err_val = ir_build_test_err_src(irb, scope, node, err_union_ptr, true, false);
5303
5304 IrBasicBlockSrc *return_block = ir_create_basic_block(irb, scope, "ErrRetReturn");
5305 IrBasicBlockSrc *continue_block = ir_create_basic_block(irb, scope, "ErrRetContinue");
5306 IrInstSrc *is_comptime;
42745307 bool should_inline = ir_should_inline(irb->exec, scope);
42755308 if (should_inline) {
42765309 is_comptime = ir_build_const_bool(irb, scope, node, true);
......@@ -4280,10 +5313,10 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
42805313 ir_mark_gen(ir_build_cond_br(irb, scope, node, is_err_val, return_block, continue_block, is_comptime));
42815314
42825315 ir_set_cursor_at_end_and_append_block(irb, return_block);
4283 IrInstruction *err_val_ptr = ir_build_unwrap_err_code(irb, scope, node, err_union_ptr);
4284 IrInstruction *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr);
5316 IrInstSrc *err_val_ptr = ir_build_unwrap_err_code_src(irb, scope, node, err_union_ptr);
5317 IrInstSrc *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr);
42855318 ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, node, err_val, nullptr));
4286 IrInstructionSpillBegin *spill_begin = ir_build_spill_begin(irb, scope, node, err_val,
5319 IrInstSrcSpillBegin *spill_begin = ir_build_spill_begin_src(irb, scope, node, err_val,
42875320 SpillIdRetErrCode);
42885321 ResultLocReturn *result_loc_ret = allocate<ResultLocReturn>(1, "ResultLocReturn");
42895322 result_loc_ret->base.id = ResultLocIdReturn;
......@@ -4291,15 +5324,15 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
42915324 ir_build_end_expr(irb, scope, node, err_val, &result_loc_ret->base);
42925325 if (!ir_gen_defers_for_block(irb, scope, outer_scope, true)) {
42935326 if (irb->codegen->have_err_ret_tracing && !should_inline) {
4294 ir_build_save_err_ret_addr(irb, scope, node);
5327 ir_build_save_err_ret_addr_src(irb, scope, node);
42955328 }
4296 err_val = ir_build_spill_end(irb, scope, node, spill_begin);
4297 IrInstruction *ret_inst = ir_build_return(irb, scope, node, err_val);
5329 err_val = ir_build_spill_end_src(irb, scope, node, spill_begin);
5330 IrInstSrc *ret_inst = ir_build_return_src(irb, scope, node, err_val);
42985331 result_loc_ret->base.source_instruction = ret_inst;
42995332 }
43005333
43015334 ir_set_cursor_at_end_and_append_block(irb, continue_block);
4302 IrInstruction *unwrapped_ptr = ir_build_unwrap_err_payload(irb, scope, node, err_union_ptr, false, false);
5335 IrInstSrc *unwrapped_ptr = ir_build_unwrap_err_payload_src(irb, scope, node, err_union_ptr, false, false);
43035336 if (lval == LValPtr)
43045337 return unwrapped_ptr;
43055338 else
......@@ -4310,7 +5343,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
43105343}
43115344
43125345static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_scope,
4313 Buf *name, bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstruction *is_comptime,
5346 Buf *name, bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstSrc *is_comptime,
43145347 bool skip_name_check)
43155348{
43165349 ZigVar *variable_entry = allocate<ZigVar>(1, "ZigVar");
......@@ -4322,7 +5355,7 @@ static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_s
43225355 variable_entry->const_value = create_const_vals(1);
43235356
43245357 if (is_comptime != nullptr) {
4325 is_comptime->ref_count += 1;
5358 is_comptime->base.ref_count += 1;
43265359 }
43275360
43285361 if (name) {
......@@ -4372,8 +5405,8 @@ static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_s
43725405
43735406// Set name to nullptr to make the variable anonymous (not visible to programmer).
43745407// After you call this function var->child_scope has the variable in scope
4375static ZigVar *ir_create_var(IrBuilder *irb, AstNode *node, Scope *scope, Buf *name,
4376 bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstruction *is_comptime)
5408static ZigVar *ir_create_var(IrBuilderSrc *irb, AstNode *node, Scope *scope, Buf *name,
5409 bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstSrc *is_comptime)
43775410{
43785411 bool is_underscored = name ? buf_eql_str(name, "_") : false;
43795412 ZigVar *var = create_local_var(irb->codegen, node, scope,
......@@ -4396,13 +5429,13 @@ static ResultLocPeer *create_peer_result(ResultLocPeerParent *peer_parent) {
43965429 return result;
43975430}
43985431
4399static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode *block_node, LVal lval,
5432static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode *block_node, LVal lval,
44005433 ResultLoc *result_loc)
44015434{
44025435 assert(block_node->type == NodeTypeBlock);
44035436
4404 ZigList<IrInstruction *> incoming_values = {0};
4405 ZigList<IrBasicBlock *> incoming_blocks = {0};
5437 ZigList<IrInstSrc *> incoming_values = {0};
5438 ZigList<IrBasicBlockSrc *> incoming_blocks = {0};
44065439
44075440 ScopeBlock *scope_block = create_block_scope(irb->codegen, block_node, parent_scope);
44085441
......@@ -4438,11 +5471,11 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
44385471 }
44395472
44405473 bool is_continuation_unreachable = false;
4441 IrInstruction *noreturn_return_value = nullptr;
5474 IrInstSrc *noreturn_return_value = nullptr;
44425475 for (size_t i = 0; i < block_node->data.block.statements.length; i += 1) {
44435476 AstNode *statement_node = block_node->data.block.statements.at(i);
44445477
4445 IrInstruction *statement_value = ir_gen_node(irb, statement_node, child_scope);
5478 IrInstSrc *statement_value = ir_gen_node(irb, statement_node, child_scope);
44465479 is_continuation_unreachable = instr_is_unreachable(statement_value);
44475480 if (is_continuation_unreachable) {
44485481 // keep the last noreturn statement value around in case we need to return it
......@@ -4450,15 +5483,15 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
44505483 }
44515484 // This logic must be kept in sync with
44525485 // [STMT_EXPR_TEST_THING] <--- (search this token)
4453 if (statement_node->type == NodeTypeDefer && statement_value != irb->codegen->invalid_instruction) {
5486 if (statement_node->type == NodeTypeDefer && statement_value != irb->codegen->invalid_inst_src) {
44545487 // defer starts a new scope
44555488 child_scope = statement_node->data.defer.child_scope;
44565489 assert(child_scope);
4457 } else if (statement_value->id == IrInstructionIdDeclVarSrc) {
5490 } else if (statement_value->id == IrInstSrcIdDeclVar) {
44585491 // variable declarations start a new scope
4459 IrInstructionDeclVarSrc *decl_var_instruction = (IrInstructionDeclVarSrc *)statement_value;
5492 IrInstSrcDeclVar *decl_var_instruction = (IrInstSrcDeclVar *)statement_value;
44605493 child_scope = decl_var_instruction->var->child_scope;
4461 } else if (statement_value != irb->codegen->invalid_instruction && !is_continuation_unreachable) {
5494 } else if (statement_value != irb->codegen->invalid_inst_src && !is_continuation_unreachable) {
44625495 // this statement's value must be void
44635496 ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, statement_node, statement_value));
44645497 }
......@@ -4474,12 +5507,12 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
44745507 scope_block->peer_parent->peers.last()->next_bb = scope_block->end_block;
44755508 }
44765509 ir_set_cursor_at_end_and_append_block(irb, scope_block->end_block);
4477 IrInstruction *phi = ir_build_phi(irb, parent_scope, block_node, incoming_blocks.length,
5510 IrInstSrc *phi = ir_build_phi(irb, parent_scope, block_node, incoming_blocks.length,
44785511 incoming_blocks.items, incoming_values.items, scope_block->peer_parent);
44795512 return ir_expr_wrap(irb, parent_scope, phi, result_loc);
44805513 } else {
44815514 incoming_blocks.append(irb->current_basic_block);
4482 IrInstruction *else_expr_result = ir_mark_gen(ir_build_const_void(irb, parent_scope, block_node));
5515 IrInstSrc *else_expr_result = ir_mark_gen(ir_build_const_void(irb, parent_scope, block_node));
44835516
44845517 if (scope_block->peer_parent != nullptr) {
44855518 ResultLocPeer *peer_result = create_peer_result(scope_block->peer_parent);
......@@ -4499,15 +5532,15 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
44995532 ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false);
45005533 }
45015534
4502 IrInstruction *result;
5535 IrInstSrc *result;
45035536 if (block_node->data.block.name != nullptr) {
45045537 ir_mark_gen(ir_build_br(irb, parent_scope, block_node, scope_block->end_block, scope_block->is_comptime));
45055538 ir_set_cursor_at_end_and_append_block(irb, scope_block->end_block);
4506 IrInstruction *phi = ir_build_phi(irb, parent_scope, block_node, incoming_blocks.length,
5539 IrInstSrc *phi = ir_build_phi(irb, parent_scope, block_node, incoming_blocks.length,
45075540 incoming_blocks.items, incoming_values.items, scope_block->peer_parent);
45085541 result = ir_expr_wrap(irb, parent_scope, phi, result_loc);
45095542 } else {
4510 IrInstruction *void_inst = ir_mark_gen(ir_build_const_void(irb, child_scope, block_node));
5543 IrInstSrc *void_inst = ir_mark_gen(ir_build_const_void(irb, child_scope, block_node));
45115544 result = ir_lval_wrap(irb, parent_scope, void_inst, lval, result_loc);
45125545 }
45135546 if (!is_return_from_fn)
......@@ -4518,30 +5551,30 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
45185551
45195552 ir_mark_gen(ir_build_add_implicit_return_type(irb, child_scope, block_node, result, nullptr));
45205553 ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false);
4521 return ir_mark_gen(ir_build_return(irb, child_scope, result->source_node, result));
5554 return ir_mark_gen(ir_build_return_src(irb, child_scope, result->base.source_node, result));
45225555}
45235556
4524static IrInstruction *ir_gen_bin_op_id(IrBuilder *irb, Scope *scope, AstNode *node, IrBinOp op_id) {
5557static IrInstSrc *ir_gen_bin_op_id(IrBuilderSrc *irb, Scope *scope, AstNode *node, IrBinOp op_id) {
45255558 Scope *inner_scope = scope;
45265559 if (op_id == IrBinOpArrayCat || op_id == IrBinOpArrayMult) {
45275560 inner_scope = create_comptime_scope(irb->codegen, node, scope);
45285561 }
45295562
4530 IrInstruction *op1 = ir_gen_node(irb, node->data.bin_op_expr.op1, inner_scope);
4531 IrInstruction *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, inner_scope);
5563 IrInstSrc *op1 = ir_gen_node(irb, node->data.bin_op_expr.op1, inner_scope);
5564 IrInstSrc *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, inner_scope);
45325565
4533 if (op1 == irb->codegen->invalid_instruction || op2 == irb->codegen->invalid_instruction)
4534 return irb->codegen->invalid_instruction;
5566 if (op1 == irb->codegen->invalid_inst_src || op2 == irb->codegen->invalid_inst_src)
5567 return irb->codegen->invalid_inst_src;
45355568
45365569 return ir_build_bin_op(irb, scope, node, op_id, op1, op2, true);
45375570}
45385571
4539static IrInstruction *ir_gen_merge_err_sets(IrBuilder *irb, Scope *scope, AstNode *node) {
4540 IrInstruction *op1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope);
4541 IrInstruction *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
5572static IrInstSrc *ir_gen_merge_err_sets(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
5573 IrInstSrc *op1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope);
5574 IrInstSrc *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
45425575
4543 if (op1 == irb->codegen->invalid_instruction || op2 == irb->codegen->invalid_instruction)
4544 return irb->codegen->invalid_instruction;
5576 if (op1 == irb->codegen->invalid_inst_src || op2 == irb->codegen->invalid_inst_src)
5577 return irb->codegen->invalid_inst_src;
45455578
45465579 // TODO only pass type_name when the || operator is the top level AST node in the var decl expr
45475580 Buf bare_name = BUF_INIT;
......@@ -4550,10 +5583,10 @@ static IrInstruction *ir_gen_merge_err_sets(IrBuilder *irb, Scope *scope, AstNod
45505583 return ir_build_merge_err_sets(irb, scope, node, op1, op2, type_name);
45515584}
45525585
4553static IrInstruction *ir_gen_assign(IrBuilder *irb, Scope *scope, AstNode *node) {
4554 IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr);
4555 if (lvalue == irb->codegen->invalid_instruction)
4556 return irb->codegen->invalid_instruction;
5586static IrInstSrc *ir_gen_assign(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
5587 IrInstSrc *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr);
5588 if (lvalue == irb->codegen->invalid_inst_src)
5589 return irb->codegen->invalid_inst_src;
45575590
45585591 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1, "ResultLocInstruction");
45595592 result_loc_inst->base.id = ResultLocIdInstruction;
......@@ -4561,49 +5594,49 @@ static IrInstruction *ir_gen_assign(IrBuilder *irb, Scope *scope, AstNode *node)
45615594 ir_ref_instruction(lvalue, irb->current_basic_block);
45625595 ir_build_reset_result(irb, scope, node, &result_loc_inst->base);
45635596
4564 IrInstruction *rvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op2, scope, LValNone,
5597 IrInstSrc *rvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op2, scope, LValNone,
45655598 &result_loc_inst->base);
4566 if (rvalue == irb->codegen->invalid_instruction)
4567 return irb->codegen->invalid_instruction;
5599 if (rvalue == irb->codegen->invalid_inst_src)
5600 return irb->codegen->invalid_inst_src;
45685601
45695602 return ir_build_const_void(irb, scope, node);
45705603}
45715604
4572static IrInstruction *ir_gen_assign_merge_err_sets(IrBuilder *irb, Scope *scope, AstNode *node) {
4573 IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr);
4574 if (lvalue == irb->codegen->invalid_instruction)
5605static IrInstSrc *ir_gen_assign_merge_err_sets(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
5606 IrInstSrc *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr);
5607 if (lvalue == irb->codegen->invalid_inst_src)
45755608 return lvalue;
4576 IrInstruction *op1 = ir_build_load_ptr(irb, scope, node->data.bin_op_expr.op1, lvalue);
4577 IrInstruction *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
4578 if (op2 == irb->codegen->invalid_instruction)
5609 IrInstSrc *op1 = ir_build_load_ptr(irb, scope, node->data.bin_op_expr.op1, lvalue);
5610 IrInstSrc *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
5611 if (op2 == irb->codegen->invalid_inst_src)
45795612 return op2;
4580 IrInstruction *result = ir_build_merge_err_sets(irb, scope, node, op1, op2, nullptr);
5613 IrInstSrc *result = ir_build_merge_err_sets(irb, scope, node, op1, op2, nullptr);
45815614 ir_build_store_ptr(irb, scope, node, lvalue, result);
45825615 return ir_build_const_void(irb, scope, node);
45835616}
45845617
4585static IrInstruction *ir_gen_assign_op(IrBuilder *irb, Scope *scope, AstNode *node, IrBinOp op_id) {
4586 IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr);
4587 if (lvalue == irb->codegen->invalid_instruction)
5618static IrInstSrc *ir_gen_assign_op(IrBuilderSrc *irb, Scope *scope, AstNode *node, IrBinOp op_id) {
5619 IrInstSrc *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr);
5620 if (lvalue == irb->codegen->invalid_inst_src)
45885621 return lvalue;
4589 IrInstruction *op1 = ir_build_load_ptr(irb, scope, node->data.bin_op_expr.op1, lvalue);
4590 IrInstruction *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
4591 if (op2 == irb->codegen->invalid_instruction)
5622 IrInstSrc *op1 = ir_build_load_ptr(irb, scope, node->data.bin_op_expr.op1, lvalue);
5623 IrInstSrc *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
5624 if (op2 == irb->codegen->invalid_inst_src)
45925625 return op2;
4593 IrInstruction *result = ir_build_bin_op(irb, scope, node, op_id, op1, op2, true);
5626 IrInstSrc *result = ir_build_bin_op(irb, scope, node, op_id, op1, op2, true);
45945627 ir_build_store_ptr(irb, scope, node, lvalue, result);
45955628 return ir_build_const_void(irb, scope, node);
45965629}
45975630
4598static IrInstruction *ir_gen_bool_or(IrBuilder *irb, Scope *scope, AstNode *node) {
5631static IrInstSrc *ir_gen_bool_or(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
45995632 assert(node->type == NodeTypeBinOpExpr);
46005633
4601 IrInstruction *val1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope);
4602 if (val1 == irb->codegen->invalid_instruction)
4603 return irb->codegen->invalid_instruction;
4604 IrBasicBlock *post_val1_block = irb->current_basic_block;
5634 IrInstSrc *val1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope);
5635 if (val1 == irb->codegen->invalid_inst_src)
5636 return irb->codegen->invalid_inst_src;
5637 IrBasicBlockSrc *post_val1_block = irb->current_basic_block;
46055638
4606 IrInstruction *is_comptime;
5639 IrInstSrc *is_comptime;
46075640 if (ir_should_inline(irb->exec, scope)) {
46085641 is_comptime = ir_build_const_bool(irb, scope, node, true);
46095642 } else {
......@@ -4611,41 +5644,41 @@ static IrInstruction *ir_gen_bool_or(IrBuilder *irb, Scope *scope, AstNode *node
46115644 }
46125645
46135646 // block for when val1 == false
4614 IrBasicBlock *false_block = ir_create_basic_block(irb, scope, "BoolOrFalse");
5647 IrBasicBlockSrc *false_block = ir_create_basic_block(irb, scope, "BoolOrFalse");
46155648 // block for when val1 == true (don't even evaluate the second part)
4616 IrBasicBlock *true_block = ir_create_basic_block(irb, scope, "BoolOrTrue");
5649 IrBasicBlockSrc *true_block = ir_create_basic_block(irb, scope, "BoolOrTrue");
46175650
46185651 ir_build_cond_br(irb, scope, node, val1, true_block, false_block, is_comptime);
46195652
46205653 ir_set_cursor_at_end_and_append_block(irb, false_block);
4621 IrInstruction *val2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
4622 if (val2 == irb->codegen->invalid_instruction)
4623 return irb->codegen->invalid_instruction;
4624 IrBasicBlock *post_val2_block = irb->current_basic_block;
5654 IrInstSrc *val2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
5655 if (val2 == irb->codegen->invalid_inst_src)
5656 return irb->codegen->invalid_inst_src;
5657 IrBasicBlockSrc *post_val2_block = irb->current_basic_block;
46255658
46265659 ir_build_br(irb, scope, node, true_block, is_comptime);
46275660
46285661 ir_set_cursor_at_end_and_append_block(irb, true_block);
46295662
4630 IrInstruction **incoming_values = allocate<IrInstruction *>(2, "IrInstruction *");
5663 IrInstSrc **incoming_values = allocate<IrInstSrc *>(2, "IrInstSrc *");
46315664 incoming_values[0] = val1;
46325665 incoming_values[1] = val2;
4633 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *");
5666 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
46345667 incoming_blocks[0] = post_val1_block;
46355668 incoming_blocks[1] = post_val2_block;
46365669
46375670 return ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, nullptr);
46385671}
46395672
4640static IrInstruction *ir_gen_bool_and(IrBuilder *irb, Scope *scope, AstNode *node) {
5673static IrInstSrc *ir_gen_bool_and(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
46415674 assert(node->type == NodeTypeBinOpExpr);
46425675
4643 IrInstruction *val1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope);
4644 if (val1 == irb->codegen->invalid_instruction)
4645 return irb->codegen->invalid_instruction;
4646 IrBasicBlock *post_val1_block = irb->current_basic_block;
5676 IrInstSrc *val1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope);
5677 if (val1 == irb->codegen->invalid_inst_src)
5678 return irb->codegen->invalid_inst_src;
5679 IrBasicBlockSrc *post_val1_block = irb->current_basic_block;
46475680
4648 IrInstruction *is_comptime;
5681 IrInstSrc *is_comptime;
46495682 if (ir_should_inline(irb->exec, scope)) {
46505683 is_comptime = ir_build_const_bool(irb, scope, node, true);
46515684 } else {
......@@ -4653,34 +5686,34 @@ static IrInstruction *ir_gen_bool_and(IrBuilder *irb, Scope *scope, AstNode *nod
46535686 }
46545687
46555688 // block for when val1 == true
4656 IrBasicBlock *true_block = ir_create_basic_block(irb, scope, "BoolAndTrue");
5689 IrBasicBlockSrc *true_block = ir_create_basic_block(irb, scope, "BoolAndTrue");
46575690 // block for when val1 == false (don't even evaluate the second part)
4658 IrBasicBlock *false_block = ir_create_basic_block(irb, scope, "BoolAndFalse");
5691 IrBasicBlockSrc *false_block = ir_create_basic_block(irb, scope, "BoolAndFalse");
46595692
46605693 ir_build_cond_br(irb, scope, node, val1, true_block, false_block, is_comptime);
46615694
46625695 ir_set_cursor_at_end_and_append_block(irb, true_block);
4663 IrInstruction *val2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
4664 if (val2 == irb->codegen->invalid_instruction)
4665 return irb->codegen->invalid_instruction;
4666 IrBasicBlock *post_val2_block = irb->current_basic_block;
5696 IrInstSrc *val2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
5697 if (val2 == irb->codegen->invalid_inst_src)
5698 return irb->codegen->invalid_inst_src;
5699 IrBasicBlockSrc *post_val2_block = irb->current_basic_block;
46675700
46685701 ir_build_br(irb, scope, node, false_block, is_comptime);
46695702
46705703 ir_set_cursor_at_end_and_append_block(irb, false_block);
46715704
4672 IrInstruction **incoming_values = allocate<IrInstruction *>(2);
5705 IrInstSrc **incoming_values = allocate<IrInstSrc *>(2);
46735706 incoming_values[0] = val1;
46745707 incoming_values[1] = val2;
4675 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *");
5708 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
46765709 incoming_blocks[0] = post_val1_block;
46775710 incoming_blocks[1] = post_val2_block;
46785711
46795712 return ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, nullptr);
46805713}
46815714
4682static ResultLocPeerParent *ir_build_result_peers(IrBuilder *irb, IrInstruction *cond_br_inst,
4683 IrBasicBlock *end_block, ResultLoc *parent, IrInstruction *is_comptime)
5715static ResultLocPeerParent *ir_build_result_peers(IrBuilderSrc *irb, IrInstSrc *cond_br_inst,
5716 IrBasicBlockSrc *end_block, ResultLoc *parent, IrInstSrc *is_comptime)
46845717{
46855718 ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1);
46865719 peer_parent->base.id = ResultLocIdPeerParent;
......@@ -4690,17 +5723,17 @@ static ResultLocPeerParent *ir_build_result_peers(IrBuilder *irb, IrInstruction
46905723 peer_parent->is_comptime = is_comptime;
46915724 peer_parent->parent = parent;
46925725
4693 IrInstruction *popped_inst = irb->current_basic_block->instruction_list.pop();
4694 ir_assert(popped_inst == cond_br_inst, cond_br_inst);
5726 IrInstSrc *popped_inst = irb->current_basic_block->instruction_list.pop();
5727 ir_assert(popped_inst == cond_br_inst, &cond_br_inst->base);
46955728
4696 ir_build_reset_result(irb, cond_br_inst->scope, cond_br_inst->source_node, &peer_parent->base);
5729 ir_build_reset_result(irb, cond_br_inst->base.scope, cond_br_inst->base.source_node, &peer_parent->base);
46975730 irb->current_basic_block->instruction_list.append(popped_inst);
46985731
46995732 return peer_parent;
47005733}
47015734
4702static ResultLocPeerParent *ir_build_binary_result_peers(IrBuilder *irb, IrInstruction *cond_br_inst,
4703 IrBasicBlock *else_block, IrBasicBlock *end_block, ResultLoc *parent, IrInstruction *is_comptime)
5735static ResultLocPeerParent *ir_build_binary_result_peers(IrBuilderSrc *irb, IrInstSrc *cond_br_inst,
5736 IrBasicBlockSrc *else_block, IrBasicBlockSrc *end_block, ResultLoc *parent, IrInstSrc *is_comptime)
47045737{
47055738 ResultLocPeerParent *peer_parent = ir_build_result_peers(irb, cond_br_inst, end_block, parent, is_comptime);
47065739
......@@ -4713,7 +5746,7 @@ static ResultLocPeerParent *ir_build_binary_result_peers(IrBuilder *irb, IrInstr
47135746 return peer_parent;
47145747}
47155748
4716static IrInstruction *ir_gen_orelse(IrBuilder *irb, Scope *parent_scope, AstNode *node, LVal lval,
5749static IrInstSrc *ir_gen_orelse(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node, LVal lval,
47175750 ResultLoc *result_loc)
47185751{
47195752 assert(node->type == NodeTypeBinOpExpr);
......@@ -4721,73 +5754,73 @@ static IrInstruction *ir_gen_orelse(IrBuilder *irb, Scope *parent_scope, AstNode
47215754 AstNode *op1_node = node->data.bin_op_expr.op1;
47225755 AstNode *op2_node = node->data.bin_op_expr.op2;
47235756
4724 IrInstruction *maybe_ptr = ir_gen_node_extra(irb, op1_node, parent_scope, LValPtr, nullptr);
4725 if (maybe_ptr == irb->codegen->invalid_instruction)
4726 return irb->codegen->invalid_instruction;
5757 IrInstSrc *maybe_ptr = ir_gen_node_extra(irb, op1_node, parent_scope, LValPtr, nullptr);
5758 if (maybe_ptr == irb->codegen->invalid_inst_src)
5759 return irb->codegen->invalid_inst_src;
47275760
4728 IrInstruction *maybe_val = ir_build_load_ptr(irb, parent_scope, node, maybe_ptr);
4729 IrInstruction *is_non_null = ir_build_test_nonnull(irb, parent_scope, node, maybe_val);
5761 IrInstSrc *maybe_val = ir_build_load_ptr(irb, parent_scope, node, maybe_ptr);
5762 IrInstSrc *is_non_null = ir_build_test_non_null_src(irb, parent_scope, node, maybe_val);
47305763
4731 IrInstruction *is_comptime;
5764 IrInstSrc *is_comptime;
47325765 if (ir_should_inline(irb->exec, parent_scope)) {
47335766 is_comptime = ir_build_const_bool(irb, parent_scope, node, true);
47345767 } else {
47355768 is_comptime = ir_build_test_comptime(irb, parent_scope, node, is_non_null);
47365769 }
47375770
4738 IrBasicBlock *ok_block = ir_create_basic_block(irb, parent_scope, "OptionalNonNull");
4739 IrBasicBlock *null_block = ir_create_basic_block(irb, parent_scope, "OptionalNull");
4740 IrBasicBlock *end_block = ir_create_basic_block(irb, parent_scope, "OptionalEnd");
4741 IrInstruction *cond_br_inst = ir_build_cond_br(irb, parent_scope, node, is_non_null, ok_block, null_block, is_comptime);
5771 IrBasicBlockSrc *ok_block = ir_create_basic_block(irb, parent_scope, "OptionalNonNull");
5772 IrBasicBlockSrc *null_block = ir_create_basic_block(irb, parent_scope, "OptionalNull");
5773 IrBasicBlockSrc *end_block = ir_create_basic_block(irb, parent_scope, "OptionalEnd");
5774 IrInstSrc *cond_br_inst = ir_build_cond_br(irb, parent_scope, node, is_non_null, ok_block, null_block, is_comptime);
47425775
47435776 ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, ok_block, end_block,
47445777 result_loc, is_comptime);
47455778
47465779 ir_set_cursor_at_end_and_append_block(irb, null_block);
4747 IrInstruction *null_result = ir_gen_node_extra(irb, op2_node, parent_scope, LValNone,
5780 IrInstSrc *null_result = ir_gen_node_extra(irb, op2_node, parent_scope, LValNone,
47485781 &peer_parent->peers.at(0)->base);
4749 if (null_result == irb->codegen->invalid_instruction)
4750 return irb->codegen->invalid_instruction;
4751 IrBasicBlock *after_null_block = irb->current_basic_block;
5782 if (null_result == irb->codegen->invalid_inst_src)
5783 return irb->codegen->invalid_inst_src;
5784 IrBasicBlockSrc *after_null_block = irb->current_basic_block;
47525785 if (!instr_is_unreachable(null_result))
47535786 ir_mark_gen(ir_build_br(irb, parent_scope, node, end_block, is_comptime));
47545787
47555788 ir_set_cursor_at_end_and_append_block(irb, ok_block);
4756 IrInstruction *unwrapped_ptr = ir_build_optional_unwrap_ptr(irb, parent_scope, node, maybe_ptr, false, false);
4757 IrInstruction *unwrapped_payload = ir_build_load_ptr(irb, parent_scope, node, unwrapped_ptr);
5789 IrInstSrc *unwrapped_ptr = ir_build_optional_unwrap_ptr(irb, parent_scope, node, maybe_ptr, false, false);
5790 IrInstSrc *unwrapped_payload = ir_build_load_ptr(irb, parent_scope, node, unwrapped_ptr);
47585791 ir_build_end_expr(irb, parent_scope, node, unwrapped_payload, &peer_parent->peers.at(1)->base);
4759 IrBasicBlock *after_ok_block = irb->current_basic_block;
5792 IrBasicBlockSrc *after_ok_block = irb->current_basic_block;
47605793 ir_build_br(irb, parent_scope, node, end_block, is_comptime);
47615794
47625795 ir_set_cursor_at_end_and_append_block(irb, end_block);
4763 IrInstruction **incoming_values = allocate<IrInstruction *>(2);
5796 IrInstSrc **incoming_values = allocate<IrInstSrc *>(2);
47645797 incoming_values[0] = null_result;
47655798 incoming_values[1] = unwrapped_payload;
4766 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *");
5799 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
47675800 incoming_blocks[0] = after_null_block;
47685801 incoming_blocks[1] = after_ok_block;
4769 IrInstruction *phi = ir_build_phi(irb, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent);
5802 IrInstSrc *phi = ir_build_phi(irb, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent);
47705803 return ir_lval_wrap(irb, parent_scope, phi, lval, result_loc);
47715804}
47725805
4773static IrInstruction *ir_gen_error_union(IrBuilder *irb, Scope *parent_scope, AstNode *node) {
5806static IrInstSrc *ir_gen_error_union(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) {
47745807 assert(node->type == NodeTypeBinOpExpr);
47755808
47765809 AstNode *op1_node = node->data.bin_op_expr.op1;
47775810 AstNode *op2_node = node->data.bin_op_expr.op2;
47785811
4779 IrInstruction *err_set = ir_gen_node(irb, op1_node, parent_scope);
4780 if (err_set == irb->codegen->invalid_instruction)
4781 return irb->codegen->invalid_instruction;
5812 IrInstSrc *err_set = ir_gen_node(irb, op1_node, parent_scope);
5813 if (err_set == irb->codegen->invalid_inst_src)
5814 return irb->codegen->invalid_inst_src;
47825815
4783 IrInstruction *payload = ir_gen_node(irb, op2_node, parent_scope);
4784 if (payload == irb->codegen->invalid_instruction)
4785 return irb->codegen->invalid_instruction;
5816 IrInstSrc *payload = ir_gen_node(irb, op2_node, parent_scope);
5817 if (payload == irb->codegen->invalid_inst_src)
5818 return irb->codegen->invalid_inst_src;
47865819
47875820 return ir_build_error_union(irb, parent_scope, node, err_set, payload);
47885821}
47895822
4790static IrInstruction *ir_gen_bin_op(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) {
5823static IrInstSrc *ir_gen_bin_op(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) {
47915824 assert(node->type == NodeTypeBinOpExpr);
47925825
47935826 BinOpType bin_op_type = node->data.bin_op_expr.bin_op;
......@@ -4880,30 +5913,30 @@ static IrInstruction *ir_gen_bin_op(IrBuilder *irb, Scope *scope, AstNode *node,
48805913 zig_unreachable();
48815914}
48825915
4883static IrInstruction *ir_gen_int_lit(IrBuilder *irb, Scope *scope, AstNode *node) {
5916static IrInstSrc *ir_gen_int_lit(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
48845917 assert(node->type == NodeTypeIntLiteral);
48855918
48865919 return ir_build_const_bigint(irb, scope, node, node->data.int_literal.bigint);
48875920}
48885921
4889static IrInstruction *ir_gen_float_lit(IrBuilder *irb, Scope *scope, AstNode *node) {
5922static IrInstSrc *ir_gen_float_lit(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
48905923 assert(node->type == NodeTypeFloatLiteral);
48915924
48925925 if (node->data.float_literal.overflow) {
48935926 add_node_error(irb->codegen, node, buf_sprintf("float literal out of range of any type"));
4894 return irb->codegen->invalid_instruction;
5927 return irb->codegen->invalid_inst_src;
48955928 }
48965929
48975930 return ir_build_const_bigfloat(irb, scope, node, node->data.float_literal.bigfloat);
48985931}
48995932
4900static IrInstruction *ir_gen_char_lit(IrBuilder *irb, Scope *scope, AstNode *node) {
5933static IrInstSrc *ir_gen_char_lit(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
49015934 assert(node->type == NodeTypeCharLiteral);
49025935
49035936 return ir_build_const_uint(irb, scope, node, node->data.char_literal.value);
49045937}
49055938
4906static IrInstruction *ir_gen_null_literal(IrBuilder *irb, Scope *scope, AstNode *node) {
5939static IrInstSrc *ir_gen_null_literal(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
49075940 assert(node->type == NodeTypeNullLiteral);
49085941
49095942 return ir_build_const_null(irb, scope, node);
......@@ -4921,11 +5954,11 @@ static void populate_invalid_variable_in_scope(CodeGen *g, Scope *scope, AstNode
49215954 init_tld(&tld_var->base, TldIdVar, var_name, VisibModPub, node, &scope_decls->base);
49225955 tld_var->base.resolution = TldResolutionInvalid;
49235956 tld_var->var = add_variable(g, node, &scope_decls->base, var_name, false,
4924 g->invalid_instruction->value, &tld_var->base, g->builtin_types.entry_invalid);
5957 g->invalid_inst_gen->value, &tld_var->base, g->builtin_types.entry_invalid);
49255958 scope_decls->decl_table.put(var_name, &tld_var->base);
49265959}
49275960
4928static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) {
5961static IrInstSrc *ir_gen_symbol(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) {
49295962 Error err;
49305963 assert(node->type == NodeTypeSymbol);
49315964
......@@ -4933,15 +5966,16 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
49335966
49345967 if (buf_eql_str(variable_name, "_")) {
49355968 if (lval == LValPtr) {
4936 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, node);
4937 const_instruction->base.value->type = get_pointer_to_type(irb->codegen,
5969 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, node);
5970 const_instruction->value = create_const_vals(1);
5971 const_instruction->value->type = get_pointer_to_type(irb->codegen,
49385972 irb->codegen->builtin_types.entry_void, false);
4939 const_instruction->base.value->special = ConstValSpecialStatic;
4940 const_instruction->base.value->data.x_ptr.special = ConstPtrSpecialDiscard;
5973 const_instruction->value->special = ConstValSpecialStatic;
5974 const_instruction->value->data.x_ptr.special = ConstPtrSpecialDiscard;
49415975 return &const_instruction->base;
49425976 } else {
49435977 add_node_error(irb->codegen, node, buf_sprintf("`_` may only be used to assign things to"));
4944 return irb->codegen->invalid_instruction;
5978 return irb->codegen->invalid_inst_src;
49455979 }
49465980 }
49475981
......@@ -4951,13 +5985,13 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
49515985 add_node_error(irb->codegen, node,
49525986 buf_sprintf("primitive integer type '%s' exceeds maximum bit width of 65535",
49535987 buf_ptr(variable_name)));
4954 return irb->codegen->invalid_instruction;
5988 return irb->codegen->invalid_inst_src;
49555989 }
49565990 assert(err == ErrorPrimitiveTypeNotFound);
49575991 } else {
4958 IrInstruction *value = ir_build_const_type(irb, scope, node, primitive_type);
5992 IrInstSrc *value = ir_build_const_type(irb, scope, node, primitive_type);
49595993 if (lval == LValPtr) {
4960 return ir_build_ref(irb, scope, node, value, false, false);
5994 return ir_build_ref_src(irb, scope, node, value, false, false);
49615995 } else {
49625996 return ir_expr_wrap(irb, scope, value, result_loc);
49635997 }
......@@ -4966,7 +6000,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
49666000 ScopeFnDef *crossed_fndef_scope;
49676001 ZigVar *var = find_variable(irb->codegen, scope, variable_name, &crossed_fndef_scope);
49686002 if (var) {
4969 IrInstruction *var_ptr = ir_build_var_ptr_x(irb, scope, node, var, crossed_fndef_scope);
6003 IrInstSrc *var_ptr = ir_build_var_ptr_x(irb, scope, node, var, crossed_fndef_scope);
49706004 if (lval == LValPtr) {
49716005 return var_ptr;
49726006 } else {
......@@ -4976,7 +6010,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
49766010
49776011 Tld *tld = find_decl(irb->codegen, scope, variable_name);
49786012 if (tld) {
4979 IrInstruction *decl_ref = ir_build_decl_ref(irb, scope, node, tld, lval);
6013 IrInstSrc *decl_ref = ir_build_decl_ref(irb, scope, node, tld, lval);
49806014 if (lval == LValPtr) {
49816015 return decl_ref;
49826016 } else {
......@@ -4987,50 +6021,50 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
49876021 if (get_container_scope(node->owner)->any_imports_failed) {
49886022 // skip the error message since we had a failing import in this file
49896023 // if an import breaks we don't need redundant undeclared identifier errors
4990 return irb->codegen->invalid_instruction;
6024 return irb->codegen->invalid_inst_src;
49916025 }
49926026
49936027 return ir_build_undeclared_identifier(irb, scope, node, variable_name);
49946028}
49956029
4996static IrInstruction *ir_gen_array_access(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,
6030static IrInstSrc *ir_gen_array_access(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
49976031 ResultLoc *result_loc)
49986032{
49996033 assert(node->type == NodeTypeArrayAccessExpr);
50006034
50016035 AstNode *array_ref_node = node->data.array_access_expr.array_ref_expr;
5002 IrInstruction *array_ref_instruction = ir_gen_node_extra(irb, array_ref_node, scope, LValPtr, nullptr);
5003 if (array_ref_instruction == irb->codegen->invalid_instruction)
6036 IrInstSrc *array_ref_instruction = ir_gen_node_extra(irb, array_ref_node, scope, LValPtr, nullptr);
6037 if (array_ref_instruction == irb->codegen->invalid_inst_src)
50046038 return array_ref_instruction;
50056039
50066040 AstNode *subscript_node = node->data.array_access_expr.subscript;
5007 IrInstruction *subscript_instruction = ir_gen_node(irb, subscript_node, scope);
5008 if (subscript_instruction == irb->codegen->invalid_instruction)
6041 IrInstSrc *subscript_instruction = ir_gen_node(irb, subscript_node, scope);
6042 if (subscript_instruction == irb->codegen->invalid_inst_src)
50096043 return subscript_instruction;
50106044
5011 IrInstruction *ptr_instruction = ir_build_elem_ptr(irb, scope, node, array_ref_instruction,
6045 IrInstSrc *ptr_instruction = ir_build_elem_ptr(irb, scope, node, array_ref_instruction,
50126046 subscript_instruction, true, PtrLenSingle, nullptr);
50136047 if (lval == LValPtr)
50146048 return ptr_instruction;
50156049
5016 IrInstruction *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction);
6050 IrInstSrc *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction);
50176051 return ir_expr_wrap(irb, scope, load_ptr, result_loc);
50186052}
50196053
5020static IrInstruction *ir_gen_field_access(IrBuilder *irb, Scope *scope, AstNode *node) {
6054static IrInstSrc *ir_gen_field_access(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
50216055 assert(node->type == NodeTypeFieldAccessExpr);
50226056
50236057 AstNode *container_ref_node = node->data.field_access_expr.struct_expr;
50246058 Buf *field_name = node->data.field_access_expr.field_name;
50256059
5026 IrInstruction *container_ref_instruction = ir_gen_node_extra(irb, container_ref_node, scope, LValPtr, nullptr);
5027 if (container_ref_instruction == irb->codegen->invalid_instruction)
6060 IrInstSrc *container_ref_instruction = ir_gen_node_extra(irb, container_ref_node, scope, LValPtr, nullptr);
6061 if (container_ref_instruction == irb->codegen->invalid_inst_src)
50286062 return container_ref_instruction;
50296063
50306064 return ir_build_field_ptr(irb, scope, node, container_ref_instruction, field_name, false);
50316065}
50326066
5033static IrInstruction *ir_gen_overflow_op(IrBuilder *irb, Scope *scope, AstNode *node, IrOverflowOp op) {
6067static IrInstSrc *ir_gen_overflow_op(IrBuilderSrc *irb, Scope *scope, AstNode *node, IrOverflowOp op) {
50346068 assert(node->type == NodeTypeFnCallExpr);
50356069
50366070 AstNode *type_node = node->data.fn_call_expr.params.at(0);
......@@ -5039,26 +6073,26 @@ static IrInstruction *ir_gen_overflow_op(IrBuilder *irb, Scope *scope, AstNode *
50396073 AstNode *result_ptr_node = node->data.fn_call_expr.params.at(3);
50406074
50416075
5042 IrInstruction *type_value = ir_gen_node(irb, type_node, scope);
5043 if (type_value == irb->codegen->invalid_instruction)
5044 return irb->codegen->invalid_instruction;
6076 IrInstSrc *type_value = ir_gen_node(irb, type_node, scope);
6077 if (type_value == irb->codegen->invalid_inst_src)
6078 return irb->codegen->invalid_inst_src;
50456079
5046 IrInstruction *op1 = ir_gen_node(irb, op1_node, scope);
5047 if (op1 == irb->codegen->invalid_instruction)
5048 return irb->codegen->invalid_instruction;
6080 IrInstSrc *op1 = ir_gen_node(irb, op1_node, scope);
6081 if (op1 == irb->codegen->invalid_inst_src)
6082 return irb->codegen->invalid_inst_src;
50496083
5050 IrInstruction *op2 = ir_gen_node(irb, op2_node, scope);
5051 if (op2 == irb->codegen->invalid_instruction)
5052 return irb->codegen->invalid_instruction;
6084 IrInstSrc *op2 = ir_gen_node(irb, op2_node, scope);
6085 if (op2 == irb->codegen->invalid_inst_src)
6086 return irb->codegen->invalid_inst_src;
50536087
5054 IrInstruction *result_ptr = ir_gen_node(irb, result_ptr_node, scope);
5055 if (result_ptr == irb->codegen->invalid_instruction)
5056 return irb->codegen->invalid_instruction;
6088 IrInstSrc *result_ptr = ir_gen_node(irb, result_ptr_node, scope);
6089 if (result_ptr == irb->codegen->invalid_inst_src)
6090 return irb->codegen->invalid_inst_src;
50576091
5058 return ir_build_overflow_op(irb, scope, node, op, type_value, op1, op2, result_ptr, nullptr);
6092 return ir_build_overflow_op_src(irb, scope, node, op, type_value, op1, op2, result_ptr);
50596093}
50606094
5061static IrInstruction *ir_gen_mul_add(IrBuilder *irb, Scope *scope, AstNode *node) {
6095static IrInstSrc *ir_gen_mul_add(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
50626096 assert(node->type == NodeTypeFnCallExpr);
50636097
50646098 AstNode *type_node = node->data.fn_call_expr.params.at(0);
......@@ -5066,26 +6100,26 @@ static IrInstruction *ir_gen_mul_add(IrBuilder *irb, Scope *scope, AstNode *node
50666100 AstNode *op2_node = node->data.fn_call_expr.params.at(2);
50676101 AstNode *op3_node = node->data.fn_call_expr.params.at(3);
50686102
5069 IrInstruction *type_value = ir_gen_node(irb, type_node, scope);
5070 if (type_value == irb->codegen->invalid_instruction)
5071 return irb->codegen->invalid_instruction;
6103 IrInstSrc *type_value = ir_gen_node(irb, type_node, scope);
6104 if (type_value == irb->codegen->invalid_inst_src)
6105 return irb->codegen->invalid_inst_src;
50726106
5073 IrInstruction *op1 = ir_gen_node(irb, op1_node, scope);
5074 if (op1 == irb->codegen->invalid_instruction)
5075 return irb->codegen->invalid_instruction;
6107 IrInstSrc *op1 = ir_gen_node(irb, op1_node, scope);
6108 if (op1 == irb->codegen->invalid_inst_src)
6109 return irb->codegen->invalid_inst_src;
50766110
5077 IrInstruction *op2 = ir_gen_node(irb, op2_node, scope);
5078 if (op2 == irb->codegen->invalid_instruction)
5079 return irb->codegen->invalid_instruction;
6111 IrInstSrc *op2 = ir_gen_node(irb, op2_node, scope);
6112 if (op2 == irb->codegen->invalid_inst_src)
6113 return irb->codegen->invalid_inst_src;
50806114
5081 IrInstruction *op3 = ir_gen_node(irb, op3_node, scope);
5082 if (op3 == irb->codegen->invalid_instruction)
5083 return irb->codegen->invalid_instruction;
6115 IrInstSrc *op3 = ir_gen_node(irb, op3_node, scope);
6116 if (op3 == irb->codegen->invalid_inst_src)
6117 return irb->codegen->invalid_inst_src;
50846118
5085 return ir_build_mul_add(irb, scope, node, type_value, op1, op2, op3);
6119 return ir_build_mul_add_src(irb, scope, node, type_value, op1, op2, op3);
50866120}
50876121
5088static IrInstruction *ir_gen_this(IrBuilder *irb, Scope *orig_scope, AstNode *node) {
6122static IrInstSrc *ir_gen_this(IrBuilderSrc *irb, Scope *orig_scope, AstNode *node) {
50896123 for (Scope *it_scope = orig_scope; it_scope != nullptr; it_scope = it_scope->parent) {
50906124 if (it_scope->id == ScopeIdDecls) {
50916125 ScopeDecls *decls_scope = (ScopeDecls *)it_scope;
......@@ -5100,7 +6134,7 @@ static IrInstruction *ir_gen_this(IrBuilder *irb, Scope *orig_scope, AstNode *no
51006134 zig_unreachable();
51016135}
51026136
5103static IrInstruction *ir_gen_async_call(IrBuilder *irb, Scope *scope, AstNode *await_node, AstNode *call_node,
6137static IrInstSrc *ir_gen_async_call(IrBuilderSrc *irb, Scope *scope, AstNode *await_node, AstNode *call_node,
51046138 LVal lval, ResultLoc *result_loc)
51056139{
51066140 size_t arg_offset = 3;
......@@ -5108,71 +6142,71 @@ static IrInstruction *ir_gen_async_call(IrBuilder *irb, Scope *scope, AstNode *a
51086142 add_node_error(irb->codegen, call_node,
51096143 buf_sprintf("expected at least %" ZIG_PRI_usize " arguments, found %" ZIG_PRI_usize,
51106144 arg_offset, call_node->data.fn_call_expr.params.length));
5111 return irb->codegen->invalid_instruction;
6145 return irb->codegen->invalid_inst_src;
51126146 }
51136147
51146148 AstNode *bytes_node = call_node->data.fn_call_expr.params.at(0);
5115 IrInstruction *bytes = ir_gen_node(irb, bytes_node, scope);
5116 if (bytes == irb->codegen->invalid_instruction)
6149 IrInstSrc *bytes = ir_gen_node(irb, bytes_node, scope);
6150 if (bytes == irb->codegen->invalid_inst_src)
51176151 return bytes;
51186152
51196153 AstNode *ret_ptr_node = call_node->data.fn_call_expr.params.at(1);
5120 IrInstruction *ret_ptr = ir_gen_node(irb, ret_ptr_node, scope);
5121 if (ret_ptr == irb->codegen->invalid_instruction)
6154 IrInstSrc *ret_ptr = ir_gen_node(irb, ret_ptr_node, scope);
6155 if (ret_ptr == irb->codegen->invalid_inst_src)
51226156 return ret_ptr;
51236157
51246158 AstNode *fn_ref_node = call_node->data.fn_call_expr.params.at(2);
5125 IrInstruction *fn_ref = ir_gen_node(irb, fn_ref_node, scope);
5126 if (fn_ref == irb->codegen->invalid_instruction)
6159 IrInstSrc *fn_ref = ir_gen_node(irb, fn_ref_node, scope);
6160 if (fn_ref == irb->codegen->invalid_inst_src)
51276161 return fn_ref;
51286162
51296163 size_t arg_count = call_node->data.fn_call_expr.params.length - arg_offset;
5130 IrInstruction **args = allocate<IrInstruction*>(arg_count);
6164 IrInstSrc **args = allocate<IrInstSrc*>(arg_count);
51316165 for (size_t i = 0; i < arg_count; i += 1) {
51326166 AstNode *arg_node = call_node->data.fn_call_expr.params.at(i + arg_offset);
5133 IrInstruction *arg = ir_gen_node(irb, arg_node, scope);
5134 if (arg == irb->codegen->invalid_instruction)
6167 IrInstSrc *arg = ir_gen_node(irb, arg_node, scope);
6168 if (arg == irb->codegen->invalid_inst_src)
51356169 return arg;
51366170 args[i] = arg;
51376171 }
51386172
51396173 CallModifier modifier = (await_node == nullptr) ? CallModifierAsync : CallModifierNone;
51406174 bool is_async_call_builtin = true;
5141 IrInstruction *call = ir_build_call_src(irb, scope, call_node, nullptr, fn_ref, arg_count, args,
6175 IrInstSrc *call = ir_build_call_src(irb, scope, call_node, nullptr, fn_ref, arg_count, args,
51426176 ret_ptr, modifier, is_async_call_builtin, bytes, result_loc);
51436177 return ir_lval_wrap(irb, scope, call, lval, result_loc);
51446178}
51456179
5146static IrInstruction *ir_gen_fn_call_with_args(IrBuilder *irb, Scope *scope, AstNode *source_node,
5147 AstNode *fn_ref_node, CallModifier modifier, IrInstruction *options,
6180static IrInstSrc *ir_gen_fn_call_with_args(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
6181 AstNode *fn_ref_node, CallModifier modifier, IrInstSrc *options,
51486182 AstNode **args_ptr, size_t args_len, LVal lval, ResultLoc *result_loc)
51496183{
5150 IrInstruction *fn_ref = ir_gen_node(irb, fn_ref_node, scope);
5151 if (fn_ref == irb->codegen->invalid_instruction)
6184 IrInstSrc *fn_ref = ir_gen_node(irb, fn_ref_node, scope);
6185 if (fn_ref == irb->codegen->invalid_inst_src)
51526186 return fn_ref;
51536187
5154 IrInstruction *fn_type = ir_build_typeof(irb, scope, source_node, fn_ref);
6188 IrInstSrc *fn_type = ir_build_typeof(irb, scope, source_node, fn_ref);
51556189
5156 IrInstruction **args = allocate<IrInstruction*>(args_len);
6190 IrInstSrc **args = allocate<IrInstSrc*>(args_len);
51576191 for (size_t i = 0; i < args_len; i += 1) {
51586192 AstNode *arg_node = args_ptr[i];
51596193
5160 IrInstruction *arg_index = ir_build_const_usize(irb, scope, arg_node, i);
5161 IrInstruction *arg_type = ir_build_arg_type(irb, scope, source_node, fn_type, arg_index, true);
6194 IrInstSrc *arg_index = ir_build_const_usize(irb, scope, arg_node, i);
6195 IrInstSrc *arg_type = ir_build_arg_type(irb, scope, source_node, fn_type, arg_index, true);
51626196 ResultLoc *no_result = no_result_loc();
51636197 ir_build_reset_result(irb, scope, source_node, no_result);
51646198 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, arg_type, no_result);
51656199
5166 IrInstruction *arg = ir_gen_node_extra(irb, arg_node, scope, LValNone, &result_loc_cast->base);
5167 if (arg == irb->codegen->invalid_instruction)
6200 IrInstSrc *arg = ir_gen_node_extra(irb, arg_node, scope, LValNone, &result_loc_cast->base);
6201 if (arg == irb->codegen->invalid_inst_src)
51686202 return arg;
51696203
51706204 args[i] = ir_build_implicit_cast(irb, scope, arg_node, arg, result_loc_cast);
51716205 }
51726206
5173 IrInstruction *fn_call;
6207 IrInstSrc *fn_call;
51746208 if (options != nullptr) {
5175 fn_call = ir_build_call_src_args(irb, scope, source_node, options, fn_ref, args, args_len, result_loc);
6209 fn_call = ir_build_call_args(irb, scope, source_node, options, fn_ref, args, args_len, result_loc);
51766210 } else {
51776211 fn_call = ir_build_call_src(irb, scope, source_node, nullptr, fn_ref, args_len, args, nullptr,
51786212 modifier, false, nullptr, result_loc);
......@@ -5180,7 +6214,7 @@ static IrInstruction *ir_gen_fn_call_with_args(IrBuilder *irb, Scope *scope, Ast
51806214 return ir_lval_wrap(irb, scope, fn_call, lval, result_loc);
51816215}
51826216
5183static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,
6217static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
51846218 ResultLoc *result_loc)
51856219{
51866220 assert(node->type == NodeTypeFnCallExpr);
......@@ -5192,7 +6226,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
51926226 if (!entry) {
51936227 add_node_error(irb->codegen, node,
51946228 buf_sprintf("invalid builtin function: '%s'", buf_ptr(name)));
5195 return irb->codegen->invalid_instruction;
6229 return irb->codegen->invalid_inst_src;
51966230 }
51976231
51986232 BuiltinFnEntry *builtin_fn = entry->value;
......@@ -5202,7 +6236,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
52026236 add_node_error(irb->codegen, node,
52036237 buf_sprintf("expected %" ZIG_PRI_usize " arguments, found %" ZIG_PRI_usize,
52046238 builtin_fn->param_count, actual_param_count));
5205 return irb->codegen->invalid_instruction;
6239 return irb->codegen->invalid_inst_src;
52066240 }
52076241
52086242 switch (builtin_fn->id) {
......@@ -5213,197 +6247,197 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
52136247 Scope *sub_scope = create_typeof_scope(irb->codegen, node, scope);
52146248
52156249 AstNode *arg_node = node->data.fn_call_expr.params.at(0);
5216 IrInstruction *arg = ir_gen_node(irb, arg_node, sub_scope);
5217 if (arg == irb->codegen->invalid_instruction)
6250 IrInstSrc *arg = ir_gen_node(irb, arg_node, sub_scope);
6251 if (arg == irb->codegen->invalid_inst_src)
52186252 return arg;
52196253
5220 IrInstruction *type_of = ir_build_typeof(irb, scope, node, arg);
6254 IrInstSrc *type_of = ir_build_typeof(irb, scope, node, arg);
52216255 return ir_lval_wrap(irb, scope, type_of, lval, result_loc);
52226256 }
52236257 case BuiltinFnIdSetCold:
52246258 {
52256259 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5226 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5227 if (arg0_value == irb->codegen->invalid_instruction)
6260 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6261 if (arg0_value == irb->codegen->invalid_inst_src)
52286262 return arg0_value;
52296263
5230 IrInstruction *set_cold = ir_build_set_cold(irb, scope, node, arg0_value);
6264 IrInstSrc *set_cold = ir_build_set_cold(irb, scope, node, arg0_value);
52316265 return ir_lval_wrap(irb, scope, set_cold, lval, result_loc);
52326266 }
52336267 case BuiltinFnIdSetRuntimeSafety:
52346268 {
52356269 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5236 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5237 if (arg0_value == irb->codegen->invalid_instruction)
6270 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6271 if (arg0_value == irb->codegen->invalid_inst_src)
52386272 return arg0_value;
52396273
5240 IrInstruction *set_safety = ir_build_set_runtime_safety(irb, scope, node, arg0_value);
6274 IrInstSrc *set_safety = ir_build_set_runtime_safety(irb, scope, node, arg0_value);
52416275 return ir_lval_wrap(irb, scope, set_safety, lval, result_loc);
52426276 }
52436277 case BuiltinFnIdSetFloatMode:
52446278 {
52456279 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5246 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5247 if (arg0_value == irb->codegen->invalid_instruction)
6280 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6281 if (arg0_value == irb->codegen->invalid_inst_src)
52486282 return arg0_value;
52496283
5250 IrInstruction *set_float_mode = ir_build_set_float_mode(irb, scope, node, arg0_value);
6284 IrInstSrc *set_float_mode = ir_build_set_float_mode(irb, scope, node, arg0_value);
52516285 return ir_lval_wrap(irb, scope, set_float_mode, lval, result_loc);
52526286 }
52536287 case BuiltinFnIdSizeof:
52546288 case BuiltinFnIdBitSizeof:
52556289 {
52566290 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5257 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5258 if (arg0_value == irb->codegen->invalid_instruction)
6291 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6292 if (arg0_value == irb->codegen->invalid_inst_src)
52596293 return arg0_value;
52606294
5261 IrInstruction *size_of = ir_build_size_of(irb, scope, node, arg0_value, builtin_fn->id == BuiltinFnIdBitSizeof);
6295 IrInstSrc *size_of = ir_build_size_of(irb, scope, node, arg0_value, builtin_fn->id == BuiltinFnIdBitSizeof);
52626296 return ir_lval_wrap(irb, scope, size_of, lval, result_loc);
52636297 }
52646298 case BuiltinFnIdImport:
52656299 {
52666300 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5267 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5268 if (arg0_value == irb->codegen->invalid_instruction)
6301 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6302 if (arg0_value == irb->codegen->invalid_inst_src)
52696303 return arg0_value;
52706304
5271 IrInstruction *import = ir_build_import(irb, scope, node, arg0_value);
6305 IrInstSrc *import = ir_build_import(irb, scope, node, arg0_value);
52726306 return ir_lval_wrap(irb, scope, import, lval, result_loc);
52736307 }
52746308 case BuiltinFnIdCImport:
52756309 {
5276 IrInstruction *c_import = ir_build_c_import(irb, scope, node);
6310 IrInstSrc *c_import = ir_build_c_import(irb, scope, node);
52776311 return ir_lval_wrap(irb, scope, c_import, lval, result_loc);
52786312 }
52796313 case BuiltinFnIdCInclude:
52806314 {
52816315 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5282 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5283 if (arg0_value == irb->codegen->invalid_instruction)
6316 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6317 if (arg0_value == irb->codegen->invalid_inst_src)
52846318 return arg0_value;
52856319
52866320 if (!exec_c_import_buf(irb->exec)) {
52876321 add_node_error(irb->codegen, node, buf_sprintf("C include valid only inside C import block"));
5288 return irb->codegen->invalid_instruction;
6322 return irb->codegen->invalid_inst_src;
52896323 }
52906324
5291 IrInstruction *c_include = ir_build_c_include(irb, scope, node, arg0_value);
6325 IrInstSrc *c_include = ir_build_c_include(irb, scope, node, arg0_value);
52926326 return ir_lval_wrap(irb, scope, c_include, lval, result_loc);
52936327 }
52946328 case BuiltinFnIdCDefine:
52956329 {
52966330 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5297 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5298 if (arg0_value == irb->codegen->invalid_instruction)
6331 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6332 if (arg0_value == irb->codegen->invalid_inst_src)
52996333 return arg0_value;
53006334
53016335 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5302 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5303 if (arg1_value == irb->codegen->invalid_instruction)
6336 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6337 if (arg1_value == irb->codegen->invalid_inst_src)
53046338 return arg1_value;
53056339
53066340 if (!exec_c_import_buf(irb->exec)) {
53076341 add_node_error(irb->codegen, node, buf_sprintf("C define valid only inside C import block"));
5308 return irb->codegen->invalid_instruction;
6342 return irb->codegen->invalid_inst_src;
53096343 }
53106344
5311 IrInstruction *c_define = ir_build_c_define(irb, scope, node, arg0_value, arg1_value);
6345 IrInstSrc *c_define = ir_build_c_define(irb, scope, node, arg0_value, arg1_value);
53126346 return ir_lval_wrap(irb, scope, c_define, lval, result_loc);
53136347 }
53146348 case BuiltinFnIdCUndef:
53156349 {
53166350 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5317 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5318 if (arg0_value == irb->codegen->invalid_instruction)
6351 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6352 if (arg0_value == irb->codegen->invalid_inst_src)
53196353 return arg0_value;
53206354
53216355 if (!exec_c_import_buf(irb->exec)) {
53226356 add_node_error(irb->codegen, node, buf_sprintf("C undef valid only inside C import block"));
5323 return irb->codegen->invalid_instruction;
6357 return irb->codegen->invalid_inst_src;
53246358 }
53256359
5326 IrInstruction *c_undef = ir_build_c_undef(irb, scope, node, arg0_value);
6360 IrInstSrc *c_undef = ir_build_c_undef(irb, scope, node, arg0_value);
53276361 return ir_lval_wrap(irb, scope, c_undef, lval, result_loc);
53286362 }
53296363 case BuiltinFnIdCompileErr:
53306364 {
53316365 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5332 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5333 if (arg0_value == irb->codegen->invalid_instruction)
6366 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6367 if (arg0_value == irb->codegen->invalid_inst_src)
53346368 return arg0_value;
53356369
5336 IrInstruction *compile_err = ir_build_compile_err(irb, scope, node, arg0_value);
6370 IrInstSrc *compile_err = ir_build_compile_err(irb, scope, node, arg0_value);
53376371 return ir_lval_wrap(irb, scope, compile_err, lval, result_loc);
53386372 }
53396373 case BuiltinFnIdCompileLog:
53406374 {
5341 IrInstruction **args = allocate<IrInstruction*>(actual_param_count);
6375 IrInstSrc **args = allocate<IrInstSrc*>(actual_param_count);
53426376
53436377 for (size_t i = 0; i < actual_param_count; i += 1) {
53446378 AstNode *arg_node = node->data.fn_call_expr.params.at(i);
53456379 args[i] = ir_gen_node(irb, arg_node, scope);
5346 if (args[i] == irb->codegen->invalid_instruction)
5347 return irb->codegen->invalid_instruction;
6380 if (args[i] == irb->codegen->invalid_inst_src)
6381 return irb->codegen->invalid_inst_src;
53486382 }
53496383
5350 IrInstruction *compile_log = ir_build_compile_log(irb, scope, node, actual_param_count, args);
6384 IrInstSrc *compile_log = ir_build_compile_log(irb, scope, node, actual_param_count, args);
53516385 return ir_lval_wrap(irb, scope, compile_log, lval, result_loc);
53526386 }
53536387 case BuiltinFnIdErrName:
53546388 {
53556389 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5356 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5357 if (arg0_value == irb->codegen->invalid_instruction)
6390 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6391 if (arg0_value == irb->codegen->invalid_inst_src)
53586392 return arg0_value;
53596393
5360 IrInstruction *err_name = ir_build_err_name(irb, scope, node, arg0_value);
6394 IrInstSrc *err_name = ir_build_err_name(irb, scope, node, arg0_value);
53616395 return ir_lval_wrap(irb, scope, err_name, lval, result_loc);
53626396 }
53636397 case BuiltinFnIdEmbedFile:
53646398 {
53656399 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5366 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5367 if (arg0_value == irb->codegen->invalid_instruction)
6400 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6401 if (arg0_value == irb->codegen->invalid_inst_src)
53686402 return arg0_value;
53696403
5370 IrInstruction *embed_file = ir_build_embed_file(irb, scope, node, arg0_value);
6404 IrInstSrc *embed_file = ir_build_embed_file(irb, scope, node, arg0_value);
53716405 return ir_lval_wrap(irb, scope, embed_file, lval, result_loc);
53726406 }
53736407 case BuiltinFnIdCmpxchgWeak:
53746408 case BuiltinFnIdCmpxchgStrong:
53756409 {
53766410 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5377 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5378 if (arg0_value == irb->codegen->invalid_instruction)
6411 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6412 if (arg0_value == irb->codegen->invalid_inst_src)
53796413 return arg0_value;
53806414
53816415 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5382 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5383 if (arg1_value == irb->codegen->invalid_instruction)
6416 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6417 if (arg1_value == irb->codegen->invalid_inst_src)
53846418 return arg1_value;
53856419
53866420 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
5387 IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope);
5388 if (arg2_value == irb->codegen->invalid_instruction)
6421 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
6422 if (arg2_value == irb->codegen->invalid_inst_src)
53896423 return arg2_value;
53906424
53916425 AstNode *arg3_node = node->data.fn_call_expr.params.at(3);
5392 IrInstruction *arg3_value = ir_gen_node(irb, arg3_node, scope);
5393 if (arg3_value == irb->codegen->invalid_instruction)
6426 IrInstSrc *arg3_value = ir_gen_node(irb, arg3_node, scope);
6427 if (arg3_value == irb->codegen->invalid_inst_src)
53946428 return arg3_value;
53956429
53966430 AstNode *arg4_node = node->data.fn_call_expr.params.at(4);
5397 IrInstruction *arg4_value = ir_gen_node(irb, arg4_node, scope);
5398 if (arg4_value == irb->codegen->invalid_instruction)
6431 IrInstSrc *arg4_value = ir_gen_node(irb, arg4_node, scope);
6432 if (arg4_value == irb->codegen->invalid_inst_src)
53996433 return arg4_value;
54006434
54016435 AstNode *arg5_node = node->data.fn_call_expr.params.at(5);
5402 IrInstruction *arg5_value = ir_gen_node(irb, arg5_node, scope);
5403 if (arg5_value == irb->codegen->invalid_instruction)
6436 IrInstSrc *arg5_value = ir_gen_node(irb, arg5_node, scope);
6437 if (arg5_value == irb->codegen->invalid_inst_src)
54046438 return arg5_value;
54056439
5406 IrInstruction *cmpxchg = ir_build_cmpxchg_src(irb, scope, node, arg0_value, arg1_value,
6440 IrInstSrc *cmpxchg = ir_build_cmpxchg_src(irb, scope, node, arg0_value, arg1_value,
54076441 arg2_value, arg3_value, arg4_value, arg5_value, (builtin_fn->id == BuiltinFnIdCmpxchgWeak),
54086442 result_loc);
54096443 return ir_lval_wrap(irb, scope, cmpxchg, lval, result_loc);
......@@ -5411,86 +6445,86 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
54116445 case BuiltinFnIdFence:
54126446 {
54136447 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5414 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5415 if (arg0_value == irb->codegen->invalid_instruction)
6448 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6449 if (arg0_value == irb->codegen->invalid_inst_src)
54166450 return arg0_value;
54176451
5418 IrInstruction *fence = ir_build_fence(irb, scope, node, arg0_value, AtomicOrderUnordered);
6452 IrInstSrc *fence = ir_build_fence(irb, scope, node, arg0_value);
54196453 return ir_lval_wrap(irb, scope, fence, lval, result_loc);
54206454 }
54216455 case BuiltinFnIdDivExact:
54226456 {
54236457 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5424 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5425 if (arg0_value == irb->codegen->invalid_instruction)
6458 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6459 if (arg0_value == irb->codegen->invalid_inst_src)
54266460 return arg0_value;
54276461
54286462 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5429 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5430 if (arg1_value == irb->codegen->invalid_instruction)
6463 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6464 if (arg1_value == irb->codegen->invalid_inst_src)
54316465 return arg1_value;
54326466
5433 IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivExact, arg0_value, arg1_value, true);
6467 IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivExact, arg0_value, arg1_value, true);
54346468 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);
54356469 }
54366470 case BuiltinFnIdDivTrunc:
54376471 {
54386472 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5439 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5440 if (arg0_value == irb->codegen->invalid_instruction)
6473 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6474 if (arg0_value == irb->codegen->invalid_inst_src)
54416475 return arg0_value;
54426476
54436477 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5444 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5445 if (arg1_value == irb->codegen->invalid_instruction)
6478 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6479 if (arg1_value == irb->codegen->invalid_inst_src)
54466480 return arg1_value;
54476481
5448 IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivTrunc, arg0_value, arg1_value, true);
6482 IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivTrunc, arg0_value, arg1_value, true);
54496483 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);
54506484 }
54516485 case BuiltinFnIdDivFloor:
54526486 {
54536487 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5454 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5455 if (arg0_value == irb->codegen->invalid_instruction)
6488 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6489 if (arg0_value == irb->codegen->invalid_inst_src)
54566490 return arg0_value;
54576491
54586492 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5459 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5460 if (arg1_value == irb->codegen->invalid_instruction)
6493 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6494 if (arg1_value == irb->codegen->invalid_inst_src)
54616495 return arg1_value;
54626496
5463 IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivFloor, arg0_value, arg1_value, true);
6497 IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivFloor, arg0_value, arg1_value, true);
54646498 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);
54656499 }
54666500 case BuiltinFnIdRem:
54676501 {
54686502 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5469 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5470 if (arg0_value == irb->codegen->invalid_instruction)
6503 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6504 if (arg0_value == irb->codegen->invalid_inst_src)
54716505 return arg0_value;
54726506
54736507 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5474 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5475 if (arg1_value == irb->codegen->invalid_instruction)
6508 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6509 if (arg1_value == irb->codegen->invalid_inst_src)
54766510 return arg1_value;
54776511
5478 IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpRemRem, arg0_value, arg1_value, true);
6512 IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpRemRem, arg0_value, arg1_value, true);
54796513 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);
54806514 }
54816515 case BuiltinFnIdMod:
54826516 {
54836517 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5484 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5485 if (arg0_value == irb->codegen->invalid_instruction)
6518 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6519 if (arg0_value == irb->codegen->invalid_inst_src)
54866520 return arg0_value;
54876521
54886522 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5489 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5490 if (arg1_value == irb->codegen->invalid_instruction)
6523 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6524 if (arg1_value == irb->codegen->invalid_inst_src)
54916525 return arg1_value;
54926526
5493 IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpRemMod, arg0_value, arg1_value, true);
6527 IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpRemMod, arg0_value, arg1_value, true);
54946528 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);
54956529 }
54966530 case BuiltinFnIdSqrt:
......@@ -5509,406 +6543,406 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
55096543 case BuiltinFnIdRound:
55106544 {
55116545 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5512 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5513 if (arg0_value == irb->codegen->invalid_instruction)
6546 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6547 if (arg0_value == irb->codegen->invalid_inst_src)
55146548 return arg0_value;
55156549
5516 IrInstruction *inst = ir_build_float_op(irb, scope, node, arg0_value, builtin_fn->id);
6550 IrInstSrc *inst = ir_build_float_op_src(irb, scope, node, arg0_value, builtin_fn->id);
55176551 return ir_lval_wrap(irb, scope, inst, lval, result_loc);
55186552 }
55196553 case BuiltinFnIdTruncate:
55206554 {
55216555 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5522 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5523 if (arg0_value == irb->codegen->invalid_instruction)
6556 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6557 if (arg0_value == irb->codegen->invalid_inst_src)
55246558 return arg0_value;
55256559
55266560 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5527 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5528 if (arg1_value == irb->codegen->invalid_instruction)
6561 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6562 if (arg1_value == irb->codegen->invalid_inst_src)
55296563 return arg1_value;
55306564
5531 IrInstruction *truncate = ir_build_truncate(irb, scope, node, arg0_value, arg1_value);
6565 IrInstSrc *truncate = ir_build_truncate(irb, scope, node, arg0_value, arg1_value);
55326566 return ir_lval_wrap(irb, scope, truncate, lval, result_loc);
55336567 }
55346568 case BuiltinFnIdIntCast:
55356569 {
55366570 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5537 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5538 if (arg0_value == irb->codegen->invalid_instruction)
6571 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6572 if (arg0_value == irb->codegen->invalid_inst_src)
55396573 return arg0_value;
55406574
55416575 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5542 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5543 if (arg1_value == irb->codegen->invalid_instruction)
6576 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6577 if (arg1_value == irb->codegen->invalid_inst_src)
55446578 return arg1_value;
55456579
5546 IrInstruction *result = ir_build_int_cast(irb, scope, node, arg0_value, arg1_value);
6580 IrInstSrc *result = ir_build_int_cast(irb, scope, node, arg0_value, arg1_value);
55476581 return ir_lval_wrap(irb, scope, result, lval, result_loc);
55486582 }
55496583 case BuiltinFnIdFloatCast:
55506584 {
55516585 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5552 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5553 if (arg0_value == irb->codegen->invalid_instruction)
6586 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6587 if (arg0_value == irb->codegen->invalid_inst_src)
55546588 return arg0_value;
55556589
55566590 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5557 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5558 if (arg1_value == irb->codegen->invalid_instruction)
6591 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6592 if (arg1_value == irb->codegen->invalid_inst_src)
55596593 return arg1_value;
55606594
5561 IrInstruction *result = ir_build_float_cast(irb, scope, node, arg0_value, arg1_value);
6595 IrInstSrc *result = ir_build_float_cast(irb, scope, node, arg0_value, arg1_value);
55626596 return ir_lval_wrap(irb, scope, result, lval, result_loc);
55636597 }
55646598 case BuiltinFnIdErrSetCast:
55656599 {
55666600 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5567 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5568 if (arg0_value == irb->codegen->invalid_instruction)
6601 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6602 if (arg0_value == irb->codegen->invalid_inst_src)
55696603 return arg0_value;
55706604
55716605 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5572 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5573 if (arg1_value == irb->codegen->invalid_instruction)
6606 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6607 if (arg1_value == irb->codegen->invalid_inst_src)
55746608 return arg1_value;
55756609
5576 IrInstruction *result = ir_build_err_set_cast(irb, scope, node, arg0_value, arg1_value);
6610 IrInstSrc *result = ir_build_err_set_cast(irb, scope, node, arg0_value, arg1_value);
55776611 return ir_lval_wrap(irb, scope, result, lval, result_loc);
55786612 }
55796613 case BuiltinFnIdFromBytes:
55806614 {
55816615 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5582 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5583 if (arg0_value == irb->codegen->invalid_instruction)
6616 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6617 if (arg0_value == irb->codegen->invalid_inst_src)
55846618 return arg0_value;
55856619
55866620 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5587 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5588 if (arg1_value == irb->codegen->invalid_instruction)
6621 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6622 if (arg1_value == irb->codegen->invalid_inst_src)
55896623 return arg1_value;
55906624
5591 IrInstruction *result = ir_build_from_bytes(irb, scope, node, arg0_value, arg1_value, result_loc);
6625 IrInstSrc *result = ir_build_from_bytes(irb, scope, node, arg0_value, arg1_value, result_loc);
55926626 return ir_lval_wrap(irb, scope, result, lval, result_loc);
55936627 }
55946628 case BuiltinFnIdToBytes:
55956629 {
55966630 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5597 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5598 if (arg0_value == irb->codegen->invalid_instruction)
6631 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6632 if (arg0_value == irb->codegen->invalid_inst_src)
55996633 return arg0_value;
56006634
5601 IrInstruction *result = ir_build_to_bytes(irb, scope, node, arg0_value, result_loc);
6635 IrInstSrc *result = ir_build_to_bytes(irb, scope, node, arg0_value, result_loc);
56026636 return ir_lval_wrap(irb, scope, result, lval, result_loc);
56036637 }
56046638 case BuiltinFnIdIntToFloat:
56056639 {
56066640 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5607 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5608 if (arg0_value == irb->codegen->invalid_instruction)
6641 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6642 if (arg0_value == irb->codegen->invalid_inst_src)
56096643 return arg0_value;
56106644
56116645 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5612 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5613 if (arg1_value == irb->codegen->invalid_instruction)
6646 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6647 if (arg1_value == irb->codegen->invalid_inst_src)
56146648 return arg1_value;
56156649
5616 IrInstruction *result = ir_build_int_to_float(irb, scope, node, arg0_value, arg1_value);
6650 IrInstSrc *result = ir_build_int_to_float(irb, scope, node, arg0_value, arg1_value);
56176651 return ir_lval_wrap(irb, scope, result, lval, result_loc);
56186652 }
56196653 case BuiltinFnIdFloatToInt:
56206654 {
56216655 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5622 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5623 if (arg0_value == irb->codegen->invalid_instruction)
6656 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6657 if (arg0_value == irb->codegen->invalid_inst_src)
56246658 return arg0_value;
56256659
56266660 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5627 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5628 if (arg1_value == irb->codegen->invalid_instruction)
6661 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6662 if (arg1_value == irb->codegen->invalid_inst_src)
56296663 return arg1_value;
56306664
5631 IrInstruction *result = ir_build_float_to_int(irb, scope, node, arg0_value, arg1_value);
6665 IrInstSrc *result = ir_build_float_to_int(irb, scope, node, arg0_value, arg1_value);
56326666 return ir_lval_wrap(irb, scope, result, lval, result_loc);
56336667 }
56346668 case BuiltinFnIdErrToInt:
56356669 {
56366670 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5637 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5638 if (arg0_value == irb->codegen->invalid_instruction)
6671 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6672 if (arg0_value == irb->codegen->invalid_inst_src)
56396673 return arg0_value;
56406674
5641 IrInstruction *result = ir_build_err_to_int(irb, scope, node, arg0_value);
6675 IrInstSrc *result = ir_build_err_to_int_src(irb, scope, node, arg0_value);
56426676 return ir_lval_wrap(irb, scope, result, lval, result_loc);
56436677 }
56446678 case BuiltinFnIdIntToErr:
56456679 {
56466680 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5647 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5648 if (arg0_value == irb->codegen->invalid_instruction)
6681 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6682 if (arg0_value == irb->codegen->invalid_inst_src)
56496683 return arg0_value;
56506684
5651 IrInstruction *result = ir_build_int_to_err(irb, scope, node, arg0_value);
6685 IrInstSrc *result = ir_build_int_to_err_src(irb, scope, node, arg0_value);
56526686 return ir_lval_wrap(irb, scope, result, lval, result_loc);
56536687 }
56546688 case BuiltinFnIdBoolToInt:
56556689 {
56566690 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5657 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5658 if (arg0_value == irb->codegen->invalid_instruction)
6691 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6692 if (arg0_value == irb->codegen->invalid_inst_src)
56596693 return arg0_value;
56606694
5661 IrInstruction *result = ir_build_bool_to_int(irb, scope, node, arg0_value);
6695 IrInstSrc *result = ir_build_bool_to_int(irb, scope, node, arg0_value);
56626696 return ir_lval_wrap(irb, scope, result, lval, result_loc);
56636697 }
56646698 case BuiltinFnIdIntType:
56656699 {
56666700 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5667 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5668 if (arg0_value == irb->codegen->invalid_instruction)
6701 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6702 if (arg0_value == irb->codegen->invalid_inst_src)
56696703 return arg0_value;
56706704
56716705 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5672 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5673 if (arg1_value == irb->codegen->invalid_instruction)
6706 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6707 if (arg1_value == irb->codegen->invalid_inst_src)
56746708 return arg1_value;
56756709
5676 IrInstruction *int_type = ir_build_int_type(irb, scope, node, arg0_value, arg1_value);
6710 IrInstSrc *int_type = ir_build_int_type(irb, scope, node, arg0_value, arg1_value);
56776711 return ir_lval_wrap(irb, scope, int_type, lval, result_loc);
56786712 }
56796713 case BuiltinFnIdVectorType:
56806714 {
56816715 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5682 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5683 if (arg0_value == irb->codegen->invalid_instruction)
6716 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6717 if (arg0_value == irb->codegen->invalid_inst_src)
56846718 return arg0_value;
56856719
56866720 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5687 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5688 if (arg1_value == irb->codegen->invalid_instruction)
6721 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6722 if (arg1_value == irb->codegen->invalid_inst_src)
56896723 return arg1_value;
56906724
5691 IrInstruction *vector_type = ir_build_vector_type(irb, scope, node, arg0_value, arg1_value);
6725 IrInstSrc *vector_type = ir_build_vector_type(irb, scope, node, arg0_value, arg1_value);
56926726 return ir_lval_wrap(irb, scope, vector_type, lval, result_loc);
56936727 }
56946728 case BuiltinFnIdShuffle:
56956729 {
56966730 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5697 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5698 if (arg0_value == irb->codegen->invalid_instruction)
6731 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6732 if (arg0_value == irb->codegen->invalid_inst_src)
56996733 return arg0_value;
57006734
57016735 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5702 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5703 if (arg1_value == irb->codegen->invalid_instruction)
6736 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6737 if (arg1_value == irb->codegen->invalid_inst_src)
57046738 return arg1_value;
57056739
57066740 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
5707 IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope);
5708 if (arg2_value == irb->codegen->invalid_instruction)
6741 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
6742 if (arg2_value == irb->codegen->invalid_inst_src)
57096743 return arg2_value;
57106744
57116745 AstNode *arg3_node = node->data.fn_call_expr.params.at(3);
5712 IrInstruction *arg3_value = ir_gen_node(irb, arg3_node, scope);
5713 if (arg3_value == irb->codegen->invalid_instruction)
6746 IrInstSrc *arg3_value = ir_gen_node(irb, arg3_node, scope);
6747 if (arg3_value == irb->codegen->invalid_inst_src)
57146748 return arg3_value;
57156749
5716 IrInstruction *shuffle_vector = ir_build_shuffle_vector(irb, scope, node,
6750 IrInstSrc *shuffle_vector = ir_build_shuffle_vector(irb, scope, node,
57176751 arg0_value, arg1_value, arg2_value, arg3_value);
57186752 return ir_lval_wrap(irb, scope, shuffle_vector, lval, result_loc);
57196753 }
57206754 case BuiltinFnIdSplat:
57216755 {
57226756 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5723 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5724 if (arg0_value == irb->codegen->invalid_instruction)
6757 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6758 if (arg0_value == irb->codegen->invalid_inst_src)
57256759 return arg0_value;
57266760
57276761 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5728 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5729 if (arg1_value == irb->codegen->invalid_instruction)
6762 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6763 if (arg1_value == irb->codegen->invalid_inst_src)
57306764 return arg1_value;
57316765
5732 IrInstruction *splat = ir_build_splat_src(irb, scope, node,
6766 IrInstSrc *splat = ir_build_splat_src(irb, scope, node,
57336767 arg0_value, arg1_value);
57346768 return ir_lval_wrap(irb, scope, splat, lval, result_loc);
57356769 }
57366770 case BuiltinFnIdMemcpy:
57376771 {
57386772 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5739 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5740 if (arg0_value == irb->codegen->invalid_instruction)
6773 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6774 if (arg0_value == irb->codegen->invalid_inst_src)
57416775 return arg0_value;
57426776
57436777 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5744 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5745 if (arg1_value == irb->codegen->invalid_instruction)
6778 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6779 if (arg1_value == irb->codegen->invalid_inst_src)
57466780 return arg1_value;
57476781
57486782 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
5749 IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope);
5750 if (arg2_value == irb->codegen->invalid_instruction)
6783 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
6784 if (arg2_value == irb->codegen->invalid_inst_src)
57516785 return arg2_value;
57526786
5753 IrInstruction *ir_memcpy = ir_build_memcpy(irb, scope, node, arg0_value, arg1_value, arg2_value);
6787 IrInstSrc *ir_memcpy = ir_build_memcpy_src(irb, scope, node, arg0_value, arg1_value, arg2_value);
57546788 return ir_lval_wrap(irb, scope, ir_memcpy, lval, result_loc);
57556789 }
57566790 case BuiltinFnIdMemset:
57576791 {
57586792 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5759 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5760 if (arg0_value == irb->codegen->invalid_instruction)
6793 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6794 if (arg0_value == irb->codegen->invalid_inst_src)
57616795 return arg0_value;
57626796
57636797 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5764 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5765 if (arg1_value == irb->codegen->invalid_instruction)
6798 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6799 if (arg1_value == irb->codegen->invalid_inst_src)
57666800 return arg1_value;
57676801
57686802 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
5769 IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope);
5770 if (arg2_value == irb->codegen->invalid_instruction)
6803 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
6804 if (arg2_value == irb->codegen->invalid_inst_src)
57716805 return arg2_value;
57726806
5773 IrInstruction *ir_memset = ir_build_memset(irb, scope, node, arg0_value, arg1_value, arg2_value);
6807 IrInstSrc *ir_memset = ir_build_memset_src(irb, scope, node, arg0_value, arg1_value, arg2_value);
57746808 return ir_lval_wrap(irb, scope, ir_memset, lval, result_loc);
57756809 }
57766810 case BuiltinFnIdMemberCount:
57776811 {
57786812 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5779 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5780 if (arg0_value == irb->codegen->invalid_instruction)
6813 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6814 if (arg0_value == irb->codegen->invalid_inst_src)
57816815 return arg0_value;
57826816
5783 IrInstruction *member_count = ir_build_member_count(irb, scope, node, arg0_value);
6817 IrInstSrc *member_count = ir_build_member_count(irb, scope, node, arg0_value);
57846818 return ir_lval_wrap(irb, scope, member_count, lval, result_loc);
57856819 }
57866820 case BuiltinFnIdMemberType:
57876821 {
57886822 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5789 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5790 if (arg0_value == irb->codegen->invalid_instruction)
6823 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6824 if (arg0_value == irb->codegen->invalid_inst_src)
57916825 return arg0_value;
57926826
57936827 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5794 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5795 if (arg1_value == irb->codegen->invalid_instruction)
6828 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6829 if (arg1_value == irb->codegen->invalid_inst_src)
57966830 return arg1_value;
57976831
57986832
5799 IrInstruction *member_type = ir_build_member_type(irb, scope, node, arg0_value, arg1_value);
6833 IrInstSrc *member_type = ir_build_member_type(irb, scope, node, arg0_value, arg1_value);
58006834 return ir_lval_wrap(irb, scope, member_type, lval, result_loc);
58016835 }
58026836 case BuiltinFnIdMemberName:
58036837 {
58046838 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5805 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5806 if (arg0_value == irb->codegen->invalid_instruction)
6839 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6840 if (arg0_value == irb->codegen->invalid_inst_src)
58076841 return arg0_value;
58086842
58096843 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5810 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5811 if (arg1_value == irb->codegen->invalid_instruction)
6844 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6845 if (arg1_value == irb->codegen->invalid_inst_src)
58126846 return arg1_value;
58136847
58146848
5815 IrInstruction *member_name = ir_build_member_name(irb, scope, node, arg0_value, arg1_value);
6849 IrInstSrc *member_name = ir_build_member_name(irb, scope, node, arg0_value, arg1_value);
58166850 return ir_lval_wrap(irb, scope, member_name, lval, result_loc);
58176851 }
58186852 case BuiltinFnIdField:
58196853 {
58206854 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5821 IrInstruction *arg0_value = ir_gen_node_extra(irb, arg0_node, scope, LValPtr, nullptr);
5822 if (arg0_value == irb->codegen->invalid_instruction)
6855 IrInstSrc *arg0_value = ir_gen_node_extra(irb, arg0_node, scope, LValPtr, nullptr);
6856 if (arg0_value == irb->codegen->invalid_inst_src)
58236857 return arg0_value;
58246858
58256859 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5826 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5827 if (arg1_value == irb->codegen->invalid_instruction)
6860 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6861 if (arg1_value == irb->codegen->invalid_inst_src)
58286862 return arg1_value;
58296863
5830 IrInstruction *ptr_instruction = ir_build_field_ptr_instruction(irb, scope, node,
6864 IrInstSrc *ptr_instruction = ir_build_field_ptr_instruction(irb, scope, node,
58316865 arg0_value, arg1_value, false);
58326866
58336867 if (lval == LValPtr)
58346868 return ptr_instruction;
58356869
5836 IrInstruction *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction);
6870 IrInstSrc *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction);
58376871 return ir_expr_wrap(irb, scope, load_ptr, result_loc);
58386872 }
58396873 case BuiltinFnIdHasField:
58406874 {
58416875 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5842 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5843 if (arg0_value == irb->codegen->invalid_instruction)
6876 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6877 if (arg0_value == irb->codegen->invalid_inst_src)
58446878 return arg0_value;
58456879
58466880 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5847 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5848 if (arg1_value == irb->codegen->invalid_instruction)
6881 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6882 if (arg1_value == irb->codegen->invalid_inst_src)
58496883 return arg1_value;
58506884
5851 IrInstruction *type_info = ir_build_has_field(irb, scope, node, arg0_value, arg1_value);
6885 IrInstSrc *type_info = ir_build_has_field(irb, scope, node, arg0_value, arg1_value);
58526886 return ir_lval_wrap(irb, scope, type_info, lval, result_loc);
58536887 }
58546888 case BuiltinFnIdTypeInfo:
58556889 {
58566890 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5857 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5858 if (arg0_value == irb->codegen->invalid_instruction)
6891 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6892 if (arg0_value == irb->codegen->invalid_inst_src)
58596893 return arg0_value;
58606894
5861 IrInstruction *type_info = ir_build_type_info(irb, scope, node, arg0_value);
6895 IrInstSrc *type_info = ir_build_type_info(irb, scope, node, arg0_value);
58626896 return ir_lval_wrap(irb, scope, type_info, lval, result_loc);
58636897 }
58646898 case BuiltinFnIdType:
58656899 {
58666900 AstNode *arg_node = node->data.fn_call_expr.params.at(0);
5867 IrInstruction *arg = ir_gen_node(irb, arg_node, scope);
5868 if (arg == irb->codegen->invalid_instruction)
6901 IrInstSrc *arg = ir_gen_node(irb, arg_node, scope);
6902 if (arg == irb->codegen->invalid_inst_src)
58696903 return arg;
58706904
5871 IrInstruction *type = ir_build_type(irb, scope, node, arg);
6905 IrInstSrc *type = ir_build_type(irb, scope, node, arg);
58726906 return ir_lval_wrap(irb, scope, type, lval, result_loc);
58736907 }
58746908 case BuiltinFnIdBreakpoint:
58756909 return ir_lval_wrap(irb, scope, ir_build_breakpoint(irb, scope, node), lval, result_loc);
58766910 case BuiltinFnIdReturnAddress:
5877 return ir_lval_wrap(irb, scope, ir_build_return_address(irb, scope, node), lval, result_loc);
6911 return ir_lval_wrap(irb, scope, ir_build_return_address_src(irb, scope, node), lval, result_loc);
58786912 case BuiltinFnIdFrameAddress:
5879 return ir_lval_wrap(irb, scope, ir_build_frame_address(irb, scope, node), lval, result_loc);
6913 return ir_lval_wrap(irb, scope, ir_build_frame_address_src(irb, scope, node), lval, result_loc);
58806914 case BuiltinFnIdFrameHandle:
58816915 if (!irb->exec->fn_entry) {
58826916 add_node_error(irb->codegen, node, buf_sprintf("@frame() called outside of function definition"));
5883 return irb->codegen->invalid_instruction;
6917 return irb->codegen->invalid_inst_src;
58846918 }
5885 return ir_lval_wrap(irb, scope, ir_build_handle(irb, scope, node), lval, result_loc);
6919 return ir_lval_wrap(irb, scope, ir_build_handle_src(irb, scope, node), lval, result_loc);
58866920 case BuiltinFnIdFrameType: {
58876921 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5888 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5889 if (arg0_value == irb->codegen->invalid_instruction)
6922 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6923 if (arg0_value == irb->codegen->invalid_inst_src)
58906924 return arg0_value;
58916925
5892 IrInstruction *frame_type = ir_build_frame_type(irb, scope, node, arg0_value);
6926 IrInstSrc *frame_type = ir_build_frame_type(irb, scope, node, arg0_value);
58936927 return ir_lval_wrap(irb, scope, frame_type, lval, result_loc);
58946928 }
58956929 case BuiltinFnIdFrameSize: {
58966930 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5897 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5898 if (arg0_value == irb->codegen->invalid_instruction)
6931 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6932 if (arg0_value == irb->codegen->invalid_inst_src)
58996933 return arg0_value;
59006934
5901 IrInstruction *frame_size = ir_build_frame_size_src(irb, scope, node, arg0_value);
6935 IrInstSrc *frame_size = ir_build_frame_size_src(irb, scope, node, arg0_value);
59026936 return ir_lval_wrap(irb, scope, frame_size, lval, result_loc);
59036937 }
59046938 case BuiltinFnIdAlignOf:
59056939 {
59066940 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5907 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5908 if (arg0_value == irb->codegen->invalid_instruction)
6941 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6942 if (arg0_value == irb->codegen->invalid_inst_src)
59096943 return arg0_value;
59106944
5911 IrInstruction *align_of = ir_build_align_of(irb, scope, node, arg0_value);
6945 IrInstSrc *align_of = ir_build_align_of(irb, scope, node, arg0_value);
59126946 return ir_lval_wrap(irb, scope, align_of, lval, result_loc);
59136947 }
59146948 case BuiltinFnIdAddWithOverflow:
......@@ -5924,43 +6958,43 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
59246958 case BuiltinFnIdTypeName:
59256959 {
59266960 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5927 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5928 if (arg0_value == irb->codegen->invalid_instruction)
6961 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6962 if (arg0_value == irb->codegen->invalid_inst_src)
59296963 return arg0_value;
59306964
5931 IrInstruction *type_name = ir_build_type_name(irb, scope, node, arg0_value);
6965 IrInstSrc *type_name = ir_build_type_name(irb, scope, node, arg0_value);
59326966 return ir_lval_wrap(irb, scope, type_name, lval, result_loc);
59336967 }
59346968 case BuiltinFnIdPanic:
59356969 {
59366970 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5937 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5938 if (arg0_value == irb->codegen->invalid_instruction)
6971 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6972 if (arg0_value == irb->codegen->invalid_inst_src)
59396973 return arg0_value;
59406974
5941 IrInstruction *panic = ir_build_panic(irb, scope, node, arg0_value);
6975 IrInstSrc *panic = ir_build_panic_src(irb, scope, node, arg0_value);
59426976 return ir_lval_wrap(irb, scope, panic, lval, result_loc);
59436977 }
59446978 case BuiltinFnIdPtrCast:
59456979 {
59466980 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5947 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
5948 if (arg0_value == irb->codegen->invalid_instruction)
6981 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6982 if (arg0_value == irb->codegen->invalid_inst_src)
59496983 return arg0_value;
59506984
59516985 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5952 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
5953 if (arg1_value == irb->codegen->invalid_instruction)
6986 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6987 if (arg1_value == irb->codegen->invalid_inst_src)
59546988 return arg1_value;
59556989
5956 IrInstruction *ptr_cast = ir_build_ptr_cast_src(irb, scope, node, arg0_value, arg1_value, true);
6990 IrInstSrc *ptr_cast = ir_build_ptr_cast_src(irb, scope, node, arg0_value, arg1_value, true);
59576991 return ir_lval_wrap(irb, scope, ptr_cast, lval, result_loc);
59586992 }
59596993 case BuiltinFnIdBitCast:
59606994 {
59616995 AstNode *dest_type_node = node->data.fn_call_expr.params.at(0);
5962 IrInstruction *dest_type = ir_gen_node(irb, dest_type_node, scope);
5963 if (dest_type == irb->codegen->invalid_instruction)
6996 IrInstSrc *dest_type = ir_gen_node(irb, dest_type_node, scope);
6997 if (dest_type == irb->codegen->invalid_inst_src)
59646998 return dest_type;
59656999
59667000 ResultLocBitCast *result_loc_bit_cast = allocate<ResultLocBitCast>(1);
......@@ -5972,125 +7006,126 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
59727006 ir_build_reset_result(irb, scope, node, &result_loc_bit_cast->base);
59737007
59747008 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5975 IrInstruction *arg1_value = ir_gen_node_extra(irb, arg1_node, scope, LValNone,
7009 IrInstSrc *arg1_value = ir_gen_node_extra(irb, arg1_node, scope, LValNone,
59767010 &result_loc_bit_cast->base);
5977 if (arg1_value == irb->codegen->invalid_instruction)
7011 if (arg1_value == irb->codegen->invalid_inst_src)
59787012 return arg1_value;
59797013
5980 IrInstruction *bitcast = ir_build_bit_cast_src(irb, scope, arg1_node, arg1_value, result_loc_bit_cast);
7014 IrInstSrc *bitcast = ir_build_bit_cast_src(irb, scope, arg1_node, arg1_value, result_loc_bit_cast);
59817015 return ir_lval_wrap(irb, scope, bitcast, lval, result_loc);
59827016 }
59837017 case BuiltinFnIdAs:
59847018 {
59857019 AstNode *dest_type_node = node->data.fn_call_expr.params.at(0);
5986 IrInstruction *dest_type = ir_gen_node(irb, dest_type_node, scope);
5987 if (dest_type == irb->codegen->invalid_instruction)
7020 IrInstSrc *dest_type = ir_gen_node(irb, dest_type_node, scope);
7021 if (dest_type == irb->codegen->invalid_inst_src)
59887022 return dest_type;
59897023
59907024 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, dest_type, result_loc);
59917025
59927026 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5993 IrInstruction *arg1_value = ir_gen_node_extra(irb, arg1_node, scope, LValNone,
7027 IrInstSrc *arg1_value = ir_gen_node_extra(irb, arg1_node, scope, LValNone,
59947028 &result_loc_cast->base);
5995 if (arg1_value == irb->codegen->invalid_instruction)
7029 if (arg1_value == irb->codegen->invalid_inst_src)
59967030 return arg1_value;
59977031
5998 IrInstruction *result = ir_build_implicit_cast(irb, scope, node, arg1_value, result_loc_cast);
7032 IrInstSrc *result = ir_build_implicit_cast(irb, scope, node, arg1_value, result_loc_cast);
59997033 return ir_lval_wrap(irb, scope, result, lval, result_loc);
60007034 }
60017035 case BuiltinFnIdIntToPtr:
60027036 {
60037037 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6004 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6005 if (arg0_value == irb->codegen->invalid_instruction)
7038 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7039 if (arg0_value == irb->codegen->invalid_inst_src)
60067040 return arg0_value;
60077041
60087042 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6009 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
6010 if (arg1_value == irb->codegen->invalid_instruction)
7043 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
7044 if (arg1_value == irb->codegen->invalid_inst_src)
60117045 return arg1_value;
60127046
6013 IrInstruction *int_to_ptr = ir_build_int_to_ptr(irb, scope, node, arg0_value, arg1_value);
7047 IrInstSrc *int_to_ptr = ir_build_int_to_ptr_src(irb, scope, node, arg0_value, arg1_value);
60147048 return ir_lval_wrap(irb, scope, int_to_ptr, lval, result_loc);
60157049 }
60167050 case BuiltinFnIdPtrToInt:
60177051 {
60187052 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6019 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6020 if (arg0_value == irb->codegen->invalid_instruction)
7053 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7054 if (arg0_value == irb->codegen->invalid_inst_src)
60217055 return arg0_value;
60227056
6023 IrInstruction *ptr_to_int = ir_build_ptr_to_int(irb, scope, node, arg0_value);
7057 IrInstSrc *ptr_to_int = ir_build_ptr_to_int_src(irb, scope, node, arg0_value);
60247058 return ir_lval_wrap(irb, scope, ptr_to_int, lval, result_loc);
60257059 }
60267060 case BuiltinFnIdTagName:
60277061 {
60287062 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6029 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6030 if (arg0_value == irb->codegen->invalid_instruction)
7063 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7064 if (arg0_value == irb->codegen->invalid_inst_src)
60317065 return arg0_value;
60327066
6033 IrInstruction *tag_name = ir_build_tag_name(irb, scope, node, arg0_value);
7067 IrInstSrc *tag_name = ir_build_tag_name_src(irb, scope, node, arg0_value);
60347068 return ir_lval_wrap(irb, scope, tag_name, lval, result_loc);
60357069 }
60367070 case BuiltinFnIdTagType:
60377071 {
60387072 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6039 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6040 if (arg0_value == irb->codegen->invalid_instruction)
7073 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7074 if (arg0_value == irb->codegen->invalid_inst_src)
60417075 return arg0_value;
60427076
6043 IrInstruction *tag_type = ir_build_tag_type(irb, scope, node, arg0_value);
7077 IrInstSrc *tag_type = ir_build_tag_type(irb, scope, node, arg0_value);
60447078 return ir_lval_wrap(irb, scope, tag_type, lval, result_loc);
60457079 }
60467080 case BuiltinFnIdFieldParentPtr:
60477081 {
60487082 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6049 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6050 if (arg0_value == irb->codegen->invalid_instruction)
7083 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7084 if (arg0_value == irb->codegen->invalid_inst_src)
60517085 return arg0_value;
60527086
60537087 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6054 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
6055 if (arg1_value == irb->codegen->invalid_instruction)
7088 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
7089 if (arg1_value == irb->codegen->invalid_inst_src)
60567090 return arg1_value;
60577091
60587092 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
6059 IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope);
6060 if (arg2_value == irb->codegen->invalid_instruction)
7093 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
7094 if (arg2_value == irb->codegen->invalid_inst_src)
60617095 return arg2_value;
60627096
6063 IrInstruction *field_parent_ptr = ir_build_field_parent_ptr(irb, scope, node, arg0_value, arg1_value, arg2_value, nullptr);
7097 IrInstSrc *field_parent_ptr = ir_build_field_parent_ptr_src(irb, scope, node,
7098 arg0_value, arg1_value, arg2_value);
60647099 return ir_lval_wrap(irb, scope, field_parent_ptr, lval, result_loc);
60657100 }
60667101 case BuiltinFnIdByteOffsetOf:
60677102 {
60687103 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6069 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6070 if (arg0_value == irb->codegen->invalid_instruction)
7104 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7105 if (arg0_value == irb->codegen->invalid_inst_src)
60717106 return arg0_value;
60727107
60737108 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6074 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
6075 if (arg1_value == irb->codegen->invalid_instruction)
7109 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
7110 if (arg1_value == irb->codegen->invalid_inst_src)
60767111 return arg1_value;
60777112
6078 IrInstruction *offset_of = ir_build_byte_offset_of(irb, scope, node, arg0_value, arg1_value);
7113 IrInstSrc *offset_of = ir_build_byte_offset_of(irb, scope, node, arg0_value, arg1_value);
60797114 return ir_lval_wrap(irb, scope, offset_of, lval, result_loc);
60807115 }
60817116 case BuiltinFnIdBitOffsetOf:
60827117 {
60837118 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6084 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6085 if (arg0_value == irb->codegen->invalid_instruction)
7119 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7120 if (arg0_value == irb->codegen->invalid_inst_src)
60867121 return arg0_value;
60877122
60887123 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6089 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
6090 if (arg1_value == irb->codegen->invalid_instruction)
7124 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
7125 if (arg1_value == irb->codegen->invalid_inst_src)
60917126 return arg1_value;
60927127
6093 IrInstruction *offset_of = ir_build_bit_offset_of(irb, scope, node, arg0_value, arg1_value);
7128 IrInstSrc *offset_of = ir_build_bit_offset_of(irb, scope, node, arg0_value, arg1_value);
60947129 return ir_lval_wrap(irb, scope, offset_of, lval, result_loc);
60957130 }
60967131 case BuiltinFnIdNewStackCall:
......@@ -6099,45 +7134,45 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
60997134 add_node_error(irb->codegen, node,
61007135 buf_sprintf("expected at least 2 arguments, found %" ZIG_PRI_usize,
61017136 node->data.fn_call_expr.params.length));
6102 return irb->codegen->invalid_instruction;
7137 return irb->codegen->invalid_inst_src;
61037138 }
61047139
61057140 AstNode *new_stack_node = node->data.fn_call_expr.params.at(0);
6106 IrInstruction *new_stack = ir_gen_node(irb, new_stack_node, scope);
6107 if (new_stack == irb->codegen->invalid_instruction)
7141 IrInstSrc *new_stack = ir_gen_node(irb, new_stack_node, scope);
7142 if (new_stack == irb->codegen->invalid_inst_src)
61087143 return new_stack;
61097144
61107145 AstNode *fn_ref_node = node->data.fn_call_expr.params.at(1);
6111 IrInstruction *fn_ref = ir_gen_node(irb, fn_ref_node, scope);
6112 if (fn_ref == irb->codegen->invalid_instruction)
7146 IrInstSrc *fn_ref = ir_gen_node(irb, fn_ref_node, scope);
7147 if (fn_ref == irb->codegen->invalid_inst_src)
61137148 return fn_ref;
61147149
61157150 size_t arg_count = node->data.fn_call_expr.params.length - 2;
61167151
6117 IrInstruction **args = allocate<IrInstruction*>(arg_count);
7152 IrInstSrc **args = allocate<IrInstSrc*>(arg_count);
61187153 for (size_t i = 0; i < arg_count; i += 1) {
61197154 AstNode *arg_node = node->data.fn_call_expr.params.at(i + 2);
61207155 args[i] = ir_gen_node(irb, arg_node, scope);
6121 if (args[i] == irb->codegen->invalid_instruction)
7156 if (args[i] == irb->codegen->invalid_inst_src)
61227157 return args[i];
61237158 }
61247159
6125 IrInstruction *call = ir_build_call_src(irb, scope, node, nullptr, fn_ref, arg_count, args,
7160 IrInstSrc *call = ir_build_call_src(irb, scope, node, nullptr, fn_ref, arg_count, args,
61267161 nullptr, CallModifierNone, false, new_stack, result_loc);
61277162 return ir_lval_wrap(irb, scope, call, lval, result_loc);
61287163 }
61297164 case BuiltinFnIdCall: {
61307165 // Cast the options parameter to the options type
61317166 ZigType *options_type = get_builtin_type(irb->codegen, "CallOptions");
6132 IrInstruction *options_type_inst = ir_build_const_type(irb, scope, node, options_type);
7167 IrInstSrc *options_type_inst = ir_build_const_type(irb, scope, node, options_type);
61337168 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, options_type_inst, no_result_loc());
61347169
61357170 AstNode *options_node = node->data.fn_call_expr.params.at(0);
6136 IrInstruction *options_inner = ir_gen_node_extra(irb, options_node, scope,
7171 IrInstSrc *options_inner = ir_gen_node_extra(irb, options_node, scope,
61377172 LValNone, &result_loc_cast->base);
6138 if (options_inner == irb->codegen->invalid_instruction)
7173 if (options_inner == irb->codegen->invalid_inst_src)
61397174 return options_inner;
6140 IrInstruction *options = ir_build_implicit_cast(irb, scope, options_node, options_inner, result_loc_cast);
7175 IrInstSrc *options = ir_build_implicit_cast(irb, scope, options_node, options_inner, result_loc_cast);
61417176
61427177 AstNode *fn_ref_node = node->data.fn_call_expr.params.at(1);
61437178 AstNode *args_node = node->data.fn_call_expr.params.at(2);
......@@ -6153,18 +7188,18 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
61537188 } else {
61547189 exec_add_error_node(irb->codegen, irb->exec, args_node,
61557190 buf_sprintf("TODO: @call with anon struct literal"));
6156 return irb->codegen->invalid_instruction;
7191 return irb->codegen->invalid_inst_src;
61577192 }
61587193 } else {
6159 IrInstruction *fn_ref = ir_gen_node(irb, fn_ref_node, scope);
6160 if (fn_ref == irb->codegen->invalid_instruction)
7194 IrInstSrc *fn_ref = ir_gen_node(irb, fn_ref_node, scope);
7195 if (fn_ref == irb->codegen->invalid_inst_src)
61617196 return fn_ref;
61627197
6163 IrInstruction *args = ir_gen_node(irb, args_node, scope);
6164 if (args == irb->codegen->invalid_instruction)
7198 IrInstSrc *args = ir_gen_node(irb, args_node, scope);
7199 if (args == irb->codegen->invalid_inst_src)
61657200 return args;
61667201
6167 IrInstruction *call = ir_build_call_extra(irb, scope, node, options, fn_ref, args, result_loc);
7202 IrInstSrc *call = ir_build_call_extra(irb, scope, node, options, fn_ref, args, result_loc);
61687203 return ir_lval_wrap(irb, scope, call, lval, result_loc);
61697204 }
61707205 }
......@@ -6173,237 +7208,233 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
61737208 case BuiltinFnIdTypeId:
61747209 {
61757210 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6176 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6177 if (arg0_value == irb->codegen->invalid_instruction)
7211 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7212 if (arg0_value == irb->codegen->invalid_inst_src)
61787213 return arg0_value;
61797214
6180 IrInstruction *type_id = ir_build_type_id(irb, scope, node, arg0_value);
7215 IrInstSrc *type_id = ir_build_type_id(irb, scope, node, arg0_value);
61817216 return ir_lval_wrap(irb, scope, type_id, lval, result_loc);
61827217 }
61837218 case BuiltinFnIdShlExact:
61847219 {
61857220 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6186 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6187 if (arg0_value == irb->codegen->invalid_instruction)
7221 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7222 if (arg0_value == irb->codegen->invalid_inst_src)
61887223 return arg0_value;
61897224
61907225 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6191 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
6192 if (arg1_value == irb->codegen->invalid_instruction)
7226 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
7227 if (arg1_value == irb->codegen->invalid_inst_src)
61937228 return arg1_value;
61947229
6195 IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpBitShiftLeftExact, arg0_value, arg1_value, true);
7230 IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpBitShiftLeftExact, arg0_value, arg1_value, true);
61967231 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);
61977232 }
61987233 case BuiltinFnIdShrExact:
61997234 {
62007235 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6201 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6202 if (arg0_value == irb->codegen->invalid_instruction)
7236 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7237 if (arg0_value == irb->codegen->invalid_inst_src)
62037238 return arg0_value;
62047239
62057240 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6206 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
6207 if (arg1_value == irb->codegen->invalid_instruction)
7241 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
7242 if (arg1_value == irb->codegen->invalid_inst_src)
62087243 return arg1_value;
62097244
6210 IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpBitShiftRightExact, arg0_value, arg1_value, true);
7245 IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpBitShiftRightExact, arg0_value, arg1_value, true);
62117246 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);
62127247 }
62137248 case BuiltinFnIdSetEvalBranchQuota:
62147249 {
62157250 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6216 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6217 if (arg0_value == irb->codegen->invalid_instruction)
7251 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7252 if (arg0_value == irb->codegen->invalid_inst_src)
62187253 return arg0_value;
62197254
6220 IrInstruction *set_eval_branch_quota = ir_build_set_eval_branch_quota(irb, scope, node, arg0_value);
7255 IrInstSrc *set_eval_branch_quota = ir_build_set_eval_branch_quota(irb, scope, node, arg0_value);
62217256 return ir_lval_wrap(irb, scope, set_eval_branch_quota, lval, result_loc);
62227257 }
62237258 case BuiltinFnIdAlignCast:
62247259 {
62257260 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6226 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6227 if (arg0_value == irb->codegen->invalid_instruction)
7261 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7262 if (arg0_value == irb->codegen->invalid_inst_src)
62287263 return arg0_value;
62297264
62307265 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6231 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
6232 if (arg1_value == irb->codegen->invalid_instruction)
7266 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
7267 if (arg1_value == irb->codegen->invalid_inst_src)
62337268 return arg1_value;
62347269
6235 IrInstruction *align_cast = ir_build_align_cast(irb, scope, node, arg0_value, arg1_value);
7270 IrInstSrc *align_cast = ir_build_align_cast_src(irb, scope, node, arg0_value, arg1_value);
62367271 return ir_lval_wrap(irb, scope, align_cast, lval, result_loc);
62377272 }
62387273 case BuiltinFnIdOpaqueType:
62397274 {
6240 IrInstruction *opaque_type = ir_build_opaque_type(irb, scope, node);
7275 IrInstSrc *opaque_type = ir_build_opaque_type(irb, scope, node);
62417276 return ir_lval_wrap(irb, scope, opaque_type, lval, result_loc);
62427277 }
62437278 case BuiltinFnIdThis:
62447279 {
6245 IrInstruction *this_inst = ir_gen_this(irb, scope, node);
7280 IrInstSrc *this_inst = ir_gen_this(irb, scope, node);
62467281 return ir_lval_wrap(irb, scope, this_inst, lval, result_loc);
62477282 }
62487283 case BuiltinFnIdSetAlignStack:
62497284 {
62507285 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6251 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6252 if (arg0_value == irb->codegen->invalid_instruction)
7286 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7287 if (arg0_value == irb->codegen->invalid_inst_src)
62537288 return arg0_value;
62547289
6255 IrInstruction *set_align_stack = ir_build_set_align_stack(irb, scope, node, arg0_value);
7290 IrInstSrc *set_align_stack = ir_build_set_align_stack(irb, scope, node, arg0_value);
62567291 return ir_lval_wrap(irb, scope, set_align_stack, lval, result_loc);
62577292 }
62587293 case BuiltinFnIdArgType:
62597294 {
62607295 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6261 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6262 if (arg0_value == irb->codegen->invalid_instruction)
7296 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7297 if (arg0_value == irb->codegen->invalid_inst_src)
62637298 return arg0_value;
62647299
62657300 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6266 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
6267 if (arg1_value == irb->codegen->invalid_instruction)
7301 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
7302 if (arg1_value == irb->codegen->invalid_inst_src)
62687303 return arg1_value;
62697304
6270 IrInstruction *arg_type = ir_build_arg_type(irb, scope, node, arg0_value, arg1_value, false);
7305 IrInstSrc *arg_type = ir_build_arg_type(irb, scope, node, arg0_value, arg1_value, false);
62717306 return ir_lval_wrap(irb, scope, arg_type, lval, result_loc);
62727307 }
62737308 case BuiltinFnIdExport:
62747309 {
62757310 // Cast the options parameter to the options type
62767311 ZigType *options_type = get_builtin_type(irb->codegen, "ExportOptions");
6277 IrInstruction *options_type_inst = ir_build_const_type(irb, scope, node, options_type);
7312 IrInstSrc *options_type_inst = ir_build_const_type(irb, scope, node, options_type);
62787313 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, options_type_inst, no_result_loc());
62797314
62807315 AstNode *target_node = node->data.fn_call_expr.params.at(0);
6281 IrInstruction *target_value = ir_gen_node(irb, target_node, scope);
6282 if (target_value == irb->codegen->invalid_instruction)
7316 IrInstSrc *target_value = ir_gen_node(irb, target_node, scope);
7317 if (target_value == irb->codegen->invalid_inst_src)
62837318 return target_value;
62847319
62857320 AstNode *options_node = node->data.fn_call_expr.params.at(1);
6286 IrInstruction *options_value = ir_gen_node_extra(irb, options_node,
7321 IrInstSrc *options_value = ir_gen_node_extra(irb, options_node,
62877322 scope, LValNone, &result_loc_cast->base);
6288 if (options_value == irb->codegen->invalid_instruction)
7323 if (options_value == irb->codegen->invalid_inst_src)
62897324 return options_value;
62907325
6291 IrInstruction *casted_options_value = ir_build_implicit_cast(
7326 IrInstSrc *casted_options_value = ir_build_implicit_cast(
62927327 irb, scope, options_node, options_value, result_loc_cast);
62937328
6294 IrInstruction *ir_export = ir_build_export(irb, scope, node, target_value, casted_options_value);
7329 IrInstSrc *ir_export = ir_build_export(irb, scope, node, target_value, casted_options_value);
62957330 return ir_lval_wrap(irb, scope, ir_export, lval, result_loc);
62967331 }
62977332 case BuiltinFnIdErrorReturnTrace:
62987333 {
6299 IrInstruction *error_return_trace = ir_build_error_return_trace(irb, scope, node, IrInstructionErrorReturnTrace::Null);
7334 IrInstSrc *error_return_trace = ir_build_error_return_trace_src(irb, scope, node,
7335 IrInstErrorReturnTraceNull);
63007336 return ir_lval_wrap(irb, scope, error_return_trace, lval, result_loc);
63017337 }
63027338 case BuiltinFnIdAtomicRmw:
63037339 {
63047340 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6305 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6306 if (arg0_value == irb->codegen->invalid_instruction)
7341 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7342 if (arg0_value == irb->codegen->invalid_inst_src)
63077343 return arg0_value;
63087344
63097345 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6310 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
6311 if (arg1_value == irb->codegen->invalid_instruction)
7346 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
7347 if (arg1_value == irb->codegen->invalid_inst_src)
63127348 return arg1_value;
63137349
63147350 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
6315 IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope);
6316 if (arg2_value == irb->codegen->invalid_instruction)
7351 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
7352 if (arg2_value == irb->codegen->invalid_inst_src)
63177353 return arg2_value;
63187354
63197355 AstNode *arg3_node = node->data.fn_call_expr.params.at(3);
6320 IrInstruction *arg3_value = ir_gen_node(irb, arg3_node, scope);
6321 if (arg3_value == irb->codegen->invalid_instruction)
7356 IrInstSrc *arg3_value = ir_gen_node(irb, arg3_node, scope);
7357 if (arg3_value == irb->codegen->invalid_inst_src)
63227358 return arg3_value;
63237359
63247360 AstNode *arg4_node = node->data.fn_call_expr.params.at(4);
6325 IrInstruction *arg4_value = ir_gen_node(irb, arg4_node, scope);
6326 if (arg4_value == irb->codegen->invalid_instruction)
7361 IrInstSrc *arg4_value = ir_gen_node(irb, arg4_node, scope);
7362 if (arg4_value == irb->codegen->invalid_inst_src)
63277363 return arg4_value;
63287364
6329 IrInstruction *inst = ir_build_atomic_rmw(irb, scope, node, arg0_value, arg1_value, arg2_value, arg3_value,
6330 arg4_value,
6331 // these 2 values don't mean anything since we passed non-null values for other args
6332 AtomicRmwOp_xchg, AtomicOrderMonotonic);
7365 IrInstSrc *inst = ir_build_atomic_rmw_src(irb, scope, node,
7366 arg0_value, arg1_value, arg2_value, arg3_value, arg4_value);
63337367 return ir_lval_wrap(irb, scope, inst, lval, result_loc);
63347368 }
63357369 case BuiltinFnIdAtomicLoad:
63367370 {
63377371 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6338 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6339 if (arg0_value == irb->codegen->invalid_instruction)
7372 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7373 if (arg0_value == irb->codegen->invalid_inst_src)
63407374 return arg0_value;
63417375
63427376 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6343 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
6344 if (arg1_value == irb->codegen->invalid_instruction)
7377 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
7378 if (arg1_value == irb->codegen->invalid_inst_src)
63457379 return arg1_value;
63467380
63477381 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
6348 IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope);
6349 if (arg2_value == irb->codegen->invalid_instruction)
7382 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
7383 if (arg2_value == irb->codegen->invalid_inst_src)
63507384 return arg2_value;
63517385
6352 IrInstruction *inst = ir_build_atomic_load(irb, scope, node, arg0_value, arg1_value, arg2_value,
6353 // this value does not mean anything since we passed non-null values for other arg
6354 AtomicOrderMonotonic);
7386 IrInstSrc *inst = ir_build_atomic_load_src(irb, scope, node, arg0_value, arg1_value, arg2_value);
63557387 return ir_lval_wrap(irb, scope, inst, lval, result_loc);
63567388 }
63577389 case BuiltinFnIdAtomicStore:
63587390 {
63597391 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6360 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6361 if (arg0_value == irb->codegen->invalid_instruction)
7392 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7393 if (arg0_value == irb->codegen->invalid_inst_src)
63627394 return arg0_value;
63637395
63647396 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6365 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
6366 if (arg1_value == irb->codegen->invalid_instruction)
7397 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
7398 if (arg1_value == irb->codegen->invalid_inst_src)
63677399 return arg1_value;
63687400
63697401 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
6370 IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope);
6371 if (arg2_value == irb->codegen->invalid_instruction)
7402 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
7403 if (arg2_value == irb->codegen->invalid_inst_src)
63727404 return arg2_value;
63737405
63747406 AstNode *arg3_node = node->data.fn_call_expr.params.at(3);
6375 IrInstruction *arg3_value = ir_gen_node(irb, arg3_node, scope);
6376 if (arg3_value == irb->codegen->invalid_instruction)
7407 IrInstSrc *arg3_value = ir_gen_node(irb, arg3_node, scope);
7408 if (arg3_value == irb->codegen->invalid_inst_src)
63777409 return arg3_value;
63787410
6379 IrInstruction *inst = ir_build_atomic_store(irb, scope, node, arg0_value, arg1_value, arg2_value, arg3_value,
6380 // this value does not mean anything since we passed non-null values for other arg
6381 AtomicOrderMonotonic);
7411 IrInstSrc *inst = ir_build_atomic_store_src(irb, scope, node, arg0_value, arg1_value,
7412 arg2_value, arg3_value);
63827413 return ir_lval_wrap(irb, scope, inst, lval, result_loc);
63837414 }
63847415 case BuiltinFnIdIntToEnum:
63857416 {
63867417 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6387 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6388 if (arg0_value == irb->codegen->invalid_instruction)
7418 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7419 if (arg0_value == irb->codegen->invalid_inst_src)
63897420 return arg0_value;
63907421
63917422 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6392 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
6393 if (arg1_value == irb->codegen->invalid_instruction)
7423 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
7424 if (arg1_value == irb->codegen->invalid_inst_src)
63947425 return arg1_value;
63957426
6396 IrInstruction *result = ir_build_int_to_enum(irb, scope, node, arg0_value, arg1_value);
7427 IrInstSrc *result = ir_build_int_to_enum_src(irb, scope, node, arg0_value, arg1_value);
63977428 return ir_lval_wrap(irb, scope, result, lval, result_loc);
63987429 }
63997430 case BuiltinFnIdEnumToInt:
64007431 {
64017432 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6402 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6403 if (arg0_value == irb->codegen->invalid_instruction)
7433 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7434 if (arg0_value == irb->codegen->invalid_inst_src)
64047435 return arg0_value;
64057436
6406 IrInstruction *result = ir_build_enum_to_int(irb, scope, node, arg0_value);
7437 IrInstSrc *result = ir_build_enum_to_int(irb, scope, node, arg0_value);
64077438 return ir_lval_wrap(irb, scope, result, lval, result_loc);
64087439 }
64097440 case BuiltinFnIdCtz:
......@@ -6413,16 +7444,16 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
64137444 case BuiltinFnIdBitReverse:
64147445 {
64157446 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6416 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6417 if (arg0_value == irb->codegen->invalid_instruction)
7447 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7448 if (arg0_value == irb->codegen->invalid_inst_src)
64187449 return arg0_value;
64197450
64207451 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6421 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
6422 if (arg1_value == irb->codegen->invalid_instruction)
7452 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
7453 if (arg1_value == irb->codegen->invalid_inst_src)
64237454 return arg1_value;
64247455
6425 IrInstruction *result;
7456 IrInstSrc *result;
64267457 switch (builtin_fn->id) {
64277458 case BuiltinFnIdCtz:
64287459 result = ir_build_ctz(irb, scope, node, arg0_value, arg1_value);
......@@ -6447,28 +7478,28 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
64477478 case BuiltinFnIdHasDecl:
64487479 {
64497480 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6450 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
6451 if (arg0_value == irb->codegen->invalid_instruction)
7481 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7482 if (arg0_value == irb->codegen->invalid_inst_src)
64527483 return arg0_value;
64537484
64547485 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6455 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
6456 if (arg1_value == irb->codegen->invalid_instruction)
7486 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
7487 if (arg1_value == irb->codegen->invalid_inst_src)
64577488 return arg1_value;
64587489
6459 IrInstruction *has_decl = ir_build_has_decl(irb, scope, node, arg0_value, arg1_value);
7490 IrInstSrc *has_decl = ir_build_has_decl(irb, scope, node, arg0_value, arg1_value);
64607491 return ir_lval_wrap(irb, scope, has_decl, lval, result_loc);
64617492 }
64627493 case BuiltinFnIdUnionInit:
64637494 {
64647495 AstNode *union_type_node = node->data.fn_call_expr.params.at(0);
6465 IrInstruction *union_type_inst = ir_gen_node(irb, union_type_node, scope);
6466 if (union_type_inst == irb->codegen->invalid_instruction)
7496 IrInstSrc *union_type_inst = ir_gen_node(irb, union_type_node, scope);
7497 if (union_type_inst == irb->codegen->invalid_inst_src)
64677498 return union_type_inst;
64687499
64697500 AstNode *name_node = node->data.fn_call_expr.params.at(1);
6470 IrInstruction *name_inst = ir_gen_node(irb, name_node, scope);
6471 if (name_inst == irb->codegen->invalid_instruction)
7501 IrInstSrc *name_inst = ir_gen_node(irb, name_node, scope);
7502 if (name_inst == irb->codegen->invalid_inst_src)
64727503 return name_inst;
64737504
64747505 AstNode *init_node = node->data.fn_call_expr.params.at(2);
......@@ -6480,7 +7511,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
64807511 zig_unreachable();
64817512}
64827513
6483static IrInstruction *ir_gen_fn_call(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,
7514static IrInstSrc *ir_gen_fn_call(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
64847515 ResultLoc *result_loc)
64857516{
64867517 assert(node->type == NodeTypeFnCallExpr);
......@@ -6493,16 +7524,16 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, Scope *scope, AstNode *node
64937524 nullptr, node->data.fn_call_expr.params.items, node->data.fn_call_expr.params.length, lval, result_loc);
64947525}
64957526
6496static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,
7527static IrInstSrc *ir_gen_if_bool_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
64977528 ResultLoc *result_loc)
64987529{
64997530 assert(node->type == NodeTypeIfBoolExpr);
65007531
6501 IrInstruction *condition = ir_gen_node(irb, node->data.if_bool_expr.condition, scope);
6502 if (condition == irb->codegen->invalid_instruction)
6503 return irb->codegen->invalid_instruction;
7532 IrInstSrc *condition = ir_gen_node(irb, node->data.if_bool_expr.condition, scope);
7533 if (condition == irb->codegen->invalid_inst_src)
7534 return irb->codegen->invalid_inst_src;
65047535
6505 IrInstruction *is_comptime;
7536 IrInstSrc *is_comptime;
65067537 if (ir_should_inline(irb->exec, scope)) {
65077538 is_comptime = ir_build_const_bool(irb, scope, node, true);
65087539 } else {
......@@ -6512,11 +7543,11 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode
65127543 AstNode *then_node = node->data.if_bool_expr.then_block;
65137544 AstNode *else_node = node->data.if_bool_expr.else_node;
65147545
6515 IrBasicBlock *then_block = ir_create_basic_block(irb, scope, "Then");
6516 IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "Else");
6517 IrBasicBlock *endif_block = ir_create_basic_block(irb, scope, "EndIf");
7546 IrBasicBlockSrc *then_block = ir_create_basic_block(irb, scope, "Then");
7547 IrBasicBlockSrc *else_block = ir_create_basic_block(irb, scope, "Else");
7548 IrBasicBlockSrc *endif_block = ir_create_basic_block(irb, scope, "EndIf");
65187549
6519 IrInstruction *cond_br_inst = ir_build_cond_br(irb, scope, node, condition,
7550 IrInstSrc *cond_br_inst = ir_build_cond_br(irb, scope, node, condition,
65207551 then_block, else_block, is_comptime);
65217552 ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, endif_block,
65227553 result_loc, is_comptime);
......@@ -6524,70 +7555,70 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode
65247555 ir_set_cursor_at_end_and_append_block(irb, then_block);
65257556
65267557 Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, scope, is_comptime);
6527 IrInstruction *then_expr_result = ir_gen_node_extra(irb, then_node, subexpr_scope, lval,
7558 IrInstSrc *then_expr_result = ir_gen_node_extra(irb, then_node, subexpr_scope, lval,
65287559 &peer_parent->peers.at(0)->base);
6529 if (then_expr_result == irb->codegen->invalid_instruction)
6530 return irb->codegen->invalid_instruction;
6531 IrBasicBlock *after_then_block = irb->current_basic_block;
7560 if (then_expr_result == irb->codegen->invalid_inst_src)
7561 return irb->codegen->invalid_inst_src;
7562 IrBasicBlockSrc *after_then_block = irb->current_basic_block;
65327563 if (!instr_is_unreachable(then_expr_result))
65337564 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));
65347565
65357566 ir_set_cursor_at_end_and_append_block(irb, else_block);
6536 IrInstruction *else_expr_result;
7567 IrInstSrc *else_expr_result;
65377568 if (else_node) {
65387569 else_expr_result = ir_gen_node_extra(irb, else_node, subexpr_scope, lval, &peer_parent->peers.at(1)->base);
6539 if (else_expr_result == irb->codegen->invalid_instruction)
6540 return irb->codegen->invalid_instruction;
7570 if (else_expr_result == irb->codegen->invalid_inst_src)
7571 return irb->codegen->invalid_inst_src;
65417572 } else {
65427573 else_expr_result = ir_build_const_void(irb, scope, node);
65437574 ir_build_end_expr(irb, scope, node, else_expr_result, &peer_parent->peers.at(1)->base);
65447575 }
6545 IrBasicBlock *after_else_block = irb->current_basic_block;
7576 IrBasicBlockSrc *after_else_block = irb->current_basic_block;
65467577 if (!instr_is_unreachable(else_expr_result))
65477578 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));
65487579
65497580 ir_set_cursor_at_end_and_append_block(irb, endif_block);
6550 IrInstruction **incoming_values = allocate<IrInstruction *>(2);
7581 IrInstSrc **incoming_values = allocate<IrInstSrc *>(2);
65517582 incoming_values[0] = then_expr_result;
65527583 incoming_values[1] = else_expr_result;
6553 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *");
7584 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
65547585 incoming_blocks[0] = after_then_block;
65557586 incoming_blocks[1] = after_else_block;
65567587
6557 IrInstruction *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent);
7588 IrInstSrc *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent);
65587589 return ir_expr_wrap(irb, scope, phi, result_loc);
65597590}
65607591
6561static IrInstruction *ir_gen_prefix_op_id_lval(IrBuilder *irb, Scope *scope, AstNode *node, IrUnOp op_id, LVal lval) {
7592static IrInstSrc *ir_gen_prefix_op_id_lval(IrBuilderSrc *irb, Scope *scope, AstNode *node, IrUnOp op_id, LVal lval) {
65627593 assert(node->type == NodeTypePrefixOpExpr);
65637594 AstNode *expr_node = node->data.prefix_op_expr.primary_expr;
65647595
6565 IrInstruction *value = ir_gen_node_extra(irb, expr_node, scope, lval, nullptr);
6566 if (value == irb->codegen->invalid_instruction)
7596 IrInstSrc *value = ir_gen_node_extra(irb, expr_node, scope, lval, nullptr);
7597 if (value == irb->codegen->invalid_inst_src)
65677598 return value;
65687599
65697600 return ir_build_un_op(irb, scope, node, op_id, value);
65707601}
65717602
6572static IrInstruction *ir_gen_prefix_op_id(IrBuilder *irb, Scope *scope, AstNode *node, IrUnOp op_id) {
7603static IrInstSrc *ir_gen_prefix_op_id(IrBuilderSrc *irb, Scope *scope, AstNode *node, IrUnOp op_id) {
65737604 return ir_gen_prefix_op_id_lval(irb, scope, node, op_id, LValNone);
65747605}
65757606
6576static IrInstruction *ir_expr_wrap(IrBuilder *irb, Scope *scope, IrInstruction *inst, ResultLoc *result_loc) {
6577 if (inst == irb->codegen->invalid_instruction) return inst;
6578 ir_build_end_expr(irb, scope, inst->source_node, inst, result_loc);
7607static IrInstSrc *ir_expr_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *inst, ResultLoc *result_loc) {
7608 if (inst == irb->codegen->invalid_inst_src) return inst;
7609 ir_build_end_expr(irb, scope, inst->base.source_node, inst, result_loc);
65797610 return inst;
65807611}
65817612
6582static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval,
7613static IrInstSrc *ir_lval_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *value, LVal lval,
65837614 ResultLoc *result_loc)
65847615{
65857616 // This logic must be kept in sync with
65867617 // [STMT_EXPR_TEST_THING] <--- (search this token)
6587 if (value == irb->codegen->invalid_instruction ||
7618 if (value == irb->codegen->invalid_inst_src ||
65887619 instr_is_unreachable(value) ||
6589 value->source_node->type == NodeTypeDefer ||
6590 value->id == IrInstructionIdDeclVarSrc)
7620 value->base.source_node->type == NodeTypeDefer ||
7621 value->id == IrInstSrcIdDeclVar)
65917622 {
65927623 return value;
65937624 }
......@@ -6595,7 +7626,7 @@ static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *
65957626 if (lval == LValPtr) {
65967627 // We needed a pointer to a value, but we got a value. So we create
65977628 // an instruction which just makes a pointer of it.
6598 return ir_build_ref(irb, scope, value->source_node, value, false, false);
7629 return ir_build_ref_src(irb, scope, value->base.source_node, value, false, false);
65997630 } else if (result_loc != nullptr) {
66007631 return ir_expr_wrap(irb, scope, value, result_loc);
66017632 } else {
......@@ -6618,7 +7649,7 @@ static PtrLen star_token_to_ptr_len(TokenId token_id) {
66187649 }
66197650}
66207651
6621static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode *node) {
7652static IrInstSrc *ir_gen_pointer_type(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
66227653 assert(node->type == NodeTypePointerType);
66237654
66247655 PtrLen ptr_len = star_token_to_ptr_len(node->data.pointer_type.star_token->id);
......@@ -6630,26 +7661,26 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode
66307661 AstNode *expr_node = node->data.pointer_type.op_expr;
66317662 AstNode *align_expr = node->data.pointer_type.align_expr;
66327663
6633 IrInstruction *sentinel;
7664 IrInstSrc *sentinel;
66347665 if (sentinel_expr != nullptr) {
66357666 sentinel = ir_gen_node(irb, sentinel_expr, scope);
6636 if (sentinel == irb->codegen->invalid_instruction)
7667 if (sentinel == irb->codegen->invalid_inst_src)
66377668 return sentinel;
66387669 } else {
66397670 sentinel = nullptr;
66407671 }
66417672
6642 IrInstruction *align_value;
7673 IrInstSrc *align_value;
66437674 if (align_expr != nullptr) {
66447675 align_value = ir_gen_node(irb, align_expr, scope);
6645 if (align_value == irb->codegen->invalid_instruction)
7676 if (align_value == irb->codegen->invalid_inst_src)
66467677 return align_value;
66477678 } else {
66487679 align_value = nullptr;
66497680 }
66507681
6651 IrInstruction *child_type = ir_gen_node(irb, expr_node, scope);
6652 if (child_type == irb->codegen->invalid_instruction)
7682 IrInstSrc *child_type = ir_gen_node(irb, expr_node, scope);
7683 if (child_type == irb->codegen->invalid_inst_src)
66537684 return child_type;
66547685
66557686 uint32_t bit_offset_start = 0;
......@@ -6659,7 +7690,7 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode
66597690 bigint_append_buf(val_buf, node->data.pointer_type.bit_offset_start, 10);
66607691 exec_add_error_node(irb->codegen, irb->exec, node,
66617692 buf_sprintf("value %s too large for u32 bit offset", buf_ptr(val_buf)));
6662 return irb->codegen->invalid_instruction;
7693 return irb->codegen->invalid_inst_src;
66637694 }
66647695 bit_offset_start = bigint_as_u32(node->data.pointer_type.bit_offset_start);
66657696 }
......@@ -6671,7 +7702,7 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode
66717702 bigint_append_buf(val_buf, node->data.pointer_type.host_int_bytes, 10);
66727703 exec_add_error_node(irb->codegen, irb->exec, node,
66737704 buf_sprintf("value %s too large for u32 byte count", buf_ptr(val_buf)));
6674 return irb->codegen->invalid_instruction;
7705 return irb->codegen->invalid_inst_src;
66757706 }
66767707 host_int_bytes = bigint_as_u32(node->data.pointer_type.host_int_bytes);
66777708 }
......@@ -6679,43 +7710,43 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode
66797710 if (host_int_bytes != 0 && bit_offset_start >= host_int_bytes * 8) {
66807711 exec_add_error_node(irb->codegen, irb->exec, node,
66817712 buf_sprintf("bit offset starts after end of host integer"));
6682 return irb->codegen->invalid_instruction;
7713 return irb->codegen->invalid_inst_src;
66837714 }
66847715
66857716 return ir_build_ptr_type(irb, scope, node, child_type, is_const, is_volatile,
66867717 ptr_len, sentinel, align_value, bit_offset_start, host_int_bytes, is_allow_zero);
66877718}
66887719
6689static IrInstruction *ir_gen_catch_unreachable(IrBuilder *irb, Scope *scope, AstNode *source_node,
7720static IrInstSrc *ir_gen_catch_unreachable(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
66907721 AstNode *expr_node, LVal lval, ResultLoc *result_loc)
66917722{
6692 IrInstruction *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
6693 if (err_union_ptr == irb->codegen->invalid_instruction)
6694 return irb->codegen->invalid_instruction;
7723 IrInstSrc *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
7724 if (err_union_ptr == irb->codegen->invalid_inst_src)
7725 return irb->codegen->invalid_inst_src;
66957726
6696 IrInstruction *payload_ptr = ir_build_unwrap_err_payload(irb, scope, source_node, err_union_ptr, true, false);
6697 if (payload_ptr == irb->codegen->invalid_instruction)
6698 return irb->codegen->invalid_instruction;
7727 IrInstSrc *payload_ptr = ir_build_unwrap_err_payload_src(irb, scope, source_node, err_union_ptr, true, false);
7728 if (payload_ptr == irb->codegen->invalid_inst_src)
7729 return irb->codegen->invalid_inst_src;
66997730
67007731 if (lval == LValPtr)
67017732 return payload_ptr;
67027733
6703 IrInstruction *load_ptr = ir_build_load_ptr(irb, scope, source_node, payload_ptr);
7734 IrInstSrc *load_ptr = ir_build_load_ptr(irb, scope, source_node, payload_ptr);
67047735 return ir_expr_wrap(irb, scope, load_ptr, result_loc);
67057736}
67067737
6707static IrInstruction *ir_gen_bool_not(IrBuilder *irb, Scope *scope, AstNode *node) {
7738static IrInstSrc *ir_gen_bool_not(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
67087739 assert(node->type == NodeTypePrefixOpExpr);
67097740 AstNode *expr_node = node->data.prefix_op_expr.primary_expr;
67107741
6711 IrInstruction *value = ir_gen_node(irb, expr_node, scope);
6712 if (value == irb->codegen->invalid_instruction)
6713 return irb->codegen->invalid_instruction;
7742 IrInstSrc *value = ir_gen_node(irb, expr_node, scope);
7743 if (value == irb->codegen->invalid_inst_src)
7744 return irb->codegen->invalid_inst_src;
67147745
67157746 return ir_build_bool_not(irb, scope, node, value);
67167747}
67177748
6718static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,
7749static IrInstSrc *ir_gen_prefix_op_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
67197750 ResultLoc *result_loc)
67207751{
67217752 assert(node->type == NodeTypePrefixOpExpr);
......@@ -6743,12 +7774,12 @@ static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNod
67437774 zig_unreachable();
67447775}
67457776
6746static IrInstruction *ir_gen_union_init_expr(IrBuilder *irb, Scope *scope, AstNode *source_node,
6747 IrInstruction *union_type, IrInstruction *field_name, AstNode *expr_node,
7777static IrInstSrc *ir_gen_union_init_expr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
7778 IrInstSrc *union_type, IrInstSrc *field_name, AstNode *expr_node,
67487779 LVal lval, ResultLoc *parent_result_loc)
67497780{
6750 IrInstruction *container_ptr = ir_build_resolve_result(irb, scope, source_node, parent_result_loc, union_type);
6751 IrInstruction *field_ptr = ir_build_field_ptr_instruction(irb, scope, source_node, container_ptr,
7781 IrInstSrc *container_ptr = ir_build_resolve_result(irb, scope, source_node, parent_result_loc, union_type);
7782 IrInstSrc *field_ptr = ir_build_field_ptr_instruction(irb, scope, source_node, container_ptr,
67527783 field_name, true);
67537784
67547785 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);
......@@ -6757,18 +7788,18 @@ static IrInstruction *ir_gen_union_init_expr(IrBuilder *irb, Scope *scope, AstNo
67577788 ir_ref_instruction(field_ptr, irb->current_basic_block);
67587789 ir_build_reset_result(irb, scope, expr_node, &result_loc_inst->base);
67597790
6760 IrInstruction *expr_value = ir_gen_node_extra(irb, expr_node, scope, LValNone,
7791 IrInstSrc *expr_value = ir_gen_node_extra(irb, expr_node, scope, LValNone,
67617792 &result_loc_inst->base);
6762 if (expr_value == irb->codegen->invalid_instruction)
7793 if (expr_value == irb->codegen->invalid_inst_src)
67637794 return expr_value;
67647795
6765 IrInstruction *init_union = ir_build_union_init_named_field(irb, scope, source_node, union_type,
7796 IrInstSrc *init_union = ir_build_union_init_named_field(irb, scope, source_node, union_type,
67667797 field_name, field_ptr, container_ptr);
67677798
67687799 return ir_lval_wrap(irb, scope, init_union, lval, parent_result_loc);
67697800}
67707801
6771static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,
7802static IrInstSrc *ir_gen_container_init_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
67727803 ResultLoc *parent_result_loc)
67737804{
67747805 assert(node->type == NodeTypeContainerInitExpr);
......@@ -6780,42 +7811,42 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
67807811 ResultLoc *child_result_loc;
67817812 AstNode *init_array_type_source_node;
67827813 if (container_init_expr->type != nullptr) {
6783 IrInstruction *container_type;
7814 IrInstSrc *container_type;
67847815 if (container_init_expr->type->type == NodeTypeInferredArrayType) {
67857816 if (kind == ContainerInitKindStruct) {
67867817 add_node_error(irb->codegen, container_init_expr->type,
67877818 buf_sprintf("initializing array with struct syntax"));
6788 return irb->codegen->invalid_instruction;
7819 return irb->codegen->invalid_inst_src;
67897820 }
6790 IrInstruction *sentinel;
7821 IrInstSrc *sentinel;
67917822 if (container_init_expr->type->data.inferred_array_type.sentinel != nullptr) {
67927823 sentinel = ir_gen_node(irb, container_init_expr->type->data.inferred_array_type.sentinel, scope);
6793 if (sentinel == irb->codegen->invalid_instruction)
7824 if (sentinel == irb->codegen->invalid_inst_src)
67947825 return sentinel;
67957826 } else {
67967827 sentinel = nullptr;
67977828 }
67987829
6799 IrInstruction *elem_type = ir_gen_node(irb,
7830 IrInstSrc *elem_type = ir_gen_node(irb,
68007831 container_init_expr->type->data.inferred_array_type.child_type, scope);
6801 if (elem_type == irb->codegen->invalid_instruction)
7832 if (elem_type == irb->codegen->invalid_inst_src)
68027833 return elem_type;
68037834 size_t item_count = container_init_expr->entries.length;
6804 IrInstruction *item_count_inst = ir_build_const_usize(irb, scope, node, item_count);
7835 IrInstSrc *item_count_inst = ir_build_const_usize(irb, scope, node, item_count);
68057836 container_type = ir_build_array_type(irb, scope, node, item_count_inst, sentinel, elem_type);
68067837 } else {
68077838 container_type = ir_gen_node(irb, container_init_expr->type, scope);
6808 if (container_type == irb->codegen->invalid_instruction)
7839 if (container_type == irb->codegen->invalid_inst_src)
68097840 return container_type;
68107841 }
68117842
68127843 result_loc_cast = ir_build_cast_result_loc(irb, container_type, parent_result_loc);
68137844 child_result_loc = &result_loc_cast->base;
6814 init_array_type_source_node = container_type->source_node;
7845 init_array_type_source_node = container_type->base.source_node;
68157846 } else {
68167847 child_result_loc = parent_result_loc;
68177848 if (parent_result_loc->source_instruction != nullptr) {
6818 init_array_type_source_node = parent_result_loc->source_instruction->source_node;
7849 init_array_type_source_node = parent_result_loc->source_instruction->base.source_node;
68197850 } else {
68207851 init_array_type_source_node = node;
68217852 }
......@@ -6823,11 +7854,11 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
68237854
68247855 switch (kind) {
68257856 case ContainerInitKindStruct: {
6826 IrInstruction *container_ptr = ir_build_resolve_result(irb, scope, node, child_result_loc,
7857 IrInstSrc *container_ptr = ir_build_resolve_result(irb, scope, node, child_result_loc,
68277858 nullptr);
68287859
68297860 size_t field_count = container_init_expr->entries.length;
6830 IrInstructionContainerInitFieldsField *fields = allocate<IrInstructionContainerInitFieldsField>(field_count);
7861 IrInstSrcContainerInitFieldsField *fields = allocate<IrInstSrcContainerInitFieldsField>(field_count);
68317862 for (size_t i = 0; i < field_count; i += 1) {
68327863 AstNode *entry_node = container_init_expr->entries.at(i);
68337864 assert(entry_node->type == NodeTypeStructValueField);
......@@ -6835,7 +7866,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
68357866 Buf *name = entry_node->data.struct_val_field.name;
68367867 AstNode *expr_node = entry_node->data.struct_val_field.expr;
68377868
6838 IrInstruction *field_ptr = ir_build_field_ptr(irb, scope, entry_node, container_ptr, name, true);
7869 IrInstSrc *field_ptr = ir_build_field_ptr(irb, scope, entry_node, container_ptr, name, true);
68397870 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);
68407871 result_loc_inst->base.id = ResultLocIdInstruction;
68417872 result_loc_inst->base.source_instruction = field_ptr;
......@@ -6843,16 +7874,16 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
68437874 ir_ref_instruction(field_ptr, irb->current_basic_block);
68447875 ir_build_reset_result(irb, scope, expr_node, &result_loc_inst->base);
68457876
6846 IrInstruction *expr_value = ir_gen_node_extra(irb, expr_node, scope, LValNone,
7877 IrInstSrc *expr_value = ir_gen_node_extra(irb, expr_node, scope, LValNone,
68477878 &result_loc_inst->base);
6848 if (expr_value == irb->codegen->invalid_instruction)
7879 if (expr_value == irb->codegen->invalid_inst_src)
68497880 return expr_value;
68507881
68517882 fields[i].name = name;
68527883 fields[i].source_node = entry_node;
68537884 fields[i].result_loc = field_ptr;
68547885 }
6855 IrInstruction *result = ir_build_container_init_fields(irb, scope, node, field_count,
7886 IrInstSrc *result = ir_build_container_init_fields(irb, scope, node, field_count,
68567887 fields, container_ptr);
68577888
68587889 if (result_loc_cast != nullptr) {
......@@ -6863,15 +7894,15 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
68637894 case ContainerInitKindArray: {
68647895 size_t item_count = container_init_expr->entries.length;
68657896
6866 IrInstruction *container_ptr = ir_build_resolve_result(irb, scope, node, child_result_loc,
7897 IrInstSrc *container_ptr = ir_build_resolve_result(irb, scope, node, child_result_loc,
68677898 nullptr);
68687899
6869 IrInstruction **result_locs = allocate<IrInstruction *>(item_count);
7900 IrInstSrc **result_locs = allocate<IrInstSrc *>(item_count);
68707901 for (size_t i = 0; i < item_count; i += 1) {
68717902 AstNode *expr_node = container_init_expr->entries.at(i);
68727903
6873 IrInstruction *elem_index = ir_build_const_usize(irb, scope, expr_node, i);
6874 IrInstruction *elem_ptr = ir_build_elem_ptr(irb, scope, expr_node, container_ptr,
7904 IrInstSrc *elem_index = ir_build_const_usize(irb, scope, expr_node, i);
7905 IrInstSrc *elem_ptr = ir_build_elem_ptr(irb, scope, expr_node, container_ptr,
68757906 elem_index, false, PtrLenSingle, init_array_type_source_node);
68767907 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);
68777908 result_loc_inst->base.id = ResultLocIdInstruction;
......@@ -6880,14 +7911,14 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
68807911 ir_ref_instruction(elem_ptr, irb->current_basic_block);
68817912 ir_build_reset_result(irb, scope, expr_node, &result_loc_inst->base);
68827913
6883 IrInstruction *expr_value = ir_gen_node_extra(irb, expr_node, scope, LValNone,
7914 IrInstSrc *expr_value = ir_gen_node_extra(irb, expr_node, scope, LValNone,
68847915 &result_loc_inst->base);
6885 if (expr_value == irb->codegen->invalid_instruction)
7916 if (expr_value == irb->codegen->invalid_inst_src)
68867917 return expr_value;
68877918
68887919 result_locs[i] = elem_ptr;
68897920 }
6890 IrInstruction *result = ir_build_container_init_list(irb, scope, node, item_count,
7921 IrInstSrc *result = ir_build_container_init_list(irb, scope, node, item_count,
68917922 result_locs, container_ptr, init_array_type_source_node);
68927923 if (result_loc_cast != nullptr) {
68937924 result = ir_build_implicit_cast(irb, scope, node, result, result_loc_cast);
......@@ -6898,19 +7929,19 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
68987929 zig_unreachable();
68997930}
69007931
6901static ResultLocVar *ir_build_var_result_loc(IrBuilder *irb, IrInstruction *alloca, ZigVar *var) {
7932static ResultLocVar *ir_build_var_result_loc(IrBuilderSrc *irb, IrInstSrc *alloca, ZigVar *var) {
69027933 ResultLocVar *result_loc_var = allocate<ResultLocVar>(1);
69037934 result_loc_var->base.id = ResultLocIdVar;
69047935 result_loc_var->base.source_instruction = alloca;
69057936 result_loc_var->base.allow_write_through_const = true;
69067937 result_loc_var->var = var;
69077938
6908 ir_build_reset_result(irb, alloca->scope, alloca->source_node, &result_loc_var->base);
7939 ir_build_reset_result(irb, alloca->base.scope, alloca->base.source_node, &result_loc_var->base);
69097940
69107941 return result_loc_var;
69117942}
69127943
6913static ResultLocCast *ir_build_cast_result_loc(IrBuilder *irb, IrInstruction *dest_type,
7944static ResultLocCast *ir_build_cast_result_loc(IrBuilderSrc *irb, IrInstSrc *dest_type,
69147945 ResultLoc *parent_result_loc)
69157946{
69167947 ResultLocCast *result_loc_cast = allocate<ResultLocCast>(1);
......@@ -6920,37 +7951,37 @@ static ResultLocCast *ir_build_cast_result_loc(IrBuilder *irb, IrInstruction *de
69207951 ir_ref_instruction(dest_type, irb->current_basic_block);
69217952 result_loc_cast->parent = parent_result_loc;
69227953
6923 ir_build_reset_result(irb, dest_type->scope, dest_type->source_node, &result_loc_cast->base);
7954 ir_build_reset_result(irb, dest_type->base.scope, dest_type->base.source_node, &result_loc_cast->base);
69247955
69257956 return result_loc_cast;
69267957}
69277958
6928static void build_decl_var_and_init(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigVar *var,
6929 IrInstruction *init, const char *name_hint, IrInstruction *is_comptime)
7959static void build_decl_var_and_init(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, ZigVar *var,
7960 IrInstSrc *init, const char *name_hint, IrInstSrc *is_comptime)
69307961{
6931 IrInstruction *alloca = ir_build_alloca_src(irb, scope, source_node, nullptr, name_hint, is_comptime);
7962 IrInstSrc *alloca = ir_build_alloca_src(irb, scope, source_node, nullptr, name_hint, is_comptime);
69327963 ResultLocVar *var_result_loc = ir_build_var_result_loc(irb, alloca, var);
69337964 ir_build_end_expr(irb, scope, source_node, init, &var_result_loc->base);
69347965 ir_build_var_decl_src(irb, scope, source_node, var, nullptr, alloca);
69357966}
69367967
6937static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *node) {
7968static IrInstSrc *ir_gen_var_decl(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
69387969 assert(node->type == NodeTypeVariableDeclaration);
69397970
69407971 AstNodeVariableDeclaration *variable_declaration = &node->data.variable_declaration;
69417972
69427973 if (buf_eql_str(variable_declaration->symbol, "_")) {
69437974 add_node_error(irb->codegen, node, buf_sprintf("`_` is not a declarable symbol"));
6944 return irb->codegen->invalid_instruction;
7975 return irb->codegen->invalid_inst_src;
69457976 }
69467977
69477978 // Used for the type expr and the align expr
69487979 Scope *comptime_scope = create_comptime_scope(irb->codegen, node, scope);
69497980
6950 IrInstruction *type_instruction;
7981 IrInstSrc *type_instruction;
69517982 if (variable_declaration->type != nullptr) {
69527983 type_instruction = ir_gen_node(irb, variable_declaration->type, comptime_scope);
6953 if (type_instruction == irb->codegen->invalid_instruction)
7984 if (type_instruction == irb->codegen->invalid_inst_src)
69547985 return type_instruction;
69557986 } else {
69567987 type_instruction = nullptr;
......@@ -6961,22 +7992,22 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
69617992 bool is_extern = variable_declaration->is_extern;
69627993
69637994 bool is_comptime_scalar = ir_should_inline(irb->exec, scope) || variable_declaration->is_comptime;
6964 IrInstruction *is_comptime = ir_build_const_bool(irb, scope, node, is_comptime_scalar);
7995 IrInstSrc *is_comptime = ir_build_const_bool(irb, scope, node, is_comptime_scalar);
69657996 ZigVar *var = ir_create_var(irb, node, scope, variable_declaration->symbol,
69667997 is_const, is_const, is_shadowable, is_comptime);
6967 // we detect IrInstructionIdDeclVarSrc in gen_block to make sure the next node
7998 // we detect IrInstSrcDeclVar in gen_block to make sure the next node
69687999 // is inside var->child_scope
69698000
69708001 if (!is_extern && !variable_declaration->expr) {
69718002 var->var_type = irb->codegen->builtin_types.entry_invalid;
69728003 add_node_error(irb->codegen, node, buf_sprintf("variables must be initialized"));
6973 return irb->codegen->invalid_instruction;
8004 return irb->codegen->invalid_inst_src;
69748005 }
69758006
6976 IrInstruction *align_value = nullptr;
8007 IrInstSrc *align_value = nullptr;
69778008 if (variable_declaration->align_expr != nullptr) {
69788009 align_value = ir_gen_node(irb, variable_declaration->align_expr, comptime_scope);
6979 if (align_value == irb->codegen->invalid_instruction)
8010 if (align_value == irb->codegen->invalid_inst_src)
69808011 return align_value;
69818012 }
69828013
......@@ -6988,7 +8019,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
69888019 // Parser should ensure that this never happens
69898020 assert(variable_declaration->threadlocal_tok == nullptr);
69908021
6991 IrInstruction *alloca = ir_build_alloca_src(irb, scope, node, align_value,
8022 IrInstSrc *alloca = ir_build_alloca_src(irb, scope, node, align_value,
69928023 buf_ptr(variable_declaration->symbol), is_comptime);
69938024
69948025 // Create a result location for the initialization expression.
......@@ -7006,19 +8037,19 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
70068037 Scope *init_scope = is_comptime_scalar ?
70078038 create_comptime_scope(irb->codegen, variable_declaration->expr, scope) : scope;
70088039
7009 // Temporarily set the name of the IrExecutable to the VariableDeclaration
8040 // Temporarily set the name of the IrExecutableSrc to the VariableDeclaration
70108041 // so that the struct or enum from the init expression inherits the name.
70118042 Buf *old_exec_name = irb->exec->name;
70128043 irb->exec->name = variable_declaration->symbol;
7013 IrInstruction *init_value = ir_gen_node_extra(irb, variable_declaration->expr, init_scope,
8044 IrInstSrc *init_value = ir_gen_node_extra(irb, variable_declaration->expr, init_scope,
70148045 LValNone, init_result_loc);
70158046 irb->exec->name = old_exec_name;
70168047
7017 if (init_value == irb->codegen->invalid_instruction)
7018 return irb->codegen->invalid_instruction;
8048 if (init_value == irb->codegen->invalid_inst_src)
8049 return irb->codegen->invalid_inst_src;
70198050
70208051 if (result_loc_cast != nullptr) {
7021 IrInstruction *implicit_cast = ir_build_implicit_cast(irb, scope, init_value->source_node,
8052 IrInstSrc *implicit_cast = ir_build_implicit_cast(irb, scope, init_value->base.source_node,
70228053 init_value, result_loc_cast);
70238054 ir_build_end_expr(irb, scope, node, implicit_cast, &result_loc_var->base);
70248055 }
......@@ -7026,7 +8057,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
70268057 return ir_build_var_decl_src(irb, scope, node, var, align_value, alloca);
70278058}
70288059
7029static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,
8060static IrInstSrc *ir_gen_while_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
70308061 ResultLoc *result_loc)
70318062{
70328063 assert(node->type == NodeTypeWhileExpr);
......@@ -7034,15 +8065,15 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
70348065 AstNode *continue_expr_node = node->data.while_expr.continue_expr;
70358066 AstNode *else_node = node->data.while_expr.else_node;
70368067
7037 IrBasicBlock *cond_block = ir_create_basic_block(irb, scope, "WhileCond");
7038 IrBasicBlock *body_block = ir_create_basic_block(irb, scope, "WhileBody");
7039 IrBasicBlock *continue_block = continue_expr_node ?
8068 IrBasicBlockSrc *cond_block = ir_create_basic_block(irb, scope, "WhileCond");
8069 IrBasicBlockSrc *body_block = ir_create_basic_block(irb, scope, "WhileBody");
8070 IrBasicBlockSrc *continue_block = continue_expr_node ?
70408071 ir_create_basic_block(irb, scope, "WhileContinue") : cond_block;
7041 IrBasicBlock *end_block = ir_create_basic_block(irb, scope, "WhileEnd");
7042 IrBasicBlock *else_block = else_node ?
8072 IrBasicBlockSrc *end_block = ir_create_basic_block(irb, scope, "WhileEnd");
8073 IrBasicBlockSrc *else_block = else_node ?
70438074 ir_create_basic_block(irb, scope, "WhileElse") : end_block;
70448075
7045 IrInstruction *is_comptime = ir_build_const_bool(irb, scope, node,
8076 IrInstSrc *is_comptime = ir_build_const_bool(irb, scope, node,
70468077 ir_should_inline(irb->exec, scope) || node->data.while_expr.is_inline);
70478078 ir_build_br(irb, scope, node, cond_block, is_comptime);
70488079
......@@ -7063,15 +8094,15 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
70638094 } else {
70648095 payload_scope = subexpr_scope;
70658096 }
7066 IrInstruction *err_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope,
8097 IrInstSrc *err_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope,
70678098 LValPtr, nullptr);
7068 if (err_val_ptr == irb->codegen->invalid_instruction)
8099 if (err_val_ptr == irb->codegen->invalid_inst_src)
70698100 return err_val_ptr;
7070 IrInstruction *is_err = ir_build_test_err_src(irb, scope, node->data.while_expr.condition, err_val_ptr,
8101 IrInstSrc *is_err = ir_build_test_err_src(irb, scope, node->data.while_expr.condition, err_val_ptr,
70718102 true, false);
7072 IrBasicBlock *after_cond_block = irb->current_basic_block;
7073 IrInstruction *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node));
7074 IrInstruction *cond_br_inst;
8103 IrBasicBlockSrc *after_cond_block = irb->current_basic_block;
8104 IrInstSrc *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node));
8105 IrInstSrc *cond_br_inst;
70758106 if (!instr_is_unreachable(is_err)) {
70768107 cond_br_inst = ir_build_cond_br(irb, scope, node->data.while_expr.condition, is_err,
70778108 else_block, body_block, is_comptime);
......@@ -7086,15 +8117,15 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
70868117
70878118 ir_set_cursor_at_end_and_append_block(irb, body_block);
70888119 if (var_symbol) {
7089 IrInstruction *payload_ptr = ir_build_unwrap_err_payload(irb, payload_scope, symbol_node,
8120 IrInstSrc *payload_ptr = ir_build_unwrap_err_payload_src(irb, payload_scope, symbol_node,
70908121 err_val_ptr, false, false);
7091 IrInstruction *var_ptr = node->data.while_expr.var_is_ptr ?
7092 ir_build_ref(irb, payload_scope, symbol_node, payload_ptr, true, false) : payload_ptr;
8122 IrInstSrc *var_ptr = node->data.while_expr.var_is_ptr ?
8123 ir_build_ref_src(irb, payload_scope, symbol_node, payload_ptr, true, false) : payload_ptr;
70938124 ir_build_var_decl_src(irb, payload_scope, symbol_node, payload_var, nullptr, var_ptr);
70948125 }
70958126
7096 ZigList<IrInstruction *> incoming_values = {0};
7097 ZigList<IrBasicBlock *> incoming_blocks = {0};
8127 ZigList<IrInstSrc *> incoming_values = {0};
8128 ZigList<IrBasicBlockSrc *> incoming_blocks = {0};
70988129
70998130 ScopeLoop *loop_scope = create_loop_scope(irb->codegen, node, payload_scope);
71008131 loop_scope->break_block = end_block;
......@@ -7108,8 +8139,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
71088139 // Note the body block of the loop is not the place that lval and result_loc are used -
71098140 // it's actually in break statements, handled similarly to return statements.
71108141 // That is why we set those values in loop_scope above and not in this ir_gen_node call.
7111 IrInstruction *body_result = ir_gen_node(irb, node->data.while_expr.body, &loop_scope->base);
7112 if (body_result == irb->codegen->invalid_instruction)
8142 IrInstSrc *body_result = ir_gen_node(irb, node->data.while_expr.body, &loop_scope->base);
8143 if (body_result == irb->codegen->invalid_inst_src)
71138144 return body_result;
71148145
71158146 if (!instr_is_unreachable(body_result)) {
......@@ -7119,8 +8150,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
71198150
71208151 if (continue_expr_node) {
71218152 ir_set_cursor_at_end_and_append_block(irb, continue_block);
7122 IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, payload_scope);
7123 if (expr_result == irb->codegen->invalid_instruction)
8153 IrInstSrc *expr_result = ir_gen_node(irb, continue_expr_node, payload_scope);
8154 if (expr_result == irb->codegen->invalid_inst_src)
71248155 return expr_result;
71258156 if (!instr_is_unreachable(expr_result)) {
71268157 ir_mark_gen(ir_build_check_statement_is_void(irb, payload_scope, continue_expr_node, expr_result));
......@@ -7136,7 +8167,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
71368167 ZigVar *err_var = ir_create_var(irb, err_symbol_node, scope, err_symbol,
71378168 true, false, false, is_comptime);
71388169 Scope *err_scope = err_var->child_scope;
7139 IrInstruction *err_ptr = ir_build_unwrap_err_code(irb, err_scope, err_symbol_node, err_val_ptr);
8170 IrInstSrc *err_ptr = ir_build_unwrap_err_code_src(irb, err_scope, err_symbol_node, err_val_ptr);
71408171 ir_build_var_decl_src(irb, err_scope, symbol_node, err_var, nullptr, err_ptr);
71418172
71428173 if (peer_parent->peers.length != 0) {
......@@ -7144,12 +8175,12 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
71448175 }
71458176 ResultLocPeer *peer_result = create_peer_result(peer_parent);
71468177 peer_parent->peers.append(peer_result);
7147 IrInstruction *else_result = ir_gen_node_extra(irb, else_node, err_scope, lval, &peer_result->base);
7148 if (else_result == irb->codegen->invalid_instruction)
8178 IrInstSrc *else_result = ir_gen_node_extra(irb, else_node, err_scope, lval, &peer_result->base);
8179 if (else_result == irb->codegen->invalid_inst_src)
71498180 return else_result;
71508181 if (!instr_is_unreachable(else_result))
71518182 ir_mark_gen(ir_build_br(irb, scope, node, end_block, is_comptime));
7152 IrBasicBlock *after_else_block = irb->current_basic_block;
8183 IrBasicBlockSrc *after_else_block = irb->current_basic_block;
71538184 ir_set_cursor_at_end_and_append_block(irb, end_block);
71548185 if (else_result) {
71558186 incoming_blocks.append(after_else_block);
......@@ -7162,7 +8193,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
71628193 peer_parent->peers.last()->next_bb = end_block;
71638194 }
71648195
7165 IrInstruction *phi = ir_build_phi(irb, scope, node, incoming_blocks.length,
8196 IrInstSrc *phi = ir_build_phi(irb, scope, node, incoming_blocks.length,
71668197 incoming_blocks.items, incoming_values.items, peer_parent);
71678198 return ir_expr_wrap(irb, scope, phi, result_loc);
71688199 } else if (var_symbol != nullptr) {
......@@ -7174,15 +8205,15 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
71748205 ZigVar *payload_var = ir_create_var(irb, symbol_node, subexpr_scope, var_symbol,
71758206 true, false, false, is_comptime);
71768207 Scope *child_scope = payload_var->child_scope;
7177 IrInstruction *maybe_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope,
8208 IrInstSrc *maybe_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope,
71788209 LValPtr, nullptr);
7179 if (maybe_val_ptr == irb->codegen->invalid_instruction)
8210 if (maybe_val_ptr == irb->codegen->invalid_inst_src)
71808211 return maybe_val_ptr;
7181 IrInstruction *maybe_val = ir_build_load_ptr(irb, scope, node->data.while_expr.condition, maybe_val_ptr);
7182 IrInstruction *is_non_null = ir_build_test_nonnull(irb, scope, node->data.while_expr.condition, maybe_val);
7183 IrBasicBlock *after_cond_block = irb->current_basic_block;
7184 IrInstruction *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node));
7185 IrInstruction *cond_br_inst;
8212 IrInstSrc *maybe_val = ir_build_load_ptr(irb, scope, node->data.while_expr.condition, maybe_val_ptr);
8213 IrInstSrc *is_non_null = ir_build_test_non_null_src(irb, scope, node->data.while_expr.condition, maybe_val);
8214 IrBasicBlockSrc *after_cond_block = irb->current_basic_block;
8215 IrInstSrc *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node));
8216 IrInstSrc *cond_br_inst;
71868217 if (!instr_is_unreachable(is_non_null)) {
71878218 cond_br_inst = ir_build_cond_br(irb, scope, node->data.while_expr.condition, is_non_null,
71888219 body_block, else_block, is_comptime);
......@@ -7196,13 +8227,13 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
71968227 is_comptime);
71978228
71988229 ir_set_cursor_at_end_and_append_block(irb, body_block);
7199 IrInstruction *payload_ptr = ir_build_optional_unwrap_ptr(irb, child_scope, symbol_node, maybe_val_ptr, false, false);
7200 IrInstruction *var_ptr = node->data.while_expr.var_is_ptr ?
7201 ir_build_ref(irb, child_scope, symbol_node, payload_ptr, true, false) : payload_ptr;
8230 IrInstSrc *payload_ptr = ir_build_optional_unwrap_ptr(irb, child_scope, symbol_node, maybe_val_ptr, false, false);
8231 IrInstSrc *var_ptr = node->data.while_expr.var_is_ptr ?
8232 ir_build_ref_src(irb, child_scope, symbol_node, payload_ptr, true, false) : payload_ptr;
72028233 ir_build_var_decl_src(irb, child_scope, symbol_node, payload_var, nullptr, var_ptr);
72038234
7204 ZigList<IrInstruction *> incoming_values = {0};
7205 ZigList<IrBasicBlock *> incoming_blocks = {0};
8235 ZigList<IrInstSrc *> incoming_values = {0};
8236 ZigList<IrBasicBlockSrc *> incoming_blocks = {0};
72068237
72078238 ScopeLoop *loop_scope = create_loop_scope(irb->codegen, node, child_scope);
72088239 loop_scope->break_block = end_block;
......@@ -7216,8 +8247,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
72168247 // Note the body block of the loop is not the place that lval and result_loc are used -
72178248 // it's actually in break statements, handled similarly to return statements.
72188249 // That is why we set those values in loop_scope above and not in this ir_gen_node call.
7219 IrInstruction *body_result = ir_gen_node(irb, node->data.while_expr.body, &loop_scope->base);
7220 if (body_result == irb->codegen->invalid_instruction)
8250 IrInstSrc *body_result = ir_gen_node(irb, node->data.while_expr.body, &loop_scope->base);
8251 if (body_result == irb->codegen->invalid_inst_src)
72218252 return body_result;
72228253
72238254 if (!instr_is_unreachable(body_result)) {
......@@ -7227,8 +8258,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
72278258
72288259 if (continue_expr_node) {
72298260 ir_set_cursor_at_end_and_append_block(irb, continue_block);
7230 IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, child_scope);
7231 if (expr_result == irb->codegen->invalid_instruction)
8261 IrInstSrc *expr_result = ir_gen_node(irb, continue_expr_node, child_scope);
8262 if (expr_result == irb->codegen->invalid_inst_src)
72328263 return expr_result;
72338264 if (!instr_is_unreachable(expr_result)) {
72348265 ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, continue_expr_node, expr_result));
......@@ -7236,7 +8267,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
72368267 }
72378268 }
72388269
7239 IrInstruction *else_result = nullptr;
8270 IrInstSrc *else_result = nullptr;
72408271 if (else_node) {
72418272 ir_set_cursor_at_end_and_append_block(irb, else_block);
72428273
......@@ -7246,12 +8277,12 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
72468277 ResultLocPeer *peer_result = create_peer_result(peer_parent);
72478278 peer_parent->peers.append(peer_result);
72488279 else_result = ir_gen_node_extra(irb, else_node, scope, lval, &peer_result->base);
7249 if (else_result == irb->codegen->invalid_instruction)
8280 if (else_result == irb->codegen->invalid_inst_src)
72508281 return else_result;
72518282 if (!instr_is_unreachable(else_result))
72528283 ir_mark_gen(ir_build_br(irb, scope, node, end_block, is_comptime));
72538284 }
7254 IrBasicBlock *after_else_block = irb->current_basic_block;
8285 IrBasicBlockSrc *after_else_block = irb->current_basic_block;
72558286 ir_set_cursor_at_end_and_append_block(irb, end_block);
72568287 if (else_result) {
72578288 incoming_blocks.append(after_else_block);
......@@ -7264,17 +8295,17 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
72648295 peer_parent->peers.last()->next_bb = end_block;
72658296 }
72668297
7267 IrInstruction *phi = ir_build_phi(irb, scope, node, incoming_blocks.length,
8298 IrInstSrc *phi = ir_build_phi(irb, scope, node, incoming_blocks.length,
72688299 incoming_blocks.items, incoming_values.items, peer_parent);
72698300 return ir_expr_wrap(irb, scope, phi, result_loc);
72708301 } else {
72718302 ir_set_cursor_at_end_and_append_block(irb, cond_block);
7272 IrInstruction *cond_val = ir_gen_node(irb, node->data.while_expr.condition, scope);
7273 if (cond_val == irb->codegen->invalid_instruction)
8303 IrInstSrc *cond_val = ir_gen_node(irb, node->data.while_expr.condition, scope);
8304 if (cond_val == irb->codegen->invalid_inst_src)
72748305 return cond_val;
7275 IrBasicBlock *after_cond_block = irb->current_basic_block;
7276 IrInstruction *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node));
7277 IrInstruction *cond_br_inst;
8306 IrBasicBlockSrc *after_cond_block = irb->current_basic_block;
8307 IrInstSrc *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node));
8308 IrInstSrc *cond_br_inst;
72788309 if (!instr_is_unreachable(cond_val)) {
72798310 cond_br_inst = ir_build_cond_br(irb, scope, node->data.while_expr.condition, cond_val,
72808311 body_block, else_block, is_comptime);
......@@ -7288,8 +8319,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
72888319 is_comptime);
72898320 ir_set_cursor_at_end_and_append_block(irb, body_block);
72908321
7291 ZigList<IrInstruction *> incoming_values = {0};
7292 ZigList<IrBasicBlock *> incoming_blocks = {0};
8322 ZigList<IrInstSrc *> incoming_values = {0};
8323 ZigList<IrBasicBlockSrc *> incoming_blocks = {0};
72938324
72948325 Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, scope, is_comptime);
72958326
......@@ -7305,8 +8336,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
73058336 // Note the body block of the loop is not the place that lval and result_loc are used -
73068337 // it's actually in break statements, handled similarly to return statements.
73078338 // That is why we set those values in loop_scope above and not in this ir_gen_node call.
7308 IrInstruction *body_result = ir_gen_node(irb, node->data.while_expr.body, &loop_scope->base);
7309 if (body_result == irb->codegen->invalid_instruction)
8339 IrInstSrc *body_result = ir_gen_node(irb, node->data.while_expr.body, &loop_scope->base);
8340 if (body_result == irb->codegen->invalid_inst_src)
73108341 return body_result;
73118342
73128343 if (!instr_is_unreachable(body_result)) {
......@@ -7316,8 +8347,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
73168347
73178348 if (continue_expr_node) {
73188349 ir_set_cursor_at_end_and_append_block(irb, continue_block);
7319 IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, subexpr_scope);
7320 if (expr_result == irb->codegen->invalid_instruction)
8350 IrInstSrc *expr_result = ir_gen_node(irb, continue_expr_node, subexpr_scope);
8351 if (expr_result == irb->codegen->invalid_inst_src)
73218352 return expr_result;
73228353 if (!instr_is_unreachable(expr_result)) {
73238354 ir_mark_gen(ir_build_check_statement_is_void(irb, scope, continue_expr_node, expr_result));
......@@ -7325,7 +8356,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
73258356 }
73268357 }
73278358
7328 IrInstruction *else_result = nullptr;
8359 IrInstSrc *else_result = nullptr;
73298360 if (else_node) {
73308361 ir_set_cursor_at_end_and_append_block(irb, else_block);
73318362
......@@ -7336,12 +8367,12 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
73368367 peer_parent->peers.append(peer_result);
73378368
73388369 else_result = ir_gen_node_extra(irb, else_node, subexpr_scope, lval, &peer_result->base);
7339 if (else_result == irb->codegen->invalid_instruction)
8370 if (else_result == irb->codegen->invalid_inst_src)
73408371 return else_result;
73418372 if (!instr_is_unreachable(else_result))
73428373 ir_mark_gen(ir_build_br(irb, scope, node, end_block, is_comptime));
73438374 }
7344 IrBasicBlock *after_else_block = irb->current_basic_block;
8375 IrBasicBlockSrc *after_else_block = irb->current_basic_block;
73458376 ir_set_cursor_at_end_and_append_block(irb, end_block);
73468377 if (else_result) {
73478378 incoming_blocks.append(after_else_block);
......@@ -7354,13 +8385,13 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
73548385 peer_parent->peers.last()->next_bb = end_block;
73558386 }
73568387
7357 IrInstruction *phi = ir_build_phi(irb, scope, node, incoming_blocks.length,
8388 IrInstSrc *phi = ir_build_phi(irb, scope, node, incoming_blocks.length,
73588389 incoming_blocks.items, incoming_values.items, peer_parent);
73598390 return ir_expr_wrap(irb, scope, phi, result_loc);
73608391 }
73618392}
73628393
7363static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNode *node, LVal lval,
8394static IrInstSrc *ir_gen_for_expr(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node, LVal lval,
73648395 ResultLoc *result_loc)
73658396{
73668397 assert(node->type == NodeTypeForExpr);
......@@ -7373,17 +8404,17 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
73738404
73748405 if (!elem_node) {
73758406 add_node_error(irb->codegen, node, buf_sprintf("for loop expression missing element parameter"));
7376 return irb->codegen->invalid_instruction;
8407 return irb->codegen->invalid_inst_src;
73778408 }
73788409 assert(elem_node->type == NodeTypeSymbol);
73798410
73808411 ScopeExpr *spill_scope = create_expr_scope(irb->codegen, node, parent_scope);
73818412
7382 IrInstruction *array_val_ptr = ir_gen_node_extra(irb, array_node, &spill_scope->base, LValPtr, nullptr);
7383 if (array_val_ptr == irb->codegen->invalid_instruction)
8413 IrInstSrc *array_val_ptr = ir_gen_node_extra(irb, array_node, &spill_scope->base, LValPtr, nullptr);
8414 if (array_val_ptr == irb->codegen->invalid_inst_src)
73848415 return array_val_ptr;
73858416
7386 IrInstruction *is_comptime = ir_build_const_bool(irb, parent_scope, node,
8417 IrInstSrc *is_comptime = ir_build_const_bool(irb, parent_scope, node,
73878418 ir_should_inline(irb->exec, parent_scope) || node->data.for_expr.is_inline);
73888419
73898420 AstNode *index_var_source_node;
......@@ -7400,50 +8431,50 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
74008431 index_var_name = "i";
74018432 }
74028433
7403 IrInstruction *zero = ir_build_const_usize(irb, parent_scope, node, 0);
8434 IrInstSrc *zero = ir_build_const_usize(irb, parent_scope, node, 0);
74048435 build_decl_var_and_init(irb, parent_scope, index_var_source_node, index_var, zero, index_var_name, is_comptime);
74058436 parent_scope = index_var->child_scope;
74068437
7407 IrInstruction *one = ir_build_const_usize(irb, parent_scope, node, 1);
7408 IrInstruction *index_ptr = ir_build_var_ptr(irb, parent_scope, node, index_var);
8438 IrInstSrc *one = ir_build_const_usize(irb, parent_scope, node, 1);
8439 IrInstSrc *index_ptr = ir_build_var_ptr(irb, parent_scope, node, index_var);
74098440
74108441
7411 IrBasicBlock *cond_block = ir_create_basic_block(irb, parent_scope, "ForCond");
7412 IrBasicBlock *body_block = ir_create_basic_block(irb, parent_scope, "ForBody");
7413 IrBasicBlock *end_block = ir_create_basic_block(irb, parent_scope, "ForEnd");
7414 IrBasicBlock *else_block = else_node ? ir_create_basic_block(irb, parent_scope, "ForElse") : end_block;
7415 IrBasicBlock *continue_block = ir_create_basic_block(irb, parent_scope, "ForContinue");
8442 IrBasicBlockSrc *cond_block = ir_create_basic_block(irb, parent_scope, "ForCond");
8443 IrBasicBlockSrc *body_block = ir_create_basic_block(irb, parent_scope, "ForBody");
8444 IrBasicBlockSrc *end_block = ir_create_basic_block(irb, parent_scope, "ForEnd");
8445 IrBasicBlockSrc *else_block = else_node ? ir_create_basic_block(irb, parent_scope, "ForElse") : end_block;
8446 IrBasicBlockSrc *continue_block = ir_create_basic_block(irb, parent_scope, "ForContinue");
74168447
74178448 Buf *len_field_name = buf_create_from_str("len");
7418 IrInstruction *len_ref = ir_build_field_ptr(irb, parent_scope, node, array_val_ptr, len_field_name, false);
7419 IrInstruction *len_val = ir_build_load_ptr(irb, &spill_scope->base, node, len_ref);
8449 IrInstSrc *len_ref = ir_build_field_ptr(irb, parent_scope, node, array_val_ptr, len_field_name, false);
8450 IrInstSrc *len_val = ir_build_load_ptr(irb, &spill_scope->base, node, len_ref);
74208451 ir_build_br(irb, parent_scope, node, cond_block, is_comptime);
74218452
74228453 ir_set_cursor_at_end_and_append_block(irb, cond_block);
7423 IrInstruction *index_val = ir_build_load_ptr(irb, &spill_scope->base, node, index_ptr);
7424 IrInstruction *cond = ir_build_bin_op(irb, parent_scope, node, IrBinOpCmpLessThan, index_val, len_val, false);
7425 IrBasicBlock *after_cond_block = irb->current_basic_block;
7426 IrInstruction *void_else_value = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, parent_scope, node));
7427 IrInstruction *cond_br_inst = ir_mark_gen(ir_build_cond_br(irb, parent_scope, node, cond,
8454 IrInstSrc *index_val = ir_build_load_ptr(irb, &spill_scope->base, node, index_ptr);
8455 IrInstSrc *cond = ir_build_bin_op(irb, parent_scope, node, IrBinOpCmpLessThan, index_val, len_val, false);
8456 IrBasicBlockSrc *after_cond_block = irb->current_basic_block;
8457 IrInstSrc *void_else_value = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, parent_scope, node));
8458 IrInstSrc *cond_br_inst = ir_mark_gen(ir_build_cond_br(irb, parent_scope, node, cond,
74288459 body_block, else_block, is_comptime));
74298460
74308461 ResultLocPeerParent *peer_parent = ir_build_result_peers(irb, cond_br_inst, end_block, result_loc, is_comptime);
74318462
74328463 ir_set_cursor_at_end_and_append_block(irb, body_block);
74338464 Scope *elem_ptr_scope = node->data.for_expr.elem_is_ptr ? parent_scope : &spill_scope->base;
7434 IrInstruction *elem_ptr = ir_build_elem_ptr(irb, elem_ptr_scope, node, array_val_ptr, index_val, false,
8465 IrInstSrc *elem_ptr = ir_build_elem_ptr(irb, elem_ptr_scope, node, array_val_ptr, index_val, false,
74358466 PtrLenSingle, nullptr);
74368467 // TODO make it an error to write to element variable or i variable.
74378468 Buf *elem_var_name = elem_node->data.symbol_expr.symbol;
74388469 ZigVar *elem_var = ir_create_var(irb, elem_node, parent_scope, elem_var_name, true, false, false, is_comptime);
74398470 Scope *child_scope = elem_var->child_scope;
74408471
7441 IrInstruction *var_ptr = node->data.for_expr.elem_is_ptr ?
7442 ir_build_ref(irb, &spill_scope->base, elem_node, elem_ptr, true, false) : elem_ptr;
8472 IrInstSrc *var_ptr = node->data.for_expr.elem_is_ptr ?
8473 ir_build_ref_src(irb, &spill_scope->base, elem_node, elem_ptr, true, false) : elem_ptr;
74438474 ir_build_var_decl_src(irb, parent_scope, elem_node, elem_var, nullptr, var_ptr);
74448475
7445 ZigList<IrInstruction *> incoming_values = {0};
7446 ZigList<IrBasicBlock *> incoming_blocks = {0};
8476 ZigList<IrInstSrc *> incoming_values = {0};
8477 ZigList<IrBasicBlockSrc *> incoming_blocks = {0};
74478478 ScopeLoop *loop_scope = create_loop_scope(irb->codegen, node, child_scope);
74488479 loop_scope->break_block = end_block;
74498480 loop_scope->continue_block = continue_block;
......@@ -7457,9 +8488,9 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
74578488 // Note the body block of the loop is not the place that lval and result_loc are used -
74588489 // it's actually in break statements, handled similarly to return statements.
74598490 // That is why we set those values in loop_scope above and not in this ir_gen_node call.
7460 IrInstruction *body_result = ir_gen_node(irb, body_node, &loop_scope->base);
7461 if (body_result == irb->codegen->invalid_instruction)
7462 return irb->codegen->invalid_instruction;
8491 IrInstSrc *body_result = ir_gen_node(irb, body_node, &loop_scope->base);
8492 if (body_result == irb->codegen->invalid_inst_src)
8493 return irb->codegen->invalid_inst_src;
74638494
74648495 if (!instr_is_unreachable(body_result)) {
74658496 ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, node->data.for_expr.body, body_result));
......@@ -7467,11 +8498,11 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
74678498 }
74688499
74698500 ir_set_cursor_at_end_and_append_block(irb, continue_block);
7470 IrInstruction *new_index_val = ir_build_bin_op(irb, child_scope, node, IrBinOpAdd, index_val, one, false);
8501 IrInstSrc *new_index_val = ir_build_bin_op(irb, child_scope, node, IrBinOpAdd, index_val, one, false);
74718502 ir_build_store_ptr(irb, child_scope, node, index_ptr, new_index_val)->allow_write_through_const = true;
74728503 ir_build_br(irb, child_scope, node, cond_block, is_comptime);
74738504
7474 IrInstruction *else_result = nullptr;
8505 IrInstSrc *else_result = nullptr;
74758506 if (else_node) {
74768507 ir_set_cursor_at_end_and_append_block(irb, else_block);
74778508
......@@ -7481,12 +8512,12 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
74818512 ResultLocPeer *peer_result = create_peer_result(peer_parent);
74828513 peer_parent->peers.append(peer_result);
74838514 else_result = ir_gen_node_extra(irb, else_node, parent_scope, LValNone, &peer_result->base);
7484 if (else_result == irb->codegen->invalid_instruction)
8515 if (else_result == irb->codegen->invalid_inst_src)
74858516 return else_result;
74868517 if (!instr_is_unreachable(else_result))
74878518 ir_mark_gen(ir_build_br(irb, parent_scope, node, end_block, is_comptime));
74888519 }
7489 IrBasicBlock *after_else_block = irb->current_basic_block;
8520 IrBasicBlockSrc *after_else_block = irb->current_basic_block;
74908521 ir_set_cursor_at_end_and_append_block(irb, end_block);
74918522
74928523 if (else_result) {
......@@ -7500,29 +8531,29 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
75008531 peer_parent->peers.last()->next_bb = end_block;
75018532 }
75028533
7503 IrInstruction *phi = ir_build_phi(irb, parent_scope, node, incoming_blocks.length,
8534 IrInstSrc *phi = ir_build_phi(irb, parent_scope, node, incoming_blocks.length,
75048535 incoming_blocks.items, incoming_values.items, peer_parent);
75058536 return ir_lval_wrap(irb, parent_scope, phi, lval, result_loc);
75068537}
75078538
7508static IrInstruction *ir_gen_bool_literal(IrBuilder *irb, Scope *scope, AstNode *node) {
8539static IrInstSrc *ir_gen_bool_literal(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
75098540 assert(node->type == NodeTypeBoolLiteral);
75108541 return ir_build_const_bool(irb, scope, node, node->data.bool_literal.value);
75118542}
75128543
7513static IrInstruction *ir_gen_enum_literal(IrBuilder *irb, Scope *scope, AstNode *node) {
8544static IrInstSrc *ir_gen_enum_literal(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
75148545 assert(node->type == NodeTypeEnumLiteral);
75158546 Buf *name = &node->data.enum_literal.identifier->data.str_lit.str;
75168547 return ir_build_const_enum_literal(irb, scope, node, name);
75178548}
75188549
7519static IrInstruction *ir_gen_string_literal(IrBuilder *irb, Scope *scope, AstNode *node) {
8550static IrInstSrc *ir_gen_string_literal(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
75208551 assert(node->type == NodeTypeStringLiteral);
75218552
75228553 return ir_build_const_str_lit(irb, scope, node, node->data.string_literal.buf);
75238554}
75248555
7525static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *node) {
8556static IrInstSrc *ir_gen_array_type(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
75268557 assert(node->type == NodeTypeArrayType);
75278558
75288559 AstNode *size_node = node->data.array_type.size;
......@@ -7535,10 +8566,10 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *n
75358566
75368567 Scope *comptime_scope = create_comptime_scope(irb->codegen, node, scope);
75378568
7538 IrInstruction *sentinel;
8569 IrInstSrc *sentinel;
75398570 if (sentinel_expr != nullptr) {
75408571 sentinel = ir_gen_node(irb, sentinel_expr, comptime_scope);
7541 if (sentinel == irb->codegen->invalid_instruction)
8572 if (sentinel == irb->codegen->invalid_inst_src)
75428573 return sentinel;
75438574 } else {
75448575 sentinel = nullptr;
......@@ -7547,42 +8578,42 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *n
75478578 if (size_node) {
75488579 if (is_const) {
75498580 add_node_error(irb->codegen, node, buf_create_from_str("const qualifier invalid on array type"));
7550 return irb->codegen->invalid_instruction;
8581 return irb->codegen->invalid_inst_src;
75518582 }
75528583 if (is_volatile) {
75538584 add_node_error(irb->codegen, node, buf_create_from_str("volatile qualifier invalid on array type"));
7554 return irb->codegen->invalid_instruction;
8585 return irb->codegen->invalid_inst_src;
75558586 }
75568587 if (is_allow_zero) {
75578588 add_node_error(irb->codegen, node, buf_create_from_str("allowzero qualifier invalid on array type"));
7558 return irb->codegen->invalid_instruction;
8589 return irb->codegen->invalid_inst_src;
75598590 }
75608591 if (align_expr != nullptr) {
75618592 add_node_error(irb->codegen, node, buf_create_from_str("align qualifier invalid on array type"));
7562 return irb->codegen->invalid_instruction;
8593 return irb->codegen->invalid_inst_src;
75638594 }
75648595
7565 IrInstruction *size_value = ir_gen_node(irb, size_node, comptime_scope);
7566 if (size_value == irb->codegen->invalid_instruction)
8596 IrInstSrc *size_value = ir_gen_node(irb, size_node, comptime_scope);
8597 if (size_value == irb->codegen->invalid_inst_src)
75678598 return size_value;
75688599
7569 IrInstruction *child_type = ir_gen_node(irb, child_type_node, comptime_scope);
7570 if (child_type == irb->codegen->invalid_instruction)
8600 IrInstSrc *child_type = ir_gen_node(irb, child_type_node, comptime_scope);
8601 if (child_type == irb->codegen->invalid_inst_src)
75718602 return child_type;
75728603
75738604 return ir_build_array_type(irb, scope, node, size_value, sentinel, child_type);
75748605 } else {
7575 IrInstruction *align_value;
8606 IrInstSrc *align_value;
75768607 if (align_expr != nullptr) {
75778608 align_value = ir_gen_node(irb, align_expr, comptime_scope);
7578 if (align_value == irb->codegen->invalid_instruction)
8609 if (align_value == irb->codegen->invalid_inst_src)
75798610 return align_value;
75808611 } else {
75818612 align_value = nullptr;
75828613 }
75838614
7584 IrInstruction *child_type = ir_gen_node(irb, child_type_node, comptime_scope);
7585 if (child_type == irb->codegen->invalid_instruction)
8615 IrInstSrc *child_type = ir_gen_node(irb, child_type_node, comptime_scope);
8616 if (child_type == irb->codegen->invalid_inst_src)
75868617 return child_type;
75878618
75888619 return ir_build_slice_type(irb, scope, node, child_type, is_const, is_volatile, sentinel,
......@@ -7590,15 +8621,15 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *n
75908621 }
75918622}
75928623
7593static IrInstruction *ir_gen_anyframe_type(IrBuilder *irb, Scope *scope, AstNode *node) {
8624static IrInstSrc *ir_gen_anyframe_type(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
75948625 assert(node->type == NodeTypeAnyFrameType);
75958626
75968627 AstNode *payload_type_node = node->data.anyframe_type.payload_type;
7597 IrInstruction *payload_type_value = nullptr;
8628 IrInstSrc *payload_type_value = nullptr;
75988629
75998630 if (payload_type_node != nullptr) {
76008631 payload_type_value = ir_gen_node(irb, payload_type_node, scope);
7601 if (payload_type_value == irb->codegen->invalid_instruction)
8632 if (payload_type_value == irb->codegen->invalid_inst_src)
76028633 return payload_type_value;
76038634
76048635 }
......@@ -7606,7 +8637,7 @@ static IrInstruction *ir_gen_anyframe_type(IrBuilder *irb, Scope *scope, AstNode
76068637 return ir_build_anyframe_type(irb, scope, node, payload_type_value);
76078638}
76088639
7609static IrInstruction *ir_gen_undefined_literal(IrBuilder *irb, Scope *scope, AstNode *node) {
8640static IrInstSrc *ir_gen_undefined_literal(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
76108641 assert(node->type == NodeTypeUndefinedLiteral);
76118642 return ir_build_const_undefined(irb, scope, node);
76128643}
......@@ -7723,13 +8754,13 @@ static size_t find_asm_index(CodeGen *g, AstNode *node, AsmToken *tok, Buf *src_
77238754 return SIZE_MAX;
77248755}
77258756
7726static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *node) {
8757static IrInstSrc *ir_gen_asm_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
77278758 assert(node->type == NodeTypeAsmExpr);
77288759 AstNodeAsmExpr *asm_expr = &node->data.asm_expr;
77298760
7730 IrInstruction *asm_template = ir_gen_node(irb, asm_expr->asm_template, scope);
7731 if (asm_template == irb->codegen->invalid_instruction)
7732 return irb->codegen->invalid_instruction;
8761 IrInstSrc *asm_template = ir_gen_node(irb, asm_expr->asm_template, scope);
8762 if (asm_template == irb->codegen->invalid_inst_src)
8763 return irb->codegen->invalid_inst_src;
77338764
77348765 bool is_volatile = asm_expr->volatile_token != nullptr;
77358766 bool in_fn_scope = (scope_fn_entry(scope) != nullptr);
......@@ -7738,7 +8769,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod
77388769 if (is_volatile) {
77398770 add_token_error(irb->codegen, node->owner, asm_expr->volatile_token,
77408771 buf_sprintf("volatile is meaningless on global assembly"));
7741 return irb->codegen->invalid_instruction;
8772 return irb->codegen->invalid_inst_src;
77428773 }
77438774
77448775 if (asm_expr->output_list.length != 0 || asm_expr->input_list.length != 0 ||
......@@ -7746,34 +8777,34 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod
77468777 {
77478778 add_node_error(irb->codegen, node,
77488779 buf_sprintf("global assembly cannot have inputs, outputs, or clobbers"));
7749 return irb->codegen->invalid_instruction;
8780 return irb->codegen->invalid_inst_src;
77508781 }
77518782
77528783 return ir_build_asm_src(irb, scope, node, asm_template, nullptr, nullptr,
77538784 nullptr, 0, is_volatile, true);
77548785 }
77558786
7756 IrInstruction **input_list = allocate<IrInstruction *>(asm_expr->input_list.length);
7757 IrInstruction **output_types = allocate<IrInstruction *>(asm_expr->output_list.length);
8787 IrInstSrc **input_list = allocate<IrInstSrc *>(asm_expr->input_list.length);
8788 IrInstSrc **output_types = allocate<IrInstSrc *>(asm_expr->output_list.length);
77588789 ZigVar **output_vars = allocate<ZigVar *>(asm_expr->output_list.length);
77598790 size_t return_count = 0;
77608791 if (!is_volatile && asm_expr->output_list.length == 0) {
77618792 add_node_error(irb->codegen, node,
77628793 buf_sprintf("assembly expression with no output must be marked volatile"));
7763 return irb->codegen->invalid_instruction;
8794 return irb->codegen->invalid_inst_src;
77648795 }
77658796 for (size_t i = 0; i < asm_expr->output_list.length; i += 1) {
77668797 AsmOutput *asm_output = asm_expr->output_list.at(i);
77678798 if (asm_output->return_type) {
77688799 return_count += 1;
77698800
7770 IrInstruction *return_type = ir_gen_node(irb, asm_output->return_type, scope);
7771 if (return_type == irb->codegen->invalid_instruction)
7772 return irb->codegen->invalid_instruction;
8801 IrInstSrc *return_type = ir_gen_node(irb, asm_output->return_type, scope);
8802 if (return_type == irb->codegen->invalid_inst_src)
8803 return irb->codegen->invalid_inst_src;
77738804 if (return_count > 1) {
77748805 add_node_error(irb->codegen, node,
77758806 buf_sprintf("inline assembly allows up to one output value"));
7776 return irb->codegen->invalid_instruction;
8807 return irb->codegen->invalid_inst_src;
77778808 }
77788809 output_types[i] = return_type;
77798810 } else {
......@@ -7786,7 +8817,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod
77868817 } else {
77878818 add_node_error(irb->codegen, node,
77888819 buf_sprintf("use of undeclared identifier '%s'", buf_ptr(variable_name)));
7789 return irb->codegen->invalid_instruction;
8820 return irb->codegen->invalid_inst_src;
77908821 }
77918822 }
77928823
......@@ -7796,14 +8827,14 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod
77968827 buf_sprintf("invalid modifier starting output constraint for '%s': '%c', only '=' is supported."
77978828 " Compiler TODO: see https://github.com/ziglang/zig/issues/215",
77988829 buf_ptr(asm_output->asm_symbolic_name), modifier));
7799 return irb->codegen->invalid_instruction;
8830 return irb->codegen->invalid_inst_src;
78008831 }
78018832 }
78028833 for (size_t i = 0; i < asm_expr->input_list.length; i += 1) {
78038834 AsmInput *asm_input = asm_expr->input_list.at(i);
7804 IrInstruction *input_value = ir_gen_node(irb, asm_input->expr, scope);
7805 if (input_value == irb->codegen->invalid_instruction)
7806 return irb->codegen->invalid_instruction;
8835 IrInstSrc *input_value = ir_gen_node(irb, asm_input->expr, scope);
8836 if (input_value == irb->codegen->invalid_inst_src)
8837 return irb->codegen->invalid_inst_src;
78078838
78088839 input_list[i] = input_value;
78098840 }
......@@ -7812,7 +8843,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod
78128843 output_vars, return_count, is_volatile, false);
78138844}
78148845
7815static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,
8846static IrInstSrc *ir_gen_if_optional_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
78168847 ResultLoc *result_loc)
78178848{
78188849 assert(node->type == NodeTypeIfOptional);
......@@ -7823,24 +8854,24 @@ static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstN
78238854 AstNode *else_node = node->data.test_expr.else_node;
78248855 bool var_is_ptr = node->data.test_expr.var_is_ptr;
78258856
7826 IrInstruction *maybe_val_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
7827 if (maybe_val_ptr == irb->codegen->invalid_instruction)
8857 IrInstSrc *maybe_val_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
8858 if (maybe_val_ptr == irb->codegen->invalid_inst_src)
78288859 return maybe_val_ptr;
78298860
7830 IrInstruction *maybe_val = ir_build_load_ptr(irb, scope, node, maybe_val_ptr);
7831 IrInstruction *is_non_null = ir_build_test_nonnull(irb, scope, node, maybe_val);
8861 IrInstSrc *maybe_val = ir_build_load_ptr(irb, scope, node, maybe_val_ptr);
8862 IrInstSrc *is_non_null = ir_build_test_non_null_src(irb, scope, node, maybe_val);
78328863
7833 IrBasicBlock *then_block = ir_create_basic_block(irb, scope, "OptionalThen");
7834 IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "OptionalElse");
7835 IrBasicBlock *endif_block = ir_create_basic_block(irb, scope, "OptionalEndIf");
8864 IrBasicBlockSrc *then_block = ir_create_basic_block(irb, scope, "OptionalThen");
8865 IrBasicBlockSrc *else_block = ir_create_basic_block(irb, scope, "OptionalElse");
8866 IrBasicBlockSrc *endif_block = ir_create_basic_block(irb, scope, "OptionalEndIf");
78368867
7837 IrInstruction *is_comptime;
8868 IrInstSrc *is_comptime;
78388869 if (ir_should_inline(irb->exec, scope)) {
78398870 is_comptime = ir_build_const_bool(irb, scope, node, true);
78408871 } else {
78418872 is_comptime = ir_build_test_comptime(irb, scope, node, is_non_null);
78428873 }
7843 IrInstruction *cond_br_inst = ir_build_cond_br(irb, scope, node, is_non_null,
8874 IrInstSrc *cond_br_inst = ir_build_cond_br(irb, scope, node, is_non_null,
78448875 then_block, else_block, is_comptime);
78458876
78468877 ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, endif_block,
......@@ -7856,48 +8887,48 @@ static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstN
78568887 ZigVar *var = ir_create_var(irb, node, subexpr_scope,
78578888 var_symbol, is_const, is_const, is_shadowable, is_comptime);
78588889
7859 IrInstruction *payload_ptr = ir_build_optional_unwrap_ptr(irb, subexpr_scope, node, maybe_val_ptr, false, false);
7860 IrInstruction *var_ptr = var_is_ptr ? ir_build_ref(irb, subexpr_scope, node, payload_ptr, true, false) : payload_ptr;
8890 IrInstSrc *payload_ptr = ir_build_optional_unwrap_ptr(irb, subexpr_scope, node, maybe_val_ptr, false, false);
8891 IrInstSrc *var_ptr = var_is_ptr ? ir_build_ref_src(irb, subexpr_scope, node, payload_ptr, true, false) : payload_ptr;
78618892 ir_build_var_decl_src(irb, subexpr_scope, node, var, nullptr, var_ptr);
78628893 var_scope = var->child_scope;
78638894 } else {
78648895 var_scope = subexpr_scope;
78658896 }
7866 IrInstruction *then_expr_result = ir_gen_node_extra(irb, then_node, var_scope, lval,
8897 IrInstSrc *then_expr_result = ir_gen_node_extra(irb, then_node, var_scope, lval,
78678898 &peer_parent->peers.at(0)->base);
7868 if (then_expr_result == irb->codegen->invalid_instruction)
8899 if (then_expr_result == irb->codegen->invalid_inst_src)
78698900 return then_expr_result;
7870 IrBasicBlock *after_then_block = irb->current_basic_block;
8901 IrBasicBlockSrc *after_then_block = irb->current_basic_block;
78718902 if (!instr_is_unreachable(then_expr_result))
78728903 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));
78738904
78748905 ir_set_cursor_at_end_and_append_block(irb, else_block);
7875 IrInstruction *else_expr_result;
8906 IrInstSrc *else_expr_result;
78768907 if (else_node) {
78778908 else_expr_result = ir_gen_node_extra(irb, else_node, subexpr_scope, lval, &peer_parent->peers.at(1)->base);
7878 if (else_expr_result == irb->codegen->invalid_instruction)
8909 if (else_expr_result == irb->codegen->invalid_inst_src)
78798910 return else_expr_result;
78808911 } else {
78818912 else_expr_result = ir_build_const_void(irb, scope, node);
78828913 ir_build_end_expr(irb, scope, node, else_expr_result, &peer_parent->peers.at(1)->base);
78838914 }
7884 IrBasicBlock *after_else_block = irb->current_basic_block;
8915 IrBasicBlockSrc *after_else_block = irb->current_basic_block;
78858916 if (!instr_is_unreachable(else_expr_result))
78868917 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));
78878918
78888919 ir_set_cursor_at_end_and_append_block(irb, endif_block);
7889 IrInstruction **incoming_values = allocate<IrInstruction *>(2);
8920 IrInstSrc **incoming_values = allocate<IrInstSrc *>(2);
78908921 incoming_values[0] = then_expr_result;
78918922 incoming_values[1] = else_expr_result;
7892 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *");
8923 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
78938924 incoming_blocks[0] = after_then_block;
78948925 incoming_blocks[1] = after_else_block;
78958926
7896 IrInstruction *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent);
8927 IrInstSrc *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent);
78978928 return ir_expr_wrap(irb, scope, phi, result_loc);
78988929}
78998930
7900static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,
8931static IrInstSrc *ir_gen_if_err_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
79018932 ResultLoc *result_loc)
79028933{
79038934 assert(node->type == NodeTypeIfErrorExpr);
......@@ -7910,20 +8941,20 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
79108941 Buf *var_symbol = node->data.if_err_expr.var_symbol;
79118942 Buf *err_symbol = node->data.if_err_expr.err_symbol;
79128943
7913 IrInstruction *err_val_ptr = ir_gen_node_extra(irb, target_node, scope, LValPtr, nullptr);
7914 if (err_val_ptr == irb->codegen->invalid_instruction)
8944 IrInstSrc *err_val_ptr = ir_gen_node_extra(irb, target_node, scope, LValPtr, nullptr);
8945 if (err_val_ptr == irb->codegen->invalid_inst_src)
79158946 return err_val_ptr;
79168947
7917 IrInstruction *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr);
7918 IrInstruction *is_err = ir_build_test_err_src(irb, scope, node, err_val_ptr, true, false);
8948 IrInstSrc *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr);
8949 IrInstSrc *is_err = ir_build_test_err_src(irb, scope, node, err_val_ptr, true, false);
79198950
7920 IrBasicBlock *ok_block = ir_create_basic_block(irb, scope, "TryOk");
7921 IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "TryElse");
7922 IrBasicBlock *endif_block = ir_create_basic_block(irb, scope, "TryEnd");
8951 IrBasicBlockSrc *ok_block = ir_create_basic_block(irb, scope, "TryOk");
8952 IrBasicBlockSrc *else_block = ir_create_basic_block(irb, scope, "TryElse");
8953 IrBasicBlockSrc *endif_block = ir_create_basic_block(irb, scope, "TryEnd");
79238954
79248955 bool force_comptime = ir_should_inline(irb->exec, scope);
7925 IrInstruction *is_comptime = force_comptime ? ir_build_const_bool(irb, scope, node, true) : ir_build_test_comptime(irb, scope, node, is_err);
7926 IrInstruction *cond_br_inst = ir_build_cond_br(irb, scope, node, is_err, else_block, ok_block, is_comptime);
8956 IrInstSrc *is_comptime = force_comptime ? ir_build_const_bool(irb, scope, node, true) : ir_build_test_comptime(irb, scope, node, is_err);
8957 IrInstSrc *cond_br_inst = ir_build_cond_br(irb, scope, node, is_err, else_block, ok_block, is_comptime);
79278958
79288959 ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, endif_block,
79298960 result_loc, is_comptime);
......@@ -7934,29 +8965,29 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
79348965 Scope *var_scope;
79358966 if (var_symbol) {
79368967 bool is_shadowable = false;
7937 IrInstruction *var_is_comptime = force_comptime ? ir_build_const_bool(irb, subexpr_scope, node, true) : ir_build_test_comptime(irb, subexpr_scope, node, err_val);
8968 IrInstSrc *var_is_comptime = force_comptime ? ir_build_const_bool(irb, subexpr_scope, node, true) : ir_build_test_comptime(irb, subexpr_scope, node, err_val);
79388969 ZigVar *var = ir_create_var(irb, node, subexpr_scope,
79398970 var_symbol, var_is_const, var_is_const, is_shadowable, var_is_comptime);
79408971
7941 IrInstruction *payload_ptr = ir_build_unwrap_err_payload(irb, subexpr_scope, node, err_val_ptr, false, false);
7942 IrInstruction *var_ptr = var_is_ptr ?
7943 ir_build_ref(irb, subexpr_scope, node, payload_ptr, true, false) : payload_ptr;
8972 IrInstSrc *payload_ptr = ir_build_unwrap_err_payload_src(irb, subexpr_scope, node, err_val_ptr, false, false);
8973 IrInstSrc *var_ptr = var_is_ptr ?
8974 ir_build_ref_src(irb, subexpr_scope, node, payload_ptr, true, false) : payload_ptr;
79448975 ir_build_var_decl_src(irb, subexpr_scope, node, var, nullptr, var_ptr);
79458976 var_scope = var->child_scope;
79468977 } else {
79478978 var_scope = subexpr_scope;
79488979 }
7949 IrInstruction *then_expr_result = ir_gen_node_extra(irb, then_node, var_scope, lval,
8980 IrInstSrc *then_expr_result = ir_gen_node_extra(irb, then_node, var_scope, lval,
79508981 &peer_parent->peers.at(0)->base);
7951 if (then_expr_result == irb->codegen->invalid_instruction)
8982 if (then_expr_result == irb->codegen->invalid_inst_src)
79528983 return then_expr_result;
7953 IrBasicBlock *after_then_block = irb->current_basic_block;
8984 IrBasicBlockSrc *after_then_block = irb->current_basic_block;
79548985 if (!instr_is_unreachable(then_expr_result))
79558986 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));
79568987
79578988 ir_set_cursor_at_end_and_append_block(irb, else_block);
79588989
7959 IrInstruction *else_expr_result;
8990 IrInstSrc *else_expr_result;
79608991 if (else_node) {
79618992 Scope *err_var_scope;
79628993 if (err_symbol) {
......@@ -7965,40 +8996,40 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
79658996 ZigVar *var = ir_create_var(irb, node, subexpr_scope,
79668997 err_symbol, is_const, is_const, is_shadowable, is_comptime);
79678998
7968 IrInstruction *err_ptr = ir_build_unwrap_err_code(irb, subexpr_scope, node, err_val_ptr);
8999 IrInstSrc *err_ptr = ir_build_unwrap_err_code_src(irb, subexpr_scope, node, err_val_ptr);
79699000 ir_build_var_decl_src(irb, subexpr_scope, node, var, nullptr, err_ptr);
79709001 err_var_scope = var->child_scope;
79719002 } else {
79729003 err_var_scope = subexpr_scope;
79739004 }
79749005 else_expr_result = ir_gen_node_extra(irb, else_node, err_var_scope, lval, &peer_parent->peers.at(1)->base);
7975 if (else_expr_result == irb->codegen->invalid_instruction)
9006 if (else_expr_result == irb->codegen->invalid_inst_src)
79769007 return else_expr_result;
79779008 } else {
79789009 else_expr_result = ir_build_const_void(irb, scope, node);
79799010 ir_build_end_expr(irb, scope, node, else_expr_result, &peer_parent->peers.at(1)->base);
79809011 }
7981 IrBasicBlock *after_else_block = irb->current_basic_block;
9012 IrBasicBlockSrc *after_else_block = irb->current_basic_block;
79829013 if (!instr_is_unreachable(else_expr_result))
79839014 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));
79849015
79859016 ir_set_cursor_at_end_and_append_block(irb, endif_block);
7986 IrInstruction **incoming_values = allocate<IrInstruction *>(2);
9017 IrInstSrc **incoming_values = allocate<IrInstSrc *>(2);
79879018 incoming_values[0] = then_expr_result;
79889019 incoming_values[1] = else_expr_result;
7989 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *");
9020 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
79909021 incoming_blocks[0] = after_then_block;
79919022 incoming_blocks[1] = after_else_block;
79929023
7993 IrInstruction *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent);
9024 IrInstSrc *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent);
79949025 return ir_expr_wrap(irb, scope, phi, result_loc);
79959026}
79969027
7997static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *switch_node, AstNode *prong_node,
7998 IrBasicBlock *end_block, IrInstruction *is_comptime, IrInstruction *var_is_comptime,
7999 IrInstruction *target_value_ptr, IrInstruction **prong_values, size_t prong_values_len,
8000 ZigList<IrBasicBlock *> *incoming_blocks, ZigList<IrInstruction *> *incoming_values,
8001 IrInstructionSwitchElseVar **out_switch_else_var, LVal lval, ResultLoc *result_loc)
9028static bool ir_gen_switch_prong_expr(IrBuilderSrc *irb, Scope *scope, AstNode *switch_node, AstNode *prong_node,
9029 IrBasicBlockSrc *end_block, IrInstSrc *is_comptime, IrInstSrc *var_is_comptime,
9030 IrInstSrc *target_value_ptr, IrInstSrc **prong_values, size_t prong_values_len,
9031 ZigList<IrBasicBlockSrc *> *incoming_blocks, ZigList<IrInstSrc *> *incoming_values,
9032 IrInstSrcSwitchElseVar **out_switch_else_var, LVal lval, ResultLoc *result_loc)
80029033{
80039034 assert(switch_node->type == NodeTypeSwitchExpr);
80049035 assert(prong_node->type == NodeTypeSwitchProng);
......@@ -8016,28 +9047,28 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *swit
80169047 ZigVar *var = ir_create_var(irb, var_symbol_node, scope,
80179048 var_name, is_const, is_const, is_shadowable, var_is_comptime);
80189049 child_scope = var->child_scope;
8019 IrInstruction *var_ptr;
9050 IrInstSrc *var_ptr;
80209051 if (out_switch_else_var != nullptr) {
8021 IrInstructionSwitchElseVar *switch_else_var = ir_build_switch_else_var(irb, scope, var_symbol_node,
9052 IrInstSrcSwitchElseVar *switch_else_var = ir_build_switch_else_var(irb, scope, var_symbol_node,
80229053 target_value_ptr);
80239054 *out_switch_else_var = switch_else_var;
8024 IrInstruction *payload_ptr = &switch_else_var->base;
8025 var_ptr = var_is_ptr ? ir_build_ref(irb, scope, var_symbol_node, payload_ptr, true, false) : payload_ptr;
9055 IrInstSrc *payload_ptr = &switch_else_var->base;
9056 var_ptr = var_is_ptr ? ir_build_ref_src(irb, scope, var_symbol_node, payload_ptr, true, false) : payload_ptr;
80269057 } else if (prong_values != nullptr) {
8027 IrInstruction *payload_ptr = ir_build_switch_var(irb, scope, var_symbol_node, target_value_ptr,
9058 IrInstSrc *payload_ptr = ir_build_switch_var(irb, scope, var_symbol_node, target_value_ptr,
80289059 prong_values, prong_values_len);
8029 var_ptr = var_is_ptr ? ir_build_ref(irb, scope, var_symbol_node, payload_ptr, true, false) : payload_ptr;
9060 var_ptr = var_is_ptr ? ir_build_ref_src(irb, scope, var_symbol_node, payload_ptr, true, false) : payload_ptr;
80309061 } else {
80319062 var_ptr = var_is_ptr ?
8032 ir_build_ref(irb, scope, var_symbol_node, target_value_ptr, true, false) : target_value_ptr;
9063 ir_build_ref_src(irb, scope, var_symbol_node, target_value_ptr, true, false) : target_value_ptr;
80339064 }
80349065 ir_build_var_decl_src(irb, scope, var_symbol_node, var, nullptr, var_ptr);
80359066 } else {
80369067 child_scope = scope;
80379068 }
80389069
8039 IrInstruction *expr_result = ir_gen_node_extra(irb, expr_node, child_scope, lval, result_loc);
8040 if (expr_result == irb->codegen->invalid_instruction)
9070 IrInstSrc *expr_result = ir_gen_node_extra(irb, expr_node, child_scope, lval, result_loc);
9071 if (expr_result == irb->codegen->invalid_inst_src)
80419072 return false;
80429073 if (!instr_is_unreachable(expr_result))
80439074 ir_mark_gen(ir_build_br(irb, scope, switch_node, end_block, is_comptime));
......@@ -8046,25 +9077,25 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *swit
80469077 return true;
80479078}
80489079
8049static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,
9080static IrInstSrc *ir_gen_switch_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
80509081 ResultLoc *result_loc)
80519082{
80529083 assert(node->type == NodeTypeSwitchExpr);
80539084
80549085 AstNode *target_node = node->data.switch_expr.expr;
8055 IrInstruction *target_value_ptr = ir_gen_node_extra(irb, target_node, scope, LValPtr, nullptr);
8056 if (target_value_ptr == irb->codegen->invalid_instruction)
9086 IrInstSrc *target_value_ptr = ir_gen_node_extra(irb, target_node, scope, LValPtr, nullptr);
9087 if (target_value_ptr == irb->codegen->invalid_inst_src)
80579088 return target_value_ptr;
8058 IrInstruction *target_value = ir_build_switch_target(irb, scope, node, target_value_ptr);
9089 IrInstSrc *target_value = ir_build_switch_target(irb, scope, node, target_value_ptr);
80599090
8060 IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "SwitchElse");
8061 IrBasicBlock *end_block = ir_create_basic_block(irb, scope, "SwitchEnd");
9091 IrBasicBlockSrc *else_block = ir_create_basic_block(irb, scope, "SwitchElse");
9092 IrBasicBlockSrc *end_block = ir_create_basic_block(irb, scope, "SwitchEnd");
80629093
80639094 size_t prong_count = node->data.switch_expr.prongs.length;
8064 ZigList<IrInstructionSwitchBrCase> cases = {0};
9095 ZigList<IrInstSrcSwitchBrCase> cases = {0};
80659096
8066 IrInstruction *is_comptime;
8067 IrInstruction *var_is_comptime;
9097 IrInstSrc *is_comptime;
9098 IrInstSrc *var_is_comptime;
80689099 if (ir_should_inline(irb->exec, scope)) {
80699100 is_comptime = ir_build_const_bool(irb, scope, node, true);
80709101 var_is_comptime = is_comptime;
......@@ -8073,11 +9104,11 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
80739104 var_is_comptime = ir_build_test_comptime(irb, scope, node, target_value_ptr);
80749105 }
80759106
8076 ZigList<IrInstruction *> incoming_values = {0};
8077 ZigList<IrBasicBlock *> incoming_blocks = {0};
8078 ZigList<IrInstructionCheckSwitchProngsRange> check_ranges = {0};
9107 ZigList<IrInstSrc *> incoming_values = {0};
9108 ZigList<IrBasicBlockSrc *> incoming_blocks = {0};
9109 ZigList<IrInstSrcCheckSwitchProngsRange> check_ranges = {0};
80799110
8080 IrInstructionSwitchElseVar *switch_else_var = nullptr;
9111 IrInstSrcSwitchElseVar *switch_else_var = nullptr;
80819112
80829113 ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1);
80839114 peer_parent->base.id = ResultLocIdPeerParent;
......@@ -8099,7 +9130,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
80999130 if (prong_node->data.switch_prong.any_items_are_range) {
81009131 ResultLocPeer *this_peer_result_loc = create_peer_result(peer_parent);
81019132
8102 IrInstruction *ok_bit = nullptr;
9133 IrInstSrc *ok_bit = nullptr;
81039134 AstNode *last_item_node = nullptr;
81049135 for (size_t item_i = 0; item_i < prong_item_count; item_i += 1) {
81059136 AstNode *item_node = prong_node->data.switch_prong.items.at(item_i);
......@@ -8108,23 +9139,23 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
81089139 AstNode *start_node = item_node->data.switch_range.start;
81099140 AstNode *end_node = item_node->data.switch_range.end;
81109141
8111 IrInstruction *start_value = ir_gen_node(irb, start_node, comptime_scope);
8112 if (start_value == irb->codegen->invalid_instruction)
8113 return irb->codegen->invalid_instruction;
9142 IrInstSrc *start_value = ir_gen_node(irb, start_node, comptime_scope);
9143 if (start_value == irb->codegen->invalid_inst_src)
9144 return irb->codegen->invalid_inst_src;
81149145
8115 IrInstruction *end_value = ir_gen_node(irb, end_node, comptime_scope);
8116 if (end_value == irb->codegen->invalid_instruction)
8117 return irb->codegen->invalid_instruction;
9146 IrInstSrc *end_value = ir_gen_node(irb, end_node, comptime_scope);
9147 if (end_value == irb->codegen->invalid_inst_src)
9148 return irb->codegen->invalid_inst_src;
81189149
8119 IrInstructionCheckSwitchProngsRange *check_range = check_ranges.add_one();
9150 IrInstSrcCheckSwitchProngsRange *check_range = check_ranges.add_one();
81209151 check_range->start = start_value;
81219152 check_range->end = end_value;
81229153
8123 IrInstruction *lower_range_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpGreaterOrEq,
9154 IrInstSrc *lower_range_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpGreaterOrEq,
81249155 target_value, start_value, false);
8125 IrInstruction *upper_range_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpLessOrEq,
9156 IrInstSrc *upper_range_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpLessOrEq,
81269157 target_value, end_value, false);
8127 IrInstruction *both_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolAnd,
9158 IrInstSrc *both_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolAnd,
81289159 lower_range_ok, upper_range_ok, false);
81299160 if (ok_bit) {
81309161 ok_bit = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolOr, both_ok, ok_bit, false);
......@@ -8132,15 +9163,15 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
81329163 ok_bit = both_ok;
81339164 }
81349165 } else {
8135 IrInstruction *item_value = ir_gen_node(irb, item_node, comptime_scope);
8136 if (item_value == irb->codegen->invalid_instruction)
8137 return irb->codegen->invalid_instruction;
9166 IrInstSrc *item_value = ir_gen_node(irb, item_node, comptime_scope);
9167 if (item_value == irb->codegen->invalid_inst_src)
9168 return irb->codegen->invalid_inst_src;
81389169
8139 IrInstructionCheckSwitchProngsRange *check_range = check_ranges.add_one();
9170 IrInstSrcCheckSwitchProngsRange *check_range = check_ranges.add_one();
81409171 check_range->start = item_value;
81419172 check_range->end = item_value;
81429173
8143 IrInstruction *cmp_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpEq,
9174 IrInstSrc *cmp_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpEq,
81449175 item_value, target_value, false);
81459176 if (ok_bit) {
81469177 ok_bit = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolOr, cmp_ok, ok_bit, false);
......@@ -8150,12 +9181,12 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
81509181 }
81519182 }
81529183
8153 IrBasicBlock *range_block_yes = ir_create_basic_block(irb, scope, "SwitchRangeYes");
8154 IrBasicBlock *range_block_no = ir_create_basic_block(irb, scope, "SwitchRangeNo");
9184 IrBasicBlockSrc *range_block_yes = ir_create_basic_block(irb, scope, "SwitchRangeYes");
9185 IrBasicBlockSrc *range_block_no = ir_create_basic_block(irb, scope, "SwitchRangeNo");
81559186
81569187 assert(ok_bit);
81579188 assert(last_item_node);
8158 IrInstruction *br_inst = ir_mark_gen(ir_build_cond_br(irb, scope, last_item_node, ok_bit,
9189 IrInstSrc *br_inst = ir_mark_gen(ir_build_cond_br(irb, scope, last_item_node, ok_bit,
81599190 range_block_yes, range_block_no, is_comptime));
81609191 if (peer_parent->base.source_instruction == nullptr) {
81619192 peer_parent->base.source_instruction = br_inst;
......@@ -8170,7 +9201,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
81709201 is_comptime, var_is_comptime, target_value_ptr, nullptr, 0,
81719202 &incoming_blocks, &incoming_values, nullptr, LValNone, &this_peer_result_loc->base))
81729203 {
8173 return irb->codegen->invalid_instruction;
9204 return irb->codegen->invalid_inst_src;
81749205 }
81759206
81769207 ir_set_cursor_at_end_and_append_block(irb, range_block_no);
......@@ -8181,7 +9212,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
81819212 buf_sprintf("multiple else prongs in switch expression"));
81829213 add_error_note(irb->codegen, msg, else_prong,
81839214 buf_sprintf("previous else prong is here"));
8184 return irb->codegen->invalid_instruction;
9215 return irb->codegen->invalid_inst_src;
81859216 }
81869217 else_prong = prong_node;
81879218 } else if (prong_item_count == 1 &&
......@@ -8192,7 +9223,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
81929223 buf_sprintf("multiple '_' prongs in switch expression"));
81939224 add_error_note(irb->codegen, msg, underscore_prong,
81949225 buf_sprintf("previous '_' prong is here"));
8195 return irb->codegen->invalid_instruction;
9226 return irb->codegen->invalid_inst_src;
81969227 }
81979228 underscore_prong = prong_node;
81989229 } else {
......@@ -8207,11 +9238,11 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
82079238 else
82089239 add_error_note(irb->codegen, msg, underscore_prong,
82099240 buf_sprintf("'_' prong is here"));
8210 return irb->codegen->invalid_instruction;
9241 return irb->codegen->invalid_inst_src;
82119242 }
82129243 ResultLocPeer *this_peer_result_loc = create_peer_result(peer_parent);
82139244
8214 IrBasicBlock *prev_block = irb->current_basic_block;
9245 IrBasicBlockSrc *prev_block = irb->current_basic_block;
82159246 if (peer_parent->peers.length > 0) {
82169247 peer_parent->peers.last()->next_bb = else_block;
82179248 }
......@@ -8221,7 +9252,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
82219252 is_comptime, var_is_comptime, target_value_ptr, nullptr, 0, &incoming_blocks, &incoming_values,
82229253 &switch_else_var, LValNone, &this_peer_result_loc->base))
82239254 {
8224 return irb->codegen->invalid_instruction;
9255 return irb->codegen->invalid_inst_src;
82259256 }
82269257 ir_set_cursor_at_end(irb, prev_block);
82279258 }
......@@ -8240,29 +9271,29 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
82409271
82419272 ResultLocPeer *this_peer_result_loc = create_peer_result(peer_parent);
82429273
8243 IrBasicBlock *prong_block = ir_create_basic_block(irb, scope, "SwitchProng");
8244 IrInstruction **items = allocate<IrInstruction *>(prong_item_count);
9274 IrBasicBlockSrc *prong_block = ir_create_basic_block(irb, scope, "SwitchProng");
9275 IrInstSrc **items = allocate<IrInstSrc *>(prong_item_count);
82459276
82469277 for (size_t item_i = 0; item_i < prong_item_count; item_i += 1) {
82479278 AstNode *item_node = prong_node->data.switch_prong.items.at(item_i);
82489279 assert(item_node->type != NodeTypeSwitchRange);
82499280
8250 IrInstruction *item_value = ir_gen_node(irb, item_node, comptime_scope);
8251 if (item_value == irb->codegen->invalid_instruction)
8252 return irb->codegen->invalid_instruction;
9281 IrInstSrc *item_value = ir_gen_node(irb, item_node, comptime_scope);
9282 if (item_value == irb->codegen->invalid_inst_src)
9283 return irb->codegen->invalid_inst_src;
82539284
8254 IrInstructionCheckSwitchProngsRange *check_range = check_ranges.add_one();
9285 IrInstSrcCheckSwitchProngsRange *check_range = check_ranges.add_one();
82559286 check_range->start = item_value;
82569287 check_range->end = item_value;
82579288
8258 IrInstructionSwitchBrCase *this_case = cases.add_one();
9289 IrInstSrcSwitchBrCase *this_case = cases.add_one();
82599290 this_case->value = item_value;
82609291 this_case->block = prong_block;
82619292
82629293 items[item_i] = item_value;
82639294 }
82649295
8265 IrBasicBlock *prev_block = irb->current_basic_block;
9296 IrBasicBlockSrc *prev_block = irb->current_basic_block;
82669297 if (peer_parent->peers.length > 0) {
82679298 peer_parent->peers.last()->next_bb = prong_block;
82689299 }
......@@ -8272,21 +9303,21 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
82729303 is_comptime, var_is_comptime, target_value_ptr, items, prong_item_count,
82739304 &incoming_blocks, &incoming_values, nullptr, LValNone, &this_peer_result_loc->base))
82749305 {
8275 return irb->codegen->invalid_instruction;
9306 return irb->codegen->invalid_inst_src;
82769307 }
82779308
82789309 ir_set_cursor_at_end(irb, prev_block);
82799310
82809311 }
82819312
8282 IrInstruction *switch_prongs_void = ir_build_check_switch_prongs(irb, scope, node, target_value,
9313 IrInstSrc *switch_prongs_void = ir_build_check_switch_prongs(irb, scope, node, target_value,
82839314 check_ranges.items, check_ranges.length, else_prong != nullptr, underscore_prong != nullptr);
82849315
8285 IrInstruction *br_instruction;
9316 IrInstSrc *br_instruction;
82869317 if (cases.length == 0) {
82879318 br_instruction = ir_build_br(irb, scope, node, else_block, is_comptime);
82889319 } else {
8289 IrInstructionSwitchBr *switch_br = ir_build_switch_br(irb, scope, node, target_value, else_block,
9320 IrInstSrcSwitchBr *switch_br = ir_build_switch_br_src(irb, scope, node, target_value, else_block,
82909321 cases.length, cases.items, is_comptime, switch_prongs_void);
82919322 if (switch_else_var != nullptr) {
82929323 switch_else_var->switch_br = switch_br;
......@@ -8314,7 +9345,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
83149345
83159346 ir_set_cursor_at_end_and_append_block(irb, end_block);
83169347 assert(incoming_blocks.length == incoming_values.length);
8317 IrInstruction *result_instruction;
9348 IrInstSrc *result_instruction;
83189349 if (incoming_blocks.length == 0) {
83199350 result_instruction = ir_build_const_void(irb, scope, node);
83209351 } else {
......@@ -8324,7 +9355,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
83249355 return ir_lval_wrap(irb, scope, result_instruction, lval, result_loc);
83259356}
83269357
8327static IrInstruction *ir_gen_comptime(IrBuilder *irb, Scope *parent_scope, AstNode *node, LVal lval) {
9358static IrInstSrc *ir_gen_comptime(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node, LVal lval) {
83289359 assert(node->type == NodeTypeCompTime);
83299360
83309361 Scope *child_scope = create_comptime_scope(irb->codegen, node, parent_scope);
......@@ -8332,28 +9363,28 @@ static IrInstruction *ir_gen_comptime(IrBuilder *irb, Scope *parent_scope, AstNo
83329363 return ir_gen_node_extra(irb, node->data.comptime_expr.expr, child_scope, lval, nullptr);
83339364}
83349365
8335static IrInstruction *ir_gen_return_from_block(IrBuilder *irb, Scope *break_scope, AstNode *node, ScopeBlock *block_scope) {
8336 IrInstruction *is_comptime;
9366static IrInstSrc *ir_gen_return_from_block(IrBuilderSrc *irb, Scope *break_scope, AstNode *node, ScopeBlock *block_scope) {
9367 IrInstSrc *is_comptime;
83379368 if (ir_should_inline(irb->exec, break_scope)) {
83389369 is_comptime = ir_build_const_bool(irb, break_scope, node, true);
83399370 } else {
83409371 is_comptime = block_scope->is_comptime;
83419372 }
83429373
8343 IrInstruction *result_value;
9374 IrInstSrc *result_value;
83449375 if (node->data.break_expr.expr) {
83459376 ResultLocPeer *peer_result = create_peer_result(block_scope->peer_parent);
83469377 block_scope->peer_parent->peers.append(peer_result);
83479378
83489379 result_value = ir_gen_node_extra(irb, node->data.break_expr.expr, break_scope, block_scope->lval,
83499380 &peer_result->base);
8350 if (result_value == irb->codegen->invalid_instruction)
8351 return irb->codegen->invalid_instruction;
9381 if (result_value == irb->codegen->invalid_inst_src)
9382 return irb->codegen->invalid_inst_src;
83529383 } else {
83539384 result_value = ir_build_const_void(irb, break_scope, node);
83549385 }
83559386
8356 IrBasicBlock *dest_block = block_scope->end_block;
9387 IrBasicBlockSrc *dest_block = block_scope->end_block;
83579388 ir_gen_defers_for_block(irb, break_scope, dest_block->scope, false);
83589389
83599390 block_scope->incoming_blocks->append(irb->current_basic_block);
......@@ -8361,7 +9392,7 @@ static IrInstruction *ir_gen_return_from_block(IrBuilder *irb, Scope *break_scop
83619392 return ir_build_br(irb, break_scope, node, dest_block, is_comptime);
83629393}
83639394
8364static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode *node) {
9395static IrInstSrc *ir_gen_break(IrBuilderSrc *irb, Scope *break_scope, AstNode *node) {
83659396 assert(node->type == NodeTypeBreak);
83669397
83679398 // Search up the scope. We'll find one of these things first:
......@@ -8376,14 +9407,14 @@ static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode *
83769407 if (search_scope == nullptr || search_scope->id == ScopeIdFnDef) {
83779408 if (node->data.break_expr.name != nullptr) {
83789409 add_node_error(irb->codegen, node, buf_sprintf("label not found: '%s'", buf_ptr(node->data.break_expr.name)));
8379 return irb->codegen->invalid_instruction;
9410 return irb->codegen->invalid_inst_src;
83809411 } else {
83819412 add_node_error(irb->codegen, node, buf_sprintf("break expression outside loop"));
8382 return irb->codegen->invalid_instruction;
9413 return irb->codegen->invalid_inst_src;
83839414 }
83849415 } else if (search_scope->id == ScopeIdDeferExpr) {
83859416 add_node_error(irb->codegen, node, buf_sprintf("cannot break out of defer expression"));
8386 return irb->codegen->invalid_instruction;
9417 return irb->codegen->invalid_inst_src;
83879418 } else if (search_scope->id == ScopeIdLoop) {
83889419 ScopeLoop *this_loop_scope = (ScopeLoop *)search_scope;
83899420 if (node->data.break_expr.name == nullptr ||
......@@ -8402,32 +9433,32 @@ static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode *
84029433 }
84039434 } else if (search_scope->id == ScopeIdSuspend) {
84049435 add_node_error(irb->codegen, node, buf_sprintf("cannot break out of suspend block"));
8405 return irb->codegen->invalid_instruction;
9436 return irb->codegen->invalid_inst_src;
84069437 }
84079438 search_scope = search_scope->parent;
84089439 }
84099440
8410 IrInstruction *is_comptime;
9441 IrInstSrc *is_comptime;
84119442 if (ir_should_inline(irb->exec, break_scope)) {
84129443 is_comptime = ir_build_const_bool(irb, break_scope, node, true);
84139444 } else {
84149445 is_comptime = loop_scope->is_comptime;
84159446 }
84169447
8417 IrInstruction *result_value;
9448 IrInstSrc *result_value;
84189449 if (node->data.break_expr.expr) {
84199450 ResultLocPeer *peer_result = create_peer_result(loop_scope->peer_parent);
84209451 loop_scope->peer_parent->peers.append(peer_result);
84219452
84229453 result_value = ir_gen_node_extra(irb, node->data.break_expr.expr, break_scope,
84239454 loop_scope->lval, &peer_result->base);
8424 if (result_value == irb->codegen->invalid_instruction)
8425 return irb->codegen->invalid_instruction;
9455 if (result_value == irb->codegen->invalid_inst_src)
9456 return irb->codegen->invalid_inst_src;
84269457 } else {
84279458 result_value = ir_build_const_void(irb, break_scope, node);
84289459 }
84299460
8430 IrBasicBlock *dest_block = loop_scope->break_block;
9461 IrBasicBlockSrc *dest_block = loop_scope->break_block;
84319462 ir_gen_defers_for_block(irb, break_scope, dest_block->scope, false);
84329463
84339464 loop_scope->incoming_blocks->append(irb->current_basic_block);
......@@ -8435,7 +9466,7 @@ static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode *
84359466 return ir_build_br(irb, break_scope, node, dest_block, is_comptime);
84369467}
84379468
8438static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, AstNode *node) {
9469static IrInstSrc *ir_gen_continue(IrBuilderSrc *irb, Scope *continue_scope, AstNode *node) {
84399470 assert(node->type == NodeTypeContinue);
84409471
84419472 // Search up the scope. We'll find one of these things first:
......@@ -8451,14 +9482,14 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast
84519482 if (search_scope == nullptr || search_scope->id == ScopeIdFnDef) {
84529483 if (node->data.continue_expr.name != nullptr) {
84539484 add_node_error(irb->codegen, node, buf_sprintf("labeled loop not found: '%s'", buf_ptr(node->data.continue_expr.name)));
8454 return irb->codegen->invalid_instruction;
9485 return irb->codegen->invalid_inst_src;
84559486 } else {
84569487 add_node_error(irb->codegen, node, buf_sprintf("continue expression outside loop"));
8457 return irb->codegen->invalid_instruction;
9488 return irb->codegen->invalid_inst_src;
84589489 }
84599490 } else if (search_scope->id == ScopeIdDeferExpr) {
84609491 add_node_error(irb->codegen, node, buf_sprintf("cannot continue out of defer expression"));
8461 return irb->codegen->invalid_instruction;
9492 return irb->codegen->invalid_inst_src;
84629493 } else if (search_scope->id == ScopeIdLoop) {
84639494 ScopeLoop *this_loop_scope = (ScopeLoop *)search_scope;
84649495 if (node->data.continue_expr.name == nullptr ||
......@@ -8474,7 +9505,7 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast
84749505 search_scope = search_scope->parent;
84759506 }
84769507
8477 IrInstruction *is_comptime;
9508 IrInstSrc *is_comptime;
84789509 if (ir_should_inline(irb->exec, continue_scope)) {
84799510 is_comptime = ir_build_const_bool(irb, continue_scope, node, true);
84809511 } else {
......@@ -8486,17 +9517,17 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast
84869517 ir_mark_gen(ir_build_check_runtime_scope(irb, continue_scope, node, scope_runtime->is_comptime, is_comptime));
84879518 }
84889519
8489 IrBasicBlock *dest_block = loop_scope->continue_block;
9520 IrBasicBlockSrc *dest_block = loop_scope->continue_block;
84909521 ir_gen_defers_for_block(irb, continue_scope, dest_block->scope, false);
84919522 return ir_mark_gen(ir_build_br(irb, continue_scope, node, dest_block, is_comptime));
84929523}
84939524
8494static IrInstruction *ir_gen_error_type(IrBuilder *irb, Scope *scope, AstNode *node) {
9525static IrInstSrc *ir_gen_error_type(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
84959526 assert(node->type == NodeTypeErrorType);
84969527 return ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_global_error_set);
84979528}
84989529
8499static IrInstruction *ir_gen_defer(IrBuilder *irb, Scope *parent_scope, AstNode *node) {
9530static IrInstSrc *ir_gen_defer(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) {
85009531 assert(node->type == NodeTypeDefer);
85019532
85029533 ScopeDefer *defer_child_scope = create_defer_scope(irb->codegen, node, parent_scope);
......@@ -8508,7 +9539,7 @@ static IrInstruction *ir_gen_defer(IrBuilder *irb, Scope *parent_scope, AstNode
85089539 return ir_build_const_void(irb, parent_scope, node);
85099540}
85109541
8511static IrInstruction *ir_gen_slice(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) {
9542static IrInstSrc *ir_gen_slice(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) {
85129543 assert(node->type == NodeTypeSliceExpr);
85139544
85149545 AstNodeSliceExpr *slice_expr = &node->data.slice_expr;
......@@ -8517,38 +9548,38 @@ static IrInstruction *ir_gen_slice(IrBuilder *irb, Scope *scope, AstNode *node,
85179548 AstNode *end_node = slice_expr->end;
85189549 AstNode *sentinel_node = slice_expr->sentinel;
85199550
8520 IrInstruction *ptr_value = ir_gen_node_extra(irb, array_node, scope, LValPtr, nullptr);
8521 if (ptr_value == irb->codegen->invalid_instruction)
8522 return irb->codegen->invalid_instruction;
9551 IrInstSrc *ptr_value = ir_gen_node_extra(irb, array_node, scope, LValPtr, nullptr);
9552 if (ptr_value == irb->codegen->invalid_inst_src)
9553 return irb->codegen->invalid_inst_src;
85239554
8524 IrInstruction *start_value = ir_gen_node(irb, start_node, scope);
8525 if (start_value == irb->codegen->invalid_instruction)
8526 return irb->codegen->invalid_instruction;
9555 IrInstSrc *start_value = ir_gen_node(irb, start_node, scope);
9556 if (start_value == irb->codegen->invalid_inst_src)
9557 return irb->codegen->invalid_inst_src;
85279558
8528 IrInstruction *end_value;
9559 IrInstSrc *end_value;
85299560 if (end_node) {
85309561 end_value = ir_gen_node(irb, end_node, scope);
8531 if (end_value == irb->codegen->invalid_instruction)
8532 return irb->codegen->invalid_instruction;
9562 if (end_value == irb->codegen->invalid_inst_src)
9563 return irb->codegen->invalid_inst_src;
85339564 } else {
85349565 end_value = nullptr;
85359566 }
85369567
8537 IrInstruction *sentinel_value;
9568 IrInstSrc *sentinel_value;
85389569 if (sentinel_node) {
85399570 sentinel_value = ir_gen_node(irb, sentinel_node, scope);
8540 if (sentinel_value == irb->codegen->invalid_instruction)
8541 return irb->codegen->invalid_instruction;
9571 if (sentinel_value == irb->codegen->invalid_inst_src)
9572 return irb->codegen->invalid_inst_src;
85429573 } else {
85439574 sentinel_value = nullptr;
85449575 }
85459576
8546 IrInstruction *slice = ir_build_slice_src(irb, scope, node, ptr_value, start_value, end_value,
9577 IrInstSrc *slice = ir_build_slice_src(irb, scope, node, ptr_value, start_value, end_value,
85479578 sentinel_value, true, result_loc);
85489579 return ir_lval_wrap(irb, scope, slice, lval, result_loc);
85499580}
85509581
8551static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode *node, LVal lval,
9582static IrInstSrc *ir_gen_catch(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node, LVal lval,
85529583 ResultLoc *result_loc)
85539584{
85549585 assert(node->type == NodeTypeCatchExpr);
......@@ -8562,29 +9593,29 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode
85629593 assert(var_node->type == NodeTypeSymbol);
85639594 Buf *var_name = var_node->data.symbol_expr.symbol;
85649595 add_node_error(irb->codegen, var_node, buf_sprintf("unused variable: '%s'", buf_ptr(var_name)));
8565 return irb->codegen->invalid_instruction;
9596 return irb->codegen->invalid_inst_src;
85669597 }
85679598 return ir_gen_catch_unreachable(irb, parent_scope, node, op1_node, lval, result_loc);
85689599 }
85699600
85709601
8571 IrInstruction *err_union_ptr = ir_gen_node_extra(irb, op1_node, parent_scope, LValPtr, nullptr);
8572 if (err_union_ptr == irb->codegen->invalid_instruction)
8573 return irb->codegen->invalid_instruction;
9602 IrInstSrc *err_union_ptr = ir_gen_node_extra(irb, op1_node, parent_scope, LValPtr, nullptr);
9603 if (err_union_ptr == irb->codegen->invalid_inst_src)
9604 return irb->codegen->invalid_inst_src;
85749605
8575 IrInstruction *is_err = ir_build_test_err_src(irb, parent_scope, node, err_union_ptr, true, false);
9606 IrInstSrc *is_err = ir_build_test_err_src(irb, parent_scope, node, err_union_ptr, true, false);
85769607
8577 IrInstruction *is_comptime;
9608 IrInstSrc *is_comptime;
85789609 if (ir_should_inline(irb->exec, parent_scope)) {
85799610 is_comptime = ir_build_const_bool(irb, parent_scope, node, true);
85809611 } else {
85819612 is_comptime = ir_build_test_comptime(irb, parent_scope, node, is_err);
85829613 }
85839614
8584 IrBasicBlock *ok_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrOk");
8585 IrBasicBlock *err_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrError");
8586 IrBasicBlock *end_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrEnd");
8587 IrInstruction *cond_br_inst = ir_build_cond_br(irb, parent_scope, node, is_err, err_block, ok_block, is_comptime);
9615 IrBasicBlockSrc *ok_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrOk");
9616 IrBasicBlockSrc *err_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrError");
9617 IrBasicBlockSrc *end_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrEnd");
9618 IrInstSrc *cond_br_inst = ir_build_cond_br(irb, parent_scope, node, is_err, err_block, ok_block, is_comptime);
85889619
85899620 ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, ok_block, end_block, result_loc,
85909621 is_comptime);
......@@ -8600,33 +9631,33 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode
86009631 ZigVar *var = ir_create_var(irb, node, subexpr_scope, var_name,
86019632 is_const, is_const, is_shadowable, is_comptime);
86029633 err_scope = var->child_scope;
8603 IrInstruction *err_ptr = ir_build_unwrap_err_code(irb, err_scope, node, err_union_ptr);
9634 IrInstSrc *err_ptr = ir_build_unwrap_err_code_src(irb, err_scope, node, err_union_ptr);
86049635 ir_build_var_decl_src(irb, err_scope, var_node, var, nullptr, err_ptr);
86059636 } else {
86069637 err_scope = subexpr_scope;
86079638 }
8608 IrInstruction *err_result = ir_gen_node_extra(irb, op2_node, err_scope, LValNone, &peer_parent->peers.at(0)->base);
8609 if (err_result == irb->codegen->invalid_instruction)
8610 return irb->codegen->invalid_instruction;
8611 IrBasicBlock *after_err_block = irb->current_basic_block;
9639 IrInstSrc *err_result = ir_gen_node_extra(irb, op2_node, err_scope, LValNone, &peer_parent->peers.at(0)->base);
9640 if (err_result == irb->codegen->invalid_inst_src)
9641 return irb->codegen->invalid_inst_src;
9642 IrBasicBlockSrc *after_err_block = irb->current_basic_block;
86129643 if (!instr_is_unreachable(err_result))
86139644 ir_mark_gen(ir_build_br(irb, parent_scope, node, end_block, is_comptime));
86149645
86159646 ir_set_cursor_at_end_and_append_block(irb, ok_block);
8616 IrInstruction *unwrapped_ptr = ir_build_unwrap_err_payload(irb, parent_scope, node, err_union_ptr, false, false);
8617 IrInstruction *unwrapped_payload = ir_build_load_ptr(irb, parent_scope, node, unwrapped_ptr);
9647 IrInstSrc *unwrapped_ptr = ir_build_unwrap_err_payload_src(irb, parent_scope, node, err_union_ptr, false, false);
9648 IrInstSrc *unwrapped_payload = ir_build_load_ptr(irb, parent_scope, node, unwrapped_ptr);
86189649 ir_build_end_expr(irb, parent_scope, node, unwrapped_payload, &peer_parent->peers.at(1)->base);
8619 IrBasicBlock *after_ok_block = irb->current_basic_block;
9650 IrBasicBlockSrc *after_ok_block = irb->current_basic_block;
86209651 ir_build_br(irb, parent_scope, node, end_block, is_comptime);
86219652
86229653 ir_set_cursor_at_end_and_append_block(irb, end_block);
8623 IrInstruction **incoming_values = allocate<IrInstruction *>(2);
9654 IrInstSrc **incoming_values = allocate<IrInstSrc *>(2);
86249655 incoming_values[0] = err_result;
86259656 incoming_values[1] = unwrapped_payload;
8626 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *");
9657 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
86279658 incoming_blocks[0] = after_err_block;
86289659 incoming_blocks[1] = after_ok_block;
8629 IrInstruction *phi = ir_build_phi(irb, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent);
9660 IrInstSrc *phi = ir_build_phi(irb, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent);
86309661 return ir_lval_wrap(irb, parent_scope, phi, lval, result_loc);
86319662}
86329663
......@@ -8644,7 +9675,7 @@ static bool render_instance_name_recursive(CodeGen *codegen, Buf *name, Scope *o
86449675 return true;
86459676}
86469677
8647static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char *kind_name,
9678static Buf *get_anon_type_name(CodeGen *codegen, IrExecutableSrc *exec, const char *kind_name,
86489679 Scope *scope, AstNode *source_node, Buf *out_bare_name)
86499680{
86509681 if (exec != nullptr && exec->name) {
......@@ -8673,7 +9704,7 @@ static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char
86739704 }
86749705}
86759706
8676static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope, AstNode *node) {
9707static IrInstSrc *ir_gen_container_decl(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) {
86779708 assert(node->type == NodeTypeContainerDecl);
86789709
86799710 ContainerKind kind = node->data.container_decl.kind;
......@@ -8798,7 +9829,7 @@ static AstNode *ast_field_to_symbol_node(AstNode *err_set_field_node) {
87989829 }
87999830}
88009831
8801static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, AstNode *node) {
9832static IrInstSrc *ir_gen_err_set_decl(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) {
88029833 assert(node->type == NodeTypeErrorSetDecl);
88039834
88049835 uint32_t err_count = node->data.err_set_decl.decls.length;
......@@ -8841,7 +9872,7 @@ static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, A
88419872 buf_sprintf("duplicate error: '%s'", buf_ptr(&err->name)));
88429873 add_error_note(irb->codegen, msg, ast_field_to_symbol_node(prev_err->decl_node),
88439874 buf_sprintf("other error here"));
8844 return irb->codegen->invalid_instruction;
9875 return irb->codegen->invalid_inst_src;
88459876 }
88469877 errors[err->value] = err;
88479878 }
......@@ -8849,11 +9880,11 @@ static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, A
88499880 return ir_build_const_type(irb, parent_scope, node, err_set_type);
88509881}
88519882
8852static IrInstruction *ir_gen_fn_proto(IrBuilder *irb, Scope *parent_scope, AstNode *node) {
9883static IrInstSrc *ir_gen_fn_proto(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) {
88539884 assert(node->type == NodeTypeFnProto);
88549885
88559886 size_t param_count = node->data.fn_proto.params.length;
8856 IrInstruction **param_types = allocate<IrInstruction*>(param_count);
9887 IrInstSrc **param_types = allocate<IrInstSrc*>(param_count);
88579888
88589889 bool is_var_args = false;
88599890 for (size_t i = 0; i < param_count; i += 1) {
......@@ -8864,59 +9895,59 @@ static IrInstruction *ir_gen_fn_proto(IrBuilder *irb, Scope *parent_scope, AstNo
88649895 }
88659896 if (param_node->data.param_decl.var_token == nullptr) {
88669897 AstNode *type_node = param_node->data.param_decl.type;
8867 IrInstruction *type_value = ir_gen_node(irb, type_node, parent_scope);
8868 if (type_value == irb->codegen->invalid_instruction)
8869 return irb->codegen->invalid_instruction;
9898 IrInstSrc *type_value = ir_gen_node(irb, type_node, parent_scope);
9899 if (type_value == irb->codegen->invalid_inst_src)
9900 return irb->codegen->invalid_inst_src;
88709901 param_types[i] = type_value;
88719902 } else {
88729903 param_types[i] = nullptr;
88739904 }
88749905 }
88759906
8876 IrInstruction *align_value = nullptr;
9907 IrInstSrc *align_value = nullptr;
88779908 if (node->data.fn_proto.align_expr != nullptr) {
88789909 align_value = ir_gen_node(irb, node->data.fn_proto.align_expr, parent_scope);
8879 if (align_value == irb->codegen->invalid_instruction)
8880 return irb->codegen->invalid_instruction;
9910 if (align_value == irb->codegen->invalid_inst_src)
9911 return irb->codegen->invalid_inst_src;
88819912 }
88829913
8883 IrInstruction *callconv_value = nullptr;
9914 IrInstSrc *callconv_value = nullptr;
88849915 if (node->data.fn_proto.callconv_expr != nullptr) {
88859916 callconv_value = ir_gen_node(irb, node->data.fn_proto.callconv_expr, parent_scope);
8886 if (callconv_value == irb->codegen->invalid_instruction)
8887 return irb->codegen->invalid_instruction;
9917 if (callconv_value == irb->codegen->invalid_inst_src)
9918 return irb->codegen->invalid_inst_src;
88889919 }
88899920
8890 IrInstruction *return_type;
9921 IrInstSrc *return_type;
88919922 if (node->data.fn_proto.return_var_token == nullptr) {
88929923 if (node->data.fn_proto.return_type == nullptr) {
88939924 return_type = ir_build_const_type(irb, parent_scope, node, irb->codegen->builtin_types.entry_void);
88949925 } else {
88959926 return_type = ir_gen_node(irb, node->data.fn_proto.return_type, parent_scope);
8896 if (return_type == irb->codegen->invalid_instruction)
8897 return irb->codegen->invalid_instruction;
9927 if (return_type == irb->codegen->invalid_inst_src)
9928 return irb->codegen->invalid_inst_src;
88989929 }
88999930 } else {
89009931 add_node_error(irb->codegen, node,
89019932 buf_sprintf("TODO implement inferred return types https://github.com/ziglang/zig/issues/447"));
8902 return irb->codegen->invalid_instruction;
9933 return irb->codegen->invalid_inst_src;
89039934 //return_type = nullptr;
89049935 }
89059936
89069937 return ir_build_fn_proto(irb, parent_scope, node, param_types, align_value, callconv_value, return_type, is_var_args);
89079938}
89089939
8909static IrInstruction *ir_gen_resume(IrBuilder *irb, Scope *scope, AstNode *node) {
9940static IrInstSrc *ir_gen_resume(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
89109941 assert(node->type == NodeTypeResume);
89119942
8912 IrInstruction *target_inst = ir_gen_node_extra(irb, node->data.resume_expr.expr, scope, LValPtr, nullptr);
8913 if (target_inst == irb->codegen->invalid_instruction)
8914 return irb->codegen->invalid_instruction;
9943 IrInstSrc *target_inst = ir_gen_node_extra(irb, node->data.resume_expr.expr, scope, LValPtr, nullptr);
9944 if (target_inst == irb->codegen->invalid_inst_src)
9945 return irb->codegen->invalid_inst_src;
89159946
8916 return ir_build_resume(irb, scope, node, target_inst);
9947 return ir_build_resume_src(irb, scope, node, target_inst);
89179948}
89189949
8919static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,
9950static IrInstSrc *ir_gen_await_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
89209951 ResultLoc *result_loc)
89219952{
89229953 assert(node->type == NodeTypeAwaitExpr);
......@@ -8937,7 +9968,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
89379968 ZigFn *fn_entry = exec_fn_entry(irb->exec);
89389969 if (!fn_entry) {
89399970 add_node_error(irb->codegen, node, buf_sprintf("await outside function definition"));
8940 return irb->codegen->invalid_instruction;
9971 return irb->codegen->invalid_inst_src;
89419972 }
89429973 ScopeSuspend *existing_suspend_scope = get_scope_suspend(scope);
89439974 if (existing_suspend_scope) {
......@@ -8946,24 +9977,24 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
89469977 add_error_note(irb->codegen, msg, existing_suspend_scope->base.source_node, buf_sprintf("suspend block here"));
89479978 existing_suspend_scope->reported_err = true;
89489979 }
8949 return irb->codegen->invalid_instruction;
9980 return irb->codegen->invalid_inst_src;
89509981 }
89519982
8952 IrInstruction *target_inst = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
8953 if (target_inst == irb->codegen->invalid_instruction)
8954 return irb->codegen->invalid_instruction;
9983 IrInstSrc *target_inst = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
9984 if (target_inst == irb->codegen->invalid_inst_src)
9985 return irb->codegen->invalid_inst_src;
89559986
8956 IrInstruction *await_inst = ir_build_await_src(irb, scope, node, target_inst, result_loc);
9987 IrInstSrc *await_inst = ir_build_await_src(irb, scope, node, target_inst, result_loc);
89579988 return ir_lval_wrap(irb, scope, await_inst, lval, result_loc);
89589989}
89599990
8960static IrInstruction *ir_gen_suspend(IrBuilder *irb, Scope *parent_scope, AstNode *node) {
9991static IrInstSrc *ir_gen_suspend(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) {
89619992 assert(node->type == NodeTypeSuspend);
89629993
89639994 ZigFn *fn_entry = exec_fn_entry(irb->exec);
89649995 if (!fn_entry) {
89659996 add_node_error(irb->codegen, node, buf_sprintf("suspend outside function definition"));
8966 return irb->codegen->invalid_instruction;
9997 return irb->codegen->invalid_inst_src;
89679998 }
89689999 ScopeSuspend *existing_suspend_scope = get_scope_suspend(parent_scope);
896910000 if (existing_suspend_scope) {
......@@ -8972,21 +10003,21 @@ static IrInstruction *ir_gen_suspend(IrBuilder *irb, Scope *parent_scope, AstNod
897210003 add_error_note(irb->codegen, msg, existing_suspend_scope->base.source_node, buf_sprintf("other suspend block here"));
897310004 existing_suspend_scope->reported_err = true;
897410005 }
8975 return irb->codegen->invalid_instruction;
10006 return irb->codegen->invalid_inst_src;
897610007 }
897710008
8978 IrInstructionSuspendBegin *begin = ir_build_suspend_begin(irb, parent_scope, node);
10009 IrInstSrcSuspendBegin *begin = ir_build_suspend_begin_src(irb, parent_scope, node);
897910010 if (node->data.suspend.block != nullptr) {
898010011 ScopeSuspend *suspend_scope = create_suspend_scope(irb->codegen, node, parent_scope);
898110012 Scope *child_scope = &suspend_scope->base;
8982 IrInstruction *susp_res = ir_gen_node(irb, node->data.suspend.block, child_scope);
10013 IrInstSrc *susp_res = ir_gen_node(irb, node->data.suspend.block, child_scope);
898310014 ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, node->data.suspend.block, susp_res));
898410015 }
898510016
8986 return ir_mark_gen(ir_build_suspend_finish(irb, parent_scope, node, begin));
10017 return ir_mark_gen(ir_build_suspend_finish_src(irb, parent_scope, node, begin));
898710018}
898810019
8989static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scope,
10020static IrInstSrc *ir_gen_node_raw(IrBuilderSrc *irb, AstNode *node, Scope *scope,
899010021 LVal lval, ResultLoc *result_loc)
899110022{
899210023 assert(scope);
......@@ -9035,39 +10066,39 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
903510066 return ir_gen_return(irb, scope, node, lval, result_loc);
903610067 case NodeTypeFieldAccessExpr:
903710068 {
9038 IrInstruction *ptr_instruction = ir_gen_field_access(irb, scope, node);
9039 if (ptr_instruction == irb->codegen->invalid_instruction)
10069 IrInstSrc *ptr_instruction = ir_gen_field_access(irb, scope, node);
10070 if (ptr_instruction == irb->codegen->invalid_inst_src)
904010071 return ptr_instruction;
904110072 if (lval == LValPtr)
904210073 return ptr_instruction;
904310074
9044 IrInstruction *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction);
10075 IrInstSrc *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction);
904510076 return ir_expr_wrap(irb, scope, load_ptr, result_loc);
904610077 }
904710078 case NodeTypePtrDeref: {
904810079 AstNode *expr_node = node->data.ptr_deref_expr.target;
9049 IrInstruction *value = ir_gen_node_extra(irb, expr_node, scope, lval, nullptr);
9050 if (value == irb->codegen->invalid_instruction)
10080 IrInstSrc *value = ir_gen_node_extra(irb, expr_node, scope, lval, nullptr);
10081 if (value == irb->codegen->invalid_inst_src)
905110082 return value;
905210083
905310084 // We essentially just converted any lvalue from &(x.*) to (&x).*;
905410085 // this inhibits checking that x is a pointer later, so we directly
905510086 // record whether the pointer check is needed
9056 IrInstruction *un_op = ir_build_un_op_lval(irb, scope, node, IrUnOpDereference, value, lval, result_loc);
10087 IrInstSrc *un_op = ir_build_un_op_lval(irb, scope, node, IrUnOpDereference, value, lval, result_loc);
905710088 return ir_expr_wrap(irb, scope, un_op, result_loc);
905810089 }
905910090 case NodeTypeUnwrapOptional: {
906010091 AstNode *expr_node = node->data.unwrap_optional.expr;
906110092
9062 IrInstruction *maybe_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
9063 if (maybe_ptr == irb->codegen->invalid_instruction)
9064 return irb->codegen->invalid_instruction;
10093 IrInstSrc *maybe_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
10094 if (maybe_ptr == irb->codegen->invalid_inst_src)
10095 return irb->codegen->invalid_inst_src;
906510096
9066 IrInstruction *unwrapped_ptr = ir_build_optional_unwrap_ptr(irb, scope, node, maybe_ptr, true, false);
10097 IrInstSrc *unwrapped_ptr = ir_build_optional_unwrap_ptr(irb, scope, node, maybe_ptr, true, false);
906710098 if (lval == LValPtr)
906810099 return unwrapped_ptr;
906910100
9070 IrInstruction *load_ptr = ir_build_load_ptr(irb, scope, node, unwrapped_ptr);
10101 IrInstSrc *load_ptr = ir_build_load_ptr(irb, scope, node, unwrapped_ptr);
907110102 return ir_expr_wrap(irb, scope, load_ptr, result_loc);
907210103 }
907310104 case NodeTypeBoolLiteral:
......@@ -9125,7 +10156,7 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
912510156 case NodeTypeInferredArrayType:
912610157 add_node_error(irb->codegen, node,
912710158 buf_sprintf("inferred array size invalid here"));
9128 return irb->codegen->invalid_instruction;
10159 return irb->codegen->invalid_inst_src;
912910160 case NodeTypeVarFieldType:
913010161 return ir_lval_wrap(irb, scope,
913110162 ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_var), lval, result_loc);
......@@ -9139,7 +10170,7 @@ static ResultLoc *no_result_loc(void) {
913910170 return &result_loc_none->base;
914010171}
914110172
9142static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval,
10173static IrInstSrc *ir_gen_node_extra(IrBuilderSrc *irb, AstNode *node, Scope *scope, LVal lval,
914310174 ResultLoc *result_loc)
914410175{
914510176 if (result_loc == nullptr) {
......@@ -9156,8 +10187,8 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *sc
915610187 } else {
915710188 child_scope = &create_expr_scope(irb->codegen, node, scope)->base;
915810189 }
9159 IrInstruction *result = ir_gen_node_raw(irb, node, child_scope, lval, result_loc);
9160 if (result == irb->codegen->invalid_instruction) {
10190 IrInstSrc *result = ir_gen_node_raw(irb, node, child_scope, lval, result_loc);
10191 if (result == irb->codegen->invalid_inst_src) {
916110192 if (irb->exec->first_err_trace_msg == nullptr) {
916210193 irb->exec->first_err_trace_msg = irb->codegen->trace_err;
916310194 }
......@@ -9165,11 +10196,22 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *sc
916510196 return result;
916610197}
916710198
9168static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope) {
10199static IrInstSrc *ir_gen_node(IrBuilderSrc *irb, AstNode *node, Scope *scope) {
916910200 return ir_gen_node_extra(irb, node, scope, LValNone, nullptr);
917010201}
917110202
9172static void invalidate_exec(IrExecutable *exec, ErrorMsg *msg) {
10203static void invalidate_exec(IrExecutableSrc *exec, ErrorMsg *msg) {
10204 if (exec->first_err_trace_msg != nullptr)
10205 return;
10206
10207 exec->first_err_trace_msg = msg;
10208
10209 for (size_t i = 0; i < exec->tld_list.length; i += 1) {
10210 exec->tld_list.items[i]->resolution = TldResolutionInvalid;
10211 }
10212}
10213
10214static void invalidate_exec_gen(IrExecutableGen *exec, ErrorMsg *msg) {
917310215 if (exec->first_err_trace_msg != nullptr)
917410216 return;
917510217
......@@ -9183,24 +10225,25 @@ static void invalidate_exec(IrExecutable *exec, ErrorMsg *msg) {
918310225 invalidate_exec(exec->source_exec, msg);
918410226}
918510227
9186bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_executable) {
10228
10229bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutableSrc *ir_executable) {
918710230 assert(node->owner);
918810231
9189 IrBuilder ir_builder = {0};
9190 IrBuilder *irb = &ir_builder;
10232 IrBuilderSrc ir_builder = {0};
10233 IrBuilderSrc *irb = &ir_builder;
919110234
919210235 irb->codegen = codegen;
919310236 irb->exec = ir_executable;
919410237 irb->main_block_node = node;
919510238
9196 IrBasicBlock *entry_block = ir_create_basic_block(irb, scope, "Entry");
10239 IrBasicBlockSrc *entry_block = ir_create_basic_block(irb, scope, "Entry");
919710240 ir_set_cursor_at_end_and_append_block(irb, entry_block);
919810241 // Entry block gets a reference because we enter it to begin.
919910242 ir_ref_bb(irb->current_basic_block);
920010243
9201 IrInstruction *result = ir_gen_node_extra(irb, node, scope, LValNone, nullptr);
10244 IrInstSrc *result = ir_gen_node_extra(irb, node, scope, LValNone, nullptr);
920210245
9203 if (result == irb->codegen->invalid_instruction)
10246 if (result == irb->codegen->invalid_inst_src)
920410247 return false;
920510248
920610249 if (irb->exec->first_err_trace_msg != nullptr) {
......@@ -9209,9 +10252,9 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
920910252 }
921010253
921110254 if (!instr_is_unreachable(result)) {
9212 ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, result->source_node, result, nullptr));
10255 ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, result->base.source_node, result, nullptr));
921310256 // no need for save_err_ret_addr because this cannot return error
9214 ir_mark_gen(ir_build_return(irb, scope, result->source_node, result));
10257 ir_mark_gen(ir_build_return_src(irb, scope, result->base.source_node, result));
921510258 }
921610259
921710260 return true;
......@@ -9220,7 +10263,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
922010263bool ir_gen_fn(CodeGen *codegen, ZigFn *fn_entry) {
922110264 assert(fn_entry);
922210265
9223 IrExecutable *ir_executable = fn_entry->ir_executable;
10266 IrExecutableSrc *ir_executable = fn_entry->ir_executable;
922410267 AstNode *body_node = fn_entry->body_node;
922510268
922610269 assert(fn_entry->child_scope);
......@@ -9228,14 +10271,21 @@ bool ir_gen_fn(CodeGen *codegen, ZigFn *fn_entry) {
922810271 return ir_gen(codegen, body_node, fn_entry->child_scope, ir_executable);
922910272}
923010273
9231static void ir_add_call_stack_errors(CodeGen *codegen, IrExecutable *exec, ErrorMsg *err_msg, int limit) {
10274static void ir_add_call_stack_errors_gen(CodeGen *codegen, IrExecutableGen *exec, ErrorMsg *err_msg, int limit) {
10275 if (!exec || !exec->source_node || limit < 0) return;
10276 add_error_note(codegen, err_msg, exec->source_node, buf_sprintf("called from here"));
10277
10278 ir_add_call_stack_errors_gen(codegen, exec->parent_exec, err_msg, limit - 1);
10279}
10280
10281static void ir_add_call_stack_errors(CodeGen *codegen, IrExecutableSrc *exec, ErrorMsg *err_msg, int limit) {
923210282 if (!exec || !exec->source_node || limit < 0) return;
923310283 add_error_note(codegen, err_msg, exec->source_node, buf_sprintf("called from here"));
923410284
9235 ir_add_call_stack_errors(codegen, exec->parent_exec, err_msg, limit - 1);
10285 ir_add_call_stack_errors_gen(codegen, exec->parent_exec, err_msg, limit - 1);
923610286}
923710287
9238static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg) {
10288static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutableSrc *exec, AstNode *source_node, Buf *msg) {
923910289 ErrorMsg *err_msg = add_node_error(codegen, source_node, msg);
924010290 invalidate_exec(exec, err_msg);
924110291 if (exec->parent_exec) {
......@@ -9244,26 +10294,40 @@ static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNo
924410294 return err_msg;
924510295}
924610296
10297static ErrorMsg *exec_add_error_node_gen(CodeGen *codegen, IrExecutableGen *exec, AstNode *source_node, Buf *msg) {
10298 ErrorMsg *err_msg = add_node_error(codegen, source_node, msg);
10299 invalidate_exec_gen(exec, err_msg);
10300 if (exec->parent_exec) {
10301 ir_add_call_stack_errors_gen(codegen, exec, err_msg, 10);
10302 }
10303 return err_msg;
10304}
10305
924710306static ErrorMsg *ir_add_error_node(IrAnalyze *ira, AstNode *source_node, Buf *msg) {
9248 return exec_add_error_node(ira->codegen, ira->new_irb.exec, source_node, msg);
10307 return exec_add_error_node_gen(ira->codegen, ira->new_irb.exec, source_node, msg);
924910308}
925010309
925110310static ErrorMsg *opt_ir_add_error_node(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, Buf *msg) {
925210311 if (ira != nullptr)
9253 return exec_add_error_node(codegen, ira->new_irb.exec, source_node, msg);
10312 return exec_add_error_node_gen(codegen, ira->new_irb.exec, source_node, msg);
925410313 else
925510314 return add_node_error(codegen, source_node, msg);
925610315}
925710316
9258static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInstruction *source_instruction, Buf *msg) {
10317static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInst *source_instruction, Buf *msg) {
925910318 return ir_add_error_node(ira, source_instruction->source_node, msg);
926010319}
926110320
9262static void ir_assert(bool ok, IrInstruction *source_instruction) {
10321static void ir_assert(bool ok, IrInst *source_instruction) {
926310322 if (ok) return;
926410323 src_assert(ok, source_instruction->source_node);
926510324}
926610325
10326static void ir_assert_gen(bool ok, IrInstGen *source_instruction) {
10327 if (ok) return;
10328 src_assert(ok, source_instruction->base.source_node);
10329}
10330
926710331// This function takes a comptime ptr and makes the child const value conform to the type
926810332// described by the pointer.
926910333static Error eval_comptime_ptr_reinterpret(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,
......@@ -9309,43 +10373,43 @@ ZigValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ZigValue *const_va
930910373 return val;
931010374}
931110375
9312static ZigValue *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec) {
9313 IrBasicBlock *bb = exec->basic_block_list.at(0);
10376static ZigValue *ir_exec_const_result(CodeGen *codegen, IrExecutableGen *exec) {
10377 IrBasicBlockGen *bb = exec->basic_block_list.at(0);
931410378 for (size_t i = 0; i < bb->instruction_list.length; i += 1) {
9315 IrInstruction *instruction = bb->instruction_list.at(i);
9316 if (instruction->id == IrInstructionIdReturn) {
9317 IrInstructionReturn *ret_inst = (IrInstructionReturn *)instruction;
9318 IrInstruction *operand = ret_inst->operand;
10379 IrInstGen *instruction = bb->instruction_list.at(i);
10380 if (instruction->id == IrInstGenIdReturn) {
10381 IrInstGenReturn *ret_inst = (IrInstGenReturn *)instruction;
10382 IrInstGen *operand = ret_inst->operand;
931910383 if (operand->value->special == ConstValSpecialRuntime) {
9320 exec_add_error_node(codegen, exec, operand->source_node,
10384 exec_add_error_node_gen(codegen, exec, operand->base.source_node,
932110385 buf_sprintf("unable to evaluate constant expression"));
9322 return codegen->invalid_instruction->value;
10386 return codegen->invalid_inst_gen->value;
932310387 }
932410388 return operand->value;
9325 } else if (ir_has_side_effects(instruction)) {
10389 } else if (ir_inst_gen_has_side_effects(instruction)) {
932610390 if (instr_is_comptime(instruction)) {
932710391 switch (instruction->id) {
9328 case IrInstructionIdUnwrapErrPayload:
9329 case IrInstructionIdUnionFieldPtr:
10392 case IrInstGenIdUnwrapErrPayload:
10393 case IrInstGenIdUnionFieldPtr:
933010394 continue;
933110395 default:
933210396 break;
933310397 }
933410398 }
9335 if (get_scope_typeof(instruction->scope) != nullptr) {
10399 if (get_scope_typeof(instruction->base.scope) != nullptr) {
933610400 // doesn't count, it's inside a @TypeOf()
933710401 continue;
933810402 }
9339 exec_add_error_node(codegen, exec, instruction->source_node,
10403 exec_add_error_node_gen(codegen, exec, instruction->base.source_node,
934010404 buf_sprintf("unable to evaluate constant expression"));
9341 return codegen->invalid_instruction->value;
10405 return codegen->invalid_inst_gen->value;
934210406 }
934310407 }
934410408 zig_unreachable();
934510409}
934610410
9347static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInstruction *source_instruction) {
9348 if (ir_should_inline(ira->new_irb.exec, source_instruction->scope)) {
10411static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInst* source_instruction) {
10412 if (ir_should_inline(ira->old_irb.exec, source_instruction->scope)) {
934910413 ir_add_error(ira, source_instruction, buf_sprintf("unable to evaluate constant expression"));
935010414 return false;
935110415 }
......@@ -10079,7 +11143,7 @@ void float_read_ieee597(ZigValue *val, uint8_t *buf, bool is_big_endian) {
1007911143 }
1008011144}
1008111145
10082static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruction, ZigType *other_type,
11146static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstGen *instruction, ZigType *other_type,
1008311147 bool explicit_cast)
1008411148{
1008511149 if (type_is_invalid(other_type)) {
......@@ -10173,7 +11237,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
1017311237 }
1017411238 Buf *val_buf = buf_alloc();
1017511239 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);
10176 ir_add_error(ira, instruction,
11240 ir_add_error_node(ira, instruction->base.source_node,
1017711241 buf_sprintf("integer value %s has no representation in type '%s'",
1017811242 buf_ptr(val_buf),
1017911243 buf_ptr(&other_type->name)));
......@@ -10268,7 +11332,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
1026811332 }
1026911333 Buf *val_buf = buf_alloc();
1027011334 float_append_buf(val_buf, const_val);
10271 ir_add_error(ira, instruction,
11335 ir_add_error_node(ira, instruction->base.source_node,
1027211336 buf_sprintf("cast of value %s to type '%s' loses information",
1027311337 buf_ptr(val_buf),
1027411338 buf_ptr(&other_type->name)));
......@@ -10277,7 +11341,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
1027711341 if (!other_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) {
1027811342 Buf *val_buf = buf_alloc();
1027911343 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);
10280 ir_add_error(ira, instruction,
11344 ir_add_error_node(ira, instruction->base.source_node,
1028111345 buf_sprintf("cannot cast negative value %s to unsigned integer type '%s'",
1028211346 buf_ptr(val_buf),
1028311347 buf_ptr(&other_type->name)));
......@@ -10298,7 +11362,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
1029811362 if (!child_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) {
1029911363 Buf *val_buf = buf_alloc();
1030011364 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);
10301 ir_add_error(ira, instruction,
11365 ir_add_error_node(ira, instruction->base.source_node,
1030211366 buf_sprintf("cannot cast negative value %s to unsigned integer type '%s'",
1030311367 buf_ptr(val_buf),
1030411368 buf_ptr(&child_type->name)));
......@@ -10321,7 +11385,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
1032111385 Buf *val_buf = buf_alloc();
1032211386 float_append_buf(val_buf, const_val);
1032311387
10324 ir_add_error(ira, instruction,
11388 ir_add_error_node(ira, instruction->base.source_node,
1032511389 buf_sprintf("fractional component prevents float value %s from being casted to type '%s'",
1032611390 buf_ptr(val_buf),
1032711391 buf_ptr(&other_type->name)));
......@@ -10351,7 +11415,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
1035111415 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);
1035211416 }
1035311417
10354 ir_add_error(ira, instruction,
11418 ir_add_error_node(ira, instruction->base.source_node,
1035511419 buf_sprintf("%s value %s cannot be coerced to type '%s'",
1035611420 num_lit_str,
1035711421 buf_ptr(val_buf),
......@@ -10805,11 +11869,11 @@ static void update_errors_helper(CodeGen *g, ErrorTableEntry ***errors, size_t *
1080511869}
1080611870
1080711871static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigType *expected_type,
10808 IrInstruction **instructions, size_t instruction_count)
11872 IrInstGen **instructions, size_t instruction_count)
1080911873{
1081011874 Error err;
1081111875 assert(instruction_count >= 1);
10812 IrInstruction *prev_inst;
11876 IrInstGen *prev_inst;
1081311877 size_t i = 0;
1081411878 for (;;) {
1081511879 prev_inst = instructions[i];
......@@ -10829,7 +11893,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1082911893 size_t errors_count = 0;
1083011894 ZigType *err_set_type = nullptr;
1083111895 if (prev_inst->value->type->id == ZigTypeIdErrorSet) {
10832 if (!resolve_inferred_error_set(ira->codegen, prev_inst->value->type, prev_inst->source_node)) {
11896 if (!resolve_inferred_error_set(ira->codegen, prev_inst->value->type, prev_inst->base.source_node)) {
1083311897 return ira->codegen->builtin_types.entry_invalid;
1083411898 }
1083511899 if (type_is_global_error_set(prev_inst->value->type)) {
......@@ -10849,7 +11913,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1084911913 bool any_are_null = (prev_inst->value->type->id == ZigTypeIdNull);
1085011914 bool convert_to_const_slice = false;
1085111915 for (; i < instruction_count; i += 1) {
10852 IrInstruction *cur_inst = instructions[i];
11916 IrInstGen *cur_inst = instructions[i];
1085311917 ZigType *cur_type = cur_inst->value->type;
1085411918 ZigType *prev_type = prev_inst->value->type;
1085511919
......@@ -10871,14 +11935,14 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1087111935 }
1087211936
1087311937 if (prev_type->id == ZigTypeIdErrorSet) {
10874 ir_assert(err_set_type != nullptr, prev_inst);
11938 ir_assert_gen(err_set_type != nullptr, prev_inst);
1087511939 if (cur_type->id == ZigTypeIdErrorSet) {
1087611940 if (type_is_global_error_set(err_set_type)) {
1087711941 continue;
1087811942 }
1087911943 bool allow_infer = cur_type->data.error_set.infer_fn != nullptr &&
1088011944 cur_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry;
10881 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->source_node)) {
11945 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->base.source_node)) {
1088211946 return ira->codegen->builtin_types.entry_invalid;
1088311947 }
1088411948 if (!allow_infer && type_is_global_error_set(cur_type)) {
......@@ -10946,7 +12010,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1094612010 ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type;
1094712011 bool allow_infer = cur_err_set_type->data.error_set.infer_fn != nullptr &&
1094812012 cur_err_set_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry;
10949 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) {
12013 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->base.source_node)) {
1095012014 return ira->codegen->builtin_types.entry_invalid;
1095112015 }
1095212016 if (!allow_infer && type_is_global_error_set(cur_err_set_type)) {
......@@ -11001,7 +12065,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1100112065 if (cur_type->id == ZigTypeIdErrorSet) {
1100212066 bool allow_infer = cur_type->data.error_set.infer_fn != nullptr &&
1100312067 cur_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry;
11004 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->source_node)) {
12068 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->base.source_node)) {
1100512069 return ira->codegen->builtin_types.entry_invalid;
1100612070 }
1100712071 if (!allow_infer && type_is_global_error_set(cur_type)) {
......@@ -11024,7 +12088,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1102412088 err_set_type = cur_type;
1102512089 }
1102612090
11027 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, err_set_type, cur_inst->source_node)) {
12091 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, err_set_type, cur_inst->base.source_node)) {
1102812092 return ira->codegen->builtin_types.entry_invalid;
1102912093 }
1103012094
......@@ -11087,11 +12151,11 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1108712151 bool allow_infer_cur = cur_err_set_type->data.error_set.infer_fn != nullptr &&
1108812152 cur_err_set_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry;
1108912153
11090 if (!allow_infer_prev && !resolve_inferred_error_set(ira->codegen, prev_err_set_type, cur_inst->source_node)) {
12154 if (!allow_infer_prev && !resolve_inferred_error_set(ira->codegen, prev_err_set_type, cur_inst->base.source_node)) {
1109112155 return ira->codegen->builtin_types.entry_invalid;
1109212156 }
1109312157
11094 if (!allow_infer_cur && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) {
12158 if (!allow_infer_cur && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->base.source_node)) {
1109512159 return ira->codegen->builtin_types.entry_invalid;
1109612160 }
1109712161
......@@ -11268,7 +12332,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1126812332 ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type;
1126912333 bool allow_infer = cur_err_set_type->data.error_set.infer_fn != nullptr &&
1127012334 cur_err_set_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry;
11271 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) {
12335 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->base.source_node)) {
1127212336 return ira->codegen->builtin_types.entry_invalid;
1127312337 }
1127412338 if ((!allow_infer && type_is_global_error_set(cur_err_set_type)) ||
......@@ -11463,9 +12527,9 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1146312527 ErrorMsg *msg = ir_add_error_node(ira, source_node,
1146412528 buf_sprintf("incompatible types: '%s' and '%s'",
1146512529 buf_ptr(&prev_type->name), buf_ptr(&cur_type->name)));
11466 add_error_note(ira->codegen, msg, prev_inst->source_node,
12530 add_error_note(ira->codegen, msg, prev_inst->base.source_node,
1146712531 buf_sprintf("type '%s' here", buf_ptr(&prev_type->name)));
11468 add_error_note(ira->codegen, msg, cur_inst->source_node,
12532 add_error_note(ira->codegen, msg, cur_inst->base.source_node,
1146912533 buf_sprintf("type '%s' here", buf_ptr(&cur_type->name)));
1147012534
1147112535 return ira->codegen->builtin_types.entry_invalid;
......@@ -11535,7 +12599,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1153512599 }
1153612600}
1153712601
11538static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_instr,
12602static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInst *source_instr,
1153912603 CastOp cast_op,
1154012604 ZigValue *other_val, ZigType *other_type,
1154112605 ZigValue *const_val, ZigType *new_type)
......@@ -11635,58 +12699,56 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_
1163512699 return true;
1163612700}
1163712701
11638static IrInstruction *ir_const(IrAnalyze *ira, IrInstruction *old_instruction, ZigType *ty) {
11639 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
11640 old_instruction->scope, old_instruction->source_node);
11641 IrInstruction *new_instruction = &const_instruction->base;
12702static IrInstGen *ir_const(IrAnalyze *ira, IrInst *inst, ZigType *ty) {
12703 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
12704 inst->scope, inst->source_node);
12705 IrInstGen *new_instruction = &const_instruction->base;
1164212706 new_instruction->value->type = ty;
1164312707 new_instruction->value->special = ConstValSpecialStatic;
1164412708 return new_instruction;
1164512709}
1164612710
11647static IrInstruction *ir_const_noval(IrAnalyze *ira, IrInstruction *old_instruction) {
11648 IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(&ira->new_irb,
12711static IrInstGen *ir_const_noval(IrAnalyze *ira, IrInst *old_instruction) {
12712 IrInstGenConst *const_instruction = ir_create_inst_noval<IrInstGenConst>(&ira->new_irb,
1164912713 old_instruction->scope, old_instruction->source_node);
1165012714 return &const_instruction->base;
1165112715}
1165212716
11653// This function initializes the new IrInstruction with the provided ZigValue,
12717// This function initializes the new IrInstGen with the provided ZigValue,
1165412718// rather than creating a new one.
11655static IrInstruction *ir_const_move(IrAnalyze *ira, IrInstruction *old_instruction, ZigValue *val) {
11656 IrInstruction *result = ir_const_noval(ira, old_instruction);
12719static IrInstGen *ir_const_move(IrAnalyze *ira, IrInst *old_instruction, ZigValue *val) {
12720 IrInstGen *result = ir_const_noval(ira, old_instruction);
1165712721 result->value = val;
1165812722 return result;
1165912723}
1166012724
11661static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
12725static IrInstGen *ir_resolve_cast(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value,
1166212726 ZigType *wanted_type, CastOp cast_op)
1166312727{
1166412728 if (instr_is_comptime(value) || !type_has_bits(wanted_type)) {
11665 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
12729 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1166612730 if (!eval_const_expr_implicit_cast(ira, source_instr, cast_op, value->value, value->value->type,
1166712731 result->value, wanted_type))
1166812732 {
11669 return ira->codegen->invalid_instruction;
12733 return ira->codegen->invalid_inst_gen;
1167012734 }
1167112735 return result;
1167212736 } else {
11673 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type, value, cast_op);
11674 result->value->type = wanted_type;
11675 return result;
12737 return ir_build_cast(ira, source_instr, wanted_type, value, cast_op);
1167612738 }
1167712739}
1167812740
11679static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrInstruction *source_instr,
11680 IrInstruction *value, ZigType *wanted_type)
12741static IrInstGen *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrInst* source_instr,
12742 IrInstGen *value, ZigType *wanted_type)
1168112743{
11682 assert(value->value->type->id == ZigTypeIdPointer);
12744 ir_assert(value->value->type->id == ZigTypeIdPointer, source_instr);
1168312745
1168412746 Error err;
1168512747
1168612748 if ((err = type_resolve(ira->codegen, value->value->type->data.pointer.child_type,
1168712749 ResolveStatusAlignmentKnown)))
1168812750 {
11689 return ira->codegen->invalid_instruction;
12751 return ira->codegen->invalid_inst_gen;
1169012752 }
1169112753
1169212754 wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, value->value->type));
......@@ -11694,9 +12756,9 @@ static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira,
1169412756 if (instr_is_comptime(value)) {
1169512757 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, value->value, source_instr->source_node);
1169612758 if (pointee == nullptr)
11697 return ira->codegen->invalid_instruction;
12759 return ira->codegen->invalid_inst_gen;
1169812760 if (pointee->special != ConstValSpecialRuntime) {
11699 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
12761 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1170012762 result->value->data.x_ptr.special = ConstPtrSpecialBaseArray;
1170112763 result->value->data.x_ptr.mut = value->value->data.x_ptr.mut;
1170212764 result->value->data.x_ptr.data.base_array.array_val = pointee;
......@@ -11705,21 +12767,18 @@ static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira,
1170512767 }
1170612768 }
1170712769
11708 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node,
11709 wanted_type, value, CastOpBitCast);
11710 result->value->type = wanted_type;
11711 return result;
12770 return ir_build_cast(ira, source_instr, wanted_type, value, CastOpBitCast);
1171212771}
1171312772
11714static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruction *source_instr,
11715 IrInstruction *array_ptr, ZigType *wanted_type, ResultLoc *result_loc)
12773static IrInstGen *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInst* source_instr,
12774 IrInstGen *array_ptr, ZigType *wanted_type, ResultLoc *result_loc)
1171612775{
1171712776 Error err;
1171812777
1171912778 if ((err = type_resolve(ira->codegen, array_ptr->value->type->data.pointer.child_type,
1172012779 ResolveStatusAlignmentKnown)))
1172112780 {
11722 return ira->codegen->invalid_instruction;
12781 return ira->codegen->invalid_inst_gen;
1172312782 }
1172412783
1172512784 wanted_type = adjust_slice_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, array_ptr->value->type));
......@@ -11727,14 +12786,14 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc
1172712786 if (instr_is_comptime(array_ptr)) {
1172812787 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, array_ptr->value, source_instr->source_node);
1172912788 if (pointee == nullptr)
11730 return ira->codegen->invalid_instruction;
12789 return ira->codegen->invalid_inst_gen;
1173112790 if (pointee->special != ConstValSpecialRuntime) {
1173212791 assert(array_ptr->value->type->id == ZigTypeIdPointer);
1173312792 ZigType *array_type = array_ptr->value->type->data.pointer.child_type;
1173412793 assert(is_slice(wanted_type));
1173512794 bool is_const = wanted_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const;
1173612795
11737 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
12796 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1173812797 init_const_slice(ira->codegen, result->value, pointee, 0, array_type->data.array.len, is_const);
1173912798 result->value->data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = array_ptr->value->data.x_ptr.mut;
1174012799 result->value->type = wanted_type;
......@@ -11743,32 +12802,34 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc
1174312802 }
1174412803
1174512804 if (result_loc == nullptr) result_loc = no_result_loc();
11746 IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true,
12805 IrInstGen *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true,
1174712806 false, true);
11748 if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) {
12807 if (type_is_invalid(result_loc_inst->value->type) ||
12808 result_loc_inst->value->type->id == ZigTypeIdUnreachable)
12809 {
1174912810 return result_loc_inst;
1175012811 }
1175112812 return ir_build_ptr_of_array_to_slice(ira, source_instr, wanted_type, array_ptr, result_loc_inst);
1175212813}
1175312814
11754static IrBasicBlock *ir_get_new_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrInstruction *ref_old_instruction) {
12815static IrBasicBlockGen *ir_get_new_bb(IrAnalyze *ira, IrBasicBlockSrc *old_bb, IrInst *ref_old_instruction) {
1175512816 assert(old_bb);
1175612817
11757 if (old_bb->other) {
11758 if (ref_old_instruction == nullptr || old_bb->other->ref_instruction != ref_old_instruction) {
11759 return old_bb->other;
12818 if (old_bb->child) {
12819 if (ref_old_instruction == nullptr || old_bb->child->ref_instruction != ref_old_instruction) {
12820 return old_bb->child;
1176012821 }
1176112822 }
1176212823
11763 IrBasicBlock *new_bb = ir_build_bb_from(&ira->new_irb, old_bb);
12824 IrBasicBlockGen *new_bb = ir_build_bb_from(ira, old_bb);
1176412825 new_bb->ref_instruction = ref_old_instruction;
1176512826
1176612827 return new_bb;
1176712828}
1176812829
11769static IrBasicBlock *ir_get_new_bb_runtime(IrAnalyze *ira, IrBasicBlock *old_bb, IrInstruction *ref_old_instruction) {
12830static IrBasicBlockGen *ir_get_new_bb_runtime(IrAnalyze *ira, IrBasicBlockSrc *old_bb, IrInst *ref_old_instruction) {
1177012831 assert(ref_old_instruction != nullptr);
11771 IrBasicBlock *new_bb = ir_get_new_bb(ira, old_bb, ref_old_instruction);
12832 IrBasicBlockGen *new_bb = ir_get_new_bb(ira, old_bb, ref_old_instruction);
1177212833 if (new_bb->must_be_comptime_source_instr) {
1177312834 ErrorMsg *msg = ir_add_error(ira, ref_old_instruction,
1177412835 buf_sprintf("control flow attempts to use compile-time variable at runtime"));
......@@ -11779,24 +12840,24 @@ static IrBasicBlock *ir_get_new_bb_runtime(IrAnalyze *ira, IrBasicBlock *old_bb,
1177912840 return new_bb;
1178012841}
1178112842
11782static void ir_start_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrBasicBlock *const_predecessor_bb) {
11783 ir_assert(!old_bb->suspended, (old_bb->instruction_list.length != 0) ? old_bb->instruction_list.at(0) : nullptr);
12843static void ir_start_bb(IrAnalyze *ira, IrBasicBlockSrc *old_bb, IrBasicBlockSrc *const_predecessor_bb) {
12844 ir_assert(!old_bb->suspended, (old_bb->instruction_list.length != 0) ? &old_bb->instruction_list.at(0)->base : nullptr);
1178412845 ira->instruction_index = 0;
1178512846 ira->old_irb.current_basic_block = old_bb;
1178612847 ira->const_predecessor_bb = const_predecessor_bb;
1178712848 ira->old_bb_index = old_bb->index;
1178812849}
1178912850
11790static IrInstruction *ira_suspend(IrAnalyze *ira, IrInstruction *old_instruction, IrBasicBlock *next_bb,
12851static IrInstGen *ira_suspend(IrAnalyze *ira, IrInst *old_instruction, IrBasicBlockSrc *next_bb,
1179112852 IrSuspendPosition *suspend_pos)
1179212853{
1179312854 if (ira->codegen->verbose_ir) {
11794 fprintf(stderr, "suspend %s_%zu %s_%zu #%" PRIu32 " (%zu,%zu)\n",
12855 fprintf(stderr, "suspend %s_%" PRIu32 " %s_%" PRIu32 " #%" PRIu32 " (%zu,%zu)\n",
1179512856 ira->old_irb.current_basic_block->name_hint,
1179612857 ira->old_irb.current_basic_block->debug_id,
1179712858 ira->old_irb.exec->basic_block_list.at(ira->old_bb_index)->name_hint,
1179812859 ira->old_irb.exec->basic_block_list.at(ira->old_bb_index)->debug_id,
11799 ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index)->debug_id,
12860 ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index)->base.debug_id,
1180012861 ira->old_bb_index, ira->instruction_index);
1180112862 }
1180212863 suspend_pos->basic_block_index = ira->old_bb_index;
......@@ -11811,13 +12872,13 @@ static IrInstruction *ira_suspend(IrAnalyze *ira, IrInstruction *old_instruction
1181112872 assert(ira->old_irb.current_basic_block == next_bb);
1181212873 ira->instruction_index = 0;
1181312874 ira->const_predecessor_bb = nullptr;
11814 next_bb->other = ir_get_new_bb_runtime(ira, next_bb, old_instruction);
11815 ira->new_irb.current_basic_block = next_bb->other;
12875 next_bb->child = ir_get_new_bb_runtime(ira, next_bb, old_instruction);
12876 ira->new_irb.current_basic_block = next_bb->child;
1181612877 }
1181712878 return ira->codegen->unreach_instruction;
1181812879}
1181912880
11820static IrInstruction *ira_resume(IrAnalyze *ira) {
12881static IrInstGen *ira_resume(IrAnalyze *ira) {
1182112882 IrSuspendPosition pos = ira->resume_stack.pop();
1182212883 if (ira->codegen->verbose_ir) {
1182312884 fprintf(stderr, "resume (%zu,%zu) ", pos.basic_block_index, pos.instruction_index);
......@@ -11830,12 +12891,12 @@ static IrInstruction *ira_resume(IrAnalyze *ira) {
1183012891 ira->instruction_index = pos.instruction_index;
1183112892 assert(pos.instruction_index < ira->old_irb.current_basic_block->instruction_list.length);
1183212893 if (ira->codegen->verbose_ir) {
11833 fprintf(stderr, "%s_%zu #%" PRIu32 "\n", ira->old_irb.current_basic_block->name_hint,
12894 fprintf(stderr, "%s_%" PRIu32 " #%" PRIu32 "\n", ira->old_irb.current_basic_block->name_hint,
1183412895 ira->old_irb.current_basic_block->debug_id,
11835 ira->old_irb.current_basic_block->instruction_list.at(pos.instruction_index)->debug_id);
12896 ira->old_irb.current_basic_block->instruction_list.at(pos.instruction_index)->base.debug_id);
1183612897 }
1183712898 ira->const_predecessor_bb = nullptr;
11838 ira->new_irb.current_basic_block = ira->old_irb.current_basic_block->other;
12899 ira->new_irb.current_basic_block = ira->old_irb.current_basic_block->child;
1183912900 assert(ira->new_irb.current_basic_block != nullptr);
1184012901 return ira->codegen->unreach_instruction;
1184112902}
......@@ -11846,8 +12907,8 @@ static void ir_start_next_bb(IrAnalyze *ira) {
1184612907 bool need_repeat = true;
1184712908 for (;;) {
1184812909 while (ira->old_bb_index < ira->old_irb.exec->basic_block_list.length) {
11849 IrBasicBlock *old_bb = ira->old_irb.exec->basic_block_list.at(ira->old_bb_index);
11850 if (old_bb->other == nullptr && old_bb->suspend_instruction_ref == nullptr) {
12910 IrBasicBlockSrc *old_bb = ira->old_irb.exec->basic_block_list.at(ira->old_bb_index);
12911 if (old_bb->child == nullptr && old_bb->suspend_instruction_ref == nullptr) {
1185112912 ira->old_bb_index += 1;
1185212913 continue;
1185312914 }
......@@ -11855,8 +12916,8 @@ static void ir_start_next_bb(IrAnalyze *ira) {
1185512916 // if it's a suspended block,
1185612917 // then skip it
1185712918 if (old_bb->suspended ||
11858 (old_bb->other != nullptr && old_bb->other->instruction_list.length != 0) ||
11859 (old_bb->other != nullptr && old_bb->other->already_appended))
12919 (old_bb->child != nullptr && old_bb->child->instruction_list.length != 0) ||
12920 (old_bb->child != nullptr && old_bb->child->already_appended))
1186012921 {
1186112922 ira->old_bb_index += 1;
1186212923 continue;
......@@ -11870,10 +12931,10 @@ static void ir_start_next_bb(IrAnalyze *ira) {
1187012931 return;
1187112932 }
1187212933
11873 if (old_bb->other == nullptr) {
11874 old_bb->other = ir_get_new_bb_runtime(ira, old_bb, old_bb->suspend_instruction_ref);
12934 if (old_bb->child == nullptr) {
12935 old_bb->child = ir_get_new_bb_runtime(ira, old_bb, old_bb->suspend_instruction_ref);
1187512936 }
11876 ira->new_irb.current_basic_block = old_bb->other;
12937 ira->new_irb.current_basic_block = old_bb->child;
1187712938 ir_start_bb(ira, old_bb, nullptr);
1187812939 return;
1187912940 }
......@@ -11893,16 +12954,16 @@ static void ir_finish_bb(IrAnalyze *ira) {
1189312954 if (!ira->new_irb.current_basic_block->already_appended) {
1189412955 ira->new_irb.current_basic_block->already_appended = true;
1189512956 if (ira->codegen->verbose_ir) {
11896 fprintf(stderr, "append new bb %s_%zu\n", ira->new_irb.current_basic_block->name_hint,
12957 fprintf(stderr, "append new bb %s_%" PRIu32 "\n", ira->new_irb.current_basic_block->name_hint,
1189712958 ira->new_irb.current_basic_block->debug_id);
1189812959 }
1189912960 ira->new_irb.exec->basic_block_list.append(ira->new_irb.current_basic_block);
1190012961 }
1190112962 ira->instruction_index += 1;
1190212963 while (ira->instruction_index < ira->old_irb.current_basic_block->instruction_list.length) {
11903 IrInstruction *next_instruction = ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index);
12964 IrInstSrc *next_instruction = ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index);
1190412965 if (!next_instruction->is_gen) {
11905 ir_add_error(ira, next_instruction, buf_sprintf("unreachable code"));
12966 ir_add_error(ira, &next_instruction->base, buf_sprintf("unreachable code"));
1190612967 break;
1190712968 }
1190812969 ira->instruction_index += 1;
......@@ -11911,7 +12972,7 @@ static void ir_finish_bb(IrAnalyze *ira) {
1191112972 ir_start_next_bb(ira);
1191212973}
1191312974
11914static IrInstruction *ir_unreach_error(IrAnalyze *ira) {
12975static IrInstGen *ir_unreach_error(IrAnalyze *ira) {
1191512976 ira->old_bb_index = SIZE_MAX;
1191612977 if (ira->new_irb.exec->first_err_trace_msg == nullptr) {
1191712978 ira->new_irb.exec->first_err_trace_msg = ira->codegen->trace_err;
......@@ -11919,7 +12980,7 @@ static IrInstruction *ir_unreach_error(IrAnalyze *ira) {
1191912980 return ira->codegen->unreach_instruction;
1192012981}
1192112982
11922static bool ir_emit_backward_branch(IrAnalyze *ira, IrInstruction *source_instruction) {
12983static bool ir_emit_backward_branch(IrAnalyze *ira, IrInst* source_instruction) {
1192312984 size_t *bbc = ira->new_irb.exec->backward_branch_count;
1192412985 size_t *quota = ira->new_irb.exec->backward_branch_quota;
1192512986
......@@ -11938,66 +12999,82 @@ static bool ir_emit_backward_branch(IrAnalyze *ira, IrInstruction *source_instru
1193812999 return true;
1193913000}
1194013001
11941static IrInstruction *ir_inline_bb(IrAnalyze *ira, IrInstruction *source_instruction, IrBasicBlock *old_bb) {
13002static IrInstGen *ir_inline_bb(IrAnalyze *ira, IrInst* source_instruction, IrBasicBlockSrc *old_bb) {
1194213003 if (old_bb->debug_id <= ira->old_irb.current_basic_block->debug_id) {
1194313004 if (!ir_emit_backward_branch(ira, source_instruction))
1194413005 return ir_unreach_error(ira);
1194513006 }
1194613007
11947 old_bb->other = ira->old_irb.current_basic_block->other;
13008 old_bb->child = ira->old_irb.current_basic_block->child;
1194813009 ir_start_bb(ira, old_bb, ira->old_irb.current_basic_block);
1194913010 return ira->codegen->unreach_instruction;
1195013011}
1195113012
11952static IrInstruction *ir_finish_anal(IrAnalyze *ira, IrInstruction *instruction) {
13013static IrInstGen *ir_finish_anal(IrAnalyze *ira, IrInstGen *instruction) {
1195313014 if (instruction->value->type->id == ZigTypeIdUnreachable)
1195413015 ir_finish_bb(ira);
1195513016 return instruction;
1195613017}
1195713018
11958static IrInstruction *ir_const_type(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) {
11959 IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_type);
13019static IrInstGen *ir_const_fn(IrAnalyze *ira, IrInst *source_instr, ZigFn *fn_entry) {
13020 IrInstGen *result = ir_const(ira, source_instr, fn_entry->type_entry);
13021 result->value->special = ConstValSpecialStatic;
13022 result->value->data.x_ptr.data.fn.fn_entry = fn_entry;
13023 result->value->data.x_ptr.mut = ConstPtrMutComptimeConst;
13024 result->value->data.x_ptr.special = ConstPtrSpecialFunction;
13025 return result;
13026}
13027
13028static IrInstGen *ir_const_bound_fn(IrAnalyze *ira, IrInst *src_inst, ZigFn *fn_entry, IrInstGen *first_arg) {
13029 IrInstGen *result = ir_const(ira, src_inst, get_bound_fn_type(ira->codegen, fn_entry));
13030 result->value->data.x_bound_fn.fn = fn_entry;
13031 result->value->data.x_bound_fn.first_arg = first_arg;
13032 return result;
13033}
13034
13035static IrInstGen *ir_const_type(IrAnalyze *ira, IrInst *source_instruction, ZigType *ty) {
13036 IrInstGen *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_type);
1196013037 result->value->data.x_type = ty;
1196113038 return result;
1196213039}
1196313040
11964static IrInstruction *ir_const_bool(IrAnalyze *ira, IrInstruction *source_instruction, bool value) {
11965 IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_bool);
13041static IrInstGen *ir_const_bool(IrAnalyze *ira, IrInst *source_instruction, bool value) {
13042 IrInstGen *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_bool);
1196613043 result->value->data.x_bool = value;
1196713044 return result;
1196813045}
1196913046
11970static IrInstruction *ir_const_undef(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) {
11971 IrInstruction *result = ir_const(ira, source_instruction, ty);
13047static IrInstGen *ir_const_undef(IrAnalyze *ira, IrInst *source_instruction, ZigType *ty) {
13048 IrInstGen *result = ir_const(ira, source_instruction, ty);
1197213049 result->value->special = ConstValSpecialUndef;
1197313050 return result;
1197413051}
1197513052
11976static IrInstruction *ir_const_unreachable(IrAnalyze *ira, IrInstruction *source_instruction) {
11977 IrInstruction *result = ir_const_noval(ira, source_instruction);
13053static IrInstGen *ir_const_unreachable(IrAnalyze *ira, IrInst *source_instruction) {
13054 IrInstGen *result = ir_const_noval(ira, source_instruction);
1197813055 result->value = ira->codegen->intern.for_unreachable();
1197913056 return result;
1198013057}
1198113058
11982static IrInstruction *ir_const_void(IrAnalyze *ira, IrInstruction *source_instruction) {
11983 IrInstruction *result = ir_const_noval(ira, source_instruction);
13059static IrInstGen *ir_const_void(IrAnalyze *ira, IrInst *source_instruction) {
13060 IrInstGen *result = ir_const_noval(ira, source_instruction);
1198413061 result->value = ira->codegen->intern.for_void();
1198513062 return result;
1198613063}
1198713064
11988static IrInstruction *ir_const_unsigned(IrAnalyze *ira, IrInstruction *source_instruction, uint64_t value) {
11989 IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_num_lit_int);
13065static IrInstGen *ir_const_unsigned(IrAnalyze *ira, IrInst *source_instruction, uint64_t value) {
13066 IrInstGen *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_num_lit_int);
1199013067 bigint_init_unsigned(&result->value->data.x_bigint, value);
1199113068 return result;
1199213069}
1199313070
11994static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instruction,
13071static IrInstGen *ir_get_const_ptr(IrAnalyze *ira, IrInst *instruction,
1199513072 ZigValue *pointee, ZigType *pointee_type,
1199613073 ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align)
1199713074{
1199813075 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type,
1199913076 ptr_is_const, ptr_is_volatile, PtrLenSingle, ptr_align, 0, 0, false);
12000 IrInstruction *const_instr = ir_const(ira, instruction, ptr_type);
13077 IrInstGen *const_instr = ir_const(ira, instruction, ptr_type);
1200113078 ZigValue *const_val = const_instr->value;
1200213079 const_val->data.x_ptr.special = ConstPtrSpecialRef;
1200313080 const_val->data.x_ptr.mut = ptr_mut;
......@@ -12005,7 +13082,7 @@ static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instructio
1200513082 return const_instr;
1200613083}
1200713084
12008static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode *source_node,
13085static Error ir_resolve_const_val(CodeGen *codegen, IrExecutableGen *exec, AstNode *source_node,
1200913086 ZigValue *val, UndefAllowed undef_allowed)
1201013087{
1201113088 Error err;
......@@ -12017,14 +13094,14 @@ static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode
1201713094 if (!type_has_bits(val->type))
1201813095 return ErrorNone;
1201913096
12020 exec_add_error_node(codegen, exec, source_node,
13097 exec_add_error_node_gen(codegen, exec, source_node,
1202113098 buf_sprintf("unable to evaluate constant expression"));
1202213099 return ErrorSemanticAnalyzeFail;
1202313100 case ConstValSpecialUndef:
1202413101 if (undef_allowed == UndefOk || undef_allowed == LazyOk)
1202513102 return ErrorNone;
1202613103
12027 exec_add_error_node(codegen, exec, source_node,
13104 exec_add_error_node_gen(codegen, exec, source_node,
1202813105 buf_sprintf("use of undefined value here causes undefined behavior"));
1202913106 return ErrorSemanticAnalyzeFail;
1203013107 case ConstValSpecialLazy:
......@@ -12039,9 +13116,9 @@ static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode
1203913116 }
1204013117}
1204113118
12042static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed) {
13119static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstGen *value, UndefAllowed undef_allowed) {
1204313120 Error err;
12044 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, value->source_node,
13121 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, value->base.source_node,
1204513122 value->value, undef_allowed)))
1204613123 {
1204713124 return nullptr;
......@@ -12052,14 +13129,14 @@ static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAll
1205213129ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
1205313130 ZigType *expected_type, size_t *backward_branch_count, size_t *backward_branch_quota,
1205413131 ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,
12055 IrExecutable *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef_allowed)
13132 IrExecutableGen *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef_allowed)
1205613133{
1205713134 Error err;
1205813135
1205913136 if (expected_type != nullptr && type_is_invalid(expected_type))
12060 return codegen->invalid_instruction->value;
13137 return codegen->invalid_inst_gen->value;
1206113138
12062 IrExecutable *ir_executable = allocate<IrExecutable>(1, "IrExecutablePass1");
13139 IrExecutableSrc *ir_executable = allocate<IrExecutableSrc>(1, "IrExecutableSrc");
1206313140 ir_executable->source_node = source_node;
1206413141 ir_executable->parent_exec = parent_exec;
1206513142 ir_executable->name = exec_name;
......@@ -12069,21 +13146,21 @@ ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
1206913146 ir_executable->begin_scope = scope;
1207013147
1207113148 if (!ir_gen(codegen, node, scope, ir_executable))
12072 return codegen->invalid_instruction->value;
13149 return codegen->invalid_inst_gen->value;
1207313150
1207413151 if (ir_executable->first_err_trace_msg != nullptr) {
1207513152 codegen->trace_err = ir_executable->first_err_trace_msg;
12076 return codegen->invalid_instruction->value;
13153 return codegen->invalid_inst_gen->value;
1207713154 }
1207813155
1207913156 if (codegen->verbose_ir) {
1208013157 fprintf(stderr, "\nSource: ");
1208113158 ast_render(stderr, node, 4);
1208213159 fprintf(stderr, "\n{ // (IR)\n");
12083 ir_print(codegen, stderr, ir_executable, 2, IrPassSrc);
13160 ir_print_src(codegen, stderr, ir_executable, 2);
1208413161 fprintf(stderr, "}\n");
1208513162 }
12086 IrExecutable *analyzed_executable = allocate<IrExecutable>(1, "IrExecutablePass2");
13163 IrExecutableGen *analyzed_executable = allocate<IrExecutableGen>(1, "IrExecutableGen");
1208713164 analyzed_executable->source_node = source_node;
1208813165 analyzed_executable->parent_exec = parent_exec;
1208913166 analyzed_executable->source_exec = ir_executable;
......@@ -12096,31 +13173,31 @@ ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
1209613173 analyzed_executable->begin_scope = scope;
1209713174 ZigType *result_type = ir_analyze(codegen, ir_executable, analyzed_executable, expected_type, expected_type_source_node);
1209813175 if (type_is_invalid(result_type)) {
12099 return codegen->invalid_instruction->value;
13176 return codegen->invalid_inst_gen->value;
1210013177 }
1210113178
1210213179 if (codegen->verbose_ir) {
1210313180 fprintf(stderr, "{ // (analyzed)\n");
12104 ir_print(codegen, stderr, analyzed_executable, 2, IrPassGen);
13181 ir_print_gen(codegen, stderr, analyzed_executable, 2);
1210513182 fprintf(stderr, "}\n");
1210613183 }
1210713184
1210813185 ZigValue *result = ir_exec_const_result(codegen, analyzed_executable);
1210913186 if (type_is_invalid(result->type))
12110 return codegen->invalid_instruction->value;
13187 return codegen->invalid_inst_gen->value;
1211113188
1211213189 if ((err = ir_resolve_const_val(codegen, analyzed_executable, node, result, undef_allowed)))
12113 return codegen->invalid_instruction->value;
13190 return codegen->invalid_inst_gen->value;
1211413191
1211513192 return result;
1211613193}
1211713194
12118static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstruction *err_value) {
13195static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstGen *err_value) {
1211913196 if (type_is_invalid(err_value->value->type))
1212013197 return nullptr;
1212113198
1212213199 if (err_value->value->type->id != ZigTypeIdErrorSet) {
12123 ir_add_error(ira, err_value,
13200 ir_add_error_node(ira, err_value->base.source_node,
1212413201 buf_sprintf("expected error, found '%s'", buf_ptr(&err_value->value->type->name)));
1212513202 return nullptr;
1212613203 }
......@@ -12133,7 +13210,7 @@ static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstruction *err_valu
1213313210 return const_val->data.x_err_set;
1213413211}
1213513212
12136static ZigType *ir_resolve_const_type(CodeGen *codegen, IrExecutable *exec, AstNode *source_node,
13213static ZigType *ir_resolve_const_type(CodeGen *codegen, IrExecutableGen *exec, AstNode *source_node,
1213713214 ZigValue *val)
1213813215{
1213913216 Error err;
......@@ -12144,18 +13221,18 @@ static ZigType *ir_resolve_const_type(CodeGen *codegen, IrExecutable *exec, AstN
1214413221 return val->data.x_type;
1214513222}
1214613223
12147static ZigValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstruction *type_value) {
13224static ZigValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstGen *type_value) {
1214813225 if (type_is_invalid(type_value->value->type))
1214913226 return nullptr;
1215013227
1215113228 if (type_value->value->type->id != ZigTypeIdMetaType) {
12152 ir_add_error(ira, type_value,
13229 ir_add_error_node(ira, type_value->base.source_node,
1215313230 buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->value->type->name)));
1215413231 return nullptr;
1215513232 }
1215613233
1215713234 Error err;
12158 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, type_value->source_node,
13235 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, type_value->base.source_node,
1215913236 type_value->value, LazyOk)))
1216013237 {
1216113238 return nullptr;
......@@ -12164,17 +13241,17 @@ static ZigValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstruction *type_value)
1216413241 return type_value->value;
1216513242}
1216613243
12167static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) {
13244static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstGen *type_value) {
1216813245 ZigValue *val = ir_resolve_type_lazy(ira, type_value);
1216913246 if (val == nullptr)
1217013247 return ira->codegen->builtin_types.entry_invalid;
1217113248
12172 return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, type_value->source_node, val);
13249 return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, type_value->base.source_node, val);
1217313250}
1217413251
12175static Error ir_validate_vector_elem_type(IrAnalyze *ira, IrInstruction *source_instr, ZigType *elem_type) {
13252static Error ir_validate_vector_elem_type(IrAnalyze *ira, AstNode *source_node, ZigType *elem_type) {
1217613253 if (!is_valid_vector_elem_type(elem_type)) {
12177 ir_add_error(ira, source_instr,
13254 ir_add_error_node(ira, source_node,
1217813255 buf_sprintf("vector element type must be integer, float, bool, or pointer; '%s' is invalid",
1217913256 buf_ptr(&elem_type->name)));
1218013257 return ErrorSemanticAnalyzeFail;
......@@ -12182,28 +13259,28 @@ static Error ir_validate_vector_elem_type(IrAnalyze *ira, IrInstruction *source_
1218213259 return ErrorNone;
1218313260}
1218413261
12185static ZigType *ir_resolve_vector_elem_type(IrAnalyze *ira, IrInstruction *elem_type_value) {
13262static ZigType *ir_resolve_vector_elem_type(IrAnalyze *ira, IrInstGen *elem_type_value) {
1218613263 Error err;
1218713264 ZigType *elem_type = ir_resolve_type(ira, elem_type_value);
1218813265 if (type_is_invalid(elem_type))
1218913266 return ira->codegen->builtin_types.entry_invalid;
12190 if ((err = ir_validate_vector_elem_type(ira, elem_type_value, elem_type)))
13267 if ((err = ir_validate_vector_elem_type(ira, elem_type_value->base.source_node, elem_type)))
1219113268 return ira->codegen->builtin_types.entry_invalid;
1219213269 return elem_type;
1219313270}
1219413271
12195static ZigType *ir_resolve_int_type(IrAnalyze *ira, IrInstruction *type_value) {
13272static ZigType *ir_resolve_int_type(IrAnalyze *ira, IrInstGen *type_value) {
1219613273 ZigType *ty = ir_resolve_type(ira, type_value);
1219713274 if (type_is_invalid(ty))
1219813275 return ira->codegen->builtin_types.entry_invalid;
1219913276
1220013277 if (ty->id != ZigTypeIdInt) {
12201 ErrorMsg *msg = ir_add_error(ira, type_value,
13278 ErrorMsg *msg = ir_add_error_node(ira, type_value->base.source_node,
1220213279 buf_sprintf("expected integer type, found '%s'", buf_ptr(&ty->name)));
1220313280 if (ty->id == ZigTypeIdVector &&
1220413281 ty->data.vector.elem_type->id == ZigTypeIdInt)
1220513282 {
12206 add_error_note(ira->codegen, msg, type_value->source_node,
13283 add_error_note(ira->codegen, msg, type_value->base.source_node,
1220713284 buf_sprintf("represent vectors with their element types, i.e. '%s'",
1220813285 buf_ptr(&ty->data.vector.elem_type->name)));
1220913286 }
......@@ -12213,12 +13290,12 @@ static ZigType *ir_resolve_int_type(IrAnalyze *ira, IrInstruction *type_value) {
1221313290 return ty;
1221413291}
1221513292
12216static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInstruction *op_source, IrInstruction *type_value) {
13293static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInst *op_source, IrInstGen *type_value) {
1221713294 if (type_is_invalid(type_value->value->type))
1221813295 return ira->codegen->builtin_types.entry_invalid;
1221913296
1222013297 if (type_value->value->type->id != ZigTypeIdMetaType) {
12221 ErrorMsg *msg = ir_add_error(ira, type_value,
13298 ErrorMsg *msg = ir_add_error_node(ira, type_value->base.source_node,
1222213299 buf_sprintf("expected error set type, found '%s'", buf_ptr(&type_value->value->type->name)));
1222313300 add_error_note(ira->codegen, msg, op_source->source_node,
1222413301 buf_sprintf("`||` merges error sets; `or` performs boolean OR"));
......@@ -12232,7 +13309,7 @@ static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInstruction *op_sour
1223213309 assert(const_val->data.x_type != nullptr);
1223313310 ZigType *result_type = const_val->data.x_type;
1223413311 if (result_type->id != ZigTypeIdErrorSet) {
12235 ErrorMsg *msg = ir_add_error(ira, type_value,
13312 ErrorMsg *msg = ir_add_error_node(ira, type_value->base.source_node,
1223613313 buf_sprintf("expected error set type, found type '%s'", buf_ptr(&result_type->name)));
1223713314 add_error_note(ira->codegen, msg, op_source->source_node,
1223813315 buf_sprintf("`||` merges error sets; `or` performs boolean OR"));
......@@ -12241,15 +13318,12 @@ static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInstruction *op_sour
1224113318 return result_type;
1224213319}
1224313320
12244static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {
12245 if (fn_value == ira->codegen->invalid_instruction)
12246 return nullptr;
12247
13321static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstGen *fn_value) {
1224813322 if (type_is_invalid(fn_value->value->type))
1224913323 return nullptr;
1225013324
1225113325 if (fn_value->value->type->id != ZigTypeIdFn) {
12252 ir_add_error_node(ira, fn_value->source_node,
13326 ir_add_error_node(ira, fn_value->base.source_node,
1225313327 buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->value->type->name)));
1225413328 return nullptr;
1225513329 }
......@@ -12265,22 +13339,22 @@ static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {
1226513339 return const_val->data.x_ptr.data.fn.fn_entry;
1226613340}
1226713341
12268static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
12269 ZigType *wanted_type, ResultLoc *result_loc)
13342static IrInstGen *ir_analyze_optional_wrap(IrAnalyze *ira, IrInst* source_instr,
13343 IrInstGen *value, ZigType *wanted_type, ResultLoc *result_loc)
1227013344{
1227113345 assert(wanted_type->id == ZigTypeIdOptional);
1227213346
1227313347 if (instr_is_comptime(value)) {
1227413348 ZigType *payload_type = wanted_type->data.maybe.child_type;
12275 IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type);
13349 IrInstGen *casted_payload = ir_implicit_cast(ira, value, payload_type);
1227613350 if (type_is_invalid(casted_payload->value->type))
12277 return ira->codegen->invalid_instruction;
13351 return ira->codegen->invalid_inst_gen;
1227813352
1227913353 ZigValue *val = ir_resolve_const(ira, casted_payload, UndefOk);
1228013354 if (!val)
12281 return ira->codegen->invalid_instruction;
13355 return ira->codegen->invalid_inst_gen;
1228213356
12283 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
13357 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
1228413358 source_instr->scope, source_instr->source_node);
1228513359 const_instruction->base.value->special = ConstValSpecialStatic;
1228613360 if (types_have_same_zig_comptime_repr(ira->codegen, wanted_type, payload_type)) {
......@@ -12295,40 +13369,42 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so
1229513369 if (result_loc == nullptr && handle_is_ptr(wanted_type)) {
1229613370 result_loc = no_result_loc();
1229713371 }
12298 IrInstruction *result_loc_inst = nullptr;
13372 IrInstGen *result_loc_inst = nullptr;
1229913373 if (result_loc != nullptr) {
1230013374 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true);
12301 if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) {
13375 if (type_is_invalid(result_loc_inst->value->type) ||
13376 result_loc_inst->value->type->id == ZigTypeIdUnreachable)
13377 {
1230213378 return result_loc_inst;
1230313379 }
1230413380 }
12305 IrInstruction *result = ir_build_optional_wrap(ira, source_instr, wanted_type, value, result_loc_inst);
13381 IrInstGen *result = ir_build_optional_wrap(ira, source_instr, wanted_type, value, result_loc_inst);
1230613382 result->value->data.rh_maybe = RuntimeHintOptionalNonNull;
1230713383 return result;
1230813384}
1230913385
12310static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction *source_instr,
12311 IrInstruction *value, ZigType *wanted_type, ResultLoc *result_loc)
13386static IrInstGen *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInst* source_instr,
13387 IrInstGen *value, ZigType *wanted_type, ResultLoc *result_loc)
1231213388{
1231313389 assert(wanted_type->id == ZigTypeIdErrorUnion);
1231413390
1231513391 ZigType *payload_type = wanted_type->data.error_union.payload_type;
1231613392 ZigType *err_set_type = wanted_type->data.error_union.err_set_type;
1231713393 if (instr_is_comptime(value)) {
12318 IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type);
13394 IrInstGen *casted_payload = ir_implicit_cast(ira, value, payload_type);
1231913395 if (type_is_invalid(casted_payload->value->type))
12320 return ira->codegen->invalid_instruction;
13396 return ira->codegen->invalid_inst_gen;
1232113397
1232213398 ZigValue *val = ir_resolve_const(ira, casted_payload, UndefBad);
1232313399 if (!val)
12324 return ira->codegen->invalid_instruction;
13400 return ira->codegen->invalid_inst_gen;
1232513401
1232613402 ZigValue *err_set_val = create_const_vals(1);
1232713403 err_set_val->type = err_set_type;
1232813404 err_set_val->special = ConstValSpecialStatic;
1232913405 err_set_val->data.x_err_set = nullptr;
1233013406
12331 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
13407 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
1233213408 source_instr->scope, source_instr->source_node);
1233313409 const_instruction->base.value->type = wanted_type;
1233413410 const_instruction->base.value->special = ConstValSpecialStatic;
......@@ -12337,23 +13413,24 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction
1233713413 return &const_instruction->base;
1233813414 }
1233913415
12340 IrInstruction *result_loc_inst;
13416 IrInstGen *result_loc_inst;
1234113417 if (handle_is_ptr(wanted_type)) {
1234213418 if (result_loc == nullptr) result_loc = no_result_loc();
1234313419 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true);
12344 if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) {
13420 if (type_is_invalid(result_loc_inst->value->type) ||
13421 result_loc_inst->value->type->id == ZigTypeIdUnreachable) {
1234513422 return result_loc_inst;
1234613423 }
1234713424 } else {
1234813425 result_loc_inst = nullptr;
1234913426 }
1235013427
12351 IrInstruction *result = ir_build_err_wrap_payload(ira, source_instr, wanted_type, value, result_loc_inst);
13428 IrInstGen *result = ir_build_err_wrap_payload(ira, source_instr, wanted_type, value, result_loc_inst);
1235213429 result->value->data.rh_error_union = RuntimeHintErrorUnionNonError;
1235313430 return result;
1235413431}
1235513432
12356static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
13433static IrInstGen *ir_analyze_err_set_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value,
1235713434 ZigType *wanted_type)
1235813435{
1235913436 assert(value->value->type->id == ZigTypeIdErrorSet);
......@@ -12362,10 +13439,10 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou
1236213439 if (instr_is_comptime(value)) {
1236313440 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
1236413441 if (!val)
12365 return ira->codegen->invalid_instruction;
13442 return ira->codegen->invalid_inst_gen;
1236613443
1236713444 if (!resolve_inferred_error_set(ira->codegen, wanted_type, source_instr->source_node)) {
12368 return ira->codegen->invalid_instruction;
13445 return ira->codegen->invalid_inst_gen;
1236913446 }
1237013447 if (!type_is_global_error_set(wanted_type)) {
1237113448 bool subset = false;
......@@ -12379,11 +13456,11 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou
1237913456 ir_add_error(ira, source_instr,
1238013457 buf_sprintf("error.%s not a member of error set '%s'",
1238113458 buf_ptr(&val->data.x_err_set->name), buf_ptr(&wanted_type->name)));
12382 return ira->codegen->invalid_instruction;
13459 return ira->codegen->invalid_inst_gen;
1238313460 }
1238413461 }
1238513462
12386 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
13463 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
1238713464 source_instr->scope, source_instr->source_node);
1238813465 const_instruction->base.value->type = wanted_type;
1238913466 const_instruction->base.value->special = ConstValSpecialStatic;
......@@ -12391,18 +13468,16 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou
1239113468 return &const_instruction->base;
1239213469 }
1239313470
12394 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type, value, CastOpErrSet);
12395 result->value->type = wanted_type;
12396 return result;
13471 return ir_build_cast(ira, source_instr, wanted_type, value, CastOpErrSet);
1239713472}
1239813473
12399static IrInstruction *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInstruction *source_instr,
12400 IrInstruction *frame_ptr, ZigType *wanted_type)
13474static IrInstGen *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInst* source_instr,
13475 IrInstGen *frame_ptr, ZigType *wanted_type)
1240113476{
1240213477 if (instr_is_comptime(frame_ptr)) {
1240313478 ZigValue *ptr_val = ir_resolve_const(ira, frame_ptr, UndefBad);
1240413479 if (ptr_val == nullptr)
12405 return ira->codegen->invalid_instruction;
13480 return ira->codegen->invalid_inst_gen;
1240613481
1240713482 ir_assert(ptr_val->type->id == ZigTypeIdPointer, source_instr);
1240813483 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
......@@ -12410,44 +13485,38 @@ static IrInstruction *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInstruc
1241013485 }
1241113486 }
1241213487
12413 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node,
12414 wanted_type, frame_ptr, CastOpBitCast);
12415 result->value->type = wanted_type;
12416 return result;
13488 return ir_build_cast(ira, source_instr, wanted_type, frame_ptr, CastOpBitCast);
1241713489}
1241813490
12419static IrInstruction *ir_analyze_anyframe_to_anyframe(IrAnalyze *ira, IrInstruction *source_instr,
12420 IrInstruction *value, ZigType *wanted_type)
13491static IrInstGen *ir_analyze_anyframe_to_anyframe(IrAnalyze *ira, IrInst* source_instr,
13492 IrInstGen *value, ZigType *wanted_type)
1242113493{
1242213494 if (instr_is_comptime(value)) {
1242313495 zig_panic("TODO comptime anyframe->T to anyframe");
1242413496 }
1242513497
12426 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node,
12427 wanted_type, value, CastOpBitCast);
12428 result->value->type = wanted_type;
12429 return result;
13498 return ir_build_cast(ira, source_instr, wanted_type, value, CastOpBitCast);
1243013499}
1243113500
1243213501
12433static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
13502static IrInstGen *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value,
1243413503 ZigType *wanted_type, ResultLoc *result_loc)
1243513504{
1243613505 assert(wanted_type->id == ZigTypeIdErrorUnion);
1243713506
12438 IrInstruction *casted_value = ir_implicit_cast(ira, value, wanted_type->data.error_union.err_set_type);
13507 IrInstGen *casted_value = ir_implicit_cast(ira, value, wanted_type->data.error_union.err_set_type);
1243913508
1244013509 if (instr_is_comptime(casted_value)) {
1244113510 ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad);
1244213511 if (!val)
12443 return ira->codegen->invalid_instruction;
13512 return ira->codegen->invalid_inst_gen;
1244413513
1244513514 ZigValue *err_set_val = create_const_vals(1);
1244613515 err_set_val->special = ConstValSpecialStatic;
1244713516 err_set_val->type = wanted_type->data.error_union.err_set_type;
1244813517 err_set_val->data.x_err_set = val->data.x_err_set;
1244913518
12450 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
13519 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
1245113520 source_instr->scope, source_instr->source_node);
1245213521 const_instruction->base.value->type = wanted_type;
1245313522 const_instruction->base.value->special = ConstValSpecialStatic;
......@@ -12456,11 +13525,13 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so
1245613525 return &const_instruction->base;
1245713526 }
1245813527
12459 IrInstruction *result_loc_inst;
13528 IrInstGen *result_loc_inst;
1246013529 if (handle_is_ptr(wanted_type)) {
1246113530 if (result_loc == nullptr) result_loc = no_result_loc();
1246213531 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true);
12463 if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) {
13532 if (type_is_invalid(result_loc_inst->value->type) ||
13533 result_loc_inst->value->type->id == ZigTypeIdUnreachable)
13534 {
1246413535 return result_loc_inst;
1246513536 }
1246613537 } else {
......@@ -12468,19 +13539,19 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so
1246813539 }
1246913540
1247013541
12471 IrInstruction *result = ir_build_err_wrap_code(ira, source_instr, wanted_type, value, result_loc_inst);
13542 IrInstGen *result = ir_build_err_wrap_code(ira, source_instr, wanted_type, value, result_loc_inst);
1247213543 result->value->data.rh_error_union = RuntimeHintErrorUnionError;
1247313544 return result;
1247413545}
1247513546
12476static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) {
13547static IrInstGen *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value, ZigType *wanted_type) {
1247713548 assert(wanted_type->id == ZigTypeIdOptional);
1247813549 assert(instr_is_comptime(value));
1247913550
1248013551 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
1248113552 assert(val != nullptr);
1248213553
12483 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
13554 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1248413555 result->value->special = ConstValSpecialStatic;
1248513556 if (get_codegen_ptr_type(wanted_type) != nullptr) {
1248613557 result->value->data.x_ptr.special = ConstPtrSpecialNull;
......@@ -12492,8 +13563,8 @@ static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *so
1249213563 return result;
1249313564}
1249413565
12495static IrInstruction *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInstruction *source_instr,
12496 IrInstruction *value, ZigType *wanted_type)
13566static IrInstGen *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInst *source_instr,
13567 IrInstGen *value, ZigType *wanted_type)
1249713568{
1249813569 assert(wanted_type->id == ZigTypeIdPointer);
1249913570 assert(wanted_type->data.pointer.ptr_len == PtrLenC);
......@@ -12502,24 +13573,24 @@ static IrInstruction *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInstruction
1250213573 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
1250313574 assert(val != nullptr);
1250413575
12505 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
13576 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1250613577 result->value->data.x_ptr.special = ConstPtrSpecialNull;
1250713578 result->value->data.x_ptr.mut = ConstPtrMutComptimeConst;
1250813579 return result;
1250913580}
1251013581
12511static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *value,
13582static IrInstGen *ir_get_ref(IrAnalyze *ira, IrInst* source_instruction, IrInstGen *value,
1251213583 bool is_const, bool is_volatile)
1251313584{
1251413585 Error err;
1251513586
1251613587 if (type_is_invalid(value->value->type))
12517 return ira->codegen->invalid_instruction;
13588 return ira->codegen->invalid_inst_gen;
1251813589
1251913590 if (instr_is_comptime(value)) {
1252013591 ZigValue *val = ir_resolve_const(ira, value, LazyOk);
1252113592 if (!val)
12522 return ira->codegen->invalid_instruction;
13593 return ira->codegen->invalid_inst_gen;
1252313594 return ir_get_const_ptr(ira, source_instruction, val, value->value->type,
1252413595 ConstPtrMutComptimeConst, is_const, is_volatile, 0);
1252513596 }
......@@ -12528,9 +13599,9 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi
1252813599 is_const, is_volatile, PtrLenSingle, 0, 0, 0, false);
1252913600
1253013601 if ((err = type_resolve(ira->codegen, ptr_type, ResolveStatusZeroBitsKnown)))
12531 return ira->codegen->invalid_instruction;
13602 return ira->codegen->invalid_inst_gen;
1253213603
12533 IrInstruction *result_loc;
13604 IrInstGen *result_loc;
1253413605 if (type_has_bits(ptr_type) && !handle_is_ptr(value->value->type)) {
1253513606 result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), value->value->type, nullptr, true,
1253613607 false, true);
......@@ -12538,12 +13609,12 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi
1253813609 result_loc = nullptr;
1253913610 }
1254013611
12541 IrInstruction *new_instruction = ir_build_ref_gen(ira, source_instruction, ptr_type, value, result_loc);
13612 IrInstGen *new_instruction = ir_build_ref_gen(ira, source_instruction, ptr_type, value, result_loc);
1254213613 new_instruction->value->data.rh_ptr = RuntimeHintPtrStack;
1254313614 return new_instruction;
1254413615}
1254513616
12546static ZigType *ir_resolve_union_tag_type(IrAnalyze *ira, IrInstruction *source_instr, ZigType *union_type) {
13617static ZigType *ir_resolve_union_tag_type(IrAnalyze *ira, AstNode *source_node, ZigType *union_type) {
1254713618 assert(union_type->id == ZigTypeIdUnion);
1254813619
1254913620 Error err;
......@@ -12555,36 +13626,36 @@ static ZigType *ir_resolve_union_tag_type(IrAnalyze *ira, IrInstruction *source_
1255513626 assert(union_type->data.unionation.tag_type != nullptr);
1255613627 return union_type->data.unionation.tag_type;
1255713628 } else {
12558 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("union '%s' has no tag",
13629 ErrorMsg *msg = ir_add_error_node(ira, source_node, buf_sprintf("union '%s' has no tag",
1255913630 buf_ptr(&union_type->name)));
1256013631 add_error_note(ira->codegen, msg, decl_node, buf_sprintf("consider 'union(enum)' here"));
1256113632 return ira->codegen->builtin_types.entry_invalid;
1256213633 }
1256313634}
1256413635
12565static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target) {
13636static IrInstGen *ir_analyze_enum_to_int(IrAnalyze *ira, IrInst *source_instr, IrInstGen *target) {
1256613637 Error err;
1256713638
12568 IrInstruction *enum_target;
13639 IrInstGen *enum_target;
1256913640 ZigType *enum_type;
1257013641 if (target->value->type->id == ZigTypeIdUnion) {
12571 enum_type = ir_resolve_union_tag_type(ira, target, target->value->type);
13642 enum_type = ir_resolve_union_tag_type(ira, target->base.source_node, target->value->type);
1257213643 if (type_is_invalid(enum_type))
12573 return ira->codegen->invalid_instruction;
13644 return ira->codegen->invalid_inst_gen;
1257413645 enum_target = ir_implicit_cast(ira, target, enum_type);
1257513646 if (type_is_invalid(enum_target->value->type))
12576 return ira->codegen->invalid_instruction;
13647 return ira->codegen->invalid_inst_gen;
1257713648 } else if (target->value->type->id == ZigTypeIdEnum) {
1257813649 enum_target = target;
1257913650 enum_type = target->value->type;
1258013651 } else {
12581 ir_add_error(ira, target,
13652 ir_add_error_node(ira, target->base.source_node,
1258213653 buf_sprintf("expected enum, found type '%s'", buf_ptr(&target->value->type->name)));
12583 return ira->codegen->invalid_instruction;
13654 return ira->codegen->invalid_inst_gen;
1258413655 }
1258513656
1258613657 if ((err = type_resolve(ira->codegen, enum_type, ResolveStatusSizeKnown)))
12587 return ira->codegen->invalid_instruction;
13658 return ira->codegen->invalid_inst_gen;
1258813659
1258913660 ZigType *tag_type = enum_type->data.enumeration.tag_int_type;
1259013661 assert(tag_type->id == ZigTypeIdInt || tag_type->id == ZigTypeIdComptimeInt);
......@@ -12593,7 +13664,7 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour
1259313664 if (enum_type->data.enumeration.layout == ContainerLayoutAuto &&
1259413665 enum_type->data.enumeration.src_field_count == 1)
1259513666 {
12596 IrInstruction *result = ir_const(ira, source_instr, tag_type);
13667 IrInstGen *result = ir_const(ira, source_instr, tag_type);
1259713668 init_const_bigint(result->value, tag_type,
1259813669 &enum_type->data.enumeration.fields[0].value);
1259913670 return result;
......@@ -12602,20 +13673,17 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour
1260213673 if (instr_is_comptime(enum_target)) {
1260313674 ZigValue *val = ir_resolve_const(ira, enum_target, UndefBad);
1260413675 if (!val)
12605 return ira->codegen->invalid_instruction;
12606 IrInstruction *result = ir_const(ira, source_instr, tag_type);
13676 return ira->codegen->invalid_inst_gen;
13677 IrInstGen *result = ir_const(ira, source_instr, tag_type);
1260713678 init_const_bigint(result->value, tag_type, &val->data.x_enum_tag);
1260813679 return result;
1260913680 }
1261013681
12611 IrInstruction *result = ir_build_widen_or_shorten(&ira->new_irb, source_instr->scope,
12612 source_instr->source_node, enum_target);
12613 result->value->type = tag_type;
12614 return result;
13682 return ir_build_widen_or_shorten(ira, source_instr->scope, source_instr->source_node, enum_target, tag_type);
1261513683}
1261613684
12617static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *source_instr,
12618 IrInstruction *target, ZigType *wanted_type)
13685static IrInstGen *ir_analyze_union_to_tag(IrAnalyze *ira, IrInst* source_instr,
13686 IrInstGen *target, ZigType *wanted_type)
1261913687{
1262013688 assert(target->value->type->id == ZigTypeIdUnion);
1262113689 assert(wanted_type->id == ZigTypeIdEnum);
......@@ -12624,8 +13692,8 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou
1262413692 if (instr_is_comptime(target)) {
1262513693 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
1262613694 if (!val)
12627 return ira->codegen->invalid_instruction;
12628 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
13695 return ira->codegen->invalid_inst_gen;
13696 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1262913697 result->value->special = ConstValSpecialStatic;
1263013698 result->value->type = wanted_type;
1263113699 bigint_init_bigint(&result->value->data.x_enum_tag, &val->data.x_union.tag);
......@@ -12636,7 +13704,7 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou
1263613704 if (wanted_type->data.enumeration.layout == ContainerLayoutAuto &&
1263713705 wanted_type->data.enumeration.src_field_count == 1)
1263813706 {
12639 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
13707 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1264013708 result->value->special = ConstValSpecialStatic;
1264113709 result->value->type = wanted_type;
1264213710 TypeEnumField *enum_field = target->value->type->data.unionation.fields[0].enum_field;
......@@ -12644,48 +13712,45 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou
1264413712 return result;
1264513713 }
1264613714
12647 IrInstruction *result = ir_build_union_tag(&ira->new_irb, source_instr->scope,
12648 source_instr->source_node, target);
12649 result->value->type = wanted_type;
12650 return result;
13715 return ir_build_union_tag(ira, source_instr, target, wanted_type);
1265113716}
1265213717
12653static IrInstruction *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInstruction *source_instr,
12654 IrInstruction *target, ZigType *wanted_type)
13718static IrInstGen *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInst* source_instr,
13719 IrInstGen *target, ZigType *wanted_type)
1265513720{
12656 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
13721 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1265713722 result->value->special = ConstValSpecialUndef;
1265813723 return result;
1265913724}
1266013725
12661static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *source_instr,
12662 IrInstruction *uncasted_target, ZigType *wanted_type)
13726static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr,
13727 IrInstGen *uncasted_target, ZigType *wanted_type)
1266313728{
1266413729 Error err;
1266513730 assert(wanted_type->id == ZigTypeIdUnion);
1266613731
1266713732 if ((err = type_resolve(ira->codegen, wanted_type, ResolveStatusZeroBitsKnown)))
12668 return ira->codegen->invalid_instruction;
13733 return ira->codegen->invalid_inst_gen;
1266913734
12670 IrInstruction *target = ir_implicit_cast(ira, uncasted_target, wanted_type->data.unionation.tag_type);
13735 IrInstGen *target = ir_implicit_cast(ira, uncasted_target, wanted_type->data.unionation.tag_type);
1267113736 if (type_is_invalid(target->value->type))
12672 return ira->codegen->invalid_instruction;
13737 return ira->codegen->invalid_inst_gen;
1267313738
1267413739 if (instr_is_comptime(target)) {
1267513740 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
1267613741 if (!val)
12677 return ira->codegen->invalid_instruction;
13742 return ira->codegen->invalid_inst_gen;
1267813743 TypeUnionField *union_field = find_union_field_by_tag(wanted_type, &val->data.x_enum_tag);
1267913744 assert(union_field != nullptr);
1268013745 ZigType *field_type = resolve_union_field_type(ira->codegen, union_field);
1268113746 if (field_type == nullptr)
12682 return ira->codegen->invalid_instruction;
13747 return ira->codegen->invalid_inst_gen;
1268313748 if ((err = type_resolve(ira->codegen, field_type, ResolveStatusZeroBitsKnown)))
12684 return ira->codegen->invalid_instruction;
13749 return ira->codegen->invalid_inst_gen;
1268513750
1268613751 switch (type_has_one_possible_value(ira->codegen, field_type)) {
1268713752 case OnePossibleValueInvalid:
12688 return ira->codegen->invalid_instruction;
13753 return ira->codegen->invalid_inst_gen;
1268913754 case OnePossibleValueNo: {
1269013755 AstNode *field_node = wanted_type->data.unionation.decl_node->data.container_decl.fields.at(
1269113756 union_field->enum_field->decl_index);
......@@ -12696,13 +13761,13 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so
1269613761 buf_ptr(union_field->name)));
1269713762 add_error_note(ira->codegen, msg, field_node,
1269813763 buf_sprintf("field '%s' declared here", buf_ptr(union_field->name)));
12699 return ira->codegen->invalid_instruction;
13764 return ira->codegen->invalid_inst_gen;
1270013765 }
1270113766 case OnePossibleValueYes:
1270213767 break;
1270313768 }
1270413769
12705 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
13770 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1270613771 result->value->special = ConstValSpecialStatic;
1270713772 result->value->type = wanted_type;
1270813773 bigint_init_bigint(&result->value->data.x_union.tag, &val->data.x_enum_tag);
......@@ -12715,9 +13780,7 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so
1271513780 // if the union has all fields 0 bits, we can do it
1271613781 // and in fact it's a noop cast because the union value is just the enum value
1271713782 if (wanted_type->data.unionation.gen_field_count == 0) {
12718 IrInstruction *result = ir_build_cast(&ira->new_irb, target->scope, target->source_node, wanted_type, target, CastOpNoop);
12719 result->value->type = wanted_type;
12720 return result;
13783 return ir_build_cast(ira, &target->base, wanted_type, target, CastOpNoop);
1272113784 }
1272213785
1272313786 ErrorMsg *msg = ir_add_error(ira, source_instr,
......@@ -12727,10 +13790,10 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so
1272713790 TypeUnionField *union_field = &wanted_type->data.unionation.fields[i];
1272813791 ZigType *field_type = resolve_union_field_type(ira->codegen, union_field);
1272913792 if (field_type == nullptr)
12730 return ira->codegen->invalid_instruction;
13793 return ira->codegen->invalid_inst_gen;
1273113794 bool has_bits;
1273213795 if ((err = type_has_bits2(ira->codegen, field_type, &has_bits)))
12733 return ira->codegen->invalid_instruction;
13796 return ira->codegen->invalid_inst_gen;
1273413797 if (has_bits) {
1273513798 AstNode *field_node = wanted_type->data.unionation.decl_node->data.container_decl.fields.at(i);
1273613799 add_error_note(ira->codegen, msg, field_node,
......@@ -12739,23 +13802,23 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so
1273913802 buf_ptr(&field_type->name)));
1274013803 }
1274113804 }
12742 return ira->codegen->invalid_instruction;
13805 return ira->codegen->invalid_inst_gen;
1274313806}
1274413807
12745static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction *source_instr,
12746 IrInstruction *target, ZigType *wanted_type)
13808static IrInstGen *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInst* source_instr,
13809 IrInstGen *target, ZigType *wanted_type)
1274713810{
1274813811 assert(wanted_type->id == ZigTypeIdInt || wanted_type->id == ZigTypeIdFloat);
1274913812
1275013813 if (instr_is_comptime(target)) {
1275113814 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
1275213815 if (!val)
12753 return ira->codegen->invalid_instruction;
13816 return ira->codegen->invalid_inst_gen;
1275413817 if (wanted_type->id == ZigTypeIdInt) {
1275513818 if (bigint_cmp_zero(&val->data.x_bigint) == CmpLT && !wanted_type->data.integral.is_signed) {
1275613819 ir_add_error(ira, source_instr,
1275713820 buf_sprintf("attempt to cast negative value to unsigned integer"));
12758 return ira->codegen->invalid_instruction;
13821 return ira->codegen->invalid_inst_gen;
1275913822 }
1276013823 if (!bigint_fits_in_bits(&val->data.x_bigint, wanted_type->data.integral.bit_count,
1276113824 wanted_type->data.integral.is_signed))
......@@ -12763,10 +13826,10 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction
1276313826 ir_add_error(ira, source_instr,
1276413827 buf_sprintf("cast from '%s' to '%s' truncates bits",
1276513828 buf_ptr(&target->value->type->name), buf_ptr(&wanted_type->name)));
12766 return ira->codegen->invalid_instruction;
13829 return ira->codegen->invalid_inst_gen;
1276713830 }
1276813831 }
12769 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
13832 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1277013833 result->value->type = wanted_type;
1277113834 if (wanted_type->id == ZigTypeIdInt) {
1277213835 bigint_init_bigint(&result->value->data.x_bigint, &val->data.x_bigint);
......@@ -12783,19 +13846,16 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction
1278313846 assert(wanted_type->id == ZigTypeIdInt);
1278413847 assert(type_has_bits(target->value->type));
1278513848 ir_build_assert_zero(ira, source_instr, target);
12786 IrInstruction *result = ir_const_unsigned(ira, source_instr, 0);
13849 IrInstGen *result = ir_const_unsigned(ira, source_instr, 0);
1278713850 result->value->type = wanted_type;
1278813851 return result;
1278913852 }
1279013853
12791 IrInstruction *result = ir_build_widen_or_shorten(&ira->new_irb, source_instr->scope,
12792 source_instr->source_node, target);
12793 result->value->type = wanted_type;
12794 return result;
13854 return ir_build_widen_or_shorten(ira, source_instr->scope, source_instr->source_node, target, wanted_type);
1279513855}
1279613856
12797static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *source_instr,
12798 IrInstruction *target, ZigType *wanted_type)
13857static IrInstGen *ir_analyze_int_to_enum(IrAnalyze *ira, IrInst* source_instr,
13858 IrInstGen *target, ZigType *wanted_type)
1279913859{
1280013860 Error err;
1280113861 assert(wanted_type->id == ZigTypeIdEnum);
......@@ -12803,14 +13863,14 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour
1280313863 ZigType *actual_type = target->value->type;
1280413864
1280513865 if ((err = type_resolve(ira->codegen, wanted_type, ResolveStatusSizeKnown)))
12806 return ira->codegen->invalid_instruction;
13866 return ira->codegen->invalid_inst_gen;
1280713867
1280813868 if (actual_type != wanted_type->data.enumeration.tag_int_type) {
1280913869 ir_add_error(ira, source_instr,
1281013870 buf_sprintf("integer to enum cast from '%s' instead of its tag type, '%s'",
1281113871 buf_ptr(&actual_type->name),
1281213872 buf_ptr(&wanted_type->data.enumeration.tag_int_type->name)));
12813 return ira->codegen->invalid_instruction;
13873 return ira->codegen->invalid_inst_gen;
1281413874 }
1281513875
1281613876 assert(actual_type->id == ZigTypeIdInt || actual_type->id == ZigTypeIdComptimeInt);
......@@ -12818,7 +13878,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour
1281813878 if (instr_is_comptime(target)) {
1281913879 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
1282013880 if (!val)
12821 return ira->codegen->invalid_instruction;
13881 return ira->codegen->invalid_inst_gen;
1282213882
1282313883 TypeEnumField *field = find_enum_field_by_tag(wanted_type, &val->data.x_bigint);
1282413884 if (field == nullptr && !wanted_type->data.enumeration.non_exhaustive) {
......@@ -12829,28 +13889,25 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour
1282913889 buf_ptr(&wanted_type->name), buf_ptr(val_buf)));
1283013890 add_error_note(ira->codegen, msg, wanted_type->data.enumeration.decl_node,
1283113891 buf_sprintf("'%s' declared here", buf_ptr(&wanted_type->name)));
12832 return ira->codegen->invalid_instruction;
13892 return ira->codegen->invalid_inst_gen;
1283313893 }
1283413894
12835 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
13895 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1283613896 bigint_init_bigint(&result->value->data.x_enum_tag, &val->data.x_bigint);
1283713897 return result;
1283813898 }
1283913899
12840 IrInstruction *result = ir_build_int_to_enum(&ira->new_irb, source_instr->scope,
12841 source_instr->source_node, nullptr, target);
12842 result->value->type = wanted_type;
12843 return result;
13900 return ir_build_int_to_enum_gen(ira, source_instr->scope, source_instr->source_node, wanted_type, target);
1284413901}
1284513902
12846static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction *source_instr,
12847 IrInstruction *target, ZigType *wanted_type)
13903static IrInstGen *ir_analyze_number_to_literal(IrAnalyze *ira, IrInst* source_instr,
13904 IrInstGen *target, ZigType *wanted_type)
1284813905{
1284913906 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
1285013907 if (!val)
12851 return ira->codegen->invalid_instruction;
13908 return ira->codegen->invalid_inst_gen;
1285213909
12853 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
13910 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1285413911 if (wanted_type->id == ZigTypeIdComptimeFloat) {
1285513912 float_init_float(result->value, val);
1285613913 } else if (wanted_type->id == ZigTypeIdComptimeInt) {
......@@ -12861,7 +13918,7 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction
1286113918 return result;
1286213919}
1286313920
12864static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
13921static IrInstGen *ir_analyze_int_to_err(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target,
1286513922 ZigType *wanted_type)
1286613923{
1286713924 assert(target->value->type->id == ZigTypeIdInt);
......@@ -12871,12 +13928,12 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc
1287113928 if (instr_is_comptime(target)) {
1287213929 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
1287313930 if (!val)
12874 return ira->codegen->invalid_instruction;
13931 return ira->codegen->invalid_inst_gen;
1287513932
12876 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
13933 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1287713934
1287813935 if (!resolve_inferred_error_set(ira->codegen, wanted_type, source_instr->source_node)) {
12879 return ira->codegen->invalid_instruction;
13936 return ira->codegen->invalid_inst_gen;
1288013937 }
1288113938
1288213939 if (type_is_global_error_set(wanted_type)) {
......@@ -12888,7 +13945,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc
1288813945 bigint_append_buf(val_buf, &val->data.x_bigint, 10);
1288913946 ir_add_error(ira, source_instr,
1289013947 buf_sprintf("integer value %s represents no error", buf_ptr(val_buf)));
12891 return ira->codegen->invalid_instruction;
13948 return ira->codegen->invalid_inst_gen;
1289213949 }
1289313950
1289413951 size_t index = bigint_as_usize(&val->data.x_bigint);
......@@ -12912,7 +13969,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc
1291213969 bigint_append_buf(val_buf, &val->data.x_bigint, 10);
1291313970 ir_add_error(ira, source_instr,
1291413971 buf_sprintf("integer value %s represents no error in '%s'", buf_ptr(val_buf), buf_ptr(&wanted_type->name)));
12915 return ira->codegen->invalid_instruction;
13972 return ira->codegen->invalid_inst_gen;
1291613973 }
1291713974
1291813975 result->value->data.x_err_set = err;
......@@ -12920,12 +13977,10 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc
1292013977 }
1292113978 }
1292213979
12923 IrInstruction *result = ir_build_int_to_err(&ira->new_irb, source_instr->scope, source_instr->source_node, target);
12924 result->value->type = wanted_type;
12925 return result;
13980 return ir_build_int_to_err_gen(ira, source_instr->scope, source_instr->source_node, target, wanted_type);
1292613981}
1292713982
12928static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
13983static IrInstGen *ir_analyze_err_to_int(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target,
1292913984 ZigType *wanted_type)
1293013985{
1293113986 assert(wanted_type->id == ZigTypeIdInt);
......@@ -12935,9 +13990,9 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
1293513990 if (instr_is_comptime(target)) {
1293613991 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
1293713992 if (!val)
12938 return ira->codegen->invalid_instruction;
13993 return ira->codegen->invalid_inst_gen;
1293913994
12940 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
13995 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1294113996
1294213997 ErrorTableEntry *err;
1294313998 if (err_type->id == ZigTypeIdErrorUnion) {
......@@ -12957,7 +14012,7 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
1295714012 ir_add_error_node(ira, source_instr->source_node,
1295814013 buf_sprintf("error code '%s' does not fit in '%s'",
1295914014 buf_ptr(&err->name), buf_ptr(&wanted_type->name)));
12960 return ira->codegen->invalid_instruction;
14015 return ira->codegen->invalid_inst_gen;
1296114016 }
1296214017
1296314018 return result;
......@@ -12973,14 +14028,14 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
1297314028 }
1297414029 if (!type_is_global_error_set(err_set_type)) {
1297514030 if (!resolve_inferred_error_set(ira->codegen, err_set_type, source_instr->source_node)) {
12976 return ira->codegen->invalid_instruction;
14031 return ira->codegen->invalid_inst_gen;
1297714032 }
1297814033 if (err_set_type->data.error_set.err_count == 0) {
12979 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
14034 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1298014035 bigint_init_unsigned(&result->value->data.x_bigint, 0);
1298114036 return result;
1298214037 } else if (err_set_type->data.error_set.err_count == 1) {
12983 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
14038 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1298414039 ErrorTableEntry *err = err_set_type->data.error_set.errors[0];
1298514040 bigint_init_unsigned(&result->value->data.x_bigint, err->value);
1298614041 return result;
......@@ -12992,21 +14047,19 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
1299214047 if (!bigint_fits_in_bits(&bn, wanted_type->data.integral.bit_count, wanted_type->data.integral.is_signed)) {
1299314048 ir_add_error_node(ira, source_instr->source_node,
1299414049 buf_sprintf("too many error values to fit in '%s'", buf_ptr(&wanted_type->name)));
12995 return ira->codegen->invalid_instruction;
14050 return ira->codegen->invalid_inst_gen;
1299614051 }
1299714052
12998 IrInstruction *result = ir_build_err_to_int(&ira->new_irb, source_instr->scope, source_instr->source_node, target);
12999 result->value->type = wanted_type;
13000 return result;
14053 return ir_build_err_to_int_gen(ira, source_instr->scope, source_instr->source_node, target, wanted_type);
1300114054}
1300214055
13003static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
14056static IrInstGen *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target,
1300414057 ZigType *wanted_type)
1300514058{
1300614059 assert(wanted_type->id == ZigTypeIdPointer);
1300714060 Error err;
1300814061 if ((err = type_resolve(ira->codegen, target->value->type->data.pointer.child_type, ResolveStatusAlignmentKnown)))
13009 return ira->codegen->invalid_instruction;
14062 return ira->codegen->invalid_inst_gen;
1301014063 assert((wanted_type->data.pointer.is_const && target->value->type->data.pointer.is_const) || !target->value->type->data.pointer.is_const);
1301114064 wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, target->value->type));
1301214065 ZigType *array_type = wanted_type->data.pointer.child_type;
......@@ -13016,12 +14069,12 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou
1301614069 if (instr_is_comptime(target)) {
1301714070 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
1301814071 if (!val)
13019 return ira->codegen->invalid_instruction;
14072 return ira->codegen->invalid_inst_gen;
1302014073
1302114074 assert(val->type->id == ZigTypeIdPointer);
1302214075 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node);
1302314076 if (pointee == nullptr)
13024 return ira->codegen->invalid_instruction;
14077 return ira->codegen->invalid_inst_gen;
1302514078 if (pointee->special != ConstValSpecialRuntime) {
1302614079 ZigValue *array_val = create_const_vals(1);
1302714080 array_val->special = ConstValSpecialStatic;
......@@ -13031,7 +14084,7 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou
1303114084 array_val->parent.id = ConstParentIdScalar;
1303214085 array_val->parent.data.p_scalar.scalar_val = pointee;
1303314086
13034 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
14087 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
1303514088 source_instr->scope, source_instr->source_node);
1303614089 const_instruction->base.value->type = wanted_type;
1303714090 const_instruction->base.value->special = ConstValSpecialStatic;
......@@ -13043,10 +14096,7 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou
1304314096 }
1304414097
1304514098 // pointer to array and pointer to single item are represented the same way at runtime
13046 IrInstruction *result = ir_build_cast(&ira->new_irb, target->scope, target->source_node,
13047 wanted_type, target, CastOpBitCast);
13048 result->value->type = wanted_type;
13049 return result;
14099 return ir_build_cast(ira, &target->base, wanted_type, target, CastOpBitCast);
1305014100}
1305114101
1305214102static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCastOnly *cast_result,
......@@ -13234,12 +14284,12 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa
1323414284 }
1323514285}
1323614286
13237static IrInstruction *ir_analyze_array_to_vector(IrAnalyze *ira, IrInstruction *source_instr,
13238 IrInstruction *array, ZigType *vector_type)
14287static IrInstGen *ir_analyze_array_to_vector(IrAnalyze *ira, IrInst* source_instr,
14288 IrInstGen *array, ZigType *vector_type)
1323914289{
1324014290 if (instr_is_comptime(array)) {
1324114291 // arrays and vectors have the same ZigValue representation
13242 IrInstruction *result = ir_const(ira, source_instr, vector_type);
14292 IrInstGen *result = ir_const(ira, source_instr, vector_type);
1324314293 copy_const_val(result->value, array->value);
1324414294 result->value->type = vector_type;
1324514295 return result;
......@@ -13247,12 +14297,12 @@ static IrInstruction *ir_analyze_array_to_vector(IrAnalyze *ira, IrInstruction *
1324714297 return ir_build_array_to_vector(ira, source_instr, array, vector_type);
1324814298}
1324914299
13250static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction *source_instr,
13251 IrInstruction *vector, ZigType *array_type, ResultLoc *result_loc)
14300static IrInstGen *ir_analyze_vector_to_array(IrAnalyze *ira, IrInst* source_instr,
14301 IrInstGen *vector, ZigType *array_type, ResultLoc *result_loc)
1325214302{
1325314303 if (instr_is_comptime(vector)) {
1325414304 // arrays and vectors have the same ZigValue representation
13255 IrInstruction *result = ir_const(ira, source_instr, array_type);
14305 IrInstGen *result = ir_const(ira, source_instr, array_type);
1325614306 copy_const_val(result->value, vector->value);
1325714307 result->value->type = array_type;
1325814308 return result;
......@@ -13260,18 +14310,18 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction *
1326014310 if (result_loc == nullptr) {
1326114311 result_loc = no_result_loc();
1326214312 }
13263 IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, array_type, nullptr,
14313 IrInstGen *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, array_type, nullptr,
1326414314 true, false, true);
13265 if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) {
14315 if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) {
1326614316 return result_loc_inst;
1326714317 }
1326814318 return ir_build_vector_to_array(ira, source_instr, array_type, vector, result_loc_inst);
1326914319}
1327014320
13271static IrInstruction *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInstruction *source_instr,
13272 IrInstruction *integer, ZigType *dest_type)
14321static IrInstGen *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInst* source_instr,
14322 IrInstGen *integer, ZigType *dest_type)
1327314323{
13274 IrInstruction *unsigned_integer;
14324 IrInstGen *unsigned_integer;
1327514325 if (instr_is_comptime(integer)) {
1327614326 unsigned_integer = integer;
1327714327 } else {
......@@ -13284,7 +14334,7 @@ static IrInstruction *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInstruction *sou
1328414334 buf_sprintf("integer type '%s' too big for implicit @intToPtr to type '%s'",
1328514335 buf_ptr(&integer->value->type->name),
1328614336 buf_ptr(&dest_type->name)));
13287 return ira->codegen->invalid_instruction;
14337 return ira->codegen->invalid_inst_gen;
1328814338 }
1328914339
1329014340 if (integer->value->type->data.integral.is_signed) {
......@@ -13292,7 +14342,7 @@ static IrInstruction *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInstruction *sou
1329214342 integer->value->type->data.integral.bit_count);
1329314343 unsigned_integer = ir_analyze_bit_cast(ira, source_instr, integer, unsigned_int_type);
1329414344 if (type_is_invalid(unsigned_integer->value->type))
13295 return ira->codegen->invalid_instruction;
14345 return ira->codegen->invalid_inst_gen;
1329614346 } else {
1329714347 unsigned_integer = integer;
1329814348 }
......@@ -13312,14 +14362,14 @@ static bool is_pointery_and_elem_is_not_pointery(ZigType *ty) {
1331214362 return false;
1331314363}
1331414364
13315static IrInstruction *ir_analyze_enum_literal(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
14365static IrInstGen *ir_analyze_enum_literal(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value,
1331614366 ZigType *enum_type)
1331714367{
1331814368 assert(enum_type->id == ZigTypeIdEnum);
1331914369
1332014370 Error err;
1332114371 if ((err = type_resolve(ira->codegen, enum_type, ResolveStatusZeroBitsKnown)))
13322 return ira->codegen->invalid_instruction;
14372 return ira->codegen->invalid_inst_gen;
1332314373
1332414374 TypeEnumField *field = find_enum_type_field(enum_type, value->value->data.x_enum_literal);
1332514375 if (field == nullptr) {
......@@ -13327,40 +14377,40 @@ static IrInstruction *ir_analyze_enum_literal(IrAnalyze *ira, IrInstruction *sou
1332714377 buf_ptr(&enum_type->name), buf_ptr(value->value->data.x_enum_literal)));
1332814378 add_error_note(ira->codegen, msg, enum_type->data.enumeration.decl_node,
1332914379 buf_sprintf("'%s' declared here", buf_ptr(&enum_type->name)));
13330 return ira->codegen->invalid_instruction;
14380 return ira->codegen->invalid_inst_gen;
1333114381 }
13332 IrInstruction *result = ir_const(ira, source_instr, enum_type);
14382 IrInstGen *result = ir_const(ira, source_instr, enum_type);
1333314383 bigint_init_bigint(&result->value->data.x_enum_tag, &field->value);
1333414384
1333514385 return result;
1333614386}
1333714387
13338static IrInstruction *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInstruction *source_instr,
13339 IrInstruction *value, ZigType *wanted_type)
14388static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInst* source_instr,
14389 IrInstGen *value, ZigType *wanted_type)
1334014390{
1334114391 ir_add_error(ira, source_instr, buf_sprintf("TODO: type coercion of anon list literal to array"));
13342 return ira->codegen->invalid_instruction;
14392 return ira->codegen->invalid_inst_gen;
1334314393}
1334414394
13345static IrInstruction *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInstruction *source_instr,
13346 IrInstruction *value, ZigType *wanted_type)
14395static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* source_instr,
14396 IrInstGen *value, ZigType *wanted_type)
1334714397{
1334814398 ir_add_error(ira, source_instr, buf_sprintf("TODO: type coercion of anon struct literal to struct"));
13349 return ira->codegen->invalid_instruction;
14399 return ira->codegen->invalid_inst_gen;
1335014400}
1335114401
13352static IrInstruction *ir_analyze_struct_literal_to_union(IrAnalyze *ira, IrInstruction *source_instr,
13353 IrInstruction *value, ZigType *wanted_type)
14402static IrInstGen *ir_analyze_struct_literal_to_union(IrAnalyze *ira, IrInst* source_instr,
14403 IrInstGen *value, ZigType *wanted_type)
1335414404{
1335514405 ir_add_error(ira, source_instr, buf_sprintf("TODO: type coercion of anon struct literal to union"));
13356 return ira->codegen->invalid_instruction;
14406 return ira->codegen->invalid_inst_gen;
1335714407}
1335814408
1335914409// Add a compile error and return ErrorSemanticAnalyzeFail if the pointer alignment does not work,
1336014410// otherwise return ErrorNone. Does not emit any instructions.
1336114411// Assumes that the pointer types have element types with the same ABI alignment. Avoids resolving the
1336214412// pointer types' alignments if both of the pointer types are ABI aligned.
13363static Error ir_cast_ptr_align(IrAnalyze *ira, IrInstruction *source_instr, ZigType *dest_ptr_type,
14413static Error ir_cast_ptr_align(IrAnalyze *ira, IrInst* source_instr, ZigType *dest_ptr_type,
1336414414 ZigType *src_ptr_type, AstNode *src_source_node)
1336514415{
1336614416 Error err;
......@@ -13394,37 +14444,37 @@ static Error ir_cast_ptr_align(IrAnalyze *ira, IrInstruction *source_instr, ZigT
1339414444 return ErrorNone;
1339514445}
1339614446
13397static IrInstruction *ir_analyze_struct_value_field_value(IrAnalyze *ira, IrInstruction *source_instr,
13398 IrInstruction *struct_operand, TypeStructField *field)
14447static IrInstGen *ir_analyze_struct_value_field_value(IrAnalyze *ira, IrInst* source_instr,
14448 IrInstGen *struct_operand, TypeStructField *field)
1339914449{
13400 IrInstruction *struct_ptr = ir_get_ref(ira, source_instr, struct_operand, true, false);
14450 IrInstGen *struct_ptr = ir_get_ref(ira, source_instr, struct_operand, true, false);
1340114451 if (type_is_invalid(struct_ptr->value->type))
13402 return ira->codegen->invalid_instruction;
13403 IrInstruction *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, struct_ptr,
14452 return ira->codegen->invalid_inst_gen;
14453 IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, struct_ptr,
1340414454 struct_operand->value->type, false);
1340514455 if (type_is_invalid(field_ptr->value->type))
13406 return ira->codegen->invalid_instruction;
14456 return ira->codegen->invalid_inst_gen;
1340714457 return ir_get_deref(ira, source_instr, field_ptr, nullptr);
1340814458}
1340914459
13410static IrInstruction *ir_analyze_optional_value_payload_value(IrAnalyze *ira, IrInstruction *source_instr,
13411 IrInstruction *optional_operand, bool safety_check_on)
14460static IrInstGen *ir_analyze_optional_value_payload_value(IrAnalyze *ira, IrInst* source_instr,
14461 IrInstGen *optional_operand, bool safety_check_on)
1341214462{
13413 IrInstruction *opt_ptr = ir_get_ref(ira, source_instr, optional_operand, true, false);
13414 IrInstruction *payload_ptr = ir_analyze_unwrap_optional_payload(ira, source_instr, opt_ptr,
14463 IrInstGen *opt_ptr = ir_get_ref(ira, source_instr, optional_operand, true, false);
14464 IrInstGen *payload_ptr = ir_analyze_unwrap_optional_payload(ira, source_instr, opt_ptr,
1341514465 safety_check_on, false);
1341614466 return ir_get_deref(ira, source_instr, payload_ptr, nullptr);
1341714467}
1341814468
13419static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_instr,
13420 ZigType *wanted_type, IrInstruction *value)
14469static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
14470 ZigType *wanted_type, IrInstGen *value)
1342114471{
1342214472 Error err;
1342314473 ZigType *actual_type = value->value->type;
1342414474 AstNode *source_node = source_instr->source_node;
1342514475
1342614476 if (type_is_invalid(wanted_type) || type_is_invalid(actual_type)) {
13427 return ira->codegen->invalid_instruction;
14477 return ira->codegen->invalid_inst_gen;
1342814478 }
1342914479
1343014480 // This means the wanted type is anything.
......@@ -13436,7 +14486,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1343614486 ConstCastOnly const_cast_result = types_match_const_cast_only(ira, wanted_type, actual_type,
1343714487 source_node, false);
1343814488 if (const_cast_result.id == ConstCastResultIdInvalid)
13439 return ira->codegen->invalid_instruction;
14489 return ira->codegen->invalid_inst_gen;
1344014490 if (const_cast_result.id == ConstCastResultIdOk) {
1344114491 return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpNoop);
1344214492 }
......@@ -13470,7 +14520,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1347014520 if (ir_num_lit_fits_in_other_type(ira, value, wanted_child_type, true)) {
1347114521 return ir_analyze_optional_wrap(ira, source_instr, value, wanted_type, nullptr);
1347214522 } else {
13473 return ira->codegen->invalid_instruction;
14523 return ira->codegen->invalid_inst_gen;
1347414524 }
1347514525 } else if (
1347614526 wanted_child_type->id == ZigTypeIdPointer &&
......@@ -13480,18 +14530,18 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1348014530 actual_type->data.pointer.child_type->id == ZigTypeIdArray)
1348114531 {
1348214532 if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type, ResolveStatusAlignmentKnown)))
13483 return ira->codegen->invalid_instruction;
14533 return ira->codegen->invalid_inst_gen;
1348414534 if ((err = type_resolve(ira->codegen, wanted_child_type->data.pointer.child_type, ResolveStatusAlignmentKnown)))
13485 return ira->codegen->invalid_instruction;
14535 return ira->codegen->invalid_inst_gen;
1348614536 if (get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, wanted_child_type) &&
1348714537 types_match_const_cast_only(ira, wanted_child_type->data.pointer.child_type,
1348814538 actual_type->data.pointer.child_type->data.array.child_type, source_node,
1348914539 !wanted_child_type->data.pointer.is_const).id == ConstCastResultIdOk)
1349014540 {
13491 IrInstruction *cast1 = ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, source_instr, value,
14541 IrInstGen *cast1 = ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, source_instr, value,
1349214542 wanted_child_type);
1349314543 if (type_is_invalid(cast1->value->type))
13494 return ira->codegen->invalid_instruction;
14544 return ira->codegen->invalid_inst_gen;
1349514545 return ir_analyze_optional_wrap(ira, source_instr, cast1, wanted_type, nullptr);
1349614546 }
1349714547 }
......@@ -13509,7 +14559,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1350914559 if (ir_num_lit_fits_in_other_type(ira, value, wanted_type->data.error_union.payload_type, true)) {
1351014560 return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type, nullptr);
1351114561 } else {
13512 return ira->codegen->invalid_instruction;
14562 return ira->codegen->invalid_inst_gen;
1351314563 }
1351414564 }
1351514565 }
......@@ -13525,13 +14575,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1352514575 actual_type->id == ZigTypeIdComptimeInt ||
1352614576 actual_type->id == ZigTypeIdComptimeFloat)
1352714577 {
13528 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value);
14578 IrInstGen *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value);
1352914579 if (type_is_invalid(cast1->value->type))
13530 return ira->codegen->invalid_instruction;
14580 return ira->codegen->invalid_inst_gen;
1353114581
13532 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
14582 IrInstGen *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
1353314583 if (type_is_invalid(cast2->value->type))
13534 return ira->codegen->invalid_instruction;
14584 return ira->codegen->invalid_inst_gen;
1353514585
1353614586 return cast2;
1353714587 }
......@@ -13546,13 +14596,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1354614596 wanted_type->id == ZigTypeIdFloat || wanted_type->id == ZigTypeIdComptimeFloat))
1354714597 {
1354814598 if (value->value->special == ConstValSpecialUndef) {
13549 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
14599 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1355014600 result->value->special = ConstValSpecialUndef;
1355114601 return result;
1355214602 }
1355314603 if (ir_num_lit_fits_in_other_type(ira, value, wanted_type, true)) {
1355414604 if (wanted_type->id == ZigTypeIdComptimeInt || wanted_type->id == ZigTypeIdInt) {
13555 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
14605 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1355614606 if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) {
1355714607 copy_const_val(result->value, value->value);
1355814608 result->value->type = wanted_type;
......@@ -13561,7 +14611,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1356114611 }
1356214612 return result;
1356314613 } else if (wanted_type->id == ZigTypeIdComptimeFloat || wanted_type->id == ZigTypeIdFloat) {
13564 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
14614 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1356514615 if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) {
1356614616 BigFloat bf;
1356714617 bigfloat_init_bigint(&bf, &value->value->data.x_bigint);
......@@ -13573,7 +14623,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1357314623 }
1357414624 zig_unreachable();
1357514625 } else {
13576 return ira->codegen->invalid_instruction;
14626 return ira->codegen->invalid_inst_gen;
1357714627 }
1357814628 }
1357914629
......@@ -13609,13 +14659,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1360914659 actual_type->data.pointer.ptr_len == PtrLenSingle &&
1361014660 actual_type->data.pointer.child_type->id == ZigTypeIdArray)
1361114661 {
13612 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value);
14662 IrInstGen *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value);
1361314663 if (type_is_invalid(cast1->value->type))
13614 return ira->codegen->invalid_instruction;
14664 return ira->codegen->invalid_inst_gen;
1361514665
13616 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
14666 IrInstGen *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
1361714667 if (type_is_invalid(cast2->value->type))
13618 return ira->codegen->invalid_instruction;
14668 return ira->codegen->invalid_inst_gen;
1361914669
1362014670 return cast2;
1362114671 }
......@@ -13636,9 +14686,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1363614686 actual_array_type->data.array.sentinel)))
1363714687 {
1363814688 if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type, ResolveStatusAlignmentKnown)))
13639 return ira->codegen->invalid_instruction;
14689 return ira->codegen->invalid_inst_gen;
1364014690 if ((err = type_resolve(ira->codegen, wanted_type->data.pointer.child_type, ResolveStatusAlignmentKnown)))
13641 return ira->codegen->invalid_instruction;
14691 return ira->codegen->invalid_inst_gen;
1364214692 if (get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, wanted_type) &&
1364314693 types_match_const_cast_only(ira, wanted_type->data.pointer.child_type,
1364414694 actual_type->data.pointer.child_type->data.array.child_type, source_node,
......@@ -13679,24 +14729,24 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1367914729 if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type,
1368014730 ResolveStatusAlignmentKnown)))
1368114731 {
13682 return ira->codegen->invalid_instruction;
14732 return ira->codegen->invalid_inst_gen;
1368314733 }
1368414734 if ((err = type_resolve(ira->codegen, slice_ptr_type->data.pointer.child_type,
1368514735 ResolveStatusAlignmentKnown)))
1368614736 {
13687 return ira->codegen->invalid_instruction;
14737 return ira->codegen->invalid_inst_gen;
1368814738 }
1368914739 ok_align = get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, slice_ptr_type);
1369014740 }
1369114741 if (ok_align) {
1369214742 if (wanted_type->id == ZigTypeIdErrorUnion) {
13693 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, slice_type, value);
14743 IrInstGen *cast1 = ir_analyze_cast(ira, source_instr, slice_type, value);
1369414744 if (type_is_invalid(cast1->value->type))
13695 return ira->codegen->invalid_instruction;
14745 return ira->codegen->invalid_inst_gen;
1369614746
13697 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
14747 IrInstGen *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
1369814748 if (type_is_invalid(cast2->value->type))
13699 return ira->codegen->invalid_instruction;
14749 return ira->codegen->invalid_inst_gen;
1370014750
1370114751 return cast2;
1370214752 } else {
......@@ -13731,12 +14781,12 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1373114781 if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type,
1373214782 ResolveStatusAlignmentKnown)))
1373314783 {
13734 return ira->codegen->invalid_instruction;
14784 return ira->codegen->invalid_inst_gen;
1373514785 }
1373614786 if ((err = type_resolve(ira->codegen, slice_ptr_type->data.pointer.child_type,
1373714787 ResolveStatusAlignmentKnown)))
1373814788 {
13739 return ira->codegen->invalid_instruction;
14789 return ira->codegen->invalid_inst_gen;
1374014790 }
1374114791 ok_align = get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, slice_ptr_type);
1374214792 }
......@@ -13777,7 +14827,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1377714827 }
1377814828 }
1377914829 if (ok) {
13780 IrInstruction *cast1 = ir_analyze_frame_ptr_to_anyframe(ira, source_instr, value, anyframe_type);
14830 IrInstGen *cast1 = ir_analyze_frame_ptr_to_anyframe(ira, source_instr, value, anyframe_type);
1378114831 if (anyframe_type == wanted_type)
1378214832 return cast1;
1378314833 return ir_analyze_cast(ira, source_instr, wanted_type, cast1);
......@@ -13832,28 +14882,28 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1383214882 if (actual_type->id == ZigTypeIdEnumLiteral &&
1383314883 (wanted_type->id == ZigTypeIdOptional && wanted_type->data.maybe.child_type->id == ZigTypeIdEnum))
1383414884 {
13835 IrInstruction *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.maybe.child_type);
13836 if (result == ira->codegen->invalid_instruction)
14885 IrInstGen *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.maybe.child_type);
14886 if (type_is_invalid(result->value->type))
1383714887 return result;
1383814888
13839 return ir_analyze_optional_wrap(ira, result, value, wanted_type, nullptr);
14889 return ir_analyze_optional_wrap(ira, source_instr, value, wanted_type, nullptr);
1384014890 }
1384114891
1384214892 // cast from enum literal to error union when payload is an enum
1384314893 if (actual_type->id == ZigTypeIdEnumLiteral &&
1384414894 (wanted_type->id == ZigTypeIdErrorUnion && wanted_type->data.error_union.payload_type->id == ZigTypeIdEnum))
1384514895 {
13846 IrInstruction *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.error_union.payload_type);
13847 if (result == ira->codegen->invalid_instruction)
14896 IrInstGen *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.error_union.payload_type);
14897 if (type_is_invalid(result->value->type))
1384814898 return result;
1384914899
13850 return ir_analyze_err_wrap_payload(ira, result, value, wanted_type, nullptr);
14900 return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type, nullptr);
1385114901 }
1385214902
1385314903 // cast from union to the enum type of the union
1385414904 if (actual_type->id == ZigTypeIdUnion && wanted_type->id == ZigTypeIdEnum) {
1385514905 if ((err = type_resolve(ira->codegen, actual_type, ResolveStatusZeroBitsKnown)))
13856 return ira->codegen->invalid_instruction;
14906 return ira->codegen->invalid_inst_gen;
1385714907
1385814908 if (actual_type->data.unionation.tag_type == wanted_type) {
1385914909 return ir_analyze_union_to_tag(ira, source_instr, value, wanted_type);
......@@ -13881,8 +14931,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1388114931 (!actual_type->data.pointer.is_const || wanted_type->data.pointer.is_const) &&
1388214932 (!actual_type->data.pointer.is_volatile || wanted_type->data.pointer.is_volatile))
1388314933 {
13884 if ((err = ir_cast_ptr_align(ira, source_instr, wanted_type, actual_type, value->source_node)))
13885 return ira->codegen->invalid_instruction;
14934 if ((err = ir_cast_ptr_align(ira, source_instr, wanted_type, actual_type, value->base.source_node)))
14935 return ira->codegen->invalid_inst_gen;
1388614936
1388714937 return ir_analyze_ptr_to_array(ira, source_instr, value, wanted_type);
1388814938 }
......@@ -13905,7 +14955,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1390514955 slice_ptr_type->data.pointer.sentinel))))
1390614956 {
1390714957 TypeStructField *ptr_field = actual_type->data.structure.fields[slice_ptr_index];
13908 IrInstruction *slice_ptr = ir_analyze_struct_value_field_value(ira, source_instr, value, ptr_field);
14958 IrInstGen *slice_ptr = ir_analyze_struct_value_field_value(ira, source_instr, value, ptr_field);
1390914959 return ir_implicit_cast2(ira, source_instr, slice_ptr, wanted_type);
1391014960 }
1391114961 }
......@@ -13936,7 +14986,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1393614986 {
1393714987 bool has_bits;
1393814988 if ((err = type_has_bits2(ira->codegen, actual_type, &has_bits)))
13939 return ira->codegen->invalid_instruction;
14989 return ira->codegen->invalid_inst_gen;
1394014990 if (!has_bits) {
1394114991 return ir_get_ref(ira, source_instr, value, false, false);
1394214992 }
......@@ -14003,9 +15053,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1400315053
1400415054 // T to ?U, where T implicitly casts to U
1400515055 if (wanted_type->id == ZigTypeIdOptional && actual_type->id != ZigTypeIdOptional) {
14006 IrInstruction *cast1 = ir_implicit_cast2(ira, source_instr, value, wanted_type->data.maybe.child_type);
15056 IrInstGen *cast1 = ir_implicit_cast2(ira, source_instr, value, wanted_type->data.maybe.child_type);
1400715057 if (type_is_invalid(cast1->value->type))
14008 return ira->codegen->invalid_instruction;
15058 return ira->codegen->invalid_inst_gen;
1400915059 return ir_implicit_cast2(ira, source_instr, cast1, wanted_type);
1401015060 }
1401115061
......@@ -14013,9 +15063,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1401315063 if (wanted_type->id == ZigTypeIdErrorUnion && actual_type->id != ZigTypeIdErrorUnion &&
1401415064 actual_type->id != ZigTypeIdErrorSet)
1401515065 {
14016 IrInstruction *cast1 = ir_implicit_cast2(ira, source_instr, value, wanted_type->data.error_union.payload_type);
15066 IrInstGen *cast1 = ir_implicit_cast2(ira, source_instr, value, wanted_type->data.error_union.payload_type);
1401715067 if (type_is_invalid(cast1->value->type))
14018 return ira->codegen->invalid_instruction;
15068 return ira->codegen->invalid_inst_gen;
1401915069 return ir_implicit_cast2(ira, source_instr, cast1, wanted_type);
1402015070 }
1402115071
......@@ -14024,14 +15074,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1402415074 buf_ptr(&wanted_type->name),
1402515075 buf_ptr(&actual_type->name)));
1402615076 report_recursive_error(ira, source_instr->source_node, &const_cast_result, parent_msg);
14027 return ira->codegen->invalid_instruction;
15077 return ira->codegen->invalid_inst_gen;
1402815078}
1402915079
14030static IrInstruction *ir_implicit_cast2(IrAnalyze *ira, IrInstruction *value_source_instr,
14031 IrInstruction *value, ZigType *expected_type)
15080static IrInstGen *ir_implicit_cast2(IrAnalyze *ira, IrInst *value_source_instr,
15081 IrInstGen *value, ZigType *expected_type)
1403215082{
1403315083 assert(value);
14034 assert(value != ira->codegen->invalid_instruction);
1403515084 assert(!expected_type || !type_is_invalid(expected_type));
1403615085 assert(value->value->type);
1403715086 assert(!type_is_invalid(value->value->type));
......@@ -14045,17 +15094,17 @@ static IrInstruction *ir_implicit_cast2(IrAnalyze *ira, IrInstruction *value_sou
1404515094 return ir_analyze_cast(ira, value_source_instr, expected_type, value);
1404615095}
1404715096
14048static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type) {
14049 return ir_implicit_cast2(ira, value, value, expected_type);
15097static IrInstGen *ir_implicit_cast(IrAnalyze *ira, IrInstGen *value, ZigType *expected_type) {
15098 return ir_implicit_cast2(ira, &value->base, value, expected_type);
1405015099}
1405115100
14052static ZigType *get_ptr_elem_type(CodeGen *g, IrInstruction *ptr) {
14053 ir_assert(ptr->value->type->id == ZigTypeIdPointer, ptr);
15101static ZigType *get_ptr_elem_type(CodeGen *g, IrInstGen *ptr) {
15102 ir_assert_gen(ptr->value->type->id == ZigTypeIdPointer, ptr);
1405415103 ZigType *elem_type = ptr->value->type->data.pointer.child_type;
1405515104 if (elem_type != g->builtin_types.entry_var)
1405615105 return elem_type;
1405715106
14058 if (ir_resolve_lazy(g, ptr->source_node, ptr->value))
15107 if (ir_resolve_lazy(g, ptr->base.source_node, ptr->value))
1405915108 return g->builtin_types.entry_invalid;
1406015109
1406115110 assert(value_is_comptime(ptr->value));
......@@ -14063,28 +15112,28 @@ static ZigType *get_ptr_elem_type(CodeGen *g, IrInstruction *ptr) {
1406315112 return pointee->type;
1406415113}
1406515114
14066static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr,
15115static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrInstGen *ptr,
1406715116 ResultLoc *result_loc)
1406815117{
1406915118 Error err;
1407015119 ZigType *ptr_type = ptr->value->type;
1407115120 if (type_is_invalid(ptr_type))
14072 return ira->codegen->invalid_instruction;
15121 return ira->codegen->invalid_inst_gen;
1407315122
1407415123 if (ptr_type->id != ZigTypeIdPointer) {
1407515124 ir_add_error_node(ira, source_instruction->source_node,
1407615125 buf_sprintf("attempt to dereference non-pointer type '%s'",
1407715126 buf_ptr(&ptr_type->name)));
14078 return ira->codegen->invalid_instruction;
15127 return ira->codegen->invalid_inst_gen;
1407915128 }
1408015129
1408115130 ZigType *child_type = ptr_type->data.pointer.child_type;
1408215131 if (type_is_invalid(child_type))
14083 return ira->codegen->invalid_instruction;
15132 return ira->codegen->invalid_inst_gen;
1408415133 // if the child type has one possible value, the deref is comptime
1408515134 switch (type_has_one_possible_value(ira->codegen, child_type)) {
1408615135 case OnePossibleValueInvalid:
14087 return ira->codegen->invalid_instruction;
15136 return ira->codegen->invalid_inst_gen;
1408815137 case OnePossibleValueYes:
1408915138 return ir_const_move(ira, source_instruction,
1409015139 get_the_one_possible_value(ira->codegen, child_type));
......@@ -14093,8 +15142,8 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
1409315142 }
1409415143 if (instr_is_comptime(ptr)) {
1409515144 if (ptr->value->special == ConstValSpecialUndef) {
14096 ir_add_error(ira, ptr, buf_sprintf("attempt to dereference undefined value"));
14097 return ira->codegen->invalid_instruction;
15145 ir_add_error(ira, &ptr->base, buf_sprintf("attempt to dereference undefined value"));
15146 return ira->codegen->invalid_inst_gen;
1409815147 }
1409915148 if (ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
1410015149 ZigValue *pointee = const_ptr_pointee_unchecked(ira->codegen, ptr->value);
......@@ -14102,12 +15151,12 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
1410215151 child_type = pointee->type;
1410315152 }
1410415153 if (pointee->special != ConstValSpecialRuntime) {
14105 IrInstruction *result = ir_const(ira, source_instruction, child_type);
15154 IrInstGen *result = ir_const(ira, source_instruction, child_type);
1410615155
1410715156 if ((err = ir_read_const_ptr(ira, ira->codegen, source_instruction->source_node, result->value,
1410815157 ptr->value)))
1410915158 {
14110 return ira->codegen->invalid_instruction;
15159 return ira->codegen->invalid_inst_gen;
1411115160 }
1411215161 result->value->type = child_type;
1411315162 return result;
......@@ -14116,38 +15165,38 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
1411615165 }
1411715166
1411815167 // if the instruction is a const ref instruction we can skip it
14119 if (ptr->id == IrInstructionIdRef) {
14120 IrInstructionRef *ref_inst = reinterpret_cast<IrInstructionRef *>(ptr);
14121 return ref_inst->value;
15168 if (ptr->id == IrInstGenIdRef) {
15169 IrInstGenRef *ref_inst = reinterpret_cast<IrInstGenRef *>(ptr);
15170 return ref_inst->operand;
1412215171 }
1412315172
1412415173 // If the instruction is a element pointer instruction to a vector, we emit
1412515174 // vector element extract instruction rather than load pointer. If the
1412615175 // pointer type has non-VECTOR_INDEX_RUNTIME value, it would have been
14127 // possible to implement this in the codegen for IrInstructionLoadPtrGen.
15176 // possible to implement this in the codegen for IrInstGenLoadPtr.
1412815177 // However if it has VECTOR_INDEX_RUNTIME then we must emit a compile error
1412915178 // if the vector index cannot be determined right here, right now, because
1413015179 // the type information does not contain enough information to actually
1413115180 // perform a dereference.
1413215181 if (ptr_type->data.pointer.vector_index == VECTOR_INDEX_RUNTIME) {
14133 if (ptr->id == IrInstructionIdElemPtr) {
14134 IrInstructionElemPtr *elem_ptr = (IrInstructionElemPtr *)ptr;
14135 IrInstruction *vector_loaded = ir_get_deref(ira, elem_ptr->array_ptr,
15182 if (ptr->id == IrInstGenIdElemPtr) {
15183 IrInstGenElemPtr *elem_ptr = (IrInstGenElemPtr *)ptr;
15184 IrInstGen *vector_loaded = ir_get_deref(ira, &elem_ptr->array_ptr->base,
1413615185 elem_ptr->array_ptr, nullptr);
14137 IrInstruction *elem_index = elem_ptr->elem_index;
15186 IrInstGen *elem_index = elem_ptr->elem_index;
1413815187 return ir_build_vector_extract_elem(ira, source_instruction, vector_loaded, elem_index);
1413915188 }
14140 ir_add_error(ira, ptr,
15189 ir_add_error(ira, &ptr->base,
1414115190 buf_sprintf("unable to determine vector element index of type '%s'", buf_ptr(&ptr_type->name)));
14142 return ira->codegen->invalid_instruction;
15191 return ira->codegen->invalid_inst_gen;
1414315192 }
1414415193
14145 IrInstruction *result_loc_inst;
15194 IrInstGen *result_loc_inst;
1414615195 if (ptr_type->data.pointer.host_int_bytes != 0 && handle_is_ptr(child_type)) {
1414715196 if (result_loc == nullptr) result_loc = no_result_loc();
1414815197 result_loc_inst = ir_resolve_result(ira, source_instruction, result_loc, child_type, nullptr,
1414915198 true, false, true);
14150 if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) {
15199 if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) {
1415115200 return result_loc_inst;
1415215201 }
1415315202 } else {
......@@ -14157,7 +15206,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
1415715206 return ir_build_load_ptr_gen(ira, source_instruction, ptr, child_type, result_loc_inst);
1415815207}
1415915208
14160static bool ir_resolve_const_align(CodeGen *codegen, IrExecutable *exec, AstNode *source_node,
15209static bool ir_resolve_const_align(CodeGen *codegen, IrExecutableGen *exec, AstNode *source_node,
1416115210 ZigValue *const_val, uint32_t *out)
1416215211{
1416315212 Error err;
......@@ -14166,12 +15215,12 @@ static bool ir_resolve_const_align(CodeGen *codegen, IrExecutable *exec, AstNode
1416615215
1416715216 uint32_t align_bytes = bigint_as_u32(&const_val->data.x_bigint);
1416815217 if (align_bytes == 0) {
14169 exec_add_error_node(codegen, exec, source_node, buf_sprintf("alignment must be >= 1"));
15218 exec_add_error_node_gen(codegen, exec, source_node, buf_sprintf("alignment must be >= 1"));
1417015219 return false;
1417115220 }
1417215221
1417315222 if (!is_power_of_2(align_bytes)) {
14174 exec_add_error_node(codegen, exec, source_node,
15223 exec_add_error_node_gen(codegen, exec, source_node,
1417515224 buf_sprintf("alignment value %" PRIu32 " is not a power of 2", align_bytes));
1417615225 return false;
1417715226 }
......@@ -14180,7 +15229,7 @@ static bool ir_resolve_const_align(CodeGen *codegen, IrExecutable *exec, AstNode
1418015229 return true;
1418115230}
1418215231
14183static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, ZigType *elem_type, uint32_t *out) {
15232static bool ir_resolve_align(IrAnalyze *ira, IrInstGen *value, ZigType *elem_type, uint32_t *out) {
1418415233 if (type_is_invalid(value->value->type))
1418515234 return false;
1418615235
......@@ -14201,19 +15250,19 @@ static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, ZigType *elem
1420115250 }
1420215251 }
1420315252
14204 IrInstruction *casted_value = ir_implicit_cast(ira, value, get_align_amt_type(ira->codegen));
15253 IrInstGen *casted_value = ir_implicit_cast(ira, value, get_align_amt_type(ira->codegen));
1420515254 if (type_is_invalid(casted_value->value->type))
1420615255 return false;
1420715256
14208 return ir_resolve_const_align(ira->codegen, ira->new_irb.exec, value->source_node,
15257 return ir_resolve_const_align(ira->codegen, ira->new_irb.exec, value->base.source_node,
1420915258 casted_value->value, out);
1421015259}
1421115260
14212static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstruction *value, ZigType *int_type, uint64_t *out) {
15261static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstGen *value, ZigType *int_type, uint64_t *out) {
1421315262 if (type_is_invalid(value->value->type))
1421415263 return false;
1421515264
14216 IrInstruction *casted_value = ir_implicit_cast(ira, value, int_type);
15265 IrInstGen *casted_value = ir_implicit_cast(ira, value, int_type);
1421715266 if (type_is_invalid(casted_value->value->type))
1421815267 return false;
1421915268
......@@ -14225,15 +15274,15 @@ static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstruction *value, ZigType *i
1422515274 return true;
1422615275}
1422715276
14228static bool ir_resolve_usize(IrAnalyze *ira, IrInstruction *value, uint64_t *out) {
15277static bool ir_resolve_usize(IrAnalyze *ira, IrInstGen *value, uint64_t *out) {
1422915278 return ir_resolve_unsigned(ira, value, ira->codegen->builtin_types.entry_usize, out);
1423015279}
1423115280
14232static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) {
15281static bool ir_resolve_bool(IrAnalyze *ira, IrInstGen *value, bool *out) {
1423315282 if (type_is_invalid(value->value->type))
1423415283 return false;
1423515284
14236 IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_bool);
15285 IrInstGen *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_bool);
1423715286 if (type_is_invalid(casted_value->value->type))
1423815287 return false;
1423915288
......@@ -14245,7 +15294,7 @@ static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) {
1424515294 return true;
1424615295}
1424715296
14248static bool ir_resolve_comptime(IrAnalyze *ira, IrInstruction *value, bool *out) {
15297static bool ir_resolve_comptime(IrAnalyze *ira, IrInstGen *value, bool *out) {
1424915298 if (!value) {
1425015299 *out = false;
1425115300 return true;
......@@ -14253,13 +15302,13 @@ static bool ir_resolve_comptime(IrAnalyze *ira, IrInstruction *value, bool *out)
1425315302 return ir_resolve_bool(ira, value, out);
1425415303}
1425515304
14256static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, AtomicOrder *out) {
15305static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstGen *value, AtomicOrder *out) {
1425715306 if (type_is_invalid(value->value->type))
1425815307 return false;
1425915308
1426015309 ZigType *atomic_order_type = get_builtin_type(ira->codegen, "AtomicOrder");
1426115310
14262 IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_order_type);
15311 IrInstGen *casted_value = ir_implicit_cast(ira, value, atomic_order_type);
1426315312 if (type_is_invalid(casted_value->value->type))
1426415313 return false;
1426515314
......@@ -14271,13 +15320,13 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic
1427115320 return true;
1427215321}
1427315322
14274static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, AtomicRmwOp *out) {
15323static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstGen *value, AtomicRmwOp *out) {
1427515324 if (type_is_invalid(value->value->type))
1427615325 return false;
1427715326
1427815327 ZigType *atomic_rmw_op_type = get_builtin_type(ira->codegen, "AtomicRmwOp");
1427915328
14280 IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_rmw_op_type);
15329 IrInstGen *casted_value = ir_implicit_cast(ira, value, atomic_rmw_op_type);
1428115330 if (type_is_invalid(casted_value->value->type))
1428215331 return false;
1428315332
......@@ -14289,13 +15338,13 @@ static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, Atomi
1428915338 return true;
1429015339}
1429115340
14292static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, GlobalLinkageId *out) {
15341static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstGen *value, GlobalLinkageId *out) {
1429315342 if (type_is_invalid(value->value->type))
1429415343 return false;
1429515344
1429615345 ZigType *global_linkage_type = get_builtin_type(ira->codegen, "GlobalLinkage");
1429715346
14298 IrInstruction *casted_value = ir_implicit_cast(ira, value, global_linkage_type);
15347 IrInstGen *casted_value = ir_implicit_cast(ira, value, global_linkage_type);
1429915348 if (type_is_invalid(casted_value->value->type))
1430015349 return false;
1430115350
......@@ -14307,13 +15356,13 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob
1430715356 return true;
1430815357}
1430915358
14310static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMode *out) {
15359static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstGen *value, FloatMode *out) {
1431115360 if (type_is_invalid(value->value->type))
1431215361 return false;
1431315362
1431415363 ZigType *float_mode_type = get_builtin_type(ira->codegen, "FloatMode");
1431515364
14316 IrInstruction *casted_value = ir_implicit_cast(ira, value, float_mode_type);
15365 IrInstGen *casted_value = ir_implicit_cast(ira, value, float_mode_type);
1431715366 if (type_is_invalid(casted_value->value->type))
1431815367 return false;
1431915368
......@@ -14325,14 +15374,14 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod
1432515374 return true;
1432615375}
1432715376
14328static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
15377static Buf *ir_resolve_str(IrAnalyze *ira, IrInstGen *value) {
1432915378 if (type_is_invalid(value->value->type))
1433015379 return nullptr;
1433115380
1433215381 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
1433315382 true, false, PtrLenUnknown, 0, 0, 0, false);
1433415383 ZigType *str_type = get_slice_type(ira->codegen, ptr_type);
14335 IrInstruction *casted_value = ir_implicit_cast(ira, value, str_type);
15384 IrInstGen *casted_value = ir_implicit_cast(ira, value, str_type);
1433615385 if (type_is_invalid(casted_value->value->type))
1433715386 return nullptr;
1433815387
......@@ -14356,7 +15405,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
1435615405 size_t new_index = ptr_field->data.x_ptr.data.base_array.elem_index + i;
1435715406 ZigValue *char_val = &array_val->data.x_array.data.s_none.elements[new_index];
1435815407 if (char_val->special == ConstValSpecialUndef) {
14359 ir_add_error(ira, casted_value, buf_sprintf("use of undefined value"));
15408 ir_add_error(ira, &casted_value->base, buf_sprintf("use of undefined value"));
1436015409 return nullptr;
1436115410 }
1436215411 uint64_t big_c = bigint_as_u64(&char_val->data.x_bigint);
......@@ -14367,10 +15416,10 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
1436715416 return result;
1436815417}
1436915418
14370static IrInstruction *ir_analyze_instruction_add_implicit_return_type(IrAnalyze *ira,
14371 IrInstructionAddImplicitReturnType *instruction)
15419static IrInstGen *ir_analyze_instruction_add_implicit_return_type(IrAnalyze *ira,
15420 IrInstSrcAddImplicitReturnType *instruction)
1437215421{
14373 IrInstruction *value = instruction->value->child;
15422 IrInstGen *value = instruction->value->child;
1437415423 if (type_is_invalid(value->value->type))
1437515424 return ir_unreach_error(ira);
1437615425
......@@ -14378,15 +15427,15 @@ static IrInstruction *ir_analyze_instruction_add_implicit_return_type(IrAnalyze
1437815427 ira->src_implicit_return_type_list.append(value);
1437915428 }
1438015429
14381 return ir_const_void(ira, &instruction->base);
15430 return ir_const_void(ira, &instruction->base.base);
1438215431}
1438315432
14384static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructionReturn *instruction) {
14385 IrInstruction *operand = instruction->operand->child;
15433static IrInstGen *ir_analyze_instruction_return(IrAnalyze *ira, IrInstSrcReturn *instruction) {
15434 IrInstGen *operand = instruction->operand->child;
1438615435 if (type_is_invalid(operand->value->type))
1438715436 return ir_unreach_error(ira);
1438815437
14389 IrInstruction *casted_operand = ir_implicit_cast(ira, operand, ira->explicit_return_type);
15438 IrInstGen *casted_operand = ir_implicit_cast(ira, operand, ira->explicit_return_type);
1439015439 if (type_is_invalid(casted_operand->value->type)) {
1439115440 AstNode *source_node = ira->explicit_return_type_source_node;
1439215441 if (source_node != nullptr) {
......@@ -14401,9 +15450,7 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio
1440115450 handle_is_ptr(ira->explicit_return_type))
1440215451 {
1440315452 // result location mechanism took care of it.
14404 IrInstruction *result = ir_build_return(&ira->new_irb, instruction->base.scope,
14405 instruction->base.source_node, nullptr);
14406 result->value->type = ira->codegen->builtin_types.entry_unreachable;
15453 IrInstGen *result = ir_build_return_gen(ira, &instruction->base.base, nullptr);
1440715454 return ir_finish_anal(ira, result);
1440815455 }
1440915456
......@@ -14411,47 +15458,45 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio
1441115458 casted_operand->value->type->id == ZigTypeIdPointer &&
1441215459 casted_operand->value->data.rh_ptr == RuntimeHintPtrStack)
1441315460 {
14414 ir_add_error(ira, casted_operand, buf_sprintf("function returns address of local variable"));
15461 ir_add_error(ira, &casted_operand->base, buf_sprintf("function returns address of local variable"));
1441515462 return ir_unreach_error(ira);
1441615463 }
1441715464
14418 IrInstruction *result = ir_build_return(&ira->new_irb, instruction->base.scope,
14419 instruction->base.source_node, casted_operand);
14420 result->value->type = ira->codegen->builtin_types.entry_unreachable;
15465 IrInstGen *result = ir_build_return_gen(ira, &instruction->base.base, casted_operand);
1442115466 return ir_finish_anal(ira, result);
1442215467}
1442315468
14424static IrInstruction *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *instruction) {
14425 return ir_const_move(ira, &instruction->base, instruction->base.value);
15469static IrInstGen *ir_analyze_instruction_const(IrAnalyze *ira, IrInstSrcConst *instruction) {
15470 return ir_const_move(ira, &instruction->base.base, instruction->value);
1442615471}
1442715472
14428static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
14429 IrInstruction *op1 = bin_op_instruction->op1->child;
15473static IrInstGen *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstSrcBinOp *bin_op_instruction) {
15474 IrInstGen *op1 = bin_op_instruction->op1->child;
1443015475 if (type_is_invalid(op1->value->type))
14431 return ira->codegen->invalid_instruction;
15476 return ira->codegen->invalid_inst_gen;
1443215477
14433 IrInstruction *op2 = bin_op_instruction->op2->child;
15478 IrInstGen *op2 = bin_op_instruction->op2->child;
1443415479 if (type_is_invalid(op2->value->type))
14435 return ira->codegen->invalid_instruction;
15480 return ira->codegen->invalid_inst_gen;
1443615481
1443715482 ZigType *bool_type = ira->codegen->builtin_types.entry_bool;
1443815483
14439 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, bool_type);
14440 if (casted_op1 == ira->codegen->invalid_instruction)
14441 return ira->codegen->invalid_instruction;
15484 IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, bool_type);
15485 if (type_is_invalid(casted_op1->value->type))
15486 return ira->codegen->invalid_inst_gen;
1444215487
14443 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, bool_type);
14444 if (casted_op2 == ira->codegen->invalid_instruction)
14445 return ira->codegen->invalid_instruction;
15488 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, bool_type);
15489 if (type_is_invalid(casted_op2->value->type))
15490 return ira->codegen->invalid_inst_gen;
1444615491
1444715492 if (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2)) {
1444815493 ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);
1444915494 if (op1_val == nullptr)
14450 return ira->codegen->invalid_instruction;
15495 return ira->codegen->invalid_inst_gen;
1445115496
1445215497 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
1445315498 if (op2_val == nullptr)
14454 return ira->codegen->invalid_instruction;
15499 return ira->codegen->invalid_inst_gen;
1445515500
1445615501 assert(casted_op1->value->type->id == ZigTypeIdBool);
1445715502 assert(casted_op2->value->type->id == ZigTypeIdBool);
......@@ -14463,14 +15508,11 @@ static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp
1446315508 } else {
1446415509 zig_unreachable();
1446515510 }
14466 return ir_const_bool(ira, &bin_op_instruction->base, result_bool);
15511 return ir_const_bool(ira, &bin_op_instruction->base.base, result_bool);
1446715512 }
1446815513
14469 IrInstruction *result = ir_build_bin_op(&ira->new_irb,
14470 bin_op_instruction->base.scope, bin_op_instruction->base.source_node,
15514 return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, bool_type,
1447115515 bin_op_instruction->op_id, casted_op1, casted_op2, bin_op_instruction->safety_check_on);
14472 result->value->type = bool_type;
14473 return result;
1447415516}
1447515517
1447615518static bool resolve_cmp_op_id(IrBinOp op_id, Cmp cmp) {
......@@ -14535,12 +15577,13 @@ static void set_optional_payload(ZigValue *opt_val, ZigValue *payload) {
1453515577 }
1453615578}
1453715579
14538static IrInstruction *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_type,
14539 ZigValue *op1_val, ZigValue *op2_val, IrInstructionBinOp *bin_op_instruction, IrBinOp op_id,
14540 bool one_possible_value) {
15580static IrInstGen *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_type,
15581 ZigValue *op1_val, ZigValue *op2_val, IrInstSrcBinOp *bin_op_instruction, IrBinOp op_id,
15582 bool one_possible_value)
15583{
1454115584 if (op1_val->special == ConstValSpecialUndef ||
1454215585 op2_val->special == ConstValSpecialUndef)
14543 return ir_const_undef(ira, &bin_op_instruction->base, resolved_type);
15586 return ir_const_undef(ira, &bin_op_instruction->base.base, resolved_type);
1454415587 if (resolved_type->id == ZigTypeIdPointer && op_id != IrBinOpCmpEq && op_id != IrBinOpCmpNotEq) {
1454515588 if ((op1_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr ||
1454615589 op1_val->data.x_ptr.special == ConstPtrSpecialNull) &&
......@@ -14560,7 +15603,7 @@ static IrInstruction *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_t
1456015603 cmp_result = CmpEQ;
1456115604 }
1456215605 bool answer = resolve_cmp_op_id(op_id, cmp_result);
14563 return ir_const_bool(ira, &bin_op_instruction->base, answer);
15606 return ir_const_bool(ira, &bin_op_instruction->base.base, answer);
1456415607 }
1456515608 } else {
1456615609 bool are_equal = one_possible_value || const_values_equal(ira->codegen, op1_val, op2_val);
......@@ -14572,7 +15615,7 @@ static IrInstruction *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_t
1457215615 } else {
1457315616 zig_unreachable();
1457415617 }
14575 return ir_const_bool(ira, &bin_op_instruction->base, answer);
15618 return ir_const_bool(ira, &bin_op_instruction->base.base, answer);
1457615619 }
1457715620 zig_unreachable();
1457815621}
......@@ -14626,7 +15669,7 @@ static Error lazy_cmp_zero(AstNode *source_node, ZigValue *val, Cmp *result) {
1462615669 zig_unreachable();
1462715670}
1462815671
14629static ErrorMsg *ir_eval_bin_op_cmp_scalar(IrAnalyze *ira, IrInstruction *source_instr,
15672static ErrorMsg *ir_eval_bin_op_cmp_scalar(IrAnalyze *ira, IrInst* source_instr,
1463015673 ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val, ZigValue *out_val)
1463115674{
1463215675 Error err;
......@@ -14704,14 +15747,14 @@ never_mind_just_calculate_it_normally:
1470415747 return nullptr;
1470515748 }
1470615749 if (op1_val->type->id == ZigTypeIdComptimeFloat) {
14707 IrInstruction *tmp = ir_const_noval(ira, source_instr);
15750 IrInstGen *tmp = ir_const_noval(ira, source_instr);
1470815751 tmp->value = op1_val;
14709 IrInstruction *casted = ir_implicit_cast(ira, tmp, op2_val->type);
15752 IrInstGen *casted = ir_implicit_cast(ira, tmp, op2_val->type);
1471015753 op1_val = casted->value;
1471115754 } else if (op2_val->type->id == ZigTypeIdComptimeFloat) {
14712 IrInstruction *tmp = ir_const_noval(ira, source_instr);
15755 IrInstGen *tmp = ir_const_noval(ira, source_instr);
1471315756 tmp->value = op2_val;
14714 IrInstruction *casted = ir_implicit_cast(ira, tmp, op1_val->type);
15757 IrInstGen *casted = ir_implicit_cast(ira, tmp, op1_val->type);
1471515758 op2_val = casted->value;
1471615759 }
1471715760 Cmp cmp_result = float_cmp(op1_val, op2_val);
......@@ -14753,8 +15796,8 @@ never_mind_just_calculate_it_normally:
1475315796 return nullptr;
1475415797}
1475515798
14756static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstruction *source_instr,
14757 IrInstruction *op1, IrInstruction *op2, IrBinOp op_id)
15799static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_instr,
15800 IrInstGen *op1, IrInstGen *op2, IrBinOp op_id)
1475815801{
1475915802 Error err;
1476015803
......@@ -14767,7 +15810,7 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
1476715810 ir_add_error(ira, source_instr,
1476815811 buf_sprintf("vector length mismatch: %" PRIu32 " and %" PRIu32,
1476915812 op1->value->type->data.vector.len, op2->value->type->data.vector.len));
14770 return ira->codegen->invalid_instruction;
15813 return ira->codegen->invalid_inst_gen;
1477115814 }
1477215815 result_type = get_vector_type(ira->codegen, op1->value->type->data.vector.len, scalar_result_type);
1477315816 op1_scalar_type = op1->value->type->data.vector.elem_type;
......@@ -14776,13 +15819,13 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
1477615819 ir_add_error(ira, source_instr,
1477715820 buf_sprintf("mixed scalar and vector operands to comparison operator: '%s' and '%s'",
1477815821 buf_ptr(&op1->value->type->name), buf_ptr(&op2->value->type->name)));
14779 return ira->codegen->invalid_instruction;
15822 return ira->codegen->invalid_inst_gen;
1478015823 }
1478115824
1478215825 bool opv_op1;
1478315826 switch (type_has_one_possible_value(ira->codegen, op1->value->type)) {
1478415827 case OnePossibleValueInvalid:
14785 return ira->codegen->invalid_instruction;
15828 return ira->codegen->invalid_inst_gen;
1478615829 case OnePossibleValueYes:
1478715830 opv_op1 = true;
1478815831 break;
......@@ -14793,7 +15836,7 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
1479315836 bool opv_op2;
1479415837 switch (type_has_one_possible_value(ira->codegen, op2->value->type)) {
1479515838 case OnePossibleValueInvalid:
14796 return ira->codegen->invalid_instruction;
15839 return ira->codegen->invalid_inst_gen;
1479715840 case OnePossibleValueYes:
1479815841 opv_op2 = true;
1479915842 break;
......@@ -14804,21 +15847,21 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
1480415847 Cmp op1_cmp_zero;
1480515848 bool have_op1_cmp_zero = false;
1480615849 if ((err = lazy_cmp_zero(source_instr->source_node, op1->value, &op1_cmp_zero))) {
14807 if (err != ErrorNotLazy) return ira->codegen->invalid_instruction;
15850 if (err != ErrorNotLazy) return ira->codegen->invalid_inst_gen;
1480815851 } else {
1480915852 have_op1_cmp_zero = true;
1481015853 }
1481115854 Cmp op2_cmp_zero;
1481215855 bool have_op2_cmp_zero = false;
1481315856 if ((err = lazy_cmp_zero(source_instr->source_node, op2->value, &op2_cmp_zero))) {
14814 if (err != ErrorNotLazy) return ira->codegen->invalid_instruction;
15857 if (err != ErrorNotLazy) return ira->codegen->invalid_inst_gen;
1481515858 } else {
1481615859 have_op2_cmp_zero = true;
1481715860 }
1481815861 if (((opv_op1 || instr_is_comptime(op1)) && (opv_op2 || instr_is_comptime(op2))) ||
1481915862 (have_op1_cmp_zero && have_op2_cmp_zero))
1482015863 {
14821 IrInstruction *result_instruction = ir_const(ira, source_instr, result_type);
15864 IrInstGen *result_instruction = ir_const(ira, source_instr, result_type);
1482215865 ZigValue *out_val = result_instruction->value;
1482315866 if (result_type->id == ZigTypeIdVector) {
1482415867 size_t len = result_type->data.vector.len;
......@@ -14836,7 +15879,7 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
1483615879 if (msg != nullptr) {
1483715880 add_error_note(ira->codegen, msg, source_instr->source_node,
1483815881 buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i));
14839 return ira->codegen->invalid_instruction;
15882 return ira->codegen->invalid_inst_gen;
1484015883 }
1484115884 }
1484215885 out_val->type = result_type;
......@@ -14845,7 +15888,7 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
1484515888 if (ir_eval_bin_op_cmp_scalar(ira, source_instr, op1->value, op_id,
1484615889 op2->value, out_val) != nullptr)
1484715890 {
14848 return ira->codegen->invalid_instruction;
15891 return ira->codegen->invalid_inst_gen;
1484915892 }
1485015893 }
1485115894 return result_instruction;
......@@ -14939,10 +15982,10 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
1493915982 }
1494015983 ZigType *dest_type = (result_type->id == ZigTypeIdVector) ?
1494115984 get_vector_type(ira->codegen, result_type->data.vector.len, dest_scalar_type) : dest_scalar_type;
14942 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, dest_type);
14943 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, dest_type);
15985 IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, dest_type);
15986 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, dest_type);
1494415987 if (type_is_invalid(casted_op1->value->type) || type_is_invalid(casted_op2->value->type))
14945 return ira->codegen->invalid_instruction;
15988 return ira->codegen->invalid_inst_gen;
1494615989 return ir_build_bin_op_gen(ira, source_instr, result_type, op_id, casted_op1, casted_op2, true);
1494715990 }
1494815991
......@@ -14972,12 +16015,12 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
1497216015 if (instr_is_comptime(op1)) {
1497316016 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefOk);
1497416017 if (op1_val == nullptr)
14975 return ira->codegen->invalid_instruction;
16018 return ira->codegen->invalid_inst_gen;
1497616019 if (op1_val->special == ConstValSpecialUndef)
1497716020 return ir_const_undef(ira, source_instr, ira->codegen->builtin_types.entry_bool);
1497816021 if (result_type->id == ZigTypeIdVector) {
14979 ir_add_error(ira, op1, buf_sprintf("compiler bug: TODO: support comptime vector here"));
14980 return ira->codegen->invalid_instruction;
16022 ir_add_error(ira, &op1->base, buf_sprintf("compiler bug: TODO: support comptime vector here"));
16023 return ira->codegen->invalid_inst_gen;
1498116024 }
1498216025 bool is_unsigned;
1498316026 if (op1_is_float) {
......@@ -15016,12 +16059,12 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
1501616059 if (instr_is_comptime(op2)) {
1501716060 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefOk);
1501816061 if (op2_val == nullptr)
15019 return ira->codegen->invalid_instruction;
16062 return ira->codegen->invalid_inst_gen;
1502016063 if (op2_val->special == ConstValSpecialUndef)
1502116064 return ir_const_undef(ira, source_instr, ira->codegen->builtin_types.entry_bool);
1502216065 if (result_type->id == ZigTypeIdVector) {
15023 ir_add_error(ira, op2, buf_sprintf("compiler bug: TODO: support comptime vector here"));
15024 return ira->codegen->invalid_instruction;
16066 ir_add_error(ira, &op2->base, buf_sprintf("compiler bug: TODO: support comptime vector here"));
16067 return ira->codegen->invalid_inst_gen;
1502516068 }
1502616069 bool is_unsigned;
1502716070 if (op2_is_float) {
......@@ -15062,35 +16105,35 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
1506216105 ZigType *dest_type = (result_type->id == ZigTypeIdVector) ?
1506316106 get_vector_type(ira->codegen, result_type->data.vector.len, dest_scalar_type) : dest_scalar_type;
1506416107
15065 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, dest_type);
16108 IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, dest_type);
1506616109 if (type_is_invalid(casted_op1->value->type))
15067 return ira->codegen->invalid_instruction;
15068 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, dest_type);
16110 return ira->codegen->invalid_inst_gen;
16111 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, dest_type);
1506916112 if (type_is_invalid(casted_op2->value->type))
15070 return ira->codegen->invalid_instruction;
16113 return ira->codegen->invalid_inst_gen;
1507116114 return ir_build_bin_op_gen(ira, source_instr, result_type, op_id, casted_op1, casted_op2, true);
1507216115}
1507316116
15074static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
15075 IrInstruction *op1 = bin_op_instruction->op1->child;
16117static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_instruction) {
16118 IrInstGen *op1 = bin_op_instruction->op1->child;
1507616119 if (type_is_invalid(op1->value->type))
15077 return ira->codegen->invalid_instruction;
16120 return ira->codegen->invalid_inst_gen;
1507816121
15079 IrInstruction *op2 = bin_op_instruction->op2->child;
16122 IrInstGen *op2 = bin_op_instruction->op2->child;
1508016123 if (type_is_invalid(op2->value->type))
15081 return ira->codegen->invalid_instruction;
16124 return ira->codegen->invalid_inst_gen;
1508216125
15083 AstNode *source_node = bin_op_instruction->base.source_node;
16126 AstNode *source_node = bin_op_instruction->base.base.source_node;
1508416127
1508516128 IrBinOp op_id = bin_op_instruction->op_id;
1508616129 bool is_equality_cmp = (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq);
1508716130 if (is_equality_cmp && op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdNull) {
15088 return ir_const_bool(ira, &bin_op_instruction->base, (op_id == IrBinOpCmpEq));
16131 return ir_const_bool(ira, &bin_op_instruction->base.base, (op_id == IrBinOpCmpEq));
1508916132 } else if (is_equality_cmp &&
1509016133 ((op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdOptional) ||
1509116134 (op2->value->type->id == ZigTypeIdNull && op1->value->type->id == ZigTypeIdOptional)))
1509216135 {
15093 IrInstruction *maybe_op;
16136 IrInstGen *maybe_op;
1509416137 if (op1->value->type->id == ZigTypeIdNull) {
1509516138 maybe_op = op2;
1509616139 } else if (op2->value->type->id == ZigTypeIdNull) {
......@@ -15101,21 +16144,16 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1510116144 if (instr_is_comptime(maybe_op)) {
1510216145 ZigValue *maybe_val = ir_resolve_const(ira, maybe_op, UndefBad);
1510316146 if (!maybe_val)
15104 return ira->codegen->invalid_instruction;
16147 return ira->codegen->invalid_inst_gen;
1510516148 bool is_null = optional_value_is_null(maybe_val);
1510616149 bool bool_result = (op_id == IrBinOpCmpEq) ? is_null : !is_null;
15107 return ir_const_bool(ira, &bin_op_instruction->base, bool_result);
16150 return ir_const_bool(ira, &bin_op_instruction->base.base, bool_result);
1510816151 }
1510916152
15110 IrInstruction *is_non_null = ir_build_test_nonnull(&ira->new_irb, bin_op_instruction->base.scope,
15111 source_node, maybe_op);
15112 is_non_null->value->type = ira->codegen->builtin_types.entry_bool;
16153 IrInstGen *is_non_null = ir_build_test_non_null_gen(ira, &bin_op_instruction->base.base, maybe_op);
1511316154
1511416155 if (op_id == IrBinOpCmpEq) {
15115 IrInstruction *result = ir_build_bool_not(&ira->new_irb, bin_op_instruction->base.scope,
15116 bin_op_instruction->base.source_node, is_non_null);
15117 result->value->type = ira->codegen->builtin_types.entry_bool;
15118 return result;
16156 return ir_build_bool_not_gen(ira, &bin_op_instruction->base.base, is_non_null);
1511916157 } else {
1512016158 return is_non_null;
1512116159 }
......@@ -15125,7 +16163,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1512516163 (op2->value->type->id == ZigTypeIdNull && op1->value->type->id == ZigTypeIdPointer &&
1512616164 op1->value->type->data.pointer.ptr_len == PtrLenC)))
1512716165 {
15128 IrInstruction *c_ptr_op;
16166 IrInstGen *c_ptr_op;
1512916167 if (op1->value->type->id == ZigTypeIdNull) {
1513016168 c_ptr_op = op2;
1513116169 } else if (op2->value->type->id == ZigTypeIdNull) {
......@@ -15136,24 +16174,19 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1513616174 if (instr_is_comptime(c_ptr_op)) {
1513716175 ZigValue *c_ptr_val = ir_resolve_const(ira, c_ptr_op, UndefOk);
1513816176 if (!c_ptr_val)
15139 return ira->codegen->invalid_instruction;
16177 return ira->codegen->invalid_inst_gen;
1514016178 if (c_ptr_val->special == ConstValSpecialUndef)
15141 return ir_const_undef(ira, &bin_op_instruction->base, ira->codegen->builtin_types.entry_bool);
16179 return ir_const_undef(ira, &bin_op_instruction->base.base, ira->codegen->builtin_types.entry_bool);
1514216180 bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull ||
1514316181 (c_ptr_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&
1514416182 c_ptr_val->data.x_ptr.data.hard_coded_addr.addr == 0);
1514516183 bool bool_result = (op_id == IrBinOpCmpEq) ? is_null : !is_null;
15146 return ir_const_bool(ira, &bin_op_instruction->base, bool_result);
16184 return ir_const_bool(ira, &bin_op_instruction->base.base, bool_result);
1514716185 }
15148 IrInstruction *is_non_null = ir_build_test_nonnull(&ira->new_irb, bin_op_instruction->base.scope,
15149 source_node, c_ptr_op);
15150 is_non_null->value->type = ira->codegen->builtin_types.entry_bool;
16186 IrInstGen *is_non_null = ir_build_test_non_null_gen(ira, &bin_op_instruction->base.base, c_ptr_op);
1515116187
1515216188 if (op_id == IrBinOpCmpEq) {
15153 IrInstruction *result = ir_build_bool_not(&ira->new_irb, bin_op_instruction->base.scope,
15154 bin_op_instruction->base.source_node, is_non_null);
15155 result->value->type = ira->codegen->builtin_types.entry_bool;
15156 return result;
16189 return ir_build_bool_not_gen(ira, &bin_op_instruction->base.base, is_non_null);
1515716190 } else {
1515816191 return is_non_null;
1515916192 }
......@@ -15161,61 +16194,57 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1516116194 ZigType *non_null_type = (op1->value->type->id == ZigTypeIdNull) ? op2->value->type : op1->value->type;
1516216195 ir_add_error_node(ira, source_node, buf_sprintf("comparison of '%s' with null",
1516316196 buf_ptr(&non_null_type->name)));
15164 return ira->codegen->invalid_instruction;
16197 return ira->codegen->invalid_inst_gen;
1516516198 } else if (is_equality_cmp && (
1516616199 (op1->value->type->id == ZigTypeIdEnumLiteral && op2->value->type->id == ZigTypeIdUnion) ||
1516716200 (op2->value->type->id == ZigTypeIdEnumLiteral && op1->value->type->id == ZigTypeIdUnion)))
1516816201 {
1516916202 // Support equality comparison between a union's tag value and a enum literal
15170 IrInstruction *union_val = op1->value->type->id == ZigTypeIdUnion ? op1 : op2;
15171 IrInstruction *enum_val = op1->value->type->id == ZigTypeIdUnion ? op2 : op1;
16203 IrInstGen *union_val = op1->value->type->id == ZigTypeIdUnion ? op1 : op2;
16204 IrInstGen *enum_val = op1->value->type->id == ZigTypeIdUnion ? op2 : op1;
1517216205
1517316206 ZigType *tag_type = union_val->value->type->data.unionation.tag_type;
1517416207 assert(tag_type != nullptr);
1517516208
15176 IrInstruction *casted_union = ir_implicit_cast(ira, union_val, tag_type);
16209 IrInstGen *casted_union = ir_implicit_cast(ira, union_val, tag_type);
1517716210 if (type_is_invalid(casted_union->value->type))
15178 return ira->codegen->invalid_instruction;
16211 return ira->codegen->invalid_inst_gen;
1517916212
15180 IrInstruction *casted_val = ir_implicit_cast(ira, enum_val, tag_type);
16213 IrInstGen *casted_val = ir_implicit_cast(ira, enum_val, tag_type);
1518116214 if (type_is_invalid(casted_val->value->type))
15182 return ira->codegen->invalid_instruction;
16215 return ira->codegen->invalid_inst_gen;
1518316216
1518416217 if (instr_is_comptime(casted_union)) {
1518516218 ZigValue *const_union_val = ir_resolve_const(ira, casted_union, UndefBad);
1518616219 if (!const_union_val)
15187 return ira->codegen->invalid_instruction;
16220 return ira->codegen->invalid_inst_gen;
1518816221
1518916222 ZigValue *const_enum_val = ir_resolve_const(ira, casted_val, UndefBad);
1519016223 if (!const_enum_val)
15191 return ira->codegen->invalid_instruction;
16224 return ira->codegen->invalid_inst_gen;
1519216225
1519316226 Cmp cmp_result = bigint_cmp(&const_union_val->data.x_union.tag, &const_enum_val->data.x_enum_tag);
1519416227 bool bool_result = (op_id == IrBinOpCmpEq) ? cmp_result == CmpEQ : cmp_result != CmpEQ;
1519516228
15196 return ir_const_bool(ira, &bin_op_instruction->base, bool_result);
16229 return ir_const_bool(ira, &bin_op_instruction->base.base, bool_result);
1519716230 }
1519816231
15199 IrInstruction *result = ir_build_bin_op(&ira->new_irb,
15200 bin_op_instruction->base.scope, bin_op_instruction->base.source_node,
16232 return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, ira->codegen->builtin_types.entry_bool,
1520116233 op_id, casted_union, casted_val, bin_op_instruction->safety_check_on);
15202 result->value->type = ira->codegen->builtin_types.entry_bool;
15203
15204 return result;
1520516234 }
1520616235
1520716236 if (op1->value->type->id == ZigTypeIdErrorSet && op2->value->type->id == ZigTypeIdErrorSet) {
1520816237 if (!is_equality_cmp) {
1520916238 ir_add_error_node(ira, source_node, buf_sprintf("operator not allowed for errors"));
15210 return ira->codegen->invalid_instruction;
16239 return ira->codegen->invalid_inst_gen;
1521116240 }
1521216241 ZigType *intersect_type = get_error_set_intersection(ira, op1->value->type, op2->value->type, source_node);
1521316242 if (type_is_invalid(intersect_type)) {
15214 return ira->codegen->invalid_instruction;
16243 return ira->codegen->invalid_inst_gen;
1521516244 }
1521616245
1521716246 if (!resolve_inferred_error_set(ira->codegen, intersect_type, source_node)) {
15218 return ira->codegen->invalid_instruction;
16247 return ira->codegen->invalid_inst_gen;
1521916248 }
1522016249
1522116250 // exception if one of the operators has the type of the empty error set, we allow the comparison
......@@ -15232,7 +16261,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1523216261 } else {
1523316262 zig_unreachable();
1523416263 }
15235 return ir_const_bool(ira, &bin_op_instruction->base, answer);
16264 return ir_const_bool(ira, &bin_op_instruction->base.base, answer);
1523616265 }
1523716266
1523816267 if (!type_is_global_error_set(intersect_type)) {
......@@ -15240,7 +16269,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1524016269 ir_add_error_node(ira, source_node,
1524116270 buf_sprintf("error sets '%s' and '%s' have no common errors",
1524216271 buf_ptr(&op1->value->type->name), buf_ptr(&op2->value->type->name)));
15243 return ira->codegen->invalid_instruction;
16272 return ira->codegen->invalid_inst_gen;
1524416273 }
1524516274 if (op1->value->type->data.error_set.err_count == 1 && op2->value->type->data.error_set.err_count == 1) {
1524616275 bool are_equal = true;
......@@ -15252,17 +16281,17 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1525216281 } else {
1525316282 zig_unreachable();
1525416283 }
15255 return ir_const_bool(ira, &bin_op_instruction->base, answer);
16284 return ir_const_bool(ira, &bin_op_instruction->base.base, answer);
1525616285 }
1525716286 }
1525816287
1525916288 if (instr_is_comptime(op1) && instr_is_comptime(op2)) {
1526016289 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
1526116290 if (op1_val == nullptr)
15262 return ira->codegen->invalid_instruction;
16291 return ira->codegen->invalid_inst_gen;
1526316292 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);
1526416293 if (op2_val == nullptr)
15265 return ira->codegen->invalid_instruction;
16294 return ira->codegen->invalid_inst_gen;
1526616295
1526716296 bool answer;
1526816297 bool are_equal = op1_val->data.x_err_set->value == op2_val->data.x_err_set->value;
......@@ -15274,27 +16303,24 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1527416303 zig_unreachable();
1527516304 }
1527616305
15277 return ir_const_bool(ira, &bin_op_instruction->base, answer);
16306 return ir_const_bool(ira, &bin_op_instruction->base.base, answer);
1527816307 }
1527916308
15280 IrInstruction *result = ir_build_bin_op(&ira->new_irb,
15281 bin_op_instruction->base.scope, bin_op_instruction->base.source_node,
16309 return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, ira->codegen->builtin_types.entry_bool,
1528216310 op_id, op1, op2, bin_op_instruction->safety_check_on);
15283 result->value->type = ira->codegen->builtin_types.entry_bool;
15284 return result;
1528516311 }
1528616312
1528716313 if (type_is_numeric(op1->value->type) && type_is_numeric(op2->value->type)) {
1528816314 // This operation allows any combination of integer and float types, regardless of the
1528916315 // signed-ness, comptime-ness, and bit-width. So peer type resolution is incorrect for
1529016316 // numeric types.
15291 return ir_analyze_bin_op_cmp_numeric(ira, &bin_op_instruction->base, op1, op2, op_id);
16317 return ir_analyze_bin_op_cmp_numeric(ira, &bin_op_instruction->base.base, op1, op2, op_id);
1529216318 }
1529316319
15294 IrInstruction *instructions[] = {op1, op2};
16320 IrInstGen *instructions[] = {op1, op2};
1529516321 ZigType *resolved_type = ir_resolve_peer_types(ira, source_node, nullptr, instructions, 2);
1529616322 if (type_is_invalid(resolved_type))
15297 return ira->codegen->invalid_instruction;
16323 return ira->codegen->invalid_inst_gen;
1529816324
1529916325 bool operator_allowed;
1530016326 switch (resolved_type->id) {
......@@ -15342,21 +16368,21 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1534216368 if (!operator_allowed) {
1534316369 ir_add_error_node(ira, source_node,
1534416370 buf_sprintf("operator not allowed for type '%s'", buf_ptr(&resolved_type->name)));
15345 return ira->codegen->invalid_instruction;
16371 return ira->codegen->invalid_inst_gen;
1534616372 }
1534716373
15348 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, resolved_type);
15349 if (casted_op1 == ira->codegen->invalid_instruction)
15350 return ira->codegen->invalid_instruction;
16374 IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, resolved_type);
16375 if (type_is_invalid(casted_op1->value->type))
16376 return ira->codegen->invalid_inst_gen;
1535116377
15352 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, resolved_type);
15353 if (casted_op2 == ira->codegen->invalid_instruction)
15354 return ira->codegen->invalid_instruction;
16378 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, resolved_type);
16379 if (type_is_invalid(casted_op2->value->type))
16380 return ira->codegen->invalid_inst_gen;
1535516381
1535616382 bool one_possible_value;
1535716383 switch (type_has_one_possible_value(ira->codegen, resolved_type)) {
1535816384 case OnePossibleValueInvalid:
15359 return ira->codegen->invalid_instruction;
16385 return ira->codegen->invalid_inst_gen;
1536016386 case OnePossibleValueYes:
1536116387 one_possible_value = true;
1536216388 break;
......@@ -15368,20 +16394,20 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1536816394 if (one_possible_value || (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2))) {
1536916395 ZigValue *op1_val = one_possible_value ? casted_op1->value : ir_resolve_const(ira, casted_op1, UndefBad);
1537016396 if (op1_val == nullptr)
15371 return ira->codegen->invalid_instruction;
16397 return ira->codegen->invalid_inst_gen;
1537216398 ZigValue *op2_val = one_possible_value ? casted_op2->value : ir_resolve_const(ira, casted_op2, UndefBad);
1537316399 if (op2_val == nullptr)
15374 return ira->codegen->invalid_instruction;
16400 return ira->codegen->invalid_inst_gen;
1537516401 if (resolved_type->id != ZigTypeIdVector)
1537616402 return ir_evaluate_bin_op_cmp(ira, resolved_type, op1_val, op2_val, bin_op_instruction, op_id, one_possible_value);
15377 IrInstruction *result = ir_const(ira, &bin_op_instruction->base,
16403 IrInstGen *result = ir_const(ira, &bin_op_instruction->base.base,
1537816404 get_vector_type(ira->codegen, resolved_type->data.vector.len, ira->codegen->builtin_types.entry_bool));
1537916405 result->value->data.x_array.data.s_none.elements =
1538016406 create_const_vals(resolved_type->data.vector.len);
1538116407
1538216408 expand_undef_array(ira->codegen, result->value);
1538316409 for (size_t i = 0;i < resolved_type->data.vector.len;i++) {
15384 IrInstruction *cur_res = ir_evaluate_bin_op_cmp(ira, resolved_type->data.vector.elem_type,
16410 IrInstGen *cur_res = ir_evaluate_bin_op_cmp(ira, resolved_type->data.vector.elem_type,
1538516411 &op1_val->data.x_array.data.s_none.elements[i],
1538616412 &op2_val->data.x_array.data.s_none.elements[i],
1538716413 bin_op_instruction, op_id, one_possible_value);
......@@ -15390,19 +16416,14 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1539016416 return result;
1539116417 }
1539216418
15393 IrInstruction *result = ir_build_bin_op(&ira->new_irb,
15394 bin_op_instruction->base.scope, bin_op_instruction->base.source_node,
16419 ZigType *res_type = (resolved_type->id == ZigTypeIdVector) ?
16420 get_vector_type(ira->codegen, resolved_type->data.vector.len, ira->codegen->builtin_types.entry_bool) :
16421 ira->codegen->builtin_types.entry_bool;
16422 return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, res_type,
1539516423 op_id, casted_op1, casted_op2, bin_op_instruction->safety_check_on);
15396 if (resolved_type->id == ZigTypeIdVector) {
15397 result->value->type = get_vector_type(ira->codegen, resolved_type->data.vector.len,
15398 ira->codegen->builtin_types.entry_bool);
15399 } else {
15400 result->value->type = ira->codegen->builtin_types.entry_bool;
15401 }
15402 return result;
1540316424}
1540416425
15405static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInstruction *source_instr, ZigType *type_entry,
16426static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInst* source_instr, ZigType *type_entry,
1540616427 ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val, ZigValue *out_val)
1540716428{
1540816429 bool is_int;
......@@ -15582,10 +16603,10 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInstruction *source_in
1558216603}
1558316604
1558416605// This works on operands that have already been checked to be comptime known.
15585static IrInstruction *ir_analyze_math_op(IrAnalyze *ira, IrInstruction *source_instr,
16606static IrInstGen *ir_analyze_math_op(IrAnalyze *ira, IrInst* source_instr,
1558616607 ZigType *type_entry, ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val)
1558716608{
15588 IrInstruction *result_instruction = ir_const(ira, source_instr, type_entry);
16609 IrInstGen *result_instruction = ir_const(ira, source_instr, type_entry);
1558916610 ZigValue *out_val = result_instruction->value;
1559016611 if (type_entry->id == ZigTypeIdVector) {
1559116612 expand_undef_array(ira->codegen, op1_val);
......@@ -15606,43 +16627,43 @@ static IrInstruction *ir_analyze_math_op(IrAnalyze *ira, IrInstruction *source_i
1560616627 if (msg != nullptr) {
1560716628 add_error_note(ira->codegen, msg, source_instr->source_node,
1560816629 buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i));
15609 return ira->codegen->invalid_instruction;
16630 return ira->codegen->invalid_inst_gen;
1561016631 }
1561116632 }
1561216633 out_val->type = type_entry;
1561316634 out_val->special = ConstValSpecialStatic;
1561416635 } else {
1561516636 if (ir_eval_math_op_scalar(ira, source_instr, type_entry, op1_val, op_id, op2_val, out_val) != nullptr) {
15616 return ira->codegen->invalid_instruction;
16637 return ira->codegen->invalid_inst_gen;
1561716638 }
1561816639 }
1561916640 return ir_implicit_cast(ira, result_instruction, type_entry);
1562016641}
1562116642
15622static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
15623 IrInstruction *op1 = bin_op_instruction->op1->child;
16643static IrInstGen *ir_analyze_bit_shift(IrAnalyze *ira, IrInstSrcBinOp *bin_op_instruction) {
16644 IrInstGen *op1 = bin_op_instruction->op1->child;
1562416645 if (type_is_invalid(op1->value->type))
15625 return ira->codegen->invalid_instruction;
16646 return ira->codegen->invalid_inst_gen;
1562616647
1562716648 if (op1->value->type->id != ZigTypeIdInt && op1->value->type->id != ZigTypeIdComptimeInt) {
15628 ir_add_error(ira, bin_op_instruction->op1,
16649 ir_add_error(ira, &bin_op_instruction->op1->base,
1562916650 buf_sprintf("bit shifting operation expected integer type, found '%s'",
1563016651 buf_ptr(&op1->value->type->name)));
15631 return ira->codegen->invalid_instruction;
16652 return ira->codegen->invalid_inst_gen;
1563216653 }
1563316654
15634 IrInstruction *op2 = bin_op_instruction->op2->child;
16655 IrInstGen *op2 = bin_op_instruction->op2->child;
1563516656 if (type_is_invalid(op2->value->type))
15636 return ira->codegen->invalid_instruction;
16657 return ira->codegen->invalid_inst_gen;
1563716658
1563816659 if (op2->value->type->id != ZigTypeIdInt && op2->value->type->id != ZigTypeIdComptimeInt) {
15639 ir_add_error(ira, bin_op_instruction->op2,
16660 ir_add_error(ira, &bin_op_instruction->op2->base,
1564016661 buf_sprintf("shift amount has to be an integer type, but found '%s'",
1564116662 buf_ptr(&op2->value->type->name)));
15642 return ira->codegen->invalid_instruction;
16663 return ira->codegen->invalid_inst_gen;
1564316664 }
1564416665
15645 IrInstruction *casted_op2;
16666 IrInstGen *casted_op2;
1564616667 IrBinOp op_id = bin_op_instruction->op_id;
1564716668 if (op1->value->type->id == ZigTypeIdComptimeInt) {
1564816669 casted_op2 = op2;
......@@ -15654,8 +16675,8 @@ static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *b
1565416675 if (casted_op2->value->data.x_bigint.is_negative) {
1565516676 Buf *val_buf = buf_alloc();
1565616677 bigint_append_buf(val_buf, &casted_op2->value->data.x_bigint, 10);
15657 ir_add_error(ira, casted_op2, buf_sprintf("shift by negative value %s", buf_ptr(val_buf)));
15658 return ira->codegen->invalid_instruction;
16678 ir_add_error(ira, &casted_op2->base, buf_sprintf("shift by negative value %s", buf_ptr(val_buf)));
16679 return ira->codegen->invalid_inst_gen;
1565916680 }
1566016681 } else {
1566116682 ZigType *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen,
......@@ -15665,57 +16686,51 @@ static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *b
1566516686
1566616687 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);
1566716688 if (op2_val == nullptr)
15668 return ira->codegen->invalid_instruction;
16689 return ira->codegen->invalid_inst_gen;
1566916690 if (!bigint_fits_in_bits(&op2_val->data.x_bigint,
1567016691 shift_amt_type->data.integral.bit_count,
1567116692 op2_val->data.x_bigint.is_negative)) {
1567216693 Buf *val_buf = buf_alloc();
1567316694 bigint_append_buf(val_buf, &op2_val->data.x_bigint, 10);
1567416695 ErrorMsg* msg = ir_add_error(ira,
15675 &bin_op_instruction->base,
16696 &bin_op_instruction->base.base,
1567616697 buf_sprintf("RHS of shift is too large for LHS type"));
1567716698 add_error_note(
1567816699 ira->codegen,
1567916700 msg,
15680 op2->source_node,
16701 op2->base.source_node,
1568116702 buf_sprintf("value %s cannot fit into type %s",
1568216703 buf_ptr(val_buf),
1568316704 buf_ptr(&shift_amt_type->name)));
15684 return ira->codegen->invalid_instruction;
16705 return ira->codegen->invalid_inst_gen;
1568516706 }
1568616707 }
1568716708
1568816709 casted_op2 = ir_implicit_cast(ira, op2, shift_amt_type);
15689 if (casted_op2 == ira->codegen->invalid_instruction)
15690 return ira->codegen->invalid_instruction;
16710 if (type_is_invalid(casted_op2->value->type))
16711 return ira->codegen->invalid_inst_gen;
1569116712 }
1569216713
1569316714 if (instr_is_comptime(op1) && instr_is_comptime(casted_op2)) {
1569416715 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
1569516716 if (op1_val == nullptr)
15696 return ira->codegen->invalid_instruction;
16717 return ira->codegen->invalid_inst_gen;
1569716718
1569816719 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
1569916720 if (op2_val == nullptr)
15700 return ira->codegen->invalid_instruction;
16721 return ira->codegen->invalid_inst_gen;
1570116722
15702 return ir_analyze_math_op(ira, &bin_op_instruction->base, op1->value->type, op1_val, op_id, op2_val);
16723 return ir_analyze_math_op(ira, &bin_op_instruction->base.base, op1->value->type, op1_val, op_id, op2_val);
1570316724 } else if (op1->value->type->id == ZigTypeIdComptimeInt) {
15704 ir_add_error(ira, &bin_op_instruction->base,
16725 ir_add_error(ira, &bin_op_instruction->base.base,
1570516726 buf_sprintf("LHS of shift must be an integer type, or RHS must be compile-time known"));
15706 return ira->codegen->invalid_instruction;
16727 return ira->codegen->invalid_inst_gen;
1570716728 } else if (instr_is_comptime(casted_op2) && bigint_cmp_zero(&casted_op2->value->data.x_bigint) == CmpEQ) {
15708 IrInstruction *result = ir_build_cast(&ira->new_irb, bin_op_instruction->base.scope,
15709 bin_op_instruction->base.source_node, op1->value->type, op1, CastOpNoop);
15710 result->value->type = op1->value->type;
15711 return result;
16729 return ir_build_cast(ira, &bin_op_instruction->base.base, op1->value->type, op1, CastOpNoop);
1571216730 }
1571316731
15714 IrInstruction *result = ir_build_bin_op(&ira->new_irb, bin_op_instruction->base.scope,
15715 bin_op_instruction->base.source_node, op_id,
15716 op1, casted_op2, bin_op_instruction->safety_check_on);
15717 result->value->type = op1->value->type;
15718 return result;
16732 return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, op1->value->type,
16733 op_id, op1, casted_op2, bin_op_instruction->safety_check_on);
1571916734}
1572016735
1572116736static bool ok_float_op(IrBinOp op) {
......@@ -15779,24 +16794,24 @@ static bool is_pointer_arithmetic_allowed(ZigType *lhs_type, IrBinOp op) {
1577916794 zig_unreachable();
1578016795}
1578116796
15782static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *instruction) {
16797static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruction) {
1578316798 Error err;
1578416799
15785 IrInstruction *op1 = instruction->op1->child;
16800 IrInstGen *op1 = instruction->op1->child;
1578616801 if (type_is_invalid(op1->value->type))
15787 return ira->codegen->invalid_instruction;
16802 return ira->codegen->invalid_inst_gen;
1578816803
15789 IrInstruction *op2 = instruction->op2->child;
16804 IrInstGen *op2 = instruction->op2->child;
1579016805 if (type_is_invalid(op2->value->type))
15791 return ira->codegen->invalid_instruction;
16806 return ira->codegen->invalid_inst_gen;
1579216807
1579316808 IrBinOp op_id = instruction->op_id;
1579416809
1579516810 // look for pointer math
1579616811 if (is_pointer_arithmetic_allowed(op1->value->type, op_id)) {
15797 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, ira->codegen->builtin_types.entry_usize);
16812 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, ira->codegen->builtin_types.entry_usize);
1579816813 if (type_is_invalid(casted_op2->value->type))
15799 return ira->codegen->invalid_instruction;
16814 return ira->codegen->invalid_inst_gen;
1580016815
1580116816 // If either operand is undef, result is undef.
1580216817 ZigValue *op1_val = nullptr;
......@@ -15804,28 +16819,28 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1580416819 if (instr_is_comptime(op1)) {
1580516820 op1_val = ir_resolve_const(ira, op1, UndefOk);
1580616821 if (op1_val == nullptr)
15807 return ira->codegen->invalid_instruction;
16822 return ira->codegen->invalid_inst_gen;
1580816823 if (op1_val->special == ConstValSpecialUndef)
15809 return ir_const_undef(ira, &instruction->base, op1->value->type);
16824 return ir_const_undef(ira, &instruction->base.base, op1->value->type);
1581016825 }
1581116826 if (instr_is_comptime(casted_op2)) {
1581216827 op2_val = ir_resolve_const(ira, casted_op2, UndefOk);
1581316828 if (op2_val == nullptr)
15814 return ira->codegen->invalid_instruction;
16829 return ira->codegen->invalid_inst_gen;
1581516830 if (op2_val->special == ConstValSpecialUndef)
15816 return ir_const_undef(ira, &instruction->base, op1->value->type);
16831 return ir_const_undef(ira, &instruction->base.base, op1->value->type);
1581716832 }
1581816833
1581916834 ZigType *elem_type = op1->value->type->data.pointer.child_type;
1582016835 if ((err = type_resolve(ira->codegen, elem_type, ResolveStatusSizeKnown)))
15821 return ira->codegen->invalid_instruction;
16836 return ira->codegen->invalid_inst_gen;
1582216837
1582316838 // NOTE: this variable is meaningful iff op2_val is not null!
1582416839 uint64_t byte_offset;
1582516840 if (op2_val != nullptr) {
1582616841 uint64_t elem_offset;
1582716842 if (!ir_resolve_usize(ira, casted_op2, &elem_offset))
15828 return ira->codegen->invalid_instruction;
16843 return ira->codegen->invalid_inst_gen;
1582916844
1583016845 byte_offset = type_size(ira->codegen, elem_type) * elem_offset;
1583116846 }
......@@ -15840,7 +16855,7 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1584016855 {
1584116856 uint32_t align_bytes;
1584216857 if ((err = resolve_ptr_align(ira, op1->value->type, &align_bytes)))
15843 return ira->codegen->invalid_instruction;
16858 return ira->codegen->invalid_inst_gen;
1584416859
1584516860 // If the addend is not a comptime-known value we can still count on
1584616861 // it being a multiple of the type size
......@@ -15869,23 +16884,20 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1586916884 } else {
1587016885 zig_unreachable();
1587116886 }
15872 IrInstruction *result = ir_const(ira, &instruction->base, result_type);
16887 IrInstGen *result = ir_const(ira, &instruction->base.base, result_type);
1587316888 result->value->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
1587416889 result->value->data.x_ptr.mut = ConstPtrMutRuntimeVar;
1587516890 result->value->data.x_ptr.data.hard_coded_addr.addr = new_addr;
1587616891 return result;
1587716892 }
1587816893
15879 IrInstruction *result = ir_build_bin_op(&ira->new_irb, instruction->base.scope,
15880 instruction->base.source_node, op_id, op1, casted_op2, true);
15881 result->value->type = result_type;
15882 return result;
16894 return ir_build_bin_op_gen(ira, &instruction->base.base, result_type, op_id, op1, casted_op2, true);
1588316895 }
1588416896
15885 IrInstruction *instructions[] = {op1, op2};
15886 ZigType *resolved_type = ir_resolve_peer_types(ira, instruction->base.source_node, nullptr, instructions, 2);
16897 IrInstGen *instructions[] = {op1, op2};
16898 ZigType *resolved_type = ir_resolve_peer_types(ira, instruction->base.base.source_node, nullptr, instructions, 2);
1588716899 if (type_is_invalid(resolved_type))
15888 return ira->codegen->invalid_instruction;
16900 return ira->codegen->invalid_inst_gen;
1588916901
1589016902 bool is_int = resolved_type->id == ZigTypeIdInt || resolved_type->id == ZigTypeIdComptimeInt;
1589116903 bool is_float = resolved_type->id == ZigTypeIdFloat || resolved_type->id == ZigTypeIdComptimeFloat;
......@@ -15905,11 +16917,11 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1590516917 if (instr_is_comptime(op1) && instr_is_comptime(op2)) {
1590616918 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
1590716919 if (op1_val == nullptr)
15908 return ira->codegen->invalid_instruction;
16920 return ira->codegen->invalid_inst_gen;
1590916921
1591016922 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);
1591116923 if (op2_val == nullptr)
15912 return ira->codegen->invalid_instruction;
16924 return ira->codegen->invalid_inst_gen;
1591316925
1591416926 if (bigint_cmp_zero(&op2_val->data.x_bigint) == CmpEQ) {
1591516927 // the division by zero error will be caught later, but we don't have a
......@@ -15928,11 +16940,11 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1592816940 }
1592916941 }
1593016942 if (!ok) {
15931 ir_add_error(ira, &instruction->base,
16943 ir_add_error(ira, &instruction->base.base,
1593216944 buf_sprintf("division with '%s' and '%s': signed integers must use @divTrunc, @divFloor, or @divExact",
1593316945 buf_ptr(&op1->value->type->name),
1593416946 buf_ptr(&op2->value->type->name)));
15935 return ira->codegen->invalid_instruction;
16947 return ira->codegen->invalid_inst_gen;
1593616948 }
1593716949 } else {
1593816950 op_id = IrBinOpDivTrunc;
......@@ -15943,12 +16955,12 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1594316955 if (instr_is_comptime(op1) && instr_is_comptime(op2)) {
1594416956 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
1594516957 if (op1_val == nullptr)
15946 return ira->codegen->invalid_instruction;
16958 return ira->codegen->invalid_inst_gen;
1594716959
1594816960 if (is_int) {
1594916961 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);
1595016962 if (op2_val == nullptr)
15951 return ira->codegen->invalid_instruction;
16963 return ira->codegen->invalid_inst_gen;
1595216964
1595316965 if (bigint_cmp_zero(&op2->value->data.x_bigint) == CmpEQ) {
1595416966 // the division by zero error will be caught later, but we don't
......@@ -15962,13 +16974,13 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1596216974 ok = bigint_cmp(&rem_result, &mod_result) == CmpEQ;
1596316975 }
1596416976 } else {
15965 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, resolved_type);
15966 if (casted_op2 == ira->codegen->invalid_instruction)
15967 return ira->codegen->invalid_instruction;
16977 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, resolved_type);
16978 if (type_is_invalid(casted_op2->value->type))
16979 return ira->codegen->invalid_inst_gen;
1596816980
1596916981 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
1597016982 if (op2_val == nullptr)
15971 return ira->codegen->invalid_instruction;
16983 return ira->codegen->invalid_inst_gen;
1597216984
1597316985 if (float_cmp_zero(casted_op2->value) == CmpEQ) {
1597416986 // the division by zero error will be caught later, but we don't
......@@ -15984,11 +16996,11 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1598416996 }
1598516997 }
1598616998 if (!ok) {
15987 ir_add_error(ira, &instruction->base,
16999 ir_add_error(ira, &instruction->base.base,
1598817000 buf_sprintf("remainder division with '%s' and '%s': signed integers and floats must use @rem or @mod",
1598917001 buf_ptr(&op1->value->type->name),
1599017002 buf_ptr(&op2->value->type->name)));
15991 return ira->codegen->invalid_instruction;
17003 return ira->codegen->invalid_inst_gen;
1599217004 }
1599317005 }
1599417006 op_id = IrBinOpRemRem;
......@@ -16008,12 +17020,12 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1600817020 }
1600917021 }
1601017022 if (!ok) {
16011 AstNode *source_node = instruction->base.source_node;
17023 AstNode *source_node = instruction->base.base.source_node;
1601217024 ir_add_error_node(ira, source_node,
1601317025 buf_sprintf("invalid operands to binary expression: '%s' and '%s'",
1601417026 buf_ptr(&op1->value->type->name),
1601517027 buf_ptr(&op2->value->type->name)));
16016 return ira->codegen->invalid_instruction;
17028 return ira->codegen->invalid_inst_gen;
1601717029 }
1601817030
1601917031 if (resolved_type->id == ZigTypeIdComptimeInt) {
......@@ -16026,33 +17038,31 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
1602617038 }
1602717039 }
1602817040
16029 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, resolved_type);
16030 if (casted_op1 == ira->codegen->invalid_instruction)
16031 return ira->codegen->invalid_instruction;
17041 IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, resolved_type);
17042 if (type_is_invalid(casted_op1->value->type))
17043 return ira->codegen->invalid_inst_gen;
1603217044
16033 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, resolved_type);
16034 if (casted_op2 == ira->codegen->invalid_instruction)
16035 return ira->codegen->invalid_instruction;
17045 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, resolved_type);
17046 if (type_is_invalid(casted_op2->value->type))
17047 return ira->codegen->invalid_inst_gen;
1603617048
1603717049 if (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2)) {
1603817050 ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);
1603917051 if (op1_val == nullptr)
16040 return ira->codegen->invalid_instruction;
17052 return ira->codegen->invalid_inst_gen;
1604117053 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
1604217054 if (op2_val == nullptr)
16043 return ira->codegen->invalid_instruction;
17055 return ira->codegen->invalid_inst_gen;
1604417056
16045 return ir_analyze_math_op(ira, &instruction->base, resolved_type, op1_val, op_id, op2_val);
17057 return ir_analyze_math_op(ira, &instruction->base.base, resolved_type, op1_val, op_id, op2_val);
1604617058 }
1604717059
16048 IrInstruction *result = ir_build_bin_op(&ira->new_irb, instruction->base.scope,
16049 instruction->base.source_node, op_id, casted_op1, casted_op2, instruction->safety_check_on);
16050 result->value->type = resolved_type;
16051 return result;
17060 return ir_build_bin_op_gen(ira, &instruction->base.base, resolved_type,
17061 op_id, casted_op1, casted_op2, instruction->safety_check_on);
1605217062}
1605317063
16054static IrInstruction *ir_analyze_tuple_cat(IrAnalyze *ira, IrInstruction *source_instr,
16055 IrInstruction *op1, IrInstruction *op2)
17064static IrInstGen *ir_analyze_tuple_cat(IrAnalyze *ira, IrInst* source_instr,
17065 IrInstGen *op1, IrInstGen *op2)
1605617066{
1605717067 Error err;
1605817068 ZigType *op1_type = op1->value->type;
......@@ -16069,9 +17079,9 @@ static IrInstruction *ir_analyze_tuple_cat(IrAnalyze *ira, IrInstruction *source
1606917079 new_type->data.structure.special = StructSpecialInferredTuple;
1607017080 new_type->data.structure.resolve_status = ResolveStatusBeingInferred;
1607117081
16072 bool is_comptime = ir_should_inline(ira->new_irb.exec, source_instr->scope);
17082 bool is_comptime = ir_should_inline(ira->old_irb.exec, source_instr->scope);
1607317083
16074 IrInstruction *new_struct_ptr = ir_resolve_result(ira, source_instr, no_result_loc(),
17084 IrInstGen *new_struct_ptr = ir_resolve_result(ira, source_instr, no_result_loc(),
1607517085 new_type, nullptr, false, false, true);
1607617086 uint32_t new_field_count = op1_field_count + op2_field_count;
1607717087
......@@ -16095,13 +17105,13 @@ static IrInstruction *ir_analyze_tuple_cat(IrAnalyze *ira, IrInstruction *source
1609517105 new_field->is_comptime = src_field->is_comptime;
1609617106 }
1609717107 if ((err = type_resolve(ira->codegen, new_type, ResolveStatusZeroBitsKnown)))
16098 return ira->codegen->invalid_instruction;
17108 return ira->codegen->invalid_inst_gen;
1609917109
16100 ZigList<IrInstruction *> const_ptrs = {};
16101 IrInstruction *first_non_const_instruction = nullptr;
17110 ZigList<IrInstGen *> const_ptrs = {};
17111 IrInstGen *first_non_const_instruction = nullptr;
1610217112 for (uint32_t i = 0; i < new_field_count; i += 1) {
1610317113 TypeStructField *dst_field = new_type->data.structure.fields[i];
16104 IrInstruction *src_struct_op;
17114 IrInstGen *src_struct_op;
1610517115 TypeStructField *src_field;
1610617116 if (i < op1_field_count) {
1610717117 src_field = op1_type->data.structure.fields[i];
......@@ -16110,73 +17120,73 @@ static IrInstruction *ir_analyze_tuple_cat(IrAnalyze *ira, IrInstruction *source
1611017120 src_field = op2_type->data.structure.fields[i - op1_field_count];
1611117121 src_struct_op = op2;
1611217122 }
16113 IrInstruction *field_value = ir_analyze_struct_value_field_value(ira, source_instr,
17123 IrInstGen *field_value = ir_analyze_struct_value_field_value(ira, source_instr,
1611417124 src_struct_op, src_field);
1611517125 if (type_is_invalid(field_value->value->type))
16116 return ira->codegen->invalid_instruction;
16117 IrInstruction *dest_ptr = ir_analyze_struct_field_ptr(ira, source_instr, dst_field,
17126 return ira->codegen->invalid_inst_gen;
17127 IrInstGen *dest_ptr = ir_analyze_struct_field_ptr(ira, source_instr, dst_field,
1611817128 new_struct_ptr, new_type, true);
1611917129 if (type_is_invalid(dest_ptr->value->type))
16120 return ira->codegen->invalid_instruction;
17130 return ira->codegen->invalid_inst_gen;
1612117131 if (instr_is_comptime(field_value)) {
1612217132 const_ptrs.append(dest_ptr);
1612317133 } else {
1612417134 first_non_const_instruction = field_value;
1612517135 }
16126 IrInstruction *store_ptr_inst = ir_analyze_store_ptr(ira, source_instr, dest_ptr, field_value,
17136 IrInstGen *store_ptr_inst = ir_analyze_store_ptr(ira, source_instr, dest_ptr, field_value,
1612717137 true);
1612817138 if (type_is_invalid(store_ptr_inst->value->type))
16129 return ira->codegen->invalid_instruction;
17139 return ira->codegen->invalid_inst_gen;
1613017140 }
1613117141 if (const_ptrs.length != new_field_count) {
1613217142 new_struct_ptr->value->special = ConstValSpecialRuntime;
1613317143 for (size_t i = 0; i < const_ptrs.length; i += 1) {
16134 IrInstruction *elem_result_loc = const_ptrs.at(i);
17144 IrInstGen *elem_result_loc = const_ptrs.at(i);
1613517145 assert(elem_result_loc->value->special == ConstValSpecialStatic);
1613617146 if (elem_result_loc->value->type->data.pointer.inferred_struct_field != nullptr) {
1613717147 // This field will be generated comptime; no need to do this.
1613817148 continue;
1613917149 }
16140 IrInstruction *deref = ir_get_deref(ira, elem_result_loc, elem_result_loc, nullptr);
17150 IrInstGen *deref = ir_get_deref(ira, &elem_result_loc->base, elem_result_loc, nullptr);
1614117151 elem_result_loc->value->special = ConstValSpecialRuntime;
16142 ir_analyze_store_ptr(ira, elem_result_loc, elem_result_loc, deref, false);
17152 ir_analyze_store_ptr(ira, &elem_result_loc->base, elem_result_loc, deref, false);
1614317153 }
1614417154 }
16145 IrInstruction *result = ir_get_deref(ira, source_instr, new_struct_ptr, nullptr);
17155 IrInstGen *result = ir_get_deref(ira, source_instr, new_struct_ptr, nullptr);
1614617156 if (instr_is_comptime(result))
1614717157 return result;
1614817158
1614917159 if (is_comptime) {
16150 ir_add_error_node(ira, first_non_const_instruction->source_node,
17160 ir_add_error(ira, &first_non_const_instruction->base,
1615117161 buf_sprintf("unable to evaluate constant expression"));
16152 return ira->codegen->invalid_instruction;
17162 return ira->codegen->invalid_inst_gen;
1615317163 }
1615417164
1615517165 return result;
1615617166}
1615717167
16158static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruction) {
16159 IrInstruction *op1 = instruction->op1->child;
17168static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instruction) {
17169 IrInstGen *op1 = instruction->op1->child;
1616017170 ZigType *op1_type = op1->value->type;
1616117171 if (type_is_invalid(op1_type))
16162 return ira->codegen->invalid_instruction;
17172 return ira->codegen->invalid_inst_gen;
1616317173
16164 IrInstruction *op2 = instruction->op2->child;
17174 IrInstGen *op2 = instruction->op2->child;
1616517175 ZigType *op2_type = op2->value->type;
1616617176 if (type_is_invalid(op2_type))
16167 return ira->codegen->invalid_instruction;
17177 return ira->codegen->invalid_inst_gen;
1616817178
1616917179 if (is_tuple(op1_type) && is_tuple(op2_type)) {
16170 return ir_analyze_tuple_cat(ira, &instruction->base, op1, op2);
17180 return ir_analyze_tuple_cat(ira, &instruction->base.base, op1, op2);
1617117181 }
1617217182
1617317183 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
1617417184 if (!op1_val)
16175 return ira->codegen->invalid_instruction;
17185 return ira->codegen->invalid_inst_gen;
1617617186
1617717187 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);
1617817188 if (!op2_val)
16179 return ira->codegen->invalid_instruction;
17189 return ira->codegen->invalid_inst_gen;
1618017190
1618117191 ZigValue *sentinel1 = nullptr;
1618217192 ZigValue *op1_array_val;
......@@ -16214,15 +17224,15 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1621417224 {
1621517225 ZigType *array_type = op1_type->data.pointer.child_type;
1621617226 child_type = array_type->data.array.child_type;
16217 op1_array_val = const_ptr_pointee(ira, ira->codegen, op1_val, op1->source_node);
17227 op1_array_val = const_ptr_pointee(ira, ira->codegen, op1_val, op1->base.source_node);
1621817228 if (op1_array_val == nullptr)
16219 return ira->codegen->invalid_instruction;
17229 return ira->codegen->invalid_inst_gen;
1622017230 op1_array_index = 0;
1622117231 op1_array_end = array_type->data.array.len;
1622217232 sentinel1 = array_type->data.array.sentinel;
1622317233 } else {
16224 ir_add_error(ira, op1, buf_sprintf("expected array, found '%s'", buf_ptr(&op1->value->type->name)));
16225 return ira->codegen->invalid_instruction;
17234 ir_add_error(ira, &op1->base, buf_sprintf("expected array, found '%s'", buf_ptr(&op1->value->type->name)));
17235 return ira->codegen->invalid_inst_gen;
1622617236 }
1622717237
1622817238 ZigValue *sentinel2 = nullptr;
......@@ -16262,23 +17272,23 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1626217272 {
1626317273 ZigType *array_type = op2_type->data.pointer.child_type;
1626417274 op2_type_valid = array_type->data.array.child_type == child_type;
16265 op2_array_val = const_ptr_pointee(ira, ira->codegen, op2_val, op2->source_node);
17275 op2_array_val = const_ptr_pointee(ira, ira->codegen, op2_val, op2->base.source_node);
1626617276 if (op2_array_val == nullptr)
16267 return ira->codegen->invalid_instruction;
17277 return ira->codegen->invalid_inst_gen;
1626817278 op2_array_index = 0;
1626917279 op2_array_end = array_type->data.array.len;
1627017280
1627117281 sentinel2 = array_type->data.array.sentinel;
1627217282 } else {
16273 ir_add_error(ira, op2,
17283 ir_add_error(ira, &op2->base,
1627417284 buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op2->value->type->name)));
16275 return ira->codegen->invalid_instruction;
17285 return ira->codegen->invalid_inst_gen;
1627617286 }
1627717287 if (!op2_type_valid) {
16278 ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'",
17288 ir_add_error(ira, &op2->base, buf_sprintf("expected array of type '%s', found '%s'",
1627917289 buf_ptr(&child_type->name),
1628017290 buf_ptr(&op2->value->type->name)));
16281 return ira->codegen->invalid_instruction;
17291 return ira->codegen->invalid_inst_gen;
1628217292 }
1628317293
1628417294 ZigValue *sentinel;
......@@ -16295,7 +17305,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1629517305 }
1629617306
1629717307 // The type of result is populated in the following if blocks
16298 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
17308 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
1629917309 ZigValue *out_val = result->value;
1630017310
1630117311 ZigValue *out_array_val;
......@@ -16383,14 +17393,14 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1638317393 return result;
1638417394}
1638517395
16386static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *instruction) {
16387 IrInstruction *op1 = instruction->op1->child;
17396static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruction) {
17397 IrInstGen *op1 = instruction->op1->child;
1638817398 if (type_is_invalid(op1->value->type))
16389 return ira->codegen->invalid_instruction;
17399 return ira->codegen->invalid_inst_gen;
1639017400
16391 IrInstruction *op2 = instruction->op2->child;
17401 IrInstGen *op2 = instruction->op2->child;
1639217402 if (type_is_invalid(op2->value->type))
16393 return ira->codegen->invalid_instruction;
17403 return ira->codegen->invalid_inst_gen;
1639417404
1639517405 bool want_ptr_to_array = false;
1639617406 ZigType *array_type;
......@@ -16399,49 +17409,49 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *
1639917409 array_type = op1->value->type;
1640017410 array_val = ir_resolve_const(ira, op1, UndefOk);
1640117411 if (array_val == nullptr)
16402 return ira->codegen->invalid_instruction;
17412 return ira->codegen->invalid_inst_gen;
1640317413 } else if (op1->value->type->id == ZigTypeIdPointer && op1->value->type->data.pointer.ptr_len == PtrLenSingle &&
1640417414 op1->value->type->data.pointer.child_type->id == ZigTypeIdArray)
1640517415 {
1640617416 array_type = op1->value->type->data.pointer.child_type;
16407 IrInstruction *array_inst = ir_get_deref(ira, op1, op1, nullptr);
17417 IrInstGen *array_inst = ir_get_deref(ira, &op1->base, op1, nullptr);
1640817418 if (type_is_invalid(array_inst->value->type))
16409 return ira->codegen->invalid_instruction;
17419 return ira->codegen->invalid_inst_gen;
1641017420 array_val = ir_resolve_const(ira, array_inst, UndefOk);
1641117421 if (array_val == nullptr)
16412 return ira->codegen->invalid_instruction;
17422 return ira->codegen->invalid_inst_gen;
1641317423 want_ptr_to_array = true;
1641417424 } else {
16415 ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value->type->name)));
16416 return ira->codegen->invalid_instruction;
17425 ir_add_error(ira, &op1->base, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value->type->name)));
17426 return ira->codegen->invalid_inst_gen;
1641717427 }
1641817428
1641917429 uint64_t mult_amt;
1642017430 if (!ir_resolve_usize(ira, op2, &mult_amt))
16421 return ira->codegen->invalid_instruction;
17431 return ira->codegen->invalid_inst_gen;
1642217432
1642317433 uint64_t old_array_len = array_type->data.array.len;
1642417434 uint64_t new_array_len;
1642517435
1642617436 if (mul_u64_overflow(old_array_len, mult_amt, &new_array_len)) {
16427 ir_add_error(ira, &instruction->base, buf_sprintf("operation results in overflow"));
16428 return ira->codegen->invalid_instruction;
17437 ir_add_error(ira, &instruction->base.base, buf_sprintf("operation results in overflow"));
17438 return ira->codegen->invalid_inst_gen;
1642917439 }
1643017440
1643117441 ZigType *child_type = array_type->data.array.child_type;
1643217442 ZigType *result_array_type = get_array_type(ira->codegen, child_type, new_array_len,
1643317443 array_type->data.array.sentinel);
1643417444
16435 IrInstruction *array_result;
17445 IrInstGen *array_result;
1643617446 if (array_val->special == ConstValSpecialUndef || array_val->data.x_array.special == ConstArraySpecialUndef) {
16437 array_result = ir_const_undef(ira, &instruction->base, result_array_type);
17447 array_result = ir_const_undef(ira, &instruction->base.base, result_array_type);
1643817448 } else {
16439 array_result = ir_const(ira, &instruction->base, result_array_type);
17449 array_result = ir_const(ira, &instruction->base.base, result_array_type);
1644017450 ZigValue *out_val = array_result->value;
1644117451
1644217452 switch (type_has_one_possible_value(ira->codegen, result_array_type)) {
1644317453 case OnePossibleValueInvalid:
16444 return ira->codegen->invalid_instruction;
17454 return ira->codegen->invalid_inst_gen;
1644517455 case OnePossibleValueYes:
1644617456 goto skip_computation;
1644717457 case OnePossibleValueNo:
......@@ -16477,35 +17487,35 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *
1647717487 }
1647817488skip_computation:
1647917489 if (want_ptr_to_array) {
16480 return ir_get_ref(ira, &instruction->base, array_result, true, false);
17490 return ir_get_ref(ira, &instruction->base.base, array_result, true, false);
1648117491 } else {
1648217492 return array_result;
1648317493 }
1648417494}
1648517495
16486static IrInstruction *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira,
16487 IrInstructionMergeErrSets *instruction)
17496static IrInstGen *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira,
17497 IrInstSrcMergeErrSets *instruction)
1648817498{
16489 ZigType *op1_type = ir_resolve_error_set_type(ira, &instruction->base, instruction->op1->child);
17499 ZigType *op1_type = ir_resolve_error_set_type(ira, &instruction->base.base, instruction->op1->child);
1649017500 if (type_is_invalid(op1_type))
16491 return ira->codegen->invalid_instruction;
17501 return ira->codegen->invalid_inst_gen;
1649217502
16493 ZigType *op2_type = ir_resolve_error_set_type(ira, &instruction->base, instruction->op2->child);
17503 ZigType *op2_type = ir_resolve_error_set_type(ira, &instruction->base.base, instruction->op2->child);
1649417504 if (type_is_invalid(op2_type))
16495 return ira->codegen->invalid_instruction;
17505 return ira->codegen->invalid_inst_gen;
1649617506
1649717507 if (type_is_global_error_set(op1_type) ||
1649817508 type_is_global_error_set(op2_type))
1649917509 {
16500 return ir_const_type(ira, &instruction->base, ira->codegen->builtin_types.entry_global_error_set);
17510 return ir_const_type(ira, &instruction->base.base, ira->codegen->builtin_types.entry_global_error_set);
1650117511 }
1650217512
16503 if (!resolve_inferred_error_set(ira->codegen, op1_type, instruction->op1->child->source_node)) {
16504 return ira->codegen->invalid_instruction;
17513 if (!resolve_inferred_error_set(ira->codegen, op1_type, instruction->op1->child->base.source_node)) {
17514 return ira->codegen->invalid_inst_gen;
1650517515 }
1650617516
16507 if (!resolve_inferred_error_set(ira->codegen, op2_type, instruction->op2->child->source_node)) {
16508 return ira->codegen->invalid_instruction;
17517 if (!resolve_inferred_error_set(ira->codegen, op2_type, instruction->op2->child->base.source_node)) {
17518 return ira->codegen->invalid_inst_gen;
1650917519 }
1651017520
1651117521 size_t errors_count = ira->codegen->errors_by_index.length;
......@@ -16518,11 +17528,11 @@ static IrInstruction *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira,
1651817528 ZigType *result_type = get_error_set_union(ira->codegen, errors, op1_type, op2_type, instruction->type_name);
1651917529 deallocate(errors, errors_count, "ErrorTableEntry *");
1652017530
16521 return ir_const_type(ira, &instruction->base, result_type);
17531 return ir_const_type(ira, &instruction->base.base, result_type);
1652217532}
1652317533
1652417534
16525static IrInstruction *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
17535static IrInstGen *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstSrcBinOp *bin_op_instruction) {
1652617536 IrBinOp op_id = bin_op_instruction->op_id;
1652717537 switch (op_id) {
1652817538 case IrBinOpInvalid:
......@@ -16567,41 +17577,39 @@ static IrInstruction *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructio
1656717577 zig_unreachable();
1656817578}
1656917579
16570static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
16571 IrInstructionDeclVarSrc *decl_var_instruction)
16572{
17580static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclVar *decl_var_instruction) {
1657317581 Error err;
1657417582 ZigVar *var = decl_var_instruction->var;
1657517583
1657617584 ZigType *explicit_type = nullptr;
16577 IrInstruction *var_type = nullptr;
17585 IrInstGen *var_type = nullptr;
1657817586 if (decl_var_instruction->var_type != nullptr) {
1657917587 var_type = decl_var_instruction->var_type->child;
1658017588 ZigType *proposed_type = ir_resolve_type(ira, var_type);
16581 explicit_type = validate_var_type(ira->codegen, var_type->source_node, proposed_type);
17589 explicit_type = validate_var_type(ira->codegen, var_type->base.source_node, proposed_type);
1658217590 if (type_is_invalid(explicit_type)) {
1658317591 var->var_type = ira->codegen->builtin_types.entry_invalid;
16584 return ira->codegen->invalid_instruction;
17592 return ira->codegen->invalid_inst_gen;
1658517593 }
1658617594 }
1658717595
16588 AstNode *source_node = decl_var_instruction->base.source_node;
17596 AstNode *source_node = decl_var_instruction->base.base.source_node;
1658917597
1659017598 bool is_comptime_var = ir_get_var_is_comptime(var);
1659117599
1659217600 bool var_class_requires_const = false;
1659317601
16594 IrInstruction *var_ptr = decl_var_instruction->ptr->child;
17602 IrInstGen *var_ptr = decl_var_instruction->ptr->child;
1659517603 // if this is null, a compiler error happened and did not initialize the variable.
1659617604 // if there are no compile errors there may be a missing ir_expr_wrap in pass1 IR generation.
1659717605 if (var_ptr == nullptr || type_is_invalid(var_ptr->value->type)) {
16598 ir_assert(var_ptr != nullptr || ira->codegen->errors.length != 0, &decl_var_instruction->base);
17606 ir_assert(var_ptr != nullptr || ira->codegen->errors.length != 0, &decl_var_instruction->base.base);
1659917607 var->var_type = ira->codegen->builtin_types.entry_invalid;
16600 return ira->codegen->invalid_instruction;
17608 return ira->codegen->invalid_inst_gen;
1660117609 }
1660217610
1660317611 // The ir_build_var_decl_src call is supposed to pass a pointer to the allocation, not an initialization value.
16604 ir_assert(var_ptr->value->type->id == ZigTypeIdPointer, &decl_var_instruction->base);
17612 ir_assert(var_ptr->value->type->id == ZigTypeIdPointer, &decl_var_instruction->base.base);
1660517613
1660617614 ZigType *result_type = var_ptr->value->type->data.pointer.child_type;
1660717615 if (type_is_invalid(result_type)) {
......@@ -16612,7 +17620,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
1661217620
1661317621 ZigValue *init_val = nullptr;
1661417622 if (instr_is_comptime(var_ptr) && var_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
16615 init_val = const_ptr_pointee(ira, ira->codegen, var_ptr->value, decl_var_instruction->base.source_node);
17623 init_val = const_ptr_pointee(ira, ira->codegen, var_ptr->value, decl_var_instruction->base.base.source_node);
1661617624 if (is_comptime_var) {
1661717625 if (var->gen_is_const) {
1661817626 var->const_value = init_val;
......@@ -16639,7 +17647,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
1663917647 case ReqCompTimeNo:
1664017648 if (init_val != nullptr && value_is_comptime(init_val)) {
1664117649 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,
16642 decl_var_instruction->base.source_node, init_val, UndefOk)))
17650 decl_var_instruction->base.base.source_node, init_val, UndefOk)))
1664317651 {
1664417652 result_type = ira->codegen->builtin_types.entry_invalid;
1664517653 } else if (init_val->type->id == ZigTypeIdFn &&
......@@ -16687,13 +17695,13 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
1668717695 assert(var->var_type);
1668817696
1668917697 if (type_is_invalid(result_type)) {
16690 return ir_const_void(ira, &decl_var_instruction->base);
17698 return ir_const_void(ira, &decl_var_instruction->base.base);
1669117699 }
1669217700
1669317701 if (decl_var_instruction->align_value == nullptr) {
1669417702 if ((err = type_resolve(ira->codegen, result_type, ResolveStatusAlignmentKnown))) {
1669517703 var->var_type = ira->codegen->builtin_types.entry_invalid;
16696 return ir_const_void(ira, &decl_var_instruction->base);
17704 return ir_const_void(ira, &decl_var_instruction->base.base);
1669717705 }
1669817706 var->align_bytes = get_abi_alignment(ira->codegen, result_type);
1669917707 } else {
......@@ -16712,17 +17720,17 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
1671217720 // we need a runtime ptr but we have a comptime val.
1671317721 // since it's a comptime val there are no instructions for it.
1671417722 // we memcpy the init value here
16715 IrInstruction *deref = ir_get_deref(ira, var_ptr, var_ptr, nullptr);
17723 IrInstGen *deref = ir_get_deref(ira, &var_ptr->base, var_ptr, nullptr);
1671617724 if (type_is_invalid(deref->value->type)) {
1671717725 var->var_type = ira->codegen->builtin_types.entry_invalid;
16718 return ira->codegen->invalid_instruction;
17726 return ira->codegen->invalid_inst_gen;
1671917727 }
1672017728 // If this assertion trips, something is wrong with the IR instructions, because
1672117729 // we expected the above deref to return a constant value, but it created a runtime
1672217730 // instruction.
1672317731 assert(deref->value->special != ConstValSpecialRuntime);
1672417732 var_ptr->value->special = ConstValSpecialRuntime;
16725 ir_analyze_store_ptr(ira, var_ptr, var_ptr, deref, false);
17733 ir_analyze_store_ptr(ira, &var_ptr->base, var_ptr, deref, false);
1672617734 }
1672717735
1672817736 if (instr_is_comptime(var_ptr) && var->mem_slot_index != SIZE_MAX) {
......@@ -16732,84 +17740,84 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
1673217740 ira_ref(var->owner_exec->analysis);
1673317741
1673417742 if (is_comptime_var || (var_class_requires_const && var->gen_is_const)) {
16735 return ir_const_void(ira, &decl_var_instruction->base);
17743 return ir_const_void(ira, &decl_var_instruction->base.base);
1673617744 }
1673717745 }
1673817746 } else if (is_comptime_var) {
16739 ir_add_error(ira, &decl_var_instruction->base,
17747 ir_add_error(ira, &decl_var_instruction->base.base,
1674017748 buf_sprintf("cannot store runtime value in compile time variable"));
1674117749 var->var_type = ira->codegen->builtin_types.entry_invalid;
16742 return ira->codegen->invalid_instruction;
17750 return ira->codegen->invalid_inst_gen;
1674317751 }
1674417752
16745 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
17753 ZigFn *fn_entry = ira->new_irb.exec->fn_entry;
1674617754 if (fn_entry)
1674717755 fn_entry->variable_list.append(var);
1674817756
16749 return ir_build_var_decl_gen(ira, &decl_var_instruction->base, var, var_ptr);
17757 return ir_build_var_decl_gen(ira, &decl_var_instruction->base.base, var, var_ptr);
1675017758}
1675117759
16752static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExport *instruction) {
16753 IrInstruction *target = instruction->target->child;
17760static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport *instruction) {
17761 IrInstGen *target = instruction->target->child;
1675417762 if (type_is_invalid(target->value->type))
16755 return ira->codegen->invalid_instruction;
17763 return ira->codegen->invalid_inst_gen;
1675617764
16757 IrInstruction *options = instruction->options->child;
17765 IrInstGen *options = instruction->options->child;
1675817766 if (type_is_invalid(options->value->type))
16759 return ira->codegen->invalid_instruction;
17767 return ira->codegen->invalid_inst_gen;
1676017768
1676117769 ZigType *options_type = options->value->type;
1676217770 assert(options_type->id == ZigTypeIdStruct);
1676317771
1676417772 TypeStructField *name_field = find_struct_type_field(options_type, buf_create_from_str("name"));
16765 ir_assert(name_field != nullptr, &instruction->base);
16766 IrInstruction *name_inst = ir_analyze_struct_value_field_value(ira, &instruction->base, options, name_field);
17773 ir_assert(name_field != nullptr, &instruction->base.base);
17774 IrInstGen *name_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, name_field);
1676717775 if (type_is_invalid(name_inst->value->type))
16768 return ira->codegen->invalid_instruction;
17776 return ira->codegen->invalid_inst_gen;
1676917777
1677017778 TypeStructField *linkage_field = find_struct_type_field(options_type, buf_create_from_str("linkage"));
16771 ir_assert(linkage_field != nullptr, &instruction->base);
16772 IrInstruction *linkage_inst = ir_analyze_struct_value_field_value(ira, &instruction->base, options, linkage_field);
17779 ir_assert(linkage_field != nullptr, &instruction->base.base);
17780 IrInstGen *linkage_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, linkage_field);
1677317781 if (type_is_invalid(linkage_inst->value->type))
16774 return ira->codegen->invalid_instruction;
17782 return ira->codegen->invalid_inst_gen;
1677517783
1677617784 TypeStructField *section_field = find_struct_type_field(options_type, buf_create_from_str("section"));
16777 ir_assert(section_field != nullptr, &instruction->base);
16778 IrInstruction *section_inst = ir_analyze_struct_value_field_value(ira, &instruction->base, options, section_field);
17785 ir_assert(section_field != nullptr, &instruction->base.base);
17786 IrInstGen *section_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, section_field);
1677917787 if (type_is_invalid(section_inst->value->type))
16780 return ira->codegen->invalid_instruction;
17788 return ira->codegen->invalid_inst_gen;
1678117789
1678217790 // The `section` field is optional, we have to unwrap it first
16783 IrInstruction *non_null_check = ir_analyze_test_non_null(ira, &instruction->base, section_inst);
17791 IrInstGen *non_null_check = ir_analyze_test_non_null(ira, &instruction->base.base, section_inst);
1678417792 bool is_non_null;
1678517793 if (!ir_resolve_bool(ira, non_null_check, &is_non_null))
16786 return ira->codegen->invalid_instruction;
17794 return ira->codegen->invalid_inst_gen;
1678717795
16788 IrInstruction *section_str_inst = nullptr;
17796 IrInstGen *section_str_inst = nullptr;
1678917797 if (is_non_null) {
16790 section_str_inst = ir_analyze_optional_value_payload_value(ira, &instruction->base, section_inst, false);
17798 section_str_inst = ir_analyze_optional_value_payload_value(ira, &instruction->base.base, section_inst, false);
1679117799 if (type_is_invalid(section_str_inst->value->type))
16792 return ira->codegen->invalid_instruction;
17800 return ira->codegen->invalid_inst_gen;
1679317801 }
1679417802
1679517803 // Resolve all the comptime values
1679617804 Buf *symbol_name = ir_resolve_str(ira, name_inst);
1679717805 if (!symbol_name)
16798 return ira->codegen->invalid_instruction;
17806 return ira->codegen->invalid_inst_gen;
1679917807
1680017808 if (buf_len(symbol_name) < 1) {
16801 ir_add_error(ira, name_inst,
17809 ir_add_error(ira, &name_inst->base,
1680217810 buf_sprintf("exported symbol name cannot be empty"));
16803 return ira->codegen->invalid_instruction;
17811 return ira->codegen->invalid_inst_gen;
1680417812 }
1680517813
1680617814 GlobalLinkageId global_linkage_id;
1680717815 if (!ir_resolve_global_linkage(ira, linkage_inst, &global_linkage_id))
16808 return ira->codegen->invalid_instruction;
17816 return ira->codegen->invalid_inst_gen;
1680917817
1681017818 Buf *section_name = nullptr;
1681117819 if (section_str_inst != nullptr && !(section_name = ir_resolve_str(ira, section_str_inst)))
16812 return ira->codegen->invalid_instruction;
17820 return ira->codegen->invalid_inst_gen;
1681317821
1681417822 // TODO: This function needs to be audited.
1681517823 // It's not clear how all the different types are supposed to be handled.
......@@ -16817,15 +17825,15 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
1681717825 // in another file.
1681817826 TldFn *tld_fn = allocate<TldFn>(1);
1681917827 tld_fn->base.id = TldIdFn;
16820 tld_fn->base.source_node = instruction->base.source_node;
17828 tld_fn->base.source_node = instruction->base.base.source_node;
1682117829
1682217830 auto entry = ira->codegen->exported_symbol_names.put_unique(symbol_name, &tld_fn->base);
1682317831 if (entry) {
1682417832 AstNode *other_export_node = entry->value->source_node;
16825 ErrorMsg *msg = ir_add_error(ira, &instruction->base,
17833 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base,
1682617834 buf_sprintf("exported symbol collision: '%s'", buf_ptr(symbol_name)));
1682717835 add_error_note(ira->codegen, msg, other_export_node, buf_sprintf("other symbol is here"));
16828 return ira->codegen->invalid_instruction;
17836 return ira->codegen->invalid_inst_gen;
1682917837 }
1683017838
1683117839 Error err;
......@@ -16841,12 +17849,12 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
1684117849 CallingConvention cc = fn_entry->type_entry->data.fn.fn_type_id.cc;
1684217850 switch (cc) {
1684317851 case CallingConventionUnspecified: {
16844 ErrorMsg *msg = ir_add_error(ira, target,
17852 ErrorMsg *msg = ir_add_error(ira, &target->base,
1684517853 buf_sprintf("exported function must specify calling convention"));
1684617854 add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here"));
1684717855 } break;
1684817856 case CallingConventionAsync: {
16849 ErrorMsg *msg = ir_add_error(ira, target,
17857 ErrorMsg *msg = ir_add_error(ira, &target->base,
1685017858 buf_sprintf("exported function cannot be async"));
1685117859 add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here"));
1685217860 } break;
......@@ -16869,10 +17877,10 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
1686917877 } break;
1687017878 case ZigTypeIdStruct:
1687117879 if (is_slice(target->value->type)) {
16872 ir_add_error(ira, target,
17880 ir_add_error(ira, &target->base,
1687317881 buf_sprintf("unable to export value of type '%s'", buf_ptr(&target->value->type->name)));
1687417882 } else if (target->value->type->data.structure.layout != ContainerLayoutExtern) {
16875 ErrorMsg *msg = ir_add_error(ira, target,
17883 ErrorMsg *msg = ir_add_error(ira, &target->base,
1687617884 buf_sprintf("exported struct value must be declared extern"));
1687717885 add_error_note(ira->codegen, msg, target->value->type->data.structure.decl_node, buf_sprintf("declared here"));
1687817886 } else {
......@@ -16881,7 +17889,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
1688117889 break;
1688217890 case ZigTypeIdUnion:
1688317891 if (target->value->type->data.unionation.layout != ContainerLayoutExtern) {
16884 ErrorMsg *msg = ir_add_error(ira, target,
17892 ErrorMsg *msg = ir_add_error(ira, &target->base,
1688517893 buf_sprintf("exported union value must be declared extern"));
1688617894 add_error_note(ira->codegen, msg, target->value->type->data.unionation.decl_node, buf_sprintf("declared here"));
1688717895 } else {
......@@ -16890,7 +17898,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
1689017898 break;
1689117899 case ZigTypeIdEnum:
1689217900 if (target->value->type->data.enumeration.layout != ContainerLayoutExtern) {
16893 ErrorMsg *msg = ir_add_error(ira, target,
17901 ErrorMsg *msg = ir_add_error(ira, &target->base,
1689417902 buf_sprintf("exported enum value must be declared extern"));
1689517903 add_error_note(ira->codegen, msg, target->value->type->data.enumeration.decl_node, buf_sprintf("declared here"));
1689617904 } else {
......@@ -16900,10 +17908,10 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
1690017908 case ZigTypeIdArray: {
1690117909 bool ok_type;
1690217910 if ((err = type_allowed_in_extern(ira->codegen, target->value->type->data.array.child_type, &ok_type)))
16903 return ira->codegen->invalid_instruction;
17911 return ira->codegen->invalid_inst_gen;
1690417912
1690517913 if (!ok_type) {
16906 ir_add_error(ira, target,
17914 ir_add_error(ira, &target->base,
1690717915 buf_sprintf("array element type '%s' not extern-compatible",
1690817916 buf_ptr(&target->value->type->data.array.child_type->name)));
1690917917 } else {
......@@ -16918,31 +17926,31 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
1691817926 zig_unreachable();
1691917927 case ZigTypeIdStruct:
1692017928 if (is_slice(type_value)) {
16921 ir_add_error(ira, target,
17929 ir_add_error(ira, &target->base,
1692217930 buf_sprintf("unable to export type '%s'", buf_ptr(&type_value->name)));
1692317931 } else if (type_value->data.structure.layout != ContainerLayoutExtern) {
16924 ErrorMsg *msg = ir_add_error(ira, target,
17932 ErrorMsg *msg = ir_add_error(ira, &target->base,
1692517933 buf_sprintf("exported struct must be declared extern"));
1692617934 add_error_note(ira->codegen, msg, type_value->data.structure.decl_node, buf_sprintf("declared here"));
1692717935 }
1692817936 break;
1692917937 case ZigTypeIdUnion:
1693017938 if (type_value->data.unionation.layout != ContainerLayoutExtern) {
16931 ErrorMsg *msg = ir_add_error(ira, target,
17939 ErrorMsg *msg = ir_add_error(ira, &target->base,
1693217940 buf_sprintf("exported union must be declared extern"));
1693317941 add_error_note(ira->codegen, msg, type_value->data.unionation.decl_node, buf_sprintf("declared here"));
1693417942 }
1693517943 break;
1693617944 case ZigTypeIdEnum:
1693717945 if (type_value->data.enumeration.layout != ContainerLayoutExtern) {
16938 ErrorMsg *msg = ir_add_error(ira, target,
17946 ErrorMsg *msg = ir_add_error(ira, &target->base,
1693917947 buf_sprintf("exported enum must be declared extern"));
1694017948 add_error_note(ira->codegen, msg, type_value->data.enumeration.decl_node, buf_sprintf("declared here"));
1694117949 }
1694217950 break;
1694317951 case ZigTypeIdFn: {
1694417952 if (type_value->data.fn.fn_type_id.cc == CallingConventionUnspecified) {
16945 ir_add_error(ira, target,
17953 ir_add_error(ira, &target->base,
1694617954 buf_sprintf("exported function type must specify calling convention"));
1694717955 }
1694817956 } break;
......@@ -16968,7 +17976,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
1696817976 case ZigTypeIdOpaque:
1696917977 case ZigTypeIdFnFrame:
1697017978 case ZigTypeIdAnyFrame:
16971 ir_add_error(ira, target,
17979 ir_add_error(ira, &target->base,
1697217980 buf_sprintf("invalid export target '%s'", buf_ptr(&type_value->name)));
1697317981 break;
1697417982 }
......@@ -16993,61 +18001,55 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
1699318001 case ZigTypeIdEnumLiteral:
1699418002 case ZigTypeIdFnFrame:
1699518003 case ZigTypeIdAnyFrame:
16996 ir_add_error(ira, target,
18004 ir_add_error(ira, &target->base,
1699718005 buf_sprintf("invalid export target type '%s'", buf_ptr(&target->value->type->name)));
1699818006 break;
1699918007 }
1700018008
1700118009 // TODO audit the various ways to use @export
17002 if (want_var_export && target->id == IrInstructionIdLoadPtrGen) {
17003 IrInstructionLoadPtrGen *load_ptr = reinterpret_cast<IrInstructionLoadPtrGen *>(target);
17004 if (load_ptr->ptr->id == IrInstructionIdVarPtr) {
17005 IrInstructionVarPtr *var_ptr = reinterpret_cast<IrInstructionVarPtr *>(load_ptr->ptr);
18010 if (want_var_export && target->id == IrInstGenIdLoadPtr) {
18011 IrInstGenLoadPtr *load_ptr = reinterpret_cast<IrInstGenLoadPtr *>(target);
18012 if (load_ptr->ptr->id == IrInstGenIdVarPtr) {
18013 IrInstGenVarPtr *var_ptr = reinterpret_cast<IrInstGenVarPtr *>(load_ptr->ptr);
1700618014 ZigVar *var = var_ptr->var;
1700718015 add_var_export(ira->codegen, var, buf_ptr(symbol_name), global_linkage_id);
1700818016 var->section_name = section_name;
1700918017 }
1701018018 }
1701118019
17012 return ir_const_void(ira, &instruction->base);
18020 return ir_const_void(ira, &instruction->base.base);
1701318021}
1701418022
17015static bool exec_has_err_ret_trace(CodeGen *g, IrExecutable *exec) {
18023static bool exec_has_err_ret_trace(CodeGen *g, IrExecutableSrc *exec) {
1701618024 ZigFn *fn_entry = exec_fn_entry(exec);
1701718025 return fn_entry != nullptr && fn_entry->calls_or_awaits_errorable_fn && g->have_err_ret_tracing;
1701818026}
1701918027
17020static IrInstruction *ir_analyze_instruction_error_return_trace(IrAnalyze *ira,
17021 IrInstructionErrorReturnTrace *instruction)
18028static IrInstGen *ir_analyze_instruction_error_return_trace(IrAnalyze *ira,
18029 IrInstSrcErrorReturnTrace *instruction)
1702218030{
1702318031 ZigType *ptr_to_stack_trace_type = get_pointer_to_type(ira->codegen, get_stack_trace_type(ira->codegen), false);
17024 if (instruction->optional == IrInstructionErrorReturnTrace::Null) {
18032 if (instruction->optional == IrInstErrorReturnTraceNull) {
1702518033 ZigType *optional_type = get_optional_type(ira->codegen, ptr_to_stack_trace_type);
17026 if (!exec_has_err_ret_trace(ira->codegen, ira->new_irb.exec)) {
17027 IrInstruction *result = ir_const(ira, &instruction->base, optional_type);
18034 if (!exec_has_err_ret_trace(ira->codegen, ira->old_irb.exec)) {
18035 IrInstGen *result = ir_const(ira, &instruction->base.base, optional_type);
1702818036 ZigValue *out_val = result->value;
1702918037 assert(get_codegen_ptr_type(optional_type) != nullptr);
1703018038 out_val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
1703118039 out_val->data.x_ptr.data.hard_coded_addr.addr = 0;
1703218040 return result;
1703318041 }
17034 IrInstruction *new_instruction = ir_build_error_return_trace(&ira->new_irb, instruction->base.scope,
17035 instruction->base.source_node, instruction->optional);
17036 new_instruction->value->type = optional_type;
17037 return new_instruction;
18042 return ir_build_error_return_trace_gen(ira, instruction->base.base.scope,
18043 instruction->base.base.source_node, instruction->optional, optional_type);
1703818044 } else {
1703918045 assert(ira->codegen->have_err_ret_tracing);
17040 IrInstruction *new_instruction = ir_build_error_return_trace(&ira->new_irb, instruction->base.scope,
17041 instruction->base.source_node, instruction->optional);
17042 new_instruction->value->type = ptr_to_stack_trace_type;
17043 return new_instruction;
18046 return ir_build_error_return_trace_gen(ira, instruction->base.base.scope,
18047 instruction->base.base.source_node, instruction->optional, ptr_to_stack_trace_type);
1704418048 }
1704518049}
1704618050
17047static IrInstruction *ir_analyze_instruction_error_union(IrAnalyze *ira,
17048 IrInstructionErrorUnion *instruction)
17049{
17050 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type);
18051static IrInstGen *ir_analyze_instruction_error_union(IrAnalyze *ira, IrInstSrcErrorUnion *instruction) {
18052 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);
1705118053 result->value->special = ConstValSpecialLazy;
1705218054
1705318055 LazyValueErrUnionType *lazy_err_union_type = allocate<LazyValueErrUnionType>(1, "LazyValueErrUnionType");
......@@ -17057,16 +18059,16 @@ static IrInstruction *ir_analyze_instruction_error_union(IrAnalyze *ira,
1705718059
1705818060 lazy_err_union_type->err_set_type = instruction->err_set->child;
1705918061 if (ir_resolve_type_lazy(ira, lazy_err_union_type->err_set_type) == nullptr)
17060 return ira->codegen->invalid_instruction;
18062 return ira->codegen->invalid_inst_gen;
1706118063
1706218064 lazy_err_union_type->payload_type = instruction->payload->child;
1706318065 if (ir_resolve_type_lazy(ira, lazy_err_union_type->payload_type) == nullptr)
17064 return ira->codegen->invalid_instruction;
18066 return ira->codegen->invalid_inst_gen;
1706518067
1706618068 return result;
1706718069}
1706818070
17069static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_inst, ZigType *var_type,
18071static IrInstGen *ir_analyze_alloca(IrAnalyze *ira, IrInst *source_inst, ZigType *var_type,
1707018072 uint32_t align, const char *name_hint, bool force_comptime)
1707118073{
1707218074 Error err;
......@@ -17074,7 +18076,7 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in
1707418076 ZigValue *pointee = create_const_vals(1);
1707518077 pointee->special = ConstValSpecialUndef;
1707618078
17077 IrInstructionAllocaGen *result = ir_build_alloca_gen(ira, source_inst, align, name_hint);
18079 IrInstGenAlloca *result = ir_build_alloca_gen(ira, source_inst, align, name_hint);
1707818080 result->base.value->special = ConstValSpecialStatic;
1707918081 result->base.value->data.x_ptr.special = ConstPtrSpecialRef;
1708018082 result->base.value->data.x_ptr.mut = force_comptime ? ConstPtrMutComptimeVar : ConstPtrMutInfer;
......@@ -17082,15 +18084,15 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in
1708218084
1708318085 bool var_type_has_bits;
1708418086 if ((err = type_has_bits2(ira->codegen, var_type, &var_type_has_bits)))
17085 return ira->codegen->invalid_instruction;
18087 return ira->codegen->invalid_inst_gen;
1708618088 if (align != 0) {
1708718089 if ((err = type_resolve(ira->codegen, var_type, ResolveStatusAlignmentKnown)))
17088 return ira->codegen->invalid_instruction;
18090 return ira->codegen->invalid_inst_gen;
1708918091 if (!var_type_has_bits) {
1709018092 ir_add_error(ira, source_inst,
1709118093 buf_sprintf("variable '%s' of zero-bit type '%s' has no in-memory representation, it cannot be aligned",
1709218094 name_hint, buf_ptr(&var_type->name)));
17093 return ira->codegen->invalid_instruction;
18095 return ira->codegen->invalid_inst_gen;
1709418096 }
1709518097 }
1709618098 assert(result->base.value->data.x_ptr.special != ConstPtrSpecialInvalid);
......@@ -17099,15 +18101,14 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in
1709918101 result->base.value->type = get_pointer_to_type_extra(ira->codegen, var_type, false, false,
1710018102 PtrLenSingle, align, 0, 0, false);
1710118103
17102 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
18104 ZigFn *fn_entry = ira->new_irb.exec->fn_entry;
1710318105 if (fn_entry != nullptr) {
1710418106 fn_entry->alloca_gen_list.append(result);
1710518107 }
17106 result->base.is_gen = true;
1710718108 return &result->base;
1710818109}
1710918110
17110static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, IrInstruction *suspend_source_instr,
18111static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, IrInst *suspend_source_instr,
1711118112 ResultLoc *result_loc)
1711218113{
1711318114 switch (result_loc->id) {
......@@ -17150,7 +18151,7 @@ static bool type_can_bit_cast(ZigType *t) {
1715018151 }
1715118152}
1715218153
17153static void set_up_result_loc_for_inferred_comptime(IrInstruction *ptr) {
18154static void set_up_result_loc_for_inferred_comptime(IrInstGen *ptr) {
1715418155 ZigValue *undef_child = create_const_vals(1);
1715518156 undef_child->type = ptr->value->type->data.pointer.child_type;
1715618157 undef_child->special = ConstValSpecialUndef;
......@@ -17189,16 +18190,16 @@ static Error ir_result_has_type(IrAnalyze *ira, ResultLoc *result_loc, bool *out
1718918190 zig_unreachable();
1719018191}
1719118192
17192static IrInstruction *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstruction *suspend_source_instr,
18193static IrInstGen *ir_resolve_no_result_loc(IrAnalyze *ira, IrInst *suspend_source_instr,
1719318194 ResultLoc *result_loc, ZigType *value_type, bool force_runtime, bool non_null_comptime)
1719418195{
1719518196 if (type_is_invalid(value_type))
17196 return ira->codegen->invalid_instruction;
17197 IrInstructionAllocaGen *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr, 0, "");
18197 return ira->codegen->invalid_inst_gen;
18198 IrInstGenAlloca *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr, 0, "");
1719818199 alloca_gen->base.value->type = get_pointer_to_type_extra(ira->codegen, value_type, false, false,
1719918200 PtrLenSingle, 0, 0, 0, false);
1720018201 set_up_result_loc_for_inferred_comptime(&alloca_gen->base);
17201 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
18202 ZigFn *fn_entry = ira->new_irb.exec->fn_entry;
1720218203 if (fn_entry != nullptr && get_scope_typeof(suspend_source_instr->scope) == nullptr) {
1720318204 fn_entry->alloca_gen_list.append(alloca_gen);
1720418205 }
......@@ -17208,8 +18209,8 @@ static IrInstruction *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstruction *su
1720818209}
1720918210
1721018211// when calling this function, at the callsite must check for result type noreturn and propagate it up
17211static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr,
17212 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime,
18212static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_instr,
18213 ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime,
1721318214 bool non_null_comptime, bool allow_discard)
1721418215{
1721518216 Error err;
......@@ -17235,35 +18236,34 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1723518236 }
1723618237 case ResultLocIdVar: {
1723718238 ResultLocVar *result_loc_var = reinterpret_cast<ResultLocVar *>(result_loc);
17238 assert(result_loc->source_instruction->id == IrInstructionIdAllocaSrc);
18239 assert(result_loc->source_instruction->id == IrInstSrcIdAlloca);
1723918240
1724018241 if (value_type->id == ZigTypeIdUnreachable || value_type->id == ZigTypeIdOpaque) {
17241 ir_add_error(ira, result_loc->source_instruction,
18242 ir_add_error(ira, &result_loc->source_instruction->base,
1724218243 buf_sprintf("variable of type '%s' not allowed", buf_ptr(&value_type->name)));
17243 return ira->codegen->invalid_instruction;
18244 return ira->codegen->invalid_inst_gen;
1724418245 }
1724518246
17246 IrInstructionAllocaSrc *alloca_src =
17247 reinterpret_cast<IrInstructionAllocaSrc *>(result_loc->source_instruction);
18247 IrInstSrcAlloca *alloca_src = reinterpret_cast<IrInstSrcAlloca *>(result_loc->source_instruction);
1724818248 bool force_comptime;
1724918249 if (!ir_resolve_comptime(ira, alloca_src->is_comptime->child, &force_comptime))
17250 return ira->codegen->invalid_instruction;
18250 return ira->codegen->invalid_inst_gen;
1725118251 bool is_comptime = force_comptime || (!force_runtime && value != nullptr &&
1725218252 value->value->special != ConstValSpecialRuntime && result_loc_var->var->gen_is_const);
1725318253
1725418254 if (alloca_src->base.child == nullptr || is_comptime) {
1725518255 uint32_t align = 0;
1725618256 if (alloca_src->align != nullptr && !ir_resolve_align(ira, alloca_src->align->child, nullptr, &align)) {
17257 return ira->codegen->invalid_instruction;
18257 return ira->codegen->invalid_inst_gen;
1725818258 }
17259 IrInstruction *alloca_gen;
18259 IrInstGen *alloca_gen;
1726018260 if (is_comptime && value != nullptr) {
1726118261 if (align > value->value->llvm_align) {
1726218262 value->value->llvm_align = align;
1726318263 }
17264 alloca_gen = ir_get_ref(ira, result_loc->source_instruction, value, true, false);
18264 alloca_gen = ir_get_ref(ira, &result_loc->source_instruction->base, value, true, false);
1726518265 } else {
17266 alloca_gen = ir_analyze_alloca(ira, result_loc->source_instruction, value_type, align,
18266 alloca_gen = ir_analyze_alloca(ira, &result_loc->source_instruction->base, value_type, align,
1726718267 alloca_src->name_hint, force_comptime);
1726818268 if (force_runtime) {
1726918269 alloca_gen->value->data.x_ptr.mut = ConstPtrMutRuntimeVar;
......@@ -17271,7 +18271,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1727118271 }
1727218272 }
1727318273 if (alloca_src->base.child != nullptr && !result_loc->written) {
17274 alloca_src->base.child->ref_count = 0;
18274 alloca_src->base.child->base.ref_count = 0;
1727518275 }
1727618276 alloca_src->base.child = alloca_gen;
1727718277 }
......@@ -17296,9 +18296,9 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1729618296 }
1729718297 bool has_bits;
1729818298 if ((err = type_has_bits2(ira->codegen, ira->explicit_return_type, &has_bits)))
17299 return ira->codegen->invalid_instruction;
18299 return ira->codegen->invalid_inst_gen;
1730018300 if (!has_bits || !handle_is_ptr(ira->explicit_return_type)) {
17301 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
18301 ZigFn *fn_entry = ira->new_irb.exec->fn_entry;
1730218302 if (fn_entry == nullptr || fn_entry->inferred_async_node == nullptr) {
1730318303 return nullptr;
1730418304 }
......@@ -17306,8 +18306,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1730618306
1730718307 ZigType *ptr_return_type = get_pointer_to_type(ira->codegen, ira->explicit_return_type, false);
1730818308 result_loc->written = true;
17309 result_loc->resolved_loc = ir_build_return_ptr(ira, result_loc->source_instruction, ptr_return_type);
17310 if (ir_should_inline(ira->old_irb.exec, result_loc->source_instruction->scope)) {
18309 result_loc->resolved_loc = ir_build_return_ptr(ira, &result_loc->source_instruction->base, ptr_return_type);
18310 if (ir_should_inline(ira->old_irb.exec, result_loc->source_instruction->base.scope)) {
1731118311 set_up_result_loc_for_inferred_comptime(result_loc->resolved_loc);
1731218312 }
1731318313 return result_loc->resolved_loc;
......@@ -17317,7 +18317,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1731718317 ResultLocPeerParent *peer_parent = result_peer->parent;
1731818318
1731918319 if (peer_parent->peers.length == 1) {
17320 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,
18320 IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,
1732118321 value_type, value, force_runtime, non_null_comptime, true);
1732218322 result_peer->suspend_pos.basic_block_index = SIZE_MAX;
1732318323 result_peer->suspend_pos.instruction_index = SIZE_MAX;
......@@ -17333,7 +18333,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1733318333
1733418334 bool is_condition_comptime;
1733518335 if (!ir_resolve_comptime(ira, peer_parent->is_comptime->child, &is_condition_comptime))
17336 return ira->codegen->invalid_instruction;
18336 return ira->codegen->invalid_inst_gen;
1733718337 if (is_condition_comptime) {
1733818338 peer_parent->skipped = true;
1733918339 if (non_null_comptime) {
......@@ -17344,10 +18344,10 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1734418344 }
1734518345 bool peer_parent_has_type;
1734618346 if ((err = ir_result_has_type(ira, peer_parent->parent, &peer_parent_has_type)))
17347 return ira->codegen->invalid_instruction;
18347 return ira->codegen->invalid_inst_gen;
1734818348 if (peer_parent_has_type) {
1734918349 peer_parent->skipped = true;
17350 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,
18350 IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,
1735118351 value_type, value, force_runtime || !is_condition_comptime, true, true);
1735218352 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||
1735318353 parent_result_loc->value->type->id == ZigTypeIdUnreachable)
......@@ -17364,7 +18364,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1736418364 if (peer_parent->end_bb->suspend_instruction_ref == nullptr) {
1736518365 peer_parent->end_bb->suspend_instruction_ref = suspend_source_instr;
1736618366 }
17367 IrInstruction *unreach_inst = ira_suspend(ira, suspend_source_instr, result_peer->next_bb,
18367 IrInstGen *unreach_inst = ira_suspend(ira, suspend_source_instr, result_peer->next_bb,
1736818368 &result_peer->suspend_pos);
1736918369 if (result_peer->next_bb == nullptr) {
1737018370 ir_start_next_bb(ira);
......@@ -17372,7 +18372,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1737218372 return unreach_inst;
1737318373 }
1737418374
17375 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,
18375 IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,
1737618376 peer_parent->resolved_type, nullptr, force_runtime, non_null_comptime, true);
1737718377 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||
1737818378 parent_result_loc->value->type->id == ZigTypeIdUnreachable)
......@@ -17391,24 +18391,24 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1739118391 ResultLocCast *result_cast = reinterpret_cast<ResultLocCast *>(result_loc);
1739218392 ZigType *dest_type = ir_resolve_type(ira, result_cast->base.source_instruction->child);
1739318393 if (type_is_invalid(dest_type))
17394 return ira->codegen->invalid_instruction;
18394 return ira->codegen->invalid_inst_gen;
1739518395
1739618396 if (dest_type == ira->codegen->builtin_types.entry_var) {
1739718397 return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type,
1739818398 force_runtime, non_null_comptime);
1739918399 }
1740018400
17401 IrInstruction *casted_value;
18401 IrInstGen *casted_value;
1740218402 if (value != nullptr) {
1740318403 casted_value = ir_implicit_cast(ira, value, dest_type);
1740418404 if (type_is_invalid(casted_value->value->type))
17405 return ira->codegen->invalid_instruction;
18405 return ira->codegen->invalid_inst_gen;
1740618406 dest_type = casted_value->value->type;
1740718407 } else {
1740818408 casted_value = nullptr;
1740918409 }
1741018410
17411 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_cast->parent,
18411 IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_cast->parent,
1741218412 dest_type, casted_value, force_runtime, non_null_comptime, true);
1741318413 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||
1741418414 parent_result_loc->value->type->id == ZigTypeIdUnreachable)
......@@ -17422,11 +18422,11 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1742218422 if ((err = type_resolve(ira->codegen, parent_ptr_type->data.pointer.child_type,
1742318423 ResolveStatusAlignmentKnown)))
1742418424 {
17425 return ira->codegen->invalid_instruction;
18425 return ira->codegen->invalid_inst_gen;
1742618426 }
1742718427 uint64_t parent_ptr_align = get_ptr_align(ira->codegen, parent_ptr_type);
1742818428 if ((err = type_resolve(ira->codegen, value_type, ResolveStatusAlignmentKnown))) {
17429 return ira->codegen->invalid_instruction;
18429 return ira->codegen->invalid_inst_gen;
1743018430 }
1743118431 if (!type_has_bits(value_type)) {
1743218432 parent_ptr_align = 0;
......@@ -17449,9 +18449,9 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1744918449
1745018450 ConstCastOnly const_cast_result = types_match_const_cast_only(ira,
1745118451 parent_result_loc->value->type, ptr_type,
17452 result_cast->base.source_instruction->source_node, false);
18452 result_cast->base.source_instruction->base.source_node, false);
1745318453 if (const_cast_result.id == ConstCastResultIdInvalid)
17454 return ira->codegen->invalid_instruction;
18454 return ira->codegen->invalid_inst_gen;
1745518455 if (const_cast_result.id != ConstCastResultIdOk) {
1745618456 if (allow_discard) {
1745718457 return parent_result_loc;
......@@ -17465,42 +18465,42 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1746518465
1746618466 result_loc->written = true;
1746718467 result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc,
17468 ptr_type, result_cast->base.source_instruction, false);
18468 ptr_type, &result_cast->base.source_instruction->base, false);
1746918469 return result_loc->resolved_loc;
1747018470 }
1747118471 case ResultLocIdBitCast: {
1747218472 ResultLocBitCast *result_bit_cast = reinterpret_cast<ResultLocBitCast *>(result_loc);
1747318473 ZigType *dest_type = ir_resolve_type(ira, result_bit_cast->base.source_instruction->child);
1747418474 if (type_is_invalid(dest_type))
17475 return ira->codegen->invalid_instruction;
18475 return ira->codegen->invalid_inst_gen;
1747618476
1747718477 if (get_codegen_ptr_type(dest_type) != nullptr) {
17478 ir_add_error(ira, result_loc->source_instruction,
18478 ir_add_error(ira, &result_loc->source_instruction->base,
1747918479 buf_sprintf("unable to @bitCast to pointer type '%s'", buf_ptr(&dest_type->name)));
17480 return ira->codegen->invalid_instruction;
18480 return ira->codegen->invalid_inst_gen;
1748118481 }
1748218482
1748318483 if (!type_can_bit_cast(dest_type)) {
17484 ir_add_error(ira, result_loc->source_instruction,
18484 ir_add_error(ira, &result_loc->source_instruction->base,
1748518485 buf_sprintf("unable to @bitCast to type '%s'", buf_ptr(&dest_type->name)));
17486 return ira->codegen->invalid_instruction;
18486 return ira->codegen->invalid_inst_gen;
1748718487 }
1748818488
1748918489 if (get_codegen_ptr_type(value_type) != nullptr) {
1749018490 ir_add_error(ira, suspend_source_instr,
1749118491 buf_sprintf("unable to @bitCast from pointer type '%s'", buf_ptr(&value_type->name)));
17492 return ira->codegen->invalid_instruction;
18492 return ira->codegen->invalid_inst_gen;
1749318493 }
1749418494
1749518495 if (!type_can_bit_cast(value_type)) {
1749618496 ir_add_error(ira, suspend_source_instr,
1749718497 buf_sprintf("unable to @bitCast from type '%s'", buf_ptr(&value_type->name)));
17498 return ira->codegen->invalid_instruction;
18498 return ira->codegen->invalid_inst_gen;
1749918499 }
1750018500
17501 IrInstruction *bitcasted_value;
18501 IrInstGen *bitcasted_value;
1750218502 if (value != nullptr) {
17503 bitcasted_value = ir_analyze_bit_cast(ira, result_loc->source_instruction, value, dest_type);
18503 bitcasted_value = ir_analyze_bit_cast(ira, &result_loc->source_instruction->base, value, dest_type);
1750418504 dest_type = bitcasted_value->value->type;
1750518505 } else {
1750618506 bitcasted_value = nullptr;
......@@ -17510,7 +18510,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1751018510 return bitcasted_value;
1751118511 }
1751218512
17513 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_bit_cast->parent,
18513 IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_bit_cast->parent,
1751418514 dest_type, bitcasted_value, force_runtime, non_null_comptime, true);
1751518515 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||
1751618516 parent_result_loc->value->type->id == ZigTypeIdUnreachable)
......@@ -17523,7 +18523,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1752318523
1752418524 bool has_bits;
1752518525 if ((err = type_has_bits2(ira->codegen, child_type, &has_bits))) {
17526 return ira->codegen->invalid_instruction;
18526 return ira->codegen->invalid_inst_gen;
1752718527 }
1752818528
1752918529 // This happens when the bitCast result is assigned to _
......@@ -17533,12 +18533,12 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1753318533 }
1753418534
1753518535 if ((err = type_resolve(ira->codegen, child_type, ResolveStatusAlignmentKnown))) {
17536 return ira->codegen->invalid_instruction;
18536 return ira->codegen->invalid_inst_gen;
1753718537 }
1753818538
1753918539 uint64_t parent_ptr_align = get_ptr_align(ira->codegen, parent_ptr_type);
1754018540 if ((err = type_resolve(ira->codegen, value_type, ResolveStatusAlignmentKnown))) {
17541 return ira->codegen->invalid_instruction;
18541 return ira->codegen->invalid_inst_gen;
1754218542 }
1754318543 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value_type,
1754418544 parent_ptr_type->data.pointer.is_const, parent_ptr_type->data.pointer.is_volatile, PtrLenSingle,
......@@ -17546,29 +18546,33 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1754618546
1754718547 result_loc->written = true;
1754818548 result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc,
17549 ptr_type, result_bit_cast->base.source_instruction, false);
18549 ptr_type, &result_bit_cast->base.source_instruction->base, false);
1755018550 return result_loc->resolved_loc;
1755118551 }
1755218552 }
1755318553 zig_unreachable();
1755418554}
1755518555
17556static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_source_instr,
17557 ResultLoc *result_loc_pass1, ZigType *value_type, IrInstruction *value, bool force_runtime,
18556static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr,
18557 ResultLoc *result_loc_pass1, ZigType *value_type, IrInstGen *value, bool force_runtime,
1755818558 bool non_null_comptime, bool allow_discard)
1755918559{
1756018560 Error err;
1756118561 if (!allow_discard && result_loc_pass1->id == ResultLocIdInstruction &&
17562 instr_is_comptime(result_loc_pass1->source_instruction) &&
17563 result_loc_pass1->source_instruction->value->type->id == ZigTypeIdPointer &&
17564 result_loc_pass1->source_instruction->value->data.x_ptr.special == ConstPtrSpecialDiscard)
18562 result_loc_pass1->source_instruction->id == IrInstSrcIdConst)
1756518563 {
17566 result_loc_pass1 = no_result_loc();
18564 IrInstSrcConst *const_inst = reinterpret_cast<IrInstSrcConst *>(result_loc_pass1->source_instruction);
18565 if (value_is_comptime(const_inst->value) &&
18566 const_inst->value->type->id == ZigTypeIdPointer &&
18567 const_inst->value->data.x_ptr.special == ConstPtrSpecialDiscard)
18568 {
18569 result_loc_pass1 = no_result_loc();
18570 }
1756718571 }
1756818572 bool was_already_resolved = result_loc_pass1->resolved_loc != nullptr;
17569 IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type,
18573 IrInstGen *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type,
1757018574 value, force_runtime, non_null_comptime, allow_discard);
17571 if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value->type)))
18575 if (result_loc == nullptr || (result_loc->value->type->id == ZigTypeIdUnreachable || type_is_invalid(result_loc->value->type)))
1757218576 return result_loc;
1757318577
1757418578 if ((force_runtime || (value != nullptr && !instr_is_comptime(value))) &&
......@@ -17591,11 +18595,11 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
1759118595 field->type_entry = value_type;
1759218596 field->type_val = create_const_type(ira->codegen, field->type_entry);
1759318597 field->src_index = old_field_count;
17594 field->decl_node = value ? value->source_node : suspend_source_instr->source_node;
18598 field->decl_node = value ? value->base.source_node : suspend_source_instr->source_node;
1759518599 if (value && instr_is_comptime(value)) {
1759618600 ZigValue *val = ir_resolve_const(ira, value, UndefOk);
1759718601 if (!val)
17598 return ira->codegen->invalid_instruction;
18602 return ira->codegen->invalid_inst_gen;
1759918603 field->is_comptime = true;
1760018604 field->init_val = create_const_vals(1);
1760118605 copy_const_val(field->init_val, val);
......@@ -17603,7 +18607,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
1760318607 }
1760418608
1760518609 ZigType *struct_ptr_type = get_pointer_to_type(ira->codegen, isf->inferred_struct_type, false);
17606 IrInstruction *casted_ptr;
18610 IrInstGen *casted_ptr;
1760718611 if (instr_is_comptime(result_loc)) {
1760818612 casted_ptr = ir_const(ira, suspend_source_instr, struct_ptr_type);
1760918613 copy_const_val(casted_ptr->value, result_loc->value);
......@@ -17614,7 +18618,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
1761418618 if (instr_is_comptime(casted_ptr)) {
1761518619 ZigValue *ptr_val = ir_resolve_const(ira, casted_ptr, UndefBad);
1761618620 if (!ptr_val)
17617 return ira->codegen->invalid_instruction;
18621 return ira->codegen->invalid_inst_gen;
1761818622 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
1761918623 ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val,
1762018624 suspend_source_instr->source_node);
......@@ -17644,7 +18648,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
1764418648 {
1764518649 bool has_bits;
1764618650 if ((err = type_has_bits2(ira->codegen, value_type, &has_bits)))
17647 return ira->codegen->invalid_instruction;
18651 return ira->codegen->invalid_inst_gen;
1764818652 if (has_bits) {
1764918653 result_loc_pass1->written = false;
1765018654 return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, result_loc, false, true);
......@@ -17652,12 +18656,12 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
1765218656 } else if (actual_elem_type->id == ZigTypeIdErrorUnion && value_type->id != ZigTypeIdErrorUnion) {
1765318657 bool has_bits;
1765418658 if ((err = type_has_bits2(ira->codegen, value_type, &has_bits)))
17655 return ira->codegen->invalid_instruction;
18659 return ira->codegen->invalid_inst_gen;
1765618660 if (has_bits) {
1765718661 if (value_type->id == ZigTypeIdErrorSet) {
1765818662 return ir_analyze_unwrap_err_code(ira, suspend_source_instr, result_loc, true);
1765918663 } else {
17660 IrInstruction *unwrapped_err_ptr = ir_analyze_unwrap_error_payload(ira, suspend_source_instr,
18664 IrInstGen *unwrapped_err_ptr = ir_analyze_unwrap_error_payload(ira, suspend_source_instr,
1766118665 result_loc, false, true);
1766218666 ZigType *actual_payload_type = actual_elem_type->data.error_union.payload_type;
1766318667 if (actual_payload_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional &&
......@@ -17672,37 +18676,35 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
1767218676 return result_loc;
1767318677}
1767418678
17675static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira,
17676 IrInstructionResolveResult *instruction)
17677{
18679static IrInstGen *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrInstSrcResolveResult *instruction) {
1767818680 ZigType *implicit_elem_type;
1767918681 if (instruction->ty == nullptr) {
1768018682 if (instruction->result_loc->id == ResultLocIdCast) {
1768118683 implicit_elem_type = ir_resolve_type(ira,
1768218684 instruction->result_loc->source_instruction->child);
1768318685 if (type_is_invalid(implicit_elem_type))
17684 return ira->codegen->invalid_instruction;
18686 return ira->codegen->invalid_inst_gen;
1768518687 } else if (instruction->result_loc->id == ResultLocIdReturn) {
1768618688 implicit_elem_type = ira->explicit_return_type;
1768718689 if (type_is_invalid(implicit_elem_type))
17688 return ira->codegen->invalid_instruction;
18690 return ira->codegen->invalid_inst_gen;
1768918691 } else {
1769018692 implicit_elem_type = ira->codegen->builtin_types.entry_var;
1769118693 }
1769218694 if (implicit_elem_type == ira->codegen->builtin_types.entry_var) {
1769318695 Buf *bare_name = buf_alloc();
1769418696 Buf *name = get_anon_type_name(ira->codegen, nullptr, container_string(ContainerKindStruct),
17695 instruction->base.scope, instruction->base.source_node, bare_name);
18697 instruction->base.base.scope, instruction->base.base.source_node, bare_name);
1769618698
1769718699 StructSpecial struct_special = StructSpecialInferredStruct;
17698 if (instruction->base.source_node->type == NodeTypeContainerInitExpr &&
17699 instruction->base.source_node->data.container_init_expr.kind == ContainerInitKindArray)
18700 if (instruction->base.base.source_node->type == NodeTypeContainerInitExpr &&
18701 instruction->base.base.source_node->data.container_init_expr.kind == ContainerInitKindArray)
1770018702 {
1770118703 struct_special = StructSpecialInferredTuple;
1770218704 }
1770318705
1770418706 ZigType *inferred_struct_type = get_partial_container_type(ira->codegen,
17705 instruction->base.scope, ContainerKindStruct, instruction->base.source_node,
18707 instruction->base.base.scope, ContainerKindStruct, instruction->base.base.source_node,
1770618708 buf_ptr(name), bare_name, ContainerLayoutAuto);
1770718709 inferred_struct_type->data.structure.special = struct_special;
1770818710 inferred_struct_type->data.structure.resolve_status = ResolveStatusBeingInferred;
......@@ -17711,21 +18713,21 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira,
1771118713 } else {
1771218714 implicit_elem_type = ir_resolve_type(ira, instruction->ty->child);
1771318715 if (type_is_invalid(implicit_elem_type))
17714 return ira->codegen->invalid_instruction;
18716 return ira->codegen->invalid_inst_gen;
1771518717 }
17716 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
18718 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
1771718719 implicit_elem_type, nullptr, false, true, true);
1771818720 if (result_loc != nullptr)
1771918721 return result_loc;
1772018722
17721 ZigFn *fn = exec_fn_entry(ira->new_irb.exec);
18723 ZigFn *fn = ira->new_irb.exec->fn_entry;
1772218724 if (fn != nullptr && fn->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync &&
1772318725 instruction->result_loc->id == ResultLocIdReturn)
1772418726 {
17725 result_loc = ir_resolve_result(ira, &instruction->base, no_result_loc(),
18727 result_loc = ir_resolve_result(ira, &instruction->base.base, no_result_loc(),
1772618728 implicit_elem_type, nullptr, false, true, true);
1772718729 if (result_loc != nullptr &&
17728 (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)))
18730 (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable))
1772918731 {
1773018732 return result_loc;
1773118733 }
......@@ -17733,9 +18735,9 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira,
1773318735 return result_loc;
1773418736 }
1773518737
17736 IrInstruction *result = ir_const(ira, &instruction->base, implicit_elem_type);
18738 IrInstGen *result = ir_const(ira, &instruction->base.base, implicit_elem_type);
1773718739 result->value->special = ConstValSpecialUndef;
17738 IrInstruction *ptr = ir_get_ref(ira, &instruction->base, result, false, false);
18740 IrInstGen *ptr = ir_get_ref(ira, &instruction->base.base, result, false, false);
1773918741 ptr->value->data.x_ptr.mut = ConstPtrMutComptimeVar;
1774018742 return ptr;
1774118743}
......@@ -17759,8 +18761,7 @@ static void ir_reset_result(ResultLoc *result_loc) {
1775918761 break;
1776018762 }
1776118763 case ResultLocIdVar: {
17762 IrInstructionAllocaSrc *alloca_src =
17763 reinterpret_cast<IrInstructionAllocaSrc *>(result_loc->source_instruction);
18764 IrInstSrcAlloca *alloca_src = reinterpret_cast<IrInstSrcAlloca *>(result_loc->source_instruction);
1776418765 alloca_src->base.child = nullptr;
1776518766 break;
1776618767 }
......@@ -17776,18 +18777,18 @@ static void ir_reset_result(ResultLoc *result_loc) {
1777618777 }
1777718778}
1777818779
17779static IrInstruction *ir_analyze_instruction_reset_result(IrAnalyze *ira, IrInstructionResetResult *instruction) {
18780static IrInstGen *ir_analyze_instruction_reset_result(IrAnalyze *ira, IrInstSrcResetResult *instruction) {
1778018781 ir_reset_result(instruction->result_loc);
17781 return ir_const_void(ira, &instruction->base);
18782 return ir_const_void(ira, &instruction->base.base);
1778218783}
1778318784
17784static IrInstruction *get_async_call_result_loc(IrAnalyze *ira, IrInstruction *source_instr,
17785 ZigType *fn_ret_type, bool is_async_call_builtin, IrInstruction **args_ptr, size_t args_len,
17786 IrInstruction *ret_ptr_uncasted)
18785static IrInstGen *get_async_call_result_loc(IrAnalyze *ira, IrInst* source_instr,
18786 ZigType *fn_ret_type, bool is_async_call_builtin, IrInstGen **args_ptr, size_t args_len,
18787 IrInstGen *ret_ptr_uncasted)
1778718788{
1778818789 ir_assert(is_async_call_builtin, source_instr);
1778918790 if (type_is_invalid(ret_ptr_uncasted->value->type))
17790 return ira->codegen->invalid_instruction;
18791 return ira->codegen->invalid_inst_gen;
1779118792 if (ret_ptr_uncasted->value->type->id == ZigTypeIdVoid) {
1779218793 // Result location will be inside the async frame.
1779318794 return nullptr;
......@@ -17795,57 +18796,57 @@ static IrInstruction *get_async_call_result_loc(IrAnalyze *ira, IrInstruction *s
1779518796 return ir_implicit_cast(ira, ret_ptr_uncasted, get_pointer_to_type(ira->codegen, fn_ret_type, false));
1779618797}
1779718798
17798static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstruction *source_instr, ZigFn *fn_entry,
17799 ZigType *fn_type, IrInstruction *fn_ref, IrInstruction **casted_args, size_t arg_count,
17800 IrInstruction *casted_new_stack, bool is_async_call_builtin, IrInstruction *ret_ptr_uncasted,
18799static IrInstGen *ir_analyze_async_call(IrAnalyze *ira, IrInst* source_instr, ZigFn *fn_entry,
18800 ZigType *fn_type, IrInstGen *fn_ref, IrInstGen **casted_args, size_t arg_count,
18801 IrInstGen *casted_new_stack, bool is_async_call_builtin, IrInstGen *ret_ptr_uncasted,
1780118802 ResultLoc *call_result_loc)
1780218803{
1780318804 if (fn_entry == nullptr) {
1780418805 if (fn_type->data.fn.fn_type_id.cc != CallingConventionAsync) {
17805 ir_add_error(ira, fn_ref,
18806 ir_add_error(ira, &fn_ref->base,
1780618807 buf_sprintf("expected async function, found '%s'", buf_ptr(&fn_type->name)));
17807 return ira->codegen->invalid_instruction;
18808 return ira->codegen->invalid_inst_gen;
1780818809 }
1780918810 if (casted_new_stack == nullptr) {
17810 ir_add_error(ira, fn_ref, buf_sprintf("function is not comptime-known; @asyncCall required"));
17811 return ira->codegen->invalid_instruction;
18811 ir_add_error(ira, &fn_ref->base, buf_sprintf("function is not comptime-known; @asyncCall required"));
18812 return ira->codegen->invalid_inst_gen;
1781218813 }
1781318814 }
1781418815 if (casted_new_stack != nullptr) {
1781518816 ZigType *fn_ret_type = fn_type->data.fn.fn_type_id.return_type;
17816 IrInstruction *ret_ptr = get_async_call_result_loc(ira, source_instr, fn_ret_type, is_async_call_builtin,
18817 IrInstGen *ret_ptr = get_async_call_result_loc(ira, source_instr, fn_ret_type, is_async_call_builtin,
1781718818 casted_args, arg_count, ret_ptr_uncasted);
1781818819 if (ret_ptr != nullptr && type_is_invalid(ret_ptr->value->type))
17819 return ira->codegen->invalid_instruction;
18820 return ira->codegen->invalid_inst_gen;
1782018821
1782118822 ZigType *anyframe_type = get_any_frame_type(ira->codegen, fn_ret_type);
1782218823
17823 IrInstructionCallGen *call_gen = ir_build_call_gen(ira, source_instr, fn_entry, fn_ref,
18824 IrInstGenCall *call_gen = ir_build_call_gen(ira, source_instr, fn_entry, fn_ref,
1782418825 arg_count, casted_args, CallModifierAsync, casted_new_stack,
1782518826 is_async_call_builtin, ret_ptr, anyframe_type);
1782618827 return &call_gen->base;
1782718828 } else {
1782818829 ZigType *frame_type = get_fn_frame_type(ira->codegen, fn_entry);
17829 IrInstruction *result_loc = ir_resolve_result(ira, source_instr, call_result_loc,
18830 IrInstGen *result_loc = ir_resolve_result(ira, source_instr, call_result_loc,
1783018831 frame_type, nullptr, true, true, false);
17831 if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) {
18832 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
1783218833 return result_loc;
1783318834 }
1783418835 result_loc = ir_implicit_cast(ira, result_loc, get_pointer_to_type(ira->codegen, frame_type, false));
1783518836 if (type_is_invalid(result_loc->value->type))
17836 return ira->codegen->invalid_instruction;
18837 return ira->codegen->invalid_inst_gen;
1783718838 return &ir_build_call_gen(ira, source_instr, fn_entry, fn_ref, arg_count,
1783818839 casted_args, CallModifierAsync, casted_new_stack,
1783918840 is_async_call_builtin, result_loc, frame_type)->base;
1784018841 }
1784118842}
1784218843static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node,
17843 IrInstruction *arg, Scope **exec_scope, size_t *next_proto_i)
18844 IrInstGen *arg, Scope **exec_scope, size_t *next_proto_i)
1784418845{
1784518846 AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(*next_proto_i);
1784618847 assert(param_decl_node->type == NodeTypeParamDecl);
1784718848
17848 IrInstruction *casted_arg;
18849 IrInstGen *casted_arg;
1784918850 if (param_decl_node->data.param_decl.var_token == nullptr) {
1785018851 AstNode *param_type_node = param_decl_node->data.param_decl.type;
1785118852 ZigType *param_type = ir_analyze_type_expr(ira, *exec_scope, param_type_node);
......@@ -17873,15 +18874,15 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node
1787318874}
1787418875
1787518876static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_node,
17876 IrInstruction *arg, Scope **child_scope, size_t *next_proto_i,
17877 GenericFnTypeId *generic_id, FnTypeId *fn_type_id, IrInstruction **casted_args,
18877 IrInstGen *arg, Scope **child_scope, size_t *next_proto_i,
18878 GenericFnTypeId *generic_id, FnTypeId *fn_type_id, IrInstGen **casted_args,
1787818879 ZigFn *impl_fn)
1787918880{
1788018881 AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(*next_proto_i);
1788118882 assert(param_decl_node->type == NodeTypeParamDecl);
1788218883 bool is_var_args = param_decl_node->data.param_decl.is_var_args;
1788318884 bool arg_part_of_generic_id = false;
17884 IrInstruction *casted_arg;
18885 IrInstGen *casted_arg;
1788518886 if (is_var_args) {
1788618887 arg_part_of_generic_id = true;
1788718888 casted_arg = arg;
......@@ -17941,7 +18942,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
1794118942 } else if (casted_arg->value->type->id == ZigTypeIdComptimeInt ||
1794218943 casted_arg->value->type->id == ZigTypeIdComptimeFloat)
1794318944 {
17944 ir_add_error(ira, casted_arg,
18945 ir_add_error(ira, &casted_arg->base,
1794518946 buf_sprintf("compiler bug: integer and float literals in var args function must be casted. https://github.com/ziglang/zig/issues/557"));
1794618947 return false;
1794718948 }
......@@ -17958,17 +18959,17 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
1795818959 return true;
1795918960}
1796018961
17961static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, ZigVar *var) {
18962static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, IrInst *source_instr, ZigVar *var) {
1796218963 while (var->next_var != nullptr) {
1796318964 var = var->next_var;
1796418965 }
1796518966
1796618967 if (var->mem_slot_index != SIZE_MAX && var->owner_exec->analysis == nullptr) {
1796718968 assert(ira->codegen->errors.length != 0);
17968 return ira->codegen->invalid_instruction;
18969 return ira->codegen->invalid_inst_gen;
1796918970 }
1797018971 if (var->var_type == nullptr || type_is_invalid(var->var_type))
17971 return ira->codegen->invalid_instruction;
18972 return ira->codegen->invalid_inst_gen;
1797218973
1797318974 ZigValue *mem_slot = nullptr;
1797418975
......@@ -17976,8 +18977,7 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
1797618977 bool linkage_makes_it_runtime = var->decl_node->data.variable_declaration.is_extern;
1797718978 bool is_volatile = false;
1797818979
17979 IrInstruction *result = ir_build_var_ptr(&ira->new_irb,
17980 instruction->scope, instruction->source_node, var);
18980 IrInstGen *result = ir_build_var_ptr_gen(ira, source_instr, var);
1798118981 result->value->type = get_pointer_to_type_extra(ira->codegen, var->var_type,
1798218982 var->src_is_const, is_volatile, PtrLenSingle, var->align_bytes, 0, 0, false);
1798318983
......@@ -18030,7 +19030,7 @@ no_mem_slot:
1803019030}
1803119031
1803219032// This function is called when a comptime value becomes accessible at runtime.
18033static void mark_comptime_value_escape(IrAnalyze *ira, IrInstruction *source_instr, ZigValue *val) {
19033static void mark_comptime_value_escape(IrAnalyze *ira, IrInst* source_instr, ZigValue *val) {
1803419034 ir_assert(value_is_comptime(val), source_instr);
1803519035 if (val->special == ConstValSpecialUndef)
1803619036 return;
......@@ -18043,8 +19043,8 @@ static void mark_comptime_value_escape(IrAnalyze *ira, IrInstruction *source_ins
1804319043 }
1804419044}
1804519045
18046static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source_instr,
18047 IrInstruction *ptr, IrInstruction *uncasted_value, bool allow_write_through_const)
19046static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr,
19047 IrInstGen *ptr, IrInstGen *uncasted_value, bool allow_write_through_const)
1804819048{
1804919049 assert(ptr->value->type->id == ZigTypeIdPointer);
1805019050
......@@ -18053,24 +19053,24 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
1805319053 uncasted_value->value->type->id == ZigTypeIdErrorSet)
1805419054 {
1805519055 ir_add_error(ira, source_instr, buf_sprintf("error is discarded"));
18056 return ira->codegen->invalid_instruction;
19056 return ira->codegen->invalid_inst_gen;
1805719057 }
1805819058 return ir_const_void(ira, source_instr);
1805919059 }
1806019060
1806119061 if (ptr->value->type->data.pointer.is_const && !allow_write_through_const) {
1806219062 ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant"));
18063 return ira->codegen->invalid_instruction;
19063 return ira->codegen->invalid_inst_gen;
1806419064 }
1806519065
1806619066 ZigType *child_type = ptr->value->type->data.pointer.child_type;
18067 IrInstruction *value = ir_implicit_cast(ira, uncasted_value, child_type);
18068 if (value == ira->codegen->invalid_instruction)
18069 return ira->codegen->invalid_instruction;
19067 IrInstGen *value = ir_implicit_cast(ira, uncasted_value, child_type);
19068 if (type_is_invalid(value->value->type))
19069 return ira->codegen->invalid_inst_gen;
1807019070
1807119071 switch (type_has_one_possible_value(ira->codegen, child_type)) {
1807219072 case OnePossibleValueInvalid:
18073 return ira->codegen->invalid_instruction;
19073 return ira->codegen->invalid_inst_gen;
1807419074 case OnePossibleValueYes:
1807519075 return ir_const_void(ira, source_instr);
1807619076 case OnePossibleValueNo:
......@@ -18080,7 +19080,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
1808019080 if (instr_is_comptime(ptr) && ptr->value->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
1808119081 if (!allow_write_through_const && ptr->value->data.x_ptr.mut == ConstPtrMutComptimeConst) {
1808219082 ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant"));
18083 return ira->codegen->invalid_instruction;
19083 return ira->codegen->invalid_inst_gen;
1808419084 }
1808519085 if ((allow_write_through_const && ptr->value->data.x_ptr.mut == ConstPtrMutComptimeConst) ||
1808619086 ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar ||
......@@ -18089,7 +19089,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
1808919089 if (instr_is_comptime(value)) {
1809019090 ZigValue *dest_val = const_ptr_pointee(ira, ira->codegen, ptr->value, source_instr->source_node);
1809119091 if (dest_val == nullptr)
18092 return ira->codegen->invalid_instruction;
19092 return ira->codegen->invalid_inst_gen;
1809319093 if (dest_val->special != ConstValSpecialRuntime) {
1809419094 copy_const_val(dest_val, value->value);
1809519095
......@@ -18109,7 +19109,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
1810919109 ZigValue *dest_val = const_ptr_pointee_unchecked(ira->codegen, ptr->value);
1811019110 dest_val->type = ira->codegen->builtin_types.entry_invalid;
1811119111
18112 return ira->codegen->invalid_instruction;
19112 return ira->codegen->invalid_inst_gen;
1811319113 }
1811419114 }
1811519115 }
......@@ -18122,15 +19122,15 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
1812219122
1812319123 switch (type_requires_comptime(ira->codegen, child_type)) {
1812419124 case ReqCompTimeInvalid:
18125 return ira->codegen->invalid_instruction;
19125 return ira->codegen->invalid_inst_gen;
1812619126 case ReqCompTimeYes:
1812719127 switch (type_has_one_possible_value(ira->codegen, ptr->value->type)) {
1812819128 case OnePossibleValueInvalid:
18129 return ira->codegen->invalid_instruction;
19129 return ira->codegen->invalid_inst_gen;
1813019130 case OnePossibleValueNo:
1813119131 ir_add_error(ira, source_instr,
1813219132 buf_sprintf("cannot store runtime value in type '%s'", buf_ptr(&child_type->name)));
18133 return ira->codegen->invalid_instruction;
19133 return ira->codegen->invalid_inst_gen;
1813419134 case OnePossibleValueYes:
1813519135 return ir_const_void(ira, source_instr);
1813619136 }
......@@ -18144,30 +19144,28 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
1814419144 }
1814519145
1814619146 // If this is a store to a pointer with a runtime-known vector index,
18147 // we have to figure out the IrInstruction which represents the index and
18148 // emit a IrInstructionVectorStoreElem, or emit a compile error
19147 // we have to figure out the IrInstGen which represents the index and
19148 // emit a IrInstGenVectorStoreElem, or emit a compile error
1814919149 // explaining why it is impossible for this store to work. Which is that
1815019150 // the pointer address is of the vector; without the element index being known
1815119151 // we cannot properly perform the insertion.
1815219152 if (ptr->value->type->data.pointer.vector_index == VECTOR_INDEX_RUNTIME) {
18153 if (ptr->id == IrInstructionIdElemPtr) {
18154 IrInstructionElemPtr *elem_ptr = (IrInstructionElemPtr *)ptr;
19153 if (ptr->id == IrInstGenIdElemPtr) {
19154 IrInstGenElemPtr *elem_ptr = (IrInstGenElemPtr *)ptr;
1815519155 return ir_build_vector_store_elem(ira, source_instr, elem_ptr->array_ptr,
1815619156 elem_ptr->elem_index, value);
1815719157 }
18158 ir_add_error(ira, ptr,
19158 ir_add_error(ira, &ptr->base,
1815919159 buf_sprintf("unable to determine vector element index of type '%s'",
1816019160 buf_ptr(&ptr->value->type->name)));
18161 return ira->codegen->invalid_instruction;
19161 return ira->codegen->invalid_inst_gen;
1816219162 }
1816319163
18164 IrInstructionStorePtr *store_ptr = ir_build_store_ptr(&ira->new_irb, source_instr->scope,
18165 source_instr->source_node, ptr, value);
18166 return &store_ptr->base;
19164 return ir_build_store_ptr_gen(ira, source_instr, ptr, value);
1816719165}
1816819166
18169static IrInstruction *analyze_casted_new_stack(IrAnalyze *ira, IrInstruction *source_instr,
18170 IrInstruction *new_stack, bool is_async_call_builtin, ZigFn *fn_entry)
19167static IrInstGen *analyze_casted_new_stack(IrAnalyze *ira, IrInst* source_instr,
19168 IrInstGen *new_stack, bool is_async_call_builtin, ZigFn *fn_entry)
1817119169{
1817219170 if (new_stack == nullptr)
1817319171 return nullptr;
......@@ -18196,11 +19194,11 @@ static IrInstruction *analyze_casted_new_stack(IrAnalyze *ira, IrInstruction *so
1819619194 }
1819719195}
1819819196
18199static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_instr,
18200 ZigFn *fn_entry, ZigType *fn_type, IrInstruction *fn_ref,
18201 IrInstruction *first_arg_ptr, CallModifier modifier,
18202 IrInstruction *new_stack, bool is_async_call_builtin,
18203 IrInstruction **args_ptr, size_t args_len, IrInstruction *ret_ptr, ResultLoc *call_result_loc)
19197static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
19198 ZigFn *fn_entry, ZigType *fn_type, IrInstGen *fn_ref,
19199 IrInstGen *first_arg_ptr, CallModifier modifier,
19200 IrInstGen *new_stack, bool is_async_call_builtin,
19201 IrInstGen **args_ptr, size_t args_len, IrInstGen *ret_ptr, ResultLoc *call_result_loc)
1820419202{
1820519203 Error err;
1820619204 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;
......@@ -18221,11 +19219,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1822119219 AstNode *fn_proto_node = fn_entry ? fn_entry->proto_node : nullptr;;
1822219220
1822319221 if (fn_type_id->cc == CallingConventionNaked) {
18224 ErrorMsg *msg = ir_add_error(ira, fn_ref, buf_sprintf("unable to call function with naked calling convention"));
19222 ErrorMsg *msg = ir_add_error(ira, &fn_ref->base, buf_sprintf("unable to call function with naked calling convention"));
1822519223 if (fn_proto_node) {
1822619224 add_error_note(ira->codegen, msg, fn_proto_node, buf_sprintf("declared here"));
1822719225 }
18228 return ira->codegen->invalid_instruction;
19226 return ira->codegen->invalid_inst_gen;
1822919227 }
1823019228
1823119229 if (fn_type_id->is_var_args) {
......@@ -18236,7 +19234,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1823619234 add_error_note(ira->codegen, msg, fn_proto_node,
1823719235 buf_sprintf("declared here"));
1823819236 }
18239 return ira->codegen->invalid_instruction;
19237 return ira->codegen->invalid_inst_gen;
1824019238 }
1824119239 } else if (src_param_count != call_param_count) {
1824219240 ErrorMsg *msg = ir_add_error_node(ira, source_node,
......@@ -18245,18 +19243,18 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1824519243 add_error_note(ira->codegen, msg, fn_proto_node,
1824619244 buf_sprintf("declared here"));
1824719245 }
18248 return ira->codegen->invalid_instruction;
19246 return ira->codegen->invalid_inst_gen;
1824919247 }
1825019248
1825119249 if (modifier == CallModifierCompileTime) {
1825219250 // No special handling is needed for compile time evaluation of generic functions.
1825319251 if (!fn_entry || fn_entry->body_node == nullptr) {
18254 ir_add_error(ira, fn_ref, buf_sprintf("unable to evaluate constant expression"));
18255 return ira->codegen->invalid_instruction;
19252 ir_add_error(ira, &fn_ref->base, buf_sprintf("unable to evaluate constant expression"));
19253 return ira->codegen->invalid_inst_gen;
1825619254 }
1825719255
1825819256 if (!ir_emit_backward_branch(ira, source_instr))
18259 return ira->codegen->invalid_instruction;
19257 return ira->codegen->invalid_inst_gen;
1826019258
1826119259 // Fork a scope of the function with known values for the parameters.
1826219260 Scope *exec_scope = &fn_entry->fndef_scope->base;
......@@ -18269,47 +19267,47 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1826919267 if (fn_type_id->next_param_index >= 1) {
1827019268 ZigType *param_type = fn_type_id->param_info[next_proto_i].type;
1827119269 if (type_is_invalid(param_type))
18272 return ira->codegen->invalid_instruction;
19270 return ira->codegen->invalid_inst_gen;
1827319271 first_arg_known_bare = param_type->id != ZigTypeIdPointer;
1827419272 }
1827519273
18276 IrInstruction *first_arg;
19274 IrInstGen *first_arg;
1827719275 if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type)) {
1827819276 first_arg = first_arg_ptr;
1827919277 } else {
18280 first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr, nullptr);
19278 first_arg = ir_get_deref(ira, &first_arg_ptr->base, first_arg_ptr, nullptr);
1828119279 if (type_is_invalid(first_arg->value->type))
18282 return ira->codegen->invalid_instruction;
19280 return ira->codegen->invalid_inst_gen;
1828319281 }
1828419282
1828519283 if (!ir_analyze_fn_call_inline_arg(ira, fn_proto_node, first_arg, &exec_scope, &next_proto_i))
18286 return ira->codegen->invalid_instruction;
19284 return ira->codegen->invalid_inst_gen;
1828719285 }
1828819286
1828919287 if (fn_proto_node->data.fn_proto.is_var_args) {
1829019288 ir_add_error(ira, source_instr,
1829119289 buf_sprintf("compiler bug: unable to call var args function at compile time. https://github.com/ziglang/zig/issues/313"));
18292 return ira->codegen->invalid_instruction;
19290 return ira->codegen->invalid_inst_gen;
1829319291 }
1829419292
1829519293
1829619294 for (size_t call_i = 0; call_i < args_len; call_i += 1) {
18297 IrInstruction *old_arg = args_ptr[call_i];
19295 IrInstGen *old_arg = args_ptr[call_i];
1829819296
1829919297 if (!ir_analyze_fn_call_inline_arg(ira, fn_proto_node, old_arg, &exec_scope, &next_proto_i))
18300 return ira->codegen->invalid_instruction;
19298 return ira->codegen->invalid_inst_gen;
1830119299 }
1830219300
1830319301 AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;
1830419302 ZigType *specified_return_type = ir_analyze_type_expr(ira, exec_scope, return_type_node);
1830519303 if (type_is_invalid(specified_return_type))
18306 return ira->codegen->invalid_instruction;
19304 return ira->codegen->invalid_inst_gen;
1830719305 ZigType *return_type;
1830819306 ZigType *inferred_err_set_type = nullptr;
1830919307 if (fn_proto_node->data.fn_proto.auto_err_set) {
1831019308 inferred_err_set_type = get_auto_err_set_type(ira->codegen, fn_entry);
1831119309 if ((err = type_resolve(ira->codegen, specified_return_type, ResolveStatusSizeKnown)))
18312 return ira->codegen->invalid_instruction;
19310 return ira->codegen->invalid_inst_gen;
1831319311 return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type);
1831419312 } else {
1831519313 return_type = specified_return_type;
......@@ -18354,24 +19352,24 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1835419352 }
1835519353
1835619354 if (type_is_invalid(result->type)) {
18357 return ira->codegen->invalid_instruction;
19355 return ira->codegen->invalid_inst_gen;
1835819356 }
1835919357 }
1836019358
18361 IrInstruction *new_instruction = ir_const_move(ira, source_instr, result);
19359 IrInstGen *new_instruction = ir_const_move(ira, source_instr, result);
1836219360 return ir_finish_anal(ira, new_instruction);
1836319361 }
1836419362
1836519363 if (fn_type->data.fn.is_generic) {
1836619364 if (!fn_entry) {
18367 ir_add_error(ira, fn_ref,
19365 ir_add_error(ira, &fn_ref->base,
1836819366 buf_sprintf("calling a generic function requires compile-time known function value"));
18369 return ira->codegen->invalid_instruction;
19367 return ira->codegen->invalid_inst_gen;
1837019368 }
1837119369
1837219370 size_t new_fn_arg_count = first_arg_1_or_0 + args_len;
1837319371
18374 IrInstruction **casted_args = allocate<IrInstruction *>(new_fn_arg_count);
19372 IrInstGen **casted_args = allocate<IrInstGen *>(new_fn_arg_count);
1837519373
1837619374 // Fork a scope of the function with known values for the parameters.
1837719375 Scope *parent_scope = fn_entry->fndef_scope->base.parent;
......@@ -18400,30 +19398,30 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1840019398 if (fn_type_id->next_param_index >= 1) {
1840119399 ZigType *param_type = fn_type_id->param_info[next_proto_i].type;
1840219400 if (type_is_invalid(param_type))
18403 return ira->codegen->invalid_instruction;
19401 return ira->codegen->invalid_inst_gen;
1840419402 first_arg_known_bare = param_type->id != ZigTypeIdPointer;
1840519403 }
1840619404
18407 IrInstruction *first_arg;
19405 IrInstGen *first_arg;
1840819406 if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type)) {
1840919407 first_arg = first_arg_ptr;
1841019408 } else {
18411 first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr, nullptr);
19409 first_arg = ir_get_deref(ira, &first_arg_ptr->base, first_arg_ptr, nullptr);
1841219410 if (type_is_invalid(first_arg->value->type))
18413 return ira->codegen->invalid_instruction;
19411 return ira->codegen->invalid_inst_gen;
1841419412 }
1841519413
1841619414 if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, first_arg, &impl_fn->child_scope,
1841719415 &next_proto_i, generic_id, &inst_fn_type_id, casted_args, impl_fn))
1841819416 {
18419 return ira->codegen->invalid_instruction;
19417 return ira->codegen->invalid_inst_gen;
1842019418 }
1842119419 }
1842219420
18423 ZigFn *parent_fn_entry = exec_fn_entry(ira->new_irb.exec);
19421 ZigFn *parent_fn_entry = ira->new_irb.exec->fn_entry;
1842419422 assert(parent_fn_entry);
1842519423 for (size_t call_i = 0; call_i < args_len; call_i += 1) {
18426 IrInstruction *arg = args_ptr[call_i];
19424 IrInstGen *arg = args_ptr[call_i];
1842719425
1842819426 AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(next_proto_i);
1842919427 assert(param_decl_node->type == NodeTypeParamDecl);
......@@ -18431,7 +19429,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1843119429 if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, arg, &impl_fn->child_scope,
1843219430 &next_proto_i, generic_id, &inst_fn_type_id, casted_args, impl_fn))
1843319431 {
18434 return ira->codegen->invalid_instruction;
19432 return ira->codegen->invalid_inst_gen;
1843519433 }
1843619434 }
1843719435
......@@ -18441,7 +19439,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1844119439 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota,
1844219440 nullptr, nullptr, fn_proto_node->data.fn_proto.align_expr, nullptr, ira->new_irb.exec,
1844319441 nullptr, UndefBad);
18444 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
19442 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
1844519443 impl_fn->child_scope, fn_proto_node->data.fn_proto.align_expr);
1844619444 copy_const_val(const_instruction->base.value, align_result);
1844719445
......@@ -18455,11 +19453,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1845519453 AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;
1845619454 ZigType *specified_return_type = ir_analyze_type_expr(ira, impl_fn->child_scope, return_type_node);
1845719455 if (type_is_invalid(specified_return_type))
18458 return ira->codegen->invalid_instruction;
19456 return ira->codegen->invalid_inst_gen;
1845919457 if (fn_proto_node->data.fn_proto.auto_err_set) {
1846019458 ZigType *inferred_err_set_type = get_auto_err_set_type(ira->codegen, impl_fn);
1846119459 if ((err = type_resolve(ira->codegen, specified_return_type, ResolveStatusSizeKnown)))
18462 return ira->codegen->invalid_instruction;
19460 return ira->codegen->invalid_inst_gen;
1846319461 inst_fn_type_id.return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type);
1846419462 } else {
1846519463 inst_fn_type_id.return_type = specified_return_type;
......@@ -18472,7 +19470,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1847219470 CallModifierCompileTime, new_stack, is_async_call_builtin, args_ptr, args_len,
1847319471 ret_ptr, call_result_loc);
1847419472 case ReqCompTimeInvalid:
18475 return ira->codegen->invalid_instruction;
19473 return ira->codegen->invalid_inst_gen;
1847619474 case ReqCompTimeNo:
1847719475 break;
1847819476 }
......@@ -18486,7 +19484,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1848619484 // finish instantiating the function
1848719485 impl_fn->type_entry = get_fn_type(ira->codegen, &inst_fn_type_id);
1848819486 if (type_is_invalid(impl_fn->type_entry))
18489 return ira->codegen->invalid_instruction;
19487 return ira->codegen->invalid_inst_gen;
1849019488
1849119489 impl_fn->ir_executable->source_node = source_instr->source_node;
1849219490 impl_fn->ir_executable->parent_exec = ira->new_irb.exec;
......@@ -18504,25 +19502,25 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1850419502 parent_fn_entry->calls_or_awaits_errorable_fn = true;
1850519503 }
1850619504
18507 IrInstruction *casted_new_stack = analyze_casted_new_stack(ira, source_instr, new_stack,
19505 IrInstGen *casted_new_stack = analyze_casted_new_stack(ira, source_instr, new_stack,
1850819506 is_async_call_builtin, impl_fn);
1850919507 if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type))
18510 return ira->codegen->invalid_instruction;
19508 return ira->codegen->invalid_inst_gen;
1851119509
1851219510 size_t impl_param_count = impl_fn_type_id->param_count;
1851319511 if (modifier == CallModifierAsync) {
18514 IrInstruction *result = ir_analyze_async_call(ira, source_instr, impl_fn, impl_fn->type_entry,
19512 IrInstGen *result = ir_analyze_async_call(ira, source_instr, impl_fn, impl_fn->type_entry,
1851519513 nullptr, casted_args, impl_param_count, casted_new_stack, is_async_call_builtin, ret_ptr,
1851619514 call_result_loc);
1851719515 return ir_finish_anal(ira, result);
1851819516 }
1851919517
18520 IrInstruction *result_loc;
19518 IrInstGen *result_loc;
1852119519 if (handle_is_ptr(impl_fn_type_id->return_type)) {
1852219520 result_loc = ir_resolve_result(ira, source_instr, call_result_loc,
1852319521 impl_fn_type_id->return_type, nullptr, true, true, false);
1852419522 if (result_loc != nullptr) {
18525 if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) {
19523 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
1852619524 return result_loc;
1852719525 }
1852819526 ZigType *res_child_type = result_loc->value->type->data.pointer.child_type;
......@@ -18538,7 +19536,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1853819536 result_loc = get_async_call_result_loc(ira, source_instr, impl_fn_type_id->return_type,
1853919537 is_async_call_builtin, args_ptr, args_len, ret_ptr);
1854019538 if (result_loc != nullptr && type_is_invalid(result_loc->value->type))
18541 return ira->codegen->invalid_instruction;
19539 return ira->codegen->invalid_inst_gen;
1854219540 } else {
1854319541 result_loc = nullptr;
1854419542 }
......@@ -18547,11 +19545,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1854719545 parent_fn_entry->inferred_async_node == nullptr &&
1854819546 modifier != CallModifierNoAsync)
1854919547 {
18550 parent_fn_entry->inferred_async_node = fn_ref->source_node;
19548 parent_fn_entry->inferred_async_node = fn_ref->base.source_node;
1855119549 parent_fn_entry->inferred_async_fn = impl_fn;
1855219550 }
1855319551
18554 IrInstructionCallGen *new_call_instruction = ir_build_call_gen(ira, source_instr,
19552 IrInstGenCall *new_call_instruction = ir_build_call_gen(ira, source_instr,
1855519553 impl_fn, nullptr, impl_param_count, casted_args, modifier, casted_new_stack,
1855619554 is_async_call_builtin, result_loc, impl_fn_type_id->return_type);
1855719555
......@@ -18562,7 +19560,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1856219560 return ir_finish_anal(ira, &new_call_instruction->base);
1856319561 }
1856419562
18565 ZigFn *parent_fn_entry = exec_fn_entry(ira->new_irb.exec);
19563 ZigFn *parent_fn_entry = ira->new_irb.exec->fn_entry;
1856619564 assert(fn_type_id->return_type != nullptr);
1856719565 assert(parent_fn_entry != nullptr);
1856819566 if (fn_type_can_fail(fn_type_id)) {
......@@ -18570,46 +19568,46 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1857019568 }
1857119569
1857219570
18573 IrInstruction **casted_args = allocate<IrInstruction *>(call_param_count);
19571 IrInstGen **casted_args = allocate<IrInstGen *>(call_param_count);
1857419572 size_t next_arg_index = 0;
1857519573 if (first_arg_ptr) {
1857619574 assert(first_arg_ptr->value->type->id == ZigTypeIdPointer);
1857719575
1857819576 ZigType *param_type = fn_type_id->param_info[next_arg_index].type;
1857919577 if (type_is_invalid(param_type))
18580 return ira->codegen->invalid_instruction;
19578 return ira->codegen->invalid_inst_gen;
1858119579
18582 IrInstruction *first_arg;
19580 IrInstGen *first_arg;
1858319581 if (param_type->id == ZigTypeIdPointer &&
1858419582 handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type))
1858519583 {
1858619584 first_arg = first_arg_ptr;
1858719585 } else {
18588 first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr, nullptr);
19586 first_arg = ir_get_deref(ira, &first_arg_ptr->base, first_arg_ptr, nullptr);
1858919587 if (type_is_invalid(first_arg->value->type))
18590 return ira->codegen->invalid_instruction;
19588 return ira->codegen->invalid_inst_gen;
1859119589 }
1859219590
18593 IrInstruction *casted_arg = ir_implicit_cast(ira, first_arg, param_type);
19591 IrInstGen *casted_arg = ir_implicit_cast(ira, first_arg, param_type);
1859419592 if (type_is_invalid(casted_arg->value->type))
18595 return ira->codegen->invalid_instruction;
19593 return ira->codegen->invalid_inst_gen;
1859619594
1859719595 casted_args[next_arg_index] = casted_arg;
1859819596 next_arg_index += 1;
1859919597 }
1860019598 for (size_t call_i = 0; call_i < args_len; call_i += 1) {
18601 IrInstruction *old_arg = args_ptr[call_i];
19599 IrInstGen *old_arg = args_ptr[call_i];
1860219600 if (type_is_invalid(old_arg->value->type))
18603 return ira->codegen->invalid_instruction;
19601 return ira->codegen->invalid_inst_gen;
1860419602
18605 IrInstruction *casted_arg;
19603 IrInstGen *casted_arg;
1860619604 if (next_arg_index < src_param_count) {
1860719605 ZigType *param_type = fn_type_id->param_info[next_arg_index].type;
1860819606 if (type_is_invalid(param_type))
18609 return ira->codegen->invalid_instruction;
19607 return ira->codegen->invalid_inst_gen;
1861019608 casted_arg = ir_implicit_cast(ira, old_arg, param_type);
1861119609 if (type_is_invalid(casted_arg->value->type))
18612 return ira->codegen->invalid_instruction;
19610 return ira->codegen->invalid_inst_gen;
1861319611 } else {
1861419612 casted_arg = old_arg;
1861519613 }
......@@ -18622,21 +19620,21 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1862219620
1862319621 ZigType *return_type = fn_type_id->return_type;
1862419622 if (type_is_invalid(return_type))
18625 return ira->codegen->invalid_instruction;
19623 return ira->codegen->invalid_inst_gen;
1862619624
1862719625 if (fn_entry != nullptr && fn_entry->fn_inline == FnInlineAlways && modifier == CallModifierNeverInline) {
1862819626 ir_add_error(ira, source_instr,
1862919627 buf_sprintf("no-inline call of inline function"));
18630 return ira->codegen->invalid_instruction;
19628 return ira->codegen->invalid_inst_gen;
1863119629 }
1863219630
18633 IrInstruction *casted_new_stack = analyze_casted_new_stack(ira, source_instr, new_stack,
19631 IrInstGen *casted_new_stack = analyze_casted_new_stack(ira, source_instr, new_stack,
1863419632 is_async_call_builtin, fn_entry);
1863519633 if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type))
18636 return ira->codegen->invalid_instruction;
19634 return ira->codegen->invalid_inst_gen;
1863719635
1863819636 if (modifier == CallModifierAsync) {
18639 IrInstruction *result = ir_analyze_async_call(ira, source_instr, fn_entry, fn_type, fn_ref,
19637 IrInstGen *result = ir_analyze_async_call(ira, source_instr, fn_entry, fn_type, fn_ref,
1864019638 casted_args, call_param_count, casted_new_stack, is_async_call_builtin, ret_ptr, call_result_loc);
1864119639 return ir_finish_anal(ira, result);
1864219640 }
......@@ -18645,16 +19643,16 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1864519643 parent_fn_entry->inferred_async_node == nullptr &&
1864619644 modifier != CallModifierNoAsync)
1864719645 {
18648 parent_fn_entry->inferred_async_node = fn_ref->source_node;
19646 parent_fn_entry->inferred_async_node = fn_ref->base.source_node;
1864919647 parent_fn_entry->inferred_async_fn = fn_entry;
1865019648 }
1865119649
18652 IrInstruction *result_loc;
19650 IrInstGen *result_loc;
1865319651 if (handle_is_ptr(return_type)) {
1865419652 result_loc = ir_resolve_result(ira, source_instr, call_result_loc,
1865519653 return_type, nullptr, true, true, false);
1865619654 if (result_loc != nullptr) {
18657 if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) {
19655 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
1865819656 return result_loc;
1865919657 }
1866019658 ZigType *res_child_type = result_loc->value->type->data.pointer.child_type;
......@@ -18670,12 +19668,12 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1867019668 result_loc = get_async_call_result_loc(ira, source_instr, return_type, is_async_call_builtin,
1867119669 args_ptr, args_len, ret_ptr);
1867219670 if (result_loc != nullptr && type_is_invalid(result_loc->value->type))
18673 return ira->codegen->invalid_instruction;
19671 return ira->codegen->invalid_inst_gen;
1867419672 } else {
1867519673 result_loc = nullptr;
1867619674 }
1867719675
18678 IrInstructionCallGen *new_call_instruction = ir_build_call_gen(ira, source_instr, fn_entry, fn_ref,
19676 IrInstGenCall *new_call_instruction = ir_build_call_gen(ira, source_instr, fn_entry, fn_ref,
1867919677 call_param_count, casted_args, modifier, casted_new_stack,
1868019678 is_async_call_builtin, result_loc, return_type);
1868119679 if (get_scope_typeof(source_instr->scope) == nullptr) {
......@@ -18684,62 +19682,62 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1868419682 return ir_finish_anal(ira, &new_call_instruction->base);
1868519683}
1868619684
18687static IrInstruction *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstructionCallSrc *call_instruction,
18688 ZigFn *fn_entry, ZigType *fn_type, IrInstruction *fn_ref,
18689 IrInstruction *first_arg_ptr, CallModifier modifier)
19685static IrInstGen *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstSrcCall *call_instruction,
19686 ZigFn *fn_entry, ZigType *fn_type, IrInstGen *fn_ref,
19687 IrInstGen *first_arg_ptr, CallModifier modifier)
1869019688{
18691 IrInstruction *new_stack = nullptr;
19689 IrInstGen *new_stack = nullptr;
1869219690 if (call_instruction->new_stack) {
1869319691 new_stack = call_instruction->new_stack->child;
1869419692 if (type_is_invalid(new_stack->value->type))
18695 return ira->codegen->invalid_instruction;
19693 return ira->codegen->invalid_inst_gen;
1869619694 }
18697 IrInstruction **args_ptr = allocate<IrInstruction *>(call_instruction->arg_count, "IrInstruction *");
19695 IrInstGen **args_ptr = allocate<IrInstGen *>(call_instruction->arg_count, "IrInstGen *");
1869819696 for (size_t i = 0; i < call_instruction->arg_count; i += 1) {
1869919697 args_ptr[i] = call_instruction->args[i]->child;
1870019698 if (type_is_invalid(args_ptr[i]->value->type))
18701 return ira->codegen->invalid_instruction;
19699 return ira->codegen->invalid_inst_gen;
1870219700 }
18703 IrInstruction *ret_ptr = nullptr;
19701 IrInstGen *ret_ptr = nullptr;
1870419702 if (call_instruction->ret_ptr != nullptr) {
1870519703 ret_ptr = call_instruction->ret_ptr->child;
1870619704 if (type_is_invalid(ret_ptr->value->type))
18707 return ira->codegen->invalid_instruction;
19705 return ira->codegen->invalid_inst_gen;
1870819706 }
18709 IrInstruction *result = ir_analyze_fn_call(ira, &call_instruction->base, fn_entry, fn_type, fn_ref,
19707 IrInstGen *result = ir_analyze_fn_call(ira, &call_instruction->base.base, fn_entry, fn_type, fn_ref,
1871019708 first_arg_ptr, modifier, new_stack, call_instruction->is_async_call_builtin,
1871119709 args_ptr, call_instruction->arg_count, ret_ptr, call_instruction->result_loc);
18712 deallocate(args_ptr, call_instruction->arg_count, "IrInstruction *");
19710 deallocate(args_ptr, call_instruction->arg_count, "IrInstGen *");
1871319711 return result;
1871419712}
1871519713
18716static IrInstruction *ir_analyze_call_extra(IrAnalyze *ira, IrInstruction *source_instr,
18717 IrInstruction *pass1_options, IrInstruction *pass1_fn_ref, IrInstruction **args_ptr, size_t args_len,
19714static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr,
19715 IrInstSrc *pass1_options, IrInstSrc *pass1_fn_ref, IrInstGen **args_ptr, size_t args_len,
1871819716 ResultLoc *result_loc)
1871919717{
18720 IrInstruction *options = pass1_options->child;
19718 IrInstGen *options = pass1_options->child;
1872119719 if (type_is_invalid(options->value->type))
18722 return ira->codegen->invalid_instruction;
19720 return ira->codegen->invalid_inst_gen;
1872319721
18724 IrInstruction *fn_ref = pass1_fn_ref->child;
19722 IrInstGen *fn_ref = pass1_fn_ref->child;
1872519723 if (type_is_invalid(fn_ref->value->type))
18726 return ira->codegen->invalid_instruction;
19724 return ira->codegen->invalid_inst_gen;
1872719725
1872819726 TypeStructField *modifier_field = find_struct_type_field(options->value->type, buf_create_from_str("modifier"));
1872919727 ir_assert(modifier_field != nullptr, source_instr);
18730 IrInstruction *modifier_inst = ir_analyze_struct_value_field_value(ira, source_instr, options, modifier_field);
19728 IrInstGen *modifier_inst = ir_analyze_struct_value_field_value(ira, source_instr, options, modifier_field);
1873119729 ZigValue *modifier_val = ir_resolve_const(ira, modifier_inst, UndefBad);
1873219730 if (modifier_val == nullptr)
18733 return ira->codegen->invalid_instruction;
19731 return ira->codegen->invalid_inst_gen;
1873419732 CallModifier modifier = (CallModifier)bigint_as_u32(&modifier_val->data.x_enum_tag);
1873519733
18736 if (ir_should_inline(ira->new_irb.exec, source_instr->scope)) {
19734 if (ir_should_inline(ira->old_irb.exec, source_instr->scope)) {
1873719735 switch (modifier) {
1873819736 case CallModifierBuiltin:
1873919737 zig_unreachable();
1874019738 case CallModifierAsync:
1874119739 ir_add_error(ira, source_instr, buf_sprintf("TODO: comptime @call with async modifier"));
18742 return ira->codegen->invalid_instruction;
19740 return ira->codegen->invalid_inst_gen;
1874319741 case CallModifierCompileTime:
1874419742 case CallModifierNone:
1874519743 case CallModifierAlwaysInline:
......@@ -18750,15 +19748,15 @@ static IrInstruction *ir_analyze_call_extra(IrAnalyze *ira, IrInstruction *sourc
1875019748 case CallModifierNeverInline:
1875119749 ir_add_error(ira, source_instr,
1875219750 buf_sprintf("unable to perform 'never_inline' call at compile-time"));
18753 return ira->codegen->invalid_instruction;
19751 return ira->codegen->invalid_inst_gen;
1875419752 case CallModifierNeverTail:
1875519753 ir_add_error(ira, source_instr,
1875619754 buf_sprintf("unable to perform 'never_tail' call at compile-time"));
18757 return ira->codegen->invalid_instruction;
19755 return ira->codegen->invalid_inst_gen;
1875819756 }
1875919757 }
1876019758
18761 IrInstruction *first_arg_ptr = nullptr;
19759 IrInstGen *first_arg_ptr = nullptr;
1876219760 ZigFn *fn = nullptr;
1876319761 if (instr_is_comptime(fn_ref)) {
1876419762 if (fn_ref->value->type->id == ZigTypeIdBoundFn) {
......@@ -18766,7 +19764,7 @@ static IrInstruction *ir_analyze_call_extra(IrAnalyze *ira, IrInstruction *sourc
1876619764 fn = fn_ref->value->data.x_bound_fn.fn;
1876719765 first_arg_ptr = fn_ref->value->data.x_bound_fn.first_arg;
1876819766 if (type_is_invalid(first_arg_ptr->value->type))
18769 return ira->codegen->invalid_instruction;
19767 return ira->codegen->invalid_inst_gen;
1877019768 } else {
1877119769 fn = ir_resolve_fn(ira, fn_ref);
1877219770 }
......@@ -18778,9 +19776,9 @@ static IrInstruction *ir_analyze_call_extra(IrAnalyze *ira, IrInstruction *sourc
1877819776 case CallModifierAlwaysInline:
1877919777 case CallModifierAsync:
1878019778 if (fn == nullptr) {
18781 ir_add_error(ira, modifier_inst,
19779 ir_add_error(ira, &modifier_inst->base,
1878219780 buf_sprintf("the specified modifier requires a comptime-known function"));
18783 return ira->codegen->invalid_instruction;
19781 return ira->codegen->invalid_inst_gen;
1878419782 }
1878519783 default:
1878619784 break;
......@@ -18790,93 +19788,93 @@ static IrInstruction *ir_analyze_call_extra(IrAnalyze *ira, IrInstruction *sourc
1879019788
1879119789 TypeStructField *stack_field = find_struct_type_field(options->value->type, buf_create_from_str("stack"));
1879219790 ir_assert(stack_field != nullptr, source_instr);
18793 IrInstruction *opt_stack = ir_analyze_struct_value_field_value(ira, source_instr, options, stack_field);
19791 IrInstGen *opt_stack = ir_analyze_struct_value_field_value(ira, source_instr, options, stack_field);
1879419792 if (type_is_invalid(opt_stack->value->type))
18795 return ira->codegen->invalid_instruction;
19793 return ira->codegen->invalid_inst_gen;
1879619794
18797 IrInstruction *stack_is_non_null_inst = ir_analyze_test_non_null(ira, source_instr, opt_stack);
19795 IrInstGen *stack_is_non_null_inst = ir_analyze_test_non_null(ira, source_instr, opt_stack);
1879819796 bool stack_is_non_null;
1879919797 if (!ir_resolve_bool(ira, stack_is_non_null_inst, &stack_is_non_null))
18800 return ira->codegen->invalid_instruction;
19798 return ira->codegen->invalid_inst_gen;
1880119799
18802 IrInstruction *stack = nullptr;
19800 IrInstGen *stack = nullptr;
1880319801 if (stack_is_non_null) {
1880419802 stack = ir_analyze_optional_value_payload_value(ira, source_instr, opt_stack, false);
1880519803 if (type_is_invalid(stack->value->type))
18806 return ira->codegen->invalid_instruction;
19804 return ira->codegen->invalid_inst_gen;
1880719805 }
1880819806
1880919807 return ir_analyze_fn_call(ira, source_instr, fn, fn_type, fn_ref, first_arg_ptr,
1881019808 modifier, stack, false, args_ptr, args_len, nullptr, result_loc);
1881119809}
1881219810
18813static IrInstruction *ir_analyze_instruction_call_extra(IrAnalyze *ira, IrInstructionCallExtra *instruction) {
18814 IrInstruction *args = instruction->args->child;
19811static IrInstGen *ir_analyze_instruction_call_extra(IrAnalyze *ira, IrInstSrcCallExtra *instruction) {
19812 IrInstGen *args = instruction->args->child;
1881519813 ZigType *args_type = args->value->type;
1881619814 if (type_is_invalid(args_type))
18817 return ira->codegen->invalid_instruction;
19815 return ira->codegen->invalid_inst_gen;
1881819816
1881919817 if (args_type->id != ZigTypeIdStruct) {
18820 ir_add_error(ira, args,
19818 ir_add_error(ira, &args->base,
1882119819 buf_sprintf("expected tuple or struct, found '%s'", buf_ptr(&args_type->name)));
18822 return ira->codegen->invalid_instruction;
19820 return ira->codegen->invalid_inst_gen;
1882319821 }
1882419822
18825 IrInstruction **args_ptr = nullptr;
19823 IrInstGen **args_ptr = nullptr;
1882619824 size_t args_len = 0;
1882719825
1882819826 if (is_tuple(args_type)) {
1882919827 args_len = args_type->data.structure.src_field_count;
18830 args_ptr = allocate<IrInstruction *>(args_len, "IrInstruction *");
19828 args_ptr = allocate<IrInstGen *>(args_len, "IrInstGen *");
1883119829 for (size_t i = 0; i < args_len; i += 1) {
1883219830 TypeStructField *arg_field = args_type->data.structure.fields[i];
18833 args_ptr[i] = ir_analyze_struct_value_field_value(ira, &instruction->base, args, arg_field);
19831 args_ptr[i] = ir_analyze_struct_value_field_value(ira, &instruction->base.base, args, arg_field);
1883419832 if (type_is_invalid(args_ptr[i]->value->type))
18835 return ira->codegen->invalid_instruction;
19833 return ira->codegen->invalid_inst_gen;
1883619834 }
1883719835 } else {
18838 ir_add_error(ira, args, buf_sprintf("TODO: struct args"));
18839 return ira->codegen->invalid_instruction;
19836 ir_add_error(ira, &args->base, buf_sprintf("TODO: struct args"));
19837 return ira->codegen->invalid_inst_gen;
1884019838 }
18841 IrInstruction *result = ir_analyze_call_extra(ira, &instruction->base, instruction->options,
19839 IrInstGen *result = ir_analyze_call_extra(ira, &instruction->base.base, instruction->options,
1884219840 instruction->fn_ref, args_ptr, args_len, instruction->result_loc);
18843 deallocate(args_ptr, args_len, "IrInstruction *");
19841 deallocate(args_ptr, args_len, "IrInstGen *");
1884419842 return result;
1884519843}
1884619844
18847static IrInstruction *ir_analyze_instruction_call_args(IrAnalyze *ira, IrInstructionCallSrcArgs *instruction) {
18848 IrInstruction **args_ptr = allocate<IrInstruction *>(instruction->args_len, "IrInstruction *");
19845static IrInstGen *ir_analyze_instruction_call_args(IrAnalyze *ira, IrInstSrcCallArgs *instruction) {
19846 IrInstGen **args_ptr = allocate<IrInstGen *>(instruction->args_len, "IrInstGen *");
1884919847 for (size_t i = 0; i < instruction->args_len; i += 1) {
1885019848 args_ptr[i] = instruction->args_ptr[i]->child;
1885119849 if (type_is_invalid(args_ptr[i]->value->type))
18852 return ira->codegen->invalid_instruction;
19850 return ira->codegen->invalid_inst_gen;
1885319851 }
1885419852
18855 IrInstruction *result = ir_analyze_call_extra(ira, &instruction->base, instruction->options,
19853 IrInstGen *result = ir_analyze_call_extra(ira, &instruction->base.base, instruction->options,
1885619854 instruction->fn_ref, args_ptr, instruction->args_len, instruction->result_loc);
18857 deallocate(args_ptr, instruction->args_len, "IrInstruction *");
19855 deallocate(args_ptr, instruction->args_len, "IrInstGen *");
1885819856 return result;
1885919857}
1886019858
18861static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCallSrc *call_instruction) {
18862 IrInstruction *fn_ref = call_instruction->fn_ref->child;
19859static IrInstGen *ir_analyze_instruction_call(IrAnalyze *ira, IrInstSrcCall *call_instruction) {
19860 IrInstGen *fn_ref = call_instruction->fn_ref->child;
1886319861 if (type_is_invalid(fn_ref->value->type))
18864 return ira->codegen->invalid_instruction;
19862 return ira->codegen->invalid_inst_gen;
1886519863
1886619864 bool is_comptime = (call_instruction->modifier == CallModifierCompileTime) ||
18867 ir_should_inline(ira->new_irb.exec, call_instruction->base.scope);
19865 ir_should_inline(ira->old_irb.exec, call_instruction->base.base.scope);
1886819866 CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier;
1886919867
1887019868 if (is_comptime || instr_is_comptime(fn_ref)) {
1887119869 if (fn_ref->value->type->id == ZigTypeIdMetaType) {
1887219870 ZigType *ty = ir_resolve_type(ira, fn_ref);
1887319871 if (ty == nullptr)
18874 return ira->codegen->invalid_instruction;
18875 ErrorMsg *msg = ir_add_error_node(ira, fn_ref->source_node,
19872 return ira->codegen->invalid_inst_gen;
19873 ErrorMsg *msg = ir_add_error(ira, &fn_ref->base,
1887619874 buf_sprintf("type '%s' not a function", buf_ptr(&ty->name)));
18877 add_error_note(ira->codegen, msg, call_instruction->base.source_node,
19875 add_error_note(ira->codegen, msg, call_instruction->base.base.source_node,
1887819876 buf_sprintf("use @as builtin for type coercion"));
18879 return ira->codegen->invalid_instruction;
19877 return ira->codegen->invalid_inst_gen;
1888019878 } else if (fn_ref->value->type->id == ZigTypeIdFn) {
1888119879 ZigFn *fn_table_entry = ir_resolve_fn(ira, fn_ref);
1888219880 ZigType *fn_type = fn_table_entry ? fn_table_entry->type_entry : fn_ref->value->type;
......@@ -18886,14 +19884,14 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC
1888619884 } else if (fn_ref->value->type->id == ZigTypeIdBoundFn) {
1888719885 assert(fn_ref->value->special == ConstValSpecialStatic);
1888819886 ZigFn *fn_table_entry = fn_ref->value->data.x_bound_fn.fn;
18889 IrInstruction *first_arg_ptr = fn_ref->value->data.x_bound_fn.first_arg;
19887 IrInstGen *first_arg_ptr = fn_ref->value->data.x_bound_fn.first_arg;
1889019888 CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier;
1889119889 return ir_analyze_fn_call_src(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry,
1889219890 fn_ref, first_arg_ptr, modifier);
1889319891 } else {
18894 ir_add_error_node(ira, fn_ref->source_node,
19892 ir_add_error(ira, &fn_ref->base,
1889519893 buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value->type->name)));
18896 return ira->codegen->invalid_instruction;
19894 return ira->codegen->invalid_inst_gen;
1889719895 }
1889819896 }
1889919897
......@@ -18901,9 +19899,9 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC
1890119899 return ir_analyze_fn_call_src(ira, call_instruction, nullptr, fn_ref->value->type,
1890219900 fn_ref, nullptr, modifier);
1890319901 } else {
18904 ir_add_error_node(ira, fn_ref->source_node,
19902 ir_add_error(ira, &fn_ref->base,
1890519903 buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value->type->name)));
18906 return ira->codegen->invalid_instruction;
19904 return ira->codegen->invalid_inst_gen;
1890719905 }
1890819906}
1890919907
......@@ -18992,8 +19990,8 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source
1899219990 zig_unreachable();
1899319991}
1899419992
18995static IrInstruction *ir_analyze_optional_type(IrAnalyze *ira, IrInstructionUnOp *instruction) {
18996 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type);
19993static IrInstGen *ir_analyze_optional_type(IrAnalyze *ira, IrInstSrcUnOp *instruction) {
19994 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);
1899719995 result->value->special = ConstValSpecialLazy;
1899819996
1899919997 LazyValueOptType *lazy_opt_type = allocate<LazyValueOptType>(1, "LazyValueOptType");
......@@ -19003,12 +20001,12 @@ static IrInstruction *ir_analyze_optional_type(IrAnalyze *ira, IrInstructionUnOp
1900320001
1900420002 lazy_opt_type->payload_type = instruction->value->child;
1900520003 if (ir_resolve_type_lazy(ira, lazy_opt_type->payload_type) == nullptr)
19006 return ira->codegen->invalid_instruction;
20004 return ira->codegen->invalid_inst_gen;
1900720005
1900820006 return result;
1900920007}
1901020008
19011static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInstruction *source_instr, ZigType *scalar_type,
20009static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInst* source_instr, ZigType *scalar_type,
1901220010 ZigValue *operand_val, ZigValue *scalar_out_val, bool is_wrap_op)
1901320011{
1901420012 bool is_float = (scalar_type->id == ZigTypeIdFloat || scalar_type->id == ZigTypeIdComptimeFloat);
......@@ -19043,19 +20041,19 @@ static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInstruction *source_i
1904320041 return nullptr;
1904420042}
1904520043
19046static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *instruction) {
19047 IrInstruction *value = instruction->value->child;
20044static IrInstGen *ir_analyze_negation(IrAnalyze *ira, IrInstSrcUnOp *instruction) {
20045 IrInstGen *value = instruction->value->child;
1904820046 ZigType *expr_type = value->value->type;
1904920047 if (type_is_invalid(expr_type))
19050 return ira->codegen->invalid_instruction;
20048 return ira->codegen->invalid_inst_gen;
1905120049
1905220050 if (!(expr_type->id == ZigTypeIdInt || expr_type->id == ZigTypeIdComptimeInt ||
1905320051 expr_type->id == ZigTypeIdFloat || expr_type->id == ZigTypeIdComptimeFloat ||
1905420052 expr_type->id == ZigTypeIdVector))
1905520053 {
19056 ir_add_error(ira, &instruction->base,
20054 ir_add_error(ira, &instruction->base.base,
1905720055 buf_sprintf("negation of type '%s'", buf_ptr(&expr_type->name)));
19058 return ira->codegen->invalid_instruction;
20056 return ira->codegen->invalid_inst_gen;
1905920057 }
1906020058
1906120059 bool is_wrap_op = (instruction->op_id == IrUnOpNegationWrap);
......@@ -19065,9 +20063,9 @@ static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *ins
1906520063 if (instr_is_comptime(value)) {
1906620064 ZigValue *operand_val = ir_resolve_const(ira, value, UndefBad);
1906720065 if (!operand_val)
19068 return ira->codegen->invalid_instruction;
20066 return ira->codegen->invalid_inst_gen;
1906920067
19070 IrInstruction *result_instruction = ir_const(ira, &instruction->base, expr_type);
20068 IrInstGen *result_instruction = ir_const(ira, &instruction->base.base, expr_type);
1907120069 ZigValue *out_val = result_instruction->value;
1907220070 if (expr_type->id == ZigTypeIdVector) {
1907320071 expand_undef_array(ira->codegen, operand_val);
......@@ -19079,63 +20077,60 @@ static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *ins
1907920077 ZigValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i];
1908020078 assert(scalar_operand_val->type == scalar_type);
1908120079 assert(scalar_out_val->type == scalar_type);
19082 ErrorMsg *msg = ir_eval_negation_scalar(ira, &instruction->base, scalar_type,
20080 ErrorMsg *msg = ir_eval_negation_scalar(ira, &instruction->base.base, scalar_type,
1908320081 scalar_operand_val, scalar_out_val, is_wrap_op);
1908420082 if (msg != nullptr) {
19085 add_error_note(ira->codegen, msg, instruction->base.source_node,
20083 add_error_note(ira->codegen, msg, instruction->base.base.source_node,
1908620084 buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i));
19087 return ira->codegen->invalid_instruction;
20085 return ira->codegen->invalid_inst_gen;
1908820086 }
1908920087 }
1909020088 out_val->type = expr_type;
1909120089 out_val->special = ConstValSpecialStatic;
1909220090 } else {
19093 if (ir_eval_negation_scalar(ira, &instruction->base, scalar_type, operand_val, out_val,
20091 if (ir_eval_negation_scalar(ira, &instruction->base.base, scalar_type, operand_val, out_val,
1909420092 is_wrap_op) != nullptr)
1909520093 {
19096 return ira->codegen->invalid_instruction;
20094 return ira->codegen->invalid_inst_gen;
1909720095 }
1909820096 }
1909920097 return result_instruction;
1910020098 }
1910120099
19102 IrInstruction *result = ir_build_un_op(&ira->new_irb,
19103 instruction->base.scope, instruction->base.source_node,
19104 instruction->op_id, value);
19105 result->value->type = expr_type;
19106 return result;
20100 if (is_wrap_op) {
20101 return ir_build_negation_wrapping(ira, &instruction->base.base, value, expr_type);
20102 } else {
20103 return ir_build_negation(ira, &instruction->base.base, value, expr_type);
20104 }
1910720105}
1910820106
19109static IrInstruction *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *instruction) {
19110 IrInstruction *value = instruction->value->child;
20107static IrInstGen *ir_analyze_bin_not(IrAnalyze *ira, IrInstSrcUnOp *instruction) {
20108 IrInstGen *value = instruction->value->child;
1911120109 ZigType *expr_type = value->value->type;
1911220110 if (type_is_invalid(expr_type))
19113 return ira->codegen->invalid_instruction;
20111 return ira->codegen->invalid_inst_gen;
1911420112
1911520113 if (expr_type->id == ZigTypeIdInt) {
1911620114 if (instr_is_comptime(value)) {
1911720115 ZigValue *target_const_val = ir_resolve_const(ira, value, UndefBad);
1911820116 if (target_const_val == nullptr)
19119 return ira->codegen->invalid_instruction;
20117 return ira->codegen->invalid_inst_gen;
1912020118
19121 IrInstruction *result = ir_const(ira, &instruction->base, expr_type);
20119 IrInstGen *result = ir_const(ira, &instruction->base.base, expr_type);
1912220120 bigint_not(&result->value->data.x_bigint, &target_const_val->data.x_bigint,
1912320121 expr_type->data.integral.bit_count, expr_type->data.integral.is_signed);
1912420122 return result;
1912520123 }
1912620124
19127 IrInstruction *result = ir_build_un_op(&ira->new_irb, instruction->base.scope,
19128 instruction->base.source_node, IrUnOpBinNot, value);
19129 result->value->type = expr_type;
19130 return result;
20125 return ir_build_binary_not(ira, &instruction->base.base, value, expr_type);
1913120126 }
1913220127
19133 ir_add_error(ira, &instruction->base,
20128 ir_add_error(ira, &instruction->base.base,
1913420129 buf_sprintf("unable to perform binary not operation on type '%s'", buf_ptr(&expr_type->name)));
19135 return ira->codegen->invalid_instruction;
20130 return ira->codegen->invalid_inst_gen;
1913620131}
1913720132
19138static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstructionUnOp *instruction) {
20133static IrInstGen *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstSrcUnOp *instruction) {
1913920134 IrUnOp op_id = instruction->op_id;
1914020135 switch (op_id) {
1914120136 case IrUnOpInvalid:
......@@ -19146,26 +20141,26 @@ static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstruction
1914620141 case IrUnOpNegationWrap:
1914720142 return ir_analyze_negation(ira, instruction);
1914820143 case IrUnOpDereference: {
19149 IrInstruction *ptr = instruction->value->child;
20144 IrInstGen *ptr = instruction->value->child;
1915020145 if (type_is_invalid(ptr->value->type))
19151 return ira->codegen->invalid_instruction;
20146 return ira->codegen->invalid_inst_gen;
1915220147 ZigType *ptr_type = ptr->value->type;
1915320148 if (ptr_type->id == ZigTypeIdPointer && ptr_type->data.pointer.ptr_len == PtrLenUnknown) {
19154 ir_add_error_node(ira, instruction->base.source_node,
20149 ir_add_error_node(ira, instruction->base.base.source_node,
1915520150 buf_sprintf("index syntax required for unknown-length pointer type '%s'",
1915620151 buf_ptr(&ptr_type->name)));
19157 return ira->codegen->invalid_instruction;
20152 return ira->codegen->invalid_inst_gen;
1915820153 }
1915920154
19160 IrInstruction *result = ir_get_deref(ira, &instruction->base, ptr, instruction->result_loc);
19161 if (result == ira->codegen->invalid_instruction)
19162 return ira->codegen->invalid_instruction;
20155 IrInstGen *result = ir_get_deref(ira, &instruction->base.base, ptr, instruction->result_loc);
20156 if (type_is_invalid(result->value->type))
20157 return ira->codegen->invalid_inst_gen;
1916320158
1916420159 // If the result needs to be an lvalue, type check it
1916520160 if (instruction->lval == LValPtr && result->value->type->id != ZigTypeIdPointer) {
19166 ir_add_error(ira, &instruction->base,
20161 ir_add_error(ira, &instruction->base.base,
1916720162 buf_sprintf("attempt to dereference non-pointer type '%s'", buf_ptr(&result->value->type->name)));
19168 return ira->codegen->invalid_instruction;
20163 return ira->codegen->invalid_inst_gen;
1916920164 }
1917020165
1917120166 return result;
......@@ -19177,42 +20172,40 @@ static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstruction
1917720172}
1917820173
1917920174static void ir_push_resume(IrAnalyze *ira, IrSuspendPosition pos) {
19180 IrBasicBlock *old_bb = ira->old_irb.exec->basic_block_list.at(pos.basic_block_index);
20175 IrBasicBlockSrc *old_bb = ira->old_irb.exec->basic_block_list.at(pos.basic_block_index);
1918120176 if (old_bb->in_resume_stack) return;
1918220177 ira->resume_stack.append(pos);
1918320178 old_bb->in_resume_stack = true;
1918420179}
1918520180
19186static void ir_push_resume_block(IrAnalyze *ira, IrBasicBlock *old_bb) {
20181static void ir_push_resume_block(IrAnalyze *ira, IrBasicBlockSrc *old_bb) {
1918720182 if (ira->resume_stack.length != 0) {
1918820183 ir_push_resume(ira, {old_bb->index, 0});
1918920184 }
1919020185}
1919120186
19192static IrInstruction *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr *br_instruction) {
19193 IrBasicBlock *old_dest_block = br_instruction->dest_block;
20187static IrInstGen *ir_analyze_instruction_br(IrAnalyze *ira, IrInstSrcBr *br_instruction) {
20188 IrBasicBlockSrc *old_dest_block = br_instruction->dest_block;
1919420189
1919520190 bool is_comptime;
1919620191 if (!ir_resolve_comptime(ira, br_instruction->is_comptime->child, &is_comptime))
1919720192 return ir_unreach_error(ira);
1919820193
1919920194 if (is_comptime || (old_dest_block->ref_count == 1 && old_dest_block->suspend_instruction_ref == nullptr))
19200 return ir_inline_bb(ira, &br_instruction->base, old_dest_block);
20195 return ir_inline_bb(ira, &br_instruction->base.base, old_dest_block);
1920120196
19202 IrBasicBlock *new_bb = ir_get_new_bb_runtime(ira, old_dest_block, &br_instruction->base);
20197 IrBasicBlockGen *new_bb = ir_get_new_bb_runtime(ira, old_dest_block, &br_instruction->base.base);
1920320198 if (new_bb == nullptr)
1920420199 return ir_unreach_error(ira);
1920520200
1920620201 ir_push_resume_block(ira, old_dest_block);
1920720202
19208 IrInstruction *result = ir_build_br(&ira->new_irb,
19209 br_instruction->base.scope, br_instruction->base.source_node, new_bb, nullptr);
19210 result->value->type = ira->codegen->builtin_types.entry_unreachable;
20203 IrInstGen *result = ir_build_br_gen(ira, &br_instruction->base.base, new_bb);
1921120204 return ir_finish_anal(ira, result);
1921220205}
1921320206
19214static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructionCondBr *cond_br_instruction) {
19215 IrInstruction *condition = cond_br_instruction->condition->child;
20207static IrInstGen *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstSrcCondBr *cond_br_instruction) {
20208 IrInstGen *condition = cond_br_instruction->condition->child;
1921620209 if (type_is_invalid(condition->value->type))
1921720210 return ir_unreach_error(ira);
1921820211
......@@ -19221,7 +20214,7 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi
1922120214 return ir_unreach_error(ira);
1922220215
1922320216 ZigType *bool_type = ira->codegen->builtin_types.entry_bool;
19224 IrInstruction *casted_condition = ir_implicit_cast(ira, condition, bool_type);
20217 IrInstGen *casted_condition = ir_implicit_cast(ira, condition, bool_type);
1922520218 if (type_is_invalid(casted_condition->value->type))
1922620219 return ir_unreach_error(ira);
1922720220
......@@ -19230,67 +20223,61 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi
1923020223 if (!ir_resolve_bool(ira, casted_condition, &cond_is_true))
1923120224 return ir_unreach_error(ira);
1923220225
19233 IrBasicBlock *old_dest_block = cond_is_true ?
20226 IrBasicBlockSrc *old_dest_block = cond_is_true ?
1923420227 cond_br_instruction->then_block : cond_br_instruction->else_block;
1923520228
1923620229 if (is_comptime || (old_dest_block->ref_count == 1 && old_dest_block->suspend_instruction_ref == nullptr))
19237 return ir_inline_bb(ira, &cond_br_instruction->base, old_dest_block);
20230 return ir_inline_bb(ira, &cond_br_instruction->base.base, old_dest_block);
1923820231
19239 IrBasicBlock *new_dest_block = ir_get_new_bb_runtime(ira, old_dest_block, &cond_br_instruction->base);
20232 IrBasicBlockGen *new_dest_block = ir_get_new_bb_runtime(ira, old_dest_block, &cond_br_instruction->base.base);
1924020233 if (new_dest_block == nullptr)
1924120234 return ir_unreach_error(ira);
1924220235
1924320236 ir_push_resume_block(ira, old_dest_block);
1924420237
19245 IrInstruction *result = ir_build_br(&ira->new_irb,
19246 cond_br_instruction->base.scope, cond_br_instruction->base.source_node, new_dest_block, nullptr);
19247 result->value->type = ira->codegen->builtin_types.entry_unreachable;
20238 IrInstGen *result = ir_build_br_gen(ira, &cond_br_instruction->base.base, new_dest_block);
1924820239 return ir_finish_anal(ira, result);
1924920240 }
1925020241
1925120242 assert(cond_br_instruction->then_block != cond_br_instruction->else_block);
19252 IrBasicBlock *new_then_block = ir_get_new_bb_runtime(ira, cond_br_instruction->then_block, &cond_br_instruction->base);
20243 IrBasicBlockGen *new_then_block = ir_get_new_bb_runtime(ira, cond_br_instruction->then_block, &cond_br_instruction->base.base);
1925320244 if (new_then_block == nullptr)
1925420245 return ir_unreach_error(ira);
1925520246
19256 IrBasicBlock *new_else_block = ir_get_new_bb_runtime(ira, cond_br_instruction->else_block, &cond_br_instruction->base);
20247 IrBasicBlockGen *new_else_block = ir_get_new_bb_runtime(ira, cond_br_instruction->else_block, &cond_br_instruction->base.base);
1925720248 if (new_else_block == nullptr)
1925820249 return ir_unreach_error(ira);
1925920250
1926020251 ir_push_resume_block(ira, cond_br_instruction->else_block);
1926120252 ir_push_resume_block(ira, cond_br_instruction->then_block);
1926220253
19263 IrInstruction *result = ir_build_cond_br(&ira->new_irb,
19264 cond_br_instruction->base.scope, cond_br_instruction->base.source_node,
19265 casted_condition, new_then_block, new_else_block, nullptr);
19266 result->value->type = ira->codegen->builtin_types.entry_unreachable;
20254 IrInstGen *result = ir_build_cond_br_gen(ira, &cond_br_instruction->base.base,
20255 casted_condition, new_then_block, new_else_block);
1926720256 return ir_finish_anal(ira, result);
1926820257}
1926920258
19270static IrInstruction *ir_analyze_instruction_unreachable(IrAnalyze *ira,
19271 IrInstructionUnreachable *unreachable_instruction)
20259static IrInstGen *ir_analyze_instruction_unreachable(IrAnalyze *ira,
20260 IrInstSrcUnreachable *unreachable_instruction)
1927220261{
19273 IrInstruction *result = ir_build_unreachable(&ira->new_irb,
19274 unreachable_instruction->base.scope, unreachable_instruction->base.source_node);
19275 result->value->type = ira->codegen->builtin_types.entry_unreachable;
20262 IrInstGen *result = ir_build_unreachable_gen(ira, &unreachable_instruction->base.base);
1927620263 return ir_finish_anal(ira, result);
1927720264}
1927820265
19279static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPhi *phi_instruction) {
20266static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_instruction) {
1928020267 Error err;
1928120268
1928220269 if (ira->const_predecessor_bb) {
1928320270 for (size_t i = 0; i < phi_instruction->incoming_count; i += 1) {
19284 IrBasicBlock *predecessor = phi_instruction->incoming_blocks[i];
20271 IrBasicBlockSrc *predecessor = phi_instruction->incoming_blocks[i];
1928520272 if (predecessor != ira->const_predecessor_bb)
1928620273 continue;
19287 IrInstruction *value = phi_instruction->incoming_values[i]->child;
20274 IrInstGen *value = phi_instruction->incoming_values[i]->child;
1928820275 assert(value->value->type);
1928920276 if (type_is_invalid(value->value->type))
19290 return ira->codegen->invalid_instruction;
20277 return ira->codegen->invalid_inst_gen;
1929120278
1929220279 if (value->value->special != ConstValSpecialRuntime) {
19293 IrInstruction *result = ir_const(ira, &phi_instruction->base, nullptr);
20280 IrInstGen *result = ir_const(ira, &phi_instruction->base.base, nullptr);
1929420281 copy_const_val(result->value, value->value);
1929520282 return result;
1929620283 } else {
......@@ -19305,17 +20292,17 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1930520292 peer_parent->peers.length >= 2)
1930620293 {
1930720294 if (peer_parent->resolved_type == nullptr) {
19308 IrInstruction **instructions = allocate<IrInstruction *>(peer_parent->peers.length);
20295 IrInstGen **instructions = allocate<IrInstGen *>(peer_parent->peers.length);
1930920296 for (size_t i = 0; i < peer_parent->peers.length; i += 1) {
1931020297 ResultLocPeer *this_peer = peer_parent->peers.at(i);
1931120298
19312 IrInstruction *gen_instruction = this_peer->base.gen_instruction;
20299 IrInstGen *gen_instruction = this_peer->base.gen_instruction;
1931320300 if (gen_instruction == nullptr) {
1931420301 // unreachable instructions will cause implicit_elem_type to be null
1931520302 if (this_peer->base.implicit_elem_type == nullptr) {
19316 instructions[i] = ir_const_unreachable(ira, this_peer->base.source_instruction);
20303 instructions[i] = ir_const_unreachable(ira, &this_peer->base.source_instruction->base);
1931720304 } else {
19318 instructions[i] = ir_const(ira, this_peer->base.source_instruction,
20305 instructions[i] = ir_const(ira, &this_peer->base.source_instruction->base,
1931920306 this_peer->base.implicit_elem_type);
1932020307 instructions[i]->value->special = ConstValSpecialRuntime;
1932120308 }
......@@ -19324,34 +20311,34 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1932420311 }
1932520312
1932620313 }
19327 ZigType *expected_type = ir_result_loc_expected_type(ira, &phi_instruction->base, peer_parent->parent);
20314 ZigType *expected_type = ir_result_loc_expected_type(ira, &phi_instruction->base.base, peer_parent->parent);
1932820315 peer_parent->resolved_type = ir_resolve_peer_types(ira,
19329 peer_parent->base.source_instruction->source_node, expected_type, instructions,
20316 peer_parent->base.source_instruction->base.source_node, expected_type, instructions,
1933020317 peer_parent->peers.length);
1933120318 if (type_is_invalid(peer_parent->resolved_type))
19332 return ira->codegen->invalid_instruction;
20319 return ira->codegen->invalid_inst_gen;
1933320320
1933420321 // the logic below assumes there are no instructions in the new current basic block yet
19335 ir_assert(ira->new_irb.current_basic_block->instruction_list.length == 0, &phi_instruction->base);
20322 ir_assert(ira->new_irb.current_basic_block->instruction_list.length == 0, &phi_instruction->base.base);
1933620323
1933720324 // In case resolving the parent activates a suspend, do it now
19338 IrInstruction *parent_result_loc = ir_resolve_result(ira, &phi_instruction->base, peer_parent->parent,
20325 IrInstGen *parent_result_loc = ir_resolve_result(ira, &phi_instruction->base.base, peer_parent->parent,
1933920326 peer_parent->resolved_type, nullptr, false, false, true);
1934020327 if (parent_result_loc != nullptr &&
19341 (type_is_invalid(parent_result_loc->value->type) || instr_is_unreachable(parent_result_loc)))
20328 (type_is_invalid(parent_result_loc->value->type) || parent_result_loc->value->type->id == ZigTypeIdUnreachable))
1934220329 {
1934320330 return parent_result_loc;
1934420331 }
1934520332 // If the above code generated any instructions in the current basic block, we need
1934620333 // to move them to the peer parent predecessor.
19347 ZigList<IrInstruction *> instrs_to_move = {};
20334 ZigList<IrInstGen *> instrs_to_move = {};
1934820335 while (ira->new_irb.current_basic_block->instruction_list.length != 0) {
1934920336 instrs_to_move.append(ira->new_irb.current_basic_block->instruction_list.pop());
1935020337 }
1935120338 if (instrs_to_move.length != 0) {
19352 IrBasicBlock *predecessor = peer_parent->base.source_instruction->child->owner_bb;
19353 IrInstruction *branch_instruction = predecessor->instruction_list.pop();
19354 ir_assert(branch_instruction->value->type->id == ZigTypeIdUnreachable, &phi_instruction->base);
20339 IrBasicBlockGen *predecessor = peer_parent->base.source_instruction->child->owner_bb;
20340 IrInstGen *branch_instruction = predecessor->instruction_list.pop();
20341 ir_assert(branch_instruction->value->type->id == ZigTypeIdUnreachable, &phi_instruction->base.base);
1935520342 while (instrs_to_move.length != 0) {
1935620343 predecessor->instruction_list.append(instrs_to_move.pop());
1935720344 }
......@@ -19360,7 +20347,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1936020347 }
1936120348
1936220349 IrSuspendPosition suspend_pos;
19363 ira_suspend(ira, &phi_instruction->base, nullptr, &suspend_pos);
20350 ira_suspend(ira, &phi_instruction->base.base, nullptr, &suspend_pos);
1936420351 ir_push_resume(ira, suspend_pos);
1936520352
1936620353 for (size_t i = 0; i < peer_parent->peers.length; i += 1) {
......@@ -19376,34 +20363,32 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1937620363 return ira_resume(ira);
1937720364 }
1937820365
19379 ZigList<IrBasicBlock*> new_incoming_blocks = {0};
19380 ZigList<IrInstruction*> new_incoming_values = {0};
20366 ZigList<IrBasicBlockGen*> new_incoming_blocks = {0};
20367 ZigList<IrInstGen*> new_incoming_values = {0};
1938120368
1938220369 for (size_t i = 0; i < phi_instruction->incoming_count; i += 1) {
19383 IrBasicBlock *predecessor = phi_instruction->incoming_blocks[i];
20370 IrBasicBlockSrc *predecessor = phi_instruction->incoming_blocks[i];
1938420371 if (predecessor->ref_count == 0)
1938520372 continue;
1938620373
1938720374
19388 IrInstruction *old_value = phi_instruction->incoming_values[i];
20375 IrInstSrc *old_value = phi_instruction->incoming_values[i];
1938920376 assert(old_value);
19390 IrInstruction *new_value = old_value->child;
19391 if (!new_value || new_value->value->type->id == ZigTypeIdUnreachable || predecessor->other == nullptr)
20377 IrInstGen *new_value = old_value->child;
20378 if (!new_value || new_value->value->type->id == ZigTypeIdUnreachable || predecessor->child == nullptr)
1939220379 continue;
1939320380
1939420381 if (type_is_invalid(new_value->value->type))
19395 return ira->codegen->invalid_instruction;
20382 return ira->codegen->invalid_inst_gen;
1939620383
1939720384
19398 assert(predecessor->other);
19399 new_incoming_blocks.append(predecessor->other);
20385 assert(predecessor->child);
20386 new_incoming_blocks.append(predecessor->child);
1940020387 new_incoming_values.append(new_value);
1940120388 }
1940220389
1940320390 if (new_incoming_blocks.length == 0) {
19404 IrInstruction *result = ir_build_unreachable(&ira->new_irb,
19405 phi_instruction->base.scope, phi_instruction->base.source_node);
19406 result->value->type = ira->codegen->builtin_types.entry_unreachable;
20391 IrInstGen *result = ir_build_unreachable_gen(ira, &phi_instruction->base.base);
1940720392 return ir_finish_anal(ira, result);
1940820393 }
1940920394
......@@ -19415,7 +20400,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1941520400 if (peer_parent != nullptr) {
1941620401 bool peer_parent_has_type;
1941720402 if ((err = ir_result_has_type(ira, peer_parent->parent, &peer_parent_has_type)))
19418 return ira->codegen->invalid_instruction;
20403 return ira->codegen->invalid_inst_gen;
1941920404 if (peer_parent_has_type) {
1942020405 if (peer_parent->parent->id == ResultLocIdReturn) {
1942120406 resolved_type = ira->explicit_return_type;
......@@ -19423,27 +20408,27 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1942320408 resolved_type = ir_resolve_type(ira, peer_parent->parent->source_instruction->child);
1942420409 } else if (peer_parent->parent->resolved_loc) {
1942520410 ZigType *resolved_loc_ptr_type = peer_parent->parent->resolved_loc->value->type;
19426 ir_assert(resolved_loc_ptr_type->id == ZigTypeIdPointer, &phi_instruction->base);
20411 ir_assert(resolved_loc_ptr_type->id == ZigTypeIdPointer, &phi_instruction->base.base);
1942720412 resolved_type = resolved_loc_ptr_type->data.pointer.child_type;
1942820413 }
1942920414
1943020415 if (resolved_type != nullptr && type_is_invalid(resolved_type))
19431 return ira->codegen->invalid_instruction;
20416 return ira->codegen->invalid_inst_gen;
1943220417 }
1943320418 }
1943420419
1943520420 if (resolved_type == nullptr) {
19436 resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.source_node, nullptr,
20421 resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.base.source_node, nullptr,
1943720422 new_incoming_values.items, new_incoming_values.length);
1943820423 if (type_is_invalid(resolved_type))
19439 return ira->codegen->invalid_instruction;
20424 return ira->codegen->invalid_inst_gen;
1944020425 }
1944120426
1944220427 switch (type_has_one_possible_value(ira->codegen, resolved_type)) {
1944320428 case OnePossibleValueInvalid:
19444 return ira->codegen->invalid_instruction;
20429 return ira->codegen->invalid_inst_gen;
1944520430 case OnePossibleValueYes:
19446 return ir_const_move(ira, &phi_instruction->base,
20431 return ir_const_move(ira, &phi_instruction->base.base,
1944720432 get_the_one_possible_value(ira->codegen, resolved_type));
1944820433 case OnePossibleValueNo:
1944920434 break;
......@@ -19451,11 +20436,11 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1945120436
1945220437 switch (type_requires_comptime(ira->codegen, resolved_type)) {
1945320438 case ReqCompTimeInvalid:
19454 return ira->codegen->invalid_instruction;
20439 return ira->codegen->invalid_inst_gen;
1945520440 case ReqCompTimeYes:
19456 ir_add_error_node(ira, phi_instruction->base.source_node,
20441 ir_add_error(ira, &phi_instruction->base.base,
1945720442 buf_sprintf("values of type '%s' must be comptime known", buf_ptr(&resolved_type->name)));
19458 return ira->codegen->invalid_instruction;
20443 return ira->codegen->invalid_inst_gen;
1945920444 case ReqCompTimeNo:
1946020445 break;
1946120446 }
......@@ -19465,16 +20450,16 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1946520450 // cast all values to the resolved type. however we can't put cast instructions in front of the phi instruction.
1946620451 // so we go back and insert the casts as the last instruction in the corresponding predecessor blocks, and
1946720452 // then make sure the branch instruction is preserved.
19468 IrBasicBlock *cur_bb = ira->new_irb.current_basic_block;
20453 IrBasicBlockGen *cur_bb = ira->new_irb.current_basic_block;
1946920454 for (size_t i = 0; i < new_incoming_values.length; i += 1) {
19470 IrInstruction *new_value = new_incoming_values.at(i);
19471 IrBasicBlock *predecessor = new_incoming_blocks.at(i);
19472 ir_assert(predecessor->instruction_list.length != 0, &phi_instruction->base);
19473 IrInstruction *branch_instruction = predecessor->instruction_list.pop();
19474 ir_set_cursor_at_end(&ira->new_irb, predecessor);
19475 IrInstruction *casted_value = ir_implicit_cast(ira, new_value, resolved_type);
20455 IrInstGen *new_value = new_incoming_values.at(i);
20456 IrBasicBlockGen *predecessor = new_incoming_blocks.at(i);
20457 ir_assert(predecessor->instruction_list.length != 0, &phi_instruction->base.base);
20458 IrInstGen *branch_instruction = predecessor->instruction_list.pop();
20459 ir_set_cursor_at_end_gen(&ira->new_irb, predecessor);
20460 IrInstGen *casted_value = ir_implicit_cast(ira, new_value, resolved_type);
1947620461 if (type_is_invalid(casted_value->value->type)) {
19477 return ira->codegen->invalid_instruction;
20462 return ira->codegen->invalid_inst_gen;
1947820463 }
1947920464 new_incoming_values.items[i] = casted_value;
1948020465 predecessor->instruction_list.append(branch_instruction);
......@@ -19485,12 +20470,10 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1948520470 all_stack_ptrs = false;
1948620471 }
1948720472 }
19488 ir_set_cursor_at_end(&ira->new_irb, cur_bb);
20473 ir_set_cursor_at_end_gen(&ira->new_irb, cur_bb);
1948920474
19490 IrInstruction *result = ir_build_phi(&ira->new_irb,
19491 phi_instruction->base.scope, phi_instruction->base.source_node,
19492 new_incoming_blocks.length, new_incoming_blocks.items, new_incoming_values.items, nullptr);
19493 result->value->type = resolved_type;
20475 IrInstGen *result = ir_build_phi_gen(ira, &phi_instruction->base.base,
20476 new_incoming_blocks.length, new_incoming_blocks.items, new_incoming_values.items, resolved_type);
1949420477
1949520478 if (all_stack_ptrs) {
1949620479 assert(result->value->special == ConstValSpecialRuntime);
......@@ -19500,17 +20483,17 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1950020483 return result;
1950120484}
1950220485
19503static IrInstruction *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarPtr *instruction) {
20486static IrInstGen *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstSrcVarPtr *instruction) {
1950420487 ZigVar *var = instruction->var;
19505 IrInstruction *result = ir_get_var_ptr(ira, &instruction->base, var);
20488 IrInstGen *result = ir_get_var_ptr(ira, &instruction->base.base, var);
1950620489 if (instruction->crossed_fndef_scope != nullptr && !instr_is_comptime(result)) {
19507 ErrorMsg *msg = ir_add_error(ira, &instruction->base,
20490 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base,
1950820491 buf_sprintf("'%s' not accessible from inner function", var->name));
1950920492 add_error_note(ira->codegen, msg, instruction->crossed_fndef_scope->base.source_node,
1951020493 buf_sprintf("crossed function definition here"));
1951120494 add_error_note(ira->codegen, msg, var->decl_node,
1951220495 buf_sprintf("declared here"));
19513 return ira->codegen->invalid_instruction;
20496 return ira->codegen->invalid_inst_gen;
1951420497 }
1951520498 return result;
1951620499}
......@@ -19561,17 +20544,17 @@ static ZigType *adjust_ptr_len(CodeGen *g, ZigType *ptr_type, PtrLen ptr_len) {
1956120544 ptr_type->data.pointer.allow_zero);
1956220545}
1956320546
19564static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionElemPtr *elem_ptr_instruction) {
20547static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemPtr *elem_ptr_instruction) {
1956520548 Error err;
19566 IrInstruction *array_ptr = elem_ptr_instruction->array_ptr->child;
20549 IrInstGen *array_ptr = elem_ptr_instruction->array_ptr->child;
1956720550 if (type_is_invalid(array_ptr->value->type))
19568 return ira->codegen->invalid_instruction;
20551 return ira->codegen->invalid_inst_gen;
1956920552
1957020553 ZigValue *orig_array_ptr_val = array_ptr->value;
1957120554
19572 IrInstruction *elem_index = elem_ptr_instruction->elem_index->child;
20555 IrInstGen *elem_index = elem_ptr_instruction->elem_index->child;
1957320556 if (type_is_invalid(elem_index->value->type))
19574 return ira->codegen->invalid_instruction;
20557 return ira->codegen->invalid_inst_gen;
1957520558
1957620559 ZigType *ptr_type = orig_array_ptr_val->type;
1957720560 assert(ptr_type->id == ZigTypeIdPointer);
......@@ -19583,7 +20566,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1958320566 ZigType *return_type;
1958420567
1958520568 if (type_is_invalid(array_type)) {
19586 return ira->codegen->invalid_instruction;
20569 return ira->codegen->invalid_inst_gen;
1958720570 } else if (array_type->id == ZigTypeIdArray ||
1958820571 (array_type->id == ZigTypeIdPointer &&
1958920572 array_type->data.pointer.ptr_len == PtrLenSingle &&
......@@ -19594,15 +20577,15 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1959420577 ptr_type = ptr_type->data.pointer.child_type;
1959520578 if (orig_array_ptr_val->special != ConstValSpecialRuntime) {
1959620579 orig_array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val,
19597 elem_ptr_instruction->base.source_node);
20580 elem_ptr_instruction->base.base.source_node);
1959820581 if (orig_array_ptr_val == nullptr)
19599 return ira->codegen->invalid_instruction;
20582 return ira->codegen->invalid_inst_gen;
1960020583 }
1960120584 }
1960220585 if (array_type->data.array.len == 0) {
19603 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
20586 ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node,
1960420587 buf_sprintf("index 0 outside array of size 0"));
19605 return ira->codegen->invalid_instruction;
20588 return ira->codegen->invalid_inst_gen;
1960620589 }
1960720590 ZigType *child_type = array_type->data.array.child_type;
1960820591 if (ptr_type->data.pointer.host_int_bytes == 0) {
......@@ -19613,7 +20596,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1961320596 } else {
1961420597 uint64_t elem_val_scalar;
1961520598 if (!ir_resolve_usize(ira, elem_index, &elem_val_scalar))
19616 return ira->codegen->invalid_instruction;
20599 return ira->codegen->invalid_inst_gen;
1961720600
1961820601 size_t bit_width = type_size_bits(ira->codegen, child_type);
1961920602 size_t bit_offset = bit_width * elem_val_scalar;
......@@ -19625,9 +20608,9 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1962520608 }
1962620609 } else if (array_type->id == ZigTypeIdPointer) {
1962720610 if (array_type->data.pointer.ptr_len == PtrLenSingle) {
19628 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
20611 ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node,
1962920612 buf_sprintf("index of single-item pointer"));
19630 return ira->codegen->invalid_instruction;
20613 return ira->codegen->invalid_inst_gen;
1963120614 }
1963220615 return_type = adjust_ptr_len(ira->codegen, array_type, elem_ptr_instruction->ptr_len);
1963320616 } else if (is_slice(array_type)) {
......@@ -19641,38 +20624,38 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1964120624 array_type->data.structure.resolve_status == ResolveStatusBeingInferred)
1964220625 {
1964320626 ZigType *usize = ira->codegen->builtin_types.entry_usize;
19644 IrInstruction *casted_elem_index = ir_implicit_cast(ira, elem_index, usize);
20627 IrInstGen *casted_elem_index = ir_implicit_cast(ira, elem_index, usize);
1964520628 if (type_is_invalid(casted_elem_index->value->type))
19646 return ira->codegen->invalid_instruction;
19647 ir_assert(instr_is_comptime(casted_elem_index), &elem_ptr_instruction->base);
20629 return ira->codegen->invalid_inst_gen;
20630 ir_assert(instr_is_comptime(casted_elem_index), &elem_ptr_instruction->base.base);
1964820631 Buf *field_name = buf_alloc();
1964920632 bigint_append_buf(field_name, &casted_elem_index->value->data.x_bigint, 10);
19650 return ir_analyze_inferred_field_ptr(ira, field_name, &elem_ptr_instruction->base,
20633 return ir_analyze_inferred_field_ptr(ira, field_name, &elem_ptr_instruction->base.base,
1965120634 array_ptr, array_type);
1965220635 } else if (is_tuple(array_type)) {
1965320636 uint64_t elem_index_scalar;
1965420637 if (!ir_resolve_usize(ira, elem_index, &elem_index_scalar))
19655 return ira->codegen->invalid_instruction;
20638 return ira->codegen->invalid_inst_gen;
1965620639 if (elem_index_scalar >= array_type->data.structure.src_field_count) {
19657 ir_add_error(ira, &elem_ptr_instruction->base, buf_sprintf(
20640 ir_add_error(ira, &elem_ptr_instruction->base.base, buf_sprintf(
1965820641 "field index %" ZIG_PRI_u64 " outside tuple '%s' which has %" PRIu32 " fields",
1965920642 elem_index_scalar, buf_ptr(&array_type->name),
1966020643 array_type->data.structure.src_field_count));
19661 return ira->codegen->invalid_instruction;
20644 return ira->codegen->invalid_inst_gen;
1966220645 }
1966320646 TypeStructField *field = array_type->data.structure.fields[elem_index_scalar];
19664 return ir_analyze_struct_field_ptr(ira, &elem_ptr_instruction->base, field, array_ptr,
20647 return ir_analyze_struct_field_ptr(ira, &elem_ptr_instruction->base.base, field, array_ptr,
1966520648 array_type, false);
1966620649 } else {
19667 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
20650 ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node,
1966820651 buf_sprintf("array access of non-array type '%s'", buf_ptr(&array_type->name)));
19669 return ira->codegen->invalid_instruction;
20652 return ira->codegen->invalid_inst_gen;
1967020653 }
1967120654
1967220655 ZigType *usize = ira->codegen->builtin_types.entry_usize;
19673 IrInstruction *casted_elem_index = ir_implicit_cast(ira, elem_index, usize);
19674 if (casted_elem_index == ira->codegen->invalid_instruction)
19675 return ira->codegen->invalid_instruction;
20656 IrInstGen *casted_elem_index = ir_implicit_cast(ira, elem_index, usize);
20657 if (type_is_invalid(casted_elem_index->value->type))
20658 return ira->codegen->invalid_inst_gen;
1967620659
1967720660 bool safety_check_on = elem_ptr_instruction->safety_check_on;
1967820661 if (instr_is_comptime(casted_elem_index)) {
......@@ -19681,15 +20664,15 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1968120664 uint64_t array_len = array_type->data.array.len;
1968220665 if (index == array_len && array_type->data.array.sentinel != nullptr) {
1968320666 ZigType *elem_type = array_type->data.array.child_type;
19684 IrInstruction *sentinel_elem = ir_const(ira, &elem_ptr_instruction->base, elem_type);
20667 IrInstGen *sentinel_elem = ir_const(ira, &elem_ptr_instruction->base.base, elem_type);
1968520668 copy_const_val(sentinel_elem->value, array_type->data.array.sentinel);
19686 return ir_get_ref(ira, &elem_ptr_instruction->base, sentinel_elem, true, false);
20669 return ir_get_ref(ira, &elem_ptr_instruction->base.base, sentinel_elem, true, false);
1968720670 }
1968820671 if (index >= array_len) {
19689 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
20672 ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node,
1969020673 buf_sprintf("index %" ZIG_PRI_u64 " outside array of size %" ZIG_PRI_u64,
1969120674 index, array_len));
19692 return ira->codegen->invalid_instruction;
20675 return ira->codegen->invalid_inst_gen;
1969320676 }
1969420677 safety_check_on = false;
1969520678 }
......@@ -19705,7 +20688,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1970520688 // figure out the largest alignment possible
1970620689
1970720690 if ((err = type_resolve(ira->codegen, return_type->data.pointer.child_type, ResolveStatusSizeKnown)))
19708 return ira->codegen->invalid_instruction;
20691 return ira->codegen->invalid_inst_gen;
1970920692
1971020693 uint64_t elem_size = type_size(ira->codegen, return_type->data.pointer.child_type);
1971120694 uint64_t abi_align = get_abi_alignment(ira->codegen, return_type->data.pointer.child_type);
......@@ -19735,9 +20718,9 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1973520718 array_type->id == ZigTypeIdArray))
1973620719 {
1973720720 ZigValue *array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val,
19738 elem_ptr_instruction->base.source_node);
20721 elem_ptr_instruction->base.base.source_node);
1973920722 if (array_ptr_val == nullptr)
19740 return ira->codegen->invalid_instruction;
20723 return ira->codegen->invalid_inst_gen;
1974120724
1974220725 if (array_ptr_val->special == ConstValSpecialUndef &&
1974320726 elem_ptr_instruction->init_array_type_source_node != nullptr)
......@@ -19755,16 +20738,16 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1975520738 elem_val->parent.data.p_array.elem_index = i;
1975620739 }
1975720740 } else if (is_slice(array_type)) {
19758 ir_assert(array_ptr->value->type->id == ZigTypeIdPointer, &elem_ptr_instruction->base);
20741 ir_assert(array_ptr->value->type->id == ZigTypeIdPointer, &elem_ptr_instruction->base.base);
1975920742 ZigType *actual_array_type = array_ptr->value->type->data.pointer.child_type;
1976020743
1976120744 if (type_is_invalid(actual_array_type))
19762 return ira->codegen->invalid_instruction;
20745 return ira->codegen->invalid_inst_gen;
1976320746 if (actual_array_type->id != ZigTypeIdArray) {
1976420747 ir_add_error_node(ira, elem_ptr_instruction->init_array_type_source_node,
1976520748 buf_sprintf("array literal requires address-of operator to coerce to slice type '%s'",
1976620749 buf_ptr(&actual_array_type->name)));
19767 return ira->codegen->invalid_instruction;
20750 return ira->codegen->invalid_inst_gen;
1976820751 }
1976920752
1977020753 ZigValue *array_init_val = create_const_vals(1);
......@@ -19789,7 +20772,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1978920772 ir_add_error_node(ira, elem_ptr_instruction->init_array_type_source_node,
1979020773 buf_sprintf("expected array type or [_], found '%s'",
1979120774 buf_ptr(&array_type->name)));
19792 return ira->codegen->invalid_instruction;
20775 return ira->codegen->invalid_inst_gen;
1979320776 }
1979420777 }
1979520778
......@@ -19798,7 +20781,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1979820781 array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr))
1979920782 {
1980020783 if (array_type->id == ZigTypeIdPointer) {
19801 IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type);
20784 IrInstGen *result = ir_const(ira, &elem_ptr_instruction->base.base, return_type);
1980220785 ZigValue *out_val = result->value;
1980320786 out_val->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut;
1980420787 size_t new_index;
......@@ -19867,33 +20850,31 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1986720850 zig_panic("TODO elem ptr on a null pointer");
1986820851 }
1986920852 if (new_index >= mem_size) {
19870 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
20853 ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node,
1987120854 buf_sprintf("index %" ZIG_PRI_u64 " outside pointer of size %" ZIG_PRI_usize "", index, old_size));
19872 return ira->codegen->invalid_instruction;
20855 return ira->codegen->invalid_inst_gen;
1987320856 }
1987420857 return result;
1987520858 } else if (is_slice(array_type)) {
1987620859 ZigValue *ptr_field = array_ptr_val->data.x_struct.fields[slice_ptr_index];
19877 ir_assert(ptr_field != nullptr, &elem_ptr_instruction->base);
20860 ir_assert(ptr_field != nullptr, &elem_ptr_instruction->base.base);
1987820861 if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
19879 IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope,
19880 elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, false,
19881 elem_ptr_instruction->ptr_len, nullptr);
19882 result->value->type = return_type;
19883 return result;
20862 return ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.base.scope,
20863 elem_ptr_instruction->base.base.source_node, array_ptr, casted_elem_index, false,
20864 return_type);
1988420865 }
1988520866 ZigValue *len_field = array_ptr_val->data.x_struct.fields[slice_len_index];
19886 IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type);
20867 IrInstGen *result = ir_const(ira, &elem_ptr_instruction->base.base, return_type);
1988720868 ZigValue *out_val = result->value;
1988820869 ZigType *slice_ptr_type = array_type->data.structure.fields[slice_ptr_index]->type_entry;
1988920870 uint64_t slice_len = bigint_as_u64(&len_field->data.x_bigint);
1989020871 uint64_t full_slice_len = slice_len +
1989120872 ((slice_ptr_type->data.pointer.sentinel != nullptr) ? 1 : 0);
1989220873 if (index >= full_slice_len) {
19893 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
20874 ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node,
1989420875 buf_sprintf("index %" ZIG_PRI_u64 " outside slice of size %" ZIG_PRI_u64,
1989520876 index, slice_len));
19896 return ira->codegen->invalid_instruction;
20877 return ira->codegen->invalid_inst_gen;
1989720878 }
1989820879 out_val->data.x_ptr.mut = ptr_field->data.x_ptr.mut;
1989920880 switch (ptr_field->data.x_ptr.special) {
......@@ -19913,7 +20894,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1991320894 {
1991420895 ir_assert(new_index <
1991520896 ptr_field->data.x_ptr.data.base_array.array_val->type->data.array.len,
19916 &elem_ptr_instruction->base);
20897 &elem_ptr_instruction->base.base);
1991720898 }
1991820899 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
1991920900 out_val->data.x_ptr.data.base_array.array_val =
......@@ -19938,15 +20919,14 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1993820919 }
1993920920 return result;
1994020921 } else if (array_type->id == ZigTypeIdArray || array_type->id == ZigTypeIdVector) {
19941 IrInstruction *result;
20922 IrInstGen *result;
1994220923 if (orig_array_ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
19943 result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope,
19944 elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index,
19945 false, elem_ptr_instruction->ptr_len, nullptr);
19946 result->value->type = return_type;
20924 result = ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.base.scope,
20925 elem_ptr_instruction->base.base.source_node, array_ptr, casted_elem_index,
20926 false, return_type);
1994720927 result->value->special = ConstValSpecialStatic;
1994820928 } else {
19949 result = ir_const(ira, &elem_ptr_instruction->base, return_type);
20929 result = ir_const(ira, &elem_ptr_instruction->base.base, return_type);
1995020930 }
1995120931 ZigValue *out_val = result->value;
1995220932 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
......@@ -19972,19 +20952,19 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1997220952 // runtime known element index
1997320953 switch (type_requires_comptime(ira->codegen, return_type)) {
1997420954 case ReqCompTimeYes:
19975 ir_add_error(ira, elem_index,
20955 ir_add_error(ira, &elem_index->base,
1997620956 buf_sprintf("values of type '%s' must be comptime known, but index value is runtime known",
1997720957 buf_ptr(&return_type->data.pointer.child_type->name)));
19978 return ira->codegen->invalid_instruction;
20958 return ira->codegen->invalid_inst_gen;
1997920959 case ReqCompTimeInvalid:
19980 return ira->codegen->invalid_instruction;
20960 return ira->codegen->invalid_inst_gen;
1998120961 case ReqCompTimeNo:
1998220962 break;
1998320963 }
1998420964
1998520965 if (return_type->data.pointer.explicit_alignment != 0) {
1998620966 if ((err = type_resolve(ira->codegen, return_type->data.pointer.child_type, ResolveStatusSizeKnown)))
19987 return ira->codegen->invalid_instruction;
20967 return ira->codegen->invalid_inst_gen;
1998820968
1998920969 uint64_t elem_size = type_size(ira->codegen, return_type->data.pointer.child_type);
1999020970 uint64_t abi_align = get_abi_alignment(ira->codegen, return_type->data.pointer.child_type);
......@@ -20002,16 +20982,13 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
2000220982 }
2000320983 }
2000420984
20005 IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope,
20006 elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, safety_check_on,
20007 elem_ptr_instruction->ptr_len, nullptr);
20008 result->value->type = return_type;
20009 return result;
20985 return ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.base.scope,
20986 elem_ptr_instruction->base.base.source_node, array_ptr, casted_elem_index, safety_check_on, return_type);
2001020987}
2001120988
20012static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,
20013 ZigType *bare_struct_type, Buf *field_name, IrInstruction *source_instr,
20014 IrInstruction *container_ptr, ZigType *container_type)
20989static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira,
20990 ZigType *bare_struct_type, Buf *field_name, IrInst* source_instr,
20991 IrInstGen *container_ptr, ZigType *container_type)
2001520992{
2001620993 if (!is_slice(bare_struct_type)) {
2001720994 ScopeDecls *container_scope = get_container_scope(bare_struct_type);
......@@ -20021,29 +20998,27 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,
2002120998 if (tld->id == TldIdFn) {
2002220999 resolve_top_level_decl(ira->codegen, tld, source_instr->source_node, false);
2002321000 if (tld->resolution == TldResolutionInvalid)
20024 return ira->codegen->invalid_instruction;
21001 return ira->codegen->invalid_inst_gen;
2002521002 TldFn *tld_fn = (TldFn *)tld;
2002621003 ZigFn *fn_entry = tld_fn->fn_entry;
2002721004 if (type_is_invalid(fn_entry->type_entry))
20028 return ira->codegen->invalid_instruction;
21005 return ira->codegen->invalid_inst_gen;
2002921006
20030 IrInstruction *bound_fn_value = ir_build_const_bound_fn(&ira->new_irb, source_instr->scope,
20031 source_instr->source_node, fn_entry, container_ptr);
21007 IrInstGen *bound_fn_value = ir_const_bound_fn(ira, source_instr, fn_entry, container_ptr);
2003221008 return ir_get_ref(ira, source_instr, bound_fn_value, true, false);
2003321009 } else if (tld->id == TldIdVar) {
2003421010 resolve_top_level_decl(ira->codegen, tld, source_instr->source_node, false);
2003521011 if (tld->resolution == TldResolutionInvalid)
20036 return ira->codegen->invalid_instruction;
21012 return ira->codegen->invalid_inst_gen;
2003721013 TldVar *tld_var = (TldVar *)tld;
2003821014 ZigVar *var = tld_var->var;
2003921015 if (type_is_invalid(var->var_type))
20040 return ira->codegen->invalid_instruction;
21016 return ira->codegen->invalid_inst_gen;
2004121017
2004221018 if (var->const_value->type->id == ZigTypeIdFn) {
2004321019 ir_assert(var->const_value->data.x_ptr.special == ConstPtrSpecialFunction, source_instr);
2004421020 ZigFn *fn = var->const_value->data.x_ptr.data.fn.fn_entry;
20045 IrInstruction *bound_fn_value = ir_build_const_bound_fn(&ira->new_irb, source_instr->scope,
20046 source_instr->source_node, fn, container_ptr);
21021 IrInstGen *bound_fn_value = ir_const_bound_fn(ira, source_instr, fn, container_ptr);
2004721022 return ir_get_ref(ira, source_instr, bound_fn_value, true, false);
2004821023 }
2004921024 }
......@@ -20063,7 +21038,7 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,
2006321038 }
2006421039 ir_add_error_node(ira, source_instr->source_node,
2006521040 buf_sprintf("no member named '%s' in %s'%s'", buf_ptr(field_name), prefix_name, buf_ptr(&bare_struct_type->name)));
20066 return ira->codegen->invalid_instruction;
21041 return ira->codegen->invalid_inst_gen;
2006721042}
2006821043
2006921044static void memoize_field_init_val(CodeGen *codegen, ZigType *container_type, TypeStructField *field) {
......@@ -20078,24 +21053,24 @@ static void memoize_field_init_val(CodeGen *codegen, ZigType *container_type, Ty
2007821053 field->type_entry, nullptr, UndefOk);
2007921054}
2008021055
20081static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction *source_instr,
20082 TypeStructField *field, IrInstruction *struct_ptr, ZigType *struct_type, bool initializing)
21056static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_instr,
21057 TypeStructField *field, IrInstGen *struct_ptr, ZigType *struct_type, bool initializing)
2008321058{
2008421059 Error err;
2008521060 ZigType *field_type = resolve_struct_field_type(ira->codegen, field);
2008621061 if (field_type == nullptr)
20087 return ira->codegen->invalid_instruction;
21062 return ira->codegen->invalid_inst_gen;
2008821063 if (field->is_comptime) {
20089 IrInstruction *elem = ir_const(ira, source_instr, field_type);
21064 IrInstGen *elem = ir_const(ira, source_instr, field_type);
2009021065 memoize_field_init_val(ira->codegen, struct_type, field);
2009121066 copy_const_val(elem->value, field->init_val);
2009221067 return ir_get_ref(ira, source_instr, elem, true, false);
2009321068 }
2009421069 switch (type_has_one_possible_value(ira->codegen, field_type)) {
2009521070 case OnePossibleValueInvalid:
20096 return ira->codegen->invalid_instruction;
21071 return ira->codegen->invalid_inst_gen;
2009721072 case OnePossibleValueYes: {
20098 IrInstruction *elem = ir_const_move(ira, source_instr,
21073 IrInstGen *elem = ir_const_move(ira, source_instr,
2009921074 get_the_one_possible_value(ira->codegen, field_type));
2010021075 return ir_get_ref(ira, source_instr, elem, false, false);
2010121076 }
......@@ -20113,7 +21088,7 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction
2011321088 (struct_type->data.structure.layout == ContainerLayoutAuto) ?
2011421089 ResolveStatusZeroBitsKnown : ResolveStatusSizeKnown;
2011521090 if ((err = type_resolve(ira->codegen, struct_type, needed_resolve_status)))
20116 return ira->codegen->invalid_instruction;
21091 return ira->codegen->invalid_inst_gen;
2011721092 assert(struct_ptr->value->type->id == ZigTypeIdPointer);
2011821093 uint32_t ptr_bit_offset = struct_ptr->value->type->data.pointer.bit_offset_in_host;
2011921094 uint32_t ptr_host_int_bytes = struct_ptr->value->type->data.pointer.host_int_bytes;
......@@ -20127,14 +21102,14 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction
2012721102 if (instr_is_comptime(struct_ptr)) {
2012821103 ZigValue *ptr_val = ir_resolve_const(ira, struct_ptr, UndefBad);
2012921104 if (!ptr_val)
20130 return ira->codegen->invalid_instruction;
21105 return ira->codegen->invalid_inst_gen;
2013121106
2013221107 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
2013321108 ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
2013421109 if (struct_val == nullptr)
20135 return ira->codegen->invalid_instruction;
21110 return ira->codegen->invalid_inst_gen;
2013621111 if (type_is_invalid(struct_val->type))
20137 return ira->codegen->invalid_instruction;
21112 return ira->codegen->invalid_inst_gen;
2013821113 if (initializing && struct_val->special == ConstValSpecialUndef) {
2013921114 struct_val->data.x_struct.fields = alloc_const_vals_ptrs(struct_type->data.structure.src_field_count);
2014021115 struct_val->special = ConstValSpecialStatic;
......@@ -20148,11 +21123,9 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction
2014821123 field_val->parent.data.p_struct.field_index = i;
2014921124 }
2015021125 }
20151 IrInstruction *result;
21126 IrInstGen *result;
2015221127 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
20153 result = ir_build_struct_field_ptr(&ira->new_irb, source_instr->scope,
20154 source_instr->source_node, struct_ptr, field);
20155 result->value->type = ptr_type;
21128 result = ir_build_struct_field_ptr(ira, source_instr, struct_ptr, field, ptr_type);
2015621129 result->value->special = ConstValSpecialStatic;
2015721130 } else {
2015821131 result = ir_const(ira, source_instr, ptr_type);
......@@ -20165,14 +21138,11 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction
2016521138 return result;
2016621139 }
2016721140 }
20168 IrInstruction *result = ir_build_struct_field_ptr(&ira->new_irb, source_instr->scope, source_instr->source_node,
20169 struct_ptr, field);
20170 result->value->type = ptr_type;
20171 return result;
21141 return ir_build_struct_field_ptr(ira, source_instr, struct_ptr, field, ptr_type);
2017221142}
2017321143
20174static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,
20175 IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type)
21144static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,
21145 IrInst* source_instr, IrInstGen *container_ptr, ZigType *container_type)
2017621146{
2017721147 // The type of the field is not available until a store using this pointer happens.
2017821148 // So, here we create a special pointer type which has the inferred struct type and
......@@ -20195,12 +21165,11 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n
2019521165 if (instr_is_comptime(container_ptr)) {
2019621166 ZigValue *ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
2019721167 if (ptr_val == nullptr)
20198 return ira->codegen->invalid_instruction;
21168 return ira->codegen->invalid_inst_gen;
2019921169
20200 IrInstruction *result;
21170 IrInstGen *result;
2020121171 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
20202 result = ir_build_cast(&ira->new_irb, source_instr->scope,
20203 source_instr->source_node, container_ptr_type, container_ptr, CastOpNoop);
21172 result = ir_build_cast(ira, source_instr, container_ptr_type, container_ptr, CastOpNoop);
2020421173 } else {
2020521174 result = ir_const(ira, source_instr, field_ptr_type);
2020621175 }
......@@ -20209,14 +21178,11 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n
2020921178 return result;
2021021179 }
2021121180
20212 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope,
20213 source_instr->source_node, field_ptr_type, container_ptr, CastOpNoop);
20214 result->value->type = field_ptr_type;
20215 return result;
21181 return ir_build_cast(ira, source_instr, field_ptr_type, container_ptr, CastOpNoop);
2021621182}
2021721183
20218static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,
20219 IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type, bool initializing)
21184static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,
21185 IrInst* source_instr, IrInstGen *container_ptr, ZigType *container_type, bool initializing)
2022021186{
2022121187 Error err;
2022221188
......@@ -20229,7 +21195,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
2022921195 }
2023021196
2023121197 if ((err = type_resolve(ira->codegen, bare_type, ResolveStatusZeroBitsKnown)))
20232 return ira->codegen->invalid_instruction;
21198 return ira->codegen->invalid_inst_gen;
2023321199
2023421200 assert(container_ptr->value->type->id == ZigTypeIdPointer);
2023521201 if (bare_type->id == ZigTypeIdStruct) {
......@@ -20259,22 +21225,22 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
2025921225
2026021226 ZigType *field_type = resolve_union_field_type(ira->codegen, field);
2026121227 if (field_type == nullptr)
20262 return ira->codegen->invalid_instruction;
21228 return ira->codegen->invalid_inst_gen;
2026321229
2026421230 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type,
2026521231 is_const, is_volatile, PtrLenSingle, 0, 0, 0, false);
2026621232 if (instr_is_comptime(container_ptr)) {
2026721233 ZigValue *ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
2026821234 if (!ptr_val)
20269 return ira->codegen->invalid_instruction;
21235 return ira->codegen->invalid_inst_gen;
2027021236
2027121237 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar &&
2027221238 ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
2027321239 ZigValue *union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
2027421240 if (union_val == nullptr)
20275 return ira->codegen->invalid_instruction;
21241 return ira->codegen->invalid_inst_gen;
2027621242 if (type_is_invalid(union_val->type))
20277 return ira->codegen->invalid_instruction;
21243 return ira->codegen->invalid_inst_gen;
2027821244
2027921245 if (initializing) {
2028021246 ZigValue *payload_val = create_const_vals(1);
......@@ -20295,17 +21261,16 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
2029521261 ir_add_error_node(ira, source_instr->source_node,
2029621262 buf_sprintf("accessing union field '%s' while field '%s' is set", buf_ptr(field_name),
2029721263 buf_ptr(actual_field->name)));
20298 return ira->codegen->invalid_instruction;
21264 return ira->codegen->invalid_inst_gen;
2029921265 }
2030021266 }
2030121267
2030221268 ZigValue *payload_val = union_val->data.x_union.payload;
2030321269
20304 IrInstruction *result;
21270 IrInstGen *result;
2030521271 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
20306 result = ir_build_union_field_ptr(&ira->new_irb, source_instr->scope,
20307 source_instr->source_node, container_ptr, field, true, initializing);
20308 result->value->type = ptr_type;
21272 result = ir_build_union_field_ptr(ira, source_instr, container_ptr, field, true,
21273 initializing, ptr_type);
2030921274 result->value->special = ConstValSpecialStatic;
2031021275 } else {
2031121276 result = ir_const(ira, source_instr, ptr_type);
......@@ -20318,10 +21283,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
2031821283 }
2031921284 }
2032021285
20321 IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb, source_instr->scope,
20322 source_instr->source_node, container_ptr, field, true, initializing);
20323 result->value->type = ptr_type;
20324 return result;
21286 return ir_build_union_field_ptr(ira, source_instr, container_ptr, field, true, initializing, ptr_type);
2032521287 }
2032621288
2032721289 zig_unreachable();
......@@ -20362,15 +21324,15 @@ static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name,
2036221324 link_lib->symbols.append(symbol_name);
2036321325}
2036421326
20365static IrInstruction *ir_error_dependency_loop(IrAnalyze *ira, IrInstruction *source_instr) {
21327static IrInstGen *ir_error_dependency_loop(IrAnalyze *ira, IrInst* source_instr) {
2036621328 ir_add_error(ira, source_instr, buf_sprintf("dependency loop detected"));
20367 return ira->codegen->invalid_instruction;
21329 return ira->codegen->invalid_inst_gen;
2036821330}
2036921331
20370static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instruction, Tld *tld) {
21332static IrInstGen *ir_analyze_decl_ref(IrAnalyze *ira, IrInst* source_instruction, Tld *tld) {
2037121333 resolve_top_level_decl(ira->codegen, tld, source_instruction->source_node, true);
2037221334 if (tld->resolution == TldResolutionInvalid) {
20373 return ira->codegen->invalid_instruction;
21335 return ira->codegen->invalid_inst_gen;
2037421336 }
2037521337
2037621338 switch (tld->id) {
......@@ -20397,14 +21359,13 @@ static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_
2039721359 assert(fn_entry->type_entry);
2039821360
2039921361 if (type_is_invalid(fn_entry->type_entry))
20400 return ira->codegen->invalid_instruction;
21362 return ira->codegen->invalid_inst_gen;
2040121363
2040221364 if (tld_fn->extern_lib_name != nullptr) {
2040321365 add_link_lib_symbol(ira, tld_fn->extern_lib_name, &fn_entry->symbol_name, source_instruction->source_node);
2040421366 }
2040521367
20406 IrInstruction *fn_inst = ir_create_const_fn(&ira->new_irb, source_instruction->scope,
20407 source_instruction->source_node, fn_entry);
21368 IrInstGen *fn_inst = ir_const_fn(ira, source_instruction, fn_entry);
2040821369 return ir_get_ref(ira, source_instruction, fn_inst, true, false);
2040921370 }
2041021371 }
......@@ -20422,40 +21383,40 @@ static ErrorTableEntry *find_err_table_entry(ZigType *err_set_type, Buf *field_n
2042221383 return nullptr;
2042321384}
2042421385
20425static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFieldPtr *field_ptr_instruction) {
21386static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFieldPtr *field_ptr_instruction) {
2042621387 Error err;
20427 IrInstruction *container_ptr = field_ptr_instruction->container_ptr->child;
21388 IrInstGen *container_ptr = field_ptr_instruction->container_ptr->child;
2042821389 if (type_is_invalid(container_ptr->value->type))
20429 return ira->codegen->invalid_instruction;
21390 return ira->codegen->invalid_inst_gen;
2043021391
2043121392 ZigType *container_type = container_ptr->value->type->data.pointer.child_type;
2043221393
2043321394 Buf *field_name = field_ptr_instruction->field_name_buffer;
2043421395 if (!field_name) {
20435 IrInstruction *field_name_expr = field_ptr_instruction->field_name_expr->child;
21396 IrInstGen *field_name_expr = field_ptr_instruction->field_name_expr->child;
2043621397 field_name = ir_resolve_str(ira, field_name_expr);
2043721398 if (!field_name)
20438 return ira->codegen->invalid_instruction;
21399 return ira->codegen->invalid_inst_gen;
2043921400 }
2044021401
2044121402
20442 AstNode *source_node = field_ptr_instruction->base.source_node;
21403 AstNode *source_node = field_ptr_instruction->base.base.source_node;
2044321404
2044421405 if (type_is_invalid(container_type)) {
20445 return ira->codegen->invalid_instruction;
21406 return ira->codegen->invalid_inst_gen;
2044621407 } else if (is_tuple(container_type) && !field_ptr_instruction->initializing && buf_eql_str(field_name, "len")) {
20447 IrInstruction *len_inst = ir_const_unsigned(ira, &field_ptr_instruction->base,
21408 IrInstGen *len_inst = ir_const_unsigned(ira, &field_ptr_instruction->base.base,
2044821409 container_type->data.structure.src_field_count);
20449 return ir_get_ref(ira, &field_ptr_instruction->base, len_inst, true, false);
21410 return ir_get_ref(ira, &field_ptr_instruction->base.base, len_inst, true, false);
2045021411 } else if (is_slice(container_type) || is_container_ref(container_type)) {
2045121412 assert(container_ptr->value->type->id == ZigTypeIdPointer);
2045221413 if (container_type->id == ZigTypeIdPointer) {
2045321414 ZigType *bare_type = container_ref_type(container_type);
20454 IrInstruction *container_child = ir_get_deref(ira, &field_ptr_instruction->base, container_ptr, nullptr);
20455 IrInstruction *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base, container_child, bare_type, field_ptr_instruction->initializing);
21415 IrInstGen *container_child = ir_get_deref(ira, &field_ptr_instruction->base.base, container_ptr, nullptr);
21416 IrInstGen *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base.base, container_child, bare_type, field_ptr_instruction->initializing);
2045621417 return result;
2045721418 } else {
20458 IrInstruction *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base, container_ptr, container_type, field_ptr_instruction->initializing);
21419 IrInstGen *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base.base, container_ptr, container_type, field_ptr_instruction->initializing);
2045921420 return result;
2046021421 }
2046121422 } else if (is_array_ref(container_type) && !field_ptr_instruction->initializing) {
......@@ -20470,42 +21431,42 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
2047021431 ZigType *usize = ira->codegen->builtin_types.entry_usize;
2047121432 bool ptr_is_const = true;
2047221433 bool ptr_is_volatile = false;
20473 return ir_get_const_ptr(ira, &field_ptr_instruction->base, len_val,
21434 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, len_val,
2047421435 usize, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
2047521436 } else {
2047621437 ir_add_error_node(ira, source_node,
2047721438 buf_sprintf("no member named '%s' in '%s'", buf_ptr(field_name),
2047821439 buf_ptr(&container_type->name)));
20479 return ira->codegen->invalid_instruction;
21440 return ira->codegen->invalid_inst_gen;
2048021441 }
2048121442 } else if (container_type->id == ZigTypeIdMetaType) {
2048221443 ZigValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
2048321444 if (!container_ptr_val)
20484 return ira->codegen->invalid_instruction;
21445 return ira->codegen->invalid_inst_gen;
2048521446
2048621447 assert(container_ptr->value->type->id == ZigTypeIdPointer);
2048721448 ZigValue *child_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val, source_node);
2048821449 if (child_val == nullptr)
20489 return ira->codegen->invalid_instruction;
21450 return ira->codegen->invalid_inst_gen;
2049021451 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,
20491 field_ptr_instruction->base.source_node, child_val, UndefBad)))
21452 field_ptr_instruction->base.base.source_node, child_val, UndefBad)))
2049221453 {
20493 return ira->codegen->invalid_instruction;
21454 return ira->codegen->invalid_inst_gen;
2049421455 }
2049521456 ZigType *child_type = child_val->data.x_type;
2049621457
2049721458 if (type_is_invalid(child_type)) {
20498 return ira->codegen->invalid_instruction;
21459 return ira->codegen->invalid_inst_gen;
2049921460 } else if (is_container(child_type)) {
2050021461 if (child_type->id == ZigTypeIdEnum) {
2050121462 if ((err = type_resolve(ira->codegen, child_type, ResolveStatusSizeKnown)))
20502 return ira->codegen->invalid_instruction;
21463 return ira->codegen->invalid_inst_gen;
2050321464
2050421465 TypeEnumField *field = find_enum_type_field(child_type, field_name);
2050521466 if (field) {
2050621467 bool ptr_is_const = true;
2050721468 bool ptr_is_volatile = false;
20508 return ir_get_const_ptr(ira, &field_ptr_instruction->base,
21469 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
2050921470 create_const_enum(child_type, &field->value), child_type,
2051021471 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
2051121472 }
......@@ -20514,37 +21475,37 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
2051421475 Tld *tld = find_container_decl(ira->codegen, container_scope, field_name);
2051521476 if (tld) {
2051621477 if (tld->visib_mod == VisibModPrivate &&
20517 tld->import != get_scope_import(field_ptr_instruction->base.scope))
21478 tld->import != get_scope_import(field_ptr_instruction->base.base.scope))
2051821479 {
20519 ErrorMsg *msg = ir_add_error(ira, &field_ptr_instruction->base,
21480 ErrorMsg *msg = ir_add_error(ira, &field_ptr_instruction->base.base,
2052021481 buf_sprintf("'%s' is private", buf_ptr(field_name)));
2052121482 add_error_note(ira->codegen, msg, tld->source_node, buf_sprintf("declared here"));
20522 return ira->codegen->invalid_instruction;
21483 return ira->codegen->invalid_inst_gen;
2052321484 }
20524 return ir_analyze_decl_ref(ira, &field_ptr_instruction->base, tld);
21485 return ir_analyze_decl_ref(ira, &field_ptr_instruction->base.base, tld);
2052521486 }
2052621487 if (child_type->id == ZigTypeIdUnion &&
2052721488 (child_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr ||
2052821489 child_type->data.unionation.decl_node->data.container_decl.auto_enum))
2052921490 {
2053021491 if ((err = type_resolve(ira->codegen, child_type, ResolveStatusSizeKnown)))
20531 return ira->codegen->invalid_instruction;
21492 return ira->codegen->invalid_inst_gen;
2053221493 TypeUnionField *field = find_union_type_field(child_type, field_name);
2053321494 if (field) {
2053421495 ZigType *enum_type = child_type->data.unionation.tag_type;
2053521496 bool ptr_is_const = true;
2053621497 bool ptr_is_volatile = false;
20537 return ir_get_const_ptr(ira, &field_ptr_instruction->base,
21498 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
2053821499 create_const_enum(enum_type, &field->enum_field->value), enum_type,
2053921500 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
2054021501 }
2054121502 }
2054221503 const char *container_name = (child_type == ira->codegen->root_import) ?
2054321504 "root source file" : buf_ptr(buf_sprintf("container '%s'", buf_ptr(&child_type->name)));
20544 ir_add_error(ira, &field_ptr_instruction->base,
21505 ir_add_error(ira, &field_ptr_instruction->base.base,
2054521506 buf_sprintf("%s has no member called '%s'",
2054621507 container_name, buf_ptr(field_name)));
20547 return ira->codegen->invalid_instruction;
21508 return ira->codegen->invalid_inst_gen;
2054821509 } else if (child_type->id == ZigTypeIdErrorSet) {
2054921510 ErrorTableEntry *err_entry;
2055021511 ZigType *err_set_type;
......@@ -20554,7 +21515,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
2055421515 err_entry = existing_entry->value;
2055521516 } else {
2055621517 err_entry = allocate<ErrorTableEntry>(1);
20557 err_entry->decl_node = field_ptr_instruction->base.source_node;
21518 err_entry->decl_node = field_ptr_instruction->base.base.source_node;
2055821519 buf_init_from_buf(&err_entry->name, field_name);
2055921520 size_t error_value_count = ira->codegen->errors_by_index.length;
2056021521 assert((uint32_t)error_value_count < (((uint32_t)1) << (uint32_t)ira->codegen->err_tag_type->data.integral.bit_count));
......@@ -20564,19 +21525,19 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
2056421525 }
2056521526 if (err_entry->set_with_only_this_in_it == nullptr) {
2056621527 err_entry->set_with_only_this_in_it = make_err_set_with_one_item(ira->codegen,
20567 field_ptr_instruction->base.scope, field_ptr_instruction->base.source_node,
21528 field_ptr_instruction->base.base.scope, field_ptr_instruction->base.base.source_node,
2056821529 err_entry);
2056921530 }
2057021531 err_set_type = err_entry->set_with_only_this_in_it;
2057121532 } else {
20572 if (!resolve_inferred_error_set(ira->codegen, child_type, field_ptr_instruction->base.source_node)) {
20573 return ira->codegen->invalid_instruction;
21533 if (!resolve_inferred_error_set(ira->codegen, child_type, field_ptr_instruction->base.base.source_node)) {
21534 return ira->codegen->invalid_inst_gen;
2057421535 }
2057521536 err_entry = find_err_table_entry(child_type, field_name);
2057621537 if (err_entry == nullptr) {
20577 ir_add_error(ira, &field_ptr_instruction->base,
21538 ir_add_error(ira, &field_ptr_instruction->base.base,
2057821539 buf_sprintf("no error named '%s' in '%s'", buf_ptr(field_name), buf_ptr(&child_type->name)));
20579 return ira->codegen->invalid_instruction;
21540 return ira->codegen->invalid_inst_gen;
2058021541 }
2058121542 err_set_type = child_type;
2058221543 }
......@@ -20587,13 +21548,13 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
2058721548
2058821549 bool ptr_is_const = true;
2058921550 bool ptr_is_volatile = false;
20590 return ir_get_const_ptr(ira, &field_ptr_instruction->base, const_val,
21551 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, const_val,
2059121552 err_set_type, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
2059221553 } else if (child_type->id == ZigTypeIdInt) {
2059321554 if (buf_eql_str(field_name, "bit_count")) {
2059421555 bool ptr_is_const = true;
2059521556 bool ptr_is_volatile = false;
20596 return ir_get_const_ptr(ira, &field_ptr_instruction->base,
21557 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
2059721558 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,
2059821559 child_type->data.integral.bit_count, false),
2059921560 ira->codegen->builtin_types.entry_num_lit_int,
......@@ -20601,36 +21562,36 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
2060121562 } else if (buf_eql_str(field_name, "is_signed")) {
2060221563 bool ptr_is_const = true;
2060321564 bool ptr_is_volatile = false;
20604 return ir_get_const_ptr(ira, &field_ptr_instruction->base,
21565 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
2060521566 create_const_bool(ira->codegen, child_type->data.integral.is_signed),
2060621567 ira->codegen->builtin_types.entry_bool,
2060721568 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
2060821569 } else {
20609 ir_add_error(ira, &field_ptr_instruction->base,
21570 ir_add_error(ira, &field_ptr_instruction->base.base,
2061021571 buf_sprintf("type '%s' has no member called '%s'",
2061121572 buf_ptr(&child_type->name), buf_ptr(field_name)));
20612 return ira->codegen->invalid_instruction;
21573 return ira->codegen->invalid_inst_gen;
2061321574 }
2061421575 } else if (child_type->id == ZigTypeIdFloat) {
2061521576 if (buf_eql_str(field_name, "bit_count")) {
2061621577 bool ptr_is_const = true;
2061721578 bool ptr_is_volatile = false;
20618 return ir_get_const_ptr(ira, &field_ptr_instruction->base,
21579 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
2061921580 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,
2062021581 child_type->data.floating.bit_count, false),
2062121582 ira->codegen->builtin_types.entry_num_lit_int,
2062221583 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
2062321584 } else {
20624 ir_add_error(ira, &field_ptr_instruction->base,
21585 ir_add_error(ira, &field_ptr_instruction->base.base,
2062521586 buf_sprintf("type '%s' has no member called '%s'",
2062621587 buf_ptr(&child_type->name), buf_ptr(field_name)));
20627 return ira->codegen->invalid_instruction;
21588 return ira->codegen->invalid_inst_gen;
2062821589 }
2062921590 } else if (child_type->id == ZigTypeIdPointer) {
2063021591 if (buf_eql_str(field_name, "Child")) {
2063121592 bool ptr_is_const = true;
2063221593 bool ptr_is_volatile = false;
20633 return ir_get_const_ptr(ira, &field_ptr_instruction->base,
21594 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
2063421595 create_const_type(ira->codegen, child_type->data.pointer.child_type),
2063521596 ira->codegen->builtin_types.entry_type,
2063621597 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
......@@ -20640,75 +21601,75 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
2064021601 if ((err = type_resolve(ira->codegen, child_type->data.pointer.child_type,
2064121602 ResolveStatusAlignmentKnown)))
2064221603 {
20643 return ira->codegen->invalid_instruction;
21604 return ira->codegen->invalid_inst_gen;
2064421605 }
20645 return ir_get_const_ptr(ira, &field_ptr_instruction->base,
21606 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
2064621607 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,
2064721608 get_ptr_align(ira->codegen, child_type), false),
2064821609 ira->codegen->builtin_types.entry_num_lit_int,
2064921610 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
2065021611 } else {
20651 ir_add_error(ira, &field_ptr_instruction->base,
21612 ir_add_error(ira, &field_ptr_instruction->base.base,
2065221613 buf_sprintf("type '%s' has no member called '%s'",
2065321614 buf_ptr(&child_type->name), buf_ptr(field_name)));
20654 return ira->codegen->invalid_instruction;
21615 return ira->codegen->invalid_inst_gen;
2065521616 }
2065621617 } else if (child_type->id == ZigTypeIdArray) {
2065721618 if (buf_eql_str(field_name, "Child")) {
2065821619 bool ptr_is_const = true;
2065921620 bool ptr_is_volatile = false;
20660 return ir_get_const_ptr(ira, &field_ptr_instruction->base,
21621 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
2066121622 create_const_type(ira->codegen, child_type->data.array.child_type),
2066221623 ira->codegen->builtin_types.entry_type,
2066321624 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
2066421625 } else if (buf_eql_str(field_name, "len")) {
2066521626 bool ptr_is_const = true;
2066621627 bool ptr_is_volatile = false;
20667 return ir_get_const_ptr(ira, &field_ptr_instruction->base,
21628 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
2066821629 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,
2066921630 child_type->data.array.len, false),
2067021631 ira->codegen->builtin_types.entry_num_lit_int,
2067121632 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
2067221633 } else {
20673 ir_add_error(ira, &field_ptr_instruction->base,
21634 ir_add_error(ira, &field_ptr_instruction->base.base,
2067421635 buf_sprintf("type '%s' has no member called '%s'",
2067521636 buf_ptr(&child_type->name), buf_ptr(field_name)));
20676 return ira->codegen->invalid_instruction;
21637 return ira->codegen->invalid_inst_gen;
2067721638 }
2067821639 } else if (child_type->id == ZigTypeIdErrorUnion) {
2067921640 if (buf_eql_str(field_name, "Payload")) {
2068021641 bool ptr_is_const = true;
2068121642 bool ptr_is_volatile = false;
20682 return ir_get_const_ptr(ira, &field_ptr_instruction->base,
21643 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
2068321644 create_const_type(ira->codegen, child_type->data.error_union.payload_type),
2068421645 ira->codegen->builtin_types.entry_type,
2068521646 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
2068621647 } else if (buf_eql_str(field_name, "ErrorSet")) {
2068721648 bool ptr_is_const = true;
2068821649 bool ptr_is_volatile = false;
20689 return ir_get_const_ptr(ira, &field_ptr_instruction->base,
21650 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
2069021651 create_const_type(ira->codegen, child_type->data.error_union.err_set_type),
2069121652 ira->codegen->builtin_types.entry_type,
2069221653 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
2069321654 } else {
20694 ir_add_error(ira, &field_ptr_instruction->base,
21655 ir_add_error(ira, &field_ptr_instruction->base.base,
2069521656 buf_sprintf("type '%s' has no member called '%s'",
2069621657 buf_ptr(&child_type->name), buf_ptr(field_name)));
20697 return ira->codegen->invalid_instruction;
21658 return ira->codegen->invalid_inst_gen;
2069821659 }
2069921660 } else if (child_type->id == ZigTypeIdOptional) {
2070021661 if (buf_eql_str(field_name, "Child")) {
2070121662 bool ptr_is_const = true;
2070221663 bool ptr_is_volatile = false;
20703 return ir_get_const_ptr(ira, &field_ptr_instruction->base,
21664 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
2070421665 create_const_type(ira->codegen, child_type->data.maybe.child_type),
2070521666 ira->codegen->builtin_types.entry_type,
2070621667 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
2070721668 } else {
20708 ir_add_error(ira, &field_ptr_instruction->base,
21669 ir_add_error(ira, &field_ptr_instruction->base.base,
2070921670 buf_sprintf("type '%s' has no member called '%s'",
2071021671 buf_ptr(&child_type->name), buf_ptr(field_name)));
20711 return ira->codegen->invalid_instruction;
21672 return ira->codegen->invalid_inst_gen;
2071221673 }
2071321674 } else if (child_type->id == ZigTypeIdFn) {
2071421675 if (buf_eql_str(field_name, "ReturnType")) {
......@@ -20716,121 +21677,121 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
2071621677 // Return type can only ever be null, if the function is generic
2071721678 assert(child_type->data.fn.is_generic);
2071821679
20719 ir_add_error(ira, &field_ptr_instruction->base,
21680 ir_add_error(ira, &field_ptr_instruction->base.base,
2072021681 buf_sprintf("ReturnType has not been resolved because '%s' is generic", buf_ptr(&child_type->name)));
20721 return ira->codegen->invalid_instruction;
21682 return ira->codegen->invalid_inst_gen;
2072221683 }
2072321684
2072421685 bool ptr_is_const = true;
2072521686 bool ptr_is_volatile = false;
20726 return ir_get_const_ptr(ira, &field_ptr_instruction->base,
21687 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
2072721688 create_const_type(ira->codegen, child_type->data.fn.fn_type_id.return_type),
2072821689 ira->codegen->builtin_types.entry_type,
2072921690 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
2073021691 } else if (buf_eql_str(field_name, "is_var_args")) {
2073121692 bool ptr_is_const = true;
2073221693 bool ptr_is_volatile = false;
20733 return ir_get_const_ptr(ira, &field_ptr_instruction->base,
21694 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
2073421695 create_const_bool(ira->codegen, child_type->data.fn.fn_type_id.is_var_args),
2073521696 ira->codegen->builtin_types.entry_bool,
2073621697 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
2073721698 } else if (buf_eql_str(field_name, "arg_count")) {
2073821699 bool ptr_is_const = true;
2073921700 bool ptr_is_volatile = false;
20740 return ir_get_const_ptr(ira, &field_ptr_instruction->base,
21701 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
2074121702 create_const_usize(ira->codegen, child_type->data.fn.fn_type_id.param_count),
2074221703 ira->codegen->builtin_types.entry_usize,
2074321704 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
2074421705 } else {
20745 ir_add_error(ira, &field_ptr_instruction->base,
21706 ir_add_error(ira, &field_ptr_instruction->base.base,
2074621707 buf_sprintf("type '%s' has no member called '%s'",
2074721708 buf_ptr(&child_type->name), buf_ptr(field_name)));
20748 return ira->codegen->invalid_instruction;
21709 return ira->codegen->invalid_inst_gen;
2074921710 }
2075021711 } else {
20751 ir_add_error(ira, &field_ptr_instruction->base,
21712 ir_add_error(ira, &field_ptr_instruction->base.base,
2075221713 buf_sprintf("type '%s' does not support field access", buf_ptr(&child_type->name)));
20753 return ira->codegen->invalid_instruction;
21714 return ira->codegen->invalid_inst_gen;
2075421715 }
2075521716 } else if (field_ptr_instruction->initializing) {
20756 ir_add_error(ira, &field_ptr_instruction->base,
21717 ir_add_error(ira, &field_ptr_instruction->base.base,
2075721718 buf_sprintf("type '%s' does not support struct initialization syntax", buf_ptr(&container_type->name)));
20758 return ira->codegen->invalid_instruction;
21719 return ira->codegen->invalid_inst_gen;
2075921720 } else {
20760 ir_add_error_node(ira, field_ptr_instruction->base.source_node,
21721 ir_add_error_node(ira, field_ptr_instruction->base.base.source_node,
2076121722 buf_sprintf("type '%s' does not support field access", buf_ptr(&container_type->name)));
20762 return ira->codegen->invalid_instruction;
21723 return ira->codegen->invalid_inst_gen;
2076321724 }
2076421725}
2076521726
20766static IrInstruction *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstructionStorePtr *instruction) {
20767 IrInstruction *ptr = instruction->ptr->child;
21727static IrInstGen *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstSrcStorePtr *instruction) {
21728 IrInstGen *ptr = instruction->ptr->child;
2076821729 if (type_is_invalid(ptr->value->type))
20769 return ira->codegen->invalid_instruction;
21730 return ira->codegen->invalid_inst_gen;
2077021731
20771 IrInstruction *value = instruction->value->child;
21732 IrInstGen *value = instruction->value->child;
2077221733 if (type_is_invalid(value->value->type))
20773 return ira->codegen->invalid_instruction;
21734 return ira->codegen->invalid_inst_gen;
2077421735
20775 return ir_analyze_store_ptr(ira, &instruction->base, ptr, value, instruction->allow_write_through_const);
21736 return ir_analyze_store_ptr(ira, &instruction->base.base, ptr, value, instruction->allow_write_through_const);
2077621737}
2077721738
20778static IrInstruction *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstructionLoadPtr *instruction) {
20779 IrInstruction *ptr = instruction->ptr->child;
21739static IrInstGen *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstSrcLoadPtr *instruction) {
21740 IrInstGen *ptr = instruction->ptr->child;
2078021741 if (type_is_invalid(ptr->value->type))
20781 return ira->codegen->invalid_instruction;
20782 return ir_get_deref(ira, &instruction->base, ptr, nullptr);
21742 return ira->codegen->invalid_inst_gen;
21743 return ir_get_deref(ira, &instruction->base.base, ptr, nullptr);
2078321744}
2078421745
20785static IrInstruction *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructionTypeOf *typeof_instruction) {
20786 IrInstruction *expr_value = typeof_instruction->value->child;
21746static IrInstGen *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstSrcTypeOf *typeof_instruction) {
21747 IrInstGen *expr_value = typeof_instruction->value->child;
2078721748 ZigType *type_entry = expr_value->value->type;
2078821749 if (type_is_invalid(type_entry))
20789 return ira->codegen->invalid_instruction;
20790 return ir_const_type(ira, &typeof_instruction->base, type_entry);
21750 return ira->codegen->invalid_inst_gen;
21751 return ir_const_type(ira, &typeof_instruction->base.base, type_entry);
2079121752}
2079221753
20793static IrInstruction *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstructionSetCold *instruction) {
21754static IrInstGen *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstSrcSetCold *instruction) {
2079421755 if (ira->new_irb.exec->is_inline) {
2079521756 // ignore setCold when running functions at compile time
20796 return ir_const_void(ira, &instruction->base);
21757 return ir_const_void(ira, &instruction->base.base);
2079721758 }
2079821759
20799 IrInstruction *is_cold_value = instruction->is_cold->child;
21760 IrInstGen *is_cold_value = instruction->is_cold->child;
2080021761 bool want_cold;
2080121762 if (!ir_resolve_bool(ira, is_cold_value, &want_cold))
20802 return ira->codegen->invalid_instruction;
21763 return ira->codegen->invalid_inst_gen;
2080321764
20804 ZigFn *fn_entry = scope_fn_entry(instruction->base.scope);
21765 ZigFn *fn_entry = scope_fn_entry(instruction->base.base.scope);
2080521766 if (fn_entry == nullptr) {
20806 ir_add_error(ira, &instruction->base, buf_sprintf("@setCold outside function"));
20807 return ira->codegen->invalid_instruction;
21767 ir_add_error(ira, &instruction->base.base, buf_sprintf("@setCold outside function"));
21768 return ira->codegen->invalid_inst_gen;
2080821769 }
2080921770
2081021771 if (fn_entry->set_cold_node != nullptr) {
20811 ErrorMsg *msg = ir_add_error(ira, &instruction->base, buf_sprintf("cold set twice in same function"));
21772 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base, buf_sprintf("cold set twice in same function"));
2081221773 add_error_note(ira->codegen, msg, fn_entry->set_cold_node, buf_sprintf("first set here"));
20813 return ira->codegen->invalid_instruction;
21774 return ira->codegen->invalid_inst_gen;
2081421775 }
2081521776
20816 fn_entry->set_cold_node = instruction->base.source_node;
21777 fn_entry->set_cold_node = instruction->base.base.source_node;
2081721778 fn_entry->is_cold = want_cold;
2081821779
20819 return ir_const_void(ira, &instruction->base);
21780 return ir_const_void(ira, &instruction->base.base);
2082021781}
2082121782
20822static IrInstruction *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,
20823 IrInstructionSetRuntimeSafety *set_runtime_safety_instruction)
21783static IrInstGen *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,
21784 IrInstSrcSetRuntimeSafety *set_runtime_safety_instruction)
2082421785{
2082521786 if (ira->new_irb.exec->is_inline) {
2082621787 // ignore setRuntimeSafety when running functions at compile time
20827 return ir_const_void(ira, &set_runtime_safety_instruction->base);
21788 return ir_const_void(ira, &set_runtime_safety_instruction->base.base);
2082821789 }
2082921790
2083021791 bool *safety_off_ptr;
2083121792 AstNode **safety_set_node_ptr;
2083221793
20833 Scope *scope = set_runtime_safety_instruction->base.scope;
21794 Scope *scope = set_runtime_safety_instruction->base.base.scope;
2083421795 while (scope != nullptr) {
2083521796 if (scope->id == ScopeIdBlock) {
2083621797 ScopeBlock *block_scope = (ScopeBlock *)scope;
......@@ -20856,36 +21817,36 @@ static IrInstruction *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,
2085621817 }
2085721818 assert(scope != nullptr);
2085821819
20859 IrInstruction *safety_on_value = set_runtime_safety_instruction->safety_on->child;
21820 IrInstGen *safety_on_value = set_runtime_safety_instruction->safety_on->child;
2086021821 bool want_runtime_safety;
2086121822 if (!ir_resolve_bool(ira, safety_on_value, &want_runtime_safety))
20862 return ira->codegen->invalid_instruction;
21823 return ira->codegen->invalid_inst_gen;
2086321824
20864 AstNode *source_node = set_runtime_safety_instruction->base.source_node;
21825 AstNode *source_node = set_runtime_safety_instruction->base.base.source_node;
2086521826 if (*safety_set_node_ptr) {
2086621827 ErrorMsg *msg = ir_add_error_node(ira, source_node,
2086721828 buf_sprintf("runtime safety set twice for same scope"));
2086821829 add_error_note(ira->codegen, msg, *safety_set_node_ptr, buf_sprintf("first set here"));
20869 return ira->codegen->invalid_instruction;
21830 return ira->codegen->invalid_inst_gen;
2087021831 }
2087121832 *safety_set_node_ptr = source_node;
2087221833 *safety_off_ptr = !want_runtime_safety;
2087321834
20874 return ir_const_void(ira, &set_runtime_safety_instruction->base);
21835 return ir_const_void(ira, &set_runtime_safety_instruction->base.base);
2087521836}
2087621837
20877static IrInstruction *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
20878 IrInstructionSetFloatMode *instruction)
21838static IrInstGen *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
21839 IrInstSrcSetFloatMode *instruction)
2087921840{
2088021841 if (ira->new_irb.exec->is_inline) {
2088121842 // ignore setFloatMode when running functions at compile time
20882 return ir_const_void(ira, &instruction->base);
21843 return ir_const_void(ira, &instruction->base.base);
2088321844 }
2088421845
2088521846 bool *fast_math_on_ptr;
2088621847 AstNode **fast_math_set_node_ptr;
2088721848
20888 Scope *scope = instruction->base.scope;
21849 Scope *scope = instruction->base.base.scope;
2088921850 while (scope != nullptr) {
2089021851 if (scope->id == ScopeIdBlock) {
2089121852 ScopeBlock *block_scope = (ScopeBlock *)scope;
......@@ -20911,42 +21872,38 @@ static IrInstruction *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
2091121872 }
2091221873 assert(scope != nullptr);
2091321874
20914 IrInstruction *float_mode_value = instruction->mode_value->child;
21875 IrInstGen *float_mode_value = instruction->mode_value->child;
2091521876 FloatMode float_mode_scalar;
2091621877 if (!ir_resolve_float_mode(ira, float_mode_value, &float_mode_scalar))
20917 return ira->codegen->invalid_instruction;
21878 return ira->codegen->invalid_inst_gen;
2091821879
20919 AstNode *source_node = instruction->base.source_node;
21880 AstNode *source_node = instruction->base.base.source_node;
2092021881 if (*fast_math_set_node_ptr) {
2092121882 ErrorMsg *msg = ir_add_error_node(ira, source_node,
2092221883 buf_sprintf("float mode set twice for same scope"));
2092321884 add_error_note(ira->codegen, msg, *fast_math_set_node_ptr, buf_sprintf("first set here"));
20924 return ira->codegen->invalid_instruction;
21885 return ira->codegen->invalid_inst_gen;
2092521886 }
2092621887 *fast_math_set_node_ptr = source_node;
2092721888 *fast_math_on_ptr = (float_mode_scalar == FloatModeOptimized);
2092821889
20929 return ir_const_void(ira, &instruction->base);
21890 return ir_const_void(ira, &instruction->base.base);
2093021891}
2093121892
20932static IrInstruction *ir_analyze_instruction_any_frame_type(IrAnalyze *ira,
20933 IrInstructionAnyFrameType *instruction)
20934{
21893static IrInstGen *ir_analyze_instruction_any_frame_type(IrAnalyze *ira, IrInstSrcAnyFrameType *instruction) {
2093521894 ZigType *payload_type = nullptr;
2093621895 if (instruction->payload_type != nullptr) {
2093721896 payload_type = ir_resolve_type(ira, instruction->payload_type->child);
2093821897 if (type_is_invalid(payload_type))
20939 return ira->codegen->invalid_instruction;
21898 return ira->codegen->invalid_inst_gen;
2094021899 }
2094121900
2094221901 ZigType *any_frame_type = get_any_frame_type(ira->codegen, payload_type);
20943 return ir_const_type(ira, &instruction->base, any_frame_type);
21902 return ir_const_type(ira, &instruction->base.base, any_frame_type);
2094421903}
2094521904
20946static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira,
20947 IrInstructionSliceType *slice_type_instruction)
20948{
20949 IrInstruction *result = ir_const(ira, &slice_type_instruction->base, ira->codegen->builtin_types.entry_type);
21905static IrInstGen *ir_analyze_instruction_slice_type(IrAnalyze *ira, IrInstSrcSliceType *slice_type_instruction) {
21906 IrInstGen *result = ir_const(ira, &slice_type_instruction->base.base, ira->codegen->builtin_types.entry_type);
2095021907 result->value->special = ConstValSpecialLazy;
2095121908
2095221909 LazyValueSliceType *lazy_slice_type = allocate<LazyValueSliceType>(1, "LazyValueSliceType");
......@@ -20957,18 +21914,18 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira,
2095721914 if (slice_type_instruction->align_value != nullptr) {
2095821915 lazy_slice_type->align_inst = slice_type_instruction->align_value->child;
2095921916 if (ir_resolve_const(ira, lazy_slice_type->align_inst, LazyOk) == nullptr)
20960 return ira->codegen->invalid_instruction;
21917 return ira->codegen->invalid_inst_gen;
2096121918 }
2096221919
2096321920 if (slice_type_instruction->sentinel != nullptr) {
2096421921 lazy_slice_type->sentinel = slice_type_instruction->sentinel->child;
2096521922 if (ir_resolve_const(ira, lazy_slice_type->sentinel, LazyOk) == nullptr)
20966 return ira->codegen->invalid_instruction;
21923 return ira->codegen->invalid_inst_gen;
2096721924 }
2096821925
2096921926 lazy_slice_type->elem_type = slice_type_instruction->child_type->child;
2097021927 if (ir_resolve_type_lazy(ira, lazy_slice_type->elem_type) == nullptr)
20971 return ira->codegen->invalid_instruction;
21928 return ira->codegen->invalid_inst_gen;
2097221929
2097321930 lazy_slice_type->is_const = slice_type_instruction->is_const;
2097421931 lazy_slice_type->is_volatile = slice_type_instruction->is_volatile;
......@@ -20977,31 +21934,31 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira,
2097721934 return result;
2097821935}
2097921936
20980static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAsmSrc *asm_instruction) {
21937static IrInstGen *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstSrcAsm *asm_instruction) {
2098121938 Error err;
2098221939
20983 assert(asm_instruction->base.source_node->type == NodeTypeAsmExpr);
21940 assert(asm_instruction->base.base.source_node->type == NodeTypeAsmExpr);
2098421941
20985 AstNode *node = asm_instruction->base.source_node;
20986 AstNodeAsmExpr *asm_expr = &asm_instruction->base.source_node->data.asm_expr;
21942 AstNode *node = asm_instruction->base.base.source_node;
21943 AstNodeAsmExpr *asm_expr = &asm_instruction->base.base.source_node->data.asm_expr;
2098721944
2098821945 Buf *template_buf = ir_resolve_str(ira, asm_instruction->asm_template->child);
2098921946 if (template_buf == nullptr)
20990 return ira->codegen->invalid_instruction;
21947 return ira->codegen->invalid_inst_gen;
2099121948
2099221949 if (asm_instruction->is_global) {
2099321950 buf_append_char(&ira->codegen->global_asm, '\n');
2099421951 buf_append_buf(&ira->codegen->global_asm, template_buf);
2099521952
20996 return ir_const_void(ira, &asm_instruction->base);
21953 return ir_const_void(ira, &asm_instruction->base.base);
2099721954 }
2099821955
20999 if (!ir_emit_global_runtime_side_effect(ira, &asm_instruction->base))
21000 return ira->codegen->invalid_instruction;
21956 if (!ir_emit_global_runtime_side_effect(ira, &asm_instruction->base.base))
21957 return ira->codegen->invalid_inst_gen;
2100121958
2100221959 ZigList<AsmToken> tok_list = {};
2100321960 if ((err = parse_asm_template(ira, node, template_buf, &tok_list))) {
21004 return ira->codegen->invalid_instruction;
21961 return ira->codegen->invalid_inst_gen;
2100521962 }
2100621963
2100721964 for (size_t token_i = 0; token_i < tok_list.length; token_i += 1) {
......@@ -21015,15 +21972,15 @@ static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAs
2101521972 add_node_error(ira->codegen, node,
2101621973 buf_sprintf("could not find '%.*s' in the inputs or outputs",
2101721974 len, ptr));
21018 return ira->codegen->invalid_instruction;
21975 return ira->codegen->invalid_inst_gen;
2101921976 }
2102021977 }
2102121978 }
2102221979
2102321980 // TODO validate the output types and variable types
2102421981
21025 IrInstruction **input_list = allocate<IrInstruction *>(asm_expr->input_list.length);
21026 IrInstruction **output_types = allocate<IrInstruction *>(asm_expr->output_list.length);
21982 IrInstGen **input_list = allocate<IrInstGen *>(asm_expr->input_list.length);
21983 IrInstGen **output_types = allocate<IrInstGen *>(asm_expr->output_list.length);
2102721984
2102821985 ZigType *return_type = ira->codegen->builtin_types.entry_void;
2102921986 for (size_t i = 0; i < asm_expr->output_list.length; i += 1) {
......@@ -21032,39 +21989,34 @@ static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAs
2103221989 output_types[i] = asm_instruction->output_types[i]->child;
2103321990 return_type = ir_resolve_type(ira, output_types[i]);
2103421991 if (type_is_invalid(return_type))
21035 return ira->codegen->invalid_instruction;
21992 return ira->codegen->invalid_inst_gen;
2103621993 }
2103721994 }
2103821995
2103921996 for (size_t i = 0; i < asm_expr->input_list.length; i += 1) {
21040 IrInstruction *const input_value = asm_instruction->input_list[i]->child;
21997 IrInstGen *const input_value = asm_instruction->input_list[i]->child;
2104121998 if (type_is_invalid(input_value->value->type))
21042 return ira->codegen->invalid_instruction;
21999 return ira->codegen->invalid_inst_gen;
2104322000
2104422001 if (instr_is_comptime(input_value) &&
2104522002 (input_value->value->type->id == ZigTypeIdComptimeInt ||
2104622003 input_value->value->type->id == ZigTypeIdComptimeFloat)) {
21047 ir_add_error_node(ira, input_value->source_node,
22004 ir_add_error(ira, &input_value->base,
2104822005 buf_sprintf("expected sized integer or sized float, found %s", buf_ptr(&input_value->value->type->name)));
21049 return ira->codegen->invalid_instruction;
22006 return ira->codegen->invalid_inst_gen;
2105022007 }
2105122008
2105222009 input_list[i] = input_value;
2105322010 }
2105422011
21055 IrInstruction *result = ir_build_asm_gen(ira,
21056 asm_instruction->base.scope, asm_instruction->base.source_node,
22012 return ir_build_asm_gen(ira, &asm_instruction->base.base,
2105722013 template_buf, tok_list.items, tok_list.length,
2105822014 input_list, output_types, asm_instruction->output_vars, asm_instruction->return_count,
21059 asm_instruction->has_side_effects);
21060 result->value->type = return_type;
21061 return result;
22015 asm_instruction->has_side_effects, return_type);
2106222016}
2106322017
21064static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira,
21065 IrInstructionArrayType *array_type_instruction)
21066{
21067 IrInstruction *result = ir_const(ira, &array_type_instruction->base, ira->codegen->builtin_types.entry_type);
22018static IrInstGen *ir_analyze_instruction_array_type(IrAnalyze *ira, IrInstSrcArrayType *array_type_instruction) {
22019 IrInstGen *result = ir_const(ira, &array_type_instruction->base.base, ira->codegen->builtin_types.entry_type);
2106822020 result->value->special = ConstValSpecialLazy;
2106922021
2107022022 LazyValueArrayType *lazy_array_type = allocate<LazyValueArrayType>(1, "LazyValueArrayType");
......@@ -21074,22 +22026,22 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira,
2107422026
2107522027 lazy_array_type->elem_type = array_type_instruction->child_type->child;
2107622028 if (ir_resolve_type_lazy(ira, lazy_array_type->elem_type) == nullptr)
21077 return ira->codegen->invalid_instruction;
22029 return ira->codegen->invalid_inst_gen;
2107822030
2107922031 if (!ir_resolve_usize(ira, array_type_instruction->size->child, &lazy_array_type->length))
21080 return ira->codegen->invalid_instruction;
22032 return ira->codegen->invalid_inst_gen;
2108122033
2108222034 if (array_type_instruction->sentinel != nullptr) {
2108322035 lazy_array_type->sentinel = array_type_instruction->sentinel->child;
2108422036 if (ir_resolve_const(ira, lazy_array_type->sentinel, LazyOk) == nullptr)
21085 return ira->codegen->invalid_instruction;
22037 return ira->codegen->invalid_inst_gen;
2108622038 }
2108722039
2108822040 return result;
2108922041}
2109022042
21091static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstructionSizeOf *instruction) {
21092 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int);
22043static IrInstGen *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstSrcSizeOf *instruction) {
22044 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int);
2109322045 result->value->special = ConstValSpecialLazy;
2109422046
2109522047 LazyValueSizeOf *lazy_size_of = allocate<LazyValueSizeOf>(1, "LazyValueSizeOf");
......@@ -21100,19 +22052,19 @@ static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstructi
2110022052
2110122053 lazy_size_of->target_type = instruction->type_value->child;
2110222054 if (ir_resolve_type_lazy(ira, lazy_size_of->target_type) == nullptr)
21103 return ira->codegen->invalid_instruction;
22055 return ira->codegen->invalid_inst_gen;
2110422056
2110522057 return result;
2110622058}
2110722059
21108static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *source_inst, IrInstruction *value) {
22060static IrInstGen *ir_analyze_test_non_null(IrAnalyze *ira, IrInst *source_inst, IrInstGen *value) {
2110922061 ZigType *type_entry = value->value->type;
2111022062
2111122063 if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.allow_zero) {
2111222064 if (instr_is_comptime(value)) {
2111322065 ZigValue *c_ptr_val = ir_resolve_const(ira, value, UndefOk);
2111422066 if (c_ptr_val == nullptr)
21115 return ira->codegen->invalid_instruction;
22067 return ira->codegen->invalid_inst_gen;
2111622068 if (c_ptr_val->special == ConstValSpecialUndef)
2111722069 return ir_const_undef(ira, source_inst, ira->codegen->builtin_types.entry_bool);
2111822070 bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull ||
......@@ -21121,25 +22073,19 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so
2112122073 return ir_const_bool(ira, source_inst, !is_null);
2112222074 }
2112322075
21124 IrInstruction *result = ir_build_test_nonnull(&ira->new_irb,
21125 source_inst->scope, source_inst->source_node, value);
21126 result->value->type = ira->codegen->builtin_types.entry_bool;
21127 return result;
22076 return ir_build_test_non_null_gen(ira, source_inst, value);
2112822077 } else if (type_entry->id == ZigTypeIdOptional) {
2112922078 if (instr_is_comptime(value)) {
2113022079 ZigValue *maybe_val = ir_resolve_const(ira, value, UndefOk);
2113122080 if (maybe_val == nullptr)
21132 return ira->codegen->invalid_instruction;
22081 return ira->codegen->invalid_inst_gen;
2113322082 if (maybe_val->special == ConstValSpecialUndef)
2113422083 return ir_const_undef(ira, source_inst, ira->codegen->builtin_types.entry_bool);
2113522084
2113622085 return ir_const_bool(ira, source_inst, !optional_value_is_null(maybe_val));
2113722086 }
2113822087
21139 IrInstruction *result = ir_build_test_nonnull(&ira->new_irb,
21140 source_inst->scope, source_inst->source_node, value);
21141 result->value->type = ira->codegen->builtin_types.entry_bool;
21142 return result;
22088 return ir_build_test_non_null_gen(ira, source_inst, value);
2114322089 } else if (type_entry->id == ZigTypeIdNull) {
2114422090 return ir_const_bool(ira, source_inst, false);
2114522091 } else {
......@@ -21147,51 +22093,51 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so
2114722093 }
2114822094}
2114922095
21150static IrInstruction *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstructionTestNonNull *instruction) {
21151 IrInstruction *value = instruction->value->child;
22096static IrInstGen *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstSrcTestNonNull *instruction) {
22097 IrInstGen *value = instruction->value->child;
2115222098 if (type_is_invalid(value->value->type))
21153 return ira->codegen->invalid_instruction;
22099 return ira->codegen->invalid_inst_gen;
2115422100
21155 return ir_analyze_test_non_null(ira, &instruction->base, value);
22101 return ir_analyze_test_non_null(ira, &instruction->base.base, value);
2115622102}
2115722103
21158static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstruction *source_instr,
21159 IrInstruction *base_ptr, bool safety_check_on, bool initializing)
22104static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* source_instr,
22105 IrInstGen *base_ptr, bool safety_check_on, bool initializing)
2116022106{
2116122107 ZigType *type_entry = get_ptr_elem_type(ira->codegen, base_ptr);
2116222108 if (type_is_invalid(type_entry))
21163 return ira->codegen->invalid_instruction;
22109 return ira->codegen->invalid_inst_gen;
2116422110
2116522111 if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.ptr_len == PtrLenC) {
2116622112 if (instr_is_comptime(base_ptr)) {
2116722113 ZigValue *val = ir_resolve_const(ira, base_ptr, UndefBad);
2116822114 if (!val)
21169 return ira->codegen->invalid_instruction;
22115 return ira->codegen->invalid_inst_gen;
2117022116 if (val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
2117122117 ZigValue *c_ptr_val = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node);
2117222118 if (c_ptr_val == nullptr)
21173 return ira->codegen->invalid_instruction;
22119 return ira->codegen->invalid_inst_gen;
2117422120 bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull ||
2117522121 (c_ptr_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&
2117622122 c_ptr_val->data.x_ptr.data.hard_coded_addr.addr == 0);
2117722123 if (is_null) {
2117822124 ir_add_error(ira, source_instr, buf_sprintf("unable to unwrap null"));
21179 return ira->codegen->invalid_instruction;
22125 return ira->codegen->invalid_inst_gen;
2118022126 }
2118122127 return base_ptr;
2118222128 }
2118322129 }
2118422130 if (!safety_check_on)
2118522131 return base_ptr;
21186 IrInstruction *c_ptr_val = ir_get_deref(ira, source_instr, base_ptr, nullptr);
22132 IrInstGen *c_ptr_val = ir_get_deref(ira, source_instr, base_ptr, nullptr);
2118722133 ir_build_assert_non_null(ira, source_instr, c_ptr_val);
2118822134 return base_ptr;
2118922135 }
2119022136
2119122137 if (type_entry->id != ZigTypeIdOptional) {
21192 ir_add_error_node(ira, base_ptr->source_node,
22138 ir_add_error(ira, &base_ptr->base,
2119322139 buf_sprintf("expected optional type, found '%s'", buf_ptr(&type_entry->name)));
21194 return ira->codegen->invalid_instruction;
22140 return ira->codegen->invalid_inst_gen;
2119522141 }
2119622142
2119722143 ZigType *child_type = type_entry->data.maybe.child_type;
......@@ -21204,16 +22150,16 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr
2120422150 if (instr_is_comptime(base_ptr)) {
2120522151 ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad);
2120622152 if (!ptr_val)
21207 return ira->codegen->invalid_instruction;
22153 return ira->codegen->invalid_inst_gen;
2120822154 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
2120922155 ZigValue *optional_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
2121022156 if (optional_val == nullptr)
21211 return ira->codegen->invalid_instruction;
22157 return ira->codegen->invalid_inst_gen;
2121222158
2121322159 if (initializing) {
2121422160 switch (type_has_one_possible_value(ira->codegen, child_type)) {
2121522161 case OnePossibleValueInvalid:
21216 return ira->codegen->invalid_instruction;
22162 return ira->codegen->invalid_inst_gen;
2121722163 case OnePossibleValueNo:
2121822164 if (!same_comptime_repr) {
2121922165 ZigValue *payload_val = create_const_vals(1);
......@@ -21240,14 +22186,13 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr
2124022186 }
2124122187 } else if (optional_value_is_null(optional_val)) {
2124222188 ir_add_error(ira, source_instr, buf_sprintf("unable to unwrap null"));
21243 return ira->codegen->invalid_instruction;
22189 return ira->codegen->invalid_inst_gen;
2124422190 }
2124522191
21246 IrInstruction *result;
22192 IrInstGen *result;
2124722193 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
21248 result = ir_build_optional_unwrap_ptr(&ira->new_irb, source_instr->scope,
21249 source_instr->source_node, base_ptr, false, initializing);
21250 result->value->type = result_type;
22194 result = ir_build_optional_unwrap_ptr_gen(ira, source_instr, base_ptr, false,
22195 initializing, result_type);
2125122196 result->value->special = ConstValSpecialStatic;
2125222197 } else {
2125322198 result = ir_const(ira, source_instr, result_type);
......@@ -21257,7 +22202,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr
2125722202 result_val->data.x_ptr.mut = ptr_val->data.x_ptr.mut;
2125822203 switch (type_has_one_possible_value(ira->codegen, child_type)) {
2125922204 case OnePossibleValueInvalid:
21260 return ira->codegen->invalid_instruction;
22205 return ira->codegen->invalid_inst_gen;
2126122206 case OnePossibleValueNo:
2126222207 if (same_comptime_repr) {
2126322208 result_val->data.x_ptr.data.ref.pointee = optional_val;
......@@ -21275,131 +22220,120 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr
2127522220 }
2127622221 }
2127722222
21278 IrInstruction *result = ir_build_optional_unwrap_ptr(&ira->new_irb, source_instr->scope,
21279 source_instr->source_node, base_ptr, safety_check_on, initializing);
21280 result->value->type = result_type;
21281 return result;
22223 return ir_build_optional_unwrap_ptr_gen(ira, source_instr, base_ptr, safety_check_on,
22224 initializing, result_type);
2128222225}
2128322226
21284static IrInstruction *ir_analyze_instruction_optional_unwrap_ptr(IrAnalyze *ira,
21285 IrInstructionOptionalUnwrapPtr *instruction)
22227static IrInstGen *ir_analyze_instruction_optional_unwrap_ptr(IrAnalyze *ira,
22228 IrInstSrcOptionalUnwrapPtr *instruction)
2128622229{
21287 IrInstruction *base_ptr = instruction->base_ptr->child;
22230 IrInstGen *base_ptr = instruction->base_ptr->child;
2128822231 if (type_is_invalid(base_ptr->value->type))
21289 return ira->codegen->invalid_instruction;
22232 return ira->codegen->invalid_inst_gen;
2129022233
21291 return ir_analyze_unwrap_optional_payload(ira, &instruction->base, base_ptr,
22234 return ir_analyze_unwrap_optional_payload(ira, &instruction->base.base, base_ptr,
2129222235 instruction->safety_check_on, false);
2129322236}
2129422237
21295static IrInstruction *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCtz *instruction) {
22238static IrInstGen *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstSrcCtz *instruction) {
2129622239 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);
2129722240 if (type_is_invalid(int_type))
21298 return ira->codegen->invalid_instruction;
22241 return ira->codegen->invalid_inst_gen;
2129922242
21300 IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type);
22243 IrInstGen *op = ir_implicit_cast(ira, instruction->op->child, int_type);
2130122244 if (type_is_invalid(op->value->type))
21302 return ira->codegen->invalid_instruction;
22245 return ira->codegen->invalid_inst_gen;
2130322246
2130422247 if (int_type->data.integral.bit_count == 0)
21305 return ir_const_unsigned(ira, &instruction->base, 0);
22248 return ir_const_unsigned(ira, &instruction->base.base, 0);
2130622249
2130722250 if (instr_is_comptime(op)) {
2130822251 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
2130922252 if (val == nullptr)
21310 return ira->codegen->invalid_instruction;
22253 return ira->codegen->invalid_inst_gen;
2131122254 if (val->special == ConstValSpecialUndef)
21312 return ir_const_undef(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int);
22255 return ir_const_undef(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int);
2131322256 size_t result_usize = bigint_ctz(&op->value->data.x_bigint, int_type->data.integral.bit_count);
21314 return ir_const_unsigned(ira, &instruction->base, result_usize);
22257 return ir_const_unsigned(ira, &instruction->base.base, result_usize);
2131522258 }
2131622259
2131722260 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count);
21318 IrInstruction *result = ir_build_ctz(&ira->new_irb, instruction->base.scope,
21319 instruction->base.source_node, nullptr, op);
21320 result->value->type = return_type;
21321 return result;
22261 return ir_build_ctz_gen(ira, &instruction->base.base, return_type, op);
2132222262}
2132322263
21324static IrInstruction *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionClz *instruction) {
22264static IrInstGen *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstSrcClz *instruction) {
2132522265 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);
2132622266 if (type_is_invalid(int_type))
21327 return ira->codegen->invalid_instruction;
22267 return ira->codegen->invalid_inst_gen;
2132822268
21329 IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type);
22269 IrInstGen *op = ir_implicit_cast(ira, instruction->op->child, int_type);
2133022270 if (type_is_invalid(op->value->type))
21331 return ira->codegen->invalid_instruction;
22271 return ira->codegen->invalid_inst_gen;
2133222272
2133322273 if (int_type->data.integral.bit_count == 0)
21334 return ir_const_unsigned(ira, &instruction->base, 0);
22274 return ir_const_unsigned(ira, &instruction->base.base, 0);
2133522275
2133622276 if (instr_is_comptime(op)) {
2133722277 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
2133822278 if (val == nullptr)
21339 return ira->codegen->invalid_instruction;
22279 return ira->codegen->invalid_inst_gen;
2134022280 if (val->special == ConstValSpecialUndef)
21341 return ir_const_undef(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int);
22281 return ir_const_undef(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int);
2134222282 size_t result_usize = bigint_clz(&op->value->data.x_bigint, int_type->data.integral.bit_count);
21343 return ir_const_unsigned(ira, &instruction->base, result_usize);
22283 return ir_const_unsigned(ira, &instruction->base.base, result_usize);
2134422284 }
2134522285
2134622286 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count);
21347 IrInstruction *result = ir_build_clz(&ira->new_irb, instruction->base.scope,
21348 instruction->base.source_node, nullptr, op);
21349 result->value->type = return_type;
21350 return result;
22287 return ir_build_clz_gen(ira, &instruction->base.base, return_type, op);
2135122288}
2135222289
21353static IrInstruction *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstructionPopCount *instruction) {
22290static IrInstGen *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstSrcPopCount *instruction) {
2135422291 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);
2135522292 if (type_is_invalid(int_type))
21356 return ira->codegen->invalid_instruction;
22293 return ira->codegen->invalid_inst_gen;
2135722294
21358 IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type);
22295 IrInstGen *op = ir_implicit_cast(ira, instruction->op->child, int_type);
2135922296 if (type_is_invalid(op->value->type))
21360 return ira->codegen->invalid_instruction;
22297 return ira->codegen->invalid_inst_gen;
2136122298
2136222299 if (int_type->data.integral.bit_count == 0)
21363 return ir_const_unsigned(ira, &instruction->base, 0);
22300 return ir_const_unsigned(ira, &instruction->base.base, 0);
2136422301
2136522302 if (instr_is_comptime(op)) {
2136622303 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
2136722304 if (val == nullptr)
21368 return ira->codegen->invalid_instruction;
22305 return ira->codegen->invalid_inst_gen;
2136922306 if (val->special == ConstValSpecialUndef)
21370 return ir_const_undef(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int);
22307 return ir_const_undef(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int);
2137122308
2137222309 if (bigint_cmp_zero(&val->data.x_bigint) != CmpLT) {
2137322310 size_t result = bigint_popcount_unsigned(&val->data.x_bigint);
21374 return ir_const_unsigned(ira, &instruction->base, result);
22311 return ir_const_unsigned(ira, &instruction->base.base, result);
2137522312 }
2137622313 size_t result = bigint_popcount_signed(&val->data.x_bigint, int_type->data.integral.bit_count);
21377 return ir_const_unsigned(ira, &instruction->base, result);
22314 return ir_const_unsigned(ira, &instruction->base.base, result);
2137822315 }
2137922316
2138022317 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count);
21381 IrInstruction *result = ir_build_pop_count(&ira->new_irb, instruction->base.scope,
21382 instruction->base.source_node, nullptr, op);
21383 result->value->type = return_type;
21384 return result;
22318 return ir_build_pop_count_gen(ira, &instruction->base.base, return_type, op);
2138522319}
2138622320
21387static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value) {
22321static IrInstGen *ir_analyze_union_tag(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value, bool is_gen) {
2138822322 if (type_is_invalid(value->value->type))
21389 return ira->codegen->invalid_instruction;
22323 return ira->codegen->invalid_inst_gen;
2139022324
2139122325 if (value->value->type->id != ZigTypeIdUnion) {
21392 ir_add_error(ira, value,
22326 ir_add_error(ira, &value->base,
2139322327 buf_sprintf("expected enum or union type, found '%s'", buf_ptr(&value->value->type->name)));
21394 return ira->codegen->invalid_instruction;
22328 return ira->codegen->invalid_inst_gen;
2139522329 }
21396 if (!value->value->type->data.unionation.have_explicit_tag_type && !source_instr->is_gen) {
22330 if (!value->value->type->data.unionation.have_explicit_tag_type && !is_gen) {
2139722331 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("union has no associated enum"));
2139822332 if (value->value->type->data.unionation.decl_node != nullptr) {
2139922333 add_error_note(ira->codegen, msg, value->value->type->data.unionation.decl_node,
2140022334 buf_sprintf("declared here"));
2140122335 }
21402 return ira->codegen->invalid_instruction;
22336 return ira->codegen->invalid_inst_gen;
2140322337 }
2140422338
2140522339 ZigType *tag_type = value->value->type->data.unionation.tag_type;
......@@ -21408,9 +22342,9 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source
2140822342 if (instr_is_comptime(value)) {
2140922343 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
2141022344 if (!val)
21411 return ira->codegen->invalid_instruction;
22345 return ira->codegen->invalid_inst_gen;
2141222346
21413 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
22347 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
2141422348 source_instr->scope, source_instr->source_node);
2141522349 const_instruction->base.value->type = tag_type;
2141622350 const_instruction->base.value->special = ConstValSpecialStatic;
......@@ -21418,15 +22352,13 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source
2141822352 return &const_instruction->base;
2141922353 }
2142022354
21421 IrInstruction *result = ir_build_union_tag(&ira->new_irb, source_instr->scope, source_instr->source_node, value);
21422 result->value->type = tag_type;
21423 return result;
22355 return ir_build_union_tag(ira, source_instr, value, tag_type);
2142422356}
2142522357
21426static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,
21427 IrInstructionSwitchBr *switch_br_instruction)
22358static IrInstGen *ir_analyze_instruction_switch_br(IrAnalyze *ira,
22359 IrInstSrcSwitchBr *switch_br_instruction)
2142822360{
21429 IrInstruction *target_value = switch_br_instruction->target_value->child;
22361 IrInstGen *target_value = switch_br_instruction->target_value->child;
2143022362 if (type_is_invalid(target_value->value->type))
2143122363 return ir_unreach_error(ira);
2143222364
......@@ -21441,21 +22373,21 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,
2144122373
2144222374 bool is_comptime;
2144322375 if (!ir_resolve_comptime(ira, switch_br_instruction->is_comptime->child, &is_comptime))
21444 return ira->codegen->invalid_instruction;
22376 return ira->codegen->invalid_inst_gen;
2144522377
2144622378 if (is_comptime || instr_is_comptime(target_value)) {
2144722379 ZigValue *target_val = ir_resolve_const(ira, target_value, UndefBad);
2144822380 if (!target_val)
2144922381 return ir_unreach_error(ira);
2145022382
21451 IrBasicBlock *old_dest_block = switch_br_instruction->else_block;
22383 IrBasicBlockSrc *old_dest_block = switch_br_instruction->else_block;
2145222384 for (size_t i = 0; i < case_count; i += 1) {
21453 IrInstructionSwitchBrCase *old_case = &switch_br_instruction->cases[i];
21454 IrInstruction *case_value = old_case->value->child;
22385 IrInstSrcSwitchBrCase *old_case = &switch_br_instruction->cases[i];
22386 IrInstGen *case_value = old_case->value->child;
2145522387 if (type_is_invalid(case_value->value->type))
2145622388 return ir_unreach_error(ira);
2145722389
21458 IrInstruction *casted_case_value = ir_implicit_cast(ira, case_value, target_value->value->type);
22390 IrInstGen *casted_case_value = ir_implicit_cast(ira, case_value, target_value->value->type);
2145922391 if (type_is_invalid(casted_case_value->value->type))
2146022392 return ir_unreach_error(ira);
2146122393
......@@ -21470,23 +22402,20 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,
2147022402 }
2147122403
2147222404 if (is_comptime || old_dest_block->ref_count == 1) {
21473 return ir_inline_bb(ira, &switch_br_instruction->base, old_dest_block);
22405 return ir_inline_bb(ira, &switch_br_instruction->base.base, old_dest_block);
2147422406 } else {
21475 IrBasicBlock *new_dest_block = ir_get_new_bb(ira, old_dest_block, &switch_br_instruction->base);
21476 IrInstruction *result = ir_build_br(&ira->new_irb,
21477 switch_br_instruction->base.scope, switch_br_instruction->base.source_node,
21478 new_dest_block, nullptr);
21479 result->value->type = ira->codegen->builtin_types.entry_unreachable;
22407 IrBasicBlockGen *new_dest_block = ir_get_new_bb(ira, old_dest_block, &switch_br_instruction->base.base);
22408 IrInstGen *result = ir_build_br_gen(ira, &switch_br_instruction->base.base, new_dest_block);
2148022409 return ir_finish_anal(ira, result);
2148122410 }
2148222411 }
2148322412
21484 IrInstructionSwitchBrCase *cases = allocate<IrInstructionSwitchBrCase>(case_count);
22413 IrInstGenSwitchBrCase *cases = allocate<IrInstGenSwitchBrCase>(case_count);
2148522414 for (size_t i = 0; i < case_count; i += 1) {
21486 IrInstructionSwitchBrCase *old_case = &switch_br_instruction->cases[i];
21487 IrInstructionSwitchBrCase *new_case = &cases[i];
21488 new_case->block = ir_get_new_bb(ira, old_case->block, &switch_br_instruction->base);
21489 new_case->value = ira->codegen->invalid_instruction;
22415 IrInstSrcSwitchBrCase *old_case = &switch_br_instruction->cases[i];
22416 IrInstGenSwitchBrCase *new_case = &cases[i];
22417 new_case->block = ir_get_new_bb(ira, old_case->block, &switch_br_instruction->base.base);
22418 new_case->value = ira->codegen->invalid_inst_gen;
2149022419
2149122420 // Calling ir_get_new_bb set the ref_instruction on the new basic block.
2149222421 // However a switch br may branch to the same basic block which would trigger an
......@@ -21494,12 +22423,12 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,
2149422423 // it back after the loop.
2149522424 new_case->block->ref_instruction = nullptr;
2149622425
21497 IrInstruction *old_value = old_case->value;
21498 IrInstruction *new_value = old_value->child;
22426 IrInstSrc *old_value = old_case->value;
22427 IrInstGen *new_value = old_value->child;
2149922428 if (type_is_invalid(new_value->value->type))
2150022429 continue;
2150122430
21502 IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, target_value->value->type);
22431 IrInstGen *casted_new_value = ir_implicit_cast(ira, new_value, target_value->value->type);
2150322432 if (type_is_invalid(casted_new_value->value->type))
2150422433 continue;
2150522434
......@@ -21510,47 +22439,45 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,
2151022439 }
2151122440
2151222441 for (size_t i = 0; i < case_count; i += 1) {
21513 IrInstructionSwitchBrCase *new_case = &cases[i];
21514 if (new_case->value == ira->codegen->invalid_instruction)
22442 IrInstGenSwitchBrCase *new_case = &cases[i];
22443 if (type_is_invalid(new_case->value->value->type))
2151522444 return ir_unreach_error(ira);
21516 new_case->block->ref_instruction = &switch_br_instruction->base;
22445 new_case->block->ref_instruction = &switch_br_instruction->base.base;
2151722446 }
2151822447
21519 IrBasicBlock *new_else_block = ir_get_new_bb(ira, switch_br_instruction->else_block, &switch_br_instruction->base);
21520 IrInstructionSwitchBr *switch_br = ir_build_switch_br(&ira->new_irb,
21521 switch_br_instruction->base.scope, switch_br_instruction->base.source_node,
21522 target_value, new_else_block, case_count, cases, nullptr, nullptr);
21523 switch_br->base.value->type = ira->codegen->builtin_types.entry_unreachable;
22448 IrBasicBlockGen *new_else_block = ir_get_new_bb(ira, switch_br_instruction->else_block, &switch_br_instruction->base.base);
22449 IrInstGenSwitchBr *switch_br = ir_build_switch_br_gen(ira, &switch_br_instruction->base.base,
22450 target_value, new_else_block, case_count, cases);
2152422451 return ir_finish_anal(ira, &switch_br->base);
2152522452}
2152622453
21527static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
21528 IrInstructionSwitchTarget *switch_target_instruction)
22454static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira,
22455 IrInstSrcSwitchTarget *switch_target_instruction)
2152922456{
2153022457 Error err;
21531 IrInstruction *target_value_ptr = switch_target_instruction->target_value_ptr->child;
22458 IrInstGen *target_value_ptr = switch_target_instruction->target_value_ptr->child;
2153222459 if (type_is_invalid(target_value_ptr->value->type))
21533 return ira->codegen->invalid_instruction;
22460 return ira->codegen->invalid_inst_gen;
2153422461
2153522462 if (target_value_ptr->value->type->id == ZigTypeIdMetaType) {
2153622463 assert(instr_is_comptime(target_value_ptr));
2153722464 ZigType *ptr_type = target_value_ptr->value->data.x_type;
2153822465 assert(ptr_type->id == ZigTypeIdPointer);
21539 return ir_const_type(ira, &switch_target_instruction->base, ptr_type->data.pointer.child_type);
22466 return ir_const_type(ira, &switch_target_instruction->base.base, ptr_type->data.pointer.child_type);
2154022467 }
2154122468
2154222469 ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type;
2154322470 ZigValue *pointee_val = nullptr;
2154422471 if (instr_is_comptime(target_value_ptr) && target_value_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
21545 pointee_val = const_ptr_pointee(ira, ira->codegen, target_value_ptr->value, target_value_ptr->source_node);
22472 pointee_val = const_ptr_pointee(ira, ira->codegen, target_value_ptr->value, target_value_ptr->base.source_node);
2154622473 if (pointee_val == nullptr)
21547 return ira->codegen->invalid_instruction;
22474 return ira->codegen->invalid_inst_gen;
2154822475
2154922476 if (pointee_val->special == ConstValSpecialRuntime)
2155022477 pointee_val = nullptr;
2155122478 }
2155222479 if ((err = type_resolve(ira->codegen, target_type, ResolveStatusSizeKnown)))
21553 return ira->codegen->invalid_instruction;
22480 return ira->codegen->invalid_inst_gen;
2155422481
2155522482 switch (target_type->id) {
2155622483 case ZigTypeIdInvalid:
......@@ -21567,13 +22494,13 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
2156722494 case ZigTypeIdFn:
2156822495 case ZigTypeIdErrorSet: {
2156922496 if (pointee_val) {
21570 IrInstruction *result = ir_const(ira, &switch_target_instruction->base, nullptr);
22497 IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, nullptr);
2157122498 copy_const_val(result->value, pointee_val);
2157222499 result->value->type = target_type;
2157322500 return result;
2157422501 }
2157522502
21576 IrInstruction *result = ir_get_deref(ira, &switch_target_instruction->base, target_value_ptr, nullptr);
22503 IrInstGen *result = ir_get_deref(ira, &switch_target_instruction->base.base, target_value_ptr, nullptr);
2157722504 result->value->type = target_type;
2157822505 return result;
2157922506 }
......@@ -21582,52 +22509,49 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
2158222509 if (!decl_node->data.container_decl.auto_enum &&
2158322510 decl_node->data.container_decl.init_arg_expr == nullptr)
2158422511 {
21585 ErrorMsg *msg = ir_add_error(ira, target_value_ptr,
22512 ErrorMsg *msg = ir_add_error(ira, &target_value_ptr->base,
2158622513 buf_sprintf("switch on union which has no attached enum"));
2158722514 add_error_note(ira->codegen, msg, decl_node,
2158822515 buf_sprintf("consider 'union(enum)' here"));
21589 return ira->codegen->invalid_instruction;
22516 return ira->codegen->invalid_inst_gen;
2159022517 }
2159122518 ZigType *tag_type = target_type->data.unionation.tag_type;
2159222519 assert(tag_type != nullptr);
2159322520 assert(tag_type->id == ZigTypeIdEnum);
2159422521 if (pointee_val) {
21595 IrInstruction *result = ir_const(ira, &switch_target_instruction->base, tag_type);
22522 IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, tag_type);
2159622523 bigint_init_bigint(&result->value->data.x_enum_tag, &pointee_val->data.x_union.tag);
2159722524 return result;
2159822525 }
2159922526 if (tag_type->data.enumeration.src_field_count == 1) {
21600 IrInstruction *result = ir_const(ira, &switch_target_instruction->base, tag_type);
22527 IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, tag_type);
2160122528 TypeEnumField *only_field = &tag_type->data.enumeration.fields[0];
2160222529 bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value);
2160322530 return result;
2160422531 }
2160522532
21606 IrInstruction *union_value = ir_get_deref(ira, &switch_target_instruction->base, target_value_ptr, nullptr);
22533 IrInstGen *union_value = ir_get_deref(ira, &switch_target_instruction->base.base, target_value_ptr, nullptr);
2160722534 union_value->value->type = target_type;
2160822535
21609 IrInstruction *union_tag_inst = ir_build_union_tag(&ira->new_irb, switch_target_instruction->base.scope,
21610 switch_target_instruction->base.source_node, union_value);
21611 union_tag_inst->value->type = tag_type;
21612 return union_tag_inst;
22536 return ir_build_union_tag(ira, &switch_target_instruction->base.base, union_value, tag_type);
2161322537 }
2161422538 case ZigTypeIdEnum: {
2161522539 if ((err = type_resolve(ira->codegen, target_type, ResolveStatusZeroBitsKnown)))
21616 return ira->codegen->invalid_instruction;
22540 return ira->codegen->invalid_inst_gen;
2161722541 if (target_type->data.enumeration.src_field_count == 1) {
2161822542 TypeEnumField *only_field = &target_type->data.enumeration.fields[0];
21619 IrInstruction *result = ir_const(ira, &switch_target_instruction->base, target_type);
22543 IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, target_type);
2162022544 bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value);
2162122545 return result;
2162222546 }
2162322547
2162422548 if (pointee_val) {
21625 IrInstruction *result = ir_const(ira, &switch_target_instruction->base, target_type);
22549 IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, target_type);
2162622550 bigint_init_bigint(&result->value->data.x_enum_tag, &pointee_val->data.x_enum_tag);
2162722551 return result;
2162822552 }
2162922553
21630 IrInstruction *enum_value = ir_get_deref(ira, &switch_target_instruction->base, target_value_ptr, nullptr);
22554 IrInstGen *enum_value = ir_get_deref(ira, &switch_target_instruction->base.base, target_value_ptr, nullptr);
2163122555 enum_value->value->type = target_type;
2163222556 return enum_value;
2163322557 }
......@@ -21643,17 +22567,17 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
2164322567 case ZigTypeIdVector:
2164422568 case ZigTypeIdFnFrame:
2164522569 case ZigTypeIdAnyFrame:
21646 ir_add_error(ira, &switch_target_instruction->base,
22570 ir_add_error(ira, &switch_target_instruction->base.base,
2164722571 buf_sprintf("invalid switch target type '%s'", buf_ptr(&target_type->name)));
21648 return ira->codegen->invalid_instruction;
22572 return ira->codegen->invalid_inst_gen;
2164922573 }
2165022574 zig_unreachable();
2165122575}
2165222576
21653static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstructionSwitchVar *instruction) {
21654 IrInstruction *target_value_ptr = instruction->target_value_ptr->child;
22577static IrInstGen *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstSrcSwitchVar *instruction) {
22578 IrInstGen *target_value_ptr = instruction->target_value_ptr->child;
2165522579 if (type_is_invalid(target_value_ptr->value->type))
21656 return ira->codegen->invalid_instruction;
22580 return ira->codegen->invalid_inst_gen;
2165722581
2165822582 ZigType *ref_type = target_value_ptr->value->type;
2165922583 assert(ref_type->id == ZigTypeIdPointer);
......@@ -21664,62 +22588,62 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru
2166422588 assert(enum_type->id == ZigTypeIdEnum);
2166522589 assert(instruction->prongs_len > 0);
2166622590
21667 IrInstruction *first_prong_value = instruction->prongs_ptr[0]->child;
22591 IrInstGen *first_prong_value = instruction->prongs_ptr[0]->child;
2166822592 if (type_is_invalid(first_prong_value->value->type))
21669 return ira->codegen->invalid_instruction;
22593 return ira->codegen->invalid_inst_gen;
2167022594
21671 IrInstruction *first_casted_prong_value = ir_implicit_cast(ira, first_prong_value, enum_type);
22595 IrInstGen *first_casted_prong_value = ir_implicit_cast(ira, first_prong_value, enum_type);
2167222596 if (type_is_invalid(first_casted_prong_value->value->type))
21673 return ira->codegen->invalid_instruction;
22597 return ira->codegen->invalid_inst_gen;
2167422598
2167522599 ZigValue *first_prong_val = ir_resolve_const(ira, first_casted_prong_value, UndefBad);
2167622600 if (first_prong_val == nullptr)
21677 return ira->codegen->invalid_instruction;
22601 return ira->codegen->invalid_inst_gen;
2167822602
2167922603 TypeUnionField *first_field = find_union_field_by_tag(target_type, &first_prong_val->data.x_enum_tag);
2168022604
2168122605 ErrorMsg *invalid_payload_msg = nullptr;
2168222606 for (size_t prong_i = 1; prong_i < instruction->prongs_len; prong_i += 1) {
21683 IrInstruction *this_prong_inst = instruction->prongs_ptr[prong_i]->child;
22607 IrInstGen *this_prong_inst = instruction->prongs_ptr[prong_i]->child;
2168422608 if (type_is_invalid(this_prong_inst->value->type))
21685 return ira->codegen->invalid_instruction;
22609 return ira->codegen->invalid_inst_gen;
2168622610
21687 IrInstruction *this_casted_prong_value = ir_implicit_cast(ira, this_prong_inst, enum_type);
22611 IrInstGen *this_casted_prong_value = ir_implicit_cast(ira, this_prong_inst, enum_type);
2168822612 if (type_is_invalid(this_casted_prong_value->value->type))
21689 return ira->codegen->invalid_instruction;
22613 return ira->codegen->invalid_inst_gen;
2169022614
2169122615 ZigValue *this_prong = ir_resolve_const(ira, this_casted_prong_value, UndefBad);
2169222616 if (this_prong == nullptr)
21693 return ira->codegen->invalid_instruction;
22617 return ira->codegen->invalid_inst_gen;
2169422618
2169522619 TypeUnionField *payload_field = find_union_field_by_tag(target_type, &this_prong->data.x_enum_tag);
2169622620 ZigType *payload_type = payload_field->type_entry;
2169722621 if (first_field->type_entry != payload_type) {
2169822622 if (invalid_payload_msg == nullptr) {
21699 invalid_payload_msg = ir_add_error(ira, &instruction->base,
22623 invalid_payload_msg = ir_add_error(ira, &instruction->base.base,
2170022624 buf_sprintf("capture group with incompatible types"));
21701 add_error_note(ira->codegen, invalid_payload_msg, first_prong_value->source_node,
22625 add_error_note(ira->codegen, invalid_payload_msg, first_prong_value->base.source_node,
2170222626 buf_sprintf("type '%s' here", buf_ptr(&first_field->type_entry->name)));
2170322627 }
21704 add_error_note(ira->codegen, invalid_payload_msg, this_prong_inst->source_node,
22628 add_error_note(ira->codegen, invalid_payload_msg, this_prong_inst->base.source_node,
2170522629 buf_sprintf("type '%s' here", buf_ptr(&payload_field->type_entry->name)));
2170622630 }
2170722631 }
2170822632
2170922633 if (invalid_payload_msg != nullptr) {
21710 return ira->codegen->invalid_instruction;
22634 return ira->codegen->invalid_inst_gen;
2171122635 }
2171222636
2171322637 if (instr_is_comptime(target_value_ptr)) {
2171422638 ZigValue *target_val_ptr = ir_resolve_const(ira, target_value_ptr, UndefBad);
2171522639 if (!target_value_ptr)
21716 return ira->codegen->invalid_instruction;
22640 return ira->codegen->invalid_inst_gen;
2171722641
21718 ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, target_val_ptr, instruction->base.source_node);
22642 ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, target_val_ptr, instruction->base.base.source_node);
2171922643 if (pointee_val == nullptr)
21720 return ira->codegen->invalid_instruction;
22644 return ira->codegen->invalid_inst_gen;
2172122645
21722 IrInstruction *result = ir_const(ira, &instruction->base,
22646 IrInstGen *result = ir_const(ira, &instruction->base.base,
2172322647 get_pointer_to_type(ira->codegen, first_field->type_entry,
2172422648 target_val_ptr->type->data.pointer.is_const));
2172522649 ZigValue *out_val = result->value;
......@@ -21729,11 +22653,10 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru
2172922653 return result;
2173022654 }
2173122655
21732 IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb,
21733 instruction->base.scope, instruction->base.source_node, target_value_ptr, first_field, false, false);
21734 result->value->type = get_pointer_to_type(ira->codegen, first_field->type_entry,
22656 ZigType *result_type = get_pointer_to_type(ira->codegen, first_field->type_entry,
2173522657 target_value_ptr->value->type->data.pointer.is_const);
21736 return result;
22658 return ir_build_union_field_ptr(ira, &instruction->base.base, target_value_ptr, first_field,
22659 false, false, result_type);
2173722660 } else if (target_type->id == ZigTypeIdErrorSet) {
2173822661 // construct an error set from the prong values
2173922662 ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet);
......@@ -21746,7 +22669,7 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru
2174622669 for (size_t i = 0; i < instruction->prongs_len; i += 1) {
2174722670 ErrorTableEntry *err = ir_resolve_error(ira, instruction->prongs_ptr[i]->child);
2174822671 if (err == nullptr)
21749 return ira->codegen->invalid_instruction;
22672 return ira->codegen->invalid_inst_gen;
2175022673 error_list.append(err);
2175122674 buf_appendf(&err_set_type->name, "%s,", buf_ptr(&err->name));
2175222675 }
......@@ -21762,29 +22685,29 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru
2176222685 ref_type->data.pointer.explicit_alignment,
2176322686 ref_type->data.pointer.bit_offset_in_host, ref_type->data.pointer.host_int_bytes,
2176422687 ref_type->data.pointer.allow_zero);
21765 return ir_analyze_ptr_cast(ira, &instruction->base, target_value_ptr, new_target_value_ptr_type,
21766 &instruction->base, false);
22688 return ir_analyze_ptr_cast(ira, &instruction->base.base, target_value_ptr, new_target_value_ptr_type,
22689 &instruction->base.base, false);
2176722690 } else {
21768 ir_add_error(ira, &instruction->base,
22691 ir_add_error(ira, &instruction->base.base,
2176922692 buf_sprintf("switch on type '%s' provides no expression parameter", buf_ptr(&target_type->name)));
21770 return ira->codegen->invalid_instruction;
22693 return ira->codegen->invalid_inst_gen;
2177122694 }
2177222695}
2177322696
21774static IrInstruction *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,
21775 IrInstructionSwitchElseVar *instruction)
22697static IrInstGen *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,
22698 IrInstSrcSwitchElseVar *instruction)
2177622699{
21777 IrInstruction *target_value_ptr = instruction->target_value_ptr->child;
22700 IrInstGen *target_value_ptr = instruction->target_value_ptr->child;
2177822701 if (type_is_invalid(target_value_ptr->value->type))
21779 return ira->codegen->invalid_instruction;
22702 return ira->codegen->invalid_inst_gen;
2178022703
2178122704 ZigType *ref_type = target_value_ptr->value->type;
2178222705 assert(ref_type->id == ZigTypeIdPointer);
2178322706 ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type;
2178422707 if (target_type->id == ZigTypeIdErrorSet) {
2178522708 // make a new set that has the other cases removed
21786 if (!resolve_inferred_error_set(ira->codegen, target_type, instruction->base.source_node)) {
21787 return ira->codegen->invalid_instruction;
22709 if (!resolve_inferred_error_set(ira->codegen, target_type, instruction->base.base.source_node)) {
22710 return ira->codegen->invalid_inst_gen;
2178822711 }
2178922712 if (type_is_global_error_set(target_type)) {
2179022713 // the type of the else capture variable still has to be the global error set.
......@@ -21794,17 +22717,17 @@ static IrInstruction *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,
2179422717 // Make note of the errors handled by other cases
2179522718 ErrorTableEntry **errors = allocate<ErrorTableEntry *>(ira->codegen->errors_by_index.length);
2179622719 for (size_t case_i = 0; case_i < instruction->switch_br->case_count; case_i += 1) {
21797 IrInstructionSwitchBrCase *br_case = &instruction->switch_br->cases[case_i];
21798 IrInstruction *case_expr = br_case->value->child;
22720 IrInstSrcSwitchBrCase *br_case = &instruction->switch_br->cases[case_i];
22721 IrInstGen *case_expr = br_case->value->child;
2179922722 if (case_expr->value->type->id == ZigTypeIdErrorSet) {
2180022723 ErrorTableEntry *err = ir_resolve_error(ira, case_expr);
2180122724 if (err == nullptr)
21802 return ira->codegen->invalid_instruction;
22725 return ira->codegen->invalid_inst_gen;
2180322726 errors[err->value] = err;
2180422727 } else if (case_expr->value->type->id == ZigTypeIdMetaType) {
2180522728 ZigType *err_set_type = ir_resolve_type(ira, case_expr);
2180622729 if (type_is_invalid(err_set_type))
21807 return ira->codegen->invalid_instruction;
22730 return ira->codegen->invalid_inst_gen;
2180822731 populate_error_set_table(errors, err_set_type);
2180922732 } else {
2181022733 zig_unreachable();
......@@ -21843,27 +22766,22 @@ static IrInstruction *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,
2184322766 ref_type->data.pointer.explicit_alignment,
2184422767 ref_type->data.pointer.bit_offset_in_host, ref_type->data.pointer.host_int_bytes,
2184522768 ref_type->data.pointer.allow_zero);
21846 return ir_analyze_ptr_cast(ira, &instruction->base, target_value_ptr, new_target_value_ptr_type,
21847 &instruction->base, false);
22769 return ir_analyze_ptr_cast(ira, &instruction->base.base, target_value_ptr, new_target_value_ptr_type,
22770 &instruction->base.base, false);
2184822771 }
2184922772
2185022773 return target_value_ptr;
2185122774}
2185222775
21853static IrInstruction *ir_analyze_instruction_union_tag(IrAnalyze *ira, IrInstructionUnionTag *instruction) {
21854 IrInstruction *value = instruction->value->child;
21855 return ir_analyze_union_tag(ira, &instruction->base, value);
21856}
21857
21858static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructionImport *import_instruction) {
22776static IrInstGen *ir_analyze_instruction_import(IrAnalyze *ira, IrInstSrcImport *import_instruction) {
2185922777 Error err;
2186022778
21861 IrInstruction *name_value = import_instruction->name->child;
22779 IrInstGen *name_value = import_instruction->name->child;
2186222780 Buf *import_target_str = ir_resolve_str(ira, name_value);
2186322781 if (!import_target_str)
21864 return ira->codegen->invalid_instruction;
22782 return ira->codegen->invalid_inst_gen;
2186522783
21866 AstNode *source_node = import_instruction->base.source_node;
22784 AstNode *source_node = import_instruction->base.base.source_node;
2186722785 ZigType *import = source_node->owner;
2186822786
2186922787 ZigType *target_import;
......@@ -21876,48 +22794,48 @@ static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructio
2187622794 ir_add_error_node(ira, source_node,
2187722795 buf_sprintf("import of file outside package path: '%s'",
2187822796 buf_ptr(import_target_path)));
21879 return ira->codegen->invalid_instruction;
22797 return ira->codegen->invalid_inst_gen;
2188022798 } else if (err == ErrorFileNotFound) {
2188122799 ir_add_error_node(ira, source_node,
2188222800 buf_sprintf("unable to find '%s'", buf_ptr(import_target_path)));
21883 return ira->codegen->invalid_instruction;
22801 return ira->codegen->invalid_inst_gen;
2188422802 } else {
2188522803 ir_add_error_node(ira, source_node,
2188622804 buf_sprintf("unable to open '%s': %s", buf_ptr(&full_path), err_str(err)));
21887 return ira->codegen->invalid_instruction;
22805 return ira->codegen->invalid_inst_gen;
2188822806 }
2188922807 }
2189022808
21891 return ir_const_type(ira, &import_instruction->base, target_import);
22809 return ir_const_type(ira, &import_instruction->base.base, target_import);
2189222810}
2189322811
21894static IrInstruction *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstructionRef *ref_instruction) {
21895 IrInstruction *value = ref_instruction->value->child;
22812static IrInstGen *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstSrcRef *ref_instruction) {
22813 IrInstGen *value = ref_instruction->value->child;
2189622814 if (type_is_invalid(value->value->type))
21897 return ira->codegen->invalid_instruction;
21898 return ir_get_ref(ira, &ref_instruction->base, value, ref_instruction->is_const, ref_instruction->is_volatile);
22815 return ira->codegen->invalid_inst_gen;
22816 return ir_get_ref(ira, &ref_instruction->base.base, value, ref_instruction->is_const, ref_instruction->is_volatile);
2189922817}
2190022818
21901static IrInstruction *ir_analyze_union_init(IrAnalyze *ira, IrInstruction *source_instruction,
21902 AstNode *field_source_node, ZigType *union_type, Buf *field_name, IrInstruction *field_result_loc,
21903 IrInstruction *result_loc)
22819static IrInstGen *ir_analyze_union_init(IrAnalyze *ira, IrInst* source_instruction,
22820 AstNode *field_source_node, ZigType *union_type, Buf *field_name, IrInstGen *field_result_loc,
22821 IrInstGen *result_loc)
2190422822{
2190522823 Error err;
2190622824 assert(union_type->id == ZigTypeIdUnion);
2190722825
2190822826 if ((err = type_resolve(ira->codegen, union_type, ResolveStatusSizeKnown)))
21909 return ira->codegen->invalid_instruction;
22827 return ira->codegen->invalid_inst_gen;
2191022828
2191122829 TypeUnionField *type_field = find_union_type_field(union_type, field_name);
2191222830 if (type_field == nullptr) {
2191322831 ir_add_error_node(ira, field_source_node,
2191422832 buf_sprintf("no member named '%s' in union '%s'",
2191522833 buf_ptr(field_name), buf_ptr(&union_type->name)));
21916 return ira->codegen->invalid_instruction;
22834 return ira->codegen->invalid_inst_gen;
2191722835 }
2191822836
2191922837 if (type_is_invalid(type_field->type_entry))
21920 return ira->codegen->invalid_instruction;
22838 return ira->codegen->invalid_inst_gen;
2192122839
2192222840 if (result_loc->value->data.x_ptr.mut == ConstPtrMutInfer) {
2192322841 if (instr_is_comptime(field_result_loc) &&
......@@ -21929,42 +22847,42 @@ static IrInstruction *ir_analyze_union_init(IrAnalyze *ira, IrInstruction *sourc
2192922847 }
2193022848 }
2193122849
21932 bool is_comptime = ir_should_inline(ira->new_irb.exec, source_instruction->scope)
22850 bool is_comptime = ir_should_inline(ira->old_irb.exec, source_instruction->scope)
2193322851 || type_requires_comptime(ira->codegen, union_type) == ReqCompTimeYes;
2193422852
21935 IrInstruction *result = ir_get_deref(ira, source_instruction, result_loc, nullptr);
22853 IrInstGen *result = ir_get_deref(ira, source_instruction, result_loc, nullptr);
2193622854 if (is_comptime && !instr_is_comptime(result)) {
21937 ir_add_error(ira, field_result_loc,
22855 ir_add_error(ira, &field_result_loc->base,
2193822856 buf_sprintf("unable to evaluate constant expression"));
21939 return ira->codegen->invalid_instruction;
22857 return ira->codegen->invalid_inst_gen;
2194022858 }
2194122859 return result;
2194222860}
2194322861
21944static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruction *instruction,
21945 ZigType *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields,
21946 IrInstruction *result_loc)
22862static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *source_instr,
22863 ZigType *container_type, size_t instr_field_count, IrInstSrcContainerInitFieldsField *fields,
22864 IrInstGen *result_loc)
2194722865{
2194822866 Error err;
2194922867 if (container_type->id == ZigTypeIdUnion) {
2195022868 if (instr_field_count != 1) {
21951 ir_add_error(ira, instruction,
22869 ir_add_error(ira, source_instr,
2195222870 buf_sprintf("union initialization expects exactly one field"));
21953 return ira->codegen->invalid_instruction;
22871 return ira->codegen->invalid_inst_gen;
2195422872 }
21955 IrInstructionContainerInitFieldsField *field = &fields[0];
21956 IrInstruction *field_result_loc = field->result_loc->child;
22873 IrInstSrcContainerInitFieldsField *field = &fields[0];
22874 IrInstGen *field_result_loc = field->result_loc->child;
2195722875 if (type_is_invalid(field_result_loc->value->type))
21958 return ira->codegen->invalid_instruction;
22876 return ira->codegen->invalid_inst_gen;
2195922877
21960 return ir_analyze_union_init(ira, instruction, field->source_node, container_type, field->name,
22878 return ir_analyze_union_init(ira, source_instr, field->source_node, container_type, field->name,
2196122879 field_result_loc, result_loc);
2196222880 }
2196322881 if (container_type->id != ZigTypeIdStruct || is_slice(container_type)) {
21964 ir_add_error(ira, instruction,
22882 ir_add_error(ira, source_instr,
2196522883 buf_sprintf("type '%s' does not support struct initialization syntax",
2196622884 buf_ptr(&container_type->name)));
21967 return ira->codegen->invalid_instruction;
22885 return ira->codegen->invalid_inst_gen;
2196822886 }
2196922887
2197022888 if (container_type->data.structure.resolve_status == ResolveStatusBeingInferred) {
......@@ -21973,16 +22891,16 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc
2197322891 }
2197422892
2197522893 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))
21976 return ira->codegen->invalid_instruction;
22894 return ira->codegen->invalid_inst_gen;
2197722895
2197822896 size_t actual_field_count = container_type->data.structure.src_field_count;
2197922897
21980 IrInstruction *first_non_const_instruction = nullptr;
22898 IrInstGen *first_non_const_instruction = nullptr;
2198122899
2198222900 AstNode **field_assign_nodes = allocate<AstNode *>(actual_field_count);
21983 ZigList<IrInstruction *> const_ptrs = {};
22901 ZigList<IrInstGen *> const_ptrs = {};
2198422902
21985 bool is_comptime = ir_should_inline(ira->new_irb.exec, instruction->scope)
22903 bool is_comptime = ir_should_inline(ira->old_irb.exec, source_instr->scope)
2198622904 || type_requires_comptime(ira->codegen, container_type) == ReqCompTimeYes;
2198722905
2198822906
......@@ -21998,29 +22916,29 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc
2199822916 // comptime-known values.
2199922917
2200022918 for (size_t i = 0; i < instr_field_count; i += 1) {
22001 IrInstructionContainerInitFieldsField *field = &fields[i];
22919 IrInstSrcContainerInitFieldsField *field = &fields[i];
2200222920
22003 IrInstruction *field_result_loc = field->result_loc->child;
22921 IrInstGen *field_result_loc = field->result_loc->child;
2200422922 if (type_is_invalid(field_result_loc->value->type))
22005 return ira->codegen->invalid_instruction;
22923 return ira->codegen->invalid_inst_gen;
2200622924
2200722925 TypeStructField *type_field = find_struct_type_field(container_type, field->name);
2200822926 if (!type_field) {
2200922927 ir_add_error_node(ira, field->source_node,
2201022928 buf_sprintf("no member named '%s' in struct '%s'",
2201122929 buf_ptr(field->name), buf_ptr(&container_type->name)));
22012 return ira->codegen->invalid_instruction;
22930 return ira->codegen->invalid_inst_gen;
2201322931 }
2201422932
2201522933 if (type_is_invalid(type_field->type_entry))
22016 return ira->codegen->invalid_instruction;
22934 return ira->codegen->invalid_inst_gen;
2201722935
2201822936 size_t field_index = type_field->src_index;
2201922937 AstNode *existing_assign_node = field_assign_nodes[field_index];
2202022938 if (existing_assign_node) {
2202122939 ErrorMsg *msg = ir_add_error_node(ira, field->source_node, buf_sprintf("duplicate field"));
2202222940 add_error_note(ira->codegen, msg, existing_assign_node, buf_sprintf("other field here"));
22023 return ira->codegen->invalid_instruction;
22941 return ira->codegen->invalid_inst_gen;
2202422942 }
2202522943 field_assign_nodes[field_index] = field->source_node;
2202622944
......@@ -22041,20 +22959,20 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc
2204122959 TypeStructField *field = container_type->data.structure.fields[i];
2204222960 memoize_field_init_val(ira->codegen, container_type, field);
2204322961 if (field->init_val == nullptr) {
22044 ir_add_error_node(ira, instruction->source_node,
22962 ir_add_error(ira, source_instr,
2204522963 buf_sprintf("missing field: '%s'", buf_ptr(container_type->data.structure.fields[i]->name)));
2204622964 any_missing = true;
2204722965 continue;
2204822966 }
2204922967 if (type_is_invalid(field->init_val->type))
22050 return ira->codegen->invalid_instruction;
22968 return ira->codegen->invalid_inst_gen;
2205122969
22052 IrInstruction *runtime_inst = ir_const(ira, instruction, field->init_val->type);
22970 IrInstGen *runtime_inst = ir_const(ira, source_instr, field->init_val->type);
2205322971 copy_const_val(runtime_inst->value, field->init_val);
2205422972
22055 IrInstruction *field_ptr = ir_analyze_struct_field_ptr(ira, instruction, field, result_loc,
22973 IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, result_loc,
2205622974 container_type, true);
22057 ir_analyze_store_ptr(ira, instruction, field_ptr, runtime_inst, false);
22975 ir_analyze_store_ptr(ira, source_instr, field_ptr, runtime_inst, false);
2205822976 if (instr_is_comptime(field_ptr) && field_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
2205922977 const_ptrs.append(field_ptr);
2206022978 } else {
......@@ -22062,39 +22980,39 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc
2206222980 }
2206322981 }
2206422982 if (any_missing)
22065 return ira->codegen->invalid_instruction;
22983 return ira->codegen->invalid_inst_gen;
2206622984
2206722985 if (result_loc->value->data.x_ptr.mut == ConstPtrMutInfer) {
2206822986 if (const_ptrs.length != actual_field_count) {
2206922987 result_loc->value->special = ConstValSpecialRuntime;
2207022988 for (size_t i = 0; i < const_ptrs.length; i += 1) {
22071 IrInstruction *field_result_loc = const_ptrs.at(i);
22072 IrInstruction *deref = ir_get_deref(ira, field_result_loc, field_result_loc, nullptr);
22989 IrInstGen *field_result_loc = const_ptrs.at(i);
22990 IrInstGen *deref = ir_get_deref(ira, &field_result_loc->base, field_result_loc, nullptr);
2207322991 field_result_loc->value->special = ConstValSpecialRuntime;
22074 ir_analyze_store_ptr(ira, field_result_loc, field_result_loc, deref, false);
22992 ir_analyze_store_ptr(ira, &field_result_loc->base, field_result_loc, deref, false);
2207522993 }
2207622994 }
2207722995 }
2207822996
22079 IrInstruction *result = ir_get_deref(ira, instruction, result_loc, nullptr);
22997 IrInstGen *result = ir_get_deref(ira, source_instr, result_loc, nullptr);
2208022998
2208122999 if (is_comptime && !instr_is_comptime(result)) {
22082 ir_add_error_node(ira, first_non_const_instruction->source_node,
23000 ir_add_error_node(ira, first_non_const_instruction->base.source_node,
2208323001 buf_sprintf("unable to evaluate constant expression"));
22084 return ira->codegen->invalid_instruction;
23002 return ira->codegen->invalid_inst_gen;
2208523003 }
2208623004
2208723005 return result;
2208823006}
2208923007
22090static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
22091 IrInstructionContainerInitList *instruction)
23008static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
23009 IrInstSrcContainerInitList *instruction)
2209223010{
22093 ir_assert(instruction->result_loc != nullptr, &instruction->base);
22094 IrInstruction *result_loc = instruction->result_loc->child;
23011 ir_assert(instruction->result_loc != nullptr, &instruction->base.base);
23012 IrInstGen *result_loc = instruction->result_loc->child;
2209523013 if (type_is_invalid(result_loc->value->type))
2209623014 return result_loc;
22097 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base);
23015 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base.base);
2209823016
2209923017 ZigType *container_type = result_loc->value->type->data.pointer.child_type;
2210023018
......@@ -22104,24 +23022,24 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
2210423022 ir_add_error_node(ira, instruction->init_array_type_source_node,
2210523023 buf_sprintf("array literal requires address-of operator to coerce to slice type '%s'",
2210623024 buf_ptr(&container_type->name)));
22107 return ira->codegen->invalid_instruction;
23025 return ira->codegen->invalid_inst_gen;
2210823026 }
2210923027
2211023028 if (container_type->id == ZigTypeIdVoid) {
2211123029 if (elem_count != 0) {
22112 ir_add_error_node(ira, instruction->base.source_node,
23030 ir_add_error_node(ira, instruction->base.base.source_node,
2211323031 buf_sprintf("void expression expects no arguments"));
22114 return ira->codegen->invalid_instruction;
23032 return ira->codegen->invalid_inst_gen;
2211523033 }
22116 return ir_const_void(ira, &instruction->base);
23034 return ir_const_void(ira, &instruction->base.base);
2211723035 }
2211823036
2211923037 if (container_type->id == ZigTypeIdStruct && elem_count == 0) {
22120 ir_assert(instruction->result_loc != nullptr, &instruction->base);
22121 IrInstruction *result_loc = instruction->result_loc->child;
23038 ir_assert(instruction->result_loc != nullptr, &instruction->base.base);
23039 IrInstGen *result_loc = instruction->result_loc->child;
2212223040 if (type_is_invalid(result_loc->value->type))
2212323041 return result_loc;
22124 return ir_analyze_container_init_fields(ira, &instruction->base, container_type, 0, nullptr, result_loc);
23042 return ir_analyze_container_init_fields(ira, &instruction->base.base, container_type, 0, nullptr, result_loc);
2212523043 }
2212623044
2212723045 if (container_type->id == ZigTypeIdArray) {
......@@ -22129,10 +23047,10 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
2212923047 if (container_type->data.array.len != elem_count) {
2213023048 ZigType *literal_type = get_array_type(ira->codegen, child_type, elem_count, nullptr);
2213123049
22132 ir_add_error(ira, &instruction->base,
23050 ir_add_error(ira, &instruction->base.base,
2213323051 buf_sprintf("expected %s literal, found %s literal",
2213423052 buf_ptr(&container_type->name), buf_ptr(&literal_type->name)));
22135 return ira->codegen->invalid_instruction;
23053 return ira->codegen->invalid_inst_gen;
2213623054 }
2213723055 } else if (container_type->id == ZigTypeIdStruct &&
2213823056 container_type->data.structure.resolve_status == ResolveStatusBeingInferred)
......@@ -22142,17 +23060,17 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
2214223060 } else if (container_type->id == ZigTypeIdVector) {
2214323061 // OK
2214423062 } else {
22145 ir_add_error_node(ira, instruction->base.source_node,
23063 ir_add_error(ira, &instruction->base.base,
2214623064 buf_sprintf("type '%s' does not support array initialization",
2214723065 buf_ptr(&container_type->name)));
22148 return ira->codegen->invalid_instruction;
23066 return ira->codegen->invalid_inst_gen;
2214923067 }
2215023068
2215123069 switch (type_has_one_possible_value(ira->codegen, container_type)) {
2215223070 case OnePossibleValueInvalid:
22153 return ira->codegen->invalid_instruction;
23071 return ira->codegen->invalid_inst_gen;
2215423072 case OnePossibleValueYes:
22155 return ir_const_move(ira, &instruction->base,
23073 return ir_const_move(ira, &instruction->base.base,
2215623074 get_the_one_possible_value(ira->codegen, container_type));
2215723075 case OnePossibleValueNo:
2215823076 break;
......@@ -22161,16 +23079,16 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
2216123079 bool is_comptime;
2216223080 switch (type_requires_comptime(ira->codegen, container_type)) {
2216323081 case ReqCompTimeInvalid:
22164 return ira->codegen->invalid_instruction;
23082 return ira->codegen->invalid_inst_gen;
2216523083 case ReqCompTimeNo:
22166 is_comptime = ir_should_inline(ira->new_irb.exec, instruction->base.scope);
23084 is_comptime = ir_should_inline(ira->old_irb.exec, instruction->base.base.scope);
2216723085 break;
2216823086 case ReqCompTimeYes:
2216923087 is_comptime = true;
2217023088 break;
2217123089 }
2217223090
22173 IrInstruction *first_non_const_instruction = nullptr;
23091 IrInstGen *first_non_const_instruction = nullptr;
2217423092
2217523093 // The Result Location Mechanism has already emitted runtime instructions to
2217623094 // initialize runtime elements and has omitted instructions for the comptime
......@@ -22179,12 +23097,12 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
2217923097 // array initialization can be a comptime value, overwrite ConstPtrMutInfer with
2218023098 // ConstPtrMutComptimeConst. Otherwise, emit instructions to runtime-initialize the
2218123099 // elements that have comptime-known values.
22182 ZigList<IrInstruction *> const_ptrs = {};
23100 ZigList<IrInstGen *> const_ptrs = {};
2218323101
2218423102 for (size_t i = 0; i < elem_count; i += 1) {
22185 IrInstruction *elem_result_loc = instruction->elem_result_loc_list[i]->child;
23103 IrInstGen *elem_result_loc = instruction->elem_result_loc_list[i]->child;
2218623104 if (type_is_invalid(elem_result_loc->value->type))
22187 return ira->codegen->invalid_instruction;
23105 return ira->codegen->invalid_inst_gen;
2218823106
2218923107 assert(elem_result_loc->value->type->id == ZigTypeIdPointer);
2219023108
......@@ -22201,81 +23119,79 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
2220123119 if (const_ptrs.length != elem_count) {
2220223120 result_loc->value->special = ConstValSpecialRuntime;
2220323121 for (size_t i = 0; i < const_ptrs.length; i += 1) {
22204 IrInstruction *elem_result_loc = const_ptrs.at(i);
23122 IrInstGen *elem_result_loc = const_ptrs.at(i);
2220523123 assert(elem_result_loc->value->special == ConstValSpecialStatic);
2220623124 if (elem_result_loc->value->type->data.pointer.inferred_struct_field != nullptr) {
2220723125 // This field will be generated comptime; no need to do this.
2220823126 continue;
2220923127 }
22210 IrInstruction *deref = ir_get_deref(ira, elem_result_loc, elem_result_loc, nullptr);
23128 IrInstGen *deref = ir_get_deref(ira, &elem_result_loc->base, elem_result_loc, nullptr);
2221123129 elem_result_loc->value->special = ConstValSpecialRuntime;
22212 ir_analyze_store_ptr(ira, elem_result_loc, elem_result_loc, deref, false);
23130 ir_analyze_store_ptr(ira, &elem_result_loc->base, elem_result_loc, deref, false);
2221323131 }
2221423132 }
2221523133 }
2221623134
22217 IrInstruction *result = ir_get_deref(ira, &instruction->base, result_loc, nullptr);
23135 IrInstGen *result = ir_get_deref(ira, &instruction->base.base, result_loc, nullptr);
2221823136 if (instr_is_comptime(result))
2221923137 return result;
2222023138
2222123139 if (is_comptime) {
22222 ir_add_error_node(ira, first_non_const_instruction->source_node,
23140 ir_add_error(ira, &first_non_const_instruction->base,
2222323141 buf_sprintf("unable to evaluate constant expression"));
22224 return ira->codegen->invalid_instruction;
23142 return ira->codegen->invalid_inst_gen;
2222523143 }
2222623144
2222723145 ZigType *result_elem_type = result_loc->value->type->data.pointer.child_type;
2222823146 if (is_slice(result_elem_type)) {
22229 ErrorMsg *msg = ir_add_error(ira, &instruction->base,
23147 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base,
2223023148 buf_sprintf("runtime-initialized array cannot be casted to slice type '%s'",
2223123149 buf_ptr(&result_elem_type->name)));
22232 add_error_note(ira->codegen, msg, first_non_const_instruction->source_node,
23150 add_error_note(ira->codegen, msg, first_non_const_instruction->base.source_node,
2223323151 buf_sprintf("this value is not comptime-known"));
22234 return ira->codegen->invalid_instruction;
23152 return ira->codegen->invalid_inst_gen;
2223523153 }
2223623154 return result;
2223723155}
2223823156
22239static IrInstruction *ir_analyze_instruction_container_init_fields(IrAnalyze *ira,
22240 IrInstructionContainerInitFields *instruction)
23157static IrInstGen *ir_analyze_instruction_container_init_fields(IrAnalyze *ira,
23158 IrInstSrcContainerInitFields *instruction)
2224123159{
22242 ir_assert(instruction->result_loc != nullptr, &instruction->base);
22243 IrInstruction *result_loc = instruction->result_loc->child;
23160 ir_assert(instruction->result_loc != nullptr, &instruction->base.base);
23161 IrInstGen *result_loc = instruction->result_loc->child;
2224423162 if (type_is_invalid(result_loc->value->type))
2224523163 return result_loc;
2224623164
22247 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base);
23165 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base.base);
2224823166 ZigType *container_type = result_loc->value->type->data.pointer.child_type;
2224923167
22250 return ir_analyze_container_init_fields(ira, &instruction->base, container_type,
23168 return ir_analyze_container_init_fields(ira, &instruction->base.base, container_type,
2225123169 instruction->field_count, instruction->fields, result_loc);
2225223170}
2225323171
22254static IrInstruction *ir_analyze_instruction_compile_err(IrAnalyze *ira,
22255 IrInstructionCompileErr *instruction)
22256{
22257 IrInstruction *msg_value = instruction->msg->child;
23172static IrInstGen *ir_analyze_instruction_compile_err(IrAnalyze *ira, IrInstSrcCompileErr *instruction) {
23173 IrInstGen *msg_value = instruction->msg->child;
2225823174 Buf *msg_buf = ir_resolve_str(ira, msg_value);
2225923175 if (!msg_buf)
22260 return ira->codegen->invalid_instruction;
23176 return ira->codegen->invalid_inst_gen;
2226123177
22262 ir_add_error(ira, &instruction->base, msg_buf);
23178 ir_add_error(ira, &instruction->base.base, msg_buf);
2226323179
22264 return ira->codegen->invalid_instruction;
23180 return ira->codegen->invalid_inst_gen;
2226523181}
2226623182
22267static IrInstruction *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstructionCompileLog *instruction) {
23183static IrInstGen *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstSrcCompileLog *instruction) {
2226823184 Buf buf = BUF_INIT;
2226923185 fprintf(stderr, "| ");
2227023186 for (size_t i = 0; i < instruction->msg_count; i += 1) {
22271 IrInstruction *msg = instruction->msg_list[i]->child;
23187 IrInstGen *msg = instruction->msg_list[i]->child;
2227223188 if (type_is_invalid(msg->value->type))
22273 return ira->codegen->invalid_instruction;
23189 return ira->codegen->invalid_inst_gen;
2227423190 buf_resize(&buf, 0);
2227523191 if (msg->value->special == ConstValSpecialLazy) {
2227623192 // Resolve any lazy value that's passed, we need its value
22277 if (ir_resolve_lazy(ira->codegen, msg->source_node, msg->value))
22278 return ira->codegen->invalid_instruction;
23193 if (ir_resolve_lazy(ira->codegen, msg->base.source_node, msg->value))
23194 return ira->codegen->invalid_inst_gen;
2227923195 }
2228023196 render_const_value(ira->codegen, &buf, msg->value);
2228123197 const char *comma_str = (i != 0) ? ", " : "";
......@@ -22283,25 +23199,25 @@ static IrInstruction *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstr
2228323199 }
2228423200 fprintf(stderr, "\n");
2228523201
22286 auto *expr = &instruction->base.source_node->data.fn_call_expr;
23202 auto *expr = &instruction->base.base.source_node->data.fn_call_expr;
2228723203 if (!expr->seen) {
2228823204 // Here we bypass higher level functions such as ir_add_error because we do not want
2228923205 // invalidate_exec to be called.
22290 add_node_error(ira->codegen, instruction->base.source_node, buf_sprintf("found compile log statement"));
23206 add_node_error(ira->codegen, instruction->base.base.source_node, buf_sprintf("found compile log statement"));
2229123207 }
2229223208 expr->seen = true;
2229323209
22294 return ir_const_void(ira, &instruction->base);
23210 return ir_const_void(ira, &instruction->base.base);
2229523211}
2229623212
22297static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstructionErrName *instruction) {
22298 IrInstruction *value = instruction->value->child;
23213static IrInstGen *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstSrcErrName *instruction) {
23214 IrInstGen *value = instruction->value->child;
2229923215 if (type_is_invalid(value->value->type))
22300 return ira->codegen->invalid_instruction;
23216 return ira->codegen->invalid_inst_gen;
2230123217
22302 IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_global_error_set);
23218 IrInstGen *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_global_error_set);
2230323219 if (type_is_invalid(casted_value->value->type))
22304 return ira->codegen->invalid_instruction;
23220 return ira->codegen->invalid_inst_gen;
2230523221
2230623222 ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
2230723223 true, false, PtrLenUnknown, 0, 0, 0, false);
......@@ -22309,13 +23225,13 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct
2230923225 if (instr_is_comptime(casted_value)) {
2231023226 ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad);
2231123227 if (val == nullptr)
22312 return ira->codegen->invalid_instruction;
23228 return ira->codegen->invalid_inst_gen;
2231323229 ErrorTableEntry *err = casted_value->value->data.x_err_set;
2231423230 if (!err->cached_error_name_val) {
2231523231 ZigValue *array_val = create_const_str_lit(ira->codegen, &err->name)->data.x_ptr.data.ref.pointee;
2231623232 err->cached_error_name_val = create_const_slice(ira->codegen, array_val, 0, buf_len(&err->name), true);
2231723233 }
22318 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
23234 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
2231923235 copy_const_val(result->value, err->cached_error_name_val);
2232023236 result->value->type = str_type;
2232123237 return result;
......@@ -22323,20 +23239,17 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct
2232323239
2232423240 ira->codegen->generate_error_name_table = true;
2232523241
22326 IrInstruction *result = ir_build_err_name(&ira->new_irb,
22327 instruction->base.scope, instruction->base.source_node, value);
22328 result->value->type = str_type;
22329 return result;
23242 return ir_build_err_name_gen(ira, &instruction->base.base, value, str_type);
2233023243}
2233123244
22332static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstructionTagName *instruction) {
23245static IrInstGen *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstSrcTagName *instruction) {
2233323246 Error err;
22334 IrInstruction *target = instruction->target->child;
23247 IrInstGen *target = instruction->target->child;
2233523248 if (type_is_invalid(target->value->type))
22336 return ira->codegen->invalid_instruction;
23249 return ira->codegen->invalid_inst_gen;
2233723250
2233823251 if (target->value->type->id == ZigTypeIdEnumLiteral) {
22339 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
23252 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
2234023253 Buf *field_name = target->value->data.x_enum_literal;
2234123254 ZigValue *array_val = create_const_str_lit(ira->codegen, field_name)->data.x_ptr.data.ref.pointee;
2234223255 init_const_slice(ira->codegen, result->value, array_val, 0, buf_len(field_name), true);
......@@ -22344,9 +23257,9 @@ static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIns
2234423257 }
2234523258
2234623259 if (target->value->type->id == ZigTypeIdUnion) {
22347 target = ir_analyze_union_tag(ira, &instruction->base, target);
23260 target = ir_analyze_union_tag(ira, &instruction->base.base, target, instruction->base.is_gen);
2234823261 if (type_is_invalid(target->value->type))
22349 return ira->codegen->invalid_instruction;
23262 return ira->codegen->invalid_inst_gen;
2235023263 }
2235123264
2235223265 if (target->value->type->id != ZigTypeIdEnum) {
......@@ -22359,75 +23272,73 @@ static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIns
2235923272 !target->value->type->data.enumeration.non_exhaustive) {
2236023273 TypeEnumField *only_field = &target->value->type->data.enumeration.fields[0];
2236123274 ZigValue *array_val = create_const_str_lit(ira->codegen, only_field->name)->data.x_ptr.data.ref.pointee;
22362 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
23275 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
2236323276 init_const_slice(ira->codegen, result->value, array_val, 0, buf_len(only_field->name), true);
2236423277 return result;
2236523278 }
2236623279
2236723280 if (instr_is_comptime(target)) {
2236823281 if ((err = type_resolve(ira->codegen, target->value->type, ResolveStatusZeroBitsKnown)))
22369 return ira->codegen->invalid_instruction;
23282 return ira->codegen->invalid_inst_gen;
2237023283 if (target->value->type->data.enumeration.non_exhaustive) {
22371 add_node_error(ira->codegen, instruction->base.source_node,
23284 ir_add_error(ira, &instruction->base.base,
2237223285 buf_sprintf("TODO @tagName on non-exhaustive enum https://github.com/ziglang/zig/issues/3991"));
22373 return ira->codegen->invalid_instruction;
23286 return ira->codegen->invalid_inst_gen;
2237423287 }
2237523288 TypeEnumField *field = find_enum_field_by_tag(target->value->type, &target->value->data.x_bigint);
2237623289 ZigValue *array_val = create_const_str_lit(ira->codegen, field->name)->data.x_ptr.data.ref.pointee;
22377 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
23290 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
2237823291 init_const_slice(ira->codegen, result->value, array_val, 0, buf_len(field->name), true);
2237923292 return result;
2238023293 }
2238123294
22382 IrInstruction *result = ir_build_tag_name(&ira->new_irb, instruction->base.scope,
22383 instruction->base.source_node, target);
2238423295 ZigType *u8_ptr_type = get_pointer_to_type_extra(
2238523296 ira->codegen, ira->codegen->builtin_types.entry_u8,
2238623297 true, false, PtrLenUnknown,
2238723298 0, 0, 0, false);
22388 result->value->type = get_slice_type(ira->codegen, u8_ptr_type);
22389 return result;
23299 ZigType *result_type = get_slice_type(ira->codegen, u8_ptr_type);
23300 return ir_build_tag_name_gen(ira, &instruction->base.base, target, result_type);
2239023301}
2239123302
22392static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
22393 IrInstructionFieldParentPtr *instruction)
23303static IrInstGen *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
23304 IrInstSrcFieldParentPtr *instruction)
2239423305{
2239523306 Error err;
22396 IrInstruction *type_value = instruction->type_value->child;
23307 IrInstGen *type_value = instruction->type_value->child;
2239723308 ZigType *container_type = ir_resolve_type(ira, type_value);
2239823309 if (type_is_invalid(container_type))
22399 return ira->codegen->invalid_instruction;
23310 return ira->codegen->invalid_inst_gen;
2240023311
22401 IrInstruction *field_name_value = instruction->field_name->child;
23312 IrInstGen *field_name_value = instruction->field_name->child;
2240223313 Buf *field_name = ir_resolve_str(ira, field_name_value);
2240323314 if (!field_name)
22404 return ira->codegen->invalid_instruction;
23315 return ira->codegen->invalid_inst_gen;
2240523316
22406 IrInstruction *field_ptr = instruction->field_ptr->child;
23317 IrInstGen *field_ptr = instruction->field_ptr->child;
2240723318 if (type_is_invalid(field_ptr->value->type))
22408 return ira->codegen->invalid_instruction;
23319 return ira->codegen->invalid_inst_gen;
2240923320
2241023321 if (container_type->id != ZigTypeIdStruct) {
22411 ir_add_error(ira, type_value,
23322 ir_add_error(ira, &type_value->base,
2241223323 buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name)));
22413 return ira->codegen->invalid_instruction;
23324 return ira->codegen->invalid_inst_gen;
2241423325 }
2241523326
2241623327 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))
22417 return ira->codegen->invalid_instruction;
23328 return ira->codegen->invalid_inst_gen;
2241823329
2241923330 TypeStructField *field = find_struct_type_field(container_type, field_name);
2242023331 if (field == nullptr) {
22421 ir_add_error(ira, field_name_value,
23332 ir_add_error(ira, &field_name_value->base,
2242223333 buf_sprintf("struct '%s' has no field '%s'",
2242323334 buf_ptr(&container_type->name), buf_ptr(field_name)));
22424 return ira->codegen->invalid_instruction;
23335 return ira->codegen->invalid_inst_gen;
2242523336 }
2242623337
2242723338 if (field_ptr->value->type->id != ZigTypeIdPointer) {
22428 ir_add_error(ira, field_ptr,
23339 ir_add_error(ira, &field_ptr->base,
2242923340 buf_sprintf("expected pointer, found '%s'", buf_ptr(&field_ptr->value->type->name)));
22430 return ira->codegen->invalid_instruction;
23341 return ira->codegen->invalid_inst_gen;
2243123342 }
2243223343
2243323344 bool is_packed = (container_type->data.structure.layout == ContainerLayoutPacked);
......@@ -22439,9 +23350,9 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
2243923350 field_ptr->value->type->data.pointer.is_volatile,
2244023351 PtrLenSingle,
2244123352 field_ptr_align, 0, 0, false);
22442 IrInstruction *casted_field_ptr = ir_implicit_cast(ira, field_ptr, field_ptr_type);
23353 IrInstGen *casted_field_ptr = ir_implicit_cast(ira, field_ptr, field_ptr_type);
2244323354 if (type_is_invalid(casted_field_ptr->value->type))
22444 return ira->codegen->invalid_instruction;
23355 return ira->codegen->invalid_inst_gen;
2244523356
2244623357 ZigType *result_type = get_pointer_to_type_extra(ira->codegen, container_type,
2244723358 casted_field_ptr->value->type->data.pointer.is_const,
......@@ -22452,23 +23363,23 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
2245223363 if (instr_is_comptime(casted_field_ptr)) {
2245323364 ZigValue *field_ptr_val = ir_resolve_const(ira, casted_field_ptr, UndefBad);
2245423365 if (!field_ptr_val)
22455 return ira->codegen->invalid_instruction;
23366 return ira->codegen->invalid_inst_gen;
2245623367
2245723368 if (field_ptr_val->data.x_ptr.special != ConstPtrSpecialBaseStruct) {
22458 ir_add_error(ira, field_ptr, buf_sprintf("pointer value not based on parent struct"));
22459 return ira->codegen->invalid_instruction;
23369 ir_add_error(ira, &field_ptr->base, buf_sprintf("pointer value not based on parent struct"));
23370 return ira->codegen->invalid_inst_gen;
2246023371 }
2246123372
2246223373 size_t ptr_field_index = field_ptr_val->data.x_ptr.data.base_struct.field_index;
2246323374 if (ptr_field_index != field->src_index) {
22464 ir_add_error(ira, &instruction->base,
23375 ir_add_error(ira, &instruction->base.base,
2246523376 buf_sprintf("field '%s' has index %" ZIG_PRI_usize " but pointer value is index %" ZIG_PRI_usize " of struct '%s'",
2246623377 buf_ptr(field->name), field->src_index,
2246723378 ptr_field_index, buf_ptr(&container_type->name)));
22468 return ira->codegen->invalid_instruction;
23379 return ira->codegen->invalid_inst_gen;
2246923380 }
2247023381
22471 IrInstruction *result = ir_const(ira, &instruction->base, result_type);
23382 IrInstGen *result = ir_const(ira, &instruction->base.base, result_type);
2247223383 ZigValue *out_val = result->value;
2247323384 out_val->data.x_ptr.special = ConstPtrSpecialRef;
2247423385 out_val->data.x_ptr.data.ref.pointee = field_ptr_val->data.x_ptr.data.base_struct.struct_val;
......@@ -22476,15 +23387,12 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
2247623387 return result;
2247723388 }
2247823389
22479 IrInstruction *result = ir_build_field_parent_ptr(&ira->new_irb, instruction->base.scope,
22480 instruction->base.source_node, type_value, field_name_value, casted_field_ptr, field);
22481 result->value->type = result_type;
22482 return result;
23390 return ir_build_field_parent_ptr_gen(ira, &instruction->base.base, casted_field_ptr, field, result_type);
2248323391}
2248423392
2248523393static TypeStructField *validate_byte_offset(IrAnalyze *ira,
22486 IrInstruction *type_value,
22487 IrInstruction *field_name_value,
23394 IrInstGen *type_value,
23395 IrInstGen *field_name_value,
2248823396 size_t *byte_offset)
2248923397{
2249023398 ZigType *container_type = ir_resolve_type(ira, type_value);
......@@ -22500,21 +23408,21 @@ static TypeStructField *validate_byte_offset(IrAnalyze *ira,
2250023408 return nullptr;
2250123409
2250223410 if (container_type->id != ZigTypeIdStruct) {
22503 ir_add_error(ira, type_value,
23411 ir_add_error(ira, &type_value->base,
2250423412 buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name)));
2250523413 return nullptr;
2250623414 }
2250723415
2250823416 TypeStructField *field = find_struct_type_field(container_type, field_name);
2250923417 if (field == nullptr) {
22510 ir_add_error(ira, field_name_value,
23418 ir_add_error(ira, &field_name_value->base,
2251123419 buf_sprintf("struct '%s' has no field '%s'",
2251223420 buf_ptr(&container_type->name), buf_ptr(field_name)));
2251323421 return nullptr;
2251423422 }
2251523423
2251623424 if (!type_has_bits(field->type_entry)) {
22517 ir_add_error(ira, field_name_value,
23425 ir_add_error(ira, &field_name_value->base,
2251823426 buf_sprintf("zero-bit field '%s' in struct '%s' has no offset",
2251923427 buf_ptr(field_name), buf_ptr(&container_type->name)));
2252023428 return nullptr;
......@@ -22524,36 +23432,32 @@ static TypeStructField *validate_byte_offset(IrAnalyze *ira,
2252423432 return field;
2252523433}
2252623434
22527static IrInstruction *ir_analyze_instruction_byte_offset_of(IrAnalyze *ira,
22528 IrInstructionByteOffsetOf *instruction)
22529{
22530 IrInstruction *type_value = instruction->type_value->child;
23435static IrInstGen *ir_analyze_instruction_byte_offset_of(IrAnalyze *ira, IrInstSrcByteOffsetOf *instruction) {
23436 IrInstGen *type_value = instruction->type_value->child;
2253123437 if (type_is_invalid(type_value->value->type))
22532 return ira->codegen->invalid_instruction;
23438 return ira->codegen->invalid_inst_gen;
2253323439
22534 IrInstruction *field_name_value = instruction->field_name->child;
23440 IrInstGen *field_name_value = instruction->field_name->child;
2253523441 size_t byte_offset = 0;
2253623442 if (!validate_byte_offset(ira, type_value, field_name_value, &byte_offset))
22537 return ira->codegen->invalid_instruction;
23443 return ira->codegen->invalid_inst_gen;
2253823444
2253923445
22540 return ir_const_unsigned(ira, &instruction->base, byte_offset);
23446 return ir_const_unsigned(ira, &instruction->base.base, byte_offset);
2254123447}
2254223448
22543static IrInstruction *ir_analyze_instruction_bit_offset_of(IrAnalyze *ira,
22544 IrInstructionBitOffsetOf *instruction)
22545{
22546 IrInstruction *type_value = instruction->type_value->child;
23449static IrInstGen *ir_analyze_instruction_bit_offset_of(IrAnalyze *ira, IrInstSrcBitOffsetOf *instruction) {
23450 IrInstGen *type_value = instruction->type_value->child;
2254723451 if (type_is_invalid(type_value->value->type))
22548 return ira->codegen->invalid_instruction;
22549 IrInstruction *field_name_value = instruction->field_name->child;
23452 return ira->codegen->invalid_inst_gen;
23453 IrInstGen *field_name_value = instruction->field_name->child;
2255023454 size_t byte_offset = 0;
2255123455 TypeStructField *field = nullptr;
2255223456 if (!(field = validate_byte_offset(ira, type_value, field_name_value, &byte_offset)))
22553 return ira->codegen->invalid_instruction;
23457 return ira->codegen->invalid_inst_gen;
2255423458
2255523459 size_t bit_offset = byte_offset * 8 + field->bit_offset_in_host;
22556 return ir_const_unsigned(ira, &instruction->base, bit_offset);
23460 return ir_const_unsigned(ira, &instruction->base.base, bit_offset);
2255723461}
2255823462
2255923463static void ensure_field_index(ZigType *type, const char *field_name, size_t index) {
......@@ -22601,7 +23505,7 @@ static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, Zig
2260123505 return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, nullptr, var->const_value);
2260223506}
2260323507
22604static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr, ZigValue *out_val,
23508static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigValue *out_val,
2260523509 ScopeDecls *decls_scope)
2260623510{
2260723511 Error err;
......@@ -22959,7 +23863,7 @@ static void make_enum_field_val(IrAnalyze *ira, ZigValue *enum_field_val, TypeEn
2295923863 enum_field_val->data.x_struct.fields = inner_fields;
2296023864}
2296123865
22962static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr, ZigType *type_entry,
23866static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigType *type_entry,
2296323867 ZigValue **out)
2296423868{
2296523869 Error err;
......@@ -23547,22 +24451,20 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2354724451 return ErrorNone;
2354824452}
2354924453
23550static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira,
23551 IrInstructionTypeInfo *instruction)
23552{
24454static IrInstGen *ir_analyze_instruction_type_info(IrAnalyze *ira, IrInstSrcTypeInfo *instruction) {
2355324455 Error err;
23554 IrInstruction *type_value = instruction->type_value->child;
24456 IrInstGen *type_value = instruction->type_value->child;
2355524457 ZigType *type_entry = ir_resolve_type(ira, type_value);
2355624458 if (type_is_invalid(type_entry))
23557 return ira->codegen->invalid_instruction;
24459 return ira->codegen->invalid_inst_gen;
2355824460
2355924461 ZigType *result_type = ir_type_info_get_type(ira, nullptr, nullptr);
2356024462
2356124463 ZigValue *payload;
23562 if ((err = ir_make_type_info_value(ira, &instruction->base, type_entry, &payload)))
23563 return ira->codegen->invalid_instruction;
24464 if ((err = ir_make_type_info_value(ira, &instruction->base.base, type_entry, &payload)))
24465 return ira->codegen->invalid_inst_gen;
2356424466
23565 IrInstruction *result = ir_const(ira, &instruction->base, result_type);
24467 IrInstGen *result = ir_const(ira, &instruction->base.base, result_type);
2356624468 ZigValue *out_val = result->value;
2356724469 bigint_init_unsigned(&out_val->data.x_union.tag, type_id_index(type_entry));
2356824470 out_val->data.x_union.payload = payload;
......@@ -23586,15 +24488,15 @@ static ZigValue *get_const_field(IrAnalyze *ira, AstNode *source_node, ZigValue
2358624488 return val;
2358724489}
2358824490
23589static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_instr, ZigValue *struct_value,
24491static Error get_const_field_sentinel(IrAnalyze *ira, IrInst* source_instr, ZigValue *struct_value,
2359024492 const char *name, size_t field_index, ZigType *elem_type, ZigValue **result)
2359124493{
2359224494 ZigValue *field_val = get_const_field(ira, source_instr->source_node, struct_value, name, field_index);
2359324495 if (field_val == nullptr)
2359424496 return ErrorSemanticAnalyzeFail;
2359524497
23596 IrInstruction *field_inst = ir_const_move(ira, source_instr, field_val);
23597 IrInstruction *casted_field_inst = ir_implicit_cast(ira, field_inst,
24498 IrInstGen *field_inst = ir_const_move(ira, source_instr, field_val);
24499 IrInstGen *casted_field_inst = ir_implicit_cast(ira, field_inst,
2359824500 get_optional_type(ira->codegen, elem_type));
2359924501 if (type_is_invalid(casted_field_inst->value->type))
2360024502 return ErrorSemanticAnalyzeFail;
......@@ -23633,12 +24535,12 @@ static ZigType *get_const_field_meta_type(IrAnalyze *ira, AstNode *source_node,
2363324535{
2363424536 ZigValue *value = get_const_field(ira, source_node, struct_value, name, field_index);
2363524537 if (value == nullptr)
23636 return ira->codegen->invalid_instruction->value->type;
24538 return ira->codegen->invalid_inst_gen->value->type;
2363724539 assert(value->type == ira->codegen->builtin_types.entry_type);
2363824540 return value->data.x_type;
2363924541}
2364024542
23641static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, ZigTypeId tagTypeId, ZigValue *payload) {
24543static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeId tagTypeId, ZigValue *payload) {
2364224544 Error err;
2364324545 switch (tagTypeId) {
2364424546 case ZigTypeIdInvalid:
......@@ -23654,21 +24556,21 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
2365424556 case ZigTypeIdInt: {
2365524557 assert(payload->special == ConstValSpecialStatic);
2365624558 assert(payload->type == ir_type_info_get_type(ira, "Int", nullptr));
23657 BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "bits", 1);
24559 BigInt *bi = get_const_field_lit_int(ira, source_instr->source_node, payload, "bits", 1);
2365824560 if (bi == nullptr)
23659 return ira->codegen->invalid_instruction->value->type;
24561 return ira->codegen->invalid_inst_gen->value->type;
2366024562 bool is_signed;
23661 if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_signed", 0, &is_signed)))
23662 return ira->codegen->invalid_instruction->value->type;
24563 if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_signed", 0, &is_signed)))
24564 return ira->codegen->invalid_inst_gen->value->type;
2366324565 return get_int_type(ira->codegen, is_signed, bigint_as_u32(bi));
2366424566 }
2366524567 case ZigTypeIdFloat:
2366624568 {
2366724569 assert(payload->special == ConstValSpecialStatic);
2366824570 assert(payload->type == ir_type_info_get_type(ira, "Float", nullptr));
23669 BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "bits", 0);
24571 BigInt *bi = get_const_field_lit_int(ira, source_instr->source_node, payload, "bits", 0);
2367024572 if (bi == nullptr)
23671 return ira->codegen->invalid_instruction->value->type;
24573 return ira->codegen->invalid_inst_gen->value->type;
2367224574 uint32_t bits = bigint_as_u32(bi);
2367324575 switch (bits) {
2367424576 case 16: return ira->codegen->builtin_types.entry_f16;
......@@ -23676,48 +24578,47 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
2367624578 case 64: return ira->codegen->builtin_types.entry_f64;
2367724579 case 128: return ira->codegen->builtin_types.entry_f128;
2367824580 }
23679 ir_add_error(ira, instruction,
23680 buf_sprintf("%d-bit float unsupported", bits));
23681 return ira->codegen->invalid_instruction->value->type;
24581 ir_add_error(ira, source_instr, buf_sprintf("%d-bit float unsupported", bits));
24582 return ira->codegen->invalid_inst_gen->value->type;
2368224583 }
2368324584 case ZigTypeIdPointer:
2368424585 {
2368524586 ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);
2368624587 assert(payload->special == ConstValSpecialStatic);
2368724588 assert(payload->type == type_info_pointer_type);
23688 ZigValue *size_value = get_const_field(ira, instruction->source_node, payload, "size", 0);
24589 ZigValue *size_value = get_const_field(ira, source_instr->source_node, payload, "size", 0);
2368924590 assert(size_value->type == ir_type_info_get_type(ira, "Size", type_info_pointer_type));
2369024591 BuiltinPtrSize size_enum_index = (BuiltinPtrSize)bigint_as_u32(&size_value->data.x_enum_tag);
2369124592 PtrLen ptr_len = size_enum_index_to_ptr_len(size_enum_index);
23692 ZigType *elem_type = get_const_field_meta_type(ira, instruction->source_node, payload, "child", 4);
24593 ZigType *elem_type = get_const_field_meta_type(ira, source_instr->source_node, payload, "child", 4);
2369324594 if (type_is_invalid(elem_type))
23694 return ira->codegen->invalid_instruction->value->type;
24595 return ira->codegen->invalid_inst_gen->value->type;
2369524596 ZigValue *sentinel;
23696 if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 6,
24597 if ((err = get_const_field_sentinel(ira, source_instr, payload, "sentinel", 6,
2369724598 elem_type, &sentinel)))
2369824599 {
23699 return ira->codegen->invalid_instruction->value->type;
24600 return ira->codegen->invalid_inst_gen->value->type;
2370024601 }
23701 BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "alignment", 3);
24602 BigInt *bi = get_const_field_lit_int(ira, source_instr->source_node, payload, "alignment", 3);
2370224603 if (bi == nullptr)
23703 return ira->codegen->invalid_instruction->value->type;
24604 return ira->codegen->invalid_inst_gen->value->type;
2370424605
2370524606 bool is_const;
23706 if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_const", 1, &is_const)))
23707 return ira->codegen->invalid_instruction->value->type;
24607 if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_const", 1, &is_const)))
24608 return ira->codegen->invalid_inst_gen->value->type;
2370824609
2370924610 bool is_volatile;
23710 if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_volatile", 2,
24611 if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_volatile", 2,
2371124612 &is_volatile)))
2371224613 {
23713 return ira->codegen->invalid_instruction->value->type;
24614 return ira->codegen->invalid_inst_gen->value->type;
2371424615 }
2371524616
2371624617 bool is_allowzero;
23717 if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_allowzero", 5,
24618 if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_allowzero", 5,
2371824619 &is_allowzero)))
2371924620 {
23720 return ira->codegen->invalid_instruction->value->type;
24621 return ira->codegen->invalid_inst_gen->value->type;
2372124622 }
2372224623
2372324624
......@@ -23738,18 +24639,18 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
2373824639 case ZigTypeIdArray: {
2373924640 assert(payload->special == ConstValSpecialStatic);
2374024641 assert(payload->type == ir_type_info_get_type(ira, "Array", nullptr));
23741 ZigType *elem_type = get_const_field_meta_type(ira, instruction->source_node, payload, "child", 1);
24642 ZigType *elem_type = get_const_field_meta_type(ira, source_instr->source_node, payload, "child", 1);
2374224643 if (type_is_invalid(elem_type))
23743 return ira->codegen->invalid_instruction->value->type;
24644 return ira->codegen->invalid_inst_gen->value->type;
2374424645 ZigValue *sentinel;
23745 if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 2,
24646 if ((err = get_const_field_sentinel(ira, source_instr, payload, "sentinel", 2,
2374624647 elem_type, &sentinel)))
2374724648 {
23748 return ira->codegen->invalid_instruction->value->type;
24649 return ira->codegen->invalid_inst_gen->value->type;
2374924650 }
23750 BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "len", 0);
24651 BigInt *bi = get_const_field_lit_int(ira, source_instr->source_node, payload, "len", 0);
2375124652 if (bi == nullptr)
23752 return ira->codegen->invalid_instruction->value->type;
24653 return ira->codegen->invalid_inst_gen->value->type;
2375324654 return get_array_type(ira->codegen, elem_type, bigint_as_u64(bi), sentinel);
2375424655 }
2375524656 case ZigTypeIdComptimeFloat:
......@@ -23769,78 +24670,77 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
2376924670 case ZigTypeIdAnyFrame:
2377024671 case ZigTypeIdVector:
2377124672 case ZigTypeIdEnumLiteral:
23772 ir_add_error(ira, instruction, buf_sprintf(
24673 ir_add_error(ira, source_instr, buf_sprintf(
2377324674 "TODO implement @Type for 'TypeInfo.%s': see https://github.com/ziglang/zig/issues/2907", type_id_name(tagTypeId)));
23774 return ira->codegen->invalid_instruction->value->type;
24675 return ira->codegen->invalid_inst_gen->value->type;
2377524676 case ZigTypeIdUnion:
2377624677 case ZigTypeIdFn:
2377724678 case ZigTypeIdBoundFn:
2377824679 case ZigTypeIdStruct:
23779 ir_add_error(ira, instruction, buf_sprintf(
24680 ir_add_error(ira, source_instr, buf_sprintf(
2378024681 "@Type not availble for 'TypeInfo.%s'", type_id_name(tagTypeId)));
23781 return ira->codegen->invalid_instruction->value->type;
24682 return ira->codegen->invalid_inst_gen->value->type;
2378224683 }
2378324684 zig_unreachable();
2378424685}
2378524686
23786static IrInstruction *ir_analyze_instruction_type(IrAnalyze *ira, IrInstructionType *instruction) {
23787 IrInstruction *type_info_ir = instruction->type_info->child;
23788 if (type_is_invalid(type_info_ir->value->type))
23789 return ira->codegen->invalid_instruction;
24687static IrInstGen *ir_analyze_instruction_type(IrAnalyze *ira, IrInstSrcType *instruction) {
24688 IrInstGen *uncasted_type_info = instruction->type_info->child;
24689 if (type_is_invalid(uncasted_type_info->value->type))
24690 return ira->codegen->invalid_inst_gen;
2379024691
23791 IrInstruction *casted_ir = ir_implicit_cast(ira, type_info_ir, ir_type_info_get_type(ira, nullptr, nullptr));
23792 if (type_is_invalid(casted_ir->value->type))
23793 return ira->codegen->invalid_instruction;
24692 IrInstGen *type_info = ir_implicit_cast(ira, uncasted_type_info, ir_type_info_get_type(ira, nullptr, nullptr));
24693 if (type_is_invalid(type_info->value->type))
24694 return ira->codegen->invalid_inst_gen;
2379424695
23795 ZigValue *type_info_value = ir_resolve_const(ira, casted_ir, UndefBad);
23796 if (!type_info_value)
23797 return ira->codegen->invalid_instruction;
23798 ZigTypeId typeId = type_id_at_index(bigint_as_usize(&type_info_value->data.x_union.tag));
23799 ZigType *type = type_info_to_type(ira, type_info_ir, typeId, type_info_value->data.x_union.payload);
24696 ZigValue *type_info_val = ir_resolve_const(ira, type_info, UndefBad);
24697 if (type_info_val == nullptr)
24698 return ira->codegen->invalid_inst_gen;
24699 ZigTypeId type_id_tag = type_id_at_index(bigint_as_usize(&type_info_val->data.x_union.tag));
24700 ZigType *type = type_info_to_type(ira, &uncasted_type_info->base, type_id_tag,
24701 type_info_val->data.x_union.payload);
2380024702 if (type_is_invalid(type))
23801 return ira->codegen->invalid_instruction;
23802 return ir_const_type(ira, &instruction->base, type);
24703 return ira->codegen->invalid_inst_gen;
24704 return ir_const_type(ira, &instruction->base.base, type);
2380324705}
2380424706
23805static IrInstruction *ir_analyze_instruction_type_id(IrAnalyze *ira,
23806 IrInstructionTypeId *instruction)
23807{
23808 IrInstruction *type_value = instruction->type_value->child;
24707static IrInstGen *ir_analyze_instruction_type_id(IrAnalyze *ira, IrInstSrcTypeId *instruction) {
24708 IrInstGen *type_value = instruction->type_value->child;
2380924709 ZigType *type_entry = ir_resolve_type(ira, type_value);
2381024710 if (type_is_invalid(type_entry))
23811 return ira->codegen->invalid_instruction;
24711 return ira->codegen->invalid_inst_gen;
2381224712
2381324713 ZigType *result_type = get_builtin_type(ira->codegen, "TypeId");
2381424714
23815 IrInstruction *result = ir_const(ira, &instruction->base, result_type);
24715 IrInstGen *result = ir_const(ira, &instruction->base.base, result_type);
2381624716 bigint_init_unsigned(&result->value->data.x_enum_tag, type_id_index(type_entry));
2381724717 return result;
2381824718}
2381924719
23820static IrInstruction *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira,
23821 IrInstructionSetEvalBranchQuota *instruction)
24720static IrInstGen *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira,
24721 IrInstSrcSetEvalBranchQuota *instruction)
2382224722{
2382324723 uint64_t new_quota;
2382424724 if (!ir_resolve_usize(ira, instruction->new_quota->child, &new_quota))
23825 return ira->codegen->invalid_instruction;
24725 return ira->codegen->invalid_inst_gen;
2382624726
2382724727 if (new_quota > *ira->new_irb.exec->backward_branch_quota) {
2382824728 *ira->new_irb.exec->backward_branch_quota = new_quota;
2382924729 }
2383024730
23831 return ir_const_void(ira, &instruction->base);
24731 return ir_const_void(ira, &instruction->base.base);
2383224732}
2383324733
23834static IrInstruction *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstructionTypeName *instruction) {
23835 IrInstruction *type_value = instruction->type_value->child;
24734static IrInstGen *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstSrcTypeName *instruction) {
24735 IrInstGen *type_value = instruction->type_value->child;
2383624736 ZigType *type_entry = ir_resolve_type(ira, type_value);
2383724737 if (type_is_invalid(type_entry))
23838 return ira->codegen->invalid_instruction;
24738 return ira->codegen->invalid_inst_gen;
2383924739
2384024740 if (!type_entry->cached_const_name_val) {
2384124741 type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, type_bare_name(type_entry));
2384224742 }
23843 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
24743 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
2384424744 copy_const_val(result->value, type_entry->cached_const_name_val);
2384524745 return result;
2384624746}
......@@ -23852,13 +24752,13 @@ static void ir_cimport_cache_paths(Buf *cache_dir, Buf *tmp_c_file_digest, Buf *
2385224752 buf_ptr(cache_dir), buf_ptr(tmp_c_file_digest));
2385324753 buf_appendf(out_zig_path, "%s" OS_SEP "cimport.zig", buf_ptr(out_zig_dir));
2385424754}
23855static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstructionCImport *instruction) {
24755static IrInstGen *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstSrcCImport *instruction) {
2385624756 Error err;
23857 AstNode *node = instruction->base.source_node;
24757 AstNode *node = instruction->base.base.source_node;
2385824758 assert(node->type == NodeTypeFnCallExpr);
2385924759 AstNode *block_node = node->data.fn_call_expr.params.at(0);
2386024760
23861 ScopeCImport *cimport_scope = create_cimport_scope(ira->codegen, node, instruction->base.scope);
24761 ScopeCImport *cimport_scope = create_cimport_scope(ira->codegen, node, instruction->base.base.scope);
2386224762
2386324763 // Execute the C import block like an inline function
2386424764 ZigType *void_type = ira->codegen->builtin_types.entry_void;
......@@ -23866,9 +24766,9 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
2386624766 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr,
2386724767 &cimport_scope->buf, block_node, nullptr, nullptr, nullptr, UndefBad);
2386824768 if (type_is_invalid(cimport_result->type))
23869 return ira->codegen->invalid_instruction;
24769 return ira->codegen->invalid_inst_gen;
2387024770
23871 ZigPackage *cur_scope_pkg = scope_package(instruction->base.scope);
24771 ZigPackage *cur_scope_pkg = scope_package(instruction->base.base.scope);
2387224772 Buf *namespace_name = buf_sprintf("%s.cimport:%" ZIG_PRI_usize ":%" ZIG_PRI_usize,
2387324773 buf_ptr(&cur_scope_pkg->pkg_path), node->line + 1, node->column + 1);
2387424774
......@@ -23880,7 +24780,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
2388024780 CacheHash *cache_hash;
2388124781 if ((err = create_c_object_cache(ira->codegen, &cache_hash, false))) {
2388224782 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to create cache: %s", err_str(err)));
23883 return ira->codegen->invalid_instruction;
24783 return ira->codegen->invalid_inst_gen;
2388424784 }
2388524785 cache_buf(cache_hash, &cimport_scope->buf);
2388624786
......@@ -23892,7 +24792,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
2389224792 if ((err = cache_hit(cache_hash, &tmp_c_file_digest))) {
2389324793 if (err != ErrorInvalidFormat) {
2389424794 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to check cache: %s", err_str(err)));
23895 return ira->codegen->invalid_instruction;
24795 return ira->codegen->invalid_inst_gen;
2389624796 }
2389724797 }
2389824798 ira->codegen->caches_to_release.append(cache_hash);
......@@ -23911,12 +24811,12 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
2391124811
2391224812 if ((err = os_make_path(tmp_c_file_dir))) {
2391324813 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to make dir: %s", err_str(err)));
23914 return ira->codegen->invalid_instruction;
24814 return ira->codegen->invalid_inst_gen;
2391524815 }
2391624816
2391724817 if ((err = os_write_file(&tmp_c_file_path, &cimport_scope->buf))) {
2391824818 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to write .h file: %s", err_str(err)));
23919 return ira->codegen->invalid_instruction;
24819 return ira->codegen->invalid_inst_gen;
2392024820 }
2392124821 if (ira->codegen->verbose_cimport) {
2392224822 fprintf(stderr, "@cImport source: %s\n", buf_ptr(&tmp_c_file_path));
......@@ -23951,7 +24851,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
2395124851 {
2395224852 if (err != ErrorCCompileErrors) {
2395324853 ir_add_error_node(ira, node, buf_sprintf("C import failed: %s", err_str(err)));
23954 return ira->codegen->invalid_instruction;
24854 return ira->codegen->invalid_inst_gen;
2395524855 }
2395624856
2395724857 ErrorMsg *parent_err_msg = ir_add_error_node(ira, node, buf_sprintf("C import failed"));
......@@ -23972,7 +24872,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
2397224872 }
2397324873 }
2397424874
23975 return ira->codegen->invalid_instruction;
24875 return ira->codegen->invalid_inst_gen;
2397624876 }
2397724877 if (ira->codegen->verbose_cimport) {
2397824878 fprintf(stderr, "@cImport .d file: %s\n", buf_ptr(tmp_dep_file));
......@@ -23980,29 +24880,29 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
2398024880
2398124881 if ((err = cache_add_dep_file(cache_hash, tmp_dep_file, false))) {
2398224882 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to parse .d file: %s", err_str(err)));
23983 return ira->codegen->invalid_instruction;
24883 return ira->codegen->invalid_inst_gen;
2398424884 }
2398524885 if ((err = cache_final(cache_hash, &tmp_c_file_digest))) {
2398624886 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to finalize cache: %s", err_str(err)));
23987 return ira->codegen->invalid_instruction;
24887 return ira->codegen->invalid_inst_gen;
2398824888 }
2398924889
2399024890 ir_cimport_cache_paths(ira->codegen->cache_dir, &tmp_c_file_digest, out_zig_dir, out_zig_path);
2399124891 if ((err = os_make_path(out_zig_dir))) {
2399224892 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to make output dir: %s", err_str(err)));
23993 return ira->codegen->invalid_instruction;
24893 return ira->codegen->invalid_inst_gen;
2399424894 }
2399524895 FILE *out_file = fopen(buf_ptr(out_zig_path), "wb");
2399624896 if (out_file == nullptr) {
2399724897 ir_add_error_node(ira, node,
2399824898 buf_sprintf("C import failed: unable to open output file: %s", strerror(errno)));
23999 return ira->codegen->invalid_instruction;
24899 return ira->codegen->invalid_inst_gen;
2400024900 }
2400124901 stage2_render_ast(ast, out_file);
2400224902 if (fclose(out_file) != 0) {
2400324903 ir_add_error_node(ira, node,
2400424904 buf_sprintf("C import failed: unable to write to output file: %s", strerror(errno)));
24005 return ira->codegen->invalid_instruction;
24905 return ira->codegen->invalid_inst_gen;
2400624906 }
2400724907
2400824908 if (ira->codegen->verbose_cimport) {
......@@ -24021,90 +24921,90 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
2402124921 if ((err = file_fetch(ira->codegen, out_zig_path, import_code))) {
2402224922 ir_add_error_node(ira, node,
2402324923 buf_sprintf("unable to open '%s': %s", buf_ptr(out_zig_path), err_str(err)));
24024 return ira->codegen->invalid_instruction;
24924 return ira->codegen->invalid_inst_gen;
2402524925 }
2402624926 ZigType *child_import = add_source_file(ira->codegen, cimport_pkg, out_zig_path,
2402724927 import_code, SourceKindCImport);
24028 return ir_const_type(ira, &instruction->base, child_import);
24928 return ir_const_type(ira, &instruction->base.base, child_import);
2402924929}
2403024930
24031static IrInstruction *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstructionCInclude *instruction) {
24032 IrInstruction *name_value = instruction->name->child;
24931static IrInstGen *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstSrcCInclude *instruction) {
24932 IrInstGen *name_value = instruction->name->child;
2403324933 if (type_is_invalid(name_value->value->type))
24034 return ira->codegen->invalid_instruction;
24934 return ira->codegen->invalid_inst_gen;
2403524935
2403624936 Buf *include_name = ir_resolve_str(ira, name_value);
2403724937 if (!include_name)
24038 return ira->codegen->invalid_instruction;
24938 return ira->codegen->invalid_inst_gen;
2403924939
24040 Buf *c_import_buf = exec_c_import_buf(ira->new_irb.exec);
24940 Buf *c_import_buf = ira->new_irb.exec->c_import_buf;
2404124941 // We check for this error in pass1
2404224942 assert(c_import_buf);
2404324943
2404424944 buf_appendf(c_import_buf, "#include <%s>\n", buf_ptr(include_name));
2404524945
24046 return ir_const_void(ira, &instruction->base);
24946 return ir_const_void(ira, &instruction->base.base);
2404724947}
2404824948
24049static IrInstruction *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstructionCDefine *instruction) {
24050 IrInstruction *name = instruction->name->child;
24949static IrInstGen *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstSrcCDefine *instruction) {
24950 IrInstGen *name = instruction->name->child;
2405124951 if (type_is_invalid(name->value->type))
24052 return ira->codegen->invalid_instruction;
24952 return ira->codegen->invalid_inst_gen;
2405324953
2405424954 Buf *define_name = ir_resolve_str(ira, name);
2405524955 if (!define_name)
24056 return ira->codegen->invalid_instruction;
24956 return ira->codegen->invalid_inst_gen;
2405724957
24058 IrInstruction *value = instruction->value->child;
24958 IrInstGen *value = instruction->value->child;
2405924959 if (type_is_invalid(value->value->type))
24060 return ira->codegen->invalid_instruction;
24960 return ira->codegen->invalid_inst_gen;
2406124961
2406224962 Buf *define_value = nullptr;
2406324963 // The second parameter is either a string or void (equivalent to "")
2406424964 if (value->value->type->id != ZigTypeIdVoid) {
2406524965 define_value = ir_resolve_str(ira, value);
2406624966 if (!define_value)
24067 return ira->codegen->invalid_instruction;
24967 return ira->codegen->invalid_inst_gen;
2406824968 }
2406924969
24070 Buf *c_import_buf = exec_c_import_buf(ira->new_irb.exec);
24970 Buf *c_import_buf = ira->new_irb.exec->c_import_buf;
2407124971 // We check for this error in pass1
2407224972 assert(c_import_buf);
2407324973
2407424974 buf_appendf(c_import_buf, "#define %s %s\n", buf_ptr(define_name),
2407524975 define_value ? buf_ptr(define_value) : "");
2407624976
24077 return ir_const_void(ira, &instruction->base);
24977 return ir_const_void(ira, &instruction->base.base);
2407824978}
2407924979
24080static IrInstruction *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructionCUndef *instruction) {
24081 IrInstruction *name = instruction->name->child;
24980static IrInstGen *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstSrcCUndef *instruction) {
24981 IrInstGen *name = instruction->name->child;
2408224982 if (type_is_invalid(name->value->type))
24083 return ira->codegen->invalid_instruction;
24983 return ira->codegen->invalid_inst_gen;
2408424984
2408524985 Buf *undef_name = ir_resolve_str(ira, name);
2408624986 if (!undef_name)
24087 return ira->codegen->invalid_instruction;
24987 return ira->codegen->invalid_inst_gen;
2408824988
24089 Buf *c_import_buf = exec_c_import_buf(ira->new_irb.exec);
24989 Buf *c_import_buf = ira->new_irb.exec->c_import_buf;
2409024990 // We check for this error in pass1
2409124991 assert(c_import_buf);
2409224992
2409324993 buf_appendf(c_import_buf, "#undef %s\n", buf_ptr(undef_name));
2409424994
24095 return ir_const_void(ira, &instruction->base);
24995 return ir_const_void(ira, &instruction->base.base);
2409624996}
2409724997
24098static IrInstruction *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstructionEmbedFile *instruction) {
24099 IrInstruction *name = instruction->name->child;
24998static IrInstGen *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstSrcEmbedFile *instruction) {
24999 IrInstGen *name = instruction->name->child;
2410025000 if (type_is_invalid(name->value->type))
24101 return ira->codegen->invalid_instruction;
25001 return ira->codegen->invalid_inst_gen;
2410225002
2410325003 Buf *rel_file_path = ir_resolve_str(ira, name);
2410425004 if (!rel_file_path)
24105 return ira->codegen->invalid_instruction;
25005 return ira->codegen->invalid_inst_gen;
2410625006
24107 ZigType *import = get_scope_import(instruction->base.scope);
25007 ZigType *import = get_scope_import(instruction->base.base.scope);
2410825008 // figure out absolute path to resource
2410925009 Buf source_dir_path = BUF_INIT;
2411025010 os_path_dirname(import->data.structure.root_struct->path, &source_dir_path);
......@@ -24121,93 +25021,95 @@ static IrInstruction *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstru
2412125021 Error err;
2412225022 if ((err = file_fetch(ira->codegen, file_path, file_contents))) {
2412325023 if (err == ErrorFileNotFound) {
24124 ir_add_error(ira, instruction->name, buf_sprintf("unable to find '%s'", buf_ptr(file_path)));
24125 return ira->codegen->invalid_instruction;
25024 ir_add_error(ira, &instruction->name->base,
25025 buf_sprintf("unable to find '%s'", buf_ptr(file_path)));
25026 return ira->codegen->invalid_inst_gen;
2412625027 } else {
24127 ir_add_error(ira, instruction->name, buf_sprintf("unable to open '%s': %s", buf_ptr(file_path), err_str(err)));
24128 return ira->codegen->invalid_instruction;
25028 ir_add_error(ira, &instruction->name->base,
25029 buf_sprintf("unable to open '%s': %s", buf_ptr(file_path), err_str(err)));
25030 return ira->codegen->invalid_inst_gen;
2412925031 }
2413025032 }
2413125033
2413225034 ZigType *result_type = get_array_type(ira->codegen,
2413325035 ira->codegen->builtin_types.entry_u8, buf_len(file_contents), nullptr);
24134 IrInstruction *result = ir_const(ira, &instruction->base, result_type);
25036 IrInstGen *result = ir_const(ira, &instruction->base.base, result_type);
2413525037 init_const_str_lit(ira->codegen, result->value, file_contents);
2413625038 return result;
2413725039}
2413825040
24139static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructionCmpxchgSrc *instruction) {
25041static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxchg *instruction) {
2414025042 ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->type_value->child);
2414125043 if (type_is_invalid(operand_type))
24142 return ira->codegen->invalid_instruction;
25044 return ira->codegen->invalid_inst_gen;
2414325045
2414425046 if (operand_type->id == ZigTypeIdFloat) {
24145 ir_add_error(ira, instruction->type_value->child,
25047 ir_add_error(ira, &instruction->type_value->child->base,
2414625048 buf_sprintf("expected integer, enum or pointer type, found '%s'", buf_ptr(&operand_type->name)));
24147 return ira->codegen->invalid_instruction;
25049 return ira->codegen->invalid_inst_gen;
2414825050 }
2414925051
24150 IrInstruction *ptr = instruction->ptr->child;
25052 IrInstGen *ptr = instruction->ptr->child;
2415125053 if (type_is_invalid(ptr->value->type))
24152 return ira->codegen->invalid_instruction;
25054 return ira->codegen->invalid_inst_gen;
2415325055
2415425056 // TODO let this be volatile
2415525057 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);
24156 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr, ptr_type);
25058 IrInstGen *casted_ptr = ir_implicit_cast(ira, ptr, ptr_type);
2415725059 if (type_is_invalid(casted_ptr->value->type))
24158 return ira->codegen->invalid_instruction;
25060 return ira->codegen->invalid_inst_gen;
2415925061
24160 IrInstruction *cmp_value = instruction->cmp_value->child;
25062 IrInstGen *cmp_value = instruction->cmp_value->child;
2416125063 if (type_is_invalid(cmp_value->value->type))
24162 return ira->codegen->invalid_instruction;
25064 return ira->codegen->invalid_inst_gen;
2416325065
24164 IrInstruction *new_value = instruction->new_value->child;
25066 IrInstGen *new_value = instruction->new_value->child;
2416525067 if (type_is_invalid(new_value->value->type))
24166 return ira->codegen->invalid_instruction;
25068 return ira->codegen->invalid_inst_gen;
2416725069
24168 IrInstruction *success_order_value = instruction->success_order_value->child;
25070 IrInstGen *success_order_value = instruction->success_order_value->child;
2416925071 if (type_is_invalid(success_order_value->value->type))
24170 return ira->codegen->invalid_instruction;
25072 return ira->codegen->invalid_inst_gen;
2417125073
2417225074 AtomicOrder success_order;
2417325075 if (!ir_resolve_atomic_order(ira, success_order_value, &success_order))
24174 return ira->codegen->invalid_instruction;
25076 return ira->codegen->invalid_inst_gen;
2417525077
24176 IrInstruction *failure_order_value = instruction->failure_order_value->child;
25078 IrInstGen *failure_order_value = instruction->failure_order_value->child;
2417725079 if (type_is_invalid(failure_order_value->value->type))
24178 return ira->codegen->invalid_instruction;
25080 return ira->codegen->invalid_inst_gen;
2417925081
2418025082 AtomicOrder failure_order;
2418125083 if (!ir_resolve_atomic_order(ira, failure_order_value, &failure_order))
24182 return ira->codegen->invalid_instruction;
25084 return ira->codegen->invalid_inst_gen;
2418325085
24184 IrInstruction *casted_cmp_value = ir_implicit_cast(ira, cmp_value, operand_type);
25086 IrInstGen *casted_cmp_value = ir_implicit_cast(ira, cmp_value, operand_type);
2418525087 if (type_is_invalid(casted_cmp_value->value->type))
24186 return ira->codegen->invalid_instruction;
25088 return ira->codegen->invalid_inst_gen;
2418725089
24188 IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, operand_type);
25090 IrInstGen *casted_new_value = ir_implicit_cast(ira, new_value, operand_type);
2418925091 if (type_is_invalid(casted_new_value->value->type))
24190 return ira->codegen->invalid_instruction;
25092 return ira->codegen->invalid_inst_gen;
2419125093
2419225094 if (success_order < AtomicOrderMonotonic) {
24193 ir_add_error(ira, success_order_value,
25095 ir_add_error(ira, &success_order_value->base,
2419425096 buf_sprintf("success atomic ordering must be Monotonic or stricter"));
24195 return ira->codegen->invalid_instruction;
25097 return ira->codegen->invalid_inst_gen;
2419625098 }
2419725099 if (failure_order < AtomicOrderMonotonic) {
24198 ir_add_error(ira, failure_order_value,
25100 ir_add_error(ira, &failure_order_value->base,
2419925101 buf_sprintf("failure atomic ordering must be Monotonic or stricter"));
24200 return ira->codegen->invalid_instruction;
25102 return ira->codegen->invalid_inst_gen;
2420125103 }
2420225104 if (failure_order > success_order) {
24203 ir_add_error(ira, failure_order_value,
25105 ir_add_error(ira, &failure_order_value->base,
2420425106 buf_sprintf("failure atomic ordering must be no stricter than success"));
24205 return ira->codegen->invalid_instruction;
25107 return ira->codegen->invalid_inst_gen;
2420625108 }
2420725109 if (failure_order == AtomicOrderRelease || failure_order == AtomicOrderAcqRel) {
24208 ir_add_error(ira, failure_order_value,
25110 ir_add_error(ira, &failure_order_value->base,
2420925111 buf_sprintf("failure atomic ordering must not be Release or AcqRel"));
24210 return ira->codegen->invalid_instruction;
25112 return ira->codegen->invalid_inst_gen;
2421125113 }
2421225114
2421325115 if (instr_is_comptime(casted_ptr) && casted_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar &&
......@@ -24216,66 +25118,63 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi
2421625118 }
2421725119
2421825120 ZigType *result_type = get_optional_type(ira->codegen, operand_type);
24219 IrInstruction *result_loc;
25121 IrInstGen *result_loc;
2422025122 if (handle_is_ptr(result_type)) {
24221 result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
25123 result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
2422225124 result_type, nullptr, true, false, true);
24223 if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) {
25125 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
2422425126 return result_loc;
2422525127 }
2422625128 } else {
2422725129 result_loc = nullptr;
2422825130 }
2422925131
24230 return ir_build_cmpxchg_gen(ira, &instruction->base, result_type,
25132 return ir_build_cmpxchg_gen(ira, &instruction->base.base, result_type,
2423125133 casted_ptr, casted_cmp_value, casted_new_value,
2423225134 success_order, failure_order, instruction->is_weak, result_loc);
2423325135}
2423425136
24235static IrInstruction *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructionFence *instruction) {
24236 IrInstruction *order_value = instruction->order_value->child;
24237 if (type_is_invalid(order_value->value->type))
24238 return ira->codegen->invalid_instruction;
25137static IrInstGen *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstSrcFence *instruction) {
25138 IrInstGen *order_inst = instruction->order->child;
25139 if (type_is_invalid(order_inst->value->type))
25140 return ira->codegen->invalid_inst_gen;
2423925141
2424025142 AtomicOrder order;
24241 if (!ir_resolve_atomic_order(ira, order_value, &order))
24242 return ira->codegen->invalid_instruction;
25143 if (!ir_resolve_atomic_order(ira, order_inst, &order))
25144 return ira->codegen->invalid_inst_gen;
2424325145
2424425146 if (order < AtomicOrderAcquire) {
24245 ir_add_error(ira, order_value,
25147 ir_add_error(ira, &order_inst->base,
2424625148 buf_sprintf("atomic ordering must be Acquire or stricter"));
24247 return ira->codegen->invalid_instruction;
25149 return ira->codegen->invalid_inst_gen;
2424825150 }
2424925151
24250 IrInstruction *result = ir_build_fence(&ira->new_irb,
24251 instruction->base.scope, instruction->base.source_node, order_value, order);
24252 result->value->type = ira->codegen->builtin_types.entry_void;
24253 return result;
25152 return ir_build_fence_gen(ira, &instruction->base.base, order);
2425425153}
2425525154
24256static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstructionTruncate *instruction) {
24257 IrInstruction *dest_type_value = instruction->dest_type->child;
25155static IrInstGen *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstSrcTruncate *instruction) {
25156 IrInstGen *dest_type_value = instruction->dest_type->child;
2425825157 ZigType *dest_type = ir_resolve_type(ira, dest_type_value);
2425925158 if (type_is_invalid(dest_type))
24260 return ira->codegen->invalid_instruction;
25159 return ira->codegen->invalid_inst_gen;
2426125160
2426225161 if (dest_type->id != ZigTypeIdInt &&
2426325162 dest_type->id != ZigTypeIdComptimeInt)
2426425163 {
24265 ir_add_error(ira, dest_type_value, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
24266 return ira->codegen->invalid_instruction;
25164 ir_add_error(ira, &dest_type_value->base, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
25165 return ira->codegen->invalid_inst_gen;
2426725166 }
2426825167
24269 IrInstruction *target = instruction->target->child;
25168 IrInstGen *target = instruction->target->child;
2427025169 ZigType *src_type = target->value->type;
2427125170 if (type_is_invalid(src_type))
24272 return ira->codegen->invalid_instruction;
25171 return ira->codegen->invalid_inst_gen;
2427325172
2427425173 if (src_type->id != ZigTypeIdInt &&
2427525174 src_type->id != ZigTypeIdComptimeInt)
2427625175 {
24277 ir_add_error(ira, target, buf_sprintf("expected integer type, found '%s'", buf_ptr(&src_type->name)));
24278 return ira->codegen->invalid_instruction;
25176 ir_add_error(ira, &target->base, buf_sprintf("expected integer type, found '%s'", buf_ptr(&src_type->name)));
25177 return ira->codegen->invalid_inst_gen;
2427925178 }
2428025179
2428125180 if (dest_type->id == ZigTypeIdComptimeInt) {
......@@ -24285,54 +25184,51 @@ static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruct
2428525184 if (instr_is_comptime(target)) {
2428625185 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
2428725186 if (val == nullptr)
24288 return ira->codegen->invalid_instruction;
25187 return ira->codegen->invalid_inst_gen;
2428925188
24290 IrInstruction *result = ir_const(ira, &instruction->base, dest_type);
25189 IrInstGen *result = ir_const(ira, &instruction->base.base, dest_type);
2429125190 bigint_truncate(&result->value->data.x_bigint, &val->data.x_bigint,
2429225191 dest_type->data.integral.bit_count, dest_type->data.integral.is_signed);
2429325192 return result;
2429425193 }
2429525194
2429625195 if (src_type->data.integral.bit_count == 0 || dest_type->data.integral.bit_count == 0) {
24297 IrInstruction *result = ir_const(ira, &instruction->base, dest_type);
25196 IrInstGen *result = ir_const(ira, &instruction->base.base, dest_type);
2429825197 bigint_init_unsigned(&result->value->data.x_bigint, 0);
2429925198 return result;
2430025199 }
2430125200
2430225201 if (src_type->data.integral.is_signed != dest_type->data.integral.is_signed) {
2430325202 const char *sign_str = dest_type->data.integral.is_signed ? "signed" : "unsigned";
24304 ir_add_error(ira, target, buf_sprintf("expected %s integer type, found '%s'", sign_str, buf_ptr(&src_type->name)));
24305 return ira->codegen->invalid_instruction;
25203 ir_add_error(ira, &target->base, buf_sprintf("expected %s integer type, found '%s'", sign_str, buf_ptr(&src_type->name)));
25204 return ira->codegen->invalid_inst_gen;
2430625205 } else if (src_type->data.integral.bit_count < dest_type->data.integral.bit_count) {
24307 ir_add_error(ira, target, buf_sprintf("type '%s' has fewer bits than destination type '%s'",
25206 ir_add_error(ira, &target->base, buf_sprintf("type '%s' has fewer bits than destination type '%s'",
2430825207 buf_ptr(&src_type->name), buf_ptr(&dest_type->name)));
24309 return ira->codegen->invalid_instruction;
25208 return ira->codegen->invalid_inst_gen;
2431025209 }
2431125210
24312 IrInstruction *new_instruction = ir_build_truncate(&ira->new_irb, instruction->base.scope,
24313 instruction->base.source_node, dest_type_value, target);
24314 new_instruction->value->type = dest_type;
24315 return new_instruction;
25211 return ir_build_truncate_gen(ira, &instruction->base.base, dest_type, target);
2431625212}
2431725213
24318static IrInstruction *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstructionIntCast *instruction) {
25214static IrInstGen *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstSrcIntCast *instruction) {
2431925215 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);
2432025216 if (type_is_invalid(dest_type))
24321 return ira->codegen->invalid_instruction;
25217 return ira->codegen->invalid_inst_gen;
2432225218
2432325219 if (dest_type->id != ZigTypeIdInt && dest_type->id != ZigTypeIdComptimeInt) {
24324 ir_add_error(ira, instruction->dest_type, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
24325 return ira->codegen->invalid_instruction;
25220 ir_add_error(ira, &instruction->dest_type->base, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
25221 return ira->codegen->invalid_inst_gen;
2432625222 }
2432725223
24328 IrInstruction *target = instruction->target->child;
25224 IrInstGen *target = instruction->target->child;
2432925225 if (type_is_invalid(target->value->type))
24330 return ira->codegen->invalid_instruction;
25226 return ira->codegen->invalid_inst_gen;
2433125227
2433225228 if (target->value->type->id != ZigTypeIdInt && target->value->type->id != ZigTypeIdComptimeInt) {
24333 ir_add_error(ira, instruction->target, buf_sprintf("expected integer type, found '%s'",
25229 ir_add_error(ira, &instruction->target->base, buf_sprintf("expected integer type, found '%s'",
2433425230 buf_ptr(&target->value->type->name)));
24335 return ira->codegen->invalid_instruction;
25231 return ira->codegen->invalid_inst_gen;
2433625232 }
2433725233
2433825234 if (instr_is_comptime(target)) {
......@@ -24340,28 +25236,28 @@ static IrInstruction *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruct
2434025236 }
2434125237
2434225238 if (dest_type->id == ZigTypeIdComptimeInt) {
24343 ir_add_error(ira, instruction->target, buf_sprintf("attempt to cast runtime value to '%s'",
25239 ir_add_error(ira, &instruction->target->base, buf_sprintf("attempt to cast runtime value to '%s'",
2434425240 buf_ptr(&dest_type->name)));
24345 return ira->codegen->invalid_instruction;
25241 return ira->codegen->invalid_inst_gen;
2434625242 }
2434725243
24348 return ir_analyze_widen_or_shorten(ira, &instruction->base, target, dest_type);
25244 return ir_analyze_widen_or_shorten(ira, &instruction->base.base, target, dest_type);
2434925245}
2435025246
24351static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstructionFloatCast *instruction) {
25247static IrInstGen *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstSrcFloatCast *instruction) {
2435225248 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);
2435325249 if (type_is_invalid(dest_type))
24354 return ira->codegen->invalid_instruction;
25250 return ira->codegen->invalid_inst_gen;
2435525251
2435625252 if (dest_type->id != ZigTypeIdFloat) {
24357 ir_add_error(ira, instruction->dest_type,
25253 ir_add_error(ira, &instruction->dest_type->base,
2435825254 buf_sprintf("expected float type, found '%s'", buf_ptr(&dest_type->name)));
24359 return ira->codegen->invalid_instruction;
25255 return ira->codegen->invalid_inst_gen;
2436025256 }
2436125257
24362 IrInstruction *target = instruction->target->child;
25258 IrInstGen *target = instruction->target->child;
2436325259 if (type_is_invalid(target->value->type))
24364 return ira->codegen->invalid_instruction;
25260 return ira->codegen->invalid_inst_gen;
2436525261
2436625262 if (target->value->type->id == ZigTypeIdComptimeInt ||
2436725263 target->value->type->id == ZigTypeIdComptimeFloat)
......@@ -24373,55 +25269,55 @@ static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstru
2437325269 } else {
2437425270 op = CastOpNumLitToConcrete;
2437525271 }
24376 return ir_resolve_cast(ira, &instruction->base, target, dest_type, op);
25272 return ir_resolve_cast(ira, &instruction->base.base, target, dest_type, op);
2437725273 } else {
24378 return ira->codegen->invalid_instruction;
25274 return ira->codegen->invalid_inst_gen;
2437925275 }
2438025276 }
2438125277
2438225278 if (target->value->type->id != ZigTypeIdFloat) {
24383 ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'",
25279 ir_add_error(ira, &instruction->target->base, buf_sprintf("expected float type, found '%s'",
2438425280 buf_ptr(&target->value->type->name)));
24385 return ira->codegen->invalid_instruction;
25281 return ira->codegen->invalid_inst_gen;
2438625282 }
2438725283
24388 return ir_analyze_widen_or_shorten(ira, &instruction->base, target, dest_type);
25284 return ir_analyze_widen_or_shorten(ira, &instruction->base.base, target, dest_type);
2438925285}
2439025286
24391static IrInstruction *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstructionErrSetCast *instruction) {
25287static IrInstGen *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstSrcErrSetCast *instruction) {
2439225288 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);
2439325289 if (type_is_invalid(dest_type))
24394 return ira->codegen->invalid_instruction;
25290 return ira->codegen->invalid_inst_gen;
2439525291
2439625292 if (dest_type->id != ZigTypeIdErrorSet) {
24397 ir_add_error(ira, instruction->dest_type,
25293 ir_add_error(ira, &instruction->dest_type->base,
2439825294 buf_sprintf("expected error set type, found '%s'", buf_ptr(&dest_type->name)));
24399 return ira->codegen->invalid_instruction;
25295 return ira->codegen->invalid_inst_gen;
2440025296 }
2440125297
24402 IrInstruction *target = instruction->target->child;
25298 IrInstGen *target = instruction->target->child;
2440325299 if (type_is_invalid(target->value->type))
24404 return ira->codegen->invalid_instruction;
25300 return ira->codegen->invalid_inst_gen;
2440525301
2440625302 if (target->value->type->id != ZigTypeIdErrorSet) {
24407 ir_add_error(ira, instruction->target,
25303 ir_add_error(ira, &instruction->target->base,
2440825304 buf_sprintf("expected error set type, found '%s'", buf_ptr(&target->value->type->name)));
24409 return ira->codegen->invalid_instruction;
25305 return ira->codegen->invalid_inst_gen;
2441025306 }
2441125307
24412 return ir_analyze_err_set_cast(ira, &instruction->base, target, dest_type);
25308 return ir_analyze_err_set_cast(ira, &instruction->base.base, target, dest_type);
2441325309}
2441425310
24415static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionFromBytes *instruction) {
25311static IrInstGen *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstSrcFromBytes *instruction) {
2441625312 Error err;
2441725313
2441825314 ZigType *dest_child_type = ir_resolve_type(ira, instruction->dest_child_type->child);
2441925315 if (type_is_invalid(dest_child_type))
24420 return ira->codegen->invalid_instruction;
25316 return ira->codegen->invalid_inst_gen;
2442125317
24422 IrInstruction *target = instruction->target->child;
25318 IrInstGen *target = instruction->target->child;
2442325319 if (type_is_invalid(target->value->type))
24424 return ira->codegen->invalid_instruction;
25320 return ira->codegen->invalid_inst_gen;
2442525321
2442625322 bool src_ptr_const;
2442725323 bool src_ptr_volatile;
......@@ -24431,27 +25327,27 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
2443125327 src_ptr_volatile = target->value->type->data.pointer.is_volatile;
2443225328
2443325329 if ((err = resolve_ptr_align(ira, target->value->type, &src_ptr_align)))
24434 return ira->codegen->invalid_instruction;
25330 return ira->codegen->invalid_inst_gen;
2443525331 } else if (is_slice(target->value->type)) {
2443625332 ZigType *src_ptr_type = target->value->type->data.structure.fields[slice_ptr_index]->type_entry;
2443725333 src_ptr_const = src_ptr_type->data.pointer.is_const;
2443825334 src_ptr_volatile = src_ptr_type->data.pointer.is_volatile;
2443925335
2444025336 if ((err = resolve_ptr_align(ira, src_ptr_type, &src_ptr_align)))
24441 return ira->codegen->invalid_instruction;
25337 return ira->codegen->invalid_inst_gen;
2444225338 } else {
2444325339 src_ptr_const = true;
2444425340 src_ptr_volatile = false;
2444525341
2444625342 if ((err = type_resolve(ira->codegen, target->value->type, ResolveStatusAlignmentKnown)))
24447 return ira->codegen->invalid_instruction;
25343 return ira->codegen->invalid_inst_gen;
2444825344
2444925345 src_ptr_align = get_abi_alignment(ira->codegen, target->value->type);
2445025346 }
2445125347
2445225348 if (src_ptr_align != 0) {
2445325349 if ((err = type_resolve(ira->codegen, dest_child_type, ResolveStatusAlignmentKnown)))
24454 return ira->codegen->invalid_instruction;
25350 return ira->codegen->invalid_inst_gen;
2445525351 }
2445625352
2445725353 ZigType *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_child_type,
......@@ -24464,9 +25360,9 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
2446425360 src_ptr_align, 0, 0, false);
2446525361 ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr);
2446625362
24467 IrInstruction *casted_value = ir_implicit_cast(ira, target, u8_slice);
25363 IrInstGen *casted_value = ir_implicit_cast(ira, target, u8_slice);
2446825364 if (type_is_invalid(casted_value->value->type))
24469 return ira->codegen->invalid_instruction;
25365 return ira->codegen->invalid_inst_gen;
2447025366
2447125367 bool have_known_len = false;
2447225368 uint64_t known_len;
......@@ -24474,7 +25370,7 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
2447425370 if (instr_is_comptime(casted_value)) {
2447525371 ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad);
2447625372 if (!val)
24477 return ira->codegen->invalid_instruction;
25373 return ira->codegen->invalid_inst_gen;
2447825374
2447925375 ZigValue *len_val = val->data.x_struct.fields[slice_len_index];
2448025376 if (value_is_comptime(len_val)) {
......@@ -24483,9 +25379,9 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
2448325379 }
2448425380 }
2448525381
24486 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
25382 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
2448725383 dest_slice_type, nullptr, true, false, true);
24488 if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) {
25384 if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable)) {
2448925385 return result_loc;
2449025386 }
2449125387
......@@ -24502,41 +25398,41 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
2450225398
2450325399 if (have_known_len) {
2450425400 if ((err = type_resolve(ira->codegen, dest_child_type, ResolveStatusSizeKnown)))
24505 return ira->codegen->invalid_instruction;
25401 return ira->codegen->invalid_inst_gen;
2450625402 uint64_t child_type_size = type_size(ira->codegen, dest_child_type);
2450725403 uint64_t remainder = known_len % child_type_size;
2450825404 if (remainder != 0) {
24509 ErrorMsg *msg = ir_add_error(ira, &instruction->base,
25405 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base,
2451025406 buf_sprintf("unable to convert [%" ZIG_PRI_u64 "]u8 to %s: size mismatch",
2451125407 known_len, buf_ptr(&dest_slice_type->name)));
24512 add_error_note(ira->codegen, msg, instruction->dest_child_type->source_node,
25408 add_error_note(ira->codegen, msg, instruction->dest_child_type->base.source_node,
2451325409 buf_sprintf("%s has size %" ZIG_PRI_u64 "; remaining bytes: %" ZIG_PRI_u64,
2451425410 buf_ptr(&dest_child_type->name), child_type_size, remainder));
24515 return ira->codegen->invalid_instruction;
25411 return ira->codegen->invalid_inst_gen;
2451625412 }
2451725413 }
2451825414
24519 return ir_build_resize_slice(ira, &instruction->base, casted_value, dest_slice_type, result_loc);
25415 return ir_build_resize_slice(ira, &instruction->base.base, casted_value, dest_slice_type, result_loc);
2452025416}
2452125417
24522static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstructionToBytes *instruction) {
25418static IrInstGen *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstSrcToBytes *instruction) {
2452325419 Error err;
2452425420
24525 IrInstruction *target = instruction->target->child;
25421 IrInstGen *target = instruction->target->child;
2452625422 if (type_is_invalid(target->value->type))
24527 return ira->codegen->invalid_instruction;
25423 return ira->codegen->invalid_inst_gen;
2452825424
2452925425 if (!is_slice(target->value->type)) {
24530 ir_add_error(ira, instruction->target,
25426 ir_add_error(ira, &instruction->target->base,
2453125427 buf_sprintf("expected slice, found '%s'", buf_ptr(&target->value->type->name)));
24532 return ira->codegen->invalid_instruction;
25428 return ira->codegen->invalid_inst_gen;
2453325429 }
2453425430
2453525431 ZigType *src_ptr_type = target->value->type->data.structure.fields[slice_ptr_index]->type_entry;
2453625432
2453725433 uint32_t alignment;
2453825434 if ((err = resolve_ptr_align(ira, src_ptr_type, &alignment)))
24539 return ira->codegen->invalid_instruction;
25435 return ira->codegen->invalid_inst_gen;
2454025436
2454125437 ZigType *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
2454225438 src_ptr_type->data.pointer.is_const, src_ptr_type->data.pointer.is_volatile, PtrLenUnknown,
......@@ -24546,9 +25442,9 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct
2454625442 if (instr_is_comptime(target)) {
2454725443 ZigValue *target_val = ir_resolve_const(ira, target, UndefBad);
2454825444 if (target_val == nullptr)
24549 return ira->codegen->invalid_instruction;
25445 return ira->codegen->invalid_inst_gen;
2455025446
24551 IrInstruction *result = ir_const(ira, &instruction->base, dest_slice_type);
25447 IrInstGen *result = ir_const(ira, &instruction->base.base, dest_slice_type);
2455225448 result->value->data.x_struct.fields = alloc_const_vals_ptrs(2);
2455325449
2455425450 ZigValue *ptr_val = result->value->data.x_struct.fields[slice_ptr_index];
......@@ -24568,13 +25464,13 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct
2456825464 return result;
2456925465 }
2457025466
24571 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
25467 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
2457225468 dest_slice_type, nullptr, true, false, true);
24573 if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) {
25469 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
2457425470 return result_loc;
2457525471 }
2457625472
24577 return ir_build_resize_slice(ira, &instruction->base, target, dest_slice_type, result_loc);
25473 return ir_build_resize_slice(ira, &instruction->base.base, target, dest_slice_type, result_loc);
2457825474}
2457925475
2458025476static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align) {
......@@ -24591,26 +25487,26 @@ static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_ali
2459125487 return ErrorNone;
2459225488}
2459325489
24594static IrInstruction *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstructionIntToFloat *instruction) {
25490static IrInstGen *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstSrcIntToFloat *instruction) {
2459525491 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);
2459625492 if (type_is_invalid(dest_type))
24597 return ira->codegen->invalid_instruction;
25493 return ira->codegen->invalid_inst_gen;
2459825494
24599 IrInstruction *target = instruction->target->child;
25495 IrInstGen *target = instruction->target->child;
2460025496 if (type_is_invalid(target->value->type))
24601 return ira->codegen->invalid_instruction;
25497 return ira->codegen->invalid_inst_gen;
2460225498
2460325499 if (target->value->type->id != ZigTypeIdInt && target->value->type->id != ZigTypeIdComptimeInt) {
24604 ir_add_error(ira, instruction->target, buf_sprintf("expected int type, found '%s'",
25500 ir_add_error(ira, &instruction->target->base, buf_sprintf("expected int type, found '%s'",
2460525501 buf_ptr(&target->value->type->name)));
24606 return ira->codegen->invalid_instruction;
25502 return ira->codegen->invalid_inst_gen;
2460725503 }
2460825504
24609 return ir_resolve_cast(ira, &instruction->base, target, dest_type, CastOpIntToFloat);
25505 return ir_resolve_cast(ira, &instruction->base.base, target, dest_type, CastOpIntToFloat);
2461025506}
2461125507
24612static IrInstruction *ir_analyze_float_to_int(IrAnalyze *ira, IrInstruction *source_instr,
24613 ZigType *dest_type, IrInstruction *operand, AstNode *operand_source_node)
25508static IrInstGen *ir_analyze_float_to_int(IrAnalyze *ira, IrInst* source_instr,
25509 ZigType *dest_type, IrInstGen *operand, AstNode *operand_source_node)
2461425510{
2461525511 if (operand->value->type->id == ZigTypeIdComptimeInt) {
2461625512 return ir_implicit_cast(ira, operand, dest_type);
......@@ -24619,106 +25515,107 @@ static IrInstruction *ir_analyze_float_to_int(IrAnalyze *ira, IrInstruction *sou
2461925515 if (operand->value->type->id != ZigTypeIdFloat && operand->value->type->id != ZigTypeIdComptimeFloat) {
2462025516 ir_add_error_node(ira, operand_source_node, buf_sprintf("expected float type, found '%s'",
2462125517 buf_ptr(&operand->value->type->name)));
24622 return ira->codegen->invalid_instruction;
25518 return ira->codegen->invalid_inst_gen;
2462325519 }
2462425520
2462525521 return ir_resolve_cast(ira, source_instr, operand, dest_type, CastOpFloatToInt);
2462625522}
2462725523
24628static IrInstruction *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstructionFloatToInt *instruction) {
25524static IrInstGen *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstSrcFloatToInt *instruction) {
2462925525 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);
2463025526 if (type_is_invalid(dest_type))
24631 return ira->codegen->invalid_instruction;
25527 return ira->codegen->invalid_inst_gen;
2463225528
24633 IrInstruction *operand = instruction->target->child;
25529 IrInstGen *operand = instruction->target->child;
2463425530 if (type_is_invalid(operand->value->type))
24635 return ira->codegen->invalid_instruction;
25531 return ira->codegen->invalid_inst_gen;
2463625532
24637 return ir_analyze_float_to_int(ira, &instruction->base, dest_type, operand, instruction->target->source_node);
25533 return ir_analyze_float_to_int(ira, &instruction->base.base, dest_type, operand,
25534 instruction->target->base.source_node);
2463825535}
2463925536
24640static IrInstruction *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstructionErrToInt *instruction) {
24641 IrInstruction *target = instruction->target->child;
25537static IrInstGen *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstSrcErrToInt *instruction) {
25538 IrInstGen *target = instruction->target->child;
2464225539 if (type_is_invalid(target->value->type))
24643 return ira->codegen->invalid_instruction;
25540 return ira->codegen->invalid_inst_gen;
2464425541
24645 IrInstruction *casted_target;
25542 IrInstGen *casted_target;
2464625543 if (target->value->type->id == ZigTypeIdErrorSet) {
2464725544 casted_target = target;
2464825545 } else {
2464925546 casted_target = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_global_error_set);
2465025547 if (type_is_invalid(casted_target->value->type))
24651 return ira->codegen->invalid_instruction;
25548 return ira->codegen->invalid_inst_gen;
2465225549 }
2465325550
24654 return ir_analyze_err_to_int(ira, &instruction->base, casted_target, ira->codegen->err_tag_type);
25551 return ir_analyze_err_to_int(ira, &instruction->base.base, casted_target, ira->codegen->err_tag_type);
2465525552}
2465625553
24657static IrInstruction *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstructionIntToErr *instruction) {
24658 IrInstruction *target = instruction->target->child;
25554static IrInstGen *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstSrcIntToErr *instruction) {
25555 IrInstGen *target = instruction->target->child;
2465925556 if (type_is_invalid(target->value->type))
24660 return ira->codegen->invalid_instruction;
25557 return ira->codegen->invalid_inst_gen;
2466125558
24662 IrInstruction *casted_target = ir_implicit_cast(ira, target, ira->codegen->err_tag_type);
25559 IrInstGen *casted_target = ir_implicit_cast(ira, target, ira->codegen->err_tag_type);
2466325560 if (type_is_invalid(casted_target->value->type))
24664 return ira->codegen->invalid_instruction;
25561 return ira->codegen->invalid_inst_gen;
2466525562
24666 return ir_analyze_int_to_err(ira, &instruction->base, casted_target, ira->codegen->builtin_types.entry_global_error_set);
25563 return ir_analyze_int_to_err(ira, &instruction->base.base, casted_target, ira->codegen->builtin_types.entry_global_error_set);
2466725564}
2466825565
24669static IrInstruction *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstructionBoolToInt *instruction) {
24670 IrInstruction *target = instruction->target->child;
25566static IrInstGen *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstSrcBoolToInt *instruction) {
25567 IrInstGen *target = instruction->target->child;
2467125568 if (type_is_invalid(target->value->type))
24672 return ira->codegen->invalid_instruction;
25569 return ira->codegen->invalid_inst_gen;
2467325570
2467425571 if (target->value->type->id != ZigTypeIdBool) {
24675 ir_add_error(ira, instruction->target, buf_sprintf("expected bool, found '%s'",
25572 ir_add_error(ira, &instruction->target->base, buf_sprintf("expected bool, found '%s'",
2467625573 buf_ptr(&target->value->type->name)));
24677 return ira->codegen->invalid_instruction;
25574 return ira->codegen->invalid_inst_gen;
2467825575 }
2467925576
2468025577 if (instr_is_comptime(target)) {
2468125578 bool is_true;
2468225579 if (!ir_resolve_bool(ira, target, &is_true))
24683 return ira->codegen->invalid_instruction;
25580 return ira->codegen->invalid_inst_gen;
2468425581
24685 return ir_const_unsigned(ira, &instruction->base, is_true ? 1 : 0);
25582 return ir_const_unsigned(ira, &instruction->base.base, is_true ? 1 : 0);
2468625583 }
2468725584
2468825585 ZigType *u1_type = get_int_type(ira->codegen, false, 1);
24689 return ir_resolve_cast(ira, &instruction->base, target, u1_type, CastOpBoolToInt);
25586 return ir_resolve_cast(ira, &instruction->base.base, target, u1_type, CastOpBoolToInt);
2469025587}
2469125588
24692static IrInstruction *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstructionIntType *instruction) {
24693 IrInstruction *is_signed_value = instruction->is_signed->child;
25589static IrInstGen *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstSrcIntType *instruction) {
25590 IrInstGen *is_signed_value = instruction->is_signed->child;
2469425591 bool is_signed;
2469525592 if (!ir_resolve_bool(ira, is_signed_value, &is_signed))
24696 return ira->codegen->invalid_instruction;
25593 return ira->codegen->invalid_inst_gen;
2469725594
24698 IrInstruction *bit_count_value = instruction->bit_count->child;
25595 IrInstGen *bit_count_value = instruction->bit_count->child;
2469925596 uint64_t bit_count;
2470025597 if (!ir_resolve_unsigned(ira, bit_count_value, ira->codegen->builtin_types.entry_u16, &bit_count))
24701 return ira->codegen->invalid_instruction;
25598 return ira->codegen->invalid_inst_gen;
2470225599
24703 return ir_const_type(ira, &instruction->base, get_int_type(ira->codegen, is_signed, (uint32_t)bit_count));
25600 return ir_const_type(ira, &instruction->base.base, get_int_type(ira->codegen, is_signed, (uint32_t)bit_count));
2470425601}
2470525602
24706static IrInstruction *ir_analyze_instruction_vector_type(IrAnalyze *ira, IrInstructionVectorType *instruction) {
25603static IrInstGen *ir_analyze_instruction_vector_type(IrAnalyze *ira, IrInstSrcVectorType *instruction) {
2470725604 uint64_t len;
2470825605 if (!ir_resolve_unsigned(ira, instruction->len->child, ira->codegen->builtin_types.entry_u32, &len))
24709 return ira->codegen->invalid_instruction;
25606 return ira->codegen->invalid_inst_gen;
2471025607
2471125608 ZigType *elem_type = ir_resolve_vector_elem_type(ira, instruction->elem_type->child);
2471225609 if (type_is_invalid(elem_type))
24713 return ira->codegen->invalid_instruction;
25610 return ira->codegen->invalid_inst_gen;
2471425611
2471525612 ZigType *vector_type = get_vector_type(ira->codegen, len, elem_type);
2471625613
24717 return ir_const_type(ira, &instruction->base, vector_type);
25614 return ir_const_type(ira, &instruction->base.base, vector_type);
2471825615}
2471925616
24720static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *source_instr,
24721 ZigType *scalar_type, IrInstruction *a, IrInstruction *b, IrInstruction *mask)
25617static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr,
25618 ZigType *scalar_type, IrInstGen *a, IrInstGen *b, IrInstGen *mask)
2472225619{
2472325620 ir_assert(source_instr && scalar_type && a && b && mask, source_instr);
2472425621 ir_assert(is_valid_vector_elem_type(scalar_type), source_instr);
......@@ -24729,15 +25626,15 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
2472925626 } else if (mask->value->type->id == ZigTypeIdArray) {
2473025627 len_mask = mask->value->type->data.array.len;
2473125628 } else {
24732 ir_add_error(ira, mask,
25629 ir_add_error(ira, &mask->base,
2473325630 buf_sprintf("expected vector or array, found '%s'",
2473425631 buf_ptr(&mask->value->type->name)));
24735 return ira->codegen->invalid_instruction;
25632 return ira->codegen->invalid_inst_gen;
2473625633 }
2473725634 mask = ir_implicit_cast(ira, mask, get_vector_type(ira->codegen, len_mask,
2473825635 ira->codegen->builtin_types.entry_i32));
2473925636 if (type_is_invalid(mask->value->type))
24740 return ira->codegen->invalid_instruction;
25637 return ira->codegen->invalid_inst_gen;
2474125638
2474225639 uint32_t len_a;
2474325640 if (a->value->type->id == ZigTypeIdVector) {
......@@ -24747,11 +25644,11 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
2474725644 } else if (a->value->type->id == ZigTypeIdUndefined) {
2474825645 len_a = UINT32_MAX;
2474925646 } else {
24750 ir_add_error(ira, a,
25647 ir_add_error(ira, &a->base,
2475125648 buf_sprintf("expected vector or array with element type '%s', found '%s'",
2475225649 buf_ptr(&scalar_type->name),
2475325650 buf_ptr(&a->value->type->name)));
24754 return ira->codegen->invalid_instruction;
25651 return ira->codegen->invalid_inst_gen;
2475525652 }
2475625653
2475725654 uint32_t len_b;
......@@ -24762,38 +25659,38 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
2476225659 } else if (b->value->type->id == ZigTypeIdUndefined) {
2476325660 len_b = UINT32_MAX;
2476425661 } else {
24765 ir_add_error(ira, b,
25662 ir_add_error(ira, &b->base,
2476625663 buf_sprintf("expected vector or array with element type '%s', found '%s'",
2476725664 buf_ptr(&scalar_type->name),
2476825665 buf_ptr(&b->value->type->name)));
24769 return ira->codegen->invalid_instruction;
25666 return ira->codegen->invalid_inst_gen;
2477025667 }
2477125668
2477225669 if (len_a == UINT32_MAX && len_b == UINT32_MAX) {
24773 return ir_const_undef(ira, a, get_vector_type(ira->codegen, len_mask, scalar_type));
25670 return ir_const_undef(ira, &a->base, get_vector_type(ira->codegen, len_mask, scalar_type));
2477425671 }
2477525672
2477625673 if (len_a == UINT32_MAX) {
2477725674 len_a = len_b;
24778 a = ir_const_undef(ira, a, get_vector_type(ira->codegen, len_a, scalar_type));
25675 a = ir_const_undef(ira, &a->base, get_vector_type(ira->codegen, len_a, scalar_type));
2477925676 } else {
2478025677 a = ir_implicit_cast(ira, a, get_vector_type(ira->codegen, len_a, scalar_type));
2478125678 if (type_is_invalid(a->value->type))
24782 return ira->codegen->invalid_instruction;
25679 return ira->codegen->invalid_inst_gen;
2478325680 }
2478425681
2478525682 if (len_b == UINT32_MAX) {
2478625683 len_b = len_a;
24787 b = ir_const_undef(ira, b, get_vector_type(ira->codegen, len_b, scalar_type));
25684 b = ir_const_undef(ira, &b->base, get_vector_type(ira->codegen, len_b, scalar_type));
2478825685 } else {
2478925686 b = ir_implicit_cast(ira, b, get_vector_type(ira->codegen, len_b, scalar_type));
2479025687 if (type_is_invalid(b->value->type))
24791 return ira->codegen->invalid_instruction;
25688 return ira->codegen->invalid_inst_gen;
2479225689 }
2479325690
2479425691 ZigValue *mask_val = ir_resolve_const(ira, mask, UndefOk);
2479525692 if (mask_val == nullptr)
24796 return ira->codegen->invalid_instruction;
25693 return ira->codegen->invalid_inst_gen;
2479725694
2479825695 expand_undef_array(ira->codegen, mask_val);
2479925696
......@@ -24803,7 +25700,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
2480325700 continue;
2480425701 int32_t v_i32 = bigint_as_signed(&mask_elem_val->data.x_bigint);
2480525702 uint32_t v;
24806 IrInstruction *chosen_operand;
25703 IrInstGen *chosen_operand;
2480725704 if (v_i32 >= 0) {
2480825705 v = (uint32_t)v_i32;
2480925706 chosen_operand = a;
......@@ -24812,16 +25709,16 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
2481225709 chosen_operand = b;
2481325710 }
2481425711 if (v >= chosen_operand->value->type->data.vector.len) {
24815 ErrorMsg *msg = ir_add_error(ira, mask,
25712 ErrorMsg *msg = ir_add_error(ira, &mask->base,
2481625713 buf_sprintf("mask index '%u' has out-of-bounds selection", i));
24817 add_error_note(ira->codegen, msg, chosen_operand->source_node,
25714 add_error_note(ira->codegen, msg, chosen_operand->base.source_node,
2481825715 buf_sprintf("selected index '%u' out of bounds of %s", v,
2481925716 buf_ptr(&chosen_operand->value->type->name)));
2482025717 if (chosen_operand == a && v < len_a + len_b) {
24821 add_error_note(ira->codegen, msg, b->source_node,
25718 add_error_note(ira->codegen, msg, b->base.source_node,
2482225719 buf_create_from_str("selections from the second vector are specified with negative numbers"));
2482325720 }
24824 return ira->codegen->invalid_instruction;
25721 return ira->codegen->invalid_inst_gen;
2482525722 }
2482625723 }
2482725724
......@@ -24829,16 +25726,16 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
2482925726 if (instr_is_comptime(a) && instr_is_comptime(b)) {
2483025727 ZigValue *a_val = ir_resolve_const(ira, a, UndefOk);
2483125728 if (a_val == nullptr)
24832 return ira->codegen->invalid_instruction;
25729 return ira->codegen->invalid_inst_gen;
2483325730
2483425731 ZigValue *b_val = ir_resolve_const(ira, b, UndefOk);
2483525732 if (b_val == nullptr)
24836 return ira->codegen->invalid_instruction;
25733 return ira->codegen->invalid_inst_gen;
2483725734
2483825735 expand_undef_array(ira->codegen, a_val);
2483925736 expand_undef_array(ira->codegen, b_val);
2484025737
24841 IrInstruction *result = ir_const(ira, source_instr, result_type);
25738 IrInstGen *result = ir_const(ira, source_instr, result_type);
2484225739 result->value->data.x_array.data.s_none.elements = create_const_vals(len_mask);
2484325740 for (uint32_t i = 0; i < mask_val->type->data.vector.len; i += 1) {
2484425741 ZigValue *mask_elem_val = &mask_val->data.x_array.data.s_none.elements[i];
......@@ -24870,7 +25767,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
2487025767 uint32_t len_min = min(len_a, len_b);
2487125768 uint32_t len_max = max(len_a, len_b);
2487225769
24873 IrInstruction *expand_mask = ir_const(ira, mask,
25770 IrInstGen *expand_mask = ir_const(ira, &mask->base,
2487425771 get_vector_type(ira->codegen, len_max, ira->codegen->builtin_types.entry_i32));
2487525772 expand_mask->value->data.x_array.data.s_none.elements = create_const_vals(len_max);
2487625773 uint32_t i = 0;
......@@ -24879,7 +25776,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
2487925776 for (; i < len_max; i += 1)
2488025777 bigint_init_signed(&expand_mask->value->data.x_array.data.s_none.elements[i].data.x_bigint, -1);
2488125778
24882 IrInstruction *undef = ir_const_undef(ira, source_instr,
25779 IrInstGen *undef = ir_const_undef(ira, source_instr,
2488325780 get_vector_type(ira->codegen, len_min, scalar_type));
2488425781
2488525782 if (len_b < len_a) {
......@@ -24889,62 +25786,59 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
2488925786 }
2489025787 }
2489125788
24892 IrInstruction *result = ir_build_shuffle_vector(&ira->new_irb,
24893 source_instr->scope, source_instr->source_node,
24894 nullptr, a, b, mask);
24895 result->value->type = result_type;
24896 return result;
25789 return ir_build_shuffle_vector_gen(ira, source_instr->scope, source_instr->source_node,
25790 result_type, a, b, mask);
2489725791}
2489825792
24899static IrInstruction *ir_analyze_instruction_shuffle_vector(IrAnalyze *ira, IrInstructionShuffleVector *instruction) {
24900 ZigType *scalar_type = ir_resolve_vector_elem_type(ira, instruction->scalar_type);
25793static IrInstGen *ir_analyze_instruction_shuffle_vector(IrAnalyze *ira, IrInstSrcShuffleVector *instruction) {
25794 ZigType *scalar_type = ir_resolve_vector_elem_type(ira, instruction->scalar_type->child);
2490125795 if (type_is_invalid(scalar_type))
24902 return ira->codegen->invalid_instruction;
25796 return ira->codegen->invalid_inst_gen;
2490325797
24904 IrInstruction *a = instruction->a->child;
25798 IrInstGen *a = instruction->a->child;
2490525799 if (type_is_invalid(a->value->type))
24906 return ira->codegen->invalid_instruction;
25800 return ira->codegen->invalid_inst_gen;
2490725801
24908 IrInstruction *b = instruction->b->child;
25802 IrInstGen *b = instruction->b->child;
2490925803 if (type_is_invalid(b->value->type))
24910 return ira->codegen->invalid_instruction;
25804 return ira->codegen->invalid_inst_gen;
2491125805
24912 IrInstruction *mask = instruction->mask->child;
25806 IrInstGen *mask = instruction->mask->child;
2491325807 if (type_is_invalid(mask->value->type))
24914 return ira->codegen->invalid_instruction;
25808 return ira->codegen->invalid_inst_gen;
2491525809
24916 return ir_analyze_shuffle_vector(ira, &instruction->base, scalar_type, a, b, mask);
25810 return ir_analyze_shuffle_vector(ira, &instruction->base.base, scalar_type, a, b, mask);
2491725811}
2491825812
24919static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstructionSplatSrc *instruction) {
25813static IrInstGen *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstSrcSplat *instruction) {
2492025814 Error err;
2492125815
24922 IrInstruction *len = instruction->len->child;
25816 IrInstGen *len = instruction->len->child;
2492325817 if (type_is_invalid(len->value->type))
24924 return ira->codegen->invalid_instruction;
25818 return ira->codegen->invalid_inst_gen;
2492525819
24926 IrInstruction *scalar = instruction->scalar->child;
25820 IrInstGen *scalar = instruction->scalar->child;
2492725821 if (type_is_invalid(scalar->value->type))
24928 return ira->codegen->invalid_instruction;
25822 return ira->codegen->invalid_inst_gen;
2492925823
2493025824 uint64_t len_u64;
2493125825 if (!ir_resolve_unsigned(ira, len, ira->codegen->builtin_types.entry_u32, &len_u64))
24932 return ira->codegen->invalid_instruction;
25826 return ira->codegen->invalid_inst_gen;
2493325827 uint32_t len_int = len_u64;
2493425828
24935 if ((err = ir_validate_vector_elem_type(ira, scalar, scalar->value->type)))
24936 return ira->codegen->invalid_instruction;
25829 if ((err = ir_validate_vector_elem_type(ira, scalar->base.source_node, scalar->value->type)))
25830 return ira->codegen->invalid_inst_gen;
2493725831
2493825832 ZigType *return_type = get_vector_type(ira->codegen, len_int, scalar->value->type);
2493925833
2494025834 if (instr_is_comptime(scalar)) {
2494125835 ZigValue *scalar_val = ir_resolve_const(ira, scalar, UndefOk);
2494225836 if (scalar_val == nullptr)
24943 return ira->codegen->invalid_instruction;
25837 return ira->codegen->invalid_inst_gen;
2494425838 if (scalar_val->special == ConstValSpecialUndef)
24945 return ir_const_undef(ira, &instruction->base, return_type);
25839 return ir_const_undef(ira, &instruction->base.base, return_type);
2494625840
24947 IrInstruction *result = ir_const(ira, &instruction->base, return_type);
25841 IrInstGen *result = ir_const(ira, &instruction->base.base, return_type);
2494825842 result->value->data.x_array.data.s_none.elements = create_const_vals(len_int);
2494925843 for (uint32_t i = 0; i < len_int; i += 1) {
2495025844 copy_const_val(&result->value->data.x_array.data.s_none.elements[i], scalar_val);
......@@ -24952,48 +25846,45 @@ static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstruction
2495225846 return result;
2495325847 }
2495425848
24955 return ir_build_splat_gen(ira, &instruction->base, return_type, scalar);
25849 return ir_build_splat_gen(ira, &instruction->base.base, return_type, scalar);
2495625850}
2495725851
24958static IrInstruction *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstructionBoolNot *instruction) {
24959 IrInstruction *value = instruction->value->child;
25852static IrInstGen *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstSrcBoolNot *instruction) {
25853 IrInstGen *value = instruction->value->child;
2496025854 if (type_is_invalid(value->value->type))
24961 return ira->codegen->invalid_instruction;
25855 return ira->codegen->invalid_inst_gen;
2496225856
2496325857 ZigType *bool_type = ira->codegen->builtin_types.entry_bool;
2496425858
24965 IrInstruction *casted_value = ir_implicit_cast(ira, value, bool_type);
25859 IrInstGen *casted_value = ir_implicit_cast(ira, value, bool_type);
2496625860 if (type_is_invalid(casted_value->value->type))
24967 return ira->codegen->invalid_instruction;
25861 return ira->codegen->invalid_inst_gen;
2496825862
2496925863 if (instr_is_comptime(casted_value)) {
2497025864 ZigValue *value = ir_resolve_const(ira, casted_value, UndefBad);
2497125865 if (value == nullptr)
24972 return ira->codegen->invalid_instruction;
25866 return ira->codegen->invalid_inst_gen;
2497325867
24974 return ir_const_bool(ira, &instruction->base, !value->data.x_bool);
25868 return ir_const_bool(ira, &instruction->base.base, !value->data.x_bool);
2497525869 }
2497625870
24977 IrInstruction *result = ir_build_bool_not(&ira->new_irb, instruction->base.scope,
24978 instruction->base.source_node, casted_value);
24979 result->value->type = bool_type;
24980 return result;
25871 return ir_build_bool_not_gen(ira, &instruction->base.base, casted_value);
2498125872}
2498225873
24983static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemset *instruction) {
25874static IrInstGen *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstSrcMemset *instruction) {
2498425875 Error err;
2498525876
24986 IrInstruction *dest_ptr = instruction->dest_ptr->child;
25877 IrInstGen *dest_ptr = instruction->dest_ptr->child;
2498725878 if (type_is_invalid(dest_ptr->value->type))
24988 return ira->codegen->invalid_instruction;
25879 return ira->codegen->invalid_inst_gen;
2498925880
24990 IrInstruction *byte_value = instruction->byte->child;
25881 IrInstGen *byte_value = instruction->byte->child;
2499125882 if (type_is_invalid(byte_value->value->type))
24992 return ira->codegen->invalid_instruction;
25883 return ira->codegen->invalid_inst_gen;
2499325884
24994 IrInstruction *count_value = instruction->count->child;
25885 IrInstGen *count_value = instruction->count->child;
2499525886 if (type_is_invalid(count_value->value->type))
24996 return ira->codegen->invalid_instruction;
25887 return ira->codegen->invalid_inst_gen;
2499725888
2499825889 ZigType *dest_uncasted_type = dest_ptr->value->type;
2499925890 bool dest_is_volatile = (dest_uncasted_type->id == ZigTypeIdPointer) &&
......@@ -25004,24 +25895,24 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio
2500425895 uint32_t dest_align;
2500525896 if (dest_uncasted_type->id == ZigTypeIdPointer) {
2500625897 if ((err = resolve_ptr_align(ira, dest_uncasted_type, &dest_align)))
25007 return ira->codegen->invalid_instruction;
25898 return ira->codegen->invalid_inst_gen;
2500825899 } else {
2500925900 dest_align = get_abi_alignment(ira->codegen, u8);
2501025901 }
2501125902 ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile,
2501225903 PtrLenUnknown, dest_align, 0, 0, false);
2501325904
25014 IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr);
25905 IrInstGen *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr);
2501525906 if (type_is_invalid(casted_dest_ptr->value->type))
25016 return ira->codegen->invalid_instruction;
25907 return ira->codegen->invalid_inst_gen;
2501725908
25018 IrInstruction *casted_byte = ir_implicit_cast(ira, byte_value, u8);
25909 IrInstGen *casted_byte = ir_implicit_cast(ira, byte_value, u8);
2501925910 if (type_is_invalid(casted_byte->value->type))
25020 return ira->codegen->invalid_instruction;
25911 return ira->codegen->invalid_inst_gen;
2502125912
25022 IrInstruction *casted_count = ir_implicit_cast(ira, count_value, usize);
25913 IrInstGen *casted_count = ir_implicit_cast(ira, count_value, usize);
2502325914 if (type_is_invalid(casted_count->value->type))
25024 return ira->codegen->invalid_instruction;
25915 return ira->codegen->invalid_inst_gen;
2502525916
2502625917 // TODO test this at comptime with u8 and non-u8 types
2502725918 if (instr_is_comptime(casted_dest_ptr) &&
......@@ -25030,15 +25921,15 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio
2503025921 {
2503125922 ZigValue *dest_ptr_val = ir_resolve_const(ira, casted_dest_ptr, UndefBad);
2503225923 if (dest_ptr_val == nullptr)
25033 return ira->codegen->invalid_instruction;
25924 return ira->codegen->invalid_inst_gen;
2503425925
2503525926 ZigValue *byte_val = ir_resolve_const(ira, casted_byte, UndefOk);
2503625927 if (byte_val == nullptr)
25037 return ira->codegen->invalid_instruction;
25928 return ira->codegen->invalid_inst_gen;
2503825929
2503925930 ZigValue *count_val = ir_resolve_const(ira, casted_count, UndefBad);
2504025931 if (count_val == nullptr)
25041 return ira->codegen->invalid_instruction;
25932 return ira->codegen->invalid_inst_gen;
2504225933
2504325934 if (casted_dest_ptr->value->data.x_ptr.special != ConstPtrSpecialHardCodedAddr &&
2504425935 casted_dest_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar)
......@@ -25083,38 +25974,35 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio
2508325974 size_t count = bigint_as_usize(&count_val->data.x_bigint);
2508425975 size_t end = start + count;
2508525976 if (end > bound_end) {
25086 ir_add_error(ira, count_value, buf_sprintf("out of bounds pointer access"));
25087 return ira->codegen->invalid_instruction;
25977 ir_add_error(ira, &count_value->base, buf_sprintf("out of bounds pointer access"));
25978 return ira->codegen->invalid_inst_gen;
2508825979 }
2508925980
2509025981 for (size_t i = start; i < end; i += 1) {
2509125982 copy_const_val(&dest_elements[i], byte_val);
2509225983 }
2509325984
25094 return ir_const_void(ira, &instruction->base);
25985 return ir_const_void(ira, &instruction->base.base);
2509525986 }
2509625987 }
2509725988
25098 IrInstruction *result = ir_build_memset(&ira->new_irb, instruction->base.scope, instruction->base.source_node,
25099 casted_dest_ptr, casted_byte, casted_count);
25100 result->value->type = ira->codegen->builtin_types.entry_void;
25101 return result;
25989 return ir_build_memset_gen(ira, &instruction->base.base, casted_dest_ptr, casted_byte, casted_count);
2510225990}
2510325991
25104static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcpy *instruction) {
25992static IrInstGen *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstSrcMemcpy *instruction) {
2510525993 Error err;
2510625994
25107 IrInstruction *dest_ptr = instruction->dest_ptr->child;
25995 IrInstGen *dest_ptr = instruction->dest_ptr->child;
2510825996 if (type_is_invalid(dest_ptr->value->type))
25109 return ira->codegen->invalid_instruction;
25997 return ira->codegen->invalid_inst_gen;
2511025998
25111 IrInstruction *src_ptr = instruction->src_ptr->child;
25999 IrInstGen *src_ptr = instruction->src_ptr->child;
2511226000 if (type_is_invalid(src_ptr->value->type))
25113 return ira->codegen->invalid_instruction;
26001 return ira->codegen->invalid_inst_gen;
2511426002
25115 IrInstruction *count_value = instruction->count->child;
26003 IrInstGen *count_value = instruction->count->child;
2511626004 if (type_is_invalid(count_value->value->type))
25117 return ira->codegen->invalid_instruction;
26005 return ira->codegen->invalid_inst_gen;
2511826006
2511926007 ZigType *u8 = ira->codegen->builtin_types.entry_u8;
2512026008 ZigType *dest_uncasted_type = dest_ptr->value->type;
......@@ -25127,7 +26015,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
2512726015 uint32_t dest_align;
2512826016 if (dest_uncasted_type->id == ZigTypeIdPointer) {
2512926017 if ((err = resolve_ptr_align(ira, dest_uncasted_type, &dest_align)))
25130 return ira->codegen->invalid_instruction;
26018 return ira->codegen->invalid_inst_gen;
2513126019 } else {
2513226020 dest_align = get_abi_alignment(ira->codegen, u8);
2513326021 }
......@@ -25135,7 +26023,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
2513526023 uint32_t src_align;
2513626024 if (src_uncasted_type->id == ZigTypeIdPointer) {
2513726025 if ((err = resolve_ptr_align(ira, src_uncasted_type, &src_align)))
25138 return ira->codegen->invalid_instruction;
26026 return ira->codegen->invalid_inst_gen;
2513926027 } else {
2514026028 src_align = get_abi_alignment(ira->codegen, u8);
2514126029 }
......@@ -25146,17 +26034,17 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
2514626034 ZigType *u8_ptr_const = get_pointer_to_type_extra(ira->codegen, u8, true, src_is_volatile,
2514726035 PtrLenUnknown, src_align, 0, 0, false);
2514826036
25149 IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr_mut);
26037 IrInstGen *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr_mut);
2515026038 if (type_is_invalid(casted_dest_ptr->value->type))
25151 return ira->codegen->invalid_instruction;
26039 return ira->codegen->invalid_inst_gen;
2515226040
25153 IrInstruction *casted_src_ptr = ir_implicit_cast(ira, src_ptr, u8_ptr_const);
26041 IrInstGen *casted_src_ptr = ir_implicit_cast(ira, src_ptr, u8_ptr_const);
2515426042 if (type_is_invalid(casted_src_ptr->value->type))
25155 return ira->codegen->invalid_instruction;
26043 return ira->codegen->invalid_inst_gen;
2515626044
25157 IrInstruction *casted_count = ir_implicit_cast(ira, count_value, usize);
26045 IrInstGen *casted_count = ir_implicit_cast(ira, count_value, usize);
2515826046 if (type_is_invalid(casted_count->value->type))
25159 return ira->codegen->invalid_instruction;
26047 return ira->codegen->invalid_inst_gen;
2516026048
2516126049 // TODO test this at comptime with u8 and non-u8 types
2516226050 // TODO test with dest ptr being a global runtime variable
......@@ -25166,15 +26054,15 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
2516626054 {
2516726055 ZigValue *dest_ptr_val = ir_resolve_const(ira, casted_dest_ptr, UndefBad);
2516826056 if (dest_ptr_val == nullptr)
25169 return ira->codegen->invalid_instruction;
26057 return ira->codegen->invalid_inst_gen;
2517026058
2517126059 ZigValue *src_ptr_val = ir_resolve_const(ira, casted_src_ptr, UndefBad);
2517226060 if (src_ptr_val == nullptr)
25173 return ira->codegen->invalid_instruction;
26061 return ira->codegen->invalid_inst_gen;
2517426062
2517526063 ZigValue *count_val = ir_resolve_const(ira, casted_count, UndefBad);
2517626064 if (count_val == nullptr)
25177 return ira->codegen->invalid_instruction;
26065 return ira->codegen->invalid_inst_gen;
2517826066
2517926067 if (dest_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
2518026068 size_t count = bigint_as_usize(&count_val->data.x_bigint);
......@@ -25217,8 +26105,8 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
2521726105 }
2521826106
2521926107 if (dest_start + count > dest_end) {
25220 ir_add_error(ira, &instruction->base, buf_sprintf("out of bounds pointer access"));
25221 return ira->codegen->invalid_instruction;
26108 ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds pointer access"));
26109 return ira->codegen->invalid_inst_gen;
2522226110 }
2522326111
2522426112 ZigValue *src_elements;
......@@ -25260,8 +26148,8 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
2526026148 }
2526126149
2526226150 if (src_start + count > src_end) {
25263 ir_add_error(ira, &instruction->base, buf_sprintf("out of bounds pointer access"));
25264 return ira->codegen->invalid_instruction;
26151 ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds pointer access"));
26152 return ira->codegen->invalid_inst_gen;
2526526153 }
2526626154
2526726155 // TODO check for noalias violations - this should be generalized to work for any function
......@@ -25270,42 +26158,39 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
2527026158 copy_const_val(&dest_elements[dest_start + i], &src_elements[src_start + i]);
2527126159 }
2527226160
25273 return ir_const_void(ira, &instruction->base);
26161 return ir_const_void(ira, &instruction->base.base);
2527426162 }
2527526163 }
2527626164
25277 IrInstruction *result = ir_build_memcpy(&ira->new_irb, instruction->base.scope, instruction->base.source_node,
25278 casted_dest_ptr, casted_src_ptr, casted_count);
25279 result->value->type = ira->codegen->builtin_types.entry_void;
25280 return result;
26165 return ir_build_memcpy_gen(ira, &instruction->base.base, casted_dest_ptr, casted_src_ptr, casted_count);
2528126166}
2528226167
25283static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSliceSrc *instruction) {
25284 IrInstruction *ptr_ptr = instruction->ptr->child;
26168static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *instruction) {
26169 IrInstGen *ptr_ptr = instruction->ptr->child;
2528526170 if (type_is_invalid(ptr_ptr->value->type))
25286 return ira->codegen->invalid_instruction;
26171 return ira->codegen->invalid_inst_gen;
2528726172
2528826173 ZigType *ptr_ptr_type = ptr_ptr->value->type;
2528926174 assert(ptr_ptr_type->id == ZigTypeIdPointer);
2529026175 ZigType *array_type = ptr_ptr_type->data.pointer.child_type;
2529126176
25292 IrInstruction *start = instruction->start->child;
26177 IrInstGen *start = instruction->start->child;
2529326178 if (type_is_invalid(start->value->type))
25294 return ira->codegen->invalid_instruction;
26179 return ira->codegen->invalid_inst_gen;
2529526180
2529626181 ZigType *usize = ira->codegen->builtin_types.entry_usize;
25297 IrInstruction *casted_start = ir_implicit_cast(ira, start, usize);
26182 IrInstGen *casted_start = ir_implicit_cast(ira, start, usize);
2529826183 if (type_is_invalid(casted_start->value->type))
25299 return ira->codegen->invalid_instruction;
26184 return ira->codegen->invalid_inst_gen;
2530026185
25301 IrInstruction *end;
26186 IrInstGen *end;
2530226187 if (instruction->end) {
2530326188 end = instruction->end->child;
2530426189 if (type_is_invalid(end->value->type))
25305 return ira->codegen->invalid_instruction;
26190 return ira->codegen->invalid_inst_gen;
2530626191 end = ir_implicit_cast(ira, end, usize);
2530726192 if (type_is_invalid(end->value->type))
25308 return ira->codegen->invalid_instruction;
26193 return ira->codegen->invalid_inst_gen;
2530926194 } else {
2531026195 end = nullptr;
2531126196 }
......@@ -25333,8 +26218,8 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2533326218 PtrLenUnknown,
2533426219 array_type->data.pointer.explicit_alignment, 0, 0, false);
2533526220 } else {
25336 ir_add_error(ira, &instruction->base, buf_sprintf("slice of single-item pointer"));
25337 return ira->codegen->invalid_instruction;
26221 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of single-item pointer"));
26222 return ira->codegen->invalid_inst_gen;
2533826223 }
2533926224 } else {
2534026225 elem_type = array_type->data.pointer.child_type;
......@@ -25344,8 +26229,8 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2534426229 ZigType *maybe_sentineled_slice_ptr_type = array_type;
2534526230 non_sentinel_slice_ptr_type = adjust_ptr_sentinel(ira->codegen, maybe_sentineled_slice_ptr_type, nullptr);
2534626231 if (!end) {
25347 ir_add_error(ira, &instruction->base, buf_sprintf("slice of pointer must include end value"));
25348 return ira->codegen->invalid_instruction;
26232 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of pointer must include end value"));
26233 return ira->codegen->invalid_inst_gen;
2534926234 }
2535026235 }
2535126236 } else if (is_slice(array_type)) {
......@@ -25353,23 +26238,23 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2535326238 non_sentinel_slice_ptr_type = adjust_ptr_sentinel(ira->codegen, maybe_sentineled_slice_ptr_type, nullptr);
2535426239 elem_type = non_sentinel_slice_ptr_type->data.pointer.child_type;
2535526240 } else {
25356 ir_add_error(ira, &instruction->base,
26241 ir_add_error(ira, &instruction->base.base,
2535726242 buf_sprintf("slice of non-array type '%s'", buf_ptr(&array_type->name)));
25358 return ira->codegen->invalid_instruction;
26243 return ira->codegen->invalid_inst_gen;
2535926244 }
2536026245
2536126246 ZigType *return_type;
2536226247 ZigValue *sentinel_val = nullptr;
2536326248 if (instruction->sentinel) {
25364 IrInstruction *uncasted_sentinel = instruction->sentinel->child;
26249 IrInstGen *uncasted_sentinel = instruction->sentinel->child;
2536526250 if (type_is_invalid(uncasted_sentinel->value->type))
25366 return ira->codegen->invalid_instruction;
25367 IrInstruction *sentinel = ir_implicit_cast(ira, uncasted_sentinel, elem_type);
26251 return ira->codegen->invalid_inst_gen;
26252 IrInstGen *sentinel = ir_implicit_cast(ira, uncasted_sentinel, elem_type);
2536826253 if (type_is_invalid(sentinel->value->type))
25369 return ira->codegen->invalid_instruction;
26254 return ira->codegen->invalid_inst_gen;
2537026255 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);
2537126256 if (sentinel_val == nullptr)
25372 return ira->codegen->invalid_instruction;
26257 return ira->codegen->invalid_inst_gen;
2537326258 ZigType *slice_ptr_type = adjust_ptr_sentinel(ira->codegen, non_sentinel_slice_ptr_type, sentinel_val);
2537426259 return_type = get_slice_type(ira->codegen, slice_ptr_type);
2537526260 } else {
......@@ -25391,9 +26276,9 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2539126276 if (array_type->id == ZigTypeIdPointer) {
2539226277 ZigType *child_array_type = array_type->data.pointer.child_type;
2539326278 assert(child_array_type->id == ZigTypeIdArray);
25394 parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node);
26279 parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node);
2539526280 if (parent_ptr == nullptr)
25396 return ira->codegen->invalid_instruction;
26281 return ira->codegen->invalid_inst_gen;
2539726282
2539826283
2539926284 if (parent_ptr->special == ConstValSpecialUndef) {
......@@ -25402,26 +26287,26 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2540226287 rel_end = SIZE_MAX;
2540326288 ptr_is_undef = true;
2540426289 } else {
25405 array_val = const_ptr_pointee(ira, ira->codegen, parent_ptr, instruction->base.source_node);
26290 array_val = const_ptr_pointee(ira, ira->codegen, parent_ptr, instruction->base.base.source_node);
2540626291 if (array_val == nullptr)
25407 return ira->codegen->invalid_instruction;
26292 return ira->codegen->invalid_inst_gen;
2540826293
2540926294 rel_end = child_array_type->data.array.len;
2541026295 abs_offset = 0;
2541126296 }
2541226297 } else {
25413 array_val = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node);
26298 array_val = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node);
2541426299 if (array_val == nullptr)
25415 return ira->codegen->invalid_instruction;
26300 return ira->codegen->invalid_inst_gen;
2541626301 rel_end = array_type->data.array.len;
2541726302 parent_ptr = nullptr;
2541826303 abs_offset = 0;
2541926304 }
2542026305 } else if (array_type->id == ZigTypeIdPointer) {
2542126306 assert(array_type->data.pointer.ptr_len == PtrLenUnknown);
25422 parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node);
26307 parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node);
2542326308 if (parent_ptr == nullptr)
25424 return ira->codegen->invalid_instruction;
26309 return ira->codegen->invalid_inst_gen;
2542526310
2542626311 if (parent_ptr->special == ConstValSpecialUndef) {
2542726312 array_val = nullptr;
......@@ -25467,19 +26352,19 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2546726352 zig_panic("TODO slice of null ptr");
2546826353 }
2546926354 } else if (is_slice(array_type)) {
25470 ZigValue *slice_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node);
26355 ZigValue *slice_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node);
2547126356 if (slice_ptr == nullptr)
25472 return ira->codegen->invalid_instruction;
26357 return ira->codegen->invalid_inst_gen;
2547326358
2547426359 if (slice_ptr->special == ConstValSpecialUndef) {
25475 ir_add_error(ira, &instruction->base, buf_sprintf("slice of undefined"));
25476 return ira->codegen->invalid_instruction;
26360 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of undefined"));
26361 return ira->codegen->invalid_inst_gen;
2547726362 }
2547826363
2547926364 parent_ptr = slice_ptr->data.x_struct.fields[slice_ptr_index];
2548026365 if (parent_ptr->special == ConstValSpecialUndef) {
25481 ir_add_error(ira, &instruction->base, buf_sprintf("slice of undefined"));
25482 return ira->codegen->invalid_instruction;
26366 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of undefined"));
26367 return ira->codegen->invalid_inst_gen;
2548326368 }
2548426369
2548526370 ZigValue *len_val = slice_ptr->data.x_struct.fields[slice_len_index];
......@@ -25522,37 +26407,37 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2552226407
2552326408 ZigValue *start_val = ir_resolve_const(ira, casted_start, UndefBad);
2552426409 if (!start_val)
25525 return ira->codegen->invalid_instruction;
26410 return ira->codegen->invalid_inst_gen;
2552626411
2552726412 uint64_t start_scalar = bigint_as_u64(&start_val->data.x_bigint);
2552826413 if (!ptr_is_undef && start_scalar > rel_end) {
25529 ir_add_error(ira, &instruction->base, buf_sprintf("out of bounds slice"));
25530 return ira->codegen->invalid_instruction;
26414 ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds slice"));
26415 return ira->codegen->invalid_inst_gen;
2553126416 }
2553226417
2553326418 uint64_t end_scalar = rel_end;
2553426419 if (end) {
2553526420 ZigValue *end_val = ir_resolve_const(ira, end, UndefBad);
2553626421 if (!end_val)
25537 return ira->codegen->invalid_instruction;
26422 return ira->codegen->invalid_inst_gen;
2553826423 end_scalar = bigint_as_u64(&end_val->data.x_bigint);
2553926424 }
2554026425 if (!ptr_is_undef) {
2554126426 if (end_scalar > rel_end) {
25542 ir_add_error(ira, &instruction->base, buf_sprintf("out of bounds slice"));
25543 return ira->codegen->invalid_instruction;
26427 ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds slice"));
26428 return ira->codegen->invalid_inst_gen;
2554426429 }
2554526430 if (start_scalar > end_scalar) {
25546 ir_add_error(ira, &instruction->base, buf_sprintf("slice start is greater than end"));
25547 return ira->codegen->invalid_instruction;
26431 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice start is greater than end"));
26432 return ira->codegen->invalid_inst_gen;
2554826433 }
2554926434 }
2555026435 if (ptr_is_undef && start_scalar != end_scalar) {
25551 ir_add_error(ira, &instruction->base, buf_sprintf("non-zero length slice of undefined pointer"));
25552 return ira->codegen->invalid_instruction;
26436 ir_add_error(ira, &instruction->base.base, buf_sprintf("non-zero length slice of undefined pointer"));
26437 return ira->codegen->invalid_inst_gen;
2555326438 }
2555426439
25555 IrInstruction *result = ir_const(ira, &instruction->base, return_type);
26440 IrInstGen *result = ir_const(ira, &instruction->base.base, return_type);
2555626441 ZigValue *out_val = result->value;
2555726442 out_val->data.x_struct.fields = alloc_const_vals_ptrs(2);
2555826443
......@@ -25609,28 +26494,28 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2560926494 return result;
2561026495 }
2561126496
25612 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
26497 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
2561326498 return_type, nullptr, true, false, true);
25614 if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) {
26499 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
2561526500 return result_loc;
2561626501 }
25617 return ir_build_slice_gen(ira, &instruction->base, return_type,
26502 return ir_build_slice_gen(ira, &instruction->base.base, return_type,
2561826503 ptr_ptr, casted_start, end, instruction->safety_check_on, result_loc);
2561926504}
2562026505
25621static IrInstruction *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstructionMemberCount *instruction) {
26506static IrInstGen *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstSrcMemberCount *instruction) {
2562226507 Error err;
25623 IrInstruction *container = instruction->container->child;
26508 IrInstGen *container = instruction->container->child;
2562426509 if (type_is_invalid(container->value->type))
25625 return ira->codegen->invalid_instruction;
26510 return ira->codegen->invalid_inst_gen;
2562626511 ZigType *container_type = ir_resolve_type(ira, container);
2562726512
2562826513 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))
25629 return ira->codegen->invalid_instruction;
26514 return ira->codegen->invalid_inst_gen;
2563026515
2563126516 uint64_t result;
2563226517 if (type_is_invalid(container_type)) {
25633 return ira->codegen->invalid_instruction;
26518 return ira->codegen->invalid_inst_gen;
2563426519 } else if (container_type->id == ZigTypeIdEnum) {
2563526520 result = container_type->data.enumeration.src_field_count;
2563626521 } else if (container_type->id == ZigTypeIdStruct) {
......@@ -25638,135 +26523,135 @@ static IrInstruction *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInst
2563826523 } else if (container_type->id == ZigTypeIdUnion) {
2563926524 result = container_type->data.unionation.src_field_count;
2564026525 } else if (container_type->id == ZigTypeIdErrorSet) {
25641 if (!resolve_inferred_error_set(ira->codegen, container_type, instruction->base.source_node)) {
25642 return ira->codegen->invalid_instruction;
26526 if (!resolve_inferred_error_set(ira->codegen, container_type, instruction->base.base.source_node)) {
26527 return ira->codegen->invalid_inst_gen;
2564326528 }
2564426529 if (type_is_global_error_set(container_type)) {
25645 ir_add_error(ira, &instruction->base, buf_sprintf("global error set member count not available at comptime"));
25646 return ira->codegen->invalid_instruction;
26530 ir_add_error(ira, &instruction->base.base, buf_sprintf("global error set member count not available at comptime"));
26531 return ira->codegen->invalid_inst_gen;
2564726532 }
2564826533 result = container_type->data.error_set.err_count;
2564926534 } else {
25650 ir_add_error(ira, &instruction->base, buf_sprintf("no value count available for type '%s'", buf_ptr(&container_type->name)));
25651 return ira->codegen->invalid_instruction;
26535 ir_add_error(ira, &instruction->base.base, buf_sprintf("no value count available for type '%s'", buf_ptr(&container_type->name)));
26536 return ira->codegen->invalid_inst_gen;
2565226537 }
2565326538
25654 return ir_const_unsigned(ira, &instruction->base, result);
26539 return ir_const_unsigned(ira, &instruction->base.base, result);
2565526540}
2565626541
25657static IrInstruction *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstructionMemberType *instruction) {
26542static IrInstGen *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstSrcMemberType *instruction) {
2565826543 Error err;
25659 IrInstruction *container_type_value = instruction->container_type->child;
26544 IrInstGen *container_type_value = instruction->container_type->child;
2566026545 ZigType *container_type = ir_resolve_type(ira, container_type_value);
2566126546 if (type_is_invalid(container_type))
25662 return ira->codegen->invalid_instruction;
26547 return ira->codegen->invalid_inst_gen;
2566326548
2566426549 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))
25665 return ira->codegen->invalid_instruction;
26550 return ira->codegen->invalid_inst_gen;
2566626551
2566726552
2566826553 uint64_t member_index;
25669 IrInstruction *index_value = instruction->member_index->child;
26554 IrInstGen *index_value = instruction->member_index->child;
2567026555 if (!ir_resolve_usize(ira, index_value, &member_index))
25671 return ira->codegen->invalid_instruction;
26556 return ira->codegen->invalid_inst_gen;
2567226557
2567326558 if (container_type->id == ZigTypeIdStruct) {
2567426559 if (member_index >= container_type->data.structure.src_field_count) {
25675 ir_add_error(ira, index_value,
26560 ir_add_error(ira, &index_value->base,
2567626561 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
2567726562 member_index, buf_ptr(&container_type->name), container_type->data.structure.src_field_count));
25678 return ira->codegen->invalid_instruction;
26563 return ira->codegen->invalid_inst_gen;
2567926564 }
2568026565 TypeStructField *field = container_type->data.structure.fields[member_index];
2568126566
25682 return ir_const_type(ira, &instruction->base, field->type_entry);
26567 return ir_const_type(ira, &instruction->base.base, field->type_entry);
2568326568 } else if (container_type->id == ZigTypeIdUnion) {
2568426569 if (member_index >= container_type->data.unionation.src_field_count) {
25685 ir_add_error(ira, index_value,
26570 ir_add_error(ira, &index_value->base,
2568626571 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
2568726572 member_index, buf_ptr(&container_type->name), container_type->data.unionation.src_field_count));
25688 return ira->codegen->invalid_instruction;
26573 return ira->codegen->invalid_inst_gen;
2568926574 }
2569026575 TypeUnionField *field = &container_type->data.unionation.fields[member_index];
2569126576
25692 return ir_const_type(ira, &instruction->base, field->type_entry);
26577 return ir_const_type(ira, &instruction->base.base, field->type_entry);
2569326578 } else {
25694 ir_add_error(ira, container_type_value,
26579 ir_add_error(ira, &container_type_value->base,
2569526580 buf_sprintf("type '%s' does not support @memberType", buf_ptr(&container_type->name)));
25696 return ira->codegen->invalid_instruction;
26581 return ira->codegen->invalid_inst_gen;
2569726582 }
2569826583}
2569926584
25700static IrInstruction *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstructionMemberName *instruction) {
26585static IrInstGen *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstSrcMemberName *instruction) {
2570126586 Error err;
25702 IrInstruction *container_type_value = instruction->container_type->child;
26587 IrInstGen *container_type_value = instruction->container_type->child;
2570326588 ZigType *container_type = ir_resolve_type(ira, container_type_value);
2570426589 if (type_is_invalid(container_type))
25705 return ira->codegen->invalid_instruction;
26590 return ira->codegen->invalid_inst_gen;
2570626591
2570726592 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))
25708 return ira->codegen->invalid_instruction;
26593 return ira->codegen->invalid_inst_gen;
2570926594
2571026595 uint64_t member_index;
25711 IrInstruction *index_value = instruction->member_index->child;
26596 IrInstGen *index_value = instruction->member_index->child;
2571226597 if (!ir_resolve_usize(ira, index_value, &member_index))
25713 return ira->codegen->invalid_instruction;
26598 return ira->codegen->invalid_inst_gen;
2571426599
2571526600 if (container_type->id == ZigTypeIdStruct) {
2571626601 if (member_index >= container_type->data.structure.src_field_count) {
25717 ir_add_error(ira, index_value,
26602 ir_add_error(ira, &index_value->base,
2571826603 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
2571926604 member_index, buf_ptr(&container_type->name), container_type->data.structure.src_field_count));
25720 return ira->codegen->invalid_instruction;
26605 return ira->codegen->invalid_inst_gen;
2572126606 }
2572226607 TypeStructField *field = container_type->data.structure.fields[member_index];
2572326608
25724 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
26609 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
2572526610 init_const_str_lit(ira->codegen, result->value, field->name);
2572626611 return result;
2572726612 } else if (container_type->id == ZigTypeIdEnum) {
2572826613 if (member_index >= container_type->data.enumeration.src_field_count) {
25729 ir_add_error(ira, index_value,
26614 ir_add_error(ira, &index_value->base,
2573026615 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
2573126616 member_index, buf_ptr(&container_type->name), container_type->data.enumeration.src_field_count));
25732 return ira->codegen->invalid_instruction;
26617 return ira->codegen->invalid_inst_gen;
2573326618 }
2573426619 TypeEnumField *field = &container_type->data.enumeration.fields[member_index];
2573526620
25736 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
26621 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
2573726622 init_const_str_lit(ira->codegen, result->value, field->name);
2573826623 return result;
2573926624 } else if (container_type->id == ZigTypeIdUnion) {
2574026625 if (member_index >= container_type->data.unionation.src_field_count) {
25741 ir_add_error(ira, index_value,
26626 ir_add_error(ira, &index_value->base,
2574226627 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
2574326628 member_index, buf_ptr(&container_type->name), container_type->data.unionation.src_field_count));
25744 return ira->codegen->invalid_instruction;
26629 return ira->codegen->invalid_inst_gen;
2574526630 }
2574626631 TypeUnionField *field = &container_type->data.unionation.fields[member_index];
2574726632
25748 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
26633 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
2574926634 init_const_str_lit(ira->codegen, result->value, field->name);
2575026635 return result;
2575126636 } else {
25752 ir_add_error(ira, container_type_value,
26637 ir_add_error(ira, &container_type_value->base,
2575326638 buf_sprintf("type '%s' does not support @memberName", buf_ptr(&container_type->name)));
25754 return ira->codegen->invalid_instruction;
26639 return ira->codegen->invalid_inst_gen;
2575526640 }
2575626641}
2575726642
25758static IrInstruction *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstructionHasField *instruction) {
26643static IrInstGen *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstSrcHasField *instruction) {
2575926644 Error err;
2576026645 ZigType *container_type = ir_resolve_type(ira, instruction->container_type->child);
2576126646 if (type_is_invalid(container_type))
25762 return ira->codegen->invalid_instruction;
26647 return ira->codegen->invalid_inst_gen;
2576326648
2576426649 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusZeroBitsKnown)))
25765 return ira->codegen->invalid_instruction;
26650 return ira->codegen->invalid_inst_gen;
2576626651
2576726652 Buf *field_name = ir_resolve_str(ira, instruction->field_name->child);
2576826653 if (field_name == nullptr)
25769 return ira->codegen->invalid_instruction;
26654 return ira->codegen->invalid_inst_gen;
2577026655
2577126656 bool result;
2577226657 if (container_type->id == ZigTypeIdStruct) {
......@@ -25776,91 +26661,77 @@ static IrInstruction *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstruc
2577626661 } else if (container_type->id == ZigTypeIdUnion) {
2577726662 result = find_union_type_field(container_type, field_name) != nullptr;
2577826663 } else {
25779 ir_add_error(ira, instruction->container_type,
26664 ir_add_error(ira, &instruction->container_type->base,
2578026665 buf_sprintf("type '%s' does not support @hasField", buf_ptr(&container_type->name)));
25781 return ira->codegen->invalid_instruction;
26666 return ira->codegen->invalid_inst_gen;
2578226667 }
25783 return ir_const_bool(ira, &instruction->base, result);
26668 return ir_const_bool(ira, &instruction->base.base, result);
2578426669}
2578526670
25786static IrInstruction *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstructionBreakpoint *instruction) {
25787 IrInstruction *result = ir_build_breakpoint(&ira->new_irb,
25788 instruction->base.scope, instruction->base.source_node);
25789 result->value->type = ira->codegen->builtin_types.entry_void;
25790 return result;
26671static IrInstGen *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstSrcBreakpoint *instruction) {
26672 return ir_build_breakpoint_gen(ira, &instruction->base.base);
2579126673}
2579226674
25793static IrInstruction *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstructionReturnAddress *instruction) {
25794 IrInstruction *result = ir_build_return_address(&ira->new_irb,
25795 instruction->base.scope, instruction->base.source_node);
25796 result->value->type = ira->codegen->builtin_types.entry_usize;
25797 return result;
26675static IrInstGen *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstSrcReturnAddress *instruction) {
26676 return ir_build_return_address_gen(ira, &instruction->base.base);
2579826677}
2579926678
25800static IrInstruction *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstructionFrameAddress *instruction) {
25801 IrInstruction *result = ir_build_frame_address(&ira->new_irb,
25802 instruction->base.scope, instruction->base.source_node);
25803 result->value->type = ira->codegen->builtin_types.entry_usize;
25804 return result;
26679static IrInstGen *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstSrcFrameAddress *instruction) {
26680 return ir_build_frame_address_gen(ira, &instruction->base.base);
2580526681}
2580626682
25807static IrInstruction *ir_analyze_instruction_frame_handle(IrAnalyze *ira, IrInstructionFrameHandle *instruction) {
25808 ZigFn *fn = exec_fn_entry(ira->new_irb.exec);
25809 ir_assert(fn != nullptr, &instruction->base);
26683static IrInstGen *ir_analyze_instruction_frame_handle(IrAnalyze *ira, IrInstSrcFrameHandle *instruction) {
26684 ZigFn *fn = ira->new_irb.exec->fn_entry;
26685 ir_assert(fn != nullptr, &instruction->base.base);
2581026686
2581126687 if (fn->inferred_async_node == nullptr) {
25812 fn->inferred_async_node = instruction->base.source_node;
26688 fn->inferred_async_node = instruction->base.base.source_node;
2581326689 }
2581426690
2581526691 ZigType *frame_type = get_fn_frame_type(ira->codegen, fn);
2581626692 ZigType *ptr_frame_type = get_pointer_to_type(ira->codegen, frame_type, false);
2581726693
25818 IrInstruction *result = ir_build_handle(&ira->new_irb, instruction->base.scope, instruction->base.source_node);
25819 result->value->type = ptr_frame_type;
25820 return result;
26694 return ir_build_handle_gen(ira, &instruction->base.base, ptr_frame_type);
2582126695}
2582226696
25823static IrInstruction *ir_analyze_instruction_frame_type(IrAnalyze *ira, IrInstructionFrameType *instruction) {
26697static IrInstGen *ir_analyze_instruction_frame_type(IrAnalyze *ira, IrInstSrcFrameType *instruction) {
2582426698 ZigFn *fn = ir_resolve_fn(ira, instruction->fn->child);
2582526699 if (fn == nullptr)
25826 return ira->codegen->invalid_instruction;
26700 return ira->codegen->invalid_inst_gen;
2582726701
2582826702 if (fn->type_entry->data.fn.is_generic) {
25829 ir_add_error(ira, &instruction->base,
26703 ir_add_error(ira, &instruction->base.base,
2583026704 buf_sprintf("@Frame() of generic function"));
25831 return ira->codegen->invalid_instruction;
26705 return ira->codegen->invalid_inst_gen;
2583226706 }
2583326707
2583426708 ZigType *ty = get_fn_frame_type(ira->codegen, fn);
25835 return ir_const_type(ira, &instruction->base, ty);
26709 return ir_const_type(ira, &instruction->base.base, ty);
2583626710}
2583726711
25838static IrInstruction *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstructionFrameSizeSrc *instruction) {
25839 IrInstruction *fn = instruction->fn->child;
26712static IrInstGen *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstSrcFrameSize *instruction) {
26713 IrInstGen *fn = instruction->fn->child;
2584026714 if (type_is_invalid(fn->value->type))
25841 return ira->codegen->invalid_instruction;
26715 return ira->codegen->invalid_inst_gen;
2584226716
2584326717 if (fn->value->type->id != ZigTypeIdFn) {
25844 ir_add_error(ira, fn,
26718 ir_add_error(ira, &fn->base,
2584526719 buf_sprintf("expected function, found '%s'", buf_ptr(&fn->value->type->name)));
25846 return ira->codegen->invalid_instruction;
26720 return ira->codegen->invalid_inst_gen;
2584726721 }
2584826722
2584926723 ira->codegen->need_frame_size_prefix_data = true;
2585026724
25851 IrInstruction *result = ir_build_frame_size_gen(&ira->new_irb, instruction->base.scope,
25852 instruction->base.source_node, fn);
25853 result->value->type = ira->codegen->builtin_types.entry_usize;
25854 return result;
26725 return ir_build_frame_size_gen(ira, &instruction->base.base, fn);
2585526726}
2585626727
25857static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstructionAlignOf *instruction) {
26728static IrInstGen *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstSrcAlignOf *instruction) {
2585826729 // Here we create a lazy value in order to avoid resolving the alignment of the type
2585926730 // immediately. This avoids false positive dependency loops such as:
2586026731 // const Node = struct {
2586126732 // field: []align(@alignOf(Node)) Node,
2586226733 // };
25863 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int);
26734 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int);
2586426735 result->value->special = ConstValSpecialLazy;
2586526736
2586626737 LazyValueAlignOf *lazy_align_of = allocate<LazyValueAlignOf>(1, "LazyValueAlignOf");
......@@ -25870,41 +26741,41 @@ static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruct
2587026741
2587126742 lazy_align_of->target_type = instruction->type_value->child;
2587226743 if (ir_resolve_type_lazy(ira, lazy_align_of->target_type) == nullptr)
25873 return ira->codegen->invalid_instruction;
26744 return ira->codegen->invalid_inst_gen;
2587426745
2587526746 return result;
2587626747}
2587726748
25878static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstructionOverflowOp *instruction) {
26749static IrInstGen *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstSrcOverflowOp *instruction) {
2587926750 Error err;
2588026751
25881 IrInstruction *type_value = instruction->type_value->child;
26752 IrInstGen *type_value = instruction->type_value->child;
2588226753 if (type_is_invalid(type_value->value->type))
25883 return ira->codegen->invalid_instruction;
26754 return ira->codegen->invalid_inst_gen;
2588426755
2588526756 ZigType *dest_type = ir_resolve_type(ira, type_value);
2588626757 if (type_is_invalid(dest_type))
25887 return ira->codegen->invalid_instruction;
26758 return ira->codegen->invalid_inst_gen;
2588826759
2588926760 if (dest_type->id != ZigTypeIdInt) {
25890 ir_add_error(ira, type_value,
26761 ir_add_error(ira, &type_value->base,
2589126762 buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
25892 return ira->codegen->invalid_instruction;
26763 return ira->codegen->invalid_inst_gen;
2589326764 }
2589426765
25895 IrInstruction *op1 = instruction->op1->child;
26766 IrInstGen *op1 = instruction->op1->child;
2589626767 if (type_is_invalid(op1->value->type))
25897 return ira->codegen->invalid_instruction;
26768 return ira->codegen->invalid_inst_gen;
2589826769
25899 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, dest_type);
26770 IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, dest_type);
2590026771 if (type_is_invalid(casted_op1->value->type))
25901 return ira->codegen->invalid_instruction;
26772 return ira->codegen->invalid_inst_gen;
2590226773
25903 IrInstruction *op2 = instruction->op2->child;
26774 IrInstGen *op2 = instruction->op2->child;
2590426775 if (type_is_invalid(op2->value->type))
25905 return ira->codegen->invalid_instruction;
26776 return ira->codegen->invalid_inst_gen;
2590626777
25907 IrInstruction *casted_op2;
26778 IrInstGen *casted_op2;
2590826779 if (instruction->op == IrOverflowOpShl) {
2590926780 ZigType *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen,
2591026781 dest_type->data.integral.bit_count - 1);
......@@ -25913,17 +26784,17 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr
2591326784 casted_op2 = ir_implicit_cast(ira, op2, dest_type);
2591426785 }
2591526786 if (type_is_invalid(casted_op2->value->type))
25916 return ira->codegen->invalid_instruction;
26787 return ira->codegen->invalid_inst_gen;
2591726788
25918 IrInstruction *result_ptr = instruction->result_ptr->child;
26789 IrInstGen *result_ptr = instruction->result_ptr->child;
2591926790 if (type_is_invalid(result_ptr->value->type))
25920 return ira->codegen->invalid_instruction;
26791 return ira->codegen->invalid_inst_gen;
2592126792
2592226793 ZigType *expected_ptr_type;
2592326794 if (result_ptr->value->type->id == ZigTypeIdPointer) {
2592426795 uint32_t alignment;
2592526796 if ((err = resolve_ptr_align(ira, result_ptr->value->type, &alignment)))
25926 return ira->codegen->invalid_instruction;
26797 return ira->codegen->invalid_inst_gen;
2592726798 expected_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_type,
2592826799 false, result_ptr->value->type->data.pointer.is_volatile,
2592926800 PtrLenSingle,
......@@ -25932,9 +26803,9 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr
2593226803 expected_ptr_type = get_pointer_to_type(ira->codegen, dest_type, false);
2593326804 }
2593426805
25935 IrInstruction *casted_result_ptr = ir_implicit_cast(ira, result_ptr, expected_ptr_type);
26806 IrInstGen *casted_result_ptr = ir_implicit_cast(ira, result_ptr, expected_ptr_type);
2593626807 if (type_is_invalid(casted_result_ptr->value->type))
25937 return ira->codegen->invalid_instruction;
26808 return ira->codegen->invalid_inst_gen;
2593826809
2593926810 if (instr_is_comptime(casted_op1) &&
2594026811 instr_is_comptime(casted_op2) &&
......@@ -25942,22 +26813,22 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr
2594226813 {
2594326814 ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);
2594426815 if (op1_val == nullptr)
25945 return ira->codegen->invalid_instruction;
26816 return ira->codegen->invalid_inst_gen;
2594626817
2594726818 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
2594826819 if (op2_val == nullptr)
25949 return ira->codegen->invalid_instruction;
26820 return ira->codegen->invalid_inst_gen;
2595026821
2595126822 ZigValue *result_val = ir_resolve_const(ira, casted_result_ptr, UndefBad);
2595226823 if (result_val == nullptr)
25953 return ira->codegen->invalid_instruction;
26824 return ira->codegen->invalid_inst_gen;
2595426825
2595526826 BigInt *op1_bigint = &op1_val->data.x_bigint;
2595626827 BigInt *op2_bigint = &op2_val->data.x_bigint;
2595726828 ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, result_val,
25958 casted_result_ptr->source_node);
26829 casted_result_ptr->base.source_node);
2595926830 if (pointee_val == nullptr)
25960 return ira->codegen->invalid_instruction;
26831 return ira->codegen->invalid_inst_gen;
2596126832 BigInt *dest_bigint = &pointee_val->data.x_bigint;
2596226833 switch (instruction->op) {
2596326834 case IrOverflowOpAdd:
......@@ -25984,17 +26855,14 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr
2598426855 dest_type->data.integral.is_signed);
2598526856 }
2598626857 pointee_val->special = ConstValSpecialStatic;
25987 return ir_const_bool(ira, &instruction->base, result_bool);
26858 return ir_const_bool(ira, &instruction->base.base, result_bool);
2598826859 }
2598926860
25990 IrInstruction *result = ir_build_overflow_op(&ira->new_irb,
25991 instruction->base.scope, instruction->base.source_node,
25992 instruction->op, type_value, casted_op1, casted_op2, casted_result_ptr, dest_type);
25993 result->value->type = ira->codegen->builtin_types.entry_bool;
25994 return result;
26861 return ir_build_overflow_op_gen(ira, &instruction->base.base, instruction->op,
26862 casted_op1, casted_op2, casted_result_ptr, dest_type);
2599526863}
2599626864
25997static void ir_eval_mul_add(IrAnalyze *ira, IrInstructionMulAdd *source_instr, ZigType *float_type,
26865static void ir_eval_mul_add(IrAnalyze *ira, IrInstSrcMulAdd *source_instr, ZigType *float_type,
2599826866 ZigValue *op1, ZigValue *op2, ZigValue *op3, ZigValue *out_val) {
2599926867 if (float_type->id == ZigTypeIdComptimeFloat) {
2600026868 f128M_mulAdd(&out_val->data.x_bigfloat.value, &op1->data.x_bigfloat.value, &op2->data.x_bigfloat.value,
......@@ -26021,61 +26889,61 @@ static void ir_eval_mul_add(IrAnalyze *ira, IrInstructionMulAdd *source_instr, Z
2602126889 }
2602226890}
2602326891
26024static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructionMulAdd *instruction) {
26025 IrInstruction *type_value = instruction->type_value->child;
26892static IrInstGen *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstSrcMulAdd *instruction) {
26893 IrInstGen *type_value = instruction->type_value->child;
2602626894 if (type_is_invalid(type_value->value->type))
26027 return ira->codegen->invalid_instruction;
26895 return ira->codegen->invalid_inst_gen;
2602826896
2602926897 ZigType *expr_type = ir_resolve_type(ira, type_value);
2603026898 if (type_is_invalid(expr_type))
26031 return ira->codegen->invalid_instruction;
26899 return ira->codegen->invalid_inst_gen;
2603226900
2603326901 // Only allow float types, and vectors of floats.
2603426902 ZigType *float_type = (expr_type->id == ZigTypeIdVector) ? expr_type->data.vector.elem_type : expr_type;
2603526903 if (float_type->id != ZigTypeIdFloat) {
26036 ir_add_error(ira, type_value,
26904 ir_add_error(ira, &type_value->base,
2603726905 buf_sprintf("expected float or vector of float type, found '%s'", buf_ptr(&float_type->name)));
26038 return ira->codegen->invalid_instruction;
26906 return ira->codegen->invalid_inst_gen;
2603926907 }
2604026908
26041 IrInstruction *op1 = instruction->op1->child;
26909 IrInstGen *op1 = instruction->op1->child;
2604226910 if (type_is_invalid(op1->value->type))
26043 return ira->codegen->invalid_instruction;
26911 return ira->codegen->invalid_inst_gen;
2604426912
26045 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, expr_type);
26913 IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, expr_type);
2604626914 if (type_is_invalid(casted_op1->value->type))
26047 return ira->codegen->invalid_instruction;
26915 return ira->codegen->invalid_inst_gen;
2604826916
26049 IrInstruction *op2 = instruction->op2->child;
26917 IrInstGen *op2 = instruction->op2->child;
2605026918 if (type_is_invalid(op2->value->type))
26051 return ira->codegen->invalid_instruction;
26919 return ira->codegen->invalid_inst_gen;
2605226920
26053 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, expr_type);
26921 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, expr_type);
2605426922 if (type_is_invalid(casted_op2->value->type))
26055 return ira->codegen->invalid_instruction;
26923 return ira->codegen->invalid_inst_gen;
2605626924
26057 IrInstruction *op3 = instruction->op3->child;
26925 IrInstGen *op3 = instruction->op3->child;
2605826926 if (type_is_invalid(op3->value->type))
26059 return ira->codegen->invalid_instruction;
26927 return ira->codegen->invalid_inst_gen;
2606026928
26061 IrInstruction *casted_op3 = ir_implicit_cast(ira, op3, expr_type);
26929 IrInstGen *casted_op3 = ir_implicit_cast(ira, op3, expr_type);
2606226930 if (type_is_invalid(casted_op3->value->type))
26063 return ira->codegen->invalid_instruction;
26931 return ira->codegen->invalid_inst_gen;
2606426932
2606526933 if (instr_is_comptime(casted_op1) &&
2606626934 instr_is_comptime(casted_op2) &&
2606726935 instr_is_comptime(casted_op3)) {
2606826936 ZigValue *op1_const = ir_resolve_const(ira, casted_op1, UndefBad);
2606926937 if (!op1_const)
26070 return ira->codegen->invalid_instruction;
26938 return ira->codegen->invalid_inst_gen;
2607126939 ZigValue *op2_const = ir_resolve_const(ira, casted_op2, UndefBad);
2607226940 if (!op2_const)
26073 return ira->codegen->invalid_instruction;
26941 return ira->codegen->invalid_inst_gen;
2607426942 ZigValue *op3_const = ir_resolve_const(ira, casted_op3, UndefBad);
2607526943 if (!op3_const)
26076 return ira->codegen->invalid_instruction;
26944 return ira->codegen->invalid_inst_gen;
2607726945
26078 IrInstruction *result = ir_const(ira, &instruction->base, expr_type);
26946 IrInstGen *result = ir_const(ira, &instruction->base.base, expr_type);
2607926947 ZigValue *out_val = result->value;
2608026948
2608126949 if (expr_type->id == ZigTypeIdVector) {
......@@ -26106,63 +26974,59 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi
2610626974 return result;
2610726975 }
2610826976
26109 IrInstruction *result = ir_build_mul_add(&ira->new_irb,
26110 instruction->base.scope, instruction->base.source_node,
26111 type_value, casted_op1, casted_op2, casted_op3);
26112 result->value->type = expr_type;
26113 return result;
26977 return ir_build_mul_add_gen(ira, &instruction->base.base, casted_op1, casted_op2, casted_op3, expr_type);
2611426978}
2611526979
26116static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTestErrSrc *instruction) {
26117 IrInstruction *base_ptr = instruction->base_ptr->child;
26980static IrInstGen *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstSrcTestErr *instruction) {
26981 IrInstGen *base_ptr = instruction->base_ptr->child;
2611826982 if (type_is_invalid(base_ptr->value->type))
26119 return ira->codegen->invalid_instruction;
26983 return ira->codegen->invalid_inst_gen;
2612026984
26121 IrInstruction *value;
26985 IrInstGen *value;
2612226986 if (instruction->base_ptr_is_payload) {
2612326987 value = base_ptr;
2612426988 } else {
26125 value = ir_get_deref(ira, &instruction->base, base_ptr, nullptr);
26989 value = ir_get_deref(ira, &instruction->base.base, base_ptr, nullptr);
2612626990 }
2612726991
2612826992 ZigType *type_entry = value->value->type;
2612926993 if (type_is_invalid(type_entry))
26130 return ira->codegen->invalid_instruction;
26994 return ira->codegen->invalid_inst_gen;
2613126995 if (type_entry->id == ZigTypeIdErrorUnion) {
2613226996 if (instr_is_comptime(value)) {
2613326997 ZigValue *err_union_val = ir_resolve_const(ira, value, UndefBad);
2613426998 if (!err_union_val)
26135 return ira->codegen->invalid_instruction;
26999 return ira->codegen->invalid_inst_gen;
2613627000
2613727001 if (err_union_val->special != ConstValSpecialRuntime) {
2613827002 ErrorTableEntry *err = err_union_val->data.x_err_union.error_set->data.x_err_set;
26139 return ir_const_bool(ira, &instruction->base, (err != nullptr));
27003 return ir_const_bool(ira, &instruction->base.base, (err != nullptr));
2614027004 }
2614127005 }
2614227006
2614327007 if (instruction->resolve_err_set) {
2614427008 ZigType *err_set_type = type_entry->data.error_union.err_set_type;
26145 if (!resolve_inferred_error_set(ira->codegen, err_set_type, instruction->base.source_node)) {
26146 return ira->codegen->invalid_instruction;
27009 if (!resolve_inferred_error_set(ira->codegen, err_set_type, instruction->base.base.source_node)) {
27010 return ira->codegen->invalid_inst_gen;
2614727011 }
2614827012 if (!type_is_global_error_set(err_set_type) &&
2614927013 err_set_type->data.error_set.err_count == 0)
2615027014 {
2615127015 assert(!err_set_type->data.error_set.incomplete);
26152 return ir_const_bool(ira, &instruction->base, false);
27016 return ir_const_bool(ira, &instruction->base.base, false);
2615327017 }
2615427018 }
2615527019
26156 return ir_build_test_err_gen(ira, &instruction->base, value);
27020 return ir_build_test_err_gen(ira, &instruction->base.base, value);
2615727021 } else if (type_entry->id == ZigTypeIdErrorSet) {
26158 return ir_const_bool(ira, &instruction->base, true);
27022 return ir_const_bool(ira, &instruction->base.base, true);
2615927023 } else {
26160 return ir_const_bool(ira, &instruction->base, false);
27024 return ir_const_bool(ira, &instruction->base.base, false);
2616127025 }
2616227026}
2616327027
26164static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *source_instr,
26165 IrInstruction *base_ptr, bool initializing)
27028static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_instr,
27029 IrInstGen *base_ptr, bool initializing)
2616627030{
2616727031 ZigType *ptr_type = base_ptr->value->type;
2616827032
......@@ -26171,12 +27035,12 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *
2617127035
2617227036 ZigType *type_entry = ptr_type->data.pointer.child_type;
2617327037 if (type_is_invalid(type_entry))
26174 return ira->codegen->invalid_instruction;
27038 return ira->codegen->invalid_inst_gen;
2617527039
2617627040 if (type_entry->id != ZigTypeIdErrorUnion) {
26177 ir_add_error(ira, base_ptr,
27041 ir_add_error(ira, &base_ptr->base,
2617827042 buf_sprintf("expected error union type, found '%s'", buf_ptr(&type_entry->name)));
26179 return ira->codegen->invalid_instruction;
27043 return ira->codegen->invalid_inst_gen;
2618027044 }
2618127045
2618227046 ZigType *err_set_type = type_entry->data.error_union.err_set_type;
......@@ -26187,13 +27051,13 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *
2618727051 if (instr_is_comptime(base_ptr)) {
2618827052 ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad);
2618927053 if (!ptr_val)
26190 return ira->codegen->invalid_instruction;
27054 return ira->codegen->invalid_inst_gen;
2619127055 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar &&
2619227056 ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr)
2619327057 {
2619427058 ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
2619527059 if (err_union_val == nullptr)
26196 return ira->codegen->invalid_instruction;
27060 return ira->codegen->invalid_inst_gen;
2619727061
2619827062 if (initializing && err_union_val->special == ConstValSpecialUndef) {
2619927063 ZigValue *vals = create_const_vals(2);
......@@ -26216,11 +27080,10 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *
2621627080 }
2621727081 ir_assert(err_union_val->special != ConstValSpecialRuntime, source_instr);
2621827082
26219 IrInstruction *result;
27083 IrInstGen *result;
2622027084 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
26221 result = ir_build_unwrap_err_code(&ira->new_irb, source_instr->scope,
26222 source_instr->source_node, base_ptr);
26223 result->value->type = result_type;
27085 result = ir_build_unwrap_err_code_gen(ira, source_instr->scope,
27086 source_instr->source_node, base_ptr, result_type);
2622427087 result->value->special = ConstValSpecialStatic;
2622527088 } else {
2622627089 result = ir_const(ira, source_instr, result_type);
......@@ -26233,23 +27096,18 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *
2623327096 }
2623427097 }
2623527098
26236 IrInstruction *result = ir_build_unwrap_err_code(&ira->new_irb,
26237 source_instr->scope, source_instr->source_node, base_ptr);
26238 result->value->type = result_type;
26239 return result;
27099 return ir_build_unwrap_err_code_gen(ira, source_instr->scope, source_instr->source_node, base_ptr, result_type);
2624027100}
2624127101
26242static IrInstruction *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,
26243 IrInstructionUnwrapErrCode *instruction)
26244{
26245 IrInstruction *base_ptr = instruction->err_union_ptr->child;
27102static IrInstGen *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, IrInstSrcUnwrapErrCode *instruction) {
27103 IrInstGen *base_ptr = instruction->err_union_ptr->child;
2624627104 if (type_is_invalid(base_ptr->value->type))
26247 return ira->codegen->invalid_instruction;
26248 return ir_analyze_unwrap_err_code(ira, &instruction->base, base_ptr, false);
27105 return ira->codegen->invalid_inst_gen;
27106 return ir_analyze_unwrap_err_code(ira, &instruction->base.base, base_ptr, false);
2624927107}
2625027108
26251static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruction *source_instr,
26252 IrInstruction *base_ptr, bool safety_check_on, bool initializing)
27109static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source_instr,
27110 IrInstGen *base_ptr, bool safety_check_on, bool initializing)
2625327111{
2625427112 ZigType *ptr_type = base_ptr->value->type;
2625527113
......@@ -26258,17 +27116,17 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct
2625827116
2625927117 ZigType *type_entry = ptr_type->data.pointer.child_type;
2626027118 if (type_is_invalid(type_entry))
26261 return ira->codegen->invalid_instruction;
27119 return ira->codegen->invalid_inst_gen;
2626227120
2626327121 if (type_entry->id != ZigTypeIdErrorUnion) {
26264 ir_add_error(ira, base_ptr,
27122 ir_add_error(ira, &base_ptr->base,
2626527123 buf_sprintf("expected error union type, found '%s'", buf_ptr(&type_entry->name)));
26266 return ira->codegen->invalid_instruction;
27124 return ira->codegen->invalid_inst_gen;
2626727125 }
2626827126
2626927127 ZigType *payload_type = type_entry->data.error_union.payload_type;
2627027128 if (type_is_invalid(payload_type))
26271 return ira->codegen->invalid_instruction;
27129 return ira->codegen->invalid_inst_gen;
2627227130
2627327131 ZigType *result_type = get_pointer_to_type_extra(ira->codegen, payload_type,
2627427132 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
......@@ -26277,11 +27135,11 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct
2627727135 if (instr_is_comptime(base_ptr)) {
2627827136 ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad);
2627927137 if (!ptr_val)
26280 return ira->codegen->invalid_instruction;
27138 return ira->codegen->invalid_inst_gen;
2628127139 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
2628227140 ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
2628327141 if (err_union_val == nullptr)
26284 return ira->codegen->invalid_instruction;
27142 return ira->codegen->invalid_inst_gen;
2628527143 if (initializing && err_union_val->special == ConstValSpecialUndef) {
2628627144 ZigValue *vals = create_const_vals(2);
2628727145 ZigValue *err_set_val = &vals[0];
......@@ -26304,14 +27162,13 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct
2630427162 if (err != nullptr) {
2630527163 ir_add_error(ira, source_instr,
2630627164 buf_sprintf("caught unexpected error '%s'", buf_ptr(&err->name)));
26307 return ira->codegen->invalid_instruction;
27165 return ira->codegen->invalid_inst_gen;
2630827166 }
2630927167
26310 IrInstruction *result;
27168 IrInstGen *result;
2631127169 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
26312 result = ir_build_unwrap_err_payload(&ira->new_irb, source_instr->scope,
26313 source_instr->source_node, base_ptr, safety_check_on, initializing);
26314 result->value->type = result_type;
27170 result = ir_build_unwrap_err_payload_gen(ira, source_instr->scope,
27171 source_instr->source_node, base_ptr, safety_check_on, initializing, result_type);
2631527172 result->value->special = ConstValSpecialStatic;
2631627173 } else {
2631727174 result = ir_const(ira, source_instr, result_type);
......@@ -26324,28 +27181,26 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct
2632427181 }
2632527182 }
2632627183
26327 IrInstruction *result = ir_build_unwrap_err_payload(&ira->new_irb, source_instr->scope,
26328 source_instr->source_node, base_ptr, safety_check_on, initializing);
26329 result->value->type = result_type;
26330 return result;
27184 return ir_build_unwrap_err_payload_gen(ira, source_instr->scope, source_instr->source_node,
27185 base_ptr, safety_check_on, initializing, result_type);
2633127186}
2633227187
26333static IrInstruction *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
26334 IrInstructionUnwrapErrPayload *instruction)
27188static IrInstGen *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
27189 IrInstSrcUnwrapErrPayload *instruction)
2633527190{
2633627191 assert(instruction->value->child);
26337 IrInstruction *value = instruction->value->child;
27192 IrInstGen *value = instruction->value->child;
2633827193 if (type_is_invalid(value->value->type))
26339 return ira->codegen->invalid_instruction;
27194 return ira->codegen->invalid_inst_gen;
2634027195
26341 return ir_analyze_unwrap_error_payload(ira, &instruction->base, value, instruction->safety_check_on, false);
27196 return ir_analyze_unwrap_error_payload(ira, &instruction->base.base, value, instruction->safety_check_on, false);
2634227197}
2634327198
26344static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstructionFnProto *instruction) {
26345 AstNode *proto_node = instruction->base.source_node;
27199static IrInstGen *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstSrcFnProto *instruction) {
27200 AstNode *proto_node = instruction->base.base.source_node;
2634627201 assert(proto_node->type == NodeTypeFnProto);
2634727202
26348 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type);
27203 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);
2634927204 result->value->special = ConstValSpecialLazy;
2635027205
2635127206 LazyValueFnType *lazy_fn_type = allocate<LazyValueFnType>(1, "LazyValueFnType");
......@@ -26354,29 +27209,29 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct
2635427209 lazy_fn_type->base.id = LazyValueIdFnType;
2635527210
2635627211 if (proto_node->data.fn_proto.auto_err_set) {
26357 ir_add_error(ira, &instruction->base,
27212 ir_add_error(ira, &instruction->base.base,
2635827213 buf_sprintf("inferring error set of return type valid only for function definitions"));
26359 return ira->codegen->invalid_instruction;
27214 return ira->codegen->invalid_inst_gen;
2636027215 }
2636127216
2636227217 lazy_fn_type->cc = cc_from_fn_proto(&proto_node->data.fn_proto);
2636327218 if (instruction->callconv_value != nullptr) {
2636427219 ZigType *cc_enum_type = get_builtin_type(ira->codegen, "CallingConvention");
2636527220
26366 IrInstruction *casted_value = ir_implicit_cast(ira, instruction->callconv_value, cc_enum_type);
27221 IrInstGen *casted_value = ir_implicit_cast(ira, instruction->callconv_value->child, cc_enum_type);
2636727222 if (type_is_invalid(casted_value->value->type))
26368 return ira->codegen->invalid_instruction;
27223 return ira->codegen->invalid_inst_gen;
2636927224
2637027225 ZigValue *const_value = ir_resolve_const(ira, casted_value, UndefBad);
2637127226 if (const_value == nullptr)
26372 return ira->codegen->invalid_instruction;
27227 return ira->codegen->invalid_inst_gen;
2637327228
2637427229 lazy_fn_type->cc = (CallingConvention)bigint_as_u32(&const_value->data.x_enum_tag);
2637527230 }
2637627231
2637727232 size_t param_count = proto_node->data.fn_proto.params.length;
2637827233 lazy_fn_type->proto_node = proto_node;
26379 lazy_fn_type->param_types = allocate<IrInstruction *>(param_count);
27234 lazy_fn_type->param_types = allocate<IrInstGen *>(param_count);
2638027235
2638127236 for (size_t param_index = 0; param_index < param_count; param_index += 1) {
2638227237 AstNode *param_node = proto_node->data.fn_proto.params.at(param_index);
......@@ -26401,63 +27256,63 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct
2640127256 return result;
2640227257 }
2640327258
26404 IrInstruction *param_type_value = instruction->param_types[param_index]->child;
27259 IrInstGen *param_type_value = instruction->param_types[param_index]->child;
2640527260 if (type_is_invalid(param_type_value->value->type))
26406 return ira->codegen->invalid_instruction;
27261 return ira->codegen->invalid_inst_gen;
2640727262 if (ir_resolve_const(ira, param_type_value, LazyOk) == nullptr)
26408 return ira->codegen->invalid_instruction;
27263 return ira->codegen->invalid_inst_gen;
2640927264 lazy_fn_type->param_types[param_index] = param_type_value;
2641027265 }
2641127266
2641227267 if (instruction->align_value != nullptr) {
2641327268 lazy_fn_type->align_inst = instruction->align_value->child;
2641427269 if (ir_resolve_const(ira, lazy_fn_type->align_inst, LazyOk) == nullptr)
26415 return ira->codegen->invalid_instruction;
27270 return ira->codegen->invalid_inst_gen;
2641627271 }
2641727272
2641827273 lazy_fn_type->return_type = instruction->return_type->child;
2641927274 if (ir_resolve_const(ira, lazy_fn_type->return_type, LazyOk) == nullptr)
26420 return ira->codegen->invalid_instruction;
27275 return ira->codegen->invalid_inst_gen;
2642127276
2642227277 return result;
2642327278}
2642427279
26425static IrInstruction *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstructionTestComptime *instruction) {
26426 IrInstruction *value = instruction->value->child;
27280static IrInstGen *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstSrcTestComptime *instruction) {
27281 IrInstGen *value = instruction->value->child;
2642727282 if (type_is_invalid(value->value->type))
26428 return ira->codegen->invalid_instruction;
27283 return ira->codegen->invalid_inst_gen;
2642927284
26430 return ir_const_bool(ira, &instruction->base, instr_is_comptime(value));
27285 return ir_const_bool(ira, &instruction->base.base, instr_is_comptime(value));
2643127286}
2643227287
26433static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
26434 IrInstructionCheckSwitchProngs *instruction)
27288static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
27289 IrInstSrcCheckSwitchProngs *instruction)
2643527290{
26436 IrInstruction *target_value = instruction->target_value->child;
27291 IrInstGen *target_value = instruction->target_value->child;
2643727292 ZigType *switch_type = target_value->value->type;
2643827293 if (type_is_invalid(switch_type))
26439 return ira->codegen->invalid_instruction;
27294 return ira->codegen->invalid_inst_gen;
2644027295
2644127296 if (switch_type->id == ZigTypeIdEnum) {
2644227297 HashMap<BigInt, AstNode *, bigint_hash, bigint_eql> field_prev_uses = {};
2644327298 field_prev_uses.init(switch_type->data.enumeration.src_field_count);
2644427299
2644527300 for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {
26446 IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i];
27301 IrInstSrcCheckSwitchProngsRange *range = &instruction->ranges[range_i];
2644727302
26448 IrInstruction *start_value_uncasted = range->start->child;
27303 IrInstGen *start_value_uncasted = range->start->child;
2644927304 if (type_is_invalid(start_value_uncasted->value->type))
26450 return ira->codegen->invalid_instruction;
26451 IrInstruction *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type);
27305 return ira->codegen->invalid_inst_gen;
27306 IrInstGen *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type);
2645227307 if (type_is_invalid(start_value->value->type))
26453 return ira->codegen->invalid_instruction;
27308 return ira->codegen->invalid_inst_gen;
2645427309
26455 IrInstruction *end_value_uncasted = range->end->child;
27310 IrInstGen *end_value_uncasted = range->end->child;
2645627311 if (type_is_invalid(end_value_uncasted->value->type))
26457 return ira->codegen->invalid_instruction;
26458 IrInstruction *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type);
27312 return ira->codegen->invalid_inst_gen;
27313 IrInstGen *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type);
2645927314 if (type_is_invalid(end_value->value->type))
26460 return ira->codegen->invalid_instruction;
27315 return ira->codegen->invalid_inst_gen;
2646127316
2646227317 assert(start_value->value->type->id == ZigTypeIdEnum);
2646327318 BigInt start_index;
......@@ -26468,7 +27323,7 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2646827323 bigint_init_bigint(&end_index, &end_value->value->data.x_enum_tag);
2646927324
2647027325 if (bigint_cmp(&start_index, &end_index) == CmpGT) {
26471 ir_add_error(ira, start_value,
27326 ir_add_error(ira, &start_value->base,
2647227327 buf_sprintf("range start value is greater than the end value"));
2647327328 }
2647427329
......@@ -26479,12 +27334,12 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2647927334 if (cmp == CmpGT) {
2648027335 break;
2648127336 }
26482 auto entry = field_prev_uses.put_unique(field_index, start_value->source_node);
27337 auto entry = field_prev_uses.put_unique(field_index, start_value->base.source_node);
2648327338 if (entry) {
2648427339 AstNode *prev_node = entry->value;
2648527340 TypeEnumField *enum_field = find_enum_field_by_tag(switch_type, &field_index);
2648627341 assert(enum_field != nullptr);
26487 ErrorMsg *msg = ir_add_error(ira, start_value,
27342 ErrorMsg *msg = ir_add_error(ira, &start_value->base,
2648827343 buf_sprintf("duplicate switch value: '%s.%s'", buf_ptr(&switch_type->name),
2648927344 buf_ptr(enum_field->name)));
2649027345 add_error_note(ira->codegen, msg, prev_node, buf_sprintf("other value is here"));
......@@ -26494,7 +27349,7 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2649427349 }
2649527350 if (instruction->have_underscore_prong) {
2649627351 if (!switch_type->data.enumeration.non_exhaustive){
26497 ir_add_error(ira, &instruction->base,
27352 ir_add_error(ira, &instruction->base.base,
2649827353 buf_sprintf("switch on non-exhaustive enum has `_` prong"));
2649927354 }
2650027355 for (uint32_t i = 0; i < switch_type->data.enumeration.src_field_count; i += 1) {
......@@ -26504,14 +27359,14 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2650427359
2650527360 auto entry = field_prev_uses.maybe_get(enum_field->value);
2650627361 if (!entry) {
26507 ir_add_error(ira, &instruction->base,
27362 ir_add_error(ira, &instruction->base.base,
2650827363 buf_sprintf("enumeration value '%s.%s' not handled in switch", buf_ptr(&switch_type->name),
2650927364 buf_ptr(enum_field->name)));
2651027365 }
2651127366 }
2651227367 } else if (!instruction->have_else_prong) {
2651327368 if (switch_type->data.enumeration.non_exhaustive) {
26514 ir_add_error(ira, &instruction->base,
27369 ir_add_error(ira, &instruction->base.base,
2651527370 buf_sprintf("switch on non-exhaustive enum must include `else` or `_` prong"));
2651627371 }
2651727372 for (uint32_t i = 0; i < switch_type->data.enumeration.src_field_count; i += 1) {
......@@ -26519,69 +27374,69 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2651927374
2652027375 auto entry = field_prev_uses.maybe_get(enum_field->value);
2652127376 if (!entry) {
26522 ir_add_error(ira, &instruction->base,
27377 ir_add_error(ira, &instruction->base.base,
2652327378 buf_sprintf("enumeration value '%s.%s' not handled in switch", buf_ptr(&switch_type->name),
2652427379 buf_ptr(enum_field->name)));
2652527380 }
2652627381 }
2652727382 }
2652827383 } else if (switch_type->id == ZigTypeIdErrorSet) {
26529 if (!resolve_inferred_error_set(ira->codegen, switch_type, target_value->source_node)) {
26530 return ira->codegen->invalid_instruction;
27384 if (!resolve_inferred_error_set(ira->codegen, switch_type, target_value->base.source_node)) {
27385 return ira->codegen->invalid_inst_gen;
2653127386 }
2653227387
2653327388 size_t field_prev_uses_count = ira->codegen->errors_by_index.length;
2653427389 AstNode **field_prev_uses = allocate<AstNode *>(field_prev_uses_count, "AstNode *");
2653527390
2653627391 for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {
26537 IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i];
27392 IrInstSrcCheckSwitchProngsRange *range = &instruction->ranges[range_i];
2653827393
26539 IrInstruction *start_value_uncasted = range->start->child;
27394 IrInstGen *start_value_uncasted = range->start->child;
2654027395 if (type_is_invalid(start_value_uncasted->value->type))
26541 return ira->codegen->invalid_instruction;
26542 IrInstruction *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type);
27396 return ira->codegen->invalid_inst_gen;
27397 IrInstGen *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type);
2654327398 if (type_is_invalid(start_value->value->type))
26544 return ira->codegen->invalid_instruction;
27399 return ira->codegen->invalid_inst_gen;
2654527400
26546 IrInstruction *end_value_uncasted = range->end->child;
27401 IrInstGen *end_value_uncasted = range->end->child;
2654727402 if (type_is_invalid(end_value_uncasted->value->type))
26548 return ira->codegen->invalid_instruction;
26549 IrInstruction *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type);
27403 return ira->codegen->invalid_inst_gen;
27404 IrInstGen *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type);
2655027405 if (type_is_invalid(end_value->value->type))
26551 return ira->codegen->invalid_instruction;
27406 return ira->codegen->invalid_inst_gen;
2655227407
26553 ir_assert(start_value->value->type->id == ZigTypeIdErrorSet, &instruction->base);
27408 ir_assert(start_value->value->type->id == ZigTypeIdErrorSet, &instruction->base.base);
2655427409 uint32_t start_index = start_value->value->data.x_err_set->value;
2655527410
26556 ir_assert(end_value->value->type->id == ZigTypeIdErrorSet, &instruction->base);
27411 ir_assert(end_value->value->type->id == ZigTypeIdErrorSet, &instruction->base.base);
2655727412 uint32_t end_index = end_value->value->data.x_err_set->value;
2655827413
2655927414 if (start_index != end_index) {
26560 ir_add_error(ira, end_value, buf_sprintf("ranges not allowed when switching on errors"));
26561 return ira->codegen->invalid_instruction;
27415 ir_add_error(ira, &end_value->base, buf_sprintf("ranges not allowed when switching on errors"));
27416 return ira->codegen->invalid_inst_gen;
2656227417 }
2656327418
2656427419 AstNode *prev_node = field_prev_uses[start_index];
2656527420 if (prev_node != nullptr) {
2656627421 Buf *err_name = &ira->codegen->errors_by_index.at(start_index)->name;
26567 ErrorMsg *msg = ir_add_error(ira, start_value,
27422 ErrorMsg *msg = ir_add_error(ira, &start_value->base,
2656827423 buf_sprintf("duplicate switch value: '%s.%s'", buf_ptr(&switch_type->name), buf_ptr(err_name)));
2656927424 add_error_note(ira->codegen, msg, prev_node, buf_sprintf("other value is here"));
2657027425 }
26571 field_prev_uses[start_index] = start_value->source_node;
27426 field_prev_uses[start_index] = start_value->base.source_node;
2657227427 }
2657327428 if (!instruction->have_else_prong) {
2657427429 if (type_is_global_error_set(switch_type)) {
26575 ir_add_error(ira, &instruction->base,
27430 ir_add_error(ira, &instruction->base.base,
2657627431 buf_sprintf("else prong required when switching on type 'anyerror'"));
26577 return ira->codegen->invalid_instruction;
27432 return ira->codegen->invalid_inst_gen;
2657827433 } else {
2657927434 for (uint32_t i = 0; i < switch_type->data.error_set.err_count; i += 1) {
2658027435 ErrorTableEntry *err_entry = switch_type->data.error_set.errors[i];
2658127436
2658227437 AstNode *prev_node = field_prev_uses[err_entry->value];
2658327438 if (prev_node == nullptr) {
26584 ir_add_error(ira, &instruction->base,
27439 ir_add_error(ira, &instruction->base.base,
2658527440 buf_sprintf("error.%s not handled in switch", buf_ptr(&err_entry->name)));
2658627441 }
2658727442 }
......@@ -26592,44 +27447,44 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2659227447 } else if (switch_type->id == ZigTypeIdInt) {
2659327448 RangeSet rs = {0};
2659427449 for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {
26595 IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i];
27450 IrInstSrcCheckSwitchProngsRange *range = &instruction->ranges[range_i];
2659627451
26597 IrInstruction *start_value = range->start->child;
27452 IrInstGen *start_value = range->start->child;
2659827453 if (type_is_invalid(start_value->value->type))
26599 return ira->codegen->invalid_instruction;
26600 IrInstruction *casted_start_value = ir_implicit_cast(ira, start_value, switch_type);
27454 return ira->codegen->invalid_inst_gen;
27455 IrInstGen *casted_start_value = ir_implicit_cast(ira, start_value, switch_type);
2660127456 if (type_is_invalid(casted_start_value->value->type))
26602 return ira->codegen->invalid_instruction;
27457 return ira->codegen->invalid_inst_gen;
2660327458
26604 IrInstruction *end_value = range->end->child;
27459 IrInstGen *end_value = range->end->child;
2660527460 if (type_is_invalid(end_value->value->type))
26606 return ira->codegen->invalid_instruction;
26607 IrInstruction *casted_end_value = ir_implicit_cast(ira, end_value, switch_type);
27461 return ira->codegen->invalid_inst_gen;
27462 IrInstGen *casted_end_value = ir_implicit_cast(ira, end_value, switch_type);
2660827463 if (type_is_invalid(casted_end_value->value->type))
26609 return ira->codegen->invalid_instruction;
27464 return ira->codegen->invalid_inst_gen;
2661027465
2661127466 ZigValue *start_val = ir_resolve_const(ira, casted_start_value, UndefBad);
2661227467 if (!start_val)
26613 return ira->codegen->invalid_instruction;
27468 return ira->codegen->invalid_inst_gen;
2661427469
2661527470 ZigValue *end_val = ir_resolve_const(ira, casted_end_value, UndefBad);
2661627471 if (!end_val)
26617 return ira->codegen->invalid_instruction;
27472 return ira->codegen->invalid_inst_gen;
2661827473
2661927474 assert(start_val->type->id == ZigTypeIdInt || start_val->type->id == ZigTypeIdComptimeInt);
2662027475 assert(end_val->type->id == ZigTypeIdInt || end_val->type->id == ZigTypeIdComptimeInt);
2662127476
2662227477 if (bigint_cmp(&start_val->data.x_bigint, &end_val->data.x_bigint) == CmpGT) {
26623 ir_add_error(ira, start_value,
27478 ir_add_error(ira, &start_value->base,
2662427479 buf_sprintf("range start value is greater than the end value"));
2662527480 }
2662627481
2662727482 AstNode *prev_node = rangeset_add_range(&rs, &start_val->data.x_bigint, &end_val->data.x_bigint,
26628 start_value->source_node);
27483 start_value->base.source_node);
2662927484 if (prev_node != nullptr) {
26630 ErrorMsg *msg = ir_add_error(ira, start_value, buf_sprintf("duplicate switch value"));
27485 ErrorMsg *msg = ir_add_error(ira, &start_value->base, buf_sprintf("duplicate switch value"));
2663127486 add_error_note(ira->codegen, msg, prev_node, buf_sprintf("previous value is here"));
26632 return ira->codegen->invalid_instruction;
27487 return ira->codegen->invalid_inst_gen;
2663327488 }
2663427489 }
2663527490 if (!instruction->have_else_prong) {
......@@ -26638,25 +27493,25 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2663827493 BigInt max_val;
2663927494 eval_min_max_value_int(ira->codegen, switch_type, &max_val, true);
2664027495 if (!rangeset_spans(&rs, &min_val, &max_val)) {
26641 ir_add_error(ira, &instruction->base, buf_sprintf("switch must handle all possibilities"));
26642 return ira->codegen->invalid_instruction;
27496 ir_add_error(ira, &instruction->base.base, buf_sprintf("switch must handle all possibilities"));
27497 return ira->codegen->invalid_inst_gen;
2664327498 }
2664427499 }
2664527500 } else if (switch_type->id == ZigTypeIdBool) {
2664627501 int seenTrue = 0;
2664727502 int seenFalse = 0;
2664827503 for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {
26649 IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i];
27504 IrInstSrcCheckSwitchProngsRange *range = &instruction->ranges[range_i];
2665027505
26651 IrInstruction *value = range->start->child;
27506 IrInstGen *value = range->start->child;
2665227507
26653 IrInstruction *casted_value = ir_implicit_cast(ira, value, switch_type);
27508 IrInstGen *casted_value = ir_implicit_cast(ira, value, switch_type);
2665427509 if (type_is_invalid(casted_value->value->type))
26655 return ira->codegen->invalid_instruction;
27510 return ira->codegen->invalid_inst_gen;
2665627511
2665727512 ZigValue *const_expr_val = ir_resolve_const(ira, casted_value, UndefBad);
2665827513 if (!const_expr_val)
26659 return ira->codegen->invalid_instruction;
27514 return ira->codegen->invalid_inst_gen;
2666027515
2666127516 assert(const_expr_val->type->id == ZigTypeIdBool);
2666227517
......@@ -26667,60 +27522,59 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2666727522 }
2666827523
2666927524 if ((seenTrue > 1) || (seenFalse > 1)) {
26670 ir_add_error(ira, value, buf_sprintf("duplicate switch value"));
26671 return ira->codegen->invalid_instruction;
27525 ir_add_error(ira, &value->base, buf_sprintf("duplicate switch value"));
27526 return ira->codegen->invalid_inst_gen;
2667227527 }
2667327528 }
2667427529 if (((seenTrue < 1) || (seenFalse < 1)) && !instruction->have_else_prong) {
26675 ir_add_error(ira, &instruction->base, buf_sprintf("switch must handle all possibilities"));
26676 return ira->codegen->invalid_instruction;
27530 ir_add_error(ira, &instruction->base.base, buf_sprintf("switch must handle all possibilities"));
27531 return ira->codegen->invalid_inst_gen;
2667727532 }
2667827533 } else if (!instruction->have_else_prong) {
26679 ir_add_error(ira, &instruction->base,
27534 ir_add_error(ira, &instruction->base.base,
2668027535 buf_sprintf("else prong required when switching on type '%s'", buf_ptr(&switch_type->name)));
26681 return ira->codegen->invalid_instruction;
27536 return ira->codegen->invalid_inst_gen;
2668227537 }
26683 return ir_const_void(ira, &instruction->base);
27538 return ir_const_void(ira, &instruction->base.base);
2668427539}
2668527540
26686static IrInstruction *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira,
26687 IrInstructionCheckStatementIsVoid *instruction)
27541static IrInstGen *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira,
27542 IrInstSrcCheckStatementIsVoid *instruction)
2668827543{
26689 IrInstruction *statement_value = instruction->statement_value->child;
27544 IrInstGen *statement_value = instruction->statement_value->child;
2669027545 ZigType *statement_type = statement_value->value->type;
2669127546 if (type_is_invalid(statement_type))
26692 return ira->codegen->invalid_instruction;
27547 return ira->codegen->invalid_inst_gen;
2669327548
2669427549 if (statement_type->id != ZigTypeIdVoid && statement_type->id != ZigTypeIdUnreachable) {
26695 ir_add_error(ira, &instruction->base, buf_sprintf("expression value is ignored"));
27550 ir_add_error(ira, &instruction->base.base, buf_sprintf("expression value is ignored"));
2669627551 }
2669727552
26698 return ir_const_void(ira, &instruction->base);
27553 return ir_const_void(ira, &instruction->base.base);
2669927554}
2670027555
26701static IrInstruction *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic *instruction) {
26702 IrInstruction *msg = instruction->msg->child;
27556static IrInstGen *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstSrcPanic *instruction) {
27557 IrInstGen *msg = instruction->msg->child;
2670327558 if (type_is_invalid(msg->value->type))
2670427559 return ir_unreach_error(ira);
2670527560
26706 if (ir_should_inline(ira->new_irb.exec, instruction->base.scope)) {
26707 ir_add_error(ira, &instruction->base, buf_sprintf("encountered @panic at compile-time"));
27561 if (ir_should_inline(ira->old_irb.exec, instruction->base.base.scope)) {
27562 ir_add_error(ira, &instruction->base.base, buf_sprintf("encountered @panic at compile-time"));
2670827563 return ir_unreach_error(ira);
2670927564 }
2671027565
2671127566 ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
2671227567 true, false, PtrLenUnknown, 0, 0, 0, false);
2671327568 ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type);
26714 IrInstruction *casted_msg = ir_implicit_cast(ira, msg, str_type);
27569 IrInstGen *casted_msg = ir_implicit_cast(ira, msg, str_type);
2671527570 if (type_is_invalid(casted_msg->value->type))
2671627571 return ir_unreach_error(ira);
2671727572
26718 IrInstruction *new_instruction = ir_build_panic(&ira->new_irb, instruction->base.scope,
26719 instruction->base.source_node, casted_msg);
27573 IrInstGen *new_instruction = ir_build_panic_gen(ira, &instruction->base.base, casted_msg);
2672027574 return ir_finish_anal(ira, new_instruction);
2672127575}
2672227576
26723static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint32_t align_bytes, bool safety_check_on) {
27577static IrInstGen *ir_align_cast(IrAnalyze *ira, IrInstGen *target, uint32_t align_bytes, bool safety_check_on) {
2672427578 Error err;
2672527579
2672627580 ZigType *target_type = target->value->type;
......@@ -26732,7 +27586,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3
2673227586 if (target_type->id == ZigTypeIdPointer) {
2673327587 result_type = adjust_ptr_align(ira->codegen, target_type, align_bytes);
2673427588 if ((err = resolve_ptr_align(ira, target_type, &old_align_bytes)))
26735 return ira->codegen->invalid_instruction;
27589 return ira->codegen->invalid_inst_gen;
2673627590 } else if (target_type->id == ZigTypeIdFn) {
2673727591 FnTypeId fn_type_id = target_type->data.fn.fn_type_id;
2673827592 old_align_bytes = fn_type_id.alignment;
......@@ -26743,7 +27597,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3
2674327597 {
2674427598 ZigType *ptr_type = target_type->data.maybe.child_type;
2674527599 if ((err = resolve_ptr_align(ira, ptr_type, &old_align_bytes)))
26746 return ira->codegen->invalid_instruction;
27600 return ira->codegen->invalid_inst_gen;
2674727601 ZigType *better_ptr_type = adjust_ptr_align(ira->codegen, ptr_type, align_bytes);
2674827602
2674927603 result_type = get_optional_type(ira->codegen, better_ptr_type);
......@@ -26758,47 +27612,44 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3
2675827612 } else if (is_slice(target_type)) {
2675927613 ZigType *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index]->type_entry;
2676027614 if ((err = resolve_ptr_align(ira, slice_ptr_type, &old_align_bytes)))
26761 return ira->codegen->invalid_instruction;
27615 return ira->codegen->invalid_inst_gen;
2676227616 ZigType *result_ptr_type = adjust_ptr_align(ira->codegen, slice_ptr_type, align_bytes);
2676327617 result_type = get_slice_type(ira->codegen, result_ptr_type);
2676427618 } else {
26765 ir_add_error(ira, target,
27619 ir_add_error(ira, &target->base,
2676627620 buf_sprintf("expected pointer or slice, found '%s'", buf_ptr(&target_type->name)));
26767 return ira->codegen->invalid_instruction;
27621 return ira->codegen->invalid_inst_gen;
2676827622 }
2676927623
2677027624 if (instr_is_comptime(target)) {
2677127625 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
2677227626 if (!val)
26773 return ira->codegen->invalid_instruction;
27627 return ira->codegen->invalid_inst_gen;
2677427628
2677527629 if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&
2677627630 val->data.x_ptr.data.hard_coded_addr.addr % align_bytes != 0)
2677727631 {
26778 ir_add_error(ira, target,
27632 ir_add_error(ira, &target->base,
2677927633 buf_sprintf("pointer address 0x%" ZIG_PRI_x64 " is not aligned to %" PRIu32 " bytes",
2678027634 val->data.x_ptr.data.hard_coded_addr.addr, align_bytes));
26781 return ira->codegen->invalid_instruction;
27635 return ira->codegen->invalid_inst_gen;
2678227636 }
2678327637
26784 IrInstruction *result = ir_const(ira, target, result_type);
27638 IrInstGen *result = ir_const(ira, &target->base, result_type);
2678527639 copy_const_val(result->value, val);
2678627640 result->value->type = result_type;
2678727641 return result;
2678827642 }
2678927643
26790 IrInstruction *result;
2679127644 if (safety_check_on && align_bytes > old_align_bytes && align_bytes != 1) {
26792 result = ir_build_align_cast(&ira->new_irb, target->scope, target->source_node, nullptr, target);
27645 return ir_build_align_cast_gen(ira, target->base.scope, target->base.source_node, target, result_type);
2679327646 } else {
26794 result = ir_build_cast(&ira->new_irb, target->scope, target->source_node, result_type, target, CastOpNoop);
27647 return ir_build_cast(ira, &target->base, result_type, target, CastOpNoop);
2679527648 }
26796 result->value->type = result_type;
26797 return result;
2679827649}
2679927650
26800static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *ptr,
26801 ZigType *dest_type, IrInstruction *dest_type_src, bool safety_check_on)
27651static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *ptr,
27652 ZigType *dest_type, IrInst *dest_type_src, bool safety_check_on)
2680227653{
2680327654 Error err;
2680427655
......@@ -26814,44 +27665,44 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
2681427665
2681527666 ZigType *src_ptr_type = get_src_ptr_type(src_type);
2681627667 if (src_ptr_type == nullptr) {
26817 ir_add_error(ira, ptr, buf_sprintf("expected pointer, found '%s'", buf_ptr(&src_type->name)));
26818 return ira->codegen->invalid_instruction;
27668 ir_add_error(ira, &ptr->base, buf_sprintf("expected pointer, found '%s'", buf_ptr(&src_type->name)));
27669 return ira->codegen->invalid_inst_gen;
2681927670 }
2682027671
2682127672 ZigType *dest_ptr_type = get_src_ptr_type(dest_type);
2682227673 if (dest_ptr_type == nullptr) {
2682327674 ir_add_error(ira, dest_type_src,
2682427675 buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name)));
26825 return ira->codegen->invalid_instruction;
27676 return ira->codegen->invalid_inst_gen;
2682627677 }
2682727678
2682827679 if (get_ptr_const(src_type) && !get_ptr_const(dest_type)) {
2682927680 ir_add_error(ira, source_instr, buf_sprintf("cast discards const qualifier"));
26830 return ira->codegen->invalid_instruction;
27681 return ira->codegen->invalid_inst_gen;
2683127682 }
2683227683 uint32_t src_align_bytes;
2683327684 if ((err = resolve_ptr_align(ira, src_type, &src_align_bytes)))
26834 return ira->codegen->invalid_instruction;
27685 return ira->codegen->invalid_inst_gen;
2683527686
2683627687 uint32_t dest_align_bytes;
2683727688 if ((err = resolve_ptr_align(ira, dest_type, &dest_align_bytes)))
26838 return ira->codegen->invalid_instruction;
27689 return ira->codegen->invalid_inst_gen;
2683927690
2684027691 if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown)))
26841 return ira->codegen->invalid_instruction;
27692 return ira->codegen->invalid_inst_gen;
2684227693
2684327694 if ((err = type_resolve(ira->codegen, src_type, ResolveStatusZeroBitsKnown)))
26844 return ira->codegen->invalid_instruction;
27695 return ira->codegen->invalid_inst_gen;
2684527696
2684627697 if (type_has_bits(dest_type) && !type_has_bits(src_type)) {
2684727698 ErrorMsg *msg = ir_add_error(ira, source_instr,
2684827699 buf_sprintf("'%s' and '%s' do not have the same in-memory representation",
2684927700 buf_ptr(&src_type->name), buf_ptr(&dest_type->name)));
26850 add_error_note(ira->codegen, msg, ptr->source_node,
27701 add_error_note(ira->codegen, msg, ptr->base.source_node,
2685127702 buf_sprintf("'%s' has no in-memory bits", buf_ptr(&src_type->name)));
2685227703 add_error_note(ira->codegen, msg, dest_type_src->source_node,
2685327704 buf_sprintf("'%s' has in-memory bits", buf_ptr(&dest_type->name)));
26854 return ira->codegen->invalid_instruction;
27705 return ira->codegen->invalid_inst_gen;
2685527706 }
2685627707
2685727708 if (instr_is_comptime(ptr)) {
......@@ -26859,7 +27710,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
2685927710 UndefAllowed is_undef_allowed = dest_allows_addr_zero ? UndefOk : UndefBad;
2686027711 ZigValue *val = ir_resolve_const(ira, ptr, is_undef_allowed);
2686127712 if (!val)
26862 return ira->codegen->invalid_instruction;
27713 return ira->codegen->invalid_inst_gen;
2686327714
2686427715 if (value_is_comptime(val) && val->special != ConstValSpecialUndef) {
2686527716 bool is_addr_zero = val->data.x_ptr.special == ConstPtrSpecialNull ||
......@@ -26868,16 +27719,16 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
2686827719 if (is_addr_zero && !dest_allows_addr_zero) {
2686927720 ir_add_error(ira, source_instr,
2687027721 buf_sprintf("null pointer casted to type '%s'", buf_ptr(&dest_type->name)));
26871 return ira->codegen->invalid_instruction;
27722 return ira->codegen->invalid_inst_gen;
2687227723 }
2687327724 }
2687427725
26875 IrInstruction *result;
27726 IrInstGen *result;
2687627727 if (ptr->value->data.x_ptr.mut == ConstPtrMutInfer) {
2687727728 result = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on);
2687827729
2687927730 if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown)))
26880 return ira->codegen->invalid_instruction;
27731 return ira->codegen->invalid_inst_gen;
2688127732 } else {
2688227733 result = ir_const(ira, source_instr, dest_type);
2688327734 }
......@@ -26895,40 +27746,40 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
2689527746
2689627747 if (dest_align_bytes > src_align_bytes) {
2689727748 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("cast increases pointer alignment"));
26898 add_error_note(ira->codegen, msg, ptr->source_node,
27749 add_error_note(ira->codegen, msg, ptr->base.source_node,
2689927750 buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&src_type->name), src_align_bytes));
2690027751 add_error_note(ira->codegen, msg, dest_type_src->source_node,
2690127752 buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&dest_type->name), dest_align_bytes));
26902 return ira->codegen->invalid_instruction;
27753 return ira->codegen->invalid_inst_gen;
2690327754 }
2690427755
26905 IrInstruction *casted_ptr = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on);
27756 IrInstGen *casted_ptr = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on);
2690627757
2690727758 // Keep the bigger alignment, it can only help-
2690827759 // unless the target is zero bits.
26909 IrInstruction *result;
27760 IrInstGen *result;
2691027761 if (src_align_bytes > dest_align_bytes && type_has_bits(dest_type)) {
2691127762 result = ir_align_cast(ira, casted_ptr, src_align_bytes, false);
2691227763 if (type_is_invalid(result->value->type))
26913 return ira->codegen->invalid_instruction;
27764 return ira->codegen->invalid_inst_gen;
2691427765 } else {
2691527766 result = casted_ptr;
2691627767 }
2691727768 return result;
2691827769}
2691927770
26920static IrInstruction *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstructionPtrCastSrc *instruction) {
26921 IrInstruction *dest_type_value = instruction->dest_type->child;
27771static IrInstGen *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstSrcPtrCast *instruction) {
27772 IrInstGen *dest_type_value = instruction->dest_type->child;
2692227773 ZigType *dest_type = ir_resolve_type(ira, dest_type_value);
2692327774 if (type_is_invalid(dest_type))
26924 return ira->codegen->invalid_instruction;
27775 return ira->codegen->invalid_inst_gen;
2692527776
26926 IrInstruction *ptr = instruction->ptr->child;
27777 IrInstGen *ptr = instruction->ptr->child;
2692727778 ZigType *src_type = ptr->value->type;
2692827779 if (type_is_invalid(src_type))
26929 return ira->codegen->invalid_instruction;
27780 return ira->codegen->invalid_inst_gen;
2693027781
26931 return ir_analyze_ptr_cast(ira, &instruction->base, ptr, dest_type, dest_type_value,
27782 return ir_analyze_ptr_cast(ira, &instruction->base.base, ptr, dest_type, &dest_type_value->base,
2693227783 instruction->safety_check_on);
2693327784}
2693427785
......@@ -27259,7 +28110,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
2725928110 zig_unreachable();
2726028111}
2726128112
27262static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
28113static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value,
2726328114 ZigType *dest_type)
2726428115{
2726528116 Error err;
......@@ -27275,14 +28126,14 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_
2727528126 buf_sprintf("cannot cast a value of type '%s'", buf_ptr(&dest_type->name)));
2727628127 add_error_note(ira->codegen, msg, source_instr->source_node,
2727728128 buf_sprintf("use @intToEnum for type coercion"));
27278 return ira->codegen->invalid_instruction;
28129 return ira->codegen->invalid_inst_gen;
2727928130 }
2728028131
2728128132 if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusSizeKnown)))
27282 return ira->codegen->invalid_instruction;
28133 return ira->codegen->invalid_inst_gen;
2728328134
2728428135 if ((err = type_resolve(ira->codegen, src_type, ResolveStatusSizeKnown)))
27285 return ira->codegen->invalid_instruction;
28136 return ira->codegen->invalid_inst_gen;
2728628137
2728728138 uint64_t dest_size_bytes = type_size(ira->codegen, dest_type);
2728828139 uint64_t src_size_bytes = type_size(ira->codegen, src_type);
......@@ -27291,7 +28142,7 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_
2729128142 buf_sprintf("destination type '%s' has size %" ZIG_PRI_u64 " but source type '%s' has size %" ZIG_PRI_u64,
2729228143 buf_ptr(&dest_type->name), dest_size_bytes,
2729328144 buf_ptr(&src_type->name), src_size_bytes));
27294 return ira->codegen->invalid_instruction;
28145 return ira->codegen->invalid_inst_gen;
2729528146 }
2729628147
2729728148 uint64_t dest_size_bits = type_size_bits(ira->codegen, dest_type);
......@@ -27301,26 +28152,26 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_
2730128152 buf_sprintf("destination type '%s' has %" ZIG_PRI_u64 " bits but source type '%s' has %" ZIG_PRI_u64 " bits",
2730228153 buf_ptr(&dest_type->name), dest_size_bits,
2730328154 buf_ptr(&src_type->name), src_size_bits));
27304 return ira->codegen->invalid_instruction;
28155 return ira->codegen->invalid_inst_gen;
2730528156 }
2730628157
2730728158 if (instr_is_comptime(value)) {
2730828159 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
2730928160 if (!val)
27310 return ira->codegen->invalid_instruction;
28161 return ira->codegen->invalid_inst_gen;
2731128162
27312 IrInstruction *result = ir_const(ira, source_instr, dest_type);
28163 IrInstGen *result = ir_const(ira, source_instr, dest_type);
2731328164 uint8_t *buf = allocate_nonzero<uint8_t>(src_size_bytes);
2731428165 buf_write_value_bytes(ira->codegen, buf, val);
2731528166 if ((err = buf_read_value_bytes(ira, ira->codegen, source_instr->source_node, buf, result->value)))
27316 return ira->codegen->invalid_instruction;
28167 return ira->codegen->invalid_inst_gen;
2731728168 return result;
2731828169 }
2731928170
2732028171 return ir_build_bit_cast_gen(ira, source_instr, value, dest_type);
2732128172}
2732228173
27323static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
28174static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target,
2732428175 ZigType *ptr_type)
2732528176{
2732628177 Error err;
......@@ -27328,136 +28179,128 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc
2732828179 ir_assert(get_src_ptr_type(ptr_type) != nullptr, source_instr);
2732928180 ir_assert(type_has_bits(ptr_type), source_instr);
2733028181
27331 IrInstruction *casted_int = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_usize);
28182 IrInstGen *casted_int = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_usize);
2733228183 if (type_is_invalid(casted_int->value->type))
27333 return ira->codegen->invalid_instruction;
28184 return ira->codegen->invalid_inst_gen;
2733428185
2733528186 if (instr_is_comptime(casted_int)) {
2733628187 ZigValue *val = ir_resolve_const(ira, casted_int, UndefBad);
2733728188 if (!val)
27338 return ira->codegen->invalid_instruction;
28189 return ira->codegen->invalid_inst_gen;
2733928190
2734028191 uint64_t addr = bigint_as_u64(&val->data.x_bigint);
2734128192 if (!ptr_allows_addr_zero(ptr_type) && addr == 0) {
2734228193 ir_add_error(ira, source_instr,
2734328194 buf_sprintf("pointer type '%s' does not allow address zero", buf_ptr(&ptr_type->name)));
27344 return ira->codegen->invalid_instruction;
28195 return ira->codegen->invalid_inst_gen;
2734528196 }
2734628197
2734728198 uint32_t align_bytes;
2734828199 if ((err = resolve_ptr_align(ira, ptr_type, &align_bytes)))
27349 return ira->codegen->invalid_instruction;
28200 return ira->codegen->invalid_inst_gen;
2735028201
2735128202 if (addr != 0 && addr % align_bytes != 0) {
2735228203 ir_add_error(ira, source_instr,
2735328204 buf_sprintf("pointer type '%s' requires aligned address",
2735428205 buf_ptr(&ptr_type->name)));
27355 return ira->codegen->invalid_instruction;
28206 return ira->codegen->invalid_inst_gen;
2735628207 }
2735728208
27358 IrInstruction *result = ir_const(ira, source_instr, ptr_type);
28209 IrInstGen *result = ir_const(ira, source_instr, ptr_type);
2735928210 result->value->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
2736028211 result->value->data.x_ptr.mut = ConstPtrMutRuntimeVar;
2736128212 result->value->data.x_ptr.data.hard_coded_addr.addr = addr;
2736228213 return result;
2736328214 }
2736428215
27365 IrInstruction *result = ir_build_int_to_ptr(&ira->new_irb, source_instr->scope,
27366 source_instr->source_node, nullptr, casted_int);
27367 result->value->type = ptr_type;
27368 return result;
28216 return ir_build_int_to_ptr_gen(ira, source_instr->scope, source_instr->source_node, casted_int, ptr_type);
2736928217}
2737028218
27371static IrInstruction *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstructionIntToPtr *instruction) {
28219static IrInstGen *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstSrcIntToPtr *instruction) {
2737228220 Error err;
27373 IrInstruction *dest_type_value = instruction->dest_type->child;
28221 IrInstGen *dest_type_value = instruction->dest_type->child;
2737428222 ZigType *dest_type = ir_resolve_type(ira, dest_type_value);
2737528223 if (type_is_invalid(dest_type))
27376 return ira->codegen->invalid_instruction;
28224 return ira->codegen->invalid_inst_gen;
2737728225
2737828226 // We explicitly check for the size, so we can use get_src_ptr_type
2737928227 if (get_src_ptr_type(dest_type) == nullptr) {
27380 ir_add_error(ira, dest_type_value, buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name)));
27381 return ira->codegen->invalid_instruction;
28228 ir_add_error(ira, &dest_type_value->base, buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name)));
28229 return ira->codegen->invalid_inst_gen;
2738228230 }
2738328231
2738428232 bool has_bits;
2738528233 if ((err = type_has_bits2(ira->codegen, dest_type, &has_bits)))
27386 return ira->codegen->invalid_instruction;
28234 return ira->codegen->invalid_inst_gen;
2738728235
2738828236 if (!has_bits) {
27389 ir_add_error(ira, dest_type_value,
28237 ir_add_error(ira, &dest_type_value->base,
2739028238 buf_sprintf("type '%s' has 0 bits and cannot store information", buf_ptr(&dest_type->name)));
27391 return ira->codegen->invalid_instruction;
28239 return ira->codegen->invalid_inst_gen;
2739228240 }
2739328241
27394 IrInstruction *target = instruction->target->child;
28242 IrInstGen *target = instruction->target->child;
2739528243 if (type_is_invalid(target->value->type))
27396 return ira->codegen->invalid_instruction;
28244 return ira->codegen->invalid_inst_gen;
2739728245
27398 return ir_analyze_int_to_ptr(ira, &instruction->base, target, dest_type);
28246 return ir_analyze_int_to_ptr(ira, &instruction->base.base, target, dest_type);
2739928247}
2740028248
27401static IrInstruction *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
27402 IrInstructionDeclRef *instruction)
27403{
27404 IrInstruction *ref_instruction = ir_analyze_decl_ref(ira, &instruction->base, instruction->tld);
28249static IrInstGen *ir_analyze_instruction_decl_ref(IrAnalyze *ira, IrInstSrcDeclRef *instruction) {
28250 IrInstGen *ref_instruction = ir_analyze_decl_ref(ira, &instruction->base.base, instruction->tld);
2740528251 if (type_is_invalid(ref_instruction->value->type)) {
27406 return ira->codegen->invalid_instruction;
28252 return ira->codegen->invalid_inst_gen;
2740728253 }
2740828254
2740928255 if (instruction->lval == LValPtr) {
2741028256 return ref_instruction;
2741128257 } else {
27412 return ir_get_deref(ira, &instruction->base, ref_instruction, nullptr);
28258 return ir_get_deref(ira, &instruction->base.base, ref_instruction, nullptr);
2741328259 }
2741428260}
2741528261
27416static IrInstruction *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstructionPtrToInt *instruction) {
28262static IrInstGen *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstSrcPtrToInt *instruction) {
2741728263 Error err;
27418 IrInstruction *target = instruction->target->child;
28264 IrInstGen *target = instruction->target->child;
2741928265 if (type_is_invalid(target->value->type))
27420 return ira->codegen->invalid_instruction;
28266 return ira->codegen->invalid_inst_gen;
2742128267
2742228268 ZigType *usize = ira->codegen->builtin_types.entry_usize;
2742328269
2742428270 // We check size explicitly so we can use get_src_ptr_type here.
2742528271 if (get_src_ptr_type(target->value->type) == nullptr) {
27426 ir_add_error(ira, target,
28272 ir_add_error(ira, &target->base,
2742728273 buf_sprintf("expected pointer, found '%s'", buf_ptr(&target->value->type->name)));
27428 return ira->codegen->invalid_instruction;
28274 return ira->codegen->invalid_inst_gen;
2742928275 }
2743028276
2743128277 bool has_bits;
2743228278 if ((err = type_has_bits2(ira->codegen, target->value->type, &has_bits)))
27433 return ira->codegen->invalid_instruction;
28279 return ira->codegen->invalid_inst_gen;
2743428280
2743528281 if (!has_bits) {
27436 ir_add_error(ira, target,
28282 ir_add_error(ira, &target->base,
2743728283 buf_sprintf("pointer to size 0 type has no address"));
27438 return ira->codegen->invalid_instruction;
28284 return ira->codegen->invalid_inst_gen;
2743928285 }
2744028286
2744128287 if (instr_is_comptime(target)) {
2744228288 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
2744328289 if (!val)
27444 return ira->codegen->invalid_instruction;
28290 return ira->codegen->invalid_inst_gen;
2744528291 if (val->type->id == ZigTypeIdPointer && val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
27446 IrInstruction *result = ir_const(ira, &instruction->base, usize);
28292 IrInstGen *result = ir_const(ira, &instruction->base.base, usize);
2744728293 bigint_init_unsigned(&result->value->data.x_bigint, val->data.x_ptr.data.hard_coded_addr.addr);
2744828294 result->value->type = usize;
2744928295 return result;
2745028296 }
2745128297 }
2745228298
27453 IrInstruction *result = ir_build_ptr_to_int(&ira->new_irb, instruction->base.scope,
27454 instruction->base.source_node, target);
27455 result->value->type = usize;
27456 return result;
28299 return ir_build_ptr_to_int_gen(ira, &instruction->base.base, target);
2745728300}
2745828301
27459static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstructionPtrType *instruction) {
27460 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type);
28302static IrInstGen *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstSrcPtrType *instruction) {
28303 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);
2746128304 result->value->special = ConstValSpecialLazy;
2746228305
2746328306 LazyValuePtrType *lazy_ptr_type = allocate<LazyValuePtrType>(1, "LazyValuePtrType");
......@@ -27468,17 +28311,17 @@ static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruct
2746828311 if (instruction->sentinel != nullptr) {
2746928312 lazy_ptr_type->sentinel = instruction->sentinel->child;
2747028313 if (ir_resolve_const(ira, lazy_ptr_type->sentinel, LazyOk) == nullptr)
27471 return ira->codegen->invalid_instruction;
28314 return ira->codegen->invalid_inst_gen;
2747228315 }
2747328316
2747428317 lazy_ptr_type->elem_type = instruction->child_type->child;
2747528318 if (ir_resolve_type_lazy(ira, lazy_ptr_type->elem_type) == nullptr)
27476 return ira->codegen->invalid_instruction;
28319 return ira->codegen->invalid_inst_gen;
2747728320
2747828321 if (instruction->align_value != nullptr) {
2747928322 lazy_ptr_type->align_inst = instruction->align_value->child;
2748028323 if (ir_resolve_const(ira, lazy_ptr_type->align_inst, LazyOk) == nullptr)
27481 return ira->codegen->invalid_instruction;
28324 return ira->codegen->invalid_inst_gen;
2748228325 }
2748328326
2748428327 lazy_ptr_type->ptr_len = instruction->ptr_len;
......@@ -27491,10 +28334,10 @@ static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruct
2749128334 return result;
2749228335}
2749328336
27494static IrInstruction *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstructionAlignCast *instruction) {
27495 IrInstruction *target = instruction->target->child;
28337static IrInstGen *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstSrcAlignCast *instruction) {
28338 IrInstGen *target = instruction->target->child;
2749628339 if (type_is_invalid(target->value->type))
27497 return ira->codegen->invalid_instruction;
28340 return ira->codegen->invalid_inst_gen;
2749828341
2749928342 ZigType *elem_type = nullptr;
2750028343 if (is_slice(target->value->type)) {
......@@ -27505,192 +28348,192 @@ static IrInstruction *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstru
2750528348 }
2750628349
2750728350 uint32_t align_bytes;
27508 IrInstruction *align_bytes_inst = instruction->align_bytes->child;
28351 IrInstGen *align_bytes_inst = instruction->align_bytes->child;
2750928352 if (!ir_resolve_align(ira, align_bytes_inst, elem_type, &align_bytes))
27510 return ira->codegen->invalid_instruction;
28353 return ira->codegen->invalid_inst_gen;
2751128354
27512 IrInstruction *result = ir_align_cast(ira, target, align_bytes, true);
28355 IrInstGen *result = ir_align_cast(ira, target, align_bytes, true);
2751328356 if (type_is_invalid(result->value->type))
27514 return ira->codegen->invalid_instruction;
28357 return ira->codegen->invalid_inst_gen;
2751528358
2751628359 return result;
2751728360}
2751828361
27519static IrInstruction *ir_analyze_instruction_opaque_type(IrAnalyze *ira, IrInstructionOpaqueType *instruction) {
28362static IrInstGen *ir_analyze_instruction_opaque_type(IrAnalyze *ira, IrInstSrcOpaqueType *instruction) {
2752028363 Buf *bare_name = buf_alloc();
27521 Buf *full_name = get_anon_type_name(ira->codegen, ira->new_irb.exec, "opaque",
27522 instruction->base.scope, instruction->base.source_node, bare_name);
27523 ZigType *result_type = get_opaque_type(ira->codegen, instruction->base.scope, instruction->base.source_node,
27524 buf_ptr(full_name), bare_name);
27525 return ir_const_type(ira, &instruction->base, result_type);
28364 Buf *full_name = get_anon_type_name(ira->codegen, ira->old_irb.exec, "opaque",
28365 instruction->base.base.scope, instruction->base.base.source_node, bare_name);
28366 ZigType *result_type = get_opaque_type(ira->codegen, instruction->base.base.scope,
28367 instruction->base.base.source_node, buf_ptr(full_name), bare_name);
28368 return ir_const_type(ira, &instruction->base.base, result_type);
2752628369}
2752728370
27528static IrInstruction *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, IrInstructionSetAlignStack *instruction) {
28371static IrInstGen *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, IrInstSrcSetAlignStack *instruction) {
2752928372 uint32_t align_bytes;
27530 IrInstruction *align_bytes_inst = instruction->align_bytes->child;
28373 IrInstGen *align_bytes_inst = instruction->align_bytes->child;
2753128374 if (!ir_resolve_align(ira, align_bytes_inst, nullptr, &align_bytes))
27532 return ira->codegen->invalid_instruction;
28375 return ira->codegen->invalid_inst_gen;
2753328376
2753428377 if (align_bytes > 256) {
27535 ir_add_error(ira, &instruction->base, buf_sprintf("attempt to @setAlignStack(%" PRIu32 "); maximum is 256", align_bytes));
27536 return ira->codegen->invalid_instruction;
28378 ir_add_error(ira, &instruction->base.base, buf_sprintf("attempt to @setAlignStack(%" PRIu32 "); maximum is 256", align_bytes));
28379 return ira->codegen->invalid_inst_gen;
2753728380 }
2753828381
27539 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
28382 ZigFn *fn_entry = ira->new_irb.exec->fn_entry;
2754028383 if (fn_entry == nullptr) {
27541 ir_add_error(ira, &instruction->base, buf_sprintf("@setAlignStack outside function"));
27542 return ira->codegen->invalid_instruction;
28384 ir_add_error(ira, &instruction->base.base, buf_sprintf("@setAlignStack outside function"));
28385 return ira->codegen->invalid_inst_gen;
2754328386 }
2754428387 if (fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionNaked) {
27545 ir_add_error(ira, &instruction->base, buf_sprintf("@setAlignStack in naked function"));
27546 return ira->codegen->invalid_instruction;
28388 ir_add_error(ira, &instruction->base.base, buf_sprintf("@setAlignStack in naked function"));
28389 return ira->codegen->invalid_inst_gen;
2754728390 }
2754828391
2754928392 if (fn_entry->fn_inline == FnInlineAlways) {
27550 ir_add_error(ira, &instruction->base, buf_sprintf("@setAlignStack in inline function"));
27551 return ira->codegen->invalid_instruction;
28393 ir_add_error(ira, &instruction->base.base, buf_sprintf("@setAlignStack in inline function"));
28394 return ira->codegen->invalid_inst_gen;
2755228395 }
2755328396
2755428397 if (fn_entry->set_alignstack_node != nullptr) {
27555 ErrorMsg *msg = ir_add_error_node(ira, instruction->base.source_node,
28398 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base,
2755628399 buf_sprintf("alignstack set twice"));
2755728400 add_error_note(ira->codegen, msg, fn_entry->set_alignstack_node, buf_sprintf("first set here"));
27558 return ira->codegen->invalid_instruction;
28401 return ira->codegen->invalid_inst_gen;
2755928402 }
2756028403
27561 fn_entry->set_alignstack_node = instruction->base.source_node;
28404 fn_entry->set_alignstack_node = instruction->base.base.source_node;
2756228405 fn_entry->alignstack_value = align_bytes;
2756328406
27564 return ir_const_void(ira, &instruction->base);
28407 return ir_const_void(ira, &instruction->base.base);
2756528408}
2756628409
27567static IrInstruction *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstructionArgType *instruction) {
27568 IrInstruction *fn_type_inst = instruction->fn_type->child;
28410static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgType *instruction) {
28411 IrInstGen *fn_type_inst = instruction->fn_type->child;
2756928412 ZigType *fn_type = ir_resolve_type(ira, fn_type_inst);
2757028413 if (type_is_invalid(fn_type))
27571 return ira->codegen->invalid_instruction;
28414 return ira->codegen->invalid_inst_gen;
2757228415
27573 IrInstruction *arg_index_inst = instruction->arg_index->child;
28416 IrInstGen *arg_index_inst = instruction->arg_index->child;
2757428417 uint64_t arg_index;
2757528418 if (!ir_resolve_usize(ira, arg_index_inst, &arg_index))
27576 return ira->codegen->invalid_instruction;
28419 return ira->codegen->invalid_inst_gen;
2757728420
2757828421 if (fn_type->id == ZigTypeIdBoundFn) {
2757928422 fn_type = fn_type->data.bound_fn.fn_type;
2758028423 arg_index += 1;
2758128424 }
2758228425 if (fn_type->id != ZigTypeIdFn) {
27583 ir_add_error(ira, fn_type_inst, buf_sprintf("expected function, found '%s'", buf_ptr(&fn_type->name)));
27584 return ira->codegen->invalid_instruction;
28426 ir_add_error(ira, &fn_type_inst->base, buf_sprintf("expected function, found '%s'", buf_ptr(&fn_type->name)));
28427 return ira->codegen->invalid_inst_gen;
2758528428 }
2758628429
2758728430 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;
2758828431 if (arg_index >= fn_type_id->param_count) {
2758928432 if (instruction->allow_var) {
2759028433 // TODO remove this with var args
27591 return ir_const_type(ira, &instruction->base, ira->codegen->builtin_types.entry_var);
28434 return ir_const_type(ira, &instruction->base.base, ira->codegen->builtin_types.entry_var);
2759228435 }
27593 ir_add_error(ira, arg_index_inst,
28436 ir_add_error(ira, &arg_index_inst->base,
2759428437 buf_sprintf("arg index %" ZIG_PRI_u64 " out of bounds; '%s' has %" ZIG_PRI_usize " arguments",
2759528438 arg_index, buf_ptr(&fn_type->name), fn_type_id->param_count));
27596 return ira->codegen->invalid_instruction;
28439 return ira->codegen->invalid_inst_gen;
2759728440 }
2759828441
2759928442 ZigType *result_type = fn_type_id->param_info[arg_index].type;
2760028443 if (result_type == nullptr) {
2760128444 // Args are only unresolved if our function is generic.
27602 ir_assert(fn_type->data.fn.is_generic, &instruction->base);
28445 ir_assert(fn_type->data.fn.is_generic, &instruction->base.base);
2760328446
2760428447 if (instruction->allow_var) {
27605 return ir_const_type(ira, &instruction->base, ira->codegen->builtin_types.entry_var);
28448 return ir_const_type(ira, &instruction->base.base, ira->codegen->builtin_types.entry_var);
2760628449 } else {
27607 ir_add_error(ira, arg_index_inst,
28450 ir_add_error(ira, &arg_index_inst->base,
2760828451 buf_sprintf("@ArgType could not resolve the type of arg %" ZIG_PRI_u64 " because '%s' is generic",
2760928452 arg_index, buf_ptr(&fn_type->name)));
27610 return ira->codegen->invalid_instruction;
28453 return ira->codegen->invalid_inst_gen;
2761128454 }
2761228455 }
27613 return ir_const_type(ira, &instruction->base, result_type);
28456 return ir_const_type(ira, &instruction->base.base, result_type);
2761428457}
2761528458
27616static IrInstruction *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstructionTagType *instruction) {
28459static IrInstGen *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstSrcTagType *instruction) {
2761728460 Error err;
27618 IrInstruction *target_inst = instruction->target->child;
28461 IrInstGen *target_inst = instruction->target->child;
2761928462 ZigType *enum_type = ir_resolve_type(ira, target_inst);
2762028463 if (type_is_invalid(enum_type))
27621 return ira->codegen->invalid_instruction;
28464 return ira->codegen->invalid_inst_gen;
2762228465
2762328466 if (enum_type->id == ZigTypeIdEnum) {
2762428467 if ((err = type_resolve(ira->codegen, enum_type, ResolveStatusSizeKnown)))
27625 return ira->codegen->invalid_instruction;
28468 return ira->codegen->invalid_inst_gen;
2762628469
27627 return ir_const_type(ira, &instruction->base, enum_type->data.enumeration.tag_int_type);
28470 return ir_const_type(ira, &instruction->base.base, enum_type->data.enumeration.tag_int_type);
2762828471 } else if (enum_type->id == ZigTypeIdUnion) {
27629 ZigType *tag_type = ir_resolve_union_tag_type(ira, instruction->target, enum_type);
28472 ZigType *tag_type = ir_resolve_union_tag_type(ira, instruction->target->base.source_node, enum_type);
2763028473 if (type_is_invalid(tag_type))
27631 return ira->codegen->invalid_instruction;
27632 return ir_const_type(ira, &instruction->base, tag_type);
28474 return ira->codegen->invalid_inst_gen;
28475 return ir_const_type(ira, &instruction->base.base, tag_type);
2763328476 } else {
27634 ir_add_error(ira, target_inst, buf_sprintf("expected enum or union, found '%s'",
28477 ir_add_error(ira, &target_inst->base, buf_sprintf("expected enum or union, found '%s'",
2763528478 buf_ptr(&enum_type->name)));
27636 return ira->codegen->invalid_instruction;
28479 return ira->codegen->invalid_inst_gen;
2763728480 }
2763828481}
2763928482
27640static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op) {
28483static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op) {
2764128484 ZigType *operand_type = ir_resolve_type(ira, op);
2764228485 if (type_is_invalid(operand_type))
2764328486 return ira->codegen->builtin_types.entry_invalid;
2764428487
2764528488 if (operand_type->id == ZigTypeIdInt) {
2764628489 if (operand_type->data.integral.bit_count < 8) {
27647 ir_add_error(ira, op,
28490 ir_add_error(ira, &op->base,
2764828491 buf_sprintf("expected integer type 8 bits or larger, found %" PRIu32 "-bit integer type",
2764928492 operand_type->data.integral.bit_count));
2765028493 return ira->codegen->builtin_types.entry_invalid;
2765128494 }
2765228495 uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch);
2765328496 if (operand_type->data.integral.bit_count > max_atomic_bits) {
27654 ir_add_error(ira, op,
28497 ir_add_error(ira, &op->base,
2765528498 buf_sprintf("expected %" PRIu32 "-bit integer type or smaller, found %" PRIu32 "-bit integer type",
2765628499 max_atomic_bits, operand_type->data.integral.bit_count));
2765728500 return ira->codegen->builtin_types.entry_invalid;
2765828501 }
2765928502 if (!is_power_of_2(operand_type->data.integral.bit_count)) {
27660 ir_add_error(ira, op,
28503 ir_add_error(ira, &op->base,
2766128504 buf_sprintf("%" PRIu32 "-bit integer type is not a power of 2", operand_type->data.integral.bit_count));
2766228505 return ira->codegen->builtin_types.entry_invalid;
2766328506 }
2766428507 } else if (operand_type->id == ZigTypeIdEnum) {
2766528508 ZigType *int_type = operand_type->data.enumeration.tag_int_type;
2766628509 if (int_type->data.integral.bit_count < 8) {
27667 ir_add_error(ira, op,
28510 ir_add_error(ira, &op->base,
2766828511 buf_sprintf("expected enum tag type 8 bits or larger, found %" PRIu32 "-bit tag type",
2766928512 int_type->data.integral.bit_count));
2767028513 return ira->codegen->builtin_types.entry_invalid;
2767128514 }
2767228515 uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch);
2767328516 if (int_type->data.integral.bit_count > max_atomic_bits) {
27674 ir_add_error(ira, op,
28517 ir_add_error(ira, &op->base,
2767528518 buf_sprintf("expected %" PRIu32 "-bit enum tag type or smaller, found %" PRIu32 "-bit tag type",
2767628519 max_atomic_bits, int_type->data.integral.bit_count));
2767728520 return ira->codegen->builtin_types.entry_invalid;
2767828521 }
2767928522 if (!is_power_of_2(int_type->data.integral.bit_count)) {
27680 ir_add_error(ira, op,
28523 ir_add_error(ira, &op->base,
2768128524 buf_sprintf("%" PRIu32 "-bit enum tag type is not a power of 2", int_type->data.integral.bit_count));
2768228525 return ira->codegen->builtin_types.entry_invalid;
2768328526 }
2768428527 } else if (operand_type->id == ZigTypeIdFloat) {
2768528528 uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch);
2768628529 if (operand_type->data.floating.bit_count > max_atomic_bits) {
27687 ir_add_error(ira, op,
28530 ir_add_error(ira, &op->base,
2768828531 buf_sprintf("expected %" PRIu32 "-bit float or smaller, found %" PRIu32 "-bit float",
2768928532 max_atomic_bits, (uint32_t) operand_type->data.floating.bit_count));
2769028533 return ira->codegen->builtin_types.entry_invalid;
2769128534 }
2769228535 } else if (get_codegen_ptr_type(operand_type) == nullptr) {
27693 ir_add_error(ira, op,
28536 ir_add_error(ira, &op->base,
2769428537 buf_sprintf("expected integer, float, enum or pointer type, found '%s'", buf_ptr(&operand_type->name)));
2769528538 return ira->codegen->builtin_types.entry_invalid;
2769628539 }
......@@ -27698,172 +28541,146 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op
2769828541 return operand_type;
2769928542}
2770028543
27701static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstructionAtomicRmw *instruction) {
28544static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAtomicRmw *instruction) {
2770228545 ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child);
2770328546 if (type_is_invalid(operand_type))
27704 return ira->codegen->invalid_instruction;
28547 return ira->codegen->invalid_inst_gen;
2770528548
27706 IrInstruction *ptr_inst = instruction->ptr->child;
28549 IrInstGen *ptr_inst = instruction->ptr->child;
2770728550 if (type_is_invalid(ptr_inst->value->type))
27708 return ira->codegen->invalid_instruction;
28551 return ira->codegen->invalid_inst_gen;
2770928552
2771028553 // TODO let this be volatile
2771128554 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);
27712 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);
28555 IrInstGen *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);
2771328556 if (type_is_invalid(casted_ptr->value->type))
27714 return ira->codegen->invalid_instruction;
28557 return ira->codegen->invalid_inst_gen;
2771528558
2771628559 AtomicRmwOp op;
27717 if (instruction->op == nullptr) {
27718 op = instruction->resolved_op;
27719 } else {
27720 if (!ir_resolve_atomic_rmw_op(ira, instruction->op->child, &op)) {
27721 return ira->codegen->invalid_instruction;
27722 }
28560 if (!ir_resolve_atomic_rmw_op(ira, instruction->op->child, &op)) {
28561 return ira->codegen->invalid_inst_gen;
2772328562 }
2772428563
2772528564 if (operand_type->id == ZigTypeIdEnum && op != AtomicRmwOp_xchg) {
27726 ir_add_error(ira, instruction->op,
28565 ir_add_error(ira, &instruction->op->base,
2772728566 buf_sprintf("@atomicRmw on enum only works with .Xchg"));
27728 return ira->codegen->invalid_instruction;
28567 return ira->codegen->invalid_inst_gen;
2772928568 } else if (operand_type->id == ZigTypeIdFloat && op > AtomicRmwOp_sub) {
27730 ir_add_error(ira, instruction->op,
28569 ir_add_error(ira, &instruction->op->base,
2773128570 buf_sprintf("@atomicRmw with float only works with .Xchg, .Add and .Sub"));
27732 return ira->codegen->invalid_instruction;
28571 return ira->codegen->invalid_inst_gen;
2773328572 }
2773428573
27735 IrInstruction *operand = instruction->operand->child;
28574 IrInstGen *operand = instruction->operand->child;
2773628575 if (type_is_invalid(operand->value->type))
27737 return ira->codegen->invalid_instruction;
28576 return ira->codegen->invalid_inst_gen;
2773828577
27739 IrInstruction *casted_operand = ir_implicit_cast(ira, operand, operand_type);
28578 IrInstGen *casted_operand = ir_implicit_cast(ira, operand, operand_type);
2774028579 if (type_is_invalid(casted_operand->value->type))
27741 return ira->codegen->invalid_instruction;
28580 return ira->codegen->invalid_inst_gen;
2774228581
2774328582 AtomicOrder ordering;
27744 if (instruction->ordering == nullptr) {
27745 ordering = instruction->resolved_ordering;
27746 } else {
27747 if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering))
27748 return ira->codegen->invalid_instruction;
27749 if (ordering == AtomicOrderUnordered) {
27750 ir_add_error(ira, instruction->ordering,
27751 buf_sprintf("@atomicRmw atomic ordering must not be Unordered"));
27752 return ira->codegen->invalid_instruction;
27753 }
28583 if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering))
28584 return ira->codegen->invalid_inst_gen;
28585 if (ordering == AtomicOrderUnordered) {
28586 ir_add_error(ira, &instruction->ordering->base,
28587 buf_sprintf("@atomicRmw atomic ordering must not be Unordered"));
28588 return ira->codegen->invalid_inst_gen;
2775428589 }
2775528590
2775628591 if (instr_is_comptime(casted_operand) && instr_is_comptime(casted_ptr) && casted_ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar)
2775728592 {
27758 zig_panic("TODO compile-time execution of atomicRmw");
28593 ir_add_error(ira, &instruction->base.base,
28594 buf_sprintf("compiler bug: TODO compile-time execution of @atomicRmw"));
28595 return ira->codegen->invalid_inst_gen;
2775928596 }
2776028597
27761 IrInstruction *result = ir_build_atomic_rmw(&ira->new_irb, instruction->base.scope,
27762 instruction->base.source_node, nullptr, casted_ptr, nullptr, casted_operand, nullptr,
27763 op, ordering);
27764 result->value->type = operand_type;
27765 return result;
28598 return ir_build_atomic_rmw_gen(ira, &instruction->base.base, casted_ptr, casted_operand, op,
28599 ordering, operand_type);
2776628600}
2776728601
27768static IrInstruction *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstructionAtomicLoad *instruction) {
28602static IrInstGen *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstSrcAtomicLoad *instruction) {
2776928603 ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child);
2777028604 if (type_is_invalid(operand_type))
27771 return ira->codegen->invalid_instruction;
28605 return ira->codegen->invalid_inst_gen;
2777228606
27773 IrInstruction *ptr_inst = instruction->ptr->child;
28607 IrInstGen *ptr_inst = instruction->ptr->child;
2777428608 if (type_is_invalid(ptr_inst->value->type))
27775 return ira->codegen->invalid_instruction;
28609 return ira->codegen->invalid_inst_gen;
2777628610
2777728611 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, true);
27778 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);
28612 IrInstGen *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);
2777928613 if (type_is_invalid(casted_ptr->value->type))
27780 return ira->codegen->invalid_instruction;
28614 return ira->codegen->invalid_inst_gen;
2778128615
2778228616 AtomicOrder ordering;
27783 if (instruction->ordering == nullptr) {
27784 ordering = instruction->resolved_ordering;
27785 } else {
27786 if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering))
27787 return ira->codegen->invalid_instruction;
27788 }
28617 if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering))
28618 return ira->codegen->invalid_inst_gen;
2778928619
2779028620 if (ordering == AtomicOrderRelease || ordering == AtomicOrderAcqRel) {
27791 ir_assert(instruction->ordering != nullptr, &instruction->base);
27792 ir_add_error(ira, instruction->ordering,
28621 ir_assert(instruction->ordering != nullptr, &instruction->base.base);
28622 ir_add_error(ira, &instruction->ordering->base,
2779328623 buf_sprintf("@atomicLoad atomic ordering must not be Release or AcqRel"));
27794 return ira->codegen->invalid_instruction;
28624 return ira->codegen->invalid_inst_gen;
2779528625 }
2779628626
2779728627 if (instr_is_comptime(casted_ptr)) {
27798 IrInstruction *result = ir_get_deref(ira, &instruction->base, casted_ptr, nullptr);
27799 ir_assert(result->value->type != nullptr, &instruction->base);
28628 IrInstGen *result = ir_get_deref(ira, &instruction->base.base, casted_ptr, nullptr);
28629 ir_assert(result->value->type != nullptr, &instruction->base.base);
2780028630 return result;
2780128631 }
2780228632
27803 IrInstruction *result = ir_build_atomic_load(&ira->new_irb, instruction->base.scope,
27804 instruction->base.source_node, nullptr, casted_ptr, nullptr, ordering);
27805 result->value->type = operand_type;
27806 return result;
28633 return ir_build_atomic_load_gen(ira, &instruction->base.base, casted_ptr, ordering, operand_type);
2780728634}
2780828635
27809static IrInstruction *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInstructionAtomicStore *instruction) {
28636static IrInstGen *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInstSrcAtomicStore *instruction) {
2781028637 ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child);
2781128638 if (type_is_invalid(operand_type))
27812 return ira->codegen->invalid_instruction;
28639 return ira->codegen->invalid_inst_gen;
2781328640
27814 IrInstruction *ptr_inst = instruction->ptr->child;
28641 IrInstGen *ptr_inst = instruction->ptr->child;
2781528642 if (type_is_invalid(ptr_inst->value->type))
27816 return ira->codegen->invalid_instruction;
28643 return ira->codegen->invalid_inst_gen;
2781728644
2781828645 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);
27819 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);
28646 IrInstGen *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);
2782028647 if (type_is_invalid(casted_ptr->value->type))
27821 return ira->codegen->invalid_instruction;
28648 return ira->codegen->invalid_inst_gen;
2782228649
27823 IrInstruction *value = instruction->value->child;
28650 IrInstGen *value = instruction->value->child;
2782428651 if (type_is_invalid(value->value->type))
27825 return ira->codegen->invalid_instruction;
28652 return ira->codegen->invalid_inst_gen;
2782628653
27827 IrInstruction *casted_value = ir_implicit_cast(ira, value, operand_type);
28654 IrInstGen *casted_value = ir_implicit_cast(ira, value, operand_type);
2782828655 if (type_is_invalid(casted_value->value->type))
27829 return ira->codegen->invalid_instruction;
28656 return ira->codegen->invalid_inst_gen;
2783028657
2783128658
2783228659 AtomicOrder ordering;
27833 if (instruction->ordering == nullptr) {
27834 ordering = instruction->resolved_ordering;
27835 } else {
27836 if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering))
27837 return ira->codegen->invalid_instruction;
27838 }
28660 if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering))
28661 return ira->codegen->invalid_inst_gen;
2783928662
2784028663 if (ordering == AtomicOrderAcquire || ordering == AtomicOrderAcqRel) {
27841 ir_assert(instruction->ordering != nullptr, &instruction->base);
27842 ir_add_error(ira, instruction->ordering,
28664 ir_assert(instruction->ordering != nullptr, &instruction->base.base);
28665 ir_add_error(ira, &instruction->ordering->base,
2784328666 buf_sprintf("@atomicStore atomic ordering must not be Acquire or AcqRel"));
27844 return ira->codegen->invalid_instruction;
28667 return ira->codegen->invalid_inst_gen;
2784528668 }
2784628669
2784728670 if (instr_is_comptime(casted_value) && instr_is_comptime(casted_ptr)) {
27848 IrInstruction *result = ir_analyze_store_ptr(ira, &instruction->base, casted_ptr, value, false);
28671 IrInstGen *result = ir_analyze_store_ptr(ira, &instruction->base.base, casted_ptr, value, false);
2784928672 result->value->type = ira->codegen->builtin_types.entry_void;
2785028673 return result;
2785128674 }
2785228675
27853 IrInstruction *result = ir_build_atomic_store(&ira->new_irb, instruction->base.scope,
27854 instruction->base.source_node, nullptr, casted_ptr, casted_value, nullptr, ordering);
27855 result->value->type = ira->codegen->builtin_types.entry_void;
27856 return result;
28676 return ir_build_atomic_store_gen(ira, &instruction->base.base, casted_ptr, casted_value, ordering);
2785728677}
2785828678
27859static IrInstruction *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstructionSaveErrRetAddr *instruction) {
27860 IrInstruction *result = ir_build_save_err_ret_addr(&ira->new_irb, instruction->base.scope,
27861 instruction->base.source_node);
27862 result->value->type = ira->codegen->builtin_types.entry_void;
27863 return result;
28679static IrInstGen *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstSrcSaveErrRetAddr *instruction) {
28680 return ir_build_save_err_ret_addr_gen(ira, &instruction->base.base);
2786428681}
2786528682
27866static ErrorMsg *ir_eval_float_op(IrAnalyze *ira, IrInstruction *source_instr, BuiltinFnId fop, ZigType *float_type,
28683static ErrorMsg *ir_eval_float_op(IrAnalyze *ira, IrInst* source_instr, BuiltinFnId fop, ZigType *float_type,
2786728684 ZigValue *op, ZigValue *out_val)
2786828685{
2786928686 assert(ira && source_instr && float_type && out_val && op);
......@@ -28076,30 +28893,30 @@ static ErrorMsg *ir_eval_float_op(IrAnalyze *ira, IrInstruction *source_instr, B
2807628893 return nullptr;
2807728894}
2807828895
28079static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstructionFloatOp *instruction) {
28080 IrInstruction *operand = instruction->operand->child;
28896static IrInstGen *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstSrcFloatOp *instruction) {
28897 IrInstGen *operand = instruction->operand->child;
2808128898 ZigType *operand_type = operand->value->type;
2808228899 if (type_is_invalid(operand_type))
28083 return ira->codegen->invalid_instruction;
28900 return ira->codegen->invalid_inst_gen;
2808428901
2808528902 // This instruction accepts floats and vectors of floats.
2808628903 ZigType *scalar_type = (operand_type->id == ZigTypeIdVector) ?
2808728904 operand_type->data.vector.elem_type : operand_type;
2808828905
2808928906 if (scalar_type->id != ZigTypeIdFloat && scalar_type->id != ZigTypeIdComptimeFloat) {
28090 ir_add_error(ira, operand,
28907 ir_add_error(ira, &operand->base,
2809128908 buf_sprintf("expected float type, found '%s'", buf_ptr(&scalar_type->name)));
28092 return ira->codegen->invalid_instruction;
28909 return ira->codegen->invalid_inst_gen;
2809328910 }
2809428911
2809528912 if (instr_is_comptime(operand)) {
2809628913 ZigValue *operand_val = ir_resolve_const(ira, operand, UndefOk);
2809728914 if (operand_val == nullptr)
28098 return ira->codegen->invalid_instruction;
28915 return ira->codegen->invalid_inst_gen;
2809928916 if (operand_val->special == ConstValSpecialUndef)
28100 return ir_const_undef(ira, &instruction->base, operand_type);
28917 return ir_const_undef(ira, &instruction->base.base, operand_type);
2810128918
28102 IrInstruction *result = ir_const(ira, &instruction->base, operand_type);
28919 IrInstGen *result = ir_const(ira, &instruction->base.base, operand_type);
2810328920 ZigValue *out_val = result->value;
2810428921
2810528922 if (operand_type->id == ZigTypeIdVector) {
......@@ -28110,47 +28927,44 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct
2811028927 for (size_t i = 0; i < len; i += 1) {
2811128928 ZigValue *elem_operand = &operand_val->data.x_array.data.s_none.elements[i];
2811228929 ZigValue *float_out_val = &out_val->data.x_array.data.s_none.elements[i];
28113 ir_assert(elem_operand->type == scalar_type, &instruction->base);
28114 ir_assert(float_out_val->type == scalar_type, &instruction->base);
28115 ErrorMsg *msg = ir_eval_float_op(ira, &instruction->base, instruction->fn_id, scalar_type,
28930 ir_assert(elem_operand->type == scalar_type, &instruction->base.base);
28931 ir_assert(float_out_val->type == scalar_type, &instruction->base.base);
28932 ErrorMsg *msg = ir_eval_float_op(ira, &instruction->base.base, instruction->fn_id, scalar_type,
2811628933 elem_operand, float_out_val);
2811728934 if (msg != nullptr) {
28118 add_error_note(ira->codegen, msg, instruction->base.source_node,
28935 add_error_note(ira->codegen, msg, instruction->base.base.source_node,
2811928936 buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i));
28120 return ira->codegen->invalid_instruction;
28937 return ira->codegen->invalid_inst_gen;
2812128938 }
2812228939 float_out_val->type = scalar_type;
2812328940 }
2812428941 out_val->type = operand_type;
2812528942 out_val->special = ConstValSpecialStatic;
2812628943 } else {
28127 if (ir_eval_float_op(ira, &instruction->base, instruction->fn_id, scalar_type,
28944 if (ir_eval_float_op(ira, &instruction->base.base, instruction->fn_id, scalar_type,
2812828945 operand_val, out_val) != nullptr)
2812928946 {
28130 return ira->codegen->invalid_instruction;
28947 return ira->codegen->invalid_inst_gen;
2813128948 }
2813228949 }
2813328950 return result;
2813428951 }
2813528952
28136 ir_assert(scalar_type->id == ZigTypeIdFloat, &instruction->base);
28953 ir_assert(scalar_type->id == ZigTypeIdFloat, &instruction->base.base);
2813728954
28138 IrInstruction *result = ir_build_float_op(&ira->new_irb, instruction->base.scope,
28139 instruction->base.source_node, operand, instruction->fn_id);
28140 result->value->type = operand_type;
28141 return result;
28955 return ir_build_float_op_gen(ira, &instruction->base.base, operand, instruction->fn_id, operand_type);
2814228956}
2814328957
28144static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstructionBswap *instruction) {
28958static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *instruction) {
2814528959 Error err;
2814628960
2814728961 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);
2814828962 if (type_is_invalid(int_type))
28149 return ira->codegen->invalid_instruction;
28963 return ira->codegen->invalid_inst_gen;
2815028964
28151 IrInstruction *uncasted_op = instruction->op->child;
28965 IrInstGen *uncasted_op = instruction->op->child;
2815228966 if (type_is_invalid(uncasted_op->value->type))
28153 return ira->codegen->invalid_instruction;
28967 return ira->codegen->invalid_inst_gen;
2815428968
2815528969 uint32_t vector_len; // UINT32_MAX means not a vector
2815628970 if (uncasted_op->value->type->id == ZigTypeIdArray &&
......@@ -28166,28 +28980,28 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction
2816628980 bool is_vector = (vector_len != UINT32_MAX);
2816728981 ZigType *op_type = is_vector ? get_vector_type(ira->codegen, vector_len, int_type) : int_type;
2816828982
28169 IrInstruction *op = ir_implicit_cast(ira, uncasted_op, op_type);
28983 IrInstGen *op = ir_implicit_cast(ira, uncasted_op, op_type);
2817028984 if (type_is_invalid(op->value->type))
28171 return ira->codegen->invalid_instruction;
28985 return ira->codegen->invalid_inst_gen;
2817228986
2817328987 if (int_type->data.integral.bit_count == 8 || int_type->data.integral.bit_count == 0)
2817428988 return op;
2817528989
2817628990 if (int_type->data.integral.bit_count % 8 != 0) {
28177 ir_add_error(ira, instruction->op,
28991 ir_add_error(ira, &instruction->op->base,
2817828992 buf_sprintf("@byteSwap integer type '%s' has %" PRIu32 " bits which is not evenly divisible by 8",
2817928993 buf_ptr(&int_type->name), int_type->data.integral.bit_count));
28180 return ira->codegen->invalid_instruction;
28994 return ira->codegen->invalid_inst_gen;
2818128995 }
2818228996
2818328997 if (instr_is_comptime(op)) {
2818428998 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
2818528999 if (val == nullptr)
28186 return ira->codegen->invalid_instruction;
29000 return ira->codegen->invalid_inst_gen;
2818729001 if (val->special == ConstValSpecialUndef)
28188 return ir_const_undef(ira, &instruction->base, op_type);
29002 return ir_const_undef(ira, &instruction->base.base, op_type);
2818929003
28190 IrInstruction *result = ir_const(ira, &instruction->base, op_type);
29004 IrInstGen *result = ir_const(ira, &instruction->base.base, op_type);
2819129005 size_t buf_size = int_type->data.integral.bit_count / 8;
2819229006 uint8_t *buf = allocate_nonzero<uint8_t>(buf_size);
2819329007 if (is_vector) {
......@@ -28195,10 +29009,10 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction
2819529009 result->value->data.x_array.data.s_none.elements = create_const_vals(op_type->data.vector.len);
2819629010 for (unsigned i = 0; i < op_type->data.vector.len; i += 1) {
2819729011 ZigValue *op_elem_val = &val->data.x_array.data.s_none.elements[i];
28198 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, instruction->base.source_node,
29012 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, instruction->base.base.source_node,
2819929013 op_elem_val, UndefOk)))
2820029014 {
28201 return ira->codegen->invalid_instruction;
29015 return ira->codegen->invalid_inst_gen;
2820229016 }
2820329017 ZigValue *result_elem_val = &result->value->data.x_array.data.s_none.elements[i];
2820429018 result_elem_val->type = int_type;
......@@ -28220,23 +29034,20 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction
2822029034 return result;
2822129035 }
2822229036
28223 IrInstruction *result = ir_build_bswap(&ira->new_irb, instruction->base.scope,
28224 instruction->base.source_node, nullptr, op);
28225 result->value->type = op_type;
28226 return result;
29037 return ir_build_bswap_gen(ira, &instruction->base.base, op_type, op);
2822729038}
2822829039
28229static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstructionBitReverse *instruction) {
29040static IrInstGen *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstSrcBitReverse *instruction) {
2823029041 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);
2823129042 if (type_is_invalid(int_type))
28232 return ira->codegen->invalid_instruction;
29043 return ira->codegen->invalid_inst_gen;
2823329044
28234 IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type);
29045 IrInstGen *op = ir_implicit_cast(ira, instruction->op->child, int_type);
2823529046 if (type_is_invalid(op->value->type))
28236 return ira->codegen->invalid_instruction;
29047 return ira->codegen->invalid_inst_gen;
2823729048
2823829049 if (int_type->data.integral.bit_count == 0) {
28239 IrInstruction *result = ir_const(ira, &instruction->base, int_type);
29050 IrInstGen *result = ir_const(ira, &instruction->base.base, int_type);
2824029051 bigint_init_unsigned(&result->value->data.x_bigint, 0);
2824129052 return result;
2824229053 }
......@@ -28244,11 +29055,11 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr
2824429055 if (instr_is_comptime(op)) {
2824529056 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
2824629057 if (val == nullptr)
28247 return ira->codegen->invalid_instruction;
29058 return ira->codegen->invalid_inst_gen;
2824829059 if (val->special == ConstValSpecialUndef)
28249 return ir_const_undef(ira, &instruction->base, int_type);
29060 return ir_const_undef(ira, &instruction->base.base, int_type);
2825029061
28251 IrInstruction *result = ir_const(ira, &instruction->base, int_type);
29062 IrInstGen *result = ir_const(ira, &instruction->base.base, int_type);
2825229063 size_t num_bits = int_type->data.integral.bit_count;
2825329064 size_t buf_size = (num_bits + 7) / 8;
2825429065 uint8_t *comptime_buf = allocate_nonzero<uint8_t>(buf_size);
......@@ -28275,128 +29086,125 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr
2827529086 return result;
2827629087 }
2827729088
28278 IrInstruction *result = ir_build_bit_reverse(&ira->new_irb, instruction->base.scope,
28279 instruction->base.source_node, nullptr, op);
28280 result->value->type = int_type;
28281 return result;
29089 return ir_build_bit_reverse_gen(ira, &instruction->base.base, int_type, op);
2828229090}
2828329091
2828429092
28285static IrInstruction *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstructionEnumToInt *instruction) {
28286 IrInstruction *target = instruction->target->child;
29093static IrInstGen *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstSrcEnumToInt *instruction) {
29094 IrInstGen *target = instruction->target->child;
2828729095 if (type_is_invalid(target->value->type))
28288 return ira->codegen->invalid_instruction;
29096 return ira->codegen->invalid_inst_gen;
2828929097
28290 return ir_analyze_enum_to_int(ira, &instruction->base, target);
29098 return ir_analyze_enum_to_int(ira, &instruction->base.base, target);
2829129099}
2829229100
28293static IrInstruction *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstructionIntToEnum *instruction) {
29101static IrInstGen *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstSrcIntToEnum *instruction) {
2829429102 Error err;
28295 IrInstruction *dest_type_value = instruction->dest_type->child;
29103 IrInstGen *dest_type_value = instruction->dest_type->child;
2829629104 ZigType *dest_type = ir_resolve_type(ira, dest_type_value);
2829729105 if (type_is_invalid(dest_type))
28298 return ira->codegen->invalid_instruction;
29106 return ira->codegen->invalid_inst_gen;
2829929107
2830029108 if (dest_type->id != ZigTypeIdEnum) {
28301 ir_add_error(ira, instruction->dest_type,
29109 ir_add_error(ira, &instruction->dest_type->base,
2830229110 buf_sprintf("expected enum, found type '%s'", buf_ptr(&dest_type->name)));
28303 return ira->codegen->invalid_instruction;
29111 return ira->codegen->invalid_inst_gen;
2830429112 }
2830529113
2830629114 if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown)))
28307 return ira->codegen->invalid_instruction;
29115 return ira->codegen->invalid_inst_gen;
2830829116
2830929117 ZigType *tag_type = dest_type->data.enumeration.tag_int_type;
2831029118
28311 IrInstruction *target = instruction->target->child;
29119 IrInstGen *target = instruction->target->child;
2831229120 if (type_is_invalid(target->value->type))
28313 return ira->codegen->invalid_instruction;
29121 return ira->codegen->invalid_inst_gen;
2831429122
28315 IrInstruction *casted_target = ir_implicit_cast(ira, target, tag_type);
29123 IrInstGen *casted_target = ir_implicit_cast(ira, target, tag_type);
2831629124 if (type_is_invalid(casted_target->value->type))
28317 return ira->codegen->invalid_instruction;
29125 return ira->codegen->invalid_inst_gen;
2831829126
28319 return ir_analyze_int_to_enum(ira, &instruction->base, casted_target, dest_type);
29127 return ir_analyze_int_to_enum(ira, &instruction->base.base, casted_target, dest_type);
2832029128}
2832129129
28322static IrInstruction *ir_analyze_instruction_check_runtime_scope(IrAnalyze *ira, IrInstructionCheckRuntimeScope *instruction) {
28323 IrInstruction *block_comptime_inst = instruction->scope_is_comptime->child;
29130static IrInstGen *ir_analyze_instruction_check_runtime_scope(IrAnalyze *ira, IrInstSrcCheckRuntimeScope *instruction) {
29131 IrInstGen *block_comptime_inst = instruction->scope_is_comptime->child;
2832429132 bool scope_is_comptime;
2832529133 if (!ir_resolve_bool(ira, block_comptime_inst, &scope_is_comptime))
28326 return ira->codegen->invalid_instruction;
29134 return ira->codegen->invalid_inst_gen;
2832729135
28328 IrInstruction *is_comptime_inst = instruction->is_comptime->child;
29136 IrInstGen *is_comptime_inst = instruction->is_comptime->child;
2832929137 bool is_comptime;
2833029138 if (!ir_resolve_bool(ira, is_comptime_inst, &is_comptime))
28331 return ira->codegen->invalid_instruction;
29139 return ira->codegen->invalid_inst_gen;
2833229140
2833329141 if (!scope_is_comptime && is_comptime) {
28334 ErrorMsg *msg = ir_add_error(ira, &instruction->base,
29142 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base,
2833529143 buf_sprintf("comptime control flow inside runtime block"));
28336 add_error_note(ira->codegen, msg, block_comptime_inst->source_node,
29144 add_error_note(ira->codegen, msg, block_comptime_inst->base.source_node,
2833729145 buf_sprintf("runtime block created here"));
28338 return ira->codegen->invalid_instruction;
29146 return ira->codegen->invalid_inst_gen;
2833929147 }
2834029148
28341 return ir_const_void(ira, &instruction->base);
29149 return ir_const_void(ira, &instruction->base.base);
2834229150}
2834329151
28344static IrInstruction *ir_analyze_instruction_has_decl(IrAnalyze *ira, IrInstructionHasDecl *instruction) {
29152static IrInstGen *ir_analyze_instruction_has_decl(IrAnalyze *ira, IrInstSrcHasDecl *instruction) {
2834529153 ZigType *container_type = ir_resolve_type(ira, instruction->container->child);
2834629154 if (type_is_invalid(container_type))
28347 return ira->codegen->invalid_instruction;
29155 return ira->codegen->invalid_inst_gen;
2834829156
2834929157 Buf *name = ir_resolve_str(ira, instruction->name->child);
2835029158 if (name == nullptr)
28351 return ira->codegen->invalid_instruction;
29159 return ira->codegen->invalid_inst_gen;
2835229160
2835329161 if (!is_container(container_type)) {
28354 ir_add_error(ira, instruction->container,
29162 ir_add_error(ira, &instruction->container->base,
2835529163 buf_sprintf("expected struct, enum, or union; found '%s'", buf_ptr(&container_type->name)));
28356 return ira->codegen->invalid_instruction;
29164 return ira->codegen->invalid_inst_gen;
2835729165 }
2835829166
2835929167 ScopeDecls *container_scope = get_container_scope(container_type);
2836029168 Tld *tld = find_container_decl(ira->codegen, container_scope, name);
2836129169 if (tld == nullptr)
28362 return ir_const_bool(ira, &instruction->base, false);
29170 return ir_const_bool(ira, &instruction->base.base, false);
2836329171
28364 if (tld->visib_mod == VisibModPrivate && tld->import != get_scope_import(instruction->base.scope)) {
28365 return ir_const_bool(ira, &instruction->base, false);
29172 if (tld->visib_mod == VisibModPrivate && tld->import != get_scope_import(instruction->base.base.scope)) {
29173 return ir_const_bool(ira, &instruction->base.base, false);
2836629174 }
2836729175
28368 return ir_const_bool(ira, &instruction->base, true);
29176 return ir_const_bool(ira, &instruction->base.base, true);
2836929177}
2837029178
28371static IrInstruction *ir_analyze_instruction_undeclared_ident(IrAnalyze *ira, IrInstructionUndeclaredIdent *instruction) {
29179static IrInstGen *ir_analyze_instruction_undeclared_ident(IrAnalyze *ira, IrInstSrcUndeclaredIdent *instruction) {
2837229180 // put a variable of same name with invalid type in global scope
2837329181 // so that future references to this same name will find a variable with an invalid type
28374 populate_invalid_variable_in_scope(ira->codegen, instruction->base.scope, instruction->base.source_node,
28375 instruction->name);
28376 ir_add_error(ira, &instruction->base,
29182 populate_invalid_variable_in_scope(ira->codegen, instruction->base.base.scope,
29183 instruction->base.base.source_node, instruction->name);
29184 ir_add_error(ira, &instruction->base.base,
2837729185 buf_sprintf("use of undeclared identifier '%s'", buf_ptr(instruction->name)));
28378 return ira->codegen->invalid_instruction;
29186 return ira->codegen->invalid_inst_gen;
2837929187}
2838029188
28381static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstructionEndExpr *instruction) {
28382 IrInstruction *value = instruction->value->child;
29189static IrInstGen *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstSrcEndExpr *instruction) {
29190 IrInstGen *value = instruction->value->child;
2838329191 if (type_is_invalid(value->value->type))
28384 return ira->codegen->invalid_instruction;
29192 return ira->codegen->invalid_inst_gen;
2838529193
2838629194 bool was_written = instruction->result_loc->written;
28387 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
29195 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
2838829196 value->value->type, value, false, false, true);
2838929197 if (result_loc != nullptr) {
2839029198 if (type_is_invalid(result_loc->value->type))
28391 return ira->codegen->invalid_instruction;
29199 return ira->codegen->invalid_inst_gen;
2839229200 if (result_loc->value->type->id == ZigTypeIdUnreachable)
2839329201 return result_loc;
2839429202
2839529203 if (!was_written || instruction->result_loc->id == ResultLocIdPeer) {
28396 IrInstruction *store_ptr = ir_analyze_store_ptr(ira, &instruction->base, result_loc, value,
29204 IrInstGen *store_ptr = ir_analyze_store_ptr(ira, &instruction->base.base, result_loc, value,
2839729205 instruction->result_loc->allow_write_through_const);
2839829206 if (type_is_invalid(store_ptr->value->type)) {
28399 return ira->codegen->invalid_instruction;
29207 return ira->codegen->invalid_inst_gen;
2840029208 }
2840129209 }
2840229210
......@@ -28411,33 +29219,33 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct
2841129219 }
2841229220 }
2841329221
28414 return ir_const_void(ira, &instruction->base);
29222 return ir_const_void(ira, &instruction->base.base);
2841529223}
2841629224
28417static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstructionImplicitCast *instruction) {
28418 IrInstruction *operand = instruction->operand->child;
29225static IrInstGen *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstSrcImplicitCast *instruction) {
29226 IrInstGen *operand = instruction->operand->child;
2841929227 if (type_is_invalid(operand->value->type))
2842029228 return operand;
2842129229
28422 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base,
29230 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base,
2842329231 &instruction->result_loc_cast->base, operand->value->type, operand, false, false, true);
28424 if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)))
29232 if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable))
2842529233 return result_loc;
2842629234
2842729235 ZigType *dest_type = ir_resolve_type(ira, instruction->result_loc_cast->base.source_instruction->child);
2842829236 if (type_is_invalid(dest_type))
28429 return ira->codegen->invalid_instruction;
28430 return ir_implicit_cast2(ira, &instruction->base, operand, dest_type);
29237 return ira->codegen->invalid_inst_gen;
29238 return ir_implicit_cast2(ira, &instruction->base.base, operand, dest_type);
2843129239}
2843229240
28433static IrInstruction *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstructionBitCastSrc *instruction) {
28434 IrInstruction *operand = instruction->operand->child;
29241static IrInstGen *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstSrcBitCast *instruction) {
29242 IrInstGen *operand = instruction->operand->child;
2843529243 if (type_is_invalid(operand->value->type))
2843629244 return operand;
2843729245
28438 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base,
29246 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base,
2843929247 &instruction->result_loc_bit_cast->base, operand->value->type, operand, false, false, true);
28440 if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)))
29248 if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable))
2844129249 return result_loc;
2844229250
2844329251 if (instruction->result_loc_bit_cast->parent->gen_instruction != nullptr) {
......@@ -28447,70 +29255,66 @@ static IrInstruction *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInst
2844729255 return result_loc;
2844829256}
2844929257
28450static IrInstruction *ir_analyze_instruction_union_init_named_field(IrAnalyze *ira,
28451 IrInstructionUnionInitNamedField *instruction)
29258static IrInstGen *ir_analyze_instruction_union_init_named_field(IrAnalyze *ira,
29259 IrInstSrcUnionInitNamedField *instruction)
2845229260{
2845329261 ZigType *union_type = ir_resolve_type(ira, instruction->union_type->child);
2845429262 if (type_is_invalid(union_type))
28455 return ira->codegen->invalid_instruction;
29263 return ira->codegen->invalid_inst_gen;
2845629264
2845729265 if (union_type->id != ZigTypeIdUnion) {
28458 ir_add_error(ira, instruction->union_type,
29266 ir_add_error(ira, &instruction->union_type->base,
2845929267 buf_sprintf("non-union type '%s' passed to @unionInit", buf_ptr(&union_type->name)));
28460 return ira->codegen->invalid_instruction;
29268 return ira->codegen->invalid_inst_gen;
2846129269 }
2846229270
2846329271 Buf *field_name = ir_resolve_str(ira, instruction->field_name->child);
2846429272 if (field_name == nullptr)
28465 return ira->codegen->invalid_instruction;
29273 return ira->codegen->invalid_inst_gen;
2846629274
28467 IrInstruction *field_result_loc = instruction->field_result_loc->child;
29275 IrInstGen *field_result_loc = instruction->field_result_loc->child;
2846829276 if (type_is_invalid(field_result_loc->value->type))
28469 return ira->codegen->invalid_instruction;
29277 return ira->codegen->invalid_inst_gen;
2847029278
28471 IrInstruction *result_loc = instruction->result_loc->child;
29279 IrInstGen *result_loc = instruction->result_loc->child;
2847229280 if (type_is_invalid(result_loc->value->type))
28473 return ira->codegen->invalid_instruction;
29281 return ira->codegen->invalid_inst_gen;
2847429282
28475 return ir_analyze_union_init(ira, &instruction->base, instruction->base.source_node,
29283 return ir_analyze_union_init(ira, &instruction->base.base, instruction->base.base.source_node,
2847629284 union_type, field_name, field_result_loc, result_loc);
2847729285}
2847829286
28479static IrInstruction *ir_analyze_instruction_suspend_begin(IrAnalyze *ira, IrInstructionSuspendBegin *instruction) {
28480 IrInstructionSuspendBegin *result = ir_build_suspend_begin(&ira->new_irb, instruction->base.scope,
28481 instruction->base.source_node);
28482 return &result->base;
29287static IrInstGen *ir_analyze_instruction_suspend_begin(IrAnalyze *ira, IrInstSrcSuspendBegin *instruction) {
29288 return ir_build_suspend_begin_gen(ira, &instruction->base.base);
2848329289}
2848429290
28485static IrInstruction *ir_analyze_instruction_suspend_finish(IrAnalyze *ira,
28486 IrInstructionSuspendFinish *instruction)
28487{
28488 IrInstruction *begin_base = instruction->begin->base.child;
29291static IrInstGen *ir_analyze_instruction_suspend_finish(IrAnalyze *ira, IrInstSrcSuspendFinish *instruction) {
29292 IrInstGen *begin_base = instruction->begin->base.child;
2848929293 if (type_is_invalid(begin_base->value->type))
28490 return ira->codegen->invalid_instruction;
28491 ir_assert(begin_base->id == IrInstructionIdSuspendBegin, &instruction->base);
28492 IrInstructionSuspendBegin *begin = reinterpret_cast<IrInstructionSuspendBegin *>(begin_base);
29294 return ira->codegen->invalid_inst_gen;
29295 ir_assert(begin_base->id == IrInstGenIdSuspendBegin, &instruction->base.base);
29296 IrInstGenSuspendBegin *begin = reinterpret_cast<IrInstGenSuspendBegin *>(begin_base);
2849329297
28494 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
28495 ir_assert(fn_entry != nullptr, &instruction->base);
29298 ZigFn *fn_entry = ira->new_irb.exec->fn_entry;
29299 ir_assert(fn_entry != nullptr, &instruction->base.base);
2849629300
2849729301 if (fn_entry->inferred_async_node == nullptr) {
28498 fn_entry->inferred_async_node = instruction->base.source_node;
29302 fn_entry->inferred_async_node = instruction->base.base.source_node;
2849929303 }
2850029304
28501 return ir_build_suspend_finish(&ira->new_irb, instruction->base.scope, instruction->base.source_node, begin);
29305 return ir_build_suspend_finish_gen(ira, &instruction->base.base, begin);
2850229306}
2850329307
28504static IrInstruction *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInstruction *source_instr,
28505 IrInstruction *frame_ptr, ZigFn **target_fn)
29308static IrInstGen *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInst* source_instr,
29309 IrInstGen *frame_ptr, ZigFn **target_fn)
2850629310{
2850729311 if (type_is_invalid(frame_ptr->value->type))
28508 return ira->codegen->invalid_instruction;
29312 return ira->codegen->invalid_inst_gen;
2850929313
2851029314 *target_fn = nullptr;
2851129315
2851229316 ZigType *result_type;
28513 IrInstruction *frame;
29317 IrInstGen *frame;
2851429318 if (frame_ptr->value->type->id == ZigTypeIdPointer &&
2851529319 frame_ptr->value->type->data.pointer.ptr_len == PtrLenSingle &&
2851629320 frame_ptr->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame)
......@@ -28533,38 +29337,38 @@ static IrInstruction *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInstruct
2853329337 {
2853429338 ir_add_error(ira, source_instr,
2853529339 buf_sprintf("expected anyframe->T, found '%s'", buf_ptr(&frame->value->type->name)));
28536 return ira->codegen->invalid_instruction;
29340 return ira->codegen->invalid_inst_gen;
2853729341 } else {
2853829342 result_type = frame->value->type->data.any_frame.result_type;
2853929343 }
2854029344 }
2854129345
2854229346 ZigType *any_frame_type = get_any_frame_type(ira->codegen, result_type);
28543 IrInstruction *casted_frame = ir_implicit_cast(ira, frame, any_frame_type);
29347 IrInstGen *casted_frame = ir_implicit_cast(ira, frame, any_frame_type);
2854429348 if (type_is_invalid(casted_frame->value->type))
28545 return ira->codegen->invalid_instruction;
29349 return ira->codegen->invalid_inst_gen;
2854629350
2854729351 return casted_frame;
2854829352}
2854929353
28550static IrInstruction *ir_analyze_instruction_await(IrAnalyze *ira, IrInstructionAwaitSrc *instruction) {
28551 IrInstruction *operand = instruction->frame->child;
29354static IrInstGen *ir_analyze_instruction_await(IrAnalyze *ira, IrInstSrcAwait *instruction) {
29355 IrInstGen *operand = instruction->frame->child;
2855229356 if (type_is_invalid(operand->value->type))
28553 return ira->codegen->invalid_instruction;
29357 return ira->codegen->invalid_inst_gen;
2855429358 ZigFn *target_fn;
28555 IrInstruction *frame = analyze_frame_ptr_to_anyframe_T(ira, &instruction->base, operand, &target_fn);
29359 IrInstGen *frame = analyze_frame_ptr_to_anyframe_T(ira, &instruction->base.base, operand, &target_fn);
2855629360 if (type_is_invalid(frame->value->type))
28557 return ira->codegen->invalid_instruction;
29361 return ira->codegen->invalid_inst_gen;
2855829362
2855929363 ZigType *result_type = frame->value->type->data.any_frame.result_type;
2856029364
28561 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
28562 ir_assert(fn_entry != nullptr, &instruction->base);
29365 ZigFn *fn_entry = ira->new_irb.exec->fn_entry;
29366 ir_assert(fn_entry != nullptr, &instruction->base.base);
2856329367
2856429368 // If it's not @Frame(func) then it's definitely a suspend point
2856529369 if (target_fn == nullptr) {
2856629370 if (fn_entry->inferred_async_node == nullptr) {
28567 fn_entry->inferred_async_node = instruction->base.source_node;
29371 fn_entry->inferred_async_node = instruction->base.base.source_node;
2856829372 }
2856929373 }
2857029374
......@@ -28572,401 +29376,364 @@ static IrInstruction *ir_analyze_instruction_await(IrAnalyze *ira, IrInstruction
2857229376 fn_entry->calls_or_awaits_errorable_fn = true;
2857329377 }
2857429378
28575 IrInstruction *result_loc;
29379 IrInstGen *result_loc;
2857629380 if (type_has_bits(result_type)) {
28577 result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
29381 result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
2857829382 result_type, nullptr, true, true, true);
28579 if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)))
29383 if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable))
2858029384 return result_loc;
2858129385 } else {
2858229386 result_loc = nullptr;
2858329387 }
2858429388
28585 IrInstructionAwaitGen *result = ir_build_await_gen(ira, &instruction->base, frame, result_type, result_loc);
29389 IrInstGenAwait *result = ir_build_await_gen(ira, &instruction->base.base, frame, result_type, result_loc);
2858629390 result->target_fn = target_fn;
2858729391 fn_entry->await_list.append(result);
2858829392 return ir_finish_anal(ira, &result->base);
2858929393}
2859029394
28591static IrInstruction *ir_analyze_instruction_resume(IrAnalyze *ira, IrInstructionResume *instruction) {
28592 IrInstruction *frame_ptr = instruction->frame->child;
29395static IrInstGen *ir_analyze_instruction_resume(IrAnalyze *ira, IrInstSrcResume *instruction) {
29396 IrInstGen *frame_ptr = instruction->frame->child;
2859329397 if (type_is_invalid(frame_ptr->value->type))
28594 return ira->codegen->invalid_instruction;
29398 return ira->codegen->invalid_inst_gen;
2859529399
28596 IrInstruction *frame;
29400 IrInstGen *frame;
2859729401 if (frame_ptr->value->type->id == ZigTypeIdPointer &&
2859829402 frame_ptr->value->type->data.pointer.ptr_len == PtrLenSingle &&
2859929403 frame_ptr->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame)
2860029404 {
2860129405 frame = frame_ptr;
2860229406 } else {
28603 frame = ir_get_deref(ira, &instruction->base, frame_ptr, nullptr);
29407 frame = ir_get_deref(ira, &instruction->base.base, frame_ptr, nullptr);
2860429408 }
2860529409
2860629410 ZigType *any_frame_type = get_any_frame_type(ira->codegen, nullptr);
28607 IrInstruction *casted_frame = ir_implicit_cast(ira, frame, any_frame_type);
29411 IrInstGen *casted_frame = ir_implicit_cast(ira, frame, any_frame_type);
2860829412 if (type_is_invalid(casted_frame->value->type))
28609 return ira->codegen->invalid_instruction;
29413 return ira->codegen->invalid_inst_gen;
2861029414
28611 return ir_build_resume(&ira->new_irb, instruction->base.scope, instruction->base.source_node, casted_frame);
29415 return ir_build_resume_gen(ira, &instruction->base.base, casted_frame);
2861229416}
2861329417
28614static IrInstruction *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstructionSpillBegin *instruction) {
28615 if (ir_should_inline(ira->new_irb.exec, instruction->base.scope))
28616 return ir_const_void(ira, &instruction->base);
29418static IrInstGen *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstSrcSpillBegin *instruction) {
29419 if (ir_should_inline(ira->old_irb.exec, instruction->base.base.scope))
29420 return ir_const_void(ira, &instruction->base.base);
2861729421
28618 IrInstruction *operand = instruction->operand->child;
29422 IrInstGen *operand = instruction->operand->child;
2861929423 if (type_is_invalid(operand->value->type))
28620 return ira->codegen->invalid_instruction;
29424 return ira->codegen->invalid_inst_gen;
2862129425
2862229426 if (!type_has_bits(operand->value->type))
28623 return ir_const_void(ira, &instruction->base);
29427 return ir_const_void(ira, &instruction->base.base);
2862429428
28625 ir_assert(instruction->spill_id == SpillIdRetErrCode, &instruction->base);
29429 ir_assert(instruction->spill_id == SpillIdRetErrCode, &instruction->base.base);
2862629430 ira->new_irb.exec->need_err_code_spill = true;
2862729431
28628 IrInstructionSpillBegin *result = ir_build_spill_begin(&ira->new_irb, instruction->base.scope,
28629 instruction->base.source_node, operand, instruction->spill_id);
28630 return &result->base;
29432 return ir_build_spill_begin_gen(ira, &instruction->base.base, operand, instruction->spill_id);
2863129433}
2863229434
28633static IrInstruction *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstructionSpillEnd *instruction) {
28634 IrInstruction *operand = instruction->begin->operand->child;
29435static IrInstGen *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstSrcSpillEnd *instruction) {
29436 IrInstGen *operand = instruction->begin->operand->child;
2863529437 if (type_is_invalid(operand->value->type))
28636 return ira->codegen->invalid_instruction;
29438 return ira->codegen->invalid_inst_gen;
2863729439
28638 if (ir_should_inline(ira->new_irb.exec, instruction->base.scope) || !type_has_bits(operand->value->type))
29440 if (ir_should_inline(ira->old_irb.exec, instruction->base.base.scope) || !type_has_bits(operand->value->type))
2863929441 return operand;
2864029442
28641 ir_assert(instruction->begin->base.child->id == IrInstructionIdSpillBegin, &instruction->base);
28642 IrInstructionSpillBegin *begin = reinterpret_cast<IrInstructionSpillBegin *>(instruction->begin->base.child);
29443 ir_assert(instruction->begin->base.child->id == IrInstGenIdSpillBegin, &instruction->base.base);
29444 IrInstGenSpillBegin *begin = reinterpret_cast<IrInstGenSpillBegin *>(instruction->begin->base.child);
2864329445
28644 IrInstruction *result = ir_build_spill_end(&ira->new_irb, instruction->base.scope,
28645 instruction->base.source_node, begin);
28646 result->value->type = operand->value->type;
28647 return result;
29446 return ir_build_spill_end_gen(ira, &instruction->base.base, begin, operand->value->type);
2864829447}
2864929448
28650static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction *instruction) {
29449static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruction) {
2865129450 switch (instruction->id) {
28652 case IrInstructionIdInvalid:
28653 case IrInstructionIdWidenOrShorten:
28654 case IrInstructionIdStructFieldPtr:
28655 case IrInstructionIdUnionFieldPtr:
28656 case IrInstructionIdOptionalWrap:
28657 case IrInstructionIdErrWrapCode:
28658 case IrInstructionIdErrWrapPayload:
28659 case IrInstructionIdCast:
28660 case IrInstructionIdDeclVarGen:
28661 case IrInstructionIdPtrCastGen:
28662 case IrInstructionIdCmpxchgGen:
28663 case IrInstructionIdArrayToVector:
28664 case IrInstructionIdVectorToArray:
28665 case IrInstructionIdPtrOfArrayToSlice:
28666 case IrInstructionIdAssertZero:
28667 case IrInstructionIdAssertNonNull:
28668 case IrInstructionIdResizeSlice:
28669 case IrInstructionIdLoadPtrGen:
28670 case IrInstructionIdBitCastGen:
28671 case IrInstructionIdCallGen:
28672 case IrInstructionIdReturnPtr:
28673 case IrInstructionIdAllocaGen:
28674 case IrInstructionIdSliceGen:
28675 case IrInstructionIdRefGen:
28676 case IrInstructionIdTestErrGen:
28677 case IrInstructionIdFrameSizeGen:
28678 case IrInstructionIdAwaitGen:
28679 case IrInstructionIdSplatGen:
28680 case IrInstructionIdVectorExtractElem:
28681 case IrInstructionIdVectorStoreElem:
28682 case IrInstructionIdAsmGen:
29451 case IrInstSrcIdInvalid:
2868329452 zig_unreachable();
2868429453
28685 case IrInstructionIdReturn:
28686 return ir_analyze_instruction_return(ira, (IrInstructionReturn *)instruction);
28687 case IrInstructionIdConst:
28688 return ir_analyze_instruction_const(ira, (IrInstructionConst *)instruction);
28689 case IrInstructionIdUnOp:
28690 return ir_analyze_instruction_un_op(ira, (IrInstructionUnOp *)instruction);
28691 case IrInstructionIdBinOp:
28692 return ir_analyze_instruction_bin_op(ira, (IrInstructionBinOp *)instruction);
28693 case IrInstructionIdMergeErrSets:
28694 return ir_analyze_instruction_merge_err_sets(ira, (IrInstructionMergeErrSets *)instruction);
28695 case IrInstructionIdDeclVarSrc:
28696 return ir_analyze_instruction_decl_var(ira, (IrInstructionDeclVarSrc *)instruction);
28697 case IrInstructionIdLoadPtr:
28698 return ir_analyze_instruction_load_ptr(ira, (IrInstructionLoadPtr *)instruction);
28699 case IrInstructionIdStorePtr:
28700 return ir_analyze_instruction_store_ptr(ira, (IrInstructionStorePtr *)instruction);
28701 case IrInstructionIdElemPtr:
28702 return ir_analyze_instruction_elem_ptr(ira, (IrInstructionElemPtr *)instruction);
28703 case IrInstructionIdVarPtr:
28704 return ir_analyze_instruction_var_ptr(ira, (IrInstructionVarPtr *)instruction);
28705 case IrInstructionIdFieldPtr:
28706 return ir_analyze_instruction_field_ptr(ira, (IrInstructionFieldPtr *)instruction);
28707 case IrInstructionIdCallSrc:
28708 return ir_analyze_instruction_call(ira, (IrInstructionCallSrc *)instruction);
28709 case IrInstructionIdCallSrcArgs:
28710 return ir_analyze_instruction_call_args(ira, (IrInstructionCallSrcArgs *)instruction);
28711 case IrInstructionIdCallExtra:
28712 return ir_analyze_instruction_call_extra(ira, (IrInstructionCallExtra *)instruction);
28713 case IrInstructionIdBr:
28714 return ir_analyze_instruction_br(ira, (IrInstructionBr *)instruction);
28715 case IrInstructionIdCondBr:
28716 return ir_analyze_instruction_cond_br(ira, (IrInstructionCondBr *)instruction);
28717 case IrInstructionIdUnreachable:
28718 return ir_analyze_instruction_unreachable(ira, (IrInstructionUnreachable *)instruction);
28719 case IrInstructionIdPhi:
28720 return ir_analyze_instruction_phi(ira, (IrInstructionPhi *)instruction);
28721 case IrInstructionIdTypeOf:
28722 return ir_analyze_instruction_typeof(ira, (IrInstructionTypeOf *)instruction);
28723 case IrInstructionIdSetCold:
28724 return ir_analyze_instruction_set_cold(ira, (IrInstructionSetCold *)instruction);
28725 case IrInstructionIdSetRuntimeSafety:
28726 return ir_analyze_instruction_set_runtime_safety(ira, (IrInstructionSetRuntimeSafety *)instruction);
28727 case IrInstructionIdSetFloatMode:
28728 return ir_analyze_instruction_set_float_mode(ira, (IrInstructionSetFloatMode *)instruction);
28729 case IrInstructionIdAnyFrameType:
28730 return ir_analyze_instruction_any_frame_type(ira, (IrInstructionAnyFrameType *)instruction);
28731 case IrInstructionIdSliceType:
28732 return ir_analyze_instruction_slice_type(ira, (IrInstructionSliceType *)instruction);
28733 case IrInstructionIdAsmSrc:
28734 return ir_analyze_instruction_asm(ira, (IrInstructionAsmSrc *)instruction);
28735 case IrInstructionIdArrayType:
28736 return ir_analyze_instruction_array_type(ira, (IrInstructionArrayType *)instruction);
28737 case IrInstructionIdSizeOf:
28738 return ir_analyze_instruction_size_of(ira, (IrInstructionSizeOf *)instruction);
28739 case IrInstructionIdTestNonNull:
28740 return ir_analyze_instruction_test_non_null(ira, (IrInstructionTestNonNull *)instruction);
28741 case IrInstructionIdOptionalUnwrapPtr:
28742 return ir_analyze_instruction_optional_unwrap_ptr(ira, (IrInstructionOptionalUnwrapPtr *)instruction);
28743 case IrInstructionIdClz:
28744 return ir_analyze_instruction_clz(ira, (IrInstructionClz *)instruction);
28745 case IrInstructionIdCtz:
28746 return ir_analyze_instruction_ctz(ira, (IrInstructionCtz *)instruction);
28747 case IrInstructionIdPopCount:
28748 return ir_analyze_instruction_pop_count(ira, (IrInstructionPopCount *)instruction);
28749 case IrInstructionIdBswap:
28750 return ir_analyze_instruction_bswap(ira, (IrInstructionBswap *)instruction);
28751 case IrInstructionIdBitReverse:
28752 return ir_analyze_instruction_bit_reverse(ira, (IrInstructionBitReverse *)instruction);
28753 case IrInstructionIdSwitchBr:
28754 return ir_analyze_instruction_switch_br(ira, (IrInstructionSwitchBr *)instruction);
28755 case IrInstructionIdSwitchTarget:
28756 return ir_analyze_instruction_switch_target(ira, (IrInstructionSwitchTarget *)instruction);
28757 case IrInstructionIdSwitchVar:
28758 return ir_analyze_instruction_switch_var(ira, (IrInstructionSwitchVar *)instruction);
28759 case IrInstructionIdSwitchElseVar:
28760 return ir_analyze_instruction_switch_else_var(ira, (IrInstructionSwitchElseVar *)instruction);
28761 case IrInstructionIdUnionTag:
28762 return ir_analyze_instruction_union_tag(ira, (IrInstructionUnionTag *)instruction);
28763 case IrInstructionIdImport:
28764 return ir_analyze_instruction_import(ira, (IrInstructionImport *)instruction);
28765 case IrInstructionIdRef:
28766 return ir_analyze_instruction_ref(ira, (IrInstructionRef *)instruction);
28767 case IrInstructionIdContainerInitList:
28768 return ir_analyze_instruction_container_init_list(ira, (IrInstructionContainerInitList *)instruction);
28769 case IrInstructionIdContainerInitFields:
28770 return ir_analyze_instruction_container_init_fields(ira, (IrInstructionContainerInitFields *)instruction);
28771 case IrInstructionIdCompileErr:
28772 return ir_analyze_instruction_compile_err(ira, (IrInstructionCompileErr *)instruction);
28773 case IrInstructionIdCompileLog:
28774 return ir_analyze_instruction_compile_log(ira, (IrInstructionCompileLog *)instruction);
28775 case IrInstructionIdErrName:
28776 return ir_analyze_instruction_err_name(ira, (IrInstructionErrName *)instruction);
28777 case IrInstructionIdTypeName:
28778 return ir_analyze_instruction_type_name(ira, (IrInstructionTypeName *)instruction);
28779 case IrInstructionIdCImport:
28780 return ir_analyze_instruction_c_import(ira, (IrInstructionCImport *)instruction);
28781 case IrInstructionIdCInclude:
28782 return ir_analyze_instruction_c_include(ira, (IrInstructionCInclude *)instruction);
28783 case IrInstructionIdCDefine:
28784 return ir_analyze_instruction_c_define(ira, (IrInstructionCDefine *)instruction);
28785 case IrInstructionIdCUndef:
28786 return ir_analyze_instruction_c_undef(ira, (IrInstructionCUndef *)instruction);
28787 case IrInstructionIdEmbedFile:
28788 return ir_analyze_instruction_embed_file(ira, (IrInstructionEmbedFile *)instruction);
28789 case IrInstructionIdCmpxchgSrc:
28790 return ir_analyze_instruction_cmpxchg(ira, (IrInstructionCmpxchgSrc *)instruction);
28791 case IrInstructionIdFence:
28792 return ir_analyze_instruction_fence(ira, (IrInstructionFence *)instruction);
28793 case IrInstructionIdTruncate:
28794 return ir_analyze_instruction_truncate(ira, (IrInstructionTruncate *)instruction);
28795 case IrInstructionIdIntCast:
28796 return ir_analyze_instruction_int_cast(ira, (IrInstructionIntCast *)instruction);
28797 case IrInstructionIdFloatCast:
28798 return ir_analyze_instruction_float_cast(ira, (IrInstructionFloatCast *)instruction);
28799 case IrInstructionIdErrSetCast:
28800 return ir_analyze_instruction_err_set_cast(ira, (IrInstructionErrSetCast *)instruction);
28801 case IrInstructionIdFromBytes:
28802 return ir_analyze_instruction_from_bytes(ira, (IrInstructionFromBytes *)instruction);
28803 case IrInstructionIdToBytes:
28804 return ir_analyze_instruction_to_bytes(ira, (IrInstructionToBytes *)instruction);
28805 case IrInstructionIdIntToFloat:
28806 return ir_analyze_instruction_int_to_float(ira, (IrInstructionIntToFloat *)instruction);
28807 case IrInstructionIdFloatToInt:
28808 return ir_analyze_instruction_float_to_int(ira, (IrInstructionFloatToInt *)instruction);
28809 case IrInstructionIdBoolToInt:
28810 return ir_analyze_instruction_bool_to_int(ira, (IrInstructionBoolToInt *)instruction);
28811 case IrInstructionIdIntType:
28812 return ir_analyze_instruction_int_type(ira, (IrInstructionIntType *)instruction);
28813 case IrInstructionIdVectorType:
28814 return ir_analyze_instruction_vector_type(ira, (IrInstructionVectorType *)instruction);
28815 case IrInstructionIdShuffleVector:
28816 return ir_analyze_instruction_shuffle_vector(ira, (IrInstructionShuffleVector *)instruction);
28817 case IrInstructionIdSplatSrc:
28818 return ir_analyze_instruction_splat(ira, (IrInstructionSplatSrc *)instruction);
28819 case IrInstructionIdBoolNot:
28820 return ir_analyze_instruction_bool_not(ira, (IrInstructionBoolNot *)instruction);
28821 case IrInstructionIdMemset:
28822 return ir_analyze_instruction_memset(ira, (IrInstructionMemset *)instruction);
28823 case IrInstructionIdMemcpy:
28824 return ir_analyze_instruction_memcpy(ira, (IrInstructionMemcpy *)instruction);
28825 case IrInstructionIdSliceSrc:
28826 return ir_analyze_instruction_slice(ira, (IrInstructionSliceSrc *)instruction);
28827 case IrInstructionIdMemberCount:
28828 return ir_analyze_instruction_member_count(ira, (IrInstructionMemberCount *)instruction);
28829 case IrInstructionIdMemberType:
28830 return ir_analyze_instruction_member_type(ira, (IrInstructionMemberType *)instruction);
28831 case IrInstructionIdMemberName:
28832 return ir_analyze_instruction_member_name(ira, (IrInstructionMemberName *)instruction);
28833 case IrInstructionIdBreakpoint:
28834 return ir_analyze_instruction_breakpoint(ira, (IrInstructionBreakpoint *)instruction);
28835 case IrInstructionIdReturnAddress:
28836 return ir_analyze_instruction_return_address(ira, (IrInstructionReturnAddress *)instruction);
28837 case IrInstructionIdFrameAddress:
28838 return ir_analyze_instruction_frame_address(ira, (IrInstructionFrameAddress *)instruction);
28839 case IrInstructionIdFrameHandle:
28840 return ir_analyze_instruction_frame_handle(ira, (IrInstructionFrameHandle *)instruction);
28841 case IrInstructionIdFrameType:
28842 return ir_analyze_instruction_frame_type(ira, (IrInstructionFrameType *)instruction);
28843 case IrInstructionIdFrameSizeSrc:
28844 return ir_analyze_instruction_frame_size(ira, (IrInstructionFrameSizeSrc *)instruction);
28845 case IrInstructionIdAlignOf:
28846 return ir_analyze_instruction_align_of(ira, (IrInstructionAlignOf *)instruction);
28847 case IrInstructionIdOverflowOp:
28848 return ir_analyze_instruction_overflow_op(ira, (IrInstructionOverflowOp *)instruction);
28849 case IrInstructionIdTestErrSrc:
28850 return ir_analyze_instruction_test_err(ira, (IrInstructionTestErrSrc *)instruction);
28851 case IrInstructionIdUnwrapErrCode:
28852 return ir_analyze_instruction_unwrap_err_code(ira, (IrInstructionUnwrapErrCode *)instruction);
28853 case IrInstructionIdUnwrapErrPayload:
28854 return ir_analyze_instruction_unwrap_err_payload(ira, (IrInstructionUnwrapErrPayload *)instruction);
28855 case IrInstructionIdFnProto:
28856 return ir_analyze_instruction_fn_proto(ira, (IrInstructionFnProto *)instruction);
28857 case IrInstructionIdTestComptime:
28858 return ir_analyze_instruction_test_comptime(ira, (IrInstructionTestComptime *)instruction);
28859 case IrInstructionIdCheckSwitchProngs:
28860 return ir_analyze_instruction_check_switch_prongs(ira, (IrInstructionCheckSwitchProngs *)instruction);
28861 case IrInstructionIdCheckStatementIsVoid:
28862 return ir_analyze_instruction_check_statement_is_void(ira, (IrInstructionCheckStatementIsVoid *)instruction);
28863 case IrInstructionIdDeclRef:
28864 return ir_analyze_instruction_decl_ref(ira, (IrInstructionDeclRef *)instruction);
28865 case IrInstructionIdPanic:
28866 return ir_analyze_instruction_panic(ira, (IrInstructionPanic *)instruction);
28867 case IrInstructionIdPtrCastSrc:
28868 return ir_analyze_instruction_ptr_cast(ira, (IrInstructionPtrCastSrc *)instruction);
28869 case IrInstructionIdIntToPtr:
28870 return ir_analyze_instruction_int_to_ptr(ira, (IrInstructionIntToPtr *)instruction);
28871 case IrInstructionIdPtrToInt:
28872 return ir_analyze_instruction_ptr_to_int(ira, (IrInstructionPtrToInt *)instruction);
28873 case IrInstructionIdTagName:
28874 return ir_analyze_instruction_enum_tag_name(ira, (IrInstructionTagName *)instruction);
28875 case IrInstructionIdFieldParentPtr:
28876 return ir_analyze_instruction_field_parent_ptr(ira, (IrInstructionFieldParentPtr *)instruction);
28877 case IrInstructionIdByteOffsetOf:
28878 return ir_analyze_instruction_byte_offset_of(ira, (IrInstructionByteOffsetOf *)instruction);
28879 case IrInstructionIdBitOffsetOf:
28880 return ir_analyze_instruction_bit_offset_of(ira, (IrInstructionBitOffsetOf *)instruction);
28881 case IrInstructionIdTypeInfo:
28882 return ir_analyze_instruction_type_info(ira, (IrInstructionTypeInfo *) instruction);
28883 case IrInstructionIdType:
28884 return ir_analyze_instruction_type(ira, (IrInstructionType *)instruction);
28885 case IrInstructionIdHasField:
28886 return ir_analyze_instruction_has_field(ira, (IrInstructionHasField *) instruction);
28887 case IrInstructionIdTypeId:
28888 return ir_analyze_instruction_type_id(ira, (IrInstructionTypeId *)instruction);
28889 case IrInstructionIdSetEvalBranchQuota:
28890 return ir_analyze_instruction_set_eval_branch_quota(ira, (IrInstructionSetEvalBranchQuota *)instruction);
28891 case IrInstructionIdPtrType:
28892 return ir_analyze_instruction_ptr_type(ira, (IrInstructionPtrType *)instruction);
28893 case IrInstructionIdAlignCast:
28894 return ir_analyze_instruction_align_cast(ira, (IrInstructionAlignCast *)instruction);
28895 case IrInstructionIdImplicitCast:
28896 return ir_analyze_instruction_implicit_cast(ira, (IrInstructionImplicitCast *)instruction);
28897 case IrInstructionIdResolveResult:
28898 return ir_analyze_instruction_resolve_result(ira, (IrInstructionResolveResult *)instruction);
28899 case IrInstructionIdResetResult:
28900 return ir_analyze_instruction_reset_result(ira, (IrInstructionResetResult *)instruction);
28901 case IrInstructionIdOpaqueType:
28902 return ir_analyze_instruction_opaque_type(ira, (IrInstructionOpaqueType *)instruction);
28903 case IrInstructionIdSetAlignStack:
28904 return ir_analyze_instruction_set_align_stack(ira, (IrInstructionSetAlignStack *)instruction);
28905 case IrInstructionIdArgType:
28906 return ir_analyze_instruction_arg_type(ira, (IrInstructionArgType *)instruction);
28907 case IrInstructionIdTagType:
28908 return ir_analyze_instruction_tag_type(ira, (IrInstructionTagType *)instruction);
28909 case IrInstructionIdExport:
28910 return ir_analyze_instruction_export(ira, (IrInstructionExport *)instruction);
28911 case IrInstructionIdErrorReturnTrace:
28912 return ir_analyze_instruction_error_return_trace(ira, (IrInstructionErrorReturnTrace *)instruction);
28913 case IrInstructionIdErrorUnion:
28914 return ir_analyze_instruction_error_union(ira, (IrInstructionErrorUnion *)instruction);
28915 case IrInstructionIdAtomicRmw:
28916 return ir_analyze_instruction_atomic_rmw(ira, (IrInstructionAtomicRmw *)instruction);
28917 case IrInstructionIdAtomicLoad:
28918 return ir_analyze_instruction_atomic_load(ira, (IrInstructionAtomicLoad *)instruction);
28919 case IrInstructionIdAtomicStore:
28920 return ir_analyze_instruction_atomic_store(ira, (IrInstructionAtomicStore *)instruction);
28921 case IrInstructionIdSaveErrRetAddr:
28922 return ir_analyze_instruction_save_err_ret_addr(ira, (IrInstructionSaveErrRetAddr *)instruction);
28923 case IrInstructionIdAddImplicitReturnType:
28924 return ir_analyze_instruction_add_implicit_return_type(ira, (IrInstructionAddImplicitReturnType *)instruction);
28925 case IrInstructionIdFloatOp:
28926 return ir_analyze_instruction_float_op(ira, (IrInstructionFloatOp *)instruction);
28927 case IrInstructionIdMulAdd:
28928 return ir_analyze_instruction_mul_add(ira, (IrInstructionMulAdd *)instruction);
28929 case IrInstructionIdIntToErr:
28930 return ir_analyze_instruction_int_to_err(ira, (IrInstructionIntToErr *)instruction);
28931 case IrInstructionIdErrToInt:
28932 return ir_analyze_instruction_err_to_int(ira, (IrInstructionErrToInt *)instruction);
28933 case IrInstructionIdIntToEnum:
28934 return ir_analyze_instruction_int_to_enum(ira, (IrInstructionIntToEnum *)instruction);
28935 case IrInstructionIdEnumToInt:
28936 return ir_analyze_instruction_enum_to_int(ira, (IrInstructionEnumToInt *)instruction);
28937 case IrInstructionIdCheckRuntimeScope:
28938 return ir_analyze_instruction_check_runtime_scope(ira, (IrInstructionCheckRuntimeScope *)instruction);
28939 case IrInstructionIdHasDecl:
28940 return ir_analyze_instruction_has_decl(ira, (IrInstructionHasDecl *)instruction);
28941 case IrInstructionIdUndeclaredIdent:
28942 return ir_analyze_instruction_undeclared_ident(ira, (IrInstructionUndeclaredIdent *)instruction);
28943 case IrInstructionIdAllocaSrc:
29454 case IrInstSrcIdReturn:
29455 return ir_analyze_instruction_return(ira, (IrInstSrcReturn *)instruction);
29456 case IrInstSrcIdConst:
29457 return ir_analyze_instruction_const(ira, (IrInstSrcConst *)instruction);
29458 case IrInstSrcIdUnOp:
29459 return ir_analyze_instruction_un_op(ira, (IrInstSrcUnOp *)instruction);
29460 case IrInstSrcIdBinOp:
29461 return ir_analyze_instruction_bin_op(ira, (IrInstSrcBinOp *)instruction);
29462 case IrInstSrcIdMergeErrSets:
29463 return ir_analyze_instruction_merge_err_sets(ira, (IrInstSrcMergeErrSets *)instruction);
29464 case IrInstSrcIdDeclVar:
29465 return ir_analyze_instruction_decl_var(ira, (IrInstSrcDeclVar *)instruction);
29466 case IrInstSrcIdLoadPtr:
29467 return ir_analyze_instruction_load_ptr(ira, (IrInstSrcLoadPtr *)instruction);
29468 case IrInstSrcIdStorePtr:
29469 return ir_analyze_instruction_store_ptr(ira, (IrInstSrcStorePtr *)instruction);
29470 case IrInstSrcIdElemPtr:
29471 return ir_analyze_instruction_elem_ptr(ira, (IrInstSrcElemPtr *)instruction);
29472 case IrInstSrcIdVarPtr:
29473 return ir_analyze_instruction_var_ptr(ira, (IrInstSrcVarPtr *)instruction);
29474 case IrInstSrcIdFieldPtr:
29475 return ir_analyze_instruction_field_ptr(ira, (IrInstSrcFieldPtr *)instruction);
29476 case IrInstSrcIdCall:
29477 return ir_analyze_instruction_call(ira, (IrInstSrcCall *)instruction);
29478 case IrInstSrcIdCallArgs:
29479 return ir_analyze_instruction_call_args(ira, (IrInstSrcCallArgs *)instruction);
29480 case IrInstSrcIdCallExtra:
29481 return ir_analyze_instruction_call_extra(ira, (IrInstSrcCallExtra *)instruction);
29482 case IrInstSrcIdBr:
29483 return ir_analyze_instruction_br(ira, (IrInstSrcBr *)instruction);
29484 case IrInstSrcIdCondBr:
29485 return ir_analyze_instruction_cond_br(ira, (IrInstSrcCondBr *)instruction);
29486 case IrInstSrcIdUnreachable:
29487 return ir_analyze_instruction_unreachable(ira, (IrInstSrcUnreachable *)instruction);
29488 case IrInstSrcIdPhi:
29489 return ir_analyze_instruction_phi(ira, (IrInstSrcPhi *)instruction);
29490 case IrInstSrcIdTypeOf:
29491 return ir_analyze_instruction_typeof(ira, (IrInstSrcTypeOf *)instruction);
29492 case IrInstSrcIdSetCold:
29493 return ir_analyze_instruction_set_cold(ira, (IrInstSrcSetCold *)instruction);
29494 case IrInstSrcIdSetRuntimeSafety:
29495 return ir_analyze_instruction_set_runtime_safety(ira, (IrInstSrcSetRuntimeSafety *)instruction);
29496 case IrInstSrcIdSetFloatMode:
29497 return ir_analyze_instruction_set_float_mode(ira, (IrInstSrcSetFloatMode *)instruction);
29498 case IrInstSrcIdAnyFrameType:
29499 return ir_analyze_instruction_any_frame_type(ira, (IrInstSrcAnyFrameType *)instruction);
29500 case IrInstSrcIdSliceType:
29501 return ir_analyze_instruction_slice_type(ira, (IrInstSrcSliceType *)instruction);
29502 case IrInstSrcIdAsm:
29503 return ir_analyze_instruction_asm(ira, (IrInstSrcAsm *)instruction);
29504 case IrInstSrcIdArrayType:
29505 return ir_analyze_instruction_array_type(ira, (IrInstSrcArrayType *)instruction);
29506 case IrInstSrcIdSizeOf:
29507 return ir_analyze_instruction_size_of(ira, (IrInstSrcSizeOf *)instruction);
29508 case IrInstSrcIdTestNonNull:
29509 return ir_analyze_instruction_test_non_null(ira, (IrInstSrcTestNonNull *)instruction);
29510 case IrInstSrcIdOptionalUnwrapPtr:
29511 return ir_analyze_instruction_optional_unwrap_ptr(ira, (IrInstSrcOptionalUnwrapPtr *)instruction);
29512 case IrInstSrcIdClz:
29513 return ir_analyze_instruction_clz(ira, (IrInstSrcClz *)instruction);
29514 case IrInstSrcIdCtz:
29515 return ir_analyze_instruction_ctz(ira, (IrInstSrcCtz *)instruction);
29516 case IrInstSrcIdPopCount:
29517 return ir_analyze_instruction_pop_count(ira, (IrInstSrcPopCount *)instruction);
29518 case IrInstSrcIdBswap:
29519 return ir_analyze_instruction_bswap(ira, (IrInstSrcBswap *)instruction);
29520 case IrInstSrcIdBitReverse:
29521 return ir_analyze_instruction_bit_reverse(ira, (IrInstSrcBitReverse *)instruction);
29522 case IrInstSrcIdSwitchBr:
29523 return ir_analyze_instruction_switch_br(ira, (IrInstSrcSwitchBr *)instruction);
29524 case IrInstSrcIdSwitchTarget:
29525 return ir_analyze_instruction_switch_target(ira, (IrInstSrcSwitchTarget *)instruction);
29526 case IrInstSrcIdSwitchVar:
29527 return ir_analyze_instruction_switch_var(ira, (IrInstSrcSwitchVar *)instruction);
29528 case IrInstSrcIdSwitchElseVar:
29529 return ir_analyze_instruction_switch_else_var(ira, (IrInstSrcSwitchElseVar *)instruction);
29530 case IrInstSrcIdImport:
29531 return ir_analyze_instruction_import(ira, (IrInstSrcImport *)instruction);
29532 case IrInstSrcIdRef:
29533 return ir_analyze_instruction_ref(ira, (IrInstSrcRef *)instruction);
29534 case IrInstSrcIdContainerInitList:
29535 return ir_analyze_instruction_container_init_list(ira, (IrInstSrcContainerInitList *)instruction);
29536 case IrInstSrcIdContainerInitFields:
29537 return ir_analyze_instruction_container_init_fields(ira, (IrInstSrcContainerInitFields *)instruction);
29538 case IrInstSrcIdCompileErr:
29539 return ir_analyze_instruction_compile_err(ira, (IrInstSrcCompileErr *)instruction);
29540 case IrInstSrcIdCompileLog:
29541 return ir_analyze_instruction_compile_log(ira, (IrInstSrcCompileLog *)instruction);
29542 case IrInstSrcIdErrName:
29543 return ir_analyze_instruction_err_name(ira, (IrInstSrcErrName *)instruction);
29544 case IrInstSrcIdTypeName:
29545 return ir_analyze_instruction_type_name(ira, (IrInstSrcTypeName *)instruction);
29546 case IrInstSrcIdCImport:
29547 return ir_analyze_instruction_c_import(ira, (IrInstSrcCImport *)instruction);
29548 case IrInstSrcIdCInclude:
29549 return ir_analyze_instruction_c_include(ira, (IrInstSrcCInclude *)instruction);
29550 case IrInstSrcIdCDefine:
29551 return ir_analyze_instruction_c_define(ira, (IrInstSrcCDefine *)instruction);
29552 case IrInstSrcIdCUndef:
29553 return ir_analyze_instruction_c_undef(ira, (IrInstSrcCUndef *)instruction);
29554 case IrInstSrcIdEmbedFile:
29555 return ir_analyze_instruction_embed_file(ira, (IrInstSrcEmbedFile *)instruction);
29556 case IrInstSrcIdCmpxchg:
29557 return ir_analyze_instruction_cmpxchg(ira, (IrInstSrcCmpxchg *)instruction);
29558 case IrInstSrcIdFence:
29559 return ir_analyze_instruction_fence(ira, (IrInstSrcFence *)instruction);
29560 case IrInstSrcIdTruncate:
29561 return ir_analyze_instruction_truncate(ira, (IrInstSrcTruncate *)instruction);
29562 case IrInstSrcIdIntCast:
29563 return ir_analyze_instruction_int_cast(ira, (IrInstSrcIntCast *)instruction);
29564 case IrInstSrcIdFloatCast:
29565 return ir_analyze_instruction_float_cast(ira, (IrInstSrcFloatCast *)instruction);
29566 case IrInstSrcIdErrSetCast:
29567 return ir_analyze_instruction_err_set_cast(ira, (IrInstSrcErrSetCast *)instruction);
29568 case IrInstSrcIdFromBytes:
29569 return ir_analyze_instruction_from_bytes(ira, (IrInstSrcFromBytes *)instruction);
29570 case IrInstSrcIdToBytes:
29571 return ir_analyze_instruction_to_bytes(ira, (IrInstSrcToBytes *)instruction);
29572 case IrInstSrcIdIntToFloat:
29573 return ir_analyze_instruction_int_to_float(ira, (IrInstSrcIntToFloat *)instruction);
29574 case IrInstSrcIdFloatToInt:
29575 return ir_analyze_instruction_float_to_int(ira, (IrInstSrcFloatToInt *)instruction);
29576 case IrInstSrcIdBoolToInt:
29577 return ir_analyze_instruction_bool_to_int(ira, (IrInstSrcBoolToInt *)instruction);
29578 case IrInstSrcIdIntType:
29579 return ir_analyze_instruction_int_type(ira, (IrInstSrcIntType *)instruction);
29580 case IrInstSrcIdVectorType:
29581 return ir_analyze_instruction_vector_type(ira, (IrInstSrcVectorType *)instruction);
29582 case IrInstSrcIdShuffleVector:
29583 return ir_analyze_instruction_shuffle_vector(ira, (IrInstSrcShuffleVector *)instruction);
29584 case IrInstSrcIdSplat:
29585 return ir_analyze_instruction_splat(ira, (IrInstSrcSplat *)instruction);
29586 case IrInstSrcIdBoolNot:
29587 return ir_analyze_instruction_bool_not(ira, (IrInstSrcBoolNot *)instruction);
29588 case IrInstSrcIdMemset:
29589 return ir_analyze_instruction_memset(ira, (IrInstSrcMemset *)instruction);
29590 case IrInstSrcIdMemcpy:
29591 return ir_analyze_instruction_memcpy(ira, (IrInstSrcMemcpy *)instruction);
29592 case IrInstSrcIdSlice:
29593 return ir_analyze_instruction_slice(ira, (IrInstSrcSlice *)instruction);
29594 case IrInstSrcIdMemberCount:
29595 return ir_analyze_instruction_member_count(ira, (IrInstSrcMemberCount *)instruction);
29596 case IrInstSrcIdMemberType:
29597 return ir_analyze_instruction_member_type(ira, (IrInstSrcMemberType *)instruction);
29598 case IrInstSrcIdMemberName:
29599 return ir_analyze_instruction_member_name(ira, (IrInstSrcMemberName *)instruction);
29600 case IrInstSrcIdBreakpoint:
29601 return ir_analyze_instruction_breakpoint(ira, (IrInstSrcBreakpoint *)instruction);
29602 case IrInstSrcIdReturnAddress:
29603 return ir_analyze_instruction_return_address(ira, (IrInstSrcReturnAddress *)instruction);
29604 case IrInstSrcIdFrameAddress:
29605 return ir_analyze_instruction_frame_address(ira, (IrInstSrcFrameAddress *)instruction);
29606 case IrInstSrcIdFrameHandle:
29607 return ir_analyze_instruction_frame_handle(ira, (IrInstSrcFrameHandle *)instruction);
29608 case IrInstSrcIdFrameType:
29609 return ir_analyze_instruction_frame_type(ira, (IrInstSrcFrameType *)instruction);
29610 case IrInstSrcIdFrameSize:
29611 return ir_analyze_instruction_frame_size(ira, (IrInstSrcFrameSize *)instruction);
29612 case IrInstSrcIdAlignOf:
29613 return ir_analyze_instruction_align_of(ira, (IrInstSrcAlignOf *)instruction);
29614 case IrInstSrcIdOverflowOp:
29615 return ir_analyze_instruction_overflow_op(ira, (IrInstSrcOverflowOp *)instruction);
29616 case IrInstSrcIdTestErr:
29617 return ir_analyze_instruction_test_err(ira, (IrInstSrcTestErr *)instruction);
29618 case IrInstSrcIdUnwrapErrCode:
29619 return ir_analyze_instruction_unwrap_err_code(ira, (IrInstSrcUnwrapErrCode *)instruction);
29620 case IrInstSrcIdUnwrapErrPayload:
29621 return ir_analyze_instruction_unwrap_err_payload(ira, (IrInstSrcUnwrapErrPayload *)instruction);
29622 case IrInstSrcIdFnProto:
29623 return ir_analyze_instruction_fn_proto(ira, (IrInstSrcFnProto *)instruction);
29624 case IrInstSrcIdTestComptime:
29625 return ir_analyze_instruction_test_comptime(ira, (IrInstSrcTestComptime *)instruction);
29626 case IrInstSrcIdCheckSwitchProngs:
29627 return ir_analyze_instruction_check_switch_prongs(ira, (IrInstSrcCheckSwitchProngs *)instruction);
29628 case IrInstSrcIdCheckStatementIsVoid:
29629 return ir_analyze_instruction_check_statement_is_void(ira, (IrInstSrcCheckStatementIsVoid *)instruction);
29630 case IrInstSrcIdDeclRef:
29631 return ir_analyze_instruction_decl_ref(ira, (IrInstSrcDeclRef *)instruction);
29632 case IrInstSrcIdPanic:
29633 return ir_analyze_instruction_panic(ira, (IrInstSrcPanic *)instruction);
29634 case IrInstSrcIdPtrCast:
29635 return ir_analyze_instruction_ptr_cast(ira, (IrInstSrcPtrCast *)instruction);
29636 case IrInstSrcIdIntToPtr:
29637 return ir_analyze_instruction_int_to_ptr(ira, (IrInstSrcIntToPtr *)instruction);
29638 case IrInstSrcIdPtrToInt:
29639 return ir_analyze_instruction_ptr_to_int(ira, (IrInstSrcPtrToInt *)instruction);
29640 case IrInstSrcIdTagName:
29641 return ir_analyze_instruction_enum_tag_name(ira, (IrInstSrcTagName *)instruction);
29642 case IrInstSrcIdFieldParentPtr:
29643 return ir_analyze_instruction_field_parent_ptr(ira, (IrInstSrcFieldParentPtr *)instruction);
29644 case IrInstSrcIdByteOffsetOf:
29645 return ir_analyze_instruction_byte_offset_of(ira, (IrInstSrcByteOffsetOf *)instruction);
29646 case IrInstSrcIdBitOffsetOf:
29647 return ir_analyze_instruction_bit_offset_of(ira, (IrInstSrcBitOffsetOf *)instruction);
29648 case IrInstSrcIdTypeInfo:
29649 return ir_analyze_instruction_type_info(ira, (IrInstSrcTypeInfo *) instruction);
29650 case IrInstSrcIdType:
29651 return ir_analyze_instruction_type(ira, (IrInstSrcType *)instruction);
29652 case IrInstSrcIdHasField:
29653 return ir_analyze_instruction_has_field(ira, (IrInstSrcHasField *) instruction);
29654 case IrInstSrcIdTypeId:
29655 return ir_analyze_instruction_type_id(ira, (IrInstSrcTypeId *)instruction);
29656 case IrInstSrcIdSetEvalBranchQuota:
29657 return ir_analyze_instruction_set_eval_branch_quota(ira, (IrInstSrcSetEvalBranchQuota *)instruction);
29658 case IrInstSrcIdPtrType:
29659 return ir_analyze_instruction_ptr_type(ira, (IrInstSrcPtrType *)instruction);
29660 case IrInstSrcIdAlignCast:
29661 return ir_analyze_instruction_align_cast(ira, (IrInstSrcAlignCast *)instruction);
29662 case IrInstSrcIdImplicitCast:
29663 return ir_analyze_instruction_implicit_cast(ira, (IrInstSrcImplicitCast *)instruction);
29664 case IrInstSrcIdResolveResult:
29665 return ir_analyze_instruction_resolve_result(ira, (IrInstSrcResolveResult *)instruction);
29666 case IrInstSrcIdResetResult:
29667 return ir_analyze_instruction_reset_result(ira, (IrInstSrcResetResult *)instruction);
29668 case IrInstSrcIdOpaqueType:
29669 return ir_analyze_instruction_opaque_type(ira, (IrInstSrcOpaqueType *)instruction);
29670 case IrInstSrcIdSetAlignStack:
29671 return ir_analyze_instruction_set_align_stack(ira, (IrInstSrcSetAlignStack *)instruction);
29672 case IrInstSrcIdArgType:
29673 return ir_analyze_instruction_arg_type(ira, (IrInstSrcArgType *)instruction);
29674 case IrInstSrcIdTagType:
29675 return ir_analyze_instruction_tag_type(ira, (IrInstSrcTagType *)instruction);
29676 case IrInstSrcIdExport:
29677 return ir_analyze_instruction_export(ira, (IrInstSrcExport *)instruction);
29678 case IrInstSrcIdErrorReturnTrace:
29679 return ir_analyze_instruction_error_return_trace(ira, (IrInstSrcErrorReturnTrace *)instruction);
29680 case IrInstSrcIdErrorUnion:
29681 return ir_analyze_instruction_error_union(ira, (IrInstSrcErrorUnion *)instruction);
29682 case IrInstSrcIdAtomicRmw:
29683 return ir_analyze_instruction_atomic_rmw(ira, (IrInstSrcAtomicRmw *)instruction);
29684 case IrInstSrcIdAtomicLoad:
29685 return ir_analyze_instruction_atomic_load(ira, (IrInstSrcAtomicLoad *)instruction);
29686 case IrInstSrcIdAtomicStore:
29687 return ir_analyze_instruction_atomic_store(ira, (IrInstSrcAtomicStore *)instruction);
29688 case IrInstSrcIdSaveErrRetAddr:
29689 return ir_analyze_instruction_save_err_ret_addr(ira, (IrInstSrcSaveErrRetAddr *)instruction);
29690 case IrInstSrcIdAddImplicitReturnType:
29691 return ir_analyze_instruction_add_implicit_return_type(ira, (IrInstSrcAddImplicitReturnType *)instruction);
29692 case IrInstSrcIdFloatOp:
29693 return ir_analyze_instruction_float_op(ira, (IrInstSrcFloatOp *)instruction);
29694 case IrInstSrcIdMulAdd:
29695 return ir_analyze_instruction_mul_add(ira, (IrInstSrcMulAdd *)instruction);
29696 case IrInstSrcIdIntToErr:
29697 return ir_analyze_instruction_int_to_err(ira, (IrInstSrcIntToErr *)instruction);
29698 case IrInstSrcIdErrToInt:
29699 return ir_analyze_instruction_err_to_int(ira, (IrInstSrcErrToInt *)instruction);
29700 case IrInstSrcIdIntToEnum:
29701 return ir_analyze_instruction_int_to_enum(ira, (IrInstSrcIntToEnum *)instruction);
29702 case IrInstSrcIdEnumToInt:
29703 return ir_analyze_instruction_enum_to_int(ira, (IrInstSrcEnumToInt *)instruction);
29704 case IrInstSrcIdCheckRuntimeScope:
29705 return ir_analyze_instruction_check_runtime_scope(ira, (IrInstSrcCheckRuntimeScope *)instruction);
29706 case IrInstSrcIdHasDecl:
29707 return ir_analyze_instruction_has_decl(ira, (IrInstSrcHasDecl *)instruction);
29708 case IrInstSrcIdUndeclaredIdent:
29709 return ir_analyze_instruction_undeclared_ident(ira, (IrInstSrcUndeclaredIdent *)instruction);
29710 case IrInstSrcIdAlloca:
2894429711 return nullptr;
28945 case IrInstructionIdEndExpr:
28946 return ir_analyze_instruction_end_expr(ira, (IrInstructionEndExpr *)instruction);
28947 case IrInstructionIdBitCastSrc:
28948 return ir_analyze_instruction_bit_cast_src(ira, (IrInstructionBitCastSrc *)instruction);
28949 case IrInstructionIdUnionInitNamedField:
28950 return ir_analyze_instruction_union_init_named_field(ira, (IrInstructionUnionInitNamedField *)instruction);
28951 case IrInstructionIdSuspendBegin:
28952 return ir_analyze_instruction_suspend_begin(ira, (IrInstructionSuspendBegin *)instruction);
28953 case IrInstructionIdSuspendFinish:
28954 return ir_analyze_instruction_suspend_finish(ira, (IrInstructionSuspendFinish *)instruction);
28955 case IrInstructionIdResume:
28956 return ir_analyze_instruction_resume(ira, (IrInstructionResume *)instruction);
28957 case IrInstructionIdAwaitSrc:
28958 return ir_analyze_instruction_await(ira, (IrInstructionAwaitSrc *)instruction);
28959 case IrInstructionIdSpillBegin:
28960 return ir_analyze_instruction_spill_begin(ira, (IrInstructionSpillBegin *)instruction);
28961 case IrInstructionIdSpillEnd:
28962 return ir_analyze_instruction_spill_end(ira, (IrInstructionSpillEnd *)instruction);
29712 case IrInstSrcIdEndExpr:
29713 return ir_analyze_instruction_end_expr(ira, (IrInstSrcEndExpr *)instruction);
29714 case IrInstSrcIdBitCast:
29715 return ir_analyze_instruction_bit_cast_src(ira, (IrInstSrcBitCast *)instruction);
29716 case IrInstSrcIdUnionInitNamedField:
29717 return ir_analyze_instruction_union_init_named_field(ira, (IrInstSrcUnionInitNamedField *)instruction);
29718 case IrInstSrcIdSuspendBegin:
29719 return ir_analyze_instruction_suspend_begin(ira, (IrInstSrcSuspendBegin *)instruction);
29720 case IrInstSrcIdSuspendFinish:
29721 return ir_analyze_instruction_suspend_finish(ira, (IrInstSrcSuspendFinish *)instruction);
29722 case IrInstSrcIdResume:
29723 return ir_analyze_instruction_resume(ira, (IrInstSrcResume *)instruction);
29724 case IrInstSrcIdAwait:
29725 return ir_analyze_instruction_await(ira, (IrInstSrcAwait *)instruction);
29726 case IrInstSrcIdSpillBegin:
29727 return ir_analyze_instruction_spill_begin(ira, (IrInstSrcSpillBegin *)instruction);
29728 case IrInstSrcIdSpillEnd:
29729 return ir_analyze_instruction_spill_end(ira, (IrInstSrcSpillEnd *)instruction);
2896329730 }
2896429731 zig_unreachable();
2896529732}
2896629733
2896729734// This function attempts to evaluate IR code while doing type checking and other analysis.
28968// It emits a new IrExecutable which is partially evaluated IR code.
28969ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_exec,
29735// It emits to a new IrExecutableGen which is partially evaluated IR code.
29736ZigType *ir_analyze(CodeGen *codegen, IrExecutableSrc *old_exec, IrExecutableGen *new_exec,
2897029737 ZigType *expected_type, AstNode *expected_type_source_node)
2897129738{
2897229739 assert(old_exec->first_err_trace_msg == nullptr);
......@@ -28992,18 +29759,18 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
2899229759 ira->exec_context.mem_slot_list.items[i] = &vals[i];
2899329760 }
2899429761
28995 IrBasicBlock *old_entry_bb = ira->old_irb.exec->basic_block_list.at(0);
28996 IrBasicBlock *new_entry_bb = ir_get_new_bb(ira, old_entry_bb, nullptr);
28997 ir_ref_bb(new_entry_bb);
29762 IrBasicBlockSrc *old_entry_bb = ira->old_irb.exec->basic_block_list.at(0);
29763 IrBasicBlockGen *new_entry_bb = ir_get_new_bb(ira, old_entry_bb, nullptr);
29764 ir_ref_bb_gen(new_entry_bb);
2899829765 ira->new_irb.current_basic_block = new_entry_bb;
2899929766 ira->old_bb_index = 0;
2900029767
2900129768 ir_start_bb(ira, old_entry_bb, nullptr);
2900229769
2900329770 while (ira->old_bb_index < ira->old_irb.exec->basic_block_list.length) {
29004 IrInstruction *old_instruction = ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index);
29771 IrInstSrc *old_instruction = ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index);
2900529772
29006 if (old_instruction->ref_count == 0 && !ir_has_side_effects(old_instruction)) {
29773 if (old_instruction->base.ref_count == 0 && !ir_inst_src_has_side_effects(old_instruction)) {
2900729774 ira->instruction_index += 1;
2900829775 continue;
2900929776 }
......@@ -29012,14 +29779,14 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
2901229779 fprintf(stderr, "~ ");
2901329780 old_instruction->src();
2901429781 fprintf(stderr, "~ ");
29015 ir_print_instruction(codegen, stderr, old_instruction, 0, IrPassSrc);
29782 ir_print_inst_src(codegen, stderr, old_instruction, 0);
2901629783 bool want_break = false;
29017 if (ira->break_debug_id == old_instruction->debug_id) {
29784 if (ira->break_debug_id == old_instruction->base.debug_id) {
2901829785 want_break = true;
29019 } else if (old_instruction->source_node != nullptr) {
29786 } else if (old_instruction->base.source_node != nullptr) {
2902029787 for (size_t i = 0; i < dbg_ir_breakpoints_count; i += 1) {
29021 if (dbg_ir_breakpoints_buf[i].line == old_instruction->source_node->line + 1 &&
29022 buf_ends_with_str(old_instruction->source_node->owner->data.structure.root_struct->path,
29788 if (dbg_ir_breakpoints_buf[i].line == old_instruction->base.source_node->line + 1 &&
29789 buf_ends_with_str(old_instruction->base.source_node->owner->data.structure.root_struct->path,
2902329790 dbg_ir_breakpoints_buf[i].src_file))
2902429791 {
2902529792 want_break = true;
......@@ -29028,9 +29795,9 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
2902829795 }
2902929796 if (want_break) BREAKPOINT;
2903029797 }
29031 IrInstruction *new_instruction = ir_analyze_instruction_base(ira, old_instruction);
29798 IrInstGen *new_instruction = ir_analyze_instruction_base(ira, old_instruction);
2903229799 if (new_instruction != nullptr) {
29033 ir_assert(new_instruction->value->type != nullptr || new_instruction->value->type != nullptr, old_instruction);
29800 ir_assert(new_instruction->value->type != nullptr || new_instruction->value->type != nullptr, &old_instruction->base);
2903429801 old_instruction->child = new_instruction;
2903529802
2903629803 if (type_is_invalid(new_instruction->value->type)) {
......@@ -29044,19 +29811,19 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
2904429811 new_exec->first_err_trace_msg = ira->codegen->trace_err;
2904529812 }
2904629813 if (new_exec->first_err_trace_msg != nullptr &&
29047 !old_instruction->source_node->already_traced_this_node)
29814 !old_instruction->base.source_node->already_traced_this_node)
2904829815 {
29049 old_instruction->source_node->already_traced_this_node = true;
29816 old_instruction->base.source_node->already_traced_this_node = true;
2905029817 new_exec->first_err_trace_msg = add_error_note(ira->codegen, new_exec->first_err_trace_msg,
29051 old_instruction->source_node, buf_create_from_str("referenced here"));
29818 old_instruction->base.source_node, buf_create_from_str("referenced here"));
2905229819 }
2905329820 return ira->codegen->builtin_types.entry_invalid;
2905429821 } else if (ira->codegen->verbose_ir) {
2905529822 fprintf(stderr, "-> ");
29056 if (instr_is_unreachable(new_instruction)) {
29823 if (new_instruction->value->type->id == ZigTypeIdUnreachable) {
2905729824 fprintf(stderr, "(noreturn)\n");
2905829825 } else {
29059 ir_print_instruction(codegen, stderr, new_instruction, 0, IrPassGen);
29826 ir_print_inst_gen(codegen, stderr, new_instruction, 0);
2906029827 }
2906129828 }
2906229829
......@@ -29096,204 +29863,279 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
2909629863 return res_type;
2909729864}
2909829865
29099bool ir_has_side_effects(IrInstruction *instruction) {
29866bool ir_inst_gen_has_side_effects(IrInstGen *instruction) {
2910029867 switch (instruction->id) {
29101 case IrInstructionIdInvalid:
29868 case IrInstGenIdInvalid:
2910229869 zig_unreachable();
29103 case IrInstructionIdBr:
29104 case IrInstructionIdCondBr:
29105 case IrInstructionIdSwitchBr:
29106 case IrInstructionIdDeclVarSrc:
29107 case IrInstructionIdDeclVarGen:
29108 case IrInstructionIdStorePtr:
29109 case IrInstructionIdVectorStoreElem:
29110 case IrInstructionIdCallExtra:
29111 case IrInstructionIdCallSrc:
29112 case IrInstructionIdCallSrcArgs:
29113 case IrInstructionIdCallGen:
29114 case IrInstructionIdReturn:
29115 case IrInstructionIdUnreachable:
29116 case IrInstructionIdSetCold:
29117 case IrInstructionIdSetRuntimeSafety:
29118 case IrInstructionIdSetFloatMode:
29119 case IrInstructionIdImport:
29120 case IrInstructionIdCompileErr:
29121 case IrInstructionIdCompileLog:
29122 case IrInstructionIdCImport:
29123 case IrInstructionIdCInclude:
29124 case IrInstructionIdCDefine:
29125 case IrInstructionIdCUndef:
29126 case IrInstructionIdFence:
29127 case IrInstructionIdMemset:
29128 case IrInstructionIdMemcpy:
29129 case IrInstructionIdBreakpoint:
29130 case IrInstructionIdOverflowOp: // TODO when we support multiple returns this can be side effect free
29131 case IrInstructionIdCheckSwitchProngs:
29132 case IrInstructionIdCheckStatementIsVoid:
29133 case IrInstructionIdCheckRuntimeScope:
29134 case IrInstructionIdPanic:
29135 case IrInstructionIdSetEvalBranchQuota:
29136 case IrInstructionIdPtrType:
29137 case IrInstructionIdSetAlignStack:
29138 case IrInstructionIdExport:
29139 case IrInstructionIdSaveErrRetAddr:
29140 case IrInstructionIdAddImplicitReturnType:
29141 case IrInstructionIdAtomicRmw:
29142 case IrInstructionIdAtomicStore:
29143 case IrInstructionIdCmpxchgGen:
29144 case IrInstructionIdCmpxchgSrc:
29145 case IrInstructionIdAssertZero:
29146 case IrInstructionIdAssertNonNull:
29147 case IrInstructionIdResizeSlice:
29148 case IrInstructionIdUndeclaredIdent:
29149 case IrInstructionIdEndExpr:
29150 case IrInstructionIdPtrOfArrayToSlice:
29151 case IrInstructionIdSliceGen:
29152 case IrInstructionIdOptionalWrap:
29153 case IrInstructionIdVectorToArray:
29154 case IrInstructionIdResetResult:
29155 case IrInstructionIdSuspendBegin:
29156 case IrInstructionIdSuspendFinish:
29157 case IrInstructionIdResume:
29158 case IrInstructionIdAwaitSrc:
29159 case IrInstructionIdAwaitGen:
29160 case IrInstructionIdSpillBegin:
29870 case IrInstGenIdBr:
29871 case IrInstGenIdCondBr:
29872 case IrInstGenIdSwitchBr:
29873 case IrInstGenIdDeclVar:
29874 case IrInstGenIdStorePtr:
29875 case IrInstGenIdVectorStoreElem:
29876 case IrInstGenIdCall:
29877 case IrInstGenIdReturn:
29878 case IrInstGenIdUnreachable:
29879 case IrInstGenIdFence:
29880 case IrInstGenIdMemset:
29881 case IrInstGenIdMemcpy:
29882 case IrInstGenIdBreakpoint:
29883 case IrInstGenIdOverflowOp: // TODO when we support multiple returns this can be side effect free
29884 case IrInstGenIdPanic:
29885 case IrInstGenIdSaveErrRetAddr:
29886 case IrInstGenIdAtomicRmw:
29887 case IrInstGenIdAtomicStore:
29888 case IrInstGenIdCmpxchg:
29889 case IrInstGenIdAssertZero:
29890 case IrInstGenIdAssertNonNull:
29891 case IrInstGenIdResizeSlice:
29892 case IrInstGenIdPtrOfArrayToSlice:
29893 case IrInstGenIdSlice:
29894 case IrInstGenIdOptionalWrap:
29895 case IrInstGenIdVectorToArray:
29896 case IrInstGenIdSuspendBegin:
29897 case IrInstGenIdSuspendFinish:
29898 case IrInstGenIdResume:
29899 case IrInstGenIdAwait:
29900 case IrInstGenIdSpillBegin:
2916129901 return true;
2916229902
29163 case IrInstructionIdPhi:
29164 case IrInstructionIdUnOp:
29165 case IrInstructionIdBinOp:
29166 case IrInstructionIdMergeErrSets:
29167 case IrInstructionIdLoadPtr:
29168 case IrInstructionIdConst:
29169 case IrInstructionIdCast:
29170 case IrInstructionIdContainerInitList:
29171 case IrInstructionIdContainerInitFields:
29172 case IrInstructionIdUnionInitNamedField:
29173 case IrInstructionIdFieldPtr:
29174 case IrInstructionIdElemPtr:
29175 case IrInstructionIdVarPtr:
29176 case IrInstructionIdReturnPtr:
29177 case IrInstructionIdTypeOf:
29178 case IrInstructionIdStructFieldPtr:
29179 case IrInstructionIdArrayType:
29180 case IrInstructionIdSliceType:
29181 case IrInstructionIdAnyFrameType:
29182 case IrInstructionIdSizeOf:
29183 case IrInstructionIdTestNonNull:
29184 case IrInstructionIdOptionalUnwrapPtr:
29185 case IrInstructionIdClz:
29186 case IrInstructionIdCtz:
29187 case IrInstructionIdPopCount:
29188 case IrInstructionIdBswap:
29189 case IrInstructionIdBitReverse:
29190 case IrInstructionIdSwitchVar:
29191 case IrInstructionIdSwitchElseVar:
29192 case IrInstructionIdSwitchTarget:
29193 case IrInstructionIdUnionTag:
29194 case IrInstructionIdRef:
29195 case IrInstructionIdEmbedFile:
29196 case IrInstructionIdTruncate:
29197 case IrInstructionIdIntType:
29198 case IrInstructionIdVectorType:
29199 case IrInstructionIdShuffleVector:
29200 case IrInstructionIdSplatSrc:
29201 case IrInstructionIdSplatGen:
29202 case IrInstructionIdBoolNot:
29203 case IrInstructionIdSliceSrc:
29204 case IrInstructionIdMemberCount:
29205 case IrInstructionIdMemberType:
29206 case IrInstructionIdMemberName:
29207 case IrInstructionIdAlignOf:
29208 case IrInstructionIdReturnAddress:
29209 case IrInstructionIdFrameAddress:
29210 case IrInstructionIdFrameHandle:
29211 case IrInstructionIdFrameType:
29212 case IrInstructionIdFrameSizeSrc:
29213 case IrInstructionIdFrameSizeGen:
29214 case IrInstructionIdTestErrSrc:
29215 case IrInstructionIdTestErrGen:
29216 case IrInstructionIdFnProto:
29217 case IrInstructionIdTestComptime:
29218 case IrInstructionIdPtrCastSrc:
29219 case IrInstructionIdPtrCastGen:
29220 case IrInstructionIdBitCastSrc:
29221 case IrInstructionIdBitCastGen:
29222 case IrInstructionIdWidenOrShorten:
29223 case IrInstructionIdPtrToInt:
29224 case IrInstructionIdIntToPtr:
29225 case IrInstructionIdIntToEnum:
29226 case IrInstructionIdIntToErr:
29227 case IrInstructionIdErrToInt:
29228 case IrInstructionIdDeclRef:
29229 case IrInstructionIdErrName:
29230 case IrInstructionIdTypeName:
29231 case IrInstructionIdTagName:
29232 case IrInstructionIdFieldParentPtr:
29233 case IrInstructionIdByteOffsetOf:
29234 case IrInstructionIdBitOffsetOf:
29235 case IrInstructionIdTypeInfo:
29236 case IrInstructionIdType:
29237 case IrInstructionIdHasField:
29238 case IrInstructionIdTypeId:
29239 case IrInstructionIdAlignCast:
29240 case IrInstructionIdImplicitCast:
29241 case IrInstructionIdResolveResult:
29242 case IrInstructionIdOpaqueType:
29243 case IrInstructionIdArgType:
29244 case IrInstructionIdTagType:
29245 case IrInstructionIdErrorReturnTrace:
29246 case IrInstructionIdErrorUnion:
29247 case IrInstructionIdFloatOp:
29248 case IrInstructionIdMulAdd:
29249 case IrInstructionIdAtomicLoad:
29250 case IrInstructionIdIntCast:
29251 case IrInstructionIdFloatCast:
29252 case IrInstructionIdErrSetCast:
29253 case IrInstructionIdIntToFloat:
29254 case IrInstructionIdFloatToInt:
29255 case IrInstructionIdBoolToInt:
29256 case IrInstructionIdFromBytes:
29257 case IrInstructionIdToBytes:
29258 case IrInstructionIdEnumToInt:
29259 case IrInstructionIdArrayToVector:
29260 case IrInstructionIdHasDecl:
29261 case IrInstructionIdAllocaSrc:
29262 case IrInstructionIdAllocaGen:
29263 case IrInstructionIdSpillEnd:
29264 case IrInstructionIdVectorExtractElem:
29903 case IrInstGenIdPhi:
29904 case IrInstGenIdBinOp:
29905 case IrInstGenIdConst:
29906 case IrInstGenIdCast:
29907 case IrInstGenIdElemPtr:
29908 case IrInstGenIdVarPtr:
29909 case IrInstGenIdReturnPtr:
29910 case IrInstGenIdStructFieldPtr:
29911 case IrInstGenIdTestNonNull:
29912 case IrInstGenIdOptionalUnwrapPtr:
29913 case IrInstGenIdClz:
29914 case IrInstGenIdCtz:
29915 case IrInstGenIdPopCount:
29916 case IrInstGenIdBswap:
29917 case IrInstGenIdBitReverse:
29918 case IrInstGenIdUnionTag:
29919 case IrInstGenIdTruncate:
29920 case IrInstGenIdShuffleVector:
29921 case IrInstGenIdSplat:
29922 case IrInstGenIdBoolNot:
29923 case IrInstGenIdReturnAddress:
29924 case IrInstGenIdFrameAddress:
29925 case IrInstGenIdFrameHandle:
29926 case IrInstGenIdFrameSize:
29927 case IrInstGenIdTestErr:
29928 case IrInstGenIdPtrCast:
29929 case IrInstGenIdBitCast:
29930 case IrInstGenIdWidenOrShorten:
29931 case IrInstGenIdPtrToInt:
29932 case IrInstGenIdIntToPtr:
29933 case IrInstGenIdIntToEnum:
29934 case IrInstGenIdIntToErr:
29935 case IrInstGenIdErrToInt:
29936 case IrInstGenIdErrName:
29937 case IrInstGenIdTagName:
29938 case IrInstGenIdFieldParentPtr:
29939 case IrInstGenIdAlignCast:
29940 case IrInstGenIdErrorReturnTrace:
29941 case IrInstGenIdFloatOp:
29942 case IrInstGenIdMulAdd:
29943 case IrInstGenIdAtomicLoad:
29944 case IrInstGenIdArrayToVector:
29945 case IrInstGenIdAlloca:
29946 case IrInstGenIdSpillEnd:
29947 case IrInstGenIdVectorExtractElem:
29948 case IrInstGenIdBinaryNot:
29949 case IrInstGenIdNegation:
29950 case IrInstGenIdNegationWrapping:
2926529951 return false;
2926629952
29267 case IrInstructionIdAsmSrc:
29953 case IrInstGenIdAsm:
2926829954 {
29269 IrInstructionAsmSrc *asm_instruction = (IrInstructionAsmSrc *)instruction;
29955 IrInstGenAsm *asm_instruction = (IrInstGenAsm *)instruction;
2927029956 return asm_instruction->has_side_effects;
2927129957 }
29958 case IrInstGenIdUnwrapErrPayload:
29959 {
29960 IrInstGenUnwrapErrPayload *unwrap_err_payload_instruction =
29961 (IrInstGenUnwrapErrPayload *)instruction;
29962 return unwrap_err_payload_instruction->safety_check_on ||
29963 unwrap_err_payload_instruction->initializing;
29964 }
29965 case IrInstGenIdUnwrapErrCode:
29966 return reinterpret_cast<IrInstGenUnwrapErrCode *>(instruction)->initializing;
29967 case IrInstGenIdUnionFieldPtr:
29968 return reinterpret_cast<IrInstGenUnionFieldPtr *>(instruction)->initializing;
29969 case IrInstGenIdErrWrapPayload:
29970 return reinterpret_cast<IrInstGenErrWrapPayload *>(instruction)->result_loc != nullptr;
29971 case IrInstGenIdErrWrapCode:
29972 return reinterpret_cast<IrInstGenErrWrapCode *>(instruction)->result_loc != nullptr;
29973 case IrInstGenIdLoadPtr:
29974 return reinterpret_cast<IrInstGenLoadPtr *>(instruction)->result_loc != nullptr;
29975 case IrInstGenIdRef:
29976 return reinterpret_cast<IrInstGenRef *>(instruction)->result_loc != nullptr;
29977 }
29978 zig_unreachable();
29979}
29980
29981bool ir_inst_src_has_side_effects(IrInstSrc *instruction) {
29982 switch (instruction->id) {
29983 case IrInstSrcIdInvalid:
29984 zig_unreachable();
29985 case IrInstSrcIdBr:
29986 case IrInstSrcIdCondBr:
29987 case IrInstSrcIdSwitchBr:
29988 case IrInstSrcIdDeclVar:
29989 case IrInstSrcIdStorePtr:
29990 case IrInstSrcIdCallExtra:
29991 case IrInstSrcIdCall:
29992 case IrInstSrcIdCallArgs:
29993 case IrInstSrcIdReturn:
29994 case IrInstSrcIdUnreachable:
29995 case IrInstSrcIdSetCold:
29996 case IrInstSrcIdSetRuntimeSafety:
29997 case IrInstSrcIdSetFloatMode:
29998 case IrInstSrcIdImport:
29999 case IrInstSrcIdCompileErr:
30000 case IrInstSrcIdCompileLog:
30001 case IrInstSrcIdCImport:
30002 case IrInstSrcIdCInclude:
30003 case IrInstSrcIdCDefine:
30004 case IrInstSrcIdCUndef:
30005 case IrInstSrcIdFence:
30006 case IrInstSrcIdMemset:
30007 case IrInstSrcIdMemcpy:
30008 case IrInstSrcIdBreakpoint:
30009 case IrInstSrcIdOverflowOp: // TODO when we support multiple returns this can be side effect free
30010 case IrInstSrcIdCheckSwitchProngs:
30011 case IrInstSrcIdCheckStatementIsVoid:
30012 case IrInstSrcIdCheckRuntimeScope:
30013 case IrInstSrcIdPanic:
30014 case IrInstSrcIdSetEvalBranchQuota:
30015 case IrInstSrcIdPtrType:
30016 case IrInstSrcIdSetAlignStack:
30017 case IrInstSrcIdExport:
30018 case IrInstSrcIdSaveErrRetAddr:
30019 case IrInstSrcIdAddImplicitReturnType:
30020 case IrInstSrcIdAtomicRmw:
30021 case IrInstSrcIdAtomicStore:
30022 case IrInstSrcIdCmpxchg:
30023 case IrInstSrcIdUndeclaredIdent:
30024 case IrInstSrcIdEndExpr:
30025 case IrInstSrcIdResetResult:
30026 case IrInstSrcIdSuspendBegin:
30027 case IrInstSrcIdSuspendFinish:
30028 case IrInstSrcIdResume:
30029 case IrInstSrcIdAwait:
30030 case IrInstSrcIdSpillBegin:
30031 return true;
30032
30033 case IrInstSrcIdPhi:
30034 case IrInstSrcIdUnOp:
30035 case IrInstSrcIdBinOp:
30036 case IrInstSrcIdMergeErrSets:
30037 case IrInstSrcIdLoadPtr:
30038 case IrInstSrcIdConst:
30039 case IrInstSrcIdContainerInitList:
30040 case IrInstSrcIdContainerInitFields:
30041 case IrInstSrcIdUnionInitNamedField:
30042 case IrInstSrcIdFieldPtr:
30043 case IrInstSrcIdElemPtr:
30044 case IrInstSrcIdVarPtr:
30045 case IrInstSrcIdTypeOf:
30046 case IrInstSrcIdArrayType:
30047 case IrInstSrcIdSliceType:
30048 case IrInstSrcIdAnyFrameType:
30049 case IrInstSrcIdSizeOf:
30050 case IrInstSrcIdTestNonNull:
30051 case IrInstSrcIdOptionalUnwrapPtr:
30052 case IrInstSrcIdClz:
30053 case IrInstSrcIdCtz:
30054 case IrInstSrcIdPopCount:
30055 case IrInstSrcIdBswap:
30056 case IrInstSrcIdBitReverse:
30057 case IrInstSrcIdSwitchVar:
30058 case IrInstSrcIdSwitchElseVar:
30059 case IrInstSrcIdSwitchTarget:
30060 case IrInstSrcIdRef:
30061 case IrInstSrcIdEmbedFile:
30062 case IrInstSrcIdTruncate:
30063 case IrInstSrcIdIntType:
30064 case IrInstSrcIdVectorType:
30065 case IrInstSrcIdShuffleVector:
30066 case IrInstSrcIdSplat:
30067 case IrInstSrcIdBoolNot:
30068 case IrInstSrcIdSlice:
30069 case IrInstSrcIdMemberCount:
30070 case IrInstSrcIdMemberType:
30071 case IrInstSrcIdMemberName:
30072 case IrInstSrcIdAlignOf:
30073 case IrInstSrcIdReturnAddress:
30074 case IrInstSrcIdFrameAddress:
30075 case IrInstSrcIdFrameHandle:
30076 case IrInstSrcIdFrameType:
30077 case IrInstSrcIdFrameSize:
30078 case IrInstSrcIdTestErr:
30079 case IrInstSrcIdFnProto:
30080 case IrInstSrcIdTestComptime:
30081 case IrInstSrcIdPtrCast:
30082 case IrInstSrcIdBitCast:
30083 case IrInstSrcIdPtrToInt:
30084 case IrInstSrcIdIntToPtr:
30085 case IrInstSrcIdIntToEnum:
30086 case IrInstSrcIdIntToErr:
30087 case IrInstSrcIdErrToInt:
30088 case IrInstSrcIdDeclRef:
30089 case IrInstSrcIdErrName:
30090 case IrInstSrcIdTypeName:
30091 case IrInstSrcIdTagName:
30092 case IrInstSrcIdFieldParentPtr:
30093 case IrInstSrcIdByteOffsetOf:
30094 case IrInstSrcIdBitOffsetOf:
30095 case IrInstSrcIdTypeInfo:
30096 case IrInstSrcIdType:
30097 case IrInstSrcIdHasField:
30098 case IrInstSrcIdTypeId:
30099 case IrInstSrcIdAlignCast:
30100 case IrInstSrcIdImplicitCast:
30101 case IrInstSrcIdResolveResult:
30102 case IrInstSrcIdOpaqueType:
30103 case IrInstSrcIdArgType:
30104 case IrInstSrcIdTagType:
30105 case IrInstSrcIdErrorReturnTrace:
30106 case IrInstSrcIdErrorUnion:
30107 case IrInstSrcIdFloatOp:
30108 case IrInstSrcIdMulAdd:
30109 case IrInstSrcIdAtomicLoad:
30110 case IrInstSrcIdIntCast:
30111 case IrInstSrcIdFloatCast:
30112 case IrInstSrcIdErrSetCast:
30113 case IrInstSrcIdIntToFloat:
30114 case IrInstSrcIdFloatToInt:
30115 case IrInstSrcIdBoolToInt:
30116 case IrInstSrcIdFromBytes:
30117 case IrInstSrcIdToBytes:
30118 case IrInstSrcIdEnumToInt:
30119 case IrInstSrcIdHasDecl:
30120 case IrInstSrcIdAlloca:
30121 case IrInstSrcIdSpillEnd:
30122 return false;
2927230123
29273 case IrInstructionIdAsmGen:
30124 case IrInstSrcIdAsm:
2927430125 {
29275 IrInstructionAsmGen *asm_instruction = (IrInstructionAsmGen *)instruction;
30126 IrInstSrcAsm *asm_instruction = (IrInstSrcAsm *)instruction;
2927630127 return asm_instruction->has_side_effects;
2927730128 }
29278 case IrInstructionIdUnwrapErrPayload:
30129
30130 case IrInstSrcIdUnwrapErrPayload:
2927930131 {
29280 IrInstructionUnwrapErrPayload *unwrap_err_payload_instruction =
29281 (IrInstructionUnwrapErrPayload *)instruction;
30132 IrInstSrcUnwrapErrPayload *unwrap_err_payload_instruction =
30133 (IrInstSrcUnwrapErrPayload *)instruction;
2928230134 return unwrap_err_payload_instruction->safety_check_on ||
2928330135 unwrap_err_payload_instruction->initializing;
2928430136 }
29285 case IrInstructionIdUnwrapErrCode:
29286 return reinterpret_cast<IrInstructionUnwrapErrCode *>(instruction)->initializing;
29287 case IrInstructionIdUnionFieldPtr:
29288 return reinterpret_cast<IrInstructionUnionFieldPtr *>(instruction)->initializing;
29289 case IrInstructionIdErrWrapPayload:
29290 return reinterpret_cast<IrInstructionErrWrapPayload *>(instruction)->result_loc != nullptr;
29291 case IrInstructionIdErrWrapCode:
29292 return reinterpret_cast<IrInstructionErrWrapCode *>(instruction)->result_loc != nullptr;
29293 case IrInstructionIdLoadPtrGen:
29294 return reinterpret_cast<IrInstructionLoadPtrGen *>(instruction)->result_loc != nullptr;
29295 case IrInstructionIdRefGen:
29296 return reinterpret_cast<IrInstructionRefGen *>(instruction)->result_loc != nullptr;
30137 case IrInstSrcIdUnwrapErrCode:
30138 return reinterpret_cast<IrInstSrcUnwrapErrCode *>(instruction)->initializing;
2929730139 }
2929830140 zig_unreachable();
2929930141}
......@@ -29327,14 +30169,14 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La
2932730169 param_info->type = nullptr;
2932830170 return get_generic_fn_type(ira->codegen, &fn_type_id);
2932930171 } else {
29330 IrInstruction *param_type_inst = lazy_fn_type->param_types[fn_type_id.next_param_index];
30172 IrInstGen *param_type_inst = lazy_fn_type->param_types[fn_type_id.next_param_index];
2933130173 ZigType *param_type = ir_resolve_type(ira, param_type_inst);
2933230174 if (type_is_invalid(param_type))
2933330175 return nullptr;
2933430176 switch (type_requires_comptime(ira->codegen, param_type)) {
2933530177 case ReqCompTimeYes:
2933630178 if (!calling_convention_allows_zig_types(fn_type_id.cc)) {
29337 ir_add_error(ira, param_type_inst,
30179 ir_add_error(ira, &param_type_inst->base,
2933830180 buf_sprintf("parameter of type '%s' not allowed in function with calling convention '%s'",
2933930181 buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc)));
2934030182 return nullptr;
......@@ -29352,7 +30194,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La
2935230194 if ((err = type_has_bits2(ira->codegen, param_type, &has_bits)))
2935330195 return nullptr;
2935430196 if (!has_bits) {
29355 ir_add_error(ira, param_type_inst,
30197 ir_add_error(ira, &param_type_inst->base,
2935630198 buf_sprintf("parameter of type '%s' has 0 bits; not allowed in function with calling convention '%s'",
2935730199 buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc)));
2935830200 return nullptr;
......@@ -29371,7 +30213,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La
2937130213 if (type_is_invalid(fn_type_id.return_type))
2937230214 return nullptr;
2937330215 if (fn_type_id.return_type->id == ZigTypeIdOpaque) {
29374 ir_add_error(ira, lazy_fn_type->return_type, buf_create_from_str("return type cannot be opaque"));
30216 ir_add_error(ira, &lazy_fn_type->return_type->base, buf_create_from_str("return type cannot be opaque"));
2937530217 return nullptr;
2937630218 }
2937730219
......@@ -29403,7 +30245,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2940330245 case ZigTypeIdBoundFn:
2940430246 case ZigTypeIdVoid:
2940530247 case ZigTypeIdOpaque:
29406 ir_add_error(ira, lazy_align_of->target_type,
30248 ir_add_error(ira, &lazy_align_of->target_type->base,
2940730249 buf_sprintf("no align available for type '%s'",
2940830250 buf_ptr(&lazy_align_of->target_type->value->data.x_type->name)));
2940930251 return ErrorSemanticAnalyzeFail;
......@@ -29453,7 +30295,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2945330295 case ZigTypeIdNull:
2945430296 case ZigTypeIdBoundFn:
2945530297 case ZigTypeIdOpaque:
29456 ir_add_error(ira, lazy_size_of->target_type,
30298 ir_add_error(ira, &lazy_size_of->target_type->base,
2945730299 buf_sprintf("no size available for type '%s'",
2945830300 buf_ptr(&lazy_size_of->target_type->value->data.x_type->name)));
2945930301 return ErrorSemanticAnalyzeFail;
......@@ -29511,7 +30353,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2951130353 if (lazy_slice_type->sentinel != nullptr) {
2951230354 if (type_is_invalid(lazy_slice_type->sentinel->value->type))
2951330355 return ErrorSemanticAnalyzeFail;
29514 IrInstruction *sentinel = ir_implicit_cast(ira, lazy_slice_type->sentinel, elem_type);
30356 IrInstGen *sentinel = ir_implicit_cast(ira, lazy_slice_type->sentinel, elem_type);
2951530357 if (type_is_invalid(sentinel->value->type))
2951630358 return ErrorSemanticAnalyzeFail;
2951730359 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);
......@@ -29534,7 +30376,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2953430376 case ZigTypeIdUndefined:
2953530377 case ZigTypeIdNull:
2953630378 case ZigTypeIdOpaque:
29537 ir_add_error(ira, lazy_slice_type->elem_type,
30379 ir_add_error(ira, &lazy_slice_type->elem_type->base,
2953830380 buf_sprintf("slice of type '%s' not allowed", buf_ptr(&elem_type->name)));
2953930381 return ErrorSemanticAnalyzeFail;
2954030382 case ZigTypeIdMetaType:
......@@ -29590,7 +30432,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2959030432 if (lazy_ptr_type->sentinel != nullptr) {
2959130433 if (type_is_invalid(lazy_ptr_type->sentinel->value->type))
2959230434 return ErrorSemanticAnalyzeFail;
29593 IrInstruction *sentinel = ir_implicit_cast(ira, lazy_ptr_type->sentinel, elem_type);
30435 IrInstGen *sentinel = ir_implicit_cast(ira, lazy_ptr_type->sentinel, elem_type);
2959430436 if (type_is_invalid(sentinel->value->type))
2959530437 return ErrorSemanticAnalyzeFail;
2959630438 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);
......@@ -29607,11 +30449,11 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2960730449 }
2960830450
2960930451 if (elem_type->id == ZigTypeIdUnreachable) {
29610 ir_add_error(ira, lazy_ptr_type->elem_type,
30452 ir_add_error(ira, &lazy_ptr_type->elem_type->base,
2961130453 buf_create_from_str("pointer to noreturn not allowed"));
2961230454 return ErrorSemanticAnalyzeFail;
2961330455 } else if (elem_type->id == ZigTypeIdOpaque && lazy_ptr_type->ptr_len == PtrLenUnknown) {
29614 ir_add_error(ira, lazy_ptr_type->elem_type,
30456 ir_add_error(ira, &lazy_ptr_type->elem_type->base,
2961530457 buf_create_from_str("unknown-length pointer to opaque"));
2961630458 return ErrorSemanticAnalyzeFail;
2961730459 } else if (lazy_ptr_type->ptr_len == PtrLenC) {
......@@ -29619,16 +30461,16 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2961930461 if ((err = type_allowed_in_extern(ira->codegen, elem_type, &ok_type)))
2962030462 return err;
2962130463 if (!ok_type) {
29622 ir_add_error(ira, lazy_ptr_type->elem_type,
30464 ir_add_error(ira, &lazy_ptr_type->elem_type->base,
2962330465 buf_sprintf("C pointers cannot point to non-C-ABI-compatible type '%s'",
2962430466 buf_ptr(&elem_type->name)));
2962530467 return ErrorSemanticAnalyzeFail;
2962630468 } else if (elem_type->id == ZigTypeIdOpaque) {
29627 ir_add_error(ira, lazy_ptr_type->elem_type,
30469 ir_add_error(ira, &lazy_ptr_type->elem_type->base,
2962830470 buf_sprintf("C pointers cannot point opaque types"));
2962930471 return ErrorSemanticAnalyzeFail;
2963030472 } else if (lazy_ptr_type->is_allowzero) {
29631 ir_add_error(ira, lazy_ptr_type->elem_type,
30473 ir_add_error(ira, &lazy_ptr_type->elem_type->base,
2963230474 buf_sprintf("C pointers always allow address zero"));
2963330475 return ErrorSemanticAnalyzeFail;
2963430476 }
......@@ -29666,7 +30508,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2966630508 case ZigTypeIdUndefined:
2966730509 case ZigTypeIdNull:
2966830510 case ZigTypeIdOpaque:
29669 ir_add_error(ira, lazy_array_type->elem_type,
30511 ir_add_error(ira, &lazy_array_type->elem_type->base,
2967030512 buf_sprintf("array of type '%s' not allowed",
2967130513 buf_ptr(&elem_type->name)));
2967230514 return ErrorSemanticAnalyzeFail;
......@@ -29701,7 +30543,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2970130543 if (lazy_array_type->sentinel != nullptr) {
2970230544 if (type_is_invalid(lazy_array_type->sentinel->value->type))
2970330545 return ErrorSemanticAnalyzeFail;
29704 IrInstruction *sentinel = ir_implicit_cast(ira, lazy_array_type->sentinel, elem_type);
30546 IrInstGen *sentinel = ir_implicit_cast(ira, lazy_array_type->sentinel, elem_type);
2970530547 if (type_is_invalid(sentinel->value->type))
2970630548 return ErrorSemanticAnalyzeFail;
2970730549 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);
......@@ -29725,7 +30567,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2972530567 return ErrorSemanticAnalyzeFail;
2972630568
2972730569 if (payload_type->id == ZigTypeIdOpaque || payload_type->id == ZigTypeIdUnreachable) {
29728 ir_add_error(ira, lazy_opt_type->payload_type,
30570 ir_add_error(ira, &lazy_opt_type->payload_type->base,
2972930571 buf_sprintf("type '%s' cannot be optional", buf_ptr(&payload_type->name)));
2973030572 return ErrorSemanticAnalyzeFail;
2973130573 }
......@@ -29767,7 +30609,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2976730609 return ErrorSemanticAnalyzeFail;
2976830610
2976930611 if (err_set_type->id != ZigTypeIdErrorSet) {
29770 ir_add_error(ira, lazy_err_union_type->err_set_type,
30612 ir_add_error(ira, &lazy_err_union_type->err_set_type->base,
2977130613 buf_sprintf("expected error set type, found type '%s'",
2977230614 buf_ptr(&err_set_type->name)));
2977330615 return ErrorSemanticAnalyzeFail;
......@@ -29803,8 +30645,8 @@ Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ZigValue *val) {
2980330645 return ErrorNone;
2980430646}
2980530647
29806void IrInstruction::src() {
29807 IrInstruction *inst = this;
30648void IrInst::src() {
30649 IrInst *inst = this;
2980830650 if (inst->source_node != nullptr) {
2980930651 inst->source_node->src();
2981030652 } else {
......@@ -29812,26 +30654,45 @@ void IrInstruction::src() {
2981230654 }
2981330655}
2981430656
29815void IrInstruction::dump() {
29816 IrInstruction *inst = this;
30657void IrInst::dump() {
30658 this->src();
30659 fprintf(stderr, "IrInst(#%" PRIu32 ")\n", this->debug_id);
30660}
30661
30662void IrInstSrc::src() {
30663 this->base.src();
30664}
30665
30666void IrInstGen::src() {
30667 this->base.src();
30668}
30669
30670void IrInstSrc::dump() {
30671 IrInstSrc *inst = this;
2981730672 inst->src();
29818 IrPass pass = (inst->child == nullptr) ? IrPassGen : IrPassSrc;
29819 if (inst->scope == nullptr) {
30673 if (inst->base.scope == nullptr) {
2982030674 fprintf(stderr, "(null scope)\n");
2982130675 } else {
29822 ir_print_instruction(inst->scope->codegen, stderr, inst, 0, pass);
29823 if (pass == IrPassSrc) {
29824 fprintf(stderr, "-> ");
29825 ir_print_instruction(inst->scope->codegen, stderr, inst->child, 0, IrPassGen);
29826 }
30676 ir_print_inst_src(inst->base.scope->codegen, stderr, inst, 0);
30677 fprintf(stderr, "-> ");
30678 ir_print_inst_gen(inst->base.scope->codegen, stderr, inst->child, 0);
30679 }
30680}
30681void IrInstGen::dump() {
30682 IrInstGen *inst = this;
30683 inst->src();
30684 if (inst->base.scope == nullptr) {
30685 fprintf(stderr, "(null scope)\n");
30686 } else {
30687 ir_print_inst_gen(inst->base.scope->codegen, stderr, inst, 0);
2982730688 }
2982830689}
2982930690
2983030691void IrAnalyze::dump() {
29831 ir_print(this->codegen, stderr, this->new_irb.exec, 0, IrPassGen);
30692 ir_print_gen(this->codegen, stderr, this->new_irb.exec, 0);
2983230693 if (this->new_irb.current_basic_block != nullptr) {
2983330694 fprintf(stderr, "Current basic block:\n");
29834 ir_print_basic_block(this->codegen, stderr, this->new_irb.current_basic_block, 1, IrPassGen);
30695 ir_print_basic_block_gen(this->codegen, stderr, this->new_irb.current_basic_block, 1);
2983530696 }
2983630697}
2983730698
src/ir.hpp+10-10
......@@ -10,33 +10,33 @@
1010
1111#include "all_types.hpp"
1212
13enum IrPass {
14 IrPassSrc,
15 IrPassGen,
16};
17
18bool ir_gen(CodeGen *g, AstNode *node, Scope *scope, IrExecutable *ir_executable);
13bool ir_gen(CodeGen *g, AstNode *node, Scope *scope, IrExecutableSrc *ir_executable);
1914bool ir_gen_fn(CodeGen *g, ZigFn *fn_entry);
2015
16IrInstGen *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node, ZigFn *fn,
17 ZigType *var_type, const char *name_hint);
18
2119ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
2220 ZigType *expected_type, size_t *backward_branch_count, size_t *backward_branch_quota,
2321 ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,
24 IrExecutable *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef);
22 IrExecutableGen *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef);
2523
2624Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ZigValue *val);
2725
28ZigType *ir_analyze(CodeGen *g, IrExecutable *old_executable, IrExecutable *new_executable,
26ZigType *ir_analyze(CodeGen *g, IrExecutableSrc *old_executable, IrExecutableGen *new_executable,
2927 ZigType *expected_type, AstNode *expected_type_source_node);
3028
31bool ir_has_side_effects(IrInstruction *instruction);
29bool ir_inst_gen_has_side_effects(IrInstGen *inst);
30bool ir_inst_src_has_side_effects(IrInstSrc *inst);
3231
3332struct IrAnalyze;
3433ZigValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ZigValue *const_val,
3534 AstNode *source_node);
36const char *float_op_to_name(BuiltinFnId op);
3735
3836// for debugging purposes
3937void dbg_ir_break(const char *src_file, uint32_t line);
4038void dbg_ir_clear(void);
4139
40void destroy_instruction_gen(IrInstGen *inst);
41
4242#endif
src/ir_print.cpp+1998-1281
......@@ -10,19 +10,35 @@
1010#include "ir_print.hpp"
1111#include "os.hpp"
1212
13static uint32_t hash_instruction_ptr(IrInstruction* instruction) {
13static uint32_t hash_inst_src_ptr(IrInstSrc* instruction) {
1414 return (uint32_t)(uintptr_t)instruction;
1515}
1616
17static bool instruction_ptr_equal(IrInstruction* a, IrInstruction* b) {
17static uint32_t hash_inst_gen_ptr(IrInstGen* instruction) {
18 return (uint32_t)(uintptr_t)instruction;
19}
20
21static bool inst_src_ptr_eql(IrInstSrc* a, IrInstSrc* b) {
1822 return a == b;
1923}
2024
21using InstructionSet = HashMap<IrInstruction*, uint8_t, hash_instruction_ptr, instruction_ptr_equal>;
22using InstructionList = ZigList<IrInstruction*>;
25static bool inst_gen_ptr_eql(IrInstGen* a, IrInstGen* b) {
26 return a == b;
27}
28
29using InstSetSrc = HashMap<IrInstSrc*, uint8_t, hash_inst_src_ptr, inst_src_ptr_eql>;
30using InstSetGen = HashMap<IrInstGen*, uint8_t, hash_inst_gen_ptr, inst_gen_ptr_eql>;
31using InstListSrc = ZigList<IrInstSrc*>;
32using InstListGen = ZigList<IrInstGen*>;
33
34struct IrPrintSrc {
35 CodeGen *codegen;
36 FILE *f;
37 int indent;
38 int indent_size;
39};
2340
24struct IrPrint {
25 IrPass pass;
41struct IrPrintGen {
2642 CodeGen *codegen;
2743 FILE *f;
2844 int indent;
......@@ -32,417 +48,590 @@ struct IrPrint {
3248 // present in the instruction list. Thus we track which instructions
3349 // are printed (per executable) and after each pass 2 instruction those
3450 // var instructions are rendered in a trailing fashion.
35 InstructionSet printed;
36 InstructionList pending;
51 InstSetGen printed;
52 InstListGen pending;
3753};
3854
39static void ir_print_other_instruction(IrPrint *irp, IrInstruction *instruction);
55static void ir_print_other_inst_src(IrPrintSrc *irp, IrInstSrc *inst);
56static void ir_print_other_inst_gen(IrPrintGen *irp, IrInstGen *inst);
4057
41const char* ir_instruction_type_str(IrInstructionId id) {
58const char* ir_inst_src_type_str(IrInstSrcId id) {
4259 switch (id) {
43 case IrInstructionIdInvalid:
44 return "Invalid";
45 case IrInstructionIdShuffleVector:
46 return "Shuffle";
47 case IrInstructionIdSplatSrc:
48 return "SplatSrc";
49 case IrInstructionIdSplatGen:
50 return "SplatGen";
51 case IrInstructionIdDeclVarSrc:
52 return "DeclVarSrc";
53 case IrInstructionIdDeclVarGen:
54 return "DeclVarGen";
55 case IrInstructionIdBr:
56 return "Br";
57 case IrInstructionIdCondBr:
58 return "CondBr";
59 case IrInstructionIdSwitchBr:
60 return "SwitchBr";
61 case IrInstructionIdSwitchVar:
62 return "SwitchVar";
63 case IrInstructionIdSwitchElseVar:
64 return "SwitchElseVar";
65 case IrInstructionIdSwitchTarget:
66 return "SwitchTarget";
67 case IrInstructionIdPhi:
68 return "Phi";
69 case IrInstructionIdUnOp:
70 return "UnOp";
71 case IrInstructionIdBinOp:
72 return "BinOp";
73 case IrInstructionIdMergeErrSets:
74 return "MergeErrSets";
75 case IrInstructionIdLoadPtr:
76 return "LoadPtr";
77 case IrInstructionIdLoadPtrGen:
78 return "LoadPtrGen";
79 case IrInstructionIdStorePtr:
80 return "StorePtr";
81 case IrInstructionIdVectorStoreElem:
82 return "VectorStoreElem";
83 case IrInstructionIdFieldPtr:
84 return "FieldPtr";
85 case IrInstructionIdStructFieldPtr:
86 return "StructFieldPtr";
87 case IrInstructionIdUnionFieldPtr:
88 return "UnionFieldPtr";
89 case IrInstructionIdElemPtr:
90 return "ElemPtr";
91 case IrInstructionIdVarPtr:
92 return "VarPtr";
93 case IrInstructionIdReturnPtr:
94 return "ReturnPtr";
95 case IrInstructionIdCallExtra:
96 return "CallExtra";
97 case IrInstructionIdCallSrc:
98 return "CallSrc";
99 case IrInstructionIdCallSrcArgs:
100 return "CallSrcArgs";
101 case IrInstructionIdCallGen:
102 return "CallGen";
103 case IrInstructionIdConst:
104 return "Const";
105 case IrInstructionIdReturn:
106 return "Return";
107 case IrInstructionIdCast:
108 return "Cast";
109 case IrInstructionIdResizeSlice:
110 return "ResizeSlice";
111 case IrInstructionIdContainerInitList:
112 return "ContainerInitList";
113 case IrInstructionIdContainerInitFields:
114 return "ContainerInitFields";
115 case IrInstructionIdUnreachable:
116 return "Unreachable";
117 case IrInstructionIdTypeOf:
118 return "TypeOf";
119 case IrInstructionIdSetCold:
120 return "SetCold";
121 case IrInstructionIdSetRuntimeSafety:
122 return "SetRuntimeSafety";
123 case IrInstructionIdSetFloatMode:
124 return "SetFloatMode";
125 case IrInstructionIdArrayType:
126 return "ArrayType";
127 case IrInstructionIdAnyFrameType:
128 return "AnyFrameType";
129 case IrInstructionIdSliceType:
130 return "SliceType";
131 case IrInstructionIdAsmSrc:
132 return "AsmSrc";
133 case IrInstructionIdAsmGen:
134 return "AsmGen";
135 case IrInstructionIdSizeOf:
136 return "SizeOf";
137 case IrInstructionIdTestNonNull:
138 return "TestNonNull";
139 case IrInstructionIdOptionalUnwrapPtr:
140 return "OptionalUnwrapPtr";
141 case IrInstructionIdOptionalWrap:
142 return "OptionalWrap";
143 case IrInstructionIdUnionTag:
144 return "UnionTag";
145 case IrInstructionIdClz:
146 return "Clz";
147 case IrInstructionIdCtz:
148 return "Ctz";
149 case IrInstructionIdPopCount:
150 return "PopCount";
151 case IrInstructionIdBswap:
152 return "Bswap";
153 case IrInstructionIdBitReverse:
154 return "BitReverse";
155 case IrInstructionIdImport:
156 return "Import";
157 case IrInstructionIdCImport:
158 return "CImport";
159 case IrInstructionIdCInclude:
160 return "CInclude";
161 case IrInstructionIdCDefine:
162 return "CDefine";
163 case IrInstructionIdCUndef:
164 return "CUndef";
165 case IrInstructionIdRef:
166 return "Ref";
167 case IrInstructionIdRefGen:
168 return "RefGen";
169 case IrInstructionIdCompileErr:
170 return "CompileErr";
171 case IrInstructionIdCompileLog:
172 return "CompileLog";
173 case IrInstructionIdErrName:
174 return "ErrName";
175 case IrInstructionIdEmbedFile:
176 return "EmbedFile";
177 case IrInstructionIdCmpxchgSrc:
178 return "CmpxchgSrc";
179 case IrInstructionIdCmpxchgGen:
180 return "CmpxchgGen";
181 case IrInstructionIdFence:
182 return "Fence";
183 case IrInstructionIdTruncate:
184 return "Truncate";
185 case IrInstructionIdIntCast:
186 return "IntCast";
187 case IrInstructionIdFloatCast:
188 return "FloatCast";
189 case IrInstructionIdIntToFloat:
190 return "IntToFloat";
191 case IrInstructionIdFloatToInt:
192 return "FloatToInt";
193 case IrInstructionIdBoolToInt:
194 return "BoolToInt";
195 case IrInstructionIdIntType:
196 return "IntType";
197 case IrInstructionIdVectorType:
198 return "VectorType";
199 case IrInstructionIdBoolNot:
200 return "BoolNot";
201 case IrInstructionIdMemset:
202 return "Memset";
203 case IrInstructionIdMemcpy:
204 return "Memcpy";
205 case IrInstructionIdSliceSrc:
206 return "SliceSrc";
207 case IrInstructionIdSliceGen:
208 return "SliceGen";
209 case IrInstructionIdMemberCount:
210 return "MemberCount";
211 case IrInstructionIdMemberType:
212 return "MemberType";
213 case IrInstructionIdMemberName:
214 return "MemberName";
215 case IrInstructionIdBreakpoint:
216 return "Breakpoint";
217 case IrInstructionIdReturnAddress:
218 return "ReturnAddress";
219 case IrInstructionIdFrameAddress:
220 return "FrameAddress";
221 case IrInstructionIdFrameHandle:
222 return "FrameHandle";
223 case IrInstructionIdFrameType:
224 return "FrameType";
225 case IrInstructionIdFrameSizeSrc:
226 return "FrameSizeSrc";
227 case IrInstructionIdFrameSizeGen:
228 return "FrameSizeGen";
229 case IrInstructionIdAlignOf:
230 return "AlignOf";
231 case IrInstructionIdOverflowOp:
232 return "OverflowOp";
233 case IrInstructionIdTestErrSrc:
234 return "TestErrSrc";
235 case IrInstructionIdTestErrGen:
236 return "TestErrGen";
237 case IrInstructionIdMulAdd:
238 return "MulAdd";
239 case IrInstructionIdFloatOp:
240 return "FloatOp";
241 case IrInstructionIdUnwrapErrCode:
242 return "UnwrapErrCode";
243 case IrInstructionIdUnwrapErrPayload:
244 return "UnwrapErrPayload";
245 case IrInstructionIdErrWrapCode:
246 return "ErrWrapCode";
247 case IrInstructionIdErrWrapPayload:
248 return "ErrWrapPayload";
249 case IrInstructionIdFnProto:
250 return "FnProto";
251 case IrInstructionIdTestComptime:
252 return "TestComptime";
253 case IrInstructionIdPtrCastSrc:
254 return "PtrCastSrc";
255 case IrInstructionIdPtrCastGen:
256 return "PtrCastGen";
257 case IrInstructionIdBitCastSrc:
258 return "BitCastSrc";
259 case IrInstructionIdBitCastGen:
260 return "BitCastGen";
261 case IrInstructionIdWidenOrShorten:
262 return "WidenOrShorten";
263 case IrInstructionIdIntToPtr:
264 return "IntToPtr";
265 case IrInstructionIdPtrToInt:
266 return "PtrToInt";
267 case IrInstructionIdIntToEnum:
268 return "IntToEnum";
269 case IrInstructionIdEnumToInt:
270 return "EnumToInt";
271 case IrInstructionIdIntToErr:
272 return "IntToErr";
273 case IrInstructionIdErrToInt:
274 return "ErrToInt";
275 case IrInstructionIdCheckSwitchProngs:
276 return "CheckSwitchProngs";
277 case IrInstructionIdCheckStatementIsVoid:
278 return "CheckStatementIsVoid";
279 case IrInstructionIdTypeName:
280 return "TypeName";
281 case IrInstructionIdDeclRef:
282 return "DeclRef";
283 case IrInstructionIdPanic:
284 return "Panic";
285 case IrInstructionIdTagName:
286 return "TagName";
287 case IrInstructionIdTagType:
288 return "TagType";
289 case IrInstructionIdFieldParentPtr:
290 return "FieldParentPtr";
291 case IrInstructionIdByteOffsetOf:
292 return "ByteOffsetOf";
293 case IrInstructionIdBitOffsetOf:
294 return "BitOffsetOf";
295 case IrInstructionIdTypeInfo:
296 return "TypeInfo";
297 case IrInstructionIdType:
298 return "Type";
299 case IrInstructionIdHasField:
300 return "HasField";
301 case IrInstructionIdTypeId:
302 return "TypeId";
303 case IrInstructionIdSetEvalBranchQuota:
304 return "SetEvalBranchQuota";
305 case IrInstructionIdPtrType:
306 return "PtrType";
307 case IrInstructionIdAlignCast:
308 return "AlignCast";
309 case IrInstructionIdImplicitCast:
310 return "ImplicitCast";
311 case IrInstructionIdResolveResult:
312 return "ResolveResult";
313 case IrInstructionIdResetResult:
314 return "ResetResult";
315 case IrInstructionIdOpaqueType:
316 return "OpaqueType";
317 case IrInstructionIdSetAlignStack:
318 return "SetAlignStack";
319 case IrInstructionIdArgType:
320 return "ArgType";
321 case IrInstructionIdExport:
322 return "Export";
323 case IrInstructionIdErrorReturnTrace:
324 return "ErrorReturnTrace";
325 case IrInstructionIdErrorUnion:
326 return "ErrorUnion";
327 case IrInstructionIdAtomicRmw:
328 return "AtomicRmw";
329 case IrInstructionIdAtomicLoad:
330 return "AtomicLoad";
331 case IrInstructionIdAtomicStore:
332 return "AtomicStore";
333 case IrInstructionIdSaveErrRetAddr:
334 return "SaveErrRetAddr";
335 case IrInstructionIdAddImplicitReturnType:
336 return "AddImplicitReturnType";
337 case IrInstructionIdErrSetCast:
338 return "ErrSetCast";
339 case IrInstructionIdToBytes:
340 return "ToBytes";
341 case IrInstructionIdFromBytes:
342 return "FromBytes";
343 case IrInstructionIdCheckRuntimeScope:
344 return "CheckRuntimeScope";
345 case IrInstructionIdVectorToArray:
346 return "VectorToArray";
347 case IrInstructionIdArrayToVector:
348 return "ArrayToVector";
349 case IrInstructionIdAssertZero:
350 return "AssertZero";
351 case IrInstructionIdAssertNonNull:
352 return "AssertNonNull";
353 case IrInstructionIdHasDecl:
354 return "HasDecl";
355 case IrInstructionIdUndeclaredIdent:
356 return "UndeclaredIdent";
357 case IrInstructionIdAllocaSrc:
358 return "AllocaSrc";
359 case IrInstructionIdAllocaGen:
360 return "AllocaGen";
361 case IrInstructionIdEndExpr:
362 return "EndExpr";
363 case IrInstructionIdPtrOfArrayToSlice:
364 return "PtrOfArrayToSlice";
365 case IrInstructionIdUnionInitNamedField:
366 return "UnionInitNamedField";
367 case IrInstructionIdSuspendBegin:
368 return "SuspendBegin";
369 case IrInstructionIdSuspendFinish:
370 return "SuspendFinish";
371 case IrInstructionIdAwaitSrc:
372 return "AwaitSrc";
373 case IrInstructionIdAwaitGen:
374 return "AwaitGen";
375 case IrInstructionIdResume:
376 return "Resume";
377 case IrInstructionIdSpillBegin:
378 return "SpillBegin";
379 case IrInstructionIdSpillEnd:
380 return "SpillEnd";
381 case IrInstructionIdVectorExtractElem:
382 return "VectorExtractElem";
60 case IrInstSrcIdInvalid:
61 return "SrcInvalid";
62 case IrInstSrcIdShuffleVector:
63 return "SrcShuffle";
64 case IrInstSrcIdSplat:
65 return "SrcSplat";
66 case IrInstSrcIdDeclVar:
67 return "SrcDeclVar";
68 case IrInstSrcIdBr:
69 return "SrcBr";
70 case IrInstSrcIdCondBr:
71 return "SrcCondBr";
72 case IrInstSrcIdSwitchBr:
73 return "SrcSwitchBr";
74 case IrInstSrcIdSwitchVar:
75 return "SrcSwitchVar";
76 case IrInstSrcIdSwitchElseVar:
77 return "SrcSwitchElseVar";
78 case IrInstSrcIdSwitchTarget:
79 return "SrcSwitchTarget";
80 case IrInstSrcIdPhi:
81 return "SrcPhi";
82 case IrInstSrcIdUnOp:
83 return "SrcUnOp";
84 case IrInstSrcIdBinOp:
85 return "SrcBinOp";
86 case IrInstSrcIdMergeErrSets:
87 return "SrcMergeErrSets";
88 case IrInstSrcIdLoadPtr:
89 return "SrcLoadPtr";
90 case IrInstSrcIdStorePtr:
91 return "SrcStorePtr";
92 case IrInstSrcIdFieldPtr:
93 return "SrcFieldPtr";
94 case IrInstSrcIdElemPtr:
95 return "SrcElemPtr";
96 case IrInstSrcIdVarPtr:
97 return "SrcVarPtr";
98 case IrInstSrcIdCallExtra:
99 return "SrcCallExtra";
100 case IrInstSrcIdCall:
101 return "SrcCall";
102 case IrInstSrcIdCallArgs:
103 return "SrcCallArgs";
104 case IrInstSrcIdConst:
105 return "SrcConst";
106 case IrInstSrcIdReturn:
107 return "SrcReturn";
108 case IrInstSrcIdContainerInitList:
109 return "SrcContainerInitList";
110 case IrInstSrcIdContainerInitFields:
111 return "SrcContainerInitFields";
112 case IrInstSrcIdUnreachable:
113 return "SrcUnreachable";
114 case IrInstSrcIdTypeOf:
115 return "SrcTypeOf";
116 case IrInstSrcIdSetCold:
117 return "SrcSetCold";
118 case IrInstSrcIdSetRuntimeSafety:
119 return "SrcSetRuntimeSafety";
120 case IrInstSrcIdSetFloatMode:
121 return "SrcSetFloatMode";
122 case IrInstSrcIdArrayType:
123 return "SrcArrayType";
124 case IrInstSrcIdAnyFrameType:
125 return "SrcAnyFrameType";
126 case IrInstSrcIdSliceType:
127 return "SrcSliceType";
128 case IrInstSrcIdAsm:
129 return "SrcAsm";
130 case IrInstSrcIdSizeOf:
131 return "SrcSizeOf";
132 case IrInstSrcIdTestNonNull:
133 return "SrcTestNonNull";
134 case IrInstSrcIdOptionalUnwrapPtr:
135 return "SrcOptionalUnwrapPtr";
136 case IrInstSrcIdClz:
137 return "SrcClz";
138 case IrInstSrcIdCtz:
139 return "SrcCtz";
140 case IrInstSrcIdPopCount:
141 return "SrcPopCount";
142 case IrInstSrcIdBswap:
143 return "SrcBswap";
144 case IrInstSrcIdBitReverse:
145 return "SrcBitReverse";
146 case IrInstSrcIdImport:
147 return "SrcImport";
148 case IrInstSrcIdCImport:
149 return "SrcCImport";
150 case IrInstSrcIdCInclude:
151 return "SrcCInclude";
152 case IrInstSrcIdCDefine:
153 return "SrcCDefine";
154 case IrInstSrcIdCUndef:
155 return "SrcCUndef";
156 case IrInstSrcIdRef:
157 return "SrcRef";
158 case IrInstSrcIdCompileErr:
159 return "SrcCompileErr";
160 case IrInstSrcIdCompileLog:
161 return "SrcCompileLog";
162 case IrInstSrcIdErrName:
163 return "SrcErrName";
164 case IrInstSrcIdEmbedFile:
165 return "SrcEmbedFile";
166 case IrInstSrcIdCmpxchg:
167 return "SrcCmpxchg";
168 case IrInstSrcIdFence:
169 return "SrcFence";
170 case IrInstSrcIdTruncate:
171 return "SrcTruncate";
172 case IrInstSrcIdIntCast:
173 return "SrcIntCast";
174 case IrInstSrcIdFloatCast:
175 return "SrcFloatCast";
176 case IrInstSrcIdIntToFloat:
177 return "SrcIntToFloat";
178 case IrInstSrcIdFloatToInt:
179 return "SrcFloatToInt";
180 case IrInstSrcIdBoolToInt:
181 return "SrcBoolToInt";
182 case IrInstSrcIdIntType:
183 return "SrcIntType";
184 case IrInstSrcIdVectorType:
185 return "SrcVectorType";
186 case IrInstSrcIdBoolNot:
187 return "SrcBoolNot";
188 case IrInstSrcIdMemset:
189 return "SrcMemset";
190 case IrInstSrcIdMemcpy:
191 return "SrcMemcpy";
192 case IrInstSrcIdSlice:
193 return "SrcSlice";
194 case IrInstSrcIdMemberCount:
195 return "SrcMemberCount";
196 case IrInstSrcIdMemberType:
197 return "SrcMemberType";
198 case IrInstSrcIdMemberName:
199 return "SrcMemberName";
200 case IrInstSrcIdBreakpoint:
201 return "SrcBreakpoint";
202 case IrInstSrcIdReturnAddress:
203 return "SrcReturnAddress";
204 case IrInstSrcIdFrameAddress:
205 return "SrcFrameAddress";
206 case IrInstSrcIdFrameHandle:
207 return "SrcFrameHandle";
208 case IrInstSrcIdFrameType:
209 return "SrcFrameType";
210 case IrInstSrcIdFrameSize:
211 return "SrcFrameSize";
212 case IrInstSrcIdAlignOf:
213 return "SrcAlignOf";
214 case IrInstSrcIdOverflowOp:
215 return "SrcOverflowOp";
216 case IrInstSrcIdTestErr:
217 return "SrcTestErr";
218 case IrInstSrcIdMulAdd:
219 return "SrcMulAdd";
220 case IrInstSrcIdFloatOp:
221 return "SrcFloatOp";
222 case IrInstSrcIdUnwrapErrCode:
223 return "SrcUnwrapErrCode";
224 case IrInstSrcIdUnwrapErrPayload:
225 return "SrcUnwrapErrPayload";
226 case IrInstSrcIdFnProto:
227 return "SrcFnProto";
228 case IrInstSrcIdTestComptime:
229 return "SrcTestComptime";
230 case IrInstSrcIdPtrCast:
231 return "SrcPtrCast";
232 case IrInstSrcIdBitCast:
233 return "SrcBitCast";
234 case IrInstSrcIdIntToPtr:
235 return "SrcIntToPtr";
236 case IrInstSrcIdPtrToInt:
237 return "SrcPtrToInt";
238 case IrInstSrcIdIntToEnum:
239 return "SrcIntToEnum";
240 case IrInstSrcIdEnumToInt:
241 return "SrcEnumToInt";
242 case IrInstSrcIdIntToErr:
243 return "SrcIntToErr";
244 case IrInstSrcIdErrToInt:
245 return "SrcErrToInt";
246 case IrInstSrcIdCheckSwitchProngs:
247 return "SrcCheckSwitchProngs";
248 case IrInstSrcIdCheckStatementIsVoid:
249 return "SrcCheckStatementIsVoid";
250 case IrInstSrcIdTypeName:
251 return "SrcTypeName";
252 case IrInstSrcIdDeclRef:
253 return "SrcDeclRef";
254 case IrInstSrcIdPanic:
255 return "SrcPanic";
256 case IrInstSrcIdTagName:
257 return "SrcTagName";
258 case IrInstSrcIdTagType:
259 return "SrcTagType";
260 case IrInstSrcIdFieldParentPtr:
261 return "SrcFieldParentPtr";
262 case IrInstSrcIdByteOffsetOf:
263 return "SrcByteOffsetOf";
264 case IrInstSrcIdBitOffsetOf:
265 return "SrcBitOffsetOf";
266 case IrInstSrcIdTypeInfo:
267 return "SrcTypeInfo";
268 case IrInstSrcIdType:
269 return "SrcType";
270 case IrInstSrcIdHasField:
271 return "SrcHasField";
272 case IrInstSrcIdTypeId:
273 return "SrcTypeId";
274 case IrInstSrcIdSetEvalBranchQuota:
275 return "SrcSetEvalBranchQuota";
276 case IrInstSrcIdPtrType:
277 return "SrcPtrType";
278 case IrInstSrcIdAlignCast:
279 return "SrcAlignCast";
280 case IrInstSrcIdImplicitCast:
281 return "SrcImplicitCast";
282 case IrInstSrcIdResolveResult:
283 return "SrcResolveResult";
284 case IrInstSrcIdResetResult:
285 return "SrcResetResult";
286 case IrInstSrcIdOpaqueType:
287 return "SrcOpaqueType";
288 case IrInstSrcIdSetAlignStack:
289 return "SrcSetAlignStack";
290 case IrInstSrcIdArgType:
291 return "SrcArgType";
292 case IrInstSrcIdExport:
293 return "SrcExport";
294 case IrInstSrcIdErrorReturnTrace:
295 return "SrcErrorReturnTrace";
296 case IrInstSrcIdErrorUnion:
297 return "SrcErrorUnion";
298 case IrInstSrcIdAtomicRmw:
299 return "SrcAtomicRmw";
300 case IrInstSrcIdAtomicLoad:
301 return "SrcAtomicLoad";
302 case IrInstSrcIdAtomicStore:
303 return "SrcAtomicStore";
304 case IrInstSrcIdSaveErrRetAddr:
305 return "SrcSaveErrRetAddr";
306 case IrInstSrcIdAddImplicitReturnType:
307 return "SrcAddImplicitReturnType";
308 case IrInstSrcIdErrSetCast:
309 return "SrcErrSetCast";
310 case IrInstSrcIdToBytes:
311 return "SrcToBytes";
312 case IrInstSrcIdFromBytes:
313 return "SrcFromBytes";
314 case IrInstSrcIdCheckRuntimeScope:
315 return "SrcCheckRuntimeScope";
316 case IrInstSrcIdHasDecl:
317 return "SrcHasDecl";
318 case IrInstSrcIdUndeclaredIdent:
319 return "SrcUndeclaredIdent";
320 case IrInstSrcIdAlloca:
321 return "SrcAlloca";
322 case IrInstSrcIdEndExpr:
323 return "SrcEndExpr";
324 case IrInstSrcIdUnionInitNamedField:
325 return "SrcUnionInitNamedField";
326 case IrInstSrcIdSuspendBegin:
327 return "SrcSuspendBegin";
328 case IrInstSrcIdSuspendFinish:
329 return "SrcSuspendFinish";
330 case IrInstSrcIdAwait:
331 return "SrcAwaitSr";
332 case IrInstSrcIdResume:
333 return "SrcResume";
334 case IrInstSrcIdSpillBegin:
335 return "SrcSpillBegin";
336 case IrInstSrcIdSpillEnd:
337 return "SrcSpillEnd";
383338 }
384339 zig_unreachable();
385340}
386341
387static void ir_print_indent(IrPrint *irp) {
342const char* ir_inst_gen_type_str(IrInstGenId id) {
343 switch (id) {
344 case IrInstGenIdInvalid:
345 return "GenInvalid";
346 case IrInstGenIdShuffleVector:
347 return "GenShuffle";
348 case IrInstGenIdSplat:
349 return "GenSplat";
350 case IrInstGenIdDeclVar:
351 return "GenDeclVar";
352 case IrInstGenIdBr:
353 return "GenBr";
354 case IrInstGenIdCondBr:
355 return "GenCondBr";
356 case IrInstGenIdSwitchBr:
357 return "GenSwitchBr";
358 case IrInstGenIdPhi:
359 return "GenPhi";
360 case IrInstGenIdBinOp:
361 return "GenBinOp";
362 case IrInstGenIdLoadPtr:
363 return "GenLoadPtr";
364 case IrInstGenIdStorePtr:
365 return "GenStorePtr";
366 case IrInstGenIdVectorStoreElem:
367 return "GenVectorStoreElem";
368 case IrInstGenIdStructFieldPtr:
369 return "GenStructFieldPtr";
370 case IrInstGenIdUnionFieldPtr:
371 return "GenUnionFieldPtr";
372 case IrInstGenIdElemPtr:
373 return "GenElemPtr";
374 case IrInstGenIdVarPtr:
375 return "GenVarPtr";
376 case IrInstGenIdReturnPtr:
377 return "GenReturnPtr";
378 case IrInstGenIdCall:
379 return "GenCall";
380 case IrInstGenIdConst:
381 return "GenConst";
382 case IrInstGenIdReturn:
383 return "GenReturn";
384 case IrInstGenIdCast:
385 return "GenCast";
386 case IrInstGenIdResizeSlice:
387 return "GenResizeSlice";
388 case IrInstGenIdUnreachable:
389 return "GenUnreachable";
390 case IrInstGenIdAsm:
391 return "GenAsm";
392 case IrInstGenIdTestNonNull:
393 return "GenTestNonNull";
394 case IrInstGenIdOptionalUnwrapPtr:
395 return "GenOptionalUnwrapPtr";
396 case IrInstGenIdOptionalWrap:
397 return "GenOptionalWrap";
398 case IrInstGenIdUnionTag:
399 return "GenUnionTag";
400 case IrInstGenIdClz:
401 return "GenClz";
402 case IrInstGenIdCtz:
403 return "GenCtz";
404 case IrInstGenIdPopCount:
405 return "GenPopCount";
406 case IrInstGenIdBswap:
407 return "GenBswap";
408 case IrInstGenIdBitReverse:
409 return "GenBitReverse";
410 case IrInstGenIdRef:
411 return "GenRef";
412 case IrInstGenIdErrName:
413 return "GenErrName";
414 case IrInstGenIdCmpxchg:
415 return "GenCmpxchg";
416 case IrInstGenIdFence:
417 return "GenFence";
418 case IrInstGenIdTruncate:
419 return "GenTruncate";
420 case IrInstGenIdBoolNot:
421 return "GenBoolNot";
422 case IrInstGenIdMemset:
423 return "GenMemset";
424 case IrInstGenIdMemcpy:
425 return "GenMemcpy";
426 case IrInstGenIdSlice:
427 return "GenSlice";
428 case IrInstGenIdBreakpoint:
429 return "GenBreakpoint";
430 case IrInstGenIdReturnAddress:
431 return "GenReturnAddress";
432 case IrInstGenIdFrameAddress:
433 return "GenFrameAddress";
434 case IrInstGenIdFrameHandle:
435 return "GenFrameHandle";
436 case IrInstGenIdFrameSize:
437 return "GenFrameSize";
438 case IrInstGenIdOverflowOp:
439 return "GenOverflowOp";
440 case IrInstGenIdTestErr:
441 return "GenTestErr";
442 case IrInstGenIdMulAdd:
443 return "GenMulAdd";
444 case IrInstGenIdFloatOp:
445 return "GenFloatOp";
446 case IrInstGenIdUnwrapErrCode:
447 return "GenUnwrapErrCode";
448 case IrInstGenIdUnwrapErrPayload:
449 return "GenUnwrapErrPayload";
450 case IrInstGenIdErrWrapCode:
451 return "GenErrWrapCode";
452 case IrInstGenIdErrWrapPayload:
453 return "GenErrWrapPayload";
454 case IrInstGenIdPtrCast:
455 return "GenPtrCast";
456 case IrInstGenIdBitCast:
457 return "GenBitCast";
458 case IrInstGenIdWidenOrShorten:
459 return "GenWidenOrShorten";
460 case IrInstGenIdIntToPtr:
461 return "GenIntToPtr";
462 case IrInstGenIdPtrToInt:
463 return "GenPtrToInt";
464 case IrInstGenIdIntToEnum:
465 return "GenIntToEnum";
466 case IrInstGenIdIntToErr:
467 return "GenIntToErr";
468 case IrInstGenIdErrToInt:
469 return "GenErrToInt";
470 case IrInstGenIdPanic:
471 return "GenPanic";
472 case IrInstGenIdTagName:
473 return "GenTagName";
474 case IrInstGenIdFieldParentPtr:
475 return "GenFieldParentPtr";
476 case IrInstGenIdAlignCast:
477 return "GenAlignCast";
478 case IrInstGenIdErrorReturnTrace:
479 return "GenErrorReturnTrace";
480 case IrInstGenIdAtomicRmw:
481 return "GenAtomicRmw";
482 case IrInstGenIdAtomicLoad:
483 return "GenAtomicLoad";
484 case IrInstGenIdAtomicStore:
485 return "GenAtomicStore";
486 case IrInstGenIdSaveErrRetAddr:
487 return "GenSaveErrRetAddr";
488 case IrInstGenIdVectorToArray:
489 return "GenVectorToArray";
490 case IrInstGenIdArrayToVector:
491 return "GenArrayToVector";
492 case IrInstGenIdAssertZero:
493 return "GenAssertZero";
494 case IrInstGenIdAssertNonNull:
495 return "GenAssertNonNull";
496 case IrInstGenIdAlloca:
497 return "GenAlloca";
498 case IrInstGenIdPtrOfArrayToSlice:
499 return "GenPtrOfArrayToSlice";
500 case IrInstGenIdSuspendBegin:
501 return "GenSuspendBegin";
502 case IrInstGenIdSuspendFinish:
503 return "GenSuspendFinish";
504 case IrInstGenIdAwait:
505 return "GenAwait";
506 case IrInstGenIdResume:
507 return "GenResume";
508 case IrInstGenIdSpillBegin:
509 return "GenSpillBegin";
510 case IrInstGenIdSpillEnd:
511 return "GenSpillEnd";
512 case IrInstGenIdVectorExtractElem:
513 return "GenVectorExtractElem";
514 case IrInstGenIdBinaryNot:
515 return "GenBinaryNot";
516 case IrInstGenIdNegation:
517 return "GenNegation";
518 case IrInstGenIdNegationWrapping:
519 return "GenNegationWrapping";
520 }
521 zig_unreachable();
522}
523
524static void ir_print_indent_src(IrPrintSrc *irp) {
388525 for (int i = 0; i < irp->indent; i += 1) {
389526 fprintf(irp->f, " ");
390527 }
391528}
392529
393static void ir_print_prefix(IrPrint *irp, IrInstruction *instruction, bool trailing) {
394 ir_print_indent(irp);
530static void ir_print_indent_gen(IrPrintGen *irp) {
531 for (int i = 0; i < irp->indent; i += 1) {
532 fprintf(irp->f, " ");
533 }
534}
535
536static void ir_print_prefix_src(IrPrintSrc *irp, IrInstSrc *instruction, bool trailing) {
537 ir_print_indent_src(irp);
538 const char mark = trailing ? ':' : '#';
539 const char *type_name;
540 if (instruction->id == IrInstSrcIdConst) {
541 type_name = buf_ptr(&reinterpret_cast<IrInstSrcConst *>(instruction)->value->type->name);
542 } else if (instruction->is_noreturn) {
543 type_name = "noreturn";
544 } else {
545 type_name = "(unknown)";
546 }
547 const char *ref_count = ir_inst_src_has_side_effects(instruction) ?
548 "-" : buf_ptr(buf_sprintf("%" PRIu32 "", instruction->base.ref_count));
549 fprintf(irp->f, "%c%-3" PRIu32 "| %-22s| %-12s| %-2s| ", mark, instruction->base.debug_id,
550 ir_inst_src_type_str(instruction->id), type_name, ref_count);
551}
552
553static void ir_print_prefix_gen(IrPrintGen *irp, IrInstGen *instruction, bool trailing) {
554 ir_print_indent_gen(irp);
395555 const char mark = trailing ? ':' : '#';
396556 const char *type_name = instruction->value->type ? buf_ptr(&instruction->value->type->name) : "(unknown)";
397 const char *ref_count = ir_has_side_effects(instruction) ?
398 "-" : buf_ptr(buf_sprintf("%" PRIu32 "", instruction->ref_count));
399 fprintf(irp->f, "%c%-3" PRIu32 "| %-22s| %-12s| %-2s| ", mark, instruction->debug_id,
400 ir_instruction_type_str(instruction->id), type_name, ref_count);
557 const char *ref_count = ir_inst_gen_has_side_effects(instruction) ?
558 "-" : buf_ptr(buf_sprintf("%" PRIu32 "", instruction->base.ref_count));
559 fprintf(irp->f, "%c%-3" PRIu32 "| %-22s| %-12s| %-2s| ", mark, instruction->base.debug_id,
560 ir_inst_gen_type_str(instruction->id), type_name, ref_count);
401561}
402562
403static void ir_print_const_value(IrPrint *irp, ZigValue *const_val) {
404 Buf buf = BUF_INIT;
405 buf_resize(&buf, 0);
406 render_const_value(irp->codegen, &buf, const_val);
407 fprintf(irp->f, "%s", buf_ptr(&buf));
563static void ir_print_var_src(IrPrintSrc *irp, IrInstSrc *inst) {
564 fprintf(irp->f, "#%" PRIu32 "", inst->base.debug_id);
408565}
409566
410static void ir_print_var_instruction(IrPrint *irp, IrInstruction *instruction) {
411 fprintf(irp->f, "#%" PRIu32 "", instruction->debug_id);
412 if (irp->pass != IrPassSrc && irp->printed.maybe_get(instruction) == nullptr) {
413 irp->printed.put(instruction, 0);
414 irp->pending.append(instruction);
567static void ir_print_var_gen(IrPrintGen *irp, IrInstGen *inst) {
568 fprintf(irp->f, "#%" PRIu32 "", inst->base.debug_id);
569 if (irp->printed.maybe_get(inst) == nullptr) {
570 irp->printed.put(inst, 0);
571 irp->pending.append(inst);
415572 }
416573}
417574
418static void ir_print_other_instruction(IrPrint *irp, IrInstruction *instruction) {
419 if (instruction == nullptr) {
575static void ir_print_other_inst_src(IrPrintSrc *irp, IrInstSrc *inst) {
576 if (inst == nullptr) {
420577 fprintf(irp->f, "(null)");
421578 return;
422579 }
580 ir_print_var_src(irp, inst);
581}
582
583static void ir_print_const_value(CodeGen *g, FILE *f, ZigValue *const_val) {
584 Buf buf = BUF_INIT;
585 buf_resize(&buf, 0);
586 render_const_value(g, &buf, const_val);
587 fprintf(f, "%s", buf_ptr(&buf));
588}
589
590static void ir_print_other_inst_gen(IrPrintGen *irp, IrInstGen *inst) {
591 if (inst == nullptr) {
592 fprintf(irp->f, "(null)");
593 return;
594 }
595
596 if (inst->value->special != ConstValSpecialRuntime) {
597 ir_print_const_value(irp->codegen, irp->f, inst->value);
598 } else {
599 ir_print_var_gen(irp, inst);
600 }
601}
423602
424 if (instruction->value->special != ConstValSpecialRuntime) {
425 ir_print_const_value(irp, instruction->value);
603static void ir_print_other_block(IrPrintSrc *irp, IrBasicBlockSrc *bb) {
604 if (bb == nullptr) {
605 fprintf(irp->f, "(null block)");
426606 } else {
427 ir_print_var_instruction(irp, instruction);
607 fprintf(irp->f, "$%s_%" PRIu32 "", bb->name_hint, bb->debug_id);
428608 }
429609}
430610
431static void ir_print_other_block(IrPrint *irp, IrBasicBlock *bb) {
611static void ir_print_other_block_gen(IrPrintGen *irp, IrBasicBlockGen *bb) {
432612 if (bb == nullptr) {
433613 fprintf(irp->f, "(null block)");
434614 } else {
435 fprintf(irp->f, "$%s_%" ZIG_PRI_usize "", bb->name_hint, bb->debug_id);
615 fprintf(irp->f, "$%s_%" PRIu32 "", bb->name_hint, bb->debug_id);
436616 }
437617}
438618
439static void ir_print_return(IrPrint *irp, IrInstructionReturn *instruction) {
619static void ir_print_return_src(IrPrintSrc *irp, IrInstSrcReturn *inst) {
440620 fprintf(irp->f, "return ");
441 ir_print_other_instruction(irp, instruction->operand);
621 ir_print_other_inst_src(irp, inst->operand);
442622}
443623
444static void ir_print_const(IrPrint *irp, IrInstructionConst *const_instruction) {
445 ir_print_const_value(irp, const_instruction->base.value);
624static void ir_print_return_gen(IrPrintGen *irp, IrInstGenReturn *inst) {
625 fprintf(irp->f, "return ");
626 ir_print_other_inst_gen(irp, inst->operand);
627}
628
629static void ir_print_const(IrPrintSrc *irp, IrInstSrcConst *const_instruction) {
630 ir_print_const_value(irp->codegen, irp->f, const_instruction->value);
631}
632
633static void ir_print_const(IrPrintGen *irp, IrInstGenConst *const_instruction) {
634 ir_print_const_value(irp->codegen, irp->f, const_instruction->base.value);
446635}
447636
448637static const char *ir_bin_op_id_str(IrBinOp op_id) {
......@@ -531,89 +720,111 @@ static const char *ir_un_op_id_str(IrUnOp op_id) {
531720 zig_unreachable();
532721}
533722
534static void ir_print_un_op(IrPrint *irp, IrInstructionUnOp *un_op_instruction) {
535 fprintf(irp->f, "%s ", ir_un_op_id_str(un_op_instruction->op_id));
536 ir_print_other_instruction(irp, un_op_instruction->value);
723static void ir_print_un_op(IrPrintSrc *irp, IrInstSrcUnOp *inst) {
724 fprintf(irp->f, "%s ", ir_un_op_id_str(inst->op_id));
725 ir_print_other_inst_src(irp, inst->value);
726}
727
728static void ir_print_bin_op(IrPrintSrc *irp, IrInstSrcBinOp *bin_op_instruction) {
729 ir_print_other_inst_src(irp, bin_op_instruction->op1);
730 fprintf(irp->f, " %s ", ir_bin_op_id_str(bin_op_instruction->op_id));
731 ir_print_other_inst_src(irp, bin_op_instruction->op2);
732 if (!bin_op_instruction->safety_check_on) {
733 fprintf(irp->f, " // no safety");
734 }
537735}
538736
539static void ir_print_bin_op(IrPrint *irp, IrInstructionBinOp *bin_op_instruction) {
540 ir_print_other_instruction(irp, bin_op_instruction->op1);
737static void ir_print_bin_op(IrPrintGen *irp, IrInstGenBinOp *bin_op_instruction) {
738 ir_print_other_inst_gen(irp, bin_op_instruction->op1);
541739 fprintf(irp->f, " %s ", ir_bin_op_id_str(bin_op_instruction->op_id));
542 ir_print_other_instruction(irp, bin_op_instruction->op2);
740 ir_print_other_inst_gen(irp, bin_op_instruction->op2);
543741 if (!bin_op_instruction->safety_check_on) {
544742 fprintf(irp->f, " // no safety");
545743 }
546744}
547745
548static void ir_print_merge_err_sets(IrPrint *irp, IrInstructionMergeErrSets *instruction) {
549 ir_print_other_instruction(irp, instruction->op1);
746static void ir_print_merge_err_sets(IrPrintSrc *irp, IrInstSrcMergeErrSets *instruction) {
747 ir_print_other_inst_src(irp, instruction->op1);
550748 fprintf(irp->f, " || ");
551 ir_print_other_instruction(irp, instruction->op2);
749 ir_print_other_inst_src(irp, instruction->op2);
552750 if (instruction->type_name != nullptr) {
553751 fprintf(irp->f, " // name=%s", buf_ptr(instruction->type_name));
554752 }
555753}
556754
557static void ir_print_decl_var_src(IrPrint *irp, IrInstructionDeclVarSrc *decl_var_instruction) {
755static void ir_print_decl_var_src(IrPrintSrc *irp, IrInstSrcDeclVar *decl_var_instruction) {
558756 const char *var_or_const = decl_var_instruction->var->gen_is_const ? "const" : "var";
559757 const char *name = decl_var_instruction->var->name;
560758 if (decl_var_instruction->var_type) {
561759 fprintf(irp->f, "%s %s: ", var_or_const, name);
562 ir_print_other_instruction(irp, decl_var_instruction->var_type);
760 ir_print_other_inst_src(irp, decl_var_instruction->var_type);
563761 fprintf(irp->f, " ");
564762 } else {
565763 fprintf(irp->f, "%s %s ", var_or_const, name);
566764 }
567765 if (decl_var_instruction->align_value) {
568766 fprintf(irp->f, "align ");
569 ir_print_other_instruction(irp, decl_var_instruction->align_value);
767 ir_print_other_inst_src(irp, decl_var_instruction->align_value);
570768 fprintf(irp->f, " ");
571769 }
572770 fprintf(irp->f, "= ");
573 ir_print_other_instruction(irp, decl_var_instruction->ptr);
771 ir_print_other_inst_src(irp, decl_var_instruction->ptr);
574772 if (decl_var_instruction->var->is_comptime != nullptr) {
575773 fprintf(irp->f, " // comptime = ");
576 ir_print_other_instruction(irp, decl_var_instruction->var->is_comptime);
774 ir_print_other_inst_src(irp, decl_var_instruction->var->is_comptime);
577775 }
578776}
579777
580static void ir_print_cast(IrPrint *irp, IrInstructionCast *cast_instruction) {
581 fprintf(irp->f, "cast ");
582 ir_print_other_instruction(irp, cast_instruction->value);
583 fprintf(irp->f, " to %s", buf_ptr(&cast_instruction->dest_type->name));
778static const char *cast_op_str(CastOp op) {
779 switch (op) {
780 case CastOpNoCast: return "NoCast";
781 case CastOpNoop: return "NoOp";
782 case CastOpIntToFloat: return "IntToFloat";
783 case CastOpFloatToInt: return "FloatToInt";
784 case CastOpBoolToInt: return "BoolToInt";
785 case CastOpNumLitToConcrete: return "NumLitToConcrate";
786 case CastOpErrSet: return "ErrSet";
787 case CastOpBitCast: return "BitCast";
788 }
789 zig_unreachable();
790}
791
792static void ir_print_cast(IrPrintGen *irp, IrInstGenCast *cast_instruction) {
793 fprintf(irp->f, "%s cast ", cast_op_str(cast_instruction->cast_op));
794 ir_print_other_inst_gen(irp, cast_instruction->value);
584795}
585796
586static void ir_print_result_loc_var(IrPrint *irp, ResultLocVar *result_loc_var) {
797static void ir_print_result_loc_var(IrPrintSrc *irp, ResultLocVar *result_loc_var) {
587798 fprintf(irp->f, "var(");
588 ir_print_other_instruction(irp, result_loc_var->base.source_instruction);
799 ir_print_other_inst_src(irp, result_loc_var->base.source_instruction);
589800 fprintf(irp->f, ")");
590801}
591802
592static void ir_print_result_loc_instruction(IrPrint *irp, ResultLocInstruction *result_loc_inst) {
803static void ir_print_result_loc_instruction(IrPrintSrc *irp, ResultLocInstruction *result_loc_inst) {
593804 fprintf(irp->f, "inst(");
594 ir_print_other_instruction(irp, result_loc_inst->base.source_instruction);
805 ir_print_other_inst_src(irp, result_loc_inst->base.source_instruction);
595806 fprintf(irp->f, ")");
596807}
597808
598static void ir_print_result_loc_peer(IrPrint *irp, ResultLocPeer *result_loc_peer) {
809static void ir_print_result_loc_peer(IrPrintSrc *irp, ResultLocPeer *result_loc_peer) {
599810 fprintf(irp->f, "peer(next=");
600811 ir_print_other_block(irp, result_loc_peer->next_bb);
601812 fprintf(irp->f, ")");
602813}
603814
604static void ir_print_result_loc_bit_cast(IrPrint *irp, ResultLocBitCast *result_loc_bit_cast) {
815static void ir_print_result_loc_bit_cast(IrPrintSrc *irp, ResultLocBitCast *result_loc_bit_cast) {
605816 fprintf(irp->f, "bitcast(ty=");
606 ir_print_other_instruction(irp, result_loc_bit_cast->base.source_instruction);
817 ir_print_other_inst_src(irp, result_loc_bit_cast->base.source_instruction);
607818 fprintf(irp->f, ")");
608819}
609820
610static void ir_print_result_loc_cast(IrPrint *irp, ResultLocCast *result_loc_cast) {
821static void ir_print_result_loc_cast(IrPrintSrc *irp, ResultLocCast *result_loc_cast) {
611822 fprintf(irp->f, "cast(ty=");
612 ir_print_other_instruction(irp, result_loc_cast->base.source_instruction);
823 ir_print_other_inst_src(irp, result_loc_cast->base.source_instruction);
613824 fprintf(irp->f, ")");
614825}
615826
616static void ir_print_result_loc(IrPrint *irp, ResultLoc *result_loc) {
827static void ir_print_result_loc(IrPrintSrc *irp, ResultLoc *result_loc) {
617828 switch (result_loc->id) {
618829 case ResultLocIdInvalid:
619830 zig_unreachable();
......@@ -640,34 +851,34 @@ static void ir_print_result_loc(IrPrint *irp, ResultLoc *result_loc) {
640851 zig_unreachable();
641852}
642853
643static void ir_print_call_extra(IrPrint *irp, IrInstructionCallExtra *instruction) {
854static void ir_print_call_extra(IrPrintSrc *irp, IrInstSrcCallExtra *instruction) {
644855 fprintf(irp->f, "opts=");
645 ir_print_other_instruction(irp, instruction->options);
856 ir_print_other_inst_src(irp, instruction->options);
646857 fprintf(irp->f, ", fn=");
647 ir_print_other_instruction(irp, instruction->fn_ref);
858 ir_print_other_inst_src(irp, instruction->fn_ref);
648859 fprintf(irp->f, ", args=");
649 ir_print_other_instruction(irp, instruction->args);
860 ir_print_other_inst_src(irp, instruction->args);
650861 fprintf(irp->f, ", result=");
651862 ir_print_result_loc(irp, instruction->result_loc);
652863}
653864
654static void ir_print_call_src_args(IrPrint *irp, IrInstructionCallSrcArgs *instruction) {
865static void ir_print_call_args(IrPrintSrc *irp, IrInstSrcCallArgs *instruction) {
655866 fprintf(irp->f, "opts=");
656 ir_print_other_instruction(irp, instruction->options);
867 ir_print_other_inst_src(irp, instruction->options);
657868 fprintf(irp->f, ", fn=");
658 ir_print_other_instruction(irp, instruction->fn_ref);
869 ir_print_other_inst_src(irp, instruction->fn_ref);
659870 fprintf(irp->f, ", args=(");
660871 for (size_t i = 0; i < instruction->args_len; i += 1) {
661 IrInstruction *arg = instruction->args_ptr[i];
872 IrInstSrc *arg = instruction->args_ptr[i];
662873 if (i != 0)
663874 fprintf(irp->f, ", ");
664 ir_print_other_instruction(irp, arg);
875 ir_print_other_inst_src(irp, arg);
665876 }
666877 fprintf(irp->f, "), result=");
667878 ir_print_result_loc(irp, instruction->result_loc);
668879}
669880
670static void ir_print_call_src(IrPrint *irp, IrInstructionCallSrc *call_instruction) {
881static void ir_print_call_src(IrPrintSrc *irp, IrInstSrcCall *call_instruction) {
671882 switch (call_instruction->modifier) {
672883 case CallModifierNone:
673884 break;
......@@ -699,20 +910,20 @@ static void ir_print_call_src(IrPrint *irp, IrInstructionCallSrc *call_instructi
699910 fprintf(irp->f, "%s", buf_ptr(&call_instruction->fn_entry->symbol_name));
700911 } else {
701912 assert(call_instruction->fn_ref);
702 ir_print_other_instruction(irp, call_instruction->fn_ref);
913 ir_print_other_inst_src(irp, call_instruction->fn_ref);
703914 }
704915 fprintf(irp->f, "(");
705916 for (size_t i = 0; i < call_instruction->arg_count; i += 1) {
706 IrInstruction *arg = call_instruction->args[i];
917 IrInstSrc *arg = call_instruction->args[i];
707918 if (i != 0)
708919 fprintf(irp->f, ", ");
709 ir_print_other_instruction(irp, arg);
920 ir_print_other_inst_src(irp, arg);
710921 }
711922 fprintf(irp->f, ")result=");
712923 ir_print_result_loc(irp, call_instruction->result_loc);
713924}
714925
715static void ir_print_call_gen(IrPrint *irp, IrInstructionCallGen *call_instruction) {
926static void ir_print_call_gen(IrPrintGen *irp, IrInstGenCall *call_instruction) {
716927 switch (call_instruction->modifier) {
717928 case CallModifierNone:
718929 break;
......@@ -744,221 +955,291 @@ static void ir_print_call_gen(IrPrint *irp, IrInstructionCallGen *call_instructi
744955 fprintf(irp->f, "%s", buf_ptr(&call_instruction->fn_entry->symbol_name));
745956 } else {
746957 assert(call_instruction->fn_ref);
747 ir_print_other_instruction(irp, call_instruction->fn_ref);
958 ir_print_other_inst_gen(irp, call_instruction->fn_ref);
748959 }
749960 fprintf(irp->f, "(");
750961 for (size_t i = 0; i < call_instruction->arg_count; i += 1) {
751 IrInstruction *arg = call_instruction->args[i];
962 IrInstGen *arg = call_instruction->args[i];
752963 if (i != 0)
753964 fprintf(irp->f, ", ");
754 ir_print_other_instruction(irp, arg);
965 ir_print_other_inst_gen(irp, arg);
755966 }
756967 fprintf(irp->f, ")result=");
757 ir_print_other_instruction(irp, call_instruction->result_loc);
968 ir_print_other_inst_gen(irp, call_instruction->result_loc);
758969}
759970
760static void ir_print_cond_br(IrPrint *irp, IrInstructionCondBr *cond_br_instruction) {
971static void ir_print_cond_br(IrPrintSrc *irp, IrInstSrcCondBr *inst) {
761972 fprintf(irp->f, "if (");
762 ir_print_other_instruction(irp, cond_br_instruction->condition);
973 ir_print_other_inst_src(irp, inst->condition);
763974 fprintf(irp->f, ") ");
764 ir_print_other_block(irp, cond_br_instruction->then_block);
975 ir_print_other_block(irp, inst->then_block);
765976 fprintf(irp->f, " else ");
766 ir_print_other_block(irp, cond_br_instruction->else_block);
767 if (cond_br_instruction->is_comptime != nullptr) {
977 ir_print_other_block(irp, inst->else_block);
978 if (inst->is_comptime != nullptr) {
768979 fprintf(irp->f, " // comptime = ");
769 ir_print_other_instruction(irp, cond_br_instruction->is_comptime);
980 ir_print_other_inst_src(irp, inst->is_comptime);
770981 }
771982}
772983
773static void ir_print_br(IrPrint *irp, IrInstructionBr *br_instruction) {
984static void ir_print_cond_br(IrPrintGen *irp, IrInstGenCondBr *inst) {
985 fprintf(irp->f, "if (");
986 ir_print_other_inst_gen(irp, inst->condition);
987 fprintf(irp->f, ") ");
988 ir_print_other_block_gen(irp, inst->then_block);
989 fprintf(irp->f, " else ");
990 ir_print_other_block_gen(irp, inst->else_block);
991}
992
993static void ir_print_br(IrPrintSrc *irp, IrInstSrcBr *br_instruction) {
774994 fprintf(irp->f, "goto ");
775995 ir_print_other_block(irp, br_instruction->dest_block);
776996 if (br_instruction->is_comptime != nullptr) {
777997 fprintf(irp->f, " // comptime = ");
778 ir_print_other_instruction(irp, br_instruction->is_comptime);
998 ir_print_other_inst_src(irp, br_instruction->is_comptime);
779999 }
7801000}
7811001
782static void ir_print_phi(IrPrint *irp, IrInstructionPhi *phi_instruction) {
1002static void ir_print_br(IrPrintGen *irp, IrInstGenBr *inst) {
1003 fprintf(irp->f, "goto ");
1004 ir_print_other_block_gen(irp, inst->dest_block);
1005}
1006
1007static void ir_print_phi(IrPrintSrc *irp, IrInstSrcPhi *phi_instruction) {
7831008 assert(phi_instruction->incoming_count != 0);
7841009 assert(phi_instruction->incoming_count != SIZE_MAX);
7851010 for (size_t i = 0; i < phi_instruction->incoming_count; i += 1) {
786 IrBasicBlock *incoming_block = phi_instruction->incoming_blocks[i];
787 IrInstruction *incoming_value = phi_instruction->incoming_values[i];
1011 IrBasicBlockSrc *incoming_block = phi_instruction->incoming_blocks[i];
1012 IrInstSrc *incoming_value = phi_instruction->incoming_values[i];
7881013 if (i != 0)
7891014 fprintf(irp->f, " ");
7901015 ir_print_other_block(irp, incoming_block);
7911016 fprintf(irp->f, ":");
792 ir_print_other_instruction(irp, incoming_value);
1017 ir_print_other_inst_src(irp, incoming_value);
7931018 }
7941019}
7951020
796static void ir_print_container_init_list(IrPrint *irp, IrInstructionContainerInitList *instruction) {
1021static void ir_print_phi(IrPrintGen *irp, IrInstGenPhi *phi_instruction) {
1022 assert(phi_instruction->incoming_count != 0);
1023 assert(phi_instruction->incoming_count != SIZE_MAX);
1024 for (size_t i = 0; i < phi_instruction->incoming_count; i += 1) {
1025 IrBasicBlockGen *incoming_block = phi_instruction->incoming_blocks[i];
1026 IrInstGen *incoming_value = phi_instruction->incoming_values[i];
1027 if (i != 0)
1028 fprintf(irp->f, " ");
1029 ir_print_other_block_gen(irp, incoming_block);
1030 fprintf(irp->f, ":");
1031 ir_print_other_inst_gen(irp, incoming_value);
1032 }
1033}
1034
1035static void ir_print_container_init_list(IrPrintSrc *irp, IrInstSrcContainerInitList *instruction) {
7971036 fprintf(irp->f, "{");
7981037 if (instruction->item_count > 50) {
7991038 fprintf(irp->f, "...(%" ZIG_PRI_usize " items)...", instruction->item_count);
8001039 } else {
8011040 for (size_t i = 0; i < instruction->item_count; i += 1) {
802 IrInstruction *result_loc = instruction->elem_result_loc_list[i];
1041 IrInstSrc *result_loc = instruction->elem_result_loc_list[i];
8031042 if (i != 0)
8041043 fprintf(irp->f, ", ");
805 ir_print_other_instruction(irp, result_loc);
1044 ir_print_other_inst_src(irp, result_loc);
8061045 }
8071046 }
8081047 fprintf(irp->f, "}result=");
809 ir_print_other_instruction(irp, instruction->result_loc);
1048 ir_print_other_inst_src(irp, instruction->result_loc);
8101049}
8111050
812static void ir_print_container_init_fields(IrPrint *irp, IrInstructionContainerInitFields *instruction) {
1051static void ir_print_container_init_fields(IrPrintSrc *irp, IrInstSrcContainerInitFields *instruction) {
8131052 fprintf(irp->f, "{");
8141053 for (size_t i = 0; i < instruction->field_count; i += 1) {
815 IrInstructionContainerInitFieldsField *field = &instruction->fields[i];
1054 IrInstSrcContainerInitFieldsField *field = &instruction->fields[i];
8161055 const char *comma = (i == 0) ? "" : ", ";
8171056 fprintf(irp->f, "%s.%s = ", comma, buf_ptr(field->name));
818 ir_print_other_instruction(irp, field->result_loc);
1057 ir_print_other_inst_src(irp, field->result_loc);
8191058 }
8201059 fprintf(irp->f, "}result=");
821 ir_print_other_instruction(irp, instruction->result_loc);
1060 ir_print_other_inst_src(irp, instruction->result_loc);
1061}
1062
1063static void ir_print_unreachable(IrPrintSrc *irp, IrInstSrcUnreachable *instruction) {
1064 fprintf(irp->f, "unreachable");
8221065}
8231066
824static void ir_print_unreachable(IrPrint *irp, IrInstructionUnreachable *instruction) {
1067static void ir_print_unreachable(IrPrintGen *irp, IrInstGenUnreachable *instruction) {
8251068 fprintf(irp->f, "unreachable");
8261069}
8271070
828static void ir_print_elem_ptr(IrPrint *irp, IrInstructionElemPtr *instruction) {
1071static void ir_print_elem_ptr(IrPrintSrc *irp, IrInstSrcElemPtr *instruction) {
8291072 fprintf(irp->f, "&");
830 ir_print_other_instruction(irp, instruction->array_ptr);
1073 ir_print_other_inst_src(irp, instruction->array_ptr);
8311074 fprintf(irp->f, "[");
832 ir_print_other_instruction(irp, instruction->elem_index);
1075 ir_print_other_inst_src(irp, instruction->elem_index);
8331076 fprintf(irp->f, "]");
8341077 if (!instruction->safety_check_on) {
8351078 fprintf(irp->f, " // no safety");
8361079 }
8371080}
8381081
839static void ir_print_var_ptr(IrPrint *irp, IrInstructionVarPtr *instruction) {
1082static void ir_print_elem_ptr(IrPrintGen *irp, IrInstGenElemPtr *instruction) {
1083 fprintf(irp->f, "&");
1084 ir_print_other_inst_gen(irp, instruction->array_ptr);
1085 fprintf(irp->f, "[");
1086 ir_print_other_inst_gen(irp, instruction->elem_index);
1087 fprintf(irp->f, "]");
1088 if (!instruction->safety_check_on) {
1089 fprintf(irp->f, " // no safety");
1090 }
1091}
1092
1093static void ir_print_var_ptr(IrPrintSrc *irp, IrInstSrcVarPtr *instruction) {
1094 fprintf(irp->f, "&%s", instruction->var->name);
1095}
1096
1097static void ir_print_var_ptr(IrPrintGen *irp, IrInstGenVarPtr *instruction) {
8401098 fprintf(irp->f, "&%s", instruction->var->name);
8411099}
8421100
843static void ir_print_return_ptr(IrPrint *irp, IrInstructionReturnPtr *instruction) {
1101static void ir_print_return_ptr(IrPrintGen *irp, IrInstGenReturnPtr *instruction) {
8441102 fprintf(irp->f, "@ReturnPtr");
8451103}
8461104
847static void ir_print_load_ptr(IrPrint *irp, IrInstructionLoadPtr *instruction) {
848 ir_print_other_instruction(irp, instruction->ptr);
1105static void ir_print_load_ptr(IrPrintSrc *irp, IrInstSrcLoadPtr *instruction) {
1106 ir_print_other_inst_src(irp, instruction->ptr);
8491107 fprintf(irp->f, ".*");
8501108}
8511109
852static void ir_print_load_ptr_gen(IrPrint *irp, IrInstructionLoadPtrGen *instruction) {
1110static void ir_print_load_ptr_gen(IrPrintGen *irp, IrInstGenLoadPtr *instruction) {
8531111 fprintf(irp->f, "loadptr(");
854 ir_print_other_instruction(irp, instruction->ptr);
1112 ir_print_other_inst_gen(irp, instruction->ptr);
8551113 fprintf(irp->f, ")result=");
856 ir_print_other_instruction(irp, instruction->result_loc);
1114 ir_print_other_inst_gen(irp, instruction->result_loc);
1115}
1116
1117static void ir_print_store_ptr(IrPrintSrc *irp, IrInstSrcStorePtr *instruction) {
1118 fprintf(irp->f, "*");
1119 ir_print_var_src(irp, instruction->ptr);
1120 fprintf(irp->f, " = ");
1121 ir_print_other_inst_src(irp, instruction->value);
8571122}
8581123
859static void ir_print_store_ptr(IrPrint *irp, IrInstructionStorePtr *instruction) {
1124static void ir_print_store_ptr(IrPrintGen *irp, IrInstGenStorePtr *instruction) {
8601125 fprintf(irp->f, "*");
861 ir_print_var_instruction(irp, instruction->ptr);
1126 ir_print_var_gen(irp, instruction->ptr);
8621127 fprintf(irp->f, " = ");
863 ir_print_other_instruction(irp, instruction->value);
1128 ir_print_other_inst_gen(irp, instruction->value);
8641129}
8651130
866static void ir_print_vector_store_elem(IrPrint *irp, IrInstructionVectorStoreElem *instruction) {
1131static void ir_print_vector_store_elem(IrPrintGen *irp, IrInstGenVectorStoreElem *instruction) {
8671132 fprintf(irp->f, "vector_ptr=");
868 ir_print_var_instruction(irp, instruction->vector_ptr);
1133 ir_print_var_gen(irp, instruction->vector_ptr);
8691134 fprintf(irp->f, ",index=");
870 ir_print_var_instruction(irp, instruction->index);
1135 ir_print_var_gen(irp, instruction->index);
8711136 fprintf(irp->f, ",value=");
872 ir_print_other_instruction(irp, instruction->value);
1137 ir_print_other_inst_gen(irp, instruction->value);
8731138}
8741139
875static void ir_print_typeof(IrPrint *irp, IrInstructionTypeOf *instruction) {
1140static void ir_print_typeof(IrPrintSrc *irp, IrInstSrcTypeOf *instruction) {
8761141 fprintf(irp->f, "@TypeOf(");
877 ir_print_other_instruction(irp, instruction->value);
1142 ir_print_other_inst_src(irp, instruction->value);
8781143 fprintf(irp->f, ")");
8791144}
8801145
881static void ir_print_field_ptr(IrPrint *irp, IrInstructionFieldPtr *instruction) {
1146static void ir_print_binary_not(IrPrintGen *irp, IrInstGenBinaryNot *instruction) {
1147 fprintf(irp->f, "~");
1148 ir_print_other_inst_gen(irp, instruction->operand);
1149}
1150
1151static void ir_print_negation(IrPrintGen *irp, IrInstGenNegation *instruction) {
1152 fprintf(irp->f, "-");
1153 ir_print_other_inst_gen(irp, instruction->operand);
1154}
1155
1156static void ir_print_negation_wrapping(IrPrintGen *irp, IrInstGenNegationWrapping *instruction) {
1157 fprintf(irp->f, "-%%");
1158 ir_print_other_inst_gen(irp, instruction->operand);
1159}
1160
1161
1162static void ir_print_field_ptr(IrPrintSrc *irp, IrInstSrcFieldPtr *instruction) {
8821163 if (instruction->field_name_buffer) {
8831164 fprintf(irp->f, "fieldptr ");
884 ir_print_other_instruction(irp, instruction->container_ptr);
1165 ir_print_other_inst_src(irp, instruction->container_ptr);
8851166 fprintf(irp->f, ".%s", buf_ptr(instruction->field_name_buffer));
8861167 } else {
8871168 assert(instruction->field_name_expr);
8881169 fprintf(irp->f, "@field(");
889 ir_print_other_instruction(irp, instruction->container_ptr);
1170 ir_print_other_inst_src(irp, instruction->container_ptr);
8901171 fprintf(irp->f, ", ");
891 ir_print_other_instruction(irp, instruction->field_name_expr);
1172 ir_print_other_inst_src(irp, instruction->field_name_expr);
8921173 fprintf(irp->f, ")");
8931174 }
8941175}
8951176
896static void ir_print_struct_field_ptr(IrPrint *irp, IrInstructionStructFieldPtr *instruction) {
1177static void ir_print_struct_field_ptr(IrPrintGen *irp, IrInstGenStructFieldPtr *instruction) {
8971178 fprintf(irp->f, "@StructFieldPtr(&");
898 ir_print_other_instruction(irp, instruction->struct_ptr);
1179 ir_print_other_inst_gen(irp, instruction->struct_ptr);
8991180 fprintf(irp->f, ".%s", buf_ptr(instruction->field->name));
9001181 fprintf(irp->f, ")");
9011182}
9021183
903static void ir_print_union_field_ptr(IrPrint *irp, IrInstructionUnionFieldPtr *instruction) {
1184static void ir_print_union_field_ptr(IrPrintGen *irp, IrInstGenUnionFieldPtr *instruction) {
9041185 fprintf(irp->f, "@UnionFieldPtr(&");
905 ir_print_other_instruction(irp, instruction->union_ptr);
1186 ir_print_other_inst_gen(irp, instruction->union_ptr);
9061187 fprintf(irp->f, ".%s", buf_ptr(instruction->field->enum_field->name));
9071188 fprintf(irp->f, ")");
9081189}
9091190
910static void ir_print_set_cold(IrPrint *irp, IrInstructionSetCold *instruction) {
1191static void ir_print_set_cold(IrPrintSrc *irp, IrInstSrcSetCold *instruction) {
9111192 fprintf(irp->f, "@setCold(");
912 ir_print_other_instruction(irp, instruction->is_cold);
1193 ir_print_other_inst_src(irp, instruction->is_cold);
9131194 fprintf(irp->f, ")");
9141195}
9151196
916static void ir_print_set_runtime_safety(IrPrint *irp, IrInstructionSetRuntimeSafety *instruction) {
1197static void ir_print_set_runtime_safety(IrPrintSrc *irp, IrInstSrcSetRuntimeSafety *instruction) {
9171198 fprintf(irp->f, "@setRuntimeSafety(");
918 ir_print_other_instruction(irp, instruction->safety_on);
1199 ir_print_other_inst_src(irp, instruction->safety_on);
9191200 fprintf(irp->f, ")");
9201201}
9211202
922static void ir_print_set_float_mode(IrPrint *irp, IrInstructionSetFloatMode *instruction) {
1203static void ir_print_set_float_mode(IrPrintSrc *irp, IrInstSrcSetFloatMode *instruction) {
9231204 fprintf(irp->f, "@setFloatMode(");
924 ir_print_other_instruction(irp, instruction->scope_value);
1205 ir_print_other_inst_src(irp, instruction->scope_value);
9251206 fprintf(irp->f, ", ");
926 ir_print_other_instruction(irp, instruction->mode_value);
1207 ir_print_other_inst_src(irp, instruction->mode_value);
9271208 fprintf(irp->f, ")");
9281209}
9291210
930static void ir_print_array_type(IrPrint *irp, IrInstructionArrayType *instruction) {
1211static void ir_print_array_type(IrPrintSrc *irp, IrInstSrcArrayType *instruction) {
9311212 fprintf(irp->f, "[");
932 ir_print_other_instruction(irp, instruction->size);
1213 ir_print_other_inst_src(irp, instruction->size);
9331214 if (instruction->sentinel != nullptr) {
9341215 fprintf(irp->f, ":");
935 ir_print_other_instruction(irp, instruction->sentinel);
1216 ir_print_other_inst_src(irp, instruction->sentinel);
9361217 }
9371218 fprintf(irp->f, "]");
938 ir_print_other_instruction(irp, instruction->child_type);
1219 ir_print_other_inst_src(irp, instruction->child_type);
9391220}
9401221
941static void ir_print_slice_type(IrPrint *irp, IrInstructionSliceType *instruction) {
1222static void ir_print_slice_type(IrPrintSrc *irp, IrInstSrcSliceType *instruction) {
9421223 const char *const_kw = instruction->is_const ? "const " : "";
9431224 fprintf(irp->f, "[]%s", const_kw);
944 ir_print_other_instruction(irp, instruction->child_type);
1225 ir_print_other_inst_src(irp, instruction->child_type);
9451226}
9461227
947static void ir_print_any_frame_type(IrPrint *irp, IrInstructionAnyFrameType *instruction) {
1228static void ir_print_any_frame_type(IrPrintSrc *irp, IrInstSrcAnyFrameType *instruction) {
9481229 if (instruction->payload_type == nullptr) {
9491230 fprintf(irp->f, "anyframe");
9501231 } else {
9511232 fprintf(irp->f, "anyframe->");
952 ir_print_other_instruction(irp, instruction->payload_type);
1233 ir_print_other_inst_src(irp, instruction->payload_type);
9531234 }
9541235}
9551236
956static void ir_print_asm_src(IrPrint *irp, IrInstructionAsmSrc *instruction) {
957 assert(instruction->base.source_node->type == NodeTypeAsmExpr);
958 AstNodeAsmExpr *asm_expr = &instruction->base.source_node->data.asm_expr;
1237static void ir_print_asm_src(IrPrintSrc *irp, IrInstSrcAsm *instruction) {
1238 assert(instruction->base.base.source_node->type == NodeTypeAsmExpr);
1239 AstNodeAsmExpr *asm_expr = &instruction->base.base.source_node->data.asm_expr;
9591240 const char *volatile_kw = instruction->has_side_effects ? " volatile" : "";
9601241 fprintf(irp->f, "asm%s (", volatile_kw);
961 ir_print_other_instruction(irp, instruction->asm_template);
1242 ir_print_other_inst_src(irp, instruction->asm_template);
9621243
9631244 for (size_t i = 0; i < asm_expr->output_list.length; i += 1) {
9641245 AsmOutput *asm_output = asm_expr->output_list.at(i);
......@@ -969,7 +1250,7 @@ static void ir_print_asm_src(IrPrint *irp, IrInstructionAsmSrc *instruction) {
9691250 buf_ptr(asm_output->constraint));
9701251 if (asm_output->return_type) {
9711252 fprintf(irp->f, "-> ");
972 ir_print_other_instruction(irp, instruction->output_types[i]);
1253 ir_print_other_inst_src(irp, instruction->output_types[i]);
9731254 } else {
9741255 fprintf(irp->f, "%s", buf_ptr(asm_output->variable_name));
9751256 }
......@@ -984,7 +1265,7 @@ static void ir_print_asm_src(IrPrint *irp, IrInstructionAsmSrc *instruction) {
9841265 fprintf(irp->f, "[%s] \"%s\" (",
9851266 buf_ptr(asm_input->asm_symbolic_name),
9861267 buf_ptr(asm_input->constraint));
987 ir_print_other_instruction(irp, instruction->input_list[i]);
1268 ir_print_other_inst_src(irp, instruction->input_list[i]);
9881269 fprintf(irp->f, ")");
9891270 }
9901271 fprintf(irp->f, " : ");
......@@ -996,9 +1277,9 @@ static void ir_print_asm_src(IrPrint *irp, IrInstructionAsmSrc *instruction) {
9961277 fprintf(irp->f, ")");
9971278}
9981279
999static void ir_print_asm_gen(IrPrint *irp, IrInstructionAsmGen *instruction) {
1000 assert(instruction->base.source_node->type == NodeTypeAsmExpr);
1001 AstNodeAsmExpr *asm_expr = &instruction->base.source_node->data.asm_expr;
1280static void ir_print_asm_gen(IrPrintGen *irp, IrInstGenAsm *instruction) {
1281 assert(instruction->base.base.source_node->type == NodeTypeAsmExpr);
1282 AstNodeAsmExpr *asm_expr = &instruction->base.base.source_node->data.asm_expr;
10021283 const char *volatile_kw = instruction->has_side_effects ? " volatile" : "";
10031284 fprintf(irp->f, "asm%s (\"%s\") : ", volatile_kw, buf_ptr(instruction->asm_template));
10041285
......@@ -1011,7 +1292,7 @@ static void ir_print_asm_gen(IrPrint *irp, IrInstructionAsmGen *instruction) {
10111292 buf_ptr(asm_output->constraint));
10121293 if (asm_output->return_type) {
10131294 fprintf(irp->f, "-> ");
1014 ir_print_other_instruction(irp, instruction->output_types[i]);
1295 ir_print_other_inst_gen(irp, instruction->output_types[i]);
10151296 } else {
10161297 fprintf(irp->f, "%s", buf_ptr(asm_output->variable_name));
10171298 }
......@@ -1026,7 +1307,7 @@ static void ir_print_asm_gen(IrPrint *irp, IrInstructionAsmGen *instruction) {
10261307 fprintf(irp->f, "[%s] \"%s\" (",
10271308 buf_ptr(asm_input->asm_symbolic_name),
10281309 buf_ptr(asm_input->constraint));
1029 ir_print_other_instruction(irp, instruction->input_list[i]);
1310 ir_print_other_inst_gen(irp, instruction->input_list[i]);
10301311 fprintf(irp->f, ")");
10311312 }
10321313 fprintf(irp->f, " : ");
......@@ -1038,96 +1319,120 @@ static void ir_print_asm_gen(IrPrint *irp, IrInstructionAsmGen *instruction) {
10381319 fprintf(irp->f, ")");
10391320}
10401321
1041static void ir_print_size_of(IrPrint *irp, IrInstructionSizeOf *instruction) {
1322static void ir_print_size_of(IrPrintSrc *irp, IrInstSrcSizeOf *instruction) {
10421323 if (instruction->bit_size)
10431324 fprintf(irp->f, "@bitSizeOf(");
10441325 else
10451326 fprintf(irp->f, "@sizeOf(");
1046 ir_print_other_instruction(irp, instruction->type_value);
1327 ir_print_other_inst_src(irp, instruction->type_value);
10471328 fprintf(irp->f, ")");
10481329}
10491330
1050static void ir_print_test_non_null(IrPrint *irp, IrInstructionTestNonNull *instruction) {
1051 ir_print_other_instruction(irp, instruction->value);
1331static void ir_print_test_non_null(IrPrintSrc *irp, IrInstSrcTestNonNull *instruction) {
1332 ir_print_other_inst_src(irp, instruction->value);
1333 fprintf(irp->f, " != null");
1334}
1335
1336static void ir_print_test_non_null(IrPrintGen *irp, IrInstGenTestNonNull *instruction) {
1337 ir_print_other_inst_gen(irp, instruction->value);
10521338 fprintf(irp->f, " != null");
10531339}
10541340
1055static void ir_print_optional_unwrap_ptr(IrPrint *irp, IrInstructionOptionalUnwrapPtr *instruction) {
1341static void ir_print_optional_unwrap_ptr(IrPrintSrc *irp, IrInstSrcOptionalUnwrapPtr *instruction) {
10561342 fprintf(irp->f, "&");
1057 ir_print_other_instruction(irp, instruction->base_ptr);
1343 ir_print_other_inst_src(irp, instruction->base_ptr);
10581344 fprintf(irp->f, ".*.?");
10591345 if (!instruction->safety_check_on) {
10601346 fprintf(irp->f, " // no safety");
10611347 }
10621348}
10631349
1064static void ir_print_clz(IrPrint *irp, IrInstructionClz *instruction) {
1065 fprintf(irp->f, "@clz(");
1066 if (instruction->type != nullptr) {
1067 ir_print_other_instruction(irp, instruction->type);
1068 } else {
1069 fprintf(irp->f, "null");
1350static void ir_print_optional_unwrap_ptr(IrPrintGen *irp, IrInstGenOptionalUnwrapPtr *instruction) {
1351 fprintf(irp->f, "&");
1352 ir_print_other_inst_gen(irp, instruction->base_ptr);
1353 fprintf(irp->f, ".*.?");
1354 if (!instruction->safety_check_on) {
1355 fprintf(irp->f, " // no safety");
10701356 }
1357}
1358
1359static void ir_print_clz(IrPrintSrc *irp, IrInstSrcClz *instruction) {
1360 fprintf(irp->f, "@clz(");
1361 ir_print_other_inst_src(irp, instruction->type);
10711362 fprintf(irp->f, ",");
1072 ir_print_other_instruction(irp, instruction->op);
1363 ir_print_other_inst_src(irp, instruction->op);
10731364 fprintf(irp->f, ")");
10741365}
10751366
1076static void ir_print_ctz(IrPrint *irp, IrInstructionCtz *instruction) {
1367static void ir_print_clz(IrPrintGen *irp, IrInstGenClz *instruction) {
1368 fprintf(irp->f, "@clz(");
1369 ir_print_other_inst_gen(irp, instruction->op);
1370 fprintf(irp->f, ")");
1371}
1372
1373static void ir_print_ctz(IrPrintSrc *irp, IrInstSrcCtz *instruction) {
10771374 fprintf(irp->f, "@ctz(");
1078 if (instruction->type != nullptr) {
1079 ir_print_other_instruction(irp, instruction->type);
1080 } else {
1081 fprintf(irp->f, "null");
1082 }
1375 ir_print_other_inst_src(irp, instruction->type);
10831376 fprintf(irp->f, ",");
1084 ir_print_other_instruction(irp, instruction->op);
1377 ir_print_other_inst_src(irp, instruction->op);
10851378 fprintf(irp->f, ")");
10861379}
10871380
1088static void ir_print_pop_count(IrPrint *irp, IrInstructionPopCount *instruction) {
1381static void ir_print_ctz(IrPrintGen *irp, IrInstGenCtz *instruction) {
1382 fprintf(irp->f, "@ctz(");
1383 ir_print_other_inst_gen(irp, instruction->op);
1384 fprintf(irp->f, ")");
1385}
1386
1387static void ir_print_pop_count(IrPrintSrc *irp, IrInstSrcPopCount *instruction) {
10891388 fprintf(irp->f, "@popCount(");
1090 if (instruction->type != nullptr) {
1091 ir_print_other_instruction(irp, instruction->type);
1092 } else {
1093 fprintf(irp->f, "null");
1094 }
1389 ir_print_other_inst_src(irp, instruction->type);
10951390 fprintf(irp->f, ",");
1096 ir_print_other_instruction(irp, instruction->op);
1391 ir_print_other_inst_src(irp, instruction->op);
10971392 fprintf(irp->f, ")");
10981393}
10991394
1100static void ir_print_bswap(IrPrint *irp, IrInstructionBswap *instruction) {
1395static void ir_print_pop_count(IrPrintGen *irp, IrInstGenPopCount *instruction) {
1396 fprintf(irp->f, "@popCount(");
1397 ir_print_other_inst_gen(irp, instruction->op);
1398 fprintf(irp->f, ")");
1399}
1400
1401static void ir_print_bswap(IrPrintSrc *irp, IrInstSrcBswap *instruction) {
11011402 fprintf(irp->f, "@byteSwap(");
1102 if (instruction->type != nullptr) {
1103 ir_print_other_instruction(irp, instruction->type);
1104 } else {
1105 fprintf(irp->f, "null");
1106 }
1403 ir_print_other_inst_src(irp, instruction->type);
11071404 fprintf(irp->f, ",");
1108 ir_print_other_instruction(irp, instruction->op);
1405 ir_print_other_inst_src(irp, instruction->op);
11091406 fprintf(irp->f, ")");
11101407}
11111408
1112static void ir_print_bit_reverse(IrPrint *irp, IrInstructionBitReverse *instruction) {
1409static void ir_print_bswap(IrPrintGen *irp, IrInstGenBswap *instruction) {
1410 fprintf(irp->f, "@byteSwap(");
1411 ir_print_other_inst_gen(irp, instruction->op);
1412 fprintf(irp->f, ")");
1413}
1414
1415static void ir_print_bit_reverse(IrPrintSrc *irp, IrInstSrcBitReverse *instruction) {
11131416 fprintf(irp->f, "@bitReverse(");
1114 if (instruction->type != nullptr) {
1115 ir_print_other_instruction(irp, instruction->type);
1116 } else {
1117 fprintf(irp->f, "null");
1118 }
1417 ir_print_other_inst_src(irp, instruction->type);
11191418 fprintf(irp->f, ",");
1120 ir_print_other_instruction(irp, instruction->op);
1419 ir_print_other_inst_src(irp, instruction->op);
11211420 fprintf(irp->f, ")");
11221421}
11231422
1124static void ir_print_switch_br(IrPrint *irp, IrInstructionSwitchBr *instruction) {
1423static void ir_print_bit_reverse(IrPrintGen *irp, IrInstGenBitReverse *instruction) {
1424 fprintf(irp->f, "@bitReverse(");
1425 ir_print_other_inst_gen(irp, instruction->op);
1426 fprintf(irp->f, ")");
1427}
1428
1429static void ir_print_switch_br(IrPrintSrc *irp, IrInstSrcSwitchBr *instruction) {
11251430 fprintf(irp->f, "switch (");
1126 ir_print_other_instruction(irp, instruction->target_value);
1431 ir_print_other_inst_src(irp, instruction->target_value);
11271432 fprintf(irp->f, ") ");
11281433 for (size_t i = 0; i < instruction->case_count; i += 1) {
1129 IrInstructionSwitchBrCase *this_case = &instruction->cases[i];
1130 ir_print_other_instruction(irp, this_case->value);
1434 IrInstSrcSwitchBrCase *this_case = &instruction->cases[i];
1435 ir_print_other_inst_src(irp, this_case->value);
11311436 fprintf(irp->f, " => ");
11321437 ir_print_other_block(irp, this_case->block);
11331438 fprintf(irp->f, ", ");
......@@ -1136,359 +1441,453 @@ static void ir_print_switch_br(IrPrint *irp, IrInstructionSwitchBr *instruction)
11361441 ir_print_other_block(irp, instruction->else_block);
11371442 if (instruction->is_comptime != nullptr) {
11381443 fprintf(irp->f, " // comptime = ");
1139 ir_print_other_instruction(irp, instruction->is_comptime);
1444 ir_print_other_inst_src(irp, instruction->is_comptime);
1445 }
1446}
1447
1448static void ir_print_switch_br(IrPrintGen *irp, IrInstGenSwitchBr *instruction) {
1449 fprintf(irp->f, "switch (");
1450 ir_print_other_inst_gen(irp, instruction->target_value);
1451 fprintf(irp->f, ") ");
1452 for (size_t i = 0; i < instruction->case_count; i += 1) {
1453 IrInstGenSwitchBrCase *this_case = &instruction->cases[i];
1454 ir_print_other_inst_gen(irp, this_case->value);
1455 fprintf(irp->f, " => ");
1456 ir_print_other_block_gen(irp, this_case->block);
1457 fprintf(irp->f, ", ");
11401458 }
1459 fprintf(irp->f, "else => ");
1460 ir_print_other_block_gen(irp, instruction->else_block);
11411461}
11421462
1143static void ir_print_switch_var(IrPrint *irp, IrInstructionSwitchVar *instruction) {
1463static void ir_print_switch_var(IrPrintSrc *irp, IrInstSrcSwitchVar *instruction) {
11441464 fprintf(irp->f, "switchvar ");
1145 ir_print_other_instruction(irp, instruction->target_value_ptr);
1465 ir_print_other_inst_src(irp, instruction->target_value_ptr);
11461466 for (size_t i = 0; i < instruction->prongs_len; i += 1) {
11471467 fprintf(irp->f, ", ");
1148 ir_print_other_instruction(irp, instruction->prongs_ptr[i]);
1468 ir_print_other_inst_src(irp, instruction->prongs_ptr[i]);
11491469 }
11501470}
11511471
1152static void ir_print_switch_else_var(IrPrint *irp, IrInstructionSwitchElseVar *instruction) {
1472static void ir_print_switch_else_var(IrPrintSrc *irp, IrInstSrcSwitchElseVar *instruction) {
11531473 fprintf(irp->f, "switchelsevar ");
1154 ir_print_other_instruction(irp, &instruction->switch_br->base);
1474 ir_print_other_inst_src(irp, &instruction->switch_br->base);
11551475}
11561476
1157static void ir_print_switch_target(IrPrint *irp, IrInstructionSwitchTarget *instruction) {
1477static void ir_print_switch_target(IrPrintSrc *irp, IrInstSrcSwitchTarget *instruction) {
11581478 fprintf(irp->f, "switchtarget ");
1159 ir_print_other_instruction(irp, instruction->target_value_ptr);
1479 ir_print_other_inst_src(irp, instruction->target_value_ptr);
11601480}
11611481
1162static void ir_print_union_tag(IrPrint *irp, IrInstructionUnionTag *instruction) {
1482static void ir_print_union_tag(IrPrintGen *irp, IrInstGenUnionTag *instruction) {
11631483 fprintf(irp->f, "uniontag ");
1164 ir_print_other_instruction(irp, instruction->value);
1484 ir_print_other_inst_gen(irp, instruction->value);
11651485}
11661486
1167static void ir_print_import(IrPrint *irp, IrInstructionImport *instruction) {
1487static void ir_print_import(IrPrintSrc *irp, IrInstSrcImport *instruction) {
11681488 fprintf(irp->f, "@import(");
1169 ir_print_other_instruction(irp, instruction->name);
1489 ir_print_other_inst_src(irp, instruction->name);
11701490 fprintf(irp->f, ")");
11711491}
11721492
1173static void ir_print_ref(IrPrint *irp, IrInstructionRef *instruction) {
1493static void ir_print_ref(IrPrintSrc *irp, IrInstSrcRef *instruction) {
11741494 const char *const_str = instruction->is_const ? "const " : "";
11751495 const char *volatile_str = instruction->is_volatile ? "volatile " : "";
11761496 fprintf(irp->f, "%s%sref ", const_str, volatile_str);
1177 ir_print_other_instruction(irp, instruction->value);
1497 ir_print_other_inst_src(irp, instruction->value);
11781498}
11791499
1180static void ir_print_ref_gen(IrPrint *irp, IrInstructionRefGen *instruction) {
1500static void ir_print_ref_gen(IrPrintGen *irp, IrInstGenRef *instruction) {
11811501 fprintf(irp->f, "@ref(");
1182 ir_print_other_instruction(irp, instruction->operand);
1502 ir_print_other_inst_gen(irp, instruction->operand);
11831503 fprintf(irp->f, ")result=");
1184 ir_print_other_instruction(irp, instruction->result_loc);
1504 ir_print_other_inst_gen(irp, instruction->result_loc);
11851505}
11861506
1187static void ir_print_compile_err(IrPrint *irp, IrInstructionCompileErr *instruction) {
1507static void ir_print_compile_err(IrPrintSrc *irp, IrInstSrcCompileErr *instruction) {
11881508 fprintf(irp->f, "@compileError(");
1189 ir_print_other_instruction(irp, instruction->msg);
1509 ir_print_other_inst_src(irp, instruction->msg);
11901510 fprintf(irp->f, ")");
11911511}
11921512
1193static void ir_print_compile_log(IrPrint *irp, IrInstructionCompileLog *instruction) {
1513static void ir_print_compile_log(IrPrintSrc *irp, IrInstSrcCompileLog *instruction) {
11941514 fprintf(irp->f, "@compileLog(");
11951515 for (size_t i = 0; i < instruction->msg_count; i += 1) {
11961516 if (i != 0)
11971517 fprintf(irp->f, ",");
1198 IrInstruction *msg = instruction->msg_list[i];
1199 ir_print_other_instruction(irp, msg);
1518 IrInstSrc *msg = instruction->msg_list[i];
1519 ir_print_other_inst_src(irp, msg);
12001520 }
12011521 fprintf(irp->f, ")");
12021522}
12031523
1204static void ir_print_err_name(IrPrint *irp, IrInstructionErrName *instruction) {
1524static void ir_print_err_name(IrPrintSrc *irp, IrInstSrcErrName *instruction) {
12051525 fprintf(irp->f, "@errorName(");
1206 ir_print_other_instruction(irp, instruction->value);
1526 ir_print_other_inst_src(irp, instruction->value);
12071527 fprintf(irp->f, ")");
12081528}
12091529
1210static void ir_print_c_import(IrPrint *irp, IrInstructionCImport *instruction) {
1530static void ir_print_err_name(IrPrintGen *irp, IrInstGenErrName *instruction) {
1531 fprintf(irp->f, "@errorName(");
1532 ir_print_other_inst_gen(irp, instruction->value);
1533 fprintf(irp->f, ")");
1534}
1535
1536static void ir_print_c_import(IrPrintSrc *irp, IrInstSrcCImport *instruction) {
12111537 fprintf(irp->f, "@cImport(...)");
12121538}
12131539
1214static void ir_print_c_include(IrPrint *irp, IrInstructionCInclude *instruction) {
1540static void ir_print_c_include(IrPrintSrc *irp, IrInstSrcCInclude *instruction) {
12151541 fprintf(irp->f, "@cInclude(");
1216 ir_print_other_instruction(irp, instruction->name);
1542 ir_print_other_inst_src(irp, instruction->name);
12171543 fprintf(irp->f, ")");
12181544}
12191545
1220static void ir_print_c_define(IrPrint *irp, IrInstructionCDefine *instruction) {
1546static void ir_print_c_define(IrPrintSrc *irp, IrInstSrcCDefine *instruction) {
12211547 fprintf(irp->f, "@cDefine(");
1222 ir_print_other_instruction(irp, instruction->name);
1548 ir_print_other_inst_src(irp, instruction->name);
12231549 fprintf(irp->f, ", ");
1224 ir_print_other_instruction(irp, instruction->value);
1550 ir_print_other_inst_src(irp, instruction->value);
12251551 fprintf(irp->f, ")");
12261552}
12271553
1228static void ir_print_c_undef(IrPrint *irp, IrInstructionCUndef *instruction) {
1554static void ir_print_c_undef(IrPrintSrc *irp, IrInstSrcCUndef *instruction) {
12291555 fprintf(irp->f, "@cUndef(");
1230 ir_print_other_instruction(irp, instruction->name);
1556 ir_print_other_inst_src(irp, instruction->name);
12311557 fprintf(irp->f, ")");
12321558}
12331559
1234static void ir_print_embed_file(IrPrint *irp, IrInstructionEmbedFile *instruction) {
1560static void ir_print_embed_file(IrPrintSrc *irp, IrInstSrcEmbedFile *instruction) {
12351561 fprintf(irp->f, "@embedFile(");
1236 ir_print_other_instruction(irp, instruction->name);
1562 ir_print_other_inst_src(irp, instruction->name);
12371563 fprintf(irp->f, ")");
12381564}
12391565
1240static void ir_print_cmpxchg_src(IrPrint *irp, IrInstructionCmpxchgSrc *instruction) {
1566static void ir_print_cmpxchg_src(IrPrintSrc *irp, IrInstSrcCmpxchg *instruction) {
12411567 fprintf(irp->f, "@cmpxchg(");
1242 ir_print_other_instruction(irp, instruction->ptr);
1568 ir_print_other_inst_src(irp, instruction->ptr);
12431569 fprintf(irp->f, ", ");
1244 ir_print_other_instruction(irp, instruction->cmp_value);
1570 ir_print_other_inst_src(irp, instruction->cmp_value);
12451571 fprintf(irp->f, ", ");
1246 ir_print_other_instruction(irp, instruction->new_value);
1572 ir_print_other_inst_src(irp, instruction->new_value);
12471573 fprintf(irp->f, ", ");
1248 ir_print_other_instruction(irp, instruction->success_order_value);
1574 ir_print_other_inst_src(irp, instruction->success_order_value);
12491575 fprintf(irp->f, ", ");
1250 ir_print_other_instruction(irp, instruction->failure_order_value);
1576 ir_print_other_inst_src(irp, instruction->failure_order_value);
12511577 fprintf(irp->f, ")result=");
12521578 ir_print_result_loc(irp, instruction->result_loc);
12531579}
12541580
1255static void ir_print_cmpxchg_gen(IrPrint *irp, IrInstructionCmpxchgGen *instruction) {
1581static void ir_print_cmpxchg_gen(IrPrintGen *irp, IrInstGenCmpxchg *instruction) {
12561582 fprintf(irp->f, "@cmpxchg(");
1257 ir_print_other_instruction(irp, instruction->ptr);
1583 ir_print_other_inst_gen(irp, instruction->ptr);
12581584 fprintf(irp->f, ", ");
1259 ir_print_other_instruction(irp, instruction->cmp_value);
1585 ir_print_other_inst_gen(irp, instruction->cmp_value);
12601586 fprintf(irp->f, ", ");
1261 ir_print_other_instruction(irp, instruction->new_value);
1587 ir_print_other_inst_gen(irp, instruction->new_value);
12621588 fprintf(irp->f, ", TODO print atomic orders)result=");
1263 ir_print_other_instruction(irp, instruction->result_loc);
1589 ir_print_other_inst_gen(irp, instruction->result_loc);
12641590}
12651591
1266static void ir_print_fence(IrPrint *irp, IrInstructionFence *instruction) {
1592static void ir_print_fence(IrPrintSrc *irp, IrInstSrcFence *instruction) {
12671593 fprintf(irp->f, "@fence(");
1268 ir_print_other_instruction(irp, instruction->order_value);
1594 ir_print_other_inst_src(irp, instruction->order);
12691595 fprintf(irp->f, ")");
12701596}
12711597
1272static void ir_print_truncate(IrPrint *irp, IrInstructionTruncate *instruction) {
1598static const char *atomic_order_str(AtomicOrder order) {
1599 switch (order) {
1600 case AtomicOrderUnordered: return "Unordered";
1601 case AtomicOrderMonotonic: return "Monotonic";
1602 case AtomicOrderAcquire: return "Acquire";
1603 case AtomicOrderRelease: return "Release";
1604 case AtomicOrderAcqRel: return "AcqRel";
1605 case AtomicOrderSeqCst: return "SeqCst";
1606 }
1607 zig_unreachable();
1608}
1609
1610static void ir_print_fence(IrPrintGen *irp, IrInstGenFence *instruction) {
1611 fprintf(irp->f, "fence %s", atomic_order_str(instruction->order));
1612}
1613
1614static void ir_print_truncate(IrPrintSrc *irp, IrInstSrcTruncate *instruction) {
12731615 fprintf(irp->f, "@truncate(");
1274 ir_print_other_instruction(irp, instruction->dest_type);
1616 ir_print_other_inst_src(irp, instruction->dest_type);
12751617 fprintf(irp->f, ", ");
1276 ir_print_other_instruction(irp, instruction->target);
1618 ir_print_other_inst_src(irp, instruction->target);
12771619 fprintf(irp->f, ")");
12781620}
12791621
1280static void ir_print_int_cast(IrPrint *irp, IrInstructionIntCast *instruction) {
1622static void ir_print_truncate(IrPrintGen *irp, IrInstGenTruncate *instruction) {
1623 fprintf(irp->f, "@truncate(");
1624 ir_print_other_inst_gen(irp, instruction->target);
1625 fprintf(irp->f, ")");
1626}
1627
1628static void ir_print_int_cast(IrPrintSrc *irp, IrInstSrcIntCast *instruction) {
12811629 fprintf(irp->f, "@intCast(");
1282 ir_print_other_instruction(irp, instruction->dest_type);
1630 ir_print_other_inst_src(irp, instruction->dest_type);
12831631 fprintf(irp->f, ", ");
1284 ir_print_other_instruction(irp, instruction->target);
1632 ir_print_other_inst_src(irp, instruction->target);
12851633 fprintf(irp->f, ")");
12861634}
12871635
1288static void ir_print_float_cast(IrPrint *irp, IrInstructionFloatCast *instruction) {
1636static void ir_print_float_cast(IrPrintSrc *irp, IrInstSrcFloatCast *instruction) {
12891637 fprintf(irp->f, "@floatCast(");
1290 ir_print_other_instruction(irp, instruction->dest_type);
1638 ir_print_other_inst_src(irp, instruction->dest_type);
12911639 fprintf(irp->f, ", ");
1292 ir_print_other_instruction(irp, instruction->target);
1640 ir_print_other_inst_src(irp, instruction->target);
12931641 fprintf(irp->f, ")");
12941642}
12951643
1296static void ir_print_err_set_cast(IrPrint *irp, IrInstructionErrSetCast *instruction) {
1644static void ir_print_err_set_cast(IrPrintSrc *irp, IrInstSrcErrSetCast *instruction) {
12971645 fprintf(irp->f, "@errSetCast(");
1298 ir_print_other_instruction(irp, instruction->dest_type);
1646 ir_print_other_inst_src(irp, instruction->dest_type);
12991647 fprintf(irp->f, ", ");
1300 ir_print_other_instruction(irp, instruction->target);
1648 ir_print_other_inst_src(irp, instruction->target);
13011649 fprintf(irp->f, ")");
13021650}
13031651
1304static void ir_print_from_bytes(IrPrint *irp, IrInstructionFromBytes *instruction) {
1652static void ir_print_from_bytes(IrPrintSrc *irp, IrInstSrcFromBytes *instruction) {
13051653 fprintf(irp->f, "@bytesToSlice(");
1306 ir_print_other_instruction(irp, instruction->dest_child_type);
1654 ir_print_other_inst_src(irp, instruction->dest_child_type);
13071655 fprintf(irp->f, ", ");
1308 ir_print_other_instruction(irp, instruction->target);
1656 ir_print_other_inst_src(irp, instruction->target);
13091657 fprintf(irp->f, ")");
13101658}
13111659
1312static void ir_print_to_bytes(IrPrint *irp, IrInstructionToBytes *instruction) {
1660static void ir_print_to_bytes(IrPrintSrc *irp, IrInstSrcToBytes *instruction) {
13131661 fprintf(irp->f, "@sliceToBytes(");
1314 ir_print_other_instruction(irp, instruction->target);
1662 ir_print_other_inst_src(irp, instruction->target);
13151663 fprintf(irp->f, ")");
13161664}
13171665
1318static void ir_print_int_to_float(IrPrint *irp, IrInstructionIntToFloat *instruction) {
1666static void ir_print_int_to_float(IrPrintSrc *irp, IrInstSrcIntToFloat *instruction) {
13191667 fprintf(irp->f, "@intToFloat(");
1320 ir_print_other_instruction(irp, instruction->dest_type);
1668 ir_print_other_inst_src(irp, instruction->dest_type);
13211669 fprintf(irp->f, ", ");
1322 ir_print_other_instruction(irp, instruction->target);
1670 ir_print_other_inst_src(irp, instruction->target);
13231671 fprintf(irp->f, ")");
13241672}
13251673
1326static void ir_print_float_to_int(IrPrint *irp, IrInstructionFloatToInt *instruction) {
1674static void ir_print_float_to_int(IrPrintSrc *irp, IrInstSrcFloatToInt *instruction) {
13271675 fprintf(irp->f, "@floatToInt(");
1328 ir_print_other_instruction(irp, instruction->dest_type);
1676 ir_print_other_inst_src(irp, instruction->dest_type);
13291677 fprintf(irp->f, ", ");
1330 ir_print_other_instruction(irp, instruction->target);
1678 ir_print_other_inst_src(irp, instruction->target);
13311679 fprintf(irp->f, ")");
13321680}
13331681
1334static void ir_print_bool_to_int(IrPrint *irp, IrInstructionBoolToInt *instruction) {
1682static void ir_print_bool_to_int(IrPrintSrc *irp, IrInstSrcBoolToInt *instruction) {
13351683 fprintf(irp->f, "@boolToInt(");
1336 ir_print_other_instruction(irp, instruction->target);
1684 ir_print_other_inst_src(irp, instruction->target);
13371685 fprintf(irp->f, ")");
13381686}
13391687
1340static void ir_print_int_type(IrPrint *irp, IrInstructionIntType *instruction) {
1688static void ir_print_int_type(IrPrintSrc *irp, IrInstSrcIntType *instruction) {
13411689 fprintf(irp->f, "@IntType(");
1342 ir_print_other_instruction(irp, instruction->is_signed);
1690 ir_print_other_inst_src(irp, instruction->is_signed);
13431691 fprintf(irp->f, ", ");
1344 ir_print_other_instruction(irp, instruction->bit_count);
1692 ir_print_other_inst_src(irp, instruction->bit_count);
13451693 fprintf(irp->f, ")");
13461694}
13471695
1348static void ir_print_vector_type(IrPrint *irp, IrInstructionVectorType *instruction) {
1696static void ir_print_vector_type(IrPrintSrc *irp, IrInstSrcVectorType *instruction) {
13491697 fprintf(irp->f, "@Vector(");
1350 ir_print_other_instruction(irp, instruction->len);
1698 ir_print_other_inst_src(irp, instruction->len);
13511699 fprintf(irp->f, ", ");
1352 ir_print_other_instruction(irp, instruction->elem_type);
1700 ir_print_other_inst_src(irp, instruction->elem_type);
13531701 fprintf(irp->f, ")");
13541702}
13551703
1356static void ir_print_shuffle_vector(IrPrint *irp, IrInstructionShuffleVector *instruction) {
1704static void ir_print_shuffle_vector(IrPrintSrc *irp, IrInstSrcShuffleVector *instruction) {
13571705 fprintf(irp->f, "@shuffle(");
1358 ir_print_other_instruction(irp, instruction->scalar_type);
1706 ir_print_other_inst_src(irp, instruction->scalar_type);
13591707 fprintf(irp->f, ", ");
1360 ir_print_other_instruction(irp, instruction->a);
1708 ir_print_other_inst_src(irp, instruction->a);
13611709 fprintf(irp->f, ", ");
1362 ir_print_other_instruction(irp, instruction->b);
1710 ir_print_other_inst_src(irp, instruction->b);
13631711 fprintf(irp->f, ", ");
1364 ir_print_other_instruction(irp, instruction->mask);
1712 ir_print_other_inst_src(irp, instruction->mask);
13651713 fprintf(irp->f, ")");
13661714}
13671715
1368static void ir_print_splat_src(IrPrint *irp, IrInstructionSplatSrc *instruction) {
1716static void ir_print_shuffle_vector(IrPrintGen *irp, IrInstGenShuffleVector *instruction) {
1717 fprintf(irp->f, "@shuffle(");
1718 ir_print_other_inst_gen(irp, instruction->a);
1719 fprintf(irp->f, ", ");
1720 ir_print_other_inst_gen(irp, instruction->b);
1721 fprintf(irp->f, ", ");
1722 ir_print_other_inst_gen(irp, instruction->mask);
1723 fprintf(irp->f, ")");
1724}
1725
1726static void ir_print_splat_src(IrPrintSrc *irp, IrInstSrcSplat *instruction) {
13691727 fprintf(irp->f, "@splat(");
1370 ir_print_other_instruction(irp, instruction->len);
1728 ir_print_other_inst_src(irp, instruction->len);
13711729 fprintf(irp->f, ", ");
1372 ir_print_other_instruction(irp, instruction->scalar);
1730 ir_print_other_inst_src(irp, instruction->scalar);
13731731 fprintf(irp->f, ")");
13741732}
13751733
1376static void ir_print_splat_gen(IrPrint *irp, IrInstructionSplatGen *instruction) {
1734static void ir_print_splat_gen(IrPrintGen *irp, IrInstGenSplat *instruction) {
13771735 fprintf(irp->f, "@splat(");
1378 ir_print_other_instruction(irp, instruction->scalar);
1736 ir_print_other_inst_gen(irp, instruction->scalar);
13791737 fprintf(irp->f, ")");
13801738}
13811739
1382static void ir_print_bool_not(IrPrint *irp, IrInstructionBoolNot *instruction) {
1740static void ir_print_bool_not(IrPrintSrc *irp, IrInstSrcBoolNot *instruction) {
1741 fprintf(irp->f, "! ");
1742 ir_print_other_inst_src(irp, instruction->value);
1743}
1744
1745static void ir_print_bool_not(IrPrintGen *irp, IrInstGenBoolNot *instruction) {
13831746 fprintf(irp->f, "! ");
1384 ir_print_other_instruction(irp, instruction->value);
1747 ir_print_other_inst_gen(irp, instruction->value);
13851748}
13861749
1387static void ir_print_memset(IrPrint *irp, IrInstructionMemset *instruction) {
1750static void ir_print_memset(IrPrintSrc *irp, IrInstSrcMemset *instruction) {
13881751 fprintf(irp->f, "@memset(");
1389 ir_print_other_instruction(irp, instruction->dest_ptr);
1752 ir_print_other_inst_src(irp, instruction->dest_ptr);
1753 fprintf(irp->f, ", ");
1754 ir_print_other_inst_src(irp, instruction->byte);
1755 fprintf(irp->f, ", ");
1756 ir_print_other_inst_src(irp, instruction->count);
1757 fprintf(irp->f, ")");
1758}
1759
1760static void ir_print_memset(IrPrintGen *irp, IrInstGenMemset *instruction) {
1761 fprintf(irp->f, "@memset(");
1762 ir_print_other_inst_gen(irp, instruction->dest_ptr);
1763 fprintf(irp->f, ", ");
1764 ir_print_other_inst_gen(irp, instruction->byte);
1765 fprintf(irp->f, ", ");
1766 ir_print_other_inst_gen(irp, instruction->count);
1767 fprintf(irp->f, ")");
1768}
1769
1770static void ir_print_memcpy(IrPrintSrc *irp, IrInstSrcMemcpy *instruction) {
1771 fprintf(irp->f, "@memcpy(");
1772 ir_print_other_inst_src(irp, instruction->dest_ptr);
13901773 fprintf(irp->f, ", ");
1391 ir_print_other_instruction(irp, instruction->byte);
1774 ir_print_other_inst_src(irp, instruction->src_ptr);
13921775 fprintf(irp->f, ", ");
1393 ir_print_other_instruction(irp, instruction->count);
1776 ir_print_other_inst_src(irp, instruction->count);
13941777 fprintf(irp->f, ")");
13951778}
13961779
1397static void ir_print_memcpy(IrPrint *irp, IrInstructionMemcpy *instruction) {
1780static void ir_print_memcpy(IrPrintGen *irp, IrInstGenMemcpy *instruction) {
13981781 fprintf(irp->f, "@memcpy(");
1399 ir_print_other_instruction(irp, instruction->dest_ptr);
1782 ir_print_other_inst_gen(irp, instruction->dest_ptr);
14001783 fprintf(irp->f, ", ");
1401 ir_print_other_instruction(irp, instruction->src_ptr);
1784 ir_print_other_inst_gen(irp, instruction->src_ptr);
14021785 fprintf(irp->f, ", ");
1403 ir_print_other_instruction(irp, instruction->count);
1786 ir_print_other_inst_gen(irp, instruction->count);
14041787 fprintf(irp->f, ")");
14051788}
14061789
1407static void ir_print_slice_src(IrPrint *irp, IrInstructionSliceSrc *instruction) {
1408 ir_print_other_instruction(irp, instruction->ptr);
1790static void ir_print_slice_src(IrPrintSrc *irp, IrInstSrcSlice *instruction) {
1791 ir_print_other_inst_src(irp, instruction->ptr);
14091792 fprintf(irp->f, "[");
1410 ir_print_other_instruction(irp, instruction->start);
1793 ir_print_other_inst_src(irp, instruction->start);
14111794 fprintf(irp->f, "..");
14121795 if (instruction->end)
1413 ir_print_other_instruction(irp, instruction->end);
1796 ir_print_other_inst_src(irp, instruction->end);
14141797 fprintf(irp->f, "]result=");
14151798 ir_print_result_loc(irp, instruction->result_loc);
14161799}
14171800
1418static void ir_print_slice_gen(IrPrint *irp, IrInstructionSliceGen *instruction) {
1419 ir_print_other_instruction(irp, instruction->ptr);
1801static void ir_print_slice_gen(IrPrintGen *irp, IrInstGenSlice *instruction) {
1802 ir_print_other_inst_gen(irp, instruction->ptr);
14201803 fprintf(irp->f, "[");
1421 ir_print_other_instruction(irp, instruction->start);
1804 ir_print_other_inst_gen(irp, instruction->start);
14221805 fprintf(irp->f, "..");
14231806 if (instruction->end)
1424 ir_print_other_instruction(irp, instruction->end);
1807 ir_print_other_inst_gen(irp, instruction->end);
14251808 fprintf(irp->f, "]result=");
1426 ir_print_other_instruction(irp, instruction->result_loc);
1809 ir_print_other_inst_gen(irp, instruction->result_loc);
14271810}
14281811
1429static void ir_print_member_count(IrPrint *irp, IrInstructionMemberCount *instruction) {
1812static void ir_print_member_count(IrPrintSrc *irp, IrInstSrcMemberCount *instruction) {
14301813 fprintf(irp->f, "@memberCount(");
1431 ir_print_other_instruction(irp, instruction->container);
1814 ir_print_other_inst_src(irp, instruction->container);
14321815 fprintf(irp->f, ")");
14331816}
14341817
1435static void ir_print_member_type(IrPrint *irp, IrInstructionMemberType *instruction) {
1818static void ir_print_member_type(IrPrintSrc *irp, IrInstSrcMemberType *instruction) {
14361819 fprintf(irp->f, "@memberType(");
1437 ir_print_other_instruction(irp, instruction->container_type);
1820 ir_print_other_inst_src(irp, instruction->container_type);
14381821 fprintf(irp->f, ", ");
1439 ir_print_other_instruction(irp, instruction->member_index);
1822 ir_print_other_inst_src(irp, instruction->member_index);
14401823 fprintf(irp->f, ")");
14411824}
14421825
1443static void ir_print_member_name(IrPrint *irp, IrInstructionMemberName *instruction) {
1826static void ir_print_member_name(IrPrintSrc *irp, IrInstSrcMemberName *instruction) {
14441827 fprintf(irp->f, "@memberName(");
1445 ir_print_other_instruction(irp, instruction->container_type);
1828 ir_print_other_inst_src(irp, instruction->container_type);
14461829 fprintf(irp->f, ", ");
1447 ir_print_other_instruction(irp, instruction->member_index);
1830 ir_print_other_inst_src(irp, instruction->member_index);
14481831 fprintf(irp->f, ")");
14491832}
14501833
1451static void ir_print_breakpoint(IrPrint *irp, IrInstructionBreakpoint *instruction) {
1834static void ir_print_breakpoint(IrPrintSrc *irp, IrInstSrcBreakpoint *instruction) {
1835 fprintf(irp->f, "@breakpoint()");
1836}
1837
1838static void ir_print_breakpoint(IrPrintGen *irp, IrInstGenBreakpoint *instruction) {
14521839 fprintf(irp->f, "@breakpoint()");
14531840}
14541841
1455static void ir_print_frame_address(IrPrint *irp, IrInstructionFrameAddress *instruction) {
1842static void ir_print_frame_address(IrPrintSrc *irp, IrInstSrcFrameAddress *instruction) {
1843 fprintf(irp->f, "@frameAddress()");
1844}
1845
1846static void ir_print_frame_address(IrPrintGen *irp, IrInstGenFrameAddress *instruction) {
14561847 fprintf(irp->f, "@frameAddress()");
14571848}
14581849
1459static void ir_print_handle(IrPrint *irp, IrInstructionFrameHandle *instruction) {
1850static void ir_print_handle(IrPrintSrc *irp, IrInstSrcFrameHandle *instruction) {
14601851 fprintf(irp->f, "@frame()");
14611852}
14621853
1463static void ir_print_frame_type(IrPrint *irp, IrInstructionFrameType *instruction) {
1854static void ir_print_handle(IrPrintGen *irp, IrInstGenFrameHandle *instruction) {
1855 fprintf(irp->f, "@frame()");
1856}
1857
1858static void ir_print_frame_type(IrPrintSrc *irp, IrInstSrcFrameType *instruction) {
14641859 fprintf(irp->f, "@Frame(");
1465 ir_print_other_instruction(irp, instruction->fn);
1860 ir_print_other_inst_src(irp, instruction->fn);
14661861 fprintf(irp->f, ")");
14671862}
14681863
1469static void ir_print_frame_size_src(IrPrint *irp, IrInstructionFrameSizeSrc *instruction) {
1864static void ir_print_frame_size_src(IrPrintSrc *irp, IrInstSrcFrameSize *instruction) {
14701865 fprintf(irp->f, "@frameSize(");
1471 ir_print_other_instruction(irp, instruction->fn);
1866 ir_print_other_inst_src(irp, instruction->fn);
14721867 fprintf(irp->f, ")");
14731868}
14741869
1475static void ir_print_frame_size_gen(IrPrint *irp, IrInstructionFrameSizeGen *instruction) {
1870static void ir_print_frame_size_gen(IrPrintGen *irp, IrInstGenFrameSize *instruction) {
14761871 fprintf(irp->f, "@frameSize(");
1477 ir_print_other_instruction(irp, instruction->fn);
1872 ir_print_other_inst_gen(irp, instruction->fn);
14781873 fprintf(irp->f, ")");
14791874}
14801875
1481static void ir_print_return_address(IrPrint *irp, IrInstructionReturnAddress *instruction) {
1876static void ir_print_return_address(IrPrintSrc *irp, IrInstSrcReturnAddress *instruction) {
1877 fprintf(irp->f, "@returnAddress()");
1878}
1879
1880static void ir_print_return_address(IrPrintGen *irp, IrInstGenReturnAddress *instruction) {
14821881 fprintf(irp->f, "@returnAddress()");
14831882}
14841883
1485static void ir_print_align_of(IrPrint *irp, IrInstructionAlignOf *instruction) {
1884static void ir_print_align_of(IrPrintSrc *irp, IrInstSrcAlignOf *instruction) {
14861885 fprintf(irp->f, "@alignOf(");
1487 ir_print_other_instruction(irp, instruction->type_value);
1886 ir_print_other_inst_src(irp, instruction->type_value);
14881887 fprintf(irp->f, ")");
14891888}
14901889
1491static void ir_print_overflow_op(IrPrint *irp, IrInstructionOverflowOp *instruction) {
1890static void ir_print_overflow_op(IrPrintSrc *irp, IrInstSrcOverflowOp *instruction) {
14921891 switch (instruction->op) {
14931892 case IrOverflowOpAdd:
14941893 fprintf(irp->f, "@addWithOverflow(");
......@@ -1503,1146 +1902,1457 @@ static void ir_print_overflow_op(IrPrint *irp, IrInstructionOverflowOp *instruct
15031902 fprintf(irp->f, "@shlWithOverflow(");
15041903 break;
15051904 }
1506 ir_print_other_instruction(irp, instruction->type_value);
1905 ir_print_other_inst_src(irp, instruction->type_value);
15071906 fprintf(irp->f, ", ");
1508 ir_print_other_instruction(irp, instruction->op1);
1907 ir_print_other_inst_src(irp, instruction->op1);
1908 fprintf(irp->f, ", ");
1909 ir_print_other_inst_src(irp, instruction->op2);
1910 fprintf(irp->f, ", ");
1911 ir_print_other_inst_src(irp, instruction->result_ptr);
1912 fprintf(irp->f, ")");
1913}
1914
1915static void ir_print_overflow_op(IrPrintGen *irp, IrInstGenOverflowOp *instruction) {
1916 switch (instruction->op) {
1917 case IrOverflowOpAdd:
1918 fprintf(irp->f, "@addWithOverflow(");
1919 break;
1920 case IrOverflowOpSub:
1921 fprintf(irp->f, "@subWithOverflow(");
1922 break;
1923 case IrOverflowOpMul:
1924 fprintf(irp->f, "@mulWithOverflow(");
1925 break;
1926 case IrOverflowOpShl:
1927 fprintf(irp->f, "@shlWithOverflow(");
1928 break;
1929 }
1930 ir_print_other_inst_gen(irp, instruction->op1);
15091931 fprintf(irp->f, ", ");
1510 ir_print_other_instruction(irp, instruction->op2);
1932 ir_print_other_inst_gen(irp, instruction->op2);
15111933 fprintf(irp->f, ", ");
1512 ir_print_other_instruction(irp, instruction->result_ptr);
1934 ir_print_other_inst_gen(irp, instruction->result_ptr);
15131935 fprintf(irp->f, ")");
15141936}
15151937
1516static void ir_print_test_err_src(IrPrint *irp, IrInstructionTestErrSrc *instruction) {
1938static void ir_print_test_err_src(IrPrintSrc *irp, IrInstSrcTestErr *instruction) {
15171939 fprintf(irp->f, "@testError(");
1518 ir_print_other_instruction(irp, instruction->base_ptr);
1940 ir_print_other_inst_src(irp, instruction->base_ptr);
15191941 fprintf(irp->f, ")");
15201942}
15211943
1522static void ir_print_test_err_gen(IrPrint *irp, IrInstructionTestErrGen *instruction) {
1944static void ir_print_test_err_gen(IrPrintGen *irp, IrInstGenTestErr *instruction) {
15231945 fprintf(irp->f, "@testError(");
1524 ir_print_other_instruction(irp, instruction->err_union);
1946 ir_print_other_inst_gen(irp, instruction->err_union);
1947 fprintf(irp->f, ")");
1948}
1949
1950static void ir_print_unwrap_err_code(IrPrintSrc *irp, IrInstSrcUnwrapErrCode *instruction) {
1951 fprintf(irp->f, "UnwrapErrorCode(");
1952 ir_print_other_inst_src(irp, instruction->err_union_ptr);
15251953 fprintf(irp->f, ")");
15261954}
15271955
1528static void ir_print_unwrap_err_code(IrPrint *irp, IrInstructionUnwrapErrCode *instruction) {
1956static void ir_print_unwrap_err_code(IrPrintGen *irp, IrInstGenUnwrapErrCode *instruction) {
15291957 fprintf(irp->f, "UnwrapErrorCode(");
1530 ir_print_other_instruction(irp, instruction->err_union_ptr);
1958 ir_print_other_inst_gen(irp, instruction->err_union_ptr);
15311959 fprintf(irp->f, ")");
15321960}
15331961
1534static void ir_print_unwrap_err_payload(IrPrint *irp, IrInstructionUnwrapErrPayload *instruction) {
1962static void ir_print_unwrap_err_payload(IrPrintSrc *irp, IrInstSrcUnwrapErrPayload *instruction) {
1963 fprintf(irp->f, "ErrorUnionFieldPayload(");
1964 ir_print_other_inst_src(irp, instruction->value);
1965 fprintf(irp->f, ")safety=%d,init=%d",instruction->safety_check_on, instruction->initializing);
1966}
1967
1968static void ir_print_unwrap_err_payload(IrPrintGen *irp, IrInstGenUnwrapErrPayload *instruction) {
15351969 fprintf(irp->f, "ErrorUnionFieldPayload(");
1536 ir_print_other_instruction(irp, instruction->value);
1970 ir_print_other_inst_gen(irp, instruction->value);
15371971 fprintf(irp->f, ")safety=%d,init=%d",instruction->safety_check_on, instruction->initializing);
15381972}
15391973
1540static void ir_print_optional_wrap(IrPrint *irp, IrInstructionOptionalWrap *instruction) {
1974static void ir_print_optional_wrap(IrPrintGen *irp, IrInstGenOptionalWrap *instruction) {
15411975 fprintf(irp->f, "@optionalWrap(");
1542 ir_print_other_instruction(irp, instruction->operand);
1976 ir_print_other_inst_gen(irp, instruction->operand);
15431977 fprintf(irp->f, ")result=");
1544 ir_print_other_instruction(irp, instruction->result_loc);
1978 ir_print_other_inst_gen(irp, instruction->result_loc);
15451979}
15461980
1547static void ir_print_err_wrap_code(IrPrint *irp, IrInstructionErrWrapCode *instruction) {
1981static void ir_print_err_wrap_code(IrPrintGen *irp, IrInstGenErrWrapCode *instruction) {
15481982 fprintf(irp->f, "@errWrapCode(");
1549 ir_print_other_instruction(irp, instruction->operand);
1983 ir_print_other_inst_gen(irp, instruction->operand);
15501984 fprintf(irp->f, ")result=");
1551 ir_print_other_instruction(irp, instruction->result_loc);
1985 ir_print_other_inst_gen(irp, instruction->result_loc);
15521986}
15531987
1554static void ir_print_err_wrap_payload(IrPrint *irp, IrInstructionErrWrapPayload *instruction) {
1988static void ir_print_err_wrap_payload(IrPrintGen *irp, IrInstGenErrWrapPayload *instruction) {
15551989 fprintf(irp->f, "@errWrapPayload(");
1556 ir_print_other_instruction(irp, instruction->operand);
1990 ir_print_other_inst_gen(irp, instruction->operand);
15571991 fprintf(irp->f, ")result=");
1558 ir_print_other_instruction(irp, instruction->result_loc);
1992 ir_print_other_inst_gen(irp, instruction->result_loc);
15591993}
15601994
1561static void ir_print_fn_proto(IrPrint *irp, IrInstructionFnProto *instruction) {
1995static void ir_print_fn_proto(IrPrintSrc *irp, IrInstSrcFnProto *instruction) {
15621996 fprintf(irp->f, "fn(");
1563 for (size_t i = 0; i < instruction->base.source_node->data.fn_proto.params.length; i += 1) {
1997 for (size_t i = 0; i < instruction->base.base.source_node->data.fn_proto.params.length; i += 1) {
15641998 if (i != 0)
15651999 fprintf(irp->f, ",");
1566 if (instruction->is_var_args && i == instruction->base.source_node->data.fn_proto.params.length - 1) {
2000 if (instruction->is_var_args && i == instruction->base.base.source_node->data.fn_proto.params.length - 1) {
15672001 fprintf(irp->f, "...");
15682002 } else {
1569 ir_print_other_instruction(irp, instruction->param_types[i]);
2003 ir_print_other_inst_src(irp, instruction->param_types[i]);
15702004 }
15712005 }
15722006 fprintf(irp->f, ")");
15732007 if (instruction->align_value != nullptr) {
15742008 fprintf(irp->f, " align ");
1575 ir_print_other_instruction(irp, instruction->align_value);
2009 ir_print_other_inst_src(irp, instruction->align_value);
15762010 fprintf(irp->f, " ");
15772011 }
15782012 fprintf(irp->f, "->");
1579 ir_print_other_instruction(irp, instruction->return_type);
2013 ir_print_other_inst_src(irp, instruction->return_type);
15802014}
15812015
1582static void ir_print_test_comptime(IrPrint *irp, IrInstructionTestComptime *instruction) {
2016static void ir_print_test_comptime(IrPrintSrc *irp, IrInstSrcTestComptime *instruction) {
15832017 fprintf(irp->f, "@testComptime(");
1584 ir_print_other_instruction(irp, instruction->value);
2018 ir_print_other_inst_src(irp, instruction->value);
15852019 fprintf(irp->f, ")");
15862020}
15872021
1588static void ir_print_ptr_cast_src(IrPrint *irp, IrInstructionPtrCastSrc *instruction) {
2022static void ir_print_ptr_cast_src(IrPrintSrc *irp, IrInstSrcPtrCast *instruction) {
15892023 fprintf(irp->f, "@ptrCast(");
15902024 if (instruction->dest_type) {
1591 ir_print_other_instruction(irp, instruction->dest_type);
2025 ir_print_other_inst_src(irp, instruction->dest_type);
15922026 }
15932027 fprintf(irp->f, ",");
1594 ir_print_other_instruction(irp, instruction->ptr);
2028 ir_print_other_inst_src(irp, instruction->ptr);
15952029 fprintf(irp->f, ")");
15962030}
15972031
1598static void ir_print_ptr_cast_gen(IrPrint *irp, IrInstructionPtrCastGen *instruction) {
2032static void ir_print_ptr_cast_gen(IrPrintGen *irp, IrInstGenPtrCast *instruction) {
15992033 fprintf(irp->f, "@ptrCast(");
1600 ir_print_other_instruction(irp, instruction->ptr);
2034 ir_print_other_inst_gen(irp, instruction->ptr);
16012035 fprintf(irp->f, ")");
16022036}
16032037
1604static void ir_print_implicit_cast(IrPrint *irp, IrInstructionImplicitCast *instruction) {
2038static void ir_print_implicit_cast(IrPrintSrc *irp, IrInstSrcImplicitCast *instruction) {
16052039 fprintf(irp->f, "@implicitCast(");
1606 ir_print_other_instruction(irp, instruction->operand);
2040 ir_print_other_inst_src(irp, instruction->operand);
16072041 fprintf(irp->f, ")result=");
16082042 ir_print_result_loc(irp, &instruction->result_loc_cast->base);
16092043}
16102044
1611static void ir_print_bit_cast_src(IrPrint *irp, IrInstructionBitCastSrc *instruction) {
2045static void ir_print_bit_cast_src(IrPrintSrc *irp, IrInstSrcBitCast *instruction) {
16122046 fprintf(irp->f, "@bitCast(");
1613 ir_print_other_instruction(irp, instruction->operand);
2047 ir_print_other_inst_src(irp, instruction->operand);
16142048 fprintf(irp->f, ")result=");
16152049 ir_print_result_loc(irp, &instruction->result_loc_bit_cast->base);
16162050}
16172051
1618static void ir_print_bit_cast_gen(IrPrint *irp, IrInstructionBitCastGen *instruction) {
2052static void ir_print_bit_cast_gen(IrPrintGen *irp, IrInstGenBitCast *instruction) {
16192053 fprintf(irp->f, "@bitCast(");
1620 ir_print_other_instruction(irp, instruction->operand);
2054 ir_print_other_inst_gen(irp, instruction->operand);
16212055 fprintf(irp->f, ")");
16222056}
16232057
1624static void ir_print_widen_or_shorten(IrPrint *irp, IrInstructionWidenOrShorten *instruction) {
2058static void ir_print_widen_or_shorten(IrPrintGen *irp, IrInstGenWidenOrShorten *instruction) {
16252059 fprintf(irp->f, "WidenOrShorten(");
1626 ir_print_other_instruction(irp, instruction->target);
2060 ir_print_other_inst_gen(irp, instruction->target);
16272061 fprintf(irp->f, ")");
16282062}
16292063
1630static void ir_print_ptr_to_int(IrPrint *irp, IrInstructionPtrToInt *instruction) {
2064static void ir_print_ptr_to_int(IrPrintSrc *irp, IrInstSrcPtrToInt *instruction) {
16312065 fprintf(irp->f, "@ptrToInt(");
1632 ir_print_other_instruction(irp, instruction->target);
2066 ir_print_other_inst_src(irp, instruction->target);
16332067 fprintf(irp->f, ")");
16342068}
16352069
1636static void ir_print_int_to_ptr(IrPrint *irp, IrInstructionIntToPtr *instruction) {
2070static void ir_print_ptr_to_int(IrPrintGen *irp, IrInstGenPtrToInt *instruction) {
2071 fprintf(irp->f, "@ptrToInt(");
2072 ir_print_other_inst_gen(irp, instruction->target);
2073 fprintf(irp->f, ")");
2074}
2075
2076static void ir_print_int_to_ptr(IrPrintSrc *irp, IrInstSrcIntToPtr *instruction) {
16372077 fprintf(irp->f, "@intToPtr(");
1638 if (instruction->dest_type == nullptr) {
1639 fprintf(irp->f, "(null)");
1640 } else {
1641 ir_print_other_instruction(irp, instruction->dest_type);
1642 }
2078 ir_print_other_inst_src(irp, instruction->dest_type);
16432079 fprintf(irp->f, ",");
1644 ir_print_other_instruction(irp, instruction->target);
2080 ir_print_other_inst_src(irp, instruction->target);
16452081 fprintf(irp->f, ")");
16462082}
16472083
1648static void ir_print_int_to_enum(IrPrint *irp, IrInstructionIntToEnum *instruction) {
2084static void ir_print_int_to_ptr(IrPrintGen *irp, IrInstGenIntToPtr *instruction) {
2085 fprintf(irp->f, "@intToPtr(");
2086 ir_print_other_inst_gen(irp, instruction->target);
2087 fprintf(irp->f, ")");
2088}
2089
2090static void ir_print_int_to_enum(IrPrintSrc *irp, IrInstSrcIntToEnum *instruction) {
16492091 fprintf(irp->f, "@intToEnum(");
1650 if (instruction->dest_type == nullptr) {
1651 fprintf(irp->f, "(null)");
1652 } else {
1653 ir_print_other_instruction(irp, instruction->dest_type);
1654 }
1655 ir_print_other_instruction(irp, instruction->target);
2092 ir_print_other_inst_src(irp, instruction->dest_type);
2093 fprintf(irp->f, ",");
2094 ir_print_other_inst_src(irp, instruction->target);
16562095 fprintf(irp->f, ")");
16572096}
16582097
1659static void ir_print_enum_to_int(IrPrint *irp, IrInstructionEnumToInt *instruction) {
2098static void ir_print_int_to_enum(IrPrintGen *irp, IrInstGenIntToEnum *instruction) {
2099 fprintf(irp->f, "@intToEnum(");
2100 ir_print_other_inst_gen(irp, instruction->target);
2101 fprintf(irp->f, ")");
2102}
2103
2104static void ir_print_enum_to_int(IrPrintSrc *irp, IrInstSrcEnumToInt *instruction) {
16602105 fprintf(irp->f, "@enumToInt(");
1661 ir_print_other_instruction(irp, instruction->target);
2106 ir_print_other_inst_src(irp, instruction->target);
16622107 fprintf(irp->f, ")");
16632108}
16642109
1665static void ir_print_check_runtime_scope(IrPrint *irp, IrInstructionCheckRuntimeScope *instruction) {
2110static void ir_print_check_runtime_scope(IrPrintSrc *irp, IrInstSrcCheckRuntimeScope *instruction) {
16662111 fprintf(irp->f, "@checkRuntimeScope(");
1667 ir_print_other_instruction(irp, instruction->scope_is_comptime);
2112 ir_print_other_inst_src(irp, instruction->scope_is_comptime);
16682113 fprintf(irp->f, ",");
1669 ir_print_other_instruction(irp, instruction->is_comptime);
2114 ir_print_other_inst_src(irp, instruction->is_comptime);
16702115 fprintf(irp->f, ")");
16712116}
16722117
1673static void ir_print_array_to_vector(IrPrint *irp, IrInstructionArrayToVector *instruction) {
2118static void ir_print_array_to_vector(IrPrintGen *irp, IrInstGenArrayToVector *instruction) {
16742119 fprintf(irp->f, "ArrayToVector(");
1675 ir_print_other_instruction(irp, instruction->array);
2120 ir_print_other_inst_gen(irp, instruction->array);
16762121 fprintf(irp->f, ")");
16772122}
16782123
1679static void ir_print_vector_to_array(IrPrint *irp, IrInstructionVectorToArray *instruction) {
2124static void ir_print_vector_to_array(IrPrintGen *irp, IrInstGenVectorToArray *instruction) {
16802125 fprintf(irp->f, "VectorToArray(");
1681 ir_print_other_instruction(irp, instruction->vector);
2126 ir_print_other_inst_gen(irp, instruction->vector);
16822127 fprintf(irp->f, ")result=");
1683 ir_print_other_instruction(irp, instruction->result_loc);
2128 ir_print_other_inst_gen(irp, instruction->result_loc);
16842129}
16852130
1686static void ir_print_ptr_of_array_to_slice(IrPrint *irp, IrInstructionPtrOfArrayToSlice *instruction) {
2131static void ir_print_ptr_of_array_to_slice(IrPrintGen *irp, IrInstGenPtrOfArrayToSlice *instruction) {
16872132 fprintf(irp->f, "PtrOfArrayToSlice(");
1688 ir_print_other_instruction(irp, instruction->operand);
2133 ir_print_other_inst_gen(irp, instruction->operand);
16892134 fprintf(irp->f, ")result=");
1690 ir_print_other_instruction(irp, instruction->result_loc);
2135 ir_print_other_inst_gen(irp, instruction->result_loc);
16912136}
16922137
1693static void ir_print_assert_zero(IrPrint *irp, IrInstructionAssertZero *instruction) {
2138static void ir_print_assert_zero(IrPrintGen *irp, IrInstGenAssertZero *instruction) {
16942139 fprintf(irp->f, "AssertZero(");
1695 ir_print_other_instruction(irp, instruction->target);
2140 ir_print_other_inst_gen(irp, instruction->target);
16962141 fprintf(irp->f, ")");
16972142}
16982143
1699static void ir_print_assert_non_null(IrPrint *irp, IrInstructionAssertNonNull *instruction) {
2144static void ir_print_assert_non_null(IrPrintGen *irp, IrInstGenAssertNonNull *instruction) {
17002145 fprintf(irp->f, "AssertNonNull(");
1701 ir_print_other_instruction(irp, instruction->target);
2146 ir_print_other_inst_gen(irp, instruction->target);
17022147 fprintf(irp->f, ")");
17032148}
17042149
1705static void ir_print_resize_slice(IrPrint *irp, IrInstructionResizeSlice *instruction) {
2150static void ir_print_resize_slice(IrPrintGen *irp, IrInstGenResizeSlice *instruction) {
17062151 fprintf(irp->f, "@resizeSlice(");
1707 ir_print_other_instruction(irp, instruction->operand);
2152 ir_print_other_inst_gen(irp, instruction->operand);
17082153 fprintf(irp->f, ")result=");
1709 ir_print_other_instruction(irp, instruction->result_loc);
2154 ir_print_other_inst_gen(irp, instruction->result_loc);
17102155}
17112156
1712static void ir_print_alloca_src(IrPrint *irp, IrInstructionAllocaSrc *instruction) {
2157static void ir_print_alloca_src(IrPrintSrc *irp, IrInstSrcAlloca *instruction) {
17132158 fprintf(irp->f, "Alloca(align=");
1714 ir_print_other_instruction(irp, instruction->align);
2159 ir_print_other_inst_src(irp, instruction->align);
17152160 fprintf(irp->f, ",name=%s)", instruction->name_hint);
17162161}
17172162
1718static void ir_print_alloca_gen(IrPrint *irp, IrInstructionAllocaGen *instruction) {
2163static void ir_print_alloca_gen(IrPrintGen *irp, IrInstGenAlloca *instruction) {
17192164 fprintf(irp->f, "Alloca(align=%" PRIu32 ",name=%s)", instruction->align, instruction->name_hint);
17202165}
17212166
1722static void ir_print_end_expr(IrPrint *irp, IrInstructionEndExpr *instruction) {
2167static void ir_print_end_expr(IrPrintSrc *irp, IrInstSrcEndExpr *instruction) {
17232168 fprintf(irp->f, "EndExpr(result=");
17242169 ir_print_result_loc(irp, instruction->result_loc);
17252170 fprintf(irp->f, ",value=");
1726 ir_print_other_instruction(irp, instruction->value);
2171 ir_print_other_inst_src(irp, instruction->value);
17272172 fprintf(irp->f, ")");
17282173}
17292174
1730static void ir_print_int_to_err(IrPrint *irp, IrInstructionIntToErr *instruction) {
2175static void ir_print_int_to_err(IrPrintSrc *irp, IrInstSrcIntToErr *instruction) {
17312176 fprintf(irp->f, "inttoerr ");
1732 ir_print_other_instruction(irp, instruction->target);
2177 ir_print_other_inst_src(irp, instruction->target);
17332178}
17342179
1735static void ir_print_err_to_int(IrPrint *irp, IrInstructionErrToInt *instruction) {
2180static void ir_print_int_to_err(IrPrintGen *irp, IrInstGenIntToErr *instruction) {
2181 fprintf(irp->f, "inttoerr ");
2182 ir_print_other_inst_gen(irp, instruction->target);
2183}
2184
2185static void ir_print_err_to_int(IrPrintSrc *irp, IrInstSrcErrToInt *instruction) {
2186 fprintf(irp->f, "errtoint ");
2187 ir_print_other_inst_src(irp, instruction->target);
2188}
2189
2190static void ir_print_err_to_int(IrPrintGen *irp, IrInstGenErrToInt *instruction) {
17362191 fprintf(irp->f, "errtoint ");
1737 ir_print_other_instruction(irp, instruction->target);
2192 ir_print_other_inst_gen(irp, instruction->target);
17382193}
17392194
1740static void ir_print_check_switch_prongs(IrPrint *irp, IrInstructionCheckSwitchProngs *instruction) {
2195static void ir_print_check_switch_prongs(IrPrintSrc *irp, IrInstSrcCheckSwitchProngs *instruction) {
17412196 fprintf(irp->f, "@checkSwitchProngs(");
1742 ir_print_other_instruction(irp, instruction->target_value);
2197 ir_print_other_inst_src(irp, instruction->target_value);
17432198 fprintf(irp->f, ",");
17442199 for (size_t i = 0; i < instruction->range_count; i += 1) {
17452200 if (i != 0)
17462201 fprintf(irp->f, ",");
1747 ir_print_other_instruction(irp, instruction->ranges[i].start);
2202 ir_print_other_inst_src(irp, instruction->ranges[i].start);
17482203 fprintf(irp->f, "...");
1749 ir_print_other_instruction(irp, instruction->ranges[i].end);
2204 ir_print_other_inst_src(irp, instruction->ranges[i].end);
17502205 }
17512206 const char *have_else_str = instruction->have_else_prong ? "yes" : "no";
17522207 fprintf(irp->f, ")else:%s", have_else_str);
17532208}
17542209
1755static void ir_print_check_statement_is_void(IrPrint *irp, IrInstructionCheckStatementIsVoid *instruction) {
2210static void ir_print_check_statement_is_void(IrPrintSrc *irp, IrInstSrcCheckStatementIsVoid *instruction) {
17562211 fprintf(irp->f, "@checkStatementIsVoid(");
1757 ir_print_other_instruction(irp, instruction->statement_value);
2212 ir_print_other_inst_src(irp, instruction->statement_value);
17582213 fprintf(irp->f, ")");
17592214}
17602215
1761static void ir_print_type_name(IrPrint *irp, IrInstructionTypeName *instruction) {
2216static void ir_print_type_name(IrPrintSrc *irp, IrInstSrcTypeName *instruction) {
17622217 fprintf(irp->f, "typename ");
1763 ir_print_other_instruction(irp, instruction->type_value);
2218 ir_print_other_inst_src(irp, instruction->type_value);
2219}
2220
2221static void ir_print_tag_name(IrPrintSrc *irp, IrInstSrcTagName *instruction) {
2222 fprintf(irp->f, "tagname ");
2223 ir_print_other_inst_src(irp, instruction->target);
17642224}
17652225
1766static void ir_print_tag_name(IrPrint *irp, IrInstructionTagName *instruction) {
2226static void ir_print_tag_name(IrPrintGen *irp, IrInstGenTagName *instruction) {
17672227 fprintf(irp->f, "tagname ");
1768 ir_print_other_instruction(irp, instruction->target);
2228 ir_print_other_inst_gen(irp, instruction->target);
17692229}
17702230
1771static void ir_print_ptr_type(IrPrint *irp, IrInstructionPtrType *instruction) {
2231static void ir_print_ptr_type(IrPrintSrc *irp, IrInstSrcPtrType *instruction) {
17722232 fprintf(irp->f, "&");
17732233 if (instruction->align_value != nullptr) {
17742234 fprintf(irp->f, "align(");
1775 ir_print_other_instruction(irp, instruction->align_value);
2235 ir_print_other_inst_src(irp, instruction->align_value);
17762236 fprintf(irp->f, ")");
17772237 }
17782238 const char *const_str = instruction->is_const ? "const " : "";
17792239 const char *volatile_str = instruction->is_volatile ? "volatile " : "";
17802240 fprintf(irp->f, ":%" PRIu32 ":%" PRIu32 " %s%s", instruction->bit_offset_start, instruction->host_int_bytes,
17812241 const_str, volatile_str);
1782 ir_print_other_instruction(irp, instruction->child_type);
2242 ir_print_other_inst_src(irp, instruction->child_type);
17832243}
17842244
1785static void ir_print_decl_ref(IrPrint *irp, IrInstructionDeclRef *instruction) {
2245static void ir_print_decl_ref(IrPrintSrc *irp, IrInstSrcDeclRef *instruction) {
17862246 const char *ptr_str = (instruction->lval == LValPtr) ? "ptr " : "";
17872247 fprintf(irp->f, "declref %s%s", ptr_str, buf_ptr(instruction->tld->name));
17882248}
17892249
1790static void ir_print_panic(IrPrint *irp, IrInstructionPanic *instruction) {
2250static void ir_print_panic(IrPrintSrc *irp, IrInstSrcPanic *instruction) {
17912251 fprintf(irp->f, "@panic(");
1792 ir_print_other_instruction(irp, instruction->msg);
2252 ir_print_other_inst_src(irp, instruction->msg);
17932253 fprintf(irp->f, ")");
17942254}
17952255
1796static void ir_print_field_parent_ptr(IrPrint *irp, IrInstructionFieldParentPtr *instruction) {
2256static void ir_print_panic(IrPrintGen *irp, IrInstGenPanic *instruction) {
2257 fprintf(irp->f, "@panic(");
2258 ir_print_other_inst_gen(irp, instruction->msg);
2259 fprintf(irp->f, ")");
2260}
2261
2262static void ir_print_field_parent_ptr(IrPrintSrc *irp, IrInstSrcFieldParentPtr *instruction) {
17972263 fprintf(irp->f, "@fieldParentPtr(");
1798 ir_print_other_instruction(irp, instruction->type_value);
2264 ir_print_other_inst_src(irp, instruction->type_value);
17992265 fprintf(irp->f, ",");
1800 ir_print_other_instruction(irp, instruction->field_name);
2266 ir_print_other_inst_src(irp, instruction->field_name);
18012267 fprintf(irp->f, ",");
1802 ir_print_other_instruction(irp, instruction->field_ptr);
2268 ir_print_other_inst_src(irp, instruction->field_ptr);
18032269 fprintf(irp->f, ")");
18042270}
18052271
1806static void ir_print_byte_offset_of(IrPrint *irp, IrInstructionByteOffsetOf *instruction) {
2272static void ir_print_field_parent_ptr(IrPrintGen *irp, IrInstGenFieldParentPtr *instruction) {
2273 fprintf(irp->f, "@fieldParentPtr(%s,", buf_ptr(instruction->field->name));
2274 ir_print_other_inst_gen(irp, instruction->field_ptr);
2275 fprintf(irp->f, ")");
2276}
2277
2278static void ir_print_byte_offset_of(IrPrintSrc *irp, IrInstSrcByteOffsetOf *instruction) {
18072279 fprintf(irp->f, "@byte_offset_of(");
1808 ir_print_other_instruction(irp, instruction->type_value);
2280 ir_print_other_inst_src(irp, instruction->type_value);
18092281 fprintf(irp->f, ",");
1810 ir_print_other_instruction(irp, instruction->field_name);
2282 ir_print_other_inst_src(irp, instruction->field_name);
18112283 fprintf(irp->f, ")");
18122284}
18132285
1814static void ir_print_bit_offset_of(IrPrint *irp, IrInstructionBitOffsetOf *instruction) {
2286static void ir_print_bit_offset_of(IrPrintSrc *irp, IrInstSrcBitOffsetOf *instruction) {
18152287 fprintf(irp->f, "@bit_offset_of(");
1816 ir_print_other_instruction(irp, instruction->type_value);
2288 ir_print_other_inst_src(irp, instruction->type_value);
18172289 fprintf(irp->f, ",");
1818 ir_print_other_instruction(irp, instruction->field_name);
2290 ir_print_other_inst_src(irp, instruction->field_name);
18192291 fprintf(irp->f, ")");
18202292}
18212293
1822static void ir_print_type_info(IrPrint *irp, IrInstructionTypeInfo *instruction) {
2294static void ir_print_type_info(IrPrintSrc *irp, IrInstSrcTypeInfo *instruction) {
18232295 fprintf(irp->f, "@typeInfo(");
1824 ir_print_other_instruction(irp, instruction->type_value);
2296 ir_print_other_inst_src(irp, instruction->type_value);
18252297 fprintf(irp->f, ")");
18262298}
18272299
1828static void ir_print_type(IrPrint *irp, IrInstructionType *instruction) {
2300static void ir_print_type(IrPrintSrc *irp, IrInstSrcType *instruction) {
18292301 fprintf(irp->f, "@Type(");
1830 ir_print_other_instruction(irp, instruction->type_info);
2302 ir_print_other_inst_src(irp, instruction->type_info);
18312303 fprintf(irp->f, ")");
18322304}
18332305
1834static void ir_print_has_field(IrPrint *irp, IrInstructionHasField *instruction) {
2306static void ir_print_has_field(IrPrintSrc *irp, IrInstSrcHasField *instruction) {
18352307 fprintf(irp->f, "@hasField(");
1836 ir_print_other_instruction(irp, instruction->container_type);
2308 ir_print_other_inst_src(irp, instruction->container_type);
18372309 fprintf(irp->f, ",");
1838 ir_print_other_instruction(irp, instruction->field_name);
2310 ir_print_other_inst_src(irp, instruction->field_name);
18392311 fprintf(irp->f, ")");
18402312}
18412313
1842static void ir_print_type_id(IrPrint *irp, IrInstructionTypeId *instruction) {
2314static void ir_print_type_id(IrPrintSrc *irp, IrInstSrcTypeId *instruction) {
18432315 fprintf(irp->f, "@typeId(");
1844 ir_print_other_instruction(irp, instruction->type_value);
2316 ir_print_other_inst_src(irp, instruction->type_value);
18452317 fprintf(irp->f, ")");
18462318}
18472319
1848static void ir_print_set_eval_branch_quota(IrPrint *irp, IrInstructionSetEvalBranchQuota *instruction) {
2320static void ir_print_set_eval_branch_quota(IrPrintSrc *irp, IrInstSrcSetEvalBranchQuota *instruction) {
18492321 fprintf(irp->f, "@setEvalBranchQuota(");
1850 ir_print_other_instruction(irp, instruction->new_quota);
2322 ir_print_other_inst_src(irp, instruction->new_quota);
18512323 fprintf(irp->f, ")");
18522324}
18532325
1854static void ir_print_align_cast(IrPrint *irp, IrInstructionAlignCast *instruction) {
2326static void ir_print_align_cast(IrPrintSrc *irp, IrInstSrcAlignCast *instruction) {
18552327 fprintf(irp->f, "@alignCast(");
1856 if (instruction->align_bytes == nullptr) {
1857 fprintf(irp->f, "null");
1858 } else {
1859 ir_print_other_instruction(irp, instruction->align_bytes);
1860 }
2328 ir_print_other_inst_src(irp, instruction->align_bytes);
18612329 fprintf(irp->f, ",");
1862 ir_print_other_instruction(irp, instruction->target);
2330 ir_print_other_inst_src(irp, instruction->target);
2331 fprintf(irp->f, ")");
2332}
2333
2334static void ir_print_align_cast(IrPrintGen *irp, IrInstGenAlignCast *instruction) {
2335 fprintf(irp->f, "@alignCast(");
2336 ir_print_other_inst_gen(irp, instruction->target);
18632337 fprintf(irp->f, ")");
18642338}
18652339
1866static void ir_print_resolve_result(IrPrint *irp, IrInstructionResolveResult *instruction) {
2340static void ir_print_resolve_result(IrPrintSrc *irp, IrInstSrcResolveResult *instruction) {
18672341 fprintf(irp->f, "ResolveResult(");
18682342 ir_print_result_loc(irp, instruction->result_loc);
18692343 fprintf(irp->f, ")");
18702344}
18712345
1872static void ir_print_reset_result(IrPrint *irp, IrInstructionResetResult *instruction) {
2346static void ir_print_reset_result(IrPrintSrc *irp, IrInstSrcResetResult *instruction) {
18732347 fprintf(irp->f, "ResetResult(");
18742348 ir_print_result_loc(irp, instruction->result_loc);
18752349 fprintf(irp->f, ")");
18762350}
18772351
1878static void ir_print_opaque_type(IrPrint *irp, IrInstructionOpaqueType *instruction) {
2352static void ir_print_opaque_type(IrPrintSrc *irp, IrInstSrcOpaqueType *instruction) {
18792353 fprintf(irp->f, "@OpaqueType()");
18802354}
18812355
1882static void ir_print_set_align_stack(IrPrint *irp, IrInstructionSetAlignStack *instruction) {
2356static void ir_print_set_align_stack(IrPrintSrc *irp, IrInstSrcSetAlignStack *instruction) {
18832357 fprintf(irp->f, "@setAlignStack(");
1884 ir_print_other_instruction(irp, instruction->align_bytes);
2358 ir_print_other_inst_src(irp, instruction->align_bytes);
18852359 fprintf(irp->f, ")");
18862360}
18872361
1888static void ir_print_arg_type(IrPrint *irp, IrInstructionArgType *instruction) {
2362static void ir_print_arg_type(IrPrintSrc *irp, IrInstSrcArgType *instruction) {
18892363 fprintf(irp->f, "@ArgType(");
1890 ir_print_other_instruction(irp, instruction->fn_type);
2364 ir_print_other_inst_src(irp, instruction->fn_type);
18912365 fprintf(irp->f, ",");
1892 ir_print_other_instruction(irp, instruction->arg_index);
2366 ir_print_other_inst_src(irp, instruction->arg_index);
18932367 fprintf(irp->f, ")");
18942368}
18952369
1896static void ir_print_enum_tag_type(IrPrint *irp, IrInstructionTagType *instruction) {
2370static void ir_print_enum_tag_type(IrPrintSrc *irp, IrInstSrcTagType *instruction) {
18972371 fprintf(irp->f, "@TagType(");
1898 ir_print_other_instruction(irp, instruction->target);
2372 ir_print_other_inst_src(irp, instruction->target);
18992373 fprintf(irp->f, ")");
19002374}
19012375
1902static void ir_print_export(IrPrint *irp, IrInstructionExport *instruction) {
2376static void ir_print_export(IrPrintSrc *irp, IrInstSrcExport *instruction) {
19032377 fprintf(irp->f, "@export(");
1904 ir_print_other_instruction(irp, instruction->target);
2378 ir_print_other_inst_src(irp, instruction->target);
19052379 fprintf(irp->f, ",");
1906 ir_print_other_instruction(irp, instruction->options);
2380 ir_print_other_inst_src(irp, instruction->options);
2381 fprintf(irp->f, ")");
2382}
2383
2384static void ir_print_error_return_trace(IrPrintSrc *irp, IrInstSrcErrorReturnTrace *instruction) {
2385 fprintf(irp->f, "@errorReturnTrace(");
2386 switch (instruction->optional) {
2387 case IrInstErrorReturnTraceNull:
2388 fprintf(irp->f, "Null");
2389 break;
2390 case IrInstErrorReturnTraceNonNull:
2391 fprintf(irp->f, "NonNull");
2392 break;
2393 }
19072394 fprintf(irp->f, ")");
19082395}
19092396
1910static void ir_print_error_return_trace(IrPrint *irp, IrInstructionErrorReturnTrace *instruction) {
2397static void ir_print_error_return_trace(IrPrintGen *irp, IrInstGenErrorReturnTrace *instruction) {
19112398 fprintf(irp->f, "@errorReturnTrace(");
19122399 switch (instruction->optional) {
1913 case IrInstructionErrorReturnTrace::Null:
2400 case IrInstErrorReturnTraceNull:
19142401 fprintf(irp->f, "Null");
19152402 break;
1916 case IrInstructionErrorReturnTrace::NonNull:
2403 case IrInstErrorReturnTraceNonNull:
19172404 fprintf(irp->f, "NonNull");
19182405 break;
19192406 }
19202407 fprintf(irp->f, ")");
19212408}
19222409
1923static void ir_print_error_union(IrPrint *irp, IrInstructionErrorUnion *instruction) {
1924 ir_print_other_instruction(irp, instruction->err_set);
2410static void ir_print_error_union(IrPrintSrc *irp, IrInstSrcErrorUnion *instruction) {
2411 ir_print_other_inst_src(irp, instruction->err_set);
19252412 fprintf(irp->f, "!");
1926 ir_print_other_instruction(irp, instruction->payload);
2413 ir_print_other_inst_src(irp, instruction->payload);
19272414}
19282415
1929static void ir_print_atomic_rmw(IrPrint *irp, IrInstructionAtomicRmw *instruction) {
2416static void ir_print_atomic_rmw(IrPrintSrc *irp, IrInstSrcAtomicRmw *instruction) {
19302417 fprintf(irp->f, "@atomicRmw(");
1931 if (instruction->operand_type != nullptr) {
1932 ir_print_other_instruction(irp, instruction->operand_type);
1933 } else {
1934 fprintf(irp->f, "[TODO print]");
1935 }
2418 ir_print_other_inst_src(irp, instruction->operand_type);
19362419 fprintf(irp->f, ",");
1937 ir_print_other_instruction(irp, instruction->ptr);
2420 ir_print_other_inst_src(irp, instruction->ptr);
19382421 fprintf(irp->f, ",");
1939 if (instruction->op != nullptr) {
1940 ir_print_other_instruction(irp, instruction->op);
1941 } else {
1942 fprintf(irp->f, "[TODO print]");
1943 }
2422 ir_print_other_inst_src(irp, instruction->op);
19442423 fprintf(irp->f, ",");
1945 ir_print_other_instruction(irp, instruction->operand);
2424 ir_print_other_inst_src(irp, instruction->operand);
19462425 fprintf(irp->f, ",");
1947 if (instruction->ordering != nullptr) {
1948 ir_print_other_instruction(irp, instruction->ordering);
1949 } else {
1950 fprintf(irp->f, "[TODO print]");
1951 }
2426 ir_print_other_inst_src(irp, instruction->ordering);
19522427 fprintf(irp->f, ")");
19532428}
19542429
1955static void ir_print_atomic_load(IrPrint *irp, IrInstructionAtomicLoad *instruction) {
2430static void ir_print_atomic_rmw(IrPrintGen *irp, IrInstGenAtomicRmw *instruction) {
2431 fprintf(irp->f, "@atomicRmw(");
2432 ir_print_other_inst_gen(irp, instruction->ptr);
2433 fprintf(irp->f, ",[TODO print op],");
2434 ir_print_other_inst_gen(irp, instruction->operand);
2435 fprintf(irp->f, ",%s)", atomic_order_str(instruction->ordering));
2436}
2437
2438static void ir_print_atomic_load(IrPrintSrc *irp, IrInstSrcAtomicLoad *instruction) {
19562439 fprintf(irp->f, "@atomicLoad(");
1957 if (instruction->operand_type != nullptr) {
1958 ir_print_other_instruction(irp, instruction->operand_type);
1959 } else {
1960 fprintf(irp->f, "[TODO print]");
1961 }
2440 ir_print_other_inst_src(irp, instruction->operand_type);
19622441 fprintf(irp->f, ",");
1963 ir_print_other_instruction(irp, instruction->ptr);
2442 ir_print_other_inst_src(irp, instruction->ptr);
19642443 fprintf(irp->f, ",");
1965 if (instruction->ordering != nullptr) {
1966 ir_print_other_instruction(irp, instruction->ordering);
1967 } else {
1968 fprintf(irp->f, "[TODO print]");
1969 }
2444 ir_print_other_inst_src(irp, instruction->ordering);
19702445 fprintf(irp->f, ")");
19712446}
19722447
1973static void ir_print_atomic_store(IrPrint *irp, IrInstructionAtomicStore *instruction) {
2448static void ir_print_atomic_load(IrPrintGen *irp, IrInstGenAtomicLoad *instruction) {
2449 fprintf(irp->f, "@atomicLoad(");
2450 ir_print_other_inst_gen(irp, instruction->ptr);
2451 fprintf(irp->f, ",%s)", atomic_order_str(instruction->ordering));
2452}
2453
2454static void ir_print_atomic_store(IrPrintSrc *irp, IrInstSrcAtomicStore *instruction) {
19742455 fprintf(irp->f, "@atomicStore(");
1975 if (instruction->operand_type != nullptr) {
1976 ir_print_other_instruction(irp, instruction->operand_type);
1977 } else {
1978 fprintf(irp->f, "[TODO print]");
1979 }
2456 ir_print_other_inst_src(irp, instruction->operand_type);
19802457 fprintf(irp->f, ",");
1981 ir_print_other_instruction(irp, instruction->ptr);
2458 ir_print_other_inst_src(irp, instruction->ptr);
19822459 fprintf(irp->f, ",");
1983 ir_print_other_instruction(irp, instruction->value);
2460 ir_print_other_inst_src(irp, instruction->value);
19842461 fprintf(irp->f, ",");
1985 if (instruction->ordering != nullptr) {
1986 ir_print_other_instruction(irp, instruction->ordering);
1987 } else {
1988 fprintf(irp->f, "[TODO print]");
1989 }
2462 ir_print_other_inst_src(irp, instruction->ordering);
19902463 fprintf(irp->f, ")");
19912464}
19922465
2466static void ir_print_atomic_store(IrPrintGen *irp, IrInstGenAtomicStore *instruction) {
2467 fprintf(irp->f, "@atomicStore(");
2468 ir_print_other_inst_gen(irp, instruction->ptr);
2469 fprintf(irp->f, ",");
2470 ir_print_other_inst_gen(irp, instruction->value);
2471 fprintf(irp->f, ",%s)", atomic_order_str(instruction->ordering));
2472}
2473
2474
2475static void ir_print_save_err_ret_addr(IrPrintSrc *irp, IrInstSrcSaveErrRetAddr *instruction) {
2476 fprintf(irp->f, "@saveErrRetAddr()");
2477}
19932478
1994static void ir_print_save_err_ret_addr(IrPrint *irp, IrInstructionSaveErrRetAddr *instruction) {
2479static void ir_print_save_err_ret_addr(IrPrintGen *irp, IrInstGenSaveErrRetAddr *instruction) {
19952480 fprintf(irp->f, "@saveErrRetAddr()");
19962481}
19972482
1998static void ir_print_add_implicit_return_type(IrPrint *irp, IrInstructionAddImplicitReturnType *instruction) {
2483static void ir_print_add_implicit_return_type(IrPrintSrc *irp, IrInstSrcAddImplicitReturnType *instruction) {
19992484 fprintf(irp->f, "@addImplicitReturnType(");
2000 ir_print_other_instruction(irp, instruction->value);
2485 ir_print_other_inst_src(irp, instruction->value);
2486 fprintf(irp->f, ")");
2487}
2488
2489static void ir_print_float_op(IrPrintSrc *irp, IrInstSrcFloatOp *instruction) {
2490 fprintf(irp->f, "@%s(", float_op_to_name(instruction->fn_id));
2491 ir_print_other_inst_src(irp, instruction->operand);
20012492 fprintf(irp->f, ")");
20022493}
20032494
2004static void ir_print_float_op(IrPrint *irp, IrInstructionFloatOp *instruction) {
2495static void ir_print_float_op(IrPrintGen *irp, IrInstGenFloatOp *instruction) {
20052496 fprintf(irp->f, "@%s(", float_op_to_name(instruction->fn_id));
2006 ir_print_other_instruction(irp, instruction->operand);
2497 ir_print_other_inst_gen(irp, instruction->operand);
20072498 fprintf(irp->f, ")");
20082499}
20092500
2010static void ir_print_mul_add(IrPrint *irp, IrInstructionMulAdd *instruction) {
2501static void ir_print_mul_add(IrPrintSrc *irp, IrInstSrcMulAdd *instruction) {
20112502 fprintf(irp->f, "@mulAdd(");
2012 if (instruction->type_value != nullptr) {
2013 ir_print_other_instruction(irp, instruction->type_value);
2014 } else {
2015 fprintf(irp->f, "null");
2016 }
2503 ir_print_other_inst_src(irp, instruction->type_value);
20172504 fprintf(irp->f, ",");
2018 ir_print_other_instruction(irp, instruction->op1);
2505 ir_print_other_inst_src(irp, instruction->op1);
20192506 fprintf(irp->f, ",");
2020 ir_print_other_instruction(irp, instruction->op2);
2507 ir_print_other_inst_src(irp, instruction->op2);
20212508 fprintf(irp->f, ",");
2022 ir_print_other_instruction(irp, instruction->op3);
2509 ir_print_other_inst_src(irp, instruction->op3);
20232510 fprintf(irp->f, ")");
20242511}
20252512
2026static void ir_print_decl_var_gen(IrPrint *irp, IrInstructionDeclVarGen *decl_var_instruction) {
2513static void ir_print_mul_add(IrPrintGen *irp, IrInstGenMulAdd *instruction) {
2514 fprintf(irp->f, "@mulAdd(");
2515 ir_print_other_inst_gen(irp, instruction->op1);
2516 fprintf(irp->f, ",");
2517 ir_print_other_inst_gen(irp, instruction->op2);
2518 fprintf(irp->f, ",");
2519 ir_print_other_inst_gen(irp, instruction->op3);
2520 fprintf(irp->f, ")");
2521}
2522
2523static void ir_print_decl_var_gen(IrPrintGen *irp, IrInstGenDeclVar *decl_var_instruction) {
20272524 ZigVar *var = decl_var_instruction->var;
20282525 const char *var_or_const = decl_var_instruction->var->gen_is_const ? "const" : "var";
20292526 const char *name = decl_var_instruction->var->name;
20302527 fprintf(irp->f, "%s %s: %s align(%u) = ", var_or_const, name, buf_ptr(&var->var_type->name),
20312528 var->align_bytes);
20322529
2033 ir_print_other_instruction(irp, decl_var_instruction->var_ptr);
2034 if (decl_var_instruction->var->is_comptime != nullptr) {
2035 fprintf(irp->f, " // comptime = ");
2036 ir_print_other_instruction(irp, decl_var_instruction->var->is_comptime);
2037 }
2530 ir_print_other_inst_gen(irp, decl_var_instruction->var_ptr);
20382531}
20392532
2040static void ir_print_has_decl(IrPrint *irp, IrInstructionHasDecl *instruction) {
2533static void ir_print_has_decl(IrPrintSrc *irp, IrInstSrcHasDecl *instruction) {
20412534 fprintf(irp->f, "@hasDecl(");
2042 ir_print_other_instruction(irp, instruction->container);
2535 ir_print_other_inst_src(irp, instruction->container);
20432536 fprintf(irp->f, ",");
2044 ir_print_other_instruction(irp, instruction->name);
2537 ir_print_other_inst_src(irp, instruction->name);
20452538 fprintf(irp->f, ")");
20462539}
20472540
2048static void ir_print_undeclared_ident(IrPrint *irp, IrInstructionUndeclaredIdent *instruction) {
2541static void ir_print_undeclared_ident(IrPrintSrc *irp, IrInstSrcUndeclaredIdent *instruction) {
20492542 fprintf(irp->f, "@undeclaredIdent(%s)", buf_ptr(instruction->name));
20502543}
20512544
2052static void ir_print_union_init_named_field(IrPrint *irp, IrInstructionUnionInitNamedField *instruction) {
2545static void ir_print_union_init_named_field(IrPrintSrc *irp, IrInstSrcUnionInitNamedField *instruction) {
20532546 fprintf(irp->f, "@unionInit(");
2054 ir_print_other_instruction(irp, instruction->union_type);
2547 ir_print_other_inst_src(irp, instruction->union_type);
20552548 fprintf(irp->f, ", ");
2056 ir_print_other_instruction(irp, instruction->field_name);
2549 ir_print_other_inst_src(irp, instruction->field_name);
20572550 fprintf(irp->f, ", ");
2058 ir_print_other_instruction(irp, instruction->field_result_loc);
2551 ir_print_other_inst_src(irp, instruction->field_result_loc);
20592552 fprintf(irp->f, ", ");
2060 ir_print_other_instruction(irp, instruction->result_loc);
2553 ir_print_other_inst_src(irp, instruction->result_loc);
20612554 fprintf(irp->f, ")");
20622555}
20632556
2064static void ir_print_suspend_begin(IrPrint *irp, IrInstructionSuspendBegin *instruction) {
2557static void ir_print_suspend_begin(IrPrintSrc *irp, IrInstSrcSuspendBegin *instruction) {
2558 fprintf(irp->f, "@suspendBegin()");
2559}
2560
2561static void ir_print_suspend_begin(IrPrintGen *irp, IrInstGenSuspendBegin *instruction) {
20652562 fprintf(irp->f, "@suspendBegin()");
20662563}
20672564
2068static void ir_print_suspend_finish(IrPrint *irp, IrInstructionSuspendFinish *instruction) {
2565static void ir_print_suspend_finish(IrPrintSrc *irp, IrInstSrcSuspendFinish *instruction) {
2566 fprintf(irp->f, "@suspendFinish()");
2567}
2568
2569static void ir_print_suspend_finish(IrPrintGen *irp, IrInstGenSuspendFinish *instruction) {
20692570 fprintf(irp->f, "@suspendFinish()");
20702571}
20712572
2072static void ir_print_resume(IrPrint *irp, IrInstructionResume *instruction) {
2573static void ir_print_resume(IrPrintSrc *irp, IrInstSrcResume *instruction) {
20732574 fprintf(irp->f, "resume ");
2074 ir_print_other_instruction(irp, instruction->frame);
2575 ir_print_other_inst_src(irp, instruction->frame);
20752576}
20762577
2077static void ir_print_await_src(IrPrint *irp, IrInstructionAwaitSrc *instruction) {
2578static void ir_print_resume(IrPrintGen *irp, IrInstGenResume *instruction) {
2579 fprintf(irp->f, "resume ");
2580 ir_print_other_inst_gen(irp, instruction->frame);
2581}
2582
2583static void ir_print_await_src(IrPrintSrc *irp, IrInstSrcAwait *instruction) {
20782584 fprintf(irp->f, "@await(");
2079 ir_print_other_instruction(irp, instruction->frame);
2585 ir_print_other_inst_src(irp, instruction->frame);
20802586 fprintf(irp->f, ",");
20812587 ir_print_result_loc(irp, instruction->result_loc);
20822588 fprintf(irp->f, ")");
20832589}
20842590
2085static void ir_print_await_gen(IrPrint *irp, IrInstructionAwaitGen *instruction) {
2591static void ir_print_await_gen(IrPrintGen *irp, IrInstGenAwait *instruction) {
20862592 fprintf(irp->f, "@await(");
2087 ir_print_other_instruction(irp, instruction->frame);
2593 ir_print_other_inst_gen(irp, instruction->frame);
20882594 fprintf(irp->f, ",");
2089 ir_print_other_instruction(irp, instruction->result_loc);
2595 ir_print_other_inst_gen(irp, instruction->result_loc);
2596 fprintf(irp->f, ")");
2597}
2598
2599static void ir_print_spill_begin(IrPrintSrc *irp, IrInstSrcSpillBegin *instruction) {
2600 fprintf(irp->f, "@spillBegin(");
2601 ir_print_other_inst_src(irp, instruction->operand);
20902602 fprintf(irp->f, ")");
20912603}
20922604
2093static void ir_print_spill_begin(IrPrint *irp, IrInstructionSpillBegin *instruction) {
2605static void ir_print_spill_begin(IrPrintGen *irp, IrInstGenSpillBegin *instruction) {
20942606 fprintf(irp->f, "@spillBegin(");
2095 ir_print_other_instruction(irp, instruction->operand);
2607 ir_print_other_inst_gen(irp, instruction->operand);
20962608 fprintf(irp->f, ")");
20972609}
20982610
2099static void ir_print_spill_end(IrPrint *irp, IrInstructionSpillEnd *instruction) {
2611static void ir_print_spill_end(IrPrintSrc *irp, IrInstSrcSpillEnd *instruction) {
21002612 fprintf(irp->f, "@spillEnd(");
2101 ir_print_other_instruction(irp, &instruction->begin->base);
2613 ir_print_other_inst_src(irp, &instruction->begin->base);
21022614 fprintf(irp->f, ")");
21032615}
21042616
2105static void ir_print_vector_extract_elem(IrPrint *irp, IrInstructionVectorExtractElem *instruction) {
2617static void ir_print_spill_end(IrPrintGen *irp, IrInstGenSpillEnd *instruction) {
2618 fprintf(irp->f, "@spillEnd(");
2619 ir_print_other_inst_gen(irp, &instruction->begin->base);
2620 fprintf(irp->f, ")");
2621}
2622
2623static void ir_print_vector_extract_elem(IrPrintGen *irp, IrInstGenVectorExtractElem *instruction) {
21062624 fprintf(irp->f, "@vectorExtractElem(");
2107 ir_print_other_instruction(irp, instruction->vector);
2625 ir_print_other_inst_gen(irp, instruction->vector);
21082626 fprintf(irp->f, ",");
2109 ir_print_other_instruction(irp, instruction->index);
2627 ir_print_other_inst_gen(irp, instruction->index);
21102628 fprintf(irp->f, ")");
21112629}
21122630
2113static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction, bool trailing) {
2114 ir_print_prefix(irp, instruction, trailing);
2631static void ir_print_inst_src(IrPrintSrc *irp, IrInstSrc *instruction, bool trailing) {
2632 ir_print_prefix_src(irp, instruction, trailing);
21152633 switch (instruction->id) {
2116 case IrInstructionIdInvalid:
2634 case IrInstSrcIdInvalid:
21172635 zig_unreachable();
2118 case IrInstructionIdReturn:
2119 ir_print_return(irp, (IrInstructionReturn *)instruction);
2636 case IrInstSrcIdReturn:
2637 ir_print_return_src(irp, (IrInstSrcReturn *)instruction);
2638 break;
2639 case IrInstSrcIdConst:
2640 ir_print_const(irp, (IrInstSrcConst *)instruction);
2641 break;
2642 case IrInstSrcIdBinOp:
2643 ir_print_bin_op(irp, (IrInstSrcBinOp *)instruction);
2644 break;
2645 case IrInstSrcIdMergeErrSets:
2646 ir_print_merge_err_sets(irp, (IrInstSrcMergeErrSets *)instruction);
2647 break;
2648 case IrInstSrcIdDeclVar:
2649 ir_print_decl_var_src(irp, (IrInstSrcDeclVar *)instruction);
2650 break;
2651 case IrInstSrcIdCallExtra:
2652 ir_print_call_extra(irp, (IrInstSrcCallExtra *)instruction);
2653 break;
2654 case IrInstSrcIdCall:
2655 ir_print_call_src(irp, (IrInstSrcCall *)instruction);
2656 break;
2657 case IrInstSrcIdCallArgs:
2658 ir_print_call_args(irp, (IrInstSrcCallArgs *)instruction);
2659 break;
2660 case IrInstSrcIdUnOp:
2661 ir_print_un_op(irp, (IrInstSrcUnOp *)instruction);
2662 break;
2663 case IrInstSrcIdCondBr:
2664 ir_print_cond_br(irp, (IrInstSrcCondBr *)instruction);
21202665 break;
2121 case IrInstructionIdConst:
2122 ir_print_const(irp, (IrInstructionConst *)instruction);
2666 case IrInstSrcIdBr:
2667 ir_print_br(irp, (IrInstSrcBr *)instruction);
21232668 break;
2124 case IrInstructionIdBinOp:
2125 ir_print_bin_op(irp, (IrInstructionBinOp *)instruction);
2669 case IrInstSrcIdPhi:
2670 ir_print_phi(irp, (IrInstSrcPhi *)instruction);
21262671 break;
2127 case IrInstructionIdMergeErrSets:
2128 ir_print_merge_err_sets(irp, (IrInstructionMergeErrSets *)instruction);
2672 case IrInstSrcIdContainerInitList:
2673 ir_print_container_init_list(irp, (IrInstSrcContainerInitList *)instruction);
21292674 break;
2130 case IrInstructionIdDeclVarSrc:
2131 ir_print_decl_var_src(irp, (IrInstructionDeclVarSrc *)instruction);
2675 case IrInstSrcIdContainerInitFields:
2676 ir_print_container_init_fields(irp, (IrInstSrcContainerInitFields *)instruction);
21322677 break;
2133 case IrInstructionIdCast:
2134 ir_print_cast(irp, (IrInstructionCast *)instruction);
2678 case IrInstSrcIdUnreachable:
2679 ir_print_unreachable(irp, (IrInstSrcUnreachable *)instruction);
21352680 break;
2136 case IrInstructionIdCallExtra:
2137 ir_print_call_extra(irp, (IrInstructionCallExtra *)instruction);
2681 case IrInstSrcIdElemPtr:
2682 ir_print_elem_ptr(irp, (IrInstSrcElemPtr *)instruction);
21382683 break;
2139 case IrInstructionIdCallSrc:
2140 ir_print_call_src(irp, (IrInstructionCallSrc *)instruction);
2684 case IrInstSrcIdVarPtr:
2685 ir_print_var_ptr(irp, (IrInstSrcVarPtr *)instruction);
21412686 break;
2142 case IrInstructionIdCallSrcArgs:
2143 ir_print_call_src_args(irp, (IrInstructionCallSrcArgs *)instruction);
2687 case IrInstSrcIdLoadPtr:
2688 ir_print_load_ptr(irp, (IrInstSrcLoadPtr *)instruction);
21442689 break;
2145 case IrInstructionIdCallGen:
2146 ir_print_call_gen(irp, (IrInstructionCallGen *)instruction);
2690 case IrInstSrcIdStorePtr:
2691 ir_print_store_ptr(irp, (IrInstSrcStorePtr *)instruction);
21472692 break;
2148 case IrInstructionIdUnOp:
2149 ir_print_un_op(irp, (IrInstructionUnOp *)instruction);
2693 case IrInstSrcIdTypeOf:
2694 ir_print_typeof(irp, (IrInstSrcTypeOf *)instruction);
21502695 break;
2151 case IrInstructionIdCondBr:
2152 ir_print_cond_br(irp, (IrInstructionCondBr *)instruction);
2696 case IrInstSrcIdFieldPtr:
2697 ir_print_field_ptr(irp, (IrInstSrcFieldPtr *)instruction);
21532698 break;
2154 case IrInstructionIdBr:
2155 ir_print_br(irp, (IrInstructionBr *)instruction);
2699 case IrInstSrcIdSetCold:
2700 ir_print_set_cold(irp, (IrInstSrcSetCold *)instruction);
21562701 break;
2157 case IrInstructionIdPhi:
2158 ir_print_phi(irp, (IrInstructionPhi *)instruction);
2702 case IrInstSrcIdSetRuntimeSafety:
2703 ir_print_set_runtime_safety(irp, (IrInstSrcSetRuntimeSafety *)instruction);
21592704 break;
2160 case IrInstructionIdContainerInitList:
2161 ir_print_container_init_list(irp, (IrInstructionContainerInitList *)instruction);
2705 case IrInstSrcIdSetFloatMode:
2706 ir_print_set_float_mode(irp, (IrInstSrcSetFloatMode *)instruction);
21622707 break;
2163 case IrInstructionIdContainerInitFields:
2164 ir_print_container_init_fields(irp, (IrInstructionContainerInitFields *)instruction);
2708 case IrInstSrcIdArrayType:
2709 ir_print_array_type(irp, (IrInstSrcArrayType *)instruction);
21652710 break;
2166 case IrInstructionIdUnreachable:
2167 ir_print_unreachable(irp, (IrInstructionUnreachable *)instruction);
2711 case IrInstSrcIdSliceType:
2712 ir_print_slice_type(irp, (IrInstSrcSliceType *)instruction);
21682713 break;
2169 case IrInstructionIdElemPtr:
2170 ir_print_elem_ptr(irp, (IrInstructionElemPtr *)instruction);
2714 case IrInstSrcIdAnyFrameType:
2715 ir_print_any_frame_type(irp, (IrInstSrcAnyFrameType *)instruction);
21712716 break;
2172 case IrInstructionIdVarPtr:
2173 ir_print_var_ptr(irp, (IrInstructionVarPtr *)instruction);
2717 case IrInstSrcIdAsm:
2718 ir_print_asm_src(irp, (IrInstSrcAsm *)instruction);
21742719 break;
2175 case IrInstructionIdReturnPtr:
2176 ir_print_return_ptr(irp, (IrInstructionReturnPtr *)instruction);
2720 case IrInstSrcIdSizeOf:
2721 ir_print_size_of(irp, (IrInstSrcSizeOf *)instruction);
21772722 break;
2178 case IrInstructionIdLoadPtr:
2179 ir_print_load_ptr(irp, (IrInstructionLoadPtr *)instruction);
2723 case IrInstSrcIdTestNonNull:
2724 ir_print_test_non_null(irp, (IrInstSrcTestNonNull *)instruction);
21802725 break;
2181 case IrInstructionIdLoadPtrGen:
2182 ir_print_load_ptr_gen(irp, (IrInstructionLoadPtrGen *)instruction);
2726 case IrInstSrcIdOptionalUnwrapPtr:
2727 ir_print_optional_unwrap_ptr(irp, (IrInstSrcOptionalUnwrapPtr *)instruction);
21832728 break;
2184 case IrInstructionIdStorePtr:
2185 ir_print_store_ptr(irp, (IrInstructionStorePtr *)instruction);
2729 case IrInstSrcIdPopCount:
2730 ir_print_pop_count(irp, (IrInstSrcPopCount *)instruction);
21862731 break;
2187 case IrInstructionIdVectorStoreElem:
2188 ir_print_vector_store_elem(irp, (IrInstructionVectorStoreElem *)instruction);
2732 case IrInstSrcIdCtz:
2733 ir_print_ctz(irp, (IrInstSrcCtz *)instruction);
21892734 break;
2190 case IrInstructionIdTypeOf:
2191 ir_print_typeof(irp, (IrInstructionTypeOf *)instruction);
2735 case IrInstSrcIdBswap:
2736 ir_print_bswap(irp, (IrInstSrcBswap *)instruction);
21922737 break;
2193 case IrInstructionIdFieldPtr:
2194 ir_print_field_ptr(irp, (IrInstructionFieldPtr *)instruction);
2738 case IrInstSrcIdBitReverse:
2739 ir_print_bit_reverse(irp, (IrInstSrcBitReverse *)instruction);
21952740 break;
2196 case IrInstructionIdStructFieldPtr:
2197 ir_print_struct_field_ptr(irp, (IrInstructionStructFieldPtr *)instruction);
2741 case IrInstSrcIdSwitchBr:
2742 ir_print_switch_br(irp, (IrInstSrcSwitchBr *)instruction);
21982743 break;
2199 case IrInstructionIdUnionFieldPtr:
2200 ir_print_union_field_ptr(irp, (IrInstructionUnionFieldPtr *)instruction);
2744 case IrInstSrcIdSwitchVar:
2745 ir_print_switch_var(irp, (IrInstSrcSwitchVar *)instruction);
22012746 break;
2202 case IrInstructionIdSetCold:
2203 ir_print_set_cold(irp, (IrInstructionSetCold *)instruction);
2747 case IrInstSrcIdSwitchElseVar:
2748 ir_print_switch_else_var(irp, (IrInstSrcSwitchElseVar *)instruction);
22042749 break;
2205 case IrInstructionIdSetRuntimeSafety:
2206 ir_print_set_runtime_safety(irp, (IrInstructionSetRuntimeSafety *)instruction);
2750 case IrInstSrcIdSwitchTarget:
2751 ir_print_switch_target(irp, (IrInstSrcSwitchTarget *)instruction);
22072752 break;
2208 case IrInstructionIdSetFloatMode:
2209 ir_print_set_float_mode(irp, (IrInstructionSetFloatMode *)instruction);
2753 case IrInstSrcIdImport:
2754 ir_print_import(irp, (IrInstSrcImport *)instruction);
22102755 break;
2211 case IrInstructionIdArrayType:
2212 ir_print_array_type(irp, (IrInstructionArrayType *)instruction);
2756 case IrInstSrcIdRef:
2757 ir_print_ref(irp, (IrInstSrcRef *)instruction);
22132758 break;
2214 case IrInstructionIdSliceType:
2215 ir_print_slice_type(irp, (IrInstructionSliceType *)instruction);
2759 case IrInstSrcIdCompileErr:
2760 ir_print_compile_err(irp, (IrInstSrcCompileErr *)instruction);
22162761 break;
2217 case IrInstructionIdAnyFrameType:
2218 ir_print_any_frame_type(irp, (IrInstructionAnyFrameType *)instruction);
2762 case IrInstSrcIdCompileLog:
2763 ir_print_compile_log(irp, (IrInstSrcCompileLog *)instruction);
22192764 break;
2220 case IrInstructionIdAsmSrc:
2221 ir_print_asm_src(irp, (IrInstructionAsmSrc *)instruction);
2765 case IrInstSrcIdErrName:
2766 ir_print_err_name(irp, (IrInstSrcErrName *)instruction);
22222767 break;
2223 case IrInstructionIdAsmGen:
2224 ir_print_asm_gen(irp, (IrInstructionAsmGen *)instruction);
2768 case IrInstSrcIdCImport:
2769 ir_print_c_import(irp, (IrInstSrcCImport *)instruction);
22252770 break;
2226 case IrInstructionIdSizeOf:
2227 ir_print_size_of(irp, (IrInstructionSizeOf *)instruction);
2771 case IrInstSrcIdCInclude:
2772 ir_print_c_include(irp, (IrInstSrcCInclude *)instruction);
22282773 break;
2229 case IrInstructionIdTestNonNull:
2230 ir_print_test_non_null(irp, (IrInstructionTestNonNull *)instruction);
2774 case IrInstSrcIdCDefine:
2775 ir_print_c_define(irp, (IrInstSrcCDefine *)instruction);
22312776 break;
2232 case IrInstructionIdOptionalUnwrapPtr:
2233 ir_print_optional_unwrap_ptr(irp, (IrInstructionOptionalUnwrapPtr *)instruction);
2777 case IrInstSrcIdCUndef:
2778 ir_print_c_undef(irp, (IrInstSrcCUndef *)instruction);
22342779 break;
2235 case IrInstructionIdPopCount:
2236 ir_print_pop_count(irp, (IrInstructionPopCount *)instruction);
2780 case IrInstSrcIdEmbedFile:
2781 ir_print_embed_file(irp, (IrInstSrcEmbedFile *)instruction);
22372782 break;
2238 case IrInstructionIdClz:
2239 ir_print_clz(irp, (IrInstructionClz *)instruction);
2783 case IrInstSrcIdCmpxchg:
2784 ir_print_cmpxchg_src(irp, (IrInstSrcCmpxchg *)instruction);
22402785 break;
2241 case IrInstructionIdCtz:
2242 ir_print_ctz(irp, (IrInstructionCtz *)instruction);
2786 case IrInstSrcIdFence:
2787 ir_print_fence(irp, (IrInstSrcFence *)instruction);
22432788 break;
2244 case IrInstructionIdBswap:
2245 ir_print_bswap(irp, (IrInstructionBswap *)instruction);
2789 case IrInstSrcIdTruncate:
2790 ir_print_truncate(irp, (IrInstSrcTruncate *)instruction);
22462791 break;
2247 case IrInstructionIdBitReverse:
2248 ir_print_bit_reverse(irp, (IrInstructionBitReverse *)instruction);
2792 case IrInstSrcIdIntCast:
2793 ir_print_int_cast(irp, (IrInstSrcIntCast *)instruction);
22492794 break;
2250 case IrInstructionIdSwitchBr:
2251 ir_print_switch_br(irp, (IrInstructionSwitchBr *)instruction);
2795 case IrInstSrcIdFloatCast:
2796 ir_print_float_cast(irp, (IrInstSrcFloatCast *)instruction);
22522797 break;
2253 case IrInstructionIdSwitchVar:
2254 ir_print_switch_var(irp, (IrInstructionSwitchVar *)instruction);
2798 case IrInstSrcIdErrSetCast:
2799 ir_print_err_set_cast(irp, (IrInstSrcErrSetCast *)instruction);
22552800 break;
2256 case IrInstructionIdSwitchElseVar:
2257 ir_print_switch_else_var(irp, (IrInstructionSwitchElseVar *)instruction);
2801 case IrInstSrcIdFromBytes:
2802 ir_print_from_bytes(irp, (IrInstSrcFromBytes *)instruction);
22582803 break;
2259 case IrInstructionIdSwitchTarget:
2260 ir_print_switch_target(irp, (IrInstructionSwitchTarget *)instruction);
2804 case IrInstSrcIdToBytes:
2805 ir_print_to_bytes(irp, (IrInstSrcToBytes *)instruction);
22612806 break;
2262 case IrInstructionIdUnionTag:
2263 ir_print_union_tag(irp, (IrInstructionUnionTag *)instruction);
2807 case IrInstSrcIdIntToFloat:
2808 ir_print_int_to_float(irp, (IrInstSrcIntToFloat *)instruction);
22642809 break;
2265 case IrInstructionIdImport:
2266 ir_print_import(irp, (IrInstructionImport *)instruction);
2810 case IrInstSrcIdFloatToInt:
2811 ir_print_float_to_int(irp, (IrInstSrcFloatToInt *)instruction);
22672812 break;
2268 case IrInstructionIdRef:
2269 ir_print_ref(irp, (IrInstructionRef *)instruction);
2813 case IrInstSrcIdBoolToInt:
2814 ir_print_bool_to_int(irp, (IrInstSrcBoolToInt *)instruction);
22702815 break;
2271 case IrInstructionIdRefGen:
2272 ir_print_ref_gen(irp, (IrInstructionRefGen *)instruction);
2816 case IrInstSrcIdIntType:
2817 ir_print_int_type(irp, (IrInstSrcIntType *)instruction);
22732818 break;
2274 case IrInstructionIdCompileErr:
2275 ir_print_compile_err(irp, (IrInstructionCompileErr *)instruction);
2819 case IrInstSrcIdVectorType:
2820 ir_print_vector_type(irp, (IrInstSrcVectorType *)instruction);
22762821 break;
2277 case IrInstructionIdCompileLog:
2278 ir_print_compile_log(irp, (IrInstructionCompileLog *)instruction);
2822 case IrInstSrcIdShuffleVector:
2823 ir_print_shuffle_vector(irp, (IrInstSrcShuffleVector *)instruction);
22792824 break;
2280 case IrInstructionIdErrName:
2281 ir_print_err_name(irp, (IrInstructionErrName *)instruction);
2825 case IrInstSrcIdSplat:
2826 ir_print_splat_src(irp, (IrInstSrcSplat *)instruction);
22822827 break;
2283 case IrInstructionIdCImport:
2284 ir_print_c_import(irp, (IrInstructionCImport *)instruction);
2828 case IrInstSrcIdBoolNot:
2829 ir_print_bool_not(irp, (IrInstSrcBoolNot *)instruction);
22852830 break;
2286 case IrInstructionIdCInclude:
2287 ir_print_c_include(irp, (IrInstructionCInclude *)instruction);
2831 case IrInstSrcIdMemset:
2832 ir_print_memset(irp, (IrInstSrcMemset *)instruction);
22882833 break;
2289 case IrInstructionIdCDefine:
2290 ir_print_c_define(irp, (IrInstructionCDefine *)instruction);
2834 case IrInstSrcIdMemcpy:
2835 ir_print_memcpy(irp, (IrInstSrcMemcpy *)instruction);
22912836 break;
2292 case IrInstructionIdCUndef:
2293 ir_print_c_undef(irp, (IrInstructionCUndef *)instruction);
2837 case IrInstSrcIdSlice:
2838 ir_print_slice_src(irp, (IrInstSrcSlice *)instruction);
22942839 break;
2295 case IrInstructionIdEmbedFile:
2296 ir_print_embed_file(irp, (IrInstructionEmbedFile *)instruction);
2840 case IrInstSrcIdMemberCount:
2841 ir_print_member_count(irp, (IrInstSrcMemberCount *)instruction);
22972842 break;
2298 case IrInstructionIdCmpxchgSrc:
2299 ir_print_cmpxchg_src(irp, (IrInstructionCmpxchgSrc *)instruction);
2843 case IrInstSrcIdMemberType:
2844 ir_print_member_type(irp, (IrInstSrcMemberType *)instruction);
23002845 break;
2301 case IrInstructionIdCmpxchgGen:
2302 ir_print_cmpxchg_gen(irp, (IrInstructionCmpxchgGen *)instruction);
2846 case IrInstSrcIdMemberName:
2847 ir_print_member_name(irp, (IrInstSrcMemberName *)instruction);
23032848 break;
2304 case IrInstructionIdFence:
2305 ir_print_fence(irp, (IrInstructionFence *)instruction);
2849 case IrInstSrcIdBreakpoint:
2850 ir_print_breakpoint(irp, (IrInstSrcBreakpoint *)instruction);
23062851 break;
2307 case IrInstructionIdTruncate:
2308 ir_print_truncate(irp, (IrInstructionTruncate *)instruction);
2852 case IrInstSrcIdReturnAddress:
2853 ir_print_return_address(irp, (IrInstSrcReturnAddress *)instruction);
23092854 break;
2310 case IrInstructionIdIntCast:
2311 ir_print_int_cast(irp, (IrInstructionIntCast *)instruction);
2855 case IrInstSrcIdFrameAddress:
2856 ir_print_frame_address(irp, (IrInstSrcFrameAddress *)instruction);
23122857 break;
2313 case IrInstructionIdFloatCast:
2314 ir_print_float_cast(irp, (IrInstructionFloatCast *)instruction);
2858 case IrInstSrcIdFrameHandle:
2859 ir_print_handle(irp, (IrInstSrcFrameHandle *)instruction);
23152860 break;
2316 case IrInstructionIdErrSetCast:
2317 ir_print_err_set_cast(irp, (IrInstructionErrSetCast *)instruction);
2861 case IrInstSrcIdFrameType:
2862 ir_print_frame_type(irp, (IrInstSrcFrameType *)instruction);
23182863 break;
2319 case IrInstructionIdFromBytes:
2320 ir_print_from_bytes(irp, (IrInstructionFromBytes *)instruction);
2864 case IrInstSrcIdFrameSize:
2865 ir_print_frame_size_src(irp, (IrInstSrcFrameSize *)instruction);
23212866 break;
2322 case IrInstructionIdToBytes:
2323 ir_print_to_bytes(irp, (IrInstructionToBytes *)instruction);
2867 case IrInstSrcIdAlignOf:
2868 ir_print_align_of(irp, (IrInstSrcAlignOf *)instruction);
23242869 break;
2325 case IrInstructionIdIntToFloat:
2326 ir_print_int_to_float(irp, (IrInstructionIntToFloat *)instruction);
2870 case IrInstSrcIdOverflowOp:
2871 ir_print_overflow_op(irp, (IrInstSrcOverflowOp *)instruction);
23272872 break;
2328 case IrInstructionIdFloatToInt:
2329 ir_print_float_to_int(irp, (IrInstructionFloatToInt *)instruction);
2873 case IrInstSrcIdTestErr:
2874 ir_print_test_err_src(irp, (IrInstSrcTestErr *)instruction);
23302875 break;
2331 case IrInstructionIdBoolToInt:
2332 ir_print_bool_to_int(irp, (IrInstructionBoolToInt *)instruction);
2876 case IrInstSrcIdUnwrapErrCode:
2877 ir_print_unwrap_err_code(irp, (IrInstSrcUnwrapErrCode *)instruction);
23332878 break;
2334 case IrInstructionIdIntType:
2335 ir_print_int_type(irp, (IrInstructionIntType *)instruction);
2879 case IrInstSrcIdUnwrapErrPayload:
2880 ir_print_unwrap_err_payload(irp, (IrInstSrcUnwrapErrPayload *)instruction);
23362881 break;
2337 case IrInstructionIdVectorType:
2338 ir_print_vector_type(irp, (IrInstructionVectorType *)instruction);
2882 case IrInstSrcIdFnProto:
2883 ir_print_fn_proto(irp, (IrInstSrcFnProto *)instruction);
23392884 break;
2340 case IrInstructionIdShuffleVector:
2341 ir_print_shuffle_vector(irp, (IrInstructionShuffleVector *)instruction);
2885 case IrInstSrcIdTestComptime:
2886 ir_print_test_comptime(irp, (IrInstSrcTestComptime *)instruction);
23422887 break;
2343 case IrInstructionIdSplatSrc:
2344 ir_print_splat_src(irp, (IrInstructionSplatSrc *)instruction);
2888 case IrInstSrcIdPtrCast:
2889 ir_print_ptr_cast_src(irp, (IrInstSrcPtrCast *)instruction);
23452890 break;
2346 case IrInstructionIdSplatGen:
2347 ir_print_splat_gen(irp, (IrInstructionSplatGen *)instruction);
2891 case IrInstSrcIdBitCast:
2892 ir_print_bit_cast_src(irp, (IrInstSrcBitCast *)instruction);
23482893 break;
2349 case IrInstructionIdBoolNot:
2350 ir_print_bool_not(irp, (IrInstructionBoolNot *)instruction);
2894 case IrInstSrcIdPtrToInt:
2895 ir_print_ptr_to_int(irp, (IrInstSrcPtrToInt *)instruction);
23512896 break;
2352 case IrInstructionIdMemset:
2353 ir_print_memset(irp, (IrInstructionMemset *)instruction);
2897 case IrInstSrcIdIntToPtr:
2898 ir_print_int_to_ptr(irp, (IrInstSrcIntToPtr *)instruction);
23542899 break;
2355 case IrInstructionIdMemcpy:
2356 ir_print_memcpy(irp, (IrInstructionMemcpy *)instruction);
2900 case IrInstSrcIdIntToEnum:
2901 ir_print_int_to_enum(irp, (IrInstSrcIntToEnum *)instruction);
23572902 break;
2358 case IrInstructionIdSliceSrc:
2359 ir_print_slice_src(irp, (IrInstructionSliceSrc *)instruction);
2903 case IrInstSrcIdIntToErr:
2904 ir_print_int_to_err(irp, (IrInstSrcIntToErr *)instruction);
23602905 break;
2361 case IrInstructionIdSliceGen:
2362 ir_print_slice_gen(irp, (IrInstructionSliceGen *)instruction);
2906 case IrInstSrcIdErrToInt:
2907 ir_print_err_to_int(irp, (IrInstSrcErrToInt *)instruction);
23632908 break;
2364 case IrInstructionIdMemberCount:
2365 ir_print_member_count(irp, (IrInstructionMemberCount *)instruction);
2909 case IrInstSrcIdCheckSwitchProngs:
2910 ir_print_check_switch_prongs(irp, (IrInstSrcCheckSwitchProngs *)instruction);
23662911 break;
2367 case IrInstructionIdMemberType:
2368 ir_print_member_type(irp, (IrInstructionMemberType *)instruction);
2912 case IrInstSrcIdCheckStatementIsVoid:
2913 ir_print_check_statement_is_void(irp, (IrInstSrcCheckStatementIsVoid *)instruction);
23692914 break;
2370 case IrInstructionIdMemberName:
2371 ir_print_member_name(irp, (IrInstructionMemberName *)instruction);
2915 case IrInstSrcIdTypeName:
2916 ir_print_type_name(irp, (IrInstSrcTypeName *)instruction);
23722917 break;
2373 case IrInstructionIdBreakpoint:
2374 ir_print_breakpoint(irp, (IrInstructionBreakpoint *)instruction);
2918 case IrInstSrcIdTagName:
2919 ir_print_tag_name(irp, (IrInstSrcTagName *)instruction);
23752920 break;
2376 case IrInstructionIdReturnAddress:
2377 ir_print_return_address(irp, (IrInstructionReturnAddress *)instruction);
2921 case IrInstSrcIdPtrType:
2922 ir_print_ptr_type(irp, (IrInstSrcPtrType *)instruction);
23782923 break;
2379 case IrInstructionIdFrameAddress:
2380 ir_print_frame_address(irp, (IrInstructionFrameAddress *)instruction);
2924 case IrInstSrcIdDeclRef:
2925 ir_print_decl_ref(irp, (IrInstSrcDeclRef *)instruction);
23812926 break;
2382 case IrInstructionIdFrameHandle:
2383 ir_print_handle(irp, (IrInstructionFrameHandle *)instruction);
2927 case IrInstSrcIdPanic:
2928 ir_print_panic(irp, (IrInstSrcPanic *)instruction);
23842929 break;
2385 case IrInstructionIdFrameType:
2386 ir_print_frame_type(irp, (IrInstructionFrameType *)instruction);
2930 case IrInstSrcIdFieldParentPtr:
2931 ir_print_field_parent_ptr(irp, (IrInstSrcFieldParentPtr *)instruction);
23872932 break;
2388 case IrInstructionIdFrameSizeSrc:
2389 ir_print_frame_size_src(irp, (IrInstructionFrameSizeSrc *)instruction);
2933 case IrInstSrcIdByteOffsetOf:
2934 ir_print_byte_offset_of(irp, (IrInstSrcByteOffsetOf *)instruction);
23902935 break;
2391 case IrInstructionIdFrameSizeGen:
2392 ir_print_frame_size_gen(irp, (IrInstructionFrameSizeGen *)instruction);
2936 case IrInstSrcIdBitOffsetOf:
2937 ir_print_bit_offset_of(irp, (IrInstSrcBitOffsetOf *)instruction);
23932938 break;
2394 case IrInstructionIdAlignOf:
2395 ir_print_align_of(irp, (IrInstructionAlignOf *)instruction);
2939 case IrInstSrcIdTypeInfo:
2940 ir_print_type_info(irp, (IrInstSrcTypeInfo *)instruction);
23962941 break;
2397 case IrInstructionIdOverflowOp:
2398 ir_print_overflow_op(irp, (IrInstructionOverflowOp *)instruction);
2942 case IrInstSrcIdType:
2943 ir_print_type(irp, (IrInstSrcType *)instruction);
23992944 break;
2400 case IrInstructionIdTestErrSrc:
2401 ir_print_test_err_src(irp, (IrInstructionTestErrSrc *)instruction);
2945 case IrInstSrcIdHasField:
2946 ir_print_has_field(irp, (IrInstSrcHasField *)instruction);
24022947 break;
2403 case IrInstructionIdTestErrGen:
2404 ir_print_test_err_gen(irp, (IrInstructionTestErrGen *)instruction);
2948 case IrInstSrcIdTypeId:
2949 ir_print_type_id(irp, (IrInstSrcTypeId *)instruction);
24052950 break;
2406 case IrInstructionIdUnwrapErrCode:
2407 ir_print_unwrap_err_code(irp, (IrInstructionUnwrapErrCode *)instruction);
2951 case IrInstSrcIdSetEvalBranchQuota:
2952 ir_print_set_eval_branch_quota(irp, (IrInstSrcSetEvalBranchQuota *)instruction);
24082953 break;
2409 case IrInstructionIdUnwrapErrPayload:
2410 ir_print_unwrap_err_payload(irp, (IrInstructionUnwrapErrPayload *)instruction);
2954 case IrInstSrcIdAlignCast:
2955 ir_print_align_cast(irp, (IrInstSrcAlignCast *)instruction);
24112956 break;
2412 case IrInstructionIdOptionalWrap:
2413 ir_print_optional_wrap(irp, (IrInstructionOptionalWrap *)instruction);
2957 case IrInstSrcIdImplicitCast:
2958 ir_print_implicit_cast(irp, (IrInstSrcImplicitCast *)instruction);
24142959 break;
2415 case IrInstructionIdErrWrapCode:
2416 ir_print_err_wrap_code(irp, (IrInstructionErrWrapCode *)instruction);
2960 case IrInstSrcIdResolveResult:
2961 ir_print_resolve_result(irp, (IrInstSrcResolveResult *)instruction);
24172962 break;
2418 case IrInstructionIdErrWrapPayload:
2419 ir_print_err_wrap_payload(irp, (IrInstructionErrWrapPayload *)instruction);
2963 case IrInstSrcIdResetResult:
2964 ir_print_reset_result(irp, (IrInstSrcResetResult *)instruction);
24202965 break;
2421 case IrInstructionIdFnProto:
2422 ir_print_fn_proto(irp, (IrInstructionFnProto *)instruction);
2966 case IrInstSrcIdOpaqueType:
2967 ir_print_opaque_type(irp, (IrInstSrcOpaqueType *)instruction);
24232968 break;
2424 case IrInstructionIdTestComptime:
2425 ir_print_test_comptime(irp, (IrInstructionTestComptime *)instruction);
2969 case IrInstSrcIdSetAlignStack:
2970 ir_print_set_align_stack(irp, (IrInstSrcSetAlignStack *)instruction);
24262971 break;
2427 case IrInstructionIdPtrCastSrc:
2428 ir_print_ptr_cast_src(irp, (IrInstructionPtrCastSrc *)instruction);
2972 case IrInstSrcIdArgType:
2973 ir_print_arg_type(irp, (IrInstSrcArgType *)instruction);
24292974 break;
2430 case IrInstructionIdPtrCastGen:
2431 ir_print_ptr_cast_gen(irp, (IrInstructionPtrCastGen *)instruction);
2975 case IrInstSrcIdTagType:
2976 ir_print_enum_tag_type(irp, (IrInstSrcTagType *)instruction);
24322977 break;
2433 case IrInstructionIdBitCastSrc:
2434 ir_print_bit_cast_src(irp, (IrInstructionBitCastSrc *)instruction);
2978 case IrInstSrcIdExport:
2979 ir_print_export(irp, (IrInstSrcExport *)instruction);
24352980 break;
2436 case IrInstructionIdBitCastGen:
2437 ir_print_bit_cast_gen(irp, (IrInstructionBitCastGen *)instruction);
2981 case IrInstSrcIdErrorReturnTrace:
2982 ir_print_error_return_trace(irp, (IrInstSrcErrorReturnTrace *)instruction);
24382983 break;
2439 case IrInstructionIdWidenOrShorten:
2440 ir_print_widen_or_shorten(irp, (IrInstructionWidenOrShorten *)instruction);
2984 case IrInstSrcIdErrorUnion:
2985 ir_print_error_union(irp, (IrInstSrcErrorUnion *)instruction);
24412986 break;
2442 case IrInstructionIdPtrToInt:
2443 ir_print_ptr_to_int(irp, (IrInstructionPtrToInt *)instruction);
2987 case IrInstSrcIdAtomicRmw:
2988 ir_print_atomic_rmw(irp, (IrInstSrcAtomicRmw *)instruction);
24442989 break;
2445 case IrInstructionIdIntToPtr:
2446 ir_print_int_to_ptr(irp, (IrInstructionIntToPtr *)instruction);
2990 case IrInstSrcIdSaveErrRetAddr:
2991 ir_print_save_err_ret_addr(irp, (IrInstSrcSaveErrRetAddr *)instruction);
2992 break;
2993 case IrInstSrcIdAddImplicitReturnType:
2994 ir_print_add_implicit_return_type(irp, (IrInstSrcAddImplicitReturnType *)instruction);
2995 break;
2996 case IrInstSrcIdFloatOp:
2997 ir_print_float_op(irp, (IrInstSrcFloatOp *)instruction);
2998 break;
2999 case IrInstSrcIdMulAdd:
3000 ir_print_mul_add(irp, (IrInstSrcMulAdd *)instruction);
3001 break;
3002 case IrInstSrcIdAtomicLoad:
3003 ir_print_atomic_load(irp, (IrInstSrcAtomicLoad *)instruction);
3004 break;
3005 case IrInstSrcIdAtomicStore:
3006 ir_print_atomic_store(irp, (IrInstSrcAtomicStore *)instruction);
3007 break;
3008 case IrInstSrcIdEnumToInt:
3009 ir_print_enum_to_int(irp, (IrInstSrcEnumToInt *)instruction);
3010 break;
3011 case IrInstSrcIdCheckRuntimeScope:
3012 ir_print_check_runtime_scope(irp, (IrInstSrcCheckRuntimeScope *)instruction);
3013 break;
3014 case IrInstSrcIdHasDecl:
3015 ir_print_has_decl(irp, (IrInstSrcHasDecl *)instruction);
3016 break;
3017 case IrInstSrcIdUndeclaredIdent:
3018 ir_print_undeclared_ident(irp, (IrInstSrcUndeclaredIdent *)instruction);
3019 break;
3020 case IrInstSrcIdAlloca:
3021 ir_print_alloca_src(irp, (IrInstSrcAlloca *)instruction);
3022 break;
3023 case IrInstSrcIdEndExpr:
3024 ir_print_end_expr(irp, (IrInstSrcEndExpr *)instruction);
3025 break;
3026 case IrInstSrcIdUnionInitNamedField:
3027 ir_print_union_init_named_field(irp, (IrInstSrcUnionInitNamedField *)instruction);
3028 break;
3029 case IrInstSrcIdSuspendBegin:
3030 ir_print_suspend_begin(irp, (IrInstSrcSuspendBegin *)instruction);
3031 break;
3032 case IrInstSrcIdSuspendFinish:
3033 ir_print_suspend_finish(irp, (IrInstSrcSuspendFinish *)instruction);
3034 break;
3035 case IrInstSrcIdResume:
3036 ir_print_resume(irp, (IrInstSrcResume *)instruction);
3037 break;
3038 case IrInstSrcIdAwait:
3039 ir_print_await_src(irp, (IrInstSrcAwait *)instruction);
3040 break;
3041 case IrInstSrcIdSpillBegin:
3042 ir_print_spill_begin(irp, (IrInstSrcSpillBegin *)instruction);
3043 break;
3044 case IrInstSrcIdSpillEnd:
3045 ir_print_spill_end(irp, (IrInstSrcSpillEnd *)instruction);
3046 break;
3047 case IrInstSrcIdClz:
3048 ir_print_clz(irp, (IrInstSrcClz *)instruction);
3049 break;
3050 }
3051 fprintf(irp->f, "\n");
3052}
3053
3054static void ir_print_inst_gen(IrPrintGen *irp, IrInstGen *instruction, bool trailing) {
3055 ir_print_prefix_gen(irp, instruction, trailing);
3056 switch (instruction->id) {
3057 case IrInstGenIdInvalid:
3058 zig_unreachable();
3059 case IrInstGenIdReturn:
3060 ir_print_return_gen(irp, (IrInstGenReturn *)instruction);
24473061 break;
2448 case IrInstructionIdIntToEnum:
2449 ir_print_int_to_enum(irp, (IrInstructionIntToEnum *)instruction);
3062 case IrInstGenIdConst:
3063 ir_print_const(irp, (IrInstGenConst *)instruction);
24503064 break;
2451 case IrInstructionIdIntToErr:
2452 ir_print_int_to_err(irp, (IrInstructionIntToErr *)instruction);
3065 case IrInstGenIdBinOp:
3066 ir_print_bin_op(irp, (IrInstGenBinOp *)instruction);
24533067 break;
2454 case IrInstructionIdErrToInt:
2455 ir_print_err_to_int(irp, (IrInstructionErrToInt *)instruction);
3068 case IrInstGenIdDeclVar:
3069 ir_print_decl_var_gen(irp, (IrInstGenDeclVar *)instruction);
24563070 break;
2457 case IrInstructionIdCheckSwitchProngs:
2458 ir_print_check_switch_prongs(irp, (IrInstructionCheckSwitchProngs *)instruction);
3071 case IrInstGenIdCast:
3072 ir_print_cast(irp, (IrInstGenCast *)instruction);
24593073 break;
2460 case IrInstructionIdCheckStatementIsVoid:
2461 ir_print_check_statement_is_void(irp, (IrInstructionCheckStatementIsVoid *)instruction);
3074 case IrInstGenIdCall:
3075 ir_print_call_gen(irp, (IrInstGenCall *)instruction);
24623076 break;
2463 case IrInstructionIdTypeName:
2464 ir_print_type_name(irp, (IrInstructionTypeName *)instruction);
3077 case IrInstGenIdCondBr:
3078 ir_print_cond_br(irp, (IrInstGenCondBr *)instruction);
24653079 break;
2466 case IrInstructionIdTagName:
2467 ir_print_tag_name(irp, (IrInstructionTagName *)instruction);
3080 case IrInstGenIdBr:
3081 ir_print_br(irp, (IrInstGenBr *)instruction);
24683082 break;
2469 case IrInstructionIdPtrType:
2470 ir_print_ptr_type(irp, (IrInstructionPtrType *)instruction);
3083 case IrInstGenIdPhi:
3084 ir_print_phi(irp, (IrInstGenPhi *)instruction);
24713085 break;
2472 case IrInstructionIdDeclRef:
2473 ir_print_decl_ref(irp, (IrInstructionDeclRef *)instruction);
3086 case IrInstGenIdUnreachable:
3087 ir_print_unreachable(irp, (IrInstGenUnreachable *)instruction);
24743088 break;
2475 case IrInstructionIdPanic:
2476 ir_print_panic(irp, (IrInstructionPanic *)instruction);
3089 case IrInstGenIdElemPtr:
3090 ir_print_elem_ptr(irp, (IrInstGenElemPtr *)instruction);
24773091 break;
2478 case IrInstructionIdFieldParentPtr:
2479 ir_print_field_parent_ptr(irp, (IrInstructionFieldParentPtr *)instruction);
3092 case IrInstGenIdVarPtr:
3093 ir_print_var_ptr(irp, (IrInstGenVarPtr *)instruction);
24803094 break;
2481 case IrInstructionIdByteOffsetOf:
2482 ir_print_byte_offset_of(irp, (IrInstructionByteOffsetOf *)instruction);
3095 case IrInstGenIdReturnPtr:
3096 ir_print_return_ptr(irp, (IrInstGenReturnPtr *)instruction);
24833097 break;
2484 case IrInstructionIdBitOffsetOf:
2485 ir_print_bit_offset_of(irp, (IrInstructionBitOffsetOf *)instruction);
3098 case IrInstGenIdLoadPtr:
3099 ir_print_load_ptr_gen(irp, (IrInstGenLoadPtr *)instruction);
24863100 break;
2487 case IrInstructionIdTypeInfo:
2488 ir_print_type_info(irp, (IrInstructionTypeInfo *)instruction);
3101 case IrInstGenIdStorePtr:
3102 ir_print_store_ptr(irp, (IrInstGenStorePtr *)instruction);
24893103 break;
2490 case IrInstructionIdType:
2491 ir_print_type(irp, (IrInstructionType *)instruction);
3104 case IrInstGenIdStructFieldPtr:
3105 ir_print_struct_field_ptr(irp, (IrInstGenStructFieldPtr *)instruction);
24923106 break;
2493 case IrInstructionIdHasField:
2494 ir_print_has_field(irp, (IrInstructionHasField *)instruction);
3107 case IrInstGenIdUnionFieldPtr:
3108 ir_print_union_field_ptr(irp, (IrInstGenUnionFieldPtr *)instruction);
24953109 break;
2496 case IrInstructionIdTypeId:
2497 ir_print_type_id(irp, (IrInstructionTypeId *)instruction);
3110 case IrInstGenIdAsm:
3111 ir_print_asm_gen(irp, (IrInstGenAsm *)instruction);
24983112 break;
2499 case IrInstructionIdSetEvalBranchQuota:
2500 ir_print_set_eval_branch_quota(irp, (IrInstructionSetEvalBranchQuota *)instruction);
3113 case IrInstGenIdTestNonNull:
3114 ir_print_test_non_null(irp, (IrInstGenTestNonNull *)instruction);
25013115 break;
2502 case IrInstructionIdAlignCast:
2503 ir_print_align_cast(irp, (IrInstructionAlignCast *)instruction);
3116 case IrInstGenIdOptionalUnwrapPtr:
3117 ir_print_optional_unwrap_ptr(irp, (IrInstGenOptionalUnwrapPtr *)instruction);
25043118 break;
2505 case IrInstructionIdImplicitCast:
2506 ir_print_implicit_cast(irp, (IrInstructionImplicitCast *)instruction);
3119 case IrInstGenIdPopCount:
3120 ir_print_pop_count(irp, (IrInstGenPopCount *)instruction);
25073121 break;
2508 case IrInstructionIdResolveResult:
2509 ir_print_resolve_result(irp, (IrInstructionResolveResult *)instruction);
3122 case IrInstGenIdClz:
3123 ir_print_clz(irp, (IrInstGenClz *)instruction);
25103124 break;
2511 case IrInstructionIdResetResult:
2512 ir_print_reset_result(irp, (IrInstructionResetResult *)instruction);
3125 case IrInstGenIdCtz:
3126 ir_print_ctz(irp, (IrInstGenCtz *)instruction);
25133127 break;
2514 case IrInstructionIdOpaqueType:
2515 ir_print_opaque_type(irp, (IrInstructionOpaqueType *)instruction);
3128 case IrInstGenIdBswap:
3129 ir_print_bswap(irp, (IrInstGenBswap *)instruction);
25163130 break;
2517 case IrInstructionIdSetAlignStack:
2518 ir_print_set_align_stack(irp, (IrInstructionSetAlignStack *)instruction);
3131 case IrInstGenIdBitReverse:
3132 ir_print_bit_reverse(irp, (IrInstGenBitReverse *)instruction);
25193133 break;
2520 case IrInstructionIdArgType:
2521 ir_print_arg_type(irp, (IrInstructionArgType *)instruction);
3134 case IrInstGenIdSwitchBr:
3135 ir_print_switch_br(irp, (IrInstGenSwitchBr *)instruction);
25223136 break;
2523 case IrInstructionIdTagType:
2524 ir_print_enum_tag_type(irp, (IrInstructionTagType *)instruction);
3137 case IrInstGenIdUnionTag:
3138 ir_print_union_tag(irp, (IrInstGenUnionTag *)instruction);
25253139 break;
2526 case IrInstructionIdExport:
2527 ir_print_export(irp, (IrInstructionExport *)instruction);
3140 case IrInstGenIdRef:
3141 ir_print_ref_gen(irp, (IrInstGenRef *)instruction);
25283142 break;
2529 case IrInstructionIdErrorReturnTrace:
2530 ir_print_error_return_trace(irp, (IrInstructionErrorReturnTrace *)instruction);
3143 case IrInstGenIdErrName:
3144 ir_print_err_name(irp, (IrInstGenErrName *)instruction);
25313145 break;
2532 case IrInstructionIdErrorUnion:
2533 ir_print_error_union(irp, (IrInstructionErrorUnion *)instruction);
3146 case IrInstGenIdCmpxchg:
3147 ir_print_cmpxchg_gen(irp, (IrInstGenCmpxchg *)instruction);
25343148 break;
2535 case IrInstructionIdAtomicRmw:
2536 ir_print_atomic_rmw(irp, (IrInstructionAtomicRmw *)instruction);
3149 case IrInstGenIdFence:
3150 ir_print_fence(irp, (IrInstGenFence *)instruction);
25373151 break;
2538 case IrInstructionIdSaveErrRetAddr:
2539 ir_print_save_err_ret_addr(irp, (IrInstructionSaveErrRetAddr *)instruction);
3152 case IrInstGenIdTruncate:
3153 ir_print_truncate(irp, (IrInstGenTruncate *)instruction);
25403154 break;
2541 case IrInstructionIdAddImplicitReturnType:
2542 ir_print_add_implicit_return_type(irp, (IrInstructionAddImplicitReturnType *)instruction);
3155 case IrInstGenIdShuffleVector:
3156 ir_print_shuffle_vector(irp, (IrInstGenShuffleVector *)instruction);
25433157 break;
2544 case IrInstructionIdFloatOp:
2545 ir_print_float_op(irp, (IrInstructionFloatOp *)instruction);
3158 case IrInstGenIdSplat:
3159 ir_print_splat_gen(irp, (IrInstGenSplat *)instruction);
25463160 break;
2547 case IrInstructionIdMulAdd:
2548 ir_print_mul_add(irp, (IrInstructionMulAdd *)instruction);
3161 case IrInstGenIdBoolNot:
3162 ir_print_bool_not(irp, (IrInstGenBoolNot *)instruction);
25493163 break;
2550 case IrInstructionIdAtomicLoad:
2551 ir_print_atomic_load(irp, (IrInstructionAtomicLoad *)instruction);
3164 case IrInstGenIdMemset:
3165 ir_print_memset(irp, (IrInstGenMemset *)instruction);
25523166 break;
2553 case IrInstructionIdAtomicStore:
2554 ir_print_atomic_store(irp, (IrInstructionAtomicStore *)instruction);
3167 case IrInstGenIdMemcpy:
3168 ir_print_memcpy(irp, (IrInstGenMemcpy *)instruction);
25553169 break;
2556 case IrInstructionIdEnumToInt:
2557 ir_print_enum_to_int(irp, (IrInstructionEnumToInt *)instruction);
3170 case IrInstGenIdSlice:
3171 ir_print_slice_gen(irp, (IrInstGenSlice *)instruction);
25583172 break;
2559 case IrInstructionIdCheckRuntimeScope:
2560 ir_print_check_runtime_scope(irp, (IrInstructionCheckRuntimeScope *)instruction);
3173 case IrInstGenIdBreakpoint:
3174 ir_print_breakpoint(irp, (IrInstGenBreakpoint *)instruction);
25613175 break;
2562 case IrInstructionIdDeclVarGen:
2563 ir_print_decl_var_gen(irp, (IrInstructionDeclVarGen *)instruction);
3176 case IrInstGenIdReturnAddress:
3177 ir_print_return_address(irp, (IrInstGenReturnAddress *)instruction);
25643178 break;
2565 case IrInstructionIdArrayToVector:
2566 ir_print_array_to_vector(irp, (IrInstructionArrayToVector *)instruction);
3179 case IrInstGenIdFrameAddress:
3180 ir_print_frame_address(irp, (IrInstGenFrameAddress *)instruction);
25673181 break;
2568 case IrInstructionIdVectorToArray:
2569 ir_print_vector_to_array(irp, (IrInstructionVectorToArray *)instruction);
3182 case IrInstGenIdFrameHandle:
3183 ir_print_handle(irp, (IrInstGenFrameHandle *)instruction);
25703184 break;
2571 case IrInstructionIdPtrOfArrayToSlice:
2572 ir_print_ptr_of_array_to_slice(irp, (IrInstructionPtrOfArrayToSlice *)instruction);
3185 case IrInstGenIdFrameSize:
3186 ir_print_frame_size_gen(irp, (IrInstGenFrameSize *)instruction);
25733187 break;
2574 case IrInstructionIdAssertZero:
2575 ir_print_assert_zero(irp, (IrInstructionAssertZero *)instruction);
3188 case IrInstGenIdOverflowOp:
3189 ir_print_overflow_op(irp, (IrInstGenOverflowOp *)instruction);
25763190 break;
2577 case IrInstructionIdAssertNonNull:
2578 ir_print_assert_non_null(irp, (IrInstructionAssertNonNull *)instruction);
3191 case IrInstGenIdTestErr:
3192 ir_print_test_err_gen(irp, (IrInstGenTestErr *)instruction);
25793193 break;
2580 case IrInstructionIdResizeSlice:
2581 ir_print_resize_slice(irp, (IrInstructionResizeSlice *)instruction);
3194 case IrInstGenIdUnwrapErrCode:
3195 ir_print_unwrap_err_code(irp, (IrInstGenUnwrapErrCode *)instruction);
25823196 break;
2583 case IrInstructionIdHasDecl:
2584 ir_print_has_decl(irp, (IrInstructionHasDecl *)instruction);
3197 case IrInstGenIdUnwrapErrPayload:
3198 ir_print_unwrap_err_payload(irp, (IrInstGenUnwrapErrPayload *)instruction);
25853199 break;
2586 case IrInstructionIdUndeclaredIdent:
2587 ir_print_undeclared_ident(irp, (IrInstructionUndeclaredIdent *)instruction);
3200 case IrInstGenIdOptionalWrap:
3201 ir_print_optional_wrap(irp, (IrInstGenOptionalWrap *)instruction);
25883202 break;
2589 case IrInstructionIdAllocaSrc:
2590 ir_print_alloca_src(irp, (IrInstructionAllocaSrc *)instruction);
3203 case IrInstGenIdErrWrapCode:
3204 ir_print_err_wrap_code(irp, (IrInstGenErrWrapCode *)instruction);
25913205 break;
2592 case IrInstructionIdAllocaGen:
2593 ir_print_alloca_gen(irp, (IrInstructionAllocaGen *)instruction);
3206 case IrInstGenIdErrWrapPayload:
3207 ir_print_err_wrap_payload(irp, (IrInstGenErrWrapPayload *)instruction);
25943208 break;
2595 case IrInstructionIdEndExpr:
2596 ir_print_end_expr(irp, (IrInstructionEndExpr *)instruction);
3209 case IrInstGenIdPtrCast:
3210 ir_print_ptr_cast_gen(irp, (IrInstGenPtrCast *)instruction);
25973211 break;
2598 case IrInstructionIdUnionInitNamedField:
2599 ir_print_union_init_named_field(irp, (IrInstructionUnionInitNamedField *)instruction);
3212 case IrInstGenIdBitCast:
3213 ir_print_bit_cast_gen(irp, (IrInstGenBitCast *)instruction);
26003214 break;
2601 case IrInstructionIdSuspendBegin:
2602 ir_print_suspend_begin(irp, (IrInstructionSuspendBegin *)instruction);
3215 case IrInstGenIdWidenOrShorten:
3216 ir_print_widen_or_shorten(irp, (IrInstGenWidenOrShorten *)instruction);
26033217 break;
2604 case IrInstructionIdSuspendFinish:
2605 ir_print_suspend_finish(irp, (IrInstructionSuspendFinish *)instruction);
3218 case IrInstGenIdPtrToInt:
3219 ir_print_ptr_to_int(irp, (IrInstGenPtrToInt *)instruction);
26063220 break;
2607 case IrInstructionIdResume:
2608 ir_print_resume(irp, (IrInstructionResume *)instruction);
3221 case IrInstGenIdIntToPtr:
3222 ir_print_int_to_ptr(irp, (IrInstGenIntToPtr *)instruction);
26093223 break;
2610 case IrInstructionIdAwaitSrc:
2611 ir_print_await_src(irp, (IrInstructionAwaitSrc *)instruction);
3224 case IrInstGenIdIntToEnum:
3225 ir_print_int_to_enum(irp, (IrInstGenIntToEnum *)instruction);
26123226 break;
2613 case IrInstructionIdAwaitGen:
2614 ir_print_await_gen(irp, (IrInstructionAwaitGen *)instruction);
3227 case IrInstGenIdIntToErr:
3228 ir_print_int_to_err(irp, (IrInstGenIntToErr *)instruction);
26153229 break;
2616 case IrInstructionIdSpillBegin:
2617 ir_print_spill_begin(irp, (IrInstructionSpillBegin *)instruction);
3230 case IrInstGenIdErrToInt:
3231 ir_print_err_to_int(irp, (IrInstGenErrToInt *)instruction);
26183232 break;
2619 case IrInstructionIdSpillEnd:
2620 ir_print_spill_end(irp, (IrInstructionSpillEnd *)instruction);
3233 case IrInstGenIdTagName:
3234 ir_print_tag_name(irp, (IrInstGenTagName *)instruction);
26213235 break;
2622 case IrInstructionIdVectorExtractElem:
2623 ir_print_vector_extract_elem(irp, (IrInstructionVectorExtractElem *)instruction);
3236 case IrInstGenIdPanic:
3237 ir_print_panic(irp, (IrInstGenPanic *)instruction);
3238 break;
3239 case IrInstGenIdFieldParentPtr:
3240 ir_print_field_parent_ptr(irp, (IrInstGenFieldParentPtr *)instruction);
3241 break;
3242 case IrInstGenIdAlignCast:
3243 ir_print_align_cast(irp, (IrInstGenAlignCast *)instruction);
3244 break;
3245 case IrInstGenIdErrorReturnTrace:
3246 ir_print_error_return_trace(irp, (IrInstGenErrorReturnTrace *)instruction);
3247 break;
3248 case IrInstGenIdAtomicRmw:
3249 ir_print_atomic_rmw(irp, (IrInstGenAtomicRmw *)instruction);
3250 break;
3251 case IrInstGenIdSaveErrRetAddr:
3252 ir_print_save_err_ret_addr(irp, (IrInstGenSaveErrRetAddr *)instruction);
3253 break;
3254 case IrInstGenIdFloatOp:
3255 ir_print_float_op(irp, (IrInstGenFloatOp *)instruction);
3256 break;
3257 case IrInstGenIdMulAdd:
3258 ir_print_mul_add(irp, (IrInstGenMulAdd *)instruction);
3259 break;
3260 case IrInstGenIdAtomicLoad:
3261 ir_print_atomic_load(irp, (IrInstGenAtomicLoad *)instruction);
3262 break;
3263 case IrInstGenIdAtomicStore:
3264 ir_print_atomic_store(irp, (IrInstGenAtomicStore *)instruction);
3265 break;
3266 case IrInstGenIdArrayToVector:
3267 ir_print_array_to_vector(irp, (IrInstGenArrayToVector *)instruction);
3268 break;
3269 case IrInstGenIdVectorToArray:
3270 ir_print_vector_to_array(irp, (IrInstGenVectorToArray *)instruction);
3271 break;
3272 case IrInstGenIdPtrOfArrayToSlice:
3273 ir_print_ptr_of_array_to_slice(irp, (IrInstGenPtrOfArrayToSlice *)instruction);
3274 break;
3275 case IrInstGenIdAssertZero:
3276 ir_print_assert_zero(irp, (IrInstGenAssertZero *)instruction);
3277 break;
3278 case IrInstGenIdAssertNonNull:
3279 ir_print_assert_non_null(irp, (IrInstGenAssertNonNull *)instruction);
3280 break;
3281 case IrInstGenIdResizeSlice:
3282 ir_print_resize_slice(irp, (IrInstGenResizeSlice *)instruction);
3283 break;
3284 case IrInstGenIdAlloca:
3285 ir_print_alloca_gen(irp, (IrInstGenAlloca *)instruction);
3286 break;
3287 case IrInstGenIdSuspendBegin:
3288 ir_print_suspend_begin(irp, (IrInstGenSuspendBegin *)instruction);
3289 break;
3290 case IrInstGenIdSuspendFinish:
3291 ir_print_suspend_finish(irp, (IrInstGenSuspendFinish *)instruction);
3292 break;
3293 case IrInstGenIdResume:
3294 ir_print_resume(irp, (IrInstGenResume *)instruction);
3295 break;
3296 case IrInstGenIdAwait:
3297 ir_print_await_gen(irp, (IrInstGenAwait *)instruction);
3298 break;
3299 case IrInstGenIdSpillBegin:
3300 ir_print_spill_begin(irp, (IrInstGenSpillBegin *)instruction);
3301 break;
3302 case IrInstGenIdSpillEnd:
3303 ir_print_spill_end(irp, (IrInstGenSpillEnd *)instruction);
3304 break;
3305 case IrInstGenIdVectorExtractElem:
3306 ir_print_vector_extract_elem(irp, (IrInstGenVectorExtractElem *)instruction);
3307 break;
3308 case IrInstGenIdVectorStoreElem:
3309 ir_print_vector_store_elem(irp, (IrInstGenVectorStoreElem *)instruction);
3310 break;
3311 case IrInstGenIdBinaryNot:
3312 ir_print_binary_not(irp, (IrInstGenBinaryNot *)instruction);
3313 break;
3314 case IrInstGenIdNegation:
3315 ir_print_negation(irp, (IrInstGenNegation *)instruction);
3316 break;
3317 case IrInstGenIdNegationWrapping:
3318 ir_print_negation_wrapping(irp, (IrInstGenNegationWrapping *)instruction);
26243319 break;
26253320 }
26263321 fprintf(irp->f, "\n");
26273322}
26283323
2629static void irp_print_basic_block(IrPrint *irp, IrBasicBlock *current_block) {
2630 fprintf(irp->f, "%s_%" ZIG_PRI_usize ":\n", current_block->name_hint, current_block->debug_id);
3324static void irp_print_basic_block_src(IrPrintSrc *irp, IrBasicBlockSrc *current_block) {
3325 fprintf(irp->f, "%s_%" PRIu32 ":\n", current_block->name_hint, current_block->debug_id);
26313326 for (size_t instr_i = 0; instr_i < current_block->instruction_list.length; instr_i += 1) {
2632 IrInstruction *instruction = current_block->instruction_list.at(instr_i);
2633 if (irp->pass != IrPassSrc) {
2634 irp->printed.put(instruction, 0);
2635 irp->pending.clear();
2636 }
2637 ir_print_instruction(irp, instruction, false);
3327 IrInstSrc *instruction = current_block->instruction_list.at(instr_i);
3328 ir_print_inst_src(irp, instruction, false);
3329 }
3330}
3331
3332static void irp_print_basic_block_gen(IrPrintGen *irp, IrBasicBlockGen *current_block) {
3333 fprintf(irp->f, "%s_%" PRIu32 ":\n", current_block->name_hint, current_block->debug_id);
3334 for (size_t instr_i = 0; instr_i < current_block->instruction_list.length; instr_i += 1) {
3335 IrInstGen *instruction = current_block->instruction_list.at(instr_i);
3336 irp->printed.put(instruction, 0);
3337 irp->pending.clear();
3338 ir_print_inst_gen(irp, instruction, false);
26383339 for (size_t j = 0; j < irp->pending.length; ++j)
2639 ir_print_instruction(irp, irp->pending.at(j), true);
3340 ir_print_inst_gen(irp, irp->pending.at(j), true);
26403341 }
26413342}
26423343
2643void ir_print_basic_block(CodeGen *codegen, FILE *f, IrBasicBlock *bb, int indent_size, IrPass pass) {
2644 IrPrint ir_print = {};
2645 ir_print.pass = pass;
3344void ir_print_basic_block_src(CodeGen *codegen, FILE *f, IrBasicBlockSrc *bb, int indent_size) {
3345 IrPrintSrc ir_print = {};
3346 ir_print.codegen = codegen;
3347 ir_print.f = f;
3348 ir_print.indent = indent_size;
3349 ir_print.indent_size = indent_size;
3350
3351 irp_print_basic_block_src(&ir_print, bb);
3352}
3353
3354void ir_print_basic_block_gen(CodeGen *codegen, FILE *f, IrBasicBlockGen *bb, int indent_size) {
3355 IrPrintGen ir_print = {};
26463356 ir_print.codegen = codegen;
26473357 ir_print.f = f;
26483358 ir_print.indent = indent_size;
......@@ -2651,16 +3361,28 @@ void ir_print_basic_block(CodeGen *codegen, FILE *f, IrBasicBlock *bb, int inden
26513361 ir_print.printed.init(64);
26523362 ir_print.pending = {};
26533363
2654 irp_print_basic_block(&ir_print, bb);
3364 irp_print_basic_block_gen(&ir_print, bb);
26553365
26563366 ir_print.pending.deinit();
26573367 ir_print.printed.deinit();
26583368}
26593369
2660void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_size, IrPass pass) {
2661 IrPrint ir_print = {};
2662 IrPrint *irp = &ir_print;
2663 irp->pass = pass;
3370void ir_print_src(CodeGen *codegen, FILE *f, IrExecutableSrc *executable, int indent_size) {
3371 IrPrintSrc ir_print = {};
3372 IrPrintSrc *irp = &ir_print;
3373 irp->codegen = codegen;
3374 irp->f = f;
3375 irp->indent = indent_size;
3376 irp->indent_size = indent_size;
3377
3378 for (size_t bb_i = 0; bb_i < executable->basic_block_list.length; bb_i += 1) {
3379 irp_print_basic_block_src(irp, executable->basic_block_list.at(bb_i));
3380 }
3381}
3382
3383void ir_print_gen(CodeGen *codegen, FILE *f, IrExecutableGen *executable, int indent_size) {
3384 IrPrintGen ir_print = {};
3385 IrPrintGen *irp = &ir_print;
26643386 irp->codegen = codegen;
26653387 irp->f = f;
26663388 irp->indent = indent_size;
......@@ -2670,32 +3392,27 @@ void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_si
26703392 irp->pending = {};
26713393
26723394 for (size_t bb_i = 0; bb_i < executable->basic_block_list.length; bb_i += 1) {
2673 irp_print_basic_block(irp, executable->basic_block_list.at(bb_i));
3395 irp_print_basic_block_gen(irp, executable->basic_block_list.at(bb_i));
26743396 }
26753397
26763398 irp->pending.deinit();
26773399 irp->printed.deinit();
26783400}
26793401
2680void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction, int indent_size, IrPass pass) {
2681 IrPrint ir_print = {};
2682 IrPrint *irp = &ir_print;
2683 irp->pass = pass;
3402void ir_print_inst_src(CodeGen *codegen, FILE *f, IrInstSrc *instruction, int indent_size) {
3403 IrPrintSrc ir_print = {};
3404 IrPrintSrc *irp = &ir_print;
26843405 irp->codegen = codegen;
26853406 irp->f = f;
26863407 irp->indent = indent_size;
26873408 irp->indent_size = indent_size;
2688 irp->printed = {};
2689 irp->printed.init(4);
2690 irp->pending = {};
26913409
2692 ir_print_instruction(irp, instruction, false);
3410 ir_print_inst_src(irp, instruction, false);
26933411}
26943412
2695void ir_print_const_expr(CodeGen *codegen, FILE *f, ZigValue *value, int indent_size, IrPass pass) {
2696 IrPrint ir_print = {};
2697 IrPrint *irp = &ir_print;
2698 irp->pass = pass;
3413void ir_print_inst_gen(CodeGen *codegen, FILE *f, IrInstGen *instruction, int indent_size) {
3414 IrPrintGen ir_print = {};
3415 IrPrintGen *irp = &ir_print;
26993416 irp->codegen = codegen;
27003417 irp->f = f;
27013418 irp->indent = indent_size;
......@@ -2704,5 +3421,5 @@ void ir_print_const_expr(CodeGen *codegen, FILE *f, ZigValue *value, int indent_
27043421 irp->printed.init(4);
27053422 irp->pending = {};
27063423
2707 ir_print_const_value(irp, value);
3424 ir_print_inst_gen(irp, instruction, false);
27083425}
src/ir_print.hpp+8-5
......@@ -12,11 +12,14 @@
1212
1313#include <stdio.h>
1414
15void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_size, IrPass pass);
16void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction, int indent_size, IrPass pass);
17void ir_print_const_expr(CodeGen *codegen, FILE *f, ZigValue *value, int indent_size, IrPass pass);
18void ir_print_basic_block(CodeGen *codegen, FILE *f, IrBasicBlock *bb, int indent_size, IrPass pass);
15void ir_print_src(CodeGen *codegen, FILE *f, IrExecutableSrc *executable, int indent_size);
16void ir_print_gen(CodeGen *codegen, FILE *f, IrExecutableGen *executable, int indent_size);
17void ir_print_inst_src(CodeGen *codegen, FILE *f, IrInstSrc *inst, int indent_size);
18void ir_print_inst_gen(CodeGen *codegen, FILE *f, IrInstGen *inst, int indent_size);
19void ir_print_basic_block_src(CodeGen *codegen, FILE *f, IrBasicBlockSrc *bb, int indent_size);
20void ir_print_basic_block_gen(CodeGen *codegen, FILE *f, IrBasicBlockGen *bb, int indent_size);
1921
20const char* ir_instruction_type_str(IrInstructionId id);
22const char* ir_inst_src_type_str(IrInstSrcId id);
23const char* ir_inst_gen_type_str(IrInstGenId id);
2124
2225#endif
src/main.cpp+5-5
......@@ -144,15 +144,15 @@ static int print_libc_usage(const char *arg0, FILE *file, int return_code) {
144144 "You can save this into a file and then edit the paths to create a cross\n"
145145 "compilation libc kit. Then you can pass `--libc [file]` for Zig to use it.\n"
146146 "\n"
147 "When compiling natively and no `--libc` argument provided, Zig automatically\n"
148 "creates zig-cache/native_libc.txt so that it does not have to detect libc\n"
149 "on every invocation. You can remove this file to have Zig re-detect the\n"
150 "native libc.\n"
147 "When compiling natively and no `--libc` argument provided, Zig will create\n"
148 "`%s/native_libc.txt`\n"
149 "so that it does not have to detect libc on every invocation. You can remove\n"
150 "this file to have Zig re-detect the native libc.\n"
151151 "\n\n"
152152 "Usage: %s libc [file]\n"
153153 "\n"
154154 "Parse a libc installation text file and validate it.\n"
155 , arg0, arg0);
155 , arg0, buf_ptr(get_global_cache_dir()), arg0);
156156 return return_code;
157157}
158158
src/parser.cpp+1-1
......@@ -147,7 +147,7 @@ static void ast_invalid_token_error(ParseContext *pc, Token *token) {
147147}
148148
149149static AstNode *ast_create_node_no_line_info(ParseContext *pc, NodeType type) {
150 AstNode *node = allocate<AstNode>(1);
150 AstNode *node = allocate<AstNode>(1, "AstNode");
151151 node->type = type;
152152 node->owner = pc->owner;
153153 return node;
src/zig_clang.cpp+9
......@@ -1625,6 +1625,10 @@ unsigned ZigClangFunctionDecl_getAlignedAttribute(const struct ZigClangFunctionD
16251625 return 0;
16261626}
16271627
1628ZigClangQualType ZigClangParmVarDecl_getOriginalType(const struct ZigClangParmVarDecl *self) {
1629 return bitcast(reinterpret_cast<const clang::ParmVarDecl *>(self)->getOriginalType());
1630}
1631
16281632const ZigClangRecordDecl *ZigClangRecordDecl_getDefinition(const ZigClangRecordDecl *zig_record_decl) {
16291633 const clang::RecordDecl *record_decl = reinterpret_cast<const clang::RecordDecl *>(zig_record_decl);
16301634 const clang::RecordDecl *definition = record_decl->getDefinition();
......@@ -1877,6 +1881,11 @@ bool ZigClangType_isRecordType(const ZigClangType *self) {
18771881 return casted->isRecordType();
18781882}
18791883
1884bool ZigClangType_isConstantArrayType(const ZigClangType *self) {
1885 auto casted = reinterpret_cast<const clang::Type *>(self);
1886 return casted->isConstantArrayType();
1887}
1888
18801889const char *ZigClangType_getTypeClassName(const ZigClangType *self) {
18811890 auto casted = reinterpret_cast<const clang::Type *>(self);
18821891 return casted->getTypeClassName();
src/zig_clang.h+3
......@@ -866,6 +866,8 @@ ZIG_EXTERN_C const char* ZigClangVarDecl_getSectionAttribute(const struct ZigCla
866866ZIG_EXTERN_C unsigned ZigClangVarDecl_getAlignedAttribute(const struct ZigClangVarDecl *self, const ZigClangASTContext* ctx);
867867ZIG_EXTERN_C unsigned ZigClangFunctionDecl_getAlignedAttribute(const struct ZigClangFunctionDecl *self, const ZigClangASTContext* ctx);
868868
869ZIG_EXTERN_C struct ZigClangQualType ZigClangParmVarDecl_getOriginalType(const struct ZigClangParmVarDecl *self);
870
869871ZIG_EXTERN_C bool ZigClangRecordDecl_getPackedAttribute(const struct ZigClangRecordDecl *);
870872ZIG_EXTERN_C const struct ZigClangRecordDecl *ZigClangRecordDecl_getDefinition(const struct ZigClangRecordDecl *);
871873ZIG_EXTERN_C const struct ZigClangEnumDecl *ZigClangEnumDecl_getDefinition(const struct ZigClangEnumDecl *);
......@@ -945,6 +947,7 @@ ZIG_EXTERN_C bool ZigClangType_isBooleanType(const struct ZigClangType *self);
945947ZIG_EXTERN_C bool ZigClangType_isVoidType(const struct ZigClangType *self);
946948ZIG_EXTERN_C bool ZigClangType_isArrayType(const struct ZigClangType *self);
947949ZIG_EXTERN_C bool ZigClangType_isRecordType(const struct ZigClangType *self);
950ZIG_EXTERN_C bool ZigClangType_isConstantArrayType(const ZigClangType *self);
948951ZIG_EXTERN_C const char *ZigClangType_getTypeClassName(const struct ZigClangType *self);
949952ZIG_EXTERN_C const struct ZigClangArrayType *ZigClangType_getAsArrayTypeUnsafe(const struct ZigClangType *self);
950953ZIG_EXTERN_C const ZigClangRecordType *ZigClangType_getAsRecordType(const ZigClangType *self);
test/stack_traces.zig+98
......@@ -51,11 +51,15 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
5151 // debug
5252 \\error: TheSkyIsFalling
5353 \\source.zig:4:5: [address] in main (test)
54 \\ return error.TheSkyIsFalling;
55 \\ ^
5456 \\
5557 ,
5658 // release-safe
5759 \\error: TheSkyIsFalling
5860 \\source.zig:4:5: [address] in std.start.main (test)
61 \\ return error.TheSkyIsFalling;
62 \\ ^
5963 \\
6064 ,
6165 // release-fast
......@@ -74,13 +78,21 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
7478 // debug
7579 \\error: TheSkyIsFalling
7680 \\source.zig:4:5: [address] in foo (test)
81 \\ return error.TheSkyIsFalling;
82 \\ ^
7783 \\source.zig:8:5: [address] in main (test)
84 \\ try foo();
85 \\ ^
7886 \\
7987 ,
8088 // release-safe
8189 \\error: TheSkyIsFalling
8290 \\source.zig:4:5: [address] in std.start.main (test)
91 \\ return error.TheSkyIsFalling;
92 \\ ^
8393 \\source.zig:8:5: [address] in std.start.main (test)
94 \\ try foo();
95 \\ ^
8496 \\
8597 ,
8698 // release-fast
......@@ -99,17 +111,33 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
99111 // debug
100112 \\error: TheSkyIsFalling
101113 \\source.zig:12:5: [address] in make_error (test)
114 \\ return error.TheSkyIsFalling;
115 \\ ^
102116 \\source.zig:8:5: [address] in bar (test)
117 \\ return make_error();
118 \\ ^
103119 \\source.zig:4:5: [address] in foo (test)
120 \\ try bar();
121 \\ ^
104122 \\source.zig:16:5: [address] in main (test)
123 \\ try foo();
124 \\ ^
105125 \\
106126 ,
107127 // release-safe
108128 \\error: TheSkyIsFalling
109129 \\source.zig:12:5: [address] in std.start.main (test)
130 \\ return error.TheSkyIsFalling;
131 \\ ^
110132 \\source.zig:8:5: [address] in std.start.main (test)
133 \\ return make_error();
134 \\ ^
111135 \\source.zig:4:5: [address] in std.start.main (test)
136 \\ try bar();
137 \\ ^
112138 \\source.zig:16:5: [address] in std.start.main (test)
139 \\ try foo();
140 \\ ^
113141 \\
114142 ,
115143 // release-fast
......@@ -130,11 +158,15 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
130158 // debug
131159 \\error: TheSkyIsFalling
132160 \\source.zig:4:5: [address] in main (test)
161 \\ return error.TheSkyIsFalling;
162 \\ ^
133163 \\
134164 ,
135165 // release-safe
136166 \\error: TheSkyIsFalling
137167 \\source.zig:4:5: [address] in std.start.posixCallMainAndExit (test)
168 \\ return error.TheSkyIsFalling;
169 \\ ^
138170 \\
139171 ,
140172 // release-fast
......@@ -153,13 +185,21 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
153185 // debug
154186 \\error: TheSkyIsFalling
155187 \\source.zig:4:5: [address] in foo (test)
188 \\ return error.TheSkyIsFalling;
189 \\ ^
156190 \\source.zig:8:5: [address] in main (test)
191 \\ try foo();
192 \\ ^
157193 \\
158194 ,
159195 // release-safe
160196 \\error: TheSkyIsFalling
161197 \\source.zig:4:5: [address] in std.start.posixCallMainAndExit (test)
198 \\ return error.TheSkyIsFalling;
199 \\ ^
162200 \\source.zig:8:5: [address] in std.start.posixCallMainAndExit (test)
201 \\ try foo();
202 \\ ^
163203 \\
164204 ,
165205 // release-fast
......@@ -178,17 +218,33 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
178218 // debug
179219 \\error: TheSkyIsFalling
180220 \\source.zig:12:5: [address] in make_error (test)
221 \\ return error.TheSkyIsFalling;
222 \\ ^
181223 \\source.zig:8:5: [address] in bar (test)
224 \\ return make_error();
225 \\ ^
182226 \\source.zig:4:5: [address] in foo (test)
227 \\ try bar();
228 \\ ^
183229 \\source.zig:16:5: [address] in main (test)
230 \\ try foo();
231 \\ ^
184232 \\
185233 ,
186234 // release-safe
187235 \\error: TheSkyIsFalling
188236 \\source.zig:12:5: [address] in std.start.posixCallMainAndExit (test)
237 \\ return error.TheSkyIsFalling;
238 \\ ^
189239 \\source.zig:8:5: [address] in std.start.posixCallMainAndExit (test)
240 \\ return make_error();
241 \\ ^
190242 \\source.zig:4:5: [address] in std.start.posixCallMainAndExit (test)
243 \\ try bar();
244 \\ ^
191245 \\source.zig:16:5: [address] in std.start.posixCallMainAndExit (test)
246 \\ try foo();
247 \\ ^
192248 \\
193249 ,
194250 // release-fast
......@@ -209,11 +265,15 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
209265 // debug
210266 \\error: TheSkyIsFalling
211267 \\source.zig:4:5: [address] in _main.0 (test.o)
268 \\ return error.TheSkyIsFalling;
269 \\ ^
212270 \\
213271 ,
214272 // release-safe
215273 \\error: TheSkyIsFalling
216274 \\source.zig:4:5: [address] in _main (test.o)
275 \\ return error.TheSkyIsFalling;
276 \\ ^
217277 \\
218278 ,
219279 // release-fast
......@@ -232,13 +292,21 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
232292 // debug
233293 \\error: TheSkyIsFalling
234294 \\source.zig:4:5: [address] in _foo (test.o)
295 \\ return error.TheSkyIsFalling;
296 \\ ^
235297 \\source.zig:8:5: [address] in _main.0 (test.o)
298 \\ try foo();
299 \\ ^
236300 \\
237301 ,
238302 // release-safe
239303 \\error: TheSkyIsFalling
240304 \\source.zig:4:5: [address] in _main (test.o)
305 \\ return error.TheSkyIsFalling;
306 \\ ^
241307 \\source.zig:8:5: [address] in _main (test.o)
308 \\ try foo();
309 \\ ^
242310 \\
243311 ,
244312 // release-fast
......@@ -257,17 +325,33 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
257325 // debug
258326 \\error: TheSkyIsFalling
259327 \\source.zig:12:5: [address] in _make_error (test.o)
328 \\ return error.TheSkyIsFalling;
329 \\ ^
260330 \\source.zig:8:5: [address] in _bar (test.o)
331 \\ return make_error();
332 \\ ^
261333 \\source.zig:4:5: [address] in _foo (test.o)
334 \\ try bar();
335 \\ ^
262336 \\source.zig:16:5: [address] in _main.0 (test.o)
337 \\ try foo();
338 \\ ^
263339 \\
264340 ,
265341 // release-safe
266342 \\error: TheSkyIsFalling
267343 \\source.zig:12:5: [address] in _main (test.o)
344 \\ return error.TheSkyIsFalling;
345 \\ ^
268346 \\source.zig:8:5: [address] in _main (test.o)
347 \\ return make_error();
348 \\ ^
269349 \\source.zig:4:5: [address] in _main (test.o)
350 \\ try bar();
351 \\ ^
270352 \\source.zig:16:5: [address] in _main (test.o)
353 \\ try foo();
354 \\ ^
271355 \\
272356 ,
273357 // release-fast
......@@ -288,6 +372,8 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
288372 // debug
289373 \\error: TheSkyIsFalling
290374 \\source.zig:4:5: [address] in main (test.obj)
375 \\ return error.TheSkyIsFalling;
376 \\ ^
291377 \\
292378 ,
293379 // release-safe
......@@ -309,7 +395,11 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
309395 // debug
310396 \\error: TheSkyIsFalling
311397 \\source.zig:4:5: [address] in foo (test.obj)
398 \\ return error.TheSkyIsFalling;
399 \\ ^
312400 \\source.zig:8:5: [address] in main (test.obj)
401 \\ try foo();
402 \\ ^
313403 \\
314404 ,
315405 // release-safe
......@@ -331,9 +421,17 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
331421 // debug
332422 \\error: TheSkyIsFalling
333423 \\source.zig:12:5: [address] in make_error (test.obj)
424 \\ return error.TheSkyIsFalling;
425 \\ ^
334426 \\source.zig:8:5: [address] in bar (test.obj)
427 \\ return make_error();
428 \\ ^
335429 \\source.zig:4:5: [address] in foo (test.obj)
430 \\ try bar();
431 \\ ^
336432 \\source.zig:16:5: [address] in main (test.obj)
433 \\ try foo();
434 \\ ^
337435 \\
338436 ,
339437 // release-safe
test/translate_c.zig+37
......@@ -3,6 +3,31 @@ const builtin = @import("builtin");
33const Target = @import("std").Target;
44
55pub fn addCases(cases: *tests.TranslateCContext) void {
6 cases.add("array initializer w/ typedef",
7 \\typedef unsigned char uuid_t[16];
8 \\static const uuid_t UUID_NULL __attribute__ ((unused)) = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
9 , &[_][]const u8{
10 \\pub const uuid_t = [16]u8;
11 \\pub const UUID_NULL: uuid_t = .{
12 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),
13 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),
14 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),
15 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),
16 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),
17 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),
18 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),
19 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),
20 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),
21 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),
22 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),
23 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),
24 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),
25 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),
26 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),
27 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),
28 \\};
29 });
30
631 cases.add("empty declaration",
732 \\;
833 , &[_][]const u8{""});
......@@ -2606,4 +2631,16 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
26062631 \\ return foo((@intCast(c_int, @bitCast(i1, @intCast(u1, @boolToInt(c)))) != @intCast(c_int, @bitCast(i1, @intCast(u1, @boolToInt(b))))));
26072632 \\}
26082633 });
2634
2635 cases.add("Don't make const parameters mutable",
2636 \\int max(const int x, int y) {
2637 \\ return (x > y) ? x : y;
2638 \\}
2639 , &[_][]const u8{
2640 \\pub export fn max(x: c_int, arg_y: c_int) c_int {
2641 \\ var y = arg_y;
2642 \\ return if (x > y) x else y;
2643 \\}
2644 });
2645
26092646}