Skip to content

Commit

Permalink
auto merge of #5592 : pcwalton/rust/xc-extern-statics, r=pcwalton
Browse files Browse the repository at this point in the history
  • Loading branch information
bors committed Mar 28, 2013
2 parents e549b80 + 58338dd commit 3dbf2c3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2540,8 +2540,9 @@ pub fn get_item_val(ccx: @CrateContext, id: ast::node_id) -> ValueRef {
}
}
_ => {
ccx.sess.bug(~"get_item_val(): unexpected variant")
ref variant => {
ccx.sess.bug(fmt!("get_item_val(): unexpected variant: %?",
variant))
}
};
if !(exprt || ccx.reachable.contains(&id)) {
Expand Down Expand Up @@ -3085,6 +3086,7 @@ pub fn trans_crate(sess: session::Session,
const_cstr_cache: @mut LinearMap::new(),
const_globals: @mut LinearMap::new(),
const_values: @mut LinearMap::new(),
extern_const_values: @mut LinearMap::new(),
module_data: @mut LinearMap::new(),
lltypes: @mut LinearMap::new(),
llsizingtypes: @mut LinearMap::new(),
Expand Down
4 changes: 4 additions & 0 deletions src/librustc/middle/trans/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ pub struct CrateContext {

// Cache of emitted const values
const_values: @mut LinearMap<ast::node_id, ValueRef>,

// Cache of external const values
extern_const_values: @mut LinearMap<ast::def_id, ValueRef>,

module_data: @mut LinearMap<~str, ValueRef>,
lltypes: @mut LinearMap<ty::t, TypeRef>,
llsizingtypes: @mut LinearMap<ty::t, TypeRef>,
Expand Down
36 changes: 31 additions & 5 deletions src/librustc/middle/trans/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ use core::prelude::*;
use back::abi;
use lib;
use lib::llvm::{ValueRef, TypeRef, llvm, True};
use metadata::csearch;
use middle::borrowck::root_map_key;
use middle::trans::_match;
use middle::trans::adt;
Expand All @@ -150,6 +151,7 @@ use middle::ty::{AutoPtr, AutoBorrowVec, AutoBorrowVecRef, AutoBorrowFn,
use util::common::indenter;
use util::ppaux::ty_to_str;

use core::cast::transmute;
use core::hashmap::linear::LinearMap;
use syntax::print::pprust::{expr_to_str};
use syntax::ast;
Expand Down Expand Up @@ -1079,11 +1081,35 @@ fn trans_lvalue_unadjusted(bcx: block, expr: @ast::expr) -> DatumBlock {
fn get_val(bcx: block, did: ast::def_id, const_ty: ty::t)
-> ValueRef {
// The LLVM global has the type of its initializer,
// which may not be equal to the enum's type for
// non-C-like enums.
PointerCast(bcx, base::get_item_val(bcx.ccx(), did.node),
T_ptr(type_of(bcx.ccx(), const_ty)))
if did.crate == ast::local_crate {
// The LLVM global has the type of its initializer,
// which may not be equal to the enum's type for
// non-C-like enums.
PointerCast(bcx,
base::get_item_val(bcx.ccx(), did.node),
T_ptr(type_of(bcx.ccx(), const_ty)))
} else {
// For external constants, we don't inline.
match bcx.ccx().extern_const_values.find(&did) {
None => {
unsafe {
let llty = type_of(bcx.ccx(), const_ty);
let symbol = csearch::get_symbol(
bcx.ccx().sess.cstore,
did);
let llval = llvm::LLVMAddGlobal(
bcx.ccx().llmod,
llty,
transmute::<&u8,*i8>(&symbol[0]));
bcx.ccx().extern_const_values.insert(
did,
llval);
llval
}
}
Some(llval) => *llval
}
}
}
let did = get_did(ccx, did);
Expand Down

0 comments on commit 3dbf2c3

Please sign in to comment.