Fix exactudiv
This commit is contained in:
parent
8697dec532
commit
fb69f73d67
@ -492,8 +492,11 @@ fn udiv(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
|
||||
}
|
||||
|
||||
fn exactudiv(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
|
||||
// TODO(antoyo): convert the arguments to unsigned?
|
||||
// TODO(antoyo): poison if not exact.
|
||||
let a_type = a.get_type().to_unsigned(self);
|
||||
let a = self.gcc_int_cast(a, a_type);
|
||||
let b_type = b.get_type().to_unsigned(self);
|
||||
let b = self.gcc_int_cast(b, b_type);
|
||||
a / b
|
||||
}
|
||||
|
||||
|
@ -279,6 +279,21 @@ fn to_signed(&self, cx: &CodegenCx<'gcc, 'tcx>) -> Type<'gcc> {
|
||||
else if self.is_u128(cx) {
|
||||
cx.i128_type
|
||||
}
|
||||
else if self.is_uchar(cx) {
|
||||
cx.char_type
|
||||
}
|
||||
else if self.is_ushort(cx) {
|
||||
cx.short_type
|
||||
}
|
||||
else if self.is_uint(cx) {
|
||||
cx.int_type
|
||||
}
|
||||
else if self.is_ulong(cx) {
|
||||
cx.long_type
|
||||
}
|
||||
else if self.is_ulonglong(cx) {
|
||||
cx.longlong_type
|
||||
}
|
||||
else {
|
||||
self.clone()
|
||||
}
|
||||
@ -300,6 +315,21 @@ fn to_unsigned(&self, cx: &CodegenCx<'gcc, 'tcx>) -> Type<'gcc> {
|
||||
else if self.is_i128(cx) {
|
||||
cx.u128_type
|
||||
}
|
||||
else if self.is_char(cx) {
|
||||
cx.uchar_type
|
||||
}
|
||||
else if self.is_short(cx) {
|
||||
cx.ushort_type
|
||||
}
|
||||
else if self.is_int(cx) {
|
||||
cx.uint_type
|
||||
}
|
||||
else if self.is_long(cx) {
|
||||
cx.ulong_type
|
||||
}
|
||||
else if self.is_longlong(cx) {
|
||||
cx.ulonglong_type
|
||||
}
|
||||
else {
|
||||
self.clone()
|
||||
}
|
||||
@ -312,6 +342,11 @@ pub trait TypeReflection<'gcc, 'tcx> {
|
||||
fn is_uint(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
|
||||
fn is_ulong(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
|
||||
fn is_ulonglong(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
|
||||
fn is_char(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
|
||||
fn is_short(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
|
||||
fn is_int(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
|
||||
fn is_long(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
|
||||
fn is_longlong(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
|
||||
|
||||
fn is_i8(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
|
||||
fn is_u8(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
|
||||
@ -332,11 +367,11 @@ pub trait TypeReflection<'gcc, 'tcx> {
|
||||
|
||||
impl<'gcc, 'tcx> TypeReflection<'gcc, 'tcx> for Type<'gcc> {
|
||||
fn is_uchar(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
|
||||
self.unqualified() == cx.u8_type
|
||||
self.unqualified() == cx.uchar_type
|
||||
}
|
||||
|
||||
fn is_ushort(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
|
||||
self.unqualified() == cx.u16_type
|
||||
self.unqualified() == cx.ushort_type
|
||||
}
|
||||
|
||||
fn is_uint(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
|
||||
@ -351,6 +386,26 @@ fn is_ulonglong(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
|
||||
self.unqualified() == cx.ulonglong_type
|
||||
}
|
||||
|
||||
fn is_char(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
|
||||
self.unqualified() == cx.char_type
|
||||
}
|
||||
|
||||
fn is_short(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
|
||||
self.unqualified() == cx.short_type
|
||||
}
|
||||
|
||||
fn is_int(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
|
||||
self.unqualified() == cx.int_type
|
||||
}
|
||||
|
||||
fn is_long(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
|
||||
self.unqualified() == cx.long_type
|
||||
}
|
||||
|
||||
fn is_longlong(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
|
||||
self.unqualified() == cx.longlong_type
|
||||
}
|
||||
|
||||
fn is_i8(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
|
||||
self.unqualified() == cx.i8_type
|
||||
}
|
||||
|
@ -54,10 +54,15 @@ pub struct CodegenCx<'gcc, 'tcx> {
|
||||
pub u128_type: Type<'gcc>,
|
||||
pub usize_type: Type<'gcc>,
|
||||
|
||||
pub char_type: Type<'gcc>,
|
||||
pub uchar_type: Type<'gcc>,
|
||||
pub short_type: Type<'gcc>,
|
||||
pub ushort_type: Type<'gcc>,
|
||||
pub int_type: Type<'gcc>,
|
||||
pub uint_type: Type<'gcc>,
|
||||
pub long_type: Type<'gcc>,
|
||||
pub ulong_type: Type<'gcc>,
|
||||
pub longlong_type: Type<'gcc>,
|
||||
pub ulonglong_type: Type<'gcc>,
|
||||
pub sizet_type: Type<'gcc>,
|
||||
|
||||
@ -146,10 +151,15 @@ pub fn new(context: &'gcc Context<'gcc>, codegen_unit: &'tcx CodegenUnit<'tcx>,
|
||||
let float_type = context.new_type::<f32>();
|
||||
let double_type = context.new_type::<f64>();
|
||||
|
||||
let char_type = context.new_c_type(CType::Char);
|
||||
let uchar_type = context.new_c_type(CType::UChar);
|
||||
let short_type = context.new_c_type(CType::Short);
|
||||
let ushort_type = context.new_c_type(CType::UShort);
|
||||
let int_type = context.new_c_type(CType::Int);
|
||||
let uint_type = context.new_c_type(CType::UInt);
|
||||
let long_type = context.new_c_type(CType::Long);
|
||||
let ulong_type = context.new_c_type(CType::ULong);
|
||||
let longlong_type = context.new_c_type(CType::LongLong);
|
||||
let ulonglong_type = context.new_c_type(CType::ULongLong);
|
||||
let sizet_type = context.new_c_type(CType::SizeT);
|
||||
|
||||
@ -202,10 +212,15 @@ pub fn new(context: &'gcc Context<'gcc>, codegen_unit: &'tcx CodegenUnit<'tcx>,
|
||||
u32_type,
|
||||
u64_type,
|
||||
u128_type,
|
||||
char_type,
|
||||
uchar_type,
|
||||
short_type,
|
||||
ushort_type,
|
||||
int_type,
|
||||
uint_type,
|
||||
long_type,
|
||||
ulong_type,
|
||||
longlong_type,
|
||||
ulonglong_type,
|
||||
sizet_type,
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user