@@ -9,6 +9,7 @@ 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+ use rustc_target:: callconv:: Conv ;
1213
1314use crate :: builder:: Builder ;
1415use crate :: context:: CodegenCx ;
@@ -104,6 +105,7 @@ pub trait FnAbiGccExt<'gcc, 'tcx> {
104105 // TODO(antoyo): return a function pointer type instead?
105106 fn gcc_type ( & self , cx : & CodegenCx < ' gcc , ' tcx > ) -> FnAbiGcc < ' gcc > ;
106107 fn ptr_to_gcc_type ( & self , cx : & CodegenCx < ' gcc , ' tcx > ) -> Type < ' gcc > ;
108+ fn gcc_cconv ( & self , cx : & CodegenCx < ' gcc , ' tcx > ) -> Option < FnAttribute < ' gcc > > ;
107109}
108110
109111impl < ' gcc , ' tcx > FnAbiGccExt < ' gcc , ' tcx > for FnAbi < ' tcx , Ty < ' tcx > > {
@@ -226,4 +228,43 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
226228 ) ;
227229 pointer_type
228230 }
231+
232+ fn gcc_cconv ( & self , cx : & CodegenCx < ' gcc , ' tcx > ) -> Option < FnAttribute < ' gcc > > {
233+ conv_to_fn_attribute ( self . conv , & cx. tcx . sess . target . arch )
234+ }
235+ }
236+
237+ pub fn conv_to_fn_attribute < ' gcc > ( conv : Conv , _arch : & str ) -> Option < FnAttribute < ' gcc > > {
238+ let attribute = match conv {
239+ Conv :: C
240+ | Conv :: Rust
241+ | Conv :: CCmseNonSecureCall
242+ | Conv :: CCmseNonSecureEntry
243+ | Conv :: RiscvInterrupt { .. } => return None , // TODO: handle this calling convention.
244+ Conv :: Cold => todo ! ( ) ,
245+ Conv :: PreserveMost => todo ! ( ) ,
246+ Conv :: PreserveAll => todo ! ( ) ,
247+ /*Conv::GpuKernel => {
248+ if arch == "amdgpu" {
249+ todo!()
250+ } else if arch == "nvptx64" {
251+ todo!()
252+ } else {
253+ panic!("Architecture {arch} does not support GpuKernel calling convention");
254+ }
255+ }*/
256+ Conv :: AvrInterrupt => todo ! ( ) ,
257+ Conv :: AvrNonBlockingInterrupt => todo ! ( ) ,
258+ Conv :: ArmAapcs => todo ! ( ) ,
259+ Conv :: Msp430Intr => todo ! ( ) ,
260+ Conv :: PtxKernel => todo ! ( ) ,
261+ Conv :: X86Fastcall => todo ! ( ) ,
262+ Conv :: X86Intr => todo ! ( ) ,
263+ Conv :: X86Stdcall => todo ! ( ) ,
264+ Conv :: X86ThisCall => todo ! ( ) ,
265+ Conv :: X86VectorCall => todo ! ( ) ,
266+ Conv :: X86_64SysV => FnAttribute :: SysvAbi ,
267+ Conv :: X86_64Win64 => FnAttribute :: MsAbi ,
268+ } ;
269+ Some ( attribute)
229270}
0 commit comments