| ... | @@ -3221,7 +3221,34 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) InnerError!WValue { | ... | @@ -3221,7 +3221,34 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) InnerError!WValue { |
| 3221 | | 3221 | |
| 3222 | fn airUnionInit(self: *Self, inst: Air.Inst.Index) InnerError!WValue { | 3222 | fn airUnionInit(self: *Self, inst: Air.Inst.Index) InnerError!WValue { |
| 3223 | if (self.liveness.isUnused(inst)) return WValue{ .none = {} }; | 3223 | if (self.liveness.isUnused(inst)) return WValue{ .none = {} }; |
| 3224 | return self.fail("TODO: Wasm backend: implement airUnionInit", .{}); | 3224 | |
| | 3225 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; |
| | 3226 | const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data; |
| | 3227 | const union_ty = self.air.typeOfIndex(inst); |
| | 3228 | const layout = union_ty.unionGetLayout(self.target); |
| | 3229 | if (layout.payload_size == 0) { |
| | 3230 | if (layout.tag_size == 0) { |
| | 3231 | return WValue{ .none = {} }; |
| | 3232 | } |
| | 3233 | assert(!isByRef(union_ty, self.target)); |
| | 3234 | return WValue{ .imm32 = extra.field_index }; |
| | 3235 | } |
| | 3236 | assert(isByRef(union_ty, self.target)); |
| | 3237 | |
| | 3238 | const result_ptr = try self.allocStack(union_ty); |
| | 3239 | const payload = try self.resolveInst(extra.init); |
| | 3240 | const union_obj = union_ty.cast(Type.Payload.Union).?.data; |
| | 3241 | assert(union_obj.haveFieldTypes()); |
| | 3242 | const field = union_obj.fields.values()[extra.field_index]; |
| | 3243 | |
| | 3244 | if (layout.tag_align >= layout.payload_align) { |
| | 3245 | const payload_ptr = try self.buildPointerOffset(result_ptr, layout.tag_size, .new); |
| | 3246 | try self.store(payload_ptr, payload, field.ty, 0); |
| | 3247 | } else { |
| | 3248 | try self.store(result_ptr, payload, field.ty, 0); |
| | 3249 | } |
| | 3250 | |
| | 3251 | return result_ptr; |
| 3225 | } | 3252 | } |
| 3226 | | 3253 | |
| 3227 | fn airPrefetch(self: *Self, inst: Air.Inst.Index) InnerError!WValue { | 3254 | fn airPrefetch(self: *Self, inst: Air.Inst.Index) InnerError!WValue { |