| author | |
| committer | |
| log | e315120b79f98163dd6413e62684d6ad148295ee |
| tree | abc748fa6b802d4007741ba1ef0fbf1fef1ef152 |
| parent | 693dbeeef2a35737cec893b50a4fed11b248dd6a |
5 files changed, 401 insertions(+), 120 deletions(-)
lib/std/zig/render.zig-1| ... | ... | @@ -1590,7 +1590,6 @@ fn renderStructInit( |
| 1590 | 1590 | return renderToken(ais, tree, rbrace, space); |
| 1591 | 1591 | } |
| 1592 | 1592 | |
| 1593 | // TODO: handle comments between elements | |
| 1594 | 1593 | fn renderArrayInit( |
| 1595 | 1594 | gpa: *Allocator, |
| 1596 | 1595 | ais: *Ais, |
src/AstGen.zig+218-28| ... | ... | @@ -822,15 +822,20 @@ pub fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) Inn |
| 822 | 822 | .@"errdefer" => return astgen.failNode(node, "TODO implement astgen.expr for .errdefer", .{}), |
| 823 | 823 | .@"try" => return astgen.failNode(node, "TODO implement astgen.expr for .Try", .{}), |
| 824 | 824 | |
| 825 | .array_init_one, | |
| 826 | .array_init_one_comma, | |
| 827 | .array_init_dot_two, | |
| 828 | .array_init_dot_two_comma, | |
| 825 | .array_init_one, .array_init_one_comma => { | |
| 826 | var elements: [1]ast.Node.Index = undefined; | |
| 827 | return arrayInitExpr(gz, scope, rl, node, tree.arrayInitOne(&elements, node)); | |
| 828 | }, | |
| 829 | .array_init_dot_two, .array_init_dot_two_comma => { | |
| 830 | var elements: [2]ast.Node.Index = undefined; | |
| 831 | return arrayInitExpr(gz, scope, rl, node, tree.arrayInitDotTwo(&elements, node)); | |
| 832 | }, | |
| 829 | 833 | .array_init_dot, |
| 830 | 834 | .array_init_dot_comma, |
| 835 | => return arrayInitExpr(gz, scope, rl, node, tree.arrayInitDot(node)), | |
| 831 | 836 | .array_init, |
| 832 | 837 | .array_init_comma, |
| 833 | => return astgen.failNode(node, "TODO implement astgen.expr for array literals", .{}), | |
| 838 | => return arrayInitExpr(gz, scope, rl, node, tree.arrayInit(node)), | |
| 834 | 839 | |
| 835 | 840 | .struct_init_one, .struct_init_one_comma => { |
| 836 | 841 | var fields: [1]ast.Node.Index = undefined; |
| ... | ... | @@ -856,6 +861,182 @@ pub fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) Inn |
| 856 | 861 | } |
| 857 | 862 | } |
| 858 | 863 | |
| 864 | pub fn arrayInitExpr( | |
| 865 | gz: *GenZir, | |
| 866 | scope: *Scope, | |
| 867 | rl: ResultLoc, | |
| 868 | node: ast.Node.Index, | |
| 869 | array_init: ast.full.ArrayInit, | |
| 870 | ) InnerError!Zir.Inst.Ref { | |
| 871 | const astgen = gz.astgen; | |
| 872 | const tree = &astgen.file.tree; | |
| 873 | const gpa = astgen.gpa; | |
| 874 | const node_tags = tree.nodes.items(.tag); | |
| 875 | const main_tokens = tree.nodes.items(.main_token); | |
| 876 | ||
| 877 | assert(array_init.ast.elements.len != 0); // Otherwise it would be struct init. | |
| 878 | ||
| 879 | const types: struct { | |
| 880 | array: Zir.Inst.Ref, | |
| 881 | elem: Zir.Inst.Ref, | |
| 882 | } = inst: { | |
| 883 | if (array_init.ast.type_expr == 0) break :inst .{ | |
| 884 | .array = .none, | |
| 885 | .elem = .none, | |
| 886 | }; | |
| 887 | ||
| 888 | infer: { | |
| 889 | const array_type: ast.full.ArrayType = switch (node_tags[array_init.ast.type_expr]) { | |
| 890 | .array_type => tree.arrayType(array_init.ast.type_expr), | |
| 891 | .array_type_sentinel => tree.arrayTypeSentinel(array_init.ast.type_expr), | |
| 892 | else => break :infer, | |
| 893 | }; | |
| 894 | // This intentionally does not support `@"_"` syntax. | |
| 895 | if (node_tags[array_type.ast.elem_count] == .identifier and | |
| 896 | mem.eql(u8, tree.tokenSlice(main_tokens[array_type.ast.elem_count]), "_")) | |
| 897 | { | |
| 898 | const tag: Zir.Inst.Tag = switch (node_tags[array_init.ast.type_expr]) { | |
| 899 | .array_type => .array_type, | |
| 900 | .array_type_sentinel => .array_type_sentinel, | |
| 901 | else => unreachable, | |
| 902 | }; | |
| 903 | const len_inst = try gz.addInt(array_init.ast.elements.len); | |
| 904 | const elem_type = try typeExpr(gz, scope, array_type.ast.elem_type); | |
| 905 | const array_type_inst = try gz.addBin(tag, len_inst, elem_type); | |
| 906 | break :inst .{ | |
| 907 | .array = array_type_inst, | |
| 908 | .elem = elem_type, | |
| 909 | }; | |
| 910 | } | |
| 911 | } | |
| 912 | const array_type_inst = try typeExpr(gz, scope, array_init.ast.type_expr); | |
| 913 | const elem_type = try gz.addUnNode(.elem_type, array_type_inst, array_init.ast.type_expr); | |
| 914 | break :inst .{ | |
| 915 | .array = array_type_inst, | |
| 916 | .elem = elem_type, | |
| 917 | }; | |
| 918 | }; | |
| 919 | ||
| 920 | switch (rl) { | |
| 921 | .discard => { | |
| 922 | for (array_init.ast.elements) |elem_init| { | |
| 923 | _ = try expr(gz, scope, .discard, elem_init); | |
| 924 | } | |
| 925 | return Zir.Inst.Ref.void_value; | |
| 926 | }, | |
| 927 | .ref => { | |
| 928 | if (types.array != .none) { | |
| 929 | return arrayInitExprRlTy(gz, scope, rl, node, array_init.ast.elements, types.array, types.elem, .array_init_ref); | |
| 930 | } else { | |
| 931 | return arrayInitExprRlNone(gz, scope, rl, node, array_init.ast.elements, .array_init_anon_ref); | |
| 932 | } | |
| 933 | }, | |
| 934 | .none, .none_or_ref => { | |
| 935 | if (types.array != .none) { | |
| 936 | return arrayInitExprRlTy(gz, scope, rl, node, array_init.ast.elements, types.array, types.elem, .array_init); | |
| 937 | } else { | |
| 938 | return arrayInitExprRlNone(gz, scope, rl, node, array_init.ast.elements, .array_init_anon); | |
| 939 | } | |
| 940 | }, | |
| 941 | .ty => |ty_inst| { | |
| 942 | if (types.array != .none) { | |
| 943 | const result = try arrayInitExprRlTy(gz, scope, rl, node, array_init.ast.elements, types.array, types.elem, .array_init); | |
| 944 | return rvalue(gz, scope, rl, result, node); | |
| 945 | } else { | |
| 946 | const elem_type = try gz.addUnNode(.elem_type, ty_inst, node); | |
| 947 | return arrayInitExprRlTy(gz, scope, rl, node, array_init.ast.elements, ty_inst, elem_type, .array_init); | |
| 948 | } | |
| 949 | }, | |
| 950 | .ptr, .inferred_ptr => |ptr_inst| { | |
| 951 | return arrayInitExprRlPtr(gz, scope, rl, node, array_init.ast.elements, ptr_inst); | |
| 952 | }, | |
| 953 | .block_ptr => |block_gz| { | |
| 954 | return arrayInitExprRlPtr(gz, scope, rl, node, array_init.ast.elements, block_gz.rl_ptr); | |
| 955 | }, | |
| 956 | } | |
| 957 | } | |
| 958 | ||
| 959 | pub fn arrayInitExprRlNone( | |
| 960 | gz: *GenZir, | |
| 961 | scope: *Scope, | |
| 962 | rl: ResultLoc, | |
| 963 | node: ast.Node.Index, | |
| 964 | elements: []const ast.Node.Index, | |
| 965 | tag: Zir.Inst.Tag, | |
| 966 | ) InnerError!Zir.Inst.Ref { | |
| 967 | const astgen = gz.astgen; | |
| 968 | const gpa = astgen.gpa; | |
| 969 | const elem_list = try gpa.alloc(Zir.Inst.Ref, elements.len); | |
| 970 | defer gpa.free(elem_list); | |
| 971 | ||
| 972 | for (elements) |elem_init, i| { | |
| 973 | elem_list[i] = try expr(gz, scope, .none, elem_init); | |
| 974 | } | |
| 975 | const init_inst = try gz.addPlNode(tag, node, Zir.Inst.MultiOp{ | |
| 976 | .operands_len = @intCast(u32, elem_list.len), | |
| 977 | }); | |
| 978 | try astgen.appendRefs(elem_list); | |
| 979 | return init_inst; | |
| 980 | } | |
| 981 | ||
| 982 | pub fn arrayInitExprRlTy( | |
| 983 | gz: *GenZir, | |
| 984 | scope: *Scope, | |
| 985 | rl: ResultLoc, | |
| 986 | node: ast.Node.Index, | |
| 987 | elements: []const ast.Node.Index, | |
| 988 | array_ty_inst: Zir.Inst.Ref, | |
| 989 | elem_ty_inst: Zir.Inst.Ref, | |
| 990 | tag: Zir.Inst.Tag, | |
| 991 | ) InnerError!Zir.Inst.Ref { | |
| 992 | const astgen = gz.astgen; | |
| 993 | const gpa = astgen.gpa; | |
| 994 | ||
| 995 | const elem_list = try gpa.alloc(Zir.Inst.Ref, elements.len); | |
| 996 | defer gpa.free(elem_list); | |
| 997 | ||
| 998 | const elem_rl: ResultLoc = .{ .ty = elem_ty_inst }; | |
| 999 | ||
| 1000 | for (elements) |elem_init, i| { | |
| 1001 | elem_list[i] = try expr(gz, scope, elem_rl, elem_init); | |
| 1002 | } | |
| 1003 | const init_inst = try gz.addPlNode(tag, node, Zir.Inst.MultiOp{ | |
| 1004 | .operands_len = @intCast(u32, elem_list.len), | |
| 1005 | }); | |
| 1006 | try astgen.appendRefs(elem_list); | |
| 1007 | return init_inst; | |
| 1008 | } | |
| 1009 | ||
| 1010 | pub fn arrayInitExprRlPtr( | |
| 1011 | gz: *GenZir, | |
| 1012 | scope: *Scope, | |
| 1013 | rl: ResultLoc, | |
| 1014 | node: ast.Node.Index, | |
| 1015 | elements: []const ast.Node.Index, | |
| 1016 | result_ptr: Zir.Inst.Ref, | |
| 1017 | ) InnerError!Zir.Inst.Ref { | |
| 1018 | const astgen = gz.astgen; | |
| 1019 | const gpa = astgen.gpa; | |
| 1020 | ||
| 1021 | const elem_ptr_list = try gpa.alloc(Zir.Inst.Index, elements.len); | |
| 1022 | defer gpa.free(elem_ptr_list); | |
| 1023 | ||
| 1024 | for (elements) |elem_init, i| { | |
| 1025 | const index_inst = try gz.addInt(i); | |
| 1026 | const elem_ptr = try gz.addPlNode(.elem_ptr_node, elem_init, Zir.Inst.Bin{ | |
| 1027 | .lhs = result_ptr, | |
| 1028 | .rhs = index_inst, | |
| 1029 | }); | |
| 1030 | elem_ptr_list[i] = gz.refToIndex(elem_ptr).?; | |
| 1031 | _ = try expr(gz, scope, .{ .ptr = elem_ptr }, elem_init); | |
| 1032 | } | |
| 1033 | _ = try gz.addPlNode(.validate_array_init_ptr, node, Zir.Inst.Block{ | |
| 1034 | .body_len = @intCast(u32, elem_ptr_list.len), | |
| 1035 | }); | |
| 1036 | try astgen.extra.appendSlice(gpa, elem_ptr_list); | |
| 1037 | return .void_value; | |
| 1038 | } | |
| 1039 | ||
| 859 | 1040 | pub fn structInitExpr( |
| 860 | 1041 | gz: *GenZir, |
| 861 | 1042 | scope: *Scope, |
| ... | ... | @@ -911,7 +1092,14 @@ pub fn structInitExpr( |
| 911 | 1092 | return init_inst; |
| 912 | 1093 | }, |
| 913 | 1094 | .ref => unreachable, // struct literal not valid as l-value |
| 914 | .ty => |ty_inst| return structInitExprRlTy(gz, scope, rl, node, struct_init, ty_inst), | |
| 1095 | .ty => |ty_inst| { | |
| 1096 | if (struct_init.ast.type_expr == 0) { | |
| 1097 | return structInitExprRlTy(gz, scope, rl, node, struct_init, ty_inst); | |
| 1098 | } | |
| 1099 | const inner_ty_inst = try typeExpr(gz, scope, struct_init.ast.type_expr); | |
| 1100 | const result = try structInitExprRlTy(gz, scope, rl, node, struct_init, inner_ty_inst); | |
| 1101 | return rvalue(gz, scope, rl, result, node); | |
| 1102 | }, | |
| 915 | 1103 | .ptr, .inferred_ptr => |ptr_inst| return structInitExprRlPtr(gz, scope, rl, node, struct_init, ptr_inst), |
| 916 | 1104 | .block_ptr => |block_gz| return structInitExprRlPtr(gz, scope, rl, node, struct_init, block_gz.rl_ptr), |
| 917 | 1105 | } |
| ... | ... | @@ -942,11 +1130,11 @@ pub fn structInitExprRlPtr( |
| 942 | 1130 | field_ptr_list[i] = gz.refToIndex(field_ptr).?; |
| 943 | 1131 | _ = try expr(gz, scope, .{ .ptr = field_ptr }, field_init); |
| 944 | 1132 | } |
| 945 | const validate_inst = try gz.addPlNode(.validate_struct_init_ptr, node, Zir.Inst.Block{ | |
| 1133 | _ = try gz.addPlNode(.validate_struct_init_ptr, node, Zir.Inst.Block{ | |
| 946 | 1134 | .body_len = @intCast(u32, field_ptr_list.len), |
| 947 | 1135 | }); |
| 948 | 1136 | try astgen.extra.appendSlice(gpa, field_ptr_list); |
| 949 | return validate_inst; | |
| 1137 | return .void_value; | |
| 950 | 1138 | } |
| 951 | 1139 | |
| 952 | 1140 | pub fn structInitExprRlTy( |
| ... | ... | @@ -1336,6 +1524,7 @@ fn blockExprStmts( |
| 1336 | 1524 | .array_mul, |
| 1337 | 1525 | .array_type, |
| 1338 | 1526 | .array_type_sentinel, |
| 1527 | .elem_type, | |
| 1339 | 1528 | .indexable_ptr_len, |
| 1340 | 1529 | .as, |
| 1341 | 1530 | .as_node, |
| ... | ... | @@ -1393,8 +1582,6 @@ fn blockExprStmts( |
| 1393 | 1582 | .param_type, |
| 1394 | 1583 | .ptrtoint, |
| 1395 | 1584 | .ref, |
| 1396 | .ret_ptr, | |
| 1397 | .ret_type, | |
| 1398 | 1585 | .shl, |
| 1399 | 1586 | .shr, |
| 1400 | 1587 | .str, |
| ... | ... | @@ -1453,6 +1640,10 @@ fn blockExprStmts( |
| 1453 | 1640 | .struct_init_empty, |
| 1454 | 1641 | .struct_init, |
| 1455 | 1642 | .struct_init_anon, |
| 1643 | .array_init, | |
| 1644 | .array_init_anon, | |
| 1645 | .array_init_ref, | |
| 1646 | .array_init_anon_ref, | |
| 1456 | 1647 | .union_init_ptr, |
| 1457 | 1648 | .field_type, |
| 1458 | 1649 | .field_type_ref, |
| ... | ... | @@ -1469,18 +1660,12 @@ fn blockExprStmts( |
| 1469 | 1660 | .type_info, |
| 1470 | 1661 | .size_of, |
| 1471 | 1662 | .bit_size_of, |
| 1472 | .this, | |
| 1473 | .ret_addr, | |
| 1474 | .builtin_src, | |
| 1475 | 1663 | .add_with_overflow, |
| 1476 | 1664 | .sub_with_overflow, |
| 1477 | 1665 | .mul_with_overflow, |
| 1478 | 1666 | .shl_with_overflow, |
| 1479 | 1667 | .log2_int_type, |
| 1480 | 1668 | .typeof_log2_int_type, |
| 1481 | .error_return_trace, | |
| 1482 | .frame, | |
| 1483 | .frame_address, | |
| 1484 | 1669 | .ptr_to_int, |
| 1485 | 1670 | .align_of, |
| 1486 | 1671 | .bool_to_int, |
| ... | ... | @@ -1575,6 +1760,7 @@ fn blockExprStmts( |
| 1575 | 1760 | .repeat, |
| 1576 | 1761 | .repeat_inline, |
| 1577 | 1762 | .validate_struct_init_ptr, |
| 1763 | .validate_array_init_ptr, | |
| 1578 | 1764 | .panic, |
| 1579 | 1765 | .set_align_stack, |
| 1580 | 1766 | .set_cold, |
| ... | ... | @@ -2572,13 +2758,17 @@ fn structDeclInner( |
| 2572 | 2758 | |
| 2573 | 2759 | field_index += 1; |
| 2574 | 2760 | } |
| 2575 | if (field_index != 0) { | |
| 2761 | { | |
| 2576 | 2762 | const empty_slot_count = 16 - (field_index % 16); |
| 2577 | cur_bit_bag >>= @intCast(u5, empty_slot_count * 2); | |
| 2763 | if (empty_slot_count < 16) { | |
| 2764 | cur_bit_bag >>= @intCast(u5, empty_slot_count * 2); | |
| 2765 | } | |
| 2578 | 2766 | } |
| 2579 | if (wip_decls.decl_index != 0) { | |
| 2767 | { | |
| 2580 | 2768 | const empty_slot_count = 16 - (wip_decls.decl_index % 16); |
| 2581 | wip_decls.cur_bit_bag >>= @intCast(u5, empty_slot_count * 2); | |
| 2769 | if (empty_slot_count < 16) { | |
| 2770 | wip_decls.cur_bit_bag >>= @intCast(u5, empty_slot_count * 2); | |
| 2771 | } | |
| 2582 | 2772 | } |
| 2583 | 2773 | |
| 2584 | 2774 | const decl_inst = try gz.addBlock(tag, node); |
| ... | ... | @@ -4609,9 +4799,9 @@ fn ret(gz: *GenZir, scope: *Scope, node: ast.Node.Index) InnerError!Zir.Inst.Ref |
| 4609 | 4799 | const operand_node = node_datas[node].lhs; |
| 4610 | 4800 | const operand: Zir.Inst.Ref = if (operand_node != 0) operand: { |
| 4611 | 4801 | const rl: ResultLoc = if (nodeMayNeedMemoryLocation(tree, operand_node)) .{ |
| 4612 | .ptr = try gz.addNode(.ret_ptr, node), | |
| 4802 | .ptr = try gz.addNodeExtended(.ret_ptr, node), | |
| 4613 | 4803 | } else .{ |
| 4614 | .ty = try gz.addNode(.ret_type, node), | |
| 4804 | .ty = try gz.addNodeExtended(.ret_type, node), | |
| 4615 | 4805 | }; |
| 4616 | 4806 | break :operand try expr(gz, scope, rl, operand_node); |
| 4617 | 4807 | } else .void_value; |
| ... | ... | @@ -5203,12 +5393,12 @@ fn builtinCall( |
| 5203 | 5393 | .breakpoint => return simpleNoOpVoid(gz, scope, rl, node, .breakpoint), |
| 5204 | 5394 | .fence => return simpleNoOpVoid(gz, scope, rl, node, .fence), |
| 5205 | 5395 | |
| 5206 | .This => return rvalue(gz, scope, rl, try gz.addNode(.this, node), node), | |
| 5207 | .return_address => return rvalue(gz, scope, rl, try gz.addNode(.ret_addr, node), node), | |
| 5208 | .src => return rvalue(gz, scope, rl, try gz.addNode(.builtin_src, node), node), | |
| 5209 | .error_return_trace => return rvalue(gz, scope, rl, try gz.addNode(.error_return_trace, node), node), | |
| 5210 | .frame => return rvalue(gz, scope, rl, try gz.addNode(.frame, node), node), | |
| 5211 | .frame_address => return rvalue(gz, scope, rl, try gz.addNode(.frame_address, node), node), | |
| 5396 | .This => return rvalue(gz, scope, rl, try gz.addNodeExtended(.this, node), node), | |
| 5397 | .return_address => return rvalue(gz, scope, rl, try gz.addNodeExtended(.ret_addr, node), node), | |
| 5398 | .src => return rvalue(gz, scope, rl, try gz.addNodeExtended(.builtin_src, node), node), | |
| 5399 | .error_return_trace => return rvalue(gz, scope, rl, try gz.addNodeExtended(.error_return_trace, node), node), | |
| 5400 | .frame => return rvalue(gz, scope, rl, try gz.addNodeExtended(.frame, node), node), | |
| 5401 | .frame_address => return rvalue(gz, scope, rl, try gz.addNodeExtended(.frame_address, node), node), | |
| 5212 | 5402 | |
| 5213 | 5403 | .type_info => return simpleUnOpType(gz, scope, rl, node, params[0], .type_info), |
| 5214 | 5404 | .size_of => return simpleUnOpType(gz, scope, rl, node, params[0], .size_of), |
src/Module.zig+17| ... | ... | @@ -1622,6 +1622,22 @@ pub const Scope = struct { |
| 1622 | 1622 | }); |
| 1623 | 1623 | } |
| 1624 | 1624 | |
| 1625 | pub fn addNodeExtended( | |
| 1626 | gz: *GenZir, | |
| 1627 | opcode: Zir.Inst.Extended, | |
| 1628 | /// Absolute node index. This function does the conversion to offset from Decl. | |
| 1629 | src_node: ast.Node.Index, | |
| 1630 | ) !Zir.Inst.Ref { | |
| 1631 | return gz.add(.{ | |
| 1632 | .tag = .extended, | |
| 1633 | .data = .{ .extended = .{ | |
| 1634 | .opcode = opcode, | |
| 1635 | .small = undefined, | |
| 1636 | .operand = @bitCast(u32, gz.nodeIndexToRelative(src_node)), | |
| 1637 | } }, | |
| 1638 | }); | |
| 1639 | } | |
| 1640 | ||
| 1625 | 1641 | /// Asserts that `str` is 8 or fewer bytes. |
| 1626 | 1642 | pub fn addSmallStr( |
| 1627 | 1643 | gz: *GenZir, |
| ... | ... | @@ -2583,6 +2599,7 @@ pub fn astGenFile(mod: *Module, file: *Scope.File, prog_node: *std.Progress.Node |
| 2583 | 2599 | return error.AnalysisFail; |
| 2584 | 2600 | } |
| 2585 | 2601 | |
| 2602 | log.debug("AstGen success: {s}", .{file.sub_file_path}); | |
| 2586 | 2603 | file.status = .success; |
| 2587 | 2604 | } |
| 2588 | 2605 |
src/Sema.zig+105-50| ... | ... | @@ -175,6 +175,7 @@ pub fn analyzeBody( |
| 175 | 175 | .elem_ptr_node => try sema.zirElemPtrNode(block, inst), |
| 176 | 176 | .elem_val => try sema.zirElemVal(block, inst), |
| 177 | 177 | .elem_val_node => try sema.zirElemValNode(block, inst), |
| 178 | .elem_type => try sema.zirElemType(block, inst), | |
| 178 | 179 | .enum_literal => try sema.zirEnumLiteral(block, inst), |
| 179 | 180 | .enum_literal_small => try sema.zirEnumLiteralSmall(block, inst), |
| 180 | 181 | .enum_to_int => try sema.zirEnumToInt(block, inst), |
| ... | ... | @@ -223,8 +224,6 @@ pub fn analyzeBody( |
| 223 | 224 | .ptr_type_simple => try sema.zirPtrTypeSimple(block, inst), |
| 224 | 225 | .ptrtoint => try sema.zirPtrtoint(block, inst), |
| 225 | 226 | .ref => try sema.zirRef(block, inst), |
| 226 | .ret_ptr => try sema.zirRetPtr(block, inst), | |
| 227 | .ret_type => try sema.zirRetType(block, inst), | |
| 228 | 227 | .shl => try sema.zirShl(block, inst), |
| 229 | 228 | .shr => try sema.zirShr(block, inst), |
| 230 | 229 | .slice_end => try sema.zirSliceEnd(block, inst), |
| ... | ... | @@ -252,9 +251,6 @@ pub fn analyzeBody( |
| 252 | 251 | .type_info => try sema.zirTypeInfo(block, inst), |
| 253 | 252 | .size_of => try sema.zirSizeOf(block, inst), |
| 254 | 253 | .bit_size_of => try sema.zirBitSizeOf(block, inst), |
| 255 | .this => try sema.zirThis(block, inst), | |
| 256 | .ret_addr => try sema.zirRetAddr(block, inst), | |
| 257 | .builtin_src => try sema.zirBuiltinSrc(block, inst), | |
| 258 | 254 | .typeof => try sema.zirTypeof(block, inst), |
| 259 | 255 | .typeof_elem => try sema.zirTypeofElem(block, inst), |
| 260 | 256 | .typeof_peer => try sema.zirTypeofPeer(block, inst), |
| ... | ... | @@ -264,12 +260,13 @@ pub fn analyzeBody( |
| 264 | 260 | .struct_init_empty => try sema.zirStructInitEmpty(block, inst), |
| 265 | 261 | .struct_init => try sema.zirStructInit(block, inst), |
| 266 | 262 | .struct_init_anon => try sema.zirStructInitAnon(block, inst), |
| 263 | .array_init => try sema.zirArrayInit(block, inst, false), | |
| 264 | .array_init_anon => try sema.zirArrayInitAnon(block, inst, false), | |
| 265 | .array_init_ref => try sema.zirArrayInit(block, inst, true), | |
| 266 | .array_init_anon_ref => try sema.zirArrayInitAnon(block, inst, true), | |
| 267 | 267 | .union_init_ptr => try sema.zirUnionInitPtr(block, inst), |
| 268 | 268 | .field_type => try sema.zirFieldType(block, inst), |
| 269 | 269 | .field_type_ref => try sema.zirFieldTypeRef(block, inst), |
| 270 | .error_return_trace => try sema.zirErrorReturnTrace(block, inst), | |
| 271 | .frame => try sema.zirFrame(block, inst), | |
| 272 | .frame_address => try sema.zirFrameAddress(block, inst), | |
| 273 | 270 | .ptr_to_int => try sema.zirPtrToInt(block, inst), |
| 274 | 271 | .align_of => try sema.zirAlignOf(block, inst), |
| 275 | 272 | .bool_to_int => try sema.zirBoolToInt(block, inst), |
| ... | ... | @@ -435,6 +432,10 @@ pub fn analyzeBody( |
| 435 | 432 | try sema.zirValidateStructInitPtr(block, inst); |
| 436 | 433 | continue; |
| 437 | 434 | }, |
| 435 | .validate_array_init_ptr => { | |
| 436 | try sema.zirValidateArrayInitPtr(block, inst); | |
| 437 | continue; | |
| 438 | }, | |
| 438 | 439 | .@"export" => { |
| 439 | 440 | try sema.zirExport(block, inst); |
| 440 | 441 | continue; |
| ... | ... | @@ -499,6 +500,28 @@ pub fn analyzeBody( |
| 499 | 500 | } |
| 500 | 501 | } |
| 501 | 502 | |
| 503 | fn zirExtended(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst { | |
| 504 | const extended = sema.code.instructions.items(.data)[inst].extended; | |
| 505 | switch (extended.opcode) { | |
| 506 | // zig fmt: off | |
| 507 | .func => return sema.zirFuncExtended( block, extended), | |
| 508 | .ret_ptr => return sema.zirRetPtr( block, extended), | |
| 509 | .ret_type => return sema.zirRetType( block, extended), | |
| 510 | .this => return sema.zirThis( block, extended), | |
| 511 | .ret_addr => return sema.zirRetAddr( block, extended), | |
| 512 | .builtin_src => return sema.zirBuiltinSrc( block, extended), | |
| 513 | .error_return_trace => return sema.zirErrorReturnTrace(block, extended), | |
| 514 | .frame => return sema.zirFrame( block, extended), | |
| 515 | .frame_address => return sema.zirFrameAddress( block, extended), | |
| 516 | .c_undef => return sema.zirCUndef( block, extended), | |
| 517 | .c_include => return sema.zirCInclude( block, extended), | |
| 518 | .c_define => return sema.zirCDefine( block, extended), | |
| 519 | .wasm_memory_size => return sema.zirWasmMemorySize( block, extended), | |
| 520 | .wasm_memory_grow => return sema.zirWasmMemoryGrow( block, extended), | |
| 521 | // zig fmt: on | |
| 522 | } | |
| 523 | } | |
| 524 | ||
| 502 | 525 | /// TODO when we rework TZIR memory layout, this function will no longer have a possible error. |
| 503 | 526 | pub fn resolveInst(sema: *Sema, zir_ref: Zir.Inst.Ref) error{OutOfMemory}!*ir.Inst { |
| 504 | 527 | var i: usize = @enumToInt(zir_ref); |
| ... | ... | @@ -990,11 +1013,15 @@ fn zirErrorSetDecl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inner |
| 990 | 1013 | return sema.mod.fail(&block.base, sema.src, "TODO implement zirErrorSetDecl", .{}); |
| 991 | 1014 | } |
| 992 | 1015 | |
| 993 | fn zirRetPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst { | |
| 1016 | fn zirRetPtr( | |
| 1017 | sema: *Sema, | |
| 1018 | block: *Scope.Block, | |
| 1019 | extended: Zir.Inst.Extended.InstData, | |
| 1020 | ) InnerError!*Inst { | |
| 994 | 1021 | const tracy = trace(@src()); |
| 995 | 1022 | defer tracy.end(); |
| 996 | 1023 | |
| 997 | const src: LazySrcLoc = .unneeded; | |
| 1024 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; | |
| 998 | 1025 | try sema.requireFunctionBlock(block, src); |
| 999 | 1026 | const fn_ty = sema.func.?.owner_decl.typed_value.most_recent.typed_value.ty; |
| 1000 | 1027 | const ret_type = fn_ty.fnReturnType(); |
| ... | ... | @@ -1011,11 +1038,15 @@ fn zirRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*In |
| 1011 | 1038 | return sema.analyzeRef(block, inst_data.src(), operand); |
| 1012 | 1039 | } |
| 1013 | 1040 | |
| 1014 | fn zirRetType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst { | |
| 1041 | fn zirRetType( | |
| 1042 | sema: *Sema, | |
| 1043 | block: *Scope.Block, | |
| 1044 | extended: Zir.Inst.Extended.InstData, | |
| 1045 | ) InnerError!*Inst { | |
| 1015 | 1046 | const tracy = trace(@src()); |
| 1016 | 1047 | defer tracy.end(); |
| 1017 | 1048 | |
| 1018 | const src: LazySrcLoc = .unneeded; | |
| 1049 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; | |
| 1019 | 1050 | try sema.requireFunctionBlock(block, src); |
| 1020 | 1051 | const fn_ty = sema.func.?.owner_decl.typed_value.most_recent.typed_value.ty; |
| 1021 | 1052 | const ret_type = fn_ty.fnReturnType(); |
| ... | ... | @@ -1247,6 +1278,12 @@ fn zirValidateStructInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Ind |
| 1247 | 1278 | } |
| 1248 | 1279 | } |
| 1249 | 1280 | |
| 1281 | fn zirValidateArrayInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!void { | |
| 1282 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | |
| 1283 | const src = inst_data.src(); | |
| 1284 | return sema.mod.fail(&block.base, src, "TODO implement Sema.zirValidateArrayInitPtr", .{}); | |
| 1285 | } | |
| 1286 | ||
| 1250 | 1287 | fn failWithBadFieldAccess( |
| 1251 | 1288 | sema: *Sema, |
| 1252 | 1289 | block: *Scope.Block, |
| ... | ... | @@ -2064,6 +2101,14 @@ fn zirOptionalTypeFromPtrElem(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.I |
| 2064 | 2101 | return sema.mod.constType(sema.arena, inst_data.src(), opt_ty); |
| 2065 | 2102 | } |
| 2066 | 2103 | |
| 2104 | fn zirElemType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst { | |
| 2105 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | |
| 2106 | const src = inst_data.src(); | |
| 2107 | const array_type = try sema.resolveType(block, src, inst_data.operand); | |
| 2108 | const elem_type = array_type.elemType(); | |
| 2109 | return sema.mod.constType(sema.arena, src, elem_type); | |
| 2110 | } | |
| 2111 | ||
| 2067 | 2112 | fn zirArrayType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst { |
| 2068 | 2113 | const tracy = trace(@src()); |
| 2069 | 2114 | defer tracy.end(); |
| ... | ... | @@ -4512,21 +4557,30 @@ fn zirBitSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr |
| 4512 | 4557 | return sema.mod.constIntUnsigned(sema.arena, src, Type.initTag(.comptime_int), bit_size); |
| 4513 | 4558 | } |
| 4514 | 4559 | |
| 4515 | fn zirThis(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst { | |
| 4516 | const src_node = sema.code.instructions.items(.data)[inst].node; | |
| 4517 | const src: LazySrcLoc = .{ .node_offset = src_node }; | |
| 4560 | fn zirThis( | |
| 4561 | sema: *Sema, | |
| 4562 | block: *Scope.Block, | |
| 4563 | extended: Zir.Inst.Extended.InstData, | |
| 4564 | ) InnerError!*Inst { | |
| 4565 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; | |
| 4518 | 4566 | return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirThis", .{}); |
| 4519 | 4567 | } |
| 4520 | 4568 | |
| 4521 | fn zirRetAddr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst { | |
| 4522 | const src_node = sema.code.instructions.items(.data)[inst].node; | |
| 4523 | const src: LazySrcLoc = .{ .node_offset = src_node }; | |
| 4569 | fn zirRetAddr( | |
| 4570 | sema: *Sema, | |
| 4571 | block: *Scope.Block, | |
| 4572 | extended: Zir.Inst.Extended.InstData, | |
| 4573 | ) InnerError!*Inst { | |
| 4574 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; | |
| 4524 | 4575 | return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirRetAddr", .{}); |
| 4525 | 4576 | } |
| 4526 | 4577 | |
| 4527 | fn zirBuiltinSrc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst { | |
| 4528 | const src_node = sema.code.instructions.items(.data)[inst].node; | |
| 4529 | const src: LazySrcLoc = .{ .node_offset = src_node }; | |
| 4578 | fn zirBuiltinSrc( | |
| 4579 | sema: *Sema, | |
| 4580 | block: *Scope.Block, | |
| 4581 | extended: Zir.Inst.Extended.InstData, | |
| 4582 | ) InnerError!*Inst { | |
| 4583 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; | |
| 4530 | 4584 | return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirBuiltinSrc", .{}); |
| 4531 | 4585 | } |
| 4532 | 4586 | |
| ... | ... | @@ -4983,6 +5037,18 @@ fn zirStructInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inn |
| 4983 | 5037 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirStructInitAnon", .{}); |
| 4984 | 5038 | } |
| 4985 | 5039 | |
| 5040 | fn zirArrayInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) InnerError!*Inst { | |
| 5041 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | |
| 5042 | const src = inst_data.src(); | |
| 5043 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirArrayInit", .{}); | |
| 5044 | } | |
| 5045 | ||
| 5046 | fn zirArrayInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) InnerError!*Inst { | |
| 5047 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | |
| 5048 | const src = inst_data.src(); | |
| 5049 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirArrayInitAnon", .{}); | |
| 5050 | } | |
| 5051 | ||
| 4986 | 5052 | fn zirFieldTypeRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst { |
| 4987 | 5053 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 4988 | 5054 | const src = inst_data.src(); |
| ... | ... | @@ -4995,21 +5061,30 @@ fn zirFieldType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr |
| 4995 | 5061 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirFieldType", .{}); |
| 4996 | 5062 | } |
| 4997 | 5063 | |
| 4998 | fn zirErrorReturnTrace(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst { | |
| 4999 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | |
| 5000 | const src = inst_data.src(); | |
| 5064 | fn zirErrorReturnTrace( | |
| 5065 | sema: *Sema, | |
| 5066 | block: *Scope.Block, | |
| 5067 | extended: Zir.Inst.Extended.InstData, | |
| 5068 | ) InnerError!*Inst { | |
| 5069 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; | |
| 5001 | 5070 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirErrorReturnTrace", .{}); |
| 5002 | 5071 | } |
| 5003 | 5072 | |
| 5004 | fn zirFrame(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst { | |
| 5005 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | |
| 5006 | const src = inst_data.src(); | |
| 5073 | fn zirFrame( | |
| 5074 | sema: *Sema, | |
| 5075 | block: *Scope.Block, | |
| 5076 | extended: Zir.Inst.Extended.InstData, | |
| 5077 | ) InnerError!*Inst { | |
| 5078 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; | |
| 5007 | 5079 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrame", .{}); |
| 5008 | 5080 | } |
| 5009 | 5081 | |
| 5010 | fn zirFrameAddress(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst { | |
| 5011 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | |
| 5012 | const src = inst_data.src(); | |
| 5082 | fn zirFrameAddress( | |
| 5083 | sema: *Sema, | |
| 5084 | block: *Scope.Block, | |
| 5085 | extended: Zir.Inst.Extended.InstData, | |
| 5086 | ) InnerError!*Inst { | |
| 5087 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; | |
| 5013 | 5088 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrameAddress", .{}); |
| 5014 | 5089 | } |
| 5015 | 5090 | |
| ... | ... | @@ -5295,24 +5370,9 @@ fn zirBuiltinAsyncCall(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) I |
| 5295 | 5370 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirBuiltinAsyncCall", .{}); |
| 5296 | 5371 | } |
| 5297 | 5372 | |
| 5298 | fn zirExtended(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst { | |
| 5299 | const extended = sema.code.instructions.items(.data)[inst].extended; | |
| 5300 | switch (extended.opcode) { | |
| 5301 | // zig fmt: off | |
| 5302 | .func => return sema.zirFuncExtended( block, inst, extended), | |
| 5303 | .c_undef => return sema.zirCUndef( block, inst, extended), | |
| 5304 | .c_include => return sema.zirCInclude( block, inst, extended), | |
| 5305 | .c_define => return sema.zirCDefine( block, inst, extended), | |
| 5306 | .wasm_memory_size => return sema.zirWasmMemorySize(block, inst, extended), | |
| 5307 | .wasm_memory_grow => return sema.zirWasmMemoryGrow(block, inst, extended), | |
| 5308 | // zig fmt: on | |
| 5309 | } | |
| 5310 | } | |
| 5311 | ||
| 5312 | 5373 | fn zirFuncExtended( |
| 5313 | 5374 | sema: *Sema, |
| 5314 | 5375 | block: *Scope.Block, |
| 5315 | inst: Zir.Inst.Index, | |
| 5316 | 5376 | extended: Zir.Inst.Extended.InstData, |
| 5317 | 5377 | ) InnerError!*Inst { |
| 5318 | 5378 | const tracy = trace(@src()); |
| ... | ... | @@ -5364,7 +5424,6 @@ fn zirFuncExtended( |
| 5364 | 5424 | fn zirCUndef( |
| 5365 | 5425 | sema: *Sema, |
| 5366 | 5426 | block: *Scope.Block, |
| 5367 | inst: Zir.Inst.Index, | |
| 5368 | 5427 | extended: Zir.Inst.Extended.InstData, |
| 5369 | 5428 | ) InnerError!*Inst { |
| 5370 | 5429 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| ... | ... | @@ -5375,7 +5434,6 @@ fn zirCUndef( |
| 5375 | 5434 | fn zirCInclude( |
| 5376 | 5435 | sema: *Sema, |
| 5377 | 5436 | block: *Scope.Block, |
| 5378 | inst: Zir.Inst.Index, | |
| 5379 | 5437 | extended: Zir.Inst.Extended.InstData, |
| 5380 | 5438 | ) InnerError!*Inst { |
| 5381 | 5439 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| ... | ... | @@ -5386,7 +5444,6 @@ fn zirCInclude( |
| 5386 | 5444 | fn zirCDefine( |
| 5387 | 5445 | sema: *Sema, |
| 5388 | 5446 | block: *Scope.Block, |
| 5389 | inst: Zir.Inst.Index, | |
| 5390 | 5447 | extended: Zir.Inst.Extended.InstData, |
| 5391 | 5448 | ) InnerError!*Inst { |
| 5392 | 5449 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| ... | ... | @@ -5397,7 +5454,6 @@ fn zirCDefine( |
| 5397 | 5454 | fn zirWasmMemorySize( |
| 5398 | 5455 | sema: *Sema, |
| 5399 | 5456 | block: *Scope.Block, |
| 5400 | inst: Zir.Inst.Index, | |
| 5401 | 5457 | extended: Zir.Inst.Extended.InstData, |
| 5402 | 5458 | ) InnerError!*Inst { |
| 5403 | 5459 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| ... | ... | @@ -5408,7 +5464,6 @@ fn zirWasmMemorySize( |
| 5408 | 5464 | fn zirWasmMemoryGrow( |
| 5409 | 5465 | sema: *Sema, |
| 5410 | 5466 | block: *Scope.Block, |
| 5411 | inst: Zir.Inst.Index, | |
| 5412 | 5467 | extended: Zir.Inst.Extended.InstData, |
| 5413 | 5468 | ) InnerError!*Inst { |
| 5414 | 5469 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
src/Zir.zig+61-41| ... | ... | @@ -169,6 +169,9 @@ pub const Inst = struct { |
| 169 | 169 | /// `[N:S]T` syntax. No source location provided. |
| 170 | 170 | /// Uses the `array_type_sentinel` field. |
| 171 | 171 | array_type_sentinel, |
| 172 | /// Given an array type, returns the element type. | |
| 173 | /// Uses the `un_node` union field. | |
| 174 | elem_type, | |
| 172 | 175 | /// Given a pointer to an indexable object, returns the len property. This is |
| 173 | 176 | /// used by for loops. This instruction also emits a for-loop specific compile |
| 174 | 177 | /// error if the indexable object is not indexable. |
| ... | ... | @@ -457,12 +460,6 @@ pub const Inst = struct { |
| 457 | 460 | /// instruction. |
| 458 | 461 | /// Uses the `un_tok` union field. |
| 459 | 462 | ref, |
| 460 | /// Obtains a pointer to the return value. | |
| 461 | /// Uses the `node` union field. | |
| 462 | ret_ptr, | |
| 463 | /// Obtains the return type of the in-scope function. | |
| 464 | /// Uses the `node` union field. | |
| 465 | ret_type, | |
| 466 | 463 | /// Sends control flow back to the function's callee. |
| 467 | 464 | /// Includes an operand as the return value. |
| 468 | 465 | /// Includes an AST node source location. |
| ... | ... | @@ -674,6 +671,13 @@ pub const Inst = struct { |
| 674 | 671 | /// because it must use one of them to find out the struct type. |
| 675 | 672 | /// Uses the `pl_node` field. Payload is `Block`. |
| 676 | 673 | validate_struct_init_ptr, |
| 674 | /// Given a set of `elem_ptr_node` instructions, assumes they are all part of an | |
| 675 | /// array initialization expression, and emits a compile error if the number of | |
| 676 | /// elements does not match the array type. | |
| 677 | /// This instruction asserts that there is at least one elem_ptr_node instruction, | |
| 678 | /// because it must use one of them to find out the array type. | |
| 679 | /// Uses the `pl_node` field. Payload is `Block`. | |
| 680 | validate_array_init_ptr, | |
| 677 | 681 | /// A struct literal with a specified type, with no fields. |
| 678 | 682 | /// Uses the `un_node` field. |
| 679 | 683 | struct_init_empty, |
| ... | ... | @@ -690,6 +694,18 @@ pub const Inst = struct { |
| 690 | 694 | /// Struct initialization without a type. |
| 691 | 695 | /// Uses the `pl_node` field. Payload is `StructInitAnon`. |
| 692 | 696 | struct_init_anon, |
| 697 | /// Array initialization syntax. | |
| 698 | /// Uses the `pl_node` field. Payload is `MultiOp`. | |
| 699 | array_init, | |
| 700 | /// Anonymous array initialization syntax. | |
| 701 | /// Uses the `pl_node` field. Payload is `MultiOp`. | |
| 702 | array_init_anon, | |
| 703 | /// Array initialization syntax, make the result a pointer. | |
| 704 | /// Uses the `pl_node` field. Payload is `MultiOp`. | |
| 705 | array_init_ref, | |
| 706 | /// Anonymous array initialization syntax, make the result a pointer. | |
| 707 | /// Uses the `pl_node` field. Payload is `MultiOp`. | |
| 708 | array_init_anon_ref, | |
| 693 | 709 | /// Given a pointer to a union and a comptime known field name, activates that field |
| 694 | 710 | /// and returns a pointer to it. |
| 695 | 711 | /// Uses the `pl_node` field. Payload is `UnionInitPtr`. |
| ... | ... | @@ -700,14 +716,8 @@ pub const Inst = struct { |
| 700 | 716 | size_of, |
| 701 | 717 | /// Implements the `@bitSizeOf` builtin. Uses `un_node`. |
| 702 | 718 | bit_size_of, |
| 703 | /// Implements the `@This` builtin. Uses `node`. | |
| 704 | this, | |
| 705 | /// Implements the `@fence` builtin. Uses `un_node`. | |
| 719 | /// Implements the `@fence` builtin. Uses `node`. | |
| 706 | 720 | fence, |
| 707 | /// Implements the `@returnAddress` builtin. Uses `un_node`. | |
| 708 | ret_addr, | |
| 709 | /// Implements the `@src` builtin. Uses `un_node`. | |
| 710 | builtin_src, | |
| 711 | 721 | /// Implements the `@addWithOverflow` builtin. Uses `pl_node` with `OverflowArithmetic`. |
| 712 | 722 | add_with_overflow, |
| 713 | 723 | /// Implements the `@subWithOverflow` builtin. Uses `pl_node` with `OverflowArithmetic`. |
| ... | ... | @@ -717,16 +727,6 @@ pub const Inst = struct { |
| 717 | 727 | /// Implements the `@shlWithOverflow` builtin. Uses `pl_node` with `OverflowArithmetic`. |
| 718 | 728 | shl_with_overflow, |
| 719 | 729 | |
| 720 | /// Implements the `@errorReturnTrace` builtin. | |
| 721 | /// Uses the `un_node` field. | |
| 722 | error_return_trace, | |
| 723 | /// Implements the `@frame` builtin. | |
| 724 | /// Uses the `un_node` field. | |
| 725 | frame, | |
| 726 | /// Implements the `@frameAddress` builtin. | |
| 727 | /// Uses the `un_node` field. | |
| 728 | frame_address, | |
| 729 | ||
| 730 | 730 | /// Implement builtin `@ptrToInt`. Uses `un_node`. |
| 731 | 731 | ptr_to_int, |
| 732 | 732 | /// Implement builtin `@errToInt`. Uses `un_node`. |
| ... | ... | @@ -951,6 +951,7 @@ pub const Inst = struct { |
| 951 | 951 | .array_mul, |
| 952 | 952 | .array_type, |
| 953 | 953 | .array_type_sentinel, |
| 954 | .elem_type, | |
| 954 | 955 | .indexable_ptr_len, |
| 955 | 956 | .as, |
| 956 | 957 | .as_node, |
| ... | ... | @@ -970,6 +971,7 @@ pub const Inst = struct { |
| 970 | 971 | .bool_and, |
| 971 | 972 | .bool_or, |
| 972 | 973 | .breakpoint, |
| 974 | .fence, | |
| 973 | 975 | .call, |
| 974 | 976 | .call_chkused, |
| 975 | 977 | .call_compile_time, |
| ... | ... | @@ -1026,8 +1028,6 @@ pub const Inst = struct { |
| 1026 | 1028 | .param_type, |
| 1027 | 1029 | .ptrtoint, |
| 1028 | 1030 | .ref, |
| 1029 | .ret_ptr, | |
| 1030 | .ret_type, | |
| 1031 | 1031 | .shl, |
| 1032 | 1032 | .shr, |
| 1033 | 1033 | .store, |
| ... | ... | @@ -1094,9 +1094,14 @@ pub const Inst = struct { |
| 1094 | 1094 | .switch_block_ref_under, |
| 1095 | 1095 | .switch_block_ref_under_multi, |
| 1096 | 1096 | .validate_struct_init_ptr, |
| 1097 | .validate_array_init_ptr, | |
| 1097 | 1098 | .struct_init_empty, |
| 1098 | 1099 | .struct_init, |
| 1099 | 1100 | .struct_init_anon, |
| 1101 | .array_init, | |
| 1102 | .array_init_anon, | |
| 1103 | .array_init_ref, | |
| 1104 | .array_init_anon_ref, | |
| 1100 | 1105 | .union_init_ptr, |
| 1101 | 1106 | .field_type, |
| 1102 | 1107 | .field_type_ref, |
| ... | ... | @@ -1105,17 +1110,10 @@ pub const Inst = struct { |
| 1105 | 1110 | .type_info, |
| 1106 | 1111 | .size_of, |
| 1107 | 1112 | .bit_size_of, |
| 1108 | .this, | |
| 1109 | .fence, | |
| 1110 | .ret_addr, | |
| 1111 | .builtin_src, | |
| 1112 | 1113 | .add_with_overflow, |
| 1113 | 1114 | .sub_with_overflow, |
| 1114 | 1115 | .mul_with_overflow, |
| 1115 | 1116 | .shl_with_overflow, |
| 1116 | .error_return_trace, | |
| 1117 | .frame, | |
| 1118 | .frame_address, | |
| 1119 | 1117 | .ptr_to_int, |
| 1120 | 1118 | .align_of, |
| 1121 | 1119 | .bool_to_int, |
| ... | ... | @@ -1211,6 +1209,30 @@ pub const Inst = struct { |
| 1211 | 1209 | /// `operand` is payload index to `ExtendedFunc`. |
| 1212 | 1210 | /// `small` is `ExtendedFunc.Small`. |
| 1213 | 1211 | func, |
| 1212 | /// Obtains a pointer to the return value. | |
| 1213 | /// `operand` is `src_node: i32`. | |
| 1214 | ret_ptr, | |
| 1215 | /// Obtains the return type of the in-scope function. | |
| 1216 | /// `operand` is `src_node: i32`. | |
| 1217 | ret_type, | |
| 1218 | /// Implements the `@This` builtin. | |
| 1219 | /// `operand` is `src_node: i32`. | |
| 1220 | this, | |
| 1221 | /// Implements the `@returnAddress` builtin. | |
| 1222 | /// `operand` is `src_node: i32`. | |
| 1223 | ret_addr, | |
| 1224 | /// Implements the `@src` builtin. | |
| 1225 | /// `operand` is `src_node: i32`. | |
| 1226 | builtin_src, | |
| 1227 | /// Implements the `@errorReturnTrace` builtin. | |
| 1228 | /// `operand` is `src_node: i32`. | |
| 1229 | error_return_trace, | |
| 1230 | /// Implements the `@frame` builtin. | |
| 1231 | /// `operand` is `src_node: i32`. | |
| 1232 | frame, | |
| 1233 | /// Implements the `@frameAddress` builtin. | |
| 1234 | /// `operand` is `src_node: i32`. | |
| 1235 | frame_address, | |
| 1214 | 1236 | /// `operand` is payload index to `UnNode`. |
| 1215 | 1237 | c_undef, |
| 1216 | 1238 | /// `operand` is payload index to `UnNode`. |
| ... | ... | @@ -2281,6 +2303,7 @@ const Writer = struct { |
| 2281 | 2303 | .pop_count, |
| 2282 | 2304 | .byte_swap, |
| 2283 | 2305 | .bit_reverse, |
| 2306 | .elem_type, | |
| 2284 | 2307 | => try self.writeUnNode(stream, inst), |
| 2285 | 2308 | |
| 2286 | 2309 | .ref, |
| ... | ... | @@ -2317,6 +2340,10 @@ const Writer = struct { |
| 2317 | 2340 | .union_decl, |
| 2318 | 2341 | .struct_init, |
| 2319 | 2342 | .struct_init_anon, |
| 2343 | .array_init, | |
| 2344 | .array_init_anon, | |
| 2345 | .array_init_ref, | |
| 2346 | .array_init_anon_ref, | |
| 2320 | 2347 | .union_init_ptr, |
| 2321 | 2348 | .field_type, |
| 2322 | 2349 | .field_type_ref, |
| ... | ... | @@ -2409,6 +2436,7 @@ const Writer = struct { |
| 2409 | 2436 | .block_inline_var, |
| 2410 | 2437 | .loop, |
| 2411 | 2438 | .validate_struct_init_ptr, |
| 2439 | .validate_array_init_ptr, | |
| 2412 | 2440 | .c_import, |
| 2413 | 2441 | => try self.writePlNodeBlock(stream, inst), |
| 2414 | 2442 | |
| ... | ... | @@ -2450,21 +2478,13 @@ const Writer = struct { |
| 2450 | 2478 | .as_node => try self.writeAs(stream, inst), |
| 2451 | 2479 | |
| 2452 | 2480 | .breakpoint, |
| 2481 | .fence, | |
| 2453 | 2482 | .opaque_decl, |
| 2454 | 2483 | .dbg_stmt_node, |
| 2455 | .ret_ptr, | |
| 2456 | .ret_type, | |
| 2457 | 2484 | .repeat, |
| 2458 | 2485 | .repeat_inline, |
| 2459 | 2486 | .alloc_inferred, |
| 2460 | 2487 | .alloc_inferred_mut, |
| 2461 | .this, | |
| 2462 | .fence, | |
| 2463 | .ret_addr, | |
| 2464 | .builtin_src, | |
| 2465 | .error_return_trace, | |
| 2466 | .frame, | |
| 2467 | .frame_address, | |
| 2468 | 2488 | => try self.writeNode(stream, inst), |
| 2469 | 2489 | |
| 2470 | 2490 | .error_value, |