Skip to content

Commit

Permalink
Added support for vectorcall ABI
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcole1340 committed Mar 12, 2022
1 parent f34e410 commit 4ced3b0
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 7 deletions.
33 changes: 29 additions & 4 deletions src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use self::struct_layout::StructLayoutTracker;

use super::BindgenOptions;

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

if let (Abi::ThisCall, false) =
(signature.abi(), ctx.options().rust_features().thiscall_abi)
{
return;
match (signature.abi(), ctx.options().rust_features()) {
(
Abi::ThisCall,
RustFeatures {
thiscall_abi: false,
..
},
) |
(
Abi::Vectorcall,
RustFeatures {
vectorcall_abi: false,
..
},
) => return,
_ => {}
}

// Do not generate variadic methods, since rust does not allow
Expand Down Expand Up @@ -3867,6 +3880,12 @@ impl TryToRustTy for FunctionSig {
warn!("Skipping function with thiscall ABI that isn't supported by the configured Rust target");
Ok(proc_macro2::TokenStream::new())
}
Abi::Vectorcall
if !ctx.options().rust_features().vectorcall_abi =>
{
warn!("Skipping function with vectorcall ABI that isn't supported by the configured Rust target");
Ok(proc_macro2::TokenStream::new())
}
_ => Ok(quote! {
unsafe extern #abi fn ( #( #arguments ),* ) #ret
}),
Expand Down Expand Up @@ -3958,6 +3977,12 @@ impl CodeGenerator for Function {
warn!("Skipping function with thiscall ABI that isn't supported by the configured Rust target");
return None;
}
Abi::Vectorcall
if !ctx.options().rust_features().vectorcall_abi =>
{
warn!("Skipping function with vectorcall ABI that isn't supported by the configured Rust target");
return None;
}
Abi::Win64 if signature.is_variadic() => {
warn!("Skipping variadic function with Win64 ABI that isn't supported");
return None;
Expand Down
11 changes: 8 additions & 3 deletions src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ macro_rules! rust_target_base {
=> Stable_1_47 => 1.47;
/// Nightly rust
/// * `thiscall` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/42202))
/// * `vectorcall` calling convention (no tracking issue)
=> Nightly => nightly;
);
}
Expand Down Expand Up @@ -234,6 +235,7 @@ rust_feature_def!(
}
Nightly {
=> thiscall_abi;
=> vectorcall_abi;
}
);

Expand All @@ -259,7 +261,8 @@ mod test {
!f_1_0.associated_const &&
!f_1_0.builtin_clone_impls &&
!f_1_0.repr_align &&
!f_1_0.thiscall_abi
!f_1_0.thiscall_abi &&
!f_1_0.vectorcall_abi
);
let f_1_21 = RustFeatures::from(RustTarget::Stable_1_21);
assert!(
Expand All @@ -269,7 +272,8 @@ mod test {
f_1_21.associated_const &&
f_1_21.builtin_clone_impls &&
!f_1_21.repr_align &&
!f_1_21.thiscall_abi
!f_1_21.thiscall_abi &&
!f_1_0.vectorcall_abi
);
let f_nightly = RustFeatures::from(RustTarget::Nightly);
assert!(
Expand All @@ -280,7 +284,8 @@ mod test {
f_nightly.builtin_clone_impls &&
f_nightly.maybe_uninit &&
f_nightly.repr_align &&
f_nightly.thiscall_abi
f_nightly.thiscall_abi &&
f_nightly.vectorcall_abi
);
}

Expand Down
4 changes: 4 additions & 0 deletions src/ir/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ pub enum Abi {
Fastcall,
/// The "thiscall" ABI.
ThisCall,
/// The "vectorcall" ABI.
Vectorcall,
/// The "aapcs" ABI.
Aapcs,
/// The "win64" ABI.
Expand All @@ -203,6 +205,7 @@ impl quote::ToTokens for Abi {
Abi::Stdcall => quote! { "stdcall" },
Abi::Fastcall => quote! { "fastcall" },
Abi::ThisCall => quote! { "thiscall" },
Abi::Vectorcall => quote! { "vectorcall" },
Abi::Aapcs => quote! { "aapcs" },
Abi::Win64 => quote! { "win64" },
Abi::Unknown(cc) => panic!(
Expand Down Expand Up @@ -241,6 +244,7 @@ fn get_abi(cc: CXCallingConv) -> Abi {
CXCallingConv_X86StdCall => Abi::Stdcall,
CXCallingConv_X86FastCall => Abi::Fastcall,
CXCallingConv_X86ThisCall => Abi::ThisCall,
CXCallingConv_X86VectorCall => Abi::Vectorcall,
CXCallingConv_AAPCS => Abi::Aapcs,
CXCallingConv_X86_64Win64 => Abi::Win64,
other => Abi::Unknown(other),
Expand Down
6 changes: 6 additions & 0 deletions tests/expectations/tests/win32-vectorcall-1_0.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#![allow(
dead_code,
non_snake_case,
non_camel_case_types,
non_upper_case_globals
)]
16 changes: 16 additions & 0 deletions tests/expectations/tests/win32-vectorcall-nightly.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#![allow(
dead_code,
non_snake_case,
non_camel_case_types,
non_upper_case_globals
)]
#![cfg(feature = "nightly")]
#![feature(abi_vectorcall)]

extern "vectorcall" {
#[link_name = "\u{1}test_vectorcall@@16"]
pub fn test_vectorcall(
a: ::std::os::raw::c_int,
b: ::std::os::raw::c_int,
) -> ::std::os::raw::c_int;
}
3 changes: 3 additions & 0 deletions tests/headers/win32-vectorcall-1_0.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// bindgen-flags: --rust-target 1.0 -- --target=x86_64-pc-windows-msvc

int __vectorcall test_vectorcall(int a, int b);
3 changes: 3 additions & 0 deletions tests/headers/win32-vectorcall-nightly.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// bindgen-flags: --rust-target nightly --raw-line '#![cfg(feature = "nightly")]' --raw-line '#![feature(abi_vectorcall)]' -- --target=x86_64-pc-windows-msvc

int __vectorcall test_vectorcall(int a, int b);

0 comments on commit 4ced3b0

Please sign in to comment.