De-@ move maps and rework parts of trans.

This commit is contained in:
Eduard Burtescu 2014-03-15 22:29:34 +02:00
parent 3f64d4126b
commit 0bb6de3076
42 changed files with 962 additions and 1048 deletions

View file

@ -559,7 +559,7 @@ fn get_symbol_hash(ccx: &CrateContext, t: ty::t) -> ~str {
let mut type_hashcodes = ccx.type_hashcodes.borrow_mut();
let mut symbol_hasher = ccx.symbol_hasher.borrow_mut();
let hash = symbol_hash(ccx.tcx, symbol_hasher.get(), t, &ccx.link_meta);
let hash = symbol_hash(ccx.tcx(), symbol_hasher.get(), t, &ccx.link_meta);
type_hashcodes.get().insert(t, hash.clone());
hash
}
@ -694,7 +694,7 @@ pub fn mangle_exported_name(ccx: &CrateContext, path: PathElems,
pub fn mangle_internal_name_by_type_only(ccx: &CrateContext,
t: ty::t,
name: &str) -> ~str {
let s = ppaux::ty_to_short_str(ccx.tcx, t);
let s = ppaux::ty_to_short_str(ccx.tcx(), t);
let path = [PathName(token::intern(name)),
PathName(token::intern(s))];
let hash = get_symbol_hash(ccx, t);
@ -704,7 +704,7 @@ pub fn mangle_internal_name_by_type_only(ccx: &CrateContext,
pub fn mangle_internal_name_by_type_and_seq(ccx: &CrateContext,
t: ty::t,
name: &str) -> ~str {
let s = ppaux::ty_to_str(ccx.tcx, t);
let s = ppaux::ty_to_str(ccx.tcx(), t);
let path = [PathName(token::intern(s)),
gensym_name(name)];
let hash = get_symbol_hash(ccx, t);

View file

@ -35,6 +35,7 @@ use std::cell::{Cell, RefCell};
use std::io;
use std::io::fs;
use std::io::MemReader;
use std::mem::drop;
use std::os;
use std::vec_ng::Vec;
use std::vec_ng;
@ -357,17 +358,20 @@ pub fn phase_3_run_analysis_passes(sess: Session,
time(time_passes, "match checking", (), |_|
middle::check_match::check_crate(&ty_cx, method_map,
moves_map, krate));
&moves_map, krate));
time(time_passes, "liveness checking", (), |_|
middle::liveness::check_crate(&ty_cx, method_map,
capture_map, krate));
&capture_map, krate));
let root_map =
time(time_passes, "borrow checking", (), |_|
middle::borrowck::check_crate(&ty_cx, method_map,
moves_map, moved_variables_set,
capture_map, krate));
&moves_map, &moved_variables_set,
&capture_map, krate));
drop(moves_map);
drop(moved_variables_set);
time(time_passes, "kind checking", (), |_|
kind::check_crate(&ty_cx, method_map, krate));
@ -396,7 +400,7 @@ pub fn phase_3_run_analysis_passes(sess: Session,
root_map: root_map,
method_map: method_map,
vtable_map: vtable_map,
capture_map: capture_map
capture_map: RefCell::new(capture_map)
},
reachable: reachable_map
}
@ -414,10 +418,13 @@ pub struct CrateTranslation {
/// Run the translation phase to LLVM, after which the AST and analysis can
/// be discarded.
pub fn phase_4_translate_to_llvm(krate: ast::Crate,
analysis: &CrateAnalysis,
outputs: &OutputFilenames) -> CrateTranslation {
time(analysis.ty_cx.sess.time_passes(), "translation", krate, |krate|
trans::base::trans_crate(krate, analysis, outputs))
analysis: CrateAnalysis,
outputs: &OutputFilenames) -> (ty::ctxt, CrateTranslation) {
// Option dance to work around the lack of stack once closures.
let time_passes = analysis.ty_cx.sess.time_passes();
let mut analysis = Some(analysis);
time(time_passes, "translation", krate, |krate|
trans::base::trans_crate(krate, analysis.take_unwrap(), outputs))
}
/// Run LLVM itself, producing a bitcode file, assembly file or object file
@ -582,9 +589,9 @@ pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &Input,
let analysis = phase_3_run_analysis_passes(sess, &expanded_crate, ast_map);
if stop_after_phase_3(&analysis.ty_cx.sess) { return; }
let trans = phase_4_translate_to_llvm(expanded_crate,
&analysis, &outputs);
(outputs, trans, analysis.ty_cx.sess)
let (tcx, trans) = phase_4_translate_to_llvm(expanded_crate,
analysis, &outputs);
(outputs, trans, tcx.sess)
};
phase_5_run_llvm_passes(&sess, &trans, &outputs);
if stop_after_phase_5(&sess) { return; }

View file

