@@ -9,6 +9,8 @@ use rustc_middle::ty::layout::LayoutOf;
9
9
#[ cfg( feature = "master" ) ]
10
10
use rustc_session:: config;
11
11
use rustc_target:: abi:: call:: { ArgAttributes , CastTarget , FnAbi , PassMode , Reg , RegKind } ;
12
+ #[ cfg( feature = "master" ) ]
13
+ use rustc_target:: callconv:: Conv ;
12
14
13
15
use crate :: builder:: Builder ;
14
16
use crate :: context:: CodegenCx ;
@@ -104,6 +106,8 @@ pub trait FnAbiGccExt<'gcc, 'tcx> {
104
106
// TODO(antoyo): return a function pointer type instead?
105
107
fn gcc_type ( & self , cx : & CodegenCx < ' gcc , ' tcx > ) -> FnAbiGcc < ' gcc > ;
106
108
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 > > ;
107
111
}
108
112
109
113
impl < ' 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>> {
226
230
) ;
227
231
pointer_type
228
232
}
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)
229
275
}
0 commit comments