mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
Merge OwnedBuilder and Builder
This commit is contained in:
parent
8ed11209d6
commit
755850f318
@ -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 @@ impl<'a, 'tcx> FunctionContext<'a, 'tcx> {
|
||||
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 @@ impl<'a, 'tcx> FunctionContext<'a, '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 @@ impl<'a, 'tcx> Drop for FunctionContext<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ impl<'blk, 'tcx> BlockAndBuilder<'blk, 'tcx> {
|
||||
impl<'blk, 'tcx> Deref for BlockAndBuilder<'blk, 'tcx> {
|
||||
type Target = Builder<'blk, 'tcx>;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.owned_builder.builder
|
||||
&self.builder
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user