X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibrustc_trans%2Fcontext.rs;h=8c6bd302e4bfdb51fd495938024285a04b8ba25c;hb=6f4ab9458a7ad06c8ce630604f533c8c0c0acef4;hp=6266452419ed9b035a32ab66603f8e5a118c2ccd;hpb=14526a37449e5943bf582990979d9d87afc5ec86;p=rust.git diff --git a/src/librustc_trans/context.rs b/src/librustc_trans/context.rs index 6266452419e..8c6bd302e4b 100644 --- a/src/librustc_trans/context.rs +++ b/src/librustc_trans/context.rs @@ -16,25 +16,28 @@ use rustc::traits; use debuginfo; use callee; +use back::symbol_export::ExportedSymbols; use base; use declare; use monomorphize::Instance; use partitioning::CodegenUnit; +use trans_item::TransItem; use type_::Type; use rustc_data_structures::base_n; -use rustc::session::config::{self, NoDebugInfo}; +use rustc::session::config::{self, NoDebugInfo, OutputFilenames}; use rustc::session::Session; use rustc::ty::subst::Substs; use rustc::ty::{self, Ty, TyCtxt}; use rustc::ty::layout::{LayoutCx, LayoutError, LayoutTyper, TyLayout}; -use rustc::util::nodemap::{NodeSet, DefIdMap, FxHashMap}; +use rustc::util::nodemap::{DefIdMap, FxHashMap, FxHashSet}; use std::ffi::{CStr, CString}; use std::cell::{Cell, RefCell}; use std::ptr; use std::iter; use std::str; +use std::sync::Arc; use std::marker::PhantomData; use syntax::ast; use syntax::symbol::InternedString; @@ -76,11 +79,12 @@ pub fn extend(&mut self, stats: Stats) { /// crate, so it must not contain references to any LLVM data structures /// (aside from metadata-related ones). pub struct SharedCrateContext<'a, 'tcx: 'a> { - exported_symbols: NodeSet, tcx: TyCtxt<'a, 'tcx, 'tcx>, check_overflow: bool, use_dll_storage_attrs: bool, + + output_filenames: &'a OutputFilenames, } /// The local portion of a `CrateContext`. There is one `LocalCrateContext` @@ -92,6 +96,13 @@ pub struct LocalCrateContext<'a, 'tcx: 'a> { llcx: ContextRef, stats: Stats, codegen_unit: CodegenUnit<'tcx>, + + /// The translation items of the whole crate. + crate_trans_items: Arc>>, + + /// Information about which symbols are exported from the crate. + exported_symbols: Arc, + /// Cache instances of monomorphic and polymorphic items instances: RefCell, ValueRef>>, /// Cache generated vtables @@ -263,8 +274,8 @@ pub unsafe fn create_context_and_module(sess: &Session, mod_name: &str) -> (Cont impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> { pub fn new(tcx: TyCtxt<'b, 'tcx, 'tcx>, - exported_symbols: NodeSet, - check_overflow: bool) + check_overflow: bool, + output_filenames: &'b OutputFilenames) -> SharedCrateContext<'b, 'tcx> { // An interesting part of Windows which MSVC forces our hand on (and // apparently MinGW didn't) is the usage of `dllimport` and `dllexport` @@ -312,10 +323,10 @@ pub fn new(tcx: TyCtxt<'b, 'tcx, 'tcx>, let use_dll_storage_attrs = tcx.sess.target.target.options.is_like_msvc; SharedCrateContext { - exported_symbols: exported_symbols, - tcx: tcx, - check_overflow: check_overflow, - use_dll_storage_attrs: use_dll_storage_attrs, + tcx, + check_overflow, + use_dll_storage_attrs, + output_filenames, } } @@ -331,10 +342,6 @@ pub fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool { ty.is_freeze(self.tcx, ty::ParamEnv::empty(traits::Reveal::All), DUMMY_SP) } - pub fn exported_symbols<'a>(&'a self) -> &'a NodeSet { - &self.exported_symbols - } - pub fn tcx<'a>(&'a self) -> TyCtxt<'a, 'tcx, 'tcx> { self.tcx } @@ -350,11 +357,17 @@ pub fn dep_graph<'a>(&'a self) -> &'a DepGraph { pub fn use_dll_storage_attrs(&self) -> bool { self.use_dll_storage_attrs } + + pub fn output_filenames(&self) -> &OutputFilenames { + self.output_filenames + } } impl<'a, 'tcx> LocalCrateContext<'a, 'tcx> { pub fn new(shared: &SharedCrateContext<'a, 'tcx>, - codegen_unit: CodegenUnit<'tcx>) + codegen_unit: CodegenUnit<'tcx>, + crate_trans_items: Arc>>, + exported_symbols: Arc,) -> LocalCrateContext<'a, 'tcx> { unsafe { // Append ".rs" to LLVM module identifier. @@ -382,10 +395,12 @@ pub fn new(shared: &SharedCrateContext<'a, 'tcx>, }; let local_ccx = LocalCrateContext { - llmod: llmod, - llcx: llcx, + llmod, + llcx, stats: Stats::default(), - codegen_unit: codegen_unit, + codegen_unit, + crate_trans_items, + exported_symbols, instances: RefCell::new(FxHashMap()), vtables: RefCell::new(FxHashMap()), const_cstr_cache: RefCell::new(FxHashMap()), @@ -401,7 +416,7 @@ pub fn new(shared: &SharedCrateContext<'a, 'tcx>, int_type: Type::from_ref(ptr::null_mut()), opaque_vec_type: Type::from_ref(ptr::null_mut()), str_slice_type: Type::from_ref(ptr::null_mut()), - dbg_cx: dbg_cx, + dbg_cx, eh_personality: Cell::new(None), eh_unwind_resume: Cell::new(None), rust_try_fn: Cell::new(None), @@ -447,7 +462,7 @@ fn dummy_ccx(shared: &'a SharedCrateContext<'a, 'tcx>, -> CrateContext<'a, 'tcx> { assert!(local_ccxs.len() == 1); CrateContext { - shared: shared, + shared, local_ccx: &local_ccxs[0] } } @@ -496,6 +511,14 @@ pub fn codegen_unit(&self) -> &CodegenUnit<'tcx> { &self.local().codegen_unit } + pub fn crate_trans_items(&self) -> &FxHashSet> { + &self.local().crate_trans_items + } + + pub fn exported_symbols(&self) -> &ExportedSymbols { + &self.local().exported_symbols + } + pub fn td(&self) -> llvm::TargetDataRef { unsafe { llvm::LLVMRustGetModuleDataLayout(self.llmod()) } }