Compare commits
2 Commits
856b4fb371
...
62790ce974
Author | SHA1 | Date |
---|---|---|
|
62790ce974 | |
|
029dc6f61d |
|
@ -298,16 +298,21 @@ impl<'ctx, 'a> CodeGenContext<'ctx, 'a> {
|
||||||
(Operator::BitOr, _) => self.builder.build_or(lhs, rhs, "or").into(),
|
(Operator::BitOr, _) => self.builder.build_or(lhs, rhs, "or").into(),
|
||||||
(Operator::BitXor, _) => self.builder.build_xor(lhs, rhs, "xor").into(),
|
(Operator::BitXor, _) => self.builder.build_xor(lhs, rhs, "xor").into(),
|
||||||
(Operator::BitAnd, _) => self.builder.build_and(lhs, rhs, "and").into(),
|
(Operator::BitAnd, _) => self.builder.build_and(lhs, rhs, "and").into(),
|
||||||
|
|
||||||
|
// Sign-ness of bitshift operators are always determined by the left operand
|
||||||
(Operator::LShift, signed) | (Operator::RShift, signed) => {
|
(Operator::LShift, signed) | (Operator::RShift, signed) => {
|
||||||
|
// RHS operand is always 32 bits
|
||||||
|
assert_eq!(rhs.get_type().get_bit_width(), 32);
|
||||||
|
|
||||||
let common_type = lhs.get_type();
|
let common_type = lhs.get_type();
|
||||||
let rhs = if common_type.get_bit_width() > rhs.get_type().get_bit_width() {
|
let rhs = if common_type.get_bit_width() > 32 {
|
||||||
if signed {
|
if signed {
|
||||||
self.builder.build_int_s_extend(rhs, common_type, "")
|
self.builder.build_int_s_extend(rhs, common_type, "")
|
||||||
} else {
|
} else {
|
||||||
self.builder.build_int_z_extend(rhs, common_type, "")
|
self.builder.build_int_z_extend(rhs, common_type, "")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.builder.build_int_truncate_or_bit_cast(rhs, common_type, "")
|
rhs
|
||||||
};
|
};
|
||||||
|
|
||||||
let rhs_gez = self.builder.build_int_compare(IntPredicate::SGE, rhs, common_type.const_zero(), "");
|
let rhs_gez = self.builder.build_int_compare(IntPredicate::SGE, rhs, common_type.const_zero(), "");
|
||||||
|
@ -325,7 +330,8 @@ impl<'ctx, 'a> CodeGenContext<'ctx, 'a> {
|
||||||
Operator::RShift => self.builder.build_right_shift(lhs, rhs, signed, "rshift").into(),
|
Operator::RShift => self.builder.build_right_shift(lhs, rhs, signed, "rshift").into(),
|
||||||
_ => unreachable!()
|
_ => unreachable!()
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
(Operator::FloorDiv, true) => self.builder.build_int_signed_div(lhs, rhs, "floordiv").into(),
|
(Operator::FloorDiv, true) => self.builder.build_int_signed_div(lhs, rhs, "floordiv").into(),
|
||||||
(Operator::FloorDiv, false) => self.builder.build_int_unsigned_div(lhs, rhs, "floordiv").into(),
|
(Operator::FloorDiv, false) => self.builder.build_int_unsigned_div(lhs, rhs, "floordiv").into(),
|
||||||
(Operator::Pow, s) => integer_power(generator, self, lhs, rhs, s).into(),
|
(Operator::Pow, s) => integer_power(generator, self, lhs, rhs, s).into(),
|
||||||
|
|
Loading…
Reference in New Issue