Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xc extern statics #5592

Merged
merged 2 commits into from
Mar 28, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libcore/rt/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ fn initialize_call_frame(regs: &mut Registers, fptr: *c_void, arg: *c_void, sp:
type Registers = [uint, ..22];

#[cfg(target_arch = "x86_64")]
fn new_regs() -> ~Registers { ~[0, .. 22] }
fn new_regs() -> ~Registers { ~([0, .. 22]) }

#[cfg(target_arch = "x86_64")]
fn initialize_call_frame(regs: &mut Registers, fptr: *c_void, arg: *c_void, sp: *mut uint) {
Expand Down
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 @@ -1096,11 +1098,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
14 changes: 9 additions & 5 deletions src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2187,17 +2187,21 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
let count = ty::eval_repeat_count(tcx, count_expr);
check_expr_with_hint(fcx, count_expr, ty::mk_uint(tcx));
let tt = ast_expr_vstore_to_vstore(fcx, ev, count, vst);
let mutability = match vst {
ast::expr_vstore_mut_box | ast::expr_vstore_mut_slice => {
ast::m_mutbl
}
_ => mutbl
};
let t: ty::t = fcx.infcx().next_ty_var();
check_expr_has_type(fcx, element, t);
let arg_t = fcx.expr_ty(element);
if ty::type_is_error(arg_t) {
ty::mk_err(tcx)
}
else if ty::type_is_bot(arg_t) {
} else if ty::type_is_bot(arg_t) {
ty::mk_bot(tcx)
}
else {
ty::mk_evec(tcx, ty::mt {ty: t, mutbl: mutbl}, tt)
} else {
ty::mk_evec(tcx, ty::mt {ty: t, mutbl: mutability}, tt)
}
}
_ =>
Expand Down
16 changes: 8 additions & 8 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ pub fn Parser(sess: @mut ParseSess,
token: @mut copy tok0.tok,
span: @mut copy tok0.sp,
last_span: @mut copy tok0.sp,
buffer: @mut [copy tok0, .. 4],
buffer: @mut ([copy tok0, .. 4]),
buffer_start: @mut 0,
buffer_end: @mut 0,
tokens_consumed: @mut 0,
Expand Down Expand Up @@ -1661,12 +1661,11 @@ pub impl Parser {
hi = e.span.hi;
// HACK: turn @[...] into a @-evec
ex = match e.node {
expr_vec(*) if m == m_mutbl =>
expr_vec(*) | expr_repeat(*) if m == m_mutbl =>
expr_vstore(e, expr_vstore_mut_box),
expr_vec(*) if m == m_imm => expr_vstore(e, expr_vstore_box),
expr_lit(@codemap::spanned {
node: lit_str(_), span: _}) if m == m_imm =>
expr_vstore(e, expr_vstore_box),
expr_vec(*) |
expr_lit(@codemap::spanned { node: lit_str(_), span: _}) |
expr_repeat(*) if m == m_imm => expr_vstore(e, expr_vstore_box),
_ => expr_unary(box(m), e)
};
}
Expand All @@ -1681,8 +1680,9 @@ pub impl Parser {
hi = e.span.hi;
// HACK: turn ~[...] into a ~-evec
ex = match e.node {
expr_vec(*) | expr_lit(@codemap::spanned {
node: lit_str(_), span: _})
expr_vec(*) |
expr_lit(@codemap::spanned { node: lit_str(_), span: _}) |
expr_repeat(*)
if m == m_imm => expr_vstore(e, expr_vstore_uniq),
_ => expr_unary(uniq(m), e)
};
Expand Down
23 changes: 23 additions & 0 deletions src/test/run-pass/expr-repeat-vstore.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use core::io::println;

fn main() {
let v: ~[int] = ~[ 1, ..5 ];
println(v[0].to_str());
println(v[1].to_str());
println(v[2].to_str());
println(v[3].to_str());
println(v[4].to_str());
let v: @[int] = @[ 2, ..5 ];
println(v[0].to_str());
println(v[1].to_str());
println(v[2].to_str());
println(v[3].to_str());
println(v[4].to_str());
let v: @mut [int] = @mut [ 3, ..5 ];
println((copy v[0]).to_str());
println((copy v[1]).to_str());
println((copy v[2]).to_str());
println((copy v[3]).to_str());
println((copy v[4]).to_str());
}