| ... | @@ -775,7 +775,9 @@ const DocData = struct { | ... | @@ -775,7 +775,9 @@ const DocData = struct { |
| 775 | sizeOf: usize, // index in `exprs` | 775 | sizeOf: usize, // index in `exprs` |
| 776 | bitSizeOf: usize, // index in `exprs` | 776 | bitSizeOf: usize, // index in `exprs` |
| 777 | intFromEnum: usize, // index in `exprs` | 777 | intFromEnum: usize, // index in `exprs` |
| 778 | compileError: usize, //index in `exprs` | 778 | compileError: usize, // index in `exprs` |
| | 779 | optionalPayload: usize, // index in `exprs` |
| | 780 | elemVal: ElemVal, |
| 779 | errorSets: usize, | 781 | errorSets: usize, |
| 780 | string: []const u8, // direct value | 782 | string: []const u8, // direct value |
| 781 | sliceIndex: usize, | 783 | sliceIndex: usize, |
| ... | @@ -791,6 +793,7 @@ const DocData = struct { | ... | @@ -791,6 +793,7 @@ const DocData = struct { |
| 791 | switchOp: SwitchOp, | 793 | switchOp: SwitchOp, |
| 792 | binOp: BinOp, | 794 | binOp: BinOp, |
| 793 | binOpIndex: usize, | 795 | binOpIndex: usize, |
| | 796 | load: usize, // index in `exprs` |
| 794 | const BinOp = struct { | 797 | const BinOp = struct { |
| 795 | lhs: usize, // index in `exprs` | 798 | lhs: usize, // index in `exprs` |
| 796 | rhs: usize, // index in `exprs` | 799 | rhs: usize, // index in `exprs` |
| ... | @@ -846,6 +849,11 @@ const DocData = struct { | ... | @@ -846,6 +849,11 @@ const DocData = struct { |
| 846 | val: WalkResult, | 849 | val: WalkResult, |
| 847 | }; | 850 | }; |
| 848 | | 851 | |
| | 852 | const ElemVal = struct { |
| | 853 | lhs: usize, // index in `exprs` |
| | 854 | rhs: usize, // index in `exprs` |
| | 855 | }; |
| | 856 | |
| 849 | pub fn jsonStringify(self: Expr, jsw: anytype) !void { | 857 | pub fn jsonStringify(self: Expr, jsw: anytype) !void { |
| 850 | const active_tag = std.meta.activeTag(self); | 858 | const active_tag = std.meta.activeTag(self); |
| 851 | try jsw.beginObject(); | 859 | try jsw.beginObject(); |
| ... | @@ -1463,6 +1471,38 @@ fn walkInstruction( | ... | @@ -1463,6 +1471,38 @@ fn walkInstruction( |
| 1463 | }; | 1471 | }; |
| 1464 | }, | 1472 | }, |
| 1465 | | 1473 | |
| | 1474 | .load => { |
| | 1475 | const un_node = data[inst_index].un_node; |
| | 1476 | const operand = try self.walkRef( |
| | 1477 | file, |
| | 1478 | parent_scope, |
| | 1479 | parent_src, |
| | 1480 | un_node.operand, |
| | 1481 | need_type, |
| | 1482 | call_ctx, |
| | 1483 | ); |
| | 1484 | const load_idx = self.exprs.items.len; |
| | 1485 | try self.exprs.append(self.arena, operand.expr); |
| | 1486 | |
| | 1487 | var typeRef: ?DocData.Expr = null; |
| | 1488 | if (operand.typeRef) |ref| { |
| | 1489 | switch (ref) { |
| | 1490 | .type => |t_index| { |
| | 1491 | switch (self.types.items[t_index]) { |
| | 1492 | .Pointer => |p| typeRef = p.child, |
| | 1493 | else => {}, |
| | 1494 | } |
| | 1495 | }, |
| | 1496 | else => {}, |
| | 1497 | } |
| | 1498 | } |
| | 1499 | |
| | 1500 | return DocData.WalkResult{ |
| | 1501 | .typeRef = typeRef, |
| | 1502 | .expr = .{ .load = load_idx }, |
| | 1503 | }; |
| | 1504 | }, |
| | 1505 | |
| 1466 | // @check array_cat and array_mul | 1506 | // @check array_cat and array_mul |
| 1467 | .add, | 1507 | .add, |
| 1468 | .addwrap, | 1508 | .addwrap, |
| ... | @@ -2862,6 +2902,72 @@ fn walkInstruction( | ... | @@ -2862,6 +2902,72 @@ fn walkInstruction( |
| 2862 | | 2902 | |
| 2863 | return result; | 2903 | return result; |
| 2864 | }, | 2904 | }, |
| | 2905 | .optional_payload_safe, .optional_payload_unsafe => { |
| | 2906 | const un_node = data[inst_index].un_node; |
| | 2907 | const operand = try self.walkRef( |
| | 2908 | file, |
| | 2909 | parent_scope, |
| | 2910 | parent_src, |
| | 2911 | un_node.operand, |
| | 2912 | need_type, |
| | 2913 | call_ctx, |
| | 2914 | ); |
| | 2915 | const optional_idx = self.exprs.items.len; |
| | 2916 | try self.exprs.append(self.arena, operand.expr); |
| | 2917 | |
| | 2918 | var typeRef: ?DocData.Expr = null; |
| | 2919 | if (operand.typeRef) |ref| { |
| | 2920 | switch (ref) { |
| | 2921 | .type => |t_index| { |
| | 2922 | const t = self.types.items[t_index]; |
| | 2923 | switch (t) { |
| | 2924 | .Optional => |opt| typeRef = opt.child, |
| | 2925 | else => { |
| | 2926 | printWithContext(file, inst_index, "Invalid type for optional_payload_*: {}\n", .{t}); |
| | 2927 | }, |
| | 2928 | } |
| | 2929 | }, |
| | 2930 | else => {}, |
| | 2931 | } |
| | 2932 | } |
| | 2933 | |
| | 2934 | return DocData.WalkResult{ |
| | 2935 | .typeRef = typeRef, |
| | 2936 | .expr = .{ .optionalPayload = optional_idx }, |
| | 2937 | }; |
| | 2938 | }, |
| | 2939 | .elem_val_node => { |
| | 2940 | const pl_node = data[inst_index].pl_node; |
| | 2941 | const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index); |
| | 2942 | const lhs = try self.walkRef( |
| | 2943 | file, |
| | 2944 | parent_scope, |
| | 2945 | parent_src, |
| | 2946 | extra.data.lhs, |
| | 2947 | need_type, |
| | 2948 | call_ctx, |
| | 2949 | ); |
| | 2950 | const rhs = try self.walkRef( |
| | 2951 | file, |
| | 2952 | parent_scope, |
| | 2953 | parent_src, |
| | 2954 | extra.data.rhs, |
| | 2955 | need_type, |
| | 2956 | call_ctx, |
| | 2957 | ); |
| | 2958 | const lhs_idx = self.exprs.items.len; |
| | 2959 | try self.exprs.append(self.arena, lhs.expr); |
| | 2960 | const rhs_idx = self.exprs.items.len; |
| | 2961 | try self.exprs.append(self.arena, rhs.expr); |
| | 2962 | return DocData.WalkResult{ |
| | 2963 | .expr = .{ |
| | 2964 | .elemVal = .{ |
| | 2965 | .lhs = lhs_idx, |
| | 2966 | .rhs = rhs_idx, |
| | 2967 | }, |
| | 2968 | }, |
| | 2969 | }; |
| | 2970 | }, |
| 2865 | .extended => { | 2971 | .extended => { |
| 2866 | const extended = data[inst_index].extended; | 2972 | const extended = data[inst_index].extended; |
| 2867 | switch (extended.opcode) { | 2973 | switch (extended.opcode) { |