about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMark-Simulacrum <mark.simulacrum@gmail.com>2016-12-16 17:39:35 -0700
committerMark Simulacrum <mark.simulacrum@gmail.com>2016-12-20 20:03:27 -0700
commit755850f31863d19b22083eaa2bbdc2c495f0b072 (patch)
treeae8926721b2d5d7988375526892b5e63d253f8ee /src
parent8ed11209d6f7ae0ca8ea21a1ffed902345a4217f (diff)
downloadrust-755850f31863d19b22083eaa2bbdc2c495f0b072.tar.gz
rust-755850f31863d19b22083eaa2bbdc2c495f0b072.zip
Merge OwnedBuilder and Builder
Diffstat (limited to 'src')
-rw-r--r--src/librustc_trans/builder.rs16
-rw-r--r--src/librustc_trans/common.rs45
2 files changed, 23 insertions, 38 deletions
diff --git a/src/librustc_trans/builder.rs b/src/librustc_trans/builder.rs
index 8c6a53da0e1..b710c08e1a4 100644
--- a/src/librustc_trans/builder.rs
+++ b/src/librustc_trans/builder.rs
@@ -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,
         }
     }
diff --git a/src/librustc_trans/common.rs b/src/librustc_trans/common.rs
index 610c4cfd108..d09cb8ce2c8 100644
--- a/src/librustc_trans/common.rs
+++ b/src/librustc_trans/common.rs
@@ -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
     }
 }