diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2018-08-14 19:18:24 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-14 19:18:24 -0400 |
commit | 40d24bb085a1a0bd11f7cf4dd87c52de529302ca (patch) | |
tree | 79a015d785f110b572fad85cd7aed70e3f50b260 /src/codegen | |
parent | bb6a1205a0e81271bf90aec33d33e2e3ca0ae7d1 (diff) | |
parent | 6e7d9bebd8c95a8ca7088cf02c17aea811d20783 (diff) |
Auto merge of #1366 - gnzlbg:vec, r=emiliov0.38.0
Map vector types to arrays and pass them by value
This PR maps vector types to arrays and passes them by value (that is, they are passed to C as `[T; N]`. This already allows defining them as a blacklisted opaque type, such that the user can provide its own definition from e.g. `std::arch`.
A subsequent PR should map vector types to unit structs with a private member:
```rust
#[repr(align(16))] pub struct __m128([f32; 4]);
```
to make their alignment at least be correct. This should allow transmuting `std::arch` types to these types properly.
Once that is done, we probably want to detect the canonical vector types (e.g. `__m128`) and pull in the type from `std`/`core`::arch instead.
Diffstat (limited to 'src/codegen')
-rw-r--r-- | src/codegen/impl_debug.rs | 9 | ||||
-rw-r--r-- | src/codegen/impl_partialeq.rs | 7 | ||||
-rw-r--r-- | src/codegen/mod.rs | 3 |
3 files changed, 18 insertions, 1 deletions
diff --git a/src/codegen/impl_debug.rs b/src/codegen/impl_debug.rs index ab934ed6..0842d849 100644 --- a/src/codegen/impl_debug.rs +++ b/src/codegen/impl_debug.rs @@ -197,6 +197,15 @@ impl<'a> ImplDebug<'a> for Item { )) } } + TypeKind::Vector(_, len) => { + let self_ids = 0..len; + Some(( + format!("{}({{}})", name), + vec![quote! { + #(format!("{:?}", self.#self_ids)),* + }] + )) + } TypeKind::ResolvedTypeRef(t) | TypeKind::TemplateAlias(t, _) | diff --git a/src/codegen/impl_partialeq.rs b/src/codegen/impl_partialeq.rs index a05c65e7..66565db6 100644 --- a/src/codegen/impl_partialeq.rs +++ b/src/codegen/impl_partialeq.rs @@ -115,6 +115,13 @@ fn gen_field(ctx: &BindgenContext, ty_item: &Item, name: &str) -> quote::Tokens &self. #name_ident [..] == &other. #name_ident [..] } }, + TypeKind::Vector(_, len) => { + let self_ids = 0..len; + let other_ids = 0..len; + quote! { + #(self.#self_ids == other.#other_ids &&)* true + } + }, TypeKind::ResolvedTypeRef(t) | TypeKind::TemplateAlias(t, _) | diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index cdf0134a..f596ddda 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -595,6 +595,7 @@ impl CodeGenerator for Type { TypeKind::Float(..) | TypeKind::Complex(..) | TypeKind::Array(..) | + TypeKind::Vector(..) | TypeKind::Pointer(..) | TypeKind::BlockPointer | TypeKind::Reference(..) | @@ -3050,7 +3051,7 @@ impl TryToRustTy for Type { ::#prefix::option::Option<#ty> }) } - TypeKind::Array(item, len) => { + TypeKind::Array(item, len) | TypeKind::Vector(item, len) => { let ty = item.try_to_rust_ty(ctx, &())?; Ok(quote! { [ #ty ; #len ] |