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 {...@@ -1689,7 +1689,9 @@ pub const LibExeObjStep = struct {
1689 }1689 }
16901690
1691 pub fn addAssemblyFile(self: *LibExeObjStep, path: []const u8) void {1691 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;
1693 }1695 }
16941696
1695 pub fn addAssemblyFileFromWriteFileStep(self: *LibExeObjStep, wfs: *WriteFileStep, basename: []const u8) void {1697 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...@@ -379,16 +379,7 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres
379 }379 }
380 } else {380 } else {
381 // we have no information to add to the address381 // we have no information to add to the address
382 if (tty_color) {382 return printLineInfo(out_stream, null, relocated_address, "???", "???", tty_color, printLineFromFileAnyOs);
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;
392 };383 };
393384
394 const mod = &di.modules[mod_index];385 const mod = &di.modules[mod_index];
...@@ -510,66 +501,15 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres...@@ -510,66 +501,15 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres
510 }501 }
511 };502 };
512503
513 if (tty_color) {504 try printLineInfo(
514 setTtyColor(TtyColor.White);505 out_stream,
515 if (opt_line_info) |li| {506 opt_line_info,
516 try out_stream.print("{}:{}:{}", .{ li.file_name, li.line, li.column });507 relocated_address,
517 } else {508 symbol_name,
518 try out_stream.print("???:?:?", .{});509 obj_basename,
519 }510 tty_color,
520 setTtyColor(TtyColor.Reset);511 printLineFromFileAnyOs,
521 try out_stream.print(": ", .{});512 );
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 }
573}513}
574514
575const TtyColor = enum {515const TtyColor = enum {
...@@ -605,7 +545,11 @@ fn setTtyColor(tty_color: TtyColor) void {...@@ -605,7 +545,11 @@ fn setTtyColor(tty_color: TtyColor) void {
605 stderr_file.write(RESET) catch return;545 stderr_file.write(RESET) catch return;
606 },546 },
607 }547 }
608 } else {548
549 return;
550 }
551
552 if (builtin.os == .windows) {
609 const S = struct {553 const S = struct {
610 var attrs: windows.WORD = undefined;554 var attrs: windows.WORD = undefined;
611 var init_attrs = false;555 var init_attrs = false;
...@@ -711,12 +655,7 @@ fn printSourceAtAddressMacOs(di: *DebugInfo, out_stream: var, address: usize, tt...@@ -711,12 +655,7 @@ fn printSourceAtAddressMacOs(di: *DebugInfo, out_stream: var, address: usize, tt
711 const adjusted_addr = 0x100000000 + (address - base_addr);655 const adjusted_addr = 0x100000000 + (address - base_addr);
712656
713 const symbol = machoSearchSymbols(di.symbols, adjusted_addr) orelse {657 const symbol = machoSearchSymbols(di.symbols, adjusted_addr) orelse {
714 if (tty_color) {658 return printLineInfo(out_stream, null, address, "???", "???", tty_color, printLineFromFileAnyOs);
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;
720 };659 };
721660
722 const symbol_name = mem.toSliceConst(u8, @ptrCast([*:0]const u8, di.strings.ptr + symbol.nlist.n_strx));661 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...@@ -724,29 +663,22 @@ fn printSourceAtAddressMacOs(di: *DebugInfo, out_stream: var, address: usize, tt
724 const ofile_path = mem.toSliceConst(u8, @ptrCast([*:0]const u8, di.strings.ptr + ofile.n_strx));663 const ofile_path = mem.toSliceConst(u8, @ptrCast([*:0]const u8, di.strings.ptr + ofile.n_strx));
725 break :blk fs.path.basename(ofile_path);664 break :blk fs.path.basename(ofile_path);
726 } else "???";665 } else "???";
727 if (getLineNumberInfoMacOs(di, symbol.*, adjusted_addr)) |line_info| {666
728 defer line_info.deinit();667 const line_info = getLineNumberInfoMacOs(di, symbol.*, adjusted_addr) catch |err| switch (err) {
729 try printLineInfo(668 error.MissingDebugInfo, error.InvalidDebugInfo => null,
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 },
748 else => return err,669 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 );
750}682}
751683
752pub fn printSourceAtAddressPosix(debug_info: *DebugInfo, out_stream: var, address: usize, tty_color: bool) !void {684pub 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...@@ -755,47 +687,46 @@ pub fn printSourceAtAddressPosix(debug_info: *DebugInfo, out_stream: var, addres
755687
756fn printLineInfo(688fn printLineInfo(
757 out_stream: var,689 out_stream: var,
758 line_info: LineInfo,690 line_info: ?LineInfo,
759 address: usize,691 address: usize,
760 symbol_name: []const u8,692 symbol_name: []const u8,
761 compile_unit_name: []const u8,693 compile_unit_name: []const u8,
762 tty_color: bool,694 tty_color: bool,
763 comptime printLineFromFile: var,695 comptime printLineFromFile: var,
764) !void {696) !void {
765 if (tty_color) {697 if (tty_color) setTtyColor(.White);
766 try out_stream.print(WHITE ++ "{}:{}:{}" ++ RESET ++ ": " ++ DIM ++ "0x{x} in {} ({})" ++ RESET ++ "\n", .{698
767 line_info.file_name,699 if (line_info) |*li| {
768 line_info.line,700 try out_stream.print("{}:{}:{}", .{ li.file_name, li.line, li.column });
769 line_info.column,701 } else {
770 address,702 try out_stream.print("???:?:?", .{});
771 symbol_name,703 }
772 compile_unit_name,704
773 });705 if (tty_color) setTtyColor(.Reset);
774 if (printLineFromFile(out_stream, line_info)) {706 try out_stream.write(": ");
775 if (line_info.column == 0) {707 if (tty_color) setTtyColor(.Dim);
776 try out_stream.write("\n");708 try out_stream.print("0x{x} in {} ({})", .{ address, symbol_name, compile_unit_name });
777 } else {709 if (tty_color) setTtyColor(.Reset);
778 {710 try out_stream.write("\n");
779 var col_i: usize = 1;711
780 while (col_i < line_info.column) : (col_i += 1) {712 // Show the matching source code line if possible
781 try out_stream.writeByte(' ');713 if (line_info) |li| {
782 }714 if (noasync printLineFromFile(out_stream, li)) {
783 }715 if (li.column > 0) {
784 try out_stream.write(GREEN ++ "^" ++ RESET ++ "\n");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);
785 }723 }
724 try out_stream.write("\n");
786 } else |err| switch (err) {725 } else |err| switch (err) {
787 error.EndOfFile, error.FileNotFound => {},726 error.EndOfFile, error.FileNotFound => {},
727 error.BadPathName => {},
788 else => return err,728 else => return err,
789 }729 }
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 });
799 }730 }
800}731}
801732
...@@ -1240,38 +1171,26 @@ pub const DwarfInfo = struct {...@@ -1240,38 +1171,26 @@ pub const DwarfInfo = struct {
1240 comptime printLineFromFile: var,1171 comptime printLineFromFile: var,
1241 ) !void {1172 ) !void {
1242 const compile_unit = self.findCompileUnit(address) catch {1173 const compile_unit = self.findCompileUnit(address) catch {
1243 if (tty_color) {1174 return printLineInfo(out_stream, null, address, "???", "???", tty_color, printLineFromFile);
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;
1249 };1175 };
1176
1250 const compile_unit_name = try compile_unit.die.getAttrString(self, DW.AT_name);1177 const compile_unit_name = try compile_unit.die.getAttrString(self, DW.AT_name);
1251 if (self.getLineNumberInfo(compile_unit.*, address)) |line_info| {1178 const symbol_name = self.getSymbolName(address) orelse "???";
1252 defer line_info.deinit();1179 const line_info = self.getLineNumberInfo(compile_unit.*, address) catch |err| switch (err) {
1253 const symbol_name = self.getSymbolName(address) orelse "???";1180 error.MissingDebugInfo, error.InvalidDebugInfo => null,
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 },
1273 else => return err,1181 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 );
1275 }1194 }
12761195
1277 fn getSymbolName(di: *DwarfInfo, address: u64) ?[]const u8 {1196 fn getSymbolName(di: *DwarfInfo, address: u64) ?[]const u8 {
...@@ -1458,9 +1377,13 @@ pub const DwarfInfo = struct {...@@ -1458,9 +1377,13 @@ pub const DwarfInfo = struct {
1458 if (compile_unit.pc_range) |range| {1377 if (compile_unit.pc_range) |range| {
1459 if (target_address >= range.start and target_address < range.end) return compile_unit;1378 if (target_address >= range.start and target_address < range.end) return compile_unit;
1460 }1379 }
1461 if (compile_unit.die.getAttrSecOffset(DW.AT_ranges)) |ranges_offset| {1380 if (di.debug_ranges) |debug_ranges| {
1462 var base_address: usize = 0;1381 if (compile_unit.die.getAttrSecOffset(DW.AT_ranges)) |ranges_offset| {
1463 if (di.debug_ranges) |debug_ranges| {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
1464 try di.dwarf_seekable_stream.seekTo(debug_ranges.offset + ranges_offset);1387 try di.dwarf_seekable_stream.seekTo(debug_ranges.offset + ranges_offset);
1465 while (true) {1388 while (true) {
1466 const begin_addr = try di.dwarf_in_stream.readIntLittle(usize);1389 const begin_addr = try di.dwarf_in_stream.readIntLittle(usize);
...@@ -1468,18 +1391,21 @@ pub const DwarfInfo = struct {...@@ -1468,18 +1391,21 @@ pub const DwarfInfo = struct {
1468 if (begin_addr == 0 and end_addr == 0) {1391 if (begin_addr == 0 and end_addr == 0) {
1469 break;1392 break;
1470 }1393 }
1394 // This entry selects a new value for the base address
1471 if (begin_addr == maxInt(usize)) {1395 if (begin_addr == maxInt(usize)) {
1472 base_address = begin_addr;1396 base_address = end_addr;
1473 continue;1397 continue;
1474 }1398 }
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) {
1476 return compile_unit;1400 return compile_unit;
1477 }1401 }
1478 }1402 }
1403
1404 return error.InvalidDebugInfo;
1405 } else |err| {
1406 if (err != error.MissingDebugInfo) return err;
1407 continue;
1479 }1408 }
1480 } else |err| {
1481 if (err != error.MissingDebugInfo) return err;
1482 continue;
1483 }1409 }
1484 }1410 }
1485 return error.MissingDebugInfo;1411 return error.MissingDebugInfo;
...@@ -1552,7 +1478,8 @@ pub const DwarfInfo = struct {...@@ -1552,7 +1478,8 @@ pub const DwarfInfo = struct {
15521478
1553 assert(line_info_offset < di.debug_line.size);1479 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
1557 var is_64: bool = undefined;1484 var is_64: bool = undefined;
1558 const unit_length = try readInitialLength(@TypeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64);1485 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 {...@@ -1620,7 +1547,9 @@ pub const DwarfInfo = struct {
16201547
1621 try di.dwarf_seekable_stream.seekTo(prog_start_offset);1548 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) {
1624 const opcode = try di.dwarf_in_stream.readByte();1553 const opcode = try di.dwarf_in_stream.readByte();
16251554
1626 if (opcode == DW.LNS_extended_op) {1555 if (opcode == DW.LNS_extended_op) {
...@@ -1631,7 +1560,7 @@ pub const DwarfInfo = struct {...@@ -1631,7 +1560,7 @@ pub const DwarfInfo = struct {
1631 DW.LNE_end_sequence => {1560 DW.LNE_end_sequence => {
1632 prog.end_sequence = true;1561 prog.end_sequence = true;
1633 if (try prog.checkLineMatch()) |info| return info;1562 if (try prog.checkLineMatch()) |info| return info;
1634 return error.MissingDebugInfo;1563 prog.reset();
1635 },1564 },
1636 DW.LNE_set_address => {1565 DW.LNE_set_address => {
1637 const addr = try di.dwarf_in_stream.readInt(usize, di.endian);1566 const addr = try di.dwarf_in_stream.readInt(usize, di.endian);
...@@ -1888,6 +1817,7 @@ const LineNumberProgram = struct {...@@ -1888,6 +1817,7 @@ const LineNumberProgram = struct {
1888 basic_block: bool,1817 basic_block: bool,
1889 end_sequence: bool,1818 end_sequence: bool,
18901819
1820 default_is_stmt: bool,
1891 target_address: usize,1821 target_address: usize,
1892 include_dirs: []const []const u8,1822 include_dirs: []const []const u8,
1893 file_entries: *ArrayList(FileEntry),1823 file_entries: *ArrayList(FileEntry),
...@@ -1900,6 +1830,25 @@ const LineNumberProgram = struct {...@@ -1900,6 +1830,25 @@ const LineNumberProgram = struct {
1900 prev_basic_block: bool,1830 prev_basic_block: bool,
1901 prev_end_sequence: bool,1831 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
1903 pub fn init(is_stmt: bool, include_dirs: []const []const u8, file_entries: *ArrayList(FileEntry), target_address: usize) LineNumberProgram {1852 pub fn init(is_stmt: bool, include_dirs: []const []const u8, file_entries: *ArrayList(FileEntry), target_address: usize) LineNumberProgram {
1904 return LineNumberProgram{1853 return LineNumberProgram{
1905 .address = 0,1854 .address = 0,
...@@ -1911,6 +1860,7 @@ const LineNumberProgram = struct {...@@ -1911,6 +1860,7 @@ const LineNumberProgram = struct {
1911 .end_sequence = false,1860 .end_sequence = false,
1912 .include_dirs = include_dirs,1861 .include_dirs = include_dirs,
1913 .file_entries = file_entries,1862 .file_entries = file_entries,
1863 .default_is_stmt = is_stmt,
1914 .target_address = target_address,1864 .target_address = target_address,
1915 .prev_address = 0,1865 .prev_address = 0,
1916 .prev_file = undefined,1866 .prev_file = undefined,
lib/std/fmt.zig+11-6
...@@ -431,7 +431,7 @@ pub fn formatType(...@@ -431,7 +431,7 @@ pub fn formatType(
431 },431 },
432 else => return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) }),432 else => return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) }),
433 },433 },
434 .Many => {434 .Many, .C => {
435 if (ptr_info.child == u8) {435 if (ptr_info.child == u8) {
436 if (fmt.len > 0 and fmt[0] == 's') {436 if (fmt.len > 0 and fmt[0] == 's') {
437 const len = mem.len(u8, value);437 const len = mem.len(u8, value);
...@@ -449,9 +449,6 @@ pub fn formatType(...@@ -449,9 +449,6 @@ pub fn formatType(
449 }449 }
450 return format(context, Errors, output, "{}@{x}", .{ @typeName(ptr_info.child), @ptrToInt(value.ptr) });450 return format(context, Errors, output, "{}@{x}", .{ @typeName(ptr_info.child), @ptrToInt(value.ptr) });
451 },451 },
452 .C => {
453 return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) });
454 },
455 },452 },
456 .Array => |info| {453 .Array => |info| {
457 const Slice = @Type(builtin.TypeInfo{454 const Slice = @Type(builtin.TypeInfo{
...@@ -1290,8 +1287,16 @@ test "pointer" {...@@ -1290,8 +1287,16 @@ test "pointer" {
1290}1287}
12911288
1292test "cstr" {1289test "cstr" {
1293 try testFmt("cstr: Test C\n", "cstr: {s}\n", .{"Test C"});1290 try testFmt(
1294 try testFmt("cstr: Test C \n", "cstr: {s:10}\n", .{"Test C"});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 );
1295}1300}
12961301
1297test "filesize" {1302test "filesize" {
lib/std/io/out_stream.zig+8-4
...@@ -45,10 +45,14 @@ pub fn OutStream(comptime WriteError: type) type {...@@ -45,10 +45,14 @@ pub fn OutStream(comptime WriteError: type) type {
45 }45 }
4646
47 pub fn writeByteNTimes(self: *Self, byte: u8, n: usize) Error!void {47 pub fn writeByteNTimes(self: *Self, byte: u8, n: usize) Error!void {
48 const slice = @as(*const [1]u8, &byte)[0..];48 var bytes: [256]u8 = undefined;
49 var i: usize = 0;49 mem.set(u8, bytes[0..], byte);
50 while (i < n) : (i += 1) {50
51 try self.writeFn(self, slice);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;
52 }56 }
53 }57 }
5458
lib/std/special/compiler_rt.zig+1
...@@ -130,6 +130,7 @@ comptime {...@@ -130,6 +130,7 @@ comptime {
130 @export(@import("compiler_rt/int.zig").__udivmoddi4, .{ .name = "__udivmoddi4", .linkage = linkage });130 @export(@import("compiler_rt/int.zig").__udivmoddi4, .{ .name = "__udivmoddi4", .linkage = linkage });
131 @export(@import("compiler_rt/popcountdi2.zig").__popcountdi2, .{ .name = "__popcountdi2", .linkage = linkage });131 @export(@import("compiler_rt/popcountdi2.zig").__popcountdi2, .{ .name = "__popcountdi2", .linkage = linkage });
132132
133 @export(@import("compiler_rt/int.zig").__mulsi3, .{ .name = "__mulsi3", .linkage = linkage });
133 @export(@import("compiler_rt/muldi3.zig").__muldi3, .{ .name = "__muldi3", .linkage = linkage });134 @export(@import("compiler_rt/muldi3.zig").__muldi3, .{ .name = "__muldi3", .linkage = linkage });
134 @export(@import("compiler_rt/int.zig").__divmoddi4, .{ .name = "__divmoddi4", .linkage = linkage });135 @export(@import("compiler_rt/int.zig").__divmoddi4, .{ .name = "__divmoddi4", .linkage = linkage });
135 @export(@import("compiler_rt/int.zig").__divsi3, .{ .name = "__divsi3", .linkage = linkage });136 @export(@import("compiler_rt/int.zig").__divsi3, .{ .name = "__divsi3", .linkage = linkage });
lib/std/special/compiler_rt/int.zig+60
...@@ -1,6 +1,8 @@...@@ -1,6 +1,8 @@
1// Builtin functions that operate on integer types1// Builtin functions that operate on integer types
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const testing = @import("std").testing;3const testing = @import("std").testing;
4const maxInt = @import("std").math.maxInt;
5const minInt = @import("std").math.minInt;
46
5const udivmod = @import("udivmod.zig").udivmod;7const udivmod = @import("udivmod.zig").udivmod;
68
...@@ -578,3 +580,61 @@ fn test_one_umodsi3(a: u32, b: u32, expected_r: u32) void {...@@ -578,3 +580,61 @@ fn test_one_umodsi3(a: u32, b: u32, expected_r: u32) void {
578 const r: u32 = __umodsi3(a, b);580 const r: u32 = __umodsi3(a, b);
579 testing.expect(r == expected_r);581 testing.expect(r == expected_r);
580}582}
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...@@ -768,6 +768,7 @@ pub extern fn ZigClangFieldDecl_getCanonicalDecl(field_decl: ?*const struct_ZigC
768pub extern fn ZigClangEnumDecl_getCanonicalDecl(self: ?*const struct_ZigClangEnumDecl) ?*const struct_ZigClangTagDecl;768pub extern fn ZigClangEnumDecl_getCanonicalDecl(self: ?*const struct_ZigClangEnumDecl) ?*const struct_ZigClangTagDecl;
769pub extern fn ZigClangTypedefNameDecl_getCanonicalDecl(self: ?*const struct_ZigClangTypedefNameDecl) ?*const struct_ZigClangTypedefNameDecl;769pub extern fn ZigClangTypedefNameDecl_getCanonicalDecl(self: ?*const struct_ZigClangTypedefNameDecl) ?*const struct_ZigClangTypedefNameDecl;
770pub extern fn ZigClangFunctionDecl_getCanonicalDecl(self: ?*const struct_ZigClangFunctionDecl) ?*const struct_ZigClangFunctionDecl;770pub extern fn ZigClangFunctionDecl_getCanonicalDecl(self: ?*const struct_ZigClangFunctionDecl) ?*const struct_ZigClangFunctionDecl;
771pub extern fn ZigClangParmVarDecl_getOriginalType(self: ?*const struct_ZigClangParmVarDecl) struct_ZigClangQualType;
771pub extern fn ZigClangVarDecl_getCanonicalDecl(self: ?*const struct_ZigClangVarDecl) ?*const struct_ZigClangVarDecl;772pub extern fn ZigClangVarDecl_getCanonicalDecl(self: ?*const struct_ZigClangVarDecl) ?*const struct_ZigClangVarDecl;
772pub extern fn ZigClangVarDecl_getSectionAttribute(self: *const ZigClangVarDecl, len: *usize) ?[*]const u8;773pub extern fn ZigClangVarDecl_getSectionAttribute(self: *const ZigClangVarDecl, len: *usize) ?[*]const u8;
773pub extern fn ZigClangFunctionDecl_getAlignedAttribute(self: *const ZigClangFunctionDecl, *const ZigClangASTContext) c_uint;774pub extern fn ZigClangFunctionDecl_getAlignedAttribute(self: *const ZigClangFunctionDecl, *const ZigClangASTContext) c_uint;
...@@ -809,6 +810,7 @@ pub extern fn ZigClangQualType_isRestrictQualified(self: struct_ZigClangQualType...@@ -809,6 +810,7 @@ pub extern fn ZigClangQualType_isRestrictQualified(self: struct_ZigClangQualType
809pub extern fn ZigClangType_getTypeClass(self: ?*const struct_ZigClangType) ZigClangTypeClass;810pub extern fn ZigClangType_getTypeClass(self: ?*const struct_ZigClangType) ZigClangTypeClass;
810pub extern fn ZigClangType_getPointeeType(self: ?*const struct_ZigClangType) struct_ZigClangQualType;811pub extern fn ZigClangType_getPointeeType(self: ?*const struct_ZigClangType) struct_ZigClangQualType;
811pub extern fn ZigClangType_isVoidType(self: ?*const struct_ZigClangType) bool;812pub extern fn ZigClangType_isVoidType(self: ?*const struct_ZigClangType) bool;
813pub extern fn ZigClangType_isConstantArrayType(self: ?*const struct_ZigClangType) bool;
812pub extern fn ZigClangType_isRecordType(self: ?*const struct_ZigClangType) bool;814pub extern fn ZigClangType_isRecordType(self: ?*const struct_ZigClangType) bool;
813pub extern fn ZigClangType_isArrayType(self: ?*const struct_ZigClangType) bool;815pub extern fn ZigClangType_isArrayType(self: ?*const struct_ZigClangType) bool;
814pub extern fn ZigClangType_isBooleanType(self: ?*const struct_ZigClangType) bool;816pub 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 {...@@ -485,6 +485,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {
485 block_scope.block_node = block_node;485 block_scope.block_node = block_node;
486486
487 var it = proto_node.params.iterator(0);487 var it = proto_node.params.iterator(0);
488 var param_id: c_uint = 0;
488 while (it.next()) |p| {489 while (it.next()) |p| {
489 const param = @fieldParentPtr(ast.Node.ParamDecl, "base", p.*);490 const param = @fieldParentPtr(ast.Node.ParamDecl, "base", p.*);
490 const param_name = if (param.name_token) |name_tok|491 const param_name = if (param.name_token) |name_tok|
...@@ -498,18 +499,27 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {...@@ -498,18 +499,27 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {
498499
499 const mangled_param_name = try block_scope.makeMangledName(c, param_name);500 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
501 const arg_name = blk: {506 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});
503 break :blk try block_scope.makeMangledName(c, bare_arg_name);509 break :blk try block_scope.makeMangledName(c, bare_arg_name);
504 };510 };
505511
506 const node = try transCreateNodeVarDecl(c, false, false, mangled_param_name);512 if (!is_const) {
507 node.eq_token = try appendToken(c, .Equal, "=");513 const node = try transCreateNodeVarDecl(c, false, false, mangled_param_name);
508 node.init_node = try transCreateNodeIdentifier(c, arg_name);514 node.eq_token = try appendToken(c, .Equal, "=");
509 node.semicolon_token = try appendToken(c, .Semicolon, ";");515 node.init_node = try transCreateNodeIdentifier(c, arg_name);
510 try block_node.statements.push(&node.base);516 node.semicolon_token = try appendToken(c, .Semicolon, ";");
511 param.name_token = try appendIdentifier(c, arg_name);517 try block_node.statements.push(&node.base);
512 _ = try appendToken(c, .Colon, ":");518 param.name_token = try appendIdentifier(c, arg_name);
519 _ = try appendToken(c, .Colon, ":");
520 }
521
522 param_id += 1;
513 }523 }
514524
515 transCompoundStmtInline(rp, &block_scope.base, @ptrCast(*const ZigClangCompoundStmt, body_stmt), block_node) catch |err| switch (err) {525 transCompoundStmtInline(rp, &block_scope.base, @ptrCast(*const ZigClangCompoundStmt, body_stmt), block_node) catch |err| switch (err) {
...@@ -1982,7 +1992,8 @@ fn transInitListExprArray(...@@ -1982,7 +1992,8 @@ fn transInitListExprArray(
1982 const arr_type = ZigClangType_getAsArrayTypeUnsafe(ty);1992 const arr_type = ZigClangType_getAsArrayTypeUnsafe(ty);
1983 const child_qt = ZigClangArrayType_getElementType(arr_type);1993 const child_qt = ZigClangArrayType_getElementType(arr_type);
1984 const init_count = ZigClangInitListExpr_getNumInits(expr);1994 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);
1986 const size_ap_int = ZigClangConstantArrayType_getSize(const_arr_ty);1997 const size_ap_int = ZigClangConstantArrayType_getSize(const_arr_ty);
1987 const all_count = ZigClangAPInt_getLimitedValue(size_ap_int, math.maxInt(usize));1998 const all_count = ZigClangAPInt_getLimitedValue(size_ap_int, math.maxInt(usize));
1988 const leftover_count = all_count - init_count;1999 const leftover_count = all_count - init_count;
src/all_types.hpp+1380-908
...@@ -33,12 +33,15 @@ struct BuiltinFnEntry;...@@ -33,12 +33,15 @@ struct BuiltinFnEntry;
33struct TypeStructField;33struct TypeStructField;
34struct CodeGen;34struct CodeGen;
35struct ZigValue;35struct ZigValue;
36struct IrInstruction;36struct IrInst;
37struct IrInstructionCast;37struct IrInstSrc;
38struct IrInstructionAllocaGen;38struct IrInstGen;
39struct IrInstructionCallGen;39struct IrInstGenCast;
40struct IrInstructionAwaitGen;40struct IrInstGenAlloca;
41struct IrBasicBlock;41struct IrInstGenCall;
42struct IrInstGenAwait;
43struct IrBasicBlockSrc;
44struct IrBasicBlockGen;
42struct ScopeDecls;45struct ScopeDecls;
43struct ZigWindowsSDK;46struct ZigWindowsSDK;
44struct Tld;47struct Tld;
...@@ -50,6 +53,7 @@ struct ResultLocPeerParent;...@@ -50,6 +53,7 @@ struct ResultLocPeerParent;
50struct ResultLocBitCast;53struct ResultLocBitCast;
51struct ResultLocCast;54struct ResultLocCast;
52struct ResultLocReturn;55struct ResultLocReturn;
56struct IrExecutableGen;
5357
54enum PtrLen {58enum PtrLen {
55 PtrLenUnknown,59 PtrLenUnknown,
...@@ -97,8 +101,8 @@ enum X64CABIClass {...@@ -97,8 +101,8 @@ enum X64CABIClass {
97 X64CABIClass_SSE,101 X64CABIClass_SSE,
98};102};
99103
100struct IrExecutable {104struct IrExecutableSrc {
101 ZigList<IrBasicBlock *> basic_block_list;105 ZigList<IrBasicBlockSrc *> basic_block_list;
102 Buf *name;106 Buf *name;
103 ZigFn *name_fn;107 ZigFn *name_fn;
104 size_t mem_slot_count;108 size_t mem_slot_count;
...@@ -108,8 +112,7 @@ struct IrExecutable {...@@ -108,8 +112,7 @@ struct IrExecutable {
108 ZigFn *fn_entry;112 ZigFn *fn_entry;
109 Buf *c_import_buf;113 Buf *c_import_buf;
110 AstNode *source_node;114 AstNode *source_node;
111 IrExecutable *parent_exec;115 IrExecutableGen *parent_exec;
112 IrExecutable *source_exec;
113 IrAnalyze *analysis;116 IrAnalyze *analysis;
114 Scope *begin_scope;117 Scope *begin_scope;
115 ErrorMsg *first_err_trace_msg;118 ErrorMsg *first_err_trace_msg;
...@@ -124,6 +127,32 @@ struct IrExecutable {...@@ -124,6 +127,32 @@ struct IrExecutable {
124 void src();127 void src();
125};128};
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
127enum OutType {156enum OutType {
128 OutTypeUnknown,157 OutTypeUnknown,
129 OutTypeExe,158 OutTypeExe,
...@@ -287,7 +316,7 @@ struct ConstErrValue {...@@ -287,7 +316,7 @@ struct ConstErrValue {
287316
288struct ConstBoundFnValue {317struct ConstBoundFnValue {
289 ZigFn *fn;318 ZigFn *fn;
290 IrInstruction *first_arg;319 IrInstGen *first_arg;
291};320};
292321
293struct ConstArgTuple {322struct ConstArgTuple {
...@@ -350,14 +379,14 @@ struct LazyValueAlignOf {...@@ -350,14 +379,14 @@ struct LazyValueAlignOf {
350 LazyValue base;379 LazyValue base;
351380
352 IrAnalyze *ira;381 IrAnalyze *ira;
353 IrInstruction *target_type;382 IrInstGen *target_type;
354};383};
355384
356struct LazyValueSizeOf {385struct LazyValueSizeOf {
357 LazyValue base;386 LazyValue base;
358387
359 IrAnalyze *ira;388 IrAnalyze *ira;
360 IrInstruction *target_type;389 IrInstGen *target_type;
361390
362 bool bit_size;391 bool bit_size;
363};392};
...@@ -366,9 +395,9 @@ struct LazyValueSliceType {...@@ -366,9 +395,9 @@ struct LazyValueSliceType {
366 LazyValue base;395 LazyValue base;
367396
368 IrAnalyze *ira;397 IrAnalyze *ira;
369 IrInstruction *sentinel; // can be null398 IrInstGen *sentinel; // can be null
370 IrInstruction *elem_type;399 IrInstGen *elem_type;
371 IrInstruction *align_inst; // can be null400 IrInstGen *align_inst; // can be null
372401
373 bool is_const;402 bool is_const;
374 bool is_volatile;403 bool is_volatile;
...@@ -379,8 +408,8 @@ struct LazyValueArrayType {...@@ -379,8 +408,8 @@ struct LazyValueArrayType {
379 LazyValue base;408 LazyValue base;
380409
381 IrAnalyze *ira;410 IrAnalyze *ira;
382 IrInstruction *sentinel; // can be null411 IrInstGen *sentinel; // can be null
383 IrInstruction *elem_type;412 IrInstGen *elem_type;
384 uint64_t length;413 uint64_t length;
385};414};
386415
...@@ -388,9 +417,9 @@ struct LazyValuePtrType {...@@ -388,9 +417,9 @@ struct LazyValuePtrType {
388 LazyValue base;417 LazyValue base;
389418
390 IrAnalyze *ira;419 IrAnalyze *ira;
391 IrInstruction *sentinel; // can be null420 IrInstGen *sentinel; // can be null
392 IrInstruction *elem_type;421 IrInstGen *elem_type;
393 IrInstruction *align_inst; // can be null422 IrInstGen *align_inst; // can be null
394423
395 PtrLen ptr_len;424 PtrLen ptr_len;
396 uint32_t bit_offset_in_host;425 uint32_t bit_offset_in_host;
...@@ -405,7 +434,7 @@ struct LazyValueOptType {...@@ -405,7 +434,7 @@ struct LazyValueOptType {
405 LazyValue base;434 LazyValue base;
406435
407 IrAnalyze *ira;436 IrAnalyze *ira;
408 IrInstruction *payload_type;437 IrInstGen *payload_type;
409};438};
410439
411struct LazyValueFnType {440struct LazyValueFnType {
...@@ -413,9 +442,9 @@ struct LazyValueFnType {...@@ -413,9 +442,9 @@ struct LazyValueFnType {
413442
414 IrAnalyze *ira;443 IrAnalyze *ira;
415 AstNode *proto_node;444 AstNode *proto_node;
416 IrInstruction **param_types;445 IrInstGen **param_types;
417 IrInstruction *align_inst; // can be null446 IrInstGen *align_inst; // can be null
418 IrInstruction *return_type;447 IrInstGen *return_type;
419448
420 CallingConvention cc;449 CallingConvention cc;
421 bool is_generic;450 bool is_generic;
...@@ -425,8 +454,8 @@ struct LazyValueErrUnionType {...@@ -425,8 +454,8 @@ struct LazyValueErrUnionType {
425 LazyValue base;454 LazyValue base;
426455
427 IrAnalyze *ira;456 IrAnalyze *ira;
428 IrInstruction *err_set_type;457 IrInstGen *err_set_type;
429 IrInstruction *payload_type;458 IrInstGen *payload_type;
430 Buf *type_name;459 Buf *type_name;
431};460};
432461
...@@ -1602,19 +1631,19 @@ struct ZigFn {...@@ -1602,19 +1631,19 @@ struct ZigFn {
1602 // in the case of async functions this is the implicit return type according to the1631 // in the case of async functions this is the implicit return type according to the
1603 // zig source code, not according to zig ir1632 // zig source code, not according to zig ir
1604 ZigType *src_implicit_return_type;1633 ZigType *src_implicit_return_type;
1605 IrExecutable *ir_executable;1634 IrExecutableSrc *ir_executable;
1606 IrExecutable analyzed_executable;1635 IrExecutableGen analyzed_executable;
1607 size_t prealloc_bbc;1636 size_t prealloc_bbc;
1608 size_t prealloc_backward_branch_quota;1637 size_t prealloc_backward_branch_quota;
1609 AstNode **param_source_nodes;1638 AstNode **param_source_nodes;
1610 Buf **param_names;1639 Buf **param_names;
1611 IrInstruction *err_code_spill;1640 IrInstGen *err_code_spill;
1612 AstNode *assumed_non_async;1641 AstNode *assumed_non_async;
16131642
1614 AstNode *fn_no_inline_set_node;1643 AstNode *fn_no_inline_set_node;
1615 AstNode *fn_static_eval_set_node;1644 AstNode *fn_static_eval_set_node;
16161645
1617 ZigList<IrInstructionAllocaGen *> alloca_gen_list;1646 ZigList<IrInstGenAlloca *> alloca_gen_list;
1618 ZigList<ZigVar *> variable_list;1647 ZigList<ZigVar *> variable_list;
16191648
1620 Buf *section_name;1649 Buf *section_name;
...@@ -1626,8 +1655,8 @@ struct ZigFn {...@@ -1626,8 +1655,8 @@ struct ZigFn {
1626 AstNode *non_async_node;1655 AstNode *non_async_node;
16271656
1628 ZigList<GlobalExport> export_list;1657 ZigList<GlobalExport> export_list;
1629 ZigList<IrInstructionCallGen *> call_list;1658 ZigList<IrInstGenCall *> call_list;
1630 ZigList<IrInstructionAwaitGen *> await_list;1659 ZigList<IrInstGenAwait *> await_list;
16311660
1632 LLVMValueRef valgrind_client_request_array;1661 LLVMValueRef valgrind_client_request_array;
16331662
...@@ -2098,8 +2127,9 @@ struct CodeGen {...@@ -2098,8 +2127,9 @@ struct CodeGen {
2098 Buf *zig_c_headers_dir; // Cannot be overridden; derived from zig_lib_dir.2127 Buf *zig_c_headers_dir; // Cannot be overridden; derived from zig_lib_dir.
2099 Buf *zig_std_special_dir; // Cannot be overridden; derived from zig_lib_dir.2128 Buf *zig_std_special_dir; // Cannot be overridden; derived from zig_lib_dir.
21002129
2101 IrInstruction *invalid_instruction;2130 IrInstSrc *invalid_inst_src;
2102 IrInstruction *unreach_instruction;2131 IrInstGen *invalid_inst_gen;
2132 IrInstGen *unreach_instruction;
21032133
2104 ZigValue panic_msg_vals[PanicMsgIdCount];2134 ZigValue panic_msg_vals[PanicMsgIdCount];
21052135
...@@ -2223,8 +2253,8 @@ struct ZigVar {...@@ -2223,8 +2253,8 @@ struct ZigVar {
2223 ZigValue *const_value;2253 ZigValue *const_value;
2224 ZigType *var_type;2254 ZigType *var_type;
2225 LLVMValueRef value_ref;2255 LLVMValueRef value_ref;
2226 IrInstruction *is_comptime;2256 IrInstSrc *is_comptime;
2227 IrInstruction *ptr_instruction;2257 IrInstGen *ptr_instruction;
2228 // which node is the declaration of the variable2258 // which node is the declaration of the variable
2229 AstNode *decl_node;2259 AstNode *decl_node;
2230 ZigLLVMDILocalVariable *di_loc_var;2260 ZigLLVMDILocalVariable *di_loc_var;
...@@ -2233,7 +2263,7 @@ struct ZigVar {...@@ -2233,7 +2263,7 @@ struct ZigVar {
2233 Scope *child_scope;2263 Scope *child_scope;
2234 LLVMValueRef param_value_ref;2264 LLVMValueRef param_value_ref;
2235 size_t mem_slot_index;2265 size_t mem_slot_index;
2236 IrExecutable *owner_exec;2266 IrExecutableSrc *owner_exec;
22372267
2238 Buf *section_name;2268 Buf *section_name;
22392269
...@@ -2324,11 +2354,11 @@ struct ScopeBlock {...@@ -2324,11 +2354,11 @@ struct ScopeBlock {
2324 Scope base;2354 Scope base;
23252355
2326 Buf *name;2356 Buf *name;
2327 IrBasicBlock *end_block;2357 IrBasicBlockSrc *end_block;
2328 IrInstruction *is_comptime;2358 IrInstSrc *is_comptime;
2329 ResultLocPeerParent *peer_parent;2359 ResultLocPeerParent *peer_parent;
2330 ZigList<IrInstruction *> *incoming_values;2360 ZigList<IrInstSrc *> *incoming_values;
2331 ZigList<IrBasicBlock *> *incoming_blocks;2361 ZigList<IrBasicBlockSrc *> *incoming_blocks;
23322362
2333 AstNode *safety_set_node;2363 AstNode *safety_set_node;
2334 AstNode *fast_math_set_node;2364 AstNode *fast_math_set_node;
...@@ -2379,11 +2409,11 @@ struct ScopeLoop {...@@ -2379,11 +2409,11 @@ struct ScopeLoop {
23792409
2380 LVal lval;2410 LVal lval;
2381 Buf *name;2411 Buf *name;
2382 IrBasicBlock *break_block;2412 IrBasicBlockSrc *break_block;
2383 IrBasicBlock *continue_block;2413 IrBasicBlockSrc *continue_block;
2384 IrInstruction *is_comptime;2414 IrInstSrc *is_comptime;
2385 ZigList<IrInstruction *> *incoming_values;2415 ZigList<IrInstSrc *> *incoming_values;
2386 ZigList<IrBasicBlock *> *incoming_blocks;2416 ZigList<IrBasicBlockSrc *> *incoming_blocks;
2387 ResultLocPeerParent *peer_parent;2417 ResultLocPeerParent *peer_parent;
2388 ScopeExpr *spill_scope;2418 ScopeExpr *spill_scope;
2389};2419};
...@@ -2394,7 +2424,7 @@ struct ScopeLoop {...@@ -2394,7 +2424,7 @@ struct ScopeLoop {
2394struct ScopeRuntime {2424struct ScopeRuntime {
2395 Scope base;2425 Scope base;
23962426
2397 IrInstruction *is_comptime;2427 IrInstSrc *is_comptime;
2398};2428};
23992429
2400// This scope is created for a suspend block in order to have labeled2430// This scope is created for a suspend block in order to have labeled
...@@ -2473,319 +2503,450 @@ enum AtomicRmwOp {...@@ -2473,319 +2503,450 @@ enum AtomicRmwOp {
2473// to another basic block.2503// to another basic block.
2474// Phi instructions must be first in a basic block.2504// Phi instructions must be first in a basic block.
2475// The last instruction in a basic block must be of type unreachable.2505// The last instruction in a basic block must be of type unreachable.
2476struct IrBasicBlock {2506struct IrBasicBlockSrc {
2477 ZigList<IrInstruction *> instruction_list;2507 ZigList<IrInstSrc *> instruction_list;
2478 IrBasicBlock *other;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;
2479 Scope *scope;2524 Scope *scope;
2480 const char *name_hint;2525 const char *name_hint;
2481 size_t debug_id;2526 uint32_t index; // index into the basic block list
2482 size_t ref_count;2527 uint32_t ref_count;
2483 // index into the basic block list
2484 size_t index;
2485 LLVMBasicBlockRef llvm_block;2528 LLVMBasicBlockRef llvm_block;
2486 LLVMBasicBlockRef llvm_exit_block;2529 LLVMBasicBlockRef llvm_exit_block;
2487 // The instruction that referenced this basic block and caused us to2530 // The instruction that referenced this basic block and caused us to
2488 // analyze the basic block. If the same instruction wants us to emit2531 // analyze the basic block. If the same instruction wants us to emit
2489 // the same basic block, then we re-generate it instead of saving it.2532 // the same basic block, then we re-generate it instead of saving it.
2490 IrInstruction *ref_instruction;2533 IrInst *ref_instruction;
2491 // When this is non-null, a branch to this basic block is only allowed2534 // When this is non-null, a branch to this basic block is only allowed
2492 // if the branch is comptime. The instruction points to the reason2535 // if the branch is comptime. The instruction points to the reason
2493 // the basic block must be comptime.2536 // the basic block must be comptime.
2494 IrInstruction *must_be_comptime_source_instr;2537 IrInst *must_be_comptime_source_instr;
2495 IrInstruction *suspend_instruction_ref;2538
2539 uint32_t debug_id;
2496 bool already_appended;2540 bool already_appended;
2497 bool suspended;
2498 bool in_resume_stack;
2499};2541};
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.
2506// Src instructions are generated by ir_gen_* functions in ir.cpp from AST.2543// Src instructions are generated by ir_gen_* functions in ir.cpp from AST.
2507// ir_analyze_* functions consume Src instructions and produce Gen instructions.2544// 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
2508// ir_render_* functions in codegen.cpp consume Gen instructions and produce LLVM IR.2688// ir_render_* functions in codegen.cpp consume Gen instructions and produce LLVM IR.
2509// Src instructions do not have type information; Gen instructions do.2689// Src instructions do not have type information; Gen instructions do.
2510enum IrInstructionId {2690enum IrInstGenId {
2511 IrInstructionIdInvalid,2691 IrInstGenIdInvalid,
2512 IrInstructionIdDeclVarSrc,2692 IrInstGenIdDeclVar,
2513 IrInstructionIdDeclVarGen,2693 IrInstGenIdBr,
2514 IrInstructionIdBr,2694 IrInstGenIdCondBr,
2515 IrInstructionIdCondBr,2695 IrInstGenIdSwitchBr,
2516 IrInstructionIdSwitchBr,2696 IrInstGenIdPhi,
2517 IrInstructionIdSwitchVar,2697 IrInstGenIdBinaryNot,
2518 IrInstructionIdSwitchElseVar,2698 IrInstGenIdNegation,
2519 IrInstructionIdSwitchTarget,2699 IrInstGenIdNegationWrapping,
2520 IrInstructionIdPhi,2700 IrInstGenIdBinOp,
2521 IrInstructionIdUnOp,2701 IrInstGenIdLoadPtr,
2522 IrInstructionIdBinOp,2702 IrInstGenIdStorePtr,
2523 IrInstructionIdMergeErrSets,2703 IrInstGenIdVectorStoreElem,
2524 IrInstructionIdLoadPtr,2704 IrInstGenIdStructFieldPtr,
2525 IrInstructionIdLoadPtrGen,2705 IrInstGenIdUnionFieldPtr,
2526 IrInstructionIdStorePtr,2706 IrInstGenIdElemPtr,
2527 IrInstructionIdVectorStoreElem,2707 IrInstGenIdVarPtr,
2528 IrInstructionIdFieldPtr,2708 IrInstGenIdReturnPtr,
2529 IrInstructionIdStructFieldPtr,2709 IrInstGenIdCall,
2530 IrInstructionIdUnionFieldPtr,2710 IrInstGenIdReturn,
2531 IrInstructionIdElemPtr,2711 IrInstGenIdCast,
2532 IrInstructionIdVarPtr,2712 IrInstGenIdResizeSlice,
2533 IrInstructionIdReturnPtr,2713 IrInstGenIdUnreachable,
2534 IrInstructionIdCallSrc,2714 IrInstGenIdAsm,
2535 IrInstructionIdCallSrcArgs,2715 IrInstGenIdTestNonNull,
2536 IrInstructionIdCallExtra,2716 IrInstGenIdOptionalUnwrapPtr,
2537 IrInstructionIdCallGen,2717 IrInstGenIdOptionalWrap,
2538 IrInstructionIdConst,2718 IrInstGenIdUnionTag,
2539 IrInstructionIdReturn,2719 IrInstGenIdClz,
2540 IrInstructionIdCast,2720 IrInstGenIdCtz,
2541 IrInstructionIdResizeSlice,2721 IrInstGenIdPopCount,
2542 IrInstructionIdContainerInitList,2722 IrInstGenIdBswap,
2543 IrInstructionIdContainerInitFields,2723 IrInstGenIdBitReverse,
2544 IrInstructionIdUnreachable,2724 IrInstGenIdRef,
2545 IrInstructionIdTypeOf,2725 IrInstGenIdErrName,
2546 IrInstructionIdSetCold,2726 IrInstGenIdCmpxchg,
2547 IrInstructionIdSetRuntimeSafety,2727 IrInstGenIdFence,
2548 IrInstructionIdSetFloatMode,2728 IrInstGenIdTruncate,
2549 IrInstructionIdArrayType,2729 IrInstGenIdShuffleVector,
2550 IrInstructionIdAnyFrameType,2730 IrInstGenIdSplat,
2551 IrInstructionIdSliceType,2731 IrInstGenIdBoolNot,
2552 IrInstructionIdAsmSrc,2732 IrInstGenIdMemset,
2553 IrInstructionIdAsmGen,2733 IrInstGenIdMemcpy,
2554 IrInstructionIdSizeOf,2734 IrInstGenIdSlice,
2555 IrInstructionIdTestNonNull,2735 IrInstGenIdBreakpoint,
2556 IrInstructionIdOptionalUnwrapPtr,2736 IrInstGenIdReturnAddress,
2557 IrInstructionIdOptionalWrap,2737 IrInstGenIdFrameAddress,
2558 IrInstructionIdUnionTag,2738 IrInstGenIdFrameHandle,
2559 IrInstructionIdClz,2739 IrInstGenIdFrameSize,
2560 IrInstructionIdCtz,2740 IrInstGenIdOverflowOp,
2561 IrInstructionIdPopCount,2741 IrInstGenIdTestErr,
2562 IrInstructionIdBswap,2742 IrInstGenIdMulAdd,
2563 IrInstructionIdBitReverse,2743 IrInstGenIdFloatOp,
2564 IrInstructionIdImport,2744 IrInstGenIdUnwrapErrCode,
2565 IrInstructionIdCImport,2745 IrInstGenIdUnwrapErrPayload,
2566 IrInstructionIdCInclude,2746 IrInstGenIdErrWrapCode,
2567 IrInstructionIdCDefine,2747 IrInstGenIdErrWrapPayload,
2568 IrInstructionIdCUndef,2748 IrInstGenIdPtrCast,
2569 IrInstructionIdRef,2749 IrInstGenIdBitCast,
2570 IrInstructionIdRefGen,2750 IrInstGenIdWidenOrShorten,
2571 IrInstructionIdCompileErr,2751 IrInstGenIdIntToPtr,
2572 IrInstructionIdCompileLog,2752 IrInstGenIdPtrToInt,
2573 IrInstructionIdErrName,2753 IrInstGenIdIntToEnum,
2574 IrInstructionIdEmbedFile,2754 IrInstGenIdIntToErr,
2575 IrInstructionIdCmpxchgSrc,2755 IrInstGenIdErrToInt,
2576 IrInstructionIdCmpxchgGen,2756 IrInstGenIdPanic,
2577 IrInstructionIdFence,2757 IrInstGenIdTagName,
2578 IrInstructionIdTruncate,2758 IrInstGenIdFieldParentPtr,
2579 IrInstructionIdIntCast,2759 IrInstGenIdAlignCast,
2580 IrInstructionIdFloatCast,2760 IrInstGenIdErrorReturnTrace,
2581 IrInstructionIdIntToFloat,2761 IrInstGenIdAtomicRmw,
2582 IrInstructionIdFloatToInt,2762 IrInstGenIdAtomicLoad,
2583 IrInstructionIdBoolToInt,2763 IrInstGenIdAtomicStore,
2584 IrInstructionIdIntType,2764 IrInstGenIdSaveErrRetAddr,
2585 IrInstructionIdVectorType,2765 IrInstGenIdVectorToArray,
2586 IrInstructionIdShuffleVector,2766 IrInstGenIdArrayToVector,
2587 IrInstructionIdSplatSrc,2767 IrInstGenIdAssertZero,
2588 IrInstructionIdSplatGen,2768 IrInstGenIdAssertNonNull,
2589 IrInstructionIdBoolNot,2769 IrInstGenIdPtrOfArrayToSlice,
2590 IrInstructionIdMemset,2770 IrInstGenIdSuspendBegin,
2591 IrInstructionIdMemcpy,2771 IrInstGenIdSuspendFinish,
2592 IrInstructionIdSliceSrc,2772 IrInstGenIdAwait,
2593 IrInstructionIdSliceGen,2773 IrInstGenIdResume,
2594 IrInstructionIdMemberCount,2774 IrInstGenIdSpillBegin,
2595 IrInstructionIdMemberType,2775 IrInstGenIdSpillEnd,
2596 IrInstructionIdMemberName,2776 IrInstGenIdVectorExtractElem,
2597 IrInstructionIdBreakpoint,2777 IrInstGenIdAlloca,
2598 IrInstructionIdReturnAddress,2778 IrInstGenIdConst,
2599 IrInstructionIdFrameAddress,2779};
2600 IrInstructionIdFrameHandle,2780
2601 IrInstructionIdFrameType,2781// Common fields between IrInstSrc and IrInstGen. This allows future passes
2602 IrInstructionIdFrameSizeSrc,2782// after pass2 to be added to zig.
2603 IrInstructionIdFrameSizeGen,2783struct IrInst {
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;
2689 // if ref_count is zero and the instruction has no side effects,2784 // if ref_count is zero and the instruction has no side effects,
2690 // the instruction can be omitted in codegen2785 // the instruction can be omitted in codegen
2691 uint32_t ref_count;2786 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
2692 // When analyzing IR, instructions that point to this instruction in the "old ir"2806 // When analyzing IR, instructions that point to this instruction in the "old ir"
2693 // can find the instruction that corresponds to this value in the "new ir"2807 // can find the instruction that corresponds to this value in the "new ir"
2694 // with this child field.2808 // with this child field.
2695 IrInstruction *child;2809 IrInstGen *child;
2696 IrBasicBlock *owner_bb;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;
2697 // Nearly any instruction can have to be stored as a local variable before suspending2825 // Nearly any instruction can have to be stored as a local variable before suspending
2698 // and then loaded after resuming, in case there is an expression with a suspend point2826 // and then loaded after resuming, in case there is an expression with a suspend point
2699 // in it, such as: x + await y2827 // in it, such as: x + await y
2700 IrInstruction *spill;2828 IrInstGen *spill;
2701 IrInstructionId id;
2702 // true if this instruction was generated by zig and not from user code
2703 bool is_gen;
27042829
2705 // for debugging purposes, these are useful to call to inspect the instruction2830 // for debugging purposes, these are useful to call to inspect the instruction
2706 void dump();2831 void dump();
2707 void src();2832 void src();
2708};2833};
27092834
2710struct IrInstructionDeclVarSrc {2835struct IrInstSrcDeclVar {
2711 IrInstruction base;2836 IrInstSrc base;
27122837
2713 ZigVar *var;2838 ZigVar *var;
2714 IrInstruction *var_type;2839 IrInstSrc *var_type;
2715 IrInstruction *align_value;2840 IrInstSrc *align_value;
2716 IrInstruction *ptr;2841 IrInstSrc *ptr;
2717};2842};
27182843
2719struct IrInstructionDeclVarGen {2844struct IrInstGenDeclVar {
2720 IrInstruction base;2845 IrInstGen base;
27212846
2722 ZigVar *var;2847 ZigVar *var;
2723 IrInstruction *var_ptr;2848 IrInstGen *var_ptr;
2724};2849};
27252850
2726struct IrInstructionCondBr {2851struct IrInstSrcCondBr {
2727 IrInstruction base;2852 IrInstSrc base;
27282853
2729 IrInstruction *condition;2854 IrInstSrc *condition;
2730 IrBasicBlock *then_block;2855 IrBasicBlockSrc *then_block;
2731 IrBasicBlock *else_block;2856 IrBasicBlockSrc *else_block;
2732 IrInstruction *is_comptime;2857 IrInstSrc *is_comptime;
2733 ResultLoc *result_loc;2858 ResultLoc *result_loc;
2734};2859};
27352860
2736struct IrInstructionBr {2861struct IrInstGenCondBr {
2737 IrInstruction base;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;2890 IrInstSrc *target_value;
2740 IrInstruction *is_comptime;2891 IrBasicBlockSrc *else_block;
2892 size_t case_count;
2893 IrInstSrcSwitchBrCase *cases;
2894 IrInstSrc *is_comptime;
2895 IrInstSrc *switch_prongs_void;
2741};2896};
27422897
2743struct IrInstructionSwitchBrCase {2898struct IrInstGenSwitchBrCase {
2744 IrInstruction *value;2899 IrInstGen *value;
2745 IrBasicBlock *block;2900 IrBasicBlockGen *block;
2746};2901};
27472902
2748struct IrInstructionSwitchBr {2903struct IrInstGenSwitchBr {
2749 IrInstruction base;2904 IrInstGen base;
27502905
2751 IrInstruction *target_value;2906 IrInstGen *target_value;
2752 IrBasicBlock *else_block;2907 IrBasicBlockGen *else_block;
2753 size_t case_count;2908 size_t case_count;
2754 IrInstructionSwitchBrCase *cases;2909 IrInstGenSwitchBrCase *cases;
2755 IrInstruction *is_comptime;
2756 IrInstruction *switch_prongs_void;
2757};2910};
27582911
2759struct IrInstructionSwitchVar {2912struct IrInstSrcSwitchVar {
2760 IrInstruction base;2913 IrInstSrc base;
27612914
2762 IrInstruction *target_value_ptr;2915 IrInstSrc *target_value_ptr;
2763 IrInstruction **prongs_ptr;2916 IrInstSrc **prongs_ptr;
2764 size_t prongs_len;2917 size_t prongs_len;
2765};2918};
27662919
2767struct IrInstructionSwitchElseVar {2920struct IrInstSrcSwitchElseVar {
2768 IrInstruction base;2921 IrInstSrc base;
27692922
2770 IrInstruction *target_value_ptr;2923 IrInstSrc *target_value_ptr;
2771 IrInstructionSwitchBr *switch_br;2924 IrInstSrcSwitchBr *switch_br;
2772};2925};
27732926
2774struct IrInstructionSwitchTarget {2927struct IrInstSrcSwitchTarget {
2775 IrInstruction base;2928 IrInstSrc base;
27762929
2777 IrInstruction *target_value_ptr;2930 IrInstSrc *target_value_ptr;
2778};2931};
27792932
2780struct IrInstructionPhi {2933struct IrInstSrcPhi {
2781 IrInstruction base;2934 IrInstSrc base;
27822935
2783 size_t incoming_count;2936 size_t incoming_count;
2784 IrBasicBlock **incoming_blocks;2937 IrBasicBlockSrc **incoming_blocks;
2785 IrInstruction **incoming_values;2938 IrInstSrc **incoming_values;
2786 ResultLocPeerParent *peer_parent;2939 ResultLocPeerParent *peer_parent;
2787};2940};
27882941
2942struct IrInstGenPhi {
2943 IrInstGen base;
2944
2945 size_t incoming_count;
2946 IrBasicBlockGen **incoming_blocks;
2947 IrInstGen **incoming_values;
2948};
2949
2789enum IrUnOp {2950enum IrUnOp {
2790 IrUnOpInvalid,2951 IrUnOpInvalid,
2791 IrUnOpBinNot,2952 IrUnOpBinNot,
...@@ -2795,15 +2956,30 @@ enum IrUnOp {...@@ -2795,15 +2956,30 @@ enum IrUnOp {
2795 IrUnOpOptional,2956 IrUnOpOptional,
2796};2957};
27972958
2798struct IrInstructionUnOp {2959struct IrInstSrcUnOp {
2799 IrInstruction base;2960 IrInstSrc base;
28002961
2801 IrUnOp op_id;2962 IrUnOp op_id;
2802 LVal lval;2963 LVal lval;
2803 IrInstruction *value;2964 IrInstSrc *value;
2804 ResultLoc *result_loc;2965 ResultLoc *result_loc;
2805};2966};
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
2807enum IrBinOp {2983enum IrBinOp {
2808 IrBinOpInvalid,2984 IrBinOpInvalid,
2809 IrBinOpBoolOr,2985 IrBinOpBoolOr,
...@@ -2838,113 +3014,144 @@ enum IrBinOp {...@@ -2838,113 +3014,144 @@ enum IrBinOp {
2838 IrBinOpArrayMult,3014 IrBinOpArrayMult,
2839};3015};
28403016
2841struct IrInstructionBinOp {3017struct IrInstSrcBinOp {
2842 IrInstruction base;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;3029 IrInstGen *op1;
2845 IrInstruction *op2;3030 IrInstGen *op2;
2846 IrBinOp op_id;3031 IrBinOp op_id;
2847 bool safety_check_on;3032 bool safety_check_on;
2848};3033};
28493034
2850struct IrInstructionMergeErrSets {3035struct IrInstSrcMergeErrSets {
2851 IrInstruction base;3036 IrInstSrc base;
28523037
2853 IrInstruction *op1;3038 IrInstSrc *op1;
2854 IrInstruction *op2;3039 IrInstSrc *op2;
2855 Buf *type_name;3040 Buf *type_name;
2856};3041};
28573042
2858struct IrInstructionLoadPtr {3043struct IrInstSrcLoadPtr {
2859 IrInstruction base;3044 IrInstSrc base;
28603045
2861 IrInstruction *ptr;3046 IrInstSrc *ptr;
2862};3047};
28633048
2864struct IrInstructionLoadPtrGen {3049struct IrInstGenLoadPtr {
2865 IrInstruction base;3050 IrInstGen base;
28663051
2867 IrInstruction *ptr;3052 IrInstGen *ptr;
2868 IrInstruction *result_loc;3053 IrInstGen *result_loc;
2869};3054};
28703055
2871struct IrInstructionStorePtr {3056struct IrInstSrcStorePtr {
2872 IrInstruction base;3057 IrInstSrc base;
3058
3059 IrInstSrc *ptr;
3060 IrInstSrc *value;
28733061
2874 bool allow_write_through_const;3062 bool allow_write_through_const;
2875 IrInstruction *ptr;
2876 IrInstruction *value;
2877};3063};
28783064
2879struct IrInstructionVectorStoreElem {3065struct IrInstGenStorePtr {
2880 IrInstruction base;3066 IrInstGen base;
28813067
2882 IrInstruction *vector_ptr;3068 IrInstGen *ptr;
2883 IrInstruction *index;3069 IrInstGen *value;
2884 IrInstruction *value;
2885};3070};
28863071
2887struct IrInstructionFieldPtr {3072struct IrInstGenVectorStoreElem {
2888 IrInstruction base;3073 IrInstGen base;
28893074
2890 bool initializing;3075 IrInstGen *vector_ptr;
2891 IrInstruction *container_ptr;3076 IrInstGen *index;
3077 IrInstGen *value;
3078};
3079
3080struct IrInstSrcFieldPtr {
3081 IrInstSrc base;
3082
3083 IrInstSrc *container_ptr;
2892 Buf *field_name_buffer;3084 Buf *field_name_buffer;
2893 IrInstruction *field_name_expr;3085 IrInstSrc *field_name_expr;
3086 bool initializing;
2894};3087};
28953088
2896struct IrInstructionStructFieldPtr {3089struct IrInstGenStructFieldPtr {
2897 IrInstruction base;3090 IrInstGen base;
28983091
2899 IrInstruction *struct_ptr;3092 IrInstGen *struct_ptr;
2900 TypeStructField *field;3093 TypeStructField *field;
2901 bool is_const;3094 bool is_const;
2902};3095};
29033096
2904struct IrInstructionUnionFieldPtr {3097struct IrInstGenUnionFieldPtr {
2905 IrInstruction base;3098 IrInstGen base;
29063099
3100 IrInstGen *union_ptr;
3101 TypeUnionField *field;
2907 bool safety_check_on;3102 bool safety_check_on;
2908 bool initializing;3103 bool initializing;
2909 IrInstruction *union_ptr;
2910 TypeUnionField *field;
2911};3104};
29123105
2913struct IrInstructionElemPtr {3106struct IrInstSrcElemPtr {
2914 IrInstruction base;3107 IrInstSrc base;
29153108
2916 IrInstruction *array_ptr;3109 IrInstSrc *array_ptr;
2917 IrInstruction *elem_index;3110 IrInstSrc *elem_index;
2918 AstNode *init_array_type_source_node;3111 AstNode *init_array_type_source_node;
2919 PtrLen ptr_len;3112 PtrLen ptr_len;
2920 bool safety_check_on;3113 bool safety_check_on;
2921};3114};
29223115
2923struct IrInstructionVarPtr {3116struct IrInstGenElemPtr {
2924 IrInstruction base;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
2926 ZigVar *var;3127 ZigVar *var;
2927 ScopeFnDef *crossed_fndef_scope;3128 ScopeFnDef *crossed_fndef_scope;
2928};3129};
29293130
3131struct IrInstGenVarPtr {
3132 IrInstGen base;
3133
3134 ZigVar *var;
3135};
3136
2930// For functions that have a return type for which handle_is_ptr is true, a3137// For functions that have a return type for which handle_is_ptr is true, a
2931// result location pointer is the secret first parameter ("sret"). This3138// result location pointer is the secret first parameter ("sret"). This
2932// instruction returns that pointer.3139// instruction returns that pointer.
2933struct IrInstructionReturnPtr {3140struct IrInstGenReturnPtr {
2934 IrInstruction base;3141 IrInstGen base;
2935};3142};
29363143
2937struct IrInstructionCallSrc {3144struct IrInstSrcCall {
2938 IrInstruction base;3145 IrInstSrc base;
29393146
2940 IrInstruction *fn_ref;3147 IrInstSrc *fn_ref;
2941 ZigFn *fn_entry;3148 ZigFn *fn_entry;
2942 size_t arg_count;3149 size_t arg_count;
2943 IrInstruction **args;3150 IrInstSrc **args;
2944 IrInstruction *ret_ptr;3151 IrInstSrc *ret_ptr;
2945 ResultLoc *result_loc;3152 ResultLoc *result_loc;
29463153
2947 IrInstruction *new_stack;3154 IrInstSrc *new_stack;
29483155
2949 CallModifier modifier;3156 CallModifier modifier;
2950 bool is_async_call_builtin;3157 bool is_async_call_builtin;
...@@ -2952,12 +3159,12 @@ struct IrInstructionCallSrc {...@@ -2952,12 +3159,12 @@ struct IrInstructionCallSrc {
29523159
2953// This is a pass1 instruction, used by @call when the args node is3160// This is a pass1 instruction, used by @call when the args node is
2954// a tuple or struct literal.3161// a tuple or struct literal.
2955struct IrInstructionCallSrcArgs {3162struct IrInstSrcCallArgs {
2956 IrInstruction base;3163 IrInstSrc base;
29573164
2958 IrInstruction *options;3165 IrInstSrc *options;
2959 IrInstruction *fn_ref;3166 IrInstSrc *fn_ref;
2960 IrInstruction **args_ptr;3167 IrInstSrc **args_ptr;
2961 size_t args_len;3168 size_t args_len;
2962 ResultLoc *result_loc;3169 ResultLoc *result_loc;
2963};3170};
...@@ -2965,42 +3172,54 @@ struct IrInstructionCallSrcArgs {...@@ -2965,42 +3172,54 @@ struct IrInstructionCallSrcArgs {
2965// This is a pass1 instruction, used by @call, when the args node3172// This is a pass1 instruction, used by @call, when the args node
2966// is not a literal.3173// is not a literal.
2967// `args` is expected to be either a struct or a tuple.3174// `args` is expected to be either a struct or a tuple.
2968struct IrInstructionCallExtra {3175struct IrInstSrcCallExtra {
2969 IrInstruction base;3176 IrInstSrc base;
29703177
2971 IrInstruction *options;3178 IrInstSrc *options;
2972 IrInstruction *fn_ref;3179 IrInstSrc *fn_ref;
2973 IrInstruction *args;3180 IrInstSrc *args;
2974 ResultLoc *result_loc;3181 ResultLoc *result_loc;
2975};3182};
29763183
2977struct IrInstructionCallGen {3184struct IrInstGenCall {
2978 IrInstruction base;3185 IrInstGen base;
29793186
2980 IrInstruction *fn_ref;3187 IrInstGen *fn_ref;
2981 ZigFn *fn_entry;3188 ZigFn *fn_entry;
2982 size_t arg_count;3189 size_t arg_count;
2983 IrInstruction **args;3190 IrInstGen **args;
2984 IrInstruction *result_loc;3191 IrInstGen *result_loc;
2985 IrInstruction *frame_result_loc;3192 IrInstGen *frame_result_loc;
2986 IrInstruction *new_stack;3193 IrInstGen *new_stack;
29873194
2988 CallModifier modifier;3195 CallModifier modifier;
29893196
2990 bool is_async_call_builtin;3197 bool is_async_call_builtin;
2991};3198};
29923199
2993struct IrInstructionConst {3200struct IrInstSrcConst {
2994 IrInstruction base;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;
2995};3214};
29963215
2997// When an IrExecutable is not in a function, a return instruction means that3216// When an IrExecutable is not in a function, a return instruction means that
2998// the expression returns with that value, even though a return statement from3217// the expression returns with that value, even though a return statement from
2999// an AST perspective is invalid.3218// an AST perspective is invalid.
3000struct IrInstructionReturn {3219struct IrInstGenReturn {
3001 IrInstruction base;3220 IrInstGen base;
30023221
3003 IrInstruction *operand;3222 IrInstGen *operand;
3004};3223};
30053224
3006enum CastOp {3225enum CastOp {
...@@ -3015,89 +3234,92 @@ enum CastOp {...@@ -3015,89 +3234,92 @@ enum CastOp {
3015};3234};
30163235
3017// TODO get rid of this instruction, replace with instructions for each op code3236// TODO get rid of this instruction, replace with instructions for each op code
3018struct IrInstructionCast {3237struct IrInstGenCast {
3019 IrInstruction base;3238 IrInstGen base;
30203239
3021 IrInstruction *value;3240 IrInstGen *value;
3022 ZigType *dest_type;
3023 CastOp cast_op;3241 CastOp cast_op;
3024};3242};
30253243
3026struct IrInstructionResizeSlice {3244struct IrInstGenResizeSlice {
3027 IrInstruction base;3245 IrInstGen base;
30283246
3029 IrInstruction *operand;3247 IrInstGen *operand;
3030 IrInstruction *result_loc;3248 IrInstGen *result_loc;
3031};3249};
30323250
3033struct IrInstructionContainerInitList {3251struct IrInstSrcContainerInitList {
3034 IrInstruction base;3252 IrInstSrc base;
30353253
3036 IrInstruction *elem_type;3254 IrInstSrc *elem_type;
3037 size_t item_count;3255 size_t item_count;
3038 IrInstruction **elem_result_loc_list;3256 IrInstSrc **elem_result_loc_list;
3039 IrInstruction *result_loc;3257 IrInstSrc *result_loc;
3040 AstNode *init_array_type_source_node;3258 AstNode *init_array_type_source_node;
3041};3259};
30423260
3043struct IrInstructionContainerInitFieldsField {3261struct IrInstSrcContainerInitFieldsField {
3044 Buf *name;3262 Buf *name;
3045 AstNode *source_node;3263 AstNode *source_node;
3046 TypeStructField *type_struct_field;3264 TypeStructField *type_struct_field;
3047 IrInstruction *result_loc;3265 IrInstSrc *result_loc;
3048};3266};
30493267
3050struct IrInstructionContainerInitFields {3268struct IrInstSrcContainerInitFields {
3051 IrInstruction base;3269 IrInstSrc base;
30523270
3053 size_t field_count;3271 size_t field_count;
3054 IrInstructionContainerInitFieldsField *fields;3272 IrInstSrcContainerInitFieldsField *fields;
3055 IrInstruction *result_loc;3273 IrInstSrc *result_loc;
3274};
3275
3276struct IrInstSrcUnreachable {
3277 IrInstSrc base;
3056};3278};
30573279
3058struct IrInstructionUnreachable {3280struct IrInstGenUnreachable {
3059 IrInstruction base;3281 IrInstGen base;
3060};3282};
30613283
3062struct IrInstructionTypeOf {3284struct IrInstSrcTypeOf {
3063 IrInstruction base;3285 IrInstSrc base;
30643286
3065 IrInstruction *value;3287 IrInstSrc *value;
3066};3288};
30673289
3068struct IrInstructionSetCold {3290struct IrInstSrcSetCold {
3069 IrInstruction base;3291 IrInstSrc base;
30703292
3071 IrInstruction *is_cold;3293 IrInstSrc *is_cold;
3072};3294};
30733295
3074struct IrInstructionSetRuntimeSafety {3296struct IrInstSrcSetRuntimeSafety {
3075 IrInstruction base;3297 IrInstSrc base;
30763298
3077 IrInstruction *safety_on;3299 IrInstSrc *safety_on;
3078};3300};
30793301
3080struct IrInstructionSetFloatMode {3302struct IrInstSrcSetFloatMode {
3081 IrInstruction base;3303 IrInstSrc base;
30823304
3083 IrInstruction *scope_value;3305 IrInstSrc *scope_value;
3084 IrInstruction *mode_value;3306 IrInstSrc *mode_value;
3085};3307};
30863308
3087struct IrInstructionArrayType {3309struct IrInstSrcArrayType {
3088 IrInstruction base;3310 IrInstSrc base;
30893311
3090 IrInstruction *size;3312 IrInstSrc *size;
3091 IrInstruction *sentinel;3313 IrInstSrc *sentinel;
3092 IrInstruction *child_type;3314 IrInstSrc *child_type;
3093};3315};
30943316
3095struct IrInstructionPtrType {3317struct IrInstSrcPtrType {
3096 IrInstruction base;3318 IrInstSrc base;
30973319
3098 IrInstruction *sentinel;3320 IrInstSrc *sentinel;
3099 IrInstruction *align_value;3321 IrInstSrc *align_value;
3100 IrInstruction *child_type;3322 IrInstSrc *child_type;
3101 uint32_t bit_offset_start;3323 uint32_t bit_offset_start;
3102 uint32_t host_int_bytes;3324 uint32_t host_int_bytes;
3103 PtrLen ptr_len;3325 PtrLen ptr_len;
...@@ -3106,375 +3328,459 @@ struct IrInstructionPtrType {...@@ -3106,375 +3328,459 @@ struct IrInstructionPtrType {
3106 bool is_allow_zero;3328 bool is_allow_zero;
3107};3329};
31083330
3109struct IrInstructionAnyFrameType {3331struct IrInstSrcAnyFrameType {
3110 IrInstruction base;3332 IrInstSrc base;
31113333
3112 IrInstruction *payload_type;3334 IrInstSrc *payload_type;
3113};3335};
31143336
3115struct IrInstructionSliceType {3337struct IrInstSrcSliceType {
3116 IrInstruction base;3338 IrInstSrc base;
31173339
3118 IrInstruction *sentinel;3340 IrInstSrc *sentinel;
3119 IrInstruction *align_value;3341 IrInstSrc *align_value;
3120 IrInstruction *child_type;3342 IrInstSrc *child_type;
3121 bool is_const;3343 bool is_const;
3122 bool is_volatile;3344 bool is_volatile;
3123 bool is_allow_zero;3345 bool is_allow_zero;
3124};3346};
31253347
3126struct IrInstructionAsmSrc {3348struct IrInstSrcAsm {
3127 IrInstruction base;3349 IrInstSrc base;
31283350
3129 IrInstruction *asm_template;3351 IrInstSrc *asm_template;
3130 IrInstruction **input_list;3352 IrInstSrc **input_list;
3131 IrInstruction **output_types;3353 IrInstSrc **output_types;
3132 ZigVar **output_vars;3354 ZigVar **output_vars;
3133 size_t return_count;3355 size_t return_count;
3134 bool has_side_effects;3356 bool has_side_effects;
3135 bool is_global;3357 bool is_global;
3136};3358};
31373359
3138struct IrInstructionAsmGen {3360struct IrInstGenAsm {
3139 IrInstruction base;3361 IrInstGen base;
31403362
3141 Buf *asm_template;3363 Buf *asm_template;
3142 AsmToken *token_list;3364 AsmToken *token_list;
3143 size_t token_list_len;3365 size_t token_list_len;
3144 IrInstruction **input_list;3366 IrInstGen **input_list;
3145 IrInstruction **output_types;3367 IrInstGen **output_types;
3146 ZigVar **output_vars;3368 ZigVar **output_vars;
3147 size_t return_count;3369 size_t return_count;
3148 bool has_side_effects;3370 bool has_side_effects;
3149};3371};
31503372
3151struct IrInstructionSizeOf {3373struct IrInstSrcSizeOf {
3152 IrInstruction base;3374 IrInstSrc base;
31533375
3376 IrInstSrc *type_value;
3154 bool bit_size;3377 bool bit_size;
3155 IrInstruction *type_value;
3156};3378};
31573379
3158// returns true if nonnull, returns false if null3380// returns true if nonnull, returns false if null
3159// this is so that `zeroes` sets maybe values to null3381struct IrInstSrcTestNonNull {
3160struct IrInstructionTestNonNull {3382 IrInstSrc base;
3161 IrInstruction base;3383
3384 IrInstSrc *value;
3385};
3386
3387struct IrInstGenTestNonNull {
3388 IrInstGen base;
31623389
3163 IrInstruction *value;3390 IrInstGen *value;
3164};3391};
31653392
3166// Takes a pointer to an optional value, returns a pointer3393// Takes a pointer to an optional value, returns a pointer
3167// to the payload.3394// to the payload.
3168struct IrInstructionOptionalUnwrapPtr {3395struct IrInstSrcOptionalUnwrapPtr {
3169 IrInstruction base;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;
3171 bool safety_check_on;3407 bool safety_check_on;
3172 bool initializing;3408 bool initializing;
3173 IrInstruction *base_ptr;
3174};3409};
31753410
3176struct IrInstructionCtz {3411struct IrInstSrcCtz {
3177 IrInstruction base;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;3434 IrInstGen *op;
3180 IrInstruction *op;
3181};3435};
31823436
3183struct IrInstructionClz {3437struct IrInstSrcPopCount {
3184 IrInstruction base;3438 IrInstSrc base;
31853439
3186 IrInstruction *type;3440 IrInstSrc *type;
3187 IrInstruction *op;3441 IrInstSrc *op;
3188};3442};
31893443
3190struct IrInstructionPopCount {3444struct IrInstGenPopCount {
3191 IrInstruction base;3445 IrInstGen base;
31923446
3193 IrInstruction *type;3447 IrInstGen *op;
3194 IrInstruction *op;
3195};3448};
31963449
3197struct IrInstructionUnionTag {3450struct IrInstGenUnionTag {
3198 IrInstruction base;3451 IrInstGen base;
31993452
3200 IrInstruction *value;3453 IrInstGen *value;
3201};3454};
32023455
3203struct IrInstructionImport {3456struct IrInstSrcImport {
3204 IrInstruction base;3457 IrInstSrc base;
32053458
3206 IrInstruction *name;3459 IrInstSrc *name;
3207};3460};
32083461
3209struct IrInstructionRef {3462struct IrInstSrcRef {
3210 IrInstruction base;3463 IrInstSrc base;
32113464
3212 IrInstruction *value;3465 IrInstSrc *value;
3213 bool is_const;3466 bool is_const;
3214 bool is_volatile;3467 bool is_volatile;
3215};3468};
32163469
3217struct IrInstructionRefGen {3470struct IrInstGenRef {
3218 IrInstruction base;3471 IrInstGen base;
32193472
3220 IrInstruction *operand;3473 IrInstGen *operand;
3221 IrInstruction *result_loc;3474 IrInstGen *result_loc;
3222};3475};
32233476
3224struct IrInstructionCompileErr {3477struct IrInstSrcCompileErr {
3225 IrInstruction base;3478 IrInstSrc base;
32263479
3227 IrInstruction *msg;3480 IrInstSrc *msg;
3228};3481};
32293482
3230struct IrInstructionCompileLog {3483struct IrInstSrcCompileLog {
3231 IrInstruction base;3484 IrInstSrc base;
32323485
3233 size_t msg_count;3486 size_t msg_count;
3234 IrInstruction **msg_list;3487 IrInstSrc **msg_list;
3235};3488};
32363489
3237struct IrInstructionErrName {3490struct IrInstSrcErrName {
3238 IrInstruction base;3491 IrInstSrc base;
32393492
3240 IrInstruction *value;3493 IrInstSrc *value;
3241};3494};
32423495
3243struct IrInstructionCImport {3496struct IrInstGenErrName {
3244 IrInstruction base;3497 IrInstGen base;
3498
3499 IrInstGen *value;
3500};
3501
3502struct IrInstSrcCImport {
3503 IrInstSrc base;
3245};3504};
32463505
3247struct IrInstructionCInclude {3506struct IrInstSrcCInclude {
3248 IrInstruction base;3507 IrInstSrc base;
32493508
3250 IrInstruction *name;3509 IrInstSrc *name;
3251};3510};
32523511
3253struct IrInstructionCDefine {3512struct IrInstSrcCDefine {
3254 IrInstruction base;3513 IrInstSrc base;
32553514
3256 IrInstruction *name;3515 IrInstSrc *name;
3257 IrInstruction *value;3516 IrInstSrc *value;
3258};3517};
32593518
3260struct IrInstructionCUndef {3519struct IrInstSrcCUndef {
3261 IrInstruction base;3520 IrInstSrc base;
32623521
3263 IrInstruction *name;3522 IrInstSrc *name;
3264};3523};
32653524
3266struct IrInstructionEmbedFile {3525struct IrInstSrcEmbedFile {
3267 IrInstruction base;3526 IrInstSrc base;
32683527
3269 IrInstruction *name;3528 IrInstSrc *name;
3270};3529};
32713530
3272struct IrInstructionCmpxchgSrc {3531struct IrInstSrcCmpxchg {
3273 IrInstruction base;3532 IrInstSrc base;
32743533
3275 bool is_weak;3534 bool is_weak;
3276 IrInstruction *type_value;3535 IrInstSrc *type_value;
3277 IrInstruction *ptr;3536 IrInstSrc *ptr;
3278 IrInstruction *cmp_value;3537 IrInstSrc *cmp_value;
3279 IrInstruction *new_value;3538 IrInstSrc *new_value;
3280 IrInstruction *success_order_value;3539 IrInstSrc *success_order_value;
3281 IrInstruction *failure_order_value;3540 IrInstSrc *failure_order_value;
3282 ResultLoc *result_loc;3541 ResultLoc *result_loc;
3283};3542};
32843543
3285struct IrInstructionCmpxchgGen {3544struct IrInstGenCmpxchg {
3286 IrInstruction base;3545 IrInstGen base;
32873546
3288 bool is_weak;
3289 AtomicOrder success_order;3547 AtomicOrder success_order;
3290 AtomicOrder failure_order;3548 AtomicOrder failure_order;
3291 IrInstruction *ptr;3549 IrInstGen *ptr;
3292 IrInstruction *cmp_value;3550 IrInstGen *cmp_value;
3293 IrInstruction *new_value;3551 IrInstGen *new_value;
3294 IrInstruction *result_loc;3552 IrInstGen *result_loc;
3553 bool is_weak;
3295};3554};
32963555
3297struct IrInstructionFence {3556struct IrInstSrcFence {
3298 IrInstruction base;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:
3303 AtomicOrder order;3565 AtomicOrder order;
3304};3566};
33053567
3306struct IrInstructionTruncate {3568struct IrInstSrcTruncate {
3307 IrInstruction base;3569 IrInstSrc base;
3570
3571 IrInstSrc *dest_type;
3572 IrInstSrc *target;
3573};
3574
3575struct IrInstGenTruncate {
3576 IrInstGen base;
33083577
3309 IrInstruction *dest_type;3578 IrInstGen *target;
3310 IrInstruction *target;
3311};3579};
33123580
3313struct IrInstructionIntCast {3581struct IrInstSrcIntCast {
3314 IrInstruction base;3582 IrInstSrc base;
33153583
3316 IrInstruction *dest_type;3584 IrInstSrc *dest_type;
3317 IrInstruction *target;3585 IrInstSrc *target;
3318};3586};
33193587
3320struct IrInstructionFloatCast {3588struct IrInstSrcFloatCast {
3321 IrInstruction base;3589 IrInstSrc base;
33223590
3323 IrInstruction *dest_type;3591 IrInstSrc *dest_type;
3324 IrInstruction *target;3592 IrInstSrc *target;
3325};3593};
33263594
3327struct IrInstructionErrSetCast {3595struct IrInstSrcErrSetCast {
3328 IrInstruction base;3596 IrInstSrc base;
33293597
3330 IrInstruction *dest_type;3598 IrInstSrc *dest_type;
3331 IrInstruction *target;3599 IrInstSrc *target;
3332};3600};
33333601
3334struct IrInstructionToBytes {3602struct IrInstSrcToBytes {
3335 IrInstruction base;3603 IrInstSrc base;
33363604
3337 IrInstruction *target;3605 IrInstSrc *target;
3338 ResultLoc *result_loc;3606 ResultLoc *result_loc;
3339};3607};
33403608
3341struct IrInstructionFromBytes {3609struct IrInstSrcFromBytes {
3342 IrInstruction base;3610 IrInstSrc base;
33433611
3344 IrInstruction *dest_child_type;3612 IrInstSrc *dest_child_type;
3345 IrInstruction *target;3613 IrInstSrc *target;
3346 ResultLoc *result_loc;3614 ResultLoc *result_loc;
3347};3615};
33483616
3349struct IrInstructionIntToFloat {3617struct IrInstSrcIntToFloat {
3350 IrInstruction base;3618 IrInstSrc base;
33513619
3352 IrInstruction *dest_type;3620 IrInstSrc *dest_type;
3353 IrInstruction *target;3621 IrInstSrc *target;
3354};3622};
33553623
3356struct IrInstructionFloatToInt {3624struct IrInstSrcFloatToInt {
3357 IrInstruction base;3625 IrInstSrc base;
33583626
3359 IrInstruction *dest_type;3627 IrInstSrc *dest_type;
3360 IrInstruction *target;3628 IrInstSrc *target;
3361};3629};
33623630
3363struct IrInstructionBoolToInt {3631struct IrInstSrcBoolToInt {
3364 IrInstruction base;3632 IrInstSrc base;
33653633
3366 IrInstruction *target;3634 IrInstSrc *target;
3367};3635};
33683636
3369struct IrInstructionIntType {3637struct IrInstSrcIntType {
3370 IrInstruction base;3638 IrInstSrc base;
33713639
3372 IrInstruction *is_signed;3640 IrInstSrc *is_signed;
3373 IrInstruction *bit_count;3641 IrInstSrc *bit_count;
3374};3642};
33753643
3376struct IrInstructionVectorType {3644struct IrInstSrcVectorType {
3377 IrInstruction base;3645 IrInstSrc base;
33783646
3379 IrInstruction *len;3647 IrInstSrc *len;
3380 IrInstruction *elem_type;3648 IrInstSrc *elem_type;
3381};3649};
33823650
3383struct IrInstructionBoolNot {3651struct IrInstSrcBoolNot {
3384 IrInstruction base;3652 IrInstSrc base;
33853653
3386 IrInstruction *value;3654 IrInstSrc *value;
3387};3655};
33883656
3389struct IrInstructionMemset {3657struct IrInstGenBoolNot {
3390 IrInstruction base;3658 IrInstGen base;
33913659
3392 IrInstruction *dest_ptr;3660 IrInstGen *value;
3393 IrInstruction *byte;
3394 IrInstruction *count;
3395};3661};
33963662
3397struct IrInstructionMemcpy {3663struct IrInstSrcMemset {
3398 IrInstruction base;3664 IrInstSrc base;
33993665
3400 IrInstruction *dest_ptr;3666 IrInstSrc *dest_ptr;
3401 IrInstruction *src_ptr;3667 IrInstSrc *byte;
3402 IrInstruction *count;3668 IrInstSrc *count;
3403};3669};
34043670
3405struct IrInstructionSliceSrc {3671struct IrInstGenMemset {
3406 IrInstruction base;3672 IrInstGen base;
34073673
3408 bool safety_check_on;3674 IrInstGen *dest_ptr;
3409 IrInstruction *ptr;3675 IrInstGen *byte;
3410 IrInstruction *start;3676 IrInstGen *count;
3411 IrInstruction *end;3677};
3412 IrInstruction *sentinel;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;
3413 ResultLoc *result_loc;3702 ResultLoc *result_loc;
3703 bool safety_check_on;
3414};3704};
34153705
3416struct IrInstructionSliceGen {3706struct IrInstGenSlice {
3417 IrInstruction base;3707 IrInstGen base;
34183708
3709 IrInstGen *ptr;
3710 IrInstGen *start;
3711 IrInstGen *end;
3712 IrInstGen *result_loc;
3419 bool safety_check_on;3713 bool safety_check_on;
3420 IrInstruction *ptr;
3421 IrInstruction *start;
3422 IrInstruction *end;
3423 IrInstruction *result_loc;
3424};3714};
34253715
3426struct IrInstructionMemberCount {3716struct IrInstSrcMemberCount {
3427 IrInstruction base;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;
3430};3727};
34313728
3432struct IrInstructionMemberType {3729struct IrInstSrcMemberName {
3433 IrInstruction base;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;3740struct IrInstGenBreakpoint {
3436 IrInstruction *member_index;3741 IrInstGen base;
3437};3742};
34383743
3439struct IrInstructionMemberName {3744struct IrInstSrcReturnAddress {
3440 IrInstruction base;3745 IrInstSrc base;
3746};
34413747
3442 IrInstruction *container_type;3748struct IrInstGenReturnAddress {
3443 IrInstruction *member_index;3749 IrInstGen base;
3444};3750};
34453751
3446struct IrInstructionBreakpoint {3752struct IrInstSrcFrameAddress {
3447 IrInstruction base;3753 IrInstSrc base;
3448};3754};
34493755
3450struct IrInstructionReturnAddress {3756struct IrInstGenFrameAddress {
3451 IrInstruction base;3757 IrInstGen base;
3452};3758};
34533759
3454struct IrInstructionFrameAddress {3760struct IrInstSrcFrameHandle {
3455 IrInstruction base;3761 IrInstSrc base;
3456};3762};
34573763
3458struct IrInstructionFrameHandle {3764struct IrInstGenFrameHandle {
3459 IrInstruction base;3765 IrInstGen base;
3460};3766};
34613767
3462struct IrInstructionFrameType {3768struct IrInstSrcFrameType {
3463 IrInstruction base;3769 IrInstSrc base;
34643770
3465 IrInstruction *fn;3771 IrInstSrc *fn;
3466};3772};
34673773
3468struct IrInstructionFrameSizeSrc {3774struct IrInstSrcFrameSize {
3469 IrInstruction base;3775 IrInstSrc base;
34703776
3471 IrInstruction *fn;3777 IrInstSrc *fn;
3472};3778};
34733779
3474struct IrInstructionFrameSizeGen {3780struct IrInstGenFrameSize {
3475 IrInstruction base;3781 IrInstGen base;
34763782
3477 IrInstruction *fn;3783 IrInstGen *fn;
3478};3784};
34793785
3480enum IrOverflowOp {3786enum IrOverflowOp {
...@@ -3484,560 +3790,713 @@ enum IrOverflowOp {...@@ -3484,560 +3790,713 @@ enum IrOverflowOp {
3484 IrOverflowOpShl,3790 IrOverflowOpShl,
3485};3791};
34863792
3487struct IrInstructionOverflowOp {3793struct IrInstSrcOverflowOp {
3488 IrInstruction base;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
3490 IrOverflowOp op;3806 IrOverflowOp op;
3491 IrInstruction *type_value;3807 IrInstGen *op1;
3492 IrInstruction *op1;3808 IrInstGen *op2;
3493 IrInstruction *op2;3809 IrInstGen *result_ptr;
3494 IrInstruction *result_ptr;
34953810
3811 // TODO can this field be removed?
3496 ZigType *result_ptr_type;3812 ZigType *result_ptr_type;
3497};3813};
34983814
3499struct IrInstructionMulAdd {3815struct IrInstSrcMulAdd {
3500 IrInstruction base;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;3827 IrInstGen *op1;
3503 IrInstruction *op1;3828 IrInstGen *op2;
3504 IrInstruction *op2;3829 IrInstGen *op3;
3505 IrInstruction *op3;
3506};3830};
35073831
3508struct IrInstructionAlignOf {3832struct IrInstSrcAlignOf {
3509 IrInstruction base;3833 IrInstSrc base;
35103834
3511 IrInstruction *type_value;3835 IrInstSrc *type_value;
3512};3836};
35133837
3514// returns true if error, returns false if not error3838// returns true if error, returns false if not error
3515struct IrInstructionTestErrSrc {3839struct IrInstSrcTestErr {
3516 IrInstruction base;3840 IrInstSrc base;
35173841
3842 IrInstSrc *base_ptr;
3518 bool resolve_err_set;3843 bool resolve_err_set;
3519 bool base_ptr_is_payload;3844 bool base_ptr_is_payload;
3520 IrInstruction *base_ptr;
3521};3845};
35223846
3523struct IrInstructionTestErrGen {3847struct IrInstGenTestErr {
3524 IrInstruction base;3848 IrInstGen base;
35253849
3526 IrInstruction *err_union;3850 IrInstGen *err_union;
3527};3851};
35283852
3529// Takes an error union pointer, returns a pointer to the error code.3853// Takes an error union pointer, returns a pointer to the error code.
3530struct IrInstructionUnwrapErrCode {3854struct IrInstSrcUnwrapErrCode {
3531 IrInstruction base;3855 IrInstSrc base;
35323856
3857 IrInstSrc *err_union_ptr;
3533 bool initializing;3858 bool initializing;
3534 IrInstruction *err_union_ptr;
3535};3859};
35363860
3537struct IrInstructionUnwrapErrPayload {3861struct IrInstGenUnwrapErrCode {
3538 IrInstruction base;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;
3540 bool safety_check_on;3880 bool safety_check_on;
3541 bool initializing;3881 bool initializing;
3542 IrInstruction *value;
3543};3882};
35443883
3545struct IrInstructionOptionalWrap {3884struct IrInstGenOptionalWrap {
3546 IrInstruction base;3885 IrInstGen base;
35473886
3548 IrInstruction *operand;3887 IrInstGen *operand;
3549 IrInstruction *result_loc;3888 IrInstGen *result_loc;
3550};3889};
35513890
3552struct IrInstructionErrWrapPayload {3891struct IrInstGenErrWrapPayload {
3553 IrInstruction base;3892 IrInstGen base;
35543893
3555 IrInstruction *operand;3894 IrInstGen *operand;
3556 IrInstruction *result_loc;3895 IrInstGen *result_loc;
3557};3896};
35583897
3559struct IrInstructionErrWrapCode {3898struct IrInstGenErrWrapCode {
3560 IrInstruction base;3899 IrInstGen base;
35613900
3562 IrInstruction *operand;3901 IrInstGen *operand;
3563 IrInstruction *result_loc;3902 IrInstGen *result_loc;
3564};3903};
35653904
3566struct IrInstructionFnProto {3905struct IrInstSrcFnProto {
3567 IrInstruction base;3906 IrInstSrc base;
35683907
3569 IrInstruction **param_types;3908 IrInstSrc **param_types;
3570 IrInstruction *align_value;3909 IrInstSrc *align_value;
3571 IrInstruction *callconv_value;3910 IrInstSrc *callconv_value;
3572 IrInstruction *return_type;3911 IrInstSrc *return_type;
3573 bool is_var_args;3912 bool is_var_args;
3574};3913};
35753914
3576// true if the target value is compile time known, false otherwise3915// true if the target value is compile time known, false otherwise
3577struct IrInstructionTestComptime {3916struct IrInstSrcTestComptime {
3578 IrInstruction base;3917 IrInstSrc base;
35793918
3580 IrInstruction *value;3919 IrInstSrc *value;
3581};3920};
35823921
3583struct IrInstructionPtrCastSrc {3922struct IrInstSrcPtrCast {
3584 IrInstruction base;3923 IrInstSrc base;
35853924
3586 IrInstruction *dest_type;3925 IrInstSrc *dest_type;
3587 IrInstruction *ptr;3926 IrInstSrc *ptr;
3588 bool safety_check_on;3927 bool safety_check_on;
3589};3928};
35903929
3591struct IrInstructionPtrCastGen {3930struct IrInstGenPtrCast {
3592 IrInstruction base;3931 IrInstGen base;
35933932
3594 IrInstruction *ptr;3933 IrInstGen *ptr;
3595 bool safety_check_on;3934 bool safety_check_on;
3596};3935};
35973936
3598struct IrInstructionImplicitCast {3937struct IrInstSrcImplicitCast {
3599 IrInstruction base;3938 IrInstSrc base;
36003939
3601 IrInstruction *operand;3940 IrInstSrc *operand;
3602 ResultLocCast *result_loc_cast;3941 ResultLocCast *result_loc_cast;
3603};3942};
36043943
3605struct IrInstructionBitCastSrc {3944struct IrInstSrcBitCast {
3606 IrInstruction base;3945 IrInstSrc base;
36073946
3608 IrInstruction *operand;3947 IrInstSrc *operand;
3609 ResultLocBitCast *result_loc_bit_cast;3948 ResultLocBitCast *result_loc_bit_cast;
3610};3949};
36113950
3612struct IrInstructionBitCastGen {3951struct IrInstGenBitCast {
3613 IrInstruction base;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;
3616};3986};
36173987
3618struct IrInstructionWidenOrShorten {3988struct IrInstSrcIntToEnum {
3619 IrInstruction base;3989 IrInstSrc base;
36203990
3621 IrInstruction *target;3991 IrInstSrc *dest_type;
3992 IrInstSrc *target;
3622};3993};
36233994
3624struct IrInstructionPtrToInt {3995struct IrInstGenIntToEnum {
3625 IrInstruction base;3996 IrInstGen base;
36263997
3627 IrInstruction *target;3998 IrInstGen *target;
3628};3999};
36294000
3630struct IrInstructionIntToPtr {4001struct IrInstSrcEnumToInt {
3631 IrInstruction base;4002 IrInstSrc base;
36324003
3633 IrInstruction *dest_type;4004 IrInstSrc *target;
3634 IrInstruction *target;
3635};4005};
36364006
3637struct IrInstructionIntToEnum {4007struct IrInstSrcIntToErr {
3638 IrInstruction base;4008 IrInstSrc base;
36394009
3640 IrInstruction *dest_type;4010 IrInstSrc *target;
3641 IrInstruction *target;
3642};4011};
36434012
3644struct IrInstructionEnumToInt {4013struct IrInstGenIntToErr {
3645 IrInstruction base;4014 IrInstGen base;
36464015
3647 IrInstruction *target;4016 IrInstGen *target;
3648};4017};
36494018
3650struct IrInstructionIntToErr {4019struct IrInstSrcErrToInt {
3651 IrInstruction base;4020 IrInstSrc base;
36524021
3653 IrInstruction *target;4022 IrInstSrc *target;
3654};4023};
36554024
3656struct IrInstructionErrToInt {4025struct IrInstGenErrToInt {
3657 IrInstruction base;4026 IrInstGen base;
36584027
3659 IrInstruction *target;4028 IrInstGen *target;
3660};4029};
36614030
3662struct IrInstructionCheckSwitchProngsRange {4031struct IrInstSrcCheckSwitchProngsRange {
3663 IrInstruction *start;4032 IrInstSrc *start;
3664 IrInstruction *end;4033 IrInstSrc *end;
3665};4034};
36664035
3667struct IrInstructionCheckSwitchProngs {4036struct IrInstSrcCheckSwitchProngs {
3668 IrInstruction base;4037 IrInstSrc base;
36694038
3670 IrInstruction *target_value;4039 IrInstSrc *target_value;
3671 IrInstructionCheckSwitchProngsRange *ranges;4040 IrInstSrcCheckSwitchProngsRange *ranges;
3672 size_t range_count;4041 size_t range_count;
3673 bool have_else_prong;4042 bool have_else_prong;
3674 bool have_underscore_prong;4043 bool have_underscore_prong;
3675};4044};
36764045
3677struct IrInstructionCheckStatementIsVoid {4046struct IrInstSrcCheckStatementIsVoid {
3678 IrInstruction base;4047 IrInstSrc base;
36794048
3680 IrInstruction *statement_value;4049 IrInstSrc *statement_value;
3681};4050};
36824051
3683struct IrInstructionTypeName {4052struct IrInstSrcTypeName {
3684 IrInstruction base;4053 IrInstSrc base;
36854054
3686 IrInstruction *type_value;4055 IrInstSrc *type_value;
3687};4056};
36884057
3689struct IrInstructionDeclRef {4058struct IrInstSrcDeclRef {
3690 IrInstruction base;4059 IrInstSrc base;
36914060
3692 LVal lval;4061 LVal lval;
3693 Tld *tld;4062 Tld *tld;
3694};4063};
36954064
3696struct IrInstructionPanic {4065struct IrInstSrcPanic {
3697 IrInstruction base;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;
3700};4087};
37014088
3702struct IrInstructionTagName {4089struct IrInstSrcTagType {
3703 IrInstruction base;4090 IrInstSrc base;
37044091
3705 IrInstruction *target;4092 IrInstSrc *target;
3706};4093};
37074094
3708struct IrInstructionTagType {4095struct IrInstSrcFieldParentPtr {
3709 IrInstruction base;4096 IrInstSrc base;
37104097
3711 IrInstruction *target;4098 IrInstSrc *type_value;
4099 IrInstSrc *field_name;
4100 IrInstSrc *field_ptr;
3712};4101};
37134102
3714struct IrInstructionFieldParentPtr {4103struct IrInstGenFieldParentPtr {
3715 IrInstruction base;4104 IrInstGen base;
37164105
3717 IrInstruction *type_value;4106 IrInstGen *field_ptr;
3718 IrInstruction *field_name;
3719 IrInstruction *field_ptr;
3720 TypeStructField *field;4107 TypeStructField *field;
3721};4108};
37224109
3723struct IrInstructionByteOffsetOf {4110struct IrInstSrcByteOffsetOf {
3724 IrInstruction base;4111 IrInstSrc base;
4112
4113 IrInstSrc *type_value;
4114 IrInstSrc *field_name;
4115};
4116
4117struct IrInstSrcBitOffsetOf {
4118 IrInstSrc base;
37254119
3726 IrInstruction *type_value;4120 IrInstSrc *type_value;
3727 IrInstruction *field_name;4121 IrInstSrc *field_name;
3728};4122};
37294123
3730struct IrInstructionBitOffsetOf {4124struct IrInstSrcTypeInfo {
3731 IrInstruction base;4125 IrInstSrc base;
37324126
3733 IrInstruction *type_value;4127 IrInstSrc *type_value;
3734 IrInstruction *field_name;
3735};4128};
37364129
3737struct IrInstructionTypeInfo {4130struct IrInstSrcType {
3738 IrInstruction base;4131 IrInstSrc base;
37394132
3740 IrInstruction *type_value;4133 IrInstSrc *type_info;
3741};4134};
37424135
3743struct IrInstructionType {4136struct IrInstSrcHasField {
3744 IrInstruction base;4137 IrInstSrc base;
37454138
3746 IrInstruction *type_info;4139 IrInstSrc *container_type;
4140 IrInstSrc *field_name;
3747};4141};
37484142
3749struct IrInstructionHasField {4143struct IrInstSrcTypeId {
3750 IrInstruction base;4144 IrInstSrc base;
37514145
3752 IrInstruction *container_type;4146 IrInstSrc *type_value;
3753 IrInstruction *field_name;
3754};4147};
37554148
3756struct IrInstructionTypeId {4149struct IrInstSrcSetEvalBranchQuota {
3757 IrInstruction base;4150 IrInstSrc base;
37584151
3759 IrInstruction *type_value;4152 IrInstSrc *new_quota;
3760};4153};
37614154
3762struct IrInstructionSetEvalBranchQuota {4155struct IrInstSrcAlignCast {
3763 IrInstruction base;4156 IrInstSrc base;
37644157
3765 IrInstruction *new_quota;4158 IrInstSrc *align_bytes;
4159 IrInstSrc *target;
3766};4160};
37674161
3768struct IrInstructionAlignCast {4162struct IrInstGenAlignCast {
3769 IrInstruction base;4163 IrInstGen base;
37704164
3771 IrInstruction *align_bytes;4165 IrInstGen *target;
3772 IrInstruction *target;
3773};4166};
37744167
3775struct IrInstructionOpaqueType {4168struct IrInstSrcOpaqueType {
3776 IrInstruction base;4169 IrInstSrc base;
3777};4170};
37784171
3779struct IrInstructionSetAlignStack {4172struct IrInstSrcSetAlignStack {
3780 IrInstruction base;4173 IrInstSrc base;
37814174
3782 IrInstruction *align_bytes;4175 IrInstSrc *align_bytes;
3783};4176};
37844177
3785struct IrInstructionArgType {4178struct IrInstSrcArgType {
3786 IrInstruction base;4179 IrInstSrc base;
37874180
3788 IrInstruction *fn_type;4181 IrInstSrc *fn_type;
3789 IrInstruction *arg_index;4182 IrInstSrc *arg_index;
3790 bool allow_var;4183 bool allow_var;
3791};4184};
37924185
3793struct IrInstructionExport {4186struct IrInstSrcExport {
3794 IrInstruction base;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;4201 IrInstErrorReturnTraceOptional optional;
3797 IrInstruction *options;
3798};4202};
37994203
3800struct IrInstructionErrorReturnTrace {4204struct IrInstGenErrorReturnTrace {
3801 IrInstruction base;4205 IrInstGen base;
38024206
3803 enum Optional {4207 IrInstErrorReturnTraceOptional optional;
3804 Null,
3805 NonNull,
3806 } optional;
3807};4208};
38084209
3809struct IrInstructionErrorUnion {4210struct IrInstSrcErrorUnion {
3810 IrInstruction base;4211 IrInstSrc base;
38114212
3812 IrInstruction *err_set;4213 IrInstSrc *err_set;
3813 IrInstruction *payload;4214 IrInstSrc *payload;
3814 Buf *type_name;4215 Buf *type_name;
3815};4216};
38164217
3817struct IrInstructionAtomicRmw {4218struct IrInstSrcAtomicRmw {
3818 IrInstruction base;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;4248 IrInstGen *ptr;
3821 IrInstruction *ptr;4249 AtomicOrder ordering;
3822 IrInstruction *op;
3823 AtomicRmwOp resolved_op;
3824 IrInstruction *operand;
3825 IrInstruction *ordering;
3826 AtomicOrder resolved_ordering;
3827};4250};
38284251
3829struct IrInstructionAtomicLoad {4252struct IrInstSrcAtomicStore {
3830 IrInstruction base;4253 IrInstSrc base;
38314254
3832 IrInstruction *operand_type;4255 IrInstSrc *operand_type;
3833 IrInstruction *ptr;4256 IrInstSrc *ptr;
3834 IrInstruction *ordering;4257 IrInstSrc *value;
3835 AtomicOrder resolved_ordering;4258 IrInstSrc *ordering;
3836};4259};
38374260
3838struct IrInstructionAtomicStore {4261struct IrInstGenAtomicStore {
3839 IrInstruction base;4262 IrInstGen base;
4263
4264 IrInstGen *ptr;
4265 IrInstGen *value;
4266 AtomicOrder ordering;
4267};
38404268
3841 IrInstruction *operand_type;4269struct IrInstSrcSaveErrRetAddr {
3842 IrInstruction *ptr;4270 IrInstSrc base;
3843 IrInstruction *value;
3844 IrInstruction *ordering;
3845 AtomicOrder resolved_ordering;
3846};4271};
38474272
3848struct IrInstructionSaveErrRetAddr {4273struct IrInstGenSaveErrRetAddr {
3849 IrInstruction base;4274 IrInstGen base;
3850};4275};
38514276
3852struct IrInstructionAddImplicitReturnType {4277struct IrInstSrcAddImplicitReturnType {
3853 IrInstruction base;4278 IrInstSrc base;
38544279
3855 IrInstruction *value;4280 IrInstSrc *value;
3856 ResultLocReturn *result_loc_ret;4281 ResultLocReturn *result_loc_ret;
3857};4282};
38584283
3859// For float ops which take a single argument4284// For float ops that take a single argument
3860struct IrInstructionFloatOp {4285struct IrInstSrcFloatOp {
3861 IrInstruction base;4286 IrInstSrc base;
4287
4288 IrInstSrc *operand;
4289 BuiltinFnId fn_id;
4290};
4291
4292struct IrInstGenFloatOp {
4293 IrInstGen base;
38624294
4295 IrInstGen *operand;
3863 BuiltinFnId fn_id;4296 BuiltinFnId fn_id;
3864 IrInstruction *operand;
3865};4297};
38664298
3867struct IrInstructionCheckRuntimeScope {4299struct IrInstSrcCheckRuntimeScope {
3868 IrInstruction base;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;4322 IrInstSrc *type;
3871 IrInstruction *is_comptime;4323 IrInstSrc *op;
3872};4324};
38734325
3874struct IrInstructionBswap {4326struct IrInstGenBitReverse {
3875 IrInstruction base;4327 IrInstGen base;
38764328
3877 IrInstruction *type;4329 IrInstGen *op;
3878 IrInstruction *op;
3879};4330};
38804331
3881struct IrInstructionBitReverse {4332struct IrInstGenArrayToVector {
3882 IrInstruction base;4333 IrInstGen base;
38834334
3884 IrInstruction *type;4335 IrInstGen *array;
3885 IrInstruction *op;
3886};4336};
38874337
3888struct IrInstructionArrayToVector {4338struct IrInstGenVectorToArray {
3889 IrInstruction base;4339 IrInstGen base;
38904340
3891 IrInstruction *array;4341 IrInstGen *vector;
4342 IrInstGen *result_loc;
3892};4343};
38934344
3894struct IrInstructionVectorToArray {4345struct IrInstSrcShuffleVector {
3895 IrInstruction base;4346 IrInstSrc base;
38964347
3897 IrInstruction *vector;4348 IrInstSrc *scalar_type;
3898 IrInstruction *result_loc;4349 IrInstSrc *a;
4350 IrInstSrc *b;
4351 IrInstSrc *mask; // This is in zig-format, not llvm format
3899};4352};
39004353
3901struct IrInstructionShuffleVector {4354struct IrInstGenShuffleVector {
3902 IrInstruction base;4355 IrInstGen base;
39034356
3904 IrInstruction *scalar_type;4357 IrInstGen *a;
3905 IrInstruction *a;4358 IrInstGen *b;
3906 IrInstruction *b;4359 IrInstGen *mask; // This is in zig-format, not llvm format
3907 IrInstruction *mask; // This is in zig-format, not llvm format
3908};4360};
39094361
3910struct IrInstructionSplatSrc {4362struct IrInstSrcSplat {
3911 IrInstruction base;4363 IrInstSrc base;
39124364
3913 IrInstruction *len;4365 IrInstSrc *len;
3914 IrInstruction *scalar;4366 IrInstSrc *scalar;
3915};4367};
39164368
3917struct IrInstructionSplatGen {4369struct IrInstGenSplat {
3918 IrInstruction base;4370 IrInstGen base;
39194371
3920 IrInstruction *scalar;4372 IrInstGen *scalar;
3921};4373};
39224374
3923struct IrInstructionAssertZero {4375struct IrInstGenAssertZero {
3924 IrInstruction base;4376 IrInstGen base;
39254377
3926 IrInstruction *target;4378 IrInstGen *target;
3927};4379};
39284380
3929struct IrInstructionAssertNonNull {4381struct IrInstGenAssertNonNull {
3930 IrInstruction base;4382 IrInstGen base;
39314383
3932 IrInstruction *target;4384 IrInstGen *target;
3933};4385};
39344386
3935struct IrInstructionUnionInitNamedField {4387struct IrInstSrcUnionInitNamedField {
3936 IrInstruction base;4388 IrInstSrc base;
39374389
3938 IrInstruction *union_type;4390 IrInstSrc *union_type;
3939 IrInstruction *field_name;4391 IrInstSrc *field_name;
3940 IrInstruction *field_result_loc;4392 IrInstSrc *field_result_loc;
3941 IrInstruction *result_loc;4393 IrInstSrc *result_loc;
3942};4394};
39434395
3944struct IrInstructionHasDecl {4396struct IrInstSrcHasDecl {
3945 IrInstruction base;4397 IrInstSrc base;
39464398
3947 IrInstruction *container;4399 IrInstSrc *container;
3948 IrInstruction *name;4400 IrInstSrc *name;
3949};4401};
39504402
3951struct IrInstructionUndeclaredIdent {4403struct IrInstSrcUndeclaredIdent {
3952 IrInstruction base;4404 IrInstSrc base;
39534405
3954 Buf *name;4406 Buf *name;
3955};4407};
39564408
3957struct IrInstructionAllocaSrc {4409struct IrInstSrcAlloca {
3958 IrInstruction base;4410 IrInstSrc base;
39594411
3960 IrInstruction *align;4412 IrInstSrc *align;
3961 IrInstruction *is_comptime;4413 IrInstSrc *is_comptime;
3962 const char *name_hint;4414 const char *name_hint;
3963};4415};
39644416
3965struct IrInstructionAllocaGen {4417struct IrInstGenAlloca {
3966 IrInstruction base;4418 IrInstGen base;
39674419
3968 uint32_t align;4420 uint32_t align;
3969 const char *name_hint;4421 const char *name_hint;
3970 size_t field_index;4422 size_t field_index;
3971};4423};
39724424
3973struct IrInstructionEndExpr {4425struct IrInstSrcEndExpr {
3974 IrInstruction base;4426 IrInstSrc base;
39754427
3976 IrInstruction *value;4428 IrInstSrc *value;
3977 ResultLoc *result_loc;4429 ResultLoc *result_loc;
3978};4430};
39794431
3980// This one is for writing through the result pointer.4432// This one is for writing through the result pointer.
3981struct IrInstructionResolveResult {4433struct IrInstSrcResolveResult {
3982 IrInstruction base;4434 IrInstSrc base;
39834435
3984 ResultLoc *result_loc;4436 ResultLoc *result_loc;
3985 IrInstruction *ty;4437 IrInstSrc *ty;
3986};4438};
39874439
3988// This one is when you want to read the value of the result.4440struct IrInstSrcResetResult {
3989// You have to give the value in case it is comptime.4441 IrInstSrc base;
3990struct IrInstructionResultPtr {
3991 IrInstruction base;
39924442
3993 ResultLoc *result_loc;4443 ResultLoc *result_loc;
3994 IrInstruction *result;
3995};4444};
39964445
3997struct IrInstructionResetResult {4446struct IrInstGenPtrOfArrayToSlice {
3998 IrInstruction base;4447 IrInstGen base;
39994448
4000 ResultLoc *result_loc;4449 IrInstGen *operand;
4450 IrInstGen *result_loc;
4001};4451};
40024452
4003struct IrInstructionPtrOfArrayToSlice {4453struct IrInstSrcSuspendBegin {
4004 IrInstruction base;4454 IrInstSrc base;
4005
4006 IrInstruction *operand;
4007 IrInstruction *result_loc;
4008};4455};
40094456
4010struct IrInstructionSuspendBegin {4457struct IrInstGenSuspendBegin {
4011 IrInstruction base;4458 IrInstGen base;
40124459
4013 LLVMBasicBlockRef resume_bb;4460 LLVMBasicBlockRef resume_bb;
4014};4461};
40154462
4016struct IrInstructionSuspendFinish {4463struct IrInstSrcSuspendFinish {
4017 IrInstruction base;4464 IrInstSrc base;
4465
4466 IrInstSrcSuspendBegin *begin;
4467};
4468
4469struct IrInstGenSuspendFinish {
4470 IrInstGen base;
40184471
4019 IrInstructionSuspendBegin *begin;4472 IrInstGenSuspendBegin *begin;
4020};4473};
40214474
4022struct IrInstructionAwaitSrc {4475struct IrInstSrcAwait {
4023 IrInstruction base;4476 IrInstSrc base;
40244477
4025 IrInstruction *frame;4478 IrInstSrc *frame;
4026 ResultLoc *result_loc;4479 ResultLoc *result_loc;
4027};4480};
40284481
4029struct IrInstructionAwaitGen {4482struct IrInstGenAwait {
4030 IrInstruction base;4483 IrInstGen base;
40314484
4032 IrInstruction *frame;4485 IrInstGen *frame;
4033 IrInstruction *result_loc;4486 IrInstGen *result_loc;
4034 ZigFn *target_fn;4487 ZigFn *target_fn;
4035};4488};
40364489
4037struct IrInstructionResume {4490struct IrInstSrcResume {
4038 IrInstruction base;4491 IrInstSrc base;
4492
4493 IrInstSrc *frame;
4494};
4495
4496struct IrInstGenResume {
4497 IrInstGen base;
40394498
4040 IrInstruction *frame;4499 IrInstGen *frame;
4041};4500};
40424501
4043enum SpillId {4502enum SpillId {
...@@ -4045,24 +4504,37 @@ enum SpillId {...@@ -4045,24 +4504,37 @@ enum SpillId {
4045 SpillIdRetErrCode,4504 SpillIdRetErrCode,
4046};4505};
40474506
4048struct IrInstructionSpillBegin {4507struct IrInstSrcSpillBegin {
4049 IrInstruction base;4508 IrInstSrc base;
4509
4510 IrInstSrc *operand;
4511 SpillId spill_id;
4512};
4513
4514struct IrInstGenSpillBegin {
4515 IrInstGen base;
40504516
4051 SpillId spill_id;4517 SpillId spill_id;
4052 IrInstruction *operand;4518 IrInstGen *operand;
4519};
4520
4521struct IrInstSrcSpillEnd {
4522 IrInstSrc base;
4523
4524 IrInstSrcSpillBegin *begin;
4053};4525};
40544526
4055struct IrInstructionSpillEnd {4527struct IrInstGenSpillEnd {
4056 IrInstruction base;4528 IrInstGen base;
40574529
4058 IrInstructionSpillBegin *begin;4530 IrInstGenSpillBegin *begin;
4059};4531};
40604532
4061struct IrInstructionVectorExtractElem {4533struct IrInstGenVectorExtractElem {
4062 IrInstruction base;4534 IrInstGen base;
40634535
4064 IrInstruction *vector;4536 IrInstGen *vector;
4065 IrInstruction *index;4537 IrInstGen *index;
4066};4538};
40674539
4068enum ResultLocId {4540enum ResultLocId {
...@@ -4083,9 +4555,9 @@ struct ResultLoc {...@@ -4083,9 +4555,9 @@ struct ResultLoc {
4083 ResultLocId id;4555 ResultLocId id;
4084 bool written;4556 bool written;
4085 bool allow_write_through_const;4557 bool allow_write_through_const;
4086 IrInstruction *resolved_loc; // result ptr4558 IrInstGen *resolved_loc; // result ptr
4087 IrInstruction *source_instruction;4559 IrInstSrc *source_instruction;
4088 IrInstruction *gen_instruction; // value to store to the result loc4560 IrInstGen *gen_instruction; // value to store to the result loc
4089 ZigType *implicit_elem_type;4561 ZigType *implicit_elem_type;
4090};4562};
40914563
...@@ -4115,18 +4587,18 @@ struct ResultLocPeerParent {...@@ -4115,18 +4587,18 @@ struct ResultLocPeerParent {
41154587
4116 bool skipped;4588 bool skipped;
4117 bool done_resuming;4589 bool done_resuming;
4118 IrBasicBlock *end_bb;4590 IrBasicBlockSrc *end_bb;
4119 ResultLoc *parent;4591 ResultLoc *parent;
4120 ZigList<ResultLocPeer *> peers;4592 ZigList<ResultLocPeer *> peers;
4121 ZigType *resolved_type;4593 ZigType *resolved_type;
4122 IrInstruction *is_comptime;4594 IrInstSrc *is_comptime;
4123};4595};
41244596
4125struct ResultLocPeer {4597struct ResultLocPeer {
4126 ResultLoc base;4598 ResultLoc base;
41274599
4128 ResultLocPeerParent *parent;4600 ResultLocPeerParent *parent;
4129 IrBasicBlock *next_bb;4601 IrBasicBlockSrc *next_bb;
4130 IrSuspendPosition suspend_pos;4602 IrSuspendPosition suspend_pos;
4131};4603};
41324604
...@@ -4197,7 +4669,7 @@ struct FnWalkAttrs {...@@ -4197,7 +4669,7 @@ struct FnWalkAttrs {
4197struct FnWalkCall {4669struct FnWalkCall {
4198 ZigList<LLVMValueRef> *gen_param_values;4670 ZigList<LLVMValueRef> *gen_param_values;
4199 ZigList<ZigType *> *gen_param_types;4671 ZigList<ZigType *> *gen_param_types;
4200 IrInstructionCallGen *inst;4672 IrInstGenCall *inst;
4201 bool is_var_args;4673 bool is_var_args;
4202};4674};
42034675
src/analyze.cpp+94-61
...@@ -199,7 +199,7 @@ ScopeLoop *create_loop_scope(CodeGen *g, AstNode *node, Scope *parent) {...@@ -199,7 +199,7 @@ ScopeLoop *create_loop_scope(CodeGen *g, AstNode *node, Scope *parent) {
199 return scope;199 return scope;
200}200}
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) {
203 ScopeRuntime *scope = allocate<ScopeRuntime>(1);203 ScopeRuntime *scope = allocate<ScopeRuntime>(1);
204 scope->is_comptime = is_comptime;204 scope->is_comptime = is_comptime;
205 init_scope(g, &scope->base, ScopeIdRuntime, node, parent);205 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...@@ -3350,7 +3350,7 @@ static void get_fully_qualified_decl_name(CodeGen *g, Buf *buf, Tld *tld, bool i
33503350
3351ZigFn *create_fn_raw(CodeGen *g, FnInline inline_value) {3351ZigFn *create_fn_raw(CodeGen *g, FnInline inline_value) {
3352 ZigFn *fn_entry = allocate<ZigFn>(1, "ZigFn");3352 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
3355 fn_entry->prealloc_backward_branch_quota = default_backward_branch_quota;3355 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...@@ -4097,7 +4097,7 @@ static void preview_use_decl(CodeGen *g, TldUsingNamespace *using_namespace, Sco
4097 if (type_is_invalid(result->type)) {4097 if (type_is_invalid(result->type)) {
4098 dest_decls_scope->any_imports_failed = true;4098 dest_decls_scope->any_imports_failed = true;
4099 using_namespace->base.resolution = TldResolutionInvalid;4099 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;
4101 return;4101 return;
4102 }4102 }
41034103
...@@ -4106,7 +4106,7 @@ static void preview_use_decl(CodeGen *g, TldUsingNamespace *using_namespace, Sco...@@ -4106,7 +4106,7 @@ static void preview_use_decl(CodeGen *g, TldUsingNamespace *using_namespace, Sco
4106 buf_sprintf("expected struct, enum, or union; found '%s'", buf_ptr(&result->data.x_type->name)));4106 buf_sprintf("expected struct, enum, or union; found '%s'", buf_ptr(&result->data.x_type->name)));
4107 dest_decls_scope->any_imports_failed = true;4107 dest_decls_scope->any_imports_failed = true;
4108 using_namespace->base.resolution = TldResolutionInvalid;4108 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;
4110 return;4110 return;
4111 }4111 }
4112}4112}
...@@ -4667,12 +4667,12 @@ static void analyze_fn_async(CodeGen *g, ZigFn *fn, bool resolve_frame) {...@@ -4667,12 +4667,12 @@ static void analyze_fn_async(CodeGen *g, ZigFn *fn, bool resolve_frame) {
4667 }4667 }
46684668
4669 for (size_t i = 0; i < fn->call_list.length; i += 1) {4669 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);
4671 if (call->fn_entry == nullptr) {4671 if (call->fn_entry == nullptr) {
4672 // TODO function pointer call here, could be anything4672 // TODO function pointer call here, could be anything
4673 continue;4673 continue;
4674 }4674 }
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,
4676 call->modifier))4676 call->modifier))
4677 {4677 {
4678 case ErrorSemanticAnalyzeFail:4678 case ErrorSemanticAnalyzeFail:
...@@ -4690,10 +4690,10 @@ static void analyze_fn_async(CodeGen *g, ZigFn *fn, bool resolve_frame) {...@@ -4690,10 +4690,10 @@ static void analyze_fn_async(CodeGen *g, ZigFn *fn, bool resolve_frame) {
4690 }4690 }
4691 }4691 }
4692 for (size_t i = 0; i < fn->await_list.length; i += 1) {4692 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);
4694 // TODO If this is a noasync await, it doesn't count4694 // TODO If this is a noasync await, it doesn't count
4695 // https://github.com/ziglang/zig/issues/31574695 // 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,
4697 CallModifierNone))4697 CallModifierNone))
4698 {4698 {
4699 case ErrorSemanticAnalyzeFail:4699 case ErrorSemanticAnalyzeFail:
...@@ -4784,7 +4784,7 @@ static void analyze_fn_ir(CodeGen *g, ZigFn *fn, AstNode *return_type_node) {...@@ -4784,7 +4784,7 @@ static void analyze_fn_ir(CodeGen *g, ZigFn *fn, AstNode *return_type_node) {
47844784
4785 if (g->verbose_ir) {4785 if (g->verbose_ir) {
4786 fprintf(stderr, "fn %s() { // (analyzed)\n", buf_ptr(&fn->symbol_name));4786 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);
4788 fprintf(stderr, "}\n");4788 fprintf(stderr, "}\n");
4789 }4789 }
4790 fn->anal_state = FnAnalStateComplete;4790 fn->anal_state = FnAnalStateComplete;
...@@ -4827,7 +4827,7 @@ static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry) {...@@ -4827,7 +4827,7 @@ static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry) {
4827 fprintf(stderr, "\n");4827 fprintf(stderr, "\n");
4828 ast_render(stderr, fn_table_entry->body_node, 4);4828 ast_render(stderr, fn_table_entry->body_node, 4);
4829 fprintf(stderr, "\nfn %s() { // (IR)\n", buf_ptr(&fn_table_entry->symbol_name));4829 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);
4831 fprintf(stderr, "}\n");4831 fprintf(stderr, "}\n");
4832 }4832 }
48334833
...@@ -6191,13 +6191,13 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6191,13 +6191,13 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
6191 ZigType *fn_type = get_async_fn_type(g, fn->type_entry);6191 ZigType *fn_type = get_async_fn_type(g, fn->type_entry);
61926192
6193 if (fn->analyzed_executable.need_err_code_spill) {6193 if (fn->analyzed_executable.need_err_code_spill) {
6194 IrInstructionAllocaGen *alloca_gen = allocate<IrInstructionAllocaGen>(1);6194 IrInstGenAlloca *alloca_gen = allocate<IrInstGenAlloca>(1);
6195 alloca_gen->base.id = IrInstructionIdAllocaGen;6195 alloca_gen->base.id = IrInstGenIdAlloca;
6196 alloca_gen->base.source_node = fn->proto_node;6196 alloca_gen->base.base.source_node = fn->proto_node;
6197 alloca_gen->base.scope = fn->child_scope;6197 alloca_gen->base.base.scope = fn->child_scope;
6198 alloca_gen->base.value = allocate<ZigValue>(1, "ZigValue");6198 alloca_gen->base.value = allocate<ZigValue>(1, "ZigValue");
6199 alloca_gen->base.value->type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false);6199 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;
6201 alloca_gen->name_hint = "";6201 alloca_gen->name_hint = "";
6202 fn->alloca_gen_list.append(alloca_gen);6202 fn->alloca_gen_list.append(alloca_gen);
6203 fn->err_code_spill = &alloca_gen->base;6203 fn->err_code_spill = &alloca_gen->base;
...@@ -6205,18 +6205,18 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6205,18 +6205,18 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
62056205
6206 ZigType *largest_call_frame_type = nullptr;6206 ZigType *largest_call_frame_type = nullptr;
6207 // Later we'll change this to be largest_call_frame_type instead of void.6207 // 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,
6209 fn, g->builtin_types.entry_void, "@async_call_frame");6209 fn, g->builtin_types.entry_void, "@async_call_frame");
62106210
6211 for (size_t i = 0; i < fn->call_list.length; i += 1) {6211 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);
6213 if (call->new_stack != nullptr) {6213 if (call->new_stack != nullptr) {
6214 // don't need to allocate a frame for this6214 // don't need to allocate a frame for this
6215 continue;6215 continue;
6216 }6216 }
6217 ZigFn *callee = call->fn_entry;6217 ZigFn *callee = call->fn_entry;
6218 if (callee == nullptr) {6218 if (callee == nullptr) {
6219 add_node_error(g, call->base.source_node,6219 add_node_error(g, call->base.base.source_node,
6220 buf_sprintf("function is not comptime-known; @asyncCall required"));6220 buf_sprintf("function is not comptime-known; @asyncCall required"));
6221 return ErrorSemanticAnalyzeFail;6221 return ErrorSemanticAnalyzeFail;
6222 }6222 }
...@@ -6226,14 +6226,14 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6226,14 +6226,14 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
6226 if (callee->anal_state == FnAnalStateProbing) {6226 if (callee->anal_state == FnAnalStateProbing) {
6227 ErrorMsg *msg = add_node_error(g, fn->proto_node,6227 ErrorMsg *msg = add_node_error(g, fn->proto_node,
6228 buf_sprintf("unable to determine async function frame of '%s'", buf_ptr(&fn->symbol_name)));6228 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,
6230 buf_sprintf("analysis of function '%s' depends on the frame", buf_ptr(&callee->symbol_name)));6230 buf_sprintf("analysis of function '%s' depends on the frame", buf_ptr(&callee->symbol_name)));
6231 return ErrorSemanticAnalyzeFail;6231 return ErrorSemanticAnalyzeFail;
6232 }6232 }
62336233
6234 ZigType *callee_frame_type = get_fn_frame_type(g, callee);6234 ZigType *callee_frame_type = get_fn_frame_type(g, callee);
6235 frame_type->data.frame.resolve_loop_type = callee_frame_type;6235 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
6238 analyze_fn_body(g, callee);6238 analyze_fn_body(g, callee);
6239 if (callee->anal_state == FnAnalStateInvalid) {6239 if (callee->anal_state == FnAnalStateInvalid) {
...@@ -6249,7 +6249,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6249,7 +6249,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
6249 if (!fn_is_async(callee))6249 if (!fn_is_async(callee))
6250 continue;6250 continue;
62516251
6252 mark_suspension_point(call->base.scope);6252 mark_suspension_point(call->base.base.scope);
62536253
6254 if ((err = type_resolve(g, callee_frame_type, ResolveStatusSizeKnown))) {6254 if ((err = type_resolve(g, callee_frame_type, ResolveStatusSizeKnown))) {
6255 return err;6255 return err;
...@@ -6271,7 +6271,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6271,7 +6271,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
6271 // For example: foo() + await z6271 // For example: foo() + await z
6272 // The funtion call result of foo() must be spilled.6272 // The funtion call result of foo() must be spilled.
6273 for (size_t i = 0; i < fn->await_list.length; i += 1) {6273 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);
6275 // TODO If this is a noasync await, it doesn't suspend6275 // TODO If this is a noasync await, it doesn't suspend
6276 // https://github.com/ziglang/zig/issues/31576276 // https://github.com/ziglang/zig/issues/3157
6277 if (await->base.value->special != ConstValSpecialRuntime) {6277 if (await->base.value->special != ConstValSpecialRuntime) {
...@@ -6293,52 +6293,51 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6293,52 +6293,51 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
6293 }6293 }
6294 // This await is a suspend point, but it might not need a spill.6294 // This await is a suspend point, but it might not need a spill.
6295 // We do need to mark the ExprScope as having a suspend point in it.6295 // 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
6298 if (await->result_loc != nullptr) {6298 if (await->result_loc != nullptr) {
6299 // If there's a result location, that is the spill6299 // If there's a result location, that is the spill
6300 continue;6300 continue;
6301 }6301 }
6302 if (await->base.ref_count == 0)6302 if (await->base.base.ref_count == 0)
6303 continue;6303 continue;
6304 if (!type_has_bits(await->base.value->type))6304 if (!type_has_bits(await->base.value->type))
6305 continue;6305 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,
6307 await->base.value->type, "");6307 await->base.value->type, "");
6308 }6308 }
6309 for (size_t block_i = 0; block_i < fn->analyzed_executable.basic_block_list.length; block_i += 1) {6309 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);
6311 for (size_t instr_i = 0; instr_i < block->instruction_list.length; instr_i += 1) {6311 for (size_t instr_i = 0; instr_i < block->instruction_list.length; instr_i += 1) {
6312 IrInstruction *instruction = block->instruction_list.at(instr_i);6312 IrInstGen *instruction = block->instruction_list.at(instr_i);
6313 if (instruction->id == IrInstructionIdSuspendFinish) {6313 if (instruction->id == IrInstGenIdSuspendFinish) {
6314 mark_suspension_point(instruction->scope);6314 mark_suspension_point(instruction->base.scope);
6315 }6315 }
6316 }6316 }
6317 }6317 }
6318 // Now that we've marked all the expr scopes that have to spill, we go over the instructions6318 // Now that we've marked all the expr scopes that have to spill, we go over the instructions
6319 // and spill the relevant ones.6319 // and spill the relevant ones.
6320 for (size_t block_i = 0; block_i < fn->analyzed_executable.basic_block_list.length; block_i += 1) {6320 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);
6322 for (size_t instr_i = 0; instr_i < block->instruction_list.length; instr_i += 1) {6322 for (size_t instr_i = 0; instr_i < block->instruction_list.length; instr_i += 1) {
6323 IrInstruction *instruction = block->instruction_list.at(instr_i);6323 IrInstGen *instruction = block->instruction_list.at(instr_i);
6324 if (instruction->id == IrInstructionIdAwaitGen ||6324 if (instruction->id == IrInstGenIdAwait ||
6325 instruction->id == IrInstructionIdVarPtr ||6325 instruction->id == IrInstGenIdVarPtr ||
6326 instruction->id == IrInstructionIdDeclRef ||6326 instruction->id == IrInstGenIdAlloca)
6327 instruction->id == IrInstructionIdAllocaGen)
6328 {6327 {
6329 // This instruction does its own spilling specially, or otherwise doesn't need it.6328 // This instruction does its own spilling specially, or otherwise doesn't need it.
6330 continue;6329 continue;
6331 }6330 }
6332 if (instruction->value->special != ConstValSpecialRuntime)6331 if (instruction->value->special != ConstValSpecialRuntime)
6333 continue;6332 continue;
6334 if (instruction->ref_count == 0)6333 if (instruction->base.ref_count == 0)
6335 continue;6334 continue;
6336 if ((err = type_resolve(g, instruction->value->type, ResolveStatusZeroBitsKnown)))6335 if ((err = type_resolve(g, instruction->value->type, ResolveStatusZeroBitsKnown)))
6337 return ErrorSemanticAnalyzeFail;6336 return ErrorSemanticAnalyzeFail;
6338 if (!type_has_bits(instruction->value->type))6337 if (!type_has_bits(instruction->value->type))
6339 continue;6338 continue;
6340 if (scope_needs_spill(instruction->scope)) {6339 if (scope_needs_spill(instruction->base.scope)) {
6341 instruction->spill = ir_create_alloca(g, instruction->scope, instruction->source_node,6340 instruction->spill = ir_create_alloca(g, instruction->base.scope, instruction->base.source_node,
6342 fn, instruction->value->type, "");6341 fn, instruction->value->type, "");
6343 }6342 }
6344 }6343 }
...@@ -6389,14 +6388,14 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6389,14 +6388,14 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
6389 }6388 }
63906389
6391 for (size_t alloca_i = 0; alloca_i < fn->alloca_gen_list.length; alloca_i += 1) {6390 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);
6393 instruction->field_index = SIZE_MAX;6392 instruction->field_index = SIZE_MAX;
6394 ZigType *ptr_type = instruction->base.value->type;6393 ZigType *ptr_type = instruction->base.value->type;
6395 assert(ptr_type->id == ZigTypeIdPointer);6394 assert(ptr_type->id == ZigTypeIdPointer);
6396 ZigType *child_type = ptr_type->data.pointer.child_type;6395 ZigType *child_type = ptr_type->data.pointer.child_type;
6397 if (!type_has_bits(child_type))6396 if (!type_has_bits(child_type))
6398 continue;6397 continue;
6399 if (instruction->base.ref_count == 0)6398 if (instruction->base.base.ref_count == 0)
6400 continue;6399 continue;
6401 if (instruction->base.value->special != ConstValSpecialRuntime) {6400 if (instruction->base.value->special != ConstValSpecialRuntime) {
6402 if (const_ptr_pointee(nullptr, g, instruction->base.value, nullptr)->special !=6401 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) {...@@ -6407,7 +6406,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
6407 }6406 }
64086407
6409 frame_type->data.frame.resolve_loop_type = child_type;6408 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;
6411 if ((err = type_resolve(g, child_type, ResolveStatusSizeKnown))) {6410 if ((err = type_resolve(g, child_type, ResolveStatusSizeKnown))) {
6412 return err;6411 return err;
6413 }6412 }
...@@ -6421,7 +6420,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6421,7 +6420,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
6421 instruction->field_index = fields.length;6420 instruction->field_index = fields.length;
64226421
6423 src_assert(child_type->id != ZigTypeIdPointer || child_type->data.pointer.inferred_struct_field == nullptr,6422 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);
6425 fields.append({name, child_type, instruction->align});6424 fields.append({name, child_type, instruction->align});
6426 }6425 }
64276426
...@@ -6554,8 +6553,10 @@ bool ir_get_var_is_comptime(ZigVar *var) {...@@ -6554,8 +6553,10 @@ bool ir_get_var_is_comptime(ZigVar *var) {
6554 // As an optimization, is_comptime values which are constant are allowed6553 // As an optimization, is_comptime values which are constant are allowed
6555 // to be omitted from analysis. In this case, there is no child instruction6554 // to be omitted from analysis. In this case, there is no child instruction
6556 // and we simply look at the unanalyzed const parent instruction.6555 // and we simply look at the unanalyzed const parent instruction.
6557 assert(var->is_comptime->value->type->id == ZigTypeIdBool);6556 assert(var->is_comptime->id == IrInstSrcIdConst);
6558 var->is_comptime_memoized_value = var->is_comptime->value->data.x_bool;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;
6559 var->is_comptime = nullptr;6560 var->is_comptime = nullptr;
6560 return var->is_comptime_memoized_value;6561 return var->is_comptime_memoized_value;
6561}6562}
...@@ -9193,21 +9194,6 @@ void src_assert(bool ok, AstNode *source_node) {...@@ -9193,21 +9194,6 @@ void src_assert(bool ok, AstNode *source_node) {
9193 stage2_panic(msg, strlen(msg));9194 stage2_panic(msg, strlen(msg));
9194}9195}
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
9211Error analyze_import(CodeGen *g, ZigType *source_import, Buf *import_target_str,9197Error analyze_import(CodeGen *g, ZigType *source_import, Buf *import_target_str,
9212 ZigType **out_import, Buf **out_import_target_path, Buf *out_full_path)9198 ZigType **out_import, Buf **out_import_target_path, Buf *out_full_path)
9213{9199{
...@@ -9268,8 +9254,17 @@ Error analyze_import(CodeGen *g, ZigType *source_import, Buf *import_target_str,...@@ -9268,8 +9254,17 @@ Error analyze_import(CodeGen *g, ZigType *source_import, Buf *import_target_str,
9268}9254}
92699255
92709256
9271void IrExecutable::src() {9257void IrExecutableSrc::src() {
9272 IrExecutable *it;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;
9273 for (it = this; it != nullptr && it->source_node != nullptr; it = it->parent_exec) {9268 for (it = this; it != nullptr && it->source_node != nullptr; it = it->parent_exec) {
9274 it->source_node->src();9269 it->source_node->src();
9275 }9270 }
...@@ -9357,3 +9352,41 @@ bool type_is_numeric(ZigType *ty) {...@@ -9357,3 +9352,41 @@ bool type_is_numeric(ZigType *ty) {
9357 }9352 }
9358 zig_unreachable();9353 zig_unreachable();
9359}9354}
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);...@@ -120,7 +120,7 @@ ScopeLoop *create_loop_scope(CodeGen *g, AstNode *node, Scope *parent);
120ScopeSuspend *create_suspend_scope(CodeGen *g, AstNode *node, Scope *parent);120ScopeSuspend *create_suspend_scope(CodeGen *g, AstNode *node, Scope *parent);
121ScopeFnDef *create_fndef_scope(CodeGen *g, AstNode *node, Scope *parent, ZigFn *fn_entry);121ScopeFnDef *create_fndef_scope(CodeGen *g, AstNode *node, Scope *parent, ZigFn *fn_entry);
122Scope *create_comptime_scope(CodeGen *g, AstNode *node, Scope *parent);122Scope *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);
124Scope *create_typeof_scope(CodeGen *g, AstNode *node, Scope *parent);124Scope *create_typeof_scope(CodeGen *g, AstNode *node, Scope *parent);
125ScopeExpr *create_expr_scope(CodeGen *g, AstNode *node, Scope *parent);125ScopeExpr *create_expr_scope(CodeGen *g, AstNode *node, Scope *parent);
126126
...@@ -271,8 +271,6 @@ ZigType *resolve_struct_field_type(CodeGen *g, TypeStructField *struct_field);...@@ -271,8 +271,6 @@ ZigType *resolve_struct_field_type(CodeGen *g, TypeStructField *struct_field);
271271
272void add_async_error_notes(CodeGen *g, ErrorMsg *msg, ZigFn *fn);272void 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);
276Error analyze_import(CodeGen *codegen, ZigType *source_import, Buf *import_target_str,274Error analyze_import(CodeGen *codegen, ZigType *source_import, Buf *import_target_str,
277 ZigType **out_import, Buf **out_import_target_path, Buf *out_full_path);275 ZigType **out_import, Buf **out_import_target_path, Buf *out_full_path);
278ZigValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry);276ZigValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry);
...@@ -281,4 +279,5 @@ void copy_const_val(ZigValue *dest, ZigValue *src);...@@ -281,4 +279,5 @@ void copy_const_val(ZigValue *dest, ZigValue *src);
281bool type_has_optional_repr(ZigType *ty);279bool type_has_optional_repr(ZigType *ty);
282bool is_opt_err_set(ZigType *ty);280bool is_opt_err_set(ZigType *ty);
283bool type_is_numeric(ZigType *ty);281bool type_is_numeric(ZigType *ty);
282const char *float_op_to_name(BuiltinFnId op);
284#endif283#endif
src/codegen.cpp+413-476
...@@ -186,7 +186,7 @@ static void generate_error_name_table(CodeGen *g);...@@ -186,7 +186,7 @@ static void generate_error_name_table(CodeGen *g);
186static bool value_is_all_undef(CodeGen *g, ZigValue *const_val);186static bool value_is_all_undef(CodeGen *g, ZigValue *const_val);
187static void gen_undef_init(CodeGen *g, uint32_t ptr_align_bytes, ZigType *value_type, LLVMValueRef ptr);187static void gen_undef_init(CodeGen *g, uint32_t ptr_align_bytes, ZigType *value_type, LLVMValueRef ptr);
188static LLVMValueRef build_alloca(CodeGen *g, ZigType *type_entry, const char *name, uint32_t alignment);188static 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,
190 LLVMValueRef target_frame_ptr, ZigType *result_type, ZigType *ptr_result_type,190 LLVMValueRef target_frame_ptr, ZigType *result_type, ZigType *ptr_result_type,
191 LLVMValueRef result_loc, bool non_async);191 LLVMValueRef result_loc, bool non_async);
192static Error get_tmp_filename(CodeGen *g, Buf *out, Buf *suffix);192static 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...@@ -872,14 +872,14 @@ static LLVMValueRef get_handle_value(CodeGen *g, LLVMValueRef ptr, ZigType *type
872 }872 }
873}873}
874874
875static void ir_assert(bool ok, IrInstruction *source_instruction) {875static void ir_assert(bool ok, IrInstGen *source_instruction) {
876 if (ok) return;876 if (ok) return;
877 src_assert(ok, source_instruction->source_node);877 src_assert(ok, source_instruction->base.source_node);
878}878}
879879
880static bool ir_want_fast_math(CodeGen *g, IrInstruction *instruction) {880static bool ir_want_fast_math(CodeGen *g, IrInstGen *instruction) {
881 // TODO memoize881 // TODO memoize
882 Scope *scope = instruction->scope;882 Scope *scope = instruction->base.scope;
883 while (scope) {883 while (scope) {
884 if (scope->id == ScopeIdBlock) {884 if (scope->id == ScopeIdBlock) {
885 ScopeBlock *block_scope = (ScopeBlock *)scope;885 ScopeBlock *block_scope = (ScopeBlock *)scope;
...@@ -914,8 +914,8 @@ static bool ir_want_runtime_safety_scope(CodeGen *g, Scope *scope) {...@@ -914,8 +914,8 @@ static bool ir_want_runtime_safety_scope(CodeGen *g, Scope *scope) {
914 g->build_mode != BuildModeSmallRelease);914 g->build_mode != BuildModeSmallRelease);
915}915}
916916
917static bool ir_want_runtime_safety(CodeGen *g, IrInstruction *instruction) {917static bool ir_want_runtime_safety(CodeGen *g, IrInstGen *instruction) {
918 return ir_want_runtime_safety_scope(g, instruction->scope);918 return ir_want_runtime_safety_scope(g, instruction->base.scope);
919}919}
920920
921static Buf *panic_msg_buf(PanicMsgId msg_id) {921static Buf *panic_msg_buf(PanicMsgId msg_id) {
...@@ -1041,8 +1041,8 @@ static void gen_assertion_scope(CodeGen *g, PanicMsgId msg_id, Scope *source_sco...@@ -1041,8 +1041,8 @@ static void gen_assertion_scope(CodeGen *g, PanicMsgId msg_id, Scope *source_sco
1041 }1041 }
1042}1042}
10431043
1044static void gen_assertion(CodeGen *g, PanicMsgId msg_id, IrInstruction *source_instruction) {1044static void gen_assertion(CodeGen *g, PanicMsgId msg_id, IrInstGen *source_instruction) {
1045 return gen_assertion_scope(g, msg_id, source_instruction->scope);1045 return gen_assertion_scope(g, msg_id, source_instruction->base.scope);
1046}1046}
10471047
1048static LLVMValueRef get_stacksave_fn_val(CodeGen *g) {1048static LLVMValueRef get_stacksave_fn_val(CodeGen *g) {
...@@ -1756,7 +1756,7 @@ static void gen_var_debug_decl(CodeGen *g, ZigVar *var) {...@@ -1756,7 +1756,7 @@ static void gen_var_debug_decl(CodeGen *g, ZigVar *var) {
1756 LLVMGetInsertBlock(g->builder));1756 LLVMGetInsertBlock(g->builder));
1757}1757}
17581758
1759static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {1759static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstGen *instruction) {
1760 Error err;1760 Error err;
17611761
1762 bool value_has_bits;1762 bool value_has_bits;
...@@ -1767,8 +1767,8 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {...@@ -1767,8 +1767,8 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {
1767 return nullptr;1767 return nullptr;
17681768
1769 if (!instruction->llvm_value) {1769 if (!instruction->llvm_value) {
1770 if (instruction->id == IrInstructionIdAwaitGen) {1770 if (instruction->id == IrInstGenIdAwait) {
1771 IrInstructionAwaitGen *await = reinterpret_cast<IrInstructionAwaitGen*>(instruction);1771 IrInstGenAwait *await = reinterpret_cast<IrInstGenAwait*>(instruction);
1772 if (await->result_loc != nullptr) {1772 if (await->result_loc != nullptr) {
1773 return get_handle_value(g, ir_llvm_value(g, await->result_loc),1773 return get_handle_value(g, ir_llvm_value(g, await->result_loc),
1774 await->result_loc->value->type->data.pointer.child_type, await->result_loc->value->type);1774 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_...@@ -1851,9 +1851,9 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_
1851 case FnWalkIdCall: {1851 case FnWalkIdCall: {
1852 if (src_i >= fn_walk->data.call.inst->arg_count)1852 if (src_i >= fn_walk->data.call.inst->arg_count)
1853 return false;1853 return false;
1854 IrInstruction *arg = fn_walk->data.call.inst->args[src_i];1854 IrInstGen *arg = fn_walk->data.call.inst->args[src_i];
1855 ty = arg->value->type;1855 ty = arg->value->type;
1856 source_node = arg->source_node;1856 source_node = arg->base.source_node;
1857 val = ir_llvm_value(g, arg);1857 val = ir_llvm_value(g, arg);
1858 break;1858 break;
1859 }1859 }
...@@ -2086,10 +2086,10 @@ void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk) {...@@ -2086,10 +2086,10 @@ void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk) {
2086 return;2086 return;
2087 }2087 }
2088 if (fn_walk->id == FnWalkIdCall) {2088 if (fn_walk->id == FnWalkIdCall) {
2089 IrInstructionCallGen *instruction = fn_walk->data.call.inst;2089 IrInstGenCall *instruction = fn_walk->data.call.inst;
2090 bool is_var_args = fn_walk->data.call.is_var_args;2090 bool is_var_args = fn_walk->data.call.is_var_args;
2091 for (size_t call_i = 0; call_i < instruction->arg_count; call_i += 1) {2091 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];
2093 ZigType *param_type = param_instruction->value->type;2093 ZigType *param_type = param_instruction->value->type;
2094 if (is_var_args || type_has_bits(param_type)) {2094 if (is_var_args || type_has_bits(param_type)) {
2095 LLVMValueRef param_value = ir_llvm_value(g, param_instruction);2095 LLVMValueRef param_value = ir_llvm_value(g, param_instruction);
...@@ -2304,14 +2304,14 @@ static LLVMValueRef get_merge_err_ret_traces_fn_val(CodeGen *g) {...@@ -2304,14 +2304,14 @@ static LLVMValueRef get_merge_err_ret_traces_fn_val(CodeGen *g) {
2304 return fn_val;2304 return fn_val;
23052305
2306}2306}
2307static LLVMValueRef ir_render_save_err_ret_addr(CodeGen *g, IrExecutable *executable,2307static LLVMValueRef ir_render_save_err_ret_addr(CodeGen *g, IrExecutableGen *executable,
2308 IrInstructionSaveErrRetAddr *save_err_ret_addr_instruction)2308 IrInstGenSaveErrRetAddr *save_err_ret_addr_instruction)
2309{2309{
2310 assert(g->have_err_ret_tracing);2310 assert(g->have_err_ret_tracing);
23112311
2312 LLVMValueRef return_err_fn = get_return_err_fn(g);2312 LLVMValueRef return_err_fn = get_return_err_fn(g);
2313 bool is_llvm_alloca;2313 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,
2315 &is_llvm_alloca);2315 &is_llvm_alloca);
2316 ZigLLVMBuildCall(g->builder, return_err_fn, &my_err_trace_val, 1,2316 ZigLLVMBuildCall(g->builder, return_err_fn, &my_err_trace_val, 1,
2317 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");2317 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");
...@@ -2326,7 +2326,7 @@ static LLVMValueRef ir_render_save_err_ret_addr(CodeGen *g, IrExecutable *execut...@@ -2326,7 +2326,7 @@ static LLVMValueRef ir_render_save_err_ret_addr(CodeGen *g, IrExecutable *execut
2326 return nullptr;2326 return nullptr;
2327}2327}
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,
2330 LLVMBasicBlockRef end_bb)2330 LLVMBasicBlockRef end_bb)
2331{2331{
2332 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;2332 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...@@ -2403,7 +2403,7 @@ static LLVMValueRef gen_maybe_atomic_op(CodeGen *g, LLVMAtomicRMWBinOp op, LLVMV
2403 }2403 }
2404}2404}
24052405
2406static void gen_async_return(CodeGen *g, IrInstructionReturn *instruction) {2406static void gen_async_return(CodeGen *g, IrInstGenReturn *instruction) {
2407 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;2407 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;
24082408
2409 ZigType *operand_type = (instruction->operand != nullptr) ? instruction->operand->value->type : nullptr;2409 ZigType *operand_type = (instruction->operand != nullptr) ? instruction->operand->value->type : nullptr;
...@@ -2482,7 +2482,7 @@ static void gen_async_return(CodeGen *g, IrInstructionReturn *instruction) {...@@ -2482,7 +2482,7 @@ static void gen_async_return(CodeGen *g, IrInstructionReturn *instruction) {
2482 frame_index_trace_arg(g, ret_type) + 1, "");2482 frame_index_trace_arg(g, ret_type) + 1, "");
2483 LLVMValueRef dest_trace_ptr = LLVMBuildLoad(g->builder, awaiter_trace_ptr_ptr, "");2483 LLVMValueRef dest_trace_ptr = LLVMBuildLoad(g->builder, awaiter_trace_ptr_ptr, "");
2484 bool is_llvm_alloca;2484 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);
2486 LLVMValueRef args[] = { dest_trace_ptr, my_err_trace_val };2486 LLVMValueRef args[] = { dest_trace_ptr, my_err_trace_val };
2487 ZigLLVMBuildCall(g->builder, get_merge_err_ret_traces_fn_val(g), args, 2,2487 ZigLLVMBuildCall(g->builder, get_merge_err_ret_traces_fn_val(g), args, 2,
2488 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");2488 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");
...@@ -2497,7 +2497,7 @@ static void gen_async_return(CodeGen *g, IrInstructionReturn *instruction) {...@@ -2497,7 +2497,7 @@ static void gen_async_return(CodeGen *g, IrInstructionReturn *instruction) {
2497 LLVMBuildRetVoid(g->builder);2497 LLVMBuildRetVoid(g->builder);
2498}2498}
24992499
2500static LLVMValueRef ir_render_return(CodeGen *g, IrExecutable *executable, IrInstructionReturn *instruction) {2500static LLVMValueRef ir_render_return(CodeGen *g, IrExecutableGen *executable, IrInstGenReturn *instruction) {
2501 if (fn_is_async(g->cur_fn)) {2501 if (fn_is_async(g->cur_fn)) {
2502 gen_async_return(g, instruction);2502 gen_async_return(g, instruction);
2503 return nullptr;2503 return nullptr;
...@@ -2838,12 +2838,12 @@ static LLVMValueRef gen_rem(CodeGen *g, bool want_runtime_safety, bool want_fast...@@ -2838,12 +2838,12 @@ static LLVMValueRef gen_rem(CodeGen *g, bool want_runtime_safety, bool want_fast
28382838
2839}2839}
28402840
2841static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,2841static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutableGen *executable,
2842 IrInstructionBinOp *bin_op_instruction)2842 IrInstGenBinOp *bin_op_instruction)
2843{2843{
2844 IrBinOp op_id = bin_op_instruction->op_id;2844 IrBinOp op_id = bin_op_instruction->op_id;
2845 IrInstruction *op1 = bin_op_instruction->op1;2845 IrInstGen *op1 = bin_op_instruction->op1;
2846 IrInstruction *op2 = bin_op_instruction->op2;2846 IrInstGen *op2 = bin_op_instruction->op2;
28472847
2848 ZigType *operand_type = op1->value->type;2848 ZigType *operand_type = op1->value->type;
2849 ZigType *scalar_type = (operand_type->id == ZigTypeIdVector) ? operand_type->data.vector.elem_type : operand_type;2849 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...@@ -3048,8 +3048,8 @@ static void add_error_range_check(CodeGen *g, ZigType *err_set_type, ZigType *in
3048 }3048 }
3049}3049}
30503050
3051static LLVMValueRef ir_render_resize_slice(CodeGen *g, IrExecutable *executable,3051static LLVMValueRef ir_render_resize_slice(CodeGen *g, IrExecutableGen *executable,
3052 IrInstructionResizeSlice *instruction)3052 IrInstGenResizeSlice *instruction)
3053{3053{
3054 ZigType *actual_type = instruction->operand->value->type;3054 ZigType *actual_type = instruction->operand->value->type;
3055 ZigType *wanted_type = instruction->base.value->type;3055 ZigType *wanted_type = instruction->base.value->type;
...@@ -3116,8 +3116,8 @@ static LLVMValueRef ir_render_resize_slice(CodeGen *g, IrExecutable *executable,...@@ -3116,8 +3116,8 @@ static LLVMValueRef ir_render_resize_slice(CodeGen *g, IrExecutable *executable,
3116 return result_loc;3116 return result_loc;
3117}3117}
31183118
3119static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,3119static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutableGen *executable,
3120 IrInstructionCast *cast_instruction)3120 IrInstGenCast *cast_instruction)
3121{3121{
3122 ZigType *actual_type = cast_instruction->value->value->type;3122 ZigType *actual_type = cast_instruction->value->value->type;
3123 ZigType *wanted_type = cast_instruction->base.value->type;3123 ZigType *wanted_type = cast_instruction->base.value->type;
...@@ -3194,8 +3194,8 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,...@@ -3194,8 +3194,8 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
3194 zig_unreachable();3194 zig_unreachable();
3195}3195}
31963196
3197static LLVMValueRef ir_render_ptr_of_array_to_slice(CodeGen *g, IrExecutable *executable,3197static LLVMValueRef ir_render_ptr_of_array_to_slice(CodeGen *g, IrExecutableGen *executable,
3198 IrInstructionPtrOfArrayToSlice *instruction)3198 IrInstGenPtrOfArrayToSlice *instruction)
3199{3199{
3200 ZigType *actual_type = instruction->operand->value->type;3200 ZigType *actual_type = instruction->operand->value->type;
3201 ZigType *slice_type = instruction->base.value->type;3201 ZigType *slice_type = instruction->base.value->type;
...@@ -3231,8 +3231,8 @@ static LLVMValueRef ir_render_ptr_of_array_to_slice(CodeGen *g, IrExecutable *ex...@@ -3231,8 +3231,8 @@ static LLVMValueRef ir_render_ptr_of_array_to_slice(CodeGen *g, IrExecutable *ex
3231 return result_loc;3231 return result_loc;
3232}3232}
32333233
3234static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutable *executable,3234static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutableGen *executable,
3235 IrInstructionPtrCastGen *instruction)3235 IrInstGenPtrCast *instruction)
3236{3236{
3237 ZigType *wanted_type = instruction->base.value->type;3237 ZigType *wanted_type = instruction->base.value->type;
3238 if (!type_has_bits(wanted_type)) {3238 if (!type_has_bits(wanted_type)) {
...@@ -3257,8 +3257,8 @@ static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutable *executable,...@@ -3257,8 +3257,8 @@ static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutable *executable,
3257 return result_ptr;3257 return result_ptr;
3258}3258}
32593259
3260static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutable *executable,3260static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutableGen *executable,
3261 IrInstructionBitCastGen *instruction)3261 IrInstGenBitCast *instruction)
3262{3262{
3263 ZigType *wanted_type = instruction->base.value->type;3263 ZigType *wanted_type = instruction->base.value->type;
3264 ZigType *actual_type = instruction->operand->value->type;3264 ZigType *actual_type = instruction->operand->value->type;
...@@ -3281,8 +3281,8 @@ static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutable *executable,...@@ -3281,8 +3281,8 @@ static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutable *executable,
3281 }3281 }
3282}3282}
32833283
3284static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executable,3284static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutableGen *executable,
3285 IrInstructionWidenOrShorten *instruction)3285 IrInstGenWidenOrShorten *instruction)
3286{3286{
3287 ZigType *actual_type = instruction->target->value->type;3287 ZigType *actual_type = instruction->target->value->type;
3288 // TODO instead of this logic, use the Noop instruction to change the type from3288 // 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...@@ -3298,7 +3298,7 @@ static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executa
3298 instruction->base.value->type, target_val);3298 instruction->base.value->type, target_val);
3299}3299}
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) {
3302 ZigType *wanted_type = instruction->base.value->type;3302 ZigType *wanted_type = instruction->base.value->type;
3303 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);3303 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...@@ -3336,13 +3336,13 @@ static LLVMValueRef ir_render_int_to_ptr(CodeGen *g, IrExecutable *executable, I
3336 return LLVMBuildIntToPtr(g->builder, target_val, get_llvm_type(g, wanted_type), "");3336 return LLVMBuildIntToPtr(g->builder, target_val, get_llvm_type(g, wanted_type), "");
3337}3337}
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) {
3340 ZigType *wanted_type = instruction->base.value->type;3340 ZigType *wanted_type = instruction->base.value->type;
3341 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);3341 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
3342 return LLVMBuildPtrToInt(g->builder, target_val, get_llvm_type(g, wanted_type), "");3342 return LLVMBuildPtrToInt(g->builder, target_val, get_llvm_type(g, wanted_type), "");
3343}3343}
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) {
3346 ZigType *wanted_type = instruction->base.value->type;3346 ZigType *wanted_type = instruction->base.value->type;
3347 assert(wanted_type->id == ZigTypeIdEnum);3347 assert(wanted_type->id == ZigTypeIdEnum);
3348 ZigType *tag_int_type = wanted_type->data.enumeration.tag_int_type;3348 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,...@@ -3369,7 +3369,7 @@ static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutable *executable,
3369 return tag_int_value;3369 return tag_int_value;
3370}3370}
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) {
3373 ZigType *wanted_type = instruction->base.value->type;3373 ZigType *wanted_type = instruction->base.value->type;
3374 assert(wanted_type->id == ZigTypeIdErrorSet);3374 assert(wanted_type->id == ZigTypeIdErrorSet);
33753375
...@@ -3386,7 +3386,7 @@ static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, I...@@ -3386,7 +3386,7 @@ static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, I
3386 return gen_widen_or_shorten(g, false, actual_type, g->err_tag_type, target_val);3386 return gen_widen_or_shorten(g, false, actual_type, g->err_tag_type, target_val);
3387}3387}
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) {
3390 ZigType *wanted_type = instruction->base.value->type;3390 ZigType *wanted_type = instruction->base.value->type;
3391 assert(wanted_type->id == ZigTypeIdInt);3391 assert(wanted_type->id == ZigTypeIdInt);
3392 assert(!wanted_type->data.integral.is_signed);3392 assert(!wanted_type->data.integral.is_signed);
...@@ -3412,8 +3412,8 @@ static LLVMValueRef ir_render_err_to_int(CodeGen *g, IrExecutable *executable, I...@@ -3412,8 +3412,8 @@ static LLVMValueRef ir_render_err_to_int(CodeGen *g, IrExecutable *executable, I
3412 }3412 }
3413}3413}
34143414
3415static LLVMValueRef ir_render_unreachable(CodeGen *g, IrExecutable *executable,3415static LLVMValueRef ir_render_unreachable(CodeGen *g, IrExecutableGen *executable,
3416 IrInstructionUnreachable *unreachable_instruction)3416 IrInstGenUnreachable *unreachable_instruction)
3417{3417{
3418 if (ir_want_runtime_safety(g, &unreachable_instruction->base)) {3418 if (ir_want_runtime_safety(g, &unreachable_instruction->base)) {
3419 gen_safety_crash(g, PanicMsgIdUnreachable);3419 gen_safety_crash(g, PanicMsgIdUnreachable);
...@@ -3423,8 +3423,8 @@ static LLVMValueRef ir_render_unreachable(CodeGen *g, IrExecutable *executable,...@@ -3423,8 +3423,8 @@ static LLVMValueRef ir_render_unreachable(CodeGen *g, IrExecutable *executable,
3423 return nullptr;3423 return nullptr;
3424}3424}
34253425
3426static LLVMValueRef ir_render_cond_br(CodeGen *g, IrExecutable *executable,3426static LLVMValueRef ir_render_cond_br(CodeGen *g, IrExecutableGen *executable,
3427 IrInstructionCondBr *cond_br_instruction)3427 IrInstGenCondBr *cond_br_instruction)
3428{3428{
3429 LLVMBuildCondBr(g->builder,3429 LLVMBuildCondBr(g->builder,
3430 ir_llvm_value(g, cond_br_instruction->condition),3430 ir_llvm_value(g, cond_br_instruction->condition),
...@@ -3433,51 +3433,56 @@ static LLVMValueRef ir_render_cond_br(CodeGen *g, IrExecutable *executable,...@@ -3433,51 +3433,56 @@ static LLVMValueRef ir_render_cond_br(CodeGen *g, IrExecutable *executable,
3433 return nullptr;3433 return nullptr;
3434}3434}
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) {
3437 LLVMBuildBr(g->builder, br_instruction->dest_block->llvm_block);3437 LLVMBuildBr(g->builder, br_instruction->dest_block->llvm_block);
3438 return nullptr;3438 return nullptr;
3439}3439}
34403440
3441static LLVMValueRef ir_render_un_op(CodeGen *g, IrExecutable *executable, IrInstructionUnOp *un_op_instruction) {3441static LLVMValueRef ir_render_binary_not(CodeGen *g, IrExecutableGen *executable,
3442 IrUnOp op_id = un_op_instruction->op_id;3442 IrInstGenBinaryNot *inst)
3443 LLVMValueRef expr = ir_llvm_value(g, un_op_instruction->value);3443{
3444 ZigType *operand_type = un_op_instruction->value->value->type;3444 LLVMValueRef operand = ir_llvm_value(g, inst->operand);
3445 ZigType *scalar_type = (operand_type->id == ZigTypeIdVector) ? operand_type->data.vector.elem_type : operand_type;3445 return LLVMBuildNot(g->builder, operand, "");
34463446}
3447 switch (op_id) {3447
3448 case IrUnOpInvalid:3448static LLVMValueRef ir_gen_negation(CodeGen *g, IrInstGen *inst, IrInstGen *operand, bool wrapping) {
3449 case IrUnOpOptional:3449 LLVMValueRef llvm_operand = ir_llvm_value(g, operand);
3450 case IrUnOpDereference:3450 ZigType *operand_type = operand->value->type;
3451 zig_unreachable();3451 ZigType *scalar_type = (operand_type->id == ZigTypeIdVector) ?
3452 case IrUnOpNegation:3452 operand_type->data.vector.elem_type : operand_type;
3453 case IrUnOpNegationWrap:3453
3454 {3454 if (scalar_type->id == ZigTypeIdFloat) {
3455 if (scalar_type->id == ZigTypeIdFloat) {3455 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, inst));
3456 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &un_op_instruction->base));3456 return LLVMBuildFNeg(g->builder, llvm_operand, "");
3457 return LLVMBuildFNeg(g->builder, expr, "");3457 } else if (scalar_type->id == ZigTypeIdInt) {
3458 } else if (scalar_type->id == ZigTypeIdInt) {3458 if (wrapping) {
3459 if (op_id == IrUnOpNegationWrap) {3459 return LLVMBuildNeg(g->builder, llvm_operand, "");
3460 return LLVMBuildNeg(g->builder, expr, "");3460 } else if (ir_want_runtime_safety(g, inst)) {
3461 } else if (ir_want_runtime_safety(g, &un_op_instruction->base)) {3461 LLVMValueRef zero = LLVMConstNull(LLVMTypeOf(llvm_operand));
3462 LLVMValueRef zero = LLVMConstNull(LLVMTypeOf(expr));3462 return gen_overflow_op(g, operand_type, AddSubMulSub, zero, llvm_operand);
3463 return gen_overflow_op(g, operand_type, AddSubMulSub, zero, expr);3463 } else if (scalar_type->data.integral.is_signed) {
3464 } else if (scalar_type->data.integral.is_signed) {3464 return LLVMBuildNSWNeg(g->builder, llvm_operand, "");
3465 return LLVMBuildNSWNeg(g->builder, expr, "");3465 } else {
3466 } else {3466 return LLVMBuildNUWNeg(g->builder, llvm_operand, "");
3467 return LLVMBuildNUWNeg(g->builder, expr, "");3467 }
3468 }3468 } else {
3469 } else {3469 zig_unreachable();
3470 zig_unreachable();
3471 }
3472 }
3473 case IrUnOpBinNot:
3474 return LLVMBuildNot(g->builder, expr, "");
3475 }3470 }
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);
3478}3483}
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) {
3481 LLVMValueRef value = ir_llvm_value(g, instruction->value);3486 LLVMValueRef value = ir_llvm_value(g, instruction->value);
3482 LLVMValueRef zero = LLVMConstNull(LLVMTypeOf(value));3487 LLVMValueRef zero = LLVMConstNull(LLVMTypeOf(value));
3483 return LLVMBuildICmp(g->builder, LLVMIntEQ, value, zero, "");3488 return LLVMBuildICmp(g->builder, LLVMIntEQ, value, zero, "");
...@@ -3491,14 +3496,14 @@ static void render_decl_var(CodeGen *g, ZigVar *var) {...@@ -3491,14 +3496,14 @@ static void render_decl_var(CodeGen *g, ZigVar *var) {
3491 gen_var_debug_decl(g, var);3496 gen_var_debug_decl(g, var);
3492}3497}
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) {
3495 instruction->var->ptr_instruction = instruction->var_ptr;3500 instruction->var->ptr_instruction = instruction->var_ptr;
3496 render_decl_var(g, instruction->var);3501 render_decl_var(g, instruction->var);
3497 return nullptr;3502 return nullptr;
3498}3503}
34993504
3500static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutable *executable,3505static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutableGen *executable,
3501 IrInstructionLoadPtrGen *instruction)3506 IrInstGenLoadPtr *instruction)
3502{3507{
3503 ZigType *child_type = instruction->base.value->type;3508 ZigType *child_type = instruction->base.value->type;
3504 if (!type_has_bits(child_type))3509 if (!type_has_bits(child_type))
...@@ -3700,7 +3705,7 @@ static void gen_undef_init(CodeGen *g, uint32_t ptr_align_bytes, ZigType *value_...@@ -3700,7 +3705,7 @@ static void gen_undef_init(CodeGen *g, uint32_t ptr_align_bytes, ZigType *value_
3700 }3705 }
3701}3706}
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) {
3704 Error err;3709 Error err;
37053710
3706 ZigType *ptr_type = instruction->ptr->value->type;3711 ZigType *ptr_type = instruction->ptr->value->type;
...@@ -3710,7 +3715,7 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir...@@ -3710,7 +3715,7 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir
3710 codegen_report_errors_and_exit(g);3715 codegen_report_errors_and_exit(g);
3711 if (!ptr_type_has_bits)3716 if (!ptr_type_has_bits)
3712 return nullptr;3717 return nullptr;
3713 if (instruction->ptr->ref_count == 0) {3718 if (instruction->ptr->base.ref_count == 0) {
3714 // In this case, this StorePtr instruction should be elided. Something happened like this:3719 // In this case, this StorePtr instruction should be elided. Something happened like this:
3715 // var t = true;3720 // var t = true;
3716 // const x = if (t) Num.Two else unreachable;3721 // const x = if (t) Num.Two else unreachable;
...@@ -3732,8 +3737,8 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir...@@ -3732,8 +3737,8 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir
3732 return nullptr;3737 return nullptr;
3733}3738}
37343739
3735static LLVMValueRef ir_render_vector_store_elem(CodeGen *g, IrExecutable *executable,3740static LLVMValueRef ir_render_vector_store_elem(CodeGen *g, IrExecutableGen *executable,
3736 IrInstructionVectorStoreElem *instruction)3741 IrInstGenVectorStoreElem *instruction)
3737{3742{
3738 LLVMValueRef vector_ptr = ir_llvm_value(g, instruction->vector_ptr);3743 LLVMValueRef vector_ptr = ir_llvm_value(g, instruction->vector_ptr);
3739 LLVMValueRef index = ir_llvm_value(g, instruction->index);3744 LLVMValueRef index = ir_llvm_value(g, instruction->index);
...@@ -3745,7 +3750,7 @@ static LLVMValueRef ir_render_vector_store_elem(CodeGen *g, IrExecutable *execut...@@ -3745,7 +3750,7 @@ static LLVMValueRef ir_render_vector_store_elem(CodeGen *g, IrExecutable *execut
3745 return nullptr;3750 return nullptr;
3746}3751}
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) {
3749 if (instruction->base.value->special != ConstValSpecialRuntime)3754 if (instruction->base.value->special != ConstValSpecialRuntime)
3750 return ir_llvm_value(g, &instruction->base);3755 return ir_llvm_value(g, &instruction->base);
3751 ZigVar *var = instruction->var;3756 ZigVar *var = instruction->var;
...@@ -3757,8 +3762,8 @@ static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrIn...@@ -3757,8 +3762,8 @@ static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrIn
3757 }3762 }
3758}3763}
37593764
3760static LLVMValueRef ir_render_return_ptr(CodeGen *g, IrExecutable *executable,3765static LLVMValueRef ir_render_return_ptr(CodeGen *g, IrExecutableGen *executable,
3761 IrInstructionReturnPtr *instruction)3766 IrInstGenReturnPtr *instruction)
3762{3767{
3763 if (!type_has_bits(instruction->base.value->type))3768 if (!type_has_bits(instruction->base.value->type))
3764 return nullptr;3769 return nullptr;
...@@ -3766,7 +3771,7 @@ static LLVMValueRef ir_render_return_ptr(CodeGen *g, IrExecutable *executable,...@@ -3766,7 +3771,7 @@ static LLVMValueRef ir_render_return_ptr(CodeGen *g, IrExecutable *executable,
3766 return g->cur_ret_ptr;3771 return g->cur_ret_ptr;
3767}3772}
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) {
3770 LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->array_ptr);3775 LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->array_ptr);
3771 ZigType *array_ptr_type = instruction->array_ptr->value->type;3776 ZigType *array_ptr_type = instruction->array_ptr->value->type;
3772 assert(array_ptr_type->id == ZigTypeIdPointer);3777 assert(array_ptr_type->id == ZigTypeIdPointer);
...@@ -3942,7 +3947,7 @@ static void render_async_spills(CodeGen *g) {...@@ -3942,7 +3947,7 @@ static void render_async_spills(CodeGen *g) {
3942 ZigType *frame_type = g->cur_fn->frame_type->data.frame.locals_struct;3947 ZigType *frame_type = g->cur_fn->frame_type->data.frame.locals_struct;
39433948
3944 for (size_t alloca_i = 0; alloca_i < g->cur_fn->alloca_gen_list.length; alloca_i += 1) {3949 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);
3946 if (instruction->field_index == SIZE_MAX)3951 if (instruction->field_index == SIZE_MAX)
3947 continue;3952 continue;
39483953
...@@ -4009,7 +4014,7 @@ static void gen_init_stack_trace(CodeGen *g, LLVMValueRef trace_field_ptr, LLVMV...@@ -4009,7 +4014,7 @@ static void gen_init_stack_trace(CodeGen *g, LLVMValueRef trace_field_ptr, LLVMV
4009 LLVMBuildStore(g->builder, LLVMConstInt(usize_type_ref, stack_trace_ptr_count, false), addrs_len_ptr);4014 LLVMBuildStore(g->builder, LLVMConstInt(usize_type_ref, stack_trace_ptr_count, false), addrs_len_ptr);
4010}4015}
40114016
4012static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstructionCallGen *instruction) {4017static LLVMValueRef ir_render_call(CodeGen *g, IrExecutableGen *executable, IrInstGenCall *instruction) {
4013 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;4018 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;
40144019
4015 LLVMValueRef fn_val;4020 LLVMValueRef fn_val;
...@@ -4144,7 +4149,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr...@@ -4144,7 +4149,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
4144 LLVMValueRef err_ret_trace_ptr_ptr = LLVMBuildStructGEP(g->builder, frame_result_loc,4149 LLVMValueRef err_ret_trace_ptr_ptr = LLVMBuildStructGEP(g->builder, frame_result_loc,
4145 frame_index_trace_arg(g, src_return_type) + 1, "");4150 frame_index_trace_arg(g, src_return_type) + 1, "");
4146 bool is_llvm_alloca;4151 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,
4148 &is_llvm_alloca);4153 &is_llvm_alloca);
4149 LLVMBuildStore(g->builder, my_err_ret_trace_val, err_ret_trace_ptr_ptr);4154 LLVMBuildStore(g->builder, my_err_ret_trace_val, err_ret_trace_ptr_ptr);
4150 }4155 }
...@@ -4203,7 +4208,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr...@@ -4203,7 +4208,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
4203 gen_init_stack_trace(g, trace_field_ptr, addrs_field_ptr);4208 gen_init_stack_trace(g, trace_field_ptr, addrs_field_ptr);
42044209
4205 bool is_llvm_alloca;4210 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));
4207 }4212 }
4208 }4213 }
4209 } else {4214 } else {
...@@ -4212,7 +4217,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr...@@ -4212,7 +4217,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
4212 }4217 }
4213 if (prefix_arg_err_ret_stack) {4218 if (prefix_arg_err_ret_stack) {
4214 bool is_llvm_alloca;4219 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));
4216 }4221 }
4217 }4222 }
4218 FnWalk fn_walk = {};4223 FnWalk fn_walk = {};
...@@ -4322,13 +4327,13 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr...@@ -4322,13 +4327,13 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
43224327
4323 LLVMPositionBuilderAtEnd(g->builder, call_bb);4328 LLVMPositionBuilderAtEnd(g->builder, call_bb);
4324 gen_assert_resume_id(g, &instruction->base, ResumeIdReturn, PanicMsgIdResumedAnAwaitingFn, nullptr);4329 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
4327 if (!type_has_bits(src_return_type))4332 if (!type_has_bits(src_return_type))
4328 return nullptr;4333 return nullptr;
43294334
4330 if (result_loc != nullptr) {4335 if (result_loc != nullptr) {
4331 if (instruction->result_loc->id == IrInstructionIdReturnPtr) {4336 if (instruction->result_loc->id == IrInstGenIdReturnPtr) {
4332 instruction->base.spill = nullptr;4337 instruction->base.spill = nullptr;
4333 return g->cur_ret_ptr;4338 return g->cur_ret_ptr;
4334 } else {4339 } else {
...@@ -4388,8 +4393,8 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr...@@ -4388,8 +4393,8 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
4388 }4393 }
4389}4394}
43904395
4391static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executable,4396static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutableGen *executable,
4392 IrInstructionStructFieldPtr *instruction)4397 IrInstGenStructFieldPtr *instruction)
4393{4398{
4394 Error err;4399 Error err;
43954400
...@@ -4439,8 +4444,8 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executa...@@ -4439,8 +4444,8 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executa
4439 return field_ptr_val;4444 return field_ptr_val;
4440}4445}
44414446
4442static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutable *executable,4447static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutableGen *executable,
4443 IrInstructionUnionFieldPtr *instruction)4448 IrInstGenUnionFieldPtr *instruction)
4444{4449{
4445 if (instruction->base.value->special != ConstValSpecialRuntime)4450 if (instruction->base.value->special != ConstValSpecialRuntime)
4446 return nullptr;4451 return nullptr;
...@@ -4539,8 +4544,8 @@ static size_t find_asm_index(CodeGen *g, AstNode *node, AsmToken *tok, Buf *src_...@@ -4539,8 +4544,8 @@ static size_t find_asm_index(CodeGen *g, AstNode *node, AsmToken *tok, Buf *src_
4539 return SIZE_MAX;4544 return SIZE_MAX;
4540}4545}
45414546
4542static LLVMValueRef ir_render_asm_gen(CodeGen *g, IrExecutable *executable, IrInstructionAsmGen *instruction) {4547static LLVMValueRef ir_render_asm_gen(CodeGen *g, IrExecutableGen *executable, IrInstGenAsm *instruction) {
4543 AstNode *asm_node = instruction->base.source_node;4548 AstNode *asm_node = instruction->base.base.source_node;
4544 assert(asm_node->type == NodeTypeAsmExpr);4549 assert(asm_node->type == NodeTypeAsmExpr);
4545 AstNodeAsmExpr *asm_expr = &asm_node->data.asm_expr;4550 AstNodeAsmExpr *asm_expr = &asm_node->data.asm_expr;
45464551
...@@ -4624,7 +4629,7 @@ static LLVMValueRef ir_render_asm_gen(CodeGen *g, IrExecutable *executable, IrIn...@@ -4624,7 +4629,7 @@ static LLVMValueRef ir_render_asm_gen(CodeGen *g, IrExecutable *executable, IrIn
4624 for (size_t i = 0; i < asm_expr->input_list.length; i += 1, total_index += 1, param_index += 1) {4629 for (size_t i = 0; i < asm_expr->input_list.length; i += 1, total_index += 1, param_index += 1) {
4625 AsmInput *asm_input = asm_expr->input_list.at(i);4630 AsmInput *asm_input = asm_expr->input_list.at(i);
4626 buf_replace(asm_input->constraint, ',', '|');4631 buf_replace(asm_input->constraint, ',', '|');
4627 IrInstruction *ir_input = instruction->input_list[i];4632 IrInstGen *ir_input = instruction->input_list[i];
4628 buf_append_buf(&constraint_buf, asm_input->constraint);4633 buf_append_buf(&constraint_buf, asm_input->constraint);
4629 if (total_index + 1 < total_constraint_count) {4634 if (total_index + 1 < total_constraint_count) {
4630 buf_append_char(&constraint_buf, ',');4635 buf_append_char(&constraint_buf, ',');
...@@ -4687,14 +4692,14 @@ static LLVMValueRef gen_non_null_bit(CodeGen *g, ZigType *maybe_type, LLVMValueR...@@ -4687,14 +4692,14 @@ static LLVMValueRef gen_non_null_bit(CodeGen *g, ZigType *maybe_type, LLVMValueR
4687 return gen_load_untyped(g, maybe_field_ptr, 0, false, "");4692 return gen_load_untyped(g, maybe_field_ptr, 0, false, "");
4688}4693}
46894694
4690static LLVMValueRef ir_render_test_non_null(CodeGen *g, IrExecutable *executable,4695static LLVMValueRef ir_render_test_non_null(CodeGen *g, IrExecutableGen *executable,
4691 IrInstructionTestNonNull *instruction)4696 IrInstGenTestNonNull *instruction)
4692{4697{
4693 return gen_non_null_bit(g, instruction->value->value->type, ir_llvm_value(g, instruction->value));4698 return gen_non_null_bit(g, instruction->value->value->type, ir_llvm_value(g, instruction->value));
4694}4699}
46954700
4696static LLVMValueRef ir_render_optional_unwrap_ptr(CodeGen *g, IrExecutable *executable,4701static LLVMValueRef ir_render_optional_unwrap_ptr(CodeGen *g, IrExecutableGen *executable,
4697 IrInstructionOptionalUnwrapPtr *instruction)4702 IrInstGenOptionalUnwrapPtr *instruction)
4698{4703{
4699 if (instruction->base.value->special != ConstValSpecialRuntime)4704 if (instruction->base.value->special != ConstValSpecialRuntime)
4700 return nullptr;4705 return nullptr;
...@@ -4796,7 +4801,7 @@ static LLVMValueRef get_int_builtin_fn(CodeGen *g, ZigType *expr_type, BuiltinFn...@@ -4796,7 +4801,7 @@ static LLVMValueRef get_int_builtin_fn(CodeGen *g, ZigType *expr_type, BuiltinFn
4796 return fn_val;4801 return fn_val;
4797}4802}
47984803
4799static LLVMValueRef ir_render_clz(CodeGen *g, IrExecutable *executable, IrInstructionClz *instruction) {4804static LLVMValueRef ir_render_clz(CodeGen *g, IrExecutableGen *executable, IrInstGenClz *instruction) {
4800 ZigType *int_type = instruction->op->value->type;4805 ZigType *int_type = instruction->op->value->type;
4801 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdClz);4806 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdClz);
4802 LLVMValueRef operand = ir_llvm_value(g, instruction->op);4807 LLVMValueRef operand = ir_llvm_value(g, instruction->op);
...@@ -4808,7 +4813,7 @@ static LLVMValueRef ir_render_clz(CodeGen *g, IrExecutable *executable, IrInstru...@@ -4808,7 +4813,7 @@ static LLVMValueRef ir_render_clz(CodeGen *g, IrExecutable *executable, IrInstru
4808 return gen_widen_or_shorten(g, false, int_type, instruction->base.value->type, wrong_size_int);4813 return gen_widen_or_shorten(g, false, int_type, instruction->base.value->type, wrong_size_int);
4809}4814}
48104815
4811static LLVMValueRef ir_render_ctz(CodeGen *g, IrExecutable *executable, IrInstructionCtz *instruction) {4816static LLVMValueRef ir_render_ctz(CodeGen *g, IrExecutableGen *executable, IrInstGenCtz *instruction) {
4812 ZigType *int_type = instruction->op->value->type;4817 ZigType *int_type = instruction->op->value->type;
4813 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdCtz);4818 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdCtz);
4814 LLVMValueRef operand = ir_llvm_value(g, instruction->op);4819 LLVMValueRef operand = ir_llvm_value(g, instruction->op);
...@@ -4820,7 +4825,7 @@ static LLVMValueRef ir_render_ctz(CodeGen *g, IrExecutable *executable, IrInstru...@@ -4820,7 +4825,7 @@ static LLVMValueRef ir_render_ctz(CodeGen *g, IrExecutable *executable, IrInstru
4820 return gen_widen_or_shorten(g, false, int_type, instruction->base.value->type, wrong_size_int);4825 return gen_widen_or_shorten(g, false, int_type, instruction->base.value->type, wrong_size_int);
4821}4826}
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) {
4824 uint64_t len_a = instruction->a->value->type->data.vector.len;4829 uint64_t len_a = instruction->a->value->type->data.vector.len;
4825 uint64_t len_mask = instruction->mask->value->type->data.vector.len;4830 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...@@ -4829,7 +4834,7 @@ static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutable *executabl
4829 // when changing code, so Zig uses negative numbers to index the4834 // when changing code, so Zig uses negative numbers to index the
4830 // second vector. These start at -1 and go down, and are easiest to use4835 // second vector. These start at -1 and go down, and are easiest to use
4831 // with the ~ operator. Here we convert between the two formats.4836 // with the ~ operator. Here we convert between the two formats.
4832 IrInstruction *mask = instruction->mask;4837 IrInstGen *mask = instruction->mask;
4833 LLVMValueRef *values = allocate<LLVMValueRef>(len_mask);4838 LLVMValueRef *values = allocate<LLVMValueRef>(len_mask);
4834 for (uint64_t i = 0; i < len_mask; i++) {4839 for (uint64_t i = 0; i < len_mask; i++) {
4835 if (mask->value->data.x_array.data.s_none.elements[i].special == ConstValSpecialUndef) {4840 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...@@ -4850,7 +4855,7 @@ static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutable *executabl
4850 llvm_mask_value, "");4855 llvm_mask_value, "");
4851}4856}
48524857
4853static LLVMValueRef ir_render_splat(CodeGen *g, IrExecutable *executable, IrInstructionSplatGen *instruction) {4858static LLVMValueRef ir_render_splat(CodeGen *g, IrExecutableGen *executable, IrInstGenSplat *instruction) {
4854 ZigType *result_type = instruction->base.value->type;4859 ZigType *result_type = instruction->base.value->type;
4855 ir_assert(result_type->id == ZigTypeIdVector, &instruction->base);4860 ir_assert(result_type->id == ZigTypeIdVector, &instruction->base);
4856 uint32_t len = result_type->data.vector.len;4861 uint32_t len = result_type->data.vector.len;
...@@ -4862,7 +4867,7 @@ static LLVMValueRef ir_render_splat(CodeGen *g, IrExecutable *executable, IrInst...@@ -4862,7 +4867,7 @@ static LLVMValueRef ir_render_splat(CodeGen *g, IrExecutable *executable, IrInst
4862 return LLVMBuildShuffleVector(g->builder, op_vector, undef_vector, LLVMConstNull(mask_llvm_type), "");4867 return LLVMBuildShuffleVector(g->builder, op_vector, undef_vector, LLVMConstNull(mask_llvm_type), "");
4863}4868}
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) {
4866 ZigType *int_type = instruction->op->value->type;4871 ZigType *int_type = instruction->op->value->type;
4867 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdPopCount);4872 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdPopCount);
4868 LLVMValueRef operand = ir_llvm_value(g, instruction->op);4873 LLVMValueRef operand = ir_llvm_value(g, instruction->op);
...@@ -4870,7 +4875,7 @@ static LLVMValueRef ir_render_pop_count(CodeGen *g, IrExecutable *executable, Ir...@@ -4870,7 +4875,7 @@ static LLVMValueRef ir_render_pop_count(CodeGen *g, IrExecutable *executable, Ir
4870 return gen_widen_or_shorten(g, false, int_type, instruction->base.value->type, wrong_size_int);4875 return gen_widen_or_shorten(g, false, int_type, instruction->base.value->type, wrong_size_int);
4871}4876}
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) {
4874 ZigType *target_type = instruction->target_value->value->type;4879 ZigType *target_type = instruction->target_value->value->type;
4875 LLVMBasicBlockRef else_block = instruction->else_block->llvm_block;4880 LLVMBasicBlockRef else_block = instruction->else_block->llvm_block;
48764881
...@@ -4884,7 +4889,7 @@ static LLVMValueRef ir_render_switch_br(CodeGen *g, IrExecutable *executable, Ir...@@ -4884,7 +4889,7 @@ static LLVMValueRef ir_render_switch_br(CodeGen *g, IrExecutable *executable, Ir
4884 (unsigned)instruction->case_count);4889 (unsigned)instruction->case_count);
48854890
4886 for (size_t i = 0; i < instruction->case_count; i += 1) {4891 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
4889 LLVMValueRef case_value = ir_llvm_value(g, this_case->value);4894 LLVMValueRef case_value = ir_llvm_value(g, this_case->value);
4890 if (target_type->id == ZigTypeIdPointer) {4895 if (target_type->id == ZigTypeIdPointer) {
...@@ -4898,7 +4903,7 @@ static LLVMValueRef ir_render_switch_br(CodeGen *g, IrExecutable *executable, Ir...@@ -4898,7 +4903,7 @@ static LLVMValueRef ir_render_switch_br(CodeGen *g, IrExecutable *executable, Ir
4898 return nullptr;4903 return nullptr;
4899}4904}
49004905
4901static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutable *executable, IrInstructionPhi *instruction) {4906static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutableGen *executable, IrInstGenPhi *instruction) {
4902 if (!type_has_bits(instruction->base.value->type))4907 if (!type_has_bits(instruction->base.value->type))
4903 return nullptr;4908 return nullptr;
49044909
...@@ -4920,7 +4925,7 @@ static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutable *executable, IrInstru...@@ -4920,7 +4925,7 @@ static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutable *executable, IrInstru
4920 return phi;4925 return phi;
4921}4926}
49224927
4923static LLVMValueRef ir_render_ref(CodeGen *g, IrExecutable *executable, IrInstructionRefGen *instruction) {4928static LLVMValueRef ir_render_ref(CodeGen *g, IrExecutableGen *executable, IrInstGenRef *instruction) {
4924 if (!type_has_bits(instruction->base.value->type)) {4929 if (!type_has_bits(instruction->base.value->type)) {
4925 return nullptr;4930 return nullptr;
4926 }4931 }
...@@ -4934,7 +4939,7 @@ static LLVMValueRef ir_render_ref(CodeGen *g, IrExecutable *executable, IrInstru...@@ -4934,7 +4939,7 @@ static LLVMValueRef ir_render_ref(CodeGen *g, IrExecutable *executable, IrInstru
4934 }4939 }
4935}4940}
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) {
4938 assert(g->generate_error_name_table);4943 assert(g->generate_error_name_table);
49394944
4940 if (g->errors_by_index.length == 1) {4945 if (g->errors_by_index.length == 1) {
...@@ -5055,13 +5060,13 @@ static LLVMValueRef get_enum_tag_name_function(CodeGen *g, ZigType *enum_type) {...@@ -5055,13 +5060,13 @@ static LLVMValueRef get_enum_tag_name_function(CodeGen *g, ZigType *enum_type) {
5055 return fn_val;5060 return fn_val;
5056}5061}
50575062
5058static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutable *executable,5063static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutableGen *executable,
5059 IrInstructionTagName *instruction)5064 IrInstGenTagName *instruction)
5060{5065{
5061 ZigType *enum_type = instruction->target->value->type;5066 ZigType *enum_type = instruction->target->value->type;
5062 assert(enum_type->id == ZigTypeIdEnum);5067 assert(enum_type->id == ZigTypeIdEnum);
5063 if (enum_type->data.enumeration.non_exhaustive) {5068 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,
5065 buf_sprintf("TODO @tagName on non-exhaustive enum https://github.com/ziglang/zig/issues/3991"));5070 buf_sprintf("TODO @tagName on non-exhaustive enum https://github.com/ziglang/zig/issues/3991"));
5066 codegen_report_errors_and_exit(g);5071 codegen_report_errors_and_exit(g);
5067 }5072 }
...@@ -5073,8 +5078,8 @@ static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutable *executable...@@ -5073,8 +5078,8 @@ static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutable *executable
5073 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");5078 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");
5074}5079}
50755080
5076static LLVMValueRef ir_render_field_parent_ptr(CodeGen *g, IrExecutable *executable,5081static LLVMValueRef ir_render_field_parent_ptr(CodeGen *g, IrExecutableGen *executable,
5077 IrInstructionFieldParentPtr *instruction)5082 IrInstGenFieldParentPtr *instruction)
5078{5083{
5079 ZigType *container_ptr_type = instruction->base.value->type;5084 ZigType *container_ptr_type = instruction->base.value->type;
5080 assert(container_ptr_type->id == ZigTypeIdPointer);5085 assert(container_ptr_type->id == ZigTypeIdPointer);
...@@ -5100,7 +5105,7 @@ static LLVMValueRef ir_render_field_parent_ptr(CodeGen *g, IrExecutable *executa...@@ -5100,7 +5105,7 @@ static LLVMValueRef ir_render_field_parent_ptr(CodeGen *g, IrExecutable *executa
5100 }5105 }
5101}5106}
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) {
5104 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);5109 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
5105 assert(target_val);5110 assert(target_val);
51065111
...@@ -5163,11 +5168,11 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I...@@ -5163,11 +5168,11 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I
5163 return target_val;5168 return target_val;
5164}5169}
51655170
5166static LLVMValueRef ir_render_error_return_trace(CodeGen *g, IrExecutable *executable,5171static LLVMValueRef ir_render_error_return_trace(CodeGen *g, IrExecutableGen *executable,
5167 IrInstructionErrorReturnTrace *instruction)5172 IrInstGenErrorReturnTrace *instruction)
5168{5173{
5169 bool is_llvm_alloca;5174 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);
5171 if (cur_err_ret_trace_val == nullptr) {5176 if (cur_err_ret_trace_val == nullptr) {
5172 return LLVMConstNull(get_llvm_type(g, ptr_to_stack_trace_type(g)));5177 return LLVMConstNull(get_llvm_type(g, ptr_to_stack_trace_type(g)));
5173 }5178 }
...@@ -5205,7 +5210,7 @@ static enum ZigLLVM_AtomicRMWBinOp to_ZigLLVMAtomicRMWBinOp(AtomicRmwOp op, bool...@@ -5205,7 +5210,7 @@ static enum ZigLLVM_AtomicRMWBinOp to_ZigLLVMAtomicRMWBinOp(AtomicRmwOp op, bool
5205 zig_unreachable();5210 zig_unreachable();
5206}5211}
52075212
5208static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutable *executable, IrInstructionCmpxchgGen *instruction) {5213static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutableGen *executable, IrInstGenCmpxchg *instruction) {
5209 LLVMValueRef ptr_val = ir_llvm_value(g, instruction->ptr);5214 LLVMValueRef ptr_val = ir_llvm_value(g, instruction->ptr);
5210 LLVMValueRef cmp_val = ir_llvm_value(g, instruction->cmp_value);5215 LLVMValueRef cmp_val = ir_llvm_value(g, instruction->cmp_value);
5211 LLVMValueRef new_val = ir_llvm_value(g, instruction->new_value);5216 LLVMValueRef new_val = ir_llvm_value(g, instruction->new_value);
...@@ -5246,13 +5251,13 @@ static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutable *executable, IrIn...@@ -5246,13 +5251,13 @@ static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutable *executable, IrIn
5246 return result_loc;5251 return result_loc;
5247}5252}
52485253
5249static LLVMValueRef ir_render_fence(CodeGen *g, IrExecutable *executable, IrInstructionFence *instruction) {5254static LLVMValueRef ir_render_fence(CodeGen *g, IrExecutableGen *executable, IrInstGenFence *instruction) {
5250 LLVMAtomicOrdering atomic_order = to_LLVMAtomicOrdering(instruction->order);5255 LLVMAtomicOrdering atomic_order = to_LLVMAtomicOrdering(instruction->order);
5251 LLVMBuildFence(g->builder, atomic_order, false, "");5256 LLVMBuildFence(g->builder, atomic_order, false, "");
5252 return nullptr;5257 return nullptr;
5253}5258}
52545259
5255static LLVMValueRef ir_render_truncate(CodeGen *g, IrExecutable *executable, IrInstructionTruncate *instruction) {5260static LLVMValueRef ir_render_truncate(CodeGen *g, IrExecutableGen *executable, IrInstGenTruncate *instruction) {
5256 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);5261 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
5257 ZigType *dest_type = instruction->base.value->type;5262 ZigType *dest_type = instruction->base.value->type;
5258 ZigType *src_type = instruction->target->value->type;5263 ZigType *src_type = instruction->target->value->type;
...@@ -5267,7 +5272,7 @@ static LLVMValueRef ir_render_truncate(CodeGen *g, IrExecutable *executable, IrI...@@ -5267,7 +5272,7 @@ static LLVMValueRef ir_render_truncate(CodeGen *g, IrExecutable *executable, IrI
5267 }5272 }
5268}5273}
52695274
5270static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutable *executable, IrInstructionMemset *instruction) {5275static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutableGen *executable, IrInstGenMemset *instruction) {
5271 LLVMValueRef dest_ptr = ir_llvm_value(g, instruction->dest_ptr);5276 LLVMValueRef dest_ptr = ir_llvm_value(g, instruction->dest_ptr);
5272 LLVMValueRef len_val = ir_llvm_value(g, instruction->count);5277 LLVMValueRef len_val = ir_llvm_value(g, instruction->count);
52735278
...@@ -5279,7 +5284,7 @@ static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutable *executable, IrIns...@@ -5279,7 +5284,7 @@ static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutable *executable, IrIns
52795284
5280 bool val_is_undef = value_is_all_undef(g, instruction->byte->value);5285 bool val_is_undef = value_is_all_undef(g, instruction->byte->value);
5281 LLVMValueRef fill_char;5286 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)) {
5283 fill_char = LLVMConstInt(LLVMInt8Type(), 0xaa, false);5288 fill_char = LLVMConstInt(LLVMInt8Type(), 0xaa, false);
5284 } else {5289 } else {
5285 fill_char = ir_llvm_value(g, instruction->byte);5290 fill_char = ir_llvm_value(g, instruction->byte);
...@@ -5293,7 +5298,7 @@ static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutable *executable, IrIns...@@ -5293,7 +5298,7 @@ static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutable *executable, IrIns
5293 return nullptr;5298 return nullptr;
5294}5299}
52955300
5296static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutable *executable, IrInstructionMemcpy *instruction) {5301static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutableGen *executable, IrInstGenMemcpy *instruction) {
5297 LLVMValueRef dest_ptr = ir_llvm_value(g, instruction->dest_ptr);5302 LLVMValueRef dest_ptr = ir_llvm_value(g, instruction->dest_ptr);
5298 LLVMValueRef src_ptr = ir_llvm_value(g, instruction->src_ptr);5303 LLVMValueRef src_ptr = ir_llvm_value(g, instruction->src_ptr);
5299 LLVMValueRef len_val = ir_llvm_value(g, instruction->count);5304 LLVMValueRef len_val = ir_llvm_value(g, instruction->count);
...@@ -5315,7 +5320,7 @@ static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutable *executable, IrIns...@@ -5315,7 +5320,7 @@ static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutable *executable, IrIns
5315 return nullptr;5320 return nullptr;
5316}5321}
53175322
5318static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInstructionSliceGen *instruction) {5323static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutableGen *executable, IrInstGenSlice *instruction) {
5319 LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->ptr);5324 LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->ptr);
5320 ZigType *array_ptr_type = instruction->ptr->value->type;5325 ZigType *array_ptr_type = instruction->ptr->value->type;
5321 assert(array_ptr_type->id == ZigTypeIdPointer);5326 assert(array_ptr_type->id == ZigTypeIdPointer);
...@@ -5477,13 +5482,13 @@ static LLVMValueRef get_trap_fn_val(CodeGen *g) {...@@ -5477,13 +5482,13 @@ static LLVMValueRef get_trap_fn_val(CodeGen *g) {
5477}5482}
54785483
54795484
5480static LLVMValueRef ir_render_breakpoint(CodeGen *g, IrExecutable *executable, IrInstructionBreakpoint *instruction) {5485static LLVMValueRef ir_render_breakpoint(CodeGen *g, IrExecutableGen *executable, IrInstGenBreakpoint *instruction) {
5481 LLVMBuildCall(g->builder, get_trap_fn_val(g), nullptr, 0, "");5486 LLVMBuildCall(g->builder, get_trap_fn_val(g), nullptr, 0, "");
5482 return nullptr;5487 return nullptr;
5483}5488}
54845489
5485static LLVMValueRef ir_render_return_address(CodeGen *g, IrExecutable *executable,5490static LLVMValueRef ir_render_return_address(CodeGen *g, IrExecutableGen *executable,
5486 IrInstructionReturnAddress *instruction)5491 IrInstGenReturnAddress *instruction)
5487{5492{
5488 LLVMValueRef zero = LLVMConstNull(g->builtin_types.entry_i32->llvm_type);5493 LLVMValueRef zero = LLVMConstNull(g->builtin_types.entry_i32->llvm_type);
5489 LLVMValueRef ptr_val = LLVMBuildCall(g->builder, get_return_address_fn_val(g), &zero, 1, "");5494 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) {...@@ -5504,19 +5509,19 @@ static LLVMValueRef get_frame_address_fn_val(CodeGen *g) {
5504 return g->frame_address_fn_val;5509 return g->frame_address_fn_val;
5505}5510}
55065511
5507static LLVMValueRef ir_render_frame_address(CodeGen *g, IrExecutable *executable,5512static LLVMValueRef ir_render_frame_address(CodeGen *g, IrExecutableGen *executable,
5508 IrInstructionFrameAddress *instruction)5513 IrInstGenFrameAddress *instruction)
5509{5514{
5510 LLVMValueRef zero = LLVMConstNull(g->builtin_types.entry_i32->llvm_type);5515 LLVMValueRef zero = LLVMConstNull(g->builtin_types.entry_i32->llvm_type);
5511 LLVMValueRef ptr_val = LLVMBuildCall(g->builder, get_frame_address_fn_val(g), &zero, 1, "");5516 LLVMValueRef ptr_val = LLVMBuildCall(g->builder, get_frame_address_fn_val(g), &zero, 1, "");
5512 return LLVMBuildPtrToInt(g->builder, ptr_val, g->builtin_types.entry_usize->llvm_type, "");5517 return LLVMBuildPtrToInt(g->builder, ptr_val, g->builtin_types.entry_usize->llvm_type, "");
5513}5518}
55145519
5515static LLVMValueRef ir_render_handle(CodeGen *g, IrExecutable *executable, IrInstructionFrameHandle *instruction) {5520static LLVMValueRef ir_render_handle(CodeGen *g, IrExecutableGen *executable, IrInstGenFrameHandle *instruction) {
5516 return g->cur_frame_ptr;5521 return g->cur_frame_ptr;
5517}5522}
55185523
5519static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstructionOverflowOp *instruction) {5524static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstGenOverflowOp *instruction) {
5520 ZigType *int_type = instruction->result_ptr_type;5525 ZigType *int_type = instruction->result_ptr_type;
5521 assert(int_type->id == ZigTypeIdInt);5526 assert(int_type->id == ZigTypeIdInt);
55225527
...@@ -5541,7 +5546,7 @@ static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstructionOverflowOp...@@ -5541,7 +5546,7 @@ static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstructionOverflowOp
5541 return overflow_bit;5546 return overflow_bit;
5542}5547}
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) {
5545 AddSubMul add_sub_mul;5550 AddSubMul add_sub_mul;
5546 switch (instruction->op) {5551 switch (instruction->op) {
5547 case IrOverflowOpAdd:5552 case IrOverflowOpAdd:
...@@ -5579,7 +5584,7 @@ static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutable *executable,...@@ -5579,7 +5584,7 @@ static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutable *executable,
5579 return overflow_bit;5584 return overflow_bit;
5580}5585}
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) {
5583 ZigType *err_union_type = instruction->err_union->value->type;5588 ZigType *err_union_type = instruction->err_union->value->type;
5584 ZigType *payload_type = err_union_type->data.error_union.payload_type;5589 ZigType *payload_type = err_union_type->data.error_union.payload_type;
5585 LLVMValueRef err_union_handle = ir_llvm_value(g, instruction->err_union);5590 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...@@ -5596,8 +5601,8 @@ static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrI
5596 return LLVMBuildICmp(g->builder, LLVMIntNE, err_val, zero, "");5601 return LLVMBuildICmp(g->builder, LLVMIntNE, err_val, zero, "");
5597}5602}
55985603
5599static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executable,5604static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutableGen *executable,
5600 IrInstructionUnwrapErrCode *instruction)5605 IrInstGenUnwrapErrCode *instruction)
5601{5606{
5602 if (instruction->base.value->special != ConstValSpecialRuntime)5607 if (instruction->base.value->special != ConstValSpecialRuntime)
5603 return nullptr;5608 return nullptr;
...@@ -5616,8 +5621,8 @@ static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executab...@@ -5616,8 +5621,8 @@ static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executab
5616 }5621 }
5617}5622}
56185623
5619static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *executable,5624static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutableGen *executable,
5620 IrInstructionUnwrapErrPayload *instruction)5625 IrInstGenUnwrapErrPayload *instruction)
5621{5626{
5622 Error err;5627 Error err;
56235628
...@@ -5660,7 +5665,7 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *execu...@@ -5660,7 +5665,7 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *execu
5660 LLVMBuildCondBr(g->builder, cond_val, ok_block, err_block);5665 LLVMBuildCondBr(g->builder, cond_val, ok_block, err_block);
56615666
5662 LLVMPositionBuilderAtEnd(g->builder, err_block);5667 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
5665 LLVMPositionBuilderAtEnd(g->builder, ok_block);5670 LLVMPositionBuilderAtEnd(g->builder, ok_block);
5666 }5671 }
...@@ -5677,7 +5682,7 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *execu...@@ -5677,7 +5682,7 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *execu
5677 }5682 }
5678}5683}
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) {
5681 ZigType *wanted_type = instruction->base.value->type;5686 ZigType *wanted_type = instruction->base.value->type;
56825687
5683 assert(wanted_type->id == ZigTypeIdOptional);5688 assert(wanted_type->id == ZigTypeIdOptional);
...@@ -5713,7 +5718,7 @@ static LLVMValueRef ir_render_optional_wrap(CodeGen *g, IrExecutable *executable...@@ -5713,7 +5718,7 @@ static LLVMValueRef ir_render_optional_wrap(CodeGen *g, IrExecutable *executable
5713 return result_loc;5718 return result_loc;
5714}5719}
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) {
5717 ZigType *wanted_type = instruction->base.value->type;5722 ZigType *wanted_type = instruction->base.value->type;
57185723
5719 assert(wanted_type->id == ZigTypeIdErrorUnion);5724 assert(wanted_type->id == ZigTypeIdErrorUnion);
...@@ -5733,7 +5738,7 @@ static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutable *executable...@@ -5733,7 +5738,7 @@ static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutable *executable
5733 return result_loc;5738 return result_loc;
5734}5739}
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) {
5737 ZigType *wanted_type = instruction->base.value->type;5742 ZigType *wanted_type = instruction->base.value->type;
57385743
5739 assert(wanted_type->id == ZigTypeIdErrorUnion);5744 assert(wanted_type->id == ZigTypeIdErrorUnion);
...@@ -5764,7 +5769,7 @@ static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutable *executa...@@ -5764,7 +5769,7 @@ static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutable *executa
5764 return result_loc;5769 return result_loc;
5765}5770}
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) {
5768 ZigType *union_type = instruction->value->value->type;5773 ZigType *union_type = instruction->value->value->type;
57695774
5770 ZigType *tag_type = union_type->data.unionation.tag_type;5775 ZigType *tag_type = union_type->data.unionation.tag_type;
...@@ -5782,15 +5787,15 @@ static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutable *executable, Ir...@@ -5782,15 +5787,15 @@ static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutable *executable, Ir
5782 return get_handle_value(g, tag_field_ptr, tag_type, ptr_type);5787 return get_handle_value(g, tag_field_ptr, tag_type, ptr_type);
5783}5788}
57845789
5785static LLVMValueRef ir_render_panic(CodeGen *g, IrExecutable *executable, IrInstructionPanic *instruction) {5790static LLVMValueRef ir_render_panic(CodeGen *g, IrExecutableGen *executable, IrInstGenPanic *instruction) {
5786 bool is_llvm_alloca;5791 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);
5788 gen_panic(g, ir_llvm_value(g, instruction->msg), err_ret_trace_val, is_llvm_alloca);5793 gen_panic(g, ir_llvm_value(g, instruction->msg), err_ret_trace_val, is_llvm_alloca);
5789 return nullptr;5794 return nullptr;
5790}5795}
57915796
5792static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutable *executable,5797static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutableGen *executable,
5793 IrInstructionAtomicRmw *instruction)5798 IrInstGenAtomicRmw *instruction)
5794{5799{
5795 bool is_signed;5800 bool is_signed;
5796 ZigType *operand_type = instruction->operand->value->type;5801 ZigType *operand_type = instruction->operand->value->type;
...@@ -5800,8 +5805,8 @@ static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutable *executable,...@@ -5800,8 +5805,8 @@ static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutable *executable,
5800 } else {5805 } else {
5801 is_signed = false;5806 is_signed = false;
5802 }5807 }
5803 enum ZigLLVM_AtomicRMWBinOp op = to_ZigLLVMAtomicRMWBinOp(instruction->resolved_op, is_signed, is_float);5808 enum ZigLLVM_AtomicRMWBinOp op = to_ZigLLVMAtomicRMWBinOp(instruction->op, is_signed, is_float);
5804 LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->resolved_ordering);5809 LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->ordering);
5805 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);5810 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
5806 LLVMValueRef operand = ir_llvm_value(g, instruction->operand);5811 LLVMValueRef operand = ir_llvm_value(g, instruction->operand);
58075812
...@@ -5818,20 +5823,20 @@ static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutable *executable,...@@ -5818,20 +5823,20 @@ static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutable *executable,
5818 return LLVMBuildIntToPtr(g->builder, uncasted_result, get_llvm_type(g, operand_type), "");5823 return LLVMBuildIntToPtr(g->builder, uncasted_result, get_llvm_type(g, operand_type), "");
5819}5824}
58205825
5821static LLVMValueRef ir_render_atomic_load(CodeGen *g, IrExecutable *executable,5826static LLVMValueRef ir_render_atomic_load(CodeGen *g, IrExecutableGen *executable,
5822 IrInstructionAtomicLoad *instruction)5827 IrInstGenAtomicLoad *instruction)
5823{5828{
5824 LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->resolved_ordering);5829 LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->ordering);
5825 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);5830 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
5826 LLVMValueRef load_inst = gen_load(g, ptr, instruction->ptr->value->type, "");5831 LLVMValueRef load_inst = gen_load(g, ptr, instruction->ptr->value->type, "");
5827 LLVMSetOrdering(load_inst, ordering);5832 LLVMSetOrdering(load_inst, ordering);
5828 return load_inst;5833 return load_inst;
5829}5834}
58305835
5831static LLVMValueRef ir_render_atomic_store(CodeGen *g, IrExecutable *executable,5836static LLVMValueRef ir_render_atomic_store(CodeGen *g, IrExecutableGen *executable,
5832 IrInstructionAtomicStore *instruction)5837 IrInstGenAtomicStore *instruction)
5833{5838{
5834 LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->resolved_ordering);5839 LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->ordering);
5835 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);5840 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
5836 LLVMValueRef value = ir_llvm_value(g, instruction->value);5841 LLVMValueRef value = ir_llvm_value(g, instruction->value);
5837 LLVMValueRef store_inst = gen_store(g, value, ptr, instruction->ptr->value->type);5842 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,...@@ -5839,13 +5844,13 @@ static LLVMValueRef ir_render_atomic_store(CodeGen *g, IrExecutable *executable,
5839 return nullptr;5844 return nullptr;
5840}5845}
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) {
5843 LLVMValueRef operand = ir_llvm_value(g, instruction->operand);5848 LLVMValueRef operand = ir_llvm_value(g, instruction->operand);
5844 LLVMValueRef fn_val = get_float_fn(g, instruction->base.value->type, ZigLLVMFnIdFloatOp, instruction->fn_id);5849 LLVMValueRef fn_val = get_float_fn(g, instruction->base.value->type, ZigLLVMFnIdFloatOp, instruction->fn_id);
5845 return LLVMBuildCall(g->builder, fn_val, &operand, 1, "");5850 return LLVMBuildCall(g->builder, fn_val, &operand, 1, "");
5846}5851}
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) {
5849 LLVMValueRef op1 = ir_llvm_value(g, instruction->op1);5854 LLVMValueRef op1 = ir_llvm_value(g, instruction->op1);
5850 LLVMValueRef op2 = ir_llvm_value(g, instruction->op2);5855 LLVMValueRef op2 = ir_llvm_value(g, instruction->op2);
5851 LLVMValueRef op3 = ir_llvm_value(g, instruction->op3);5856 LLVMValueRef op3 = ir_llvm_value(g, instruction->op3);
...@@ -5860,7 +5865,7 @@ static LLVMValueRef ir_render_mul_add(CodeGen *g, IrExecutable *executable, IrIn...@@ -5860,7 +5865,7 @@ static LLVMValueRef ir_render_mul_add(CodeGen *g, IrExecutable *executable, IrIn
5860 return LLVMBuildCall(g->builder, fn_val, args, 3, "");5865 return LLVMBuildCall(g->builder, fn_val, args, 3, "");
5861}5866}
58625867
5863static LLVMValueRef ir_render_bswap(CodeGen *g, IrExecutable *executable, IrInstructionBswap *instruction) {5868static LLVMValueRef ir_render_bswap(CodeGen *g, IrExecutableGen *executable, IrInstGenBswap *instruction) {
5864 LLVMValueRef op = ir_llvm_value(g, instruction->op);5869 LLVMValueRef op = ir_llvm_value(g, instruction->op);
5865 ZigType *expr_type = instruction->base.value->type;5870 ZigType *expr_type = instruction->base.value->type;
5866 bool is_vector = expr_type->id == ZigTypeIdVector;5871 bool is_vector = expr_type->id == ZigTypeIdVector;
...@@ -5894,7 +5899,7 @@ static LLVMValueRef ir_render_bswap(CodeGen *g, IrExecutable *executable, IrInst...@@ -5894,7 +5899,7 @@ static LLVMValueRef ir_render_bswap(CodeGen *g, IrExecutable *executable, IrInst
5894 return LLVMBuildTrunc(g->builder, shifted, get_llvm_type(g, expr_type), "");5899 return LLVMBuildTrunc(g->builder, shifted, get_llvm_type(g, expr_type), "");
5895}5900}
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) {
5898 LLVMValueRef op = ir_llvm_value(g, instruction->op);5903 LLVMValueRef op = ir_llvm_value(g, instruction->op);
5899 ZigType *int_type = instruction->base.value->type;5904 ZigType *int_type = instruction->base.value->type;
5900 assert(int_type->id == ZigTypeIdInt);5905 assert(int_type->id == ZigTypeIdInt);
...@@ -5902,8 +5907,8 @@ static LLVMValueRef ir_render_bit_reverse(CodeGen *g, IrExecutable *executable,...@@ -5902,8 +5907,8 @@ static LLVMValueRef ir_render_bit_reverse(CodeGen *g, IrExecutable *executable,
5902 return LLVMBuildCall(g->builder, fn_val, &op, 1, "");5907 return LLVMBuildCall(g->builder, fn_val, &op, 1, "");
5903}5908}
59045909
5905static LLVMValueRef ir_render_vector_to_array(CodeGen *g, IrExecutable *executable,5910static LLVMValueRef ir_render_vector_to_array(CodeGen *g, IrExecutableGen *executable,
5906 IrInstructionVectorToArray *instruction)5911 IrInstGenVectorToArray *instruction)
5907{5912{
5908 ZigType *array_type = instruction->base.value->type;5913 ZigType *array_type = instruction->base.value->type;
5909 assert(array_type->id == ZigTypeIdArray);5914 assert(array_type->id == ZigTypeIdArray);
...@@ -5936,8 +5941,8 @@ static LLVMValueRef ir_render_vector_to_array(CodeGen *g, IrExecutable *executab...@@ -5936,8 +5941,8 @@ static LLVMValueRef ir_render_vector_to_array(CodeGen *g, IrExecutable *executab
5936 return result_loc;5941 return result_loc;
5937}5942}
59385943
5939static LLVMValueRef ir_render_array_to_vector(CodeGen *g, IrExecutable *executable,5944static LLVMValueRef ir_render_array_to_vector(CodeGen *g, IrExecutableGen *executable,
5940 IrInstructionArrayToVector *instruction)5945 IrInstGenArrayToVector *instruction)
5941{5946{
5942 ZigType *vector_type = instruction->base.value->type;5947 ZigType *vector_type = instruction->base.value->type;
5943 assert(vector_type->id == ZigTypeIdVector);5948 assert(vector_type->id == ZigTypeIdVector);
...@@ -5973,8 +5978,8 @@ static LLVMValueRef ir_render_array_to_vector(CodeGen *g, IrExecutable *executab...@@ -5973,8 +5978,8 @@ static LLVMValueRef ir_render_array_to_vector(CodeGen *g, IrExecutable *executab
5973 }5978 }
5974}5979}
59755980
5976static LLVMValueRef ir_render_assert_zero(CodeGen *g, IrExecutable *executable,5981static LLVMValueRef ir_render_assert_zero(CodeGen *g, IrExecutableGen *executable,
5977 IrInstructionAssertZero *instruction)5982 IrInstGenAssertZero *instruction)
5978{5983{
5979 LLVMValueRef target = ir_llvm_value(g, instruction->target);5984 LLVMValueRef target = ir_llvm_value(g, instruction->target);
5980 ZigType *int_type = instruction->target->value->type;5985 ZigType *int_type = instruction->target->value->type;
...@@ -5984,8 +5989,8 @@ static LLVMValueRef ir_render_assert_zero(CodeGen *g, IrExecutable *executable,...@@ -5984,8 +5989,8 @@ static LLVMValueRef ir_render_assert_zero(CodeGen *g, IrExecutable *executable,
5984 return nullptr;5989 return nullptr;
5985}5990}
59865991
5987static LLVMValueRef ir_render_assert_non_null(CodeGen *g, IrExecutable *executable,5992static LLVMValueRef ir_render_assert_non_null(CodeGen *g, IrExecutableGen *executable,
5988 IrInstructionAssertNonNull *instruction)5993 IrInstGenAssertNonNull *instruction)
5989{5994{
5990 LLVMValueRef target = ir_llvm_value(g, instruction->target);5995 LLVMValueRef target = ir_llvm_value(g, instruction->target);
5991 ZigType *target_type = instruction->target->value->type;5996 ZigType *target_type = instruction->target->value->type;
...@@ -6009,8 +6014,8 @@ static LLVMValueRef ir_render_assert_non_null(CodeGen *g, IrExecutable *executab...@@ -6009,8 +6014,8 @@ static LLVMValueRef ir_render_assert_non_null(CodeGen *g, IrExecutable *executab
6009 return nullptr;6014 return nullptr;
6010}6015}
60116016
6012static LLVMValueRef ir_render_suspend_begin(CodeGen *g, IrExecutable *executable,6017static LLVMValueRef ir_render_suspend_begin(CodeGen *g, IrExecutableGen *executable,
6013 IrInstructionSuspendBegin *instruction)6018 IrInstGenSuspendBegin *instruction)
6014{6019{
6015 if (fn_is_async(g->cur_fn)) {6020 if (fn_is_async(g->cur_fn)) {
6016 instruction->resume_bb = gen_suspend_begin(g, "SuspendResume");6021 instruction->resume_bb = gen_suspend_begin(g, "SuspendResume");
...@@ -6018,8 +6023,8 @@ static LLVMValueRef ir_render_suspend_begin(CodeGen *g, IrExecutable *executable...@@ -6018,8 +6023,8 @@ static LLVMValueRef ir_render_suspend_begin(CodeGen *g, IrExecutable *executable
6018 return nullptr;6023 return nullptr;
6019}6024}
60206025
6021static LLVMValueRef ir_render_suspend_finish(CodeGen *g, IrExecutable *executable,6026static LLVMValueRef ir_render_suspend_finish(CodeGen *g, IrExecutableGen *executable,
6022 IrInstructionSuspendFinish *instruction)6027 IrInstGenSuspendFinish *instruction)
6023{6028{
6024 LLVMBuildRetVoid(g->builder);6029 LLVMBuildRetVoid(g->builder);
60256030
...@@ -6027,11 +6032,11 @@ static LLVMValueRef ir_render_suspend_finish(CodeGen *g, IrExecutable *executabl...@@ -6027,11 +6032,11 @@ static LLVMValueRef ir_render_suspend_finish(CodeGen *g, IrExecutable *executabl
6027 if (ir_want_runtime_safety(g, &instruction->base)) {6032 if (ir_want_runtime_safety(g, &instruction->base)) {
6028 LLVMBuildStore(g->builder, g->cur_bad_not_suspended_index, g->cur_async_resume_index_ptr);6033 LLVMBuildStore(g->builder, g->cur_bad_not_suspended_index, g->cur_async_resume_index_ptr);
6029 }6034 }
6030 render_async_var_decls(g, instruction->base.scope);6035 render_async_var_decls(g, instruction->base.base.scope);
6031 return nullptr;6036 return nullptr;
6032}6037}
60336038
6034static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstruction *source_instr,6039static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstGen *source_instr,
6035 LLVMValueRef target_frame_ptr, ZigType *result_type, ZigType *ptr_result_type,6040 LLVMValueRef target_frame_ptr, ZigType *result_type, ZigType *ptr_result_type,
6036 LLVMValueRef result_loc, bool non_async)6041 LLVMValueRef result_loc, bool non_async)
6037{6042{
...@@ -6057,7 +6062,7 @@ static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstruction *source_ins...@@ -6057,7 +6062,7 @@ static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstruction *source_ins
6057 frame_index_trace_arg(g, result_type), "");6062 frame_index_trace_arg(g, result_type), "");
6058 LLVMValueRef src_trace_ptr = LLVMBuildLoad(g->builder, their_trace_ptr_ptr, "");6063 LLVMValueRef src_trace_ptr = LLVMBuildLoad(g->builder, their_trace_ptr_ptr, "");
6059 bool is_llvm_alloca;6064 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);
6061 LLVMValueRef args[] = { dest_trace_ptr, src_trace_ptr };6066 LLVMValueRef args[] = { dest_trace_ptr, src_trace_ptr };
6062 ZigLLVMBuildCall(g->builder, get_merge_err_ret_traces_fn_val(g), args, 2,6067 ZigLLVMBuildCall(g->builder, get_merge_err_ret_traces_fn_val(g), args, 2,
6063 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");6068 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");
...@@ -6070,7 +6075,7 @@ static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstruction *source_ins...@@ -6070,7 +6075,7 @@ static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstruction *source_ins
6070 }6075 }
6071}6076}
60726077
6073static LLVMValueRef ir_render_await(CodeGen *g, IrExecutable *executable, IrInstructionAwaitGen *instruction) {6078static LLVMValueRef ir_render_await(CodeGen *g, IrExecutableGen *executable, IrInstGenAwait *instruction) {
6074 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;6079 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;
6075 LLVMValueRef zero = LLVMConstNull(usize_type_ref);6080 LLVMValueRef zero = LLVMConstNull(usize_type_ref);
6076 LLVMValueRef target_frame_ptr = ir_llvm_value(g, instruction->frame);6081 LLVMValueRef target_frame_ptr = ir_llvm_value(g, instruction->frame);
...@@ -6107,7 +6112,7 @@ static LLVMValueRef ir_render_await(CodeGen *g, IrExecutable *executable, IrInst...@@ -6107,7 +6112,7 @@ static LLVMValueRef ir_render_await(CodeGen *g, IrExecutable *executable, IrInst
6107 // supply the error return trace pointer6112 // supply the error return trace pointer
6108 if (codegen_fn_has_err_ret_tracing_arg(g, result_type)) {6113 if (codegen_fn_has_err_ret_tracing_arg(g, result_type)) {
6109 bool is_llvm_alloca;6114 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);
6111 assert(my_err_ret_trace_val != nullptr);6116 assert(my_err_ret_trace_val != nullptr);
6112 LLVMValueRef err_ret_trace_ptr_ptr = LLVMBuildStructGEP(g->builder, target_frame_ptr,6117 LLVMValueRef err_ret_trace_ptr_ptr = LLVMBuildStructGEP(g->builder, target_frame_ptr,
6113 frame_index_trace_arg(g, result_type) + 1, "");6118 frame_index_trace_arg(g, result_type) + 1, "");
...@@ -6155,7 +6160,7 @@ static LLVMValueRef ir_render_await(CodeGen *g, IrExecutable *executable, IrInst...@@ -6155,7 +6160,7 @@ static LLVMValueRef ir_render_await(CodeGen *g, IrExecutable *executable, IrInst
6155 return nullptr;6160 return nullptr;
6156}6161}
61576162
6158static LLVMValueRef ir_render_resume(CodeGen *g, IrExecutable *executable, IrInstructionResume *instruction) {6163static LLVMValueRef ir_render_resume(CodeGen *g, IrExecutableGen *executable, IrInstGenResume *instruction) {
6159 LLVMValueRef frame = ir_llvm_value(g, instruction->frame);6164 LLVMValueRef frame = ir_llvm_value(g, instruction->frame);
6160 ZigType *frame_type = instruction->frame->value->type;6165 ZigType *frame_type = instruction->frame->value->type;
6161 assert(frame_type->id == ZigTypeIdAnyFrame);6166 assert(frame_type->id == ZigTypeIdAnyFrame);
...@@ -6164,15 +6169,15 @@ static LLVMValueRef ir_render_resume(CodeGen *g, IrExecutable *executable, IrIns...@@ -6164,15 +6169,15 @@ static LLVMValueRef ir_render_resume(CodeGen *g, IrExecutable *executable, IrIns
6164 return nullptr;6169 return nullptr;
6165}6170}
61666171
6167static LLVMValueRef ir_render_frame_size(CodeGen *g, IrExecutable *executable,6172static LLVMValueRef ir_render_frame_size(CodeGen *g, IrExecutableGen *executable,
6168 IrInstructionFrameSizeGen *instruction)6173 IrInstGenFrameSize *instruction)
6169{6174{
6170 LLVMValueRef fn_val = ir_llvm_value(g, instruction->fn);6175 LLVMValueRef fn_val = ir_llvm_value(g, instruction->fn);
6171 return gen_frame_size(g, fn_val);6176 return gen_frame_size(g, fn_val);
6172}6177}
61736178
6174static LLVMValueRef ir_render_spill_begin(CodeGen *g, IrExecutable *executable,6179static LLVMValueRef ir_render_spill_begin(CodeGen *g, IrExecutableGen *executable,
6175 IrInstructionSpillBegin *instruction)6180 IrInstGenSpillBegin *instruction)
6176{6181{
6177 if (!fn_is_async(g->cur_fn))6182 if (!fn_is_async(g->cur_fn))
6178 return nullptr;6183 return nullptr;
...@@ -6191,7 +6196,7 @@ static LLVMValueRef ir_render_spill_begin(CodeGen *g, IrExecutable *executable,...@@ -6191,7 +6196,7 @@ static LLVMValueRef ir_render_spill_begin(CodeGen *g, IrExecutable *executable,
6191 zig_unreachable();6196 zig_unreachable();
6192}6197}
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) {
6195 if (!fn_is_async(g->cur_fn))6200 if (!fn_is_async(g->cur_fn))
6196 return ir_llvm_value(g, instruction->begin->operand);6201 return ir_llvm_value(g, instruction->begin->operand);
61976202
...@@ -6207,17 +6212,17 @@ static LLVMValueRef ir_render_spill_end(CodeGen *g, IrExecutable *executable, Ir...@@ -6207,17 +6212,17 @@ static LLVMValueRef ir_render_spill_end(CodeGen *g, IrExecutable *executable, Ir
6207 zig_unreachable();6212 zig_unreachable();
6208}6213}
62096214
6210static LLVMValueRef ir_render_vector_extract_elem(CodeGen *g, IrExecutable *executable,6215static LLVMValueRef ir_render_vector_extract_elem(CodeGen *g, IrExecutableGen *executable,
6211 IrInstructionVectorExtractElem *instruction)6216 IrInstGenVectorExtractElem *instruction)
6212{6217{
6213 LLVMValueRef vector = ir_llvm_value(g, instruction->vector);6218 LLVMValueRef vector = ir_llvm_value(g, instruction->vector);
6214 LLVMValueRef index = ir_llvm_value(g, instruction->index);6219 LLVMValueRef index = ir_llvm_value(g, instruction->index);
6215 return LLVMBuildExtractElement(g->builder, vector, index, "");6220 return LLVMBuildExtractElement(g->builder, vector, index, "");
6216}6221}
62176222
6218static void set_debug_location(CodeGen *g, IrInstruction *instruction) {6223static void set_debug_location(CodeGen *g, IrInstGen *instruction) {
6219 AstNode *source_node = instruction->source_node;6224 AstNode *source_node = instruction->base.source_node;
6220 Scope *scope = instruction->scope;6225 Scope *scope = instruction->base.scope;
62216226
6222 assert(source_node);6227 assert(source_node);
6223 assert(scope);6228 assert(scope);
...@@ -6226,263 +6231,183 @@ static void set_debug_location(CodeGen *g, IrInstruction *instruction) {...@@ -6226,263 +6231,183 @@ static void set_debug_location(CodeGen *g, IrInstruction *instruction) {
6226 (int)source_node->column + 1, get_di_scope(g, scope));6231 (int)source_node->column + 1, get_di_scope(g, scope));
6227}6232}
62286233
6229static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable, IrInstruction *instruction) {6234static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutableGen *executable, IrInstGen *instruction) {
6230 switch (instruction->id) {6235 switch (instruction->id) {
6231 case IrInstructionIdInvalid:6236 case IrInstGenIdInvalid:
6232 case IrInstructionIdConst:6237 case IrInstGenIdConst:
6233 case IrInstructionIdTypeOf:6238 case IrInstGenIdAlloca:
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:
6318 zig_unreachable();6239 zig_unreachable();
63196240
6320 case IrInstructionIdDeclVarGen:6241 case IrInstGenIdDeclVar:
6321 return ir_render_decl_var(g, executable, (IrInstructionDeclVarGen *)instruction);6242 return ir_render_decl_var(g, executable, (IrInstGenDeclVar *)instruction);
6322 case IrInstructionIdReturn:6243 case IrInstGenIdReturn:
6323 return ir_render_return(g, executable, (IrInstructionReturn *)instruction);6244 return ir_render_return(g, executable, (IrInstGenReturn *)instruction);
6324 case IrInstructionIdBinOp:6245 case IrInstGenIdBinOp:
6325 return ir_render_bin_op(g, executable, (IrInstructionBinOp *)instruction);6246 return ir_render_bin_op(g, executable, (IrInstGenBinOp *)instruction);
6326 case IrInstructionIdCast:6247 case IrInstGenIdCast:
6327 return ir_render_cast(g, executable, (IrInstructionCast *)instruction);6248 return ir_render_cast(g, executable, (IrInstGenCast *)instruction);
6328 case IrInstructionIdUnreachable:6249 case IrInstGenIdUnreachable:
6329 return ir_render_unreachable(g, executable, (IrInstructionUnreachable *)instruction);6250 return ir_render_unreachable(g, executable, (IrInstGenUnreachable *)instruction);
6330 case IrInstructionIdCondBr:6251 case IrInstGenIdCondBr:
6331 return ir_render_cond_br(g, executable, (IrInstructionCondBr *)instruction);6252 return ir_render_cond_br(g, executable, (IrInstGenCondBr *)instruction);
6332 case IrInstructionIdBr:6253 case IrInstGenIdBr:
6333 return ir_render_br(g, executable, (IrInstructionBr *)instruction);6254 return ir_render_br(g, executable, (IrInstGenBr *)instruction);
6334 case IrInstructionIdUnOp:6255 case IrInstGenIdBinaryNot:
6335 return ir_render_un_op(g, executable, (IrInstructionUnOp *)instruction);6256 return ir_render_binary_not(g, executable, (IrInstGenBinaryNot *)instruction);
6336 case IrInstructionIdLoadPtrGen:6257 case IrInstGenIdNegation:
6337 return ir_render_load_ptr(g, executable, (IrInstructionLoadPtrGen *)instruction);6258 return ir_render_negation(g, executable, (IrInstGenNegation *)instruction);
6338 case IrInstructionIdStorePtr:6259 case IrInstGenIdNegationWrapping:
6339 return ir_render_store_ptr(g, executable, (IrInstructionStorePtr *)instruction);6260 return ir_render_negation_wrapping(g, executable, (IrInstGenNegationWrapping *)instruction);
6340 case IrInstructionIdVectorStoreElem:6261 case IrInstGenIdLoadPtr:
6341 return ir_render_vector_store_elem(g, executable, (IrInstructionVectorStoreElem *)instruction);6262 return ir_render_load_ptr(g, executable, (IrInstGenLoadPtr *)instruction);
6342 case IrInstructionIdVarPtr:6263 case IrInstGenIdStorePtr:
6343 return ir_render_var_ptr(g, executable, (IrInstructionVarPtr *)instruction);6264 return ir_render_store_ptr(g, executable, (IrInstGenStorePtr *)instruction);
6344 case IrInstructionIdReturnPtr:6265 case IrInstGenIdVectorStoreElem:
6345 return ir_render_return_ptr(g, executable, (IrInstructionReturnPtr *)instruction);6266 return ir_render_vector_store_elem(g, executable, (IrInstGenVectorStoreElem *)instruction);
6346 case IrInstructionIdElemPtr:6267 case IrInstGenIdVarPtr:
6347 return ir_render_elem_ptr(g, executable, (IrInstructionElemPtr *)instruction);6268 return ir_render_var_ptr(g, executable, (IrInstGenVarPtr *)instruction);
6348 case IrInstructionIdCallGen:6269 case IrInstGenIdReturnPtr:
6349 return ir_render_call(g, executable, (IrInstructionCallGen *)instruction);6270 return ir_render_return_ptr(g, executable, (IrInstGenReturnPtr *)instruction);
6350 case IrInstructionIdStructFieldPtr:6271 case IrInstGenIdElemPtr:
6351 return ir_render_struct_field_ptr(g, executable, (IrInstructionStructFieldPtr *)instruction);6272 return ir_render_elem_ptr(g, executable, (IrInstGenElemPtr *)instruction);
6352 case IrInstructionIdUnionFieldPtr:6273 case IrInstGenIdCall:
6353 return ir_render_union_field_ptr(g, executable, (IrInstructionUnionFieldPtr *)instruction);6274 return ir_render_call(g, executable, (IrInstGenCall *)instruction);
6354 case IrInstructionIdAsmGen:6275 case IrInstGenIdStructFieldPtr:
6355 return ir_render_asm_gen(g, executable, (IrInstructionAsmGen *)instruction);6276 return ir_render_struct_field_ptr(g, executable, (IrInstGenStructFieldPtr *)instruction);
6356 case IrInstructionIdTestNonNull:6277 case IrInstGenIdUnionFieldPtr:
6357 return ir_render_test_non_null(g, executable, (IrInstructionTestNonNull *)instruction);6278 return ir_render_union_field_ptr(g, executable, (IrInstGenUnionFieldPtr *)instruction);
6358 case IrInstructionIdOptionalUnwrapPtr:6279 case IrInstGenIdAsm:
6359 return ir_render_optional_unwrap_ptr(g, executable, (IrInstructionOptionalUnwrapPtr *)instruction);6280 return ir_render_asm_gen(g, executable, (IrInstGenAsm *)instruction);
6360 case IrInstructionIdClz:6281 case IrInstGenIdTestNonNull:
6361 return ir_render_clz(g, executable, (IrInstructionClz *)instruction);6282 return ir_render_test_non_null(g, executable, (IrInstGenTestNonNull *)instruction);
6362 case IrInstructionIdCtz:6283 case IrInstGenIdOptionalUnwrapPtr:
6363 return ir_render_ctz(g, executable, (IrInstructionCtz *)instruction);6284 return ir_render_optional_unwrap_ptr(g, executable, (IrInstGenOptionalUnwrapPtr *)instruction);
6364 case IrInstructionIdPopCount:6285 case IrInstGenIdClz:
6365 return ir_render_pop_count(g, executable, (IrInstructionPopCount *)instruction);6286 return ir_render_clz(g, executable, (IrInstGenClz *)instruction);
6366 case IrInstructionIdSwitchBr:6287 case IrInstGenIdCtz:
6367 return ir_render_switch_br(g, executable, (IrInstructionSwitchBr *)instruction);6288 return ir_render_ctz(g, executable, (IrInstGenCtz *)instruction);
6368 case IrInstructionIdBswap:6289 case IrInstGenIdPopCount:
6369 return ir_render_bswap(g, executable, (IrInstructionBswap *)instruction);6290 return ir_render_pop_count(g, executable, (IrInstGenPopCount *)instruction);
6370 case IrInstructionIdBitReverse:6291 case IrInstGenIdSwitchBr:
6371 return ir_render_bit_reverse(g, executable, (IrInstructionBitReverse *)instruction);6292 return ir_render_switch_br(g, executable, (IrInstGenSwitchBr *)instruction);
6372 case IrInstructionIdPhi:6293 case IrInstGenIdBswap:
6373 return ir_render_phi(g, executable, (IrInstructionPhi *)instruction);6294 return ir_render_bswap(g, executable, (IrInstGenBswap *)instruction);
6374 case IrInstructionIdRefGen:6295 case IrInstGenIdBitReverse:
6375 return ir_render_ref(g, executable, (IrInstructionRefGen *)instruction);6296 return ir_render_bit_reverse(g, executable, (IrInstGenBitReverse *)instruction);
6376 case IrInstructionIdErrName:6297 case IrInstGenIdPhi:
6377 return ir_render_err_name(g, executable, (IrInstructionErrName *)instruction);6298 return ir_render_phi(g, executable, (IrInstGenPhi *)instruction);
6378 case IrInstructionIdCmpxchgGen:6299 case IrInstGenIdRef:
6379 return ir_render_cmpxchg(g, executable, (IrInstructionCmpxchgGen *)instruction);6300 return ir_render_ref(g, executable, (IrInstGenRef *)instruction);
6380 case IrInstructionIdFence:6301 case IrInstGenIdErrName:
6381 return ir_render_fence(g, executable, (IrInstructionFence *)instruction);6302 return ir_render_err_name(g, executable, (IrInstGenErrName *)instruction);
6382 case IrInstructionIdTruncate:6303 case IrInstGenIdCmpxchg:
6383 return ir_render_truncate(g, executable, (IrInstructionTruncate *)instruction);6304 return ir_render_cmpxchg(g, executable, (IrInstGenCmpxchg *)instruction);
6384 case IrInstructionIdBoolNot:6305 case IrInstGenIdFence:
6385 return ir_render_bool_not(g, executable, (IrInstructionBoolNot *)instruction);6306 return ir_render_fence(g, executable, (IrInstGenFence *)instruction);
6386 case IrInstructionIdMemset:6307 case IrInstGenIdTruncate:
6387 return ir_render_memset(g, executable, (IrInstructionMemset *)instruction);6308 return ir_render_truncate(g, executable, (IrInstGenTruncate *)instruction);
6388 case IrInstructionIdMemcpy:6309 case IrInstGenIdBoolNot:
6389 return ir_render_memcpy(g, executable, (IrInstructionMemcpy *)instruction);6310 return ir_render_bool_not(g, executable, (IrInstGenBoolNot *)instruction);
6390 case IrInstructionIdSliceGen:6311 case IrInstGenIdMemset:
6391 return ir_render_slice(g, executable, (IrInstructionSliceGen *)instruction);6312 return ir_render_memset(g, executable, (IrInstGenMemset *)instruction);
6392 case IrInstructionIdBreakpoint:6313 case IrInstGenIdMemcpy:
6393 return ir_render_breakpoint(g, executable, (IrInstructionBreakpoint *)instruction);6314 return ir_render_memcpy(g, executable, (IrInstGenMemcpy *)instruction);
6394 case IrInstructionIdReturnAddress:6315 case IrInstGenIdSlice:
6395 return ir_render_return_address(g, executable, (IrInstructionReturnAddress *)instruction);6316 return ir_render_slice(g, executable, (IrInstGenSlice *)instruction);
6396 case IrInstructionIdFrameAddress:6317 case IrInstGenIdBreakpoint:
6397 return ir_render_frame_address(g, executable, (IrInstructionFrameAddress *)instruction);6318 return ir_render_breakpoint(g, executable, (IrInstGenBreakpoint *)instruction);
6398 case IrInstructionIdFrameHandle:6319 case IrInstGenIdReturnAddress:
6399 return ir_render_handle(g, executable, (IrInstructionFrameHandle *)instruction);6320 return ir_render_return_address(g, executable, (IrInstGenReturnAddress *)instruction);
6400 case IrInstructionIdOverflowOp:6321 case IrInstGenIdFrameAddress:
6401 return ir_render_overflow_op(g, executable, (IrInstructionOverflowOp *)instruction);6322 return ir_render_frame_address(g, executable, (IrInstGenFrameAddress *)instruction);
6402 case IrInstructionIdTestErrGen:6323 case IrInstGenIdFrameHandle:
6403 return ir_render_test_err(g, executable, (IrInstructionTestErrGen *)instruction);6324 return ir_render_handle(g, executable, (IrInstGenFrameHandle *)instruction);
6404 case IrInstructionIdUnwrapErrCode:6325 case IrInstGenIdOverflowOp:
6405 return ir_render_unwrap_err_code(g, executable, (IrInstructionUnwrapErrCode *)instruction);6326 return ir_render_overflow_op(g, executable, (IrInstGenOverflowOp *)instruction);
6406 case IrInstructionIdUnwrapErrPayload:6327 case IrInstGenIdTestErr:
6407 return ir_render_unwrap_err_payload(g, executable, (IrInstructionUnwrapErrPayload *)instruction);6328 return ir_render_test_err(g, executable, (IrInstGenTestErr *)instruction);
6408 case IrInstructionIdOptionalWrap:6329 case IrInstGenIdUnwrapErrCode:
6409 return ir_render_optional_wrap(g, executable, (IrInstructionOptionalWrap *)instruction);6330 return ir_render_unwrap_err_code(g, executable, (IrInstGenUnwrapErrCode *)instruction);
6410 case IrInstructionIdErrWrapCode:6331 case IrInstGenIdUnwrapErrPayload:
6411 return ir_render_err_wrap_code(g, executable, (IrInstructionErrWrapCode *)instruction);6332 return ir_render_unwrap_err_payload(g, executable, (IrInstGenUnwrapErrPayload *)instruction);
6412 case IrInstructionIdErrWrapPayload:6333 case IrInstGenIdOptionalWrap:
6413 return ir_render_err_wrap_payload(g, executable, (IrInstructionErrWrapPayload *)instruction);6334 return ir_render_optional_wrap(g, executable, (IrInstGenOptionalWrap *)instruction);
6414 case IrInstructionIdUnionTag:6335 case IrInstGenIdErrWrapCode:
6415 return ir_render_union_tag(g, executable, (IrInstructionUnionTag *)instruction);6336 return ir_render_err_wrap_code(g, executable, (IrInstGenErrWrapCode *)instruction);
6416 case IrInstructionIdPtrCastGen:6337 case IrInstGenIdErrWrapPayload:
6417 return ir_render_ptr_cast(g, executable, (IrInstructionPtrCastGen *)instruction);6338 return ir_render_err_wrap_payload(g, executable, (IrInstGenErrWrapPayload *)instruction);
6418 case IrInstructionIdBitCastGen:6339 case IrInstGenIdUnionTag:
6419 return ir_render_bit_cast(g, executable, (IrInstructionBitCastGen *)instruction);6340 return ir_render_union_tag(g, executable, (IrInstGenUnionTag *)instruction);
6420 case IrInstructionIdWidenOrShorten:6341 case IrInstGenIdPtrCast:
6421 return ir_render_widen_or_shorten(g, executable, (IrInstructionWidenOrShorten *)instruction);6342 return ir_render_ptr_cast(g, executable, (IrInstGenPtrCast *)instruction);
6422 case IrInstructionIdPtrToInt:6343 case IrInstGenIdBitCast:
6423 return ir_render_ptr_to_int(g, executable, (IrInstructionPtrToInt *)instruction);6344 return ir_render_bit_cast(g, executable, (IrInstGenBitCast *)instruction);
6424 case IrInstructionIdIntToPtr:6345 case IrInstGenIdWidenOrShorten:
6425 return ir_render_int_to_ptr(g, executable, (IrInstructionIntToPtr *)instruction);6346 return ir_render_widen_or_shorten(g, executable, (IrInstGenWidenOrShorten *)instruction);
6426 case IrInstructionIdIntToEnum:6347 case IrInstGenIdPtrToInt:
6427 return ir_render_int_to_enum(g, executable, (IrInstructionIntToEnum *)instruction);6348 return ir_render_ptr_to_int(g, executable, (IrInstGenPtrToInt *)instruction);
6428 case IrInstructionIdIntToErr:6349 case IrInstGenIdIntToPtr:
6429 return ir_render_int_to_err(g, executable, (IrInstructionIntToErr *)instruction);6350 return ir_render_int_to_ptr(g, executable, (IrInstGenIntToPtr *)instruction);
6430 case IrInstructionIdErrToInt:6351 case IrInstGenIdIntToEnum:
6431 return ir_render_err_to_int(g, executable, (IrInstructionErrToInt *)instruction);6352 return ir_render_int_to_enum(g, executable, (IrInstGenIntToEnum *)instruction);
6432 case IrInstructionIdPanic:6353 case IrInstGenIdIntToErr:
6433 return ir_render_panic(g, executable, (IrInstructionPanic *)instruction);6354 return ir_render_int_to_err(g, executable, (IrInstGenIntToErr *)instruction);
6434 case IrInstructionIdTagName:6355 case IrInstGenIdErrToInt:
6435 return ir_render_enum_tag_name(g, executable, (IrInstructionTagName *)instruction);6356 return ir_render_err_to_int(g, executable, (IrInstGenErrToInt *)instruction);
6436 case IrInstructionIdFieldParentPtr:6357 case IrInstGenIdPanic:
6437 return ir_render_field_parent_ptr(g, executable, (IrInstructionFieldParentPtr *)instruction);6358 return ir_render_panic(g, executable, (IrInstGenPanic *)instruction);
6438 case IrInstructionIdAlignCast:6359 case IrInstGenIdTagName:
6439 return ir_render_align_cast(g, executable, (IrInstructionAlignCast *)instruction);6360 return ir_render_enum_tag_name(g, executable, (IrInstGenTagName *)instruction);
6440 case IrInstructionIdErrorReturnTrace:6361 case IrInstGenIdFieldParentPtr:
6441 return ir_render_error_return_trace(g, executable, (IrInstructionErrorReturnTrace *)instruction);6362 return ir_render_field_parent_ptr(g, executable, (IrInstGenFieldParentPtr *)instruction);
6442 case IrInstructionIdAtomicRmw:6363 case IrInstGenIdAlignCast:
6443 return ir_render_atomic_rmw(g, executable, (IrInstructionAtomicRmw *)instruction);6364 return ir_render_align_cast(g, executable, (IrInstGenAlignCast *)instruction);
6444 case IrInstructionIdAtomicLoad:6365 case IrInstGenIdErrorReturnTrace:
6445 return ir_render_atomic_load(g, executable, (IrInstructionAtomicLoad *)instruction);6366 return ir_render_error_return_trace(g, executable, (IrInstGenErrorReturnTrace *)instruction);
6446 case IrInstructionIdAtomicStore:6367 case IrInstGenIdAtomicRmw:
6447 return ir_render_atomic_store(g, executable, (IrInstructionAtomicStore *)instruction);6368 return ir_render_atomic_rmw(g, executable, (IrInstGenAtomicRmw *)instruction);
6448 case IrInstructionIdSaveErrRetAddr:6369 case IrInstGenIdAtomicLoad:
6449 return ir_render_save_err_ret_addr(g, executable, (IrInstructionSaveErrRetAddr *)instruction);6370 return ir_render_atomic_load(g, executable, (IrInstGenAtomicLoad *)instruction);
6450 case IrInstructionIdFloatOp:6371 case IrInstGenIdAtomicStore:
6451 return ir_render_float_op(g, executable, (IrInstructionFloatOp *)instruction);6372 return ir_render_atomic_store(g, executable, (IrInstGenAtomicStore *)instruction);
6452 case IrInstructionIdMulAdd:6373 case IrInstGenIdSaveErrRetAddr:
6453 return ir_render_mul_add(g, executable, (IrInstructionMulAdd *)instruction);6374 return ir_render_save_err_ret_addr(g, executable, (IrInstGenSaveErrRetAddr *)instruction);
6454 case IrInstructionIdArrayToVector:6375 case IrInstGenIdFloatOp:
6455 return ir_render_array_to_vector(g, executable, (IrInstructionArrayToVector *)instruction);6376 return ir_render_float_op(g, executable, (IrInstGenFloatOp *)instruction);
6456 case IrInstructionIdVectorToArray:6377 case IrInstGenIdMulAdd:
6457 return ir_render_vector_to_array(g, executable, (IrInstructionVectorToArray *)instruction);6378 return ir_render_mul_add(g, executable, (IrInstGenMulAdd *)instruction);
6458 case IrInstructionIdAssertZero:6379 case IrInstGenIdArrayToVector:
6459 return ir_render_assert_zero(g, executable, (IrInstructionAssertZero *)instruction);6380 return ir_render_array_to_vector(g, executable, (IrInstGenArrayToVector *)instruction);
6460 case IrInstructionIdAssertNonNull:6381 case IrInstGenIdVectorToArray:
6461 return ir_render_assert_non_null(g, executable, (IrInstructionAssertNonNull *)instruction);6382 return ir_render_vector_to_array(g, executable, (IrInstGenVectorToArray *)instruction);
6462 case IrInstructionIdResizeSlice:6383 case IrInstGenIdAssertZero:
6463 return ir_render_resize_slice(g, executable, (IrInstructionResizeSlice *)instruction);6384 return ir_render_assert_zero(g, executable, (IrInstGenAssertZero *)instruction);
6464 case IrInstructionIdPtrOfArrayToSlice:6385 case IrInstGenIdAssertNonNull:
6465 return ir_render_ptr_of_array_to_slice(g, executable, (IrInstructionPtrOfArrayToSlice *)instruction);6386 return ir_render_assert_non_null(g, executable, (IrInstGenAssertNonNull *)instruction);
6466 case IrInstructionIdSuspendBegin:6387 case IrInstGenIdResizeSlice:
6467 return ir_render_suspend_begin(g, executable, (IrInstructionSuspendBegin *)instruction);6388 return ir_render_resize_slice(g, executable, (IrInstGenResizeSlice *)instruction);
6468 case IrInstructionIdSuspendFinish:6389 case IrInstGenIdPtrOfArrayToSlice:
6469 return ir_render_suspend_finish(g, executable, (IrInstructionSuspendFinish *)instruction);6390 return ir_render_ptr_of_array_to_slice(g, executable, (IrInstGenPtrOfArrayToSlice *)instruction);
6470 case IrInstructionIdResume:6391 case IrInstGenIdSuspendBegin:
6471 return ir_render_resume(g, executable, (IrInstructionResume *)instruction);6392 return ir_render_suspend_begin(g, executable, (IrInstGenSuspendBegin *)instruction);
6472 case IrInstructionIdFrameSizeGen:6393 case IrInstGenIdSuspendFinish:
6473 return ir_render_frame_size(g, executable, (IrInstructionFrameSizeGen *)instruction);6394 return ir_render_suspend_finish(g, executable, (IrInstGenSuspendFinish *)instruction);
6474 case IrInstructionIdAwaitGen:6395 case IrInstGenIdResume:
6475 return ir_render_await(g, executable, (IrInstructionAwaitGen *)instruction);6396 return ir_render_resume(g, executable, (IrInstGenResume *)instruction);
6476 case IrInstructionIdSpillBegin:6397 case IrInstGenIdFrameSize:
6477 return ir_render_spill_begin(g, executable, (IrInstructionSpillBegin *)instruction);6398 return ir_render_frame_size(g, executable, (IrInstGenFrameSize *)instruction);
6478 case IrInstructionIdSpillEnd:6399 case IrInstGenIdAwait:
6479 return ir_render_spill_end(g, executable, (IrInstructionSpillEnd *)instruction);6400 return ir_render_await(g, executable, (IrInstGenAwait *)instruction);
6480 case IrInstructionIdShuffleVector:6401 case IrInstGenIdSpillBegin:
6481 return ir_render_shuffle_vector(g, executable, (IrInstructionShuffleVector *) instruction);6402 return ir_render_spill_begin(g, executable, (IrInstGenSpillBegin *)instruction);
6482 case IrInstructionIdSplatGen:6403 case IrInstGenIdSpillEnd:
6483 return ir_render_splat(g, executable, (IrInstructionSplatGen *) instruction);6404 return ir_render_spill_end(g, executable, (IrInstGenSpillEnd *)instruction);
6484 case IrInstructionIdVectorExtractElem:6405 case IrInstGenIdShuffleVector:
6485 return ir_render_vector_extract_elem(g, executable, (IrInstructionVectorExtractElem *) instruction);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);
6486 }6411 }
6487 zig_unreachable();6412 zig_unreachable();
6488}6413}
...@@ -6490,21 +6415,21 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,...@@ -6490,21 +6415,21 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
6490static void ir_render(CodeGen *g, ZigFn *fn_entry) {6415static void ir_render(CodeGen *g, ZigFn *fn_entry) {
6491 assert(fn_entry);6416 assert(fn_entry);
64926417
6493 IrExecutable *executable = &fn_entry->analyzed_executable;6418 IrExecutableGen *executable = &fn_entry->analyzed_executable;
6494 assert(executable->basic_block_list.length > 0);6419 assert(executable->basic_block_list.length > 0);
64956420
6496 for (size_t block_i = 0; block_i < executable->basic_block_list.length; block_i += 1) {6421 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);
6498 if (get_scope_typeof(current_block->scope) != nullptr) {6423 if (get_scope_typeof(current_block->scope) != nullptr) {
6499 LLVMBuildBr(g->builder, current_block->llvm_block);6424 LLVMBuildBr(g->builder, current_block->llvm_block);
6500 }6425 }
6501 assert(current_block->llvm_block);6426 assert(current_block->llvm_block);
6502 LLVMPositionBuilderAtEnd(g->builder, current_block->llvm_block);6427 LLVMPositionBuilderAtEnd(g->builder, current_block->llvm_block);
6503 for (size_t instr_i = 0; instr_i < current_block->instruction_list.length; instr_i += 1) {6428 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);6429 IrInstGen *instruction = current_block->instruction_list.at(instr_i);
6505 if (instruction->ref_count == 0 && !ir_has_side_effects(instruction))6430 if (instruction->base.ref_count == 0 && !ir_inst_gen_has_side_effects(instruction))
6506 continue;6431 continue;
6507 if (get_scope_typeof(instruction->scope) != nullptr)6432 if (get_scope_typeof(instruction->base.scope) != nullptr)
6508 continue;6433 continue;
65096434
6510 if (!g->strip_debug_symbols) {6435 if (!g->strip_debug_symbols) {
...@@ -7396,7 +7321,7 @@ static void generate_error_name_table(CodeGen *g) {...@@ -7396,7 +7321,7 @@ static void generate_error_name_table(CodeGen *g) {
7396}7321}
73977322
7398static void build_all_basic_blocks(CodeGen *g, ZigFn *fn) {7323static void build_all_basic_blocks(CodeGen *g, ZigFn *fn) {
7399 IrExecutable *executable = &fn->analyzed_executable;7324 IrExecutableGen *executable = &fn->analyzed_executable;
7400 assert(executable->basic_block_list.length > 0);7325 assert(executable->basic_block_list.length > 0);
7401 LLVMValueRef fn_val = fn_llvm_value(g, fn);7326 LLVMValueRef fn_val = fn_llvm_value(g, fn);
7402 LLVMBasicBlockRef first_bb = nullptr;7327 LLVMBasicBlockRef first_bb = nullptr;
...@@ -7405,7 +7330,7 @@ static void build_all_basic_blocks(CodeGen *g, ZigFn *fn) {...@@ -7405,7 +7330,7 @@ static void build_all_basic_blocks(CodeGen *g, ZigFn *fn) {
7405 g->cur_preamble_llvm_block = first_bb;7330 g->cur_preamble_llvm_block = first_bb;
7406 }7331 }
7407 for (size_t block_i = 0; block_i < executable->basic_block_list.length; block_i += 1) {7332 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);
7409 bb->llvm_block = LLVMAppendBasicBlock(fn_val, bb->name_hint);7334 bb->llvm_block = LLVMAppendBasicBlock(fn_val, bb->name_hint);
7410 }7335 }
7411 if (first_bb == nullptr) {7336 if (first_bb == nullptr) {
...@@ -7638,10 +7563,10 @@ static void do_code_gen(CodeGen *g) {...@@ -7638,10 +7563,10 @@ static void do_code_gen(CodeGen *g) {
7638 if (!is_async) {7563 if (!is_async) {
7639 // allocate async frames for noasync calls & awaits to async functions7564 // allocate async frames for noasync calls & awaits to async functions
7640 ZigType *largest_call_frame_type = nullptr;7565 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,
7642 fn_table_entry->body_node, fn_table_entry, g->builtin_types.entry_void, "@async_call_frame");7567 fn_table_entry->body_node, fn_table_entry, g->builtin_types.entry_void, "@async_call_frame");
7643 for (size_t i = 0; i < fn_table_entry->call_list.length; i += 1) {7568 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);
7645 if (call->fn_entry == nullptr)7570 if (call->fn_entry == nullptr)
7646 continue;7571 continue;
7647 if (!fn_is_async(call->fn_entry))7572 if (!fn_is_async(call->fn_entry))
...@@ -7663,7 +7588,7 @@ static void do_code_gen(CodeGen *g) {...@@ -7663,7 +7588,7 @@ static void do_code_gen(CodeGen *g) {
7663 }7588 }
7664 // allocate temporary stack data7589 // allocate temporary stack data
7665 for (size_t alloca_i = 0; alloca_i < fn_table_entry->alloca_gen_list.length; alloca_i += 1) {7590 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);
7667 ZigType *ptr_type = instruction->base.value->type;7592 ZigType *ptr_type = instruction->base.value->type;
7668 assert(ptr_type->id == ZigTypeIdPointer);7593 assert(ptr_type->id == ZigTypeIdPointer);
7669 ZigType *child_type = ptr_type->data.pointer.child_type;7594 ZigType *child_type = ptr_type->data.pointer.child_type;
...@@ -7671,7 +7596,7 @@ static void do_code_gen(CodeGen *g) {...@@ -7671,7 +7596,7 @@ static void do_code_gen(CodeGen *g) {
7671 zig_unreachable();7596 zig_unreachable();
7672 if (!type_has_bits(child_type))7597 if (!type_has_bits(child_type))
7673 continue;7598 continue;
7674 if (instruction->base.ref_count == 0)7599 if (instruction->base.base.ref_count == 0)
7675 continue;7600 continue;
7676 if (instruction->base.value->special != ConstValSpecialRuntime) {7601 if (instruction->base.value->special != ConstValSpecialRuntime) {
7677 if (const_ptr_pointee(nullptr, g, instruction->base.value, nullptr)->special !=7602 if (const_ptr_pointee(nullptr, g, instruction->base.value, nullptr)->special !=
...@@ -7788,7 +7713,7 @@ static void do_code_gen(CodeGen *g) {...@@ -7788,7 +7713,7 @@ static void do_code_gen(CodeGen *g) {
7788 ZigLLVMSetCurrentDebugLocation(g->builder, (int)source_node->line + 1,7713 ZigLLVMSetCurrentDebugLocation(g->builder, (int)source_node->line + 1,
7789 (int)source_node->column + 1, get_di_scope(g, fn_table_entry->child_scope));7714 (int)source_node->column + 1, get_di_scope(g, fn_table_entry->child_scope));
7790 }7715 }
7791 IrExecutable *executable = &fn_table_entry->analyzed_executable;7716 IrExecutableGen *executable = &fn_table_entry->analyzed_executable;
7792 LLVMBasicBlockRef bad_resume_block = LLVMAppendBasicBlock(g->cur_fn_val, "BadResume");7717 LLVMBasicBlockRef bad_resume_block = LLVMAppendBasicBlock(g->cur_fn_val, "BadResume");
7793 LLVMPositionBuilderAtEnd(g->builder, bad_resume_block);7718 LLVMPositionBuilderAtEnd(g->builder, bad_resume_block);
7794 gen_assertion_scope(g, PanicMsgIdBadResume, fn_table_entry->child_scope);7719 gen_assertion_scope(g, PanicMsgIdBadResume, fn_table_entry->child_scope);
...@@ -7815,7 +7740,7 @@ static void do_code_gen(CodeGen *g) {...@@ -7815,7 +7740,7 @@ static void do_code_gen(CodeGen *g) {
7815 g->cur_async_switch_instr = switch_instr;7740 g->cur_async_switch_instr = switch_instr;
78167741
7817 LLVMValueRef zero = LLVMConstNull(usize_type_ref);7742 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);
7819 LLVMAddCase(switch_instr, zero, entry_block->llvm_block);7744 LLVMAddCase(switch_instr, zero, entry_block->llvm_block);
7820 g->cur_resume_block_count += 1;7745 g->cur_resume_block_count += 1;
78217746
...@@ -7847,7 +7772,7 @@ static void do_code_gen(CodeGen *g) {...@@ -7847,7 +7772,7 @@ static void do_code_gen(CodeGen *g) {
78477772
7848 gen_init_stack_trace(g, trace_field_ptr, addrs_field_ptr);7773 gen_init_stack_trace(g, trace_field_ptr, addrs_field_ptr);
7849 }7774 }
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);
7851 } else {7776 } else {
7852 // create debug variable declarations for parameters7777 // create debug variable declarations for parameters
7853 // rely on the first variables in the variable_list being parameters.7778 // rely on the first variables in the variable_list being parameters.
...@@ -7936,6 +7861,12 @@ static void zig_llvm_emit_output(CodeGen *g) {...@@ -7936,6 +7861,12 @@ static void zig_llvm_emit_output(CodeGen *g) {
7936 default:7861 default:
7937 zig_unreachable();7862 zig_unreachable();
7938 }7863 }
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;
7939}7870}
79407871
7941struct CIntTypeInfo {7872struct CIntTypeInfo {
...@@ -8846,15 +8777,17 @@ static void init(CodeGen *g) {...@@ -8846,15 +8777,17 @@ static void init(CodeGen *g) {
8846 define_builtin_types(g);8777 define_builtin_types(g);
8847 define_intern_values(g);8778 define_intern_values(g);
88488779
8849 IrInstruction *sentinel_instructions = allocate<IrInstruction>(2);8780 IrInstGen *sentinel_instructions = allocate<IrInstGen>(2);
8850 g->invalid_instruction = &sentinel_instructions[0];8781 g->invalid_inst_gen = &sentinel_instructions[0];
8851 g->invalid_instruction->value = allocate<ZigValue>(1, "ZigValue");8782 g->invalid_inst_gen->value = allocate<ZigValue>(1, "ZigValue");
8852 g->invalid_instruction->value->type = g->builtin_types.entry_invalid;8783 g->invalid_inst_gen->value->type = g->builtin_types.entry_invalid;
88538784
8854 g->unreach_instruction = &sentinel_instructions[1];8785 g->unreach_instruction = &sentinel_instructions[1];
8855 g->unreach_instruction->value = allocate<ZigValue>(1, "ZigValue");8786 g->unreach_instruction->value = allocate<ZigValue>(1, "ZigValue");
8856 g->unreach_instruction->value->type = g->builtin_types.entry_unreachable;8787 g->unreach_instruction->value->type = g->builtin_types.entry_unreachable;
88578788
8789 g->invalid_inst_src = allocate<IrInstSrc>(1);
8790
8858 define_builtin_fns(g);8791 define_builtin_fns(g);
8859 Error err;8792 Error err;
8860 if ((err = define_builtin_compile_vars(g))) {8793 if ((err = define_builtin_compile_vars(g))) {
...@@ -8996,7 +8929,10 @@ static void detect_libc(CodeGen *g) {...@@ -8996,7 +8929,10 @@ static void detect_libc(CodeGen *g) {
8996 "See `zig libc --help` for more details.\n", err_str(err));8929 "See `zig libc --help` for more details.\n", err_str(err));
8997 exit(1);8930 exit(1);
8998 }8931 }
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))) {
9000 fprintf(stderr, "Unable to create %s directory: %s\n",8936 fprintf(stderr, "Unable to create %s directory: %s\n",
9001 buf_ptr(g->cache_dir), err_str(err));8937 buf_ptr(g->cache_dir), err_str(err));
9002 exit(1);8938 exit(1);
...@@ -9788,6 +9724,7 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, ZigType *type_e...@@ -9788,6 +9724,7 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, ZigType *type_e
9788 zig_unreachable();9724 zig_unreachable();
9789 case ZigTypeIdVoid:9725 case ZigTypeIdVoid:
9790 case ZigTypeIdUnreachable:9726 case ZigTypeIdUnreachable:
9727 return;
9791 case ZigTypeIdBool:9728 case ZigTypeIdBool:
9792 g->c_want_stdbool = true;9729 g->c_want_stdbool = true;
9793 return;9730 return;
src/ir.cpp+7219-6358
...@@ -21,25 +21,31 @@ struct IrExecContext {...@@ -21,25 +21,31 @@ struct IrExecContext {
21 ZigList<ZigValue *> mem_slot_list;21 ZigList<ZigValue *> mem_slot_list;
22};22};
2323
24struct IrBuilder {24struct IrBuilderSrc {
25 CodeGen *codegen;25 CodeGen *codegen;
26 IrExecutable *exec;26 IrExecutableSrc *exec;
27 IrBasicBlock *current_basic_block;27 IrBasicBlockSrc *current_basic_block;
28 AstNode *main_block_node;28 AstNode *main_block_node;
29};29};
3030
31struct IrBuilderGen {
32 CodeGen *codegen;
33 IrExecutableGen *exec;
34 IrBasicBlockGen *current_basic_block;
35};
36
31struct IrAnalyze {37struct IrAnalyze {
32 CodeGen *codegen;38 CodeGen *codegen;
33 IrBuilder old_irb;39 IrBuilderSrc old_irb;
34 IrBuilder new_irb;40 IrBuilderGen new_irb;
35 IrExecContext exec_context;41 IrExecContext exec_context;
36 size_t old_bb_index;42 size_t old_bb_index;
37 size_t instruction_index;43 size_t instruction_index;
38 ZigType *explicit_return_type;44 ZigType *explicit_return_type;
39 AstNode *explicit_return_type_source_node;45 AstNode *explicit_return_type_source_node;
40 ZigList<IrInstruction *> src_implicit_return_type_list;46 ZigList<IrInstGen *> src_implicit_return_type_list;
41 ZigList<IrSuspendPosition> resume_stack;47 ZigList<IrSuspendPosition> resume_stack;
42 IrBasicBlock *const_predecessor_bb;48 IrBasicBlockSrc *const_predecessor_bb;
43 size_t ref_count;49 size_t ref_count;
44 size_t break_debug_id; // for debugging purposes50 size_t break_debug_id; // for debugging purposes
4551
...@@ -206,412 +212,538 @@ struct DbgIrBreakPoint {...@@ -206,412 +212,538 @@ struct DbgIrBreakPoint {
206DbgIrBreakPoint dbg_ir_breakpoints_buf[20];212DbgIrBreakPoint dbg_ir_breakpoints_buf[20];
207size_t dbg_ir_breakpoints_count = 0;213size_t dbg_ir_breakpoints_count = 0;
208214
209static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope);215static IrInstSrc *ir_gen_node(IrBuilderSrc *irb, AstNode *node, Scope *scope);
210static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval,216static IrInstSrc *ir_gen_node_extra(IrBuilderSrc *irb, AstNode *node, Scope *scope, LVal lval,
211 ResultLoc *result_loc);217 ResultLoc *result_loc);
212static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type);218static IrInstGen *ir_implicit_cast(IrAnalyze *ira, IrInstGen *value, ZigType *expected_type);
213static IrInstruction *ir_implicit_cast2(IrAnalyze *ira, IrInstruction *value_source_instr,219static IrInstGen *ir_implicit_cast2(IrAnalyze *ira, IrInst *value_source_instr,
214 IrInstruction *value, ZigType *expected_type);220 IrInstGen *value, ZigType *expected_type);
215static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr,221static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst *source_instr, IrInstGen *ptr,
216 ResultLoc *result_loc);222 ResultLoc *result_loc);
217static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg);223static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutableSrc *exec, AstNode *source_node, Buf *msg);
218static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,224static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,
219 IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type, bool initializing);225 IrInst* source_instr, IrInstGen *container_ptr, ZigType *container_type, bool initializing);
220static void ir_assert(bool ok, IrInstruction *source_instruction);226static void ir_assert(bool ok, IrInst* source_instruction);
221static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, ZigVar *var);227static void ir_assert_gen(bool ok, IrInstGen *source_instruction);
222static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op);228static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, IrInst *source_instr, ZigVar *var);
223static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval, ResultLoc *result_loc);229static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op);
224static IrInstruction *ir_expr_wrap(IrBuilder *irb, Scope *scope, IrInstruction *inst, ResultLoc *result_loc);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);
225static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align);232static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align);
226static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new_align);233static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new_align);
227static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf, ZigValue *val);234static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf, ZigValue *val);
228static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ZigValue *val);235static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ZigValue *val);
229static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,236static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,
230 ZigValue *out_val, ZigValue *ptr_val);237 ZigValue *out_val, ZigValue *ptr_val);
231static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *ptr,238static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *ptr,
232 ZigType *dest_type, IrInstruction *dest_type_src, bool safety_check_on);239 ZigType *dest_type, IrInst *dest_type_src, bool safety_check_on);
233static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed);240static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstGen *value, UndefAllowed undef_allowed);
234static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align);241static 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,
236 ZigType *ptr_type);243 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,
238 ZigType *dest_type);245 ZigType *dest_type);
239static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr,246static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_instr,
240 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime,247 ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime,
241 bool non_null_comptime, bool allow_discard);248 bool non_null_comptime, bool allow_discard);
242static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_source_instr,249static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr,
243 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime,250 ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime,
244 bool non_null_comptime, bool allow_discard);251 bool non_null_comptime, bool allow_discard);
245static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstruction *source_instr,252static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* source_instr,
246 IrInstruction *base_ptr, bool safety_check_on, bool initializing);253 IrInstGen *base_ptr, bool safety_check_on, bool initializing);
247static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruction *source_instr,254static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source_instr,
248 IrInstruction *base_ptr, bool safety_check_on, bool initializing);255 IrInstGen *base_ptr, bool safety_check_on, bool initializing);
249static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *source_instr,256static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_instr,
250 IrInstruction *base_ptr, bool initializing);257 IrInstGen *base_ptr, bool initializing);
251static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source_instr,258static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr,
252 IrInstruction *ptr, IrInstruction *uncasted_value, bool allow_write_through_const);259 IrInstGen *ptr, IrInstGen *uncasted_value, bool allow_write_through_const);
253static IrInstruction *ir_gen_union_init_expr(IrBuilder *irb, Scope *scope, AstNode *source_node,260static IrInstSrc *ir_gen_union_init_expr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
254 IrInstruction *union_type, IrInstruction *field_name, AstNode *expr_node,261 IrInstSrc *union_type, IrInstSrc *field_name, AstNode *expr_node,
255 LVal lval, ResultLoc *parent_result_loc);262 LVal lval, ResultLoc *parent_result_loc);
256static void ir_reset_result(ResultLoc *result_loc);263static 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,
258 Scope *scope, AstNode *source_node, Buf *out_bare_name);265 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,
260 ResultLoc *parent_result_loc);267 ResultLoc *parent_result_loc);
261static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction *source_instr,268static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_instr,
262 TypeStructField *field, IrInstruction *struct_ptr, ZigType *struct_type, bool initializing);269 TypeStructField *field, IrInstGen *struct_ptr, ZigType *struct_type, bool initializing);
263static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,270static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,
264 IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type);271 IrInst* source_instr, IrInstGen *container_ptr, ZigType *container_type);
265static ResultLoc *no_result_loc(void);272static 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) {
269#ifdef ZIG_ENABLE_MEM_PROFILE565#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);
271#else567#else
272 const char *name = nullptr;568 const char *name = nullptr;
273#endif569#endif
274 switch (inst->id) {570 switch (inst->id) {
275 case IrInstructionIdInvalid:571 case IrInstGenIdInvalid:
276 zig_unreachable();572 zig_unreachable();
277 case IrInstructionIdReturn:573 case IrInstGenIdReturn:
278 return destroy(reinterpret_cast<IrInstructionReturn *>(inst), name);574 return destroy(reinterpret_cast<IrInstGenReturn *>(inst), name);
279 case IrInstructionIdConst:575 case IrInstGenIdConst:
280 return destroy(reinterpret_cast<IrInstructionConst *>(inst), name);576 return destroy(reinterpret_cast<IrInstGenConst *>(inst), name);
281 case IrInstructionIdBinOp:577 case IrInstGenIdBinOp:
282 return destroy(reinterpret_cast<IrInstructionBinOp *>(inst), name);578 return destroy(reinterpret_cast<IrInstGenBinOp *>(inst), name);
283 case IrInstructionIdMergeErrSets:579 case IrInstGenIdCast:
284 return destroy(reinterpret_cast<IrInstructionMergeErrSets *>(inst), name);580 return destroy(reinterpret_cast<IrInstGenCast *>(inst), name);
285 case IrInstructionIdDeclVarSrc:581 case IrInstGenIdCall:
286 return destroy(reinterpret_cast<IrInstructionDeclVarSrc *>(inst), name);582 return destroy(reinterpret_cast<IrInstGenCall *>(inst), name);
287 case IrInstructionIdCast:583 case IrInstGenIdCondBr:
288 return destroy(reinterpret_cast<IrInstructionCast *>(inst), name);584 return destroy(reinterpret_cast<IrInstGenCondBr *>(inst), name);
289 case IrInstructionIdCallSrc:585 case IrInstGenIdBr:
290 return destroy(reinterpret_cast<IrInstructionCallSrc *>(inst), name);586 return destroy(reinterpret_cast<IrInstGenBr *>(inst), name);
291 case IrInstructionIdCallSrcArgs:587 case IrInstGenIdPhi:
292 return destroy(reinterpret_cast<IrInstructionCallSrcArgs *>(inst), name);588 return destroy(reinterpret_cast<IrInstGenPhi *>(inst), name);
293 case IrInstructionIdCallExtra:589 case IrInstGenIdUnreachable:
294 return destroy(reinterpret_cast<IrInstructionCallExtra *>(inst), name);590 return destroy(reinterpret_cast<IrInstGenUnreachable *>(inst), name);
295 case IrInstructionIdCallGen:591 case IrInstGenIdElemPtr:
296 return destroy(reinterpret_cast<IrInstructionCallGen *>(inst), name);592 return destroy(reinterpret_cast<IrInstGenElemPtr *>(inst), name);
297 case IrInstructionIdUnOp:593 case IrInstGenIdVarPtr:
298 return destroy(reinterpret_cast<IrInstructionUnOp *>(inst), name);594 return destroy(reinterpret_cast<IrInstGenVarPtr *>(inst), name);
299 case IrInstructionIdCondBr:595 case IrInstGenIdReturnPtr:
300 return destroy(reinterpret_cast<IrInstructionCondBr *>(inst), name);596 return destroy(reinterpret_cast<IrInstGenReturnPtr *>(inst), name);
301 case IrInstructionIdBr:597 case IrInstGenIdLoadPtr:
302 return destroy(reinterpret_cast<IrInstructionBr *>(inst), name);598 return destroy(reinterpret_cast<IrInstGenLoadPtr *>(inst), name);
303 case IrInstructionIdPhi:599 case IrInstGenIdStorePtr:
304 return destroy(reinterpret_cast<IrInstructionPhi *>(inst), name);600 return destroy(reinterpret_cast<IrInstGenStorePtr *>(inst), name);
305 case IrInstructionIdContainerInitList:601 case IrInstGenIdVectorStoreElem:
306 return destroy(reinterpret_cast<IrInstructionContainerInitList *>(inst), name);602 return destroy(reinterpret_cast<IrInstGenVectorStoreElem *>(inst), name);
307 case IrInstructionIdContainerInitFields:603 case IrInstGenIdStructFieldPtr:
308 return destroy(reinterpret_cast<IrInstructionContainerInitFields *>(inst), name);604 return destroy(reinterpret_cast<IrInstGenStructFieldPtr *>(inst), name);
309 case IrInstructionIdUnreachable:605 case IrInstGenIdUnionFieldPtr:
310 return destroy(reinterpret_cast<IrInstructionUnreachable *>(inst), name);606 return destroy(reinterpret_cast<IrInstGenUnionFieldPtr *>(inst), name);
311 case IrInstructionIdElemPtr:607 case IrInstGenIdAsm:
312 return destroy(reinterpret_cast<IrInstructionElemPtr *>(inst), name);608 return destroy(reinterpret_cast<IrInstGenAsm *>(inst), name);
313 case IrInstructionIdVarPtr:609 case IrInstGenIdTestNonNull:
314 return destroy(reinterpret_cast<IrInstructionVarPtr *>(inst), name);610 return destroy(reinterpret_cast<IrInstGenTestNonNull *>(inst), name);
315 case IrInstructionIdReturnPtr:611 case IrInstGenIdOptionalUnwrapPtr:
316 return destroy(reinterpret_cast<IrInstructionReturnPtr *>(inst), name);612 return destroy(reinterpret_cast<IrInstGenOptionalUnwrapPtr *>(inst), name);
317 case IrInstructionIdLoadPtr:613 case IrInstGenIdPopCount:
318 return destroy(reinterpret_cast<IrInstructionLoadPtr *>(inst), name);614 return destroy(reinterpret_cast<IrInstGenPopCount *>(inst), name);
319 case IrInstructionIdLoadPtrGen:615 case IrInstGenIdClz:
320 return destroy(reinterpret_cast<IrInstructionLoadPtrGen *>(inst), name);616 return destroy(reinterpret_cast<IrInstGenClz *>(inst), name);
321 case IrInstructionIdStorePtr:617 case IrInstGenIdCtz:
322 return destroy(reinterpret_cast<IrInstructionStorePtr *>(inst), name);618 return destroy(reinterpret_cast<IrInstGenCtz *>(inst), name);
323 case IrInstructionIdVectorStoreElem:619 case IrInstGenIdBswap:
324 return destroy(reinterpret_cast<IrInstructionVectorStoreElem *>(inst), name);620 return destroy(reinterpret_cast<IrInstGenBswap *>(inst), name);
325 case IrInstructionIdTypeOf:621 case IrInstGenIdBitReverse:
326 return destroy(reinterpret_cast<IrInstructionTypeOf *>(inst), name);622 return destroy(reinterpret_cast<IrInstGenBitReverse *>(inst), name);
327 case IrInstructionIdFieldPtr:623 case IrInstGenIdSwitchBr:
328 return destroy(reinterpret_cast<IrInstructionFieldPtr *>(inst), name);624 return destroy(reinterpret_cast<IrInstGenSwitchBr *>(inst), name);
329 case IrInstructionIdStructFieldPtr:625 case IrInstGenIdUnionTag:
330 return destroy(reinterpret_cast<IrInstructionStructFieldPtr *>(inst), name);626 return destroy(reinterpret_cast<IrInstGenUnionTag *>(inst), name);
331 case IrInstructionIdUnionFieldPtr:627 case IrInstGenIdRef:
332 return destroy(reinterpret_cast<IrInstructionUnionFieldPtr *>(inst), name);628 return destroy(reinterpret_cast<IrInstGenRef *>(inst), name);
333 case IrInstructionIdSetCold:629 case IrInstGenIdErrName:
334 return destroy(reinterpret_cast<IrInstructionSetCold *>(inst), name);630 return destroy(reinterpret_cast<IrInstGenErrName *>(inst), name);
335 case IrInstructionIdSetRuntimeSafety:631 case IrInstGenIdCmpxchg:
336 return destroy(reinterpret_cast<IrInstructionSetRuntimeSafety *>(inst), name);632 return destroy(reinterpret_cast<IrInstGenCmpxchg *>(inst), name);
337 case IrInstructionIdSetFloatMode:633 case IrInstGenIdFence:
338 return destroy(reinterpret_cast<IrInstructionSetFloatMode *>(inst), name);634 return destroy(reinterpret_cast<IrInstGenFence *>(inst), name);
339 case IrInstructionIdArrayType:635 case IrInstGenIdTruncate:
340 return destroy(reinterpret_cast<IrInstructionArrayType *>(inst), name);636 return destroy(reinterpret_cast<IrInstGenTruncate *>(inst), name);
341 case IrInstructionIdSliceType:637 case IrInstGenIdShuffleVector:
342 return destroy(reinterpret_cast<IrInstructionSliceType *>(inst), name);638 return destroy(reinterpret_cast<IrInstGenShuffleVector *>(inst), name);
343 case IrInstructionIdAnyFrameType:639 case IrInstGenIdSplat:
344 return destroy(reinterpret_cast<IrInstructionAnyFrameType *>(inst), name);640 return destroy(reinterpret_cast<IrInstGenSplat *>(inst), name);
345 case IrInstructionIdAsmSrc:641 case IrInstGenIdBoolNot:
346 return destroy(reinterpret_cast<IrInstructionAsmSrc *>(inst), name);642 return destroy(reinterpret_cast<IrInstGenBoolNot *>(inst), name);
347 case IrInstructionIdAsmGen:643 case IrInstGenIdMemset:
348 return destroy(reinterpret_cast<IrInstructionAsmGen *>(inst), name);644 return destroy(reinterpret_cast<IrInstGenMemset *>(inst), name);
349 case IrInstructionIdSizeOf:645 case IrInstGenIdMemcpy:
350 return destroy(reinterpret_cast<IrInstructionSizeOf *>(inst), name);646 return destroy(reinterpret_cast<IrInstGenMemcpy *>(inst), name);
351 case IrInstructionIdTestNonNull:647 case IrInstGenIdSlice:
352 return destroy(reinterpret_cast<IrInstructionTestNonNull *>(inst), name);648 return destroy(reinterpret_cast<IrInstGenSlice *>(inst), name);
353 case IrInstructionIdOptionalUnwrapPtr:649 case IrInstGenIdBreakpoint:
354 return destroy(reinterpret_cast<IrInstructionOptionalUnwrapPtr *>(inst), name);650 return destroy(reinterpret_cast<IrInstGenBreakpoint *>(inst), name);
355 case IrInstructionIdPopCount:651 case IrInstGenIdReturnAddress:
356 return destroy(reinterpret_cast<IrInstructionPopCount *>(inst), name);652 return destroy(reinterpret_cast<IrInstGenReturnAddress *>(inst), name);
357 case IrInstructionIdClz:653 case IrInstGenIdFrameAddress:
358 return destroy(reinterpret_cast<IrInstructionClz *>(inst), name);654 return destroy(reinterpret_cast<IrInstGenFrameAddress *>(inst), name);
359 case IrInstructionIdCtz:655 case IrInstGenIdFrameHandle:
360 return destroy(reinterpret_cast<IrInstructionCtz *>(inst), name);656 return destroy(reinterpret_cast<IrInstGenFrameHandle *>(inst), name);
361 case IrInstructionIdBswap:657 case IrInstGenIdFrameSize:
362 return destroy(reinterpret_cast<IrInstructionBswap *>(inst), name);658 return destroy(reinterpret_cast<IrInstGenFrameSize *>(inst), name);
363 case IrInstructionIdBitReverse:659 case IrInstGenIdOverflowOp:
364 return destroy(reinterpret_cast<IrInstructionBitReverse *>(inst), name);660 return destroy(reinterpret_cast<IrInstGenOverflowOp *>(inst), name);
365 case IrInstructionIdSwitchBr:661 case IrInstGenIdTestErr:
366 return destroy(reinterpret_cast<IrInstructionSwitchBr *>(inst), name);662 return destroy(reinterpret_cast<IrInstGenTestErr *>(inst), name);
367 case IrInstructionIdSwitchVar:663 case IrInstGenIdUnwrapErrCode:
368 return destroy(reinterpret_cast<IrInstructionSwitchVar *>(inst), name);664 return destroy(reinterpret_cast<IrInstGenUnwrapErrCode *>(inst), name);
369 case IrInstructionIdSwitchElseVar:665 case IrInstGenIdUnwrapErrPayload:
370 return destroy(reinterpret_cast<IrInstructionSwitchElseVar *>(inst), name);666 return destroy(reinterpret_cast<IrInstGenUnwrapErrPayload *>(inst), name);
371 case IrInstructionIdSwitchTarget:667 case IrInstGenIdOptionalWrap:
372 return destroy(reinterpret_cast<IrInstructionSwitchTarget *>(inst), name);668 return destroy(reinterpret_cast<IrInstGenOptionalWrap *>(inst), name);
373 case IrInstructionIdUnionTag:669 case IrInstGenIdErrWrapCode:
374 return destroy(reinterpret_cast<IrInstructionUnionTag *>(inst), name);670 return destroy(reinterpret_cast<IrInstGenErrWrapCode *>(inst), name);
375 case IrInstructionIdImport:671 case IrInstGenIdErrWrapPayload:
376 return destroy(reinterpret_cast<IrInstructionImport *>(inst), name);672 return destroy(reinterpret_cast<IrInstGenErrWrapPayload *>(inst), name);
377 case IrInstructionIdRef:673 case IrInstGenIdPtrCast:
378 return destroy(reinterpret_cast<IrInstructionRef *>(inst), name);674 return destroy(reinterpret_cast<IrInstGenPtrCast *>(inst), name);
379 case IrInstructionIdRefGen:675 case IrInstGenIdBitCast:
380 return destroy(reinterpret_cast<IrInstructionRefGen *>(inst), name);676 return destroy(reinterpret_cast<IrInstGenBitCast *>(inst), name);
381 case IrInstructionIdCompileErr:677 case IrInstGenIdWidenOrShorten:
382 return destroy(reinterpret_cast<IrInstructionCompileErr *>(inst), name);678 return destroy(reinterpret_cast<IrInstGenWidenOrShorten *>(inst), name);
383 case IrInstructionIdCompileLog:679 case IrInstGenIdPtrToInt:
384 return destroy(reinterpret_cast<IrInstructionCompileLog *>(inst), name);680 return destroy(reinterpret_cast<IrInstGenPtrToInt *>(inst), name);
385 case IrInstructionIdErrName:681 case IrInstGenIdIntToPtr:
386 return destroy(reinterpret_cast<IrInstructionErrName *>(inst), name);682 return destroy(reinterpret_cast<IrInstGenIntToPtr *>(inst), name);
387 case IrInstructionIdCImport:683 case IrInstGenIdIntToEnum:
388 return destroy(reinterpret_cast<IrInstructionCImport *>(inst), name);684 return destroy(reinterpret_cast<IrInstGenIntToEnum *>(inst), name);
389 case IrInstructionIdCInclude:685 case IrInstGenIdIntToErr:
390 return destroy(reinterpret_cast<IrInstructionCInclude *>(inst), name);686 return destroy(reinterpret_cast<IrInstGenIntToErr *>(inst), name);
391 case IrInstructionIdCDefine:687 case IrInstGenIdErrToInt:
392 return destroy(reinterpret_cast<IrInstructionCDefine *>(inst), name);688 return destroy(reinterpret_cast<IrInstGenErrToInt *>(inst), name);
393 case IrInstructionIdCUndef:689 case IrInstGenIdTagName:
394 return destroy(reinterpret_cast<IrInstructionCUndef *>(inst), name);690 return destroy(reinterpret_cast<IrInstGenTagName *>(inst), name);
395 case IrInstructionIdEmbedFile:691 case IrInstGenIdPanic:
396 return destroy(reinterpret_cast<IrInstructionEmbedFile *>(inst), name);692 return destroy(reinterpret_cast<IrInstGenPanic *>(inst), name);
397 case IrInstructionIdCmpxchgSrc:693 case IrInstGenIdFieldParentPtr:
398 return destroy(reinterpret_cast<IrInstructionCmpxchgSrc *>(inst), name);694 return destroy(reinterpret_cast<IrInstGenFieldParentPtr *>(inst), name);
399 case IrInstructionIdCmpxchgGen:695 case IrInstGenIdAlignCast:
400 return destroy(reinterpret_cast<IrInstructionCmpxchgGen *>(inst), name);696 return destroy(reinterpret_cast<IrInstGenAlignCast *>(inst), name);
401 case IrInstructionIdFence:697 case IrInstGenIdErrorReturnTrace:
402 return destroy(reinterpret_cast<IrInstructionFence *>(inst), name);698 return destroy(reinterpret_cast<IrInstGenErrorReturnTrace *>(inst), name);
403 case IrInstructionIdTruncate:699 case IrInstGenIdAtomicRmw:
404 return destroy(reinterpret_cast<IrInstructionTruncate *>(inst), name);700 return destroy(reinterpret_cast<IrInstGenAtomicRmw *>(inst), name);
405 case IrInstructionIdIntCast:701 case IrInstGenIdSaveErrRetAddr:
406 return destroy(reinterpret_cast<IrInstructionIntCast *>(inst), name);702 return destroy(reinterpret_cast<IrInstGenSaveErrRetAddr *>(inst), name);
407 case IrInstructionIdFloatCast:703 case IrInstGenIdFloatOp:
408 return destroy(reinterpret_cast<IrInstructionFloatCast *>(inst), name);704 return destroy(reinterpret_cast<IrInstGenFloatOp *>(inst), name);
409 case IrInstructionIdErrSetCast:705 case IrInstGenIdMulAdd:
410 return destroy(reinterpret_cast<IrInstructionErrSetCast *>(inst), name);706 return destroy(reinterpret_cast<IrInstGenMulAdd *>(inst), name);
411 case IrInstructionIdFromBytes:707 case IrInstGenIdAtomicLoad:
412 return destroy(reinterpret_cast<IrInstructionFromBytes *>(inst), name);708 return destroy(reinterpret_cast<IrInstGenAtomicLoad *>(inst), name);
413 case IrInstructionIdToBytes:709 case IrInstGenIdAtomicStore:
414 return destroy(reinterpret_cast<IrInstructionToBytes *>(inst), name);710 return destroy(reinterpret_cast<IrInstGenAtomicStore *>(inst), name);
415 case IrInstructionIdIntToFloat:711 case IrInstGenIdDeclVar:
416 return destroy(reinterpret_cast<IrInstructionIntToFloat *>(inst), name);712 return destroy(reinterpret_cast<IrInstGenDeclVar *>(inst), name);
417 case IrInstructionIdFloatToInt:713 case IrInstGenIdArrayToVector:
418 return destroy(reinterpret_cast<IrInstructionFloatToInt *>(inst), name);714 return destroy(reinterpret_cast<IrInstGenArrayToVector *>(inst), name);
419 case IrInstructionIdBoolToInt:715 case IrInstGenIdVectorToArray:
420 return destroy(reinterpret_cast<IrInstructionBoolToInt *>(inst), name);716 return destroy(reinterpret_cast<IrInstGenVectorToArray *>(inst), name);
421 case IrInstructionIdIntType:717 case IrInstGenIdPtrOfArrayToSlice:
422 return destroy(reinterpret_cast<IrInstructionIntType *>(inst), name);718 return destroy(reinterpret_cast<IrInstGenPtrOfArrayToSlice *>(inst), name);
423 case IrInstructionIdVectorType:719 case IrInstGenIdAssertZero:
424 return destroy(reinterpret_cast<IrInstructionVectorType *>(inst), name);720 return destroy(reinterpret_cast<IrInstGenAssertZero *>(inst), name);
425 case IrInstructionIdShuffleVector:721 case IrInstGenIdAssertNonNull:
426 return destroy(reinterpret_cast<IrInstructionShuffleVector *>(inst), name);722 return destroy(reinterpret_cast<IrInstGenAssertNonNull *>(inst), name);
427 case IrInstructionIdSplatSrc:723 case IrInstGenIdResizeSlice:
428 return destroy(reinterpret_cast<IrInstructionSplatSrc *>(inst), name);724 return destroy(reinterpret_cast<IrInstGenResizeSlice *>(inst), name);
429 case IrInstructionIdSplatGen:725 case IrInstGenIdAlloca:
430 return destroy(reinterpret_cast<IrInstructionSplatGen *>(inst), name);726 return destroy(reinterpret_cast<IrInstGenAlloca *>(inst), name);
431 case IrInstructionIdBoolNot:727 case IrInstGenIdSuspendBegin:
432 return destroy(reinterpret_cast<IrInstructionBoolNot *>(inst), name);728 return destroy(reinterpret_cast<IrInstGenSuspendBegin *>(inst), name);
433 case IrInstructionIdMemset:729 case IrInstGenIdSuspendFinish:
434 return destroy(reinterpret_cast<IrInstructionMemset *>(inst), name);730 return destroy(reinterpret_cast<IrInstGenSuspendFinish *>(inst), name);
435 case IrInstructionIdMemcpy:731 case IrInstGenIdResume:
436 return destroy(reinterpret_cast<IrInstructionMemcpy *>(inst), name);732 return destroy(reinterpret_cast<IrInstGenResume *>(inst), name);
437 case IrInstructionIdSliceSrc:733 case IrInstGenIdAwait:
438 return destroy(reinterpret_cast<IrInstructionSliceSrc *>(inst), name);734 return destroy(reinterpret_cast<IrInstGenAwait *>(inst), name);
439 case IrInstructionIdSliceGen:735 case IrInstGenIdSpillBegin:
440 return destroy(reinterpret_cast<IrInstructionSliceGen *>(inst), name);736 return destroy(reinterpret_cast<IrInstGenSpillBegin *>(inst), name);
441 case IrInstructionIdMemberCount:737 case IrInstGenIdSpillEnd:
442 return destroy(reinterpret_cast<IrInstructionMemberCount *>(inst), name);738 return destroy(reinterpret_cast<IrInstGenSpillEnd *>(inst), name);
443 case IrInstructionIdMemberType:739 case IrInstGenIdVectorExtractElem:
444 return destroy(reinterpret_cast<IrInstructionMemberType *>(inst), name);740 return destroy(reinterpret_cast<IrInstGenVectorExtractElem *>(inst), name);
445 case IrInstructionIdMemberName:741 case IrInstGenIdBinaryNot:
446 return destroy(reinterpret_cast<IrInstructionMemberName *>(inst), name);742 return destroy(reinterpret_cast<IrInstGenBinaryNot *>(inst), name);
447 case IrInstructionIdBreakpoint:743 case IrInstGenIdNegation:
448 return destroy(reinterpret_cast<IrInstructionBreakpoint *>(inst), name);744 return destroy(reinterpret_cast<IrInstGenNegation *>(inst), name);
449 case IrInstructionIdReturnAddress:745 case IrInstGenIdNegationWrapping:
450 return destroy(reinterpret_cast<IrInstructionReturnAddress *>(inst), name);746 return destroy(reinterpret_cast<IrInstGenNegationWrapping *>(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);
615 }747 }
616 zig_unreachable();748 zig_unreachable();
617}749}
...@@ -627,17 +759,17 @@ static void ira_deref(IrAnalyze *ira) {...@@ -627,17 +759,17 @@ static void ira_deref(IrAnalyze *ira) {
627 assert(ira->ref_count != 0);759 assert(ira->ref_count != 0);
628760
629 for (size_t bb_i = 0; bb_i < ira->old_irb.exec->basic_block_list.length; bb_i += 1) {761 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];
631 for (size_t inst_i = 0; inst_i < pass1_bb->instruction_list.length; inst_i += 1) {763 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];764 IrInstSrc *pass1_inst = pass1_bb->instruction_list.items[inst_i];
633 destroy_instruction(pass1_inst);765 destroy_instruction_src(pass1_inst);
634 }766 }
635 destroy(pass1_bb, "IrBasicBlock");767 destroy(pass1_bb, "IrBasicBlockSrc");
636 }768 }
637 ira->old_irb.exec->basic_block_list.deinit();769 ira->old_irb.exec->basic_block_list.deinit();
638 ira->old_irb.exec->tld_list.deinit();770 ira->old_irb.exec->tld_list.deinit();
639 // cannot destroy here because of var->owner_exec771 // cannot destroy here because of var->owner_exec
640 //destroy(ira->old_irb.exec, "IrExecutablePass1");772 //destroy(ira->old_irb.exec, "IrExecutableSrc");
641 ira->src_implicit_return_type_list.deinit();773 ira->src_implicit_return_type_list.deinit();
642 ira->resume_stack.deinit();774 ira->resume_stack.deinit();
643 ira->exec_context.mem_slot_list.deinit();775 ira->exec_context.mem_slot_list.deinit();
...@@ -785,7 +917,7 @@ static bool types_have_same_zig_comptime_repr(CodeGen *codegen, ZigType *expecte...@@ -785,7 +917,7 @@ static bool types_have_same_zig_comptime_repr(CodeGen *codegen, ZigType *expecte
785 zig_unreachable();917 zig_unreachable();
786}918}
787919
788static bool ir_should_inline(IrExecutable *exec, Scope *scope) {920static bool ir_should_inline(IrExecutableSrc *exec, Scope *scope) {
789 if (exec->is_inline)921 if (exec->is_inline)
790 return true;922 return true;
791923
...@@ -801,29 +933,41 @@ static bool ir_should_inline(IrExecutable *exec, Scope *scope) {...@@ -801,29 +933,41 @@ static bool ir_should_inline(IrExecutable *exec, Scope *scope) {
801 return false;933 return false;
802}934}
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) {
805 assert(basic_block);943 assert(basic_block);
806 assert(instruction);944 assert(instruction);
807 basic_block->instruction_list.append(instruction);945 basic_block->instruction_list.append(instruction);
808}946}
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) {
811 size_t result = exec->next_debug_id;955 size_t result = exec->next_debug_id;
812 exec->next_debug_id += 1;956 exec->next_debug_id += 1;
813 return result;957 return result;
814}958}
815959
816static size_t exec_next_mem_slot(IrExecutable *exec) {960static size_t exec_next_mem_slot(IrExecutableSrc *exec) {
817 size_t result = exec->mem_slot_count;961 size_t result = exec->mem_slot_count;
818 exec->mem_slot_count += 1;962 exec->mem_slot_count += 1;
819 return result;963 return result;
820}964}
821965
822static ZigFn *exec_fn_entry(IrExecutable *exec) {966static ZigFn *exec_fn_entry(IrExecutableSrc *exec) {
823 return exec->fn_entry;967 return exec->fn_entry;
824}968}
825969
826static Buf *exec_c_import_buf(IrExecutable *exec) {970static Buf *exec_c_import_buf(IrExecutableSrc *exec) {
827 return exec->c_import_buf;971 return exec->c_import_buf;
828}972}
829973
...@@ -831,28 +975,42 @@ static bool value_is_comptime(ZigValue *const_val) {...@@ -831,28 +975,42 @@ static bool value_is_comptime(ZigValue *const_val) {
831 return const_val->special != ConstValSpecialRuntime;975 return const_val->special != ConstValSpecialRuntime;
832}976}
833977
834static bool instr_is_comptime(IrInstruction *instruction) {978static bool instr_is_comptime(IrInstGen *instruction) {
835 return value_is_comptime(instruction->value);979 return value_is_comptime(instruction->value);
836}980}
837981
838static bool instr_is_unreachable(IrInstruction *instruction) {982static bool instr_is_unreachable(IrInstSrc *instruction) {
839 return instruction->value->type && instruction->value->type->id == ZigTypeIdUnreachable;983 return instruction->is_noreturn;
840}984}
841985
842static void ir_link_new_bb(IrBasicBlock *new_bb, IrBasicBlock *old_bb) {986static void ir_link_new_bb(IrBasicBlockGen *new_bb, IrBasicBlockSrc *old_bb) {
843 new_bb->other = old_bb;987 new_bb->parent = old_bb;
844 old_bb->other = new_bb;988 old_bb->child = new_bb;
845}989}
846990
847static void ir_ref_bb(IrBasicBlock *bb) {991static void ir_ref_bb(IrBasicBlockSrc *bb) {
848 bb->ref_count += 1;992 bb->ref_count += 1;
849}993}
850994
851static void ir_ref_instruction(IrInstruction *instruction, IrBasicBlock *cur_bb) {995static void ir_ref_bb_gen(IrBasicBlockGen *bb) {
852 assert(instruction->id != IrInstructionIdInvalid);996 bb->ref_count += 1;
853 instruction->ref_count += 1;997}
854 if (instruction->owner_bb != cur_bb && !instr_is_comptime(instruction))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 {
855 ir_ref_bb(instruction->owner_bb);1005 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);
856}1014}
8571015
858static void ir_ref_var(ZigVar *var) {1016static void ir_ref_var(ZigVar *var) {
...@@ -871,962 +1029,1259 @@ ZigType *ir_analyze_type_expr(IrAnalyze *ira, Scope *scope, AstNode *node) {...@@ -871,962 +1029,1259 @@ ZigType *ir_analyze_type_expr(IrAnalyze *ira, Scope *scope, AstNode *node) {
871 return result->data.x_type;1029 return result->data.x_type;
872}1030}
8731031
874static IrBasicBlock *ir_create_basic_block(IrBuilder *irb, Scope *scope, const char *name_hint) {1032static IrBasicBlockSrc *ir_create_basic_block(IrBuilderSrc *irb, Scope *scope, const char *name_hint) {
875 IrBasicBlock *result = allocate<IrBasicBlock>(1, "IrBasicBlock");1033 IrBasicBlockSrc *result = allocate<IrBasicBlockSrc>(1, "IrBasicBlockSrc");
876 result->scope = scope;1034 result->scope = scope;
877 result->name_hint = name_hint;1035 result->name_hint = name_hint;
878 result->debug_id = exec_next_debug_id(irb->exec);1036 result->debug_id = exec_next_debug_id(irb->exec);
879 result->index = SIZE_MAX; // set later1037 result->index = UINT32_MAX; // set later
880 return result;1038 return result;
881}1039}
8821040
883static IrBasicBlock *ir_build_bb_from(IrBuilder *irb, IrBasicBlock *other_bb) {1041static IrBasicBlockGen *ir_create_basic_block_gen(IrAnalyze *ira, Scope *scope, const char *name_hint) {
884 IrBasicBlock *new_bb = ir_create_basic_block(irb, other_bb->scope, other_bb->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);
885 ir_link_new_bb(new_bb, other_bb);1052 ir_link_new_bb(new_bb, other_bb);
886 return new_bb;1053 return new_bb;
887}1054}
8881055
889static constexpr IrInstructionId ir_instruction_id(IrInstructionDeclVarSrc *) {1056static constexpr IrInstSrcId ir_inst_id(IrInstSrcDeclVar *) {
890 return IrInstructionIdDeclVarSrc;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;
891}1286}
8921287
893static constexpr IrInstructionId ir_instruction_id(IrInstructionDeclVarGen *) {1288static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntType *) {
894 return IrInstructionIdDeclVarGen;1289 return IrInstSrcIdIntType;
895}1290}
8961291
897static constexpr IrInstructionId ir_instruction_id(IrInstructionCondBr *) {1292static constexpr IrInstSrcId ir_inst_id(IrInstSrcVectorType *) {
898 return IrInstructionIdCondBr;1293 return IrInstSrcIdVectorType;
899}1294}
9001295
901static constexpr IrInstructionId ir_instruction_id(IrInstructionBr *) {1296static constexpr IrInstSrcId ir_inst_id(IrInstSrcShuffleVector *) {
902 return IrInstructionIdBr;1297 return IrInstSrcIdShuffleVector;
903}1298}
9041299
905static constexpr IrInstructionId ir_instruction_id(IrInstructionSwitchBr *) {1300static constexpr IrInstSrcId ir_inst_id(IrInstSrcSplat *) {
906 return IrInstructionIdSwitchBr;1301 return IrInstSrcIdSplat;
907}1302}
9081303
909static constexpr IrInstructionId ir_instruction_id(IrInstructionSwitchVar *) {1304static constexpr IrInstSrcId ir_inst_id(IrInstSrcBoolNot *) {
910 return IrInstructionIdSwitchVar;1305 return IrInstSrcIdBoolNot;
911}1306}
9121307
913static constexpr IrInstructionId ir_instruction_id(IrInstructionSwitchElseVar *) {1308static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemset *) {
914 return IrInstructionIdSwitchElseVar;1309 return IrInstSrcIdMemset;
915}1310}
9161311
917static constexpr IrInstructionId ir_instruction_id(IrInstructionSwitchTarget *) {1312static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemcpy *) {
918 return IrInstructionIdSwitchTarget;1313 return IrInstSrcIdMemcpy;
919}1314}
9201315
921static constexpr IrInstructionId ir_instruction_id(IrInstructionPhi *) {1316static constexpr IrInstSrcId ir_inst_id(IrInstSrcSlice *) {
922 return IrInstructionIdPhi;1317 return IrInstSrcIdSlice;
923}1318}
9241319
925static constexpr IrInstructionId ir_instruction_id(IrInstructionUnOp *) {1320static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemberCount *) {
926 return IrInstructionIdUnOp;1321 return IrInstSrcIdMemberCount;
927}1322}
9281323
929static constexpr IrInstructionId ir_instruction_id(IrInstructionBinOp *) {1324static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemberType *) {
930 return IrInstructionIdBinOp;1325 return IrInstSrcIdMemberType;
931}1326}
9321327
933static constexpr IrInstructionId ir_instruction_id(IrInstructionMergeErrSets *) {1328static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemberName *) {
934 return IrInstructionIdMergeErrSets;1329 return IrInstSrcIdMemberName;
935}1330}
9361331
937static constexpr IrInstructionId ir_instruction_id(IrInstructionExport *) {1332static constexpr IrInstSrcId ir_inst_id(IrInstSrcBreakpoint *) {
938 return IrInstructionIdExport;1333 return IrInstSrcIdBreakpoint;
939}1334}
9401335
941static constexpr IrInstructionId ir_instruction_id(IrInstructionLoadPtr *) {1336static constexpr IrInstSrcId ir_inst_id(IrInstSrcReturnAddress *) {
942 return IrInstructionIdLoadPtr;1337 return IrInstSrcIdReturnAddress;
943}1338}
9441339
945static constexpr IrInstructionId ir_instruction_id(IrInstructionLoadPtrGen *) {1340static constexpr IrInstSrcId ir_inst_id(IrInstSrcFrameAddress *) {
946 return IrInstructionIdLoadPtrGen;1341 return IrInstSrcIdFrameAddress;
947}1342}
9481343
949static constexpr IrInstructionId ir_instruction_id(IrInstructionStorePtr *) {1344static constexpr IrInstSrcId ir_inst_id(IrInstSrcFrameHandle *) {
950 return IrInstructionIdStorePtr;1345 return IrInstSrcIdFrameHandle;
951}1346}
9521347
953static constexpr IrInstructionId ir_instruction_id(IrInstructionVectorStoreElem *) {1348static constexpr IrInstSrcId ir_inst_id(IrInstSrcFrameType *) {
954 return IrInstructionIdVectorStoreElem;1349 return IrInstSrcIdFrameType;
955}1350}
9561351
957static constexpr IrInstructionId ir_instruction_id(IrInstructionFieldPtr *) {1352static constexpr IrInstSrcId ir_inst_id(IrInstSrcFrameSize *) {
958 return IrInstructionIdFieldPtr;1353 return IrInstSrcIdFrameSize;
959}1354}
9601355
961static constexpr IrInstructionId ir_instruction_id(IrInstructionStructFieldPtr *) {1356static constexpr IrInstSrcId ir_inst_id(IrInstSrcAlignOf *) {
962 return IrInstructionIdStructFieldPtr;1357 return IrInstSrcIdAlignOf;
963}1358}
9641359
965static constexpr IrInstructionId ir_instruction_id(IrInstructionUnionFieldPtr *) {1360static constexpr IrInstSrcId ir_inst_id(IrInstSrcOverflowOp *) {
966 return IrInstructionIdUnionFieldPtr;1361 return IrInstSrcIdOverflowOp;
967}1362}
9681363
969static constexpr IrInstructionId ir_instruction_id(IrInstructionElemPtr *) {1364static constexpr IrInstSrcId ir_inst_id(IrInstSrcTestErr *) {
970 return IrInstructionIdElemPtr;1365 return IrInstSrcIdTestErr;
971}1366}
9721367
973static constexpr IrInstructionId ir_instruction_id(IrInstructionVarPtr *) {1368static constexpr IrInstSrcId ir_inst_id(IrInstSrcMulAdd *) {
974 return IrInstructionIdVarPtr;1369 return IrInstSrcIdMulAdd;
975}1370}
9761371
977static constexpr IrInstructionId ir_instruction_id(IrInstructionReturnPtr *) {1372static constexpr IrInstSrcId ir_inst_id(IrInstSrcFloatOp *) {
978 return IrInstructionIdReturnPtr;1373 return IrInstSrcIdFloatOp;
979}1374}
9801375
981static constexpr IrInstructionId ir_instruction_id(IrInstructionCallSrc *) {1376static constexpr IrInstSrcId ir_inst_id(IrInstSrcUnwrapErrCode *) {
982 return IrInstructionIdCallSrc;1377 return IrInstSrcIdUnwrapErrCode;
983}1378}
9841379
985static constexpr IrInstructionId ir_instruction_id(IrInstructionCallSrcArgs *) {1380static constexpr IrInstSrcId ir_inst_id(IrInstSrcUnwrapErrPayload *) {
986 return IrInstructionIdCallSrcArgs;1381 return IrInstSrcIdUnwrapErrPayload;
987}1382}
9881383
989static constexpr IrInstructionId ir_instruction_id(IrInstructionCallExtra *) {1384static constexpr IrInstSrcId ir_inst_id(IrInstSrcFnProto *) {
990 return IrInstructionIdCallExtra;1385 return IrInstSrcIdFnProto;
991}1386}
9921387
993static constexpr IrInstructionId ir_instruction_id(IrInstructionCallGen *) {1388static constexpr IrInstSrcId ir_inst_id(IrInstSrcTestComptime *) {
994 return IrInstructionIdCallGen;1389 return IrInstSrcIdTestComptime;
995}1390}
9961391
997static constexpr IrInstructionId ir_instruction_id(IrInstructionConst *) {1392static constexpr IrInstSrcId ir_inst_id(IrInstSrcPtrCast *) {
998 return IrInstructionIdConst;1393 return IrInstSrcIdPtrCast;
999}1394}
10001395
1001static constexpr IrInstructionId ir_instruction_id(IrInstructionReturn *) {1396static constexpr IrInstSrcId ir_inst_id(IrInstSrcBitCast *) {
1002 return IrInstructionIdReturn;1397 return IrInstSrcIdBitCast;
1003}1398}
10041399
1005static constexpr IrInstructionId ir_instruction_id(IrInstructionCast *) {1400static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntToPtr *) {
1006 return IrInstructionIdCast;1401 return IrInstSrcIdIntToPtr;
1007}1402}
10081403
1009static constexpr IrInstructionId ir_instruction_id(IrInstructionResizeSlice *) {1404static constexpr IrInstSrcId ir_inst_id(IrInstSrcPtrToInt *) {
1010 return IrInstructionIdResizeSlice;1405 return IrInstSrcIdPtrToInt;
1011}1406}
10121407
1013static constexpr IrInstructionId ir_instruction_id(IrInstructionContainerInitList *) {1408static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntToEnum *) {
1014 return IrInstructionIdContainerInitList;1409 return IrInstSrcIdIntToEnum;
1015}1410}
10161411
1017static constexpr IrInstructionId ir_instruction_id(IrInstructionContainerInitFields *) {1412static constexpr IrInstSrcId ir_inst_id(IrInstSrcEnumToInt *) {
1018 return IrInstructionIdContainerInitFields;1413 return IrInstSrcIdEnumToInt;
1019}1414}
10201415
1021static constexpr IrInstructionId ir_instruction_id(IrInstructionUnreachable *) {1416static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntToErr *) {
1022 return IrInstructionIdUnreachable;1417 return IrInstSrcIdIntToErr;
1023}1418}
10241419
1025static constexpr IrInstructionId ir_instruction_id(IrInstructionTypeOf *) {1420static constexpr IrInstSrcId ir_inst_id(IrInstSrcErrToInt *) {
1026 return IrInstructionIdTypeOf;1421 return IrInstSrcIdErrToInt;
1027}1422}
10281423
1029static constexpr IrInstructionId ir_instruction_id(IrInstructionSetCold *) {1424static constexpr IrInstSrcId ir_inst_id(IrInstSrcCheckSwitchProngs *) {
1030 return IrInstructionIdSetCold;1425 return IrInstSrcIdCheckSwitchProngs;
1031}1426}
10321427
1033static constexpr IrInstructionId ir_instruction_id(IrInstructionSetRuntimeSafety *) {1428static constexpr IrInstSrcId ir_inst_id(IrInstSrcCheckStatementIsVoid *) {
1034 return IrInstructionIdSetRuntimeSafety;1429 return IrInstSrcIdCheckStatementIsVoid;
1035}1430}
10361431
1037static constexpr IrInstructionId ir_instruction_id(IrInstructionSetFloatMode *) {1432static constexpr IrInstSrcId ir_inst_id(IrInstSrcTypeName *) {
1038 return IrInstructionIdSetFloatMode;1433 return IrInstSrcIdTypeName;
1039}1434}
10401435
1041static constexpr IrInstructionId ir_instruction_id(IrInstructionArrayType *) {1436static constexpr IrInstSrcId ir_inst_id(IrInstSrcDeclRef *) {
1042 return IrInstructionIdArrayType;1437 return IrInstSrcIdDeclRef;
1043}1438}
10441439
1045static constexpr IrInstructionId ir_instruction_id(IrInstructionAnyFrameType *) {1440static constexpr IrInstSrcId ir_inst_id(IrInstSrcPanic *) {
1046 return IrInstructionIdAnyFrameType;1441 return IrInstSrcIdPanic;
1047}1442}
10481443
1049static constexpr IrInstructionId ir_instruction_id(IrInstructionSliceType *) {1444static constexpr IrInstSrcId ir_inst_id(IrInstSrcTagName *) {
1050 return IrInstructionIdSliceType;1445 return IrInstSrcIdTagName;
1051}1446}
10521447
1053static constexpr IrInstructionId ir_instruction_id(IrInstructionAsmSrc *) {1448static constexpr IrInstSrcId ir_inst_id(IrInstSrcTagType *) {
1054 return IrInstructionIdAsmSrc;1449 return IrInstSrcIdTagType;
1055}1450}
10561451
1057static constexpr IrInstructionId ir_instruction_id(IrInstructionAsmGen *) {1452static constexpr IrInstSrcId ir_inst_id(IrInstSrcFieldParentPtr *) {
1058 return IrInstructionIdAsmGen;1453 return IrInstSrcIdFieldParentPtr;
1059}1454}
10601455
1061static constexpr IrInstructionId ir_instruction_id(IrInstructionSizeOf *) {1456static constexpr IrInstSrcId ir_inst_id(IrInstSrcByteOffsetOf *) {
1062 return IrInstructionIdSizeOf;1457 return IrInstSrcIdByteOffsetOf;
1063}1458}
10641459
1065static constexpr IrInstructionId ir_instruction_id(IrInstructionTestNonNull *) {1460static constexpr IrInstSrcId ir_inst_id(IrInstSrcBitOffsetOf *) {
1066 return IrInstructionIdTestNonNull;1461 return IrInstSrcIdBitOffsetOf;
1067}1462}
10681463
1069static constexpr IrInstructionId ir_instruction_id(IrInstructionOptionalUnwrapPtr *) {1464static constexpr IrInstSrcId ir_inst_id(IrInstSrcTypeInfo *) {
1070 return IrInstructionIdOptionalUnwrapPtr;1465 return IrInstSrcIdTypeInfo;
1071}1466}
10721467
1073static constexpr IrInstructionId ir_instruction_id(IrInstructionClz *) {1468static constexpr IrInstSrcId ir_inst_id(IrInstSrcType *) {
1074 return IrInstructionIdClz;1469 return IrInstSrcIdType;
1075}1470}
10761471
1077static constexpr IrInstructionId ir_instruction_id(IrInstructionCtz *) {1472static constexpr IrInstSrcId ir_inst_id(IrInstSrcHasField *) {
1078 return IrInstructionIdCtz;1473 return IrInstSrcIdHasField;
1079}1474}
10801475
1081static constexpr IrInstructionId ir_instruction_id(IrInstructionPopCount *) {1476static constexpr IrInstSrcId ir_inst_id(IrInstSrcTypeId *) {
1082 return IrInstructionIdPopCount;1477 return IrInstSrcIdTypeId;
1083}1478}
10841479
1085static constexpr IrInstructionId ir_instruction_id(IrInstructionBswap *) {1480static constexpr IrInstSrcId ir_inst_id(IrInstSrcSetEvalBranchQuota *) {
1086 return IrInstructionIdBswap;1481 return IrInstSrcIdSetEvalBranchQuota;
1087}1482}
10881483
1089static constexpr IrInstructionId ir_instruction_id(IrInstructionBitReverse *) {1484static constexpr IrInstSrcId ir_inst_id(IrInstSrcPtrType *) {
1090 return IrInstructionIdBitReverse;1485 return IrInstSrcIdPtrType;
1091}1486}
10921487
1093static constexpr IrInstructionId ir_instruction_id(IrInstructionUnionTag *) {1488static constexpr IrInstSrcId ir_inst_id(IrInstSrcAlignCast *) {
1094 return IrInstructionIdUnionTag;1489 return IrInstSrcIdAlignCast;
1095}1490}
10961491
1097static constexpr IrInstructionId ir_instruction_id(IrInstructionImport *) {1492static constexpr IrInstSrcId ir_inst_id(IrInstSrcImplicitCast *) {
1098 return IrInstructionIdImport;1493 return IrInstSrcIdImplicitCast;
1099}1494}
11001495
1101static constexpr IrInstructionId ir_instruction_id(IrInstructionCImport *) {1496static constexpr IrInstSrcId ir_inst_id(IrInstSrcResolveResult *) {
1102 return IrInstructionIdCImport;1497 return IrInstSrcIdResolveResult;
1103}1498}
11041499
1105static constexpr IrInstructionId ir_instruction_id(IrInstructionCInclude *) {1500static constexpr IrInstSrcId ir_inst_id(IrInstSrcResetResult *) {
1106 return IrInstructionIdCInclude;1501 return IrInstSrcIdResetResult;
1107}1502}
11081503
1109static constexpr IrInstructionId ir_instruction_id(IrInstructionCDefine *) {1504static constexpr IrInstSrcId ir_inst_id(IrInstSrcOpaqueType *) {
1110 return IrInstructionIdCDefine;1505 return IrInstSrcIdOpaqueType;
1111}1506}
11121507
1113static constexpr IrInstructionId ir_instruction_id(IrInstructionCUndef *) {1508static constexpr IrInstSrcId ir_inst_id(IrInstSrcSetAlignStack *) {
1114 return IrInstructionIdCUndef;1509 return IrInstSrcIdSetAlignStack;
1115}1510}
11161511
1117static constexpr IrInstructionId ir_instruction_id(IrInstructionRef *) {1512static constexpr IrInstSrcId ir_inst_id(IrInstSrcArgType *) {
1118 return IrInstructionIdRef;1513 return IrInstSrcIdArgType;
1119}1514}
11201515
1121static constexpr IrInstructionId ir_instruction_id(IrInstructionRefGen *) {1516static constexpr IrInstSrcId ir_inst_id(IrInstSrcExport *) {
1122 return IrInstructionIdRefGen;1517 return IrInstSrcIdExport;
1123}1518}
11241519
1125static constexpr IrInstructionId ir_instruction_id(IrInstructionCompileErr *) {1520static constexpr IrInstSrcId ir_inst_id(IrInstSrcErrorReturnTrace *) {
1126 return IrInstructionIdCompileErr;1521 return IrInstSrcIdErrorReturnTrace;
1127}1522}
11281523
1129static constexpr IrInstructionId ir_instruction_id(IrInstructionCompileLog *) {1524static constexpr IrInstSrcId ir_inst_id(IrInstSrcErrorUnion *) {
1130 return IrInstructionIdCompileLog;1525 return IrInstSrcIdErrorUnion;
1131}1526}
11321527
1133static constexpr IrInstructionId ir_instruction_id(IrInstructionErrName *) {1528static constexpr IrInstSrcId ir_inst_id(IrInstSrcAtomicRmw *) {
1134 return IrInstructionIdErrName;1529 return IrInstSrcIdAtomicRmw;
1135}1530}
11361531
1137static constexpr IrInstructionId ir_instruction_id(IrInstructionEmbedFile *) {1532static constexpr IrInstSrcId ir_inst_id(IrInstSrcAtomicLoad *) {
1138 return IrInstructionIdEmbedFile;1533 return IrInstSrcIdAtomicLoad;
1139}1534}
11401535
1141static constexpr IrInstructionId ir_instruction_id(IrInstructionCmpxchgSrc *) {1536static constexpr IrInstSrcId ir_inst_id(IrInstSrcAtomicStore *) {
1142 return IrInstructionIdCmpxchgSrc;1537 return IrInstSrcIdAtomicStore;
1143}1538}
11441539
1145static constexpr IrInstructionId ir_instruction_id(IrInstructionCmpxchgGen *) {1540static constexpr IrInstSrcId ir_inst_id(IrInstSrcSaveErrRetAddr *) {
1146 return IrInstructionIdCmpxchgGen;1541 return IrInstSrcIdSaveErrRetAddr;
1147}1542}
11481543
1149static constexpr IrInstructionId ir_instruction_id(IrInstructionFence *) {1544static constexpr IrInstSrcId ir_inst_id(IrInstSrcAddImplicitReturnType *) {
1150 return IrInstructionIdFence;1545 return IrInstSrcIdAddImplicitReturnType;
1151}1546}
11521547
1153static constexpr IrInstructionId ir_instruction_id(IrInstructionTruncate *) {1548static constexpr IrInstSrcId ir_inst_id(IrInstSrcErrSetCast *) {
1154 return IrInstructionIdTruncate;1549 return IrInstSrcIdErrSetCast;
1155}1550}
11561551
1157static constexpr IrInstructionId ir_instruction_id(IrInstructionIntCast *) {1552static constexpr IrInstSrcId ir_inst_id(IrInstSrcToBytes *) {
1158 return IrInstructionIdIntCast;1553 return IrInstSrcIdToBytes;
1159}1554}
11601555
1161static constexpr IrInstructionId ir_instruction_id(IrInstructionFloatCast *) {1556static constexpr IrInstSrcId ir_inst_id(IrInstSrcFromBytes *) {
1162 return IrInstructionIdFloatCast;1557 return IrInstSrcIdFromBytes;
1163}1558}
11641559
1165static constexpr IrInstructionId ir_instruction_id(IrInstructionErrSetCast *) {1560static constexpr IrInstSrcId ir_inst_id(IrInstSrcCheckRuntimeScope *) {
1166 return IrInstructionIdErrSetCast;1561 return IrInstSrcIdCheckRuntimeScope;
1167}1562}
11681563
1169static constexpr IrInstructionId ir_instruction_id(IrInstructionToBytes *) {1564static constexpr IrInstSrcId ir_inst_id(IrInstSrcHasDecl *) {
1170 return IrInstructionIdToBytes;1565 return IrInstSrcIdHasDecl;
1171}1566}
11721567
1173static constexpr IrInstructionId ir_instruction_id(IrInstructionFromBytes *) {1568static constexpr IrInstSrcId ir_inst_id(IrInstSrcUndeclaredIdent *) {
1174 return IrInstructionIdFromBytes;1569 return IrInstSrcIdUndeclaredIdent;
1175}1570}
11761571
1177static constexpr IrInstructionId ir_instruction_id(IrInstructionIntToFloat *) {1572static constexpr IrInstSrcId ir_inst_id(IrInstSrcAlloca *) {
1178 return IrInstructionIdIntToFloat;1573 return IrInstSrcIdAlloca;
1179}1574}
11801575
1181static constexpr IrInstructionId ir_instruction_id(IrInstructionFloatToInt *) {1576static constexpr IrInstSrcId ir_inst_id(IrInstSrcEndExpr *) {
1182 return IrInstructionIdFloatToInt;1577 return IrInstSrcIdEndExpr;
1183}1578}
11841579
1185static constexpr IrInstructionId ir_instruction_id(IrInstructionBoolToInt *) {1580static constexpr IrInstSrcId ir_inst_id(IrInstSrcUnionInitNamedField *) {
1186 return IrInstructionIdBoolToInt;1581 return IrInstSrcIdUnionInitNamedField;
1187}1582}
11881583
1189static constexpr IrInstructionId ir_instruction_id(IrInstructionIntType *) {1584static constexpr IrInstSrcId ir_inst_id(IrInstSrcSuspendBegin *) {
1190 return IrInstructionIdIntType;1585 return IrInstSrcIdSuspendBegin;
1191}1586}
11921587
1193static constexpr IrInstructionId ir_instruction_id(IrInstructionVectorType *) {1588static constexpr IrInstSrcId ir_inst_id(IrInstSrcSuspendFinish *) {
1194 return IrInstructionIdVectorType;1589 return IrInstSrcIdSuspendFinish;
1195}1590}
11961591
1197static constexpr IrInstructionId ir_instruction_id(IrInstructionShuffleVector *) {1592static constexpr IrInstSrcId ir_inst_id(IrInstSrcAwait *) {
1198 return IrInstructionIdShuffleVector;1593 return IrInstSrcIdAwait;
1199}1594}
12001595
1201static constexpr IrInstructionId ir_instruction_id(IrInstructionSplatSrc *) {1596static constexpr IrInstSrcId ir_inst_id(IrInstSrcResume *) {
1202 return IrInstructionIdSplatSrc;1597 return IrInstSrcIdResume;
1203}1598}
12041599
1205static constexpr IrInstructionId ir_instruction_id(IrInstructionSplatGen *) {1600static constexpr IrInstSrcId ir_inst_id(IrInstSrcSpillBegin *) {
1206 return IrInstructionIdSplatGen;1601 return IrInstSrcIdSpillBegin;
1207}1602}
12081603
1209static constexpr IrInstructionId ir_instruction_id(IrInstructionBoolNot *) {1604static constexpr IrInstSrcId ir_inst_id(IrInstSrcSpillEnd *) {
1210 return IrInstructionIdBoolNot;1605 return IrInstSrcIdSpillEnd;
1211}1606}
12121607
1213static constexpr IrInstructionId ir_instruction_id(IrInstructionMemset *) {1608
1214 return IrInstructionIdMemset;1609static constexpr IrInstGenId ir_inst_id(IrInstGenDeclVar *) {
1610 return IrInstGenIdDeclVar;
1215}1611}
12161612
1217static constexpr IrInstructionId ir_instruction_id(IrInstructionMemcpy *) {1613static constexpr IrInstGenId ir_inst_id(IrInstGenBr *) {
1218 return IrInstructionIdMemcpy;1614 return IrInstGenIdBr;
1219}1615}
12201616
1221static constexpr IrInstructionId ir_instruction_id(IrInstructionSliceSrc *) {1617static constexpr IrInstGenId ir_inst_id(IrInstGenCondBr *) {
1222 return IrInstructionIdSliceSrc;1618 return IrInstGenIdCondBr;
1223}1619}
12241620
1225static constexpr IrInstructionId ir_instruction_id(IrInstructionSliceGen *) {1621static constexpr IrInstGenId ir_inst_id(IrInstGenSwitchBr *) {
1226 return IrInstructionIdSliceGen;1622 return IrInstGenIdSwitchBr;
1227}1623}
12281624
1229static constexpr IrInstructionId ir_instruction_id(IrInstructionMemberCount *) {1625static constexpr IrInstGenId ir_inst_id(IrInstGenPhi *) {
1230 return IrInstructionIdMemberCount;1626 return IrInstGenIdPhi;
1231}1627}
12321628
1233static constexpr IrInstructionId ir_instruction_id(IrInstructionMemberType *) {1629static constexpr IrInstGenId ir_inst_id(IrInstGenBinaryNot *) {
1234 return IrInstructionIdMemberType;1630 return IrInstGenIdBinaryNot;
1235}1631}
12361632
1237static constexpr IrInstructionId ir_instruction_id(IrInstructionMemberName *) {1633static constexpr IrInstGenId ir_inst_id(IrInstGenNegation *) {
1238 return IrInstructionIdMemberName;1634 return IrInstGenIdNegation;
1239}1635}
12401636
1241static constexpr IrInstructionId ir_instruction_id(IrInstructionBreakpoint *) {1637static constexpr IrInstGenId ir_inst_id(IrInstGenNegationWrapping *) {
1242 return IrInstructionIdBreakpoint;1638 return IrInstGenIdNegationWrapping;
1243}1639}
12441640
1245static constexpr IrInstructionId ir_instruction_id(IrInstructionReturnAddress *) {1641static constexpr IrInstGenId ir_inst_id(IrInstGenBinOp *) {
1246 return IrInstructionIdReturnAddress;1642 return IrInstGenIdBinOp;
1247}1643}
12481644
1249static constexpr IrInstructionId ir_instruction_id(IrInstructionFrameAddress *) {1645static constexpr IrInstGenId ir_inst_id(IrInstGenLoadPtr *) {
1250 return IrInstructionIdFrameAddress;1646 return IrInstGenIdLoadPtr;
1251}1647}
12521648
1253static constexpr IrInstructionId ir_instruction_id(IrInstructionFrameHandle *) {1649static constexpr IrInstGenId ir_inst_id(IrInstGenStorePtr *) {
1254 return IrInstructionIdFrameHandle;1650 return IrInstGenIdStorePtr;
1255}1651}
12561652
1257static constexpr IrInstructionId ir_instruction_id(IrInstructionFrameType *) {1653static constexpr IrInstGenId ir_inst_id(IrInstGenVectorStoreElem *) {
1258 return IrInstructionIdFrameType;1654 return IrInstGenIdVectorStoreElem;
1259}1655}
12601656
1261static constexpr IrInstructionId ir_instruction_id(IrInstructionFrameSizeSrc *) {1657static constexpr IrInstGenId ir_inst_id(IrInstGenStructFieldPtr *) {
1262 return IrInstructionIdFrameSizeSrc;1658 return IrInstGenIdStructFieldPtr;
1263}1659}
12641660
1265static constexpr IrInstructionId ir_instruction_id(IrInstructionFrameSizeGen *) {1661static constexpr IrInstGenId ir_inst_id(IrInstGenUnionFieldPtr *) {
1266 return IrInstructionIdFrameSizeGen;1662 return IrInstGenIdUnionFieldPtr;
1267}1663}
12681664
1269static constexpr IrInstructionId ir_instruction_id(IrInstructionAlignOf *) {1665static constexpr IrInstGenId ir_inst_id(IrInstGenElemPtr *) {
1270 return IrInstructionIdAlignOf;1666 return IrInstGenIdElemPtr;
1271}1667}
12721668
1273static constexpr IrInstructionId ir_instruction_id(IrInstructionOverflowOp *) {1669static constexpr IrInstGenId ir_inst_id(IrInstGenVarPtr *) {
1274 return IrInstructionIdOverflowOp;1670 return IrInstGenIdVarPtr;
1275}1671}
12761672
1277static constexpr IrInstructionId ir_instruction_id(IrInstructionTestErrSrc *) {1673static constexpr IrInstGenId ir_inst_id(IrInstGenReturnPtr *) {
1278 return IrInstructionIdTestErrSrc;1674 return IrInstGenIdReturnPtr;
1279}1675}
12801676
1281static constexpr IrInstructionId ir_instruction_id(IrInstructionTestErrGen *) {1677static constexpr IrInstGenId ir_inst_id(IrInstGenCall *) {
1282 return IrInstructionIdTestErrGen;1678 return IrInstGenIdCall;
1283}1679}
12841680
1285static constexpr IrInstructionId ir_instruction_id(IrInstructionMulAdd *) {1681static constexpr IrInstGenId ir_inst_id(IrInstGenReturn *) {
1286 return IrInstructionIdMulAdd;1682 return IrInstGenIdReturn;
1287}1683}
12881684
1289static constexpr IrInstructionId ir_instruction_id(IrInstructionUnwrapErrCode *) {1685static constexpr IrInstGenId ir_inst_id(IrInstGenCast *) {
1290 return IrInstructionIdUnwrapErrCode;1686 return IrInstGenIdCast;
1291}1687}
12921688
1293static constexpr IrInstructionId ir_instruction_id(IrInstructionUnwrapErrPayload *) {1689static constexpr IrInstGenId ir_inst_id(IrInstGenResizeSlice *) {
1294 return IrInstructionIdUnwrapErrPayload;1690 return IrInstGenIdResizeSlice;
1295}1691}
12961692
1297static constexpr IrInstructionId ir_instruction_id(IrInstructionOptionalWrap *) {1693static constexpr IrInstGenId ir_inst_id(IrInstGenUnreachable *) {
1298 return IrInstructionIdOptionalWrap;1694 return IrInstGenIdUnreachable;
1299}1695}
13001696
1301static constexpr IrInstructionId ir_instruction_id(IrInstructionErrWrapPayload *) {1697static constexpr IrInstGenId ir_inst_id(IrInstGenAsm *) {
1302 return IrInstructionIdErrWrapPayload;1698 return IrInstGenIdAsm;
1303}1699}
13041700
1305static constexpr IrInstructionId ir_instruction_id(IrInstructionErrWrapCode *) {1701static constexpr IrInstGenId ir_inst_id(IrInstGenTestNonNull *) {
1306 return IrInstructionIdErrWrapCode;1702 return IrInstGenIdTestNonNull;
1307}1703}
13081704
1309static constexpr IrInstructionId ir_instruction_id(IrInstructionFnProto *) {1705static constexpr IrInstGenId ir_inst_id(IrInstGenOptionalUnwrapPtr *) {
1310 return IrInstructionIdFnProto;1706 return IrInstGenIdOptionalUnwrapPtr;
1311}1707}
13121708
1313static constexpr IrInstructionId ir_instruction_id(IrInstructionTestComptime *) {1709static constexpr IrInstGenId ir_inst_id(IrInstGenOptionalWrap *) {
1314 return IrInstructionIdTestComptime;1710 return IrInstGenIdOptionalWrap;
1315}1711}
13161712
1317static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrCastSrc *) {1713static constexpr IrInstGenId ir_inst_id(IrInstGenUnionTag *) {
1318 return IrInstructionIdPtrCastSrc;1714 return IrInstGenIdUnionTag;
1319}1715}
13201716
1321static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrCastGen *) {1717static constexpr IrInstGenId ir_inst_id(IrInstGenClz *) {
1322 return IrInstructionIdPtrCastGen;1718 return IrInstGenIdClz;
1323}1719}
13241720
1325static constexpr IrInstructionId ir_instruction_id(IrInstructionBitCastSrc *) {1721static constexpr IrInstGenId ir_inst_id(IrInstGenCtz *) {
1326 return IrInstructionIdBitCastSrc;1722 return IrInstGenIdCtz;
1327}1723}
13281724
1329static constexpr IrInstructionId ir_instruction_id(IrInstructionBitCastGen *) {1725static constexpr IrInstGenId ir_inst_id(IrInstGenPopCount *) {
1330 return IrInstructionIdBitCastGen;1726 return IrInstGenIdPopCount;
1331}1727}
13321728
1333static constexpr IrInstructionId ir_instruction_id(IrInstructionWidenOrShorten *) {1729static constexpr IrInstGenId ir_inst_id(IrInstGenBswap *) {
1334 return IrInstructionIdWidenOrShorten;1730 return IrInstGenIdBswap;
1335}1731}
13361732
1337static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrToInt *) {1733static constexpr IrInstGenId ir_inst_id(IrInstGenBitReverse *) {
1338 return IrInstructionIdPtrToInt;1734 return IrInstGenIdBitReverse;
1339}1735}
13401736
1341static constexpr IrInstructionId ir_instruction_id(IrInstructionIntToPtr *) {1737static constexpr IrInstGenId ir_inst_id(IrInstGenRef *) {
1342 return IrInstructionIdIntToPtr;1738 return IrInstGenIdRef;
1343}1739}
13441740
1345static constexpr IrInstructionId ir_instruction_id(IrInstructionIntToEnum *) {1741static constexpr IrInstGenId ir_inst_id(IrInstGenErrName *) {
1346 return IrInstructionIdIntToEnum;1742 return IrInstGenIdErrName;
1347}1743}
13481744
1349static constexpr IrInstructionId ir_instruction_id(IrInstructionEnumToInt *) {1745static constexpr IrInstGenId ir_inst_id(IrInstGenCmpxchg *) {
1350 return IrInstructionIdEnumToInt;1746 return IrInstGenIdCmpxchg;
1351}1747}
13521748
1353static constexpr IrInstructionId ir_instruction_id(IrInstructionIntToErr *) {1749static constexpr IrInstGenId ir_inst_id(IrInstGenFence *) {
1354 return IrInstructionIdIntToErr;1750 return IrInstGenIdFence;
1355}1751}
13561752
1357static constexpr IrInstructionId ir_instruction_id(IrInstructionErrToInt *) {1753static constexpr IrInstGenId ir_inst_id(IrInstGenTruncate *) {
1358 return IrInstructionIdErrToInt;1754 return IrInstGenIdTruncate;
1359}1755}
13601756
1361static constexpr IrInstructionId ir_instruction_id(IrInstructionCheckSwitchProngs *) {1757static constexpr IrInstGenId ir_inst_id(IrInstGenShuffleVector *) {
1362 return IrInstructionIdCheckSwitchProngs;1758 return IrInstGenIdShuffleVector;
1363}1759}
13641760
1365static constexpr IrInstructionId ir_instruction_id(IrInstructionCheckStatementIsVoid *) {1761static constexpr IrInstGenId ir_inst_id(IrInstGenSplat *) {
1366 return IrInstructionIdCheckStatementIsVoid;1762 return IrInstGenIdSplat;
1367}1763}
13681764
1369static constexpr IrInstructionId ir_instruction_id(IrInstructionTypeName *) {1765static constexpr IrInstGenId ir_inst_id(IrInstGenBoolNot *) {
1370 return IrInstructionIdTypeName;1766 return IrInstGenIdBoolNot;
1371}1767}
13721768
1373static constexpr IrInstructionId ir_instruction_id(IrInstructionDeclRef *) {1769static constexpr IrInstGenId ir_inst_id(IrInstGenMemset *) {
1374 return IrInstructionIdDeclRef;1770 return IrInstGenIdMemset;
1375}1771}
13761772
1377static constexpr IrInstructionId ir_instruction_id(IrInstructionPanic *) {1773static constexpr IrInstGenId ir_inst_id(IrInstGenMemcpy *) {
1378 return IrInstructionIdPanic;1774 return IrInstGenIdMemcpy;
1379}1775}
13801776
1381static constexpr IrInstructionId ir_instruction_id(IrInstructionTagName *) {1777static constexpr IrInstGenId ir_inst_id(IrInstGenSlice *) {
1382 return IrInstructionIdTagName;1778 return IrInstGenIdSlice;
1383}1779}
13841780
1385static constexpr IrInstructionId ir_instruction_id(IrInstructionTagType *) {1781static constexpr IrInstGenId ir_inst_id(IrInstGenBreakpoint *) {
1386 return IrInstructionIdTagType;1782 return IrInstGenIdBreakpoint;
1387}1783}
13881784
1389static constexpr IrInstructionId ir_instruction_id(IrInstructionFieldParentPtr *) {1785static constexpr IrInstGenId ir_inst_id(IrInstGenReturnAddress *) {
1390 return IrInstructionIdFieldParentPtr;1786 return IrInstGenIdReturnAddress;
1391}1787}
13921788
1393static constexpr IrInstructionId ir_instruction_id(IrInstructionByteOffsetOf *) {1789static constexpr IrInstGenId ir_inst_id(IrInstGenFrameAddress *) {
1394 return IrInstructionIdByteOffsetOf;1790 return IrInstGenIdFrameAddress;
1395}1791}
13961792
1397static constexpr IrInstructionId ir_instruction_id(IrInstructionBitOffsetOf *) {1793static constexpr IrInstGenId ir_inst_id(IrInstGenFrameHandle *) {
1398 return IrInstructionIdBitOffsetOf;1794 return IrInstGenIdFrameHandle;
1399}1795}
14001796
1401static constexpr IrInstructionId ir_instruction_id(IrInstructionTypeInfo *) {1797static constexpr IrInstGenId ir_inst_id(IrInstGenFrameSize *) {
1402 return IrInstructionIdTypeInfo;1798 return IrInstGenIdFrameSize;
1403}1799}
14041800
1405static constexpr IrInstructionId ir_instruction_id(IrInstructionType *) {1801static constexpr IrInstGenId ir_inst_id(IrInstGenOverflowOp *) {
1406 return IrInstructionIdType;1802 return IrInstGenIdOverflowOp;
1407}1803}
14081804
1409static constexpr IrInstructionId ir_instruction_id(IrInstructionHasField *) {1805static constexpr IrInstGenId ir_inst_id(IrInstGenTestErr *) {
1410 return IrInstructionIdHasField;1806 return IrInstGenIdTestErr;
1411}1807}
14121808
1413static constexpr IrInstructionId ir_instruction_id(IrInstructionTypeId *) {1809static constexpr IrInstGenId ir_inst_id(IrInstGenMulAdd *) {
1414 return IrInstructionIdTypeId;1810 return IrInstGenIdMulAdd;
1415}1811}
14161812
1417static constexpr IrInstructionId ir_instruction_id(IrInstructionSetEvalBranchQuota *) {1813static constexpr IrInstGenId ir_inst_id(IrInstGenFloatOp *) {
1418 return IrInstructionIdSetEvalBranchQuota;1814 return IrInstGenIdFloatOp;
1419}1815}
14201816
1421static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrType *) {1817static constexpr IrInstGenId ir_inst_id(IrInstGenUnwrapErrCode *) {
1422 return IrInstructionIdPtrType;1818 return IrInstGenIdUnwrapErrCode;
1423}1819}
14241820
1425static constexpr IrInstructionId ir_instruction_id(IrInstructionAlignCast *) {1821static constexpr IrInstGenId ir_inst_id(IrInstGenUnwrapErrPayload *) {
1426 return IrInstructionIdAlignCast;1822 return IrInstGenIdUnwrapErrPayload;
1427}1823}
14281824
1429static constexpr IrInstructionId ir_instruction_id(IrInstructionImplicitCast *) {1825static constexpr IrInstGenId ir_inst_id(IrInstGenErrWrapCode *) {
1430 return IrInstructionIdImplicitCast;1826 return IrInstGenIdErrWrapCode;
1431}1827}
14321828
1433static constexpr IrInstructionId ir_instruction_id(IrInstructionResolveResult *) {1829static constexpr IrInstGenId ir_inst_id(IrInstGenErrWrapPayload *) {
1434 return IrInstructionIdResolveResult;1830 return IrInstGenIdErrWrapPayload;
1435}1831}
14361832
1437static constexpr IrInstructionId ir_instruction_id(IrInstructionResetResult *) {1833static constexpr IrInstGenId ir_inst_id(IrInstGenPtrCast *) {
1438 return IrInstructionIdResetResult;1834 return IrInstGenIdPtrCast;
1439}1835}
14401836
1441static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrOfArrayToSlice *) {1837static constexpr IrInstGenId ir_inst_id(IrInstGenBitCast *) {
1442 return IrInstructionIdPtrOfArrayToSlice;1838 return IrInstGenIdBitCast;
1443}1839}
14441840
1445static constexpr IrInstructionId ir_instruction_id(IrInstructionOpaqueType *) {1841static constexpr IrInstGenId ir_inst_id(IrInstGenWidenOrShorten *) {
1446 return IrInstructionIdOpaqueType;1842 return IrInstGenIdWidenOrShorten;
1447}1843}
14481844
1449static constexpr IrInstructionId ir_instruction_id(IrInstructionSetAlignStack *) {1845static constexpr IrInstGenId ir_inst_id(IrInstGenIntToPtr *) {
1450 return IrInstructionIdSetAlignStack;1846 return IrInstGenIdIntToPtr;
1451}1847}
14521848
1453static constexpr IrInstructionId ir_instruction_id(IrInstructionArgType *) {1849static constexpr IrInstGenId ir_inst_id(IrInstGenPtrToInt *) {
1454 return IrInstructionIdArgType;1850 return IrInstGenIdPtrToInt;
1455}1851}
14561852
1457static constexpr IrInstructionId ir_instruction_id(IrInstructionErrorReturnTrace *) {1853static constexpr IrInstGenId ir_inst_id(IrInstGenIntToEnum *) {
1458 return IrInstructionIdErrorReturnTrace;1854 return IrInstGenIdIntToEnum;
1459}1855}
14601856
1461static constexpr IrInstructionId ir_instruction_id(IrInstructionErrorUnion *) {1857static constexpr IrInstGenId ir_inst_id(IrInstGenIntToErr *) {
1462 return IrInstructionIdErrorUnion;1858 return IrInstGenIdIntToErr;
1463}1859}
14641860
1465static constexpr IrInstructionId ir_instruction_id(IrInstructionAtomicRmw *) {1861static constexpr IrInstGenId ir_inst_id(IrInstGenErrToInt *) {
1466 return IrInstructionIdAtomicRmw;1862 return IrInstGenIdErrToInt;
1467}1863}
14681864
1469static constexpr IrInstructionId ir_instruction_id(IrInstructionAtomicLoad *) {1865static constexpr IrInstGenId ir_inst_id(IrInstGenPanic *) {
1470 return IrInstructionIdAtomicLoad;1866 return IrInstGenIdPanic;
1471}1867}
14721868
1473static constexpr IrInstructionId ir_instruction_id(IrInstructionAtomicStore *) {1869static constexpr IrInstGenId ir_inst_id(IrInstGenTagName *) {
1474 return IrInstructionIdAtomicStore;1870 return IrInstGenIdTagName;
1475}1871}
14761872
1477static constexpr IrInstructionId ir_instruction_id(IrInstructionSaveErrRetAddr *) {1873static constexpr IrInstGenId ir_inst_id(IrInstGenFieldParentPtr *) {
1478 return IrInstructionIdSaveErrRetAddr;1874 return IrInstGenIdFieldParentPtr;
1479}1875}
14801876
1481static constexpr IrInstructionId ir_instruction_id(IrInstructionAddImplicitReturnType *) {1877static constexpr IrInstGenId ir_inst_id(IrInstGenAlignCast *) {
1482 return IrInstructionIdAddImplicitReturnType;1878 return IrInstGenIdAlignCast;
1483}1879}
14841880
1485static constexpr IrInstructionId ir_instruction_id(IrInstructionFloatOp *) {1881static constexpr IrInstGenId ir_inst_id(IrInstGenErrorReturnTrace *) {
1486 return IrInstructionIdFloatOp;1882 return IrInstGenIdErrorReturnTrace;
1487}1883}
14881884
1489static constexpr IrInstructionId ir_instruction_id(IrInstructionCheckRuntimeScope *) {1885static constexpr IrInstGenId ir_inst_id(IrInstGenAtomicRmw *) {
1490 return IrInstructionIdCheckRuntimeScope;1886 return IrInstGenIdAtomicRmw;
1491}1887}
14921888
1493static constexpr IrInstructionId ir_instruction_id(IrInstructionVectorToArray *) {1889static constexpr IrInstGenId ir_inst_id(IrInstGenAtomicLoad *) {
1494 return IrInstructionIdVectorToArray;1890 return IrInstGenIdAtomicLoad;
1495}1891}
14961892
1497static constexpr IrInstructionId ir_instruction_id(IrInstructionArrayToVector *) {1893static constexpr IrInstGenId ir_inst_id(IrInstGenAtomicStore *) {
1498 return IrInstructionIdArrayToVector;1894 return IrInstGenIdAtomicStore;
1499}1895}
15001896
1501static constexpr IrInstructionId ir_instruction_id(IrInstructionAssertZero *) {1897static constexpr IrInstGenId ir_inst_id(IrInstGenSaveErrRetAddr *) {
1502 return IrInstructionIdAssertZero;1898 return IrInstGenIdSaveErrRetAddr;
1503}1899}
15041900
1505static constexpr IrInstructionId ir_instruction_id(IrInstructionAssertNonNull *) {1901static constexpr IrInstGenId ir_inst_id(IrInstGenVectorToArray *) {
1506 return IrInstructionIdAssertNonNull;1902 return IrInstGenIdVectorToArray;
1507}1903}
15081904
1509static constexpr IrInstructionId ir_instruction_id(IrInstructionHasDecl *) {1905static constexpr IrInstGenId ir_inst_id(IrInstGenArrayToVector *) {
1510 return IrInstructionIdHasDecl;1906 return IrInstGenIdArrayToVector;
1511}1907}
15121908
1513static constexpr IrInstructionId ir_instruction_id(IrInstructionUndeclaredIdent *) {1909static constexpr IrInstGenId ir_inst_id(IrInstGenAssertZero *) {
1514 return IrInstructionIdUndeclaredIdent;1910 return IrInstGenIdAssertZero;
1515}1911}
15161912
1517static constexpr IrInstructionId ir_instruction_id(IrInstructionAllocaSrc *) {1913static constexpr IrInstGenId ir_inst_id(IrInstGenAssertNonNull *) {
1518 return IrInstructionIdAllocaSrc;1914 return IrInstGenIdAssertNonNull;
1519}1915}
15201916
1521static constexpr IrInstructionId ir_instruction_id(IrInstructionAllocaGen *) {1917static constexpr IrInstGenId ir_inst_id(IrInstGenPtrOfArrayToSlice *) {
1522 return IrInstructionIdAllocaGen;1918 return IrInstGenIdPtrOfArrayToSlice;
1523}1919}
15241920
1525static constexpr IrInstructionId ir_instruction_id(IrInstructionEndExpr *) {1921static constexpr IrInstGenId ir_inst_id(IrInstGenSuspendBegin *) {
1526 return IrInstructionIdEndExpr;1922 return IrInstGenIdSuspendBegin;
1527}1923}
15281924
1529static constexpr IrInstructionId ir_instruction_id(IrInstructionUnionInitNamedField *) {1925static constexpr IrInstGenId ir_inst_id(IrInstGenSuspendFinish *) {
1530 return IrInstructionIdUnionInitNamedField;1926 return IrInstGenIdSuspendFinish;
1531}1927}
15321928
1533static constexpr IrInstructionId ir_instruction_id(IrInstructionSuspendBegin *) {1929static constexpr IrInstGenId ir_inst_id(IrInstGenAwait *) {
1534 return IrInstructionIdSuspendBegin;1930 return IrInstGenIdAwait;
1535}1931}
15361932
1537static constexpr IrInstructionId ir_instruction_id(IrInstructionSuspendFinish *) {1933static constexpr IrInstGenId ir_inst_id(IrInstGenResume *) {
1538 return IrInstructionIdSuspendFinish;1934 return IrInstGenIdResume;
1539}1935}
15401936
1541static constexpr IrInstructionId ir_instruction_id(IrInstructionAwaitSrc *) {1937static constexpr IrInstGenId ir_inst_id(IrInstGenSpillBegin *) {
1542 return IrInstructionIdAwaitSrc;1938 return IrInstGenIdSpillBegin;
1543}1939}
15441940
1545static constexpr IrInstructionId ir_instruction_id(IrInstructionAwaitGen *) {1941static constexpr IrInstGenId ir_inst_id(IrInstGenSpillEnd *) {
1546 return IrInstructionIdAwaitGen;1942 return IrInstGenIdSpillEnd;
1547}1943}
15481944
1549static constexpr IrInstructionId ir_instruction_id(IrInstructionResume *) {1945static constexpr IrInstGenId ir_inst_id(IrInstGenVectorExtractElem *) {
1550 return IrInstructionIdResume;1946 return IrInstGenIdVectorExtractElem;
1551}1947}
15521948
1553static constexpr IrInstructionId ir_instruction_id(IrInstructionSpillBegin *) {1949static constexpr IrInstGenId ir_inst_id(IrInstGenAlloca *) {
1554 return IrInstructionIdSpillBegin;1950 return IrInstGenIdAlloca;
1555}1951}
15561952
1557static constexpr IrInstructionId ir_instruction_id(IrInstructionSpillEnd *) {1953static constexpr IrInstGenId ir_inst_id(IrInstGenConst *) {
1558 return IrInstructionIdSpillEnd;1954 return IrInstGenIdConst;
1559}1955}
15601956
1561static constexpr IrInstructionId ir_instruction_id(IrInstructionVectorExtractElem *) {1957template<typename T>
1562 return IrInstructionIdVectorExtractElem;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;
1563}1971}
15641972
1565template<typename T>1973template<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) {
1567 const char *name = nullptr;1975 const char *name = nullptr;
1568#ifdef ZIG_ENABLE_MEM_PROFILE1976#ifdef ZIG_ENABLE_MEM_PROFILE
1569 T *dummy = nullptr;1977 T *dummy = nullptr;
1570 name = ir_instruction_type_str(ir_instruction_id(dummy));1978 name = ir_inst_gen_type_str(ir_inst_id(dummy));
1571#endif1979#endif
1572 T *special_instruction = allocate<T>(1, name);1980 T *special_instruction = allocate<T>(1, name);
1573 special_instruction->base.id = ir_instruction_id(special_instruction);1981 special_instruction->base.id = ir_inst_id(special_instruction);
1574 special_instruction->base.scope = scope;1982 special_instruction->base.base.scope = scope;
1575 special_instruction->base.source_node = source_node;1983 special_instruction->base.base.source_node = source_node;
1576 special_instruction->base.debug_id = exec_next_debug_id(irb->exec);1984 special_instruction->base.base.debug_id = exec_next_debug_id_gen(irb->exec);
1577 special_instruction->base.owner_bb = irb->current_basic_block;1985 special_instruction->base.owner_bb = irb->current_basic_block;
1578 special_instruction->base.value = allocate<ZigValue>(1, "ZigValue");1986 special_instruction->base.value = allocate<ZigValue>(1, "ZigValue");
1579 return special_instruction;1987 return special_instruction;
1580}1988}
15811989
1582template<typename T>1990template<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) {
1584 const char *name = nullptr;1992 const char *name = nullptr;
1585#ifdef ZIG_ENABLE_MEM_PROFILE1993#ifdef ZIG_ENABLE_MEM_PROFILE
1586 T *dummy = nullptr;1994 T *dummy = nullptr;
1587 name = ir_instruction_type_str(ir_instruction_id(dummy));1995 name = ir_inst_gen_type_str(ir_inst_id(dummy));
1588#endif1996#endif
1589 T *special_instruction = allocate<T>(1, name);1997 T *special_instruction = allocate<T>(1, name);
1590 special_instruction->base.id = ir_instruction_id(special_instruction);1998 special_instruction->base.id = ir_inst_id(special_instruction);
1591 special_instruction->base.scope = scope;1999 special_instruction->base.base.scope = scope;
1592 special_instruction->base.source_node = source_node;2000 special_instruction->base.base.source_node = source_node;
1593 special_instruction->base.debug_id = exec_next_debug_id(irb->exec);2001 special_instruction->base.base.debug_id = exec_next_debug_id_gen(irb->exec);
1594 special_instruction->base.owner_bb = irb->current_basic_block;2002 special_instruction->base.owner_bb = irb->current_basic_block;
1595 return special_instruction;2003 return special_instruction;
1596}2004}
15972005
1598template<typename T>2006template<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) {
1600 T *special_instruction = ir_create_instruction<T>(irb, scope, source_node);2008 T *special_instruction = ir_create_instruction<T>(irb, scope, source_node);
1601 ir_instruction_append(irb->current_basic_block, &special_instruction->base);2009 ir_instruction_append(irb->current_basic_block, &special_instruction->base);
1602 return special_instruction;2010 return special_instruction;
1603}2011}
16042012
1605static IrInstruction *ir_build_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigType *dest_type,2013template<typename T>
1606 IrInstruction *value, CastOp cast_op)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)
1607{2038{
1608 IrInstructionCast *cast_instruction = ir_build_instruction<IrInstructionCast>(irb, scope, source_node);2039 IrInstGenAlloca *alloca_gen = allocate<IrInstGenAlloca>(1);
1609 cast_instruction->dest_type = dest_type;2040 alloca_gen->base.id = IrInstGenIdAlloca;
1610 cast_instruction->value = value;2041 alloca_gen->base.base.source_node = source_node;
1611 cast_instruction->cast_op = cast_op;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;
1616}2062}
16172063
1618static IrInstruction *ir_build_cond_br(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *condition,2064static IrInstSrc *ir_build_cond_br(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *condition,
1619 IrBasicBlock *then_block, IrBasicBlock *else_block, IrInstruction *is_comptime)2065 IrBasicBlockSrc *then_block, IrBasicBlockSrc *else_block, IrInstSrc *is_comptime)
1620{2066{
1621 IrInstructionCondBr *cond_br_instruction = ir_build_instruction<IrInstructionCondBr>(irb, scope, source_node);2067 IrInstSrcCondBr *inst = ir_build_instruction<IrInstSrcCondBr>(irb, scope, source_node);
1622 cond_br_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;2068 inst->base.is_noreturn = true;
1623 cond_br_instruction->base.value->special = ConstValSpecialStatic;2069 inst->condition = condition;
1624 cond_br_instruction->condition = condition;2070 inst->then_block = then_block;
1625 cond_br_instruction->then_block = then_block;2071 inst->else_block = else_block;
1626 cond_br_instruction->else_block = else_block;2072 inst->is_comptime = is_comptime;
1627 cond_br_instruction->is_comptime = is_comptime;
16282073
1629 ir_ref_instruction(condition, irb->current_basic_block);2074 ir_ref_instruction(condition, irb->current_basic_block);
1630 ir_ref_bb(then_block);2075 ir_ref_bb(then_block);
1631 ir_ref_bb(else_block);2076 ir_ref_bb(else_block);
1632 if (is_comptime != nullptr) ir_ref_instruction(is_comptime, irb->current_basic_block);2077 if (is_comptime != nullptr) ir_ref_instruction(is_comptime, irb->current_basic_block);
16332078
1634 return &cond_br_instruction->base;2079 return &inst->base;
1635}2080}
16362081
1637static IrInstruction *ir_build_return(IrBuilder *irb, Scope *scope, AstNode *source_node,2082static IrInstGen *ir_build_cond_br_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *condition,
1638 IrInstruction *operand)2083 IrBasicBlockGen *then_block, IrBasicBlockGen *else_block)
1639{2084{
1640 IrInstructionReturn *return_instruction = ir_build_instruction<IrInstructionReturn>(irb, scope, source_node);2085 IrInstGenCondBr *inst = ir_build_inst_noreturn<IrInstGenCondBr>(&ira->new_irb, source_instr->scope, source_instr->source_node);
1641 return_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;2086 inst->condition = condition;
1642 return_instruction->base.value->special = ConstValSpecialStatic;2087 inst->then_block = then_block;
1643 return_instruction->operand = operand;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
1645 if (operand != nullptr) ir_ref_instruction(operand, irb->current_basic_block);2102 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;
1648}2115}
16492116
1650static IrInstruction *ir_build_const_void(IrBuilder *irb, Scope *scope, AstNode *source_node) {2117static IrInstSrc *ir_build_const_void(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
1651 IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(irb, scope, source_node);2118 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node);
1652 ir_instruction_append(irb->current_basic_block, &const_instruction->base);2119 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();
1654 return &const_instruction->base;2121 return &const_instruction->base;
1655}2122}
16562123
1657static IrInstruction *ir_build_const_undefined(IrBuilder *irb, Scope *scope, AstNode *source_node) {2124static IrInstSrc *ir_build_const_undefined(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
1658 IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(irb, scope, source_node);2125 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node);
1659 ir_instruction_append(irb->current_basic_block, &const_instruction->base);2126 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();
1661 return &const_instruction->base;2128 return &const_instruction->base;
1662}2129}
16632130
1664static IrInstruction *ir_build_const_uint(IrBuilder *irb, Scope *scope, AstNode *source_node, uint64_t value) {2131static IrInstSrc *ir_build_const_uint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, uint64_t value) {
1665 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);2132 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
1666 const_instruction->base.value->type = irb->codegen->builtin_types.entry_num_lit_int;2133 const_instruction->value = create_const_vals(1);
1667 const_instruction->base.value->special = ConstValSpecialStatic;2134 const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_int;
1668 bigint_init_unsigned(&const_instruction->base.value->data.x_bigint, value);2135 const_instruction->value->special = ConstValSpecialStatic;
2136 bigint_init_unsigned(&const_instruction->value->data.x_bigint, value);
1669 return &const_instruction->base;2137 return &const_instruction->base;
1670}2138}
16712139
1672static IrInstruction *ir_build_const_bigint(IrBuilder *irb, Scope *scope, AstNode *source_node, BigInt *bigint) {2140static IrInstSrc *ir_build_const_bigint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, BigInt *bigint) {
1673 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);2141 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
1674 const_instruction->base.value->type = irb->codegen->builtin_types.entry_num_lit_int;2142 const_instruction->value = create_const_vals(1);
1675 const_instruction->base.value->special = ConstValSpecialStatic;2143 const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_int;
1676 bigint_init_bigint(&const_instruction->base.value->data.x_bigint, bigint);2144 const_instruction->value->special = ConstValSpecialStatic;
2145 bigint_init_bigint(&const_instruction->value->data.x_bigint, bigint);
1677 return &const_instruction->base;2146 return &const_instruction->base;
1678}2147}
16792148
1680static IrInstruction *ir_build_const_bigfloat(IrBuilder *irb, Scope *scope, AstNode *source_node, BigFloat *bigfloat) {2149static IrInstSrc *ir_build_const_bigfloat(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, BigFloat *bigfloat) {
1681 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);2150 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
1682 const_instruction->base.value->type = irb->codegen->builtin_types.entry_num_lit_float;2151 const_instruction->value = create_const_vals(1);
1683 const_instruction->base.value->special = ConstValSpecialStatic;2152 const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_float;
1684 bigfloat_init_bigfloat(&const_instruction->base.value->data.x_bigfloat, bigfloat);2153 const_instruction->value->special = ConstValSpecialStatic;
2154 bigfloat_init_bigfloat(&const_instruction->value->data.x_bigfloat, bigfloat);
1685 return &const_instruction->base;2155 return &const_instruction->base;
1686}2156}
16872157
1688static IrInstruction *ir_build_const_null(IrBuilder *irb, Scope *scope, AstNode *source_node) {2158static IrInstSrc *ir_build_const_null(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
1689 IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(irb, scope, source_node);2159 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node);
1690 ir_instruction_append(irb->current_basic_block, &const_instruction->base);2160 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();
1692 return &const_instruction->base;2162 return &const_instruction->base;
1693}2163}
16942164
1695static IrInstruction *ir_build_const_usize(IrBuilder *irb, Scope *scope, AstNode *source_node, uint64_t value) {2165static IrInstSrc *ir_build_const_usize(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, uint64_t value) {
1696 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);2166 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
1697 const_instruction->base.value->type = irb->codegen->builtin_types.entry_usize;2167 const_instruction->value = create_const_vals(1);
1698 const_instruction->base.value->special = ConstValSpecialStatic;2168 const_instruction->value->type = irb->codegen->builtin_types.entry_usize;
1699 bigint_init_unsigned(&const_instruction->base.value->data.x_bigint, value);2169 const_instruction->value->special = ConstValSpecialStatic;
2170 bigint_init_unsigned(&const_instruction->value->data.x_bigint, value);
1700 return &const_instruction->base;2171 return &const_instruction->base;
1701}2172}
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,
1704 ZigType *type_entry)2175 ZigType *type_entry)
1705{2176{
1706 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);2177 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node);
1707 const_instruction->base.value->type = irb->codegen->builtin_types.entry_type;2178 const_instruction->value = create_const_vals(1);
1708 const_instruction->base.value->special = ConstValSpecialStatic;2179 const_instruction->value->type = irb->codegen->builtin_types.entry_type;
1709 const_instruction->base.value->data.x_type = type_entry;2180 const_instruction->value->special = ConstValSpecialStatic;
2181 const_instruction->value->data.x_type = type_entry;
1710 return &const_instruction->base;2182 return &const_instruction->base;
1711}2183}
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,
1714 ZigType *type_entry)2186 ZigType *type_entry)
1715{2187{
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);
1717 ir_instruction_append(irb->current_basic_block, instruction);2189 ir_instruction_append(irb->current_basic_block, instruction);
1718 return instruction;2190 return instruction;
1719}2191}
17202192
1721static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigFn *fn_entry) {2193static IrInstSrc *ir_build_const_import(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, ZigType *import) {
1722 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);2194 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
1723 const_instruction->base.value->type = fn_entry->type_entry;2195 const_instruction->value = create_const_vals(1);
1724 const_instruction->base.value->special = ConstValSpecialStatic;2196 const_instruction->value->type = irb->codegen->builtin_types.entry_type;
1725 const_instruction->base.value->data.x_ptr.data.fn.fn_entry = fn_entry;2197 const_instruction->value->special = ConstValSpecialStatic;
1726 const_instruction->base.value->data.x_ptr.mut = ConstPtrMutComptimeConst;2198 const_instruction->value->data.x_type = import;
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;
1744 return &const_instruction->base;2199 return &const_instruction->base;
1745}2200}
17462201
1747static IrInstruction *ir_build_const_enum_literal(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *name) {2202static IrInstSrc *ir_build_const_bool(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, bool value) {
1748 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);2203 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
1749 const_instruction->base.value->type = irb->codegen->builtin_types.entry_enum_literal;2204 const_instruction->value = create_const_vals(1);
1750 const_instruction->base.value->special = ConstValSpecialStatic;2205 const_instruction->value->type = irb->codegen->builtin_types.entry_bool;
1751 const_instruction->base.value->data.x_enum_literal = name;2206 const_instruction->value->special = ConstValSpecialStatic;
2207 const_instruction->value->data.x_bool = value;
1752 return &const_instruction->base;2208 return &const_instruction->base;
1753}2209}
17542210
1755static IrInstruction *ir_build_const_bound_fn(IrBuilder *irb, Scope *scope, AstNode *source_node,2211static IrInstSrc *ir_build_const_enum_literal(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *name) {
1756 ZigFn *fn_entry, IrInstruction *first_arg)2212 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
1757{2213 const_instruction->value = create_const_vals(1);
1758 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);2214 const_instruction->value->type = irb->codegen->builtin_types.entry_enum_literal;
1759 const_instruction->base.value->type = get_bound_fn_type(irb->codegen, fn_entry);2215 const_instruction->value->special = ConstValSpecialStatic;
1760 const_instruction->base.value->special = ConstValSpecialStatic;2216 const_instruction->value->data.x_enum_literal = name;
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;
1763 return &const_instruction->base;2217 return &const_instruction->base;
1764}2218}
17652219
1766static IrInstruction *ir_create_const_str_lit(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *str) {2220static IrInstSrc *ir_create_const_str_lit(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *str) {
1767 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);2221 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node);
1768 init_const_str_lit(irb->codegen, const_instruction->base.value, str);2222 const_instruction->value = create_const_vals(1);
2223 init_const_str_lit(irb->codegen, const_instruction->value, str);
17692224
1770 return &const_instruction->base;2225 return &const_instruction->base;
1771}2226}
17722227
1773static IrInstruction *ir_build_const_str_lit(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *str) {2228static IrInstSrc *ir_build_const_str_lit(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *str) {
1774 IrInstruction *instruction = ir_create_const_str_lit(irb, scope, source_node, str);2229 IrInstSrc *instruction = ir_create_const_str_lit(irb, scope, source_node, str);
1775 ir_instruction_append(irb->current_basic_block, instruction);2230 ir_instruction_append(irb->current_basic_block, instruction);
1776 return instruction;2231 return instruction;
1777}2232}
17782233
1779static IrInstruction *ir_build_bin_op(IrBuilder *irb, Scope *scope, AstNode *source_node, IrBinOp op_id,2234static IrInstSrc *ir_build_bin_op(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrBinOp op_id,
1780 IrInstruction *op1, IrInstruction *op2, bool safety_check_on)2235 IrInstSrc *op1, IrInstSrc *op2, bool safety_check_on)
1781{2236{
1782 IrInstructionBinOp *bin_op_instruction = ir_build_instruction<IrInstructionBinOp>(irb, scope, source_node);2237 IrInstSrcBinOp *inst = ir_build_instruction<IrInstSrcBinOp>(irb, scope, source_node);
1783 bin_op_instruction->op_id = op_id;2238 inst->op_id = op_id;
1784 bin_op_instruction->op1 = op1;2239 inst->op1 = op1;
1785 bin_op_instruction->op2 = op2;2240 inst->op2 = op2;
1786 bin_op_instruction->safety_check_on = safety_check_on;2241 inst->safety_check_on = safety_check_on;
17872242
1788 ir_ref_instruction(op1, irb->current_basic_block);2243 ir_ref_instruction(op1, irb->current_basic_block);
1789 ir_ref_instruction(op2, irb->current_basic_block);2244 ir_ref_instruction(op2, irb->current_basic_block);
17902245
1791 return &bin_op_instruction->base;2246 return &inst->base;
1792}2247}
17932248
1794static IrInstruction *ir_build_bin_op_gen(IrAnalyze *ira, IrInstruction *source_instr, ZigType *res_type,2249static IrInstGen *ir_build_bin_op_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *res_type,
1795 IrBinOp op_id, IrInstruction *op1, IrInstruction *op2, bool safety_check_on)2250 IrBinOp op_id, IrInstGen *op1, IrInstGen *op2, bool safety_check_on)
1796{2251{
1797 IrInstructionBinOp *bin_op_instruction = ir_build_instruction<IrInstructionBinOp>(&ira->new_irb,2252 IrInstGenBinOp *inst = ir_build_inst_gen<IrInstGenBinOp>(&ira->new_irb,
1798 source_instr->scope, source_instr->source_node);2253 source_instr->scope, source_instr->source_node);
1799 bin_op_instruction->base.value->type = res_type;2254 inst->base.value->type = res_type;
1800 bin_op_instruction->op_id = op_id;2255 inst->op_id = op_id;
1801 bin_op_instruction->op1 = op1;2256 inst->op1 = op1;
1802 bin_op_instruction->op2 = op2;2257 inst->op2 = op2;
1803 bin_op_instruction->safety_check_on = safety_check_on;2258 inst->safety_check_on = safety_check_on;
18042259
1805 ir_ref_instruction(op1, ira->new_irb.current_basic_block);2260 ir_ref_inst_gen(op1, ira->new_irb.current_basic_block);
1806 ir_ref_instruction(op2, 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;
1809}2264}
18102265
18112266
1812static IrInstruction *ir_build_merge_err_sets(IrBuilder *irb, Scope *scope, AstNode *source_node,2267static IrInstSrc *ir_build_merge_err_sets(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1813 IrInstruction *op1, IrInstruction *op2, Buf *type_name)2268 IrInstSrc *op1, IrInstSrc *op2, Buf *type_name)
1814{2269{
1815 IrInstructionMergeErrSets *merge_err_sets_instruction = ir_build_instruction<IrInstructionMergeErrSets>(irb, scope, source_node);2270 IrInstSrcMergeErrSets *inst = ir_build_instruction<IrInstSrcMergeErrSets>(irb, scope, source_node);
1816 merge_err_sets_instruction->op1 = op1;2271 inst->op1 = op1;
1817 merge_err_sets_instruction->op2 = op2;2272 inst->op2 = op2;
1818 merge_err_sets_instruction->type_name = type_name;2273 inst->type_name = type_name;
18192274
1820 ir_ref_instruction(op1, irb->current_basic_block);2275 ir_ref_instruction(op1, irb->current_basic_block);
1821 ir_ref_instruction(op2, irb->current_basic_block);2276 ir_ref_instruction(op2, irb->current_basic_block);
18222277
1823 return &merge_err_sets_instruction->base;2278 return &inst->base;
1824}2279}
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,
1827 ScopeFnDef *crossed_fndef_scope)2282 ScopeFnDef *crossed_fndef_scope)
1828{2283{
1829 IrInstructionVarPtr *instruction = ir_build_instruction<IrInstructionVarPtr>(irb, scope, source_node);2284 IrInstSrcVarPtr *instruction = ir_build_instruction<IrInstSrcVarPtr>(irb, scope, source_node);
1830 instruction->var = var;2285 instruction->var = var;
1831 instruction->crossed_fndef_scope = crossed_fndef_scope;2286 instruction->crossed_fndef_scope = crossed_fndef_scope;
18322287
...@@ -1835,22 +2290,31 @@ static IrInstruction *ir_build_var_ptr_x(IrBuilder *irb, Scope *scope, AstNode *...@@ -1835,22 +2290,31 @@ static IrInstruction *ir_build_var_ptr_x(IrBuilder *irb, Scope *scope, AstNode *
1835 return &instruction->base;2290 return &instruction->base;
1836}2291}
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) {
1839 return ir_build_var_ptr_x(irb, scope, source_node, var, nullptr);2294 return ir_build_var_ptr_x(irb, scope, source_node, var, nullptr);
1840}2295}
18412296
1842static IrInstruction *ir_build_return_ptr(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) {2297static IrInstGen *ir_build_var_ptr_gen(IrAnalyze *ira, IrInst *source_instr, ZigVar *var) {
1843 IrInstructionReturnPtr *instruction = ir_build_instruction<IrInstructionReturnPtr>(&ira->new_irb,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,
1844 source_instruction->scope, source_instruction->source_node);2308 source_instruction->scope, source_instruction->source_node);
1845 instruction->base.value->type = ty;2309 instruction->base.value->type = ty;
1846 return &instruction->base;2310 return &instruction->base;
1847}2311}
18482312
1849static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,2313static IrInstSrc *ir_build_elem_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1850 IrInstruction *array_ptr, IrInstruction *elem_index, bool safety_check_on, PtrLen ptr_len,2314 IrInstSrc *array_ptr, IrInstSrc *elem_index, bool safety_check_on, PtrLen ptr_len,
1851 AstNode *init_array_type_source_node)2315 AstNode *init_array_type_source_node)
1852{2316{
1853 IrInstructionElemPtr *instruction = ir_build_instruction<IrInstructionElemPtr>(irb, scope, source_node);2317 IrInstSrcElemPtr *instruction = ir_build_instruction<IrInstSrcElemPtr>(irb, scope, source_node);
1854 instruction->array_ptr = array_ptr;2318 instruction->array_ptr = array_ptr;
1855 instruction->elem_index = elem_index;2319 instruction->elem_index = elem_index;
1856 instruction->safety_check_on = safety_check_on;2320 instruction->safety_check_on = safety_check_on;
...@@ -1863,10 +2327,25 @@ static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, Scope *scope, AstNode *s...@@ -1863,10 +2327,25 @@ static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, Scope *scope, AstNode *s
1863 return &instruction->base;2327 return &instruction->base;
1864}2328}
18652329
1866static IrInstruction *ir_build_field_ptr_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node,2330static IrInstGen *ir_build_elem_ptr_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
1867 IrInstruction *container_ptr, IrInstruction *field_name_expr, bool initializing)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)
1868{2347{
1869 IrInstructionFieldPtr *instruction = ir_build_instruction<IrInstructionFieldPtr>(irb, scope, source_node);2348 IrInstSrcFieldPtr *instruction = ir_build_instruction<IrInstSrcFieldPtr>(irb, scope, source_node);
1870 instruction->container_ptr = container_ptr;2349 instruction->container_ptr = container_ptr;
1871 instruction->field_name_buffer = nullptr;2350 instruction->field_name_buffer = nullptr;
1872 instruction->field_name_expr = field_name_expr;2351 instruction->field_name_expr = field_name_expr;
...@@ -1878,10 +2357,10 @@ static IrInstruction *ir_build_field_ptr_instruction(IrBuilder *irb, Scope *scop...@@ -1878,10 +2357,10 @@ static IrInstruction *ir_build_field_ptr_instruction(IrBuilder *irb, Scope *scop
1878 return &instruction->base;2357 return &instruction->base;
1879}2358}
18802359
1881static IrInstruction *ir_build_field_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,2360static IrInstSrc *ir_build_field_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1882 IrInstruction *container_ptr, Buf *field_name, bool initializing)2361 IrInstSrc *container_ptr, Buf *field_name, bool initializing)
1883{2362{
1884 IrInstructionFieldPtr *instruction = ir_build_instruction<IrInstructionFieldPtr>(irb, scope, source_node);2363 IrInstSrcFieldPtr *instruction = ir_build_instruction<IrInstSrcFieldPtr>(irb, scope, source_node);
1885 instruction->container_ptr = container_ptr;2364 instruction->container_ptr = container_ptr;
1886 instruction->field_name_buffer = field_name;2365 instruction->field_name_buffer = field_name;
1887 instruction->field_name_expr = nullptr;2366 instruction->field_name_expr = nullptr;
...@@ -1892,10 +2371,10 @@ static IrInstruction *ir_build_field_ptr(IrBuilder *irb, Scope *scope, AstNode *...@@ -1892,10 +2371,10 @@ static IrInstruction *ir_build_field_ptr(IrBuilder *irb, Scope *scope, AstNode *
1892 return &instruction->base;2371 return &instruction->base;
1893}2372}
18942373
1895static IrInstruction *ir_build_has_field(IrBuilder *irb, Scope *scope, AstNode *source_node,2374static IrInstSrc *ir_build_has_field(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1896 IrInstruction *container_type, IrInstruction *field_name)2375 IrInstSrc *container_type, IrInstSrc *field_name)
1897{2376{
1898 IrInstructionHasField *instruction = ir_build_instruction<IrInstructionHasField>(irb, scope, source_node);2377 IrInstSrcHasField *instruction = ir_build_instruction<IrInstSrcHasField>(irb, scope, source_node);
1899 instruction->container_type = container_type;2378 instruction->container_type = container_type;
1900 instruction->field_name = field_name;2379 instruction->field_name = field_name;
19012380
...@@ -1905,36 +2384,39 @@ static IrInstruction *ir_build_has_field(IrBuilder *irb, Scope *scope, AstNode *...@@ -1905,36 +2384,39 @@ static IrInstruction *ir_build_has_field(IrBuilder *irb, Scope *scope, AstNode *
1905 return &instruction->base;2384 return &instruction->base;
1906}2385}
19072386
1908static IrInstruction *ir_build_struct_field_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,2387static IrInstGen *ir_build_struct_field_ptr(IrAnalyze *ira, IrInst *source_instr,
1909 IrInstruction *struct_ptr, TypeStructField *field)2388 IrInstGen *struct_ptr, TypeStructField *field, ZigType *ptr_type)
1910{2389{
1911 IrInstructionStructFieldPtr *instruction = ir_build_instruction<IrInstructionStructFieldPtr>(irb, scope, source_node);2390 IrInstGenStructFieldPtr *inst = ir_build_inst_gen<IrInstGenStructFieldPtr>(&ira->new_irb, source_instr->scope, source_instr->source_node);
1912 instruction->struct_ptr = struct_ptr;2391 inst->base.value->type = ptr_type;
1913 instruction->field = field;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;
1918}2398}
19192399
1920static IrInstruction *ir_build_union_field_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,2400static IrInstGen *ir_build_union_field_ptr(IrAnalyze *ira, IrInst *source_instr,
1921 IrInstruction *union_ptr, TypeUnionField *field, bool safety_check_on, bool initializing)2401 IrInstGen *union_ptr, TypeUnionField *field, bool safety_check_on, bool initializing, ZigType *ptr_type)
1922{2402{
1923 IrInstructionUnionFieldPtr *instruction = ir_build_instruction<IrInstructionUnionFieldPtr>(irb, scope, source_node);2403 IrInstGenUnionFieldPtr *inst = ir_build_inst_gen<IrInstGenUnionFieldPtr>(&ira->new_irb,
1924 instruction->initializing = initializing;2404 source_instr->scope, source_instr->source_node);
1925 instruction->safety_check_on = safety_check_on;2405 inst->base.value->type = ptr_type;
1926 instruction->union_ptr = union_ptr;2406 inst->initializing = initializing;
1927 instruction->field = field;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;
1932}2414}
19332415
1934static IrInstruction *ir_build_call_extra(IrBuilder *irb, Scope *scope, AstNode *source_node,2416static IrInstSrc *ir_build_call_extra(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1935 IrInstruction *options, IrInstruction *fn_ref, IrInstruction *args, ResultLoc *result_loc)2417 IrInstSrc *options, IrInstSrc *fn_ref, IrInstSrc *args, ResultLoc *result_loc)
1936{2418{
1937 IrInstructionCallExtra *call_instruction = ir_build_instruction<IrInstructionCallExtra>(irb, scope, source_node);2419 IrInstSrcCallExtra *call_instruction = ir_build_instruction<IrInstSrcCallExtra>(irb, scope, source_node);
1938 call_instruction->options = options;2420 call_instruction->options = options;
1939 call_instruction->fn_ref = fn_ref;2421 call_instruction->fn_ref = fn_ref;
1940 call_instruction->args = args;2422 call_instruction->args = args;
...@@ -1947,11 +2429,11 @@ static IrInstruction *ir_build_call_extra(IrBuilder *irb, Scope *scope, AstNode...@@ -1947,11 +2429,11 @@ static IrInstruction *ir_build_call_extra(IrBuilder *irb, Scope *scope, AstNode
1947 return &call_instruction->base;2429 return &call_instruction->base;
1948}2430}
19492431
1950static IrInstruction *ir_build_call_src_args(IrBuilder *irb, Scope *scope, AstNode *source_node,2432static IrInstSrc *ir_build_call_args(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1951 IrInstruction *options, IrInstruction *fn_ref, IrInstruction **args_ptr, size_t args_len,2433 IrInstSrc *options, IrInstSrc *fn_ref, IrInstSrc **args_ptr, size_t args_len,
1952 ResultLoc *result_loc)2434 ResultLoc *result_loc)
1953{2435{
1954 IrInstructionCallSrcArgs *call_instruction = ir_build_instruction<IrInstructionCallSrcArgs>(irb, scope, source_node);2436 IrInstSrcCallArgs *call_instruction = ir_build_instruction<IrInstSrcCallArgs>(irb, scope, source_node);
1955 call_instruction->options = options;2437 call_instruction->options = options;
1956 call_instruction->fn_ref = fn_ref;2438 call_instruction->fn_ref = fn_ref;
1957 call_instruction->args_ptr = args_ptr;2439 call_instruction->args_ptr = args_ptr;
...@@ -1966,12 +2448,12 @@ static IrInstruction *ir_build_call_src_args(IrBuilder *irb, Scope *scope, AstNo...@@ -1966,12 +2448,12 @@ static IrInstruction *ir_build_call_src_args(IrBuilder *irb, Scope *scope, AstNo
1966 return &call_instruction->base;2448 return &call_instruction->base;
1967}2449}
19682450
1969static IrInstruction *ir_build_call_src(IrBuilder *irb, Scope *scope, AstNode *source_node,2451static IrInstSrc *ir_build_call_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1970 ZigFn *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args,2452 ZigFn *fn_entry, IrInstSrc *fn_ref, size_t arg_count, IrInstSrc **args,
1971 IrInstruction *ret_ptr, CallModifier modifier, bool is_async_call_builtin,2453 IrInstSrc *ret_ptr, CallModifier modifier, bool is_async_call_builtin,
1972 IrInstruction *new_stack, ResultLoc *result_loc)2454 IrInstSrc *new_stack, ResultLoc *result_loc)
1973{2455{
1974 IrInstructionCallSrc *call_instruction = ir_build_instruction<IrInstructionCallSrc>(irb, scope, source_node);2456 IrInstSrcCall *call_instruction = ir_build_instruction<IrInstSrcCall>(irb, scope, source_node);
1975 call_instruction->fn_entry = fn_entry;2457 call_instruction->fn_entry = fn_entry;
1976 call_instruction->fn_ref = fn_ref;2458 call_instruction->fn_ref = fn_ref;
1977 call_instruction->args = args;2459 call_instruction->args = args;
...@@ -1991,12 +2473,12 @@ static IrInstruction *ir_build_call_src(IrBuilder *irb, Scope *scope, AstNode *s...@@ -1991,12 +2473,12 @@ static IrInstruction *ir_build_call_src(IrBuilder *irb, Scope *scope, AstNode *s
1991 return &call_instruction->base;2473 return &call_instruction->base;
1992}2474}
19932475
1994static IrInstructionCallGen *ir_build_call_gen(IrAnalyze *ira, IrInstruction *source_instruction,2476static IrInstGenCall *ir_build_call_gen(IrAnalyze *ira, IrInst *source_instruction,
1995 ZigFn *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args,2477 ZigFn *fn_entry, IrInstGen *fn_ref, size_t arg_count, IrInstGen **args,
1996 CallModifier modifier, IrInstruction *new_stack, bool is_async_call_builtin,2478 CallModifier modifier, IrInstGen *new_stack, bool is_async_call_builtin,
1997 IrInstruction *result_loc, ZigType *return_type)2479 IrInstGen *result_loc, ZigType *return_type)
1998{2480{
1999 IrInstructionCallGen *call_instruction = ir_build_instruction<IrInstructionCallGen>(&ira->new_irb,2481 IrInstGenCall *call_instruction = ir_build_inst_gen<IrInstGenCall>(&ira->new_irb,
2000 source_instruction->scope, source_instruction->source_node);2482 source_instruction->scope, source_instruction->source_node);
2001 call_instruction->base.value->type = return_type;2483 call_instruction->base.value->type = return_type;
2002 call_instruction->fn_entry = fn_entry;2484 call_instruction->fn_entry = fn_entry;
...@@ -2008,23 +2490,23 @@ static IrInstructionCallGen *ir_build_call_gen(IrAnalyze *ira, IrInstruction *so...@@ -2008,23 +2490,23 @@ static IrInstructionCallGen *ir_build_call_gen(IrAnalyze *ira, IrInstruction *so
2008 call_instruction->new_stack = new_stack;2490 call_instruction->new_stack = new_stack;
2009 call_instruction->result_loc = result_loc;2491 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);
2012 for (size_t i = 0; i < arg_count; i += 1)2494 for (size_t i = 0; i < arg_count; i += 1)
2013 ir_ref_instruction(args[i], ira->new_irb.current_basic_block);2495 ir_ref_inst_gen(args[i], ira->new_irb.current_basic_block);
2014 if (new_stack != nullptr) ir_ref_instruction(new_stack, ira->new_irb.current_basic_block);2496 if (new_stack != nullptr) ir_ref_inst_gen(new_stack, ira->new_irb.current_basic_block);
2015 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);2497 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
20162498
2017 return call_instruction;2499 return call_instruction;
2018}2500}
20192501
2020static IrInstruction *ir_build_phi(IrBuilder *irb, Scope *scope, AstNode *source_node,2502static IrInstSrc *ir_build_phi(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2021 size_t incoming_count, IrBasicBlock **incoming_blocks, IrInstruction **incoming_values,2503 size_t incoming_count, IrBasicBlockSrc **incoming_blocks, IrInstSrc **incoming_values,
2022 ResultLocPeerParent *peer_parent)2504 ResultLocPeerParent *peer_parent)
2023{2505{
2024 assert(incoming_count != 0);2506 assert(incoming_count != 0);
2025 assert(incoming_count != SIZE_MAX);2507 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);
2028 phi_instruction->incoming_count = incoming_count;2510 phi_instruction->incoming_count = incoming_count;
2029 phi_instruction->incoming_blocks = incoming_blocks;2511 phi_instruction->incoming_blocks = incoming_blocks;
2030 phi_instruction->incoming_values = incoming_values;2512 phi_instruction->incoming_values = incoming_values;
...@@ -2038,56 +2520,77 @@ static IrInstruction *ir_build_phi(IrBuilder *irb, Scope *scope, AstNode *source...@@ -2038,56 +2520,77 @@ static IrInstruction *ir_build_phi(IrBuilder *irb, Scope *scope, AstNode *source
2038 return &phi_instruction->base;2520 return &phi_instruction->base;
2039}2521}
20402522
2041static IrInstruction *ir_create_br(IrBuilder *irb, Scope *scope, AstNode *source_node,2523static IrInstGen *ir_build_phi_gen(IrAnalyze *ira, IrInst *source_instr, size_t incoming_count,
2042 IrBasicBlock *dest_block, IrInstruction *is_comptime)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)
2043{2546{
2044 IrInstructionBr *br_instruction = ir_create_instruction<IrInstructionBr>(irb, scope, source_node);2547 IrInstSrcBr *inst = ir_build_instruction<IrInstSrcBr>(irb, scope, source_node);
2045 br_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;2548 inst->base.is_noreturn = true;
2046 br_instruction->base.value->special = ConstValSpecialStatic;2549 inst->dest_block = dest_block;
2047 br_instruction->dest_block = dest_block;2550 inst->is_comptime = is_comptime;
2048 br_instruction->is_comptime = is_comptime;
20492551
2050 ir_ref_bb(dest_block);2552 ir_ref_bb(dest_block);
2051 if (is_comptime) ir_ref_instruction(is_comptime, irb->current_basic_block);2553 if (is_comptime) ir_ref_instruction(is_comptime, irb->current_basic_block);
20522554
2053 return &br_instruction->base;2555 return &inst->base;
2054}2556}
20552557
2056static IrInstruction *ir_build_br(IrBuilder *irb, Scope *scope, AstNode *source_node,2558static IrInstGen *ir_build_br_gen(IrAnalyze *ira, IrInst *source_instr, IrBasicBlockGen *dest_block) {
2057 IrBasicBlock *dest_block, IrInstruction *is_comptime)2559 IrInstGenBr *inst = ir_build_inst_noreturn<IrInstGenBr>(&ira->new_irb, source_instr->scope, source_instr->source_node);
2058{2560 inst->dest_block = dest_block;
2059 IrInstruction *instruction = ir_create_br(irb, scope, source_node, dest_block, is_comptime);2561
2060 ir_instruction_append(irb->current_basic_block, instruction);2562 ir_ref_bb_gen(dest_block);
2061 return instruction;2563
2564 return &inst->base;
2062}2565}
20632566
2064static IrInstruction *ir_build_ptr_type(IrBuilder *irb, Scope *scope, AstNode *source_node,2567static IrInstSrc *ir_build_ptr_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2065 IrInstruction *child_type, bool is_const, bool is_volatile, PtrLen ptr_len,2568 IrInstSrc *child_type, bool is_const, bool is_volatile, PtrLen ptr_len,
2066 IrInstruction *sentinel, IrInstruction *align_value,2569 IrInstSrc *sentinel, IrInstSrc *align_value,
2067 uint32_t bit_offset_start, uint32_t host_int_bytes, bool is_allow_zero)2570 uint32_t bit_offset_start, uint32_t host_int_bytes, bool is_allow_zero)
2068{2571{
2069 IrInstructionPtrType *ptr_type_of_instruction = ir_build_instruction<IrInstructionPtrType>(irb, scope, source_node);2572 IrInstSrcPtrType *inst = ir_build_instruction<IrInstSrcPtrType>(irb, scope, source_node);
2070 ptr_type_of_instruction->sentinel = sentinel;2573 inst->sentinel = sentinel;
2071 ptr_type_of_instruction->align_value = align_value;2574 inst->align_value = align_value;
2072 ptr_type_of_instruction->child_type = child_type;2575 inst->child_type = child_type;
2073 ptr_type_of_instruction->is_const = is_const;2576 inst->is_const = is_const;
2074 ptr_type_of_instruction->is_volatile = is_volatile;2577 inst->is_volatile = is_volatile;
2075 ptr_type_of_instruction->ptr_len = ptr_len;2578 inst->ptr_len = ptr_len;
2076 ptr_type_of_instruction->bit_offset_start = bit_offset_start;2579 inst->bit_offset_start = bit_offset_start;
2077 ptr_type_of_instruction->host_int_bytes = host_int_bytes;2580 inst->host_int_bytes = host_int_bytes;
2078 ptr_type_of_instruction->is_allow_zero = is_allow_zero;2581 inst->is_allow_zero = is_allow_zero;
20792582
2080 if (sentinel) ir_ref_instruction(sentinel, irb->current_basic_block);2583 if (sentinel) ir_ref_instruction(sentinel, irb->current_basic_block);
2081 if (align_value) ir_ref_instruction(align_value, irb->current_basic_block);2584 if (align_value) ir_ref_instruction(align_value, irb->current_basic_block);
2082 ir_ref_instruction(child_type, irb->current_basic_block);2585 ir_ref_instruction(child_type, irb->current_basic_block);
20832586
2084 return &ptr_type_of_instruction->base;2587 return &inst->base;
2085}2588}
20862589
2087static IrInstruction *ir_build_un_op_lval(IrBuilder *irb, Scope *scope, AstNode *source_node, IrUnOp op_id,2590static IrInstSrc *ir_build_un_op_lval(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrUnOp op_id,
2088 IrInstruction *value, LVal lval, ResultLoc *result_loc)2591 IrInstSrc *value, LVal lval, ResultLoc *result_loc)
2089{2592{
2090 IrInstructionUnOp *instruction = ir_build_instruction<IrInstructionUnOp>(irb, scope, source_node);2593 IrInstSrcUnOp *instruction = ir_build_instruction<IrInstSrcUnOp>(irb, scope, source_node);
2091 instruction->op_id = op_id;2594 instruction->op_id = op_id;
2092 instruction->value = value;2595 instruction->value = value;
2093 instruction->lval = lval;2596 instruction->lval = lval;
...@@ -2098,36 +2601,73 @@ static IrInstruction *ir_build_un_op_lval(IrBuilder *irb, Scope *scope, AstNode...@@ -2098,36 +2601,73 @@ static IrInstruction *ir_build_un_op_lval(IrBuilder *irb, Scope *scope, AstNode
2098 return &instruction->base;2601 return &instruction->base;
2099}2602}
21002603
2101static IrInstruction *ir_build_un_op(IrBuilder *irb, Scope *scope, AstNode *source_node, IrUnOp op_id,2604static IrInstSrc *ir_build_un_op(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrUnOp op_id,
2102 IrInstruction *value)2605 IrInstSrc *value)
2103{2606{
2104 return ir_build_un_op_lval(irb, scope, source_node, op_id, value, LValNone, nullptr);2607 return ir_build_un_op_lval(irb, scope, source_node, op_id, value, LValNone, nullptr);
2105}2608}
21062609
2107static IrInstruction *ir_build_container_init_list(IrBuilder *irb, Scope *scope, AstNode *source_node,2610static IrInstGen *ir_build_negation(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand, ZigType *expr_type) {
2108 size_t item_count, IrInstruction **elem_result_loc_list, IrInstruction *result_loc,2611 IrInstGenNegation *instruction = ir_build_inst_gen<IrInstGenNegation>(&ira->new_irb,
2109 AstNode *init_array_type_source_node)2612 source_instr->scope, source_instr->source_node);
2110{2613 instruction->base.value->type = expr_type;
2111 IrInstructionContainerInitList *container_init_list_instruction =2614 instruction->operand = operand;
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;
21172615
2118 for (size_t i = 0; i < item_count; i += 1) {2616 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
2119 ir_ref_instruction(elem_result_loc_list[i], 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);
2120 }2660 }
2121 if (result_loc != nullptr) ir_ref_instruction(result_loc, irb->current_basic_block);2661 if (result_loc != nullptr) ir_ref_instruction(result_loc, irb->current_basic_block);
21222662
2123 return &container_init_list_instruction->base;2663 return &container_init_list_instruction->base;
2124}2664}
21252665
2126static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scope, AstNode *source_node,2666static IrInstSrc *ir_build_container_init_fields(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2127 size_t field_count, IrInstructionContainerInitFieldsField *fields, IrInstruction *result_loc)2667 size_t field_count, IrInstSrcContainerInitFieldsField *fields, IrInstSrc *result_loc)
2128{2668{
2129 IrInstructionContainerInitFields *container_init_fields_instruction =2669 IrInstSrcContainerInitFields *container_init_fields_instruction =
2130 ir_build_instruction<IrInstructionContainerInitFields>(irb, scope, source_node);2670 ir_build_instruction<IrInstSrcContainerInitFields>(irb, scope, source_node);
2131 container_init_fields_instruction->field_count = field_count;2671 container_init_fields_instruction->field_count = field_count;
2132 container_init_fields_instruction->fields = fields;2672 container_init_fields_instruction->fields = fields;
2133 container_init_fields_instruction->result_loc = result_loc;2673 container_init_fields_instruction->result_loc = result_loc;
...@@ -2140,20 +2680,21 @@ static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scop...@@ -2140,20 +2680,21 @@ static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scop
2140 return &container_init_fields_instruction->base;2680 return &container_init_fields_instruction->base;
2141}2681}
21422682
2143static IrInstruction *ir_build_unreachable(IrBuilder *irb, Scope *scope, AstNode *source_node) {2683static IrInstSrc *ir_build_unreachable(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
2144 IrInstructionUnreachable *unreachable_instruction =2684 IrInstSrcUnreachable *inst = ir_build_instruction<IrInstSrcUnreachable>(irb, scope, source_node);
2145 ir_build_instruction<IrInstructionUnreachable>(irb, scope, source_node);2685 inst->base.is_noreturn = true;
2146 unreachable_instruction->base.value->special = ConstValSpecialStatic;2686 return &inst->base;
2147 unreachable_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;2687}
2148 return &unreachable_instruction->base;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;
2149}2692}
21502693
2151static IrInstructionStorePtr *ir_build_store_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,2694static IrInstSrcStorePtr *ir_build_store_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2152 IrInstruction *ptr, IrInstruction *value)2695 IrInstSrc *ptr, IrInstSrc *value)
2153{2696{
2154 IrInstructionStorePtr *instruction = ir_build_instruction<IrInstructionStorePtr>(irb, scope, source_node);2697 IrInstSrcStorePtr *instruction = ir_build_instruction<IrInstSrcStorePtr>(irb, scope, source_node);
2155 instruction->base.value->special = ConstValSpecialStatic;
2156 instruction->base.value->type = irb->codegen->builtin_types.entry_void;
2157 instruction->ptr = ptr;2698 instruction->ptr = ptr;
2158 instruction->value = value;2699 instruction->value = value;
21592700
...@@ -2163,76 +2704,83 @@ static IrInstructionStorePtr *ir_build_store_ptr(IrBuilder *irb, Scope *scope, A...@@ -2163,76 +2704,83 @@ static IrInstructionStorePtr *ir_build_store_ptr(IrBuilder *irb, Scope *scope, A
2163 return instruction;2704 return instruction;
2164}2705}
21652706
2166static IrInstruction *ir_build_vector_store_elem(IrAnalyze *ira, IrInstruction *source_instruction,2707static IrInstGen *ir_build_store_ptr_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *ptr, IrInstGen *value) {
2167 IrInstruction *vector_ptr, IrInstruction *index, IrInstruction *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)
2168{2721{
2169 IrInstructionVectorStoreElem *inst = ir_build_instruction<IrInstructionVectorStoreElem>(2722 IrInstGenVectorStoreElem *inst = ir_build_inst_void<IrInstGenVectorStoreElem>(
2170 &ira->new_irb, source_instruction->scope, source_instruction->source_node);2723 &ira->new_irb, src_inst->scope, src_inst->source_node);
2171 inst->base.value->type = ira->codegen->builtin_types.entry_void;
2172 inst->vector_ptr = vector_ptr;2724 inst->vector_ptr = vector_ptr;
2173 inst->index = index;2725 inst->index = index;
2174 inst->value = value;2726 inst->value = value;
21752727
2176 ir_ref_instruction(vector_ptr, ira->new_irb.current_basic_block);2728 ir_ref_inst_gen(vector_ptr, ira->new_irb.current_basic_block);
2177 ir_ref_instruction(index, ira->new_irb.current_basic_block);2729 ir_ref_inst_gen(index, ira->new_irb.current_basic_block);
2178 ir_ref_instruction(value, ira->new_irb.current_basic_block);2730 ir_ref_inst_gen(value, ira->new_irb.current_basic_block);
21792731
2180 return &inst->base;2732 return &inst->base;
2181}2733}
21822734
2183static IrInstruction *ir_build_var_decl_src(IrBuilder *irb, Scope *scope, AstNode *source_node,2735static IrInstSrc *ir_build_var_decl_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2184 ZigVar *var, IrInstruction *align_value, IrInstruction *ptr)2736 ZigVar *var, IrInstSrc *align_value, IrInstSrc *ptr)
2185{2737{
2186 IrInstructionDeclVarSrc *decl_var_instruction = ir_build_instruction<IrInstructionDeclVarSrc>(irb, scope, source_node);2738 IrInstSrcDeclVar *inst = ir_build_instruction<IrInstSrcDeclVar>(irb, scope, source_node);
2187 decl_var_instruction->base.value->special = ConstValSpecialStatic;2739 inst->var = var;
2188 decl_var_instruction->base.value->type = irb->codegen->builtin_types.entry_void;2740 inst->align_value = align_value;
2189 decl_var_instruction->var = var;2741 inst->ptr = ptr;
2190 decl_var_instruction->align_value = align_value;
2191 decl_var_instruction->ptr = ptr;
21922742
2193 if (align_value != nullptr) ir_ref_instruction(align_value, irb->current_basic_block);2743 if (align_value != nullptr) ir_ref_instruction(align_value, irb->current_basic_block);
2194 ir_ref_instruction(ptr, irb->current_basic_block);2744 ir_ref_instruction(ptr, irb->current_basic_block);
21952745
2196 return &decl_var_instruction->base;2746 return &inst->base;
2197}2747}
21982748
2199static IrInstruction *ir_build_var_decl_gen(IrAnalyze *ira, IrInstruction *source_instruction,2749static IrInstGen *ir_build_var_decl_gen(IrAnalyze *ira, IrInst *source_instruction,
2200 ZigVar *var, IrInstruction *var_ptr)2750 ZigVar *var, IrInstGen *var_ptr)
2201{2751{
2202 IrInstructionDeclVarGen *decl_var_instruction = ir_build_instruction<IrInstructionDeclVarGen>(&ira->new_irb,2752 IrInstGenDeclVar *inst = ir_build_inst_gen<IrInstGenDeclVar>(&ira->new_irb,
2203 source_instruction->scope, source_instruction->source_node);2753 source_instruction->scope, source_instruction->source_node);
2204 decl_var_instruction->base.value->special = ConstValSpecialStatic;2754 inst->base.value->special = ConstValSpecialStatic;
2205 decl_var_instruction->base.value->type = ira->codegen->builtin_types.entry_void;2755 inst->base.value->type = ira->codegen->builtin_types.entry_void;
2206 decl_var_instruction->var = var;2756 inst->var = var;
2207 decl_var_instruction->var_ptr = var_ptr;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;
2212}2762}
22132763
2214static IrInstruction *ir_build_resize_slice(IrAnalyze *ira, IrInstruction *source_instruction,2764static IrInstGen *ir_build_resize_slice(IrAnalyze *ira, IrInst *source_instruction,
2215 IrInstruction *operand, ZigType *ty, IrInstruction *result_loc)2765 IrInstGen *operand, ZigType *ty, IrInstGen *result_loc)
2216{2766{
2217 IrInstructionResizeSlice *instruction = ir_build_instruction<IrInstructionResizeSlice>(&ira->new_irb,2767 IrInstGenResizeSlice *instruction = ir_build_inst_gen<IrInstGenResizeSlice>(&ira->new_irb,
2218 source_instruction->scope, source_instruction->source_node);2768 source_instruction->scope, source_instruction->source_node);
2219 instruction->base.value->type = ty;2769 instruction->base.value->type = ty;
2220 instruction->operand = operand;2770 instruction->operand = operand;
2221 instruction->result_loc = result_loc;2771 instruction->result_loc = result_loc;
22222772
2223 ir_ref_instruction(operand, ira->new_irb.current_basic_block);2773 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
2224 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);2774 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
22252775
2226 return &instruction->base;2776 return &instruction->base;
2227}2777}
22282778
2229static IrInstruction *ir_build_export(IrBuilder *irb, Scope *scope, AstNode *source_node,2779static IrInstSrc *ir_build_export(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2230 IrInstruction *target, IrInstruction *options)2780 IrInstSrc *target, IrInstSrc *options)
2231{2781{
2232 IrInstructionExport *export_instruction = ir_build_instruction<IrInstructionExport>(2782 IrInstSrcExport *export_instruction = ir_build_instruction<IrInstSrcExport>(
2233 irb, scope, source_node);2783 irb, scope, source_node);
2234 export_instruction->base.value->special = ConstValSpecialStatic;
2235 export_instruction->base.value->type = irb->codegen->builtin_types.entry_void;
2236 export_instruction->target = target;2784 export_instruction->target = target;
2237 export_instruction->options = options;2785 export_instruction->options = options;
22382786
...@@ -2242,8 +2790,8 @@ static IrInstruction *ir_build_export(IrBuilder *irb, Scope *scope, AstNode *sou...@@ -2242,8 +2790,8 @@ static IrInstruction *ir_build_export(IrBuilder *irb, Scope *scope, AstNode *sou
2242 return &export_instruction->base;2790 return &export_instruction->base;
2243}2791}
22442792
2245static IrInstruction *ir_build_load_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *ptr) {2793static IrInstSrc *ir_build_load_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *ptr) {
2246 IrInstructionLoadPtr *instruction = ir_build_instruction<IrInstructionLoadPtr>(irb, scope, source_node);2794 IrInstSrcLoadPtr *instruction = ir_build_instruction<IrInstSrcLoadPtr>(irb, scope, source_node);
2247 instruction->ptr = ptr;2795 instruction->ptr = ptr;
22482796
2249 ir_ref_instruction(ptr, irb->current_basic_block);2797 ir_ref_instruction(ptr, irb->current_basic_block);
...@@ -2251,8 +2799,23 @@ static IrInstruction *ir_build_load_ptr(IrBuilder *irb, Scope *scope, AstNode *s...@@ -2251,8 +2799,23 @@ static IrInstruction *ir_build_load_ptr(IrBuilder *irb, Scope *scope, AstNode *s
2251 return &instruction->base;2799 return &instruction->base;
2252}2800}
22532801
2254static IrInstruction *ir_build_typeof(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) {2802static IrInstGen *ir_build_load_ptr_gen(IrAnalyze *ira, IrInst *source_instruction,
2255 IrInstructionTypeOf *instruction = ir_build_instruction<IrInstructionTypeOf>(irb, scope, source_node);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);
2256 instruction->value = value;2819 instruction->value = value;
22572820
2258 ir_ref_instruction(value, irb->current_basic_block);2821 ir_ref_instruction(value, irb->current_basic_block);
...@@ -2260,8 +2823,8 @@ static IrInstruction *ir_build_typeof(IrBuilder *irb, Scope *scope, AstNode *sou...@@ -2260,8 +2823,8 @@ static IrInstruction *ir_build_typeof(IrBuilder *irb, Scope *scope, AstNode *sou
2260 return &instruction->base;2823 return &instruction->base;
2261}2824}
22622825
2263static IrInstruction *ir_build_set_cold(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *is_cold) {2826static IrInstSrc *ir_build_set_cold(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *is_cold) {
2264 IrInstructionSetCold *instruction = ir_build_instruction<IrInstructionSetCold>(irb, scope, source_node);2827 IrInstSrcSetCold *instruction = ir_build_instruction<IrInstSrcSetCold>(irb, scope, source_node);
2265 instruction->is_cold = is_cold;2828 instruction->is_cold = is_cold;
22662829
2267 ir_ref_instruction(is_cold, irb->current_basic_block);2830 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...@@ -2269,21 +2832,21 @@ static IrInstruction *ir_build_set_cold(IrBuilder *irb, Scope *scope, AstNode *s
2269 return &instruction->base;2832 return &instruction->base;
2270}2833}
22712834
2272static IrInstruction *ir_build_set_runtime_safety(IrBuilder *irb, Scope *scope, AstNode *source_node,2835static IrInstSrc *ir_build_set_runtime_safety(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2273 IrInstruction *safety_on)2836 IrInstSrc *safety_on)
2274{2837{
2275 IrInstructionSetRuntimeSafety *instruction = ir_build_instruction<IrInstructionSetRuntimeSafety>(irb, scope, source_node);2838 IrInstSrcSetRuntimeSafety *inst = ir_build_instruction<IrInstSrcSetRuntimeSafety>(irb, scope, source_node);
2276 instruction->safety_on = safety_on;2839 inst->safety_on = safety_on;
22772840
2278 ir_ref_instruction(safety_on, irb->current_basic_block);2841 ir_ref_instruction(safety_on, irb->current_basic_block);
22792842
2280 return &instruction->base;2843 return &inst->base;
2281}2844}
22822845
2283static IrInstruction *ir_build_set_float_mode(IrBuilder *irb, Scope *scope, AstNode *source_node,2846static IrInstSrc *ir_build_set_float_mode(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2284 IrInstruction *mode_value)2847 IrInstSrc *mode_value)
2285{2848{
2286 IrInstructionSetFloatMode *instruction = ir_build_instruction<IrInstructionSetFloatMode>(irb, scope, source_node);2849 IrInstSrcSetFloatMode *instruction = ir_build_instruction<IrInstSrcSetFloatMode>(irb, scope, source_node);
2287 instruction->mode_value = mode_value;2850 instruction->mode_value = mode_value;
22882851
2289 ir_ref_instruction(mode_value, irb->current_basic_block);2852 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...@@ -2291,10 +2854,10 @@ static IrInstruction *ir_build_set_float_mode(IrBuilder *irb, Scope *scope, AstN
2291 return &instruction->base;2854 return &instruction->base;
2292}2855}
22932856
2294static IrInstruction *ir_build_array_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *size,2857static IrInstSrc *ir_build_array_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *size,
2295 IrInstruction *sentinel, IrInstruction *child_type)2858 IrInstSrc *sentinel, IrInstSrc *child_type)
2296{2859{
2297 IrInstructionArrayType *instruction = ir_build_instruction<IrInstructionArrayType>(irb, scope, source_node);2860 IrInstSrcArrayType *instruction = ir_build_instruction<IrInstSrcArrayType>(irb, scope, source_node);
2298 instruction->size = size;2861 instruction->size = size;
2299 instruction->sentinel = sentinel;2862 instruction->sentinel = sentinel;
2300 instruction->child_type = child_type;2863 instruction->child_type = child_type;
...@@ -2306,10 +2869,10 @@ static IrInstruction *ir_build_array_type(IrBuilder *irb, Scope *scope, AstNode...@@ -2306,10 +2869,10 @@ static IrInstruction *ir_build_array_type(IrBuilder *irb, Scope *scope, AstNode
2306 return &instruction->base;2869 return &instruction->base;
2307}2870}
23082871
2309static IrInstruction *ir_build_anyframe_type(IrBuilder *irb, Scope *scope, AstNode *source_node,2872static IrInstSrc *ir_build_anyframe_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2310 IrInstruction *payload_type)2873 IrInstSrc *payload_type)
2311{2874{
2312 IrInstructionAnyFrameType *instruction = ir_build_instruction<IrInstructionAnyFrameType>(irb, scope, source_node);2875 IrInstSrcAnyFrameType *instruction = ir_build_instruction<IrInstSrcAnyFrameType>(irb, scope, source_node);
2313 instruction->payload_type = payload_type;2876 instruction->payload_type = payload_type;
23142877
2315 if (payload_type != nullptr) ir_ref_instruction(payload_type, irb->current_basic_block);2878 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...@@ -2317,11 +2880,11 @@ static IrInstruction *ir_build_anyframe_type(IrBuilder *irb, Scope *scope, AstNo
2317 return &instruction->base;2880 return &instruction->base;
2318}2881}
23192882
2320static IrInstruction *ir_build_slice_type(IrBuilder *irb, Scope *scope, AstNode *source_node,2883static IrInstSrc *ir_build_slice_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2321 IrInstruction *child_type, bool is_const, bool is_volatile,2884 IrInstSrc *child_type, bool is_const, bool is_volatile,
2322 IrInstruction *sentinel, IrInstruction *align_value, bool is_allow_zero)2885 IrInstSrc *sentinel, IrInstSrc *align_value, bool is_allow_zero)
2323{2886{
2324 IrInstructionSliceType *instruction = ir_build_instruction<IrInstructionSliceType>(irb, scope, source_node);2887 IrInstSrcSliceType *instruction = ir_build_instruction<IrInstSrcSliceType>(irb, scope, source_node);
2325 instruction->is_const = is_const;2888 instruction->is_const = is_const;
2326 instruction->is_volatile = is_volatile;2889 instruction->is_volatile = is_volatile;
2327 instruction->child_type = child_type;2890 instruction->child_type = child_type;
...@@ -2336,11 +2899,11 @@ static IrInstruction *ir_build_slice_type(IrBuilder *irb, Scope *scope, AstNode...@@ -2336,11 +2899,11 @@ static IrInstruction *ir_build_slice_type(IrBuilder *irb, Scope *scope, AstNode
2336 return &instruction->base;2899 return &instruction->base;
2337}2900}
23382901
2339static IrInstruction *ir_build_asm_src(IrBuilder *irb, Scope *scope, AstNode *source_node,2902static IrInstSrc *ir_build_asm_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2340 IrInstruction *asm_template, IrInstruction **input_list, IrInstruction **output_types,2903 IrInstSrc *asm_template, IrInstSrc **input_list, IrInstSrc **output_types,
2341 ZigVar **output_vars, size_t return_count, bool has_side_effects, bool is_global)2904 ZigVar **output_vars, size_t return_count, bool has_side_effects, bool is_global)
2342{2905{
2343 IrInstructionAsmSrc *instruction = ir_build_instruction<IrInstructionAsmSrc>(irb, scope, source_node);2906 IrInstSrcAsm *instruction = ir_build_instruction<IrInstSrcAsm>(irb, scope, source_node);
2344 instruction->asm_template = asm_template;2907 instruction->asm_template = asm_template;
2345 instruction->input_list = input_list;2908 instruction->input_list = input_list;
2346 instruction->output_types = output_types;2909 instruction->output_types = output_types;
...@@ -2351,24 +2914,25 @@ static IrInstruction *ir_build_asm_src(IrBuilder *irb, Scope *scope, AstNode *so...@@ -2351,24 +2914,25 @@ static IrInstruction *ir_build_asm_src(IrBuilder *irb, Scope *scope, AstNode *so
23512914
2352 assert(source_node->type == NodeTypeAsmExpr);2915 assert(source_node->type == NodeTypeAsmExpr);
2353 for (size_t i = 0; i < source_node->data.asm_expr.output_list.length; i += 1) {2916 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];
2355 if (output_type) ir_ref_instruction(output_type, irb->current_basic_block);2918 if (output_type) ir_ref_instruction(output_type, irb->current_basic_block);
2356 }2919 }
23572920
2358 for (size_t i = 0; i < source_node->data.asm_expr.input_list.length; i += 1) {2921 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];
2360 ir_ref_instruction(input_value, irb->current_basic_block);2923 ir_ref_instruction(input_value, irb->current_basic_block);
2361 }2924 }
23622925
2363 return &instruction->base;2926 return &instruction->base;
2364}2927}
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,
2367 Buf *asm_template, AsmToken *token_list, size_t token_list_len,2930 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,2931 IrInstGen **input_list, IrInstGen **output_types, ZigVar **output_vars, size_t return_count,
2369 bool has_side_effects)2932 bool has_side_effects, ZigType *return_type)
2370{2933{
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;
2372 instruction->asm_template = asm_template;2936 instruction->asm_template = asm_template;
2373 instruction->token_list = token_list;2937 instruction->token_list = token_list;
2374 instruction->token_list_len = token_list_len;2938 instruction->token_list_len = token_list_len;
...@@ -2378,22 +2942,24 @@ static IrInstruction *ir_build_asm_gen(IrAnalyze *ira, Scope *scope, AstNode *so...@@ -2378,22 +2942,24 @@ static IrInstruction *ir_build_asm_gen(IrAnalyze *ira, Scope *scope, AstNode *so
2378 instruction->return_count = return_count;2942 instruction->return_count = return_count;
2379 instruction->has_side_effects = has_side_effects;2943 instruction->has_side_effects = has_side_effects;
23802944
2381 assert(source_node->type == NodeTypeAsmExpr);2945 assert(source_instr->source_node->type == NodeTypeAsmExpr);
2382 for (size_t i = 0; i < source_node->data.asm_expr.output_list.length; i += 1) {2946 for (size_t i = 0; i < source_instr->source_node->data.asm_expr.output_list.length; i += 1) {
2383 IrInstruction *output_type = output_types[i];2947 IrInstGen *output_type = output_types[i];
2384 if (output_type) ir_ref_instruction(output_type, ira->new_irb.current_basic_block);2948 if (output_type) ir_ref_inst_gen(output_type, ira->new_irb.current_basic_block);
2385 }2949 }
23862950
2387 for (size_t i = 0; i < source_node->data.asm_expr.input_list.length; i += 1) {2951 for (size_t i = 0; i < source_instr->source_node->data.asm_expr.input_list.length; i += 1) {
2388 IrInstruction *input_value = input_list[i];2952 IrInstGen *input_value = input_list[i];
2389 ir_ref_instruction(input_value, ira->new_irb.current_basic_block);2953 ir_ref_inst_gen(input_value, ira->new_irb.current_basic_block);
2390 }2954 }
23912955
2392 return &instruction->base;2956 return &instruction->base;
2393}2957}
23942958
2395static IrInstruction *ir_build_size_of(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type_value, bool bit_size) {2959static IrInstSrc *ir_build_size_of(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_value,
2396 IrInstructionSizeOf *instruction = ir_build_instruction<IrInstructionSizeOf>(irb, scope, source_node);2960 bool bit_size)
2961{
2962 IrInstSrcSizeOf *instruction = ir_build_instruction<IrInstSrcSizeOf>(irb, scope, source_node);
2397 instruction->type_value = type_value;2963 instruction->type_value = type_value;
2398 instruction->bit_size = bit_size;2964 instruction->bit_size = bit_size;
23992965
...@@ -2402,8 +2968,10 @@ static IrInstruction *ir_build_size_of(IrBuilder *irb, Scope *scope, AstNode *so...@@ -2402,8 +2968,10 @@ static IrInstruction *ir_build_size_of(IrBuilder *irb, Scope *scope, AstNode *so
2402 return &instruction->base;2968 return &instruction->base;
2403}2969}
24042970
2405static IrInstruction *ir_build_test_nonnull(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) {2971static IrInstSrc *ir_build_test_non_null_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2406 IrInstructionTestNonNull *instruction = ir_build_instruction<IrInstructionTestNonNull>(irb, scope, source_node);2972 IrInstSrc *value)
2973{
2974 IrInstSrcTestNonNull *instruction = ir_build_instruction<IrInstSrcTestNonNull>(irb, scope, source_node);
2407 instruction->value = value;2975 instruction->value = value;
24082976
2409 ir_ref_instruction(value, irb->current_basic_block);2977 ir_ref_instruction(value, irb->current_basic_block);
...@@ -2411,10 +2979,21 @@ static IrInstruction *ir_build_test_nonnull(IrBuilder *irb, Scope *scope, AstNod...@@ -2411,10 +2979,21 @@ static IrInstruction *ir_build_test_nonnull(IrBuilder *irb, Scope *scope, AstNod
2411 return &instruction->base;2979 return &instruction->base;
2412}2980}
24132981
2414static IrInstruction *ir_build_optional_unwrap_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,2982static IrInstGen *ir_build_test_non_null_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value) {
2415 IrInstruction *base_ptr, bool safety_check_on, bool initializing)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)
2416{2995{
2417 IrInstructionOptionalUnwrapPtr *instruction = ir_build_instruction<IrInstructionOptionalUnwrapPtr>(irb, scope, source_node);2996 IrInstSrcOptionalUnwrapPtr *instruction = ir_build_instruction<IrInstSrcOptionalUnwrapPtr>(irb, scope, source_node);
2418 instruction->base_ptr = base_ptr;2997 instruction->base_ptr = base_ptr;
2419 instruction->safety_check_on = safety_check_on;2998 instruction->safety_check_on = safety_check_on;
2420 instruction->initializing = initializing;2999 instruction->initializing = initializing;
...@@ -2424,113 +3003,198 @@ static IrInstruction *ir_build_optional_unwrap_ptr(IrBuilder *irb, Scope *scope,...@@ -2424,113 +3003,198 @@ static IrInstruction *ir_build_optional_unwrap_ptr(IrBuilder *irb, Scope *scope,
2424 return &instruction->base;3003 return &instruction->base;
2425}3004}
24263005
2427static IrInstruction *ir_build_optional_wrap(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *result_ty,3006static IrInstGen *ir_build_optional_unwrap_ptr_gen(IrAnalyze *ira, IrInst *source_instr,
2428 IrInstruction *operand, IrInstruction *result_loc)3007 IrInstGen *base_ptr, bool safety_check_on, bool initializing, ZigType *result_type)
2429{3008{
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>(
2431 &ira->new_irb, source_instruction->scope, source_instruction->source_node);3025 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
2432 instruction->base.value->type = result_ty;3026 instruction->base.value->type = result_ty;
2433 instruction->operand = operand;3027 instruction->operand = operand;
2434 instruction->result_loc = result_loc;3028 instruction->result_loc = result_loc;
24353029
2436 ir_ref_instruction(operand, ira->new_irb.current_basic_block);3030 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
2437 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);3031 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
24383032
2439 return &instruction->base;3033 return &instruction->base;
2440}3034}
24413035
2442static IrInstruction *ir_build_err_wrap_payload(IrAnalyze *ira, IrInstruction *source_instruction,3036static IrInstGen *ir_build_err_wrap_payload(IrAnalyze *ira, IrInst *source_instruction,
2443 ZigType *result_type, IrInstruction *operand, IrInstruction *result_loc)3037 ZigType *result_type, IrInstGen *operand, IrInstGen *result_loc)
2444{3038{
2445 IrInstructionErrWrapPayload *instruction = ir_build_instruction<IrInstructionErrWrapPayload>(3039 IrInstGenErrWrapPayload *instruction = ir_build_inst_gen<IrInstGenErrWrapPayload>(
2446 &ira->new_irb, source_instruction->scope, source_instruction->source_node);3040 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
2447 instruction->base.value->type = result_type;3041 instruction->base.value->type = result_type;
2448 instruction->operand = operand;3042 instruction->operand = operand;
2449 instruction->result_loc = result_loc;3043 instruction->result_loc = result_loc;
24503044
2451 ir_ref_instruction(operand, ira->new_irb.current_basic_block);3045 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
2452 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);3046 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
24533047
2454 return &instruction->base;3048 return &instruction->base;
2455}3049}
24563050
2457static IrInstruction *ir_build_err_wrap_code(IrAnalyze *ira, IrInstruction *source_instruction,3051static IrInstGen *ir_build_err_wrap_code(IrAnalyze *ira, IrInst *source_instruction,
2458 ZigType *result_type, IrInstruction *operand, IrInstruction *result_loc)3052 ZigType *result_type, IrInstGen *operand, IrInstGen *result_loc)
2459{3053{
2460 IrInstructionErrWrapCode *instruction = ir_build_instruction<IrInstructionErrWrapCode>(3054 IrInstGenErrWrapCode *instruction = ir_build_inst_gen<IrInstGenErrWrapCode>(
2461 &ira->new_irb, source_instruction->scope, source_instruction->source_node);3055 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
2462 instruction->base.value->type = result_type;3056 instruction->base.value->type = result_type;
2463 instruction->operand = operand;3057 instruction->operand = operand;
2464 instruction->result_loc = result_loc;3058 instruction->result_loc = result_loc;
24653059
2466 ir_ref_instruction(operand, ira->new_irb.current_basic_block);3060 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
2467 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);3061 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
24683062
2469 return &instruction->base;3063 return &instruction->base;
2470}3064}
24713065
2472static IrInstruction *ir_build_clz(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type, IrInstruction *op) {3066static IrInstSrc *ir_build_clz(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type,
2473 IrInstructionClz *instruction = ir_build_instruction<IrInstructionClz>(irb, scope, source_node);3067 IrInstSrc *op)
3068{
3069 IrInstSrcClz *instruction = ir_build_instruction<IrInstSrcClz>(irb, scope, source_node);
2474 instruction->type = type;3070 instruction->type = type;
2475 instruction->op = op;3071 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);
2478 ir_ref_instruction(op, irb->current_basic_block);3074 ir_ref_instruction(op, irb->current_basic_block);
24793075
2480 return &instruction->base;3076 return &instruction->base;
2481}3077}
24823078
2483static IrInstruction *ir_build_ctz(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type, IrInstruction *op) {3079static IrInstGen *ir_build_clz_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *result_type, IrInstGen *op) {
2484 IrInstructionCtz *instruction = ir_build_instruction<IrInstructionCtz>(irb, scope, source_node);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);
2485 instruction->type = type;3094 instruction->type = type;
2486 instruction->op = op;3095 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);
2489 ir_ref_instruction(op, irb->current_basic_block);3098 ir_ref_instruction(op, irb->current_basic_block);
24903099
2491 return &instruction->base;3100 return &instruction->base;
2492}3101}
24933102
2494static IrInstruction *ir_build_pop_count(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type, IrInstruction *op) {3103static IrInstGen *ir_build_ctz_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *result_type, IrInstGen *op) {
2495 IrInstructionPopCount *instruction = ir_build_instruction<IrInstructionPopCount>(irb, scope, source_node);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);
2496 instruction->type = type;3118 instruction->type = type;
2497 instruction->op = op;3119 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);
2500 ir_ref_instruction(op, irb->current_basic_block);3122 ir_ref_instruction(op, irb->current_basic_block);
25013123
2502 return &instruction->base;3124 return &instruction->base;
2503}3125}
25043126
2505static IrInstruction *ir_build_bswap(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type, IrInstruction *op) {3127static IrInstGen *ir_build_pop_count_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *result_type,
2506 IrInstructionBswap *instruction = ir_build_instruction<IrInstructionBswap>(irb, scope, source_node);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);
2507 instruction->type = type;3144 instruction->type = type;
2508 instruction->op = op;3145 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);
2511 ir_ref_instruction(op, irb->current_basic_block);3148 ir_ref_instruction(op, irb->current_basic_block);
25123149
2513 return &instruction->base;3150 return &instruction->base;
2514}3151}
25153152
2516static IrInstruction *ir_build_bit_reverse(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type, IrInstruction *op) {3153static IrInstGen *ir_build_bswap_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *op_type,
2517 IrInstructionBitReverse *instruction = ir_build_instruction<IrInstructionBitReverse>(irb, scope, source_node);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);
2518 instruction->type = type;3170 instruction->type = type;
2519 instruction->op = op;3171 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);
2522 ir_ref_instruction(op, irb->current_basic_block);3174 ir_ref_instruction(op, irb->current_basic_block);
25233175
2524 return &instruction->base;3176 return &instruction->base;
2525}3177}
25263178
2527static IrInstructionSwitchBr *ir_build_switch_br(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *target_value,3179static IrInstGen *ir_build_bit_reverse_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *int_type,
2528 IrBasicBlock *else_block, size_t case_count, IrInstructionSwitchBrCase *cases, IrInstruction *is_comptime,3180 IrInstGen *op)
2529 IrInstruction *switch_prongs_void)
2530{3181{
2531 IrInstructionSwitchBr *instruction = ir_build_instruction<IrInstructionSwitchBr>(irb, scope, source_node);3182 IrInstGenBitReverse *instruction = ir_build_inst_gen<IrInstGenBitReverse>(&ira->new_irb,
2532 instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;3183 source_instr->scope, source_instr->source_node);
2533 instruction->base.value->special = ConstValSpecialStatic;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;
2534 instruction->target_value = target_value;3198 instruction->target_value = target_value;
2535 instruction->else_block = else_block;3199 instruction->else_block = else_block;
2536 instruction->case_count = case_count;3200 instruction->case_count = case_count;
...@@ -2539,9 +3203,9 @@ static IrInstructionSwitchBr *ir_build_switch_br(IrBuilder *irb, Scope *scope, A...@@ -2539,9 +3203,9 @@ static IrInstructionSwitchBr *ir_build_switch_br(IrBuilder *irb, Scope *scope, A
2539 instruction->switch_prongs_void = switch_prongs_void;3203 instruction->switch_prongs_void = switch_prongs_void;
25403204
2541 ir_ref_instruction(target_value, irb->current_basic_block);3205 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);
2543 ir_ref_bb(else_block);3207 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
2546 for (size_t i = 0; i < case_count; i += 1) {3210 for (size_t i = 0; i < case_count; i += 1) {
2547 ir_ref_instruction(cases[i].value, irb->current_basic_block);3211 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...@@ -2551,10 +3215,31 @@ static IrInstructionSwitchBr *ir_build_switch_br(IrBuilder *irb, Scope *scope, A
2551 return instruction;3215 return instruction;
2552}3216}
25533217
2554static IrInstruction *ir_build_switch_target(IrBuilder *irb, Scope *scope, AstNode *source_node,3218static IrInstGenSwitchBr *ir_build_switch_br_gen(IrAnalyze *ira, IrInst *source_instr,
2555 IrInstruction *target_value_ptr)3219 IrInstGen *target_value, IrBasicBlockGen *else_block, size_t case_count, IrInstGenSwitchBrCase *cases)
2556{3220{
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);
2558 instruction->target_value_ptr = target_value_ptr;3243 instruction->target_value_ptr = target_value_ptr;
25593244
2560 ir_ref_instruction(target_value_ptr, irb->current_basic_block);3245 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...@@ -2562,10 +3247,10 @@ static IrInstruction *ir_build_switch_target(IrBuilder *irb, Scope *scope, AstNo
2562 return &instruction->base;3247 return &instruction->base;
2563}3248}
25643249
2565static IrInstruction *ir_build_switch_var(IrBuilder *irb, Scope *scope, AstNode *source_node,3250static IrInstSrc *ir_build_switch_var(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2566 IrInstruction *target_value_ptr, IrInstruction **prongs_ptr, size_t prongs_len)3251 IrInstSrc *target_value_ptr, IrInstSrc **prongs_ptr, size_t prongs_len)
2567{3252{
2568 IrInstructionSwitchVar *instruction = ir_build_instruction<IrInstructionSwitchVar>(irb, scope, source_node);3253 IrInstSrcSwitchVar *instruction = ir_build_instruction<IrInstSrcSwitchVar>(irb, scope, source_node);
2569 instruction->target_value_ptr = target_value_ptr;3254 instruction->target_value_ptr = target_value_ptr;
2570 instruction->prongs_ptr = prongs_ptr;3255 instruction->prongs_ptr = prongs_ptr;
2571 instruction->prongs_len = prongs_len;3256 instruction->prongs_len = prongs_len;
...@@ -2579,10 +3264,10 @@ static IrInstruction *ir_build_switch_var(IrBuilder *irb, Scope *scope, AstNode...@@ -2579,10 +3264,10 @@ static IrInstruction *ir_build_switch_var(IrBuilder *irb, Scope *scope, AstNode
2579}3264}
25803265
2581// For this instruction the switch_br must be set later.3266// For this instruction the switch_br must be set later.
2582static IrInstructionSwitchElseVar *ir_build_switch_else_var(IrBuilder *irb, Scope *scope, AstNode *source_node,3267static IrInstSrcSwitchElseVar *ir_build_switch_else_var(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2583 IrInstruction *target_value_ptr)3268 IrInstSrc *target_value_ptr)
2584{3269{
2585 IrInstructionSwitchElseVar *instruction = ir_build_instruction<IrInstructionSwitchElseVar>(irb, scope, source_node);3270 IrInstSrcSwitchElseVar *instruction = ir_build_instruction<IrInstSrcSwitchElseVar>(irb, scope, source_node);
2586 instruction->target_value_ptr = target_value_ptr;3271 instruction->target_value_ptr = target_value_ptr;
25873272
2588 ir_ref_instruction(target_value_ptr, irb->current_basic_block);3273 ir_ref_instruction(target_value_ptr, irb->current_basic_block);
...@@ -2590,17 +3275,21 @@ static IrInstructionSwitchElseVar *ir_build_switch_else_var(IrBuilder *irb, Scop...@@ -2590,17 +3275,21 @@ static IrInstructionSwitchElseVar *ir_build_switch_else_var(IrBuilder *irb, Scop
2590 return instruction;3275 return instruction;
2591}3276}
25923277
2593static IrInstruction *ir_build_union_tag(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) {3278static IrInstGen *ir_build_union_tag(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value,
2594 IrInstructionUnionTag *instruction = ir_build_instruction<IrInstructionUnionTag>(irb, scope, source_node);3279 ZigType *tag_type)
3280{
3281 IrInstGenUnionTag *instruction = ir_build_inst_gen<IrInstGenUnionTag>(&ira->new_irb,
3282 source_instr->scope, source_instr->source_node);
2595 instruction->value = value;3283 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
2599 return &instruction->base;3288 return &instruction->base;
2600}3289}
26013290
2602static IrInstruction *ir_build_import(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *name) {3291static IrInstSrc *ir_build_import(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name) {
2603 IrInstructionImport *instruction = ir_build_instruction<IrInstructionImport>(irb, scope, source_node);3292 IrInstSrcImport *instruction = ir_build_instruction<IrInstSrcImport>(irb, scope, source_node);
2604 instruction->name = name;3293 instruction->name = name;
26053294
2606 ir_ref_instruction(name, irb->current_basic_block);3295 ir_ref_instruction(name, irb->current_basic_block);
...@@ -2608,10 +3297,10 @@ static IrInstruction *ir_build_import(IrBuilder *irb, Scope *scope, AstNode *sou...@@ -2608,10 +3297,10 @@ static IrInstruction *ir_build_import(IrBuilder *irb, Scope *scope, AstNode *sou
2608 return &instruction->base;3297 return &instruction->base;
2609}3298}
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,
2612 bool is_const, bool is_volatile)3301 bool is_const, bool is_volatile)
2613{3302{
2614 IrInstructionRef *instruction = ir_build_instruction<IrInstructionRef>(irb, scope, source_node);3303 IrInstSrcRef *instruction = ir_build_instruction<IrInstSrcRef>(irb, scope, source_node);
2615 instruction->value = value;3304 instruction->value = value;
2616 instruction->is_const = is_const;3305 instruction->is_const = is_const;
2617 instruction->is_volatile = is_volatile;3306 instruction->is_volatile = is_volatile;
...@@ -2621,23 +3310,23 @@ static IrInstruction *ir_build_ref(IrBuilder *irb, Scope *scope, AstNode *source...@@ -2621,23 +3310,23 @@ static IrInstruction *ir_build_ref(IrBuilder *irb, Scope *scope, AstNode *source
2621 return &instruction->base;3310 return &instruction->base;
2622}3311}
26233312
2624static IrInstruction *ir_build_ref_gen(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *result_type,3313static IrInstGen *ir_build_ref_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_type,
2625 IrInstruction *operand, IrInstruction *result_loc)3314 IrInstGen *operand, IrInstGen *result_loc)
2626{3315{
2627 IrInstructionRefGen *instruction = ir_build_instruction<IrInstructionRefGen>(&ira->new_irb,3316 IrInstGenRef *instruction = ir_build_inst_gen<IrInstGenRef>(&ira->new_irb,
2628 source_instruction->scope, source_instruction->source_node);3317 source_instruction->scope, source_instruction->source_node);
2629 instruction->base.value->type = result_type;3318 instruction->base.value->type = result_type;
2630 instruction->operand = operand;3319 instruction->operand = operand;
2631 instruction->result_loc = result_loc;3320 instruction->result_loc = result_loc;
26323321
2633 ir_ref_instruction(operand, ira->new_irb.current_basic_block);3322 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
2634 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);3323 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
26353324
2636 return &instruction->base;3325 return &instruction->base;
2637}3326}
26383327
2639static IrInstruction *ir_build_compile_err(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *msg) {3328static IrInstSrc *ir_build_compile_err(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *msg) {
2640 IrInstructionCompileErr *instruction = ir_build_instruction<IrInstructionCompileErr>(irb, scope, source_node);3329 IrInstSrcCompileErr *instruction = ir_build_instruction<IrInstSrcCompileErr>(irb, scope, source_node);
2641 instruction->msg = msg;3330 instruction->msg = msg;
26423331
2643 ir_ref_instruction(msg, irb->current_basic_block);3332 ir_ref_instruction(msg, irb->current_basic_block);
...@@ -2645,10 +3334,10 @@ static IrInstruction *ir_build_compile_err(IrBuilder *irb, Scope *scope, AstNode...@@ -2645,10 +3334,10 @@ static IrInstruction *ir_build_compile_err(IrBuilder *irb, Scope *scope, AstNode
2645 return &instruction->base;3334 return &instruction->base;
2646}3335}
26473336
2648static IrInstruction *ir_build_compile_log(IrBuilder *irb, Scope *scope, AstNode *source_node,3337static IrInstSrc *ir_build_compile_log(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2649 size_t msg_count, IrInstruction **msg_list)3338 size_t msg_count, IrInstSrc **msg_list)
2650{3339{
2651 IrInstructionCompileLog *instruction = ir_build_instruction<IrInstructionCompileLog>(irb, scope, source_node);3340 IrInstSrcCompileLog *instruction = ir_build_instruction<IrInstSrcCompileLog>(irb, scope, source_node);
2652 instruction->msg_count = msg_count;3341 instruction->msg_count = msg_count;
2653 instruction->msg_list = msg_list;3342 instruction->msg_list = msg_list;
26543343
...@@ -2659,8 +3348,8 @@ static IrInstruction *ir_build_compile_log(IrBuilder *irb, Scope *scope, AstNode...@@ -2659,8 +3348,8 @@ static IrInstruction *ir_build_compile_log(IrBuilder *irb, Scope *scope, AstNode
2659 return &instruction->base;3348 return &instruction->base;
2660}3349}
26613350
2662static IrInstruction *ir_build_err_name(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) {3351static IrInstSrc *ir_build_err_name(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value) {
2663 IrInstructionErrName *instruction = ir_build_instruction<IrInstructionErrName>(irb, scope, source_node);3352 IrInstSrcErrName *instruction = ir_build_instruction<IrInstSrcErrName>(irb, scope, source_node);
2664 instruction->value = value;3353 instruction->value = value;
26653354
2666 ir_ref_instruction(value, irb->current_basic_block);3355 ir_ref_instruction(value, irb->current_basic_block);
...@@ -2668,13 +3357,26 @@ static IrInstruction *ir_build_err_name(IrBuilder *irb, Scope *scope, AstNode *s...@@ -2668,13 +3357,26 @@ static IrInstruction *ir_build_err_name(IrBuilder *irb, Scope *scope, AstNode *s
2668 return &instruction->base;3357 return &instruction->base;
2669}3358}
26703359
2671static IrInstruction *ir_build_c_import(IrBuilder *irb, Scope *scope, AstNode *source_node) {3360static IrInstGen *ir_build_err_name_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value,
2672 IrInstructionCImport *instruction = ir_build_instruction<IrInstructionCImport>(irb, scope, source_node);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);
2673 return &instruction->base;3375 return &instruction->base;
2674}3376}
26753377
2676static IrInstruction *ir_build_c_include(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *name) {3378static IrInstSrc *ir_build_c_include(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name) {
2677 IrInstructionCInclude *instruction = ir_build_instruction<IrInstructionCInclude>(irb, scope, source_node);3379 IrInstSrcCInclude *instruction = ir_build_instruction<IrInstSrcCInclude>(irb, scope, source_node);
2678 instruction->name = name;3380 instruction->name = name;
26793381
2680 ir_ref_instruction(name, irb->current_basic_block);3382 ir_ref_instruction(name, irb->current_basic_block);
...@@ -2682,8 +3384,8 @@ static IrInstruction *ir_build_c_include(IrBuilder *irb, Scope *scope, AstNode *...@@ -2682,8 +3384,8 @@ static IrInstruction *ir_build_c_include(IrBuilder *irb, Scope *scope, AstNode *
2682 return &instruction->base;3384 return &instruction->base;
2683}3385}
26843386
2685static IrInstruction *ir_build_c_define(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *name, IrInstruction *value) {3387static IrInstSrc *ir_build_c_define(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name, IrInstSrc *value) {
2686 IrInstructionCDefine *instruction = ir_build_instruction<IrInstructionCDefine>(irb, scope, source_node);3388 IrInstSrcCDefine *instruction = ir_build_instruction<IrInstSrcCDefine>(irb, scope, source_node);
2687 instruction->name = name;3389 instruction->name = name;
2688 instruction->value = value;3390 instruction->value = value;
26893391
...@@ -2693,8 +3395,8 @@ static IrInstruction *ir_build_c_define(IrBuilder *irb, Scope *scope, AstNode *s...@@ -2693,8 +3395,8 @@ static IrInstruction *ir_build_c_define(IrBuilder *irb, Scope *scope, AstNode *s
2693 return &instruction->base;3395 return &instruction->base;
2694}3396}
26953397
2696static IrInstruction *ir_build_c_undef(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *name) {3398static IrInstSrc *ir_build_c_undef(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name) {
2697 IrInstructionCUndef *instruction = ir_build_instruction<IrInstructionCUndef>(irb, scope, source_node);3399 IrInstSrcCUndef *instruction = ir_build_instruction<IrInstSrcCUndef>(irb, scope, source_node);
2698 instruction->name = name;3400 instruction->name = name;
26993401
2700 ir_ref_instruction(name, irb->current_basic_block);3402 ir_ref_instruction(name, irb->current_basic_block);
...@@ -2702,8 +3404,8 @@ static IrInstruction *ir_build_c_undef(IrBuilder *irb, Scope *scope, AstNode *so...@@ -2702,8 +3404,8 @@ static IrInstruction *ir_build_c_undef(IrBuilder *irb, Scope *scope, AstNode *so
2702 return &instruction->base;3404 return &instruction->base;
2703}3405}
27043406
2705static IrInstruction *ir_build_embed_file(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *name) {3407static IrInstSrc *ir_build_embed_file(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name) {
2706 IrInstructionEmbedFile *instruction = ir_build_instruction<IrInstructionEmbedFile>(irb, scope, source_node);3408 IrInstSrcEmbedFile *instruction = ir_build_instruction<IrInstSrcEmbedFile>(irb, scope, source_node);
2707 instruction->name = name;3409 instruction->name = name;
27083410
2709 ir_ref_instruction(name, irb->current_basic_block);3411 ir_ref_instruction(name, irb->current_basic_block);
...@@ -2711,11 +3413,11 @@ static IrInstruction *ir_build_embed_file(IrBuilder *irb, Scope *scope, AstNode...@@ -2711,11 +3413,11 @@ static IrInstruction *ir_build_embed_file(IrBuilder *irb, Scope *scope, AstNode
2711 return &instruction->base;3413 return &instruction->base;
2712}3414}
27133415
2714static IrInstruction *ir_build_cmpxchg_src(IrBuilder *irb, Scope *scope, AstNode *source_node,3416static IrInstSrc *ir_build_cmpxchg_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2715 IrInstruction *type_value, IrInstruction *ptr, IrInstruction *cmp_value, IrInstruction *new_value,3417 IrInstSrc *type_value, IrInstSrc *ptr, IrInstSrc *cmp_value, IrInstSrc *new_value,
2716 IrInstruction *success_order_value, IrInstruction *failure_order_value, bool is_weak, ResultLoc *result_loc)3418 IrInstSrc *success_order_value, IrInstSrc *failure_order_value, bool is_weak, ResultLoc *result_loc)
2717{3419{
2718 IrInstructionCmpxchgSrc *instruction = ir_build_instruction<IrInstructionCmpxchgSrc>(irb, scope, source_node);3420 IrInstSrcCmpxchg *instruction = ir_build_instruction<IrInstSrcCmpxchg>(irb, scope, source_node);
2719 instruction->type_value = type_value;3421 instruction->type_value = type_value;
2720 instruction->ptr = ptr;3422 instruction->ptr = ptr;
2721 instruction->cmp_value = cmp_value;3423 instruction->cmp_value = cmp_value;
...@@ -2735,11 +3437,11 @@ static IrInstruction *ir_build_cmpxchg_src(IrBuilder *irb, Scope *scope, AstNode...@@ -2735,11 +3437,11 @@ static IrInstruction *ir_build_cmpxchg_src(IrBuilder *irb, Scope *scope, AstNode
2735 return &instruction->base;3437 return &instruction->base;
2736}3438}
27373439
2738static IrInstruction *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *result_type,3440static IrInstGen *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_type,
2739 IrInstruction *ptr, IrInstruction *cmp_value, IrInstruction *new_value,3441 IrInstGen *ptr, IrInstGen *cmp_value, IrInstGen *new_value,
2740 AtomicOrder success_order, AtomicOrder failure_order, bool is_weak, IrInstruction *result_loc)3442 AtomicOrder success_order, AtomicOrder failure_order, bool is_weak, IrInstGen *result_loc)
2741{3443{
2742 IrInstructionCmpxchgGen *instruction = ir_build_instruction<IrInstructionCmpxchgGen>(&ira->new_irb,3444 IrInstGenCmpxchg *instruction = ir_build_inst_gen<IrInstGenCmpxchg>(&ira->new_irb,
2743 source_instruction->scope, source_instruction->source_node);3445 source_instruction->scope, source_instruction->source_node);
2744 instruction->base.value->type = result_type;3446 instruction->base.value->type = result_type;
2745 instruction->ptr = ptr;3447 instruction->ptr = ptr;
...@@ -2750,26 +3452,35 @@ static IrInstruction *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInstruction *source...@@ -2750,26 +3452,35 @@ static IrInstruction *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInstruction *source
2750 instruction->is_weak = is_weak;3452 instruction->is_weak = is_weak;
2751 instruction->result_loc = result_loc;3453 instruction->result_loc = result_loc;
27523454
2753 ir_ref_instruction(ptr, ira->new_irb.current_basic_block);3455 ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block);
2754 ir_ref_instruction(cmp_value, ira->new_irb.current_basic_block);3456 ir_ref_inst_gen(cmp_value, ira->new_irb.current_basic_block);
2755 ir_ref_instruction(new_value, ira->new_irb.current_basic_block);3457 ir_ref_inst_gen(new_value, ira->new_irb.current_basic_block);
2756 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);3458 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
27573459
2758 return &instruction->base;3460 return &instruction->base;
2759}3461}
27603462
2761static IrInstruction *ir_build_fence(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *order_value, AtomicOrder order) {3463static IrInstSrc *ir_build_fence(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *order) {
2762 IrInstructionFence *instruction = ir_build_instruction<IrInstructionFence>(irb, scope, source_node);3464 IrInstSrcFence *instruction = ir_build_instruction<IrInstSrcFence>(irb, scope, source_node);
2763 instruction->order_value = order_value;
2764 instruction->order = order;3465 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
2768 return &instruction->base;3477 return &instruction->base;
2769}3478}
27703479
2771static IrInstruction *ir_build_truncate(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_type, IrInstruction *target) {3480static IrInstSrc *ir_build_truncate(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2772 IrInstructionTruncate *instruction = ir_build_instruction<IrInstructionTruncate>(irb, scope, source_node);3481 IrInstSrc *dest_type, IrInstSrc *target)
3482{
3483 IrInstSrcTruncate *instruction = ir_build_instruction<IrInstSrcTruncate>(irb, scope, source_node);
2773 instruction->dest_type = dest_type;3484 instruction->dest_type = dest_type;
2774 instruction->target = target;3485 instruction->target = target;
27753486
...@@ -2779,8 +3490,23 @@ static IrInstruction *ir_build_truncate(IrBuilder *irb, Scope *scope, AstNode *s...@@ -2779,8 +3490,23 @@ static IrInstruction *ir_build_truncate(IrBuilder *irb, Scope *scope, AstNode *s
2779 return &instruction->base;3490 return &instruction->base;
2780}3491}
27813492
2782static IrInstruction *ir_build_int_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_type, IrInstruction *target) {3493static IrInstGen *ir_build_truncate_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *dest_type,
2783 IrInstructionIntCast *instruction = ir_build_instruction<IrInstructionIntCast>(irb, scope, source_node);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);
2784 instruction->dest_type = dest_type;3510 instruction->dest_type = dest_type;
2785 instruction->target = target;3511 instruction->target = target;
27863512
...@@ -2790,8 +3516,10 @@ static IrInstruction *ir_build_int_cast(IrBuilder *irb, Scope *scope, AstNode *s...@@ -2790,8 +3516,10 @@ static IrInstruction *ir_build_int_cast(IrBuilder *irb, Scope *scope, AstNode *s
2790 return &instruction->base;3516 return &instruction->base;
2791}3517}
27923518
2793static IrInstruction *ir_build_float_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_type, IrInstruction *target) {3519static IrInstSrc *ir_build_float_cast(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *dest_type,
2794 IrInstructionFloatCast *instruction = ir_build_instruction<IrInstructionFloatCast>(irb, scope, source_node);3520 IrInstSrc *target)
3521{
3522 IrInstSrcFloatCast *instruction = ir_build_instruction<IrInstSrcFloatCast>(irb, scope, source_node);
2795 instruction->dest_type = dest_type;3523 instruction->dest_type = dest_type;
2796 instruction->target = target;3524 instruction->target = target;
27973525
...@@ -2801,8 +3529,10 @@ static IrInstruction *ir_build_float_cast(IrBuilder *irb, Scope *scope, AstNode...@@ -2801,8 +3529,10 @@ static IrInstruction *ir_build_float_cast(IrBuilder *irb, Scope *scope, AstNode
2801 return &instruction->base;3529 return &instruction->base;
2802}3530}
28033531
2804static IrInstruction *ir_build_err_set_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_type, IrInstruction *target) {3532static IrInstSrc *ir_build_err_set_cast(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2805 IrInstructionErrSetCast *instruction = ir_build_instruction<IrInstructionErrSetCast>(irb, scope, source_node);3533 IrInstSrc *dest_type, IrInstSrc *target)
3534{
3535 IrInstSrcErrSetCast *instruction = ir_build_instruction<IrInstSrcErrSetCast>(irb, scope, source_node);
2806 instruction->dest_type = dest_type;3536 instruction->dest_type = dest_type;
2807 instruction->target = target;3537 instruction->target = target;
28083538
...@@ -2812,10 +3542,10 @@ static IrInstruction *ir_build_err_set_cast(IrBuilder *irb, Scope *scope, AstNod...@@ -2812,10 +3542,10 @@ static IrInstruction *ir_build_err_set_cast(IrBuilder *irb, Scope *scope, AstNod
2812 return &instruction->base;3542 return &instruction->base;
2813}3543}
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,
2816 ResultLoc *result_loc)3546 ResultLoc *result_loc)
2817{3547{
2818 IrInstructionToBytes *instruction = ir_build_instruction<IrInstructionToBytes>(irb, scope, source_node);3548 IrInstSrcToBytes *instruction = ir_build_instruction<IrInstSrcToBytes>(irb, scope, source_node);
2819 instruction->target = target;3549 instruction->target = target;
2820 instruction->result_loc = result_loc;3550 instruction->result_loc = result_loc;
28213551
...@@ -2824,10 +3554,10 @@ static IrInstruction *ir_build_to_bytes(IrBuilder *irb, Scope *scope, AstNode *s...@@ -2824,10 +3554,10 @@ static IrInstruction *ir_build_to_bytes(IrBuilder *irb, Scope *scope, AstNode *s
2824 return &instruction->base;3554 return &instruction->base;
2825}3555}
28263556
2827static IrInstruction *ir_build_from_bytes(IrBuilder *irb, Scope *scope, AstNode *source_node,3557static IrInstSrc *ir_build_from_bytes(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2828 IrInstruction *dest_child_type, IrInstruction *target, ResultLoc *result_loc)3558 IrInstSrc *dest_child_type, IrInstSrc *target, ResultLoc *result_loc)
2829{3559{
2830 IrInstructionFromBytes *instruction = ir_build_instruction<IrInstructionFromBytes>(irb, scope, source_node);3560 IrInstSrcFromBytes *instruction = ir_build_instruction<IrInstSrcFromBytes>(irb, scope, source_node);
2831 instruction->dest_child_type = dest_child_type;3561 instruction->dest_child_type = dest_child_type;
2832 instruction->target = target;3562 instruction->target = target;
2833 instruction->result_loc = result_loc;3563 instruction->result_loc = result_loc;
...@@ -2838,8 +3568,10 @@ static IrInstruction *ir_build_from_bytes(IrBuilder *irb, Scope *scope, AstNode...@@ -2838,8 +3568,10 @@ static IrInstruction *ir_build_from_bytes(IrBuilder *irb, Scope *scope, AstNode
2838 return &instruction->base;3568 return &instruction->base;
2839}3569}
28403570
2841static IrInstruction *ir_build_int_to_float(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_type, IrInstruction *target) {3571static IrInstSrc *ir_build_int_to_float(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2842 IrInstructionIntToFloat *instruction = ir_build_instruction<IrInstructionIntToFloat>(irb, scope, source_node);3572 IrInstSrc *dest_type, IrInstSrc *target)
3573{
3574 IrInstSrcIntToFloat *instruction = ir_build_instruction<IrInstSrcIntToFloat>(irb, scope, source_node);
2843 instruction->dest_type = dest_type;3575 instruction->dest_type = dest_type;
2844 instruction->target = target;3576 instruction->target = target;
28453577
...@@ -2849,8 +3581,10 @@ static IrInstruction *ir_build_int_to_float(IrBuilder *irb, Scope *scope, AstNod...@@ -2849,8 +3581,10 @@ static IrInstruction *ir_build_int_to_float(IrBuilder *irb, Scope *scope, AstNod
2849 return &instruction->base;3581 return &instruction->base;
2850}3582}
28513583
2852static IrInstruction *ir_build_float_to_int(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_type, IrInstruction *target) {3584static IrInstSrc *ir_build_float_to_int(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2853 IrInstructionFloatToInt *instruction = ir_build_instruction<IrInstructionFloatToInt>(irb, scope, source_node);3585 IrInstSrc *dest_type, IrInstSrc *target)
3586{
3587 IrInstSrcFloatToInt *instruction = ir_build_instruction<IrInstSrcFloatToInt>(irb, scope, source_node);
2854 instruction->dest_type = dest_type;3588 instruction->dest_type = dest_type;
2855 instruction->target = target;3589 instruction->target = target;
28563590
...@@ -2860,8 +3594,8 @@ static IrInstruction *ir_build_float_to_int(IrBuilder *irb, Scope *scope, AstNod...@@ -2860,8 +3594,8 @@ static IrInstruction *ir_build_float_to_int(IrBuilder *irb, Scope *scope, AstNod
2860 return &instruction->base;3594 return &instruction->base;
2861}3595}
28623596
2863static IrInstruction *ir_build_bool_to_int(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *target) {3597static IrInstSrc *ir_build_bool_to_int(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *target) {
2864 IrInstructionBoolToInt *instruction = ir_build_instruction<IrInstructionBoolToInt>(irb, scope, source_node);3598 IrInstSrcBoolToInt *instruction = ir_build_instruction<IrInstSrcBoolToInt>(irb, scope, source_node);
2865 instruction->target = target;3599 instruction->target = target;
28663600
2867 ir_ref_instruction(target, irb->current_basic_block);3601 ir_ref_instruction(target, irb->current_basic_block);
...@@ -2869,8 +3603,10 @@ static IrInstruction *ir_build_bool_to_int(IrBuilder *irb, Scope *scope, AstNode...@@ -2869,8 +3603,10 @@ static IrInstruction *ir_build_bool_to_int(IrBuilder *irb, Scope *scope, AstNode
2869 return &instruction->base;3603 return &instruction->base;
2870}3604}
28713605
2872static IrInstruction *ir_build_int_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *is_signed, IrInstruction *bit_count) {3606static IrInstSrc *ir_build_int_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *is_signed,
2873 IrInstructionIntType *instruction = ir_build_instruction<IrInstructionIntType>(irb, scope, source_node);3607 IrInstSrc *bit_count)
3608{
3609 IrInstSrcIntType *instruction = ir_build_instruction<IrInstSrcIntType>(irb, scope, source_node);
2874 instruction->is_signed = is_signed;3610 instruction->is_signed = is_signed;
2875 instruction->bit_count = bit_count;3611 instruction->bit_count = bit_count;
28763612
...@@ -2880,10 +3616,10 @@ static IrInstruction *ir_build_int_type(IrBuilder *irb, Scope *scope, AstNode *s...@@ -2880,10 +3616,10 @@ static IrInstruction *ir_build_int_type(IrBuilder *irb, Scope *scope, AstNode *s
2880 return &instruction->base;3616 return &instruction->base;
2881}3617}
28823618
2883static IrInstruction *ir_build_vector_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *len,3619static IrInstSrc *ir_build_vector_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *len,
2884 IrInstruction *elem_type)3620 IrInstSrc *elem_type)
2885{3621{
2886 IrInstructionVectorType *instruction = ir_build_instruction<IrInstructionVectorType>(irb, scope, source_node);3622 IrInstSrcVectorType *instruction = ir_build_instruction<IrInstSrcVectorType>(irb, scope, source_node);
2887 instruction->len = len;3623 instruction->len = len;
2888 instruction->elem_type = elem_type;3624 instruction->elem_type = elem_type;
28893625
...@@ -2893,18 +3629,16 @@ static IrInstruction *ir_build_vector_type(IrBuilder *irb, Scope *scope, AstNode...@@ -2893,18 +3629,16 @@ static IrInstruction *ir_build_vector_type(IrBuilder *irb, Scope *scope, AstNode
2893 return &instruction->base;3629 return &instruction->base;
2894}3630}
28953631
2896static IrInstruction *ir_build_shuffle_vector(IrBuilder *irb, Scope *scope, AstNode *source_node,3632static IrInstSrc *ir_build_shuffle_vector(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2897 IrInstruction *scalar_type, IrInstruction *a, IrInstruction *b, IrInstruction *mask)3633 IrInstSrc *scalar_type, IrInstSrc *a, IrInstSrc *b, IrInstSrc *mask)
2898{3634{
2899 IrInstructionShuffleVector *instruction = ir_build_instruction<IrInstructionShuffleVector>(irb, scope, source_node);3635 IrInstSrcShuffleVector *instruction = ir_build_instruction<IrInstSrcShuffleVector>(irb, scope, source_node);
2900 instruction->scalar_type = scalar_type;3636 instruction->scalar_type = scalar_type;
2901 instruction->a = a;3637 instruction->a = a;
2902 instruction->b = b;3638 instruction->b = b;
2903 instruction->mask = mask;3639 instruction->mask = mask;
29043640
2905 if (scalar_type != nullptr) {3641 if (scalar_type != nullptr) ir_ref_instruction(scalar_type, irb->current_basic_block);
2906 ir_ref_instruction(scalar_type, irb->current_basic_block);
2907 }
2908 ir_ref_instruction(a, irb->current_basic_block);3642 ir_ref_instruction(a, irb->current_basic_block);
2909 ir_ref_instruction(b, irb->current_basic_block);3643 ir_ref_instruction(b, irb->current_basic_block);
2910 ir_ref_instruction(mask, irb->current_basic_block);3644 ir_ref_instruction(mask, irb->current_basic_block);
...@@ -2912,10 +3646,26 @@ static IrInstruction *ir_build_shuffle_vector(IrBuilder *irb, Scope *scope, AstN...@@ -2912,10 +3646,26 @@ static IrInstruction *ir_build_shuffle_vector(IrBuilder *irb, Scope *scope, AstN
2912 return &instruction->base;3646 return &instruction->base;
2913}3647}
29143648
2915static IrInstruction *ir_build_splat_src(IrBuilder *irb, Scope *scope, AstNode *source_node,3649static IrInstGen *ir_build_shuffle_vector_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
2916 IrInstruction *len, IrInstruction *scalar)3650 ZigType *result_type, IrInstGen *a, IrInstGen *b, IrInstGen *mask)
2917{3651{
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);
2919 instruction->len = len;3669 instruction->len = len;
2920 instruction->scalar = scalar;3670 instruction->scalar = scalar;
29213671
...@@ -2925,8 +3675,21 @@ static IrInstruction *ir_build_splat_src(IrBuilder *irb, Scope *scope, AstNode *...@@ -2925,8 +3675,21 @@ static IrInstruction *ir_build_splat_src(IrBuilder *irb, Scope *scope, AstNode *
2925 return &instruction->base;3675 return &instruction->base;
2926}3676}
29273677
2928static IrInstruction *ir_build_bool_not(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) {3678static IrInstGen *ir_build_splat_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_type,
2929 IrInstructionBoolNot *instruction = ir_build_instruction<IrInstructionBoolNot>(irb, scope, source_node);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);
2930 instruction->value = value;3693 instruction->value = value;
29313694
2932 ir_ref_instruction(value, irb->current_basic_block);3695 ir_ref_instruction(value, irb->current_basic_block);
...@@ -2934,10 +3697,21 @@ static IrInstruction *ir_build_bool_not(IrBuilder *irb, Scope *scope, AstNode *s...@@ -2934,10 +3697,21 @@ static IrInstruction *ir_build_bool_not(IrBuilder *irb, Scope *scope, AstNode *s
2934 return &instruction->base;3697 return &instruction->base;
2935}3698}
29363699
2937static IrInstruction *ir_build_memset(IrBuilder *irb, Scope *scope, AstNode *source_node,3700static IrInstGen *ir_build_bool_not_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value) {
2938 IrInstruction *dest_ptr, IrInstruction *byte, IrInstruction *count)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)
2939{3713{
2940 IrInstructionMemset *instruction = ir_build_instruction<IrInstructionMemset>(irb, scope, source_node);3714 IrInstSrcMemset *instruction = ir_build_instruction<IrInstSrcMemset>(irb, scope, source_node);
2941 instruction->dest_ptr = dest_ptr;3715 instruction->dest_ptr = dest_ptr;
2942 instruction->byte = byte;3716 instruction->byte = byte;
2943 instruction->count = count;3717 instruction->count = count;
...@@ -2949,10 +3723,26 @@ static IrInstruction *ir_build_memset(IrBuilder *irb, Scope *scope, AstNode *sou...@@ -2949,10 +3723,26 @@ static IrInstruction *ir_build_memset(IrBuilder *irb, Scope *scope, AstNode *sou
2949 return &instruction->base;3723 return &instruction->base;
2950}3724}
29513725
2952static IrInstruction *ir_build_memcpy(IrBuilder *irb, Scope *scope, AstNode *source_node,3726static IrInstGen *ir_build_memset_gen(IrAnalyze *ira, IrInst *source_instr,
2953 IrInstruction *dest_ptr, IrInstruction *src_ptr, IrInstruction *count)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)
2954{3744{
2955 IrInstructionMemcpy *instruction = ir_build_instruction<IrInstructionMemcpy>(irb, scope, source_node);3745 IrInstSrcMemcpy *instruction = ir_build_instruction<IrInstSrcMemcpy>(irb, scope, source_node);
2956 instruction->dest_ptr = dest_ptr;3746 instruction->dest_ptr = dest_ptr;
2957 instruction->src_ptr = src_ptr;3747 instruction->src_ptr = src_ptr;
2958 instruction->count = count;3748 instruction->count = count;
...@@ -2964,11 +3754,27 @@ static IrInstruction *ir_build_memcpy(IrBuilder *irb, Scope *scope, AstNode *sou...@@ -2964,11 +3754,27 @@ static IrInstruction *ir_build_memcpy(IrBuilder *irb, Scope *scope, AstNode *sou
2964 return &instruction->base;3754 return &instruction->base;
2965}3755}
29663756
2967static IrInstruction *ir_build_slice_src(IrBuilder *irb, Scope *scope, AstNode *source_node,3757static IrInstGen *ir_build_memcpy_gen(IrAnalyze *ira, IrInst *source_instr,
2968 IrInstruction *ptr, IrInstruction *start, IrInstruction *end, IrInstruction *sentinel,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,
2969 bool safety_check_on, ResultLoc *result_loc)3775 bool safety_check_on, ResultLoc *result_loc)
2970{3776{
2971 IrInstructionSliceSrc *instruction = ir_build_instruction<IrInstructionSliceSrc>(irb, scope, source_node);3777 IrInstSrcSlice *instruction = ir_build_instruction<IrInstSrcSlice>(irb, scope, source_node);
2972 instruction->ptr = ptr;3778 instruction->ptr = ptr;
2973 instruction->start = start;3779 instruction->start = start;
2974 instruction->end = end;3780 instruction->end = end;
...@@ -2984,23 +3790,10 @@ static IrInstruction *ir_build_slice_src(IrBuilder *irb, Scope *scope, AstNode *...@@ -2984,23 +3790,10 @@ static IrInstruction *ir_build_slice_src(IrBuilder *irb, Scope *scope, AstNode *
2984 return &instruction->base;3790 return &instruction->base;
2985}3791}
29863792
2987static IrInstruction *ir_build_splat_gen(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *result_type,3793static IrInstGen *ir_build_slice_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *slice_type,
2988 IrInstruction *scalar)3794 IrInstGen *ptr, IrInstGen *start, IrInstGen *end, bool safety_check_on, IrInstGen *result_loc)
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)
3002{3795{
3003 IrInstructionSliceGen *instruction = ir_build_instruction<IrInstructionSliceGen>(3796 IrInstGenSlice *instruction = ir_build_inst_gen<IrInstGenSlice>(
3004 &ira->new_irb, source_instruction->scope, source_instruction->source_node);3797 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
3005 instruction->base.value->type = slice_type;3798 instruction->base.value->type = slice_type;
3006 instruction->ptr = ptr;3799 instruction->ptr = ptr;
...@@ -3009,16 +3802,16 @@ static IrInstruction *ir_build_slice_gen(IrAnalyze *ira, IrInstruction *source_i...@@ -3009,16 +3802,16 @@ static IrInstruction *ir_build_slice_gen(IrAnalyze *ira, IrInstruction *source_i
3009 instruction->safety_check_on = safety_check_on;3802 instruction->safety_check_on = safety_check_on;
3010 instruction->result_loc = result_loc;3803 instruction->result_loc = result_loc;
30113804
3012 ir_ref_instruction(ptr, ira->new_irb.current_basic_block);3805 ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block);
3013 ir_ref_instruction(start, ira->new_irb.current_basic_block);3806 ir_ref_inst_gen(start, ira->new_irb.current_basic_block);
3014 if (end) ir_ref_instruction(end, ira->new_irb.current_basic_block);3807 if (end) ir_ref_inst_gen(end, ira->new_irb.current_basic_block);
3015 ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);3808 ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
30163809
3017 return &instruction->base;3810 return &instruction->base;
3018}3811}
30193812
3020static IrInstruction *ir_build_member_count(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *container) {3813static IrInstSrc *ir_build_member_count(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *container) {
3021 IrInstructionMemberCount *instruction = ir_build_instruction<IrInstructionMemberCount>(irb, scope, source_node);3814 IrInstSrcMemberCount *instruction = ir_build_instruction<IrInstSrcMemberCount>(irb, scope, source_node);
3022 instruction->container = container;3815 instruction->container = container;
30233816
3024 ir_ref_instruction(container, irb->current_basic_block);3817 ir_ref_instruction(container, irb->current_basic_block);
...@@ -3026,10 +3819,10 @@ static IrInstruction *ir_build_member_count(IrBuilder *irb, Scope *scope, AstNod...@@ -3026,10 +3819,10 @@ static IrInstruction *ir_build_member_count(IrBuilder *irb, Scope *scope, AstNod
3026 return &instruction->base;3819 return &instruction->base;
3027}3820}
30283821
3029static IrInstruction *ir_build_member_type(IrBuilder *irb, Scope *scope, AstNode *source_node,3822static IrInstSrc *ir_build_member_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3030 IrInstruction *container_type, IrInstruction *member_index)3823 IrInstSrc *container_type, IrInstSrc *member_index)
3031{3824{
3032 IrInstructionMemberType *instruction = ir_build_instruction<IrInstructionMemberType>(irb, scope, source_node);3825 IrInstSrcMemberType *instruction = ir_build_instruction<IrInstSrcMemberType>(irb, scope, source_node);
3033 instruction->container_type = container_type;3826 instruction->container_type = container_type;
3034 instruction->member_index = member_index;3827 instruction->member_index = member_index;
30353828
...@@ -3039,10 +3832,10 @@ static IrInstruction *ir_build_member_type(IrBuilder *irb, Scope *scope, AstNode...@@ -3039,10 +3832,10 @@ static IrInstruction *ir_build_member_type(IrBuilder *irb, Scope *scope, AstNode
3039 return &instruction->base;3832 return &instruction->base;
3040}3833}
30413834
3042static IrInstruction *ir_build_member_name(IrBuilder *irb, Scope *scope, AstNode *source_node,3835static IrInstSrc *ir_build_member_name(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3043 IrInstruction *container_type, IrInstruction *member_index)3836 IrInstSrc *container_type, IrInstSrc *member_index)
3044{3837{
3045 IrInstructionMemberName *instruction = ir_build_instruction<IrInstructionMemberName>(irb, scope, source_node);3838 IrInstSrcMemberName *instruction = ir_build_instruction<IrInstSrcMemberName>(irb, scope, source_node);
3046 instruction->container_type = container_type;3839 instruction->container_type = container_type;
3047 instruction->member_index = member_index;3840 instruction->member_index = member_index;
30483841
...@@ -3052,65 +3845,88 @@ static IrInstruction *ir_build_member_name(IrBuilder *irb, Scope *scope, AstNode...@@ -3052,65 +3845,88 @@ static IrInstruction *ir_build_member_name(IrBuilder *irb, Scope *scope, AstNode
3052 return &instruction->base;3845 return &instruction->base;
3053}3846}
30543847
3055static IrInstruction *ir_build_breakpoint(IrBuilder *irb, Scope *scope, AstNode *source_node) {3848static IrInstSrc *ir_build_breakpoint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
3056 IrInstructionBreakpoint *instruction = ir_build_instruction<IrInstructionBreakpoint>(irb, scope, source_node);3849 IrInstSrcBreakpoint *instruction = ir_build_instruction<IrInstSrcBreakpoint>(irb, scope, source_node);
3057 return &instruction->base;3850 return &instruction->base;
3058}3851}
30593852
3060static IrInstruction *ir_build_return_address(IrBuilder *irb, Scope *scope, AstNode *source_node) {3853static IrInstGen *ir_build_breakpoint_gen(IrAnalyze *ira, IrInst *source_instr) {
3061 IrInstructionReturnAddress *instruction = ir_build_instruction<IrInstructionReturnAddress>(irb, scope, source_node);3854 IrInstGenBreakpoint *instruction = ir_build_inst_void<IrInstGenBreakpoint>(&ira->new_irb,
3855 source_instr->scope, source_instr->source_node);
3062 return &instruction->base;3856 return &instruction->base;
3063}3857}
30643858
3065static IrInstruction *ir_build_frame_address(IrBuilder *irb, Scope *scope, AstNode *source_node) {3859static IrInstSrc *ir_build_return_address_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
3066 IrInstructionFrameAddress *instruction = ir_build_instruction<IrInstructionFrameAddress>(irb, scope, source_node);3860 IrInstSrcReturnAddress *instruction = ir_build_instruction<IrInstSrcReturnAddress>(irb, scope, source_node);
3067 return &instruction->base;3861 return &instruction->base;
3068}3862}
30693863
3070static IrInstruction *ir_build_handle(IrBuilder *irb, Scope *scope, AstNode *source_node) {3864static IrInstGen *ir_build_return_address_gen(IrAnalyze *ira, IrInst *source_instr) {
3071 IrInstructionFrameHandle *instruction = ir_build_instruction<IrInstructionFrameHandle>(irb, scope, source_node);3865 IrInstGenReturnAddress *inst = ir_build_inst_gen<IrInstGenReturnAddress>(&ira->new_irb, source_instr->scope, source_instr->source_node);
3072 return &instruction->base;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;
3073}3890}
30743891
3075static IrInstruction *ir_build_frame_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *fn) {3892static IrInstSrc *ir_build_frame_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *fn) {
3076 IrInstructionFrameType *instruction = ir_build_instruction<IrInstructionFrameType>(irb, scope, source_node);3893 IrInstSrcFrameType *inst = ir_build_instruction<IrInstSrcFrameType>(irb, scope, source_node);
3077 instruction->fn = fn;3894 inst->fn = fn;
30783895
3079 ir_ref_instruction(fn, irb->current_basic_block);3896 ir_ref_instruction(fn, irb->current_basic_block);
30803897
3081 return &instruction->base;3898 return &inst->base;
3082}3899}
30833900
3084static IrInstruction *ir_build_frame_size_src(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *fn) {3901static IrInstSrc *ir_build_frame_size_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *fn) {
3085 IrInstructionFrameSizeSrc *instruction = ir_build_instruction<IrInstructionFrameSizeSrc>(irb, scope, source_node);3902 IrInstSrcFrameSize *inst = ir_build_instruction<IrInstSrcFrameSize>(irb, scope, source_node);
3086 instruction->fn = fn;3903 inst->fn = fn;
30873904
3088 ir_ref_instruction(fn, irb->current_basic_block);3905 ir_ref_instruction(fn, irb->current_basic_block);
30893906
3090 return &instruction->base;3907 return &inst->base;
3091}3908}
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)
3094{3911{
3095 IrInstructionFrameSizeGen *instruction = ir_build_instruction<IrInstructionFrameSizeGen>(irb, scope, source_node);3912 IrInstGenFrameSize *inst = ir_build_inst_gen<IrInstGenFrameSize>(&ira->new_irb, source_instr->scope, source_instr->source_node);
3096 instruction->fn = fn;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;
3101}3919}
31023920
3103static IrInstruction *ir_build_overflow_op(IrBuilder *irb, Scope *scope, AstNode *source_node,3921static IrInstSrc *ir_build_overflow_op_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3104 IrOverflowOp op, IrInstruction *type_value, IrInstruction *op1, IrInstruction *op2,3922 IrOverflowOp op, IrInstSrc *type_value, IrInstSrc *op1, IrInstSrc *op2, IrInstSrc *result_ptr)
3105 IrInstruction *result_ptr, ZigType *result_ptr_type)
3106{3923{
3107 IrInstructionOverflowOp *instruction = ir_build_instruction<IrInstructionOverflowOp>(irb, scope, source_node);3924 IrInstSrcOverflowOp *instruction = ir_build_instruction<IrInstSrcOverflowOp>(irb, scope, source_node);
3108 instruction->op = op;3925 instruction->op = op;
3109 instruction->type_value = type_value;3926 instruction->type_value = type_value;
3110 instruction->op1 = op1;3927 instruction->op1 = op1;
3111 instruction->op2 = op2;3928 instruction->op2 = op2;
3112 instruction->result_ptr = result_ptr;3929 instruction->result_ptr = result_ptr;
3113 instruction->result_ptr_type = result_ptr_type;
31143930
3115 ir_ref_instruction(type_value, irb->current_basic_block);3931 ir_ref_instruction(type_value, irb->current_basic_block);
3116 ir_ref_instruction(op1, irb->current_basic_block);3932 ir_ref_instruction(op1, irb->current_basic_block);
...@@ -3120,49 +3936,30 @@ static IrInstruction *ir_build_overflow_op(IrBuilder *irb, Scope *scope, AstNode...@@ -3120,49 +3936,30 @@ static IrInstruction *ir_build_overflow_op(IrBuilder *irb, Scope *scope, AstNode
3120 return &instruction->base;3936 return &instruction->base;
3121}3937}
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,3952 ir_ref_inst_gen(op1, ira->new_irb.current_basic_block);
3125// lround, llround, lrint, llrint3953 ir_ref_inst_gen(op2, ira->new_irb.current_basic_block);
3126// So far this is only non-complicated type functions.3954 ir_ref_inst_gen(result_ptr, ira->new_irb.current_basic_block);
3127const char *float_op_to_name(BuiltinFnId op) {3955
3128 switch (op) {3956 return &instruction->base;
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 }
3160}3957}
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,
3163 BuiltinFnId fn_id)3960 BuiltinFnId fn_id)
3164{3961{
3165 IrInstructionFloatOp *instruction = ir_build_instruction<IrInstructionFloatOp>(irb, scope, source_node);3962 IrInstSrcFloatOp *instruction = ir_build_instruction<IrInstSrcFloatOp>(irb, scope, source_node);
3166 instruction->operand = operand;3963 instruction->operand = operand;
3167 instruction->fn_id = fn_id;3964 instruction->fn_id = fn_id;
31683965
...@@ -3171,9 +3968,24 @@ static IrInstruction *ir_build_float_op(IrBuilder *irb, Scope *scope, AstNode *s...@@ -3171,9 +3968,24 @@ static IrInstruction *ir_build_float_op(IrBuilder *irb, Scope *scope, AstNode *s
3171 return &instruction->base;3968 return &instruction->base;
3172}3969}
31733970
3174static IrInstruction *ir_build_mul_add(IrBuilder *irb, Scope *scope, AstNode *source_node,3971static IrInstGen *ir_build_float_op_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand,
3175 IrInstruction *type_value, IrInstruction *op1, IrInstruction *op2, IrInstruction *op3) {3972 BuiltinFnId fn_id, ZigType *operand_type)
3176 IrInstructionMulAdd *instruction = ir_build_instruction<IrInstructionMulAdd>(irb, scope, source_node);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);
3177 instruction->type_value = type_value;3989 instruction->type_value = type_value;
3178 instruction->op1 = op1;3990 instruction->op1 = op1;
3179 instruction->op2 = op2;3991 instruction->op2 = op2;
...@@ -3187,8 +3999,25 @@ static IrInstruction *ir_build_mul_add(IrBuilder *irb, Scope *scope, AstNode *so...@@ -3187,8 +3999,25 @@ static IrInstruction *ir_build_mul_add(IrBuilder *irb, Scope *scope, AstNode *so
3187 return &instruction->base;3999 return &instruction->base;
3188}4000}
31894001
3190static IrInstruction *ir_build_align_of(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type_value) {4002static IrInstGen *ir_build_mul_add_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *op1, IrInstGen *op2,
3191 IrInstructionAlignOf *instruction = ir_build_instruction<IrInstructionAlignOf>(irb, scope, source_node);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);
3192 instruction->type_value = type_value;4021 instruction->type_value = type_value;
31934022
3194 ir_ref_instruction(type_value, irb->current_basic_block);4023 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...@@ -3196,10 +4025,10 @@ static IrInstruction *ir_build_align_of(IrBuilder *irb, Scope *scope, AstNode *s
3196 return &instruction->base;4025 return &instruction->base;
3197}4026}
31984027
3199static IrInstruction *ir_build_test_err_src(IrBuilder *irb, Scope *scope, AstNode *source_node,4028static IrInstSrc *ir_build_test_err_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3200 IrInstruction *base_ptr, bool resolve_err_set, bool base_ptr_is_payload)4029 IrInstSrc *base_ptr, bool resolve_err_set, bool base_ptr_is_payload)
3201{4030{
3202 IrInstructionTestErrSrc *instruction = ir_build_instruction<IrInstructionTestErrSrc>(irb, scope, source_node);4031 IrInstSrcTestErr *instruction = ir_build_instruction<IrInstSrcTestErr>(irb, scope, source_node);
3203 instruction->base_ptr = base_ptr;4032 instruction->base_ptr = base_ptr;
3204 instruction->resolve_err_set = resolve_err_set;4033 instruction->resolve_err_set = resolve_err_set;
3205 instruction->base_ptr_is_payload = base_ptr_is_payload;4034 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...@@ -3209,48 +4038,72 @@ static IrInstruction *ir_build_test_err_src(IrBuilder *irb, Scope *scope, AstNod
3209 return &instruction->base;4038 return &instruction->base;
3210}4039}
32114040
3212static IrInstruction *ir_build_test_err_gen(IrAnalyze *ira, IrInstruction *source_instruction,4041static IrInstGen *ir_build_test_err_gen(IrAnalyze *ira, IrInst *source_instruction, IrInstGen *err_union) {
3213 IrInstruction *err_union)4042 IrInstGenTestErr *instruction = ir_build_inst_gen<IrInstGenTestErr>(
3214{
3215 IrInstructionTestErrGen *instruction = ir_build_instruction<IrInstructionTestErrGen>(
3216 &ira->new_irb, source_instruction->scope, source_instruction->source_node);4043 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
3217 instruction->base.value->type = ira->codegen->builtin_types.entry_bool;4044 instruction->base.value->type = ira->codegen->builtin_types.entry_bool;
3218 instruction->err_union = err_union;4045 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
3222 return &instruction->base;4049 return &instruction->base;
3223}4050}
32244051
3225static IrInstruction *ir_build_unwrap_err_code(IrBuilder *irb, Scope *scope, AstNode *source_node,4052static IrInstSrc *ir_build_unwrap_err_code_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3226 IrInstruction *err_union_ptr)4053 IrInstSrc *err_union_ptr)
3227{4054{
3228 IrInstructionUnwrapErrCode *instruction = ir_build_instruction<IrInstructionUnwrapErrCode>(irb, scope, source_node);4055 IrInstSrcUnwrapErrCode *inst = ir_build_instruction<IrInstSrcUnwrapErrCode>(irb, scope, source_node);
3229 instruction->err_union_ptr = err_union_ptr;4056 inst->err_union_ptr = err_union_ptr;
32304057
3231 ir_ref_instruction(err_union_ptr, irb->current_basic_block);4058 ir_ref_instruction(err_union_ptr, irb->current_basic_block);
32324059
3233 return &instruction->base;4060 return &inst->base;
3234}4061}
32354062
3236static IrInstruction *ir_build_unwrap_err_payload(IrBuilder *irb, Scope *scope, AstNode *source_node,4063static IrInstGen *ir_build_unwrap_err_code_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
3237 IrInstruction *value, bool safety_check_on, bool initializing)4064 IrInstGen *err_union_ptr, ZigType *result_type)
3238{4065{
3239 IrInstructionUnwrapErrPayload *instruction = ir_build_instruction<IrInstructionUnwrapErrPayload>(irb, scope, source_node);4066 IrInstGenUnwrapErrCode *inst = ir_build_inst_gen<IrInstGenUnwrapErrCode>(&ira->new_irb, scope, source_node);
3240 instruction->value = value;4067 inst->base.value->type = result_type;
3241 instruction->safety_check_on = safety_check_on;4068 inst->err_union_ptr = err_union_ptr;
3242 instruction->initializing = initializing;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
3244 ir_ref_instruction(value, irb->current_basic_block);4083 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;
3247}4100}
32484101
3249static IrInstruction *ir_build_fn_proto(IrBuilder *irb, Scope *scope, AstNode *source_node,4102static IrInstSrc *ir_build_fn_proto(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3250 IrInstruction **param_types, IrInstruction *align_value, IrInstruction *callconv_value,4103 IrInstSrc **param_types, IrInstSrc *align_value, IrInstSrc *callconv_value,
3251 IrInstruction *return_type, bool is_var_args)4104 IrInstSrc *return_type, bool is_var_args)
3252{4105{
3253 IrInstructionFnProto *instruction = ir_build_instruction<IrInstructionFnProto>(irb, scope, source_node);4106 IrInstSrcFnProto *instruction = ir_build_instruction<IrInstSrcFnProto>(irb, scope, source_node);
3254 instruction->param_types = param_types;4107 instruction->param_types = param_types;
3255 instruction->align_value = align_value;4108 instruction->align_value = align_value;
3256 instruction->callconv_value = callconv_value;4109 instruction->callconv_value = callconv_value;
...@@ -3270,8 +4123,8 @@ static IrInstruction *ir_build_fn_proto(IrBuilder *irb, Scope *scope, AstNode *s...@@ -3270,8 +4123,8 @@ static IrInstruction *ir_build_fn_proto(IrBuilder *irb, Scope *scope, AstNode *s
3270 return &instruction->base;4123 return &instruction->base;
3271}4124}
32724125
3273static IrInstruction *ir_build_test_comptime(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) {4126static IrInstSrc *ir_build_test_comptime(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value) {
3274 IrInstructionTestComptime *instruction = ir_build_instruction<IrInstructionTestComptime>(irb, scope, source_node);4127 IrInstSrcTestComptime *instruction = ir_build_instruction<IrInstSrcTestComptime>(irb, scope, source_node);
3275 instruction->value = value;4128 instruction->value = value;
32764129
3277 ir_ref_instruction(value, irb->current_basic_block);4130 ir_ref_instruction(value, irb->current_basic_block);
...@@ -3279,10 +4132,10 @@ static IrInstruction *ir_build_test_comptime(IrBuilder *irb, Scope *scope, AstNo...@@ -3279,10 +4132,10 @@ static IrInstruction *ir_build_test_comptime(IrBuilder *irb, Scope *scope, AstNo
3279 return &instruction->base;4132 return &instruction->base;
3280}4133}
32814134
3282static IrInstruction *ir_build_ptr_cast_src(IrBuilder *irb, Scope *scope, AstNode *source_node,4135static IrInstSrc *ir_build_ptr_cast_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3283 IrInstruction *dest_type, IrInstruction *ptr, bool safety_check_on)4136 IrInstSrc *dest_type, IrInstSrc *ptr, bool safety_check_on)
3284{4137{
3285 IrInstructionPtrCastSrc *instruction = ir_build_instruction<IrInstructionPtrCastSrc>(4138 IrInstSrcPtrCast *instruction = ir_build_instruction<IrInstSrcPtrCast>(
3286 irb, scope, source_node);4139 irb, scope, source_node);
3287 instruction->dest_type = dest_type;4140 instruction->dest_type = dest_type;
3288 instruction->ptr = ptr;4141 instruction->ptr = ptr;
...@@ -3294,39 +4147,24 @@ static IrInstruction *ir_build_ptr_cast_src(IrBuilder *irb, Scope *scope, AstNod...@@ -3294,39 +4147,24 @@ static IrInstruction *ir_build_ptr_cast_src(IrBuilder *irb, Scope *scope, AstNod
3294 return &instruction->base;4147 return &instruction->base;
3295}4148}
32964149
3297static IrInstruction *ir_build_ptr_cast_gen(IrAnalyze *ira, IrInstruction *source_instruction,4150static IrInstGen *ir_build_ptr_cast_gen(IrAnalyze *ira, IrInst *source_instruction,
3298 ZigType *ptr_type, IrInstruction *ptr, bool safety_check_on)4151 ZigType *ptr_type, IrInstGen *ptr, bool safety_check_on)
3299{4152{
3300 IrInstructionPtrCastGen *instruction = ir_build_instruction<IrInstructionPtrCastGen>(4153 IrInstGenPtrCast *instruction = ir_build_inst_gen<IrInstGenPtrCast>(
3301 &ira->new_irb, source_instruction->scope, source_instruction->source_node);4154 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
3302 instruction->base.value->type = ptr_type;4155 instruction->base.value->type = ptr_type;
3303 instruction->ptr = ptr;4156 instruction->ptr = ptr;
3304 instruction->safety_check_on = safety_check_on;4157 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
3308 return &instruction->base;4161 return &instruction->base;
3309}4162}
33104163
3311static IrInstruction *ir_build_load_ptr_gen(IrAnalyze *ira, IrInstruction *source_instruction,4164static IrInstSrc *ir_build_implicit_cast(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3312 IrInstruction *ptr, ZigType *ty, IrInstruction *result_loc)4165 IrInstSrc *operand, ResultLocCast *result_loc_cast)
3313{4166{
3314 IrInstructionLoadPtrGen *instruction = ir_build_instruction<IrInstructionLoadPtrGen>(4167 IrInstSrcImplicitCast *instruction = ir_build_instruction<IrInstSrcImplicitCast>(irb, scope, source_node);
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);
3330 instruction->operand = operand;4168 instruction->operand = operand;
3331 instruction->result_loc_cast = result_loc_cast;4169 instruction->result_loc_cast = result_loc_cast;
33324170
...@@ -3335,10 +4173,10 @@ static IrInstruction *ir_build_implicit_cast(IrBuilder *irb, Scope *scope, AstNo...@@ -3335,10 +4173,10 @@ static IrInstruction *ir_build_implicit_cast(IrBuilder *irb, Scope *scope, AstNo
3335 return &instruction->base;4173 return &instruction->base;
3336}4174}
33374175
3338static IrInstruction *ir_build_bit_cast_src(IrBuilder *irb, Scope *scope, AstNode *source_node,4176static IrInstSrc *ir_build_bit_cast_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3339 IrInstruction *operand, ResultLocBitCast *result_loc_bit_cast)4177 IrInstSrc *operand, ResultLocBitCast *result_loc_bit_cast)
3340{4178{
3341 IrInstructionBitCastSrc *instruction = ir_build_instruction<IrInstructionBitCastSrc>(irb, scope, source_node);4179 IrInstSrcBitCast *instruction = ir_build_instruction<IrInstSrcBitCast>(irb, scope, source_node);
3342 instruction->operand = operand;4180 instruction->operand = operand;
3343 instruction->result_loc_bit_cast = result_loc_bit_cast;4181 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...@@ -3347,62 +4185,81 @@ static IrInstruction *ir_build_bit_cast_src(IrBuilder *irb, Scope *scope, AstNod
3347 return &instruction->base;4185 return &instruction->base;
3348}4186}
33494187
3350static IrInstruction *ir_build_bit_cast_gen(IrAnalyze *ira, IrInstruction *source_instruction,4188static IrInstGen *ir_build_bit_cast_gen(IrAnalyze *ira, IrInst *source_instruction,
3351 IrInstruction *operand, ZigType *ty)4189 IrInstGen *operand, ZigType *ty)
3352{4190{
3353 IrInstructionBitCastGen *instruction = ir_build_instruction<IrInstructionBitCastGen>(4191 IrInstGenBitCast *instruction = ir_build_inst_gen<IrInstGenBitCast>(
3354 &ira->new_irb, source_instruction->scope, source_instruction->source_node);4192 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
3355 instruction->base.value->type = ty;4193 instruction->base.value->type = ty;
3356 instruction->operand = operand;4194 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
3360 return &instruction->base;4198 return &instruction->base;
3361}4199}
33624200
3363static IrInstruction *ir_build_widen_or_shorten(IrBuilder *irb, Scope *scope, AstNode *source_node,4201static IrInstGen *ir_build_widen_or_shorten(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target,
3364 IrInstruction *target)4202 ZigType *result_type)
3365{4203{
3366 IrInstructionWidenOrShorten *instruction = ir_build_instruction<IrInstructionWidenOrShorten>(4204 IrInstGenWidenOrShorten *inst = ir_build_inst_gen<IrInstGenWidenOrShorten>(&ira->new_irb, scope, source_node);
3367 irb, scope, source_node);4205 inst->base.value->type = result_type;
3368 instruction->target = target;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;
3373}4211}
33744212
3375static IrInstruction *ir_build_int_to_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,4213static IrInstSrc *ir_build_int_to_ptr_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3376 IrInstruction *dest_type, IrInstruction *target)4214 IrInstSrc *dest_type, IrInstSrc *target)
3377{4215{
3378 IrInstructionIntToPtr *instruction = ir_build_instruction<IrInstructionIntToPtr>(4216 IrInstSrcIntToPtr *instruction = ir_build_instruction<IrInstSrcIntToPtr>(irb, scope, source_node);
3379 irb, scope, source_node);
3380 instruction->dest_type = dest_type;4217 instruction->dest_type = dest_type;
3381 instruction->target = target;4218 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);
3384 ir_ref_instruction(target, irb->current_basic_block);4221 ir_ref_instruction(target, irb->current_basic_block);
33854222
3386 return &instruction->base;4223 return &instruction->base;
3387}4224}
33884225
3389static IrInstruction *ir_build_ptr_to_int(IrBuilder *irb, Scope *scope, AstNode *source_node,4226static IrInstGen *ir_build_int_to_ptr_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
3390 IrInstruction *target)4227 IrInstGen *target, ZigType *ptr_type)
3391{4228{
3392 IrInstructionPtrToInt *instruction = ir_build_instruction<IrInstructionPtrToInt>(4229 IrInstGenIntToPtr *instruction = ir_build_inst_gen<IrInstGenIntToPtr>(&ira->new_irb, scope, source_node);
3393 irb, scope, source_node);4230 instruction->base.value->type = ptr_type;
3394 instruction->target = target;4231 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
3398 return &instruction->base;4235 return &instruction->base;
3399}4236}
34004237
3401static IrInstruction *ir_build_int_to_enum(IrBuilder *irb, Scope *scope, AstNode *source_node,4238static IrInstSrc *ir_build_ptr_to_int_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3402 IrInstruction *dest_type, IrInstruction *target)4239 IrInstSrc *target)
3403{4240{
3404 IrInstructionIntToEnum *instruction = ir_build_instruction<IrInstructionIntToEnum>(4241 IrInstSrcPtrToInt *inst = ir_build_instruction<IrInstSrcPtrToInt>(irb, scope, source_node);
3405 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);
3406 instruction->dest_type = dest_type;4263 instruction->dest_type = dest_type;
3407 instruction->target = target;4264 instruction->target = target;
34084265
...@@ -3412,12 +4269,22 @@ static IrInstruction *ir_build_int_to_enum(IrBuilder *irb, Scope *scope, AstNode...@@ -3412,12 +4269,22 @@ static IrInstruction *ir_build_int_to_enum(IrBuilder *irb, Scope *scope, AstNode
3412 return &instruction->base;4269 return &instruction->base;
3413}4270}
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,4284static IrInstSrc *ir_build_enum_to_int(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3418 IrInstruction *target)4285 IrInstSrc *target)
3419{4286{
3420 IrInstructionEnumToInt *instruction = ir_build_instruction<IrInstructionEnumToInt>(4287 IrInstSrcEnumToInt *instruction = ir_build_instruction<IrInstSrcEnumToInt>(
3421 irb, scope, source_node);4288 irb, scope, source_node);
3422 instruction->target = target;4289 instruction->target = target;
34234290
...@@ -3426,11 +4293,10 @@ static IrInstruction *ir_build_enum_to_int(IrBuilder *irb, Scope *scope, AstNode...@@ -3426,11 +4293,10 @@ static IrInstruction *ir_build_enum_to_int(IrBuilder *irb, Scope *scope, AstNode
3426 return &instruction->base;4293 return &instruction->base;
3427}4294}
34284295
3429static IrInstruction *ir_build_int_to_err(IrBuilder *irb, Scope *scope, AstNode *source_node,4296static IrInstSrc *ir_build_int_to_err_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3430 IrInstruction *target)4297 IrInstSrc *target)
3431{4298{
3432 IrInstructionIntToErr *instruction = ir_build_instruction<IrInstructionIntToErr>(4299 IrInstSrcIntToErr *instruction = ir_build_instruction<IrInstSrcIntToErr>(irb, scope, source_node);
3433 irb, scope, source_node);
3434 instruction->target = target;4300 instruction->target = target;
34354301
3436 ir_ref_instruction(target, irb->current_basic_block);4302 ir_ref_instruction(target, irb->current_basic_block);
...@@ -3438,10 +4304,22 @@ static IrInstruction *ir_build_int_to_err(IrBuilder *irb, Scope *scope, AstNode...@@ -3438,10 +4304,22 @@ static IrInstruction *ir_build_int_to_err(IrBuilder *irb, Scope *scope, AstNode
3438 return &instruction->base;4304 return &instruction->base;
3439}4305}
34404306
3441static IrInstruction *ir_build_err_to_int(IrBuilder *irb, Scope *scope, AstNode *source_node,4307static IrInstGen *ir_build_int_to_err_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target,
3442 IrInstruction *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)
3443{4321{
3444 IrInstructionErrToInt *instruction = ir_build_instruction<IrInstructionErrToInt>(4322 IrInstSrcErrToInt *instruction = ir_build_instruction<IrInstSrcErrToInt>(
3445 irb, scope, source_node);4323 irb, scope, source_node);
3446 instruction->target = target;4324 instruction->target = target;
34474325
...@@ -3450,11 +4328,23 @@ static IrInstruction *ir_build_err_to_int(IrBuilder *irb, Scope *scope, AstNode...@@ -3450,11 +4328,23 @@ static IrInstruction *ir_build_err_to_int(IrBuilder *irb, Scope *scope, AstNode
3450 return &instruction->base;4328 return &instruction->base;
3451}4329}
34524330
3453static IrInstruction *ir_build_check_switch_prongs(IrBuilder *irb, Scope *scope, AstNode *source_node,4331static IrInstGen *ir_build_err_to_int_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target,
3454 IrInstruction *target_value, IrInstructionCheckSwitchProngsRange *ranges, size_t range_count,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,
3455 bool have_else_prong, bool have_underscore_prong)4345 bool have_else_prong, bool have_underscore_prong)
3456{4346{
3457 IrInstructionCheckSwitchProngs *instruction = ir_build_instruction<IrInstructionCheckSwitchProngs>(4347 IrInstSrcCheckSwitchProngs *instruction = ir_build_instruction<IrInstSrcCheckSwitchProngs>(
3458 irb, scope, source_node);4348 irb, scope, source_node);
3459 instruction->target_value = target_value;4349 instruction->target_value = target_value;
3460 instruction->ranges = ranges;4350 instruction->ranges = ranges;
...@@ -3471,10 +4361,10 @@ static IrInstruction *ir_build_check_switch_prongs(IrBuilder *irb, Scope *scope,...@@ -3471,10 +4361,10 @@ static IrInstruction *ir_build_check_switch_prongs(IrBuilder *irb, Scope *scope,
3471 return &instruction->base;4361 return &instruction->base;
3472}4362}
34734363
3474static IrInstruction *ir_build_check_statement_is_void(IrBuilder *irb, Scope *scope, AstNode *source_node,4364static IrInstSrc *ir_build_check_statement_is_void(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3475 IrInstruction* statement_value)4365 IrInstSrc* statement_value)
3476{4366{
3477 IrInstructionCheckStatementIsVoid *instruction = ir_build_instruction<IrInstructionCheckStatementIsVoid>(4367 IrInstSrcCheckStatementIsVoid *instruction = ir_build_instruction<IrInstSrcCheckStatementIsVoid>(
3478 irb, scope, source_node);4368 irb, scope, source_node);
3479 instruction->statement_value = statement_value;4369 instruction->statement_value = statement_value;
34804370
...@@ -3483,11 +4373,10 @@ static IrInstruction *ir_build_check_statement_is_void(IrBuilder *irb, Scope *sc...@@ -3483,11 +4373,10 @@ static IrInstruction *ir_build_check_statement_is_void(IrBuilder *irb, Scope *sc
3483 return &instruction->base;4373 return &instruction->base;
3484}4374}
34854375
3486static IrInstruction *ir_build_type_name(IrBuilder *irb, Scope *scope, AstNode *source_node,4376static IrInstSrc *ir_build_type_name(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3487 IrInstruction *type_value)4377 IrInstSrc *type_value)
3488{4378{
3489 IrInstructionTypeName *instruction = ir_build_instruction<IrInstructionTypeName>(4379 IrInstSrcTypeName *instruction = ir_build_instruction<IrInstSrcTypeName>(irb, scope, source_node);
3490 irb, scope, source_node);
3491 instruction->type_value = type_value;4380 instruction->type_value = type_value;
34924381
3493 ir_ref_instruction(type_value, irb->current_basic_block);4382 ir_ref_instruction(type_value, irb->current_basic_block);
...@@ -3495,40 +4384,60 @@ static IrInstruction *ir_build_type_name(IrBuilder *irb, Scope *scope, AstNode *...@@ -3495,40 +4384,60 @@ static IrInstruction *ir_build_type_name(IrBuilder *irb, Scope *scope, AstNode *
3495 return &instruction->base;4384 return &instruction->base;
3496}4385}
34974386
3498static IrInstruction *ir_build_decl_ref(IrBuilder *irb, Scope *scope, AstNode *source_node, Tld *tld, LVal lval) {4387static IrInstSrc *ir_build_decl_ref(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Tld *tld, LVal lval) {
3499 IrInstructionDeclRef *instruction = ir_build_instruction<IrInstructionDeclRef>(irb, scope, source_node);4388 IrInstSrcDeclRef *instruction = ir_build_instruction<IrInstSrcDeclRef>(irb, scope, source_node);
3500 instruction->tld = tld;4389 instruction->tld = tld;
3501 instruction->lval = lval;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
3503 return &instruction->base;4412 return &instruction->base;
3504}4413}
35054414
3506static IrInstruction *ir_build_panic(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *msg) {4415static IrInstSrc *ir_build_tag_name_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *target) {
3507 IrInstructionPanic *instruction = ir_build_instruction<IrInstructionPanic>(irb, scope, source_node);4416 IrInstSrcTagName *instruction = ir_build_instruction<IrInstSrcTagName>(irb, scope, source_node);
3508 instruction->base.value->special = ConstValSpecialStatic;4417 instruction->target = target;
3509 instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;
3510 instruction->msg = msg;
35114418
3512 ir_ref_instruction(msg, irb->current_basic_block);4419 ir_ref_instruction(target, irb->current_basic_block);
35134420
3514 return &instruction->base;4421 return &instruction->base;
3515}4422}
35164423
3517static IrInstruction *ir_build_tag_name(IrBuilder *irb, Scope *scope, AstNode *source_node,4424static IrInstGen *ir_build_tag_name_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *target,
3518 IrInstruction *target)4425 ZigType *result_type)
3519{4426{
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;
3521 instruction->target = target;4430 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
3525 return &instruction->base;4434 return &instruction->base;
3526}4435}
35274436
3528static IrInstruction *ir_build_tag_type(IrBuilder *irb, Scope *scope, AstNode *source_node,4437static IrInstSrc *ir_build_tag_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3529 IrInstruction *target)4438 IrInstSrc *target)
3530{4439{
3531 IrInstructionTagType *instruction = ir_build_instruction<IrInstructionTagType>(irb, scope, source_node);4440 IrInstSrcTagType *instruction = ir_build_instruction<IrInstSrcTagType>(irb, scope, source_node);
3532 instruction->target = target;4441 instruction->target = target;
35334442
3534 ir_ref_instruction(target, irb->current_basic_block);4443 ir_ref_instruction(target, irb->current_basic_block);
...@@ -3536,27 +4445,40 @@ static IrInstruction *ir_build_tag_type(IrBuilder *irb, Scope *scope, AstNode *s...@@ -3536,27 +4445,40 @@ static IrInstruction *ir_build_tag_type(IrBuilder *irb, Scope *scope, AstNode *s
3536 return &instruction->base;4445 return &instruction->base;
3537}4446}
35384447
3539static IrInstruction *ir_build_field_parent_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,4448static IrInstSrc *ir_build_field_parent_ptr_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3540 IrInstruction *type_value, IrInstruction *field_name, IrInstruction *field_ptr, TypeStructField *field)4449 IrInstSrc *type_value, IrInstSrc *field_name, IrInstSrc *field_ptr)
3541{4450{
3542 IrInstructionFieldParentPtr *instruction = ir_build_instruction<IrInstructionFieldParentPtr>(4451 IrInstSrcFieldParentPtr *inst = ir_build_instruction<IrInstSrcFieldParentPtr>(
3543 irb, scope, source_node);4452 irb, scope, source_node);
3544 instruction->type_value = type_value;4453 inst->type_value = type_value;
3545 instruction->field_name = field_name;4454 inst->field_name = field_name;
3546 instruction->field_ptr = field_ptr;4455 inst->field_ptr = field_ptr;
3547 instruction->field = field;
35484456
3549 ir_ref_instruction(type_value, irb->current_basic_block);4457 ir_ref_instruction(type_value, irb->current_basic_block);
3550 ir_ref_instruction(field_name, irb->current_basic_block);4458 ir_ref_instruction(field_name, irb->current_basic_block);
3551 ir_ref_instruction(field_ptr, irb->current_basic_block);4459 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;
3554}4476}
35554477
3556static IrInstruction *ir_build_byte_offset_of(IrBuilder *irb, Scope *scope, AstNode *source_node,4478static IrInstSrc *ir_build_byte_offset_of(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3557 IrInstruction *type_value, IrInstruction *field_name)4479 IrInstSrc *type_value, IrInstSrc *field_name)
3558{4480{
3559 IrInstructionByteOffsetOf *instruction = ir_build_instruction<IrInstructionByteOffsetOf>(irb, scope, source_node);4481 IrInstSrcByteOffsetOf *instruction = ir_build_instruction<IrInstSrcByteOffsetOf>(irb, scope, source_node);
3560 instruction->type_value = type_value;4482 instruction->type_value = type_value;
3561 instruction->field_name = field_name;4483 instruction->field_name = field_name;
35624484
...@@ -3566,10 +4488,10 @@ static IrInstruction *ir_build_byte_offset_of(IrBuilder *irb, Scope *scope, AstN...@@ -3566,10 +4488,10 @@ static IrInstruction *ir_build_byte_offset_of(IrBuilder *irb, Scope *scope, AstN
3566 return &instruction->base;4488 return &instruction->base;
3567}4489}
35684490
3569static IrInstruction *ir_build_bit_offset_of(IrBuilder *irb, Scope *scope, AstNode *source_node,4491static IrInstSrc *ir_build_bit_offset_of(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3570 IrInstruction *type_value, IrInstruction *field_name)4492 IrInstSrc *type_value, IrInstSrc *field_name)
3571{4493{
3572 IrInstructionBitOffsetOf *instruction = ir_build_instruction<IrInstructionBitOffsetOf>(irb, scope, source_node);4494 IrInstSrcBitOffsetOf *instruction = ir_build_instruction<IrInstSrcBitOffsetOf>(irb, scope, source_node);
3573 instruction->type_value = type_value;4495 instruction->type_value = type_value;
3574 instruction->field_name = field_name;4496 instruction->field_name = field_name;
35754497
...@@ -3579,9 +4501,8 @@ static IrInstruction *ir_build_bit_offset_of(IrBuilder *irb, Scope *scope, AstNo...@@ -3579,9 +4501,8 @@ static IrInstruction *ir_build_bit_offset_of(IrBuilder *irb, Scope *scope, AstNo
3579 return &instruction->base;4501 return &instruction->base;
3580}4502}
35814503
3582static IrInstruction *ir_build_type_info(IrBuilder *irb, Scope *scope, AstNode *source_node,4504static IrInstSrc *ir_build_type_info(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_value) {
3583 IrInstruction *type_value) {4505 IrInstSrcTypeInfo *instruction = ir_build_instruction<IrInstSrcTypeInfo>(irb, scope, source_node);
3584 IrInstructionTypeInfo *instruction = ir_build_instruction<IrInstructionTypeInfo>(irb, scope, source_node);
3585 instruction->type_value = type_value;4506 instruction->type_value = type_value;
35864507
3587 ir_ref_instruction(type_value, irb->current_basic_block);4508 ir_ref_instruction(type_value, irb->current_basic_block);
...@@ -3589,8 +4510,8 @@ static IrInstruction *ir_build_type_info(IrBuilder *irb, Scope *scope, AstNode *...@@ -3589,8 +4510,8 @@ static IrInstruction *ir_build_type_info(IrBuilder *irb, Scope *scope, AstNode *
3589 return &instruction->base;4510 return &instruction->base;
3590}4511}
35914512
3592static IrInstruction *ir_build_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type_info) {4513static IrInstSrc *ir_build_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_info) {
3593 IrInstructionType *instruction = ir_build_instruction<IrInstructionType>(irb, scope, source_node);4514 IrInstSrcType *instruction = ir_build_instruction<IrInstSrcType>(irb, scope, source_node);
3594 instruction->type_info = type_info;4515 instruction->type_info = type_info;
35954516
3596 ir_ref_instruction(type_info, irb->current_basic_block);4517 ir_ref_instruction(type_info, irb->current_basic_block);
...@@ -3598,10 +4519,8 @@ static IrInstruction *ir_build_type(IrBuilder *irb, Scope *scope, AstNode *sourc...@@ -3598,10 +4519,8 @@ static IrInstruction *ir_build_type(IrBuilder *irb, Scope *scope, AstNode *sourc
3598 return &instruction->base;4519 return &instruction->base;
3599}4520}
36004521
3601static IrInstruction *ir_build_type_id(IrBuilder *irb, Scope *scope, AstNode *source_node,4522static IrInstSrc *ir_build_type_id(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_value) {
3602 IrInstruction *type_value)4523 IrInstSrcTypeId *instruction = ir_build_instruction<IrInstSrcTypeId>(irb, scope, source_node);
3603{
3604 IrInstructionTypeId *instruction = ir_build_instruction<IrInstructionTypeId>(irb, scope, source_node);
3605 instruction->type_value = type_value;4524 instruction->type_value = type_value;
36064525
3607 ir_ref_instruction(type_value, irb->current_basic_block);4526 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...@@ -3609,10 +4528,10 @@ static IrInstruction *ir_build_type_id(IrBuilder *irb, Scope *scope, AstNode *so
3609 return &instruction->base;4528 return &instruction->base;
3610}4529}
36114530
3612static IrInstruction *ir_build_set_eval_branch_quota(IrBuilder *irb, Scope *scope, AstNode *source_node,4531static IrInstSrc *ir_build_set_eval_branch_quota(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3613 IrInstruction *new_quota)4532 IrInstSrc *new_quota)
3614{4533{
3615 IrInstructionSetEvalBranchQuota *instruction = ir_build_instruction<IrInstructionSetEvalBranchQuota>(irb, scope, source_node);4534 IrInstSrcSetEvalBranchQuota *instruction = ir_build_instruction<IrInstSrcSetEvalBranchQuota>(irb, scope, source_node);
3616 instruction->new_quota = new_quota;4535 instruction->new_quota = new_quota;
36174536
3618 ir_ref_instruction(new_quota, irb->current_basic_block);4537 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...@@ -3620,23 +4539,35 @@ static IrInstruction *ir_build_set_eval_branch_quota(IrBuilder *irb, Scope *scop
3620 return &instruction->base;4539 return &instruction->base;
3621}4540}
36224541
3623static IrInstruction *ir_build_align_cast(IrBuilder *irb, Scope *scope, AstNode *source_node,4542static IrInstSrc *ir_build_align_cast_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3624 IrInstruction *align_bytes, IrInstruction *target)4543 IrInstSrc *align_bytes, IrInstSrc *target)
3625{4544{
3626 IrInstructionAlignCast *instruction = ir_build_instruction<IrInstructionAlignCast>(irb, scope, source_node);4545 IrInstSrcAlignCast *instruction = ir_build_instruction<IrInstSrcAlignCast>(irb, scope, source_node);
3627 instruction->align_bytes = align_bytes;4546 instruction->align_bytes = align_bytes;
3628 instruction->target = target;4547 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);
3631 ir_ref_instruction(target, irb->current_basic_block);4550 ir_ref_instruction(target, irb->current_basic_block);
36324551
3633 return &instruction->base;4552 return &instruction->base;
3634}4553}
36354554
3636static IrInstruction *ir_build_resolve_result(IrBuilder *irb, Scope *scope, AstNode *source_node,4555static IrInstGen *ir_build_align_cast_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target,
3637 ResultLoc *result_loc, IrInstruction *ty)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)
3638{4569{
3639 IrInstructionResolveResult *instruction = ir_build_instruction<IrInstructionResolveResult>(irb, scope, source_node);4570 IrInstSrcResolveResult *instruction = ir_build_instruction<IrInstSrcResolveResult>(irb, scope, source_node);
3640 instruction->result_loc = result_loc;4571 instruction->result_loc = result_loc;
3641 instruction->ty = ty;4572 instruction->ty = ty;
36424573
...@@ -3645,25 +4576,25 @@ static IrInstruction *ir_build_resolve_result(IrBuilder *irb, Scope *scope, AstN...@@ -3645,25 +4576,25 @@ static IrInstruction *ir_build_resolve_result(IrBuilder *irb, Scope *scope, AstN
3645 return &instruction->base;4576 return &instruction->base;
3646}4577}
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,
3649 ResultLoc *result_loc)4580 ResultLoc *result_loc)
3650{4581{
3651 IrInstructionResetResult *instruction = ir_build_instruction<IrInstructionResetResult>(irb, scope, source_node);4582 IrInstSrcResetResult *instruction = ir_build_instruction<IrInstSrcResetResult>(irb, scope, source_node);
3652 instruction->result_loc = result_loc;4583 instruction->result_loc = result_loc;
36534584
3654 return &instruction->base;4585 return &instruction->base;
3655}4586}
36564587
3657static IrInstruction *ir_build_opaque_type(IrBuilder *irb, Scope *scope, AstNode *source_node) {4588static IrInstSrc *ir_build_opaque_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
3658 IrInstructionOpaqueType *instruction = ir_build_instruction<IrInstructionOpaqueType>(irb, scope, source_node);4589 IrInstSrcOpaqueType *instruction = ir_build_instruction<IrInstSrcOpaqueType>(irb, scope, source_node);
36594590
3660 return &instruction->base;4591 return &instruction->base;
3661}4592}
36624593
3663static IrInstruction *ir_build_set_align_stack(IrBuilder *irb, Scope *scope, AstNode *source_node,4594static IrInstSrc *ir_build_set_align_stack(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3664 IrInstruction *align_bytes)4595 IrInstSrc *align_bytes)
3665{4596{
3666 IrInstructionSetAlignStack *instruction = ir_build_instruction<IrInstructionSetAlignStack>(irb, scope, source_node);4597 IrInstSrcSetAlignStack *instruction = ir_build_instruction<IrInstSrcSetAlignStack>(irb, scope, source_node);
3667 instruction->align_bytes = align_bytes;4598 instruction->align_bytes = align_bytes;
36684599
3669 ir_ref_instruction(align_bytes, irb->current_basic_block);4600 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...@@ -3671,10 +4602,10 @@ static IrInstruction *ir_build_set_align_stack(IrBuilder *irb, Scope *scope, Ast
3671 return &instruction->base;4602 return &instruction->base;
3672}4603}
36734604
3674static IrInstruction *ir_build_arg_type(IrBuilder *irb, Scope *scope, AstNode *source_node,4605static IrInstSrc *ir_build_arg_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3675 IrInstruction *fn_type, IrInstruction *arg_index, bool allow_var)4606 IrInstSrc *fn_type, IrInstSrc *arg_index, bool allow_var)
3676{4607{
3677 IrInstructionArgType *instruction = ir_build_instruction<IrInstructionArgType>(irb, scope, source_node);4608 IrInstSrcArgType *instruction = ir_build_instruction<IrInstSrcArgType>(irb, scope, source_node);
3678 instruction->fn_type = fn_type;4609 instruction->fn_type = fn_type;
3679 instruction->arg_index = arg_index;4610 instruction->arg_index = arg_index;
3680 instruction->allow_var = allow_var;4611 instruction->allow_var = allow_var;
...@@ -3685,17 +4616,29 @@ static IrInstruction *ir_build_arg_type(IrBuilder *irb, Scope *scope, AstNode *s...@@ -3685,17 +4616,29 @@ static IrInstruction *ir_build_arg_type(IrBuilder *irb, Scope *scope, AstNode *s
3685 return &instruction->base;4616 return &instruction->base;
3686}4617}
36874618
3688static IrInstruction *ir_build_error_return_trace(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstructionErrorReturnTrace::Optional optional) {4619static IrInstSrc *ir_build_error_return_trace_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3689 IrInstructionErrorReturnTrace *instruction = ir_build_instruction<IrInstructionErrorReturnTrace>(irb, scope, source_node);4620 IrInstErrorReturnTraceOptional optional)
3690 instruction->optional = 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;
3693}4636}
36944637
3695static IrInstruction *ir_build_error_union(IrBuilder *irb, Scope *scope, AstNode *source_node,4638static IrInstSrc *ir_build_error_union(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3696 IrInstruction *err_set, IrInstruction *payload)4639 IrInstSrc *err_set, IrInstSrc *payload)
3697{4640{
3698 IrInstructionErrorUnion *instruction = ir_build_instruction<IrInstructionErrorUnion>(irb, scope, source_node);4641 IrInstSrcErrorUnion *instruction = ir_build_instruction<IrInstSrcErrorUnion>(irb, scope, source_node);
3699 instruction->err_set = err_set;4642 instruction->err_set = err_set;
3700 instruction->payload = payload;4643 instruction->payload = payload;
37014644
...@@ -3705,85 +4648,130 @@ static IrInstruction *ir_build_error_union(IrBuilder *irb, Scope *scope, AstNode...@@ -3705,85 +4648,130 @@ static IrInstruction *ir_build_error_union(IrBuilder *irb, Scope *scope, AstNode
3705 return &instruction->base;4648 return &instruction->base;
3706}4649}
37074650
3708static IrInstruction *ir_build_atomic_rmw(IrBuilder *irb, Scope *scope, AstNode *source_node,4651static IrInstSrc *ir_build_atomic_rmw_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3709 IrInstruction *operand_type, IrInstruction *ptr, IrInstruction *op, IrInstruction *operand,4652 IrInstSrc *operand_type, IrInstSrc *ptr, IrInstSrc *op, IrInstSrc *operand,
3710 IrInstruction *ordering, AtomicRmwOp resolved_op, AtomicOrder resolved_ordering)4653 IrInstSrc *ordering)
3711{4654{
3712 IrInstructionAtomicRmw *instruction = ir_build_instruction<IrInstructionAtomicRmw>(irb, scope, source_node);4655 IrInstSrcAtomicRmw *instruction = ir_build_instruction<IrInstSrcAtomicRmw>(irb, scope, source_node);
3713 instruction->operand_type = operand_type;4656 instruction->operand_type = operand_type;
3714 instruction->ptr = ptr;4657 instruction->ptr = ptr;
3715 instruction->op = op;4658 instruction->op = op;
3716 instruction->operand = operand;4659 instruction->operand = operand;
3717 instruction->ordering = ordering;4660 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);
3722 ir_ref_instruction(ptr, irb->current_basic_block);4663 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);
3724 ir_ref_instruction(operand, irb->current_basic_block);4665 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
3727 return &instruction->base;4684 return &instruction->base;
3728}4685}
37294686
3730static IrInstruction *ir_build_atomic_load(IrBuilder *irb, Scope *scope, AstNode *source_node,4687static IrInstSrc *ir_build_atomic_load_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3731 IrInstruction *operand_type, IrInstruction *ptr,4688 IrInstSrc *operand_type, IrInstSrc *ptr, IrInstSrc *ordering)
3732 IrInstruction *ordering, AtomicOrder resolved_ordering)
3733{4689{
3734 IrInstructionAtomicLoad *instruction = ir_build_instruction<IrInstructionAtomicLoad>(irb, scope, source_node);4690 IrInstSrcAtomicLoad *instruction = ir_build_instruction<IrInstSrcAtomicLoad>(irb, scope, source_node);
3735 instruction->operand_type = operand_type;4691 instruction->operand_type = operand_type;
3736 instruction->ptr = ptr;4692 instruction->ptr = ptr;
3737 instruction->ordering = ordering;4693 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);
3741 ir_ref_instruction(ptr, irb->current_basic_block);4696 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
3744 return &instruction->base;4713 return &instruction->base;
3745}4714}
37464715
3747static IrInstruction *ir_build_atomic_store(IrBuilder *irb, Scope *scope, AstNode *source_node,4716static IrInstSrc *ir_build_atomic_store_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3748 IrInstruction *operand_type, IrInstruction *ptr, IrInstruction *value,4717 IrInstSrc *operand_type, IrInstSrc *ptr, IrInstSrc *value, IrInstSrc *ordering)
3749 IrInstruction *ordering, AtomicOrder resolved_ordering)
3750{4718{
3751 IrInstructionAtomicStore *instruction = ir_build_instruction<IrInstructionAtomicStore>(irb, scope, source_node);4719 IrInstSrcAtomicStore *instruction = ir_build_instruction<IrInstSrcAtomicStore>(irb, scope, source_node);
3752 instruction->operand_type = operand_type;4720 instruction->operand_type = operand_type;
3753 instruction->ptr = ptr;4721 instruction->ptr = ptr;
3754 instruction->value = value;4722 instruction->value = value;
3755 instruction->ordering = ordering;4723 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);
3759 ir_ref_instruction(ptr, irb->current_basic_block);4726 ir_ref_instruction(ptr, irb->current_basic_block);
3760 ir_ref_instruction(value, irb->current_basic_block);4727 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
3763 return &instruction->base;4730 return &instruction->base;
3764}4731}
37654732
3766static IrInstruction *ir_build_save_err_ret_addr(IrBuilder *irb, Scope *scope, AstNode *source_node) {4733static IrInstGen *ir_build_atomic_store_gen(IrAnalyze *ira, IrInst *source_instr,
3767 IrInstructionSaveErrRetAddr *instruction = ir_build_instruction<IrInstructionSaveErrRetAddr>(irb, scope, source_node);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
3768 return &instruction->base;4745 return &instruction->base;
3769}4746}
37704747
3771static IrInstruction *ir_build_add_implicit_return_type(IrBuilder *irb, Scope *scope, AstNode *source_node,4748static IrInstSrc *ir_build_save_err_ret_addr_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
3772 IrInstruction *value, ResultLocReturn *result_loc_ret)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)
3773{4761{
3774 IrInstructionAddImplicitReturnType *instruction = ir_build_instruction<IrInstructionAddImplicitReturnType>(irb, scope, source_node);4762 IrInstSrcAddImplicitReturnType *inst = ir_build_instruction<IrInstSrcAddImplicitReturnType>(irb, scope, source_node);
3775 instruction->value = value;4763 inst->value = value;
3776 instruction->result_loc_ret = result_loc_ret;4764 inst->result_loc_ret = result_loc_ret;
37774765
3778 ir_ref_instruction(value, irb->current_basic_block);4766 ir_ref_instruction(value, irb->current_basic_block);
37794767
3780 return &instruction->base;4768 return &inst->base;
3781}4769}
37824770
3783static IrInstruction *ir_build_has_decl(IrBuilder *irb, Scope *scope, AstNode *source_node,4771static IrInstSrc *ir_build_has_decl(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3784 IrInstruction *container, IrInstruction *name)4772 IrInstSrc *container, IrInstSrc *name)
3785{4773{
3786 IrInstructionHasDecl *instruction = ir_build_instruction<IrInstructionHasDecl>(irb, scope, source_node);4774 IrInstSrcHasDecl *instruction = ir_build_instruction<IrInstSrcHasDecl>(irb, scope, source_node);
3787 instruction->container = container;4775 instruction->container = container;
3788 instruction->name = name;4776 instruction->name = name;
37894777
...@@ -3793,17 +4781,15 @@ static IrInstruction *ir_build_has_decl(IrBuilder *irb, Scope *scope, AstNode *s...@@ -3793,17 +4781,15 @@ static IrInstruction *ir_build_has_decl(IrBuilder *irb, Scope *scope, AstNode *s
3793 return &instruction->base;4781 return &instruction->base;
3794}4782}
37954783
3796static IrInstruction *ir_build_undeclared_identifier(IrBuilder *irb, Scope *scope, AstNode *source_node,4784static IrInstSrc *ir_build_undeclared_identifier(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *name) {
3797 Buf *name)4785 IrInstSrcUndeclaredIdent *instruction = ir_build_instruction<IrInstSrcUndeclaredIdent>(irb, scope, source_node);
3798{
3799 IrInstructionUndeclaredIdent *instruction = ir_build_instruction<IrInstructionUndeclaredIdent>(irb, scope, source_node);
3800 instruction->name = name;4786 instruction->name = name;
38014787
3802 return &instruction->base;4788 return &instruction->base;
3803}4789}
38044790
3805static IrInstruction *ir_build_check_runtime_scope(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *scope_is_comptime, IrInstruction *is_comptime) {4791static IrInstSrc *ir_build_check_runtime_scope(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *scope_is_comptime, IrInstSrc *is_comptime) {
3806 IrInstructionCheckRuntimeScope *instruction = ir_build_instruction<IrInstructionCheckRuntimeScope>(irb, scope, source_node);4792 IrInstSrcCheckRuntimeScope *instruction = ir_build_instruction<IrInstSrcCheckRuntimeScope>(irb, scope, source_node);
3807 instruction->scope_is_comptime = scope_is_comptime;4793 instruction->scope_is_comptime = scope_is_comptime;
3808 instruction->is_comptime = is_comptime;4794 instruction->is_comptime = is_comptime;
38094795
...@@ -3813,10 +4799,10 @@ static IrInstruction *ir_build_check_runtime_scope(IrBuilder *irb, Scope *scope,...@@ -3813,10 +4799,10 @@ static IrInstruction *ir_build_check_runtime_scope(IrBuilder *irb, Scope *scope,
3813 return &instruction->base;4799 return &instruction->base;
3814}4800}
38154801
3816static IrInstruction *ir_build_union_init_named_field(IrBuilder *irb, Scope *scope, AstNode *source_node,4802static IrInstSrc *ir_build_union_init_named_field(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3817 IrInstruction *union_type, IrInstruction *field_name, IrInstruction *field_result_loc, IrInstruction *result_loc)4803 IrInstSrc *union_type, IrInstSrc *field_name, IrInstSrc *field_result_loc, IrInstSrc *result_loc)
3818{4804{
3819 IrInstructionUnionInitNamedField *instruction = ir_build_instruction<IrInstructionUnionInitNamedField>(irb, scope, source_node);4805 IrInstSrcUnionInitNamedField *instruction = ir_build_instruction<IrInstSrcUnionInitNamedField>(irb, scope, source_node);
3820 instruction->union_type = union_type;4806 instruction->union_type = union_type;
3821 instruction->field_name = field_name;4807 instruction->field_name = field_name;
3822 instruction->field_result_loc = field_result_loc;4808 instruction->field_result_loc = field_result_loc;
...@@ -3831,79 +4817,79 @@ static IrInstruction *ir_build_union_init_named_field(IrBuilder *irb, Scope *sco...@@ -3831,79 +4817,79 @@ static IrInstruction *ir_build_union_init_named_field(IrBuilder *irb, Scope *sco
3831}4817}
38324818
38334819
3834static IrInstruction *ir_build_vector_to_array(IrAnalyze *ira, IrInstruction *source_instruction,4820static IrInstGen *ir_build_vector_to_array(IrAnalyze *ira, IrInst *source_instruction,
3835 ZigType *result_type, IrInstruction *vector, IrInstruction *result_loc)4821 ZigType *result_type, IrInstGen *vector, IrInstGen *result_loc)
3836{4822{
3837 IrInstructionVectorToArray *instruction = ir_build_instruction<IrInstructionVectorToArray>(&ira->new_irb,4823 IrInstGenVectorToArray *instruction = ir_build_inst_gen<IrInstGenVectorToArray>(&ira->new_irb,
3838 source_instruction->scope, source_instruction->source_node);4824 source_instruction->scope, source_instruction->source_node);
3839 instruction->base.value->type = result_type;4825 instruction->base.value->type = result_type;
3840 instruction->vector = vector;4826 instruction->vector = vector;
3841 instruction->result_loc = result_loc;4827 instruction->result_loc = result_loc;
38424828
3843 ir_ref_instruction(vector, ira->new_irb.current_basic_block);4829 ir_ref_inst_gen(vector, ira->new_irb.current_basic_block);
3844 ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);4830 ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
38454831
3846 return &instruction->base;4832 return &instruction->base;
3847}4833}
38484834
3849static IrInstruction *ir_build_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruction *source_instruction,4835static IrInstGen *ir_build_ptr_of_array_to_slice(IrAnalyze *ira, IrInst *source_instruction,
3850 ZigType *result_type, IrInstruction *operand, IrInstruction *result_loc)4836 ZigType *result_type, IrInstGen *operand, IrInstGen *result_loc)
3851{4837{
3852 IrInstructionPtrOfArrayToSlice *instruction = ir_build_instruction<IrInstructionPtrOfArrayToSlice>(&ira->new_irb,4838 IrInstGenPtrOfArrayToSlice *instruction = ir_build_inst_gen<IrInstGenPtrOfArrayToSlice>(&ira->new_irb,
3853 source_instruction->scope, source_instruction->source_node);4839 source_instruction->scope, source_instruction->source_node);
3854 instruction->base.value->type = result_type;4840 instruction->base.value->type = result_type;
3855 instruction->operand = operand;4841 instruction->operand = operand;
3856 instruction->result_loc = result_loc;4842 instruction->result_loc = result_loc;
38574843
3858 ir_ref_instruction(operand, ira->new_irb.current_basic_block);4844 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
3859 ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);4845 ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
38604846
3861 return &instruction->base;4847 return &instruction->base;
3862}4848}
38634849
3864static IrInstruction *ir_build_array_to_vector(IrAnalyze *ira, IrInstruction *source_instruction,4850static IrInstGen *ir_build_array_to_vector(IrAnalyze *ira, IrInst *source_instruction,
3865 IrInstruction *array, ZigType *result_type)4851 IrInstGen *array, ZigType *result_type)
3866{4852{
3867 IrInstructionArrayToVector *instruction = ir_build_instruction<IrInstructionArrayToVector>(&ira->new_irb,4853 IrInstGenArrayToVector *instruction = ir_build_inst_gen<IrInstGenArrayToVector>(&ira->new_irb,
3868 source_instruction->scope, source_instruction->source_node);4854 source_instruction->scope, source_instruction->source_node);
3869 instruction->base.value->type = result_type;4855 instruction->base.value->type = result_type;
3870 instruction->array = array;4856 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
3874 return &instruction->base;4860 return &instruction->base;
3875}4861}
38764862
3877static IrInstruction *ir_build_assert_zero(IrAnalyze *ira, IrInstruction *source_instruction,4863static IrInstGen *ir_build_assert_zero(IrAnalyze *ira, IrInst *source_instruction,
3878 IrInstruction *target)4864 IrInstGen *target)
3879{4865{
3880 IrInstructionAssertZero *instruction = ir_build_instruction<IrInstructionAssertZero>(&ira->new_irb,4866 IrInstGenAssertZero *instruction = ir_build_inst_gen<IrInstGenAssertZero>(&ira->new_irb,
3881 source_instruction->scope, source_instruction->source_node);4867 source_instruction->scope, source_instruction->source_node);
3882 instruction->base.value->type = ira->codegen->builtin_types.entry_void;4868 instruction->base.value->type = ira->codegen->builtin_types.entry_void;
3883 instruction->target = target;4869 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
3887 return &instruction->base;4873 return &instruction->base;
3888}4874}
38894875
3890static IrInstruction *ir_build_assert_non_null(IrAnalyze *ira, IrInstruction *source_instruction,4876static IrInstGen *ir_build_assert_non_null(IrAnalyze *ira, IrInst *source_instruction,
3891 IrInstruction *target)4877 IrInstGen *target)
3892{4878{
3893 IrInstructionAssertNonNull *instruction = ir_build_instruction<IrInstructionAssertNonNull>(&ira->new_irb,4879 IrInstGenAssertNonNull *instruction = ir_build_inst_gen<IrInstGenAssertNonNull>(&ira->new_irb,
3894 source_instruction->scope, source_instruction->source_node);4880 source_instruction->scope, source_instruction->source_node);
3895 instruction->base.value->type = ira->codegen->builtin_types.entry_void;4881 instruction->base.value->type = ira->codegen->builtin_types.entry_void;
3896 instruction->target = target;4882 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
3900 return &instruction->base;4886 return &instruction->base;
3901}4887}
39024888
3903static IrInstruction *ir_build_alloca_src(IrBuilder *irb, Scope *scope, AstNode *source_node,4889static IrInstSrc *ir_build_alloca_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3904 IrInstruction *align, const char *name_hint, IrInstruction *is_comptime)4890 IrInstSrc *align, const char *name_hint, IrInstSrc *is_comptime)
3905{4891{
3906 IrInstructionAllocaSrc *instruction = ir_build_instruction<IrInstructionAllocaSrc>(irb, scope, source_node);4892 IrInstSrcAlloca *instruction = ir_build_instruction<IrInstSrcAlloca>(irb, scope, source_node);
3907 instruction->base.is_gen = true;4893 instruction->base.is_gen = true;
3908 instruction->align = align;4894 instruction->align = align;
3909 instruction->name_hint = name_hint;4895 instruction->name_hint = name_hint;
...@@ -3915,10 +4901,10 @@ static IrInstruction *ir_build_alloca_src(IrBuilder *irb, Scope *scope, AstNode...@@ -3915,10 +4901,10 @@ static IrInstruction *ir_build_alloca_src(IrBuilder *irb, Scope *scope, AstNode
3915 return &instruction->base;4901 return &instruction->base;
3916}4902}
39174903
3918static IrInstructionAllocaGen *ir_build_alloca_gen(IrAnalyze *ira, IrInstruction *source_instruction,4904static IrInstGenAlloca *ir_build_alloca_gen(IrAnalyze *ira, IrInst *source_instruction,
3919 uint32_t align, const char *name_hint)4905 uint32_t align, const char *name_hint)
3920{4906{
3921 IrInstructionAllocaGen *instruction = ir_create_instruction<IrInstructionAllocaGen>(&ira->new_irb,4907 IrInstGenAlloca *instruction = ir_create_inst_gen<IrInstGenAlloca>(&ira->new_irb,
3922 source_instruction->scope, source_instruction->source_node);4908 source_instruction->scope, source_instruction->source_node);
3923 instruction->align = align;4909 instruction->align = align;
3924 instruction->name_hint = name_hint;4910 instruction->name_hint = name_hint;
...@@ -3926,10 +4912,10 @@ static IrInstructionAllocaGen *ir_build_alloca_gen(IrAnalyze *ira, IrInstruction...@@ -3926,10 +4912,10 @@ static IrInstructionAllocaGen *ir_build_alloca_gen(IrAnalyze *ira, IrInstruction
3926 return instruction;4912 return instruction;
3927}4913}
39284914
3929static IrInstruction *ir_build_end_expr(IrBuilder *irb, Scope *scope, AstNode *source_node,4915static IrInstSrc *ir_build_end_expr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3930 IrInstruction *value, ResultLoc *result_loc)4916 IrInstSrc *value, ResultLoc *result_loc)
3931{4917{
3932 IrInstructionEndExpr *instruction = ir_build_instruction<IrInstructionEndExpr>(irb, scope, source_node);4918 IrInstSrcEndExpr *instruction = ir_build_instruction<IrInstSrcEndExpr>(irb, scope, source_node);
3933 instruction->base.is_gen = true;4919 instruction->base.is_gen = true;
3934 instruction->value = value;4920 instruction->value = value;
3935 instruction->result_loc = result_loc;4921 instruction->result_loc = result_loc;
...@@ -3939,29 +4925,41 @@ static IrInstruction *ir_build_end_expr(IrBuilder *irb, Scope *scope, AstNode *s...@@ -3939,29 +4925,41 @@ static IrInstruction *ir_build_end_expr(IrBuilder *irb, Scope *scope, AstNode *s
3939 return &instruction->base;4925 return &instruction->base;
3940}4926}
39414927
3942static IrInstructionSuspendBegin *ir_build_suspend_begin(IrBuilder *irb, Scope *scope, AstNode *source_node) {4928static IrInstSrcSuspendBegin *ir_build_suspend_begin_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
3943 IrInstructionSuspendBegin *instruction = ir_build_instruction<IrInstructionSuspendBegin>(irb, scope, source_node);4929 return ir_build_instruction<IrInstSrcSuspendBegin>(irb, scope, source_node);
3944 instruction->base.value->type = irb->codegen->builtin_types.entry_void;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;
3947}4936}
39484937
3949static IrInstruction *ir_build_suspend_finish(IrBuilder *irb, Scope *scope, AstNode *source_node,4938static IrInstSrc *ir_build_suspend_finish_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3950 IrInstructionSuspendBegin *begin)4939 IrInstSrcSuspendBegin *begin)
3951{4940{
3952 IrInstructionSuspendFinish *instruction = ir_build_instruction<IrInstructionSuspendFinish>(irb, scope, source_node);4941 IrInstSrcSuspendFinish *inst = ir_build_instruction<IrInstSrcSuspendFinish>(irb, scope, source_node);
3953 instruction->base.value->type = irb->codegen->builtin_types.entry_void;4942 inst->begin = begin;
3954 instruction->begin = begin;
39554943
3956 ir_ref_instruction(&begin->base, irb->current_basic_block);4944 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;
3959}4957}
39604958
3961static IrInstruction *ir_build_await_src(IrBuilder *irb, Scope *scope, AstNode *source_node,4959static IrInstSrc *ir_build_await_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3962 IrInstruction *frame, ResultLoc *result_loc)4960 IrInstSrc *frame, ResultLoc *result_loc)
3963{4961{
3964 IrInstructionAwaitSrc *instruction = ir_build_instruction<IrInstructionAwaitSrc>(irb, scope, source_node);4962 IrInstSrcAwait *instruction = ir_build_instruction<IrInstSrcAwait>(irb, scope, source_node);
3965 instruction->frame = frame;4963 instruction->frame = frame;
3966 instruction->result_loc = result_loc;4964 instruction->result_loc = result_loc;
39674965
...@@ -3970,24 +4968,23 @@ static IrInstruction *ir_build_await_src(IrBuilder *irb, Scope *scope, AstNode *...@@ -3970,24 +4968,23 @@ static IrInstruction *ir_build_await_src(IrBuilder *irb, Scope *scope, AstNode *
3970 return &instruction->base;4968 return &instruction->base;
3971}4969}
39724970
3973static IrInstructionAwaitGen *ir_build_await_gen(IrAnalyze *ira, IrInstruction *source_instruction,4971static IrInstGenAwait *ir_build_await_gen(IrAnalyze *ira, IrInst *source_instruction,
3974 IrInstruction *frame, ZigType *result_type, IrInstruction *result_loc)4972 IrInstGen *frame, ZigType *result_type, IrInstGen *result_loc)
3975{4973{
3976 IrInstructionAwaitGen *instruction = ir_build_instruction<IrInstructionAwaitGen>(&ira->new_irb,4974 IrInstGenAwait *instruction = ir_build_inst_gen<IrInstGenAwait>(&ira->new_irb,
3977 source_instruction->scope, source_instruction->source_node);4975 source_instruction->scope, source_instruction->source_node);
3978 instruction->base.value->type = result_type;4976 instruction->base.value->type = result_type;
3979 instruction->frame = frame;4977 instruction->frame = frame;
3980 instruction->result_loc = result_loc;4978 instruction->result_loc = result_loc;
39814979
3982 ir_ref_instruction(frame, ira->new_irb.current_basic_block);4980 ir_ref_inst_gen(frame, ira->new_irb.current_basic_block);
3983 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);4981 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
39844982
3985 return instruction;4983 return instruction;
3986}4984}
39874985
3988static IrInstruction *ir_build_resume(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *frame) {4986static IrInstSrc *ir_build_resume_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *frame) {
3989 IrInstructionResume *instruction = ir_build_instruction<IrInstructionResume>(irb, scope, source_node);4987 IrInstSrcResume *instruction = ir_build_instruction<IrInstSrcResume>(irb, scope, source_node);
3990 instruction->base.value->type = irb->codegen->builtin_types.entry_void;
3991 instruction->frame = frame;4988 instruction->frame = frame;
39924989
3993 ir_ref_instruction(frame, irb->current_basic_block);4990 ir_ref_instruction(frame, irb->current_basic_block);
...@@ -3995,12 +4992,20 @@ static IrInstruction *ir_build_resume(IrBuilder *irb, Scope *scope, AstNode *sou...@@ -3995,12 +4992,20 @@ static IrInstruction *ir_build_resume(IrBuilder *irb, Scope *scope, AstNode *sou
3995 return &instruction->base;4992 return &instruction->base;
3996}4993}
39974994
3998static IrInstructionSpillBegin *ir_build_spill_begin(IrBuilder *irb, Scope *scope, AstNode *source_node,4995static IrInstGen *ir_build_resume_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *frame) {
3999 IrInstruction *operand, SpillId spill_id)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)
4000{5007{
4001 IrInstructionSpillBegin *instruction = ir_build_instruction<IrInstructionSpillBegin>(irb, scope, source_node);5008 IrInstSrcSpillBegin *instruction = ir_build_instruction<IrInstSrcSpillBegin>(irb, scope, source_node);
4002 instruction->base.value->special = ConstValSpecialStatic;
4003 instruction->base.value->type = irb->codegen->builtin_types.entry_void;
4004 instruction->operand = operand;5009 instruction->operand = operand;
4005 instruction->spill_id = spill_id;5010 instruction->spill_id = spill_id;
40065011
...@@ -4009,10 +5014,23 @@ static IrInstructionSpillBegin *ir_build_spill_begin(IrBuilder *irb, Scope *scop...@@ -4009,10 +5014,23 @@ static IrInstructionSpillBegin *ir_build_spill_begin(IrBuilder *irb, Scope *scop
4009 return instruction;5014 return instruction;
4010}5015}
40115016
4012static IrInstruction *ir_build_spill_end(IrBuilder *irb, Scope *scope, AstNode *source_node,5017static IrInstGen *ir_build_spill_begin_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand,
4013 IrInstructionSpillBegin *begin)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)
4014{5032{
4015 IrInstructionSpillEnd *instruction = ir_build_instruction<IrInstructionSpillEnd>(irb, scope, source_node);5033 IrInstSrcSpillEnd *instruction = ir_build_instruction<IrInstSrcSpillEnd>(irb, scope, source_node);
4016 instruction->begin = begin;5034 instruction->begin = begin;
40175035
4018 ir_ref_instruction(&begin->base, irb->current_basic_block);5036 ir_ref_instruction(&begin->base, irb->current_basic_block);
...@@ -4020,22 +5038,35 @@ static IrInstruction *ir_build_spill_end(IrBuilder *irb, Scope *scope, AstNode *...@@ -4020,22 +5038,35 @@ static IrInstruction *ir_build_spill_end(IrBuilder *irb, Scope *scope, AstNode *
4020 return &instruction->base;5038 return &instruction->base;
4021}5039}
40225040
4023static IrInstruction *ir_build_vector_extract_elem(IrAnalyze *ira, IrInstruction *source_instruction,5041static IrInstGen *ir_build_spill_end_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGenSpillBegin *begin,
4024 IrInstruction *vector, IrInstruction *index)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)
4025{5056{
4026 IrInstructionVectorExtractElem *instruction = ir_build_instruction<IrInstructionVectorExtractElem>(5057 IrInstGenVectorExtractElem *instruction = ir_build_inst_gen<IrInstGenVectorExtractElem>(
4027 &ira->new_irb, source_instruction->scope, source_instruction->source_node);5058 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
4028 instruction->base.value->type = vector->value->type->data.vector.elem_type;5059 instruction->base.value->type = vector->value->type->data.vector.elem_type;
4029 instruction->vector = vector;5060 instruction->vector = vector;
4030 instruction->index = index;5061 instruction->index = index;
40315062
4032 ir_ref_instruction(vector, ira->new_irb.current_basic_block);5063 ir_ref_inst_gen(vector, ira->new_irb.current_basic_block);
4033 ir_ref_instruction(index, ira->new_irb.current_basic_block);5064 ir_ref_inst_gen(index, ira->new_irb.current_basic_block);
40345065
4035 return &instruction->base;5066 return &instruction->base;
4036}5067}
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) {
4039 results[ReturnKindUnconditional] = 0;5070 results[ReturnKindUnconditional] = 0;
4040 results[ReturnKindError] = 0;5071 results[ReturnKindError] = 0;
40415072
...@@ -4072,12 +5103,12 @@ static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_sco...@@ -4072,12 +5103,12 @@ static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_sco
4072 }5103 }
4073}5104}
40745105
4075static IrInstruction *ir_mark_gen(IrInstruction *instruction) {5106static IrInstSrc *ir_mark_gen(IrInstSrc *instruction) {
4076 instruction->is_gen = true;5107 instruction->is_gen = true;
4077 return instruction;5108 return instruction;
4078}5109}
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) {
4081 Scope *scope = inner_scope;5112 Scope *scope = inner_scope;
4082 bool is_noreturn = false;5113 bool is_noreturn = false;
4083 while (scope != outer_scope) {5114 while (scope != outer_scope) {
...@@ -4094,11 +5125,9 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o...@@ -4094,11 +5125,9 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o
4094 {5125 {
4095 AstNode *defer_expr_node = defer_node->data.defer.expr;5126 AstNode *defer_expr_node = defer_node->data.defer.expr;
4096 Scope *defer_expr_scope = defer_node->data.defer.expr_scope;5127 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);5128 IrInstSrc *defer_expr_value = ir_gen_node(irb, defer_expr_node, defer_expr_scope);
4098 if (defer_expr_value != irb->codegen->invalid_instruction) {5129 if (defer_expr_value != irb->codegen->invalid_inst_src) {
4099 if (defer_expr_value->value->type != nullptr &&5130 if (defer_expr_value->is_noreturn) {
4100 defer_expr_value->value->type->id == ZigTypeIdUnreachable)
4101 {
4102 is_noreturn = true;5131 is_noreturn = true;
4103 } else {5132 } else {
4104 ir_mark_gen(ir_build_check_statement_is_void(irb, defer_expr_scope, defer_expr_node,5133 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...@@ -4130,13 +5159,17 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o
4130 return is_noreturn;5159 return is_noreturn;
4131}5160}
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) {
4134 assert(basic_block);5163 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);
4136 irb->current_basic_block = basic_block;5169 irb->current_basic_block = basic_block;
4137}5170}
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) {
4140 basic_block->index = irb->exec->basic_block_list.length;5173 basic_block->index = irb->exec->basic_block_list.length;
4141 irb->exec->basic_block_list.append(basic_block);5174 irb->exec->basic_block_list.append(basic_block);
4142 ir_set_cursor_at_end(irb, basic_block);5175 ir_set_cursor_at_end(irb, basic_block);
...@@ -4166,13 +5199,13 @@ static ScopeDeferExpr *get_scope_defer_expr(Scope *scope) {...@@ -4166,13 +5199,13 @@ static ScopeDeferExpr *get_scope_defer_expr(Scope *scope) {
4166 return nullptr;5199 return nullptr;
4167}5200}
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) {
4170 assert(node->type == NodeTypeReturnExpr);5203 assert(node->type == NodeTypeReturnExpr);
41715204
4172 ZigFn *fn_entry = exec_fn_entry(irb->exec);5205 ZigFn *fn_entry = exec_fn_entry(irb->exec);
4173 if (!fn_entry) {5206 if (!fn_entry) {
4174 add_node_error(irb->codegen, node, buf_sprintf("return expression outside function definition"));5207 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;
4176 }5209 }
41775210
4178 ScopeDeferExpr *scope_defer_expr = get_scope_defer_expr(scope);5211 ScopeDeferExpr *scope_defer_expr = get_scope_defer_expr(scope);
...@@ -4181,7 +5214,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -4181,7 +5214,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
4181 add_node_error(irb->codegen, node, buf_sprintf("cannot return from defer expression"));5214 add_node_error(irb->codegen, node, buf_sprintf("cannot return from defer expression"));
4182 scope_defer_expr->reported_err = true;5215 scope_defer_expr->reported_err = true;
4183 }5216 }
4184 return irb->codegen->invalid_instruction;5217 return irb->codegen->invalid_inst_src;
4185 }5218 }
41865219
4187 Scope *outer_scope = irb->exec->begin_scope;5220 Scope *outer_scope = irb->exec->begin_scope;
...@@ -4194,15 +5227,15 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -4194,15 +5227,15 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
4194 result_loc_ret->base.id = ResultLocIdReturn;5227 result_loc_ret->base.id = ResultLocIdReturn;
4195 ir_build_reset_result(irb, scope, node, &result_loc_ret->base);5228 ir_build_reset_result(irb, scope, node, &result_loc_ret->base);
41965229
4197 IrInstruction *return_value;5230 IrInstSrc *return_value;
4198 if (expr_node) {5231 if (expr_node) {
4199 // Temporarily set this so that if we return a type it gets the name of the function5232 // Temporarily set this so that if we return a type it gets the name of the function
4200 ZigFn *prev_name_fn = irb->exec->name_fn;5233 ZigFn *prev_name_fn = irb->exec->name_fn;
4201 irb->exec->name_fn = exec_fn_entry(irb->exec);5234 irb->exec->name_fn = exec_fn_entry(irb->exec);
4202 return_value = ir_gen_node_extra(irb, expr_node, scope, LValNone, &result_loc_ret->base);5235 return_value = ir_gen_node_extra(irb, expr_node, scope, LValNone, &result_loc_ret->base);
4203 irb->exec->name_fn = prev_name_fn;5236 irb->exec->name_fn = prev_name_fn;
4204 if (return_value == irb->codegen->invalid_instruction)5237 if (return_value == irb->codegen->invalid_inst_src)
4205 return irb->codegen->invalid_instruction;5238 return irb->codegen->invalid_inst_src;
4206 } else {5239 } else {
4207 return_value = ir_build_const_void(irb, scope, node);5240 return_value = ir_build_const_void(irb, scope, node);
4208 }5241 }
...@@ -4215,22 +5248,22 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -4215,22 +5248,22 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
4215 if (!have_err_defers && !irb->codegen->have_err_ret_tracing) {5248 if (!have_err_defers && !irb->codegen->have_err_ret_tracing) {
4216 // only generate unconditional defers5249 // only generate unconditional defers
4217 ir_gen_defers_for_block(irb, scope, outer_scope, false);5250 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);
4219 result_loc_ret->base.source_instruction = result;5252 result_loc_ret->base.source_instruction = result;
4220 return result;5253 return result;
4221 }5254 }
4222 bool should_inline = ir_should_inline(irb->exec, scope);5255 bool should_inline = ir_should_inline(irb->exec, scope);
42235256
4224 IrBasicBlock *err_block = ir_create_basic_block(irb, scope, "ErrRetErr");5257 IrBasicBlockSrc *err_block = ir_create_basic_block(irb, scope, "ErrRetErr");
4225 IrBasicBlock *ok_block = ir_create_basic_block(irb, scope, "ErrRetOk");5258 IrBasicBlockSrc *ok_block = ir_create_basic_block(irb, scope, "ErrRetOk");
42265259
4227 if (!have_err_defers) {5260 if (!have_err_defers) {
4228 ir_gen_defers_for_block(irb, scope, outer_scope, false);5261 ir_gen_defers_for_block(irb, scope, outer_scope, false);
4229 }5262 }
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;
4234 if (should_inline) {5267 if (should_inline) {
4235 is_comptime = ir_build_const_bool(irb, scope, node, should_inline);5268 is_comptime = ir_build_const_bool(irb, scope, node, should_inline);
4236 } else {5269 } else {
...@@ -4238,14 +5271,14 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -4238,14 +5271,14 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
4238 }5271 }
42395272
4240 ir_mark_gen(ir_build_cond_br(irb, scope, node, is_err, err_block, ok_block, is_comptime));5273 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
4243 ir_set_cursor_at_end_and_append_block(irb, err_block);5276 ir_set_cursor_at_end_and_append_block(irb, err_block);
4244 if (have_err_defers) {5277 if (have_err_defers) {
4245 ir_gen_defers_for_block(irb, scope, outer_scope, true);5278 ir_gen_defers_for_block(irb, scope, outer_scope, true);
4246 }5279 }
4247 if (irb->codegen->have_err_ret_tracing && !should_inline) {5280 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);
4249 }5282 }
4250 ir_build_br(irb, scope, node, ret_stmt_block, is_comptime);5283 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,...@@ -4256,21 +5289,21 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
4256 ir_build_br(irb, scope, node, ret_stmt_block, is_comptime);5289 ir_build_br(irb, scope, node, ret_stmt_block, is_comptime);
42575290
4258 ir_set_cursor_at_end_and_append_block(irb, ret_stmt_block);5291 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);
4260 result_loc_ret->base.source_instruction = result;5293 result_loc_ret->base.source_instruction = result;
4261 return result;5294 return result;
4262 }5295 }
4263 case ReturnKindError:5296 case ReturnKindError:
4264 {5297 {
4265 assert(expr_node);5298 assert(expr_node);
4266 IrInstruction *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);5299 IrInstSrc *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
4267 if (err_union_ptr == irb->codegen->invalid_instruction)5300 if (err_union_ptr == irb->codegen->invalid_inst_src)
4268 return irb->codegen->invalid_instruction;5301 return irb->codegen->invalid_inst_src;
4269 IrInstruction *is_err_val = ir_build_test_err_src(irb, scope, node, err_union_ptr, true, false);5302 IrInstSrc *is_err_val = ir_build_test_err_src(irb, scope, node, err_union_ptr, true, false);
42705303
4271 IrBasicBlock *return_block = ir_create_basic_block(irb, scope, "ErrRetReturn");5304 IrBasicBlockSrc *return_block = ir_create_basic_block(irb, scope, "ErrRetReturn");
4272 IrBasicBlock *continue_block = ir_create_basic_block(irb, scope, "ErrRetContinue");5305 IrBasicBlockSrc *continue_block = ir_create_basic_block(irb, scope, "ErrRetContinue");
4273 IrInstruction *is_comptime;5306 IrInstSrc *is_comptime;
4274 bool should_inline = ir_should_inline(irb->exec, scope);5307 bool should_inline = ir_should_inline(irb->exec, scope);
4275 if (should_inline) {5308 if (should_inline) {
4276 is_comptime = ir_build_const_bool(irb, scope, node, true);5309 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,...@@ -4280,10 +5313,10 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
4280 ir_mark_gen(ir_build_cond_br(irb, scope, node, is_err_val, return_block, continue_block, is_comptime));5313 ir_mark_gen(ir_build_cond_br(irb, scope, node, is_err_val, return_block, continue_block, is_comptime));
42815314
4282 ir_set_cursor_at_end_and_append_block(irb, return_block);5315 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);5316 IrInstSrc *err_val_ptr = ir_build_unwrap_err_code_src(irb, scope, node, err_union_ptr);
4284 IrInstruction *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr);5317 IrInstSrc *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr);
4285 ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, node, err_val, nullptr));5318 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,
4287 SpillIdRetErrCode);5320 SpillIdRetErrCode);
4288 ResultLocReturn *result_loc_ret = allocate<ResultLocReturn>(1, "ResultLocReturn");5321 ResultLocReturn *result_loc_ret = allocate<ResultLocReturn>(1, "ResultLocReturn");
4289 result_loc_ret->base.id = ResultLocIdReturn;5322 result_loc_ret->base.id = ResultLocIdReturn;
...@@ -4291,15 +5324,15 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -4291,15 +5324,15 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
4291 ir_build_end_expr(irb, scope, node, err_val, &result_loc_ret->base);5324 ir_build_end_expr(irb, scope, node, err_val, &result_loc_ret->base);
4292 if (!ir_gen_defers_for_block(irb, scope, outer_scope, true)) {5325 if (!ir_gen_defers_for_block(irb, scope, outer_scope, true)) {
4293 if (irb->codegen->have_err_ret_tracing && !should_inline) {5326 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);
4295 }5328 }
4296 err_val = ir_build_spill_end(irb, scope, node, spill_begin);5329 err_val = ir_build_spill_end_src(irb, scope, node, spill_begin);
4297 IrInstruction *ret_inst = ir_build_return(irb, scope, node, err_val);5330 IrInstSrc *ret_inst = ir_build_return_src(irb, scope, node, err_val);
4298 result_loc_ret->base.source_instruction = ret_inst;5331 result_loc_ret->base.source_instruction = ret_inst;
4299 }5332 }
43005333
4301 ir_set_cursor_at_end_and_append_block(irb, continue_block);5334 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);
4303 if (lval == LValPtr)5336 if (lval == LValPtr)
4304 return unwrapped_ptr;5337 return unwrapped_ptr;
4305 else5338 else
...@@ -4310,7 +5343,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -4310,7 +5343,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
4310}5343}
43115344
4312static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_scope,5345static 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,
4314 bool skip_name_check)5347 bool skip_name_check)
4315{5348{
4316 ZigVar *variable_entry = allocate<ZigVar>(1, "ZigVar");5349 ZigVar *variable_entry = allocate<ZigVar>(1, "ZigVar");
...@@ -4322,7 +5355,7 @@ static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_s...@@ -4322,7 +5355,7 @@ static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_s
4322 variable_entry->const_value = create_const_vals(1);5355 variable_entry->const_value = create_const_vals(1);
43235356
4324 if (is_comptime != nullptr) {5357 if (is_comptime != nullptr) {
4325 is_comptime->ref_count += 1;5358 is_comptime->base.ref_count += 1;
4326 }5359 }
43275360
4328 if (name) {5361 if (name) {
...@@ -4372,8 +5405,8 @@ static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_s...@@ -4372,8 +5405,8 @@ static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_s
43725405
4373// Set name to nullptr to make the variable anonymous (not visible to programmer).5406// Set name to nullptr to make the variable anonymous (not visible to programmer).
4374// After you call this function var->child_scope has the variable in scope5407// 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,5408static ZigVar *ir_create_var(IrBuilderSrc *irb, AstNode *node, Scope *scope, Buf *name,
4376 bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstruction *is_comptime)5409 bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstSrc *is_comptime)
4377{5410{
4378 bool is_underscored = name ? buf_eql_str(name, "_") : false;5411 bool is_underscored = name ? buf_eql_str(name, "_") : false;
4379 ZigVar *var = create_local_var(irb->codegen, node, scope,5412 ZigVar *var = create_local_var(irb->codegen, node, scope,
...@@ -4396,13 +5429,13 @@ static ResultLocPeer *create_peer_result(ResultLocPeerParent *peer_parent) {...@@ -4396,13 +5429,13 @@ static ResultLocPeer *create_peer_result(ResultLocPeerParent *peer_parent) {
4396 return result;5429 return result;
4397}5430}
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,
4400 ResultLoc *result_loc)5433 ResultLoc *result_loc)
4401{5434{
4402 assert(block_node->type == NodeTypeBlock);5435 assert(block_node->type == NodeTypeBlock);
44035436
4404 ZigList<IrInstruction *> incoming_values = {0};5437 ZigList<IrInstSrc *> incoming_values = {0};
4405 ZigList<IrBasicBlock *> incoming_blocks = {0};5438 ZigList<IrBasicBlockSrc *> incoming_blocks = {0};
44065439
4407 ScopeBlock *scope_block = create_block_scope(irb->codegen, block_node, parent_scope);5440 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...@@ -4438,11 +5471,11 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
4438 }5471 }
44395472
4440 bool is_continuation_unreachable = false;5473 bool is_continuation_unreachable = false;
4441 IrInstruction *noreturn_return_value = nullptr;5474 IrInstSrc *noreturn_return_value = nullptr;
4442 for (size_t i = 0; i < block_node->data.block.statements.length; i += 1) {5475 for (size_t i = 0; i < block_node->data.block.statements.length; i += 1) {
4443 AstNode *statement_node = block_node->data.block.statements.at(i);5476 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);
4446 is_continuation_unreachable = instr_is_unreachable(statement_value);5479 is_continuation_unreachable = instr_is_unreachable(statement_value);
4447 if (is_continuation_unreachable) {5480 if (is_continuation_unreachable) {
4448 // keep the last noreturn statement value around in case we need to return it5481 // 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...@@ -4450,15 +5483,15 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
4450 }5483 }
4451 // This logic must be kept in sync with5484 // This logic must be kept in sync with
4452 // [STMT_EXPR_TEST_THING] <--- (search this token)5485 // [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) {
4454 // defer starts a new scope5487 // defer starts a new scope
4455 child_scope = statement_node->data.defer.child_scope;5488 child_scope = statement_node->data.defer.child_scope;
4456 assert(child_scope);5489 assert(child_scope);
4457 } else if (statement_value->id == IrInstructionIdDeclVarSrc) {5490 } else if (statement_value->id == IrInstSrcIdDeclVar) {
4458 // variable declarations start a new scope5491 // variable declarations start a new scope
4459 IrInstructionDeclVarSrc *decl_var_instruction = (IrInstructionDeclVarSrc *)statement_value;5492 IrInstSrcDeclVar *decl_var_instruction = (IrInstSrcDeclVar *)statement_value;
4460 child_scope = decl_var_instruction->var->child_scope;5493 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) {
4462 // this statement's value must be void5495 // this statement's value must be void
4463 ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, statement_node, statement_value));5496 ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, statement_node, statement_value));
4464 }5497 }
...@@ -4474,12 +5507,12 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode...@@ -4474,12 +5507,12 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
4474 scope_block->peer_parent->peers.last()->next_bb = scope_block->end_block;5507 scope_block->peer_parent->peers.last()->next_bb = scope_block->end_block;
4475 }5508 }
4476 ir_set_cursor_at_end_and_append_block(irb, scope_block->end_block);5509 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,
4478 incoming_blocks.items, incoming_values.items, scope_block->peer_parent);5511 incoming_blocks.items, incoming_values.items, scope_block->peer_parent);
4479 return ir_expr_wrap(irb, parent_scope, phi, result_loc);5512 return ir_expr_wrap(irb, parent_scope, phi, result_loc);
4480 } else {5513 } else {
4481 incoming_blocks.append(irb->current_basic_block);5514 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
4484 if (scope_block->peer_parent != nullptr) {5517 if (scope_block->peer_parent != nullptr) {
4485 ResultLocPeer *peer_result = create_peer_result(scope_block->peer_parent);5518 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...@@ -4499,15 +5532,15 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
4499 ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false);5532 ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false);
4500 }5533 }
45015534
4502 IrInstruction *result;5535 IrInstSrc *result;
4503 if (block_node->data.block.name != nullptr) {5536 if (block_node->data.block.name != nullptr) {
4504 ir_mark_gen(ir_build_br(irb, parent_scope, block_node, scope_block->end_block, scope_block->is_comptime));5537 ir_mark_gen(ir_build_br(irb, parent_scope, block_node, scope_block->end_block, scope_block->is_comptime));
4505 ir_set_cursor_at_end_and_append_block(irb, scope_block->end_block);5538 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,
4507 incoming_blocks.items, incoming_values.items, scope_block->peer_parent);5540 incoming_blocks.items, incoming_values.items, scope_block->peer_parent);
4508 result = ir_expr_wrap(irb, parent_scope, phi, result_loc);5541 result = ir_expr_wrap(irb, parent_scope, phi, result_loc);
4509 } else {5542 } 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));
4511 result = ir_lval_wrap(irb, parent_scope, void_inst, lval, result_loc);5544 result = ir_lval_wrap(irb, parent_scope, void_inst, lval, result_loc);
4512 }5545 }
4513 if (!is_return_from_fn)5546 if (!is_return_from_fn)
...@@ -4518,30 +5551,30 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode...@@ -4518,30 +5551,30 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
45185551
4519 ir_mark_gen(ir_build_add_implicit_return_type(irb, child_scope, block_node, result, nullptr));5552 ir_mark_gen(ir_build_add_implicit_return_type(irb, child_scope, block_node, result, nullptr));
4520 ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false);5553 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));
4522}5555}
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) {
4525 Scope *inner_scope = scope;5558 Scope *inner_scope = scope;
4526 if (op_id == IrBinOpArrayCat || op_id == IrBinOpArrayMult) {5559 if (op_id == IrBinOpArrayCat || op_id == IrBinOpArrayMult) {
4527 inner_scope = create_comptime_scope(irb->codegen, node, scope);5560 inner_scope = create_comptime_scope(irb->codegen, node, scope);
4528 }5561 }
45295562
4530 IrInstruction *op1 = ir_gen_node(irb, node->data.bin_op_expr.op1, inner_scope);5563 IrInstSrc *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);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)5566 if (op1 == irb->codegen->invalid_inst_src || op2 == irb->codegen->invalid_inst_src)
4534 return irb->codegen->invalid_instruction;5567 return irb->codegen->invalid_inst_src;
45355568
4536 return ir_build_bin_op(irb, scope, node, op_id, op1, op2, true);5569 return ir_build_bin_op(irb, scope, node, op_id, op1, op2, true);
4537}5570}
45385571
4539static IrInstruction *ir_gen_merge_err_sets(IrBuilder *irb, Scope *scope, AstNode *node) {5572static IrInstSrc *ir_gen_merge_err_sets(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
4540 IrInstruction *op1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope);5573 IrInstSrc *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);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)5576 if (op1 == irb->codegen->invalid_inst_src || op2 == irb->codegen->invalid_inst_src)
4544 return irb->codegen->invalid_instruction;5577 return irb->codegen->invalid_inst_src;
45455578
4546 // TODO only pass type_name when the || operator is the top level AST node in the var decl expr5579 // TODO only pass type_name when the || operator is the top level AST node in the var decl expr
4547 Buf bare_name = BUF_INIT;5580 Buf bare_name = BUF_INIT;
...@@ -4550,10 +5583,10 @@ static IrInstruction *ir_gen_merge_err_sets(IrBuilder *irb, Scope *scope, AstNod...@@ -4550,10 +5583,10 @@ static IrInstruction *ir_gen_merge_err_sets(IrBuilder *irb, Scope *scope, AstNod
4550 return ir_build_merge_err_sets(irb, scope, node, op1, op2, type_name);5583 return ir_build_merge_err_sets(irb, scope, node, op1, op2, type_name);
4551}5584}
45525585
4553static IrInstruction *ir_gen_assign(IrBuilder *irb, Scope *scope, AstNode *node) {5586static IrInstSrc *ir_gen_assign(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
4554 IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr);5587 IrInstSrc *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr);
4555 if (lvalue == irb->codegen->invalid_instruction)5588 if (lvalue == irb->codegen->invalid_inst_src)
4556 return irb->codegen->invalid_instruction;5589 return irb->codegen->invalid_inst_src;
45575590
4558 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1, "ResultLocInstruction");5591 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1, "ResultLocInstruction");
4559 result_loc_inst->base.id = ResultLocIdInstruction;5592 result_loc_inst->base.id = ResultLocIdInstruction;
...@@ -4561,49 +5594,49 @@ static IrInstruction *ir_gen_assign(IrBuilder *irb, Scope *scope, AstNode *node)...@@ -4561,49 +5594,49 @@ static IrInstruction *ir_gen_assign(IrBuilder *irb, Scope *scope, AstNode *node)
4561 ir_ref_instruction(lvalue, irb->current_basic_block);5594 ir_ref_instruction(lvalue, irb->current_basic_block);
4562 ir_build_reset_result(irb, scope, node, &result_loc_inst->base);5595 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,
4565 &result_loc_inst->base);5598 &result_loc_inst->base);
4566 if (rvalue == irb->codegen->invalid_instruction)5599 if (rvalue == irb->codegen->invalid_inst_src)
4567 return irb->codegen->invalid_instruction;5600 return irb->codegen->invalid_inst_src;
45685601
4569 return ir_build_const_void(irb, scope, node);5602 return ir_build_const_void(irb, scope, node);
4570}5603}
45715604
4572static IrInstruction *ir_gen_assign_merge_err_sets(IrBuilder *irb, Scope *scope, AstNode *node) {5605static IrInstSrc *ir_gen_assign_merge_err_sets(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
4573 IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr);5606 IrInstSrc *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr);
4574 if (lvalue == irb->codegen->invalid_instruction)5607 if (lvalue == irb->codegen->invalid_inst_src)
4575 return lvalue;5608 return lvalue;
4576 IrInstruction *op1 = ir_build_load_ptr(irb, scope, node->data.bin_op_expr.op1, lvalue);5609 IrInstSrc *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);5610 IrInstSrc *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
4578 if (op2 == irb->codegen->invalid_instruction)5611 if (op2 == irb->codegen->invalid_inst_src)
4579 return op2;5612 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);
4581 ir_build_store_ptr(irb, scope, node, lvalue, result);5614 ir_build_store_ptr(irb, scope, node, lvalue, result);
4582 return ir_build_const_void(irb, scope, node);5615 return ir_build_const_void(irb, scope, node);
4583}5616}
45845617
4585static IrInstruction *ir_gen_assign_op(IrBuilder *irb, Scope *scope, AstNode *node, IrBinOp op_id) {5618static IrInstSrc *ir_gen_assign_op(IrBuilderSrc *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);5619 IrInstSrc *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr);
4587 if (lvalue == irb->codegen->invalid_instruction)5620 if (lvalue == irb->codegen->invalid_inst_src)
4588 return lvalue;5621 return lvalue;
4589 IrInstruction *op1 = ir_build_load_ptr(irb, scope, node->data.bin_op_expr.op1, lvalue);5622 IrInstSrc *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);5623 IrInstSrc *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
4591 if (op2 == irb->codegen->invalid_instruction)5624 if (op2 == irb->codegen->invalid_inst_src)
4592 return op2;5625 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);
4594 ir_build_store_ptr(irb, scope, node, lvalue, result);5627 ir_build_store_ptr(irb, scope, node, lvalue, result);
4595 return ir_build_const_void(irb, scope, node);5628 return ir_build_const_void(irb, scope, node);
4596}5629}
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) {
4599 assert(node->type == NodeTypeBinOpExpr);5632 assert(node->type == NodeTypeBinOpExpr);
46005633
4601 IrInstruction *val1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope);5634 IrInstSrc *val1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope);
4602 if (val1 == irb->codegen->invalid_instruction)5635 if (val1 == irb->codegen->invalid_inst_src)
4603 return irb->codegen->invalid_instruction;5636 return irb->codegen->invalid_inst_src;
4604 IrBasicBlock *post_val1_block = irb->current_basic_block;5637 IrBasicBlockSrc *post_val1_block = irb->current_basic_block;
46055638
4606 IrInstruction *is_comptime;5639 IrInstSrc *is_comptime;
4607 if (ir_should_inline(irb->exec, scope)) {5640 if (ir_should_inline(irb->exec, scope)) {
4608 is_comptime = ir_build_const_bool(irb, scope, node, true);5641 is_comptime = ir_build_const_bool(irb, scope, node, true);
4609 } else {5642 } else {
...@@ -4611,41 +5644,41 @@ static IrInstruction *ir_gen_bool_or(IrBuilder *irb, Scope *scope, AstNode *node...@@ -4611,41 +5644,41 @@ static IrInstruction *ir_gen_bool_or(IrBuilder *irb, Scope *scope, AstNode *node
4611 }5644 }
46125645
4613 // block for when val1 == false5646 // 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");
4615 // block for when val1 == true (don't even evaluate the second part)5648 // 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
4618 ir_build_cond_br(irb, scope, node, val1, true_block, false_block, is_comptime);5651 ir_build_cond_br(irb, scope, node, val1, true_block, false_block, is_comptime);
46195652
4620 ir_set_cursor_at_end_and_append_block(irb, false_block);5653 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);5654 IrInstSrc *val2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
4622 if (val2 == irb->codegen->invalid_instruction)5655 if (val2 == irb->codegen->invalid_inst_src)
4623 return irb->codegen->invalid_instruction;5656 return irb->codegen->invalid_inst_src;
4624 IrBasicBlock *post_val2_block = irb->current_basic_block;5657 IrBasicBlockSrc *post_val2_block = irb->current_basic_block;
46255658
4626 ir_build_br(irb, scope, node, true_block, is_comptime);5659 ir_build_br(irb, scope, node, true_block, is_comptime);
46275660
4628 ir_set_cursor_at_end_and_append_block(irb, true_block);5661 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 *");
4631 incoming_values[0] = val1;5664 incoming_values[0] = val1;
4632 incoming_values[1] = val2;5665 incoming_values[1] = val2;
4633 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *");5666 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
4634 incoming_blocks[0] = post_val1_block;5667 incoming_blocks[0] = post_val1_block;
4635 incoming_blocks[1] = post_val2_block;5668 incoming_blocks[1] = post_val2_block;
46365669
4637 return ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, nullptr);5670 return ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, nullptr);
4638}5671}
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) {
4641 assert(node->type == NodeTypeBinOpExpr);5674 assert(node->type == NodeTypeBinOpExpr);
46425675
4643 IrInstruction *val1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope);5676 IrInstSrc *val1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope);
4644 if (val1 == irb->codegen->invalid_instruction)5677 if (val1 == irb->codegen->invalid_inst_src)
4645 return irb->codegen->invalid_instruction;5678 return irb->codegen->invalid_inst_src;
4646 IrBasicBlock *post_val1_block = irb->current_basic_block;5679 IrBasicBlockSrc *post_val1_block = irb->current_basic_block;
46475680
4648 IrInstruction *is_comptime;5681 IrInstSrc *is_comptime;
4649 if (ir_should_inline(irb->exec, scope)) {5682 if (ir_should_inline(irb->exec, scope)) {
4650 is_comptime = ir_build_const_bool(irb, scope, node, true);5683 is_comptime = ir_build_const_bool(irb, scope, node, true);
4651 } else {5684 } else {
...@@ -4653,34 +5686,34 @@ static IrInstruction *ir_gen_bool_and(IrBuilder *irb, Scope *scope, AstNode *nod...@@ -4653,34 +5686,34 @@ static IrInstruction *ir_gen_bool_and(IrBuilder *irb, Scope *scope, AstNode *nod
4653 }5686 }
46545687
4655 // block for when val1 == true5688 // 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");
4657 // block for when val1 == false (don't even evaluate the second part)5690 // 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
4660 ir_build_cond_br(irb, scope, node, val1, true_block, false_block, is_comptime);5693 ir_build_cond_br(irb, scope, node, val1, true_block, false_block, is_comptime);
46615694
4662 ir_set_cursor_at_end_and_append_block(irb, true_block);5695 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);5696 IrInstSrc *val2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
4664 if (val2 == irb->codegen->invalid_instruction)5697 if (val2 == irb->codegen->invalid_inst_src)
4665 return irb->codegen->invalid_instruction;5698 return irb->codegen->invalid_inst_src;
4666 IrBasicBlock *post_val2_block = irb->current_basic_block;5699 IrBasicBlockSrc *post_val2_block = irb->current_basic_block;
46675700
4668 ir_build_br(irb, scope, node, false_block, is_comptime);5701 ir_build_br(irb, scope, node, false_block, is_comptime);
46695702
4670 ir_set_cursor_at_end_and_append_block(irb, false_block);5703 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);
4673 incoming_values[0] = val1;5706 incoming_values[0] = val1;
4674 incoming_values[1] = val2;5707 incoming_values[1] = val2;
4675 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *");5708 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
4676 incoming_blocks[0] = post_val1_block;5709 incoming_blocks[0] = post_val1_block;
4677 incoming_blocks[1] = post_val2_block;5710 incoming_blocks[1] = post_val2_block;
46785711
4679 return ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, nullptr);5712 return ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, nullptr);
4680}5713}
46815714
4682static ResultLocPeerParent *ir_build_result_peers(IrBuilder *irb, IrInstruction *cond_br_inst,5715static ResultLocPeerParent *ir_build_result_peers(IrBuilderSrc *irb, IrInstSrc *cond_br_inst,
4683 IrBasicBlock *end_block, ResultLoc *parent, IrInstruction *is_comptime)5716 IrBasicBlockSrc *end_block, ResultLoc *parent, IrInstSrc *is_comptime)
4684{5717{
4685 ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1);5718 ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1);
4686 peer_parent->base.id = ResultLocIdPeerParent;5719 peer_parent->base.id = ResultLocIdPeerParent;
...@@ -4690,17 +5723,17 @@ static ResultLocPeerParent *ir_build_result_peers(IrBuilder *irb, IrInstruction...@@ -4690,17 +5723,17 @@ static ResultLocPeerParent *ir_build_result_peers(IrBuilder *irb, IrInstruction
4690 peer_parent->is_comptime = is_comptime;5723 peer_parent->is_comptime = is_comptime;
4691 peer_parent->parent = parent;5724 peer_parent->parent = parent;
46925725
4693 IrInstruction *popped_inst = irb->current_basic_block->instruction_list.pop();5726 IrInstSrc *popped_inst = irb->current_basic_block->instruction_list.pop();
4694 ir_assert(popped_inst == cond_br_inst, cond_br_inst);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);
4697 irb->current_basic_block->instruction_list.append(popped_inst);5730 irb->current_basic_block->instruction_list.append(popped_inst);
46985731
4699 return peer_parent;5732 return peer_parent;
4700}5733}
47015734
4702static ResultLocPeerParent *ir_build_binary_result_peers(IrBuilder *irb, IrInstruction *cond_br_inst,5735static ResultLocPeerParent *ir_build_binary_result_peers(IrBuilderSrc *irb, IrInstSrc *cond_br_inst,
4703 IrBasicBlock *else_block, IrBasicBlock *end_block, ResultLoc *parent, IrInstruction *is_comptime)5736 IrBasicBlockSrc *else_block, IrBasicBlockSrc *end_block, ResultLoc *parent, IrInstSrc *is_comptime)
4704{5737{
4705 ResultLocPeerParent *peer_parent = ir_build_result_peers(irb, cond_br_inst, end_block, parent, is_comptime);5738 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...@@ -4713,7 +5746,7 @@ static ResultLocPeerParent *ir_build_binary_result_peers(IrBuilder *irb, IrInstr
4713 return peer_parent;5746 return peer_parent;
4714}5747}
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,
4717 ResultLoc *result_loc)5750 ResultLoc *result_loc)
4718{5751{
4719 assert(node->type == NodeTypeBinOpExpr);5752 assert(node->type == NodeTypeBinOpExpr);
...@@ -4721,73 +5754,73 @@ static IrInstruction *ir_gen_orelse(IrBuilder *irb, Scope *parent_scope, AstNode...@@ -4721,73 +5754,73 @@ static IrInstruction *ir_gen_orelse(IrBuilder *irb, Scope *parent_scope, AstNode
4721 AstNode *op1_node = node->data.bin_op_expr.op1;5754 AstNode *op1_node = node->data.bin_op_expr.op1;
4722 AstNode *op2_node = node->data.bin_op_expr.op2;5755 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);5757 IrInstSrc *maybe_ptr = ir_gen_node_extra(irb, op1_node, parent_scope, LValPtr, nullptr);
4725 if (maybe_ptr == irb->codegen->invalid_instruction)5758 if (maybe_ptr == irb->codegen->invalid_inst_src)
4726 return irb->codegen->invalid_instruction;5759 return irb->codegen->invalid_inst_src;
47275760
4728 IrInstruction *maybe_val = ir_build_load_ptr(irb, parent_scope, node, maybe_ptr);5761 IrInstSrc *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);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;
4732 if (ir_should_inline(irb->exec, parent_scope)) {5765 if (ir_should_inline(irb->exec, parent_scope)) {
4733 is_comptime = ir_build_const_bool(irb, parent_scope, node, true);5766 is_comptime = ir_build_const_bool(irb, parent_scope, node, true);
4734 } else {5767 } else {
4735 is_comptime = ir_build_test_comptime(irb, parent_scope, node, is_non_null);5768 is_comptime = ir_build_test_comptime(irb, parent_scope, node, is_non_null);
4736 }5769 }
47375770
4738 IrBasicBlock *ok_block = ir_create_basic_block(irb, parent_scope, "OptionalNonNull");5771 IrBasicBlockSrc *ok_block = ir_create_basic_block(irb, parent_scope, "OptionalNonNull");
4739 IrBasicBlock *null_block = ir_create_basic_block(irb, parent_scope, "OptionalNull");5772 IrBasicBlockSrc *null_block = ir_create_basic_block(irb, parent_scope, "OptionalNull");
4740 IrBasicBlock *end_block = ir_create_basic_block(irb, parent_scope, "OptionalEnd");5773 IrBasicBlockSrc *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);5774 IrInstSrc *cond_br_inst = ir_build_cond_br(irb, parent_scope, node, is_non_null, ok_block, null_block, is_comptime);
47425775
4743 ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, ok_block, end_block,5776 ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, ok_block, end_block,
4744 result_loc, is_comptime);5777 result_loc, is_comptime);
47455778
4746 ir_set_cursor_at_end_and_append_block(irb, null_block);5779 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,
4748 &peer_parent->peers.at(0)->base);5781 &peer_parent->peers.at(0)->base);
4749 if (null_result == irb->codegen->invalid_instruction)5782 if (null_result == irb->codegen->invalid_inst_src)
4750 return irb->codegen->invalid_instruction;5783 return irb->codegen->invalid_inst_src;
4751 IrBasicBlock *after_null_block = irb->current_basic_block;5784 IrBasicBlockSrc *after_null_block = irb->current_basic_block;
4752 if (!instr_is_unreachable(null_result))5785 if (!instr_is_unreachable(null_result))
4753 ir_mark_gen(ir_build_br(irb, parent_scope, node, end_block, is_comptime));5786 ir_mark_gen(ir_build_br(irb, parent_scope, node, end_block, is_comptime));
47545787
4755 ir_set_cursor_at_end_and_append_block(irb, ok_block);5788 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);5789 IrInstSrc *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);5790 IrInstSrc *unwrapped_payload = ir_build_load_ptr(irb, parent_scope, node, unwrapped_ptr);
4758 ir_build_end_expr(irb, parent_scope, node, unwrapped_payload, &peer_parent->peers.at(1)->base);5791 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;
4760 ir_build_br(irb, parent_scope, node, end_block, is_comptime);5793 ir_build_br(irb, parent_scope, node, end_block, is_comptime);
47615794
4762 ir_set_cursor_at_end_and_append_block(irb, end_block);5795 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);
4764 incoming_values[0] = null_result;5797 incoming_values[0] = null_result;
4765 incoming_values[1] = unwrapped_payload;5798 incoming_values[1] = unwrapped_payload;
4766 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *");5799 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
4767 incoming_blocks[0] = after_null_block;5800 incoming_blocks[0] = after_null_block;
4768 incoming_blocks[1] = after_ok_block;5801 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);
4770 return ir_lval_wrap(irb, parent_scope, phi, lval, result_loc);5803 return ir_lval_wrap(irb, parent_scope, phi, lval, result_loc);
4771}5804}
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) {
4774 assert(node->type == NodeTypeBinOpExpr);5807 assert(node->type == NodeTypeBinOpExpr);
47755808
4776 AstNode *op1_node = node->data.bin_op_expr.op1;5809 AstNode *op1_node = node->data.bin_op_expr.op1;
4777 AstNode *op2_node = node->data.bin_op_expr.op2;5810 AstNode *op2_node = node->data.bin_op_expr.op2;
47785811
4779 IrInstruction *err_set = ir_gen_node(irb, op1_node, parent_scope);5812 IrInstSrc *err_set = ir_gen_node(irb, op1_node, parent_scope);
4780 if (err_set == irb->codegen->invalid_instruction)5813 if (err_set == irb->codegen->invalid_inst_src)
4781 return irb->codegen->invalid_instruction;5814 return irb->codegen->invalid_inst_src;
47825815
4783 IrInstruction *payload = ir_gen_node(irb, op2_node, parent_scope);5816 IrInstSrc *payload = ir_gen_node(irb, op2_node, parent_scope);
4784 if (payload == irb->codegen->invalid_instruction)5817 if (payload == irb->codegen->invalid_inst_src)
4785 return irb->codegen->invalid_instruction;5818 return irb->codegen->invalid_inst_src;
47865819
4787 return ir_build_error_union(irb, parent_scope, node, err_set, payload);5820 return ir_build_error_union(irb, parent_scope, node, err_set, payload);
4788}5821}
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) {
4791 assert(node->type == NodeTypeBinOpExpr);5824 assert(node->type == NodeTypeBinOpExpr);
47925825
4793 BinOpType bin_op_type = node->data.bin_op_expr.bin_op;5826 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,...@@ -4880,30 +5913,30 @@ static IrInstruction *ir_gen_bin_op(IrBuilder *irb, Scope *scope, AstNode *node,
4880 zig_unreachable();5913 zig_unreachable();
4881}5914}
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) {
4884 assert(node->type == NodeTypeIntLiteral);5917 assert(node->type == NodeTypeIntLiteral);
48855918
4886 return ir_build_const_bigint(irb, scope, node, node->data.int_literal.bigint);5919 return ir_build_const_bigint(irb, scope, node, node->data.int_literal.bigint);
4887}5920}
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) {
4890 assert(node->type == NodeTypeFloatLiteral);5923 assert(node->type == NodeTypeFloatLiteral);
48915924
4892 if (node->data.float_literal.overflow) {5925 if (node->data.float_literal.overflow) {
4893 add_node_error(irb->codegen, node, buf_sprintf("float literal out of range of any type"));5926 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;
4895 }5928 }
48965929
4897 return ir_build_const_bigfloat(irb, scope, node, node->data.float_literal.bigfloat);5930 return ir_build_const_bigfloat(irb, scope, node, node->data.float_literal.bigfloat);
4898}5931}
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) {
4901 assert(node->type == NodeTypeCharLiteral);5934 assert(node->type == NodeTypeCharLiteral);
49025935
4903 return ir_build_const_uint(irb, scope, node, node->data.char_literal.value);5936 return ir_build_const_uint(irb, scope, node, node->data.char_literal.value);
4904}5937}
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) {
4907 assert(node->type == NodeTypeNullLiteral);5940 assert(node->type == NodeTypeNullLiteral);
49085941
4909 return ir_build_const_null(irb, scope, node);5942 return ir_build_const_null(irb, scope, node);
...@@ -4921,11 +5954,11 @@ static void populate_invalid_variable_in_scope(CodeGen *g, Scope *scope, AstNode...@@ -4921,11 +5954,11 @@ static void populate_invalid_variable_in_scope(CodeGen *g, Scope *scope, AstNode
4921 init_tld(&tld_var->base, TldIdVar, var_name, VisibModPub, node, &scope_decls->base);5954 init_tld(&tld_var->base, TldIdVar, var_name, VisibModPub, node, &scope_decls->base);
4922 tld_var->base.resolution = TldResolutionInvalid;5955 tld_var->base.resolution = TldResolutionInvalid;
4923 tld_var->var = add_variable(g, node, &scope_decls->base, var_name, false,5956 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);
4925 scope_decls->decl_table.put(var_name, &tld_var->base);5958 scope_decls->decl_table.put(var_name, &tld_var->base);
4926}5959}
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) {
4929 Error err;5962 Error err;
4930 assert(node->type == NodeTypeSymbol);5963 assert(node->type == NodeTypeSymbol);
49315964
...@@ -4933,15 +5966,16 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -4933,15 +5966,16 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
49335966
4934 if (buf_eql_str(variable_name, "_")) {5967 if (buf_eql_str(variable_name, "_")) {
4935 if (lval == LValPtr) {5968 if (lval == LValPtr) {
4936 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, node);5969 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, node);
4937 const_instruction->base.value->type = get_pointer_to_type(irb->codegen,5970 const_instruction->value = create_const_vals(1);
5971 const_instruction->value->type = get_pointer_to_type(irb->codegen,
4938 irb->codegen->builtin_types.entry_void, false);5972 irb->codegen->builtin_types.entry_void, false);
4939 const_instruction->base.value->special = ConstValSpecialStatic;5973 const_instruction->value->special = ConstValSpecialStatic;
4940 const_instruction->base.value->data.x_ptr.special = ConstPtrSpecialDiscard;5974 const_instruction->value->data.x_ptr.special = ConstPtrSpecialDiscard;
4941 return &const_instruction->base;5975 return &const_instruction->base;
4942 } else {5976 } else {
4943 add_node_error(irb->codegen, node, buf_sprintf("`_` may only be used to assign things to"));5977 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;
4945 }5979 }
4946 }5980 }
49475981
...@@ -4951,13 +5985,13 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -4951,13 +5985,13 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
4951 add_node_error(irb->codegen, node,5985 add_node_error(irb->codegen, node,
4952 buf_sprintf("primitive integer type '%s' exceeds maximum bit width of 65535",5986 buf_sprintf("primitive integer type '%s' exceeds maximum bit width of 65535",
4953 buf_ptr(variable_name)));5987 buf_ptr(variable_name)));
4954 return irb->codegen->invalid_instruction;5988 return irb->codegen->invalid_inst_src;
4955 }5989 }
4956 assert(err == ErrorPrimitiveTypeNotFound);5990 assert(err == ErrorPrimitiveTypeNotFound);
4957 } else {5991 } 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);
4959 if (lval == LValPtr) {5993 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);
4961 } else {5995 } else {
4962 return ir_expr_wrap(irb, scope, value, result_loc);5996 return ir_expr_wrap(irb, scope, value, result_loc);
4963 }5997 }
...@@ -4966,7 +6000,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -4966,7 +6000,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
4966 ScopeFnDef *crossed_fndef_scope;6000 ScopeFnDef *crossed_fndef_scope;
4967 ZigVar *var = find_variable(irb->codegen, scope, variable_name, &crossed_fndef_scope);6001 ZigVar *var = find_variable(irb->codegen, scope, variable_name, &crossed_fndef_scope);
4968 if (var) {6002 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);
4970 if (lval == LValPtr) {6004 if (lval == LValPtr) {
4971 return var_ptr;6005 return var_ptr;
4972 } else {6006 } else {
...@@ -4976,7 +6010,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -4976,7 +6010,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
49766010
4977 Tld *tld = find_decl(irb->codegen, scope, variable_name);6011 Tld *tld = find_decl(irb->codegen, scope, variable_name);
4978 if (tld) {6012 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);
4980 if (lval == LValPtr) {6014 if (lval == LValPtr) {
4981 return decl_ref;6015 return decl_ref;
4982 } else {6016 } else {
...@@ -4987,50 +6021,50 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -4987,50 +6021,50 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
4987 if (get_container_scope(node->owner)->any_imports_failed) {6021 if (get_container_scope(node->owner)->any_imports_failed) {
4988 // skip the error message since we had a failing import in this file6022 // skip the error message since we had a failing import in this file
4989 // if an import breaks we don't need redundant undeclared identifier errors6023 // 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;
4991 }6025 }
49926026
4993 return ir_build_undeclared_identifier(irb, scope, node, variable_name);6027 return ir_build_undeclared_identifier(irb, scope, node, variable_name);
4994}6028}
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,
4997 ResultLoc *result_loc)6031 ResultLoc *result_loc)
4998{6032{
4999 assert(node->type == NodeTypeArrayAccessExpr);6033 assert(node->type == NodeTypeArrayAccessExpr);
50006034
5001 AstNode *array_ref_node = node->data.array_access_expr.array_ref_expr;6035 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);6036 IrInstSrc *array_ref_instruction = ir_gen_node_extra(irb, array_ref_node, scope, LValPtr, nullptr);
5003 if (array_ref_instruction == irb->codegen->invalid_instruction)6037 if (array_ref_instruction == irb->codegen->invalid_inst_src)
5004 return array_ref_instruction;6038 return array_ref_instruction;
50056039
5006 AstNode *subscript_node = node->data.array_access_expr.subscript;6040 AstNode *subscript_node = node->data.array_access_expr.subscript;
5007 IrInstruction *subscript_instruction = ir_gen_node(irb, subscript_node, scope);6041 IrInstSrc *subscript_instruction = ir_gen_node(irb, subscript_node, scope);
5008 if (subscript_instruction == irb->codegen->invalid_instruction)6042 if (subscript_instruction == irb->codegen->invalid_inst_src)
5009 return subscript_instruction;6043 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,
5012 subscript_instruction, true, PtrLenSingle, nullptr);6046 subscript_instruction, true, PtrLenSingle, nullptr);
5013 if (lval == LValPtr)6047 if (lval == LValPtr)
5014 return ptr_instruction;6048 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);
5017 return ir_expr_wrap(irb, scope, load_ptr, result_loc);6051 return ir_expr_wrap(irb, scope, load_ptr, result_loc);
5018}6052}
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) {
5021 assert(node->type == NodeTypeFieldAccessExpr);6055 assert(node->type == NodeTypeFieldAccessExpr);
50226056
5023 AstNode *container_ref_node = node->data.field_access_expr.struct_expr;6057 AstNode *container_ref_node = node->data.field_access_expr.struct_expr;
5024 Buf *field_name = node->data.field_access_expr.field_name;6058 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);6060 IrInstSrc *container_ref_instruction = ir_gen_node_extra(irb, container_ref_node, scope, LValPtr, nullptr);
5027 if (container_ref_instruction == irb->codegen->invalid_instruction)6061 if (container_ref_instruction == irb->codegen->invalid_inst_src)
5028 return container_ref_instruction;6062 return container_ref_instruction;
50296063
5030 return ir_build_field_ptr(irb, scope, node, container_ref_instruction, field_name, false);6064 return ir_build_field_ptr(irb, scope, node, container_ref_instruction, field_name, false);
5031}6065}
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) {
5034 assert(node->type == NodeTypeFnCallExpr);6068 assert(node->type == NodeTypeFnCallExpr);
50356069
5036 AstNode *type_node = node->data.fn_call_expr.params.at(0);6070 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 *...@@ -5039,26 +6073,26 @@ static IrInstruction *ir_gen_overflow_op(IrBuilder *irb, Scope *scope, AstNode *
5039 AstNode *result_ptr_node = node->data.fn_call_expr.params.at(3);6073 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);6076 IrInstSrc *type_value = ir_gen_node(irb, type_node, scope);
5043 if (type_value == irb->codegen->invalid_instruction)6077 if (type_value == irb->codegen->invalid_inst_src)
5044 return irb->codegen->invalid_instruction;6078 return irb->codegen->invalid_inst_src;
50456079
5046 IrInstruction *op1 = ir_gen_node(irb, op1_node, scope);6080 IrInstSrc *op1 = ir_gen_node(irb, op1_node, scope);
5047 if (op1 == irb->codegen->invalid_instruction)6081 if (op1 == irb->codegen->invalid_inst_src)
5048 return irb->codegen->invalid_instruction;6082 return irb->codegen->invalid_inst_src;
50496083
5050 IrInstruction *op2 = ir_gen_node(irb, op2_node, scope);6084 IrInstSrc *op2 = ir_gen_node(irb, op2_node, scope);
5051 if (op2 == irb->codegen->invalid_instruction)6085 if (op2 == irb->codegen->invalid_inst_src)
5052 return irb->codegen->invalid_instruction;6086 return irb->codegen->invalid_inst_src;
50536087
5054 IrInstruction *result_ptr = ir_gen_node(irb, result_ptr_node, scope);6088 IrInstSrc *result_ptr = ir_gen_node(irb, result_ptr_node, scope);
5055 if (result_ptr == irb->codegen->invalid_instruction)6089 if (result_ptr == irb->codegen->invalid_inst_src)
5056 return irb->codegen->invalid_instruction;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);
5059}6093}
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) {
5062 assert(node->type == NodeTypeFnCallExpr);6096 assert(node->type == NodeTypeFnCallExpr);
50636097
5064 AstNode *type_node = node->data.fn_call_expr.params.at(0);6098 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...@@ -5066,26 +6100,26 @@ static IrInstruction *ir_gen_mul_add(IrBuilder *irb, Scope *scope, AstNode *node
5066 AstNode *op2_node = node->data.fn_call_expr.params.at(2);6100 AstNode *op2_node = node->data.fn_call_expr.params.at(2);
5067 AstNode *op3_node = node->data.fn_call_expr.params.at(3);6101 AstNode *op3_node = node->data.fn_call_expr.params.at(3);
50686102
5069 IrInstruction *type_value = ir_gen_node(irb, type_node, scope);6103 IrInstSrc *type_value = ir_gen_node(irb, type_node, scope);
5070 if (type_value == irb->codegen->invalid_instruction)6104 if (type_value == irb->codegen->invalid_inst_src)
5071 return irb->codegen->invalid_instruction;6105 return irb->codegen->invalid_inst_src;
50726106
5073 IrInstruction *op1 = ir_gen_node(irb, op1_node, scope);6107 IrInstSrc *op1 = ir_gen_node(irb, op1_node, scope);
5074 if (op1 == irb->codegen->invalid_instruction)6108 if (op1 == irb->codegen->invalid_inst_src)
5075 return irb->codegen->invalid_instruction;6109 return irb->codegen->invalid_inst_src;
50766110
5077 IrInstruction *op2 = ir_gen_node(irb, op2_node, scope);6111 IrInstSrc *op2 = ir_gen_node(irb, op2_node, scope);
5078 if (op2 == irb->codegen->invalid_instruction)6112 if (op2 == irb->codegen->invalid_inst_src)
5079 return irb->codegen->invalid_instruction;6113 return irb->codegen->invalid_inst_src;
50806114
5081 IrInstruction *op3 = ir_gen_node(irb, op3_node, scope);6115 IrInstSrc *op3 = ir_gen_node(irb, op3_node, scope);
5082 if (op3 == irb->codegen->invalid_instruction)6116 if (op3 == irb->codegen->invalid_inst_src)
5083 return irb->codegen->invalid_instruction;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);
5086}6120}
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) {
5089 for (Scope *it_scope = orig_scope; it_scope != nullptr; it_scope = it_scope->parent) {6123 for (Scope *it_scope = orig_scope; it_scope != nullptr; it_scope = it_scope->parent) {
5090 if (it_scope->id == ScopeIdDecls) {6124 if (it_scope->id == ScopeIdDecls) {
5091 ScopeDecls *decls_scope = (ScopeDecls *)it_scope;6125 ScopeDecls *decls_scope = (ScopeDecls *)it_scope;
...@@ -5100,7 +6134,7 @@ static IrInstruction *ir_gen_this(IrBuilder *irb, Scope *orig_scope, AstNode *no...@@ -5100,7 +6134,7 @@ static IrInstruction *ir_gen_this(IrBuilder *irb, Scope *orig_scope, AstNode *no
5100 zig_unreachable();6134 zig_unreachable();
5101}6135}
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,
5104 LVal lval, ResultLoc *result_loc)6138 LVal lval, ResultLoc *result_loc)
5105{6139{
5106 size_t arg_offset = 3;6140 size_t arg_offset = 3;
...@@ -5108,71 +6142,71 @@ static IrInstruction *ir_gen_async_call(IrBuilder *irb, Scope *scope, AstNode *a...@@ -5108,71 +6142,71 @@ static IrInstruction *ir_gen_async_call(IrBuilder *irb, Scope *scope, AstNode *a
5108 add_node_error(irb->codegen, call_node,6142 add_node_error(irb->codegen, call_node,
5109 buf_sprintf("expected at least %" ZIG_PRI_usize " arguments, found %" ZIG_PRI_usize,6143 buf_sprintf("expected at least %" ZIG_PRI_usize " arguments, found %" ZIG_PRI_usize,
5110 arg_offset, call_node->data.fn_call_expr.params.length));6144 arg_offset, call_node->data.fn_call_expr.params.length));
5111 return irb->codegen->invalid_instruction;6145 return irb->codegen->invalid_inst_src;
5112 }6146 }
51136147
5114 AstNode *bytes_node = call_node->data.fn_call_expr.params.at(0);6148 AstNode *bytes_node = call_node->data.fn_call_expr.params.at(0);
5115 IrInstruction *bytes = ir_gen_node(irb, bytes_node, scope);6149 IrInstSrc *bytes = ir_gen_node(irb, bytes_node, scope);
5116 if (bytes == irb->codegen->invalid_instruction)6150 if (bytes == irb->codegen->invalid_inst_src)
5117 return bytes;6151 return bytes;
51186152
5119 AstNode *ret_ptr_node = call_node->data.fn_call_expr.params.at(1);6153 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);6154 IrInstSrc *ret_ptr = ir_gen_node(irb, ret_ptr_node, scope);
5121 if (ret_ptr == irb->codegen->invalid_instruction)6155 if (ret_ptr == irb->codegen->invalid_inst_src)
5122 return ret_ptr;6156 return ret_ptr;
51236157
5124 AstNode *fn_ref_node = call_node->data.fn_call_expr.params.at(2);6158 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);6159 IrInstSrc *fn_ref = ir_gen_node(irb, fn_ref_node, scope);
5126 if (fn_ref == irb->codegen->invalid_instruction)6160 if (fn_ref == irb->codegen->invalid_inst_src)
5127 return fn_ref;6161 return fn_ref;
51286162
5129 size_t arg_count = call_node->data.fn_call_expr.params.length - arg_offset;6163 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);
5131 for (size_t i = 0; i < arg_count; i += 1) {6165 for (size_t i = 0; i < arg_count; i += 1) {
5132 AstNode *arg_node = call_node->data.fn_call_expr.params.at(i + arg_offset);6166 AstNode *arg_node = call_node->data.fn_call_expr.params.at(i + arg_offset);
5133 IrInstruction *arg = ir_gen_node(irb, arg_node, scope);6167 IrInstSrc *arg = ir_gen_node(irb, arg_node, scope);
5134 if (arg == irb->codegen->invalid_instruction)6168 if (arg == irb->codegen->invalid_inst_src)
5135 return arg;6169 return arg;
5136 args[i] = arg;6170 args[i] = arg;
5137 }6171 }
51386172
5139 CallModifier modifier = (await_node == nullptr) ? CallModifierAsync : CallModifierNone;6173 CallModifier modifier = (await_node == nullptr) ? CallModifierAsync : CallModifierNone;
5140 bool is_async_call_builtin = true;6174 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,
5142 ret_ptr, modifier, is_async_call_builtin, bytes, result_loc);6176 ret_ptr, modifier, is_async_call_builtin, bytes, result_loc);
5143 return ir_lval_wrap(irb, scope, call, lval, result_loc);6177 return ir_lval_wrap(irb, scope, call, lval, result_loc);
5144}6178}
51456179
5146static IrInstruction *ir_gen_fn_call_with_args(IrBuilder *irb, Scope *scope, AstNode *source_node,6180static IrInstSrc *ir_gen_fn_call_with_args(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
5147 AstNode *fn_ref_node, CallModifier modifier, IrInstruction *options,6181 AstNode *fn_ref_node, CallModifier modifier, IrInstSrc *options,
5148 AstNode **args_ptr, size_t args_len, LVal lval, ResultLoc *result_loc)6182 AstNode **args_ptr, size_t args_len, LVal lval, ResultLoc *result_loc)
5149{6183{
5150 IrInstruction *fn_ref = ir_gen_node(irb, fn_ref_node, scope);6184 IrInstSrc *fn_ref = ir_gen_node(irb, fn_ref_node, scope);
5151 if (fn_ref == irb->codegen->invalid_instruction)6185 if (fn_ref == irb->codegen->invalid_inst_src)
5152 return fn_ref;6186 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);
5157 for (size_t i = 0; i < args_len; i += 1) {6191 for (size_t i = 0; i < args_len; i += 1) {
5158 AstNode *arg_node = args_ptr[i];6192 AstNode *arg_node = args_ptr[i];
51596193
5160 IrInstruction *arg_index = ir_build_const_usize(irb, scope, arg_node, i);6194 IrInstSrc *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);6195 IrInstSrc *arg_type = ir_build_arg_type(irb, scope, source_node, fn_type, arg_index, true);
5162 ResultLoc *no_result = no_result_loc();6196 ResultLoc *no_result = no_result_loc();
5163 ir_build_reset_result(irb, scope, source_node, no_result);6197 ir_build_reset_result(irb, scope, source_node, no_result);
5164 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, arg_type, no_result);6198 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);6200 IrInstSrc *arg = ir_gen_node_extra(irb, arg_node, scope, LValNone, &result_loc_cast->base);
5167 if (arg == irb->codegen->invalid_instruction)6201 if (arg == irb->codegen->invalid_inst_src)
5168 return arg;6202 return arg;
51696203
5170 args[i] = ir_build_implicit_cast(irb, scope, arg_node, arg, result_loc_cast);6204 args[i] = ir_build_implicit_cast(irb, scope, arg_node, arg, result_loc_cast);
5171 }6205 }
51726206
5173 IrInstruction *fn_call;6207 IrInstSrc *fn_call;
5174 if (options != nullptr) {6208 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);
5176 } else {6210 } else {
5177 fn_call = ir_build_call_src(irb, scope, source_node, nullptr, fn_ref, args_len, args, nullptr,6211 fn_call = ir_build_call_src(irb, scope, source_node, nullptr, fn_ref, args_len, args, nullptr,
5178 modifier, false, nullptr, result_loc);6212 modifier, false, nullptr, result_loc);
...@@ -5180,7 +6214,7 @@ static IrInstruction *ir_gen_fn_call_with_args(IrBuilder *irb, Scope *scope, Ast...@@ -5180,7 +6214,7 @@ static IrInstruction *ir_gen_fn_call_with_args(IrBuilder *irb, Scope *scope, Ast
5180 return ir_lval_wrap(irb, scope, fn_call, lval, result_loc);6214 return ir_lval_wrap(irb, scope, fn_call, lval, result_loc);
5181}6215}
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,
5184 ResultLoc *result_loc)6218 ResultLoc *result_loc)
5185{6219{
5186 assert(node->type == NodeTypeFnCallExpr);6220 assert(node->type == NodeTypeFnCallExpr);
...@@ -5192,7 +6226,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -5192,7 +6226,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
5192 if (!entry) {6226 if (!entry) {
5193 add_node_error(irb->codegen, node,6227 add_node_error(irb->codegen, node,
5194 buf_sprintf("invalid builtin function: '%s'", buf_ptr(name)));6228 buf_sprintf("invalid builtin function: '%s'", buf_ptr(name)));
5195 return irb->codegen->invalid_instruction;6229 return irb->codegen->invalid_inst_src;
5196 }6230 }
51976231
5198 BuiltinFnEntry *builtin_fn = entry->value;6232 BuiltinFnEntry *builtin_fn = entry->value;
...@@ -5202,7 +6236,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -5202,7 +6236,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
5202 add_node_error(irb->codegen, node,6236 add_node_error(irb->codegen, node,
5203 buf_sprintf("expected %" ZIG_PRI_usize " arguments, found %" ZIG_PRI_usize,6237 buf_sprintf("expected %" ZIG_PRI_usize " arguments, found %" ZIG_PRI_usize,
5204 builtin_fn->param_count, actual_param_count));6238 builtin_fn->param_count, actual_param_count));
5205 return irb->codegen->invalid_instruction;6239 return irb->codegen->invalid_inst_src;
5206 }6240 }
52076241
5208 switch (builtin_fn->id) {6242 switch (builtin_fn->id) {
...@@ -5213,197 +6247,197 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -5213,197 +6247,197 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
5213 Scope *sub_scope = create_typeof_scope(irb->codegen, node, scope);6247 Scope *sub_scope = create_typeof_scope(irb->codegen, node, scope);
52146248
5215 AstNode *arg_node = node->data.fn_call_expr.params.at(0);6249 AstNode *arg_node = node->data.fn_call_expr.params.at(0);
5216 IrInstruction *arg = ir_gen_node(irb, arg_node, sub_scope);6250 IrInstSrc *arg = ir_gen_node(irb, arg_node, sub_scope);
5217 if (arg == irb->codegen->invalid_instruction)6251 if (arg == irb->codegen->invalid_inst_src)
5218 return arg;6252 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);
5221 return ir_lval_wrap(irb, scope, type_of, lval, result_loc);6255 return ir_lval_wrap(irb, scope, type_of, lval, result_loc);
5222 }6256 }
5223 case BuiltinFnIdSetCold:6257 case BuiltinFnIdSetCold:
5224 {6258 {
5225 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6259 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5226 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6260 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5227 if (arg0_value == irb->codegen->invalid_instruction)6261 if (arg0_value == irb->codegen->invalid_inst_src)
5228 return arg0_value;6262 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);
5231 return ir_lval_wrap(irb, scope, set_cold, lval, result_loc);6265 return ir_lval_wrap(irb, scope, set_cold, lval, result_loc);
5232 }6266 }
5233 case BuiltinFnIdSetRuntimeSafety:6267 case BuiltinFnIdSetRuntimeSafety:
5234 {6268 {
5235 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6269 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5236 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6270 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5237 if (arg0_value == irb->codegen->invalid_instruction)6271 if (arg0_value == irb->codegen->invalid_inst_src)
5238 return arg0_value;6272 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);
5241 return ir_lval_wrap(irb, scope, set_safety, lval, result_loc);6275 return ir_lval_wrap(irb, scope, set_safety, lval, result_loc);
5242 }6276 }
5243 case BuiltinFnIdSetFloatMode:6277 case BuiltinFnIdSetFloatMode:
5244 {6278 {
5245 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6279 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5246 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6280 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5247 if (arg0_value == irb->codegen->invalid_instruction)6281 if (arg0_value == irb->codegen->invalid_inst_src)
5248 return arg0_value;6282 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);
5251 return ir_lval_wrap(irb, scope, set_float_mode, lval, result_loc);6285 return ir_lval_wrap(irb, scope, set_float_mode, lval, result_loc);
5252 }6286 }
5253 case BuiltinFnIdSizeof:6287 case BuiltinFnIdSizeof:
5254 case BuiltinFnIdBitSizeof:6288 case BuiltinFnIdBitSizeof:
5255 {6289 {
5256 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6290 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5257 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6291 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5258 if (arg0_value == irb->codegen->invalid_instruction)6292 if (arg0_value == irb->codegen->invalid_inst_src)
5259 return arg0_value;6293 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);
5262 return ir_lval_wrap(irb, scope, size_of, lval, result_loc);6296 return ir_lval_wrap(irb, scope, size_of, lval, result_loc);
5263 }6297 }
5264 case BuiltinFnIdImport:6298 case BuiltinFnIdImport:
5265 {6299 {
5266 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6300 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5267 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6301 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5268 if (arg0_value == irb->codegen->invalid_instruction)6302 if (arg0_value == irb->codegen->invalid_inst_src)
5269 return arg0_value;6303 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);
5272 return ir_lval_wrap(irb, scope, import, lval, result_loc);6306 return ir_lval_wrap(irb, scope, import, lval, result_loc);
5273 }6307 }
5274 case BuiltinFnIdCImport:6308 case BuiltinFnIdCImport:
5275 {6309 {
5276 IrInstruction *c_import = ir_build_c_import(irb, scope, node);6310 IrInstSrc *c_import = ir_build_c_import(irb, scope, node);
5277 return ir_lval_wrap(irb, scope, c_import, lval, result_loc);6311 return ir_lval_wrap(irb, scope, c_import, lval, result_loc);
5278 }6312 }
5279 case BuiltinFnIdCInclude:6313 case BuiltinFnIdCInclude:
5280 {6314 {
5281 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6315 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5282 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6316 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5283 if (arg0_value == irb->codegen->invalid_instruction)6317 if (arg0_value == irb->codegen->invalid_inst_src)
5284 return arg0_value;6318 return arg0_value;
52856319
5286 if (!exec_c_import_buf(irb->exec)) {6320 if (!exec_c_import_buf(irb->exec)) {
5287 add_node_error(irb->codegen, node, buf_sprintf("C include valid only inside C import block"));6321 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;
5289 }6323 }
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);
5292 return ir_lval_wrap(irb, scope, c_include, lval, result_loc);6326 return ir_lval_wrap(irb, scope, c_include, lval, result_loc);
5293 }6327 }
5294 case BuiltinFnIdCDefine:6328 case BuiltinFnIdCDefine:
5295 {6329 {
5296 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6330 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5297 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6331 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5298 if (arg0_value == irb->codegen->invalid_instruction)6332 if (arg0_value == irb->codegen->invalid_inst_src)
5299 return arg0_value;6333 return arg0_value;
53006334
5301 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6335 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5302 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6336 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5303 if (arg1_value == irb->codegen->invalid_instruction)6337 if (arg1_value == irb->codegen->invalid_inst_src)
5304 return arg1_value;6338 return arg1_value;
53056339
5306 if (!exec_c_import_buf(irb->exec)) {6340 if (!exec_c_import_buf(irb->exec)) {
5307 add_node_error(irb->codegen, node, buf_sprintf("C define valid only inside C import block"));6341 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;
5309 }6343 }
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);
5312 return ir_lval_wrap(irb, scope, c_define, lval, result_loc);6346 return ir_lval_wrap(irb, scope, c_define, lval, result_loc);
5313 }6347 }
5314 case BuiltinFnIdCUndef:6348 case BuiltinFnIdCUndef:
5315 {6349 {
5316 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6350 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5317 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6351 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5318 if (arg0_value == irb->codegen->invalid_instruction)6352 if (arg0_value == irb->codegen->invalid_inst_src)
5319 return arg0_value;6353 return arg0_value;
53206354
5321 if (!exec_c_import_buf(irb->exec)) {6355 if (!exec_c_import_buf(irb->exec)) {
5322 add_node_error(irb->codegen, node, buf_sprintf("C undef valid only inside C import block"));6356 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;
5324 }6358 }
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);
5327 return ir_lval_wrap(irb, scope, c_undef, lval, result_loc);6361 return ir_lval_wrap(irb, scope, c_undef, lval, result_loc);
5328 }6362 }
5329 case BuiltinFnIdCompileErr:6363 case BuiltinFnIdCompileErr:
5330 {6364 {
5331 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6365 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5332 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6366 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5333 if (arg0_value == irb->codegen->invalid_instruction)6367 if (arg0_value == irb->codegen->invalid_inst_src)
5334 return arg0_value;6368 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);
5337 return ir_lval_wrap(irb, scope, compile_err, lval, result_loc);6371 return ir_lval_wrap(irb, scope, compile_err, lval, result_loc);
5338 }6372 }
5339 case BuiltinFnIdCompileLog:6373 case BuiltinFnIdCompileLog:
5340 {6374 {
5341 IrInstruction **args = allocate<IrInstruction*>(actual_param_count);6375 IrInstSrc **args = allocate<IrInstSrc*>(actual_param_count);
53426376
5343 for (size_t i = 0; i < actual_param_count; i += 1) {6377 for (size_t i = 0; i < actual_param_count; i += 1) {
5344 AstNode *arg_node = node->data.fn_call_expr.params.at(i);6378 AstNode *arg_node = node->data.fn_call_expr.params.at(i);
5345 args[i] = ir_gen_node(irb, arg_node, scope);6379 args[i] = ir_gen_node(irb, arg_node, scope);
5346 if (args[i] == irb->codegen->invalid_instruction)6380 if (args[i] == irb->codegen->invalid_inst_src)
5347 return irb->codegen->invalid_instruction;6381 return irb->codegen->invalid_inst_src;
5348 }6382 }
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);
5351 return ir_lval_wrap(irb, scope, compile_log, lval, result_loc);6385 return ir_lval_wrap(irb, scope, compile_log, lval, result_loc);
5352 }6386 }
5353 case BuiltinFnIdErrName:6387 case BuiltinFnIdErrName:
5354 {6388 {
5355 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6389 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5356 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6390 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5357 if (arg0_value == irb->codegen->invalid_instruction)6391 if (arg0_value == irb->codegen->invalid_inst_src)
5358 return arg0_value;6392 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);
5361 return ir_lval_wrap(irb, scope, err_name, lval, result_loc);6395 return ir_lval_wrap(irb, scope, err_name, lval, result_loc);
5362 }6396 }
5363 case BuiltinFnIdEmbedFile:6397 case BuiltinFnIdEmbedFile:
5364 {6398 {
5365 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6399 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5366 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6400 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5367 if (arg0_value == irb->codegen->invalid_instruction)6401 if (arg0_value == irb->codegen->invalid_inst_src)
5368 return arg0_value;6402 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);
5371 return ir_lval_wrap(irb, scope, embed_file, lval, result_loc);6405 return ir_lval_wrap(irb, scope, embed_file, lval, result_loc);
5372 }6406 }
5373 case BuiltinFnIdCmpxchgWeak:6407 case BuiltinFnIdCmpxchgWeak:
5374 case BuiltinFnIdCmpxchgStrong:6408 case BuiltinFnIdCmpxchgStrong:
5375 {6409 {
5376 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6410 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5377 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6411 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5378 if (arg0_value == irb->codegen->invalid_instruction)6412 if (arg0_value == irb->codegen->invalid_inst_src)
5379 return arg0_value;6413 return arg0_value;
53806414
5381 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6415 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5382 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6416 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5383 if (arg1_value == irb->codegen->invalid_instruction)6417 if (arg1_value == irb->codegen->invalid_inst_src)
5384 return arg1_value;6418 return arg1_value;
53856419
5386 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);6420 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
5387 IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope);6421 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
5388 if (arg2_value == irb->codegen->invalid_instruction)6422 if (arg2_value == irb->codegen->invalid_inst_src)
5389 return arg2_value;6423 return arg2_value;
53906424
5391 AstNode *arg3_node = node->data.fn_call_expr.params.at(3);6425 AstNode *arg3_node = node->data.fn_call_expr.params.at(3);
5392 IrInstruction *arg3_value = ir_gen_node(irb, arg3_node, scope);6426 IrInstSrc *arg3_value = ir_gen_node(irb, arg3_node, scope);
5393 if (arg3_value == irb->codegen->invalid_instruction)6427 if (arg3_value == irb->codegen->invalid_inst_src)
5394 return arg3_value;6428 return arg3_value;
53956429
5396 AstNode *arg4_node = node->data.fn_call_expr.params.at(4);6430 AstNode *arg4_node = node->data.fn_call_expr.params.at(4);
5397 IrInstruction *arg4_value = ir_gen_node(irb, arg4_node, scope);6431 IrInstSrc *arg4_value = ir_gen_node(irb, arg4_node, scope);
5398 if (arg4_value == irb->codegen->invalid_instruction)6432 if (arg4_value == irb->codegen->invalid_inst_src)
5399 return arg4_value;6433 return arg4_value;
54006434
5401 AstNode *arg5_node = node->data.fn_call_expr.params.at(5);6435 AstNode *arg5_node = node->data.fn_call_expr.params.at(5);
5402 IrInstruction *arg5_value = ir_gen_node(irb, arg5_node, scope);6436 IrInstSrc *arg5_value = ir_gen_node(irb, arg5_node, scope);
5403 if (arg5_value == irb->codegen->invalid_instruction)6437 if (arg5_value == irb->codegen->invalid_inst_src)
5404 return arg5_value;6438 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,
5407 arg2_value, arg3_value, arg4_value, arg5_value, (builtin_fn->id == BuiltinFnIdCmpxchgWeak),6441 arg2_value, arg3_value, arg4_value, arg5_value, (builtin_fn->id == BuiltinFnIdCmpxchgWeak),
5408 result_loc);6442 result_loc);
5409 return ir_lval_wrap(irb, scope, cmpxchg, lval, result_loc);6443 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...@@ -5411,86 +6445,86 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
5411 case BuiltinFnIdFence:6445 case BuiltinFnIdFence:
5412 {6446 {
5413 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6447 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5414 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6448 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5415 if (arg0_value == irb->codegen->invalid_instruction)6449 if (arg0_value == irb->codegen->invalid_inst_src)
5416 return arg0_value;6450 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);
5419 return ir_lval_wrap(irb, scope, fence, lval, result_loc);6453 return ir_lval_wrap(irb, scope, fence, lval, result_loc);
5420 }6454 }
5421 case BuiltinFnIdDivExact:6455 case BuiltinFnIdDivExact:
5422 {6456 {
5423 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6457 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5424 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6458 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5425 if (arg0_value == irb->codegen->invalid_instruction)6459 if (arg0_value == irb->codegen->invalid_inst_src)
5426 return arg0_value;6460 return arg0_value;
54276461
5428 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6462 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5429 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6463 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5430 if (arg1_value == irb->codegen->invalid_instruction)6464 if (arg1_value == irb->codegen->invalid_inst_src)
5431 return arg1_value;6465 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);
5434 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);6468 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);
5435 }6469 }
5436 case BuiltinFnIdDivTrunc:6470 case BuiltinFnIdDivTrunc:
5437 {6471 {
5438 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6472 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5439 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6473 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5440 if (arg0_value == irb->codegen->invalid_instruction)6474 if (arg0_value == irb->codegen->invalid_inst_src)
5441 return arg0_value;6475 return arg0_value;
54426476
5443 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6477 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5444 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6478 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5445 if (arg1_value == irb->codegen->invalid_instruction)6479 if (arg1_value == irb->codegen->invalid_inst_src)
5446 return arg1_value;6480 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);
5449 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);6483 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);
5450 }6484 }
5451 case BuiltinFnIdDivFloor:6485 case BuiltinFnIdDivFloor:
5452 {6486 {
5453 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6487 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5454 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6488 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5455 if (arg0_value == irb->codegen->invalid_instruction)6489 if (arg0_value == irb->codegen->invalid_inst_src)
5456 return arg0_value;6490 return arg0_value;
54576491
5458 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6492 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5459 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6493 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5460 if (arg1_value == irb->codegen->invalid_instruction)6494 if (arg1_value == irb->codegen->invalid_inst_src)
5461 return arg1_value;6495 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);
5464 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);6498 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);
5465 }6499 }
5466 case BuiltinFnIdRem:6500 case BuiltinFnIdRem:
5467 {6501 {
5468 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6502 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5469 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6503 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5470 if (arg0_value == irb->codegen->invalid_instruction)6504 if (arg0_value == irb->codegen->invalid_inst_src)
5471 return arg0_value;6505 return arg0_value;
54726506
5473 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6507 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5474 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6508 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5475 if (arg1_value == irb->codegen->invalid_instruction)6509 if (arg1_value == irb->codegen->invalid_inst_src)
5476 return arg1_value;6510 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);
5479 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);6513 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);
5480 }6514 }
5481 case BuiltinFnIdMod:6515 case BuiltinFnIdMod:
5482 {6516 {
5483 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6517 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5484 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6518 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5485 if (arg0_value == irb->codegen->invalid_instruction)6519 if (arg0_value == irb->codegen->invalid_inst_src)
5486 return arg0_value;6520 return arg0_value;
54876521
5488 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6522 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5489 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6523 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5490 if (arg1_value == irb->codegen->invalid_instruction)6524 if (arg1_value == irb->codegen->invalid_inst_src)
5491 return arg1_value;6525 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);
5494 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);6528 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);
5495 }6529 }
5496 case BuiltinFnIdSqrt:6530 case BuiltinFnIdSqrt:
...@@ -5509,406 +6543,406 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -5509,406 +6543,406 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
5509 case BuiltinFnIdRound:6543 case BuiltinFnIdRound:
5510 {6544 {
5511 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6545 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5512 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6546 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5513 if (arg0_value == irb->codegen->invalid_instruction)6547 if (arg0_value == irb->codegen->invalid_inst_src)
5514 return arg0_value;6548 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);
5517 return ir_lval_wrap(irb, scope, inst, lval, result_loc);6551 return ir_lval_wrap(irb, scope, inst, lval, result_loc);
5518 }6552 }
5519 case BuiltinFnIdTruncate:6553 case BuiltinFnIdTruncate:
5520 {6554 {
5521 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6555 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5522 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6556 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5523 if (arg0_value == irb->codegen->invalid_instruction)6557 if (arg0_value == irb->codegen->invalid_inst_src)
5524 return arg0_value;6558 return arg0_value;
55256559
5526 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6560 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5527 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6561 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5528 if (arg1_value == irb->codegen->invalid_instruction)6562 if (arg1_value == irb->codegen->invalid_inst_src)
5529 return arg1_value;6563 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);
5532 return ir_lval_wrap(irb, scope, truncate, lval, result_loc);6566 return ir_lval_wrap(irb, scope, truncate, lval, result_loc);
5533 }6567 }
5534 case BuiltinFnIdIntCast:6568 case BuiltinFnIdIntCast:
5535 {6569 {
5536 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6570 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5537 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6571 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5538 if (arg0_value == irb->codegen->invalid_instruction)6572 if (arg0_value == irb->codegen->invalid_inst_src)
5539 return arg0_value;6573 return arg0_value;
55406574
5541 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6575 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5542 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6576 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5543 if (arg1_value == irb->codegen->invalid_instruction)6577 if (arg1_value == irb->codegen->invalid_inst_src)
5544 return arg1_value;6578 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);
5547 return ir_lval_wrap(irb, scope, result, lval, result_loc);6581 return ir_lval_wrap(irb, scope, result, lval, result_loc);
5548 }6582 }
5549 case BuiltinFnIdFloatCast:6583 case BuiltinFnIdFloatCast:
5550 {6584 {
5551 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6585 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5552 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6586 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5553 if (arg0_value == irb->codegen->invalid_instruction)6587 if (arg0_value == irb->codegen->invalid_inst_src)
5554 return arg0_value;6588 return arg0_value;
55556589
5556 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6590 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5557 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6591 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5558 if (arg1_value == irb->codegen->invalid_instruction)6592 if (arg1_value == irb->codegen->invalid_inst_src)
5559 return arg1_value;6593 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);
5562 return ir_lval_wrap(irb, scope, result, lval, result_loc);6596 return ir_lval_wrap(irb, scope, result, lval, result_loc);
5563 }6597 }
5564 case BuiltinFnIdErrSetCast:6598 case BuiltinFnIdErrSetCast:
5565 {6599 {
5566 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6600 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5567 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6601 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5568 if (arg0_value == irb->codegen->invalid_instruction)6602 if (arg0_value == irb->codegen->invalid_inst_src)
5569 return arg0_value;6603 return arg0_value;
55706604
5571 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6605 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5572 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6606 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5573 if (arg1_value == irb->codegen->invalid_instruction)6607 if (arg1_value == irb->codegen->invalid_inst_src)
5574 return arg1_value;6608 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);
5577 return ir_lval_wrap(irb, scope, result, lval, result_loc);6611 return ir_lval_wrap(irb, scope, result, lval, result_loc);
5578 }6612 }
5579 case BuiltinFnIdFromBytes:6613 case BuiltinFnIdFromBytes:
5580 {6614 {
5581 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6615 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5582 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6616 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5583 if (arg0_value == irb->codegen->invalid_instruction)6617 if (arg0_value == irb->codegen->invalid_inst_src)
5584 return arg0_value;6618 return arg0_value;
55856619
5586 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6620 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5587 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6621 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5588 if (arg1_value == irb->codegen->invalid_instruction)6622 if (arg1_value == irb->codegen->invalid_inst_src)
5589 return arg1_value;6623 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);
5592 return ir_lval_wrap(irb, scope, result, lval, result_loc);6626 return ir_lval_wrap(irb, scope, result, lval, result_loc);
5593 }6627 }
5594 case BuiltinFnIdToBytes:6628 case BuiltinFnIdToBytes:
5595 {6629 {
5596 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6630 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5597 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6631 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5598 if (arg0_value == irb->codegen->invalid_instruction)6632 if (arg0_value == irb->codegen->invalid_inst_src)
5599 return arg0_value;6633 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);
5602 return ir_lval_wrap(irb, scope, result, lval, result_loc);6636 return ir_lval_wrap(irb, scope, result, lval, result_loc);
5603 }6637 }
5604 case BuiltinFnIdIntToFloat:6638 case BuiltinFnIdIntToFloat:
5605 {6639 {
5606 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6640 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5607 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6641 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5608 if (arg0_value == irb->codegen->invalid_instruction)6642 if (arg0_value == irb->codegen->invalid_inst_src)
5609 return arg0_value;6643 return arg0_value;
56106644
5611 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6645 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5612 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6646 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5613 if (arg1_value == irb->codegen->invalid_instruction)6647 if (arg1_value == irb->codegen->invalid_inst_src)
5614 return arg1_value;6648 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);
5617 return ir_lval_wrap(irb, scope, result, lval, result_loc);6651 return ir_lval_wrap(irb, scope, result, lval, result_loc);
5618 }6652 }
5619 case BuiltinFnIdFloatToInt:6653 case BuiltinFnIdFloatToInt:
5620 {6654 {
5621 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6655 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5622 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6656 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5623 if (arg0_value == irb->codegen->invalid_instruction)6657 if (arg0_value == irb->codegen->invalid_inst_src)
5624 return arg0_value;6658 return arg0_value;
56256659
5626 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6660 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5627 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6661 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5628 if (arg1_value == irb->codegen->invalid_instruction)6662 if (arg1_value == irb->codegen->invalid_inst_src)
5629 return arg1_value;6663 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);
5632 return ir_lval_wrap(irb, scope, result, lval, result_loc);6666 return ir_lval_wrap(irb, scope, result, lval, result_loc);
5633 }6667 }
5634 case BuiltinFnIdErrToInt:6668 case BuiltinFnIdErrToInt:
5635 {6669 {
5636 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6670 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5637 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6671 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5638 if (arg0_value == irb->codegen->invalid_instruction)6672 if (arg0_value == irb->codegen->invalid_inst_src)
5639 return arg0_value;6673 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);
5642 return ir_lval_wrap(irb, scope, result, lval, result_loc);6676 return ir_lval_wrap(irb, scope, result, lval, result_loc);
5643 }6677 }
5644 case BuiltinFnIdIntToErr:6678 case BuiltinFnIdIntToErr:
5645 {6679 {
5646 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6680 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5647 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6681 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5648 if (arg0_value == irb->codegen->invalid_instruction)6682 if (arg0_value == irb->codegen->invalid_inst_src)
5649 return arg0_value;6683 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);
5652 return ir_lval_wrap(irb, scope, result, lval, result_loc);6686 return ir_lval_wrap(irb, scope, result, lval, result_loc);
5653 }6687 }
5654 case BuiltinFnIdBoolToInt:6688 case BuiltinFnIdBoolToInt:
5655 {6689 {
5656 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6690 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5657 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6691 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5658 if (arg0_value == irb->codegen->invalid_instruction)6692 if (arg0_value == irb->codegen->invalid_inst_src)
5659 return arg0_value;6693 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);
5662 return ir_lval_wrap(irb, scope, result, lval, result_loc);6696 return ir_lval_wrap(irb, scope, result, lval, result_loc);
5663 }6697 }
5664 case BuiltinFnIdIntType:6698 case BuiltinFnIdIntType:
5665 {6699 {
5666 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6700 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5667 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6701 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5668 if (arg0_value == irb->codegen->invalid_instruction)6702 if (arg0_value == irb->codegen->invalid_inst_src)
5669 return arg0_value;6703 return arg0_value;
56706704
5671 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6705 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5672 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6706 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5673 if (arg1_value == irb->codegen->invalid_instruction)6707 if (arg1_value == irb->codegen->invalid_inst_src)
5674 return arg1_value;6708 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);
5677 return ir_lval_wrap(irb, scope, int_type, lval, result_loc);6711 return ir_lval_wrap(irb, scope, int_type, lval, result_loc);
5678 }6712 }
5679 case BuiltinFnIdVectorType:6713 case BuiltinFnIdVectorType:
5680 {6714 {
5681 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6715 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5682 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6716 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5683 if (arg0_value == irb->codegen->invalid_instruction)6717 if (arg0_value == irb->codegen->invalid_inst_src)
5684 return arg0_value;6718 return arg0_value;
56856719
5686 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6720 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5687 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6721 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5688 if (arg1_value == irb->codegen->invalid_instruction)6722 if (arg1_value == irb->codegen->invalid_inst_src)
5689 return arg1_value;6723 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);
5692 return ir_lval_wrap(irb, scope, vector_type, lval, result_loc);6726 return ir_lval_wrap(irb, scope, vector_type, lval, result_loc);
5693 }6727 }
5694 case BuiltinFnIdShuffle:6728 case BuiltinFnIdShuffle:
5695 {6729 {
5696 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6730 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5697 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6731 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5698 if (arg0_value == irb->codegen->invalid_instruction)6732 if (arg0_value == irb->codegen->invalid_inst_src)
5699 return arg0_value;6733 return arg0_value;
57006734
5701 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6735 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5702 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6736 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5703 if (arg1_value == irb->codegen->invalid_instruction)6737 if (arg1_value == irb->codegen->invalid_inst_src)
5704 return arg1_value;6738 return arg1_value;
57056739
5706 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);6740 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
5707 IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope);6741 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
5708 if (arg2_value == irb->codegen->invalid_instruction)6742 if (arg2_value == irb->codegen->invalid_inst_src)
5709 return arg2_value;6743 return arg2_value;
57106744
5711 AstNode *arg3_node = node->data.fn_call_expr.params.at(3);6745 AstNode *arg3_node = node->data.fn_call_expr.params.at(3);
5712 IrInstruction *arg3_value = ir_gen_node(irb, arg3_node, scope);6746 IrInstSrc *arg3_value = ir_gen_node(irb, arg3_node, scope);
5713 if (arg3_value == irb->codegen->invalid_instruction)6747 if (arg3_value == irb->codegen->invalid_inst_src)
5714 return arg3_value;6748 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,
5717 arg0_value, arg1_value, arg2_value, arg3_value);6751 arg0_value, arg1_value, arg2_value, arg3_value);
5718 return ir_lval_wrap(irb, scope, shuffle_vector, lval, result_loc);6752 return ir_lval_wrap(irb, scope, shuffle_vector, lval, result_loc);
5719 }6753 }
5720 case BuiltinFnIdSplat:6754 case BuiltinFnIdSplat:
5721 {6755 {
5722 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6756 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5723 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6757 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5724 if (arg0_value == irb->codegen->invalid_instruction)6758 if (arg0_value == irb->codegen->invalid_inst_src)
5725 return arg0_value;6759 return arg0_value;
57266760
5727 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6761 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5728 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6762 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5729 if (arg1_value == irb->codegen->invalid_instruction)6763 if (arg1_value == irb->codegen->invalid_inst_src)
5730 return arg1_value;6764 return arg1_value;
57316765
5732 IrInstruction *splat = ir_build_splat_src(irb, scope, node,6766 IrInstSrc *splat = ir_build_splat_src(irb, scope, node,
5733 arg0_value, arg1_value);6767 arg0_value, arg1_value);
5734 return ir_lval_wrap(irb, scope, splat, lval, result_loc);6768 return ir_lval_wrap(irb, scope, splat, lval, result_loc);
5735 }6769 }
5736 case BuiltinFnIdMemcpy:6770 case BuiltinFnIdMemcpy:
5737 {6771 {
5738 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6772 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5739 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6773 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5740 if (arg0_value == irb->codegen->invalid_instruction)6774 if (arg0_value == irb->codegen->invalid_inst_src)
5741 return arg0_value;6775 return arg0_value;
57426776
5743 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6777 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5744 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6778 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5745 if (arg1_value == irb->codegen->invalid_instruction)6779 if (arg1_value == irb->codegen->invalid_inst_src)
5746 return arg1_value;6780 return arg1_value;
57476781
5748 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);6782 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
5749 IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope);6783 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
5750 if (arg2_value == irb->codegen->invalid_instruction)6784 if (arg2_value == irb->codegen->invalid_inst_src)
5751 return arg2_value;6785 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);
5754 return ir_lval_wrap(irb, scope, ir_memcpy, lval, result_loc);6788 return ir_lval_wrap(irb, scope, ir_memcpy, lval, result_loc);
5755 }6789 }
5756 case BuiltinFnIdMemset:6790 case BuiltinFnIdMemset:
5757 {6791 {
5758 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6792 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5759 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6793 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5760 if (arg0_value == irb->codegen->invalid_instruction)6794 if (arg0_value == irb->codegen->invalid_inst_src)
5761 return arg0_value;6795 return arg0_value;
57626796
5763 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6797 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5764 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6798 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5765 if (arg1_value == irb->codegen->invalid_instruction)6799 if (arg1_value == irb->codegen->invalid_inst_src)
5766 return arg1_value;6800 return arg1_value;
57676801
5768 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);6802 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
5769 IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope);6803 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
5770 if (arg2_value == irb->codegen->invalid_instruction)6804 if (arg2_value == irb->codegen->invalid_inst_src)
5771 return arg2_value;6805 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);
5774 return ir_lval_wrap(irb, scope, ir_memset, lval, result_loc);6808 return ir_lval_wrap(irb, scope, ir_memset, lval, result_loc);
5775 }6809 }
5776 case BuiltinFnIdMemberCount:6810 case BuiltinFnIdMemberCount:
5777 {6811 {
5778 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6812 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5779 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6813 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5780 if (arg0_value == irb->codegen->invalid_instruction)6814 if (arg0_value == irb->codegen->invalid_inst_src)
5781 return arg0_value;6815 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);
5784 return ir_lval_wrap(irb, scope, member_count, lval, result_loc);6818 return ir_lval_wrap(irb, scope, member_count, lval, result_loc);
5785 }6819 }
5786 case BuiltinFnIdMemberType:6820 case BuiltinFnIdMemberType:
5787 {6821 {
5788 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6822 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5789 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6823 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5790 if (arg0_value == irb->codegen->invalid_instruction)6824 if (arg0_value == irb->codegen->invalid_inst_src)
5791 return arg0_value;6825 return arg0_value;
57926826
5793 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6827 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5794 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6828 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5795 if (arg1_value == irb->codegen->invalid_instruction)6829 if (arg1_value == irb->codegen->invalid_inst_src)
5796 return arg1_value;6830 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);
5800 return ir_lval_wrap(irb, scope, member_type, lval, result_loc);6834 return ir_lval_wrap(irb, scope, member_type, lval, result_loc);
5801 }6835 }
5802 case BuiltinFnIdMemberName:6836 case BuiltinFnIdMemberName:
5803 {6837 {
5804 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6838 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5805 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6839 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5806 if (arg0_value == irb->codegen->invalid_instruction)6840 if (arg0_value == irb->codegen->invalid_inst_src)
5807 return arg0_value;6841 return arg0_value;
58086842
5809 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6843 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5810 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6844 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5811 if (arg1_value == irb->codegen->invalid_instruction)6845 if (arg1_value == irb->codegen->invalid_inst_src)
5812 return arg1_value;6846 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);
5816 return ir_lval_wrap(irb, scope, member_name, lval, result_loc);6850 return ir_lval_wrap(irb, scope, member_name, lval, result_loc);
5817 }6851 }
5818 case BuiltinFnIdField:6852 case BuiltinFnIdField:
5819 {6853 {
5820 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6854 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);6855 IrInstSrc *arg0_value = ir_gen_node_extra(irb, arg0_node, scope, LValPtr, nullptr);
5822 if (arg0_value == irb->codegen->invalid_instruction)6856 if (arg0_value == irb->codegen->invalid_inst_src)
5823 return arg0_value;6857 return arg0_value;
58246858
5825 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6859 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5826 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6860 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5827 if (arg1_value == irb->codegen->invalid_instruction)6861 if (arg1_value == irb->codegen->invalid_inst_src)
5828 return arg1_value;6862 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,
5831 arg0_value, arg1_value, false);6865 arg0_value, arg1_value, false);
58326866
5833 if (lval == LValPtr)6867 if (lval == LValPtr)
5834 return ptr_instruction;6868 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);
5837 return ir_expr_wrap(irb, scope, load_ptr, result_loc);6871 return ir_expr_wrap(irb, scope, load_ptr, result_loc);
5838 }6872 }
5839 case BuiltinFnIdHasField:6873 case BuiltinFnIdHasField:
5840 {6874 {
5841 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6875 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5842 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6876 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5843 if (arg0_value == irb->codegen->invalid_instruction)6877 if (arg0_value == irb->codegen->invalid_inst_src)
5844 return arg0_value;6878 return arg0_value;
58456879
5846 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6880 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5847 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6881 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5848 if (arg1_value == irb->codegen->invalid_instruction)6882 if (arg1_value == irb->codegen->invalid_inst_src)
5849 return arg1_value;6883 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);
5852 return ir_lval_wrap(irb, scope, type_info, lval, result_loc);6886 return ir_lval_wrap(irb, scope, type_info, lval, result_loc);
5853 }6887 }
5854 case BuiltinFnIdTypeInfo:6888 case BuiltinFnIdTypeInfo:
5855 {6889 {
5856 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6890 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5857 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6891 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5858 if (arg0_value == irb->codegen->invalid_instruction)6892 if (arg0_value == irb->codegen->invalid_inst_src)
5859 return arg0_value;6893 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);
5862 return ir_lval_wrap(irb, scope, type_info, lval, result_loc);6896 return ir_lval_wrap(irb, scope, type_info, lval, result_loc);
5863 }6897 }
5864 case BuiltinFnIdType:6898 case BuiltinFnIdType:
5865 {6899 {
5866 AstNode *arg_node = node->data.fn_call_expr.params.at(0);6900 AstNode *arg_node = node->data.fn_call_expr.params.at(0);
5867 IrInstruction *arg = ir_gen_node(irb, arg_node, scope);6901 IrInstSrc *arg = ir_gen_node(irb, arg_node, scope);
5868 if (arg == irb->codegen->invalid_instruction)6902 if (arg == irb->codegen->invalid_inst_src)
5869 return arg;6903 return arg;
58706904
5871 IrInstruction *type = ir_build_type(irb, scope, node, arg);6905 IrInstSrc *type = ir_build_type(irb, scope, node, arg);
5872 return ir_lval_wrap(irb, scope, type, lval, result_loc);6906 return ir_lval_wrap(irb, scope, type, lval, result_loc);
5873 }6907 }
5874 case BuiltinFnIdBreakpoint:6908 case BuiltinFnIdBreakpoint:
5875 return ir_lval_wrap(irb, scope, ir_build_breakpoint(irb, scope, node), lval, result_loc);6909 return ir_lval_wrap(irb, scope, ir_build_breakpoint(irb, scope, node), lval, result_loc);
5876 case BuiltinFnIdReturnAddress:6910 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);
5878 case BuiltinFnIdFrameAddress:6912 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);
5880 case BuiltinFnIdFrameHandle:6914 case BuiltinFnIdFrameHandle:
5881 if (!irb->exec->fn_entry) {6915 if (!irb->exec->fn_entry) {
5882 add_node_error(irb->codegen, node, buf_sprintf("@frame() called outside of function definition"));6916 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;
5884 }6918 }
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);
5886 case BuiltinFnIdFrameType: {6920 case BuiltinFnIdFrameType: {
5887 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6921 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5888 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6922 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5889 if (arg0_value == irb->codegen->invalid_instruction)6923 if (arg0_value == irb->codegen->invalid_inst_src)
5890 return arg0_value;6924 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);
5893 return ir_lval_wrap(irb, scope, frame_type, lval, result_loc);6927 return ir_lval_wrap(irb, scope, frame_type, lval, result_loc);
5894 }6928 }
5895 case BuiltinFnIdFrameSize: {6929 case BuiltinFnIdFrameSize: {
5896 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6930 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5897 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6931 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5898 if (arg0_value == irb->codegen->invalid_instruction)6932 if (arg0_value == irb->codegen->invalid_inst_src)
5899 return arg0_value;6933 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);
5902 return ir_lval_wrap(irb, scope, frame_size, lval, result_loc);6936 return ir_lval_wrap(irb, scope, frame_size, lval, result_loc);
5903 }6937 }
5904 case BuiltinFnIdAlignOf:6938 case BuiltinFnIdAlignOf:
5905 {6939 {
5906 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6940 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5907 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6941 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5908 if (arg0_value == irb->codegen->invalid_instruction)6942 if (arg0_value == irb->codegen->invalid_inst_src)
5909 return arg0_value;6943 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);
5912 return ir_lval_wrap(irb, scope, align_of, lval, result_loc);6946 return ir_lval_wrap(irb, scope, align_of, lval, result_loc);
5913 }6947 }
5914 case BuiltinFnIdAddWithOverflow:6948 case BuiltinFnIdAddWithOverflow:
...@@ -5924,43 +6958,43 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -5924,43 +6958,43 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
5924 case BuiltinFnIdTypeName:6958 case BuiltinFnIdTypeName:
5925 {6959 {
5926 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6960 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5927 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6961 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5928 if (arg0_value == irb->codegen->invalid_instruction)6962 if (arg0_value == irb->codegen->invalid_inst_src)
5929 return arg0_value;6963 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);
5932 return ir_lval_wrap(irb, scope, type_name, lval, result_loc);6966 return ir_lval_wrap(irb, scope, type_name, lval, result_loc);
5933 }6967 }
5934 case BuiltinFnIdPanic:6968 case BuiltinFnIdPanic:
5935 {6969 {
5936 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6970 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5937 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6971 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5938 if (arg0_value == irb->codegen->invalid_instruction)6972 if (arg0_value == irb->codegen->invalid_inst_src)
5939 return arg0_value;6973 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);
5942 return ir_lval_wrap(irb, scope, panic, lval, result_loc);6976 return ir_lval_wrap(irb, scope, panic, lval, result_loc);
5943 }6977 }
5944 case BuiltinFnIdPtrCast:6978 case BuiltinFnIdPtrCast:
5945 {6979 {
5946 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6980 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5947 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6981 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5948 if (arg0_value == irb->codegen->invalid_instruction)6982 if (arg0_value == irb->codegen->invalid_inst_src)
5949 return arg0_value;6983 return arg0_value;
59506984
5951 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6985 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5952 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6986 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5953 if (arg1_value == irb->codegen->invalid_instruction)6987 if (arg1_value == irb->codegen->invalid_inst_src)
5954 return arg1_value;6988 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);
5957 return ir_lval_wrap(irb, scope, ptr_cast, lval, result_loc);6991 return ir_lval_wrap(irb, scope, ptr_cast, lval, result_loc);
5958 }6992 }
5959 case BuiltinFnIdBitCast:6993 case BuiltinFnIdBitCast:
5960 {6994 {
5961 AstNode *dest_type_node = node->data.fn_call_expr.params.at(0);6995 AstNode *dest_type_node = node->data.fn_call_expr.params.at(0);
5962 IrInstruction *dest_type = ir_gen_node(irb, dest_type_node, scope);6996 IrInstSrc *dest_type = ir_gen_node(irb, dest_type_node, scope);
5963 if (dest_type == irb->codegen->invalid_instruction)6997 if (dest_type == irb->codegen->invalid_inst_src)
5964 return dest_type;6998 return dest_type;
59656999
5966 ResultLocBitCast *result_loc_bit_cast = allocate<ResultLocBitCast>(1);7000 ResultLocBitCast *result_loc_bit_cast = allocate<ResultLocBitCast>(1);
...@@ -5972,125 +7006,126 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -5972,125 +7006,126 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
5972 ir_build_reset_result(irb, scope, node, &result_loc_bit_cast->base);7006 ir_build_reset_result(irb, scope, node, &result_loc_bit_cast->base);
59737007
5974 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);7008 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,
5976 &result_loc_bit_cast->base);7010 &result_loc_bit_cast->base);
5977 if (arg1_value == irb->codegen->invalid_instruction)7011 if (arg1_value == irb->codegen->invalid_inst_src)
5978 return arg1_value;7012 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);
5981 return ir_lval_wrap(irb, scope, bitcast, lval, result_loc);7015 return ir_lval_wrap(irb, scope, bitcast, lval, result_loc);
5982 }7016 }
5983 case BuiltinFnIdAs:7017 case BuiltinFnIdAs:
5984 {7018 {
5985 AstNode *dest_type_node = node->data.fn_call_expr.params.at(0);7019 AstNode *dest_type_node = node->data.fn_call_expr.params.at(0);
5986 IrInstruction *dest_type = ir_gen_node(irb, dest_type_node, scope);7020 IrInstSrc *dest_type = ir_gen_node(irb, dest_type_node, scope);
5987 if (dest_type == irb->codegen->invalid_instruction)7021 if (dest_type == irb->codegen->invalid_inst_src)
5988 return dest_type;7022 return dest_type;
59897023
5990 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, dest_type, result_loc);7024 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, dest_type, result_loc);
59917025
5992 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);7026 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,
5994 &result_loc_cast->base);7028 &result_loc_cast->base);
5995 if (arg1_value == irb->codegen->invalid_instruction)7029 if (arg1_value == irb->codegen->invalid_inst_src)
5996 return arg1_value;7030 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);
5999 return ir_lval_wrap(irb, scope, result, lval, result_loc);7033 return ir_lval_wrap(irb, scope, result, lval, result_loc);
6000 }7034 }
6001 case BuiltinFnIdIntToPtr:7035 case BuiltinFnIdIntToPtr:
6002 {7036 {
6003 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7037 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6004 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7038 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6005 if (arg0_value == irb->codegen->invalid_instruction)7039 if (arg0_value == irb->codegen->invalid_inst_src)
6006 return arg0_value;7040 return arg0_value;
60077041
6008 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);7042 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6009 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);7043 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6010 if (arg1_value == irb->codegen->invalid_instruction)7044 if (arg1_value == irb->codegen->invalid_inst_src)
6011 return arg1_value;7045 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);
6014 return ir_lval_wrap(irb, scope, int_to_ptr, lval, result_loc);7048 return ir_lval_wrap(irb, scope, int_to_ptr, lval, result_loc);
6015 }7049 }
6016 case BuiltinFnIdPtrToInt:7050 case BuiltinFnIdPtrToInt:
6017 {7051 {
6018 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7052 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6019 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7053 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6020 if (arg0_value == irb->codegen->invalid_instruction)7054 if (arg0_value == irb->codegen->invalid_inst_src)
6021 return arg0_value;7055 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);
6024 return ir_lval_wrap(irb, scope, ptr_to_int, lval, result_loc);7058 return ir_lval_wrap(irb, scope, ptr_to_int, lval, result_loc);
6025 }7059 }
6026 case BuiltinFnIdTagName:7060 case BuiltinFnIdTagName:
6027 {7061 {
6028 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7062 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6029 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7063 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6030 if (arg0_value == irb->codegen->invalid_instruction)7064 if (arg0_value == irb->codegen->invalid_inst_src)
6031 return arg0_value;7065 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);
6034 return ir_lval_wrap(irb, scope, tag_name, lval, result_loc);7068 return ir_lval_wrap(irb, scope, tag_name, lval, result_loc);
6035 }7069 }
6036 case BuiltinFnIdTagType:7070 case BuiltinFnIdTagType:
6037 {7071 {
6038 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7072 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6039 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7073 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6040 if (arg0_value == irb->codegen->invalid_instruction)7074 if (arg0_value == irb->codegen->invalid_inst_src)
6041 return arg0_value;7075 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);
6044 return ir_lval_wrap(irb, scope, tag_type, lval, result_loc);7078 return ir_lval_wrap(irb, scope, tag_type, lval, result_loc);
6045 }7079 }
6046 case BuiltinFnIdFieldParentPtr:7080 case BuiltinFnIdFieldParentPtr:
6047 {7081 {
6048 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7082 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6049 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7083 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6050 if (arg0_value == irb->codegen->invalid_instruction)7084 if (arg0_value == irb->codegen->invalid_inst_src)
6051 return arg0_value;7085 return arg0_value;
60527086
6053 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);7087 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6054 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);7088 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6055 if (arg1_value == irb->codegen->invalid_instruction)7089 if (arg1_value == irb->codegen->invalid_inst_src)
6056 return arg1_value;7090 return arg1_value;
60577091
6058 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);7092 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
6059 IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope);7093 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
6060 if (arg2_value == irb->codegen->invalid_instruction)7094 if (arg2_value == irb->codegen->invalid_inst_src)
6061 return arg2_value;7095 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);
6064 return ir_lval_wrap(irb, scope, field_parent_ptr, lval, result_loc);7099 return ir_lval_wrap(irb, scope, field_parent_ptr, lval, result_loc);
6065 }7100 }
6066 case BuiltinFnIdByteOffsetOf:7101 case BuiltinFnIdByteOffsetOf:
6067 {7102 {
6068 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7103 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6069 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7104 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6070 if (arg0_value == irb->codegen->invalid_instruction)7105 if (arg0_value == irb->codegen->invalid_inst_src)
6071 return arg0_value;7106 return arg0_value;
60727107
6073 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);7108 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6074 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);7109 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6075 if (arg1_value == irb->codegen->invalid_instruction)7110 if (arg1_value == irb->codegen->invalid_inst_src)
6076 return arg1_value;7111 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);
6079 return ir_lval_wrap(irb, scope, offset_of, lval, result_loc);7114 return ir_lval_wrap(irb, scope, offset_of, lval, result_loc);
6080 }7115 }
6081 case BuiltinFnIdBitOffsetOf:7116 case BuiltinFnIdBitOffsetOf:
6082 {7117 {
6083 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7118 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6084 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7119 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6085 if (arg0_value == irb->codegen->invalid_instruction)7120 if (arg0_value == irb->codegen->invalid_inst_src)
6086 return arg0_value;7121 return arg0_value;
60877122
6088 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);7123 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6089 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);7124 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6090 if (arg1_value == irb->codegen->invalid_instruction)7125 if (arg1_value == irb->codegen->invalid_inst_src)
6091 return arg1_value;7126 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);
6094 return ir_lval_wrap(irb, scope, offset_of, lval, result_loc);7129 return ir_lval_wrap(irb, scope, offset_of, lval, result_loc);
6095 }7130 }
6096 case BuiltinFnIdNewStackCall:7131 case BuiltinFnIdNewStackCall:
...@@ -6099,45 +7134,45 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -6099,45 +7134,45 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
6099 add_node_error(irb->codegen, node,7134 add_node_error(irb->codegen, node,
6100 buf_sprintf("expected at least 2 arguments, found %" ZIG_PRI_usize,7135 buf_sprintf("expected at least 2 arguments, found %" ZIG_PRI_usize,
6101 node->data.fn_call_expr.params.length));7136 node->data.fn_call_expr.params.length));
6102 return irb->codegen->invalid_instruction;7137 return irb->codegen->invalid_inst_src;
6103 }7138 }
61047139
6105 AstNode *new_stack_node = node->data.fn_call_expr.params.at(0);7140 AstNode *new_stack_node = node->data.fn_call_expr.params.at(0);
6106 IrInstruction *new_stack = ir_gen_node(irb, new_stack_node, scope);7141 IrInstSrc *new_stack = ir_gen_node(irb, new_stack_node, scope);
6107 if (new_stack == irb->codegen->invalid_instruction)7142 if (new_stack == irb->codegen->invalid_inst_src)
6108 return new_stack;7143 return new_stack;
61097144
6110 AstNode *fn_ref_node = node->data.fn_call_expr.params.at(1);7145 AstNode *fn_ref_node = node->data.fn_call_expr.params.at(1);
6111 IrInstruction *fn_ref = ir_gen_node(irb, fn_ref_node, scope);7146 IrInstSrc *fn_ref = ir_gen_node(irb, fn_ref_node, scope);
6112 if (fn_ref == irb->codegen->invalid_instruction)7147 if (fn_ref == irb->codegen->invalid_inst_src)
6113 return fn_ref;7148 return fn_ref;
61147149
6115 size_t arg_count = node->data.fn_call_expr.params.length - 2;7150 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);
6118 for (size_t i = 0; i < arg_count; i += 1) {7153 for (size_t i = 0; i < arg_count; i += 1) {
6119 AstNode *arg_node = node->data.fn_call_expr.params.at(i + 2);7154 AstNode *arg_node = node->data.fn_call_expr.params.at(i + 2);
6120 args[i] = ir_gen_node(irb, arg_node, scope);7155 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)
6122 return args[i];7157 return args[i];
6123 }7158 }
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,
6126 nullptr, CallModifierNone, false, new_stack, result_loc);7161 nullptr, CallModifierNone, false, new_stack, result_loc);
6127 return ir_lval_wrap(irb, scope, call, lval, result_loc);7162 return ir_lval_wrap(irb, scope, call, lval, result_loc);
6128 }7163 }
6129 case BuiltinFnIdCall: {7164 case BuiltinFnIdCall: {
6130 // Cast the options parameter to the options type7165 // Cast the options parameter to the options type
6131 ZigType *options_type = get_builtin_type(irb->codegen, "CallOptions");7166 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);
6133 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, options_type_inst, no_result_loc());7168 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, options_type_inst, no_result_loc());
61347169
6135 AstNode *options_node = node->data.fn_call_expr.params.at(0);7170 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,
6137 LValNone, &result_loc_cast->base);7172 LValNone, &result_loc_cast->base);
6138 if (options_inner == irb->codegen->invalid_instruction)7173 if (options_inner == irb->codegen->invalid_inst_src)
6139 return options_inner;7174 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
6142 AstNode *fn_ref_node = node->data.fn_call_expr.params.at(1);7177 AstNode *fn_ref_node = node->data.fn_call_expr.params.at(1);
6143 AstNode *args_node = node->data.fn_call_expr.params.at(2);7178 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...@@ -6153,18 +7188,18 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
6153 } else {7188 } else {
6154 exec_add_error_node(irb->codegen, irb->exec, args_node,7189 exec_add_error_node(irb->codegen, irb->exec, args_node,
6155 buf_sprintf("TODO: @call with anon struct literal"));7190 buf_sprintf("TODO: @call with anon struct literal"));
6156 return irb->codegen->invalid_instruction;7191 return irb->codegen->invalid_inst_src;
6157 }7192 }
6158 } else {7193 } else {
6159 IrInstruction *fn_ref = ir_gen_node(irb, fn_ref_node, scope);7194 IrInstSrc *fn_ref = ir_gen_node(irb, fn_ref_node, scope);
6160 if (fn_ref == irb->codegen->invalid_instruction)7195 if (fn_ref == irb->codegen->invalid_inst_src)
6161 return fn_ref;7196 return fn_ref;
61627197
6163 IrInstruction *args = ir_gen_node(irb, args_node, scope);7198 IrInstSrc *args = ir_gen_node(irb, args_node, scope);
6164 if (args == irb->codegen->invalid_instruction)7199 if (args == irb->codegen->invalid_inst_src)
6165 return args;7200 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);
6168 return ir_lval_wrap(irb, scope, call, lval, result_loc);7203 return ir_lval_wrap(irb, scope, call, lval, result_loc);
6169 }7204 }
6170 }7205 }
...@@ -6173,237 +7208,233 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -6173,237 +7208,233 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
6173 case BuiltinFnIdTypeId:7208 case BuiltinFnIdTypeId:
6174 {7209 {
6175 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7210 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6176 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7211 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6177 if (arg0_value == irb->codegen->invalid_instruction)7212 if (arg0_value == irb->codegen->invalid_inst_src)
6178 return arg0_value;7213 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);
6181 return ir_lval_wrap(irb, scope, type_id, lval, result_loc);7216 return ir_lval_wrap(irb, scope, type_id, lval, result_loc);
6182 }7217 }
6183 case BuiltinFnIdShlExact:7218 case BuiltinFnIdShlExact:
6184 {7219 {
6185 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7220 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6186 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7221 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6187 if (arg0_value == irb->codegen->invalid_instruction)7222 if (arg0_value == irb->codegen->invalid_inst_src)
6188 return arg0_value;7223 return arg0_value;
61897224
6190 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);7225 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6191 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);7226 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6192 if (arg1_value == irb->codegen->invalid_instruction)7227 if (arg1_value == irb->codegen->invalid_inst_src)
6193 return arg1_value;7228 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);
6196 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);7231 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);
6197 }7232 }
6198 case BuiltinFnIdShrExact:7233 case BuiltinFnIdShrExact:
6199 {7234 {
6200 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7235 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6201 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7236 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6202 if (arg0_value == irb->codegen->invalid_instruction)7237 if (arg0_value == irb->codegen->invalid_inst_src)
6203 return arg0_value;7238 return arg0_value;
62047239
6205 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);7240 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6206 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);7241 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6207 if (arg1_value == irb->codegen->invalid_instruction)7242 if (arg1_value == irb->codegen->invalid_inst_src)
6208 return arg1_value;7243 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);
6211 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);7246 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);
6212 }7247 }
6213 case BuiltinFnIdSetEvalBranchQuota:7248 case BuiltinFnIdSetEvalBranchQuota:
6214 {7249 {
6215 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7250 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6216 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7251 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6217 if (arg0_value == irb->codegen->invalid_instruction)7252 if (arg0_value == irb->codegen->invalid_inst_src)
6218 return arg0_value;7253 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);
6221 return ir_lval_wrap(irb, scope, set_eval_branch_quota, lval, result_loc);7256 return ir_lval_wrap(irb, scope, set_eval_branch_quota, lval, result_loc);
6222 }7257 }
6223 case BuiltinFnIdAlignCast:7258 case BuiltinFnIdAlignCast:
6224 {7259 {
6225 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7260 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6226 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7261 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6227 if (arg0_value == irb->codegen->invalid_instruction)7262 if (arg0_value == irb->codegen->invalid_inst_src)
6228 return arg0_value;7263 return arg0_value;
62297264
6230 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);7265 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6231 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);7266 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6232 if (arg1_value == irb->codegen->invalid_instruction)7267 if (arg1_value == irb->codegen->invalid_inst_src)
6233 return arg1_value;7268 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);
6236 return ir_lval_wrap(irb, scope, align_cast, lval, result_loc);7271 return ir_lval_wrap(irb, scope, align_cast, lval, result_loc);
6237 }7272 }
6238 case BuiltinFnIdOpaqueType:7273 case BuiltinFnIdOpaqueType:
6239 {7274 {
6240 IrInstruction *opaque_type = ir_build_opaque_type(irb, scope, node);7275 IrInstSrc *opaque_type = ir_build_opaque_type(irb, scope, node);
6241 return ir_lval_wrap(irb, scope, opaque_type, lval, result_loc);7276 return ir_lval_wrap(irb, scope, opaque_type, lval, result_loc);
6242 }7277 }
6243 case BuiltinFnIdThis:7278 case BuiltinFnIdThis:
6244 {7279 {
6245 IrInstruction *this_inst = ir_gen_this(irb, scope, node);7280 IrInstSrc *this_inst = ir_gen_this(irb, scope, node);
6246 return ir_lval_wrap(irb, scope, this_inst, lval, result_loc);7281 return ir_lval_wrap(irb, scope, this_inst, lval, result_loc);
6247 }7282 }
6248 case BuiltinFnIdSetAlignStack:7283 case BuiltinFnIdSetAlignStack:
6249 {7284 {
6250 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7285 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6251 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7286 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6252 if (arg0_value == irb->codegen->invalid_instruction)7287 if (arg0_value == irb->codegen->invalid_inst_src)
6253 return arg0_value;7288 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);
6256 return ir_lval_wrap(irb, scope, set_align_stack, lval, result_loc);7291 return ir_lval_wrap(irb, scope, set_align_stack, lval, result_loc);
6257 }7292 }
6258 case BuiltinFnIdArgType:7293 case BuiltinFnIdArgType:
6259 {7294 {
6260 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7295 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6261 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7296 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6262 if (arg0_value == irb->codegen->invalid_instruction)7297 if (arg0_value == irb->codegen->invalid_inst_src)
6263 return arg0_value;7298 return arg0_value;
62647299
6265 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);7300 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6266 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);7301 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6267 if (arg1_value == irb->codegen->invalid_instruction)7302 if (arg1_value == irb->codegen->invalid_inst_src)
6268 return arg1_value;7303 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);
6271 return ir_lval_wrap(irb, scope, arg_type, lval, result_loc);7306 return ir_lval_wrap(irb, scope, arg_type, lval, result_loc);
6272 }7307 }
6273 case BuiltinFnIdExport:7308 case BuiltinFnIdExport:
6274 {7309 {
6275 // Cast the options parameter to the options type7310 // Cast the options parameter to the options type
6276 ZigType *options_type = get_builtin_type(irb->codegen, "ExportOptions");7311 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);
6278 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, options_type_inst, no_result_loc());7313 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, options_type_inst, no_result_loc());
62797314
6280 AstNode *target_node = node->data.fn_call_expr.params.at(0);7315 AstNode *target_node = node->data.fn_call_expr.params.at(0);
6281 IrInstruction *target_value = ir_gen_node(irb, target_node, scope);7316 IrInstSrc *target_value = ir_gen_node(irb, target_node, scope);
6282 if (target_value == irb->codegen->invalid_instruction)7317 if (target_value == irb->codegen->invalid_inst_src)
6283 return target_value;7318 return target_value;
62847319
6285 AstNode *options_node = node->data.fn_call_expr.params.at(1);7320 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,
6287 scope, LValNone, &result_loc_cast->base);7322 scope, LValNone, &result_loc_cast->base);
6288 if (options_value == irb->codegen->invalid_instruction)7323 if (options_value == irb->codegen->invalid_inst_src)
6289 return options_value;7324 return options_value;
62907325
6291 IrInstruction *casted_options_value = ir_build_implicit_cast(7326 IrInstSrc *casted_options_value = ir_build_implicit_cast(
6292 irb, scope, options_node, options_value, result_loc_cast);7327 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);
6295 return ir_lval_wrap(irb, scope, ir_export, lval, result_loc);7330 return ir_lval_wrap(irb, scope, ir_export, lval, result_loc);
6296 }7331 }
6297 case BuiltinFnIdErrorReturnTrace:7332 case BuiltinFnIdErrorReturnTrace:
6298 {7333 {
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);
6300 return ir_lval_wrap(irb, scope, error_return_trace, lval, result_loc);7336 return ir_lval_wrap(irb, scope, error_return_trace, lval, result_loc);
6301 }7337 }
6302 case BuiltinFnIdAtomicRmw:7338 case BuiltinFnIdAtomicRmw:
6303 {7339 {
6304 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7340 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6305 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7341 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6306 if (arg0_value == irb->codegen->invalid_instruction)7342 if (arg0_value == irb->codegen->invalid_inst_src)
6307 return arg0_value;7343 return arg0_value;
63087344
6309 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);7345 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6310 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);7346 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6311 if (arg1_value == irb->codegen->invalid_instruction)7347 if (arg1_value == irb->codegen->invalid_inst_src)
6312 return arg1_value;7348 return arg1_value;
63137349
6314 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);7350 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
6315 IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope);7351 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
6316 if (arg2_value == irb->codegen->invalid_instruction)7352 if (arg2_value == irb->codegen->invalid_inst_src)
6317 return arg2_value;7353 return arg2_value;
63187354
6319 AstNode *arg3_node = node->data.fn_call_expr.params.at(3);7355 AstNode *arg3_node = node->data.fn_call_expr.params.at(3);
6320 IrInstruction *arg3_value = ir_gen_node(irb, arg3_node, scope);7356 IrInstSrc *arg3_value = ir_gen_node(irb, arg3_node, scope);
6321 if (arg3_value == irb->codegen->invalid_instruction)7357 if (arg3_value == irb->codegen->invalid_inst_src)
6322 return arg3_value;7358 return arg3_value;
63237359
6324 AstNode *arg4_node = node->data.fn_call_expr.params.at(4);7360 AstNode *arg4_node = node->data.fn_call_expr.params.at(4);
6325 IrInstruction *arg4_value = ir_gen_node(irb, arg4_node, scope);7361 IrInstSrc *arg4_value = ir_gen_node(irb, arg4_node, scope);
6326 if (arg4_value == irb->codegen->invalid_instruction)7362 if (arg4_value == irb->codegen->invalid_inst_src)
6327 return arg4_value;7363 return arg4_value;
63287364
6329 IrInstruction *inst = ir_build_atomic_rmw(irb, scope, node, arg0_value, arg1_value, arg2_value, arg3_value,7365 IrInstSrc *inst = ir_build_atomic_rmw_src(irb, scope, node,
6330 arg4_value,7366 arg0_value, arg1_value, arg2_value, arg3_value, arg4_value);
6331 // these 2 values don't mean anything since we passed non-null values for other args
6332 AtomicRmwOp_xchg, AtomicOrderMonotonic);
6333 return ir_lval_wrap(irb, scope, inst, lval, result_loc);7367 return ir_lval_wrap(irb, scope, inst, lval, result_loc);
6334 }7368 }
6335 case BuiltinFnIdAtomicLoad:7369 case BuiltinFnIdAtomicLoad:
6336 {7370 {
6337 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7371 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6338 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7372 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6339 if (arg0_value == irb->codegen->invalid_instruction)7373 if (arg0_value == irb->codegen->invalid_inst_src)
6340 return arg0_value;7374 return arg0_value;
63417375
6342 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);7376 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6343 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);7377 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6344 if (arg1_value == irb->codegen->invalid_instruction)7378 if (arg1_value == irb->codegen->invalid_inst_src)
6345 return arg1_value;7379 return arg1_value;
63467380
6347 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);7381 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
6348 IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope);7382 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
6349 if (arg2_value == irb->codegen->invalid_instruction)7383 if (arg2_value == irb->codegen->invalid_inst_src)
6350 return arg2_value;7384 return arg2_value;
63517385
6352 IrInstruction *inst = ir_build_atomic_load(irb, scope, node, arg0_value, arg1_value, arg2_value,7386 IrInstSrc *inst = ir_build_atomic_load_src(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);
6355 return ir_lval_wrap(irb, scope, inst, lval, result_loc);7387 return ir_lval_wrap(irb, scope, inst, lval, result_loc);
6356 }7388 }
6357 case BuiltinFnIdAtomicStore:7389 case BuiltinFnIdAtomicStore:
6358 {7390 {
6359 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7391 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6360 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7392 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6361 if (arg0_value == irb->codegen->invalid_instruction)7393 if (arg0_value == irb->codegen->invalid_inst_src)
6362 return arg0_value;7394 return arg0_value;
63637395
6364 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);7396 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6365 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);7397 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6366 if (arg1_value == irb->codegen->invalid_instruction)7398 if (arg1_value == irb->codegen->invalid_inst_src)
6367 return arg1_value;7399 return arg1_value;
63687400
6369 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);7401 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
6370 IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope);7402 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
6371 if (arg2_value == irb->codegen->invalid_instruction)7403 if (arg2_value == irb->codegen->invalid_inst_src)
6372 return arg2_value;7404 return arg2_value;
63737405
6374 AstNode *arg3_node = node->data.fn_call_expr.params.at(3);7406 AstNode *arg3_node = node->data.fn_call_expr.params.at(3);
6375 IrInstruction *arg3_value = ir_gen_node(irb, arg3_node, scope);7407 IrInstSrc *arg3_value = ir_gen_node(irb, arg3_node, scope);
6376 if (arg3_value == irb->codegen->invalid_instruction)7408 if (arg3_value == irb->codegen->invalid_inst_src)
6377 return arg3_value;7409 return arg3_value;
63787410
6379 IrInstruction *inst = ir_build_atomic_store(irb, scope, node, arg0_value, arg1_value, arg2_value, arg3_value,7411 IrInstSrc *inst = ir_build_atomic_store_src(irb, scope, node, arg0_value, arg1_value,
6380 // this value does not mean anything since we passed non-null values for other arg7412 arg2_value, arg3_value);
6381 AtomicOrderMonotonic);
6382 return ir_lval_wrap(irb, scope, inst, lval, result_loc);7413 return ir_lval_wrap(irb, scope, inst, lval, result_loc);
6383 }7414 }
6384 case BuiltinFnIdIntToEnum:7415 case BuiltinFnIdIntToEnum:
6385 {7416 {
6386 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7417 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6387 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7418 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6388 if (arg0_value == irb->codegen->invalid_instruction)7419 if (arg0_value == irb->codegen->invalid_inst_src)
6389 return arg0_value;7420 return arg0_value;
63907421
6391 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);7422 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6392 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);7423 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6393 if (arg1_value == irb->codegen->invalid_instruction)7424 if (arg1_value == irb->codegen->invalid_inst_src)
6394 return arg1_value;7425 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);
6397 return ir_lval_wrap(irb, scope, result, lval, result_loc);7428 return ir_lval_wrap(irb, scope, result, lval, result_loc);
6398 }7429 }
6399 case BuiltinFnIdEnumToInt:7430 case BuiltinFnIdEnumToInt:
6400 {7431 {
6401 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7432 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6402 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7433 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6403 if (arg0_value == irb->codegen->invalid_instruction)7434 if (arg0_value == irb->codegen->invalid_inst_src)
6404 return arg0_value;7435 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);
6407 return ir_lval_wrap(irb, scope, result, lval, result_loc);7438 return ir_lval_wrap(irb, scope, result, lval, result_loc);
6408 }7439 }
6409 case BuiltinFnIdCtz:7440 case BuiltinFnIdCtz:
...@@ -6413,16 +7444,16 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -6413,16 +7444,16 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
6413 case BuiltinFnIdBitReverse:7444 case BuiltinFnIdBitReverse:
6414 {7445 {
6415 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7446 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6416 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7447 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6417 if (arg0_value == irb->codegen->invalid_instruction)7448 if (arg0_value == irb->codegen->invalid_inst_src)
6418 return arg0_value;7449 return arg0_value;
64197450
6420 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);7451 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6421 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);7452 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6422 if (arg1_value == irb->codegen->invalid_instruction)7453 if (arg1_value == irb->codegen->invalid_inst_src)
6423 return arg1_value;7454 return arg1_value;
64247455
6425 IrInstruction *result;7456 IrInstSrc *result;
6426 switch (builtin_fn->id) {7457 switch (builtin_fn->id) {
6427 case BuiltinFnIdCtz:7458 case BuiltinFnIdCtz:
6428 result = ir_build_ctz(irb, scope, node, arg0_value, arg1_value);7459 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...@@ -6447,28 +7478,28 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
6447 case BuiltinFnIdHasDecl:7478 case BuiltinFnIdHasDecl:
6448 {7479 {
6449 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7480 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6450 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7481 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6451 if (arg0_value == irb->codegen->invalid_instruction)7482 if (arg0_value == irb->codegen->invalid_inst_src)
6452 return arg0_value;7483 return arg0_value;
64537484
6454 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);7485 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6455 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);7486 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6456 if (arg1_value == irb->codegen->invalid_instruction)7487 if (arg1_value == irb->codegen->invalid_inst_src)
6457 return arg1_value;7488 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);
6460 return ir_lval_wrap(irb, scope, has_decl, lval, result_loc);7491 return ir_lval_wrap(irb, scope, has_decl, lval, result_loc);
6461 }7492 }
6462 case BuiltinFnIdUnionInit:7493 case BuiltinFnIdUnionInit:
6463 {7494 {
6464 AstNode *union_type_node = node->data.fn_call_expr.params.at(0);7495 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);7496 IrInstSrc *union_type_inst = ir_gen_node(irb, union_type_node, scope);
6466 if (union_type_inst == irb->codegen->invalid_instruction)7497 if (union_type_inst == irb->codegen->invalid_inst_src)
6467 return union_type_inst;7498 return union_type_inst;
64687499
6469 AstNode *name_node = node->data.fn_call_expr.params.at(1);7500 AstNode *name_node = node->data.fn_call_expr.params.at(1);
6470 IrInstruction *name_inst = ir_gen_node(irb, name_node, scope);7501 IrInstSrc *name_inst = ir_gen_node(irb, name_node, scope);
6471 if (name_inst == irb->codegen->invalid_instruction)7502 if (name_inst == irb->codegen->invalid_inst_src)
6472 return name_inst;7503 return name_inst;
64737504
6474 AstNode *init_node = node->data.fn_call_expr.params.at(2);7505 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...@@ -6480,7 +7511,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
6480 zig_unreachable();7511 zig_unreachable();
6481}7512}
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,
6484 ResultLoc *result_loc)7515 ResultLoc *result_loc)
6485{7516{
6486 assert(node->type == NodeTypeFnCallExpr);7517 assert(node->type == NodeTypeFnCallExpr);
...@@ -6493,16 +7524,16 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, Scope *scope, AstNode *node...@@ -6493,16 +7524,16 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, Scope *scope, AstNode *node
6493 nullptr, node->data.fn_call_expr.params.items, node->data.fn_call_expr.params.length, lval, result_loc);7524 nullptr, node->data.fn_call_expr.params.items, node->data.fn_call_expr.params.length, lval, result_loc);
6494}7525}
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,
6497 ResultLoc *result_loc)7528 ResultLoc *result_loc)
6498{7529{
6499 assert(node->type == NodeTypeIfBoolExpr);7530 assert(node->type == NodeTypeIfBoolExpr);
65007531
6501 IrInstruction *condition = ir_gen_node(irb, node->data.if_bool_expr.condition, scope);7532 IrInstSrc *condition = ir_gen_node(irb, node->data.if_bool_expr.condition, scope);
6502 if (condition == irb->codegen->invalid_instruction)7533 if (condition == irb->codegen->invalid_inst_src)
6503 return irb->codegen->invalid_instruction;7534 return irb->codegen->invalid_inst_src;
65047535
6505 IrInstruction *is_comptime;7536 IrInstSrc *is_comptime;
6506 if (ir_should_inline(irb->exec, scope)) {7537 if (ir_should_inline(irb->exec, scope)) {
6507 is_comptime = ir_build_const_bool(irb, scope, node, true);7538 is_comptime = ir_build_const_bool(irb, scope, node, true);
6508 } else {7539 } else {
...@@ -6512,11 +7543,11 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode...@@ -6512,11 +7543,11 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode
6512 AstNode *then_node = node->data.if_bool_expr.then_block;7543 AstNode *then_node = node->data.if_bool_expr.then_block;
6513 AstNode *else_node = node->data.if_bool_expr.else_node;7544 AstNode *else_node = node->data.if_bool_expr.else_node;
65147545
6515 IrBasicBlock *then_block = ir_create_basic_block(irb, scope, "Then");7546 IrBasicBlockSrc *then_block = ir_create_basic_block(irb, scope, "Then");
6516 IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "Else");7547 IrBasicBlockSrc *else_block = ir_create_basic_block(irb, scope, "Else");
6517 IrBasicBlock *endif_block = ir_create_basic_block(irb, scope, "EndIf");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,
6520 then_block, else_block, is_comptime);7551 then_block, else_block, is_comptime);
6521 ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, endif_block,7552 ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, endif_block,
6522 result_loc, is_comptime);7553 result_loc, is_comptime);
...@@ -6524,70 +7555,70 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode...@@ -6524,70 +7555,70 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode
6524 ir_set_cursor_at_end_and_append_block(irb, then_block);7555 ir_set_cursor_at_end_and_append_block(irb, then_block);
65257556
6526 Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, scope, is_comptime);7557 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,
6528 &peer_parent->peers.at(0)->base);7559 &peer_parent->peers.at(0)->base);
6529 if (then_expr_result == irb->codegen->invalid_instruction)7560 if (then_expr_result == irb->codegen->invalid_inst_src)
6530 return irb->codegen->invalid_instruction;7561 return irb->codegen->invalid_inst_src;
6531 IrBasicBlock *after_then_block = irb->current_basic_block;7562 IrBasicBlockSrc *after_then_block = irb->current_basic_block;
6532 if (!instr_is_unreachable(then_expr_result))7563 if (!instr_is_unreachable(then_expr_result))
6533 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));7564 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));
65347565
6535 ir_set_cursor_at_end_and_append_block(irb, else_block);7566 ir_set_cursor_at_end_and_append_block(irb, else_block);
6536 IrInstruction *else_expr_result;7567 IrInstSrc *else_expr_result;
6537 if (else_node) {7568 if (else_node) {
6538 else_expr_result = ir_gen_node_extra(irb, else_node, subexpr_scope, lval, &peer_parent->peers.at(1)->base);7569 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)7570 if (else_expr_result == irb->codegen->invalid_inst_src)
6540 return irb->codegen->invalid_instruction;7571 return irb->codegen->invalid_inst_src;
6541 } else {7572 } else {
6542 else_expr_result = ir_build_const_void(irb, scope, node);7573 else_expr_result = ir_build_const_void(irb, scope, node);
6543 ir_build_end_expr(irb, scope, node, else_expr_result, &peer_parent->peers.at(1)->base);7574 ir_build_end_expr(irb, scope, node, else_expr_result, &peer_parent->peers.at(1)->base);
6544 }7575 }
6545 IrBasicBlock *after_else_block = irb->current_basic_block;7576 IrBasicBlockSrc *after_else_block = irb->current_basic_block;
6546 if (!instr_is_unreachable(else_expr_result))7577 if (!instr_is_unreachable(else_expr_result))
6547 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));7578 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));
65487579
6549 ir_set_cursor_at_end_and_append_block(irb, endif_block);7580 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);
6551 incoming_values[0] = then_expr_result;7582 incoming_values[0] = then_expr_result;
6552 incoming_values[1] = else_expr_result;7583 incoming_values[1] = else_expr_result;
6553 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *");7584 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
6554 incoming_blocks[0] = after_then_block;7585 incoming_blocks[0] = after_then_block;
6555 incoming_blocks[1] = after_else_block;7586 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);
6558 return ir_expr_wrap(irb, scope, phi, result_loc);7589 return ir_expr_wrap(irb, scope, phi, result_loc);
6559}7590}
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) {
6562 assert(node->type == NodeTypePrefixOpExpr);7593 assert(node->type == NodeTypePrefixOpExpr);
6563 AstNode *expr_node = node->data.prefix_op_expr.primary_expr;7594 AstNode *expr_node = node->data.prefix_op_expr.primary_expr;
65647595
6565 IrInstruction *value = ir_gen_node_extra(irb, expr_node, scope, lval, nullptr);7596 IrInstSrc *value = ir_gen_node_extra(irb, expr_node, scope, lval, nullptr);
6566 if (value == irb->codegen->invalid_instruction)7597 if (value == irb->codegen->invalid_inst_src)
6567 return value;7598 return value;
65687599
6569 return ir_build_un_op(irb, scope, node, op_id, value);7600 return ir_build_un_op(irb, scope, node, op_id, value);
6570}7601}
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) {
6573 return ir_gen_prefix_op_id_lval(irb, scope, node, op_id, LValNone);7604 return ir_gen_prefix_op_id_lval(irb, scope, node, op_id, LValNone);
6574}7605}
65757606
6576static IrInstruction *ir_expr_wrap(IrBuilder *irb, Scope *scope, IrInstruction *inst, ResultLoc *result_loc) {7607static IrInstSrc *ir_expr_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *inst, ResultLoc *result_loc) {
6577 if (inst == irb->codegen->invalid_instruction) return inst;7608 if (inst == irb->codegen->invalid_inst_src) return inst;
6578 ir_build_end_expr(irb, scope, inst->source_node, inst, result_loc);7609 ir_build_end_expr(irb, scope, inst->base.source_node, inst, result_loc);
6579 return inst;7610 return inst;
6580}7611}
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,
6583 ResultLoc *result_loc)7614 ResultLoc *result_loc)
6584{7615{
6585 // This logic must be kept in sync with7616 // This logic must be kept in sync with
6586 // [STMT_EXPR_TEST_THING] <--- (search this token)7617 // [STMT_EXPR_TEST_THING] <--- (search this token)
6587 if (value == irb->codegen->invalid_instruction ||7618 if (value == irb->codegen->invalid_inst_src ||
6588 instr_is_unreachable(value) ||7619 instr_is_unreachable(value) ||
6589 value->source_node->type == NodeTypeDefer ||7620 value->base.source_node->type == NodeTypeDefer ||
6590 value->id == IrInstructionIdDeclVarSrc)7621 value->id == IrInstSrcIdDeclVar)
6591 {7622 {
6592 return value;7623 return value;
6593 }7624 }
...@@ -6595,7 +7626,7 @@ static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *...@@ -6595,7 +7626,7 @@ static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *
6595 if (lval == LValPtr) {7626 if (lval == LValPtr) {
6596 // We needed a pointer to a value, but we got a value. So we create7627 // We needed a pointer to a value, but we got a value. So we create
6597 // an instruction which just makes a pointer of it.7628 // 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);
6599 } else if (result_loc != nullptr) {7630 } else if (result_loc != nullptr) {
6600 return ir_expr_wrap(irb, scope, value, result_loc);7631 return ir_expr_wrap(irb, scope, value, result_loc);
6601 } else {7632 } else {
...@@ -6618,7 +7649,7 @@ static PtrLen star_token_to_ptr_len(TokenId token_id) {...@@ -6618,7 +7649,7 @@ static PtrLen star_token_to_ptr_len(TokenId token_id) {
6618 }7649 }
6619}7650}
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) {
6622 assert(node->type == NodeTypePointerType);7653 assert(node->type == NodeTypePointerType);
66237654
6624 PtrLen ptr_len = star_token_to_ptr_len(node->data.pointer_type.star_token->id);7655 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...@@ -6630,26 +7661,26 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode
6630 AstNode *expr_node = node->data.pointer_type.op_expr;7661 AstNode *expr_node = node->data.pointer_type.op_expr;
6631 AstNode *align_expr = node->data.pointer_type.align_expr;7662 AstNode *align_expr = node->data.pointer_type.align_expr;
66327663
6633 IrInstruction *sentinel;7664 IrInstSrc *sentinel;
6634 if (sentinel_expr != nullptr) {7665 if (sentinel_expr != nullptr) {
6635 sentinel = ir_gen_node(irb, sentinel_expr, scope);7666 sentinel = ir_gen_node(irb, sentinel_expr, scope);
6636 if (sentinel == irb->codegen->invalid_instruction)7667 if (sentinel == irb->codegen->invalid_inst_src)
6637 return sentinel;7668 return sentinel;
6638 } else {7669 } else {
6639 sentinel = nullptr;7670 sentinel = nullptr;
6640 }7671 }
66417672
6642 IrInstruction *align_value;7673 IrInstSrc *align_value;
6643 if (align_expr != nullptr) {7674 if (align_expr != nullptr) {
6644 align_value = ir_gen_node(irb, align_expr, scope);7675 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)
6646 return align_value;7677 return align_value;
6647 } else {7678 } else {
6648 align_value = nullptr;7679 align_value = nullptr;
6649 }7680 }
66507681
6651 IrInstruction *child_type = ir_gen_node(irb, expr_node, scope);7682 IrInstSrc *child_type = ir_gen_node(irb, expr_node, scope);
6652 if (child_type == irb->codegen->invalid_instruction)7683 if (child_type == irb->codegen->invalid_inst_src)
6653 return child_type;7684 return child_type;
66547685
6655 uint32_t bit_offset_start = 0;7686 uint32_t bit_offset_start = 0;
...@@ -6659,7 +7690,7 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode...@@ -6659,7 +7690,7 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode
6659 bigint_append_buf(val_buf, node->data.pointer_type.bit_offset_start, 10);7690 bigint_append_buf(val_buf, node->data.pointer_type.bit_offset_start, 10);
6660 exec_add_error_node(irb->codegen, irb->exec, node,7691 exec_add_error_node(irb->codegen, irb->exec, node,
6661 buf_sprintf("value %s too large for u32 bit offset", buf_ptr(val_buf)));7692 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;
6663 }7694 }
6664 bit_offset_start = bigint_as_u32(node->data.pointer_type.bit_offset_start);7695 bit_offset_start = bigint_as_u32(node->data.pointer_type.bit_offset_start);
6665 }7696 }
...@@ -6671,7 +7702,7 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode...@@ -6671,7 +7702,7 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode
6671 bigint_append_buf(val_buf, node->data.pointer_type.host_int_bytes, 10);7702 bigint_append_buf(val_buf, node->data.pointer_type.host_int_bytes, 10);
6672 exec_add_error_node(irb->codegen, irb->exec, node,7703 exec_add_error_node(irb->codegen, irb->exec, node,
6673 buf_sprintf("value %s too large for u32 byte count", buf_ptr(val_buf)));7704 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;
6675 }7706 }
6676 host_int_bytes = bigint_as_u32(node->data.pointer_type.host_int_bytes);7707 host_int_bytes = bigint_as_u32(node->data.pointer_type.host_int_bytes);
6677 }7708 }
...@@ -6679,43 +7710,43 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode...@@ -6679,43 +7710,43 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode
6679 if (host_int_bytes != 0 && bit_offset_start >= host_int_bytes * 8) {7710 if (host_int_bytes != 0 && bit_offset_start >= host_int_bytes * 8) {
6680 exec_add_error_node(irb->codegen, irb->exec, node,7711 exec_add_error_node(irb->codegen, irb->exec, node,
6681 buf_sprintf("bit offset starts after end of host integer"));7712 buf_sprintf("bit offset starts after end of host integer"));
6682 return irb->codegen->invalid_instruction;7713 return irb->codegen->invalid_inst_src;
6683 }7714 }
66847715
6685 return ir_build_ptr_type(irb, scope, node, child_type, is_const, is_volatile,7716 return ir_build_ptr_type(irb, scope, node, child_type, is_const, is_volatile,
6686 ptr_len, sentinel, align_value, bit_offset_start, host_int_bytes, is_allow_zero);7717 ptr_len, sentinel, align_value, bit_offset_start, host_int_bytes, is_allow_zero);
6687}7718}
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,
6690 AstNode *expr_node, LVal lval, ResultLoc *result_loc)7721 AstNode *expr_node, LVal lval, ResultLoc *result_loc)
6691{7722{
6692 IrInstruction *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);7723 IrInstSrc *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
6693 if (err_union_ptr == irb->codegen->invalid_instruction)7724 if (err_union_ptr == irb->codegen->invalid_inst_src)
6694 return irb->codegen->invalid_instruction;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);7727 IrInstSrc *payload_ptr = ir_build_unwrap_err_payload_src(irb, scope, source_node, err_union_ptr, true, false);
6697 if (payload_ptr == irb->codegen->invalid_instruction)7728 if (payload_ptr == irb->codegen->invalid_inst_src)
6698 return irb->codegen->invalid_instruction;7729 return irb->codegen->invalid_inst_src;
66997730
6700 if (lval == LValPtr)7731 if (lval == LValPtr)
6701 return payload_ptr;7732 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);
6704 return ir_expr_wrap(irb, scope, load_ptr, result_loc);7735 return ir_expr_wrap(irb, scope, load_ptr, result_loc);
6705}7736}
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) {
6708 assert(node->type == NodeTypePrefixOpExpr);7739 assert(node->type == NodeTypePrefixOpExpr);
6709 AstNode *expr_node = node->data.prefix_op_expr.primary_expr;7740 AstNode *expr_node = node->data.prefix_op_expr.primary_expr;
67107741
6711 IrInstruction *value = ir_gen_node(irb, expr_node, scope);7742 IrInstSrc *value = ir_gen_node(irb, expr_node, scope);
6712 if (value == irb->codegen->invalid_instruction)7743 if (value == irb->codegen->invalid_inst_src)
6713 return irb->codegen->invalid_instruction;7744 return irb->codegen->invalid_inst_src;
67147745
6715 return ir_build_bool_not(irb, scope, node, value);7746 return ir_build_bool_not(irb, scope, node, value);
6716}7747}
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,
6719 ResultLoc *result_loc)7750 ResultLoc *result_loc)
6720{7751{
6721 assert(node->type == NodeTypePrefixOpExpr);7752 assert(node->type == NodeTypePrefixOpExpr);
...@@ -6743,12 +7774,12 @@ static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNod...@@ -6743,12 +7774,12 @@ static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNod
6743 zig_unreachable();7774 zig_unreachable();
6744}7775}
67457776
6746static IrInstruction *ir_gen_union_init_expr(IrBuilder *irb, Scope *scope, AstNode *source_node,7777static IrInstSrc *ir_gen_union_init_expr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
6747 IrInstruction *union_type, IrInstruction *field_name, AstNode *expr_node,7778 IrInstSrc *union_type, IrInstSrc *field_name, AstNode *expr_node,
6748 LVal lval, ResultLoc *parent_result_loc)7779 LVal lval, ResultLoc *parent_result_loc)
6749{7780{
6750 IrInstruction *container_ptr = ir_build_resolve_result(irb, scope, source_node, parent_result_loc, union_type);7781 IrInstSrc *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,7782 IrInstSrc *field_ptr = ir_build_field_ptr_instruction(irb, scope, source_node, container_ptr,
6752 field_name, true);7783 field_name, true);
67537784
6754 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);7785 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);
...@@ -6757,18 +7788,18 @@ static IrInstruction *ir_gen_union_init_expr(IrBuilder *irb, Scope *scope, AstNo...@@ -6757,18 +7788,18 @@ static IrInstruction *ir_gen_union_init_expr(IrBuilder *irb, Scope *scope, AstNo
6757 ir_ref_instruction(field_ptr, irb->current_basic_block);7788 ir_ref_instruction(field_ptr, irb->current_basic_block);
6758 ir_build_reset_result(irb, scope, expr_node, &result_loc_inst->base);7789 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,
6761 &result_loc_inst->base);7792 &result_loc_inst->base);
6762 if (expr_value == irb->codegen->invalid_instruction)7793 if (expr_value == irb->codegen->invalid_inst_src)
6763 return expr_value;7794 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,
6766 field_name, field_ptr, container_ptr);7797 field_name, field_ptr, container_ptr);
67677798
6768 return ir_lval_wrap(irb, scope, init_union, lval, parent_result_loc);7799 return ir_lval_wrap(irb, scope, init_union, lval, parent_result_loc);
6769}7800}
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,
6772 ResultLoc *parent_result_loc)7803 ResultLoc *parent_result_loc)
6773{7804{
6774 assert(node->type == NodeTypeContainerInitExpr);7805 assert(node->type == NodeTypeContainerInitExpr);
...@@ -6780,42 +7811,42 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A...@@ -6780,42 +7811,42 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
6780 ResultLoc *child_result_loc;7811 ResultLoc *child_result_loc;
6781 AstNode *init_array_type_source_node;7812 AstNode *init_array_type_source_node;
6782 if (container_init_expr->type != nullptr) {7813 if (container_init_expr->type != nullptr) {
6783 IrInstruction *container_type;7814 IrInstSrc *container_type;
6784 if (container_init_expr->type->type == NodeTypeInferredArrayType) {7815 if (container_init_expr->type->type == NodeTypeInferredArrayType) {
6785 if (kind == ContainerInitKindStruct) {7816 if (kind == ContainerInitKindStruct) {
6786 add_node_error(irb->codegen, container_init_expr->type,7817 add_node_error(irb->codegen, container_init_expr->type,
6787 buf_sprintf("initializing array with struct syntax"));7818 buf_sprintf("initializing array with struct syntax"));
6788 return irb->codegen->invalid_instruction;7819 return irb->codegen->invalid_inst_src;
6789 }7820 }
6790 IrInstruction *sentinel;7821 IrInstSrc *sentinel;
6791 if (container_init_expr->type->data.inferred_array_type.sentinel != nullptr) {7822 if (container_init_expr->type->data.inferred_array_type.sentinel != nullptr) {
6792 sentinel = ir_gen_node(irb, container_init_expr->type->data.inferred_array_type.sentinel, scope);7823 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)
6794 return sentinel;7825 return sentinel;
6795 } else {7826 } else {
6796 sentinel = nullptr;7827 sentinel = nullptr;
6797 }7828 }
67987829
6799 IrInstruction *elem_type = ir_gen_node(irb,7830 IrInstSrc *elem_type = ir_gen_node(irb,
6800 container_init_expr->type->data.inferred_array_type.child_type, scope);7831 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)
6802 return elem_type;7833 return elem_type;
6803 size_t item_count = container_init_expr->entries.length;7834 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);
6805 container_type = ir_build_array_type(irb, scope, node, item_count_inst, sentinel, elem_type);7836 container_type = ir_build_array_type(irb, scope, node, item_count_inst, sentinel, elem_type);
6806 } else {7837 } else {
6807 container_type = ir_gen_node(irb, container_init_expr->type, scope);7838 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)
6809 return container_type;7840 return container_type;
6810 }7841 }
68117842
6812 result_loc_cast = ir_build_cast_result_loc(irb, container_type, parent_result_loc);7843 result_loc_cast = ir_build_cast_result_loc(irb, container_type, parent_result_loc);
6813 child_result_loc = &result_loc_cast->base;7844 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;
6815 } else {7846 } else {
6816 child_result_loc = parent_result_loc;7847 child_result_loc = parent_result_loc;
6817 if (parent_result_loc->source_instruction != nullptr) {7848 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;
6819 } else {7850 } else {
6820 init_array_type_source_node = node;7851 init_array_type_source_node = node;
6821 }7852 }
...@@ -6823,11 +7854,11 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A...@@ -6823,11 +7854,11 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
68237854
6824 switch (kind) {7855 switch (kind) {
6825 case ContainerInitKindStruct: {7856 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,
6827 nullptr);7858 nullptr);
68287859
6829 size_t field_count = container_init_expr->entries.length;7860 size_t field_count = container_init_expr->entries.length;
6830 IrInstructionContainerInitFieldsField *fields = allocate<IrInstructionContainerInitFieldsField>(field_count);7861 IrInstSrcContainerInitFieldsField *fields = allocate<IrInstSrcContainerInitFieldsField>(field_count);
6831 for (size_t i = 0; i < field_count; i += 1) {7862 for (size_t i = 0; i < field_count; i += 1) {
6832 AstNode *entry_node = container_init_expr->entries.at(i);7863 AstNode *entry_node = container_init_expr->entries.at(i);
6833 assert(entry_node->type == NodeTypeStructValueField);7864 assert(entry_node->type == NodeTypeStructValueField);
...@@ -6835,7 +7866,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A...@@ -6835,7 +7866,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
6835 Buf *name = entry_node->data.struct_val_field.name;7866 Buf *name = entry_node->data.struct_val_field.name;
6836 AstNode *expr_node = entry_node->data.struct_val_field.expr;7867 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);
6839 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);7870 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);
6840 result_loc_inst->base.id = ResultLocIdInstruction;7871 result_loc_inst->base.id = ResultLocIdInstruction;
6841 result_loc_inst->base.source_instruction = field_ptr;7872 result_loc_inst->base.source_instruction = field_ptr;
...@@ -6843,16 +7874,16 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A...@@ -6843,16 +7874,16 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
6843 ir_ref_instruction(field_ptr, irb->current_basic_block);7874 ir_ref_instruction(field_ptr, irb->current_basic_block);
6844 ir_build_reset_result(irb, scope, expr_node, &result_loc_inst->base);7875 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,
6847 &result_loc_inst->base);7878 &result_loc_inst->base);
6848 if (expr_value == irb->codegen->invalid_instruction)7879 if (expr_value == irb->codegen->invalid_inst_src)
6849 return expr_value;7880 return expr_value;
68507881
6851 fields[i].name = name;7882 fields[i].name = name;
6852 fields[i].source_node = entry_node;7883 fields[i].source_node = entry_node;
6853 fields[i].result_loc = field_ptr;7884 fields[i].result_loc = field_ptr;
6854 }7885 }
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,
6856 fields, container_ptr);7887 fields, container_ptr);
68577888
6858 if (result_loc_cast != nullptr) {7889 if (result_loc_cast != nullptr) {
...@@ -6863,15 +7894,15 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A...@@ -6863,15 +7894,15 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
6863 case ContainerInitKindArray: {7894 case ContainerInitKindArray: {
6864 size_t item_count = container_init_expr->entries.length;7895 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,
6867 nullptr);7898 nullptr);
68687899
6869 IrInstruction **result_locs = allocate<IrInstruction *>(item_count);7900 IrInstSrc **result_locs = allocate<IrInstSrc *>(item_count);
6870 for (size_t i = 0; i < item_count; i += 1) {7901 for (size_t i = 0; i < item_count; i += 1) {
6871 AstNode *expr_node = container_init_expr->entries.at(i);7902 AstNode *expr_node = container_init_expr->entries.at(i);
68727903
6873 IrInstruction *elem_index = ir_build_const_usize(irb, scope, expr_node, i);7904 IrInstSrc *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,7905 IrInstSrc *elem_ptr = ir_build_elem_ptr(irb, scope, expr_node, container_ptr,
6875 elem_index, false, PtrLenSingle, init_array_type_source_node);7906 elem_index, false, PtrLenSingle, init_array_type_source_node);
6876 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);7907 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);
6877 result_loc_inst->base.id = ResultLocIdInstruction;7908 result_loc_inst->base.id = ResultLocIdInstruction;
...@@ -6880,14 +7911,14 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A...@@ -6880,14 +7911,14 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
6880 ir_ref_instruction(elem_ptr, irb->current_basic_block);7911 ir_ref_instruction(elem_ptr, irb->current_basic_block);
6881 ir_build_reset_result(irb, scope, expr_node, &result_loc_inst->base);7912 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,
6884 &result_loc_inst->base);7915 &result_loc_inst->base);
6885 if (expr_value == irb->codegen->invalid_instruction)7916 if (expr_value == irb->codegen->invalid_inst_src)
6886 return expr_value;7917 return expr_value;
68877918
6888 result_locs[i] = elem_ptr;7919 result_locs[i] = elem_ptr;
6889 }7920 }
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,
6891 result_locs, container_ptr, init_array_type_source_node);7922 result_locs, container_ptr, init_array_type_source_node);
6892 if (result_loc_cast != nullptr) {7923 if (result_loc_cast != nullptr) {
6893 result = ir_build_implicit_cast(irb, scope, node, result, result_loc_cast);7924 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...@@ -6898,19 +7929,19 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
6898 zig_unreachable();7929 zig_unreachable();
6899}7930}
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) {
6902 ResultLocVar *result_loc_var = allocate<ResultLocVar>(1);7933 ResultLocVar *result_loc_var = allocate<ResultLocVar>(1);
6903 result_loc_var->base.id = ResultLocIdVar;7934 result_loc_var->base.id = ResultLocIdVar;
6904 result_loc_var->base.source_instruction = alloca;7935 result_loc_var->base.source_instruction = alloca;
6905 result_loc_var->base.allow_write_through_const = true;7936 result_loc_var->base.allow_write_through_const = true;
6906 result_loc_var->var = var;7937 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
6910 return result_loc_var;7941 return result_loc_var;
6911}7942}
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,
6914 ResultLoc *parent_result_loc)7945 ResultLoc *parent_result_loc)
6915{7946{
6916 ResultLocCast *result_loc_cast = allocate<ResultLocCast>(1);7947 ResultLocCast *result_loc_cast = allocate<ResultLocCast>(1);
...@@ -6920,37 +7951,37 @@ static ResultLocCast *ir_build_cast_result_loc(IrBuilder *irb, IrInstruction *de...@@ -6920,37 +7951,37 @@ static ResultLocCast *ir_build_cast_result_loc(IrBuilder *irb, IrInstruction *de
6920 ir_ref_instruction(dest_type, irb->current_basic_block);7951 ir_ref_instruction(dest_type, irb->current_basic_block);
6921 result_loc_cast->parent = parent_result_loc;7952 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
6925 return result_loc_cast;7956 return result_loc_cast;
6926}7957}
69277958
6928static void build_decl_var_and_init(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigVar *var,7959static void build_decl_var_and_init(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, ZigVar *var,
6929 IrInstruction *init, const char *name_hint, IrInstruction *is_comptime)7960 IrInstSrc *init, const char *name_hint, IrInstSrc *is_comptime)
6930{7961{
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);
6932 ResultLocVar *var_result_loc = ir_build_var_result_loc(irb, alloca, var);7963 ResultLocVar *var_result_loc = ir_build_var_result_loc(irb, alloca, var);
6933 ir_build_end_expr(irb, scope, source_node, init, &var_result_loc->base);7964 ir_build_end_expr(irb, scope, source_node, init, &var_result_loc->base);
6934 ir_build_var_decl_src(irb, scope, source_node, var, nullptr, alloca);7965 ir_build_var_decl_src(irb, scope, source_node, var, nullptr, alloca);
6935}7966}
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) {
6938 assert(node->type == NodeTypeVariableDeclaration);7969 assert(node->type == NodeTypeVariableDeclaration);
69397970
6940 AstNodeVariableDeclaration *variable_declaration = &node->data.variable_declaration;7971 AstNodeVariableDeclaration *variable_declaration = &node->data.variable_declaration;
69417972
6942 if (buf_eql_str(variable_declaration->symbol, "_")) {7973 if (buf_eql_str(variable_declaration->symbol, "_")) {
6943 add_node_error(irb->codegen, node, buf_sprintf("`_` is not a declarable symbol"));7974 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;
6945 }7976 }
69467977
6947 // Used for the type expr and the align expr7978 // Used for the type expr and the align expr
6948 Scope *comptime_scope = create_comptime_scope(irb->codegen, node, scope);7979 Scope *comptime_scope = create_comptime_scope(irb->codegen, node, scope);
69497980
6950 IrInstruction *type_instruction;7981 IrInstSrc *type_instruction;
6951 if (variable_declaration->type != nullptr) {7982 if (variable_declaration->type != nullptr) {
6952 type_instruction = ir_gen_node(irb, variable_declaration->type, comptime_scope);7983 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)
6954 return type_instruction;7985 return type_instruction;
6955 } else {7986 } else {
6956 type_instruction = nullptr;7987 type_instruction = nullptr;
...@@ -6961,22 +7992,22 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod...@@ -6961,22 +7992,22 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
6961 bool is_extern = variable_declaration->is_extern;7992 bool is_extern = variable_declaration->is_extern;
69627993
6963 bool is_comptime_scalar = ir_should_inline(irb->exec, scope) || variable_declaration->is_comptime;7994 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);
6965 ZigVar *var = ir_create_var(irb, node, scope, variable_declaration->symbol,7996 ZigVar *var = ir_create_var(irb, node, scope, variable_declaration->symbol,
6966 is_const, is_const, is_shadowable, is_comptime);7997 is_const, is_const, is_shadowable, is_comptime);
6967 // we detect IrInstructionIdDeclVarSrc in gen_block to make sure the next node7998 // we detect IrInstSrcDeclVar in gen_block to make sure the next node
6968 // is inside var->child_scope7999 // is inside var->child_scope
69698000
6970 if (!is_extern && !variable_declaration->expr) {8001 if (!is_extern && !variable_declaration->expr) {
6971 var->var_type = irb->codegen->builtin_types.entry_invalid;8002 var->var_type = irb->codegen->builtin_types.entry_invalid;
6972 add_node_error(irb->codegen, node, buf_sprintf("variables must be initialized"));8003 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;
6974 }8005 }
69758006
6976 IrInstruction *align_value = nullptr;8007 IrInstSrc *align_value = nullptr;
6977 if (variable_declaration->align_expr != nullptr) {8008 if (variable_declaration->align_expr != nullptr) {
6978 align_value = ir_gen_node(irb, variable_declaration->align_expr, comptime_scope);8009 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)
6980 return align_value;8011 return align_value;
6981 }8012 }
69828013
...@@ -6988,7 +8019,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod...@@ -6988,7 +8019,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
6988 // Parser should ensure that this never happens8019 // Parser should ensure that this never happens
6989 assert(variable_declaration->threadlocal_tok == nullptr);8020 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,
6992 buf_ptr(variable_declaration->symbol), is_comptime);8023 buf_ptr(variable_declaration->symbol), is_comptime);
69938024
6994 // Create a result location for the initialization expression.8025 // Create a result location for the initialization expression.
...@@ -7006,19 +8037,19 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod...@@ -7006,19 +8037,19 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
7006 Scope *init_scope = is_comptime_scalar ?8037 Scope *init_scope = is_comptime_scalar ?
7007 create_comptime_scope(irb->codegen, variable_declaration->expr, scope) : scope;8038 create_comptime_scope(irb->codegen, variable_declaration->expr, scope) : scope;
70088039
7009 // Temporarily set the name of the IrExecutable to the VariableDeclaration8040 // Temporarily set the name of the IrExecutableSrc to the VariableDeclaration
7010 // so that the struct or enum from the init expression inherits the name.8041 // so that the struct or enum from the init expression inherits the name.
7011 Buf *old_exec_name = irb->exec->name;8042 Buf *old_exec_name = irb->exec->name;
7012 irb->exec->name = variable_declaration->symbol;8043 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,
7014 LValNone, init_result_loc);8045 LValNone, init_result_loc);
7015 irb->exec->name = old_exec_name;8046 irb->exec->name = old_exec_name;
70168047
7017 if (init_value == irb->codegen->invalid_instruction)8048 if (init_value == irb->codegen->invalid_inst_src)
7018 return irb->codegen->invalid_instruction;8049 return irb->codegen->invalid_inst_src;
70198050
7020 if (result_loc_cast != nullptr) {8051 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,
7022 init_value, result_loc_cast);8053 init_value, result_loc_cast);
7023 ir_build_end_expr(irb, scope, node, implicit_cast, &result_loc_var->base);8054 ir_build_end_expr(irb, scope, node, implicit_cast, &result_loc_var->base);
7024 }8055 }
...@@ -7026,7 +8057,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod...@@ -7026,7 +8057,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
7026 return ir_build_var_decl_src(irb, scope, node, var, align_value, alloca);8057 return ir_build_var_decl_src(irb, scope, node, var, align_value, alloca);
7027}8058}
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,
7030 ResultLoc *result_loc)8061 ResultLoc *result_loc)
7031{8062{
7032 assert(node->type == NodeTypeWhileExpr);8063 assert(node->type == NodeTypeWhileExpr);
...@@ -7034,15 +8065,15 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7034,15 +8065,15 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
7034 AstNode *continue_expr_node = node->data.while_expr.continue_expr;8065 AstNode *continue_expr_node = node->data.while_expr.continue_expr;
7035 AstNode *else_node = node->data.while_expr.else_node;8066 AstNode *else_node = node->data.while_expr.else_node;
70368067
7037 IrBasicBlock *cond_block = ir_create_basic_block(irb, scope, "WhileCond");8068 IrBasicBlockSrc *cond_block = ir_create_basic_block(irb, scope, "WhileCond");
7038 IrBasicBlock *body_block = ir_create_basic_block(irb, scope, "WhileBody");8069 IrBasicBlockSrc *body_block = ir_create_basic_block(irb, scope, "WhileBody");
7039 IrBasicBlock *continue_block = continue_expr_node ?8070 IrBasicBlockSrc *continue_block = continue_expr_node ?
7040 ir_create_basic_block(irb, scope, "WhileContinue") : cond_block;8071 ir_create_basic_block(irb, scope, "WhileContinue") : cond_block;
7041 IrBasicBlock *end_block = ir_create_basic_block(irb, scope, "WhileEnd");8072 IrBasicBlockSrc *end_block = ir_create_basic_block(irb, scope, "WhileEnd");
7042 IrBasicBlock *else_block = else_node ?8073 IrBasicBlockSrc *else_block = else_node ?
7043 ir_create_basic_block(irb, scope, "WhileElse") : end_block;8074 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,
7046 ir_should_inline(irb->exec, scope) || node->data.while_expr.is_inline);8077 ir_should_inline(irb->exec, scope) || node->data.while_expr.is_inline);
7047 ir_build_br(irb, scope, node, cond_block, is_comptime);8078 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...@@ -7063,15 +8094,15 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
7063 } else {8094 } else {
7064 payload_scope = subexpr_scope;8095 payload_scope = subexpr_scope;
7065 }8096 }
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,
7067 LValPtr, nullptr);8098 LValPtr, nullptr);
7068 if (err_val_ptr == irb->codegen->invalid_instruction)8099 if (err_val_ptr == irb->codegen->invalid_inst_src)
7069 return err_val_ptr;8100 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,
7071 true, false);8102 true, false);
7072 IrBasicBlock *after_cond_block = irb->current_basic_block;8103 IrBasicBlockSrc *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));8104 IrInstSrc *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node));
7074 IrInstruction *cond_br_inst;8105 IrInstSrc *cond_br_inst;
7075 if (!instr_is_unreachable(is_err)) {8106 if (!instr_is_unreachable(is_err)) {
7076 cond_br_inst = ir_build_cond_br(irb, scope, node->data.while_expr.condition, is_err,8107 cond_br_inst = ir_build_cond_br(irb, scope, node->data.while_expr.condition, is_err,
7077 else_block, body_block, is_comptime);8108 else_block, body_block, is_comptime);
...@@ -7086,15 +8117,15 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7086,15 +8117,15 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
70868117
7087 ir_set_cursor_at_end_and_append_block(irb, body_block);8118 ir_set_cursor_at_end_and_append_block(irb, body_block);
7088 if (var_symbol) {8119 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,
7090 err_val_ptr, false, false);8121 err_val_ptr, false, false);
7091 IrInstruction *var_ptr = node->data.while_expr.var_is_ptr ?8122 IrInstSrc *var_ptr = node->data.while_expr.var_is_ptr ?
7092 ir_build_ref(irb, payload_scope, symbol_node, payload_ptr, true, false) : payload_ptr;8123 ir_build_ref_src(irb, payload_scope, symbol_node, payload_ptr, true, false) : payload_ptr;
7093 ir_build_var_decl_src(irb, payload_scope, symbol_node, payload_var, nullptr, var_ptr);8124 ir_build_var_decl_src(irb, payload_scope, symbol_node, payload_var, nullptr, var_ptr);
7094 }8125 }
70958126
7096 ZigList<IrInstruction *> incoming_values = {0};8127 ZigList<IrInstSrc *> incoming_values = {0};
7097 ZigList<IrBasicBlock *> incoming_blocks = {0};8128 ZigList<IrBasicBlockSrc *> incoming_blocks = {0};
70988129
7099 ScopeLoop *loop_scope = create_loop_scope(irb->codegen, node, payload_scope);8130 ScopeLoop *loop_scope = create_loop_scope(irb->codegen, node, payload_scope);
7100 loop_scope->break_block = end_block;8131 loop_scope->break_block = end_block;
...@@ -7108,8 +8139,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7108,8 +8139,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
7108 // Note the body block of the loop is not the place that lval and result_loc are used -8139 // Note the body block of the loop is not the place that lval and result_loc are used -
7109 // it's actually in break statements, handled similarly to return statements.8140 // it's actually in break statements, handled similarly to return statements.
7110 // That is why we set those values in loop_scope above and not in this ir_gen_node call.8141 // 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);8142 IrInstSrc *body_result = ir_gen_node(irb, node->data.while_expr.body, &loop_scope->base);
7112 if (body_result == irb->codegen->invalid_instruction)8143 if (body_result == irb->codegen->invalid_inst_src)
7113 return body_result;8144 return body_result;
71148145
7115 if (!instr_is_unreachable(body_result)) {8146 if (!instr_is_unreachable(body_result)) {
...@@ -7119,8 +8150,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7119,8 +8150,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
71198150
7120 if (continue_expr_node) {8151 if (continue_expr_node) {
7121 ir_set_cursor_at_end_and_append_block(irb, continue_block);8152 ir_set_cursor_at_end_and_append_block(irb, continue_block);
7122 IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, payload_scope);8153 IrInstSrc *expr_result = ir_gen_node(irb, continue_expr_node, payload_scope);
7123 if (expr_result == irb->codegen->invalid_instruction)8154 if (expr_result == irb->codegen->invalid_inst_src)
7124 return expr_result;8155 return expr_result;
7125 if (!instr_is_unreachable(expr_result)) {8156 if (!instr_is_unreachable(expr_result)) {
7126 ir_mark_gen(ir_build_check_statement_is_void(irb, payload_scope, continue_expr_node, expr_result));8157 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...@@ -7136,7 +8167,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
7136 ZigVar *err_var = ir_create_var(irb, err_symbol_node, scope, err_symbol,8167 ZigVar *err_var = ir_create_var(irb, err_symbol_node, scope, err_symbol,
7137 true, false, false, is_comptime);8168 true, false, false, is_comptime);
7138 Scope *err_scope = err_var->child_scope;8169 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);
7140 ir_build_var_decl_src(irb, err_scope, symbol_node, err_var, nullptr, err_ptr);8171 ir_build_var_decl_src(irb, err_scope, symbol_node, err_var, nullptr, err_ptr);
71418172
7142 if (peer_parent->peers.length != 0) {8173 if (peer_parent->peers.length != 0) {
...@@ -7144,12 +8175,12 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7144,12 +8175,12 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
7144 }8175 }
7145 ResultLocPeer *peer_result = create_peer_result(peer_parent);8176 ResultLocPeer *peer_result = create_peer_result(peer_parent);
7146 peer_parent->peers.append(peer_result);8177 peer_parent->peers.append(peer_result);
7147 IrInstruction *else_result = ir_gen_node_extra(irb, else_node, err_scope, lval, &peer_result->base);8178 IrInstSrc *else_result = ir_gen_node_extra(irb, else_node, err_scope, lval, &peer_result->base);
7148 if (else_result == irb->codegen->invalid_instruction)8179 if (else_result == irb->codegen->invalid_inst_src)
7149 return else_result;8180 return else_result;
7150 if (!instr_is_unreachable(else_result))8181 if (!instr_is_unreachable(else_result))
7151 ir_mark_gen(ir_build_br(irb, scope, node, end_block, is_comptime));8182 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;
7153 ir_set_cursor_at_end_and_append_block(irb, end_block);8184 ir_set_cursor_at_end_and_append_block(irb, end_block);
7154 if (else_result) {8185 if (else_result) {
7155 incoming_blocks.append(after_else_block);8186 incoming_blocks.append(after_else_block);
...@@ -7162,7 +8193,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7162,7 +8193,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
7162 peer_parent->peers.last()->next_bb = end_block;8193 peer_parent->peers.last()->next_bb = end_block;
7163 }8194 }
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,
7166 incoming_blocks.items, incoming_values.items, peer_parent);8197 incoming_blocks.items, incoming_values.items, peer_parent);
7167 return ir_expr_wrap(irb, scope, phi, result_loc);8198 return ir_expr_wrap(irb, scope, phi, result_loc);
7168 } else if (var_symbol != nullptr) {8199 } else if (var_symbol != nullptr) {
...@@ -7174,15 +8205,15 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7174,15 +8205,15 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
7174 ZigVar *payload_var = ir_create_var(irb, symbol_node, subexpr_scope, var_symbol,8205 ZigVar *payload_var = ir_create_var(irb, symbol_node, subexpr_scope, var_symbol,
7175 true, false, false, is_comptime);8206 true, false, false, is_comptime);
7176 Scope *child_scope = payload_var->child_scope;8207 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,
7178 LValPtr, nullptr);8209 LValPtr, nullptr);
7179 if (maybe_val_ptr == irb->codegen->invalid_instruction)8210 if (maybe_val_ptr == irb->codegen->invalid_inst_src)
7180 return maybe_val_ptr;8211 return maybe_val_ptr;
7181 IrInstruction *maybe_val = ir_build_load_ptr(irb, scope, node->data.while_expr.condition, maybe_val_ptr);8212 IrInstSrc *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);8213 IrInstSrc *is_non_null = ir_build_test_non_null_src(irb, scope, node->data.while_expr.condition, maybe_val);
7183 IrBasicBlock *after_cond_block = irb->current_basic_block;8214 IrBasicBlockSrc *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));8215 IrInstSrc *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node));
7185 IrInstruction *cond_br_inst;8216 IrInstSrc *cond_br_inst;
7186 if (!instr_is_unreachable(is_non_null)) {8217 if (!instr_is_unreachable(is_non_null)) {
7187 cond_br_inst = ir_build_cond_br(irb, scope, node->data.while_expr.condition, is_non_null,8218 cond_br_inst = ir_build_cond_br(irb, scope, node->data.while_expr.condition, is_non_null,
7188 body_block, else_block, is_comptime);8219 body_block, else_block, is_comptime);
...@@ -7196,13 +8227,13 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7196,13 +8227,13 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
7196 is_comptime);8227 is_comptime);
71978228
7198 ir_set_cursor_at_end_and_append_block(irb, body_block);8229 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);8230 IrInstSrc *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 ?8231 IrInstSrc *var_ptr = node->data.while_expr.var_is_ptr ?
7201 ir_build_ref(irb, child_scope, symbol_node, payload_ptr, true, false) : payload_ptr;8232 ir_build_ref_src(irb, child_scope, symbol_node, payload_ptr, true, false) : payload_ptr;
7202 ir_build_var_decl_src(irb, child_scope, symbol_node, payload_var, nullptr, var_ptr);8233 ir_build_var_decl_src(irb, child_scope, symbol_node, payload_var, nullptr, var_ptr);
72038234
7204 ZigList<IrInstruction *> incoming_values = {0};8235 ZigList<IrInstSrc *> incoming_values = {0};
7205 ZigList<IrBasicBlock *> incoming_blocks = {0};8236 ZigList<IrBasicBlockSrc *> incoming_blocks = {0};
72068237
7207 ScopeLoop *loop_scope = create_loop_scope(irb->codegen, node, child_scope);8238 ScopeLoop *loop_scope = create_loop_scope(irb->codegen, node, child_scope);
7208 loop_scope->break_block = end_block;8239 loop_scope->break_block = end_block;
...@@ -7216,8 +8247,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7216,8 +8247,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
7216 // Note the body block of the loop is not the place that lval and result_loc are used -8247 // Note the body block of the loop is not the place that lval and result_loc are used -
7217 // it's actually in break statements, handled similarly to return statements.8248 // it's actually in break statements, handled similarly to return statements.
7218 // That is why we set those values in loop_scope above and not in this ir_gen_node call.8249 // 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);8250 IrInstSrc *body_result = ir_gen_node(irb, node->data.while_expr.body, &loop_scope->base);
7220 if (body_result == irb->codegen->invalid_instruction)8251 if (body_result == irb->codegen->invalid_inst_src)
7221 return body_result;8252 return body_result;
72228253
7223 if (!instr_is_unreachable(body_result)) {8254 if (!instr_is_unreachable(body_result)) {
...@@ -7227,8 +8258,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7227,8 +8258,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
72278258
7228 if (continue_expr_node) {8259 if (continue_expr_node) {
7229 ir_set_cursor_at_end_and_append_block(irb, continue_block);8260 ir_set_cursor_at_end_and_append_block(irb, continue_block);
7230 IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, child_scope);8261 IrInstSrc *expr_result = ir_gen_node(irb, continue_expr_node, child_scope);
7231 if (expr_result == irb->codegen->invalid_instruction)8262 if (expr_result == irb->codegen->invalid_inst_src)
7232 return expr_result;8263 return expr_result;
7233 if (!instr_is_unreachable(expr_result)) {8264 if (!instr_is_unreachable(expr_result)) {
7234 ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, continue_expr_node, expr_result));8265 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...@@ -7236,7 +8267,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
7236 }8267 }
7237 }8268 }
72388269
7239 IrInstruction *else_result = nullptr;8270 IrInstSrc *else_result = nullptr;
7240 if (else_node) {8271 if (else_node) {
7241 ir_set_cursor_at_end_and_append_block(irb, else_block);8272 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...@@ -7246,12 +8277,12 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
7246 ResultLocPeer *peer_result = create_peer_result(peer_parent);8277 ResultLocPeer *peer_result = create_peer_result(peer_parent);
7247 peer_parent->peers.append(peer_result);8278 peer_parent->peers.append(peer_result);
7248 else_result = ir_gen_node_extra(irb, else_node, scope, lval, &peer_result->base);8279 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)
7250 return else_result;8281 return else_result;
7251 if (!instr_is_unreachable(else_result))8282 if (!instr_is_unreachable(else_result))
7252 ir_mark_gen(ir_build_br(irb, scope, node, end_block, is_comptime));8283 ir_mark_gen(ir_build_br(irb, scope, node, end_block, is_comptime));
7253 }8284 }
7254 IrBasicBlock *after_else_block = irb->current_basic_block;8285 IrBasicBlockSrc *after_else_block = irb->current_basic_block;
7255 ir_set_cursor_at_end_and_append_block(irb, end_block);8286 ir_set_cursor_at_end_and_append_block(irb, end_block);
7256 if (else_result) {8287 if (else_result) {
7257 incoming_blocks.append(after_else_block);8288 incoming_blocks.append(after_else_block);
...@@ -7264,17 +8295,17 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7264,17 +8295,17 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
7264 peer_parent->peers.last()->next_bb = end_block;8295 peer_parent->peers.last()->next_bb = end_block;
7265 }8296 }
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,
7268 incoming_blocks.items, incoming_values.items, peer_parent);8299 incoming_blocks.items, incoming_values.items, peer_parent);
7269 return ir_expr_wrap(irb, scope, phi, result_loc);8300 return ir_expr_wrap(irb, scope, phi, result_loc);
7270 } else {8301 } else {
7271 ir_set_cursor_at_end_and_append_block(irb, cond_block);8302 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);8303 IrInstSrc *cond_val = ir_gen_node(irb, node->data.while_expr.condition, scope);
7273 if (cond_val == irb->codegen->invalid_instruction)8304 if (cond_val == irb->codegen->invalid_inst_src)
7274 return cond_val;8305 return cond_val;
7275 IrBasicBlock *after_cond_block = irb->current_basic_block;8306 IrBasicBlockSrc *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));8307 IrInstSrc *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node));
7277 IrInstruction *cond_br_inst;8308 IrInstSrc *cond_br_inst;
7278 if (!instr_is_unreachable(cond_val)) {8309 if (!instr_is_unreachable(cond_val)) {
7279 cond_br_inst = ir_build_cond_br(irb, scope, node->data.while_expr.condition, cond_val,8310 cond_br_inst = ir_build_cond_br(irb, scope, node->data.while_expr.condition, cond_val,
7280 body_block, else_block, is_comptime);8311 body_block, else_block, is_comptime);
...@@ -7288,8 +8319,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7288,8 +8319,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
7288 is_comptime);8319 is_comptime);
7289 ir_set_cursor_at_end_and_append_block(irb, body_block);8320 ir_set_cursor_at_end_and_append_block(irb, body_block);
72908321
7291 ZigList<IrInstruction *> incoming_values = {0};8322 ZigList<IrInstSrc *> incoming_values = {0};
7292 ZigList<IrBasicBlock *> incoming_blocks = {0};8323 ZigList<IrBasicBlockSrc *> incoming_blocks = {0};
72938324
7294 Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, scope, is_comptime);8325 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...@@ -7305,8 +8336,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
7305 // Note the body block of the loop is not the place that lval and result_loc are used -8336 // Note the body block of the loop is not the place that lval and result_loc are used -
7306 // it's actually in break statements, handled similarly to return statements.8337 // it's actually in break statements, handled similarly to return statements.
7307 // That is why we set those values in loop_scope above and not in this ir_gen_node call.8338 // 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);8339 IrInstSrc *body_result = ir_gen_node(irb, node->data.while_expr.body, &loop_scope->base);
7309 if (body_result == irb->codegen->invalid_instruction)8340 if (body_result == irb->codegen->invalid_inst_src)
7310 return body_result;8341 return body_result;
73118342
7312 if (!instr_is_unreachable(body_result)) {8343 if (!instr_is_unreachable(body_result)) {
...@@ -7316,8 +8347,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7316,8 +8347,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
73168347
7317 if (continue_expr_node) {8348 if (continue_expr_node) {
7318 ir_set_cursor_at_end_and_append_block(irb, continue_block);8349 ir_set_cursor_at_end_and_append_block(irb, continue_block);
7319 IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, subexpr_scope);8350 IrInstSrc *expr_result = ir_gen_node(irb, continue_expr_node, subexpr_scope);
7320 if (expr_result == irb->codegen->invalid_instruction)8351 if (expr_result == irb->codegen->invalid_inst_src)
7321 return expr_result;8352 return expr_result;
7322 if (!instr_is_unreachable(expr_result)) {8353 if (!instr_is_unreachable(expr_result)) {
7323 ir_mark_gen(ir_build_check_statement_is_void(irb, scope, continue_expr_node, expr_result));8354 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...@@ -7325,7 +8356,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
7325 }8356 }
7326 }8357 }
73278358
7328 IrInstruction *else_result = nullptr;8359 IrInstSrc *else_result = nullptr;
7329 if (else_node) {8360 if (else_node) {
7330 ir_set_cursor_at_end_and_append_block(irb, else_block);8361 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...@@ -7336,12 +8367,12 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
7336 peer_parent->peers.append(peer_result);8367 peer_parent->peers.append(peer_result);
73378368
7338 else_result = ir_gen_node_extra(irb, else_node, subexpr_scope, lval, &peer_result->base);8369 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)
7340 return else_result;8371 return else_result;
7341 if (!instr_is_unreachable(else_result))8372 if (!instr_is_unreachable(else_result))
7342 ir_mark_gen(ir_build_br(irb, scope, node, end_block, is_comptime));8373 ir_mark_gen(ir_build_br(irb, scope, node, end_block, is_comptime));
7343 }8374 }
7344 IrBasicBlock *after_else_block = irb->current_basic_block;8375 IrBasicBlockSrc *after_else_block = irb->current_basic_block;
7345 ir_set_cursor_at_end_and_append_block(irb, end_block);8376 ir_set_cursor_at_end_and_append_block(irb, end_block);
7346 if (else_result) {8377 if (else_result) {
7347 incoming_blocks.append(after_else_block);8378 incoming_blocks.append(after_else_block);
...@@ -7354,13 +8385,13 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7354,13 +8385,13 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
7354 peer_parent->peers.last()->next_bb = end_block;8385 peer_parent->peers.last()->next_bb = end_block;
7355 }8386 }
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,
7358 incoming_blocks.items, incoming_values.items, peer_parent);8389 incoming_blocks.items, incoming_values.items, peer_parent);
7359 return ir_expr_wrap(irb, scope, phi, result_loc);8390 return ir_expr_wrap(irb, scope, phi, result_loc);
7360 }8391 }
7361}8392}
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,
7364 ResultLoc *result_loc)8395 ResultLoc *result_loc)
7365{8396{
7366 assert(node->type == NodeTypeForExpr);8397 assert(node->type == NodeTypeForExpr);
...@@ -7373,17 +8404,17 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -7373,17 +8404,17 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
73738404
7374 if (!elem_node) {8405 if (!elem_node) {
7375 add_node_error(irb->codegen, node, buf_sprintf("for loop expression missing element parameter"));8406 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;
7377 }8408 }
7378 assert(elem_node->type == NodeTypeSymbol);8409 assert(elem_node->type == NodeTypeSymbol);
73798410
7380 ScopeExpr *spill_scope = create_expr_scope(irb->codegen, node, parent_scope);8411 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);8413 IrInstSrc *array_val_ptr = ir_gen_node_extra(irb, array_node, &spill_scope->base, LValPtr, nullptr);
7383 if (array_val_ptr == irb->codegen->invalid_instruction)8414 if (array_val_ptr == irb->codegen->invalid_inst_src)
7384 return array_val_ptr;8415 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,
7387 ir_should_inline(irb->exec, parent_scope) || node->data.for_expr.is_inline);8418 ir_should_inline(irb->exec, parent_scope) || node->data.for_expr.is_inline);
73888419
7389 AstNode *index_var_source_node;8420 AstNode *index_var_source_node;
...@@ -7400,50 +8431,50 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -7400,50 +8431,50 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
7400 index_var_name = "i";8431 index_var_name = "i";
7401 }8432 }
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);
7404 build_decl_var_and_init(irb, parent_scope, index_var_source_node, index_var, zero, index_var_name, is_comptime);8435 build_decl_var_and_init(irb, parent_scope, index_var_source_node, index_var, zero, index_var_name, is_comptime);
7405 parent_scope = index_var->child_scope;8436 parent_scope = index_var->child_scope;
74068437
7407 IrInstruction *one = ir_build_const_usize(irb, parent_scope, node, 1);8438 IrInstSrc *one = ir_build_const_usize(irb, parent_scope, node, 1);
7408 IrInstruction *index_ptr = ir_build_var_ptr(irb, parent_scope, node, index_var);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");8442 IrBasicBlockSrc *cond_block = ir_create_basic_block(irb, parent_scope, "ForCond");
7412 IrBasicBlock *body_block = ir_create_basic_block(irb, parent_scope, "ForBody");8443 IrBasicBlockSrc *body_block = ir_create_basic_block(irb, parent_scope, "ForBody");
7413 IrBasicBlock *end_block = ir_create_basic_block(irb, parent_scope, "ForEnd");8444 IrBasicBlockSrc *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;8445 IrBasicBlockSrc *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");8446 IrBasicBlockSrc *continue_block = ir_create_basic_block(irb, parent_scope, "ForContinue");
74168447
7417 Buf *len_field_name = buf_create_from_str("len");8448 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);8449 IrInstSrc *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);8450 IrInstSrc *len_val = ir_build_load_ptr(irb, &spill_scope->base, node, len_ref);
7420 ir_build_br(irb, parent_scope, node, cond_block, is_comptime);8451 ir_build_br(irb, parent_scope, node, cond_block, is_comptime);
74218452
7422 ir_set_cursor_at_end_and_append_block(irb, cond_block);8453 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);8454 IrInstSrc *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);8455 IrInstSrc *cond = ir_build_bin_op(irb, parent_scope, node, IrBinOpCmpLessThan, index_val, len_val, false);
7425 IrBasicBlock *after_cond_block = irb->current_basic_block;8456 IrBasicBlockSrc *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));8457 IrInstSrc *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,8458 IrInstSrc *cond_br_inst = ir_mark_gen(ir_build_cond_br(irb, parent_scope, node, cond,
7428 body_block, else_block, is_comptime));8459 body_block, else_block, is_comptime));
74298460
7430 ResultLocPeerParent *peer_parent = ir_build_result_peers(irb, cond_br_inst, end_block, result_loc, is_comptime);8461 ResultLocPeerParent *peer_parent = ir_build_result_peers(irb, cond_br_inst, end_block, result_loc, is_comptime);
74318462
7432 ir_set_cursor_at_end_and_append_block(irb, body_block);8463 ir_set_cursor_at_end_and_append_block(irb, body_block);
7433 Scope *elem_ptr_scope = node->data.for_expr.elem_is_ptr ? parent_scope : &spill_scope->base;8464 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,
7435 PtrLenSingle, nullptr);8466 PtrLenSingle, nullptr);
7436 // TODO make it an error to write to element variable or i variable.8467 // TODO make it an error to write to element variable or i variable.
7437 Buf *elem_var_name = elem_node->data.symbol_expr.symbol;8468 Buf *elem_var_name = elem_node->data.symbol_expr.symbol;
7438 ZigVar *elem_var = ir_create_var(irb, elem_node, parent_scope, elem_var_name, true, false, false, is_comptime);8469 ZigVar *elem_var = ir_create_var(irb, elem_node, parent_scope, elem_var_name, true, false, false, is_comptime);
7439 Scope *child_scope = elem_var->child_scope;8470 Scope *child_scope = elem_var->child_scope;
74408471
7441 IrInstruction *var_ptr = node->data.for_expr.elem_is_ptr ?8472 IrInstSrc *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;8473 ir_build_ref_src(irb, &spill_scope->base, elem_node, elem_ptr, true, false) : elem_ptr;
7443 ir_build_var_decl_src(irb, parent_scope, elem_node, elem_var, nullptr, var_ptr);8474 ir_build_var_decl_src(irb, parent_scope, elem_node, elem_var, nullptr, var_ptr);
74448475
7445 ZigList<IrInstruction *> incoming_values = {0};8476 ZigList<IrInstSrc *> incoming_values = {0};
7446 ZigList<IrBasicBlock *> incoming_blocks = {0};8477 ZigList<IrBasicBlockSrc *> incoming_blocks = {0};
7447 ScopeLoop *loop_scope = create_loop_scope(irb->codegen, node, child_scope);8478 ScopeLoop *loop_scope = create_loop_scope(irb->codegen, node, child_scope);
7448 loop_scope->break_block = end_block;8479 loop_scope->break_block = end_block;
7449 loop_scope->continue_block = continue_block;8480 loop_scope->continue_block = continue_block;
...@@ -7457,9 +8488,9 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -7457,9 +8488,9 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
7457 // Note the body block of the loop is not the place that lval and result_loc are used -8488 // Note the body block of the loop is not the place that lval and result_loc are used -
7458 // it's actually in break statements, handled similarly to return statements.8489 // it's actually in break statements, handled similarly to return statements.
7459 // That is why we set those values in loop_scope above and not in this ir_gen_node call.8490 // 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);8491 IrInstSrc *body_result = ir_gen_node(irb, body_node, &loop_scope->base);
7461 if (body_result == irb->codegen->invalid_instruction)8492 if (body_result == irb->codegen->invalid_inst_src)
7462 return irb->codegen->invalid_instruction;8493 return irb->codegen->invalid_inst_src;
74638494
7464 if (!instr_is_unreachable(body_result)) {8495 if (!instr_is_unreachable(body_result)) {
7465 ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, node->data.for_expr.body, body_result));8496 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...@@ -7467,11 +8498,11 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
7467 }8498 }
74688499
7469 ir_set_cursor_at_end_and_append_block(irb, continue_block);8500 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);
7471 ir_build_store_ptr(irb, child_scope, node, index_ptr, new_index_val)->allow_write_through_const = true;8502 ir_build_store_ptr(irb, child_scope, node, index_ptr, new_index_val)->allow_write_through_const = true;
7472 ir_build_br(irb, child_scope, node, cond_block, is_comptime);8503 ir_build_br(irb, child_scope, node, cond_block, is_comptime);
74738504
7474 IrInstruction *else_result = nullptr;8505 IrInstSrc *else_result = nullptr;
7475 if (else_node) {8506 if (else_node) {
7476 ir_set_cursor_at_end_and_append_block(irb, else_block);8507 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...@@ -7481,12 +8512,12 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
7481 ResultLocPeer *peer_result = create_peer_result(peer_parent);8512 ResultLocPeer *peer_result = create_peer_result(peer_parent);
7482 peer_parent->peers.append(peer_result);8513 peer_parent->peers.append(peer_result);
7483 else_result = ir_gen_node_extra(irb, else_node, parent_scope, LValNone, &peer_result->base);8514 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)
7485 return else_result;8516 return else_result;
7486 if (!instr_is_unreachable(else_result))8517 if (!instr_is_unreachable(else_result))
7487 ir_mark_gen(ir_build_br(irb, parent_scope, node, end_block, is_comptime));8518 ir_mark_gen(ir_build_br(irb, parent_scope, node, end_block, is_comptime));
7488 }8519 }
7489 IrBasicBlock *after_else_block = irb->current_basic_block;8520 IrBasicBlockSrc *after_else_block = irb->current_basic_block;
7490 ir_set_cursor_at_end_and_append_block(irb, end_block);8521 ir_set_cursor_at_end_and_append_block(irb, end_block);
74918522
7492 if (else_result) {8523 if (else_result) {
...@@ -7500,29 +8531,29 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -7500,29 +8531,29 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
7500 peer_parent->peers.last()->next_bb = end_block;8531 peer_parent->peers.last()->next_bb = end_block;
7501 }8532 }
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,
7504 incoming_blocks.items, incoming_values.items, peer_parent);8535 incoming_blocks.items, incoming_values.items, peer_parent);
7505 return ir_lval_wrap(irb, parent_scope, phi, lval, result_loc);8536 return ir_lval_wrap(irb, parent_scope, phi, lval, result_loc);
7506}8537}
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) {
7509 assert(node->type == NodeTypeBoolLiteral);8540 assert(node->type == NodeTypeBoolLiteral);
7510 return ir_build_const_bool(irb, scope, node, node->data.bool_literal.value);8541 return ir_build_const_bool(irb, scope, node, node->data.bool_literal.value);
7511}8542}
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) {
7514 assert(node->type == NodeTypeEnumLiteral);8545 assert(node->type == NodeTypeEnumLiteral);
7515 Buf *name = &node->data.enum_literal.identifier->data.str_lit.str;8546 Buf *name = &node->data.enum_literal.identifier->data.str_lit.str;
7516 return ir_build_const_enum_literal(irb, scope, node, name);8547 return ir_build_const_enum_literal(irb, scope, node, name);
7517}8548}
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) {
7520 assert(node->type == NodeTypeStringLiteral);8551 assert(node->type == NodeTypeStringLiteral);
75218552
7522 return ir_build_const_str_lit(irb, scope, node, node->data.string_literal.buf);8553 return ir_build_const_str_lit(irb, scope, node, node->data.string_literal.buf);
7523}8554}
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) {
7526 assert(node->type == NodeTypeArrayType);8557 assert(node->type == NodeTypeArrayType);
75278558
7528 AstNode *size_node = node->data.array_type.size;8559 AstNode *size_node = node->data.array_type.size;
...@@ -7535,10 +8566,10 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7535,10 +8566,10 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *n
75358566
7536 Scope *comptime_scope = create_comptime_scope(irb->codegen, node, scope);8567 Scope *comptime_scope = create_comptime_scope(irb->codegen, node, scope);
75378568
7538 IrInstruction *sentinel;8569 IrInstSrc *sentinel;
7539 if (sentinel_expr != nullptr) {8570 if (sentinel_expr != nullptr) {
7540 sentinel = ir_gen_node(irb, sentinel_expr, comptime_scope);8571 sentinel = ir_gen_node(irb, sentinel_expr, comptime_scope);
7541 if (sentinel == irb->codegen->invalid_instruction)8572 if (sentinel == irb->codegen->invalid_inst_src)
7542 return sentinel;8573 return sentinel;
7543 } else {8574 } else {
7544 sentinel = nullptr;8575 sentinel = nullptr;
...@@ -7547,42 +8578,42 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7547,42 +8578,42 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *n
7547 if (size_node) {8578 if (size_node) {
7548 if (is_const) {8579 if (is_const) {
7549 add_node_error(irb->codegen, node, buf_create_from_str("const qualifier invalid on array type"));8580 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;
7551 }8582 }
7552 if (is_volatile) {8583 if (is_volatile) {
7553 add_node_error(irb->codegen, node, buf_create_from_str("volatile qualifier invalid on array type"));8584 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;
7555 }8586 }
7556 if (is_allow_zero) {8587 if (is_allow_zero) {
7557 add_node_error(irb->codegen, node, buf_create_from_str("allowzero qualifier invalid on array type"));8588 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;
7559 }8590 }
7560 if (align_expr != nullptr) {8591 if (align_expr != nullptr) {
7561 add_node_error(irb->codegen, node, buf_create_from_str("align qualifier invalid on array type"));8592 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;
7563 }8594 }
75648595
7565 IrInstruction *size_value = ir_gen_node(irb, size_node, comptime_scope);8596 IrInstSrc *size_value = ir_gen_node(irb, size_node, comptime_scope);
7566 if (size_value == irb->codegen->invalid_instruction)8597 if (size_value == irb->codegen->invalid_inst_src)
7567 return size_value;8598 return size_value;
75688599
7569 IrInstruction *child_type = ir_gen_node(irb, child_type_node, comptime_scope);8600 IrInstSrc *child_type = ir_gen_node(irb, child_type_node, comptime_scope);
7570 if (child_type == irb->codegen->invalid_instruction)8601 if (child_type == irb->codegen->invalid_inst_src)
7571 return child_type;8602 return child_type;
75728603
7573 return ir_build_array_type(irb, scope, node, size_value, sentinel, child_type);8604 return ir_build_array_type(irb, scope, node, size_value, sentinel, child_type);
7574 } else {8605 } else {
7575 IrInstruction *align_value;8606 IrInstSrc *align_value;
7576 if (align_expr != nullptr) {8607 if (align_expr != nullptr) {
7577 align_value = ir_gen_node(irb, align_expr, comptime_scope);8608 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)
7579 return align_value;8610 return align_value;
7580 } else {8611 } else {
7581 align_value = nullptr;8612 align_value = nullptr;
7582 }8613 }
75838614
7584 IrInstruction *child_type = ir_gen_node(irb, child_type_node, comptime_scope);8615 IrInstSrc *child_type = ir_gen_node(irb, child_type_node, comptime_scope);
7585 if (child_type == irb->codegen->invalid_instruction)8616 if (child_type == irb->codegen->invalid_inst_src)
7586 return child_type;8617 return child_type;
75878618
7588 return ir_build_slice_type(irb, scope, node, child_type, is_const, is_volatile, sentinel,8619 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...@@ -7590,15 +8621,15 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *n
7590 }8621 }
7591}8622}
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) {
7594 assert(node->type == NodeTypeAnyFrameType);8625 assert(node->type == NodeTypeAnyFrameType);
75958626
7596 AstNode *payload_type_node = node->data.anyframe_type.payload_type;8627 AstNode *payload_type_node = node->data.anyframe_type.payload_type;
7597 IrInstruction *payload_type_value = nullptr;8628 IrInstSrc *payload_type_value = nullptr;
75988629
7599 if (payload_type_node != nullptr) {8630 if (payload_type_node != nullptr) {
7600 payload_type_value = ir_gen_node(irb, payload_type_node, scope);8631 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)
7602 return payload_type_value;8633 return payload_type_value;
76038634
7604 }8635 }
...@@ -7606,7 +8637,7 @@ static IrInstruction *ir_gen_anyframe_type(IrBuilder *irb, Scope *scope, AstNode...@@ -7606,7 +8637,7 @@ static IrInstruction *ir_gen_anyframe_type(IrBuilder *irb, Scope *scope, AstNode
7606 return ir_build_anyframe_type(irb, scope, node, payload_type_value);8637 return ir_build_anyframe_type(irb, scope, node, payload_type_value);
7607}8638}
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) {
7610 assert(node->type == NodeTypeUndefinedLiteral);8641 assert(node->type == NodeTypeUndefinedLiteral);
7611 return ir_build_const_undefined(irb, scope, node);8642 return ir_build_const_undefined(irb, scope, node);
7612}8643}
...@@ -7723,13 +8754,13 @@ static size_t find_asm_index(CodeGen *g, AstNode *node, AsmToken *tok, Buf *src_...@@ -7723,13 +8754,13 @@ static size_t find_asm_index(CodeGen *g, AstNode *node, AsmToken *tok, Buf *src_
7723 return SIZE_MAX;8754 return SIZE_MAX;
7724}8755}
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) {
7727 assert(node->type == NodeTypeAsmExpr);8758 assert(node->type == NodeTypeAsmExpr);
7728 AstNodeAsmExpr *asm_expr = &node->data.asm_expr;8759 AstNodeAsmExpr *asm_expr = &node->data.asm_expr;
77298760
7730 IrInstruction *asm_template = ir_gen_node(irb, asm_expr->asm_template, scope);8761 IrInstSrc *asm_template = ir_gen_node(irb, asm_expr->asm_template, scope);
7731 if (asm_template == irb->codegen->invalid_instruction)8762 if (asm_template == irb->codegen->invalid_inst_src)
7732 return irb->codegen->invalid_instruction;8763 return irb->codegen->invalid_inst_src;
77338764
7734 bool is_volatile = asm_expr->volatile_token != nullptr;8765 bool is_volatile = asm_expr->volatile_token != nullptr;
7735 bool in_fn_scope = (scope_fn_entry(scope) != nullptr);8766 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...@@ -7738,7 +8769,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod
7738 if (is_volatile) {8769 if (is_volatile) {
7739 add_token_error(irb->codegen, node->owner, asm_expr->volatile_token,8770 add_token_error(irb->codegen, node->owner, asm_expr->volatile_token,
7740 buf_sprintf("volatile is meaningless on global assembly"));8771 buf_sprintf("volatile is meaningless on global assembly"));
7741 return irb->codegen->invalid_instruction;8772 return irb->codegen->invalid_inst_src;
7742 }8773 }
77438774
7744 if (asm_expr->output_list.length != 0 || asm_expr->input_list.length != 0 ||8775 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...@@ -7746,34 +8777,34 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod
7746 {8777 {
7747 add_node_error(irb->codegen, node,8778 add_node_error(irb->codegen, node,
7748 buf_sprintf("global assembly cannot have inputs, outputs, or clobbers"));8779 buf_sprintf("global assembly cannot have inputs, outputs, or clobbers"));
7749 return irb->codegen->invalid_instruction;8780 return irb->codegen->invalid_inst_src;
7750 }8781 }
77518782
7752 return ir_build_asm_src(irb, scope, node, asm_template, nullptr, nullptr,8783 return ir_build_asm_src(irb, scope, node, asm_template, nullptr, nullptr,
7753 nullptr, 0, is_volatile, true);8784 nullptr, 0, is_volatile, true);
7754 }8785 }
77558786
7756 IrInstruction **input_list = allocate<IrInstruction *>(asm_expr->input_list.length);8787 IrInstSrc **input_list = allocate<IrInstSrc *>(asm_expr->input_list.length);
7757 IrInstruction **output_types = allocate<IrInstruction *>(asm_expr->output_list.length);8788 IrInstSrc **output_types = allocate<IrInstSrc *>(asm_expr->output_list.length);
7758 ZigVar **output_vars = allocate<ZigVar *>(asm_expr->output_list.length);8789 ZigVar **output_vars = allocate<ZigVar *>(asm_expr->output_list.length);
7759 size_t return_count = 0;8790 size_t return_count = 0;
7760 if (!is_volatile && asm_expr->output_list.length == 0) {8791 if (!is_volatile && asm_expr->output_list.length == 0) {
7761 add_node_error(irb->codegen, node,8792 add_node_error(irb->codegen, node,
7762 buf_sprintf("assembly expression with no output must be marked volatile"));8793 buf_sprintf("assembly expression with no output must be marked volatile"));
7763 return irb->codegen->invalid_instruction;8794 return irb->codegen->invalid_inst_src;
7764 }8795 }
7765 for (size_t i = 0; i < asm_expr->output_list.length; i += 1) {8796 for (size_t i = 0; i < asm_expr->output_list.length; i += 1) {
7766 AsmOutput *asm_output = asm_expr->output_list.at(i);8797 AsmOutput *asm_output = asm_expr->output_list.at(i);
7767 if (asm_output->return_type) {8798 if (asm_output->return_type) {
7768 return_count += 1;8799 return_count += 1;
77698800
7770 IrInstruction *return_type = ir_gen_node(irb, asm_output->return_type, scope);8801 IrInstSrc *return_type = ir_gen_node(irb, asm_output->return_type, scope);
7771 if (return_type == irb->codegen->invalid_instruction)8802 if (return_type == irb->codegen->invalid_inst_src)
7772 return irb->codegen->invalid_instruction;8803 return irb->codegen->invalid_inst_src;
7773 if (return_count > 1) {8804 if (return_count > 1) {
7774 add_node_error(irb->codegen, node,8805 add_node_error(irb->codegen, node,
7775 buf_sprintf("inline assembly allows up to one output value"));8806 buf_sprintf("inline assembly allows up to one output value"));
7776 return irb->codegen->invalid_instruction;8807 return irb->codegen->invalid_inst_src;
7777 }8808 }
7778 output_types[i] = return_type;8809 output_types[i] = return_type;
7779 } else {8810 } else {
...@@ -7786,7 +8817,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod...@@ -7786,7 +8817,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod
7786 } else {8817 } else {
7787 add_node_error(irb->codegen, node,8818 add_node_error(irb->codegen, node,
7788 buf_sprintf("use of undeclared identifier '%s'", buf_ptr(variable_name)));8819 buf_sprintf("use of undeclared identifier '%s'", buf_ptr(variable_name)));
7789 return irb->codegen->invalid_instruction;8820 return irb->codegen->invalid_inst_src;
7790 }8821 }
7791 }8822 }
77928823
...@@ -7796,14 +8827,14 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod...@@ -7796,14 +8827,14 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod
7796 buf_sprintf("invalid modifier starting output constraint for '%s': '%c', only '=' is supported."8827 buf_sprintf("invalid modifier starting output constraint for '%s': '%c', only '=' is supported."
7797 " Compiler TODO: see https://github.com/ziglang/zig/issues/215",8828 " Compiler TODO: see https://github.com/ziglang/zig/issues/215",
7798 buf_ptr(asm_output->asm_symbolic_name), modifier));8829 buf_ptr(asm_output->asm_symbolic_name), modifier));
7799 return irb->codegen->invalid_instruction;8830 return irb->codegen->invalid_inst_src;
7800 }8831 }
7801 }8832 }
7802 for (size_t i = 0; i < asm_expr->input_list.length; i += 1) {8833 for (size_t i = 0; i < asm_expr->input_list.length; i += 1) {
7803 AsmInput *asm_input = asm_expr->input_list.at(i);8834 AsmInput *asm_input = asm_expr->input_list.at(i);
7804 IrInstruction *input_value = ir_gen_node(irb, asm_input->expr, scope);8835 IrInstSrc *input_value = ir_gen_node(irb, asm_input->expr, scope);
7805 if (input_value == irb->codegen->invalid_instruction)8836 if (input_value == irb->codegen->invalid_inst_src)
7806 return irb->codegen->invalid_instruction;8837 return irb->codegen->invalid_inst_src;
78078838
7808 input_list[i] = input_value;8839 input_list[i] = input_value;
7809 }8840 }
...@@ -7812,7 +8843,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod...@@ -7812,7 +8843,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod
7812 output_vars, return_count, is_volatile, false);8843 output_vars, return_count, is_volatile, false);
7813}8844}
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,
7816 ResultLoc *result_loc)8847 ResultLoc *result_loc)
7817{8848{
7818 assert(node->type == NodeTypeIfOptional);8849 assert(node->type == NodeTypeIfOptional);
...@@ -7823,24 +8854,24 @@ static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstN...@@ -7823,24 +8854,24 @@ static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstN
7823 AstNode *else_node = node->data.test_expr.else_node;8854 AstNode *else_node = node->data.test_expr.else_node;
7824 bool var_is_ptr = node->data.test_expr.var_is_ptr;8855 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);8857 IrInstSrc *maybe_val_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
7827 if (maybe_val_ptr == irb->codegen->invalid_instruction)8858 if (maybe_val_ptr == irb->codegen->invalid_inst_src)
7828 return maybe_val_ptr;8859 return maybe_val_ptr;
78298860
7830 IrInstruction *maybe_val = ir_build_load_ptr(irb, scope, node, maybe_val_ptr);8861 IrInstSrc *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);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");8864 IrBasicBlockSrc *then_block = ir_create_basic_block(irb, scope, "OptionalThen");
7834 IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "OptionalElse");8865 IrBasicBlockSrc *else_block = ir_create_basic_block(irb, scope, "OptionalElse");
7835 IrBasicBlock *endif_block = ir_create_basic_block(irb, scope, "OptionalEndIf");8866 IrBasicBlockSrc *endif_block = ir_create_basic_block(irb, scope, "OptionalEndIf");
78368867
7837 IrInstruction *is_comptime;8868 IrInstSrc *is_comptime;
7838 if (ir_should_inline(irb->exec, scope)) {8869 if (ir_should_inline(irb->exec, scope)) {
7839 is_comptime = ir_build_const_bool(irb, scope, node, true);8870 is_comptime = ir_build_const_bool(irb, scope, node, true);
7840 } else {8871 } else {
7841 is_comptime = ir_build_test_comptime(irb, scope, node, is_non_null);8872 is_comptime = ir_build_test_comptime(irb, scope, node, is_non_null);
7842 }8873 }
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,
7844 then_block, else_block, is_comptime);8875 then_block, else_block, is_comptime);
78458876
7846 ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, endif_block,8877 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...@@ -7856,48 +8887,48 @@ static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstN
7856 ZigVar *var = ir_create_var(irb, node, subexpr_scope,8887 ZigVar *var = ir_create_var(irb, node, subexpr_scope,
7857 var_symbol, is_const, is_const, is_shadowable, is_comptime);8888 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);8890 IrInstSrc *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;8891 IrInstSrc *var_ptr = var_is_ptr ? ir_build_ref_src(irb, subexpr_scope, node, payload_ptr, true, false) : payload_ptr;
7861 ir_build_var_decl_src(irb, subexpr_scope, node, var, nullptr, var_ptr);8892 ir_build_var_decl_src(irb, subexpr_scope, node, var, nullptr, var_ptr);
7862 var_scope = var->child_scope;8893 var_scope = var->child_scope;
7863 } else {8894 } else {
7864 var_scope = subexpr_scope;8895 var_scope = subexpr_scope;
7865 }8896 }
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,
7867 &peer_parent->peers.at(0)->base);8898 &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)
7869 return then_expr_result;8900 return then_expr_result;
7870 IrBasicBlock *after_then_block = irb->current_basic_block;8901 IrBasicBlockSrc *after_then_block = irb->current_basic_block;
7871 if (!instr_is_unreachable(then_expr_result))8902 if (!instr_is_unreachable(then_expr_result))
7872 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));8903 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));
78738904
7874 ir_set_cursor_at_end_and_append_block(irb, else_block);8905 ir_set_cursor_at_end_and_append_block(irb, else_block);
7875 IrInstruction *else_expr_result;8906 IrInstSrc *else_expr_result;
7876 if (else_node) {8907 if (else_node) {
7877 else_expr_result = ir_gen_node_extra(irb, else_node, subexpr_scope, lval, &peer_parent->peers.at(1)->base);8908 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)
7879 return else_expr_result;8910 return else_expr_result;
7880 } else {8911 } else {
7881 else_expr_result = ir_build_const_void(irb, scope, node);8912 else_expr_result = ir_build_const_void(irb, scope, node);
7882 ir_build_end_expr(irb, scope, node, else_expr_result, &peer_parent->peers.at(1)->base);8913 ir_build_end_expr(irb, scope, node, else_expr_result, &peer_parent->peers.at(1)->base);
7883 }8914 }
7884 IrBasicBlock *after_else_block = irb->current_basic_block;8915 IrBasicBlockSrc *after_else_block = irb->current_basic_block;
7885 if (!instr_is_unreachable(else_expr_result))8916 if (!instr_is_unreachable(else_expr_result))
7886 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));8917 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));
78878918
7888 ir_set_cursor_at_end_and_append_block(irb, endif_block);8919 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);
7890 incoming_values[0] = then_expr_result;8921 incoming_values[0] = then_expr_result;
7891 incoming_values[1] = else_expr_result;8922 incoming_values[1] = else_expr_result;
7892 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *");8923 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
7893 incoming_blocks[0] = after_then_block;8924 incoming_blocks[0] = after_then_block;
7894 incoming_blocks[1] = after_else_block;8925 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);
7897 return ir_expr_wrap(irb, scope, phi, result_loc);8928 return ir_expr_wrap(irb, scope, phi, result_loc);
7898}8929}
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,
7901 ResultLoc *result_loc)8932 ResultLoc *result_loc)
7902{8933{
7903 assert(node->type == NodeTypeIfErrorExpr);8934 assert(node->type == NodeTypeIfErrorExpr);
...@@ -7910,20 +8941,20 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -7910,20 +8941,20 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
7910 Buf *var_symbol = node->data.if_err_expr.var_symbol;8941 Buf *var_symbol = node->data.if_err_expr.var_symbol;
7911 Buf *err_symbol = node->data.if_err_expr.err_symbol;8942 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);8944 IrInstSrc *err_val_ptr = ir_gen_node_extra(irb, target_node, scope, LValPtr, nullptr);
7914 if (err_val_ptr == irb->codegen->invalid_instruction)8945 if (err_val_ptr == irb->codegen->invalid_inst_src)
7915 return err_val_ptr;8946 return err_val_ptr;
79168947
7917 IrInstruction *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr);8948 IrInstSrc *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);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");8951 IrBasicBlockSrc *ok_block = ir_create_basic_block(irb, scope, "TryOk");
7921 IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "TryElse");8952 IrBasicBlockSrc *else_block = ir_create_basic_block(irb, scope, "TryElse");
7922 IrBasicBlock *endif_block = ir_create_basic_block(irb, scope, "TryEnd");8953 IrBasicBlockSrc *endif_block = ir_create_basic_block(irb, scope, "TryEnd");
79238954
7924 bool force_comptime = ir_should_inline(irb->exec, scope);8955 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);8956 IrInstSrc *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);8957 IrInstSrc *cond_br_inst = ir_build_cond_br(irb, scope, node, is_err, else_block, ok_block, is_comptime);
79278958
7928 ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, endif_block,8959 ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, endif_block,
7929 result_loc, is_comptime);8960 result_loc, is_comptime);
...@@ -7934,29 +8965,29 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -7934,29 +8965,29 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
7934 Scope *var_scope;8965 Scope *var_scope;
7935 if (var_symbol) {8966 if (var_symbol) {
7936 bool is_shadowable = false;8967 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);
7938 ZigVar *var = ir_create_var(irb, node, subexpr_scope,8969 ZigVar *var = ir_create_var(irb, node, subexpr_scope,
7939 var_symbol, var_is_const, var_is_const, is_shadowable, var_is_comptime);8970 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);8972 IrInstSrc *payload_ptr = ir_build_unwrap_err_payload_src(irb, subexpr_scope, node, err_val_ptr, false, false);
7942 IrInstruction *var_ptr = var_is_ptr ?8973 IrInstSrc *var_ptr = var_is_ptr ?
7943 ir_build_ref(irb, subexpr_scope, node, payload_ptr, true, false) : payload_ptr;8974 ir_build_ref_src(irb, subexpr_scope, node, payload_ptr, true, false) : payload_ptr;
7944 ir_build_var_decl_src(irb, subexpr_scope, node, var, nullptr, var_ptr);8975 ir_build_var_decl_src(irb, subexpr_scope, node, var, nullptr, var_ptr);
7945 var_scope = var->child_scope;8976 var_scope = var->child_scope;
7946 } else {8977 } else {
7947 var_scope = subexpr_scope;8978 var_scope = subexpr_scope;
7948 }8979 }
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,
7950 &peer_parent->peers.at(0)->base);8981 &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)
7952 return then_expr_result;8983 return then_expr_result;
7953 IrBasicBlock *after_then_block = irb->current_basic_block;8984 IrBasicBlockSrc *after_then_block = irb->current_basic_block;
7954 if (!instr_is_unreachable(then_expr_result))8985 if (!instr_is_unreachable(then_expr_result))
7955 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));8986 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));
79568987
7957 ir_set_cursor_at_end_and_append_block(irb, else_block);8988 ir_set_cursor_at_end_and_append_block(irb, else_block);
79588989
7959 IrInstruction *else_expr_result;8990 IrInstSrc *else_expr_result;
7960 if (else_node) {8991 if (else_node) {
7961 Scope *err_var_scope;8992 Scope *err_var_scope;
7962 if (err_symbol) {8993 if (err_symbol) {
...@@ -7965,40 +8996,40 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -7965,40 +8996,40 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
7965 ZigVar *var = ir_create_var(irb, node, subexpr_scope,8996 ZigVar *var = ir_create_var(irb, node, subexpr_scope,
7966 err_symbol, is_const, is_const, is_shadowable, is_comptime);8997 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);
7969 ir_build_var_decl_src(irb, subexpr_scope, node, var, nullptr, err_ptr);9000 ir_build_var_decl_src(irb, subexpr_scope, node, var, nullptr, err_ptr);
7970 err_var_scope = var->child_scope;9001 err_var_scope = var->child_scope;
7971 } else {9002 } else {
7972 err_var_scope = subexpr_scope;9003 err_var_scope = subexpr_scope;
7973 }9004 }
7974 else_expr_result = ir_gen_node_extra(irb, else_node, err_var_scope, lval, &peer_parent->peers.at(1)->base);9005 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)
7976 return else_expr_result;9007 return else_expr_result;
7977 } else {9008 } else {
7978 else_expr_result = ir_build_const_void(irb, scope, node);9009 else_expr_result = ir_build_const_void(irb, scope, node);
7979 ir_build_end_expr(irb, scope, node, else_expr_result, &peer_parent->peers.at(1)->base);9010 ir_build_end_expr(irb, scope, node, else_expr_result, &peer_parent->peers.at(1)->base);
7980 }9011 }
7981 IrBasicBlock *after_else_block = irb->current_basic_block;9012 IrBasicBlockSrc *after_else_block = irb->current_basic_block;
7982 if (!instr_is_unreachable(else_expr_result))9013 if (!instr_is_unreachable(else_expr_result))
7983 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));9014 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));
79849015
7985 ir_set_cursor_at_end_and_append_block(irb, endif_block);9016 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);
7987 incoming_values[0] = then_expr_result;9018 incoming_values[0] = then_expr_result;
7988 incoming_values[1] = else_expr_result;9019 incoming_values[1] = else_expr_result;
7989 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *");9020 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
7990 incoming_blocks[0] = after_then_block;9021 incoming_blocks[0] = after_then_block;
7991 incoming_blocks[1] = after_else_block;9022 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);
7994 return ir_expr_wrap(irb, scope, phi, result_loc);9025 return ir_expr_wrap(irb, scope, phi, result_loc);
7995}9026}
79969027
7997static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *switch_node, AstNode *prong_node,9028static bool ir_gen_switch_prong_expr(IrBuilderSrc *irb, Scope *scope, AstNode *switch_node, AstNode *prong_node,
7998 IrBasicBlock *end_block, IrInstruction *is_comptime, IrInstruction *var_is_comptime,9029 IrBasicBlockSrc *end_block, IrInstSrc *is_comptime, IrInstSrc *var_is_comptime,
7999 IrInstruction *target_value_ptr, IrInstruction **prong_values, size_t prong_values_len,9030 IrInstSrc *target_value_ptr, IrInstSrc **prong_values, size_t prong_values_len,
8000 ZigList<IrBasicBlock *> *incoming_blocks, ZigList<IrInstruction *> *incoming_values,9031 ZigList<IrBasicBlockSrc *> *incoming_blocks, ZigList<IrInstSrc *> *incoming_values,
8001 IrInstructionSwitchElseVar **out_switch_else_var, LVal lval, ResultLoc *result_loc)9032 IrInstSrcSwitchElseVar **out_switch_else_var, LVal lval, ResultLoc *result_loc)
8002{9033{
8003 assert(switch_node->type == NodeTypeSwitchExpr);9034 assert(switch_node->type == NodeTypeSwitchExpr);
8004 assert(prong_node->type == NodeTypeSwitchProng);9035 assert(prong_node->type == NodeTypeSwitchProng);
...@@ -8016,28 +9047,28 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *swit...@@ -8016,28 +9047,28 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *swit
8016 ZigVar *var = ir_create_var(irb, var_symbol_node, scope,9047 ZigVar *var = ir_create_var(irb, var_symbol_node, scope,
8017 var_name, is_const, is_const, is_shadowable, var_is_comptime);9048 var_name, is_const, is_const, is_shadowable, var_is_comptime);
8018 child_scope = var->child_scope;9049 child_scope = var->child_scope;
8019 IrInstruction *var_ptr;9050 IrInstSrc *var_ptr;
8020 if (out_switch_else_var != nullptr) {9051 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,
8022 target_value_ptr);9053 target_value_ptr);
8023 *out_switch_else_var = switch_else_var;9054 *out_switch_else_var = switch_else_var;
8024 IrInstruction *payload_ptr = &switch_else_var->base;9055 IrInstSrc *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;9056 var_ptr = var_is_ptr ? ir_build_ref_src(irb, scope, var_symbol_node, payload_ptr, true, false) : payload_ptr;
8026 } else if (prong_values != nullptr) {9057 } 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,
8028 prong_values, prong_values_len);9059 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;
8030 } else {9061 } else {
8031 var_ptr = var_is_ptr ?9062 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;
8033 }9064 }
8034 ir_build_var_decl_src(irb, scope, var_symbol_node, var, nullptr, var_ptr);9065 ir_build_var_decl_src(irb, scope, var_symbol_node, var, nullptr, var_ptr);
8035 } else {9066 } else {
8036 child_scope = scope;9067 child_scope = scope;
8037 }9068 }
80389069
8039 IrInstruction *expr_result = ir_gen_node_extra(irb, expr_node, child_scope, lval, result_loc);9070 IrInstSrc *expr_result = ir_gen_node_extra(irb, expr_node, child_scope, lval, result_loc);
8040 if (expr_result == irb->codegen->invalid_instruction)9071 if (expr_result == irb->codegen->invalid_inst_src)
8041 return false;9072 return false;
8042 if (!instr_is_unreachable(expr_result))9073 if (!instr_is_unreachable(expr_result))
8043 ir_mark_gen(ir_build_br(irb, scope, switch_node, end_block, is_comptime));9074 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...@@ -8046,25 +9077,25 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *swit
8046 return true;9077 return true;
8047}9078}
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,
8050 ResultLoc *result_loc)9081 ResultLoc *result_loc)
8051{9082{
8052 assert(node->type == NodeTypeSwitchExpr);9083 assert(node->type == NodeTypeSwitchExpr);
80539084
8054 AstNode *target_node = node->data.switch_expr.expr;9085 AstNode *target_node = node->data.switch_expr.expr;
8055 IrInstruction *target_value_ptr = ir_gen_node_extra(irb, target_node, scope, LValPtr, nullptr);9086 IrInstSrc *target_value_ptr = ir_gen_node_extra(irb, target_node, scope, LValPtr, nullptr);
8056 if (target_value_ptr == irb->codegen->invalid_instruction)9087 if (target_value_ptr == irb->codegen->invalid_inst_src)
8057 return target_value_ptr;9088 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");9091 IrBasicBlockSrc *else_block = ir_create_basic_block(irb, scope, "SwitchElse");
8061 IrBasicBlock *end_block = ir_create_basic_block(irb, scope, "SwitchEnd");9092 IrBasicBlockSrc *end_block = ir_create_basic_block(irb, scope, "SwitchEnd");
80629093
8063 size_t prong_count = node->data.switch_expr.prongs.length;9094 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;9097 IrInstSrc *is_comptime;
8067 IrInstruction *var_is_comptime;9098 IrInstSrc *var_is_comptime;
8068 if (ir_should_inline(irb->exec, scope)) {9099 if (ir_should_inline(irb->exec, scope)) {
8069 is_comptime = ir_build_const_bool(irb, scope, node, true);9100 is_comptime = ir_build_const_bool(irb, scope, node, true);
8070 var_is_comptime = is_comptime;9101 var_is_comptime = is_comptime;
...@@ -8073,11 +9104,11 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -8073,11 +9104,11 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
8073 var_is_comptime = ir_build_test_comptime(irb, scope, node, target_value_ptr);9104 var_is_comptime = ir_build_test_comptime(irb, scope, node, target_value_ptr);
8074 }9105 }
80759106
8076 ZigList<IrInstruction *> incoming_values = {0};9107 ZigList<IrInstSrc *> incoming_values = {0};
8077 ZigList<IrBasicBlock *> incoming_blocks = {0};9108 ZigList<IrBasicBlockSrc *> incoming_blocks = {0};
8078 ZigList<IrInstructionCheckSwitchProngsRange> check_ranges = {0};9109 ZigList<IrInstSrcCheckSwitchProngsRange> check_ranges = {0};
80799110
8080 IrInstructionSwitchElseVar *switch_else_var = nullptr;9111 IrInstSrcSwitchElseVar *switch_else_var = nullptr;
80819112
8082 ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1);9113 ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1);
8083 peer_parent->base.id = ResultLocIdPeerParent;9114 peer_parent->base.id = ResultLocIdPeerParent;
...@@ -8099,7 +9130,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -8099,7 +9130,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
8099 if (prong_node->data.switch_prong.any_items_are_range) {9130 if (prong_node->data.switch_prong.any_items_are_range) {
8100 ResultLocPeer *this_peer_result_loc = create_peer_result(peer_parent);9131 ResultLocPeer *this_peer_result_loc = create_peer_result(peer_parent);
81019132
8102 IrInstruction *ok_bit = nullptr;9133 IrInstSrc *ok_bit = nullptr;
8103 AstNode *last_item_node = nullptr;9134 AstNode *last_item_node = nullptr;
8104 for (size_t item_i = 0; item_i < prong_item_count; item_i += 1) {9135 for (size_t item_i = 0; item_i < prong_item_count; item_i += 1) {
8105 AstNode *item_node = prong_node->data.switch_prong.items.at(item_i);9136 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 *...@@ -8108,23 +9139,23 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
8108 AstNode *start_node = item_node->data.switch_range.start;9139 AstNode *start_node = item_node->data.switch_range.start;
8109 AstNode *end_node = item_node->data.switch_range.end;9140 AstNode *end_node = item_node->data.switch_range.end;
81109141
8111 IrInstruction *start_value = ir_gen_node(irb, start_node, comptime_scope);9142 IrInstSrc *start_value = ir_gen_node(irb, start_node, comptime_scope);
8112 if (start_value == irb->codegen->invalid_instruction)9143 if (start_value == irb->codegen->invalid_inst_src)
8113 return irb->codegen->invalid_instruction;9144 return irb->codegen->invalid_inst_src;
81149145
8115 IrInstruction *end_value = ir_gen_node(irb, end_node, comptime_scope);9146 IrInstSrc *end_value = ir_gen_node(irb, end_node, comptime_scope);
8116 if (end_value == irb->codegen->invalid_instruction)9147 if (end_value == irb->codegen->invalid_inst_src)
8117 return irb->codegen->invalid_instruction;9148 return irb->codegen->invalid_inst_src;
81189149
8119 IrInstructionCheckSwitchProngsRange *check_range = check_ranges.add_one();9150 IrInstSrcCheckSwitchProngsRange *check_range = check_ranges.add_one();
8120 check_range->start = start_value;9151 check_range->start = start_value;
8121 check_range->end = end_value;9152 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,
8124 target_value, start_value, false);9155 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,
8126 target_value, end_value, false);9157 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,
8128 lower_range_ok, upper_range_ok, false);9159 lower_range_ok, upper_range_ok, false);
8129 if (ok_bit) {9160 if (ok_bit) {
8130 ok_bit = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolOr, both_ok, ok_bit, false);9161 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 *...@@ -8132,15 +9163,15 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
8132 ok_bit = both_ok;9163 ok_bit = both_ok;
8133 }9164 }
8134 } else {9165 } else {
8135 IrInstruction *item_value = ir_gen_node(irb, item_node, comptime_scope);9166 IrInstSrc *item_value = ir_gen_node(irb, item_node, comptime_scope);
8136 if (item_value == irb->codegen->invalid_instruction)9167 if (item_value == irb->codegen->invalid_inst_src)
8137 return irb->codegen->invalid_instruction;9168 return irb->codegen->invalid_inst_src;
81389169
8139 IrInstructionCheckSwitchProngsRange *check_range = check_ranges.add_one();9170 IrInstSrcCheckSwitchProngsRange *check_range = check_ranges.add_one();
8140 check_range->start = item_value;9171 check_range->start = item_value;
8141 check_range->end = item_value;9172 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,
8144 item_value, target_value, false);9175 item_value, target_value, false);
8145 if (ok_bit) {9176 if (ok_bit) {
8146 ok_bit = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolOr, cmp_ok, ok_bit, false);9177 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 *...@@ -8150,12 +9181,12 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
8150 }9181 }
8151 }9182 }
81529183
8153 IrBasicBlock *range_block_yes = ir_create_basic_block(irb, scope, "SwitchRangeYes");9184 IrBasicBlockSrc *range_block_yes = ir_create_basic_block(irb, scope, "SwitchRangeYes");
8154 IrBasicBlock *range_block_no = ir_create_basic_block(irb, scope, "SwitchRangeNo");9185 IrBasicBlockSrc *range_block_no = ir_create_basic_block(irb, scope, "SwitchRangeNo");
81559186
8156 assert(ok_bit);9187 assert(ok_bit);
8157 assert(last_item_node);9188 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,
8159 range_block_yes, range_block_no, is_comptime));9190 range_block_yes, range_block_no, is_comptime));
8160 if (peer_parent->base.source_instruction == nullptr) {9191 if (peer_parent->base.source_instruction == nullptr) {
8161 peer_parent->base.source_instruction = br_inst;9192 peer_parent->base.source_instruction = br_inst;
...@@ -8170,7 +9201,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -8170,7 +9201,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
8170 is_comptime, var_is_comptime, target_value_ptr, nullptr, 0,9201 is_comptime, var_is_comptime, target_value_ptr, nullptr, 0,
8171 &incoming_blocks, &incoming_values, nullptr, LValNone, &this_peer_result_loc->base))9202 &incoming_blocks, &incoming_values, nullptr, LValNone, &this_peer_result_loc->base))
8172 {9203 {
8173 return irb->codegen->invalid_instruction;9204 return irb->codegen->invalid_inst_src;
8174 }9205 }
81759206
8176 ir_set_cursor_at_end_and_append_block(irb, range_block_no);9207 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 *...@@ -8181,7 +9212,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
8181 buf_sprintf("multiple else prongs in switch expression"));9212 buf_sprintf("multiple else prongs in switch expression"));
8182 add_error_note(irb->codegen, msg, else_prong,9213 add_error_note(irb->codegen, msg, else_prong,
8183 buf_sprintf("previous else prong is here"));9214 buf_sprintf("previous else prong is here"));
8184 return irb->codegen->invalid_instruction;9215 return irb->codegen->invalid_inst_src;
8185 }9216 }
8186 else_prong = prong_node;9217 else_prong = prong_node;
8187 } else if (prong_item_count == 1 && 9218 } else if (prong_item_count == 1 &&
...@@ -8192,7 +9223,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -8192,7 +9223,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
8192 buf_sprintf("multiple '_' prongs in switch expression"));9223 buf_sprintf("multiple '_' prongs in switch expression"));
8193 add_error_note(irb->codegen, msg, underscore_prong,9224 add_error_note(irb->codegen, msg, underscore_prong,
8194 buf_sprintf("previous '_' prong is here"));9225 buf_sprintf("previous '_' prong is here"));
8195 return irb->codegen->invalid_instruction;9226 return irb->codegen->invalid_inst_src;
8196 }9227 }
8197 underscore_prong = prong_node;9228 underscore_prong = prong_node;
8198 } else {9229 } else {
...@@ -8207,11 +9238,11 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -8207,11 +9238,11 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
8207 else9238 else
8208 add_error_note(irb->codegen, msg, underscore_prong,9239 add_error_note(irb->codegen, msg, underscore_prong,
8209 buf_sprintf("'_' prong is here"));9240 buf_sprintf("'_' prong is here"));
8210 return irb->codegen->invalid_instruction;9241 return irb->codegen->invalid_inst_src;
8211 }9242 }
8212 ResultLocPeer *this_peer_result_loc = create_peer_result(peer_parent);9243 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;
8215 if (peer_parent->peers.length > 0) {9246 if (peer_parent->peers.length > 0) {
8216 peer_parent->peers.last()->next_bb = else_block;9247 peer_parent->peers.last()->next_bb = else_block;
8217 }9248 }
...@@ -8221,7 +9252,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -8221,7 +9252,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
8221 is_comptime, var_is_comptime, target_value_ptr, nullptr, 0, &incoming_blocks, &incoming_values,9252 is_comptime, var_is_comptime, target_value_ptr, nullptr, 0, &incoming_blocks, &incoming_values,
8222 &switch_else_var, LValNone, &this_peer_result_loc->base))9253 &switch_else_var, LValNone, &this_peer_result_loc->base))
8223 {9254 {
8224 return irb->codegen->invalid_instruction;9255 return irb->codegen->invalid_inst_src;
8225 }9256 }
8226 ir_set_cursor_at_end(irb, prev_block);9257 ir_set_cursor_at_end(irb, prev_block);
8227 }9258 }
...@@ -8240,29 +9271,29 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -8240,29 +9271,29 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
82409271
8241 ResultLocPeer *this_peer_result_loc = create_peer_result(peer_parent);9272 ResultLocPeer *this_peer_result_loc = create_peer_result(peer_parent);
82429273
8243 IrBasicBlock *prong_block = ir_create_basic_block(irb, scope, "SwitchProng");9274 IrBasicBlockSrc *prong_block = ir_create_basic_block(irb, scope, "SwitchProng");
8244 IrInstruction **items = allocate<IrInstruction *>(prong_item_count);9275 IrInstSrc **items = allocate<IrInstSrc *>(prong_item_count);
82459276
8246 for (size_t item_i = 0; item_i < prong_item_count; item_i += 1) {9277 for (size_t item_i = 0; item_i < prong_item_count; item_i += 1) {
8247 AstNode *item_node = prong_node->data.switch_prong.items.at(item_i);9278 AstNode *item_node = prong_node->data.switch_prong.items.at(item_i);
8248 assert(item_node->type != NodeTypeSwitchRange);9279 assert(item_node->type != NodeTypeSwitchRange);
82499280
8250 IrInstruction *item_value = ir_gen_node(irb, item_node, comptime_scope);9281 IrInstSrc *item_value = ir_gen_node(irb, item_node, comptime_scope);
8251 if (item_value == irb->codegen->invalid_instruction)9282 if (item_value == irb->codegen->invalid_inst_src)
8252 return irb->codegen->invalid_instruction;9283 return irb->codegen->invalid_inst_src;
82539284
8254 IrInstructionCheckSwitchProngsRange *check_range = check_ranges.add_one();9285 IrInstSrcCheckSwitchProngsRange *check_range = check_ranges.add_one();
8255 check_range->start = item_value;9286 check_range->start = item_value;
8256 check_range->end = item_value;9287 check_range->end = item_value;
82579288
8258 IrInstructionSwitchBrCase *this_case = cases.add_one();9289 IrInstSrcSwitchBrCase *this_case = cases.add_one();
8259 this_case->value = item_value;9290 this_case->value = item_value;
8260 this_case->block = prong_block;9291 this_case->block = prong_block;
82619292
8262 items[item_i] = item_value;9293 items[item_i] = item_value;
8263 }9294 }
82649295
8265 IrBasicBlock *prev_block = irb->current_basic_block;9296 IrBasicBlockSrc *prev_block = irb->current_basic_block;
8266 if (peer_parent->peers.length > 0) {9297 if (peer_parent->peers.length > 0) {
8267 peer_parent->peers.last()->next_bb = prong_block;9298 peer_parent->peers.last()->next_bb = prong_block;
8268 }9299 }
...@@ -8272,21 +9303,21 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -8272,21 +9303,21 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
8272 is_comptime, var_is_comptime, target_value_ptr, items, prong_item_count,9303 is_comptime, var_is_comptime, target_value_ptr, items, prong_item_count,
8273 &incoming_blocks, &incoming_values, nullptr, LValNone, &this_peer_result_loc->base))9304 &incoming_blocks, &incoming_values, nullptr, LValNone, &this_peer_result_loc->base))
8274 {9305 {
8275 return irb->codegen->invalid_instruction;9306 return irb->codegen->invalid_inst_src;
8276 }9307 }
82779308
8278 ir_set_cursor_at_end(irb, prev_block);9309 ir_set_cursor_at_end(irb, prev_block);
82799310
8280 }9311 }
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,
8283 check_ranges.items, check_ranges.length, else_prong != nullptr, underscore_prong != nullptr);9314 check_ranges.items, check_ranges.length, else_prong != nullptr, underscore_prong != nullptr);
82849315
8285 IrInstruction *br_instruction;9316 IrInstSrc *br_instruction;
8286 if (cases.length == 0) {9317 if (cases.length == 0) {
8287 br_instruction = ir_build_br(irb, scope, node, else_block, is_comptime);9318 br_instruction = ir_build_br(irb, scope, node, else_block, is_comptime);
8288 } else {9319 } 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,
8290 cases.length, cases.items, is_comptime, switch_prongs_void);9321 cases.length, cases.items, is_comptime, switch_prongs_void);
8291 if (switch_else_var != nullptr) {9322 if (switch_else_var != nullptr) {
8292 switch_else_var->switch_br = switch_br;9323 switch_else_var->switch_br = switch_br;
...@@ -8314,7 +9345,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -8314,7 +9345,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
83149345
8315 ir_set_cursor_at_end_and_append_block(irb, end_block);9346 ir_set_cursor_at_end_and_append_block(irb, end_block);
8316 assert(incoming_blocks.length == incoming_values.length);9347 assert(incoming_blocks.length == incoming_values.length);
8317 IrInstruction *result_instruction;9348 IrInstSrc *result_instruction;
8318 if (incoming_blocks.length == 0) {9349 if (incoming_blocks.length == 0) {
8319 result_instruction = ir_build_const_void(irb, scope, node);9350 result_instruction = ir_build_const_void(irb, scope, node);
8320 } else {9351 } else {
...@@ -8324,7 +9355,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -8324,7 +9355,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
8324 return ir_lval_wrap(irb, scope, result_instruction, lval, result_loc);9355 return ir_lval_wrap(irb, scope, result_instruction, lval, result_loc);
8325}9356}
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) {
8328 assert(node->type == NodeTypeCompTime);9359 assert(node->type == NodeTypeCompTime);
83299360
8330 Scope *child_scope = create_comptime_scope(irb->codegen, node, parent_scope);9361 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...@@ -8332,28 +9363,28 @@ static IrInstruction *ir_gen_comptime(IrBuilder *irb, Scope *parent_scope, AstNo
8332 return ir_gen_node_extra(irb, node->data.comptime_expr.expr, child_scope, lval, nullptr);9363 return ir_gen_node_extra(irb, node->data.comptime_expr.expr, child_scope, lval, nullptr);
8333}9364}
83349365
8335static IrInstruction *ir_gen_return_from_block(IrBuilder *irb, Scope *break_scope, AstNode *node, ScopeBlock *block_scope) {9366static IrInstSrc *ir_gen_return_from_block(IrBuilderSrc *irb, Scope *break_scope, AstNode *node, ScopeBlock *block_scope) {
8336 IrInstruction *is_comptime;9367 IrInstSrc *is_comptime;
8337 if (ir_should_inline(irb->exec, break_scope)) {9368 if (ir_should_inline(irb->exec, break_scope)) {
8338 is_comptime = ir_build_const_bool(irb, break_scope, node, true);9369 is_comptime = ir_build_const_bool(irb, break_scope, node, true);
8339 } else {9370 } else {
8340 is_comptime = block_scope->is_comptime;9371 is_comptime = block_scope->is_comptime;
8341 }9372 }
83429373
8343 IrInstruction *result_value;9374 IrInstSrc *result_value;
8344 if (node->data.break_expr.expr) {9375 if (node->data.break_expr.expr) {
8345 ResultLocPeer *peer_result = create_peer_result(block_scope->peer_parent);9376 ResultLocPeer *peer_result = create_peer_result(block_scope->peer_parent);
8346 block_scope->peer_parent->peers.append(peer_result);9377 block_scope->peer_parent->peers.append(peer_result);
83479378
8348 result_value = ir_gen_node_extra(irb, node->data.break_expr.expr, break_scope, block_scope->lval,9379 result_value = ir_gen_node_extra(irb, node->data.break_expr.expr, break_scope, block_scope->lval,
8349 &peer_result->base);9380 &peer_result->base);
8350 if (result_value == irb->codegen->invalid_instruction)9381 if (result_value == irb->codegen->invalid_inst_src)
8351 return irb->codegen->invalid_instruction;9382 return irb->codegen->invalid_inst_src;
8352 } else {9383 } else {
8353 result_value = ir_build_const_void(irb, break_scope, node);9384 result_value = ir_build_const_void(irb, break_scope, node);
8354 }9385 }
83559386
8356 IrBasicBlock *dest_block = block_scope->end_block;9387 IrBasicBlockSrc *dest_block = block_scope->end_block;
8357 ir_gen_defers_for_block(irb, break_scope, dest_block->scope, false);9388 ir_gen_defers_for_block(irb, break_scope, dest_block->scope, false);
83589389
8359 block_scope->incoming_blocks->append(irb->current_basic_block);9390 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...@@ -8361,7 +9392,7 @@ static IrInstruction *ir_gen_return_from_block(IrBuilder *irb, Scope *break_scop
8361 return ir_build_br(irb, break_scope, node, dest_block, is_comptime);9392 return ir_build_br(irb, break_scope, node, dest_block, is_comptime);
8362}9393}
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) {
8365 assert(node->type == NodeTypeBreak);9396 assert(node->type == NodeTypeBreak);
83669397
8367 // Search up the scope. We'll find one of these things first:9398 // 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 *...@@ -8376,14 +9407,14 @@ static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode *
8376 if (search_scope == nullptr || search_scope->id == ScopeIdFnDef) {9407 if (search_scope == nullptr || search_scope->id == ScopeIdFnDef) {
8377 if (node->data.break_expr.name != nullptr) {9408 if (node->data.break_expr.name != nullptr) {
8378 add_node_error(irb->codegen, node, buf_sprintf("label not found: '%s'", buf_ptr(node->data.break_expr.name)));9409 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;
8380 } else {9411 } else {
8381 add_node_error(irb->codegen, node, buf_sprintf("break expression outside loop"));9412 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;
8383 }9414 }
8384 } else if (search_scope->id == ScopeIdDeferExpr) {9415 } else if (search_scope->id == ScopeIdDeferExpr) {
8385 add_node_error(irb->codegen, node, buf_sprintf("cannot break out of defer expression"));9416 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;
8387 } else if (search_scope->id == ScopeIdLoop) {9418 } else if (search_scope->id == ScopeIdLoop) {
8388 ScopeLoop *this_loop_scope = (ScopeLoop *)search_scope;9419 ScopeLoop *this_loop_scope = (ScopeLoop *)search_scope;
8389 if (node->data.break_expr.name == nullptr ||9420 if (node->data.break_expr.name == nullptr ||
...@@ -8402,32 +9433,32 @@ static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode *...@@ -8402,32 +9433,32 @@ static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode *
8402 }9433 }
8403 } else if (search_scope->id == ScopeIdSuspend) {9434 } else if (search_scope->id == ScopeIdSuspend) {
8404 add_node_error(irb->codegen, node, buf_sprintf("cannot break out of suspend block"));9435 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;
8406 }9437 }
8407 search_scope = search_scope->parent;9438 search_scope = search_scope->parent;
8408 }9439 }
84099440
8410 IrInstruction *is_comptime;9441 IrInstSrc *is_comptime;
8411 if (ir_should_inline(irb->exec, break_scope)) {9442 if (ir_should_inline(irb->exec, break_scope)) {
8412 is_comptime = ir_build_const_bool(irb, break_scope, node, true);9443 is_comptime = ir_build_const_bool(irb, break_scope, node, true);
8413 } else {9444 } else {
8414 is_comptime = loop_scope->is_comptime;9445 is_comptime = loop_scope->is_comptime;
8415 }9446 }
84169447
8417 IrInstruction *result_value;9448 IrInstSrc *result_value;
8418 if (node->data.break_expr.expr) {9449 if (node->data.break_expr.expr) {
8419 ResultLocPeer *peer_result = create_peer_result(loop_scope->peer_parent);9450 ResultLocPeer *peer_result = create_peer_result(loop_scope->peer_parent);
8420 loop_scope->peer_parent->peers.append(peer_result);9451 loop_scope->peer_parent->peers.append(peer_result);
84219452
8422 result_value = ir_gen_node_extra(irb, node->data.break_expr.expr, break_scope,9453 result_value = ir_gen_node_extra(irb, node->data.break_expr.expr, break_scope,
8423 loop_scope->lval, &peer_result->base);9454 loop_scope->lval, &peer_result->base);
8424 if (result_value == irb->codegen->invalid_instruction)9455 if (result_value == irb->codegen->invalid_inst_src)
8425 return irb->codegen->invalid_instruction;9456 return irb->codegen->invalid_inst_src;
8426 } else {9457 } else {
8427 result_value = ir_build_const_void(irb, break_scope, node);9458 result_value = ir_build_const_void(irb, break_scope, node);
8428 }9459 }
84299460
8430 IrBasicBlock *dest_block = loop_scope->break_block;9461 IrBasicBlockSrc *dest_block = loop_scope->break_block;
8431 ir_gen_defers_for_block(irb, break_scope, dest_block->scope, false);9462 ir_gen_defers_for_block(irb, break_scope, dest_block->scope, false);
84329463
8433 loop_scope->incoming_blocks->append(irb->current_basic_block);9464 loop_scope->incoming_blocks->append(irb->current_basic_block);
...@@ -8435,7 +9466,7 @@ static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode *...@@ -8435,7 +9466,7 @@ static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode *
8435 return ir_build_br(irb, break_scope, node, dest_block, is_comptime);9466 return ir_build_br(irb, break_scope, node, dest_block, is_comptime);
8436}9467}
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) {
8439 assert(node->type == NodeTypeContinue);9470 assert(node->type == NodeTypeContinue);
84409471
8441 // Search up the scope. We'll find one of these things first:9472 // 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...@@ -8451,14 +9482,14 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast
8451 if (search_scope == nullptr || search_scope->id == ScopeIdFnDef) {9482 if (search_scope == nullptr || search_scope->id == ScopeIdFnDef) {
8452 if (node->data.continue_expr.name != nullptr) {9483 if (node->data.continue_expr.name != nullptr) {
8453 add_node_error(irb->codegen, node, buf_sprintf("labeled loop not found: '%s'", buf_ptr(node->data.continue_expr.name)));9484 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;
8455 } else {9486 } else {
8456 add_node_error(irb->codegen, node, buf_sprintf("continue expression outside loop"));9487 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;
8458 }9489 }
8459 } else if (search_scope->id == ScopeIdDeferExpr) {9490 } else if (search_scope->id == ScopeIdDeferExpr) {
8460 add_node_error(irb->codegen, node, buf_sprintf("cannot continue out of defer expression"));9491 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;
8462 } else if (search_scope->id == ScopeIdLoop) {9493 } else if (search_scope->id == ScopeIdLoop) {
8463 ScopeLoop *this_loop_scope = (ScopeLoop *)search_scope;9494 ScopeLoop *this_loop_scope = (ScopeLoop *)search_scope;
8464 if (node->data.continue_expr.name == nullptr ||9495 if (node->data.continue_expr.name == nullptr ||
...@@ -8474,7 +9505,7 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast...@@ -8474,7 +9505,7 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast
8474 search_scope = search_scope->parent;9505 search_scope = search_scope->parent;
8475 }9506 }
84769507
8477 IrInstruction *is_comptime;9508 IrInstSrc *is_comptime;
8478 if (ir_should_inline(irb->exec, continue_scope)) {9509 if (ir_should_inline(irb->exec, continue_scope)) {
8479 is_comptime = ir_build_const_bool(irb, continue_scope, node, true);9510 is_comptime = ir_build_const_bool(irb, continue_scope, node, true);
8480 } else {9511 } else {
...@@ -8486,17 +9517,17 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast...@@ -8486,17 +9517,17 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast
8486 ir_mark_gen(ir_build_check_runtime_scope(irb, continue_scope, node, scope_runtime->is_comptime, is_comptime));9517 ir_mark_gen(ir_build_check_runtime_scope(irb, continue_scope, node, scope_runtime->is_comptime, is_comptime));
8487 }9518 }
84889519
8489 IrBasicBlock *dest_block = loop_scope->continue_block;9520 IrBasicBlockSrc *dest_block = loop_scope->continue_block;
8490 ir_gen_defers_for_block(irb, continue_scope, dest_block->scope, false);9521 ir_gen_defers_for_block(irb, continue_scope, dest_block->scope, false);
8491 return ir_mark_gen(ir_build_br(irb, continue_scope, node, dest_block, is_comptime));9522 return ir_mark_gen(ir_build_br(irb, continue_scope, node, dest_block, is_comptime));
8492}9523}
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) {
8495 assert(node->type == NodeTypeErrorType);9526 assert(node->type == NodeTypeErrorType);
8496 return ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_global_error_set);9527 return ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_global_error_set);
8497}9528}
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) {
8500 assert(node->type == NodeTypeDefer);9531 assert(node->type == NodeTypeDefer);
85019532
8502 ScopeDefer *defer_child_scope = create_defer_scope(irb->codegen, node, parent_scope);9533 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...@@ -8508,7 +9539,7 @@ static IrInstruction *ir_gen_defer(IrBuilder *irb, Scope *parent_scope, AstNode
8508 return ir_build_const_void(irb, parent_scope, node);9539 return ir_build_const_void(irb, parent_scope, node);
8509}9540}
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) {
8512 assert(node->type == NodeTypeSliceExpr);9543 assert(node->type == NodeTypeSliceExpr);
85139544
8514 AstNodeSliceExpr *slice_expr = &node->data.slice_expr;9545 AstNodeSliceExpr *slice_expr = &node->data.slice_expr;
...@@ -8517,38 +9548,38 @@ static IrInstruction *ir_gen_slice(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -8517,38 +9548,38 @@ static IrInstruction *ir_gen_slice(IrBuilder *irb, Scope *scope, AstNode *node,
8517 AstNode *end_node = slice_expr->end;9548 AstNode *end_node = slice_expr->end;
8518 AstNode *sentinel_node = slice_expr->sentinel;9549 AstNode *sentinel_node = slice_expr->sentinel;
85199550
8520 IrInstruction *ptr_value = ir_gen_node_extra(irb, array_node, scope, LValPtr, nullptr);9551 IrInstSrc *ptr_value = ir_gen_node_extra(irb, array_node, scope, LValPtr, nullptr);
8521 if (ptr_value == irb->codegen->invalid_instruction)9552 if (ptr_value == irb->codegen->invalid_inst_src)
8522 return irb->codegen->invalid_instruction;9553 return irb->codegen->invalid_inst_src;
85239554
8524 IrInstruction *start_value = ir_gen_node(irb, start_node, scope);9555 IrInstSrc *start_value = ir_gen_node(irb, start_node, scope);
8525 if (start_value == irb->codegen->invalid_instruction)9556 if (start_value == irb->codegen->invalid_inst_src)
8526 return irb->codegen->invalid_instruction;9557 return irb->codegen->invalid_inst_src;
85279558
8528 IrInstruction *end_value;9559 IrInstSrc *end_value;
8529 if (end_node) {9560 if (end_node) {
8530 end_value = ir_gen_node(irb, end_node, scope);9561 end_value = ir_gen_node(irb, end_node, scope);
8531 if (end_value == irb->codegen->invalid_instruction)9562 if (end_value == irb->codegen->invalid_inst_src)
8532 return irb->codegen->invalid_instruction;9563 return irb->codegen->invalid_inst_src;
8533 } else {9564 } else {
8534 end_value = nullptr;9565 end_value = nullptr;
8535 }9566 }
85369567
8537 IrInstruction *sentinel_value;9568 IrInstSrc *sentinel_value;
8538 if (sentinel_node) {9569 if (sentinel_node) {
8539 sentinel_value = ir_gen_node(irb, sentinel_node, scope);9570 sentinel_value = ir_gen_node(irb, sentinel_node, scope);
8540 if (sentinel_value == irb->codegen->invalid_instruction)9571 if (sentinel_value == irb->codegen->invalid_inst_src)
8541 return irb->codegen->invalid_instruction;9572 return irb->codegen->invalid_inst_src;
8542 } else {9573 } else {
8543 sentinel_value = nullptr;9574 sentinel_value = nullptr;
8544 }9575 }
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,
8547 sentinel_value, true, result_loc);9578 sentinel_value, true, result_loc);
8548 return ir_lval_wrap(irb, scope, slice, lval, result_loc);9579 return ir_lval_wrap(irb, scope, slice, lval, result_loc);
8549}9580}
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,
8552 ResultLoc *result_loc)9583 ResultLoc *result_loc)
8553{9584{
8554 assert(node->type == NodeTypeCatchExpr);9585 assert(node->type == NodeTypeCatchExpr);
...@@ -8562,29 +9593,29 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode...@@ -8562,29 +9593,29 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode
8562 assert(var_node->type == NodeTypeSymbol);9593 assert(var_node->type == NodeTypeSymbol);
8563 Buf *var_name = var_node->data.symbol_expr.symbol;9594 Buf *var_name = var_node->data.symbol_expr.symbol;
8564 add_node_error(irb->codegen, var_node, buf_sprintf("unused variable: '%s'", buf_ptr(var_name)));9595 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;
8566 }9597 }
8567 return ir_gen_catch_unreachable(irb, parent_scope, node, op1_node, lval, result_loc);9598 return ir_gen_catch_unreachable(irb, parent_scope, node, op1_node, lval, result_loc);
8568 }9599 }
85699600
85709601
8571 IrInstruction *err_union_ptr = ir_gen_node_extra(irb, op1_node, parent_scope, LValPtr, nullptr);9602 IrInstSrc *err_union_ptr = ir_gen_node_extra(irb, op1_node, parent_scope, LValPtr, nullptr);
8572 if (err_union_ptr == irb->codegen->invalid_instruction)9603 if (err_union_ptr == irb->codegen->invalid_inst_src)
8573 return irb->codegen->invalid_instruction;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;
8578 if (ir_should_inline(irb->exec, parent_scope)) {9609 if (ir_should_inline(irb->exec, parent_scope)) {
8579 is_comptime = ir_build_const_bool(irb, parent_scope, node, true);9610 is_comptime = ir_build_const_bool(irb, parent_scope, node, true);
8580 } else {9611 } else {
8581 is_comptime = ir_build_test_comptime(irb, parent_scope, node, is_err);9612 is_comptime = ir_build_test_comptime(irb, parent_scope, node, is_err);
8582 }9613 }
85839614
8584 IrBasicBlock *ok_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrOk");9615 IrBasicBlockSrc *ok_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrOk");
8585 IrBasicBlock *err_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrError");9616 IrBasicBlockSrc *err_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrError");
8586 IrBasicBlock *end_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrEnd");9617 IrBasicBlockSrc *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);9618 IrInstSrc *cond_br_inst = ir_build_cond_br(irb, parent_scope, node, is_err, err_block, ok_block, is_comptime);
85889619
8589 ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, ok_block, end_block, result_loc,9620 ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, ok_block, end_block, result_loc,
8590 is_comptime);9621 is_comptime);
...@@ -8600,33 +9631,33 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode...@@ -8600,33 +9631,33 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode
8600 ZigVar *var = ir_create_var(irb, node, subexpr_scope, var_name,9631 ZigVar *var = ir_create_var(irb, node, subexpr_scope, var_name,
8601 is_const, is_const, is_shadowable, is_comptime);9632 is_const, is_const, is_shadowable, is_comptime);
8602 err_scope = var->child_scope;9633 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);
8604 ir_build_var_decl_src(irb, err_scope, var_node, var, nullptr, err_ptr);9635 ir_build_var_decl_src(irb, err_scope, var_node, var, nullptr, err_ptr);
8605 } else {9636 } else {
8606 err_scope = subexpr_scope;9637 err_scope = subexpr_scope;
8607 }9638 }
8608 IrInstruction *err_result = ir_gen_node_extra(irb, op2_node, err_scope, LValNone, &peer_parent->peers.at(0)->base);9639 IrInstSrc *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)9640 if (err_result == irb->codegen->invalid_inst_src)
8610 return irb->codegen->invalid_instruction;9641 return irb->codegen->invalid_inst_src;
8611 IrBasicBlock *after_err_block = irb->current_basic_block;9642 IrBasicBlockSrc *after_err_block = irb->current_basic_block;
8612 if (!instr_is_unreachable(err_result))9643 if (!instr_is_unreachable(err_result))
8613 ir_mark_gen(ir_build_br(irb, parent_scope, node, end_block, is_comptime));9644 ir_mark_gen(ir_build_br(irb, parent_scope, node, end_block, is_comptime));
86149645
8615 ir_set_cursor_at_end_and_append_block(irb, ok_block);9646 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);9647 IrInstSrc *unwrapped_ptr = ir_build_unwrap_err_payload_src(irb, parent_scope, node, err_union_ptr, false, false);
8617 IrInstruction *unwrapped_payload = ir_build_load_ptr(irb, parent_scope, node, unwrapped_ptr);9648 IrInstSrc *unwrapped_payload = ir_build_load_ptr(irb, parent_scope, node, unwrapped_ptr);
8618 ir_build_end_expr(irb, parent_scope, node, unwrapped_payload, &peer_parent->peers.at(1)->base);9649 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;
8620 ir_build_br(irb, parent_scope, node, end_block, is_comptime);9651 ir_build_br(irb, parent_scope, node, end_block, is_comptime);
86219652
8622 ir_set_cursor_at_end_and_append_block(irb, end_block);9653 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);
8624 incoming_values[0] = err_result;9655 incoming_values[0] = err_result;
8625 incoming_values[1] = unwrapped_payload;9656 incoming_values[1] = unwrapped_payload;
8626 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *");9657 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
8627 incoming_blocks[0] = after_err_block;9658 incoming_blocks[0] = after_err_block;
8628 incoming_blocks[1] = after_ok_block;9659 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);
8630 return ir_lval_wrap(irb, parent_scope, phi, lval, result_loc);9661 return ir_lval_wrap(irb, parent_scope, phi, lval, result_loc);
8631}9662}
86329663
...@@ -8644,7 +9675,7 @@ static bool render_instance_name_recursive(CodeGen *codegen, Buf *name, Scope *o...@@ -8644,7 +9675,7 @@ static bool render_instance_name_recursive(CodeGen *codegen, Buf *name, Scope *o
8644 return true;9675 return true;
8645}9676}
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,
8648 Scope *scope, AstNode *source_node, Buf *out_bare_name)9679 Scope *scope, AstNode *source_node, Buf *out_bare_name)
8649{9680{
8650 if (exec != nullptr && exec->name) {9681 if (exec != nullptr && exec->name) {
...@@ -8673,7 +9704,7 @@ static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char...@@ -8673,7 +9704,7 @@ static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char
8673 }9704 }
8674}9705}
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) {
8677 assert(node->type == NodeTypeContainerDecl);9708 assert(node->type == NodeTypeContainerDecl);
86789709
8679 ContainerKind kind = node->data.container_decl.kind;9710 ContainerKind kind = node->data.container_decl.kind;
...@@ -8798,7 +9829,7 @@ static AstNode *ast_field_to_symbol_node(AstNode *err_set_field_node) {...@@ -8798,7 +9829,7 @@ static AstNode *ast_field_to_symbol_node(AstNode *err_set_field_node) {
8798 }9829 }
8799}9830}
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) {
8802 assert(node->type == NodeTypeErrorSetDecl);9833 assert(node->type == NodeTypeErrorSetDecl);
88039834
8804 uint32_t err_count = node->data.err_set_decl.decls.length;9835 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...@@ -8841,7 +9872,7 @@ static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, A
8841 buf_sprintf("duplicate error: '%s'", buf_ptr(&err->name)));9872 buf_sprintf("duplicate error: '%s'", buf_ptr(&err->name)));
8842 add_error_note(irb->codegen, msg, ast_field_to_symbol_node(prev_err->decl_node),9873 add_error_note(irb->codegen, msg, ast_field_to_symbol_node(prev_err->decl_node),
8843 buf_sprintf("other error here"));9874 buf_sprintf("other error here"));
8844 return irb->codegen->invalid_instruction;9875 return irb->codegen->invalid_inst_src;
8845 }9876 }
8846 errors[err->value] = err;9877 errors[err->value] = err;
8847 }9878 }
...@@ -8849,11 +9880,11 @@ static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, A...@@ -8849,11 +9880,11 @@ static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, A
8849 return ir_build_const_type(irb, parent_scope, node, err_set_type);9880 return ir_build_const_type(irb, parent_scope, node, err_set_type);
8850}9881}
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) {
8853 assert(node->type == NodeTypeFnProto);9884 assert(node->type == NodeTypeFnProto);
88549885
8855 size_t param_count = node->data.fn_proto.params.length;9886 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
8858 bool is_var_args = false;9889 bool is_var_args = false;
8859 for (size_t i = 0; i < param_count; i += 1) {9890 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...@@ -8864,59 +9895,59 @@ static IrInstruction *ir_gen_fn_proto(IrBuilder *irb, Scope *parent_scope, AstNo
8864 }9895 }
8865 if (param_node->data.param_decl.var_token == nullptr) {9896 if (param_node->data.param_decl.var_token == nullptr) {
8866 AstNode *type_node = param_node->data.param_decl.type;9897 AstNode *type_node = param_node->data.param_decl.type;
8867 IrInstruction *type_value = ir_gen_node(irb, type_node, parent_scope);9898 IrInstSrc *type_value = ir_gen_node(irb, type_node, parent_scope);
8868 if (type_value == irb->codegen->invalid_instruction)9899 if (type_value == irb->codegen->invalid_inst_src)
8869 return irb->codegen->invalid_instruction;9900 return irb->codegen->invalid_inst_src;
8870 param_types[i] = type_value;9901 param_types[i] = type_value;
8871 } else {9902 } else {
8872 param_types[i] = nullptr;9903 param_types[i] = nullptr;
8873 }9904 }
8874 }9905 }
88759906
8876 IrInstruction *align_value = nullptr;9907 IrInstSrc *align_value = nullptr;
8877 if (node->data.fn_proto.align_expr != nullptr) {9908 if (node->data.fn_proto.align_expr != nullptr) {
8878 align_value = ir_gen_node(irb, node->data.fn_proto.align_expr, parent_scope);9909 align_value = ir_gen_node(irb, node->data.fn_proto.align_expr, parent_scope);
8879 if (align_value == irb->codegen->invalid_instruction)9910 if (align_value == irb->codegen->invalid_inst_src)
8880 return irb->codegen->invalid_instruction;9911 return irb->codegen->invalid_inst_src;
8881 }9912 }
88829913
8883 IrInstruction *callconv_value = nullptr;9914 IrInstSrc *callconv_value = nullptr;
8884 if (node->data.fn_proto.callconv_expr != nullptr) {9915 if (node->data.fn_proto.callconv_expr != nullptr) {
8885 callconv_value = ir_gen_node(irb, node->data.fn_proto.callconv_expr, parent_scope);9916 callconv_value = ir_gen_node(irb, node->data.fn_proto.callconv_expr, parent_scope);
8886 if (callconv_value == irb->codegen->invalid_instruction)9917 if (callconv_value == irb->codegen->invalid_inst_src)
8887 return irb->codegen->invalid_instruction;9918 return irb->codegen->invalid_inst_src;
8888 }9919 }
88899920
8890 IrInstruction *return_type;9921 IrInstSrc *return_type;
8891 if (node->data.fn_proto.return_var_token == nullptr) {9922 if (node->data.fn_proto.return_var_token == nullptr) {
8892 if (node->data.fn_proto.return_type == nullptr) {9923 if (node->data.fn_proto.return_type == nullptr) {
8893 return_type = ir_build_const_type(irb, parent_scope, node, irb->codegen->builtin_types.entry_void);9924 return_type = ir_build_const_type(irb, parent_scope, node, irb->codegen->builtin_types.entry_void);
8894 } else {9925 } else {
8895 return_type = ir_gen_node(irb, node->data.fn_proto.return_type, parent_scope);9926 return_type = ir_gen_node(irb, node->data.fn_proto.return_type, parent_scope);
8896 if (return_type == irb->codegen->invalid_instruction)9927 if (return_type == irb->codegen->invalid_inst_src)
8897 return irb->codegen->invalid_instruction;9928 return irb->codegen->invalid_inst_src;
8898 }9929 }
8899 } else {9930 } else {
8900 add_node_error(irb->codegen, node,9931 add_node_error(irb->codegen, node,
8901 buf_sprintf("TODO implement inferred return types https://github.com/ziglang/zig/issues/447"));9932 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;
8903 //return_type = nullptr;9934 //return_type = nullptr;
8904 }9935 }
89059936
8906 return ir_build_fn_proto(irb, parent_scope, node, param_types, align_value, callconv_value, return_type, is_var_args);9937 return ir_build_fn_proto(irb, parent_scope, node, param_types, align_value, callconv_value, return_type, is_var_args);
8907}9938}
89089939
8909static IrInstruction *ir_gen_resume(IrBuilder *irb, Scope *scope, AstNode *node) {9940static IrInstSrc *ir_gen_resume(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
8910 assert(node->type == NodeTypeResume);9941 assert(node->type == NodeTypeResume);
89119942
8912 IrInstruction *target_inst = ir_gen_node_extra(irb, node->data.resume_expr.expr, scope, LValPtr, nullptr);9943 IrInstSrc *target_inst = ir_gen_node_extra(irb, node->data.resume_expr.expr, scope, LValPtr, nullptr);
8913 if (target_inst == irb->codegen->invalid_instruction)9944 if (target_inst == irb->codegen->invalid_inst_src)
8914 return irb->codegen->invalid_instruction;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);
8917}9948}
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,
8920 ResultLoc *result_loc)9951 ResultLoc *result_loc)
8921{9952{
8922 assert(node->type == NodeTypeAwaitExpr);9953 assert(node->type == NodeTypeAwaitExpr);
...@@ -8937,7 +9968,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -8937,7 +9968,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
8937 ZigFn *fn_entry = exec_fn_entry(irb->exec);9968 ZigFn *fn_entry = exec_fn_entry(irb->exec);
8938 if (!fn_entry) {9969 if (!fn_entry) {
8939 add_node_error(irb->codegen, node, buf_sprintf("await outside function definition"));9970 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;
8941 }9972 }
8942 ScopeSuspend *existing_suspend_scope = get_scope_suspend(scope);9973 ScopeSuspend *existing_suspend_scope = get_scope_suspend(scope);
8943 if (existing_suspend_scope) {9974 if (existing_suspend_scope) {
...@@ -8946,24 +9977,24 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -8946,24 +9977,24 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
8946 add_error_note(irb->codegen, msg, existing_suspend_scope->base.source_node, buf_sprintf("suspend block here"));9977 add_error_note(irb->codegen, msg, existing_suspend_scope->base.source_node, buf_sprintf("suspend block here"));
8947 existing_suspend_scope->reported_err = true;9978 existing_suspend_scope->reported_err = true;
8948 }9979 }
8949 return irb->codegen->invalid_instruction;9980 return irb->codegen->invalid_inst_src;
8950 }9981 }
89519982
8952 IrInstruction *target_inst = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);9983 IrInstSrc *target_inst = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
8953 if (target_inst == irb->codegen->invalid_instruction)9984 if (target_inst == irb->codegen->invalid_inst_src)
8954 return irb->codegen->invalid_instruction;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);
8957 return ir_lval_wrap(irb, scope, await_inst, lval, result_loc);9988 return ir_lval_wrap(irb, scope, await_inst, lval, result_loc);
8958}9989}
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) {
8961 assert(node->type == NodeTypeSuspend);9992 assert(node->type == NodeTypeSuspend);
89629993
8963 ZigFn *fn_entry = exec_fn_entry(irb->exec);9994 ZigFn *fn_entry = exec_fn_entry(irb->exec);
8964 if (!fn_entry) {9995 if (!fn_entry) {
8965 add_node_error(irb->codegen, node, buf_sprintf("suspend outside function definition"));9996 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;
8967 }9998 }
8968 ScopeSuspend *existing_suspend_scope = get_scope_suspend(parent_scope);9999 ScopeSuspend *existing_suspend_scope = get_scope_suspend(parent_scope);
8969 if (existing_suspend_scope) {10000 if (existing_suspend_scope) {
...@@ -8972,21 +10003,21 @@ static IrInstruction *ir_gen_suspend(IrBuilder *irb, Scope *parent_scope, AstNod...@@ -8972,21 +10003,21 @@ static IrInstruction *ir_gen_suspend(IrBuilder *irb, Scope *parent_scope, AstNod
8972 add_error_note(irb->codegen, msg, existing_suspend_scope->base.source_node, buf_sprintf("other suspend block here"));10003 add_error_note(irb->codegen, msg, existing_suspend_scope->base.source_node, buf_sprintf("other suspend block here"));
8973 existing_suspend_scope->reported_err = true;10004 existing_suspend_scope->reported_err = true;
8974 }10005 }
8975 return irb->codegen->invalid_instruction;10006 return irb->codegen->invalid_inst_src;
8976 }10007 }
897710008
8978 IrInstructionSuspendBegin *begin = ir_build_suspend_begin(irb, parent_scope, node);10009 IrInstSrcSuspendBegin *begin = ir_build_suspend_begin_src(irb, parent_scope, node);
8979 if (node->data.suspend.block != nullptr) {10010 if (node->data.suspend.block != nullptr) {
8980 ScopeSuspend *suspend_scope = create_suspend_scope(irb->codegen, node, parent_scope);10011 ScopeSuspend *suspend_scope = create_suspend_scope(irb->codegen, node, parent_scope);
8981 Scope *child_scope = &suspend_scope->base;10012 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);
8983 ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, node->data.suspend.block, susp_res));10014 ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, node->data.suspend.block, susp_res));
8984 }10015 }
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));
8987}10018}
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,
8990 LVal lval, ResultLoc *result_loc)10021 LVal lval, ResultLoc *result_loc)
8991{10022{
8992 assert(scope);10023 assert(scope);
...@@ -9035,39 +10066,39 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop...@@ -9035,39 +10066,39 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
9035 return ir_gen_return(irb, scope, node, lval, result_loc);10066 return ir_gen_return(irb, scope, node, lval, result_loc);
9036 case NodeTypeFieldAccessExpr:10067 case NodeTypeFieldAccessExpr:
9037 {10068 {
9038 IrInstruction *ptr_instruction = ir_gen_field_access(irb, scope, node);10069 IrInstSrc *ptr_instruction = ir_gen_field_access(irb, scope, node);
9039 if (ptr_instruction == irb->codegen->invalid_instruction)10070 if (ptr_instruction == irb->codegen->invalid_inst_src)
9040 return ptr_instruction;10071 return ptr_instruction;
9041 if (lval == LValPtr)10072 if (lval == LValPtr)
9042 return ptr_instruction;10073 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);
9045 return ir_expr_wrap(irb, scope, load_ptr, result_loc);10076 return ir_expr_wrap(irb, scope, load_ptr, result_loc);
9046 }10077 }
9047 case NodeTypePtrDeref: {10078 case NodeTypePtrDeref: {
9048 AstNode *expr_node = node->data.ptr_deref_expr.target;10079 AstNode *expr_node = node->data.ptr_deref_expr.target;
9049 IrInstruction *value = ir_gen_node_extra(irb, expr_node, scope, lval, nullptr);10080 IrInstSrc *value = ir_gen_node_extra(irb, expr_node, scope, lval, nullptr);
9050 if (value == irb->codegen->invalid_instruction)10081 if (value == irb->codegen->invalid_inst_src)
9051 return value;10082 return value;
905210083
9053 // We essentially just converted any lvalue from &(x.*) to (&x).*;10084 // We essentially just converted any lvalue from &(x.*) to (&x).*;
9054 // this inhibits checking that x is a pointer later, so we directly10085 // this inhibits checking that x is a pointer later, so we directly
9055 // record whether the pointer check is needed10086 // 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);
9057 return ir_expr_wrap(irb, scope, un_op, result_loc);10088 return ir_expr_wrap(irb, scope, un_op, result_loc);
9058 }10089 }
9059 case NodeTypeUnwrapOptional: {10090 case NodeTypeUnwrapOptional: {
9060 AstNode *expr_node = node->data.unwrap_optional.expr;10091 AstNode *expr_node = node->data.unwrap_optional.expr;
906110092
9062 IrInstruction *maybe_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);10093 IrInstSrc *maybe_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
9063 if (maybe_ptr == irb->codegen->invalid_instruction)10094 if (maybe_ptr == irb->codegen->invalid_inst_src)
9064 return irb->codegen->invalid_instruction;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);
9067 if (lval == LValPtr)10098 if (lval == LValPtr)
9068 return unwrapped_ptr;10099 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);
9071 return ir_expr_wrap(irb, scope, load_ptr, result_loc);10102 return ir_expr_wrap(irb, scope, load_ptr, result_loc);
9072 }10103 }
9073 case NodeTypeBoolLiteral:10104 case NodeTypeBoolLiteral:
...@@ -9125,7 +10156,7 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop...@@ -9125,7 +10156,7 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
9125 case NodeTypeInferredArrayType:10156 case NodeTypeInferredArrayType:
9126 add_node_error(irb->codegen, node,10157 add_node_error(irb->codegen, node,
9127 buf_sprintf("inferred array size invalid here"));10158 buf_sprintf("inferred array size invalid here"));
9128 return irb->codegen->invalid_instruction;10159 return irb->codegen->invalid_inst_src;
9129 case NodeTypeVarFieldType:10160 case NodeTypeVarFieldType:
9130 return ir_lval_wrap(irb, scope,10161 return ir_lval_wrap(irb, scope,
9131 ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_var), lval, result_loc);10162 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) {...@@ -9139,7 +10170,7 @@ static ResultLoc *no_result_loc(void) {
9139 return &result_loc_none->base;10170 return &result_loc_none->base;
9140}10171}
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,
9143 ResultLoc *result_loc)10174 ResultLoc *result_loc)
9144{10175{
9145 if (result_loc == nullptr) {10176 if (result_loc == nullptr) {
...@@ -9156,8 +10187,8 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *sc...@@ -9156,8 +10187,8 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *sc
9156 } else {10187 } else {
9157 child_scope = &create_expr_scope(irb->codegen, node, scope)->base;10188 child_scope = &create_expr_scope(irb->codegen, node, scope)->base;
9158 }10189 }
9159 IrInstruction *result = ir_gen_node_raw(irb, node, child_scope, lval, result_loc);10190 IrInstSrc *result = ir_gen_node_raw(irb, node, child_scope, lval, result_loc);
9160 if (result == irb->codegen->invalid_instruction) {10191 if (result == irb->codegen->invalid_inst_src) {
9161 if (irb->exec->first_err_trace_msg == nullptr) {10192 if (irb->exec->first_err_trace_msg == nullptr) {
9162 irb->exec->first_err_trace_msg = irb->codegen->trace_err;10193 irb->exec->first_err_trace_msg = irb->codegen->trace_err;
9163 }10194 }
...@@ -9165,11 +10196,22 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *sc...@@ -9165,11 +10196,22 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *sc
9165 return result;10196 return result;
9166}10197}
916710198
9168static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope) {10199static IrInstSrc *ir_gen_node(IrBuilderSrc *irb, AstNode *node, Scope *scope) {
9169 return ir_gen_node_extra(irb, node, scope, LValNone, nullptr);10200 return ir_gen_node_extra(irb, node, scope, LValNone, nullptr);
9170}10201}
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) {
9173 if (exec->first_err_trace_msg != nullptr)10215 if (exec->first_err_trace_msg != nullptr)
9174 return;10216 return;
917510217
...@@ -9183,24 +10225,25 @@ static void invalidate_exec(IrExecutable *exec, ErrorMsg *msg) {...@@ -9183,24 +10225,25 @@ static void invalidate_exec(IrExecutable *exec, ErrorMsg *msg) {
9183 invalidate_exec(exec->source_exec, msg);10225 invalidate_exec(exec->source_exec, msg);
9184}10226}
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) {
9187 assert(node->owner);10230 assert(node->owner);
918810231
9189 IrBuilder ir_builder = {0};10232 IrBuilderSrc ir_builder = {0};
9190 IrBuilder *irb = &ir_builder;10233 IrBuilderSrc *irb = &ir_builder;
919110234
9192 irb->codegen = codegen;10235 irb->codegen = codegen;
9193 irb->exec = ir_executable;10236 irb->exec = ir_executable;
9194 irb->main_block_node = node;10237 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");
9197 ir_set_cursor_at_end_and_append_block(irb, entry_block);10240 ir_set_cursor_at_end_and_append_block(irb, entry_block);
9198 // Entry block gets a reference because we enter it to begin.10241 // Entry block gets a reference because we enter it to begin.
9199 ir_ref_bb(irb->current_basic_block);10242 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)
9204 return false;10247 return false;
920510248
9206 if (irb->exec->first_err_trace_msg != nullptr) {10249 if (irb->exec->first_err_trace_msg != nullptr) {
...@@ -9209,9 +10252,9 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec...@@ -9209,9 +10252,9 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
9209 }10252 }
921010253
9211 if (!instr_is_unreachable(result)) {10254 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));
9213 // no need for save_err_ret_addr because this cannot return error10256 // 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));
9215 }10258 }
921610259
9217 return true;10260 return true;
...@@ -9220,7 +10263,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec...@@ -9220,7 +10263,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
9220bool ir_gen_fn(CodeGen *codegen, ZigFn *fn_entry) {10263bool ir_gen_fn(CodeGen *codegen, ZigFn *fn_entry) {
9221 assert(fn_entry);10264 assert(fn_entry);
922210265
9223 IrExecutable *ir_executable = fn_entry->ir_executable;10266 IrExecutableSrc *ir_executable = fn_entry->ir_executable;
9224 AstNode *body_node = fn_entry->body_node;10267 AstNode *body_node = fn_entry->body_node;
922510268
9226 assert(fn_entry->child_scope);10269 assert(fn_entry->child_scope);
...@@ -9228,14 +10271,21 @@ bool ir_gen_fn(CodeGen *codegen, ZigFn *fn_entry) {...@@ -9228,14 +10271,21 @@ bool ir_gen_fn(CodeGen *codegen, ZigFn *fn_entry) {
9228 return ir_gen(codegen, body_node, fn_entry->child_scope, ir_executable);10271 return ir_gen(codegen, body_node, fn_entry->child_scope, ir_executable);
9229}10272}
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) {
9232 if (!exec || !exec->source_node || limit < 0) return;10282 if (!exec || !exec->source_node || limit < 0) return;
9233 add_error_note(codegen, err_msg, exec->source_node, buf_sprintf("called from here"));10283 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);
9236}10286}
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) {
9239 ErrorMsg *err_msg = add_node_error(codegen, source_node, msg);10289 ErrorMsg *err_msg = add_node_error(codegen, source_node, msg);
9240 invalidate_exec(exec, err_msg);10290 invalidate_exec(exec, err_msg);
9241 if (exec->parent_exec) {10291 if (exec->parent_exec) {
...@@ -9244,26 +10294,40 @@ static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNo...@@ -9244,26 +10294,40 @@ static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNo
9244 return err_msg;10294 return err_msg;
9245}10295}
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
9247static ErrorMsg *ir_add_error_node(IrAnalyze *ira, AstNode *source_node, Buf *msg) {10306static 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);
9249}10308}
925010309
9251static ErrorMsg *opt_ir_add_error_node(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, Buf *msg) {10310static ErrorMsg *opt_ir_add_error_node(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, Buf *msg) {
9252 if (ira != nullptr)10311 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);
9254 else10313 else
9255 return add_node_error(codegen, source_node, msg);10314 return add_node_error(codegen, source_node, msg);
9256}10315}
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) {
9259 return ir_add_error_node(ira, source_instruction->source_node, msg);10318 return ir_add_error_node(ira, source_instruction->source_node, msg);
9260}10319}
926110320
9262static void ir_assert(bool ok, IrInstruction *source_instruction) {10321static void ir_assert(bool ok, IrInst *source_instruction) {
9263 if (ok) return;10322 if (ok) return;
9264 src_assert(ok, source_instruction->source_node);10323 src_assert(ok, source_instruction->source_node);
9265}10324}
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
9267// This function takes a comptime ptr and makes the child const value conform to the type10331// This function takes a comptime ptr and makes the child const value conform to the type
9268// described by the pointer.10332// described by the pointer.
9269static Error eval_comptime_ptr_reinterpret(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,10333static 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...@@ -9309,43 +10373,43 @@ ZigValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ZigValue *const_va
9309 return val;10373 return val;
9310}10374}
931110375
9312static ZigValue *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec) {10376static ZigValue *ir_exec_const_result(CodeGen *codegen, IrExecutableGen *exec) {
9313 IrBasicBlock *bb = exec->basic_block_list.at(0);10377 IrBasicBlockGen *bb = exec->basic_block_list.at(0);
9314 for (size_t i = 0; i < bb->instruction_list.length; i += 1) {10378 for (size_t i = 0; i < bb->instruction_list.length; i += 1) {
9315 IrInstruction *instruction = bb->instruction_list.at(i);10379 IrInstGen *instruction = bb->instruction_list.at(i);
9316 if (instruction->id == IrInstructionIdReturn) {10380 if (instruction->id == IrInstGenIdReturn) {
9317 IrInstructionReturn *ret_inst = (IrInstructionReturn *)instruction;10381 IrInstGenReturn *ret_inst = (IrInstGenReturn *)instruction;
9318 IrInstruction *operand = ret_inst->operand;10382 IrInstGen *operand = ret_inst->operand;
9319 if (operand->value->special == ConstValSpecialRuntime) {10383 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,
9321 buf_sprintf("unable to evaluate constant expression"));10385 buf_sprintf("unable to evaluate constant expression"));
9322 return codegen->invalid_instruction->value;10386 return codegen->invalid_inst_gen->value;
9323 }10387 }
9324 return operand->value;10388 return operand->value;
9325 } else if (ir_has_side_effects(instruction)) {10389 } else if (ir_inst_gen_has_side_effects(instruction)) {
9326 if (instr_is_comptime(instruction)) {10390 if (instr_is_comptime(instruction)) {
9327 switch (instruction->id) {10391 switch (instruction->id) {
9328 case IrInstructionIdUnwrapErrPayload:10392 case IrInstGenIdUnwrapErrPayload:
9329 case IrInstructionIdUnionFieldPtr:10393 case IrInstGenIdUnionFieldPtr:
9330 continue;10394 continue;
9331 default:10395 default:
9332 break;10396 break;
9333 }10397 }
9334 }10398 }
9335 if (get_scope_typeof(instruction->scope) != nullptr) {10399 if (get_scope_typeof(instruction->base.scope) != nullptr) {
9336 // doesn't count, it's inside a @TypeOf()10400 // doesn't count, it's inside a @TypeOf()
9337 continue;10401 continue;
9338 }10402 }
9339 exec_add_error_node(codegen, exec, instruction->source_node,10403 exec_add_error_node_gen(codegen, exec, instruction->base.source_node,
9340 buf_sprintf("unable to evaluate constant expression"));10404 buf_sprintf("unable to evaluate constant expression"));
9341 return codegen->invalid_instruction->value;10405 return codegen->invalid_inst_gen->value;
9342 }10406 }
9343 }10407 }
9344 zig_unreachable();10408 zig_unreachable();
9345}10409}
934610410
9347static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInstruction *source_instruction) {10411static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInst* source_instruction) {
9348 if (ir_should_inline(ira->new_irb.exec, source_instruction->scope)) {10412 if (ir_should_inline(ira->old_irb.exec, source_instruction->scope)) {
9349 ir_add_error(ira, source_instruction, buf_sprintf("unable to evaluate constant expression"));10413 ir_add_error(ira, source_instruction, buf_sprintf("unable to evaluate constant expression"));
9350 return false;10414 return false;
9351 }10415 }
...@@ -10079,7 +11143,7 @@ void float_read_ieee597(ZigValue *val, uint8_t *buf, bool is_big_endian) {...@@ -10079,7 +11143,7 @@ void float_read_ieee597(ZigValue *val, uint8_t *buf, bool is_big_endian) {
10079 }11143 }
10080}11144}
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,
10083 bool explicit_cast)11147 bool explicit_cast)
10084{11148{
10085 if (type_is_invalid(other_type)) {11149 if (type_is_invalid(other_type)) {
...@@ -10173,7 +11237,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc...@@ -10173,7 +11237,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
10173 }11237 }
10174 Buf *val_buf = buf_alloc();11238 Buf *val_buf = buf_alloc();
10175 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);11239 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,
10177 buf_sprintf("integer value %s has no representation in type '%s'",11241 buf_sprintf("integer value %s has no representation in type '%s'",
10178 buf_ptr(val_buf),11242 buf_ptr(val_buf),
10179 buf_ptr(&other_type->name)));11243 buf_ptr(&other_type->name)));
...@@ -10268,7 +11332,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc...@@ -10268,7 +11332,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
10268 }11332 }
10269 Buf *val_buf = buf_alloc();11333 Buf *val_buf = buf_alloc();
10270 float_append_buf(val_buf, const_val);11334 float_append_buf(val_buf, const_val);
10271 ir_add_error(ira, instruction,11335 ir_add_error_node(ira, instruction->base.source_node,
10272 buf_sprintf("cast of value %s to type '%s' loses information",11336 buf_sprintf("cast of value %s to type '%s' loses information",
10273 buf_ptr(val_buf),11337 buf_ptr(val_buf),
10274 buf_ptr(&other_type->name)));11338 buf_ptr(&other_type->name)));
...@@ -10277,7 +11341,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc...@@ -10277,7 +11341,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
10277 if (!other_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) {11341 if (!other_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) {
10278 Buf *val_buf = buf_alloc();11342 Buf *val_buf = buf_alloc();
10279 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);11343 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,
10281 buf_sprintf("cannot cast negative value %s to unsigned integer type '%s'",11345 buf_sprintf("cannot cast negative value %s to unsigned integer type '%s'",
10282 buf_ptr(val_buf),11346 buf_ptr(val_buf),
10283 buf_ptr(&other_type->name)));11347 buf_ptr(&other_type->name)));
...@@ -10298,7 +11362,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc...@@ -10298,7 +11362,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
10298 if (!child_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) {11362 if (!child_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) {
10299 Buf *val_buf = buf_alloc();11363 Buf *val_buf = buf_alloc();
10300 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);11364 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,
10302 buf_sprintf("cannot cast negative value %s to unsigned integer type '%s'",11366 buf_sprintf("cannot cast negative value %s to unsigned integer type '%s'",
10303 buf_ptr(val_buf),11367 buf_ptr(val_buf),
10304 buf_ptr(&child_type->name)));11368 buf_ptr(&child_type->name)));
...@@ -10321,7 +11385,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc...@@ -10321,7 +11385,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
10321 Buf *val_buf = buf_alloc();11385 Buf *val_buf = buf_alloc();
10322 float_append_buf(val_buf, const_val);11386 float_append_buf(val_buf, const_val);
1032311387
10324 ir_add_error(ira, instruction,11388 ir_add_error_node(ira, instruction->base.source_node,
10325 buf_sprintf("fractional component prevents float value %s from being casted to type '%s'",11389 buf_sprintf("fractional component prevents float value %s from being casted to type '%s'",
10326 buf_ptr(val_buf),11390 buf_ptr(val_buf),
10327 buf_ptr(&other_type->name)));11391 buf_ptr(&other_type->name)));
...@@ -10351,7 +11415,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc...@@ -10351,7 +11415,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
10351 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);11415 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);
10352 }11416 }
1035311417
10354 ir_add_error(ira, instruction,11418 ir_add_error_node(ira, instruction->base.source_node,
10355 buf_sprintf("%s value %s cannot be coerced to type '%s'",11419 buf_sprintf("%s value %s cannot be coerced to type '%s'",
10356 num_lit_str,11420 num_lit_str,
10357 buf_ptr(val_buf),11421 buf_ptr(val_buf),
...@@ -10805,11 +11869,11 @@ static void update_errors_helper(CodeGen *g, ErrorTableEntry ***errors, size_t *...@@ -10805,11 +11869,11 @@ static void update_errors_helper(CodeGen *g, ErrorTableEntry ***errors, size_t *
10805}11869}
1080611870
10807static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigType *expected_type,11871static 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)
10809{11873{
10810 Error err;11874 Error err;
10811 assert(instruction_count >= 1);11875 assert(instruction_count >= 1);
10812 IrInstruction *prev_inst;11876 IrInstGen *prev_inst;
10813 size_t i = 0;11877 size_t i = 0;
10814 for (;;) {11878 for (;;) {
10815 prev_inst = instructions[i];11879 prev_inst = instructions[i];
...@@ -10829,7 +11893,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -10829,7 +11893,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
10829 size_t errors_count = 0;11893 size_t errors_count = 0;
10830 ZigType *err_set_type = nullptr;11894 ZigType *err_set_type = nullptr;
10831 if (prev_inst->value->type->id == ZigTypeIdErrorSet) {11895 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)) {
10833 return ira->codegen->builtin_types.entry_invalid;11897 return ira->codegen->builtin_types.entry_invalid;
10834 }11898 }
10835 if (type_is_global_error_set(prev_inst->value->type)) {11899 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...@@ -10849,7 +11913,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
10849 bool any_are_null = (prev_inst->value->type->id == ZigTypeIdNull);11913 bool any_are_null = (prev_inst->value->type->id == ZigTypeIdNull);
10850 bool convert_to_const_slice = false;11914 bool convert_to_const_slice = false;
10851 for (; i < instruction_count; i += 1) {11915 for (; i < instruction_count; i += 1) {
10852 IrInstruction *cur_inst = instructions[i];11916 IrInstGen *cur_inst = instructions[i];
10853 ZigType *cur_type = cur_inst->value->type;11917 ZigType *cur_type = cur_inst->value->type;
10854 ZigType *prev_type = prev_inst->value->type;11918 ZigType *prev_type = prev_inst->value->type;
1085511919
...@@ -10871,14 +11935,14 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -10871,14 +11935,14 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
10871 }11935 }
1087211936
10873 if (prev_type->id == ZigTypeIdErrorSet) {11937 if (prev_type->id == ZigTypeIdErrorSet) {
10874 ir_assert(err_set_type != nullptr, prev_inst);11938 ir_assert_gen(err_set_type != nullptr, prev_inst);
10875 if (cur_type->id == ZigTypeIdErrorSet) {11939 if (cur_type->id == ZigTypeIdErrorSet) {
10876 if (type_is_global_error_set(err_set_type)) {11940 if (type_is_global_error_set(err_set_type)) {
10877 continue;11941 continue;
10878 }11942 }
10879 bool allow_infer = cur_type->data.error_set.infer_fn != nullptr &&11943 bool allow_infer = cur_type->data.error_set.infer_fn != nullptr &&
10880 cur_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry;11944 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)) {
10882 return ira->codegen->builtin_types.entry_invalid;11946 return ira->codegen->builtin_types.entry_invalid;
10883 }11947 }
10884 if (!allow_infer && type_is_global_error_set(cur_type)) {11948 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...@@ -10946,7 +12010,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
10946 ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type;12010 ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type;
10947 bool allow_infer = cur_err_set_type->data.error_set.infer_fn != nullptr &&12011 bool allow_infer = cur_err_set_type->data.error_set.infer_fn != nullptr &&
10948 cur_err_set_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry;12012 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)) {
10950 return ira->codegen->builtin_types.entry_invalid;12014 return ira->codegen->builtin_types.entry_invalid;
10951 }12015 }
10952 if (!allow_infer && type_is_global_error_set(cur_err_set_type)) {12016 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...@@ -11001,7 +12065,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
11001 if (cur_type->id == ZigTypeIdErrorSet) {12065 if (cur_type->id == ZigTypeIdErrorSet) {
11002 bool allow_infer = cur_type->data.error_set.infer_fn != nullptr &&12066 bool allow_infer = cur_type->data.error_set.infer_fn != nullptr &&
11003 cur_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry;12067 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)) {
11005 return ira->codegen->builtin_types.entry_invalid;12069 return ira->codegen->builtin_types.entry_invalid;
11006 }12070 }
11007 if (!allow_infer && type_is_global_error_set(cur_type)) {12071 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...@@ -11024,7 +12088,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
11024 err_set_type = cur_type;12088 err_set_type = cur_type;
11025 }12089 }
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)) {
11028 return ira->codegen->builtin_types.entry_invalid;12092 return ira->codegen->builtin_types.entry_invalid;
11029 }12093 }
1103012094
...@@ -11087,11 +12151,11 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -11087,11 +12151,11 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
11087 bool allow_infer_cur = cur_err_set_type->data.error_set.infer_fn != nullptr &&12151 bool allow_infer_cur = cur_err_set_type->data.error_set.infer_fn != nullptr &&
11088 cur_err_set_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry;12152 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)) {
11091 return ira->codegen->builtin_types.entry_invalid;12155 return ira->codegen->builtin_types.entry_invalid;
11092 }12156 }
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)) {
11095 return ira->codegen->builtin_types.entry_invalid;12159 return ira->codegen->builtin_types.entry_invalid;
11096 }12160 }
1109712161
...@@ -11268,7 +12332,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -11268,7 +12332,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
11268 ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type;12332 ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type;
11269 bool allow_infer = cur_err_set_type->data.error_set.infer_fn != nullptr &&12333 bool allow_infer = cur_err_set_type->data.error_set.infer_fn != nullptr &&
11270 cur_err_set_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry;12334 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)) {
11272 return ira->codegen->builtin_types.entry_invalid;12336 return ira->codegen->builtin_types.entry_invalid;
11273 }12337 }
11274 if ((!allow_infer && type_is_global_error_set(cur_err_set_type)) ||12338 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...@@ -11463,9 +12527,9 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
11463 ErrorMsg *msg = ir_add_error_node(ira, source_node,12527 ErrorMsg *msg = ir_add_error_node(ira, source_node,
11464 buf_sprintf("incompatible types: '%s' and '%s'",12528 buf_sprintf("incompatible types: '%s' and '%s'",
11465 buf_ptr(&prev_type->name), buf_ptr(&cur_type->name)));12529 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,
11467 buf_sprintf("type '%s' here", buf_ptr(&prev_type->name)));12531 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,
11469 buf_sprintf("type '%s' here", buf_ptr(&cur_type->name)));12533 buf_sprintf("type '%s' here", buf_ptr(&cur_type->name)));
1147012534
11471 return ira->codegen->builtin_types.entry_invalid;12535 return ira->codegen->builtin_types.entry_invalid;
...@@ -11535,7 +12599,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -11535,7 +12599,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
11535 }12599 }
11536}12600}
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,
11539 CastOp cast_op,12603 CastOp cast_op,
11540 ZigValue *other_val, ZigType *other_type,12604 ZigValue *other_val, ZigType *other_type,
11541 ZigValue *const_val, ZigType *new_type)12605 ZigValue *const_val, ZigType *new_type)
...@@ -11635,58 +12699,56 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_...@@ -11635,58 +12699,56 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_
11635 return true;12699 return true;
11636}12700}
1163712701
11638static IrInstruction *ir_const(IrAnalyze *ira, IrInstruction *old_instruction, ZigType *ty) {12702static IrInstGen *ir_const(IrAnalyze *ira, IrInst *inst, ZigType *ty) {
11639 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,12703 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
11640 old_instruction->scope, old_instruction->source_node);12704 inst->scope, inst->source_node);
11641 IrInstruction *new_instruction = &const_instruction->base;12705 IrInstGen *new_instruction = &const_instruction->base;
11642 new_instruction->value->type = ty;12706 new_instruction->value->type = ty;
11643 new_instruction->value->special = ConstValSpecialStatic;12707 new_instruction->value->special = ConstValSpecialStatic;
11644 return new_instruction;12708 return new_instruction;
11645}12709}
1164612710
11647static IrInstruction *ir_const_noval(IrAnalyze *ira, IrInstruction *old_instruction) {12711static IrInstGen *ir_const_noval(IrAnalyze *ira, IrInst *old_instruction) {
11648 IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(&ira->new_irb,12712 IrInstGenConst *const_instruction = ir_create_inst_noval<IrInstGenConst>(&ira->new_irb,
11649 old_instruction->scope, old_instruction->source_node);12713 old_instruction->scope, old_instruction->source_node);
11650 return &const_instruction->base;12714 return &const_instruction->base;
11651}12715}
1165212716
11653// This function initializes the new IrInstruction with the provided ZigValue,12717// This function initializes the new IrInstGen with the provided ZigValue,
11654// rather than creating a new one.12718// rather than creating a new one.
11655static IrInstruction *ir_const_move(IrAnalyze *ira, IrInstruction *old_instruction, ZigValue *val) {12719static IrInstGen *ir_const_move(IrAnalyze *ira, IrInst *old_instruction, ZigValue *val) {
11656 IrInstruction *result = ir_const_noval(ira, old_instruction);12720 IrInstGen *result = ir_const_noval(ira, old_instruction);
11657 result->value = val;12721 result->value = val;
11658 return result;12722 return result;
11659}12723}
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,
11662 ZigType *wanted_type, CastOp cast_op)12726 ZigType *wanted_type, CastOp cast_op)
11663{12727{
11664 if (instr_is_comptime(value) || !type_has_bits(wanted_type)) {12728 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);
11666 if (!eval_const_expr_implicit_cast(ira, source_instr, cast_op, value->value, value->value->type,12730 if (!eval_const_expr_implicit_cast(ira, source_instr, cast_op, value->value, value->value->type,
11667 result->value, wanted_type))12731 result->value, wanted_type))
11668 {12732 {
11669 return ira->codegen->invalid_instruction;12733 return ira->codegen->invalid_inst_gen;
11670 }12734 }
11671 return result;12735 return result;
11672 } else {12736 } else {
11673 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type, value, cast_op);12737 return ir_build_cast(ira, source_instr, wanted_type, value, cast_op);
11674 result->value->type = wanted_type;
11675 return result;
11676 }12738 }
11677}12739}
1167812740
11679static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrInstruction *source_instr,12741static IrInstGen *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrInst* source_instr,
11680 IrInstruction *value, ZigType *wanted_type)12742 IrInstGen *value, ZigType *wanted_type)
11681{12743{
11682 assert(value->value->type->id == ZigTypeIdPointer);12744 ir_assert(value->value->type->id == ZigTypeIdPointer, source_instr);
1168312745
11684 Error err;12746 Error err;
1168512747
11686 if ((err = type_resolve(ira->codegen, value->value->type->data.pointer.child_type,12748 if ((err = type_resolve(ira->codegen, value->value->type->data.pointer.child_type,
11687 ResolveStatusAlignmentKnown)))12749 ResolveStatusAlignmentKnown)))
11688 {12750 {
11689 return ira->codegen->invalid_instruction;12751 return ira->codegen->invalid_inst_gen;
11690 }12752 }
1169112753
11692 wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, value->value->type));12754 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,...@@ -11694,9 +12756,9 @@ static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira,
11694 if (instr_is_comptime(value)) {12756 if (instr_is_comptime(value)) {
11695 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, value->value, source_instr->source_node);12757 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, value->value, source_instr->source_node);
11696 if (pointee == nullptr)12758 if (pointee == nullptr)
11697 return ira->codegen->invalid_instruction;12759 return ira->codegen->invalid_inst_gen;
11698 if (pointee->special != ConstValSpecialRuntime) {12760 if (pointee->special != ConstValSpecialRuntime) {
11699 IrInstruction *result = ir_const(ira, source_instr, wanted_type);12761 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
11700 result->value->data.x_ptr.special = ConstPtrSpecialBaseArray;12762 result->value->data.x_ptr.special = ConstPtrSpecialBaseArray;
11701 result->value->data.x_ptr.mut = value->value->data.x_ptr.mut;12763 result->value->data.x_ptr.mut = value->value->data.x_ptr.mut;
11702 result->value->data.x_ptr.data.base_array.array_val = pointee;12764 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,...@@ -11705,21 +12767,18 @@ static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira,
11705 }12767 }
11706 }12768 }
1170712769
11708 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node,12770 return ir_build_cast(ira, source_instr, wanted_type, value, CastOpBitCast);
11709 wanted_type, value, CastOpBitCast);
11710 result->value->type = wanted_type;
11711 return result;
11712}12771}
1171312772
11714static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruction *source_instr,12773static IrInstGen *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInst* source_instr,
11715 IrInstruction *array_ptr, ZigType *wanted_type, ResultLoc *result_loc)12774 IrInstGen *array_ptr, ZigType *wanted_type, ResultLoc *result_loc)
11716{12775{
11717 Error err;12776 Error err;
1171812777
11719 if ((err = type_resolve(ira->codegen, array_ptr->value->type->data.pointer.child_type,12778 if ((err = type_resolve(ira->codegen, array_ptr->value->type->data.pointer.child_type,
11720 ResolveStatusAlignmentKnown)))12779 ResolveStatusAlignmentKnown)))
11721 {12780 {
11722 return ira->codegen->invalid_instruction;12781 return ira->codegen->invalid_inst_gen;
11723 }12782 }
1172412783
11725 wanted_type = adjust_slice_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, array_ptr->value->type));12784 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...@@ -11727,14 +12786,14 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc
11727 if (instr_is_comptime(array_ptr)) {12786 if (instr_is_comptime(array_ptr)) {
11728 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, array_ptr->value, source_instr->source_node);12787 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, array_ptr->value, source_instr->source_node);
11729 if (pointee == nullptr)12788 if (pointee == nullptr)
11730 return ira->codegen->invalid_instruction;12789 return ira->codegen->invalid_inst_gen;
11731 if (pointee->special != ConstValSpecialRuntime) {12790 if (pointee->special != ConstValSpecialRuntime) {
11732 assert(array_ptr->value->type->id == ZigTypeIdPointer);12791 assert(array_ptr->value->type->id == ZigTypeIdPointer);
11733 ZigType *array_type = array_ptr->value->type->data.pointer.child_type;12792 ZigType *array_type = array_ptr->value->type->data.pointer.child_type;
11734 assert(is_slice(wanted_type));12793 assert(is_slice(wanted_type));
11735 bool is_const = wanted_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const;12794 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);
11738 init_const_slice(ira->codegen, result->value, pointee, 0, array_type->data.array.len, is_const);12797 init_const_slice(ira->codegen, result->value, pointee, 0, array_type->data.array.len, is_const);
11739 result->value->data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = array_ptr->value->data.x_ptr.mut;12798 result->value->data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = array_ptr->value->data.x_ptr.mut;
11740 result->value->type = wanted_type;12799 result->value->type = wanted_type;
...@@ -11743,32 +12802,34 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc...@@ -11743,32 +12802,34 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc
11743 }12802 }
1174412803
11745 if (result_loc == nullptr) result_loc = no_result_loc();12804 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,
11747 false, true);12806 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 {
11749 return result_loc_inst;12810 return result_loc_inst;
11750 }12811 }
11751 return ir_build_ptr_of_array_to_slice(ira, source_instr, wanted_type, array_ptr, result_loc_inst);12812 return ir_build_ptr_of_array_to_slice(ira, source_instr, wanted_type, array_ptr, result_loc_inst);
11752}12813}
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) {
11755 assert(old_bb);12816 assert(old_bb);
1175612817
11757 if (old_bb->other) {12818 if (old_bb->child) {
11758 if (ref_old_instruction == nullptr || old_bb->other->ref_instruction != ref_old_instruction) {12819 if (ref_old_instruction == nullptr || old_bb->child->ref_instruction != ref_old_instruction) {
11759 return old_bb->other;12820 return old_bb->child;
11760 }12821 }
11761 }12822 }
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);
11764 new_bb->ref_instruction = ref_old_instruction;12825 new_bb->ref_instruction = ref_old_instruction;
1176512826
11766 return new_bb;12827 return new_bb;
11767}12828}
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) {
11770 assert(ref_old_instruction != nullptr);12831 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);
11772 if (new_bb->must_be_comptime_source_instr) {12833 if (new_bb->must_be_comptime_source_instr) {
11773 ErrorMsg *msg = ir_add_error(ira, ref_old_instruction,12834 ErrorMsg *msg = ir_add_error(ira, ref_old_instruction,
11774 buf_sprintf("control flow attempts to use compile-time variable at runtime"));12835 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,...@@ -11779,24 +12840,24 @@ static IrBasicBlock *ir_get_new_bb_runtime(IrAnalyze *ira, IrBasicBlock *old_bb,
11779 return new_bb;12840 return new_bb;
11780}12841}
1178112842
11782static void ir_start_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrBasicBlock *const_predecessor_bb) {12843static void ir_start_bb(IrAnalyze *ira, IrBasicBlockSrc *old_bb, IrBasicBlockSrc *const_predecessor_bb) {
11783 ir_assert(!old_bb->suspended, (old_bb->instruction_list.length != 0) ? old_bb->instruction_list.at(0) : nullptr);12844 ir_assert(!old_bb->suspended, (old_bb->instruction_list.length != 0) ? &old_bb->instruction_list.at(0)->base : nullptr);
11784 ira->instruction_index = 0;12845 ira->instruction_index = 0;
11785 ira->old_irb.current_basic_block = old_bb;12846 ira->old_irb.current_basic_block = old_bb;
11786 ira->const_predecessor_bb = const_predecessor_bb;12847 ira->const_predecessor_bb = const_predecessor_bb;
11787 ira->old_bb_index = old_bb->index;12848 ira->old_bb_index = old_bb->index;
11788}12849}
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,
11791 IrSuspendPosition *suspend_pos)12852 IrSuspendPosition *suspend_pos)
11792{12853{
11793 if (ira->codegen->verbose_ir) {12854 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",
11795 ira->old_irb.current_basic_block->name_hint,12856 ira->old_irb.current_basic_block->name_hint,
11796 ira->old_irb.current_basic_block->debug_id,12857 ira->old_irb.current_basic_block->debug_id,
11797 ira->old_irb.exec->basic_block_list.at(ira->old_bb_index)->name_hint,12858 ira->old_irb.exec->basic_block_list.at(ira->old_bb_index)->name_hint,
11798 ira->old_irb.exec->basic_block_list.at(ira->old_bb_index)->debug_id,12859 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,
11800 ira->old_bb_index, ira->instruction_index);12861 ira->old_bb_index, ira->instruction_index);
11801 }12862 }
11802 suspend_pos->basic_block_index = ira->old_bb_index;12863 suspend_pos->basic_block_index = ira->old_bb_index;
...@@ -11811,13 +12872,13 @@ static IrInstruction *ira_suspend(IrAnalyze *ira, IrInstruction *old_instruction...@@ -11811,13 +12872,13 @@ static IrInstruction *ira_suspend(IrAnalyze *ira, IrInstruction *old_instruction
11811 assert(ira->old_irb.current_basic_block == next_bb);12872 assert(ira->old_irb.current_basic_block == next_bb);
11812 ira->instruction_index = 0;12873 ira->instruction_index = 0;
11813 ira->const_predecessor_bb = nullptr;12874 ira->const_predecessor_bb = nullptr;
11814 next_bb->other = ir_get_new_bb_runtime(ira, next_bb, old_instruction);12875 next_bb->child = ir_get_new_bb_runtime(ira, next_bb, old_instruction);
11815 ira->new_irb.current_basic_block = next_bb->other;12876 ira->new_irb.current_basic_block = next_bb->child;
11816 }12877 }
11817 return ira->codegen->unreach_instruction;12878 return ira->codegen->unreach_instruction;
11818}12879}
1181912880
11820static IrInstruction *ira_resume(IrAnalyze *ira) {12881static IrInstGen *ira_resume(IrAnalyze *ira) {
11821 IrSuspendPosition pos = ira->resume_stack.pop();12882 IrSuspendPosition pos = ira->resume_stack.pop();
11822 if (ira->codegen->verbose_ir) {12883 if (ira->codegen->verbose_ir) {
11823 fprintf(stderr, "resume (%zu,%zu) ", pos.basic_block_index, pos.instruction_index);12884 fprintf(stderr, "resume (%zu,%zu) ", pos.basic_block_index, pos.instruction_index);
...@@ -11830,12 +12891,12 @@ static IrInstruction *ira_resume(IrAnalyze *ira) {...@@ -11830,12 +12891,12 @@ static IrInstruction *ira_resume(IrAnalyze *ira) {
11830 ira->instruction_index = pos.instruction_index;12891 ira->instruction_index = pos.instruction_index;
11831 assert(pos.instruction_index < ira->old_irb.current_basic_block->instruction_list.length);12892 assert(pos.instruction_index < ira->old_irb.current_basic_block->instruction_list.length);
11832 if (ira->codegen->verbose_ir) {12893 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,
11834 ira->old_irb.current_basic_block->debug_id,12895 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);
11836 }12897 }
11837 ira->const_predecessor_bb = nullptr;12898 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;
11839 assert(ira->new_irb.current_basic_block != nullptr);12900 assert(ira->new_irb.current_basic_block != nullptr);
11840 return ira->codegen->unreach_instruction;12901 return ira->codegen->unreach_instruction;
11841}12902}
...@@ -11846,8 +12907,8 @@ static void ir_start_next_bb(IrAnalyze *ira) {...@@ -11846,8 +12907,8 @@ static void ir_start_next_bb(IrAnalyze *ira) {
11846 bool need_repeat = true;12907 bool need_repeat = true;
11847 for (;;) {12908 for (;;) {
11848 while (ira->old_bb_index < ira->old_irb.exec->basic_block_list.length) {12909 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);12910 IrBasicBlockSrc *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) {12911 if (old_bb->child == nullptr && old_bb->suspend_instruction_ref == nullptr) {
11851 ira->old_bb_index += 1;12912 ira->old_bb_index += 1;
11852 continue;12913 continue;
11853 }12914 }
...@@ -11855,8 +12916,8 @@ static void ir_start_next_bb(IrAnalyze *ira) {...@@ -11855,8 +12916,8 @@ static void ir_start_next_bb(IrAnalyze *ira) {
11855 // if it's a suspended block,12916 // if it's a suspended block,
11856 // then skip it12917 // then skip it
11857 if (old_bb->suspended ||12918 if (old_bb->suspended ||
11858 (old_bb->other != nullptr && old_bb->other->instruction_list.length != 0) ||12919 (old_bb->child != nullptr && old_bb->child->instruction_list.length != 0) ||
11859 (old_bb->other != nullptr && old_bb->other->already_appended))12920 (old_bb->child != nullptr && old_bb->child->already_appended))
11860 {12921 {
11861 ira->old_bb_index += 1;12922 ira->old_bb_index += 1;
11862 continue;12923 continue;
...@@ -11870,10 +12931,10 @@ static void ir_start_next_bb(IrAnalyze *ira) {...@@ -11870,10 +12931,10 @@ static void ir_start_next_bb(IrAnalyze *ira) {
11870 return;12931 return;
11871 }12932 }
1187212933
11873 if (old_bb->other == nullptr) {12934 if (old_bb->child == nullptr) {
11874 old_bb->other = ir_get_new_bb_runtime(ira, old_bb, old_bb->suspend_instruction_ref);12935 old_bb->child = ir_get_new_bb_runtime(ira, old_bb, old_bb->suspend_instruction_ref);
11875 }12936 }
11876 ira->new_irb.current_basic_block = old_bb->other;12937 ira->new_irb.current_basic_block = old_bb->child;
11877 ir_start_bb(ira, old_bb, nullptr);12938 ir_start_bb(ira, old_bb, nullptr);
11878 return;12939 return;
11879 }12940 }
...@@ -11893,16 +12954,16 @@ static void ir_finish_bb(IrAnalyze *ira) {...@@ -11893,16 +12954,16 @@ static void ir_finish_bb(IrAnalyze *ira) {
11893 if (!ira->new_irb.current_basic_block->already_appended) {12954 if (!ira->new_irb.current_basic_block->already_appended) {
11894 ira->new_irb.current_basic_block->already_appended = true;12955 ira->new_irb.current_basic_block->already_appended = true;
11895 if (ira->codegen->verbose_ir) {12956 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,
11897 ira->new_irb.current_basic_block->debug_id);12958 ira->new_irb.current_basic_block->debug_id);
11898 }12959 }
11899 ira->new_irb.exec->basic_block_list.append(ira->new_irb.current_basic_block);12960 ira->new_irb.exec->basic_block_list.append(ira->new_irb.current_basic_block);
11900 }12961 }
11901 ira->instruction_index += 1;12962 ira->instruction_index += 1;
11902 while (ira->instruction_index < ira->old_irb.current_basic_block->instruction_list.length) {12963 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);
11904 if (!next_instruction->is_gen) {12965 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"));
11906 break;12967 break;
11907 }12968 }
11908 ira->instruction_index += 1;12969 ira->instruction_index += 1;
...@@ -11911,7 +12972,7 @@ static void ir_finish_bb(IrAnalyze *ira) {...@@ -11911,7 +12972,7 @@ static void ir_finish_bb(IrAnalyze *ira) {
11911 ir_start_next_bb(ira);12972 ir_start_next_bb(ira);
11912}12973}
1191312974
11914static IrInstruction *ir_unreach_error(IrAnalyze *ira) {12975static IrInstGen *ir_unreach_error(IrAnalyze *ira) {
11915 ira->old_bb_index = SIZE_MAX;12976 ira->old_bb_index = SIZE_MAX;
11916 if (ira->new_irb.exec->first_err_trace_msg == nullptr) {12977 if (ira->new_irb.exec->first_err_trace_msg == nullptr) {
11917 ira->new_irb.exec->first_err_trace_msg = ira->codegen->trace_err;12978 ira->new_irb.exec->first_err_trace_msg = ira->codegen->trace_err;
...@@ -11919,7 +12980,7 @@ static IrInstruction *ir_unreach_error(IrAnalyze *ira) {...@@ -11919,7 +12980,7 @@ static IrInstruction *ir_unreach_error(IrAnalyze *ira) {
11919 return ira->codegen->unreach_instruction;12980 return ira->codegen->unreach_instruction;
11920}12981}
1192112982
11922static bool ir_emit_backward_branch(IrAnalyze *ira, IrInstruction *source_instruction) {12983static bool ir_emit_backward_branch(IrAnalyze *ira, IrInst* source_instruction) {
11923 size_t *bbc = ira->new_irb.exec->backward_branch_count;12984 size_t *bbc = ira->new_irb.exec->backward_branch_count;
11924 size_t *quota = ira->new_irb.exec->backward_branch_quota;12985 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...@@ -11938,66 +12999,82 @@ static bool ir_emit_backward_branch(IrAnalyze *ira, IrInstruction *source_instru
11938 return true;12999 return true;
11939}13000}
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) {
11942 if (old_bb->debug_id <= ira->old_irb.current_basic_block->debug_id) {13003 if (old_bb->debug_id <= ira->old_irb.current_basic_block->debug_id) {
11943 if (!ir_emit_backward_branch(ira, source_instruction))13004 if (!ir_emit_backward_branch(ira, source_instruction))
11944 return ir_unreach_error(ira);13005 return ir_unreach_error(ira);
11945 }13006 }
1194613007
11947 old_bb->other = ira->old_irb.current_basic_block->other;13008 old_bb->child = ira->old_irb.current_basic_block->child;
11948 ir_start_bb(ira, old_bb, ira->old_irb.current_basic_block);13009 ir_start_bb(ira, old_bb, ira->old_irb.current_basic_block);
11949 return ira->codegen->unreach_instruction;13010 return ira->codegen->unreach_instruction;
11950}13011}
1195113012
11952static IrInstruction *ir_finish_anal(IrAnalyze *ira, IrInstruction *instruction) {13013static IrInstGen *ir_finish_anal(IrAnalyze *ira, IrInstGen *instruction) {
11953 if (instruction->value->type->id == ZigTypeIdUnreachable)13014 if (instruction->value->type->id == ZigTypeIdUnreachable)
11954 ir_finish_bb(ira);13015 ir_finish_bb(ira);
11955 return instruction;13016 return instruction;
11956}13017}
1195713018
11958static IrInstruction *ir_const_type(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) {13019static IrInstGen *ir_const_fn(IrAnalyze *ira, IrInst *source_instr, ZigFn *fn_entry) {
11959 IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_type);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);
11960 result->value->data.x_type = ty;13037 result->value->data.x_type = ty;
11961 return result;13038 return result;
11962}13039}
1196313040
11964static IrInstruction *ir_const_bool(IrAnalyze *ira, IrInstruction *source_instruction, bool value) {13041static IrInstGen *ir_const_bool(IrAnalyze *ira, IrInst *source_instruction, bool value) {
11965 IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_bool);13042 IrInstGen *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_bool);
11966 result->value->data.x_bool = value;13043 result->value->data.x_bool = value;
11967 return result;13044 return result;
11968}13045}
1196913046
11970static IrInstruction *ir_const_undef(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) {13047static IrInstGen *ir_const_undef(IrAnalyze *ira, IrInst *source_instruction, ZigType *ty) {
11971 IrInstruction *result = ir_const(ira, source_instruction, ty);13048 IrInstGen *result = ir_const(ira, source_instruction, ty);
11972 result->value->special = ConstValSpecialUndef;13049 result->value->special = ConstValSpecialUndef;
11973 return result;13050 return result;
11974}13051}
1197513052
11976static IrInstruction *ir_const_unreachable(IrAnalyze *ira, IrInstruction *source_instruction) {13053static IrInstGen *ir_const_unreachable(IrAnalyze *ira, IrInst *source_instruction) {
11977 IrInstruction *result = ir_const_noval(ira, source_instruction);13054 IrInstGen *result = ir_const_noval(ira, source_instruction);
11978 result->value = ira->codegen->intern.for_unreachable();13055 result->value = ira->codegen->intern.for_unreachable();
11979 return result;13056 return result;
11980}13057}
1198113058
11982static IrInstruction *ir_const_void(IrAnalyze *ira, IrInstruction *source_instruction) {13059static IrInstGen *ir_const_void(IrAnalyze *ira, IrInst *source_instruction) {
11983 IrInstruction *result = ir_const_noval(ira, source_instruction);13060 IrInstGen *result = ir_const_noval(ira, source_instruction);
11984 result->value = ira->codegen->intern.for_void();13061 result->value = ira->codegen->intern.for_void();
11985 return result;13062 return result;
11986}13063}
1198713064
11988static IrInstruction *ir_const_unsigned(IrAnalyze *ira, IrInstruction *source_instruction, uint64_t value) {13065static IrInstGen *ir_const_unsigned(IrAnalyze *ira, IrInst *source_instruction, uint64_t value) {
11989 IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_num_lit_int);13066 IrInstGen *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_num_lit_int);
11990 bigint_init_unsigned(&result->value->data.x_bigint, value);13067 bigint_init_unsigned(&result->value->data.x_bigint, value);
11991 return result;13068 return result;
11992}13069}
1199313070
11994static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instruction,13071static IrInstGen *ir_get_const_ptr(IrAnalyze *ira, IrInst *instruction,
11995 ZigValue *pointee, ZigType *pointee_type,13072 ZigValue *pointee, ZigType *pointee_type,
11996 ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align)13073 ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align)
11997{13074{
11998 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type,13075 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type,
11999 ptr_is_const, ptr_is_volatile, PtrLenSingle, ptr_align, 0, 0, false);13076 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);
12001 ZigValue *const_val = const_instr->value;13078 ZigValue *const_val = const_instr->value;
12002 const_val->data.x_ptr.special = ConstPtrSpecialRef;13079 const_val->data.x_ptr.special = ConstPtrSpecialRef;
12003 const_val->data.x_ptr.mut = ptr_mut;13080 const_val->data.x_ptr.mut = ptr_mut;
...@@ -12005,7 +13082,7 @@ static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instructio...@@ -12005,7 +13082,7 @@ static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instructio
12005 return const_instr;13082 return const_instr;
12006}13083}
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,
12009 ZigValue *val, UndefAllowed undef_allowed)13086 ZigValue *val, UndefAllowed undef_allowed)
12010{13087{
12011 Error err;13088 Error err;
...@@ -12017,14 +13094,14 @@ static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode...@@ -12017,14 +13094,14 @@ static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode
12017 if (!type_has_bits(val->type))13094 if (!type_has_bits(val->type))
12018 return ErrorNone;13095 return ErrorNone;
1201913096
12020 exec_add_error_node(codegen, exec, source_node,13097 exec_add_error_node_gen(codegen, exec, source_node,
12021 buf_sprintf("unable to evaluate constant expression"));13098 buf_sprintf("unable to evaluate constant expression"));
12022 return ErrorSemanticAnalyzeFail;13099 return ErrorSemanticAnalyzeFail;
12023 case ConstValSpecialUndef:13100 case ConstValSpecialUndef:
12024 if (undef_allowed == UndefOk || undef_allowed == LazyOk)13101 if (undef_allowed == UndefOk || undef_allowed == LazyOk)
12025 return ErrorNone;13102 return ErrorNone;
1202613103
12027 exec_add_error_node(codegen, exec, source_node,13104 exec_add_error_node_gen(codegen, exec, source_node,
12028 buf_sprintf("use of undefined value here causes undefined behavior"));13105 buf_sprintf("use of undefined value here causes undefined behavior"));
12029 return ErrorSemanticAnalyzeFail;13106 return ErrorSemanticAnalyzeFail;
12030 case ConstValSpecialLazy:13107 case ConstValSpecialLazy:
...@@ -12039,9 +13116,9 @@ static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode...@@ -12039,9 +13116,9 @@ static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode
12039 }13116 }
12040}13117}
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) {
12043 Error err;13120 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,
12045 value->value, undef_allowed)))13122 value->value, undef_allowed)))
12046 {13123 {
12047 return nullptr;13124 return nullptr;
...@@ -12052,14 +13129,14 @@ static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAll...@@ -12052,14 +13129,14 @@ static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAll
12052ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,13129ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
12053 ZigType *expected_type, size_t *backward_branch_count, size_t *backward_branch_quota,13130 ZigType *expected_type, size_t *backward_branch_count, size_t *backward_branch_quota,
12054 ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,13131 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)
12056{13133{
12057 Error err;13134 Error err;
1205813135
12059 if (expected_type != nullptr && type_is_invalid(expected_type))13136 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");
12063 ir_executable->source_node = source_node;13140 ir_executable->source_node = source_node;
12064 ir_executable->parent_exec = parent_exec;13141 ir_executable->parent_exec = parent_exec;
12065 ir_executable->name = exec_name;13142 ir_executable->name = exec_name;
...@@ -12069,21 +13146,21 @@ ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,...@@ -12069,21 +13146,21 @@ ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
12069 ir_executable->begin_scope = scope;13146 ir_executable->begin_scope = scope;
1207013147
12071 if (!ir_gen(codegen, node, scope, ir_executable))13148 if (!ir_gen(codegen, node, scope, ir_executable))
12072 return codegen->invalid_instruction->value;13149 return codegen->invalid_inst_gen->value;
1207313150
12074 if (ir_executable->first_err_trace_msg != nullptr) {13151 if (ir_executable->first_err_trace_msg != nullptr) {
12075 codegen->trace_err = ir_executable->first_err_trace_msg;13152 codegen->trace_err = ir_executable->first_err_trace_msg;
12076 return codegen->invalid_instruction->value;13153 return codegen->invalid_inst_gen->value;
12077 }13154 }
1207813155
12079 if (codegen->verbose_ir) {13156 if (codegen->verbose_ir) {
12080 fprintf(stderr, "\nSource: ");13157 fprintf(stderr, "\nSource: ");
12081 ast_render(stderr, node, 4);13158 ast_render(stderr, node, 4);
12082 fprintf(stderr, "\n{ // (IR)\n");13159 fprintf(stderr, "\n{ // (IR)\n");
12083 ir_print(codegen, stderr, ir_executable, 2, IrPassSrc);13160 ir_print_src(codegen, stderr, ir_executable, 2);
12084 fprintf(stderr, "}\n");13161 fprintf(stderr, "}\n");
12085 }13162 }
12086 IrExecutable *analyzed_executable = allocate<IrExecutable>(1, "IrExecutablePass2");13163 IrExecutableGen *analyzed_executable = allocate<IrExecutableGen>(1, "IrExecutableGen");
12087 analyzed_executable->source_node = source_node;13164 analyzed_executable->source_node = source_node;
12088 analyzed_executable->parent_exec = parent_exec;13165 analyzed_executable->parent_exec = parent_exec;
12089 analyzed_executable->source_exec = ir_executable;13166 analyzed_executable->source_exec = ir_executable;
...@@ -12096,31 +13173,31 @@ ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,...@@ -12096,31 +13173,31 @@ ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
12096 analyzed_executable->begin_scope = scope;13173 analyzed_executable->begin_scope = scope;
12097 ZigType *result_type = ir_analyze(codegen, ir_executable, analyzed_executable, expected_type, expected_type_source_node);13174 ZigType *result_type = ir_analyze(codegen, ir_executable, analyzed_executable, expected_type, expected_type_source_node);
12098 if (type_is_invalid(result_type)) {13175 if (type_is_invalid(result_type)) {
12099 return codegen->invalid_instruction->value;13176 return codegen->invalid_inst_gen->value;
12100 }13177 }
1210113178
12102 if (codegen->verbose_ir) {13179 if (codegen->verbose_ir) {
12103 fprintf(stderr, "{ // (analyzed)\n");13180 fprintf(stderr, "{ // (analyzed)\n");
12104 ir_print(codegen, stderr, analyzed_executable, 2, IrPassGen);13181 ir_print_gen(codegen, stderr, analyzed_executable, 2);
12105 fprintf(stderr, "}\n");13182 fprintf(stderr, "}\n");
12106 }13183 }
1210713184
12108 ZigValue *result = ir_exec_const_result(codegen, analyzed_executable);13185 ZigValue *result = ir_exec_const_result(codegen, analyzed_executable);
12109 if (type_is_invalid(result->type))13186 if (type_is_invalid(result->type))
12110 return codegen->invalid_instruction->value;13187 return codegen->invalid_inst_gen->value;
1211113188
12112 if ((err = ir_resolve_const_val(codegen, analyzed_executable, node, result, undef_allowed)))13189 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
12115 return result;13192 return result;
12116}13193}
1211713194
12118static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstruction *err_value) {13195static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstGen *err_value) {
12119 if (type_is_invalid(err_value->value->type))13196 if (type_is_invalid(err_value->value->type))
12120 return nullptr;13197 return nullptr;
1212113198
12122 if (err_value->value->type->id != ZigTypeIdErrorSet) {13199 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,
12124 buf_sprintf("expected error, found '%s'", buf_ptr(&err_value->value->type->name)));13201 buf_sprintf("expected error, found '%s'", buf_ptr(&err_value->value->type->name)));
12125 return nullptr;13202 return nullptr;
12126 }13203 }
...@@ -12133,7 +13210,7 @@ static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstruction *err_valu...@@ -12133,7 +13210,7 @@ static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstruction *err_valu
12133 return const_val->data.x_err_set;13210 return const_val->data.x_err_set;
12134}13211}
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,
12137 ZigValue *val)13214 ZigValue *val)
12138{13215{
12139 Error err;13216 Error err;
...@@ -12144,18 +13221,18 @@ static ZigType *ir_resolve_const_type(CodeGen *codegen, IrExecutable *exec, AstN...@@ -12144,18 +13221,18 @@ static ZigType *ir_resolve_const_type(CodeGen *codegen, IrExecutable *exec, AstN
12144 return val->data.x_type;13221 return val->data.x_type;
12145}13222}
1214613223
12147static ZigValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstruction *type_value) {13224static ZigValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstGen *type_value) {
12148 if (type_is_invalid(type_value->value->type))13225 if (type_is_invalid(type_value->value->type))
12149 return nullptr;13226 return nullptr;
1215013227
12151 if (type_value->value->type->id != ZigTypeIdMetaType) {13228 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,
12153 buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->value->type->name)));13230 buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->value->type->name)));
12154 return nullptr;13231 return nullptr;
12155 }13232 }
1215613233
12157 Error err;13234 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,
12159 type_value->value, LazyOk)))13236 type_value->value, LazyOk)))
12160 {13237 {
12161 return nullptr;13238 return nullptr;
...@@ -12164,17 +13241,17 @@ static ZigValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstruction *type_value)...@@ -12164,17 +13241,17 @@ static ZigValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstruction *type_value)
12164 return type_value->value;13241 return type_value->value;
12165}13242}
1216613243
12167static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) {13244static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstGen *type_value) {
12168 ZigValue *val = ir_resolve_type_lazy(ira, type_value);13245 ZigValue *val = ir_resolve_type_lazy(ira, type_value);
12169 if (val == nullptr)13246 if (val == nullptr)
12170 return ira->codegen->builtin_types.entry_invalid;13247 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);
12173}13250}
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) {
12176 if (!is_valid_vector_elem_type(elem_type)) {13253 if (!is_valid_vector_elem_type(elem_type)) {
12177 ir_add_error(ira, source_instr,13254 ir_add_error_node(ira, source_node,
12178 buf_sprintf("vector element type must be integer, float, bool, or pointer; '%s' is invalid",13255 buf_sprintf("vector element type must be integer, float, bool, or pointer; '%s' is invalid",
12179 buf_ptr(&elem_type->name)));13256 buf_ptr(&elem_type->name)));
12180 return ErrorSemanticAnalyzeFail;13257 return ErrorSemanticAnalyzeFail;
...@@ -12182,28 +13259,28 @@ static Error ir_validate_vector_elem_type(IrAnalyze *ira, IrInstruction *source_...@@ -12182,28 +13259,28 @@ static Error ir_validate_vector_elem_type(IrAnalyze *ira, IrInstruction *source_
12182 return ErrorNone;13259 return ErrorNone;
12183}13260}
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) {
12186 Error err;13263 Error err;
12187 ZigType *elem_type = ir_resolve_type(ira, elem_type_value);13264 ZigType *elem_type = ir_resolve_type(ira, elem_type_value);
12188 if (type_is_invalid(elem_type))13265 if (type_is_invalid(elem_type))
12189 return ira->codegen->builtin_types.entry_invalid;13266 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)))
12191 return ira->codegen->builtin_types.entry_invalid;13268 return ira->codegen->builtin_types.entry_invalid;
12192 return elem_type;13269 return elem_type;
12193}13270}
1219413271
12195static ZigType *ir_resolve_int_type(IrAnalyze *ira, IrInstruction *type_value) {13272static ZigType *ir_resolve_int_type(IrAnalyze *ira, IrInstGen *type_value) {
12196 ZigType *ty = ir_resolve_type(ira, type_value);13273 ZigType *ty = ir_resolve_type(ira, type_value);
12197 if (type_is_invalid(ty))13274 if (type_is_invalid(ty))
12198 return ira->codegen->builtin_types.entry_invalid;13275 return ira->codegen->builtin_types.entry_invalid;
1219913276
12200 if (ty->id != ZigTypeIdInt) {13277 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,
12202 buf_sprintf("expected integer type, found '%s'", buf_ptr(&ty->name)));13279 buf_sprintf("expected integer type, found '%s'", buf_ptr(&ty->name)));
12203 if (ty->id == ZigTypeIdVector &&13280 if (ty->id == ZigTypeIdVector &&
12204 ty->data.vector.elem_type->id == ZigTypeIdInt)13281 ty->data.vector.elem_type->id == ZigTypeIdInt)
12205 {13282 {
12206 add_error_note(ira->codegen, msg, type_value->source_node,13283 add_error_note(ira->codegen, msg, type_value->base.source_node,
12207 buf_sprintf("represent vectors with their element types, i.e. '%s'",13284 buf_sprintf("represent vectors with their element types, i.e. '%s'",
12208 buf_ptr(&ty->data.vector.elem_type->name)));13285 buf_ptr(&ty->data.vector.elem_type->name)));
12209 }13286 }
...@@ -12213,12 +13290,12 @@ static ZigType *ir_resolve_int_type(IrAnalyze *ira, IrInstruction *type_value) {...@@ -12213,12 +13290,12 @@ static ZigType *ir_resolve_int_type(IrAnalyze *ira, IrInstruction *type_value) {
12213 return ty;13290 return ty;
12214}13291}
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) {
12217 if (type_is_invalid(type_value->value->type))13294 if (type_is_invalid(type_value->value->type))
12218 return ira->codegen->builtin_types.entry_invalid;13295 return ira->codegen->builtin_types.entry_invalid;
1221913296
12220 if (type_value->value->type->id != ZigTypeIdMetaType) {13297 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,
12222 buf_sprintf("expected error set type, found '%s'", buf_ptr(&type_value->value->type->name)));13299 buf_sprintf("expected error set type, found '%s'", buf_ptr(&type_value->value->type->name)));
12223 add_error_note(ira->codegen, msg, op_source->source_node,13300 add_error_note(ira->codegen, msg, op_source->source_node,
12224 buf_sprintf("`||` merges error sets; `or` performs boolean OR"));13301 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...@@ -12232,7 +13309,7 @@ static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInstruction *op_sour
12232 assert(const_val->data.x_type != nullptr);13309 assert(const_val->data.x_type != nullptr);
12233 ZigType *result_type = const_val->data.x_type;13310 ZigType *result_type = const_val->data.x_type;
12234 if (result_type->id != ZigTypeIdErrorSet) {13311 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,
12236 buf_sprintf("expected error set type, found type '%s'", buf_ptr(&result_type->name)));13313 buf_sprintf("expected error set type, found type '%s'", buf_ptr(&result_type->name)));
12237 add_error_note(ira->codegen, msg, op_source->source_node,13314 add_error_note(ira->codegen, msg, op_source->source_node,
12238 buf_sprintf("`||` merges error sets; `or` performs boolean OR"));13315 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...@@ -12241,15 +13318,12 @@ static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInstruction *op_sour
12241 return result_type;13318 return result_type;
12242}13319}
1224313320
12244static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {13321static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstGen *fn_value) {
12245 if (fn_value == ira->codegen->invalid_instruction)
12246 return nullptr;
12247
12248 if (type_is_invalid(fn_value->value->type))13322 if (type_is_invalid(fn_value->value->type))
12249 return nullptr;13323 return nullptr;
1225013324
12251 if (fn_value->value->type->id != ZigTypeIdFn) {13325 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,
12253 buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->value->type->name)));13327 buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->value->type->name)));
12254 return nullptr;13328 return nullptr;
12255 }13329 }
...@@ -12265,22 +13339,22 @@ static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {...@@ -12265,22 +13339,22 @@ static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {
12265 return const_val->data.x_ptr.data.fn.fn_entry;13339 return const_val->data.x_ptr.data.fn.fn_entry;
12266}13340}
1226713341
12268static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,13342static IrInstGen *ir_analyze_optional_wrap(IrAnalyze *ira, IrInst* source_instr,
12269 ZigType *wanted_type, ResultLoc *result_loc)13343 IrInstGen *value, ZigType *wanted_type, ResultLoc *result_loc)
12270{13344{
12271 assert(wanted_type->id == ZigTypeIdOptional);13345 assert(wanted_type->id == ZigTypeIdOptional);
1227213346
12273 if (instr_is_comptime(value)) {13347 if (instr_is_comptime(value)) {
12274 ZigType *payload_type = wanted_type->data.maybe.child_type;13348 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);
12276 if (type_is_invalid(casted_payload->value->type))13350 if (type_is_invalid(casted_payload->value->type))
12277 return ira->codegen->invalid_instruction;13351 return ira->codegen->invalid_inst_gen;
1227813352
12279 ZigValue *val = ir_resolve_const(ira, casted_payload, UndefOk);13353 ZigValue *val = ir_resolve_const(ira, casted_payload, UndefOk);
12280 if (!val)13354 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,
12284 source_instr->scope, source_instr->source_node);13358 source_instr->scope, source_instr->source_node);
12285 const_instruction->base.value->special = ConstValSpecialStatic;13359 const_instruction->base.value->special = ConstValSpecialStatic;
12286 if (types_have_same_zig_comptime_repr(ira->codegen, wanted_type, payload_type)) {13360 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...@@ -12295,40 +13369,42 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so
12295 if (result_loc == nullptr && handle_is_ptr(wanted_type)) {13369 if (result_loc == nullptr && handle_is_ptr(wanted_type)) {
12296 result_loc = no_result_loc();13370 result_loc = no_result_loc();
12297 }13371 }
12298 IrInstruction *result_loc_inst = nullptr;13372 IrInstGen *result_loc_inst = nullptr;
12299 if (result_loc != nullptr) {13373 if (result_loc != nullptr) {
12300 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true);13374 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 {
12302 return result_loc_inst;13378 return result_loc_inst;
12303 }13379 }
12304 }13380 }
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);
12306 result->value->data.rh_maybe = RuntimeHintOptionalNonNull;13382 result->value->data.rh_maybe = RuntimeHintOptionalNonNull;
12307 return result;13383 return result;
12308}13384}
1230913385
12310static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction *source_instr,13386static IrInstGen *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInst* source_instr,
12311 IrInstruction *value, ZigType *wanted_type, ResultLoc *result_loc)13387 IrInstGen *value, ZigType *wanted_type, ResultLoc *result_loc)
12312{13388{
12313 assert(wanted_type->id == ZigTypeIdErrorUnion);13389 assert(wanted_type->id == ZigTypeIdErrorUnion);
1231413390
12315 ZigType *payload_type = wanted_type->data.error_union.payload_type;13391 ZigType *payload_type = wanted_type->data.error_union.payload_type;
12316 ZigType *err_set_type = wanted_type->data.error_union.err_set_type;13392 ZigType *err_set_type = wanted_type->data.error_union.err_set_type;
12317 if (instr_is_comptime(value)) {13393 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);
12319 if (type_is_invalid(casted_payload->value->type))13395 if (type_is_invalid(casted_payload->value->type))
12320 return ira->codegen->invalid_instruction;13396 return ira->codegen->invalid_inst_gen;
1232113397
12322 ZigValue *val = ir_resolve_const(ira, casted_payload, UndefBad);13398 ZigValue *val = ir_resolve_const(ira, casted_payload, UndefBad);
12323 if (!val)13399 if (!val)
12324 return ira->codegen->invalid_instruction;13400 return ira->codegen->invalid_inst_gen;
1232513401
12326 ZigValue *err_set_val = create_const_vals(1);13402 ZigValue *err_set_val = create_const_vals(1);
12327 err_set_val->type = err_set_type;13403 err_set_val->type = err_set_type;
12328 err_set_val->special = ConstValSpecialStatic;13404 err_set_val->special = ConstValSpecialStatic;
12329 err_set_val->data.x_err_set = nullptr;13405 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,
12332 source_instr->scope, source_instr->source_node);13408 source_instr->scope, source_instr->source_node);
12333 const_instruction->base.value->type = wanted_type;13409 const_instruction->base.value->type = wanted_type;
12334 const_instruction->base.value->special = ConstValSpecialStatic;13410 const_instruction->base.value->special = ConstValSpecialStatic;
...@@ -12337,23 +13413,24 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction...@@ -12337,23 +13413,24 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction
12337 return &const_instruction->base;13413 return &const_instruction->base;
12338 }13414 }
1233913415
12340 IrInstruction *result_loc_inst;13416 IrInstGen *result_loc_inst;
12341 if (handle_is_ptr(wanted_type)) {13417 if (handle_is_ptr(wanted_type)) {
12342 if (result_loc == nullptr) result_loc = no_result_loc();13418 if (result_loc == nullptr) result_loc = no_result_loc();
12343 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true);13419 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) {
12345 return result_loc_inst;13422 return result_loc_inst;
12346 }13423 }
12347 } else {13424 } else {
12348 result_loc_inst = nullptr;13425 result_loc_inst = nullptr;
12349 }13426 }
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);
12352 result->value->data.rh_error_union = RuntimeHintErrorUnionNonError;13429 result->value->data.rh_error_union = RuntimeHintErrorUnionNonError;
12353 return result;13430 return result;
12354}13431}
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,
12357 ZigType *wanted_type)13434 ZigType *wanted_type)
12358{13435{
12359 assert(value->value->type->id == ZigTypeIdErrorSet);13436 assert(value->value->type->id == ZigTypeIdErrorSet);
...@@ -12362,10 +13439,10 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou...@@ -12362,10 +13439,10 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou
12362 if (instr_is_comptime(value)) {13439 if (instr_is_comptime(value)) {
12363 ZigValue *val = ir_resolve_const(ira, value, UndefBad);13440 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
12364 if (!val)13441 if (!val)
12365 return ira->codegen->invalid_instruction;13442 return ira->codegen->invalid_inst_gen;
1236613443
12367 if (!resolve_inferred_error_set(ira->codegen, wanted_type, source_instr->source_node)) {13444 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;
12369 }13446 }
12370 if (!type_is_global_error_set(wanted_type)) {13447 if (!type_is_global_error_set(wanted_type)) {
12371 bool subset = false;13448 bool subset = false;
...@@ -12379,11 +13456,11 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou...@@ -12379,11 +13456,11 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou
12379 ir_add_error(ira, source_instr,13456 ir_add_error(ira, source_instr,
12380 buf_sprintf("error.%s not a member of error set '%s'",13457 buf_sprintf("error.%s not a member of error set '%s'",
12381 buf_ptr(&val->data.x_err_set->name), buf_ptr(&wanted_type->name)));13458 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;
12383 }13460 }
12384 }13461 }
1238513462
12386 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,13463 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
12387 source_instr->scope, source_instr->source_node);13464 source_instr->scope, source_instr->source_node);
12388 const_instruction->base.value->type = wanted_type;13465 const_instruction->base.value->type = wanted_type;
12389 const_instruction->base.value->special = ConstValSpecialStatic;13466 const_instruction->base.value->special = ConstValSpecialStatic;
...@@ -12391,18 +13468,16 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou...@@ -12391,18 +13468,16 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou
12391 return &const_instruction->base;13468 return &const_instruction->base;
12392 }13469 }
1239313470
12394 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type, value, CastOpErrSet);13471 return ir_build_cast(ira, source_instr, wanted_type, value, CastOpErrSet);
12395 result->value->type = wanted_type;
12396 return result;
12397}13472}
1239813473
12399static IrInstruction *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInstruction *source_instr,13474static IrInstGen *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInst* source_instr,
12400 IrInstruction *frame_ptr, ZigType *wanted_type)13475 IrInstGen *frame_ptr, ZigType *wanted_type)
12401{13476{
12402 if (instr_is_comptime(frame_ptr)) {13477 if (instr_is_comptime(frame_ptr)) {
12403 ZigValue *ptr_val = ir_resolve_const(ira, frame_ptr, UndefBad);13478 ZigValue *ptr_val = ir_resolve_const(ira, frame_ptr, UndefBad);
12404 if (ptr_val == nullptr)13479 if (ptr_val == nullptr)
12405 return ira->codegen->invalid_instruction;13480 return ira->codegen->invalid_inst_gen;
1240613481
12407 ir_assert(ptr_val->type->id == ZigTypeIdPointer, source_instr);13482 ir_assert(ptr_val->type->id == ZigTypeIdPointer, source_instr);
12408 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {13483 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
...@@ -12410,44 +13485,38 @@ static IrInstruction *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInstruc...@@ -12410,44 +13485,38 @@ static IrInstruction *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInstruc
12410 }13485 }
12411 }13486 }
1241213487
12413 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node,13488 return ir_build_cast(ira, source_instr, wanted_type, frame_ptr, CastOpBitCast);
12414 wanted_type, frame_ptr, CastOpBitCast);
12415 result->value->type = wanted_type;
12416 return result;
12417}13489}
1241813490
12419static IrInstruction *ir_analyze_anyframe_to_anyframe(IrAnalyze *ira, IrInstruction *source_instr,13491static IrInstGen *ir_analyze_anyframe_to_anyframe(IrAnalyze *ira, IrInst* source_instr,
12420 IrInstruction *value, ZigType *wanted_type)13492 IrInstGen *value, ZigType *wanted_type)
12421{13493{
12422 if (instr_is_comptime(value)) {13494 if (instr_is_comptime(value)) {
12423 zig_panic("TODO comptime anyframe->T to anyframe");13495 zig_panic("TODO comptime anyframe->T to anyframe");
12424 }13496 }
1242513497
12426 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node,13498 return ir_build_cast(ira, source_instr, wanted_type, value, CastOpBitCast);
12427 wanted_type, value, CastOpBitCast);
12428 result->value->type = wanted_type;
12429 return result;
12430}13499}
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,
12434 ZigType *wanted_type, ResultLoc *result_loc)13503 ZigType *wanted_type, ResultLoc *result_loc)
12435{13504{
12436 assert(wanted_type->id == ZigTypeIdErrorUnion);13505 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
12440 if (instr_is_comptime(casted_value)) {13509 if (instr_is_comptime(casted_value)) {
12441 ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad);13510 ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad);
12442 if (!val)13511 if (!val)
12443 return ira->codegen->invalid_instruction;13512 return ira->codegen->invalid_inst_gen;
1244413513
12445 ZigValue *err_set_val = create_const_vals(1);13514 ZigValue *err_set_val = create_const_vals(1);
12446 err_set_val->special = ConstValSpecialStatic;13515 err_set_val->special = ConstValSpecialStatic;
12447 err_set_val->type = wanted_type->data.error_union.err_set_type;13516 err_set_val->type = wanted_type->data.error_union.err_set_type;
12448 err_set_val->data.x_err_set = val->data.x_err_set;13517 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,
12451 source_instr->scope, source_instr->source_node);13520 source_instr->scope, source_instr->source_node);
12452 const_instruction->base.value->type = wanted_type;13521 const_instruction->base.value->type = wanted_type;
12453 const_instruction->base.value->special = ConstValSpecialStatic;13522 const_instruction->base.value->special = ConstValSpecialStatic;
...@@ -12456,11 +13525,13 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so...@@ -12456,11 +13525,13 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so
12456 return &const_instruction->base;13525 return &const_instruction->base;
12457 }13526 }
1245813527
12459 IrInstruction *result_loc_inst;13528 IrInstGen *result_loc_inst;
12460 if (handle_is_ptr(wanted_type)) {13529 if (handle_is_ptr(wanted_type)) {
12461 if (result_loc == nullptr) result_loc = no_result_loc();13530 if (result_loc == nullptr) result_loc = no_result_loc();
12462 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true);13531 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 {
12464 return result_loc_inst;13535 return result_loc_inst;
12465 }13536 }
12466 } else {13537 } else {
...@@ -12468,19 +13539,19 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so...@@ -12468,19 +13539,19 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so
12468 }13539 }
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);
12472 result->value->data.rh_error_union = RuntimeHintErrorUnionError;13543 result->value->data.rh_error_union = RuntimeHintErrorUnionError;
12473 return result;13544 return result;
12474}13545}
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) {
12477 assert(wanted_type->id == ZigTypeIdOptional);13548 assert(wanted_type->id == ZigTypeIdOptional);
12478 assert(instr_is_comptime(value));13549 assert(instr_is_comptime(value));
1247913550
12480 ZigValue *val = ir_resolve_const(ira, value, UndefBad);13551 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
12481 assert(val != nullptr);13552 assert(val != nullptr);
1248213553
12483 IrInstruction *result = ir_const(ira, source_instr, wanted_type);13554 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
12484 result->value->special = ConstValSpecialStatic;13555 result->value->special = ConstValSpecialStatic;
12485 if (get_codegen_ptr_type(wanted_type) != nullptr) {13556 if (get_codegen_ptr_type(wanted_type) != nullptr) {
12486 result->value->data.x_ptr.special = ConstPtrSpecialNull;13557 result->value->data.x_ptr.special = ConstPtrSpecialNull;
...@@ -12492,8 +13563,8 @@ static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *so...@@ -12492,8 +13563,8 @@ static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *so
12492 return result;13563 return result;
12493}13564}
1249413565
12495static IrInstruction *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInstruction *source_instr,13566static IrInstGen *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInst *source_instr,
12496 IrInstruction *value, ZigType *wanted_type)13567 IrInstGen *value, ZigType *wanted_type)
12497{13568{
12498 assert(wanted_type->id == ZigTypeIdPointer);13569 assert(wanted_type->id == ZigTypeIdPointer);
12499 assert(wanted_type->data.pointer.ptr_len == PtrLenC);13570 assert(wanted_type->data.pointer.ptr_len == PtrLenC);
...@@ -12502,24 +13573,24 @@ static IrInstruction *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInstruction...@@ -12502,24 +13573,24 @@ static IrInstruction *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInstruction
12502 ZigValue *val = ir_resolve_const(ira, value, UndefBad);13573 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
12503 assert(val != nullptr);13574 assert(val != nullptr);
1250413575
12505 IrInstruction *result = ir_const(ira, source_instr, wanted_type);13576 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
12506 result->value->data.x_ptr.special = ConstPtrSpecialNull;13577 result->value->data.x_ptr.special = ConstPtrSpecialNull;
12507 result->value->data.x_ptr.mut = ConstPtrMutComptimeConst;13578 result->value->data.x_ptr.mut = ConstPtrMutComptimeConst;
12508 return result;13579 return result;
12509}13580}
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,
12512 bool is_const, bool is_volatile)13583 bool is_const, bool is_volatile)
12513{13584{
12514 Error err;13585 Error err;
1251513586
12516 if (type_is_invalid(value->value->type))13587 if (type_is_invalid(value->value->type))
12517 return ira->codegen->invalid_instruction;13588 return ira->codegen->invalid_inst_gen;
1251813589
12519 if (instr_is_comptime(value)) {13590 if (instr_is_comptime(value)) {
12520 ZigValue *val = ir_resolve_const(ira, value, LazyOk);13591 ZigValue *val = ir_resolve_const(ira, value, LazyOk);
12521 if (!val)13592 if (!val)
12522 return ira->codegen->invalid_instruction;13593 return ira->codegen->invalid_inst_gen;
12523 return ir_get_const_ptr(ira, source_instruction, val, value->value->type,13594 return ir_get_const_ptr(ira, source_instruction, val, value->value->type,
12524 ConstPtrMutComptimeConst, is_const, is_volatile, 0);13595 ConstPtrMutComptimeConst, is_const, is_volatile, 0);
12525 }13596 }
...@@ -12528,9 +13599,9 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi...@@ -12528,9 +13599,9 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi
12528 is_const, is_volatile, PtrLenSingle, 0, 0, 0, false);13599 is_const, is_volatile, PtrLenSingle, 0, 0, 0, false);
1252913600
12530 if ((err = type_resolve(ira->codegen, ptr_type, ResolveStatusZeroBitsKnown)))13601 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;
12534 if (type_has_bits(ptr_type) && !handle_is_ptr(value->value->type)) {13605 if (type_has_bits(ptr_type) && !handle_is_ptr(value->value->type)) {
12535 result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), value->value->type, nullptr, true,13606 result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), value->value->type, nullptr, true,
12536 false, true);13607 false, true);
...@@ -12538,12 +13609,12 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi...@@ -12538,12 +13609,12 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi
12538 result_loc = nullptr;13609 result_loc = nullptr;
12539 }13610 }
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);
12542 new_instruction->value->data.rh_ptr = RuntimeHintPtrStack;13613 new_instruction->value->data.rh_ptr = RuntimeHintPtrStack;
12543 return new_instruction;13614 return new_instruction;
12544}13615}
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) {
12547 assert(union_type->id == ZigTypeIdUnion);13618 assert(union_type->id == ZigTypeIdUnion);
1254813619
12549 Error err;13620 Error err;
...@@ -12555,36 +13626,36 @@ static ZigType *ir_resolve_union_tag_type(IrAnalyze *ira, IrInstruction *source_...@@ -12555,36 +13626,36 @@ static ZigType *ir_resolve_union_tag_type(IrAnalyze *ira, IrInstruction *source_
12555 assert(union_type->data.unionation.tag_type != nullptr);13626 assert(union_type->data.unionation.tag_type != nullptr);
12556 return union_type->data.unionation.tag_type;13627 return union_type->data.unionation.tag_type;
12557 } else {13628 } 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",
12559 buf_ptr(&union_type->name)));13630 buf_ptr(&union_type->name)));
12560 add_error_note(ira->codegen, msg, decl_node, buf_sprintf("consider 'union(enum)' here"));13631 add_error_note(ira->codegen, msg, decl_node, buf_sprintf("consider 'union(enum)' here"));
12561 return ira->codegen->builtin_types.entry_invalid;13632 return ira->codegen->builtin_types.entry_invalid;
12562 }13633 }
12563}13634}
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) {
12566 Error err;13637 Error err;
1256713638
12568 IrInstruction *enum_target;13639 IrInstGen *enum_target;
12569 ZigType *enum_type;13640 ZigType *enum_type;
12570 if (target->value->type->id == ZigTypeIdUnion) {13641 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);
12572 if (type_is_invalid(enum_type))13643 if (type_is_invalid(enum_type))
12573 return ira->codegen->invalid_instruction;13644 return ira->codegen->invalid_inst_gen;
12574 enum_target = ir_implicit_cast(ira, target, enum_type);13645 enum_target = ir_implicit_cast(ira, target, enum_type);
12575 if (type_is_invalid(enum_target->value->type))13646 if (type_is_invalid(enum_target->value->type))
12576 return ira->codegen->invalid_instruction;13647 return ira->codegen->invalid_inst_gen;
12577 } else if (target->value->type->id == ZigTypeIdEnum) {13648 } else if (target->value->type->id == ZigTypeIdEnum) {
12578 enum_target = target;13649 enum_target = target;
12579 enum_type = target->value->type;13650 enum_type = target->value->type;
12580 } else {13651 } else {
12581 ir_add_error(ira, target,13652 ir_add_error_node(ira, target->base.source_node,
12582 buf_sprintf("expected enum, found type '%s'", buf_ptr(&target->value->type->name)));13653 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;
12584 }13655 }
1258513656
12586 if ((err = type_resolve(ira->codegen, enum_type, ResolveStatusSizeKnown)))13657 if ((err = type_resolve(ira->codegen, enum_type, ResolveStatusSizeKnown)))
12587 return ira->codegen->invalid_instruction;13658 return ira->codegen->invalid_inst_gen;
1258813659
12589 ZigType *tag_type = enum_type->data.enumeration.tag_int_type;13660 ZigType *tag_type = enum_type->data.enumeration.tag_int_type;
12590 assert(tag_type->id == ZigTypeIdInt || tag_type->id == ZigTypeIdComptimeInt);13661 assert(tag_type->id == ZigTypeIdInt || tag_type->id == ZigTypeIdComptimeInt);
...@@ -12593,7 +13664,7 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour...@@ -12593,7 +13664,7 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour
12593 if (enum_type->data.enumeration.layout == ContainerLayoutAuto &&13664 if (enum_type->data.enumeration.layout == ContainerLayoutAuto &&
12594 enum_type->data.enumeration.src_field_count == 1)13665 enum_type->data.enumeration.src_field_count == 1)
12595 {13666 {
12596 IrInstruction *result = ir_const(ira, source_instr, tag_type);13667 IrInstGen *result = ir_const(ira, source_instr, tag_type);
12597 init_const_bigint(result->value, tag_type,13668 init_const_bigint(result->value, tag_type,
12598 &enum_type->data.enumeration.fields[0].value);13669 &enum_type->data.enumeration.fields[0].value);
12599 return result;13670 return result;
...@@ -12602,20 +13673,17 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour...@@ -12602,20 +13673,17 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour
12602 if (instr_is_comptime(enum_target)) {13673 if (instr_is_comptime(enum_target)) {
12603 ZigValue *val = ir_resolve_const(ira, enum_target, UndefBad);13674 ZigValue *val = ir_resolve_const(ira, enum_target, UndefBad);
12604 if (!val)13675 if (!val)
12605 return ira->codegen->invalid_instruction;13676 return ira->codegen->invalid_inst_gen;
12606 IrInstruction *result = ir_const(ira, source_instr, tag_type);13677 IrInstGen *result = ir_const(ira, source_instr, tag_type);
12607 init_const_bigint(result->value, tag_type, &val->data.x_enum_tag);13678 init_const_bigint(result->value, tag_type, &val->data.x_enum_tag);
12608 return result;13679 return result;
12609 }13680 }
1261013681
12611 IrInstruction *result = ir_build_widen_or_shorten(&ira->new_irb, source_instr->scope,13682 return ir_build_widen_or_shorten(ira, source_instr->scope, source_instr->source_node, enum_target, tag_type);
12612 source_instr->source_node, enum_target);
12613 result->value->type = tag_type;
12614 return result;
12615}13683}
1261613684
12617static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *source_instr,13685static IrInstGen *ir_analyze_union_to_tag(IrAnalyze *ira, IrInst* source_instr,
12618 IrInstruction *target, ZigType *wanted_type)13686 IrInstGen *target, ZigType *wanted_type)
12619{13687{
12620 assert(target->value->type->id == ZigTypeIdUnion);13688 assert(target->value->type->id == ZigTypeIdUnion);
12621 assert(wanted_type->id == ZigTypeIdEnum);13689 assert(wanted_type->id == ZigTypeIdEnum);
...@@ -12624,8 +13692,8 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou...@@ -12624,8 +13692,8 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou
12624 if (instr_is_comptime(target)) {13692 if (instr_is_comptime(target)) {
12625 ZigValue *val = ir_resolve_const(ira, target, UndefBad);13693 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
12626 if (!val)13694 if (!val)
12627 return ira->codegen->invalid_instruction;13695 return ira->codegen->invalid_inst_gen;
12628 IrInstruction *result = ir_const(ira, source_instr, wanted_type);13696 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
12629 result->value->special = ConstValSpecialStatic;13697 result->value->special = ConstValSpecialStatic;
12630 result->value->type = wanted_type;13698 result->value->type = wanted_type;
12631 bigint_init_bigint(&result->value->data.x_enum_tag, &val->data.x_union.tag);13699 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...@@ -12636,7 +13704,7 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou
12636 if (wanted_type->data.enumeration.layout == ContainerLayoutAuto &&13704 if (wanted_type->data.enumeration.layout == ContainerLayoutAuto &&
12637 wanted_type->data.enumeration.src_field_count == 1)13705 wanted_type->data.enumeration.src_field_count == 1)
12638 {13706 {
12639 IrInstruction *result = ir_const(ira, source_instr, wanted_type);13707 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
12640 result->value->special = ConstValSpecialStatic;13708 result->value->special = ConstValSpecialStatic;
12641 result->value->type = wanted_type;13709 result->value->type = wanted_type;
12642 TypeEnumField *enum_field = target->value->type->data.unionation.fields[0].enum_field;13710 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...@@ -12644,48 +13712,45 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou
12644 return result;13712 return result;
12645 }13713 }
1264613714
12647 IrInstruction *result = ir_build_union_tag(&ira->new_irb, source_instr->scope,13715 return ir_build_union_tag(ira, source_instr, target, wanted_type);
12648 source_instr->source_node, target);
12649 result->value->type = wanted_type;
12650 return result;
12651}13716}
1265213717
12653static IrInstruction *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInstruction *source_instr,13718static IrInstGen *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInst* source_instr,
12654 IrInstruction *target, ZigType *wanted_type)13719 IrInstGen *target, ZigType *wanted_type)
12655{13720{
12656 IrInstruction *result = ir_const(ira, source_instr, wanted_type);13721 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
12657 result->value->special = ConstValSpecialUndef;13722 result->value->special = ConstValSpecialUndef;
12658 return result;13723 return result;
12659}13724}
1266013725
12661static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *source_instr,13726static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr,
12662 IrInstruction *uncasted_target, ZigType *wanted_type)13727 IrInstGen *uncasted_target, ZigType *wanted_type)
12663{13728{
12664 Error err;13729 Error err;
12665 assert(wanted_type->id == ZigTypeIdUnion);13730 assert(wanted_type->id == ZigTypeIdUnion);
1266613731
12667 if ((err = type_resolve(ira->codegen, wanted_type, ResolveStatusZeroBitsKnown)))13732 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);
12671 if (type_is_invalid(target->value->type))13736 if (type_is_invalid(target->value->type))
12672 return ira->codegen->invalid_instruction;13737 return ira->codegen->invalid_inst_gen;
1267313738
12674 if (instr_is_comptime(target)) {13739 if (instr_is_comptime(target)) {
12675 ZigValue *val = ir_resolve_const(ira, target, UndefBad);13740 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
12676 if (!val)13741 if (!val)
12677 return ira->codegen->invalid_instruction;13742 return ira->codegen->invalid_inst_gen;
12678 TypeUnionField *union_field = find_union_field_by_tag(wanted_type, &val->data.x_enum_tag);13743 TypeUnionField *union_field = find_union_field_by_tag(wanted_type, &val->data.x_enum_tag);
12679 assert(union_field != nullptr);13744 assert(union_field != nullptr);
12680 ZigType *field_type = resolve_union_field_type(ira->codegen, union_field);13745 ZigType *field_type = resolve_union_field_type(ira->codegen, union_field);
12681 if (field_type == nullptr)13746 if (field_type == nullptr)
12682 return ira->codegen->invalid_instruction;13747 return ira->codegen->invalid_inst_gen;
12683 if ((err = type_resolve(ira->codegen, field_type, ResolveStatusZeroBitsKnown)))13748 if ((err = type_resolve(ira->codegen, field_type, ResolveStatusZeroBitsKnown)))
12684 return ira->codegen->invalid_instruction;13749 return ira->codegen->invalid_inst_gen;
1268513750
12686 switch (type_has_one_possible_value(ira->codegen, field_type)) {13751 switch (type_has_one_possible_value(ira->codegen, field_type)) {
12687 case OnePossibleValueInvalid:13752 case OnePossibleValueInvalid:
12688 return ira->codegen->invalid_instruction;13753 return ira->codegen->invalid_inst_gen;
12689 case OnePossibleValueNo: {13754 case OnePossibleValueNo: {
12690 AstNode *field_node = wanted_type->data.unionation.decl_node->data.container_decl.fields.at(13755 AstNode *field_node = wanted_type->data.unionation.decl_node->data.container_decl.fields.at(
12691 union_field->enum_field->decl_index);13756 union_field->enum_field->decl_index);
...@@ -12696,13 +13761,13 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so...@@ -12696,13 +13761,13 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so
12696 buf_ptr(union_field->name)));13761 buf_ptr(union_field->name)));
12697 add_error_note(ira->codegen, msg, field_node,13762 add_error_note(ira->codegen, msg, field_node,
12698 buf_sprintf("field '%s' declared here", buf_ptr(union_field->name)));13763 buf_sprintf("field '%s' declared here", buf_ptr(union_field->name)));
12699 return ira->codegen->invalid_instruction;13764 return ira->codegen->invalid_inst_gen;
12700 }13765 }
12701 case OnePossibleValueYes:13766 case OnePossibleValueYes:
12702 break;13767 break;
12703 }13768 }
1270413769
12705 IrInstruction *result = ir_const(ira, source_instr, wanted_type);13770 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
12706 result->value->special = ConstValSpecialStatic;13771 result->value->special = ConstValSpecialStatic;
12707 result->value->type = wanted_type;13772 result->value->type = wanted_type;
12708 bigint_init_bigint(&result->value->data.x_union.tag, &val->data.x_enum_tag);13773 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...@@ -12715,9 +13780,7 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so
12715 // if the union has all fields 0 bits, we can do it13780 // if the union has all fields 0 bits, we can do it
12716 // and in fact it's a noop cast because the union value is just the enum value13781 // and in fact it's a noop cast because the union value is just the enum value
12717 if (wanted_type->data.unionation.gen_field_count == 0) {13782 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);13783 return ir_build_cast(ira, &target->base, wanted_type, target, CastOpNoop);
12719 result->value->type = wanted_type;
12720 return result;
12721 }13784 }
1272213785
12723 ErrorMsg *msg = ir_add_error(ira, source_instr,13786 ErrorMsg *msg = ir_add_error(ira, source_instr,
...@@ -12727,10 +13790,10 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so...@@ -12727,10 +13790,10 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so
12727 TypeUnionField *union_field = &wanted_type->data.unionation.fields[i];13790 TypeUnionField *union_field = &wanted_type->data.unionation.fields[i];
12728 ZigType *field_type = resolve_union_field_type(ira->codegen, union_field);13791 ZigType *field_type = resolve_union_field_type(ira->codegen, union_field);
12729 if (field_type == nullptr)13792 if (field_type == nullptr)
12730 return ira->codegen->invalid_instruction;13793 return ira->codegen->invalid_inst_gen;
12731 bool has_bits;13794 bool has_bits;
12732 if ((err = type_has_bits2(ira->codegen, field_type, &has_bits)))13795 if ((err = type_has_bits2(ira->codegen, field_type, &has_bits)))
12733 return ira->codegen->invalid_instruction;13796 return ira->codegen->invalid_inst_gen;
12734 if (has_bits) {13797 if (has_bits) {
12735 AstNode *field_node = wanted_type->data.unionation.decl_node->data.container_decl.fields.at(i);13798 AstNode *field_node = wanted_type->data.unionation.decl_node->data.container_decl.fields.at(i);
12736 add_error_note(ira->codegen, msg, field_node,13799 add_error_note(ira->codegen, msg, field_node,
...@@ -12739,23 +13802,23 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so...@@ -12739,23 +13802,23 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so
12739 buf_ptr(&field_type->name)));13802 buf_ptr(&field_type->name)));
12740 }13803 }
12741 }13804 }
12742 return ira->codegen->invalid_instruction;13805 return ira->codegen->invalid_inst_gen;
12743}13806}
1274413807
12745static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction *source_instr,13808static IrInstGen *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInst* source_instr,
12746 IrInstruction *target, ZigType *wanted_type)13809 IrInstGen *target, ZigType *wanted_type)
12747{13810{
12748 assert(wanted_type->id == ZigTypeIdInt || wanted_type->id == ZigTypeIdFloat);13811 assert(wanted_type->id == ZigTypeIdInt || wanted_type->id == ZigTypeIdFloat);
1274913812
12750 if (instr_is_comptime(target)) {13813 if (instr_is_comptime(target)) {
12751 ZigValue *val = ir_resolve_const(ira, target, UndefBad);13814 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
12752 if (!val)13815 if (!val)
12753 return ira->codegen->invalid_instruction;13816 return ira->codegen->invalid_inst_gen;
12754 if (wanted_type->id == ZigTypeIdInt) {13817 if (wanted_type->id == ZigTypeIdInt) {
12755 if (bigint_cmp_zero(&val->data.x_bigint) == CmpLT && !wanted_type->data.integral.is_signed) {13818 if (bigint_cmp_zero(&val->data.x_bigint) == CmpLT && !wanted_type->data.integral.is_signed) {
12756 ir_add_error(ira, source_instr,13819 ir_add_error(ira, source_instr,
12757 buf_sprintf("attempt to cast negative value to unsigned integer"));13820 buf_sprintf("attempt to cast negative value to unsigned integer"));
12758 return ira->codegen->invalid_instruction;13821 return ira->codegen->invalid_inst_gen;
12759 }13822 }
12760 if (!bigint_fits_in_bits(&val->data.x_bigint, wanted_type->data.integral.bit_count,13823 if (!bigint_fits_in_bits(&val->data.x_bigint, wanted_type->data.integral.bit_count,
12761 wanted_type->data.integral.is_signed))13824 wanted_type->data.integral.is_signed))
...@@ -12763,10 +13826,10 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction...@@ -12763,10 +13826,10 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction
12763 ir_add_error(ira, source_instr,13826 ir_add_error(ira, source_instr,
12764 buf_sprintf("cast from '%s' to '%s' truncates bits",13827 buf_sprintf("cast from '%s' to '%s' truncates bits",
12765 buf_ptr(&target->value->type->name), buf_ptr(&wanted_type->name)));13828 buf_ptr(&target->value->type->name), buf_ptr(&wanted_type->name)));
12766 return ira->codegen->invalid_instruction;13829 return ira->codegen->invalid_inst_gen;
12767 }13830 }
12768 }13831 }
12769 IrInstruction *result = ir_const(ira, source_instr, wanted_type);13832 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
12770 result->value->type = wanted_type;13833 result->value->type = wanted_type;
12771 if (wanted_type->id == ZigTypeIdInt) {13834 if (wanted_type->id == ZigTypeIdInt) {
12772 bigint_init_bigint(&result->value->data.x_bigint, &val->data.x_bigint);13835 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...@@ -12783,19 +13846,16 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction
12783 assert(wanted_type->id == ZigTypeIdInt);13846 assert(wanted_type->id == ZigTypeIdInt);
12784 assert(type_has_bits(target->value->type));13847 assert(type_has_bits(target->value->type));
12785 ir_build_assert_zero(ira, source_instr, target);13848 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);
12787 result->value->type = wanted_type;13850 result->value->type = wanted_type;
12788 return result;13851 return result;
12789 }13852 }
1279013853
12791 IrInstruction *result = ir_build_widen_or_shorten(&ira->new_irb, source_instr->scope,13854 return ir_build_widen_or_shorten(ira, source_instr->scope, source_instr->source_node, target, wanted_type);
12792 source_instr->source_node, target);
12793 result->value->type = wanted_type;
12794 return result;
12795}13855}
1279613856
12797static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *source_instr,13857static IrInstGen *ir_analyze_int_to_enum(IrAnalyze *ira, IrInst* source_instr,
12798 IrInstruction *target, ZigType *wanted_type)13858 IrInstGen *target, ZigType *wanted_type)
12799{13859{
12800 Error err;13860 Error err;
12801 assert(wanted_type->id == ZigTypeIdEnum);13861 assert(wanted_type->id == ZigTypeIdEnum);
...@@ -12803,14 +13863,14 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour...@@ -12803,14 +13863,14 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour
12803 ZigType *actual_type = target->value->type;13863 ZigType *actual_type = target->value->type;
1280413864
12805 if ((err = type_resolve(ira->codegen, wanted_type, ResolveStatusSizeKnown)))13865 if ((err = type_resolve(ira->codegen, wanted_type, ResolveStatusSizeKnown)))
12806 return ira->codegen->invalid_instruction;13866 return ira->codegen->invalid_inst_gen;
1280713867
12808 if (actual_type != wanted_type->data.enumeration.tag_int_type) {13868 if (actual_type != wanted_type->data.enumeration.tag_int_type) {
12809 ir_add_error(ira, source_instr,13869 ir_add_error(ira, source_instr,
12810 buf_sprintf("integer to enum cast from '%s' instead of its tag type, '%s'",13870 buf_sprintf("integer to enum cast from '%s' instead of its tag type, '%s'",
12811 buf_ptr(&actual_type->name),13871 buf_ptr(&actual_type->name),
12812 buf_ptr(&wanted_type->data.enumeration.tag_int_type->name)));13872 buf_ptr(&wanted_type->data.enumeration.tag_int_type->name)));
12813 return ira->codegen->invalid_instruction;13873 return ira->codegen->invalid_inst_gen;
12814 }13874 }
1281513875
12816 assert(actual_type->id == ZigTypeIdInt || actual_type->id == ZigTypeIdComptimeInt);13876 assert(actual_type->id == ZigTypeIdInt || actual_type->id == ZigTypeIdComptimeInt);
...@@ -12818,7 +13878,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour...@@ -12818,7 +13878,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour
12818 if (instr_is_comptime(target)) {13878 if (instr_is_comptime(target)) {
12819 ZigValue *val = ir_resolve_const(ira, target, UndefBad);13879 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
12820 if (!val)13880 if (!val)
12821 return ira->codegen->invalid_instruction;13881 return ira->codegen->invalid_inst_gen;
1282213882
12823 TypeEnumField *field = find_enum_field_by_tag(wanted_type, &val->data.x_bigint);13883 TypeEnumField *field = find_enum_field_by_tag(wanted_type, &val->data.x_bigint);
12824 if (field == nullptr && !wanted_type->data.enumeration.non_exhaustive) {13884 if (field == nullptr && !wanted_type->data.enumeration.non_exhaustive) {
...@@ -12829,28 +13889,25 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour...@@ -12829,28 +13889,25 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour
12829 buf_ptr(&wanted_type->name), buf_ptr(val_buf)));13889 buf_ptr(&wanted_type->name), buf_ptr(val_buf)));
12830 add_error_note(ira->codegen, msg, wanted_type->data.enumeration.decl_node,13890 add_error_note(ira->codegen, msg, wanted_type->data.enumeration.decl_node,
12831 buf_sprintf("'%s' declared here", buf_ptr(&wanted_type->name)));13891 buf_sprintf("'%s' declared here", buf_ptr(&wanted_type->name)));
12832 return ira->codegen->invalid_instruction;13892 return ira->codegen->invalid_inst_gen;
12833 }13893 }
1283413894
12835 IrInstruction *result = ir_const(ira, source_instr, wanted_type);13895 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
12836 bigint_init_bigint(&result->value->data.x_enum_tag, &val->data.x_bigint);13896 bigint_init_bigint(&result->value->data.x_enum_tag, &val->data.x_bigint);
12837 return result;13897 return result;
12838 }13898 }
1283913899
12840 IrInstruction *result = ir_build_int_to_enum(&ira->new_irb, source_instr->scope,13900 return ir_build_int_to_enum_gen(ira, source_instr->scope, source_instr->source_node, wanted_type, target);
12841 source_instr->source_node, nullptr, target);
12842 result->value->type = wanted_type;
12843 return result;
12844}13901}
1284513902
12846static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction *source_instr,13903static IrInstGen *ir_analyze_number_to_literal(IrAnalyze *ira, IrInst* source_instr,
12847 IrInstruction *target, ZigType *wanted_type)13904 IrInstGen *target, ZigType *wanted_type)
12848{13905{
12849 ZigValue *val = ir_resolve_const(ira, target, UndefBad);13906 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
12850 if (!val)13907 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);
12854 if (wanted_type->id == ZigTypeIdComptimeFloat) {13911 if (wanted_type->id == ZigTypeIdComptimeFloat) {
12855 float_init_float(result->value, val);13912 float_init_float(result->value, val);
12856 } else if (wanted_type->id == ZigTypeIdComptimeInt) {13913 } else if (wanted_type->id == ZigTypeIdComptimeInt) {
...@@ -12861,7 +13918,7 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction...@@ -12861,7 +13918,7 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction
12861 return result;13918 return result;
12862}13919}
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,
12865 ZigType *wanted_type)13922 ZigType *wanted_type)
12866{13923{
12867 assert(target->value->type->id == ZigTypeIdInt);13924 assert(target->value->type->id == ZigTypeIdInt);
...@@ -12871,12 +13928,12 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc...@@ -12871,12 +13928,12 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc
12871 if (instr_is_comptime(target)) {13928 if (instr_is_comptime(target)) {
12872 ZigValue *val = ir_resolve_const(ira, target, UndefBad);13929 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
12873 if (!val)13930 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
12878 if (!resolve_inferred_error_set(ira->codegen, wanted_type, source_instr->source_node)) {13935 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;
12880 }13937 }
1288113938
12882 if (type_is_global_error_set(wanted_type)) {13939 if (type_is_global_error_set(wanted_type)) {
...@@ -12888,7 +13945,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc...@@ -12888,7 +13945,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc
12888 bigint_append_buf(val_buf, &val->data.x_bigint, 10);13945 bigint_append_buf(val_buf, &val->data.x_bigint, 10);
12889 ir_add_error(ira, source_instr,13946 ir_add_error(ira, source_instr,
12890 buf_sprintf("integer value %s represents no error", buf_ptr(val_buf)));13947 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;
12892 }13949 }
1289313950
12894 size_t index = bigint_as_usize(&val->data.x_bigint);13951 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...@@ -12912,7 +13969,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc
12912 bigint_append_buf(val_buf, &val->data.x_bigint, 10);13969 bigint_append_buf(val_buf, &val->data.x_bigint, 10);
12913 ir_add_error(ira, source_instr,13970 ir_add_error(ira, source_instr,
12914 buf_sprintf("integer value %s represents no error in '%s'", buf_ptr(val_buf), buf_ptr(&wanted_type->name)));13971 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;
12916 }13973 }
1291713974
12918 result->value->data.x_err_set = err;13975 result->value->data.x_err_set = err;
...@@ -12920,12 +13977,10 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc...@@ -12920,12 +13977,10 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc
12920 }13977 }
12921 }13978 }
1292213979
12923 IrInstruction *result = ir_build_int_to_err(&ira->new_irb, source_instr->scope, source_instr->source_node, target);13980 return ir_build_int_to_err_gen(ira, source_instr->scope, source_instr->source_node, target, wanted_type);
12924 result->value->type = wanted_type;
12925 return result;
12926}13981}
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,
12929 ZigType *wanted_type)13984 ZigType *wanted_type)
12930{13985{
12931 assert(wanted_type->id == ZigTypeIdInt);13986 assert(wanted_type->id == ZigTypeIdInt);
...@@ -12935,9 +13990,9 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc...@@ -12935,9 +13990,9 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
12935 if (instr_is_comptime(target)) {13990 if (instr_is_comptime(target)) {
12936 ZigValue *val = ir_resolve_const(ira, target, UndefBad);13991 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
12937 if (!val)13992 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
12942 ErrorTableEntry *err;13997 ErrorTableEntry *err;
12943 if (err_type->id == ZigTypeIdErrorUnion) {13998 if (err_type->id == ZigTypeIdErrorUnion) {
...@@ -12957,7 +14012,7 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc...@@ -12957,7 +14012,7 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
12957 ir_add_error_node(ira, source_instr->source_node,14012 ir_add_error_node(ira, source_instr->source_node,
12958 buf_sprintf("error code '%s' does not fit in '%s'",14013 buf_sprintf("error code '%s' does not fit in '%s'",
12959 buf_ptr(&err->name), buf_ptr(&wanted_type->name)));14014 buf_ptr(&err->name), buf_ptr(&wanted_type->name)));
12960 return ira->codegen->invalid_instruction;14015 return ira->codegen->invalid_inst_gen;
12961 }14016 }
1296214017
12963 return result;14018 return result;
...@@ -12973,14 +14028,14 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc...@@ -12973,14 +14028,14 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
12973 }14028 }
12974 if (!type_is_global_error_set(err_set_type)) {14029 if (!type_is_global_error_set(err_set_type)) {
12975 if (!resolve_inferred_error_set(ira->codegen, err_set_type, source_instr->source_node)) {14030 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;
12977 }14032 }
12978 if (err_set_type->data.error_set.err_count == 0) {14033 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);
12980 bigint_init_unsigned(&result->value->data.x_bigint, 0);14035 bigint_init_unsigned(&result->value->data.x_bigint, 0);
12981 return result;14036 return result;
12982 } else if (err_set_type->data.error_set.err_count == 1) {14037 } 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);
12984 ErrorTableEntry *err = err_set_type->data.error_set.errors[0];14039 ErrorTableEntry *err = err_set_type->data.error_set.errors[0];
12985 bigint_init_unsigned(&result->value->data.x_bigint, err->value);14040 bigint_init_unsigned(&result->value->data.x_bigint, err->value);
12986 return result;14041 return result;
...@@ -12992,21 +14047,19 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc...@@ -12992,21 +14047,19 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
12992 if (!bigint_fits_in_bits(&bn, wanted_type->data.integral.bit_count, wanted_type->data.integral.is_signed)) {14047 if (!bigint_fits_in_bits(&bn, wanted_type->data.integral.bit_count, wanted_type->data.integral.is_signed)) {
12993 ir_add_error_node(ira, source_instr->source_node,14048 ir_add_error_node(ira, source_instr->source_node,
12994 buf_sprintf("too many error values to fit in '%s'", buf_ptr(&wanted_type->name)));14049 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;
12996 }14051 }
1299714052
12998 IrInstruction *result = ir_build_err_to_int(&ira->new_irb, source_instr->scope, source_instr->source_node, target);14053 return ir_build_err_to_int_gen(ira, source_instr->scope, source_instr->source_node, target, wanted_type);
12999 result->value->type = wanted_type;
13000 return result;
13001}14054}
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,
13004 ZigType *wanted_type)14057 ZigType *wanted_type)
13005{14058{
13006 assert(wanted_type->id == ZigTypeIdPointer);14059 assert(wanted_type->id == ZigTypeIdPointer);
13007 Error err;14060 Error err;
13008 if ((err = type_resolve(ira->codegen, target->value->type->data.pointer.child_type, ResolveStatusAlignmentKnown)))14061 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;
13010 assert((wanted_type->data.pointer.is_const && target->value->type->data.pointer.is_const) || !target->value->type->data.pointer.is_const);14063 assert((wanted_type->data.pointer.is_const && target->value->type->data.pointer.is_const) || !target->value->type->data.pointer.is_const);
13011 wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, target->value->type));14064 wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, target->value->type));
13012 ZigType *array_type = wanted_type->data.pointer.child_type;14065 ZigType *array_type = wanted_type->data.pointer.child_type;
...@@ -13016,12 +14069,12 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou...@@ -13016,12 +14069,12 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou
13016 if (instr_is_comptime(target)) {14069 if (instr_is_comptime(target)) {
13017 ZigValue *val = ir_resolve_const(ira, target, UndefBad);14070 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
13018 if (!val)14071 if (!val)
13019 return ira->codegen->invalid_instruction;14072 return ira->codegen->invalid_inst_gen;
1302014073
13021 assert(val->type->id == ZigTypeIdPointer);14074 assert(val->type->id == ZigTypeIdPointer);
13022 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node);14075 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node);
13023 if (pointee == nullptr)14076 if (pointee == nullptr)
13024 return ira->codegen->invalid_instruction;14077 return ira->codegen->invalid_inst_gen;
13025 if (pointee->special != ConstValSpecialRuntime) {14078 if (pointee->special != ConstValSpecialRuntime) {
13026 ZigValue *array_val = create_const_vals(1);14079 ZigValue *array_val = create_const_vals(1);
13027 array_val->special = ConstValSpecialStatic;14080 array_val->special = ConstValSpecialStatic;
...@@ -13031,7 +14084,7 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou...@@ -13031,7 +14084,7 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou
13031 array_val->parent.id = ConstParentIdScalar;14084 array_val->parent.id = ConstParentIdScalar;
13032 array_val->parent.data.p_scalar.scalar_val = pointee;14085 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,
13035 source_instr->scope, source_instr->source_node);14088 source_instr->scope, source_instr->source_node);
13036 const_instruction->base.value->type = wanted_type;14089 const_instruction->base.value->type = wanted_type;
13037 const_instruction->base.value->special = ConstValSpecialStatic;14090 const_instruction->base.value->special = ConstValSpecialStatic;
...@@ -13043,10 +14096,7 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou...@@ -13043,10 +14096,7 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou
13043 }14096 }
1304414097
13045 // pointer to array and pointer to single item are represented the same way at runtime14098 // 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,14099 return ir_build_cast(ira, &target->base, wanted_type, target, CastOpBitCast);
13047 wanted_type, target, CastOpBitCast);
13048 result->value->type = wanted_type;
13049 return result;
13050}14100}
1305114101
13052static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCastOnly *cast_result,14102static 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...@@ -13234,12 +14284,12 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa
13234 }14284 }
13235}14285}
1323614286
13237static IrInstruction *ir_analyze_array_to_vector(IrAnalyze *ira, IrInstruction *source_instr,14287static IrInstGen *ir_analyze_array_to_vector(IrAnalyze *ira, IrInst* source_instr,
13238 IrInstruction *array, ZigType *vector_type)14288 IrInstGen *array, ZigType *vector_type)
13239{14289{
13240 if (instr_is_comptime(array)) {14290 if (instr_is_comptime(array)) {
13241 // arrays and vectors have the same ZigValue representation14291 // 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);
13243 copy_const_val(result->value, array->value);14293 copy_const_val(result->value, array->value);
13244 result->value->type = vector_type;14294 result->value->type = vector_type;
13245 return result;14295 return result;
...@@ -13247,12 +14297,12 @@ static IrInstruction *ir_analyze_array_to_vector(IrAnalyze *ira, IrInstruction *...@@ -13247,12 +14297,12 @@ static IrInstruction *ir_analyze_array_to_vector(IrAnalyze *ira, IrInstruction *
13247 return ir_build_array_to_vector(ira, source_instr, array, vector_type);14297 return ir_build_array_to_vector(ira, source_instr, array, vector_type);
13248}14298}
1324914299
13250static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction *source_instr,14300static IrInstGen *ir_analyze_vector_to_array(IrAnalyze *ira, IrInst* source_instr,
13251 IrInstruction *vector, ZigType *array_type, ResultLoc *result_loc)14301 IrInstGen *vector, ZigType *array_type, ResultLoc *result_loc)
13252{14302{
13253 if (instr_is_comptime(vector)) {14303 if (instr_is_comptime(vector)) {
13254 // arrays and vectors have the same ZigValue representation14304 // 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);
13256 copy_const_val(result->value, vector->value);14306 copy_const_val(result->value, vector->value);
13257 result->value->type = array_type;14307 result->value->type = array_type;
13258 return result;14308 return result;
...@@ -13260,18 +14310,18 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction *...@@ -13260,18 +14310,18 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction *
13260 if (result_loc == nullptr) {14310 if (result_loc == nullptr) {
13261 result_loc = no_result_loc();14311 result_loc = no_result_loc();
13262 }14312 }
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,
13264 true, false, true);14314 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) {
13266 return result_loc_inst;14316 return result_loc_inst;
13267 }14317 }
13268 return ir_build_vector_to_array(ira, source_instr, array_type, vector, result_loc_inst);14318 return ir_build_vector_to_array(ira, source_instr, array_type, vector, result_loc_inst);
13269}14319}
1327014320
13271static IrInstruction *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInstruction *source_instr,14321static IrInstGen *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInst* source_instr,
13272 IrInstruction *integer, ZigType *dest_type)14322 IrInstGen *integer, ZigType *dest_type)
13273{14323{
13274 IrInstruction *unsigned_integer;14324 IrInstGen *unsigned_integer;
13275 if (instr_is_comptime(integer)) {14325 if (instr_is_comptime(integer)) {
13276 unsigned_integer = integer;14326 unsigned_integer = integer;
13277 } else {14327 } else {
...@@ -13284,7 +14334,7 @@ static IrInstruction *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInstruction *sou...@@ -13284,7 +14334,7 @@ static IrInstruction *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInstruction *sou
13284 buf_sprintf("integer type '%s' too big for implicit @intToPtr to type '%s'",14334 buf_sprintf("integer type '%s' too big for implicit @intToPtr to type '%s'",
13285 buf_ptr(&integer->value->type->name),14335 buf_ptr(&integer->value->type->name),
13286 buf_ptr(&dest_type->name)));14336 buf_ptr(&dest_type->name)));
13287 return ira->codegen->invalid_instruction;14337 return ira->codegen->invalid_inst_gen;
13288 }14338 }
1328914339
13290 if (integer->value->type->data.integral.is_signed) {14340 if (integer->value->type->data.integral.is_signed) {
...@@ -13292,7 +14342,7 @@ static IrInstruction *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInstruction *sou...@@ -13292,7 +14342,7 @@ static IrInstruction *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInstruction *sou
13292 integer->value->type->data.integral.bit_count);14342 integer->value->type->data.integral.bit_count);
13293 unsigned_integer = ir_analyze_bit_cast(ira, source_instr, integer, unsigned_int_type);14343 unsigned_integer = ir_analyze_bit_cast(ira, source_instr, integer, unsigned_int_type);
13294 if (type_is_invalid(unsigned_integer->value->type))14344 if (type_is_invalid(unsigned_integer->value->type))
13295 return ira->codegen->invalid_instruction;14345 return ira->codegen->invalid_inst_gen;
13296 } else {14346 } else {
13297 unsigned_integer = integer;14347 unsigned_integer = integer;
13298 }14348 }
...@@ -13312,14 +14362,14 @@ static bool is_pointery_and_elem_is_not_pointery(ZigType *ty) {...@@ -13312,14 +14362,14 @@ static bool is_pointery_and_elem_is_not_pointery(ZigType *ty) {
13312 return false;14362 return false;
13313}14363}
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,
13316 ZigType *enum_type)14366 ZigType *enum_type)
13317{14367{
13318 assert(enum_type->id == ZigTypeIdEnum);14368 assert(enum_type->id == ZigTypeIdEnum);
1331914369
13320 Error err;14370 Error err;
13321 if ((err = type_resolve(ira->codegen, enum_type, ResolveStatusZeroBitsKnown)))14371 if ((err = type_resolve(ira->codegen, enum_type, ResolveStatusZeroBitsKnown)))
13322 return ira->codegen->invalid_instruction;14372 return ira->codegen->invalid_inst_gen;
1332314373
13324 TypeEnumField *field = find_enum_type_field(enum_type, value->value->data.x_enum_literal);14374 TypeEnumField *field = find_enum_type_field(enum_type, value->value->data.x_enum_literal);
13325 if (field == nullptr) {14375 if (field == nullptr) {
...@@ -13327,40 +14377,40 @@ static IrInstruction *ir_analyze_enum_literal(IrAnalyze *ira, IrInstruction *sou...@@ -13327,40 +14377,40 @@ static IrInstruction *ir_analyze_enum_literal(IrAnalyze *ira, IrInstruction *sou
13327 buf_ptr(&enum_type->name), buf_ptr(value->value->data.x_enum_literal)));14377 buf_ptr(&enum_type->name), buf_ptr(value->value->data.x_enum_literal)));
13328 add_error_note(ira->codegen, msg, enum_type->data.enumeration.decl_node,14378 add_error_note(ira->codegen, msg, enum_type->data.enumeration.decl_node,
13329 buf_sprintf("'%s' declared here", buf_ptr(&enum_type->name)));14379 buf_sprintf("'%s' declared here", buf_ptr(&enum_type->name)));
13330 return ira->codegen->invalid_instruction;14380 return ira->codegen->invalid_inst_gen;
13331 }14381 }
13332 IrInstruction *result = ir_const(ira, source_instr, enum_type);14382 IrInstGen *result = ir_const(ira, source_instr, enum_type);
13333 bigint_init_bigint(&result->value->data.x_enum_tag, &field->value);14383 bigint_init_bigint(&result->value->data.x_enum_tag, &field->value);
1333414384
13335 return result;14385 return result;
13336}14386}
1333714387
13338static IrInstruction *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInstruction *source_instr,14388static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInst* source_instr,
13339 IrInstruction *value, ZigType *wanted_type)14389 IrInstGen *value, ZigType *wanted_type)
13340{14390{
13341 ir_add_error(ira, source_instr, buf_sprintf("TODO: type coercion of anon list literal to array"));14391 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;
13343}14393}
1334414394
13345static IrInstruction *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInstruction *source_instr,14395static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* source_instr,
13346 IrInstruction *value, ZigType *wanted_type)14396 IrInstGen *value, ZigType *wanted_type)
13347{14397{
13348 ir_add_error(ira, source_instr, buf_sprintf("TODO: type coercion of anon struct literal to struct"));14398 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;
13350}14400}
1335114401
13352static IrInstruction *ir_analyze_struct_literal_to_union(IrAnalyze *ira, IrInstruction *source_instr,14402static IrInstGen *ir_analyze_struct_literal_to_union(IrAnalyze *ira, IrInst* source_instr,
13353 IrInstruction *value, ZigType *wanted_type)14403 IrInstGen *value, ZigType *wanted_type)
13354{14404{
13355 ir_add_error(ira, source_instr, buf_sprintf("TODO: type coercion of anon struct literal to union"));14405 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;
13357}14407}
1335814408
13359// Add a compile error and return ErrorSemanticAnalyzeFail if the pointer alignment does not work,14409// Add a compile error and return ErrorSemanticAnalyzeFail if the pointer alignment does not work,
13360// otherwise return ErrorNone. Does not emit any instructions.14410// otherwise return ErrorNone. Does not emit any instructions.
13361// Assumes that the pointer types have element types with the same ABI alignment. Avoids resolving the14411// Assumes that the pointer types have element types with the same ABI alignment. Avoids resolving the
13362// pointer types' alignments if both of the pointer types are ABI aligned.14412// 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,
13364 ZigType *src_ptr_type, AstNode *src_source_node)14414 ZigType *src_ptr_type, AstNode *src_source_node)
13365{14415{
13366 Error err;14416 Error err;
...@@ -13394,37 +14444,37 @@ static Error ir_cast_ptr_align(IrAnalyze *ira, IrInstruction *source_instr, ZigT...@@ -13394,37 +14444,37 @@ static Error ir_cast_ptr_align(IrAnalyze *ira, IrInstruction *source_instr, ZigT
13394 return ErrorNone;14444 return ErrorNone;
13395}14445}
1339614446
13397static IrInstruction *ir_analyze_struct_value_field_value(IrAnalyze *ira, IrInstruction *source_instr,14447static IrInstGen *ir_analyze_struct_value_field_value(IrAnalyze *ira, IrInst* source_instr,
13398 IrInstruction *struct_operand, TypeStructField *field)14448 IrInstGen *struct_operand, TypeStructField *field)
13399{14449{
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);
13401 if (type_is_invalid(struct_ptr->value->type))14451 if (type_is_invalid(struct_ptr->value->type))
13402 return ira->codegen->invalid_instruction;14452 return ira->codegen->invalid_inst_gen;
13403 IrInstruction *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, struct_ptr,14453 IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, struct_ptr,
13404 struct_operand->value->type, false);14454 struct_operand->value->type, false);
13405 if (type_is_invalid(field_ptr->value->type))14455 if (type_is_invalid(field_ptr->value->type))
13406 return ira->codegen->invalid_instruction;14456 return ira->codegen->invalid_inst_gen;
13407 return ir_get_deref(ira, source_instr, field_ptr, nullptr);14457 return ir_get_deref(ira, source_instr, field_ptr, nullptr);
13408}14458}
1340914459
13410static IrInstruction *ir_analyze_optional_value_payload_value(IrAnalyze *ira, IrInstruction *source_instr,14460static IrInstGen *ir_analyze_optional_value_payload_value(IrAnalyze *ira, IrInst* source_instr,
13411 IrInstruction *optional_operand, bool safety_check_on)14461 IrInstGen *optional_operand, bool safety_check_on)
13412{14462{
13413 IrInstruction *opt_ptr = ir_get_ref(ira, source_instr, optional_operand, true, false);14463 IrInstGen *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,14464 IrInstGen *payload_ptr = ir_analyze_unwrap_optional_payload(ira, source_instr, opt_ptr,
13415 safety_check_on, false);14465 safety_check_on, false);
13416 return ir_get_deref(ira, source_instr, payload_ptr, nullptr);14466 return ir_get_deref(ira, source_instr, payload_ptr, nullptr);
13417}14467}
1341814468
13419static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_instr,14469static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
13420 ZigType *wanted_type, IrInstruction *value)14470 ZigType *wanted_type, IrInstGen *value)
13421{14471{
13422 Error err;14472 Error err;
13423 ZigType *actual_type = value->value->type;14473 ZigType *actual_type = value->value->type;
13424 AstNode *source_node = source_instr->source_node;14474 AstNode *source_node = source_instr->source_node;
1342514475
13426 if (type_is_invalid(wanted_type) || type_is_invalid(actual_type)) {14476 if (type_is_invalid(wanted_type) || type_is_invalid(actual_type)) {
13427 return ira->codegen->invalid_instruction;14477 return ira->codegen->invalid_inst_gen;
13428 }14478 }
1342914479
13430 // This means the wanted type is anything.14480 // This means the wanted type is anything.
...@@ -13436,7 +14486,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13436,7 +14486,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13436 ConstCastOnly const_cast_result = types_match_const_cast_only(ira, wanted_type, actual_type,14486 ConstCastOnly const_cast_result = types_match_const_cast_only(ira, wanted_type, actual_type,
13437 source_node, false);14487 source_node, false);
13438 if (const_cast_result.id == ConstCastResultIdInvalid)14488 if (const_cast_result.id == ConstCastResultIdInvalid)
13439 return ira->codegen->invalid_instruction;14489 return ira->codegen->invalid_inst_gen;
13440 if (const_cast_result.id == ConstCastResultIdOk) {14490 if (const_cast_result.id == ConstCastResultIdOk) {
13441 return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpNoop);14491 return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpNoop);
13442 }14492 }
...@@ -13470,7 +14520,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13470,7 +14520,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13470 if (ir_num_lit_fits_in_other_type(ira, value, wanted_child_type, true)) {14520 if (ir_num_lit_fits_in_other_type(ira, value, wanted_child_type, true)) {
13471 return ir_analyze_optional_wrap(ira, source_instr, value, wanted_type, nullptr);14521 return ir_analyze_optional_wrap(ira, source_instr, value, wanted_type, nullptr);
13472 } else {14522 } else {
13473 return ira->codegen->invalid_instruction;14523 return ira->codegen->invalid_inst_gen;
13474 }14524 }
13475 } else if (14525 } else if (
13476 wanted_child_type->id == ZigTypeIdPointer &&14526 wanted_child_type->id == ZigTypeIdPointer &&
...@@ -13480,18 +14530,18 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13480,18 +14530,18 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13480 actual_type->data.pointer.child_type->id == ZigTypeIdArray)14530 actual_type->data.pointer.child_type->id == ZigTypeIdArray)
13481 {14531 {
13482 if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type, ResolveStatusAlignmentKnown)))14532 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;
13484 if ((err = type_resolve(ira->codegen, wanted_child_type->data.pointer.child_type, ResolveStatusAlignmentKnown)))14534 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;
13486 if (get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, wanted_child_type) &&14536 if (get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, wanted_child_type) &&
13487 types_match_const_cast_only(ira, wanted_child_type->data.pointer.child_type,14537 types_match_const_cast_only(ira, wanted_child_type->data.pointer.child_type,
13488 actual_type->data.pointer.child_type->data.array.child_type, source_node,14538 actual_type->data.pointer.child_type->data.array.child_type, source_node,
13489 !wanted_child_type->data.pointer.is_const).id == ConstCastResultIdOk)14539 !wanted_child_type->data.pointer.is_const).id == ConstCastResultIdOk)
13490 {14540 {
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,
13492 wanted_child_type);14542 wanted_child_type);
13493 if (type_is_invalid(cast1->value->type))14543 if (type_is_invalid(cast1->value->type))
13494 return ira->codegen->invalid_instruction;14544 return ira->codegen->invalid_inst_gen;
13495 return ir_analyze_optional_wrap(ira, source_instr, cast1, wanted_type, nullptr);14545 return ir_analyze_optional_wrap(ira, source_instr, cast1, wanted_type, nullptr);
13496 }14546 }
13497 }14547 }
...@@ -13509,7 +14559,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13509,7 +14559,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13509 if (ir_num_lit_fits_in_other_type(ira, value, wanted_type->data.error_union.payload_type, true)) {14559 if (ir_num_lit_fits_in_other_type(ira, value, wanted_type->data.error_union.payload_type, true)) {
13510 return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type, nullptr);14560 return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type, nullptr);
13511 } else {14561 } else {
13512 return ira->codegen->invalid_instruction;14562 return ira->codegen->invalid_inst_gen;
13513 }14563 }
13514 }14564 }
13515 }14565 }
...@@ -13525,13 +14575,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13525,13 +14575,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13525 actual_type->id == ZigTypeIdComptimeInt ||14575 actual_type->id == ZigTypeIdComptimeInt ||
13526 actual_type->id == ZigTypeIdComptimeFloat)14576 actual_type->id == ZigTypeIdComptimeFloat)
13527 {14577 {
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);
13529 if (type_is_invalid(cast1->value->type))14579 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);
13533 if (type_is_invalid(cast2->value->type))14583 if (type_is_invalid(cast2->value->type))
13534 return ira->codegen->invalid_instruction;14584 return ira->codegen->invalid_inst_gen;
1353514585
13536 return cast2;14586 return cast2;
13537 }14587 }
...@@ -13546,13 +14596,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13546,13 +14596,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13546 wanted_type->id == ZigTypeIdFloat || wanted_type->id == ZigTypeIdComptimeFloat))14596 wanted_type->id == ZigTypeIdFloat || wanted_type->id == ZigTypeIdComptimeFloat))
13547 {14597 {
13548 if (value->value->special == ConstValSpecialUndef) {14598 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);
13550 result->value->special = ConstValSpecialUndef;14600 result->value->special = ConstValSpecialUndef;
13551 return result;14601 return result;
13552 }14602 }
13553 if (ir_num_lit_fits_in_other_type(ira, value, wanted_type, true)) {14603 if (ir_num_lit_fits_in_other_type(ira, value, wanted_type, true)) {
13554 if (wanted_type->id == ZigTypeIdComptimeInt || wanted_type->id == ZigTypeIdInt) {14604 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);
13556 if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) {14606 if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) {
13557 copy_const_val(result->value, value->value);14607 copy_const_val(result->value, value->value);
13558 result->value->type = wanted_type;14608 result->value->type = wanted_type;
...@@ -13561,7 +14611,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13561,7 +14611,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13561 }14611 }
13562 return result;14612 return result;
13563 } else if (wanted_type->id == ZigTypeIdComptimeFloat || wanted_type->id == ZigTypeIdFloat) {14613 } 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);
13565 if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) {14615 if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) {
13566 BigFloat bf;14616 BigFloat bf;
13567 bigfloat_init_bigint(&bf, &value->value->data.x_bigint);14617 bigfloat_init_bigint(&bf, &value->value->data.x_bigint);
...@@ -13573,7 +14623,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13573,7 +14623,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13573 }14623 }
13574 zig_unreachable();14624 zig_unreachable();
13575 } else {14625 } else {
13576 return ira->codegen->invalid_instruction;14626 return ira->codegen->invalid_inst_gen;
13577 }14627 }
13578 }14628 }
1357914629
...@@ -13609,13 +14659,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13609,13 +14659,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13609 actual_type->data.pointer.ptr_len == PtrLenSingle &&14659 actual_type->data.pointer.ptr_len == PtrLenSingle &&
13610 actual_type->data.pointer.child_type->id == ZigTypeIdArray)14660 actual_type->data.pointer.child_type->id == ZigTypeIdArray)
13611 {14661 {
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);
13613 if (type_is_invalid(cast1->value->type))14663 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);
13617 if (type_is_invalid(cast2->value->type))14667 if (type_is_invalid(cast2->value->type))
13618 return ira->codegen->invalid_instruction;14668 return ira->codegen->invalid_inst_gen;
1361914669
13620 return cast2;14670 return cast2;
13621 }14671 }
...@@ -13636,9 +14686,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13636,9 +14686,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13636 actual_array_type->data.array.sentinel)))14686 actual_array_type->data.array.sentinel)))
13637 {14687 {
13638 if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type, ResolveStatusAlignmentKnown)))14688 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;
13640 if ((err = type_resolve(ira->codegen, wanted_type->data.pointer.child_type, ResolveStatusAlignmentKnown)))14690 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;
13642 if (get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, wanted_type) &&14692 if (get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, wanted_type) &&
13643 types_match_const_cast_only(ira, wanted_type->data.pointer.child_type,14693 types_match_const_cast_only(ira, wanted_type->data.pointer.child_type,
13644 actual_type->data.pointer.child_type->data.array.child_type, source_node,14694 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...@@ -13679,24 +14729,24 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13679 if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type,14729 if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type,
13680 ResolveStatusAlignmentKnown)))14730 ResolveStatusAlignmentKnown)))
13681 {14731 {
13682 return ira->codegen->invalid_instruction;14732 return ira->codegen->invalid_inst_gen;
13683 }14733 }
13684 if ((err = type_resolve(ira->codegen, slice_ptr_type->data.pointer.child_type,14734 if ((err = type_resolve(ira->codegen, slice_ptr_type->data.pointer.child_type,
13685 ResolveStatusAlignmentKnown)))14735 ResolveStatusAlignmentKnown)))
13686 {14736 {
13687 return ira->codegen->invalid_instruction;14737 return ira->codegen->invalid_inst_gen;
13688 }14738 }
13689 ok_align = get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, slice_ptr_type);14739 ok_align = get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, slice_ptr_type);
13690 }14740 }
13691 if (ok_align) {14741 if (ok_align) {
13692 if (wanted_type->id == ZigTypeIdErrorUnion) {14742 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);
13694 if (type_is_invalid(cast1->value->type))14744 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);
13698 if (type_is_invalid(cast2->value->type))14748 if (type_is_invalid(cast2->value->type))
13699 return ira->codegen->invalid_instruction;14749 return ira->codegen->invalid_inst_gen;
1370014750
13701 return cast2;14751 return cast2;
13702 } else {14752 } else {
...@@ -13731,12 +14781,12 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13731,12 +14781,12 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13731 if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type,14781 if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type,
13732 ResolveStatusAlignmentKnown)))14782 ResolveStatusAlignmentKnown)))
13733 {14783 {
13734 return ira->codegen->invalid_instruction;14784 return ira->codegen->invalid_inst_gen;
13735 }14785 }
13736 if ((err = type_resolve(ira->codegen, slice_ptr_type->data.pointer.child_type,14786 if ((err = type_resolve(ira->codegen, slice_ptr_type->data.pointer.child_type,
13737 ResolveStatusAlignmentKnown)))14787 ResolveStatusAlignmentKnown)))
13738 {14788 {
13739 return ira->codegen->invalid_instruction;14789 return ira->codegen->invalid_inst_gen;
13740 }14790 }
13741 ok_align = get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, slice_ptr_type);14791 ok_align = get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, slice_ptr_type);
13742 }14792 }
...@@ -13777,7 +14827,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13777,7 +14827,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13777 }14827 }
13778 }14828 }
13779 if (ok) {14829 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);
13781 if (anyframe_type == wanted_type)14831 if (anyframe_type == wanted_type)
13782 return cast1;14832 return cast1;
13783 return ir_analyze_cast(ira, source_instr, wanted_type, cast1);14833 return ir_analyze_cast(ira, source_instr, wanted_type, cast1);
...@@ -13832,28 +14882,28 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13832,28 +14882,28 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13832 if (actual_type->id == ZigTypeIdEnumLiteral &&14882 if (actual_type->id == ZigTypeIdEnumLiteral &&
13833 (wanted_type->id == ZigTypeIdOptional && wanted_type->data.maybe.child_type->id == ZigTypeIdEnum))14883 (wanted_type->id == ZigTypeIdOptional && wanted_type->data.maybe.child_type->id == ZigTypeIdEnum))
13834 {14884 {
13835 IrInstruction *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.maybe.child_type);14885 IrInstGen *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.maybe.child_type);
13836 if (result == ira->codegen->invalid_instruction)14886 if (type_is_invalid(result->value->type))
13837 return result;14887 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);
13840 }14890 }
1384114891
13842 // cast from enum literal to error union when payload is an enum14892 // cast from enum literal to error union when payload is an enum
13843 if (actual_type->id == ZigTypeIdEnumLiteral &&14893 if (actual_type->id == ZigTypeIdEnumLiteral &&
13844 (wanted_type->id == ZigTypeIdErrorUnion && wanted_type->data.error_union.payload_type->id == ZigTypeIdEnum))14894 (wanted_type->id == ZigTypeIdErrorUnion && wanted_type->data.error_union.payload_type->id == ZigTypeIdEnum))
13845 {14895 {
13846 IrInstruction *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.error_union.payload_type);14896 IrInstGen *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.error_union.payload_type);
13847 if (result == ira->codegen->invalid_instruction)14897 if (type_is_invalid(result->value->type))
13848 return result;14898 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);
13851 }14901 }
1385214902
13853 // cast from union to the enum type of the union14903 // cast from union to the enum type of the union
13854 if (actual_type->id == ZigTypeIdUnion && wanted_type->id == ZigTypeIdEnum) {14904 if (actual_type->id == ZigTypeIdUnion && wanted_type->id == ZigTypeIdEnum) {
13855 if ((err = type_resolve(ira->codegen, actual_type, ResolveStatusZeroBitsKnown)))14905 if ((err = type_resolve(ira->codegen, actual_type, ResolveStatusZeroBitsKnown)))
13856 return ira->codegen->invalid_instruction;14906 return ira->codegen->invalid_inst_gen;
1385714907
13858 if (actual_type->data.unionation.tag_type == wanted_type) {14908 if (actual_type->data.unionation.tag_type == wanted_type) {
13859 return ir_analyze_union_to_tag(ira, source_instr, value, wanted_type);14909 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...@@ -13881,8 +14931,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13881 (!actual_type->data.pointer.is_const || wanted_type->data.pointer.is_const) &&14931 (!actual_type->data.pointer.is_const || wanted_type->data.pointer.is_const) &&
13882 (!actual_type->data.pointer.is_volatile || wanted_type->data.pointer.is_volatile))14932 (!actual_type->data.pointer.is_volatile || wanted_type->data.pointer.is_volatile))
13883 {14933 {
13884 if ((err = ir_cast_ptr_align(ira, source_instr, wanted_type, actual_type, value->source_node)))14934 if ((err = ir_cast_ptr_align(ira, source_instr, wanted_type, actual_type, value->base.source_node)))
13885 return ira->codegen->invalid_instruction;14935 return ira->codegen->invalid_inst_gen;
1388614936
13887 return ir_analyze_ptr_to_array(ira, source_instr, value, wanted_type);14937 return ir_analyze_ptr_to_array(ira, source_instr, value, wanted_type);
13888 }14938 }
...@@ -13905,7 +14955,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13905,7 +14955,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13905 slice_ptr_type->data.pointer.sentinel))))14955 slice_ptr_type->data.pointer.sentinel))))
13906 {14956 {
13907 TypeStructField *ptr_field = actual_type->data.structure.fields[slice_ptr_index];14957 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);
13909 return ir_implicit_cast2(ira, source_instr, slice_ptr, wanted_type);14959 return ir_implicit_cast2(ira, source_instr, slice_ptr, wanted_type);
13910 }14960 }
13911 }14961 }
...@@ -13936,7 +14986,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13936,7 +14986,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13936 {14986 {
13937 bool has_bits;14987 bool has_bits;
13938 if ((err = type_has_bits2(ira->codegen, actual_type, &has_bits)))14988 if ((err = type_has_bits2(ira->codegen, actual_type, &has_bits)))
13939 return ira->codegen->invalid_instruction;14989 return ira->codegen->invalid_inst_gen;
13940 if (!has_bits) {14990 if (!has_bits) {
13941 return ir_get_ref(ira, source_instr, value, false, false);14991 return ir_get_ref(ira, source_instr, value, false, false);
13942 }14992 }
...@@ -14003,9 +15053,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -14003,9 +15053,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1400315053
14004 // T to ?U, where T implicitly casts to U15054 // T to ?U, where T implicitly casts to U
14005 if (wanted_type->id == ZigTypeIdOptional && actual_type->id != ZigTypeIdOptional) {15055 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);
14007 if (type_is_invalid(cast1->value->type))15057 if (type_is_invalid(cast1->value->type))
14008 return ira->codegen->invalid_instruction;15058 return ira->codegen->invalid_inst_gen;
14009 return ir_implicit_cast2(ira, source_instr, cast1, wanted_type);15059 return ir_implicit_cast2(ira, source_instr, cast1, wanted_type);
14010 }15060 }
1401115061
...@@ -14013,9 +15063,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -14013,9 +15063,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
14013 if (wanted_type->id == ZigTypeIdErrorUnion && actual_type->id != ZigTypeIdErrorUnion &&15063 if (wanted_type->id == ZigTypeIdErrorUnion && actual_type->id != ZigTypeIdErrorUnion &&
14014 actual_type->id != ZigTypeIdErrorSet)15064 actual_type->id != ZigTypeIdErrorSet)
14015 {15065 {
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);
14017 if (type_is_invalid(cast1->value->type))15067 if (type_is_invalid(cast1->value->type))
14018 return ira->codegen->invalid_instruction;15068 return ira->codegen->invalid_inst_gen;
14019 return ir_implicit_cast2(ira, source_instr, cast1, wanted_type);15069 return ir_implicit_cast2(ira, source_instr, cast1, wanted_type);
14020 }15070 }
1402115071
...@@ -14024,14 +15074,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -14024,14 +15074,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
14024 buf_ptr(&wanted_type->name),15074 buf_ptr(&wanted_type->name),
14025 buf_ptr(&actual_type->name)));15075 buf_ptr(&actual_type->name)));
14026 report_recursive_error(ira, source_instr->source_node, &const_cast_result, parent_msg);15076 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;
14028}15078}
1402915079
14030static IrInstruction *ir_implicit_cast2(IrAnalyze *ira, IrInstruction *value_source_instr,15080static IrInstGen *ir_implicit_cast2(IrAnalyze *ira, IrInst *value_source_instr,
14031 IrInstruction *value, ZigType *expected_type)15081 IrInstGen *value, ZigType *expected_type)
14032{15082{
14033 assert(value);15083 assert(value);
14034 assert(value != ira->codegen->invalid_instruction);
14035 assert(!expected_type || !type_is_invalid(expected_type));15084 assert(!expected_type || !type_is_invalid(expected_type));
14036 assert(value->value->type);15085 assert(value->value->type);
14037 assert(!type_is_invalid(value->value->type));15086 assert(!type_is_invalid(value->value->type));
...@@ -14045,17 +15094,17 @@ static IrInstruction *ir_implicit_cast2(IrAnalyze *ira, IrInstruction *value_sou...@@ -14045,17 +15094,17 @@ static IrInstruction *ir_implicit_cast2(IrAnalyze *ira, IrInstruction *value_sou
14045 return ir_analyze_cast(ira, value_source_instr, expected_type, value);15094 return ir_analyze_cast(ira, value_source_instr, expected_type, value);
14046}15095}
1404715096
14048static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type) {15097static IrInstGen *ir_implicit_cast(IrAnalyze *ira, IrInstGen *value, ZigType *expected_type) {
14049 return ir_implicit_cast2(ira, value, value, expected_type);15098 return ir_implicit_cast2(ira, &value->base, value, expected_type);
14050}15099}
1405115100
14052static ZigType *get_ptr_elem_type(CodeGen *g, IrInstruction *ptr) {15101static ZigType *get_ptr_elem_type(CodeGen *g, IrInstGen *ptr) {
14053 ir_assert(ptr->value->type->id == ZigTypeIdPointer, ptr);15102 ir_assert_gen(ptr->value->type->id == ZigTypeIdPointer, ptr);
14054 ZigType *elem_type = ptr->value->type->data.pointer.child_type;15103 ZigType *elem_type = ptr->value->type->data.pointer.child_type;
14055 if (elem_type != g->builtin_types.entry_var)15104 if (elem_type != g->builtin_types.entry_var)
14056 return elem_type;15105 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))
14059 return g->builtin_types.entry_invalid;15108 return g->builtin_types.entry_invalid;
1406015109
14061 assert(value_is_comptime(ptr->value));15110 assert(value_is_comptime(ptr->value));
...@@ -14063,28 +15112,28 @@ static ZigType *get_ptr_elem_type(CodeGen *g, IrInstruction *ptr) {...@@ -14063,28 +15112,28 @@ static ZigType *get_ptr_elem_type(CodeGen *g, IrInstruction *ptr) {
14063 return pointee->type;15112 return pointee->type;
14064}15113}
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,
14067 ResultLoc *result_loc)15116 ResultLoc *result_loc)
14068{15117{
14069 Error err;15118 Error err;
14070 ZigType *ptr_type = ptr->value->type;15119 ZigType *ptr_type = ptr->value->type;
14071 if (type_is_invalid(ptr_type))15120 if (type_is_invalid(ptr_type))
14072 return ira->codegen->invalid_instruction;15121 return ira->codegen->invalid_inst_gen;
1407315122
14074 if (ptr_type->id != ZigTypeIdPointer) {15123 if (ptr_type->id != ZigTypeIdPointer) {
14075 ir_add_error_node(ira, source_instruction->source_node,15124 ir_add_error_node(ira, source_instruction->source_node,
14076 buf_sprintf("attempt to dereference non-pointer type '%s'",15125 buf_sprintf("attempt to dereference non-pointer type '%s'",
14077 buf_ptr(&ptr_type->name)));15126 buf_ptr(&ptr_type->name)));
14078 return ira->codegen->invalid_instruction;15127 return ira->codegen->invalid_inst_gen;
14079 }15128 }
1408015129
14081 ZigType *child_type = ptr_type->data.pointer.child_type;15130 ZigType *child_type = ptr_type->data.pointer.child_type;
14082 if (type_is_invalid(child_type))15131 if (type_is_invalid(child_type))
14083 return ira->codegen->invalid_instruction;15132 return ira->codegen->invalid_inst_gen;
14084 // if the child type has one possible value, the deref is comptime15133 // if the child type has one possible value, the deref is comptime
14085 switch (type_has_one_possible_value(ira->codegen, child_type)) {15134 switch (type_has_one_possible_value(ira->codegen, child_type)) {
14086 case OnePossibleValueInvalid:15135 case OnePossibleValueInvalid:
14087 return ira->codegen->invalid_instruction;15136 return ira->codegen->invalid_inst_gen;
14088 case OnePossibleValueYes:15137 case OnePossibleValueYes:
14089 return ir_const_move(ira, source_instruction,15138 return ir_const_move(ira, source_instruction,
14090 get_the_one_possible_value(ira->codegen, child_type));15139 get_the_one_possible_value(ira->codegen, child_type));
...@@ -14093,8 +15142,8 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc...@@ -14093,8 +15142,8 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
14093 }15142 }
14094 if (instr_is_comptime(ptr)) {15143 if (instr_is_comptime(ptr)) {
14095 if (ptr->value->special == ConstValSpecialUndef) {15144 if (ptr->value->special == ConstValSpecialUndef) {
14096 ir_add_error(ira, ptr, buf_sprintf("attempt to dereference undefined value"));15145 ir_add_error(ira, &ptr->base, buf_sprintf("attempt to dereference undefined value"));
14097 return ira->codegen->invalid_instruction;15146 return ira->codegen->invalid_inst_gen;
14098 }15147 }
14099 if (ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {15148 if (ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
14100 ZigValue *pointee = const_ptr_pointee_unchecked(ira->codegen, ptr->value);15149 ZigValue *pointee = const_ptr_pointee_unchecked(ira->codegen, ptr->value);
...@@ -14102,12 +15151,12 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc...@@ -14102,12 +15151,12 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
14102 child_type = pointee->type;15151 child_type = pointee->type;
14103 }15152 }
14104 if (pointee->special != ConstValSpecialRuntime) {15153 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
14107 if ((err = ir_read_const_ptr(ira, ira->codegen, source_instruction->source_node, result->value,15156 if ((err = ir_read_const_ptr(ira, ira->codegen, source_instruction->source_node, result->value,
14108 ptr->value)))15157 ptr->value)))
14109 {15158 {
14110 return ira->codegen->invalid_instruction;15159 return ira->codegen->invalid_inst_gen;
14111 }15160 }
14112 result->value->type = child_type;15161 result->value->type = child_type;
14113 return result;15162 return result;
...@@ -14116,38 +15165,38 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc...@@ -14116,38 +15165,38 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
14116 }15165 }
1411715166
14118 // if the instruction is a const ref instruction we can skip it15167 // if the instruction is a const ref instruction we can skip it
14119 if (ptr->id == IrInstructionIdRef) {15168 if (ptr->id == IrInstGenIdRef) {
14120 IrInstructionRef *ref_inst = reinterpret_cast<IrInstructionRef *>(ptr);15169 IrInstGenRef *ref_inst = reinterpret_cast<IrInstGenRef *>(ptr);
14121 return ref_inst->value;15170 return ref_inst->operand;
14122 }15171 }
1412315172
14124 // If the instruction is a element pointer instruction to a vector, we emit15173 // If the instruction is a element pointer instruction to a vector, we emit
14125 // vector element extract instruction rather than load pointer. If the15174 // vector element extract instruction rather than load pointer. If the
14126 // pointer type has non-VECTOR_INDEX_RUNTIME value, it would have been15175 // 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.
14128 // However if it has VECTOR_INDEX_RUNTIME then we must emit a compile error15177 // However if it has VECTOR_INDEX_RUNTIME then we must emit a compile error
14129 // if the vector index cannot be determined right here, right now, because15178 // if the vector index cannot be determined right here, right now, because
14130 // the type information does not contain enough information to actually15179 // the type information does not contain enough information to actually
14131 // perform a dereference.15180 // perform a dereference.
14132 if (ptr_type->data.pointer.vector_index == VECTOR_INDEX_RUNTIME) {15181 if (ptr_type->data.pointer.vector_index == VECTOR_INDEX_RUNTIME) {
14133 if (ptr->id == IrInstructionIdElemPtr) {15182 if (ptr->id == IrInstGenIdElemPtr) {
14134 IrInstructionElemPtr *elem_ptr = (IrInstructionElemPtr *)ptr;15183 IrInstGenElemPtr *elem_ptr = (IrInstGenElemPtr *)ptr;
14135 IrInstruction *vector_loaded = ir_get_deref(ira, elem_ptr->array_ptr,15184 IrInstGen *vector_loaded = ir_get_deref(ira, &elem_ptr->array_ptr->base,
14136 elem_ptr->array_ptr, nullptr);15185 elem_ptr->array_ptr, nullptr);
14137 IrInstruction *elem_index = elem_ptr->elem_index;15186 IrInstGen *elem_index = elem_ptr->elem_index;
14138 return ir_build_vector_extract_elem(ira, source_instruction, vector_loaded, elem_index);15187 return ir_build_vector_extract_elem(ira, source_instruction, vector_loaded, elem_index);
14139 }15188 }
14140 ir_add_error(ira, ptr,15189 ir_add_error(ira, &ptr->base,
14141 buf_sprintf("unable to determine vector element index of type '%s'", buf_ptr(&ptr_type->name)));15190 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;
14143 }15192 }
1414415193
14145 IrInstruction *result_loc_inst;15194 IrInstGen *result_loc_inst;
14146 if (ptr_type->data.pointer.host_int_bytes != 0 && handle_is_ptr(child_type)) {15195 if (ptr_type->data.pointer.host_int_bytes != 0 && handle_is_ptr(child_type)) {
14147 if (result_loc == nullptr) result_loc = no_result_loc();15196 if (result_loc == nullptr) result_loc = no_result_loc();
14148 result_loc_inst = ir_resolve_result(ira, source_instruction, result_loc, child_type, nullptr,15197 result_loc_inst = ir_resolve_result(ira, source_instruction, result_loc, child_type, nullptr,
14149 true, false, true);15198 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) {
14151 return result_loc_inst;15200 return result_loc_inst;
14152 }15201 }
14153 } else {15202 } else {
...@@ -14157,7 +15206,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc...@@ -14157,7 +15206,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
14157 return ir_build_load_ptr_gen(ira, source_instruction, ptr, child_type, result_loc_inst);15206 return ir_build_load_ptr_gen(ira, source_instruction, ptr, child_type, result_loc_inst);
14158}15207}
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,
14161 ZigValue *const_val, uint32_t *out)15210 ZigValue *const_val, uint32_t *out)
14162{15211{
14163 Error err;15212 Error err;
...@@ -14166,12 +15215,12 @@ static bool ir_resolve_const_align(CodeGen *codegen, IrExecutable *exec, AstNode...@@ -14166,12 +15215,12 @@ static bool ir_resolve_const_align(CodeGen *codegen, IrExecutable *exec, AstNode
1416615215
14167 uint32_t align_bytes = bigint_as_u32(&const_val->data.x_bigint);15216 uint32_t align_bytes = bigint_as_u32(&const_val->data.x_bigint);
14168 if (align_bytes == 0) {15217 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"));
14170 return false;15219 return false;
14171 }15220 }
1417215221
14173 if (!is_power_of_2(align_bytes)) {15222 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,
14175 buf_sprintf("alignment value %" PRIu32 " is not a power of 2", align_bytes));15224 buf_sprintf("alignment value %" PRIu32 " is not a power of 2", align_bytes));
14176 return false;15225 return false;
14177 }15226 }
...@@ -14180,7 +15229,7 @@ static bool ir_resolve_const_align(CodeGen *codegen, IrExecutable *exec, AstNode...@@ -14180,7 +15229,7 @@ static bool ir_resolve_const_align(CodeGen *codegen, IrExecutable *exec, AstNode
14180 return true;15229 return true;
14181}15230}
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) {
14184 if (type_is_invalid(value->value->type))15233 if (type_is_invalid(value->value->type))
14185 return false;15234 return false;
1418615235
...@@ -14201,19 +15250,19 @@ static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, ZigType *elem...@@ -14201,19 +15250,19 @@ static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, ZigType *elem
14201 }15250 }
14202 }15251 }
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));
14205 if (type_is_invalid(casted_value->value->type))15254 if (type_is_invalid(casted_value->value->type))
14206 return false;15255 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,
14209 casted_value->value, out);15258 casted_value->value, out);
14210}15259}
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) {
14213 if (type_is_invalid(value->value->type))15262 if (type_is_invalid(value->value->type))
14214 return false;15263 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);
14217 if (type_is_invalid(casted_value->value->type))15266 if (type_is_invalid(casted_value->value->type))
14218 return false;15267 return false;
1421915268
...@@ -14225,15 +15274,15 @@ static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstruction *value, ZigType *i...@@ -14225,15 +15274,15 @@ static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstruction *value, ZigType *i
14225 return true;15274 return true;
14226}15275}
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) {
14229 return ir_resolve_unsigned(ira, value, ira->codegen->builtin_types.entry_usize, out);15278 return ir_resolve_unsigned(ira, value, ira->codegen->builtin_types.entry_usize, out);
14230}15279}
1423115280
14232static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) {15281static bool ir_resolve_bool(IrAnalyze *ira, IrInstGen *value, bool *out) {
14233 if (type_is_invalid(value->value->type))15282 if (type_is_invalid(value->value->type))
14234 return false;15283 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);
14237 if (type_is_invalid(casted_value->value->type))15286 if (type_is_invalid(casted_value->value->type))
14238 return false;15287 return false;
1423915288
...@@ -14245,7 +15294,7 @@ static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) {...@@ -14245,7 +15294,7 @@ static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) {
14245 return true;15294 return true;
14246}15295}
1424715296
14248static bool ir_resolve_comptime(IrAnalyze *ira, IrInstruction *value, bool *out) {15297static bool ir_resolve_comptime(IrAnalyze *ira, IrInstGen *value, bool *out) {
14249 if (!value) {15298 if (!value) {
14250 *out = false;15299 *out = false;
14251 return true;15300 return true;
...@@ -14253,13 +15302,13 @@ static bool ir_resolve_comptime(IrAnalyze *ira, IrInstruction *value, bool *out)...@@ -14253,13 +15302,13 @@ static bool ir_resolve_comptime(IrAnalyze *ira, IrInstruction *value, bool *out)
14253 return ir_resolve_bool(ira, value, out);15302 return ir_resolve_bool(ira, value, out);
14254}15303}
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) {
14257 if (type_is_invalid(value->value->type))15306 if (type_is_invalid(value->value->type))
14258 return false;15307 return false;
1425915308
14260 ZigType *atomic_order_type = get_builtin_type(ira->codegen, "AtomicOrder");15309 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);
14263 if (type_is_invalid(casted_value->value->type))15312 if (type_is_invalid(casted_value->value->type))
14264 return false;15313 return false;
1426515314
...@@ -14271,13 +15320,13 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic...@@ -14271,13 +15320,13 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic
14271 return true;15320 return true;
14272}15321}
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) {
14275 if (type_is_invalid(value->value->type))15324 if (type_is_invalid(value->value->type))
14276 return false;15325 return false;
1427715326
14278 ZigType *atomic_rmw_op_type = get_builtin_type(ira->codegen, "AtomicRmwOp");15327 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);
14281 if (type_is_invalid(casted_value->value->type))15330 if (type_is_invalid(casted_value->value->type))
14282 return false;15331 return false;
1428315332
...@@ -14289,13 +15338,13 @@ static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, Atomi...@@ -14289,13 +15338,13 @@ static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, Atomi
14289 return true;15338 return true;
14290}15339}
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) {
14293 if (type_is_invalid(value->value->type))15342 if (type_is_invalid(value->value->type))
14294 return false;15343 return false;
1429515344
14296 ZigType *global_linkage_type = get_builtin_type(ira->codegen, "GlobalLinkage");15345 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);
14299 if (type_is_invalid(casted_value->value->type))15348 if (type_is_invalid(casted_value->value->type))
14300 return false;15349 return false;
1430115350
...@@ -14307,13 +15356,13 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob...@@ -14307,13 +15356,13 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob
14307 return true;15356 return true;
14308}15357}
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) {
14311 if (type_is_invalid(value->value->type))15360 if (type_is_invalid(value->value->type))
14312 return false;15361 return false;
1431315362
14314 ZigType *float_mode_type = get_builtin_type(ira->codegen, "FloatMode");15363 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);
14317 if (type_is_invalid(casted_value->value->type))15366 if (type_is_invalid(casted_value->value->type))
14318 return false;15367 return false;
1431915368
...@@ -14325,14 +15374,14 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod...@@ -14325,14 +15374,14 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod
14325 return true;15374 return true;
14326}15375}
1432715376
14328static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {15377static Buf *ir_resolve_str(IrAnalyze *ira, IrInstGen *value) {
14329 if (type_is_invalid(value->value->type))15378 if (type_is_invalid(value->value->type))
14330 return nullptr;15379 return nullptr;
1433115380
14332 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,15381 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
14333 true, false, PtrLenUnknown, 0, 0, 0, false);15382 true, false, PtrLenUnknown, 0, 0, 0, false);
14334 ZigType *str_type = get_slice_type(ira->codegen, ptr_type);15383 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);
14336 if (type_is_invalid(casted_value->value->type))15385 if (type_is_invalid(casted_value->value->type))
14337 return nullptr;15386 return nullptr;
1433815387
...@@ -14356,7 +15405,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {...@@ -14356,7 +15405,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
14356 size_t new_index = ptr_field->data.x_ptr.data.base_array.elem_index + i;15405 size_t new_index = ptr_field->data.x_ptr.data.base_array.elem_index + i;
14357 ZigValue *char_val = &array_val->data.x_array.data.s_none.elements[new_index];15406 ZigValue *char_val = &array_val->data.x_array.data.s_none.elements[new_index];
14358 if (char_val->special == ConstValSpecialUndef) {15407 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"));
14360 return nullptr;15409 return nullptr;
14361 }15410 }
14362 uint64_t big_c = bigint_as_u64(&char_val->data.x_bigint);15411 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) {...@@ -14367,10 +15416,10 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
14367 return result;15416 return result;
14368}15417}
1436915418
14370static IrInstruction *ir_analyze_instruction_add_implicit_return_type(IrAnalyze *ira,15419static IrInstGen *ir_analyze_instruction_add_implicit_return_type(IrAnalyze *ira,
14371 IrInstructionAddImplicitReturnType *instruction)15420 IrInstSrcAddImplicitReturnType *instruction)
14372{15421{
14373 IrInstruction *value = instruction->value->child;15422 IrInstGen *value = instruction->value->child;
14374 if (type_is_invalid(value->value->type))15423 if (type_is_invalid(value->value->type))
14375 return ir_unreach_error(ira);15424 return ir_unreach_error(ira);
1437615425
...@@ -14378,15 +15427,15 @@ static IrInstruction *ir_analyze_instruction_add_implicit_return_type(IrAnalyze...@@ -14378,15 +15427,15 @@ static IrInstruction *ir_analyze_instruction_add_implicit_return_type(IrAnalyze
14378 ira->src_implicit_return_type_list.append(value);15427 ira->src_implicit_return_type_list.append(value);
14379 }15428 }
1438015429
14381 return ir_const_void(ira, &instruction->base);15430 return ir_const_void(ira, &instruction->base.base);
14382}15431}
1438315432
14384static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructionReturn *instruction) {15433static IrInstGen *ir_analyze_instruction_return(IrAnalyze *ira, IrInstSrcReturn *instruction) {
14385 IrInstruction *operand = instruction->operand->child;15434 IrInstGen *operand = instruction->operand->child;
14386 if (type_is_invalid(operand->value->type))15435 if (type_is_invalid(operand->value->type))
14387 return ir_unreach_error(ira);15436 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);
14390 if (type_is_invalid(casted_operand->value->type)) {15439 if (type_is_invalid(casted_operand->value->type)) {
14391 AstNode *source_node = ira->explicit_return_type_source_node;15440 AstNode *source_node = ira->explicit_return_type_source_node;
14392 if (source_node != nullptr) {15441 if (source_node != nullptr) {
...@@ -14401,9 +15450,7 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio...@@ -14401,9 +15450,7 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio
14401 handle_is_ptr(ira->explicit_return_type))15450 handle_is_ptr(ira->explicit_return_type))
14402 {15451 {
14403 // result location mechanism took care of it.15452 // result location mechanism took care of it.
14404 IrInstruction *result = ir_build_return(&ira->new_irb, instruction->base.scope,15453 IrInstGen *result = ir_build_return_gen(ira, &instruction->base.base, nullptr);
14405 instruction->base.source_node, nullptr);
14406 result->value->type = ira->codegen->builtin_types.entry_unreachable;
14407 return ir_finish_anal(ira, result);15454 return ir_finish_anal(ira, result);
14408 }15455 }
1440915456
...@@ -14411,47 +15458,45 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio...@@ -14411,47 +15458,45 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio
14411 casted_operand->value->type->id == ZigTypeIdPointer &&15458 casted_operand->value->type->id == ZigTypeIdPointer &&
14412 casted_operand->value->data.rh_ptr == RuntimeHintPtrStack)15459 casted_operand->value->data.rh_ptr == RuntimeHintPtrStack)
14413 {15460 {
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"));
14415 return ir_unreach_error(ira);15462 return ir_unreach_error(ira);
14416 }15463 }
1441715464
14418 IrInstruction *result = ir_build_return(&ira->new_irb, instruction->base.scope,15465 IrInstGen *result = ir_build_return_gen(ira, &instruction->base.base, casted_operand);
14419 instruction->base.source_node, casted_operand);
14420 result->value->type = ira->codegen->builtin_types.entry_unreachable;
14421 return ir_finish_anal(ira, result);15466 return ir_finish_anal(ira, result);
14422}15467}
1442315468
14424static IrInstruction *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *instruction) {15469static IrInstGen *ir_analyze_instruction_const(IrAnalyze *ira, IrInstSrcConst *instruction) {
14425 return ir_const_move(ira, &instruction->base, instruction->base.value);15470 return ir_const_move(ira, &instruction->base.base, instruction->value);
14426}15471}
1442715472
14428static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {15473static IrInstGen *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstSrcBinOp *bin_op_instruction) {
14429 IrInstruction *op1 = bin_op_instruction->op1->child;15474 IrInstGen *op1 = bin_op_instruction->op1->child;
14430 if (type_is_invalid(op1->value->type))15475 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;
14434 if (type_is_invalid(op2->value->type))15479 if (type_is_invalid(op2->value->type))
14435 return ira->codegen->invalid_instruction;15480 return ira->codegen->invalid_inst_gen;
1443615481
14437 ZigType *bool_type = ira->codegen->builtin_types.entry_bool;15482 ZigType *bool_type = ira->codegen->builtin_types.entry_bool;
1443815483
14439 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, bool_type);15484 IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, bool_type);
14440 if (casted_op1 == ira->codegen->invalid_instruction)15485 if (type_is_invalid(casted_op1->value->type))
14441 return ira->codegen->invalid_instruction;15486 return ira->codegen->invalid_inst_gen;
1444215487
14443 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, bool_type);15488 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, bool_type);
14444 if (casted_op2 == ira->codegen->invalid_instruction)15489 if (type_is_invalid(casted_op2->value->type))
14445 return ira->codegen->invalid_instruction;15490 return ira->codegen->invalid_inst_gen;
1444615491
14447 if (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2)) {15492 if (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2)) {
14448 ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);15493 ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);
14449 if (op1_val == nullptr)15494 if (op1_val == nullptr)
14450 return ira->codegen->invalid_instruction;15495 return ira->codegen->invalid_inst_gen;
1445115496
14452 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);15497 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
14453 if (op2_val == nullptr)15498 if (op2_val == nullptr)
14454 return ira->codegen->invalid_instruction;15499 return ira->codegen->invalid_inst_gen;
1445515500
14456 assert(casted_op1->value->type->id == ZigTypeIdBool);15501 assert(casted_op1->value->type->id == ZigTypeIdBool);
14457 assert(casted_op2->value->type->id == ZigTypeIdBool);15502 assert(casted_op2->value->type->id == ZigTypeIdBool);
...@@ -14463,14 +15508,11 @@ static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp...@@ -14463,14 +15508,11 @@ static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp
14463 } else {15508 } else {
14464 zig_unreachable();15509 zig_unreachable();
14465 }15510 }
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);
14467 }15512 }
1446815513
14469 IrInstruction *result = ir_build_bin_op(&ira->new_irb,15514 return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, bool_type,
14470 bin_op_instruction->base.scope, bin_op_instruction->base.source_node,
14471 bin_op_instruction->op_id, casted_op1, casted_op2, bin_op_instruction->safety_check_on);15515 bin_op_instruction->op_id, casted_op1, casted_op2, bin_op_instruction->safety_check_on);
14472 result->value->type = bool_type;
14473 return result;
14474}15516}
1447515517
14476static bool resolve_cmp_op_id(IrBinOp op_id, Cmp cmp) {15518static bool resolve_cmp_op_id(IrBinOp op_id, Cmp cmp) {
...@@ -14535,12 +15577,13 @@ static void set_optional_payload(ZigValue *opt_val, ZigValue *payload) {...@@ -14535,12 +15577,13 @@ static void set_optional_payload(ZigValue *opt_val, ZigValue *payload) {
14535 }15577 }
14536}15578}
1453715579
14538static IrInstruction *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_type,15580static IrInstGen *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_type,
14539 ZigValue *op1_val, ZigValue *op2_val, IrInstructionBinOp *bin_op_instruction, IrBinOp op_id,15581 ZigValue *op1_val, ZigValue *op2_val, IrInstSrcBinOp *bin_op_instruction, IrBinOp op_id,
14540 bool one_possible_value) {15582 bool one_possible_value)
15583{
14541 if (op1_val->special == ConstValSpecialUndef ||15584 if (op1_val->special == ConstValSpecialUndef ||
14542 op2_val->special == ConstValSpecialUndef)15585 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);
14544 if (resolved_type->id == ZigTypeIdPointer && op_id != IrBinOpCmpEq && op_id != IrBinOpCmpNotEq) {15587 if (resolved_type->id == ZigTypeIdPointer && op_id != IrBinOpCmpEq && op_id != IrBinOpCmpNotEq) {
14545 if ((op1_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr ||15588 if ((op1_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr ||
14546 op1_val->data.x_ptr.special == ConstPtrSpecialNull) &&15589 op1_val->data.x_ptr.special == ConstPtrSpecialNull) &&
...@@ -14560,7 +15603,7 @@ static IrInstruction *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_t...@@ -14560,7 +15603,7 @@ static IrInstruction *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_t
14560 cmp_result = CmpEQ;15603 cmp_result = CmpEQ;
14561 }15604 }
14562 bool answer = resolve_cmp_op_id(op_id, cmp_result);15605 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);
14564 }15607 }
14565 } else {15608 } else {
14566 bool are_equal = one_possible_value || const_values_equal(ira->codegen, op1_val, op2_val);15609 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...@@ -14572,7 +15615,7 @@ static IrInstruction *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_t
14572 } else {15615 } else {
14573 zig_unreachable();15616 zig_unreachable();
14574 }15617 }
14575 return ir_const_bool(ira, &bin_op_instruction->base, answer);15618 return ir_const_bool(ira, &bin_op_instruction->base.base, answer);
14576 }15619 }
14577 zig_unreachable();15620 zig_unreachable();
14578}15621}
...@@ -14626,7 +15669,7 @@ static Error lazy_cmp_zero(AstNode *source_node, ZigValue *val, Cmp *result) {...@@ -14626,7 +15669,7 @@ static Error lazy_cmp_zero(AstNode *source_node, ZigValue *val, Cmp *result) {
14626 zig_unreachable();15669 zig_unreachable();
14627}15670}
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,
14630 ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val, ZigValue *out_val)15673 ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val, ZigValue *out_val)
14631{15674{
14632 Error err;15675 Error err;
...@@ -14704,14 +15747,14 @@ never_mind_just_calculate_it_normally:...@@ -14704,14 +15747,14 @@ never_mind_just_calculate_it_normally:
14704 return nullptr;15747 return nullptr;
14705 }15748 }
14706 if (op1_val->type->id == ZigTypeIdComptimeFloat) {15749 if (op1_val->type->id == ZigTypeIdComptimeFloat) {
14707 IrInstruction *tmp = ir_const_noval(ira, source_instr);15750 IrInstGen *tmp = ir_const_noval(ira, source_instr);
14708 tmp->value = op1_val;15751 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);
14710 op1_val = casted->value;15753 op1_val = casted->value;
14711 } else if (op2_val->type->id == ZigTypeIdComptimeFloat) {15754 } 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);
14713 tmp->value = op2_val;15756 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);
14715 op2_val = casted->value;15758 op2_val = casted->value;
14716 }15759 }
14717 Cmp cmp_result = float_cmp(op1_val, op2_val);15760 Cmp cmp_result = float_cmp(op1_val, op2_val);
...@@ -14753,8 +15796,8 @@ never_mind_just_calculate_it_normally:...@@ -14753,8 +15796,8 @@ never_mind_just_calculate_it_normally:
14753 return nullptr;15796 return nullptr;
14754}15797}
1475515798
14756static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstruction *source_instr,15799static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_instr,
14757 IrInstruction *op1, IrInstruction *op2, IrBinOp op_id)15800 IrInstGen *op1, IrInstGen *op2, IrBinOp op_id)
14758{15801{
14759 Error err;15802 Error err;
1476015803
...@@ -14767,7 +15810,7 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio...@@ -14767,7 +15810,7 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
14767 ir_add_error(ira, source_instr,15810 ir_add_error(ira, source_instr,
14768 buf_sprintf("vector length mismatch: %" PRIu32 " and %" PRIu32,15811 buf_sprintf("vector length mismatch: %" PRIu32 " and %" PRIu32,
14769 op1->value->type->data.vector.len, op2->value->type->data.vector.len));15812 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;
14771 }15814 }
14772 result_type = get_vector_type(ira->codegen, op1->value->type->data.vector.len, scalar_result_type);15815 result_type = get_vector_type(ira->codegen, op1->value->type->data.vector.len, scalar_result_type);
14773 op1_scalar_type = op1->value->type->data.vector.elem_type;15816 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...@@ -14776,13 +15819,13 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
14776 ir_add_error(ira, source_instr,15819 ir_add_error(ira, source_instr,
14777 buf_sprintf("mixed scalar and vector operands to comparison operator: '%s' and '%s'",15820 buf_sprintf("mixed scalar and vector operands to comparison operator: '%s' and '%s'",
14778 buf_ptr(&op1->value->type->name), buf_ptr(&op2->value->type->name)));15821 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;
14780 }15823 }
1478115824
14782 bool opv_op1;15825 bool opv_op1;
14783 switch (type_has_one_possible_value(ira->codegen, op1->value->type)) {15826 switch (type_has_one_possible_value(ira->codegen, op1->value->type)) {
14784 case OnePossibleValueInvalid:15827 case OnePossibleValueInvalid:
14785 return ira->codegen->invalid_instruction;15828 return ira->codegen->invalid_inst_gen;
14786 case OnePossibleValueYes:15829 case OnePossibleValueYes:
14787 opv_op1 = true;15830 opv_op1 = true;
14788 break;15831 break;
...@@ -14793,7 +15836,7 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio...@@ -14793,7 +15836,7 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
14793 bool opv_op2;15836 bool opv_op2;
14794 switch (type_has_one_possible_value(ira->codegen, op2->value->type)) {15837 switch (type_has_one_possible_value(ira->codegen, op2->value->type)) {
14795 case OnePossibleValueInvalid:15838 case OnePossibleValueInvalid:
14796 return ira->codegen->invalid_instruction;15839 return ira->codegen->invalid_inst_gen;
14797 case OnePossibleValueYes:15840 case OnePossibleValueYes:
14798 opv_op2 = true;15841 opv_op2 = true;
14799 break;15842 break;
...@@ -14804,21 +15847,21 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio...@@ -14804,21 +15847,21 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
14804 Cmp op1_cmp_zero;15847 Cmp op1_cmp_zero;
14805 bool have_op1_cmp_zero = false;15848 bool have_op1_cmp_zero = false;
14806 if ((err = lazy_cmp_zero(source_instr->source_node, op1->value, &op1_cmp_zero))) {15849 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;
14808 } else {15851 } else {
14809 have_op1_cmp_zero = true;15852 have_op1_cmp_zero = true;
14810 }15853 }
14811 Cmp op2_cmp_zero;15854 Cmp op2_cmp_zero;
14812 bool have_op2_cmp_zero = false;15855 bool have_op2_cmp_zero = false;
14813 if ((err = lazy_cmp_zero(source_instr->source_node, op2->value, &op2_cmp_zero))) {15856 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;
14815 } else {15858 } else {
14816 have_op2_cmp_zero = true;15859 have_op2_cmp_zero = true;
14817 }15860 }
14818 if (((opv_op1 || instr_is_comptime(op1)) && (opv_op2 || instr_is_comptime(op2))) ||15861 if (((opv_op1 || instr_is_comptime(op1)) && (opv_op2 || instr_is_comptime(op2))) ||
14819 (have_op1_cmp_zero && have_op2_cmp_zero))15862 (have_op1_cmp_zero && have_op2_cmp_zero))
14820 {15863 {
14821 IrInstruction *result_instruction = ir_const(ira, source_instr, result_type);15864 IrInstGen *result_instruction = ir_const(ira, source_instr, result_type);
14822 ZigValue *out_val = result_instruction->value;15865 ZigValue *out_val = result_instruction->value;
14823 if (result_type->id == ZigTypeIdVector) {15866 if (result_type->id == ZigTypeIdVector) {
14824 size_t len = result_type->data.vector.len;15867 size_t len = result_type->data.vector.len;
...@@ -14836,7 +15879,7 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio...@@ -14836,7 +15879,7 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
14836 if (msg != nullptr) {15879 if (msg != nullptr) {
14837 add_error_note(ira->codegen, msg, source_instr->source_node,15880 add_error_note(ira->codegen, msg, source_instr->source_node,
14838 buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i));15881 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;
14840 }15883 }
14841 }15884 }
14842 out_val->type = result_type;15885 out_val->type = result_type;
...@@ -14845,7 +15888,7 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio...@@ -14845,7 +15888,7 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
14845 if (ir_eval_bin_op_cmp_scalar(ira, source_instr, op1->value, op_id,15888 if (ir_eval_bin_op_cmp_scalar(ira, source_instr, op1->value, op_id,
14846 op2->value, out_val) != nullptr)15889 op2->value, out_val) != nullptr)
14847 {15890 {
14848 return ira->codegen->invalid_instruction;15891 return ira->codegen->invalid_inst_gen;
14849 }15892 }
14850 }15893 }
14851 return result_instruction;15894 return result_instruction;
...@@ -14939,10 +15982,10 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio...@@ -14939,10 +15982,10 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
14939 }15982 }
14940 ZigType *dest_type = (result_type->id == ZigTypeIdVector) ?15983 ZigType *dest_type = (result_type->id == ZigTypeIdVector) ?
14941 get_vector_type(ira->codegen, result_type->data.vector.len, dest_scalar_type) : dest_scalar_type;15984 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);15985 IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, dest_type);
14943 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, dest_type);15986 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, dest_type);
14944 if (type_is_invalid(casted_op1->value->type) || type_is_invalid(casted_op2->value->type))15987 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;
14946 return ir_build_bin_op_gen(ira, source_instr, result_type, op_id, casted_op1, casted_op2, true);15989 return ir_build_bin_op_gen(ira, source_instr, result_type, op_id, casted_op1, casted_op2, true);
14947 }15990 }
1494815991
...@@ -14972,12 +16015,12 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio...@@ -14972,12 +16015,12 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
14972 if (instr_is_comptime(op1)) {16015 if (instr_is_comptime(op1)) {
14973 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefOk);16016 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefOk);
14974 if (op1_val == nullptr)16017 if (op1_val == nullptr)
14975 return ira->codegen->invalid_instruction;16018 return ira->codegen->invalid_inst_gen;
14976 if (op1_val->special == ConstValSpecialUndef)16019 if (op1_val->special == ConstValSpecialUndef)
14977 return ir_const_undef(ira, source_instr, ira->codegen->builtin_types.entry_bool);16020 return ir_const_undef(ira, source_instr, ira->codegen->builtin_types.entry_bool);
14978 if (result_type->id == ZigTypeIdVector) {16021 if (result_type->id == ZigTypeIdVector) {
14979 ir_add_error(ira, op1, buf_sprintf("compiler bug: TODO: support comptime vector here"));16022 ir_add_error(ira, &op1->base, buf_sprintf("compiler bug: TODO: support comptime vector here"));
14980 return ira->codegen->invalid_instruction;16023 return ira->codegen->invalid_inst_gen;
14981 }16024 }
14982 bool is_unsigned;16025 bool is_unsigned;
14983 if (op1_is_float) {16026 if (op1_is_float) {
...@@ -15016,12 +16059,12 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio...@@ -15016,12 +16059,12 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
15016 if (instr_is_comptime(op2)) {16059 if (instr_is_comptime(op2)) {
15017 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefOk);16060 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefOk);
15018 if (op2_val == nullptr)16061 if (op2_val == nullptr)
15019 return ira->codegen->invalid_instruction;16062 return ira->codegen->invalid_inst_gen;
15020 if (op2_val->special == ConstValSpecialUndef)16063 if (op2_val->special == ConstValSpecialUndef)
15021 return ir_const_undef(ira, source_instr, ira->codegen->builtin_types.entry_bool);16064 return ir_const_undef(ira, source_instr, ira->codegen->builtin_types.entry_bool);
15022 if (result_type->id == ZigTypeIdVector) {16065 if (result_type->id == ZigTypeIdVector) {
15023 ir_add_error(ira, op2, buf_sprintf("compiler bug: TODO: support comptime vector here"));16066 ir_add_error(ira, &op2->base, buf_sprintf("compiler bug: TODO: support comptime vector here"));
15024 return ira->codegen->invalid_instruction;16067 return ira->codegen->invalid_inst_gen;
15025 }16068 }
15026 bool is_unsigned;16069 bool is_unsigned;
15027 if (op2_is_float) {16070 if (op2_is_float) {
...@@ -15062,35 +16105,35 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio...@@ -15062,35 +16105,35 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
15062 ZigType *dest_type = (result_type->id == ZigTypeIdVector) ?16105 ZigType *dest_type = (result_type->id == ZigTypeIdVector) ?
15063 get_vector_type(ira->codegen, result_type->data.vector.len, dest_scalar_type) : dest_scalar_type;16106 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);
15066 if (type_is_invalid(casted_op1->value->type))16109 if (type_is_invalid(casted_op1->value->type))
15067 return ira->codegen->invalid_instruction;16110 return ira->codegen->invalid_inst_gen;
15068 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, dest_type);16111 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, dest_type);
15069 if (type_is_invalid(casted_op2->value->type))16112 if (type_is_invalid(casted_op2->value->type))
15070 return ira->codegen->invalid_instruction;16113 return ira->codegen->invalid_inst_gen;
15071 return ir_build_bin_op_gen(ira, source_instr, result_type, op_id, casted_op1, casted_op2, true);16114 return ir_build_bin_op_gen(ira, source_instr, result_type, op_id, casted_op1, casted_op2, true);
15072}16115}
1507316116
15074static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {16117static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_instruction) {
15075 IrInstruction *op1 = bin_op_instruction->op1->child;16118 IrInstGen *op1 = bin_op_instruction->op1->child;
15076 if (type_is_invalid(op1->value->type))16119 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;
15080 if (type_is_invalid(op2->value->type))16123 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
15085 IrBinOp op_id = bin_op_instruction->op_id;16128 IrBinOp op_id = bin_op_instruction->op_id;
15086 bool is_equality_cmp = (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq);16129 bool is_equality_cmp = (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq);
15087 if (is_equality_cmp && op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdNull) {16130 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));
15089 } else if (is_equality_cmp &&16132 } else if (is_equality_cmp &&
15090 ((op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdOptional) ||16133 ((op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdOptional) ||
15091 (op2->value->type->id == ZigTypeIdNull && op1->value->type->id == ZigTypeIdOptional)))16134 (op2->value->type->id == ZigTypeIdNull && op1->value->type->id == ZigTypeIdOptional)))
15092 {16135 {
15093 IrInstruction *maybe_op;16136 IrInstGen *maybe_op;
15094 if (op1->value->type->id == ZigTypeIdNull) {16137 if (op1->value->type->id == ZigTypeIdNull) {
15095 maybe_op = op2;16138 maybe_op = op2;
15096 } else if (op2->value->type->id == ZigTypeIdNull) {16139 } else if (op2->value->type->id == ZigTypeIdNull) {
...@@ -15101,21 +16144,16 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -15101,21 +16144,16 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
15101 if (instr_is_comptime(maybe_op)) {16144 if (instr_is_comptime(maybe_op)) {
15102 ZigValue *maybe_val = ir_resolve_const(ira, maybe_op, UndefBad);16145 ZigValue *maybe_val = ir_resolve_const(ira, maybe_op, UndefBad);
15103 if (!maybe_val)16146 if (!maybe_val)
15104 return ira->codegen->invalid_instruction;16147 return ira->codegen->invalid_inst_gen;
15105 bool is_null = optional_value_is_null(maybe_val);16148 bool is_null = optional_value_is_null(maybe_val);
15106 bool bool_result = (op_id == IrBinOpCmpEq) ? is_null : !is_null;16149 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);
15108 }16151 }
1510916152
15110 IrInstruction *is_non_null = ir_build_test_nonnull(&ira->new_irb, bin_op_instruction->base.scope,16153 IrInstGen *is_non_null = ir_build_test_non_null_gen(ira, &bin_op_instruction->base.base, maybe_op);
15111 source_node, maybe_op);
15112 is_non_null->value->type = ira->codegen->builtin_types.entry_bool;
1511316154
15114 if (op_id == IrBinOpCmpEq) {16155 if (op_id == IrBinOpCmpEq) {
15115 IrInstruction *result = ir_build_bool_not(&ira->new_irb, bin_op_instruction->base.scope,16156 return ir_build_bool_not_gen(ira, &bin_op_instruction->base.base, is_non_null);
15116 bin_op_instruction->base.source_node, is_non_null);
15117 result->value->type = ira->codegen->builtin_types.entry_bool;
15118 return result;
15119 } else {16157 } else {
15120 return is_non_null;16158 return is_non_null;
15121 }16159 }
...@@ -15125,7 +16163,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -15125,7 +16163,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
15125 (op2->value->type->id == ZigTypeIdNull && op1->value->type->id == ZigTypeIdPointer &&16163 (op2->value->type->id == ZigTypeIdNull && op1->value->type->id == ZigTypeIdPointer &&
15126 op1->value->type->data.pointer.ptr_len == PtrLenC)))16164 op1->value->type->data.pointer.ptr_len == PtrLenC)))
15127 {16165 {
15128 IrInstruction *c_ptr_op;16166 IrInstGen *c_ptr_op;
15129 if (op1->value->type->id == ZigTypeIdNull) {16167 if (op1->value->type->id == ZigTypeIdNull) {
15130 c_ptr_op = op2;16168 c_ptr_op = op2;
15131 } else if (op2->value->type->id == ZigTypeIdNull) {16169 } else if (op2->value->type->id == ZigTypeIdNull) {
...@@ -15136,24 +16174,19 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -15136,24 +16174,19 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
15136 if (instr_is_comptime(c_ptr_op)) {16174 if (instr_is_comptime(c_ptr_op)) {
15137 ZigValue *c_ptr_val = ir_resolve_const(ira, c_ptr_op, UndefOk);16175 ZigValue *c_ptr_val = ir_resolve_const(ira, c_ptr_op, UndefOk);
15138 if (!c_ptr_val)16176 if (!c_ptr_val)
15139 return ira->codegen->invalid_instruction;16177 return ira->codegen->invalid_inst_gen;
15140 if (c_ptr_val->special == ConstValSpecialUndef)16178 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);
15142 bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull ||16180 bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull ||
15143 (c_ptr_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&16181 (c_ptr_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&
15144 c_ptr_val->data.x_ptr.data.hard_coded_addr.addr == 0);16182 c_ptr_val->data.x_ptr.data.hard_coded_addr.addr == 0);
15145 bool bool_result = (op_id == IrBinOpCmpEq) ? is_null : !is_null;16183 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);
15147 }16185 }
15148 IrInstruction *is_non_null = ir_build_test_nonnull(&ira->new_irb, bin_op_instruction->base.scope,16186 IrInstGen *is_non_null = ir_build_test_non_null_gen(ira, &bin_op_instruction->base.base, c_ptr_op);
15149 source_node, c_ptr_op);
15150 is_non_null->value->type = ira->codegen->builtin_types.entry_bool;
1515116187
15152 if (op_id == IrBinOpCmpEq) {16188 if (op_id == IrBinOpCmpEq) {
15153 IrInstruction *result = ir_build_bool_not(&ira->new_irb, bin_op_instruction->base.scope,16189 return ir_build_bool_not_gen(ira, &bin_op_instruction->base.base, is_non_null);
15154 bin_op_instruction->base.source_node, is_non_null);
15155 result->value->type = ira->codegen->builtin_types.entry_bool;
15156 return result;
15157 } else {16190 } else {
15158 return is_non_null;16191 return is_non_null;
15159 }16192 }
...@@ -15161,61 +16194,57 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -15161,61 +16194,57 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
15161 ZigType *non_null_type = (op1->value->type->id == ZigTypeIdNull) ? op2->value->type : op1->value->type;16194 ZigType *non_null_type = (op1->value->type->id == ZigTypeIdNull) ? op2->value->type : op1->value->type;
15162 ir_add_error_node(ira, source_node, buf_sprintf("comparison of '%s' with null",16195 ir_add_error_node(ira, source_node, buf_sprintf("comparison of '%s' with null",
15163 buf_ptr(&non_null_type->name)));16196 buf_ptr(&non_null_type->name)));
15164 return ira->codegen->invalid_instruction;16197 return ira->codegen->invalid_inst_gen;
15165 } else if (is_equality_cmp && (16198 } else if (is_equality_cmp && (
15166 (op1->value->type->id == ZigTypeIdEnumLiteral && op2->value->type->id == ZigTypeIdUnion) ||16199 (op1->value->type->id == ZigTypeIdEnumLiteral && op2->value->type->id == ZigTypeIdUnion) ||
15167 (op2->value->type->id == ZigTypeIdEnumLiteral && op1->value->type->id == ZigTypeIdUnion)))16200 (op2->value->type->id == ZigTypeIdEnumLiteral && op1->value->type->id == ZigTypeIdUnion)))
15168 {16201 {
15169 // Support equality comparison between a union's tag value and a enum literal16202 // Support equality comparison between a union's tag value and a enum literal
15170 IrInstruction *union_val = op1->value->type->id == ZigTypeIdUnion ? op1 : op2;16203 IrInstGen *union_val = op1->value->type->id == ZigTypeIdUnion ? op1 : op2;
15171 IrInstruction *enum_val = op1->value->type->id == ZigTypeIdUnion ? op2 : op1;16204 IrInstGen *enum_val = op1->value->type->id == ZigTypeIdUnion ? op2 : op1;
1517216205
15173 ZigType *tag_type = union_val->value->type->data.unionation.tag_type;16206 ZigType *tag_type = union_val->value->type->data.unionation.tag_type;
15174 assert(tag_type != nullptr);16207 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);
15177 if (type_is_invalid(casted_union->value->type))16210 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);
15181 if (type_is_invalid(casted_val->value->type))16214 if (type_is_invalid(casted_val->value->type))
15182 return ira->codegen->invalid_instruction;16215 return ira->codegen->invalid_inst_gen;
1518316216
15184 if (instr_is_comptime(casted_union)) {16217 if (instr_is_comptime(casted_union)) {
15185 ZigValue *const_union_val = ir_resolve_const(ira, casted_union, UndefBad);16218 ZigValue *const_union_val = ir_resolve_const(ira, casted_union, UndefBad);
15186 if (!const_union_val)16219 if (!const_union_val)
15187 return ira->codegen->invalid_instruction;16220 return ira->codegen->invalid_inst_gen;
1518816221
15189 ZigValue *const_enum_val = ir_resolve_const(ira, casted_val, UndefBad);16222 ZigValue *const_enum_val = ir_resolve_const(ira, casted_val, UndefBad);
15190 if (!const_enum_val)16223 if (!const_enum_val)
15191 return ira->codegen->invalid_instruction;16224 return ira->codegen->invalid_inst_gen;
1519216225
15193 Cmp cmp_result = bigint_cmp(&const_union_val->data.x_union.tag, &const_enum_val->data.x_enum_tag);16226 Cmp cmp_result = bigint_cmp(&const_union_val->data.x_union.tag, &const_enum_val->data.x_enum_tag);
15194 bool bool_result = (op_id == IrBinOpCmpEq) ? cmp_result == CmpEQ : cmp_result != CmpEQ;16227 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);
15197 }16230 }
1519816231
15199 IrInstruction *result = ir_build_bin_op(&ira->new_irb,16232 return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, ira->codegen->builtin_types.entry_bool,
15200 bin_op_instruction->base.scope, bin_op_instruction->base.source_node,
15201 op_id, casted_union, casted_val, bin_op_instruction->safety_check_on);16233 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;
15205 }16234 }
1520616235
15207 if (op1->value->type->id == ZigTypeIdErrorSet && op2->value->type->id == ZigTypeIdErrorSet) {16236 if (op1->value->type->id == ZigTypeIdErrorSet && op2->value->type->id == ZigTypeIdErrorSet) {
15208 if (!is_equality_cmp) {16237 if (!is_equality_cmp) {
15209 ir_add_error_node(ira, source_node, buf_sprintf("operator not allowed for errors"));16238 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;
15211 }16240 }
15212 ZigType *intersect_type = get_error_set_intersection(ira, op1->value->type, op2->value->type, source_node);16241 ZigType *intersect_type = get_error_set_intersection(ira, op1->value->type, op2->value->type, source_node);
15213 if (type_is_invalid(intersect_type)) {16242 if (type_is_invalid(intersect_type)) {
15214 return ira->codegen->invalid_instruction;16243 return ira->codegen->invalid_inst_gen;
15215 }16244 }
1521616245
15217 if (!resolve_inferred_error_set(ira->codegen, intersect_type, source_node)) {16246 if (!resolve_inferred_error_set(ira->codegen, intersect_type, source_node)) {
15218 return ira->codegen->invalid_instruction;16247 return ira->codegen->invalid_inst_gen;
15219 }16248 }
1522016249
15221 // exception if one of the operators has the type of the empty error set, we allow the comparison16250 // 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 *...@@ -15232,7 +16261,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
15232 } else {16261 } else {
15233 zig_unreachable();16262 zig_unreachable();
15234 }16263 }
15235 return ir_const_bool(ira, &bin_op_instruction->base, answer);16264 return ir_const_bool(ira, &bin_op_instruction->base.base, answer);
15236 }16265 }
1523716266
15238 if (!type_is_global_error_set(intersect_type)) {16267 if (!type_is_global_error_set(intersect_type)) {
...@@ -15240,7 +16269,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -15240,7 +16269,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
15240 ir_add_error_node(ira, source_node,16269 ir_add_error_node(ira, source_node,
15241 buf_sprintf("error sets '%s' and '%s' have no common errors",16270 buf_sprintf("error sets '%s' and '%s' have no common errors",
15242 buf_ptr(&op1->value->type->name), buf_ptr(&op2->value->type->name)));16271 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;
15244 }16273 }
15245 if (op1->value->type->data.error_set.err_count == 1 && op2->value->type->data.error_set.err_count == 1) {16274 if (op1->value->type->data.error_set.err_count == 1 && op2->value->type->data.error_set.err_count == 1) {
15246 bool are_equal = true;16275 bool are_equal = true;
...@@ -15252,17 +16281,17 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -15252,17 +16281,17 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
15252 } else {16281 } else {
15253 zig_unreachable();16282 zig_unreachable();
15254 }16283 }
15255 return ir_const_bool(ira, &bin_op_instruction->base, answer);16284 return ir_const_bool(ira, &bin_op_instruction->base.base, answer);
15256 }16285 }
15257 }16286 }
1525816287
15259 if (instr_is_comptime(op1) && instr_is_comptime(op2)) {16288 if (instr_is_comptime(op1) && instr_is_comptime(op2)) {
15260 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);16289 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
15261 if (op1_val == nullptr)16290 if (op1_val == nullptr)
15262 return ira->codegen->invalid_instruction;16291 return ira->codegen->invalid_inst_gen;
15263 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);16292 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);
15264 if (op2_val == nullptr)16293 if (op2_val == nullptr)
15265 return ira->codegen->invalid_instruction;16294 return ira->codegen->invalid_inst_gen;
1526616295
15267 bool answer;16296 bool answer;
15268 bool are_equal = op1_val->data.x_err_set->value == op2_val->data.x_err_set->value;16297 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 *...@@ -15274,27 +16303,24 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
15274 zig_unreachable();16303 zig_unreachable();
15275 }16304 }
1527616305
15277 return ir_const_bool(ira, &bin_op_instruction->base, answer);16306 return ir_const_bool(ira, &bin_op_instruction->base.base, answer);
15278 }16307 }
1527916308
15280 IrInstruction *result = ir_build_bin_op(&ira->new_irb,16309 return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, ira->codegen->builtin_types.entry_bool,
15281 bin_op_instruction->base.scope, bin_op_instruction->base.source_node,
15282 op_id, op1, op2, bin_op_instruction->safety_check_on);16310 op_id, op1, op2, bin_op_instruction->safety_check_on);
15283 result->value->type = ira->codegen->builtin_types.entry_bool;
15284 return result;
15285 }16311 }
1528616312
15287 if (type_is_numeric(op1->value->type) && type_is_numeric(op2->value->type)) {16313 if (type_is_numeric(op1->value->type) && type_is_numeric(op2->value->type)) {
15288 // This operation allows any combination of integer and float types, regardless of the16314 // This operation allows any combination of integer and float types, regardless of the
15289 // signed-ness, comptime-ness, and bit-width. So peer type resolution is incorrect for16315 // signed-ness, comptime-ness, and bit-width. So peer type resolution is incorrect for
15290 // numeric types.16316 // 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);
15292 }16318 }
1529316319
15294 IrInstruction *instructions[] = {op1, op2};16320 IrInstGen *instructions[] = {op1, op2};
15295 ZigType *resolved_type = ir_resolve_peer_types(ira, source_node, nullptr, instructions, 2);16321 ZigType *resolved_type = ir_resolve_peer_types(ira, source_node, nullptr, instructions, 2);
15296 if (type_is_invalid(resolved_type))16322 if (type_is_invalid(resolved_type))
15297 return ira->codegen->invalid_instruction;16323 return ira->codegen->invalid_inst_gen;
1529816324
15299 bool operator_allowed;16325 bool operator_allowed;
15300 switch (resolved_type->id) {16326 switch (resolved_type->id) {
...@@ -15342,21 +16368,21 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -15342,21 +16368,21 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
15342 if (!operator_allowed) {16368 if (!operator_allowed) {
15343 ir_add_error_node(ira, source_node,16369 ir_add_error_node(ira, source_node,
15344 buf_sprintf("operator not allowed for type '%s'", buf_ptr(&resolved_type->name)));16370 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;
15346 }16372 }
1534716373
15348 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, resolved_type);16374 IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, resolved_type);
15349 if (casted_op1 == ira->codegen->invalid_instruction)16375 if (type_is_invalid(casted_op1->value->type))
15350 return ira->codegen->invalid_instruction;16376 return ira->codegen->invalid_inst_gen;
1535116377
15352 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, resolved_type);16378 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, resolved_type);
15353 if (casted_op2 == ira->codegen->invalid_instruction)16379 if (type_is_invalid(casted_op2->value->type))
15354 return ira->codegen->invalid_instruction;16380 return ira->codegen->invalid_inst_gen;
1535516381
15356 bool one_possible_value;16382 bool one_possible_value;
15357 switch (type_has_one_possible_value(ira->codegen, resolved_type)) {16383 switch (type_has_one_possible_value(ira->codegen, resolved_type)) {
15358 case OnePossibleValueInvalid:16384 case OnePossibleValueInvalid:
15359 return ira->codegen->invalid_instruction;16385 return ira->codegen->invalid_inst_gen;
15360 case OnePossibleValueYes:16386 case OnePossibleValueYes:
15361 one_possible_value = true;16387 one_possible_value = true;
15362 break;16388 break;
...@@ -15368,20 +16394,20 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -15368,20 +16394,20 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
15368 if (one_possible_value || (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2))) {16394 if (one_possible_value || (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2))) {
15369 ZigValue *op1_val = one_possible_value ? casted_op1->value : ir_resolve_const(ira, casted_op1, UndefBad);16395 ZigValue *op1_val = one_possible_value ? casted_op1->value : ir_resolve_const(ira, casted_op1, UndefBad);
15370 if (op1_val == nullptr)16396 if (op1_val == nullptr)
15371 return ira->codegen->invalid_instruction;16397 return ira->codegen->invalid_inst_gen;
15372 ZigValue *op2_val = one_possible_value ? casted_op2->value : ir_resolve_const(ira, casted_op2, UndefBad);16398 ZigValue *op2_val = one_possible_value ? casted_op2->value : ir_resolve_const(ira, casted_op2, UndefBad);
15373 if (op2_val == nullptr)16399 if (op2_val == nullptr)
15374 return ira->codegen->invalid_instruction;16400 return ira->codegen->invalid_inst_gen;
15375 if (resolved_type->id != ZigTypeIdVector)16401 if (resolved_type->id != ZigTypeIdVector)
15376 return ir_evaluate_bin_op_cmp(ira, resolved_type, op1_val, op2_val, bin_op_instruction, op_id, one_possible_value);16402 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,
15378 get_vector_type(ira->codegen, resolved_type->data.vector.len, ira->codegen->builtin_types.entry_bool));16404 get_vector_type(ira->codegen, resolved_type->data.vector.len, ira->codegen->builtin_types.entry_bool));
15379 result->value->data.x_array.data.s_none.elements =16405 result->value->data.x_array.data.s_none.elements =
15380 create_const_vals(resolved_type->data.vector.len);16406 create_const_vals(resolved_type->data.vector.len);
1538116407
15382 expand_undef_array(ira->codegen, result->value);16408 expand_undef_array(ira->codegen, result->value);
15383 for (size_t i = 0;i < resolved_type->data.vector.len;i++) {16409 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,
15385 &op1_val->data.x_array.data.s_none.elements[i],16411 &op1_val->data.x_array.data.s_none.elements[i],
15386 &op2_val->data.x_array.data.s_none.elements[i],16412 &op2_val->data.x_array.data.s_none.elements[i],
15387 bin_op_instruction, op_id, one_possible_value);16413 bin_op_instruction, op_id, one_possible_value);
...@@ -15390,19 +16416,14 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -15390,19 +16416,14 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
15390 return result;16416 return result;
15391 }16417 }
1539216418
15393 IrInstruction *result = ir_build_bin_op(&ira->new_irb,16419 ZigType *res_type = (resolved_type->id == ZigTypeIdVector) ?
15394 bin_op_instruction->base.scope, bin_op_instruction->base.source_node,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,
15395 op_id, casted_op1, casted_op2, bin_op_instruction->safety_check_on);16423 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;
15403}16424}
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,
15406 ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val, ZigValue *out_val)16427 ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val, ZigValue *out_val)
15407{16428{
15408 bool is_int;16429 bool is_int;
...@@ -15582,10 +16603,10 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInstruction *source_in...@@ -15582,10 +16603,10 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInstruction *source_in
15582}16603}
1558316604
15584// This works on operands that have already been checked to be comptime known.16605// 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,
15586 ZigType *type_entry, ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val)16607 ZigType *type_entry, ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val)
15587{16608{
15588 IrInstruction *result_instruction = ir_const(ira, source_instr, type_entry);16609 IrInstGen *result_instruction = ir_const(ira, source_instr, type_entry);
15589 ZigValue *out_val = result_instruction->value;16610 ZigValue *out_val = result_instruction->value;
15590 if (type_entry->id == ZigTypeIdVector) {16611 if (type_entry->id == ZigTypeIdVector) {
15591 expand_undef_array(ira->codegen, op1_val);16612 expand_undef_array(ira->codegen, op1_val);
...@@ -15606,43 +16627,43 @@ static IrInstruction *ir_analyze_math_op(IrAnalyze *ira, IrInstruction *source_i...@@ -15606,43 +16627,43 @@ static IrInstruction *ir_analyze_math_op(IrAnalyze *ira, IrInstruction *source_i
15606 if (msg != nullptr) {16627 if (msg != nullptr) {
15607 add_error_note(ira->codegen, msg, source_instr->source_node,16628 add_error_note(ira->codegen, msg, source_instr->source_node,
15608 buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i));16629 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;
15610 }16631 }
15611 }16632 }
15612 out_val->type = type_entry;16633 out_val->type = type_entry;
15613 out_val->special = ConstValSpecialStatic;16634 out_val->special = ConstValSpecialStatic;
15614 } else {16635 } else {
15615 if (ir_eval_math_op_scalar(ira, source_instr, type_entry, op1_val, op_id, op2_val, out_val) != nullptr) {16636 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;
15617 }16638 }
15618 }16639 }
15619 return ir_implicit_cast(ira, result_instruction, type_entry);16640 return ir_implicit_cast(ira, result_instruction, type_entry);
15620}16641}
1562116642
15622static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {16643static IrInstGen *ir_analyze_bit_shift(IrAnalyze *ira, IrInstSrcBinOp *bin_op_instruction) {
15623 IrInstruction *op1 = bin_op_instruction->op1->child;16644 IrInstGen *op1 = bin_op_instruction->op1->child;
15624 if (type_is_invalid(op1->value->type))16645 if (type_is_invalid(op1->value->type))
15625 return ira->codegen->invalid_instruction;16646 return ira->codegen->invalid_inst_gen;
1562616647
15627 if (op1->value->type->id != ZigTypeIdInt && op1->value->type->id != ZigTypeIdComptimeInt) {16648 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,
15629 buf_sprintf("bit shifting operation expected integer type, found '%s'",16650 buf_sprintf("bit shifting operation expected integer type, found '%s'",
15630 buf_ptr(&op1->value->type->name)));16651 buf_ptr(&op1->value->type->name)));
15631 return ira->codegen->invalid_instruction;16652 return ira->codegen->invalid_inst_gen;
15632 }16653 }
1563316654
15634 IrInstruction *op2 = bin_op_instruction->op2->child;16655 IrInstGen *op2 = bin_op_instruction->op2->child;
15635 if (type_is_invalid(op2->value->type))16656 if (type_is_invalid(op2->value->type))
15636 return ira->codegen->invalid_instruction;16657 return ira->codegen->invalid_inst_gen;
1563716658
15638 if (op2->value->type->id != ZigTypeIdInt && op2->value->type->id != ZigTypeIdComptimeInt) {16659 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,
15640 buf_sprintf("shift amount has to be an integer type, but found '%s'",16661 buf_sprintf("shift amount has to be an integer type, but found '%s'",
15641 buf_ptr(&op2->value->type->name)));16662 buf_ptr(&op2->value->type->name)));
15642 return ira->codegen->invalid_instruction;16663 return ira->codegen->invalid_inst_gen;
15643 }16664 }
1564416665
15645 IrInstruction *casted_op2;16666 IrInstGen *casted_op2;
15646 IrBinOp op_id = bin_op_instruction->op_id;16667 IrBinOp op_id = bin_op_instruction->op_id;
15647 if (op1->value->type->id == ZigTypeIdComptimeInt) {16668 if (op1->value->type->id == ZigTypeIdComptimeInt) {
15648 casted_op2 = op2;16669 casted_op2 = op2;
...@@ -15654,8 +16675,8 @@ static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *b...@@ -15654,8 +16675,8 @@ static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *b
15654 if (casted_op2->value->data.x_bigint.is_negative) {16675 if (casted_op2->value->data.x_bigint.is_negative) {
15655 Buf *val_buf = buf_alloc();16676 Buf *val_buf = buf_alloc();
15656 bigint_append_buf(val_buf, &casted_op2->value->data.x_bigint, 10);16677 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)));16678 ir_add_error(ira, &casted_op2->base, buf_sprintf("shift by negative value %s", buf_ptr(val_buf)));
15658 return ira->codegen->invalid_instruction;16679 return ira->codegen->invalid_inst_gen;
15659 }16680 }
15660 } else {16681 } else {
15661 ZigType *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen,16682 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...@@ -15665,57 +16686,51 @@ static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *b
1566516686
15666 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);16687 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);
15667 if (op2_val == nullptr)16688 if (op2_val == nullptr)
15668 return ira->codegen->invalid_instruction;16689 return ira->codegen->invalid_inst_gen;
15669 if (!bigint_fits_in_bits(&op2_val->data.x_bigint,16690 if (!bigint_fits_in_bits(&op2_val->data.x_bigint,
15670 shift_amt_type->data.integral.bit_count,16691 shift_amt_type->data.integral.bit_count,
15671 op2_val->data.x_bigint.is_negative)) {16692 op2_val->data.x_bigint.is_negative)) {
15672 Buf *val_buf = buf_alloc();16693 Buf *val_buf = buf_alloc();
15673 bigint_append_buf(val_buf, &op2_val->data.x_bigint, 10);16694 bigint_append_buf(val_buf, &op2_val->data.x_bigint, 10);
15674 ErrorMsg* msg = ir_add_error(ira,16695 ErrorMsg* msg = ir_add_error(ira,
15675 &bin_op_instruction->base,16696 &bin_op_instruction->base.base,
15676 buf_sprintf("RHS of shift is too large for LHS type"));16697 buf_sprintf("RHS of shift is too large for LHS type"));
15677 add_error_note(16698 add_error_note(
15678 ira->codegen,16699 ira->codegen,
15679 msg,16700 msg,
15680 op2->source_node,16701 op2->base.source_node,
15681 buf_sprintf("value %s cannot fit into type %s",16702 buf_sprintf("value %s cannot fit into type %s",
15682 buf_ptr(val_buf),16703 buf_ptr(val_buf),
15683 buf_ptr(&shift_amt_type->name)));16704 buf_ptr(&shift_amt_type->name)));
15684 return ira->codegen->invalid_instruction;16705 return ira->codegen->invalid_inst_gen;
15685 }16706 }
15686 }16707 }
1568716708
15688 casted_op2 = ir_implicit_cast(ira, op2, shift_amt_type);16709 casted_op2 = ir_implicit_cast(ira, op2, shift_amt_type);
15689 if (casted_op2 == ira->codegen->invalid_instruction)16710 if (type_is_invalid(casted_op2->value->type))
15690 return ira->codegen->invalid_instruction;16711 return ira->codegen->invalid_inst_gen;
15691 }16712 }
1569216713
15693 if (instr_is_comptime(op1) && instr_is_comptime(casted_op2)) {16714 if (instr_is_comptime(op1) && instr_is_comptime(casted_op2)) {
15694 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);16715 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
15695 if (op1_val == nullptr)16716 if (op1_val == nullptr)
15696 return ira->codegen->invalid_instruction;16717 return ira->codegen->invalid_inst_gen;
1569716718
15698 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);16719 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
15699 if (op2_val == nullptr)16720 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);
15703 } else if (op1->value->type->id == ZigTypeIdComptimeInt) {16724 } 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,
15705 buf_sprintf("LHS of shift must be an integer type, or RHS must be compile-time known"));16726 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;
15707 } else if (instr_is_comptime(casted_op2) && bigint_cmp_zero(&casted_op2->value->data.x_bigint) == CmpEQ) {16728 } 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,16729 return ir_build_cast(ira, &bin_op_instruction->base.base, op1->value->type, op1, CastOpNoop);
15709 bin_op_instruction->base.source_node, op1->value->type, op1, CastOpNoop);
15710 result->value->type = op1->value->type;
15711 return result;
15712 }16730 }
1571316731
15714 IrInstruction *result = ir_build_bin_op(&ira->new_irb, bin_op_instruction->base.scope,16732 return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, op1->value->type,
15715 bin_op_instruction->base.source_node, op_id,16733 op_id, op1, casted_op2, bin_op_instruction->safety_check_on);
15716 op1, casted_op2, bin_op_instruction->safety_check_on);
15717 result->value->type = op1->value->type;
15718 return result;
15719}16734}
1572016735
15721static bool ok_float_op(IrBinOp op) {16736static bool ok_float_op(IrBinOp op) {
...@@ -15779,24 +16794,24 @@ static bool is_pointer_arithmetic_allowed(ZigType *lhs_type, IrBinOp op) {...@@ -15779,24 +16794,24 @@ static bool is_pointer_arithmetic_allowed(ZigType *lhs_type, IrBinOp op) {
15779 zig_unreachable();16794 zig_unreachable();
15780}16795}
1578116796
15782static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *instruction) {16797static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruction) {
15783 Error err;16798 Error err;
1578416799
15785 IrInstruction *op1 = instruction->op1->child;16800 IrInstGen *op1 = instruction->op1->child;
15786 if (type_is_invalid(op1->value->type))16801 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;
15790 if (type_is_invalid(op2->value->type))16805 if (type_is_invalid(op2->value->type))
15791 return ira->codegen->invalid_instruction;16806 return ira->codegen->invalid_inst_gen;
1579216807
15793 IrBinOp op_id = instruction->op_id;16808 IrBinOp op_id = instruction->op_id;
1579416809
15795 // look for pointer math16810 // look for pointer math
15796 if (is_pointer_arithmetic_allowed(op1->value->type, op_id)) {16811 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);
15798 if (type_is_invalid(casted_op2->value->type))16813 if (type_is_invalid(casted_op2->value->type))
15799 return ira->codegen->invalid_instruction;16814 return ira->codegen->invalid_inst_gen;
1580016815
15801 // If either operand is undef, result is undef.16816 // If either operand is undef, result is undef.
15802 ZigValue *op1_val = nullptr;16817 ZigValue *op1_val = nullptr;
...@@ -15804,28 +16819,28 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -15804,28 +16819,28 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
15804 if (instr_is_comptime(op1)) {16819 if (instr_is_comptime(op1)) {
15805 op1_val = ir_resolve_const(ira, op1, UndefOk);16820 op1_val = ir_resolve_const(ira, op1, UndefOk);
15806 if (op1_val == nullptr)16821 if (op1_val == nullptr)
15807 return ira->codegen->invalid_instruction;16822 return ira->codegen->invalid_inst_gen;
15808 if (op1_val->special == ConstValSpecialUndef)16823 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);
15810 }16825 }
15811 if (instr_is_comptime(casted_op2)) {16826 if (instr_is_comptime(casted_op2)) {
15812 op2_val = ir_resolve_const(ira, casted_op2, UndefOk);16827 op2_val = ir_resolve_const(ira, casted_op2, UndefOk);
15813 if (op2_val == nullptr)16828 if (op2_val == nullptr)
15814 return ira->codegen->invalid_instruction;16829 return ira->codegen->invalid_inst_gen;
15815 if (op2_val->special == ConstValSpecialUndef)16830 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);
15817 }16832 }
1581816833
15819 ZigType *elem_type = op1->value->type->data.pointer.child_type;16834 ZigType *elem_type = op1->value->type->data.pointer.child_type;
15820 if ((err = type_resolve(ira->codegen, elem_type, ResolveStatusSizeKnown)))16835 if ((err = type_resolve(ira->codegen, elem_type, ResolveStatusSizeKnown)))
15821 return ira->codegen->invalid_instruction;16836 return ira->codegen->invalid_inst_gen;
1582216837
15823 // NOTE: this variable is meaningful iff op2_val is not null!16838 // NOTE: this variable is meaningful iff op2_val is not null!
15824 uint64_t byte_offset;16839 uint64_t byte_offset;
15825 if (op2_val != nullptr) {16840 if (op2_val != nullptr) {
15826 uint64_t elem_offset;16841 uint64_t elem_offset;
15827 if (!ir_resolve_usize(ira, casted_op2, &elem_offset))16842 if (!ir_resolve_usize(ira, casted_op2, &elem_offset))
15828 return ira->codegen->invalid_instruction;16843 return ira->codegen->invalid_inst_gen;
1582916844
15830 byte_offset = type_size(ira->codegen, elem_type) * elem_offset;16845 byte_offset = type_size(ira->codegen, elem_type) * elem_offset;
15831 }16846 }
...@@ -15840,7 +16855,7 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -15840,7 +16855,7 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
15840 {16855 {
15841 uint32_t align_bytes;16856 uint32_t align_bytes;
15842 if ((err = resolve_ptr_align(ira, op1->value->type, &align_bytes)))16857 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
15845 // If the addend is not a comptime-known value we can still count on16860 // If the addend is not a comptime-known value we can still count on
15846 // it being a multiple of the type size16861 // it being a multiple of the type size
...@@ -15869,23 +16884,20 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -15869,23 +16884,20 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
15869 } else {16884 } else {
15870 zig_unreachable();16885 zig_unreachable();
15871 }16886 }
15872 IrInstruction *result = ir_const(ira, &instruction->base, result_type);16887 IrInstGen *result = ir_const(ira, &instruction->base.base, result_type);
15873 result->value->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;16888 result->value->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
15874 result->value->data.x_ptr.mut = ConstPtrMutRuntimeVar;16889 result->value->data.x_ptr.mut = ConstPtrMutRuntimeVar;
15875 result->value->data.x_ptr.data.hard_coded_addr.addr = new_addr;16890 result->value->data.x_ptr.data.hard_coded_addr.addr = new_addr;
15876 return result;16891 return result;
15877 }16892 }
1587816893
15879 IrInstruction *result = ir_build_bin_op(&ira->new_irb, instruction->base.scope,16894 return ir_build_bin_op_gen(ira, &instruction->base.base, result_type, op_id, op1, casted_op2, true);
15880 instruction->base.source_node, op_id, op1, casted_op2, true);
15881 result->value->type = result_type;
15882 return result;
15883 }16895 }
1588416896
15885 IrInstruction *instructions[] = {op1, op2};16897 IrInstGen *instructions[] = {op1, op2};
15886 ZigType *resolved_type = ir_resolve_peer_types(ira, instruction->base.source_node, nullptr, instructions, 2);16898 ZigType *resolved_type = ir_resolve_peer_types(ira, instruction->base.base.source_node, nullptr, instructions, 2);
15887 if (type_is_invalid(resolved_type))16899 if (type_is_invalid(resolved_type))
15888 return ira->codegen->invalid_instruction;16900 return ira->codegen->invalid_inst_gen;
1588916901
15890 bool is_int = resolved_type->id == ZigTypeIdInt || resolved_type->id == ZigTypeIdComptimeInt;16902 bool is_int = resolved_type->id == ZigTypeIdInt || resolved_type->id == ZigTypeIdComptimeInt;
15891 bool is_float = resolved_type->id == ZigTypeIdFloat || resolved_type->id == ZigTypeIdComptimeFloat;16903 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...@@ -15905,11 +16917,11 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
15905 if (instr_is_comptime(op1) && instr_is_comptime(op2)) {16917 if (instr_is_comptime(op1) && instr_is_comptime(op2)) {
15906 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);16918 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
15907 if (op1_val == nullptr)16919 if (op1_val == nullptr)
15908 return ira->codegen->invalid_instruction;16920 return ira->codegen->invalid_inst_gen;
1590916921
15910 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);16922 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);
15911 if (op2_val == nullptr)16923 if (op2_val == nullptr)
15912 return ira->codegen->invalid_instruction;16924 return ira->codegen->invalid_inst_gen;
1591316925
15914 if (bigint_cmp_zero(&op2_val->data.x_bigint) == CmpEQ) {16926 if (bigint_cmp_zero(&op2_val->data.x_bigint) == CmpEQ) {
15915 // the division by zero error will be caught later, but we don't have a16927 // 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...@@ -15928,11 +16940,11 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
15928 }16940 }
15929 }16941 }
15930 if (!ok) {16942 if (!ok) {
15931 ir_add_error(ira, &instruction->base,16943 ir_add_error(ira, &instruction->base.base,
15932 buf_sprintf("division with '%s' and '%s': signed integers must use @divTrunc, @divFloor, or @divExact",16944 buf_sprintf("division with '%s' and '%s': signed integers must use @divTrunc, @divFloor, or @divExact",
15933 buf_ptr(&op1->value->type->name),16945 buf_ptr(&op1->value->type->name),
15934 buf_ptr(&op2->value->type->name)));16946 buf_ptr(&op2->value->type->name)));
15935 return ira->codegen->invalid_instruction;16947 return ira->codegen->invalid_inst_gen;
15936 }16948 }
15937 } else {16949 } else {
15938 op_id = IrBinOpDivTrunc;16950 op_id = IrBinOpDivTrunc;
...@@ -15943,12 +16955,12 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -15943,12 +16955,12 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
15943 if (instr_is_comptime(op1) && instr_is_comptime(op2)) {16955 if (instr_is_comptime(op1) && instr_is_comptime(op2)) {
15944 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);16956 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
15945 if (op1_val == nullptr)16957 if (op1_val == nullptr)
15946 return ira->codegen->invalid_instruction;16958 return ira->codegen->invalid_inst_gen;
1594716959
15948 if (is_int) {16960 if (is_int) {
15949 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);16961 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);
15950 if (op2_val == nullptr)16962 if (op2_val == nullptr)
15951 return ira->codegen->invalid_instruction;16963 return ira->codegen->invalid_inst_gen;
1595216964
15953 if (bigint_cmp_zero(&op2->value->data.x_bigint) == CmpEQ) {16965 if (bigint_cmp_zero(&op2->value->data.x_bigint) == CmpEQ) {
15954 // the division by zero error will be caught later, but we don't16966 // 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...@@ -15962,13 +16974,13 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
15962 ok = bigint_cmp(&rem_result, &mod_result) == CmpEQ;16974 ok = bigint_cmp(&rem_result, &mod_result) == CmpEQ;
15963 }16975 }
15964 } else {16976 } else {
15965 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, resolved_type);16977 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, resolved_type);
15966 if (casted_op2 == ira->codegen->invalid_instruction)16978 if (type_is_invalid(casted_op2->value->type))
15967 return ira->codegen->invalid_instruction;16979 return ira->codegen->invalid_inst_gen;
1596816980
15969 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);16981 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
15970 if (op2_val == nullptr)16982 if (op2_val == nullptr)
15971 return ira->codegen->invalid_instruction;16983 return ira->codegen->invalid_inst_gen;
1597216984
15973 if (float_cmp_zero(casted_op2->value) == CmpEQ) {16985 if (float_cmp_zero(casted_op2->value) == CmpEQ) {
15974 // the division by zero error will be caught later, but we don't16986 // 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...@@ -15984,11 +16996,11 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
15984 }16996 }
15985 }16997 }
15986 if (!ok) {16998 if (!ok) {
15987 ir_add_error(ira, &instruction->base,16999 ir_add_error(ira, &instruction->base.base,
15988 buf_sprintf("remainder division with '%s' and '%s': signed integers and floats must use @rem or @mod",17000 buf_sprintf("remainder division with '%s' and '%s': signed integers and floats must use @rem or @mod",
15989 buf_ptr(&op1->value->type->name),17001 buf_ptr(&op1->value->type->name),
15990 buf_ptr(&op2->value->type->name)));17002 buf_ptr(&op2->value->type->name)));
15991 return ira->codegen->invalid_instruction;17003 return ira->codegen->invalid_inst_gen;
15992 }17004 }
15993 }17005 }
15994 op_id = IrBinOpRemRem;17006 op_id = IrBinOpRemRem;
...@@ -16008,12 +17020,12 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -16008,12 +17020,12 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
16008 }17020 }
16009 }17021 }
16010 if (!ok) {17022 if (!ok) {
16011 AstNode *source_node = instruction->base.source_node;17023 AstNode *source_node = instruction->base.base.source_node;
16012 ir_add_error_node(ira, source_node,17024 ir_add_error_node(ira, source_node,
16013 buf_sprintf("invalid operands to binary expression: '%s' and '%s'",17025 buf_sprintf("invalid operands to binary expression: '%s' and '%s'",
16014 buf_ptr(&op1->value->type->name),17026 buf_ptr(&op1->value->type->name),
16015 buf_ptr(&op2->value->type->name)));17027 buf_ptr(&op2->value->type->name)));
16016 return ira->codegen->invalid_instruction;17028 return ira->codegen->invalid_inst_gen;
16017 }17029 }
1601817030
16019 if (resolved_type->id == ZigTypeIdComptimeInt) {17031 if (resolved_type->id == ZigTypeIdComptimeInt) {
...@@ -16026,33 +17038,31 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -16026,33 +17038,31 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
16026 }17038 }
16027 }17039 }
1602817040
16029 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, resolved_type);17041 IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, resolved_type);
16030 if (casted_op1 == ira->codegen->invalid_instruction)17042 if (type_is_invalid(casted_op1->value->type))
16031 return ira->codegen->invalid_instruction;17043 return ira->codegen->invalid_inst_gen;
1603217044
16033 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, resolved_type);17045 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, resolved_type);
16034 if (casted_op2 == ira->codegen->invalid_instruction)17046 if (type_is_invalid(casted_op2->value->type))
16035 return ira->codegen->invalid_instruction;17047 return ira->codegen->invalid_inst_gen;
1603617048
16037 if (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2)) {17049 if (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2)) {
16038 ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);17050 ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);
16039 if (op1_val == nullptr)17051 if (op1_val == nullptr)
16040 return ira->codegen->invalid_instruction;17052 return ira->codegen->invalid_inst_gen;
16041 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);17053 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
16042 if (op2_val == nullptr)17054 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);
16046 }17058 }
1604717059
16048 IrInstruction *result = ir_build_bin_op(&ira->new_irb, instruction->base.scope,17060 return ir_build_bin_op_gen(ira, &instruction->base.base, resolved_type,
16049 instruction->base.source_node, op_id, casted_op1, casted_op2, instruction->safety_check_on);17061 op_id, casted_op1, casted_op2, instruction->safety_check_on);
16050 result->value->type = resolved_type;
16051 return result;
16052}17062}
1605317063
16054static IrInstruction *ir_analyze_tuple_cat(IrAnalyze *ira, IrInstruction *source_instr,17064static IrInstGen *ir_analyze_tuple_cat(IrAnalyze *ira, IrInst* source_instr,
16055 IrInstruction *op1, IrInstruction *op2)17065 IrInstGen *op1, IrInstGen *op2)
16056{17066{
16057 Error err;17067 Error err;
16058 ZigType *op1_type = op1->value->type;17068 ZigType *op1_type = op1->value->type;
...@@ -16069,9 +17079,9 @@ static IrInstruction *ir_analyze_tuple_cat(IrAnalyze *ira, IrInstruction *source...@@ -16069,9 +17079,9 @@ static IrInstruction *ir_analyze_tuple_cat(IrAnalyze *ira, IrInstruction *source
16069 new_type->data.structure.special = StructSpecialInferredTuple;17079 new_type->data.structure.special = StructSpecialInferredTuple;
16070 new_type->data.structure.resolve_status = ResolveStatusBeingInferred;17080 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(),
16075 new_type, nullptr, false, false, true);17085 new_type, nullptr, false, false, true);
16076 uint32_t new_field_count = op1_field_count + op2_field_count;17086 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...@@ -16095,13 +17105,13 @@ static IrInstruction *ir_analyze_tuple_cat(IrAnalyze *ira, IrInstruction *source
16095 new_field->is_comptime = src_field->is_comptime;17105 new_field->is_comptime = src_field->is_comptime;
16096 }17106 }
16097 if ((err = type_resolve(ira->codegen, new_type, ResolveStatusZeroBitsKnown)))17107 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 = {};17110 ZigList<IrInstGen *> const_ptrs = {};
16101 IrInstruction *first_non_const_instruction = nullptr;17111 IrInstGen *first_non_const_instruction = nullptr;
16102 for (uint32_t i = 0; i < new_field_count; i += 1) {17112 for (uint32_t i = 0; i < new_field_count; i += 1) {
16103 TypeStructField *dst_field = new_type->data.structure.fields[i];17113 TypeStructField *dst_field = new_type->data.structure.fields[i];
16104 IrInstruction *src_struct_op;17114 IrInstGen *src_struct_op;
16105 TypeStructField *src_field;17115 TypeStructField *src_field;
16106 if (i < op1_field_count) {17116 if (i < op1_field_count) {
16107 src_field = op1_type->data.structure.fields[i];17117 src_field = op1_type->data.structure.fields[i];
...@@ -16110,73 +17120,73 @@ static IrInstruction *ir_analyze_tuple_cat(IrAnalyze *ira, IrInstruction *source...@@ -16110,73 +17120,73 @@ static IrInstruction *ir_analyze_tuple_cat(IrAnalyze *ira, IrInstruction *source
16110 src_field = op2_type->data.structure.fields[i - op1_field_count];17120 src_field = op2_type->data.structure.fields[i - op1_field_count];
16111 src_struct_op = op2;17121 src_struct_op = op2;
16112 }17122 }
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,
16114 src_struct_op, src_field);17124 src_struct_op, src_field);
16115 if (type_is_invalid(field_value->value->type))17125 if (type_is_invalid(field_value->value->type))
16116 return ira->codegen->invalid_instruction;17126 return ira->codegen->invalid_inst_gen;
16117 IrInstruction *dest_ptr = ir_analyze_struct_field_ptr(ira, source_instr, dst_field,17127 IrInstGen *dest_ptr = ir_analyze_struct_field_ptr(ira, source_instr, dst_field,
16118 new_struct_ptr, new_type, true);17128 new_struct_ptr, new_type, true);
16119 if (type_is_invalid(dest_ptr->value->type))17129 if (type_is_invalid(dest_ptr->value->type))
16120 return ira->codegen->invalid_instruction;17130 return ira->codegen->invalid_inst_gen;
16121 if (instr_is_comptime(field_value)) {17131 if (instr_is_comptime(field_value)) {
16122 const_ptrs.append(dest_ptr);17132 const_ptrs.append(dest_ptr);
16123 } else {17133 } else {
16124 first_non_const_instruction = field_value;17134 first_non_const_instruction = field_value;
16125 }17135 }
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,
16127 true);17137 true);
16128 if (type_is_invalid(store_ptr_inst->value->type))17138 if (type_is_invalid(store_ptr_inst->value->type))
16129 return ira->codegen->invalid_instruction;17139 return ira->codegen->invalid_inst_gen;
16130 }17140 }
16131 if (const_ptrs.length != new_field_count) {17141 if (const_ptrs.length != new_field_count) {
16132 new_struct_ptr->value->special = ConstValSpecialRuntime;17142 new_struct_ptr->value->special = ConstValSpecialRuntime;
16133 for (size_t i = 0; i < const_ptrs.length; i += 1) {17143 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);
16135 assert(elem_result_loc->value->special == ConstValSpecialStatic);17145 assert(elem_result_loc->value->special == ConstValSpecialStatic);
16136 if (elem_result_loc->value->type->data.pointer.inferred_struct_field != nullptr) {17146 if (elem_result_loc->value->type->data.pointer.inferred_struct_field != nullptr) {
16137 // This field will be generated comptime; no need to do this.17147 // This field will be generated comptime; no need to do this.
16138 continue;17148 continue;
16139 }17149 }
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);
16141 elem_result_loc->value->special = ConstValSpecialRuntime;17151 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);
16143 }17153 }
16144 }17154 }
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);
16146 if (instr_is_comptime(result))17156 if (instr_is_comptime(result))
16147 return result;17157 return result;
1614817158
16149 if (is_comptime) {17159 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,
16151 buf_sprintf("unable to evaluate constant expression"));17161 buf_sprintf("unable to evaluate constant expression"));
16152 return ira->codegen->invalid_instruction;17162 return ira->codegen->invalid_inst_gen;
16153 }17163 }
1615417164
16155 return result;17165 return result;
16156}17166}
1615717167
16158static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruction) {17168static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instruction) {
16159 IrInstruction *op1 = instruction->op1->child;17169 IrInstGen *op1 = instruction->op1->child;
16160 ZigType *op1_type = op1->value->type;17170 ZigType *op1_type = op1->value->type;
16161 if (type_is_invalid(op1_type))17171 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;
16165 ZigType *op2_type = op2->value->type;17175 ZigType *op2_type = op2->value->type;
16166 if (type_is_invalid(op2_type))17176 if (type_is_invalid(op2_type))
16167 return ira->codegen->invalid_instruction;17177 return ira->codegen->invalid_inst_gen;
1616817178
16169 if (is_tuple(op1_type) && is_tuple(op2_type)) {17179 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);
16171 }17181 }
1617217182
16173 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);17183 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
16174 if (!op1_val)17184 if (!op1_val)
16175 return ira->codegen->invalid_instruction;17185 return ira->codegen->invalid_inst_gen;
1617617186
16177 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);17187 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);
16178 if (!op2_val)17188 if (!op2_val)
16179 return ira->codegen->invalid_instruction;17189 return ira->codegen->invalid_inst_gen;
1618017190
16181 ZigValue *sentinel1 = nullptr;17191 ZigValue *sentinel1 = nullptr;
16182 ZigValue *op1_array_val;17192 ZigValue *op1_array_val;
...@@ -16214,15 +17224,15 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -16214,15 +17224,15 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
16214 {17224 {
16215 ZigType *array_type = op1_type->data.pointer.child_type;17225 ZigType *array_type = op1_type->data.pointer.child_type;
16216 child_type = array_type->data.array.child_type;17226 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);
16218 if (op1_array_val == nullptr)17228 if (op1_array_val == nullptr)
16219 return ira->codegen->invalid_instruction;17229 return ira->codegen->invalid_inst_gen;
16220 op1_array_index = 0;17230 op1_array_index = 0;
16221 op1_array_end = array_type->data.array.len;17231 op1_array_end = array_type->data.array.len;
16222 sentinel1 = array_type->data.array.sentinel;17232 sentinel1 = array_type->data.array.sentinel;
16223 } else {17233 } else {
16224 ir_add_error(ira, op1, buf_sprintf("expected array, found '%s'", buf_ptr(&op1->value->type->name)));17234 ir_add_error(ira, &op1->base, buf_sprintf("expected array, found '%s'", buf_ptr(&op1->value->type->name)));
16225 return ira->codegen->invalid_instruction;17235 return ira->codegen->invalid_inst_gen;
16226 }17236 }
1622717237
16228 ZigValue *sentinel2 = nullptr;17238 ZigValue *sentinel2 = nullptr;
...@@ -16262,23 +17272,23 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -16262,23 +17272,23 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
16262 {17272 {
16263 ZigType *array_type = op2_type->data.pointer.child_type;17273 ZigType *array_type = op2_type->data.pointer.child_type;
16264 op2_type_valid = array_type->data.array.child_type == child_type;17274 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);
16266 if (op2_array_val == nullptr)17276 if (op2_array_val == nullptr)
16267 return ira->codegen->invalid_instruction;17277 return ira->codegen->invalid_inst_gen;
16268 op2_array_index = 0;17278 op2_array_index = 0;
16269 op2_array_end = array_type->data.array.len;17279 op2_array_end = array_type->data.array.len;
1627017280
16271 sentinel2 = array_type->data.array.sentinel;17281 sentinel2 = array_type->data.array.sentinel;
16272 } else {17282 } else {
16273 ir_add_error(ira, op2,17283 ir_add_error(ira, &op2->base,
16274 buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op2->value->type->name)));17284 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;
16276 }17286 }
16277 if (!op2_type_valid) {17287 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'",
16279 buf_ptr(&child_type->name),17289 buf_ptr(&child_type->name),
16280 buf_ptr(&op2->value->type->name)));17290 buf_ptr(&op2->value->type->name)));
16281 return ira->codegen->invalid_instruction;17291 return ira->codegen->invalid_inst_gen;
16282 }17292 }
1628317293
16284 ZigValue *sentinel;17294 ZigValue *sentinel;
...@@ -16295,7 +17305,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -16295,7 +17305,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
16295 }17305 }
1629617306
16297 // The type of result is populated in the following if blocks17307 // 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);
16299 ZigValue *out_val = result->value;17309 ZigValue *out_val = result->value;
1630017310
16301 ZigValue *out_array_val;17311 ZigValue *out_array_val;
...@@ -16383,14 +17393,14 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -16383,14 +17393,14 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
16383 return result;17393 return result;
16384}17394}
1638517395
16386static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *instruction) {17396static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruction) {
16387 IrInstruction *op1 = instruction->op1->child;17397 IrInstGen *op1 = instruction->op1->child;
16388 if (type_is_invalid(op1->value->type))17398 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;
16392 if (type_is_invalid(op2->value->type))17402 if (type_is_invalid(op2->value->type))
16393 return ira->codegen->invalid_instruction;17403 return ira->codegen->invalid_inst_gen;
1639417404
16395 bool want_ptr_to_array = false;17405 bool want_ptr_to_array = false;
16396 ZigType *array_type;17406 ZigType *array_type;
...@@ -16399,49 +17409,49 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *...@@ -16399,49 +17409,49 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *
16399 array_type = op1->value->type;17409 array_type = op1->value->type;
16400 array_val = ir_resolve_const(ira, op1, UndefOk);17410 array_val = ir_resolve_const(ira, op1, UndefOk);
16401 if (array_val == nullptr)17411 if (array_val == nullptr)
16402 return ira->codegen->invalid_instruction;17412 return ira->codegen->invalid_inst_gen;
16403 } else if (op1->value->type->id == ZigTypeIdPointer && op1->value->type->data.pointer.ptr_len == PtrLenSingle &&17413 } else if (op1->value->type->id == ZigTypeIdPointer && op1->value->type->data.pointer.ptr_len == PtrLenSingle &&
16404 op1->value->type->data.pointer.child_type->id == ZigTypeIdArray)17414 op1->value->type->data.pointer.child_type->id == ZigTypeIdArray)
16405 {17415 {
16406 array_type = op1->value->type->data.pointer.child_type;17416 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);
16408 if (type_is_invalid(array_inst->value->type))17418 if (type_is_invalid(array_inst->value->type))
16409 return ira->codegen->invalid_instruction;17419 return ira->codegen->invalid_inst_gen;
16410 array_val = ir_resolve_const(ira, array_inst, UndefOk);17420 array_val = ir_resolve_const(ira, array_inst, UndefOk);
16411 if (array_val == nullptr)17421 if (array_val == nullptr)
16412 return ira->codegen->invalid_instruction;17422 return ira->codegen->invalid_inst_gen;
16413 want_ptr_to_array = true;17423 want_ptr_to_array = true;
16414 } else {17424 } else {
16415 ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value->type->name)));17425 ir_add_error(ira, &op1->base, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value->type->name)));
16416 return ira->codegen->invalid_instruction;17426 return ira->codegen->invalid_inst_gen;
16417 }17427 }
1641817428
16419 uint64_t mult_amt;17429 uint64_t mult_amt;
16420 if (!ir_resolve_usize(ira, op2, &mult_amt))17430 if (!ir_resolve_usize(ira, op2, &mult_amt))
16421 return ira->codegen->invalid_instruction;17431 return ira->codegen->invalid_inst_gen;
1642217432
16423 uint64_t old_array_len = array_type->data.array.len;17433 uint64_t old_array_len = array_type->data.array.len;
16424 uint64_t new_array_len;17434 uint64_t new_array_len;
1642517435
16426 if (mul_u64_overflow(old_array_len, mult_amt, &new_array_len)) {17436 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"));17437 ir_add_error(ira, &instruction->base.base, buf_sprintf("operation results in overflow"));
16428 return ira->codegen->invalid_instruction;17438 return ira->codegen->invalid_inst_gen;
16429 }17439 }
1643017440
16431 ZigType *child_type = array_type->data.array.child_type;17441 ZigType *child_type = array_type->data.array.child_type;
16432 ZigType *result_array_type = get_array_type(ira->codegen, child_type, new_array_len,17442 ZigType *result_array_type = get_array_type(ira->codegen, child_type, new_array_len,
16433 array_type->data.array.sentinel);17443 array_type->data.array.sentinel);
1643417444
16435 IrInstruction *array_result;17445 IrInstGen *array_result;
16436 if (array_val->special == ConstValSpecialUndef || array_val->data.x_array.special == ConstArraySpecialUndef) {17446 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);
16438 } else {17448 } else {
16439 array_result = ir_const(ira, &instruction->base, result_array_type);17449 array_result = ir_const(ira, &instruction->base.base, result_array_type);
16440 ZigValue *out_val = array_result->value;17450 ZigValue *out_val = array_result->value;
1644117451
16442 switch (type_has_one_possible_value(ira->codegen, result_array_type)) {17452 switch (type_has_one_possible_value(ira->codegen, result_array_type)) {
16443 case OnePossibleValueInvalid:17453 case OnePossibleValueInvalid:
16444 return ira->codegen->invalid_instruction;17454 return ira->codegen->invalid_inst_gen;
16445 case OnePossibleValueYes:17455 case OnePossibleValueYes:
16446 goto skip_computation;17456 goto skip_computation;
16447 case OnePossibleValueNo:17457 case OnePossibleValueNo:
...@@ -16477,35 +17487,35 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *...@@ -16477,35 +17487,35 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *
16477 }17487 }
16478skip_computation:17488skip_computation:
16479 if (want_ptr_to_array) {17489 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);
16481 } else {17491 } else {
16482 return array_result;17492 return array_result;
16483 }17493 }
16484}17494}
1648517495
16486static IrInstruction *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira,17496static IrInstGen *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira,
16487 IrInstructionMergeErrSets *instruction)17497 IrInstSrcMergeErrSets *instruction)
16488{17498{
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);
16490 if (type_is_invalid(op1_type))17500 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);
16494 if (type_is_invalid(op2_type))17504 if (type_is_invalid(op2_type))
16495 return ira->codegen->invalid_instruction;17505 return ira->codegen->invalid_inst_gen;
1649617506
16497 if (type_is_global_error_set(op1_type) ||17507 if (type_is_global_error_set(op1_type) ||
16498 type_is_global_error_set(op2_type))17508 type_is_global_error_set(op2_type))
16499 {17509 {
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);
16501 }17511 }
1650217512
16503 if (!resolve_inferred_error_set(ira->codegen, op1_type, instruction->op1->child->source_node)) {17513 if (!resolve_inferred_error_set(ira->codegen, op1_type, instruction->op1->child->base.source_node)) {
16504 return ira->codegen->invalid_instruction;17514 return ira->codegen->invalid_inst_gen;
16505 }17515 }
1650617516
16507 if (!resolve_inferred_error_set(ira->codegen, op2_type, instruction->op2->child->source_node)) {17517 if (!resolve_inferred_error_set(ira->codegen, op2_type, instruction->op2->child->base.source_node)) {
16508 return ira->codegen->invalid_instruction;17518 return ira->codegen->invalid_inst_gen;
16509 }17519 }
1651017520
16511 size_t errors_count = ira->codegen->errors_by_index.length;17521 size_t errors_count = ira->codegen->errors_by_index.length;
...@@ -16518,11 +17528,11 @@ static IrInstruction *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira,...@@ -16518,11 +17528,11 @@ static IrInstruction *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira,
16518 ZigType *result_type = get_error_set_union(ira->codegen, errors, op1_type, op2_type, instruction->type_name);17528 ZigType *result_type = get_error_set_union(ira->codegen, errors, op1_type, op2_type, instruction->type_name);
16519 deallocate(errors, errors_count, "ErrorTableEntry *");17529 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);
16522}17532}
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) {
16526 IrBinOp op_id = bin_op_instruction->op_id;17536 IrBinOp op_id = bin_op_instruction->op_id;
16527 switch (op_id) {17537 switch (op_id) {
16528 case IrBinOpInvalid:17538 case IrBinOpInvalid:
...@@ -16567,41 +17577,39 @@ static IrInstruction *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructio...@@ -16567,41 +17577,39 @@ static IrInstruction *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructio
16567 zig_unreachable();17577 zig_unreachable();
16568}17578}
1656917579
16570static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,17580static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclVar *decl_var_instruction) {
16571 IrInstructionDeclVarSrc *decl_var_instruction)
16572{
16573 Error err;17581 Error err;
16574 ZigVar *var = decl_var_instruction->var;17582 ZigVar *var = decl_var_instruction->var;
1657517583
16576 ZigType *explicit_type = nullptr;17584 ZigType *explicit_type = nullptr;
16577 IrInstruction *var_type = nullptr;17585 IrInstGen *var_type = nullptr;
16578 if (decl_var_instruction->var_type != nullptr) {17586 if (decl_var_instruction->var_type != nullptr) {
16579 var_type = decl_var_instruction->var_type->child;17587 var_type = decl_var_instruction->var_type->child;
16580 ZigType *proposed_type = ir_resolve_type(ira, var_type);17588 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);
16582 if (type_is_invalid(explicit_type)) {17590 if (type_is_invalid(explicit_type)) {
16583 var->var_type = ira->codegen->builtin_types.entry_invalid;17591 var->var_type = ira->codegen->builtin_types.entry_invalid;
16584 return ira->codegen->invalid_instruction;17592 return ira->codegen->invalid_inst_gen;
16585 }17593 }
16586 }17594 }
1658717595
16588 AstNode *source_node = decl_var_instruction->base.source_node;17596 AstNode *source_node = decl_var_instruction->base.base.source_node;
1658917597
16590 bool is_comptime_var = ir_get_var_is_comptime(var);17598 bool is_comptime_var = ir_get_var_is_comptime(var);
1659117599
16592 bool var_class_requires_const = false;17600 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;
16595 // if this is null, a compiler error happened and did not initialize the variable.17603 // if this is null, a compiler error happened and did not initialize the variable.
16596 // if there are no compile errors there may be a missing ir_expr_wrap in pass1 IR generation.17604 // if there are no compile errors there may be a missing ir_expr_wrap in pass1 IR generation.
16597 if (var_ptr == nullptr || type_is_invalid(var_ptr->value->type)) {17605 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);
16599 var->var_type = ira->codegen->builtin_types.entry_invalid;17607 var->var_type = ira->codegen->builtin_types.entry_invalid;
16600 return ira->codegen->invalid_instruction;17608 return ira->codegen->invalid_inst_gen;
16601 }17609 }
1660217610
16603 // The ir_build_var_decl_src call is supposed to pass a pointer to the allocation, not an initialization value.17611 // 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
16606 ZigType *result_type = var_ptr->value->type->data.pointer.child_type;17614 ZigType *result_type = var_ptr->value->type->data.pointer.child_type;
16607 if (type_is_invalid(result_type)) {17615 if (type_is_invalid(result_type)) {
...@@ -16612,7 +17620,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,...@@ -16612,7 +17620,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
1661217620
16613 ZigValue *init_val = nullptr;17621 ZigValue *init_val = nullptr;
16614 if (instr_is_comptime(var_ptr) && var_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {17622 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);
16616 if (is_comptime_var) {17624 if (is_comptime_var) {
16617 if (var->gen_is_const) {17625 if (var->gen_is_const) {
16618 var->const_value = init_val;17626 var->const_value = init_val;
...@@ -16639,7 +17647,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,...@@ -16639,7 +17647,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
16639 case ReqCompTimeNo:17647 case ReqCompTimeNo:
16640 if (init_val != nullptr && value_is_comptime(init_val)) {17648 if (init_val != nullptr && value_is_comptime(init_val)) {
16641 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,17649 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)))
16643 {17651 {
16644 result_type = ira->codegen->builtin_types.entry_invalid;17652 result_type = ira->codegen->builtin_types.entry_invalid;
16645 } else if (init_val->type->id == ZigTypeIdFn &&17653 } else if (init_val->type->id == ZigTypeIdFn &&
...@@ -16687,13 +17695,13 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,...@@ -16687,13 +17695,13 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
16687 assert(var->var_type);17695 assert(var->var_type);
1668817696
16689 if (type_is_invalid(result_type)) {17697 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);
16691 }17699 }
1669217700
16693 if (decl_var_instruction->align_value == nullptr) {17701 if (decl_var_instruction->align_value == nullptr) {
16694 if ((err = type_resolve(ira->codegen, result_type, ResolveStatusAlignmentKnown))) {17702 if ((err = type_resolve(ira->codegen, result_type, ResolveStatusAlignmentKnown))) {
16695 var->var_type = ira->codegen->builtin_types.entry_invalid;17703 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);
16697 }17705 }
16698 var->align_bytes = get_abi_alignment(ira->codegen, result_type);17706 var->align_bytes = get_abi_alignment(ira->codegen, result_type);
16699 } else {17707 } else {
...@@ -16712,17 +17720,17 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,...@@ -16712,17 +17720,17 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
16712 // we need a runtime ptr but we have a comptime val.17720 // we need a runtime ptr but we have a comptime val.
16713 // since it's a comptime val there are no instructions for it.17721 // since it's a comptime val there are no instructions for it.
16714 // we memcpy the init value here17722 // 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);
16716 if (type_is_invalid(deref->value->type)) {17724 if (type_is_invalid(deref->value->type)) {
16717 var->var_type = ira->codegen->builtin_types.entry_invalid;17725 var->var_type = ira->codegen->builtin_types.entry_invalid;
16718 return ira->codegen->invalid_instruction;17726 return ira->codegen->invalid_inst_gen;
16719 }17727 }
16720 // If this assertion trips, something is wrong with the IR instructions, because17728 // If this assertion trips, something is wrong with the IR instructions, because
16721 // we expected the above deref to return a constant value, but it created a runtime17729 // we expected the above deref to return a constant value, but it created a runtime
16722 // instruction.17730 // instruction.
16723 assert(deref->value->special != ConstValSpecialRuntime);17731 assert(deref->value->special != ConstValSpecialRuntime);
16724 var_ptr->value->special = ConstValSpecialRuntime;17732 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);
16726 }17734 }
1672717735
16728 if (instr_is_comptime(var_ptr) && var->mem_slot_index != SIZE_MAX) {17736 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,...@@ -16732,84 +17740,84 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
16732 ira_ref(var->owner_exec->analysis);17740 ira_ref(var->owner_exec->analysis);
1673317741
16734 if (is_comptime_var || (var_class_requires_const && var->gen_is_const)) {17742 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);
16736 }17744 }
16737 }17745 }
16738 } else if (is_comptime_var) {17746 } else if (is_comptime_var) {
16739 ir_add_error(ira, &decl_var_instruction->base,17747 ir_add_error(ira, &decl_var_instruction->base.base,
16740 buf_sprintf("cannot store runtime value in compile time variable"));17748 buf_sprintf("cannot store runtime value in compile time variable"));
16741 var->var_type = ira->codegen->builtin_types.entry_invalid;17749 var->var_type = ira->codegen->builtin_types.entry_invalid;
16742 return ira->codegen->invalid_instruction;17750 return ira->codegen->invalid_inst_gen;
16743 }17751 }
1674417752
16745 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);17753 ZigFn *fn_entry = ira->new_irb.exec->fn_entry;
16746 if (fn_entry)17754 if (fn_entry)
16747 fn_entry->variable_list.append(var);17755 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);
16750}17758}
1675117759
16752static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExport *instruction) {17760static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport *instruction) {
16753 IrInstruction *target = instruction->target->child;17761 IrInstGen *target = instruction->target->child;
16754 if (type_is_invalid(target->value->type))17762 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;
16758 if (type_is_invalid(options->value->type))17766 if (type_is_invalid(options->value->type))
16759 return ira->codegen->invalid_instruction;17767 return ira->codegen->invalid_inst_gen;
1676017768
16761 ZigType *options_type = options->value->type;17769 ZigType *options_type = options->value->type;
16762 assert(options_type->id == ZigTypeIdStruct);17770 assert(options_type->id == ZigTypeIdStruct);
1676317771
16764 TypeStructField *name_field = find_struct_type_field(options_type, buf_create_from_str("name"));17772 TypeStructField *name_field = find_struct_type_field(options_type, buf_create_from_str("name"));
16765 ir_assert(name_field != nullptr, &instruction->base);17773 ir_assert(name_field != nullptr, &instruction->base.base);
16766 IrInstruction *name_inst = ir_analyze_struct_value_field_value(ira, &instruction->base, options, name_field);17774 IrInstGen *name_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, name_field);
16767 if (type_is_invalid(name_inst->value->type))17775 if (type_is_invalid(name_inst->value->type))
16768 return ira->codegen->invalid_instruction;17776 return ira->codegen->invalid_inst_gen;
1676917777
16770 TypeStructField *linkage_field = find_struct_type_field(options_type, buf_create_from_str("linkage"));17778 TypeStructField *linkage_field = find_struct_type_field(options_type, buf_create_from_str("linkage"));
16771 ir_assert(linkage_field != nullptr, &instruction->base);17779 ir_assert(linkage_field != nullptr, &instruction->base.base);
16772 IrInstruction *linkage_inst = ir_analyze_struct_value_field_value(ira, &instruction->base, options, linkage_field);17780 IrInstGen *linkage_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, linkage_field);
16773 if (type_is_invalid(linkage_inst->value->type))17781 if (type_is_invalid(linkage_inst->value->type))
16774 return ira->codegen->invalid_instruction;17782 return ira->codegen->invalid_inst_gen;
1677517783
16776 TypeStructField *section_field = find_struct_type_field(options_type, buf_create_from_str("section"));17784 TypeStructField *section_field = find_struct_type_field(options_type, buf_create_from_str("section"));
16777 ir_assert(section_field != nullptr, &instruction->base);17785 ir_assert(section_field != nullptr, &instruction->base.base);
16778 IrInstruction *section_inst = ir_analyze_struct_value_field_value(ira, &instruction->base, options, section_field);17786 IrInstGen *section_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, section_field);
16779 if (type_is_invalid(section_inst->value->type))17787 if (type_is_invalid(section_inst->value->type))
16780 return ira->codegen->invalid_instruction;17788 return ira->codegen->invalid_inst_gen;
1678117789
16782 // The `section` field is optional, we have to unwrap it first17790 // 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);
16784 bool is_non_null;17792 bool is_non_null;
16785 if (!ir_resolve_bool(ira, non_null_check, &is_non_null))17793 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;
16789 if (is_non_null) {17797 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);
16791 if (type_is_invalid(section_str_inst->value->type))17799 if (type_is_invalid(section_str_inst->value->type))
16792 return ira->codegen->invalid_instruction;17800 return ira->codegen->invalid_inst_gen;
16793 }17801 }
1679417802
16795 // Resolve all the comptime values17803 // Resolve all the comptime values
16796 Buf *symbol_name = ir_resolve_str(ira, name_inst);17804 Buf *symbol_name = ir_resolve_str(ira, name_inst);
16797 if (!symbol_name)17805 if (!symbol_name)
16798 return ira->codegen->invalid_instruction;17806 return ira->codegen->invalid_inst_gen;
1679917807
16800 if (buf_len(symbol_name) < 1) {17808 if (buf_len(symbol_name) < 1) {
16801 ir_add_error(ira, name_inst,17809 ir_add_error(ira, &name_inst->base,
16802 buf_sprintf("exported symbol name cannot be empty"));17810 buf_sprintf("exported symbol name cannot be empty"));
16803 return ira->codegen->invalid_instruction;17811 return ira->codegen->invalid_inst_gen;
16804 }17812 }
1680517813
16806 GlobalLinkageId global_linkage_id;17814 GlobalLinkageId global_linkage_id;
16807 if (!ir_resolve_global_linkage(ira, linkage_inst, &global_linkage_id))17815 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
16810 Buf *section_name = nullptr;17818 Buf *section_name = nullptr;
16811 if (section_str_inst != nullptr && !(section_name = ir_resolve_str(ira, section_str_inst)))17819 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
16814 // TODO: This function needs to be audited.17822 // TODO: This function needs to be audited.
16815 // It's not clear how all the different types are supposed to be handled.17823 // 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...@@ -16817,15 +17825,15 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
16817 // in another file.17825 // in another file.
16818 TldFn *tld_fn = allocate<TldFn>(1);17826 TldFn *tld_fn = allocate<TldFn>(1);
16819 tld_fn->base.id = TldIdFn;17827 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
16822 auto entry = ira->codegen->exported_symbol_names.put_unique(symbol_name, &tld_fn->base);17830 auto entry = ira->codegen->exported_symbol_names.put_unique(symbol_name, &tld_fn->base);
16823 if (entry) {17831 if (entry) {
16824 AstNode *other_export_node = entry->value->source_node;17832 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,
16826 buf_sprintf("exported symbol collision: '%s'", buf_ptr(symbol_name)));17834 buf_sprintf("exported symbol collision: '%s'", buf_ptr(symbol_name)));
16827 add_error_note(ira->codegen, msg, other_export_node, buf_sprintf("other symbol is here"));17835 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;
16829 }17837 }
1683017838
16831 Error err;17839 Error err;
...@@ -16841,12 +17849,12 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio...@@ -16841,12 +17849,12 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
16841 CallingConvention cc = fn_entry->type_entry->data.fn.fn_type_id.cc;17849 CallingConvention cc = fn_entry->type_entry->data.fn.fn_type_id.cc;
16842 switch (cc) {17850 switch (cc) {
16843 case CallingConventionUnspecified: {17851 case CallingConventionUnspecified: {
16844 ErrorMsg *msg = ir_add_error(ira, target,17852 ErrorMsg *msg = ir_add_error(ira, &target->base,
16845 buf_sprintf("exported function must specify calling convention"));17853 buf_sprintf("exported function must specify calling convention"));
16846 add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here"));17854 add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here"));
16847 } break;17855 } break;
16848 case CallingConventionAsync: {17856 case CallingConventionAsync: {
16849 ErrorMsg *msg = ir_add_error(ira, target,17857 ErrorMsg *msg = ir_add_error(ira, &target->base,
16850 buf_sprintf("exported function cannot be async"));17858 buf_sprintf("exported function cannot be async"));
16851 add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here"));17859 add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here"));
16852 } break;17860 } break;
...@@ -16869,10 +17877,10 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio...@@ -16869,10 +17877,10 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
16869 } break;17877 } break;
16870 case ZigTypeIdStruct:17878 case ZigTypeIdStruct:
16871 if (is_slice(target->value->type)) {17879 if (is_slice(target->value->type)) {
16872 ir_add_error(ira, target,17880 ir_add_error(ira, &target->base,
16873 buf_sprintf("unable to export value of type '%s'", buf_ptr(&target->value->type->name)));17881 buf_sprintf("unable to export value of type '%s'", buf_ptr(&target->value->type->name)));
16874 } else if (target->value->type->data.structure.layout != ContainerLayoutExtern) {17882 } 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,
16876 buf_sprintf("exported struct value must be declared extern"));17884 buf_sprintf("exported struct value must be declared extern"));
16877 add_error_note(ira->codegen, msg, target->value->type->data.structure.decl_node, buf_sprintf("declared here"));17885 add_error_note(ira->codegen, msg, target->value->type->data.structure.decl_node, buf_sprintf("declared here"));
16878 } else {17886 } else {
...@@ -16881,7 +17889,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio...@@ -16881,7 +17889,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
16881 break;17889 break;
16882 case ZigTypeIdUnion:17890 case ZigTypeIdUnion:
16883 if (target->value->type->data.unionation.layout != ContainerLayoutExtern) {17891 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,
16885 buf_sprintf("exported union value must be declared extern"));17893 buf_sprintf("exported union value must be declared extern"));
16886 add_error_note(ira->codegen, msg, target->value->type->data.unionation.decl_node, buf_sprintf("declared here"));17894 add_error_note(ira->codegen, msg, target->value->type->data.unionation.decl_node, buf_sprintf("declared here"));
16887 } else {17895 } else {
...@@ -16890,7 +17898,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio...@@ -16890,7 +17898,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
16890 break;17898 break;
16891 case ZigTypeIdEnum:17899 case ZigTypeIdEnum:
16892 if (target->value->type->data.enumeration.layout != ContainerLayoutExtern) {17900 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,
16894 buf_sprintf("exported enum value must be declared extern"));17902 buf_sprintf("exported enum value must be declared extern"));
16895 add_error_note(ira->codegen, msg, target->value->type->data.enumeration.decl_node, buf_sprintf("declared here"));17903 add_error_note(ira->codegen, msg, target->value->type->data.enumeration.decl_node, buf_sprintf("declared here"));
16896 } else {17904 } else {
...@@ -16900,10 +17908,10 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio...@@ -16900,10 +17908,10 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
16900 case ZigTypeIdArray: {17908 case ZigTypeIdArray: {
16901 bool ok_type;17909 bool ok_type;
16902 if ((err = type_allowed_in_extern(ira->codegen, target->value->type->data.array.child_type, &ok_type)))17910 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
16905 if (!ok_type) {17913 if (!ok_type) {
16906 ir_add_error(ira, target,17914 ir_add_error(ira, &target->base,
16907 buf_sprintf("array element type '%s' not extern-compatible",17915 buf_sprintf("array element type '%s' not extern-compatible",
16908 buf_ptr(&target->value->type->data.array.child_type->name)));17916 buf_ptr(&target->value->type->data.array.child_type->name)));
16909 } else {17917 } else {
...@@ -16918,31 +17926,31 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio...@@ -16918,31 +17926,31 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
16918 zig_unreachable();17926 zig_unreachable();
16919 case ZigTypeIdStruct:17927 case ZigTypeIdStruct:
16920 if (is_slice(type_value)) {17928 if (is_slice(type_value)) {
16921 ir_add_error(ira, target,17929 ir_add_error(ira, &target->base,
16922 buf_sprintf("unable to export type '%s'", buf_ptr(&type_value->name)));17930 buf_sprintf("unable to export type '%s'", buf_ptr(&type_value->name)));
16923 } else if (type_value->data.structure.layout != ContainerLayoutExtern) {17931 } 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,
16925 buf_sprintf("exported struct must be declared extern"));17933 buf_sprintf("exported struct must be declared extern"));
16926 add_error_note(ira->codegen, msg, type_value->data.structure.decl_node, buf_sprintf("declared here"));17934 add_error_note(ira->codegen, msg, type_value->data.structure.decl_node, buf_sprintf("declared here"));
16927 }17935 }
16928 break;17936 break;
16929 case ZigTypeIdUnion:17937 case ZigTypeIdUnion:
16930 if (type_value->data.unionation.layout != ContainerLayoutExtern) {17938 if (type_value->data.unionation.layout != ContainerLayoutExtern) {
16931 ErrorMsg *msg = ir_add_error(ira, target,17939 ErrorMsg *msg = ir_add_error(ira, &target->base,
16932 buf_sprintf("exported union must be declared extern"));17940 buf_sprintf("exported union must be declared extern"));
16933 add_error_note(ira->codegen, msg, type_value->data.unionation.decl_node, buf_sprintf("declared here"));17941 add_error_note(ira->codegen, msg, type_value->data.unionation.decl_node, buf_sprintf("declared here"));
16934 }17942 }
16935 break;17943 break;
16936 case ZigTypeIdEnum:17944 case ZigTypeIdEnum:
16937 if (type_value->data.enumeration.layout != ContainerLayoutExtern) {17945 if (type_value->data.enumeration.layout != ContainerLayoutExtern) {
16938 ErrorMsg *msg = ir_add_error(ira, target,17946 ErrorMsg *msg = ir_add_error(ira, &target->base,
16939 buf_sprintf("exported enum must be declared extern"));17947 buf_sprintf("exported enum must be declared extern"));
16940 add_error_note(ira->codegen, msg, type_value->data.enumeration.decl_node, buf_sprintf("declared here"));17948 add_error_note(ira->codegen, msg, type_value->data.enumeration.decl_node, buf_sprintf("declared here"));
16941 }17949 }
16942 break;17950 break;
16943 case ZigTypeIdFn: {17951 case ZigTypeIdFn: {
16944 if (type_value->data.fn.fn_type_id.cc == CallingConventionUnspecified) {17952 if (type_value->data.fn.fn_type_id.cc == CallingConventionUnspecified) {
16945 ir_add_error(ira, target,17953 ir_add_error(ira, &target->base,
16946 buf_sprintf("exported function type must specify calling convention"));17954 buf_sprintf("exported function type must specify calling convention"));
16947 }17955 }
16948 } break;17956 } break;
...@@ -16968,7 +17976,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio...@@ -16968,7 +17976,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
16968 case ZigTypeIdOpaque:17976 case ZigTypeIdOpaque:
16969 case ZigTypeIdFnFrame:17977 case ZigTypeIdFnFrame:
16970 case ZigTypeIdAnyFrame:17978 case ZigTypeIdAnyFrame:
16971 ir_add_error(ira, target,17979 ir_add_error(ira, &target->base,
16972 buf_sprintf("invalid export target '%s'", buf_ptr(&type_value->name)));17980 buf_sprintf("invalid export target '%s'", buf_ptr(&type_value->name)));
16973 break;17981 break;
16974 }17982 }
...@@ -16993,61 +18001,55 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio...@@ -16993,61 +18001,55 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
16993 case ZigTypeIdEnumLiteral:18001 case ZigTypeIdEnumLiteral:
16994 case ZigTypeIdFnFrame:18002 case ZigTypeIdFnFrame:
16995 case ZigTypeIdAnyFrame:18003 case ZigTypeIdAnyFrame:
16996 ir_add_error(ira, target,18004 ir_add_error(ira, &target->base,
16997 buf_sprintf("invalid export target type '%s'", buf_ptr(&target->value->type->name)));18005 buf_sprintf("invalid export target type '%s'", buf_ptr(&target->value->type->name)));
16998 break;18006 break;
16999 }18007 }
1700018008
17001 // TODO audit the various ways to use @export18009 // TODO audit the various ways to use @export
17002 if (want_var_export && target->id == IrInstructionIdLoadPtrGen) {18010 if (want_var_export && target->id == IrInstGenIdLoadPtr) {
17003 IrInstructionLoadPtrGen *load_ptr = reinterpret_cast<IrInstructionLoadPtrGen *>(target);18011 IrInstGenLoadPtr *load_ptr = reinterpret_cast<IrInstGenLoadPtr *>(target);
17004 if (load_ptr->ptr->id == IrInstructionIdVarPtr) {18012 if (load_ptr->ptr->id == IrInstGenIdVarPtr) {
17005 IrInstructionVarPtr *var_ptr = reinterpret_cast<IrInstructionVarPtr *>(load_ptr->ptr);18013 IrInstGenVarPtr *var_ptr = reinterpret_cast<IrInstGenVarPtr *>(load_ptr->ptr);
17006 ZigVar *var = var_ptr->var;18014 ZigVar *var = var_ptr->var;
17007 add_var_export(ira->codegen, var, buf_ptr(symbol_name), global_linkage_id);18015 add_var_export(ira->codegen, var, buf_ptr(symbol_name), global_linkage_id);
17008 var->section_name = section_name;18016 var->section_name = section_name;
17009 }18017 }
17010 }18018 }
1701118019
17012 return ir_const_void(ira, &instruction->base);18020 return ir_const_void(ira, &instruction->base.base);
17013}18021}
1701418022
17015static bool exec_has_err_ret_trace(CodeGen *g, IrExecutable *exec) {18023static bool exec_has_err_ret_trace(CodeGen *g, IrExecutableSrc *exec) {
17016 ZigFn *fn_entry = exec_fn_entry(exec);18024 ZigFn *fn_entry = exec_fn_entry(exec);
17017 return fn_entry != nullptr && fn_entry->calls_or_awaits_errorable_fn && g->have_err_ret_tracing;18025 return fn_entry != nullptr && fn_entry->calls_or_awaits_errorable_fn && g->have_err_ret_tracing;
17018}18026}
1701918027
17020static IrInstruction *ir_analyze_instruction_error_return_trace(IrAnalyze *ira,18028static IrInstGen *ir_analyze_instruction_error_return_trace(IrAnalyze *ira,
17021 IrInstructionErrorReturnTrace *instruction)18029 IrInstSrcErrorReturnTrace *instruction)
17022{18030{
17023 ZigType *ptr_to_stack_trace_type = get_pointer_to_type(ira->codegen, get_stack_trace_type(ira->codegen), false);18031 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) {
17025 ZigType *optional_type = get_optional_type(ira->codegen, ptr_to_stack_trace_type);18033 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)) {18034 if (!exec_has_err_ret_trace(ira->codegen, ira->old_irb.exec)) {
17027 IrInstruction *result = ir_const(ira, &instruction->base, optional_type);18035 IrInstGen *result = ir_const(ira, &instruction->base.base, optional_type);
17028 ZigValue *out_val = result->value;18036 ZigValue *out_val = result->value;
17029 assert(get_codegen_ptr_type(optional_type) != nullptr);18037 assert(get_codegen_ptr_type(optional_type) != nullptr);
17030 out_val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;18038 out_val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
17031 out_val->data.x_ptr.data.hard_coded_addr.addr = 0;18039 out_val->data.x_ptr.data.hard_coded_addr.addr = 0;
17032 return result;18040 return result;
17033 }18041 }
17034 IrInstruction *new_instruction = ir_build_error_return_trace(&ira->new_irb, instruction->base.scope,18042 return ir_build_error_return_trace_gen(ira, instruction->base.base.scope,
17035 instruction->base.source_node, instruction->optional);18043 instruction->base.base.source_node, instruction->optional, optional_type);
17036 new_instruction->value->type = optional_type;
17037 return new_instruction;
17038 } else {18044 } else {
17039 assert(ira->codegen->have_err_ret_tracing);18045 assert(ira->codegen->have_err_ret_tracing);
17040 IrInstruction *new_instruction = ir_build_error_return_trace(&ira->new_irb, instruction->base.scope,18046 return ir_build_error_return_trace_gen(ira, instruction->base.base.scope,
17041 instruction->base.source_node, instruction->optional);18047 instruction->base.base.source_node, instruction->optional, ptr_to_stack_trace_type);
17042 new_instruction->value->type = ptr_to_stack_trace_type;
17043 return new_instruction;
17044 }18048 }
17045}18049}
1704618050
17047static IrInstruction *ir_analyze_instruction_error_union(IrAnalyze *ira,18051static IrInstGen *ir_analyze_instruction_error_union(IrAnalyze *ira, IrInstSrcErrorUnion *instruction) {
17048 IrInstructionErrorUnion *instruction)18052 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);
17049{
17050 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type);
17051 result->value->special = ConstValSpecialLazy;18053 result->value->special = ConstValSpecialLazy;
1705218054
17053 LazyValueErrUnionType *lazy_err_union_type = allocate<LazyValueErrUnionType>(1, "LazyValueErrUnionType");18055 LazyValueErrUnionType *lazy_err_union_type = allocate<LazyValueErrUnionType>(1, "LazyValueErrUnionType");
...@@ -17057,16 +18059,16 @@ static IrInstruction *ir_analyze_instruction_error_union(IrAnalyze *ira,...@@ -17057,16 +18059,16 @@ static IrInstruction *ir_analyze_instruction_error_union(IrAnalyze *ira,
1705718059
17058 lazy_err_union_type->err_set_type = instruction->err_set->child;18060 lazy_err_union_type->err_set_type = instruction->err_set->child;
17059 if (ir_resolve_type_lazy(ira, lazy_err_union_type->err_set_type) == nullptr)18061 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
17062 lazy_err_union_type->payload_type = instruction->payload->child;18064 lazy_err_union_type->payload_type = instruction->payload->child;
17063 if (ir_resolve_type_lazy(ira, lazy_err_union_type->payload_type) == nullptr)18065 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
17066 return result;18068 return result;
17067}18069}
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,
17070 uint32_t align, const char *name_hint, bool force_comptime)18072 uint32_t align, const char *name_hint, bool force_comptime)
17071{18073{
17072 Error err;18074 Error err;
...@@ -17074,7 +18076,7 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in...@@ -17074,7 +18076,7 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in
17074 ZigValue *pointee = create_const_vals(1);18076 ZigValue *pointee = create_const_vals(1);
17075 pointee->special = ConstValSpecialUndef;18077 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);
17078 result->base.value->special = ConstValSpecialStatic;18080 result->base.value->special = ConstValSpecialStatic;
17079 result->base.value->data.x_ptr.special = ConstPtrSpecialRef;18081 result->base.value->data.x_ptr.special = ConstPtrSpecialRef;
17080 result->base.value->data.x_ptr.mut = force_comptime ? ConstPtrMutComptimeVar : ConstPtrMutInfer;18082 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...@@ -17082,15 +18084,15 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in
1708218084
17083 bool var_type_has_bits;18085 bool var_type_has_bits;
17084 if ((err = type_has_bits2(ira->codegen, var_type, &var_type_has_bits)))18086 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;
17086 if (align != 0) {18088 if (align != 0) {
17087 if ((err = type_resolve(ira->codegen, var_type, ResolveStatusAlignmentKnown)))18089 if ((err = type_resolve(ira->codegen, var_type, ResolveStatusAlignmentKnown)))
17088 return ira->codegen->invalid_instruction;18090 return ira->codegen->invalid_inst_gen;
17089 if (!var_type_has_bits) {18091 if (!var_type_has_bits) {
17090 ir_add_error(ira, source_inst,18092 ir_add_error(ira, source_inst,
17091 buf_sprintf("variable '%s' of zero-bit type '%s' has no in-memory representation, it cannot be aligned",18093 buf_sprintf("variable '%s' of zero-bit type '%s' has no in-memory representation, it cannot be aligned",
17092 name_hint, buf_ptr(&var_type->name)));18094 name_hint, buf_ptr(&var_type->name)));
17093 return ira->codegen->invalid_instruction;18095 return ira->codegen->invalid_inst_gen;
17094 }18096 }
17095 }18097 }
17096 assert(result->base.value->data.x_ptr.special != ConstPtrSpecialInvalid);18098 assert(result->base.value->data.x_ptr.special != ConstPtrSpecialInvalid);
...@@ -17099,15 +18101,14 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in...@@ -17099,15 +18101,14 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in
17099 result->base.value->type = get_pointer_to_type_extra(ira->codegen, var_type, false, false,18101 result->base.value->type = get_pointer_to_type_extra(ira->codegen, var_type, false, false,
17100 PtrLenSingle, align, 0, 0, false);18102 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;
17103 if (fn_entry != nullptr) {18105 if (fn_entry != nullptr) {
17104 fn_entry->alloca_gen_list.append(result);18106 fn_entry->alloca_gen_list.append(result);
17105 }18107 }
17106 result->base.is_gen = true;
17107 return &result->base;18108 return &result->base;
17108}18109}
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,
17111 ResultLoc *result_loc)18112 ResultLoc *result_loc)
17112{18113{
17113 switch (result_loc->id) {18114 switch (result_loc->id) {
...@@ -17150,7 +18151,7 @@ static bool type_can_bit_cast(ZigType *t) {...@@ -17150,7 +18151,7 @@ static bool type_can_bit_cast(ZigType *t) {
17150 }18151 }
17151}18152}
1715218153
17153static void set_up_result_loc_for_inferred_comptime(IrInstruction *ptr) {18154static void set_up_result_loc_for_inferred_comptime(IrInstGen *ptr) {
17154 ZigValue *undef_child = create_const_vals(1);18155 ZigValue *undef_child = create_const_vals(1);
17155 undef_child->type = ptr->value->type->data.pointer.child_type;18156 undef_child->type = ptr->value->type->data.pointer.child_type;
17156 undef_child->special = ConstValSpecialUndef;18157 undef_child->special = ConstValSpecialUndef;
...@@ -17189,16 +18190,16 @@ static Error ir_result_has_type(IrAnalyze *ira, ResultLoc *result_loc, bool *out...@@ -17189,16 +18190,16 @@ static Error ir_result_has_type(IrAnalyze *ira, ResultLoc *result_loc, bool *out
17189 zig_unreachable();18190 zig_unreachable();
17190}18191}
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,
17193 ResultLoc *result_loc, ZigType *value_type, bool force_runtime, bool non_null_comptime)18194 ResultLoc *result_loc, ZigType *value_type, bool force_runtime, bool non_null_comptime)
17194{18195{
17195 if (type_is_invalid(value_type))18196 if (type_is_invalid(value_type))
17196 return ira->codegen->invalid_instruction;18197 return ira->codegen->invalid_inst_gen;
17197 IrInstructionAllocaGen *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr, 0, "");18198 IrInstGenAlloca *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr, 0, "");
17198 alloca_gen->base.value->type = get_pointer_to_type_extra(ira->codegen, value_type, false, false,18199 alloca_gen->base.value->type = get_pointer_to_type_extra(ira->codegen, value_type, false, false,
17199 PtrLenSingle, 0, 0, 0, false);18200 PtrLenSingle, 0, 0, 0, false);
17200 set_up_result_loc_for_inferred_comptime(&alloca_gen->base);18201 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;
17202 if (fn_entry != nullptr && get_scope_typeof(suspend_source_instr->scope) == nullptr) {18203 if (fn_entry != nullptr && get_scope_typeof(suspend_source_instr->scope) == nullptr) {
17203 fn_entry->alloca_gen_list.append(alloca_gen);18204 fn_entry->alloca_gen_list.append(alloca_gen);
17204 }18205 }
...@@ -17208,8 +18209,8 @@ static IrInstruction *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstruction *su...@@ -17208,8 +18209,8 @@ static IrInstruction *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstruction *su
17208}18209}
1720918210
17210// when calling this function, at the callsite must check for result type noreturn and propagate it up18211// 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,18212static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_instr,
17212 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime,18213 ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime,
17213 bool non_null_comptime, bool allow_discard)18214 bool non_null_comptime, bool allow_discard)
17214{18215{
17215 Error err;18216 Error err;
...@@ -17235,35 +18236,34 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -17235,35 +18236,34 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
17235 }18236 }
17236 case ResultLocIdVar: {18237 case ResultLocIdVar: {
17237 ResultLocVar *result_loc_var = reinterpret_cast<ResultLocVar *>(result_loc);18238 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
17240 if (value_type->id == ZigTypeIdUnreachable || value_type->id == ZigTypeIdOpaque) {18241 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,
17242 buf_sprintf("variable of type '%s' not allowed", buf_ptr(&value_type->name)));18243 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;
17244 }18245 }
1724518246
17246 IrInstructionAllocaSrc *alloca_src =18247 IrInstSrcAlloca *alloca_src = reinterpret_cast<IrInstSrcAlloca *>(result_loc->source_instruction);
17247 reinterpret_cast<IrInstructionAllocaSrc *>(result_loc->source_instruction);
17248 bool force_comptime;18248 bool force_comptime;
17249 if (!ir_resolve_comptime(ira, alloca_src->is_comptime->child, &force_comptime))18249 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;
17251 bool is_comptime = force_comptime || (!force_runtime && value != nullptr &&18251 bool is_comptime = force_comptime || (!force_runtime && value != nullptr &&
17252 value->value->special != ConstValSpecialRuntime && result_loc_var->var->gen_is_const);18252 value->value->special != ConstValSpecialRuntime && result_loc_var->var->gen_is_const);
1725318253
17254 if (alloca_src->base.child == nullptr || is_comptime) {18254 if (alloca_src->base.child == nullptr || is_comptime) {
17255 uint32_t align = 0;18255 uint32_t align = 0;
17256 if (alloca_src->align != nullptr && !ir_resolve_align(ira, alloca_src->align->child, nullptr, &align)) {18256 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;
17258 }18258 }
17259 IrInstruction *alloca_gen;18259 IrInstGen *alloca_gen;
17260 if (is_comptime && value != nullptr) {18260 if (is_comptime && value != nullptr) {
17261 if (align > value->value->llvm_align) {18261 if (align > value->value->llvm_align) {
17262 value->value->llvm_align = align;18262 value->value->llvm_align = align;
17263 }18263 }
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);
17265 } else {18265 } 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,
17267 alloca_src->name_hint, force_comptime);18267 alloca_src->name_hint, force_comptime);
17268 if (force_runtime) {18268 if (force_runtime) {
17269 alloca_gen->value->data.x_ptr.mut = ConstPtrMutRuntimeVar;18269 alloca_gen->value->data.x_ptr.mut = ConstPtrMutRuntimeVar;
...@@ -17271,7 +18271,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -17271,7 +18271,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
17271 }18271 }
17272 }18272 }
17273 if (alloca_src->base.child != nullptr && !result_loc->written) {18273 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;
17275 }18275 }
17276 alloca_src->base.child = alloca_gen;18276 alloca_src->base.child = alloca_gen;
17277 }18277 }
...@@ -17296,9 +18296,9 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -17296,9 +18296,9 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
17296 }18296 }
17297 bool has_bits;18297 bool has_bits;
17298 if ((err = type_has_bits2(ira->codegen, ira->explicit_return_type, &has_bits)))18298 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;
17300 if (!has_bits || !handle_is_ptr(ira->explicit_return_type)) {18300 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;
17302 if (fn_entry == nullptr || fn_entry->inferred_async_node == nullptr) {18302 if (fn_entry == nullptr || fn_entry->inferred_async_node == nullptr) {
17303 return nullptr;18303 return nullptr;
17304 }18304 }
...@@ -17306,8 +18306,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -17306,8 +18306,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1730618306
17307 ZigType *ptr_return_type = get_pointer_to_type(ira->codegen, ira->explicit_return_type, false);18307 ZigType *ptr_return_type = get_pointer_to_type(ira->codegen, ira->explicit_return_type, false);
17308 result_loc->written = true;18308 result_loc->written = true;
17309 result_loc->resolved_loc = ir_build_return_ptr(ira, result_loc->source_instruction, ptr_return_type);18309 result_loc->resolved_loc = ir_build_return_ptr(ira, &result_loc->source_instruction->base, ptr_return_type);
17310 if (ir_should_inline(ira->old_irb.exec, result_loc->source_instruction->scope)) {18310 if (ir_should_inline(ira->old_irb.exec, result_loc->source_instruction->base.scope)) {
17311 set_up_result_loc_for_inferred_comptime(result_loc->resolved_loc);18311 set_up_result_loc_for_inferred_comptime(result_loc->resolved_loc);
17312 }18312 }
17313 return result_loc->resolved_loc;18313 return result_loc->resolved_loc;
...@@ -17317,7 +18317,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -17317,7 +18317,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
17317 ResultLocPeerParent *peer_parent = result_peer->parent;18317 ResultLocPeerParent *peer_parent = result_peer->parent;
1731818318
17319 if (peer_parent->peers.length == 1) {18319 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,
17321 value_type, value, force_runtime, non_null_comptime, true);18321 value_type, value, force_runtime, non_null_comptime, true);
17322 result_peer->suspend_pos.basic_block_index = SIZE_MAX;18322 result_peer->suspend_pos.basic_block_index = SIZE_MAX;
17323 result_peer->suspend_pos.instruction_index = SIZE_MAX;18323 result_peer->suspend_pos.instruction_index = SIZE_MAX;
...@@ -17333,7 +18333,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -17333,7 +18333,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1733318333
17334 bool is_condition_comptime;18334 bool is_condition_comptime;
17335 if (!ir_resolve_comptime(ira, peer_parent->is_comptime->child, &is_condition_comptime))18335 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;
17337 if (is_condition_comptime) {18337 if (is_condition_comptime) {
17338 peer_parent->skipped = true;18338 peer_parent->skipped = true;
17339 if (non_null_comptime) {18339 if (non_null_comptime) {
...@@ -17344,10 +18344,10 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -17344,10 +18344,10 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
17344 }18344 }
17345 bool peer_parent_has_type;18345 bool peer_parent_has_type;
17346 if ((err = ir_result_has_type(ira, peer_parent->parent, &peer_parent_has_type)))18346 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;
17348 if (peer_parent_has_type) {18348 if (peer_parent_has_type) {
17349 peer_parent->skipped = true;18349 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,
17351 value_type, value, force_runtime || !is_condition_comptime, true, true);18351 value_type, value, force_runtime || !is_condition_comptime, true, true);
17352 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||18352 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||
17353 parent_result_loc->value->type->id == ZigTypeIdUnreachable)18353 parent_result_loc->value->type->id == ZigTypeIdUnreachable)
...@@ -17364,7 +18364,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -17364,7 +18364,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
17364 if (peer_parent->end_bb->suspend_instruction_ref == nullptr) {18364 if (peer_parent->end_bb->suspend_instruction_ref == nullptr) {
17365 peer_parent->end_bb->suspend_instruction_ref = suspend_source_instr;18365 peer_parent->end_bb->suspend_instruction_ref = suspend_source_instr;
17366 }18366 }
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,
17368 &result_peer->suspend_pos);18368 &result_peer->suspend_pos);
17369 if (result_peer->next_bb == nullptr) {18369 if (result_peer->next_bb == nullptr) {
17370 ir_start_next_bb(ira);18370 ir_start_next_bb(ira);
...@@ -17372,7 +18372,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -17372,7 +18372,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
17372 return unreach_inst;18372 return unreach_inst;
17373 }18373 }
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,
17376 peer_parent->resolved_type, nullptr, force_runtime, non_null_comptime, true);18376 peer_parent->resolved_type, nullptr, force_runtime, non_null_comptime, true);
17377 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||18377 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||
17378 parent_result_loc->value->type->id == ZigTypeIdUnreachable)18378 parent_result_loc->value->type->id == ZigTypeIdUnreachable)
...@@ -17391,24 +18391,24 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -17391,24 +18391,24 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
17391 ResultLocCast *result_cast = reinterpret_cast<ResultLocCast *>(result_loc);18391 ResultLocCast *result_cast = reinterpret_cast<ResultLocCast *>(result_loc);
17392 ZigType *dest_type = ir_resolve_type(ira, result_cast->base.source_instruction->child);18392 ZigType *dest_type = ir_resolve_type(ira, result_cast->base.source_instruction->child);
17393 if (type_is_invalid(dest_type))18393 if (type_is_invalid(dest_type))
17394 return ira->codegen->invalid_instruction;18394 return ira->codegen->invalid_inst_gen;
1739518395
17396 if (dest_type == ira->codegen->builtin_types.entry_var) {18396 if (dest_type == ira->codegen->builtin_types.entry_var) {
17397 return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type,18397 return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type,
17398 force_runtime, non_null_comptime);18398 force_runtime, non_null_comptime);
17399 }18399 }
1740018400
17401 IrInstruction *casted_value;18401 IrInstGen *casted_value;
17402 if (value != nullptr) {18402 if (value != nullptr) {
17403 casted_value = ir_implicit_cast(ira, value, dest_type);18403 casted_value = ir_implicit_cast(ira, value, dest_type);
17404 if (type_is_invalid(casted_value->value->type))18404 if (type_is_invalid(casted_value->value->type))
17405 return ira->codegen->invalid_instruction;18405 return ira->codegen->invalid_inst_gen;
17406 dest_type = casted_value->value->type;18406 dest_type = casted_value->value->type;
17407 } else {18407 } else {
17408 casted_value = nullptr;18408 casted_value = nullptr;
17409 }18409 }
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,
17412 dest_type, casted_value, force_runtime, non_null_comptime, true);18412 dest_type, casted_value, force_runtime, non_null_comptime, true);
17413 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||18413 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||
17414 parent_result_loc->value->type->id == ZigTypeIdUnreachable)18414 parent_result_loc->value->type->id == ZigTypeIdUnreachable)
...@@ -17422,11 +18422,11 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -17422,11 +18422,11 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
17422 if ((err = type_resolve(ira->codegen, parent_ptr_type->data.pointer.child_type,18422 if ((err = type_resolve(ira->codegen, parent_ptr_type->data.pointer.child_type,
17423 ResolveStatusAlignmentKnown)))18423 ResolveStatusAlignmentKnown)))
17424 {18424 {
17425 return ira->codegen->invalid_instruction;18425 return ira->codegen->invalid_inst_gen;
17426 }18426 }
17427 uint64_t parent_ptr_align = get_ptr_align(ira->codegen, parent_ptr_type);18427 uint64_t parent_ptr_align = get_ptr_align(ira->codegen, parent_ptr_type);
17428 if ((err = type_resolve(ira->codegen, value_type, ResolveStatusAlignmentKnown))) {18428 if ((err = type_resolve(ira->codegen, value_type, ResolveStatusAlignmentKnown))) {
17429 return ira->codegen->invalid_instruction;18429 return ira->codegen->invalid_inst_gen;
17430 }18430 }
17431 if (!type_has_bits(value_type)) {18431 if (!type_has_bits(value_type)) {
17432 parent_ptr_align = 0;18432 parent_ptr_align = 0;
...@@ -17449,9 +18449,9 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -17449,9 +18449,9 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1744918449
17450 ConstCastOnly const_cast_result = types_match_const_cast_only(ira,18450 ConstCastOnly const_cast_result = types_match_const_cast_only(ira,
17451 parent_result_loc->value->type, ptr_type,18451 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);
17453 if (const_cast_result.id == ConstCastResultIdInvalid)18453 if (const_cast_result.id == ConstCastResultIdInvalid)
17454 return ira->codegen->invalid_instruction;18454 return ira->codegen->invalid_inst_gen;
17455 if (const_cast_result.id != ConstCastResultIdOk) {18455 if (const_cast_result.id != ConstCastResultIdOk) {
17456 if (allow_discard) {18456 if (allow_discard) {
17457 return parent_result_loc;18457 return parent_result_loc;
...@@ -17465,42 +18465,42 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -17465,42 +18465,42 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1746518465
17466 result_loc->written = true;18466 result_loc->written = true;
17467 result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc,18467 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);
17469 return result_loc->resolved_loc;18469 return result_loc->resolved_loc;
17470 }18470 }
17471 case ResultLocIdBitCast: {18471 case ResultLocIdBitCast: {
17472 ResultLocBitCast *result_bit_cast = reinterpret_cast<ResultLocBitCast *>(result_loc);18472 ResultLocBitCast *result_bit_cast = reinterpret_cast<ResultLocBitCast *>(result_loc);
17473 ZigType *dest_type = ir_resolve_type(ira, result_bit_cast->base.source_instruction->child);18473 ZigType *dest_type = ir_resolve_type(ira, result_bit_cast->base.source_instruction->child);
17474 if (type_is_invalid(dest_type))18474 if (type_is_invalid(dest_type))
17475 return ira->codegen->invalid_instruction;18475 return ira->codegen->invalid_inst_gen;
1747618476
17477 if (get_codegen_ptr_type(dest_type) != nullptr) {18477 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,
17479 buf_sprintf("unable to @bitCast to pointer type '%s'", buf_ptr(&dest_type->name)));18479 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;
17481 }18481 }
1748218482
17483 if (!type_can_bit_cast(dest_type)) {18483 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,
17485 buf_sprintf("unable to @bitCast to type '%s'", buf_ptr(&dest_type->name)));18485 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;
17487 }18487 }
1748818488
17489 if (get_codegen_ptr_type(value_type) != nullptr) {18489 if (get_codegen_ptr_type(value_type) != nullptr) {
17490 ir_add_error(ira, suspend_source_instr,18490 ir_add_error(ira, suspend_source_instr,
17491 buf_sprintf("unable to @bitCast from pointer type '%s'", buf_ptr(&value_type->name)));18491 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;
17493 }18493 }
1749418494
17495 if (!type_can_bit_cast(value_type)) {18495 if (!type_can_bit_cast(value_type)) {
17496 ir_add_error(ira, suspend_source_instr,18496 ir_add_error(ira, suspend_source_instr,
17497 buf_sprintf("unable to @bitCast from type '%s'", buf_ptr(&value_type->name)));18497 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;
17499 }18499 }
1750018500
17501 IrInstruction *bitcasted_value;18501 IrInstGen *bitcasted_value;
17502 if (value != nullptr) {18502 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);
17504 dest_type = bitcasted_value->value->type;18504 dest_type = bitcasted_value->value->type;
17505 } else {18505 } else {
17506 bitcasted_value = nullptr;18506 bitcasted_value = nullptr;
...@@ -17510,7 +18510,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -17510,7 +18510,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
17510 return bitcasted_value;18510 return bitcasted_value;
17511 }18511 }
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,
17514 dest_type, bitcasted_value, force_runtime, non_null_comptime, true);18514 dest_type, bitcasted_value, force_runtime, non_null_comptime, true);
17515 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||18515 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||
17516 parent_result_loc->value->type->id == ZigTypeIdUnreachable)18516 parent_result_loc->value->type->id == ZigTypeIdUnreachable)
...@@ -17523,7 +18523,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -17523,7 +18523,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1752318523
17524 bool has_bits;18524 bool has_bits;
17525 if ((err = type_has_bits2(ira->codegen, child_type, &has_bits))) {18525 if ((err = type_has_bits2(ira->codegen, child_type, &has_bits))) {
17526 return ira->codegen->invalid_instruction;18526 return ira->codegen->invalid_inst_gen;
17527 }18527 }
1752818528
17529 // This happens when the bitCast result is assigned to _18529 // This happens when the bitCast result is assigned to _
...@@ -17533,12 +18533,12 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -17533,12 +18533,12 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
17533 }18533 }
1753418534
17535 if ((err = type_resolve(ira->codegen, child_type, ResolveStatusAlignmentKnown))) {18535 if ((err = type_resolve(ira->codegen, child_type, ResolveStatusAlignmentKnown))) {
17536 return ira->codegen->invalid_instruction;18536 return ira->codegen->invalid_inst_gen;
17537 }18537 }
1753818538
17539 uint64_t parent_ptr_align = get_ptr_align(ira->codegen, parent_ptr_type);18539 uint64_t parent_ptr_align = get_ptr_align(ira->codegen, parent_ptr_type);
17540 if ((err = type_resolve(ira->codegen, value_type, ResolveStatusAlignmentKnown))) {18540 if ((err = type_resolve(ira->codegen, value_type, ResolveStatusAlignmentKnown))) {
17541 return ira->codegen->invalid_instruction;18541 return ira->codegen->invalid_inst_gen;
17542 }18542 }
17543 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value_type,18543 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value_type,
17544 parent_ptr_type->data.pointer.is_const, parent_ptr_type->data.pointer.is_volatile, PtrLenSingle,18544 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...@@ -17546,29 +18546,33 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1754618546
17547 result_loc->written = true;18547 result_loc->written = true;
17548 result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc,18548 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);
17550 return result_loc->resolved_loc;18550 return result_loc->resolved_loc;
17551 }18551 }
17552 }18552 }
17553 zig_unreachable();18553 zig_unreachable();
17554}18554}
1755518555
17556static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_source_instr,18556static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr,
17557 ResultLoc *result_loc_pass1, ZigType *value_type, IrInstruction *value, bool force_runtime,18557 ResultLoc *result_loc_pass1, ZigType *value_type, IrInstGen *value, bool force_runtime,
17558 bool non_null_comptime, bool allow_discard)18558 bool non_null_comptime, bool allow_discard)
17559{18559{
17560 Error err;18560 Error err;
17561 if (!allow_discard && result_loc_pass1->id == ResultLocIdInstruction &&18561 if (!allow_discard && result_loc_pass1->id == ResultLocIdInstruction &&
17562 instr_is_comptime(result_loc_pass1->source_instruction) &&18562 result_loc_pass1->source_instruction->id == IrInstSrcIdConst)
17563 result_loc_pass1->source_instruction->value->type->id == ZigTypeIdPointer &&
17564 result_loc_pass1->source_instruction->value->data.x_ptr.special == ConstPtrSpecialDiscard)
17565 {18563 {
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 }
17567 }18571 }
17568 bool was_already_resolved = result_loc_pass1->resolved_loc != nullptr;18572 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,
17570 value, force_runtime, non_null_comptime, allow_discard);18574 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)))
17572 return result_loc;18576 return result_loc;
1757318577
17574 if ((force_runtime || (value != nullptr && !instr_is_comptime(value))) &&18578 if ((force_runtime || (value != nullptr && !instr_is_comptime(value))) &&
...@@ -17591,11 +18595,11 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s...@@ -17591,11 +18595,11 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
17591 field->type_entry = value_type;18595 field->type_entry = value_type;
17592 field->type_val = create_const_type(ira->codegen, field->type_entry);18596 field->type_val = create_const_type(ira->codegen, field->type_entry);
17593 field->src_index = old_field_count;18597 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;
17595 if (value && instr_is_comptime(value)) {18599 if (value && instr_is_comptime(value)) {
17596 ZigValue *val = ir_resolve_const(ira, value, UndefOk);18600 ZigValue *val = ir_resolve_const(ira, value, UndefOk);
17597 if (!val)18601 if (!val)
17598 return ira->codegen->invalid_instruction;18602 return ira->codegen->invalid_inst_gen;
17599 field->is_comptime = true;18603 field->is_comptime = true;
17600 field->init_val = create_const_vals(1);18604 field->init_val = create_const_vals(1);
17601 copy_const_val(field->init_val, val);18605 copy_const_val(field->init_val, val);
...@@ -17603,7 +18607,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s...@@ -17603,7 +18607,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
17603 }18607 }
1760418608
17605 ZigType *struct_ptr_type = get_pointer_to_type(ira->codegen, isf->inferred_struct_type, false);18609 ZigType *struct_ptr_type = get_pointer_to_type(ira->codegen, isf->inferred_struct_type, false);
17606 IrInstruction *casted_ptr;18610 IrInstGen *casted_ptr;
17607 if (instr_is_comptime(result_loc)) {18611 if (instr_is_comptime(result_loc)) {
17608 casted_ptr = ir_const(ira, suspend_source_instr, struct_ptr_type);18612 casted_ptr = ir_const(ira, suspend_source_instr, struct_ptr_type);
17609 copy_const_val(casted_ptr->value, result_loc->value);18613 copy_const_val(casted_ptr->value, result_loc->value);
...@@ -17614,7 +18618,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s...@@ -17614,7 +18618,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
17614 if (instr_is_comptime(casted_ptr)) {18618 if (instr_is_comptime(casted_ptr)) {
17615 ZigValue *ptr_val = ir_resolve_const(ira, casted_ptr, UndefBad);18619 ZigValue *ptr_val = ir_resolve_const(ira, casted_ptr, UndefBad);
17616 if (!ptr_val)18620 if (!ptr_val)
17617 return ira->codegen->invalid_instruction;18621 return ira->codegen->invalid_inst_gen;
17618 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {18622 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
17619 ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val,18623 ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val,
17620 suspend_source_instr->source_node);18624 suspend_source_instr->source_node);
...@@ -17644,7 +18648,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s...@@ -17644,7 +18648,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
17644 {18648 {
17645 bool has_bits;18649 bool has_bits;
17646 if ((err = type_has_bits2(ira->codegen, value_type, &has_bits)))18650 if ((err = type_has_bits2(ira->codegen, value_type, &has_bits)))
17647 return ira->codegen->invalid_instruction;18651 return ira->codegen->invalid_inst_gen;
17648 if (has_bits) {18652 if (has_bits) {
17649 result_loc_pass1->written = false;18653 result_loc_pass1->written = false;
17650 return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, result_loc, false, true);18654 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...@@ -17652,12 +18656,12 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
17652 } else if (actual_elem_type->id == ZigTypeIdErrorUnion && value_type->id != ZigTypeIdErrorUnion) {18656 } else if (actual_elem_type->id == ZigTypeIdErrorUnion && value_type->id != ZigTypeIdErrorUnion) {
17653 bool has_bits;18657 bool has_bits;
17654 if ((err = type_has_bits2(ira->codegen, value_type, &has_bits)))18658 if ((err = type_has_bits2(ira->codegen, value_type, &has_bits)))
17655 return ira->codegen->invalid_instruction;18659 return ira->codegen->invalid_inst_gen;
17656 if (has_bits) {18660 if (has_bits) {
17657 if (value_type->id == ZigTypeIdErrorSet) {18661 if (value_type->id == ZigTypeIdErrorSet) {
17658 return ir_analyze_unwrap_err_code(ira, suspend_source_instr, result_loc, true);18662 return ir_analyze_unwrap_err_code(ira, suspend_source_instr, result_loc, true);
17659 } else {18663 } 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,
17661 result_loc, false, true);18665 result_loc, false, true);
17662 ZigType *actual_payload_type = actual_elem_type->data.error_union.payload_type;18666 ZigType *actual_payload_type = actual_elem_type->data.error_union.payload_type;
17663 if (actual_payload_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional &&18667 if (actual_payload_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional &&
...@@ -17672,37 +18676,35 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s...@@ -17672,37 +18676,35 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
17672 return result_loc;18676 return result_loc;
17673}18677}
1767418678
17675static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira,18679static IrInstGen *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrInstSrcResolveResult *instruction) {
17676 IrInstructionResolveResult *instruction)
17677{
17678 ZigType *implicit_elem_type;18680 ZigType *implicit_elem_type;
17679 if (instruction->ty == nullptr) {18681 if (instruction->ty == nullptr) {
17680 if (instruction->result_loc->id == ResultLocIdCast) {18682 if (instruction->result_loc->id == ResultLocIdCast) {
17681 implicit_elem_type = ir_resolve_type(ira,18683 implicit_elem_type = ir_resolve_type(ira,
17682 instruction->result_loc->source_instruction->child);18684 instruction->result_loc->source_instruction->child);
17683 if (type_is_invalid(implicit_elem_type))18685 if (type_is_invalid(implicit_elem_type))
17684 return ira->codegen->invalid_instruction;18686 return ira->codegen->invalid_inst_gen;
17685 } else if (instruction->result_loc->id == ResultLocIdReturn) {18687 } else if (instruction->result_loc->id == ResultLocIdReturn) {
17686 implicit_elem_type = ira->explicit_return_type;18688 implicit_elem_type = ira->explicit_return_type;
17687 if (type_is_invalid(implicit_elem_type))18689 if (type_is_invalid(implicit_elem_type))
17688 return ira->codegen->invalid_instruction;18690 return ira->codegen->invalid_inst_gen;
17689 } else {18691 } else {
17690 implicit_elem_type = ira->codegen->builtin_types.entry_var;18692 implicit_elem_type = ira->codegen->builtin_types.entry_var;
17691 }18693 }
17692 if (implicit_elem_type == ira->codegen->builtin_types.entry_var) {18694 if (implicit_elem_type == ira->codegen->builtin_types.entry_var) {
17693 Buf *bare_name = buf_alloc();18695 Buf *bare_name = buf_alloc();
17694 Buf *name = get_anon_type_name(ira->codegen, nullptr, container_string(ContainerKindStruct),18696 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
17697 StructSpecial struct_special = StructSpecialInferredStruct;18699 StructSpecial struct_special = StructSpecialInferredStruct;
17698 if (instruction->base.source_node->type == NodeTypeContainerInitExpr &&18700 if (instruction->base.base.source_node->type == NodeTypeContainerInitExpr &&
17699 instruction->base.source_node->data.container_init_expr.kind == ContainerInitKindArray)18701 instruction->base.base.source_node->data.container_init_expr.kind == ContainerInitKindArray)
17700 {18702 {
17701 struct_special = StructSpecialInferredTuple;18703 struct_special = StructSpecialInferredTuple;
17702 }18704 }
1770318705
17704 ZigType *inferred_struct_type = get_partial_container_type(ira->codegen,18706 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,
17706 buf_ptr(name), bare_name, ContainerLayoutAuto);18708 buf_ptr(name), bare_name, ContainerLayoutAuto);
17707 inferred_struct_type->data.structure.special = struct_special;18709 inferred_struct_type->data.structure.special = struct_special;
17708 inferred_struct_type->data.structure.resolve_status = ResolveStatusBeingInferred;18710 inferred_struct_type->data.structure.resolve_status = ResolveStatusBeingInferred;
...@@ -17711,21 +18713,21 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira,...@@ -17711,21 +18713,21 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira,
17711 } else {18713 } else {
17712 implicit_elem_type = ir_resolve_type(ira, instruction->ty->child);18714 implicit_elem_type = ir_resolve_type(ira, instruction->ty->child);
17713 if (type_is_invalid(implicit_elem_type))18715 if (type_is_invalid(implicit_elem_type))
17714 return ira->codegen->invalid_instruction;18716 return ira->codegen->invalid_inst_gen;
17715 }18717 }
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,
17717 implicit_elem_type, nullptr, false, true, true);18719 implicit_elem_type, nullptr, false, true, true);
17718 if (result_loc != nullptr)18720 if (result_loc != nullptr)
17719 return result_loc;18721 return result_loc;
1772018722
17721 ZigFn *fn = exec_fn_entry(ira->new_irb.exec);18723 ZigFn *fn = ira->new_irb.exec->fn_entry;
17722 if (fn != nullptr && fn->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync &&18724 if (fn != nullptr && fn->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync &&
17723 instruction->result_loc->id == ResultLocIdReturn)18725 instruction->result_loc->id == ResultLocIdReturn)
17724 {18726 {
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(),
17726 implicit_elem_type, nullptr, false, true, true);18728 implicit_elem_type, nullptr, false, true, true);
17727 if (result_loc != nullptr &&18729 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))
17729 {18731 {
17730 return result_loc;18732 return result_loc;
17731 }18733 }
...@@ -17733,9 +18735,9 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira,...@@ -17733,9 +18735,9 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira,
17733 return result_loc;18735 return result_loc;
17734 }18736 }
1773518737
17736 IrInstruction *result = ir_const(ira, &instruction->base, implicit_elem_type);18738 IrInstGen *result = ir_const(ira, &instruction->base.base, implicit_elem_type);
17737 result->value->special = ConstValSpecialUndef;18739 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);
17739 ptr->value->data.x_ptr.mut = ConstPtrMutComptimeVar;18741 ptr->value->data.x_ptr.mut = ConstPtrMutComptimeVar;
17740 return ptr;18742 return ptr;
17741}18743}
...@@ -17759,8 +18761,7 @@ static void ir_reset_result(ResultLoc *result_loc) {...@@ -17759,8 +18761,7 @@ static void ir_reset_result(ResultLoc *result_loc) {
17759 break;18761 break;
17760 }18762 }
17761 case ResultLocIdVar: {18763 case ResultLocIdVar: {
17762 IrInstructionAllocaSrc *alloca_src =18764 IrInstSrcAlloca *alloca_src = reinterpret_cast<IrInstSrcAlloca *>(result_loc->source_instruction);
17763 reinterpret_cast<IrInstructionAllocaSrc *>(result_loc->source_instruction);
17764 alloca_src->base.child = nullptr;18765 alloca_src->base.child = nullptr;
17765 break;18766 break;
17766 }18767 }
...@@ -17776,18 +18777,18 @@ static void ir_reset_result(ResultLoc *result_loc) {...@@ -17776,18 +18777,18 @@ static void ir_reset_result(ResultLoc *result_loc) {
17776 }18777 }
17777}18778}
1777818779
17779static IrInstruction *ir_analyze_instruction_reset_result(IrAnalyze *ira, IrInstructionResetResult *instruction) {18780static IrInstGen *ir_analyze_instruction_reset_result(IrAnalyze *ira, IrInstSrcResetResult *instruction) {
17780 ir_reset_result(instruction->result_loc);18781 ir_reset_result(instruction->result_loc);
17781 return ir_const_void(ira, &instruction->base);18782 return ir_const_void(ira, &instruction->base.base);
17782}18783}
1778318784
17784static IrInstruction *get_async_call_result_loc(IrAnalyze *ira, IrInstruction *source_instr,18785static IrInstGen *get_async_call_result_loc(IrAnalyze *ira, IrInst* source_instr,
17785 ZigType *fn_ret_type, bool is_async_call_builtin, IrInstruction **args_ptr, size_t args_len,18786 ZigType *fn_ret_type, bool is_async_call_builtin, IrInstGen **args_ptr, size_t args_len,
17786 IrInstruction *ret_ptr_uncasted)18787 IrInstGen *ret_ptr_uncasted)
17787{18788{
17788 ir_assert(is_async_call_builtin, source_instr);18789 ir_assert(is_async_call_builtin, source_instr);
17789 if (type_is_invalid(ret_ptr_uncasted->value->type))18790 if (type_is_invalid(ret_ptr_uncasted->value->type))
17790 return ira->codegen->invalid_instruction;18791 return ira->codegen->invalid_inst_gen;
17791 if (ret_ptr_uncasted->value->type->id == ZigTypeIdVoid) {18792 if (ret_ptr_uncasted->value->type->id == ZigTypeIdVoid) {
17792 // Result location will be inside the async frame.18793 // Result location will be inside the async frame.
17793 return nullptr;18794 return nullptr;
...@@ -17795,57 +18796,57 @@ static IrInstruction *get_async_call_result_loc(IrAnalyze *ira, IrInstruction *s...@@ -17795,57 +18796,57 @@ static IrInstruction *get_async_call_result_loc(IrAnalyze *ira, IrInstruction *s
17795 return ir_implicit_cast(ira, ret_ptr_uncasted, get_pointer_to_type(ira->codegen, fn_ret_type, false));18796 return ir_implicit_cast(ira, ret_ptr_uncasted, get_pointer_to_type(ira->codegen, fn_ret_type, false));
17796}18797}
1779718798
17798static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstruction *source_instr, ZigFn *fn_entry,18799static IrInstGen *ir_analyze_async_call(IrAnalyze *ira, IrInst* source_instr, ZigFn *fn_entry,
17799 ZigType *fn_type, IrInstruction *fn_ref, IrInstruction **casted_args, size_t arg_count,18800 ZigType *fn_type, IrInstGen *fn_ref, IrInstGen **casted_args, size_t arg_count,
17800 IrInstruction *casted_new_stack, bool is_async_call_builtin, IrInstruction *ret_ptr_uncasted,18801 IrInstGen *casted_new_stack, bool is_async_call_builtin, IrInstGen *ret_ptr_uncasted,
17801 ResultLoc *call_result_loc)18802 ResultLoc *call_result_loc)
17802{18803{
17803 if (fn_entry == nullptr) {18804 if (fn_entry == nullptr) {
17804 if (fn_type->data.fn.fn_type_id.cc != CallingConventionAsync) {18805 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,
17806 buf_sprintf("expected async function, found '%s'", buf_ptr(&fn_type->name)));18807 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;
17808 }18809 }
17809 if (casted_new_stack == nullptr) {18810 if (casted_new_stack == nullptr) {
17810 ir_add_error(ira, fn_ref, buf_sprintf("function is not comptime-known; @asyncCall required"));18811 ir_add_error(ira, &fn_ref->base, buf_sprintf("function is not comptime-known; @asyncCall required"));
17811 return ira->codegen->invalid_instruction;18812 return ira->codegen->invalid_inst_gen;
17812 }18813 }
17813 }18814 }
17814 if (casted_new_stack != nullptr) {18815 if (casted_new_stack != nullptr) {
17815 ZigType *fn_ret_type = fn_type->data.fn.fn_type_id.return_type;18816 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,
17817 casted_args, arg_count, ret_ptr_uncasted);18818 casted_args, arg_count, ret_ptr_uncasted);
17818 if (ret_ptr != nullptr && type_is_invalid(ret_ptr->value->type))18819 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
17821 ZigType *anyframe_type = get_any_frame_type(ira->codegen, fn_ret_type);18822 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,
17824 arg_count, casted_args, CallModifierAsync, casted_new_stack,18825 arg_count, casted_args, CallModifierAsync, casted_new_stack,
17825 is_async_call_builtin, ret_ptr, anyframe_type);18826 is_async_call_builtin, ret_ptr, anyframe_type);
17826 return &call_gen->base;18827 return &call_gen->base;
17827 } else {18828 } else {
17828 ZigType *frame_type = get_fn_frame_type(ira->codegen, fn_entry);18829 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,
17830 frame_type, nullptr, true, true, false);18831 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) {
17832 return result_loc;18833 return result_loc;
17833 }18834 }
17834 result_loc = ir_implicit_cast(ira, result_loc, get_pointer_to_type(ira->codegen, frame_type, false));18835 result_loc = ir_implicit_cast(ira, result_loc, get_pointer_to_type(ira->codegen, frame_type, false));
17835 if (type_is_invalid(result_loc->value->type))18836 if (type_is_invalid(result_loc->value->type))
17836 return ira->codegen->invalid_instruction;18837 return ira->codegen->invalid_inst_gen;
17837 return &ir_build_call_gen(ira, source_instr, fn_entry, fn_ref, arg_count,18838 return &ir_build_call_gen(ira, source_instr, fn_entry, fn_ref, arg_count,
17838 casted_args, CallModifierAsync, casted_new_stack,18839 casted_args, CallModifierAsync, casted_new_stack,
17839 is_async_call_builtin, result_loc, frame_type)->base;18840 is_async_call_builtin, result_loc, frame_type)->base;
17840 }18841 }
17841}18842}
17842static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node,18843static 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)
17844{18845{
17845 AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(*next_proto_i);18846 AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(*next_proto_i);
17846 assert(param_decl_node->type == NodeTypeParamDecl);18847 assert(param_decl_node->type == NodeTypeParamDecl);
1784718848
17848 IrInstruction *casted_arg;18849 IrInstGen *casted_arg;
17849 if (param_decl_node->data.param_decl.var_token == nullptr) {18850 if (param_decl_node->data.param_decl.var_token == nullptr) {
17850 AstNode *param_type_node = param_decl_node->data.param_decl.type;18851 AstNode *param_type_node = param_decl_node->data.param_decl.type;
17851 ZigType *param_type = ir_analyze_type_expr(ira, *exec_scope, param_type_node);18852 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...@@ -17873,15 +18874,15 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node
17873}18874}
1787418875
17875static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_node,18876static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_node,
17876 IrInstruction *arg, Scope **child_scope, size_t *next_proto_i,18877 IrInstGen *arg, Scope **child_scope, size_t *next_proto_i,
17877 GenericFnTypeId *generic_id, FnTypeId *fn_type_id, IrInstruction **casted_args,18878 GenericFnTypeId *generic_id, FnTypeId *fn_type_id, IrInstGen **casted_args,
17878 ZigFn *impl_fn)18879 ZigFn *impl_fn)
17879{18880{
17880 AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(*next_proto_i);18881 AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(*next_proto_i);
17881 assert(param_decl_node->type == NodeTypeParamDecl);18882 assert(param_decl_node->type == NodeTypeParamDecl);
17882 bool is_var_args = param_decl_node->data.param_decl.is_var_args;18883 bool is_var_args = param_decl_node->data.param_decl.is_var_args;
17883 bool arg_part_of_generic_id = false;18884 bool arg_part_of_generic_id = false;
17884 IrInstruction *casted_arg;18885 IrInstGen *casted_arg;
17885 if (is_var_args) {18886 if (is_var_args) {
17886 arg_part_of_generic_id = true;18887 arg_part_of_generic_id = true;
17887 casted_arg = arg;18888 casted_arg = arg;
...@@ -17941,7 +18942,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod...@@ -17941,7 +18942,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
17941 } else if (casted_arg->value->type->id == ZigTypeIdComptimeInt ||18942 } else if (casted_arg->value->type->id == ZigTypeIdComptimeInt ||
17942 casted_arg->value->type->id == ZigTypeIdComptimeFloat)18943 casted_arg->value->type->id == ZigTypeIdComptimeFloat)
17943 {18944 {
17944 ir_add_error(ira, casted_arg,18945 ir_add_error(ira, &casted_arg->base,
17945 buf_sprintf("compiler bug: integer and float literals in var args function must be casted. https://github.com/ziglang/zig/issues/557"));18946 buf_sprintf("compiler bug: integer and float literals in var args function must be casted. https://github.com/ziglang/zig/issues/557"));
17946 return false;18947 return false;
17947 }18948 }
...@@ -17958,17 +18959,17 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod...@@ -17958,17 +18959,17 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
17958 return true;18959 return true;
17959}18960}
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) {
17962 while (var->next_var != nullptr) {18963 while (var->next_var != nullptr) {
17963 var = var->next_var;18964 var = var->next_var;
17964 }18965 }
1796518966
17966 if (var->mem_slot_index != SIZE_MAX && var->owner_exec->analysis == nullptr) {18967 if (var->mem_slot_index != SIZE_MAX && var->owner_exec->analysis == nullptr) {
17967 assert(ira->codegen->errors.length != 0);18968 assert(ira->codegen->errors.length != 0);
17968 return ira->codegen->invalid_instruction;18969 return ira->codegen->invalid_inst_gen;
17969 }18970 }
17970 if (var->var_type == nullptr || type_is_invalid(var->var_type))18971 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
17973 ZigValue *mem_slot = nullptr;18974 ZigValue *mem_slot = nullptr;
1797418975
...@@ -17976,8 +18977,7 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,...@@ -17976,8 +18977,7 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
17976 bool linkage_makes_it_runtime = var->decl_node->data.variable_declaration.is_extern;18977 bool linkage_makes_it_runtime = var->decl_node->data.variable_declaration.is_extern;
17977 bool is_volatile = false;18978 bool is_volatile = false;
1797818979
17979 IrInstruction *result = ir_build_var_ptr(&ira->new_irb,18980 IrInstGen *result = ir_build_var_ptr_gen(ira, source_instr, var);
17980 instruction->scope, instruction->source_node, var);
17981 result->value->type = get_pointer_to_type_extra(ira->codegen, var->var_type,18981 result->value->type = get_pointer_to_type_extra(ira->codegen, var->var_type,
17982 var->src_is_const, is_volatile, PtrLenSingle, var->align_bytes, 0, 0, false);18982 var->src_is_const, is_volatile, PtrLenSingle, var->align_bytes, 0, 0, false);
1798318983
...@@ -18030,7 +19030,7 @@ no_mem_slot:...@@ -18030,7 +19030,7 @@ no_mem_slot:
18030}19030}
1803119031
18032// This function is called when a comptime value becomes accessible at runtime.19032// 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) {
18034 ir_assert(value_is_comptime(val), source_instr);19034 ir_assert(value_is_comptime(val), source_instr);
18035 if (val->special == ConstValSpecialUndef)19035 if (val->special == ConstValSpecialUndef)
18036 return;19036 return;
...@@ -18043,8 +19043,8 @@ static void mark_comptime_value_escape(IrAnalyze *ira, IrInstruction *source_ins...@@ -18043,8 +19043,8 @@ static void mark_comptime_value_escape(IrAnalyze *ira, IrInstruction *source_ins
18043 }19043 }
18044}19044}
1804519045
18046static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source_instr,19046static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr,
18047 IrInstruction *ptr, IrInstruction *uncasted_value, bool allow_write_through_const)19047 IrInstGen *ptr, IrInstGen *uncasted_value, bool allow_write_through_const)
18048{19048{
18049 assert(ptr->value->type->id == ZigTypeIdPointer);19049 assert(ptr->value->type->id == ZigTypeIdPointer);
1805019050
...@@ -18053,24 +19053,24 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source...@@ -18053,24 +19053,24 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
18053 uncasted_value->value->type->id == ZigTypeIdErrorSet)19053 uncasted_value->value->type->id == ZigTypeIdErrorSet)
18054 {19054 {
18055 ir_add_error(ira, source_instr, buf_sprintf("error is discarded"));19055 ir_add_error(ira, source_instr, buf_sprintf("error is discarded"));
18056 return ira->codegen->invalid_instruction;19056 return ira->codegen->invalid_inst_gen;
18057 }19057 }
18058 return ir_const_void(ira, source_instr);19058 return ir_const_void(ira, source_instr);
18059 }19059 }
1806019060
18061 if (ptr->value->type->data.pointer.is_const && !allow_write_through_const) {19061 if (ptr->value->type->data.pointer.is_const && !allow_write_through_const) {
18062 ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant"));19062 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;
18064 }19064 }
1806519065
18066 ZigType *child_type = ptr->value->type->data.pointer.child_type;19066 ZigType *child_type = ptr->value->type->data.pointer.child_type;
18067 IrInstruction *value = ir_implicit_cast(ira, uncasted_value, child_type);19067 IrInstGen *value = ir_implicit_cast(ira, uncasted_value, child_type);
18068 if (value == ira->codegen->invalid_instruction)19068 if (type_is_invalid(value->value->type))
18069 return ira->codegen->invalid_instruction;19069 return ira->codegen->invalid_inst_gen;
1807019070
18071 switch (type_has_one_possible_value(ira->codegen, child_type)) {19071 switch (type_has_one_possible_value(ira->codegen, child_type)) {
18072 case OnePossibleValueInvalid:19072 case OnePossibleValueInvalid:
18073 return ira->codegen->invalid_instruction;19073 return ira->codegen->invalid_inst_gen;
18074 case OnePossibleValueYes:19074 case OnePossibleValueYes:
18075 return ir_const_void(ira, source_instr);19075 return ir_const_void(ira, source_instr);
18076 case OnePossibleValueNo:19076 case OnePossibleValueNo:
...@@ -18080,7 +19080,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source...@@ -18080,7 +19080,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
18080 if (instr_is_comptime(ptr) && ptr->value->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {19080 if (instr_is_comptime(ptr) && ptr->value->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
18081 if (!allow_write_through_const && ptr->value->data.x_ptr.mut == ConstPtrMutComptimeConst) {19081 if (!allow_write_through_const && ptr->value->data.x_ptr.mut == ConstPtrMutComptimeConst) {
18082 ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant"));19082 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;
18084 }19084 }
18085 if ((allow_write_through_const && ptr->value->data.x_ptr.mut == ConstPtrMutComptimeConst) ||19085 if ((allow_write_through_const && ptr->value->data.x_ptr.mut == ConstPtrMutComptimeConst) ||
18086 ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar ||19086 ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar ||
...@@ -18089,7 +19089,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source...@@ -18089,7 +19089,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
18089 if (instr_is_comptime(value)) {19089 if (instr_is_comptime(value)) {
18090 ZigValue *dest_val = const_ptr_pointee(ira, ira->codegen, ptr->value, source_instr->source_node);19090 ZigValue *dest_val = const_ptr_pointee(ira, ira->codegen, ptr->value, source_instr->source_node);
18091 if (dest_val == nullptr)19091 if (dest_val == nullptr)
18092 return ira->codegen->invalid_instruction;19092 return ira->codegen->invalid_inst_gen;
18093 if (dest_val->special != ConstValSpecialRuntime) {19093 if (dest_val->special != ConstValSpecialRuntime) {
18094 copy_const_val(dest_val, value->value);19094 copy_const_val(dest_val, value->value);
1809519095
...@@ -18109,7 +19109,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source...@@ -18109,7 +19109,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
18109 ZigValue *dest_val = const_ptr_pointee_unchecked(ira->codegen, ptr->value);19109 ZigValue *dest_val = const_ptr_pointee_unchecked(ira->codegen, ptr->value);
18110 dest_val->type = ira->codegen->builtin_types.entry_invalid;19110 dest_val->type = ira->codegen->builtin_types.entry_invalid;
1811119111
18112 return ira->codegen->invalid_instruction;19112 return ira->codegen->invalid_inst_gen;
18113 }19113 }
18114 }19114 }
18115 }19115 }
...@@ -18122,15 +19122,15 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source...@@ -18122,15 +19122,15 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
1812219122
18123 switch (type_requires_comptime(ira->codegen, child_type)) {19123 switch (type_requires_comptime(ira->codegen, child_type)) {
18124 case ReqCompTimeInvalid:19124 case ReqCompTimeInvalid:
18125 return ira->codegen->invalid_instruction;19125 return ira->codegen->invalid_inst_gen;
18126 case ReqCompTimeYes:19126 case ReqCompTimeYes:
18127 switch (type_has_one_possible_value(ira->codegen, ptr->value->type)) {19127 switch (type_has_one_possible_value(ira->codegen, ptr->value->type)) {
18128 case OnePossibleValueInvalid:19128 case OnePossibleValueInvalid:
18129 return ira->codegen->invalid_instruction;19129 return ira->codegen->invalid_inst_gen;
18130 case OnePossibleValueNo:19130 case OnePossibleValueNo:
18131 ir_add_error(ira, source_instr,19131 ir_add_error(ira, source_instr,
18132 buf_sprintf("cannot store runtime value in type '%s'", buf_ptr(&child_type->name)));19132 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;
18134 case OnePossibleValueYes:19134 case OnePossibleValueYes:
18135 return ir_const_void(ira, source_instr);19135 return ir_const_void(ira, source_instr);
18136 }19136 }
...@@ -18144,30 +19144,28 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source...@@ -18144,30 +19144,28 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
18144 }19144 }
1814519145
18146 // If this is a store to a pointer with a runtime-known vector index,19146 // 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 and19147 // we have to figure out the IrInstGen which represents the index and
18148 // emit a IrInstructionVectorStoreElem, or emit a compile error19148 // emit a IrInstGenVectorStoreElem, or emit a compile error
18149 // explaining why it is impossible for this store to work. Which is that19149 // explaining why it is impossible for this store to work. Which is that
18150 // the pointer address is of the vector; without the element index being known19150 // the pointer address is of the vector; without the element index being known
18151 // we cannot properly perform the insertion.19151 // we cannot properly perform the insertion.
18152 if (ptr->value->type->data.pointer.vector_index == VECTOR_INDEX_RUNTIME) {19152 if (ptr->value->type->data.pointer.vector_index == VECTOR_INDEX_RUNTIME) {
18153 if (ptr->id == IrInstructionIdElemPtr) {19153 if (ptr->id == IrInstGenIdElemPtr) {
18154 IrInstructionElemPtr *elem_ptr = (IrInstructionElemPtr *)ptr;19154 IrInstGenElemPtr *elem_ptr = (IrInstGenElemPtr *)ptr;
18155 return ir_build_vector_store_elem(ira, source_instr, elem_ptr->array_ptr,19155 return ir_build_vector_store_elem(ira, source_instr, elem_ptr->array_ptr,
18156 elem_ptr->elem_index, value);19156 elem_ptr->elem_index, value);
18157 }19157 }
18158 ir_add_error(ira, ptr,19158 ir_add_error(ira, &ptr->base,
18159 buf_sprintf("unable to determine vector element index of type '%s'",19159 buf_sprintf("unable to determine vector element index of type '%s'",
18160 buf_ptr(&ptr->value->type->name)));19160 buf_ptr(&ptr->value->type->name)));
18161 return ira->codegen->invalid_instruction;19161 return ira->codegen->invalid_inst_gen;
18162 }19162 }
1816319163
18164 IrInstructionStorePtr *store_ptr = ir_build_store_ptr(&ira->new_irb, source_instr->scope,19164 return ir_build_store_ptr_gen(ira, source_instr, ptr, value);
18165 source_instr->source_node, ptr, value);
18166 return &store_ptr->base;
18167}19165}
1816819166
18169static IrInstruction *analyze_casted_new_stack(IrAnalyze *ira, IrInstruction *source_instr,19167static IrInstGen *analyze_casted_new_stack(IrAnalyze *ira, IrInst* source_instr,
18170 IrInstruction *new_stack, bool is_async_call_builtin, ZigFn *fn_entry)19168 IrInstGen *new_stack, bool is_async_call_builtin, ZigFn *fn_entry)
18171{19169{
18172 if (new_stack == nullptr)19170 if (new_stack == nullptr)
18173 return nullptr;19171 return nullptr;
...@@ -18196,11 +19194,11 @@ static IrInstruction *analyze_casted_new_stack(IrAnalyze *ira, IrInstruction *so...@@ -18196,11 +19194,11 @@ static IrInstruction *analyze_casted_new_stack(IrAnalyze *ira, IrInstruction *so
18196 }19194 }
18197}19195}
1819819196
18199static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_instr,19197static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
18200 ZigFn *fn_entry, ZigType *fn_type, IrInstruction *fn_ref,19198 ZigFn *fn_entry, ZigType *fn_type, IrInstGen *fn_ref,
18201 IrInstruction *first_arg_ptr, CallModifier modifier,19199 IrInstGen *first_arg_ptr, CallModifier modifier,
18202 IrInstruction *new_stack, bool is_async_call_builtin,19200 IrInstGen *new_stack, bool is_async_call_builtin,
18203 IrInstruction **args_ptr, size_t args_len, IrInstruction *ret_ptr, ResultLoc *call_result_loc)19201 IrInstGen **args_ptr, size_t args_len, IrInstGen *ret_ptr, ResultLoc *call_result_loc)
18204{19202{
18205 Error err;19203 Error err;
18206 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;19204 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...@@ -18221,11 +19219,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18221 AstNode *fn_proto_node = fn_entry ? fn_entry->proto_node : nullptr;;19219 AstNode *fn_proto_node = fn_entry ? fn_entry->proto_node : nullptr;;
1822219220
18223 if (fn_type_id->cc == CallingConventionNaked) {19221 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"));
18225 if (fn_proto_node) {19223 if (fn_proto_node) {
18226 add_error_note(ira->codegen, msg, fn_proto_node, buf_sprintf("declared here"));19224 add_error_note(ira->codegen, msg, fn_proto_node, buf_sprintf("declared here"));
18227 }19225 }
18228 return ira->codegen->invalid_instruction;19226 return ira->codegen->invalid_inst_gen;
18229 }19227 }
1823019228
18231 if (fn_type_id->is_var_args) {19229 if (fn_type_id->is_var_args) {
...@@ -18236,7 +19234,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18236,7 +19234,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18236 add_error_note(ira->codegen, msg, fn_proto_node,19234 add_error_note(ira->codegen, msg, fn_proto_node,
18237 buf_sprintf("declared here"));19235 buf_sprintf("declared here"));
18238 }19236 }
18239 return ira->codegen->invalid_instruction;19237 return ira->codegen->invalid_inst_gen;
18240 }19238 }
18241 } else if (src_param_count != call_param_count) {19239 } else if (src_param_count != call_param_count) {
18242 ErrorMsg *msg = ir_add_error_node(ira, source_node,19240 ErrorMsg *msg = ir_add_error_node(ira, source_node,
...@@ -18245,18 +19243,18 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18245,18 +19243,18 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18245 add_error_note(ira->codegen, msg, fn_proto_node,19243 add_error_note(ira->codegen, msg, fn_proto_node,
18246 buf_sprintf("declared here"));19244 buf_sprintf("declared here"));
18247 }19245 }
18248 return ira->codegen->invalid_instruction;19246 return ira->codegen->invalid_inst_gen;
18249 }19247 }
1825019248
18251 if (modifier == CallModifierCompileTime) {19249 if (modifier == CallModifierCompileTime) {
18252 // No special handling is needed for compile time evaluation of generic functions.19250 // No special handling is needed for compile time evaluation of generic functions.
18253 if (!fn_entry || fn_entry->body_node == nullptr) {19251 if (!fn_entry || fn_entry->body_node == nullptr) {
18254 ir_add_error(ira, fn_ref, buf_sprintf("unable to evaluate constant expression"));19252 ir_add_error(ira, &fn_ref->base, buf_sprintf("unable to evaluate constant expression"));
18255 return ira->codegen->invalid_instruction;19253 return ira->codegen->invalid_inst_gen;
18256 }19254 }
1825719255
18258 if (!ir_emit_backward_branch(ira, source_instr))19256 if (!ir_emit_backward_branch(ira, source_instr))
18259 return ira->codegen->invalid_instruction;19257 return ira->codegen->invalid_inst_gen;
1826019258
18261 // Fork a scope of the function with known values for the parameters.19259 // Fork a scope of the function with known values for the parameters.
18262 Scope *exec_scope = &fn_entry->fndef_scope->base;19260 Scope *exec_scope = &fn_entry->fndef_scope->base;
...@@ -18269,47 +19267,47 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18269,47 +19267,47 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18269 if (fn_type_id->next_param_index >= 1) {19267 if (fn_type_id->next_param_index >= 1) {
18270 ZigType *param_type = fn_type_id->param_info[next_proto_i].type;19268 ZigType *param_type = fn_type_id->param_info[next_proto_i].type;
18271 if (type_is_invalid(param_type))19269 if (type_is_invalid(param_type))
18272 return ira->codegen->invalid_instruction;19270 return ira->codegen->invalid_inst_gen;
18273 first_arg_known_bare = param_type->id != ZigTypeIdPointer;19271 first_arg_known_bare = param_type->id != ZigTypeIdPointer;
18274 }19272 }
1827519273
18276 IrInstruction *first_arg;19274 IrInstGen *first_arg;
18277 if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type)) {19275 if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type)) {
18278 first_arg = first_arg_ptr;19276 first_arg = first_arg_ptr;
18279 } else {19277 } 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);
18281 if (type_is_invalid(first_arg->value->type))19279 if (type_is_invalid(first_arg->value->type))
18282 return ira->codegen->invalid_instruction;19280 return ira->codegen->invalid_inst_gen;
18283 }19281 }
1828419282
18285 if (!ir_analyze_fn_call_inline_arg(ira, fn_proto_node, first_arg, &exec_scope, &next_proto_i))19283 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;
18287 }19285 }
1828819286
18289 if (fn_proto_node->data.fn_proto.is_var_args) {19287 if (fn_proto_node->data.fn_proto.is_var_args) {
18290 ir_add_error(ira, source_instr,19288 ir_add_error(ira, source_instr,
18291 buf_sprintf("compiler bug: unable to call var args function at compile time. https://github.com/ziglang/zig/issues/313"));19289 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;
18293 }19291 }
1829419292
1829519293
18296 for (size_t call_i = 0; call_i < args_len; call_i += 1) {19294 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
18299 if (!ir_analyze_fn_call_inline_arg(ira, fn_proto_node, old_arg, &exec_scope, &next_proto_i))19297 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;
18301 }19299 }
1830219300
18303 AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;19301 AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;
18304 ZigType *specified_return_type = ir_analyze_type_expr(ira, exec_scope, return_type_node);19302 ZigType *specified_return_type = ir_analyze_type_expr(ira, exec_scope, return_type_node);
18305 if (type_is_invalid(specified_return_type))19303 if (type_is_invalid(specified_return_type))
18306 return ira->codegen->invalid_instruction;19304 return ira->codegen->invalid_inst_gen;
18307 ZigType *return_type;19305 ZigType *return_type;
18308 ZigType *inferred_err_set_type = nullptr;19306 ZigType *inferred_err_set_type = nullptr;
18309 if (fn_proto_node->data.fn_proto.auto_err_set) {19307 if (fn_proto_node->data.fn_proto.auto_err_set) {
18310 inferred_err_set_type = get_auto_err_set_type(ira->codegen, fn_entry);19308 inferred_err_set_type = get_auto_err_set_type(ira->codegen, fn_entry);
18311 if ((err = type_resolve(ira->codegen, specified_return_type, ResolveStatusSizeKnown)))19309 if ((err = type_resolve(ira->codegen, specified_return_type, ResolveStatusSizeKnown)))
18312 return ira->codegen->invalid_instruction;19310 return ira->codegen->invalid_inst_gen;
18313 return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type);19311 return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type);
18314 } else {19312 } else {
18315 return_type = specified_return_type;19313 return_type = specified_return_type;
...@@ -18354,24 +19352,24 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18354,24 +19352,24 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18354 }19352 }
1835519353
18356 if (type_is_invalid(result->type)) {19354 if (type_is_invalid(result->type)) {
18357 return ira->codegen->invalid_instruction;19355 return ira->codegen->invalid_inst_gen;
18358 }19356 }
18359 }19357 }
1836019358
18361 IrInstruction *new_instruction = ir_const_move(ira, source_instr, result);19359 IrInstGen *new_instruction = ir_const_move(ira, source_instr, result);
18362 return ir_finish_anal(ira, new_instruction);19360 return ir_finish_anal(ira, new_instruction);
18363 }19361 }
1836419362
18365 if (fn_type->data.fn.is_generic) {19363 if (fn_type->data.fn.is_generic) {
18366 if (!fn_entry) {19364 if (!fn_entry) {
18367 ir_add_error(ira, fn_ref,19365 ir_add_error(ira, &fn_ref->base,
18368 buf_sprintf("calling a generic function requires compile-time known function value"));19366 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;
18370 }19368 }
1837119369
18372 size_t new_fn_arg_count = first_arg_1_or_0 + args_len;19370 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
18376 // Fork a scope of the function with known values for the parameters.19374 // Fork a scope of the function with known values for the parameters.
18377 Scope *parent_scope = fn_entry->fndef_scope->base.parent;19375 Scope *parent_scope = fn_entry->fndef_scope->base.parent;
...@@ -18400,30 +19398,30 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18400,30 +19398,30 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18400 if (fn_type_id->next_param_index >= 1) {19398 if (fn_type_id->next_param_index >= 1) {
18401 ZigType *param_type = fn_type_id->param_info[next_proto_i].type;19399 ZigType *param_type = fn_type_id->param_info[next_proto_i].type;
18402 if (type_is_invalid(param_type))19400 if (type_is_invalid(param_type))
18403 return ira->codegen->invalid_instruction;19401 return ira->codegen->invalid_inst_gen;
18404 first_arg_known_bare = param_type->id != ZigTypeIdPointer;19402 first_arg_known_bare = param_type->id != ZigTypeIdPointer;
18405 }19403 }
1840619404
18407 IrInstruction *first_arg;19405 IrInstGen *first_arg;
18408 if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type)) {19406 if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type)) {
18409 first_arg = first_arg_ptr;19407 first_arg = first_arg_ptr;
18410 } else {19408 } 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);
18412 if (type_is_invalid(first_arg->value->type))19410 if (type_is_invalid(first_arg->value->type))
18413 return ira->codegen->invalid_instruction;19411 return ira->codegen->invalid_inst_gen;
18414 }19412 }
1841519413
18416 if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, first_arg, &impl_fn->child_scope,19414 if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, first_arg, &impl_fn->child_scope,
18417 &next_proto_i, generic_id, &inst_fn_type_id, casted_args, impl_fn))19415 &next_proto_i, generic_id, &inst_fn_type_id, casted_args, impl_fn))
18418 {19416 {
18419 return ira->codegen->invalid_instruction;19417 return ira->codegen->invalid_inst_gen;
18420 }19418 }
18421 }19419 }
1842219420
18423 ZigFn *parent_fn_entry = exec_fn_entry(ira->new_irb.exec);19421 ZigFn *parent_fn_entry = ira->new_irb.exec->fn_entry;
18424 assert(parent_fn_entry);19422 assert(parent_fn_entry);
18425 for (size_t call_i = 0; call_i < args_len; call_i += 1) {19423 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
18428 AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(next_proto_i);19426 AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(next_proto_i);
18429 assert(param_decl_node->type == NodeTypeParamDecl);19427 assert(param_decl_node->type == NodeTypeParamDecl);
...@@ -18431,7 +19429,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18431,7 +19429,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18431 if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, arg, &impl_fn->child_scope,19429 if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, arg, &impl_fn->child_scope,
18432 &next_proto_i, generic_id, &inst_fn_type_id, casted_args, impl_fn))19430 &next_proto_i, generic_id, &inst_fn_type_id, casted_args, impl_fn))
18433 {19431 {
18434 return ira->codegen->invalid_instruction;19432 return ira->codegen->invalid_inst_gen;
18435 }19433 }
18436 }19434 }
1843719435
...@@ -18441,7 +19439,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18441,7 +19439,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18441 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota,19439 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota,
18442 nullptr, nullptr, fn_proto_node->data.fn_proto.align_expr, nullptr, ira->new_irb.exec,19440 nullptr, nullptr, fn_proto_node->data.fn_proto.align_expr, nullptr, ira->new_irb.exec,
18443 nullptr, UndefBad);19441 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,
18445 impl_fn->child_scope, fn_proto_node->data.fn_proto.align_expr);19443 impl_fn->child_scope, fn_proto_node->data.fn_proto.align_expr);
18446 copy_const_val(const_instruction->base.value, align_result);19444 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...@@ -18455,11 +19453,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18455 AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;19453 AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;
18456 ZigType *specified_return_type = ir_analyze_type_expr(ira, impl_fn->child_scope, return_type_node);19454 ZigType *specified_return_type = ir_analyze_type_expr(ira, impl_fn->child_scope, return_type_node);
18457 if (type_is_invalid(specified_return_type))19455 if (type_is_invalid(specified_return_type))
18458 return ira->codegen->invalid_instruction;19456 return ira->codegen->invalid_inst_gen;
18459 if (fn_proto_node->data.fn_proto.auto_err_set) {19457 if (fn_proto_node->data.fn_proto.auto_err_set) {
18460 ZigType *inferred_err_set_type = get_auto_err_set_type(ira->codegen, impl_fn);19458 ZigType *inferred_err_set_type = get_auto_err_set_type(ira->codegen, impl_fn);
18461 if ((err = type_resolve(ira->codegen, specified_return_type, ResolveStatusSizeKnown)))19459 if ((err = type_resolve(ira->codegen, specified_return_type, ResolveStatusSizeKnown)))
18462 return ira->codegen->invalid_instruction;19460 return ira->codegen->invalid_inst_gen;
18463 inst_fn_type_id.return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type);19461 inst_fn_type_id.return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type);
18464 } else {19462 } else {
18465 inst_fn_type_id.return_type = specified_return_type;19463 inst_fn_type_id.return_type = specified_return_type;
...@@ -18472,7 +19470,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18472,7 +19470,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18472 CallModifierCompileTime, new_stack, is_async_call_builtin, args_ptr, args_len,19470 CallModifierCompileTime, new_stack, is_async_call_builtin, args_ptr, args_len,
18473 ret_ptr, call_result_loc);19471 ret_ptr, call_result_loc);
18474 case ReqCompTimeInvalid:19472 case ReqCompTimeInvalid:
18475 return ira->codegen->invalid_instruction;19473 return ira->codegen->invalid_inst_gen;
18476 case ReqCompTimeNo:19474 case ReqCompTimeNo:
18477 break;19475 break;
18478 }19476 }
...@@ -18486,7 +19484,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18486,7 +19484,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18486 // finish instantiating the function19484 // finish instantiating the function
18487 impl_fn->type_entry = get_fn_type(ira->codegen, &inst_fn_type_id);19485 impl_fn->type_entry = get_fn_type(ira->codegen, &inst_fn_type_id);
18488 if (type_is_invalid(impl_fn->type_entry))19486 if (type_is_invalid(impl_fn->type_entry))
18489 return ira->codegen->invalid_instruction;19487 return ira->codegen->invalid_inst_gen;
1849019488
18491 impl_fn->ir_executable->source_node = source_instr->source_node;19489 impl_fn->ir_executable->source_node = source_instr->source_node;
18492 impl_fn->ir_executable->parent_exec = ira->new_irb.exec;19490 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...@@ -18504,25 +19502,25 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18504 parent_fn_entry->calls_or_awaits_errorable_fn = true;19502 parent_fn_entry->calls_or_awaits_errorable_fn = true;
18505 }19503 }
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,
18508 is_async_call_builtin, impl_fn);19506 is_async_call_builtin, impl_fn);
18509 if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type))19507 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
18512 size_t impl_param_count = impl_fn_type_id->param_count;19510 size_t impl_param_count = impl_fn_type_id->param_count;
18513 if (modifier == CallModifierAsync) {19511 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,
18515 nullptr, casted_args, impl_param_count, casted_new_stack, is_async_call_builtin, ret_ptr,19513 nullptr, casted_args, impl_param_count, casted_new_stack, is_async_call_builtin, ret_ptr,
18516 call_result_loc);19514 call_result_loc);
18517 return ir_finish_anal(ira, result);19515 return ir_finish_anal(ira, result);
18518 }19516 }
1851919517
18520 IrInstruction *result_loc;19518 IrInstGen *result_loc;
18521 if (handle_is_ptr(impl_fn_type_id->return_type)) {19519 if (handle_is_ptr(impl_fn_type_id->return_type)) {
18522 result_loc = ir_resolve_result(ira, source_instr, call_result_loc,19520 result_loc = ir_resolve_result(ira, source_instr, call_result_loc,
18523 impl_fn_type_id->return_type, nullptr, true, true, false);19521 impl_fn_type_id->return_type, nullptr, true, true, false);
18524 if (result_loc != nullptr) {19522 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) {
18526 return result_loc;19524 return result_loc;
18527 }19525 }
18528 ZigType *res_child_type = result_loc->value->type->data.pointer.child_type;19526 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...@@ -18538,7 +19536,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18538 result_loc = get_async_call_result_loc(ira, source_instr, impl_fn_type_id->return_type,19536 result_loc = get_async_call_result_loc(ira, source_instr, impl_fn_type_id->return_type,
18539 is_async_call_builtin, args_ptr, args_len, ret_ptr);19537 is_async_call_builtin, args_ptr, args_len, ret_ptr);
18540 if (result_loc != nullptr && type_is_invalid(result_loc->value->type))19538 if (result_loc != nullptr && type_is_invalid(result_loc->value->type))
18541 return ira->codegen->invalid_instruction;19539 return ira->codegen->invalid_inst_gen;
18542 } else {19540 } else {
18543 result_loc = nullptr;19541 result_loc = nullptr;
18544 }19542 }
...@@ -18547,11 +19545,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18547,11 +19545,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18547 parent_fn_entry->inferred_async_node == nullptr &&19545 parent_fn_entry->inferred_async_node == nullptr &&
18548 modifier != CallModifierNoAsync)19546 modifier != CallModifierNoAsync)
18549 {19547 {
18550 parent_fn_entry->inferred_async_node = fn_ref->source_node;19548 parent_fn_entry->inferred_async_node = fn_ref->base.source_node;
18551 parent_fn_entry->inferred_async_fn = impl_fn;19549 parent_fn_entry->inferred_async_fn = impl_fn;
18552 }19550 }
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,
18555 impl_fn, nullptr, impl_param_count, casted_args, modifier, casted_new_stack,19553 impl_fn, nullptr, impl_param_count, casted_args, modifier, casted_new_stack,
18556 is_async_call_builtin, result_loc, impl_fn_type_id->return_type);19554 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...@@ -18562,7 +19560,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18562 return ir_finish_anal(ira, &new_call_instruction->base);19560 return ir_finish_anal(ira, &new_call_instruction->base);
18563 }19561 }
1856419562
18565 ZigFn *parent_fn_entry = exec_fn_entry(ira->new_irb.exec);19563 ZigFn *parent_fn_entry = ira->new_irb.exec->fn_entry;
18566 assert(fn_type_id->return_type != nullptr);19564 assert(fn_type_id->return_type != nullptr);
18567 assert(parent_fn_entry != nullptr);19565 assert(parent_fn_entry != nullptr);
18568 if (fn_type_can_fail(fn_type_id)) {19566 if (fn_type_can_fail(fn_type_id)) {
...@@ -18570,46 +19568,46 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18570,46 +19568,46 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18570 }19568 }
1857119569
1857219570
18573 IrInstruction **casted_args = allocate<IrInstruction *>(call_param_count);19571 IrInstGen **casted_args = allocate<IrInstGen *>(call_param_count);
18574 size_t next_arg_index = 0;19572 size_t next_arg_index = 0;
18575 if (first_arg_ptr) {19573 if (first_arg_ptr) {
18576 assert(first_arg_ptr->value->type->id == ZigTypeIdPointer);19574 assert(first_arg_ptr->value->type->id == ZigTypeIdPointer);
1857719575
18578 ZigType *param_type = fn_type_id->param_info[next_arg_index].type;19576 ZigType *param_type = fn_type_id->param_info[next_arg_index].type;
18579 if (type_is_invalid(param_type))19577 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;
18583 if (param_type->id == ZigTypeIdPointer &&19581 if (param_type->id == ZigTypeIdPointer &&
18584 handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type))19582 handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type))
18585 {19583 {
18586 first_arg = first_arg_ptr;19584 first_arg = first_arg_ptr;
18587 } else {19585 } 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);
18589 if (type_is_invalid(first_arg->value->type))19587 if (type_is_invalid(first_arg->value->type))
18590 return ira->codegen->invalid_instruction;19588 return ira->codegen->invalid_inst_gen;
18591 }19589 }
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);
18594 if (type_is_invalid(casted_arg->value->type))19592 if (type_is_invalid(casted_arg->value->type))
18595 return ira->codegen->invalid_instruction;19593 return ira->codegen->invalid_inst_gen;
1859619594
18597 casted_args[next_arg_index] = casted_arg;19595 casted_args[next_arg_index] = casted_arg;
18598 next_arg_index += 1;19596 next_arg_index += 1;
18599 }19597 }
18600 for (size_t call_i = 0; call_i < args_len; call_i += 1) {19598 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];
18602 if (type_is_invalid(old_arg->value->type))19600 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;
18606 if (next_arg_index < src_param_count) {19604 if (next_arg_index < src_param_count) {
18607 ZigType *param_type = fn_type_id->param_info[next_arg_index].type;19605 ZigType *param_type = fn_type_id->param_info[next_arg_index].type;
18608 if (type_is_invalid(param_type))19606 if (type_is_invalid(param_type))
18609 return ira->codegen->invalid_instruction;19607 return ira->codegen->invalid_inst_gen;
18610 casted_arg = ir_implicit_cast(ira, old_arg, param_type);19608 casted_arg = ir_implicit_cast(ira, old_arg, param_type);
18611 if (type_is_invalid(casted_arg->value->type))19609 if (type_is_invalid(casted_arg->value->type))
18612 return ira->codegen->invalid_instruction;19610 return ira->codegen->invalid_inst_gen;
18613 } else {19611 } else {
18614 casted_arg = old_arg;19612 casted_arg = old_arg;
18615 }19613 }
...@@ -18622,21 +19620,21 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18622,21 +19620,21 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1862219620
18623 ZigType *return_type = fn_type_id->return_type;19621 ZigType *return_type = fn_type_id->return_type;
18624 if (type_is_invalid(return_type))19622 if (type_is_invalid(return_type))
18625 return ira->codegen->invalid_instruction;19623 return ira->codegen->invalid_inst_gen;
1862619624
18627 if (fn_entry != nullptr && fn_entry->fn_inline == FnInlineAlways && modifier == CallModifierNeverInline) {19625 if (fn_entry != nullptr && fn_entry->fn_inline == FnInlineAlways && modifier == CallModifierNeverInline) {
18628 ir_add_error(ira, source_instr,19626 ir_add_error(ira, source_instr,
18629 buf_sprintf("no-inline call of inline function"));19627 buf_sprintf("no-inline call of inline function"));
18630 return ira->codegen->invalid_instruction;19628 return ira->codegen->invalid_inst_gen;
18631 }19629 }
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,
18634 is_async_call_builtin, fn_entry);19632 is_async_call_builtin, fn_entry);
18635 if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type))19633 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
18638 if (modifier == CallModifierAsync) {19636 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,
18640 casted_args, call_param_count, casted_new_stack, is_async_call_builtin, ret_ptr, call_result_loc);19638 casted_args, call_param_count, casted_new_stack, is_async_call_builtin, ret_ptr, call_result_loc);
18641 return ir_finish_anal(ira, result);19639 return ir_finish_anal(ira, result);
18642 }19640 }
...@@ -18645,16 +19643,16 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18645,16 +19643,16 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18645 parent_fn_entry->inferred_async_node == nullptr &&19643 parent_fn_entry->inferred_async_node == nullptr &&
18646 modifier != CallModifierNoAsync)19644 modifier != CallModifierNoAsync)
18647 {19645 {
18648 parent_fn_entry->inferred_async_node = fn_ref->source_node;19646 parent_fn_entry->inferred_async_node = fn_ref->base.source_node;
18649 parent_fn_entry->inferred_async_fn = fn_entry;19647 parent_fn_entry->inferred_async_fn = fn_entry;
18650 }19648 }
1865119649
18652 IrInstruction *result_loc;19650 IrInstGen *result_loc;
18653 if (handle_is_ptr(return_type)) {19651 if (handle_is_ptr(return_type)) {
18654 result_loc = ir_resolve_result(ira, source_instr, call_result_loc,19652 result_loc = ir_resolve_result(ira, source_instr, call_result_loc,
18655 return_type, nullptr, true, true, false);19653 return_type, nullptr, true, true, false);
18656 if (result_loc != nullptr) {19654 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) {
18658 return result_loc;19656 return result_loc;
18659 }19657 }
18660 ZigType *res_child_type = result_loc->value->type->data.pointer.child_type;19658 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...@@ -18670,12 +19668,12 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18670 result_loc = get_async_call_result_loc(ira, source_instr, return_type, is_async_call_builtin,19668 result_loc = get_async_call_result_loc(ira, source_instr, return_type, is_async_call_builtin,
18671 args_ptr, args_len, ret_ptr);19669 args_ptr, args_len, ret_ptr);
18672 if (result_loc != nullptr && type_is_invalid(result_loc->value->type))19670 if (result_loc != nullptr && type_is_invalid(result_loc->value->type))
18673 return ira->codegen->invalid_instruction;19671 return ira->codegen->invalid_inst_gen;
18674 } else {19672 } else {
18675 result_loc = nullptr;19673 result_loc = nullptr;
18676 }19674 }
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,
18679 call_param_count, casted_args, modifier, casted_new_stack,19677 call_param_count, casted_args, modifier, casted_new_stack,
18680 is_async_call_builtin, result_loc, return_type);19678 is_async_call_builtin, result_loc, return_type);
18681 if (get_scope_typeof(source_instr->scope) == nullptr) {19679 if (get_scope_typeof(source_instr->scope) == nullptr) {
...@@ -18684,62 +19682,62 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18684,62 +19682,62 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18684 return ir_finish_anal(ira, &new_call_instruction->base);19682 return ir_finish_anal(ira, &new_call_instruction->base);
18685}19683}
1868619684
18687static IrInstruction *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstructionCallSrc *call_instruction,19685static IrInstGen *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstSrcCall *call_instruction,
18688 ZigFn *fn_entry, ZigType *fn_type, IrInstruction *fn_ref,19686 ZigFn *fn_entry, ZigType *fn_type, IrInstGen *fn_ref,
18689 IrInstruction *first_arg_ptr, CallModifier modifier)19687 IrInstGen *first_arg_ptr, CallModifier modifier)
18690{19688{
18691 IrInstruction *new_stack = nullptr;19689 IrInstGen *new_stack = nullptr;
18692 if (call_instruction->new_stack) {19690 if (call_instruction->new_stack) {
18693 new_stack = call_instruction->new_stack->child;19691 new_stack = call_instruction->new_stack->child;
18694 if (type_is_invalid(new_stack->value->type))19692 if (type_is_invalid(new_stack->value->type))
18695 return ira->codegen->invalid_instruction;19693 return ira->codegen->invalid_inst_gen;
18696 }19694 }
18697 IrInstruction **args_ptr = allocate<IrInstruction *>(call_instruction->arg_count, "IrInstruction *");19695 IrInstGen **args_ptr = allocate<IrInstGen *>(call_instruction->arg_count, "IrInstGen *");
18698 for (size_t i = 0; i < call_instruction->arg_count; i += 1) {19696 for (size_t i = 0; i < call_instruction->arg_count; i += 1) {
18699 args_ptr[i] = call_instruction->args[i]->child;19697 args_ptr[i] = call_instruction->args[i]->child;
18700 if (type_is_invalid(args_ptr[i]->value->type))19698 if (type_is_invalid(args_ptr[i]->value->type))
18701 return ira->codegen->invalid_instruction;19699 return ira->codegen->invalid_inst_gen;
18702 }19700 }
18703 IrInstruction *ret_ptr = nullptr;19701 IrInstGen *ret_ptr = nullptr;
18704 if (call_instruction->ret_ptr != nullptr) {19702 if (call_instruction->ret_ptr != nullptr) {
18705 ret_ptr = call_instruction->ret_ptr->child;19703 ret_ptr = call_instruction->ret_ptr->child;
18706 if (type_is_invalid(ret_ptr->value->type))19704 if (type_is_invalid(ret_ptr->value->type))
18707 return ira->codegen->invalid_instruction;19705 return ira->codegen->invalid_inst_gen;
18708 }19706 }
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,
18710 first_arg_ptr, modifier, new_stack, call_instruction->is_async_call_builtin,19708 first_arg_ptr, modifier, new_stack, call_instruction->is_async_call_builtin,
18711 args_ptr, call_instruction->arg_count, ret_ptr, call_instruction->result_loc);19709 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 *");
18713 return result;19711 return result;
18714}19712}
1871519713
18716static IrInstruction *ir_analyze_call_extra(IrAnalyze *ira, IrInstruction *source_instr,19714static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr,
18717 IrInstruction *pass1_options, IrInstruction *pass1_fn_ref, IrInstruction **args_ptr, size_t args_len,19715 IrInstSrc *pass1_options, IrInstSrc *pass1_fn_ref, IrInstGen **args_ptr, size_t args_len,
18718 ResultLoc *result_loc)19716 ResultLoc *result_loc)
18719{19717{
18720 IrInstruction *options = pass1_options->child;19718 IrInstGen *options = pass1_options->child;
18721 if (type_is_invalid(options->value->type))19719 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;
18725 if (type_is_invalid(fn_ref->value->type))19723 if (type_is_invalid(fn_ref->value->type))
18726 return ira->codegen->invalid_instruction;19724 return ira->codegen->invalid_inst_gen;
1872719725
18728 TypeStructField *modifier_field = find_struct_type_field(options->value->type, buf_create_from_str("modifier"));19726 TypeStructField *modifier_field = find_struct_type_field(options->value->type, buf_create_from_str("modifier"));
18729 ir_assert(modifier_field != nullptr, source_instr);19727 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);
18731 ZigValue *modifier_val = ir_resolve_const(ira, modifier_inst, UndefBad);19729 ZigValue *modifier_val = ir_resolve_const(ira, modifier_inst, UndefBad);
18732 if (modifier_val == nullptr)19730 if (modifier_val == nullptr)
18733 return ira->codegen->invalid_instruction;19731 return ira->codegen->invalid_inst_gen;
18734 CallModifier modifier = (CallModifier)bigint_as_u32(&modifier_val->data.x_enum_tag);19732 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)) {
18737 switch (modifier) {19735 switch (modifier) {
18738 case CallModifierBuiltin:19736 case CallModifierBuiltin:
18739 zig_unreachable();19737 zig_unreachable();
18740 case CallModifierAsync:19738 case CallModifierAsync:
18741 ir_add_error(ira, source_instr, buf_sprintf("TODO: comptime @call with async modifier"));19739 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;
18743 case CallModifierCompileTime:19741 case CallModifierCompileTime:
18744 case CallModifierNone:19742 case CallModifierNone:
18745 case CallModifierAlwaysInline:19743 case CallModifierAlwaysInline:
...@@ -18750,15 +19748,15 @@ static IrInstruction *ir_analyze_call_extra(IrAnalyze *ira, IrInstruction *sourc...@@ -18750,15 +19748,15 @@ static IrInstruction *ir_analyze_call_extra(IrAnalyze *ira, IrInstruction *sourc
18750 case CallModifierNeverInline:19748 case CallModifierNeverInline:
18751 ir_add_error(ira, source_instr,19749 ir_add_error(ira, source_instr,
18752 buf_sprintf("unable to perform 'never_inline' call at compile-time"));19750 buf_sprintf("unable to perform 'never_inline' call at compile-time"));
18753 return ira->codegen->invalid_instruction;19751 return ira->codegen->invalid_inst_gen;
18754 case CallModifierNeverTail:19752 case CallModifierNeverTail:
18755 ir_add_error(ira, source_instr,19753 ir_add_error(ira, source_instr,
18756 buf_sprintf("unable to perform 'never_tail' call at compile-time"));19754 buf_sprintf("unable to perform 'never_tail' call at compile-time"));
18757 return ira->codegen->invalid_instruction;19755 return ira->codegen->invalid_inst_gen;
18758 }19756 }
18759 }19757 }
1876019758
18761 IrInstruction *first_arg_ptr = nullptr;19759 IrInstGen *first_arg_ptr = nullptr;
18762 ZigFn *fn = nullptr;19760 ZigFn *fn = nullptr;
18763 if (instr_is_comptime(fn_ref)) {19761 if (instr_is_comptime(fn_ref)) {
18764 if (fn_ref->value->type->id == ZigTypeIdBoundFn) {19762 if (fn_ref->value->type->id == ZigTypeIdBoundFn) {
...@@ -18766,7 +19764,7 @@ static IrInstruction *ir_analyze_call_extra(IrAnalyze *ira, IrInstruction *sourc...@@ -18766,7 +19764,7 @@ static IrInstruction *ir_analyze_call_extra(IrAnalyze *ira, IrInstruction *sourc
18766 fn = fn_ref->value->data.x_bound_fn.fn;19764 fn = fn_ref->value->data.x_bound_fn.fn;
18767 first_arg_ptr = fn_ref->value->data.x_bound_fn.first_arg;19765 first_arg_ptr = fn_ref->value->data.x_bound_fn.first_arg;
18768 if (type_is_invalid(first_arg_ptr->value->type))19766 if (type_is_invalid(first_arg_ptr->value->type))
18769 return ira->codegen->invalid_instruction;19767 return ira->codegen->invalid_inst_gen;
18770 } else {19768 } else {
18771 fn = ir_resolve_fn(ira, fn_ref);19769 fn = ir_resolve_fn(ira, fn_ref);
18772 }19770 }
...@@ -18778,9 +19776,9 @@ static IrInstruction *ir_analyze_call_extra(IrAnalyze *ira, IrInstruction *sourc...@@ -18778,9 +19776,9 @@ static IrInstruction *ir_analyze_call_extra(IrAnalyze *ira, IrInstruction *sourc
18778 case CallModifierAlwaysInline:19776 case CallModifierAlwaysInline:
18779 case CallModifierAsync:19777 case CallModifierAsync:
18780 if (fn == nullptr) {19778 if (fn == nullptr) {
18781 ir_add_error(ira, modifier_inst,19779 ir_add_error(ira, &modifier_inst->base,
18782 buf_sprintf("the specified modifier requires a comptime-known function"));19780 buf_sprintf("the specified modifier requires a comptime-known function"));
18783 return ira->codegen->invalid_instruction;19781 return ira->codegen->invalid_inst_gen;
18784 }19782 }
18785 default:19783 default:
18786 break;19784 break;
...@@ -18790,93 +19788,93 @@ static IrInstruction *ir_analyze_call_extra(IrAnalyze *ira, IrInstruction *sourc...@@ -18790,93 +19788,93 @@ static IrInstruction *ir_analyze_call_extra(IrAnalyze *ira, IrInstruction *sourc
1879019788
18791 TypeStructField *stack_field = find_struct_type_field(options->value->type, buf_create_from_str("stack"));19789 TypeStructField *stack_field = find_struct_type_field(options->value->type, buf_create_from_str("stack"));
18792 ir_assert(stack_field != nullptr, source_instr);19790 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);
18794 if (type_is_invalid(opt_stack->value->type))19792 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);
18798 bool stack_is_non_null;19796 bool stack_is_non_null;
18799 if (!ir_resolve_bool(ira, stack_is_non_null_inst, &stack_is_non_null))19797 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;
18803 if (stack_is_non_null) {19801 if (stack_is_non_null) {
18804 stack = ir_analyze_optional_value_payload_value(ira, source_instr, opt_stack, false);19802 stack = ir_analyze_optional_value_payload_value(ira, source_instr, opt_stack, false);
18805 if (type_is_invalid(stack->value->type))19803 if (type_is_invalid(stack->value->type))
18806 return ira->codegen->invalid_instruction;19804 return ira->codegen->invalid_inst_gen;
18807 }19805 }
1880819806
18809 return ir_analyze_fn_call(ira, source_instr, fn, fn_type, fn_ref, first_arg_ptr,19807 return ir_analyze_fn_call(ira, source_instr, fn, fn_type, fn_ref, first_arg_ptr,
18810 modifier, stack, false, args_ptr, args_len, nullptr, result_loc);19808 modifier, stack, false, args_ptr, args_len, nullptr, result_loc);
18811}19809}
1881219810
18813static IrInstruction *ir_analyze_instruction_call_extra(IrAnalyze *ira, IrInstructionCallExtra *instruction) {19811static IrInstGen *ir_analyze_instruction_call_extra(IrAnalyze *ira, IrInstSrcCallExtra *instruction) {
18814 IrInstruction *args = instruction->args->child;19812 IrInstGen *args = instruction->args->child;
18815 ZigType *args_type = args->value->type;19813 ZigType *args_type = args->value->type;
18816 if (type_is_invalid(args_type))19814 if (type_is_invalid(args_type))
18817 return ira->codegen->invalid_instruction;19815 return ira->codegen->invalid_inst_gen;
1881819816
18819 if (args_type->id != ZigTypeIdStruct) {19817 if (args_type->id != ZigTypeIdStruct) {
18820 ir_add_error(ira, args,19818 ir_add_error(ira, &args->base,
18821 buf_sprintf("expected tuple or struct, found '%s'", buf_ptr(&args_type->name)));19819 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;
18823 }19821 }
1882419822
18825 IrInstruction **args_ptr = nullptr;19823 IrInstGen **args_ptr = nullptr;
18826 size_t args_len = 0;19824 size_t args_len = 0;
1882719825
18828 if (is_tuple(args_type)) {19826 if (is_tuple(args_type)) {
18829 args_len = args_type->data.structure.src_field_count;19827 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 *");
18831 for (size_t i = 0; i < args_len; i += 1) {19829 for (size_t i = 0; i < args_len; i += 1) {
18832 TypeStructField *arg_field = args_type->data.structure.fields[i];19830 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);
18834 if (type_is_invalid(args_ptr[i]->value->type))19832 if (type_is_invalid(args_ptr[i]->value->type))
18835 return ira->codegen->invalid_instruction;19833 return ira->codegen->invalid_inst_gen;
18836 }19834 }
18837 } else {19835 } else {
18838 ir_add_error(ira, args, buf_sprintf("TODO: struct args"));19836 ir_add_error(ira, &args->base, buf_sprintf("TODO: struct args"));
18839 return ira->codegen->invalid_instruction;19837 return ira->codegen->invalid_inst_gen;
18840 }19838 }
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,
18842 instruction->fn_ref, args_ptr, args_len, instruction->result_loc);19840 instruction->fn_ref, args_ptr, args_len, instruction->result_loc);
18843 deallocate(args_ptr, args_len, "IrInstruction *");19841 deallocate(args_ptr, args_len, "IrInstGen *");
18844 return result;19842 return result;
18845}19843}
1884619844
18847static IrInstruction *ir_analyze_instruction_call_args(IrAnalyze *ira, IrInstructionCallSrcArgs *instruction) {19845static IrInstGen *ir_analyze_instruction_call_args(IrAnalyze *ira, IrInstSrcCallArgs *instruction) {
18848 IrInstruction **args_ptr = allocate<IrInstruction *>(instruction->args_len, "IrInstruction *");19846 IrInstGen **args_ptr = allocate<IrInstGen *>(instruction->args_len, "IrInstGen *");
18849 for (size_t i = 0; i < instruction->args_len; i += 1) {19847 for (size_t i = 0; i < instruction->args_len; i += 1) {
18850 args_ptr[i] = instruction->args_ptr[i]->child;19848 args_ptr[i] = instruction->args_ptr[i]->child;
18851 if (type_is_invalid(args_ptr[i]->value->type))19849 if (type_is_invalid(args_ptr[i]->value->type))
18852 return ira->codegen->invalid_instruction;19850 return ira->codegen->invalid_inst_gen;
18853 }19851 }
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,
18856 instruction->fn_ref, args_ptr, instruction->args_len, instruction->result_loc);19854 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 *");
18858 return result;19856 return result;
18859}19857}
1886019858
18861static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCallSrc *call_instruction) {19859static IrInstGen *ir_analyze_instruction_call(IrAnalyze *ira, IrInstSrcCall *call_instruction) {
18862 IrInstruction *fn_ref = call_instruction->fn_ref->child;19860 IrInstGen *fn_ref = call_instruction->fn_ref->child;
18863 if (type_is_invalid(fn_ref->value->type))19861 if (type_is_invalid(fn_ref->value->type))
18864 return ira->codegen->invalid_instruction;19862 return ira->codegen->invalid_inst_gen;
1886519863
18866 bool is_comptime = (call_instruction->modifier == CallModifierCompileTime) ||19864 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);
18868 CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier;19866 CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier;
1886919867
18870 if (is_comptime || instr_is_comptime(fn_ref)) {19868 if (is_comptime || instr_is_comptime(fn_ref)) {
18871 if (fn_ref->value->type->id == ZigTypeIdMetaType) {19869 if (fn_ref->value->type->id == ZigTypeIdMetaType) {
18872 ZigType *ty = ir_resolve_type(ira, fn_ref);19870 ZigType *ty = ir_resolve_type(ira, fn_ref);
18873 if (ty == nullptr)19871 if (ty == nullptr)
18874 return ira->codegen->invalid_instruction;19872 return ira->codegen->invalid_inst_gen;
18875 ErrorMsg *msg = ir_add_error_node(ira, fn_ref->source_node,19873 ErrorMsg *msg = ir_add_error(ira, &fn_ref->base,
18876 buf_sprintf("type '%s' not a function", buf_ptr(&ty->name)));19874 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,
18878 buf_sprintf("use @as builtin for type coercion"));19876 buf_sprintf("use @as builtin for type coercion"));
18879 return ira->codegen->invalid_instruction;19877 return ira->codegen->invalid_inst_gen;
18880 } else if (fn_ref->value->type->id == ZigTypeIdFn) {19878 } else if (fn_ref->value->type->id == ZigTypeIdFn) {
18881 ZigFn *fn_table_entry = ir_resolve_fn(ira, fn_ref);19879 ZigFn *fn_table_entry = ir_resolve_fn(ira, fn_ref);
18882 ZigType *fn_type = fn_table_entry ? fn_table_entry->type_entry : fn_ref->value->type;19880 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...@@ -18886,14 +19884,14 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC
18886 } else if (fn_ref->value->type->id == ZigTypeIdBoundFn) {19884 } else if (fn_ref->value->type->id == ZigTypeIdBoundFn) {
18887 assert(fn_ref->value->special == ConstValSpecialStatic);19885 assert(fn_ref->value->special == ConstValSpecialStatic);
18888 ZigFn *fn_table_entry = fn_ref->value->data.x_bound_fn.fn;19886 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;
18890 CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier;19888 CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier;
18891 return ir_analyze_fn_call_src(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry,19889 return ir_analyze_fn_call_src(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry,
18892 fn_ref, first_arg_ptr, modifier);19890 fn_ref, first_arg_ptr, modifier);
18893 } else {19891 } else {
18894 ir_add_error_node(ira, fn_ref->source_node,19892 ir_add_error(ira, &fn_ref->base,
18895 buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value->type->name)));19893 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;
18897 }19895 }
18898 }19896 }
1889919897
...@@ -18901,9 +19899,9 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC...@@ -18901,9 +19899,9 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC
18901 return ir_analyze_fn_call_src(ira, call_instruction, nullptr, fn_ref->value->type,19899 return ir_analyze_fn_call_src(ira, call_instruction, nullptr, fn_ref->value->type,
18902 fn_ref, nullptr, modifier);19900 fn_ref, nullptr, modifier);
18903 } else {19901 } else {
18904 ir_add_error_node(ira, fn_ref->source_node,19902 ir_add_error(ira, &fn_ref->base,
18905 buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value->type->name)));19903 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;
18907 }19905 }
18908}19906}
1890919907
...@@ -18992,8 +19990,8 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source...@@ -18992,8 +19990,8 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source
18992 zig_unreachable();19990 zig_unreachable();
18993}19991}
1899419992
18995static IrInstruction *ir_analyze_optional_type(IrAnalyze *ira, IrInstructionUnOp *instruction) {19993static IrInstGen *ir_analyze_optional_type(IrAnalyze *ira, IrInstSrcUnOp *instruction) {
18996 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type);19994 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);
18997 result->value->special = ConstValSpecialLazy;19995 result->value->special = ConstValSpecialLazy;
1899819996
18999 LazyValueOptType *lazy_opt_type = allocate<LazyValueOptType>(1, "LazyValueOptType");19997 LazyValueOptType *lazy_opt_type = allocate<LazyValueOptType>(1, "LazyValueOptType");
...@@ -19003,12 +20001,12 @@ static IrInstruction *ir_analyze_optional_type(IrAnalyze *ira, IrInstructionUnOp...@@ -19003,12 +20001,12 @@ static IrInstruction *ir_analyze_optional_type(IrAnalyze *ira, IrInstructionUnOp
1900320001
19004 lazy_opt_type->payload_type = instruction->value->child;20002 lazy_opt_type->payload_type = instruction->value->child;
19005 if (ir_resolve_type_lazy(ira, lazy_opt_type->payload_type) == nullptr)20003 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
19008 return result;20006 return result;
19009}20007}
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,
19012 ZigValue *operand_val, ZigValue *scalar_out_val, bool is_wrap_op)20010 ZigValue *operand_val, ZigValue *scalar_out_val, bool is_wrap_op)
19013{20011{
19014 bool is_float = (scalar_type->id == ZigTypeIdFloat || scalar_type->id == ZigTypeIdComptimeFloat);20012 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...@@ -19043,19 +20041,19 @@ static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInstruction *source_i
19043 return nullptr;20041 return nullptr;
19044}20042}
1904520043
19046static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *instruction) {20044static IrInstGen *ir_analyze_negation(IrAnalyze *ira, IrInstSrcUnOp *instruction) {
19047 IrInstruction *value = instruction->value->child;20045 IrInstGen *value = instruction->value->child;
19048 ZigType *expr_type = value->value->type;20046 ZigType *expr_type = value->value->type;
19049 if (type_is_invalid(expr_type))20047 if (type_is_invalid(expr_type))
19050 return ira->codegen->invalid_instruction;20048 return ira->codegen->invalid_inst_gen;
1905120049
19052 if (!(expr_type->id == ZigTypeIdInt || expr_type->id == ZigTypeIdComptimeInt ||20050 if (!(expr_type->id == ZigTypeIdInt || expr_type->id == ZigTypeIdComptimeInt ||
19053 expr_type->id == ZigTypeIdFloat || expr_type->id == ZigTypeIdComptimeFloat ||20051 expr_type->id == ZigTypeIdFloat || expr_type->id == ZigTypeIdComptimeFloat ||
19054 expr_type->id == ZigTypeIdVector))20052 expr_type->id == ZigTypeIdVector))
19055 {20053 {
19056 ir_add_error(ira, &instruction->base,20054 ir_add_error(ira, &instruction->base.base,
19057 buf_sprintf("negation of type '%s'", buf_ptr(&expr_type->name)));20055 buf_sprintf("negation of type '%s'", buf_ptr(&expr_type->name)));
19058 return ira->codegen->invalid_instruction;20056 return ira->codegen->invalid_inst_gen;
19059 }20057 }
1906020058
19061 bool is_wrap_op = (instruction->op_id == IrUnOpNegationWrap);20059 bool is_wrap_op = (instruction->op_id == IrUnOpNegationWrap);
...@@ -19065,9 +20063,9 @@ static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *ins...@@ -19065,9 +20063,9 @@ static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *ins
19065 if (instr_is_comptime(value)) {20063 if (instr_is_comptime(value)) {
19066 ZigValue *operand_val = ir_resolve_const(ira, value, UndefBad);20064 ZigValue *operand_val = ir_resolve_const(ira, value, UndefBad);
19067 if (!operand_val)20065 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);
19071 ZigValue *out_val = result_instruction->value;20069 ZigValue *out_val = result_instruction->value;
19072 if (expr_type->id == ZigTypeIdVector) {20070 if (expr_type->id == ZigTypeIdVector) {
19073 expand_undef_array(ira->codegen, operand_val);20071 expand_undef_array(ira->codegen, operand_val);
...@@ -19079,63 +20077,60 @@ static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *ins...@@ -19079,63 +20077,60 @@ static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *ins
19079 ZigValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i];20077 ZigValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i];
19080 assert(scalar_operand_val->type == scalar_type);20078 assert(scalar_operand_val->type == scalar_type);
19081 assert(scalar_out_val->type == scalar_type);20079 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,
19083 scalar_operand_val, scalar_out_val, is_wrap_op);20081 scalar_operand_val, scalar_out_val, is_wrap_op);
19084 if (msg != nullptr) {20082 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,
19086 buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i));20084 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;
19088 }20086 }
19089 }20087 }
19090 out_val->type = expr_type;20088 out_val->type = expr_type;
19091 out_val->special = ConstValSpecialStatic;20089 out_val->special = ConstValSpecialStatic;
19092 } else {20090 } 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,
19094 is_wrap_op) != nullptr)20092 is_wrap_op) != nullptr)
19095 {20093 {
19096 return ira->codegen->invalid_instruction;20094 return ira->codegen->invalid_inst_gen;
19097 }20095 }
19098 }20096 }
19099 return result_instruction;20097 return result_instruction;
19100 }20098 }
1910120099
19102 IrInstruction *result = ir_build_un_op(&ira->new_irb,20100 if (is_wrap_op) {
19103 instruction->base.scope, instruction->base.source_node,20101 return ir_build_negation_wrapping(ira, &instruction->base.base, value, expr_type);
19104 instruction->op_id, value);20102 } else {
19105 result->value->type = expr_type;20103 return ir_build_negation(ira, &instruction->base.base, value, expr_type);
19106 return result;20104 }
19107}20105}
1910820106
19109static IrInstruction *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *instruction) {20107static IrInstGen *ir_analyze_bin_not(IrAnalyze *ira, IrInstSrcUnOp *instruction) {
19110 IrInstruction *value = instruction->value->child;20108 IrInstGen *value = instruction->value->child;
19111 ZigType *expr_type = value->value->type;20109 ZigType *expr_type = value->value->type;
19112 if (type_is_invalid(expr_type))20110 if (type_is_invalid(expr_type))
19113 return ira->codegen->invalid_instruction;20111 return ira->codegen->invalid_inst_gen;
1911420112
19115 if (expr_type->id == ZigTypeIdInt) {20113 if (expr_type->id == ZigTypeIdInt) {
19116 if (instr_is_comptime(value)) {20114 if (instr_is_comptime(value)) {
19117 ZigValue *target_const_val = ir_resolve_const(ira, value, UndefBad);20115 ZigValue *target_const_val = ir_resolve_const(ira, value, UndefBad);
19118 if (target_const_val == nullptr)20116 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);
19122 bigint_not(&result->value->data.x_bigint, &target_const_val->data.x_bigint,20120 bigint_not(&result->value->data.x_bigint, &target_const_val->data.x_bigint,
19123 expr_type->data.integral.bit_count, expr_type->data.integral.is_signed);20121 expr_type->data.integral.bit_count, expr_type->data.integral.is_signed);
19124 return result;20122 return result;
19125 }20123 }
1912620124
19127 IrInstruction *result = ir_build_un_op(&ira->new_irb, instruction->base.scope,20125 return ir_build_binary_not(ira, &instruction->base.base, value, expr_type);
19128 instruction->base.source_node, IrUnOpBinNot, value);
19129 result->value->type = expr_type;
19130 return result;
19131 }20126 }
1913220127
19133 ir_add_error(ira, &instruction->base,20128 ir_add_error(ira, &instruction->base.base,
19134 buf_sprintf("unable to perform binary not operation on type '%s'", buf_ptr(&expr_type->name)));20129 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;
19136}20131}
1913720132
19138static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstructionUnOp *instruction) {20133static IrInstGen *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstSrcUnOp *instruction) {
19139 IrUnOp op_id = instruction->op_id;20134 IrUnOp op_id = instruction->op_id;
19140 switch (op_id) {20135 switch (op_id) {
19141 case IrUnOpInvalid:20136 case IrUnOpInvalid:
...@@ -19146,26 +20141,26 @@ static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstruction...@@ -19146,26 +20141,26 @@ static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstruction
19146 case IrUnOpNegationWrap:20141 case IrUnOpNegationWrap:
19147 return ir_analyze_negation(ira, instruction);20142 return ir_analyze_negation(ira, instruction);
19148 case IrUnOpDereference: {20143 case IrUnOpDereference: {
19149 IrInstruction *ptr = instruction->value->child;20144 IrInstGen *ptr = instruction->value->child;
19150 if (type_is_invalid(ptr->value->type))20145 if (type_is_invalid(ptr->value->type))
19151 return ira->codegen->invalid_instruction;20146 return ira->codegen->invalid_inst_gen;
19152 ZigType *ptr_type = ptr->value->type;20147 ZigType *ptr_type = ptr->value->type;
19153 if (ptr_type->id == ZigTypeIdPointer && ptr_type->data.pointer.ptr_len == PtrLenUnknown) {20148 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,
19155 buf_sprintf("index syntax required for unknown-length pointer type '%s'",20150 buf_sprintf("index syntax required for unknown-length pointer type '%s'",
19156 buf_ptr(&ptr_type->name)));20151 buf_ptr(&ptr_type->name)));
19157 return ira->codegen->invalid_instruction;20152 return ira->codegen->invalid_inst_gen;
19158 }20153 }
1915920154
19160 IrInstruction *result = ir_get_deref(ira, &instruction->base, ptr, instruction->result_loc);20155 IrInstGen *result = ir_get_deref(ira, &instruction->base.base, ptr, instruction->result_loc);
19161 if (result == ira->codegen->invalid_instruction)20156 if (type_is_invalid(result->value->type))
19162 return ira->codegen->invalid_instruction;20157 return ira->codegen->invalid_inst_gen;
1916320158
19164 // If the result needs to be an lvalue, type check it20159 // If the result needs to be an lvalue, type check it
19165 if (instruction->lval == LValPtr && result->value->type->id != ZigTypeIdPointer) {20160 if (instruction->lval == LValPtr && result->value->type->id != ZigTypeIdPointer) {
19166 ir_add_error(ira, &instruction->base,20161 ir_add_error(ira, &instruction->base.base,
19167 buf_sprintf("attempt to dereference non-pointer type '%s'", buf_ptr(&result->value->type->name)));20162 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;
19169 }20164 }
1917020165
19171 return result;20166 return result;
...@@ -19177,42 +20172,40 @@ static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstruction...@@ -19177,42 +20172,40 @@ static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstruction
19177}20172}
1917820173
19179static void ir_push_resume(IrAnalyze *ira, IrSuspendPosition pos) {20174static 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);
19181 if (old_bb->in_resume_stack) return;20176 if (old_bb->in_resume_stack) return;
19182 ira->resume_stack.append(pos);20177 ira->resume_stack.append(pos);
19183 old_bb->in_resume_stack = true;20178 old_bb->in_resume_stack = true;
19184}20179}
1918520180
19186static void ir_push_resume_block(IrAnalyze *ira, IrBasicBlock *old_bb) {20181static void ir_push_resume_block(IrAnalyze *ira, IrBasicBlockSrc *old_bb) {
19187 if (ira->resume_stack.length != 0) {20182 if (ira->resume_stack.length != 0) {
19188 ir_push_resume(ira, {old_bb->index, 0});20183 ir_push_resume(ira, {old_bb->index, 0});
19189 }20184 }
19190}20185}
1919120186
19192static IrInstruction *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr *br_instruction) {20187static IrInstGen *ir_analyze_instruction_br(IrAnalyze *ira, IrInstSrcBr *br_instruction) {
19193 IrBasicBlock *old_dest_block = br_instruction->dest_block;20188 IrBasicBlockSrc *old_dest_block = br_instruction->dest_block;
1919420189
19195 bool is_comptime;20190 bool is_comptime;
19196 if (!ir_resolve_comptime(ira, br_instruction->is_comptime->child, &is_comptime))20191 if (!ir_resolve_comptime(ira, br_instruction->is_comptime->child, &is_comptime))
19197 return ir_unreach_error(ira);20192 return ir_unreach_error(ira);
1919820193
19199 if (is_comptime || (old_dest_block->ref_count == 1 && old_dest_block->suspend_instruction_ref == nullptr))20194 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);
19203 if (new_bb == nullptr)20198 if (new_bb == nullptr)
19204 return ir_unreach_error(ira);20199 return ir_unreach_error(ira);
1920520200
19206 ir_push_resume_block(ira, old_dest_block);20201 ir_push_resume_block(ira, old_dest_block);
1920720202
19208 IrInstruction *result = ir_build_br(&ira->new_irb,20203 IrInstGen *result = ir_build_br_gen(ira, &br_instruction->base.base, new_bb);
19209 br_instruction->base.scope, br_instruction->base.source_node, new_bb, nullptr);
19210 result->value->type = ira->codegen->builtin_types.entry_unreachable;
19211 return ir_finish_anal(ira, result);20204 return ir_finish_anal(ira, result);
19212}20205}
1921320206
19214static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructionCondBr *cond_br_instruction) {20207static IrInstGen *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstSrcCondBr *cond_br_instruction) {
19215 IrInstruction *condition = cond_br_instruction->condition->child;20208 IrInstGen *condition = cond_br_instruction->condition->child;
19216 if (type_is_invalid(condition->value->type))20209 if (type_is_invalid(condition->value->type))
19217 return ir_unreach_error(ira);20210 return ir_unreach_error(ira);
1921820211
...@@ -19221,7 +20214,7 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi...@@ -19221,7 +20214,7 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi
19221 return ir_unreach_error(ira);20214 return ir_unreach_error(ira);
1922220215
19223 ZigType *bool_type = ira->codegen->builtin_types.entry_bool;20216 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);
19225 if (type_is_invalid(casted_condition->value->type))20218 if (type_is_invalid(casted_condition->value->type))
19226 return ir_unreach_error(ira);20219 return ir_unreach_error(ira);
1922720220
...@@ -19230,67 +20223,61 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi...@@ -19230,67 +20223,61 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi
19230 if (!ir_resolve_bool(ira, casted_condition, &cond_is_true))20223 if (!ir_resolve_bool(ira, casted_condition, &cond_is_true))
19231 return ir_unreach_error(ira);20224 return ir_unreach_error(ira);
1923220225
19233 IrBasicBlock *old_dest_block = cond_is_true ?20226 IrBasicBlockSrc *old_dest_block = cond_is_true ?
19234 cond_br_instruction->then_block : cond_br_instruction->else_block;20227 cond_br_instruction->then_block : cond_br_instruction->else_block;
1923520228
19236 if (is_comptime || (old_dest_block->ref_count == 1 && old_dest_block->suspend_instruction_ref == nullptr))20229 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);
19240 if (new_dest_block == nullptr)20233 if (new_dest_block == nullptr)
19241 return ir_unreach_error(ira);20234 return ir_unreach_error(ira);
1924220235
19243 ir_push_resume_block(ira, old_dest_block);20236 ir_push_resume_block(ira, old_dest_block);
1924420237
19245 IrInstruction *result = ir_build_br(&ira->new_irb,20238 IrInstGen *result = ir_build_br_gen(ira, &cond_br_instruction->base.base, new_dest_block);
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;
19248 return ir_finish_anal(ira, result);20239 return ir_finish_anal(ira, result);
19249 }20240 }
1925020241
19251 assert(cond_br_instruction->then_block != cond_br_instruction->else_block);20242 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);
19253 if (new_then_block == nullptr)20244 if (new_then_block == nullptr)
19254 return ir_unreach_error(ira);20245 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);
19257 if (new_else_block == nullptr)20248 if (new_else_block == nullptr)
19258 return ir_unreach_error(ira);20249 return ir_unreach_error(ira);
1925920250
19260 ir_push_resume_block(ira, cond_br_instruction->else_block);20251 ir_push_resume_block(ira, cond_br_instruction->else_block);
19261 ir_push_resume_block(ira, cond_br_instruction->then_block);20252 ir_push_resume_block(ira, cond_br_instruction->then_block);
1926220253
19263 IrInstruction *result = ir_build_cond_br(&ira->new_irb,20254 IrInstGen *result = ir_build_cond_br_gen(ira, &cond_br_instruction->base.base,
19264 cond_br_instruction->base.scope, cond_br_instruction->base.source_node,20255 casted_condition, new_then_block, new_else_block);
19265 casted_condition, new_then_block, new_else_block, nullptr);
19266 result->value->type = ira->codegen->builtin_types.entry_unreachable;
19267 return ir_finish_anal(ira, result);20256 return ir_finish_anal(ira, result);
19268}20257}
1926920258
19270static IrInstruction *ir_analyze_instruction_unreachable(IrAnalyze *ira,20259static IrInstGen *ir_analyze_instruction_unreachable(IrAnalyze *ira,
19271 IrInstructionUnreachable *unreachable_instruction)20260 IrInstSrcUnreachable *unreachable_instruction)
19272{20261{
19273 IrInstruction *result = ir_build_unreachable(&ira->new_irb,20262 IrInstGen *result = ir_build_unreachable_gen(ira, &unreachable_instruction->base.base);
19274 unreachable_instruction->base.scope, unreachable_instruction->base.source_node);
19275 result->value->type = ira->codegen->builtin_types.entry_unreachable;
19276 return ir_finish_anal(ira, result);20263 return ir_finish_anal(ira, result);
19277}20264}
1927820265
19279static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPhi *phi_instruction) {20266static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_instruction) {
19280 Error err;20267 Error err;
1928120268
19282 if (ira->const_predecessor_bb) {20269 if (ira->const_predecessor_bb) {
19283 for (size_t i = 0; i < phi_instruction->incoming_count; i += 1) {20270 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];
19285 if (predecessor != ira->const_predecessor_bb)20272 if (predecessor != ira->const_predecessor_bb)
19286 continue;20273 continue;
19287 IrInstruction *value = phi_instruction->incoming_values[i]->child;20274 IrInstGen *value = phi_instruction->incoming_values[i]->child;
19288 assert(value->value->type);20275 assert(value->value->type);
19289 if (type_is_invalid(value->value->type))20276 if (type_is_invalid(value->value->type))
19290 return ira->codegen->invalid_instruction;20277 return ira->codegen->invalid_inst_gen;
1929120278
19292 if (value->value->special != ConstValSpecialRuntime) {20279 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);
19294 copy_const_val(result->value, value->value);20281 copy_const_val(result->value, value->value);
19295 return result;20282 return result;
19296 } else {20283 } else {
...@@ -19305,17 +20292,17 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh...@@ -19305,17 +20292,17 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
19305 peer_parent->peers.length >= 2)20292 peer_parent->peers.length >= 2)
19306 {20293 {
19307 if (peer_parent->resolved_type == nullptr) {20294 if (peer_parent->resolved_type == nullptr) {
19308 IrInstruction **instructions = allocate<IrInstruction *>(peer_parent->peers.length);20295 IrInstGen **instructions = allocate<IrInstGen *>(peer_parent->peers.length);
19309 for (size_t i = 0; i < peer_parent->peers.length; i += 1) {20296 for (size_t i = 0; i < peer_parent->peers.length; i += 1) {
19310 ResultLocPeer *this_peer = peer_parent->peers.at(i);20297 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;
19313 if (gen_instruction == nullptr) {20300 if (gen_instruction == nullptr) {
19314 // unreachable instructions will cause implicit_elem_type to be null20301 // unreachable instructions will cause implicit_elem_type to be null
19315 if (this_peer->base.implicit_elem_type == nullptr) {20302 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);
19317 } else {20304 } else {
19318 instructions[i] = ir_const(ira, this_peer->base.source_instruction,20305 instructions[i] = ir_const(ira, &this_peer->base.source_instruction->base,
19319 this_peer->base.implicit_elem_type);20306 this_peer->base.implicit_elem_type);
19320 instructions[i]->value->special = ConstValSpecialRuntime;20307 instructions[i]->value->special = ConstValSpecialRuntime;
19321 }20308 }
...@@ -19324,34 +20311,34 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh...@@ -19324,34 +20311,34 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
19324 }20311 }
1932520312
19326 }20313 }
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);
19328 peer_parent->resolved_type = ir_resolve_peer_types(ira,20315 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,
19330 peer_parent->peers.length);20317 peer_parent->peers.length);
19331 if (type_is_invalid(peer_parent->resolved_type))20318 if (type_is_invalid(peer_parent->resolved_type))
19332 return ira->codegen->invalid_instruction;20319 return ira->codegen->invalid_inst_gen;
1933320320
19334 // the logic below assumes there are no instructions in the new current basic block yet20321 // 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
19337 // In case resolving the parent activates a suspend, do it now20324 // 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,
19339 peer_parent->resolved_type, nullptr, false, false, true);20326 peer_parent->resolved_type, nullptr, false, false, true);
19340 if (parent_result_loc != nullptr &&20327 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))
19342 {20329 {
19343 return parent_result_loc;20330 return parent_result_loc;
19344 }20331 }
19345 // If the above code generated any instructions in the current basic block, we need20332 // If the above code generated any instructions in the current basic block, we need
19346 // to move them to the peer parent predecessor.20333 // to move them to the peer parent predecessor.
19347 ZigList<IrInstruction *> instrs_to_move = {};20334 ZigList<IrInstGen *> instrs_to_move = {};
19348 while (ira->new_irb.current_basic_block->instruction_list.length != 0) {20335 while (ira->new_irb.current_basic_block->instruction_list.length != 0) {
19349 instrs_to_move.append(ira->new_irb.current_basic_block->instruction_list.pop());20336 instrs_to_move.append(ira->new_irb.current_basic_block->instruction_list.pop());
19350 }20337 }
19351 if (instrs_to_move.length != 0) {20338 if (instrs_to_move.length != 0) {
19352 IrBasicBlock *predecessor = peer_parent->base.source_instruction->child->owner_bb;20339 IrBasicBlockGen *predecessor = peer_parent->base.source_instruction->child->owner_bb;
19353 IrInstruction *branch_instruction = predecessor->instruction_list.pop();20340 IrInstGen *branch_instruction = predecessor->instruction_list.pop();
19354 ir_assert(branch_instruction->value->type->id == ZigTypeIdUnreachable, &phi_instruction->base);20341 ir_assert(branch_instruction->value->type->id == ZigTypeIdUnreachable, &phi_instruction->base.base);
19355 while (instrs_to_move.length != 0) {20342 while (instrs_to_move.length != 0) {
19356 predecessor->instruction_list.append(instrs_to_move.pop());20343 predecessor->instruction_list.append(instrs_to_move.pop());
19357 }20344 }
...@@ -19360,7 +20347,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh...@@ -19360,7 +20347,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
19360 }20347 }
1936120348
19362 IrSuspendPosition suspend_pos;20349 IrSuspendPosition suspend_pos;
19363 ira_suspend(ira, &phi_instruction->base, nullptr, &suspend_pos);20350 ira_suspend(ira, &phi_instruction->base.base, nullptr, &suspend_pos);
19364 ir_push_resume(ira, suspend_pos);20351 ir_push_resume(ira, suspend_pos);
1936520352
19366 for (size_t i = 0; i < peer_parent->peers.length; i += 1) {20353 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...@@ -19376,34 +20363,32 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
19376 return ira_resume(ira);20363 return ira_resume(ira);
19377 }20364 }
1937820365
19379 ZigList<IrBasicBlock*> new_incoming_blocks = {0};20366 ZigList<IrBasicBlockGen*> new_incoming_blocks = {0};
19380 ZigList<IrInstruction*> new_incoming_values = {0};20367 ZigList<IrInstGen*> new_incoming_values = {0};
1938120368
19382 for (size_t i = 0; i < phi_instruction->incoming_count; i += 1) {20369 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];
19384 if (predecessor->ref_count == 0)20371 if (predecessor->ref_count == 0)
19385 continue;20372 continue;
1938620373
1938720374
19388 IrInstruction *old_value = phi_instruction->incoming_values[i];20375 IrInstSrc *old_value = phi_instruction->incoming_values[i];
19389 assert(old_value);20376 assert(old_value);
19390 IrInstruction *new_value = old_value->child;20377 IrInstGen *new_value = old_value->child;
19391 if (!new_value || new_value->value->type->id == ZigTypeIdUnreachable || predecessor->other == nullptr)20378 if (!new_value || new_value->value->type->id == ZigTypeIdUnreachable || predecessor->child == nullptr)
19392 continue;20379 continue;
1939320380
19394 if (type_is_invalid(new_value->value->type))20381 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);20385 assert(predecessor->child);
19399 new_incoming_blocks.append(predecessor->other);20386 new_incoming_blocks.append(predecessor->child);
19400 new_incoming_values.append(new_value);20387 new_incoming_values.append(new_value);
19401 }20388 }
1940220389
19403 if (new_incoming_blocks.length == 0) {20390 if (new_incoming_blocks.length == 0) {
19404 IrInstruction *result = ir_build_unreachable(&ira->new_irb,20391 IrInstGen *result = ir_build_unreachable_gen(ira, &phi_instruction->base.base);
19405 phi_instruction->base.scope, phi_instruction->base.source_node);
19406 result->value->type = ira->codegen->builtin_types.entry_unreachable;
19407 return ir_finish_anal(ira, result);20392 return ir_finish_anal(ira, result);
19408 }20393 }
1940920394
...@@ -19415,7 +20400,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh...@@ -19415,7 +20400,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
19415 if (peer_parent != nullptr) {20400 if (peer_parent != nullptr) {
19416 bool peer_parent_has_type;20401 bool peer_parent_has_type;
19417 if ((err = ir_result_has_type(ira, peer_parent->parent, &peer_parent_has_type)))20402 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;
19419 if (peer_parent_has_type) {20404 if (peer_parent_has_type) {
19420 if (peer_parent->parent->id == ResultLocIdReturn) {20405 if (peer_parent->parent->id == ResultLocIdReturn) {
19421 resolved_type = ira->explicit_return_type;20406 resolved_type = ira->explicit_return_type;
...@@ -19423,27 +20408,27 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh...@@ -19423,27 +20408,27 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
19423 resolved_type = ir_resolve_type(ira, peer_parent->parent->source_instruction->child);20408 resolved_type = ir_resolve_type(ira, peer_parent->parent->source_instruction->child);
19424 } else if (peer_parent->parent->resolved_loc) {20409 } else if (peer_parent->parent->resolved_loc) {
19425 ZigType *resolved_loc_ptr_type = peer_parent->parent->resolved_loc->value->type;20410 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);
19427 resolved_type = resolved_loc_ptr_type->data.pointer.child_type;20412 resolved_type = resolved_loc_ptr_type->data.pointer.child_type;
19428 }20413 }
1942920414
19430 if (resolved_type != nullptr && type_is_invalid(resolved_type))20415 if (resolved_type != nullptr && type_is_invalid(resolved_type))
19431 return ira->codegen->invalid_instruction;20416 return ira->codegen->invalid_inst_gen;
19432 }20417 }
19433 }20418 }
1943420419
19435 if (resolved_type == nullptr) {20420 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,
19437 new_incoming_values.items, new_incoming_values.length);20422 new_incoming_values.items, new_incoming_values.length);
19438 if (type_is_invalid(resolved_type))20423 if (type_is_invalid(resolved_type))
19439 return ira->codegen->invalid_instruction;20424 return ira->codegen->invalid_inst_gen;
19440 }20425 }
1944120426
19442 switch (type_has_one_possible_value(ira->codegen, resolved_type)) {20427 switch (type_has_one_possible_value(ira->codegen, resolved_type)) {
19443 case OnePossibleValueInvalid:20428 case OnePossibleValueInvalid:
19444 return ira->codegen->invalid_instruction;20429 return ira->codegen->invalid_inst_gen;
19445 case OnePossibleValueYes:20430 case OnePossibleValueYes:
19446 return ir_const_move(ira, &phi_instruction->base,20431 return ir_const_move(ira, &phi_instruction->base.base,
19447 get_the_one_possible_value(ira->codegen, resolved_type));20432 get_the_one_possible_value(ira->codegen, resolved_type));
19448 case OnePossibleValueNo:20433 case OnePossibleValueNo:
19449 break;20434 break;
...@@ -19451,11 +20436,11 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh...@@ -19451,11 +20436,11 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1945120436
19452 switch (type_requires_comptime(ira->codegen, resolved_type)) {20437 switch (type_requires_comptime(ira->codegen, resolved_type)) {
19453 case ReqCompTimeInvalid:20438 case ReqCompTimeInvalid:
19454 return ira->codegen->invalid_instruction;20439 return ira->codegen->invalid_inst_gen;
19455 case ReqCompTimeYes:20440 case ReqCompTimeYes:
19456 ir_add_error_node(ira, phi_instruction->base.source_node,20441 ir_add_error(ira, &phi_instruction->base.base,
19457 buf_sprintf("values of type '%s' must be comptime known", buf_ptr(&resolved_type->name)));20442 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;
19459 case ReqCompTimeNo:20444 case ReqCompTimeNo:
19460 break;20445 break;
19461 }20446 }
...@@ -19465,16 +20450,16 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh...@@ -19465,16 +20450,16 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
19465 // cast all values to the resolved type. however we can't put cast instructions in front of the phi instruction.20450 // cast all values to the resolved type. however we can't put cast instructions in front of the phi instruction.
19466 // so we go back and insert the casts as the last instruction in the corresponding predecessor blocks, and20451 // so we go back and insert the casts as the last instruction in the corresponding predecessor blocks, and
19467 // then make sure the branch instruction is preserved.20452 // 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;
19469 for (size_t i = 0; i < new_incoming_values.length; i += 1) {20454 for (size_t i = 0; i < new_incoming_values.length; i += 1) {
19470 IrInstruction *new_value = new_incoming_values.at(i);20455 IrInstGen *new_value = new_incoming_values.at(i);
19471 IrBasicBlock *predecessor = new_incoming_blocks.at(i);20456 IrBasicBlockGen *predecessor = new_incoming_blocks.at(i);
19472 ir_assert(predecessor->instruction_list.length != 0, &phi_instruction->base);20457 ir_assert(predecessor->instruction_list.length != 0, &phi_instruction->base.base);
19473 IrInstruction *branch_instruction = predecessor->instruction_list.pop();20458 IrInstGen *branch_instruction = predecessor->instruction_list.pop();
19474 ir_set_cursor_at_end(&ira->new_irb, predecessor);20459 ir_set_cursor_at_end_gen(&ira->new_irb, predecessor);
19475 IrInstruction *casted_value = ir_implicit_cast(ira, new_value, resolved_type);20460 IrInstGen *casted_value = ir_implicit_cast(ira, new_value, resolved_type);
19476 if (type_is_invalid(casted_value->value->type)) {20461 if (type_is_invalid(casted_value->value->type)) {
19477 return ira->codegen->invalid_instruction;20462 return ira->codegen->invalid_inst_gen;
19478 }20463 }
19479 new_incoming_values.items[i] = casted_value;20464 new_incoming_values.items[i] = casted_value;
19480 predecessor->instruction_list.append(branch_instruction);20465 predecessor->instruction_list.append(branch_instruction);
...@@ -19485,12 +20470,10 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh...@@ -19485,12 +20470,10 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
19485 all_stack_ptrs = false;20470 all_stack_ptrs = false;
19486 }20471 }
19487 }20472 }
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,20475 IrInstGen *result = ir_build_phi_gen(ira, &phi_instruction->base.base,
19491 phi_instruction->base.scope, phi_instruction->base.source_node,20476 new_incoming_blocks.length, new_incoming_blocks.items, new_incoming_values.items, resolved_type);
19492 new_incoming_blocks.length, new_incoming_blocks.items, new_incoming_values.items, nullptr);
19493 result->value->type = resolved_type;
1949420477
19495 if (all_stack_ptrs) {20478 if (all_stack_ptrs) {
19496 assert(result->value->special == ConstValSpecialRuntime);20479 assert(result->value->special == ConstValSpecialRuntime);
...@@ -19500,17 +20483,17 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh...@@ -19500,17 +20483,17 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
19500 return result;20483 return result;
19501}20484}
1950220485
19503static IrInstruction *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarPtr *instruction) {20486static IrInstGen *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstSrcVarPtr *instruction) {
19504 ZigVar *var = instruction->var;20487 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);
19506 if (instruction->crossed_fndef_scope != nullptr && !instr_is_comptime(result)) {20489 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,
19508 buf_sprintf("'%s' not accessible from inner function", var->name));20491 buf_sprintf("'%s' not accessible from inner function", var->name));
19509 add_error_note(ira->codegen, msg, instruction->crossed_fndef_scope->base.source_node,20492 add_error_note(ira->codegen, msg, instruction->crossed_fndef_scope->base.source_node,
19510 buf_sprintf("crossed function definition here"));20493 buf_sprintf("crossed function definition here"));
19511 add_error_note(ira->codegen, msg, var->decl_node,20494 add_error_note(ira->codegen, msg, var->decl_node,
19512 buf_sprintf("declared here"));20495 buf_sprintf("declared here"));
19513 return ira->codegen->invalid_instruction;20496 return ira->codegen->invalid_inst_gen;
19514 }20497 }
19515 return result;20498 return result;
19516}20499}
...@@ -19561,17 +20544,17 @@ static ZigType *adjust_ptr_len(CodeGen *g, ZigType *ptr_type, PtrLen ptr_len) {...@@ -19561,17 +20544,17 @@ static ZigType *adjust_ptr_len(CodeGen *g, ZigType *ptr_type, PtrLen ptr_len) {
19561 ptr_type->data.pointer.allow_zero);20544 ptr_type->data.pointer.allow_zero);
19562}20545}
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) {
19565 Error err;20548 Error err;
19566 IrInstruction *array_ptr = elem_ptr_instruction->array_ptr->child;20549 IrInstGen *array_ptr = elem_ptr_instruction->array_ptr->child;
19567 if (type_is_invalid(array_ptr->value->type))20550 if (type_is_invalid(array_ptr->value->type))
19568 return ira->codegen->invalid_instruction;20551 return ira->codegen->invalid_inst_gen;
1956920552
19570 ZigValue *orig_array_ptr_val = array_ptr->value;20553 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;
19573 if (type_is_invalid(elem_index->value->type))20556 if (type_is_invalid(elem_index->value->type))
19574 return ira->codegen->invalid_instruction;20557 return ira->codegen->invalid_inst_gen;
1957520558
19576 ZigType *ptr_type = orig_array_ptr_val->type;20559 ZigType *ptr_type = orig_array_ptr_val->type;
19577 assert(ptr_type->id == ZigTypeIdPointer);20560 assert(ptr_type->id == ZigTypeIdPointer);
...@@ -19583,7 +20566,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -19583,7 +20566,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
19583 ZigType *return_type;20566 ZigType *return_type;
1958420567
19585 if (type_is_invalid(array_type)) {20568 if (type_is_invalid(array_type)) {
19586 return ira->codegen->invalid_instruction;20569 return ira->codegen->invalid_inst_gen;
19587 } else if (array_type->id == ZigTypeIdArray ||20570 } else if (array_type->id == ZigTypeIdArray ||
19588 (array_type->id == ZigTypeIdPointer &&20571 (array_type->id == ZigTypeIdPointer &&
19589 array_type->data.pointer.ptr_len == PtrLenSingle &&20572 array_type->data.pointer.ptr_len == PtrLenSingle &&
...@@ -19594,15 +20577,15 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -19594,15 +20577,15 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
19594 ptr_type = ptr_type->data.pointer.child_type;20577 ptr_type = ptr_type->data.pointer.child_type;
19595 if (orig_array_ptr_val->special != ConstValSpecialRuntime) {20578 if (orig_array_ptr_val->special != ConstValSpecialRuntime) {
19596 orig_array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val,20579 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);
19598 if (orig_array_ptr_val == nullptr)20581 if (orig_array_ptr_val == nullptr)
19599 return ira->codegen->invalid_instruction;20582 return ira->codegen->invalid_inst_gen;
19600 }20583 }
19601 }20584 }
19602 if (array_type->data.array.len == 0) {20585 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,
19604 buf_sprintf("index 0 outside array of size 0"));20587 buf_sprintf("index 0 outside array of size 0"));
19605 return ira->codegen->invalid_instruction;20588 return ira->codegen->invalid_inst_gen;
19606 }20589 }
19607 ZigType *child_type = array_type->data.array.child_type;20590 ZigType *child_type = array_type->data.array.child_type;
19608 if (ptr_type->data.pointer.host_int_bytes == 0) {20591 if (ptr_type->data.pointer.host_int_bytes == 0) {
...@@ -19613,7 +20596,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -19613,7 +20596,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
19613 } else {20596 } else {
19614 uint64_t elem_val_scalar;20597 uint64_t elem_val_scalar;
19615 if (!ir_resolve_usize(ira, elem_index, &elem_val_scalar))20598 if (!ir_resolve_usize(ira, elem_index, &elem_val_scalar))
19616 return ira->codegen->invalid_instruction;20599 return ira->codegen->invalid_inst_gen;
1961720600
19618 size_t bit_width = type_size_bits(ira->codegen, child_type);20601 size_t bit_width = type_size_bits(ira->codegen, child_type);
19619 size_t bit_offset = bit_width * elem_val_scalar;20602 size_t bit_offset = bit_width * elem_val_scalar;
...@@ -19625,9 +20608,9 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -19625,9 +20608,9 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
19625 }20608 }
19626 } else if (array_type->id == ZigTypeIdPointer) {20609 } else if (array_type->id == ZigTypeIdPointer) {
19627 if (array_type->data.pointer.ptr_len == PtrLenSingle) {20610 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,
19629 buf_sprintf("index of single-item pointer"));20612 buf_sprintf("index of single-item pointer"));
19630 return ira->codegen->invalid_instruction;20613 return ira->codegen->invalid_inst_gen;
19631 }20614 }
19632 return_type = adjust_ptr_len(ira->codegen, array_type, elem_ptr_instruction->ptr_len);20615 return_type = adjust_ptr_len(ira->codegen, array_type, elem_ptr_instruction->ptr_len);
19633 } else if (is_slice(array_type)) {20616 } else if (is_slice(array_type)) {
...@@ -19641,38 +20624,38 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -19641,38 +20624,38 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
19641 array_type->data.structure.resolve_status == ResolveStatusBeingInferred)20624 array_type->data.structure.resolve_status == ResolveStatusBeingInferred)
19642 {20625 {
19643 ZigType *usize = ira->codegen->builtin_types.entry_usize;20626 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);
19645 if (type_is_invalid(casted_elem_index->value->type))20628 if (type_is_invalid(casted_elem_index->value->type))
19646 return ira->codegen->invalid_instruction;20629 return ira->codegen->invalid_inst_gen;
19647 ir_assert(instr_is_comptime(casted_elem_index), &elem_ptr_instruction->base);20630 ir_assert(instr_is_comptime(casted_elem_index), &elem_ptr_instruction->base.base);
19648 Buf *field_name = buf_alloc();20631 Buf *field_name = buf_alloc();
19649 bigint_append_buf(field_name, &casted_elem_index->value->data.x_bigint, 10);20632 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,
19651 array_ptr, array_type);20634 array_ptr, array_type);
19652 } else if (is_tuple(array_type)) {20635 } else if (is_tuple(array_type)) {
19653 uint64_t elem_index_scalar;20636 uint64_t elem_index_scalar;
19654 if (!ir_resolve_usize(ira, elem_index, &elem_index_scalar))20637 if (!ir_resolve_usize(ira, elem_index, &elem_index_scalar))
19655 return ira->codegen->invalid_instruction;20638 return ira->codegen->invalid_inst_gen;
19656 if (elem_index_scalar >= array_type->data.structure.src_field_count) {20639 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(
19658 "field index %" ZIG_PRI_u64 " outside tuple '%s' which has %" PRIu32 " fields",20641 "field index %" ZIG_PRI_u64 " outside tuple '%s' which has %" PRIu32 " fields",
19659 elem_index_scalar, buf_ptr(&array_type->name),20642 elem_index_scalar, buf_ptr(&array_type->name),
19660 array_type->data.structure.src_field_count));20643 array_type->data.structure.src_field_count));
19661 return ira->codegen->invalid_instruction;20644 return ira->codegen->invalid_inst_gen;
19662 }20645 }
19663 TypeStructField *field = array_type->data.structure.fields[elem_index_scalar];20646 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,
19665 array_type, false);20648 array_type, false);
19666 } else {20649 } 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,
19668 buf_sprintf("array access of non-array type '%s'", buf_ptr(&array_type->name)));20651 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;
19670 }20653 }
1967120654
19672 ZigType *usize = ira->codegen->builtin_types.entry_usize;20655 ZigType *usize = ira->codegen->builtin_types.entry_usize;
19673 IrInstruction *casted_elem_index = ir_implicit_cast(ira, elem_index, usize);20656 IrInstGen *casted_elem_index = ir_implicit_cast(ira, elem_index, usize);
19674 if (casted_elem_index == ira->codegen->invalid_instruction)20657 if (type_is_invalid(casted_elem_index->value->type))
19675 return ira->codegen->invalid_instruction;20658 return ira->codegen->invalid_inst_gen;
1967620659
19677 bool safety_check_on = elem_ptr_instruction->safety_check_on;20660 bool safety_check_on = elem_ptr_instruction->safety_check_on;
19678 if (instr_is_comptime(casted_elem_index)) {20661 if (instr_is_comptime(casted_elem_index)) {
...@@ -19681,15 +20664,15 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -19681,15 +20664,15 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
19681 uint64_t array_len = array_type->data.array.len;20664 uint64_t array_len = array_type->data.array.len;
19682 if (index == array_len && array_type->data.array.sentinel != nullptr) {20665 if (index == array_len && array_type->data.array.sentinel != nullptr) {
19683 ZigType *elem_type = array_type->data.array.child_type;20666 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);
19685 copy_const_val(sentinel_elem->value, array_type->data.array.sentinel);20668 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);
19687 }20670 }
19688 if (index >= array_len) {20671 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,
19690 buf_sprintf("index %" ZIG_PRI_u64 " outside array of size %" ZIG_PRI_u64,20673 buf_sprintf("index %" ZIG_PRI_u64 " outside array of size %" ZIG_PRI_u64,
19691 index, array_len));20674 index, array_len));
19692 return ira->codegen->invalid_instruction;20675 return ira->codegen->invalid_inst_gen;
19693 }20676 }
19694 safety_check_on = false;20677 safety_check_on = false;
19695 }20678 }
...@@ -19705,7 +20688,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -19705,7 +20688,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
19705 // figure out the largest alignment possible20688 // figure out the largest alignment possible
1970620689
19707 if ((err = type_resolve(ira->codegen, return_type->data.pointer.child_type, ResolveStatusSizeKnown)))20690 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
19710 uint64_t elem_size = type_size(ira->codegen, return_type->data.pointer.child_type);20693 uint64_t elem_size = type_size(ira->codegen, return_type->data.pointer.child_type);
19711 uint64_t abi_align = get_abi_alignment(ira->codegen, return_type->data.pointer.child_type);20694 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...@@ -19735,9 +20718,9 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
19735 array_type->id == ZigTypeIdArray))20718 array_type->id == ZigTypeIdArray))
19736 {20719 {
19737 ZigValue *array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val,20720 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);
19739 if (array_ptr_val == nullptr)20722 if (array_ptr_val == nullptr)
19740 return ira->codegen->invalid_instruction;20723 return ira->codegen->invalid_inst_gen;
1974120724
19742 if (array_ptr_val->special == ConstValSpecialUndef &&20725 if (array_ptr_val->special == ConstValSpecialUndef &&
19743 elem_ptr_instruction->init_array_type_source_node != nullptr)20726 elem_ptr_instruction->init_array_type_source_node != nullptr)
...@@ -19755,16 +20738,16 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -19755,16 +20738,16 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
19755 elem_val->parent.data.p_array.elem_index = i;20738 elem_val->parent.data.p_array.elem_index = i;
19756 }20739 }
19757 } else if (is_slice(array_type)) {20740 } 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);
19759 ZigType *actual_array_type = array_ptr->value->type->data.pointer.child_type;20742 ZigType *actual_array_type = array_ptr->value->type->data.pointer.child_type;
1976020743
19761 if (type_is_invalid(actual_array_type))20744 if (type_is_invalid(actual_array_type))
19762 return ira->codegen->invalid_instruction;20745 return ira->codegen->invalid_inst_gen;
19763 if (actual_array_type->id != ZigTypeIdArray) {20746 if (actual_array_type->id != ZigTypeIdArray) {
19764 ir_add_error_node(ira, elem_ptr_instruction->init_array_type_source_node,20747 ir_add_error_node(ira, elem_ptr_instruction->init_array_type_source_node,
19765 buf_sprintf("array literal requires address-of operator to coerce to slice type '%s'",20748 buf_sprintf("array literal requires address-of operator to coerce to slice type '%s'",
19766 buf_ptr(&actual_array_type->name)));20749 buf_ptr(&actual_array_type->name)));
19767 return ira->codegen->invalid_instruction;20750 return ira->codegen->invalid_inst_gen;
19768 }20751 }
1976920752
19770 ZigValue *array_init_val = create_const_vals(1);20753 ZigValue *array_init_val = create_const_vals(1);
...@@ -19789,7 +20772,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -19789,7 +20772,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
19789 ir_add_error_node(ira, elem_ptr_instruction->init_array_type_source_node,20772 ir_add_error_node(ira, elem_ptr_instruction->init_array_type_source_node,
19790 buf_sprintf("expected array type or [_], found '%s'",20773 buf_sprintf("expected array type or [_], found '%s'",
19791 buf_ptr(&array_type->name)));20774 buf_ptr(&array_type->name)));
19792 return ira->codegen->invalid_instruction;20775 return ira->codegen->invalid_inst_gen;
19793 }20776 }
19794 }20777 }
1979520778
...@@ -19798,7 +20781,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -19798,7 +20781,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
19798 array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr))20781 array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr))
19799 {20782 {
19800 if (array_type->id == ZigTypeIdPointer) {20783 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);
19802 ZigValue *out_val = result->value;20785 ZigValue *out_val = result->value;
19803 out_val->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut;20786 out_val->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut;
19804 size_t new_index;20787 size_t new_index;
...@@ -19867,33 +20850,31 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -19867,33 +20850,31 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
19867 zig_panic("TODO elem ptr on a null pointer");20850 zig_panic("TODO elem ptr on a null pointer");
19868 }20851 }
19869 if (new_index >= mem_size) {20852 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,
19871 buf_sprintf("index %" ZIG_PRI_u64 " outside pointer of size %" ZIG_PRI_usize "", index, old_size));20854 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;
19873 }20856 }
19874 return result;20857 return result;
19875 } else if (is_slice(array_type)) {20858 } else if (is_slice(array_type)) {
19876 ZigValue *ptr_field = array_ptr_val->data.x_struct.fields[slice_ptr_index];20859 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);
19878 if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {20861 if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
19879 IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope,20862 return ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.base.scope,
19880 elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, false,20863 elem_ptr_instruction->base.base.source_node, array_ptr, casted_elem_index, false,
19881 elem_ptr_instruction->ptr_len, nullptr);20864 return_type);
19882 result->value->type = return_type;
19883 return result;
19884 }20865 }
19885 ZigValue *len_field = array_ptr_val->data.x_struct.fields[slice_len_index];20866 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);
19887 ZigValue *out_val = result->value;20868 ZigValue *out_val = result->value;
19888 ZigType *slice_ptr_type = array_type->data.structure.fields[slice_ptr_index]->type_entry;20869 ZigType *slice_ptr_type = array_type->data.structure.fields[slice_ptr_index]->type_entry;
19889 uint64_t slice_len = bigint_as_u64(&len_field->data.x_bigint);20870 uint64_t slice_len = bigint_as_u64(&len_field->data.x_bigint);
19890 uint64_t full_slice_len = slice_len +20871 uint64_t full_slice_len = slice_len +
19891 ((slice_ptr_type->data.pointer.sentinel != nullptr) ? 1 : 0);20872 ((slice_ptr_type->data.pointer.sentinel != nullptr) ? 1 : 0);
19892 if (index >= full_slice_len) {20873 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,
19894 buf_sprintf("index %" ZIG_PRI_u64 " outside slice of size %" ZIG_PRI_u64,20875 buf_sprintf("index %" ZIG_PRI_u64 " outside slice of size %" ZIG_PRI_u64,
19895 index, slice_len));20876 index, slice_len));
19896 return ira->codegen->invalid_instruction;20877 return ira->codegen->invalid_inst_gen;
19897 }20878 }
19898 out_val->data.x_ptr.mut = ptr_field->data.x_ptr.mut;20879 out_val->data.x_ptr.mut = ptr_field->data.x_ptr.mut;
19899 switch (ptr_field->data.x_ptr.special) {20880 switch (ptr_field->data.x_ptr.special) {
...@@ -19913,7 +20894,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -19913,7 +20894,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
19913 {20894 {
19914 ir_assert(new_index <20895 ir_assert(new_index <
19915 ptr_field->data.x_ptr.data.base_array.array_val->type->data.array.len,20896 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);
19917 }20898 }
19918 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;20899 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
19919 out_val->data.x_ptr.data.base_array.array_val =20900 out_val->data.x_ptr.data.base_array.array_val =
...@@ -19938,15 +20919,14 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -19938,15 +20919,14 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
19938 }20919 }
19939 return result;20920 return result;
19940 } else if (array_type->id == ZigTypeIdArray || array_type->id == ZigTypeIdVector) {20921 } else if (array_type->id == ZigTypeIdArray || array_type->id == ZigTypeIdVector) {
19941 IrInstruction *result;20922 IrInstGen *result;
19942 if (orig_array_ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {20923 if (orig_array_ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
19943 result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope,20924 result = ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.base.scope,
19944 elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index,20925 elem_ptr_instruction->base.base.source_node, array_ptr, casted_elem_index,
19945 false, elem_ptr_instruction->ptr_len, nullptr);20926 false, return_type);
19946 result->value->type = return_type;
19947 result->value->special = ConstValSpecialStatic;20927 result->value->special = ConstValSpecialStatic;
19948 } else {20928 } else {
19949 result = ir_const(ira, &elem_ptr_instruction->base, return_type);20929 result = ir_const(ira, &elem_ptr_instruction->base.base, return_type);
19950 }20930 }
19951 ZigValue *out_val = result->value;20931 ZigValue *out_val = result->value;
19952 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;20932 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
...@@ -19972,19 +20952,19 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -19972,19 +20952,19 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
19972 // runtime known element index20952 // runtime known element index
19973 switch (type_requires_comptime(ira->codegen, return_type)) {20953 switch (type_requires_comptime(ira->codegen, return_type)) {
19974 case ReqCompTimeYes:20954 case ReqCompTimeYes:
19975 ir_add_error(ira, elem_index,20955 ir_add_error(ira, &elem_index->base,
19976 buf_sprintf("values of type '%s' must be comptime known, but index value is runtime known",20956 buf_sprintf("values of type '%s' must be comptime known, but index value is runtime known",
19977 buf_ptr(&return_type->data.pointer.child_type->name)));20957 buf_ptr(&return_type->data.pointer.child_type->name)));
19978 return ira->codegen->invalid_instruction;20958 return ira->codegen->invalid_inst_gen;
19979 case ReqCompTimeInvalid:20959 case ReqCompTimeInvalid:
19980 return ira->codegen->invalid_instruction;20960 return ira->codegen->invalid_inst_gen;
19981 case ReqCompTimeNo:20961 case ReqCompTimeNo:
19982 break;20962 break;
19983 }20963 }
1998420964
19985 if (return_type->data.pointer.explicit_alignment != 0) {20965 if (return_type->data.pointer.explicit_alignment != 0) {
19986 if ((err = type_resolve(ira->codegen, return_type->data.pointer.child_type, ResolveStatusSizeKnown)))20966 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
19989 uint64_t elem_size = type_size(ira->codegen, return_type->data.pointer.child_type);20969 uint64_t elem_size = type_size(ira->codegen, return_type->data.pointer.child_type);
19990 uint64_t abi_align = get_abi_alignment(ira->codegen, return_type->data.pointer.child_type);20970 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...@@ -20002,16 +20982,13 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
20002 }20982 }
20003 }20983 }
2000420984
20005 IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope,20985 return ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.base.scope,
20006 elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, safety_check_on,20986 elem_ptr_instruction->base.base.source_node, array_ptr, casted_elem_index, safety_check_on, return_type);
20007 elem_ptr_instruction->ptr_len, nullptr);
20008 result->value->type = return_type;
20009 return result;
20010}20987}
2001120988
20012static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,20989static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira,
20013 ZigType *bare_struct_type, Buf *field_name, IrInstruction *source_instr,20990 ZigType *bare_struct_type, Buf *field_name, IrInst* source_instr,
20014 IrInstruction *container_ptr, ZigType *container_type)20991 IrInstGen *container_ptr, ZigType *container_type)
20015{20992{
20016 if (!is_slice(bare_struct_type)) {20993 if (!is_slice(bare_struct_type)) {
20017 ScopeDecls *container_scope = get_container_scope(bare_struct_type);20994 ScopeDecls *container_scope = get_container_scope(bare_struct_type);
...@@ -20021,29 +20998,27 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,...@@ -20021,29 +20998,27 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,
20021 if (tld->id == TldIdFn) {20998 if (tld->id == TldIdFn) {
20022 resolve_top_level_decl(ira->codegen, tld, source_instr->source_node, false);20999 resolve_top_level_decl(ira->codegen, tld, source_instr->source_node, false);
20023 if (tld->resolution == TldResolutionInvalid)21000 if (tld->resolution == TldResolutionInvalid)
20024 return ira->codegen->invalid_instruction;21001 return ira->codegen->invalid_inst_gen;
20025 TldFn *tld_fn = (TldFn *)tld;21002 TldFn *tld_fn = (TldFn *)tld;
20026 ZigFn *fn_entry = tld_fn->fn_entry;21003 ZigFn *fn_entry = tld_fn->fn_entry;
20027 if (type_is_invalid(fn_entry->type_entry))21004 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,21007 IrInstGen *bound_fn_value = ir_const_bound_fn(ira, source_instr, fn_entry, container_ptr);
20031 source_instr->source_node, fn_entry, container_ptr);
20032 return ir_get_ref(ira, source_instr, bound_fn_value, true, false);21008 return ir_get_ref(ira, source_instr, bound_fn_value, true, false);
20033 } else if (tld->id == TldIdVar) {21009 } else if (tld->id == TldIdVar) {
20034 resolve_top_level_decl(ira->codegen, tld, source_instr->source_node, false);21010 resolve_top_level_decl(ira->codegen, tld, source_instr->source_node, false);
20035 if (tld->resolution == TldResolutionInvalid)21011 if (tld->resolution == TldResolutionInvalid)
20036 return ira->codegen->invalid_instruction;21012 return ira->codegen->invalid_inst_gen;
20037 TldVar *tld_var = (TldVar *)tld;21013 TldVar *tld_var = (TldVar *)tld;
20038 ZigVar *var = tld_var->var;21014 ZigVar *var = tld_var->var;
20039 if (type_is_invalid(var->var_type))21015 if (type_is_invalid(var->var_type))
20040 return ira->codegen->invalid_instruction;21016 return ira->codegen->invalid_inst_gen;
2004121017
20042 if (var->const_value->type->id == ZigTypeIdFn) {21018 if (var->const_value->type->id == ZigTypeIdFn) {
20043 ir_assert(var->const_value->data.x_ptr.special == ConstPtrSpecialFunction, source_instr);21019 ir_assert(var->const_value->data.x_ptr.special == ConstPtrSpecialFunction, source_instr);
20044 ZigFn *fn = var->const_value->data.x_ptr.data.fn.fn_entry;21020 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,21021 IrInstGen *bound_fn_value = ir_const_bound_fn(ira, source_instr, fn, container_ptr);
20046 source_instr->source_node, fn, container_ptr);
20047 return ir_get_ref(ira, source_instr, bound_fn_value, true, false);21022 return ir_get_ref(ira, source_instr, bound_fn_value, true, false);
20048 }21023 }
20049 }21024 }
...@@ -20063,7 +21038,7 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,...@@ -20063,7 +21038,7 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,
20063 }21038 }
20064 ir_add_error_node(ira, source_instr->source_node,21039 ir_add_error_node(ira, source_instr->source_node,
20065 buf_sprintf("no member named '%s' in %s'%s'", buf_ptr(field_name), prefix_name, buf_ptr(&bare_struct_type->name)));21040 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;
20067}21042}
2006821043
20069static void memoize_field_init_val(CodeGen *codegen, ZigType *container_type, TypeStructField *field) {21044static 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...@@ -20078,24 +21053,24 @@ static void memoize_field_init_val(CodeGen *codegen, ZigType *container_type, Ty
20078 field->type_entry, nullptr, UndefOk);21053 field->type_entry, nullptr, UndefOk);
20079}21054}
2008021055
20081static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction *source_instr,21056static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_instr,
20082 TypeStructField *field, IrInstruction *struct_ptr, ZigType *struct_type, bool initializing)21057 TypeStructField *field, IrInstGen *struct_ptr, ZigType *struct_type, bool initializing)
20083{21058{
20084 Error err;21059 Error err;
20085 ZigType *field_type = resolve_struct_field_type(ira->codegen, field);21060 ZigType *field_type = resolve_struct_field_type(ira->codegen, field);
20086 if (field_type == nullptr)21061 if (field_type == nullptr)
20087 return ira->codegen->invalid_instruction;21062 return ira->codegen->invalid_inst_gen;
20088 if (field->is_comptime) {21063 if (field->is_comptime) {
20089 IrInstruction *elem = ir_const(ira, source_instr, field_type);21064 IrInstGen *elem = ir_const(ira, source_instr, field_type);
20090 memoize_field_init_val(ira->codegen, struct_type, field);21065 memoize_field_init_val(ira->codegen, struct_type, field);
20091 copy_const_val(elem->value, field->init_val);21066 copy_const_val(elem->value, field->init_val);
20092 return ir_get_ref(ira, source_instr, elem, true, false);21067 return ir_get_ref(ira, source_instr, elem, true, false);
20093 }21068 }
20094 switch (type_has_one_possible_value(ira->codegen, field_type)) {21069 switch (type_has_one_possible_value(ira->codegen, field_type)) {
20095 case OnePossibleValueInvalid:21070 case OnePossibleValueInvalid:
20096 return ira->codegen->invalid_instruction;21071 return ira->codegen->invalid_inst_gen;
20097 case OnePossibleValueYes: {21072 case OnePossibleValueYes: {
20098 IrInstruction *elem = ir_const_move(ira, source_instr,21073 IrInstGen *elem = ir_const_move(ira, source_instr,
20099 get_the_one_possible_value(ira->codegen, field_type));21074 get_the_one_possible_value(ira->codegen, field_type));
20100 return ir_get_ref(ira, source_instr, elem, false, false);21075 return ir_get_ref(ira, source_instr, elem, false, false);
20101 }21076 }
...@@ -20113,7 +21088,7 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction...@@ -20113,7 +21088,7 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction
20113 (struct_type->data.structure.layout == ContainerLayoutAuto) ?21088 (struct_type->data.structure.layout == ContainerLayoutAuto) ?
20114 ResolveStatusZeroBitsKnown : ResolveStatusSizeKnown;21089 ResolveStatusZeroBitsKnown : ResolveStatusSizeKnown;
20115 if ((err = type_resolve(ira->codegen, struct_type, needed_resolve_status)))21090 if ((err = type_resolve(ira->codegen, struct_type, needed_resolve_status)))
20116 return ira->codegen->invalid_instruction;21091 return ira->codegen->invalid_inst_gen;
20117 assert(struct_ptr->value->type->id == ZigTypeIdPointer);21092 assert(struct_ptr->value->type->id == ZigTypeIdPointer);
20118 uint32_t ptr_bit_offset = struct_ptr->value->type->data.pointer.bit_offset_in_host;21093 uint32_t ptr_bit_offset = struct_ptr->value->type->data.pointer.bit_offset_in_host;
20119 uint32_t ptr_host_int_bytes = struct_ptr->value->type->data.pointer.host_int_bytes;21094 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...@@ -20127,14 +21102,14 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction
20127 if (instr_is_comptime(struct_ptr)) {21102 if (instr_is_comptime(struct_ptr)) {
20128 ZigValue *ptr_val = ir_resolve_const(ira, struct_ptr, UndefBad);21103 ZigValue *ptr_val = ir_resolve_const(ira, struct_ptr, UndefBad);
20129 if (!ptr_val)21104 if (!ptr_val)
20130 return ira->codegen->invalid_instruction;21105 return ira->codegen->invalid_inst_gen;
2013121106
20132 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {21107 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
20133 ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);21108 ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
20134 if (struct_val == nullptr)21109 if (struct_val == nullptr)
20135 return ira->codegen->invalid_instruction;21110 return ira->codegen->invalid_inst_gen;
20136 if (type_is_invalid(struct_val->type))21111 if (type_is_invalid(struct_val->type))
20137 return ira->codegen->invalid_instruction;21112 return ira->codegen->invalid_inst_gen;
20138 if (initializing && struct_val->special == ConstValSpecialUndef) {21113 if (initializing && struct_val->special == ConstValSpecialUndef) {
20139 struct_val->data.x_struct.fields = alloc_const_vals_ptrs(struct_type->data.structure.src_field_count);21114 struct_val->data.x_struct.fields = alloc_const_vals_ptrs(struct_type->data.structure.src_field_count);
20140 struct_val->special = ConstValSpecialStatic;21115 struct_val->special = ConstValSpecialStatic;
...@@ -20148,11 +21123,9 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction...@@ -20148,11 +21123,9 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction
20148 field_val->parent.data.p_struct.field_index = i;21123 field_val->parent.data.p_struct.field_index = i;
20149 }21124 }
20150 }21125 }
20151 IrInstruction *result;21126 IrInstGen *result;
20152 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {21127 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
20153 result = ir_build_struct_field_ptr(&ira->new_irb, source_instr->scope,21128 result = ir_build_struct_field_ptr(ira, source_instr, struct_ptr, field, ptr_type);
20154 source_instr->source_node, struct_ptr, field);
20155 result->value->type = ptr_type;
20156 result->value->special = ConstValSpecialStatic;21129 result->value->special = ConstValSpecialStatic;
20157 } else {21130 } else {
20158 result = ir_const(ira, source_instr, ptr_type);21131 result = ir_const(ira, source_instr, ptr_type);
...@@ -20165,14 +21138,11 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction...@@ -20165,14 +21138,11 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction
20165 return result;21138 return result;
20166 }21139 }
20167 }21140 }
20168 IrInstruction *result = ir_build_struct_field_ptr(&ira->new_irb, source_instr->scope, source_instr->source_node,21141 return ir_build_struct_field_ptr(ira, source_instr, struct_ptr, field, ptr_type);
20169 struct_ptr, field);
20170 result->value->type = ptr_type;
20171 return result;
20172}21142}
2017321143
20174static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,21144static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,
20175 IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type)21145 IrInst* source_instr, IrInstGen *container_ptr, ZigType *container_type)
20176{21146{
20177 // The type of the field is not available until a store using this pointer happens.21147 // The type of the field is not available until a store using this pointer happens.
20178 // So, here we create a special pointer type which has the inferred struct type and21148 // 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...@@ -20195,12 +21165,11 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n
20195 if (instr_is_comptime(container_ptr)) {21165 if (instr_is_comptime(container_ptr)) {
20196 ZigValue *ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);21166 ZigValue *ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
20197 if (ptr_val == nullptr)21167 if (ptr_val == nullptr)
20198 return ira->codegen->invalid_instruction;21168 return ira->codegen->invalid_inst_gen;
2019921169
20200 IrInstruction *result;21170 IrInstGen *result;
20201 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {21171 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
20202 result = ir_build_cast(&ira->new_irb, source_instr->scope,21172 result = ir_build_cast(ira, source_instr, container_ptr_type, container_ptr, CastOpNoop);
20203 source_instr->source_node, container_ptr_type, container_ptr, CastOpNoop);
20204 } else {21173 } else {
20205 result = ir_const(ira, source_instr, field_ptr_type);21174 result = ir_const(ira, source_instr, field_ptr_type);
20206 }21175 }
...@@ -20209,14 +21178,11 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n...@@ -20209,14 +21178,11 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n
20209 return result;21178 return result;
20210 }21179 }
2021121180
20212 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope,21181 return ir_build_cast(ira, source_instr, field_ptr_type, container_ptr, CastOpNoop);
20213 source_instr->source_node, field_ptr_type, container_ptr, CastOpNoop);
20214 result->value->type = field_ptr_type;
20215 return result;
20216}21182}
2021721183
20218static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,21184static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,
20219 IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type, bool initializing)21185 IrInst* source_instr, IrInstGen *container_ptr, ZigType *container_type, bool initializing)
20220{21186{
20221 Error err;21187 Error err;
2022221188
...@@ -20229,7 +21195,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_...@@ -20229,7 +21195,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
20229 }21195 }
2023021196
20231 if ((err = type_resolve(ira->codegen, bare_type, ResolveStatusZeroBitsKnown)))21197 if ((err = type_resolve(ira->codegen, bare_type, ResolveStatusZeroBitsKnown)))
20232 return ira->codegen->invalid_instruction;21198 return ira->codegen->invalid_inst_gen;
2023321199
20234 assert(container_ptr->value->type->id == ZigTypeIdPointer);21200 assert(container_ptr->value->type->id == ZigTypeIdPointer);
20235 if (bare_type->id == ZigTypeIdStruct) {21201 if (bare_type->id == ZigTypeIdStruct) {
...@@ -20259,22 +21225,22 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_...@@ -20259,22 +21225,22 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
2025921225
20260 ZigType *field_type = resolve_union_field_type(ira->codegen, field);21226 ZigType *field_type = resolve_union_field_type(ira->codegen, field);
20261 if (field_type == nullptr)21227 if (field_type == nullptr)
20262 return ira->codegen->invalid_instruction;21228 return ira->codegen->invalid_inst_gen;
2026321229
20264 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type,21230 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type,
20265 is_const, is_volatile, PtrLenSingle, 0, 0, 0, false);21231 is_const, is_volatile, PtrLenSingle, 0, 0, 0, false);
20266 if (instr_is_comptime(container_ptr)) {21232 if (instr_is_comptime(container_ptr)) {
20267 ZigValue *ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);21233 ZigValue *ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
20268 if (!ptr_val)21234 if (!ptr_val)
20269 return ira->codegen->invalid_instruction;21235 return ira->codegen->invalid_inst_gen;
2027021236
20271 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar &&21237 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar &&
20272 ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {21238 ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
20273 ZigValue *union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);21239 ZigValue *union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
20274 if (union_val == nullptr)21240 if (union_val == nullptr)
20275 return ira->codegen->invalid_instruction;21241 return ira->codegen->invalid_inst_gen;
20276 if (type_is_invalid(union_val->type))21242 if (type_is_invalid(union_val->type))
20277 return ira->codegen->invalid_instruction;21243 return ira->codegen->invalid_inst_gen;
2027821244
20279 if (initializing) {21245 if (initializing) {
20280 ZigValue *payload_val = create_const_vals(1);21246 ZigValue *payload_val = create_const_vals(1);
...@@ -20295,17 +21261,16 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_...@@ -20295,17 +21261,16 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
20295 ir_add_error_node(ira, source_instr->source_node,21261 ir_add_error_node(ira, source_instr->source_node,
20296 buf_sprintf("accessing union field '%s' while field '%s' is set", buf_ptr(field_name),21262 buf_sprintf("accessing union field '%s' while field '%s' is set", buf_ptr(field_name),
20297 buf_ptr(actual_field->name)));21263 buf_ptr(actual_field->name)));
20298 return ira->codegen->invalid_instruction;21264 return ira->codegen->invalid_inst_gen;
20299 }21265 }
20300 }21266 }
2030121267
20302 ZigValue *payload_val = union_val->data.x_union.payload;21268 ZigValue *payload_val = union_val->data.x_union.payload;
2030321269
20304 IrInstruction *result;21270 IrInstGen *result;
20305 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {21271 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
20306 result = ir_build_union_field_ptr(&ira->new_irb, source_instr->scope,21272 result = ir_build_union_field_ptr(ira, source_instr, container_ptr, field, true,
20307 source_instr->source_node, container_ptr, field, true, initializing);21273 initializing, ptr_type);
20308 result->value->type = ptr_type;
20309 result->value->special = ConstValSpecialStatic;21274 result->value->special = ConstValSpecialStatic;
20310 } else {21275 } else {
20311 result = ir_const(ira, source_instr, ptr_type);21276 result = ir_const(ira, source_instr, ptr_type);
...@@ -20318,10 +21283,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_...@@ -20318,10 +21283,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
20318 }21283 }
20319 }21284 }
2032021285
20321 IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb, source_instr->scope,21286 return ir_build_union_field_ptr(ira, source_instr, container_ptr, field, true, initializing, ptr_type);
20322 source_instr->source_node, container_ptr, field, true, initializing);
20323 result->value->type = ptr_type;
20324 return result;
20325 }21287 }
2032621288
20327 zig_unreachable();21289 zig_unreachable();
...@@ -20362,15 +21324,15 @@ static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name,...@@ -20362,15 +21324,15 @@ static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name,
20362 link_lib->symbols.append(symbol_name);21324 link_lib->symbols.append(symbol_name);
20363}21325}
2036421326
20365static IrInstruction *ir_error_dependency_loop(IrAnalyze *ira, IrInstruction *source_instr) {21327static IrInstGen *ir_error_dependency_loop(IrAnalyze *ira, IrInst* source_instr) {
20366 ir_add_error(ira, source_instr, buf_sprintf("dependency loop detected"));21328 ir_add_error(ira, source_instr, buf_sprintf("dependency loop detected"));
20367 return ira->codegen->invalid_instruction;21329 return ira->codegen->invalid_inst_gen;
20368}21330}
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) {
20371 resolve_top_level_decl(ira->codegen, tld, source_instruction->source_node, true);21333 resolve_top_level_decl(ira->codegen, tld, source_instruction->source_node, true);
20372 if (tld->resolution == TldResolutionInvalid) {21334 if (tld->resolution == TldResolutionInvalid) {
20373 return ira->codegen->invalid_instruction;21335 return ira->codegen->invalid_inst_gen;
20374 }21336 }
2037521337
20376 switch (tld->id) {21338 switch (tld->id) {
...@@ -20397,14 +21359,13 @@ static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_...@@ -20397,14 +21359,13 @@ static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_
20397 assert(fn_entry->type_entry);21359 assert(fn_entry->type_entry);
2039821360
20399 if (type_is_invalid(fn_entry->type_entry))21361 if (type_is_invalid(fn_entry->type_entry))
20400 return ira->codegen->invalid_instruction;21362 return ira->codegen->invalid_inst_gen;
2040121363
20402 if (tld_fn->extern_lib_name != nullptr) {21364 if (tld_fn->extern_lib_name != nullptr) {
20403 add_link_lib_symbol(ira, tld_fn->extern_lib_name, &fn_entry->symbol_name, source_instruction->source_node);21365 add_link_lib_symbol(ira, tld_fn->extern_lib_name, &fn_entry->symbol_name, source_instruction->source_node);
20404 }21366 }
2040521367
20406 IrInstruction *fn_inst = ir_create_const_fn(&ira->new_irb, source_instruction->scope,21368 IrInstGen *fn_inst = ir_const_fn(ira, source_instruction, fn_entry);
20407 source_instruction->source_node, fn_entry);
20408 return ir_get_ref(ira, source_instruction, fn_inst, true, false);21369 return ir_get_ref(ira, source_instruction, fn_inst, true, false);
20409 }21370 }
20410 }21371 }
...@@ -20422,40 +21383,40 @@ static ErrorTableEntry *find_err_table_entry(ZigType *err_set_type, Buf *field_n...@@ -20422,40 +21383,40 @@ static ErrorTableEntry *find_err_table_entry(ZigType *err_set_type, Buf *field_n
20422 return nullptr;21383 return nullptr;
20423}21384}
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) {
20426 Error err;21387 Error err;
20427 IrInstruction *container_ptr = field_ptr_instruction->container_ptr->child;21388 IrInstGen *container_ptr = field_ptr_instruction->container_ptr->child;
20428 if (type_is_invalid(container_ptr->value->type))21389 if (type_is_invalid(container_ptr->value->type))
20429 return ira->codegen->invalid_instruction;21390 return ira->codegen->invalid_inst_gen;
2043021391
20431 ZigType *container_type = container_ptr->value->type->data.pointer.child_type;21392 ZigType *container_type = container_ptr->value->type->data.pointer.child_type;
2043221393
20433 Buf *field_name = field_ptr_instruction->field_name_buffer;21394 Buf *field_name = field_ptr_instruction->field_name_buffer;
20434 if (!field_name) {21395 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;
20436 field_name = ir_resolve_str(ira, field_name_expr);21397 field_name = ir_resolve_str(ira, field_name_expr);
20437 if (!field_name)21398 if (!field_name)
20438 return ira->codegen->invalid_instruction;21399 return ira->codegen->invalid_inst_gen;
20439 }21400 }
2044021401
2044121402
20442 AstNode *source_node = field_ptr_instruction->base.source_node;21403 AstNode *source_node = field_ptr_instruction->base.base.source_node;
2044321404
20444 if (type_is_invalid(container_type)) {21405 if (type_is_invalid(container_type)) {
20445 return ira->codegen->invalid_instruction;21406 return ira->codegen->invalid_inst_gen;
20446 } else if (is_tuple(container_type) && !field_ptr_instruction->initializing && buf_eql_str(field_name, "len")) {21407 } 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,
20448 container_type->data.structure.src_field_count);21409 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);
20450 } else if (is_slice(container_type) || is_container_ref(container_type)) {21411 } else if (is_slice(container_type) || is_container_ref(container_type)) {
20451 assert(container_ptr->value->type->id == ZigTypeIdPointer);21412 assert(container_ptr->value->type->id == ZigTypeIdPointer);
20452 if (container_type->id == ZigTypeIdPointer) {21413 if (container_type->id == ZigTypeIdPointer) {
20453 ZigType *bare_type = container_ref_type(container_type);21414 ZigType *bare_type = container_ref_type(container_type);
20454 IrInstruction *container_child = ir_get_deref(ira, &field_ptr_instruction->base, container_ptr, nullptr);21415 IrInstGen *container_child = ir_get_deref(ira, &field_ptr_instruction->base.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);21416 IrInstGen *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base.base, container_child, bare_type, field_ptr_instruction->initializing);
20456 return result;21417 return result;
20457 } else {21418 } 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);
20459 return result;21420 return result;
20460 }21421 }
20461 } else if (is_array_ref(container_type) && !field_ptr_instruction->initializing) {21422 } 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...@@ -20470,42 +21431,42 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
20470 ZigType *usize = ira->codegen->builtin_types.entry_usize;21431 ZigType *usize = ira->codegen->builtin_types.entry_usize;
20471 bool ptr_is_const = true;21432 bool ptr_is_const = true;
20472 bool ptr_is_volatile = false;21433 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,
20474 usize, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21435 usize, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
20475 } else {21436 } else {
20476 ir_add_error_node(ira, source_node,21437 ir_add_error_node(ira, source_node,
20477 buf_sprintf("no member named '%s' in '%s'", buf_ptr(field_name),21438 buf_sprintf("no member named '%s' in '%s'", buf_ptr(field_name),
20478 buf_ptr(&container_type->name)));21439 buf_ptr(&container_type->name)));
20479 return ira->codegen->invalid_instruction;21440 return ira->codegen->invalid_inst_gen;
20480 }21441 }
20481 } else if (container_type->id == ZigTypeIdMetaType) {21442 } else if (container_type->id == ZigTypeIdMetaType) {
20482 ZigValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);21443 ZigValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
20483 if (!container_ptr_val)21444 if (!container_ptr_val)
20484 return ira->codegen->invalid_instruction;21445 return ira->codegen->invalid_inst_gen;
2048521446
20486 assert(container_ptr->value->type->id == ZigTypeIdPointer);21447 assert(container_ptr->value->type->id == ZigTypeIdPointer);
20487 ZigValue *child_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val, source_node);21448 ZigValue *child_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val, source_node);
20488 if (child_val == nullptr)21449 if (child_val == nullptr)
20489 return ira->codegen->invalid_instruction;21450 return ira->codegen->invalid_inst_gen;
20490 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,21451 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)))
20492 {21453 {
20493 return ira->codegen->invalid_instruction;21454 return ira->codegen->invalid_inst_gen;
20494 }21455 }
20495 ZigType *child_type = child_val->data.x_type;21456 ZigType *child_type = child_val->data.x_type;
2049621457
20497 if (type_is_invalid(child_type)) {21458 if (type_is_invalid(child_type)) {
20498 return ira->codegen->invalid_instruction;21459 return ira->codegen->invalid_inst_gen;
20499 } else if (is_container(child_type)) {21460 } else if (is_container(child_type)) {
20500 if (child_type->id == ZigTypeIdEnum) {21461 if (child_type->id == ZigTypeIdEnum) {
20501 if ((err = type_resolve(ira->codegen, child_type, ResolveStatusSizeKnown)))21462 if ((err = type_resolve(ira->codegen, child_type, ResolveStatusSizeKnown)))
20502 return ira->codegen->invalid_instruction;21463 return ira->codegen->invalid_inst_gen;
2050321464
20504 TypeEnumField *field = find_enum_type_field(child_type, field_name);21465 TypeEnumField *field = find_enum_type_field(child_type, field_name);
20505 if (field) {21466 if (field) {
20506 bool ptr_is_const = true;21467 bool ptr_is_const = true;
20507 bool ptr_is_volatile = false;21468 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,
20509 create_const_enum(child_type, &field->value), child_type,21470 create_const_enum(child_type, &field->value), child_type,
20510 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21471 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
20511 }21472 }
...@@ -20514,37 +21475,37 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc...@@ -20514,37 +21475,37 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
20514 Tld *tld = find_container_decl(ira->codegen, container_scope, field_name);21475 Tld *tld = find_container_decl(ira->codegen, container_scope, field_name);
20515 if (tld) {21476 if (tld) {
20516 if (tld->visib_mod == VisibModPrivate &&21477 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))
20518 {21479 {
20519 ErrorMsg *msg = ir_add_error(ira, &field_ptr_instruction->base,21480 ErrorMsg *msg = ir_add_error(ira, &field_ptr_instruction->base.base,
20520 buf_sprintf("'%s' is private", buf_ptr(field_name)));21481 buf_sprintf("'%s' is private", buf_ptr(field_name)));
20521 add_error_note(ira->codegen, msg, tld->source_node, buf_sprintf("declared here"));21482 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;
20523 }21484 }
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);
20525 }21486 }
20526 if (child_type->id == ZigTypeIdUnion &&21487 if (child_type->id == ZigTypeIdUnion &&
20527 (child_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr ||21488 (child_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr ||
20528 child_type->data.unionation.decl_node->data.container_decl.auto_enum))21489 child_type->data.unionation.decl_node->data.container_decl.auto_enum))
20529 {21490 {
20530 if ((err = type_resolve(ira->codegen, child_type, ResolveStatusSizeKnown)))21491 if ((err = type_resolve(ira->codegen, child_type, ResolveStatusSizeKnown)))
20531 return ira->codegen->invalid_instruction;21492 return ira->codegen->invalid_inst_gen;
20532 TypeUnionField *field = find_union_type_field(child_type, field_name);21493 TypeUnionField *field = find_union_type_field(child_type, field_name);
20533 if (field) {21494 if (field) {
20534 ZigType *enum_type = child_type->data.unionation.tag_type;21495 ZigType *enum_type = child_type->data.unionation.tag_type;
20535 bool ptr_is_const = true;21496 bool ptr_is_const = true;
20536 bool ptr_is_volatile = false;21497 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,
20538 create_const_enum(enum_type, &field->enum_field->value), enum_type,21499 create_const_enum(enum_type, &field->enum_field->value), enum_type,
20539 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21500 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
20540 }21501 }
20541 }21502 }
20542 const char *container_name = (child_type == ira->codegen->root_import) ?21503 const char *container_name = (child_type == ira->codegen->root_import) ?
20543 "root source file" : buf_ptr(buf_sprintf("container '%s'", buf_ptr(&child_type->name)));21504 "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,
20545 buf_sprintf("%s has no member called '%s'",21506 buf_sprintf("%s has no member called '%s'",
20546 container_name, buf_ptr(field_name)));21507 container_name, buf_ptr(field_name)));
20547 return ira->codegen->invalid_instruction;21508 return ira->codegen->invalid_inst_gen;
20548 } else if (child_type->id == ZigTypeIdErrorSet) {21509 } else if (child_type->id == ZigTypeIdErrorSet) {
20549 ErrorTableEntry *err_entry;21510 ErrorTableEntry *err_entry;
20550 ZigType *err_set_type;21511 ZigType *err_set_type;
...@@ -20554,7 +21515,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc...@@ -20554,7 +21515,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
20554 err_entry = existing_entry->value;21515 err_entry = existing_entry->value;
20555 } else {21516 } else {
20556 err_entry = allocate<ErrorTableEntry>(1);21517 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;
20558 buf_init_from_buf(&err_entry->name, field_name);21519 buf_init_from_buf(&err_entry->name, field_name);
20559 size_t error_value_count = ira->codegen->errors_by_index.length;21520 size_t error_value_count = ira->codegen->errors_by_index.length;
20560 assert((uint32_t)error_value_count < (((uint32_t)1) << (uint32_t)ira->codegen->err_tag_type->data.integral.bit_count));21521 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...@@ -20564,19 +21525,19 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
20564 }21525 }
20565 if (err_entry->set_with_only_this_in_it == nullptr) {21526 if (err_entry->set_with_only_this_in_it == nullptr) {
20566 err_entry->set_with_only_this_in_it = make_err_set_with_one_item(ira->codegen,21527 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,
20568 err_entry);21529 err_entry);
20569 }21530 }
20570 err_set_type = err_entry->set_with_only_this_in_it;21531 err_set_type = err_entry->set_with_only_this_in_it;
20571 } else {21532 } else {
20572 if (!resolve_inferred_error_set(ira->codegen, child_type, field_ptr_instruction->base.source_node)) {21533 if (!resolve_inferred_error_set(ira->codegen, child_type, field_ptr_instruction->base.base.source_node)) {
20573 return ira->codegen->invalid_instruction;21534 return ira->codegen->invalid_inst_gen;
20574 }21535 }
20575 err_entry = find_err_table_entry(child_type, field_name);21536 err_entry = find_err_table_entry(child_type, field_name);
20576 if (err_entry == nullptr) {21537 if (err_entry == nullptr) {
20577 ir_add_error(ira, &field_ptr_instruction->base,21538 ir_add_error(ira, &field_ptr_instruction->base.base,
20578 buf_sprintf("no error named '%s' in '%s'", buf_ptr(field_name), buf_ptr(&child_type->name)));21539 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;
20580 }21541 }
20581 err_set_type = child_type;21542 err_set_type = child_type;
20582 }21543 }
...@@ -20587,13 +21548,13 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc...@@ -20587,13 +21548,13 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
2058721548
20588 bool ptr_is_const = true;21549 bool ptr_is_const = true;
20589 bool ptr_is_volatile = false;21550 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,
20591 err_set_type, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21552 err_set_type, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
20592 } else if (child_type->id == ZigTypeIdInt) {21553 } else if (child_type->id == ZigTypeIdInt) {
20593 if (buf_eql_str(field_name, "bit_count")) {21554 if (buf_eql_str(field_name, "bit_count")) {
20594 bool ptr_is_const = true;21555 bool ptr_is_const = true;
20595 bool ptr_is_volatile = false;21556 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,
20597 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,21558 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,
20598 child_type->data.integral.bit_count, false),21559 child_type->data.integral.bit_count, false),
20599 ira->codegen->builtin_types.entry_num_lit_int,21560 ira->codegen->builtin_types.entry_num_lit_int,
...@@ -20601,36 +21562,36 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc...@@ -20601,36 +21562,36 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
20601 } else if (buf_eql_str(field_name, "is_signed")) {21562 } else if (buf_eql_str(field_name, "is_signed")) {
20602 bool ptr_is_const = true;21563 bool ptr_is_const = true;
20603 bool ptr_is_volatile = false;21564 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,
20605 create_const_bool(ira->codegen, child_type->data.integral.is_signed),21566 create_const_bool(ira->codegen, child_type->data.integral.is_signed),
20606 ira->codegen->builtin_types.entry_bool,21567 ira->codegen->builtin_types.entry_bool,
20607 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21568 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
20608 } else {21569 } else {
20609 ir_add_error(ira, &field_ptr_instruction->base,21570 ir_add_error(ira, &field_ptr_instruction->base.base,
20610 buf_sprintf("type '%s' has no member called '%s'",21571 buf_sprintf("type '%s' has no member called '%s'",
20611 buf_ptr(&child_type->name), buf_ptr(field_name)));21572 buf_ptr(&child_type->name), buf_ptr(field_name)));
20612 return ira->codegen->invalid_instruction;21573 return ira->codegen->invalid_inst_gen;
20613 }21574 }
20614 } else if (child_type->id == ZigTypeIdFloat) {21575 } else if (child_type->id == ZigTypeIdFloat) {
20615 if (buf_eql_str(field_name, "bit_count")) {21576 if (buf_eql_str(field_name, "bit_count")) {
20616 bool ptr_is_const = true;21577 bool ptr_is_const = true;
20617 bool ptr_is_volatile = false;21578 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,
20619 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,21580 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,
20620 child_type->data.floating.bit_count, false),21581 child_type->data.floating.bit_count, false),
20621 ira->codegen->builtin_types.entry_num_lit_int,21582 ira->codegen->builtin_types.entry_num_lit_int,
20622 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21583 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
20623 } else {21584 } else {
20624 ir_add_error(ira, &field_ptr_instruction->base,21585 ir_add_error(ira, &field_ptr_instruction->base.base,
20625 buf_sprintf("type '%s' has no member called '%s'",21586 buf_sprintf("type '%s' has no member called '%s'",
20626 buf_ptr(&child_type->name), buf_ptr(field_name)));21587 buf_ptr(&child_type->name), buf_ptr(field_name)));
20627 return ira->codegen->invalid_instruction;21588 return ira->codegen->invalid_inst_gen;
20628 }21589 }
20629 } else if (child_type->id == ZigTypeIdPointer) {21590 } else if (child_type->id == ZigTypeIdPointer) {
20630 if (buf_eql_str(field_name, "Child")) {21591 if (buf_eql_str(field_name, "Child")) {
20631 bool ptr_is_const = true;21592 bool ptr_is_const = true;
20632 bool ptr_is_volatile = false;21593 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,
20634 create_const_type(ira->codegen, child_type->data.pointer.child_type),21595 create_const_type(ira->codegen, child_type->data.pointer.child_type),
20635 ira->codegen->builtin_types.entry_type,21596 ira->codegen->builtin_types.entry_type,
20636 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21597 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
...@@ -20640,75 +21601,75 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc...@@ -20640,75 +21601,75 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
20640 if ((err = type_resolve(ira->codegen, child_type->data.pointer.child_type,21601 if ((err = type_resolve(ira->codegen, child_type->data.pointer.child_type,
20641 ResolveStatusAlignmentKnown)))21602 ResolveStatusAlignmentKnown)))
20642 {21603 {
20643 return ira->codegen->invalid_instruction;21604 return ira->codegen->invalid_inst_gen;
20644 }21605 }
20645 return ir_get_const_ptr(ira, &field_ptr_instruction->base,21606 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
20646 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,21607 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,
20647 get_ptr_align(ira->codegen, child_type), false),21608 get_ptr_align(ira->codegen, child_type), false),
20648 ira->codegen->builtin_types.entry_num_lit_int,21609 ira->codegen->builtin_types.entry_num_lit_int,
20649 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21610 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
20650 } else {21611 } else {
20651 ir_add_error(ira, &field_ptr_instruction->base,21612 ir_add_error(ira, &field_ptr_instruction->base.base,
20652 buf_sprintf("type '%s' has no member called '%s'",21613 buf_sprintf("type '%s' has no member called '%s'",
20653 buf_ptr(&child_type->name), buf_ptr(field_name)));21614 buf_ptr(&child_type->name), buf_ptr(field_name)));
20654 return ira->codegen->invalid_instruction;21615 return ira->codegen->invalid_inst_gen;
20655 }21616 }
20656 } else if (child_type->id == ZigTypeIdArray) {21617 } else if (child_type->id == ZigTypeIdArray) {
20657 if (buf_eql_str(field_name, "Child")) {21618 if (buf_eql_str(field_name, "Child")) {
20658 bool ptr_is_const = true;21619 bool ptr_is_const = true;
20659 bool ptr_is_volatile = false;21620 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,
20661 create_const_type(ira->codegen, child_type->data.array.child_type),21622 create_const_type(ira->codegen, child_type->data.array.child_type),
20662 ira->codegen->builtin_types.entry_type,21623 ira->codegen->builtin_types.entry_type,
20663 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21624 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
20664 } else if (buf_eql_str(field_name, "len")) {21625 } else if (buf_eql_str(field_name, "len")) {
20665 bool ptr_is_const = true;21626 bool ptr_is_const = true;
20666 bool ptr_is_volatile = false;21627 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,
20668 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,21629 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,
20669 child_type->data.array.len, false),21630 child_type->data.array.len, false),
20670 ira->codegen->builtin_types.entry_num_lit_int,21631 ira->codegen->builtin_types.entry_num_lit_int,
20671 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21632 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
20672 } else {21633 } else {
20673 ir_add_error(ira, &field_ptr_instruction->base,21634 ir_add_error(ira, &field_ptr_instruction->base.base,
20674 buf_sprintf("type '%s' has no member called '%s'",21635 buf_sprintf("type '%s' has no member called '%s'",
20675 buf_ptr(&child_type->name), buf_ptr(field_name)));21636 buf_ptr(&child_type->name), buf_ptr(field_name)));
20676 return ira->codegen->invalid_instruction;21637 return ira->codegen->invalid_inst_gen;
20677 }21638 }
20678 } else if (child_type->id == ZigTypeIdErrorUnion) {21639 } else if (child_type->id == ZigTypeIdErrorUnion) {
20679 if (buf_eql_str(field_name, "Payload")) {21640 if (buf_eql_str(field_name, "Payload")) {
20680 bool ptr_is_const = true;21641 bool ptr_is_const = true;
20681 bool ptr_is_volatile = false;21642 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,
20683 create_const_type(ira->codegen, child_type->data.error_union.payload_type),21644 create_const_type(ira->codegen, child_type->data.error_union.payload_type),
20684 ira->codegen->builtin_types.entry_type,21645 ira->codegen->builtin_types.entry_type,
20685 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21646 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
20686 } else if (buf_eql_str(field_name, "ErrorSet")) {21647 } else if (buf_eql_str(field_name, "ErrorSet")) {
20687 bool ptr_is_const = true;21648 bool ptr_is_const = true;
20688 bool ptr_is_volatile = false;21649 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,
20690 create_const_type(ira->codegen, child_type->data.error_union.err_set_type),21651 create_const_type(ira->codegen, child_type->data.error_union.err_set_type),
20691 ira->codegen->builtin_types.entry_type,21652 ira->codegen->builtin_types.entry_type,
20692 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21653 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
20693 } else {21654 } else {
20694 ir_add_error(ira, &field_ptr_instruction->base,21655 ir_add_error(ira, &field_ptr_instruction->base.base,
20695 buf_sprintf("type '%s' has no member called '%s'",21656 buf_sprintf("type '%s' has no member called '%s'",
20696 buf_ptr(&child_type->name), buf_ptr(field_name)));21657 buf_ptr(&child_type->name), buf_ptr(field_name)));
20697 return ira->codegen->invalid_instruction;21658 return ira->codegen->invalid_inst_gen;
20698 }21659 }
20699 } else if (child_type->id == ZigTypeIdOptional) {21660 } else if (child_type->id == ZigTypeIdOptional) {
20700 if (buf_eql_str(field_name, "Child")) {21661 if (buf_eql_str(field_name, "Child")) {
20701 bool ptr_is_const = true;21662 bool ptr_is_const = true;
20702 bool ptr_is_volatile = false;21663 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,
20704 create_const_type(ira->codegen, child_type->data.maybe.child_type),21665 create_const_type(ira->codegen, child_type->data.maybe.child_type),
20705 ira->codegen->builtin_types.entry_type,21666 ira->codegen->builtin_types.entry_type,
20706 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21667 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
20707 } else {21668 } else {
20708 ir_add_error(ira, &field_ptr_instruction->base,21669 ir_add_error(ira, &field_ptr_instruction->base.base,
20709 buf_sprintf("type '%s' has no member called '%s'",21670 buf_sprintf("type '%s' has no member called '%s'",
20710 buf_ptr(&child_type->name), buf_ptr(field_name)));21671 buf_ptr(&child_type->name), buf_ptr(field_name)));
20711 return ira->codegen->invalid_instruction;21672 return ira->codegen->invalid_inst_gen;
20712 }21673 }
20713 } else if (child_type->id == ZigTypeIdFn) {21674 } else if (child_type->id == ZigTypeIdFn) {
20714 if (buf_eql_str(field_name, "ReturnType")) {21675 if (buf_eql_str(field_name, "ReturnType")) {
...@@ -20716,121 +21677,121 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc...@@ -20716,121 +21677,121 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
20716 // Return type can only ever be null, if the function is generic21677 // Return type can only ever be null, if the function is generic
20717 assert(child_type->data.fn.is_generic);21678 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,
20720 buf_sprintf("ReturnType has not been resolved because '%s' is generic", buf_ptr(&child_type->name)));21681 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;
20722 }21683 }
2072321684
20724 bool ptr_is_const = true;21685 bool ptr_is_const = true;
20725 bool ptr_is_volatile = false;21686 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,
20727 create_const_type(ira->codegen, child_type->data.fn.fn_type_id.return_type),21688 create_const_type(ira->codegen, child_type->data.fn.fn_type_id.return_type),
20728 ira->codegen->builtin_types.entry_type,21689 ira->codegen->builtin_types.entry_type,
20729 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21690 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
20730 } else if (buf_eql_str(field_name, "is_var_args")) {21691 } else if (buf_eql_str(field_name, "is_var_args")) {
20731 bool ptr_is_const = true;21692 bool ptr_is_const = true;
20732 bool ptr_is_volatile = false;21693 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,
20734 create_const_bool(ira->codegen, child_type->data.fn.fn_type_id.is_var_args),21695 create_const_bool(ira->codegen, child_type->data.fn.fn_type_id.is_var_args),
20735 ira->codegen->builtin_types.entry_bool,21696 ira->codegen->builtin_types.entry_bool,
20736 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21697 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
20737 } else if (buf_eql_str(field_name, "arg_count")) {21698 } else if (buf_eql_str(field_name, "arg_count")) {
20738 bool ptr_is_const = true;21699 bool ptr_is_const = true;
20739 bool ptr_is_volatile = false;21700 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,
20741 create_const_usize(ira->codegen, child_type->data.fn.fn_type_id.param_count),21702 create_const_usize(ira->codegen, child_type->data.fn.fn_type_id.param_count),
20742 ira->codegen->builtin_types.entry_usize,21703 ira->codegen->builtin_types.entry_usize,
20743 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21704 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
20744 } else {21705 } else {
20745 ir_add_error(ira, &field_ptr_instruction->base,21706 ir_add_error(ira, &field_ptr_instruction->base.base,
20746 buf_sprintf("type '%s' has no member called '%s'",21707 buf_sprintf("type '%s' has no member called '%s'",
20747 buf_ptr(&child_type->name), buf_ptr(field_name)));21708 buf_ptr(&child_type->name), buf_ptr(field_name)));
20748 return ira->codegen->invalid_instruction;21709 return ira->codegen->invalid_inst_gen;
20749 }21710 }
20750 } else {21711 } else {
20751 ir_add_error(ira, &field_ptr_instruction->base,21712 ir_add_error(ira, &field_ptr_instruction->base.base,
20752 buf_sprintf("type '%s' does not support field access", buf_ptr(&child_type->name)));21713 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;
20754 }21715 }
20755 } else if (field_ptr_instruction->initializing) {21716 } 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,
20757 buf_sprintf("type '%s' does not support struct initialization syntax", buf_ptr(&container_type->name)));21718 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;
20759 } else {21720 } 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,
20761 buf_sprintf("type '%s' does not support field access", buf_ptr(&container_type->name)));21722 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;
20763 }21724 }
20764}21725}
2076521726
20766static IrInstruction *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstructionStorePtr *instruction) {21727static IrInstGen *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstSrcStorePtr *instruction) {
20767 IrInstruction *ptr = instruction->ptr->child;21728 IrInstGen *ptr = instruction->ptr->child;
20768 if (type_is_invalid(ptr->value->type))21729 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;
20772 if (type_is_invalid(value->value->type))21733 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);
20776}21737}
2077721738
20778static IrInstruction *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstructionLoadPtr *instruction) {21739static IrInstGen *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstSrcLoadPtr *instruction) {
20779 IrInstruction *ptr = instruction->ptr->child;21740 IrInstGen *ptr = instruction->ptr->child;
20780 if (type_is_invalid(ptr->value->type))21741 if (type_is_invalid(ptr->value->type))
20781 return ira->codegen->invalid_instruction;21742 return ira->codegen->invalid_inst_gen;
20782 return ir_get_deref(ira, &instruction->base, ptr, nullptr);21743 return ir_get_deref(ira, &instruction->base.base, ptr, nullptr);
20783}21744}
2078421745
20785static IrInstruction *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructionTypeOf *typeof_instruction) {21746static IrInstGen *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstSrcTypeOf *typeof_instruction) {
20786 IrInstruction *expr_value = typeof_instruction->value->child;21747 IrInstGen *expr_value = typeof_instruction->value->child;
20787 ZigType *type_entry = expr_value->value->type;21748 ZigType *type_entry = expr_value->value->type;
20788 if (type_is_invalid(type_entry))21749 if (type_is_invalid(type_entry))
20789 return ira->codegen->invalid_instruction;21750 return ira->codegen->invalid_inst_gen;
20790 return ir_const_type(ira, &typeof_instruction->base, type_entry);21751 return ir_const_type(ira, &typeof_instruction->base.base, type_entry);
20791}21752}
2079221753
20793static IrInstruction *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstructionSetCold *instruction) {21754static IrInstGen *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstSrcSetCold *instruction) {
20794 if (ira->new_irb.exec->is_inline) {21755 if (ira->new_irb.exec->is_inline) {
20795 // ignore setCold when running functions at compile time21756 // 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);
20797 }21758 }
2079821759
20799 IrInstruction *is_cold_value = instruction->is_cold->child;21760 IrInstGen *is_cold_value = instruction->is_cold->child;
20800 bool want_cold;21761 bool want_cold;
20801 if (!ir_resolve_bool(ira, is_cold_value, &want_cold))21762 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);
20805 if (fn_entry == nullptr) {21766 if (fn_entry == nullptr) {
20806 ir_add_error(ira, &instruction->base, buf_sprintf("@setCold outside function"));21767 ir_add_error(ira, &instruction->base.base, buf_sprintf("@setCold outside function"));
20807 return ira->codegen->invalid_instruction;21768 return ira->codegen->invalid_inst_gen;
20808 }21769 }
2080921770
20810 if (fn_entry->set_cold_node != nullptr) {21771 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"));
20812 add_error_note(ira->codegen, msg, fn_entry->set_cold_node, buf_sprintf("first set here"));21773 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;
20814 }21775 }
2081521776
20816 fn_entry->set_cold_node = instruction->base.source_node;21777 fn_entry->set_cold_node = instruction->base.base.source_node;
20817 fn_entry->is_cold = want_cold;21778 fn_entry->is_cold = want_cold;
2081821779
20819 return ir_const_void(ira, &instruction->base);21780 return ir_const_void(ira, &instruction->base.base);
20820}21781}
2082121782
20822static IrInstruction *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,21783static IrInstGen *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,
20823 IrInstructionSetRuntimeSafety *set_runtime_safety_instruction)21784 IrInstSrcSetRuntimeSafety *set_runtime_safety_instruction)
20824{21785{
20825 if (ira->new_irb.exec->is_inline) {21786 if (ira->new_irb.exec->is_inline) {
20826 // ignore setRuntimeSafety when running functions at compile time21787 // 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);
20828 }21789 }
2082921790
20830 bool *safety_off_ptr;21791 bool *safety_off_ptr;
20831 AstNode **safety_set_node_ptr;21792 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;
20834 while (scope != nullptr) {21795 while (scope != nullptr) {
20835 if (scope->id == ScopeIdBlock) {21796 if (scope->id == ScopeIdBlock) {
20836 ScopeBlock *block_scope = (ScopeBlock *)scope;21797 ScopeBlock *block_scope = (ScopeBlock *)scope;
...@@ -20856,36 +21817,36 @@ static IrInstruction *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,...@@ -20856,36 +21817,36 @@ static IrInstruction *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,
20856 }21817 }
20857 assert(scope != nullptr);21818 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;
20860 bool want_runtime_safety;21821 bool want_runtime_safety;
20861 if (!ir_resolve_bool(ira, safety_on_value, &want_runtime_safety))21822 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;
20865 if (*safety_set_node_ptr) {21826 if (*safety_set_node_ptr) {
20866 ErrorMsg *msg = ir_add_error_node(ira, source_node,21827 ErrorMsg *msg = ir_add_error_node(ira, source_node,
20867 buf_sprintf("runtime safety set twice for same scope"));21828 buf_sprintf("runtime safety set twice for same scope"));
20868 add_error_note(ira->codegen, msg, *safety_set_node_ptr, buf_sprintf("first set here"));21829 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;
20870 }21831 }
20871 *safety_set_node_ptr = source_node;21832 *safety_set_node_ptr = source_node;
20872 *safety_off_ptr = !want_runtime_safety;21833 *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);
20875}21836}
2087621837
20877static IrInstruction *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,21838static IrInstGen *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
20878 IrInstructionSetFloatMode *instruction)21839 IrInstSrcSetFloatMode *instruction)
20879{21840{
20880 if (ira->new_irb.exec->is_inline) {21841 if (ira->new_irb.exec->is_inline) {
20881 // ignore setFloatMode when running functions at compile time21842 // 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);
20883 }21844 }
2088421845
20885 bool *fast_math_on_ptr;21846 bool *fast_math_on_ptr;
20886 AstNode **fast_math_set_node_ptr;21847 AstNode **fast_math_set_node_ptr;
2088721848
20888 Scope *scope = instruction->base.scope;21849 Scope *scope = instruction->base.base.scope;
20889 while (scope != nullptr) {21850 while (scope != nullptr) {
20890 if (scope->id == ScopeIdBlock) {21851 if (scope->id == ScopeIdBlock) {
20891 ScopeBlock *block_scope = (ScopeBlock *)scope;21852 ScopeBlock *block_scope = (ScopeBlock *)scope;
...@@ -20911,42 +21872,38 @@ static IrInstruction *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,...@@ -20911,42 +21872,38 @@ static IrInstruction *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
20911 }21872 }
20912 assert(scope != nullptr);21873 assert(scope != nullptr);
2091321874
20914 IrInstruction *float_mode_value = instruction->mode_value->child;21875 IrInstGen *float_mode_value = instruction->mode_value->child;
20915 FloatMode float_mode_scalar;21876 FloatMode float_mode_scalar;
20916 if (!ir_resolve_float_mode(ira, float_mode_value, &float_mode_scalar))21877 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;
20920 if (*fast_math_set_node_ptr) {21881 if (*fast_math_set_node_ptr) {
20921 ErrorMsg *msg = ir_add_error_node(ira, source_node,21882 ErrorMsg *msg = ir_add_error_node(ira, source_node,
20922 buf_sprintf("float mode set twice for same scope"));21883 buf_sprintf("float mode set twice for same scope"));
20923 add_error_note(ira->codegen, msg, *fast_math_set_node_ptr, buf_sprintf("first set here"));21884 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;
20925 }21886 }
20926 *fast_math_set_node_ptr = source_node;21887 *fast_math_set_node_ptr = source_node;
20927 *fast_math_on_ptr = (float_mode_scalar == FloatModeOptimized);21888 *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);
20930}21891}
2093121892
20932static IrInstruction *ir_analyze_instruction_any_frame_type(IrAnalyze *ira,21893static IrInstGen *ir_analyze_instruction_any_frame_type(IrAnalyze *ira, IrInstSrcAnyFrameType *instruction) {
20933 IrInstructionAnyFrameType *instruction)
20934{
20935 ZigType *payload_type = nullptr;21894 ZigType *payload_type = nullptr;
20936 if (instruction->payload_type != nullptr) {21895 if (instruction->payload_type != nullptr) {
20937 payload_type = ir_resolve_type(ira, instruction->payload_type->child);21896 payload_type = ir_resolve_type(ira, instruction->payload_type->child);
20938 if (type_is_invalid(payload_type))21897 if (type_is_invalid(payload_type))
20939 return ira->codegen->invalid_instruction;21898 return ira->codegen->invalid_inst_gen;
20940 }21899 }
2094121900
20942 ZigType *any_frame_type = get_any_frame_type(ira->codegen, payload_type);21901 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);
20944}21903}
2094521904
20946static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira,21905static IrInstGen *ir_analyze_instruction_slice_type(IrAnalyze *ira, IrInstSrcSliceType *slice_type_instruction) {
20947 IrInstructionSliceType *slice_type_instruction)21906 IrInstGen *result = ir_const(ira, &slice_type_instruction->base.base, ira->codegen->builtin_types.entry_type);
20948{
20949 IrInstruction *result = ir_const(ira, &slice_type_instruction->base, ira->codegen->builtin_types.entry_type);
20950 result->value->special = ConstValSpecialLazy;21907 result->value->special = ConstValSpecialLazy;
2095121908
20952 LazyValueSliceType *lazy_slice_type = allocate<LazyValueSliceType>(1, "LazyValueSliceType");21909 LazyValueSliceType *lazy_slice_type = allocate<LazyValueSliceType>(1, "LazyValueSliceType");
...@@ -20957,18 +21914,18 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira,...@@ -20957,18 +21914,18 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira,
20957 if (slice_type_instruction->align_value != nullptr) {21914 if (slice_type_instruction->align_value != nullptr) {
20958 lazy_slice_type->align_inst = slice_type_instruction->align_value->child;21915 lazy_slice_type->align_inst = slice_type_instruction->align_value->child;
20959 if (ir_resolve_const(ira, lazy_slice_type->align_inst, LazyOk) == nullptr)21916 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;
20961 }21918 }
2096221919
20963 if (slice_type_instruction->sentinel != nullptr) {21920 if (slice_type_instruction->sentinel != nullptr) {
20964 lazy_slice_type->sentinel = slice_type_instruction->sentinel->child;21921 lazy_slice_type->sentinel = slice_type_instruction->sentinel->child;
20965 if (ir_resolve_const(ira, lazy_slice_type->sentinel, LazyOk) == nullptr)21922 if (ir_resolve_const(ira, lazy_slice_type->sentinel, LazyOk) == nullptr)
20966 return ira->codegen->invalid_instruction;21923 return ira->codegen->invalid_inst_gen;
20967 }21924 }
2096821925
20969 lazy_slice_type->elem_type = slice_type_instruction->child_type->child;21926 lazy_slice_type->elem_type = slice_type_instruction->child_type->child;
20970 if (ir_resolve_type_lazy(ira, lazy_slice_type->elem_type) == nullptr)21927 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
20973 lazy_slice_type->is_const = slice_type_instruction->is_const;21930 lazy_slice_type->is_const = slice_type_instruction->is_const;
20974 lazy_slice_type->is_volatile = slice_type_instruction->is_volatile;21931 lazy_slice_type->is_volatile = slice_type_instruction->is_volatile;
...@@ -20977,31 +21934,31 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira,...@@ -20977,31 +21934,31 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira,
20977 return result;21934 return result;
20978}21935}
2097921936
20980static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAsmSrc *asm_instruction) {21937static IrInstGen *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstSrcAsm *asm_instruction) {
20981 Error err;21938 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;21942 AstNode *node = asm_instruction->base.base.source_node;
20986 AstNodeAsmExpr *asm_expr = &asm_instruction->base.source_node->data.asm_expr;21943 AstNodeAsmExpr *asm_expr = &asm_instruction->base.base.source_node->data.asm_expr;
2098721944
20988 Buf *template_buf = ir_resolve_str(ira, asm_instruction->asm_template->child);21945 Buf *template_buf = ir_resolve_str(ira, asm_instruction->asm_template->child);
20989 if (template_buf == nullptr)21946 if (template_buf == nullptr)
20990 return ira->codegen->invalid_instruction;21947 return ira->codegen->invalid_inst_gen;
2099121948
20992 if (asm_instruction->is_global) {21949 if (asm_instruction->is_global) {
20993 buf_append_char(&ira->codegen->global_asm, '\n');21950 buf_append_char(&ira->codegen->global_asm, '\n');
20994 buf_append_buf(&ira->codegen->global_asm, template_buf);21951 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);
20997 }21954 }
2099821955
20999 if (!ir_emit_global_runtime_side_effect(ira, &asm_instruction->base))21956 if (!ir_emit_global_runtime_side_effect(ira, &asm_instruction->base.base))
21000 return ira->codegen->invalid_instruction;21957 return ira->codegen->invalid_inst_gen;
2100121958
21002 ZigList<AsmToken> tok_list = {};21959 ZigList<AsmToken> tok_list = {};
21003 if ((err = parse_asm_template(ira, node, template_buf, &tok_list))) {21960 if ((err = parse_asm_template(ira, node, template_buf, &tok_list))) {
21004 return ira->codegen->invalid_instruction;21961 return ira->codegen->invalid_inst_gen;
21005 }21962 }
2100621963
21007 for (size_t token_i = 0; token_i < tok_list.length; token_i += 1) {21964 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...@@ -21015,15 +21972,15 @@ static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAs
21015 add_node_error(ira->codegen, node,21972 add_node_error(ira->codegen, node,
21016 buf_sprintf("could not find '%.*s' in the inputs or outputs",21973 buf_sprintf("could not find '%.*s' in the inputs or outputs",
21017 len, ptr));21974 len, ptr));
21018 return ira->codegen->invalid_instruction;21975 return ira->codegen->invalid_inst_gen;
21019 }21976 }
21020 }21977 }
21021 }21978 }
2102221979
21023 // TODO validate the output types and variable types21980 // TODO validate the output types and variable types
2102421981
21025 IrInstruction **input_list = allocate<IrInstruction *>(asm_expr->input_list.length);21982 IrInstGen **input_list = allocate<IrInstGen *>(asm_expr->input_list.length);
21026 IrInstruction **output_types = allocate<IrInstruction *>(asm_expr->output_list.length);21983 IrInstGen **output_types = allocate<IrInstGen *>(asm_expr->output_list.length);
2102721984
21028 ZigType *return_type = ira->codegen->builtin_types.entry_void;21985 ZigType *return_type = ira->codegen->builtin_types.entry_void;
21029 for (size_t i = 0; i < asm_expr->output_list.length; i += 1) {21986 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...@@ -21032,39 +21989,34 @@ static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAs
21032 output_types[i] = asm_instruction->output_types[i]->child;21989 output_types[i] = asm_instruction->output_types[i]->child;
21033 return_type = ir_resolve_type(ira, output_types[i]);21990 return_type = ir_resolve_type(ira, output_types[i]);
21034 if (type_is_invalid(return_type))21991 if (type_is_invalid(return_type))
21035 return ira->codegen->invalid_instruction;21992 return ira->codegen->invalid_inst_gen;
21036 }21993 }
21037 }21994 }
2103821995
21039 for (size_t i = 0; i < asm_expr->input_list.length; i += 1) {21996 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;
21041 if (type_is_invalid(input_value->value->type))21998 if (type_is_invalid(input_value->value->type))
21042 return ira->codegen->invalid_instruction;21999 return ira->codegen->invalid_inst_gen;
2104322000
21044 if (instr_is_comptime(input_value) &&22001 if (instr_is_comptime(input_value) &&
21045 (input_value->value->type->id == ZigTypeIdComptimeInt ||22002 (input_value->value->type->id == ZigTypeIdComptimeInt ||
21046 input_value->value->type->id == ZigTypeIdComptimeFloat)) {22003 input_value->value->type->id == ZigTypeIdComptimeFloat)) {
21047 ir_add_error_node(ira, input_value->source_node,22004 ir_add_error(ira, &input_value->base,
21048 buf_sprintf("expected sized integer or sized float, found %s", buf_ptr(&input_value->value->type->name)));22005 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;
21050 }22007 }
2105122008
21052 input_list[i] = input_value;22009 input_list[i] = input_value;
21053 }22010 }
2105422011
21055 IrInstruction *result = ir_build_asm_gen(ira,22012 return ir_build_asm_gen(ira, &asm_instruction->base.base,
21056 asm_instruction->base.scope, asm_instruction->base.source_node,
21057 template_buf, tok_list.items, tok_list.length,22013 template_buf, tok_list.items, tok_list.length,
21058 input_list, output_types, asm_instruction->output_vars, asm_instruction->return_count,22014 input_list, output_types, asm_instruction->output_vars, asm_instruction->return_count,
21059 asm_instruction->has_side_effects);22015 asm_instruction->has_side_effects, return_type);
21060 result->value->type = return_type;
21061 return result;
21062}22016}
2106322017
21064static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira,22018static IrInstGen *ir_analyze_instruction_array_type(IrAnalyze *ira, IrInstSrcArrayType *array_type_instruction) {
21065 IrInstructionArrayType *array_type_instruction)22019 IrInstGen *result = ir_const(ira, &array_type_instruction->base.base, ira->codegen->builtin_types.entry_type);
21066{
21067 IrInstruction *result = ir_const(ira, &array_type_instruction->base, ira->codegen->builtin_types.entry_type);
21068 result->value->special = ConstValSpecialLazy;22020 result->value->special = ConstValSpecialLazy;
2106922021
21070 LazyValueArrayType *lazy_array_type = allocate<LazyValueArrayType>(1, "LazyValueArrayType");22022 LazyValueArrayType *lazy_array_type = allocate<LazyValueArrayType>(1, "LazyValueArrayType");
...@@ -21074,22 +22026,22 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira,...@@ -21074,22 +22026,22 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira,
2107422026
21075 lazy_array_type->elem_type = array_type_instruction->child_type->child;22027 lazy_array_type->elem_type = array_type_instruction->child_type->child;
21076 if (ir_resolve_type_lazy(ira, lazy_array_type->elem_type) == nullptr)22028 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
21079 if (!ir_resolve_usize(ira, array_type_instruction->size->child, &lazy_array_type->length))22031 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
21082 if (array_type_instruction->sentinel != nullptr) {22034 if (array_type_instruction->sentinel != nullptr) {
21083 lazy_array_type->sentinel = array_type_instruction->sentinel->child;22035 lazy_array_type->sentinel = array_type_instruction->sentinel->child;
21084 if (ir_resolve_const(ira, lazy_array_type->sentinel, LazyOk) == nullptr)22036 if (ir_resolve_const(ira, lazy_array_type->sentinel, LazyOk) == nullptr)
21085 return ira->codegen->invalid_instruction;22037 return ira->codegen->invalid_inst_gen;
21086 }22038 }
2108722039
21088 return result;22040 return result;
21089}22041}
2109022042
21091static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstructionSizeOf *instruction) {22043static IrInstGen *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstSrcSizeOf *instruction) {
21092 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int);22044 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int);
21093 result->value->special = ConstValSpecialLazy;22045 result->value->special = ConstValSpecialLazy;
2109422046
21095 LazyValueSizeOf *lazy_size_of = allocate<LazyValueSizeOf>(1, "LazyValueSizeOf");22047 LazyValueSizeOf *lazy_size_of = allocate<LazyValueSizeOf>(1, "LazyValueSizeOf");
...@@ -21100,19 +22052,19 @@ static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstructi...@@ -21100,19 +22052,19 @@ static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstructi
2110022052
21101 lazy_size_of->target_type = instruction->type_value->child;22053 lazy_size_of->target_type = instruction->type_value->child;
21102 if (ir_resolve_type_lazy(ira, lazy_size_of->target_type) == nullptr)22054 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
21105 return result;22057 return result;
21106}22058}
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) {
21109 ZigType *type_entry = value->value->type;22061 ZigType *type_entry = value->value->type;
2111022062
21111 if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.allow_zero) {22063 if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.allow_zero) {
21112 if (instr_is_comptime(value)) {22064 if (instr_is_comptime(value)) {
21113 ZigValue *c_ptr_val = ir_resolve_const(ira, value, UndefOk);22065 ZigValue *c_ptr_val = ir_resolve_const(ira, value, UndefOk);
21114 if (c_ptr_val == nullptr)22066 if (c_ptr_val == nullptr)
21115 return ira->codegen->invalid_instruction;22067 return ira->codegen->invalid_inst_gen;
21116 if (c_ptr_val->special == ConstValSpecialUndef)22068 if (c_ptr_val->special == ConstValSpecialUndef)
21117 return ir_const_undef(ira, source_inst, ira->codegen->builtin_types.entry_bool);22069 return ir_const_undef(ira, source_inst, ira->codegen->builtin_types.entry_bool);
21118 bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull ||22070 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...@@ -21121,25 +22073,19 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so
21121 return ir_const_bool(ira, source_inst, !is_null);22073 return ir_const_bool(ira, source_inst, !is_null);
21122 }22074 }
2112322075
21124 IrInstruction *result = ir_build_test_nonnull(&ira->new_irb,22076 return ir_build_test_non_null_gen(ira, source_inst, value);
21125 source_inst->scope, source_inst->source_node, value);
21126 result->value->type = ira->codegen->builtin_types.entry_bool;
21127 return result;
21128 } else if (type_entry->id == ZigTypeIdOptional) {22077 } else if (type_entry->id == ZigTypeIdOptional) {
21129 if (instr_is_comptime(value)) {22078 if (instr_is_comptime(value)) {
21130 ZigValue *maybe_val = ir_resolve_const(ira, value, UndefOk);22079 ZigValue *maybe_val = ir_resolve_const(ira, value, UndefOk);
21131 if (maybe_val == nullptr)22080 if (maybe_val == nullptr)
21132 return ira->codegen->invalid_instruction;22081 return ira->codegen->invalid_inst_gen;
21133 if (maybe_val->special == ConstValSpecialUndef)22082 if (maybe_val->special == ConstValSpecialUndef)
21134 return ir_const_undef(ira, source_inst, ira->codegen->builtin_types.entry_bool);22083 return ir_const_undef(ira, source_inst, ira->codegen->builtin_types.entry_bool);
2113522084
21136 return ir_const_bool(ira, source_inst, !optional_value_is_null(maybe_val));22085 return ir_const_bool(ira, source_inst, !optional_value_is_null(maybe_val));
21137 }22086 }
2113822087
21139 IrInstruction *result = ir_build_test_nonnull(&ira->new_irb,22088 return ir_build_test_non_null_gen(ira, source_inst, value);
21140 source_inst->scope, source_inst->source_node, value);
21141 result->value->type = ira->codegen->builtin_types.entry_bool;
21142 return result;
21143 } else if (type_entry->id == ZigTypeIdNull) {22089 } else if (type_entry->id == ZigTypeIdNull) {
21144 return ir_const_bool(ira, source_inst, false);22090 return ir_const_bool(ira, source_inst, false);
21145 } else {22091 } else {
...@@ -21147,51 +22093,51 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so...@@ -21147,51 +22093,51 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so
21147 }22093 }
21148}22094}
2114922095
21150static IrInstruction *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstructionTestNonNull *instruction) {22096static IrInstGen *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstSrcTestNonNull *instruction) {
21151 IrInstruction *value = instruction->value->child;22097 IrInstGen *value = instruction->value->child;
21152 if (type_is_invalid(value->value->type))22098 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);
21156}22102}
2115722103
21158static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstruction *source_instr,22104static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* source_instr,
21159 IrInstruction *base_ptr, bool safety_check_on, bool initializing)22105 IrInstGen *base_ptr, bool safety_check_on, bool initializing)
21160{22106{
21161 ZigType *type_entry = get_ptr_elem_type(ira->codegen, base_ptr);22107 ZigType *type_entry = get_ptr_elem_type(ira->codegen, base_ptr);
21162 if (type_is_invalid(type_entry))22108 if (type_is_invalid(type_entry))
21163 return ira->codegen->invalid_instruction;22109 return ira->codegen->invalid_inst_gen;
2116422110
21165 if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.ptr_len == PtrLenC) {22111 if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.ptr_len == PtrLenC) {
21166 if (instr_is_comptime(base_ptr)) {22112 if (instr_is_comptime(base_ptr)) {
21167 ZigValue *val = ir_resolve_const(ira, base_ptr, UndefBad);22113 ZigValue *val = ir_resolve_const(ira, base_ptr, UndefBad);
21168 if (!val)22114 if (!val)
21169 return ira->codegen->invalid_instruction;22115 return ira->codegen->invalid_inst_gen;
21170 if (val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {22116 if (val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
21171 ZigValue *c_ptr_val = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node);22117 ZigValue *c_ptr_val = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node);
21172 if (c_ptr_val == nullptr)22118 if (c_ptr_val == nullptr)
21173 return ira->codegen->invalid_instruction;22119 return ira->codegen->invalid_inst_gen;
21174 bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull ||22120 bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull ||
21175 (c_ptr_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&22121 (c_ptr_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&
21176 c_ptr_val->data.x_ptr.data.hard_coded_addr.addr == 0);22122 c_ptr_val->data.x_ptr.data.hard_coded_addr.addr == 0);
21177 if (is_null) {22123 if (is_null) {
21178 ir_add_error(ira, source_instr, buf_sprintf("unable to unwrap null"));22124 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;
21180 }22126 }
21181 return base_ptr;22127 return base_ptr;
21182 }22128 }
21183 }22129 }
21184 if (!safety_check_on)22130 if (!safety_check_on)
21185 return base_ptr;22131 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);
21187 ir_build_assert_non_null(ira, source_instr, c_ptr_val);22133 ir_build_assert_non_null(ira, source_instr, c_ptr_val);
21188 return base_ptr;22134 return base_ptr;
21189 }22135 }
2119022136
21191 if (type_entry->id != ZigTypeIdOptional) {22137 if (type_entry->id != ZigTypeIdOptional) {
21192 ir_add_error_node(ira, base_ptr->source_node,22138 ir_add_error(ira, &base_ptr->base,
21193 buf_sprintf("expected optional type, found '%s'", buf_ptr(&type_entry->name)));22139 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;
21195 }22141 }
2119622142
21197 ZigType *child_type = type_entry->data.maybe.child_type;22143 ZigType *child_type = type_entry->data.maybe.child_type;
...@@ -21204,16 +22150,16 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr...@@ -21204,16 +22150,16 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr
21204 if (instr_is_comptime(base_ptr)) {22150 if (instr_is_comptime(base_ptr)) {
21205 ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad);22151 ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad);
21206 if (!ptr_val)22152 if (!ptr_val)
21207 return ira->codegen->invalid_instruction;22153 return ira->codegen->invalid_inst_gen;
21208 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {22154 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
21209 ZigValue *optional_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);22155 ZigValue *optional_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
21210 if (optional_val == nullptr)22156 if (optional_val == nullptr)
21211 return ira->codegen->invalid_instruction;22157 return ira->codegen->invalid_inst_gen;
2121222158
21213 if (initializing) {22159 if (initializing) {
21214 switch (type_has_one_possible_value(ira->codegen, child_type)) {22160 switch (type_has_one_possible_value(ira->codegen, child_type)) {
21215 case OnePossibleValueInvalid:22161 case OnePossibleValueInvalid:
21216 return ira->codegen->invalid_instruction;22162 return ira->codegen->invalid_inst_gen;
21217 case OnePossibleValueNo:22163 case OnePossibleValueNo:
21218 if (!same_comptime_repr) {22164 if (!same_comptime_repr) {
21219 ZigValue *payload_val = create_const_vals(1);22165 ZigValue *payload_val = create_const_vals(1);
...@@ -21240,14 +22186,13 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr...@@ -21240,14 +22186,13 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr
21240 }22186 }
21241 } else if (optional_value_is_null(optional_val)) {22187 } else if (optional_value_is_null(optional_val)) {
21242 ir_add_error(ira, source_instr, buf_sprintf("unable to unwrap null"));22188 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;
21244 }22190 }
2124522191
21246 IrInstruction *result;22192 IrInstGen *result;
21247 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {22193 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
21248 result = ir_build_optional_unwrap_ptr(&ira->new_irb, source_instr->scope,22194 result = ir_build_optional_unwrap_ptr_gen(ira, source_instr, base_ptr, false,
21249 source_instr->source_node, base_ptr, false, initializing);22195 initializing, result_type);
21250 result->value->type = result_type;
21251 result->value->special = ConstValSpecialStatic;22196 result->value->special = ConstValSpecialStatic;
21252 } else {22197 } else {
21253 result = ir_const(ira, source_instr, result_type);22198 result = ir_const(ira, source_instr, result_type);
...@@ -21257,7 +22202,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr...@@ -21257,7 +22202,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr
21257 result_val->data.x_ptr.mut = ptr_val->data.x_ptr.mut;22202 result_val->data.x_ptr.mut = ptr_val->data.x_ptr.mut;
21258 switch (type_has_one_possible_value(ira->codegen, child_type)) {22203 switch (type_has_one_possible_value(ira->codegen, child_type)) {
21259 case OnePossibleValueInvalid:22204 case OnePossibleValueInvalid:
21260 return ira->codegen->invalid_instruction;22205 return ira->codegen->invalid_inst_gen;
21261 case OnePossibleValueNo:22206 case OnePossibleValueNo:
21262 if (same_comptime_repr) {22207 if (same_comptime_repr) {
21263 result_val->data.x_ptr.data.ref.pointee = optional_val;22208 result_val->data.x_ptr.data.ref.pointee = optional_val;
...@@ -21275,131 +22220,120 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr...@@ -21275,131 +22220,120 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr
21275 }22220 }
21276 }22221 }
2127722222
21278 IrInstruction *result = ir_build_optional_unwrap_ptr(&ira->new_irb, source_instr->scope,22223 return ir_build_optional_unwrap_ptr_gen(ira, source_instr, base_ptr, safety_check_on,
21279 source_instr->source_node, base_ptr, safety_check_on, initializing);22224 initializing, result_type);
21280 result->value->type = result_type;
21281 return result;
21282}22225}
2128322226
21284static IrInstruction *ir_analyze_instruction_optional_unwrap_ptr(IrAnalyze *ira,22227static IrInstGen *ir_analyze_instruction_optional_unwrap_ptr(IrAnalyze *ira,
21285 IrInstructionOptionalUnwrapPtr *instruction)22228 IrInstSrcOptionalUnwrapPtr *instruction)
21286{22229{
21287 IrInstruction *base_ptr = instruction->base_ptr->child;22230 IrInstGen *base_ptr = instruction->base_ptr->child;
21288 if (type_is_invalid(base_ptr->value->type))22231 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,
21292 instruction->safety_check_on, false);22235 instruction->safety_check_on, false);
21293}22236}
2129422237
21295static IrInstruction *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCtz *instruction) {22238static IrInstGen *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstSrcCtz *instruction) {
21296 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);22239 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);
21297 if (type_is_invalid(int_type))22240 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);
21301 if (type_is_invalid(op->value->type))22244 if (type_is_invalid(op->value->type))
21302 return ira->codegen->invalid_instruction;22245 return ira->codegen->invalid_inst_gen;
2130322246
21304 if (int_type->data.integral.bit_count == 0)22247 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
21307 if (instr_is_comptime(op)) {22250 if (instr_is_comptime(op)) {
21308 ZigValue *val = ir_resolve_const(ira, op, UndefOk);22251 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
21309 if (val == nullptr)22252 if (val == nullptr)
21310 return ira->codegen->invalid_instruction;22253 return ira->codegen->invalid_inst_gen;
21311 if (val->special == ConstValSpecialUndef)22254 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);
21313 size_t result_usize = bigint_ctz(&op->value->data.x_bigint, int_type->data.integral.bit_count);22256 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);
21315 }22258 }
2131622259
21317 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count);22260 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,22261 return ir_build_ctz_gen(ira, &instruction->base.base, return_type, op);
21319 instruction->base.source_node, nullptr, op);
21320 result->value->type = return_type;
21321 return result;
21322}22262}
2132322263
21324static IrInstruction *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionClz *instruction) {22264static IrInstGen *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstSrcClz *instruction) {
21325 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);22265 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);
21326 if (type_is_invalid(int_type))22266 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);
21330 if (type_is_invalid(op->value->type))22270 if (type_is_invalid(op->value->type))
21331 return ira->codegen->invalid_instruction;22271 return ira->codegen->invalid_inst_gen;
2133222272
21333 if (int_type->data.integral.bit_count == 0)22273 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
21336 if (instr_is_comptime(op)) {22276 if (instr_is_comptime(op)) {
21337 ZigValue *val = ir_resolve_const(ira, op, UndefOk);22277 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
21338 if (val == nullptr)22278 if (val == nullptr)
21339 return ira->codegen->invalid_instruction;22279 return ira->codegen->invalid_inst_gen;
21340 if (val->special == ConstValSpecialUndef)22280 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);
21342 size_t result_usize = bigint_clz(&op->value->data.x_bigint, int_type->data.integral.bit_count);22282 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);
21344 }22284 }
2134522285
21346 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count);22286 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,22287 return ir_build_clz_gen(ira, &instruction->base.base, return_type, op);
21348 instruction->base.source_node, nullptr, op);
21349 result->value->type = return_type;
21350 return result;
21351}22288}
2135222289
21353static IrInstruction *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstructionPopCount *instruction) {22290static IrInstGen *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstSrcPopCount *instruction) {
21354 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);22291 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);
21355 if (type_is_invalid(int_type))22292 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);
21359 if (type_is_invalid(op->value->type))22296 if (type_is_invalid(op->value->type))
21360 return ira->codegen->invalid_instruction;22297 return ira->codegen->invalid_inst_gen;
2136122298
21362 if (int_type->data.integral.bit_count == 0)22299 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
21365 if (instr_is_comptime(op)) {22302 if (instr_is_comptime(op)) {
21366 ZigValue *val = ir_resolve_const(ira, op, UndefOk);22303 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
21367 if (val == nullptr)22304 if (val == nullptr)
21368 return ira->codegen->invalid_instruction;22305 return ira->codegen->invalid_inst_gen;
21369 if (val->special == ConstValSpecialUndef)22306 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
21372 if (bigint_cmp_zero(&val->data.x_bigint) != CmpLT) {22309 if (bigint_cmp_zero(&val->data.x_bigint) != CmpLT) {
21373 size_t result = bigint_popcount_unsigned(&val->data.x_bigint);22310 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);
21375 }22312 }
21376 size_t result = bigint_popcount_signed(&val->data.x_bigint, int_type->data.integral.bit_count);22313 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);
21378 }22315 }
2137922316
21380 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count);22317 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,22318 return ir_build_pop_count_gen(ira, &instruction->base.base, return_type, op);
21382 instruction->base.source_node, nullptr, op);
21383 result->value->type = return_type;
21384 return result;
21385}22319}
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) {
21388 if (type_is_invalid(value->value->type))22322 if (type_is_invalid(value->value->type))
21389 return ira->codegen->invalid_instruction;22323 return ira->codegen->invalid_inst_gen;
2139022324
21391 if (value->value->type->id != ZigTypeIdUnion) {22325 if (value->value->type->id != ZigTypeIdUnion) {
21392 ir_add_error(ira, value,22326 ir_add_error(ira, &value->base,
21393 buf_sprintf("expected enum or union type, found '%s'", buf_ptr(&value->value->type->name)));22327 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;
21395 }22329 }
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) {
21397 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("union has no associated enum"));22331 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("union has no associated enum"));
21398 if (value->value->type->data.unionation.decl_node != nullptr) {22332 if (value->value->type->data.unionation.decl_node != nullptr) {
21399 add_error_note(ira->codegen, msg, value->value->type->data.unionation.decl_node,22333 add_error_note(ira->codegen, msg, value->value->type->data.unionation.decl_node,
21400 buf_sprintf("declared here"));22334 buf_sprintf("declared here"));
21401 }22335 }
21402 return ira->codegen->invalid_instruction;22336 return ira->codegen->invalid_inst_gen;
21403 }22337 }
2140422338
21405 ZigType *tag_type = value->value->type->data.unionation.tag_type;22339 ZigType *tag_type = value->value->type->data.unionation.tag_type;
...@@ -21408,9 +22342,9 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source...@@ -21408,9 +22342,9 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source
21408 if (instr_is_comptime(value)) {22342 if (instr_is_comptime(value)) {
21409 ZigValue *val = ir_resolve_const(ira, value, UndefBad);22343 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
21410 if (!val)22344 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,
21414 source_instr->scope, source_instr->source_node);22348 source_instr->scope, source_instr->source_node);
21415 const_instruction->base.value->type = tag_type;22349 const_instruction->base.value->type = tag_type;
21416 const_instruction->base.value->special = ConstValSpecialStatic;22350 const_instruction->base.value->special = ConstValSpecialStatic;
...@@ -21418,15 +22352,13 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source...@@ -21418,15 +22352,13 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source
21418 return &const_instruction->base;22352 return &const_instruction->base;
21419 }22353 }
2142022354
21421 IrInstruction *result = ir_build_union_tag(&ira->new_irb, source_instr->scope, source_instr->source_node, value);22355 return ir_build_union_tag(ira, source_instr, value, tag_type);
21422 result->value->type = tag_type;
21423 return result;
21424}22356}
2142522357
21426static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,22358static IrInstGen *ir_analyze_instruction_switch_br(IrAnalyze *ira,
21427 IrInstructionSwitchBr *switch_br_instruction)22359 IrInstSrcSwitchBr *switch_br_instruction)
21428{22360{
21429 IrInstruction *target_value = switch_br_instruction->target_value->child;22361 IrInstGen *target_value = switch_br_instruction->target_value->child;
21430 if (type_is_invalid(target_value->value->type))22362 if (type_is_invalid(target_value->value->type))
21431 return ir_unreach_error(ira);22363 return ir_unreach_error(ira);
2143222364
...@@ -21441,21 +22373,21 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,...@@ -21441,21 +22373,21 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,
2144122373
21442 bool is_comptime;22374 bool is_comptime;
21443 if (!ir_resolve_comptime(ira, switch_br_instruction->is_comptime->child, &is_comptime))22375 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
21446 if (is_comptime || instr_is_comptime(target_value)) {22378 if (is_comptime || instr_is_comptime(target_value)) {
21447 ZigValue *target_val = ir_resolve_const(ira, target_value, UndefBad);22379 ZigValue *target_val = ir_resolve_const(ira, target_value, UndefBad);
21448 if (!target_val)22380 if (!target_val)
21449 return ir_unreach_error(ira);22381 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;
21452 for (size_t i = 0; i < case_count; i += 1) {22384 for (size_t i = 0; i < case_count; i += 1) {
21453 IrInstructionSwitchBrCase *old_case = &switch_br_instruction->cases[i];22385 IrInstSrcSwitchBrCase *old_case = &switch_br_instruction->cases[i];
21454 IrInstruction *case_value = old_case->value->child;22386 IrInstGen *case_value = old_case->value->child;
21455 if (type_is_invalid(case_value->value->type))22387 if (type_is_invalid(case_value->value->type))
21456 return ir_unreach_error(ira);22388 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);
21459 if (type_is_invalid(casted_case_value->value->type))22391 if (type_is_invalid(casted_case_value->value->type))
21460 return ir_unreach_error(ira);22392 return ir_unreach_error(ira);
2146122393
...@@ -21470,23 +22402,20 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,...@@ -21470,23 +22402,20 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,
21470 }22402 }
2147122403
21472 if (is_comptime || old_dest_block->ref_count == 1) {22404 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);
21474 } else {22406 } else {
21475 IrBasicBlock *new_dest_block = ir_get_new_bb(ira, old_dest_block, &switch_br_instruction->base);22407 IrBasicBlockGen *new_dest_block = ir_get_new_bb(ira, old_dest_block, &switch_br_instruction->base.base);
21476 IrInstruction *result = ir_build_br(&ira->new_irb,22408 IrInstGen *result = ir_build_br_gen(ira, &switch_br_instruction->base.base, new_dest_block);
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;
21480 return ir_finish_anal(ira, result);22409 return ir_finish_anal(ira, result);
21481 }22410 }
21482 }22411 }
2148322412
21484 IrInstructionSwitchBrCase *cases = allocate<IrInstructionSwitchBrCase>(case_count);22413 IrInstGenSwitchBrCase *cases = allocate<IrInstGenSwitchBrCase>(case_count);
21485 for (size_t i = 0; i < case_count; i += 1) {22414 for (size_t i = 0; i < case_count; i += 1) {
21486 IrInstructionSwitchBrCase *old_case = &switch_br_instruction->cases[i];22415 IrInstSrcSwitchBrCase *old_case = &switch_br_instruction->cases[i];
21487 IrInstructionSwitchBrCase *new_case = &cases[i];22416 IrInstGenSwitchBrCase *new_case = &cases[i];
21488 new_case->block = ir_get_new_bb(ira, old_case->block, &switch_br_instruction->base);22417 new_case->block = ir_get_new_bb(ira, old_case->block, &switch_br_instruction->base.base);
21489 new_case->value = ira->codegen->invalid_instruction;22418 new_case->value = ira->codegen->invalid_inst_gen;
2149022419
21491 // Calling ir_get_new_bb set the ref_instruction on the new basic block.22420 // Calling ir_get_new_bb set the ref_instruction on the new basic block.
21492 // However a switch br may branch to the same basic block which would trigger an22421 // 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,...@@ -21494,12 +22423,12 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,
21494 // it back after the loop.22423 // it back after the loop.
21495 new_case->block->ref_instruction = nullptr;22424 new_case->block->ref_instruction = nullptr;
2149622425
21497 IrInstruction *old_value = old_case->value;22426 IrInstSrc *old_value = old_case->value;
21498 IrInstruction *new_value = old_value->child;22427 IrInstGen *new_value = old_value->child;
21499 if (type_is_invalid(new_value->value->type))22428 if (type_is_invalid(new_value->value->type))
21500 continue;22429 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);
21503 if (type_is_invalid(casted_new_value->value->type))22432 if (type_is_invalid(casted_new_value->value->type))
21504 continue;22433 continue;
2150522434
...@@ -21510,47 +22439,45 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,...@@ -21510,47 +22439,45 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,
21510 }22439 }
2151122440
21512 for (size_t i = 0; i < case_count; i += 1) {22441 for (size_t i = 0; i < case_count; i += 1) {
21513 IrInstructionSwitchBrCase *new_case = &cases[i];22442 IrInstGenSwitchBrCase *new_case = &cases[i];
21514 if (new_case->value == ira->codegen->invalid_instruction)22443 if (type_is_invalid(new_case->value->value->type))
21515 return ir_unreach_error(ira);22444 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;
21517 }22446 }
2151822447
21519 IrBasicBlock *new_else_block = ir_get_new_bb(ira, switch_br_instruction->else_block, &switch_br_instruction->base);22448 IrBasicBlockGen *new_else_block = ir_get_new_bb(ira, switch_br_instruction->else_block, &switch_br_instruction->base.base);
21520 IrInstructionSwitchBr *switch_br = ir_build_switch_br(&ira->new_irb,22449 IrInstGenSwitchBr *switch_br = ir_build_switch_br_gen(ira, &switch_br_instruction->base.base,
21521 switch_br_instruction->base.scope, switch_br_instruction->base.source_node,22450 target_value, new_else_block, case_count, cases);
21522 target_value, new_else_block, case_count, cases, nullptr, nullptr);
21523 switch_br->base.value->type = ira->codegen->builtin_types.entry_unreachable;
21524 return ir_finish_anal(ira, &switch_br->base);22451 return ir_finish_anal(ira, &switch_br->base);
21525}22452}
2152622453
21527static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,22454static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira,
21528 IrInstructionSwitchTarget *switch_target_instruction)22455 IrInstSrcSwitchTarget *switch_target_instruction)
21529{22456{
21530 Error err;22457 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;
21532 if (type_is_invalid(target_value_ptr->value->type))22459 if (type_is_invalid(target_value_ptr->value->type))
21533 return ira->codegen->invalid_instruction;22460 return ira->codegen->invalid_inst_gen;
2153422461
21535 if (target_value_ptr->value->type->id == ZigTypeIdMetaType) {22462 if (target_value_ptr->value->type->id == ZigTypeIdMetaType) {
21536 assert(instr_is_comptime(target_value_ptr));22463 assert(instr_is_comptime(target_value_ptr));
21537 ZigType *ptr_type = target_value_ptr->value->data.x_type;22464 ZigType *ptr_type = target_value_ptr->value->data.x_type;
21538 assert(ptr_type->id == ZigTypeIdPointer);22465 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);
21540 }22467 }
2154122468
21542 ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type;22469 ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type;
21543 ZigValue *pointee_val = nullptr;22470 ZigValue *pointee_val = nullptr;
21544 if (instr_is_comptime(target_value_ptr) && target_value_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {22471 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);
21546 if (pointee_val == nullptr)22473 if (pointee_val == nullptr)
21547 return ira->codegen->invalid_instruction;22474 return ira->codegen->invalid_inst_gen;
2154822475
21549 if (pointee_val->special == ConstValSpecialRuntime)22476 if (pointee_val->special == ConstValSpecialRuntime)
21550 pointee_val = nullptr;22477 pointee_val = nullptr;
21551 }22478 }
21552 if ((err = type_resolve(ira->codegen, target_type, ResolveStatusSizeKnown)))22479 if ((err = type_resolve(ira->codegen, target_type, ResolveStatusSizeKnown)))
21553 return ira->codegen->invalid_instruction;22480 return ira->codegen->invalid_inst_gen;
2155422481
21555 switch (target_type->id) {22482 switch (target_type->id) {
21556 case ZigTypeIdInvalid:22483 case ZigTypeIdInvalid:
...@@ -21567,13 +22494,13 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -21567,13 +22494,13 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
21567 case ZigTypeIdFn:22494 case ZigTypeIdFn:
21568 case ZigTypeIdErrorSet: {22495 case ZigTypeIdErrorSet: {
21569 if (pointee_val) {22496 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);
21571 copy_const_val(result->value, pointee_val);22498 copy_const_val(result->value, pointee_val);
21572 result->value->type = target_type;22499 result->value->type = target_type;
21573 return result;22500 return result;
21574 }22501 }
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);
21577 result->value->type = target_type;22504 result->value->type = target_type;
21578 return result;22505 return result;
21579 }22506 }
...@@ -21582,52 +22509,49 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -21582,52 +22509,49 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
21582 if (!decl_node->data.container_decl.auto_enum &&22509 if (!decl_node->data.container_decl.auto_enum &&
21583 decl_node->data.container_decl.init_arg_expr == nullptr)22510 decl_node->data.container_decl.init_arg_expr == nullptr)
21584 {22511 {
21585 ErrorMsg *msg = ir_add_error(ira, target_value_ptr,22512 ErrorMsg *msg = ir_add_error(ira, &target_value_ptr->base,
21586 buf_sprintf("switch on union which has no attached enum"));22513 buf_sprintf("switch on union which has no attached enum"));
21587 add_error_note(ira->codegen, msg, decl_node,22514 add_error_note(ira->codegen, msg, decl_node,
21588 buf_sprintf("consider 'union(enum)' here"));22515 buf_sprintf("consider 'union(enum)' here"));
21589 return ira->codegen->invalid_instruction;22516 return ira->codegen->invalid_inst_gen;
21590 }22517 }
21591 ZigType *tag_type = target_type->data.unionation.tag_type;22518 ZigType *tag_type = target_type->data.unionation.tag_type;
21592 assert(tag_type != nullptr);22519 assert(tag_type != nullptr);
21593 assert(tag_type->id == ZigTypeIdEnum);22520 assert(tag_type->id == ZigTypeIdEnum);
21594 if (pointee_val) {22521 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);
21596 bigint_init_bigint(&result->value->data.x_enum_tag, &pointee_val->data.x_union.tag);22523 bigint_init_bigint(&result->value->data.x_enum_tag, &pointee_val->data.x_union.tag);
21597 return result;22524 return result;
21598 }22525 }
21599 if (tag_type->data.enumeration.src_field_count == 1) {22526 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);
21601 TypeEnumField *only_field = &tag_type->data.enumeration.fields[0];22528 TypeEnumField *only_field = &tag_type->data.enumeration.fields[0];
21602 bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value);22529 bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value);
21603 return result;22530 return result;
21604 }22531 }
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);
21607 union_value->value->type = target_type;22534 union_value->value->type = target_type;
2160822535
21609 IrInstruction *union_tag_inst = ir_build_union_tag(&ira->new_irb, switch_target_instruction->base.scope,22536 return ir_build_union_tag(ira, &switch_target_instruction->base.base, union_value, tag_type);
21610 switch_target_instruction->base.source_node, union_value);
21611 union_tag_inst->value->type = tag_type;
21612 return union_tag_inst;
21613 }22537 }
21614 case ZigTypeIdEnum: {22538 case ZigTypeIdEnum: {
21615 if ((err = type_resolve(ira->codegen, target_type, ResolveStatusZeroBitsKnown)))22539 if ((err = type_resolve(ira->codegen, target_type, ResolveStatusZeroBitsKnown)))
21616 return ira->codegen->invalid_instruction;22540 return ira->codegen->invalid_inst_gen;
21617 if (target_type->data.enumeration.src_field_count == 1) {22541 if (target_type->data.enumeration.src_field_count == 1) {
21618 TypeEnumField *only_field = &target_type->data.enumeration.fields[0];22542 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);
21620 bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value);22544 bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value);
21621 return result;22545 return result;
21622 }22546 }
2162322547
21624 if (pointee_val) {22548 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);
21626 bigint_init_bigint(&result->value->data.x_enum_tag, &pointee_val->data.x_enum_tag);22550 bigint_init_bigint(&result->value->data.x_enum_tag, &pointee_val->data.x_enum_tag);
21627 return result;22551 return result;
21628 }22552 }
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);
21631 enum_value->value->type = target_type;22555 enum_value->value->type = target_type;
21632 return enum_value;22556 return enum_value;
21633 }22557 }
...@@ -21643,17 +22567,17 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -21643,17 +22567,17 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
21643 case ZigTypeIdVector:22567 case ZigTypeIdVector:
21644 case ZigTypeIdFnFrame:22568 case ZigTypeIdFnFrame:
21645 case ZigTypeIdAnyFrame:22569 case ZigTypeIdAnyFrame:
21646 ir_add_error(ira, &switch_target_instruction->base,22570 ir_add_error(ira, &switch_target_instruction->base.base,
21647 buf_sprintf("invalid switch target type '%s'", buf_ptr(&target_type->name)));22571 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;
21649 }22573 }
21650 zig_unreachable();22574 zig_unreachable();
21651}22575}
2165222576
21653static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstructionSwitchVar *instruction) {22577static IrInstGen *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstSrcSwitchVar *instruction) {
21654 IrInstruction *target_value_ptr = instruction->target_value_ptr->child;22578 IrInstGen *target_value_ptr = instruction->target_value_ptr->child;
21655 if (type_is_invalid(target_value_ptr->value->type))22579 if (type_is_invalid(target_value_ptr->value->type))
21656 return ira->codegen->invalid_instruction;22580 return ira->codegen->invalid_inst_gen;
2165722581
21658 ZigType *ref_type = target_value_ptr->value->type;22582 ZigType *ref_type = target_value_ptr->value->type;
21659 assert(ref_type->id == ZigTypeIdPointer);22583 assert(ref_type->id == ZigTypeIdPointer);
...@@ -21664,62 +22588,62 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru...@@ -21664,62 +22588,62 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru
21664 assert(enum_type->id == ZigTypeIdEnum);22588 assert(enum_type->id == ZigTypeIdEnum);
21665 assert(instruction->prongs_len > 0);22589 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;
21668 if (type_is_invalid(first_prong_value->value->type))22592 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);
21672 if (type_is_invalid(first_casted_prong_value->value->type))22596 if (type_is_invalid(first_casted_prong_value->value->type))
21673 return ira->codegen->invalid_instruction;22597 return ira->codegen->invalid_inst_gen;
2167422598
21675 ZigValue *first_prong_val = ir_resolve_const(ira, first_casted_prong_value, UndefBad);22599 ZigValue *first_prong_val = ir_resolve_const(ira, first_casted_prong_value, UndefBad);
21676 if (first_prong_val == nullptr)22600 if (first_prong_val == nullptr)
21677 return ira->codegen->invalid_instruction;22601 return ira->codegen->invalid_inst_gen;
2167822602
21679 TypeUnionField *first_field = find_union_field_by_tag(target_type, &first_prong_val->data.x_enum_tag);22603 TypeUnionField *first_field = find_union_field_by_tag(target_type, &first_prong_val->data.x_enum_tag);
2168022604
21681 ErrorMsg *invalid_payload_msg = nullptr;22605 ErrorMsg *invalid_payload_msg = nullptr;
21682 for (size_t prong_i = 1; prong_i < instruction->prongs_len; prong_i += 1) {22606 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;
21684 if (type_is_invalid(this_prong_inst->value->type))22608 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);
21688 if (type_is_invalid(this_casted_prong_value->value->type))22612 if (type_is_invalid(this_casted_prong_value->value->type))
21689 return ira->codegen->invalid_instruction;22613 return ira->codegen->invalid_inst_gen;
2169022614
21691 ZigValue *this_prong = ir_resolve_const(ira, this_casted_prong_value, UndefBad);22615 ZigValue *this_prong = ir_resolve_const(ira, this_casted_prong_value, UndefBad);
21692 if (this_prong == nullptr)22616 if (this_prong == nullptr)
21693 return ira->codegen->invalid_instruction;22617 return ira->codegen->invalid_inst_gen;
2169422618
21695 TypeUnionField *payload_field = find_union_field_by_tag(target_type, &this_prong->data.x_enum_tag);22619 TypeUnionField *payload_field = find_union_field_by_tag(target_type, &this_prong->data.x_enum_tag);
21696 ZigType *payload_type = payload_field->type_entry;22620 ZigType *payload_type = payload_field->type_entry;
21697 if (first_field->type_entry != payload_type) {22621 if (first_field->type_entry != payload_type) {
21698 if (invalid_payload_msg == nullptr) {22622 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,
21700 buf_sprintf("capture group with incompatible types"));22624 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,
21702 buf_sprintf("type '%s' here", buf_ptr(&first_field->type_entry->name)));22626 buf_sprintf("type '%s' here", buf_ptr(&first_field->type_entry->name)));
21703 }22627 }
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,
21705 buf_sprintf("type '%s' here", buf_ptr(&payload_field->type_entry->name)));22629 buf_sprintf("type '%s' here", buf_ptr(&payload_field->type_entry->name)));
21706 }22630 }
21707 }22631 }
2170822632
21709 if (invalid_payload_msg != nullptr) {22633 if (invalid_payload_msg != nullptr) {
21710 return ira->codegen->invalid_instruction;22634 return ira->codegen->invalid_inst_gen;
21711 }22635 }
2171222636
21713 if (instr_is_comptime(target_value_ptr)) {22637 if (instr_is_comptime(target_value_ptr)) {
21714 ZigValue *target_val_ptr = ir_resolve_const(ira, target_value_ptr, UndefBad);22638 ZigValue *target_val_ptr = ir_resolve_const(ira, target_value_ptr, UndefBad);
21715 if (!target_value_ptr)22639 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);
21719 if (pointee_val == nullptr)22643 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,
21723 get_pointer_to_type(ira->codegen, first_field->type_entry,22647 get_pointer_to_type(ira->codegen, first_field->type_entry,
21724 target_val_ptr->type->data.pointer.is_const));22648 target_val_ptr->type->data.pointer.is_const));
21725 ZigValue *out_val = result->value;22649 ZigValue *out_val = result->value;
...@@ -21729,11 +22653,10 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru...@@ -21729,11 +22653,10 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru
21729 return result;22653 return result;
21730 }22654 }
2173122655
21732 IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb,22656 ZigType *result_type = get_pointer_to_type(ira->codegen, first_field->type_entry,
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,
21735 target_value_ptr->value->type->data.pointer.is_const);22657 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);
21737 } else if (target_type->id == ZigTypeIdErrorSet) {22660 } else if (target_type->id == ZigTypeIdErrorSet) {
21738 // construct an error set from the prong values22661 // construct an error set from the prong values
21739 ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet);22662 ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet);
...@@ -21746,7 +22669,7 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru...@@ -21746,7 +22669,7 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru
21746 for (size_t i = 0; i < instruction->prongs_len; i += 1) {22669 for (size_t i = 0; i < instruction->prongs_len; i += 1) {
21747 ErrorTableEntry *err = ir_resolve_error(ira, instruction->prongs_ptr[i]->child);22670 ErrorTableEntry *err = ir_resolve_error(ira, instruction->prongs_ptr[i]->child);
21748 if (err == nullptr)22671 if (err == nullptr)
21749 return ira->codegen->invalid_instruction;22672 return ira->codegen->invalid_inst_gen;
21750 error_list.append(err);22673 error_list.append(err);
21751 buf_appendf(&err_set_type->name, "%s,", buf_ptr(&err->name));22674 buf_appendf(&err_set_type->name, "%s,", buf_ptr(&err->name));
21752 }22675 }
...@@ -21762,29 +22685,29 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru...@@ -21762,29 +22685,29 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru
21762 ref_type->data.pointer.explicit_alignment,22685 ref_type->data.pointer.explicit_alignment,
21763 ref_type->data.pointer.bit_offset_in_host, ref_type->data.pointer.host_int_bytes,22686 ref_type->data.pointer.bit_offset_in_host, ref_type->data.pointer.host_int_bytes,
21764 ref_type->data.pointer.allow_zero);22687 ref_type->data.pointer.allow_zero);
21765 return ir_analyze_ptr_cast(ira, &instruction->base, target_value_ptr, new_target_value_ptr_type,22688 return ir_analyze_ptr_cast(ira, &instruction->base.base, target_value_ptr, new_target_value_ptr_type,
21766 &instruction->base, false);22689 &instruction->base.base, false);
21767 } else {22690 } else {
21768 ir_add_error(ira, &instruction->base,22691 ir_add_error(ira, &instruction->base.base,
21769 buf_sprintf("switch on type '%s' provides no expression parameter", buf_ptr(&target_type->name)));22692 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;
21771 }22694 }
21772}22695}
2177322696
21774static IrInstruction *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,22697static IrInstGen *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,
21775 IrInstructionSwitchElseVar *instruction)22698 IrInstSrcSwitchElseVar *instruction)
21776{22699{
21777 IrInstruction *target_value_ptr = instruction->target_value_ptr->child;22700 IrInstGen *target_value_ptr = instruction->target_value_ptr->child;
21778 if (type_is_invalid(target_value_ptr->value->type))22701 if (type_is_invalid(target_value_ptr->value->type))
21779 return ira->codegen->invalid_instruction;22702 return ira->codegen->invalid_inst_gen;
2178022703
21781 ZigType *ref_type = target_value_ptr->value->type;22704 ZigType *ref_type = target_value_ptr->value->type;
21782 assert(ref_type->id == ZigTypeIdPointer);22705 assert(ref_type->id == ZigTypeIdPointer);
21783 ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type;22706 ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type;
21784 if (target_type->id == ZigTypeIdErrorSet) {22707 if (target_type->id == ZigTypeIdErrorSet) {
21785 // make a new set that has the other cases removed22708 // make a new set that has the other cases removed
21786 if (!resolve_inferred_error_set(ira->codegen, target_type, instruction->base.source_node)) {22709 if (!resolve_inferred_error_set(ira->codegen, target_type, instruction->base.base.source_node)) {
21787 return ira->codegen->invalid_instruction;22710 return ira->codegen->invalid_inst_gen;
21788 }22711 }
21789 if (type_is_global_error_set(target_type)) {22712 if (type_is_global_error_set(target_type)) {
21790 // the type of the else capture variable still has to be the global error set.22713 // 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,...@@ -21794,17 +22717,17 @@ static IrInstruction *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,
21794 // Make note of the errors handled by other cases22717 // Make note of the errors handled by other cases
21795 ErrorTableEntry **errors = allocate<ErrorTableEntry *>(ira->codegen->errors_by_index.length);22718 ErrorTableEntry **errors = allocate<ErrorTableEntry *>(ira->codegen->errors_by_index.length);
21796 for (size_t case_i = 0; case_i < instruction->switch_br->case_count; case_i += 1) {22719 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];22720 IrInstSrcSwitchBrCase *br_case = &instruction->switch_br->cases[case_i];
21798 IrInstruction *case_expr = br_case->value->child;22721 IrInstGen *case_expr = br_case->value->child;
21799 if (case_expr->value->type->id == ZigTypeIdErrorSet) {22722 if (case_expr->value->type->id == ZigTypeIdErrorSet) {
21800 ErrorTableEntry *err = ir_resolve_error(ira, case_expr);22723 ErrorTableEntry *err = ir_resolve_error(ira, case_expr);
21801 if (err == nullptr)22724 if (err == nullptr)
21802 return ira->codegen->invalid_instruction;22725 return ira->codegen->invalid_inst_gen;
21803 errors[err->value] = err;22726 errors[err->value] = err;
21804 } else if (case_expr->value->type->id == ZigTypeIdMetaType) {22727 } else if (case_expr->value->type->id == ZigTypeIdMetaType) {
21805 ZigType *err_set_type = ir_resolve_type(ira, case_expr);22728 ZigType *err_set_type = ir_resolve_type(ira, case_expr);
21806 if (type_is_invalid(err_set_type))22729 if (type_is_invalid(err_set_type))
21807 return ira->codegen->invalid_instruction;22730 return ira->codegen->invalid_inst_gen;
21808 populate_error_set_table(errors, err_set_type);22731 populate_error_set_table(errors, err_set_type);
21809 } else {22732 } else {
21810 zig_unreachable();22733 zig_unreachable();
...@@ -21843,27 +22766,22 @@ static IrInstruction *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,...@@ -21843,27 +22766,22 @@ static IrInstruction *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,
21843 ref_type->data.pointer.explicit_alignment,22766 ref_type->data.pointer.explicit_alignment,
21844 ref_type->data.pointer.bit_offset_in_host, ref_type->data.pointer.host_int_bytes,22767 ref_type->data.pointer.bit_offset_in_host, ref_type->data.pointer.host_int_bytes,
21845 ref_type->data.pointer.allow_zero);22768 ref_type->data.pointer.allow_zero);
21846 return ir_analyze_ptr_cast(ira, &instruction->base, target_value_ptr, new_target_value_ptr_type,22769 return ir_analyze_ptr_cast(ira, &instruction->base.base, target_value_ptr, new_target_value_ptr_type,
21847 &instruction->base, false);22770 &instruction->base.base, false);
21848 }22771 }
2184922772
21850 return target_value_ptr;22773 return target_value_ptr;
21851}22774}
2185222775
21853static IrInstruction *ir_analyze_instruction_union_tag(IrAnalyze *ira, IrInstructionUnionTag *instruction) {22776static IrInstGen *ir_analyze_instruction_import(IrAnalyze *ira, IrInstSrcImport *import_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) {
21859 Error err;22777 Error err;
2186022778
21861 IrInstruction *name_value = import_instruction->name->child;22779 IrInstGen *name_value = import_instruction->name->child;
21862 Buf *import_target_str = ir_resolve_str(ira, name_value);22780 Buf *import_target_str = ir_resolve_str(ira, name_value);
21863 if (!import_target_str)22781 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;
21867 ZigType *import = source_node->owner;22785 ZigType *import = source_node->owner;
2186822786
21869 ZigType *target_import;22787 ZigType *target_import;
...@@ -21876,48 +22794,48 @@ static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructio...@@ -21876,48 +22794,48 @@ static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructio
21876 ir_add_error_node(ira, source_node,22794 ir_add_error_node(ira, source_node,
21877 buf_sprintf("import of file outside package path: '%s'",22795 buf_sprintf("import of file outside package path: '%s'",
21878 buf_ptr(import_target_path)));22796 buf_ptr(import_target_path)));
21879 return ira->codegen->invalid_instruction;22797 return ira->codegen->invalid_inst_gen;
21880 } else if (err == ErrorFileNotFound) {22798 } else if (err == ErrorFileNotFound) {
21881 ir_add_error_node(ira, source_node,22799 ir_add_error_node(ira, source_node,
21882 buf_sprintf("unable to find '%s'", buf_ptr(import_target_path)));22800 buf_sprintf("unable to find '%s'", buf_ptr(import_target_path)));
21883 return ira->codegen->invalid_instruction;22801 return ira->codegen->invalid_inst_gen;
21884 } else {22802 } else {
21885 ir_add_error_node(ira, source_node,22803 ir_add_error_node(ira, source_node,
21886 buf_sprintf("unable to open '%s': %s", buf_ptr(&full_path), err_str(err)));22804 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;
21888 }22806 }
21889 }22807 }
2189022808
21891 return ir_const_type(ira, &import_instruction->base, target_import);22809 return ir_const_type(ira, &import_instruction->base.base, target_import);
21892}22810}
2189322811
21894static IrInstruction *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstructionRef *ref_instruction) {22812static IrInstGen *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstSrcRef *ref_instruction) {
21895 IrInstruction *value = ref_instruction->value->child;22813 IrInstGen *value = ref_instruction->value->child;
21896 if (type_is_invalid(value->value->type))22814 if (type_is_invalid(value->value->type))
21897 return ira->codegen->invalid_instruction;22815 return ira->codegen->invalid_inst_gen;
21898 return ir_get_ref(ira, &ref_instruction->base, value, ref_instruction->is_const, ref_instruction->is_volatile);22816 return ir_get_ref(ira, &ref_instruction->base.base, value, ref_instruction->is_const, ref_instruction->is_volatile);
21899}22817}
2190022818
21901static IrInstruction *ir_analyze_union_init(IrAnalyze *ira, IrInstruction *source_instruction,22819static IrInstGen *ir_analyze_union_init(IrAnalyze *ira, IrInst* source_instruction,
21902 AstNode *field_source_node, ZigType *union_type, Buf *field_name, IrInstruction *field_result_loc,22820 AstNode *field_source_node, ZigType *union_type, Buf *field_name, IrInstGen *field_result_loc,
21903 IrInstruction *result_loc)22821 IrInstGen *result_loc)
21904{22822{
21905 Error err;22823 Error err;
21906 assert(union_type->id == ZigTypeIdUnion);22824 assert(union_type->id == ZigTypeIdUnion);
2190722825
21908 if ((err = type_resolve(ira->codegen, union_type, ResolveStatusSizeKnown)))22826 if ((err = type_resolve(ira->codegen, union_type, ResolveStatusSizeKnown)))
21909 return ira->codegen->invalid_instruction;22827 return ira->codegen->invalid_inst_gen;
2191022828
21911 TypeUnionField *type_field = find_union_type_field(union_type, field_name);22829 TypeUnionField *type_field = find_union_type_field(union_type, field_name);
21912 if (type_field == nullptr) {22830 if (type_field == nullptr) {
21913 ir_add_error_node(ira, field_source_node,22831 ir_add_error_node(ira, field_source_node,
21914 buf_sprintf("no member named '%s' in union '%s'",22832 buf_sprintf("no member named '%s' in union '%s'",
21915 buf_ptr(field_name), buf_ptr(&union_type->name)));22833 buf_ptr(field_name), buf_ptr(&union_type->name)));
21916 return ira->codegen->invalid_instruction;22834 return ira->codegen->invalid_inst_gen;
21917 }22835 }
2191822836
21919 if (type_is_invalid(type_field->type_entry))22837 if (type_is_invalid(type_field->type_entry))
21920 return ira->codegen->invalid_instruction;22838 return ira->codegen->invalid_inst_gen;
2192122839
21922 if (result_loc->value->data.x_ptr.mut == ConstPtrMutInfer) {22840 if (result_loc->value->data.x_ptr.mut == ConstPtrMutInfer) {
21923 if (instr_is_comptime(field_result_loc) &&22841 if (instr_is_comptime(field_result_loc) &&
...@@ -21929,42 +22847,42 @@ static IrInstruction *ir_analyze_union_init(IrAnalyze *ira, IrInstruction *sourc...@@ -21929,42 +22847,42 @@ static IrInstruction *ir_analyze_union_init(IrAnalyze *ira, IrInstruction *sourc
21929 }22847 }
21930 }22848 }
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)
21933 || type_requires_comptime(ira->codegen, union_type) == ReqCompTimeYes;22851 || 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);
21936 if (is_comptime && !instr_is_comptime(result)) {22854 if (is_comptime && !instr_is_comptime(result)) {
21937 ir_add_error(ira, field_result_loc,22855 ir_add_error(ira, &field_result_loc->base,
21938 buf_sprintf("unable to evaluate constant expression"));22856 buf_sprintf("unable to evaluate constant expression"));
21939 return ira->codegen->invalid_instruction;22857 return ira->codegen->invalid_inst_gen;
21940 }22858 }
21941 return result;22859 return result;
21942}22860}
2194322861
21944static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruction *instruction,22862static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *source_instr,
21945 ZigType *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields,22863 ZigType *container_type, size_t instr_field_count, IrInstSrcContainerInitFieldsField *fields,
21946 IrInstruction *result_loc)22864 IrInstGen *result_loc)
21947{22865{
21948 Error err;22866 Error err;
21949 if (container_type->id == ZigTypeIdUnion) {22867 if (container_type->id == ZigTypeIdUnion) {
21950 if (instr_field_count != 1) {22868 if (instr_field_count != 1) {
21951 ir_add_error(ira, instruction,22869 ir_add_error(ira, source_instr,
21952 buf_sprintf("union initialization expects exactly one field"));22870 buf_sprintf("union initialization expects exactly one field"));
21953 return ira->codegen->invalid_instruction;22871 return ira->codegen->invalid_inst_gen;
21954 }22872 }
21955 IrInstructionContainerInitFieldsField *field = &fields[0];22873 IrInstSrcContainerInitFieldsField *field = &fields[0];
21956 IrInstruction *field_result_loc = field->result_loc->child;22874 IrInstGen *field_result_loc = field->result_loc->child;
21957 if (type_is_invalid(field_result_loc->value->type))22875 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,
21961 field_result_loc, result_loc);22879 field_result_loc, result_loc);
21962 }22880 }
21963 if (container_type->id != ZigTypeIdStruct || is_slice(container_type)) {22881 if (container_type->id != ZigTypeIdStruct || is_slice(container_type)) {
21964 ir_add_error(ira, instruction,22882 ir_add_error(ira, source_instr,
21965 buf_sprintf("type '%s' does not support struct initialization syntax",22883 buf_sprintf("type '%s' does not support struct initialization syntax",
21966 buf_ptr(&container_type->name)));22884 buf_ptr(&container_type->name)));
21967 return ira->codegen->invalid_instruction;22885 return ira->codegen->invalid_inst_gen;
21968 }22886 }
2196922887
21970 if (container_type->data.structure.resolve_status == ResolveStatusBeingInferred) {22888 if (container_type->data.structure.resolve_status == ResolveStatusBeingInferred) {
...@@ -21973,16 +22891,16 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc...@@ -21973,16 +22891,16 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc
21973 }22891 }
2197422892
21975 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))22893 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))
21976 return ira->codegen->invalid_instruction;22894 return ira->codegen->invalid_inst_gen;
2197722895
21978 size_t actual_field_count = container_type->data.structure.src_field_count;22896 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
21982 AstNode **field_assign_nodes = allocate<AstNode *>(actual_field_count);22900 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)
21986 || type_requires_comptime(ira->codegen, container_type) == ReqCompTimeYes;22904 || type_requires_comptime(ira->codegen, container_type) == ReqCompTimeYes;
2198722905
2198822906
...@@ -21998,29 +22916,29 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc...@@ -21998,29 +22916,29 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc
21998 // comptime-known values.22916 // comptime-known values.
2199922917
22000 for (size_t i = 0; i < instr_field_count; i += 1) {22918 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;
22004 if (type_is_invalid(field_result_loc->value->type))22922 if (type_is_invalid(field_result_loc->value->type))
22005 return ira->codegen->invalid_instruction;22923 return ira->codegen->invalid_inst_gen;
2200622924
22007 TypeStructField *type_field = find_struct_type_field(container_type, field->name);22925 TypeStructField *type_field = find_struct_type_field(container_type, field->name);
22008 if (!type_field) {22926 if (!type_field) {
22009 ir_add_error_node(ira, field->source_node,22927 ir_add_error_node(ira, field->source_node,
22010 buf_sprintf("no member named '%s' in struct '%s'",22928 buf_sprintf("no member named '%s' in struct '%s'",
22011 buf_ptr(field->name), buf_ptr(&container_type->name)));22929 buf_ptr(field->name), buf_ptr(&container_type->name)));
22012 return ira->codegen->invalid_instruction;22930 return ira->codegen->invalid_inst_gen;
22013 }22931 }
2201422932
22015 if (type_is_invalid(type_field->type_entry))22933 if (type_is_invalid(type_field->type_entry))
22016 return ira->codegen->invalid_instruction;22934 return ira->codegen->invalid_inst_gen;
2201722935
22018 size_t field_index = type_field->src_index;22936 size_t field_index = type_field->src_index;
22019 AstNode *existing_assign_node = field_assign_nodes[field_index];22937 AstNode *existing_assign_node = field_assign_nodes[field_index];
22020 if (existing_assign_node) {22938 if (existing_assign_node) {
22021 ErrorMsg *msg = ir_add_error_node(ira, field->source_node, buf_sprintf("duplicate field"));22939 ErrorMsg *msg = ir_add_error_node(ira, field->source_node, buf_sprintf("duplicate field"));
22022 add_error_note(ira->codegen, msg, existing_assign_node, buf_sprintf("other field here"));22940 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;
22024 }22942 }
22025 field_assign_nodes[field_index] = field->source_node;22943 field_assign_nodes[field_index] = field->source_node;
2202622944
...@@ -22041,20 +22959,20 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc...@@ -22041,20 +22959,20 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc
22041 TypeStructField *field = container_type->data.structure.fields[i];22959 TypeStructField *field = container_type->data.structure.fields[i];
22042 memoize_field_init_val(ira->codegen, container_type, field);22960 memoize_field_init_val(ira->codegen, container_type, field);
22043 if (field->init_val == nullptr) {22961 if (field->init_val == nullptr) {
22044 ir_add_error_node(ira, instruction->source_node,22962 ir_add_error(ira, source_instr,
22045 buf_sprintf("missing field: '%s'", buf_ptr(container_type->data.structure.fields[i]->name)));22963 buf_sprintf("missing field: '%s'", buf_ptr(container_type->data.structure.fields[i]->name)));
22046 any_missing = true;22964 any_missing = true;
22047 continue;22965 continue;
22048 }22966 }
22049 if (type_is_invalid(field->init_val->type))22967 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);
22053 copy_const_val(runtime_inst->value, field->init_val);22971 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,
22056 container_type, true);22974 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);
22058 if (instr_is_comptime(field_ptr) && field_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {22976 if (instr_is_comptime(field_ptr) && field_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
22059 const_ptrs.append(field_ptr);22977 const_ptrs.append(field_ptr);
22060 } else {22978 } else {
...@@ -22062,39 +22980,39 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc...@@ -22062,39 +22980,39 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc
22062 }22980 }
22063 }22981 }
22064 if (any_missing)22982 if (any_missing)
22065 return ira->codegen->invalid_instruction;22983 return ira->codegen->invalid_inst_gen;
2206622984
22067 if (result_loc->value->data.x_ptr.mut == ConstPtrMutInfer) {22985 if (result_loc->value->data.x_ptr.mut == ConstPtrMutInfer) {
22068 if (const_ptrs.length != actual_field_count) {22986 if (const_ptrs.length != actual_field_count) {
22069 result_loc->value->special = ConstValSpecialRuntime;22987 result_loc->value->special = ConstValSpecialRuntime;
22070 for (size_t i = 0; i < const_ptrs.length; i += 1) {22988 for (size_t i = 0; i < const_ptrs.length; i += 1) {
22071 IrInstruction *field_result_loc = const_ptrs.at(i);22989 IrInstGen *field_result_loc = const_ptrs.at(i);
22072 IrInstruction *deref = ir_get_deref(ira, field_result_loc, field_result_loc, nullptr);22990 IrInstGen *deref = ir_get_deref(ira, &field_result_loc->base, field_result_loc, nullptr);
22073 field_result_loc->value->special = ConstValSpecialRuntime;22991 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);
22075 }22993 }
22076 }22994 }
22077 }22995 }
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
22081 if (is_comptime && !instr_is_comptime(result)) {22999 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,
22083 buf_sprintf("unable to evaluate constant expression"));23001 buf_sprintf("unable to evaluate constant expression"));
22084 return ira->codegen->invalid_instruction;23002 return ira->codegen->invalid_inst_gen;
22085 }23003 }
2208623004
22087 return result;23005 return result;
22088}23006}
2208923007
22090static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,23008static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
22091 IrInstructionContainerInitList *instruction)23009 IrInstSrcContainerInitList *instruction)
22092{23010{
22093 ir_assert(instruction->result_loc != nullptr, &instruction->base);23011 ir_assert(instruction->result_loc != nullptr, &instruction->base.base);
22094 IrInstruction *result_loc = instruction->result_loc->child;23012 IrInstGen *result_loc = instruction->result_loc->child;
22095 if (type_is_invalid(result_loc->value->type))23013 if (type_is_invalid(result_loc->value->type))
22096 return result_loc;23014 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
22099 ZigType *container_type = result_loc->value->type->data.pointer.child_type;23017 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,...@@ -22104,24 +23022,24 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
22104 ir_add_error_node(ira, instruction->init_array_type_source_node,23022 ir_add_error_node(ira, instruction->init_array_type_source_node,
22105 buf_sprintf("array literal requires address-of operator to coerce to slice type '%s'",23023 buf_sprintf("array literal requires address-of operator to coerce to slice type '%s'",
22106 buf_ptr(&container_type->name)));23024 buf_ptr(&container_type->name)));
22107 return ira->codegen->invalid_instruction;23025 return ira->codegen->invalid_inst_gen;
22108 }23026 }
2210923027
22110 if (container_type->id == ZigTypeIdVoid) {23028 if (container_type->id == ZigTypeIdVoid) {
22111 if (elem_count != 0) {23029 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,
22113 buf_sprintf("void expression expects no arguments"));23031 buf_sprintf("void expression expects no arguments"));
22114 return ira->codegen->invalid_instruction;23032 return ira->codegen->invalid_inst_gen;
22115 }23033 }
22116 return ir_const_void(ira, &instruction->base);23034 return ir_const_void(ira, &instruction->base.base);
22117 }23035 }
2211823036
22119 if (container_type->id == ZigTypeIdStruct && elem_count == 0) {23037 if (container_type->id == ZigTypeIdStruct && elem_count == 0) {
22120 ir_assert(instruction->result_loc != nullptr, &instruction->base);23038 ir_assert(instruction->result_loc != nullptr, &instruction->base.base);
22121 IrInstruction *result_loc = instruction->result_loc->child;23039 IrInstGen *result_loc = instruction->result_loc->child;
22122 if (type_is_invalid(result_loc->value->type))23040 if (type_is_invalid(result_loc->value->type))
22123 return result_loc;23041 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);
22125 }23043 }
2212623044
22127 if (container_type->id == ZigTypeIdArray) {23045 if (container_type->id == ZigTypeIdArray) {
...@@ -22129,10 +23047,10 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -22129,10 +23047,10 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
22129 if (container_type->data.array.len != elem_count) {23047 if (container_type->data.array.len != elem_count) {
22130 ZigType *literal_type = get_array_type(ira->codegen, child_type, elem_count, nullptr);23048 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,
22133 buf_sprintf("expected %s literal, found %s literal",23051 buf_sprintf("expected %s literal, found %s literal",
22134 buf_ptr(&container_type->name), buf_ptr(&literal_type->name)));23052 buf_ptr(&container_type->name), buf_ptr(&literal_type->name)));
22135 return ira->codegen->invalid_instruction;23053 return ira->codegen->invalid_inst_gen;
22136 }23054 }
22137 } else if (container_type->id == ZigTypeIdStruct &&23055 } else if (container_type->id == ZigTypeIdStruct &&
22138 container_type->data.structure.resolve_status == ResolveStatusBeingInferred)23056 container_type->data.structure.resolve_status == ResolveStatusBeingInferred)
...@@ -22142,17 +23060,17 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -22142,17 +23060,17 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
22142 } else if (container_type->id == ZigTypeIdVector) {23060 } else if (container_type->id == ZigTypeIdVector) {
22143 // OK23061 // OK
22144 } else {23062 } else {
22145 ir_add_error_node(ira, instruction->base.source_node,23063 ir_add_error(ira, &instruction->base.base,
22146 buf_sprintf("type '%s' does not support array initialization",23064 buf_sprintf("type '%s' does not support array initialization",
22147 buf_ptr(&container_type->name)));23065 buf_ptr(&container_type->name)));
22148 return ira->codegen->invalid_instruction;23066 return ira->codegen->invalid_inst_gen;
22149 }23067 }
2215023068
22151 switch (type_has_one_possible_value(ira->codegen, container_type)) {23069 switch (type_has_one_possible_value(ira->codegen, container_type)) {
22152 case OnePossibleValueInvalid:23070 case OnePossibleValueInvalid:
22153 return ira->codegen->invalid_instruction;23071 return ira->codegen->invalid_inst_gen;
22154 case OnePossibleValueYes:23072 case OnePossibleValueYes:
22155 return ir_const_move(ira, &instruction->base,23073 return ir_const_move(ira, &instruction->base.base,
22156 get_the_one_possible_value(ira->codegen, container_type));23074 get_the_one_possible_value(ira->codegen, container_type));
22157 case OnePossibleValueNo:23075 case OnePossibleValueNo:
22158 break;23076 break;
...@@ -22161,16 +23079,16 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -22161,16 +23079,16 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
22161 bool is_comptime;23079 bool is_comptime;
22162 switch (type_requires_comptime(ira->codegen, container_type)) {23080 switch (type_requires_comptime(ira->codegen, container_type)) {
22163 case ReqCompTimeInvalid:23081 case ReqCompTimeInvalid:
22164 return ira->codegen->invalid_instruction;23082 return ira->codegen->invalid_inst_gen;
22165 case ReqCompTimeNo:23083 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);
22167 break;23085 break;
22168 case ReqCompTimeYes:23086 case ReqCompTimeYes:
22169 is_comptime = true;23087 is_comptime = true;
22170 break;23088 break;
22171 }23089 }
2217223090
22173 IrInstruction *first_non_const_instruction = nullptr;23091 IrInstGen *first_non_const_instruction = nullptr;
2217423092
22175 // The Result Location Mechanism has already emitted runtime instructions to23093 // The Result Location Mechanism has already emitted runtime instructions to
22176 // initialize runtime elements and has omitted instructions for the comptime23094 // initialize runtime elements and has omitted instructions for the comptime
...@@ -22179,12 +23097,12 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -22179,12 +23097,12 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
22179 // array initialization can be a comptime value, overwrite ConstPtrMutInfer with23097 // array initialization can be a comptime value, overwrite ConstPtrMutInfer with
22180 // ConstPtrMutComptimeConst. Otherwise, emit instructions to runtime-initialize the23098 // ConstPtrMutComptimeConst. Otherwise, emit instructions to runtime-initialize the
22181 // elements that have comptime-known values.23099 // elements that have comptime-known values.
22182 ZigList<IrInstruction *> const_ptrs = {};23100 ZigList<IrInstGen *> const_ptrs = {};
2218323101
22184 for (size_t i = 0; i < elem_count; i += 1) {23102 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;
22186 if (type_is_invalid(elem_result_loc->value->type))23104 if (type_is_invalid(elem_result_loc->value->type))
22187 return ira->codegen->invalid_instruction;23105 return ira->codegen->invalid_inst_gen;
2218823106
22189 assert(elem_result_loc->value->type->id == ZigTypeIdPointer);23107 assert(elem_result_loc->value->type->id == ZigTypeIdPointer);
2219023108
...@@ -22201,81 +23119,79 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -22201,81 +23119,79 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
22201 if (const_ptrs.length != elem_count) {23119 if (const_ptrs.length != elem_count) {
22202 result_loc->value->special = ConstValSpecialRuntime;23120 result_loc->value->special = ConstValSpecialRuntime;
22203 for (size_t i = 0; i < const_ptrs.length; i += 1) {23121 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);
22205 assert(elem_result_loc->value->special == ConstValSpecialStatic);23123 assert(elem_result_loc->value->special == ConstValSpecialStatic);
22206 if (elem_result_loc->value->type->data.pointer.inferred_struct_field != nullptr) {23124 if (elem_result_loc->value->type->data.pointer.inferred_struct_field != nullptr) {
22207 // This field will be generated comptime; no need to do this.23125 // This field will be generated comptime; no need to do this.
22208 continue;23126 continue;
22209 }23127 }
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);
22211 elem_result_loc->value->special = ConstValSpecialRuntime;23129 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);
22213 }23131 }
22214 }23132 }
22215 }23133 }
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);
22218 if (instr_is_comptime(result))23136 if (instr_is_comptime(result))
22219 return result;23137 return result;
2222023138
22221 if (is_comptime) {23139 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,
22223 buf_sprintf("unable to evaluate constant expression"));23141 buf_sprintf("unable to evaluate constant expression"));
22224 return ira->codegen->invalid_instruction;23142 return ira->codegen->invalid_inst_gen;
22225 }23143 }
2222623144
22227 ZigType *result_elem_type = result_loc->value->type->data.pointer.child_type;23145 ZigType *result_elem_type = result_loc->value->type->data.pointer.child_type;
22228 if (is_slice(result_elem_type)) {23146 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,
22230 buf_sprintf("runtime-initialized array cannot be casted to slice type '%s'",23148 buf_sprintf("runtime-initialized array cannot be casted to slice type '%s'",
22231 buf_ptr(&result_elem_type->name)));23149 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,
22233 buf_sprintf("this value is not comptime-known"));23151 buf_sprintf("this value is not comptime-known"));
22234 return ira->codegen->invalid_instruction;23152 return ira->codegen->invalid_inst_gen;
22235 }23153 }
22236 return result;23154 return result;
22237}23155}
2223823156
22239static IrInstruction *ir_analyze_instruction_container_init_fields(IrAnalyze *ira,23157static IrInstGen *ir_analyze_instruction_container_init_fields(IrAnalyze *ira,
22240 IrInstructionContainerInitFields *instruction)23158 IrInstSrcContainerInitFields *instruction)
22241{23159{
22242 ir_assert(instruction->result_loc != nullptr, &instruction->base);23160 ir_assert(instruction->result_loc != nullptr, &instruction->base.base);
22243 IrInstruction *result_loc = instruction->result_loc->child;23161 IrInstGen *result_loc = instruction->result_loc->child;
22244 if (type_is_invalid(result_loc->value->type))23162 if (type_is_invalid(result_loc->value->type))
22245 return result_loc;23163 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);
22248 ZigType *container_type = result_loc->value->type->data.pointer.child_type;23166 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,
22251 instruction->field_count, instruction->fields, result_loc);23169 instruction->field_count, instruction->fields, result_loc);
22252}23170}
2225323171
22254static IrInstruction *ir_analyze_instruction_compile_err(IrAnalyze *ira,23172static IrInstGen *ir_analyze_instruction_compile_err(IrAnalyze *ira, IrInstSrcCompileErr *instruction) {
22255 IrInstructionCompileErr *instruction)23173 IrInstGen *msg_value = instruction->msg->child;
22256{
22257 IrInstruction *msg_value = instruction->msg->child;
22258 Buf *msg_buf = ir_resolve_str(ira, msg_value);23174 Buf *msg_buf = ir_resolve_str(ira, msg_value);
22259 if (!msg_buf)23175 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;
22265}23181}
2226623182
22267static IrInstruction *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstructionCompileLog *instruction) {23183static IrInstGen *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstSrcCompileLog *instruction) {
22268 Buf buf = BUF_INIT;23184 Buf buf = BUF_INIT;
22269 fprintf(stderr, "| ");23185 fprintf(stderr, "| ");
22270 for (size_t i = 0; i < instruction->msg_count; i += 1) {23186 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;
22272 if (type_is_invalid(msg->value->type))23188 if (type_is_invalid(msg->value->type))
22273 return ira->codegen->invalid_instruction;23189 return ira->codegen->invalid_inst_gen;
22274 buf_resize(&buf, 0);23190 buf_resize(&buf, 0);
22275 if (msg->value->special == ConstValSpecialLazy) {23191 if (msg->value->special == ConstValSpecialLazy) {
22276 // Resolve any lazy value that's passed, we need its value23192 // Resolve any lazy value that's passed, we need its value
22277 if (ir_resolve_lazy(ira->codegen, msg->source_node, msg->value))23193 if (ir_resolve_lazy(ira->codegen, msg->base.source_node, msg->value))
22278 return ira->codegen->invalid_instruction;23194 return ira->codegen->invalid_inst_gen;
22279 }23195 }
22280 render_const_value(ira->codegen, &buf, msg->value);23196 render_const_value(ira->codegen, &buf, msg->value);
22281 const char *comma_str = (i != 0) ? ", " : "";23197 const char *comma_str = (i != 0) ? ", " : "";
...@@ -22283,25 +23199,25 @@ static IrInstruction *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstr...@@ -22283,25 +23199,25 @@ static IrInstruction *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstr
22283 }23199 }
22284 fprintf(stderr, "\n");23200 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;
22287 if (!expr->seen) {23203 if (!expr->seen) {
22288 // Here we bypass higher level functions such as ir_add_error because we do not want23204 // Here we bypass higher level functions such as ir_add_error because we do not want
22289 // invalidate_exec to be called.23205 // 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"));
22291 }23207 }
22292 expr->seen = true;23208 expr->seen = true;
2229323209
22294 return ir_const_void(ira, &instruction->base);23210 return ir_const_void(ira, &instruction->base.base);
22295}23211}
2229623212
22297static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstructionErrName *instruction) {23213static IrInstGen *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstSrcErrName *instruction) {
22298 IrInstruction *value = instruction->value->child;23214 IrInstGen *value = instruction->value->child;
22299 if (type_is_invalid(value->value->type))23215 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);
22303 if (type_is_invalid(casted_value->value->type))23219 if (type_is_invalid(casted_value->value->type))
22304 return ira->codegen->invalid_instruction;23220 return ira->codegen->invalid_inst_gen;
2230523221
22306 ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,23222 ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
22307 true, false, PtrLenUnknown, 0, 0, 0, false);23223 true, false, PtrLenUnknown, 0, 0, 0, false);
...@@ -22309,13 +23225,13 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct...@@ -22309,13 +23225,13 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct
22309 if (instr_is_comptime(casted_value)) {23225 if (instr_is_comptime(casted_value)) {
22310 ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad);23226 ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad);
22311 if (val == nullptr)23227 if (val == nullptr)
22312 return ira->codegen->invalid_instruction;23228 return ira->codegen->invalid_inst_gen;
22313 ErrorTableEntry *err = casted_value->value->data.x_err_set;23229 ErrorTableEntry *err = casted_value->value->data.x_err_set;
22314 if (!err->cached_error_name_val) {23230 if (!err->cached_error_name_val) {
22315 ZigValue *array_val = create_const_str_lit(ira->codegen, &err->name)->data.x_ptr.data.ref.pointee;23231 ZigValue *array_val = create_const_str_lit(ira->codegen, &err->name)->data.x_ptr.data.ref.pointee;
22316 err->cached_error_name_val = create_const_slice(ira->codegen, array_val, 0, buf_len(&err->name), true);23232 err->cached_error_name_val = create_const_slice(ira->codegen, array_val, 0, buf_len(&err->name), true);
22317 }23233 }
22318 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);23234 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
22319 copy_const_val(result->value, err->cached_error_name_val);23235 copy_const_val(result->value, err->cached_error_name_val);
22320 result->value->type = str_type;23236 result->value->type = str_type;
22321 return result;23237 return result;
...@@ -22323,20 +23239,17 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct...@@ -22323,20 +23239,17 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct
2232323239
22324 ira->codegen->generate_error_name_table = true;23240 ira->codegen->generate_error_name_table = true;
2232523241
22326 IrInstruction *result = ir_build_err_name(&ira->new_irb,23242 return ir_build_err_name_gen(ira, &instruction->base.base, value, str_type);
22327 instruction->base.scope, instruction->base.source_node, value);
22328 result->value->type = str_type;
22329 return result;
22330}23243}
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) {
22333 Error err;23246 Error err;
22334 IrInstruction *target = instruction->target->child;23247 IrInstGen *target = instruction->target->child;
22335 if (type_is_invalid(target->value->type))23248 if (type_is_invalid(target->value->type))
22336 return ira->codegen->invalid_instruction;23249 return ira->codegen->invalid_inst_gen;
2233723250
22338 if (target->value->type->id == ZigTypeIdEnumLiteral) {23251 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);
22340 Buf *field_name = target->value->data.x_enum_literal;23253 Buf *field_name = target->value->data.x_enum_literal;
22341 ZigValue *array_val = create_const_str_lit(ira->codegen, field_name)->data.x_ptr.data.ref.pointee;23254 ZigValue *array_val = create_const_str_lit(ira->codegen, field_name)->data.x_ptr.data.ref.pointee;
22342 init_const_slice(ira->codegen, result->value, array_val, 0, buf_len(field_name), true);23255 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...@@ -22344,9 +23257,9 @@ static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIns
22344 }23257 }
2234523258
22346 if (target->value->type->id == ZigTypeIdUnion) {23259 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);
22348 if (type_is_invalid(target->value->type))23261 if (type_is_invalid(target->value->type))
22349 return ira->codegen->invalid_instruction;23262 return ira->codegen->invalid_inst_gen;
22350 }23263 }
2235123264
22352 if (target->value->type->id != ZigTypeIdEnum) {23265 if (target->value->type->id != ZigTypeIdEnum) {
...@@ -22359,75 +23272,73 @@ static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIns...@@ -22359,75 +23272,73 @@ static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIns
22359 !target->value->type->data.enumeration.non_exhaustive) {23272 !target->value->type->data.enumeration.non_exhaustive) {
22360 TypeEnumField *only_field = &target->value->type->data.enumeration.fields[0];23273 TypeEnumField *only_field = &target->value->type->data.enumeration.fields[0];
22361 ZigValue *array_val = create_const_str_lit(ira->codegen, only_field->name)->data.x_ptr.data.ref.pointee;23274 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);
22363 init_const_slice(ira->codegen, result->value, array_val, 0, buf_len(only_field->name), true);23276 init_const_slice(ira->codegen, result->value, array_val, 0, buf_len(only_field->name), true);
22364 return result;23277 return result;
22365 }23278 }
2236623279
22367 if (instr_is_comptime(target)) {23280 if (instr_is_comptime(target)) {
22368 if ((err = type_resolve(ira->codegen, target->value->type, ResolveStatusZeroBitsKnown)))23281 if ((err = type_resolve(ira->codegen, target->value->type, ResolveStatusZeroBitsKnown)))
22369 return ira->codegen->invalid_instruction;23282 return ira->codegen->invalid_inst_gen;
22370 if (target->value->type->data.enumeration.non_exhaustive) {23283 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,
22372 buf_sprintf("TODO @tagName on non-exhaustive enum https://github.com/ziglang/zig/issues/3991"));23285 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;
22374 }23287 }
22375 TypeEnumField *field = find_enum_field_by_tag(target->value->type, &target->value->data.x_bigint);23288 TypeEnumField *field = find_enum_field_by_tag(target->value->type, &target->value->data.x_bigint);
22376 ZigValue *array_val = create_const_str_lit(ira->codegen, field->name)->data.x_ptr.data.ref.pointee;23289 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);
22378 init_const_slice(ira->codegen, result->value, array_val, 0, buf_len(field->name), true);23291 init_const_slice(ira->codegen, result->value, array_val, 0, buf_len(field->name), true);
22379 return result;23292 return result;
22380 }23293 }
2238123294
22382 IrInstruction *result = ir_build_tag_name(&ira->new_irb, instruction->base.scope,
22383 instruction->base.source_node, target);
22384 ZigType *u8_ptr_type = get_pointer_to_type_extra(23295 ZigType *u8_ptr_type = get_pointer_to_type_extra(
22385 ira->codegen, ira->codegen->builtin_types.entry_u8,23296 ira->codegen, ira->codegen->builtin_types.entry_u8,
22386 true, false, PtrLenUnknown,23297 true, false, PtrLenUnknown,
22387 0, 0, 0, false);23298 0, 0, 0, false);
22388 result->value->type = get_slice_type(ira->codegen, u8_ptr_type);23299 ZigType *result_type = get_slice_type(ira->codegen, u8_ptr_type);
22389 return result;23300 return ir_build_tag_name_gen(ira, &instruction->base.base, target, result_type);
22390}23301}
2239123302
22392static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,23303static IrInstGen *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
22393 IrInstructionFieldParentPtr *instruction)23304 IrInstSrcFieldParentPtr *instruction)
22394{23305{
22395 Error err;23306 Error err;
22396 IrInstruction *type_value = instruction->type_value->child;23307 IrInstGen *type_value = instruction->type_value->child;
22397 ZigType *container_type = ir_resolve_type(ira, type_value);23308 ZigType *container_type = ir_resolve_type(ira, type_value);
22398 if (type_is_invalid(container_type))23309 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;
22402 Buf *field_name = ir_resolve_str(ira, field_name_value);23313 Buf *field_name = ir_resolve_str(ira, field_name_value);
22403 if (!field_name)23314 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;
22407 if (type_is_invalid(field_ptr->value->type))23318 if (type_is_invalid(field_ptr->value->type))
22408 return ira->codegen->invalid_instruction;23319 return ira->codegen->invalid_inst_gen;
2240923320
22410 if (container_type->id != ZigTypeIdStruct) {23321 if (container_type->id != ZigTypeIdStruct) {
22411 ir_add_error(ira, type_value,23322 ir_add_error(ira, &type_value->base,
22412 buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name)));23323 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;
22414 }23325 }
2241523326
22416 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))23327 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))
22417 return ira->codegen->invalid_instruction;23328 return ira->codegen->invalid_inst_gen;
2241823329
22419 TypeStructField *field = find_struct_type_field(container_type, field_name);23330 TypeStructField *field = find_struct_type_field(container_type, field_name);
22420 if (field == nullptr) {23331 if (field == nullptr) {
22421 ir_add_error(ira, field_name_value,23332 ir_add_error(ira, &field_name_value->base,
22422 buf_sprintf("struct '%s' has no field '%s'",23333 buf_sprintf("struct '%s' has no field '%s'",
22423 buf_ptr(&container_type->name), buf_ptr(field_name)));23334 buf_ptr(&container_type->name), buf_ptr(field_name)));
22424 return ira->codegen->invalid_instruction;23335 return ira->codegen->invalid_inst_gen;
22425 }23336 }
2242623337
22427 if (field_ptr->value->type->id != ZigTypeIdPointer) {23338 if (field_ptr->value->type->id != ZigTypeIdPointer) {
22428 ir_add_error(ira, field_ptr,23339 ir_add_error(ira, &field_ptr->base,
22429 buf_sprintf("expected pointer, found '%s'", buf_ptr(&field_ptr->value->type->name)));23340 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;
22431 }23342 }
2243223343
22433 bool is_packed = (container_type->data.structure.layout == ContainerLayoutPacked);23344 bool is_packed = (container_type->data.structure.layout == ContainerLayoutPacked);
...@@ -22439,9 +23350,9 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,...@@ -22439,9 +23350,9 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
22439 field_ptr->value->type->data.pointer.is_volatile,23350 field_ptr->value->type->data.pointer.is_volatile,
22440 PtrLenSingle,23351 PtrLenSingle,
22441 field_ptr_align, 0, 0, false);23352 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);
22443 if (type_is_invalid(casted_field_ptr->value->type))23354 if (type_is_invalid(casted_field_ptr->value->type))
22444 return ira->codegen->invalid_instruction;23355 return ira->codegen->invalid_inst_gen;
2244523356
22446 ZigType *result_type = get_pointer_to_type_extra(ira->codegen, container_type,23357 ZigType *result_type = get_pointer_to_type_extra(ira->codegen, container_type,
22447 casted_field_ptr->value->type->data.pointer.is_const,23358 casted_field_ptr->value->type->data.pointer.is_const,
...@@ -22452,23 +23363,23 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,...@@ -22452,23 +23363,23 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
22452 if (instr_is_comptime(casted_field_ptr)) {23363 if (instr_is_comptime(casted_field_ptr)) {
22453 ZigValue *field_ptr_val = ir_resolve_const(ira, casted_field_ptr, UndefBad);23364 ZigValue *field_ptr_val = ir_resolve_const(ira, casted_field_ptr, UndefBad);
22454 if (!field_ptr_val)23365 if (!field_ptr_val)
22455 return ira->codegen->invalid_instruction;23366 return ira->codegen->invalid_inst_gen;
2245623367
22457 if (field_ptr_val->data.x_ptr.special != ConstPtrSpecialBaseStruct) {23368 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"));23369 ir_add_error(ira, &field_ptr->base, buf_sprintf("pointer value not based on parent struct"));
22459 return ira->codegen->invalid_instruction;23370 return ira->codegen->invalid_inst_gen;
22460 }23371 }
2246123372
22462 size_t ptr_field_index = field_ptr_val->data.x_ptr.data.base_struct.field_index;23373 size_t ptr_field_index = field_ptr_val->data.x_ptr.data.base_struct.field_index;
22463 if (ptr_field_index != field->src_index) {23374 if (ptr_field_index != field->src_index) {
22464 ir_add_error(ira, &instruction->base,23375 ir_add_error(ira, &instruction->base.base,
22465 buf_sprintf("field '%s' has index %" ZIG_PRI_usize " but pointer value is index %" ZIG_PRI_usize " of struct '%s'",23376 buf_sprintf("field '%s' has index %" ZIG_PRI_usize " but pointer value is index %" ZIG_PRI_usize " of struct '%s'",
22466 buf_ptr(field->name), field->src_index,23377 buf_ptr(field->name), field->src_index,
22467 ptr_field_index, buf_ptr(&container_type->name)));23378 ptr_field_index, buf_ptr(&container_type->name)));
22468 return ira->codegen->invalid_instruction;23379 return ira->codegen->invalid_inst_gen;
22469 }23380 }
2247023381
22471 IrInstruction *result = ir_const(ira, &instruction->base, result_type);23382 IrInstGen *result = ir_const(ira, &instruction->base.base, result_type);
22472 ZigValue *out_val = result->value;23383 ZigValue *out_val = result->value;
22473 out_val->data.x_ptr.special = ConstPtrSpecialRef;23384 out_val->data.x_ptr.special = ConstPtrSpecialRef;
22474 out_val->data.x_ptr.data.ref.pointee = field_ptr_val->data.x_ptr.data.base_struct.struct_val;23385 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,...@@ -22476,15 +23387,12 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
22476 return result;23387 return result;
22477 }23388 }
2247823389
22479 IrInstruction *result = ir_build_field_parent_ptr(&ira->new_irb, instruction->base.scope,23390 return ir_build_field_parent_ptr_gen(ira, &instruction->base.base, casted_field_ptr, field, result_type);
22480 instruction->base.source_node, type_value, field_name_value, casted_field_ptr, field);
22481 result->value->type = result_type;
22482 return result;
22483}23391}
2248423392
22485static TypeStructField *validate_byte_offset(IrAnalyze *ira,23393static TypeStructField *validate_byte_offset(IrAnalyze *ira,
22486 IrInstruction *type_value,23394 IrInstGen *type_value,
22487 IrInstruction *field_name_value,23395 IrInstGen *field_name_value,
22488 size_t *byte_offset)23396 size_t *byte_offset)
22489{23397{
22490 ZigType *container_type = ir_resolve_type(ira, type_value);23398 ZigType *container_type = ir_resolve_type(ira, type_value);
...@@ -22500,21 +23408,21 @@ static TypeStructField *validate_byte_offset(IrAnalyze *ira,...@@ -22500,21 +23408,21 @@ static TypeStructField *validate_byte_offset(IrAnalyze *ira,
22500 return nullptr;23408 return nullptr;
2250123409
22502 if (container_type->id != ZigTypeIdStruct) {23410 if (container_type->id != ZigTypeIdStruct) {
22503 ir_add_error(ira, type_value,23411 ir_add_error(ira, &type_value->base,
22504 buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name)));23412 buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name)));
22505 return nullptr;23413 return nullptr;
22506 }23414 }
2250723415
22508 TypeStructField *field = find_struct_type_field(container_type, field_name);23416 TypeStructField *field = find_struct_type_field(container_type, field_name);
22509 if (field == nullptr) {23417 if (field == nullptr) {
22510 ir_add_error(ira, field_name_value,23418 ir_add_error(ira, &field_name_value->base,
22511 buf_sprintf("struct '%s' has no field '%s'",23419 buf_sprintf("struct '%s' has no field '%s'",
22512 buf_ptr(&container_type->name), buf_ptr(field_name)));23420 buf_ptr(&container_type->name), buf_ptr(field_name)));
22513 return nullptr;23421 return nullptr;
22514 }23422 }
2251523423
22516 if (!type_has_bits(field->type_entry)) {23424 if (!type_has_bits(field->type_entry)) {
22517 ir_add_error(ira, field_name_value,23425 ir_add_error(ira, &field_name_value->base,
22518 buf_sprintf("zero-bit field '%s' in struct '%s' has no offset",23426 buf_sprintf("zero-bit field '%s' in struct '%s' has no offset",
22519 buf_ptr(field_name), buf_ptr(&container_type->name)));23427 buf_ptr(field_name), buf_ptr(&container_type->name)));
22520 return nullptr;23428 return nullptr;
...@@ -22524,36 +23432,32 @@ static TypeStructField *validate_byte_offset(IrAnalyze *ira,...@@ -22524,36 +23432,32 @@ static TypeStructField *validate_byte_offset(IrAnalyze *ira,
22524 return field;23432 return field;
22525}23433}
2252623434
22527static IrInstruction *ir_analyze_instruction_byte_offset_of(IrAnalyze *ira,23435static IrInstGen *ir_analyze_instruction_byte_offset_of(IrAnalyze *ira, IrInstSrcByteOffsetOf *instruction) {
22528 IrInstructionByteOffsetOf *instruction)23436 IrInstGen *type_value = instruction->type_value->child;
22529{
22530 IrInstruction *type_value = instruction->type_value->child;
22531 if (type_is_invalid(type_value->value->type))23437 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;
22535 size_t byte_offset = 0;23441 size_t byte_offset = 0;
22536 if (!validate_byte_offset(ira, type_value, field_name_value, &byte_offset))23442 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);
22541}23447}
2254223448
22543static IrInstruction *ir_analyze_instruction_bit_offset_of(IrAnalyze *ira,23449static IrInstGen *ir_analyze_instruction_bit_offset_of(IrAnalyze *ira, IrInstSrcBitOffsetOf *instruction) {
22544 IrInstructionBitOffsetOf *instruction)23450 IrInstGen *type_value = instruction->type_value->child;
22545{
22546 IrInstruction *type_value = instruction->type_value->child;
22547 if (type_is_invalid(type_value->value->type))23451 if (type_is_invalid(type_value->value->type))
22548 return ira->codegen->invalid_instruction;23452 return ira->codegen->invalid_inst_gen;
22549 IrInstruction *field_name_value = instruction->field_name->child;23453 IrInstGen *field_name_value = instruction->field_name->child;
22550 size_t byte_offset = 0;23454 size_t byte_offset = 0;
22551 TypeStructField *field = nullptr;23455 TypeStructField *field = nullptr;
22552 if (!(field = validate_byte_offset(ira, type_value, field_name_value, &byte_offset)))23456 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
22555 size_t bit_offset = byte_offset * 8 + field->bit_offset_in_host;23459 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);
22557}23461}
2255823462
22559static void ensure_field_index(ZigType *type, const char *field_name, size_t index) {23463static 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...@@ -22601,7 +23505,7 @@ static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, Zig
22601 return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, nullptr, var->const_value);23505 return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, nullptr, var->const_value);
22602}23506}
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,
22605 ScopeDecls *decls_scope)23509 ScopeDecls *decls_scope)
22606{23510{
22607 Error err;23511 Error err;
...@@ -22959,7 +23863,7 @@ static void make_enum_field_val(IrAnalyze *ira, ZigValue *enum_field_val, TypeEn...@@ -22959,7 +23863,7 @@ static void make_enum_field_val(IrAnalyze *ira, ZigValue *enum_field_val, TypeEn
22959 enum_field_val->data.x_struct.fields = inner_fields;23863 enum_field_val->data.x_struct.fields = inner_fields;
22960}23864}
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,
22963 ZigValue **out)23867 ZigValue **out)
22964{23868{
22965 Error err;23869 Error err;
...@@ -23547,22 +24451,20 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -23547,22 +24451,20 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
23547 return ErrorNone;24451 return ErrorNone;
23548}24452}
2354924453
23550static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira,24454static IrInstGen *ir_analyze_instruction_type_info(IrAnalyze *ira, IrInstSrcTypeInfo *instruction) {
23551 IrInstructionTypeInfo *instruction)
23552{
23553 Error err;24455 Error err;
23554 IrInstruction *type_value = instruction->type_value->child;24456 IrInstGen *type_value = instruction->type_value->child;
23555 ZigType *type_entry = ir_resolve_type(ira, type_value);24457 ZigType *type_entry = ir_resolve_type(ira, type_value);
23556 if (type_is_invalid(type_entry))24458 if (type_is_invalid(type_entry))
23557 return ira->codegen->invalid_instruction;24459 return ira->codegen->invalid_inst_gen;
2355824460
23559 ZigType *result_type = ir_type_info_get_type(ira, nullptr, nullptr);24461 ZigType *result_type = ir_type_info_get_type(ira, nullptr, nullptr);
2356024462
23561 ZigValue *payload;24463 ZigValue *payload;
23562 if ((err = ir_make_type_info_value(ira, &instruction->base, type_entry, &payload)))24464 if ((err = ir_make_type_info_value(ira, &instruction->base.base, type_entry, &payload)))
23563 return ira->codegen->invalid_instruction;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);
23566 ZigValue *out_val = result->value;24468 ZigValue *out_val = result->value;
23567 bigint_init_unsigned(&out_val->data.x_union.tag, type_id_index(type_entry));24469 bigint_init_unsigned(&out_val->data.x_union.tag, type_id_index(type_entry));
23568 out_val->data.x_union.payload = payload;24470 out_val->data.x_union.payload = payload;
...@@ -23586,15 +24488,15 @@ static ZigValue *get_const_field(IrAnalyze *ira, AstNode *source_node, ZigValue...@@ -23586,15 +24488,15 @@ static ZigValue *get_const_field(IrAnalyze *ira, AstNode *source_node, ZigValue
23586 return val;24488 return val;
23587}24489}
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,
23590 const char *name, size_t field_index, ZigType *elem_type, ZigValue **result)24492 const char *name, size_t field_index, ZigType *elem_type, ZigValue **result)
23591{24493{
23592 ZigValue *field_val = get_const_field(ira, source_instr->source_node, struct_value, name, field_index);24494 ZigValue *field_val = get_const_field(ira, source_instr->source_node, struct_value, name, field_index);
23593 if (field_val == nullptr)24495 if (field_val == nullptr)
23594 return ErrorSemanticAnalyzeFail;24496 return ErrorSemanticAnalyzeFail;
2359524497
23596 IrInstruction *field_inst = ir_const_move(ira, source_instr, field_val);24498 IrInstGen *field_inst = ir_const_move(ira, source_instr, field_val);
23597 IrInstruction *casted_field_inst = ir_implicit_cast(ira, field_inst,24499 IrInstGen *casted_field_inst = ir_implicit_cast(ira, field_inst,
23598 get_optional_type(ira->codegen, elem_type));24500 get_optional_type(ira->codegen, elem_type));
23599 if (type_is_invalid(casted_field_inst->value->type))24501 if (type_is_invalid(casted_field_inst->value->type))
23600 return ErrorSemanticAnalyzeFail;24502 return ErrorSemanticAnalyzeFail;
...@@ -23633,12 +24535,12 @@ static ZigType *get_const_field_meta_type(IrAnalyze *ira, AstNode *source_node,...@@ -23633,12 +24535,12 @@ static ZigType *get_const_field_meta_type(IrAnalyze *ira, AstNode *source_node,
23633{24535{
23634 ZigValue *value = get_const_field(ira, source_node, struct_value, name, field_index);24536 ZigValue *value = get_const_field(ira, source_node, struct_value, name, field_index);
23635 if (value == nullptr)24537 if (value == nullptr)
23636 return ira->codegen->invalid_instruction->value->type;24538 return ira->codegen->invalid_inst_gen->value->type;
23637 assert(value->type == ira->codegen->builtin_types.entry_type);24539 assert(value->type == ira->codegen->builtin_types.entry_type);
23638 return value->data.x_type;24540 return value->data.x_type;
23639}24541}
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) {
23642 Error err;24544 Error err;
23643 switch (tagTypeId) {24545 switch (tagTypeId) {
23644 case ZigTypeIdInvalid:24546 case ZigTypeIdInvalid:
...@@ -23654,21 +24556,21 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi...@@ -23654,21 +24556,21 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
23654 case ZigTypeIdInt: {24556 case ZigTypeIdInt: {
23655 assert(payload->special == ConstValSpecialStatic);24557 assert(payload->special == ConstValSpecialStatic);
23656 assert(payload->type == ir_type_info_get_type(ira, "Int", nullptr));24558 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);
23658 if (bi == nullptr)24560 if (bi == nullptr)
23659 return ira->codegen->invalid_instruction->value->type;24561 return ira->codegen->invalid_inst_gen->value->type;
23660 bool is_signed;24562 bool is_signed;
23661 if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_signed", 0, &is_signed)))24563 if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_signed", 0, &is_signed)))
23662 return ira->codegen->invalid_instruction->value->type;24564 return ira->codegen->invalid_inst_gen->value->type;
23663 return get_int_type(ira->codegen, is_signed, bigint_as_u32(bi));24565 return get_int_type(ira->codegen, is_signed, bigint_as_u32(bi));
23664 }24566 }
23665 case ZigTypeIdFloat:24567 case ZigTypeIdFloat:
23666 {24568 {
23667 assert(payload->special == ConstValSpecialStatic);24569 assert(payload->special == ConstValSpecialStatic);
23668 assert(payload->type == ir_type_info_get_type(ira, "Float", nullptr));24570 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);
23670 if (bi == nullptr)24572 if (bi == nullptr)
23671 return ira->codegen->invalid_instruction->value->type;24573 return ira->codegen->invalid_inst_gen->value->type;
23672 uint32_t bits = bigint_as_u32(bi);24574 uint32_t bits = bigint_as_u32(bi);
23673 switch (bits) {24575 switch (bits) {
23674 case 16: return ira->codegen->builtin_types.entry_f16;24576 case 16: return ira->codegen->builtin_types.entry_f16;
...@@ -23676,48 +24578,47 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi...@@ -23676,48 +24578,47 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
23676 case 64: return ira->codegen->builtin_types.entry_f64;24578 case 64: return ira->codegen->builtin_types.entry_f64;
23677 case 128: return ira->codegen->builtin_types.entry_f128;24579 case 128: return ira->codegen->builtin_types.entry_f128;
23678 }24580 }
23679 ir_add_error(ira, instruction,24581 ir_add_error(ira, source_instr, buf_sprintf("%d-bit float unsupported", bits));
23680 buf_sprintf("%d-bit float unsupported", bits));24582 return ira->codegen->invalid_inst_gen->value->type;
23681 return ira->codegen->invalid_instruction->value->type;
23682 }24583 }
23683 case ZigTypeIdPointer:24584 case ZigTypeIdPointer:
23684 {24585 {
23685 ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);24586 ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);
23686 assert(payload->special == ConstValSpecialStatic);24587 assert(payload->special == ConstValSpecialStatic);
23687 assert(payload->type == type_info_pointer_type);24588 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);
23689 assert(size_value->type == ir_type_info_get_type(ira, "Size", type_info_pointer_type));24590 assert(size_value->type == ir_type_info_get_type(ira, "Size", type_info_pointer_type));
23690 BuiltinPtrSize size_enum_index = (BuiltinPtrSize)bigint_as_u32(&size_value->data.x_enum_tag);24591 BuiltinPtrSize size_enum_index = (BuiltinPtrSize)bigint_as_u32(&size_value->data.x_enum_tag);
23691 PtrLen ptr_len = size_enum_index_to_ptr_len(size_enum_index);24592 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);
23693 if (type_is_invalid(elem_type))24594 if (type_is_invalid(elem_type))
23694 return ira->codegen->invalid_instruction->value->type;24595 return ira->codegen->invalid_inst_gen->value->type;
23695 ZigValue *sentinel;24596 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,
23697 elem_type, &sentinel)))24598 elem_type, &sentinel)))
23698 {24599 {
23699 return ira->codegen->invalid_instruction->value->type;24600 return ira->codegen->invalid_inst_gen->value->type;
23700 }24601 }
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);
23702 if (bi == nullptr)24603 if (bi == nullptr)
23703 return ira->codegen->invalid_instruction->value->type;24604 return ira->codegen->invalid_inst_gen->value->type;
2370424605
23705 bool is_const;24606 bool is_const;
23706 if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_const", 1, &is_const)))24607 if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_const", 1, &is_const)))
23707 return ira->codegen->invalid_instruction->value->type;24608 return ira->codegen->invalid_inst_gen->value->type;
2370824609
23709 bool is_volatile;24610 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,
23711 &is_volatile)))24612 &is_volatile)))
23712 {24613 {
23713 return ira->codegen->invalid_instruction->value->type;24614 return ira->codegen->invalid_inst_gen->value->type;
23714 }24615 }
2371524616
23716 bool is_allowzero;24617 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,
23718 &is_allowzero)))24619 &is_allowzero)))
23719 {24620 {
23720 return ira->codegen->invalid_instruction->value->type;24621 return ira->codegen->invalid_inst_gen->value->type;
23721 }24622 }
2372224623
2372324624
...@@ -23738,18 +24639,18 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi...@@ -23738,18 +24639,18 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
23738 case ZigTypeIdArray: {24639 case ZigTypeIdArray: {
23739 assert(payload->special == ConstValSpecialStatic);24640 assert(payload->special == ConstValSpecialStatic);
23740 assert(payload->type == ir_type_info_get_type(ira, "Array", nullptr));24641 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);
23742 if (type_is_invalid(elem_type))24643 if (type_is_invalid(elem_type))
23743 return ira->codegen->invalid_instruction->value->type;24644 return ira->codegen->invalid_inst_gen->value->type;
23744 ZigValue *sentinel;24645 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,
23746 elem_type, &sentinel)))24647 elem_type, &sentinel)))
23747 {24648 {
23748 return ira->codegen->invalid_instruction->value->type;24649 return ira->codegen->invalid_inst_gen->value->type;
23749 }24650 }
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);
23751 if (bi == nullptr)24652 if (bi == nullptr)
23752 return ira->codegen->invalid_instruction->value->type;24653 return ira->codegen->invalid_inst_gen->value->type;
23753 return get_array_type(ira->codegen, elem_type, bigint_as_u64(bi), sentinel);24654 return get_array_type(ira->codegen, elem_type, bigint_as_u64(bi), sentinel);
23754 }24655 }
23755 case ZigTypeIdComptimeFloat:24656 case ZigTypeIdComptimeFloat:
...@@ -23769,78 +24670,77 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi...@@ -23769,78 +24670,77 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
23769 case ZigTypeIdAnyFrame:24670 case ZigTypeIdAnyFrame:
23770 case ZigTypeIdVector:24671 case ZigTypeIdVector:
23771 case ZigTypeIdEnumLiteral:24672 case ZigTypeIdEnumLiteral:
23772 ir_add_error(ira, instruction, buf_sprintf(24673 ir_add_error(ira, source_instr, buf_sprintf(
23773 "TODO implement @Type for 'TypeInfo.%s': see https://github.com/ziglang/zig/issues/2907", type_id_name(tagTypeId)));24674 "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;
23775 case ZigTypeIdUnion:24676 case ZigTypeIdUnion:
23776 case ZigTypeIdFn:24677 case ZigTypeIdFn:
23777 case ZigTypeIdBoundFn:24678 case ZigTypeIdBoundFn:
23778 case ZigTypeIdStruct:24679 case ZigTypeIdStruct:
23779 ir_add_error(ira, instruction, buf_sprintf(24680 ir_add_error(ira, source_instr, buf_sprintf(
23780 "@Type not availble for 'TypeInfo.%s'", type_id_name(tagTypeId)));24681 "@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;
23782 }24683 }
23783 zig_unreachable();24684 zig_unreachable();
23784}24685}
2378524686
23786static IrInstruction *ir_analyze_instruction_type(IrAnalyze *ira, IrInstructionType *instruction) {24687static IrInstGen *ir_analyze_instruction_type(IrAnalyze *ira, IrInstSrcType *instruction) {
23787 IrInstruction *type_info_ir = instruction->type_info->child;24688 IrInstGen *uncasted_type_info = instruction->type_info->child;
23788 if (type_is_invalid(type_info_ir->value->type))24689 if (type_is_invalid(uncasted_type_info->value->type))
23789 return ira->codegen->invalid_instruction;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));24692 IrInstGen *type_info = ir_implicit_cast(ira, uncasted_type_info, ir_type_info_get_type(ira, nullptr, nullptr));
23792 if (type_is_invalid(casted_ir->value->type))24693 if (type_is_invalid(type_info->value->type))
23793 return ira->codegen->invalid_instruction;24694 return ira->codegen->invalid_inst_gen;
2379424695
23795 ZigValue *type_info_value = ir_resolve_const(ira, casted_ir, UndefBad);24696 ZigValue *type_info_val = ir_resolve_const(ira, type_info, UndefBad);
23796 if (!type_info_value)24697 if (type_info_val == nullptr)
23797 return ira->codegen->invalid_instruction;24698 return ira->codegen->invalid_inst_gen;
23798 ZigTypeId typeId = type_id_at_index(bigint_as_usize(&type_info_value->data.x_union.tag));24699 ZigTypeId type_id_tag = type_id_at_index(bigint_as_usize(&type_info_val->data.x_union.tag));
23799 ZigType *type = type_info_to_type(ira, type_info_ir, typeId, type_info_value->data.x_union.payload);24700 ZigType *type = type_info_to_type(ira, &uncasted_type_info->base, type_id_tag,
24701 type_info_val->data.x_union.payload);
23800 if (type_is_invalid(type))24702 if (type_is_invalid(type))
23801 return ira->codegen->invalid_instruction;24703 return ira->codegen->invalid_inst_gen;
23802 return ir_const_type(ira, &instruction->base, type);24704 return ir_const_type(ira, &instruction->base.base, type);
23803}24705}
2380424706
23805static IrInstruction *ir_analyze_instruction_type_id(IrAnalyze *ira,24707static IrInstGen *ir_analyze_instruction_type_id(IrAnalyze *ira, IrInstSrcTypeId *instruction) {
23806 IrInstructionTypeId *instruction)24708 IrInstGen *type_value = instruction->type_value->child;
23807{
23808 IrInstruction *type_value = instruction->type_value->child;
23809 ZigType *type_entry = ir_resolve_type(ira, type_value);24709 ZigType *type_entry = ir_resolve_type(ira, type_value);
23810 if (type_is_invalid(type_entry))24710 if (type_is_invalid(type_entry))
23811 return ira->codegen->invalid_instruction;24711 return ira->codegen->invalid_inst_gen;
2381224712
23813 ZigType *result_type = get_builtin_type(ira->codegen, "TypeId");24713 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);
23816 bigint_init_unsigned(&result->value->data.x_enum_tag, type_id_index(type_entry));24716 bigint_init_unsigned(&result->value->data.x_enum_tag, type_id_index(type_entry));
23817 return result;24717 return result;
23818}24718}
2381924719
23820static IrInstruction *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira,24720static IrInstGen *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira,
23821 IrInstructionSetEvalBranchQuota *instruction)24721 IrInstSrcSetEvalBranchQuota *instruction)
23822{24722{
23823 uint64_t new_quota;24723 uint64_t new_quota;
23824 if (!ir_resolve_usize(ira, instruction->new_quota->child, &new_quota))24724 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
23827 if (new_quota > *ira->new_irb.exec->backward_branch_quota) {24727 if (new_quota > *ira->new_irb.exec->backward_branch_quota) {
23828 *ira->new_irb.exec->backward_branch_quota = new_quota;24728 *ira->new_irb.exec->backward_branch_quota = new_quota;
23829 }24729 }
2383024730
23831 return ir_const_void(ira, &instruction->base);24731 return ir_const_void(ira, &instruction->base.base);
23832}24732}
2383324733
23834static IrInstruction *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstructionTypeName *instruction) {24734static IrInstGen *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstSrcTypeName *instruction) {
23835 IrInstruction *type_value = instruction->type_value->child;24735 IrInstGen *type_value = instruction->type_value->child;
23836 ZigType *type_entry = ir_resolve_type(ira, type_value);24736 ZigType *type_entry = ir_resolve_type(ira, type_value);
23837 if (type_is_invalid(type_entry))24737 if (type_is_invalid(type_entry))
23838 return ira->codegen->invalid_instruction;24738 return ira->codegen->invalid_inst_gen;
2383924739
23840 if (!type_entry->cached_const_name_val) {24740 if (!type_entry->cached_const_name_val) {
23841 type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, type_bare_name(type_entry));24741 type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, type_bare_name(type_entry));
23842 }24742 }
23843 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);24743 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
23844 copy_const_val(result->value, type_entry->cached_const_name_val);24744 copy_const_val(result->value, type_entry->cached_const_name_val);
23845 return result;24745 return result;
23846}24746}
...@@ -23852,13 +24752,13 @@ static void ir_cimport_cache_paths(Buf *cache_dir, Buf *tmp_c_file_digest, Buf *...@@ -23852,13 +24752,13 @@ static void ir_cimport_cache_paths(Buf *cache_dir, Buf *tmp_c_file_digest, Buf *
23852 buf_ptr(cache_dir), buf_ptr(tmp_c_file_digest));24752 buf_ptr(cache_dir), buf_ptr(tmp_c_file_digest));
23853 buf_appendf(out_zig_path, "%s" OS_SEP "cimport.zig", buf_ptr(out_zig_dir));24753 buf_appendf(out_zig_path, "%s" OS_SEP "cimport.zig", buf_ptr(out_zig_dir));
23854}24754}
23855static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstructionCImport *instruction) {24755static IrInstGen *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstSrcCImport *instruction) {
23856 Error err;24756 Error err;
23857 AstNode *node = instruction->base.source_node;24757 AstNode *node = instruction->base.base.source_node;
23858 assert(node->type == NodeTypeFnCallExpr);24758 assert(node->type == NodeTypeFnCallExpr);
23859 AstNode *block_node = node->data.fn_call_expr.params.at(0);24759 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
23863 // Execute the C import block like an inline function24763 // Execute the C import block like an inline function
23864 ZigType *void_type = ira->codegen->builtin_types.entry_void;24764 ZigType *void_type = ira->codegen->builtin_types.entry_void;
...@@ -23866,9 +24766,9 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct...@@ -23866,9 +24766,9 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
23866 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr,24766 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr,
23867 &cimport_scope->buf, block_node, nullptr, nullptr, nullptr, UndefBad);24767 &cimport_scope->buf, block_node, nullptr, nullptr, nullptr, UndefBad);
23868 if (type_is_invalid(cimport_result->type))24768 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);
23872 Buf *namespace_name = buf_sprintf("%s.cimport:%" ZIG_PRI_usize ":%" ZIG_PRI_usize,24772 Buf *namespace_name = buf_sprintf("%s.cimport:%" ZIG_PRI_usize ":%" ZIG_PRI_usize,
23873 buf_ptr(&cur_scope_pkg->pkg_path), node->line + 1, node->column + 1);24773 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...@@ -23880,7 +24780,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
23880 CacheHash *cache_hash;24780 CacheHash *cache_hash;
23881 if ((err = create_c_object_cache(ira->codegen, &cache_hash, false))) {24781 if ((err = create_c_object_cache(ira->codegen, &cache_hash, false))) {
23882 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to create cache: %s", err_str(err)));24782 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;
23884 }24784 }
23885 cache_buf(cache_hash, &cimport_scope->buf);24785 cache_buf(cache_hash, &cimport_scope->buf);
2388624786
...@@ -23892,7 +24792,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct...@@ -23892,7 +24792,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
23892 if ((err = cache_hit(cache_hash, &tmp_c_file_digest))) {24792 if ((err = cache_hit(cache_hash, &tmp_c_file_digest))) {
23893 if (err != ErrorInvalidFormat) {24793 if (err != ErrorInvalidFormat) {
23894 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to check cache: %s", err_str(err)));24794 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;
23896 }24796 }
23897 }24797 }
23898 ira->codegen->caches_to_release.append(cache_hash);24798 ira->codegen->caches_to_release.append(cache_hash);
...@@ -23911,12 +24811,12 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct...@@ -23911,12 +24811,12 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
2391124811
23912 if ((err = os_make_path(tmp_c_file_dir))) {24812 if ((err = os_make_path(tmp_c_file_dir))) {
23913 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to make dir: %s", err_str(err)));24813 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;
23915 }24815 }
2391624816
23917 if ((err = os_write_file(&tmp_c_file_path, &cimport_scope->buf))) {24817 if ((err = os_write_file(&tmp_c_file_path, &cimport_scope->buf))) {
23918 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to write .h file: %s", err_str(err)));24818 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;
23920 }24820 }
23921 if (ira->codegen->verbose_cimport) {24821 if (ira->codegen->verbose_cimport) {
23922 fprintf(stderr, "@cImport source: %s\n", buf_ptr(&tmp_c_file_path));24822 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...@@ -23951,7 +24851,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
23951 {24851 {
23952 if (err != ErrorCCompileErrors) {24852 if (err != ErrorCCompileErrors) {
23953 ir_add_error_node(ira, node, buf_sprintf("C import failed: %s", err_str(err)));24853 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;
23955 }24855 }
2395624856
23957 ErrorMsg *parent_err_msg = ir_add_error_node(ira, node, buf_sprintf("C import failed"));24857 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...@@ -23972,7 +24872,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
23972 }24872 }
23973 }24873 }
2397424874
23975 return ira->codegen->invalid_instruction;24875 return ira->codegen->invalid_inst_gen;
23976 }24876 }
23977 if (ira->codegen->verbose_cimport) {24877 if (ira->codegen->verbose_cimport) {
23978 fprintf(stderr, "@cImport .d file: %s\n", buf_ptr(tmp_dep_file));24878 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...@@ -23980,29 +24880,29 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
2398024880
23981 if ((err = cache_add_dep_file(cache_hash, tmp_dep_file, false))) {24881 if ((err = cache_add_dep_file(cache_hash, tmp_dep_file, false))) {
23982 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to parse .d file: %s", err_str(err)));24882 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;
23984 }24884 }
23985 if ((err = cache_final(cache_hash, &tmp_c_file_digest))) {24885 if ((err = cache_final(cache_hash, &tmp_c_file_digest))) {
23986 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to finalize cache: %s", err_str(err)));24886 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;
23988 }24888 }
2398924889
23990 ir_cimport_cache_paths(ira->codegen->cache_dir, &tmp_c_file_digest, out_zig_dir, out_zig_path);24890 ir_cimport_cache_paths(ira->codegen->cache_dir, &tmp_c_file_digest, out_zig_dir, out_zig_path);
23991 if ((err = os_make_path(out_zig_dir))) {24891 if ((err = os_make_path(out_zig_dir))) {
23992 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to make output dir: %s", err_str(err)));24892 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;
23994 }24894 }
23995 FILE *out_file = fopen(buf_ptr(out_zig_path), "wb");24895 FILE *out_file = fopen(buf_ptr(out_zig_path), "wb");
23996 if (out_file == nullptr) {24896 if (out_file == nullptr) {
23997 ir_add_error_node(ira, node,24897 ir_add_error_node(ira, node,
23998 buf_sprintf("C import failed: unable to open output file: %s", strerror(errno)));24898 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;
24000 }24900 }
24001 stage2_render_ast(ast, out_file);24901 stage2_render_ast(ast, out_file);
24002 if (fclose(out_file) != 0) {24902 if (fclose(out_file) != 0) {
24003 ir_add_error_node(ira, node,24903 ir_add_error_node(ira, node,
24004 buf_sprintf("C import failed: unable to write to output file: %s", strerror(errno)));24904 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;
24006 }24906 }
2400724907
24008 if (ira->codegen->verbose_cimport) {24908 if (ira->codegen->verbose_cimport) {
...@@ -24021,90 +24921,90 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct...@@ -24021,90 +24921,90 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
24021 if ((err = file_fetch(ira->codegen, out_zig_path, import_code))) {24921 if ((err = file_fetch(ira->codegen, out_zig_path, import_code))) {
24022 ir_add_error_node(ira, node,24922 ir_add_error_node(ira, node,
24023 buf_sprintf("unable to open '%s': %s", buf_ptr(out_zig_path), err_str(err)));24923 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;
24025 }24925 }
24026 ZigType *child_import = add_source_file(ira->codegen, cimport_pkg, out_zig_path,24926 ZigType *child_import = add_source_file(ira->codegen, cimport_pkg, out_zig_path,
24027 import_code, SourceKindCImport);24927 import_code, SourceKindCImport);
24028 return ir_const_type(ira, &instruction->base, child_import);24928 return ir_const_type(ira, &instruction->base.base, child_import);
24029}24929}
2403024930
24031static IrInstruction *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstructionCInclude *instruction) {24931static IrInstGen *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstSrcCInclude *instruction) {
24032 IrInstruction *name_value = instruction->name->child;24932 IrInstGen *name_value = instruction->name->child;
24033 if (type_is_invalid(name_value->value->type))24933 if (type_is_invalid(name_value->value->type))
24034 return ira->codegen->invalid_instruction;24934 return ira->codegen->invalid_inst_gen;
2403524935
24036 Buf *include_name = ir_resolve_str(ira, name_value);24936 Buf *include_name = ir_resolve_str(ira, name_value);
24037 if (!include_name)24937 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;
24041 // We check for this error in pass124941 // We check for this error in pass1
24042 assert(c_import_buf);24942 assert(c_import_buf);
2404324943
24044 buf_appendf(c_import_buf, "#include <%s>\n", buf_ptr(include_name));24944 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);
24047}24947}
2404824948
24049static IrInstruction *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstructionCDefine *instruction) {24949static IrInstGen *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstSrcCDefine *instruction) {
24050 IrInstruction *name = instruction->name->child;24950 IrInstGen *name = instruction->name->child;
24051 if (type_is_invalid(name->value->type))24951 if (type_is_invalid(name->value->type))
24052 return ira->codegen->invalid_instruction;24952 return ira->codegen->invalid_inst_gen;
2405324953
24054 Buf *define_name = ir_resolve_str(ira, name);24954 Buf *define_name = ir_resolve_str(ira, name);
24055 if (!define_name)24955 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;
24059 if (type_is_invalid(value->value->type))24959 if (type_is_invalid(value->value->type))
24060 return ira->codegen->invalid_instruction;24960 return ira->codegen->invalid_inst_gen;
2406124961
24062 Buf *define_value = nullptr;24962 Buf *define_value = nullptr;
24063 // The second parameter is either a string or void (equivalent to "")24963 // The second parameter is either a string or void (equivalent to "")
24064 if (value->value->type->id != ZigTypeIdVoid) {24964 if (value->value->type->id != ZigTypeIdVoid) {
24065 define_value = ir_resolve_str(ira, value);24965 define_value = ir_resolve_str(ira, value);
24066 if (!define_value)24966 if (!define_value)
24067 return ira->codegen->invalid_instruction;24967 return ira->codegen->invalid_inst_gen;
24068 }24968 }
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;
24071 // We check for this error in pass124971 // We check for this error in pass1
24072 assert(c_import_buf);24972 assert(c_import_buf);
2407324973
24074 buf_appendf(c_import_buf, "#define %s %s\n", buf_ptr(define_name),24974 buf_appendf(c_import_buf, "#define %s %s\n", buf_ptr(define_name),
24075 define_value ? buf_ptr(define_value) : "");24975 define_value ? buf_ptr(define_value) : "");
2407624976
24077 return ir_const_void(ira, &instruction->base);24977 return ir_const_void(ira, &instruction->base.base);
24078}24978}
2407924979
24080static IrInstruction *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructionCUndef *instruction) {24980static IrInstGen *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstSrcCUndef *instruction) {
24081 IrInstruction *name = instruction->name->child;24981 IrInstGen *name = instruction->name->child;
24082 if (type_is_invalid(name->value->type))24982 if (type_is_invalid(name->value->type))
24083 return ira->codegen->invalid_instruction;24983 return ira->codegen->invalid_inst_gen;
2408424984
24085 Buf *undef_name = ir_resolve_str(ira, name);24985 Buf *undef_name = ir_resolve_str(ira, name);
24086 if (!undef_name)24986 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;
24090 // We check for this error in pass124990 // We check for this error in pass1
24091 assert(c_import_buf);24991 assert(c_import_buf);
2409224992
24093 buf_appendf(c_import_buf, "#undef %s\n", buf_ptr(undef_name));24993 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);
24096}24996}
2409724997
24098static IrInstruction *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstructionEmbedFile *instruction) {24998static IrInstGen *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstSrcEmbedFile *instruction) {
24099 IrInstruction *name = instruction->name->child;24999 IrInstGen *name = instruction->name->child;
24100 if (type_is_invalid(name->value->type))25000 if (type_is_invalid(name->value->type))
24101 return ira->codegen->invalid_instruction;25001 return ira->codegen->invalid_inst_gen;
2410225002
24103 Buf *rel_file_path = ir_resolve_str(ira, name);25003 Buf *rel_file_path = ir_resolve_str(ira, name);
24104 if (!rel_file_path)25004 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);
24108 // figure out absolute path to resource25008 // figure out absolute path to resource
24109 Buf source_dir_path = BUF_INIT;25009 Buf source_dir_path = BUF_INIT;
24110 os_path_dirname(import->data.structure.root_struct->path, &source_dir_path);25010 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...@@ -24121,93 +25021,95 @@ static IrInstruction *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstru
24121 Error err;25021 Error err;
24122 if ((err = file_fetch(ira->codegen, file_path, file_contents))) {25022 if ((err = file_fetch(ira->codegen, file_path, file_contents))) {
24123 if (err == ErrorFileNotFound) {25023 if (err == ErrorFileNotFound) {
24124 ir_add_error(ira, instruction->name, buf_sprintf("unable to find '%s'", buf_ptr(file_path)));25024 ir_add_error(ira, &instruction->name->base,
24125 return ira->codegen->invalid_instruction;25025 buf_sprintf("unable to find '%s'", buf_ptr(file_path)));
25026 return ira->codegen->invalid_inst_gen;
24126 } else {25027 } else {
24127 ir_add_error(ira, instruction->name, buf_sprintf("unable to open '%s': %s", buf_ptr(file_path), err_str(err)));25028 ir_add_error(ira, &instruction->name->base,
24128 return ira->codegen->invalid_instruction;25029 buf_sprintf("unable to open '%s': %s", buf_ptr(file_path), err_str(err)));
25030 return ira->codegen->invalid_inst_gen;
24129 }25031 }
24130 }25032 }
2413125033
24132 ZigType *result_type = get_array_type(ira->codegen,25034 ZigType *result_type = get_array_type(ira->codegen,
24133 ira->codegen->builtin_types.entry_u8, buf_len(file_contents), nullptr);25035 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);
24135 init_const_str_lit(ira->codegen, result->value, file_contents);25037 init_const_str_lit(ira->codegen, result->value, file_contents);
24136 return result;25038 return result;
24137}25039}
2413825040
24139static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructionCmpxchgSrc *instruction) {25041static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxchg *instruction) {
24140 ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->type_value->child);25042 ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->type_value->child);
24141 if (type_is_invalid(operand_type))25043 if (type_is_invalid(operand_type))
24142 return ira->codegen->invalid_instruction;25044 return ira->codegen->invalid_inst_gen;
2414325045
24144 if (operand_type->id == ZigTypeIdFloat) {25046 if (operand_type->id == ZigTypeIdFloat) {
24145 ir_add_error(ira, instruction->type_value->child,25047 ir_add_error(ira, &instruction->type_value->child->base,
24146 buf_sprintf("expected integer, enum or pointer type, found '%s'", buf_ptr(&operand_type->name)));25048 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;
24148 }25050 }
2414925051
24150 IrInstruction *ptr = instruction->ptr->child;25052 IrInstGen *ptr = instruction->ptr->child;
24151 if (type_is_invalid(ptr->value->type))25053 if (type_is_invalid(ptr->value->type))
24152 return ira->codegen->invalid_instruction;25054 return ira->codegen->invalid_inst_gen;
2415325055
24154 // TODO let this be volatile25056 // TODO let this be volatile
24155 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);25057 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);
24157 if (type_is_invalid(casted_ptr->value->type))25059 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;
24161 if (type_is_invalid(cmp_value->value->type))25063 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;
24165 if (type_is_invalid(new_value->value->type))25067 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;
24169 if (type_is_invalid(success_order_value->value->type))25071 if (type_is_invalid(success_order_value->value->type))
24170 return ira->codegen->invalid_instruction;25072 return ira->codegen->invalid_inst_gen;
2417125073
24172 AtomicOrder success_order;25074 AtomicOrder success_order;
24173 if (!ir_resolve_atomic_order(ira, success_order_value, &success_order))25075 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;
24177 if (type_is_invalid(failure_order_value->value->type))25079 if (type_is_invalid(failure_order_value->value->type))
24178 return ira->codegen->invalid_instruction;25080 return ira->codegen->invalid_inst_gen;
2417925081
24180 AtomicOrder failure_order;25082 AtomicOrder failure_order;
24181 if (!ir_resolve_atomic_order(ira, failure_order_value, &failure_order))25083 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);
24185 if (type_is_invalid(casted_cmp_value->value->type))25087 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);
24189 if (type_is_invalid(casted_new_value->value->type))25091 if (type_is_invalid(casted_new_value->value->type))
24190 return ira->codegen->invalid_instruction;25092 return ira->codegen->invalid_inst_gen;
2419125093
24192 if (success_order < AtomicOrderMonotonic) {25094 if (success_order < AtomicOrderMonotonic) {
24193 ir_add_error(ira, success_order_value,25095 ir_add_error(ira, &success_order_value->base,
24194 buf_sprintf("success atomic ordering must be Monotonic or stricter"));25096 buf_sprintf("success atomic ordering must be Monotonic or stricter"));
24195 return ira->codegen->invalid_instruction;25097 return ira->codegen->invalid_inst_gen;
24196 }25098 }
24197 if (failure_order < AtomicOrderMonotonic) {25099 if (failure_order < AtomicOrderMonotonic) {
24198 ir_add_error(ira, failure_order_value,25100 ir_add_error(ira, &failure_order_value->base,
24199 buf_sprintf("failure atomic ordering must be Monotonic or stricter"));25101 buf_sprintf("failure atomic ordering must be Monotonic or stricter"));
24200 return ira->codegen->invalid_instruction;25102 return ira->codegen->invalid_inst_gen;
24201 }25103 }
24202 if (failure_order > success_order) {25104 if (failure_order > success_order) {
24203 ir_add_error(ira, failure_order_value,25105 ir_add_error(ira, &failure_order_value->base,
24204 buf_sprintf("failure atomic ordering must be no stricter than success"));25106 buf_sprintf("failure atomic ordering must be no stricter than success"));
24205 return ira->codegen->invalid_instruction;25107 return ira->codegen->invalid_inst_gen;
24206 }25108 }
24207 if (failure_order == AtomicOrderRelease || failure_order == AtomicOrderAcqRel) {25109 if (failure_order == AtomicOrderRelease || failure_order == AtomicOrderAcqRel) {
24208 ir_add_error(ira, failure_order_value,25110 ir_add_error(ira, &failure_order_value->base,
24209 buf_sprintf("failure atomic ordering must not be Release or AcqRel"));25111 buf_sprintf("failure atomic ordering must not be Release or AcqRel"));
24210 return ira->codegen->invalid_instruction;25112 return ira->codegen->invalid_inst_gen;
24211 }25113 }
2421225114
24213 if (instr_is_comptime(casted_ptr) && casted_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar &&25115 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...@@ -24216,66 +25118,63 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi
24216 }25118 }
2421725119
24218 ZigType *result_type = get_optional_type(ira->codegen, operand_type);25120 ZigType *result_type = get_optional_type(ira->codegen, operand_type);
24219 IrInstruction *result_loc;25121 IrInstGen *result_loc;
24220 if (handle_is_ptr(result_type)) {25122 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,
24222 result_type, nullptr, true, false, true);25124 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) {
24224 return result_loc;25126 return result_loc;
24225 }25127 }
24226 } else {25128 } else {
24227 result_loc = nullptr;25129 result_loc = nullptr;
24228 }25130 }
2422925131
24230 return ir_build_cmpxchg_gen(ira, &instruction->base, result_type,25132 return ir_build_cmpxchg_gen(ira, &instruction->base.base, result_type,
24231 casted_ptr, casted_cmp_value, casted_new_value,25133 casted_ptr, casted_cmp_value, casted_new_value,
24232 success_order, failure_order, instruction->is_weak, result_loc);25134 success_order, failure_order, instruction->is_weak, result_loc);
24233}25135}
2423425136
24235static IrInstruction *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructionFence *instruction) {25137static IrInstGen *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstSrcFence *instruction) {
24236 IrInstruction *order_value = instruction->order_value->child;25138 IrInstGen *order_inst = instruction->order->child;
24237 if (type_is_invalid(order_value->value->type))25139 if (type_is_invalid(order_inst->value->type))
24238 return ira->codegen->invalid_instruction;25140 return ira->codegen->invalid_inst_gen;
2423925141
24240 AtomicOrder order;25142 AtomicOrder order;
24241 if (!ir_resolve_atomic_order(ira, order_value, &order))25143 if (!ir_resolve_atomic_order(ira, order_inst, &order))
24242 return ira->codegen->invalid_instruction;25144 return ira->codegen->invalid_inst_gen;
2424325145
24244 if (order < AtomicOrderAcquire) {25146 if (order < AtomicOrderAcquire) {
24245 ir_add_error(ira, order_value,25147 ir_add_error(ira, &order_inst->base,
24246 buf_sprintf("atomic ordering must be Acquire or stricter"));25148 buf_sprintf("atomic ordering must be Acquire or stricter"));
24247 return ira->codegen->invalid_instruction;25149 return ira->codegen->invalid_inst_gen;
24248 }25150 }
2424925151
24250 IrInstruction *result = ir_build_fence(&ira->new_irb,25152 return ir_build_fence_gen(ira, &instruction->base.base, order);
24251 instruction->base.scope, instruction->base.source_node, order_value, order);
24252 result->value->type = ira->codegen->builtin_types.entry_void;
24253 return result;
24254}25153}
2425525154
24256static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstructionTruncate *instruction) {25155static IrInstGen *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstSrcTruncate *instruction) {
24257 IrInstruction *dest_type_value = instruction->dest_type->child;25156 IrInstGen *dest_type_value = instruction->dest_type->child;
24258 ZigType *dest_type = ir_resolve_type(ira, dest_type_value);25157 ZigType *dest_type = ir_resolve_type(ira, dest_type_value);
24259 if (type_is_invalid(dest_type))25158 if (type_is_invalid(dest_type))
24260 return ira->codegen->invalid_instruction;25159 return ira->codegen->invalid_inst_gen;
2426125160
24262 if (dest_type->id != ZigTypeIdInt &&25161 if (dest_type->id != ZigTypeIdInt &&
24263 dest_type->id != ZigTypeIdComptimeInt)25162 dest_type->id != ZigTypeIdComptimeInt)
24264 {25163 {
24265 ir_add_error(ira, dest_type_value, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));25164 ir_add_error(ira, &dest_type_value->base, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
24266 return ira->codegen->invalid_instruction;25165 return ira->codegen->invalid_inst_gen;
24267 }25166 }
2426825167
24269 IrInstruction *target = instruction->target->child;25168 IrInstGen *target = instruction->target->child;
24270 ZigType *src_type = target->value->type;25169 ZigType *src_type = target->value->type;
24271 if (type_is_invalid(src_type))25170 if (type_is_invalid(src_type))
24272 return ira->codegen->invalid_instruction;25171 return ira->codegen->invalid_inst_gen;
2427325172
24274 if (src_type->id != ZigTypeIdInt &&25173 if (src_type->id != ZigTypeIdInt &&
24275 src_type->id != ZigTypeIdComptimeInt)25174 src_type->id != ZigTypeIdComptimeInt)
24276 {25175 {
24277 ir_add_error(ira, target, buf_sprintf("expected integer type, found '%s'", buf_ptr(&src_type->name)));25176 ir_add_error(ira, &target->base, buf_sprintf("expected integer type, found '%s'", buf_ptr(&src_type->name)));
24278 return ira->codegen->invalid_instruction;25177 return ira->codegen->invalid_inst_gen;
24279 }25178 }
2428025179
24281 if (dest_type->id == ZigTypeIdComptimeInt) {25180 if (dest_type->id == ZigTypeIdComptimeInt) {
...@@ -24285,54 +25184,51 @@ static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruct...@@ -24285,54 +25184,51 @@ static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruct
24285 if (instr_is_comptime(target)) {25184 if (instr_is_comptime(target)) {
24286 ZigValue *val = ir_resolve_const(ira, target, UndefBad);25185 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
24287 if (val == nullptr)25186 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);
24291 bigint_truncate(&result->value->data.x_bigint, &val->data.x_bigint,25190 bigint_truncate(&result->value->data.x_bigint, &val->data.x_bigint,
24292 dest_type->data.integral.bit_count, dest_type->data.integral.is_signed);25191 dest_type->data.integral.bit_count, dest_type->data.integral.is_signed);
24293 return result;25192 return result;
24294 }25193 }
2429525194
24296 if (src_type->data.integral.bit_count == 0 || dest_type->data.integral.bit_count == 0) {25195 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);
24298 bigint_init_unsigned(&result->value->data.x_bigint, 0);25197 bigint_init_unsigned(&result->value->data.x_bigint, 0);
24299 return result;25198 return result;
24300 }25199 }
2430125200
24302 if (src_type->data.integral.is_signed != dest_type->data.integral.is_signed) {25201 if (src_type->data.integral.is_signed != dest_type->data.integral.is_signed) {
24303 const char *sign_str = dest_type->data.integral.is_signed ? "signed" : "unsigned";25202 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)));25203 ir_add_error(ira, &target->base, buf_sprintf("expected %s integer type, found '%s'", sign_str, buf_ptr(&src_type->name)));
24305 return ira->codegen->invalid_instruction;25204 return ira->codegen->invalid_inst_gen;
24306 } else if (src_type->data.integral.bit_count < dest_type->data.integral.bit_count) {25205 } 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'",
24308 buf_ptr(&src_type->name), buf_ptr(&dest_type->name)));25207 buf_ptr(&src_type->name), buf_ptr(&dest_type->name)));
24309 return ira->codegen->invalid_instruction;25208 return ira->codegen->invalid_inst_gen;
24310 }25209 }
2431125210
24312 IrInstruction *new_instruction = ir_build_truncate(&ira->new_irb, instruction->base.scope,25211 return ir_build_truncate_gen(ira, &instruction->base.base, dest_type, target);
24313 instruction->base.source_node, dest_type_value, target);
24314 new_instruction->value->type = dest_type;
24315 return new_instruction;
24316}25212}
2431725213
24318static IrInstruction *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstructionIntCast *instruction) {25214static IrInstGen *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstSrcIntCast *instruction) {
24319 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);25215 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);
24320 if (type_is_invalid(dest_type))25216 if (type_is_invalid(dest_type))
24321 return ira->codegen->invalid_instruction;25217 return ira->codegen->invalid_inst_gen;
2432225218
24323 if (dest_type->id != ZigTypeIdInt && dest_type->id != ZigTypeIdComptimeInt) {25219 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)));25220 ir_add_error(ira, &instruction->dest_type->base, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
24325 return ira->codegen->invalid_instruction;25221 return ira->codegen->invalid_inst_gen;
24326 }25222 }
2432725223
24328 IrInstruction *target = instruction->target->child;25224 IrInstGen *target = instruction->target->child;
24329 if (type_is_invalid(target->value->type))25225 if (type_is_invalid(target->value->type))
24330 return ira->codegen->invalid_instruction;25226 return ira->codegen->invalid_inst_gen;
2433125227
24332 if (target->value->type->id != ZigTypeIdInt && target->value->type->id != ZigTypeIdComptimeInt) {25228 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'",
24334 buf_ptr(&target->value->type->name)));25230 buf_ptr(&target->value->type->name)));
24335 return ira->codegen->invalid_instruction;25231 return ira->codegen->invalid_inst_gen;
24336 }25232 }
2433725233
24338 if (instr_is_comptime(target)) {25234 if (instr_is_comptime(target)) {
...@@ -24340,28 +25236,28 @@ static IrInstruction *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruct...@@ -24340,28 +25236,28 @@ static IrInstruction *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruct
24340 }25236 }
2434125237
24342 if (dest_type->id == ZigTypeIdComptimeInt) {25238 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'",
24344 buf_ptr(&dest_type->name)));25240 buf_ptr(&dest_type->name)));
24345 return ira->codegen->invalid_instruction;25241 return ira->codegen->invalid_inst_gen;
24346 }25242 }
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);
24349}25245}
2435025246
24351static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstructionFloatCast *instruction) {25247static IrInstGen *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstSrcFloatCast *instruction) {
24352 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);25248 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);
24353 if (type_is_invalid(dest_type))25249 if (type_is_invalid(dest_type))
24354 return ira->codegen->invalid_instruction;25250 return ira->codegen->invalid_inst_gen;
2435525251
24356 if (dest_type->id != ZigTypeIdFloat) {25252 if (dest_type->id != ZigTypeIdFloat) {
24357 ir_add_error(ira, instruction->dest_type,25253 ir_add_error(ira, &instruction->dest_type->base,
24358 buf_sprintf("expected float type, found '%s'", buf_ptr(&dest_type->name)));25254 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;
24360 }25256 }
2436125257
24362 IrInstruction *target = instruction->target->child;25258 IrInstGen *target = instruction->target->child;
24363 if (type_is_invalid(target->value->type))25259 if (type_is_invalid(target->value->type))
24364 return ira->codegen->invalid_instruction;25260 return ira->codegen->invalid_inst_gen;
2436525261
24366 if (target->value->type->id == ZigTypeIdComptimeInt ||25262 if (target->value->type->id == ZigTypeIdComptimeInt ||
24367 target->value->type->id == ZigTypeIdComptimeFloat)25263 target->value->type->id == ZigTypeIdComptimeFloat)
...@@ -24373,55 +25269,55 @@ static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstru...@@ -24373,55 +25269,55 @@ static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstru
24373 } else {25269 } else {
24374 op = CastOpNumLitToConcrete;25270 op = CastOpNumLitToConcrete;
24375 }25271 }
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);
24377 } else {25273 } else {
24378 return ira->codegen->invalid_instruction;25274 return ira->codegen->invalid_inst_gen;
24379 }25275 }
24380 }25276 }
2438125277
24382 if (target->value->type->id != ZigTypeIdFloat) {25278 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'",
24384 buf_ptr(&target->value->type->name)));25280 buf_ptr(&target->value->type->name)));
24385 return ira->codegen->invalid_instruction;25281 return ira->codegen->invalid_inst_gen;
24386 }25282 }
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);
24389}25285}
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) {
24392 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);25288 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);
24393 if (type_is_invalid(dest_type))25289 if (type_is_invalid(dest_type))
24394 return ira->codegen->invalid_instruction;25290 return ira->codegen->invalid_inst_gen;
2439525291
24396 if (dest_type->id != ZigTypeIdErrorSet) {25292 if (dest_type->id != ZigTypeIdErrorSet) {
24397 ir_add_error(ira, instruction->dest_type,25293 ir_add_error(ira, &instruction->dest_type->base,
24398 buf_sprintf("expected error set type, found '%s'", buf_ptr(&dest_type->name)));25294 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;
24400 }25296 }
2440125297
24402 IrInstruction *target = instruction->target->child;25298 IrInstGen *target = instruction->target->child;
24403 if (type_is_invalid(target->value->type))25299 if (type_is_invalid(target->value->type))
24404 return ira->codegen->invalid_instruction;25300 return ira->codegen->invalid_inst_gen;
2440525301
24406 if (target->value->type->id != ZigTypeIdErrorSet) {25302 if (target->value->type->id != ZigTypeIdErrorSet) {
24407 ir_add_error(ira, instruction->target,25303 ir_add_error(ira, &instruction->target->base,
24408 buf_sprintf("expected error set type, found '%s'", buf_ptr(&target->value->type->name)));25304 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;
24410 }25306 }
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);
24413}25309}
2441425310
24415static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionFromBytes *instruction) {25311static IrInstGen *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstSrcFromBytes *instruction) {
24416 Error err;25312 Error err;
2441725313
24418 ZigType *dest_child_type = ir_resolve_type(ira, instruction->dest_child_type->child);25314 ZigType *dest_child_type = ir_resolve_type(ira, instruction->dest_child_type->child);
24419 if (type_is_invalid(dest_child_type))25315 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;
24423 if (type_is_invalid(target->value->type))25319 if (type_is_invalid(target->value->type))
24424 return ira->codegen->invalid_instruction;25320 return ira->codegen->invalid_inst_gen;
2442525321
24426 bool src_ptr_const;25322 bool src_ptr_const;
24427 bool src_ptr_volatile;25323 bool src_ptr_volatile;
...@@ -24431,27 +25327,27 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru...@@ -24431,27 +25327,27 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
24431 src_ptr_volatile = target->value->type->data.pointer.is_volatile;25327 src_ptr_volatile = target->value->type->data.pointer.is_volatile;
2443225328
24433 if ((err = resolve_ptr_align(ira, target->value->type, &src_ptr_align)))25329 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;
24435 } else if (is_slice(target->value->type)) {25331 } else if (is_slice(target->value->type)) {
24436 ZigType *src_ptr_type = target->value->type->data.structure.fields[slice_ptr_index]->type_entry;25332 ZigType *src_ptr_type = target->value->type->data.structure.fields[slice_ptr_index]->type_entry;
24437 src_ptr_const = src_ptr_type->data.pointer.is_const;25333 src_ptr_const = src_ptr_type->data.pointer.is_const;
24438 src_ptr_volatile = src_ptr_type->data.pointer.is_volatile;25334 src_ptr_volatile = src_ptr_type->data.pointer.is_volatile;
2443925335
24440 if ((err = resolve_ptr_align(ira, src_ptr_type, &src_ptr_align)))25336 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;
24442 } else {25338 } else {
24443 src_ptr_const = true;25339 src_ptr_const = true;
24444 src_ptr_volatile = false;25340 src_ptr_volatile = false;
2444525341
24446 if ((err = type_resolve(ira->codegen, target->value->type, ResolveStatusAlignmentKnown)))25342 if ((err = type_resolve(ira->codegen, target->value->type, ResolveStatusAlignmentKnown)))
24447 return ira->codegen->invalid_instruction;25343 return ira->codegen->invalid_inst_gen;
2444825344
24449 src_ptr_align = get_abi_alignment(ira->codegen, target->value->type);25345 src_ptr_align = get_abi_alignment(ira->codegen, target->value->type);
24450 }25346 }
2445125347
24452 if (src_ptr_align != 0) {25348 if (src_ptr_align != 0) {
24453 if ((err = type_resolve(ira->codegen, dest_child_type, ResolveStatusAlignmentKnown)))25349 if ((err = type_resolve(ira->codegen, dest_child_type, ResolveStatusAlignmentKnown)))
24454 return ira->codegen->invalid_instruction;25350 return ira->codegen->invalid_inst_gen;
24455 }25351 }
2445625352
24457 ZigType *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_child_type,25353 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...@@ -24464,9 +25360,9 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
24464 src_ptr_align, 0, 0, false);25360 src_ptr_align, 0, 0, false);
24465 ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr);25361 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);
24468 if (type_is_invalid(casted_value->value->type))25364 if (type_is_invalid(casted_value->value->type))
24469 return ira->codegen->invalid_instruction;25365 return ira->codegen->invalid_inst_gen;
2447025366
24471 bool have_known_len = false;25367 bool have_known_len = false;
24472 uint64_t known_len;25368 uint64_t known_len;
...@@ -24474,7 +25370,7 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru...@@ -24474,7 +25370,7 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
24474 if (instr_is_comptime(casted_value)) {25370 if (instr_is_comptime(casted_value)) {
24475 ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad);25371 ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad);
24476 if (!val)25372 if (!val)
24477 return ira->codegen->invalid_instruction;25373 return ira->codegen->invalid_inst_gen;
2447825374
24479 ZigValue *len_val = val->data.x_struct.fields[slice_len_index];25375 ZigValue *len_val = val->data.x_struct.fields[slice_len_index];
24480 if (value_is_comptime(len_val)) {25376 if (value_is_comptime(len_val)) {
...@@ -24483,9 +25379,9 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru...@@ -24483,9 +25379,9 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
24483 }25379 }
24484 }25380 }
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,
24487 dest_slice_type, nullptr, true, false, true);25383 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)) {
24489 return result_loc;25385 return result_loc;
24490 }25386 }
2449125387
...@@ -24502,41 +25398,41 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru...@@ -24502,41 +25398,41 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
2450225398
24503 if (have_known_len) {25399 if (have_known_len) {
24504 if ((err = type_resolve(ira->codegen, dest_child_type, ResolveStatusSizeKnown)))25400 if ((err = type_resolve(ira->codegen, dest_child_type, ResolveStatusSizeKnown)))
24505 return ira->codegen->invalid_instruction;25401 return ira->codegen->invalid_inst_gen;
24506 uint64_t child_type_size = type_size(ira->codegen, dest_child_type);25402 uint64_t child_type_size = type_size(ira->codegen, dest_child_type);
24507 uint64_t remainder = known_len % child_type_size;25403 uint64_t remainder = known_len % child_type_size;
24508 if (remainder != 0) {25404 if (remainder != 0) {
24509 ErrorMsg *msg = ir_add_error(ira, &instruction->base,25405 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base,
24510 buf_sprintf("unable to convert [%" ZIG_PRI_u64 "]u8 to %s: size mismatch",25406 buf_sprintf("unable to convert [%" ZIG_PRI_u64 "]u8 to %s: size mismatch",
24511 known_len, buf_ptr(&dest_slice_type->name)));25407 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,
24513 buf_sprintf("%s has size %" ZIG_PRI_u64 "; remaining bytes: %" ZIG_PRI_u64,25409 buf_sprintf("%s has size %" ZIG_PRI_u64 "; remaining bytes: %" ZIG_PRI_u64,
24514 buf_ptr(&dest_child_type->name), child_type_size, remainder));25410 buf_ptr(&dest_child_type->name), child_type_size, remainder));
24515 return ira->codegen->invalid_instruction;25411 return ira->codegen->invalid_inst_gen;
24516 }25412 }
24517 }25413 }
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);
24520}25416}
2452125417
24522static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstructionToBytes *instruction) {25418static IrInstGen *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstSrcToBytes *instruction) {
24523 Error err;25419 Error err;
2452425420
24525 IrInstruction *target = instruction->target->child;25421 IrInstGen *target = instruction->target->child;
24526 if (type_is_invalid(target->value->type))25422 if (type_is_invalid(target->value->type))
24527 return ira->codegen->invalid_instruction;25423 return ira->codegen->invalid_inst_gen;
2452825424
24529 if (!is_slice(target->value->type)) {25425 if (!is_slice(target->value->type)) {
24530 ir_add_error(ira, instruction->target,25426 ir_add_error(ira, &instruction->target->base,
24531 buf_sprintf("expected slice, found '%s'", buf_ptr(&target->value->type->name)));25427 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;
24533 }25429 }
2453425430
24535 ZigType *src_ptr_type = target->value->type->data.structure.fields[slice_ptr_index]->type_entry;25431 ZigType *src_ptr_type = target->value->type->data.structure.fields[slice_ptr_index]->type_entry;
2453625432
24537 uint32_t alignment;25433 uint32_t alignment;
24538 if ((err = resolve_ptr_align(ira, src_ptr_type, &alignment)))25434 if ((err = resolve_ptr_align(ira, src_ptr_type, &alignment)))
24539 return ira->codegen->invalid_instruction;25435 return ira->codegen->invalid_inst_gen;
2454025436
24541 ZigType *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,25437 ZigType *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
24542 src_ptr_type->data.pointer.is_const, src_ptr_type->data.pointer.is_volatile, PtrLenUnknown,25438 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...@@ -24546,9 +25442,9 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct
24546 if (instr_is_comptime(target)) {25442 if (instr_is_comptime(target)) {
24547 ZigValue *target_val = ir_resolve_const(ira, target, UndefBad);25443 ZigValue *target_val = ir_resolve_const(ira, target, UndefBad);
24548 if (target_val == nullptr)25444 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);
24552 result->value->data.x_struct.fields = alloc_const_vals_ptrs(2);25448 result->value->data.x_struct.fields = alloc_const_vals_ptrs(2);
2455325449
24554 ZigValue *ptr_val = result->value->data.x_struct.fields[slice_ptr_index];25450 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...@@ -24568,13 +25464,13 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct
24568 return result;25464 return result;
24569 }25465 }
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,
24572 dest_slice_type, nullptr, true, false, true);25468 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) {
24574 return result_loc;25470 return result_loc;
24575 }25471 }
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);
24578}25474}
2457925475
24580static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align) {25476static 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...@@ -24591,26 +25487,26 @@ static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_ali
24591 return ErrorNone;25487 return ErrorNone;
24592}25488}
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) {
24595 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);25491 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);
24596 if (type_is_invalid(dest_type))25492 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;
24600 if (type_is_invalid(target->value->type))25496 if (type_is_invalid(target->value->type))
24601 return ira->codegen->invalid_instruction;25497 return ira->codegen->invalid_inst_gen;
2460225498
24603 if (target->value->type->id != ZigTypeIdInt && target->value->type->id != ZigTypeIdComptimeInt) {25499 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'",
24605 buf_ptr(&target->value->type->name)));25501 buf_ptr(&target->value->type->name)));
24606 return ira->codegen->invalid_instruction;25502 return ira->codegen->invalid_inst_gen;
24607 }25503 }
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);
24610}25506}
2461125507
24612static IrInstruction *ir_analyze_float_to_int(IrAnalyze *ira, IrInstruction *source_instr,25508static IrInstGen *ir_analyze_float_to_int(IrAnalyze *ira, IrInst* source_instr,
24613 ZigType *dest_type, IrInstruction *operand, AstNode *operand_source_node)25509 ZigType *dest_type, IrInstGen *operand, AstNode *operand_source_node)
24614{25510{
24615 if (operand->value->type->id == ZigTypeIdComptimeInt) {25511 if (operand->value->type->id == ZigTypeIdComptimeInt) {
24616 return ir_implicit_cast(ira, operand, dest_type);25512 return ir_implicit_cast(ira, operand, dest_type);
...@@ -24619,106 +25515,107 @@ static IrInstruction *ir_analyze_float_to_int(IrAnalyze *ira, IrInstruction *sou...@@ -24619,106 +25515,107 @@ static IrInstruction *ir_analyze_float_to_int(IrAnalyze *ira, IrInstruction *sou
24619 if (operand->value->type->id != ZigTypeIdFloat && operand->value->type->id != ZigTypeIdComptimeFloat) {25515 if (operand->value->type->id != ZigTypeIdFloat && operand->value->type->id != ZigTypeIdComptimeFloat) {
24620 ir_add_error_node(ira, operand_source_node, buf_sprintf("expected float type, found '%s'",25516 ir_add_error_node(ira, operand_source_node, buf_sprintf("expected float type, found '%s'",
24621 buf_ptr(&operand->value->type->name)));25517 buf_ptr(&operand->value->type->name)));
24622 return ira->codegen->invalid_instruction;25518 return ira->codegen->invalid_inst_gen;
24623 }25519 }
2462425520
24625 return ir_resolve_cast(ira, source_instr, operand, dest_type, CastOpFloatToInt);25521 return ir_resolve_cast(ira, source_instr, operand, dest_type, CastOpFloatToInt);
24626}25522}
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) {
24629 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);25525 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);
24630 if (type_is_invalid(dest_type))25526 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;
24634 if (type_is_invalid(operand->value->type))25530 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);
24638}25535}
2463925536
24640static IrInstruction *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstructionErrToInt *instruction) {25537static IrInstGen *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstSrcErrToInt *instruction) {
24641 IrInstruction *target = instruction->target->child;25538 IrInstGen *target = instruction->target->child;
24642 if (type_is_invalid(target->value->type))25539 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;
24646 if (target->value->type->id == ZigTypeIdErrorSet) {25543 if (target->value->type->id == ZigTypeIdErrorSet) {
24647 casted_target = target;25544 casted_target = target;
24648 } else {25545 } else {
24649 casted_target = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_global_error_set);25546 casted_target = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_global_error_set);
24650 if (type_is_invalid(casted_target->value->type))25547 if (type_is_invalid(casted_target->value->type))
24651 return ira->codegen->invalid_instruction;25548 return ira->codegen->invalid_inst_gen;
24652 }25549 }
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);
24655}25552}
2465625553
24657static IrInstruction *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstructionIntToErr *instruction) {25554static IrInstGen *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstSrcIntToErr *instruction) {
24658 IrInstruction *target = instruction->target->child;25555 IrInstGen *target = instruction->target->child;
24659 if (type_is_invalid(target->value->type))25556 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);
24663 if (type_is_invalid(casted_target->value->type))25560 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);
24667}25564}
2466825565
24669static IrInstruction *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstructionBoolToInt *instruction) {25566static IrInstGen *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstSrcBoolToInt *instruction) {
24670 IrInstruction *target = instruction->target->child;25567 IrInstGen *target = instruction->target->child;
24671 if (type_is_invalid(target->value->type))25568 if (type_is_invalid(target->value->type))
24672 return ira->codegen->invalid_instruction;25569 return ira->codegen->invalid_inst_gen;
2467325570
24674 if (target->value->type->id != ZigTypeIdBool) {25571 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'",
24676 buf_ptr(&target->value->type->name)));25573 buf_ptr(&target->value->type->name)));
24677 return ira->codegen->invalid_instruction;25574 return ira->codegen->invalid_inst_gen;
24678 }25575 }
2467925576
24680 if (instr_is_comptime(target)) {25577 if (instr_is_comptime(target)) {
24681 bool is_true;25578 bool is_true;
24682 if (!ir_resolve_bool(ira, target, &is_true))25579 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);
24686 }25583 }
2468725584
24688 ZigType *u1_type = get_int_type(ira->codegen, false, 1);25585 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);
24690}25587}
2469125588
24692static IrInstruction *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstructionIntType *instruction) {25589static IrInstGen *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstSrcIntType *instruction) {
24693 IrInstruction *is_signed_value = instruction->is_signed->child;25590 IrInstGen *is_signed_value = instruction->is_signed->child;
24694 bool is_signed;25591 bool is_signed;
24695 if (!ir_resolve_bool(ira, is_signed_value, &is_signed))25592 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;
24699 uint64_t bit_count;25596 uint64_t bit_count;
24700 if (!ir_resolve_unsigned(ira, bit_count_value, ira->codegen->builtin_types.entry_u16, &bit_count))25597 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));
24704}25601}
2470525602
24706static IrInstruction *ir_analyze_instruction_vector_type(IrAnalyze *ira, IrInstructionVectorType *instruction) {25603static IrInstGen *ir_analyze_instruction_vector_type(IrAnalyze *ira, IrInstSrcVectorType *instruction) {
24707 uint64_t len;25604 uint64_t len;
24708 if (!ir_resolve_unsigned(ira, instruction->len->child, ira->codegen->builtin_types.entry_u32, &len))25605 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
24711 ZigType *elem_type = ir_resolve_vector_elem_type(ira, instruction->elem_type->child);25608 ZigType *elem_type = ir_resolve_vector_elem_type(ira, instruction->elem_type->child);
24712 if (type_is_invalid(elem_type))25609 if (type_is_invalid(elem_type))
24713 return ira->codegen->invalid_instruction;25610 return ira->codegen->invalid_inst_gen;
2471425611
24715 ZigType *vector_type = get_vector_type(ira->codegen, len, elem_type);25612 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);
24718}25615}
2471925616
24720static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *source_instr,25617static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr,
24721 ZigType *scalar_type, IrInstruction *a, IrInstruction *b, IrInstruction *mask)25618 ZigType *scalar_type, IrInstGen *a, IrInstGen *b, IrInstGen *mask)
24722{25619{
24723 ir_assert(source_instr && scalar_type && a && b && mask, source_instr);25620 ir_assert(source_instr && scalar_type && a && b && mask, source_instr);
24724 ir_assert(is_valid_vector_elem_type(scalar_type), source_instr);25621 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...@@ -24729,15 +25626,15 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
24729 } else if (mask->value->type->id == ZigTypeIdArray) {25626 } else if (mask->value->type->id == ZigTypeIdArray) {
24730 len_mask = mask->value->type->data.array.len;25627 len_mask = mask->value->type->data.array.len;
24731 } else {25628 } else {
24732 ir_add_error(ira, mask,25629 ir_add_error(ira, &mask->base,
24733 buf_sprintf("expected vector or array, found '%s'",25630 buf_sprintf("expected vector or array, found '%s'",
24734 buf_ptr(&mask->value->type->name)));25631 buf_ptr(&mask->value->type->name)));
24735 return ira->codegen->invalid_instruction;25632 return ira->codegen->invalid_inst_gen;
24736 }25633 }
24737 mask = ir_implicit_cast(ira, mask, get_vector_type(ira->codegen, len_mask,25634 mask = ir_implicit_cast(ira, mask, get_vector_type(ira->codegen, len_mask,
24738 ira->codegen->builtin_types.entry_i32));25635 ira->codegen->builtin_types.entry_i32));
24739 if (type_is_invalid(mask->value->type))25636 if (type_is_invalid(mask->value->type))
24740 return ira->codegen->invalid_instruction;25637 return ira->codegen->invalid_inst_gen;
2474125638
24742 uint32_t len_a;25639 uint32_t len_a;
24743 if (a->value->type->id == ZigTypeIdVector) {25640 if (a->value->type->id == ZigTypeIdVector) {
...@@ -24747,11 +25644,11 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s...@@ -24747,11 +25644,11 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
24747 } else if (a->value->type->id == ZigTypeIdUndefined) {25644 } else if (a->value->type->id == ZigTypeIdUndefined) {
24748 len_a = UINT32_MAX;25645 len_a = UINT32_MAX;
24749 } else {25646 } else {
24750 ir_add_error(ira, a,25647 ir_add_error(ira, &a->base,
24751 buf_sprintf("expected vector or array with element type '%s', found '%s'",25648 buf_sprintf("expected vector or array with element type '%s', found '%s'",
24752 buf_ptr(&scalar_type->name),25649 buf_ptr(&scalar_type->name),
24753 buf_ptr(&a->value->type->name)));25650 buf_ptr(&a->value->type->name)));
24754 return ira->codegen->invalid_instruction;25651 return ira->codegen->invalid_inst_gen;
24755 }25652 }
2475625653
24757 uint32_t len_b;25654 uint32_t len_b;
...@@ -24762,38 +25659,38 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s...@@ -24762,38 +25659,38 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
24762 } else if (b->value->type->id == ZigTypeIdUndefined) {25659 } else if (b->value->type->id == ZigTypeIdUndefined) {
24763 len_b = UINT32_MAX;25660 len_b = UINT32_MAX;
24764 } else {25661 } else {
24765 ir_add_error(ira, b,25662 ir_add_error(ira, &b->base,
24766 buf_sprintf("expected vector or array with element type '%s', found '%s'",25663 buf_sprintf("expected vector or array with element type '%s', found '%s'",
24767 buf_ptr(&scalar_type->name),25664 buf_ptr(&scalar_type->name),
24768 buf_ptr(&b->value->type->name)));25665 buf_ptr(&b->value->type->name)));
24769 return ira->codegen->invalid_instruction;25666 return ira->codegen->invalid_inst_gen;
24770 }25667 }
2477125668
24772 if (len_a == UINT32_MAX && len_b == UINT32_MAX) {25669 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));
24774 }25671 }
2477525672
24776 if (len_a == UINT32_MAX) {25673 if (len_a == UINT32_MAX) {
24777 len_a = len_b;25674 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));
24779 } else {25676 } else {
24780 a = ir_implicit_cast(ira, a, get_vector_type(ira->codegen, len_a, scalar_type));25677 a = ir_implicit_cast(ira, a, get_vector_type(ira->codegen, len_a, scalar_type));
24781 if (type_is_invalid(a->value->type))25678 if (type_is_invalid(a->value->type))
24782 return ira->codegen->invalid_instruction;25679 return ira->codegen->invalid_inst_gen;
24783 }25680 }
2478425681
24785 if (len_b == UINT32_MAX) {25682 if (len_b == UINT32_MAX) {
24786 len_b = len_a;25683 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));
24788 } else {25685 } else {
24789 b = ir_implicit_cast(ira, b, get_vector_type(ira->codegen, len_b, scalar_type));25686 b = ir_implicit_cast(ira, b, get_vector_type(ira->codegen, len_b, scalar_type));
24790 if (type_is_invalid(b->value->type))25687 if (type_is_invalid(b->value->type))
24791 return ira->codegen->invalid_instruction;25688 return ira->codegen->invalid_inst_gen;
24792 }25689 }
2479325690
24794 ZigValue *mask_val = ir_resolve_const(ira, mask, UndefOk);25691 ZigValue *mask_val = ir_resolve_const(ira, mask, UndefOk);
24795 if (mask_val == nullptr)25692 if (mask_val == nullptr)
24796 return ira->codegen->invalid_instruction;25693 return ira->codegen->invalid_inst_gen;
2479725694
24798 expand_undef_array(ira->codegen, mask_val);25695 expand_undef_array(ira->codegen, mask_val);
2479925696
...@@ -24803,7 +25700,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s...@@ -24803,7 +25700,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
24803 continue;25700 continue;
24804 int32_t v_i32 = bigint_as_signed(&mask_elem_val->data.x_bigint);25701 int32_t v_i32 = bigint_as_signed(&mask_elem_val->data.x_bigint);
24805 uint32_t v;25702 uint32_t v;
24806 IrInstruction *chosen_operand;25703 IrInstGen *chosen_operand;
24807 if (v_i32 >= 0) {25704 if (v_i32 >= 0) {
24808 v = (uint32_t)v_i32;25705 v = (uint32_t)v_i32;
24809 chosen_operand = a;25706 chosen_operand = a;
...@@ -24812,16 +25709,16 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s...@@ -24812,16 +25709,16 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
24812 chosen_operand = b;25709 chosen_operand = b;
24813 }25710 }
24814 if (v >= chosen_operand->value->type->data.vector.len) {25711 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,
24816 buf_sprintf("mask index '%u' has out-of-bounds selection", i));25713 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,
24818 buf_sprintf("selected index '%u' out of bounds of %s", v,25715 buf_sprintf("selected index '%u' out of bounds of %s", v,
24819 buf_ptr(&chosen_operand->value->type->name)));25716 buf_ptr(&chosen_operand->value->type->name)));
24820 if (chosen_operand == a && v < len_a + len_b) {25717 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,
24822 buf_create_from_str("selections from the second vector are specified with negative numbers"));25719 buf_create_from_str("selections from the second vector are specified with negative numbers"));
24823 }25720 }
24824 return ira->codegen->invalid_instruction;25721 return ira->codegen->invalid_inst_gen;
24825 }25722 }
24826 }25723 }
2482725724
...@@ -24829,16 +25726,16 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s...@@ -24829,16 +25726,16 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
24829 if (instr_is_comptime(a) && instr_is_comptime(b)) {25726 if (instr_is_comptime(a) && instr_is_comptime(b)) {
24830 ZigValue *a_val = ir_resolve_const(ira, a, UndefOk);25727 ZigValue *a_val = ir_resolve_const(ira, a, UndefOk);
24831 if (a_val == nullptr)25728 if (a_val == nullptr)
24832 return ira->codegen->invalid_instruction;25729 return ira->codegen->invalid_inst_gen;
2483325730
24834 ZigValue *b_val = ir_resolve_const(ira, b, UndefOk);25731 ZigValue *b_val = ir_resolve_const(ira, b, UndefOk);
24835 if (b_val == nullptr)25732 if (b_val == nullptr)
24836 return ira->codegen->invalid_instruction;25733 return ira->codegen->invalid_inst_gen;
2483725734
24838 expand_undef_array(ira->codegen, a_val);25735 expand_undef_array(ira->codegen, a_val);
24839 expand_undef_array(ira->codegen, b_val);25736 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);
24842 result->value->data.x_array.data.s_none.elements = create_const_vals(len_mask);25739 result->value->data.x_array.data.s_none.elements = create_const_vals(len_mask);
24843 for (uint32_t i = 0; i < mask_val->type->data.vector.len; i += 1) {25740 for (uint32_t i = 0; i < mask_val->type->data.vector.len; i += 1) {
24844 ZigValue *mask_elem_val = &mask_val->data.x_array.data.s_none.elements[i];25741 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...@@ -24870,7 +25767,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
24870 uint32_t len_min = min(len_a, len_b);25767 uint32_t len_min = min(len_a, len_b);
24871 uint32_t len_max = max(len_a, len_b);25768 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,
24874 get_vector_type(ira->codegen, len_max, ira->codegen->builtin_types.entry_i32));25771 get_vector_type(ira->codegen, len_max, ira->codegen->builtin_types.entry_i32));
24875 expand_mask->value->data.x_array.data.s_none.elements = create_const_vals(len_max);25772 expand_mask->value->data.x_array.data.s_none.elements = create_const_vals(len_max);
24876 uint32_t i = 0;25773 uint32_t i = 0;
...@@ -24879,7 +25776,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s...@@ -24879,7 +25776,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
24879 for (; i < len_max; i += 1)25776 for (; i < len_max; i += 1)
24880 bigint_init_signed(&expand_mask->value->data.x_array.data.s_none.elements[i].data.x_bigint, -1);25777 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,
24883 get_vector_type(ira->codegen, len_min, scalar_type));25780 get_vector_type(ira->codegen, len_min, scalar_type));
2488425781
24885 if (len_b < len_a) {25782 if (len_b < len_a) {
...@@ -24889,62 +25786,59 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s...@@ -24889,62 +25786,59 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
24889 }25786 }
24890 }25787 }
2489125788
24892 IrInstruction *result = ir_build_shuffle_vector(&ira->new_irb,25789 return ir_build_shuffle_vector_gen(ira, source_instr->scope, source_instr->source_node,
24893 source_instr->scope, source_instr->source_node,25790 result_type, a, b, mask);
24894 nullptr, a, b, mask);
24895 result->value->type = result_type;
24896 return result;
24897}25791}
2489825792
24899static IrInstruction *ir_analyze_instruction_shuffle_vector(IrAnalyze *ira, IrInstructionShuffleVector *instruction) {25793static IrInstGen *ir_analyze_instruction_shuffle_vector(IrAnalyze *ira, IrInstSrcShuffleVector *instruction) {
24900 ZigType *scalar_type = ir_resolve_vector_elem_type(ira, instruction->scalar_type);25794 ZigType *scalar_type = ir_resolve_vector_elem_type(ira, instruction->scalar_type->child);
24901 if (type_is_invalid(scalar_type))25795 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;
24905 if (type_is_invalid(a->value->type))25799 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;
24909 if (type_is_invalid(b->value->type))25803 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;
24913 if (type_is_invalid(mask->value->type))25807 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);
24917}25811}
2491825812
24919static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstructionSplatSrc *instruction) {25813static IrInstGen *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstSrcSplat *instruction) {
24920 Error err;25814 Error err;
2492125815
24922 IrInstruction *len = instruction->len->child;25816 IrInstGen *len = instruction->len->child;
24923 if (type_is_invalid(len->value->type))25817 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;
24927 if (type_is_invalid(scalar->value->type))25821 if (type_is_invalid(scalar->value->type))
24928 return ira->codegen->invalid_instruction;25822 return ira->codegen->invalid_inst_gen;
2492925823
24930 uint64_t len_u64;25824 uint64_t len_u64;
24931 if (!ir_resolve_unsigned(ira, len, ira->codegen->builtin_types.entry_u32, &len_u64))25825 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;
24933 uint32_t len_int = len_u64;25827 uint32_t len_int = len_u64;
2493425828
24935 if ((err = ir_validate_vector_elem_type(ira, scalar, scalar->value->type)))25829 if ((err = ir_validate_vector_elem_type(ira, scalar->base.source_node, scalar->value->type)))
24936 return ira->codegen->invalid_instruction;25830 return ira->codegen->invalid_inst_gen;
2493725831
24938 ZigType *return_type = get_vector_type(ira->codegen, len_int, scalar->value->type);25832 ZigType *return_type = get_vector_type(ira->codegen, len_int, scalar->value->type);
2493925833
24940 if (instr_is_comptime(scalar)) {25834 if (instr_is_comptime(scalar)) {
24941 ZigValue *scalar_val = ir_resolve_const(ira, scalar, UndefOk);25835 ZigValue *scalar_val = ir_resolve_const(ira, scalar, UndefOk);
24942 if (scalar_val == nullptr)25836 if (scalar_val == nullptr)
24943 return ira->codegen->invalid_instruction;25837 return ira->codegen->invalid_inst_gen;
24944 if (scalar_val->special == ConstValSpecialUndef)25838 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);
24948 result->value->data.x_array.data.s_none.elements = create_const_vals(len_int);25842 result->value->data.x_array.data.s_none.elements = create_const_vals(len_int);
24949 for (uint32_t i = 0; i < len_int; i += 1) {25843 for (uint32_t i = 0; i < len_int; i += 1) {
24950 copy_const_val(&result->value->data.x_array.data.s_none.elements[i], scalar_val);25844 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...@@ -24952,48 +25846,45 @@ static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstruction
24952 return result;25846 return result;
24953 }25847 }
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);
24956}25850}
2495725851
24958static IrInstruction *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstructionBoolNot *instruction) {25852static IrInstGen *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstSrcBoolNot *instruction) {
24959 IrInstruction *value = instruction->value->child;25853 IrInstGen *value = instruction->value->child;
24960 if (type_is_invalid(value->value->type))25854 if (type_is_invalid(value->value->type))
24961 return ira->codegen->invalid_instruction;25855 return ira->codegen->invalid_inst_gen;
2496225856
24963 ZigType *bool_type = ira->codegen->builtin_types.entry_bool;25857 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);
24966 if (type_is_invalid(casted_value->value->type))25860 if (type_is_invalid(casted_value->value->type))
24967 return ira->codegen->invalid_instruction;25861 return ira->codegen->invalid_inst_gen;
2496825862
24969 if (instr_is_comptime(casted_value)) {25863 if (instr_is_comptime(casted_value)) {
24970 ZigValue *value = ir_resolve_const(ira, casted_value, UndefBad);25864 ZigValue *value = ir_resolve_const(ira, casted_value, UndefBad);
24971 if (value == nullptr)25865 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);
24975 }25869 }
2497625870
24977 IrInstruction *result = ir_build_bool_not(&ira->new_irb, instruction->base.scope,25871 return ir_build_bool_not_gen(ira, &instruction->base.base, casted_value);
24978 instruction->base.source_node, casted_value);
24979 result->value->type = bool_type;
24980 return result;
24981}25872}
2498225873
24983static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemset *instruction) {25874static IrInstGen *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstSrcMemset *instruction) {
24984 Error err;25875 Error err;
2498525876
24986 IrInstruction *dest_ptr = instruction->dest_ptr->child;25877 IrInstGen *dest_ptr = instruction->dest_ptr->child;
24987 if (type_is_invalid(dest_ptr->value->type))25878 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;
24991 if (type_is_invalid(byte_value->value->type))25882 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;
24995 if (type_is_invalid(count_value->value->type))25886 if (type_is_invalid(count_value->value->type))
24996 return ira->codegen->invalid_instruction;25887 return ira->codegen->invalid_inst_gen;
2499725888
24998 ZigType *dest_uncasted_type = dest_ptr->value->type;25889 ZigType *dest_uncasted_type = dest_ptr->value->type;
24999 bool dest_is_volatile = (dest_uncasted_type->id == ZigTypeIdPointer) &&25890 bool dest_is_volatile = (dest_uncasted_type->id == ZigTypeIdPointer) &&
...@@ -25004,24 +25895,24 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio...@@ -25004,24 +25895,24 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio
25004 uint32_t dest_align;25895 uint32_t dest_align;
25005 if (dest_uncasted_type->id == ZigTypeIdPointer) {25896 if (dest_uncasted_type->id == ZigTypeIdPointer) {
25006 if ((err = resolve_ptr_align(ira, dest_uncasted_type, &dest_align)))25897 if ((err = resolve_ptr_align(ira, dest_uncasted_type, &dest_align)))
25007 return ira->codegen->invalid_instruction;25898 return ira->codegen->invalid_inst_gen;
25008 } else {25899 } else {
25009 dest_align = get_abi_alignment(ira->codegen, u8);25900 dest_align = get_abi_alignment(ira->codegen, u8);
25010 }25901 }
25011 ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile,25902 ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile,
25012 PtrLenUnknown, dest_align, 0, 0, false);25903 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);
25015 if (type_is_invalid(casted_dest_ptr->value->type))25906 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);
25019 if (type_is_invalid(casted_byte->value->type))25910 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);
25023 if (type_is_invalid(casted_count->value->type))25914 if (type_is_invalid(casted_count->value->type))
25024 return ira->codegen->invalid_instruction;25915 return ira->codegen->invalid_inst_gen;
2502525916
25026 // TODO test this at comptime with u8 and non-u8 types25917 // TODO test this at comptime with u8 and non-u8 types
25027 if (instr_is_comptime(casted_dest_ptr) &&25918 if (instr_is_comptime(casted_dest_ptr) &&
...@@ -25030,15 +25921,15 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio...@@ -25030,15 +25921,15 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio
25030 {25921 {
25031 ZigValue *dest_ptr_val = ir_resolve_const(ira, casted_dest_ptr, UndefBad);25922 ZigValue *dest_ptr_val = ir_resolve_const(ira, casted_dest_ptr, UndefBad);
25032 if (dest_ptr_val == nullptr)25923 if (dest_ptr_val == nullptr)
25033 return ira->codegen->invalid_instruction;25924 return ira->codegen->invalid_inst_gen;
2503425925
25035 ZigValue *byte_val = ir_resolve_const(ira, casted_byte, UndefOk);25926 ZigValue *byte_val = ir_resolve_const(ira, casted_byte, UndefOk);
25036 if (byte_val == nullptr)25927 if (byte_val == nullptr)
25037 return ira->codegen->invalid_instruction;25928 return ira->codegen->invalid_inst_gen;
2503825929
25039 ZigValue *count_val = ir_resolve_const(ira, casted_count, UndefBad);25930 ZigValue *count_val = ir_resolve_const(ira, casted_count, UndefBad);
25040 if (count_val == nullptr)25931 if (count_val == nullptr)
25041 return ira->codegen->invalid_instruction;25932 return ira->codegen->invalid_inst_gen;
2504225933
25043 if (casted_dest_ptr->value->data.x_ptr.special != ConstPtrSpecialHardCodedAddr &&25934 if (casted_dest_ptr->value->data.x_ptr.special != ConstPtrSpecialHardCodedAddr &&
25044 casted_dest_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar)25935 casted_dest_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar)
...@@ -25083,38 +25974,35 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio...@@ -25083,38 +25974,35 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio
25083 size_t count = bigint_as_usize(&count_val->data.x_bigint);25974 size_t count = bigint_as_usize(&count_val->data.x_bigint);
25084 size_t end = start + count;25975 size_t end = start + count;
25085 if (end > bound_end) {25976 if (end > bound_end) {
25086 ir_add_error(ira, count_value, buf_sprintf("out of bounds pointer access"));25977 ir_add_error(ira, &count_value->base, buf_sprintf("out of bounds pointer access"));
25087 return ira->codegen->invalid_instruction;25978 return ira->codegen->invalid_inst_gen;
25088 }25979 }
2508925980
25090 for (size_t i = start; i < end; i += 1) {25981 for (size_t i = start; i < end; i += 1) {
25091 copy_const_val(&dest_elements[i], byte_val);25982 copy_const_val(&dest_elements[i], byte_val);
25092 }25983 }
2509325984
25094 return ir_const_void(ira, &instruction->base);25985 return ir_const_void(ira, &instruction->base.base);
25095 }25986 }
25096 }25987 }
2509725988
25098 IrInstruction *result = ir_build_memset(&ira->new_irb, instruction->base.scope, instruction->base.source_node,25989 return ir_build_memset_gen(ira, &instruction->base.base, casted_dest_ptr, casted_byte, casted_count);
25099 casted_dest_ptr, casted_byte, casted_count);
25100 result->value->type = ira->codegen->builtin_types.entry_void;
25101 return result;
25102}25990}
2510325991
25104static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcpy *instruction) {25992static IrInstGen *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstSrcMemcpy *instruction) {
25105 Error err;25993 Error err;
2510625994
25107 IrInstruction *dest_ptr = instruction->dest_ptr->child;25995 IrInstGen *dest_ptr = instruction->dest_ptr->child;
25108 if (type_is_invalid(dest_ptr->value->type))25996 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;
25112 if (type_is_invalid(src_ptr->value->type))26000 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;
25116 if (type_is_invalid(count_value->value->type))26004 if (type_is_invalid(count_value->value->type))
25117 return ira->codegen->invalid_instruction;26005 return ira->codegen->invalid_inst_gen;
2511826006
25119 ZigType *u8 = ira->codegen->builtin_types.entry_u8;26007 ZigType *u8 = ira->codegen->builtin_types.entry_u8;
25120 ZigType *dest_uncasted_type = dest_ptr->value->type;26008 ZigType *dest_uncasted_type = dest_ptr->value->type;
...@@ -25127,7 +26015,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio...@@ -25127,7 +26015,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
25127 uint32_t dest_align;26015 uint32_t dest_align;
25128 if (dest_uncasted_type->id == ZigTypeIdPointer) {26016 if (dest_uncasted_type->id == ZigTypeIdPointer) {
25129 if ((err = resolve_ptr_align(ira, dest_uncasted_type, &dest_align)))26017 if ((err = resolve_ptr_align(ira, dest_uncasted_type, &dest_align)))
25130 return ira->codegen->invalid_instruction;26018 return ira->codegen->invalid_inst_gen;
25131 } else {26019 } else {
25132 dest_align = get_abi_alignment(ira->codegen, u8);26020 dest_align = get_abi_alignment(ira->codegen, u8);
25133 }26021 }
...@@ -25135,7 +26023,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio...@@ -25135,7 +26023,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
25135 uint32_t src_align;26023 uint32_t src_align;
25136 if (src_uncasted_type->id == ZigTypeIdPointer) {26024 if (src_uncasted_type->id == ZigTypeIdPointer) {
25137 if ((err = resolve_ptr_align(ira, src_uncasted_type, &src_align)))26025 if ((err = resolve_ptr_align(ira, src_uncasted_type, &src_align)))
25138 return ira->codegen->invalid_instruction;26026 return ira->codegen->invalid_inst_gen;
25139 } else {26027 } else {
25140 src_align = get_abi_alignment(ira->codegen, u8);26028 src_align = get_abi_alignment(ira->codegen, u8);
25141 }26029 }
...@@ -25146,17 +26034,17 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio...@@ -25146,17 +26034,17 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
25146 ZigType *u8_ptr_const = get_pointer_to_type_extra(ira->codegen, u8, true, src_is_volatile,26034 ZigType *u8_ptr_const = get_pointer_to_type_extra(ira->codegen, u8, true, src_is_volatile,
25147 PtrLenUnknown, src_align, 0, 0, false);26035 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);
25150 if (type_is_invalid(casted_dest_ptr->value->type))26038 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);
25154 if (type_is_invalid(casted_src_ptr->value->type))26042 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);
25158 if (type_is_invalid(casted_count->value->type))26046 if (type_is_invalid(casted_count->value->type))
25159 return ira->codegen->invalid_instruction;26047 return ira->codegen->invalid_inst_gen;
2516026048
25161 // TODO test this at comptime with u8 and non-u8 types26049 // TODO test this at comptime with u8 and non-u8 types
25162 // TODO test with dest ptr being a global runtime variable26050 // TODO test with dest ptr being a global runtime variable
...@@ -25166,15 +26054,15 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio...@@ -25166,15 +26054,15 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
25166 {26054 {
25167 ZigValue *dest_ptr_val = ir_resolve_const(ira, casted_dest_ptr, UndefBad);26055 ZigValue *dest_ptr_val = ir_resolve_const(ira, casted_dest_ptr, UndefBad);
25168 if (dest_ptr_val == nullptr)26056 if (dest_ptr_val == nullptr)
25169 return ira->codegen->invalid_instruction;26057 return ira->codegen->invalid_inst_gen;
2517026058
25171 ZigValue *src_ptr_val = ir_resolve_const(ira, casted_src_ptr, UndefBad);26059 ZigValue *src_ptr_val = ir_resolve_const(ira, casted_src_ptr, UndefBad);
25172 if (src_ptr_val == nullptr)26060 if (src_ptr_val == nullptr)
25173 return ira->codegen->invalid_instruction;26061 return ira->codegen->invalid_inst_gen;
2517426062
25175 ZigValue *count_val = ir_resolve_const(ira, casted_count, UndefBad);26063 ZigValue *count_val = ir_resolve_const(ira, casted_count, UndefBad);
25176 if (count_val == nullptr)26064 if (count_val == nullptr)
25177 return ira->codegen->invalid_instruction;26065 return ira->codegen->invalid_inst_gen;
2517826066
25179 if (dest_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {26067 if (dest_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
25180 size_t count = bigint_as_usize(&count_val->data.x_bigint);26068 size_t count = bigint_as_usize(&count_val->data.x_bigint);
...@@ -25217,8 +26105,8 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio...@@ -25217,8 +26105,8 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
25217 }26105 }
2521826106
25219 if (dest_start + count > dest_end) {26107 if (dest_start + count > dest_end) {
25220 ir_add_error(ira, &instruction->base, buf_sprintf("out of bounds pointer access"));26108 ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds pointer access"));
25221 return ira->codegen->invalid_instruction;26109 return ira->codegen->invalid_inst_gen;
25222 }26110 }
2522326111
25224 ZigValue *src_elements;26112 ZigValue *src_elements;
...@@ -25260,8 +26148,8 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio...@@ -25260,8 +26148,8 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
25260 }26148 }
2526126149
25262 if (src_start + count > src_end) {26150 if (src_start + count > src_end) {
25263 ir_add_error(ira, &instruction->base, buf_sprintf("out of bounds pointer access"));26151 ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds pointer access"));
25264 return ira->codegen->invalid_instruction;26152 return ira->codegen->invalid_inst_gen;
25265 }26153 }
2526626154
25267 // TODO check for noalias violations - this should be generalized to work for any function26155 // 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...@@ -25270,42 +26158,39 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
25270 copy_const_val(&dest_elements[dest_start + i], &src_elements[src_start + i]);26158 copy_const_val(&dest_elements[dest_start + i], &src_elements[src_start + i]);
25271 }26159 }
2527226160
25273 return ir_const_void(ira, &instruction->base);26161 return ir_const_void(ira, &instruction->base.base);
25274 }26162 }
25275 }26163 }
2527626164
25277 IrInstruction *result = ir_build_memcpy(&ira->new_irb, instruction->base.scope, instruction->base.source_node,26165 return ir_build_memcpy_gen(ira, &instruction->base.base, casted_dest_ptr, casted_src_ptr, casted_count);
25278 casted_dest_ptr, casted_src_ptr, casted_count);
25279 result->value->type = ira->codegen->builtin_types.entry_void;
25280 return result;
25281}26166}
2528226167
25283static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSliceSrc *instruction) {26168static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *instruction) {
25284 IrInstruction *ptr_ptr = instruction->ptr->child;26169 IrInstGen *ptr_ptr = instruction->ptr->child;
25285 if (type_is_invalid(ptr_ptr->value->type))26170 if (type_is_invalid(ptr_ptr->value->type))
25286 return ira->codegen->invalid_instruction;26171 return ira->codegen->invalid_inst_gen;
2528726172
25288 ZigType *ptr_ptr_type = ptr_ptr->value->type;26173 ZigType *ptr_ptr_type = ptr_ptr->value->type;
25289 assert(ptr_ptr_type->id == ZigTypeIdPointer);26174 assert(ptr_ptr_type->id == ZigTypeIdPointer);
25290 ZigType *array_type = ptr_ptr_type->data.pointer.child_type;26175 ZigType *array_type = ptr_ptr_type->data.pointer.child_type;
2529126176
25292 IrInstruction *start = instruction->start->child;26177 IrInstGen *start = instruction->start->child;
25293 if (type_is_invalid(start->value->type))26178 if (type_is_invalid(start->value->type))
25294 return ira->codegen->invalid_instruction;26179 return ira->codegen->invalid_inst_gen;
2529526180
25296 ZigType *usize = ira->codegen->builtin_types.entry_usize;26181 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);
25298 if (type_is_invalid(casted_start->value->type))26183 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;
25302 if (instruction->end) {26187 if (instruction->end) {
25303 end = instruction->end->child;26188 end = instruction->end->child;
25304 if (type_is_invalid(end->value->type))26189 if (type_is_invalid(end->value->type))
25305 return ira->codegen->invalid_instruction;26190 return ira->codegen->invalid_inst_gen;
25306 end = ir_implicit_cast(ira, end, usize);26191 end = ir_implicit_cast(ira, end, usize);
25307 if (type_is_invalid(end->value->type))26192 if (type_is_invalid(end->value->type))
25308 return ira->codegen->invalid_instruction;26193 return ira->codegen->invalid_inst_gen;
25309 } else {26194 } else {
25310 end = nullptr;26195 end = nullptr;
25311 }26196 }
...@@ -25333,8 +26218,8 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -25333,8 +26218,8 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
25333 PtrLenUnknown,26218 PtrLenUnknown,
25334 array_type->data.pointer.explicit_alignment, 0, 0, false);26219 array_type->data.pointer.explicit_alignment, 0, 0, false);
25335 } else {26220 } else {
25336 ir_add_error(ira, &instruction->base, buf_sprintf("slice of single-item pointer"));26221 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of single-item pointer"));
25337 return ira->codegen->invalid_instruction;26222 return ira->codegen->invalid_inst_gen;
25338 }26223 }
25339 } else {26224 } else {
25340 elem_type = array_type->data.pointer.child_type;26225 elem_type = array_type->data.pointer.child_type;
...@@ -25344,8 +26229,8 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -25344,8 +26229,8 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
25344 ZigType *maybe_sentineled_slice_ptr_type = array_type;26229 ZigType *maybe_sentineled_slice_ptr_type = array_type;
25345 non_sentinel_slice_ptr_type = adjust_ptr_sentinel(ira->codegen, maybe_sentineled_slice_ptr_type, nullptr);26230 non_sentinel_slice_ptr_type = adjust_ptr_sentinel(ira->codegen, maybe_sentineled_slice_ptr_type, nullptr);
25346 if (!end) {26231 if (!end) {
25347 ir_add_error(ira, &instruction->base, buf_sprintf("slice of pointer must include end value"));26232 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of pointer must include end value"));
25348 return ira->codegen->invalid_instruction;26233 return ira->codegen->invalid_inst_gen;
25349 }26234 }
25350 }26235 }
25351 } else if (is_slice(array_type)) {26236 } else if (is_slice(array_type)) {
...@@ -25353,23 +26238,23 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -25353,23 +26238,23 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
25353 non_sentinel_slice_ptr_type = adjust_ptr_sentinel(ira->codegen, maybe_sentineled_slice_ptr_type, nullptr);26238 non_sentinel_slice_ptr_type = adjust_ptr_sentinel(ira->codegen, maybe_sentineled_slice_ptr_type, nullptr);
25354 elem_type = non_sentinel_slice_ptr_type->data.pointer.child_type;26239 elem_type = non_sentinel_slice_ptr_type->data.pointer.child_type;
25355 } else {26240 } else {
25356 ir_add_error(ira, &instruction->base,26241 ir_add_error(ira, &instruction->base.base,
25357 buf_sprintf("slice of non-array type '%s'", buf_ptr(&array_type->name)));26242 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;
25359 }26244 }
2536026245
25361 ZigType *return_type;26246 ZigType *return_type;
25362 ZigValue *sentinel_val = nullptr;26247 ZigValue *sentinel_val = nullptr;
25363 if (instruction->sentinel) {26248 if (instruction->sentinel) {
25364 IrInstruction *uncasted_sentinel = instruction->sentinel->child;26249 IrInstGen *uncasted_sentinel = instruction->sentinel->child;
25365 if (type_is_invalid(uncasted_sentinel->value->type))26250 if (type_is_invalid(uncasted_sentinel->value->type))
25366 return ira->codegen->invalid_instruction;26251 return ira->codegen->invalid_inst_gen;
25367 IrInstruction *sentinel = ir_implicit_cast(ira, uncasted_sentinel, elem_type);26252 IrInstGen *sentinel = ir_implicit_cast(ira, uncasted_sentinel, elem_type);
25368 if (type_is_invalid(sentinel->value->type))26253 if (type_is_invalid(sentinel->value->type))
25369 return ira->codegen->invalid_instruction;26254 return ira->codegen->invalid_inst_gen;
25370 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);26255 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);
25371 if (sentinel_val == nullptr)26256 if (sentinel_val == nullptr)
25372 return ira->codegen->invalid_instruction;26257 return ira->codegen->invalid_inst_gen;
25373 ZigType *slice_ptr_type = adjust_ptr_sentinel(ira->codegen, non_sentinel_slice_ptr_type, sentinel_val);26258 ZigType *slice_ptr_type = adjust_ptr_sentinel(ira->codegen, non_sentinel_slice_ptr_type, sentinel_val);
25374 return_type = get_slice_type(ira->codegen, slice_ptr_type);26259 return_type = get_slice_type(ira->codegen, slice_ptr_type);
25375 } else {26260 } else {
...@@ -25391,9 +26276,9 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -25391,9 +26276,9 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
25391 if (array_type->id == ZigTypeIdPointer) {26276 if (array_type->id == ZigTypeIdPointer) {
25392 ZigType *child_array_type = array_type->data.pointer.child_type;26277 ZigType *child_array_type = array_type->data.pointer.child_type;
25393 assert(child_array_type->id == ZigTypeIdArray);26278 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);
25395 if (parent_ptr == nullptr)26280 if (parent_ptr == nullptr)
25396 return ira->codegen->invalid_instruction;26281 return ira->codegen->invalid_inst_gen;
2539726282
2539826283
25399 if (parent_ptr->special == ConstValSpecialUndef) {26284 if (parent_ptr->special == ConstValSpecialUndef) {
...@@ -25402,26 +26287,26 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -25402,26 +26287,26 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
25402 rel_end = SIZE_MAX;26287 rel_end = SIZE_MAX;
25403 ptr_is_undef = true;26288 ptr_is_undef = true;
25404 } else {26289 } 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);
25406 if (array_val == nullptr)26291 if (array_val == nullptr)
25407 return ira->codegen->invalid_instruction;26292 return ira->codegen->invalid_inst_gen;
2540826293
25409 rel_end = child_array_type->data.array.len;26294 rel_end = child_array_type->data.array.len;
25410 abs_offset = 0;26295 abs_offset = 0;
25411 }26296 }
25412 } else {26297 } 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);
25414 if (array_val == nullptr)26299 if (array_val == nullptr)
25415 return ira->codegen->invalid_instruction;26300 return ira->codegen->invalid_inst_gen;
25416 rel_end = array_type->data.array.len;26301 rel_end = array_type->data.array.len;
25417 parent_ptr = nullptr;26302 parent_ptr = nullptr;
25418 abs_offset = 0;26303 abs_offset = 0;
25419 }26304 }
25420 } else if (array_type->id == ZigTypeIdPointer) {26305 } else if (array_type->id == ZigTypeIdPointer) {
25421 assert(array_type->data.pointer.ptr_len == PtrLenUnknown);26306 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);
25423 if (parent_ptr == nullptr)26308 if (parent_ptr == nullptr)
25424 return ira->codegen->invalid_instruction;26309 return ira->codegen->invalid_inst_gen;
2542526310
25426 if (parent_ptr->special == ConstValSpecialUndef) {26311 if (parent_ptr->special == ConstValSpecialUndef) {
25427 array_val = nullptr;26312 array_val = nullptr;
...@@ -25467,19 +26352,19 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -25467,19 +26352,19 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
25467 zig_panic("TODO slice of null ptr");26352 zig_panic("TODO slice of null ptr");
25468 }26353 }
25469 } else if (is_slice(array_type)) {26354 } 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);
25471 if (slice_ptr == nullptr)26356 if (slice_ptr == nullptr)
25472 return ira->codegen->invalid_instruction;26357 return ira->codegen->invalid_inst_gen;
2547326358
25474 if (slice_ptr->special == ConstValSpecialUndef) {26359 if (slice_ptr->special == ConstValSpecialUndef) {
25475 ir_add_error(ira, &instruction->base, buf_sprintf("slice of undefined"));26360 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of undefined"));
25476 return ira->codegen->invalid_instruction;26361 return ira->codegen->invalid_inst_gen;
25477 }26362 }
2547826363
25479 parent_ptr = slice_ptr->data.x_struct.fields[slice_ptr_index];26364 parent_ptr = slice_ptr->data.x_struct.fields[slice_ptr_index];
25480 if (parent_ptr->special == ConstValSpecialUndef) {26365 if (parent_ptr->special == ConstValSpecialUndef) {
25481 ir_add_error(ira, &instruction->base, buf_sprintf("slice of undefined"));26366 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of undefined"));
25482 return ira->codegen->invalid_instruction;26367 return ira->codegen->invalid_inst_gen;
25483 }26368 }
2548426369
25485 ZigValue *len_val = slice_ptr->data.x_struct.fields[slice_len_index];26370 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...@@ -25522,37 +26407,37 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2552226407
25523 ZigValue *start_val = ir_resolve_const(ira, casted_start, UndefBad);26408 ZigValue *start_val = ir_resolve_const(ira, casted_start, UndefBad);
25524 if (!start_val)26409 if (!start_val)
25525 return ira->codegen->invalid_instruction;26410 return ira->codegen->invalid_inst_gen;
2552626411
25527 uint64_t start_scalar = bigint_as_u64(&start_val->data.x_bigint);26412 uint64_t start_scalar = bigint_as_u64(&start_val->data.x_bigint);
25528 if (!ptr_is_undef && start_scalar > rel_end) {26413 if (!ptr_is_undef && start_scalar > rel_end) {
25529 ir_add_error(ira, &instruction->base, buf_sprintf("out of bounds slice"));26414 ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds slice"));
25530 return ira->codegen->invalid_instruction;26415 return ira->codegen->invalid_inst_gen;
25531 }26416 }
2553226417
25533 uint64_t end_scalar = rel_end;26418 uint64_t end_scalar = rel_end;
25534 if (end) {26419 if (end) {
25535 ZigValue *end_val = ir_resolve_const(ira, end, UndefBad);26420 ZigValue *end_val = ir_resolve_const(ira, end, UndefBad);
25536 if (!end_val)26421 if (!end_val)
25537 return ira->codegen->invalid_instruction;26422 return ira->codegen->invalid_inst_gen;
25538 end_scalar = bigint_as_u64(&end_val->data.x_bigint);26423 end_scalar = bigint_as_u64(&end_val->data.x_bigint);
25539 }26424 }
25540 if (!ptr_is_undef) {26425 if (!ptr_is_undef) {
25541 if (end_scalar > rel_end) {26426 if (end_scalar > rel_end) {
25542 ir_add_error(ira, &instruction->base, buf_sprintf("out of bounds slice"));26427 ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds slice"));
25543 return ira->codegen->invalid_instruction;26428 return ira->codegen->invalid_inst_gen;
25544 }26429 }
25545 if (start_scalar > end_scalar) {26430 if (start_scalar > end_scalar) {
25546 ir_add_error(ira, &instruction->base, buf_sprintf("slice start is greater than end"));26431 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice start is greater than end"));
25547 return ira->codegen->invalid_instruction;26432 return ira->codegen->invalid_inst_gen;
25548 }26433 }
25549 }26434 }
25550 if (ptr_is_undef && start_scalar != end_scalar) {26435 if (ptr_is_undef && start_scalar != end_scalar) {
25551 ir_add_error(ira, &instruction->base, buf_sprintf("non-zero length slice of undefined pointer"));26436 ir_add_error(ira, &instruction->base.base, buf_sprintf("non-zero length slice of undefined pointer"));
25552 return ira->codegen->invalid_instruction;26437 return ira->codegen->invalid_inst_gen;
25553 }26438 }
2555426439
25555 IrInstruction *result = ir_const(ira, &instruction->base, return_type);26440 IrInstGen *result = ir_const(ira, &instruction->base.base, return_type);
25556 ZigValue *out_val = result->value;26441 ZigValue *out_val = result->value;
25557 out_val->data.x_struct.fields = alloc_const_vals_ptrs(2);26442 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...@@ -25609,28 +26494,28 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
25609 return result;26494 return result;
25610 }26495 }
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,
25613 return_type, nullptr, true, false, true);26498 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) {
25615 return result_loc;26500 return result_loc;
25616 }26501 }
25617 return ir_build_slice_gen(ira, &instruction->base, return_type,26502 return ir_build_slice_gen(ira, &instruction->base.base, return_type,
25618 ptr_ptr, casted_start, end, instruction->safety_check_on, result_loc);26503 ptr_ptr, casted_start, end, instruction->safety_check_on, result_loc);
25619}26504}
2562026505
25621static IrInstruction *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstructionMemberCount *instruction) {26506static IrInstGen *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstSrcMemberCount *instruction) {
25622 Error err;26507 Error err;
25623 IrInstruction *container = instruction->container->child;26508 IrInstGen *container = instruction->container->child;
25624 if (type_is_invalid(container->value->type))26509 if (type_is_invalid(container->value->type))
25625 return ira->codegen->invalid_instruction;26510 return ira->codegen->invalid_inst_gen;
25626 ZigType *container_type = ir_resolve_type(ira, container);26511 ZigType *container_type = ir_resolve_type(ira, container);
2562726512
25628 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))26513 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))
25629 return ira->codegen->invalid_instruction;26514 return ira->codegen->invalid_inst_gen;
2563026515
25631 uint64_t result;26516 uint64_t result;
25632 if (type_is_invalid(container_type)) {26517 if (type_is_invalid(container_type)) {
25633 return ira->codegen->invalid_instruction;26518 return ira->codegen->invalid_inst_gen;
25634 } else if (container_type->id == ZigTypeIdEnum) {26519 } else if (container_type->id == ZigTypeIdEnum) {
25635 result = container_type->data.enumeration.src_field_count;26520 result = container_type->data.enumeration.src_field_count;
25636 } else if (container_type->id == ZigTypeIdStruct) {26521 } else if (container_type->id == ZigTypeIdStruct) {
...@@ -25638,135 +26523,135 @@ static IrInstruction *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInst...@@ -25638,135 +26523,135 @@ static IrInstruction *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInst
25638 } else if (container_type->id == ZigTypeIdUnion) {26523 } else if (container_type->id == ZigTypeIdUnion) {
25639 result = container_type->data.unionation.src_field_count;26524 result = container_type->data.unionation.src_field_count;
25640 } else if (container_type->id == ZigTypeIdErrorSet) {26525 } else if (container_type->id == ZigTypeIdErrorSet) {
25641 if (!resolve_inferred_error_set(ira->codegen, container_type, instruction->base.source_node)) {26526 if (!resolve_inferred_error_set(ira->codegen, container_type, instruction->base.base.source_node)) {
25642 return ira->codegen->invalid_instruction;26527 return ira->codegen->invalid_inst_gen;
25643 }26528 }
25644 if (type_is_global_error_set(container_type)) {26529 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"));26530 ir_add_error(ira, &instruction->base.base, buf_sprintf("global error set member count not available at comptime"));
25646 return ira->codegen->invalid_instruction;26531 return ira->codegen->invalid_inst_gen;
25647 }26532 }
25648 result = container_type->data.error_set.err_count;26533 result = container_type->data.error_set.err_count;
25649 } else {26534 } else {
25650 ir_add_error(ira, &instruction->base, buf_sprintf("no value count available for type '%s'", buf_ptr(&container_type->name)));26535 ir_add_error(ira, &instruction->base.base, buf_sprintf("no value count available for type '%s'", buf_ptr(&container_type->name)));
25651 return ira->codegen->invalid_instruction;26536 return ira->codegen->invalid_inst_gen;
25652 }26537 }
2565326538
25654 return ir_const_unsigned(ira, &instruction->base, result);26539 return ir_const_unsigned(ira, &instruction->base.base, result);
25655}26540}
2565626541
25657static IrInstruction *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstructionMemberType *instruction) {26542static IrInstGen *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstSrcMemberType *instruction) {
25658 Error err;26543 Error err;
25659 IrInstruction *container_type_value = instruction->container_type->child;26544 IrInstGen *container_type_value = instruction->container_type->child;
25660 ZigType *container_type = ir_resolve_type(ira, container_type_value);26545 ZigType *container_type = ir_resolve_type(ira, container_type_value);
25661 if (type_is_invalid(container_type))26546 if (type_is_invalid(container_type))
25662 return ira->codegen->invalid_instruction;26547 return ira->codegen->invalid_inst_gen;
2566326548
25664 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))26549 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))
25665 return ira->codegen->invalid_instruction;26550 return ira->codegen->invalid_inst_gen;
2566626551
2566726552
25668 uint64_t member_index;26553 uint64_t member_index;
25669 IrInstruction *index_value = instruction->member_index->child;26554 IrInstGen *index_value = instruction->member_index->child;
25670 if (!ir_resolve_usize(ira, index_value, &member_index))26555 if (!ir_resolve_usize(ira, index_value, &member_index))
25671 return ira->codegen->invalid_instruction;26556 return ira->codegen->invalid_inst_gen;
2567226557
25673 if (container_type->id == ZigTypeIdStruct) {26558 if (container_type->id == ZigTypeIdStruct) {
25674 if (member_index >= container_type->data.structure.src_field_count) {26559 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,
25676 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",26561 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
25677 member_index, buf_ptr(&container_type->name), container_type->data.structure.src_field_count));26562 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;
25679 }26564 }
25680 TypeStructField *field = container_type->data.structure.fields[member_index];26565 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);
25683 } else if (container_type->id == ZigTypeIdUnion) {26568 } else if (container_type->id == ZigTypeIdUnion) {
25684 if (member_index >= container_type->data.unionation.src_field_count) {26569 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,
25686 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",26571 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
25687 member_index, buf_ptr(&container_type->name), container_type->data.unionation.src_field_count));26572 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;
25689 }26574 }
25690 TypeUnionField *field = &container_type->data.unionation.fields[member_index];26575 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);
25693 } else {26578 } else {
25694 ir_add_error(ira, container_type_value,26579 ir_add_error(ira, &container_type_value->base,
25695 buf_sprintf("type '%s' does not support @memberType", buf_ptr(&container_type->name)));26580 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;
25697 }26582 }
25698}26583}
2569926584
25700static IrInstruction *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstructionMemberName *instruction) {26585static IrInstGen *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstSrcMemberName *instruction) {
25701 Error err;26586 Error err;
25702 IrInstruction *container_type_value = instruction->container_type->child;26587 IrInstGen *container_type_value = instruction->container_type->child;
25703 ZigType *container_type = ir_resolve_type(ira, container_type_value);26588 ZigType *container_type = ir_resolve_type(ira, container_type_value);
25704 if (type_is_invalid(container_type))26589 if (type_is_invalid(container_type))
25705 return ira->codegen->invalid_instruction;26590 return ira->codegen->invalid_inst_gen;
2570626591
25707 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))26592 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))
25708 return ira->codegen->invalid_instruction;26593 return ira->codegen->invalid_inst_gen;
2570926594
25710 uint64_t member_index;26595 uint64_t member_index;
25711 IrInstruction *index_value = instruction->member_index->child;26596 IrInstGen *index_value = instruction->member_index->child;
25712 if (!ir_resolve_usize(ira, index_value, &member_index))26597 if (!ir_resolve_usize(ira, index_value, &member_index))
25713 return ira->codegen->invalid_instruction;26598 return ira->codegen->invalid_inst_gen;
2571426599
25715 if (container_type->id == ZigTypeIdStruct) {26600 if (container_type->id == ZigTypeIdStruct) {
25716 if (member_index >= container_type->data.structure.src_field_count) {26601 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,
25718 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",26603 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
25719 member_index, buf_ptr(&container_type->name), container_type->data.structure.src_field_count));26604 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;
25721 }26606 }
25722 TypeStructField *field = container_type->data.structure.fields[member_index];26607 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);
25725 init_const_str_lit(ira->codegen, result->value, field->name);26610 init_const_str_lit(ira->codegen, result->value, field->name);
25726 return result;26611 return result;
25727 } else if (container_type->id == ZigTypeIdEnum) {26612 } else if (container_type->id == ZigTypeIdEnum) {
25728 if (member_index >= container_type->data.enumeration.src_field_count) {26613 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,
25730 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",26615 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
25731 member_index, buf_ptr(&container_type->name), container_type->data.enumeration.src_field_count));26616 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;
25733 }26618 }
25734 TypeEnumField *field = &container_type->data.enumeration.fields[member_index];26619 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);
25737 init_const_str_lit(ira->codegen, result->value, field->name);26622 init_const_str_lit(ira->codegen, result->value, field->name);
25738 return result;26623 return result;
25739 } else if (container_type->id == ZigTypeIdUnion) {26624 } else if (container_type->id == ZigTypeIdUnion) {
25740 if (member_index >= container_type->data.unionation.src_field_count) {26625 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,
25742 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",26627 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
25743 member_index, buf_ptr(&container_type->name), container_type->data.unionation.src_field_count));26628 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;
25745 }26630 }
25746 TypeUnionField *field = &container_type->data.unionation.fields[member_index];26631 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);
25749 init_const_str_lit(ira->codegen, result->value, field->name);26634 init_const_str_lit(ira->codegen, result->value, field->name);
25750 return result;26635 return result;
25751 } else {26636 } else {
25752 ir_add_error(ira, container_type_value,26637 ir_add_error(ira, &container_type_value->base,
25753 buf_sprintf("type '%s' does not support @memberName", buf_ptr(&container_type->name)));26638 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;
25755 }26640 }
25756}26641}
2575726642
25758static IrInstruction *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstructionHasField *instruction) {26643static IrInstGen *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstSrcHasField *instruction) {
25759 Error err;26644 Error err;
25760 ZigType *container_type = ir_resolve_type(ira, instruction->container_type->child);26645 ZigType *container_type = ir_resolve_type(ira, instruction->container_type->child);
25761 if (type_is_invalid(container_type))26646 if (type_is_invalid(container_type))
25762 return ira->codegen->invalid_instruction;26647 return ira->codegen->invalid_inst_gen;
2576326648
25764 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusZeroBitsKnown)))26649 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusZeroBitsKnown)))
25765 return ira->codegen->invalid_instruction;26650 return ira->codegen->invalid_inst_gen;
2576626651
25767 Buf *field_name = ir_resolve_str(ira, instruction->field_name->child);26652 Buf *field_name = ir_resolve_str(ira, instruction->field_name->child);
25768 if (field_name == nullptr)26653 if (field_name == nullptr)
25769 return ira->codegen->invalid_instruction;26654 return ira->codegen->invalid_inst_gen;
2577026655
25771 bool result;26656 bool result;
25772 if (container_type->id == ZigTypeIdStruct) {26657 if (container_type->id == ZigTypeIdStruct) {
...@@ -25776,91 +26661,77 @@ static IrInstruction *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstruc...@@ -25776,91 +26661,77 @@ static IrInstruction *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstruc
25776 } else if (container_type->id == ZigTypeIdUnion) {26661 } else if (container_type->id == ZigTypeIdUnion) {
25777 result = find_union_type_field(container_type, field_name) != nullptr;26662 result = find_union_type_field(container_type, field_name) != nullptr;
25778 } else {26663 } else {
25779 ir_add_error(ira, instruction->container_type,26664 ir_add_error(ira, &instruction->container_type->base,
25780 buf_sprintf("type '%s' does not support @hasField", buf_ptr(&container_type->name)));26665 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;
25782 }26667 }
25783 return ir_const_bool(ira, &instruction->base, result);26668 return ir_const_bool(ira, &instruction->base.base, result);
25784}26669}
2578526670
25786static IrInstruction *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstructionBreakpoint *instruction) {26671static IrInstGen *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstSrcBreakpoint *instruction) {
25787 IrInstruction *result = ir_build_breakpoint(&ira->new_irb,26672 return ir_build_breakpoint_gen(ira, &instruction->base.base);
25788 instruction->base.scope, instruction->base.source_node);
25789 result->value->type = ira->codegen->builtin_types.entry_void;
25790 return result;
25791}26673}
2579226674
25793static IrInstruction *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstructionReturnAddress *instruction) {26675static IrInstGen *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstSrcReturnAddress *instruction) {
25794 IrInstruction *result = ir_build_return_address(&ira->new_irb,26676 return ir_build_return_address_gen(ira, &instruction->base.base);
25795 instruction->base.scope, instruction->base.source_node);
25796 result->value->type = ira->codegen->builtin_types.entry_usize;
25797 return result;
25798}26677}
2579926678
25800static IrInstruction *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstructionFrameAddress *instruction) {26679static IrInstGen *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstSrcFrameAddress *instruction) {
25801 IrInstruction *result = ir_build_frame_address(&ira->new_irb,26680 return ir_build_frame_address_gen(ira, &instruction->base.base);
25802 instruction->base.scope, instruction->base.source_node);
25803 result->value->type = ira->codegen->builtin_types.entry_usize;
25804 return result;
25805}26681}
2580626682
25807static IrInstruction *ir_analyze_instruction_frame_handle(IrAnalyze *ira, IrInstructionFrameHandle *instruction) {26683static IrInstGen *ir_analyze_instruction_frame_handle(IrAnalyze *ira, IrInstSrcFrameHandle *instruction) {
25808 ZigFn *fn = exec_fn_entry(ira->new_irb.exec);26684 ZigFn *fn = ira->new_irb.exec->fn_entry;
25809 ir_assert(fn != nullptr, &instruction->base);26685 ir_assert(fn != nullptr, &instruction->base.base);
2581026686
25811 if (fn->inferred_async_node == nullptr) {26687 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;
25813 }26689 }
2581426690
25815 ZigType *frame_type = get_fn_frame_type(ira->codegen, fn);26691 ZigType *frame_type = get_fn_frame_type(ira->codegen, fn);
25816 ZigType *ptr_frame_type = get_pointer_to_type(ira->codegen, frame_type, false);26692 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);26694 return ir_build_handle_gen(ira, &instruction->base.base, ptr_frame_type);
25819 result->value->type = ptr_frame_type;
25820 return result;
25821}26695}
2582226696
25823static IrInstruction *ir_analyze_instruction_frame_type(IrAnalyze *ira, IrInstructionFrameType *instruction) {26697static IrInstGen *ir_analyze_instruction_frame_type(IrAnalyze *ira, IrInstSrcFrameType *instruction) {
25824 ZigFn *fn = ir_resolve_fn(ira, instruction->fn->child);26698 ZigFn *fn = ir_resolve_fn(ira, instruction->fn->child);
25825 if (fn == nullptr)26699 if (fn == nullptr)
25826 return ira->codegen->invalid_instruction;26700 return ira->codegen->invalid_inst_gen;
2582726701
25828 if (fn->type_entry->data.fn.is_generic) {26702 if (fn->type_entry->data.fn.is_generic) {
25829 ir_add_error(ira, &instruction->base,26703 ir_add_error(ira, &instruction->base.base,
25830 buf_sprintf("@Frame() of generic function"));26704 buf_sprintf("@Frame() of generic function"));
25831 return ira->codegen->invalid_instruction;26705 return ira->codegen->invalid_inst_gen;
25832 }26706 }
2583326707
25834 ZigType *ty = get_fn_frame_type(ira->codegen, fn);26708 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);
25836}26710}
2583726711
25838static IrInstruction *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstructionFrameSizeSrc *instruction) {26712static IrInstGen *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstSrcFrameSize *instruction) {
25839 IrInstruction *fn = instruction->fn->child;26713 IrInstGen *fn = instruction->fn->child;
25840 if (type_is_invalid(fn->value->type))26714 if (type_is_invalid(fn->value->type))
25841 return ira->codegen->invalid_instruction;26715 return ira->codegen->invalid_inst_gen;
2584226716
25843 if (fn->value->type->id != ZigTypeIdFn) {26717 if (fn->value->type->id != ZigTypeIdFn) {
25844 ir_add_error(ira, fn,26718 ir_add_error(ira, &fn->base,
25845 buf_sprintf("expected function, found '%s'", buf_ptr(&fn->value->type->name)));26719 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;
25847 }26721 }
2584826722
25849 ira->codegen->need_frame_size_prefix_data = true;26723 ira->codegen->need_frame_size_prefix_data = true;
2585026724
25851 IrInstruction *result = ir_build_frame_size_gen(&ira->new_irb, instruction->base.scope,26725 return ir_build_frame_size_gen(ira, &instruction->base.base, fn);
25852 instruction->base.source_node, fn);
25853 result->value->type = ira->codegen->builtin_types.entry_usize;
25854 return result;
25855}26726}
2585626727
25857static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstructionAlignOf *instruction) {26728static IrInstGen *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstSrcAlignOf *instruction) {
25858 // Here we create a lazy value in order to avoid resolving the alignment of the type26729 // Here we create a lazy value in order to avoid resolving the alignment of the type
25859 // immediately. This avoids false positive dependency loops such as:26730 // immediately. This avoids false positive dependency loops such as:
25860 // const Node = struct {26731 // const Node = struct {
25861 // field: []align(@alignOf(Node)) Node,26732 // field: []align(@alignOf(Node)) Node,
25862 // };26733 // };
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);
25864 result->value->special = ConstValSpecialLazy;26735 result->value->special = ConstValSpecialLazy;
2586526736
25866 LazyValueAlignOf *lazy_align_of = allocate<LazyValueAlignOf>(1, "LazyValueAlignOf");26737 LazyValueAlignOf *lazy_align_of = allocate<LazyValueAlignOf>(1, "LazyValueAlignOf");
...@@ -25870,41 +26741,41 @@ static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruct...@@ -25870,41 +26741,41 @@ static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruct
2587026741
25871 lazy_align_of->target_type = instruction->type_value->child;26742 lazy_align_of->target_type = instruction->type_value->child;
25872 if (ir_resolve_type_lazy(ira, lazy_align_of->target_type) == nullptr)26743 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
25875 return result;26746 return result;
25876}26747}
2587726748
25878static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstructionOverflowOp *instruction) {26749static IrInstGen *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstSrcOverflowOp *instruction) {
25879 Error err;26750 Error err;
2588026751
25881 IrInstruction *type_value = instruction->type_value->child;26752 IrInstGen *type_value = instruction->type_value->child;
25882 if (type_is_invalid(type_value->value->type))26753 if (type_is_invalid(type_value->value->type))
25883 return ira->codegen->invalid_instruction;26754 return ira->codegen->invalid_inst_gen;
2588426755
25885 ZigType *dest_type = ir_resolve_type(ira, type_value);26756 ZigType *dest_type = ir_resolve_type(ira, type_value);
25886 if (type_is_invalid(dest_type))26757 if (type_is_invalid(dest_type))
25887 return ira->codegen->invalid_instruction;26758 return ira->codegen->invalid_inst_gen;
2588826759
25889 if (dest_type->id != ZigTypeIdInt) {26760 if (dest_type->id != ZigTypeIdInt) {
25890 ir_add_error(ira, type_value,26761 ir_add_error(ira, &type_value->base,
25891 buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));26762 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;
25893 }26764 }
2589426765
25895 IrInstruction *op1 = instruction->op1->child;26766 IrInstGen *op1 = instruction->op1->child;
25896 if (type_is_invalid(op1->value->type))26767 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);
25900 if (type_is_invalid(casted_op1->value->type))26771 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;
25904 if (type_is_invalid(op2->value->type))26775 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;
25908 if (instruction->op == IrOverflowOpShl) {26779 if (instruction->op == IrOverflowOpShl) {
25909 ZigType *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen,26780 ZigType *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen,
25910 dest_type->data.integral.bit_count - 1);26781 dest_type->data.integral.bit_count - 1);
...@@ -25913,17 +26784,17 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr...@@ -25913,17 +26784,17 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr
25913 casted_op2 = ir_implicit_cast(ira, op2, dest_type);26784 casted_op2 = ir_implicit_cast(ira, op2, dest_type);
25914 }26785 }
25915 if (type_is_invalid(casted_op2->value->type))26786 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;
25919 if (type_is_invalid(result_ptr->value->type))26790 if (type_is_invalid(result_ptr->value->type))
25920 return ira->codegen->invalid_instruction;26791 return ira->codegen->invalid_inst_gen;
2592126792
25922 ZigType *expected_ptr_type;26793 ZigType *expected_ptr_type;
25923 if (result_ptr->value->type->id == ZigTypeIdPointer) {26794 if (result_ptr->value->type->id == ZigTypeIdPointer) {
25924 uint32_t alignment;26795 uint32_t alignment;
25925 if ((err = resolve_ptr_align(ira, result_ptr->value->type, &alignment)))26796 if ((err = resolve_ptr_align(ira, result_ptr->value->type, &alignment)))
25926 return ira->codegen->invalid_instruction;26797 return ira->codegen->invalid_inst_gen;
25927 expected_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_type,26798 expected_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_type,
25928 false, result_ptr->value->type->data.pointer.is_volatile,26799 false, result_ptr->value->type->data.pointer.is_volatile,
25929 PtrLenSingle,26800 PtrLenSingle,
...@@ -25932,9 +26803,9 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr...@@ -25932,9 +26803,9 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr
25932 expected_ptr_type = get_pointer_to_type(ira->codegen, dest_type, false);26803 expected_ptr_type = get_pointer_to_type(ira->codegen, dest_type, false);
25933 }26804 }
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);
25936 if (type_is_invalid(casted_result_ptr->value->type))26807 if (type_is_invalid(casted_result_ptr->value->type))
25937 return ira->codegen->invalid_instruction;26808 return ira->codegen->invalid_inst_gen;
2593826809
25939 if (instr_is_comptime(casted_op1) &&26810 if (instr_is_comptime(casted_op1) &&
25940 instr_is_comptime(casted_op2) &&26811 instr_is_comptime(casted_op2) &&
...@@ -25942,22 +26813,22 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr...@@ -25942,22 +26813,22 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr
25942 {26813 {
25943 ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);26814 ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);
25944 if (op1_val == nullptr)26815 if (op1_val == nullptr)
25945 return ira->codegen->invalid_instruction;26816 return ira->codegen->invalid_inst_gen;
2594626817
25947 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);26818 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
25948 if (op2_val == nullptr)26819 if (op2_val == nullptr)
25949 return ira->codegen->invalid_instruction;26820 return ira->codegen->invalid_inst_gen;
2595026821
25951 ZigValue *result_val = ir_resolve_const(ira, casted_result_ptr, UndefBad);26822 ZigValue *result_val = ir_resolve_const(ira, casted_result_ptr, UndefBad);
25952 if (result_val == nullptr)26823 if (result_val == nullptr)
25953 return ira->codegen->invalid_instruction;26824 return ira->codegen->invalid_inst_gen;
2595426825
25955 BigInt *op1_bigint = &op1_val->data.x_bigint;26826 BigInt *op1_bigint = &op1_val->data.x_bigint;
25956 BigInt *op2_bigint = &op2_val->data.x_bigint;26827 BigInt *op2_bigint = &op2_val->data.x_bigint;
25957 ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, result_val,26828 ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, result_val,
25958 casted_result_ptr->source_node);26829 casted_result_ptr->base.source_node);
25959 if (pointee_val == nullptr)26830 if (pointee_val == nullptr)
25960 return ira->codegen->invalid_instruction;26831 return ira->codegen->invalid_inst_gen;
25961 BigInt *dest_bigint = &pointee_val->data.x_bigint;26832 BigInt *dest_bigint = &pointee_val->data.x_bigint;
25962 switch (instruction->op) {26833 switch (instruction->op) {
25963 case IrOverflowOpAdd:26834 case IrOverflowOpAdd:
...@@ -25984,17 +26855,14 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr...@@ -25984,17 +26855,14 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr
25984 dest_type->data.integral.is_signed);26855 dest_type->data.integral.is_signed);
25985 }26856 }
25986 pointee_val->special = ConstValSpecialStatic;26857 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);
25988 }26859 }
2598926860
25990 IrInstruction *result = ir_build_overflow_op(&ira->new_irb,26861 return ir_build_overflow_op_gen(ira, &instruction->base.base, instruction->op,
25991 instruction->base.scope, instruction->base.source_node,26862 casted_op1, casted_op2, casted_result_ptr, dest_type);
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;
25995}26863}
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,
25998 ZigValue *op1, ZigValue *op2, ZigValue *op3, ZigValue *out_val) {26866 ZigValue *op1, ZigValue *op2, ZigValue *op3, ZigValue *out_val) {
25999 if (float_type->id == ZigTypeIdComptimeFloat) {26867 if (float_type->id == ZigTypeIdComptimeFloat) {
26000 f128M_mulAdd(&out_val->data.x_bigfloat.value, &op1->data.x_bigfloat.value, &op2->data.x_bigfloat.value,26868 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...@@ -26021,61 +26889,61 @@ static void ir_eval_mul_add(IrAnalyze *ira, IrInstructionMulAdd *source_instr, Z
26021 }26889 }
26022}26890}
2602326891
26024static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructionMulAdd *instruction) {26892static IrInstGen *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstSrcMulAdd *instruction) {
26025 IrInstruction *type_value = instruction->type_value->child;26893 IrInstGen *type_value = instruction->type_value->child;
26026 if (type_is_invalid(type_value->value->type))26894 if (type_is_invalid(type_value->value->type))
26027 return ira->codegen->invalid_instruction;26895 return ira->codegen->invalid_inst_gen;
2602826896
26029 ZigType *expr_type = ir_resolve_type(ira, type_value);26897 ZigType *expr_type = ir_resolve_type(ira, type_value);
26030 if (type_is_invalid(expr_type))26898 if (type_is_invalid(expr_type))
26031 return ira->codegen->invalid_instruction;26899 return ira->codegen->invalid_inst_gen;
2603226900
26033 // Only allow float types, and vectors of floats.26901 // Only allow float types, and vectors of floats.
26034 ZigType *float_type = (expr_type->id == ZigTypeIdVector) ? expr_type->data.vector.elem_type : expr_type;26902 ZigType *float_type = (expr_type->id == ZigTypeIdVector) ? expr_type->data.vector.elem_type : expr_type;
26035 if (float_type->id != ZigTypeIdFloat) {26903 if (float_type->id != ZigTypeIdFloat) {
26036 ir_add_error(ira, type_value,26904 ir_add_error(ira, &type_value->base,
26037 buf_sprintf("expected float or vector of float type, found '%s'", buf_ptr(&float_type->name)));26905 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;
26039 }26907 }
2604026908
26041 IrInstruction *op1 = instruction->op1->child;26909 IrInstGen *op1 = instruction->op1->child;
26042 if (type_is_invalid(op1->value->type))26910 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);
26046 if (type_is_invalid(casted_op1->value->type))26914 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;
26050 if (type_is_invalid(op2->value->type))26918 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);
26054 if (type_is_invalid(casted_op2->value->type))26922 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;
26058 if (type_is_invalid(op3->value->type))26926 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);
26062 if (type_is_invalid(casted_op3->value->type))26930 if (type_is_invalid(casted_op3->value->type))
26063 return ira->codegen->invalid_instruction;26931 return ira->codegen->invalid_inst_gen;
2606426932
26065 if (instr_is_comptime(casted_op1) &&26933 if (instr_is_comptime(casted_op1) &&
26066 instr_is_comptime(casted_op2) &&26934 instr_is_comptime(casted_op2) &&
26067 instr_is_comptime(casted_op3)) {26935 instr_is_comptime(casted_op3)) {
26068 ZigValue *op1_const = ir_resolve_const(ira, casted_op1, UndefBad);26936 ZigValue *op1_const = ir_resolve_const(ira, casted_op1, UndefBad);
26069 if (!op1_const)26937 if (!op1_const)
26070 return ira->codegen->invalid_instruction;26938 return ira->codegen->invalid_inst_gen;
26071 ZigValue *op2_const = ir_resolve_const(ira, casted_op2, UndefBad);26939 ZigValue *op2_const = ir_resolve_const(ira, casted_op2, UndefBad);
26072 if (!op2_const)26940 if (!op2_const)
26073 return ira->codegen->invalid_instruction;26941 return ira->codegen->invalid_inst_gen;
26074 ZigValue *op3_const = ir_resolve_const(ira, casted_op3, UndefBad);26942 ZigValue *op3_const = ir_resolve_const(ira, casted_op3, UndefBad);
26075 if (!op3_const)26943 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);
26079 ZigValue *out_val = result->value;26947 ZigValue *out_val = result->value;
2608026948
26081 if (expr_type->id == ZigTypeIdVector) {26949 if (expr_type->id == ZigTypeIdVector) {
...@@ -26106,63 +26974,59 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi...@@ -26106,63 +26974,59 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi
26106 return result;26974 return result;
26107 }26975 }
2610826976
26109 IrInstruction *result = ir_build_mul_add(&ira->new_irb,26977 return ir_build_mul_add_gen(ira, &instruction->base.base, casted_op1, casted_op2, casted_op3, expr_type);
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;
26114}26978}
2611526979
26116static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTestErrSrc *instruction) {26980static IrInstGen *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstSrcTestErr *instruction) {
26117 IrInstruction *base_ptr = instruction->base_ptr->child;26981 IrInstGen *base_ptr = instruction->base_ptr->child;
26118 if (type_is_invalid(base_ptr->value->type))26982 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;
26122 if (instruction->base_ptr_is_payload) {26986 if (instruction->base_ptr_is_payload) {
26123 value = base_ptr;26987 value = base_ptr;
26124 } else {26988 } else {
26125 value = ir_get_deref(ira, &instruction->base, base_ptr, nullptr);26989 value = ir_get_deref(ira, &instruction->base.base, base_ptr, nullptr);
26126 }26990 }
2612726991
26128 ZigType *type_entry = value->value->type;26992 ZigType *type_entry = value->value->type;
26129 if (type_is_invalid(type_entry))26993 if (type_is_invalid(type_entry))
26130 return ira->codegen->invalid_instruction;26994 return ira->codegen->invalid_inst_gen;
26131 if (type_entry->id == ZigTypeIdErrorUnion) {26995 if (type_entry->id == ZigTypeIdErrorUnion) {
26132 if (instr_is_comptime(value)) {26996 if (instr_is_comptime(value)) {
26133 ZigValue *err_union_val = ir_resolve_const(ira, value, UndefBad);26997 ZigValue *err_union_val = ir_resolve_const(ira, value, UndefBad);
26134 if (!err_union_val)26998 if (!err_union_val)
26135 return ira->codegen->invalid_instruction;26999 return ira->codegen->invalid_inst_gen;
2613627000
26137 if (err_union_val->special != ConstValSpecialRuntime) {27001 if (err_union_val->special != ConstValSpecialRuntime) {
26138 ErrorTableEntry *err = err_union_val->data.x_err_union.error_set->data.x_err_set;27002 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));
26140 }27004 }
26141 }27005 }
2614227006
26143 if (instruction->resolve_err_set) {27007 if (instruction->resolve_err_set) {
26144 ZigType *err_set_type = type_entry->data.error_union.err_set_type;27008 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)) {27009 if (!resolve_inferred_error_set(ira->codegen, err_set_type, instruction->base.base.source_node)) {
26146 return ira->codegen->invalid_instruction;27010 return ira->codegen->invalid_inst_gen;
26147 }27011 }
26148 if (!type_is_global_error_set(err_set_type) &&27012 if (!type_is_global_error_set(err_set_type) &&
26149 err_set_type->data.error_set.err_count == 0)27013 err_set_type->data.error_set.err_count == 0)
26150 {27014 {
26151 assert(!err_set_type->data.error_set.incomplete);27015 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);
26153 }27017 }
26154 }27018 }
2615527019
26156 return ir_build_test_err_gen(ira, &instruction->base, value);27020 return ir_build_test_err_gen(ira, &instruction->base.base, value);
26157 } else if (type_entry->id == ZigTypeIdErrorSet) {27021 } 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);
26159 } else {27023 } else {
26160 return ir_const_bool(ira, &instruction->base, false);27024 return ir_const_bool(ira, &instruction->base.base, false);
26161 }27025 }
26162}27026}
2616327027
26164static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *source_instr,27028static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_instr,
26165 IrInstruction *base_ptr, bool initializing)27029 IrInstGen *base_ptr, bool initializing)
26166{27030{
26167 ZigType *ptr_type = base_ptr->value->type;27031 ZigType *ptr_type = base_ptr->value->type;
2616827032
...@@ -26171,12 +27035,12 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *...@@ -26171,12 +27035,12 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *
2617127035
26172 ZigType *type_entry = ptr_type->data.pointer.child_type;27036 ZigType *type_entry = ptr_type->data.pointer.child_type;
26173 if (type_is_invalid(type_entry))27037 if (type_is_invalid(type_entry))
26174 return ira->codegen->invalid_instruction;27038 return ira->codegen->invalid_inst_gen;
2617527039
26176 if (type_entry->id != ZigTypeIdErrorUnion) {27040 if (type_entry->id != ZigTypeIdErrorUnion) {
26177 ir_add_error(ira, base_ptr,27041 ir_add_error(ira, &base_ptr->base,
26178 buf_sprintf("expected error union type, found '%s'", buf_ptr(&type_entry->name)));27042 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;
26180 }27044 }
2618127045
26182 ZigType *err_set_type = type_entry->data.error_union.err_set_type;27046 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 *...@@ -26187,13 +27051,13 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *
26187 if (instr_is_comptime(base_ptr)) {27051 if (instr_is_comptime(base_ptr)) {
26188 ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad);27052 ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad);
26189 if (!ptr_val)27053 if (!ptr_val)
26190 return ira->codegen->invalid_instruction;27054 return ira->codegen->invalid_inst_gen;
26191 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar &&27055 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar &&
26192 ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr)27056 ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr)
26193 {27057 {
26194 ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);27058 ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
26195 if (err_union_val == nullptr)27059 if (err_union_val == nullptr)
26196 return ira->codegen->invalid_instruction;27060 return ira->codegen->invalid_inst_gen;
2619727061
26198 if (initializing && err_union_val->special == ConstValSpecialUndef) {27062 if (initializing && err_union_val->special == ConstValSpecialUndef) {
26199 ZigValue *vals = create_const_vals(2);27063 ZigValue *vals = create_const_vals(2);
...@@ -26216,11 +27080,10 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *...@@ -26216,11 +27080,10 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *
26216 }27080 }
26217 ir_assert(err_union_val->special != ConstValSpecialRuntime, source_instr);27081 ir_assert(err_union_val->special != ConstValSpecialRuntime, source_instr);
2621827082
26219 IrInstruction *result;27083 IrInstGen *result;
26220 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {27084 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
26221 result = ir_build_unwrap_err_code(&ira->new_irb, source_instr->scope,27085 result = ir_build_unwrap_err_code_gen(ira, source_instr->scope,
26222 source_instr->source_node, base_ptr);27086 source_instr->source_node, base_ptr, result_type);
26223 result->value->type = result_type;
26224 result->value->special = ConstValSpecialStatic;27087 result->value->special = ConstValSpecialStatic;
26225 } else {27088 } else {
26226 result = ir_const(ira, source_instr, result_type);27089 result = ir_const(ira, source_instr, result_type);
...@@ -26233,23 +27096,18 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *...@@ -26233,23 +27096,18 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *
26233 }27096 }
26234 }27097 }
2623527098
26236 IrInstruction *result = ir_build_unwrap_err_code(&ira->new_irb,27099 return ir_build_unwrap_err_code_gen(ira, source_instr->scope, source_instr->source_node, base_ptr, result_type);
26237 source_instr->scope, source_instr->source_node, base_ptr);
26238 result->value->type = result_type;
26239 return result;
26240}27100}
2624127101
26242static IrInstruction *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,27102static IrInstGen *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, IrInstSrcUnwrapErrCode *instruction) {
26243 IrInstructionUnwrapErrCode *instruction)27103 IrInstGen *base_ptr = instruction->err_union_ptr->child;
26244{
26245 IrInstruction *base_ptr = instruction->err_union_ptr->child;
26246 if (type_is_invalid(base_ptr->value->type))27104 if (type_is_invalid(base_ptr->value->type))
26247 return ira->codegen->invalid_instruction;27105 return ira->codegen->invalid_inst_gen;
26248 return ir_analyze_unwrap_err_code(ira, &instruction->base, base_ptr, false);27106 return ir_analyze_unwrap_err_code(ira, &instruction->base.base, base_ptr, false);
26249}27107}
2625027108
26251static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruction *source_instr,27109static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source_instr,
26252 IrInstruction *base_ptr, bool safety_check_on, bool initializing)27110 IrInstGen *base_ptr, bool safety_check_on, bool initializing)
26253{27111{
26254 ZigType *ptr_type = base_ptr->value->type;27112 ZigType *ptr_type = base_ptr->value->type;
2625527113
...@@ -26258,17 +27116,17 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct...@@ -26258,17 +27116,17 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct
2625827116
26259 ZigType *type_entry = ptr_type->data.pointer.child_type;27117 ZigType *type_entry = ptr_type->data.pointer.child_type;
26260 if (type_is_invalid(type_entry))27118 if (type_is_invalid(type_entry))
26261 return ira->codegen->invalid_instruction;27119 return ira->codegen->invalid_inst_gen;
2626227120
26263 if (type_entry->id != ZigTypeIdErrorUnion) {27121 if (type_entry->id != ZigTypeIdErrorUnion) {
26264 ir_add_error(ira, base_ptr,27122 ir_add_error(ira, &base_ptr->base,
26265 buf_sprintf("expected error union type, found '%s'", buf_ptr(&type_entry->name)));27123 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;
26267 }27125 }
2626827126
26269 ZigType *payload_type = type_entry->data.error_union.payload_type;27127 ZigType *payload_type = type_entry->data.error_union.payload_type;
26270 if (type_is_invalid(payload_type))27128 if (type_is_invalid(payload_type))
26271 return ira->codegen->invalid_instruction;27129 return ira->codegen->invalid_inst_gen;
2627227130
26273 ZigType *result_type = get_pointer_to_type_extra(ira->codegen, payload_type,27131 ZigType *result_type = get_pointer_to_type_extra(ira->codegen, payload_type,
26274 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,27132 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...@@ -26277,11 +27135,11 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct
26277 if (instr_is_comptime(base_ptr)) {27135 if (instr_is_comptime(base_ptr)) {
26278 ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad);27136 ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad);
26279 if (!ptr_val)27137 if (!ptr_val)
26280 return ira->codegen->invalid_instruction;27138 return ira->codegen->invalid_inst_gen;
26281 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {27139 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
26282 ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);27140 ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
26283 if (err_union_val == nullptr)27141 if (err_union_val == nullptr)
26284 return ira->codegen->invalid_instruction;27142 return ira->codegen->invalid_inst_gen;
26285 if (initializing && err_union_val->special == ConstValSpecialUndef) {27143 if (initializing && err_union_val->special == ConstValSpecialUndef) {
26286 ZigValue *vals = create_const_vals(2);27144 ZigValue *vals = create_const_vals(2);
26287 ZigValue *err_set_val = &vals[0];27145 ZigValue *err_set_val = &vals[0];
...@@ -26304,14 +27162,13 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct...@@ -26304,14 +27162,13 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct
26304 if (err != nullptr) {27162 if (err != nullptr) {
26305 ir_add_error(ira, source_instr,27163 ir_add_error(ira, source_instr,
26306 buf_sprintf("caught unexpected error '%s'", buf_ptr(&err->name)));27164 buf_sprintf("caught unexpected error '%s'", buf_ptr(&err->name)));
26307 return ira->codegen->invalid_instruction;27165 return ira->codegen->invalid_inst_gen;
26308 }27166 }
2630927167
26310 IrInstruction *result;27168 IrInstGen *result;
26311 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {27169 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
26312 result = ir_build_unwrap_err_payload(&ira->new_irb, source_instr->scope,27170 result = ir_build_unwrap_err_payload_gen(ira, source_instr->scope,
26313 source_instr->source_node, base_ptr, safety_check_on, initializing);27171 source_instr->source_node, base_ptr, safety_check_on, initializing, result_type);
26314 result->value->type = result_type;
26315 result->value->special = ConstValSpecialStatic;27172 result->value->special = ConstValSpecialStatic;
26316 } else {27173 } else {
26317 result = ir_const(ira, source_instr, result_type);27174 result = ir_const(ira, source_instr, result_type);
...@@ -26324,28 +27181,26 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct...@@ -26324,28 +27181,26 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct
26324 }27181 }
26325 }27182 }
2632627183
26327 IrInstruction *result = ir_build_unwrap_err_payload(&ira->new_irb, source_instr->scope,27184 return ir_build_unwrap_err_payload_gen(ira, source_instr->scope, source_instr->source_node,
26328 source_instr->source_node, base_ptr, safety_check_on, initializing);27185 base_ptr, safety_check_on, initializing, result_type);
26329 result->value->type = result_type;
26330 return result;
26331}27186}
2633227187
26333static IrInstruction *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,27188static IrInstGen *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
26334 IrInstructionUnwrapErrPayload *instruction)27189 IrInstSrcUnwrapErrPayload *instruction)
26335{27190{
26336 assert(instruction->value->child);27191 assert(instruction->value->child);
26337 IrInstruction *value = instruction->value->child;27192 IrInstGen *value = instruction->value->child;
26338 if (type_is_invalid(value->value->type))27193 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);
26342}27197}
2634327198
26344static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstructionFnProto *instruction) {27199static IrInstGen *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstSrcFnProto *instruction) {
26345 AstNode *proto_node = instruction->base.source_node;27200 AstNode *proto_node = instruction->base.base.source_node;
26346 assert(proto_node->type == NodeTypeFnProto);27201 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);
26349 result->value->special = ConstValSpecialLazy;27204 result->value->special = ConstValSpecialLazy;
2635027205
26351 LazyValueFnType *lazy_fn_type = allocate<LazyValueFnType>(1, "LazyValueFnType");27206 LazyValueFnType *lazy_fn_type = allocate<LazyValueFnType>(1, "LazyValueFnType");
...@@ -26354,29 +27209,29 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct...@@ -26354,29 +27209,29 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct
26354 lazy_fn_type->base.id = LazyValueIdFnType;27209 lazy_fn_type->base.id = LazyValueIdFnType;
2635527210
26356 if (proto_node->data.fn_proto.auto_err_set) {27211 if (proto_node->data.fn_proto.auto_err_set) {
26357 ir_add_error(ira, &instruction->base,27212 ir_add_error(ira, &instruction->base.base,
26358 buf_sprintf("inferring error set of return type valid only for function definitions"));27213 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;
26360 }27215 }
2636127216
26362 lazy_fn_type->cc = cc_from_fn_proto(&proto_node->data.fn_proto);27217 lazy_fn_type->cc = cc_from_fn_proto(&proto_node->data.fn_proto);
26363 if (instruction->callconv_value != nullptr) {27218 if (instruction->callconv_value != nullptr) {
26364 ZigType *cc_enum_type = get_builtin_type(ira->codegen, "CallingConvention");27219 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);
26367 if (type_is_invalid(casted_value->value->type))27222 if (type_is_invalid(casted_value->value->type))
26368 return ira->codegen->invalid_instruction;27223 return ira->codegen->invalid_inst_gen;
2636927224
26370 ZigValue *const_value = ir_resolve_const(ira, casted_value, UndefBad);27225 ZigValue *const_value = ir_resolve_const(ira, casted_value, UndefBad);
26371 if (const_value == nullptr)27226 if (const_value == nullptr)
26372 return ira->codegen->invalid_instruction;27227 return ira->codegen->invalid_inst_gen;
2637327228
26374 lazy_fn_type->cc = (CallingConvention)bigint_as_u32(&const_value->data.x_enum_tag);27229 lazy_fn_type->cc = (CallingConvention)bigint_as_u32(&const_value->data.x_enum_tag);
26375 }27230 }
2637627231
26377 size_t param_count = proto_node->data.fn_proto.params.length;27232 size_t param_count = proto_node->data.fn_proto.params.length;
26378 lazy_fn_type->proto_node = proto_node;27233 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
26381 for (size_t param_index = 0; param_index < param_count; param_index += 1) {27236 for (size_t param_index = 0; param_index < param_count; param_index += 1) {
26382 AstNode *param_node = proto_node->data.fn_proto.params.at(param_index);27237 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...@@ -26401,63 +27256,63 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct
26401 return result;27256 return result;
26402 }27257 }
2640327258
26404 IrInstruction *param_type_value = instruction->param_types[param_index]->child;27259 IrInstGen *param_type_value = instruction->param_types[param_index]->child;
26405 if (type_is_invalid(param_type_value->value->type))27260 if (type_is_invalid(param_type_value->value->type))
26406 return ira->codegen->invalid_instruction;27261 return ira->codegen->invalid_inst_gen;
26407 if (ir_resolve_const(ira, param_type_value, LazyOk) == nullptr)27262 if (ir_resolve_const(ira, param_type_value, LazyOk) == nullptr)
26408 return ira->codegen->invalid_instruction;27263 return ira->codegen->invalid_inst_gen;
26409 lazy_fn_type->param_types[param_index] = param_type_value;27264 lazy_fn_type->param_types[param_index] = param_type_value;
26410 }27265 }
2641127266
26412 if (instruction->align_value != nullptr) {27267 if (instruction->align_value != nullptr) {
26413 lazy_fn_type->align_inst = instruction->align_value->child;27268 lazy_fn_type->align_inst = instruction->align_value->child;
26414 if (ir_resolve_const(ira, lazy_fn_type->align_inst, LazyOk) == nullptr)27269 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;
26416 }27271 }
2641727272
26418 lazy_fn_type->return_type = instruction->return_type->child;27273 lazy_fn_type->return_type = instruction->return_type->child;
26419 if (ir_resolve_const(ira, lazy_fn_type->return_type, LazyOk) == nullptr)27274 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
26422 return result;27277 return result;
26423}27278}
2642427279
26425static IrInstruction *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstructionTestComptime *instruction) {27280static IrInstGen *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstSrcTestComptime *instruction) {
26426 IrInstruction *value = instruction->value->child;27281 IrInstGen *value = instruction->value->child;
26427 if (type_is_invalid(value->value->type))27282 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));
26431}27286}
2643227287
26433static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,27288static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
26434 IrInstructionCheckSwitchProngs *instruction)27289 IrInstSrcCheckSwitchProngs *instruction)
26435{27290{
26436 IrInstruction *target_value = instruction->target_value->child;27291 IrInstGen *target_value = instruction->target_value->child;
26437 ZigType *switch_type = target_value->value->type;27292 ZigType *switch_type = target_value->value->type;
26438 if (type_is_invalid(switch_type))27293 if (type_is_invalid(switch_type))
26439 return ira->codegen->invalid_instruction;27294 return ira->codegen->invalid_inst_gen;
2644027295
26441 if (switch_type->id == ZigTypeIdEnum) {27296 if (switch_type->id == ZigTypeIdEnum) {
26442 HashMap<BigInt, AstNode *, bigint_hash, bigint_eql> field_prev_uses = {};27297 HashMap<BigInt, AstNode *, bigint_hash, bigint_eql> field_prev_uses = {};
26443 field_prev_uses.init(switch_type->data.enumeration.src_field_count);27298 field_prev_uses.init(switch_type->data.enumeration.src_field_count);
2644427299
26445 for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {27300 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;
26449 if (type_is_invalid(start_value_uncasted->value->type))27304 if (type_is_invalid(start_value_uncasted->value->type))
26450 return ira->codegen->invalid_instruction;27305 return ira->codegen->invalid_inst_gen;
26451 IrInstruction *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type);27306 IrInstGen *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type);
26452 if (type_is_invalid(start_value->value->type))27307 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;
26456 if (type_is_invalid(end_value_uncasted->value->type))27311 if (type_is_invalid(end_value_uncasted->value->type))
26457 return ira->codegen->invalid_instruction;27312 return ira->codegen->invalid_inst_gen;
26458 IrInstruction *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type);27313 IrInstGen *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type);
26459 if (type_is_invalid(end_value->value->type))27314 if (type_is_invalid(end_value->value->type))
26460 return ira->codegen->invalid_instruction;27315 return ira->codegen->invalid_inst_gen;
2646127316
26462 assert(start_value->value->type->id == ZigTypeIdEnum);27317 assert(start_value->value->type->id == ZigTypeIdEnum);
26463 BigInt start_index;27318 BigInt start_index;
...@@ -26468,7 +27323,7 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -26468,7 +27323,7 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
26468 bigint_init_bigint(&end_index, &end_value->value->data.x_enum_tag);27323 bigint_init_bigint(&end_index, &end_value->value->data.x_enum_tag);
2646927324
26470 if (bigint_cmp(&start_index, &end_index) == CmpGT) {27325 if (bigint_cmp(&start_index, &end_index) == CmpGT) {
26471 ir_add_error(ira, start_value,27326 ir_add_error(ira, &start_value->base,
26472 buf_sprintf("range start value is greater than the end value"));27327 buf_sprintf("range start value is greater than the end value"));
26473 }27328 }
2647427329
...@@ -26479,12 +27334,12 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -26479,12 +27334,12 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
26479 if (cmp == CmpGT) {27334 if (cmp == CmpGT) {
26480 break;27335 break;
26481 }27336 }
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);
26483 if (entry) {27338 if (entry) {
26484 AstNode *prev_node = entry->value;27339 AstNode *prev_node = entry->value;
26485 TypeEnumField *enum_field = find_enum_field_by_tag(switch_type, &field_index);27340 TypeEnumField *enum_field = find_enum_field_by_tag(switch_type, &field_index);
26486 assert(enum_field != nullptr);27341 assert(enum_field != nullptr);
26487 ErrorMsg *msg = ir_add_error(ira, start_value,27342 ErrorMsg *msg = ir_add_error(ira, &start_value->base,
26488 buf_sprintf("duplicate switch value: '%s.%s'", buf_ptr(&switch_type->name),27343 buf_sprintf("duplicate switch value: '%s.%s'", buf_ptr(&switch_type->name),
26489 buf_ptr(enum_field->name)));27344 buf_ptr(enum_field->name)));
26490 add_error_note(ira->codegen, msg, prev_node, buf_sprintf("other value is here"));27345 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,...@@ -26494,7 +27349,7 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
26494 }27349 }
26495 if (instruction->have_underscore_prong) {27350 if (instruction->have_underscore_prong) {
26496 if (!switch_type->data.enumeration.non_exhaustive){27351 if (!switch_type->data.enumeration.non_exhaustive){
26497 ir_add_error(ira, &instruction->base,27352 ir_add_error(ira, &instruction->base.base,
26498 buf_sprintf("switch on non-exhaustive enum has `_` prong"));27353 buf_sprintf("switch on non-exhaustive enum has `_` prong"));
26499 }27354 }
26500 for (uint32_t i = 0; i < switch_type->data.enumeration.src_field_count; i += 1) {27355 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,...@@ -26504,14 +27359,14 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2650427359
26505 auto entry = field_prev_uses.maybe_get(enum_field->value);27360 auto entry = field_prev_uses.maybe_get(enum_field->value);
26506 if (!entry) {27361 if (!entry) {
26507 ir_add_error(ira, &instruction->base,27362 ir_add_error(ira, &instruction->base.base,
26508 buf_sprintf("enumeration value '%s.%s' not handled in switch", buf_ptr(&switch_type->name),27363 buf_sprintf("enumeration value '%s.%s' not handled in switch", buf_ptr(&switch_type->name),
26509 buf_ptr(enum_field->name)));27364 buf_ptr(enum_field->name)));
26510 }27365 }
26511 }27366 }
26512 } else if (!instruction->have_else_prong) {27367 } else if (!instruction->have_else_prong) {
26513 if (switch_type->data.enumeration.non_exhaustive) {27368 if (switch_type->data.enumeration.non_exhaustive) {
26514 ir_add_error(ira, &instruction->base,27369 ir_add_error(ira, &instruction->base.base,
26515 buf_sprintf("switch on non-exhaustive enum must include `else` or `_` prong"));27370 buf_sprintf("switch on non-exhaustive enum must include `else` or `_` prong"));
26516 }27371 }
26517 for (uint32_t i = 0; i < switch_type->data.enumeration.src_field_count; i += 1) {27372 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,...@@ -26519,69 +27374,69 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2651927374
26520 auto entry = field_prev_uses.maybe_get(enum_field->value);27375 auto entry = field_prev_uses.maybe_get(enum_field->value);
26521 if (!entry) {27376 if (!entry) {
26522 ir_add_error(ira, &instruction->base,27377 ir_add_error(ira, &instruction->base.base,
26523 buf_sprintf("enumeration value '%s.%s' not handled in switch", buf_ptr(&switch_type->name),27378 buf_sprintf("enumeration value '%s.%s' not handled in switch", buf_ptr(&switch_type->name),
26524 buf_ptr(enum_field->name)));27379 buf_ptr(enum_field->name)));
26525 }27380 }
26526 }27381 }
26527 }27382 }
26528 } else if (switch_type->id == ZigTypeIdErrorSet) {27383 } else if (switch_type->id == ZigTypeIdErrorSet) {
26529 if (!resolve_inferred_error_set(ira->codegen, switch_type, target_value->source_node)) {27384 if (!resolve_inferred_error_set(ira->codegen, switch_type, target_value->base.source_node)) {
26530 return ira->codegen->invalid_instruction;27385 return ira->codegen->invalid_inst_gen;
26531 }27386 }
2653227387
26533 size_t field_prev_uses_count = ira->codegen->errors_by_index.length;27388 size_t field_prev_uses_count = ira->codegen->errors_by_index.length;
26534 AstNode **field_prev_uses = allocate<AstNode *>(field_prev_uses_count, "AstNode *");27389 AstNode **field_prev_uses = allocate<AstNode *>(field_prev_uses_count, "AstNode *");
2653527390
26536 for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {27391 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;
26540 if (type_is_invalid(start_value_uncasted->value->type))27395 if (type_is_invalid(start_value_uncasted->value->type))
26541 return ira->codegen->invalid_instruction;27396 return ira->codegen->invalid_inst_gen;
26542 IrInstruction *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type);27397 IrInstGen *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type);
26543 if (type_is_invalid(start_value->value->type))27398 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;
26547 if (type_is_invalid(end_value_uncasted->value->type))27402 if (type_is_invalid(end_value_uncasted->value->type))
26548 return ira->codegen->invalid_instruction;27403 return ira->codegen->invalid_inst_gen;
26549 IrInstruction *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type);27404 IrInstGen *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type);
26550 if (type_is_invalid(end_value->value->type))27405 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);
26554 uint32_t start_index = start_value->value->data.x_err_set->value;27409 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);
26557 uint32_t end_index = end_value->value->data.x_err_set->value;27412 uint32_t end_index = end_value->value->data.x_err_set->value;
2655827413
26559 if (start_index != end_index) {27414 if (start_index != end_index) {
26560 ir_add_error(ira, end_value, buf_sprintf("ranges not allowed when switching on errors"));27415 ir_add_error(ira, &end_value->base, buf_sprintf("ranges not allowed when switching on errors"));
26561 return ira->codegen->invalid_instruction;27416 return ira->codegen->invalid_inst_gen;
26562 }27417 }
2656327418
26564 AstNode *prev_node = field_prev_uses[start_index];27419 AstNode *prev_node = field_prev_uses[start_index];
26565 if (prev_node != nullptr) {27420 if (prev_node != nullptr) {
26566 Buf *err_name = &ira->codegen->errors_by_index.at(start_index)->name;27421 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,
26568 buf_sprintf("duplicate switch value: '%s.%s'", buf_ptr(&switch_type->name), buf_ptr(err_name)));27423 buf_sprintf("duplicate switch value: '%s.%s'", buf_ptr(&switch_type->name), buf_ptr(err_name)));
26569 add_error_note(ira->codegen, msg, prev_node, buf_sprintf("other value is here"));27424 add_error_note(ira->codegen, msg, prev_node, buf_sprintf("other value is here"));
26570 }27425 }
26571 field_prev_uses[start_index] = start_value->source_node;27426 field_prev_uses[start_index] = start_value->base.source_node;
26572 }27427 }
26573 if (!instruction->have_else_prong) {27428 if (!instruction->have_else_prong) {
26574 if (type_is_global_error_set(switch_type)) {27429 if (type_is_global_error_set(switch_type)) {
26575 ir_add_error(ira, &instruction->base,27430 ir_add_error(ira, &instruction->base.base,
26576 buf_sprintf("else prong required when switching on type 'anyerror'"));27431 buf_sprintf("else prong required when switching on type 'anyerror'"));
26577 return ira->codegen->invalid_instruction;27432 return ira->codegen->invalid_inst_gen;
26578 } else {27433 } else {
26579 for (uint32_t i = 0; i < switch_type->data.error_set.err_count; i += 1) {27434 for (uint32_t i = 0; i < switch_type->data.error_set.err_count; i += 1) {
26580 ErrorTableEntry *err_entry = switch_type->data.error_set.errors[i];27435 ErrorTableEntry *err_entry = switch_type->data.error_set.errors[i];
2658127436
26582 AstNode *prev_node = field_prev_uses[err_entry->value];27437 AstNode *prev_node = field_prev_uses[err_entry->value];
26583 if (prev_node == nullptr) {27438 if (prev_node == nullptr) {
26584 ir_add_error(ira, &instruction->base,27439 ir_add_error(ira, &instruction->base.base,
26585 buf_sprintf("error.%s not handled in switch", buf_ptr(&err_entry->name)));27440 buf_sprintf("error.%s not handled in switch", buf_ptr(&err_entry->name)));
26586 }27441 }
26587 }27442 }
...@@ -26592,44 +27447,44 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -26592,44 +27447,44 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
26592 } else if (switch_type->id == ZigTypeIdInt) {27447 } else if (switch_type->id == ZigTypeIdInt) {
26593 RangeSet rs = {0};27448 RangeSet rs = {0};
26594 for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {27449 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;
26598 if (type_is_invalid(start_value->value->type))27453 if (type_is_invalid(start_value->value->type))
26599 return ira->codegen->invalid_instruction;27454 return ira->codegen->invalid_inst_gen;
26600 IrInstruction *casted_start_value = ir_implicit_cast(ira, start_value, switch_type);27455 IrInstGen *casted_start_value = ir_implicit_cast(ira, start_value, switch_type);
26601 if (type_is_invalid(casted_start_value->value->type))27456 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;
26605 if (type_is_invalid(end_value->value->type))27460 if (type_is_invalid(end_value->value->type))
26606 return ira->codegen->invalid_instruction;27461 return ira->codegen->invalid_inst_gen;
26607 IrInstruction *casted_end_value = ir_implicit_cast(ira, end_value, switch_type);27462 IrInstGen *casted_end_value = ir_implicit_cast(ira, end_value, switch_type);
26608 if (type_is_invalid(casted_end_value->value->type))27463 if (type_is_invalid(casted_end_value->value->type))
26609 return ira->codegen->invalid_instruction;27464 return ira->codegen->invalid_inst_gen;
2661027465
26611 ZigValue *start_val = ir_resolve_const(ira, casted_start_value, UndefBad);27466 ZigValue *start_val = ir_resolve_const(ira, casted_start_value, UndefBad);
26612 if (!start_val)27467 if (!start_val)
26613 return ira->codegen->invalid_instruction;27468 return ira->codegen->invalid_inst_gen;
2661427469
26615 ZigValue *end_val = ir_resolve_const(ira, casted_end_value, UndefBad);27470 ZigValue *end_val = ir_resolve_const(ira, casted_end_value, UndefBad);
26616 if (!end_val)27471 if (!end_val)
26617 return ira->codegen->invalid_instruction;27472 return ira->codegen->invalid_inst_gen;
2661827473
26619 assert(start_val->type->id == ZigTypeIdInt || start_val->type->id == ZigTypeIdComptimeInt);27474 assert(start_val->type->id == ZigTypeIdInt || start_val->type->id == ZigTypeIdComptimeInt);
26620 assert(end_val->type->id == ZigTypeIdInt || end_val->type->id == ZigTypeIdComptimeInt);27475 assert(end_val->type->id == ZigTypeIdInt || end_val->type->id == ZigTypeIdComptimeInt);
2662127476
26622 if (bigint_cmp(&start_val->data.x_bigint, &end_val->data.x_bigint) == CmpGT) {27477 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,
26624 buf_sprintf("range start value is greater than the end value"));27479 buf_sprintf("range start value is greater than the end value"));
26625 }27480 }
2662627481
26627 AstNode *prev_node = rangeset_add_range(&rs, &start_val->data.x_bigint, &end_val->data.x_bigint,27482 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);
26629 if (prev_node != nullptr) {27484 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"));
26631 add_error_note(ira->codegen, msg, prev_node, buf_sprintf("previous value is here"));27486 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;
26633 }27488 }
26634 }27489 }
26635 if (!instruction->have_else_prong) {27490 if (!instruction->have_else_prong) {
...@@ -26638,25 +27493,25 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -26638,25 +27493,25 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
26638 BigInt max_val;27493 BigInt max_val;
26639 eval_min_max_value_int(ira->codegen, switch_type, &max_val, true);27494 eval_min_max_value_int(ira->codegen, switch_type, &max_val, true);
26640 if (!rangeset_spans(&rs, &min_val, &max_val)) {27495 if (!rangeset_spans(&rs, &min_val, &max_val)) {
26641 ir_add_error(ira, &instruction->base, buf_sprintf("switch must handle all possibilities"));27496 ir_add_error(ira, &instruction->base.base, buf_sprintf("switch must handle all possibilities"));
26642 return ira->codegen->invalid_instruction;27497 return ira->codegen->invalid_inst_gen;
26643 }27498 }
26644 }27499 }
26645 } else if (switch_type->id == ZigTypeIdBool) {27500 } else if (switch_type->id == ZigTypeIdBool) {
26646 int seenTrue = 0;27501 int seenTrue = 0;
26647 int seenFalse = 0;27502 int seenFalse = 0;
26648 for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {27503 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);
26654 if (type_is_invalid(casted_value->value->type))27509 if (type_is_invalid(casted_value->value->type))
26655 return ira->codegen->invalid_instruction;27510 return ira->codegen->invalid_inst_gen;
2665627511
26657 ZigValue *const_expr_val = ir_resolve_const(ira, casted_value, UndefBad);27512 ZigValue *const_expr_val = ir_resolve_const(ira, casted_value, UndefBad);
26658 if (!const_expr_val)27513 if (!const_expr_val)
26659 return ira->codegen->invalid_instruction;27514 return ira->codegen->invalid_inst_gen;
2666027515
26661 assert(const_expr_val->type->id == ZigTypeIdBool);27516 assert(const_expr_val->type->id == ZigTypeIdBool);
2666227517
...@@ -26667,60 +27522,59 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -26667,60 +27522,59 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
26667 }27522 }
2666827523
26669 if ((seenTrue > 1) || (seenFalse > 1)) {27524 if ((seenTrue > 1) || (seenFalse > 1)) {
26670 ir_add_error(ira, value, buf_sprintf("duplicate switch value"));27525 ir_add_error(ira, &value->base, buf_sprintf("duplicate switch value"));
26671 return ira->codegen->invalid_instruction;27526 return ira->codegen->invalid_inst_gen;
26672 }27527 }
26673 }27528 }
26674 if (((seenTrue < 1) || (seenFalse < 1)) && !instruction->have_else_prong) {27529 if (((seenTrue < 1) || (seenFalse < 1)) && !instruction->have_else_prong) {
26675 ir_add_error(ira, &instruction->base, buf_sprintf("switch must handle all possibilities"));27530 ir_add_error(ira, &instruction->base.base, buf_sprintf("switch must handle all possibilities"));
26676 return ira->codegen->invalid_instruction;27531 return ira->codegen->invalid_inst_gen;
26677 }27532 }
26678 } else if (!instruction->have_else_prong) {27533 } else if (!instruction->have_else_prong) {
26679 ir_add_error(ira, &instruction->base,27534 ir_add_error(ira, &instruction->base.base,
26680 buf_sprintf("else prong required when switching on type '%s'", buf_ptr(&switch_type->name)));27535 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;
26682 }27537 }
26683 return ir_const_void(ira, &instruction->base);27538 return ir_const_void(ira, &instruction->base.base);
26684}27539}
2668527540
26686static IrInstruction *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira,27541static IrInstGen *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira,
26687 IrInstructionCheckStatementIsVoid *instruction)27542 IrInstSrcCheckStatementIsVoid *instruction)
26688{27543{
26689 IrInstruction *statement_value = instruction->statement_value->child;27544 IrInstGen *statement_value = instruction->statement_value->child;
26690 ZigType *statement_type = statement_value->value->type;27545 ZigType *statement_type = statement_value->value->type;
26691 if (type_is_invalid(statement_type))27546 if (type_is_invalid(statement_type))
26692 return ira->codegen->invalid_instruction;27547 return ira->codegen->invalid_inst_gen;
2669327548
26694 if (statement_type->id != ZigTypeIdVoid && statement_type->id != ZigTypeIdUnreachable) {27549 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"));
26696 }27551 }
2669727552
26698 return ir_const_void(ira, &instruction->base);27553 return ir_const_void(ira, &instruction->base.base);
26699}27554}
2670027555
26701static IrInstruction *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic *instruction) {27556static IrInstGen *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstSrcPanic *instruction) {
26702 IrInstruction *msg = instruction->msg->child;27557 IrInstGen *msg = instruction->msg->child;
26703 if (type_is_invalid(msg->value->type))27558 if (type_is_invalid(msg->value->type))
26704 return ir_unreach_error(ira);27559 return ir_unreach_error(ira);
2670527560
26706 if (ir_should_inline(ira->new_irb.exec, instruction->base.scope)) {27561 if (ir_should_inline(ira->old_irb.exec, instruction->base.base.scope)) {
26707 ir_add_error(ira, &instruction->base, buf_sprintf("encountered @panic at compile-time"));27562 ir_add_error(ira, &instruction->base.base, buf_sprintf("encountered @panic at compile-time"));
26708 return ir_unreach_error(ira);27563 return ir_unreach_error(ira);
26709 }27564 }
2671027565
26711 ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,27566 ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
26712 true, false, PtrLenUnknown, 0, 0, 0, false);27567 true, false, PtrLenUnknown, 0, 0, 0, false);
26713 ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type);27568 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);
26715 if (type_is_invalid(casted_msg->value->type))27570 if (type_is_invalid(casted_msg->value->type))
26716 return ir_unreach_error(ira);27571 return ir_unreach_error(ira);
2671727572
26718 IrInstruction *new_instruction = ir_build_panic(&ira->new_irb, instruction->base.scope,27573 IrInstGen *new_instruction = ir_build_panic_gen(ira, &instruction->base.base, casted_msg);
26719 instruction->base.source_node, casted_msg);
26720 return ir_finish_anal(ira, new_instruction);27574 return ir_finish_anal(ira, new_instruction);
26721}27575}
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) {
26724 Error err;27578 Error err;
2672527579
26726 ZigType *target_type = target->value->type;27580 ZigType *target_type = target->value->type;
...@@ -26732,7 +27586,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3...@@ -26732,7 +27586,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3
26732 if (target_type->id == ZigTypeIdPointer) {27586 if (target_type->id == ZigTypeIdPointer) {
26733 result_type = adjust_ptr_align(ira->codegen, target_type, align_bytes);27587 result_type = adjust_ptr_align(ira->codegen, target_type, align_bytes);
26734 if ((err = resolve_ptr_align(ira, target_type, &old_align_bytes)))27588 if ((err = resolve_ptr_align(ira, target_type, &old_align_bytes)))
26735 return ira->codegen->invalid_instruction;27589 return ira->codegen->invalid_inst_gen;
26736 } else if (target_type->id == ZigTypeIdFn) {27590 } else if (target_type->id == ZigTypeIdFn) {
26737 FnTypeId fn_type_id = target_type->data.fn.fn_type_id;27591 FnTypeId fn_type_id = target_type->data.fn.fn_type_id;
26738 old_align_bytes = fn_type_id.alignment;27592 old_align_bytes = fn_type_id.alignment;
...@@ -26743,7 +27597,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3...@@ -26743,7 +27597,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3
26743 {27597 {
26744 ZigType *ptr_type = target_type->data.maybe.child_type;27598 ZigType *ptr_type = target_type->data.maybe.child_type;
26745 if ((err = resolve_ptr_align(ira, ptr_type, &old_align_bytes)))27599 if ((err = resolve_ptr_align(ira, ptr_type, &old_align_bytes)))
26746 return ira->codegen->invalid_instruction;27600 return ira->codegen->invalid_inst_gen;
26747 ZigType *better_ptr_type = adjust_ptr_align(ira->codegen, ptr_type, align_bytes);27601 ZigType *better_ptr_type = adjust_ptr_align(ira->codegen, ptr_type, align_bytes);
2674827602
26749 result_type = get_optional_type(ira->codegen, better_ptr_type);27603 result_type = get_optional_type(ira->codegen, better_ptr_type);
...@@ -26758,47 +27612,44 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3...@@ -26758,47 +27612,44 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3
26758 } else if (is_slice(target_type)) {27612 } else if (is_slice(target_type)) {
26759 ZigType *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index]->type_entry;27613 ZigType *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index]->type_entry;
26760 if ((err = resolve_ptr_align(ira, slice_ptr_type, &old_align_bytes)))27614 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;
26762 ZigType *result_ptr_type = adjust_ptr_align(ira->codegen, slice_ptr_type, align_bytes);27616 ZigType *result_ptr_type = adjust_ptr_align(ira->codegen, slice_ptr_type, align_bytes);
26763 result_type = get_slice_type(ira->codegen, result_ptr_type);27617 result_type = get_slice_type(ira->codegen, result_ptr_type);
26764 } else {27618 } else {
26765 ir_add_error(ira, target,27619 ir_add_error(ira, &target->base,
26766 buf_sprintf("expected pointer or slice, found '%s'", buf_ptr(&target_type->name)));27620 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;
26768 }27622 }
2676927623
26770 if (instr_is_comptime(target)) {27624 if (instr_is_comptime(target)) {
26771 ZigValue *val = ir_resolve_const(ira, target, UndefBad);27625 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
26772 if (!val)27626 if (!val)
26773 return ira->codegen->invalid_instruction;27627 return ira->codegen->invalid_inst_gen;
2677427628
26775 if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&27629 if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&
26776 val->data.x_ptr.data.hard_coded_addr.addr % align_bytes != 0)27630 val->data.x_ptr.data.hard_coded_addr.addr % align_bytes != 0)
26777 {27631 {
26778 ir_add_error(ira, target,27632 ir_add_error(ira, &target->base,
26779 buf_sprintf("pointer address 0x%" ZIG_PRI_x64 " is not aligned to %" PRIu32 " bytes",27633 buf_sprintf("pointer address 0x%" ZIG_PRI_x64 " is not aligned to %" PRIu32 " bytes",
26780 val->data.x_ptr.data.hard_coded_addr.addr, align_bytes));27634 val->data.x_ptr.data.hard_coded_addr.addr, align_bytes));
26781 return ira->codegen->invalid_instruction;27635 return ira->codegen->invalid_inst_gen;
26782 }27636 }
2678327637
26784 IrInstruction *result = ir_const(ira, target, result_type);27638 IrInstGen *result = ir_const(ira, &target->base, result_type);
26785 copy_const_val(result->value, val);27639 copy_const_val(result->value, val);
26786 result->value->type = result_type;27640 result->value->type = result_type;
26787 return result;27641 return result;
26788 }27642 }
2678927643
26790 IrInstruction *result;
26791 if (safety_check_on && align_bytes > old_align_bytes && align_bytes != 1) {27644 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);
26793 } else {27646 } 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);
26795 }27648 }
26796 result->value->type = result_type;
26797 return result;
26798}27649}
2679927650
26800static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *ptr,27651static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *ptr,
26801 ZigType *dest_type, IrInstruction *dest_type_src, bool safety_check_on)27652 ZigType *dest_type, IrInst *dest_type_src, bool safety_check_on)
26802{27653{
26803 Error err;27654 Error err;
2680427655
...@@ -26814,44 +27665,44 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_...@@ -26814,44 +27665,44 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
2681427665
26815 ZigType *src_ptr_type = get_src_ptr_type(src_type);27666 ZigType *src_ptr_type = get_src_ptr_type(src_type);
26816 if (src_ptr_type == nullptr) {27667 if (src_ptr_type == nullptr) {
26817 ir_add_error(ira, ptr, buf_sprintf("expected pointer, found '%s'", buf_ptr(&src_type->name)));27668 ir_add_error(ira, &ptr->base, buf_sprintf("expected pointer, found '%s'", buf_ptr(&src_type->name)));
26818 return ira->codegen->invalid_instruction;27669 return ira->codegen->invalid_inst_gen;
26819 }27670 }
2682027671
26821 ZigType *dest_ptr_type = get_src_ptr_type(dest_type);27672 ZigType *dest_ptr_type = get_src_ptr_type(dest_type);
26822 if (dest_ptr_type == nullptr) {27673 if (dest_ptr_type == nullptr) {
26823 ir_add_error(ira, dest_type_src,27674 ir_add_error(ira, dest_type_src,
26824 buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name)));27675 buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name)));
26825 return ira->codegen->invalid_instruction;27676 return ira->codegen->invalid_inst_gen;
26826 }27677 }
2682727678
26828 if (get_ptr_const(src_type) && !get_ptr_const(dest_type)) {27679 if (get_ptr_const(src_type) && !get_ptr_const(dest_type)) {
26829 ir_add_error(ira, source_instr, buf_sprintf("cast discards const qualifier"));27680 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;
26831 }27682 }
26832 uint32_t src_align_bytes;27683 uint32_t src_align_bytes;
26833 if ((err = resolve_ptr_align(ira, src_type, &src_align_bytes)))27684 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
26836 uint32_t dest_align_bytes;27687 uint32_t dest_align_bytes;
26837 if ((err = resolve_ptr_align(ira, dest_type, &dest_align_bytes)))27688 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
26840 if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown)))27691 if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown)))
26841 return ira->codegen->invalid_instruction;27692 return ira->codegen->invalid_inst_gen;
2684227693
26843 if ((err = type_resolve(ira->codegen, src_type, ResolveStatusZeroBitsKnown)))27694 if ((err = type_resolve(ira->codegen, src_type, ResolveStatusZeroBitsKnown)))
26844 return ira->codegen->invalid_instruction;27695 return ira->codegen->invalid_inst_gen;
2684527696
26846 if (type_has_bits(dest_type) && !type_has_bits(src_type)) {27697 if (type_has_bits(dest_type) && !type_has_bits(src_type)) {
26847 ErrorMsg *msg = ir_add_error(ira, source_instr,27698 ErrorMsg *msg = ir_add_error(ira, source_instr,
26848 buf_sprintf("'%s' and '%s' do not have the same in-memory representation",27699 buf_sprintf("'%s' and '%s' do not have the same in-memory representation",
26849 buf_ptr(&src_type->name), buf_ptr(&dest_type->name)));27700 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,
26851 buf_sprintf("'%s' has no in-memory bits", buf_ptr(&src_type->name)));27702 buf_sprintf("'%s' has no in-memory bits", buf_ptr(&src_type->name)));
26852 add_error_note(ira->codegen, msg, dest_type_src->source_node,27703 add_error_note(ira->codegen, msg, dest_type_src->source_node,
26853 buf_sprintf("'%s' has in-memory bits", buf_ptr(&dest_type->name)));27704 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;
26855 }27706 }
2685627707
26857 if (instr_is_comptime(ptr)) {27708 if (instr_is_comptime(ptr)) {
...@@ -26859,7 +27710,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_...@@ -26859,7 +27710,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
26859 UndefAllowed is_undef_allowed = dest_allows_addr_zero ? UndefOk : UndefBad;27710 UndefAllowed is_undef_allowed = dest_allows_addr_zero ? UndefOk : UndefBad;
26860 ZigValue *val = ir_resolve_const(ira, ptr, is_undef_allowed);27711 ZigValue *val = ir_resolve_const(ira, ptr, is_undef_allowed);
26861 if (!val)27712 if (!val)
26862 return ira->codegen->invalid_instruction;27713 return ira->codegen->invalid_inst_gen;
2686327714
26864 if (value_is_comptime(val) && val->special != ConstValSpecialUndef) {27715 if (value_is_comptime(val) && val->special != ConstValSpecialUndef) {
26865 bool is_addr_zero = val->data.x_ptr.special == ConstPtrSpecialNull ||27716 bool is_addr_zero = val->data.x_ptr.special == ConstPtrSpecialNull ||
...@@ -26868,16 +27719,16 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_...@@ -26868,16 +27719,16 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
26868 if (is_addr_zero && !dest_allows_addr_zero) {27719 if (is_addr_zero && !dest_allows_addr_zero) {
26869 ir_add_error(ira, source_instr,27720 ir_add_error(ira, source_instr,
26870 buf_sprintf("null pointer casted to type '%s'", buf_ptr(&dest_type->name)));27721 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;
26872 }27723 }
26873 }27724 }
2687427725
26875 IrInstruction *result;27726 IrInstGen *result;
26876 if (ptr->value->data.x_ptr.mut == ConstPtrMutInfer) {27727 if (ptr->value->data.x_ptr.mut == ConstPtrMutInfer) {
26877 result = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on);27728 result = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on);
2687827729
26879 if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown)))27730 if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown)))
26880 return ira->codegen->invalid_instruction;27731 return ira->codegen->invalid_inst_gen;
26881 } else {27732 } else {
26882 result = ir_const(ira, source_instr, dest_type);27733 result = ir_const(ira, source_instr, dest_type);
26883 }27734 }
...@@ -26895,40 +27746,40 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_...@@ -26895,40 +27746,40 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
2689527746
26896 if (dest_align_bytes > src_align_bytes) {27747 if (dest_align_bytes > src_align_bytes) {
26897 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("cast increases pointer alignment"));27748 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,
26899 buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&src_type->name), src_align_bytes));27750 buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&src_type->name), src_align_bytes));
26900 add_error_note(ira->codegen, msg, dest_type_src->source_node,27751 add_error_note(ira->codegen, msg, dest_type_src->source_node,
26901 buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&dest_type->name), dest_align_bytes));27752 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;
26903 }27754 }
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
26907 // Keep the bigger alignment, it can only help-27758 // Keep the bigger alignment, it can only help-
26908 // unless the target is zero bits.27759 // unless the target is zero bits.
26909 IrInstruction *result;27760 IrInstGen *result;
26910 if (src_align_bytes > dest_align_bytes && type_has_bits(dest_type)) {27761 if (src_align_bytes > dest_align_bytes && type_has_bits(dest_type)) {
26911 result = ir_align_cast(ira, casted_ptr, src_align_bytes, false);27762 result = ir_align_cast(ira, casted_ptr, src_align_bytes, false);
26912 if (type_is_invalid(result->value->type))27763 if (type_is_invalid(result->value->type))
26913 return ira->codegen->invalid_instruction;27764 return ira->codegen->invalid_inst_gen;
26914 } else {27765 } else {
26915 result = casted_ptr;27766 result = casted_ptr;
26916 }27767 }
26917 return result;27768 return result;
26918}27769}
2691927770
26920static IrInstruction *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstructionPtrCastSrc *instruction) {27771static IrInstGen *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstSrcPtrCast *instruction) {
26921 IrInstruction *dest_type_value = instruction->dest_type->child;27772 IrInstGen *dest_type_value = instruction->dest_type->child;
26922 ZigType *dest_type = ir_resolve_type(ira, dest_type_value);27773 ZigType *dest_type = ir_resolve_type(ira, dest_type_value);
26923 if (type_is_invalid(dest_type))27774 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;
26927 ZigType *src_type = ptr->value->type;27778 ZigType *src_type = ptr->value->type;
26928 if (type_is_invalid(src_type))27779 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,
26932 instruction->safety_check_on);27783 instruction->safety_check_on);
26933}27784}
2693427785
...@@ -27259,7 +28110,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou...@@ -27259,7 +28110,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
27259 zig_unreachable();28110 zig_unreachable();
27260}28111}
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,
27263 ZigType *dest_type)28114 ZigType *dest_type)
27264{28115{
27265 Error err;28116 Error err;
...@@ -27275,14 +28126,14 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_...@@ -27275,14 +28126,14 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_
27275 buf_sprintf("cannot cast a value of type '%s'", buf_ptr(&dest_type->name)));28126 buf_sprintf("cannot cast a value of type '%s'", buf_ptr(&dest_type->name)));
27276 add_error_note(ira->codegen, msg, source_instr->source_node,28127 add_error_note(ira->codegen, msg, source_instr->source_node,
27277 buf_sprintf("use @intToEnum for type coercion"));28128 buf_sprintf("use @intToEnum for type coercion"));
27278 return ira->codegen->invalid_instruction;28129 return ira->codegen->invalid_inst_gen;
27279 }28130 }
2728028131
27281 if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusSizeKnown)))28132 if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusSizeKnown)))
27282 return ira->codegen->invalid_instruction;28133 return ira->codegen->invalid_inst_gen;
2728328134
27284 if ((err = type_resolve(ira->codegen, src_type, ResolveStatusSizeKnown)))28135 if ((err = type_resolve(ira->codegen, src_type, ResolveStatusSizeKnown)))
27285 return ira->codegen->invalid_instruction;28136 return ira->codegen->invalid_inst_gen;
2728628137
27287 uint64_t dest_size_bytes = type_size(ira->codegen, dest_type);28138 uint64_t dest_size_bytes = type_size(ira->codegen, dest_type);
27288 uint64_t src_size_bytes = type_size(ira->codegen, src_type);28139 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_...@@ -27291,7 +28142,7 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_
27291 buf_sprintf("destination type '%s' has size %" ZIG_PRI_u64 " but source type '%s' has size %" ZIG_PRI_u64,28142 buf_sprintf("destination type '%s' has size %" ZIG_PRI_u64 " but source type '%s' has size %" ZIG_PRI_u64,
27292 buf_ptr(&dest_type->name), dest_size_bytes,28143 buf_ptr(&dest_type->name), dest_size_bytes,
27293 buf_ptr(&src_type->name), src_size_bytes));28144 buf_ptr(&src_type->name), src_size_bytes));
27294 return ira->codegen->invalid_instruction;28145 return ira->codegen->invalid_inst_gen;
27295 }28146 }
2729628147
27297 uint64_t dest_size_bits = type_size_bits(ira->codegen, dest_type);28148 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_...@@ -27301,26 +28152,26 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_
27301 buf_sprintf("destination type '%s' has %" ZIG_PRI_u64 " bits but source type '%s' has %" ZIG_PRI_u64 " bits",28152 buf_sprintf("destination type '%s' has %" ZIG_PRI_u64 " bits but source type '%s' has %" ZIG_PRI_u64 " bits",
27302 buf_ptr(&dest_type->name), dest_size_bits,28153 buf_ptr(&dest_type->name), dest_size_bits,
27303 buf_ptr(&src_type->name), src_size_bits));28154 buf_ptr(&src_type->name), src_size_bits));
27304 return ira->codegen->invalid_instruction;28155 return ira->codegen->invalid_inst_gen;
27305 }28156 }
2730628157
27307 if (instr_is_comptime(value)) {28158 if (instr_is_comptime(value)) {
27308 ZigValue *val = ir_resolve_const(ira, value, UndefBad);28159 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
27309 if (!val)28160 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);
27313 uint8_t *buf = allocate_nonzero<uint8_t>(src_size_bytes);28164 uint8_t *buf = allocate_nonzero<uint8_t>(src_size_bytes);
27314 buf_write_value_bytes(ira->codegen, buf, val);28165 buf_write_value_bytes(ira->codegen, buf, val);
27315 if ((err = buf_read_value_bytes(ira, ira->codegen, source_instr->source_node, buf, result->value)))28166 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;
27317 return result;28168 return result;
27318 }28169 }
2731928170
27320 return ir_build_bit_cast_gen(ira, source_instr, value, dest_type);28171 return ir_build_bit_cast_gen(ira, source_instr, value, dest_type);
27321}28172}
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,
27324 ZigType *ptr_type)28175 ZigType *ptr_type)
27325{28176{
27326 Error err;28177 Error err;
...@@ -27328,136 +28179,128 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc...@@ -27328,136 +28179,128 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc
27328 ir_assert(get_src_ptr_type(ptr_type) != nullptr, source_instr);28179 ir_assert(get_src_ptr_type(ptr_type) != nullptr, source_instr);
27329 ir_assert(type_has_bits(ptr_type), source_instr);28180 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);
27332 if (type_is_invalid(casted_int->value->type))28183 if (type_is_invalid(casted_int->value->type))
27333 return ira->codegen->invalid_instruction;28184 return ira->codegen->invalid_inst_gen;
2733428185
27335 if (instr_is_comptime(casted_int)) {28186 if (instr_is_comptime(casted_int)) {
27336 ZigValue *val = ir_resolve_const(ira, casted_int, UndefBad);28187 ZigValue *val = ir_resolve_const(ira, casted_int, UndefBad);
27337 if (!val)28188 if (!val)
27338 return ira->codegen->invalid_instruction;28189 return ira->codegen->invalid_inst_gen;
2733928190
27340 uint64_t addr = bigint_as_u64(&val->data.x_bigint);28191 uint64_t addr = bigint_as_u64(&val->data.x_bigint);
27341 if (!ptr_allows_addr_zero(ptr_type) && addr == 0) {28192 if (!ptr_allows_addr_zero(ptr_type) && addr == 0) {
27342 ir_add_error(ira, source_instr,28193 ir_add_error(ira, source_instr,
27343 buf_sprintf("pointer type '%s' does not allow address zero", buf_ptr(&ptr_type->name)));28194 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;
27345 }28196 }
2734628197
27347 uint32_t align_bytes;28198 uint32_t align_bytes;
27348 if ((err = resolve_ptr_align(ira, ptr_type, &align_bytes)))28199 if ((err = resolve_ptr_align(ira, ptr_type, &align_bytes)))
27349 return ira->codegen->invalid_instruction;28200 return ira->codegen->invalid_inst_gen;
2735028201
27351 if (addr != 0 && addr % align_bytes != 0) {28202 if (addr != 0 && addr % align_bytes != 0) {
27352 ir_add_error(ira, source_instr,28203 ir_add_error(ira, source_instr,
27353 buf_sprintf("pointer type '%s' requires aligned address",28204 buf_sprintf("pointer type '%s' requires aligned address",
27354 buf_ptr(&ptr_type->name)));28205 buf_ptr(&ptr_type->name)));
27355 return ira->codegen->invalid_instruction;28206 return ira->codegen->invalid_inst_gen;
27356 }28207 }
2735728208
27358 IrInstruction *result = ir_const(ira, source_instr, ptr_type);28209 IrInstGen *result = ir_const(ira, source_instr, ptr_type);
27359 result->value->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;28210 result->value->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
27360 result->value->data.x_ptr.mut = ConstPtrMutRuntimeVar;28211 result->value->data.x_ptr.mut = ConstPtrMutRuntimeVar;
27361 result->value->data.x_ptr.data.hard_coded_addr.addr = addr;28212 result->value->data.x_ptr.data.hard_coded_addr.addr = addr;
27362 return result;28213 return result;
27363 }28214 }
2736428215
27365 IrInstruction *result = ir_build_int_to_ptr(&ira->new_irb, source_instr->scope,28216 return ir_build_int_to_ptr_gen(ira, source_instr->scope, source_instr->source_node, casted_int, ptr_type);
27366 source_instr->source_node, nullptr, casted_int);
27367 result->value->type = ptr_type;
27368 return result;
27369}28217}
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) {
27372 Error err;28220 Error err;
27373 IrInstruction *dest_type_value = instruction->dest_type->child;28221 IrInstGen *dest_type_value = instruction->dest_type->child;
27374 ZigType *dest_type = ir_resolve_type(ira, dest_type_value);28222 ZigType *dest_type = ir_resolve_type(ira, dest_type_value);
27375 if (type_is_invalid(dest_type))28223 if (type_is_invalid(dest_type))
27376 return ira->codegen->invalid_instruction;28224 return ira->codegen->invalid_inst_gen;
2737728225
27378 // We explicitly check for the size, so we can use get_src_ptr_type28226 // We explicitly check for the size, so we can use get_src_ptr_type
27379 if (get_src_ptr_type(dest_type) == nullptr) {28227 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)));28228 ir_add_error(ira, &dest_type_value->base, buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name)));
27381 return ira->codegen->invalid_instruction;28229 return ira->codegen->invalid_inst_gen;
27382 }28230 }
2738328231
27384 bool has_bits;28232 bool has_bits;
27385 if ((err = type_has_bits2(ira->codegen, dest_type, &has_bits)))28233 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
27388 if (!has_bits) {28236 if (!has_bits) {
27389 ir_add_error(ira, dest_type_value,28237 ir_add_error(ira, &dest_type_value->base,
27390 buf_sprintf("type '%s' has 0 bits and cannot store information", buf_ptr(&dest_type->name)));28238 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;
27392 }28240 }
2739328241
27394 IrInstruction *target = instruction->target->child;28242 IrInstGen *target = instruction->target->child;
27395 if (type_is_invalid(target->value->type))28243 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);
27399}28247}
2740028248
27401static IrInstruction *ir_analyze_instruction_decl_ref(IrAnalyze *ira,28249static IrInstGen *ir_analyze_instruction_decl_ref(IrAnalyze *ira, IrInstSrcDeclRef *instruction) {
27402 IrInstructionDeclRef *instruction)28250 IrInstGen *ref_instruction = ir_analyze_decl_ref(ira, &instruction->base.base, instruction->tld);
27403{
27404 IrInstruction *ref_instruction = ir_analyze_decl_ref(ira, &instruction->base, instruction->tld);
27405 if (type_is_invalid(ref_instruction->value->type)) {28251 if (type_is_invalid(ref_instruction->value->type)) {
27406 return ira->codegen->invalid_instruction;28252 return ira->codegen->invalid_inst_gen;
27407 }28253 }
2740828254
27409 if (instruction->lval == LValPtr) {28255 if (instruction->lval == LValPtr) {
27410 return ref_instruction;28256 return ref_instruction;
27411 } else {28257 } else {
27412 return ir_get_deref(ira, &instruction->base, ref_instruction, nullptr);28258 return ir_get_deref(ira, &instruction->base.base, ref_instruction, nullptr);
27413 }28259 }
27414}28260}
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) {
27417 Error err;28263 Error err;
27418 IrInstruction *target = instruction->target->child;28264 IrInstGen *target = instruction->target->child;
27419 if (type_is_invalid(target->value->type))28265 if (type_is_invalid(target->value->type))
27420 return ira->codegen->invalid_instruction;28266 return ira->codegen->invalid_inst_gen;
2742128267
27422 ZigType *usize = ira->codegen->builtin_types.entry_usize;28268 ZigType *usize = ira->codegen->builtin_types.entry_usize;
2742328269
27424 // We check size explicitly so we can use get_src_ptr_type here.28270 // We check size explicitly so we can use get_src_ptr_type here.
27425 if (get_src_ptr_type(target->value->type) == nullptr) {28271 if (get_src_ptr_type(target->value->type) == nullptr) {
27426 ir_add_error(ira, target,28272 ir_add_error(ira, &target->base,
27427 buf_sprintf("expected pointer, found '%s'", buf_ptr(&target->value->type->name)));28273 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;
27429 }28275 }
2743028276
27431 bool has_bits;28277 bool has_bits;
27432 if ((err = type_has_bits2(ira->codegen, target->value->type, &has_bits)))28278 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
27435 if (!has_bits) {28281 if (!has_bits) {
27436 ir_add_error(ira, target,28282 ir_add_error(ira, &target->base,
27437 buf_sprintf("pointer to size 0 type has no address"));28283 buf_sprintf("pointer to size 0 type has no address"));
27438 return ira->codegen->invalid_instruction;28284 return ira->codegen->invalid_inst_gen;
27439 }28285 }
2744028286
27441 if (instr_is_comptime(target)) {28287 if (instr_is_comptime(target)) {
27442 ZigValue *val = ir_resolve_const(ira, target, UndefBad);28288 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
27443 if (!val)28289 if (!val)
27444 return ira->codegen->invalid_instruction;28290 return ira->codegen->invalid_inst_gen;
27445 if (val->type->id == ZigTypeIdPointer && val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {28291 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);
27447 bigint_init_unsigned(&result->value->data.x_bigint, val->data.x_ptr.data.hard_coded_addr.addr);28293 bigint_init_unsigned(&result->value->data.x_bigint, val->data.x_ptr.data.hard_coded_addr.addr);
27448 result->value->type = usize;28294 result->value->type = usize;
27449 return result;28295 return result;
27450 }28296 }
27451 }28297 }
2745228298
27453 IrInstruction *result = ir_build_ptr_to_int(&ira->new_irb, instruction->base.scope,28299 return ir_build_ptr_to_int_gen(ira, &instruction->base.base, target);
27454 instruction->base.source_node, target);
27455 result->value->type = usize;
27456 return result;
27457}28300}
2745828301
27459static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstructionPtrType *instruction) {28302static IrInstGen *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstSrcPtrType *instruction) {
27460 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type);28303 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);
27461 result->value->special = ConstValSpecialLazy;28304 result->value->special = ConstValSpecialLazy;
2746228305
27463 LazyValuePtrType *lazy_ptr_type = allocate<LazyValuePtrType>(1, "LazyValuePtrType");28306 LazyValuePtrType *lazy_ptr_type = allocate<LazyValuePtrType>(1, "LazyValuePtrType");
...@@ -27468,17 +28311,17 @@ static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruct...@@ -27468,17 +28311,17 @@ static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruct
27468 if (instruction->sentinel != nullptr) {28311 if (instruction->sentinel != nullptr) {
27469 lazy_ptr_type->sentinel = instruction->sentinel->child;28312 lazy_ptr_type->sentinel = instruction->sentinel->child;
27470 if (ir_resolve_const(ira, lazy_ptr_type->sentinel, LazyOk) == nullptr)28313 if (ir_resolve_const(ira, lazy_ptr_type->sentinel, LazyOk) == nullptr)
27471 return ira->codegen->invalid_instruction;28314 return ira->codegen->invalid_inst_gen;
27472 }28315 }
2747328316
27474 lazy_ptr_type->elem_type = instruction->child_type->child;28317 lazy_ptr_type->elem_type = instruction->child_type->child;
27475 if (ir_resolve_type_lazy(ira, lazy_ptr_type->elem_type) == nullptr)28318 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
27478 if (instruction->align_value != nullptr) {28321 if (instruction->align_value != nullptr) {
27479 lazy_ptr_type->align_inst = instruction->align_value->child;28322 lazy_ptr_type->align_inst = instruction->align_value->child;
27480 if (ir_resolve_const(ira, lazy_ptr_type->align_inst, LazyOk) == nullptr)28323 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;
27482 }28325 }
2748328326
27484 lazy_ptr_type->ptr_len = instruction->ptr_len;28327 lazy_ptr_type->ptr_len = instruction->ptr_len;
...@@ -27491,10 +28334,10 @@ static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruct...@@ -27491,10 +28334,10 @@ static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruct
27491 return result;28334 return result;
27492}28335}
2749328336
27494static IrInstruction *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstructionAlignCast *instruction) {28337static IrInstGen *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstSrcAlignCast *instruction) {
27495 IrInstruction *target = instruction->target->child;28338 IrInstGen *target = instruction->target->child;
27496 if (type_is_invalid(target->value->type))28339 if (type_is_invalid(target->value->type))
27497 return ira->codegen->invalid_instruction;28340 return ira->codegen->invalid_inst_gen;
2749828341
27499 ZigType *elem_type = nullptr;28342 ZigType *elem_type = nullptr;
27500 if (is_slice(target->value->type)) {28343 if (is_slice(target->value->type)) {
...@@ -27505,192 +28348,192 @@ static IrInstruction *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstru...@@ -27505,192 +28348,192 @@ static IrInstruction *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstru
27505 }28348 }
2750628349
27507 uint32_t align_bytes;28350 uint32_t align_bytes;
27508 IrInstruction *align_bytes_inst = instruction->align_bytes->child;28351 IrInstGen *align_bytes_inst = instruction->align_bytes->child;
27509 if (!ir_resolve_align(ira, align_bytes_inst, elem_type, &align_bytes))28352 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);
27513 if (type_is_invalid(result->value->type))28356 if (type_is_invalid(result->value->type))
27514 return ira->codegen->invalid_instruction;28357 return ira->codegen->invalid_inst_gen;
2751528358
27516 return result;28359 return result;
27517}28360}
2751828361
27519static IrInstruction *ir_analyze_instruction_opaque_type(IrAnalyze *ira, IrInstructionOpaqueType *instruction) {28362static IrInstGen *ir_analyze_instruction_opaque_type(IrAnalyze *ira, IrInstSrcOpaqueType *instruction) {
27520 Buf *bare_name = buf_alloc();28363 Buf *bare_name = buf_alloc();
27521 Buf *full_name = get_anon_type_name(ira->codegen, ira->new_irb.exec, "opaque",28364 Buf *full_name = get_anon_type_name(ira->codegen, ira->old_irb.exec, "opaque",
27522 instruction->base.scope, instruction->base.source_node, bare_name);28365 instruction->base.base.scope, instruction->base.base.source_node, bare_name);
27523 ZigType *result_type = get_opaque_type(ira->codegen, instruction->base.scope, instruction->base.source_node,28366 ZigType *result_type = get_opaque_type(ira->codegen, instruction->base.base.scope,
27524 buf_ptr(full_name), bare_name);28367 instruction->base.base.source_node, buf_ptr(full_name), bare_name);
27525 return ir_const_type(ira, &instruction->base, result_type);28368 return ir_const_type(ira, &instruction->base.base, result_type);
27526}28369}
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) {
27529 uint32_t align_bytes;28372 uint32_t align_bytes;
27530 IrInstruction *align_bytes_inst = instruction->align_bytes->child;28373 IrInstGen *align_bytes_inst = instruction->align_bytes->child;
27531 if (!ir_resolve_align(ira, align_bytes_inst, nullptr, &align_bytes))28374 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
27534 if (align_bytes > 256) {28377 if (align_bytes > 256) {
27535 ir_add_error(ira, &instruction->base, buf_sprintf("attempt to @setAlignStack(%" PRIu32 "); maximum is 256", align_bytes));28378 ir_add_error(ira, &instruction->base.base, buf_sprintf("attempt to @setAlignStack(%" PRIu32 "); maximum is 256", align_bytes));
27536 return ira->codegen->invalid_instruction;28379 return ira->codegen->invalid_inst_gen;
27537 }28380 }
2753828381
27539 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);28382 ZigFn *fn_entry = ira->new_irb.exec->fn_entry;
27540 if (fn_entry == nullptr) {28383 if (fn_entry == nullptr) {
27541 ir_add_error(ira, &instruction->base, buf_sprintf("@setAlignStack outside function"));28384 ir_add_error(ira, &instruction->base.base, buf_sprintf("@setAlignStack outside function"));
27542 return ira->codegen->invalid_instruction;28385 return ira->codegen->invalid_inst_gen;
27543 }28386 }
27544 if (fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionNaked) {28387 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"));28388 ir_add_error(ira, &instruction->base.base, buf_sprintf("@setAlignStack in naked function"));
27546 return ira->codegen->invalid_instruction;28389 return ira->codegen->invalid_inst_gen;
27547 }28390 }
2754828391
27549 if (fn_entry->fn_inline == FnInlineAlways) {28392 if (fn_entry->fn_inline == FnInlineAlways) {
27550 ir_add_error(ira, &instruction->base, buf_sprintf("@setAlignStack in inline function"));28393 ir_add_error(ira, &instruction->base.base, buf_sprintf("@setAlignStack in inline function"));
27551 return ira->codegen->invalid_instruction;28394 return ira->codegen->invalid_inst_gen;
27552 }28395 }
2755328396
27554 if (fn_entry->set_alignstack_node != nullptr) {28397 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,
27556 buf_sprintf("alignstack set twice"));28399 buf_sprintf("alignstack set twice"));
27557 add_error_note(ira->codegen, msg, fn_entry->set_alignstack_node, buf_sprintf("first set here"));28400 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;
27559 }28402 }
2756028403
27561 fn_entry->set_alignstack_node = instruction->base.source_node;28404 fn_entry->set_alignstack_node = instruction->base.base.source_node;
27562 fn_entry->alignstack_value = align_bytes;28405 fn_entry->alignstack_value = align_bytes;
2756328406
27564 return ir_const_void(ira, &instruction->base);28407 return ir_const_void(ira, &instruction->base.base);
27565}28408}
2756628409
27567static IrInstruction *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstructionArgType *instruction) {28410static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgType *instruction) {
27568 IrInstruction *fn_type_inst = instruction->fn_type->child;28411 IrInstGen *fn_type_inst = instruction->fn_type->child;
27569 ZigType *fn_type = ir_resolve_type(ira, fn_type_inst);28412 ZigType *fn_type = ir_resolve_type(ira, fn_type_inst);
27570 if (type_is_invalid(fn_type))28413 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;
27574 uint64_t arg_index;28417 uint64_t arg_index;
27575 if (!ir_resolve_usize(ira, arg_index_inst, &arg_index))28418 if (!ir_resolve_usize(ira, arg_index_inst, &arg_index))
27576 return ira->codegen->invalid_instruction;28419 return ira->codegen->invalid_inst_gen;
2757728420
27578 if (fn_type->id == ZigTypeIdBoundFn) {28421 if (fn_type->id == ZigTypeIdBoundFn) {
27579 fn_type = fn_type->data.bound_fn.fn_type;28422 fn_type = fn_type->data.bound_fn.fn_type;
27580 arg_index += 1;28423 arg_index += 1;
27581 }28424 }
27582 if (fn_type->id != ZigTypeIdFn) {28425 if (fn_type->id != ZigTypeIdFn) {
27583 ir_add_error(ira, fn_type_inst, buf_sprintf("expected function, found '%s'", buf_ptr(&fn_type->name)));28426 ir_add_error(ira, &fn_type_inst->base, buf_sprintf("expected function, found '%s'", buf_ptr(&fn_type->name)));
27584 return ira->codegen->invalid_instruction;28427 return ira->codegen->invalid_inst_gen;
27585 }28428 }
2758628429
27587 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;28430 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;
27588 if (arg_index >= fn_type_id->param_count) {28431 if (arg_index >= fn_type_id->param_count) {
27589 if (instruction->allow_var) {28432 if (instruction->allow_var) {
27590 // TODO remove this with var args28433 // 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);
27592 }28435 }
27593 ir_add_error(ira, arg_index_inst,28436 ir_add_error(ira, &arg_index_inst->base,
27594 buf_sprintf("arg index %" ZIG_PRI_u64 " out of bounds; '%s' has %" ZIG_PRI_usize " arguments",28437 buf_sprintf("arg index %" ZIG_PRI_u64 " out of bounds; '%s' has %" ZIG_PRI_usize " arguments",
27595 arg_index, buf_ptr(&fn_type->name), fn_type_id->param_count));28438 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;
27597 }28440 }
2759828441
27599 ZigType *result_type = fn_type_id->param_info[arg_index].type;28442 ZigType *result_type = fn_type_id->param_info[arg_index].type;
27600 if (result_type == nullptr) {28443 if (result_type == nullptr) {
27601 // Args are only unresolved if our function is generic.28444 // 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
27604 if (instruction->allow_var) {28447 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);
27606 } else {28449 } else {
27607 ir_add_error(ira, arg_index_inst,28450 ir_add_error(ira, &arg_index_inst->base,
27608 buf_sprintf("@ArgType could not resolve the type of arg %" ZIG_PRI_u64 " because '%s' is generic",28451 buf_sprintf("@ArgType could not resolve the type of arg %" ZIG_PRI_u64 " because '%s' is generic",
27609 arg_index, buf_ptr(&fn_type->name)));28452 arg_index, buf_ptr(&fn_type->name)));
27610 return ira->codegen->invalid_instruction;28453 return ira->codegen->invalid_inst_gen;
27611 }28454 }
27612 }28455 }
27613 return ir_const_type(ira, &instruction->base, result_type);28456 return ir_const_type(ira, &instruction->base.base, result_type);
27614}28457}
2761528458
27616static IrInstruction *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstructionTagType *instruction) {28459static IrInstGen *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstSrcTagType *instruction) {
27617 Error err;28460 Error err;
27618 IrInstruction *target_inst = instruction->target->child;28461 IrInstGen *target_inst = instruction->target->child;
27619 ZigType *enum_type = ir_resolve_type(ira, target_inst);28462 ZigType *enum_type = ir_resolve_type(ira, target_inst);
27620 if (type_is_invalid(enum_type))28463 if (type_is_invalid(enum_type))
27621 return ira->codegen->invalid_instruction;28464 return ira->codegen->invalid_inst_gen;
2762228465
27623 if (enum_type->id == ZigTypeIdEnum) {28466 if (enum_type->id == ZigTypeIdEnum) {
27624 if ((err = type_resolve(ira->codegen, enum_type, ResolveStatusSizeKnown)))28467 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);
27628 } else if (enum_type->id == ZigTypeIdUnion) {28471 } 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);
27630 if (type_is_invalid(tag_type))28473 if (type_is_invalid(tag_type))
27631 return ira->codegen->invalid_instruction;28474 return ira->codegen->invalid_inst_gen;
27632 return ir_const_type(ira, &instruction->base, tag_type);28475 return ir_const_type(ira, &instruction->base.base, tag_type);
27633 } else {28476 } 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'",
27635 buf_ptr(&enum_type->name)));28478 buf_ptr(&enum_type->name)));
27636 return ira->codegen->invalid_instruction;28479 return ira->codegen->invalid_inst_gen;
27637 }28480 }
27638}28481}
2763928482
27640static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op) {28483static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op) {
27641 ZigType *operand_type = ir_resolve_type(ira, op);28484 ZigType *operand_type = ir_resolve_type(ira, op);
27642 if (type_is_invalid(operand_type))28485 if (type_is_invalid(operand_type))
27643 return ira->codegen->builtin_types.entry_invalid;28486 return ira->codegen->builtin_types.entry_invalid;
2764428487
27645 if (operand_type->id == ZigTypeIdInt) {28488 if (operand_type->id == ZigTypeIdInt) {
27646 if (operand_type->data.integral.bit_count < 8) {28489 if (operand_type->data.integral.bit_count < 8) {
27647 ir_add_error(ira, op,28490 ir_add_error(ira, &op->base,
27648 buf_sprintf("expected integer type 8 bits or larger, found %" PRIu32 "-bit integer type",28491 buf_sprintf("expected integer type 8 bits or larger, found %" PRIu32 "-bit integer type",
27649 operand_type->data.integral.bit_count));28492 operand_type->data.integral.bit_count));
27650 return ira->codegen->builtin_types.entry_invalid;28493 return ira->codegen->builtin_types.entry_invalid;
27651 }28494 }
27652 uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch);28495 uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch);
27653 if (operand_type->data.integral.bit_count > max_atomic_bits) {28496 if (operand_type->data.integral.bit_count > max_atomic_bits) {
27654 ir_add_error(ira, op,28497 ir_add_error(ira, &op->base,
27655 buf_sprintf("expected %" PRIu32 "-bit integer type or smaller, found %" PRIu32 "-bit integer type",28498 buf_sprintf("expected %" PRIu32 "-bit integer type or smaller, found %" PRIu32 "-bit integer type",
27656 max_atomic_bits, operand_type->data.integral.bit_count));28499 max_atomic_bits, operand_type->data.integral.bit_count));
27657 return ira->codegen->builtin_types.entry_invalid;28500 return ira->codegen->builtin_types.entry_invalid;
27658 }28501 }
27659 if (!is_power_of_2(operand_type->data.integral.bit_count)) {28502 if (!is_power_of_2(operand_type->data.integral.bit_count)) {
27660 ir_add_error(ira, op,28503 ir_add_error(ira, &op->base,
27661 buf_sprintf("%" PRIu32 "-bit integer type is not a power of 2", operand_type->data.integral.bit_count));28504 buf_sprintf("%" PRIu32 "-bit integer type is not a power of 2", operand_type->data.integral.bit_count));
27662 return ira->codegen->builtin_types.entry_invalid;28505 return ira->codegen->builtin_types.entry_invalid;
27663 }28506 }
27664 } else if (operand_type->id == ZigTypeIdEnum) {28507 } else if (operand_type->id == ZigTypeIdEnum) {
27665 ZigType *int_type = operand_type->data.enumeration.tag_int_type;28508 ZigType *int_type = operand_type->data.enumeration.tag_int_type;
27666 if (int_type->data.integral.bit_count < 8) {28509 if (int_type->data.integral.bit_count < 8) {
27667 ir_add_error(ira, op,28510 ir_add_error(ira, &op->base,
27668 buf_sprintf("expected enum tag type 8 bits or larger, found %" PRIu32 "-bit tag type",28511 buf_sprintf("expected enum tag type 8 bits or larger, found %" PRIu32 "-bit tag type",
27669 int_type->data.integral.bit_count));28512 int_type->data.integral.bit_count));
27670 return ira->codegen->builtin_types.entry_invalid;28513 return ira->codegen->builtin_types.entry_invalid;
27671 }28514 }
27672 uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch);28515 uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch);
27673 if (int_type->data.integral.bit_count > max_atomic_bits) {28516 if (int_type->data.integral.bit_count > max_atomic_bits) {
27674 ir_add_error(ira, op,28517 ir_add_error(ira, &op->base,
27675 buf_sprintf("expected %" PRIu32 "-bit enum tag type or smaller, found %" PRIu32 "-bit tag type",28518 buf_sprintf("expected %" PRIu32 "-bit enum tag type or smaller, found %" PRIu32 "-bit tag type",
27676 max_atomic_bits, int_type->data.integral.bit_count));28519 max_atomic_bits, int_type->data.integral.bit_count));
27677 return ira->codegen->builtin_types.entry_invalid;28520 return ira->codegen->builtin_types.entry_invalid;
27678 }28521 }
27679 if (!is_power_of_2(int_type->data.integral.bit_count)) {28522 if (!is_power_of_2(int_type->data.integral.bit_count)) {
27680 ir_add_error(ira, op,28523 ir_add_error(ira, &op->base,
27681 buf_sprintf("%" PRIu32 "-bit enum tag type is not a power of 2", int_type->data.integral.bit_count));28524 buf_sprintf("%" PRIu32 "-bit enum tag type is not a power of 2", int_type->data.integral.bit_count));
27682 return ira->codegen->builtin_types.entry_invalid;28525 return ira->codegen->builtin_types.entry_invalid;
27683 }28526 }
27684 } else if (operand_type->id == ZigTypeIdFloat) {28527 } else if (operand_type->id == ZigTypeIdFloat) {
27685 uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch);28528 uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch);
27686 if (operand_type->data.floating.bit_count > max_atomic_bits) {28529 if (operand_type->data.floating.bit_count > max_atomic_bits) {
27687 ir_add_error(ira, op,28530 ir_add_error(ira, &op->base,
27688 buf_sprintf("expected %" PRIu32 "-bit float or smaller, found %" PRIu32 "-bit float",28531 buf_sprintf("expected %" PRIu32 "-bit float or smaller, found %" PRIu32 "-bit float",
27689 max_atomic_bits, (uint32_t) operand_type->data.floating.bit_count));28532 max_atomic_bits, (uint32_t) operand_type->data.floating.bit_count));
27690 return ira->codegen->builtin_types.entry_invalid;28533 return ira->codegen->builtin_types.entry_invalid;
27691 }28534 }
27692 } else if (get_codegen_ptr_type(operand_type) == nullptr) {28535 } else if (get_codegen_ptr_type(operand_type) == nullptr) {
27693 ir_add_error(ira, op,28536 ir_add_error(ira, &op->base,
27694 buf_sprintf("expected integer, float, enum or pointer type, found '%s'", buf_ptr(&operand_type->name)));28537 buf_sprintf("expected integer, float, enum or pointer type, found '%s'", buf_ptr(&operand_type->name)));
27695 return ira->codegen->builtin_types.entry_invalid;28538 return ira->codegen->builtin_types.entry_invalid;
27696 }28539 }
...@@ -27698,172 +28541,146 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op...@@ -27698,172 +28541,146 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op
27698 return operand_type;28541 return operand_type;
27699}28542}
2770028543
27701static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstructionAtomicRmw *instruction) {28544static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAtomicRmw *instruction) {
27702 ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child);28545 ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child);
27703 if (type_is_invalid(operand_type))28546 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;
27707 if (type_is_invalid(ptr_inst->value->type))28550 if (type_is_invalid(ptr_inst->value->type))
27708 return ira->codegen->invalid_instruction;28551 return ira->codegen->invalid_inst_gen;
2770928552
27710 // TODO let this be volatile28553 // TODO let this be volatile
27711 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);28554 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);
27713 if (type_is_invalid(casted_ptr->value->type))28556 if (type_is_invalid(casted_ptr->value->type))
27714 return ira->codegen->invalid_instruction;28557 return ira->codegen->invalid_inst_gen;
2771528558
27716 AtomicRmwOp op;28559 AtomicRmwOp op;
27717 if (instruction->op == nullptr) {28560 if (!ir_resolve_atomic_rmw_op(ira, instruction->op->child, &op)) {
27718 op = instruction->resolved_op;28561 return ira->codegen->invalid_inst_gen;
27719 } else {
27720 if (!ir_resolve_atomic_rmw_op(ira, instruction->op->child, &op)) {
27721 return ira->codegen->invalid_instruction;
27722 }
27723 }28562 }
2772428563
27725 if (operand_type->id == ZigTypeIdEnum && op != AtomicRmwOp_xchg) {28564 if (operand_type->id == ZigTypeIdEnum && op != AtomicRmwOp_xchg) {
27726 ir_add_error(ira, instruction->op,28565 ir_add_error(ira, &instruction->op->base,
27727 buf_sprintf("@atomicRmw on enum only works with .Xchg"));28566 buf_sprintf("@atomicRmw on enum only works with .Xchg"));
27728 return ira->codegen->invalid_instruction;28567 return ira->codegen->invalid_inst_gen;
27729 } else if (operand_type->id == ZigTypeIdFloat && op > AtomicRmwOp_sub) {28568 } else if (operand_type->id == ZigTypeIdFloat && op > AtomicRmwOp_sub) {
27730 ir_add_error(ira, instruction->op,28569 ir_add_error(ira, &instruction->op->base,
27731 buf_sprintf("@atomicRmw with float only works with .Xchg, .Add and .Sub"));28570 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;
27733 }28572 }
2773428573
27735 IrInstruction *operand = instruction->operand->child;28574 IrInstGen *operand = instruction->operand->child;
27736 if (type_is_invalid(operand->value->type))28575 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);
27740 if (type_is_invalid(casted_operand->value->type))28579 if (type_is_invalid(casted_operand->value->type))
27741 return ira->codegen->invalid_instruction;28580 return ira->codegen->invalid_inst_gen;
2774228581
27743 AtomicOrder ordering;28582 AtomicOrder ordering;
27744 if (instruction->ordering == nullptr) {28583 if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering))
27745 ordering = instruction->resolved_ordering;28584 return ira->codegen->invalid_inst_gen;
27746 } else {28585 if (ordering == AtomicOrderUnordered) {
27747 if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering))28586 ir_add_error(ira, &instruction->ordering->base,
27748 return ira->codegen->invalid_instruction;28587 buf_sprintf("@atomicRmw atomic ordering must not be Unordered"));
27749 if (ordering == AtomicOrderUnordered) {28588 return ira->codegen->invalid_inst_gen;
27750 ir_add_error(ira, instruction->ordering,
27751 buf_sprintf("@atomicRmw atomic ordering must not be Unordered"));
27752 return ira->codegen->invalid_instruction;
27753 }
27754 }28589 }
2775528590
27756 if (instr_is_comptime(casted_operand) && instr_is_comptime(casted_ptr) && casted_ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar)28591 if (instr_is_comptime(casted_operand) && instr_is_comptime(casted_ptr) && casted_ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar)
27757 {28592 {
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;
27759 }28596 }
2776028597
27761 IrInstruction *result = ir_build_atomic_rmw(&ira->new_irb, instruction->base.scope,28598 return ir_build_atomic_rmw_gen(ira, &instruction->base.base, casted_ptr, casted_operand, op,
27762 instruction->base.source_node, nullptr, casted_ptr, nullptr, casted_operand, nullptr,28599 ordering, operand_type);
27763 op, ordering);
27764 result->value->type = operand_type;
27765 return result;
27766}28600}
2776728601
27768static IrInstruction *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstructionAtomicLoad *instruction) {28602static IrInstGen *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstSrcAtomicLoad *instruction) {
27769 ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child);28603 ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child);
27770 if (type_is_invalid(operand_type))28604 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;
27774 if (type_is_invalid(ptr_inst->value->type))28608 if (type_is_invalid(ptr_inst->value->type))
27775 return ira->codegen->invalid_instruction;28609 return ira->codegen->invalid_inst_gen;
2777628610
27777 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, true);28611 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);
27779 if (type_is_invalid(casted_ptr->value->type))28613 if (type_is_invalid(casted_ptr->value->type))
27780 return ira->codegen->invalid_instruction;28614 return ira->codegen->invalid_inst_gen;
2778128615
27782 AtomicOrder ordering;28616 AtomicOrder ordering;
27783 if (instruction->ordering == nullptr) {28617 if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering))
27784 ordering = instruction->resolved_ordering;28618 return ira->codegen->invalid_inst_gen;
27785 } else {
27786 if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering))
27787 return ira->codegen->invalid_instruction;
27788 }
2778928619
27790 if (ordering == AtomicOrderRelease || ordering == AtomicOrderAcqRel) {28620 if (ordering == AtomicOrderRelease || ordering == AtomicOrderAcqRel) {
27791 ir_assert(instruction->ordering != nullptr, &instruction->base);28621 ir_assert(instruction->ordering != nullptr, &instruction->base.base);
27792 ir_add_error(ira, instruction->ordering,28622 ir_add_error(ira, &instruction->ordering->base,
27793 buf_sprintf("@atomicLoad atomic ordering must not be Release or AcqRel"));28623 buf_sprintf("@atomicLoad atomic ordering must not be Release or AcqRel"));
27794 return ira->codegen->invalid_instruction;28624 return ira->codegen->invalid_inst_gen;
27795 }28625 }
2779628626
27797 if (instr_is_comptime(casted_ptr)) {28627 if (instr_is_comptime(casted_ptr)) {
27798 IrInstruction *result = ir_get_deref(ira, &instruction->base, casted_ptr, nullptr);28628 IrInstGen *result = ir_get_deref(ira, &instruction->base.base, casted_ptr, nullptr);
27799 ir_assert(result->value->type != nullptr, &instruction->base);28629 ir_assert(result->value->type != nullptr, &instruction->base.base);
27800 return result;28630 return result;
27801 }28631 }
2780228632
27803 IrInstruction *result = ir_build_atomic_load(&ira->new_irb, instruction->base.scope,28633 return ir_build_atomic_load_gen(ira, &instruction->base.base, casted_ptr, ordering, operand_type);
27804 instruction->base.source_node, nullptr, casted_ptr, nullptr, ordering);
27805 result->value->type = operand_type;
27806 return result;
27807}28634}
2780828635
27809static IrInstruction *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInstructionAtomicStore *instruction) {28636static IrInstGen *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInstSrcAtomicStore *instruction) {
27810 ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child);28637 ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child);
27811 if (type_is_invalid(operand_type))28638 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;
27815 if (type_is_invalid(ptr_inst->value->type))28642 if (type_is_invalid(ptr_inst->value->type))
27816 return ira->codegen->invalid_instruction;28643 return ira->codegen->invalid_inst_gen;
2781728644
27818 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);28645 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);
27820 if (type_is_invalid(casted_ptr->value->type))28647 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;
27824 if (type_is_invalid(value->value->type))28651 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);
27828 if (type_is_invalid(casted_value->value->type))28655 if (type_is_invalid(casted_value->value->type))
27829 return ira->codegen->invalid_instruction;28656 return ira->codegen->invalid_inst_gen;
2783028657
2783128658
27832 AtomicOrder ordering;28659 AtomicOrder ordering;
27833 if (instruction->ordering == nullptr) {28660 if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering))
27834 ordering = instruction->resolved_ordering;28661 return ira->codegen->invalid_inst_gen;
27835 } else {
27836 if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering))
27837 return ira->codegen->invalid_instruction;
27838 }
2783928662
27840 if (ordering == AtomicOrderAcquire || ordering == AtomicOrderAcqRel) {28663 if (ordering == AtomicOrderAcquire || ordering == AtomicOrderAcqRel) {
27841 ir_assert(instruction->ordering != nullptr, &instruction->base);28664 ir_assert(instruction->ordering != nullptr, &instruction->base.base);
27842 ir_add_error(ira, instruction->ordering,28665 ir_add_error(ira, &instruction->ordering->base,
27843 buf_sprintf("@atomicStore atomic ordering must not be Acquire or AcqRel"));28666 buf_sprintf("@atomicStore atomic ordering must not be Acquire or AcqRel"));
27844 return ira->codegen->invalid_instruction;28667 return ira->codegen->invalid_inst_gen;
27845 }28668 }
2784628669
27847 if (instr_is_comptime(casted_value) && instr_is_comptime(casted_ptr)) {28670 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);
27849 result->value->type = ira->codegen->builtin_types.entry_void;28672 result->value->type = ira->codegen->builtin_types.entry_void;
27850 return result;28673 return result;
27851 }28674 }
2785228675
27853 IrInstruction *result = ir_build_atomic_store(&ira->new_irb, instruction->base.scope,28676 return ir_build_atomic_store_gen(ira, &instruction->base.base, casted_ptr, casted_value, ordering);
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;
27857}28677}
2785828678
27859static IrInstruction *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstructionSaveErrRetAddr *instruction) {28679static IrInstGen *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstSrcSaveErrRetAddr *instruction) {
27860 IrInstruction *result = ir_build_save_err_ret_addr(&ira->new_irb, instruction->base.scope,28680 return ir_build_save_err_ret_addr_gen(ira, &instruction->base.base);
27861 instruction->base.source_node);
27862 result->value->type = ira->codegen->builtin_types.entry_void;
27863 return result;
27864}28681}
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,
27867 ZigValue *op, ZigValue *out_val)28684 ZigValue *op, ZigValue *out_val)
27868{28685{
27869 assert(ira && source_instr && float_type && out_val && op);28686 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...@@ -28076,30 +28893,30 @@ static ErrorMsg *ir_eval_float_op(IrAnalyze *ira, IrInstruction *source_instr, B
28076 return nullptr;28893 return nullptr;
28077}28894}
2807828895
28079static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstructionFloatOp *instruction) {28896static IrInstGen *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstSrcFloatOp *instruction) {
28080 IrInstruction *operand = instruction->operand->child;28897 IrInstGen *operand = instruction->operand->child;
28081 ZigType *operand_type = operand->value->type;28898 ZigType *operand_type = operand->value->type;
28082 if (type_is_invalid(operand_type))28899 if (type_is_invalid(operand_type))
28083 return ira->codegen->invalid_instruction;28900 return ira->codegen->invalid_inst_gen;
2808428901
28085 // This instruction accepts floats and vectors of floats.28902 // This instruction accepts floats and vectors of floats.
28086 ZigType *scalar_type = (operand_type->id == ZigTypeIdVector) ?28903 ZigType *scalar_type = (operand_type->id == ZigTypeIdVector) ?
28087 operand_type->data.vector.elem_type : operand_type;28904 operand_type->data.vector.elem_type : operand_type;
2808828905
28089 if (scalar_type->id != ZigTypeIdFloat && scalar_type->id != ZigTypeIdComptimeFloat) {28906 if (scalar_type->id != ZigTypeIdFloat && scalar_type->id != ZigTypeIdComptimeFloat) {
28090 ir_add_error(ira, operand,28907 ir_add_error(ira, &operand->base,
28091 buf_sprintf("expected float type, found '%s'", buf_ptr(&scalar_type->name)));28908 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;
28093 }28910 }
2809428911
28095 if (instr_is_comptime(operand)) {28912 if (instr_is_comptime(operand)) {
28096 ZigValue *operand_val = ir_resolve_const(ira, operand, UndefOk);28913 ZigValue *operand_val = ir_resolve_const(ira, operand, UndefOk);
28097 if (operand_val == nullptr)28914 if (operand_val == nullptr)
28098 return ira->codegen->invalid_instruction;28915 return ira->codegen->invalid_inst_gen;
28099 if (operand_val->special == ConstValSpecialUndef)28916 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);
28103 ZigValue *out_val = result->value;28920 ZigValue *out_val = result->value;
2810428921
28105 if (operand_type->id == ZigTypeIdVector) {28922 if (operand_type->id == ZigTypeIdVector) {
...@@ -28110,47 +28927,44 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct...@@ -28110,47 +28927,44 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct
28110 for (size_t i = 0; i < len; i += 1) {28927 for (size_t i = 0; i < len; i += 1) {
28111 ZigValue *elem_operand = &operand_val->data.x_array.data.s_none.elements[i];28928 ZigValue *elem_operand = &operand_val->data.x_array.data.s_none.elements[i];
28112 ZigValue *float_out_val = &out_val->data.x_array.data.s_none.elements[i];28929 ZigValue *float_out_val = &out_val->data.x_array.data.s_none.elements[i];
28113 ir_assert(elem_operand->type == scalar_type, &instruction->base);28930 ir_assert(elem_operand->type == scalar_type, &instruction->base.base);
28114 ir_assert(float_out_val->type == scalar_type, &instruction->base);28931 ir_assert(float_out_val->type == scalar_type, &instruction->base.base);
28115 ErrorMsg *msg = ir_eval_float_op(ira, &instruction->base, instruction->fn_id, scalar_type,28932 ErrorMsg *msg = ir_eval_float_op(ira, &instruction->base.base, instruction->fn_id, scalar_type,
28116 elem_operand, float_out_val);28933 elem_operand, float_out_val);
28117 if (msg != nullptr) {28934 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,
28119 buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i));28936 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;
28121 }28938 }
28122 float_out_val->type = scalar_type;28939 float_out_val->type = scalar_type;
28123 }28940 }
28124 out_val->type = operand_type;28941 out_val->type = operand_type;
28125 out_val->special = ConstValSpecialStatic;28942 out_val->special = ConstValSpecialStatic;
28126 } else {28943 } 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,
28128 operand_val, out_val) != nullptr)28945 operand_val, out_val) != nullptr)
28129 {28946 {
28130 return ira->codegen->invalid_instruction;28947 return ira->codegen->invalid_inst_gen;
28131 }28948 }
28132 }28949 }
28133 return result;28950 return result;
28134 }28951 }
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,28955 return ir_build_float_op_gen(ira, &instruction->base.base, operand, instruction->fn_id, operand_type);
28139 instruction->base.source_node, operand, instruction->fn_id);
28140 result->value->type = operand_type;
28141 return result;
28142}28956}
2814328957
28144static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstructionBswap *instruction) {28958static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *instruction) {
28145 Error err;28959 Error err;
2814628960
28147 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);28961 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);
28148 if (type_is_invalid(int_type))28962 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;
28152 if (type_is_invalid(uncasted_op->value->type))28966 if (type_is_invalid(uncasted_op->value->type))
28153 return ira->codegen->invalid_instruction;28967 return ira->codegen->invalid_inst_gen;
2815428968
28155 uint32_t vector_len; // UINT32_MAX means not a vector28969 uint32_t vector_len; // UINT32_MAX means not a vector
28156 if (uncasted_op->value->type->id == ZigTypeIdArray &&28970 if (uncasted_op->value->type->id == ZigTypeIdArray &&
...@@ -28166,28 +28980,28 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction...@@ -28166,28 +28980,28 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction
28166 bool is_vector = (vector_len != UINT32_MAX);28980 bool is_vector = (vector_len != UINT32_MAX);
28167 ZigType *op_type = is_vector ? get_vector_type(ira->codegen, vector_len, int_type) : int_type;28981 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);
28170 if (type_is_invalid(op->value->type))28984 if (type_is_invalid(op->value->type))
28171 return ira->codegen->invalid_instruction;28985 return ira->codegen->invalid_inst_gen;
2817228986
28173 if (int_type->data.integral.bit_count == 8 || int_type->data.integral.bit_count == 0)28987 if (int_type->data.integral.bit_count == 8 || int_type->data.integral.bit_count == 0)
28174 return op;28988 return op;
2817528989
28176 if (int_type->data.integral.bit_count % 8 != 0) {28990 if (int_type->data.integral.bit_count % 8 != 0) {
28177 ir_add_error(ira, instruction->op,28991 ir_add_error(ira, &instruction->op->base,
28178 buf_sprintf("@byteSwap integer type '%s' has %" PRIu32 " bits which is not evenly divisible by 8",28992 buf_sprintf("@byteSwap integer type '%s' has %" PRIu32 " bits which is not evenly divisible by 8",
28179 buf_ptr(&int_type->name), int_type->data.integral.bit_count));28993 buf_ptr(&int_type->name), int_type->data.integral.bit_count));
28180 return ira->codegen->invalid_instruction;28994 return ira->codegen->invalid_inst_gen;
28181 }28995 }
2818228996
28183 if (instr_is_comptime(op)) {28997 if (instr_is_comptime(op)) {
28184 ZigValue *val = ir_resolve_const(ira, op, UndefOk);28998 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
28185 if (val == nullptr)28999 if (val == nullptr)
28186 return ira->codegen->invalid_instruction;29000 return ira->codegen->invalid_inst_gen;
28187 if (val->special == ConstValSpecialUndef)29001 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);
28191 size_t buf_size = int_type->data.integral.bit_count / 8;29005 size_t buf_size = int_type->data.integral.bit_count / 8;
28192 uint8_t *buf = allocate_nonzero<uint8_t>(buf_size);29006 uint8_t *buf = allocate_nonzero<uint8_t>(buf_size);
28193 if (is_vector) {29007 if (is_vector) {
...@@ -28195,10 +29009,10 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction...@@ -28195,10 +29009,10 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction
28195 result->value->data.x_array.data.s_none.elements = create_const_vals(op_type->data.vector.len);29009 result->value->data.x_array.data.s_none.elements = create_const_vals(op_type->data.vector.len);
28196 for (unsigned i = 0; i < op_type->data.vector.len; i += 1) {29010 for (unsigned i = 0; i < op_type->data.vector.len; i += 1) {
28197 ZigValue *op_elem_val = &val->data.x_array.data.s_none.elements[i];29011 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,
28199 op_elem_val, UndefOk)))29013 op_elem_val, UndefOk)))
28200 {29014 {
28201 return ira->codegen->invalid_instruction;29015 return ira->codegen->invalid_inst_gen;
28202 }29016 }
28203 ZigValue *result_elem_val = &result->value->data.x_array.data.s_none.elements[i];29017 ZigValue *result_elem_val = &result->value->data.x_array.data.s_none.elements[i];
28204 result_elem_val->type = int_type;29018 result_elem_val->type = int_type;
...@@ -28220,23 +29034,20 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction...@@ -28220,23 +29034,20 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction
28220 return result;29034 return result;
28221 }29035 }
2822229036
28223 IrInstruction *result = ir_build_bswap(&ira->new_irb, instruction->base.scope,29037 return ir_build_bswap_gen(ira, &instruction->base.base, op_type, op);
28224 instruction->base.source_node, nullptr, op);
28225 result->value->type = op_type;
28226 return result;
28227}29038}
2822829039
28229static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstructionBitReverse *instruction) {29040static IrInstGen *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstSrcBitReverse *instruction) {
28230 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);29041 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);
28231 if (type_is_invalid(int_type))29042 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);
28235 if (type_is_invalid(op->value->type))29046 if (type_is_invalid(op->value->type))
28236 return ira->codegen->invalid_instruction;29047 return ira->codegen->invalid_inst_gen;
2823729048
28238 if (int_type->data.integral.bit_count == 0) {29049 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);
28240 bigint_init_unsigned(&result->value->data.x_bigint, 0);29051 bigint_init_unsigned(&result->value->data.x_bigint, 0);
28241 return result;29052 return result;
28242 }29053 }
...@@ -28244,11 +29055,11 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr...@@ -28244,11 +29055,11 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr
28244 if (instr_is_comptime(op)) {29055 if (instr_is_comptime(op)) {
28245 ZigValue *val = ir_resolve_const(ira, op, UndefOk);29056 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
28246 if (val == nullptr)29057 if (val == nullptr)
28247 return ira->codegen->invalid_instruction;29058 return ira->codegen->invalid_inst_gen;
28248 if (val->special == ConstValSpecialUndef)29059 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);
28252 size_t num_bits = int_type->data.integral.bit_count;29063 size_t num_bits = int_type->data.integral.bit_count;
28253 size_t buf_size = (num_bits + 7) / 8;29064 size_t buf_size = (num_bits + 7) / 8;
28254 uint8_t *comptime_buf = allocate_nonzero<uint8_t>(buf_size);29065 uint8_t *comptime_buf = allocate_nonzero<uint8_t>(buf_size);
...@@ -28275,128 +29086,125 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr...@@ -28275,128 +29086,125 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr
28275 return result;29086 return result;
28276 }29087 }
2827729088
28278 IrInstruction *result = ir_build_bit_reverse(&ira->new_irb, instruction->base.scope,29089 return ir_build_bit_reverse_gen(ira, &instruction->base.base, int_type, op);
28279 instruction->base.source_node, nullptr, op);
28280 result->value->type = int_type;
28281 return result;
28282}29090}
2828329091
2828429092
28285static IrInstruction *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstructionEnumToInt *instruction) {29093static IrInstGen *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstSrcEnumToInt *instruction) {
28286 IrInstruction *target = instruction->target->child;29094 IrInstGen *target = instruction->target->child;
28287 if (type_is_invalid(target->value->type))29095 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);
28291}29099}
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) {
28294 Error err;29102 Error err;
28295 IrInstruction *dest_type_value = instruction->dest_type->child;29103 IrInstGen *dest_type_value = instruction->dest_type->child;
28296 ZigType *dest_type = ir_resolve_type(ira, dest_type_value);29104 ZigType *dest_type = ir_resolve_type(ira, dest_type_value);
28297 if (type_is_invalid(dest_type))29105 if (type_is_invalid(dest_type))
28298 return ira->codegen->invalid_instruction;29106 return ira->codegen->invalid_inst_gen;
2829929107
28300 if (dest_type->id != ZigTypeIdEnum) {29108 if (dest_type->id != ZigTypeIdEnum) {
28301 ir_add_error(ira, instruction->dest_type,29109 ir_add_error(ira, &instruction->dest_type->base,
28302 buf_sprintf("expected enum, found type '%s'", buf_ptr(&dest_type->name)));29110 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;
28304 }29112 }
2830529113
28306 if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown)))29114 if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown)))
28307 return ira->codegen->invalid_instruction;29115 return ira->codegen->invalid_inst_gen;
2830829116
28309 ZigType *tag_type = dest_type->data.enumeration.tag_int_type;29117 ZigType *tag_type = dest_type->data.enumeration.tag_int_type;
2831029118
28311 IrInstruction *target = instruction->target->child;29119 IrInstGen *target = instruction->target->child;
28312 if (type_is_invalid(target->value->type))29120 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);
28316 if (type_is_invalid(casted_target->value->type))29124 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);
28320}29128}
2832129129
28322static IrInstruction *ir_analyze_instruction_check_runtime_scope(IrAnalyze *ira, IrInstructionCheckRuntimeScope *instruction) {29130static IrInstGen *ir_analyze_instruction_check_runtime_scope(IrAnalyze *ira, IrInstSrcCheckRuntimeScope *instruction) {
28323 IrInstruction *block_comptime_inst = instruction->scope_is_comptime->child;29131 IrInstGen *block_comptime_inst = instruction->scope_is_comptime->child;
28324 bool scope_is_comptime;29132 bool scope_is_comptime;
28325 if (!ir_resolve_bool(ira, block_comptime_inst, &scope_is_comptime))29133 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;
28329 bool is_comptime;29137 bool is_comptime;
28330 if (!ir_resolve_bool(ira, is_comptime_inst, &is_comptime))29138 if (!ir_resolve_bool(ira, is_comptime_inst, &is_comptime))
28331 return ira->codegen->invalid_instruction;29139 return ira->codegen->invalid_inst_gen;
2833229140
28333 if (!scope_is_comptime && is_comptime) {29141 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,
28335 buf_sprintf("comptime control flow inside runtime block"));29143 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,
28337 buf_sprintf("runtime block created here"));29145 buf_sprintf("runtime block created here"));
28338 return ira->codegen->invalid_instruction;29146 return ira->codegen->invalid_inst_gen;
28339 }29147 }
2834029148
28341 return ir_const_void(ira, &instruction->base);29149 return ir_const_void(ira, &instruction->base.base);
28342}29150}
2834329151
28344static IrInstruction *ir_analyze_instruction_has_decl(IrAnalyze *ira, IrInstructionHasDecl *instruction) {29152static IrInstGen *ir_analyze_instruction_has_decl(IrAnalyze *ira, IrInstSrcHasDecl *instruction) {
28345 ZigType *container_type = ir_resolve_type(ira, instruction->container->child);29153 ZigType *container_type = ir_resolve_type(ira, instruction->container->child);
28346 if (type_is_invalid(container_type))29154 if (type_is_invalid(container_type))
28347 return ira->codegen->invalid_instruction;29155 return ira->codegen->invalid_inst_gen;
2834829156
28349 Buf *name = ir_resolve_str(ira, instruction->name->child);29157 Buf *name = ir_resolve_str(ira, instruction->name->child);
28350 if (name == nullptr)29158 if (name == nullptr)
28351 return ira->codegen->invalid_instruction;29159 return ira->codegen->invalid_inst_gen;
2835229160
28353 if (!is_container(container_type)) {29161 if (!is_container(container_type)) {
28354 ir_add_error(ira, instruction->container,29162 ir_add_error(ira, &instruction->container->base,
28355 buf_sprintf("expected struct, enum, or union; found '%s'", buf_ptr(&container_type->name)));29163 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;
28357 }29165 }
2835829166
28359 ScopeDecls *container_scope = get_container_scope(container_type);29167 ScopeDecls *container_scope = get_container_scope(container_type);
28360 Tld *tld = find_container_decl(ira->codegen, container_scope, name);29168 Tld *tld = find_container_decl(ira->codegen, container_scope, name);
28361 if (tld == nullptr)29169 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)) {29172 if (tld->visib_mod == VisibModPrivate && tld->import != get_scope_import(instruction->base.base.scope)) {
28365 return ir_const_bool(ira, &instruction->base, false);29173 return ir_const_bool(ira, &instruction->base.base, false);
28366 }29174 }
2836729175
28368 return ir_const_bool(ira, &instruction->base, true);29176 return ir_const_bool(ira, &instruction->base.base, true);
28369}29177}
2837029178
28371static IrInstruction *ir_analyze_instruction_undeclared_ident(IrAnalyze *ira, IrInstructionUndeclaredIdent *instruction) {29179static IrInstGen *ir_analyze_instruction_undeclared_ident(IrAnalyze *ira, IrInstSrcUndeclaredIdent *instruction) {
28372 // put a variable of same name with invalid type in global scope29180 // put a variable of same name with invalid type in global scope
28373 // so that future references to this same name will find a variable with an invalid type29181 // 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,29182 populate_invalid_variable_in_scope(ira->codegen, instruction->base.base.scope,
28375 instruction->name);29183 instruction->base.base.source_node, instruction->name);
28376 ir_add_error(ira, &instruction->base,29184 ir_add_error(ira, &instruction->base.base,
28377 buf_sprintf("use of undeclared identifier '%s'", buf_ptr(instruction->name)));29185 buf_sprintf("use of undeclared identifier '%s'", buf_ptr(instruction->name)));
28378 return ira->codegen->invalid_instruction;29186 return ira->codegen->invalid_inst_gen;
28379}29187}
2838029188
28381static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstructionEndExpr *instruction) {29189static IrInstGen *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstSrcEndExpr *instruction) {
28382 IrInstruction *value = instruction->value->child;29190 IrInstGen *value = instruction->value->child;
28383 if (type_is_invalid(value->value->type))29191 if (type_is_invalid(value->value->type))
28384 return ira->codegen->invalid_instruction;29192 return ira->codegen->invalid_inst_gen;
2838529193
28386 bool was_written = instruction->result_loc->written;29194 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,
28388 value->value->type, value, false, false, true);29196 value->value->type, value, false, false, true);
28389 if (result_loc != nullptr) {29197 if (result_loc != nullptr) {
28390 if (type_is_invalid(result_loc->value->type))29198 if (type_is_invalid(result_loc->value->type))
28391 return ira->codegen->invalid_instruction;29199 return ira->codegen->invalid_inst_gen;
28392 if (result_loc->value->type->id == ZigTypeIdUnreachable)29200 if (result_loc->value->type->id == ZigTypeIdUnreachable)
28393 return result_loc;29201 return result_loc;
2839429202
28395 if (!was_written || instruction->result_loc->id == ResultLocIdPeer) {29203 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,
28397 instruction->result_loc->allow_write_through_const);29205 instruction->result_loc->allow_write_through_const);
28398 if (type_is_invalid(store_ptr->value->type)) {29206 if (type_is_invalid(store_ptr->value->type)) {
28399 return ira->codegen->invalid_instruction;29207 return ira->codegen->invalid_inst_gen;
28400 }29208 }
28401 }29209 }
2840229210
...@@ -28411,33 +29219,33 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct...@@ -28411,33 +29219,33 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct
28411 }29219 }
28412 }29220 }
2841329221
28414 return ir_const_void(ira, &instruction->base);29222 return ir_const_void(ira, &instruction->base.base);
28415}29223}
2841629224
28417static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstructionImplicitCast *instruction) {29225static IrInstGen *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstSrcImplicitCast *instruction) {
28418 IrInstruction *operand = instruction->operand->child;29226 IrInstGen *operand = instruction->operand->child;
28419 if (type_is_invalid(operand->value->type))29227 if (type_is_invalid(operand->value->type))
28420 return operand;29228 return operand;
2842129229
28422 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base,29230 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base,
28423 &instruction->result_loc_cast->base, operand->value->type, operand, false, false, true);29231 &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))
28425 return result_loc;29233 return result_loc;
2842629234
28427 ZigType *dest_type = ir_resolve_type(ira, instruction->result_loc_cast->base.source_instruction->child);29235 ZigType *dest_type = ir_resolve_type(ira, instruction->result_loc_cast->base.source_instruction->child);
28428 if (type_is_invalid(dest_type))29236 if (type_is_invalid(dest_type))
28429 return ira->codegen->invalid_instruction;29237 return ira->codegen->invalid_inst_gen;
28430 return ir_implicit_cast2(ira, &instruction->base, operand, dest_type);29238 return ir_implicit_cast2(ira, &instruction->base.base, operand, dest_type);
28431}29239}
2843229240
28433static IrInstruction *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstructionBitCastSrc *instruction) {29241static IrInstGen *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstSrcBitCast *instruction) {
28434 IrInstruction *operand = instruction->operand->child;29242 IrInstGen *operand = instruction->operand->child;
28435 if (type_is_invalid(operand->value->type))29243 if (type_is_invalid(operand->value->type))
28436 return operand;29244 return operand;
2843729245
28438 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base,29246 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base,
28439 &instruction->result_loc_bit_cast->base, operand->value->type, operand, false, false, true);29247 &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))
28441 return result_loc;29249 return result_loc;
2844229250
28443 if (instruction->result_loc_bit_cast->parent->gen_instruction != nullptr) {29251 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...@@ -28447,70 +29255,66 @@ static IrInstruction *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInst
28447 return result_loc;29255 return result_loc;
28448}29256}
2844929257
28450static IrInstruction *ir_analyze_instruction_union_init_named_field(IrAnalyze *ira,29258static IrInstGen *ir_analyze_instruction_union_init_named_field(IrAnalyze *ira,
28451 IrInstructionUnionInitNamedField *instruction)29259 IrInstSrcUnionInitNamedField *instruction)
28452{29260{
28453 ZigType *union_type = ir_resolve_type(ira, instruction->union_type->child);29261 ZigType *union_type = ir_resolve_type(ira, instruction->union_type->child);
28454 if (type_is_invalid(union_type))29262 if (type_is_invalid(union_type))
28455 return ira->codegen->invalid_instruction;29263 return ira->codegen->invalid_inst_gen;
2845629264
28457 if (union_type->id != ZigTypeIdUnion) {29265 if (union_type->id != ZigTypeIdUnion) {
28458 ir_add_error(ira, instruction->union_type,29266 ir_add_error(ira, &instruction->union_type->base,
28459 buf_sprintf("non-union type '%s' passed to @unionInit", buf_ptr(&union_type->name)));29267 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;
28461 }29269 }
2846229270
28463 Buf *field_name = ir_resolve_str(ira, instruction->field_name->child);29271 Buf *field_name = ir_resolve_str(ira, instruction->field_name->child);
28464 if (field_name == nullptr)29272 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;
28468 if (type_is_invalid(field_result_loc->value->type))29276 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;
28472 if (type_is_invalid(result_loc->value->type))29280 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,
28476 union_type, field_name, field_result_loc, result_loc);29284 union_type, field_name, field_result_loc, result_loc);
28477}29285}
2847829286
28479static IrInstruction *ir_analyze_instruction_suspend_begin(IrAnalyze *ira, IrInstructionSuspendBegin *instruction) {29287static IrInstGen *ir_analyze_instruction_suspend_begin(IrAnalyze *ira, IrInstSrcSuspendBegin *instruction) {
28480 IrInstructionSuspendBegin *result = ir_build_suspend_begin(&ira->new_irb, instruction->base.scope,29288 return ir_build_suspend_begin_gen(ira, &instruction->base.base);
28481 instruction->base.source_node);
28482 return &result->base;
28483}29289}
2848429290
28485static IrInstruction *ir_analyze_instruction_suspend_finish(IrAnalyze *ira,29291static IrInstGen *ir_analyze_instruction_suspend_finish(IrAnalyze *ira, IrInstSrcSuspendFinish *instruction) {
28486 IrInstructionSuspendFinish *instruction)29292 IrInstGen *begin_base = instruction->begin->base.child;
28487{
28488 IrInstruction *begin_base = instruction->begin->base.child;
28489 if (type_is_invalid(begin_base->value->type))29293 if (type_is_invalid(begin_base->value->type))
28490 return ira->codegen->invalid_instruction;29294 return ira->codegen->invalid_inst_gen;
28491 ir_assert(begin_base->id == IrInstructionIdSuspendBegin, &instruction->base);29295 ir_assert(begin_base->id == IrInstGenIdSuspendBegin, &instruction->base.base);
28492 IrInstructionSuspendBegin *begin = reinterpret_cast<IrInstructionSuspendBegin *>(begin_base);29296 IrInstGenSuspendBegin *begin = reinterpret_cast<IrInstGenSuspendBegin *>(begin_base);
2849329297
28494 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);29298 ZigFn *fn_entry = ira->new_irb.exec->fn_entry;
28495 ir_assert(fn_entry != nullptr, &instruction->base);29299 ir_assert(fn_entry != nullptr, &instruction->base.base);
2849629300
28497 if (fn_entry->inferred_async_node == nullptr) {29301 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;
28499 }29303 }
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);
28502}29306}
2850329307
28504static IrInstruction *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInstruction *source_instr,29308static IrInstGen *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInst* source_instr,
28505 IrInstruction *frame_ptr, ZigFn **target_fn)29309 IrInstGen *frame_ptr, ZigFn **target_fn)
28506{29310{
28507 if (type_is_invalid(frame_ptr->value->type))29311 if (type_is_invalid(frame_ptr->value->type))
28508 return ira->codegen->invalid_instruction;29312 return ira->codegen->invalid_inst_gen;
2850929313
28510 *target_fn = nullptr;29314 *target_fn = nullptr;
2851129315
28512 ZigType *result_type;29316 ZigType *result_type;
28513 IrInstruction *frame;29317 IrInstGen *frame;
28514 if (frame_ptr->value->type->id == ZigTypeIdPointer &&29318 if (frame_ptr->value->type->id == ZigTypeIdPointer &&
28515 frame_ptr->value->type->data.pointer.ptr_len == PtrLenSingle &&29319 frame_ptr->value->type->data.pointer.ptr_len == PtrLenSingle &&
28516 frame_ptr->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame)29320 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...@@ -28533,38 +29337,38 @@ static IrInstruction *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInstruct
28533 {29337 {
28534 ir_add_error(ira, source_instr,29338 ir_add_error(ira, source_instr,
28535 buf_sprintf("expected anyframe->T, found '%s'", buf_ptr(&frame->value->type->name)));29339 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;
28537 } else {29341 } else {
28538 result_type = frame->value->type->data.any_frame.result_type;29342 result_type = frame->value->type->data.any_frame.result_type;
28539 }29343 }
28540 }29344 }
2854129345
28542 ZigType *any_frame_type = get_any_frame_type(ira->codegen, result_type);29346 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);
28544 if (type_is_invalid(casted_frame->value->type))29348 if (type_is_invalid(casted_frame->value->type))
28545 return ira->codegen->invalid_instruction;29349 return ira->codegen->invalid_inst_gen;
2854629350
28547 return casted_frame;29351 return casted_frame;
28548}29352}
2854929353
28550static IrInstruction *ir_analyze_instruction_await(IrAnalyze *ira, IrInstructionAwaitSrc *instruction) {29354static IrInstGen *ir_analyze_instruction_await(IrAnalyze *ira, IrInstSrcAwait *instruction) {
28551 IrInstruction *operand = instruction->frame->child;29355 IrInstGen *operand = instruction->frame->child;
28552 if (type_is_invalid(operand->value->type))29356 if (type_is_invalid(operand->value->type))
28553 return ira->codegen->invalid_instruction;29357 return ira->codegen->invalid_inst_gen;
28554 ZigFn *target_fn;29358 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);
28556 if (type_is_invalid(frame->value->type))29360 if (type_is_invalid(frame->value->type))
28557 return ira->codegen->invalid_instruction;29361 return ira->codegen->invalid_inst_gen;
2855829362
28559 ZigType *result_type = frame->value->type->data.any_frame.result_type;29363 ZigType *result_type = frame->value->type->data.any_frame.result_type;
2856029364
28561 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);29365 ZigFn *fn_entry = ira->new_irb.exec->fn_entry;
28562 ir_assert(fn_entry != nullptr, &instruction->base);29366 ir_assert(fn_entry != nullptr, &instruction->base.base);
2856329367
28564 // If it's not @Frame(func) then it's definitely a suspend point29368 // If it's not @Frame(func) then it's definitely a suspend point
28565 if (target_fn == nullptr) {29369 if (target_fn == nullptr) {
28566 if (fn_entry->inferred_async_node == nullptr) {29370 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;
28568 }29372 }
28569 }29373 }
2857029374
...@@ -28572,401 +29376,364 @@ static IrInstruction *ir_analyze_instruction_await(IrAnalyze *ira, IrInstruction...@@ -28572,401 +29376,364 @@ static IrInstruction *ir_analyze_instruction_await(IrAnalyze *ira, IrInstruction
28572 fn_entry->calls_or_awaits_errorable_fn = true;29376 fn_entry->calls_or_awaits_errorable_fn = true;
28573 }29377 }
2857429378
28575 IrInstruction *result_loc;29379 IrInstGen *result_loc;
28576 if (type_has_bits(result_type)) {29380 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,
28578 result_type, nullptr, true, true, true);29382 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))
28580 return result_loc;29384 return result_loc;
28581 } else {29385 } else {
28582 result_loc = nullptr;29386 result_loc = nullptr;
28583 }29387 }
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);
28586 result->target_fn = target_fn;29390 result->target_fn = target_fn;
28587 fn_entry->await_list.append(result);29391 fn_entry->await_list.append(result);
28588 return ir_finish_anal(ira, &result->base);29392 return ir_finish_anal(ira, &result->base);
28589}29393}
2859029394
28591static IrInstruction *ir_analyze_instruction_resume(IrAnalyze *ira, IrInstructionResume *instruction) {29395static IrInstGen *ir_analyze_instruction_resume(IrAnalyze *ira, IrInstSrcResume *instruction) {
28592 IrInstruction *frame_ptr = instruction->frame->child;29396 IrInstGen *frame_ptr = instruction->frame->child;
28593 if (type_is_invalid(frame_ptr->value->type))29397 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;
28597 if (frame_ptr->value->type->id == ZigTypeIdPointer &&29401 if (frame_ptr->value->type->id == ZigTypeIdPointer &&
28598 frame_ptr->value->type->data.pointer.ptr_len == PtrLenSingle &&29402 frame_ptr->value->type->data.pointer.ptr_len == PtrLenSingle &&
28599 frame_ptr->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame)29403 frame_ptr->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame)
28600 {29404 {
28601 frame = frame_ptr;29405 frame = frame_ptr;
28602 } else {29406 } else {
28603 frame = ir_get_deref(ira, &instruction->base, frame_ptr, nullptr);29407 frame = ir_get_deref(ira, &instruction->base.base, frame_ptr, nullptr);
28604 }29408 }
2860529409
28606 ZigType *any_frame_type = get_any_frame_type(ira->codegen, nullptr);29410 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);
28608 if (type_is_invalid(casted_frame->value->type))29412 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);
28612}29416}
2861329417
28614static IrInstruction *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstructionSpillBegin *instruction) {29418static IrInstGen *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstSrcSpillBegin *instruction) {
28615 if (ir_should_inline(ira->new_irb.exec, instruction->base.scope))29419 if (ir_should_inline(ira->old_irb.exec, instruction->base.base.scope))
28616 return ir_const_void(ira, &instruction->base);29420 return ir_const_void(ira, &instruction->base.base);
2861729421
28618 IrInstruction *operand = instruction->operand->child;29422 IrInstGen *operand = instruction->operand->child;
28619 if (type_is_invalid(operand->value->type))29423 if (type_is_invalid(operand->value->type))
28620 return ira->codegen->invalid_instruction;29424 return ira->codegen->invalid_inst_gen;
2862129425
28622 if (!type_has_bits(operand->value->type))29426 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);
28626 ira->new_irb.exec->need_err_code_spill = true;29430 ira->new_irb.exec->need_err_code_spill = true;
2862729431
28628 IrInstructionSpillBegin *result = ir_build_spill_begin(&ira->new_irb, instruction->base.scope,29432 return ir_build_spill_begin_gen(ira, &instruction->base.base, operand, instruction->spill_id);
28629 instruction->base.source_node, operand, instruction->spill_id);
28630 return &result->base;
28631}29433}
2863229434
28633static IrInstruction *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstructionSpillEnd *instruction) {29435static IrInstGen *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstSrcSpillEnd *instruction) {
28634 IrInstruction *operand = instruction->begin->operand->child;29436 IrInstGen *operand = instruction->begin->operand->child;
28635 if (type_is_invalid(operand->value->type))29437 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))
28639 return operand;29441 return operand;
2864029442
28641 ir_assert(instruction->begin->base.child->id == IrInstructionIdSpillBegin, &instruction->base);29443 ir_assert(instruction->begin->base.child->id == IrInstGenIdSpillBegin, &instruction->base.base);
28642 IrInstructionSpillBegin *begin = reinterpret_cast<IrInstructionSpillBegin *>(instruction->begin->base.child);29444 IrInstGenSpillBegin *begin = reinterpret_cast<IrInstGenSpillBegin *>(instruction->begin->base.child);
2864329445
28644 IrInstruction *result = ir_build_spill_end(&ira->new_irb, instruction->base.scope,29446 return ir_build_spill_end_gen(ira, &instruction->base.base, begin, operand->value->type);
28645 instruction->base.source_node, begin);
28646 result->value->type = operand->value->type;
28647 return result;
28648}29447}
2864929448
28650static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction *instruction) {29449static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruction) {
28651 switch (instruction->id) {29450 switch (instruction->id) {
28652 case IrInstructionIdInvalid:29451 case IrInstSrcIdInvalid:
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:
28683 zig_unreachable();29452 zig_unreachable();
2868429453
28685 case IrInstructionIdReturn:29454 case IrInstSrcIdReturn:
28686 return ir_analyze_instruction_return(ira, (IrInstructionReturn *)instruction);29455 return ir_analyze_instruction_return(ira, (IrInstSrcReturn *)instruction);
28687 case IrInstructionIdConst:29456 case IrInstSrcIdConst:
28688 return ir_analyze_instruction_const(ira, (IrInstructionConst *)instruction);29457 return ir_analyze_instruction_const(ira, (IrInstSrcConst *)instruction);
28689 case IrInstructionIdUnOp:29458 case IrInstSrcIdUnOp:
28690 return ir_analyze_instruction_un_op(ira, (IrInstructionUnOp *)instruction);29459 return ir_analyze_instruction_un_op(ira, (IrInstSrcUnOp *)instruction);
28691 case IrInstructionIdBinOp:29460 case IrInstSrcIdBinOp:
28692 return ir_analyze_instruction_bin_op(ira, (IrInstructionBinOp *)instruction);29461 return ir_analyze_instruction_bin_op(ira, (IrInstSrcBinOp *)instruction);
28693 case IrInstructionIdMergeErrSets:29462 case IrInstSrcIdMergeErrSets:
28694 return ir_analyze_instruction_merge_err_sets(ira, (IrInstructionMergeErrSets *)instruction);29463 return ir_analyze_instruction_merge_err_sets(ira, (IrInstSrcMergeErrSets *)instruction);
28695 case IrInstructionIdDeclVarSrc:29464 case IrInstSrcIdDeclVar:
28696 return ir_analyze_instruction_decl_var(ira, (IrInstructionDeclVarSrc *)instruction);29465 return ir_analyze_instruction_decl_var(ira, (IrInstSrcDeclVar *)instruction);
28697 case IrInstructionIdLoadPtr:29466 case IrInstSrcIdLoadPtr:
28698 return ir_analyze_instruction_load_ptr(ira, (IrInstructionLoadPtr *)instruction);29467 return ir_analyze_instruction_load_ptr(ira, (IrInstSrcLoadPtr *)instruction);
28699 case IrInstructionIdStorePtr:29468 case IrInstSrcIdStorePtr:
28700 return ir_analyze_instruction_store_ptr(ira, (IrInstructionStorePtr *)instruction);29469 return ir_analyze_instruction_store_ptr(ira, (IrInstSrcStorePtr *)instruction);
28701 case IrInstructionIdElemPtr:29470 case IrInstSrcIdElemPtr:
28702 return ir_analyze_instruction_elem_ptr(ira, (IrInstructionElemPtr *)instruction);29471 return ir_analyze_instruction_elem_ptr(ira, (IrInstSrcElemPtr *)instruction);
28703 case IrInstructionIdVarPtr:29472 case IrInstSrcIdVarPtr:
28704 return ir_analyze_instruction_var_ptr(ira, (IrInstructionVarPtr *)instruction);29473 return ir_analyze_instruction_var_ptr(ira, (IrInstSrcVarPtr *)instruction);
28705 case IrInstructionIdFieldPtr:29474 case IrInstSrcIdFieldPtr:
28706 return ir_analyze_instruction_field_ptr(ira, (IrInstructionFieldPtr *)instruction);29475 return ir_analyze_instruction_field_ptr(ira, (IrInstSrcFieldPtr *)instruction);
28707 case IrInstructionIdCallSrc:29476 case IrInstSrcIdCall:
28708 return ir_analyze_instruction_call(ira, (IrInstructionCallSrc *)instruction);29477 return ir_analyze_instruction_call(ira, (IrInstSrcCall *)instruction);
28709 case IrInstructionIdCallSrcArgs:29478 case IrInstSrcIdCallArgs:
28710 return ir_analyze_instruction_call_args(ira, (IrInstructionCallSrcArgs *)instruction);29479 return ir_analyze_instruction_call_args(ira, (IrInstSrcCallArgs *)instruction);
28711 case IrInstructionIdCallExtra:29480 case IrInstSrcIdCallExtra:
28712 return ir_analyze_instruction_call_extra(ira, (IrInstructionCallExtra *)instruction);29481 return ir_analyze_instruction_call_extra(ira, (IrInstSrcCallExtra *)instruction);
28713 case IrInstructionIdBr:29482 case IrInstSrcIdBr:
28714 return ir_analyze_instruction_br(ira, (IrInstructionBr *)instruction);29483 return ir_analyze_instruction_br(ira, (IrInstSrcBr *)instruction);
28715 case IrInstructionIdCondBr:29484 case IrInstSrcIdCondBr:
28716 return ir_analyze_instruction_cond_br(ira, (IrInstructionCondBr *)instruction);29485 return ir_analyze_instruction_cond_br(ira, (IrInstSrcCondBr *)instruction);
28717 case IrInstructionIdUnreachable:29486 case IrInstSrcIdUnreachable:
28718 return ir_analyze_instruction_unreachable(ira, (IrInstructionUnreachable *)instruction);29487 return ir_analyze_instruction_unreachable(ira, (IrInstSrcUnreachable *)instruction);
28719 case IrInstructionIdPhi:29488 case IrInstSrcIdPhi:
28720 return ir_analyze_instruction_phi(ira, (IrInstructionPhi *)instruction);29489 return ir_analyze_instruction_phi(ira, (IrInstSrcPhi *)instruction);
28721 case IrInstructionIdTypeOf:29490 case IrInstSrcIdTypeOf:
28722 return ir_analyze_instruction_typeof(ira, (IrInstructionTypeOf *)instruction);29491 return ir_analyze_instruction_typeof(ira, (IrInstSrcTypeOf *)instruction);
28723 case IrInstructionIdSetCold:29492 case IrInstSrcIdSetCold:
28724 return ir_analyze_instruction_set_cold(ira, (IrInstructionSetCold *)instruction);29493 return ir_analyze_instruction_set_cold(ira, (IrInstSrcSetCold *)instruction);
28725 case IrInstructionIdSetRuntimeSafety:29494 case IrInstSrcIdSetRuntimeSafety:
28726 return ir_analyze_instruction_set_runtime_safety(ira, (IrInstructionSetRuntimeSafety *)instruction);29495 return ir_analyze_instruction_set_runtime_safety(ira, (IrInstSrcSetRuntimeSafety *)instruction);
28727 case IrInstructionIdSetFloatMode:29496 case IrInstSrcIdSetFloatMode:
28728 return ir_analyze_instruction_set_float_mode(ira, (IrInstructionSetFloatMode *)instruction);29497 return ir_analyze_instruction_set_float_mode(ira, (IrInstSrcSetFloatMode *)instruction);
28729 case IrInstructionIdAnyFrameType:29498 case IrInstSrcIdAnyFrameType:
28730 return ir_analyze_instruction_any_frame_type(ira, (IrInstructionAnyFrameType *)instruction);29499 return ir_analyze_instruction_any_frame_type(ira, (IrInstSrcAnyFrameType *)instruction);
28731 case IrInstructionIdSliceType:29500 case IrInstSrcIdSliceType:
28732 return ir_analyze_instruction_slice_type(ira, (IrInstructionSliceType *)instruction);29501 return ir_analyze_instruction_slice_type(ira, (IrInstSrcSliceType *)instruction);
28733 case IrInstructionIdAsmSrc:29502 case IrInstSrcIdAsm:
28734 return ir_analyze_instruction_asm(ira, (IrInstructionAsmSrc *)instruction);29503 return ir_analyze_instruction_asm(ira, (IrInstSrcAsm *)instruction);
28735 case IrInstructionIdArrayType:29504 case IrInstSrcIdArrayType:
28736 return ir_analyze_instruction_array_type(ira, (IrInstructionArrayType *)instruction);29505 return ir_analyze_instruction_array_type(ira, (IrInstSrcArrayType *)instruction);
28737 case IrInstructionIdSizeOf:29506 case IrInstSrcIdSizeOf:
28738 return ir_analyze_instruction_size_of(ira, (IrInstructionSizeOf *)instruction);29507 return ir_analyze_instruction_size_of(ira, (IrInstSrcSizeOf *)instruction);
28739 case IrInstructionIdTestNonNull:29508 case IrInstSrcIdTestNonNull:
28740 return ir_analyze_instruction_test_non_null(ira, (IrInstructionTestNonNull *)instruction);29509 return ir_analyze_instruction_test_non_null(ira, (IrInstSrcTestNonNull *)instruction);
28741 case IrInstructionIdOptionalUnwrapPtr:29510 case IrInstSrcIdOptionalUnwrapPtr:
28742 return ir_analyze_instruction_optional_unwrap_ptr(ira, (IrInstructionOptionalUnwrapPtr *)instruction);29511 return ir_analyze_instruction_optional_unwrap_ptr(ira, (IrInstSrcOptionalUnwrapPtr *)instruction);
28743 case IrInstructionIdClz:29512 case IrInstSrcIdClz:
28744 return ir_analyze_instruction_clz(ira, (IrInstructionClz *)instruction);29513 return ir_analyze_instruction_clz(ira, (IrInstSrcClz *)instruction);
28745 case IrInstructionIdCtz:29514 case IrInstSrcIdCtz:
28746 return ir_analyze_instruction_ctz(ira, (IrInstructionCtz *)instruction);29515 return ir_analyze_instruction_ctz(ira, (IrInstSrcCtz *)instruction);
28747 case IrInstructionIdPopCount:29516 case IrInstSrcIdPopCount:
28748 return ir_analyze_instruction_pop_count(ira, (IrInstructionPopCount *)instruction);29517 return ir_analyze_instruction_pop_count(ira, (IrInstSrcPopCount *)instruction);
28749 case IrInstructionIdBswap:29518 case IrInstSrcIdBswap:
28750 return ir_analyze_instruction_bswap(ira, (IrInstructionBswap *)instruction);29519 return ir_analyze_instruction_bswap(ira, (IrInstSrcBswap *)instruction);
28751 case IrInstructionIdBitReverse:29520 case IrInstSrcIdBitReverse:
28752 return ir_analyze_instruction_bit_reverse(ira, (IrInstructionBitReverse *)instruction);29521 return ir_analyze_instruction_bit_reverse(ira, (IrInstSrcBitReverse *)instruction);
28753 case IrInstructionIdSwitchBr:29522 case IrInstSrcIdSwitchBr:
28754 return ir_analyze_instruction_switch_br(ira, (IrInstructionSwitchBr *)instruction);29523 return ir_analyze_instruction_switch_br(ira, (IrInstSrcSwitchBr *)instruction);
28755 case IrInstructionIdSwitchTarget:29524 case IrInstSrcIdSwitchTarget:
28756 return ir_analyze_instruction_switch_target(ira, (IrInstructionSwitchTarget *)instruction);29525 return ir_analyze_instruction_switch_target(ira, (IrInstSrcSwitchTarget *)instruction);
28757 case IrInstructionIdSwitchVar:29526 case IrInstSrcIdSwitchVar:
28758 return ir_analyze_instruction_switch_var(ira, (IrInstructionSwitchVar *)instruction);29527 return ir_analyze_instruction_switch_var(ira, (IrInstSrcSwitchVar *)instruction);
28759 case IrInstructionIdSwitchElseVar:29528 case IrInstSrcIdSwitchElseVar:
28760 return ir_analyze_instruction_switch_else_var(ira, (IrInstructionSwitchElseVar *)instruction);29529 return ir_analyze_instruction_switch_else_var(ira, (IrInstSrcSwitchElseVar *)instruction);
28761 case IrInstructionIdUnionTag:29530 case IrInstSrcIdImport:
28762 return ir_analyze_instruction_union_tag(ira, (IrInstructionUnionTag *)instruction);29531 return ir_analyze_instruction_import(ira, (IrInstSrcImport *)instruction);
28763 case IrInstructionIdImport:29532 case IrInstSrcIdRef:
28764 return ir_analyze_instruction_import(ira, (IrInstructionImport *)instruction);29533 return ir_analyze_instruction_ref(ira, (IrInstSrcRef *)instruction);
28765 case IrInstructionIdRef:29534 case IrInstSrcIdContainerInitList:
28766 return ir_analyze_instruction_ref(ira, (IrInstructionRef *)instruction);29535 return ir_analyze_instruction_container_init_list(ira, (IrInstSrcContainerInitList *)instruction);
28767 case IrInstructionIdContainerInitList:29536 case IrInstSrcIdContainerInitFields:
28768 return ir_analyze_instruction_container_init_list(ira, (IrInstructionContainerInitList *)instruction);29537 return ir_analyze_instruction_container_init_fields(ira, (IrInstSrcContainerInitFields *)instruction);
28769 case IrInstructionIdContainerInitFields:29538 case IrInstSrcIdCompileErr:
28770 return ir_analyze_instruction_container_init_fields(ira, (IrInstructionContainerInitFields *)instruction);29539 return ir_analyze_instruction_compile_err(ira, (IrInstSrcCompileErr *)instruction);
28771 case IrInstructionIdCompileErr:29540 case IrInstSrcIdCompileLog:
28772 return ir_analyze_instruction_compile_err(ira, (IrInstructionCompileErr *)instruction);29541 return ir_analyze_instruction_compile_log(ira, (IrInstSrcCompileLog *)instruction);
28773 case IrInstructionIdCompileLog:29542 case IrInstSrcIdErrName:
28774 return ir_analyze_instruction_compile_log(ira, (IrInstructionCompileLog *)instruction);29543 return ir_analyze_instruction_err_name(ira, (IrInstSrcErrName *)instruction);
28775 case IrInstructionIdErrName:29544 case IrInstSrcIdTypeName:
28776 return ir_analyze_instruction_err_name(ira, (IrInstructionErrName *)instruction);29545 return ir_analyze_instruction_type_name(ira, (IrInstSrcTypeName *)instruction);
28777 case IrInstructionIdTypeName:29546 case IrInstSrcIdCImport:
28778 return ir_analyze_instruction_type_name(ira, (IrInstructionTypeName *)instruction);29547 return ir_analyze_instruction_c_import(ira, (IrInstSrcCImport *)instruction);
28779 case IrInstructionIdCImport:29548 case IrInstSrcIdCInclude:
28780 return ir_analyze_instruction_c_import(ira, (IrInstructionCImport *)instruction);29549 return ir_analyze_instruction_c_include(ira, (IrInstSrcCInclude *)instruction);
28781 case IrInstructionIdCInclude:29550 case IrInstSrcIdCDefine:
28782 return ir_analyze_instruction_c_include(ira, (IrInstructionCInclude *)instruction);29551 return ir_analyze_instruction_c_define(ira, (IrInstSrcCDefine *)instruction);
28783 case IrInstructionIdCDefine:29552 case IrInstSrcIdCUndef:
28784 return ir_analyze_instruction_c_define(ira, (IrInstructionCDefine *)instruction);29553 return ir_analyze_instruction_c_undef(ira, (IrInstSrcCUndef *)instruction);
28785 case IrInstructionIdCUndef:29554 case IrInstSrcIdEmbedFile:
28786 return ir_analyze_instruction_c_undef(ira, (IrInstructionCUndef *)instruction);29555 return ir_analyze_instruction_embed_file(ira, (IrInstSrcEmbedFile *)instruction);
28787 case IrInstructionIdEmbedFile:29556 case IrInstSrcIdCmpxchg:
28788 return ir_analyze_instruction_embed_file(ira, (IrInstructionEmbedFile *)instruction);29557 return ir_analyze_instruction_cmpxchg(ira, (IrInstSrcCmpxchg *)instruction);
28789 case IrInstructionIdCmpxchgSrc:29558 case IrInstSrcIdFence:
28790 return ir_analyze_instruction_cmpxchg(ira, (IrInstructionCmpxchgSrc *)instruction);29559 return ir_analyze_instruction_fence(ira, (IrInstSrcFence *)instruction);
28791 case IrInstructionIdFence:29560 case IrInstSrcIdTruncate:
28792 return ir_analyze_instruction_fence(ira, (IrInstructionFence *)instruction);29561 return ir_analyze_instruction_truncate(ira, (IrInstSrcTruncate *)instruction);
28793 case IrInstructionIdTruncate:29562 case IrInstSrcIdIntCast:
28794 return ir_analyze_instruction_truncate(ira, (IrInstructionTruncate *)instruction);29563 return ir_analyze_instruction_int_cast(ira, (IrInstSrcIntCast *)instruction);
28795 case IrInstructionIdIntCast:29564 case IrInstSrcIdFloatCast:
28796 return ir_analyze_instruction_int_cast(ira, (IrInstructionIntCast *)instruction);29565 return ir_analyze_instruction_float_cast(ira, (IrInstSrcFloatCast *)instruction);
28797 case IrInstructionIdFloatCast:29566 case IrInstSrcIdErrSetCast:
28798 return ir_analyze_instruction_float_cast(ira, (IrInstructionFloatCast *)instruction);29567 return ir_analyze_instruction_err_set_cast(ira, (IrInstSrcErrSetCast *)instruction);
28799 case IrInstructionIdErrSetCast:29568 case IrInstSrcIdFromBytes:
28800 return ir_analyze_instruction_err_set_cast(ira, (IrInstructionErrSetCast *)instruction);29569 return ir_analyze_instruction_from_bytes(ira, (IrInstSrcFromBytes *)instruction);
28801 case IrInstructionIdFromBytes:29570 case IrInstSrcIdToBytes:
28802 return ir_analyze_instruction_from_bytes(ira, (IrInstructionFromBytes *)instruction);29571 return ir_analyze_instruction_to_bytes(ira, (IrInstSrcToBytes *)instruction);
28803 case IrInstructionIdToBytes:29572 case IrInstSrcIdIntToFloat:
28804 return ir_analyze_instruction_to_bytes(ira, (IrInstructionToBytes *)instruction);29573 return ir_analyze_instruction_int_to_float(ira, (IrInstSrcIntToFloat *)instruction);
28805 case IrInstructionIdIntToFloat:29574 case IrInstSrcIdFloatToInt:
28806 return ir_analyze_instruction_int_to_float(ira, (IrInstructionIntToFloat *)instruction);29575 return ir_analyze_instruction_float_to_int(ira, (IrInstSrcFloatToInt *)instruction);
28807 case IrInstructionIdFloatToInt:29576 case IrInstSrcIdBoolToInt:
28808 return ir_analyze_instruction_float_to_int(ira, (IrInstructionFloatToInt *)instruction);29577 return ir_analyze_instruction_bool_to_int(ira, (IrInstSrcBoolToInt *)instruction);
28809 case IrInstructionIdBoolToInt:29578 case IrInstSrcIdIntType:
28810 return ir_analyze_instruction_bool_to_int(ira, (IrInstructionBoolToInt *)instruction);29579 return ir_analyze_instruction_int_type(ira, (IrInstSrcIntType *)instruction);
28811 case IrInstructionIdIntType:29580 case IrInstSrcIdVectorType:
28812 return ir_analyze_instruction_int_type(ira, (IrInstructionIntType *)instruction);29581 return ir_analyze_instruction_vector_type(ira, (IrInstSrcVectorType *)instruction);
28813 case IrInstructionIdVectorType:29582 case IrInstSrcIdShuffleVector:
28814 return ir_analyze_instruction_vector_type(ira, (IrInstructionVectorType *)instruction);29583 return ir_analyze_instruction_shuffle_vector(ira, (IrInstSrcShuffleVector *)instruction);
28815 case IrInstructionIdShuffleVector:29584 case IrInstSrcIdSplat:
28816 return ir_analyze_instruction_shuffle_vector(ira, (IrInstructionShuffleVector *)instruction);29585 return ir_analyze_instruction_splat(ira, (IrInstSrcSplat *)instruction);
28817 case IrInstructionIdSplatSrc:29586 case IrInstSrcIdBoolNot:
28818 return ir_analyze_instruction_splat(ira, (IrInstructionSplatSrc *)instruction);29587 return ir_analyze_instruction_bool_not(ira, (IrInstSrcBoolNot *)instruction);
28819 case IrInstructionIdBoolNot:29588 case IrInstSrcIdMemset:
28820 return ir_analyze_instruction_bool_not(ira, (IrInstructionBoolNot *)instruction);29589 return ir_analyze_instruction_memset(ira, (IrInstSrcMemset *)instruction);
28821 case IrInstructionIdMemset:29590 case IrInstSrcIdMemcpy:
28822 return ir_analyze_instruction_memset(ira, (IrInstructionMemset *)instruction);29591 return ir_analyze_instruction_memcpy(ira, (IrInstSrcMemcpy *)instruction);
28823 case IrInstructionIdMemcpy:29592 case IrInstSrcIdSlice:
28824 return ir_analyze_instruction_memcpy(ira, (IrInstructionMemcpy *)instruction);29593 return ir_analyze_instruction_slice(ira, (IrInstSrcSlice *)instruction);
28825 case IrInstructionIdSliceSrc:29594 case IrInstSrcIdMemberCount:
28826 return ir_analyze_instruction_slice(ira, (IrInstructionSliceSrc *)instruction);29595 return ir_analyze_instruction_member_count(ira, (IrInstSrcMemberCount *)instruction);
28827 case IrInstructionIdMemberCount:29596 case IrInstSrcIdMemberType:
28828 return ir_analyze_instruction_member_count(ira, (IrInstructionMemberCount *)instruction);29597 return ir_analyze_instruction_member_type(ira, (IrInstSrcMemberType *)instruction);
28829 case IrInstructionIdMemberType:29598 case IrInstSrcIdMemberName:
28830 return ir_analyze_instruction_member_type(ira, (IrInstructionMemberType *)instruction);29599 return ir_analyze_instruction_member_name(ira, (IrInstSrcMemberName *)instruction);
28831 case IrInstructionIdMemberName:29600 case IrInstSrcIdBreakpoint:
28832 return ir_analyze_instruction_member_name(ira, (IrInstructionMemberName *)instruction);29601 return ir_analyze_instruction_breakpoint(ira, (IrInstSrcBreakpoint *)instruction);
28833 case IrInstructionIdBreakpoint:29602 case IrInstSrcIdReturnAddress:
28834 return ir_analyze_instruction_breakpoint(ira, (IrInstructionBreakpoint *)instruction);29603 return ir_analyze_instruction_return_address(ira, (IrInstSrcReturnAddress *)instruction);
28835 case IrInstructionIdReturnAddress:29604 case IrInstSrcIdFrameAddress:
28836 return ir_analyze_instruction_return_address(ira, (IrInstructionReturnAddress *)instruction);29605 return ir_analyze_instruction_frame_address(ira, (IrInstSrcFrameAddress *)instruction);
28837 case IrInstructionIdFrameAddress:29606 case IrInstSrcIdFrameHandle:
28838 return ir_analyze_instruction_frame_address(ira, (IrInstructionFrameAddress *)instruction);29607 return ir_analyze_instruction_frame_handle(ira, (IrInstSrcFrameHandle *)instruction);
28839 case IrInstructionIdFrameHandle:29608 case IrInstSrcIdFrameType:
28840 return ir_analyze_instruction_frame_handle(ira, (IrInstructionFrameHandle *)instruction);29609 return ir_analyze_instruction_frame_type(ira, (IrInstSrcFrameType *)instruction);
28841 case IrInstructionIdFrameType:29610 case IrInstSrcIdFrameSize:
28842 return ir_analyze_instruction_frame_type(ira, (IrInstructionFrameType *)instruction);29611 return ir_analyze_instruction_frame_size(ira, (IrInstSrcFrameSize *)instruction);
28843 case IrInstructionIdFrameSizeSrc:29612 case IrInstSrcIdAlignOf:
28844 return ir_analyze_instruction_frame_size(ira, (IrInstructionFrameSizeSrc *)instruction);29613 return ir_analyze_instruction_align_of(ira, (IrInstSrcAlignOf *)instruction);
28845 case IrInstructionIdAlignOf:29614 case IrInstSrcIdOverflowOp:
28846 return ir_analyze_instruction_align_of(ira, (IrInstructionAlignOf *)instruction);29615 return ir_analyze_instruction_overflow_op(ira, (IrInstSrcOverflowOp *)instruction);
28847 case IrInstructionIdOverflowOp:29616 case IrInstSrcIdTestErr:
28848 return ir_analyze_instruction_overflow_op(ira, (IrInstructionOverflowOp *)instruction);29617 return ir_analyze_instruction_test_err(ira, (IrInstSrcTestErr *)instruction);
28849 case IrInstructionIdTestErrSrc:29618 case IrInstSrcIdUnwrapErrCode:
28850 return ir_analyze_instruction_test_err(ira, (IrInstructionTestErrSrc *)instruction);29619 return ir_analyze_instruction_unwrap_err_code(ira, (IrInstSrcUnwrapErrCode *)instruction);
28851 case IrInstructionIdUnwrapErrCode:29620 case IrInstSrcIdUnwrapErrPayload:
28852 return ir_analyze_instruction_unwrap_err_code(ira, (IrInstructionUnwrapErrCode *)instruction);29621 return ir_analyze_instruction_unwrap_err_payload(ira, (IrInstSrcUnwrapErrPayload *)instruction);
28853 case IrInstructionIdUnwrapErrPayload:29622 case IrInstSrcIdFnProto:
28854 return ir_analyze_instruction_unwrap_err_payload(ira, (IrInstructionUnwrapErrPayload *)instruction);29623 return ir_analyze_instruction_fn_proto(ira, (IrInstSrcFnProto *)instruction);
28855 case IrInstructionIdFnProto:29624 case IrInstSrcIdTestComptime:
28856 return ir_analyze_instruction_fn_proto(ira, (IrInstructionFnProto *)instruction);29625 return ir_analyze_instruction_test_comptime(ira, (IrInstSrcTestComptime *)instruction);
28857 case IrInstructionIdTestComptime:29626 case IrInstSrcIdCheckSwitchProngs:
28858 return ir_analyze_instruction_test_comptime(ira, (IrInstructionTestComptime *)instruction);29627 return ir_analyze_instruction_check_switch_prongs(ira, (IrInstSrcCheckSwitchProngs *)instruction);
28859 case IrInstructionIdCheckSwitchProngs:29628 case IrInstSrcIdCheckStatementIsVoid:
28860 return ir_analyze_instruction_check_switch_prongs(ira, (IrInstructionCheckSwitchProngs *)instruction);29629 return ir_analyze_instruction_check_statement_is_void(ira, (IrInstSrcCheckStatementIsVoid *)instruction);
28861 case IrInstructionIdCheckStatementIsVoid:29630 case IrInstSrcIdDeclRef:
28862 return ir_analyze_instruction_check_statement_is_void(ira, (IrInstructionCheckStatementIsVoid *)instruction);29631 return ir_analyze_instruction_decl_ref(ira, (IrInstSrcDeclRef *)instruction);
28863 case IrInstructionIdDeclRef:29632 case IrInstSrcIdPanic:
28864 return ir_analyze_instruction_decl_ref(ira, (IrInstructionDeclRef *)instruction);29633 return ir_analyze_instruction_panic(ira, (IrInstSrcPanic *)instruction);
28865 case IrInstructionIdPanic:29634 case IrInstSrcIdPtrCast:
28866 return ir_analyze_instruction_panic(ira, (IrInstructionPanic *)instruction);29635 return ir_analyze_instruction_ptr_cast(ira, (IrInstSrcPtrCast *)instruction);
28867 case IrInstructionIdPtrCastSrc:29636 case IrInstSrcIdIntToPtr:
28868 return ir_analyze_instruction_ptr_cast(ira, (IrInstructionPtrCastSrc *)instruction);29637 return ir_analyze_instruction_int_to_ptr(ira, (IrInstSrcIntToPtr *)instruction);
28869 case IrInstructionIdIntToPtr:29638 case IrInstSrcIdPtrToInt:
28870 return ir_analyze_instruction_int_to_ptr(ira, (IrInstructionIntToPtr *)instruction);29639 return ir_analyze_instruction_ptr_to_int(ira, (IrInstSrcPtrToInt *)instruction);
28871 case IrInstructionIdPtrToInt:29640 case IrInstSrcIdTagName:
28872 return ir_analyze_instruction_ptr_to_int(ira, (IrInstructionPtrToInt *)instruction);29641 return ir_analyze_instruction_enum_tag_name(ira, (IrInstSrcTagName *)instruction);
28873 case IrInstructionIdTagName:29642 case IrInstSrcIdFieldParentPtr:
28874 return ir_analyze_instruction_enum_tag_name(ira, (IrInstructionTagName *)instruction);29643 return ir_analyze_instruction_field_parent_ptr(ira, (IrInstSrcFieldParentPtr *)instruction);
28875 case IrInstructionIdFieldParentPtr:29644 case IrInstSrcIdByteOffsetOf:
28876 return ir_analyze_instruction_field_parent_ptr(ira, (IrInstructionFieldParentPtr *)instruction);29645 return ir_analyze_instruction_byte_offset_of(ira, (IrInstSrcByteOffsetOf *)instruction);
28877 case IrInstructionIdByteOffsetOf:29646 case IrInstSrcIdBitOffsetOf:
28878 return ir_analyze_instruction_byte_offset_of(ira, (IrInstructionByteOffsetOf *)instruction);29647 return ir_analyze_instruction_bit_offset_of(ira, (IrInstSrcBitOffsetOf *)instruction);
28879 case IrInstructionIdBitOffsetOf:29648 case IrInstSrcIdTypeInfo:
28880 return ir_analyze_instruction_bit_offset_of(ira, (IrInstructionBitOffsetOf *)instruction);29649 return ir_analyze_instruction_type_info(ira, (IrInstSrcTypeInfo *) instruction);
28881 case IrInstructionIdTypeInfo:29650 case IrInstSrcIdType:
28882 return ir_analyze_instruction_type_info(ira, (IrInstructionTypeInfo *) instruction);29651 return ir_analyze_instruction_type(ira, (IrInstSrcType *)instruction);
28883 case IrInstructionIdType:29652 case IrInstSrcIdHasField:
28884 return ir_analyze_instruction_type(ira, (IrInstructionType *)instruction);29653 return ir_analyze_instruction_has_field(ira, (IrInstSrcHasField *) instruction);
28885 case IrInstructionIdHasField:29654 case IrInstSrcIdTypeId:
28886 return ir_analyze_instruction_has_field(ira, (IrInstructionHasField *) instruction);29655 return ir_analyze_instruction_type_id(ira, (IrInstSrcTypeId *)instruction);
28887 case IrInstructionIdTypeId:29656 case IrInstSrcIdSetEvalBranchQuota:
28888 return ir_analyze_instruction_type_id(ira, (IrInstructionTypeId *)instruction);29657 return ir_analyze_instruction_set_eval_branch_quota(ira, (IrInstSrcSetEvalBranchQuota *)instruction);
28889 case IrInstructionIdSetEvalBranchQuota:29658 case IrInstSrcIdPtrType:
28890 return ir_analyze_instruction_set_eval_branch_quota(ira, (IrInstructionSetEvalBranchQuota *)instruction);29659 return ir_analyze_instruction_ptr_type(ira, (IrInstSrcPtrType *)instruction);
28891 case IrInstructionIdPtrType:29660 case IrInstSrcIdAlignCast:
28892 return ir_analyze_instruction_ptr_type(ira, (IrInstructionPtrType *)instruction);29661 return ir_analyze_instruction_align_cast(ira, (IrInstSrcAlignCast *)instruction);
28893 case IrInstructionIdAlignCast:29662 case IrInstSrcIdImplicitCast:
28894 return ir_analyze_instruction_align_cast(ira, (IrInstructionAlignCast *)instruction);29663 return ir_analyze_instruction_implicit_cast(ira, (IrInstSrcImplicitCast *)instruction);
28895 case IrInstructionIdImplicitCast:29664 case IrInstSrcIdResolveResult:
28896 return ir_analyze_instruction_implicit_cast(ira, (IrInstructionImplicitCast *)instruction);29665 return ir_analyze_instruction_resolve_result(ira, (IrInstSrcResolveResult *)instruction);
28897 case IrInstructionIdResolveResult:29666 case IrInstSrcIdResetResult:
28898 return ir_analyze_instruction_resolve_result(ira, (IrInstructionResolveResult *)instruction);29667 return ir_analyze_instruction_reset_result(ira, (IrInstSrcResetResult *)instruction);
28899 case IrInstructionIdResetResult:29668 case IrInstSrcIdOpaqueType:
28900 return ir_analyze_instruction_reset_result(ira, (IrInstructionResetResult *)instruction);29669 return ir_analyze_instruction_opaque_type(ira, (IrInstSrcOpaqueType *)instruction);
28901 case IrInstructionIdOpaqueType:29670 case IrInstSrcIdSetAlignStack:
28902 return ir_analyze_instruction_opaque_type(ira, (IrInstructionOpaqueType *)instruction);29671 return ir_analyze_instruction_set_align_stack(ira, (IrInstSrcSetAlignStack *)instruction);
28903 case IrInstructionIdSetAlignStack:29672 case IrInstSrcIdArgType:
28904 return ir_analyze_instruction_set_align_stack(ira, (IrInstructionSetAlignStack *)instruction);29673 return ir_analyze_instruction_arg_type(ira, (IrInstSrcArgType *)instruction);
28905 case IrInstructionIdArgType:29674 case IrInstSrcIdTagType:
28906 return ir_analyze_instruction_arg_type(ira, (IrInstructionArgType *)instruction);29675 return ir_analyze_instruction_tag_type(ira, (IrInstSrcTagType *)instruction);
28907 case IrInstructionIdTagType:29676 case IrInstSrcIdExport:
28908 return ir_analyze_instruction_tag_type(ira, (IrInstructionTagType *)instruction);29677 return ir_analyze_instruction_export(ira, (IrInstSrcExport *)instruction);
28909 case IrInstructionIdExport:29678 case IrInstSrcIdErrorReturnTrace:
28910 return ir_analyze_instruction_export(ira, (IrInstructionExport *)instruction);29679 return ir_analyze_instruction_error_return_trace(ira, (IrInstSrcErrorReturnTrace *)instruction);
28911 case IrInstructionIdErrorReturnTrace:29680 case IrInstSrcIdErrorUnion:
28912 return ir_analyze_instruction_error_return_trace(ira, (IrInstructionErrorReturnTrace *)instruction);29681 return ir_analyze_instruction_error_union(ira, (IrInstSrcErrorUnion *)instruction);
28913 case IrInstructionIdErrorUnion:29682 case IrInstSrcIdAtomicRmw:
28914 return ir_analyze_instruction_error_union(ira, (IrInstructionErrorUnion *)instruction);29683 return ir_analyze_instruction_atomic_rmw(ira, (IrInstSrcAtomicRmw *)instruction);
28915 case IrInstructionIdAtomicRmw:29684 case IrInstSrcIdAtomicLoad:
28916 return ir_analyze_instruction_atomic_rmw(ira, (IrInstructionAtomicRmw *)instruction);29685 return ir_analyze_instruction_atomic_load(ira, (IrInstSrcAtomicLoad *)instruction);
28917 case IrInstructionIdAtomicLoad:29686 case IrInstSrcIdAtomicStore:
28918 return ir_analyze_instruction_atomic_load(ira, (IrInstructionAtomicLoad *)instruction);29687 return ir_analyze_instruction_atomic_store(ira, (IrInstSrcAtomicStore *)instruction);
28919 case IrInstructionIdAtomicStore:29688 case IrInstSrcIdSaveErrRetAddr:
28920 return ir_analyze_instruction_atomic_store(ira, (IrInstructionAtomicStore *)instruction);29689 return ir_analyze_instruction_save_err_ret_addr(ira, (IrInstSrcSaveErrRetAddr *)instruction);
28921 case IrInstructionIdSaveErrRetAddr:29690 case IrInstSrcIdAddImplicitReturnType:
28922 return ir_analyze_instruction_save_err_ret_addr(ira, (IrInstructionSaveErrRetAddr *)instruction);29691 return ir_analyze_instruction_add_implicit_return_type(ira, (IrInstSrcAddImplicitReturnType *)instruction);
28923 case IrInstructionIdAddImplicitReturnType:29692 case IrInstSrcIdFloatOp:
28924 return ir_analyze_instruction_add_implicit_return_type(ira, (IrInstructionAddImplicitReturnType *)instruction);29693 return ir_analyze_instruction_float_op(ira, (IrInstSrcFloatOp *)instruction);
28925 case IrInstructionIdFloatOp:29694 case IrInstSrcIdMulAdd:
28926 return ir_analyze_instruction_float_op(ira, (IrInstructionFloatOp *)instruction);29695 return ir_analyze_instruction_mul_add(ira, (IrInstSrcMulAdd *)instruction);
28927 case IrInstructionIdMulAdd:29696 case IrInstSrcIdIntToErr:
28928 return ir_analyze_instruction_mul_add(ira, (IrInstructionMulAdd *)instruction);29697 return ir_analyze_instruction_int_to_err(ira, (IrInstSrcIntToErr *)instruction);
28929 case IrInstructionIdIntToErr:29698 case IrInstSrcIdErrToInt:
28930 return ir_analyze_instruction_int_to_err(ira, (IrInstructionIntToErr *)instruction);29699 return ir_analyze_instruction_err_to_int(ira, (IrInstSrcErrToInt *)instruction);
28931 case IrInstructionIdErrToInt:29700 case IrInstSrcIdIntToEnum:
28932 return ir_analyze_instruction_err_to_int(ira, (IrInstructionErrToInt *)instruction);29701 return ir_analyze_instruction_int_to_enum(ira, (IrInstSrcIntToEnum *)instruction);
28933 case IrInstructionIdIntToEnum:29702 case IrInstSrcIdEnumToInt:
28934 return ir_analyze_instruction_int_to_enum(ira, (IrInstructionIntToEnum *)instruction);29703 return ir_analyze_instruction_enum_to_int(ira, (IrInstSrcEnumToInt *)instruction);
28935 case IrInstructionIdEnumToInt:29704 case IrInstSrcIdCheckRuntimeScope:
28936 return ir_analyze_instruction_enum_to_int(ira, (IrInstructionEnumToInt *)instruction);29705 return ir_analyze_instruction_check_runtime_scope(ira, (IrInstSrcCheckRuntimeScope *)instruction);
28937 case IrInstructionIdCheckRuntimeScope:29706 case IrInstSrcIdHasDecl:
28938 return ir_analyze_instruction_check_runtime_scope(ira, (IrInstructionCheckRuntimeScope *)instruction);29707 return ir_analyze_instruction_has_decl(ira, (IrInstSrcHasDecl *)instruction);
28939 case IrInstructionIdHasDecl:29708 case IrInstSrcIdUndeclaredIdent:
28940 return ir_analyze_instruction_has_decl(ira, (IrInstructionHasDecl *)instruction);29709 return ir_analyze_instruction_undeclared_ident(ira, (IrInstSrcUndeclaredIdent *)instruction);
28941 case IrInstructionIdUndeclaredIdent:29710 case IrInstSrcIdAlloca:
28942 return ir_analyze_instruction_undeclared_ident(ira, (IrInstructionUndeclaredIdent *)instruction);
28943 case IrInstructionIdAllocaSrc:
28944 return nullptr;29711 return nullptr;
28945 case IrInstructionIdEndExpr:29712 case IrInstSrcIdEndExpr:
28946 return ir_analyze_instruction_end_expr(ira, (IrInstructionEndExpr *)instruction);29713 return ir_analyze_instruction_end_expr(ira, (IrInstSrcEndExpr *)instruction);
28947 case IrInstructionIdBitCastSrc:29714 case IrInstSrcIdBitCast:
28948 return ir_analyze_instruction_bit_cast_src(ira, (IrInstructionBitCastSrc *)instruction);29715 return ir_analyze_instruction_bit_cast_src(ira, (IrInstSrcBitCast *)instruction);
28949 case IrInstructionIdUnionInitNamedField:29716 case IrInstSrcIdUnionInitNamedField:
28950 return ir_analyze_instruction_union_init_named_field(ira, (IrInstructionUnionInitNamedField *)instruction);29717 return ir_analyze_instruction_union_init_named_field(ira, (IrInstSrcUnionInitNamedField *)instruction);
28951 case IrInstructionIdSuspendBegin:29718 case IrInstSrcIdSuspendBegin:
28952 return ir_analyze_instruction_suspend_begin(ira, (IrInstructionSuspendBegin *)instruction);29719 return ir_analyze_instruction_suspend_begin(ira, (IrInstSrcSuspendBegin *)instruction);
28953 case IrInstructionIdSuspendFinish:29720 case IrInstSrcIdSuspendFinish:
28954 return ir_analyze_instruction_suspend_finish(ira, (IrInstructionSuspendFinish *)instruction);29721 return ir_analyze_instruction_suspend_finish(ira, (IrInstSrcSuspendFinish *)instruction);
28955 case IrInstructionIdResume:29722 case IrInstSrcIdResume:
28956 return ir_analyze_instruction_resume(ira, (IrInstructionResume *)instruction);29723 return ir_analyze_instruction_resume(ira, (IrInstSrcResume *)instruction);
28957 case IrInstructionIdAwaitSrc:29724 case IrInstSrcIdAwait:
28958 return ir_analyze_instruction_await(ira, (IrInstructionAwaitSrc *)instruction);29725 return ir_analyze_instruction_await(ira, (IrInstSrcAwait *)instruction);
28959 case IrInstructionIdSpillBegin:29726 case IrInstSrcIdSpillBegin:
28960 return ir_analyze_instruction_spill_begin(ira, (IrInstructionSpillBegin *)instruction);29727 return ir_analyze_instruction_spill_begin(ira, (IrInstSrcSpillBegin *)instruction);
28961 case IrInstructionIdSpillEnd:29728 case IrInstSrcIdSpillEnd:
28962 return ir_analyze_instruction_spill_end(ira, (IrInstructionSpillEnd *)instruction);29729 return ir_analyze_instruction_spill_end(ira, (IrInstSrcSpillEnd *)instruction);
28963 }29730 }
28964 zig_unreachable();29731 zig_unreachable();
28965}29732}
2896629733
28967// This function attempts to evaluate IR code while doing type checking and other analysis.29734// 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.29735// It emits to a new IrExecutableGen which is partially evaluated IR code.
28969ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_exec,29736ZigType *ir_analyze(CodeGen *codegen, IrExecutableSrc *old_exec, IrExecutableGen *new_exec,
28970 ZigType *expected_type, AstNode *expected_type_source_node)29737 ZigType *expected_type, AstNode *expected_type_source_node)
28971{29738{
28972 assert(old_exec->first_err_trace_msg == nullptr);29739 assert(old_exec->first_err_trace_msg == nullptr);
...@@ -28992,18 +29759,18 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_...@@ -28992,18 +29759,18 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
28992 ira->exec_context.mem_slot_list.items[i] = &vals[i];29759 ira->exec_context.mem_slot_list.items[i] = &vals[i];
28993 }29760 }
2899429761
28995 IrBasicBlock *old_entry_bb = ira->old_irb.exec->basic_block_list.at(0);29762 IrBasicBlockSrc *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);29763 IrBasicBlockGen *new_entry_bb = ir_get_new_bb(ira, old_entry_bb, nullptr);
28997 ir_ref_bb(new_entry_bb);29764 ir_ref_bb_gen(new_entry_bb);
28998 ira->new_irb.current_basic_block = new_entry_bb;29765 ira->new_irb.current_basic_block = new_entry_bb;
28999 ira->old_bb_index = 0;29766 ira->old_bb_index = 0;
2900029767
29001 ir_start_bb(ira, old_entry_bb, nullptr);29768 ir_start_bb(ira, old_entry_bb, nullptr);
2900229769
29003 while (ira->old_bb_index < ira->old_irb.exec->basic_block_list.length) {29770 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)) {
29007 ira->instruction_index += 1;29774 ira->instruction_index += 1;
29008 continue;29775 continue;
29009 }29776 }
...@@ -29012,14 +29779,14 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_...@@ -29012,14 +29779,14 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
29012 fprintf(stderr, "~ ");29779 fprintf(stderr, "~ ");
29013 old_instruction->src();29780 old_instruction->src();
29014 fprintf(stderr, "~ ");29781 fprintf(stderr, "~ ");
29015 ir_print_instruction(codegen, stderr, old_instruction, 0, IrPassSrc);29782 ir_print_inst_src(codegen, stderr, old_instruction, 0);
29016 bool want_break = false;29783 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) {
29018 want_break = true;29785 want_break = true;
29019 } else if (old_instruction->source_node != nullptr) {29786 } else if (old_instruction->base.source_node != nullptr) {
29020 for (size_t i = 0; i < dbg_ir_breakpoints_count; i += 1) {29787 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 &&29788 if (dbg_ir_breakpoints_buf[i].line == old_instruction->base.source_node->line + 1 &&
29022 buf_ends_with_str(old_instruction->source_node->owner->data.structure.root_struct->path,29789 buf_ends_with_str(old_instruction->base.source_node->owner->data.structure.root_struct->path,
29023 dbg_ir_breakpoints_buf[i].src_file))29790 dbg_ir_breakpoints_buf[i].src_file))
29024 {29791 {
29025 want_break = true;29792 want_break = true;
...@@ -29028,9 +29795,9 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_...@@ -29028,9 +29795,9 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
29028 }29795 }
29029 if (want_break) BREAKPOINT;29796 if (want_break) BREAKPOINT;
29030 }29797 }
29031 IrInstruction *new_instruction = ir_analyze_instruction_base(ira, old_instruction);29798 IrInstGen *new_instruction = ir_analyze_instruction_base(ira, old_instruction);
29032 if (new_instruction != nullptr) {29799 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);
29034 old_instruction->child = new_instruction;29801 old_instruction->child = new_instruction;
2903529802
29036 if (type_is_invalid(new_instruction->value->type)) {29803 if (type_is_invalid(new_instruction->value->type)) {
...@@ -29044,19 +29811,19 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_...@@ -29044,19 +29811,19 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
29044 new_exec->first_err_trace_msg = ira->codegen->trace_err;29811 new_exec->first_err_trace_msg = ira->codegen->trace_err;
29045 }29812 }
29046 if (new_exec->first_err_trace_msg != nullptr &&29813 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)
29048 {29815 {
29049 old_instruction->source_node->already_traced_this_node = true;29816 old_instruction->base.source_node->already_traced_this_node = true;
29050 new_exec->first_err_trace_msg = add_error_note(ira->codegen, new_exec->first_err_trace_msg,29817 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"));
29052 }29819 }
29053 return ira->codegen->builtin_types.entry_invalid;29820 return ira->codegen->builtin_types.entry_invalid;
29054 } else if (ira->codegen->verbose_ir) {29821 } else if (ira->codegen->verbose_ir) {
29055 fprintf(stderr, "-> ");29822 fprintf(stderr, "-> ");
29056 if (instr_is_unreachable(new_instruction)) {29823 if (new_instruction->value->type->id == ZigTypeIdUnreachable) {
29057 fprintf(stderr, "(noreturn)\n");29824 fprintf(stderr, "(noreturn)\n");
29058 } else {29825 } else {
29059 ir_print_instruction(codegen, stderr, new_instruction, 0, IrPassGen);29826 ir_print_inst_gen(codegen, stderr, new_instruction, 0);
29060 }29827 }
29061 }29828 }
2906229829
...@@ -29096,204 +29863,279 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_...@@ -29096,204 +29863,279 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
29096 return res_type;29863 return res_type;
29097}29864}
2909829865
29099bool ir_has_side_effects(IrInstruction *instruction) {29866bool ir_inst_gen_has_side_effects(IrInstGen *instruction) {
29100 switch (instruction->id) {29867 switch (instruction->id) {
29101 case IrInstructionIdInvalid:29868 case IrInstGenIdInvalid:
29102 zig_unreachable();29869 zig_unreachable();
29103 case IrInstructionIdBr:29870 case IrInstGenIdBr:
29104 case IrInstructionIdCondBr:29871 case IrInstGenIdCondBr:
29105 case IrInstructionIdSwitchBr:29872 case IrInstGenIdSwitchBr:
29106 case IrInstructionIdDeclVarSrc:29873 case IrInstGenIdDeclVar:
29107 case IrInstructionIdDeclVarGen:29874 case IrInstGenIdStorePtr:
29108 case IrInstructionIdStorePtr:29875 case IrInstGenIdVectorStoreElem:
29109 case IrInstructionIdVectorStoreElem:29876 case IrInstGenIdCall:
29110 case IrInstructionIdCallExtra:29877 case IrInstGenIdReturn:
29111 case IrInstructionIdCallSrc:29878 case IrInstGenIdUnreachable:
29112 case IrInstructionIdCallSrcArgs:29879 case IrInstGenIdFence:
29113 case IrInstructionIdCallGen:29880 case IrInstGenIdMemset:
29114 case IrInstructionIdReturn:29881 case IrInstGenIdMemcpy:
29115 case IrInstructionIdUnreachable:29882 case IrInstGenIdBreakpoint:
29116 case IrInstructionIdSetCold:29883 case IrInstGenIdOverflowOp: // TODO when we support multiple returns this can be side effect free
29117 case IrInstructionIdSetRuntimeSafety:29884 case IrInstGenIdPanic:
29118 case IrInstructionIdSetFloatMode:29885 case IrInstGenIdSaveErrRetAddr:
29119 case IrInstructionIdImport:29886 case IrInstGenIdAtomicRmw:
29120 case IrInstructionIdCompileErr:29887 case IrInstGenIdAtomicStore:
29121 case IrInstructionIdCompileLog:29888 case IrInstGenIdCmpxchg:
29122 case IrInstructionIdCImport:29889 case IrInstGenIdAssertZero:
29123 case IrInstructionIdCInclude:29890 case IrInstGenIdAssertNonNull:
29124 case IrInstructionIdCDefine:29891 case IrInstGenIdResizeSlice:
29125 case IrInstructionIdCUndef:29892 case IrInstGenIdPtrOfArrayToSlice:
29126 case IrInstructionIdFence:29893 case IrInstGenIdSlice:
29127 case IrInstructionIdMemset:29894 case IrInstGenIdOptionalWrap:
29128 case IrInstructionIdMemcpy:29895 case IrInstGenIdVectorToArray:
29129 case IrInstructionIdBreakpoint:29896 case IrInstGenIdSuspendBegin:
29130 case IrInstructionIdOverflowOp: // TODO when we support multiple returns this can be side effect free29897 case IrInstGenIdSuspendFinish:
29131 case IrInstructionIdCheckSwitchProngs:29898 case IrInstGenIdResume:
29132 case IrInstructionIdCheckStatementIsVoid:29899 case IrInstGenIdAwait:
29133 case IrInstructionIdCheckRuntimeScope:29900 case IrInstGenIdSpillBegin:
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:
29161 return true;29901 return true;
2916229902
29163 case IrInstructionIdPhi:29903 case IrInstGenIdPhi:
29164 case IrInstructionIdUnOp:29904 case IrInstGenIdBinOp:
29165 case IrInstructionIdBinOp:29905 case IrInstGenIdConst:
29166 case IrInstructionIdMergeErrSets:29906 case IrInstGenIdCast:
29167 case IrInstructionIdLoadPtr:29907 case IrInstGenIdElemPtr:
29168 case IrInstructionIdConst:29908 case IrInstGenIdVarPtr:
29169 case IrInstructionIdCast:29909 case IrInstGenIdReturnPtr:
29170 case IrInstructionIdContainerInitList:29910 case IrInstGenIdStructFieldPtr:
29171 case IrInstructionIdContainerInitFields:29911 case IrInstGenIdTestNonNull:
29172 case IrInstructionIdUnionInitNamedField:29912 case IrInstGenIdOptionalUnwrapPtr:
29173 case IrInstructionIdFieldPtr:29913 case IrInstGenIdClz:
29174 case IrInstructionIdElemPtr:29914 case IrInstGenIdCtz:
29175 case IrInstructionIdVarPtr:29915 case IrInstGenIdPopCount:
29176 case IrInstructionIdReturnPtr:29916 case IrInstGenIdBswap:
29177 case IrInstructionIdTypeOf:29917 case IrInstGenIdBitReverse:
29178 case IrInstructionIdStructFieldPtr:29918 case IrInstGenIdUnionTag:
29179 case IrInstructionIdArrayType:29919 case IrInstGenIdTruncate:
29180 case IrInstructionIdSliceType:29920 case IrInstGenIdShuffleVector:
29181 case IrInstructionIdAnyFrameType:29921 case IrInstGenIdSplat:
29182 case IrInstructionIdSizeOf:29922 case IrInstGenIdBoolNot:
29183 case IrInstructionIdTestNonNull:29923 case IrInstGenIdReturnAddress:
29184 case IrInstructionIdOptionalUnwrapPtr:29924 case IrInstGenIdFrameAddress:
29185 case IrInstructionIdClz:29925 case IrInstGenIdFrameHandle:
29186 case IrInstructionIdCtz:29926 case IrInstGenIdFrameSize:
29187 case IrInstructionIdPopCount:29927 case IrInstGenIdTestErr:
29188 case IrInstructionIdBswap:29928 case IrInstGenIdPtrCast:
29189 case IrInstructionIdBitReverse:29929 case IrInstGenIdBitCast:
29190 case IrInstructionIdSwitchVar:29930 case IrInstGenIdWidenOrShorten:
29191 case IrInstructionIdSwitchElseVar:29931 case IrInstGenIdPtrToInt:
29192 case IrInstructionIdSwitchTarget:29932 case IrInstGenIdIntToPtr:
29193 case IrInstructionIdUnionTag:29933 case IrInstGenIdIntToEnum:
29194 case IrInstructionIdRef:29934 case IrInstGenIdIntToErr:
29195 case IrInstructionIdEmbedFile:29935 case IrInstGenIdErrToInt:
29196 case IrInstructionIdTruncate:29936 case IrInstGenIdErrName:
29197 case IrInstructionIdIntType:29937 case IrInstGenIdTagName:
29198 case IrInstructionIdVectorType:29938 case IrInstGenIdFieldParentPtr:
29199 case IrInstructionIdShuffleVector:29939 case IrInstGenIdAlignCast:
29200 case IrInstructionIdSplatSrc:29940 case IrInstGenIdErrorReturnTrace:
29201 case IrInstructionIdSplatGen:29941 case IrInstGenIdFloatOp:
29202 case IrInstructionIdBoolNot:29942 case IrInstGenIdMulAdd:
29203 case IrInstructionIdSliceSrc:29943 case IrInstGenIdAtomicLoad:
29204 case IrInstructionIdMemberCount:29944 case IrInstGenIdArrayToVector:
29205 case IrInstructionIdMemberType:29945 case IrInstGenIdAlloca:
29206 case IrInstructionIdMemberName:29946 case IrInstGenIdSpillEnd:
29207 case IrInstructionIdAlignOf:29947 case IrInstGenIdVectorExtractElem:
29208 case IrInstructionIdReturnAddress:29948 case IrInstGenIdBinaryNot:
29209 case IrInstructionIdFrameAddress:29949 case IrInstGenIdNegation:
29210 case IrInstructionIdFrameHandle:29950 case IrInstGenIdNegationWrapping:
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:
29265 return false;29951 return false;
2926629952
29267 case IrInstructionIdAsmSrc:29953 case IrInstGenIdAsm:
29268 {29954 {
29269 IrInstructionAsmSrc *asm_instruction = (IrInstructionAsmSrc *)instruction;29955 IrInstGenAsm *asm_instruction = (IrInstGenAsm *)instruction;
29270 return asm_instruction->has_side_effects;29956 return asm_instruction->has_side_effects;
29271 }29957 }
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:
29274 {30125 {
29275 IrInstructionAsmGen *asm_instruction = (IrInstructionAsmGen *)instruction;30126 IrInstSrcAsm *asm_instruction = (IrInstSrcAsm *)instruction;
29276 return asm_instruction->has_side_effects;30127 return asm_instruction->has_side_effects;
29277 }30128 }
29278 case IrInstructionIdUnwrapErrPayload:30129
30130 case IrInstSrcIdUnwrapErrPayload:
29279 {30131 {
29280 IrInstructionUnwrapErrPayload *unwrap_err_payload_instruction =30132 IrInstSrcUnwrapErrPayload *unwrap_err_payload_instruction =
29281 (IrInstructionUnwrapErrPayload *)instruction;30133 (IrInstSrcUnwrapErrPayload *)instruction;
29282 return unwrap_err_payload_instruction->safety_check_on ||30134 return unwrap_err_payload_instruction->safety_check_on ||
29283 unwrap_err_payload_instruction->initializing;30135 unwrap_err_payload_instruction->initializing;
29284 }30136 }
29285 case IrInstructionIdUnwrapErrCode:30137 case IrInstSrcIdUnwrapErrCode:
29286 return reinterpret_cast<IrInstructionUnwrapErrCode *>(instruction)->initializing;30138 return reinterpret_cast<IrInstSrcUnwrapErrCode *>(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;
29297 }30139 }
29298 zig_unreachable();30140 zig_unreachable();
29299}30141}
...@@ -29327,14 +30169,14 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La...@@ -29327,14 +30169,14 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La
29327 param_info->type = nullptr;30169 param_info->type = nullptr;
29328 return get_generic_fn_type(ira->codegen, &fn_type_id);30170 return get_generic_fn_type(ira->codegen, &fn_type_id);
29329 } else {30171 } 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];
29331 ZigType *param_type = ir_resolve_type(ira, param_type_inst);30173 ZigType *param_type = ir_resolve_type(ira, param_type_inst);
29332 if (type_is_invalid(param_type))30174 if (type_is_invalid(param_type))
29333 return nullptr;30175 return nullptr;
29334 switch (type_requires_comptime(ira->codegen, param_type)) {30176 switch (type_requires_comptime(ira->codegen, param_type)) {
29335 case ReqCompTimeYes:30177 case ReqCompTimeYes:
29336 if (!calling_convention_allows_zig_types(fn_type_id.cc)) {30178 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,
29338 buf_sprintf("parameter of type '%s' not allowed in function with calling convention '%s'",30180 buf_sprintf("parameter of type '%s' not allowed in function with calling convention '%s'",
29339 buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc)));30181 buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc)));
29340 return nullptr;30182 return nullptr;
...@@ -29352,7 +30194,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La...@@ -29352,7 +30194,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La
29352 if ((err = type_has_bits2(ira->codegen, param_type, &has_bits)))30194 if ((err = type_has_bits2(ira->codegen, param_type, &has_bits)))
29353 return nullptr;30195 return nullptr;
29354 if (!has_bits) {30196 if (!has_bits) {
29355 ir_add_error(ira, param_type_inst,30197 ir_add_error(ira, &param_type_inst->base,
29356 buf_sprintf("parameter of type '%s' has 0 bits; not allowed in function with calling convention '%s'",30198 buf_sprintf("parameter of type '%s' has 0 bits; not allowed in function with calling convention '%s'",
29357 buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc)));30199 buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc)));
29358 return nullptr;30200 return nullptr;
...@@ -29371,7 +30213,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La...@@ -29371,7 +30213,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La
29371 if (type_is_invalid(fn_type_id.return_type))30213 if (type_is_invalid(fn_type_id.return_type))
29372 return nullptr;30214 return nullptr;
29373 if (fn_type_id.return_type->id == ZigTypeIdOpaque) {30215 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"));
29375 return nullptr;30217 return nullptr;
29376 }30218 }
2937730219
...@@ -29403,7 +30245,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {...@@ -29403,7 +30245,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
29403 case ZigTypeIdBoundFn:30245 case ZigTypeIdBoundFn:
29404 case ZigTypeIdVoid:30246 case ZigTypeIdVoid:
29405 case ZigTypeIdOpaque:30247 case ZigTypeIdOpaque:
29406 ir_add_error(ira, lazy_align_of->target_type,30248 ir_add_error(ira, &lazy_align_of->target_type->base,
29407 buf_sprintf("no align available for type '%s'",30249 buf_sprintf("no align available for type '%s'",
29408 buf_ptr(&lazy_align_of->target_type->value->data.x_type->name)));30250 buf_ptr(&lazy_align_of->target_type->value->data.x_type->name)));
29409 return ErrorSemanticAnalyzeFail;30251 return ErrorSemanticAnalyzeFail;
...@@ -29453,7 +30295,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {...@@ -29453,7 +30295,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
29453 case ZigTypeIdNull:30295 case ZigTypeIdNull:
29454 case ZigTypeIdBoundFn:30296 case ZigTypeIdBoundFn:
29455 case ZigTypeIdOpaque:30297 case ZigTypeIdOpaque:
29456 ir_add_error(ira, lazy_size_of->target_type,30298 ir_add_error(ira, &lazy_size_of->target_type->base,
29457 buf_sprintf("no size available for type '%s'",30299 buf_sprintf("no size available for type '%s'",
29458 buf_ptr(&lazy_size_of->target_type->value->data.x_type->name)));30300 buf_ptr(&lazy_size_of->target_type->value->data.x_type->name)));
29459 return ErrorSemanticAnalyzeFail;30301 return ErrorSemanticAnalyzeFail;
...@@ -29511,7 +30353,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {...@@ -29511,7 +30353,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
29511 if (lazy_slice_type->sentinel != nullptr) {30353 if (lazy_slice_type->sentinel != nullptr) {
29512 if (type_is_invalid(lazy_slice_type->sentinel->value->type))30354 if (type_is_invalid(lazy_slice_type->sentinel->value->type))
29513 return ErrorSemanticAnalyzeFail;30355 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);
29515 if (type_is_invalid(sentinel->value->type))30357 if (type_is_invalid(sentinel->value->type))
29516 return ErrorSemanticAnalyzeFail;30358 return ErrorSemanticAnalyzeFail;
29517 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);30359 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);
...@@ -29534,7 +30376,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {...@@ -29534,7 +30376,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
29534 case ZigTypeIdUndefined:30376 case ZigTypeIdUndefined:
29535 case ZigTypeIdNull:30377 case ZigTypeIdNull:
29536 case ZigTypeIdOpaque:30378 case ZigTypeIdOpaque:
29537 ir_add_error(ira, lazy_slice_type->elem_type,30379 ir_add_error(ira, &lazy_slice_type->elem_type->base,
29538 buf_sprintf("slice of type '%s' not allowed", buf_ptr(&elem_type->name)));30380 buf_sprintf("slice of type '%s' not allowed", buf_ptr(&elem_type->name)));
29539 return ErrorSemanticAnalyzeFail;30381 return ErrorSemanticAnalyzeFail;
29540 case ZigTypeIdMetaType:30382 case ZigTypeIdMetaType:
...@@ -29590,7 +30432,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {...@@ -29590,7 +30432,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
29590 if (lazy_ptr_type->sentinel != nullptr) {30432 if (lazy_ptr_type->sentinel != nullptr) {
29591 if (type_is_invalid(lazy_ptr_type->sentinel->value->type))30433 if (type_is_invalid(lazy_ptr_type->sentinel->value->type))
29592 return ErrorSemanticAnalyzeFail;30434 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);
29594 if (type_is_invalid(sentinel->value->type))30436 if (type_is_invalid(sentinel->value->type))
29595 return ErrorSemanticAnalyzeFail;30437 return ErrorSemanticAnalyzeFail;
29596 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);30438 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);
...@@ -29607,11 +30449,11 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {...@@ -29607,11 +30449,11 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
29607 }30449 }
2960830450
29609 if (elem_type->id == ZigTypeIdUnreachable) {30451 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,
29611 buf_create_from_str("pointer to noreturn not allowed"));30453 buf_create_from_str("pointer to noreturn not allowed"));
29612 return ErrorSemanticAnalyzeFail;30454 return ErrorSemanticAnalyzeFail;
29613 } else if (elem_type->id == ZigTypeIdOpaque && lazy_ptr_type->ptr_len == PtrLenUnknown) {30455 } 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,
29615 buf_create_from_str("unknown-length pointer to opaque"));30457 buf_create_from_str("unknown-length pointer to opaque"));
29616 return ErrorSemanticAnalyzeFail;30458 return ErrorSemanticAnalyzeFail;
29617 } else if (lazy_ptr_type->ptr_len == PtrLenC) {30459 } else if (lazy_ptr_type->ptr_len == PtrLenC) {
...@@ -29619,16 +30461,16 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {...@@ -29619,16 +30461,16 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
29619 if ((err = type_allowed_in_extern(ira->codegen, elem_type, &ok_type)))30461 if ((err = type_allowed_in_extern(ira->codegen, elem_type, &ok_type)))
29620 return err;30462 return err;
29621 if (!ok_type) {30463 if (!ok_type) {
29622 ir_add_error(ira, lazy_ptr_type->elem_type,30464 ir_add_error(ira, &lazy_ptr_type->elem_type->base,
29623 buf_sprintf("C pointers cannot point to non-C-ABI-compatible type '%s'",30465 buf_sprintf("C pointers cannot point to non-C-ABI-compatible type '%s'",
29624 buf_ptr(&elem_type->name)));30466 buf_ptr(&elem_type->name)));
29625 return ErrorSemanticAnalyzeFail;30467 return ErrorSemanticAnalyzeFail;
29626 } else if (elem_type->id == ZigTypeIdOpaque) {30468 } 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,
29628 buf_sprintf("C pointers cannot point opaque types"));30470 buf_sprintf("C pointers cannot point opaque types"));
29629 return ErrorSemanticAnalyzeFail;30471 return ErrorSemanticAnalyzeFail;
29630 } else if (lazy_ptr_type->is_allowzero) {30472 } 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,
29632 buf_sprintf("C pointers always allow address zero"));30474 buf_sprintf("C pointers always allow address zero"));
29633 return ErrorSemanticAnalyzeFail;30475 return ErrorSemanticAnalyzeFail;
29634 }30476 }
...@@ -29666,7 +30508,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {...@@ -29666,7 +30508,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
29666 case ZigTypeIdUndefined:30508 case ZigTypeIdUndefined:
29667 case ZigTypeIdNull:30509 case ZigTypeIdNull:
29668 case ZigTypeIdOpaque:30510 case ZigTypeIdOpaque:
29669 ir_add_error(ira, lazy_array_type->elem_type,30511 ir_add_error(ira, &lazy_array_type->elem_type->base,
29670 buf_sprintf("array of type '%s' not allowed",30512 buf_sprintf("array of type '%s' not allowed",
29671 buf_ptr(&elem_type->name)));30513 buf_ptr(&elem_type->name)));
29672 return ErrorSemanticAnalyzeFail;30514 return ErrorSemanticAnalyzeFail;
...@@ -29701,7 +30543,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {...@@ -29701,7 +30543,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
29701 if (lazy_array_type->sentinel != nullptr) {30543 if (lazy_array_type->sentinel != nullptr) {
29702 if (type_is_invalid(lazy_array_type->sentinel->value->type))30544 if (type_is_invalid(lazy_array_type->sentinel->value->type))
29703 return ErrorSemanticAnalyzeFail;30545 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);
29705 if (type_is_invalid(sentinel->value->type))30547 if (type_is_invalid(sentinel->value->type))
29706 return ErrorSemanticAnalyzeFail;30548 return ErrorSemanticAnalyzeFail;
29707 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);30549 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);
...@@ -29725,7 +30567,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {...@@ -29725,7 +30567,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
29725 return ErrorSemanticAnalyzeFail;30567 return ErrorSemanticAnalyzeFail;
2972630568
29727 if (payload_type->id == ZigTypeIdOpaque || payload_type->id == ZigTypeIdUnreachable) {30569 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,
29729 buf_sprintf("type '%s' cannot be optional", buf_ptr(&payload_type->name)));30571 buf_sprintf("type '%s' cannot be optional", buf_ptr(&payload_type->name)));
29730 return ErrorSemanticAnalyzeFail;30572 return ErrorSemanticAnalyzeFail;
29731 }30573 }
...@@ -29767,7 +30609,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {...@@ -29767,7 +30609,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
29767 return ErrorSemanticAnalyzeFail;30609 return ErrorSemanticAnalyzeFail;
2976830610
29769 if (err_set_type->id != ZigTypeIdErrorSet) {30611 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,
29771 buf_sprintf("expected error set type, found type '%s'",30613 buf_sprintf("expected error set type, found type '%s'",
29772 buf_ptr(&err_set_type->name)));30614 buf_ptr(&err_set_type->name)));
29773 return ErrorSemanticAnalyzeFail;30615 return ErrorSemanticAnalyzeFail;
...@@ -29803,8 +30645,8 @@ Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ZigValue *val) {...@@ -29803,8 +30645,8 @@ Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ZigValue *val) {
29803 return ErrorNone;30645 return ErrorNone;
29804}30646}
2980530647
29806void IrInstruction::src() {30648void IrInst::src() {
29807 IrInstruction *inst = this;30649 IrInst *inst = this;
29808 if (inst->source_node != nullptr) {30650 if (inst->source_node != nullptr) {
29809 inst->source_node->src();30651 inst->source_node->src();
29810 } else {30652 } else {
...@@ -29812,26 +30654,45 @@ void IrInstruction::src() {...@@ -29812,26 +30654,45 @@ void IrInstruction::src() {
29812 }30654 }
29813}30655}
2981430656
29815void IrInstruction::dump() {30657void IrInst::dump() {
29816 IrInstruction *inst = this;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;
29817 inst->src();30672 inst->src();
29818 IrPass pass = (inst->child == nullptr) ? IrPassGen : IrPassSrc;30673 if (inst->base.scope == nullptr) {
29819 if (inst->scope == nullptr) {
29820 fprintf(stderr, "(null scope)\n");30674 fprintf(stderr, "(null scope)\n");
29821 } else {30675 } else {
29822 ir_print_instruction(inst->scope->codegen, stderr, inst, 0, pass);30676 ir_print_inst_src(inst->base.scope->codegen, stderr, inst, 0);
29823 if (pass == IrPassSrc) {30677 fprintf(stderr, "-> ");
29824 fprintf(stderr, "-> ");30678 ir_print_inst_gen(inst->base.scope->codegen, stderr, inst->child, 0);
29825 ir_print_instruction(inst->scope->codegen, stderr, inst->child, 0, IrPassGen);30679 }
29826 }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);
29827 }30688 }
29828}30689}
2982930690
29830void IrAnalyze::dump() {30691void 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);
29832 if (this->new_irb.current_basic_block != nullptr) {30693 if (this->new_irb.current_basic_block != nullptr) {
29833 fprintf(stderr, "Current basic block:\n");30694 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);
29835 }30696 }
29836}30697}
2983730698
src/ir.hpp+10-10
...@@ -10,33 +10,33 @@...@@ -10,33 +10,33 @@
1010
11#include "all_types.hpp"11#include "all_types.hpp"
1212
13enum IrPass {13bool ir_gen(CodeGen *g, AstNode *node, Scope *scope, IrExecutableSrc *ir_executable);
14 IrPassSrc,
15 IrPassGen,
16};
17
18bool ir_gen(CodeGen *g, AstNode *node, Scope *scope, IrExecutable *ir_executable);
19bool ir_gen_fn(CodeGen *g, ZigFn *fn_entry);14bool 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
21ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,19ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
22 ZigType *expected_type, size_t *backward_branch_count, size_t *backward_branch_quota,20 ZigType *expected_type, size_t *backward_branch_count, size_t *backward_branch_quota,
23 ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,21 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
26Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ZigValue *val);24Error 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,
29 ZigType *expected_type, AstNode *expected_type_source_node);27 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
33struct IrAnalyze;32struct IrAnalyze;
34ZigValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ZigValue *const_val,33ZigValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ZigValue *const_val,
35 AstNode *source_node);34 AstNode *source_node);
36const char *float_op_to_name(BuiltinFnId op);
3735
38// for debugging purposes36// for debugging purposes
39void dbg_ir_break(const char *src_file, uint32_t line);37void dbg_ir_break(const char *src_file, uint32_t line);
40void dbg_ir_clear(void);38void dbg_ir_clear(void);
4139
40void destroy_instruction_gen(IrInstGen *inst);
41
42#endif42#endif
src/ir_print.cpp+1998-1281
...@@ -10,19 +10,35 @@...@@ -10,19 +10,35 @@
10#include "ir_print.hpp"10#include "ir_print.hpp"
11#include "os.hpp"11#include "os.hpp"
1212
13static uint32_t hash_instruction_ptr(IrInstruction* instruction) {13static uint32_t hash_inst_src_ptr(IrInstSrc* instruction) {
14 return (uint32_t)(uintptr_t)instruction;14 return (uint32_t)(uintptr_t)instruction;
15}15}
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) {
18 return a == b;22 return a == b;
19}23}
2024
21using InstructionSet = HashMap<IrInstruction*, uint8_t, hash_instruction_ptr, instruction_ptr_equal>;25static bool inst_gen_ptr_eql(IrInstGen* a, IrInstGen* b) {
22using InstructionList = ZigList<IrInstruction*>;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 {41struct IrPrintGen {
25 IrPass pass;
26 CodeGen *codegen;42 CodeGen *codegen;
27 FILE *f;43 FILE *f;
28 int indent;44 int indent;
...@@ -32,417 +48,590 @@ struct IrPrint {...@@ -32,417 +48,590 @@ struct IrPrint {
32 // present in the instruction list. Thus we track which instructions48 // present in the instruction list. Thus we track which instructions
33 // are printed (per executable) and after each pass 2 instruction those49 // are printed (per executable) and after each pass 2 instruction those
34 // var instructions are rendered in a trailing fashion.50 // var instructions are rendered in a trailing fashion.
35 InstructionSet printed;51 InstSetGen printed;
36 InstructionList pending;52 InstListGen pending;
37};53};
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) {
42 switch (id) {59 switch (id) {
43 case IrInstructionIdInvalid:60 case IrInstSrcIdInvalid:
44 return "Invalid";61 return "SrcInvalid";
45 case IrInstructionIdShuffleVector:62 case IrInstSrcIdShuffleVector:
46 return "Shuffle";63 return "SrcShuffle";
47 case IrInstructionIdSplatSrc:64 case IrInstSrcIdSplat:
48 return "SplatSrc";65 return "SrcSplat";
49 case IrInstructionIdSplatGen:66 case IrInstSrcIdDeclVar:
50 return "SplatGen";67 return "SrcDeclVar";
51 case IrInstructionIdDeclVarSrc:68 case IrInstSrcIdBr:
52 return "DeclVarSrc";69 return "SrcBr";
53 case IrInstructionIdDeclVarGen:70 case IrInstSrcIdCondBr:
54 return "DeclVarGen";71 return "SrcCondBr";
55 case IrInstructionIdBr:72 case IrInstSrcIdSwitchBr:
56 return "Br";73 return "SrcSwitchBr";
57 case IrInstructionIdCondBr:74 case IrInstSrcIdSwitchVar:
58 return "CondBr";75 return "SrcSwitchVar";
59 case IrInstructionIdSwitchBr:76 case IrInstSrcIdSwitchElseVar:
60 return "SwitchBr";77 return "SrcSwitchElseVar";
61 case IrInstructionIdSwitchVar:78 case IrInstSrcIdSwitchTarget:
62 return "SwitchVar";79 return "SrcSwitchTarget";
63 case IrInstructionIdSwitchElseVar:80 case IrInstSrcIdPhi:
64 return "SwitchElseVar";81 return "SrcPhi";
65 case IrInstructionIdSwitchTarget:82 case IrInstSrcIdUnOp:
66 return "SwitchTarget";83 return "SrcUnOp";
67 case IrInstructionIdPhi:84 case IrInstSrcIdBinOp:
68 return "Phi";85 return "SrcBinOp";
69 case IrInstructionIdUnOp:86 case IrInstSrcIdMergeErrSets:
70 return "UnOp";87 return "SrcMergeErrSets";
71 case IrInstructionIdBinOp:88 case IrInstSrcIdLoadPtr:
72 return "BinOp";89 return "SrcLoadPtr";
73 case IrInstructionIdMergeErrSets:90 case IrInstSrcIdStorePtr:
74 return "MergeErrSets";91 return "SrcStorePtr";
75 case IrInstructionIdLoadPtr:92 case IrInstSrcIdFieldPtr:
76 return "LoadPtr";93 return "SrcFieldPtr";
77 case IrInstructionIdLoadPtrGen:94 case IrInstSrcIdElemPtr:
78 return "LoadPtrGen";95 return "SrcElemPtr";
79 case IrInstructionIdStorePtr:96 case IrInstSrcIdVarPtr:
80 return "StorePtr";97 return "SrcVarPtr";
81 case IrInstructionIdVectorStoreElem:98 case IrInstSrcIdCallExtra:
82 return "VectorStoreElem";99 return "SrcCallExtra";
83 case IrInstructionIdFieldPtr:100 case IrInstSrcIdCall:
84 return "FieldPtr";101 return "SrcCall";
85 case IrInstructionIdStructFieldPtr:102 case IrInstSrcIdCallArgs:
86 return "StructFieldPtr";103 return "SrcCallArgs";
87 case IrInstructionIdUnionFieldPtr:104 case IrInstSrcIdConst:
88 return "UnionFieldPtr";105 return "SrcConst";
89 case IrInstructionIdElemPtr:106 case IrInstSrcIdReturn:
90 return "ElemPtr";107 return "SrcReturn";
91 case IrInstructionIdVarPtr:108 case IrInstSrcIdContainerInitList:
92 return "VarPtr";109 return "SrcContainerInitList";
93 case IrInstructionIdReturnPtr:110 case IrInstSrcIdContainerInitFields:
94 return "ReturnPtr";111 return "SrcContainerInitFields";
95 case IrInstructionIdCallExtra:112 case IrInstSrcIdUnreachable:
96 return "CallExtra";113 return "SrcUnreachable";
97 case IrInstructionIdCallSrc:114 case IrInstSrcIdTypeOf:
98 return "CallSrc";115 return "SrcTypeOf";
99 case IrInstructionIdCallSrcArgs:116 case IrInstSrcIdSetCold:
100 return "CallSrcArgs";117 return "SrcSetCold";
101 case IrInstructionIdCallGen:118 case IrInstSrcIdSetRuntimeSafety:
102 return "CallGen";119 return "SrcSetRuntimeSafety";
103 case IrInstructionIdConst:120 case IrInstSrcIdSetFloatMode:
104 return "Const";121 return "SrcSetFloatMode";
105 case IrInstructionIdReturn:122 case IrInstSrcIdArrayType:
106 return "Return";123 return "SrcArrayType";
107 case IrInstructionIdCast:124 case IrInstSrcIdAnyFrameType:
108 return "Cast";125 return "SrcAnyFrameType";
109 case IrInstructionIdResizeSlice:126 case IrInstSrcIdSliceType:
110 return "ResizeSlice";127 return "SrcSliceType";
111 case IrInstructionIdContainerInitList:128 case IrInstSrcIdAsm:
112 return "ContainerInitList";129 return "SrcAsm";
113 case IrInstructionIdContainerInitFields:130 case IrInstSrcIdSizeOf:
114 return "ContainerInitFields";131 return "SrcSizeOf";
115 case IrInstructionIdUnreachable:132 case IrInstSrcIdTestNonNull:
116 return "Unreachable";133 return "SrcTestNonNull";
117 case IrInstructionIdTypeOf:134 case IrInstSrcIdOptionalUnwrapPtr:
118 return "TypeOf";135 return "SrcOptionalUnwrapPtr";
119 case IrInstructionIdSetCold:136 case IrInstSrcIdClz:
120 return "SetCold";137 return "SrcClz";
121 case IrInstructionIdSetRuntimeSafety:138 case IrInstSrcIdCtz:
122 return "SetRuntimeSafety";139 return "SrcCtz";
123 case IrInstructionIdSetFloatMode:140 case IrInstSrcIdPopCount:
124 return "SetFloatMode";141 return "SrcPopCount";
125 case IrInstructionIdArrayType:142 case IrInstSrcIdBswap:
126 return "ArrayType";143 return "SrcBswap";
127 case IrInstructionIdAnyFrameType:144 case IrInstSrcIdBitReverse:
128 return "AnyFrameType";145 return "SrcBitReverse";
129 case IrInstructionIdSliceType:146 case IrInstSrcIdImport:
130 return "SliceType";147 return "SrcImport";
131 case IrInstructionIdAsmSrc:148 case IrInstSrcIdCImport:
132 return "AsmSrc";149 return "SrcCImport";
133 case IrInstructionIdAsmGen:150 case IrInstSrcIdCInclude:
134 return "AsmGen";151 return "SrcCInclude";
135 case IrInstructionIdSizeOf:152 case IrInstSrcIdCDefine:
136 return "SizeOf";153 return "SrcCDefine";
137 case IrInstructionIdTestNonNull:154 case IrInstSrcIdCUndef:
138 return "TestNonNull";155 return "SrcCUndef";
139 case IrInstructionIdOptionalUnwrapPtr:156 case IrInstSrcIdRef:
140 return "OptionalUnwrapPtr";157 return "SrcRef";
141 case IrInstructionIdOptionalWrap:158 case IrInstSrcIdCompileErr:
142 return "OptionalWrap";159 return "SrcCompileErr";
143 case IrInstructionIdUnionTag:160 case IrInstSrcIdCompileLog:
144 return "UnionTag";161 return "SrcCompileLog";
145 case IrInstructionIdClz:162 case IrInstSrcIdErrName:
146 return "Clz";163 return "SrcErrName";
147 case IrInstructionIdCtz:164 case IrInstSrcIdEmbedFile:
148 return "Ctz";165 return "SrcEmbedFile";
149 case IrInstructionIdPopCount:166 case IrInstSrcIdCmpxchg:
150 return "PopCount";167 return "SrcCmpxchg";
151 case IrInstructionIdBswap:168 case IrInstSrcIdFence:
152 return "Bswap";169 return "SrcFence";
153 case IrInstructionIdBitReverse:170 case IrInstSrcIdTruncate:
154 return "BitReverse";171 return "SrcTruncate";
155 case IrInstructionIdImport:172 case IrInstSrcIdIntCast:
156 return "Import";173 return "SrcIntCast";
157 case IrInstructionIdCImport:174 case IrInstSrcIdFloatCast:
158 return "CImport";175 return "SrcFloatCast";
159 case IrInstructionIdCInclude:176 case IrInstSrcIdIntToFloat:
160 return "CInclude";177 return "SrcIntToFloat";
161 case IrInstructionIdCDefine:178 case IrInstSrcIdFloatToInt:
162 return "CDefine";179 return "SrcFloatToInt";
163 case IrInstructionIdCUndef:180 case IrInstSrcIdBoolToInt:
164 return "CUndef";181 return "SrcBoolToInt";
165 case IrInstructionIdRef:182 case IrInstSrcIdIntType:
166 return "Ref";183 return "SrcIntType";
167 case IrInstructionIdRefGen:184 case IrInstSrcIdVectorType:
168 return "RefGen";185 return "SrcVectorType";
169 case IrInstructionIdCompileErr:186 case IrInstSrcIdBoolNot:
170 return "CompileErr";187 return "SrcBoolNot";
171 case IrInstructionIdCompileLog:188 case IrInstSrcIdMemset:
172 return "CompileLog";189 return "SrcMemset";
173 case IrInstructionIdErrName:190 case IrInstSrcIdMemcpy:
174 return "ErrName";191 return "SrcMemcpy";
175 case IrInstructionIdEmbedFile:192 case IrInstSrcIdSlice:
176 return "EmbedFile";193 return "SrcSlice";
177 case IrInstructionIdCmpxchgSrc:194 case IrInstSrcIdMemberCount:
178 return "CmpxchgSrc";195 return "SrcMemberCount";
179 case IrInstructionIdCmpxchgGen:196 case IrInstSrcIdMemberType:
180 return "CmpxchgGen";197 return "SrcMemberType";
181 case IrInstructionIdFence:198 case IrInstSrcIdMemberName:
182 return "Fence";199 return "SrcMemberName";
183 case IrInstructionIdTruncate:200 case IrInstSrcIdBreakpoint:
184 return "Truncate";201 return "SrcBreakpoint";
185 case IrInstructionIdIntCast:202 case IrInstSrcIdReturnAddress:
186 return "IntCast";203 return "SrcReturnAddress";
187 case IrInstructionIdFloatCast:204 case IrInstSrcIdFrameAddress:
188 return "FloatCast";205 return "SrcFrameAddress";
189 case IrInstructionIdIntToFloat:206 case IrInstSrcIdFrameHandle:
190 return "IntToFloat";207 return "SrcFrameHandle";
191 case IrInstructionIdFloatToInt:208 case IrInstSrcIdFrameType:
192 return "FloatToInt";209 return "SrcFrameType";
193 case IrInstructionIdBoolToInt:210 case IrInstSrcIdFrameSize:
194 return "BoolToInt";211 return "SrcFrameSize";
195 case IrInstructionIdIntType:212 case IrInstSrcIdAlignOf:
196 return "IntType";213 return "SrcAlignOf";
197 case IrInstructionIdVectorType:214 case IrInstSrcIdOverflowOp:
198 return "VectorType";215 return "SrcOverflowOp";
199 case IrInstructionIdBoolNot:216 case IrInstSrcIdTestErr:
200 return "BoolNot";217 return "SrcTestErr";
201 case IrInstructionIdMemset:218 case IrInstSrcIdMulAdd:
202 return "Memset";219 return "SrcMulAdd";
203 case IrInstructionIdMemcpy:220 case IrInstSrcIdFloatOp:
204 return "Memcpy";221 return "SrcFloatOp";
205 case IrInstructionIdSliceSrc:222 case IrInstSrcIdUnwrapErrCode:
206 return "SliceSrc";223 return "SrcUnwrapErrCode";
207 case IrInstructionIdSliceGen:224 case IrInstSrcIdUnwrapErrPayload:
208 return "SliceGen";225 return "SrcUnwrapErrPayload";
209 case IrInstructionIdMemberCount:226 case IrInstSrcIdFnProto:
210 return "MemberCount";227 return "SrcFnProto";
211 case IrInstructionIdMemberType:228 case IrInstSrcIdTestComptime:
212 return "MemberType";229 return "SrcTestComptime";
213 case IrInstructionIdMemberName:230 case IrInstSrcIdPtrCast:
214 return "MemberName";231 return "SrcPtrCast";
215 case IrInstructionIdBreakpoint:232 case IrInstSrcIdBitCast:
216 return "Breakpoint";233 return "SrcBitCast";
217 case IrInstructionIdReturnAddress:234 case IrInstSrcIdIntToPtr:
218 return "ReturnAddress";235 return "SrcIntToPtr";
219 case IrInstructionIdFrameAddress:236 case IrInstSrcIdPtrToInt:
220 return "FrameAddress";237 return "SrcPtrToInt";
221 case IrInstructionIdFrameHandle:238 case IrInstSrcIdIntToEnum:
222 return "FrameHandle";239 return "SrcIntToEnum";
223 case IrInstructionIdFrameType:240 case IrInstSrcIdEnumToInt:
224 return "FrameType";241 return "SrcEnumToInt";
225 case IrInstructionIdFrameSizeSrc:242 case IrInstSrcIdIntToErr:
226 return "FrameSizeSrc";243 return "SrcIntToErr";
227 case IrInstructionIdFrameSizeGen:244 case IrInstSrcIdErrToInt:
228 return "FrameSizeGen";245 return "SrcErrToInt";
229 case IrInstructionIdAlignOf:246 case IrInstSrcIdCheckSwitchProngs:
230 return "AlignOf";247 return "SrcCheckSwitchProngs";
231 case IrInstructionIdOverflowOp:248 case IrInstSrcIdCheckStatementIsVoid:
232 return "OverflowOp";249 return "SrcCheckStatementIsVoid";
233 case IrInstructionIdTestErrSrc:250 case IrInstSrcIdTypeName:
234 return "TestErrSrc";251 return "SrcTypeName";
235 case IrInstructionIdTestErrGen:252 case IrInstSrcIdDeclRef:
236 return "TestErrGen";253 return "SrcDeclRef";
237 case IrInstructionIdMulAdd:254 case IrInstSrcIdPanic:
238 return "MulAdd";255 return "SrcPanic";
239 case IrInstructionIdFloatOp:256 case IrInstSrcIdTagName:
240 return "FloatOp";257 return "SrcTagName";
241 case IrInstructionIdUnwrapErrCode:258 case IrInstSrcIdTagType:
242 return "UnwrapErrCode";259 return "SrcTagType";
243 case IrInstructionIdUnwrapErrPayload:260 case IrInstSrcIdFieldParentPtr:
244 return "UnwrapErrPayload";261 return "SrcFieldParentPtr";
245 case IrInstructionIdErrWrapCode:262 case IrInstSrcIdByteOffsetOf:
246 return "ErrWrapCode";263 return "SrcByteOffsetOf";
247 case IrInstructionIdErrWrapPayload:264 case IrInstSrcIdBitOffsetOf:
248 return "ErrWrapPayload";265 return "SrcBitOffsetOf";
249 case IrInstructionIdFnProto:266 case IrInstSrcIdTypeInfo:
250 return "FnProto";267 return "SrcTypeInfo";
251 case IrInstructionIdTestComptime:268 case IrInstSrcIdType:
252 return "TestComptime";269 return "SrcType";
253 case IrInstructionIdPtrCastSrc:270 case IrInstSrcIdHasField:
254 return "PtrCastSrc";271 return "SrcHasField";
255 case IrInstructionIdPtrCastGen:272 case IrInstSrcIdTypeId:
256 return "PtrCastGen";273 return "SrcTypeId";
257 case IrInstructionIdBitCastSrc:274 case IrInstSrcIdSetEvalBranchQuota:
258 return "BitCastSrc";275 return "SrcSetEvalBranchQuota";
259 case IrInstructionIdBitCastGen:276 case IrInstSrcIdPtrType:
260 return "BitCastGen";277 return "SrcPtrType";
261 case IrInstructionIdWidenOrShorten:278 case IrInstSrcIdAlignCast:
262 return "WidenOrShorten";279 return "SrcAlignCast";
263 case IrInstructionIdIntToPtr:280 case IrInstSrcIdImplicitCast:
264 return "IntToPtr";281 return "SrcImplicitCast";
265 case IrInstructionIdPtrToInt:282 case IrInstSrcIdResolveResult:
266 return "PtrToInt";283 return "SrcResolveResult";
267 case IrInstructionIdIntToEnum:284 case IrInstSrcIdResetResult:
268 return "IntToEnum";285 return "SrcResetResult";
269 case IrInstructionIdEnumToInt:286 case IrInstSrcIdOpaqueType:
270 return "EnumToInt";287 return "SrcOpaqueType";
271 case IrInstructionIdIntToErr:288 case IrInstSrcIdSetAlignStack:
272 return "IntToErr";289 return "SrcSetAlignStack";
273 case IrInstructionIdErrToInt:290 case IrInstSrcIdArgType:
274 return "ErrToInt";291 return "SrcArgType";
275 case IrInstructionIdCheckSwitchProngs:292 case IrInstSrcIdExport:
276 return "CheckSwitchProngs";293 return "SrcExport";
277 case IrInstructionIdCheckStatementIsVoid:294 case IrInstSrcIdErrorReturnTrace:
278 return "CheckStatementIsVoid";295 return "SrcErrorReturnTrace";
279 case IrInstructionIdTypeName:296 case IrInstSrcIdErrorUnion:
280 return "TypeName";297 return "SrcErrorUnion";
281 case IrInstructionIdDeclRef:298 case IrInstSrcIdAtomicRmw:
282 return "DeclRef";299 return "SrcAtomicRmw";
283 case IrInstructionIdPanic:300 case IrInstSrcIdAtomicLoad:
284 return "Panic";301 return "SrcAtomicLoad";
285 case IrInstructionIdTagName:302 case IrInstSrcIdAtomicStore:
286 return "TagName";303 return "SrcAtomicStore";
287 case IrInstructionIdTagType:304 case IrInstSrcIdSaveErrRetAddr:
288 return "TagType";305 return "SrcSaveErrRetAddr";
289 case IrInstructionIdFieldParentPtr:306 case IrInstSrcIdAddImplicitReturnType:
290 return "FieldParentPtr";307 return "SrcAddImplicitReturnType";
291 case IrInstructionIdByteOffsetOf:308 case IrInstSrcIdErrSetCast:
292 return "ByteOffsetOf";309 return "SrcErrSetCast";
293 case IrInstructionIdBitOffsetOf:310 case IrInstSrcIdToBytes:
294 return "BitOffsetOf";311 return "SrcToBytes";
295 case IrInstructionIdTypeInfo:312 case IrInstSrcIdFromBytes:
296 return "TypeInfo";313 return "SrcFromBytes";
297 case IrInstructionIdType:314 case IrInstSrcIdCheckRuntimeScope:
298 return "Type";315 return "SrcCheckRuntimeScope";
299 case IrInstructionIdHasField:316 case IrInstSrcIdHasDecl:
300 return "HasField";317 return "SrcHasDecl";
301 case IrInstructionIdTypeId:318 case IrInstSrcIdUndeclaredIdent:
302 return "TypeId";319 return "SrcUndeclaredIdent";
303 case IrInstructionIdSetEvalBranchQuota:320 case IrInstSrcIdAlloca:
304 return "SetEvalBranchQuota";321 return "SrcAlloca";
305 case IrInstructionIdPtrType:322 case IrInstSrcIdEndExpr:
306 return "PtrType";323 return "SrcEndExpr";
307 case IrInstructionIdAlignCast:324 case IrInstSrcIdUnionInitNamedField:
308 return "AlignCast";325 return "SrcUnionInitNamedField";
309 case IrInstructionIdImplicitCast:326 case IrInstSrcIdSuspendBegin:
310 return "ImplicitCast";327 return "SrcSuspendBegin";
311 case IrInstructionIdResolveResult:328 case IrInstSrcIdSuspendFinish:
312 return "ResolveResult";329 return "SrcSuspendFinish";
313 case IrInstructionIdResetResult:330 case IrInstSrcIdAwait:
314 return "ResetResult";331 return "SrcAwaitSr";
315 case IrInstructionIdOpaqueType:332 case IrInstSrcIdResume:
316 return "OpaqueType";333 return "SrcResume";
317 case IrInstructionIdSetAlignStack:334 case IrInstSrcIdSpillBegin:
318 return "SetAlignStack";335 return "SrcSpillBegin";
319 case IrInstructionIdArgType:336 case IrInstSrcIdSpillEnd:
320 return "ArgType";337 return "SrcSpillEnd";
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";
383 }338 }
384 zig_unreachable();339 zig_unreachable();
385}340}
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) {
388 for (int i = 0; i < irp->indent; i += 1) {525 for (int i = 0; i < irp->indent; i += 1) {
389 fprintf(irp->f, " ");526 fprintf(irp->f, " ");
390 }527 }
391}528}
392529
393static void ir_print_prefix(IrPrint *irp, IrInstruction *instruction, bool trailing) {530static void ir_print_indent_gen(IrPrintGen *irp) {
394 ir_print_indent(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);
395 const char mark = trailing ? ':' : '#';555 const char mark = trailing ? ':' : '#';
396 const char *type_name = instruction->value->type ? buf_ptr(&instruction->value->type->name) : "(unknown)";556 const char *type_name = instruction->value->type ? buf_ptr(&instruction->value->type->name) : "(unknown)";
397 const char *ref_count = ir_has_side_effects(instruction) ?557 const char *ref_count = ir_inst_gen_has_side_effects(instruction) ?
398 "-" : buf_ptr(buf_sprintf("%" PRIu32 "", instruction->ref_count));558 "-" : buf_ptr(buf_sprintf("%" PRIu32 "", instruction->base.ref_count));
399 fprintf(irp->f, "%c%-3" PRIu32 "| %-22s| %-12s| %-2s| ", mark, instruction->debug_id,559 fprintf(irp->f, "%c%-3" PRIu32 "| %-22s| %-12s| %-2s| ", mark, instruction->base.debug_id,
400 ir_instruction_type_str(instruction->id), type_name, ref_count);560 ir_inst_gen_type_str(instruction->id), type_name, ref_count);
401}561}
402562
403static void ir_print_const_value(IrPrint *irp, ZigValue *const_val) {563static void ir_print_var_src(IrPrintSrc *irp, IrInstSrc *inst) {
404 Buf buf = BUF_INIT;564 fprintf(irp->f, "#%" PRIu32 "", inst->base.debug_id);
405 buf_resize(&buf, 0);
406 render_const_value(irp->codegen, &buf, const_val);
407 fprintf(irp->f, "%s", buf_ptr(&buf));
408}565}
409566
410static void ir_print_var_instruction(IrPrint *irp, IrInstruction *instruction) {567static void ir_print_var_gen(IrPrintGen *irp, IrInstGen *inst) {
411 fprintf(irp->f, "#%" PRIu32 "", instruction->debug_id);568 fprintf(irp->f, "#%" PRIu32 "", inst->base.debug_id);
412 if (irp->pass != IrPassSrc && irp->printed.maybe_get(instruction) == nullptr) {569 if (irp->printed.maybe_get(inst) == nullptr) {
413 irp->printed.put(instruction, 0);570 irp->printed.put(inst, 0);
414 irp->pending.append(instruction);571 irp->pending.append(inst);
415 }572 }
416}573}
417574
418static void ir_print_other_instruction(IrPrint *irp, IrInstruction *instruction) {575static void ir_print_other_inst_src(IrPrintSrc *irp, IrInstSrc *inst) {
419 if (instruction == nullptr) {576 if (inst == nullptr) {
420 fprintf(irp->f, "(null)");577 fprintf(irp->f, "(null)");
421 return;578 return;
422 }579 }
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) {603static void ir_print_other_block(IrPrintSrc *irp, IrBasicBlockSrc *bb) {
425 ir_print_const_value(irp, instruction->value);604 if (bb == nullptr) {
605 fprintf(irp->f, "(null block)");
426 } else {606 } else {
427 ir_print_var_instruction(irp, instruction);607 fprintf(irp->f, "$%s_%" PRIu32 "", bb->name_hint, bb->debug_id);
428 }608 }
429}609}
430610
431static void ir_print_other_block(IrPrint *irp, IrBasicBlock *bb) {611static void ir_print_other_block_gen(IrPrintGen *irp, IrBasicBlockGen *bb) {
432 if (bb == nullptr) {612 if (bb == nullptr) {
433 fprintf(irp->f, "(null block)");613 fprintf(irp->f, "(null block)");
434 } else {614 } 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);
436 }616 }
437}617}
438618
439static void ir_print_return(IrPrint *irp, IrInstructionReturn *instruction) {619static void ir_print_return_src(IrPrintSrc *irp, IrInstSrcReturn *inst) {
440 fprintf(irp->f, "return ");620 fprintf(irp->f, "return ");
441 ir_print_other_instruction(irp, instruction->operand);621 ir_print_other_inst_src(irp, inst->operand);
442}622}
443623
444static void ir_print_const(IrPrint *irp, IrInstructionConst *const_instruction) {624static void ir_print_return_gen(IrPrintGen *irp, IrInstGenReturn *inst) {
445 ir_print_const_value(irp, const_instruction->base.value);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);
446}635}
447636
448static const char *ir_bin_op_id_str(IrBinOp op_id) {637static 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) {...@@ -531,89 +720,111 @@ static const char *ir_un_op_id_str(IrUnOp op_id) {
531 zig_unreachable();720 zig_unreachable();
532}721}
533722
534static void ir_print_un_op(IrPrint *irp, IrInstructionUnOp *un_op_instruction) {723static void ir_print_un_op(IrPrintSrc *irp, IrInstSrcUnOp *inst) {
535 fprintf(irp->f, "%s ", ir_un_op_id_str(un_op_instruction->op_id));724 fprintf(irp->f, "%s ", ir_un_op_id_str(inst->op_id));
536 ir_print_other_instruction(irp, un_op_instruction->value);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 }
537}735}
538736
539static void ir_print_bin_op(IrPrint *irp, IrInstructionBinOp *bin_op_instruction) {737static void ir_print_bin_op(IrPrintGen *irp, IrInstGenBinOp *bin_op_instruction) {
540 ir_print_other_instruction(irp, bin_op_instruction->op1);738 ir_print_other_inst_gen(irp, bin_op_instruction->op1);
541 fprintf(irp->f, " %s ", ir_bin_op_id_str(bin_op_instruction->op_id));739 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);
543 if (!bin_op_instruction->safety_check_on) {741 if (!bin_op_instruction->safety_check_on) {
544 fprintf(irp->f, " // no safety");742 fprintf(irp->f, " // no safety");
545 }743 }
546}744}
547745
548static void ir_print_merge_err_sets(IrPrint *irp, IrInstructionMergeErrSets *instruction) {746static void ir_print_merge_err_sets(IrPrintSrc *irp, IrInstSrcMergeErrSets *instruction) {
549 ir_print_other_instruction(irp, instruction->op1);747 ir_print_other_inst_src(irp, instruction->op1);
550 fprintf(irp->f, " || ");748 fprintf(irp->f, " || ");
551 ir_print_other_instruction(irp, instruction->op2);749 ir_print_other_inst_src(irp, instruction->op2);
552 if (instruction->type_name != nullptr) {750 if (instruction->type_name != nullptr) {
553 fprintf(irp->f, " // name=%s", buf_ptr(instruction->type_name));751 fprintf(irp->f, " // name=%s", buf_ptr(instruction->type_name));
554 }752 }
555}753}
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) {
558 const char *var_or_const = decl_var_instruction->var->gen_is_const ? "const" : "var";756 const char *var_or_const = decl_var_instruction->var->gen_is_const ? "const" : "var";
559 const char *name = decl_var_instruction->var->name;757 const char *name = decl_var_instruction->var->name;
560 if (decl_var_instruction->var_type) {758 if (decl_var_instruction->var_type) {
561 fprintf(irp->f, "%s %s: ", var_or_const, name);759 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);
563 fprintf(irp->f, " ");761 fprintf(irp->f, " ");
564 } else {762 } else {
565 fprintf(irp->f, "%s %s ", var_or_const, name);763 fprintf(irp->f, "%s %s ", var_or_const, name);
566 }764 }
567 if (decl_var_instruction->align_value) {765 if (decl_var_instruction->align_value) {
568 fprintf(irp->f, "align ");766 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);
570 fprintf(irp->f, " ");768 fprintf(irp->f, " ");
571 }769 }
572 fprintf(irp->f, "= ");770 fprintf(irp->f, "= ");
573 ir_print_other_instruction(irp, decl_var_instruction->ptr);771 ir_print_other_inst_src(irp, decl_var_instruction->ptr);
574 if (decl_var_instruction->var->is_comptime != nullptr) {772 if (decl_var_instruction->var->is_comptime != nullptr) {
575 fprintf(irp->f, " // comptime = ");773 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);
577 }775 }
578}776}
579777
580static void ir_print_cast(IrPrint *irp, IrInstructionCast *cast_instruction) {778static const char *cast_op_str(CastOp op) {
581 fprintf(irp->f, "cast ");779 switch (op) {
582 ir_print_other_instruction(irp, cast_instruction->value);780 case CastOpNoCast: return "NoCast";
583 fprintf(irp->f, " to %s", buf_ptr(&cast_instruction->dest_type->name));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);
584}795}
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) {
587 fprintf(irp->f, "var(");798 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);
589 fprintf(irp->f, ")");800 fprintf(irp->f, ")");
590}801}
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) {
593 fprintf(irp->f, "inst(");804 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);
595 fprintf(irp->f, ")");806 fprintf(irp->f, ")");
596}807}
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) {
599 fprintf(irp->f, "peer(next=");810 fprintf(irp->f, "peer(next=");
600 ir_print_other_block(irp, result_loc_peer->next_bb);811 ir_print_other_block(irp, result_loc_peer->next_bb);
601 fprintf(irp->f, ")");812 fprintf(irp->f, ")");
602}813}
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) {
605 fprintf(irp->f, "bitcast(ty=");816 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);
607 fprintf(irp->f, ")");818 fprintf(irp->f, ")");
608}819}
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) {
611 fprintf(irp->f, "cast(ty=");822 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);
613 fprintf(irp->f, ")");824 fprintf(irp->f, ")");
614}825}
615826
616static void ir_print_result_loc(IrPrint *irp, ResultLoc *result_loc) {827static void ir_print_result_loc(IrPrintSrc *irp, ResultLoc *result_loc) {
617 switch (result_loc->id) {828 switch (result_loc->id) {
618 case ResultLocIdInvalid:829 case ResultLocIdInvalid:
619 zig_unreachable();830 zig_unreachable();
...@@ -640,34 +851,34 @@ static void ir_print_result_loc(IrPrint *irp, ResultLoc *result_loc) {...@@ -640,34 +851,34 @@ static void ir_print_result_loc(IrPrint *irp, ResultLoc *result_loc) {
640 zig_unreachable();851 zig_unreachable();
641}852}
642853
643static void ir_print_call_extra(IrPrint *irp, IrInstructionCallExtra *instruction) {854static void ir_print_call_extra(IrPrintSrc *irp, IrInstSrcCallExtra *instruction) {
644 fprintf(irp->f, "opts=");855 fprintf(irp->f, "opts=");
645 ir_print_other_instruction(irp, instruction->options);856 ir_print_other_inst_src(irp, instruction->options);
646 fprintf(irp->f, ", fn=");857 fprintf(irp->f, ", fn=");
647 ir_print_other_instruction(irp, instruction->fn_ref);858 ir_print_other_inst_src(irp, instruction->fn_ref);
648 fprintf(irp->f, ", args=");859 fprintf(irp->f, ", args=");
649 ir_print_other_instruction(irp, instruction->args);860 ir_print_other_inst_src(irp, instruction->args);
650 fprintf(irp->f, ", result=");861 fprintf(irp->f, ", result=");
651 ir_print_result_loc(irp, instruction->result_loc);862 ir_print_result_loc(irp, instruction->result_loc);
652}863}
653864
654static void ir_print_call_src_args(IrPrint *irp, IrInstructionCallSrcArgs *instruction) {865static void ir_print_call_args(IrPrintSrc *irp, IrInstSrcCallArgs *instruction) {
655 fprintf(irp->f, "opts=");866 fprintf(irp->f, "opts=");
656 ir_print_other_instruction(irp, instruction->options);867 ir_print_other_inst_src(irp, instruction->options);
657 fprintf(irp->f, ", fn=");868 fprintf(irp->f, ", fn=");
658 ir_print_other_instruction(irp, instruction->fn_ref);869 ir_print_other_inst_src(irp, instruction->fn_ref);
659 fprintf(irp->f, ", args=(");870 fprintf(irp->f, ", args=(");
660 for (size_t i = 0; i < instruction->args_len; i += 1) {871 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];
662 if (i != 0)873 if (i != 0)
663 fprintf(irp->f, ", ");874 fprintf(irp->f, ", ");
664 ir_print_other_instruction(irp, arg);875 ir_print_other_inst_src(irp, arg);
665 }876 }
666 fprintf(irp->f, "), result=");877 fprintf(irp->f, "), result=");
667 ir_print_result_loc(irp, instruction->result_loc);878 ir_print_result_loc(irp, instruction->result_loc);
668}879}
669880
670static void ir_print_call_src(IrPrint *irp, IrInstructionCallSrc *call_instruction) {881static void ir_print_call_src(IrPrintSrc *irp, IrInstSrcCall *call_instruction) {
671 switch (call_instruction->modifier) {882 switch (call_instruction->modifier) {
672 case CallModifierNone:883 case CallModifierNone:
673 break;884 break;
...@@ -699,20 +910,20 @@ static void ir_print_call_src(IrPrint *irp, IrInstructionCallSrc *call_instructi...@@ -699,20 +910,20 @@ static void ir_print_call_src(IrPrint *irp, IrInstructionCallSrc *call_instructi
699 fprintf(irp->f, "%s", buf_ptr(&call_instruction->fn_entry->symbol_name));910 fprintf(irp->f, "%s", buf_ptr(&call_instruction->fn_entry->symbol_name));
700 } else {911 } else {
701 assert(call_instruction->fn_ref);912 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);
703 }914 }
704 fprintf(irp->f, "(");915 fprintf(irp->f, "(");
705 for (size_t i = 0; i < call_instruction->arg_count; i += 1) {916 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];
707 if (i != 0)918 if (i != 0)
708 fprintf(irp->f, ", ");919 fprintf(irp->f, ", ");
709 ir_print_other_instruction(irp, arg);920 ir_print_other_inst_src(irp, arg);
710 }921 }
711 fprintf(irp->f, ")result=");922 fprintf(irp->f, ")result=");
712 ir_print_result_loc(irp, call_instruction->result_loc);923 ir_print_result_loc(irp, call_instruction->result_loc);
713}924}
714925
715static void ir_print_call_gen(IrPrint *irp, IrInstructionCallGen *call_instruction) {926static void ir_print_call_gen(IrPrintGen *irp, IrInstGenCall *call_instruction) {
716 switch (call_instruction->modifier) {927 switch (call_instruction->modifier) {
717 case CallModifierNone:928 case CallModifierNone:
718 break;929 break;
...@@ -744,221 +955,291 @@ static void ir_print_call_gen(IrPrint *irp, IrInstructionCallGen *call_instructi...@@ -744,221 +955,291 @@ static void ir_print_call_gen(IrPrint *irp, IrInstructionCallGen *call_instructi
744 fprintf(irp->f, "%s", buf_ptr(&call_instruction->fn_entry->symbol_name));955 fprintf(irp->f, "%s", buf_ptr(&call_instruction->fn_entry->symbol_name));
745 } else {956 } else {
746 assert(call_instruction->fn_ref);957 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);
748 }959 }
749 fprintf(irp->f, "(");960 fprintf(irp->f, "(");
750 for (size_t i = 0; i < call_instruction->arg_count; i += 1) {961 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];
752 if (i != 0)963 if (i != 0)
753 fprintf(irp->f, ", ");964 fprintf(irp->f, ", ");
754 ir_print_other_instruction(irp, arg);965 ir_print_other_inst_gen(irp, arg);
755 }966 }
756 fprintf(irp->f, ")result=");967 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);
758}969}
759970
760static void ir_print_cond_br(IrPrint *irp, IrInstructionCondBr *cond_br_instruction) {971static void ir_print_cond_br(IrPrintSrc *irp, IrInstSrcCondBr *inst) {
761 fprintf(irp->f, "if (");972 fprintf(irp->f, "if (");
762 ir_print_other_instruction(irp, cond_br_instruction->condition);973 ir_print_other_inst_src(irp, inst->condition);
763 fprintf(irp->f, ") ");974 fprintf(irp->f, ") ");
764 ir_print_other_block(irp, cond_br_instruction->then_block);975 ir_print_other_block(irp, inst->then_block);
765 fprintf(irp->f, " else ");976 fprintf(irp->f, " else ");
766 ir_print_other_block(irp, cond_br_instruction->else_block);977 ir_print_other_block(irp, inst->else_block);
767 if (cond_br_instruction->is_comptime != nullptr) {978 if (inst->is_comptime != nullptr) {
768 fprintf(irp->f, " // comptime = ");979 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);
770 }981 }
771}982}
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) {
774 fprintf(irp->f, "goto ");994 fprintf(irp->f, "goto ");
775 ir_print_other_block(irp, br_instruction->dest_block);995 ir_print_other_block(irp, br_instruction->dest_block);
776 if (br_instruction->is_comptime != nullptr) {996 if (br_instruction->is_comptime != nullptr) {
777 fprintf(irp->f, " // comptime = ");997 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);
779 }999 }
780}1000}
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) {
783 assert(phi_instruction->incoming_count != 0);1008 assert(phi_instruction->incoming_count != 0);
784 assert(phi_instruction->incoming_count != SIZE_MAX);1009 assert(phi_instruction->incoming_count != SIZE_MAX);
785 for (size_t i = 0; i < phi_instruction->incoming_count; i += 1) {1010 for (size_t i = 0; i < phi_instruction->incoming_count; i += 1) {
786 IrBasicBlock *incoming_block = phi_instruction->incoming_blocks[i];1011 IrBasicBlockSrc *incoming_block = phi_instruction->incoming_blocks[i];
787 IrInstruction *incoming_value = phi_instruction->incoming_values[i];1012 IrInstSrc *incoming_value = phi_instruction->incoming_values[i];
788 if (i != 0)1013 if (i != 0)
789 fprintf(irp->f, " ");1014 fprintf(irp->f, " ");
790 ir_print_other_block(irp, incoming_block);1015 ir_print_other_block(irp, incoming_block);
791 fprintf(irp->f, ":");1016 fprintf(irp->f, ":");
792 ir_print_other_instruction(irp, incoming_value);1017 ir_print_other_inst_src(irp, incoming_value);
793 }1018 }
794}1019}
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) {
797 fprintf(irp->f, "{");1036 fprintf(irp->f, "{");
798 if (instruction->item_count > 50) {1037 if (instruction->item_count > 50) {
799 fprintf(irp->f, "...(%" ZIG_PRI_usize " items)...", instruction->item_count);1038 fprintf(irp->f, "...(%" ZIG_PRI_usize " items)...", instruction->item_count);
800 } else {1039 } else {
801 for (size_t i = 0; i < instruction->item_count; i += 1) {1040 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];
803 if (i != 0)1042 if (i != 0)
804 fprintf(irp->f, ", ");1043 fprintf(irp->f, ", ");
805 ir_print_other_instruction(irp, result_loc);1044 ir_print_other_inst_src(irp, result_loc);
806 }1045 }
807 }1046 }
808 fprintf(irp->f, "}result=");1047 fprintf(irp->f, "}result=");
809 ir_print_other_instruction(irp, instruction->result_loc);1048 ir_print_other_inst_src(irp, instruction->result_loc);
810}1049}
8111050
812static void ir_print_container_init_fields(IrPrint *irp, IrInstructionContainerInitFields *instruction) {1051static void ir_print_container_init_fields(IrPrintSrc *irp, IrInstSrcContainerInitFields *instruction) {
813 fprintf(irp->f, "{");1052 fprintf(irp->f, "{");
814 for (size_t i = 0; i < instruction->field_count; i += 1) {1053 for (size_t i = 0; i < instruction->field_count; i += 1) {
815 IrInstructionContainerInitFieldsField *field = &instruction->fields[i];1054 IrInstSrcContainerInitFieldsField *field = &instruction->fields[i];
816 const char *comma = (i == 0) ? "" : ", ";1055 const char *comma = (i == 0) ? "" : ", ";
817 fprintf(irp->f, "%s.%s = ", comma, buf_ptr(field->name));1056 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);
819 }1058 }
820 fprintf(irp->f, "}result=");1059 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");
822}1065}
8231066
824static void ir_print_unreachable(IrPrint *irp, IrInstructionUnreachable *instruction) {1067static void ir_print_unreachable(IrPrintGen *irp, IrInstGenUnreachable *instruction) {
825 fprintf(irp->f, "unreachable");1068 fprintf(irp->f, "unreachable");
826}1069}
8271070
828static void ir_print_elem_ptr(IrPrint *irp, IrInstructionElemPtr *instruction) {1071static void ir_print_elem_ptr(IrPrintSrc *irp, IrInstSrcElemPtr *instruction) {
829 fprintf(irp->f, "&");1072 fprintf(irp->f, "&");
830 ir_print_other_instruction(irp, instruction->array_ptr);1073 ir_print_other_inst_src(irp, instruction->array_ptr);
831 fprintf(irp->f, "[");1074 fprintf(irp->f, "[");
832 ir_print_other_instruction(irp, instruction->elem_index);1075 ir_print_other_inst_src(irp, instruction->elem_index);
833 fprintf(irp->f, "]");1076 fprintf(irp->f, "]");
834 if (!instruction->safety_check_on) {1077 if (!instruction->safety_check_on) {
835 fprintf(irp->f, " // no safety");1078 fprintf(irp->f, " // no safety");
836 }1079 }
837}1080}
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) {
840 fprintf(irp->f, "&%s", instruction->var->name);1098 fprintf(irp->f, "&%s", instruction->var->name);
841}1099}
8421100
843static void ir_print_return_ptr(IrPrint *irp, IrInstructionReturnPtr *instruction) {1101static void ir_print_return_ptr(IrPrintGen *irp, IrInstGenReturnPtr *instruction) {
844 fprintf(irp->f, "@ReturnPtr");1102 fprintf(irp->f, "@ReturnPtr");
845}1103}
8461104
847static void ir_print_load_ptr(IrPrint *irp, IrInstructionLoadPtr *instruction) {1105static void ir_print_load_ptr(IrPrintSrc *irp, IrInstSrcLoadPtr *instruction) {
848 ir_print_other_instruction(irp, instruction->ptr);1106 ir_print_other_inst_src(irp, instruction->ptr);
849 fprintf(irp->f, ".*");1107 fprintf(irp->f, ".*");
850}1108}
8511109
852static void ir_print_load_ptr_gen(IrPrint *irp, IrInstructionLoadPtrGen *instruction) {1110static void ir_print_load_ptr_gen(IrPrintGen *irp, IrInstGenLoadPtr *instruction) {
853 fprintf(irp->f, "loadptr(");1111 fprintf(irp->f, "loadptr(");
854 ir_print_other_instruction(irp, instruction->ptr);1112 ir_print_other_inst_gen(irp, instruction->ptr);
855 fprintf(irp->f, ")result=");1113 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);
857}1122}
8581123
859static void ir_print_store_ptr(IrPrint *irp, IrInstructionStorePtr *instruction) {1124static void ir_print_store_ptr(IrPrintGen *irp, IrInstGenStorePtr *instruction) {
860 fprintf(irp->f, "*");1125 fprintf(irp->f, "*");
861 ir_print_var_instruction(irp, instruction->ptr);1126 ir_print_var_gen(irp, instruction->ptr);
862 fprintf(irp->f, " = ");1127 fprintf(irp->f, " = ");
863 ir_print_other_instruction(irp, instruction->value);1128 ir_print_other_inst_gen(irp, instruction->value);
864}1129}
8651130
866static void ir_print_vector_store_elem(IrPrint *irp, IrInstructionVectorStoreElem *instruction) {1131static void ir_print_vector_store_elem(IrPrintGen *irp, IrInstGenVectorStoreElem *instruction) {
867 fprintf(irp->f, "vector_ptr=");1132 fprintf(irp->f, "vector_ptr=");
868 ir_print_var_instruction(irp, instruction->vector_ptr);1133 ir_print_var_gen(irp, instruction->vector_ptr);
869 fprintf(irp->f, ",index=");1134 fprintf(irp->f, ",index=");
870 ir_print_var_instruction(irp, instruction->index);1135 ir_print_var_gen(irp, instruction->index);
871 fprintf(irp->f, ",value=");1136 fprintf(irp->f, ",value=");
872 ir_print_other_instruction(irp, instruction->value);1137 ir_print_other_inst_gen(irp, instruction->value);
873}1138}
8741139
875static void ir_print_typeof(IrPrint *irp, IrInstructionTypeOf *instruction) {1140static void ir_print_typeof(IrPrintSrc *irp, IrInstSrcTypeOf *instruction) {
876 fprintf(irp->f, "@TypeOf(");1141 fprintf(irp->f, "@TypeOf(");
877 ir_print_other_instruction(irp, instruction->value);1142 ir_print_other_inst_src(irp, instruction->value);
878 fprintf(irp->f, ")");1143 fprintf(irp->f, ")");
879}1144}
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) {
882 if (instruction->field_name_buffer) {1163 if (instruction->field_name_buffer) {
883 fprintf(irp->f, "fieldptr ");1164 fprintf(irp->f, "fieldptr ");
884 ir_print_other_instruction(irp, instruction->container_ptr);1165 ir_print_other_inst_src(irp, instruction->container_ptr);
885 fprintf(irp->f, ".%s", buf_ptr(instruction->field_name_buffer));1166 fprintf(irp->f, ".%s", buf_ptr(instruction->field_name_buffer));
886 } else {1167 } else {
887 assert(instruction->field_name_expr);1168 assert(instruction->field_name_expr);
888 fprintf(irp->f, "@field(");1169 fprintf(irp->f, "@field(");
889 ir_print_other_instruction(irp, instruction->container_ptr);1170 ir_print_other_inst_src(irp, instruction->container_ptr);
890 fprintf(irp->f, ", ");1171 fprintf(irp->f, ", ");
891 ir_print_other_instruction(irp, instruction->field_name_expr);1172 ir_print_other_inst_src(irp, instruction->field_name_expr);
892 fprintf(irp->f, ")");1173 fprintf(irp->f, ")");
893 }1174 }
894}1175}
8951176
896static void ir_print_struct_field_ptr(IrPrint *irp, IrInstructionStructFieldPtr *instruction) {1177static void ir_print_struct_field_ptr(IrPrintGen *irp, IrInstGenStructFieldPtr *instruction) {
897 fprintf(irp->f, "@StructFieldPtr(&");1178 fprintf(irp->f, "@StructFieldPtr(&");
898 ir_print_other_instruction(irp, instruction->struct_ptr);1179 ir_print_other_inst_gen(irp, instruction->struct_ptr);
899 fprintf(irp->f, ".%s", buf_ptr(instruction->field->name));1180 fprintf(irp->f, ".%s", buf_ptr(instruction->field->name));
900 fprintf(irp->f, ")");1181 fprintf(irp->f, ")");
901}1182}
9021183
903static void ir_print_union_field_ptr(IrPrint *irp, IrInstructionUnionFieldPtr *instruction) {1184static void ir_print_union_field_ptr(IrPrintGen *irp, IrInstGenUnionFieldPtr *instruction) {
904 fprintf(irp->f, "@UnionFieldPtr(&");1185 fprintf(irp->f, "@UnionFieldPtr(&");
905 ir_print_other_instruction(irp, instruction->union_ptr);1186 ir_print_other_inst_gen(irp, instruction->union_ptr);
906 fprintf(irp->f, ".%s", buf_ptr(instruction->field->enum_field->name));1187 fprintf(irp->f, ".%s", buf_ptr(instruction->field->enum_field->name));
907 fprintf(irp->f, ")");1188 fprintf(irp->f, ")");
908}1189}
9091190
910static void ir_print_set_cold(IrPrint *irp, IrInstructionSetCold *instruction) {1191static void ir_print_set_cold(IrPrintSrc *irp, IrInstSrcSetCold *instruction) {
911 fprintf(irp->f, "@setCold(");1192 fprintf(irp->f, "@setCold(");
912 ir_print_other_instruction(irp, instruction->is_cold);1193 ir_print_other_inst_src(irp, instruction->is_cold);
913 fprintf(irp->f, ")");1194 fprintf(irp->f, ")");
914}1195}
9151196
916static void ir_print_set_runtime_safety(IrPrint *irp, IrInstructionSetRuntimeSafety *instruction) {1197static void ir_print_set_runtime_safety(IrPrintSrc *irp, IrInstSrcSetRuntimeSafety *instruction) {
917 fprintf(irp->f, "@setRuntimeSafety(");1198 fprintf(irp->f, "@setRuntimeSafety(");
918 ir_print_other_instruction(irp, instruction->safety_on);1199 ir_print_other_inst_src(irp, instruction->safety_on);
919 fprintf(irp->f, ")");1200 fprintf(irp->f, ")");
920}1201}
9211202
922static void ir_print_set_float_mode(IrPrint *irp, IrInstructionSetFloatMode *instruction) {1203static void ir_print_set_float_mode(IrPrintSrc *irp, IrInstSrcSetFloatMode *instruction) {
923 fprintf(irp->f, "@setFloatMode(");1204 fprintf(irp->f, "@setFloatMode(");
924 ir_print_other_instruction(irp, instruction->scope_value);1205 ir_print_other_inst_src(irp, instruction->scope_value);
925 fprintf(irp->f, ", ");1206 fprintf(irp->f, ", ");
926 ir_print_other_instruction(irp, instruction->mode_value);1207 ir_print_other_inst_src(irp, instruction->mode_value);
927 fprintf(irp->f, ")");1208 fprintf(irp->f, ")");
928}1209}
9291210
930static void ir_print_array_type(IrPrint *irp, IrInstructionArrayType *instruction) {1211static void ir_print_array_type(IrPrintSrc *irp, IrInstSrcArrayType *instruction) {
931 fprintf(irp->f, "[");1212 fprintf(irp->f, "[");
932 ir_print_other_instruction(irp, instruction->size);1213 ir_print_other_inst_src(irp, instruction->size);
933 if (instruction->sentinel != nullptr) {1214 if (instruction->sentinel != nullptr) {
934 fprintf(irp->f, ":");1215 fprintf(irp->f, ":");
935 ir_print_other_instruction(irp, instruction->sentinel);1216 ir_print_other_inst_src(irp, instruction->sentinel);
936 }1217 }
937 fprintf(irp->f, "]");1218 fprintf(irp->f, "]");
938 ir_print_other_instruction(irp, instruction->child_type);1219 ir_print_other_inst_src(irp, instruction->child_type);
939}1220}
9401221
941static void ir_print_slice_type(IrPrint *irp, IrInstructionSliceType *instruction) {1222static void ir_print_slice_type(IrPrintSrc *irp, IrInstSrcSliceType *instruction) {
942 const char *const_kw = instruction->is_const ? "const " : "";1223 const char *const_kw = instruction->is_const ? "const " : "";
943 fprintf(irp->f, "[]%s", const_kw);1224 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);
945}1226}
9461227
947static void ir_print_any_frame_type(IrPrint *irp, IrInstructionAnyFrameType *instruction) {1228static void ir_print_any_frame_type(IrPrintSrc *irp, IrInstSrcAnyFrameType *instruction) {
948 if (instruction->payload_type == nullptr) {1229 if (instruction->payload_type == nullptr) {
949 fprintf(irp->f, "anyframe");1230 fprintf(irp->f, "anyframe");
950 } else {1231 } else {
951 fprintf(irp->f, "anyframe->");1232 fprintf(irp->f, "anyframe->");
952 ir_print_other_instruction(irp, instruction->payload_type);1233 ir_print_other_inst_src(irp, instruction->payload_type);
953 }1234 }
954}1235}
9551236
956static void ir_print_asm_src(IrPrint *irp, IrInstructionAsmSrc *instruction) {1237static void ir_print_asm_src(IrPrintSrc *irp, IrInstSrcAsm *instruction) {
957 assert(instruction->base.source_node->type == NodeTypeAsmExpr);1238 assert(instruction->base.base.source_node->type == NodeTypeAsmExpr);
958 AstNodeAsmExpr *asm_expr = &instruction->base.source_node->data.asm_expr;1239 AstNodeAsmExpr *asm_expr = &instruction->base.base.source_node->data.asm_expr;
959 const char *volatile_kw = instruction->has_side_effects ? " volatile" : "";1240 const char *volatile_kw = instruction->has_side_effects ? " volatile" : "";
960 fprintf(irp->f, "asm%s (", volatile_kw);1241 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
963 for (size_t i = 0; i < asm_expr->output_list.length; i += 1) {1244 for (size_t i = 0; i < asm_expr->output_list.length; i += 1) {
964 AsmOutput *asm_output = asm_expr->output_list.at(i);1245 AsmOutput *asm_output = asm_expr->output_list.at(i);
...@@ -969,7 +1250,7 @@ static void ir_print_asm_src(IrPrint *irp, IrInstructionAsmSrc *instruction) {...@@ -969,7 +1250,7 @@ static void ir_print_asm_src(IrPrint *irp, IrInstructionAsmSrc *instruction) {
969 buf_ptr(asm_output->constraint));1250 buf_ptr(asm_output->constraint));
970 if (asm_output->return_type) {1251 if (asm_output->return_type) {
971 fprintf(irp->f, "-> ");1252 fprintf(irp->f, "-> ");
972 ir_print_other_instruction(irp, instruction->output_types[i]);1253 ir_print_other_inst_src(irp, instruction->output_types[i]);
973 } else {1254 } else {
974 fprintf(irp->f, "%s", buf_ptr(asm_output->variable_name));1255 fprintf(irp->f, "%s", buf_ptr(asm_output->variable_name));
975 }1256 }
...@@ -984,7 +1265,7 @@ static void ir_print_asm_src(IrPrint *irp, IrInstructionAsmSrc *instruction) {...@@ -984,7 +1265,7 @@ static void ir_print_asm_src(IrPrint *irp, IrInstructionAsmSrc *instruction) {
984 fprintf(irp->f, "[%s] \"%s\" (",1265 fprintf(irp->f, "[%s] \"%s\" (",
985 buf_ptr(asm_input->asm_symbolic_name),1266 buf_ptr(asm_input->asm_symbolic_name),
986 buf_ptr(asm_input->constraint));1267 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]);
988 fprintf(irp->f, ")");1269 fprintf(irp->f, ")");
989 }1270 }
990 fprintf(irp->f, " : ");1271 fprintf(irp->f, " : ");
...@@ -996,9 +1277,9 @@ static void ir_print_asm_src(IrPrint *irp, IrInstructionAsmSrc *instruction) {...@@ -996,9 +1277,9 @@ static void ir_print_asm_src(IrPrint *irp, IrInstructionAsmSrc *instruction) {
996 fprintf(irp->f, ")");1277 fprintf(irp->f, ")");
997}1278}
9981279
999static void ir_print_asm_gen(IrPrint *irp, IrInstructionAsmGen *instruction) {1280static void ir_print_asm_gen(IrPrintGen *irp, IrInstGenAsm *instruction) {
1000 assert(instruction->base.source_node->type == NodeTypeAsmExpr);1281 assert(instruction->base.base.source_node->type == NodeTypeAsmExpr);
1001 AstNodeAsmExpr *asm_expr = &instruction->base.source_node->data.asm_expr;1282 AstNodeAsmExpr *asm_expr = &instruction->base.base.source_node->data.asm_expr;
1002 const char *volatile_kw = instruction->has_side_effects ? " volatile" : "";1283 const char *volatile_kw = instruction->has_side_effects ? " volatile" : "";
1003 fprintf(irp->f, "asm%s (\"%s\") : ", volatile_kw, buf_ptr(instruction->asm_template));1284 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) {...@@ -1011,7 +1292,7 @@ static void ir_print_asm_gen(IrPrint *irp, IrInstructionAsmGen *instruction) {
1011 buf_ptr(asm_output->constraint));1292 buf_ptr(asm_output->constraint));
1012 if (asm_output->return_type) {1293 if (asm_output->return_type) {
1013 fprintf(irp->f, "-> ");1294 fprintf(irp->f, "-> ");
1014 ir_print_other_instruction(irp, instruction->output_types[i]);1295 ir_print_other_inst_gen(irp, instruction->output_types[i]);
1015 } else {1296 } else {
1016 fprintf(irp->f, "%s", buf_ptr(asm_output->variable_name));1297 fprintf(irp->f, "%s", buf_ptr(asm_output->variable_name));
1017 }1298 }
...@@ -1026,7 +1307,7 @@ static void ir_print_asm_gen(IrPrint *irp, IrInstructionAsmGen *instruction) {...@@ -1026,7 +1307,7 @@ static void ir_print_asm_gen(IrPrint *irp, IrInstructionAsmGen *instruction) {
1026 fprintf(irp->f, "[%s] \"%s\" (",1307 fprintf(irp->f, "[%s] \"%s\" (",
1027 buf_ptr(asm_input->asm_symbolic_name),1308 buf_ptr(asm_input->asm_symbolic_name),
1028 buf_ptr(asm_input->constraint));1309 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]);
1030 fprintf(irp->f, ")");1311 fprintf(irp->f, ")");
1031 }1312 }
1032 fprintf(irp->f, " : ");1313 fprintf(irp->f, " : ");
...@@ -1038,96 +1319,120 @@ static void ir_print_asm_gen(IrPrint *irp, IrInstructionAsmGen *instruction) {...@@ -1038,96 +1319,120 @@ static void ir_print_asm_gen(IrPrint *irp, IrInstructionAsmGen *instruction) {
1038 fprintf(irp->f, ")");1319 fprintf(irp->f, ")");
1039}1320}
10401321
1041static void ir_print_size_of(IrPrint *irp, IrInstructionSizeOf *instruction) {1322static void ir_print_size_of(IrPrintSrc *irp, IrInstSrcSizeOf *instruction) {
1042 if (instruction->bit_size)1323 if (instruction->bit_size)
1043 fprintf(irp->f, "@bitSizeOf(");1324 fprintf(irp->f, "@bitSizeOf(");
1044 else1325 else
1045 fprintf(irp->f, "@sizeOf(");1326 fprintf(irp->f, "@sizeOf(");
1046 ir_print_other_instruction(irp, instruction->type_value);1327 ir_print_other_inst_src(irp, instruction->type_value);
1047 fprintf(irp->f, ")");1328 fprintf(irp->f, ")");
1048}1329}
10491330
1050static void ir_print_test_non_null(IrPrint *irp, IrInstructionTestNonNull *instruction) {1331static void ir_print_test_non_null(IrPrintSrc *irp, IrInstSrcTestNonNull *instruction) {
1051 ir_print_other_instruction(irp, instruction->value);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);
1052 fprintf(irp->f, " != null");1338 fprintf(irp->f, " != null");
1053}1339}
10541340
1055static void ir_print_optional_unwrap_ptr(IrPrint *irp, IrInstructionOptionalUnwrapPtr *instruction) {1341static void ir_print_optional_unwrap_ptr(IrPrintSrc *irp, IrInstSrcOptionalUnwrapPtr *instruction) {
1056 fprintf(irp->f, "&");1342 fprintf(irp->f, "&");
1057 ir_print_other_instruction(irp, instruction->base_ptr);1343 ir_print_other_inst_src(irp, instruction->base_ptr);
1058 fprintf(irp->f, ".*.?");1344 fprintf(irp->f, ".*.?");
1059 if (!instruction->safety_check_on) {1345 if (!instruction->safety_check_on) {
1060 fprintf(irp->f, " // no safety");1346 fprintf(irp->f, " // no safety");
1061 }1347 }
1062}1348}
10631349
1064static void ir_print_clz(IrPrint *irp, IrInstructionClz *instruction) {1350static void ir_print_optional_unwrap_ptr(IrPrintGen *irp, IrInstGenOptionalUnwrapPtr *instruction) {
1065 fprintf(irp->f, "@clz(");1351 fprintf(irp->f, "&");
1066 if (instruction->type != nullptr) {1352 ir_print_other_inst_gen(irp, instruction->base_ptr);
1067 ir_print_other_instruction(irp, instruction->type);1353 fprintf(irp->f, ".*.?");
1068 } else {1354 if (!instruction->safety_check_on) {
1069 fprintf(irp->f, "null");1355 fprintf(irp->f, " // no safety");
1070 }1356 }
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);
1071 fprintf(irp->f, ",");1362 fprintf(irp->f, ",");
1072 ir_print_other_instruction(irp, instruction->op);1363 ir_print_other_inst_src(irp, instruction->op);
1073 fprintf(irp->f, ")");1364 fprintf(irp->f, ")");
1074}1365}
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) {
1077 fprintf(irp->f, "@ctz(");1374 fprintf(irp->f, "@ctz(");
1078 if (instruction->type != nullptr) {1375 ir_print_other_inst_src(irp, instruction->type);
1079 ir_print_other_instruction(irp, instruction->type);
1080 } else {
1081 fprintf(irp->f, "null");
1082 }
1083 fprintf(irp->f, ",");1376 fprintf(irp->f, ",");
1084 ir_print_other_instruction(irp, instruction->op);1377 ir_print_other_inst_src(irp, instruction->op);
1085 fprintf(irp->f, ")");1378 fprintf(irp->f, ")");
1086}1379}
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) {
1089 fprintf(irp->f, "@popCount(");1388 fprintf(irp->f, "@popCount(");
1090 if (instruction->type != nullptr) {1389 ir_print_other_inst_src(irp, instruction->type);
1091 ir_print_other_instruction(irp, instruction->type);
1092 } else {
1093 fprintf(irp->f, "null");
1094 }
1095 fprintf(irp->f, ",");1390 fprintf(irp->f, ",");
1096 ir_print_other_instruction(irp, instruction->op);1391 ir_print_other_inst_src(irp, instruction->op);
1097 fprintf(irp->f, ")");1392 fprintf(irp->f, ")");
1098}1393}
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) {
1101 fprintf(irp->f, "@byteSwap(");1402 fprintf(irp->f, "@byteSwap(");
1102 if (instruction->type != nullptr) {1403 ir_print_other_inst_src(irp, instruction->type);
1103 ir_print_other_instruction(irp, instruction->type);
1104 } else {
1105 fprintf(irp->f, "null");
1106 }
1107 fprintf(irp->f, ",");1404 fprintf(irp->f, ",");
1108 ir_print_other_instruction(irp, instruction->op);1405 ir_print_other_inst_src(irp, instruction->op);
1109 fprintf(irp->f, ")");1406 fprintf(irp->f, ")");
1110}1407}
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) {
1113 fprintf(irp->f, "@bitReverse(");1416 fprintf(irp->f, "@bitReverse(");
1114 if (instruction->type != nullptr) {1417 ir_print_other_inst_src(irp, instruction->type);
1115 ir_print_other_instruction(irp, instruction->type);
1116 } else {
1117 fprintf(irp->f, "null");
1118 }
1119 fprintf(irp->f, ",");1418 fprintf(irp->f, ",");
1120 ir_print_other_instruction(irp, instruction->op);1419 ir_print_other_inst_src(irp, instruction->op);
1121 fprintf(irp->f, ")");1420 fprintf(irp->f, ")");
1122}1421}
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) {
1125 fprintf(irp->f, "switch (");1430 fprintf(irp->f, "switch (");
1126 ir_print_other_instruction(irp, instruction->target_value);1431 ir_print_other_inst_src(irp, instruction->target_value);
1127 fprintf(irp->f, ") ");1432 fprintf(irp->f, ") ");
1128 for (size_t i = 0; i < instruction->case_count; i += 1) {1433 for (size_t i = 0; i < instruction->case_count; i += 1) {
1129 IrInstructionSwitchBrCase *this_case = &instruction->cases[i];1434 IrInstSrcSwitchBrCase *this_case = &instruction->cases[i];
1130 ir_print_other_instruction(irp, this_case->value);1435 ir_print_other_inst_src(irp, this_case->value);
1131 fprintf(irp->f, " => ");1436 fprintf(irp->f, " => ");
1132 ir_print_other_block(irp, this_case->block);1437 ir_print_other_block(irp, this_case->block);
1133 fprintf(irp->f, ", ");1438 fprintf(irp->f, ", ");
...@@ -1136,359 +1441,453 @@ static void ir_print_switch_br(IrPrint *irp, IrInstructionSwitchBr *instruction)...@@ -1136,359 +1441,453 @@ static void ir_print_switch_br(IrPrint *irp, IrInstructionSwitchBr *instruction)
1136 ir_print_other_block(irp, instruction->else_block);1441 ir_print_other_block(irp, instruction->else_block);
1137 if (instruction->is_comptime != nullptr) {1442 if (instruction->is_comptime != nullptr) {
1138 fprintf(irp->f, " // comptime = ");1443 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, ", ");
1140 }1458 }
1459 fprintf(irp->f, "else => ");
1460 ir_print_other_block_gen(irp, instruction->else_block);
1141}1461}
11421462
1143static void ir_print_switch_var(IrPrint *irp, IrInstructionSwitchVar *instruction) {1463static void ir_print_switch_var(IrPrintSrc *irp, IrInstSrcSwitchVar *instruction) {
1144 fprintf(irp->f, "switchvar ");1464 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);
1146 for (size_t i = 0; i < instruction->prongs_len; i += 1) {1466 for (size_t i = 0; i < instruction->prongs_len; i += 1) {
1147 fprintf(irp->f, ", ");1467 fprintf(irp->f, ", ");
1148 ir_print_other_instruction(irp, instruction->prongs_ptr[i]);1468 ir_print_other_inst_src(irp, instruction->prongs_ptr[i]);
1149 }1469 }
1150}1470}
11511471
1152static void ir_print_switch_else_var(IrPrint *irp, IrInstructionSwitchElseVar *instruction) {1472static void ir_print_switch_else_var(IrPrintSrc *irp, IrInstSrcSwitchElseVar *instruction) {
1153 fprintf(irp->f, "switchelsevar ");1473 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);
1155}1475}
11561476
1157static void ir_print_switch_target(IrPrint *irp, IrInstructionSwitchTarget *instruction) {1477static void ir_print_switch_target(IrPrintSrc *irp, IrInstSrcSwitchTarget *instruction) {
1158 fprintf(irp->f, "switchtarget ");1478 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);
1160}1480}
11611481
1162static void ir_print_union_tag(IrPrint *irp, IrInstructionUnionTag *instruction) {1482static void ir_print_union_tag(IrPrintGen *irp, IrInstGenUnionTag *instruction) {
1163 fprintf(irp->f, "uniontag ");1483 fprintf(irp->f, "uniontag ");
1164 ir_print_other_instruction(irp, instruction->value);1484 ir_print_other_inst_gen(irp, instruction->value);
1165}1485}
11661486
1167static void ir_print_import(IrPrint *irp, IrInstructionImport *instruction) {1487static void ir_print_import(IrPrintSrc *irp, IrInstSrcImport *instruction) {
1168 fprintf(irp->f, "@import(");1488 fprintf(irp->f, "@import(");
1169 ir_print_other_instruction(irp, instruction->name);1489 ir_print_other_inst_src(irp, instruction->name);
1170 fprintf(irp->f, ")");1490 fprintf(irp->f, ")");
1171}1491}
11721492
1173static void ir_print_ref(IrPrint *irp, IrInstructionRef *instruction) {1493static void ir_print_ref(IrPrintSrc *irp, IrInstSrcRef *instruction) {
1174 const char *const_str = instruction->is_const ? "const " : "";1494 const char *const_str = instruction->is_const ? "const " : "";
1175 const char *volatile_str = instruction->is_volatile ? "volatile " : "";1495 const char *volatile_str = instruction->is_volatile ? "volatile " : "";
1176 fprintf(irp->f, "%s%sref ", const_str, volatile_str);1496 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);
1178}1498}
11791499
1180static void ir_print_ref_gen(IrPrint *irp, IrInstructionRefGen *instruction) {1500static void ir_print_ref_gen(IrPrintGen *irp, IrInstGenRef *instruction) {
1181 fprintf(irp->f, "@ref(");1501 fprintf(irp->f, "@ref(");
1182 ir_print_other_instruction(irp, instruction->operand);1502 ir_print_other_inst_gen(irp, instruction->operand);
1183 fprintf(irp->f, ")result=");1503 fprintf(irp->f, ")result=");
1184 ir_print_other_instruction(irp, instruction->result_loc);1504 ir_print_other_inst_gen(irp, instruction->result_loc);
1185}1505}
11861506
1187static void ir_print_compile_err(IrPrint *irp, IrInstructionCompileErr *instruction) {1507static void ir_print_compile_err(IrPrintSrc *irp, IrInstSrcCompileErr *instruction) {
1188 fprintf(irp->f, "@compileError(");1508 fprintf(irp->f, "@compileError(");
1189 ir_print_other_instruction(irp, instruction->msg);1509 ir_print_other_inst_src(irp, instruction->msg);
1190 fprintf(irp->f, ")");1510 fprintf(irp->f, ")");
1191}1511}
11921512
1193static void ir_print_compile_log(IrPrint *irp, IrInstructionCompileLog *instruction) {1513static void ir_print_compile_log(IrPrintSrc *irp, IrInstSrcCompileLog *instruction) {
1194 fprintf(irp->f, "@compileLog(");1514 fprintf(irp->f, "@compileLog(");
1195 for (size_t i = 0; i < instruction->msg_count; i += 1) {1515 for (size_t i = 0; i < instruction->msg_count; i += 1) {
1196 if (i != 0)1516 if (i != 0)
1197 fprintf(irp->f, ",");1517 fprintf(irp->f, ",");
1198 IrInstruction *msg = instruction->msg_list[i];1518 IrInstSrc *msg = instruction->msg_list[i];
1199 ir_print_other_instruction(irp, msg);1519 ir_print_other_inst_src(irp, msg);
1200 }1520 }
1201 fprintf(irp->f, ")");1521 fprintf(irp->f, ")");
1202}1522}
12031523
1204static void ir_print_err_name(IrPrint *irp, IrInstructionErrName *instruction) {1524static void ir_print_err_name(IrPrintSrc *irp, IrInstSrcErrName *instruction) {
1205 fprintf(irp->f, "@errorName(");1525 fprintf(irp->f, "@errorName(");
1206 ir_print_other_instruction(irp, instruction->value);1526 ir_print_other_inst_src(irp, instruction->value);
1207 fprintf(irp->f, ")");1527 fprintf(irp->f, ")");
1208}1528}
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) {
1211 fprintf(irp->f, "@cImport(...)");1537 fprintf(irp->f, "@cImport(...)");
1212}1538}
12131539
1214static void ir_print_c_include(IrPrint *irp, IrInstructionCInclude *instruction) {1540static void ir_print_c_include(IrPrintSrc *irp, IrInstSrcCInclude *instruction) {
1215 fprintf(irp->f, "@cInclude(");1541 fprintf(irp->f, "@cInclude(");
1216 ir_print_other_instruction(irp, instruction->name);1542 ir_print_other_inst_src(irp, instruction->name);
1217 fprintf(irp->f, ")");1543 fprintf(irp->f, ")");
1218}1544}
12191545
1220static void ir_print_c_define(IrPrint *irp, IrInstructionCDefine *instruction) {1546static void ir_print_c_define(IrPrintSrc *irp, IrInstSrcCDefine *instruction) {
1221 fprintf(irp->f, "@cDefine(");1547 fprintf(irp->f, "@cDefine(");
1222 ir_print_other_instruction(irp, instruction->name);1548 ir_print_other_inst_src(irp, instruction->name);
1223 fprintf(irp->f, ", ");1549 fprintf(irp->f, ", ");
1224 ir_print_other_instruction(irp, instruction->value);1550 ir_print_other_inst_src(irp, instruction->value);
1225 fprintf(irp->f, ")");1551 fprintf(irp->f, ")");
1226}1552}
12271553
1228static void ir_print_c_undef(IrPrint *irp, IrInstructionCUndef *instruction) {1554static void ir_print_c_undef(IrPrintSrc *irp, IrInstSrcCUndef *instruction) {
1229 fprintf(irp->f, "@cUndef(");1555 fprintf(irp->f, "@cUndef(");
1230 ir_print_other_instruction(irp, instruction->name);1556 ir_print_other_inst_src(irp, instruction->name);
1231 fprintf(irp->f, ")");1557 fprintf(irp->f, ")");
1232}1558}
12331559
1234static void ir_print_embed_file(IrPrint *irp, IrInstructionEmbedFile *instruction) {1560static void ir_print_embed_file(IrPrintSrc *irp, IrInstSrcEmbedFile *instruction) {
1235 fprintf(irp->f, "@embedFile(");1561 fprintf(irp->f, "@embedFile(");
1236 ir_print_other_instruction(irp, instruction->name);1562 ir_print_other_inst_src(irp, instruction->name);
1237 fprintf(irp->f, ")");1563 fprintf(irp->f, ")");
1238}1564}
12391565
1240static void ir_print_cmpxchg_src(IrPrint *irp, IrInstructionCmpxchgSrc *instruction) {1566static void ir_print_cmpxchg_src(IrPrintSrc *irp, IrInstSrcCmpxchg *instruction) {
1241 fprintf(irp->f, "@cmpxchg(");1567 fprintf(irp->f, "@cmpxchg(");
1242 ir_print_other_instruction(irp, instruction->ptr);1568 ir_print_other_inst_src(irp, instruction->ptr);
1243 fprintf(irp->f, ", ");1569 fprintf(irp->f, ", ");
1244 ir_print_other_instruction(irp, instruction->cmp_value);1570 ir_print_other_inst_src(irp, instruction->cmp_value);
1245 fprintf(irp->f, ", ");1571 fprintf(irp->f, ", ");
1246 ir_print_other_instruction(irp, instruction->new_value);1572 ir_print_other_inst_src(irp, instruction->new_value);
1247 fprintf(irp->f, ", ");1573 fprintf(irp->f, ", ");
1248 ir_print_other_instruction(irp, instruction->success_order_value);1574 ir_print_other_inst_src(irp, instruction->success_order_value);
1249 fprintf(irp->f, ", ");1575 fprintf(irp->f, ", ");
1250 ir_print_other_instruction(irp, instruction->failure_order_value);1576 ir_print_other_inst_src(irp, instruction->failure_order_value);
1251 fprintf(irp->f, ")result=");1577 fprintf(irp->f, ")result=");
1252 ir_print_result_loc(irp, instruction->result_loc);1578 ir_print_result_loc(irp, instruction->result_loc);
1253}1579}
12541580
1255static void ir_print_cmpxchg_gen(IrPrint *irp, IrInstructionCmpxchgGen *instruction) {1581static void ir_print_cmpxchg_gen(IrPrintGen *irp, IrInstGenCmpxchg *instruction) {
1256 fprintf(irp->f, "@cmpxchg(");1582 fprintf(irp->f, "@cmpxchg(");
1257 ir_print_other_instruction(irp, instruction->ptr);1583 ir_print_other_inst_gen(irp, instruction->ptr);
1258 fprintf(irp->f, ", ");1584 fprintf(irp->f, ", ");
1259 ir_print_other_instruction(irp, instruction->cmp_value);1585 ir_print_other_inst_gen(irp, instruction->cmp_value);
1260 fprintf(irp->f, ", ");1586 fprintf(irp->f, ", ");
1261 ir_print_other_instruction(irp, instruction->new_value);1587 ir_print_other_inst_gen(irp, instruction->new_value);
1262 fprintf(irp->f, ", TODO print atomic orders)result=");1588 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);
1264}1590}
12651591
1266static void ir_print_fence(IrPrint *irp, IrInstructionFence *instruction) {1592static void ir_print_fence(IrPrintSrc *irp, IrInstSrcFence *instruction) {
1267 fprintf(irp->f, "@fence(");1593 fprintf(irp->f, "@fence(");
1268 ir_print_other_instruction(irp, instruction->order_value);1594 ir_print_other_inst_src(irp, instruction->order);
1269 fprintf(irp->f, ")");1595 fprintf(irp->f, ")");
1270}1596}
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) {
1273 fprintf(irp->f, "@truncate(");1615 fprintf(irp->f, "@truncate(");
1274 ir_print_other_instruction(irp, instruction->dest_type);1616 ir_print_other_inst_src(irp, instruction->dest_type);
1275 fprintf(irp->f, ", ");1617 fprintf(irp->f, ", ");
1276 ir_print_other_instruction(irp, instruction->target);1618 ir_print_other_inst_src(irp, instruction->target);
1277 fprintf(irp->f, ")");1619 fprintf(irp->f, ")");
1278}1620}
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) {
1281 fprintf(irp->f, "@intCast(");1629 fprintf(irp->f, "@intCast(");
1282 ir_print_other_instruction(irp, instruction->dest_type);1630 ir_print_other_inst_src(irp, instruction->dest_type);
1283 fprintf(irp->f, ", ");1631 fprintf(irp->f, ", ");
1284 ir_print_other_instruction(irp, instruction->target);1632 ir_print_other_inst_src(irp, instruction->target);
1285 fprintf(irp->f, ")");1633 fprintf(irp->f, ")");
1286}1634}
12871635
1288static void ir_print_float_cast(IrPrint *irp, IrInstructionFloatCast *instruction) {1636static void ir_print_float_cast(IrPrintSrc *irp, IrInstSrcFloatCast *instruction) {
1289 fprintf(irp->f, "@floatCast(");1637 fprintf(irp->f, "@floatCast(");
1290 ir_print_other_instruction(irp, instruction->dest_type);1638 ir_print_other_inst_src(irp, instruction->dest_type);
1291 fprintf(irp->f, ", ");1639 fprintf(irp->f, ", ");
1292 ir_print_other_instruction(irp, instruction->target);1640 ir_print_other_inst_src(irp, instruction->target);
1293 fprintf(irp->f, ")");1641 fprintf(irp->f, ")");
1294}1642}
12951643
1296static void ir_print_err_set_cast(IrPrint *irp, IrInstructionErrSetCast *instruction) {1644static void ir_print_err_set_cast(IrPrintSrc *irp, IrInstSrcErrSetCast *instruction) {
1297 fprintf(irp->f, "@errSetCast(");1645 fprintf(irp->f, "@errSetCast(");
1298 ir_print_other_instruction(irp, instruction->dest_type);1646 ir_print_other_inst_src(irp, instruction->dest_type);
1299 fprintf(irp->f, ", ");1647 fprintf(irp->f, ", ");
1300 ir_print_other_instruction(irp, instruction->target);1648 ir_print_other_inst_src(irp, instruction->target);
1301 fprintf(irp->f, ")");1649 fprintf(irp->f, ")");
1302}1650}
13031651
1304static void ir_print_from_bytes(IrPrint *irp, IrInstructionFromBytes *instruction) {1652static void ir_print_from_bytes(IrPrintSrc *irp, IrInstSrcFromBytes *instruction) {
1305 fprintf(irp->f, "@bytesToSlice(");1653 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);
1307 fprintf(irp->f, ", ");1655 fprintf(irp->f, ", ");
1308 ir_print_other_instruction(irp, instruction->target);1656 ir_print_other_inst_src(irp, instruction->target);
1309 fprintf(irp->f, ")");1657 fprintf(irp->f, ")");
1310}1658}
13111659
1312static void ir_print_to_bytes(IrPrint *irp, IrInstructionToBytes *instruction) {1660static void ir_print_to_bytes(IrPrintSrc *irp, IrInstSrcToBytes *instruction) {
1313 fprintf(irp->f, "@sliceToBytes(");1661 fprintf(irp->f, "@sliceToBytes(");
1314 ir_print_other_instruction(irp, instruction->target);1662 ir_print_other_inst_src(irp, instruction->target);
1315 fprintf(irp->f, ")");1663 fprintf(irp->f, ")");
1316}1664}
13171665
1318static void ir_print_int_to_float(IrPrint *irp, IrInstructionIntToFloat *instruction) {1666static void ir_print_int_to_float(IrPrintSrc *irp, IrInstSrcIntToFloat *instruction) {
1319 fprintf(irp->f, "@intToFloat(");1667 fprintf(irp->f, "@intToFloat(");
1320 ir_print_other_instruction(irp, instruction->dest_type);1668 ir_print_other_inst_src(irp, instruction->dest_type);
1321 fprintf(irp->f, ", ");1669 fprintf(irp->f, ", ");
1322 ir_print_other_instruction(irp, instruction->target);1670 ir_print_other_inst_src(irp, instruction->target);
1323 fprintf(irp->f, ")");1671 fprintf(irp->f, ")");
1324}1672}
13251673
1326static void ir_print_float_to_int(IrPrint *irp, IrInstructionFloatToInt *instruction) {1674static void ir_print_float_to_int(IrPrintSrc *irp, IrInstSrcFloatToInt *instruction) {
1327 fprintf(irp->f, "@floatToInt(");1675 fprintf(irp->f, "@floatToInt(");
1328 ir_print_other_instruction(irp, instruction->dest_type);1676 ir_print_other_inst_src(irp, instruction->dest_type);
1329 fprintf(irp->f, ", ");1677 fprintf(irp->f, ", ");
1330 ir_print_other_instruction(irp, instruction->target);1678 ir_print_other_inst_src(irp, instruction->target);
1331 fprintf(irp->f, ")");1679 fprintf(irp->f, ")");
1332}1680}
13331681
1334static void ir_print_bool_to_int(IrPrint *irp, IrInstructionBoolToInt *instruction) {1682static void ir_print_bool_to_int(IrPrintSrc *irp, IrInstSrcBoolToInt *instruction) {
1335 fprintf(irp->f, "@boolToInt(");1683 fprintf(irp->f, "@boolToInt(");
1336 ir_print_other_instruction(irp, instruction->target);1684 ir_print_other_inst_src(irp, instruction->target);
1337 fprintf(irp->f, ")");1685 fprintf(irp->f, ")");
1338}1686}
13391687
1340static void ir_print_int_type(IrPrint *irp, IrInstructionIntType *instruction) {1688static void ir_print_int_type(IrPrintSrc *irp, IrInstSrcIntType *instruction) {
1341 fprintf(irp->f, "@IntType(");1689 fprintf(irp->f, "@IntType(");
1342 ir_print_other_instruction(irp, instruction->is_signed);1690 ir_print_other_inst_src(irp, instruction->is_signed);
1343 fprintf(irp->f, ", ");1691 fprintf(irp->f, ", ");
1344 ir_print_other_instruction(irp, instruction->bit_count);1692 ir_print_other_inst_src(irp, instruction->bit_count);
1345 fprintf(irp->f, ")");1693 fprintf(irp->f, ")");
1346}1694}
13471695
1348static void ir_print_vector_type(IrPrint *irp, IrInstructionVectorType *instruction) {1696static void ir_print_vector_type(IrPrintSrc *irp, IrInstSrcVectorType *instruction) {
1349 fprintf(irp->f, "@Vector(");1697 fprintf(irp->f, "@Vector(");
1350 ir_print_other_instruction(irp, instruction->len);1698 ir_print_other_inst_src(irp, instruction->len);
1351 fprintf(irp->f, ", ");1699 fprintf(irp->f, ", ");
1352 ir_print_other_instruction(irp, instruction->elem_type);1700 ir_print_other_inst_src(irp, instruction->elem_type);
1353 fprintf(irp->f, ")");1701 fprintf(irp->f, ")");
1354}1702}
13551703
1356static void ir_print_shuffle_vector(IrPrint *irp, IrInstructionShuffleVector *instruction) {1704static void ir_print_shuffle_vector(IrPrintSrc *irp, IrInstSrcShuffleVector *instruction) {
1357 fprintf(irp->f, "@shuffle(");1705 fprintf(irp->f, "@shuffle(");
1358 ir_print_other_instruction(irp, instruction->scalar_type);1706 ir_print_other_inst_src(irp, instruction->scalar_type);
1359 fprintf(irp->f, ", ");1707 fprintf(irp->f, ", ");
1360 ir_print_other_instruction(irp, instruction->a);1708 ir_print_other_inst_src(irp, instruction->a);
1361 fprintf(irp->f, ", ");1709 fprintf(irp->f, ", ");
1362 ir_print_other_instruction(irp, instruction->b);1710 ir_print_other_inst_src(irp, instruction->b);
1363 fprintf(irp->f, ", ");1711 fprintf(irp->f, ", ");
1364 ir_print_other_instruction(irp, instruction->mask);1712 ir_print_other_inst_src(irp, instruction->mask);
1365 fprintf(irp->f, ")");1713 fprintf(irp->f, ")");
1366}1714}
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) {
1369 fprintf(irp->f, "@splat(");1727 fprintf(irp->f, "@splat(");
1370 ir_print_other_instruction(irp, instruction->len);1728 ir_print_other_inst_src(irp, instruction->len);
1371 fprintf(irp->f, ", ");1729 fprintf(irp->f, ", ");
1372 ir_print_other_instruction(irp, instruction->scalar);1730 ir_print_other_inst_src(irp, instruction->scalar);
1373 fprintf(irp->f, ")");1731 fprintf(irp->f, ")");
1374}1732}
13751733
1376static void ir_print_splat_gen(IrPrint *irp, IrInstructionSplatGen *instruction) {1734static void ir_print_splat_gen(IrPrintGen *irp, IrInstGenSplat *instruction) {
1377 fprintf(irp->f, "@splat(");1735 fprintf(irp->f, "@splat(");
1378 ir_print_other_instruction(irp, instruction->scalar);1736 ir_print_other_inst_gen(irp, instruction->scalar);
1379 fprintf(irp->f, ")");1737 fprintf(irp->f, ")");
1380}1738}
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) {
1383 fprintf(irp->f, "! ");1746 fprintf(irp->f, "! ");
1384 ir_print_other_instruction(irp, instruction->value);1747 ir_print_other_inst_gen(irp, instruction->value);
1385}1748}
13861749
1387static void ir_print_memset(IrPrint *irp, IrInstructionMemset *instruction) {1750static void ir_print_memset(IrPrintSrc *irp, IrInstSrcMemset *instruction) {
1388 fprintf(irp->f, "@memset(");1751 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);
1390 fprintf(irp->f, ", ");1773 fprintf(irp->f, ", ");
1391 ir_print_other_instruction(irp, instruction->byte);1774 ir_print_other_inst_src(irp, instruction->src_ptr);
1392 fprintf(irp->f, ", ");1775 fprintf(irp->f, ", ");
1393 ir_print_other_instruction(irp, instruction->count);1776 ir_print_other_inst_src(irp, instruction->count);
1394 fprintf(irp->f, ")");1777 fprintf(irp->f, ")");
1395}1778}
13961779
1397static void ir_print_memcpy(IrPrint *irp, IrInstructionMemcpy *instruction) {1780static void ir_print_memcpy(IrPrintGen *irp, IrInstGenMemcpy *instruction) {
1398 fprintf(irp->f, "@memcpy(");1781 fprintf(irp->f, "@memcpy(");
1399 ir_print_other_instruction(irp, instruction->dest_ptr);1782 ir_print_other_inst_gen(irp, instruction->dest_ptr);
1400 fprintf(irp->f, ", ");1783 fprintf(irp->f, ", ");
1401 ir_print_other_instruction(irp, instruction->src_ptr);1784 ir_print_other_inst_gen(irp, instruction->src_ptr);
1402 fprintf(irp->f, ", ");1785 fprintf(irp->f, ", ");
1403 ir_print_other_instruction(irp, instruction->count);1786 ir_print_other_inst_gen(irp, instruction->count);
1404 fprintf(irp->f, ")");1787 fprintf(irp->f, ")");
1405}1788}
14061789
1407static void ir_print_slice_src(IrPrint *irp, IrInstructionSliceSrc *instruction) {1790static void ir_print_slice_src(IrPrintSrc *irp, IrInstSrcSlice *instruction) {
1408 ir_print_other_instruction(irp, instruction->ptr);1791 ir_print_other_inst_src(irp, instruction->ptr);
1409 fprintf(irp->f, "[");1792 fprintf(irp->f, "[");
1410 ir_print_other_instruction(irp, instruction->start);1793 ir_print_other_inst_src(irp, instruction->start);
1411 fprintf(irp->f, "..");1794 fprintf(irp->f, "..");
1412 if (instruction->end)1795 if (instruction->end)
1413 ir_print_other_instruction(irp, instruction->end);1796 ir_print_other_inst_src(irp, instruction->end);
1414 fprintf(irp->f, "]result=");1797 fprintf(irp->f, "]result=");
1415 ir_print_result_loc(irp, instruction->result_loc);1798 ir_print_result_loc(irp, instruction->result_loc);
1416}1799}
14171800
1418static void ir_print_slice_gen(IrPrint *irp, IrInstructionSliceGen *instruction) {1801static void ir_print_slice_gen(IrPrintGen *irp, IrInstGenSlice *instruction) {
1419 ir_print_other_instruction(irp, instruction->ptr);1802 ir_print_other_inst_gen(irp, instruction->ptr);
1420 fprintf(irp->f, "[");1803 fprintf(irp->f, "[");
1421 ir_print_other_instruction(irp, instruction->start);1804 ir_print_other_inst_gen(irp, instruction->start);
1422 fprintf(irp->f, "..");1805 fprintf(irp->f, "..");
1423 if (instruction->end)1806 if (instruction->end)
1424 ir_print_other_instruction(irp, instruction->end);1807 ir_print_other_inst_gen(irp, instruction->end);
1425 fprintf(irp->f, "]result=");1808 fprintf(irp->f, "]result=");
1426 ir_print_other_instruction(irp, instruction->result_loc);1809 ir_print_other_inst_gen(irp, instruction->result_loc);
1427}1810}
14281811
1429static void ir_print_member_count(IrPrint *irp, IrInstructionMemberCount *instruction) {1812static void ir_print_member_count(IrPrintSrc *irp, IrInstSrcMemberCount *instruction) {
1430 fprintf(irp->f, "@memberCount(");1813 fprintf(irp->f, "@memberCount(");
1431 ir_print_other_instruction(irp, instruction->container);1814 ir_print_other_inst_src(irp, instruction->container);
1432 fprintf(irp->f, ")");1815 fprintf(irp->f, ")");
1433}1816}
14341817
1435static void ir_print_member_type(IrPrint *irp, IrInstructionMemberType *instruction) {1818static void ir_print_member_type(IrPrintSrc *irp, IrInstSrcMemberType *instruction) {
1436 fprintf(irp->f, "@memberType(");1819 fprintf(irp->f, "@memberType(");
1437 ir_print_other_instruction(irp, instruction->container_type);1820 ir_print_other_inst_src(irp, instruction->container_type);
1438 fprintf(irp->f, ", ");1821 fprintf(irp->f, ", ");
1439 ir_print_other_instruction(irp, instruction->member_index);1822 ir_print_other_inst_src(irp, instruction->member_index);
1440 fprintf(irp->f, ")");1823 fprintf(irp->f, ")");
1441}1824}
14421825
1443static void ir_print_member_name(IrPrint *irp, IrInstructionMemberName *instruction) {1826static void ir_print_member_name(IrPrintSrc *irp, IrInstSrcMemberName *instruction) {
1444 fprintf(irp->f, "@memberName(");1827 fprintf(irp->f, "@memberName(");
1445 ir_print_other_instruction(irp, instruction->container_type);1828 ir_print_other_inst_src(irp, instruction->container_type);
1446 fprintf(irp->f, ", ");1829 fprintf(irp->f, ", ");
1447 ir_print_other_instruction(irp, instruction->member_index);1830 ir_print_other_inst_src(irp, instruction->member_index);
1448 fprintf(irp->f, ")");1831 fprintf(irp->f, ")");
1449}1832}
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) {
1452 fprintf(irp->f, "@breakpoint()");1839 fprintf(irp->f, "@breakpoint()");
1453}1840}
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) {
1456 fprintf(irp->f, "@frameAddress()");1847 fprintf(irp->f, "@frameAddress()");
1457}1848}
14581849
1459static void ir_print_handle(IrPrint *irp, IrInstructionFrameHandle *instruction) {1850static void ir_print_handle(IrPrintSrc *irp, IrInstSrcFrameHandle *instruction) {
1460 fprintf(irp->f, "@frame()");1851 fprintf(irp->f, "@frame()");
1461}1852}
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) {
1464 fprintf(irp->f, "@Frame(");1859 fprintf(irp->f, "@Frame(");
1465 ir_print_other_instruction(irp, instruction->fn);1860 ir_print_other_inst_src(irp, instruction->fn);
1466 fprintf(irp->f, ")");1861 fprintf(irp->f, ")");
1467}1862}
14681863
1469static void ir_print_frame_size_src(IrPrint *irp, IrInstructionFrameSizeSrc *instruction) {1864static void ir_print_frame_size_src(IrPrintSrc *irp, IrInstSrcFrameSize *instruction) {
1470 fprintf(irp->f, "@frameSize(");1865 fprintf(irp->f, "@frameSize(");
1471 ir_print_other_instruction(irp, instruction->fn);1866 ir_print_other_inst_src(irp, instruction->fn);
1472 fprintf(irp->f, ")");1867 fprintf(irp->f, ")");
1473}1868}
14741869
1475static void ir_print_frame_size_gen(IrPrint *irp, IrInstructionFrameSizeGen *instruction) {1870static void ir_print_frame_size_gen(IrPrintGen *irp, IrInstGenFrameSize *instruction) {
1476 fprintf(irp->f, "@frameSize(");1871 fprintf(irp->f, "@frameSize(");
1477 ir_print_other_instruction(irp, instruction->fn);1872 ir_print_other_inst_gen(irp, instruction->fn);
1478 fprintf(irp->f, ")");1873 fprintf(irp->f, ")");
1479}1874}
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) {
1482 fprintf(irp->f, "@returnAddress()");1881 fprintf(irp->f, "@returnAddress()");
1483}1882}
14841883
1485static void ir_print_align_of(IrPrint *irp, IrInstructionAlignOf *instruction) {1884static void ir_print_align_of(IrPrintSrc *irp, IrInstSrcAlignOf *instruction) {
1486 fprintf(irp->f, "@alignOf(");1885 fprintf(irp->f, "@alignOf(");
1487 ir_print_other_instruction(irp, instruction->type_value);1886 ir_print_other_inst_src(irp, instruction->type_value);
1488 fprintf(irp->f, ")");1887 fprintf(irp->f, ")");
1489}1888}
14901889
1491static void ir_print_overflow_op(IrPrint *irp, IrInstructionOverflowOp *instruction) {1890static void ir_print_overflow_op(IrPrintSrc *irp, IrInstSrcOverflowOp *instruction) {
1492 switch (instruction->op) {1891 switch (instruction->op) {
1493 case IrOverflowOpAdd:1892 case IrOverflowOpAdd:
1494 fprintf(irp->f, "@addWithOverflow(");1893 fprintf(irp->f, "@addWithOverflow(");
...@@ -1503,1146 +1902,1457 @@ static void ir_print_overflow_op(IrPrint *irp, IrInstructionOverflowOp *instruct...@@ -1503,1146 +1902,1457 @@ static void ir_print_overflow_op(IrPrint *irp, IrInstructionOverflowOp *instruct
1503 fprintf(irp->f, "@shlWithOverflow(");1902 fprintf(irp->f, "@shlWithOverflow(");
1504 break;1903 break;
1505 }1904 }
1506 ir_print_other_instruction(irp, instruction->type_value);1905 ir_print_other_inst_src(irp, instruction->type_value);
1507 fprintf(irp->f, ", ");1906 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);
1509 fprintf(irp->f, ", ");1931 fprintf(irp->f, ", ");
1510 ir_print_other_instruction(irp, instruction->op2);1932 ir_print_other_inst_gen(irp, instruction->op2);
1511 fprintf(irp->f, ", ");1933 fprintf(irp->f, ", ");
1512 ir_print_other_instruction(irp, instruction->result_ptr);1934 ir_print_other_inst_gen(irp, instruction->result_ptr);
1513 fprintf(irp->f, ")");1935 fprintf(irp->f, ")");
1514}1936}
15151937
1516static void ir_print_test_err_src(IrPrint *irp, IrInstructionTestErrSrc *instruction) {1938static void ir_print_test_err_src(IrPrintSrc *irp, IrInstSrcTestErr *instruction) {
1517 fprintf(irp->f, "@testError(");1939 fprintf(irp->f, "@testError(");
1518 ir_print_other_instruction(irp, instruction->base_ptr);1940 ir_print_other_inst_src(irp, instruction->base_ptr);
1519 fprintf(irp->f, ")");1941 fprintf(irp->f, ")");
1520}1942}
15211943
1522static void ir_print_test_err_gen(IrPrint *irp, IrInstructionTestErrGen *instruction) {1944static void ir_print_test_err_gen(IrPrintGen *irp, IrInstGenTestErr *instruction) {
1523 fprintf(irp->f, "@testError(");1945 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);
1525 fprintf(irp->f, ")");1953 fprintf(irp->f, ")");
1526}1954}
15271955
1528static void ir_print_unwrap_err_code(IrPrint *irp, IrInstructionUnwrapErrCode *instruction) {1956static void ir_print_unwrap_err_code(IrPrintGen *irp, IrInstGenUnwrapErrCode *instruction) {
1529 fprintf(irp->f, "UnwrapErrorCode(");1957 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);
1531 fprintf(irp->f, ")");1959 fprintf(irp->f, ")");
1532}1960}
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) {
1535 fprintf(irp->f, "ErrorUnionFieldPayload(");1969 fprintf(irp->f, "ErrorUnionFieldPayload(");
1536 ir_print_other_instruction(irp, instruction->value);1970 ir_print_other_inst_gen(irp, instruction->value);
1537 fprintf(irp->f, ")safety=%d,init=%d",instruction->safety_check_on, instruction->initializing);1971 fprintf(irp->f, ")safety=%d,init=%d",instruction->safety_check_on, instruction->initializing);
1538}1972}
15391973
1540static void ir_print_optional_wrap(IrPrint *irp, IrInstructionOptionalWrap *instruction) {1974static void ir_print_optional_wrap(IrPrintGen *irp, IrInstGenOptionalWrap *instruction) {
1541 fprintf(irp->f, "@optionalWrap(");1975 fprintf(irp->f, "@optionalWrap(");
1542 ir_print_other_instruction(irp, instruction->operand);1976 ir_print_other_inst_gen(irp, instruction->operand);
1543 fprintf(irp->f, ")result=");1977 fprintf(irp->f, ")result=");
1544 ir_print_other_instruction(irp, instruction->result_loc);1978 ir_print_other_inst_gen(irp, instruction->result_loc);
1545}1979}
15461980
1547static void ir_print_err_wrap_code(IrPrint *irp, IrInstructionErrWrapCode *instruction) {1981static void ir_print_err_wrap_code(IrPrintGen *irp, IrInstGenErrWrapCode *instruction) {
1548 fprintf(irp->f, "@errWrapCode(");1982 fprintf(irp->f, "@errWrapCode(");
1549 ir_print_other_instruction(irp, instruction->operand);1983 ir_print_other_inst_gen(irp, instruction->operand);
1550 fprintf(irp->f, ")result=");1984 fprintf(irp->f, ")result=");
1551 ir_print_other_instruction(irp, instruction->result_loc);1985 ir_print_other_inst_gen(irp, instruction->result_loc);
1552}1986}
15531987
1554static void ir_print_err_wrap_payload(IrPrint *irp, IrInstructionErrWrapPayload *instruction) {1988static void ir_print_err_wrap_payload(IrPrintGen *irp, IrInstGenErrWrapPayload *instruction) {
1555 fprintf(irp->f, "@errWrapPayload(");1989 fprintf(irp->f, "@errWrapPayload(");
1556 ir_print_other_instruction(irp, instruction->operand);1990 ir_print_other_inst_gen(irp, instruction->operand);
1557 fprintf(irp->f, ")result=");1991 fprintf(irp->f, ")result=");
1558 ir_print_other_instruction(irp, instruction->result_loc);1992 ir_print_other_inst_gen(irp, instruction->result_loc);
1559}1993}
15601994
1561static void ir_print_fn_proto(IrPrint *irp, IrInstructionFnProto *instruction) {1995static void ir_print_fn_proto(IrPrintSrc *irp, IrInstSrcFnProto *instruction) {
1562 fprintf(irp->f, "fn(");1996 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) {
1564 if (i != 0)1998 if (i != 0)
1565 fprintf(irp->f, ",");1999 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) {
1567 fprintf(irp->f, "...");2001 fprintf(irp->f, "...");
1568 } else {2002 } else {
1569 ir_print_other_instruction(irp, instruction->param_types[i]);2003 ir_print_other_inst_src(irp, instruction->param_types[i]);
1570 }2004 }
1571 }2005 }
1572 fprintf(irp->f, ")");2006 fprintf(irp->f, ")");
1573 if (instruction->align_value != nullptr) {2007 if (instruction->align_value != nullptr) {
1574 fprintf(irp->f, " align ");2008 fprintf(irp->f, " align ");
1575 ir_print_other_instruction(irp, instruction->align_value);2009 ir_print_other_inst_src(irp, instruction->align_value);
1576 fprintf(irp->f, " ");2010 fprintf(irp->f, " ");
1577 }2011 }
1578 fprintf(irp->f, "->");2012 fprintf(irp->f, "->");
1579 ir_print_other_instruction(irp, instruction->return_type);2013 ir_print_other_inst_src(irp, instruction->return_type);
1580}2014}
15812015
1582static void ir_print_test_comptime(IrPrint *irp, IrInstructionTestComptime *instruction) {2016static void ir_print_test_comptime(IrPrintSrc *irp, IrInstSrcTestComptime *instruction) {
1583 fprintf(irp->f, "@testComptime(");2017 fprintf(irp->f, "@testComptime(");
1584 ir_print_other_instruction(irp, instruction->value);2018 ir_print_other_inst_src(irp, instruction->value);
1585 fprintf(irp->f, ")");2019 fprintf(irp->f, ")");
1586}2020}
15872021
1588static void ir_print_ptr_cast_src(IrPrint *irp, IrInstructionPtrCastSrc *instruction) {2022static void ir_print_ptr_cast_src(IrPrintSrc *irp, IrInstSrcPtrCast *instruction) {
1589 fprintf(irp->f, "@ptrCast(");2023 fprintf(irp->f, "@ptrCast(");
1590 if (instruction->dest_type) {2024 if (instruction->dest_type) {
1591 ir_print_other_instruction(irp, instruction->dest_type);2025 ir_print_other_inst_src(irp, instruction->dest_type);
1592 }2026 }
1593 fprintf(irp->f, ",");2027 fprintf(irp->f, ",");
1594 ir_print_other_instruction(irp, instruction->ptr);2028 ir_print_other_inst_src(irp, instruction->ptr);
1595 fprintf(irp->f, ")");2029 fprintf(irp->f, ")");
1596}2030}
15972031
1598static void ir_print_ptr_cast_gen(IrPrint *irp, IrInstructionPtrCastGen *instruction) {2032static void ir_print_ptr_cast_gen(IrPrintGen *irp, IrInstGenPtrCast *instruction) {
1599 fprintf(irp->f, "@ptrCast(");2033 fprintf(irp->f, "@ptrCast(");
1600 ir_print_other_instruction(irp, instruction->ptr);2034 ir_print_other_inst_gen(irp, instruction->ptr);
1601 fprintf(irp->f, ")");2035 fprintf(irp->f, ")");
1602}2036}
16032037
1604static void ir_print_implicit_cast(IrPrint *irp, IrInstructionImplicitCast *instruction) {2038static void ir_print_implicit_cast(IrPrintSrc *irp, IrInstSrcImplicitCast *instruction) {
1605 fprintf(irp->f, "@implicitCast(");2039 fprintf(irp->f, "@implicitCast(");
1606 ir_print_other_instruction(irp, instruction->operand);2040 ir_print_other_inst_src(irp, instruction->operand);
1607 fprintf(irp->f, ")result=");2041 fprintf(irp->f, ")result=");
1608 ir_print_result_loc(irp, &instruction->result_loc_cast->base);2042 ir_print_result_loc(irp, &instruction->result_loc_cast->base);
1609}2043}
16102044
1611static void ir_print_bit_cast_src(IrPrint *irp, IrInstructionBitCastSrc *instruction) {2045static void ir_print_bit_cast_src(IrPrintSrc *irp, IrInstSrcBitCast *instruction) {
1612 fprintf(irp->f, "@bitCast(");2046 fprintf(irp->f, "@bitCast(");
1613 ir_print_other_instruction(irp, instruction->operand);2047 ir_print_other_inst_src(irp, instruction->operand);
1614 fprintf(irp->f, ")result=");2048 fprintf(irp->f, ")result=");
1615 ir_print_result_loc(irp, &instruction->result_loc_bit_cast->base);2049 ir_print_result_loc(irp, &instruction->result_loc_bit_cast->base);
1616}2050}
16172051
1618static void ir_print_bit_cast_gen(IrPrint *irp, IrInstructionBitCastGen *instruction) {2052static void ir_print_bit_cast_gen(IrPrintGen *irp, IrInstGenBitCast *instruction) {
1619 fprintf(irp->f, "@bitCast(");2053 fprintf(irp->f, "@bitCast(");
1620 ir_print_other_instruction(irp, instruction->operand);2054 ir_print_other_inst_gen(irp, instruction->operand);
1621 fprintf(irp->f, ")");2055 fprintf(irp->f, ")");
1622}2056}
16232057
1624static void ir_print_widen_or_shorten(IrPrint *irp, IrInstructionWidenOrShorten *instruction) {2058static void ir_print_widen_or_shorten(IrPrintGen *irp, IrInstGenWidenOrShorten *instruction) {
1625 fprintf(irp->f, "WidenOrShorten(");2059 fprintf(irp->f, "WidenOrShorten(");
1626 ir_print_other_instruction(irp, instruction->target);2060 ir_print_other_inst_gen(irp, instruction->target);
1627 fprintf(irp->f, ")");2061 fprintf(irp->f, ")");
1628}2062}
16292063
1630static void ir_print_ptr_to_int(IrPrint *irp, IrInstructionPtrToInt *instruction) {2064static void ir_print_ptr_to_int(IrPrintSrc *irp, IrInstSrcPtrToInt *instruction) {
1631 fprintf(irp->f, "@ptrToInt(");2065 fprintf(irp->f, "@ptrToInt(");
1632 ir_print_other_instruction(irp, instruction->target);2066 ir_print_other_inst_src(irp, instruction->target);
1633 fprintf(irp->f, ")");2067 fprintf(irp->f, ")");
1634}2068}
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) {
1637 fprintf(irp->f, "@intToPtr(");2077 fprintf(irp->f, "@intToPtr(");
1638 if (instruction->dest_type == nullptr) {2078 ir_print_other_inst_src(irp, instruction->dest_type);
1639 fprintf(irp->f, "(null)");
1640 } else {
1641 ir_print_other_instruction(irp, instruction->dest_type);
1642 }
1643 fprintf(irp->f, ",");2079 fprintf(irp->f, ",");
1644 ir_print_other_instruction(irp, instruction->target);2080 ir_print_other_inst_src(irp, instruction->target);
1645 fprintf(irp->f, ")");2081 fprintf(irp->f, ")");
1646}2082}
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) {
1649 fprintf(irp->f, "@intToEnum(");2091 fprintf(irp->f, "@intToEnum(");
1650 if (instruction->dest_type == nullptr) {2092 ir_print_other_inst_src(irp, instruction->dest_type);
1651 fprintf(irp->f, "(null)");2093 fprintf(irp->f, ",");
1652 } else {2094 ir_print_other_inst_src(irp, instruction->target);
1653 ir_print_other_instruction(irp, instruction->dest_type);
1654 }
1655 ir_print_other_instruction(irp, instruction->target);
1656 fprintf(irp->f, ")");2095 fprintf(irp->f, ")");
1657}2096}
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) {
1660 fprintf(irp->f, "@enumToInt(");2105 fprintf(irp->f, "@enumToInt(");
1661 ir_print_other_instruction(irp, instruction->target);2106 ir_print_other_inst_src(irp, instruction->target);
1662 fprintf(irp->f, ")");2107 fprintf(irp->f, ")");
1663}2108}
16642109
1665static void ir_print_check_runtime_scope(IrPrint *irp, IrInstructionCheckRuntimeScope *instruction) {2110static void ir_print_check_runtime_scope(IrPrintSrc *irp, IrInstSrcCheckRuntimeScope *instruction) {
1666 fprintf(irp->f, "@checkRuntimeScope(");2111 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);
1668 fprintf(irp->f, ",");2113 fprintf(irp->f, ",");
1669 ir_print_other_instruction(irp, instruction->is_comptime);2114 ir_print_other_inst_src(irp, instruction->is_comptime);
1670 fprintf(irp->f, ")");2115 fprintf(irp->f, ")");
1671}2116}
16722117
1673static void ir_print_array_to_vector(IrPrint *irp, IrInstructionArrayToVector *instruction) {2118static void ir_print_array_to_vector(IrPrintGen *irp, IrInstGenArrayToVector *instruction) {
1674 fprintf(irp->f, "ArrayToVector(");2119 fprintf(irp->f, "ArrayToVector(");
1675 ir_print_other_instruction(irp, instruction->array);2120 ir_print_other_inst_gen(irp, instruction->array);
1676 fprintf(irp->f, ")");2121 fprintf(irp->f, ")");
1677}2122}
16782123
1679static void ir_print_vector_to_array(IrPrint *irp, IrInstructionVectorToArray *instruction) {2124static void ir_print_vector_to_array(IrPrintGen *irp, IrInstGenVectorToArray *instruction) {
1680 fprintf(irp->f, "VectorToArray(");2125 fprintf(irp->f, "VectorToArray(");
1681 ir_print_other_instruction(irp, instruction->vector);2126 ir_print_other_inst_gen(irp, instruction->vector);
1682 fprintf(irp->f, ")result=");2127 fprintf(irp->f, ")result=");
1683 ir_print_other_instruction(irp, instruction->result_loc);2128 ir_print_other_inst_gen(irp, instruction->result_loc);
1684}2129}
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) {
1687 fprintf(irp->f, "PtrOfArrayToSlice(");2132 fprintf(irp->f, "PtrOfArrayToSlice(");
1688 ir_print_other_instruction(irp, instruction->operand);2133 ir_print_other_inst_gen(irp, instruction->operand);
1689 fprintf(irp->f, ")result=");2134 fprintf(irp->f, ")result=");
1690 ir_print_other_instruction(irp, instruction->result_loc);2135 ir_print_other_inst_gen(irp, instruction->result_loc);
1691}2136}
16922137
1693static void ir_print_assert_zero(IrPrint *irp, IrInstructionAssertZero *instruction) {2138static void ir_print_assert_zero(IrPrintGen *irp, IrInstGenAssertZero *instruction) {
1694 fprintf(irp->f, "AssertZero(");2139 fprintf(irp->f, "AssertZero(");
1695 ir_print_other_instruction(irp, instruction->target);2140 ir_print_other_inst_gen(irp, instruction->target);
1696 fprintf(irp->f, ")");2141 fprintf(irp->f, ")");
1697}2142}
16982143
1699static void ir_print_assert_non_null(IrPrint *irp, IrInstructionAssertNonNull *instruction) {2144static void ir_print_assert_non_null(IrPrintGen *irp, IrInstGenAssertNonNull *instruction) {
1700 fprintf(irp->f, "AssertNonNull(");2145 fprintf(irp->f, "AssertNonNull(");
1701 ir_print_other_instruction(irp, instruction->target);2146 ir_print_other_inst_gen(irp, instruction->target);
1702 fprintf(irp->f, ")");2147 fprintf(irp->f, ")");
1703}2148}
17042149
1705static void ir_print_resize_slice(IrPrint *irp, IrInstructionResizeSlice *instruction) {2150static void ir_print_resize_slice(IrPrintGen *irp, IrInstGenResizeSlice *instruction) {
1706 fprintf(irp->f, "@resizeSlice(");2151 fprintf(irp->f, "@resizeSlice(");
1707 ir_print_other_instruction(irp, instruction->operand);2152 ir_print_other_inst_gen(irp, instruction->operand);
1708 fprintf(irp->f, ")result=");2153 fprintf(irp->f, ")result=");
1709 ir_print_other_instruction(irp, instruction->result_loc);2154 ir_print_other_inst_gen(irp, instruction->result_loc);
1710}2155}
17112156
1712static void ir_print_alloca_src(IrPrint *irp, IrInstructionAllocaSrc *instruction) {2157static void ir_print_alloca_src(IrPrintSrc *irp, IrInstSrcAlloca *instruction) {
1713 fprintf(irp->f, "Alloca(align=");2158 fprintf(irp->f, "Alloca(align=");
1714 ir_print_other_instruction(irp, instruction->align);2159 ir_print_other_inst_src(irp, instruction->align);
1715 fprintf(irp->f, ",name=%s)", instruction->name_hint);2160 fprintf(irp->f, ",name=%s)", instruction->name_hint);
1716}2161}
17172162
1718static void ir_print_alloca_gen(IrPrint *irp, IrInstructionAllocaGen *instruction) {2163static void ir_print_alloca_gen(IrPrintGen *irp, IrInstGenAlloca *instruction) {
1719 fprintf(irp->f, "Alloca(align=%" PRIu32 ",name=%s)", instruction->align, instruction->name_hint);2164 fprintf(irp->f, "Alloca(align=%" PRIu32 ",name=%s)", instruction->align, instruction->name_hint);
1720}2165}
17212166
1722static void ir_print_end_expr(IrPrint *irp, IrInstructionEndExpr *instruction) {2167static void ir_print_end_expr(IrPrintSrc *irp, IrInstSrcEndExpr *instruction) {
1723 fprintf(irp->f, "EndExpr(result=");2168 fprintf(irp->f, "EndExpr(result=");
1724 ir_print_result_loc(irp, instruction->result_loc);2169 ir_print_result_loc(irp, instruction->result_loc);
1725 fprintf(irp->f, ",value=");2170 fprintf(irp->f, ",value=");
1726 ir_print_other_instruction(irp, instruction->value);2171 ir_print_other_inst_src(irp, instruction->value);
1727 fprintf(irp->f, ")");2172 fprintf(irp->f, ")");
1728}2173}
17292174
1730static void ir_print_int_to_err(IrPrint *irp, IrInstructionIntToErr *instruction) {2175static void ir_print_int_to_err(IrPrintSrc *irp, IrInstSrcIntToErr *instruction) {
1731 fprintf(irp->f, "inttoerr ");2176 fprintf(irp->f, "inttoerr ");
1732 ir_print_other_instruction(irp, instruction->target);2177 ir_print_other_inst_src(irp, instruction->target);
1733}2178}
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) {
1736 fprintf(irp->f, "errtoint ");2191 fprintf(irp->f, "errtoint ");
1737 ir_print_other_instruction(irp, instruction->target);2192 ir_print_other_inst_gen(irp, instruction->target);
1738}2193}
17392194
1740static void ir_print_check_switch_prongs(IrPrint *irp, IrInstructionCheckSwitchProngs *instruction) {2195static void ir_print_check_switch_prongs(IrPrintSrc *irp, IrInstSrcCheckSwitchProngs *instruction) {
1741 fprintf(irp->f, "@checkSwitchProngs(");2196 fprintf(irp->f, "@checkSwitchProngs(");
1742 ir_print_other_instruction(irp, instruction->target_value);2197 ir_print_other_inst_src(irp, instruction->target_value);
1743 fprintf(irp->f, ",");2198 fprintf(irp->f, ",");
1744 for (size_t i = 0; i < instruction->range_count; i += 1) {2199 for (size_t i = 0; i < instruction->range_count; i += 1) {
1745 if (i != 0)2200 if (i != 0)
1746 fprintf(irp->f, ",");2201 fprintf(irp->f, ",");
1747 ir_print_other_instruction(irp, instruction->ranges[i].start);2202 ir_print_other_inst_src(irp, instruction->ranges[i].start);
1748 fprintf(irp->f, "...");2203 fprintf(irp->f, "...");
1749 ir_print_other_instruction(irp, instruction->ranges[i].end);2204 ir_print_other_inst_src(irp, instruction->ranges[i].end);
1750 }2205 }
1751 const char *have_else_str = instruction->have_else_prong ? "yes" : "no";2206 const char *have_else_str = instruction->have_else_prong ? "yes" : "no";
1752 fprintf(irp->f, ")else:%s", have_else_str);2207 fprintf(irp->f, ")else:%s", have_else_str);
1753}2208}
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) {
1756 fprintf(irp->f, "@checkStatementIsVoid(");2211 fprintf(irp->f, "@checkStatementIsVoid(");
1757 ir_print_other_instruction(irp, instruction->statement_value);2212 ir_print_other_inst_src(irp, instruction->statement_value);
1758 fprintf(irp->f, ")");2213 fprintf(irp->f, ")");
1759}2214}
17602215
1761static void ir_print_type_name(IrPrint *irp, IrInstructionTypeName *instruction) {2216static void ir_print_type_name(IrPrintSrc *irp, IrInstSrcTypeName *instruction) {
1762 fprintf(irp->f, "typename ");2217 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);
1764}2224}
17652225
1766static void ir_print_tag_name(IrPrint *irp, IrInstructionTagName *instruction) {2226static void ir_print_tag_name(IrPrintGen *irp, IrInstGenTagName *instruction) {
1767 fprintf(irp->f, "tagname ");2227 fprintf(irp->f, "tagname ");
1768 ir_print_other_instruction(irp, instruction->target);2228 ir_print_other_inst_gen(irp, instruction->target);
1769}2229}
17702230
1771static void ir_print_ptr_type(IrPrint *irp, IrInstructionPtrType *instruction) {2231static void ir_print_ptr_type(IrPrintSrc *irp, IrInstSrcPtrType *instruction) {
1772 fprintf(irp->f, "&");2232 fprintf(irp->f, "&");
1773 if (instruction->align_value != nullptr) {2233 if (instruction->align_value != nullptr) {
1774 fprintf(irp->f, "align(");2234 fprintf(irp->f, "align(");
1775 ir_print_other_instruction(irp, instruction->align_value);2235 ir_print_other_inst_src(irp, instruction->align_value);
1776 fprintf(irp->f, ")");2236 fprintf(irp->f, ")");
1777 }2237 }
1778 const char *const_str = instruction->is_const ? "const " : "";2238 const char *const_str = instruction->is_const ? "const " : "";
1779 const char *volatile_str = instruction->is_volatile ? "volatile " : "";2239 const char *volatile_str = instruction->is_volatile ? "volatile " : "";
1780 fprintf(irp->f, ":%" PRIu32 ":%" PRIu32 " %s%s", instruction->bit_offset_start, instruction->host_int_bytes,2240 fprintf(irp->f, ":%" PRIu32 ":%" PRIu32 " %s%s", instruction->bit_offset_start, instruction->host_int_bytes,
1781 const_str, volatile_str);2241 const_str, volatile_str);
1782 ir_print_other_instruction(irp, instruction->child_type);2242 ir_print_other_inst_src(irp, instruction->child_type);
1783}2243}
17842244
1785static void ir_print_decl_ref(IrPrint *irp, IrInstructionDeclRef *instruction) {2245static void ir_print_decl_ref(IrPrintSrc *irp, IrInstSrcDeclRef *instruction) {
1786 const char *ptr_str = (instruction->lval == LValPtr) ? "ptr " : "";2246 const char *ptr_str = (instruction->lval == LValPtr) ? "ptr " : "";
1787 fprintf(irp->f, "declref %s%s", ptr_str, buf_ptr(instruction->tld->name));2247 fprintf(irp->f, "declref %s%s", ptr_str, buf_ptr(instruction->tld->name));
1788}2248}
17892249
1790static void ir_print_panic(IrPrint *irp, IrInstructionPanic *instruction) {2250static void ir_print_panic(IrPrintSrc *irp, IrInstSrcPanic *instruction) {
1791 fprintf(irp->f, "@panic(");2251 fprintf(irp->f, "@panic(");
1792 ir_print_other_instruction(irp, instruction->msg);2252 ir_print_other_inst_src(irp, instruction->msg);
1793 fprintf(irp->f, ")");2253 fprintf(irp->f, ")");
1794}2254}
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) {
1797 fprintf(irp->f, "@fieldParentPtr(");2263 fprintf(irp->f, "@fieldParentPtr(");
1798 ir_print_other_instruction(irp, instruction->type_value);2264 ir_print_other_inst_src(irp, instruction->type_value);
1799 fprintf(irp->f, ",");2265 fprintf(irp->f, ",");
1800 ir_print_other_instruction(irp, instruction->field_name);2266 ir_print_other_inst_src(irp, instruction->field_name);
1801 fprintf(irp->f, ",");2267 fprintf(irp->f, ",");
1802 ir_print_other_instruction(irp, instruction->field_ptr);2268 ir_print_other_inst_src(irp, instruction->field_ptr);
1803 fprintf(irp->f, ")");2269 fprintf(irp->f, ")");
1804}2270}
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) {
1807 fprintf(irp->f, "@byte_offset_of(");2279 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);
1809 fprintf(irp->f, ",");2281 fprintf(irp->f, ",");
1810 ir_print_other_instruction(irp, instruction->field_name);2282 ir_print_other_inst_src(irp, instruction->field_name);
1811 fprintf(irp->f, ")");2283 fprintf(irp->f, ")");
1812}2284}
18132285
1814static void ir_print_bit_offset_of(IrPrint *irp, IrInstructionBitOffsetOf *instruction) {2286static void ir_print_bit_offset_of(IrPrintSrc *irp, IrInstSrcBitOffsetOf *instruction) {
1815 fprintf(irp->f, "@bit_offset_of(");2287 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);
1817 fprintf(irp->f, ",");2289 fprintf(irp->f, ",");
1818 ir_print_other_instruction(irp, instruction->field_name);2290 ir_print_other_inst_src(irp, instruction->field_name);
1819 fprintf(irp->f, ")");2291 fprintf(irp->f, ")");
1820}2292}
18212293
1822static void ir_print_type_info(IrPrint *irp, IrInstructionTypeInfo *instruction) {2294static void ir_print_type_info(IrPrintSrc *irp, IrInstSrcTypeInfo *instruction) {
1823 fprintf(irp->f, "@typeInfo(");2295 fprintf(irp->f, "@typeInfo(");
1824 ir_print_other_instruction(irp, instruction->type_value);2296 ir_print_other_inst_src(irp, instruction->type_value);
1825 fprintf(irp->f, ")");2297 fprintf(irp->f, ")");
1826}2298}
18272299
1828static void ir_print_type(IrPrint *irp, IrInstructionType *instruction) {2300static void ir_print_type(IrPrintSrc *irp, IrInstSrcType *instruction) {
1829 fprintf(irp->f, "@Type(");2301 fprintf(irp->f, "@Type(");
1830 ir_print_other_instruction(irp, instruction->type_info);2302 ir_print_other_inst_src(irp, instruction->type_info);
1831 fprintf(irp->f, ")");2303 fprintf(irp->f, ")");
1832}2304}
18332305
1834static void ir_print_has_field(IrPrint *irp, IrInstructionHasField *instruction) {2306static void ir_print_has_field(IrPrintSrc *irp, IrInstSrcHasField *instruction) {
1835 fprintf(irp->f, "@hasField(");2307 fprintf(irp->f, "@hasField(");
1836 ir_print_other_instruction(irp, instruction->container_type);2308 ir_print_other_inst_src(irp, instruction->container_type);
1837 fprintf(irp->f, ",");2309 fprintf(irp->f, ",");
1838 ir_print_other_instruction(irp, instruction->field_name);2310 ir_print_other_inst_src(irp, instruction->field_name);
1839 fprintf(irp->f, ")");2311 fprintf(irp->f, ")");
1840}2312}
18412313
1842static void ir_print_type_id(IrPrint *irp, IrInstructionTypeId *instruction) {2314static void ir_print_type_id(IrPrintSrc *irp, IrInstSrcTypeId *instruction) {
1843 fprintf(irp->f, "@typeId(");2315 fprintf(irp->f, "@typeId(");
1844 ir_print_other_instruction(irp, instruction->type_value);2316 ir_print_other_inst_src(irp, instruction->type_value);
1845 fprintf(irp->f, ")");2317 fprintf(irp->f, ")");
1846}2318}
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) {
1849 fprintf(irp->f, "@setEvalBranchQuota(");2321 fprintf(irp->f, "@setEvalBranchQuota(");
1850 ir_print_other_instruction(irp, instruction->new_quota);2322 ir_print_other_inst_src(irp, instruction->new_quota);
1851 fprintf(irp->f, ")");2323 fprintf(irp->f, ")");
1852}2324}
18532325
1854static void ir_print_align_cast(IrPrint *irp, IrInstructionAlignCast *instruction) {2326static void ir_print_align_cast(IrPrintSrc *irp, IrInstSrcAlignCast *instruction) {
1855 fprintf(irp->f, "@alignCast(");2327 fprintf(irp->f, "@alignCast(");
1856 if (instruction->align_bytes == nullptr) {2328 ir_print_other_inst_src(irp, instruction->align_bytes);
1857 fprintf(irp->f, "null");
1858 } else {
1859 ir_print_other_instruction(irp, instruction->align_bytes);
1860 }
1861 fprintf(irp->f, ",");2329 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);
1863 fprintf(irp->f, ")");2337 fprintf(irp->f, ")");
1864}2338}
18652339
1866static void ir_print_resolve_result(IrPrint *irp, IrInstructionResolveResult *instruction) {2340static void ir_print_resolve_result(IrPrintSrc *irp, IrInstSrcResolveResult *instruction) {
1867 fprintf(irp->f, "ResolveResult(");2341 fprintf(irp->f, "ResolveResult(");
1868 ir_print_result_loc(irp, instruction->result_loc);2342 ir_print_result_loc(irp, instruction->result_loc);
1869 fprintf(irp->f, ")");2343 fprintf(irp->f, ")");
1870}2344}
18712345
1872static void ir_print_reset_result(IrPrint *irp, IrInstructionResetResult *instruction) {2346static void ir_print_reset_result(IrPrintSrc *irp, IrInstSrcResetResult *instruction) {
1873 fprintf(irp->f, "ResetResult(");2347 fprintf(irp->f, "ResetResult(");
1874 ir_print_result_loc(irp, instruction->result_loc);2348 ir_print_result_loc(irp, instruction->result_loc);
1875 fprintf(irp->f, ")");2349 fprintf(irp->f, ")");
1876}2350}
18772351
1878static void ir_print_opaque_type(IrPrint *irp, IrInstructionOpaqueType *instruction) {2352static void ir_print_opaque_type(IrPrintSrc *irp, IrInstSrcOpaqueType *instruction) {
1879 fprintf(irp->f, "@OpaqueType()");2353 fprintf(irp->f, "@OpaqueType()");
1880}2354}
18812355
1882static void ir_print_set_align_stack(IrPrint *irp, IrInstructionSetAlignStack *instruction) {2356static void ir_print_set_align_stack(IrPrintSrc *irp, IrInstSrcSetAlignStack *instruction) {
1883 fprintf(irp->f, "@setAlignStack(");2357 fprintf(irp->f, "@setAlignStack(");
1884 ir_print_other_instruction(irp, instruction->align_bytes);2358 ir_print_other_inst_src(irp, instruction->align_bytes);
1885 fprintf(irp->f, ")");2359 fprintf(irp->f, ")");
1886}2360}
18872361
1888static void ir_print_arg_type(IrPrint *irp, IrInstructionArgType *instruction) {2362static void ir_print_arg_type(IrPrintSrc *irp, IrInstSrcArgType *instruction) {
1889 fprintf(irp->f, "@ArgType(");2363 fprintf(irp->f, "@ArgType(");
1890 ir_print_other_instruction(irp, instruction->fn_type);2364 ir_print_other_inst_src(irp, instruction->fn_type);
1891 fprintf(irp->f, ",");2365 fprintf(irp->f, ",");
1892 ir_print_other_instruction(irp, instruction->arg_index);2366 ir_print_other_inst_src(irp, instruction->arg_index);
1893 fprintf(irp->f, ")");2367 fprintf(irp->f, ")");
1894}2368}
18952369
1896static void ir_print_enum_tag_type(IrPrint *irp, IrInstructionTagType *instruction) {2370static void ir_print_enum_tag_type(IrPrintSrc *irp, IrInstSrcTagType *instruction) {
1897 fprintf(irp->f, "@TagType(");2371 fprintf(irp->f, "@TagType(");
1898 ir_print_other_instruction(irp, instruction->target);2372 ir_print_other_inst_src(irp, instruction->target);
1899 fprintf(irp->f, ")");2373 fprintf(irp->f, ")");
1900}2374}
19012375
1902static void ir_print_export(IrPrint *irp, IrInstructionExport *instruction) {2376static void ir_print_export(IrPrintSrc *irp, IrInstSrcExport *instruction) {
1903 fprintf(irp->f, "@export(");2377 fprintf(irp->f, "@export(");
1904 ir_print_other_instruction(irp, instruction->target);2378 ir_print_other_inst_src(irp, instruction->target);
1905 fprintf(irp->f, ",");2379 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 }
1907 fprintf(irp->f, ")");2394 fprintf(irp->f, ")");
1908}2395}
19092396
1910static void ir_print_error_return_trace(IrPrint *irp, IrInstructionErrorReturnTrace *instruction) {2397static void ir_print_error_return_trace(IrPrintGen *irp, IrInstGenErrorReturnTrace *instruction) {
1911 fprintf(irp->f, "@errorReturnTrace(");2398 fprintf(irp->f, "@errorReturnTrace(");
1912 switch (instruction->optional) {2399 switch (instruction->optional) {
1913 case IrInstructionErrorReturnTrace::Null:2400 case IrInstErrorReturnTraceNull:
1914 fprintf(irp->f, "Null");2401 fprintf(irp->f, "Null");
1915 break;2402 break;
1916 case IrInstructionErrorReturnTrace::NonNull:2403 case IrInstErrorReturnTraceNonNull:
1917 fprintf(irp->f, "NonNull");2404 fprintf(irp->f, "NonNull");
1918 break;2405 break;
1919 }2406 }
1920 fprintf(irp->f, ")");2407 fprintf(irp->f, ")");
1921}2408}
19222409
1923static void ir_print_error_union(IrPrint *irp, IrInstructionErrorUnion *instruction) {2410static void ir_print_error_union(IrPrintSrc *irp, IrInstSrcErrorUnion *instruction) {
1924 ir_print_other_instruction(irp, instruction->err_set);2411 ir_print_other_inst_src(irp, instruction->err_set);
1925 fprintf(irp->f, "!");2412 fprintf(irp->f, "!");
1926 ir_print_other_instruction(irp, instruction->payload);2413 ir_print_other_inst_src(irp, instruction->payload);
1927}2414}
19282415
1929static void ir_print_atomic_rmw(IrPrint *irp, IrInstructionAtomicRmw *instruction) {2416static void ir_print_atomic_rmw(IrPrintSrc *irp, IrInstSrcAtomicRmw *instruction) {
1930 fprintf(irp->f, "@atomicRmw(");2417 fprintf(irp->f, "@atomicRmw(");
1931 if (instruction->operand_type != nullptr) {2418 ir_print_other_inst_src(irp, instruction->operand_type);
1932 ir_print_other_instruction(irp, instruction->operand_type);
1933 } else {
1934 fprintf(irp->f, "[TODO print]");
1935 }
1936 fprintf(irp->f, ",");2419 fprintf(irp->f, ",");
1937 ir_print_other_instruction(irp, instruction->ptr);2420 ir_print_other_inst_src(irp, instruction->ptr);
1938 fprintf(irp->f, ",");2421 fprintf(irp->f, ",");
1939 if (instruction->op != nullptr) {2422 ir_print_other_inst_src(irp, instruction->op);
1940 ir_print_other_instruction(irp, instruction->op);
1941 } else {
1942 fprintf(irp->f, "[TODO print]");
1943 }
1944 fprintf(irp->f, ",");2423 fprintf(irp->f, ",");
1945 ir_print_other_instruction(irp, instruction->operand);2424 ir_print_other_inst_src(irp, instruction->operand);
1946 fprintf(irp->f, ",");2425 fprintf(irp->f, ",");
1947 if (instruction->ordering != nullptr) {2426 ir_print_other_inst_src(irp, instruction->ordering);
1948 ir_print_other_instruction(irp, instruction->ordering);
1949 } else {
1950 fprintf(irp->f, "[TODO print]");
1951 }
1952 fprintf(irp->f, ")");2427 fprintf(irp->f, ")");
1953}2428}
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) {
1956 fprintf(irp->f, "@atomicLoad(");2439 fprintf(irp->f, "@atomicLoad(");
1957 if (instruction->operand_type != nullptr) {2440 ir_print_other_inst_src(irp, instruction->operand_type);
1958 ir_print_other_instruction(irp, instruction->operand_type);
1959 } else {
1960 fprintf(irp->f, "[TODO print]");
1961 }
1962 fprintf(irp->f, ",");2441 fprintf(irp->f, ",");
1963 ir_print_other_instruction(irp, instruction->ptr);2442 ir_print_other_inst_src(irp, instruction->ptr);
1964 fprintf(irp->f, ",");2443 fprintf(irp->f, ",");
1965 if (instruction->ordering != nullptr) {2444 ir_print_other_inst_src(irp, instruction->ordering);
1966 ir_print_other_instruction(irp, instruction->ordering);
1967 } else {
1968 fprintf(irp->f, "[TODO print]");
1969 }
1970 fprintf(irp->f, ")");2445 fprintf(irp->f, ")");
1971}2446}
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) {
1974 fprintf(irp->f, "@atomicStore(");2455 fprintf(irp->f, "@atomicStore(");
1975 if (instruction->operand_type != nullptr) {2456 ir_print_other_inst_src(irp, instruction->operand_type);
1976 ir_print_other_instruction(irp, instruction->operand_type);
1977 } else {
1978 fprintf(irp->f, "[TODO print]");
1979 }
1980 fprintf(irp->f, ",");2457 fprintf(irp->f, ",");
1981 ir_print_other_instruction(irp, instruction->ptr);2458 ir_print_other_inst_src(irp, instruction->ptr);
1982 fprintf(irp->f, ",");2459 fprintf(irp->f, ",");
1983 ir_print_other_instruction(irp, instruction->value);2460 ir_print_other_inst_src(irp, instruction->value);
1984 fprintf(irp->f, ",");2461 fprintf(irp->f, ",");
1985 if (instruction->ordering != nullptr) {2462 ir_print_other_inst_src(irp, instruction->ordering);
1986 ir_print_other_instruction(irp, instruction->ordering);
1987 } else {
1988 fprintf(irp->f, "[TODO print]");
1989 }
1990 fprintf(irp->f, ")");2463 fprintf(irp->f, ")");
1991}2464}
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) {
1995 fprintf(irp->f, "@saveErrRetAddr()");2480 fprintf(irp->f, "@saveErrRetAddr()");
1996}2481}
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) {
1999 fprintf(irp->f, "@addImplicitReturnType(");2484 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);
2001 fprintf(irp->f, ")");2492 fprintf(irp->f, ")");
2002}2493}
20032494
2004static void ir_print_float_op(IrPrint *irp, IrInstructionFloatOp *instruction) {2495static void ir_print_float_op(IrPrintGen *irp, IrInstGenFloatOp *instruction) {
2005 fprintf(irp->f, "@%s(", float_op_to_name(instruction->fn_id));2496 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);
2007 fprintf(irp->f, ")");2498 fprintf(irp->f, ")");
2008}2499}
20092500
2010static void ir_print_mul_add(IrPrint *irp, IrInstructionMulAdd *instruction) {2501static void ir_print_mul_add(IrPrintSrc *irp, IrInstSrcMulAdd *instruction) {
2011 fprintf(irp->f, "@mulAdd(");2502 fprintf(irp->f, "@mulAdd(");
2012 if (instruction->type_value != nullptr) {2503 ir_print_other_inst_src(irp, instruction->type_value);
2013 ir_print_other_instruction(irp, instruction->type_value);
2014 } else {
2015 fprintf(irp->f, "null");
2016 }
2017 fprintf(irp->f, ",");2504 fprintf(irp->f, ",");
2018 ir_print_other_instruction(irp, instruction->op1);2505 ir_print_other_inst_src(irp, instruction->op1);
2019 fprintf(irp->f, ",");2506 fprintf(irp->f, ",");
2020 ir_print_other_instruction(irp, instruction->op2);2507 ir_print_other_inst_src(irp, instruction->op2);
2021 fprintf(irp->f, ",");2508 fprintf(irp->f, ",");
2022 ir_print_other_instruction(irp, instruction->op3);2509 ir_print_other_inst_src(irp, instruction->op3);
2023 fprintf(irp->f, ")");2510 fprintf(irp->f, ")");
2024}2511}
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) {
2027 ZigVar *var = decl_var_instruction->var;2524 ZigVar *var = decl_var_instruction->var;
2028 const char *var_or_const = decl_var_instruction->var->gen_is_const ? "const" : "var";2525 const char *var_or_const = decl_var_instruction->var->gen_is_const ? "const" : "var";
2029 const char *name = decl_var_instruction->var->name;2526 const char *name = decl_var_instruction->var->name;
2030 fprintf(irp->f, "%s %s: %s align(%u) = ", var_or_const, name, buf_ptr(&var->var_type->name),2527 fprintf(irp->f, "%s %s: %s align(%u) = ", var_or_const, name, buf_ptr(&var->var_type->name),
2031 var->align_bytes);2528 var->align_bytes);
20322529
2033 ir_print_other_instruction(irp, decl_var_instruction->var_ptr);2530 ir_print_other_inst_gen(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 }
2038}2531}
20392532
2040static void ir_print_has_decl(IrPrint *irp, IrInstructionHasDecl *instruction) {2533static void ir_print_has_decl(IrPrintSrc *irp, IrInstSrcHasDecl *instruction) {
2041 fprintf(irp->f, "@hasDecl(");2534 fprintf(irp->f, "@hasDecl(");
2042 ir_print_other_instruction(irp, instruction->container);2535 ir_print_other_inst_src(irp, instruction->container);
2043 fprintf(irp->f, ",");2536 fprintf(irp->f, ",");
2044 ir_print_other_instruction(irp, instruction->name);2537 ir_print_other_inst_src(irp, instruction->name);
2045 fprintf(irp->f, ")");2538 fprintf(irp->f, ")");
2046}2539}
20472540
2048static void ir_print_undeclared_ident(IrPrint *irp, IrInstructionUndeclaredIdent *instruction) {2541static void ir_print_undeclared_ident(IrPrintSrc *irp, IrInstSrcUndeclaredIdent *instruction) {
2049 fprintf(irp->f, "@undeclaredIdent(%s)", buf_ptr(instruction->name));2542 fprintf(irp->f, "@undeclaredIdent(%s)", buf_ptr(instruction->name));
2050}2543}
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) {
2053 fprintf(irp->f, "@unionInit(");2546 fprintf(irp->f, "@unionInit(");
2054 ir_print_other_instruction(irp, instruction->union_type);2547 ir_print_other_inst_src(irp, instruction->union_type);
2055 fprintf(irp->f, ", ");2548 fprintf(irp->f, ", ");
2056 ir_print_other_instruction(irp, instruction->field_name);2549 ir_print_other_inst_src(irp, instruction->field_name);
2057 fprintf(irp->f, ", ");2550 fprintf(irp->f, ", ");
2058 ir_print_other_instruction(irp, instruction->field_result_loc);2551 ir_print_other_inst_src(irp, instruction->field_result_loc);
2059 fprintf(irp->f, ", ");2552 fprintf(irp->f, ", ");
2060 ir_print_other_instruction(irp, instruction->result_loc);2553 ir_print_other_inst_src(irp, instruction->result_loc);
2061 fprintf(irp->f, ")");2554 fprintf(irp->f, ")");
2062}2555}
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) {
2065 fprintf(irp->f, "@suspendBegin()");2562 fprintf(irp->f, "@suspendBegin()");
2066}2563}
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) {
2069 fprintf(irp->f, "@suspendFinish()");2570 fprintf(irp->f, "@suspendFinish()");
2070}2571}
20712572
2072static void ir_print_resume(IrPrint *irp, IrInstructionResume *instruction) {2573static void ir_print_resume(IrPrintSrc *irp, IrInstSrcResume *instruction) {
2073 fprintf(irp->f, "resume ");2574 fprintf(irp->f, "resume ");
2074 ir_print_other_instruction(irp, instruction->frame);2575 ir_print_other_inst_src(irp, instruction->frame);
2075}2576}
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) {
2078 fprintf(irp->f, "@await(");2584 fprintf(irp->f, "@await(");
2079 ir_print_other_instruction(irp, instruction->frame);2585 ir_print_other_inst_src(irp, instruction->frame);
2080 fprintf(irp->f, ",");2586 fprintf(irp->f, ",");
2081 ir_print_result_loc(irp, instruction->result_loc);2587 ir_print_result_loc(irp, instruction->result_loc);
2082 fprintf(irp->f, ")");2588 fprintf(irp->f, ")");
2083}2589}
20842590
2085static void ir_print_await_gen(IrPrint *irp, IrInstructionAwaitGen *instruction) {2591static void ir_print_await_gen(IrPrintGen *irp, IrInstGenAwait *instruction) {
2086 fprintf(irp->f, "@await(");2592 fprintf(irp->f, "@await(");
2087 ir_print_other_instruction(irp, instruction->frame);2593 ir_print_other_inst_gen(irp, instruction->frame);
2088 fprintf(irp->f, ",");2594 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);
2090 fprintf(irp->f, ")");2602 fprintf(irp->f, ")");
2091}2603}
20922604
2093static void ir_print_spill_begin(IrPrint *irp, IrInstructionSpillBegin *instruction) {2605static void ir_print_spill_begin(IrPrintGen *irp, IrInstGenSpillBegin *instruction) {
2094 fprintf(irp->f, "@spillBegin(");2606 fprintf(irp->f, "@spillBegin(");
2095 ir_print_other_instruction(irp, instruction->operand);2607 ir_print_other_inst_gen(irp, instruction->operand);
2096 fprintf(irp->f, ")");2608 fprintf(irp->f, ")");
2097}2609}
20982610
2099static void ir_print_spill_end(IrPrint *irp, IrInstructionSpillEnd *instruction) {2611static void ir_print_spill_end(IrPrintSrc *irp, IrInstSrcSpillEnd *instruction) {
2100 fprintf(irp->f, "@spillEnd(");2612 fprintf(irp->f, "@spillEnd(");
2101 ir_print_other_instruction(irp, &instruction->begin->base);2613 ir_print_other_inst_src(irp, &instruction->begin->base);
2102 fprintf(irp->f, ")");2614 fprintf(irp->f, ")");
2103}2615}
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) {
2106 fprintf(irp->f, "@vectorExtractElem(");2624 fprintf(irp->f, "@vectorExtractElem(");
2107 ir_print_other_instruction(irp, instruction->vector);2625 ir_print_other_inst_gen(irp, instruction->vector);
2108 fprintf(irp->f, ",");2626 fprintf(irp->f, ",");
2109 ir_print_other_instruction(irp, instruction->index);2627 ir_print_other_inst_gen(irp, instruction->index);
2110 fprintf(irp->f, ")");2628 fprintf(irp->f, ")");
2111}2629}
21122630
2113static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction, bool trailing) {2631static void ir_print_inst_src(IrPrintSrc *irp, IrInstSrc *instruction, bool trailing) {
2114 ir_print_prefix(irp, instruction, trailing);2632 ir_print_prefix_src(irp, instruction, trailing);
2115 switch (instruction->id) {2633 switch (instruction->id) {
2116 case IrInstructionIdInvalid:2634 case IrInstSrcIdInvalid:
2117 zig_unreachable();2635 zig_unreachable();
2118 case IrInstructionIdReturn:2636 case IrInstSrcIdReturn:
2119 ir_print_return(irp, (IrInstructionReturn *)instruction);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);
2120 break;2665 break;
2121 case IrInstructionIdConst:2666 case IrInstSrcIdBr:
2122 ir_print_const(irp, (IrInstructionConst *)instruction);2667 ir_print_br(irp, (IrInstSrcBr *)instruction);
2123 break;2668 break;
2124 case IrInstructionIdBinOp:2669 case IrInstSrcIdPhi:
2125 ir_print_bin_op(irp, (IrInstructionBinOp *)instruction);2670 ir_print_phi(irp, (IrInstSrcPhi *)instruction);
2126 break;2671 break;
2127 case IrInstructionIdMergeErrSets:2672 case IrInstSrcIdContainerInitList:
2128 ir_print_merge_err_sets(irp, (IrInstructionMergeErrSets *)instruction);2673 ir_print_container_init_list(irp, (IrInstSrcContainerInitList *)instruction);
2129 break;2674 break;
2130 case IrInstructionIdDeclVarSrc:2675 case IrInstSrcIdContainerInitFields:
2131 ir_print_decl_var_src(irp, (IrInstructionDeclVarSrc *)instruction);2676 ir_print_container_init_fields(irp, (IrInstSrcContainerInitFields *)instruction);
2132 break;2677 break;
2133 case IrInstructionIdCast:2678 case IrInstSrcIdUnreachable:
2134 ir_print_cast(irp, (IrInstructionCast *)instruction);2679 ir_print_unreachable(irp, (IrInstSrcUnreachable *)instruction);
2135 break;2680 break;
2136 case IrInstructionIdCallExtra:2681 case IrInstSrcIdElemPtr:
2137 ir_print_call_extra(irp, (IrInstructionCallExtra *)instruction);2682 ir_print_elem_ptr(irp, (IrInstSrcElemPtr *)instruction);
2138 break;2683 break;
2139 case IrInstructionIdCallSrc:2684 case IrInstSrcIdVarPtr:
2140 ir_print_call_src(irp, (IrInstructionCallSrc *)instruction);2685 ir_print_var_ptr(irp, (IrInstSrcVarPtr *)instruction);
2141 break;2686 break;
2142 case IrInstructionIdCallSrcArgs:2687 case IrInstSrcIdLoadPtr:
2143 ir_print_call_src_args(irp, (IrInstructionCallSrcArgs *)instruction);2688 ir_print_load_ptr(irp, (IrInstSrcLoadPtr *)instruction);
2144 break;2689 break;
2145 case IrInstructionIdCallGen:2690 case IrInstSrcIdStorePtr:
2146 ir_print_call_gen(irp, (IrInstructionCallGen *)instruction);2691 ir_print_store_ptr(irp, (IrInstSrcStorePtr *)instruction);
2147 break;2692 break;
2148 case IrInstructionIdUnOp:2693 case IrInstSrcIdTypeOf:
2149 ir_print_un_op(irp, (IrInstructionUnOp *)instruction);2694 ir_print_typeof(irp, (IrInstSrcTypeOf *)instruction);
2150 break;2695 break;
2151 case IrInstructionIdCondBr:2696 case IrInstSrcIdFieldPtr:
2152 ir_print_cond_br(irp, (IrInstructionCondBr *)instruction);2697 ir_print_field_ptr(irp, (IrInstSrcFieldPtr *)instruction);
2153 break;2698 break;
2154 case IrInstructionIdBr:2699 case IrInstSrcIdSetCold:
2155 ir_print_br(irp, (IrInstructionBr *)instruction);2700 ir_print_set_cold(irp, (IrInstSrcSetCold *)instruction);
2156 break;2701 break;
2157 case IrInstructionIdPhi:2702 case IrInstSrcIdSetRuntimeSafety:
2158 ir_print_phi(irp, (IrInstructionPhi *)instruction);2703 ir_print_set_runtime_safety(irp, (IrInstSrcSetRuntimeSafety *)instruction);
2159 break;2704 break;
2160 case IrInstructionIdContainerInitList:2705 case IrInstSrcIdSetFloatMode:
2161 ir_print_container_init_list(irp, (IrInstructionContainerInitList *)instruction);2706 ir_print_set_float_mode(irp, (IrInstSrcSetFloatMode *)instruction);
2162 break;2707 break;
2163 case IrInstructionIdContainerInitFields:2708 case IrInstSrcIdArrayType:
2164 ir_print_container_init_fields(irp, (IrInstructionContainerInitFields *)instruction);2709 ir_print_array_type(irp, (IrInstSrcArrayType *)instruction);
2165 break;2710 break;
2166 case IrInstructionIdUnreachable:2711 case IrInstSrcIdSliceType:
2167 ir_print_unreachable(irp, (IrInstructionUnreachable *)instruction);2712 ir_print_slice_type(irp, (IrInstSrcSliceType *)instruction);
2168 break;2713 break;
2169 case IrInstructionIdElemPtr:2714 case IrInstSrcIdAnyFrameType:
2170 ir_print_elem_ptr(irp, (IrInstructionElemPtr *)instruction);2715 ir_print_any_frame_type(irp, (IrInstSrcAnyFrameType *)instruction);
2171 break;2716 break;
2172 case IrInstructionIdVarPtr:2717 case IrInstSrcIdAsm:
2173 ir_print_var_ptr(irp, (IrInstructionVarPtr *)instruction);2718 ir_print_asm_src(irp, (IrInstSrcAsm *)instruction);
2174 break;2719 break;
2175 case IrInstructionIdReturnPtr:2720 case IrInstSrcIdSizeOf:
2176 ir_print_return_ptr(irp, (IrInstructionReturnPtr *)instruction);2721 ir_print_size_of(irp, (IrInstSrcSizeOf *)instruction);
2177 break;2722 break;
2178 case IrInstructionIdLoadPtr:2723 case IrInstSrcIdTestNonNull:
2179 ir_print_load_ptr(irp, (IrInstructionLoadPtr *)instruction);2724 ir_print_test_non_null(irp, (IrInstSrcTestNonNull *)instruction);
2180 break;2725 break;
2181 case IrInstructionIdLoadPtrGen:2726 case IrInstSrcIdOptionalUnwrapPtr:
2182 ir_print_load_ptr_gen(irp, (IrInstructionLoadPtrGen *)instruction);2727 ir_print_optional_unwrap_ptr(irp, (IrInstSrcOptionalUnwrapPtr *)instruction);
2183 break;2728 break;
2184 case IrInstructionIdStorePtr:2729 case IrInstSrcIdPopCount:
2185 ir_print_store_ptr(irp, (IrInstructionStorePtr *)instruction);2730 ir_print_pop_count(irp, (IrInstSrcPopCount *)instruction);
2186 break;2731 break;
2187 case IrInstructionIdVectorStoreElem:2732 case IrInstSrcIdCtz:
2188 ir_print_vector_store_elem(irp, (IrInstructionVectorStoreElem *)instruction);2733 ir_print_ctz(irp, (IrInstSrcCtz *)instruction);
2189 break;2734 break;
2190 case IrInstructionIdTypeOf:2735 case IrInstSrcIdBswap:
2191 ir_print_typeof(irp, (IrInstructionTypeOf *)instruction);2736 ir_print_bswap(irp, (IrInstSrcBswap *)instruction);
2192 break;2737 break;
2193 case IrInstructionIdFieldPtr:2738 case IrInstSrcIdBitReverse:
2194 ir_print_field_ptr(irp, (IrInstructionFieldPtr *)instruction);2739 ir_print_bit_reverse(irp, (IrInstSrcBitReverse *)instruction);
2195 break;2740 break;
2196 case IrInstructionIdStructFieldPtr:2741 case IrInstSrcIdSwitchBr:
2197 ir_print_struct_field_ptr(irp, (IrInstructionStructFieldPtr *)instruction);2742 ir_print_switch_br(irp, (IrInstSrcSwitchBr *)instruction);
2198 break;2743 break;
2199 case IrInstructionIdUnionFieldPtr:2744 case IrInstSrcIdSwitchVar:
2200 ir_print_union_field_ptr(irp, (IrInstructionUnionFieldPtr *)instruction);2745 ir_print_switch_var(irp, (IrInstSrcSwitchVar *)instruction);
2201 break;2746 break;
2202 case IrInstructionIdSetCold:2747 case IrInstSrcIdSwitchElseVar:
2203 ir_print_set_cold(irp, (IrInstructionSetCold *)instruction);2748 ir_print_switch_else_var(irp, (IrInstSrcSwitchElseVar *)instruction);
2204 break;2749 break;
2205 case IrInstructionIdSetRuntimeSafety:2750 case IrInstSrcIdSwitchTarget:
2206 ir_print_set_runtime_safety(irp, (IrInstructionSetRuntimeSafety *)instruction);2751 ir_print_switch_target(irp, (IrInstSrcSwitchTarget *)instruction);
2207 break;2752 break;
2208 case IrInstructionIdSetFloatMode:2753 case IrInstSrcIdImport:
2209 ir_print_set_float_mode(irp, (IrInstructionSetFloatMode *)instruction);2754 ir_print_import(irp, (IrInstSrcImport *)instruction);
2210 break;2755 break;
2211 case IrInstructionIdArrayType:2756 case IrInstSrcIdRef:
2212 ir_print_array_type(irp, (IrInstructionArrayType *)instruction);2757 ir_print_ref(irp, (IrInstSrcRef *)instruction);
2213 break;2758 break;
2214 case IrInstructionIdSliceType:2759 case IrInstSrcIdCompileErr:
2215 ir_print_slice_type(irp, (IrInstructionSliceType *)instruction);2760 ir_print_compile_err(irp, (IrInstSrcCompileErr *)instruction);
2216 break;2761 break;
2217 case IrInstructionIdAnyFrameType:2762 case IrInstSrcIdCompileLog:
2218 ir_print_any_frame_type(irp, (IrInstructionAnyFrameType *)instruction);2763 ir_print_compile_log(irp, (IrInstSrcCompileLog *)instruction);
2219 break;2764 break;
2220 case IrInstructionIdAsmSrc:2765 case IrInstSrcIdErrName:
2221 ir_print_asm_src(irp, (IrInstructionAsmSrc *)instruction);2766 ir_print_err_name(irp, (IrInstSrcErrName *)instruction);
2222 break;2767 break;
2223 case IrInstructionIdAsmGen:2768 case IrInstSrcIdCImport:
2224 ir_print_asm_gen(irp, (IrInstructionAsmGen *)instruction);2769 ir_print_c_import(irp, (IrInstSrcCImport *)instruction);
2225 break;2770 break;
2226 case IrInstructionIdSizeOf:2771 case IrInstSrcIdCInclude:
2227 ir_print_size_of(irp, (IrInstructionSizeOf *)instruction);2772 ir_print_c_include(irp, (IrInstSrcCInclude *)instruction);
2228 break;2773 break;
2229 case IrInstructionIdTestNonNull:2774 case IrInstSrcIdCDefine:
2230 ir_print_test_non_null(irp, (IrInstructionTestNonNull *)instruction);2775 ir_print_c_define(irp, (IrInstSrcCDefine *)instruction);
2231 break;2776 break;
2232 case IrInstructionIdOptionalUnwrapPtr:2777 case IrInstSrcIdCUndef:
2233 ir_print_optional_unwrap_ptr(irp, (IrInstructionOptionalUnwrapPtr *)instruction);2778 ir_print_c_undef(irp, (IrInstSrcCUndef *)instruction);
2234 break;2779 break;
2235 case IrInstructionIdPopCount:2780 case IrInstSrcIdEmbedFile:
2236 ir_print_pop_count(irp, (IrInstructionPopCount *)instruction);2781 ir_print_embed_file(irp, (IrInstSrcEmbedFile *)instruction);
2237 break;2782 break;
2238 case IrInstructionIdClz:2783 case IrInstSrcIdCmpxchg:
2239 ir_print_clz(irp, (IrInstructionClz *)instruction);2784 ir_print_cmpxchg_src(irp, (IrInstSrcCmpxchg *)instruction);
2240 break;2785 break;
2241 case IrInstructionIdCtz:2786 case IrInstSrcIdFence:
2242 ir_print_ctz(irp, (IrInstructionCtz *)instruction);2787 ir_print_fence(irp, (IrInstSrcFence *)instruction);
2243 break;2788 break;
2244 case IrInstructionIdBswap:2789 case IrInstSrcIdTruncate:
2245 ir_print_bswap(irp, (IrInstructionBswap *)instruction);2790 ir_print_truncate(irp, (IrInstSrcTruncate *)instruction);
2246 break;2791 break;
2247 case IrInstructionIdBitReverse:2792 case IrInstSrcIdIntCast:
2248 ir_print_bit_reverse(irp, (IrInstructionBitReverse *)instruction);2793 ir_print_int_cast(irp, (IrInstSrcIntCast *)instruction);
2249 break;2794 break;
2250 case IrInstructionIdSwitchBr:2795 case IrInstSrcIdFloatCast:
2251 ir_print_switch_br(irp, (IrInstructionSwitchBr *)instruction);2796 ir_print_float_cast(irp, (IrInstSrcFloatCast *)instruction);
2252 break;2797 break;
2253 case IrInstructionIdSwitchVar:2798 case IrInstSrcIdErrSetCast:
2254 ir_print_switch_var(irp, (IrInstructionSwitchVar *)instruction);2799 ir_print_err_set_cast(irp, (IrInstSrcErrSetCast *)instruction);
2255 break;2800 break;
2256 case IrInstructionIdSwitchElseVar:2801 case IrInstSrcIdFromBytes:
2257 ir_print_switch_else_var(irp, (IrInstructionSwitchElseVar *)instruction);2802 ir_print_from_bytes(irp, (IrInstSrcFromBytes *)instruction);
2258 break;2803 break;
2259 case IrInstructionIdSwitchTarget:2804 case IrInstSrcIdToBytes:
2260 ir_print_switch_target(irp, (IrInstructionSwitchTarget *)instruction);2805 ir_print_to_bytes(irp, (IrInstSrcToBytes *)instruction);
2261 break;2806 break;
2262 case IrInstructionIdUnionTag:2807 case IrInstSrcIdIntToFloat:
2263 ir_print_union_tag(irp, (IrInstructionUnionTag *)instruction);2808 ir_print_int_to_float(irp, (IrInstSrcIntToFloat *)instruction);
2264 break;2809 break;
2265 case IrInstructionIdImport:2810 case IrInstSrcIdFloatToInt:
2266 ir_print_import(irp, (IrInstructionImport *)instruction);2811 ir_print_float_to_int(irp, (IrInstSrcFloatToInt *)instruction);
2267 break;2812 break;
2268 case IrInstructionIdRef:2813 case IrInstSrcIdBoolToInt:
2269 ir_print_ref(irp, (IrInstructionRef *)instruction);2814 ir_print_bool_to_int(irp, (IrInstSrcBoolToInt *)instruction);
2270 break;2815 break;
2271 case IrInstructionIdRefGen:2816 case IrInstSrcIdIntType:
2272 ir_print_ref_gen(irp, (IrInstructionRefGen *)instruction);2817 ir_print_int_type(irp, (IrInstSrcIntType *)instruction);
2273 break;2818 break;
2274 case IrInstructionIdCompileErr:2819 case IrInstSrcIdVectorType:
2275 ir_print_compile_err(irp, (IrInstructionCompileErr *)instruction);2820 ir_print_vector_type(irp, (IrInstSrcVectorType *)instruction);
2276 break;2821 break;
2277 case IrInstructionIdCompileLog:2822 case IrInstSrcIdShuffleVector:
2278 ir_print_compile_log(irp, (IrInstructionCompileLog *)instruction);2823 ir_print_shuffle_vector(irp, (IrInstSrcShuffleVector *)instruction);
2279 break;2824 break;
2280 case IrInstructionIdErrName:2825 case IrInstSrcIdSplat:
2281 ir_print_err_name(irp, (IrInstructionErrName *)instruction);2826 ir_print_splat_src(irp, (IrInstSrcSplat *)instruction);
2282 break;2827 break;
2283 case IrInstructionIdCImport:2828 case IrInstSrcIdBoolNot:
2284 ir_print_c_import(irp, (IrInstructionCImport *)instruction);2829 ir_print_bool_not(irp, (IrInstSrcBoolNot *)instruction);
2285 break;2830 break;
2286 case IrInstructionIdCInclude:2831 case IrInstSrcIdMemset:
2287 ir_print_c_include(irp, (IrInstructionCInclude *)instruction);2832 ir_print_memset(irp, (IrInstSrcMemset *)instruction);
2288 break;2833 break;
2289 case IrInstructionIdCDefine:2834 case IrInstSrcIdMemcpy:
2290 ir_print_c_define(irp, (IrInstructionCDefine *)instruction);2835 ir_print_memcpy(irp, (IrInstSrcMemcpy *)instruction);
2291 break;2836 break;
2292 case IrInstructionIdCUndef:2837 case IrInstSrcIdSlice:
2293 ir_print_c_undef(irp, (IrInstructionCUndef *)instruction);2838 ir_print_slice_src(irp, (IrInstSrcSlice *)instruction);
2294 break;2839 break;
2295 case IrInstructionIdEmbedFile:2840 case IrInstSrcIdMemberCount:
2296 ir_print_embed_file(irp, (IrInstructionEmbedFile *)instruction);2841 ir_print_member_count(irp, (IrInstSrcMemberCount *)instruction);
2297 break;2842 break;
2298 case IrInstructionIdCmpxchgSrc:2843 case IrInstSrcIdMemberType:
2299 ir_print_cmpxchg_src(irp, (IrInstructionCmpxchgSrc *)instruction);2844 ir_print_member_type(irp, (IrInstSrcMemberType *)instruction);
2300 break;2845 break;
2301 case IrInstructionIdCmpxchgGen:2846 case IrInstSrcIdMemberName:
2302 ir_print_cmpxchg_gen(irp, (IrInstructionCmpxchgGen *)instruction);2847 ir_print_member_name(irp, (IrInstSrcMemberName *)instruction);
2303 break;2848 break;
2304 case IrInstructionIdFence:2849 case IrInstSrcIdBreakpoint:
2305 ir_print_fence(irp, (IrInstructionFence *)instruction);2850 ir_print_breakpoint(irp, (IrInstSrcBreakpoint *)instruction);
2306 break;2851 break;
2307 case IrInstructionIdTruncate:2852 case IrInstSrcIdReturnAddress:
2308 ir_print_truncate(irp, (IrInstructionTruncate *)instruction);2853 ir_print_return_address(irp, (IrInstSrcReturnAddress *)instruction);
2309 break;2854 break;
2310 case IrInstructionIdIntCast:2855 case IrInstSrcIdFrameAddress:
2311 ir_print_int_cast(irp, (IrInstructionIntCast *)instruction);2856 ir_print_frame_address(irp, (IrInstSrcFrameAddress *)instruction);
2312 break;2857 break;
2313 case IrInstructionIdFloatCast:2858 case IrInstSrcIdFrameHandle:
2314 ir_print_float_cast(irp, (IrInstructionFloatCast *)instruction);2859 ir_print_handle(irp, (IrInstSrcFrameHandle *)instruction);
2315 break;2860 break;
2316 case IrInstructionIdErrSetCast:2861 case IrInstSrcIdFrameType:
2317 ir_print_err_set_cast(irp, (IrInstructionErrSetCast *)instruction);2862 ir_print_frame_type(irp, (IrInstSrcFrameType *)instruction);
2318 break;2863 break;
2319 case IrInstructionIdFromBytes:2864 case IrInstSrcIdFrameSize:
2320 ir_print_from_bytes(irp, (IrInstructionFromBytes *)instruction);2865 ir_print_frame_size_src(irp, (IrInstSrcFrameSize *)instruction);
2321 break;2866 break;
2322 case IrInstructionIdToBytes:2867 case IrInstSrcIdAlignOf:
2323 ir_print_to_bytes(irp, (IrInstructionToBytes *)instruction);2868 ir_print_align_of(irp, (IrInstSrcAlignOf *)instruction);
2324 break;2869 break;
2325 case IrInstructionIdIntToFloat:2870 case IrInstSrcIdOverflowOp:
2326 ir_print_int_to_float(irp, (IrInstructionIntToFloat *)instruction);2871 ir_print_overflow_op(irp, (IrInstSrcOverflowOp *)instruction);
2327 break;2872 break;
2328 case IrInstructionIdFloatToInt:2873 case IrInstSrcIdTestErr:
2329 ir_print_float_to_int(irp, (IrInstructionFloatToInt *)instruction);2874 ir_print_test_err_src(irp, (IrInstSrcTestErr *)instruction);
2330 break;2875 break;
2331 case IrInstructionIdBoolToInt:2876 case IrInstSrcIdUnwrapErrCode:
2332 ir_print_bool_to_int(irp, (IrInstructionBoolToInt *)instruction);2877 ir_print_unwrap_err_code(irp, (IrInstSrcUnwrapErrCode *)instruction);
2333 break;2878 break;
2334 case IrInstructionIdIntType:2879 case IrInstSrcIdUnwrapErrPayload:
2335 ir_print_int_type(irp, (IrInstructionIntType *)instruction);2880 ir_print_unwrap_err_payload(irp, (IrInstSrcUnwrapErrPayload *)instruction);
2336 break;2881 break;
2337 case IrInstructionIdVectorType:2882 case IrInstSrcIdFnProto:
2338 ir_print_vector_type(irp, (IrInstructionVectorType *)instruction);2883 ir_print_fn_proto(irp, (IrInstSrcFnProto *)instruction);
2339 break;2884 break;
2340 case IrInstructionIdShuffleVector:2885 case IrInstSrcIdTestComptime:
2341 ir_print_shuffle_vector(irp, (IrInstructionShuffleVector *)instruction);2886 ir_print_test_comptime(irp, (IrInstSrcTestComptime *)instruction);
2342 break;2887 break;
2343 case IrInstructionIdSplatSrc:2888 case IrInstSrcIdPtrCast:
2344 ir_print_splat_src(irp, (IrInstructionSplatSrc *)instruction);2889 ir_print_ptr_cast_src(irp, (IrInstSrcPtrCast *)instruction);
2345 break;2890 break;
2346 case IrInstructionIdSplatGen:2891 case IrInstSrcIdBitCast:
2347 ir_print_splat_gen(irp, (IrInstructionSplatGen *)instruction);2892 ir_print_bit_cast_src(irp, (IrInstSrcBitCast *)instruction);
2348 break;2893 break;
2349 case IrInstructionIdBoolNot:2894 case IrInstSrcIdPtrToInt:
2350 ir_print_bool_not(irp, (IrInstructionBoolNot *)instruction);2895 ir_print_ptr_to_int(irp, (IrInstSrcPtrToInt *)instruction);
2351 break;2896 break;
2352 case IrInstructionIdMemset:2897 case IrInstSrcIdIntToPtr:
2353 ir_print_memset(irp, (IrInstructionMemset *)instruction);2898 ir_print_int_to_ptr(irp, (IrInstSrcIntToPtr *)instruction);
2354 break;2899 break;
2355 case IrInstructionIdMemcpy:2900 case IrInstSrcIdIntToEnum:
2356 ir_print_memcpy(irp, (IrInstructionMemcpy *)instruction);2901 ir_print_int_to_enum(irp, (IrInstSrcIntToEnum *)instruction);
2357 break;2902 break;
2358 case IrInstructionIdSliceSrc:2903 case IrInstSrcIdIntToErr:
2359 ir_print_slice_src(irp, (IrInstructionSliceSrc *)instruction);2904 ir_print_int_to_err(irp, (IrInstSrcIntToErr *)instruction);
2360 break;2905 break;
2361 case IrInstructionIdSliceGen:2906 case IrInstSrcIdErrToInt:
2362 ir_print_slice_gen(irp, (IrInstructionSliceGen *)instruction);2907 ir_print_err_to_int(irp, (IrInstSrcErrToInt *)instruction);
2363 break;2908 break;
2364 case IrInstructionIdMemberCount:2909 case IrInstSrcIdCheckSwitchProngs:
2365 ir_print_member_count(irp, (IrInstructionMemberCount *)instruction);2910 ir_print_check_switch_prongs(irp, (IrInstSrcCheckSwitchProngs *)instruction);
2366 break;2911 break;
2367 case IrInstructionIdMemberType:2912 case IrInstSrcIdCheckStatementIsVoid:
2368 ir_print_member_type(irp, (IrInstructionMemberType *)instruction);2913 ir_print_check_statement_is_void(irp, (IrInstSrcCheckStatementIsVoid *)instruction);
2369 break;2914 break;
2370 case IrInstructionIdMemberName:2915 case IrInstSrcIdTypeName:
2371 ir_print_member_name(irp, (IrInstructionMemberName *)instruction);2916 ir_print_type_name(irp, (IrInstSrcTypeName *)instruction);
2372 break;2917 break;
2373 case IrInstructionIdBreakpoint:2918 case IrInstSrcIdTagName:
2374 ir_print_breakpoint(irp, (IrInstructionBreakpoint *)instruction);2919 ir_print_tag_name(irp, (IrInstSrcTagName *)instruction);
2375 break;2920 break;
2376 case IrInstructionIdReturnAddress:2921 case IrInstSrcIdPtrType:
2377 ir_print_return_address(irp, (IrInstructionReturnAddress *)instruction);2922 ir_print_ptr_type(irp, (IrInstSrcPtrType *)instruction);
2378 break;2923 break;
2379 case IrInstructionIdFrameAddress:2924 case IrInstSrcIdDeclRef:
2380 ir_print_frame_address(irp, (IrInstructionFrameAddress *)instruction);2925 ir_print_decl_ref(irp, (IrInstSrcDeclRef *)instruction);
2381 break;2926 break;
2382 case IrInstructionIdFrameHandle:2927 case IrInstSrcIdPanic:
2383 ir_print_handle(irp, (IrInstructionFrameHandle *)instruction);2928 ir_print_panic(irp, (IrInstSrcPanic *)instruction);
2384 break;2929 break;
2385 case IrInstructionIdFrameType:2930 case IrInstSrcIdFieldParentPtr:
2386 ir_print_frame_type(irp, (IrInstructionFrameType *)instruction);2931 ir_print_field_parent_ptr(irp, (IrInstSrcFieldParentPtr *)instruction);
2387 break;2932 break;
2388 case IrInstructionIdFrameSizeSrc:2933 case IrInstSrcIdByteOffsetOf:
2389 ir_print_frame_size_src(irp, (IrInstructionFrameSizeSrc *)instruction);2934 ir_print_byte_offset_of(irp, (IrInstSrcByteOffsetOf *)instruction);
2390 break;2935 break;
2391 case IrInstructionIdFrameSizeGen:2936 case IrInstSrcIdBitOffsetOf:
2392 ir_print_frame_size_gen(irp, (IrInstructionFrameSizeGen *)instruction);2937 ir_print_bit_offset_of(irp, (IrInstSrcBitOffsetOf *)instruction);
2393 break;2938 break;
2394 case IrInstructionIdAlignOf:2939 case IrInstSrcIdTypeInfo:
2395 ir_print_align_of(irp, (IrInstructionAlignOf *)instruction);2940 ir_print_type_info(irp, (IrInstSrcTypeInfo *)instruction);
2396 break;2941 break;
2397 case IrInstructionIdOverflowOp:2942 case IrInstSrcIdType:
2398 ir_print_overflow_op(irp, (IrInstructionOverflowOp *)instruction);2943 ir_print_type(irp, (IrInstSrcType *)instruction);
2399 break;2944 break;
2400 case IrInstructionIdTestErrSrc:2945 case IrInstSrcIdHasField:
2401 ir_print_test_err_src(irp, (IrInstructionTestErrSrc *)instruction);2946 ir_print_has_field(irp, (IrInstSrcHasField *)instruction);
2402 break;2947 break;
2403 case IrInstructionIdTestErrGen:2948 case IrInstSrcIdTypeId:
2404 ir_print_test_err_gen(irp, (IrInstructionTestErrGen *)instruction);2949 ir_print_type_id(irp, (IrInstSrcTypeId *)instruction);
2405 break;2950 break;
2406 case IrInstructionIdUnwrapErrCode:2951 case IrInstSrcIdSetEvalBranchQuota:
2407 ir_print_unwrap_err_code(irp, (IrInstructionUnwrapErrCode *)instruction);2952 ir_print_set_eval_branch_quota(irp, (IrInstSrcSetEvalBranchQuota *)instruction);
2408 break;2953 break;
2409 case IrInstructionIdUnwrapErrPayload:2954 case IrInstSrcIdAlignCast:
2410 ir_print_unwrap_err_payload(irp, (IrInstructionUnwrapErrPayload *)instruction);2955 ir_print_align_cast(irp, (IrInstSrcAlignCast *)instruction);
2411 break;2956 break;
2412 case IrInstructionIdOptionalWrap:2957 case IrInstSrcIdImplicitCast:
2413 ir_print_optional_wrap(irp, (IrInstructionOptionalWrap *)instruction);2958 ir_print_implicit_cast(irp, (IrInstSrcImplicitCast *)instruction);
2414 break;2959 break;
2415 case IrInstructionIdErrWrapCode:2960 case IrInstSrcIdResolveResult:
2416 ir_print_err_wrap_code(irp, (IrInstructionErrWrapCode *)instruction);2961 ir_print_resolve_result(irp, (IrInstSrcResolveResult *)instruction);
2417 break;2962 break;
2418 case IrInstructionIdErrWrapPayload:2963 case IrInstSrcIdResetResult:
2419 ir_print_err_wrap_payload(irp, (IrInstructionErrWrapPayload *)instruction);2964 ir_print_reset_result(irp, (IrInstSrcResetResult *)instruction);
2420 break;2965 break;
2421 case IrInstructionIdFnProto:2966 case IrInstSrcIdOpaqueType:
2422 ir_print_fn_proto(irp, (IrInstructionFnProto *)instruction);2967 ir_print_opaque_type(irp, (IrInstSrcOpaqueType *)instruction);
2423 break;2968 break;
2424 case IrInstructionIdTestComptime:2969 case IrInstSrcIdSetAlignStack:
2425 ir_print_test_comptime(irp, (IrInstructionTestComptime *)instruction);2970 ir_print_set_align_stack(irp, (IrInstSrcSetAlignStack *)instruction);
2426 break;2971 break;
2427 case IrInstructionIdPtrCastSrc:2972 case IrInstSrcIdArgType:
2428 ir_print_ptr_cast_src(irp, (IrInstructionPtrCastSrc *)instruction);2973 ir_print_arg_type(irp, (IrInstSrcArgType *)instruction);
2429 break;2974 break;
2430 case IrInstructionIdPtrCastGen:2975 case IrInstSrcIdTagType:
2431 ir_print_ptr_cast_gen(irp, (IrInstructionPtrCastGen *)instruction);2976 ir_print_enum_tag_type(irp, (IrInstSrcTagType *)instruction);
2432 break;2977 break;
2433 case IrInstructionIdBitCastSrc:2978 case IrInstSrcIdExport:
2434 ir_print_bit_cast_src(irp, (IrInstructionBitCastSrc *)instruction);2979 ir_print_export(irp, (IrInstSrcExport *)instruction);
2435 break;2980 break;
2436 case IrInstructionIdBitCastGen:2981 case IrInstSrcIdErrorReturnTrace:
2437 ir_print_bit_cast_gen(irp, (IrInstructionBitCastGen *)instruction);2982 ir_print_error_return_trace(irp, (IrInstSrcErrorReturnTrace *)instruction);
2438 break;2983 break;
2439 case IrInstructionIdWidenOrShorten:2984 case IrInstSrcIdErrorUnion:
2440 ir_print_widen_or_shorten(irp, (IrInstructionWidenOrShorten *)instruction);2985 ir_print_error_union(irp, (IrInstSrcErrorUnion *)instruction);
2441 break;2986 break;
2442 case IrInstructionIdPtrToInt:2987 case IrInstSrcIdAtomicRmw:
2443 ir_print_ptr_to_int(irp, (IrInstructionPtrToInt *)instruction);2988 ir_print_atomic_rmw(irp, (IrInstSrcAtomicRmw *)instruction);
2444 break;2989 break;
2445 case IrInstructionIdIntToPtr:2990 case IrInstSrcIdSaveErrRetAddr:
2446 ir_print_int_to_ptr(irp, (IrInstructionIntToPtr *)instruction);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);
2447 break;3061 break;
2448 case IrInstructionIdIntToEnum:3062 case IrInstGenIdConst:
2449 ir_print_int_to_enum(irp, (IrInstructionIntToEnum *)instruction);3063 ir_print_const(irp, (IrInstGenConst *)instruction);
2450 break;3064 break;
2451 case IrInstructionIdIntToErr:3065 case IrInstGenIdBinOp:
2452 ir_print_int_to_err(irp, (IrInstructionIntToErr *)instruction);3066 ir_print_bin_op(irp, (IrInstGenBinOp *)instruction);
2453 break;3067 break;
2454 case IrInstructionIdErrToInt:3068 case IrInstGenIdDeclVar:
2455 ir_print_err_to_int(irp, (IrInstructionErrToInt *)instruction);3069 ir_print_decl_var_gen(irp, (IrInstGenDeclVar *)instruction);
2456 break;3070 break;
2457 case IrInstructionIdCheckSwitchProngs:3071 case IrInstGenIdCast:
2458 ir_print_check_switch_prongs(irp, (IrInstructionCheckSwitchProngs *)instruction);3072 ir_print_cast(irp, (IrInstGenCast *)instruction);
2459 break;3073 break;
2460 case IrInstructionIdCheckStatementIsVoid:3074 case IrInstGenIdCall:
2461 ir_print_check_statement_is_void(irp, (IrInstructionCheckStatementIsVoid *)instruction);3075 ir_print_call_gen(irp, (IrInstGenCall *)instruction);
2462 break;3076 break;
2463 case IrInstructionIdTypeName:3077 case IrInstGenIdCondBr:
2464 ir_print_type_name(irp, (IrInstructionTypeName *)instruction);3078 ir_print_cond_br(irp, (IrInstGenCondBr *)instruction);
2465 break;3079 break;
2466 case IrInstructionIdTagName:3080 case IrInstGenIdBr:
2467 ir_print_tag_name(irp, (IrInstructionTagName *)instruction);3081 ir_print_br(irp, (IrInstGenBr *)instruction);
2468 break;3082 break;
2469 case IrInstructionIdPtrType:3083 case IrInstGenIdPhi:
2470 ir_print_ptr_type(irp, (IrInstructionPtrType *)instruction);3084 ir_print_phi(irp, (IrInstGenPhi *)instruction);
2471 break;3085 break;
2472 case IrInstructionIdDeclRef:3086 case IrInstGenIdUnreachable:
2473 ir_print_decl_ref(irp, (IrInstructionDeclRef *)instruction);3087 ir_print_unreachable(irp, (IrInstGenUnreachable *)instruction);
2474 break;3088 break;
2475 case IrInstructionIdPanic:3089 case IrInstGenIdElemPtr:
2476 ir_print_panic(irp, (IrInstructionPanic *)instruction);3090 ir_print_elem_ptr(irp, (IrInstGenElemPtr *)instruction);
2477 break;3091 break;
2478 case IrInstructionIdFieldParentPtr:3092 case IrInstGenIdVarPtr:
2479 ir_print_field_parent_ptr(irp, (IrInstructionFieldParentPtr *)instruction);3093 ir_print_var_ptr(irp, (IrInstGenVarPtr *)instruction);
2480 break;3094 break;
2481 case IrInstructionIdByteOffsetOf:3095 case IrInstGenIdReturnPtr:
2482 ir_print_byte_offset_of(irp, (IrInstructionByteOffsetOf *)instruction);3096 ir_print_return_ptr(irp, (IrInstGenReturnPtr *)instruction);
2483 break;3097 break;
2484 case IrInstructionIdBitOffsetOf:3098 case IrInstGenIdLoadPtr:
2485 ir_print_bit_offset_of(irp, (IrInstructionBitOffsetOf *)instruction);3099 ir_print_load_ptr_gen(irp, (IrInstGenLoadPtr *)instruction);
2486 break;3100 break;
2487 case IrInstructionIdTypeInfo:3101 case IrInstGenIdStorePtr:
2488 ir_print_type_info(irp, (IrInstructionTypeInfo *)instruction);3102 ir_print_store_ptr(irp, (IrInstGenStorePtr *)instruction);
2489 break;3103 break;
2490 case IrInstructionIdType:3104 case IrInstGenIdStructFieldPtr:
2491 ir_print_type(irp, (IrInstructionType *)instruction);3105 ir_print_struct_field_ptr(irp, (IrInstGenStructFieldPtr *)instruction);
2492 break;3106 break;
2493 case IrInstructionIdHasField:3107 case IrInstGenIdUnionFieldPtr:
2494 ir_print_has_field(irp, (IrInstructionHasField *)instruction);3108 ir_print_union_field_ptr(irp, (IrInstGenUnionFieldPtr *)instruction);
2495 break;3109 break;
2496 case IrInstructionIdTypeId:3110 case IrInstGenIdAsm:
2497 ir_print_type_id(irp, (IrInstructionTypeId *)instruction);3111 ir_print_asm_gen(irp, (IrInstGenAsm *)instruction);
2498 break;3112 break;
2499 case IrInstructionIdSetEvalBranchQuota:3113 case IrInstGenIdTestNonNull:
2500 ir_print_set_eval_branch_quota(irp, (IrInstructionSetEvalBranchQuota *)instruction);3114 ir_print_test_non_null(irp, (IrInstGenTestNonNull *)instruction);
2501 break;3115 break;
2502 case IrInstructionIdAlignCast:3116 case IrInstGenIdOptionalUnwrapPtr:
2503 ir_print_align_cast(irp, (IrInstructionAlignCast *)instruction);3117 ir_print_optional_unwrap_ptr(irp, (IrInstGenOptionalUnwrapPtr *)instruction);
2504 break;3118 break;
2505 case IrInstructionIdImplicitCast:3119 case IrInstGenIdPopCount:
2506 ir_print_implicit_cast(irp, (IrInstructionImplicitCast *)instruction);3120 ir_print_pop_count(irp, (IrInstGenPopCount *)instruction);
2507 break;3121 break;
2508 case IrInstructionIdResolveResult:3122 case IrInstGenIdClz:
2509 ir_print_resolve_result(irp, (IrInstructionResolveResult *)instruction);3123 ir_print_clz(irp, (IrInstGenClz *)instruction);
2510 break;3124 break;
2511 case IrInstructionIdResetResult:3125 case IrInstGenIdCtz:
2512 ir_print_reset_result(irp, (IrInstructionResetResult *)instruction);3126 ir_print_ctz(irp, (IrInstGenCtz *)instruction);
2513 break;3127 break;
2514 case IrInstructionIdOpaqueType:3128 case IrInstGenIdBswap:
2515 ir_print_opaque_type(irp, (IrInstructionOpaqueType *)instruction);3129 ir_print_bswap(irp, (IrInstGenBswap *)instruction);
2516 break;3130 break;
2517 case IrInstructionIdSetAlignStack:3131 case IrInstGenIdBitReverse:
2518 ir_print_set_align_stack(irp, (IrInstructionSetAlignStack *)instruction);3132 ir_print_bit_reverse(irp, (IrInstGenBitReverse *)instruction);
2519 break;3133 break;
2520 case IrInstructionIdArgType:3134 case IrInstGenIdSwitchBr:
2521 ir_print_arg_type(irp, (IrInstructionArgType *)instruction);3135 ir_print_switch_br(irp, (IrInstGenSwitchBr *)instruction);
2522 break;3136 break;
2523 case IrInstructionIdTagType:3137 case IrInstGenIdUnionTag:
2524 ir_print_enum_tag_type(irp, (IrInstructionTagType *)instruction);3138 ir_print_union_tag(irp, (IrInstGenUnionTag *)instruction);
2525 break;3139 break;
2526 case IrInstructionIdExport:3140 case IrInstGenIdRef:
2527 ir_print_export(irp, (IrInstructionExport *)instruction);3141 ir_print_ref_gen(irp, (IrInstGenRef *)instruction);
2528 break;3142 break;
2529 case IrInstructionIdErrorReturnTrace:3143 case IrInstGenIdErrName:
2530 ir_print_error_return_trace(irp, (IrInstructionErrorReturnTrace *)instruction);3144 ir_print_err_name(irp, (IrInstGenErrName *)instruction);
2531 break;3145 break;
2532 case IrInstructionIdErrorUnion:3146 case IrInstGenIdCmpxchg:
2533 ir_print_error_union(irp, (IrInstructionErrorUnion *)instruction);3147 ir_print_cmpxchg_gen(irp, (IrInstGenCmpxchg *)instruction);
2534 break;3148 break;
2535 case IrInstructionIdAtomicRmw:3149 case IrInstGenIdFence:
2536 ir_print_atomic_rmw(irp, (IrInstructionAtomicRmw *)instruction);3150 ir_print_fence(irp, (IrInstGenFence *)instruction);
2537 break;3151 break;
2538 case IrInstructionIdSaveErrRetAddr:3152 case IrInstGenIdTruncate:
2539 ir_print_save_err_ret_addr(irp, (IrInstructionSaveErrRetAddr *)instruction);3153 ir_print_truncate(irp, (IrInstGenTruncate *)instruction);
2540 break;3154 break;
2541 case IrInstructionIdAddImplicitReturnType:3155 case IrInstGenIdShuffleVector:
2542 ir_print_add_implicit_return_type(irp, (IrInstructionAddImplicitReturnType *)instruction);3156 ir_print_shuffle_vector(irp, (IrInstGenShuffleVector *)instruction);
2543 break;3157 break;
2544 case IrInstructionIdFloatOp:3158 case IrInstGenIdSplat:
2545 ir_print_float_op(irp, (IrInstructionFloatOp *)instruction);3159 ir_print_splat_gen(irp, (IrInstGenSplat *)instruction);
2546 break;3160 break;
2547 case IrInstructionIdMulAdd:3161 case IrInstGenIdBoolNot:
2548 ir_print_mul_add(irp, (IrInstructionMulAdd *)instruction);3162 ir_print_bool_not(irp, (IrInstGenBoolNot *)instruction);
2549 break;3163 break;
2550 case IrInstructionIdAtomicLoad:3164 case IrInstGenIdMemset:
2551 ir_print_atomic_load(irp, (IrInstructionAtomicLoad *)instruction);3165 ir_print_memset(irp, (IrInstGenMemset *)instruction);
2552 break;3166 break;
2553 case IrInstructionIdAtomicStore:3167 case IrInstGenIdMemcpy:
2554 ir_print_atomic_store(irp, (IrInstructionAtomicStore *)instruction);3168 ir_print_memcpy(irp, (IrInstGenMemcpy *)instruction);
2555 break;3169 break;
2556 case IrInstructionIdEnumToInt:3170 case IrInstGenIdSlice:
2557 ir_print_enum_to_int(irp, (IrInstructionEnumToInt *)instruction);3171 ir_print_slice_gen(irp, (IrInstGenSlice *)instruction);
2558 break;3172 break;
2559 case IrInstructionIdCheckRuntimeScope:3173 case IrInstGenIdBreakpoint:
2560 ir_print_check_runtime_scope(irp, (IrInstructionCheckRuntimeScope *)instruction);3174 ir_print_breakpoint(irp, (IrInstGenBreakpoint *)instruction);
2561 break;3175 break;
2562 case IrInstructionIdDeclVarGen:3176 case IrInstGenIdReturnAddress:
2563 ir_print_decl_var_gen(irp, (IrInstructionDeclVarGen *)instruction);3177 ir_print_return_address(irp, (IrInstGenReturnAddress *)instruction);
2564 break;3178 break;
2565 case IrInstructionIdArrayToVector:3179 case IrInstGenIdFrameAddress:
2566 ir_print_array_to_vector(irp, (IrInstructionArrayToVector *)instruction);3180 ir_print_frame_address(irp, (IrInstGenFrameAddress *)instruction);
2567 break;3181 break;
2568 case IrInstructionIdVectorToArray:3182 case IrInstGenIdFrameHandle:
2569 ir_print_vector_to_array(irp, (IrInstructionVectorToArray *)instruction);3183 ir_print_handle(irp, (IrInstGenFrameHandle *)instruction);
2570 break;3184 break;
2571 case IrInstructionIdPtrOfArrayToSlice:3185 case IrInstGenIdFrameSize:
2572 ir_print_ptr_of_array_to_slice(irp, (IrInstructionPtrOfArrayToSlice *)instruction);3186 ir_print_frame_size_gen(irp, (IrInstGenFrameSize *)instruction);
2573 break;3187 break;
2574 case IrInstructionIdAssertZero:3188 case IrInstGenIdOverflowOp:
2575 ir_print_assert_zero(irp, (IrInstructionAssertZero *)instruction);3189 ir_print_overflow_op(irp, (IrInstGenOverflowOp *)instruction);
2576 break;3190 break;
2577 case IrInstructionIdAssertNonNull:3191 case IrInstGenIdTestErr:
2578 ir_print_assert_non_null(irp, (IrInstructionAssertNonNull *)instruction);3192 ir_print_test_err_gen(irp, (IrInstGenTestErr *)instruction);
2579 break;3193 break;
2580 case IrInstructionIdResizeSlice:3194 case IrInstGenIdUnwrapErrCode:
2581 ir_print_resize_slice(irp, (IrInstructionResizeSlice *)instruction);3195 ir_print_unwrap_err_code(irp, (IrInstGenUnwrapErrCode *)instruction);
2582 break;3196 break;
2583 case IrInstructionIdHasDecl:3197 case IrInstGenIdUnwrapErrPayload:
2584 ir_print_has_decl(irp, (IrInstructionHasDecl *)instruction);3198 ir_print_unwrap_err_payload(irp, (IrInstGenUnwrapErrPayload *)instruction);
2585 break;3199 break;
2586 case IrInstructionIdUndeclaredIdent:3200 case IrInstGenIdOptionalWrap:
2587 ir_print_undeclared_ident(irp, (IrInstructionUndeclaredIdent *)instruction);3201 ir_print_optional_wrap(irp, (IrInstGenOptionalWrap *)instruction);
2588 break;3202 break;
2589 case IrInstructionIdAllocaSrc:3203 case IrInstGenIdErrWrapCode:
2590 ir_print_alloca_src(irp, (IrInstructionAllocaSrc *)instruction);3204 ir_print_err_wrap_code(irp, (IrInstGenErrWrapCode *)instruction);
2591 break;3205 break;
2592 case IrInstructionIdAllocaGen:3206 case IrInstGenIdErrWrapPayload:
2593 ir_print_alloca_gen(irp, (IrInstructionAllocaGen *)instruction);3207 ir_print_err_wrap_payload(irp, (IrInstGenErrWrapPayload *)instruction);
2594 break;3208 break;
2595 case IrInstructionIdEndExpr:3209 case IrInstGenIdPtrCast:
2596 ir_print_end_expr(irp, (IrInstructionEndExpr *)instruction);3210 ir_print_ptr_cast_gen(irp, (IrInstGenPtrCast *)instruction);
2597 break;3211 break;
2598 case IrInstructionIdUnionInitNamedField:3212 case IrInstGenIdBitCast:
2599 ir_print_union_init_named_field(irp, (IrInstructionUnionInitNamedField *)instruction);3213 ir_print_bit_cast_gen(irp, (IrInstGenBitCast *)instruction);
2600 break;3214 break;
2601 case IrInstructionIdSuspendBegin:3215 case IrInstGenIdWidenOrShorten:
2602 ir_print_suspend_begin(irp, (IrInstructionSuspendBegin *)instruction);3216 ir_print_widen_or_shorten(irp, (IrInstGenWidenOrShorten *)instruction);
2603 break;3217 break;
2604 case IrInstructionIdSuspendFinish:3218 case IrInstGenIdPtrToInt:
2605 ir_print_suspend_finish(irp, (IrInstructionSuspendFinish *)instruction);3219 ir_print_ptr_to_int(irp, (IrInstGenPtrToInt *)instruction);
2606 break;3220 break;
2607 case IrInstructionIdResume:3221 case IrInstGenIdIntToPtr:
2608 ir_print_resume(irp, (IrInstructionResume *)instruction);3222 ir_print_int_to_ptr(irp, (IrInstGenIntToPtr *)instruction);
2609 break;3223 break;
2610 case IrInstructionIdAwaitSrc:3224 case IrInstGenIdIntToEnum:
2611 ir_print_await_src(irp, (IrInstructionAwaitSrc *)instruction);3225 ir_print_int_to_enum(irp, (IrInstGenIntToEnum *)instruction);
2612 break;3226 break;
2613 case IrInstructionIdAwaitGen:3227 case IrInstGenIdIntToErr:
2614 ir_print_await_gen(irp, (IrInstructionAwaitGen *)instruction);3228 ir_print_int_to_err(irp, (IrInstGenIntToErr *)instruction);
2615 break;3229 break;
2616 case IrInstructionIdSpillBegin:3230 case IrInstGenIdErrToInt:
2617 ir_print_spill_begin(irp, (IrInstructionSpillBegin *)instruction);3231 ir_print_err_to_int(irp, (IrInstGenErrToInt *)instruction);
2618 break;3232 break;
2619 case IrInstructionIdSpillEnd:3233 case IrInstGenIdTagName:
2620 ir_print_spill_end(irp, (IrInstructionSpillEnd *)instruction);3234 ir_print_tag_name(irp, (IrInstGenTagName *)instruction);
2621 break;3235 break;
2622 case IrInstructionIdVectorExtractElem:3236 case IrInstGenIdPanic:
2623 ir_print_vector_extract_elem(irp, (IrInstructionVectorExtractElem *)instruction);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);
2624 break;3319 break;
2625 }3320 }
2626 fprintf(irp->f, "\n");3321 fprintf(irp->f, "\n");
2627}3322}
26283323
2629static void irp_print_basic_block(IrPrint *irp, IrBasicBlock *current_block) {3324static void irp_print_basic_block_src(IrPrintSrc *irp, IrBasicBlockSrc *current_block) {
2630 fprintf(irp->f, "%s_%" ZIG_PRI_usize ":\n", current_block->name_hint, current_block->debug_id);3325 fprintf(irp->f, "%s_%" PRIu32 ":\n", current_block->name_hint, current_block->debug_id);
2631 for (size_t instr_i = 0; instr_i < current_block->instruction_list.length; instr_i += 1) {3326 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);3327 IrInstSrc *instruction = current_block->instruction_list.at(instr_i);
2633 if (irp->pass != IrPassSrc) {3328 ir_print_inst_src(irp, instruction, false);
2634 irp->printed.put(instruction, 0);3329 }
2635 irp->pending.clear();3330}
2636 }3331
2637 ir_print_instruction(irp, instruction, false);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);
2638 for (size_t j = 0; j < irp->pending.length; ++j)3339 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);
2640 }3341 }
2641}3342}
26423343
2643void ir_print_basic_block(CodeGen *codegen, FILE *f, IrBasicBlock *bb, int indent_size, IrPass pass) {3344void ir_print_basic_block_src(CodeGen *codegen, FILE *f, IrBasicBlockSrc *bb, int indent_size) {
2644 IrPrint ir_print = {};3345 IrPrintSrc ir_print = {};
2645 ir_print.pass = pass;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 = {};
2646 ir_print.codegen = codegen;3356 ir_print.codegen = codegen;
2647 ir_print.f = f;3357 ir_print.f = f;
2648 ir_print.indent = indent_size;3358 ir_print.indent = indent_size;
...@@ -2651,16 +3361,28 @@ void ir_print_basic_block(CodeGen *codegen, FILE *f, IrBasicBlock *bb, int inden...@@ -2651,16 +3361,28 @@ void ir_print_basic_block(CodeGen *codegen, FILE *f, IrBasicBlock *bb, int inden
2651 ir_print.printed.init(64);3361 ir_print.printed.init(64);
2652 ir_print.pending = {};3362 ir_print.pending = {};
26533363
2654 irp_print_basic_block(&ir_print, bb);3364 irp_print_basic_block_gen(&ir_print, bb);
26553365
2656 ir_print.pending.deinit();3366 ir_print.pending.deinit();
2657 ir_print.printed.deinit();3367 ir_print.printed.deinit();
2658}3368}
26593369
2660void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_size, IrPass pass) {3370void ir_print_src(CodeGen *codegen, FILE *f, IrExecutableSrc *executable, int indent_size) {
2661 IrPrint ir_print = {};3371 IrPrintSrc ir_print = {};
2662 IrPrint *irp = &ir_print;3372 IrPrintSrc *irp = &ir_print;
2663 irp->pass = pass;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;
2664 irp->codegen = codegen;3386 irp->codegen = codegen;
2665 irp->f = f;3387 irp->f = f;
2666 irp->indent = indent_size;3388 irp->indent = indent_size;
...@@ -2670,32 +3392,27 @@ void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_si...@@ -2670,32 +3392,27 @@ void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_si
2670 irp->pending = {};3392 irp->pending = {};
26713393
2672 for (size_t bb_i = 0; bb_i < executable->basic_block_list.length; bb_i += 1) {3394 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));
2674 }3396 }
26753397
2676 irp->pending.deinit();3398 irp->pending.deinit();
2677 irp->printed.deinit();3399 irp->printed.deinit();
2678}3400}
26793401
2680void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction, int indent_size, IrPass pass) {3402void ir_print_inst_src(CodeGen *codegen, FILE *f, IrInstSrc *instruction, int indent_size) {
2681 IrPrint ir_print = {};3403 IrPrintSrc ir_print = {};
2682 IrPrint *irp = &ir_print;3404 IrPrintSrc *irp = &ir_print;
2683 irp->pass = pass;
2684 irp->codegen = codegen;3405 irp->codegen = codegen;
2685 irp->f = f;3406 irp->f = f;
2686 irp->indent = indent_size;3407 irp->indent = indent_size;
2687 irp->indent_size = indent_size;3408 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);
2693}3411}
26943412
2695void ir_print_const_expr(CodeGen *codegen, FILE *f, ZigValue *value, int indent_size, IrPass pass) {3413void ir_print_inst_gen(CodeGen *codegen, FILE *f, IrInstGen *instruction, int indent_size) {
2696 IrPrint ir_print = {};3414 IrPrintGen ir_print = {};
2697 IrPrint *irp = &ir_print;3415 IrPrintGen *irp = &ir_print;
2698 irp->pass = pass;
2699 irp->codegen = codegen;3416 irp->codegen = codegen;
2700 irp->f = f;3417 irp->f = f;
2701 irp->indent = indent_size;3418 irp->indent = indent_size;
...@@ -2704,5 +3421,5 @@ void ir_print_const_expr(CodeGen *codegen, FILE *f, ZigValue *value, int indent_...@@ -2704,5 +3421,5 @@ void ir_print_const_expr(CodeGen *codegen, FILE *f, ZigValue *value, int indent_
2704 irp->printed.init(4);3421 irp->printed.init(4);
2705 irp->pending = {};3422 irp->pending = {};
27063423
2707 ir_print_const_value(irp, value);3424 ir_print_inst_gen(irp, instruction, false);
2708}3425}
src/ir_print.hpp+8-5
...@@ -12,11 +12,14 @@...@@ -12,11 +12,14 @@
1212
13#include <stdio.h>13#include <stdio.h>
1414
15void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_size, IrPass pass);15void ir_print_src(CodeGen *codegen, FILE *f, IrExecutableSrc *executable, int indent_size);
16void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction, int indent_size, IrPass pass);16void ir_print_gen(CodeGen *codegen, FILE *f, IrExecutableGen *executable, int indent_size);
17void ir_print_const_expr(CodeGen *codegen, FILE *f, ZigValue *value, int indent_size, IrPass pass);17void ir_print_inst_src(CodeGen *codegen, FILE *f, IrInstSrc *inst, int indent_size);
18void ir_print_basic_block(CodeGen *codegen, FILE *f, IrBasicBlock *bb, int indent_size, IrPass pass);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
22#endif25#endif
src/main.cpp+5-5
...@@ -144,15 +144,15 @@ static int print_libc_usage(const char *arg0, FILE *file, int return_code) {...@@ -144,15 +144,15 @@ static int print_libc_usage(const char *arg0, FILE *file, int return_code) {
144 "You can save this into a file and then edit the paths to create a cross\n"144 "You can save this into a file and then edit the paths to create a cross\n"
145 "compilation libc kit. Then you can pass `--libc [file]` for Zig to use it.\n"145 "compilation libc kit. Then you can pass `--libc [file]` for Zig to use it.\n"
146 "\n"146 "\n"
147 "When compiling natively and no `--libc` argument provided, Zig automatically\n"147 "When compiling natively and no `--libc` argument provided, Zig will create\n"
148 "creates zig-cache/native_libc.txt so that it does not have to detect libc\n"148 "`%s/native_libc.txt`\n"
149 "on every invocation. You can remove this file to have Zig re-detect the\n"149 "so that it does not have to detect libc on every invocation. You can remove\n"
150 "native libc.\n"150 "this file to have Zig re-detect the native libc.\n"
151 "\n\n"151 "\n\n"
152 "Usage: %s libc [file]\n"152 "Usage: %s libc [file]\n"
153 "\n"153 "\n"
154 "Parse a libc installation text file and validate it.\n"154 "Parse a libc installation text file and validate it.\n"
155 , arg0, arg0);155 , arg0, buf_ptr(get_global_cache_dir()), arg0);
156 return return_code;156 return return_code;
157}157}
158158
src/parser.cpp+1-1
...@@ -147,7 +147,7 @@ static void ast_invalid_token_error(ParseContext *pc, Token *token) {...@@ -147,7 +147,7 @@ static void ast_invalid_token_error(ParseContext *pc, Token *token) {
147}147}
148148
149static AstNode *ast_create_node_no_line_info(ParseContext *pc, NodeType type) {149static AstNode *ast_create_node_no_line_info(ParseContext *pc, NodeType type) {
150 AstNode *node = allocate<AstNode>(1);150 AstNode *node = allocate<AstNode>(1, "AstNode");
151 node->type = type;151 node->type = type;
152 node->owner = pc->owner;152 node->owner = pc->owner;
153 return node;153 return node;
src/zig_clang.cpp+9
...@@ -1625,6 +1625,10 @@ unsigned ZigClangFunctionDecl_getAlignedAttribute(const struct ZigClangFunctionD...@@ -1625,6 +1625,10 @@ unsigned ZigClangFunctionDecl_getAlignedAttribute(const struct ZigClangFunctionD
1625 return 0;1625 return 0;
1626}1626}
16271627
1628ZigClangQualType ZigClangParmVarDecl_getOriginalType(const struct ZigClangParmVarDecl *self) {
1629 return bitcast(reinterpret_cast<const clang::ParmVarDecl *>(self)->getOriginalType());
1630}
1631
1628const ZigClangRecordDecl *ZigClangRecordDecl_getDefinition(const ZigClangRecordDecl *zig_record_decl) {1632const ZigClangRecordDecl *ZigClangRecordDecl_getDefinition(const ZigClangRecordDecl *zig_record_decl) {
1629 const clang::RecordDecl *record_decl = reinterpret_cast<const clang::RecordDecl *>(zig_record_decl);1633 const clang::RecordDecl *record_decl = reinterpret_cast<const clang::RecordDecl *>(zig_record_decl);
1630 const clang::RecordDecl *definition = record_decl->getDefinition();1634 const clang::RecordDecl *definition = record_decl->getDefinition();
...@@ -1877,6 +1881,11 @@ bool ZigClangType_isRecordType(const ZigClangType *self) {...@@ -1877,6 +1881,11 @@ bool ZigClangType_isRecordType(const ZigClangType *self) {
1877 return casted->isRecordType();1881 return casted->isRecordType();
1878}1882}
18791883
1884bool ZigClangType_isConstantArrayType(const ZigClangType *self) {
1885 auto casted = reinterpret_cast<const clang::Type *>(self);
1886 return casted->isConstantArrayType();
1887}
1888
1880const char *ZigClangType_getTypeClassName(const ZigClangType *self) {1889const char *ZigClangType_getTypeClassName(const ZigClangType *self) {
1881 auto casted = reinterpret_cast<const clang::Type *>(self);1890 auto casted = reinterpret_cast<const clang::Type *>(self);
1882 return casted->getTypeClassName();1891 return casted->getTypeClassName();
src/zig_clang.h+3
...@@ -866,6 +866,8 @@ ZIG_EXTERN_C const char* ZigClangVarDecl_getSectionAttribute(const struct ZigCla...@@ -866,6 +866,8 @@ ZIG_EXTERN_C const char* ZigClangVarDecl_getSectionAttribute(const struct ZigCla
866ZIG_EXTERN_C unsigned ZigClangVarDecl_getAlignedAttribute(const struct ZigClangVarDecl *self, const ZigClangASTContext* ctx);866ZIG_EXTERN_C unsigned ZigClangVarDecl_getAlignedAttribute(const struct ZigClangVarDecl *self, const ZigClangASTContext* ctx);
867ZIG_EXTERN_C unsigned ZigClangFunctionDecl_getAlignedAttribute(const struct ZigClangFunctionDecl *self, const ZigClangASTContext* ctx);867ZIG_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
869ZIG_EXTERN_C bool ZigClangRecordDecl_getPackedAttribute(const struct ZigClangRecordDecl *);871ZIG_EXTERN_C bool ZigClangRecordDecl_getPackedAttribute(const struct ZigClangRecordDecl *);
870ZIG_EXTERN_C const struct ZigClangRecordDecl *ZigClangRecordDecl_getDefinition(const struct ZigClangRecordDecl *);872ZIG_EXTERN_C const struct ZigClangRecordDecl *ZigClangRecordDecl_getDefinition(const struct ZigClangRecordDecl *);
871ZIG_EXTERN_C const struct ZigClangEnumDecl *ZigClangEnumDecl_getDefinition(const struct ZigClangEnumDecl *);873ZIG_EXTERN_C const struct ZigClangEnumDecl *ZigClangEnumDecl_getDefinition(const struct ZigClangEnumDecl *);
...@@ -945,6 +947,7 @@ ZIG_EXTERN_C bool ZigClangType_isBooleanType(const struct ZigClangType *self);...@@ -945,6 +947,7 @@ ZIG_EXTERN_C bool ZigClangType_isBooleanType(const struct ZigClangType *self);
945ZIG_EXTERN_C bool ZigClangType_isVoidType(const struct ZigClangType *self);947ZIG_EXTERN_C bool ZigClangType_isVoidType(const struct ZigClangType *self);
946ZIG_EXTERN_C bool ZigClangType_isArrayType(const struct ZigClangType *self);948ZIG_EXTERN_C bool ZigClangType_isArrayType(const struct ZigClangType *self);
947ZIG_EXTERN_C bool ZigClangType_isRecordType(const struct ZigClangType *self);949ZIG_EXTERN_C bool ZigClangType_isRecordType(const struct ZigClangType *self);
950ZIG_EXTERN_C bool ZigClangType_isConstantArrayType(const ZigClangType *self);
948ZIG_EXTERN_C const char *ZigClangType_getTypeClassName(const struct ZigClangType *self);951ZIG_EXTERN_C const char *ZigClangType_getTypeClassName(const struct ZigClangType *self);
949ZIG_EXTERN_C const struct ZigClangArrayType *ZigClangType_getAsArrayTypeUnsafe(const struct ZigClangType *self);952ZIG_EXTERN_C const struct ZigClangArrayType *ZigClangType_getAsArrayTypeUnsafe(const struct ZigClangType *self);
950ZIG_EXTERN_C const ZigClangRecordType *ZigClangType_getAsRecordType(const ZigClangType *self);953ZIG_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 {...@@ -51,11 +51,15 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
51 // debug51 // debug
52 \\error: TheSkyIsFalling52 \\error: TheSkyIsFalling
53 \\source.zig:4:5: [address] in main (test)53 \\source.zig:4:5: [address] in main (test)
54 \\ return error.TheSkyIsFalling;
55 \\ ^
54 \\56 \\
55 ,57 ,
56 // release-safe58 // release-safe
57 \\error: TheSkyIsFalling59 \\error: TheSkyIsFalling
58 \\source.zig:4:5: [address] in std.start.main (test)60 \\source.zig:4:5: [address] in std.start.main (test)
61 \\ return error.TheSkyIsFalling;
62 \\ ^
59 \\63 \\
60 ,64 ,
61 // release-fast65 // release-fast
...@@ -74,13 +78,21 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -74,13 +78,21 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
74 // debug78 // debug
75 \\error: TheSkyIsFalling79 \\error: TheSkyIsFalling
76 \\source.zig:4:5: [address] in foo (test)80 \\source.zig:4:5: [address] in foo (test)
81 \\ return error.TheSkyIsFalling;
82 \\ ^
77 \\source.zig:8:5: [address] in main (test)83 \\source.zig:8:5: [address] in main (test)
84 \\ try foo();
85 \\ ^
78 \\86 \\
79 ,87 ,
80 // release-safe88 // release-safe
81 \\error: TheSkyIsFalling89 \\error: TheSkyIsFalling
82 \\source.zig:4:5: [address] in std.start.main (test)90 \\source.zig:4:5: [address] in std.start.main (test)
91 \\ return error.TheSkyIsFalling;
92 \\ ^
83 \\source.zig:8:5: [address] in std.start.main (test)93 \\source.zig:8:5: [address] in std.start.main (test)
94 \\ try foo();
95 \\ ^
84 \\96 \\
85 ,97 ,
86 // release-fast98 // release-fast
...@@ -99,17 +111,33 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -99,17 +111,33 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
99 // debug111 // debug
100 \\error: TheSkyIsFalling112 \\error: TheSkyIsFalling
101 \\source.zig:12:5: [address] in make_error (test)113 \\source.zig:12:5: [address] in make_error (test)
114 \\ return error.TheSkyIsFalling;
115 \\ ^
102 \\source.zig:8:5: [address] in bar (test)116 \\source.zig:8:5: [address] in bar (test)
117 \\ return make_error();
118 \\ ^
103 \\source.zig:4:5: [address] in foo (test)119 \\source.zig:4:5: [address] in foo (test)
120 \\ try bar();
121 \\ ^
104 \\source.zig:16:5: [address] in main (test)122 \\source.zig:16:5: [address] in main (test)
123 \\ try foo();
124 \\ ^
105 \\125 \\
106 ,126 ,
107 // release-safe127 // release-safe
108 \\error: TheSkyIsFalling128 \\error: TheSkyIsFalling
109 \\source.zig:12:5: [address] in std.start.main (test)129 \\source.zig:12:5: [address] in std.start.main (test)
130 \\ return error.TheSkyIsFalling;
131 \\ ^
110 \\source.zig:8:5: [address] in std.start.main (test)132 \\source.zig:8:5: [address] in std.start.main (test)
133 \\ return make_error();
134 \\ ^
111 \\source.zig:4:5: [address] in std.start.main (test)135 \\source.zig:4:5: [address] in std.start.main (test)
136 \\ try bar();
137 \\ ^
112 \\source.zig:16:5: [address] in std.start.main (test)138 \\source.zig:16:5: [address] in std.start.main (test)
139 \\ try foo();
140 \\ ^
113 \\141 \\
114 ,142 ,
115 // release-fast143 // release-fast
...@@ -130,11 +158,15 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -130,11 +158,15 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
130 // debug158 // debug
131 \\error: TheSkyIsFalling159 \\error: TheSkyIsFalling
132 \\source.zig:4:5: [address] in main (test)160 \\source.zig:4:5: [address] in main (test)
161 \\ return error.TheSkyIsFalling;
162 \\ ^
133 \\163 \\
134 ,164 ,
135 // release-safe165 // release-safe
136 \\error: TheSkyIsFalling166 \\error: TheSkyIsFalling
137 \\source.zig:4:5: [address] in std.start.posixCallMainAndExit (test)167 \\source.zig:4:5: [address] in std.start.posixCallMainAndExit (test)
168 \\ return error.TheSkyIsFalling;
169 \\ ^
138 \\170 \\
139 ,171 ,
140 // release-fast172 // release-fast
...@@ -153,13 +185,21 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -153,13 +185,21 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
153 // debug185 // debug
154 \\error: TheSkyIsFalling186 \\error: TheSkyIsFalling
155 \\source.zig:4:5: [address] in foo (test)187 \\source.zig:4:5: [address] in foo (test)
188 \\ return error.TheSkyIsFalling;
189 \\ ^
156 \\source.zig:8:5: [address] in main (test)190 \\source.zig:8:5: [address] in main (test)
191 \\ try foo();
192 \\ ^
157 \\193 \\
158 ,194 ,
159 // release-safe195 // release-safe
160 \\error: TheSkyIsFalling196 \\error: TheSkyIsFalling
161 \\source.zig:4:5: [address] in std.start.posixCallMainAndExit (test)197 \\source.zig:4:5: [address] in std.start.posixCallMainAndExit (test)
198 \\ return error.TheSkyIsFalling;
199 \\ ^
162 \\source.zig:8:5: [address] in std.start.posixCallMainAndExit (test)200 \\source.zig:8:5: [address] in std.start.posixCallMainAndExit (test)
201 \\ try foo();
202 \\ ^
163 \\203 \\
164 ,204 ,
165 // release-fast205 // release-fast
...@@ -178,17 +218,33 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -178,17 +218,33 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
178 // debug218 // debug
179 \\error: TheSkyIsFalling219 \\error: TheSkyIsFalling
180 \\source.zig:12:5: [address] in make_error (test)220 \\source.zig:12:5: [address] in make_error (test)
221 \\ return error.TheSkyIsFalling;
222 \\ ^
181 \\source.zig:8:5: [address] in bar (test)223 \\source.zig:8:5: [address] in bar (test)
224 \\ return make_error();
225 \\ ^
182 \\source.zig:4:5: [address] in foo (test)226 \\source.zig:4:5: [address] in foo (test)
227 \\ try bar();
228 \\ ^
183 \\source.zig:16:5: [address] in main (test)229 \\source.zig:16:5: [address] in main (test)
230 \\ try foo();
231 \\ ^
184 \\232 \\
185 ,233 ,
186 // release-safe234 // release-safe
187 \\error: TheSkyIsFalling235 \\error: TheSkyIsFalling
188 \\source.zig:12:5: [address] in std.start.posixCallMainAndExit (test)236 \\source.zig:12:5: [address] in std.start.posixCallMainAndExit (test)
237 \\ return error.TheSkyIsFalling;
238 \\ ^
189 \\source.zig:8:5: [address] in std.start.posixCallMainAndExit (test)239 \\source.zig:8:5: [address] in std.start.posixCallMainAndExit (test)
240 \\ return make_error();
241 \\ ^
190 \\source.zig:4:5: [address] in std.start.posixCallMainAndExit (test)242 \\source.zig:4:5: [address] in std.start.posixCallMainAndExit (test)
243 \\ try bar();
244 \\ ^
191 \\source.zig:16:5: [address] in std.start.posixCallMainAndExit (test)245 \\source.zig:16:5: [address] in std.start.posixCallMainAndExit (test)
246 \\ try foo();
247 \\ ^
192 \\248 \\
193 ,249 ,
194 // release-fast250 // release-fast
...@@ -209,11 +265,15 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -209,11 +265,15 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
209 // debug265 // debug
210 \\error: TheSkyIsFalling266 \\error: TheSkyIsFalling
211 \\source.zig:4:5: [address] in _main.0 (test.o)267 \\source.zig:4:5: [address] in _main.0 (test.o)
268 \\ return error.TheSkyIsFalling;
269 \\ ^
212 \\270 \\
213 ,271 ,
214 // release-safe272 // release-safe
215 \\error: TheSkyIsFalling273 \\error: TheSkyIsFalling
216 \\source.zig:4:5: [address] in _main (test.o)274 \\source.zig:4:5: [address] in _main (test.o)
275 \\ return error.TheSkyIsFalling;
276 \\ ^
217 \\277 \\
218 ,278 ,
219 // release-fast279 // release-fast
...@@ -232,13 +292,21 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -232,13 +292,21 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
232 // debug292 // debug
233 \\error: TheSkyIsFalling293 \\error: TheSkyIsFalling
234 \\source.zig:4:5: [address] in _foo (test.o)294 \\source.zig:4:5: [address] in _foo (test.o)
295 \\ return error.TheSkyIsFalling;
296 \\ ^
235 \\source.zig:8:5: [address] in _main.0 (test.o)297 \\source.zig:8:5: [address] in _main.0 (test.o)
298 \\ try foo();
299 \\ ^
236 \\300 \\
237 ,301 ,
238 // release-safe302 // release-safe
239 \\error: TheSkyIsFalling303 \\error: TheSkyIsFalling
240 \\source.zig:4:5: [address] in _main (test.o)304 \\source.zig:4:5: [address] in _main (test.o)
305 \\ return error.TheSkyIsFalling;
306 \\ ^
241 \\source.zig:8:5: [address] in _main (test.o)307 \\source.zig:8:5: [address] in _main (test.o)
308 \\ try foo();
309 \\ ^
242 \\310 \\
243 ,311 ,
244 // release-fast312 // release-fast
...@@ -257,17 +325,33 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -257,17 +325,33 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
257 // debug325 // debug
258 \\error: TheSkyIsFalling326 \\error: TheSkyIsFalling
259 \\source.zig:12:5: [address] in _make_error (test.o)327 \\source.zig:12:5: [address] in _make_error (test.o)
328 \\ return error.TheSkyIsFalling;
329 \\ ^
260 \\source.zig:8:5: [address] in _bar (test.o)330 \\source.zig:8:5: [address] in _bar (test.o)
331 \\ return make_error();
332 \\ ^
261 \\source.zig:4:5: [address] in _foo (test.o)333 \\source.zig:4:5: [address] in _foo (test.o)
334 \\ try bar();
335 \\ ^
262 \\source.zig:16:5: [address] in _main.0 (test.o)336 \\source.zig:16:5: [address] in _main.0 (test.o)
337 \\ try foo();
338 \\ ^
263 \\339 \\
264 ,340 ,
265 // release-safe341 // release-safe
266 \\error: TheSkyIsFalling342 \\error: TheSkyIsFalling
267 \\source.zig:12:5: [address] in _main (test.o)343 \\source.zig:12:5: [address] in _main (test.o)
344 \\ return error.TheSkyIsFalling;
345 \\ ^
268 \\source.zig:8:5: [address] in _main (test.o)346 \\source.zig:8:5: [address] in _main (test.o)
347 \\ return make_error();
348 \\ ^
269 \\source.zig:4:5: [address] in _main (test.o)349 \\source.zig:4:5: [address] in _main (test.o)
350 \\ try bar();
351 \\ ^
270 \\source.zig:16:5: [address] in _main (test.o)352 \\source.zig:16:5: [address] in _main (test.o)
353 \\ try foo();
354 \\ ^
271 \\355 \\
272 ,356 ,
273 // release-fast357 // release-fast
...@@ -288,6 +372,8 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -288,6 +372,8 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
288 // debug372 // debug
289 \\error: TheSkyIsFalling373 \\error: TheSkyIsFalling
290 \\source.zig:4:5: [address] in main (test.obj)374 \\source.zig:4:5: [address] in main (test.obj)
375 \\ return error.TheSkyIsFalling;
376 \\ ^
291 \\377 \\
292 ,378 ,
293 // release-safe379 // release-safe
...@@ -309,7 +395,11 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -309,7 +395,11 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
309 // debug395 // debug
310 \\error: TheSkyIsFalling396 \\error: TheSkyIsFalling
311 \\source.zig:4:5: [address] in foo (test.obj)397 \\source.zig:4:5: [address] in foo (test.obj)
398 \\ return error.TheSkyIsFalling;
399 \\ ^
312 \\source.zig:8:5: [address] in main (test.obj)400 \\source.zig:8:5: [address] in main (test.obj)
401 \\ try foo();
402 \\ ^
313 \\403 \\
314 ,404 ,
315 // release-safe405 // release-safe
...@@ -331,9 +421,17 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -331,9 +421,17 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
331 // debug421 // debug
332 \\error: TheSkyIsFalling422 \\error: TheSkyIsFalling
333 \\source.zig:12:5: [address] in make_error (test.obj)423 \\source.zig:12:5: [address] in make_error (test.obj)
424 \\ return error.TheSkyIsFalling;
425 \\ ^
334 \\source.zig:8:5: [address] in bar (test.obj)426 \\source.zig:8:5: [address] in bar (test.obj)
427 \\ return make_error();
428 \\ ^
335 \\source.zig:4:5: [address] in foo (test.obj)429 \\source.zig:4:5: [address] in foo (test.obj)
430 \\ try bar();
431 \\ ^
336 \\source.zig:16:5: [address] in main (test.obj)432 \\source.zig:16:5: [address] in main (test.obj)
433 \\ try foo();
434 \\ ^
337 \\435 \\
338 ,436 ,
339 // release-safe437 // release-safe
test/translate_c.zig+37
...@@ -3,6 +3,31 @@ const builtin = @import("builtin");...@@ -3,6 +3,31 @@ const builtin = @import("builtin");
3const Target = @import("std").Target;3const Target = @import("std").Target;
44
5pub fn addCases(cases: *tests.TranslateCContext) void {5pub 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
6 cases.add("empty declaration",31 cases.add("empty declaration",
7 \\;32 \\;
8 , &[_][]const u8{""});33 , &[_][]const u8{""});
...@@ -2606,4 +2631,16 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2606,4 +2631,16 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2606 \\ return foo((@intCast(c_int, @bitCast(i1, @intCast(u1, @boolToInt(c)))) != @intCast(c_int, @bitCast(i1, @intCast(u1, @boolToInt(b))))));2631 \\ return foo((@intCast(c_int, @bitCast(i1, @intCast(u1, @boolToInt(c)))) != @intCast(c_int, @bitCast(i1, @intCast(u1, @boolToInt(b))))));
2607 \\}2632 \\}
2608 });2633 });
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
2609}2646}