]> git.lizzy.rs Git - rust.git/commitdiff
Move get_extern_fn and get_res_dtor out of base
authorSimonas Kazlauskas <git@kazlauskas.me>
Sat, 28 Feb 2015 21:55:50 +0000 (23:55 +0200)
committerSimonas Kazlauskas <git@kazlauskas.me>
Fri, 3 Apr 2015 12:48:04 +0000 (15:48 +0300)
These functions have only a single use and functionally belong to foreign and glue respectively
anyway

src/librustc_trans/trans/base.rs
src/librustc_trans/trans/foreign.rs
src/librustc_trans/trans/glue.rs

index 25750b6ec0e14171d03c9982b120ae6b500f7d9d..5dfa84c15d0400dfc3cec60561e9e01864a8f51d 100644 (file)
@@ -54,7 +54,7 @@
 use trans::closure;
 use trans::common::{Block, C_bool, C_bytes_in_context, C_i32, C_int, C_integral};
 use trans::common::{C_null, C_struct_in_context, C_u64, C_u8, C_undef};
-use trans::common::{CrateContext, ExternMap, FunctionContext};
+use trans::common::{CrateContext, FunctionContext};
 use trans::common::{Result, NodeIdAndSpan};
 use trans::common::{node_id_type, return_type_is_void};
 use trans::common::{type_is_immediate, type_is_zero_size, val_ty};
@@ -67,7 +67,6 @@
 use trans::expr;
 use trans::foreign;
 use trans::glue;
-use trans::inline;
 use trans::intrinsic;
 use trans::machine;
 use trans::machine::{llsize_of, llsize_of_real};
@@ -84,7 +83,7 @@
 use util::nodemap::NodeMap;
 
 use arena::TypedArena;
-use libc::{c_uint, uint64_t};
+use libc::c_uint;
 use std::ffi::{CStr, CString};
 use std::cell::{Cell, RefCell};
 use std::collections::HashSet;
@@ -218,23 +217,6 @@ pub fn decl_cdecl_fn(ccx: &CrateContext,
     decl_fn(ccx, name, llvm::CCallConv, ty, ty::FnConverging(output))
 }
 
