|
4 | 4 |
|
5 | 5 | // cSpell:words cmpti divti modti mulodi muloti udivti umodti
|
6 | 6 |
|
7 |
| -use gccjit::{BinaryOp, ComparisonOp, FunctionType, Location, RValue, ToRValue, Type, UnaryOp}; |
| 7 | +use gccjit::{ |
| 8 | + BinaryOp, CType, ComparisonOp, FunctionType, Location, RValue, ToRValue, Type, UnaryOp, |
| 9 | +}; |
8 | 10 | use rustc_abi::{CanonAbi, Endian, ExternAbi};
|
9 | 11 | use rustc_codegen_ssa::common::{IntPredicate, TypeKind};
|
10 | 12 | use rustc_codegen_ssa::traits::{BackendTypes, BaseTypeCodegenMethods, BuilderMethods, OverflowOp};
|
11 | 13 | use rustc_middle::ty::{self, Ty};
|
12 | 14 | use rustc_target::callconv::{ArgAbi, ArgAttributes, FnAbi, PassMode};
|
| 15 | +use rustc_type_ir::{Interner, TyKind}; |
13 | 16 |
|
14 | 17 | use crate::builder::{Builder, ToGccComp};
|
15 | 18 | use crate::common::{SignType, TypeReflection};
|
@@ -351,6 +354,9 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
|
351 | 354 | // TODO(antoyo): is it correct to use rhs type instead of the parameter typ?
|
352 | 355 | .new_local(self.___location, rhs.get_type(), "binopResult")
|
353 | 356 | .get_address(self.___location);
|
| 357 | + let new_type = type_kind_to_gcc_type(new_kind); |
| 358 | + let new_type = self.context.new_c_type(new_type); |
| 359 | + let lhs = self.context.new_cast(self.___location, lhs, new_type); |
354 | 360 | let overflow = self.overflow_call(intrinsic, &[lhs, rhs, res], None);
|
355 | 361 | (res.dereference(self.___location).to_rvalue(), overflow)
|
356 | 362 | }
|
@@ -1042,3 +1048,25 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
|
1042 | 1048 | self.context.new_array_constructor(None, typ, &values)
|
1043 | 1049 | }
|
1044 | 1050 | }
|
| 1051 | + |
| 1052 | +fn type_kind_to_gcc_type<I: Interner>(kind: TyKind<I>) -> CType { |
| 1053 | + use rustc_middle::ty::IntTy::*; |
| 1054 | + use rustc_middle::ty::UintTy::*; |
| 1055 | + use rustc_middle::ty::{Int, Uint}; |
| 1056 | + |
| 1057 | + match kind { |
| 1058 | + Int(I8) => CType::Int8t, |
| 1059 | + Int(I16) => CType::Int16t, |
| 1060 | + Int(I32) => CType::Int32t, |
| 1061 | + Int(I64) => CType::Int64t, |
| 1062 | + Int(I128) => CType::Int128t, |
| 1063 | + |
| 1064 | + Uint(U8) => CType::UInt8t, |
| 1065 | + Uint(U16) => CType::UInt16t, |
| 1066 | + Uint(U32) => CType::UInt32t, |
| 1067 | + Uint(U64) => CType::UInt64t, |
| 1068 | + Uint(U128) => CType::UInt128t, |
| 1069 | + |
| 1070 | + _ => unimplemented!("Kind: {:?}", kind), |
| 1071 | + } |
| 1072 | +} |
0 commit comments