提交 755850f3 编写于 作者: M Mark-Simulacrum 提交者: Mark Simulacrum

Merge OwnedBuilder and Builder

上级 8ed11209
......@@ -32,6 +32,14 @@ pub struct Builder<'a, 'tcx: 'a> {
pub ccx: &'a CrateContext<'a, 'tcx>,
}
impl<'blk, 'tcx> Drop for Builder<'blk, 'tcx> {
fn drop(&mut self) {
unsafe {
llvm::LLVMDisposeBuilder(self.llbuilder);
}
}
}
// This is a really awful way to get a zero-length c-string, but better (and a
// lot more efficient) than doing str::as_c_str("", ...) every time.
pub fn noname() -> *const c_char {
......@@ -40,9 +48,13 @@ pub fn noname() -> *const c_char {
}
impl<'a, 'tcx> Builder<'a, 'tcx> {
pub fn new(ccx: &'a CrateContext<'a, 'tcx>) -> Builder<'a, 'tcx> {
pub fn with_ccx(ccx: &'a CrateContext<'a, 'tcx>) -> Self {
// Create a fresh builder from the crate context.
let llbuilder = unsafe {
llvm::LLVMCreateBuilderInContext(ccx.llcx())
};
Builder {
llbuilder: ccx.raw_builder(),
llbuilder: llbuilder,
ccx: ccx,
}
}
......
......@@ -306,7 +306,7 @@ pub struct FunctionContext<'a, 'tcx: 'a> {
// Used and maintained by the debuginfo module.
pub debug_context: debuginfo::FunctionDebugContext,
alloca_builder: OwnedBuilder<'a, 'tcx>,
alloca_builder: Builder<'a, 'tcx>,
}
impl<'a, 'tcx> FunctionContext<'a, 'tcx> {
......@@ -359,13 +359,13 @@ pub fn new(
param_substs: param_substs,
ccx: ccx,
debug_context: debug_context,
alloca_builder: OwnedBuilder::new_with_ccx(ccx),
alloca_builder: Builder::with_ccx(ccx),
};
let val = {
let entry_bcx = fcx.build_new_block("entry-block");
let val = entry_bcx.load(C_null(Type::i8p(ccx)));
fcx.alloca_builder.builder.position_at_start(entry_bcx.llbb());
fcx.alloca_builder.position_at_start(entry_bcx.llbb());
val
};
......@@ -509,7 +509,7 @@ pub fn eh_unwind_resume(&self) -> Callee<'tcx> {
}
pub fn alloca(&self, ty: Type, name: &str) -> ValueRef {
self.alloca_builder.builder.dynamic_alloca(ty, name)
self.alloca_builder.dynamic_alloca(ty, name)
}
}
......@@ -521,33 +521,6 @@ fn drop(&mut self) {
}
}
pub struct OwnedBuilder<'blk, 'tcx: 'blk> {
builder: Builder<'blk, 'tcx>
}
impl<'blk, 'tcx> OwnedBuilder<'blk, 'tcx> {
pub fn new_with_ccx(ccx: &'blk CrateContext<'blk, 'tcx>) -> Self {
// Create a fresh builder from the crate context.
let llbuilder = unsafe {
llvm::LLVMCreateBuilderInContext(ccx.llcx())
};
OwnedBuilder {
builder: Builder {
llbuilder: llbuilder,
ccx: ccx,
}
}
}
}
impl<'blk, 'tcx> Drop for OwnedBuilder<'blk, 'tcx> {
fn drop(&mut self) {
unsafe {
llvm::LLVMDisposeBuilder(self.builder.llbuilder);
}
}
}
#[must_use]
pub struct BlockAndBuilder<'blk, 'tcx: 'blk> {
// The BasicBlockRef returned from a call to
......@@ -561,18 +534,18 @@ pub struct BlockAndBuilder<'blk, 'tcx: 'blk> {
// attached.
fcx: &'blk FunctionContext<'blk, 'tcx>,
owned_builder: OwnedBuilder<'blk, 'tcx>,
builder: Builder<'blk, 'tcx>,
}
impl<'blk, 'tcx> BlockAndBuilder<'blk, 'tcx> {
pub fn new(llbb: BasicBlockRef, fcx: &'blk FunctionContext<'blk, 'tcx>) -> Self {
let owned_builder = OwnedBuilder::new_with_ccx(fcx.ccx);
let builder = Builder::with_ccx(fcx.ccx);
// Set the builder's position to this block's end.
owned_builder.builder.position_at_end(llbb);
builder.position_at_end(llbb);
BlockAndBuilder {
llbb: llbb,
fcx: fcx,
owned_builder: owned_builder,
builder: builder,
}
}
......@@ -610,7 +583,7 @@ pub fn llbb(&self) -> BasicBlockRef {
impl<'blk, 'tcx> Deref for BlockAndBuilder<'blk, 'tcx> {
type Target = Builder<'blk, 'tcx>;
fn deref(&self) -> &Self::Target {
&self.owned_builder.builder
&self.builder
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册