use std::ffi::CString;
use std::ops::Range;
use std::ptr;
-use std::ptr::NonNull;
// All Builders must have an llfn associated with them
#[must_use]
args: &[&'ll Value],
then: &'ll BasicBlock,
catch: &'ll BasicBlock,
- bundle: Option<&OperandBundleDef>) -> &'ll Value {
+ bundle: Option<&OperandBundleDef<'ll>>) -> &'ll Value {
self.count_insn("invoke");
debug!("Invoke {:?} with args ({:?})",
args);
let args = self.check_call("invoke", llfn, args);
- let bundle = bundle.as_ref().and_then(|b| NonNull::new(b.raw()));
+ let bundle = bundle.map(|b| &*b.raw);
unsafe {
llvm::LLVMRustBuildInvoke(self.llbuilder,
}
pub fn call(&self, llfn: &'ll Value, args: &[&'ll Value],
- bundle: Option<&OperandBundleDef>) -> &'ll Value {
+ bundle: Option<&OperandBundleDef<'ll>>) -> &'ll Value {
self.count_insn("call");
debug!("Call {:?} with args ({:?})",
args);
let args = self.check_call("call", llfn, args);
- let bundle = bundle.as_ref().and_then(|b| NonNull::new(b.raw()));
+ let bundle = bundle.map(|b| &*b.raw);
unsafe {
llvm::LLVMRustBuildCall(self.llbuilder, llfn, args.as_ptr(),
/// the `OperandBundleDef` value created for MSVC landing pads.
pub struct Funclet<'ll> {
cleanuppad: &'ll Value,
- operand: OperandBundleDef,
+ operand: OperandBundleDef<'ll>,
}
impl Funclet<'ll> {
self.cleanuppad
}
- pub fn bundle(&self) -> &OperandBundleDef {
+ pub fn bundle(&self) -> &OperandBundleDef<'ll> {
&self.operand
}
}
use libc::{c_uint, c_int, size_t, c_char};
use libc::{c_ulonglong, c_void};
+use std::marker::PhantomData;
use std::ptr::NonNull;
use super::RustString;
LocalExec
}
+extern { type Opaque; }
+struct InvariantOpaque<'a> {
+ _marker: PhantomData<&'a mut &'a ()>,
+ _opaque: Opaque,
+}
+
// Opaque pointer types
extern { pub type Module; }
extern { pub type Context; }
extern { pub type SMDiagnostic; }
extern { pub type RustArchiveMember; }
pub type RustArchiveMemberRef = *mut RustArchiveMember;
-extern { pub type OperandBundleDef; }
-pub type OperandBundleDefRef = *mut OperandBundleDef;
+pub struct OperandBundleDef<'a>(InvariantOpaque<'a>);
extern { pub type Linker; }
pub type LinkerRef = *mut Linker;
NumArgs: c_uint,
Then: &'a BasicBlock,
Catch: &'a BasicBlock,
- Bundle: Option<NonNull<OperandBundleDef>>,
+ Bundle: Option<&OperandBundleDef<'a>>,
Name: *const c_char)
-> &'a Value;
pub fn LLVMBuildLandingPad(B: &'a Builder,
Fn: &'a Value,
Args: *const &'a Value,
NumArgs: c_uint,
- Bundle: Option<NonNull<OperandBundleDef>>,
+ Bundle: Option<&OperandBundleDef<'a>>,
Name: *const c_char)
-> &'a Value;
pub fn LLVMBuildSelect(B: &'a Builder,
pub fn LLVMRustSetDataLayoutFromTargetMachine(M: &'a Module, TM: &'a TargetMachine);
pub fn LLVMRustBuildOperandBundleDef(Name: *const c_char,
- Inputs: *const &Value,
+ Inputs: *const &'a Value,
NumInputs: c_uint)
- -> OperandBundleDefRef;
- pub fn LLVMRustFreeOperandBundleDef(Bundle: OperandBundleDefRef);
+ -> &'a mut OperandBundleDef<'a>;
+ pub fn LLVMRustFreeOperandBundleDef(Bundle: &'a mut OperandBundleDef<'a>);
pub fn LLVMRustPositionBuilderAtStart(B: &'a Builder, BB: &'a BasicBlock);
}
}
-pub struct OperandBundleDef {
- inner: OperandBundleDefRef,
+pub struct OperandBundleDef<'a> {
+ pub raw: &'a mut ffi::OperandBundleDef<'a>,
}
-impl OperandBundleDef {
- pub fn new(name: &str, vals: &[&'a Value]) -> OperandBundleDef {
+impl OperandBundleDef<'a> {
+ pub fn new(name: &str, vals: &[&'a Value]) -> Self {
let name = CString::new(name).unwrap();
let def = unsafe {
LLVMRustBuildOperandBundleDef(name.as_ptr(), vals.as_ptr(), vals.len() as c_uint)
};
- OperandBundleDef { inner: def }
- }
-
- pub fn raw(&self) -> OperandBundleDefRef {
- self.inner
+ OperandBundleDef { raw: def }
}
}
-impl Drop for OperandBundleDef {
+impl Drop for OperandBundleDef<'a> {
fn drop(&mut self) {
unsafe {
- LLVMRustFreeOperandBundleDef(self.inner);
+ LLVMRustFreeOperandBundleDef(&mut *(self.raw as *mut _));
}
}
}