summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-10-10 12:41:38 -0500
committerGitHub <noreply@github.com>2017-10-10 12:41:38 -0500
commitc744e684470f6b54c4f77ce9ba27f7ce74df892d (patch)
tree344b3d0c2b80089c3ccbd1607e8dfd094d514ade /src
parent5dbdadc5cc1d15e23d804b4d0ce80cae90338ef7 (diff)
parent9b95ce6a76d32a1c152bd3719d6cf46dd872b630 (diff)
Auto merge of #1065 - liranringel:thiscall, r=fitzgen
Add support for the thiscall ABI Fixes https://github.com/rust-lang-nursery/rust-bindgen/issues/541 The thiscall ABI is experimental, so in order to use it nightly is required and also the following statement: `#![feature(abi_thiscall)]` That's a problem because the `tests_expectations` crate (in the tests folder) tries to compile it (and stable is required).
Diffstat (limited to 'src')
-rw-r--r--src/codegen/mod.rs22
-rw-r--r--src/features.rs3
-rw-r--r--src/ir/function.rs4
3 files changed, 26 insertions, 3 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index 94a62b97..6d8e8a9d 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -1959,6 +1959,10 @@ impl MethodCodegen for Method {
_ => panic!("How in the world?"),
};
+ if let (Abi::ThisCall, false) = (signature.abi(), ctx.options().rust_features().thiscall_abi()) {
+ return;
+ }
+
// Do not generate variadic methods, since rust does not allow
// implementing them, and we don't do a good job at it anyway.
if signature.is_variadic() {
@@ -3072,9 +3076,17 @@ impl TryToRustTy for FunctionSig {
let arguments = utils::fnsig_arguments(ctx, &self);
let abi = self.abi();
- Ok(quote! {
- unsafe extern #abi fn ( #( #arguments ),* ) #ret
- })
+ match abi {
+ Abi::ThisCall if !ctx.options().rust_features().thiscall_abi() => {
+ warn!("Skipping function with thiscall ABI that isn't supported by the configured Rust target");
+ Ok(quote::Tokens::new())
+ }
+ _ => {
+ Ok(quote! {
+ unsafe extern #abi fn ( #( #arguments ),* ) #ret
+ })
+ }
+ }
}
}
@@ -3146,6 +3158,10 @@ impl CodeGenerator for Function {
}
let abi = match signature.abi() {
+ Abi::ThisCall if !ctx.options().rust_features().thiscall_abi() => {
+ warn!("Skipping function with thiscall ABI that isn't supported by the configured Rust target");
+ return;
+ }
Abi::Unknown(unknown_abi) => {
panic!(
"Invalid or unknown abi {:?} for function {:?} ({:?})",
diff --git a/src/features.rs b/src/features.rs
index 29e60ab7..b89185fd 100644
--- a/src/features.rs
+++ b/src/features.rs
@@ -140,6 +140,8 @@ rust_feature_def!(
=> untagged_union;
/// Constant function ([RFC 911](https://github.com/rust-lang/rfcs/blob/master/text/0911-const-fn.md))
=> const_fn;
+ /// `thiscall` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/42202))
+ => thiscall_abi;
);
impl From<RustTarget> for RustFeatures {
@@ -152,6 +154,7 @@ impl From<RustTarget> for RustFeatures {
if rust_target >= RustTarget::Nightly {
features.const_fn = true;
+ features.thiscall_abi = true;
}
features
diff --git a/src/ir/function.rs b/src/ir/function.rs
index b637f9f1..2eab6638 100644
--- a/src/ir/function.rs
+++ b/src/ir/function.rs
@@ -142,6 +142,8 @@ pub enum Abi {
Stdcall,
/// The "fastcall" ABI.
Fastcall,
+ /// The "thiscall" ABI.
+ ThisCall,
/// The "aapcs" ABI.
Aapcs,
/// The "win64" ABI.
@@ -166,6 +168,7 @@ impl quote::ToTokens for Abi {
Abi::C => quote! { "C" },
Abi::Stdcall => quote! { "stdcall" },
Abi::Fastcall => quote! { "fastcall" },
+ Abi::ThisCall => quote! { "thiscall" },
Abi::Aapcs => quote! { "aapcs" },
Abi::Win64 => quote! { "win64" },
Abi::Unknown(cc) => panic!(
@@ -200,6 +203,7 @@ fn get_abi(cc: CXCallingConv) -> Abi {
CXCallingConv_C => Abi::C,
CXCallingConv_X86StdCall => Abi::Stdcall,
CXCallingConv_X86FastCall => Abi::Fastcall,
+ CXCallingConv_X86ThisCall => Abi::ThisCall,
CXCallingConv_AAPCS => Abi::Aapcs,
CXCallingConv_X86_64Win64 => Abi::Win64,
other => Abi::Unknown(other),