diff options
author | Nick Fitzgerald <fitzgen@gmail.com> | 2016-11-10 10:39:24 -0800 |
---|---|---|
committer | Nick Fitzgerald <fitzgen@gmail.com> | 2016-11-11 10:10:29 -0800 |
commit | 53f7a50e2e4f5ef4784e005dee1e00089a7d4ec8 (patch) | |
tree | 14c3e7330b459a041c6d35071d08c760ea0f6e8a | |
parent | 8d83bdfb48e292abd7db5a3093aefce0c893d3a5 (diff) |
Add rudimentary support for `__float128`
This adds `__float128` as a builtin type, and generates an opaque array
of 16 `u8`s to represent it in the generated bindings since Rust doesn't
have an `f128` type.
Context and motivation: Somehow `__float128` is getting pulled into
SpiderMonkey headers from somewhere, and the lack of `__float128`
support was causing bindgen to hard fail in bindings generation.
-rw-r--r-- | src/clangll.rs | 1 | ||||
-rwxr-xr-x | src/codegen/mod.rs | 35 | ||||
-rw-r--r-- | src/ir/context.rs | 1 | ||||
-rw-r--r-- | src/ir/ty.rs | 7 | ||||
-rw-r--r-- | tests/expectations/tests/float128.rs | 7 | ||||
-rw-r--r-- | tests/headers/float128.hpp | 13 |
6 files changed, 43 insertions, 21 deletions
diff --git a/src/clangll.rs b/src/clangll.rs index b89c0756..b9743117 100644 --- a/src/clangll.rs +++ b/src/clangll.rs @@ -392,6 +392,7 @@ pub const CXType_Dependent: c_uint = 26; pub const CXType_ObjCId: c_uint = 27; pub const CXType_ObjCClass: c_uint = 28; pub const CXType_ObjCSel: c_uint = 29; +pub const CXType_Float128: c_uint = 30; pub const CXType_FirstBuiltin: c_uint = 2; pub const CXType_LastBuiltin: c_uint = 29; pub const CXType_Complex: c_uint = 100; diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 5e68da14..3bee69b6 100755 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -1609,27 +1609,22 @@ impl ToRustTy for Type { } } TypeKind::Float(fk) => { + // TODO: we probably should just take the type layout into + // account? + // + // Also, maybe this one shouldn't be the default? + // + // FIXME: `c_longdouble` doesn't seem to be defined in some + // systems, so we use `c_double` directly. use ir::ty::FloatKind; - if ctx.options().convert_floats { - // TODO: we probably should just take the type layout into - // account? - // - // Also, maybe this one shouldn't be the default? - match fk { - FloatKind::Float => aster::ty::TyBuilder::new().f32(), - FloatKind::Double | FloatKind::LongDouble => { - aster::ty::TyBuilder::new().f64() - } - } - } else { - // FIXME: `c_longdouble` doesn't seem to be defined in some - // systems, so we use `c_double` directly. - match fk { - FloatKind::Float => raw!(c_float), - FloatKind::Double | FloatKind::LongDouble => { - raw!(c_double) - } - } + match (fk, ctx.options().convert_floats) { + (FloatKind::Float, true) => aster::ty::TyBuilder::new().f32(), + (FloatKind::Double, true) | + (FloatKind::LongDouble, true) => aster::ty::TyBuilder::new().f64(), + (FloatKind::Float, false) => raw!(c_float), + (FloatKind::Double, false) | + (FloatKind::LongDouble, false) => raw!(c_double), + (FloatKind::Float128, _) => aster::ty::TyBuilder::new().array(16).u8(), } } TypeKind::Function(ref fs) => { diff --git a/src/ir/context.rs b/src/ir/context.rs index 00ece529..92c6fb49 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -697,6 +697,7 @@ impl<'ctx> BindgenContext<'ctx> { CXType_Float => TypeKind::Float(FloatKind::Float), CXType_Double => TypeKind::Float(FloatKind::Double), CXType_LongDouble => TypeKind::Float(FloatKind::LongDouble), + CXType_Float128 => TypeKind::Float(FloatKind::Float128), _ => return None, }; diff --git a/src/ir/ty.rs b/src/ir/ty.rs index 77dc61be..5a72eb22 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -363,6 +363,8 @@ pub enum FloatKind { Double, /// A `long double`. LongDouble, + /// A `__float128`. + Float128, } /// The different kinds of types that we can parse. @@ -771,7 +773,10 @@ impl Type { ctx); } _ => { - error!("unsupported type {:?} at {:?}", ty, location); + error!("unsupported type: kind = {:?}; ty = {:?}; at {:?}", + ty.kind(), + ty, + location); return Err(ParseError::Continue); } }; diff --git a/tests/expectations/tests/float128.rs b/tests/expectations/tests/float128.rs new file mode 100644 index 00000000..b4b7b2bc --- /dev/null +++ b/tests/expectations/tests/float128.rs @@ -0,0 +1,7 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + + diff --git a/tests/headers/float128.hpp b/tests/headers/float128.hpp new file mode 100644 index 00000000..f554e88e --- /dev/null +++ b/tests/headers/float128.hpp @@ -0,0 +1,13 @@ +// FIXME: libclang < 3.9 does not expose `__float128` in its interface, so this +// test will fail. Once we remove support for `--features llvm_stable` and +// require libclang >= 3.9, we can reenable this test. +// +// static __float128 global = 1.0; + +// FIXME: We have no way to get 128 bit aligned structs in Rust at the moment, +// and therefore the generated layout tests for this struct will fail. When we +// can enforce 128 bit alignment, we can re-enable this test. +// +// struct A { +// __float128 f; +// }; |