]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/middle/trans/common.rs
auto merge of #15999 : Kimundi/rust/fix_folder, r=nikomatsakis
[rust.git] / src / librustc / middle / trans / common.rs
index 23a391cb86dfefd35e534603313cee49f4f8d4da..71ddc2e40459c241ff48727876e23d99e7ac98b0 100644 (file)
 //! Code that is useful in various trans modules.
 
 use driver::session::Session;
-use lib::llvm::{ValueRef, BasicBlockRef, BuilderRef};
-use lib::llvm::{True, False, Bool};
-use lib::llvm::llvm;
-use lib;
+use llvm;
+use llvm::{ValueRef, BasicBlockRef, BuilderRef};
+use llvm::{True, False, Bool};
 use middle::def;
 use middle::lang_items::LangItem;
 use middle::subst;
@@ -72,7 +71,8 @@ pub fn type_is_immediate(ccx: &CrateContext, ty: ty::t) -> bool {
     }
     match ty::get(ty).sty {
         ty::ty_bot => true,
-        ty::ty_struct(..) | ty::ty_enum(..) | ty::ty_tup(..) => {
+        ty::ty_struct(..) | ty::ty_enum(..) | ty::ty_tup(..) |
+        ty::ty_unboxed_closure(..) => {
             let llty = sizing_type_of(ccx, ty);
             llsize_of_alloc(ccx, llty) <= llsize_of_alloc(ccx, ccx.int_type)
         }
@@ -221,6 +221,12 @@ fn substp(&self, tcx: &ty::ctxt, substs: &param_substs) -> T {
 pub type RvalueDatum = datum::Datum<datum::Rvalue>;
 pub type LvalueDatum = datum::Datum<datum::Lvalue>;
 
+#[deriving(Clone, Eq, PartialEq)]
+pub enum HandleItemsFlag {
+    IgnoreItems,
+    TranslateItems,
+}
+
 // Function context.  Every LLVM function we create will have one of
 // these.
 pub struct FunctionContext<'a> {
@@ -289,6 +295,9 @@ pub struct FunctionContext<'a> {
 
     // Cleanup scopes.
     pub scopes: RefCell<Vec<cleanup::CleanupScope<'a>> >,
+
+    // How to handle items encountered during translation of this function.
+    pub handle_items: HandleItemsFlag,
 }
 
 impl<'a> FunctionContext<'a> {
@@ -570,7 +579,7 @@ pub fn C_cstr(cx: &CrateContext, s: InternedString, null_terminated: bool) -> Va
         });
         llvm::LLVMSetInitializer(g, sc);
         llvm::LLVMSetGlobalConstant(g, True);
-        lib::llvm::SetLinkage(g, lib::llvm::InternalLinkage);
+        llvm::SetLinkage(g, llvm::InternalLinkage);
 
         cx.const_cstr_cache.borrow_mut().insert(s, g);
         g
@@ -599,7 +608,7 @@ pub fn C_binary_slice(cx: &CrateContext, data: &[u8]) -> ValueRef {
         });
         llvm::LLVMSetInitializer(g, lldata);
         llvm::LLVMSetGlobalConstant(g, True);
-        lib::llvm::SetLinkage(g, lib::llvm::InternalLinkage);
+        llvm::SetLinkage(g, llvm::InternalLinkage);
 
         let cs = llvm::LLVMConstPointerCast(g, Type::i8p(cx).to_ref());
         C_struct(cx, [cs, C_uint(cx, len)], false)
@@ -633,12 +642,6 @@ pub fn C_bytes(ccx: &CrateContext, bytes: &[u8]) -> ValueRef {
     }
 }
 
-pub fn get_param(fndecl: ValueRef, param: uint) -> ValueRef {
-    unsafe {
-        llvm::LLVMGetParam(fndecl, param as c_uint)
-    }
-}
-
 pub fn const_get_elt(cx: &CrateContext, v: ValueRef, us: &[c_uint])
                   -> ValueRef {
     unsafe {
@@ -793,6 +796,9 @@ pub fn resolve_vtable_under_param_substs(tcx: &ty::ctxt,
         typeck::vtable_param(n_param, n_bound) => {
             find_vtable(tcx, param_substs, n_param, n_bound)
         }
+        typeck::vtable_unboxed_closure(def_id) => {
+            typeck::vtable_unboxed_closure(def_id)
+        }
         typeck::vtable_error => typeck::vtable_error
     }
 }