-// only use this for foreign function ABIs and glue, use `get_extern_rust_fn` for Rust functions
-pub fn get_extern_fn(ccx: &CrateContext,
-                     externs: &mut ExternMap,
-                     name: &str,
-                     cc: llvm::CallConv,
-                     ty: Type,
-                     output: Ty)
-                     -> ValueRef {
-    match externs.get(name) {
-        Some(n) => return *n,
-        None => {}
-    }
-    let f = decl_fn(ccx, name, cc, ty, ty::FnConverging(output));
-    externs.insert(name.to_string(), f);
-    f
-}
-
 fn get_extern_rust_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_ty: Ty<'tcx>,
                                 name: &str, did: ast::DefId) -> ValueRef {
     match ccx.externs().borrow().get(name) {
@@ -400,45 +382,6 @@ pub fn note_unique_llvm_symbol(ccx: &CrateContext, sym: String) {
     ccx.all_llvm_symbols().borrow_mut().insert(sym);
 }
 
-
-pub fn get_res_dtor<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
-                              did: ast::DefId,
-                              t: Ty<'tcx>,
-                              parent_id: ast::DefId,
-                              substs: &Substs<'tcx>)
-                              -> ValueRef {
-    let _icx = push_ctxt("trans_res_dtor");
-    let did = inline::maybe_instantiate_inline(ccx, did);
-
-    if !substs.types.is_empty() {
-        assert_eq!(did.krate, ast::LOCAL_CRATE);
-
-        // Since we're in trans we don't care for any region parameters
-        let substs = ccx.tcx().mk_substs(Substs::erased(substs.types.clone()));
-
-        let (val, _, _) = monomorphize::monomorphic_fn(ccx, did, substs, None);
-
-        val
-    } else if did.krate == ast::LOCAL_CRATE {
-        get_item_val(ccx, did.node)
-    } else {
-        let tcx = ccx.tcx();
-        let name = csearch::get_symbol(&ccx.sess().cstore, did);
-        let class_ty = ty::lookup_item_type(tcx, parent_id).ty.subst(tcx, substs);
-        let llty = type_of_dtor(ccx, class_ty);
-        let dtor_ty = ty::mk_ctor_fn(ccx.tcx(),
-                                     did,
-                                     &[glue::get_drop_glue_type(ccx, t)],
-                                     ty::mk_nil(ccx.tcx()));
-        get_extern_fn(ccx,
-                      &mut *ccx.externs().borrow_mut(),
-                      &name[..],
-                      llvm::CCallConv,
-                      llty,
-                      dtor_ty)
-    }
-}
-
 pub fn bin_op_to_icmp_predicate(ccx: &CrateContext, op: ast::BinOp_, signed: bool)
                                 -> llvm::IntPredicate {
     match op {
index ce80c72b8478533dd63a1b187bbd00ab6eec1324..e0299ba63f5261eb1ab262e1b714ecf8b7ce9d6b 100644 (file)
@@ -165,6 +165,23 @@ pub fn register_static(ccx: &CrateContext,
     }
 }
 
+// only use this for foreign function ABIs and glue, use `get_extern_rust_fn` for Rust functions
+pub fn get_extern_fn(ccx: &CrateContext,
+                     externs: &mut ExternMap,
+                     name: &str,
+                     cc: llvm::CallConv,
+                     ty: Type,
+                     output: Ty)
+                     -> ValueRef {
+    match externs.get(name) {
+        Some(n) => return *n,
+        None => {}
+    }
+    let f = base::decl_fn(ccx, name, cc, ty, ty::FnConverging(output));
+    externs.insert(name.to_string(), f);
+    f
+}
+
 /// Registers a foreign function found in a library. Just adds a LLVM global.
 pub fn register_foreign_item_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
                                           abi: Abi, fty: Ty<'tcx>,
@@ -190,12 +207,7 @@ pub fn register_foreign_item_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
     // Create the LLVM value for the C extern fn
     let llfn_ty = lltype_for_fn_from_foreign_types(ccx, &tys);
 
-    let llfn = base::get_extern_fn(ccx,
-                                   &mut *ccx.externs().borrow_mut(),
-                                   name,
-                                   cc,
-                                   llfn_ty,
-                                   fty);
+    let llfn = get_extern_fn(ccx, &mut *ccx.externs().borrow_mut(), name, cc, llfn_ty, fty);
     add_argument_attributes(&tys, llfn);
 
     llfn
index 32b4d14177c2a050fbd512c4df1b0efe32b09448..898d4216e5a6b6addef3209163d538c38880a5e9 100644 (file)
 
 use back::abi;
 use back::link::*;
-use llvm::{ValueRef, get_param};
 use llvm;
+use llvm::{ValueRef, get_param};
+use metadata::csearch;
 use middle::lang_items::ExchangeFreeFnLangItem;
 use middle::subst;
 use middle::subst::{Subst, Substs};
+use middle::ty::{self, Ty};
 use trans::adt;
 use trans::adt::GetDtorType; // for tcx.dtor_type()
 use trans::base::*;
 use trans::cleanup;
 use trans::cleanup::CleanupMethods;
 use trans::common::*;
+use trans::consts;
 use trans::datum;
 use trans::debuginfo::DebugLoc;
 use trans::expr;
+use trans::foreign;
+use trans::inline;
 use trans::machine::*;
-use trans::type_::Type;
+use trans::monomorphize;
+use trans::tvec;
 use trans::type_of::{type_of, sizing_type_of, align_of};
-use middle::ty::{self, Ty};
-use util::ppaux::{ty_to_short_str, Repr};
+use trans::type_::Type;
 use util::ppaux;
+use util::ppaux::{ty_to_short_str, Repr};
 
 use arena::TypedArena;
 use libc::c_uint;
@@ -259,6 +265,44 @@ fn trans_struct_drop_flag<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
 
 }
 
+pub fn get_res_dtor<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
+                              did: ast::DefId,
+                              t: Ty<'tcx>,
+                              parent_id: ast::DefId,
+                              substs: &Substs<'tcx>)
+                              -> ValueRef {
+    let _icx = push_ctxt("trans_res_dtor");
+    let did = inline::maybe_instantiate_inline(ccx, did);
+
+    if !substs.types.is_empty() {
+        assert_eq!(did.krate, ast::LOCAL_CRATE);
+
+        // Since we're in trans we don't care for any region parameters
+        let substs = ccx.tcx().mk_substs(Substs::erased(substs.types.clone()));
+
+        let (val, _, _) = monomorphize::monomorphic_fn(ccx, did, substs, None);
+
+        val
+    } else if did.krate == ast::LOCAL_CRATE {
+        get_item_val(ccx, did.node)
+    } else {
+        let tcx = ccx.tcx();
+        let name = csearch::get_symbol(&ccx.sess().cstore, did);
+        let class_ty = ty::lookup_item_type(tcx, parent_id).ty.subst(tcx, substs);
+        let llty = type_of_dtor(ccx, class_ty);
+        let dtor_ty = ty::mk_ctor_fn(ccx.tcx(),
+                                     did,
+                                     &[get_drop_glue_type(ccx, t)],
+                                     ty::mk_nil(ccx.tcx()));
+        foreign::get_extern_fn(ccx,
+                      &mut *ccx.externs().borrow_mut(),
+                      &name[..],
+                      llvm::CCallConv,
+                      llty,
+                      dtor_ty)
+    }
+}
+
 fn trans_struct_drop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
                                  t: Ty<'tcx>,
                                  v0: ValueRef,