| ... | @@ -4098,11 +4098,13 @@ const DeclGen = struct { | ... | @@ -4098,11 +4098,13 @@ const DeclGen = struct { |
| 4098 | fn airSwitchBr(self: *DeclGen, inst: Air.Inst.Index) !void { | 4098 | fn airSwitchBr(self: *DeclGen, inst: Air.Inst.Index) !void { |
| 4099 | const mod = self.module; | 4099 | const mod = self.module; |
| 4100 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; | 4100 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; |
| 4101 | const cond = try self.resolve(pl_op.operand); | | |
| 4102 | const cond_ty = self.typeOf(pl_op.operand); | 4101 | const cond_ty = self.typeOf(pl_op.operand); |
| | 4102 | const cond = try self.resolve(pl_op.operand); |
| | 4103 | const cond_indirect = try self.convertToIndirect(cond_ty, cond); |
| 4103 | const switch_br = self.air.extraData(Air.SwitchBr, pl_op.payload); | 4104 | const switch_br = self.air.extraData(Air.SwitchBr, pl_op.payload); |
| 4104 | | 4105 | |
| 4105 | const cond_words: u32 = switch (cond_ty.zigTypeTag(mod)) { | 4106 | const cond_words: u32 = switch (cond_ty.zigTypeTag(mod)) { |
| | 4107 | .Bool => 1, |
| 4106 | .Int => blk: { | 4108 | .Int => blk: { |
| 4107 | const bits = cond_ty.intInfo(mod).bits; | 4109 | const bits = cond_ty.intInfo(mod).bits; |
| 4108 | const backing_bits = self.backingIntBits(bits) orelse { | 4110 | const backing_bits = self.backingIntBits(bits) orelse { |
| ... | @@ -4146,7 +4148,7 @@ const DeclGen = struct { | ... | @@ -4146,7 +4148,7 @@ const DeclGen = struct { |
| 4146 | | 4148 | |
| 4147 | // Emit the instruction before generating the blocks. | 4149 | // Emit the instruction before generating the blocks. |
| 4148 | try self.func.body.emitRaw(self.spv.gpa, .OpSwitch, 2 + (cond_words + 1) * num_conditions); | 4150 | try self.func.body.emitRaw(self.spv.gpa, .OpSwitch, 2 + (cond_words + 1) * num_conditions); |
| 4149 | self.func.body.writeOperand(IdRef, cond); | 4151 | self.func.body.writeOperand(IdRef, cond_indirect); |
| 4150 | self.func.body.writeOperand(IdRef, default); | 4152 | self.func.body.writeOperand(IdRef, default); |
| 4151 | | 4153 | |
| 4152 | // Emit each of the cases | 4154 | // Emit each of the cases |
| ... | @@ -4167,7 +4169,7 @@ const DeclGen = struct { | ... | @@ -4167,7 +4169,7 @@ const DeclGen = struct { |
| 4167 | return self.todo("switch on runtime value???", .{}); | 4169 | return self.todo("switch on runtime value???", .{}); |
| 4168 | }; | 4170 | }; |
| 4169 | const int_val = switch (cond_ty.zigTypeTag(mod)) { | 4171 | const int_val = switch (cond_ty.zigTypeTag(mod)) { |
| 4170 | .Int => if (cond_ty.isSignedInt(mod)) @as(u64, @bitCast(value.toSignedInt(mod))) else value.toUnsignedInt(mod), | 4172 | .Bool, .Int => if (cond_ty.isSignedInt(mod)) @as(u64, @bitCast(value.toSignedInt(mod))) else value.toUnsignedInt(mod), |
| 4171 | .Enum => blk: { | 4173 | .Enum => blk: { |
| 4172 | // TODO: figure out of cond_ty is correct (something with enum literals) | 4174 | // TODO: figure out of cond_ty is correct (something with enum literals) |
| 4173 | break :blk (try value.intFromEnum(cond_ty, mod)).toUnsignedInt(mod); // TODO: composite integer constants | 4175 | break :blk (try value.intFromEnum(cond_ty, mod)).toUnsignedInt(mod); // TODO: composite integer constants |