| ... | ... | @@ -2447,6 +2447,9 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void { |
| 2447 | 2447 | .register_c_flag, |
| 2448 | 2448 | .register_v_flag, |
| 2449 | 2449 | => |reg| { |
| 2450 | const reg_lock = self.register_manager.lockRegAssumeUnused(reg); |
| 2451 | defer self.register_manager.unlockReg(reg_lock); |
| 2452 | |
| 2450 | 2453 | switch (index) { |
| 2451 | 2454 | 0 => { |
| 2452 | 2455 | // get wrapped value: return register |
| ... | ... | @@ -5062,6 +5065,7 @@ fn lowerUnnamedConst(self: *Self, tv: TypedValue) InnerError!MCValue { |
| 5062 | 5065 | } |
| 5063 | 5066 | |
| 5064 | 5067 | fn genTypedValue(self: *Self, typed_value: TypedValue) InnerError!MCValue { |
| 5068 | log.debug("genTypedValue: ty = {}, val = {}", .{ typed_value.ty.fmtDebug(), typed_value.val.fmtDebug() }); |
| 5065 | 5069 | if (typed_value.val.isUndef()) |
| 5066 | 5070 | return MCValue{ .undef = {} }; |
| 5067 | 5071 | const ptr_bits = self.target.cpu.arch.ptrBitWidth(); |
| ... | ... | @@ -5075,24 +5079,14 @@ fn genTypedValue(self: *Self, typed_value: TypedValue) InnerError!MCValue { |
| 5075 | 5079 | const target = self.target.*; |
| 5076 | 5080 | |
| 5077 | 5081 | switch (typed_value.ty.zigTypeTag()) { |
| 5078 | | .Array => { |
| 5079 | | return self.lowerUnnamedConst(typed_value); |
| 5080 | | }, |
| 5081 | 5082 | .Pointer => switch (typed_value.ty.ptrSize()) { |
| 5082 | | .Slice => { |
| 5083 | | return self.lowerUnnamedConst(typed_value); |
| 5084 | | }, |
| 5083 | .Slice => {}, |
| 5085 | 5084 | else => { |
| 5086 | 5085 | switch (typed_value.val.tag()) { |
| 5087 | 5086 | .int_u64 => { |
| 5088 | 5087 | return MCValue{ .immediate = @intCast(u32, typed_value.val.toUnsignedInt(target)) }; |
| 5089 | 5088 | }, |
| 5090 | | .slice => { |
| 5091 | | return self.lowerUnnamedConst(typed_value); |
| 5092 | | }, |
| 5093 | | else => { |
| 5094 | | return self.fail("TODO codegen more kinds of const pointers", .{}); |
| 5095 | | }, |
| 5089 | else => {}, |
| 5096 | 5090 | } |
| 5097 | 5091 | }, |
| 5098 | 5092 | }, |
| ... | ... | @@ -5115,8 +5109,6 @@ fn genTypedValue(self: *Self, typed_value: TypedValue) InnerError!MCValue { |
| 5115 | 5109 | .Bool => { |
| 5116 | 5110 | return MCValue{ .immediate = @boolToInt(typed_value.val.toBool()) }; |
| 5117 | 5111 | }, |
| 5118 | | .ComptimeInt => unreachable, // semantic analysis prevents this |
| 5119 | | .ComptimeFloat => unreachable, // semantic analysis prevents this |
| 5120 | 5112 | .Optional => { |
| 5121 | 5113 | if (typed_value.ty.isPtrLikeOptional()) { |
| 5122 | 5114 | if (typed_value.val.isNull()) |
| ... | ... | @@ -5130,7 +5122,6 @@ fn genTypedValue(self: *Self, typed_value: TypedValue) InnerError!MCValue { |
| 5130 | 5122 | } else if (typed_value.ty.abiSize(self.target.*) == 1) { |
| 5131 | 5123 | return MCValue{ .immediate = @boolToInt(typed_value.val.isNull()) }; |
| 5132 | 5124 | } |
| 5133 | | return self.fail("TODO non pointer optionals", .{}); |
| 5134 | 5125 | }, |
| 5135 | 5126 | .Enum => { |
| 5136 | 5127 | if (typed_value.val.castTag(.enum_field_index)) |field_index| { |
| ... | ... | @@ -5166,28 +5157,34 @@ fn genTypedValue(self: *Self, typed_value: TypedValue) InnerError!MCValue { |
| 5166 | 5157 | const error_type = typed_value.ty.errorUnionSet(); |
| 5167 | 5158 | const payload_type = typed_value.ty.errorUnionPayload(); |
| 5168 | 5159 | |
| 5169 | | if (typed_value.val.castTag(.eu_payload)) |pl| { |
| 5160 | if (typed_value.val.castTag(.eu_payload)) |_| { |
| 5170 | 5161 | if (!payload_type.hasRuntimeBits()) { |
| 5171 | 5162 | // We use the error type directly as the type. |
| 5172 | 5163 | return MCValue{ .immediate = 0 }; |
| 5173 | 5164 | } |
| 5174 | | |
| 5175 | | _ = pl; |
| 5176 | | return self.fail("TODO implement error union const of type '{}' (non-error)", .{typed_value.ty.fmtDebug()}); |
| 5177 | 5165 | } else { |
| 5178 | 5166 | if (!payload_type.hasRuntimeBits()) { |
| 5179 | 5167 | // We use the error type directly as the type. |
| 5180 | 5168 | return self.genTypedValue(.{ .ty = error_type, .val = typed_value.val }); |
| 5181 | 5169 | } |
| 5182 | | |
| 5183 | | return self.fail("TODO implement error union const of type '{}' (error)", .{typed_value.ty.fmtDebug()}); |
| 5184 | 5170 | } |
| 5185 | 5171 | }, |
| 5186 | | .Struct => { |
| 5187 | | return self.lowerUnnamedConst(typed_value); |
| 5188 | | }, |
| 5189 | | else => return self.fail("TODO implement const of type '{}'", .{typed_value.ty.fmtDebug()}), |
| 5172 | |
| 5173 | .ComptimeInt => unreachable, // semantic analysis prevents this |
| 5174 | .ComptimeFloat => unreachable, // semantic analysis prevents this |
| 5175 | .Type => unreachable, |
| 5176 | .EnumLiteral => unreachable, |
| 5177 | .Void => unreachable, |
| 5178 | .NoReturn => unreachable, |
| 5179 | .Undefined => unreachable, |
| 5180 | .Null => unreachable, |
| 5181 | .BoundFn => unreachable, |
| 5182 | .Opaque => unreachable, |
| 5183 | |
| 5184 | else => {}, |
| 5190 | 5185 | } |
| 5186 | |
| 5187 | return self.lowerUnnamedConst(typed_value); |
| 5191 | 5188 | } |
| 5192 | 5189 | |
| 5193 | 5190 | const CallMCValues = struct { |