@@ -9,6 +9,8 @@ use rustc_middle::ty::layout::LayoutOf;
99#[ cfg( feature = "master" ) ]
1010use rustc_session:: config;
1111use rustc_target:: abi:: call:: { ArgAttributes , CastTarget , FnAbi , PassMode , Reg , RegKind } ;
12+ #[ cfg( feature = "master" ) ]
13+ use rustc_target:: callconv:: Conv ;
1214
1315use crate :: builder:: Builder ;
1416use crate :: context:: CodegenCx ;
@@ -104,6 +106,8 @@ pub trait FnAbiGccExt<'gcc, 'tcx> {
104106 // TODO(antoyo): return a function pointer type instead?
105107 fn gcc_type ( & self , cx : & CodegenCx < ' gcc , ' tcx > ) -> FnAbiGcc < ' gcc > ;
106108 fn ptr_to_gcc_type ( & self , cx : & CodegenCx < ' gcc , ' tcx > ) -> Type < ' gcc > ;
109+ #[ cfg( feature = "master" ) ]
110+ fn gcc_cconv ( & self , cx : & CodegenCx < ' gcc , ' tcx > ) -> Option < FnAttribute < ' gcc > > ;
107111}
108112
109113impl < ' gcc , ' tcx > FnAbiGccExt < ' gcc , ' tcx > for FnAbi < ' tcx , Ty < ' tcx > > {
@@ -226,4 +230,46 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
226230 ) ;
227231 pointer_type
228232 }
233+
234+ #[ cfg( feature = "master" ) ]
235+ fn gcc_cconv ( & self , cx : & CodegenCx < ' gcc , ' tcx > ) -> Option < FnAttribute < ' gcc > > {
236+ conv_to_fn_attribute ( self . conv , & cx. tcx . sess . target . arch )
237+ }
238+ }
239+
240+ #[ cfg( feature = "master" ) ]
241+ pub fn conv_to_fn_attribute < ' gcc > ( conv : Conv , _arch : & str ) -> Option < FnAttribute < ' gcc > > {
242+ // TODO: handle the calling conventions returning None.
243+ let attribute = match conv {
244+ Conv :: C
245+ | Conv :: Rust
246+ | Conv :: CCmseNonSecureCall
247+ | Conv :: CCmseNonSecureEntry
248+ | Conv :: RiscvInterrupt { .. } => return None ,
249+ Conv :: Cold => return None ,
250+ Conv :: PreserveMost => return None ,
251+ Conv :: PreserveAll => return None ,
252+ /*Conv::GpuKernel => {
253+ if arch == "amdgpu" {
254+ return None
255+ } else if arch == "nvptx64" {
256+ return None
257+ } else {
258+ panic!("Architecture {arch} does not support GpuKernel calling convention");
259+ }
260+ }*/
261+ Conv :: AvrInterrupt => return None ,
262+ Conv :: AvrNonBlockingInterrupt => return None ,
263+ Conv :: ArmAapcs => return None ,
264+ Conv :: Msp430Intr => return None ,
265+ Conv :: PtxKernel => return None ,
266+ Conv :: X86Fastcall => return None ,
267+ Conv :: X86Intr => return None ,
268+ Conv :: X86Stdcall => return None ,
269+ Conv :: X86ThisCall => return None ,
270+ Conv :: X86VectorCall => return None ,
271+ Conv :: X86_64SysV => FnAttribute :: SysvAbi ,
272+ Conv :: X86_64Win64 => FnAttribute :: MsAbi ,
273+ } ;
274+ Some ( attribute)
229275}
0 commit comments