Skip to content

Commit 8cface0

Browse files
davidcole1340Aatif Syed
authored and
Aatif Syed
committed
Added support for vectorcall ABI
1 parent 44ee1bd commit 8cface0

File tree

7 files changed

+69
-7
lines changed

7 files changed

+69
-7
lines changed

src/codegen/mod.rs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use self::struct_layout::StructLayoutTracker;
1717

1818
use super::BindgenOptions;
1919

20+
use crate::features::RustFeatures;
2021
use crate::ir::analysis::{HasVtable, Sizedness};
2122
use crate::ir::annotations::FieldAccessorKind;
2223
use crate::ir::comment;
@@ -2414,10 +2415,22 @@ impl MethodCodegen for Method {
24142415
_ => panic!("How in the world?"),
24152416
};
24162417

2417-
if let (Abi::ThisCall, false) =
2418-
(signature.abi(), ctx.options().rust_features().thiscall_abi)
2419-
{
2420-
return;
2418+
match (signature.abi(), ctx.options().rust_features()) {
2419+
(
2420+
Abi::ThisCall,
2421+
RustFeatures {
2422+
thiscall_abi: false,
2423+
..
2424+
},
2425+
) |
2426+
(
2427+
Abi::Vectorcall,
2428+
RustFeatures {
2429+
vectorcall_abi: false,
2430+
..
2431+
},
2432+
) => return,
2433+
_ => {}
24212434
}
24222435

24232436
// Do not generate variadic methods, since rust does not allow
@@ -3867,6 +3880,12 @@ impl TryToRustTy for FunctionSig {
38673880
warn!("Skipping function with thiscall ABI that isn't supported by the configured Rust target");
38683881
Ok(proc_macro2::TokenStream::new())
38693882
}
3883+
Abi::Vectorcall
3884+
if !ctx.options().rust_features().vectorcall_abi =>
3885+
{
3886+
warn!("Skipping function with vectorcall ABI that isn't supported by the configured Rust target");
3887+
Ok(proc_macro2::TokenStream::new())
3888+
}
38703889
_ => Ok(quote! {
38713890
unsafe extern #abi fn ( #( #arguments ),* ) #ret
38723891
}),
@@ -3958,6 +3977,12 @@ impl CodeGenerator for Function {
39583977
warn!("Skipping function with thiscall ABI that isn't supported by the configured Rust target");
39593978
return None;
39603979
}
3980+
Abi::Vectorcall
3981+
if !ctx.options().rust_features().vectorcall_abi =>
3982+
{
3983+
warn!("Skipping function with vectorcall ABI that isn't supported by the configured Rust target");
3984+
return None;
3985+
}
39613986
Abi::Win64 if signature.is_variadic() => {
39623987
warn!("Skipping variadic function with Win64 ABI that isn't supported");
39633988
return None;

src/features.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ macro_rules! rust_target_base {
129129
=> Stable_1_47 => 1.47;
130130
/// Nightly rust
131131
/// * `thiscall` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/42202))
132+
/// * `vectorcall` calling convention (no tracking issue)
132133
=> Nightly => nightly;
133134
);
134135
}
@@ -234,6 +235,7 @@ rust_feature_def!(
234235
}
235236
Nightly {
236237
=> thiscall_abi;
238+
=> vectorcall_abi;
237239
}
238240
);
239241

@@ -259,7 +261,8 @@ mod test {
259261
!f_1_0.associated_const &&
260262
!f_1_0.builtin_clone_impls &&
261263
!f_1_0.repr_align &&
262-
!f_1_0.thiscall_abi
264+
!f_1_0.thiscall_abi &&
265+
!f_1_0.vectorcall_abi
263266
);
264267
let f_1_21 = RustFeatures::from(RustTarget::Stable_1_21);
265268
assert!(
@@ -269,7 +272,8 @@ mod test {
269272
f_1_21.associated_const &&
270273
f_1_21.builtin_clone_impls &&
271274
!f_1_21.repr_align &&
272-
!f_1_21.thiscall_abi
275+
!f_1_21.thiscall_abi &&
276+
!f_1_21.vectorcall_abi
273277
);
274278
let f_nightly = RustFeatures::from(RustTarget::Nightly);
275279
assert!(
@@ -280,7 +284,8 @@ mod test {
280284
f_nightly.builtin_clone_impls &&
281285
f_nightly.maybe_uninit &&
282286
f_nightly.repr_align &&
283-
f_nightly.thiscall_abi
287+
f_nightly.thiscall_abi &&
288+
f_nightly.vectorcall_abi
284289
);
285290
}
286291

src/ir/function.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ pub enum Abi {
181181
Fastcall,
182182
/// The "thiscall" ABI.
183183
ThisCall,
184+
/// The "vectorcall" ABI.
185+
Vectorcall,
184186
/// The "aapcs" ABI.
185187
Aapcs,
186188
/// The "win64" ABI.
@@ -203,6 +205,7 @@ impl quote::ToTokens for Abi {
203205
Abi::Stdcall => quote! { "stdcall" },
204206
Abi::Fastcall => quote! { "fastcall" },
205207
Abi::ThisCall => quote! { "thiscall" },
208+
Abi::Vectorcall => quote! { "vectorcall" },
206209
Abi::Aapcs => quote! { "aapcs" },
207210
Abi::Win64 => quote! { "win64" },
208211
Abi::Unknown(cc) => panic!(
@@ -241,6 +244,7 @@ fn get_abi(cc: CXCallingConv) -> Abi {
241244
CXCallingConv_X86StdCall => Abi::Stdcall,
242245
CXCallingConv_X86FastCall => Abi::Fastcall,
243246
CXCallingConv_X86ThisCall => Abi::ThisCall,
247+
CXCallingConv_X86VectorCall => Abi::Vectorcall,
244248
CXCallingConv_AAPCS => Abi::Aapcs,
245249
CXCallingConv_X86_64Win64 => Abi::Win64,
246250
other => Abi::Unknown(other),
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![allow(
2+
dead_code,
3+
non_snake_case,
4+
non_camel_case_types,
5+
non_upper_case_globals
6+
)]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![allow(
2+
dead_code,
3+
non_snake_case,
4+
non_camel_case_types,
5+
non_upper_case_globals
6+
)]
7+
#![cfg(feature = "nightly")]
8+
#![feature(abi_vectorcall)]
9+
10+
extern "vectorcall" {
11+
#[link_name = "\u{1}test_vectorcall@@16"]
12+
pub fn test_vectorcall(
13+
a: ::std::os::raw::c_int,
14+
b: ::std::os::raw::c_int,
15+
) -> ::std::os::raw::c_int;
16+
}

tests/headers/win32-vectorcall-1_0.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// bindgen-flags: --rust-target 1.0 -- --target=x86_64-pc-windows-msvc
2+
3+
int __vectorcall test_vectorcall(int a, int b);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// bindgen-flags: --rust-target nightly --raw-line '#![cfg(feature = "nightly")]' --raw-line '#![feature(abi_vectorcall)]' -- --target=x86_64-pc-windows-msvc
2+
3+
int __vectorcall test_vectorcall(int a, int b);

0 commit comments

Comments
 (0)