| ... | ... | @@ -4139,11 +4139,13 @@ const DeclGen = struct { |
| 4139 | 4139 | fn airSwitchBr(self: *DeclGen, inst: Air.Inst.Index) !void { |
| 4140 | 4140 | const mod = self.module; |
| 4141 | 4141 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; |
| 4142 | | const cond = try self.resolve(pl_op.operand); |
| 4143 | 4142 | const cond_ty = self.typeOf(pl_op.operand); |
| 4143 | const cond = try self.resolve(pl_op.operand); |
| 4144 | const cond_indirect = try self.convertToIndirect(cond_ty, cond); |
| 4144 | 4145 | const switch_br = self.air.extraData(Air.SwitchBr, pl_op.payload); |
| 4145 | 4146 | |
| 4146 | 4147 | const cond_words: u32 = switch (cond_ty.zigTypeTag(mod)) { |
| 4148 | .Bool => 1, |
| 4147 | 4149 | .Int => blk: { |
| 4148 | 4150 | const bits = cond_ty.intInfo(mod).bits; |
| 4149 | 4151 | const backing_bits = self.backingIntBits(bits) orelse { |
| ... | ... | @@ -4187,7 +4189,7 @@ const DeclGen = struct { |
| 4187 | 4189 | |
| 4188 | 4190 | // Emit the instruction before generating the blocks. |
| 4189 | 4191 | try self.func.body.emitRaw(self.spv.gpa, .OpSwitch, 2 + (cond_words + 1) * num_conditions); |
| 4190 | | self.func.body.writeOperand(IdRef, cond); |
| 4192 | self.func.body.writeOperand(IdRef, cond_indirect); |
| 4191 | 4193 | self.func.body.writeOperand(IdRef, default); |
| 4192 | 4194 | |
| 4193 | 4195 | // Emit each of the cases |
| ... | ... | @@ -4208,7 +4210,7 @@ const DeclGen = struct { |
| 4208 | 4210 | return self.todo("switch on runtime value???", .{}); |
| 4209 | 4211 | }; |
| 4210 | 4212 | const int_val = switch (cond_ty.zigTypeTag(mod)) { |
| 4211 | | .Int => if (cond_ty.isSignedInt(mod)) @as(u64, @bitCast(value.toSignedInt(mod))) else value.toUnsignedInt(mod), |
| 4213 | .Bool, .Int => if (cond_ty.isSignedInt(mod)) @as(u64, @bitCast(value.toSignedInt(mod))) else value.toUnsignedInt(mod), |
| 4212 | 4214 | .Enum => blk: { |
| 4213 | 4215 | // TODO: figure out of cond_ty is correct (something with enum literals) |
| 4214 | 4216 | break :blk (try value.intFromEnum(cond_ty, mod)).toUnsignedInt(mod); // TODO: composite integer constants |