@ -34,6 +34,7 @@ use syntax;
use std::libc;
use std::cast;
use std::cell::RefCell;
use std::io::Seek;
use std::rc::Rc;
use std::vec_ng::Vec;
@ -53,13 +54,13 @@ pub struct Maps {
root_map: middle::borrowck::root_map,
method_map: middle::typeck::MethodMap,
vtable_map: middle::typeck::vtable_map,
capture_map: middle::moves::CaptureMap,
capture_map: RefCell<middle::moves::CaptureMap>,
}
struct DecodeContext<'a> {
cdata: @cstore::crate_metadata,
tcx: &'a ty::ctxt,
maps: Maps
maps: &'a Maps
}
struct ExtendedDecodeContext<'a> {
@ -82,7 +83,7 @@ trait tr_intern {
pub fn encode_inlined_item(ecx: &e::EncodeContext,
ebml_w: &mut writer::Encoder,
ii: e::InlinedItemRef,
maps: Maps) {
maps: &Maps) {
let id = match ii {
e::IIItemRef(i) => i.id,
e::IIForeignRef(i) => i.id,
@ -115,7 +116,7 @@ pub fn encode_exported_macro(ebml_w: &mut writer::Encoder, i: &ast::Item) {
pub fn decode_inlined_item(cdata: @cstore::crate_metadata,
tcx: &ty::ctxt,
maps: Maps,
maps: &Maps,
path: Vec<ast_map::PathElem>,
par_doc: ebml::Doc)
-> Result<ast::InlinedItem, Vec<ast_map::PathElem>> {
@ -906,7 +907,7 @@ impl<'a> write_tag_and_id for writer::Encoder<'a> {
struct SideTableEncodingIdVisitor<'a,'b> {
ecx_ptr: *libc::c_void,
new_ebml_w: &'a mut writer::Encoder<'b>,
maps: Maps,
maps: &'a Maps,
}
impl<'a,'b> ast_util::IdVisitingOperation for
@ -929,7 +930,7 @@ impl<'a,'b> ast_util::IdVisitingOperation for
}
fn encode_side_tables_for_ii(ecx: &e::EncodeContext,
maps: Maps,
maps: &Maps,
ebml_w: &mut writer::Encoder,
ii: &ast::InlinedItem) {
ebml_w.start_tag(c::tag_table as uint);
@ -951,7 +952,7 @@ fn encode_side_tables_for_ii(ecx: &e::EncodeContext,
}
fn encode_side_tables_for_id(ecx: &e::EncodeContext,
maps: Maps,
maps: &Maps,
ebml_w: &mut writer::Encoder,
id: ast::NodeId) {
let tcx = ecx.tcx;
@ -1075,20 +1076,16 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
}
}
{
let capture_map = maps.capture_map.borrow();
let r = capture_map.get().find(&id);
for &cap_vars in r.iter() {
ebml_w.tag(c::tag_table_capture_map, |ebml_w| {
ebml_w.id(id);
ebml_w.tag(c::tag_table_val, |ebml_w| {
ebml_w.emit_from_vec(cap_vars.deref().as_slice(),
|ebml_w, cap_var| {
cap_var.encode(ebml_w);
})
for &cap_vars in maps.capture_map.borrow().get().find(&id).iter() {
ebml_w.tag(c::tag_table_capture_map, |ebml_w| {
ebml_w.id(id);
ebml_w.tag(c::tag_table_val, |ebml_w| {
ebml_w.emit_from_vec(cap_vars.deref().as_slice(),
|ebml_w, cap_var| {
cap_var.encode(ebml_w);
})
})
}
})
}
}

View file

@ -715,9 +715,7 @@ impl<'a> CheckLoanCtxt<'a> {
fn check_captured_variables(&self,
closure_id: ast::NodeId,
span: Span) {
let capture_map = self.bccx.capture_map.borrow();
let cap_vars = capture_map.get().get(&closure_id);
for cap_var in cap_vars.deref().iter() {
for cap_var in self.bccx.capture_map.get(&closure_id).deref().iter() {
let var_id = ast_util::def_id_of_def(cap_var.def).node;
let var_path = @LpVar(var_id);
self.check_if_path_is_moved(closure_id, span,

View file

@ -47,9 +47,7 @@ pub fn gather_move_from_pat(bccx: &BorrowckCtxt,
pub fn gather_captures(bccx: &BorrowckCtxt,
move_data: &MoveData,
closure_expr: &ast::Expr) {
let capture_map = bccx.capture_map.borrow();
let captured_vars = capture_map.get().get(&closure_expr.id);
for captured_var in captured_vars.deref().iter() {
for captured_var in bccx.capture_map.get(&closure_expr.id).deref().iter() {
match captured_var.mode {
moves::CapMove => {
let cmt = bccx.cat_captured_var(closure_expr.id,

View file

@ -261,10 +261,7 @@ impl<'a> GuaranteeLifetimeContext<'a> {
match cmt.guarantor().cat {
mc::cat_local(id) |
mc::cat_arg(id) => {
let moved_variables_set = self.bccx
.moved_variables_set
.borrow();
moved_variables_set.get().contains(&id)
self.bccx.moved_variables_set.contains(&id)
}
mc::cat_rvalue(..) |
mc::cat_static_item |

View file

@ -440,9 +440,7 @@ impl<'a> GatherLoanCtxt<'a> {
fn guarantee_captures(&mut self,
closure_expr: &ast::Expr) {
let capture_map = self.bccx.capture_map.borrow();
let captured_vars = capture_map.get().get(&closure_expr.id);
for captured_var in captured_vars.deref().iter() {
for captured_var in self.bccx.capture_map.get(&closure_expr.id).deref().iter() {
match captured_var.mode {
moves::CapCopy | moves::CapMove => { continue; }
moves::CapRef => { }

View file

@ -18,6 +18,7 @@ use middle::typeck;
use middle::moves;
use middle::dataflow::DataFlowContext;
use middle::dataflow::DataFlowOperator;
use util::nodemap::NodeSet;
use util::ppaux::{note_and_explain_region, Repr, UserString};
use std::cell::{Cell, RefCell};
@ -72,9 +73,9 @@ impl<'a> Visitor<()> for BorrowckCtxt<'a> {
pub fn check_crate(tcx: &ty::ctxt,
method_map: typeck::MethodMap,
moves_map: moves::MovesMap,
moved_variables_set: moves::MovedVariablesSet,
capture_map: moves::CaptureMap,
moves_map: &NodeSet,
moved_variables_set: &NodeSet,
capture_map: &moves::CaptureMap,
krate: &ast::Crate)
-> root_map {
let mut bccx = BorrowckCtxt {
@ -157,9 +158,9 @@ fn borrowck_fn(this: &mut BorrowckCtxt,
pub struct BorrowckCtxt<'a> {
tcx: &'a ty::ctxt,
method_map: typeck::MethodMap,
moves_map: moves::MovesMap,
moved_variables_set: moves::MovedVariablesSet,
capture_map: moves::CaptureMap,
moves_map: &'a NodeSet,
moved_variables_set: &'a NodeSet,
capture_map: &'a moves::CaptureMap,
root_map: root_map,
// Statistics:
@ -416,8 +417,7 @@ impl<'a> BorrowckCtxt<'a> {
}
pub fn is_move(&self, id: ast::NodeId) -> bool {
let moves_map = self.moves_map.borrow();
moves_map.get().contains(&id)
self.moves_map.contains(&id)
}
pub fn mc(&self) -> mc::MemCategorizationContext<TcxTyper<'a>> {

View file

@ -16,7 +16,7 @@ use middle::pat_util::*;
use middle::ty::*;
use middle::ty;
use middle::typeck::MethodMap;
use middle::moves;
use util::nodemap::NodeSet;
use util::ppaux::ty_to_str;
use std::cmp;
@ -33,7 +33,7 @@ use syntax::visit::{Visitor, FnKind};
struct MatchCheckCtxt<'a> {
tcx: &'a ty::ctxt,
method_map: MethodMap,
moves_map: moves::MovesMap
moves_map: &'a NodeSet
}
impl<'a> Visitor<()> for MatchCheckCtxt<'a> {
@ -50,7 +50,7 @@ impl<'a> Visitor<()> for MatchCheckCtxt<'a> {
pub fn check_crate(tcx: &ty::ctxt,
method_map: MethodMap,
moves_map: moves::MovesMap,
moves_map: &NodeSet,
krate: &Crate) {
let mut cx = MatchCheckCtxt {
tcx: tcx,
@ -953,8 +953,7 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt,
by_ref_span = Some(span);
}
BindByValue(_) => {
let moves_map = cx.moves_map.borrow();
if moves_map.get().contains(&id) {
if cx.moves_map.contains(&id) {
any_by_move = true;
}
}
@ -991,8 +990,7 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt,
if pat_is_binding(def_map, p) {
match p.node {
PatIdent(_, _, sub) => {
let moves_map = cx.moves_map.borrow();
if moves_map.get().contains(&p.id) {
if cx.moves_map.contains(&p.id) {
check_move(p, sub);
}
}

View file

@ -126,23 +126,18 @@ pub fn lookup_variant_by_id(tcx: &ty::ctxt,
}
}
} else {
{
let extern_const_variants = tcx.extern_const_variants.borrow();
match extern_const_variants.get().find(&variant_def) {
Some(&e) => return e,
None => {}
}
match tcx.extern_const_variants.borrow().get().find(&variant_def) {
Some(&e) => return e,
None => {}
}
let maps = astencode::Maps {
root_map: @RefCell::new(HashMap::new()),
method_map: @RefCell::new(FnvHashMap::new()),
vtable_map: @RefCell::new(NodeMap::new()),
capture_map: @RefCell::new(NodeMap::new())
capture_map: RefCell::new(NodeMap::new())
};
let e = match csearch::maybe_get_item_ast(tcx, enum_def,
|a, b, c, d| astencode::decode_inlined_item(a, b,
maps,
c, d)) {
|a, b, c, d| astencode::decode_inlined_item(a, b, &maps, c, d)) {
csearch::found(ast::IIItem(item)) => match item.node {
ItemEnum(ast::EnumDef { variants: ref variants }, _) => {
variant_expr(variants.as_slice(), variant_def.node)
@ -151,12 +146,8 @@ pub fn lookup_variant_by_id(tcx: &ty::ctxt,
},
_ => None
};
{
let mut extern_const_variants = tcx.extern_const_variants
.borrow_mut();
extern_const_variants.get().insert(variant_def, e);
return e;
}
tcx.extern_const_variants.borrow_mut().get().insert(variant_def, e);
return e;
}
}
@ -187,10 +178,10 @@ pub fn lookup_const_by_id(tcx: &ty::ctxt, def_id: ast::DefId)
root_map: @RefCell::new(HashMap::new()),
method_map: @RefCell::new(FnvHashMap::new()),
vtable_map: @RefCell::new(NodeMap::new()),
capture_map: @RefCell::new(NodeMap::new())
capture_map: RefCell::new(NodeMap::new())
};
let e = match csearch::maybe_get_item_ast(tcx, def_id,
|a, b, c, d| astencode::decode_inlined_item(a, b, maps, c, d)) {
|a, b, c, d| astencode::decode_inlined_item(a, b, &maps, c, d)) {
csearch::found(ast::IIItem(item)) => match item.node {
ItemStatic(_, ast::MutImmutable, const_expr) => Some(const_expr),
_ => None

View file

@ -173,7 +173,7 @@ impl<'a> Visitor<()> for IrMaps<'a> {
pub fn check_crate(tcx: &ty::ctxt,
method_map: typeck::MethodMap,
capture_map: moves::CaptureMap,
capture_map: &moves::CaptureMap,
krate: &Crate) {
visit::walk_crate(&mut IrMaps(tcx, method_map, capture_map), krate, ());
tcx.sess.abort_if_errors();
@ -249,7 +249,7 @@ enum VarKind {
struct IrMaps<'a> {
tcx: &'a ty::ctxt,
method_map: typeck::MethodMap,
capture_map: moves::CaptureMap,
capture_map: &'a moves::CaptureMap,
num_live_nodes: uint,
num_vars: uint,
@ -262,7 +262,7 @@ struct IrMaps<'a> {
fn IrMaps<'a>(tcx: &'a ty::ctxt,
method_map: typeck::MethodMap,
capture_map: moves::CaptureMap)
capture_map: &'a moves::CaptureMap)
-> IrMaps<'a> {
IrMaps {
tcx: tcx,
@ -473,7 +473,7 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) {
// in better error messages than just pointing at the closure
// construction site.
let mut call_caps = Vec::new();
for cv in ir.capture_map.borrow().get().get(&expr.id).deref().iter() {
for cv in ir.capture_map.get(&expr.id).deref().iter() {
match moves::moved_variable_node_id_from_def(cv.def) {
Some(rv) => {
let cv_ln = ir.add_live_node(FreeVarNode(cv.span));

View file

@ -137,7 +137,6 @@ use util::common::indenter;
use util::ppaux::UserString;
use util::nodemap::{NodeMap, NodeSet};
use std::cell::RefCell;
use std::rc::Rc;
use std::vec_ng::Vec;
use syntax::ast::*;
@ -160,23 +159,19 @@ pub struct CaptureVar {
mode: CaptureMode // How variable is being accessed
}
pub type CaptureMap = @RefCell<NodeMap<Rc<Vec<CaptureVar> >>>;
pub type MovesMap = @RefCell<NodeSet>;
/**
* Set of variable node-ids that are moved.
*
* Note: The `VariableMovesMap` stores expression ids that
* are moves, whereas this set stores the ids of the variables
* that are moved at some point */
pub type MovedVariablesSet = @RefCell<NodeSet>;
pub type CaptureMap = NodeMap<Rc<Vec<CaptureVar>>>;
/** See the section Output on the module comment for explanation. */
#[deriving(Clone)]
pub struct MoveMaps {
moves_map: MovesMap,
moved_variables_set: MovedVariablesSet,
moves_map: NodeSet,
/**
* Set of variable node-ids that are moved.
*
* Note: The `moves_map` stores expression ids that are moves,
* whereas this set stores the ids of the variables that are
* moved at some point */
moved_variables_set: NodeSet,
capture_map: CaptureMap
}
@ -216,14 +211,13 @@ pub fn compute_moves(tcx: &ty::ctxt,
tcx: tcx,
method_map: method_map,
move_maps: MoveMaps {
moves_map: @RefCell::new(NodeSet::new()),
capture_map: @RefCell::new(NodeMap::new()),
moved_variables_set: @RefCell::new(NodeSet::new())
moves_map: NodeSet::new(),
moved_variables_set: NodeSet::new(),
capture_map: NodeMap::new()
}
};
let visit_cx = &mut visit_cx;
visit::walk_crate(visit_cx, krate, ());
return visit_cx.move_maps;
visit::walk_crate(&mut visit_cx, krate, ());
visit_cx.move_maps
}
pub fn moved_variable_node_id_from_def(def: Def) -> Option<NodeId> {
@ -284,7 +278,7 @@ impl<'a> VisitContext<'a> {
let expr_ty = ty::expr_ty_adjusted(self.tcx, expr,
self.method_map.borrow().get());
if ty::type_moves_by_default(self.tcx, expr_ty) {
self.move_maps.moves_map.borrow_mut().get().insert(expr.id);
self.move_maps.moves_map.insert(expr.id);
self.use_expr(expr, Move);
} else {
self.use_expr(expr, Read);
@ -349,11 +343,7 @@ impl<'a> VisitContext<'a> {
let def = def_map.get().get_copy(&expr.id);
let r = moved_variable_node_id_from_def(def);
for &id in r.iter() {
let mut moved_variables_set =
self.move_maps
.moved_variables_set
.borrow_mut();
moved_variables_set.get().insert(id);
self.move_maps.moved_variables_set.insert(id);
}
}
Read => {}
@ -361,8 +351,7 @@ impl<'a> VisitContext<'a> {
}
ExprUnary(UnDeref, base) => { // *base
if !self.use_overloaded_operator(expr, base, [])
{
if !self.use_overloaded_operator(expr, base, []) {
// Moving out of *base moves out of base.
self.use_expr(base, comp_mode);
}
@ -374,8 +363,7 @@ impl<'a> VisitContext<'a> {
}
ExprIndex(lhs, rhs) => { // lhs[rhs]
if !self.use_overloaded_operator(expr, lhs, [rhs])
{
if !self.use_overloaded_operator(expr, lhs, [rhs]) {
self.use_expr(lhs, comp_mode);
self.consume_expr(rhs);
}
@ -400,12 +388,7 @@ impl<'a> VisitContext<'a> {
// closures should be noncopyable, they shouldn't move by default;
// calling a closure should only consume it if it's once.
if mode == Move {
{
let mut moves_map = self.move_maps
.moves_map
.borrow_mut();
moves_map.get().insert(callee.id);
}
self.move_maps.moves_map.insert(callee.id);
}
self.use_expr(callee, mode);
self.use_fn_args(args.as_slice());
@ -520,15 +503,13 @@ impl<'a> VisitContext<'a> {
ExprForLoop(..) => fail!("non-desugared expr_for_loop"),
ExprUnary(_, lhs) => {
if !self.use_overloaded_operator(expr, lhs, [])
{
if !self.use_overloaded_operator(expr, lhs, []) {
self.consume_expr(lhs);
}
}
ExprBinary(_, lhs, rhs) => {
if !self.use_overloaded_operator(expr, lhs, [rhs])
{
if !self.use_overloaded_operator(expr, lhs, [rhs]) {
self.consume_expr(lhs);
self.consume_expr(rhs);
}
@ -574,12 +555,7 @@ impl<'a> VisitContext<'a> {
self.use_pat(a.pat);
}
let cap_vars = self.compute_captures(expr.id);
{
let mut capture_map = self.move_maps
.capture_map
.borrow_mut();
capture_map.get().insert(expr.id, cap_vars);
}
self.move_maps.capture_map.insert(expr.id, cap_vars);
self.consume_block(body);
}
@ -657,16 +633,12 @@ impl<'a> VisitContext<'a> {
id, bm, binding_moves);
if binding_moves {
{
let mut moves_map = self.move_maps.moves_map.borrow_mut();
moves_map.get().insert(id);
}
self.move_maps.moves_map.insert(id);
}
})
}
pub fn use_fn_args(&mut self,
arg_exprs: &[@Expr]) {
pub fn use_fn_args(&mut self, arg_exprs: &[@Expr]) {
//! Uses the argument expressions.
for arg_expr in arg_exprs.iter() {
self.use_fn_arg(*arg_expr);

View file

@ -359,7 +359,7 @@ fn variant_opt(bcx: &Block, pat_id: ast::NodeId) -> Opt {
let def_map = ccx.tcx.def_map.borrow();
match def_map.get().get_copy(&pat_id) {
ast::DefVariant(enum_id, var_id, _) => {
let variants = ty::enum_variants(ccx.tcx, enum_id);
let variants = ty::enum_variants(ccx.tcx(), enum_id);
for v in (*variants).iter() {
if var_id == v.id {
return var(v.disr_val,
@ -960,7 +960,7 @@ fn get_options(bcx: &Block, m: &[Match], col: uint) -> Vec<Opt> {
let cur = *br.pats.get(col);
match cur.node {
ast::PatLit(l) => {
add_to_set(ccx.tcx, &mut found, lit(ExprLit(l)));
add_to_set(ccx.tcx(), &mut found, lit(ExprLit(l)));
}
ast::PatIdent(..) => {
// This is one of: an enum variant, a unit-like struct, or a
@ -971,15 +971,15 @@ fn get_options(bcx: &Block, m: &[Match], col: uint) -> Vec<Opt> {
};
match opt_def {
Some(ast::DefVariant(..)) => {
add_to_set(ccx.tcx, &mut found,
add_to_set(ccx.tcx(), &mut found,
variant_opt(bcx, cur.id));
}
Some(ast::DefStruct(..)) => {
add_to_set(ccx.tcx, &mut found,
add_to_set(ccx.tcx(), &mut found,
lit(UnitLikeStructLit(cur.id)));
}
Some(ast::DefStatic(const_did, false)) => {
add_to_set(ccx.tcx, &mut found,
add_to_set(ccx.tcx(), &mut found,
lit(ConstLit(const_did)));
}
_ => {}
@ -995,18 +995,18 @@ fn get_options(bcx: &Block, m: &[Match], col: uint) -> Vec<Opt> {
match opt_def {
Some(ast::DefFn(..)) |
Some(ast::DefVariant(..)) => {
add_to_set(ccx.tcx, &mut found,
add_to_set(ccx.tcx(), &mut found,
variant_opt(bcx, cur.id));
}
Some(ast::DefStatic(const_did, false)) => {
add_to_set(ccx.tcx, &mut found,
add_to_set(ccx.tcx(), &mut found,
lit(ConstLit(const_did)));
}
_ => {}
}
}
ast::PatRange(l1, l2) => {
add_to_set(ccx.tcx, &mut found, range(l1, l2));
add_to_set(ccx.tcx(), &mut found, range(l1, l2));
}
ast::PatVec(ref before, slice, ref after) => {
let (len, vec_opt) = match slice {
@ -2224,7 +2224,7 @@ fn bind_irrefutable_pat<'a>(
match def_map.get().find(&pat.id) {
Some(&ast::DefVariant(enum_id, var_id, _)) => {
let repr = adt::represent_node(bcx, pat.id);
let vinfo = ty::enum_variant_with_id(ccx.tcx,
let vinfo = ty::enum_variant_with_id(ccx.tcx(),
enum_id,
var_id);
let args = extract_variant_args(bcx,

View file

@ -118,7 +118,7 @@ pub fn represent_node(bcx: &Block, node: ast::NodeId) -> @Repr {
/// Decides how to represent a given type.
pub fn represent_type(cx: &CrateContext, t: ty::t) -> @Repr {
debug!("Representing: {}", ty_to_str(cx.tcx, t));
debug!("Representing: {}", ty_to_str(cx.tcx(), t));
{
let adt_reprs = cx.adt_reprs.borrow();
match adt_reprs.get().find(&t) {
@ -140,19 +140,19 @@ fn represent_type_uncached(cx: &CrateContext, t: ty::t) -> Repr {
return Univariant(mk_struct(cx, elems.as_slice(), false), false)
}
ty::ty_struct(def_id, ref substs) => {
let fields = ty::lookup_struct_fields(cx.tcx, def_id);
let fields = ty::lookup_struct_fields(cx.tcx(), def_id);
let mut ftys = fields.map(|field| {
ty::lookup_field_type(cx.tcx, def_id, field.id, substs)
ty::lookup_field_type(cx.tcx(), def_id, field.id, substs)
});
let packed = ty::lookup_packed(cx.tcx, def_id);
let dtor = ty::ty_dtor(cx.tcx, def_id).has_drop_flag();
let packed = ty::lookup_packed(cx.tcx(), def_id);
let dtor = ty::ty_dtor(cx.tcx(), def_id).has_drop_flag();
if dtor { ftys.push(ty::mk_bool()); }
return Univariant(mk_struct(cx, ftys.as_slice(), packed), dtor)
}
ty::ty_enum(def_id, ref substs) => {
let cases = get_cases(cx.tcx, def_id, substs);
let hint = ty::lookup_repr_hint(cx.tcx, def_id);
let cases = get_cases(cx.tcx(), def_id, substs);
let hint = ty::lookup_repr_hint(cx.tcx(), def_id);
if cases.len() == 0 {
// Uninhabitable; represent as unit
@ -179,7 +179,7 @@ fn represent_type_uncached(cx: &CrateContext, t: ty::t) -> Repr {
if !cases.iter().enumerate().all(|(i,c)| c.discr == (i as Disr)) {
cx.sess().bug(format!("non-C-like enum {} with specified \
discriminants",
ty::item_path_str(cx.tcx, def_id)))
ty::item_path_str(cx.tcx(), def_id)))
}
if cases.len() == 1 {
@ -286,7 +286,7 @@ fn get_cases(tcx: &ty::ctxt, def_id: ast::DefId, substs: &ty::substs) -> Vec<Cas
fn mk_struct(cx: &CrateContext, tys: &[ty::t], packed: bool) -> Struct {
let lltys = tys.map(|&ty| type_of::sizing_type_of(cx, ty));
let llty_rec = Type::struct_(lltys, packed);
let llty_rec = Type::struct_(cx, lltys, packed);
Struct {
size: machine::llsize_of_alloc(cx, llty_rec) /*bad*/as u64,
align: machine::llalign_of_min(cx, llty_rec) /*bad*/as u64,
@ -415,10 +415,10 @@ fn generic_type_of(cx: &CrateContext, r: &Repr, name: Option<&str>, sizing: bool
Univariant(ref st, _) | NullablePointer{ nonnull: ref st, .. } => {
match name {
None => {
Type::struct_(struct_llfields(cx, st, sizing).as_slice(),
Type::struct_(cx, struct_llfields(cx, st, sizing).as_slice(),
st.packed)
}
Some(name) => { assert_eq!(sizing, false); Type::named_struct(name) }
Some(name) => { assert_eq!(sizing, false); Type::named_struct(cx, name) }
}
}
General(ity, ref sts) => {
@ -441,12 +441,12 @@ fn generic_type_of(cx: &CrateContext, r: &Repr, name: Option<&str>, sizing: bool
let discr_size = machine::llsize_of_alloc(cx, discr_ty) as u64;
let align_units = (size + align - 1) / align - 1;
let pad_ty = match align {
1 => Type::array(&Type::i8(), align_units),
2 => Type::array(&Type::i16(), align_units),
4 => Type::array(&Type::i32(), align_units),
8 if machine::llalign_of_min(cx, Type::i64()) == 8 =>
Type::array(&Type::i64(), align_units),
a if a.count_ones() == 1 => Type::array(&Type::vector(&Type::i32(), a / 4),
1 => Type::array(&Type::i8(cx), align_units),
2 => Type::array(&Type::i16(cx), align_units),
4 => Type::array(&Type::i32(cx), align_units),
8 if machine::llalign_of_min(cx, Type::i64(cx)) == 8 =>
Type::array(&Type::i64(cx), align_units),
a if a.count_ones() == 1 => Type::array(&Type::vector(&Type::i32(cx), a / 4),
align_units),
_ => fail!("unsupported enum alignment: {:?}", align)
};
@ -456,9 +456,9 @@ fn generic_type_of(cx: &CrateContext, r: &Repr, name: Option<&str>, sizing: bool
Type::array(&discr_ty, align / discr_size - 1),
pad_ty);
match name {
None => Type::struct_(fields.as_slice(), false),
None => Type::struct_(cx, fields.as_slice(), false),
Some(name) => {
let mut llty = Type::named_struct(name);
let mut llty = Type::named_struct(cx, name);
llty.set_struct_body(fields.as_slice(), false);
llty
}
@ -514,7 +514,7 @@ pub fn trans_get_discr(bcx: &Block, r: &Repr, scrutinee: ValueRef, cast_to: Opti
signed = ity.is_signed();
}
Univariant(..) => {
val = C_u8(0);
val = C_u8(bcx.ccx(), 0);
signed = false;
}
NullablePointer{ nonnull: ref nonnull, nndiscr, ptrfield, .. } => {
@ -581,7 +581,7 @@ pub fn trans_case<'a>(bcx: &'a Block<'a>, r: &Repr, discr: Disr)
}
NullablePointer{ .. } => {
assert!(discr == 0 || discr == 1);
_match::single_result(rslt(bcx, C_i1(discr != 0)))
_match::single_result(rslt(bcx, C_i1(bcx.ccx(), discr != 0)))
}
}
}
@ -604,7 +604,7 @@ pub fn trans_start_init(bcx: &Block, r: &Repr, val: ValueRef, discr: Disr) {
}
Univariant(ref st, true) => {
assert_eq!(discr, 0);
Store(bcx, C_bool(true),
Store(bcx, C_bool(bcx.ccx(), true),
GEPi(bcx, val, [0, st.fields.len() - 1]))
}
Univariant(..) => {
@ -706,7 +706,7 @@ fn struct_field_ptr(bcx: &Block, st: &Struct, val: ValueRef, ix: uint,
let val = if needs_cast {
let fields = st.fields.map(|&ty| type_of::type_of(ccx, ty));
let real_ty = Type::struct_(fields.as_slice(), st.packed);
let real_ty = Type::struct_(ccx, fields.as_slice(), st.packed);
PointerCast(bcx, val, real_ty.ptr_to())
} else {
val
@ -761,21 +761,21 @@ pub fn trans_const(ccx: &CrateContext, r: &Repr, discr: Disr,
vec_ng::append(
vec!(lldiscr),
vals).as_slice());
C_struct(vec_ng::append(
C_struct(ccx, vec_ng::append(
contents,
&[padding(max_sz - case.size)]).as_slice(),
&[padding(ccx, max_sz - case.size)]).as_slice(),
false)
}
Univariant(ref st, _dro) => {
assert!(discr == 0);
let contents = build_const_struct(ccx, st, vals);
C_struct(contents.as_slice(), st.packed)
C_struct(ccx, contents.as_slice(), st.packed)
}
NullablePointer{ nonnull: ref nonnull, nndiscr, .. } => {
if discr == nndiscr {
C_struct(build_const_struct(ccx,
nonnull,
vals.as_slice()).as_slice(),
C_struct(ccx, build_const_struct(ccx,
nonnull,
vals).as_slice(),
false)
} else {
let vals = nonnull.fields.map(|&ty| {
@ -783,9 +783,9 @@ pub fn trans_const(ccx: &CrateContext, r: &Repr, discr: Disr,
// field; see #8506.
C_null(type_of::sizing_type_of(ccx, ty))
}).move_iter().collect::<Vec<ValueRef> >();
C_struct(build_const_struct(ccx,
nonnull,
vals.as_slice()).as_slice(),
C_struct(ccx, build_const_struct(ccx,
nonnull,
vals.as_slice()).as_slice(),
false)
}
}
@ -817,7 +817,7 @@ fn build_const_struct(ccx: &CrateContext, st: &Struct, vals: &[ValueRef])
let target_offset = roundup(offset, type_align);
offset = roundup(offset, val_align);
if offset != target_offset {
cfields.push(padding(target_offset - offset));
cfields.push(padding(ccx, target_offset - offset));
offset = target_offset;
}
assert!(!is_undef(vals[i]));
@ -828,8 +828,8 @@ fn build_const_struct(ccx: &CrateContext, st: &Struct, vals: &[ValueRef])
return cfields;
}
fn padding(size: u64) -> ValueRef {
C_undef(Type::array(&Type::i8(), size))
fn padding(ccx: &CrateContext, size: u64) -> ValueRef {
C_undef(Type::array(&Type::i8(ccx), size))
}
// FIXME this utility routine should be somewhere more general

View file

@ -86,11 +86,11 @@ pub fn trans_inline_asm<'a>(bcx: &'a Block<'a>, ia: &ast::InlineAsm)
// Depending on how many outputs we have, the return type is different
let output_type = if num_outputs == 0 {
Type::void()
Type::void(bcx.ccx())
} else if num_outputs == 1 {
*output_types.get(0)
} else {
Type::struct_(output_types.as_slice(), false)
Type::struct_(bcx.ccx(), output_types.as_slice(), false)
};
let dialect = match ia.dialect {

View file

@ -34,7 +34,6 @@ use driver::driver::{CrateAnalysis, CrateTranslation};
use lib::llvm::{ModuleRef, ValueRef, BasicBlockRef};
use lib::llvm::{llvm, Vector};
use lib;
use metadata::common::LinkMeta;
use metadata::{csearch, encoder};
use middle::astencode;
use middle::lang_items::{LangItem, ExchangeMallocFnLangItem, StartFnLangItem};
@ -73,7 +72,6 @@ use util::sha2::Sha256;
use util::nodemap::NodeMap;
use arena::TypedArena;
use collections::HashMap;
use std::c_str::ToCStr;
use std::cell::{Cell, RefCell};
use std::libc::c_uint;
@ -93,8 +91,6 @@ use syntax::{ast, ast_util, ast_map};
use time;
pub use middle::trans::context::task_llcx;
local_data_key!(task_local_insn_key: Vec<&'static str> )
pub fn with_insn_ctxt(blk: |&[&'static str]|) {
@ -136,14 +132,14 @@ pub fn push_ctxt(s: &'static str) -> _InsnCtxt {
}
pub struct StatRecorder<'a> {
ccx: &'a CrateContext<'a>,
ccx: &'a CrateContext,
name: Option<~str>,
start: u64,
istart: uint,
}
impl<'a> StatRecorder<'a> {
pub fn new(ccx: &'a CrateContext<'a>, name: ~str) -> StatRecorder<'a> {
pub fn new(ccx: &'a CrateContext, name: ~str) -> StatRecorder<'a> {
let start = if ccx.sess().trans_stats() {
time::precise_time_ns()
} else {
@ -393,7 +389,11 @@ pub fn malloc_raw_dyn<'a>(
let r = callee::trans_lang_call(
bcx,
langcall,
[PointerCast(bcx, drop_glue, Type::glue_fn(Type::i8p()).ptr_to()), size, llalign],
[
PointerCast(bcx, drop_glue, Type::glue_fn(ccx, Type::i8p(ccx)).ptr_to()),
size,
llalign
],
None);
rslt(r.bcx, PointerCast(r.bcx, r.val, llty))
}
@ -547,14 +547,14 @@ pub fn get_res_dtor(ccx: &CrateContext,
tps: Vec::from_slice(substs),
};
let vtables = typeck::check::vtable::trans_resolve_method(ccx.tcx, did.node, &tsubsts);
let vtables = typeck::check::vtable::trans_resolve_method(ccx.tcx(), did.node, &tsubsts);
let (val, _) = monomorphize::monomorphic_fn(ccx, did, &tsubsts, vtables, None, None);
val
} else if did.krate == ast::LOCAL_CRATE {
get_item_val(ccx, did.node)
} else {
let tcx = ccx.tcx;
let tcx = ccx.tcx();
let name = csearch::get_symbol(&ccx.sess().cstore, did);
let class_ty = ty::subst_tps(tcx,
substs,
@ -624,8 +624,8 @@ pub fn compare_scalar_values<'a>(
// We don't need to do actual comparisons for nil.
// () == () holds but () < () does not.
match op {
ast::BiEq | ast::BiLe | ast::BiGe => return C_i1(true),
ast::BiNe | ast::BiLt | ast::BiGt => return C_i1(false),
ast::BiEq | ast::BiLe | ast::BiGe => return C_i1(cx.ccx(), true),
ast::BiNe | ast::BiLt | ast::BiGt => return C_i1(cx.ccx(), false),
// refinements would be nice
_ => die(cx)
}
@ -744,7 +744,7 @@ pub fn iter_structural_ty<'r,
let ccx = fcx.ccx;
let repr = adt::represent_type(ccx, t);
let variants = ty::enum_variants(ccx.tcx, tid);
let variants = ty::enum_variants(ccx.tcx(), tid);
let n_variants = (*variants).len();
// NB: we must hit the discriminant first so that structural
@ -865,7 +865,7 @@ pub fn fail_if_zero<'a>(
}
_ => {
cx.sess().bug(~"fail-if-zero on unexpected type: " +
ty_to_str(cx.ccx().tcx, rhs_t));
ty_to_str(cx.tcx(), rhs_t));
}
};
with_cond(cx, is_zero, |bcx| {
@ -920,7 +920,7 @@ pub fn invoke<'a>(
-> (ValueRef, &'a Block<'a>) {
let _icx = push_ctxt("invoke_");
if bcx.unreachable.get() {
return (C_null(Type::i8()), bcx);
return (C_null(Type::i8(bcx.ccx())), bcx);
}
match bcx.opt_node_id {
@ -983,7 +983,7 @@ pub fn need_invoke(bcx: &Block) -> bool {
pub fn do_spill(bcx: &Block, v: ValueRef, t: ty::t) -> ValueRef {
if ty::type_is_bot(t) {
return C_null(Type::i8p());
return C_null(Type::i8p(bcx.ccx()));
}
let llptr = alloc_ty(bcx, t, "");
Store(bcx, v, llptr);
@ -1085,11 +1085,11 @@ pub fn call_memcpy(cx: &Block, dst: ValueRef, src: ValueRef, n_bytes: ValueRef,
X86_64 => "llvm.memcpy.p0i8.p0i8.i64"
};
let memcpy = ccx.intrinsics.get_copy(&key);
let src_ptr = PointerCast(cx, src, Type::i8p());
let dst_ptr = PointerCast(cx, dst, Type::i8p());
let src_ptr = PointerCast(cx, src, Type::i8p(ccx));
let dst_ptr = PointerCast(cx, dst, Type::i8p(ccx));
let size = IntCast(cx, n_bytes, ccx.int_type);
let align = C_i32(align as i32);
let volatile = C_i1(false);
let align = C_i32(ccx, align as i32);
let volatile = C_i1(ccx, false);
Call(cx, memcpy, [dst_ptr, src_ptr, size, align, volatile], []);
}
@ -1130,11 +1130,11 @@ fn memzero(b: &Builder, llptr: ValueRef, ty: Type) {
};
let llintrinsicfn = ccx.intrinsics.get_copy(&intrinsic_key);
let llptr = b.pointercast(llptr, Type::i8().ptr_to());
let llzeroval = C_u8(0);
let llptr = b.pointercast(llptr, Type::i8(ccx).ptr_to());
let llzeroval = C_u8(ccx, 0);
let size = machine::llsize_of(ccx, ty);
let align = C_i32(llalign_of_min(ccx, ty) as i32);
let volatile = C_i1(false);
let align = C_i32(ccx, llalign_of_min(ccx, ty) as i32);
let volatile = C_i1(ccx, false);
b.call(llintrinsicfn, [llptr, llzeroval, size, align, volatile], []);
}
@ -1183,24 +1183,6 @@ pub struct BasicBlocks {
sa: BasicBlockRef,
}
pub fn mk_staticallocas_basic_block(llfn: ValueRef) -> BasicBlockRef {
unsafe {
let cx = task_llcx();
"static_allocas".with_c_str(|buf| {
llvm::LLVMAppendBasicBlockInContext(cx, llfn, buf)
})
}
}
pub fn mk_return_basic_block(llfn: ValueRef) -> BasicBlockRef {
unsafe {
let cx = task_llcx();
"return".with_c_str(|buf| {
llvm::LLVMAppendBasicBlockInContext(cx, llfn, buf)
})
}
}
// Creates and returns space for, or returns the argument representing, the
// slot where the return value of the function must go.
pub fn make_return_pointer(fcx: &FunctionContext, output_type: ty::t)
@ -1225,7 +1207,7 @@ pub fn make_return_pointer(fcx: &FunctionContext, output_type: ty::t)
//
// Be warned! You must call `init_function` before doing anything with the
// returned function context.
pub fn new_fn_ctxt<'a>(ccx: &'a CrateContext<'a>,
pub fn new_fn_ctxt<'a>(ccx: &'a CrateContext,
llfndecl: ValueRef,
id: ast::NodeId,
has_env: bool,
@ -1238,12 +1220,12 @@ pub fn new_fn_ctxt<'a>(ccx: &'a CrateContext<'a>,
debug!("new_fn_ctxt(path={}, id={}, param_substs={})",
if id == -1 { ~"" } else { ccx.tcx.map.path_to_str(id) },
id, param_substs.repr(ccx.tcx));
id, param_substs.repr(ccx.tcx()));
let substd_output_type = match param_substs {
None => output_type,
Some(substs) => {
ty::subst_tps(ccx.tcx,
ty::subst_tps(ccx.tcx(),
substs.tys.as_slice(),
substs.self_ty,
output_type)
@ -1296,14 +1278,14 @@ pub fn init_function<'a>(
// Use a dummy instruction as the insertion point for all allocas.
// This is later removed in FunctionContext::cleanup.
fcx.alloca_insert_pt.set(Some(unsafe {
Load(entry_bcx, C_null(Type::i8p()));
Load(entry_bcx, C_null(Type::i8p(fcx.ccx)));
llvm::LLVMGetFirstInstruction(entry_bcx.llbb)
}));
let substd_output_type = match param_substs {
None => output_type,
Some(substs) => {
ty::subst_tps(fcx.ccx.tcx,
ty::subst_tps(fcx.ccx.tcx(),
substs.tys.as_slice(),
substs.self_ty,
output_type)
@ -1458,9 +1440,9 @@ pub fn trans_closure(ccx: &CrateContext,
set_uwtable(llfndecl);
debug!("trans_closure(..., param_substs={})",
param_substs.repr(ccx.tcx));
param_substs.repr(ccx.tcx()));
let has_env = match ty::get(ty::node_id_to_type(ccx.tcx, id)).sty {
let has_env = match ty::get(ty::node_id_to_type(ccx.tcx(), id)).sty {
ty::ty_closure(_) => true,
_ => false
};
@ -1551,9 +1533,9 @@ pub fn trans_fn(ccx: &CrateContext,
id: ast::NodeId,
attrs: &[ast::Attribute]) {
let _s = StatRecorder::new(ccx, ccx.tcx.map.path_to_str(id));
debug!("trans_fn(param_substs={})", param_substs.repr(ccx.tcx));
debug!("trans_fn(param_substs={})", param_substs.repr(ccx.tcx()));
let _icx = push_ctxt("trans_fn");
let output_type = ty::ty_fn_ret(ty::node_id_to_type(ccx.tcx, id));
let output_type = ty::ty_fn_ret(ty::node_id_to_type(ccx.tcx(), id));
trans_closure(ccx, decl, body, llfndecl,
param_substs, id, attrs, output_type, |bcx| bcx);
}
@ -1607,17 +1589,17 @@ fn trans_enum_variant_or_tuple_like_struct(ccx: &CrateContext,
}
};
let ctor_ty = ty::subst_tps(ccx.tcx,
let ctor_ty = ty::subst_tps(ccx.tcx(),
ty_param_substs,
None,
ty::node_id_to_type(ccx.tcx, ctor_id));
ty::node_id_to_type(ccx.tcx(), ctor_id));
let result_ty = match ty::get(ctor_ty).sty {
ty::ty_bare_fn(ref bft) => bft.sig.output,
_ => ccx.sess().bug(
format!("trans_enum_variant_or_tuple_like_struct: \
unexpected ctor return type {}",
ty_to_str(ccx.tcx, ctor_ty)))
ty_to_str(ccx.tcx(), ctor_ty)))
};
let arena = TypedArena::new();
@ -1671,7 +1653,7 @@ pub fn trans_enum_def(ccx: &CrateContext, enum_definition: &ast::EnumDef,
}
pub struct TransItemVisitor<'a> {
ccx: &'a CrateContext<'a>,
ccx: &'a CrateContext,
}
impl<'a> Visitor<()> for TransItemVisitor<'a> {
@ -1712,7 +1694,7 @@ pub fn trans_item(ccx: &CrateContext, item: &ast::Item) {
}
ast::ItemEnum(ref enum_definition, ref generics) => {
if !generics.is_type_parameterized() {
let vi = ty::enum_variants(ccx.tcx, local_def(item.id));
let vi = ty::enum_variants(ccx.tcx(), local_def(item.id));
let mut i = 0;
trans_enum_def(ccx, enum_definition, item.id, vi, &mut i);
}
@ -1858,7 +1840,7 @@ pub fn create_entry_wrapper(ccx: &CrateContext,
fn create_entry_fn(ccx: &CrateContext,
rust_main: ValueRef,
use_start_lang_item: bool) {
let llfty = Type::func([ccx.int_type, Type::i8().ptr_to().ptr_to()],
let llfty = Type::func([ccx.int_type, Type::i8p(ccx).ptr_to()],
&ccx.int_type);
let llfn = decl_cdecl_fn(ccx.llmod, "main", llfty, ty::mk_nil());
@ -1879,14 +1861,14 @@ pub fn create_entry_wrapper(ccx: &CrateContext,
let start_fn = if start_def_id.krate == ast::LOCAL_CRATE {
get_item_val(ccx, start_def_id.node)
} else {
let start_fn_type = csearch::get_type(ccx.tcx,
let start_fn_type = csearch::get_type(ccx.tcx(),
start_def_id).ty;
trans_external_path(ccx, start_def_id, start_fn_type)
};
let args = {
let opaque_rust_main = "rust_main".with_c_str(|buf| {
llvm::LLVMBuildPointerCast(bld, rust_main, Type::i8p().to_ref(), buf)
llvm::LLVMBuildPointerCast(bld, rust_main, Type::i8p(ccx).to_ref(), buf)
});
vec!(
@ -1950,7 +1932,7 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
let item = ccx.tcx.map.get(id);
let val = match item {
ast_map::NodeItem(i) => {
let ty = ty::node_id_to_type(ccx.tcx, i.id);
let ty = ty::node_id_to_type(ccx.tcx(), i.id);
let sym = exported_name(ccx, id, ty, i.attrs.as_slice());
let v = match i.node {
@ -2108,7 +2090,7 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
match v.node.kind {
ast::TupleVariantKind(ref args) => {
assert!(args.len() != 0u);
let ty = ty::node_id_to_type(ccx.tcx, id);
let ty = ty::node_id_to_type(ccx.tcx(), id);
let parent = ccx.tcx.map.get_parent(id);
let enm = ccx.tcx.map.expect_item(parent);
let sym = exported_name(ccx,
@ -2141,7 +2123,7 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
Some(ctor_id) => {
let parent = ccx.tcx.map.get_parent(id);
let struct_item = ccx.tcx.map.expect_item(parent);
let ty = ty::node_id_to_type(ccx.tcx, ctor_id);
let ty = ty::node_id_to_type(ccx.tcx(), ctor_id);
let sym = exported_name(ccx,
id,
ty,
@ -2177,7 +2159,7 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
fn register_method(ccx: &CrateContext, id: ast::NodeId,
m: &ast::Method) -> ValueRef {
let mty = ty::node_id_to_type(ccx.tcx, id);
let mty = ty::node_id_to_type(ccx.tcx(), id);
let sym = exported_name(ccx, id, mty, m.attrs.as_slice());
@ -2197,184 +2179,166 @@ pub fn p2i(ccx: &CrateContext, v: ValueRef) -> ValueRef {
}
}
macro_rules! ifn (
($intrinsics:ident, $name:expr, $args:expr, $ret:expr) => ({
let name = $name;
// HACK(eddyb) dummy output type, shouln't affect anything.
let f = decl_cdecl_fn(llmod, name, Type::func($args, &$ret), ty::mk_nil());
$intrinsics.insert(name, f);
})
)
pub fn declare_intrinsics(llmod: ModuleRef) -> HashMap<&'static str, ValueRef> {
let i8p = Type::i8p();
let mut intrinsics = HashMap::new();
pub fn declare_intrinsics(ccx: &mut CrateContext) {
macro_rules! ifn (
($name:expr fn() -> $ret:expr) => ({
let name = $name;
// HACK(eddyb) dummy output type, shouln't affect anything.
let f = decl_cdecl_fn(ccx.llmod, name, Type::func([], &$ret), ty::mk_nil());
ccx.intrinsics.insert(name, f);
});
($name:expr fn($($arg:expr),*) -> $ret:expr) => ({
let name = $name;
// HACK(eddyb) dummy output type, shouln't affect anything.
let f = decl_cdecl_fn(ccx.llmod, name,
Type::func([$($arg),*], &$ret), ty::mk_nil());
ccx.intrinsics.insert(name, f);
})
)
macro_rules! mk_struct (
($($field_ty:expr),*) => (Type::struct_(ccx, [$($field_ty),*], false))
)
ifn!(intrinsics, "llvm.memcpy.p0i8.p0i8.i32",
[i8p, i8p, Type::i32(), Type::i32(), Type::i1()], Type::void());
ifn!(intrinsics, "llvm.memcpy.p0i8.p0i8.i64",
[i8p, i8p, Type::i64(), Type::i32(), Type::i1()], Type::void());
ifn!(intrinsics, "llvm.memmove.p0i8.p0i8.i32",
[i8p, i8p, Type::i32(), Type::i32(), Type::i1()], Type::void());
ifn!(intrinsics, "llvm.memmove.p0i8.p0i8.i64",
[i8p, i8p, Type::i64(), Type::i32(), Type::i1()], Type::void());
ifn!(intrinsics, "llvm.memset.p0i8.i32",
[i8p, Type::i8(), Type::i32(), Type::i32(), Type::i1()], Type::void());
ifn!(intrinsics, "llvm.memset.p0i8.i64",
[i8p, Type::i8(), Type::i64(), Type::i32(), Type::i1()], Type::void());
let i8p = Type::i8p(ccx);
let void = Type::void(ccx);
let i1 = Type::i1(ccx);
let t_i8 = Type::i8(ccx);
let t_i16 = Type::i16(ccx);
let t_i32 = Type::i32(ccx);
let t_i64 = Type::i64(ccx);
let t_f32 = Type::f32(ccx);
let t_f64 = Type::f64(ccx);
ifn!(intrinsics, "llvm.trap", [], Type::void());
ifn!(intrinsics, "llvm.debugtrap", [], Type::void());
ifn!(intrinsics, "llvm.frameaddress", [Type::i32()], i8p);
ifn!("llvm.memcpy.p0i8.p0i8.i32" fn(i8p, i8p, t_i32, t_i32, i1) -> void);
ifn!("llvm.memcpy.p0i8.p0i8.i64" fn(i8p, i8p, t_i64, t_i32, i1) -> void);
ifn!("llvm.memmove.p0i8.p0i8.i32" fn(i8p, i8p, t_i32, t_i32, i1) -> void);
ifn!("llvm.memmove.p0i8.p0i8.i64" fn(i8p, i8p, t_i64, t_i32, i1) -> void);
ifn!("llvm.memset.p0i8.i32" fn(i8p, t_i8, t_i32, t_i32, i1) -> void);
ifn!("llvm.memset.p0i8.i64" fn(i8p, t_i8, t_i64, t_i32, i1) -> void);
ifn!(intrinsics, "llvm.powi.f32", [Type::f32(), Type::i32()], Type::f32());
ifn!(intrinsics, "llvm.powi.f64", [Type::f64(), Type::i32()], Type::f64());
ifn!(intrinsics, "llvm.pow.f32", [Type::f32(), Type::f32()], Type::f32());
ifn!(intrinsics, "llvm.pow.f64", [Type::f64(), Type::f64()], Type::f64());
ifn!("llvm.trap" fn() -> void);
ifn!("llvm.debugtrap" fn() -> void);
ifn!("llvm.frameaddress" fn(t_i32) -> i8p);
ifn!(intrinsics, "llvm.sqrt.f32", [Type::f32()], Type::f32());
ifn!(intrinsics, "llvm.sqrt.f64", [Type::f64()], Type::f64());
ifn!(intrinsics, "llvm.sin.f32", [Type::f32()], Type::f32());
ifn!(intrinsics, "llvm.sin.f64", [Type::f64()], Type::f64());
ifn!(intrinsics, "llvm.cos.f32", [Type::f32()], Type::f32());
ifn!(intrinsics, "llvm.cos.f64", [Type::f64()], Type::f64());
ifn!(intrinsics, "llvm.exp.f32", [Type::f32()], Type::f32());
ifn!(intrinsics, "llvm.exp.f64", [Type::f64()], Type::f64());
ifn!(intrinsics, "llvm.exp2.f32", [Type::f32()], Type::f32());
ifn!(intrinsics, "llvm.exp2.f64", [Type::f64()], Type::f64());
ifn!(intrinsics, "llvm.log.f32", [Type::f32()], Type::f32());
ifn!(intrinsics, "llvm.log.f64", [Type::f64()], Type::f64());
ifn!(intrinsics, "llvm.log10.f32",[Type::f32()], Type::f32());
ifn!(intrinsics, "llvm.log10.f64",[Type::f64()], Type::f64());
ifn!(intrinsics, "llvm.log2.f32", [Type::f32()], Type::f32());
ifn!(intrinsics, "llvm.log2.f64", [Type::f64()], Type::f64());
ifn!("llvm.powi.f32" fn(t_f32, t_i32) -> t_f32);
ifn!("llvm.powi.f64" fn(t_f64, t_i32) -> t_f64);
ifn!("llvm.pow.f32" fn(t_f32, t_f32) -> t_f32);
ifn!("llvm.pow.f64" fn(t_f64, t_f64) -> t_f64);
ifn!(intrinsics, "llvm.fma.f32", [Type::f32(), Type::f32(), Type::f32()], Type::f32());
ifn!(intrinsics, "llvm.fma.f64", [Type::f64(), Type::f64(), Type::f64()], Type::f64());
ifn!("llvm.sqrt.f32" fn(t_f32) -> t_f32);
ifn!("llvm.sqrt.f64" fn(t_f64) -> t_f64);
ifn!("llvm.sin.f32" fn(t_f32) -> t_f32);
ifn!("llvm.sin.f64" fn(t_f64) -> t_f64);
ifn!("llvm.cos.f32" fn(t_f32) -> t_f32);
ifn!("llvm.cos.f64" fn(t_f64) -> t_f64);
ifn!("llvm.exp.f32" fn(t_f32) -> t_f32);
ifn!("llvm.exp.f64" fn(t_f64) -> t_f64);
ifn!("llvm.exp2.f32" fn(t_f32) -> t_f32);
ifn!("llvm.exp2.f64" fn(t_f64) -> t_f64);
ifn!("llvm.log.f32" fn(t_f32) -> t_f32);
ifn!("llvm.log.f64" fn(t_f64) -> t_f64);
ifn!("llvm.log10.f32" fn(t_f32) -> t_f32);
ifn!("llvm.log10.f64" fn(t_f64) -> t_f64);
ifn!("llvm.log2.f32" fn(t_f32) -> t_f32);
ifn!("llvm.log2.f64" fn(t_f64) -> t_f64);
ifn!(intrinsics, "llvm.fabs.f32", [Type::f32()], Type::f32());
ifn!(intrinsics, "llvm.fabs.f64", [Type::f64()], Type::f64());
ifn!("llvm.fma.f32" fn(t_f32, t_f32, t_f32) -> t_f32);
ifn!("llvm.fma.f64" fn(t_f64, t_f64, t_f64) -> t_f64);
ifn!(intrinsics, "llvm.floor.f32",[Type::f32()], Type::f32());
ifn!(intrinsics, "llvm.floor.f64",[Type::f64()], Type::f64());
ifn!(intrinsics, "llvm.ceil.f32", [Type::f32()], Type::f32());
ifn!(intrinsics, "llvm.ceil.f64", [Type::f64()], Type::f64());
ifn!(intrinsics, "llvm.trunc.f32",[Type::f32()], Type::f32());
ifn!(intrinsics, "llvm.trunc.f64",[Type::f64()], Type::f64());
ifn!("llvm.fabs.f32" fn(t_f32) -> t_f32);
ifn!("llvm.fabs.f64" fn(t_f64) -> t_f64);
ifn!(intrinsics, "llvm.rint.f32", [Type::f32()], Type::f32());
ifn!(intrinsics, "llvm.rint.f64", [Type::f64()], Type::f64());
ifn!(intrinsics, "llvm.nearbyint.f32", [Type::f32()], Type::f32());
ifn!(intrinsics, "llvm.nearbyint.f64", [Type::f64()], Type::f64());
ifn!("llvm.floor.f32" fn(t_f32) -> t_f32);
ifn!("llvm.floor.f64" fn(t_f64) -> t_f64);
ifn!("llvm.ceil.f32" fn(t_f32) -> t_f32);
ifn!("llvm.ceil.f64" fn(t_f64) -> t_f64);
ifn!("llvm.trunc.f32" fn(t_f32) -> t_f32);
ifn!("llvm.trunc.f64" fn(t_f64) -> t_f64);
ifn!(intrinsics, "llvm.ctpop.i8", [Type::i8()], Type::i8());
ifn!(intrinsics, "llvm.ctpop.i16",[Type::i16()], Type::i16());
ifn!(intrinsics, "llvm.ctpop.i32",[Type::i32()], Type::i32());
ifn!(intrinsics, "llvm.ctpop.i64",[Type::i64()], Type::i64());
ifn!("llvm.rint.f32" fn(t_f32) -> t_f32);
ifn!("llvm.rint.f64" fn(t_f64) -> t_f64);
ifn!("llvm.nearbyint.f32" fn(t_f32) -> t_f32);
ifn!("llvm.nearbyint.f64" fn(t_f64) -> t_f64);
ifn!(intrinsics, "llvm.ctlz.i8", [Type::i8() , Type::i1()], Type::i8());
ifn!(intrinsics, "llvm.ctlz.i16", [Type::i16(), Type::i1()], Type::i16());
ifn!(intrinsics, "llvm.ctlz.i32", [Type::i32(), Type::i1()], Type::i32());
ifn!(intrinsics, "llvm.ctlz.i64", [Type::i64(), Type::i1()], Type::i64());
ifn!("llvm.ctpop.i8" fn(t_i8) -> t_i8);
ifn!("llvm.ctpop.i16" fn(t_i16) -> t_i16);
ifn!("llvm.ctpop.i32" fn(t_i32) -> t_i32);
ifn!("llvm.ctpop.i64" fn(t_i64) -> t_i64);
ifn!(intrinsics, "llvm.cttz.i8", [Type::i8() , Type::i1()], Type::i8());
ifn!(intrinsics, "llvm.cttz.i16", [Type::i16(), Type::i1()], Type::i16());
ifn!(intrinsics, "llvm.cttz.i32", [Type::i32(), Type::i1()], Type::i32());
ifn!(intrinsics, "llvm.cttz.i64", [Type::i64(), Type::i1()], Type::i64());
ifn!("llvm.ctlz.i8" fn(t_i8 , i1) -> t_i8);
ifn!("llvm.ctlz.i16" fn(t_i16, i1) -> t_i16);
ifn!("llvm.ctlz.i32" fn(t_i32, i1) -> t_i32);
ifn!("llvm.ctlz.i64" fn(t_i64, i1) -> t_i64);
ifn!(intrinsics, "llvm.bswap.i16",[Type::i16()], Type::i16());
ifn!(intrinsics, "llvm.bswap.i32",[Type::i32()], Type::i32());
ifn!(intrinsics, "llvm.bswap.i64",[Type::i64()], Type::i64());
ifn!("llvm.cttz.i8" fn(t_i8 , i1) -> t_i8);
ifn!("llvm.cttz.i16" fn(t_i16, i1) -> t_i16);
ifn!("llvm.cttz.i32" fn(t_i32, i1) -> t_i32);
ifn!("llvm.cttz.i64" fn(t_i64, i1) -> t_i64);
ifn!(intrinsics, "llvm.sadd.with.overflow.i8",
[Type::i8(), Type::i8()], Type::struct_([Type::i8(), Type::i1()], false));
ifn!(intrinsics, "llvm.sadd.with.overflow.i16",
[Type::i16(), Type::i16()], Type::struct_([Type::i16(), Type::i1()], false));
ifn!(intrinsics, "llvm.sadd.with.overflow.i32",
[Type::i32(), Type::i32()], Type::struct_([Type::i32(), Type::i1()], false));
ifn!(intrinsics, "llvm.sadd.with.overflow.i64",
[Type::i64(), Type::i64()], Type::struct_([Type::i64(), Type::i1()], false));
ifn!("llvm.bswap.i16" fn(t_i16) -> t_i16);
ifn!("llvm.bswap.i32" fn(t_i32) -> t_i32);
ifn!("llvm.bswap.i64" fn(t_i64) -> t_i64);
ifn!(intrinsics, "llvm.uadd.with.overflow.i8",
[Type::i8(), Type::i8()], Type::struct_([Type::i8(), Type::i1()], false));
ifn!(intrinsics, "llvm.uadd.with.overflow.i16",
[Type::i16(), Type::i16()], Type::struct_([Type::i16(), Type::i1()], false));
ifn!(intrinsics, "llvm.uadd.with.overflow.i32",
[Type::i32(), Type::i32()], Type::struct_([Type::i32(), Type::i1()], false));
ifn!(intrinsics, "llvm.uadd.with.overflow.i64",
[Type::i64(), Type::i64()], Type::struct_([Type::i64(), Type::i1()], false));
ifn!("llvm.sadd.with.overflow.i8" fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
ifn!("llvm.sadd.with.overflow.i16" fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
ifn!("llvm.sadd.with.overflow.i32" fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
ifn!("llvm.sadd.with.overflow.i64" fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
ifn!(intrinsics, "llvm.ssub.with.overflow.i8",
[Type::i8(), Type::i8()], Type::struct_([Type::i8(), Type::i1()], false));
ifn!(intrinsics, "llvm.ssub.with.overflow.i16",
[Type::i16(), Type::i16()], Type::struct_([Type::i16(), Type::i1()], false));
ifn!(intrinsics, "llvm.ssub.with.overflow.i32",
[Type::i32(), Type::i32()], Type::struct_([Type::i32(), Type::i1()], false));
ifn!(intrinsics, "llvm.ssub.with.overflow.i64",
[Type::i64(), Type::i64()], Type::struct_([Type::i64(), Type::i1()], false));
ifn!("llvm.uadd.with.overflow.i8" fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
ifn!("llvm.uadd.with.overflow.i16" fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
ifn!("llvm.uadd.with.overflow.i32" fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
ifn!("llvm.uadd.with.overflow.i64" fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
ifn!(intrinsics, "llvm.usub.with.overflow.i8",
[Type::i8(), Type::i8()], Type::struct_([Type::i8(), Type::i1()], false));
ifn!(intrinsics, "llvm.usub.with.overflow.i16",
[Type::i16(), Type::i16()], Type::struct_([Type::i16(), Type::i1()], false));
ifn!(intrinsics, "llvm.usub.with.overflow.i32",
[Type::i32(), Type::i32()], Type::struct_([Type::i32(), Type::i1()], false));
ifn!(intrinsics, "llvm.usub.with.overflow.i64",
[Type::i64(), Type::i64()], Type::struct_([Type::i64(), Type::i1()], false));
ifn!("llvm.ssub.with.overflow.i8" fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
ifn!("llvm.ssub.with.overflow.i16" fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
ifn!("llvm.ssub.with.overflow.i32" fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
ifn!("llvm.ssub.with.overflow.i64" fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
ifn!(intrinsics, "llvm.smul.with.overflow.i8",
[Type::i8(), Type::i8()], Type::struct_([Type::i8(), Type::i1()], false));
ifn!(intrinsics, "llvm.smul.with.overflow.i16",
[Type::i16(), Type::i16()], Type::struct_([Type::i16(), Type::i1()], false));
ifn!(intrinsics, "llvm.smul.with.overflow.i32",
[Type::i32(), Type::i32()], Type::struct_([Type::i32(), Type::i1()], false));
ifn!(intrinsics, "llvm.smul.with.overflow.i64",
[Type::i64(), Type::i64()], Type::struct_([Type::i64(), Type::i1()], false));
ifn!("llvm.usub.with.overflow.i8" fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
ifn!("llvm.usub.with.overflow.i16" fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
ifn!("llvm.usub.with.overflow.i32" fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
ifn!("llvm.usub.with.overflow.i64" fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
ifn!(intrinsics, "llvm.umul.with.overflow.i8",
[Type::i8(), Type::i8()], Type::struct_([Type::i8(), Type::i1()], false));
ifn!(intrinsics, "llvm.umul.with.overflow.i16",
[Type::i16(), Type::i16()], Type::struct_([Type::i16(), Type::i1()], false));
ifn!(intrinsics, "llvm.umul.with.overflow.i32",
[Type::i32(), Type::i32()], Type::struct_([Type::i32(), Type::i1()], false));
ifn!(intrinsics, "llvm.umul.with.overflow.i64",
[Type::i64(), Type::i64()], Type::struct_([Type::i64(), Type::i1()], false));
ifn!("llvm.smul.with.overflow.i8" fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
ifn!("llvm.smul.with.overflow.i16" fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
ifn!("llvm.smul.with.overflow.i32" fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
ifn!("llvm.smul.with.overflow.i64" fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
ifn!(intrinsics, "llvm.expect.i1", [Type::i1(), Type::i1()], Type::i1());
ifn!("llvm.umul.with.overflow.i8" fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
ifn!("llvm.umul.with.overflow.i16" fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
ifn!("llvm.umul.with.overflow.i32" fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
ifn!("llvm.umul.with.overflow.i64" fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
ifn!("llvm.expect.i1" fn(i1, i1) -> i1);
// Some intrinsics were introduced in later versions of LLVM, but they have
// fallbacks in libc or libm and such. Currently, all of these intrinsics
// were introduced in LLVM 3.4, so we case on that.
macro_rules! compatible_ifn (
($intrinsics:ident, $name:expr, $cname:expr, $args:expr, $ret:expr) => ({
($name:expr, $cname:ident ($($arg:expr),*) -> $ret:expr) => ({
let name = $name;
if unsafe { llvm::LLVMVersionMinor() >= 4 } {
ifn!($intrinsics, $name, $args, $ret);
ifn!(name fn($($arg),*) -> $ret);
} else {
let f = decl_cdecl_fn(llmod, $cname,
Type::func($args, &$ret),
let f = decl_cdecl_fn(ccx.llmod, stringify!($cname),
Type::func([$($arg),*], &$ret),
ty::mk_nil());
$intrinsics.insert(name, f);
ccx.intrinsics.insert(name, f);
}
})
)
compatible_ifn!(intrinsics, "llvm.copysign.f32", "copysignf",
[Type::f32(), Type::f32()], Type::f32());
compatible_ifn!(intrinsics, "llvm.copysign.f64", "copysign",
[Type::f64(), Type::f64()], Type::f64());
compatible_ifn!(intrinsics, "llvm.round.f32", "roundf",
[Type::f32()], Type::f32());
compatible_ifn!(intrinsics, "llvm.round.f64", "round",
[Type::f64()], Type::f64());
compatible_ifn!("llvm.copysign.f32", copysignf(t_f32, t_f32) -> t_f32);
compatible_ifn!("llvm.copysign.f64", copysign(t_f64, t_f64) -> t_f64);
compatible_ifn!("llvm.round.f32", roundf(t_f32) -> t_f32);
compatible_ifn!("llvm.round.f64", round(t_f64) -> t_f64);
return intrinsics;
}
pub fn declare_dbg_intrinsics(llmod: ModuleRef, intrinsics: &mut HashMap<&'static str, ValueRef>) {
ifn!(intrinsics, "llvm.dbg.declare", [Type::metadata(), Type::metadata()], Type::void());
ifn!(intrinsics,
"llvm.dbg.value", [Type::metadata(), Type::i64(), Type::metadata()], Type::void());
if ccx.sess().opts.debuginfo != NoDebugInfo {
ifn!("llvm.dbg.declare" fn(Type::metadata(ccx), Type::metadata(ccx)) -> void);
ifn!("llvm.dbg.value" fn(Type::metadata(ccx), t_i64, Type::metadata(ccx)) -> void);
}
}
pub fn trap(bcx: &Block) {
@ -2389,40 +2353,39 @@ pub fn symname(name: &str, hash: &str, vers: &str) -> ~str {
link::exported_name(ast_map::Values(path.iter()).chain(None), hash, vers)
}
pub fn decl_crate_map(sess: &Session, mapmeta: LinkMeta,
llmod: ModuleRef) -> (~str, ValueRef) {
let targ_cfg = sess.targ_cfg;
let int_type = Type::int(targ_cfg.arch);
pub fn decl_crate_map(ccx: &mut CrateContext) {
let mut n_subcrates = 1;
let cstore = &sess.cstore;
while cstore.have_crate_data(n_subcrates) { n_subcrates += 1; }
let is_top = !sess.building_library.get() || sess.opts.cg.gen_crate_map;
while ccx.sess().cstore.have_crate_data(n_subcrates) {
n_subcrates += 1;
}
let is_top = !ccx.sess().building_library.get() || ccx.sess().opts.cg.gen_crate_map;
let sym_name = if is_top {
~"_rust_crate_map_toplevel"
} else {
symname("_rust_crate_map_" + mapmeta.crateid.name,
mapmeta.crate_hash.as_str(),
mapmeta.crateid.version_or_default())
symname("_rust_crate_map_" + ccx.link_meta.crateid.name,
ccx.link_meta.crate_hash.as_str(),
ccx.link_meta.crateid.version_or_default())
};
let maptype = Type::struct_([
Type::i32(), // version
int_type.ptr_to(), // event loop factory
let maptype = Type::struct_(ccx, [
Type::i32(ccx), // version
ccx.int_type.ptr_to(), // event loop factory
], false);
let map = sym_name.with_c_str(|buf| {
unsafe {
llvm::LLVMAddGlobal(llmod, maptype.to_ref(), buf)
llvm::LLVMAddGlobal(ccx.llmod, maptype.to_ref(), buf)
}
});
lib::llvm::SetLinkage(map, lib::llvm::ExternalLinkage);
// On windows we'd like to export the toplevel cratemap
// such that we can find it from libstd.
if targ_cfg.os == OsWin32 && is_top {
if ccx.sess().targ_cfg.os == OsWin32 && is_top {
unsafe { llvm::LLVMRustSetDLLExportStorageClass(map) }
}
return (sym_name, map);
ccx.crate_map_name = sym_name;
ccx.crate_map = map;
}
pub fn fill_crate_map(ccx: &CrateContext, map: ValueRef) {
@ -2442,8 +2405,8 @@ pub fn fill_crate_map(ccx: &CrateContext, map: ValueRef) {
None => C_null(ccx.int_type.ptr_to())
};
unsafe {
llvm::LLVMSetInitializer(map, C_struct(
[C_i32(2),
llvm::LLVMSetInitializer(map, C_struct(ccx,
[C_i32(ccx, 2),
event_loop_factory,
], false));
}
@ -2457,7 +2420,7 @@ pub fn crate_ctxt_to_encode_parms<'r>(cx: &'r CrateContext, ie: encoder::EncodeI
let link_meta = &cx.link_meta;
encoder::EncodeParams {
diag: diag,
tcx: cx.tcx,
tcx: cx.tcx(),
reexports2: cx.exp_map2,
item_symbols: item_symbols,
non_inlineable_statics: &cx.non_inlineable_statics,
@ -2475,14 +2438,14 @@ pub fn write_metadata(cx: &CrateContext, krate: &ast::Crate) -> Vec<u8> {
}
let encode_inlined_item: encoder::EncodeInlinedItem =
|ecx, ebml_w, ii| astencode::encode_inlined_item(ecx, ebml_w, ii, cx.maps);
|ecx, ebml_w, ii| astencode::encode_inlined_item(ecx, ebml_w, ii, &cx.maps);
let encode_parms = crate_ctxt_to_encode_parms(cx, encode_inlined_item);
let metadata = encoder::encode_metadata(encode_parms, krate);
let compressed = encoder::metadata_encoding_version +
flate::deflate_bytes(metadata.as_slice()).as_slice();
let llmeta = C_bytes(compressed);
let llconst = C_struct([llmeta], false);
let llmeta = C_bytes(cx, compressed);
let llconst = C_struct(cx, [llmeta], false);
let name = format!("rust_metadata_{}_{}_{}", cx.link_meta.crateid.name,
cx.link_meta.crateid.version_or_default(), cx.link_meta.crate_hash);
let llglobal = name.with_c_str(|buf| {
@ -2500,8 +2463,10 @@ pub fn write_metadata(cx: &CrateContext, krate: &ast::Crate) -> Vec<u8> {
}
pub fn trans_crate(krate: ast::Crate,
analysis: &CrateAnalysis,
output: &OutputFilenames) -> CrateTranslation {
analysis: CrateAnalysis,
output: &OutputFilenames) -> (ty::ctxt, CrateTranslation) {
let CrateAnalysis { ty_cx: tcx, exp_map2, maps, reachable, .. } = analysis;
// Before we touch LLVM, make sure that multithreading is enabled.
unsafe {
use sync::one::{Once, ONCE_INIT};
@ -2516,7 +2481,7 @@ pub fn trans_crate(krate: ast::Crate,
});
if POISONED {
analysis.ty_cx.sess.bug("couldn't enable multi-threaded LLVM");
tcx.sess.bug("couldn't enable multi-threaded LLVM");
}
}
@ -2532,19 +2497,14 @@ pub fn trans_crate(krate: ast::Crate,
// 1. http://llvm.org/bugs/show_bug.cgi?id=11479
let llmod_id = link_meta.crateid.name + ".rs";
let ccx = &CrateContext::new(llmod_id,
&analysis.ty_cx,
analysis.exp_map2,
analysis.maps,
Sha256::new(),
link_meta,
&analysis.reachable);
let ccx = CrateContext::new(llmod_id, tcx, exp_map2, maps,
Sha256::new(), link_meta, reachable);
{
let _icx = push_ctxt("text");
trans_mod(ccx, &krate.module);
trans_mod(&ccx, &krate.module);
}
fill_crate_map(ccx, ccx.crate_map);
fill_crate_map(&ccx, ccx.crate_map);
// win32: wart with exporting crate_map symbol
// We set the crate map (_rust_crate_map_toplevel) to use dll_export
@ -2564,13 +2524,13 @@ pub fn trans_crate(krate: ast::Crate,
})
}
glue::emit_tydescs(ccx);
glue::emit_tydescs(&ccx);
if ccx.sess().opts.debuginfo != NoDebugInfo {
debuginfo::finalize(ccx);
debuginfo::finalize(&ccx);
}
// Translate the metadata.
let metadata = write_metadata(ccx, &krate);
let metadata = write_metadata(&ccx, &krate);
if ccx.sess().trans_stats() {
println!("--- trans stats ---");
println!("n_static_tydescs: {}", ccx.stats.n_static_tydescs.get());
@ -2583,16 +2543,14 @@ pub fn trans_crate(krate: ast::Crate,
println!("n_inlines: {}", ccx.stats.n_inlines.get());
println!("n_closures: {}", ccx.stats.n_closures.get());
println!("fn stats:");
{
let mut fn_stats = ccx.stats.fn_stats.borrow_mut();
fn_stats.get().sort_by(|&(_, _, insns_a), &(_, _, insns_b)| {
insns_b.cmp(&insns_a)
});
for tuple in fn_stats.get().iter() {
match *tuple {
(ref name, ms, insns) => {
println!("{} insns, {} ms, {}", insns, ms, *name);
}
let mut fn_stats = ccx.stats.fn_stats.borrow_mut();
fn_stats.get().sort_by(|&(_, _, insns_a), &(_, _, insns_b)| {
insns_b.cmp(&insns_a)
});
for tuple in fn_stats.get().iter() {
match *tuple {
(ref name, ms, insns) => {
println!("{} insns, {} ms, {}", insns, ms, *name);
}
}
}
@ -2624,12 +2582,14 @@ pub fn trans_crate(krate: ast::Crate,
reachable.push(~"rust_eh_personality"); // referenced from .eh_frame section on some platforms
reachable.push(~"rust_eh_personality_catch"); // referenced from rt/rust_try.ll
CrateTranslation {
let metadata_module = ccx.metadata_llmod;
(ccx.tcx, CrateTranslation {
context: llcx,
module: llmod,
link: link_meta,
metadata_module: ccx.metadata_llmod,
metadata_module: metadata_module,
metadata: metadata,
reachable: reachable,
}
})
}

View file

@ -115,7 +115,7 @@ pub fn Invoke(cx: &Block,
attributes: &[(uint, lib::llvm::Attribute)])
-> ValueRef {
if cx.unreachable.get() {
return C_null(Type::i8());
return C_null(Type::i8(cx.ccx()));
}
check_not_terminated(cx);
terminate(cx, "Invoke");
@ -300,14 +300,18 @@ pub fn Not(cx: &Block, v: ValueRef) -> ValueRef {
/* Memory */
pub fn Malloc(cx: &Block, ty: Type) -> ValueRef {
unsafe {
if cx.unreachable.get() { return llvm::LLVMGetUndef(Type::i8p().to_ref()); }
if cx.unreachable.get() {
return llvm::LLVMGetUndef(Type::i8p(cx.ccx()).to_ref());
}
B(cx).malloc(ty)
}
}
pub fn ArrayMalloc(cx: &Block, ty: Type, val: ValueRef) -> ValueRef {
unsafe {
if cx.unreachable.get() { return llvm::LLVMGetUndef(Type::i8p().to_ref()); }
if cx.unreachable.get() {
return llvm::LLVMGetUndef(Type::i8p(cx.ccx()).to_ref());
}
B(cx).array_malloc(ty, val)
}
}
@ -357,7 +361,9 @@ pub fn Load(cx: &Block, pointer_val: ValueRef) -> ValueRef {
pub fn VolatileLoad(cx: &Block, pointer_val: ValueRef) -> ValueRef {
unsafe {
if cx.unreachable.get() { return llvm::LLVMGetUndef(Type::nil().to_ref()); }
if cx.unreachable.get() {
return llvm::LLVMGetUndef(Type::nil(cx.ccx()).to_ref());
}
B(cx).volatile_load(pointer_val)
}
}
@ -408,7 +414,9 @@ pub fn AtomicStore(cx: &Block, val: ValueRef, ptr: ValueRef, order: AtomicOrderi
pub fn GEP(cx: &Block, pointer: ValueRef, indices: &[ValueRef]) -> ValueRef {
unsafe {
if cx.unreachable.get() { return llvm::LLVMGetUndef(Type::nil().ptr_to().to_ref()); }
if cx.unreachable.get() {
return llvm::LLVMGetUndef(Type::nil(cx.ccx()).ptr_to().to_ref());
}
B(cx).gep(pointer, indices)
}
}
@ -418,35 +426,45 @@ pub fn GEP(cx: &Block, pointer: ValueRef, indices: &[ValueRef]) -> ValueRef {
#[inline]
pub fn GEPi(cx: &Block, base: ValueRef, ixs: &[uint]) -> ValueRef {
unsafe {
if cx.unreachable.get() { return llvm::LLVMGetUndef(Type::nil().ptr_to().to_ref()); }
if cx.unreachable.get() {
return llvm::LLVMGetUndef(Type::nil(cx.ccx()).ptr_to().to_ref());
}
B(cx).gepi(base, ixs)
}
}
pub fn InBoundsGEP(cx: &Block, pointer: ValueRef, indices: &[ValueRef]) -> ValueRef {
unsafe {
if cx.unreachable.get() { return llvm::LLVMGetUndef(Type::nil().ptr_to().to_ref()); }
if cx.unreachable.get() {
return llvm::LLVMGetUndef(Type::nil(cx.ccx()).ptr_to().to_ref());
}
B(cx).inbounds_gep(pointer, indices)
}
}
pub fn StructGEP(cx: &Block, pointer: ValueRef, idx: uint) -> ValueRef {
unsafe {
if cx.unreachable.get() { return llvm::LLVMGetUndef(Type::nil().ptr_to().to_ref()); }
if cx.unreachable.get() {
return llvm::LLVMGetUndef(Type::nil(cx.ccx()).ptr_to().to_ref());
}
B(cx).struct_gep(pointer, idx)
}
}
pub fn GlobalString(cx: &Block, _str: *c_char) -> ValueRef {
unsafe {
if cx.unreachable.get() { return llvm::LLVMGetUndef(Type::i8p().to_ref()); }
if cx.unreachable.get() {
return llvm::LLVMGetUndef(Type::i8p(cx.ccx()).to_ref());
}
B(cx).global_string(_str)
}
}
pub fn GlobalStringPtr(cx: &Block, _str: *c_char) -> ValueRef {
unsafe {
if cx.unreachable.get() { return llvm::LLVMGetUndef(Type::i8p().to_ref()); }
if cx.unreachable.get() {
return llvm::LLVMGetUndef(Type::i8p(cx.ccx()).to_ref());
}
B(cx).global_string_ptr(_str)
}
}
@ -591,7 +609,9 @@ pub fn FPCast(cx: &Block, val: ValueRef, dest_ty: Type) -> ValueRef {
pub fn ICmp(cx: &Block, op: IntPredicate, lhs: ValueRef, rhs: ValueRef)
-> ValueRef {
unsafe {
if cx.unreachable.get() { return llvm::LLVMGetUndef(Type::i1().to_ref()); }
if cx.unreachable.get() {
return llvm::LLVMGetUndef(Type::i1(cx.ccx()).to_ref());
}
B(cx).icmp(op, lhs, rhs)
}
}
@ -599,7 +619,9 @@ pub fn ICmp(cx: &Block, op: IntPredicate, lhs: ValueRef, rhs: ValueRef)
pub fn FCmp(cx: &Block, op: RealPredicate, lhs: ValueRef, rhs: ValueRef)
-> ValueRef {
unsafe {
if cx.unreachable.get() { return llvm::LLVMGetUndef(Type::i1().to_ref()); }
if cx.unreachable.get() {
return llvm::LLVMGetUndef(Type::i1(cx.ccx()).to_ref());
}
B(cx).fcmp(op, lhs, rhs)
}
}
@ -686,7 +708,9 @@ pub fn VAArg(cx: &Block, list: ValueRef, ty: Type) -> ValueRef {
pub fn ExtractElement(cx: &Block, vec_val: ValueRef, index: ValueRef) -> ValueRef {
unsafe {
if cx.unreachable.get() { return llvm::LLVMGetUndef(Type::nil().to_ref()); }
if cx.unreachable.get() {
return llvm::LLVMGetUndef(Type::nil(cx.ccx()).to_ref());
}
B(cx).extract_element(vec_val, index)
}
}
@ -694,7 +718,9 @@ pub fn ExtractElement(cx: &Block, vec_val: ValueRef, index: ValueRef) -> ValueRe
pub fn InsertElement(cx: &Block, vec_val: ValueRef, elt_val: ValueRef,
index: ValueRef) -> ValueRef {
unsafe {
if cx.unreachable.get() { return llvm::LLVMGetUndef(Type::nil().to_ref()); }
if cx.unreachable.get() {
return llvm::LLVMGetUndef(Type::nil(cx.ccx()).to_ref());
}
B(cx).insert_element(vec_val, elt_val, index)
}
}
@ -702,42 +728,54 @@ pub fn InsertElement(cx: &Block, vec_val: ValueRef, elt_val: ValueRef,
pub fn ShuffleVector(cx: &Block, v1: ValueRef, v2: ValueRef,
mask: ValueRef) -> ValueRef {
unsafe {
if cx.unreachable.get() { return llvm::LLVMGetUndef(Type::nil().to_ref()); }
if cx.unreachable.get() {
return llvm::LLVMGetUndef(Type::nil(cx.ccx()).to_ref());
}
B(cx).shuffle_vector(v1, v2, mask)
}
}
pub fn VectorSplat(cx: &Block, num_elts: uint, elt_val: ValueRef) -> ValueRef {
unsafe {
if cx.unreachable.get() { return llvm::LLVMGetUndef(Type::nil().to_ref()); }
if cx.unreachable.get() {
return llvm::LLVMGetUndef(Type::nil(cx.ccx()).to_ref());
}
B(cx).vector_splat(num_elts, elt_val)
}
}
pub fn ExtractValue(cx: &Block, agg_val: ValueRef, index: uint) -> ValueRef {
unsafe {
if cx.unreachable.get() { return llvm::LLVMGetUndef(Type::nil().to_ref()); }
if cx.unreachable.get() {
return llvm::LLVMGetUndef(Type::nil(cx.ccx()).to_ref());
}
B(cx).extract_value(agg_val, index)
}
}
pub fn InsertValue(cx: &Block, agg_val: ValueRef, elt_val: ValueRef, index: uint) -> ValueRef {
unsafe {
if cx.unreachable.get() { return llvm::LLVMGetUndef(Type::nil().to_ref()); }
if cx.unreachable.get() {
return llvm::LLVMGetUndef(Type::nil(cx.ccx()).to_ref());
}
B(cx).insert_value(agg_val, elt_val, index)
}
}
pub fn IsNull(cx: &Block, val: ValueRef) -> ValueRef {
unsafe {
if cx.unreachable.get() { return llvm::LLVMGetUndef(Type::i1().to_ref()); }
if cx.unreachable.get() {
return llvm::LLVMGetUndef(Type::i1(cx.ccx()).to_ref());
}
B(cx).is_null(val)
}
}
pub fn IsNotNull(cx: &Block, val: ValueRef) -> ValueRef {
unsafe {
if cx.unreachable.get() { return llvm::LLVMGetUndef(Type::i1().to_ref()); }
if cx.unreachable.get() {
return llvm::LLVMGetUndef(Type::i1(cx.ccx()).to_ref());
}
B(cx).is_not_null(val)
}
}

View file

@ -25,7 +25,7 @@ use syntax::codemap::Span;
pub struct Builder<'a> {
llbuilder: BuilderRef,
ccx: &'a CrateContext<'a>,
ccx: &'a CrateContext,
}
// This is a really awful way to get a zero-length c-string, but better (and a
@ -536,13 +536,13 @@ impl<'a> Builder<'a> {
// Small vector optimization. This should catch 100% of the cases that
// we care about.
if ixs.len() < 16 {
let mut small_vec = [ C_i32(0), ..16 ];
let mut small_vec = [ C_i32(self.ccx, 0), ..16 ];
for (small_vec_e, &ix) in small_vec.mut_iter().zip(ixs.iter()) {
*small_vec_e = C_i32(ix as i32);
*small_vec_e = C_i32(self.ccx, ix as i32);
}
self.inbounds_gep(base, small_vec.slice(0, ixs.len()))
} else {
let v = ixs.iter().map(|i| C_i32(*i as i32)).collect::<Vec<ValueRef> >();
let v = ixs.iter().map(|i| C_i32(self.ccx, *i as i32)).collect::<Vec<ValueRef>>();
self.count_insn("gepi");
self.inbounds_gep(base, v.as_slice())
}
@ -762,7 +762,7 @@ impl<'a> Builder<'a> {
self.count_insn("inlineasm");
let asm = comment_text.with_c_str(|c| {
unsafe {
llvm::LLVMConstInlineAsm(Type::func([], &Type::void()).to_ref(),
llvm::LLVMConstInlineAsm(Type::func([], &Type::void(self.ccx)).to_ref(),
c, noname(), False, False)
}
});
@ -860,8 +860,9 @@ impl<'a> Builder<'a> {
unsafe {
let elt_ty = val_ty(elt);
let undef = llvm::LLVMGetUndef(Type::vector(&elt_ty, num_elts as u64).to_ref());
let vec = self.insert_element(undef, elt, C_i32(0));
self.shuffle_vector(vec, undef, C_null(Type::vector(&Type::i32(), num_elts as u64)))
let vec = self.insert_element(undef, elt, C_i32(self.ccx, 0));
let vec_i32_ty = Type::vector(&Type::i32(self.ccx), num_elts as u64);
self.shuffle_vector(vec, undef, C_null(vec_i32_ty))
}
}

View file

@ -85,34 +85,34 @@ fn ty_size(ty: Type) -> uint {
}
}
fn classify_ret_ty(ty: Type) -> ArgType {
fn classify_ret_ty(ccx: &CrateContext, ty: Type) -> ArgType {
if is_reg_ty(ty) {
return ArgType::direct(ty, None, None, None);
}
let size = ty_size(ty);
if size <= 4 {
let llty = if size <= 1 {
Type::i8()
Type::i8(ccx)
} else if size <= 2 {
Type::i16()
Type::i16(ccx)
} else {
Type::i32()
Type::i32(ccx)
};
return ArgType::direct(ty, Some(llty), None, None);
}
ArgType::indirect(ty, Some(StructRetAttribute))
}
fn classify_arg_ty(ty: Type) -> ArgType {
fn classify_arg_ty(ccx: &CrateContext, ty: Type) -> ArgType {
if is_reg_ty(ty) {
return ArgType::direct(ty, None, None, None);
}
let align = ty_align(ty);
let size = ty_size(ty);
let llty = if align <= 4 {
Type::array(&Type::i32(), ((size + 3) / 4) as u64)
Type::array(&Type::i32(ccx), ((size + 3) / 4) as u64)
} else {
Type::array(&Type::i64(), ((size + 7) / 8) as u64)
Type::array(&Type::i64(ccx), ((size + 7) / 8) as u64)
};
ArgType::direct(ty, Some(llty), None, None)
}
@ -127,20 +127,20 @@ fn is_reg_ty(ty: Type) -> bool {
}
}
pub fn compute_abi_info(_ccx: &CrateContext,
pub fn compute_abi_info(ccx: &CrateContext,
atys: &[Type],
rty: Type,
ret_def: bool) -> FnType {
let mut arg_tys = Vec::new();
for &aty in atys.iter() {
let ty = classify_arg_ty(aty);
let ty = classify_arg_ty(ccx, aty);
arg_tys.push(ty);
}
let ret_ty = if ret_def {
classify_ret_ty(rty)
classify_ret_ty(ccx, rty)
} else {
ArgType::direct(Type::void(), None, None, None)
ArgType::direct(Type::void(ccx), None, None, None)
};
return FnType {

View file

@ -15,7 +15,6 @@ use std::cmp;
use lib::llvm::{llvm, Integer, Pointer, Float, Double, Struct, Array};
use lib::llvm::StructRetAttribute;
use middle::trans::context::CrateContext;
use middle::trans::context::task_llcx;
use middle::trans::cabi::*;
use middle::trans::type_::Type;
@ -94,7 +93,7 @@ fn classify_ret_ty(ty: Type) -> ArgType {
}
}
fn classify_arg_ty(ty: Type, offset: &mut uint) -> ArgType {
fn classify_arg_ty(ccx: &CrateContext, ty: Type, offset: &mut uint) -> ArgType {
let orig_offset = *offset;
let size = ty_size(ty) * 8;
let mut align = ty_align(ty);
@ -108,8 +107,8 @@ fn classify_arg_ty(ty: Type, offset: &mut uint) -> ArgType {
} else {
ArgType::direct(
ty,
Some(struct_ty(ty)),
padding_ty(align, orig_offset),
Some(struct_ty(ccx, ty)),
padding_ty(ccx, align, orig_offset),
None
)
}
@ -125,16 +124,16 @@ fn is_reg_ty(ty: Type) -> bool {
};
}
fn padding_ty(align: uint, offset: uint) -> Option<Type> {
fn padding_ty(ccx: &CrateContext, align: uint, offset: uint) -> Option<Type> {
if ((align - 1 ) & offset) > 0 {
return Some(Type::i32());
Some(Type::i32(ccx))
} else {
None
}
return None;
}
fn coerce_to_int(size: uint) -> Vec<Type> {
let int_ty = Type::i32();
fn coerce_to_int(ccx: &CrateContext, size: uint) -> Vec<Type> {
let int_ty = Type::i32(ccx);
let mut args = Vec::new();
let mut n = size / 32;
@ -146,27 +145,26 @@ fn coerce_to_int(size: uint) -> Vec<Type> {
let r = size % 32;
if r > 0 {
unsafe {
args.push(Type::from_ref(llvm::LLVMIntTypeInContext(task_llcx(), r as c_uint)));
args.push(Type::from_ref(llvm::LLVMIntTypeInContext(ccx.llcx, r as c_uint)));
}
}
args
}
fn struct_ty(ty: Type) -> Type {
fn struct_ty(ccx: &CrateContext, ty: Type) -> Type {
let size = ty_size(ty) * 8;
let fields = coerce_to_int(size);
return Type::struct_(fields.as_slice(), false);
Type::struct_(ccx, coerce_to_int(ccx, size).as_slice(), false)
}
pub fn compute_abi_info(_ccx: &CrateContext,
pub fn compute_abi_info(ccx: &CrateContext,
atys: &[Type],
rty: Type,
ret_def: bool) -> FnType {
let ret_ty = if ret_def {
classify_ret_ty(rty)
} else {
ArgType::direct(Type::void(), None, None, None)
ArgType::direct(Type::void(ccx), None, None, None)
};
let sret = ret_ty.is_indirect();
@ -174,7 +172,7 @@ pub fn compute_abi_info(_ccx: &CrateContext,
let mut offset = if sret { 4 } else { 0 };
for aty in atys.iter() {
let ty = classify_arg_ty(*aty, &mut offset);
let ty = classify_arg_ty(ccx, *aty, &mut offset);
arg_tys.push(ty);
};

View file

@ -25,7 +25,7 @@ pub fn compute_abi_info(ccx: &CrateContext,
let ret_ty;
if !ret_def {
ret_ty = ArgType::direct(Type::void(), None, None, None);
ret_ty = ArgType::direct(Type::void(ccx), None, None, None);
} else if rty.kind() == Struct {
// Returning a structure. Most often, this will use
// a hidden first argument. On some platforms, though,
@ -39,10 +39,10 @@ pub fn compute_abi_info(ccx: &CrateContext,
let strategy = match ccx.sess().targ_cfg.os {
OsWin32 | OsMacos => {
match llsize_of_alloc(ccx, rty) {
1 => RetValue(Type::i8()),
2 => RetValue(Type::i16()),
4 => RetValue(Type::i32()),
8 => RetValue(Type::i64()),
1 => RetValue(Type::i8(ccx)),
2 => RetValue(Type::i16(ccx)),
4 => RetValue(Type::i32(ccx)),
8 => RetValue(Type::i64(ccx)),
_ => RetPointer
}
}

View file

@ -291,7 +291,7 @@ fn classify_ty(ty: Type) -> Vec<RegClass> {
return cls;
}
fn llreg_ty(cls: &[RegClass]) -> Type {
fn llreg_ty(ccx: &CrateContext, cls: &[RegClass]) -> Type {
fn llvec_len(cls: &[RegClass]) -> uint {
let mut len = 1u;
for c in cls.iter() {
@ -309,33 +309,34 @@ fn llreg_ty(cls: &[RegClass]) -> Type {
while i < e {
match cls[i] {
Int => {
tys.push(Type::i64());
tys.push(Type::i64(ccx));
}
SSEFv => {
let vec_len = llvec_len(cls.tailn(i + 1u));
let vec_ty = Type::vector(&Type::f32(), (vec_len * 2u) as u64);
let vec_ty = Type::vector(&Type::f32(ccx), (vec_len * 2u) as u64);
tys.push(vec_ty);
i += vec_len;
continue;
}
SSEFs => {
tys.push(Type::f32());
tys.push(Type::f32(ccx));
}
SSEDs => {
tys.push(Type::f64());
tys.push(Type::f64(ccx));
}
_ => fail!("llregtype: unhandled class")
}
i += 1u;
}
return Type::struct_(tys.as_slice(), false);
return Type::struct_(ccx, tys.as_slice(), false);
}
pub fn compute_abi_info(_ccx: &CrateContext,
pub fn compute_abi_info(ccx: &CrateContext,
atys: &[Type],
rty: Type,
ret_def: bool) -> FnType {
fn x86_64_ty(ty: Type,
fn x86_64_ty(ccx: &CrateContext,
ty: Type,
is_mem_cls: |cls: &[RegClass]| -> bool,
attr: Attribute)
-> ArgType {
@ -345,7 +346,7 @@ pub fn compute_abi_info(_ccx: &CrateContext,
ArgType::indirect(ty, Some(attr))
} else {
ArgType::direct(ty,
Some(llreg_ty(cls.as_slice())),
Some(llreg_ty(ccx, cls.as_slice())),
None,
None)
}
@ -356,14 +357,14 @@ pub fn compute_abi_info(_ccx: &CrateContext,
let mut arg_tys = Vec::new();
for t in atys.iter() {
let ty = x86_64_ty(*t, |cls| cls.is_pass_byval(), ByValAttribute);
let ty = x86_64_ty(ccx, *t, |cls| cls.is_pass_byval(), ByValAttribute);
arg_tys.push(ty);
}
let ret_ty = if ret_def {
x86_64_ty(rty, |cls| cls.is_ret_bysret(), StructRetAttribute)
x86_64_ty(ccx, rty, |cls| cls.is_ret_bysret(), StructRetAttribute)
} else {
ArgType::direct(Type::void(), None, None, None)
ArgType::direct(Type::void(ccx), None, None, None)
};
return FnType {

View file

@ -267,15 +267,15 @@ pub fn trans_fn_ref_with_vtables(
let _icx = push_ctxt("trans_fn_ref_with_vtables");
let ccx = bcx.ccx();
let tcx = ccx.tcx;
let tcx = bcx.tcx();
debug!("trans_fn_ref_with_vtables(bcx={}, def_id={}, node={:?}, \
type_params={}, vtables={})",
bcx.to_str(),
def_id.repr(bcx.tcx()),
def_id.repr(tcx),
node,
type_params.repr(bcx.tcx()),
vtables.repr(bcx.tcx()));
type_params.repr(tcx),
vtables.repr(tcx));
assert!(type_params.iter().all(|t| !ty::type_needs_infer(*t)));
@ -366,12 +366,12 @@ pub fn trans_fn_ref_with_vtables(
} else if def_id.krate == ast::LOCAL_CRATE {
let map_node = session::expect(
ccx.sess(),
ccx.tcx.map.find(def_id.node),
tcx.map.find(def_id.node),
|| format!("local item should be in ast map"));
match map_node {
ast_map::NodeForeignItem(_) => {
ccx.tcx.map.get_foreign_abis(def_id.node).is_intrinsic()
tcx.map.get_foreign_abis(def_id.node).is_intrinsic()
}
_ => false
}
@ -502,9 +502,9 @@ pub fn trans_lang_call<'a>(
dest: Option<expr::Dest>)
-> Result<'a> {
let fty = if did.krate == ast::LOCAL_CRATE {
ty::node_id_to_type(bcx.ccx().tcx, did.node)
ty::node_id_to_type(bcx.tcx(), did.node)
} else {
csearch::get_type(bcx.ccx().tcx, did).ty
csearch::get_type(bcx.tcx(), did).ty
};
callee::trans_call_inner(bcx,
None,
@ -649,7 +649,7 @@ pub fn trans_call_inner<'a>(
};
let mut llresult = unsafe {
llvm::LLVMGetUndef(Type::nil().ptr_to().to_ref())
llvm::LLVMGetUndef(Type::nil(ccx).ptr_to().to_ref())
};
// The code below invokes the function, using either the Rust

View file

@ -205,7 +205,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
_ => {}
}
}
self.ccx.tcx.sess.bug("no loop scope found");
self.ccx.sess().bug("no loop scope found");
}
fn normal_exit_block(&'a self,
@ -238,10 +238,10 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
* instance of `ty`
*/
if !ty::type_needs_drop(self.ccx.tcx, ty) { return; }
if !ty::type_needs_drop(self.ccx.tcx(), ty) { return; }
let drop = ~DropValue {
is_immediate: false,
on_unwind: ty::type_needs_unwind_cleanup(self.ccx.tcx, ty),
on_unwind: ty::type_needs_unwind_cleanup(self.ccx.tcx(), ty),
val: val,
ty: ty
};
@ -249,7 +249,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
debug!("schedule_drop_mem({:?}, val={}, ty={})",
cleanup_scope,
self.ccx.tn.val_to_str(val),
ty.repr(self.ccx.tcx));
ty.repr(self.ccx.tcx()));
self.schedule_clean(cleanup_scope, drop as ~Cleanup);
}
@ -262,10 +262,10 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
* Schedules a (deep) drop of `val`, which is an instance of `ty`
*/
if !ty::type_needs_drop(self.ccx.tcx, ty) { return; }
if !ty::type_needs_drop(self.ccx.tcx(), ty) { return; }
let drop = ~DropValue {
is_immediate: true,
on_unwind: ty::type_needs_unwind_cleanup(self.ccx.tcx, ty),
on_unwind: ty::type_needs_unwind_cleanup(self.ccx.tcx(), ty),
val: val,
ty: ty
};
@ -273,7 +273,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
debug!("schedule_drop_immediate({:?}, val={}, ty={})",
cleanup_scope,
self.ccx.tn.val_to_str(val),
ty.repr(self.ccx.tcx));
ty.repr(self.ccx.tcx()));
self.schedule_clean(cleanup_scope, drop as ~Cleanup);
}
@ -330,7 +330,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
}
}
self.ccx.tcx.sess.bug(
self.ccx.sess().bug(
format!("no cleanup scope {} found",
self.ccx.tcx.map.node_to_str(cleanup_scope)));
}
@ -540,7 +540,7 @@ impl<'a> CleanupHelperMethods<'a> for FunctionContext<'a> {
}
LoopExit(id, _) => {
self.ccx.tcx.sess.bug(format!(
self.ccx.sess().bug(format!(
"cannot exit from scope {:?}, \
not in scope", id));
}
@ -669,7 +669,9 @@ impl<'a> CleanupHelperMethods<'a> for FunctionContext<'a> {
// The landing pad return type (the type being propagated). Not sure what
// this represents but it's determined by the personality function and
// this is what the EH proposal example uses.
let llretty = Type::struct_([Type::i8p(), Type::i32()], false);
let llretty = Type::struct_(self.ccx,
[Type::i8p(self.ccx), Type::i32(self.ccx)],
false);
// The exception handling personality function.
let def_id = common::langcall(pad_bcx, None, "", EhPersonalityLangItem);

View file

@ -161,8 +161,7 @@ fn allocate_cbox<'a>(bcx: &'a Block<'a>,
cdata_ty: ty::t)
-> Result<'a> {
let _icx = push_ctxt("closure::allocate_cbox");
let ccx = bcx.ccx();
let tcx = ccx.tcx;
let tcx = bcx.tcx();
// Allocate and initialize the box:
match sigil {
@ -197,7 +196,7 @@ pub fn store_environment<'a>(
-> ClosureResult<'a> {
let _icx = push_ctxt("closure::store_environment");
let ccx = bcx.ccx();
let tcx = ccx.tcx;
let tcx = ccx.tcx();
// compute the type of the closure
let cdata_ty = mk_closure_tys(tcx, bound_values.as_slice());
@ -343,7 +342,7 @@ fn load_environment<'a>(bcx: &'a Block<'a>, cdata_ty: ty::t,
fn fill_fn_pair(bcx: &Block, pair: ValueRef, llfn: ValueRef, llenvptr: ValueRef) {
Store(bcx, llfn, GEPi(bcx, pair, [0u, abi::fn_field_code]));
let llenvptr = PointerCast(bcx, llenvptr, Type::i8p());
let llenvptr = PointerCast(bcx, llenvptr, Type::i8p(bcx.ccx()));
Store(bcx, llenvptr, GEPi(bcx, pair, [0u, abi::fn_field_box]));
}
@ -433,7 +432,7 @@ pub fn get_wrapper_for_bare_fn(ccx: &CrateContext,
}
}
let tcx = ccx.tcx;
let tcx = ccx.tcx();
debug!("get_wrapper_for_bare_fn(closure_ty={})", closure_ty.repr(tcx));
@ -510,7 +509,7 @@ pub fn make_closure_from_bare_fn<'a>(bcx: &'a Block<'a>,
-> DatumBlock<'a, Expr> {
let scratch = rvalue_scratch_datum(bcx, closure_ty, "__adjust");
let wrapper = get_wrapper_for_bare_fn(bcx.ccx(), closure_ty, def, fn_ptr, true);
fill_fn_pair(bcx, scratch.val, wrapper, C_null(Type::i8p()));
fill_fn_pair(bcx, scratch.val, wrapper, C_null(Type::i8p(bcx.ccx())));
DatumBlock(bcx, scratch.to_expr_datum())
}

View file

@ -18,7 +18,6 @@ use lib::llvm::{True, False, Bool};
use lib::llvm::llvm;
use lib;
use middle::lang_items::LangItem;
use middle::trans::base;
use middle::trans::build;
use middle::trans::cleanup;
use middle::trans::datum;
@ -49,7 +48,7 @@ pub use middle::trans::context::CrateContext;
fn type_is_newtype_immediate(ccx: &CrateContext, ty: ty::t) -> bool {
match ty::get(ty).sty {
ty::ty_struct(def_id, ref substs) => {
let fields = ty::struct_fields(ccx.tcx, def_id, substs);
let fields = ty::struct_fields(ccx.tcx(), def_id, substs);
fields.len() == 1 &&
fields.get(0).ident.name ==
token::special_idents::unnamed_field.name &&
@ -62,7 +61,7 @@ fn type_is_newtype_immediate(ccx: &CrateContext, ty: ty::t) -> bool {
pub fn type_is_immediate(ccx: &CrateContext, ty: ty::t) -> bool {
use middle::trans::machine::llsize_of_alloc;
use middle::trans::type_of::sizing_type_of;
let tcx = ccx.tcx;
let tcx = ccx.tcx();
let simple = ty::type_is_scalar(ty) || ty::type_is_boxed(ty) ||
ty::type_is_unique(ty) || ty::type_is_region_ptr(ty) ||
type_is_newtype_immediate(ccx, ty) || ty::type_is_bot(ty) ||
@ -100,7 +99,7 @@ pub fn return_type_is_void(ccx: &CrateContext, ty: ty::t) -> bool {
* return type (in order to aid with C ABI compatibility).
*/
ty::type_is_nil(ty) || ty::type_is_bot(ty) || ty::type_is_empty(ccx.tcx, ty)
ty::type_is_nil(ty) || ty::type_is_bot(ty) || ty::type_is_empty(ccx.tcx(), ty)
}
/// Generates a unique symbol based off the name given. This is used to create
@ -286,7 +285,7 @@ pub struct FunctionContext<'a> {
block_arena: &'a TypedArena<Block<'a>>,
// This function's enclosing crate context.
ccx: &'a CrateContext<'a>,
ccx: &'a CrateContext,
// Used and maintained by the debuginfo module.
debug_context: debuginfo::FunctionDebugContext,
@ -330,7 +329,12 @@ impl<'a> FunctionContext<'a> {
pub fn get_llreturn(&self) -> BasicBlockRef {
if self.llreturn.get().is_none() {
self.llreturn.set(Some(base::mk_return_basic_block(self.llfn)));
self.llreturn.set(Some(unsafe {
"return".with_c_str(|buf| {
llvm::LLVMAppendBasicBlockInContext(self.ccx.llcx, self.llfn, buf)
})
}))
}
self.llreturn.get().unwrap()
@ -435,9 +439,9 @@ impl<'a> Block<'a> {
})
}
pub fn ccx(&self) -> &'a CrateContext<'a> { self.fcx.ccx }
pub fn ccx(&self) -> &'a CrateContext { self.fcx.ccx }
pub fn tcx(&self) -> &'a ty::ctxt {
self.fcx.ccx.tcx
&self.fcx.ccx.tcx
}
pub fn sess(&self) -> &'a Session { self.fcx.ccx.sess() }
@ -540,40 +544,40 @@ pub fn C_floating(s: &str, t: Type) -> ValueRef {
}
}
pub fn C_nil() -> ValueRef {
C_struct([], false)
pub fn C_nil(ccx: &CrateContext) -> ValueRef {
C_struct(ccx, [], false)
}
pub fn C_bool(val: bool) -> ValueRef {
C_integral(Type::bool(), val as u64, false)
pub fn C_bool(ccx: &CrateContext, val: bool) -> ValueRef {
C_integral(Type::bool(ccx), val as u64, false)
}
pub fn C_i1(val: bool) -> ValueRef {
C_integral(Type::i1(), val as u64, false)
pub fn C_i1(ccx: &CrateContext, val: bool) -> ValueRef {
C_integral(Type::i1(ccx), val as u64, false)
}
pub fn C_i32(i: i32) -> ValueRef {
return C_integral(Type::i32(), i as u64, true);
pub fn C_i32(ccx: &CrateContext, i: i32) -> ValueRef {
C_integral(Type::i32(ccx), i as u64, true)
}
pub fn C_i64(i: i64) -> ValueRef {
return C_integral(Type::i64(), i as u64, true);
pub fn C_i64(ccx: &CrateContext, i: i64) -> ValueRef {
C_integral(Type::i64(ccx), i as u64, true)
}
pub fn C_u64(i: u64) -> ValueRef {
return C_integral(Type::i64(), i, false);
pub fn C_u64(ccx: &CrateContext, i: u64) -> ValueRef {
C_integral(Type::i64(ccx), i, false)
}
pub fn C_int(cx: &CrateContext, i: int) -> ValueRef {
return C_integral(cx.int_type, i as u64, true);
pub fn C_int(ccx: &CrateContext, i: int) -> ValueRef {
C_integral(ccx.int_type, i as u64, true)
}
pub fn C_uint(cx: &CrateContext, i: uint) -> ValueRef {
return C_integral(cx.int_type, i as u64, false);
pub fn C_uint(ccx: &CrateContext, i: uint) -> ValueRef {
C_integral(ccx.int_type, i as u64, false)
}
pub fn C_u8(i: uint) -> ValueRef {
return C_integral(Type::i8(), i as u64, false);
pub fn C_u8(ccx: &CrateContext, i: uint) -> ValueRef {
C_integral(Type::i8(ccx), i as u64, false)
}
@ -613,15 +617,15 @@ pub fn C_cstr(cx: &CrateContext, s: InternedString) -> ValueRef {
pub fn C_str_slice(cx: &CrateContext, s: InternedString) -> ValueRef {
unsafe {
let len = s.get().len();
let cs = llvm::LLVMConstPointerCast(C_cstr(cx, s), Type::i8p().to_ref());
C_struct([cs, C_uint(cx, len)], false)
let cs = llvm::LLVMConstPointerCast(C_cstr(cx, s), Type::i8p(cx).to_ref());
C_struct(cx, [cs, C_uint(cx, len)], false)
}
}
pub fn C_binary_slice(cx: &CrateContext, data: &[u8]) -> ValueRef {
unsafe {
let len = data.len();
let lldata = C_bytes(data);
let lldata = C_bytes(cx, data);
let gsym = token::gensym("binary");
let g = format!("binary{}", gsym).with_c_str(|buf| {
@ -631,25 +635,14 @@ pub fn C_binary_slice(cx: &CrateContext, data: &[u8]) -> ValueRef {
llvm::LLVMSetGlobalConstant(g, True);
lib::llvm::SetLinkage(g, lib::llvm::InternalLinkage);
let cs = llvm::LLVMConstPointerCast(g, Type::i8p().to_ref());
C_struct([cs, C_uint(cx, len)], false)
let cs = llvm::LLVMConstPointerCast(g, Type::i8p(cx).to_ref());
C_struct(cx, [cs, C_uint(cx, len)], false)
}
}
pub fn C_zero_byte_arr(size: uint) -> ValueRef {
pub fn C_struct(ccx: &CrateContext, elts: &[ValueRef], packed: bool) -> ValueRef {
unsafe {
let mut i = 0u;
let mut elts: Vec<ValueRef> = Vec::new();
while i < size { elts.push(C_u8(0u)); i += 1u; }
return llvm::LLVMConstArray(Type::i8().to_ref(),
elts.as_ptr(), elts.len() as c_uint);
}
}
pub fn C_struct(elts: &[ValueRef], packed: bool) -> ValueRef {
unsafe {
llvm::LLVMConstStructInContext(base::task_llcx(),
llvm::LLVMConstStructInContext(ccx.llcx,
elts.as_ptr(), elts.len() as c_uint,
packed as Bool)
}
@ -667,10 +660,10 @@ pub fn C_array(ty: Type, elts: &[ValueRef]) -> ValueRef {
}
}
pub fn C_bytes(bytes: &[u8]) -> ValueRef {
pub fn C_bytes(ccx: &CrateContext, bytes: &[u8]) -> ValueRef {
unsafe {
let ptr = bytes.as_ptr() as *c_char;
return llvm::LLVMConstStringInContext(base::task_llcx(), ptr, bytes.len() as c_uint, True);
return llvm::LLVMConstStringInContext(ccx.llcx, ptr, bytes.len() as c_uint, True);
}
}
@ -853,7 +846,7 @@ pub fn node_vtables(bcx: &Block, id: ast::NodeId)
// vtables. This should eliminate any vtable_params.
pub fn resolve_vtables_in_fn_ctxt(fcx: &FunctionContext, vts: typeck::vtable_res)
-> typeck::vtable_res {
resolve_vtables_under_param_substs(fcx.ccx.tcx,
resolve_vtables_under_param_substs(fcx.ccx.tcx(),
fcx.param_substs,
vts)
}
@ -951,14 +944,14 @@ pub fn filename_and_line_num_from_span(bcx: &Block, span: Span)
let loc = bcx.sess().parse_sess.cm.lookup_char_pos(span.lo);
let filename_cstr = C_cstr(bcx.ccx(),
token::intern_and_get_ident(loc.file.name));
let filename = build::PointerCast(bcx, filename_cstr, Type::i8p());
let filename = build::PointerCast(bcx, filename_cstr, Type::i8p(bcx.ccx()));
let line = C_int(bcx.ccx(), loc.line as int);
(filename, line)
}
// Casts a Rust bool value to an i1.
pub fn bool_to_i1(bcx: &Block, llval: ValueRef) -> ValueRef {
build::ICmp(bcx, lib::llvm::IntNE, llval, C_bool(false))
build::ICmp(bcx, lib::llvm::IntNE, llval, C_bool(bcx.ccx(), false))
}
pub fn langcall(bcx: &Block,

View file

@ -41,11 +41,11 @@ pub fn const_lit(cx: &CrateContext, e: &ast::Expr, lit: ast::Lit)
-> ValueRef {
let _icx = push_ctxt("trans_lit");
match lit.node {
ast::LitChar(i) => C_integral(Type::char(), i as u64, false),
ast::LitChar(i) => C_integral(Type::char(cx), i as u64, false),
ast::LitInt(i, t) => C_integral(Type::int_from_ty(cx, t), i as u64, true),
ast::LitUint(u, t) => C_integral(Type::uint_from_ty(cx, t), u, false),
ast::LitIntUnsuffixed(i) => {
let lit_int_ty = ty::node_id_to_type(cx.tcx, e.id);
let lit_int_ty = ty::node_id_to_type(cx.tcx(), e.id);
match ty::get(lit_int_ty).sty {
ty::ty_int(t) => {
C_integral(Type::int_from_ty(cx, t), i as u64, true)
@ -55,17 +55,17 @@ pub fn const_lit(cx: &CrateContext, e: &ast::Expr, lit: ast::Lit)
}
_ => cx.sess().span_bug(lit.span,
format!("integer literal has type {} (expected int or uint)",
ty_to_str(cx.tcx, lit_int_ty)))
ty_to_str(cx.tcx(), lit_int_ty)))
}
}
ast::LitFloat(ref fs, t) => {
C_floating(fs.get(), Type::float_from_ty(t))
C_floating(fs.get(), Type::float_from_ty(cx, t))
}
ast::LitFloatUnsuffixed(ref fs) => {
let lit_float_ty = ty::node_id_to_type(cx.tcx, e.id);
let lit_float_ty = ty::node_id_to_type(cx.tcx(), e.id);
match ty::get(lit_float_ty).sty {
ty::ty_float(t) => {
C_floating(fs.get(), Type::float_from_ty(t))
C_floating(fs.get(), Type::float_from_ty(cx, t))
}
_ => {
cx.sess().span_bug(lit.span,
@ -73,8 +73,8 @@ pub fn const_lit(cx: &CrateContext, e: &ast::Expr, lit: ast::Lit)
}
}
}
ast::LitBool(b) => C_bool(b),
ast::LitNil => C_nil(),
ast::LitBool(b) => C_bool(cx, b),
ast::LitNil => C_nil(cx),
ast::LitStr(ref s, _) => C_str_slice(cx, (*s).clone()),
ast::LitBinary(ref data) => C_binary_slice(cx, data.deref().as_slice()),
}
@ -91,13 +91,13 @@ pub fn const_ptrcast(cx: &CrateContext, a: ValueRef, t: Type) -> ValueRef {
fn const_vec(cx: &CrateContext, e: &ast::Expr,
es: &[@ast::Expr], is_local: bool) -> (ValueRef, Type, bool) {
let vec_ty = ty::expr_ty(cx.tcx, e);
let unit_ty = ty::sequence_element_type(cx.tcx, vec_ty);
let vec_ty = ty::expr_ty(cx.tcx(), e);
let unit_ty = ty::sequence_element_type(cx.tcx(), vec_ty);
let llunitty = type_of::type_of(cx, unit_ty);
let (vs, inlineable) = vec::unzip(es.iter().map(|e| const_expr(cx, *e, is_local)));
// If the vector contains enums, an LLVM array won't work.
let v = if vs.iter().any(|vi| val_ty(*vi) != llunitty) {
C_struct(vs, false)
C_struct(cx, vs, false)
} else {
C_array(llunitty, vs)
};
@ -148,14 +148,14 @@ fn const_deref(cx: &CrateContext, v: ValueRef, t: ty::t, explicit: bool)
}
_ => {
cx.sess().bug(format!("unexpected dereferenceable type {}",
ty_to_str(cx.tcx, t)))
ty_to_str(cx.tcx(), t)))
}
};
(dv, mt.ty)
}
None => {
cx.sess().bug(format!("can't dereference const of type {}",
ty_to_str(cx.tcx, t)))
ty_to_str(cx.tcx(), t)))
}
}
}
@ -189,8 +189,8 @@ pub fn const_expr(cx: &CrateContext, e: &ast::Expr, is_local: bool) -> (ValueRef
let (llconst, inlineable) = const_expr_unadjusted(cx, e, is_local);
let mut llconst = llconst;
let mut inlineable = inlineable;
let ety = ty::expr_ty(cx.tcx, e);
let ety_adjusted = ty::expr_ty_adjusted(cx.tcx, e,
let ety = ty::expr_ty(cx.tcx(), e);
let ety_adjusted = ty::expr_ty_adjusted(cx.tcx(), e,
cx.maps.method_map.borrow().get());
let adjustment = {
let adjustments = cx.tcx.adjustments.borrow();
@ -201,13 +201,13 @@ pub fn const_expr(cx: &CrateContext, e: &ast::Expr, is_local: bool) -> (ValueRef
Some(adj) => {
match *adj {
ty::AutoAddEnv(ty::ReStatic, ast::BorrowedSigil) => {
let def = ty::resolve_expr(cx.tcx, e);
let def = ty::resolve_expr(cx.tcx(), e);
let wrapper = closure::get_wrapper_for_bare_fn(cx,
ety_adjusted,
def,
llconst,
is_local);
llconst = C_struct([wrapper, C_null(Type::i8p())], false)
llconst = C_struct(cx, [wrapper, C_null(Type::i8p(cx))], false)
}
ty::AutoAddEnv(ref r, ref s) => {
cx.sess()
@ -255,9 +255,8 @@ pub fn const_expr(cx: &CrateContext, e: &ast::Expr, is_local: bool) -> (ValueRef
assert_eq!(abi::slice_elt_base, 0);
assert_eq!(abi::slice_elt_len, 1);
match ty::get(ty).sty {
ty::ty_vec(_,
ty::vstore_fixed(len)) => {
llconst = C_struct([
ty::ty_vec(_, ty::vstore_fixed(len)) => {
llconst = C_struct(cx, [
llptr,
C_uint(cx, len)
], false);
@ -290,7 +289,7 @@ pub fn const_expr(cx: &CrateContext, e: &ast::Expr, is_local: bool) -> (ValueRef
llvm::LLVMDumpValue(C_undef(llty));
}
cx.sess().bug(format!("const {} of type {} has size {} instead of {}",
e.repr(cx.tcx), ty_to_str(cx.tcx, ety),
e.repr(cx.tcx()), ty_to_str(cx.tcx(), ety),
csize, tsize));
}
(llconst, inlineable)
@ -321,7 +320,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr,
/* Neither type is bottom, and we expect them to be unified
* already, so the following is safe. */
let ty = ty::expr_ty(cx.tcx, e1);
let ty = ty::expr_ty(cx.tcx(), e1);
let is_float = ty::type_is_fp(ty);
let signed = ty::type_is_signed(ty);
return (match b {
@ -397,7 +396,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr,
},
ast::ExprUnary(u, e) => {
let (te, _) = const_expr(cx, e, is_local);
let ty = ty::expr_ty(cx.tcx, e);
let ty = ty::expr_ty(cx.tcx(), e);
let is_float = ty::type_is_fp(ty);
return (match u {
ast::UnBox | ast::UnUniq | ast::UnDeref => {
@ -409,9 +408,9 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr,
ty::ty_bool => {
// Somewhat questionable, but I believe this is
// correct.
let te = llvm::LLVMConstTrunc(te, Type::i1().to_ref());
let te = llvm::LLVMConstTrunc(te, Type::i1(cx).to_ref());
let te = llvm::LLVMConstNot(te);
llvm::LLVMConstZExt(te, Type::bool().to_ref())
llvm::LLVMConstZExt(te, Type::bool(cx).to_ref())
}
_ => llvm::LLVMConstNot(te),
}
@ -423,21 +422,21 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr,
}, true)
}
ast::ExprField(base, field, _) => {
let bt = ty::expr_ty_adjusted(cx.tcx, base,
let bt = ty::expr_ty_adjusted(cx.tcx(), base,
cx.maps.method_map.borrow().get());
let brepr = adt::represent_type(cx, bt);
let (bv, inlineable) = const_expr(cx, base, is_local);
expr::with_field_tys(cx.tcx, bt, None, |discr, field_tys| {
let ix = ty::field_idx_strict(cx.tcx, field.name, field_tys);
expr::with_field_tys(cx.tcx(), bt, None, |discr, field_tys| {
let ix = ty::field_idx_strict(cx.tcx(), field.name, field_tys);
(adt::const_get_field(cx, brepr, bv, discr, ix), inlineable)
})
}
ast::ExprIndex(base, index) => {
let bt = ty::expr_ty_adjusted(cx.tcx, base,
let bt = ty::expr_ty_adjusted(cx.tcx(), base,
cx.maps.method_map.borrow().get());
let (bv, inlineable) = const_expr(cx, base, is_local);
let iv = match const_eval::eval_const_expr(cx.tcx, index) {
let iv = match const_eval::eval_const_expr(cx.tcx(), index) {
const_eval::const_int(i) => i as u64,
const_eval::const_uint(u) => u,
_ => cx.sess().span_bug(index.span,
@ -474,9 +473,9 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr,
(const_get_elt(cx, arr, [iv as c_uint]), inlineable)
}
ast::ExprCast(base, _) => {
let ety = ty::expr_ty(cx.tcx, e);
let ety = ty::expr_ty(cx.tcx(), e);
let llty = type_of::type_of(cx, ety);
let basety = ty::expr_ty(cx.tcx, base);
let basety = ty::expr_ty(cx.tcx(), base);
let (v, inlineable) = const_expr(cx, base, is_local);
return (match (expr::cast_type_kind(basety),
expr::cast_type_kind(ety)) {
@ -532,15 +531,15 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr,
(const_addr_of(cx, e), false)
}
ast::ExprTup(ref es) => {
let ety = ty::expr_ty(cx.tcx, e);
let ety = ty::expr_ty(cx.tcx(), e);
let repr = adt::represent_type(cx, ety);
let (vals, inlineable) = map_list(es.as_slice());
(adt::trans_const(cx, repr, 0, vals.as_slice()), inlineable)
}
ast::ExprStruct(_, ref fs, ref base_opt) => {
let ety = ty::expr_ty(cx.tcx, e);
let ety = ty::expr_ty(cx.tcx(), e);
let repr = adt::represent_type(cx, ety);
let tcx = cx.tcx;
let tcx = cx.tcx();
let base_val = match *base_opt {
Some(base) => Some(const_expr(cx, base, is_local)),
@ -596,23 +595,23 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr,
llvm::LLVMSetGlobalConstant(gv, True);
SetLinkage(gv, PrivateLinkage);
let p = const_ptrcast(cx, gv, llunitty);
(C_struct([p, C_uint(cx, es.len())], false), false)
(C_struct(cx, [p, C_uint(cx, es.len())], false), false)
}
_ => cx.sess().span_bug(e.span, "bad const-slice expr")
}
}
ast::ExprRepeat(elem, count, _) => {
let vec_ty = ty::expr_ty(cx.tcx, e);
let unit_ty = ty::sequence_element_type(cx.tcx, vec_ty);
let vec_ty = ty::expr_ty(cx.tcx(), e);
let unit_ty = ty::sequence_element_type(cx.tcx(), vec_ty);
let llunitty = type_of::type_of(cx, unit_ty);
let n = match const_eval::eval_const_expr(cx.tcx, count) {
let n = match const_eval::eval_const_expr(cx.tcx(), count) {
const_eval::const_int(i) => i as uint,
const_eval::const_uint(i) => i as uint,
_ => cx.sess().span_bug(count.span, "count must be integral const expression.")
};
let vs = vec::from_elem(n, const_expr(cx, elem, is_local).val0());
let v = if vs.iter().any(|vi| val_ty(*vi) != llunitty) {
C_struct(vs, false)
C_struct(cx, vs, false)
} else {
C_array(llunitty, vs)
};
@ -622,7 +621,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr,
// Assert that there are no type parameters in this path.
assert!(pth.segments.iter().all(|seg| seg.types.is_empty()));
let tcx = cx.tcx;
let tcx = cx.tcx();
let opt_def = {
let def_map = tcx.def_map.borrow();
def_map.get().find_copy(&e.id)
@ -630,7 +629,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr,
match opt_def {
Some(ast::DefFn(def_id, _purity)) => {
if !ast_util::is_local(def_id) {
let ty = csearch::get_type(cx.tcx, def_id).ty;
let ty = csearch::get_type(cx.tcx(), def_id).ty;
(base::trans_external_path(cx, def_id, ty), true)
} else {
assert!(ast_util::is_local(def_id));
@ -641,15 +640,15 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr,
get_const_val(cx, def_id)
}
Some(ast::DefVariant(enum_did, variant_did, _)) => {
let ety = ty::expr_ty(cx.tcx, e);
let ety = ty::expr_ty(cx.tcx(), e);
let repr = adt::represent_type(cx, ety);
let vinfo = ty::enum_variant_with_id(cx.tcx,
let vinfo = ty::enum_variant_with_id(cx.tcx(),
enum_did,
variant_did);
(adt::trans_const(cx, repr, vinfo.disr_val, []), true)
}
Some(ast::DefStruct(_)) => {
let ety = ty::expr_ty(cx.tcx, e);
let ety = ty::expr_ty(cx.tcx(), e);
let llty = type_of::type_of(cx, ety);
(C_null(llty), true)
}
@ -659,23 +658,23 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr,
}
}
ast::ExprCall(callee, ref args) => {
let tcx = cx.tcx;
let tcx = cx.tcx();
let opt_def = {
let def_map = tcx.def_map.borrow();
def_map.get().find_copy(&callee.id)
};
match opt_def {
Some(ast::DefStruct(_)) => {
let ety = ty::expr_ty(cx.tcx, e);
let ety = ty::expr_ty(cx.tcx(), e);
let repr = adt::represent_type(cx, ety);
let (arg_vals, inlineable) = map_list(args.as_slice());
(adt::trans_const(cx, repr, 0, arg_vals.as_slice()),
inlineable)
}
Some(ast::DefVariant(enum_did, variant_did, _)) => {
let ety = ty::expr_ty(cx.tcx, e);
let ety = ty::expr_ty(cx.tcx(), e);
let repr = adt::represent_type(cx, ety);
let vinfo = ty::enum_variant_with_id(cx.tcx,
let vinfo = ty::enum_variant_with_id(cx.tcx(),
enum_did,
variant_did);
let (arg_vals, inlineable) = map_list(args.as_slice());

View file

@ -31,14 +31,14 @@ use util::nodemap::{NodeMap, NodeSet, DefIdMap};
use std::cell::{Cell, RefCell};
use std::c_str::ToCStr;
use std::local_data;
use std::libc::c_uint;
use std::ptr;
use std::vec_ng::Vec;
use collections::{HashMap, HashSet};
use syntax::ast;
use syntax::parse::token::InternedString;
pub struct CrateContext<'a> {
pub struct CrateContext {
llmod: ModuleRef,
llcx: ContextRef,
metadata_llmod: ModuleRef,
@ -48,7 +48,7 @@ pub struct CrateContext<'a> {
intrinsics: HashMap<&'static str, ValueRef>,
item_vals: RefCell<NodeMap<ValueRef>>,
exp_map2: resolve::ExportMap2,
reachable: &'a NodeSet,
reachable: NodeSet,
item_symbols: RefCell<NodeMap<~str>>,
link_meta: LinkMeta,
drop_glues: RefCell<HashMap<ty::t, ValueRef>>,
@ -100,10 +100,9 @@ pub struct CrateContext<'a> {
symbol_hasher: RefCell<Sha256>,
type_hashcodes: RefCell<HashMap<ty::t, ~str>>,
all_llvm_symbols: RefCell<HashSet<~str>>,
tcx: &'a ty::ctxt,
tcx: ty::ctxt,
maps: astencode::Maps,
stats: @Stats,
tydesc_type: Type,
int_type: Type,
opaque_vec_type: Type,
builder: BuilderRef_res,
@ -116,18 +115,17 @@ pub struct CrateContext<'a> {
dbg_cx: Option<debuginfo::CrateDebugContext>,
}
impl<'a> CrateContext<'a> {
impl CrateContext {
pub fn new(name: &str,
tcx: &'a ty::ctxt,
tcx: ty::ctxt,
emap2: resolve::ExportMap2,
maps: astencode::Maps,
symbol_hasher: Sha256,
link_meta: LinkMeta,
reachable: &'a NodeSet)
-> CrateContext<'a> {
reachable: NodeSet)
-> CrateContext {
unsafe {
let llcx = llvm::LLVMContextCreate();
set_task_llcx(llcx);
let llmod = name.with_c_str(|buf| {
llvm::LLVMModuleCreateWithNameInContext(buf, llcx)
});
@ -144,97 +142,98 @@ impl<'a> CrateContext<'a> {
llvm::LLVMRustSetNormalizedTarget(llmod, buf);
llvm::LLVMRustSetNormalizedTarget(metadata_llmod, buf);
});
let targ_cfg = tcx.sess.targ_cfg;
let td = mk_target_data(tcx.sess.targ_cfg.target_strs.data_layout);
let tn = TypeNames::new();
let mut intrinsics = base::declare_intrinsics(llmod);
if tcx.sess.opts.debuginfo != NoDebugInfo {
base::declare_dbg_intrinsics(llmod, &mut intrinsics);
}
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);
let mut str_slice_ty = Type::named_struct("str_slice");
str_slice_ty.set_struct_body([Type::i8p(), int_type], false);
tn.associate_type("tydesc", &tydesc_type);
tn.associate_type("str_slice", &str_slice_ty);
let (crate_map_name, crate_map) = decl_crate_map(&tcx.sess, link_meta.clone(), llmod);
let dbg_cx = if tcx.sess.opts.debuginfo != NoDebugInfo {
Some(debuginfo::CrateDebugContext::new(llmod))
} else {
None
};
if tcx.sess.count_llvm_insns() {
let mut ccx = CrateContext {
llmod: llmod,
llcx: llcx,
metadata_llmod: metadata_llmod,
td: td,
tn: TypeNames::new(),
externs: RefCell::new(HashMap::new()),
intrinsics: HashMap::new(),
item_vals: RefCell::new(NodeMap::new()),
exp_map2: emap2,
reachable: reachable,
item_symbols: RefCell::new(NodeMap::new()),
link_meta: link_meta,
drop_glues: RefCell::new(HashMap::new()),
tydescs: RefCell::new(HashMap::new()),
finished_tydescs: Cell::new(false),
external: RefCell::new(DefIdMap::new()),
external_srcs: RefCell::new(NodeMap::new()),
non_inlineable_statics: RefCell::new(NodeSet::new()),
monomorphized: RefCell::new(HashMap::new()),
monomorphizing: RefCell::new(DefIdMap::new()),
vtables: RefCell::new(HashMap::new()),
const_cstr_cache: RefCell::new(HashMap::new()),
const_globals: RefCell::new(HashMap::new()),
const_values: RefCell::new(NodeMap::new()),
extern_const_values: RefCell::new(DefIdMap::new()),
impl_method_cache: RefCell::new(HashMap::new()),
closure_bare_wrapper_cache: 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(Vec::new()),
},
int_type: Type::from_ref(ptr::null()),
opaque_vec_type: Type::from_ref(ptr::null()),
builder: BuilderRef_res(llvm::LLVMCreateBuilderInContext(llcx)),
crate_map: ptr::null(),
crate_map_name: ~"",
uses_gc: false,
dbg_cx: dbg_cx,
};
ccx.int_type = Type::int(&ccx);
ccx.opaque_vec_type = Type::opaque_vec(&ccx);
ccx.tn.associate_type("tydesc", &Type::tydesc(&ccx));
let mut str_slice_ty = Type::named_struct(&ccx, "str_slice");
str_slice_ty.set_struct_body([Type::i8p(&ccx), ccx.int_type], false);
ccx.tn.associate_type("str_slice", &str_slice_ty);
decl_crate_map(&mut ccx);
base::declare_intrinsics(&mut ccx);
if ccx.sess().count_llvm_insns() {
base::init_insn_ctxt()
}
CrateContext {
llmod: llmod,
llcx: llcx,
metadata_llmod: metadata_llmod,
td: td,
tn: tn,
externs: RefCell::new(HashMap::new()),
intrinsics: intrinsics,
item_vals: RefCell::new(NodeMap::new()),
exp_map2: emap2,
reachable: reachable,
item_symbols: RefCell::new(NodeMap::new()),
link_meta: link_meta,
drop_glues: RefCell::new(HashMap::new()),
tydescs: RefCell::new(HashMap::new()),
finished_tydescs: Cell::new(false),
external: RefCell::new(DefIdMap::new()),
external_srcs: RefCell::new(NodeMap::new()),
non_inlineable_statics: RefCell::new(NodeSet::new()),
monomorphized: RefCell::new(HashMap::new()),
monomorphizing: RefCell::new(DefIdMap::new()),
vtables: RefCell::new(HashMap::new()),
const_cstr_cache: RefCell::new(HashMap::new()),
const_globals: RefCell::new(HashMap::new()),
const_values: RefCell::new(NodeMap::new()),
extern_const_values: RefCell::new(DefIdMap::new()),
impl_method_cache: RefCell::new(HashMap::new()),
closure_bare_wrapper_cache: 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(Vec::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,
}
ccx
}
}
pub fn tcx<'a>(&'a self) -> &'a ty::ctxt {
&self.tcx
}
pub fn sess<'a>(&'a self) -> &'a Session {
&self.tcx.sess
}
@ -249,7 +248,7 @@ impl<'a> CrateContext<'a> {
debug!("const_inbounds_gepi: pointer={} indices={:?}",
self.tn.val_to_str(pointer), indices);
let v: Vec<ValueRef> =
indices.iter().map(|i| C_i32(*i as i32)).collect();
indices.iter().map(|i| C_i32(self, *i as i32)).collect();
unsafe {
llvm::LLVMConstInBoundsGEP(pointer,
v.as_ptr(),
@ -272,26 +271,8 @@ impl<'a> CrateContext<'a> {
self.int_type.to_ref())
}
}
}
#[unsafe_destructor]
impl<'a> Drop for CrateContext<'a> {
fn drop(&mut self) {
unset_task_llcx();
pub fn tydesc_type(&self) -> Type {
self.tn.find_type("tydesc").unwrap()
}
}
local_data_key!(task_local_llcx_key: @ContextRef)
pub fn task_llcx() -> ContextRef {
let opt = local_data::get(task_local_llcx_key, |k| k.map(|k| *k));
*opt.expect("task-local LLVMContextRef wasn't ever set!")
}
fn set_task_llcx(c: ContextRef) {
local_data::set(task_local_llcx_key, @c);
}
fn unset_task_llcx() {
local_data::pop(task_local_llcx_key);
}

View file

@ -339,8 +339,8 @@ pub fn trans_fail<'a>(
let v_filename = C_cstr(bcx.ccx(),
token::intern_and_get_ident(loc.file.name));
let v_line = loc.line as int;
let v_str = PointerCast(bcx, v_fail_str, Type::i8p());
let v_filename = PointerCast(bcx, v_filename, Type::i8p());
let v_str = PointerCast(bcx, v_fail_str, Type::i8p(ccx));
let v_filename = PointerCast(bcx, v_filename, Type::i8p(ccx));
let args = vec!(v_str, v_filename, C_int(ccx, v_line));
let did = langcall(bcx, Some(sp), "", FailFnLangItem);
let bcx = callee::trans_lang_call(bcx,

View file

@ -635,7 +635,7 @@ impl<K:KindOps> Datum<K> {
pub fn to_str(&self, ccx: &CrateContext) -> ~str {
format!("Datum({}, {}, {:?})",
ccx.tn.val_to_str(self.val),
ty_to_str(ccx.tcx, self.ty),
ty_to_str(ccx.tcx(), self.ty),
self.kind)
}
@ -709,7 +709,7 @@ impl<'a> DatumBlock<'a, Expr> {
self.datum.shallow_copy(self.bcx, dst)
}
pub fn ccx(&self) -> &'a CrateContext<'a> {
pub fn ccx(&self) -> &'a CrateContext {
self.bcx.ccx()
}

View file

@ -369,10 +369,10 @@ pub fn create_captured_var_metadata(bcx: &Block,
let byte_offset_of_var_in_env = machine::llelement_offset(cx, llvm_env_data_type, env_index);
let address_operations = unsafe {
[llvm::LLVMDIBuilderCreateOpDeref(Type::i64().to_ref()),
llvm::LLVMDIBuilderCreateOpPlus(Type::i64().to_ref()),
C_i64(byte_offset_of_var_in_env as i64),
llvm::LLVMDIBuilderCreateOpDeref(Type::i64().to_ref())]
[llvm::LLVMDIBuilderCreateOpDeref(Type::i64(cx).to_ref()),
llvm::LLVMDIBuilderCreateOpPlus(Type::i64(cx).to_ref()),
C_i64(cx, byte_offset_of_var_in_env as i64),
llvm::LLVMDIBuilderCreateOpDeref(Type::i64(cx).to_ref())]
};
let address_op_count = match closure_sigil {
@ -719,11 +719,11 @@ pub fn create_function_debug_context(cx: &CrateContext,
_ => {
assert_type_for_node_id(cx, fn_ast_id, error_span);
let return_type = ty::node_id_to_type(cx.tcx, fn_ast_id);
let return_type = ty::node_id_to_type(cx.tcx(), fn_ast_id);
let return_type = match param_substs {
None => return_type,
Some(substs) => {
ty::subst_tps(cx.tcx,
ty::subst_tps(cx.tcx(),
substs.tys.as_slice(),
substs.self_ty,
return_type)
@ -737,11 +737,11 @@ pub fn create_function_debug_context(cx: &CrateContext,
// Arguments types
for arg in fn_decl.inputs.iter() {
assert_type_for_node_id(cx, arg.pat.id, arg.pat.span);
let arg_type = ty::node_id_to_type(cx.tcx, arg.pat.id);
let arg_type = ty::node_id_to_type(cx.tcx(), arg.pat.id);
let arg_type = match param_substs {
None => arg_type,
Some(substs) => {
ty::subst_tps(cx.tcx,
ty::subst_tps(cx.tcx(),
substs.tys.as_slice(),
substs.self_ty,
arg_type)
@ -782,7 +782,7 @@ pub fn create_function_debug_context(cx: &CrateContext,
if has_self_type {
let actual_self_type = self_type.unwrap();
// Add self type name to <...> clause of function name
let actual_self_type_name = ppaux::ty_to_str(cx.tcx, actual_self_type);
let actual_self_type_name = ppaux::ty_to_str(cx.tcx(), actual_self_type);
name_to_append_suffix_to.push_str(actual_self_type_name);
if generics.is_type_parameterized() {
@ -826,7 +826,7 @@ pub fn create_function_debug_context(cx: &CrateContext,
for (index, &ast::TyParam{ ident: ident, .. }) in generics.ty_params.iter().enumerate() {
let actual_type = *actual_types.get(index);
// Add actual type name to <...> clause of function name
let actual_type_name = ppaux::ty_to_str(cx.tcx, actual_type);
let actual_type_name = ppaux::ty_to_str(cx.tcx(), actual_type);
name_to_append_suffix_to.push_str(actual_type_name);
if index != generics.ty_params.len() - 1 {
@ -1118,7 +1118,7 @@ fn pointer_type_metadata(cx: &CrateContext,
-> DIType {
let pointer_llvm_type = type_of::type_of(cx, pointer_type);
let (pointer_size, pointer_align) = size_and_align_of(cx, pointer_llvm_type);
let name = ppaux::ty_to_str(cx.tcx, pointer_type);
let name = ppaux::ty_to_str(cx.tcx(), pointer_type);
let ptr_metadata = name.with_c_str(|name| {
unsafe {
llvm::LLVMDIBuilderCreatePointerType(
@ -1190,7 +1190,7 @@ fn prepare_struct_metadata(cx: &CrateContext,
substs: &ty::substs,
span: Span)
-> RecursiveTypeDescription {
let struct_name = ppaux::ty_to_str(cx.tcx, struct_type);
let struct_name = ppaux::ty_to_str(cx.tcx(), struct_type);
let struct_llvm_type = type_of::type_of(cx, struct_type);
let (containing_scope, definition_span) = get_namespace_and_span_for_item(cx, def_id);
@ -1205,7 +1205,7 @@ fn prepare_struct_metadata(cx: &CrateContext,
file_metadata,
definition_span);
let fields = ty::struct_fields(cx.tcx, def_id, substs);
let fields = ty::struct_fields(cx.tcx(), def_id, substs);
UnfinishedMetadata {
cache_id: cache_id_for_type(struct_type),
@ -1288,7 +1288,7 @@ fn prepare_tuple_metadata(cx: &CrateContext,
component_types: &[ty::t],
span: Span)
-> RecursiveTypeDescription {
let tuple_name = ppaux::ty_to_str(cx.tcx, tuple_type);
let tuple_name = ppaux::ty_to_str(cx.tcx(), tuple_type);
let tuple_llvm_type = type_of::type_of(cx, tuple_type);
let loc = span_start(cx, span);
@ -1393,9 +1393,9 @@ fn describe_enum_variant(cx: &CrateContext,
span: Span)
-> (DICompositeType, Type, MemberDescriptionFactory) {
let variant_llvm_type =
Type::struct_(struct_def.fields
.map(|&t| type_of::type_of(cx, t))
.as_slice(),
Type::struct_(cx, struct_def.fields
.map(|&t| type_of::type_of(cx, t))
.as_slice(),
struct_def.packed);
// Could some consistency checks here: size, align, field count, discr type
@ -1448,7 +1448,7 @@ fn prepare_enum_metadata(cx: &CrateContext,
enum_def_id: ast::DefId,
span: Span)
-> RecursiveTypeDescription {
let enum_name = ppaux::ty_to_str(cx.tcx, enum_type);
let enum_name = ppaux::ty_to_str(cx.tcx(), enum_type);
let (containing_scope, definition_span) = get_namespace_and_span_for_item(cx, enum_def_id);
let loc = span_start(cx, definition_span);
@ -1456,9 +1456,9 @@ fn prepare_enum_metadata(cx: &CrateContext,
// For empty enums there is an early exit. Just describe it as an empty struct with the
// appropriate type name
if ty::type_is_empty(cx.tcx, enum_type) {
if ty::type_is_empty(cx.tcx(), enum_type) {
let empty_type_metadata = composite_type_metadata(cx,
Type::nil(),
Type::nil(cx),
enum_name,
[],
containing_scope,
@ -1468,7 +1468,7 @@ fn prepare_enum_metadata(cx: &CrateContext,
return FinalMetadata(empty_type_metadata);
}
let variants = ty::enum_variants(cx.tcx, enum_def_id);
let variants = ty::enum_variants(cx.tcx(), enum_def_id);
let enumerators_metadata: Vec<DIDescriptor> = variants
.iter()
@ -1754,7 +1754,7 @@ fn boxed_type_metadata(cx: &CrateContext,
content_llvm_type));
let int_type = ty::mk_int();
let nil_pointer_type = ty::mk_nil_ptr(cx.tcx);
let nil_pointer_type = ty::mk_nil_ptr(cx.tcx());
let nil_pointer_type_metadata = type_metadata(cx, nil_pointer_type, codemap::DUMMY_SP);
let member_descriptions = [
@ -1811,8 +1811,8 @@ fn boxed_type_metadata(cx: &CrateContext,
member_llvm_types.len() == 5 &&
member_llvm_types[0] == cx.int_type &&
member_llvm_types[1] == Type::generic_glue_fn(cx).ptr_to() &&
member_llvm_types[2] == Type::i8().ptr_to() &&
member_llvm_types[3] == Type::i8().ptr_to() &&
member_llvm_types[2] == Type::i8(cx).ptr_to() &&
member_llvm_types[3] == Type::i8(cx).ptr_to() &&
member_llvm_types[4] == content_llvm_type
}
}
@ -1853,8 +1853,8 @@ fn vec_metadata(cx: &CrateContext,
let element_llvm_type = type_of::type_of(cx, element_type);
let (element_size, element_align) = size_and_align_of(cx, element_llvm_type);
let vec_llvm_type = Type::vec(cx.sess().targ_cfg.arch, &element_llvm_type);
let vec_type_name: &str = format!("[{}]", ppaux::ty_to_str(cx.tcx, element_type));
let vec_llvm_type = Type::vec(cx, &element_llvm_type);
let vec_type_name: &str = format!("[{}]", ppaux::ty_to_str(cx.tcx(), element_type));
let member_llvm_types = vec_llvm_type.field_types();
@ -1913,14 +1913,17 @@ fn vec_slice_metadata(cx: &CrateContext,
debug!("vec_slice_metadata: {:?}", ty::get(vec_type));
let slice_llvm_type = type_of::type_of(cx, vec_type);
let slice_type_name = ppaux::ty_to_str(cx.tcx, vec_type);
let slice_type_name = ppaux::ty_to_str(cx.tcx(), vec_type);
let member_llvm_types = slice_llvm_type.field_types();
assert!(slice_layout_is_correct(cx,
member_llvm_types.as_slice(),
element_type));
let data_ptr_type = ty::mk_ptr(cx.tcx, ty::mt { ty: element_type, mutbl: ast::MutImmutable });
let data_ptr_type = ty::mk_ptr(cx.tcx(), ty::mt {
ty: element_type,
mutbl: ast::MutImmutable
});
let member_descriptions = [
MemberDescription {
@ -2001,13 +2004,13 @@ fn trait_metadata(cx: &CrateContext,
// The implementation provided here is a stub. It makes sure that the trait type is
// assigned the correct name, size, namespace, and source location. But it does not describe
// the trait's methods.
let last = ty::with_path(cx.tcx, def_id, |mut path| path.last().unwrap());
let last = ty::with_path(cx.tcx(), def_id, |mut path| path.last().unwrap());
let ident_string = token::get_name(last.name());
let name = ppaux::trait_store_to_str(cx.tcx, trait_store) +
let name = ppaux::trait_store_to_str(cx.tcx(), trait_store) +
ppaux::mutability_to_str(mutability) +
ident_string.get();
// Add type and region parameters
let name = ppaux::parameterized(cx.tcx, name, &substs.regions,
let name = ppaux::parameterized(cx.tcx(), name, &substs.regions,
substs.tps.as_slice(), def_id, true);
let (containing_scope, definition_span) = get_namespace_and_span_for_item(cx, def_id);
@ -2044,7 +2047,7 @@ fn type_metadata(cx: &CrateContext,
pointer_type: ty::t,
type_in_box: ty::t)
-> DIType {
let content_type_name: &str = ppaux::ty_to_str(cx.tcx, type_in_box);
let content_type_name: &str = ppaux::ty_to_str(cx.tcx(), type_in_box);
let content_llvm_type = type_of::type_of(cx, type_in_box);
let content_type_metadata = type_metadata(
cx,
@ -2127,9 +2130,9 @@ fn type_metadata(cx: &CrateContext,
trait_metadata(cx, def_id, t, substs, trait_store, mutability, bounds)
},
ty::ty_struct(def_id, ref substs) => {
if ty::type_is_simd(cx.tcx, t) {
let element_type = ty::simd_type(cx.tcx, t);
let len = ty::simd_size(cx.tcx, t);
if ty::type_is_simd(cx.tcx(), t) {
let element_type = ty::simd_type(cx.tcx(), t);
let len = ty::simd_size(cx.tcx(), t);
fixed_vec_metadata(cx, element_type, len, usage_site_span)
} else {
prepare_struct_metadata(cx, t, def_id, substs, usage_site_span).finalize(cx)
@ -2176,7 +2179,7 @@ fn set_debug_location(cx: &CrateContext, debug_location: DebugLocation) {
KnownLocation { scope, line, .. } => {
let col = 0; // Always set the column to zero like Clang and GCC
debug!("setting debug location to {} {}", line, col);
let elements = [C_i32(line as i32), C_i32(col as i32), scope, ptr::null()];
let elements = [C_i32(cx, line as i32), C_i32(cx, col as i32), scope, ptr::null()];
unsafe {
metadata_node = llvm::LLVMMDNodeInContext(debug_context(cx).llcontext,
elements.as_ptr(),
@ -2748,7 +2751,7 @@ impl NamespaceTreeNode {
}
fn namespace_for_item(cx: &CrateContext, def_id: ast::DefId) -> @NamespaceTreeNode {
ty::with_path(cx.tcx, def_id, |path| {
ty::with_path(cx.tcx(), def_id, |path| {
// prepend crate name if not already present
let krate = if def_id.krate == ast::LOCAL_CRATE {
let crate_namespace_ident = token::str_to_ident(cx.link_meta.crateid.name);

View file

@ -523,7 +523,7 @@ fn trans_index<'a>(bcx: &'a Block<'a>,
let bounds_check = ICmp(bcx, lib::llvm::IntUGE, ix_val, len);
let expect = ccx.intrinsics.get_copy(&("llvm.expect.i1"));
let expected = Call(bcx, expect, [bounds_check, C_i1(false)], []);
let expected = Call(bcx, expect, [bounds_check, C_i1(ccx, false)], []);
let bcx = with_cond(bcx, expected, |bcx| {
controlflow::trans_fail_bounds_check(bcx, index_expr.span, ix_val, len)
});
@ -816,7 +816,6 @@ fn trans_def_dps_unadjusted<'a>(
dest: Dest)
-> &'a Block<'a> {
let _icx = push_ctxt("trans_def_dps_unadjusted");
let ccx = bcx.ccx();
let lldest = match dest {
SaveIn(lldest) => lldest,
@ -825,7 +824,7 @@ fn trans_def_dps_unadjusted<'a>(
match def {
ast::DefVariant(tid, vid, _) => {
let variant_info = ty::enum_variant_with_id(ccx.tcx, tid, vid);
let variant_info = ty::enum_variant_with_id(bcx.tcx(), tid, vid);
if variant_info.args.len() > 0u {
// N-ary variant.
let llfn = callee::trans_fn_ref(bcx, vid, ExprId(ref_expr.id));
@ -834,7 +833,7 @@ fn trans_def_dps_unadjusted<'a>(
} else {
// Nullary variant.
let ty = expr_ty(bcx, ref_expr);
let repr = adt::represent_type(ccx, ty);
let repr = adt::represent_type(bcx.ccx(), ty);
adt::trans_start_init(bcx, repr, lldest,
variant_info.disr_val);
return bcx;
@ -843,8 +842,8 @@ fn trans_def_dps_unadjusted<'a>(
ast::DefStruct(_) => {
let ty = expr_ty(bcx, ref_expr);
match ty::get(ty).sty {
ty::ty_struct(did, _) if ty::has_dtor(ccx.tcx, did) => {
let repr = adt::represent_type(ccx, ty);
ty::ty_struct(did, _) if ty::has_dtor(bcx.tcx(), did) => {
let repr = adt::represent_type(bcx.ccx(), ty);
adt::trans_start_init(bcx, repr, lldest, 0);
}
_ => {}
@ -1150,6 +1149,7 @@ fn trans_unary<'a>(bcx: &'a Block<'a>,
op: ast::UnOp,
sub_expr: &ast::Expr)
-> DatumBlock<'a, Expr> {
let ccx = bcx.ccx();
let mut bcx = bcx;
let _icx = push_ctxt("trans_unary_datum");
@ -1160,7 +1160,7 @@ fn trans_unary<'a>(bcx: &'a Block<'a>,
// Otherwise, we should be in the RvalueDpsExpr path.
assert!(
op == ast::UnDeref ||
!bcx.ccx().maps.method_map.borrow().get().contains_key(&method_call));
!ccx.maps.method_map.borrow().get().contains_key(&method_call));
let un_ty = expr_ty(bcx, expr);
@ -1172,8 +1172,8 @@ fn trans_unary<'a>(bcx: &'a Block<'a>,
let llcond = ICmp(bcx,
lib::llvm::IntEQ,
val,
C_bool(false));
Select(bcx, llcond, C_bool(true), C_bool(false))
C_bool(ccx, false));
Select(bcx, llcond, C_bool(ccx, true), C_bool(ccx, false))
} else {
// Note: `Not` is bitwise, not suitable for logical not.
Not(bcx, datum.to_llscalarish(bcx))
@ -1361,7 +1361,7 @@ fn trans_eager_binop<'a>(
}
ast::BiEq | ast::BiNe | ast::BiLt | ast::BiGe | ast::BiLe | ast::BiGt => {
if ty::type_is_bot(rhs_t) {
C_bool(false)
C_bool(bcx.ccx(), false)
} else {
if !ty::type_is_scalar(rhs_t) {
bcx.tcx().sess.span_bug(binop_expr.span,
@ -1369,7 +1369,7 @@ fn trans_eager_binop<'a>(
}
let cmpr = base::compare_scalar_types(bcx, lhs, rhs, rhs_t, op);
bcx = cmpr.bcx;
ZExt(bcx, cmpr.val, Type::i8())
ZExt(bcx, cmpr.val, Type::i8(bcx.ccx()))
}
}
_ => {
@ -1421,8 +1421,8 @@ fn trans_lazy_binop<'a>(
}
Br(past_rhs, join.llbb);
let phi = Phi(join, Type::bool(), [lhs, rhs], [past_lhs.llbb,
past_rhs.llbb]);
let phi = Phi(join, Type::bool(bcx.ccx()), [lhs, rhs],
[past_lhs.llbb, past_rhs.llbb]);
return immediate_rvalue_bcx(join, phi, binop_ty).to_expr_datumblock();
}
@ -1612,7 +1612,7 @@ fn trans_imm_cast<'a>(bcx: &'a Block<'a>,
bcx, datum.to_lvalue_datum(bcx, "trans_imm_cast", expr.id));
let llexpr_ptr = datum.to_llref();
let lldiscrim_a =
adt::trans_get_discr(bcx, repr, llexpr_ptr, Some(Type::i64()));
adt::trans_get_discr(bcx, repr, llexpr_ptr, Some(Type::i64(ccx)));
match k_out {
cast_integral => int_cast(bcx, ll_t_out,
val_ty(lldiscrim_a),
@ -1620,14 +1620,14 @@ fn trans_imm_cast<'a>(bcx: &'a Block<'a>,
cast_float => SIToFP(bcx, lldiscrim_a, ll_t_out),
_ => ccx.sess().bug(format!("translating unsupported cast: \
{} ({:?}) -> {} ({:?})",
t_in.repr(ccx.tcx), k_in,
t_out.repr(ccx.tcx), k_out))
t_in.repr(bcx.tcx()), k_in,
t_out.repr(bcx.tcx()), k_out))
}
}
_ => ccx.sess().bug(format!("translating unsupported cast: \
{} ({:?}) -> {} ({:?})",
t_in.repr(ccx.tcx), k_in,
t_out.repr(ccx.tcx), k_out))
t_in.repr(bcx.tcx()), k_in,
t_out.repr(bcx.tcx()), k_out))
};
return immediate_rvalue_bcx(bcx, newval, t_out).to_expr_datumblock();
}

View file

@ -134,7 +134,7 @@ pub fn llvm_linkage_by_name(name: &str) -> Option<Linkage> {
pub fn register_static(ccx: &CrateContext,
foreign_item: &ast::ForeignItem) -> ValueRef {
let ty = ty::node_id_to_type(ccx.tcx, foreign_item.id);
let ty = ty::node_id_to_type(ccx.tcx(), foreign_item.id);
let llty = type_of::type_of(ccx, ty);
// Treat the crate map static specially in order to
@ -215,7 +215,7 @@ pub fn register_foreign_item_fn(ccx: &CrateContext, abis: AbiSet,
debug!("register_foreign_item_fn(abis={}, \
path={}, \
foreign_item.id={})",
abis.repr(ccx.tcx),
abis.repr(ccx.tcx()),
ccx.tcx.map.path_to_str(foreign_item.id),
foreign_item.id);
@ -225,7 +225,7 @@ pub fn register_foreign_item_fn(ccx: &CrateContext, abis: AbiSet,
ccx.sess().span_fatal(foreign_item.span,
format!("ABI `{}` has no suitable calling convention \
for target architecture",
abis.user_string(ccx.tcx)));
abis.user_string(ccx.tcx())));
}
};
@ -240,7 +240,7 @@ pub fn register_foreign_item_fn(ccx: &CrateContext, abis: AbiSet,
}
// Create the LLVM value for the C extern fn
let llfn_ty = lltype_for_fn_from_foreign_types(&tys);
let llfn_ty = lltype_for_fn_from_foreign_types(ccx, &tys);
let llfn;
{
@ -386,7 +386,7 @@ pub fn trans_native_call<'a>(
ccx.sess().fatal(
format!("ABI string `{}` has no suitable ABI \
for target architecture",
fn_abis.user_string(ccx.tcx)));
fn_abis.user_string(ccx.tcx())));
}
};
@ -440,8 +440,8 @@ pub fn trans_native_call<'a>(
// bitcasting to the struct type yields invalid cast errors.
let llscratch = base::alloca(bcx, llforeign_ret_ty, "__cast");
Store(bcx, llforeign_retval, llscratch);
let llscratch_i8 = BitCast(bcx, llscratch, Type::i8().ptr_to());
let llretptr_i8 = BitCast(bcx, llretptr, Type::i8().ptr_to());
let llscratch_i8 = BitCast(bcx, llscratch, Type::i8(ccx).ptr_to());
let llretptr_i8 = BitCast(bcx, llretptr, Type::i8(ccx).ptr_to());
let llrust_size = machine::llsize_of_store(ccx, llrust_ret_ty);
let llforeign_align = machine::llalign_of_min(ccx, llforeign_ret_ty);
let llrust_align = machine::llalign_of_min(ccx, llrust_ret_ty);
@ -507,8 +507,8 @@ pub fn register_rust_fn_with_foreign_abi(ccx: &CrateContext,
let _icx = push_ctxt("foreign::register_foreign_fn");
let tys = foreign_types_for_id(ccx, node_id);
let llfn_ty = lltype_for_fn_from_foreign_types(&tys);
let t = ty::node_id_to_type(ccx.tcx, node_id);
let llfn_ty = lltype_for_fn_from_foreign_types(ccx, &tys);
let t = ty::node_id_to_type(ccx.tcx(), node_id);
let (cconv, output) = match ty::get(t).sty {
ty::ty_bare_fn(ref fn_ty) => {
let c = llvm_calling_convention(ccx, fn_ty.abis);
@ -547,7 +547,7 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: &CrateContext,
id: ast::NodeId)
-> ValueRef {
let _icx = push_ctxt("foreign::foreign::build_rust_fn");
let tcx = ccx.tcx;
let tcx = ccx.tcx();
let t = ty::node_id_to_type(tcx, id);
let ps = ccx.tcx.map.with_path(id, |path| {
@ -590,7 +590,7 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: &CrateContext,
tys: &ForeignTypes) {
let _icx = push_ctxt(
"foreign::trans_rust_fn_with_foreign_abi::build_wrap_fn");
let tcx = ccx.tcx;
let tcx = ccx.tcx();
debug!("build_wrap_fn(llrustfn={}, llwrapfn={})",
ccx.tn.val_to_str(llrustfn),
@ -853,7 +853,7 @@ fn foreign_signature(ccx: &CrateContext, fn_sig: &ty::FnSig, arg_tys: &[ty::t])
fn foreign_types_for_id(ccx: &CrateContext,
id: ast::NodeId) -> ForeignTypes {
foreign_types_for_fn_ty(ccx, ty::node_id_to_type(ccx.tcx, id))
foreign_types_for_fn_ty(ccx, ty::node_id_to_type(ccx.tcx(), id))
}
fn foreign_types_for_fn_ty(ccx: &CrateContext,
@ -873,7 +873,7 @@ fn foreign_types_for_fn_ty(ccx: &CrateContext,
llsig={} -> {}, \
fn_ty={} -> {}, \
ret_def={}",
ty.repr(ccx.tcx),
ty.repr(ccx.tcx()),
ccx.tn.types_to_str(llsig.llarg_tys.as_slice()),
ccx.tn.type_to_str(llsig.llret_ty),
ccx.tn.types_to_str(fn_ty.arg_tys.map(|t| t.ty).as_slice()),
@ -888,13 +888,13 @@ fn foreign_types_for_fn_ty(ccx: &CrateContext,
}
}
fn lltype_for_fn_from_foreign_types(tys: &ForeignTypes) -> Type {
fn lltype_for_fn_from_foreign_types(ccx: &CrateContext, tys: &ForeignTypes) -> Type {
let mut llargument_tys = Vec::new();
let ret_ty = tys.fn_ty.ret_ty;
let llreturn_ty = if ret_ty.is_indirect() {
llargument_tys.push(ret_ty.ty.ptr_to());
Type::void()
Type::void(ccx)
} else {
match ret_ty.cast {
Some(ty) => ty,
@ -929,8 +929,7 @@ fn lltype_for_fn_from_foreign_types(tys: &ForeignTypes) -> Type {
}
pub fn lltype_for_foreign_fn(ccx: &CrateContext, ty: ty::t) -> Type {
let fn_types = foreign_types_for_fn_ty(ccx, ty);
lltype_for_fn_from_foreign_types(&fn_types)
lltype_for_fn_from_foreign_types(ccx, &foreign_types_for_fn_ty(ccx, ty))
}
fn add_argument_attributes(tys: &ForeignTypes,

View file

@ -46,7 +46,7 @@ pub fn trans_free<'a>(cx: &'a Block<'a>, v: ValueRef) -> &'a Block<'a> {
let _icx = push_ctxt("trans_free");
callee::trans_lang_call(cx,
langcall(cx, None, "", FreeFnLangItem),
[PointerCast(cx, v, Type::i8p())],
[PointerCast(cx, v, Type::i8p(cx.ccx()))],
Some(expr::Ignore)).bcx
}
@ -55,7 +55,7 @@ pub fn trans_exchange_free<'a>(cx: &'a Block<'a>, v: ValueRef)
let _icx = push_ctxt("trans_exchange_free");
callee::trans_lang_call(cx,
langcall(cx, None, "", ExchangeFreeFnLangItem),
[PointerCast(cx, v, Type::i8p())],
[PointerCast(cx, v, Type::i8p(cx.ccx()))],
Some(expr::Ignore)).bcx
}
@ -74,7 +74,7 @@ pub fn take_ty<'a>(bcx: &'a Block<'a>, v: ValueRef, t: ty::t)
}
fn get_drop_glue_type(ccx: &CrateContext, t: ty::t) -> ty::t {
let tcx = ccx.tcx;
let tcx = ccx.tcx();
if !ty::type_needs_drop(tcx, t) {
return ty::mk_i8();
}
@ -128,21 +128,15 @@ pub fn drop_ty_immediate<'a>(bcx: &'a Block<'a>, v: ValueRef, t: ty::t)
pub fn get_drop_glue(ccx: &CrateContext, t: ty::t) -> ValueRef {
let t = get_drop_glue_type(ccx, t);
{
let drop_glues = ccx.drop_glues.borrow();
match drop_glues.get().find(&t) {
Some(&glue) => return glue,
_ => { }
}
match ccx.drop_glues.borrow().get().find(&t) {
Some(&glue) => return glue,
_ => { }
}
let llfnty = Type::glue_fn(type_of(ccx, t).ptr_to());
let llfnty = Type::glue_fn(ccx, type_of(ccx, t).ptr_to());
let glue = declare_generic_glue(ccx, t, llfnty, "drop");
{
let mut drop_glues = ccx.drop_glues.borrow_mut();
drop_glues.get().insert(t, glue);
}
ccx.drop_glues.borrow_mut().get().insert(t, glue);
make_generic_glue(ccx, t, glue, make_drop_glue, "drop");
@ -152,16 +146,16 @@ pub fn get_drop_glue(ccx: &CrateContext, t: ty::t) -> ValueRef {
pub fn lazily_emit_visit_glue(ccx: &CrateContext, ti: @tydesc_info) {
let _icx = push_ctxt("lazily_emit_visit_glue");
let llfnty = Type::glue_fn(type_of(ccx, ti.ty).ptr_to());
let llfnty = Type::glue_fn(ccx, type_of(ccx, ti.ty).ptr_to());
match ti.visit_glue.get() {
Some(_) => (),
None => {
debug!("+++ lazily_emit_tydesc_glue VISIT {}", ppaux::ty_to_str(ccx.tcx, ti.ty));
debug!("+++ lazily_emit_tydesc_glue VISIT {}", ppaux::ty_to_str(ccx.tcx(), ti.ty));
let glue_fn = declare_generic_glue(ccx, ti.ty, llfnty, "visit");
ti.visit_glue.set(Some(glue_fn));
make_generic_glue(ccx, ti.ty, glue_fn, make_visit_glue, "visit");
debug!("--- lazily_emit_tydesc_glue VISIT {}", ppaux::ty_to_str(ccx.tcx, ti.ty));
debug!("--- lazily_emit_tydesc_glue VISIT {}", ppaux::ty_to_str(ccx.tcx(), ti.ty));
}
}
}
@ -185,7 +179,7 @@ pub fn call_visit_glue(bcx: &Block, v: ValueRef, tydesc: ValueRef,
// When static type info is available, avoid casting to a generic pointer.
let llrawptr = if static_glue_fn.is_none() {
PointerCast(bcx, v, Type::i8p())
PointerCast(bcx, v, Type::i8p(ccx))
} else {
v
};
@ -283,7 +277,6 @@ fn trans_struct_drop<'a>(bcx: &'a Block<'a>,
fn make_drop_glue<'a>(bcx: &'a Block<'a>, v0: ValueRef, t: ty::t) -> &'a Block<'a> {
// NB: v0 is an *alias* of type t here, not a direct value.
let _icx = push_ctxt("make_drop_glue");
let ccx = bcx.ccx();
match ty::get(t).sty {
ty::ty_box(body_ty) => {
decr_refcnt_maybe_free(bcx, v0, body_ty)
@ -323,27 +316,27 @@ fn make_drop_glue<'a>(bcx: &'a Block<'a>, v0: ValueRef, t: ty::t) -> &'a Block<'
with_cond(bcx, IsNotNull(bcx, Load(bcx, lluniquevalue)), |bcx| {
let dtor_ptr = Load(bcx, GEPi(bcx, v0, [0, abi::trt_field_vtable]));
let dtor = Load(bcx, dtor_ptr);
Call(bcx, dtor, [PointerCast(bcx, lluniquevalue, Type::i8p())], []);
Call(bcx, dtor, [PointerCast(bcx, lluniquevalue, Type::i8p(bcx.ccx()))], []);
bcx
})
}
ty::ty_closure(ref f) if f.sigil == ast::OwnedSigil => {
let box_cell_v = GEPi(bcx, v0, [0u, abi::fn_field_box]);
let env = Load(bcx, box_cell_v);
let env_ptr_ty = Type::at_box(ccx, Type::i8()).ptr_to();
let env_ptr_ty = Type::at_box(bcx.ccx(), Type::i8(bcx.ccx())).ptr_to();
let env = PointerCast(bcx, env, env_ptr_ty);
with_cond(bcx, IsNotNull(bcx, env), |bcx| {
let dtor_ptr = GEPi(bcx, env, [0u, abi::box_field_tydesc]);
let dtor = Load(bcx, dtor_ptr);
let cdata = GEPi(bcx, env, [0u, abi::box_field_body]);
Call(bcx, dtor, [PointerCast(bcx, cdata, Type::i8p())], []);
Call(bcx, dtor, [PointerCast(bcx, cdata, Type::i8p(bcx.ccx()))], []);
// Free the environment itself
trans_exchange_free(bcx, env)
})
}
_ => {
if ty::type_needs_drop(ccx.tcx, t) &&
if ty::type_needs_drop(bcx.tcx(), t) &&
ty::type_is_structural(t) {
iter_structural_ty(bcx, v0, t, drop_ty)
} else {
@ -405,21 +398,21 @@ pub fn declare_tydesc(ccx: &CrateContext, t: ty::t) -> @tydesc_info {
if ccx.sess().count_type_sizes() {
println!("{}\t{}", llsize_of_real(ccx, llty),
ppaux::ty_to_str(ccx.tcx, t));
ppaux::ty_to_str(ccx.tcx(), t));
}
let llsize = llsize_of(ccx, llty);
let llalign = llalign_of(ccx, llty);
let name = mangle_internal_name_by_type_and_seq(ccx, t, "tydesc");
debug!("+++ declare_tydesc {} {}", ppaux::ty_to_str(ccx.tcx, t), name);
debug!("+++ declare_tydesc {} {}", ppaux::ty_to_str(ccx.tcx(), t), name);
let gvar = name.with_c_str(|buf| {
unsafe {
llvm::LLVMAddGlobal(ccx.llmod, ccx.tydesc_type.to_ref(), buf)
llvm::LLVMAddGlobal(ccx.llmod, ccx.tydesc_type().to_ref(), buf)
}
});
note_unique_llvm_symbol(ccx, name);
let ty_name = token::intern_and_get_ident(ppaux::ty_to_str(ccx.tcx, t));
let ty_name = token::intern_and_get_ident(ppaux::ty_to_str(ccx.tcx(), t));
let ty_name = C_str_slice(ccx, ty_name);
let inf = @tydesc_info {
@ -430,7 +423,7 @@ pub fn declare_tydesc(ccx: &CrateContext, t: ty::t) -> @tydesc_info {
name: ty_name,
visit_glue: Cell::new(None),
};
debug!("--- declare_tydesc {}", ppaux::ty_to_str(ccx.tcx, t));
debug!("--- declare_tydesc {}", ppaux::ty_to_str(ccx.tcx(), t));
return inf;
}
@ -438,7 +431,7 @@ fn declare_generic_glue(ccx: &CrateContext, t: ty::t, llfnty: Type,
name: &str) -> ValueRef {
let _icx = push_ctxt("declare_generic_glue");
let fn_nm = mangle_internal_name_by_type_and_seq(ccx, t, ~"glue_" + name);
debug!("{} is for type {}", fn_nm, ppaux::ty_to_str(ccx.tcx, t));
debug!("{} is for type {}", fn_nm, ppaux::ty_to_str(ccx.tcx(), t));
let llfn = decl_cdecl_fn(ccx.llmod, fn_nm, llfnty, ty::mk_nil());
note_unique_llvm_symbol(ccx, fn_nm);
return llfn;
@ -452,7 +445,7 @@ fn make_generic_glue(ccx: &CrateContext,
name: &str)
-> ValueRef {
let _icx = push_ctxt("make_generic_glue");
let glue_name = format!("glue {} {}", name, ty_to_short_str(ccx.tcx, t));
let glue_name = format!("glue {} {}", name, ty_to_short_str(ccx.tcx(), t));
let _s = StatRecorder::new(ccx, glue_name);
let arena = TypedArena::new();
@ -511,7 +504,7 @@ pub fn emit_tydescs(ccx: &CrateContext) {
}
};
let tydesc = C_named_struct(ccx.tydesc_type,
let tydesc = C_named_struct(ccx.tydesc_type(),
[ti.size, // size
ti.align, // align
drop_glue, // drop_glue

View file

@ -28,7 +28,7 @@ pub fn maybe_instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId)
Some(&Some(node_id)) => {
// Already inline
debug!("maybe_instantiate_inline({}): already inline as node id {}",
ty::item_path_str(ccx.tcx, fn_id), node_id);
ty::item_path_str(ccx.tcx(), fn_id), node_id);
return local_def(node_id);
}
Some(&None) => {
@ -42,8 +42,8 @@ pub fn maybe_instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId)
let csearch_result =
csearch::maybe_get_item_ast(
ccx.tcx, fn_id,
|a,b,c,d| astencode::decode_inlined_item(a, b, ccx.maps, c, d));
ccx.tcx(), fn_id,
|a,b,c,d| astencode::decode_inlined_item(a, b, &ccx.maps, c, d));
return match csearch_result {
csearch::not_found => {
let mut external = ccx.external.borrow_mut();
@ -104,8 +104,8 @@ pub fn maybe_instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId)
let mut my_id = 0;
match item.node {
ast::ItemEnum(_, _) => {
let vs_here = ty::enum_variants(ccx.tcx, local_def(item.id));
let vs_there = ty::enum_variants(ccx.tcx, parent_id);
let vs_here = ty::enum_variants(ccx.tcx(), local_def(item.id));
let vs_there = ty::enum_variants(ccx.tcx(), parent_id);
for (here, there) in vs_here.iter().zip(vs_there.iter()) {
if there.id == fn_id { my_id = here.id.node; }
let mut external = ccx.external.borrow_mut();
@ -146,7 +146,7 @@ pub fn maybe_instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId)
// impl type. But we aren't going to translate anyways, so don't.
if is_provided { return local_def(mth.id); }
let impl_tpt = ty::lookup_item_type(ccx.tcx, impl_did);
let impl_tpt = ty::lookup_item_type(ccx.tcx(), impl_did);
let num_type_params =
impl_tpt.generics.type_param_defs().len() +
mth.generics.ty_params.len();

View file

@ -99,7 +99,7 @@ pub fn trans_intrinsic(ccx: &CrateContext,
// convert `i1` to a `bool`, and write to the out parameter
let val = Call(bcx, llfn, [a, b], []);
let result = ExtractValue(bcx, val, 0);
let overflow = ZExt(bcx, ExtractValue(bcx, val, 1), Type::bool());
let overflow = ZExt(bcx, ExtractValue(bcx, val, 1), Type::bool(bcx.ccx()));
let ret = C_undef(type_of::type_of(bcx.ccx(), t));
let ret = InsertValue(bcx, ret, result, 0);
let ret = InsertValue(bcx, ret, overflow, 1);
@ -133,7 +133,7 @@ pub fn trans_intrinsic(ccx: &CrateContext,
fn copy_intrinsic(bcx: &Block, allow_overlap: bool, tp_ty: ty::t) {
let ccx = bcx.ccx();
let lltp_ty = type_of::type_of(ccx, tp_ty);
let align = C_i32(machine::llalign_of_min(ccx, lltp_ty) as i32);
let align = C_i32(ccx, machine::llalign_of_min(ccx, lltp_ty) as i32);
let size = machine::llsize_of(ccx, lltp_ty);
let int_size = machine::llbitsize_of_real(ccx, ccx.int_type);
let name = if allow_overlap {
@ -152,11 +152,11 @@ pub fn trans_intrinsic(ccx: &CrateContext,
let decl = bcx.fcx.llfn;
let first_real_arg = bcx.fcx.arg_pos(0u);
let dst_ptr = PointerCast(bcx, get_param(decl, first_real_arg), Type::i8p());
let src_ptr = PointerCast(bcx, get_param(decl, first_real_arg + 1), Type::i8p());
let dst_ptr = PointerCast(bcx, get_param(decl, first_real_arg), Type::i8p(ccx));
let src_ptr = PointerCast(bcx, get_param(decl, first_real_arg + 1), Type::i8p(ccx));
let count = get_param(decl, first_real_arg + 2);
let volatile = C_i1(false);
let llfn = bcx.ccx().intrinsics.get_copy(&name);
let volatile = C_i1(ccx, false);
let llfn = ccx.intrinsics.get_copy(&name);
Call(bcx, llfn, [dst_ptr, src_ptr, Mul(bcx, size, count), align, volatile], []);
RetVoid(bcx);
}
@ -164,7 +164,7 @@ pub fn trans_intrinsic(ccx: &CrateContext,
fn memset_intrinsic(bcx: &Block, tp_ty: ty::t) {
let ccx = bcx.ccx();
let lltp_ty = type_of::type_of(ccx, tp_ty);
let align = C_i32(machine::llalign_of_min(ccx, lltp_ty) as i32);
let align = C_i32(ccx, machine::llalign_of_min(ccx, lltp_ty) as i32);
let size = machine::llsize_of(ccx, lltp_ty);
let name = if machine::llbitsize_of_real(ccx, ccx.int_type) == 32 {
"llvm.memset.p0i8.i32"
@ -174,24 +174,24 @@ pub fn trans_intrinsic(ccx: &CrateContext,
let decl = bcx.fcx.llfn;
let first_real_arg = bcx.fcx.arg_pos(0u);
let dst_ptr = PointerCast(bcx, get_param(decl, first_real_arg), Type::i8p());
let dst_ptr = PointerCast(bcx, get_param(decl, first_real_arg), Type::i8p(ccx));
let val = get_param(decl, first_real_arg + 1);
let count = get_param(decl, first_real_arg + 2);
let volatile = C_i1(false);
let llfn = bcx.ccx().intrinsics.get_copy(&name);
let volatile = C_i1(ccx, false);
let llfn = ccx.intrinsics.get_copy(&name);
Call(bcx, llfn, [dst_ptr, val, Mul(bcx, size, count), align, volatile], []);
RetVoid(bcx);
}
fn count_zeros_intrinsic(bcx: &Block, name: &'static str) {
let x = get_param(bcx.fcx.llfn, bcx.fcx.arg_pos(0u));
let y = C_i1(false);
let y = C_i1(bcx.ccx(), false);
let llfn = bcx.ccx().intrinsics.get_copy(&name);
let llcall = Call(bcx, llfn, [x, y], []);
Ret(bcx, llcall);
}
let output_type = ty::ty_fn_ret(ty::node_id_to_type(ccx.tcx, item.id));
let output_type = ty::ty_fn_ret(ty::node_id_to_type(ccx.tcx(), item.id));
let arena = TypedArena::new();
let fcx = new_fn_ctxt(ccx, decl, item.id, false, output_type,
@ -328,12 +328,13 @@ pub fn trans_intrinsic(ccx: &CrateContext,
}
"type_id" => {
let hash = ty::hash_crate_independent(
ccx.tcx,
ccx.tcx(),
*substs.tys.get(0),
&ccx.link_meta.crate_hash);
// NB: This needs to be kept in lockstep with the TypeId struct in
// libstd/unstable/intrinsics.rs
let val = C_named_struct(type_of::type_of(ccx, output_type), [C_u64(hash)]);
let val = C_named_struct(type_of::type_of(ccx, output_type),
[C_u64(ccx, hash)]);
match bcx.fcx.llretptr.get() {
Some(ptr) => {
Store(bcx, val, ptr);
@ -381,9 +382,9 @@ pub fn trans_intrinsic(ccx: &CrateContext,
format!("transmute called on types with different sizes: \
{intype} ({insize, plural, =1{# bit} other{# bits}}) to \
{outtype} ({outsize, plural, =1{# bit} other{# bits}})",
intype = ty_to_str(ccx.tcx, in_type),
intype = ty_to_str(ccx.tcx(), in_type),
insize = in_type_size as uint,
outtype = ty_to_str(ccx.tcx, out_type),
outtype = ty_to_str(ccx.tcx(), out_type),
outsize = out_type_size as uint));
}
@ -421,8 +422,8 @@ pub fn trans_intrinsic(ccx: &CrateContext,
// code bloat when `transmute` is used on large structural
// types.
let lldestptr = fcx.llretptr.get().unwrap();
let lldestptr = PointerCast(bcx, lldestptr, Type::i8p());
let llsrcptr = PointerCast(bcx, llsrcval, Type::i8p());
let lldestptr = PointerCast(bcx, lldestptr, Type::i8p(ccx));
let llsrcptr = PointerCast(bcx, llsrcval, Type::i8p(ccx));
let llsize = llsize_of(ccx, llintype);
call_memcpy(bcx, lldestptr, llsrcptr, llsize, 1);
@ -434,16 +435,16 @@ pub fn trans_intrinsic(ccx: &CrateContext,
}
"needs_drop" => {
let tp_ty = *substs.tys.get(0);
Ret(bcx, C_bool(ty::type_needs_drop(ccx.tcx, tp_ty)));
Ret(bcx, C_bool(ccx, ty::type_needs_drop(ccx.tcx(), tp_ty)));
}
"owns_managed" => {
let tp_ty = *substs.tys.get(0);
Ret(bcx, C_bool(ty::type_contents(ccx.tcx, tp_ty).owns_managed()));
Ret(bcx, C_bool(ccx, ty::type_contents(ccx.tcx(), tp_ty).owns_managed()));
}
"visit_tydesc" => {
let td = get_param(decl, first_real_arg);
let visitor = get_param(decl, first_real_arg + 1u);
let td = PointerCast(bcx, td, ccx.tydesc_type.ptr_to());
let td = PointerCast(bcx, td, ccx.tydesc_type().ptr_to());
glue::call_visit_glue(bcx, visitor, td, None);
RetVoid(bcx);
}

View file

@ -51,7 +51,7 @@ pub fn trans_impl(ccx: &CrateContext,
generics: &ast::Generics,
id: ast::NodeId) {
let _icx = push_ctxt("meth::trans_impl");
let tcx = ccx.tcx;
let tcx = ccx.tcx();
debug!("trans_impl(name={}, id={:?})", name.repr(tcx), id);
@ -270,7 +270,7 @@ fn trans_monomorphized_callee<'a>(bcx: &'a Block<'a>,
match vtbl {
typeck::vtable_static(impl_did, ref rcvr_substs, rcvr_origins) => {
let ccx = bcx.ccx();
let mname = ty::trait_method(ccx.tcx, trait_id, n_method).ident;
let mname = ty::trait_method(ccx.tcx(), trait_id, n_method).ident;
let mth_id = method_with_name(bcx.ccx(), impl_did, mname.name);
// create a concatenated set of substitutions which includes
@ -319,16 +319,16 @@ fn combine_impl_and_methods_tps(bcx: &Block,
* mapped to. */
let ccx = bcx.ccx();
let method = ty::method(ccx.tcx, mth_did);
let method = ty::method(ccx.tcx(), mth_did);
let n_m_tps = method.generics.type_param_defs().len();
let node_substs = node_id_type_params(bcx, node);
debug!("rcvr_substs={:?}", rcvr_substs.repr(ccx.tcx));
debug!("rcvr_substs={:?}", rcvr_substs.repr(ccx.tcx()));
let ty_substs
= vec_ng::append(Vec::from_slice(rcvr_substs),
node_substs.tailn(node_substs.len() - n_m_tps));
debug!("n_m_tps={:?}", n_m_tps);
debug!("node_substs={:?}", node_substs.repr(ccx.tcx));
debug!("ty_substs={:?}", ty_substs.repr(ccx.tcx));
debug!("node_substs={:?}", node_substs.repr(ccx.tcx()));
debug!("ty_substs={:?}", ty_substs.repr(ccx.tcx()));
// Now, do the same work for the vtables. The vtables might not
@ -415,7 +415,7 @@ pub fn trans_trait_callee_from_llval<'a>(bcx: &'a Block<'a>,
debug!("(translating trait callee) loading second index from pair");
let llboxptr = GEPi(bcx, llpair, [0u, abi::trt_field_box]);
let llbox = Load(bcx, llboxptr);
let llself = PointerCast(bcx, llbox, Type::i8p());
let llself = PointerCast(bcx, llbox, Type::i8p(ccx));
// Load the function from the vtable and cast it to the expected type.
debug!("(translating trait callee) loading method");
@ -432,7 +432,7 @@ pub fn trans_trait_callee_from_llval<'a>(bcx: &'a Block<'a>,
PointerCast(bcx,
GEPi(bcx, llpair,
[0u, abi::trt_field_vtable]),
Type::vtable().ptr_to().ptr_to()));
Type::vtable(ccx).ptr_to().ptr_to()));
let mptr = Load(bcx, GEPi(bcx, llvtable, [0u, n_method + 1]));
let mptr = PointerCast(bcx, mptr, llcallee_ty.ptr_to());
@ -526,7 +526,7 @@ pub fn make_vtable(ccx: &CrateContext,
components.push(ptr)
}
let tbl = C_struct(components.as_slice(), false);
let tbl = C_struct(ccx, components.as_slice(), false);
let sym = token::gensym("vtable");
let vt_gvar = format!("vtable{}", sym).with_c_str(|buf| {
llvm::LLVMAddGlobal(ccx.llmod, val_ty(tbl).to_ref(), buf)
@ -544,7 +544,7 @@ fn emit_vtable_methods(bcx: &Block,
vtables: typeck::vtable_res)
-> Vec<ValueRef> {
let ccx = bcx.ccx();
let tcx = ccx.tcx;
let tcx = ccx.tcx();
let trt_id = match ty::impl_trait_ref(tcx, impl_id) {
Some(t_id) => t_id.def_id,
@ -568,7 +568,7 @@ fn emit_vtable_methods(bcx: &Block,
ty::type_has_self(ty::mk_bare_fn(tcx, m.fty.clone())) {
debug!("(making impl vtable) method has self or type params: {}",
token::get_ident(ident));
C_null(Type::nil().ptr_to())
C_null(Type::nil(ccx).ptr_to())
} else {
trans_fn_ref_with_vtables(bcx, m_id, ExprId(0), substs, Some(vtables))
}

View file

@ -41,10 +41,10 @@ pub fn monomorphic_fn(ccx: &CrateContext,
vtables={}, \
self_vtable={}, \
ref_id={:?})",
fn_id.repr(ccx.tcx),
real_substs.repr(ccx.tcx),
vtables.repr(ccx.tcx),
self_vtables.repr(ccx.tcx),
fn_id.repr(ccx.tcx()),
real_substs.repr(ccx.tcx()),
vtables.repr(ccx.tcx()),
self_vtables.repr(ccx.tcx()),
ref_id);
assert!(real_substs.tps.iter().all(|t| !ty::type_needs_infer(*t)));
@ -71,8 +71,8 @@ pub fn monomorphic_fn(ccx: &CrateContext,
fn_id={}, \
psubsts={}, \
hash_id={:?})",
fn_id.repr(ccx.tcx),
psubsts.repr(ccx.tcx),
fn_id.repr(ccx.tcx()),
psubsts.repr(ccx.tcx()),
hash_id);
{
@ -80,14 +80,14 @@ pub fn monomorphic_fn(ccx: &CrateContext,
match monomorphized.get().find(&hash_id) {
Some(&val) => {
debug!("leaving monomorphic fn {}",
ty::item_path_str(ccx.tcx, fn_id));
ty::item_path_str(ccx.tcx(), fn_id));
return (val, must_cast);
}
None => ()
}
}
let tpt = ty::lookup_item_type(ccx.tcx, fn_id);
let tpt = ty::lookup_item_type(ccx.tcx(), fn_id);
let llitem_ty = tpt.ty;
// We need to do special handling of the substitutions if we are
@ -123,9 +123,9 @@ pub fn monomorphic_fn(ccx: &CrateContext,
_ => {}
}
debug!("monomorphic_fn about to subst into {}", llitem_ty.repr(ccx.tcx));
debug!("monomorphic_fn about to subst into {}", llitem_ty.repr(ccx.tcx()));
let mono_ty = match is_static_provided {
None => ty::subst_tps(ccx.tcx, psubsts.tys.as_slice(),
None => ty::subst_tps(ccx.tcx(), psubsts.tys.as_slice(),
psubsts.self_ty, llitem_ty),
Some(num_method_ty_params) => {
// Static default methods are a little unfortunate, in
@ -146,9 +146,9 @@ pub fn monomorphic_fn(ccx: &CrateContext,
let substs = psubsts.tys.slice(0, idx) +
&[psubsts.self_ty.unwrap()] + psubsts.tys.tailn(idx);
debug!("static default: changed substitution to {}",
substs.repr(ccx.tcx));
substs.repr(ccx.tcx()));
ty::subst_tps(ccx.tcx, substs, None, llitem_ty)
ty::subst_tps(ccx.tcx(), substs, None, llitem_ty)
}
};
@ -224,7 +224,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
}
ast_map::NodeVariant(v) => {
let parent = ccx.tcx.map.get_parent(fn_id.node);
let tvs = ty::enum_variants(ccx.tcx, local_def(parent));
let tvs = ty::enum_variants(ccx.tcx(), local_def(parent));
let this_tv = *tvs.iter().find(|tv| { tv.id.node == fn_id.node}).unwrap();
let d = mk_lldecl();
set_inline_hint(d);
@ -290,7 +290,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
monomorphizing.get().insert(fn_id, depth);
}
debug!("leaving monomorphic fn {}", ty::item_path_str(ccx.tcx, fn_id));
debug!("leaving monomorphic fn {}", ty::item_path_str(ccx.tcx(), fn_id));
(lldecl, must_cast)
}
@ -303,7 +303,7 @@ pub fn make_mono_id(ccx: &CrateContext,
let precise_param_ids: Vec<(ty::t, Option<@Vec<mono_id> >)> = match substs.vtables {
Some(vts) => {
debug!("make_mono_id vtables={} substs={}",
vts.repr(ccx.tcx), substs.tys.repr(ccx.tcx));
vts.repr(ccx.tcx()), substs.tys.repr(ccx.tcx()));
let vts_iter = substs.self_vtables.iter().chain(vts.iter());
vts_iter.zip(substs_iter).map(|(vtable, subst)| {
let v = vtable.map(|vt| meth::vtable_id(ccx, vt));

View file

@ -54,7 +54,7 @@ impl<'a> Reflector<'a> {
}
pub fn c_bool(&mut self, b: bool) -> ValueRef {
C_bool(b)
C_bool(self.bcx.ccx(), b)
}
pub fn c_slice(&mut self, s: InternedString) -> ValueRef {
@ -65,7 +65,7 @@ impl<'a> Reflector<'a> {
let str_ty = ty::mk_str(bcx.tcx(), str_vstore);
let scratch = rvalue_scratch_datum(bcx, str_ty, "");
let len = C_uint(bcx.ccx(), s.get().len());
let c_str = PointerCast(bcx, C_cstr(bcx.ccx(), s), Type::i8p());
let c_str = PointerCast(bcx, C_cstr(bcx.ccx(), s), Type::i8p(bcx.ccx()));
Store(bcx, c_str, GEPi(bcx, scratch.val, [ 0, 0 ]));
Store(bcx, len, GEPi(bcx, scratch.val, [ 0, 1 ]));
scratch.val
@ -151,8 +151,8 @@ impl<'a> Reflector<'a> {
// Entrypoint
pub fn visit_ty(&mut self, t: ty::t) {
let bcx = self.bcx;
let tcx = bcx.ccx().tcx;
debug!("reflect::visit_ty {}", ty_to_str(bcx.ccx().tcx, t));
let tcx = bcx.tcx();
debug!("reflect::visit_ty {}", ty_to_str(bcx.tcx(), t));
match ty::get(t).sty {
ty::ty_bot => self.leaf("bot"),
@ -285,10 +285,10 @@ impl<'a> Reflector<'a> {
ty::ty_enum(did, ref substs) => {
let ccx = bcx.ccx();
let repr = adt::represent_type(bcx.ccx(), t);
let variants = ty::substd_enum_variants(ccx.tcx, did, substs);
let variants = ty::substd_enum_variants(ccx.tcx(), did, substs);
let llptrty = type_of(ccx, t).ptr_to();
let opaquety = ty::get_opaque_ty(ccx.tcx).unwrap();
let opaqueptrty = ty::mk_ptr(ccx.tcx, ty::mt { ty: opaquety,
let opaquety = ty::get_opaque_ty(ccx.tcx()).unwrap();
let opaqueptrty = ty::mk_ptr(ccx.tcx(), ty::mt { ty: opaquety,
mutbl: ast::MutImmutable });
let make_get_disr = || {
@ -311,7 +311,7 @@ impl<'a> Reflector<'a> {
};
let bcx = fcx.entry_bcx.get().unwrap();
let arg = BitCast(bcx, arg, llptrty);
let ret = adt::trans_get_discr(bcx, repr, arg, Some(Type::i64()));
let ret = adt::trans_get_discr(bcx, repr, arg, Some(Type::i64(ccx)));
Store(bcx, ret, fcx.llretptr.get().unwrap());
match fcx.llreturn.get() {
Some(llreturn) => Br(bcx, llreturn),
@ -328,23 +328,23 @@ impl<'a> Reflector<'a> {
self.bracketed("enum", enum_args.as_slice(), |this| {
for (i, v) in variants.iter().enumerate() {
let name = token::get_ident(v.name);
let variant_args = vec!(this.c_uint(i),
C_u64(v.disr_val),
let variant_args = [this.c_uint(i),
C_u64(ccx, v.disr_val),
this.c_uint(v.args.len()),
this.c_slice(name));
this.c_slice(name)];
this.bracketed("enum_variant",
variant_args.as_slice(),
variant_args,
|this| {
for (j, a) in v.args.iter().enumerate() {
let bcx = this.bcx;
let null = C_null(llptrty);
let ptr = adt::trans_field_ptr(bcx, repr, null, v.disr_val, j);
let offset = p2i(ccx, ptr);
let field_args = vec!(this.c_uint(j),
let field_args = [this.c_uint(j),
offset,
this.c_tydesc(*a));
this.c_tydesc(*a)];
this.visit("enum_variant_field",
field_args.as_slice());
field_args);
}
})
}
@ -393,7 +393,7 @@ pub fn emit_calls_to_trait_visit_ty<'a>(
-> &'a Block<'a> {
let fcx = bcx.fcx;
let final = fcx.new_temp_block("final");
let tydesc_ty = ty::get_tydesc_ty(bcx.ccx().tcx).unwrap();
let tydesc_ty = ty::get_tydesc_ty(bcx.tcx()).unwrap();
let tydesc_ty = type_of(bcx.ccx(), tydesc_ty);
let mut r = Reflector {
visitor_val: visitor_val,

View file

@ -71,7 +71,7 @@ pub fn get_dataptr(bcx: &Block, vptr: ValueRef) -> ValueRef {
pub fn pointer_add_byte(bcx: &Block, ptr: ValueRef, bytes: ValueRef) -> ValueRef {
let _icx = push_ctxt("tvec::pointer_add_byte");
let old_ty = val_ty(ptr);
let bptr = PointerCast(bcx, ptr, Type::i8p());
let bptr = PointerCast(bcx, ptr, Type::i8p(bcx.ccx()));
return PointerCast(bcx, InBoundsGEP(bcx, bptr, [bytes]), old_ty);
}
@ -154,8 +154,8 @@ impl VecTypes {
pub fn to_str(&self, ccx: &CrateContext) -> ~str {
format!("VecTypes \\{vec_ty={}, unit_ty={}, llunit_ty={}, llunit_size={}, \
llunit_alloc_size={}\\}",
ty_to_str(ccx.tcx, self.vec_ty),
ty_to_str(ccx.tcx, self.unit_ty),
ty_to_str(ccx.tcx(), self.vec_ty),
ty_to_str(ccx.tcx(), self.unit_ty),
ccx.tn.type_to_str(self.llunit_ty),
ccx.tn.val_to_str(self.llunit_size),
self.llunit_alloc_size)
@ -290,7 +290,7 @@ pub fn trans_lit_str<'a>(
let bytes = str_lit.get().len();
let llbytes = C_uint(bcx.ccx(), bytes);
let llcstr = C_cstr(bcx.ccx(), str_lit);
let llcstr = llvm::LLVMConstPointerCast(llcstr, Type::i8p().to_ref());
let llcstr = llvm::LLVMConstPointerCast(llcstr, Type::i8p(bcx.ccx()).to_ref());
Store(bcx, llcstr,
GEPi(bcx, lldest, [0u, abi::slice_elt_base]));
Store(bcx, llbytes,
@ -322,7 +322,7 @@ pub fn trans_uniq_vstore<'a>(bcx: &'a Block<'a>,
let llptrval = C_cstr(bcx.ccx(), (*s).clone());
let llptrval = PointerCast(bcx,
llptrval,
Type::i8p());
Type::i8p(bcx.ccx()));
let llsizeval = C_uint(bcx.ccx(), s.get().len());
let typ = ty::mk_str(bcx.tcx(), ty::vstore_uniq);
let lldestval = rvalue_scratch_datum(bcx,

View file

@ -14,10 +14,9 @@ use lib::llvm::{llvm, TypeRef, Bool, False, True, TypeKind};
use lib::llvm::{Float, Double, X86_FP80, PPC_FP128, FP128};
use middle::trans::context::CrateContext;
use middle::trans::base;
use syntax::ast;
use syntax::abi::{Architecture, X86, X86_64, Arm, Mips};
use syntax::abi::{X86, X86_64, Arm, Mips};
use std::c_str::ToCStr;
use std::cast;
@ -51,100 +50,94 @@ impl Type {
self.rf
}
pub fn void() -> Type {
ty!(llvm::LLVMVoidTypeInContext(base::task_llcx()))
pub fn void(ccx: &CrateContext) -> Type {
ty!(llvm::LLVMVoidTypeInContext(ccx.llcx))
}
pub fn nil() -> Type {
Type::empty_struct()
pub fn nil(ccx: &CrateContext) -> Type {
Type::empty_struct(ccx)
}
pub fn metadata() -> Type {
ty!(llvm::LLVMMetadataTypeInContext(base::task_llcx()))
pub fn metadata(ccx: &CrateContext) -> Type {
ty!(llvm::LLVMMetadataTypeInContext(ccx.llcx))
}
pub fn i1() -> Type {
ty!(llvm::LLVMInt1TypeInContext(base::task_llcx()))
pub fn i1(ccx: &CrateContext) -> Type {
ty!(llvm::LLVMInt1TypeInContext(ccx.llcx))
}
pub fn i8() -> Type {
ty!(llvm::LLVMInt8TypeInContext(base::task_llcx()))
pub fn i8(ccx: &CrateContext) -> Type {
ty!(llvm::LLVMInt8TypeInContext(ccx.llcx))
}
pub fn i16() -> Type {
ty!(llvm::LLVMInt16TypeInContext(base::task_llcx()))
pub fn i16(ccx: &CrateContext) -> Type {
ty!(llvm::LLVMInt16TypeInContext(ccx.llcx))
}
pub fn i32() -> Type {
ty!(llvm::LLVMInt32TypeInContext(base::task_llcx()))
pub fn i32(ccx: &CrateContext) -> Type {
ty!(llvm::LLVMInt32TypeInContext(ccx.llcx))
}
pub fn i64() -> Type {
ty!(llvm::LLVMInt64TypeInContext(base::task_llcx()))
pub fn i64(ccx: &CrateContext) -> Type {
ty!(llvm::LLVMInt64TypeInContext(ccx.llcx))
}
pub fn f32() -> Type {
ty!(llvm::LLVMFloatTypeInContext(base::task_llcx()))
pub fn f32(ccx: &CrateContext) -> Type {
ty!(llvm::LLVMFloatTypeInContext(ccx.llcx))
}
pub fn f64() -> Type {
ty!(llvm::LLVMDoubleTypeInContext(base::task_llcx()))
pub fn f64(ccx: &CrateContext) -> Type {
ty!(llvm::LLVMDoubleTypeInContext(ccx.llcx))
}
pub fn bool() -> Type {
Type::i8()
pub fn bool(ccx: &CrateContext) -> Type {
Type::i8(ccx)
}
pub fn char() -> Type {
Type::i32()
pub fn char(ccx: &CrateContext) -> Type {
Type::i32(ccx)
}
pub fn i8p() -> Type {
Type::i8().ptr_to()
pub fn i8p(ccx: &CrateContext) -> Type {
Type::i8(ccx).ptr_to()
}
pub fn int(arch: Architecture) -> Type {
match arch {
X86 | Arm | Mips => Type::i32(),
X86_64 => Type::i64()
pub fn int(ccx: &CrateContext) -> Type {
match ccx.tcx.sess.targ_cfg.arch {
X86 | Arm | Mips => Type::i32(ccx),
X86_64 => Type::i64(ccx)
}
}
pub fn float(_: Architecture) -> Type {
// All architectures currently just use doubles as the default
// float size
Type::f64()
}
pub fn int_from_ty(ctx: &CrateContext, t: ast::IntTy) -> Type {
pub fn int_from_ty(ccx: &CrateContext, t: ast::IntTy) -> Type {
match t {
ast::TyI => ctx.int_type,
ast::TyI8 => Type::i8(),
ast::TyI16 => Type::i16(),
ast::TyI32 => Type::i32(),
ast::TyI64 => Type::i64()
ast::TyI => ccx.int_type,
ast::TyI8 => Type::i8(ccx),
ast::TyI16 => Type::i16(ccx),
ast::TyI32 => Type::i32(ccx),
ast::TyI64 => Type::i64(ccx)
}
}
pub fn uint_from_ty(ctx: &CrateContext, t: ast::UintTy) -> Type {
pub fn uint_from_ty(ccx: &CrateContext, t: ast::UintTy) -> Type {
match t {
ast::TyU => ctx.int_type,
ast::TyU8 => Type::i8(),
ast::TyU16 => Type::i16(),
ast::TyU32 => Type::i32(),
ast::TyU64 => Type::i64()
ast::TyU => ccx.int_type,
ast::TyU8 => Type::i8(ccx),
ast::TyU16 => Type::i16(ccx),
ast::TyU32 => Type::i32(ccx),
ast::TyU64 => Type::i64(ccx)
}
}
pub fn float_from_ty(t: ast::FloatTy) -> Type {
pub fn float_from_ty(ccx: &CrateContext, t: ast::FloatTy) -> Type {
match t {
ast::TyF32 => Type::f32(),
ast::TyF64 => Type::f64()
ast::TyF32 => Type::f32(ccx),
ast::TyF64 => Type::f64(ccx)
}
}
pub fn size_t(arch: Architecture) -> Type {
Type::int(arch)
pub fn size_t(ccx: &CrateContext) -> Type {
Type::int(ccx)
}
pub fn func(args: &[Type], ret: &Type) -> Type {
@ -163,23 +156,23 @@ impl Type {
ty!(llvm::LLVMPointerType(ty.to_ref(), 0 as c_uint))
}
pub fn struct_(els: &[Type], packed: bool) -> Type {
pub fn struct_(ccx: &CrateContext, els: &[Type], packed: bool) -> Type {
let els : &[TypeRef] = unsafe { cast::transmute(els) };
ty!(llvm::LLVMStructTypeInContext(base::task_llcx(), els.as_ptr(),
els.len() as c_uint, packed as Bool))
ty!(llvm::LLVMStructTypeInContext(ccx.llcx, els.as_ptr(),
els.len() as c_uint,
packed as Bool))
}
pub fn named_struct(name: &str) -> Type {
let ctx = base::task_llcx();
ty!(name.with_c_str(|s| llvm::LLVMStructCreateNamed(ctx, s)))
pub fn named_struct(ccx: &CrateContext, name: &str) -> Type {
ty!(name.with_c_str(|s| llvm::LLVMStructCreateNamed(ccx.llcx, s)))
}
pub fn empty_struct() -> Type {
Type::struct_([], false)
pub fn empty_struct(ccx: &CrateContext) -> Type {
Type::struct_(ccx, [], false)
}
pub fn vtable() -> Type {
Type::array(&Type::i8p().ptr_to(), 1)
pub fn vtable(ccx: &CrateContext) -> Type {
Type::array(&Type::i8p(ccx).ptr_to(), 1)
}
pub fn generic_glue_fn(cx: &CrateContext) -> Type {
@ -188,21 +181,21 @@ impl Type {
None => ()
}
let ty = Type::glue_fn(Type::i8p());
let ty = Type::glue_fn(cx, Type::i8p(cx));
cx.tn.associate_type("glue_fn", &ty);
return ty;
ty
}
pub fn glue_fn(t: Type) -> Type {
Type::func([t], &Type::void())
pub fn glue_fn(ccx: &CrateContext, t: Type) -> Type {
Type::func([t], &Type::void(ccx))
}
pub fn tydesc(arch: Architecture) -> Type {
let mut tydesc = Type::named_struct("tydesc");
let glue_fn_ty = Type::glue_fn(Type::i8p()).ptr_to();
pub fn tydesc(ccx: &CrateContext) -> Type {
let mut tydesc = Type::named_struct(ccx, "tydesc");
let glue_fn_ty = Type::glue_fn(ccx, Type::i8p(ccx)).ptr_to();
let int_ty = Type::int(arch);
let int_ty = Type::int(ccx);
// Must mirror:
//
@ -212,10 +205,10 @@ impl Type {
int_ty, // align
glue_fn_ty, // drop
glue_fn_ty, // visit
Type::struct_([Type::i8p(), Type::int(arch)], false)]; // name
Type::struct_(ccx, [Type::i8p(ccx), Type::int(ccx)], false)]; // name
tydesc.set_struct_body(elems, false);
return tydesc;
tydesc
}
pub fn array(ty: &Type, len: u64) -> Type {
@ -226,27 +219,27 @@ impl Type {
ty!(llvm::LLVMVectorType(ty.to_ref(), len as c_uint))
}
pub fn vec(arch: Architecture, ty: &Type) -> Type {
Type::struct_(
[ Type::int(arch), Type::int(arch), Type::array(ty, 0) ],
pub fn vec(ccx: &CrateContext, ty: &Type) -> Type {
Type::struct_(ccx,
[Type::int(ccx), Type::int(ccx), Type::array(ty, 0)],
false)
}
pub fn opaque_vec(arch: Architecture) -> Type {
Type::vec(arch, &Type::i8())
pub fn opaque_vec(ccx: &CrateContext) -> Type {
Type::vec(ccx, &Type::i8(ccx))
}
// The box pointed to by @T.
pub fn at_box(ctx: &CrateContext, ty: Type) -> Type {
Type::struct_([
ctx.int_type, Type::glue_fn(Type::i8p()).ptr_to(),
Type::i8p(), Type::i8p(), ty
pub fn at_box(ccx: &CrateContext, ty: Type) -> Type {
Type::struct_(ccx, [
ccx.int_type, Type::glue_fn(ccx, Type::i8p(ccx)).ptr_to(),
Type::i8p(ccx), Type::i8p(ccx), ty
], false)
}
pub fn opaque_trait() -> Type {
let vtable = Type::glue_fn(Type::i8p()).ptr_to().ptr_to();
Type::struct_([vtable, Type::i8p()], false)
pub fn opaque_trait(ccx: &CrateContext) -> Type {
let vtable = Type::glue_fn(ccx, Type::i8p(ccx)).ptr_to().ptr_to();
Type::struct_(ccx, [vtable, Type::i8p(ccx)], false)
}
pub fn kind(&self) -> TypeKind {

View file

@ -54,7 +54,7 @@ pub fn type_of_rust_fn(cx: &CrateContext, has_env: bool,
// Arg 1: Environment
if has_env {
atys.push(Type::i8p());
atys.push(Type::i8p(cx));
}
// ... then explicit args.
@ -63,7 +63,7 @@ pub fn type_of_rust_fn(cx: &CrateContext, has_env: bool,
// Use the output as the actual return value if it's immediate.
if use_out_pointer || return_type_is_void(cx, output) {
Type::func(atys.as_slice(), &Type::void())
Type::func(atys.as_slice(), &Type::void(cx))
} else {
Type::func(atys.as_slice(), &lloutputtype)
}
@ -112,37 +112,36 @@ pub fn sizing_type_of(cx: &CrateContext, t: ty::t) -> Type {
}
let llsizingty = match ty::get(t).sty {
ty::ty_nil | ty::ty_bot => Type::nil(),
ty::ty_bool => Type::bool(),
ty::ty_char => Type::char(),
ty::ty_nil | ty::ty_bot => Type::nil(cx),
ty::ty_bool => Type::bool(cx),
ty::ty_char => Type::char(cx),
ty::ty_int(t) => Type::int_from_ty(cx, t),
ty::ty_uint(t) => Type::uint_from_ty(cx, t),
ty::ty_float(t) => Type::float_from_ty(t),
ty::ty_float(t) => Type::float_from_ty(cx, t),
ty::ty_str(ty::vstore_uniq) |
ty::ty_vec(_, ty::vstore_uniq) |
ty::ty_box(..) |
ty::ty_uniq(..) |
ty::ty_ptr(..) |
ty::ty_rptr(..) => Type::i8p(),
ty::ty_rptr(..) => Type::i8p(cx),
ty::ty_str(ty::vstore_slice(..)) |
ty::ty_vec(_, ty::vstore_slice(..)) => {
Type::struct_([Type::i8p(), Type::i8p()], false)
Type::struct_(cx, [Type::i8p(cx), Type::i8p(cx)], false)
}
ty::ty_bare_fn(..) => Type::i8p(),
ty::ty_closure(..) => Type::struct_([Type::i8p(), Type::i8p()], false),
ty::ty_trait(..) => Type::opaque_trait(),
ty::ty_bare_fn(..) => Type::i8p(cx),
ty::ty_closure(..) => Type::struct_(cx, [Type::i8p(cx), Type::i8p(cx)], false),
ty::ty_trait(..) => Type::opaque_trait(cx),
ty::ty_str(ty::vstore_fixed(size)) => Type::array(&Type::i8(), size as u64),
ty::ty_str(ty::vstore_fixed(size)) => Type::array(&Type::i8(cx), size as u64),
ty::ty_vec(mt, ty::vstore_fixed(size)) => {
Type::array(&sizing_type_of(cx, mt.ty), size as u64)
}
ty::ty_unboxed_vec(mt) => {
let sz_ty = sizing_type_of(cx, mt.ty);
Type::vec(cx.sess().targ_cfg.arch, &sz_ty)
Type::vec(cx, &sizing_type_of(cx, mt.ty))
}
ty::ty_tup(..) | ty::ty_enum(..) => {
@ -151,9 +150,9 @@ pub fn sizing_type_of(cx: &CrateContext, t: ty::t) -> Type {
}
ty::ty_struct(..) => {
if ty::type_is_simd(cx.tcx, t) {
let et = ty::simd_type(cx.tcx, t);
let n = ty::simd_size(cx.tcx, t);
if ty::type_is_simd(cx.tcx(), t) {
let et = ty::simd_type(cx.tcx(), t);
let n = ty::simd_size(cx.tcx(), t);
Type::vector(&type_of(cx, et), n as u64)
} else {
let repr = adt::represent_type(cx, t);
@ -183,21 +182,21 @@ pub fn type_of(cx: &CrateContext, t: ty::t) -> Type {
}
}
debug!("type_of {} {:?}", t.repr(cx.tcx), t);
debug!("type_of {} {:?}", t.repr(cx.tcx()), t);
// Replace any typedef'd types with their equivalent non-typedef
// type. This ensures that all LLVM nominal types that contain
// Rust types are defined as the same LLVM types. If we don't do
// this then, e.g. `Option<{myfield: bool}>` would be a different
// type than `Option<myrec>`.
let t_norm = ty::normalize_ty(cx.tcx, t);
let t_norm = ty::normalize_ty(cx.tcx(), t);
if t != t_norm {
let llty = type_of(cx, t_norm);
debug!("--> normalized {} {:?} to {} {:?} llty={}",
t.repr(cx.tcx),
t.repr(cx.tcx()),
t,
t_norm.repr(cx.tcx),
t_norm.repr(cx.tcx()),
t_norm,
cx.tn.type_to_str(llty));
let mut lltypes = cx.lltypes.borrow_mut();
@ -206,14 +205,14 @@ pub fn type_of(cx: &CrateContext, t: ty::t) -> Type {
}
let mut llty = match ty::get(t).sty {
ty::ty_nil | ty::ty_bot => Type::nil(),
ty::ty_bool => Type::bool(),
ty::ty_char => Type::char(),
ty::ty_nil | ty::ty_bot => Type::nil(cx),
ty::ty_bool => Type::bool(cx),
ty::ty_char => Type::char(cx),
ty::ty_int(t) => Type::int_from_ty(cx, t),
ty::ty_uint(t) => Type::uint_from_ty(cx, t),
ty::ty_float(t) => Type::float_from_ty(t),
ty::ty_float(t) => Type::float_from_ty(cx, t),
ty::ty_str(ty::vstore_uniq) => {
Type::vec(cx.sess().targ_cfg.arch, &Type::i8()).ptr_to()
Type::vec(cx, &Type::i8(cx)).ptr_to()
}
ty::ty_enum(did, ref substs) => {
// Only create the named struct, but don't fill it in. We
@ -231,12 +230,10 @@ pub fn type_of(cx: &CrateContext, t: ty::t) -> Type {
type_of(cx, typ).ptr_to()
}
ty::ty_vec(ref mt, ty::vstore_uniq) => {
let ty = type_of(cx, mt.ty);
Type::vec(cx.sess().targ_cfg.arch, &ty).ptr_to()
Type::vec(cx, &type_of(cx, mt.ty)).ptr_to()
}
ty::ty_unboxed_vec(ref mt) => {
let ty = type_of(cx, mt.ty);
Type::vec(cx.sess().targ_cfg.arch, &ty)
Type::vec(cx, &type_of(cx, mt.ty))
}
ty::ty_ptr(ref mt) => type_of(cx, mt.ty).ptr_to(),
ty::ty_rptr(_, ref mt) => type_of(cx, mt.ty).ptr_to(),
@ -244,7 +241,7 @@ pub fn type_of(cx: &CrateContext, t: ty::t) -> Type {
ty::ty_vec(ref mt, ty::vstore_slice(_)) => {
let p_ty = type_of(cx, mt.ty).ptr_to();
let u_ty = Type::uint_from_ty(cx, ast::TyU);
Type::struct_([p_ty, u_ty], false)
Type::struct_(cx, [p_ty, u_ty], false)
}
ty::ty_str(ty::vstore_slice(_)) => {
@ -253,7 +250,7 @@ pub fn type_of(cx: &CrateContext, t: ty::t) -> Type {
}
ty::ty_str(ty::vstore_fixed(n)) => {
Type::array(&Type::i8(), (n + 1u) as u64)
Type::array(&Type::i8(cx), (n + 1u) as u64)
}
ty::ty_vec(ref mt, ty::vstore_fixed(n)) => {
@ -265,17 +262,17 @@ pub fn type_of(cx: &CrateContext, t: ty::t) -> Type {
}
ty::ty_closure(_) => {
let fn_ty = type_of_fn_from_ty(cx, t).ptr_to();
Type::struct_([fn_ty, Type::i8p()], false)
Type::struct_(cx, [fn_ty, Type::i8p(cx)], false)
}
ty::ty_trait(..) => Type::opaque_trait(),
ty::ty_trait(..) => Type::opaque_trait(cx),
ty::ty_tup(..) => {
let repr = adt::represent_type(cx, t);
adt::type_of(cx, repr)
}
ty::ty_struct(did, ref substs) => {
if ty::type_is_simd(cx.tcx, t) {
let et = ty::simd_type(cx.tcx, t);
let n = ty::simd_size(cx.tcx, t);
if ty::type_is_simd(cx.tcx(), t) {
let et = ty::simd_type(cx.tcx(), t);
let n = ty::simd_size(cx.tcx(), t);
Type::vector(&type_of(cx, et), n as u64)
} else {
// Only create the named struct, but don't fill it in. We fill it
@ -296,7 +293,7 @@ pub fn type_of(cx: &CrateContext, t: ty::t) -> Type {
};
debug!("--> mapped t={} {:?} to llty={}",
t.repr(cx.tcx),
t.repr(cx.tcx()),
t,
cx.tn.type_to_str(llty));
{
@ -306,7 +303,7 @@ pub fn type_of(cx: &CrateContext, t: ty::t) -> Type {
// If this was an enum or struct, fill in the type now.
match ty::get(t).sty {
ty::ty_enum(..) | ty::ty_struct(..) if !ty::type_is_simd(cx.tcx, t) => {
ty::ty_enum(..) | ty::ty_struct(..) if !ty::type_is_simd(cx.tcx(), t) => {
let repr = adt::represent_type(cx, t);
adt::finish_type_of(cx, repr, &mut llty);
}
@ -327,7 +324,7 @@ pub fn llvm_type_name(cx: &CrateContext,
a_struct => { "struct" }
an_enum => { "enum" }
};
let tstr = ppaux::parameterized(cx.tcx, ty::item_path_str(cx.tcx, did),
let tstr = ppaux::parameterized(cx.tcx(), ty::item_path_str(cx.tcx(), did),
&ty::NonerasedRegions(opt_vec::Empty),
tps, did, false);
if did.krate == 0 {
@ -339,5 +336,5 @@ pub fn llvm_type_name(cx: &CrateContext,
pub fn type_of_dtor(ccx: &CrateContext, self_ty: ty::t) -> Type {
let self_ty = type_of(ccx, self_ty).ptr_to();
Type::func([self_ty], &Type::void())
Type::func([self_ty], &Type::void(ccx))
}