2013-06-13 02:19:50 -05:00
|
|
|
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2013-06-12 21:02:33 -05:00
|
|
|
|
|
|
|
use driver::session;
|
2014-03-05 02:51:47 -06:00
|
|
|
use driver::session::NoDebugInfo;
|
2013-06-16 05:52:44 -05:00
|
|
|
use lib::llvm::{ContextRef, ModuleRef, ValueRef};
|
2013-06-12 21:49:01 -05:00
|
|
|
use lib::llvm::{llvm, TargetData, TypeNames};
|
2013-08-11 20:12:57 -05:00
|
|
|
use lib::llvm::mk_target_data;
|
2013-06-12 21:02:33 -05:00
|
|
|
use metadata::common::LinkMeta;
|
|
|
|
use middle::astencode;
|
|
|
|
use middle::resolve;
|
|
|
|
use middle::trans::adt;
|
|
|
|
use middle::trans::base;
|
2013-07-21 08:33:40 -05:00
|
|
|
use middle::trans::builder::Builder;
|
2013-08-11 12:42:26 -05:00
|
|
|
use middle::trans::common::{C_i32, C_null};
|
2014-01-10 16:02:36 -06:00
|
|
|
use middle::trans::common::{mono_id,ExternMap,tydesc_info,BuilderRef_res,Stats};
|
|
|
|
use middle::trans::base::{decl_crate_map};
|
|
|
|
use middle::trans::debuginfo;
|
2013-06-15 05:16:47 -05:00
|
|
|
use middle::trans::type_::Type;
|
2014-01-10 16:02:36 -06:00
|
|
|
use middle::ty;
|
2013-12-09 15:56:53 -06:00
|
|
|
use util::sha2::Sha256;
|
2014-02-28 16:34:26 -06:00
|
|
|
use util::nodemap::{NodeMap, NodeSet, DefIdMap};
|
2013-12-09 15:56:53 -06:00
|
|
|
|
2013-12-18 20:35:33 -06:00
|
|
|
use std::cell::{Cell, RefCell};
|
2013-08-03 19:13:14 -05:00
|
|
|
use std::c_str::ToCStr;
|
2013-06-28 17:32:26 -05:00
|
|
|
use std::local_data;
|
2013-08-11 12:42:26 -05:00
|
|
|
use std::libc::c_uint;
|
2014-02-19 21:29:58 -06:00
|
|
|
use collections::{HashMap, HashSet};
|
2013-06-12 21:49:01 -05:00
|
|
|
use syntax::ast;
|
2014-01-10 16:02:36 -06:00
|
|
|
use syntax::parse::token::InternedString;
|
2013-06-12 21:49:01 -05:00
|
|
|
|
2013-06-12 21:02:33 -05:00
|
|
|
pub struct CrateContext {
|
2014-02-06 00:07:06 -06:00
|
|
|
sess: session::Session,
|
|
|
|
llmod: ModuleRef,
|
|
|
|
llcx: ContextRef,
|
|
|
|
metadata_llmod: ModuleRef,
|
|
|
|
td: TargetData,
|
|
|
|
tn: TypeNames,
|
|
|
|
externs: RefCell<ExternMap>,
|
|
|
|
intrinsics: HashMap<&'static str, ValueRef>,
|
2014-02-28 16:34:26 -06:00
|
|
|
item_vals: RefCell<NodeMap<ValueRef>>,
|
2014-02-06 00:07:06 -06:00
|
|
|
exp_map2: resolve::ExportMap2,
|
2014-02-28 16:34:26 -06:00
|
|
|
reachable: @RefCell<NodeSet>,
|
|
|
|
item_symbols: RefCell<NodeMap<~str>>,
|
2014-02-06 00:07:06 -06:00
|
|
|
link_meta: LinkMeta,
|
|
|
|
drop_glues: RefCell<HashMap<ty::t, ValueRef>>,
|
|
|
|
tydescs: RefCell<HashMap<ty::t, @tydesc_info>>,
|
|
|
|
// Set when running emit_tydescs to enforce that no more tydescs are
|
|
|
|
// created.
|
|
|
|
finished_tydescs: Cell<bool>,
|
|
|
|
// Track mapping of external ids to local items imported for inlining
|
2014-02-28 16:34:26 -06:00
|
|
|
external: RefCell<DefIdMap<Option<ast::NodeId>>>,
|
2014-02-06 00:07:06 -06:00
|
|
|
// Backwards version of the `external` map (inlined items to where they
|
|
|
|
// came from)
|
2014-02-28 16:34:26 -06:00
|
|
|
external_srcs: RefCell<NodeMap<ast::DefId>>,
|
2014-02-06 00:07:06 -06:00
|
|
|
// A set of static items which cannot be inlined into other crates. This
|
|
|
|
// will pevent in IIItem() structures from being encoded into the metadata
|
|
|
|
// that is generated
|
2014-02-28 16:34:26 -06:00
|
|
|
non_inlineable_statics: RefCell<NodeSet>,
|
2014-02-06 00:07:06 -06:00
|
|
|
// Cache instances of monomorphized functions
|
|
|
|
monomorphized: RefCell<HashMap<mono_id, ValueRef>>,
|
2014-02-28 16:34:26 -06:00
|
|
|
monomorphizing: RefCell<DefIdMap<uint>>,
|
2014-02-06 00:07:06 -06:00
|
|
|
// Cache generated vtables
|
|
|
|
vtables: RefCell<HashMap<(ty::t, mono_id), ValueRef>>,
|
|
|
|
// Cache of constant strings,
|
|
|
|
const_cstr_cache: RefCell<HashMap<InternedString, ValueRef>>,
|
2013-06-12 21:02:33 -05:00
|
|
|
|
2014-02-06 00:07:06 -06:00
|
|
|
// Reverse-direction for const ptrs cast from globals.
|
|
|
|
// Key is an int, cast from a ValueRef holding a *T,
|
|
|
|
// Val is a ValueRef holding a *[T].
|
|
|
|
//
|
|
|
|
// Needed because LLVM loses pointer->pointee association
|
|
|
|
// when we ptrcast, and we have to ptrcast during translation
|
|
|
|
// of a [T] const because we form a slice, a [*T,int] pair, not
|
|
|
|
// a pointer to an LLVM array type.
|
|
|
|
const_globals: RefCell<HashMap<int, ValueRef>>,
|
2013-06-12 21:02:33 -05:00
|
|
|
|
2014-02-06 00:07:06 -06:00
|
|
|
// Cache of emitted const values
|
2014-02-28 16:34:26 -06:00
|
|
|
const_values: RefCell<NodeMap<ValueRef>>,
|
2013-06-12 21:02:33 -05:00
|
|
|
|
2014-02-06 00:07:06 -06:00
|
|
|
// Cache of external const values
|
2014-02-28 16:34:26 -06:00
|
|
|
extern_const_values: RefCell<DefIdMap<ValueRef>>,
|
2013-06-12 21:02:33 -05:00
|
|
|
|
2014-02-06 00:07:06 -06:00
|
|
|
impl_method_cache: RefCell<HashMap<(ast::DefId, ast::Name), ast::DefId>>,
|
2013-06-14 00:38:17 -05:00
|
|
|
|
2014-02-06 00:07:06 -06:00
|
|
|
// Cache of closure wrappers for bare fn's.
|
|
|
|
closure_bare_wrapper_cache: RefCell<HashMap<ValueRef, ValueRef>>,
|
2014-01-27 06:18:36 -06:00
|
|
|
|
2014-02-06 00:07:06 -06:00
|
|
|
module_data: RefCell<HashMap<~str, ValueRef>>,
|
|
|
|
lltypes: RefCell<HashMap<ty::t, Type>>,
|
|
|
|
llsizingtypes: RefCell<HashMap<ty::t, Type>>,
|
|
|
|
adt_reprs: RefCell<HashMap<ty::t, @adt::Repr>>,
|
|
|
|
symbol_hasher: RefCell<Sha256>,
|
|
|
|
type_hashcodes: RefCell<HashMap<ty::t, ~str>>,
|
|
|
|
all_llvm_symbols: RefCell<HashSet<~str>>,
|
|
|
|
tcx: ty::ctxt,
|
|
|
|
maps: astencode::Maps,
|
|
|
|
stats: @Stats,
|
|
|
|
tydesc_type: Type,
|
|
|
|
int_type: Type,
|
|
|
|
opaque_vec_type: Type,
|
|
|
|
builder: BuilderRef_res,
|
|
|
|
crate_map: ValueRef,
|
|
|
|
crate_map_name: ~str,
|
|
|
|
// Set when at least one function uses GC. Needed so that
|
|
|
|
// decl_gc_metadata knows whether to link to the module metadata, which
|
|
|
|
// is not emitted by LLVM's GC pass when no functions use GC.
|
|
|
|
uses_gc: bool,
|
|
|
|
dbg_cx: Option<debuginfo::CrateDebugContext>,
|
|
|
|
do_not_commit_warning_issued: Cell<bool>,
|
2013-06-12 21:02:33 -05:00
|
|
|
}
|
2013-06-12 21:49:01 -05:00
|
|
|
|
|
|
|
impl CrateContext {
|
2013-06-18 11:39:16 -05:00
|
|
|
pub fn new(sess: session::Session,
|
|
|
|
name: &str,
|
|
|
|
tcx: ty::ctxt,
|
|
|
|
emap2: resolve::ExportMap2,
|
|
|
|
maps: astencode::Maps,
|
2013-12-09 15:56:53 -06:00
|
|
|
symbol_hasher: Sha256,
|
2013-06-18 11:39:16 -05:00
|
|
|
link_meta: LinkMeta,
|
2014-02-28 16:34:26 -06:00
|
|
|
reachable: @RefCell<NodeSet>)
|
2013-06-18 11:39:16 -05:00
|
|
|
-> CrateContext {
|
2013-06-12 21:49:01 -05:00
|
|
|
unsafe {
|
|
|
|
let llcx = llvm::LLVMContextCreate();
|
|
|
|
set_task_llcx(llcx);
|
2013-11-21 17:42:55 -06:00
|
|
|
let llmod = name.with_c_str(|buf| {
|
2013-08-03 19:13:14 -05:00
|
|
|
llvm::LLVMModuleCreateWithNameInContext(buf, llcx)
|
2013-11-21 17:42:55 -06:00
|
|
|
});
|
Store metadata separately in rlib files
Right now whenever an rlib file is linked against, all of the metadata from the
rlib is pulled in to the final staticlib or binary. The reason for this is that
the metadata is currently stored in a section of the object file. Note that this
is intentional for dynamic libraries in order to distribute metadata bundled
with static libraries.
This commit alters the situation for rlib libraries to instead store the
metadata in a separate file in the archive. In doing so, when the archive is
passed to the linker, none of the metadata will get pulled into the result
executable. Furthermore, the metadata file is skipped when assembling rlibs into
an archive.
The snag in this implementation comes with multiple output formats. When
generating a dylib, the metadata needs to be in the object file, but when
generating an rlib this needs to be separate. In order to accomplish this, the
metadata variable is inserted into an entirely separate LLVM Module which is
then codegen'd into a different location (foo.metadata.o). This is then linked
into dynamic libraries and silently ignored for rlib files.
While changing how metadata is inserted into archives, I have also stopped
compressing metadata when inserted into rlib files. We have wanted to stop
compressing metadata, but the sections it creates in object file sections are
apparently too large. Thankfully if it's just an arbitrary file it doesn't
matter how large it is.
I have seen massive reductions in executable sizes, as well as staticlib output
sizes (to confirm that this is all working).
2013-12-03 19:41:01 -06:00
|
|
|
let metadata_llmod = format!("{}_metadata", name).with_c_str(|buf| {
|
|
|
|
llvm::LLVMModuleCreateWithNameInContext(buf, llcx)
|
|
|
|
});
|
2013-06-12 21:49:01 -05:00
|
|
|
let data_layout: &str = sess.targ_cfg.target_strs.data_layout;
|
|
|
|
let targ_triple: &str = sess.targ_cfg.target_strs.target_triple;
|
Store metadata separately in rlib files
Right now whenever an rlib file is linked against, all of the metadata from the
rlib is pulled in to the final staticlib or binary. The reason for this is that
the metadata is currently stored in a section of the object file. Note that this
is intentional for dynamic libraries in order to distribute metadata bundled
with static libraries.
This commit alters the situation for rlib libraries to instead store the
metadata in a separate file in the archive. In doing so, when the archive is
passed to the linker, none of the metadata will get pulled into the result
executable. Furthermore, the metadata file is skipped when assembling rlibs into
an archive.
The snag in this implementation comes with multiple output formats. When
generating a dylib, the metadata needs to be in the object file, but when
generating an rlib this needs to be separate. In order to accomplish this, the
metadata variable is inserted into an entirely separate LLVM Module which is
then codegen'd into a different location (foo.metadata.o). This is then linked
into dynamic libraries and silently ignored for rlib files.
While changing how metadata is inserted into archives, I have also stopped
compressing metadata when inserted into rlib files. We have wanted to stop
compressing metadata, but the sections it creates in object file sections are
apparently too large. Thankfully if it's just an arbitrary file it doesn't
matter how large it is.
I have seen massive reductions in executable sizes, as well as staticlib output
sizes (to confirm that this is all working).
2013-12-03 19:41:01 -06:00
|
|
|
data_layout.with_c_str(|buf| {
|
|
|
|
llvm::LLVMSetDataLayout(llmod, buf);
|
|
|
|
llvm::LLVMSetDataLayout(metadata_llmod, buf);
|
|
|
|
});
|
2013-11-21 17:42:55 -06:00
|
|
|
targ_triple.with_c_str(|buf| {
|
Store metadata separately in rlib files
Right now whenever an rlib file is linked against, all of the metadata from the
rlib is pulled in to the final staticlib or binary. The reason for this is that
the metadata is currently stored in a section of the object file. Note that this
is intentional for dynamic libraries in order to distribute metadata bundled
with static libraries.
This commit alters the situation for rlib libraries to instead store the
metadata in a separate file in the archive. In doing so, when the archive is
passed to the linker, none of the metadata will get pulled into the result
executable. Furthermore, the metadata file is skipped when assembling rlibs into
an archive.
The snag in this implementation comes with multiple output formats. When
generating a dylib, the metadata needs to be in the object file, but when
generating an rlib this needs to be separate. In order to accomplish this, the
metadata variable is inserted into an entirely separate LLVM Module which is
then codegen'd into a different location (foo.metadata.o). This is then linked
into dynamic libraries and silently ignored for rlib files.
While changing how metadata is inserted into archives, I have also stopped
compressing metadata when inserted into rlib files. We have wanted to stop
compressing metadata, but the sections it creates in object file sections are
apparently too large. Thankfully if it's just an arbitrary file it doesn't
matter how large it is.
I have seen massive reductions in executable sizes, as well as staticlib output
sizes (to confirm that this is all working).
2013-12-03 19:41:01 -06:00
|
|
|
llvm::LLVMRustSetNormalizedTarget(llmod, buf);
|
|
|
|
llvm::LLVMRustSetNormalizedTarget(metadata_llmod, buf);
|
2013-11-21 17:42:55 -06:00
|
|
|
});
|
2013-06-12 21:49:01 -05:00
|
|
|
let targ_cfg = sess.targ_cfg;
|
2013-06-14 21:31:52 -05:00
|
|
|
|
2013-06-12 21:49:01 -05:00
|
|
|
let td = mk_target_data(sess.targ_cfg.target_strs.data_layout);
|
2013-12-19 18:22:26 -06:00
|
|
|
let tn = TypeNames::new();
|
2013-06-14 21:31:52 -05:00
|
|
|
|
2013-06-12 21:49:01 -05:00
|
|
|
let mut intrinsics = base::declare_intrinsics(llmod);
|
2014-03-05 02:51:47 -06:00
|
|
|
if sess.opts.debuginfo != NoDebugInfo {
|
2013-06-12 21:49:01 -05:00
|
|
|
base::declare_dbg_intrinsics(llmod, &mut intrinsics);
|
|
|
|
}
|
2013-06-15 05:16:47 -05:00
|
|
|
let int_type = Type::int(targ_cfg.arch);
|
|
|
|
let tydesc_type = Type::tydesc(targ_cfg.arch);
|
|
|
|
let opaque_vec_type = Type::opaque_vec(targ_cfg.arch);
|
|
|
|
|
2013-06-16 05:52:44 -05:00
|
|
|
let mut str_slice_ty = Type::named_struct("str_slice");
|
|
|
|
str_slice_ty.set_struct_body([Type::i8p(), int_type], false);
|
2013-06-15 22:45:48 -05:00
|
|
|
|
2013-06-15 05:16:47 -05:00
|
|
|
tn.associate_type("tydesc", &tydesc_type);
|
2013-06-15 22:45:48 -05:00
|
|
|
tn.associate_type("str_slice", &str_slice_ty);
|
2013-06-15 05:16:47 -05:00
|
|
|
|
2013-12-09 15:56:53 -06:00
|
|
|
let (crate_map_name, crate_map) = decl_crate_map(sess, link_meta.clone(), llmod);
|
2014-03-05 02:51:47 -06:00
|
|
|
let dbg_cx = if sess.opts.debuginfo != NoDebugInfo {
|
2014-01-27 07:58:40 -06:00
|
|
|
Some(debuginfo::CrateDebugContext::new(llmod))
|
2013-06-12 21:49:01 -05:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
2013-06-16 23:23:24 -05:00
|
|
|
if sess.count_llvm_insns() {
|
|
|
|
base::init_insn_ctxt()
|
|
|
|
}
|
|
|
|
|
2013-06-12 21:49:01 -05:00
|
|
|
CrateContext {
|
2014-02-06 00:07:06 -06:00
|
|
|
sess: sess,
|
|
|
|
llmod: llmod,
|
|
|
|
llcx: llcx,
|
|
|
|
metadata_llmod: metadata_llmod,
|
|
|
|
td: td,
|
|
|
|
tn: tn,
|
|
|
|
externs: RefCell::new(HashMap::new()),
|
|
|
|
intrinsics: intrinsics,
|
2014-02-28 16:34:26 -06:00
|
|
|
item_vals: RefCell::new(NodeMap::new()),
|
2014-02-06 00:07:06 -06:00
|
|
|
exp_map2: emap2,
|
|
|
|
reachable: reachable,
|
2014-02-28 16:34:26 -06:00
|
|
|
item_symbols: RefCell::new(NodeMap::new()),
|
2014-02-06 00:07:06 -06:00
|
|
|
link_meta: link_meta,
|
|
|
|
drop_glues: RefCell::new(HashMap::new()),
|
|
|
|
tydescs: RefCell::new(HashMap::new()),
|
|
|
|
finished_tydescs: Cell::new(false),
|
2014-02-28 16:34:26 -06:00
|
|
|
external: RefCell::new(DefIdMap::new()),
|
|
|
|
external_srcs: RefCell::new(NodeMap::new()),
|
|
|
|
non_inlineable_statics: RefCell::new(NodeSet::new()),
|
2014-02-06 00:07:06 -06:00
|
|
|
monomorphized: RefCell::new(HashMap::new()),
|
2014-02-28 16:34:26 -06:00
|
|
|
monomorphizing: RefCell::new(DefIdMap::new()),
|
2014-02-06 00:07:06 -06:00
|
|
|
vtables: RefCell::new(HashMap::new()),
|
|
|
|
const_cstr_cache: RefCell::new(HashMap::new()),
|
|
|
|
const_globals: RefCell::new(HashMap::new()),
|
2014-02-28 16:34:26 -06:00
|
|
|
const_values: RefCell::new(NodeMap::new()),
|
|
|
|
extern_const_values: RefCell::new(DefIdMap::new()),
|
2014-02-06 00:07:06 -06:00
|
|
|
impl_method_cache: RefCell::new(HashMap::new()),
|
|
|
|
closure_bare_wrapper_cache: RefCell::new(HashMap::new()),
|
|
|
|
module_data: RefCell::new(HashMap::new()),
|
|
|
|
lltypes: RefCell::new(HashMap::new()),
|
|
|
|
llsizingtypes: RefCell::new(HashMap::new()),
|
|
|
|
adt_reprs: RefCell::new(HashMap::new()),
|
|
|
|
symbol_hasher: RefCell::new(symbol_hasher),
|
|
|
|
type_hashcodes: RefCell::new(HashMap::new()),
|
|
|
|
all_llvm_symbols: RefCell::new(HashSet::new()),
|
|
|
|
tcx: tcx,
|
|
|
|
maps: maps,
|
|
|
|
stats: @Stats {
|
|
|
|
n_static_tydescs: Cell::new(0u),
|
|
|
|
n_glues_created: Cell::new(0u),
|
|
|
|
n_null_glues: Cell::new(0u),
|
|
|
|
n_real_glues: Cell::new(0u),
|
|
|
|
n_fns: Cell::new(0u),
|
|
|
|
n_monos: Cell::new(0u),
|
|
|
|
n_inlines: Cell::new(0u),
|
|
|
|
n_closures: Cell::new(0u),
|
|
|
|
n_llvm_insns: Cell::new(0u),
|
|
|
|
llvm_insns: RefCell::new(HashMap::new()),
|
|
|
|
fn_stats: RefCell::new(~[]),
|
|
|
|
},
|
|
|
|
tydesc_type: tydesc_type,
|
|
|
|
int_type: int_type,
|
|
|
|
opaque_vec_type: opaque_vec_type,
|
|
|
|
builder: BuilderRef_res(llvm::LLVMCreateBuilderInContext(llcx)),
|
|
|
|
crate_map: crate_map,
|
|
|
|
crate_map_name: crate_map_name,
|
|
|
|
uses_gc: false,
|
|
|
|
dbg_cx: dbg_cx,
|
|
|
|
do_not_commit_warning_issued: Cell::new(false),
|
2013-06-12 21:49:01 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-07-21 08:33:40 -05:00
|
|
|
|
2014-02-06 16:38:33 -06:00
|
|
|
pub fn builder<'a>(&'a self) -> Builder<'a> {
|
2013-07-21 08:33:40 -05:00
|
|
|
Builder::new(self)
|
|
|
|
}
|
2013-08-11 12:29:14 -05:00
|
|
|
|
|
|
|
pub fn const_inbounds_gepi(&self,
|
|
|
|
pointer: ValueRef,
|
|
|
|
indices: &[uint]) -> ValueRef {
|
2013-10-21 15:08:31 -05:00
|
|
|
debug!("const_inbounds_gepi: pointer={} indices={:?}",
|
2013-08-11 12:29:14 -05:00
|
|
|
self.tn.val_to_str(pointer), indices);
|
|
|
|
let v: ~[ValueRef] =
|
2013-08-11 13:56:43 -05:00
|
|
|
indices.iter().map(|i| C_i32(*i as i32)).collect();
|
2013-08-11 12:29:14 -05:00
|
|
|
unsafe {
|
|
|
|
llvm::LLVMConstInBoundsGEP(pointer,
|
2013-12-15 06:35:12 -06:00
|
|
|
v.as_ptr(),
|
2013-08-11 12:29:14 -05:00
|
|
|
indices.len() as c_uint)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn offsetof_gep(&self,
|
|
|
|
llptr_ty: Type,
|
|
|
|
indices: &[uint]) -> ValueRef {
|
|
|
|
/*!
|
|
|
|
* Returns the offset of applying the given GEP indices
|
|
|
|
* to an instance of `llptr_ty`. Similar to `offsetof` in C,
|
|
|
|
* except that `llptr_ty` must be a pointer type.
|
|
|
|
*/
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
let null = C_null(llptr_ty);
|
|
|
|
llvm::LLVMConstPtrToInt(self.const_inbounds_gepi(null, indices),
|
|
|
|
self.int_type.to_ref())
|
|
|
|
}
|
|
|
|
}
|
2013-06-12 21:49:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[unsafe_destructor]
|
|
|
|
impl Drop for CrateContext {
|
2013-09-16 20:18:07 -05:00
|
|
|
fn drop(&mut self) {
|
2013-07-12 03:38:44 -05:00
|
|
|
unset_task_llcx();
|
2013-06-12 21:49:01 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-17 01:34:40 -05:00
|
|
|
local_data_key!(task_local_llcx_key: @ContextRef)
|
2013-07-12 03:38:44 -05:00
|
|
|
|
2013-06-12 21:49:01 -05:00
|
|
|
pub fn task_llcx() -> ContextRef {
|
2013-09-20 01:08:47 -05:00
|
|
|
let opt = local_data::get(task_local_llcx_key, |k| k.map(|k| *k));
|
2013-06-12 21:49:01 -05:00
|
|
|
*opt.expect("task-local LLVMContextRef wasn't ever set!")
|
|
|
|
}
|
|
|
|
|
2013-07-12 03:38:44 -05:00
|
|
|
fn set_task_llcx(c: ContextRef) {
|
2013-07-09 19:25:28 -05:00
|
|
|
local_data::set(task_local_llcx_key, @c);
|
2013-06-12 21:49:01 -05:00
|
|
|
}
|
|
|
|
|
2013-07-12 03:38:44 -05:00
|
|
|
fn unset_task_llcx() {
|
2013-07-09 19:25:28 -05:00
|
|
|
local_data::pop(task_local_llcx_key);
|
2013-06-12 21:49:01 -05:00
|
|
|
}
|