Remove @-fields from CrateContext

Remove all the explicit @mut-fields from CrateContext, though many
fields are still @-ptrs.
This required changing every single function call that explicitly
took a @CrateContext, so I took advantage and changed as many as I
could get away with to &-ptrs or &mut ptrs.
This commit is contained in:
James Miller 2013-06-13 19:19:50 +12:00 committed by James Miller
parent 01e098aa05
commit cc908b772c
26 changed files with 611 additions and 512 deletions

View File

@ -622,11 +622,11 @@ pub fn symbol_hash(tcx: ty::ctxt,
hash.to_managed()
}
pub fn get_symbol_hash(ccx: @CrateContext, t: ty::t) -> @str {
pub fn get_symbol_hash(ccx: &mut CrateContext, t: ty::t) -> @str {
match ccx.type_hashcodes.find(&t) {
Some(&h) => h,
None => {
let hash = symbol_hash(ccx.tcx, ccx.symbol_hasher, t, ccx.link_meta);
let hash = symbol_hash(ccx.tcx, &mut ccx.symbol_hasher, t, ccx.link_meta);
ccx.type_hashcodes.insert(t, hash);
hash
}
@ -705,7 +705,7 @@ pub fn exported_name(sess: Session,
path_name(sess.ident_of(vers))));
}
pub fn mangle_exported_name(ccx: @CrateContext,
pub fn mangle_exported_name(ccx: &mut CrateContext,
path: path,
t: ty::t) -> ~str {
let hash = get_symbol_hash(ccx, t);
@ -714,7 +714,7 @@ pub fn mangle_exported_name(ccx: @CrateContext,
ccx.link_meta.vers);
}
pub fn mangle_internal_name_by_type_only(ccx: @CrateContext,
pub fn mangle_internal_name_by_type_only(ccx: &mut CrateContext,
t: ty::t,
name: &str) -> ~str {
let s = ppaux::ty_to_short_str(ccx.tcx, t);
@ -725,7 +725,7 @@ pub fn mangle_internal_name_by_type_only(ccx: @CrateContext,
path_name(ccx.sess.ident_of(hash))]);
}
pub fn mangle_internal_name_by_type_and_seq(ccx: @CrateContext,
pub fn mangle_internal_name_by_type_and_seq(ccx: &mut CrateContext,
t: ty::t,
name: &str) -> ~str {
let s = ppaux::ty_to_str(ccx.tcx, t);
@ -736,18 +736,18 @@ pub fn mangle_internal_name_by_type_and_seq(ccx: @CrateContext,
path_name((ccx.names)(name))]);
}
pub fn mangle_internal_name_by_path_and_seq(ccx: @CrateContext,
pub fn mangle_internal_name_by_path_and_seq(ccx: &mut CrateContext,
path: path,
flav: &str) -> ~str {
return mangle(ccx.sess,
vec::append_one(path, path_name((ccx.names)(flav))));
}
pub fn mangle_internal_name_by_path(ccx: @CrateContext, path: path) -> ~str {
pub fn mangle_internal_name_by_path(ccx: &mut CrateContext, path: path) -> ~str {
return mangle(ccx.sess, path);
}
pub fn mangle_internal_name_by_seq(ccx: @CrateContext, flav: &str) -> ~str {
pub fn mangle_internal_name_by_seq(ccx: &mut CrateContext, flav: &str) -> ~str {
return fmt!("%s_%u", flav, (ccx.names)(flav).name);
}

View File

@ -47,24 +47,26 @@ use syntax::parse::token;
use syntax;
use writer = extra::ebml::writer;
use core::cast;
// used by astencode:
type abbrev_map = @mut HashMap<ty::t, tyencode::ty_abbrev>;
pub type encode_inlined_item = @fn(ecx: @EncodeContext,
pub type encode_inlined_item<'self> = &'self fn(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
path: &[ast_map::path_elt],
ii: ast::inlined_item);
pub struct EncodeParams {
pub struct EncodeParams<'self> {
diag: @span_handler,
tcx: ty::ctxt,
reachable: reachable::map,
reexports2: middle::resolve::ExportMap2,
item_symbols: @mut HashMap<ast::node_id, ~str>,
discrim_symbols: @mut HashMap<ast::node_id, @str>,
link_meta: LinkMeta,
item_symbols: &'self HashMap<ast::node_id, ~str>,
discrim_symbols: &'self HashMap<ast::node_id, @str>,
link_meta: &'self LinkMeta,
cstore: @mut cstore::CStore,
encode_inlined_item: encode_inlined_item
encode_inlined_item: encode_inlined_item<'self>
}
struct Stats {
@ -81,31 +83,31 @@ struct Stats {
n_inlines: uint
}
pub struct EncodeContext {
pub struct EncodeContext<'self> {
diag: @span_handler,
tcx: ty::ctxt,
stats: @mut Stats,
reachable: reachable::map,
reexports2: middle::resolve::ExportMap2,
item_symbols: @mut HashMap<ast::node_id, ~str>,
discrim_symbols: @mut HashMap<ast::node_id, @str>,
link_meta: LinkMeta,
cstore: @mut cstore::CStore,
encode_inlined_item: encode_inlined_item,
item_symbols: &'self HashMap<ast::node_id, ~str>,
discrim_symbols: &'self HashMap<ast::node_id, @str>,
link_meta: &'self LinkMeta,
cstore: &'self cstore::CStore,
encode_inlined_item: encode_inlined_item<'self>,
type_abbrevs: abbrev_map
}
pub fn reachable(ecx: @EncodeContext, id: node_id) -> bool {
pub fn reachable(ecx: &EncodeContext, id: node_id) -> bool {
ecx.reachable.contains(&id)
}
fn encode_name(ecx: @EncodeContext,
fn encode_name(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
name: ident) {
ebml_w.wr_tagged_str(tag_paths_data_name, ecx.tcx.sess.str_of(name));
}
fn encode_impl_type_basename(ecx: @EncodeContext,
fn encode_impl_type_basename(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
name: ident) {
ebml_w.wr_tagged_str(tag_item_impl_type_basename,
@ -116,7 +118,7 @@ pub fn encode_def_id(ebml_w: &mut writer::Encoder, id: def_id) {
ebml_w.wr_tagged_str(tag_def_id, def_to_str(id));
}
fn encode_region_param(ecx: @EncodeContext,
fn encode_region_param(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
it: @ast::item) {
let opt_rp = ecx.tcx.region_paramd_items.find(&it.id);
@ -147,14 +149,15 @@ fn add_to_index(ebml_w: &mut writer::Encoder,
}
fn encode_trait_ref(ebml_w: &mut writer::Encoder,
ecx: @EncodeContext,
ecx: &EncodeContext,
trait_ref: &ty::TraitRef,
tag: uint) {
let r = ecx.reachable;
let ty_str_ctxt = @tyencode::ctxt {
diag: ecx.diag,
ds: def_to_str,
tcx: ecx.tcx,
reachable: |a| reachable(ecx, a),
reachable: |a| r.contains(&a),
abbrevs: tyencode::ac_use_abbrevs(ecx.type_abbrevs)};
ebml_w.start_tag(tag);
@ -174,14 +177,15 @@ pub fn def_to_str(did: def_id) -> ~str {
}
fn encode_ty_type_param_defs(ebml_w: &mut writer::Encoder,
ecx: @EncodeContext,
ecx: &EncodeContext,
params: @~[ty::TypeParameterDef],
tag: uint) {
let r = ecx.reachable;
let ty_str_ctxt = @tyencode::ctxt {
diag: ecx.diag,
ds: def_to_str,
tcx: ecx.tcx,
reachable: |a| reachable(ecx, a),
reachable: |a| r.contains(&a),
abbrevs: tyencode::ac_use_abbrevs(ecx.type_abbrevs)};
for params.each |param| {
ebml_w.start_tag(tag);
@ -191,7 +195,7 @@ fn encode_ty_type_param_defs(ebml_w: &mut writer::Encoder,
}
fn encode_type_param_bounds(ebml_w: &mut writer::Encoder,
ecx: @EncodeContext,
ecx: &EncodeContext,
params: &OptVec<TyParam>) {
let ty_param_defs =
@params.map_to_vec(|param| ecx.tcx.ty_param_defs.get_copy(&param.id));
@ -206,31 +210,33 @@ fn encode_variant_id(ebml_w: &mut writer::Encoder, vid: def_id) {
ebml_w.end_tag();
}
pub fn write_type(ecx: @EncodeContext,
pub fn write_type(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
typ: ty::t) {
let r = ecx.reachable;
let ty_str_ctxt = @tyencode::ctxt {
diag: ecx.diag,
ds: def_to_str,
tcx: ecx.tcx,
reachable: |a| reachable(ecx, a),
reachable: |a| r.contains(&a),
abbrevs: tyencode::ac_use_abbrevs(ecx.type_abbrevs)};
tyencode::enc_ty(ebml_w.writer, ty_str_ctxt, typ);
}
pub fn write_vstore(ecx: @EncodeContext,
pub fn write_vstore(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
vstore: ty::vstore) {
let r = ecx.reachable;
let ty_str_ctxt = @tyencode::ctxt {
diag: ecx.diag,
ds: def_to_str,
tcx: ecx.tcx,
reachable: |a| reachable(ecx, a),
reachable: |a| r.contains(&a),
abbrevs: tyencode::ac_use_abbrevs(ecx.type_abbrevs)};
tyencode::enc_vstore(ebml_w.writer, ty_str_ctxt, vstore);
}
fn encode_type(ecx: @EncodeContext,
fn encode_type(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
typ: ty::t) {
ebml_w.start_tag(tag_items_data_item_type);
@ -238,7 +244,7 @@ fn encode_type(ecx: @EncodeContext,
ebml_w.end_tag();
}
fn encode_transformed_self_ty(ecx: @EncodeContext,
fn encode_transformed_self_ty(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
opt_typ: Option<ty::t>) {
for opt_typ.iter().advance |&typ| {
@ -248,23 +254,24 @@ fn encode_transformed_self_ty(ecx: @EncodeContext,
}
}
fn encode_method_fty(ecx: @EncodeContext,
fn encode_method_fty(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
typ: &ty::BareFnTy) {
ebml_w.start_tag(tag_item_method_fty);
let r = ecx.reachable;
let ty_str_ctxt = @tyencode::ctxt {
diag: ecx.diag,
ds: def_to_str,
tcx: ecx.tcx,
reachable: |a| reachable(ecx, a),
reachable: |a| r.contains(&a),
abbrevs: tyencode::ac_use_abbrevs(ecx.type_abbrevs)};
tyencode::enc_bare_fn_ty(ebml_w.writer, ty_str_ctxt, typ);
ebml_w.end_tag();
}
fn encode_symbol(ecx: @EncodeContext,
fn encode_symbol(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
id: node_id) {
ebml_w.start_tag(tag_items_data_item_symbol);
@ -281,7 +288,7 @@ fn encode_symbol(ecx: @EncodeContext,
ebml_w.end_tag();
}
fn encode_discriminant(ecx: @EncodeContext,
fn encode_discriminant(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
id: node_id) {
ebml_w.start_tag(tag_items_data_item_symbol);
@ -289,7 +296,7 @@ fn encode_discriminant(ecx: @EncodeContext,
ebml_w.end_tag();
}
fn encode_disr_val(_: @EncodeContext,
fn encode_disr_val(_: &EncodeContext,
ebml_w: &mut writer::Encoder,
disr_val: int) {
ebml_w.start_tag(tag_disr_val);
@ -305,7 +312,7 @@ fn encode_parent_item(ebml_w: &mut writer::Encoder, id: def_id) {
ebml_w.end_tag();
}
fn encode_enum_variant_info(ecx: @EncodeContext,
fn encode_enum_variant_info(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
id: node_id,
variants: &[variant],
@ -349,11 +356,11 @@ fn encode_enum_variant_info(ecx: @EncodeContext,
}
}
fn encode_path(ecx: @EncodeContext,
fn encode_path(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
path: &[ast_map::path_elt],
name: ast_map::path_elt) {
fn encode_path_elt(ecx: @EncodeContext,
fn encode_path_elt(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
elt: ast_map::path_elt) {
let (tag, name) = match elt {
@ -373,7 +380,7 @@ fn encode_path(ecx: @EncodeContext,
ebml_w.end_tag();
}
fn encode_reexported_static_method(ecx: @EncodeContext,
fn encode_reexported_static_method(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
exp: &middle::resolve::Export2,
method_def_id: def_id,
@ -390,7 +397,7 @@ fn encode_reexported_static_method(ecx: @EncodeContext,
ebml_w.end_tag();
}
fn encode_reexported_static_base_methods(ecx: @EncodeContext,
fn encode_reexported_static_base_methods(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
exp: &middle::resolve::Export2)
-> bool {
@ -411,7 +418,7 @@ fn encode_reexported_static_base_methods(ecx: @EncodeContext,
}
}
fn encode_reexported_static_trait_methods(ecx: @EncodeContext,
fn encode_reexported_static_trait_methods(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
exp: &middle::resolve::Export2)
-> bool {
@ -430,7 +437,7 @@ fn encode_reexported_static_trait_methods(ecx: @EncodeContext,
}
}
fn encode_reexported_static_methods(ecx: @EncodeContext,
fn encode_reexported_static_methods(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
mod_path: &[ast_map::path_elt],
exp: &middle::resolve::Export2) {
@ -466,7 +473,7 @@ fn encode_reexported_static_methods(ecx: @EncodeContext,
}
}
fn encode_info_for_mod(ecx: @EncodeContext,
fn encode_info_for_mod(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
md: &_mod,
id: node_id,
@ -598,7 +605,7 @@ fn encode_method_sort(ebml_w: &mut writer::Encoder, sort: char) {
}
/* Returns an index of items in this class */
fn encode_info_for_struct(ecx: @EncodeContext,
fn encode_info_for_struct(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
path: &[ast_map::path_elt],
fields: &[@struct_field],
@ -633,7 +640,7 @@ fn encode_info_for_struct(ecx: @EncodeContext,
}
// This is for encoding info for ctors and dtors
fn encode_info_for_ctor(ecx: @EncodeContext,
fn encode_info_for_ctor(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
id: node_id,
ident: ident,
@ -662,7 +669,7 @@ fn encode_info_for_ctor(ecx: @EncodeContext,
ebml_w.end_tag();
}
fn encode_info_for_struct_ctor(ecx: @EncodeContext,
fn encode_info_for_struct_ctor(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
path: &[ast_map::path_elt],
name: ast::ident,
@ -684,7 +691,7 @@ fn encode_info_for_struct_ctor(ecx: @EncodeContext,
ebml_w.end_tag();
}
fn encode_method_ty_fields(ecx: @EncodeContext,
fn encode_method_ty_fields(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
method_ty: &ty::Method) {
encode_def_id(ebml_w, method_ty.def_id);
@ -698,7 +705,7 @@ fn encode_method_ty_fields(ecx: @EncodeContext,
encode_explicit_self(ebml_w, method_ty.explicit_self);
}
fn encode_info_for_method(ecx: @EncodeContext,
fn encode_info_for_method(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
impl_path: &[ast_map::path_elt],
should_inline: bool,
@ -769,7 +776,7 @@ fn should_inline(attrs: &[attribute]) -> bool {
}
}
fn encode_info_for_item(ecx: @EncodeContext,
fn encode_info_for_item(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
item: @item,
index: @mut ~[entry<int>],
@ -1075,7 +1082,7 @@ fn encode_info_for_item(ecx: @EncodeContext,
}
}
fn encode_info_for_foreign_item(ecx: @EncodeContext,
fn encode_info_for_foreign_item(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
nitem: @foreign_item,
index: @mut ~[entry<int>],
@ -1109,7 +1116,7 @@ fn encode_info_for_foreign_item(ecx: @EncodeContext,
ebml_w.end_tag();
}
fn encode_info_for_items(ecx: @EncodeContext,
fn encode_info_for_items(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
crate: &crate)
-> ~[entry<int>] {
@ -1119,15 +1126,22 @@ fn encode_info_for_items(ecx: @EncodeContext,
encode_info_for_mod(ecx, ebml_w, &crate.node.module,
crate_node_id, [],
syntax::parse::token::special_idents::invalid);
let items = ecx.tcx.items;
// See comment in `encode_side_tables_for_ii` in astencode
let ecx_ptr : *() = unsafe { cast::transmute(ecx) };
visit::visit_crate(crate, ((), visit::mk_vt(@visit::Visitor {
visit_expr: |_e, (_cx, _v)| { },
visit_item: {
let ebml_w = copy *ebml_w;
|i, (cx, v)| {
visit::visit_item(i, (cx, v));
match ecx.tcx.items.get_copy(&i.id) {
match items.get_copy(&i.id) {
ast_map::node_item(_, pt) => {
let mut ebml_w = copy ebml_w;
// See above
let ecx : &EncodeContext = unsafe { cast::transmute(ecx_ptr) };
encode_info_for_item(ecx, &mut ebml_w, i, index, *pt);
}
_ => fail!("bad item")
@ -1138,9 +1152,11 @@ fn encode_info_for_items(ecx: @EncodeContext,
let ebml_w = copy *ebml_w;
|ni, (cx, v)| {
visit::visit_foreign_item(ni, (cx, v));
match ecx.tcx.items.get_copy(&ni.id) {
match items.get_copy(&ni.id) {
ast_map::node_foreign_item(_, abi, _, pt) => {
let mut ebml_w = copy ebml_w;
// See above
let ecx : &EncodeContext = unsafe { cast::transmute(ecx_ptr) };
encode_info_for_foreign_item(ecx,
&mut ebml_w,
ni,
@ -1267,10 +1283,10 @@ fn encode_attributes(ebml_w: &mut writer::Encoder, attrs: &[attribute]) {
// metadata that Rust cares about for linking crates. This attribute requires
// 'name' and 'vers' items, so if the user didn't provide them we will throw
// them in anyway with default values.
fn synthesize_crate_attrs(ecx: @EncodeContext,
fn synthesize_crate_attrs(ecx: &EncodeContext,
crate: &crate) -> ~[attribute] {
fn synthesize_link_attr(ecx: @EncodeContext, items: ~[@meta_item]) ->
fn synthesize_link_attr(ecx: &EncodeContext, items: ~[@meta_item]) ->
attribute {
assert!(!ecx.link_meta.name.is_empty());
@ -1317,10 +1333,10 @@ fn synthesize_crate_attrs(ecx: @EncodeContext,
return attrs;
}
fn encode_crate_deps(ecx: @EncodeContext,
fn encode_crate_deps(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
cstore: @mut cstore::CStore) {
fn get_ordered_deps(ecx: @EncodeContext, cstore: @mut cstore::CStore)
cstore: &cstore::CStore) {
fn get_ordered_deps(ecx: &EncodeContext, cstore: &cstore::CStore)
-> ~[decoder::crate_dep] {
type numdep = decoder::crate_dep;
@ -1359,7 +1375,7 @@ fn encode_crate_deps(ecx: @EncodeContext,
ebml_w.end_tag();
}
fn encode_lang_items(ecx: @EncodeContext, ebml_w: &mut writer::Encoder) {
fn encode_lang_items(ecx: &EncodeContext, ebml_w: &mut writer::Encoder) {
ebml_w.start_tag(tag_lang_items);
for ecx.tcx.lang_items.each_item |def_id, i| {
@ -1383,7 +1399,7 @@ fn encode_lang_items(ecx: @EncodeContext, ebml_w: &mut writer::Encoder) {
ebml_w.end_tag(); // tag_lang_items
}
fn encode_link_args(ecx: @EncodeContext, ebml_w: &mut writer::Encoder) {
fn encode_link_args(ecx: &EncodeContext, ebml_w: &mut writer::Encoder) {
ebml_w.start_tag(tag_link_args);
let link_args = cstore::get_used_link_args(ecx.cstore);
@ -1396,7 +1412,7 @@ fn encode_link_args(ecx: @EncodeContext, ebml_w: &mut writer::Encoder) {
ebml_w.end_tag();
}
fn encode_crate_dep(ecx: @EncodeContext,
fn encode_crate_dep(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
dep: decoder::crate_dep) {
ebml_w.start_tag(tag_crate_dep);
@ -1444,10 +1460,12 @@ pub fn encode_metadata(parms: EncodeParams, crate: &crate) -> ~[u8] {
let EncodeParams{item_symbols, diag, tcx, reachable, reexports2,
discrim_symbols, cstore, encode_inlined_item,
link_meta, _} = parms;
let ecx = @EncodeContext {
let type_abbrevs = @mut HashMap::new();
let stats = @mut stats;
let ecx = EncodeContext {
diag: diag,
tcx: tcx,
stats: @mut stats,
stats: stats,
reachable: reachable,
reexports2: reexports2,
item_symbols: item_symbols,
@ -1455,7 +1473,7 @@ pub fn encode_metadata(parms: EncodeParams, crate: &crate) -> ~[u8] {
link_meta: link_meta,
cstore: cstore,
encode_inlined_item: encode_inlined_item,
type_abbrevs: @mut HashMap::new()
type_abbrevs: type_abbrevs
};
let mut ebml_w = writer::Encoder(wr as @io::Writer);
@ -1463,28 +1481,28 @@ pub fn encode_metadata(parms: EncodeParams, crate: &crate) -> ~[u8] {
encode_hash(&mut ebml_w, ecx.link_meta.extras_hash);
let mut i = *wr.pos;
let crate_attrs = synthesize_crate_attrs(ecx, crate);
let crate_attrs = synthesize_crate_attrs(&ecx, crate);
encode_attributes(&mut ebml_w, crate_attrs);
ecx.stats.attr_bytes = *wr.pos - i;
i = *wr.pos;
encode_crate_deps(ecx, &mut ebml_w, ecx.cstore);
encode_crate_deps(&ecx, &mut ebml_w, ecx.cstore);
ecx.stats.dep_bytes = *wr.pos - i;
// Encode the language items.
i = *wr.pos;
encode_lang_items(ecx, &mut ebml_w);
encode_lang_items(&ecx, &mut ebml_w);
ecx.stats.lang_item_bytes = *wr.pos - i;
// Encode the link args.
i = *wr.pos;
encode_link_args(ecx, &mut ebml_w);
encode_link_args(&ecx, &mut ebml_w);
ecx.stats.link_args_bytes = *wr.pos - i;
// Encode and index the items.
ebml_w.start_tag(tag_items);
i = *wr.pos;
let items_index = encode_info_for_items(ecx, &mut ebml_w, crate);
let items_index = encode_info_for_items(&ecx, &mut ebml_w, crate);
ecx.stats.item_bytes = *wr.pos - i;
i = *wr.pos;

View File

@ -44,6 +44,8 @@ use syntax::parse::token;
use syntax;
use writer = extra::ebml::writer;
use core::cast;
#[cfg(test)] use syntax::parse;
#[cfg(test)] use syntax::print::pprust;
@ -80,7 +82,7 @@ trait tr_intern {
// ______________________________________________________________________
// Top-level methods.
pub fn encode_inlined_item(ecx: @e::EncodeContext,
pub fn encode_inlined_item(ecx: &e::EncodeContext,
ebml_w: &mut writer::Encoder,
path: &[ast_map::path_elt],
ii: ast::inlined_item,
@ -527,7 +529,7 @@ trait read_method_map_entry_helper {
-> method_map_entry;
}
fn encode_method_map_entry(ecx: @e::EncodeContext,
fn encode_method_map_entry(ecx: &e::EncodeContext,
ebml_w: &mut writer::Encoder,
mme: method_map_entry) {
do ebml_w.emit_struct("method_map_entry", 3) |ebml_w| {
@ -604,7 +606,7 @@ impl tr for method_origin {
// ______________________________________________________________________
// Encoding and decoding vtable_res
fn encode_vtable_res(ecx: @e::EncodeContext,
fn encode_vtable_res(ecx: &e::EncodeContext,
ebml_w: &mut writer::Encoder,
dr: typeck::vtable_res) {
// can't autogenerate this code because automatic code of
@ -616,7 +618,7 @@ fn encode_vtable_res(ecx: @e::EncodeContext,
}
}
fn encode_vtable_origin(ecx: @e::EncodeContext,
fn encode_vtable_origin(ecx: &e::EncodeContext,
ebml_w: &mut writer::Encoder,
vtable_origin: &typeck::vtable_origin) {
do ebml_w.emit_enum("vtable_origin") |ebml_w| {
@ -702,53 +704,53 @@ impl vtable_decoder_helpers for reader::Decoder {
// Encoding and decoding the side tables
trait get_ty_str_ctxt {
fn ty_str_ctxt(@self) -> @tyencode::ctxt;
fn ty_str_ctxt(&self) -> @tyencode::ctxt;
}
impl get_ty_str_ctxt for e::EncodeContext {
// IMPLICIT SELF WARNING: fix this!
fn ty_str_ctxt(@self) -> @tyencode::ctxt {
impl<'self> get_ty_str_ctxt for e::EncodeContext<'self> {
fn ty_str_ctxt(&self) -> @tyencode::ctxt {
let r = self.reachable;
@tyencode::ctxt {diag: self.tcx.sess.diagnostic(),
ds: e::def_to_str,
tcx: self.tcx,
reachable: |a| encoder::reachable(self, a),
reachable: |a| r.contains(&a),
abbrevs: tyencode::ac_use_abbrevs(self.type_abbrevs)}
}
}
trait ebml_writer_helpers {
fn emit_ty(&mut self, ecx: @e::EncodeContext, ty: ty::t);
fn emit_vstore(&mut self, ecx: @e::EncodeContext, vstore: ty::vstore);
fn emit_tys(&mut self, ecx: @e::EncodeContext, tys: &[ty::t]);
fn emit_ty(&mut self, ecx: &e::EncodeContext, ty: ty::t);
fn emit_vstore(&mut self, ecx: &e::EncodeContext, vstore: ty::vstore);
fn emit_tys(&mut self, ecx: &e::EncodeContext, tys: &[ty::t]);
fn emit_type_param_def(&mut self,
ecx: @e::EncodeContext,
ecx: &e::EncodeContext,
type_param_def: &ty::TypeParameterDef);
fn emit_tpbt(&mut self,
ecx: @e::EncodeContext,
ecx: &e::EncodeContext,
tpbt: ty::ty_param_bounds_and_ty);
}
impl ebml_writer_helpers for writer::Encoder {
fn emit_ty(&mut self, ecx: @e::EncodeContext, ty: ty::t) {
fn emit_ty(&mut self, ecx: &e::EncodeContext, ty: ty::t) {
do self.emit_opaque |this| {
e::write_type(ecx, this, ty)
}
}
fn emit_vstore(&mut self, ecx: @e::EncodeContext, vstore: ty::vstore) {
fn emit_vstore(&mut self, ecx: &e::EncodeContext, vstore: ty::vstore) {
do self.emit_opaque |this| {
e::write_vstore(ecx, this, vstore)
}
}
fn emit_tys(&mut self, ecx: @e::EncodeContext, tys: &[ty::t]) {
fn emit_tys(&mut self, ecx: &e::EncodeContext, tys: &[ty::t]) {
do self.emit_from_vec(tys) |this, ty| {
this.emit_ty(ecx, *ty)
}
}
fn emit_type_param_def(&mut self,
ecx: @e::EncodeContext,
ecx: &e::EncodeContext,
type_param_def: &ty::TypeParameterDef) {
do self.emit_opaque |this| {
tyencode::enc_type_param_def(this.writer,
@ -758,7 +760,7 @@ impl ebml_writer_helpers for writer::Encoder {
}
fn emit_tpbt(&mut self,
ecx: @e::EncodeContext,
ecx: &e::EncodeContext,
tpbt: ty::ty_param_bounds_and_ty) {
do self.emit_struct("ty_param_bounds_and_ty", 2) |this| {
do this.emit_struct_field("generics", 0) |this| {
@ -800,12 +802,18 @@ impl write_tag_and_id for writer::Encoder {
}
}
fn encode_side_tables_for_ii(ecx: @e::EncodeContext,
fn encode_side_tables_for_ii(ecx: &e::EncodeContext,
maps: Maps,
ebml_w: &mut writer::Encoder,
ii: &ast::inlined_item) {
ebml_w.start_tag(c::tag_table as uint);
let new_ebml_w = copy *ebml_w;
// Because the ast visitor uses @fn, I can't pass in
// ecx directly, but /I/ know that it'll be fine since
// the lifetime is tied to the CrateContext that
// lives this entire section.
let ecx_ptr : *() = unsafe { cast::transmute(ecx) };
ast_util::visit_ids_for_inlined_item(
ii,
|id: ast::node_id| {
@ -813,12 +821,14 @@ fn encode_side_tables_for_ii(ecx: @e::EncodeContext,
// it is mutable. But I believe it's harmless since we generate
// balanced EBML.
let mut new_ebml_w = copy new_ebml_w;
// See above
let ecx : &e::EncodeContext = unsafe { cast::transmute(ecx_ptr) };
encode_side_tables_for_id(ecx, maps, &mut new_ebml_w, id)
});
ebml_w.end_tag();
}
fn encode_side_tables_for_id(ecx: @e::EncodeContext,
fn encode_side_tables_for_id(ecx: &e::EncodeContext,
maps: Maps,
ebml_w: &mut writer::Encoder,
id: ast::node_id) {

View File

@ -1314,7 +1314,7 @@ pub fn compile_submatch(bcx: block,
let vals_left = vec::append(vec::slice(vals, 0u, col).to_vec(),
vec::slice(vals, col + 1u, vals.len()));
let ccx = *bcx.fcx.ccx;
let ccx = bcx.fcx.ccx;
let mut pat_id = 0;
let mut pat_span = dummy_sp();
for m.each |br| {
@ -1755,7 +1755,7 @@ pub fn bind_irrefutable_pat(bcx: block,
binding_mode: IrrefutablePatternBindingMode)
-> block {
let _icx = bcx.insn_ctxt("match::bind_irrefutable_pat");
let ccx = *bcx.fcx.ccx;
let ccx = bcx.fcx.ccx;
let mut bcx = bcx;
// Necessary since bind_irrefutable_pat is called outside trans_match

View File

@ -111,7 +111,7 @@ pub fn represent_node(bcx: block, node: ast::node_id) -> @Repr {
}
/// Decides how to represent a given type.
pub fn represent_type(cx: @CrateContext, t: ty::t) -> @Repr {
pub fn represent_type(cx: &mut CrateContext, t: ty::t) -> @Repr {
debug!("Representing: %s", ty_to_str(cx.tcx, t));
match cx.adt_reprs.find(&t) {
Some(repr) => return *repr,
@ -123,7 +123,7 @@ pub fn represent_type(cx: @CrateContext, t: ty::t) -> @Repr {
return repr;
}
fn represent_type_uncached(cx: @CrateContext, t: ty::t) -> Repr {
fn represent_type_uncached(cx: &mut CrateContext, t: ty::t) -> Repr {
match ty::get(t).sty {
ty::ty_tup(ref elems) => {
return Univariant(mk_struct(cx, *elems, false), false)
@ -142,7 +142,7 @@ fn represent_type_uncached(cx: @CrateContext, t: ty::t) -> Repr {
ty::ty_enum(def_id, ref substs) => {
struct Case { discr: int, tys: ~[ty::t] };
impl Case {
fn is_zerolen(&self, cx: @CrateContext) -> bool {
fn is_zerolen(&self, cx: &mut CrateContext) -> bool {
mk_struct(cx, self.tys, false).size == 0
}
fn find_ptr(&self) -> Option<uint> {
@ -211,7 +211,7 @@ fn represent_type_uncached(cx: @CrateContext, t: ty::t) -> Repr {
}
}
fn mk_struct(cx: @CrateContext, tys: &[ty::t], packed: bool) -> Struct {
fn mk_struct(cx: &mut CrateContext, tys: &[ty::t], packed: bool) -> Struct {
let lltys = tys.map(|&ty| type_of::sizing_type_of(cx, ty));
let llty_rec = T_struct(lltys, packed);
Struct {
@ -227,14 +227,14 @@ fn mk_struct(cx: @CrateContext, tys: &[ty::t], packed: bool) -> Struct {
* All nominal types are LLVM structs, in order to be able to use
* forward-declared opaque types to prevent circularity in `type_of`.
*/
pub fn fields_of(cx: @CrateContext, r: &Repr) -> ~[TypeRef] {
pub fn fields_of(cx: &mut CrateContext, r: &Repr) -> ~[TypeRef] {
generic_fields_of(cx, r, false)
}
/// Like `fields_of`, but for `type_of::sizing_type_of` (q.v.).
pub fn sizing_fields_of(cx: @CrateContext, r: &Repr) -> ~[TypeRef] {
pub fn sizing_fields_of(cx: &mut CrateContext, r: &Repr) -> ~[TypeRef] {
generic_fields_of(cx, r, true)
}
fn generic_fields_of(cx: @CrateContext, r: &Repr, sizing: bool)
fn generic_fields_of(cx: &mut CrateContext, r: &Repr, sizing: bool)
-> ~[TypeRef] {
match *r {
CEnum(*) => ~[T_enum_discrim(cx)],
@ -268,7 +268,7 @@ fn generic_fields_of(cx: @CrateContext, r: &Repr, sizing: bool)
}
}
fn struct_llfields(cx: @CrateContext, st: &Struct, sizing: bool)
fn struct_llfields(cx: &mut CrateContext, st: &Struct, sizing: bool)
-> ~[TypeRef] {
if sizing {
st.fields.map(|&ty| type_of::sizing_type_of(cx, ty))
@ -454,9 +454,10 @@ fn struct_field_ptr(bcx: block, st: &Struct, val: ValueRef, ix: uint,
let ccx = bcx.ccx();
let val = if needs_cast {
let real_llty = T_struct(st.fields.map(
|&ty| type_of::type_of(ccx, ty)),
st.packed);
let fields = do st.fields.map |&ty| {
type_of::type_of(ccx, ty)
};
let real_llty = T_struct(fields, st.packed);
PointerCast(bcx, val, T_ptr(real_llty))
} else {
val
@ -494,7 +495,7 @@ pub fn trans_drop_flag_ptr(bcx: block, r: &Repr, val: ValueRef) -> ValueRef {
* this could be changed in the future to avoid allocating unnecessary
* space after values of shorter-than-maximum cases.
*/
pub fn trans_const(ccx: @CrateContext, r: &Repr, discr: int,
pub fn trans_const(ccx: &mut CrateContext, r: &Repr, discr: int,
vals: &[ValueRef]) -> ValueRef {
match *r {
CEnum(min, max) => {
@ -509,8 +510,9 @@ pub fn trans_const(ccx: @CrateContext, r: &Repr, discr: int,
General(ref cases) => {
let case = &cases[discr as uint];
let max_sz = cases.map(|s| s.size).max();
let discr_ty = C_int(ccx, discr);
let contents = build_const_struct(ccx, case,
~[C_int(ccx, discr)] + vals);
~[discr_ty] + vals);
C_struct(contents + [padding(max_sz - case.size)])
}
NullablePointer{ nonnull: ref nonnull, nndiscr, ptrfield, _ } => {
@ -538,7 +540,7 @@ pub fn trans_const(ccx: @CrateContext, r: &Repr, discr: int,
* a two-element struct will locate it at offset 4, and accesses to it
* will read the wrong memory.
*/
fn build_const_struct(ccx: @CrateContext, st: &Struct, vals: &[ValueRef])
fn build_const_struct(ccx: &mut CrateContext, st: &Struct, vals: &[ValueRef])
-> ~[ValueRef] {
assert_eq!(vals.len(), st.fields.len());
@ -579,7 +581,7 @@ fn padding(size: u64) -> ValueRef {
fn roundup(x: u64, a: u64) -> u64 { ((x + (a - 1)) / a) * a }
/// Get the discriminant of a constant value. (Not currently used.)
pub fn const_get_discrim(ccx: @CrateContext, r: &Repr, val: ValueRef)
pub fn const_get_discrim(ccx: &mut CrateContext, r: &Repr, val: ValueRef)
-> int {
match *r {
CEnum(*) => const_to_int(val) as int,
@ -598,7 +600,7 @@ pub fn const_get_discrim(ccx: @CrateContext, r: &Repr, val: ValueRef)
* (Not to be confused with `common::const_get_elt`, which operates on
* raw LLVM-level structs and arrays.)
*/
pub fn const_get_field(ccx: @CrateContext, r: &Repr, val: ValueRef,
pub fn const_get_field(ccx: &mut CrateContext, r: &Repr, val: ValueRef,
_discr: int, ix: uint) -> ValueRef {
match *r {
CEnum(*) => ccx.sess.bug("element access in C-like enum const"),
@ -609,7 +611,7 @@ pub fn const_get_field(ccx: @CrateContext, r: &Repr, val: ValueRef,
}
/// Extract field of struct-like const, skipping our alignment padding.
fn const_struct_field(ccx: @CrateContext, val: ValueRef, ix: uint)
fn const_struct_field(ccx: &mut CrateContext, val: ValueRef, ix: uint)
-> ValueRef {
// Get the ix-th non-undef element of the struct.
let mut real_ix = 0; // actual position in the struct

View File

@ -88,7 +88,7 @@ use syntax::abi::{X86, X86_64, Arm, Mips};
pub use middle::trans::context::task_llcx;
pub struct icx_popper {
ccx: @CrateContext,
ccx: @mut CrateContext,
}
#[unsafe_destructor]
@ -100,7 +100,7 @@ impl Drop for icx_popper {
}
}
pub fn icx_popper(ccx: @CrateContext) -> icx_popper {
pub fn icx_popper(ccx: @mut CrateContext) -> icx_popper {
icx_popper {
ccx: ccx
}
@ -110,7 +110,7 @@ pub trait get_insn_ctxt {
fn insn_ctxt(&self, s: &str) -> icx_popper;
}
impl get_insn_ctxt for @CrateContext {
impl get_insn_ctxt for @mut CrateContext {
fn insn_ctxt(&self, s: &str) -> icx_popper {
debug!("new insn_ctxt: %s", s);
if self.sess.count_llvm_insns() {
@ -139,7 +139,7 @@ fn fcx_has_nonzero_span(fcx: fn_ctxt) -> bool {
}
}
pub fn log_fn_time(ccx: @CrateContext, name: ~str, start: time::Timespec,
pub fn log_fn_time(ccx: @mut CrateContext, name: ~str, start: time::Timespec,
end: time::Timespec) {
let elapsed = 1000 * ((end.sec - start.sec) as int) +
((end.nsec as int) - (start.nsec as int)) / 1000000;
@ -175,7 +175,7 @@ pub fn decl_internal_cdecl_fn(llmod: ModuleRef, name: ~str, llty: TypeRef) ->
return llfn;
}
pub fn get_extern_fn(externs: ExternMap,
pub fn get_extern_fn(externs: &mut ExternMap,
llmod: ModuleRef,
name: @str,
cc: lib::llvm::CallConv,
@ -189,7 +189,7 @@ pub fn get_extern_fn(externs: ExternMap,
return f;
}
pub fn get_extern_const(externs: ExternMap, llmod: ModuleRef,
pub fn get_extern_const(externs: &mut ExternMap, llmod: ModuleRef,
name: @str, ty: TypeRef) -> ValueRef {
match externs.find(&name) {
Some(n) => return copy *n,
@ -204,11 +204,11 @@ pub fn get_extern_const(externs: ExternMap, llmod: ModuleRef,
}
}
fn get_simple_extern_fn(cx: block,
externs: ExternMap,
llmod: ModuleRef,
name: @str,
n_args: int) -> ValueRef {
fn get_simple_extern_fn(cx: block,
externs: &mut ExternMap,
llmod: ModuleRef,
name: @str,
n_args: int) -> ValueRef {
let _icx = cx.insn_ctxt("get_simple_extern_fn");
let ccx = cx.fcx.ccx;
let inputs = vec::from_elem(n_args as uint, ccx.int_type);
@ -217,7 +217,7 @@ pub fn get_extern_const(externs: ExternMap, llmod: ModuleRef,
return get_extern_fn(externs, llmod, name, lib::llvm::CCallConv, t);
}
pub fn trans_foreign_call(cx: block, externs: ExternMap,
pub fn trans_foreign_call(cx: block, externs: &mut ExternMap,
llmod: ModuleRef, name: @str, args: &[ValueRef]) ->
ValueRef {
let _icx = cx.insn_ctxt("trans_foreign_call");
@ -269,7 +269,9 @@ pub fn opaque_box_body(bcx: block,
boxptr: ValueRef) -> ValueRef {
let _icx = bcx.insn_ctxt("opaque_box_body");
let ccx = bcx.ccx();
let boxptr = PointerCast(bcx, boxptr, T_ptr(T_box(ccx, type_of(ccx, body_t))));
let ty = type_of(ccx, body_t);
let ty = T_box(ccx, ty);
let boxptr = PointerCast(bcx, boxptr, T_ptr(ty));
GEPi(bcx, boxptr, [0u, abi::box_field_body])
}
@ -335,7 +337,9 @@ pub fn non_gc_box_cast(bcx: block, val: ValueRef) -> ValueRef {
// enough space for a box of that type. This includes a rust_opaque_box
// header.
pub fn malloc_raw(bcx: block, t: ty::t, heap: heap) -> Result {
malloc_raw_dyn(bcx, t, heap, llsize_of(bcx.ccx(), type_of(bcx.ccx(), t)))
let ty = type_of(bcx.ccx(), t);
let size = llsize_of(bcx.ccx(), ty);
malloc_raw_dyn(bcx, t, heap, size)
}
pub struct MallocResult {
@ -358,8 +362,8 @@ pub fn malloc_general_dyn(bcx: block, t: ty::t, heap: heap, size: ValueRef)
pub fn malloc_general(bcx: block, t: ty::t, heap: heap)
-> MallocResult {
malloc_general_dyn(bcx, t, heap,
llsize_of(bcx.ccx(), type_of(bcx.ccx(), t)))
let ty = type_of(bcx.ccx(), t);
malloc_general_dyn(bcx, t, heap, llsize_of(bcx.ccx(), ty))
}
pub fn malloc_boxed(bcx: block, t: ty::t)
-> MallocResult {
@ -381,7 +385,8 @@ pub fn maybe_set_managed_unique_rc(bcx: block, bx: ValueRef, heap: heap) {
// such as a ~(@foo) or such. These need to have their refcount forced
// to -2 so the annihilator ignores them.
let rc = GEPi(bcx, bx, [0u, abi::box_field_refcnt]);
Store(bcx, C_int(bcx.ccx(), -2), rc);
let rc_val = C_int(bcx.ccx(), -2);
Store(bcx, rc_val, rc);
}
}
@ -392,11 +397,11 @@ pub fn malloc_unique(bcx: block, t: ty::t)
// Type descriptor and type glue stuff
pub fn get_tydesc_simple(ccx: @CrateContext, t: ty::t) -> ValueRef {
pub fn get_tydesc_simple(ccx: &mut CrateContext, t: ty::t) -> ValueRef {
get_tydesc(ccx, t).tydesc
}
pub fn get_tydesc(ccx: @CrateContext, t: ty::t) -> @mut tydesc_info {
pub fn get_tydesc(ccx: &mut CrateContext, t: ty::t) -> @mut tydesc_info {
match ccx.tydescs.find(&t) {
Some(&inf) => {
return inf;
@ -485,7 +490,7 @@ pub fn set_glue_inlining(f: ValueRef, t: ty::t) {
// Double-check that we never ask LLVM to declare the same symbol twice. It
// silently mangles such symbols, breaking our linkage model.
pub fn note_unique_llvm_symbol(ccx: @CrateContext, sym: @str) {
pub fn note_unique_llvm_symbol(ccx: &mut CrateContext, sym: @str) {
if ccx.all_llvm_symbols.contains(&sym) {
ccx.sess.bug(~"duplicate LLVM symbol: " + sym);
}
@ -493,7 +498,7 @@ pub fn note_unique_llvm_symbol(ccx: @CrateContext, sym: @str) {
}
pub fn get_res_dtor(ccx: @CrateContext,
pub fn get_res_dtor(ccx: @mut CrateContext,
did: ast::def_id,
parent_id: ast::def_id,
substs: &[ty::t])
@ -527,7 +532,7 @@ pub fn get_res_dtor(ccx: @CrateContext,
ty::lookup_item_type(tcx, parent_id).ty);
let llty = type_of_dtor(ccx, class_ty);
let name = name.to_managed(); // :-(
get_extern_fn(ccx.externs,
get_extern_fn(&mut ccx.externs,
ccx.llmod,
name,
lib::llvm::CCallConv,
@ -536,7 +541,7 @@ pub fn get_res_dtor(ccx: @CrateContext,
}
// Structural comparison: a rather involved form of glue.
pub fn maybe_name_value(cx: @CrateContext, v: ValueRef, s: &str) {
pub fn maybe_name_value(cx: &CrateContext, v: ValueRef, s: &str) {
if cx.sess.opts.save_temps {
let _: () = str::as_c_str(s, |buf| {
unsafe {
@ -818,18 +823,18 @@ pub fn null_env_ptr(bcx: block) -> ValueRef {
C_null(T_opaque_box_ptr(bcx.ccx()))
}
pub fn trans_external_path(ccx: @CrateContext, did: ast::def_id, t: ty::t)
pub fn trans_external_path(ccx: &mut CrateContext, did: ast::def_id, t: ty::t)
-> ValueRef {
let name = csearch::get_symbol(ccx.sess.cstore, did).to_managed(); // Sad
match ty::get(t).sty {
ty::ty_bare_fn(_) | ty::ty_closure(_) => {
let llty = type_of_fn_from_ty(ccx, t);
return get_extern_fn(ccx.externs, ccx.llmod, name,
return get_extern_fn(&mut ccx.externs, ccx.llmod, name,
lib::llvm::CCallConv, llty);
}
_ => {
let llty = type_of(ccx, t);
return get_extern_const(ccx.externs, ccx.llmod, name, llty);
return get_extern_const(&mut ccx.externs, ccx.llmod, name, llty);
}
};
}
@ -1166,7 +1171,7 @@ pub fn trans_stmt(cx: block, s: &ast::stmt) -> block {
debuginfo::create_local_var(bcx, *local);
}
}
ast::decl_item(i) => trans_item(*cx.fcx.ccx, i)
ast::decl_item(i) => trans_item(cx.fcx.ccx, i)
}
}
ast::stmt_mac(*) => cx.tcx().sess.bug("unexpanded macro")
@ -1456,7 +1461,7 @@ pub fn call_memcpy(cx: block, dst: ValueRef, src: ValueRef, n_bytes: ValueRef, a
X86 | Arm | Mips => "llvm.memcpy.p0i8.p0i8.i32",
X86_64 => "llvm.memcpy.p0i8.p0i8.i64"
};
let memcpy = *ccx.intrinsics.get(&key);
let memcpy = ccx.intrinsics.get_copy(&key);
let src_ptr = PointerCast(cx, src, T_ptr(T_i8()));
let dst_ptr = PointerCast(cx, dst, T_ptr(T_i8()));
let size = IntCast(cx, n_bytes, ccx.int_type);
@ -1500,7 +1505,7 @@ pub fn memzero(cx: block, llptr: ValueRef, llty: TypeRef) {
X86_64 => "llvm.memset.p0i8.i64"
};
let llintrinsicfn = *ccx.intrinsics.get(&intrinsic_key);
let llintrinsicfn = ccx.intrinsics.get_copy(&intrinsic_key);
let llptr = PointerCast(cx, llptr, T_ptr(T_i8()));
let llzeroval = C_u8(0);
let size = IntCast(cx, machine::llsize_of(ccx, llty), ccx.int_type);
@ -1572,7 +1577,7 @@ pub fn make_return_pointer(fcx: fn_ctxt, output_type: ty::t) -> ValueRef {
if !ty::type_is_immediate(output_type) {
llvm::LLVMGetParam(fcx.llfn, 0)
} else {
let lloutputtype = type_of::type_of(*fcx.ccx, output_type);
let lloutputtype = type_of::type_of(fcx.ccx, output_type);
alloca(raw_block(fcx, false, fcx.llstaticallocas), lloutputtype)
}
}
@ -1584,7 +1589,7 @@ pub fn make_return_pointer(fcx: fn_ctxt, output_type: ty::t) -> ValueRef {
// - create_llargs_for_fn_args.
// - new_fn_ctxt
// - trans_args
pub fn new_fn_ctxt_w_id(ccx: @CrateContext,
pub fn new_fn_ctxt_w_id(ccx: @mut CrateContext,
path: path,
llfndecl: ValueRef,
id: ast::node_id,
@ -1632,7 +1637,7 @@ pub fn new_fn_ctxt_w_id(ccx: @CrateContext,
param_substs: param_substs,
span: sp,
path: path,
ccx: @ccx
ccx: ccx
};
fcx.llenv = unsafe {
llvm::LLVMGetParam(llfndecl, fcx.env_arg_pos() as c_uint)
@ -1641,7 +1646,7 @@ pub fn new_fn_ctxt_w_id(ccx: @CrateContext,
fcx
}
pub fn new_fn_ctxt(ccx: @CrateContext,
pub fn new_fn_ctxt(ccx: @mut CrateContext,
path: path,
llfndecl: ValueRef,
output_type: ty::t,
@ -1817,7 +1822,7 @@ pub enum self_arg { impl_self(ty::t), impl_owned_self(ty::t), no_self, }
// trans_closure: Builds an LLVM function out of a source function.
// If the function closes over its environment a closure will be
// returned.
pub fn trans_closure(ccx: @CrateContext,
pub fn trans_closure(ccx: @mut CrateContext,
path: path,
decl: &ast::fn_decl,
body: &ast::blk,
@ -1861,7 +1866,7 @@ pub fn trans_closure(ccx: @CrateContext,
llvm::LLVMSetGC(fcx.llfn, strategy);
}
}
*ccx.uses_gc = true;
ccx.uses_gc = true;
}
// Create the first basic block in the function and keep a handle on it to
@ -1898,7 +1903,7 @@ pub fn trans_closure(ccx: @CrateContext,
// trans_fn: creates an LLVM function corresponding to a source language
// function.
pub fn trans_fn(ccx: @CrateContext,
pub fn trans_fn(ccx: @mut CrateContext,
path: path,
decl: &ast::fn_decl,
body: &ast::blk,
@ -1942,7 +1947,7 @@ pub fn trans_fn(ccx: @CrateContext,
}
}
pub fn trans_enum_variant(ccx: @CrateContext,
pub fn trans_enum_variant(ccx: @mut CrateContext,
enum_id: ast::node_id,
variant: &ast::variant,
args: &[ast::variant_arg],
@ -2018,7 +2023,7 @@ pub fn trans_enum_variant(ccx: @CrateContext,
// NB: In theory this should be merged with the function above. But the AST
// structures are completely different, so very little code would be shared.
pub fn trans_tuple_struct(ccx: @CrateContext,
pub fn trans_tuple_struct(ccx: @mut CrateContext,
fields: &[@ast::struct_field],
ctor_id: ast::node_id,
param_substs: Option<@param_substs>,
@ -2085,7 +2090,7 @@ pub fn trans_tuple_struct(ccx: @CrateContext,
finish_fn(fcx, lltop);
}
pub fn trans_enum_def(ccx: @CrateContext, enum_definition: &ast::enum_def,
pub fn trans_enum_def(ccx: @mut CrateContext, enum_definition: &ast::enum_def,
id: ast::node_id, vi: @~[ty::VariantInfo],
i: &mut uint) {
for enum_definition.variants.each |variant| {
@ -2108,7 +2113,7 @@ pub fn trans_enum_def(ccx: @CrateContext, enum_definition: &ast::enum_def,
}
}
pub fn trans_item(ccx: @CrateContext, item: &ast::item) {
pub fn trans_item(ccx: @mut CrateContext, item: &ast::item) {
let _icx = ccx.insn_ctxt("trans_item");
let path = match ccx.tcx.items.get_copy(&item.id) {
ast_map::node_item(_, p) => p,
@ -2196,7 +2201,7 @@ pub fn trans_item(ccx: @CrateContext, item: &ast::item) {
}
}
pub fn trans_struct_def(ccx: @CrateContext, struct_def: @ast::struct_def) {
pub fn trans_struct_def(ccx: @mut CrateContext, struct_def: @ast::struct_def) {
// If this is a tuple-like struct, translate the constructor.
match struct_def.ctor_id {
// We only need to translate a constructor if there are fields;
@ -2215,14 +2220,14 @@ pub fn trans_struct_def(ccx: @CrateContext, struct_def: @ast::struct_def) {
// separate modules in the compiled program. That's because modules exist
// only as a convenience for humans working with the code, to organize names
// and control visibility.
pub fn trans_mod(ccx: @CrateContext, m: &ast::_mod) {
pub fn trans_mod(ccx: @mut CrateContext, m: &ast::_mod) {
let _icx = ccx.insn_ctxt("trans_mod");
for m.items.each |item| {
trans_item(ccx, *item);
}
}
pub fn register_fn(ccx: @CrateContext,
pub fn register_fn(ccx: @mut CrateContext,
sp: span,
path: path,
node_id: ast::node_id,
@ -2232,7 +2237,7 @@ pub fn register_fn(ccx: @CrateContext,
register_fn_full(ccx, sp, path, node_id, attrs, t)
}
pub fn register_fn_full(ccx: @CrateContext,
pub fn register_fn_full(ccx: @mut CrateContext,
sp: span,
path: path,
node_id: ast::node_id,
@ -2244,7 +2249,7 @@ pub fn register_fn_full(ccx: @CrateContext,
lib::llvm::CCallConv, llfty)
}
pub fn register_fn_fuller(ccx: @CrateContext,
pub fn register_fn_fuller(ccx: @mut CrateContext,
sp: span,
path: path,
node_id: ast::node_id,
@ -2286,7 +2291,7 @@ pub fn is_entry_fn(sess: &Session, node_id: ast::node_id) -> bool {
// Create a _rust_main(args: ~[str]) function which will be called from the
// runtime rust_start function
pub fn create_entry_wrapper(ccx: @CrateContext,
pub fn create_entry_wrapper(ccx: @mut CrateContext,
_sp: span, main_llfn: ValueRef) {
let et = ccx.sess.entry_type.unwrap();
if et == session::EntryMain {
@ -2296,7 +2301,7 @@ pub fn create_entry_wrapper(ccx: @CrateContext,
create_entry_fn(ccx, main_llfn, false);
}
fn create_main(ccx: @CrateContext, main_llfn: ValueRef) -> ValueRef {
fn create_main(ccx: @mut CrateContext, main_llfn: ValueRef) -> ValueRef {
let nt = ty::mk_nil();
let llfty = type_of_fn(ccx, [], nt);
@ -2326,7 +2331,7 @@ pub fn create_entry_wrapper(ccx: @CrateContext,
return llfdecl;
}
fn create_entry_fn(ccx: @CrateContext,
fn create_entry_fn(ccx: @mut CrateContext,
rust_main: ValueRef,
use_start_lang_item: bool) {
let llfty = T_fn([ccx.int_type, T_ptr(T_ptr(T_i8()))], ccx.int_type);
@ -2420,7 +2425,7 @@ pub fn fill_fn_pair(bcx: block, pair: ValueRef, llfn: ValueRef,
Store(bcx, llenvblobptr, env_cell);
}
pub fn item_path(ccx: @CrateContext, i: @ast::item) -> path {
pub fn item_path(ccx: &CrateContext, i: @ast::item) -> path {
let base = match ccx.tcx.items.get_copy(&i.id) {
ast_map::node_item(_, p) => p,
// separate map for paths?
@ -2429,20 +2434,21 @@ pub fn item_path(ccx: @CrateContext, i: @ast::item) -> path {
vec::append(/*bad*/copy *base, [path_name(i.ident)])
}
pub fn get_item_val(ccx: @CrateContext, id: ast::node_id) -> ValueRef {
pub fn get_item_val(ccx: @mut CrateContext, id: ast::node_id) -> ValueRef {
debug!("get_item_val(id=`%?`)", id);
let tcx = ccx.tcx;
match ccx.item_vals.find(&id) {
Some(&v) => v,
let val = ccx.item_vals.find_copy(&id);
match val {
Some(v) => v,
None => {
let mut exprt = false;
let val = match tcx.items.get_copy(&id) {
let item = ccx.tcx.items.get_copy(&id);
let val = match item {
ast_map::node_item(i, pth) => {
let my_path = vec::append(/*bad*/copy *pth,
[path_name(i.ident)]);
match i.node {
ast::item_const(_, expr) => {
let typ = ty::node_id_to_type(tcx, i.id);
let typ = ty::node_id_to_type(ccx.tcx, i.id);
let s = mangle_exported_name(ccx, my_path, typ);
// We need the translated value here, because for enums the
// LLVM type is not fully determined by the Rust type.
@ -2501,13 +2507,12 @@ pub fn get_item_val(ccx: @CrateContext, id: ast::node_id) -> ValueRef {
ni.attrs)
}
ast::foreign_item_const(*) => {
let typ = ty::node_id_to_type(tcx, ni.id);
let typ = ty::node_id_to_type(ccx.tcx, ni.id);
let ident = token::ident_to_str(&ni.ident);
let g = do str::as_c_str(ident) |buf| {
unsafe {
llvm::LLVMAddGlobal(ccx.llmod,
type_of(ccx, typ),
buf)
let ty = type_of(ccx, typ);
llvm::LLVMAddGlobal(ccx.llmod, ty, buf)
}
};
g
@ -2542,7 +2547,7 @@ pub fn get_item_val(ccx: @CrateContext, id: ast::node_id) -> ValueRef {
// Only register the constructor if this is a tuple-like struct.
match struct_def.ctor_id {
None => {
tcx.sess.bug("attempt to register a constructor of \
ccx.tcx.sess.bug("attempt to register a constructor of \
a non-tuple-like struct")
}
Some(ctor_id) => {
@ -2571,7 +2576,7 @@ pub fn get_item_val(ccx: @CrateContext, id: ast::node_id) -> ValueRef {
}
}
pub fn register_method(ccx: @CrateContext,
pub fn register_method(ccx: @mut CrateContext,
id: ast::node_id,
pth: @ast_map::path,
m: @ast::method) -> ValueRef {
@ -2584,7 +2589,7 @@ pub fn register_method(ccx: @CrateContext,
}
// The constant translation pass.
pub fn trans_constant(ccx: @CrateContext, it: @ast::item) {
pub fn trans_constant(ccx: @mut CrateContext, it: @ast::item) {
let _icx = ccx.insn_ctxt("trans_constant");
match it.node {
ast::item_enum(ref enum_definition, _) => {
@ -2620,7 +2625,7 @@ pub fn trans_constant(ccx: @CrateContext, it: @ast::item) {
}
}
pub fn trans_constants(ccx: @CrateContext, crate: &ast::crate) {
pub fn trans_constants(ccx: @mut CrateContext, crate: &ast::crate) {
visit::visit_crate(
crate, ((),
visit::mk_simple_visitor(@visit::SimpleVisitor {
@ -2634,7 +2639,7 @@ pub fn vp2i(cx: block, v: ValueRef) -> ValueRef {
return PtrToInt(cx, v, ccx.int_type);
}
pub fn p2i(ccx: @CrateContext, v: ValueRef) -> ValueRef {
pub fn p2i(ccx: &CrateContext, v: ValueRef) -> ValueRef {
unsafe {
return llvm::LLVMConstPtrToInt(v, ccx.int_type);
}
@ -2853,8 +2858,8 @@ pub fn trap(bcx: block) {
}
}
pub fn decl_gc_metadata(ccx: @CrateContext, llmod_id: &str) {
if !ccx.sess.opts.gc || !*ccx.uses_gc {
pub fn decl_gc_metadata(ccx: &mut CrateContext, llmod_id: &str) {
if !ccx.sess.opts.gc || !ccx.uses_gc {
return;
}
@ -2871,7 +2876,7 @@ pub fn decl_gc_metadata(ccx: @CrateContext, llmod_id: &str) {
}
}
pub fn create_module_map(ccx: @CrateContext) -> ValueRef {
pub fn create_module_map(ccx: &mut CrateContext) -> ValueRef {
let elttype = T_struct([ccx.int_type, ccx.int_type], false);
let maptype = T_array(elttype, ccx.module_data.len() + 1);
let map = str::as_c_str("_rust_mod_map", |buf| {
@ -2881,9 +2886,21 @@ pub fn create_module_map(ccx: @CrateContext) -> ValueRef {
});
lib::llvm::SetLinkage(map, lib::llvm::InternalLinkage);
let mut elts: ~[ValueRef] = ~[];
for ccx.module_data.each |key, &val| {
let elt = C_struct([p2i(ccx, C_cstr(ccx, /* bad */key.to_managed())),
p2i(ccx, val)]);
// This is not ideal, but the borrow checker doesn't
// like the multiple borrows. At least, it doesn't
// like them on the current snapshot. (2013-06-14)
let mut keys = ~[];
for ccx.module_data.each_key |k| {
keys.push(k.to_managed());
}
for keys.each |key| {
let val = *ccx.module_data.find_equiv(key).get();
let s_const = C_cstr(ccx, *key);
let s_ptr = p2i(ccx, s_const);
let v_ptr = p2i(ccx, val);
let elt = C_struct([s_ptr, v_ptr]);
elts.push(elt);
}
let term = C_struct([C_int(ccx, 0), C_int(ccx, 0)]);
@ -2919,7 +2936,7 @@ pub fn decl_crate_map(sess: session::Session, mapmeta: LinkMeta,
return map;
}
pub fn fill_crate_map(ccx: @CrateContext, map: ValueRef) {
pub fn fill_crate_map(ccx: @mut CrateContext, map: ValueRef) {
let mut subcrates: ~[ValueRef] = ~[];
let mut i = 1;
let cstore = ccx.sess.cstore;
@ -2952,37 +2969,44 @@ pub fn fill_crate_map(ccx: @CrateContext, map: ValueRef) {
}
unsafe {
let mod_map = create_module_map(ccx);
llvm::LLVMSetInitializer(map, C_struct(
[C_i32(1),
lib::llvm::llvm::LLVMConstPointerCast(llannihilatefn,
T_ptr(T_i8())),
p2i(ccx, create_module_map(ccx)),
p2i(ccx, mod_map),
C_array(ccx.int_type, subcrates)]));
}
}
pub fn crate_ctxt_to_encode_parms(cx: @CrateContext)
-> encoder::EncodeParams {
pub fn crate_ctxt_to_encode_parms<'r>(cx: &'r CrateContext, ie: encoder::encode_inlined_item<'r>)
-> encoder::EncodeParams<'r> {
let diag = cx.sess.diagnostic();
let item_symbols = &cx.item_symbols;
let discrim_symbols = &cx.discrim_symbols;
let link_meta = &cx.link_meta;
encoder::EncodeParams {
diag: diag,
tcx: cx.tcx,
reachable: cx.reachable,
reexports2: cx.exp_map2,
item_symbols: item_symbols,
discrim_symbols: discrim_symbols,
link_meta: link_meta,
cstore: cx.sess.cstore,
encode_inlined_item: ie
}
}
pub fn write_metadata(cx: &mut CrateContext, crate: &ast::crate) {
if !*cx.sess.building_library { return; }
let encode_inlined_item: encoder::encode_inlined_item =
|ecx, ebml_w, path, ii|
astencode::encode_inlined_item(ecx, ebml_w, path, ii, cx.maps);
encoder::EncodeParams {
diag: cx.sess.diagnostic(),
tcx: cx.tcx,
reachable: cx.reachable,
reexports2: cx.exp_map2,
item_symbols: cx.item_symbols,
discrim_symbols: cx.discrim_symbols,
link_meta: /*bad*/copy cx.link_meta,
cstore: cx.sess.cstore,
encode_inlined_item: encode_inlined_item
}
}
pub fn write_metadata(cx: @CrateContext, crate: &ast::crate) {
if !*cx.sess.building_library { return; }
let encode_parms = crate_ctxt_to_encode_parms(cx);
let encode_parms = crate_ctxt_to_encode_parms(cx, encode_inlined_item);
let llmeta = C_bytes(encoder::encode_metadata(encode_parms, crate));
let llconst = C_struct([llmeta]);
let mut llglobal = str::as_c_str("rust_metadata", |buf| {
@ -3008,7 +3032,7 @@ pub fn write_metadata(cx: @CrateContext, crate: &ast::crate) {
}
// Writes the current ABI version into the crate.
pub fn write_abi_version(ccx: @CrateContext) {
pub fn write_abi_version(ccx: &mut CrateContext) {
mk_global(ccx, ~"rust_abi_version", C_uint(ccx, abi::abi_version),
false);
}
@ -3020,8 +3044,8 @@ pub fn trans_crate(sess: session::Session,
emap2: resolve::ExportMap2,
maps: astencode::Maps) -> (ContextRef, ModuleRef, LinkMeta) {
let symbol_hasher = @mut hash::default_state();
let link_meta = link::build_link_meta(sess, crate, output, symbol_hasher);
let mut symbol_hasher = hash::default_state();
let link_meta = link::build_link_meta(sess, crate, output, &mut symbol_hasher);
let reachable = reachable::find_reachable(
&crate.node.module,
emap2,
@ -3038,7 +3062,14 @@ pub fn trans_crate(sess: session::Session,
// such as a function name in the module.
// 1. http://llvm.org/bugs/show_bug.cgi?id=11479
let llmod_id = link_meta.name.to_owned() + ".rc";
let ccx = @CrateContext::new(sess, llmod_id, tcx, emap2, maps,
// FIXME(#6511): get LLVM building with --enable-threads so this
// function can be called
// if !llvm::LLVMRustStartMultithreading() {
// sess.bug("couldn't enable multi-threaded LLVM");
// }
let ccx = @mut CrateContext::new(sess, llmod_id, tcx, emap2, maps,
symbol_hasher, link_meta, reachable);
// FIXME(#6511): get LLVM building with --enable-threads so this
// function can be called

View File

@ -46,8 +46,8 @@ pub fn B(cx: block) -> BuilderRef {
pub fn count_insn(cx: block, category: &str) {
if cx.ccx().sess.count_llvm_insns() {
let h = cx.ccx().stats.llvm_insns;
let v = &*cx.ccx().stats.llvm_insn_ctxt;
let h = &mut cx.ccx().stats.llvm_insns;
let v : &[~str] = cx.ccx().stats.llvm_insn_ctxt;
// Build version of path with cycles removed.
@ -547,7 +547,7 @@ pub fn AtomicLoad(cx: block, PointerVal: ValueRef, order: AtomicOrdering) -> Val
return llvm::LLVMGetUndef(ccx.int_type);
}
count_insn(cx, "load.atomic");
let align = llalign_of_min(*ccx, ccx.int_type);
let align = llalign_of_min(ccx, ccx.int_type);
return llvm::LLVMBuildAtomicLoad(B(cx), PointerVal, noname(), order, align as c_uint);
}
}

View File

@ -18,7 +18,7 @@ use super::common::*;
use super::machine::*;
struct X86_ABIInfo {
ccx: @CrateContext
ccx: @mut CrateContext
}
impl ABIInfo for X86_ABIInfo {
@ -71,7 +71,7 @@ impl ABIInfo for X86_ABIInfo {
}
}
pub fn abi_info(ccx: @CrateContext) -> @ABIInfo {
pub fn abi_info(ccx: @mut CrateContext) -> @ABIInfo {
return @X86_ABIInfo {
ccx: ccx
} as @ABIInfo;

View File

@ -129,7 +129,7 @@ impl EnvAction {
}
impl EnvValue {
pub fn to_str(&self, ccx: @CrateContext) -> ~str {
pub fn to_str(&self, ccx: &CrateContext) -> ~str {
fmt!("%s(%s)", self.action.to_str(), self.datum.to_str(ccx))
}
}

View File

@ -124,9 +124,9 @@ pub struct Stats {
n_monos: uint,
n_inlines: uint,
n_closures: uint,
llvm_insn_ctxt: @mut ~[~str],
llvm_insns: @mut HashMap<~str, uint>,
fn_times: @mut ~[(~str, int)] // (ident, time)
llvm_insn_ctxt: ~[~str],
llvm_insns: HashMap<~str, uint>,
fn_times: ~[(~str, int)] // (ident, time)
}
pub struct BuilderRef_res {
@ -147,7 +147,7 @@ pub fn BuilderRef_res(B: BuilderRef) -> BuilderRef_res {
}
}
pub type ExternMap = @mut HashMap<@str, ValueRef>;
pub type ExternMap = HashMap<@str, ValueRef>;
// Types used for llself.
pub struct ValSelfData {
@ -266,7 +266,7 @@ pub struct fn_ctxt_ {
path: path,
// This function's enclosing crate context.
ccx: @@CrateContext
ccx: @mut CrateContext
}
impl fn_ctxt_ {
@ -295,9 +295,9 @@ impl fn_ctxt_ {
pub type fn_ctxt = @mut fn_ctxt_;
pub fn warn_not_to_commit(ccx: @CrateContext, msg: &str) {
if !*ccx.do_not_commit_warning_issued {
*ccx.do_not_commit_warning_issued = true;
pub fn warn_not_to_commit(ccx: &mut CrateContext, msg: &str) {
if !ccx.do_not_commit_warning_issued {
ccx.do_not_commit_warning_issued = true;
ccx.sess.warn(msg.to_str() + " -- do not commit like this!");
}
}
@ -659,7 +659,7 @@ pub fn block_parent(cx: block) -> block {
// Accessors
impl block_ {
pub fn ccx(@mut self) -> @CrateContext { *self.fcx.ccx }
pub fn ccx(@mut self) -> @mut CrateContext { self.fcx.ccx }
pub fn tcx(@mut self) -> ty::ctxt { self.fcx.ccx.tcx }
pub fn sess(@mut self) -> Session { self.fcx.ccx.sess }
@ -754,7 +754,7 @@ pub fn T_f64() -> TypeRef {
pub fn T_bool() -> TypeRef { return T_i8(); }
pub fn T_int(targ_cfg: @session::config) -> TypeRef {
pub fn T_int(targ_cfg: &session::config) -> TypeRef {
return match targ_cfg.arch {
X86 => T_i32(),
X86_64 => T_i64(),
@ -763,7 +763,7 @@ pub fn T_int(targ_cfg: @session::config) -> TypeRef {
};
}
pub fn T_int_ty(cx: @CrateContext, t: ast::int_ty) -> TypeRef {
pub fn T_int_ty(cx: &CrateContext, t: ast::int_ty) -> TypeRef {
match t {
ast::ty_i => cx.int_type,
ast::ty_char => T_char(),
@ -774,7 +774,7 @@ pub fn T_int_ty(cx: @CrateContext, t: ast::int_ty) -> TypeRef {
}
}
pub fn T_uint_ty(cx: @CrateContext, t: ast::uint_ty) -> TypeRef {
pub fn T_uint_ty(cx: &CrateContext, t: ast::uint_ty) -> TypeRef {
match t {
ast::ty_u => cx.int_type,
ast::ty_u8 => T_i8(),
@ -784,7 +784,7 @@ pub fn T_uint_ty(cx: @CrateContext, t: ast::uint_ty) -> TypeRef {
}
}
pub fn T_float_ty(cx: @CrateContext, t: ast::float_ty) -> TypeRef {
pub fn T_float_ty(cx: &CrateContext, t: ast::float_ty) -> TypeRef {
match t {
ast::ty_f => cx.float_type,
ast::ty_f32 => T_f32(),
@ -792,7 +792,7 @@ pub fn T_float_ty(cx: @CrateContext, t: ast::float_ty) -> TypeRef {
}
}
pub fn T_float(targ_cfg: @session::config) -> TypeRef {
pub fn T_float(targ_cfg: &session::config) -> TypeRef {
return match targ_cfg.arch {
X86 => T_f64(),
X86_64 => T_f64(),
@ -803,7 +803,7 @@ pub fn T_float(targ_cfg: @session::config) -> TypeRef {
pub fn T_char() -> TypeRef { return T_i32(); }
pub fn T_size_t(targ_cfg: @session::config) -> TypeRef {
pub fn T_size_t(targ_cfg: &session::config) -> TypeRef {
return T_int(targ_cfg);
}
@ -815,7 +815,7 @@ pub fn T_fn(inputs: &[TypeRef], output: TypeRef) -> TypeRef {
}
}
pub fn T_fn_pair(cx: @CrateContext, tfn: TypeRef) -> TypeRef {
pub fn T_fn_pair(cx: &CrateContext, tfn: TypeRef) -> TypeRef {
return T_struct([T_ptr(tfn), T_opaque_cbox_ptr(cx)], false);
}
@ -865,7 +865,7 @@ pub fn T_empty_struct() -> TypeRef { return T_struct([], false); }
// they are described by this opaque type.
pub fn T_vtable() -> TypeRef { T_array(T_ptr(T_i8()), 1u) }
pub fn T_tydesc_field(cx: @CrateContext, field: uint) -> TypeRef {
pub fn T_tydesc_field(cx: &CrateContext, field: uint) -> TypeRef {
// Bit of a kludge: pick the fn typeref out of the tydesc..
unsafe {
@ -878,7 +878,7 @@ pub fn T_tydesc_field(cx: @CrateContext, field: uint) -> TypeRef {
}
}
pub fn T_generic_glue_fn(cx: @CrateContext) -> TypeRef {
pub fn T_generic_glue_fn(cx: &mut CrateContext) -> TypeRef {
let s = @"glue_fn";
match name_has_type(cx.tn, s) {
Some(t) => return t,
@ -918,14 +918,14 @@ pub fn T_vector(t: TypeRef, n: uint) -> TypeRef {
}
// Interior vector.
pub fn T_vec2(targ_cfg: @session::config, t: TypeRef) -> TypeRef {
pub fn T_vec2(targ_cfg: &session::config, t: TypeRef) -> TypeRef {
return T_struct([T_int(targ_cfg), // fill
T_int(targ_cfg), // alloc
T_array(t, 0u)], // elements
false);
}
pub fn T_vec(ccx: @CrateContext, t: TypeRef) -> TypeRef {
pub fn T_vec(ccx: &CrateContext, t: TypeRef) -> TypeRef {
return T_vec2(ccx.sess.targ_cfg, t);
}
@ -947,16 +947,16 @@ pub fn tuplify_box_ty(tcx: ty::ctxt, t: ty::t) -> ty::t {
t]);
}
pub fn T_box_header_fields(cx: @CrateContext) -> ~[TypeRef] {
pub fn T_box_header_fields(cx: &CrateContext) -> ~[TypeRef] {
let ptr = T_ptr(T_i8());
return ~[cx.int_type, T_ptr(cx.tydesc_type), ptr, ptr];
}
pub fn T_box_header(cx: @CrateContext) -> TypeRef {
pub fn T_box_header(cx: &CrateContext) -> TypeRef {
return T_struct(T_box_header_fields(cx), false);
}
pub fn T_box(cx: @CrateContext, t: TypeRef) -> TypeRef {
pub fn T_box(cx: &CrateContext, t: TypeRef) -> TypeRef {
return T_struct(vec::append(T_box_header_fields(cx), [t]), false);
}
@ -966,15 +966,15 @@ pub fn T_box_ptr(t: TypeRef) -> TypeRef {
}
}
pub fn T_opaque_box(cx: @CrateContext) -> TypeRef {
pub fn T_opaque_box(cx: &CrateContext) -> TypeRef {
return T_box(cx, T_i8());
}
pub fn T_opaque_box_ptr(cx: @CrateContext) -> TypeRef {
pub fn T_opaque_box_ptr(cx: &CrateContext) -> TypeRef {
return T_box_ptr(T_opaque_box(cx));
}
pub fn T_unique(cx: @CrateContext, t: TypeRef) -> TypeRef {
pub fn T_unique(cx: &CrateContext, t: TypeRef) -> TypeRef {
return T_struct(vec::append(T_box_header_fields(cx), [t]), false);
}
@ -984,32 +984,32 @@ pub fn T_unique_ptr(t: TypeRef) -> TypeRef {
}
}
pub fn T_port(cx: @CrateContext, _t: TypeRef) -> TypeRef {
pub fn T_port(cx: &CrateContext, _t: TypeRef) -> TypeRef {
return T_struct([cx.int_type], false); // Refcount
}
pub fn T_chan(cx: @CrateContext, _t: TypeRef) -> TypeRef {
pub fn T_chan(cx: &CrateContext, _t: TypeRef) -> TypeRef {
return T_struct([cx.int_type], false); // Refcount
}
pub fn T_opaque_cbox_ptr(cx: @CrateContext) -> TypeRef {
pub fn T_opaque_cbox_ptr(cx: &CrateContext) -> TypeRef {
// closures look like boxes (even when they are ~fn or &fn)
// see trans_closure.rs
return T_opaque_box_ptr(cx);
}
pub fn T_enum_discrim(cx: @CrateContext) -> TypeRef {
pub fn T_enum_discrim(cx: &CrateContext) -> TypeRef {
return cx.int_type;
}
pub fn T_captured_tydescs(cx: @CrateContext, n: uint) -> TypeRef {
pub fn T_captured_tydescs(cx: &CrateContext, n: uint) -> TypeRef {
return T_struct(vec::from_elem::<TypeRef>(n, T_ptr(cx.tydesc_type)), false);
}
pub fn T_opaque_trait(cx: @CrateContext, store: ty::TraitStore) -> TypeRef {
pub fn T_opaque_trait(cx: &CrateContext, store: ty::TraitStore) -> TypeRef {
match store {
ty::BoxTraitStore => {
T_struct([T_ptr(cx.tydesc_type), T_opaque_box_ptr(cx)], false)
@ -1075,11 +1075,11 @@ pub fn C_i64(i: i64) -> ValueRef {
return C_integral(T_i64(), i as u64, True);
}
pub fn C_int(cx: @CrateContext, i: int) -> ValueRef {
pub fn C_int(cx: &CrateContext, i: int) -> ValueRef {
return C_integral(cx.int_type, i as u64, True);
}
pub fn C_uint(cx: @CrateContext, i: uint) -> ValueRef {
pub fn C_uint(cx: &CrateContext, i: uint) -> ValueRef {
return C_integral(cx.int_type, i as u64, False);
}
@ -1090,7 +1090,7 @@ pub fn C_u8(i: uint) -> ValueRef {
// This is a 'c-like' raw string, which differs from
// our boxed-and-length-annotated strings.
pub fn C_cstr(cx: @CrateContext, s: @str) -> ValueRef {
pub fn C_cstr(cx: &mut CrateContext, s: @str) -> ValueRef {
unsafe {
match cx.const_cstr_cache.find(&s) {
Some(&llval) => return llval,
@ -1116,7 +1116,7 @@ pub fn C_cstr(cx: @CrateContext, s: @str) -> ValueRef {
// NB: Do not use `do_spill_noroot` to make this into a constant string, or
// you will be kicked off fast isel. See issue #4352 for an example of this.
pub fn C_estr_slice(cx: @CrateContext, s: @str) -> ValueRef {
pub fn C_estr_slice(cx: &mut CrateContext, s: @str) -> ValueRef {
unsafe {
let len = s.len();
let cs = llvm::LLVMConstPointerCast(C_cstr(cx, s), T_ptr(T_i8()));
@ -1194,7 +1194,7 @@ pub fn C_bytes_plus_null(bytes: &[u8]) -> ValueRef {
}
}
pub fn C_shape(ccx: @CrateContext, bytes: ~[u8]) -> ValueRef {
pub fn C_shape(ccx: &CrateContext, bytes: ~[u8]) -> ValueRef {
unsafe {
let llshape = C_bytes_plus_null(bytes);
let name = fmt!("shape%u", (ccx.names)("shape").name);
@ -1214,7 +1214,7 @@ pub fn get_param(fndecl: ValueRef, param: uint) -> ValueRef {
}
}
pub fn const_get_elt(cx: @CrateContext, v: ValueRef, us: &[c_uint])
pub fn const_get_elt(cx: &CrateContext, v: ValueRef, us: &[c_uint])
-> ValueRef {
unsafe {
let r = do vec::as_imm_buf(us) |p, len| {

View File

@ -34,7 +34,7 @@ use core::libc::c_uint;
use core::str;
use syntax::{ast, ast_util, ast_map};
pub fn const_lit(cx: @CrateContext, e: @ast::expr, lit: ast::lit)
pub fn const_lit(cx: @mut CrateContext, e: @ast::expr, lit: ast::lit)
-> ValueRef {
let _icx = cx.insn_ctxt("trans_lit");
match lit.node {
@ -73,7 +73,7 @@ pub fn const_lit(cx: @CrateContext, e: @ast::expr, lit: ast::lit)
}
}
pub fn const_ptrcast(cx: @CrateContext, a: ValueRef, t: TypeRef) -> ValueRef {
pub fn const_ptrcast(cx: &mut CrateContext, a: ValueRef, t: TypeRef) -> ValueRef {
unsafe {
let b = llvm::LLVMConstPointerCast(a, T_ptr(t));
assert!(cx.const_globals.insert(b as int, a));
@ -81,7 +81,7 @@ pub fn const_ptrcast(cx: @CrateContext, a: ValueRef, t: TypeRef) -> ValueRef {
}
}
pub fn const_vec(cx: @CrateContext, e: @ast::expr, es: &[@ast::expr])
pub fn const_vec(cx: @mut CrateContext, e: @ast::expr, es: &[@ast::expr])
-> (ValueRef, ValueRef, TypeRef) {
unsafe {
let vec_ty = ty::expr_ty(cx.tcx, e);
@ -100,7 +100,7 @@ pub fn const_vec(cx: @CrateContext, e: @ast::expr, es: &[@ast::expr])
}
}
fn const_addr_of(cx: @CrateContext, cv: ValueRef) -> ValueRef {
fn const_addr_of(cx: @mut CrateContext, cv: ValueRef) -> ValueRef {
unsafe {
let gv = do str::as_c_str("const") |name| {
llvm::LLVMAddGlobal(cx.llmod, val_ty(cv), name)
@ -112,7 +112,7 @@ fn const_addr_of(cx: @CrateContext, cv: ValueRef) -> ValueRef {
}
}
fn const_deref_ptr(cx: @CrateContext, v: ValueRef) -> ValueRef {
fn const_deref_ptr(cx: @mut CrateContext, v: ValueRef) -> ValueRef {
let v = match cx.const_globals.find(&(v as int)) {
Some(&v) => v,
None => v
@ -123,13 +123,13 @@ fn const_deref_ptr(cx: @CrateContext, v: ValueRef) -> ValueRef {
}
}
fn const_deref_newtype(cx: @CrateContext, v: ValueRef, t: ty::t)
fn const_deref_newtype(cx: @mut CrateContext, v: ValueRef, t: ty::t)
-> ValueRef {
let repr = adt::represent_type(cx, t);
adt::const_get_field(cx, repr, v, 0, 0)
}
fn const_deref(cx: @CrateContext, v: ValueRef, t: ty::t, explicit: bool)
fn const_deref(cx: @mut CrateContext, v: ValueRef, t: ty::t, explicit: bool)
-> (ValueRef, ty::t) {
match ty::deref(cx.tcx, t, explicit) {
Some(ref mt) => {
@ -155,10 +155,9 @@ fn const_deref(cx: @CrateContext, v: ValueRef, t: ty::t, explicit: bool)
}
}
pub fn get_const_val(cx: @CrateContext, def_id: ast::def_id) -> ValueRef {
let mut def_id = def_id;
if !ast_util::is_local(def_id) ||
!cx.const_values.contains_key(&def_id.node) {
pub fn get_const_val(cx: @mut CrateContext, mut def_id: ast::def_id) -> ValueRef {
let contains_key = cx.const_values.contains_key(&def_id.node);
if !ast_util::is_local(def_id) || !contains_key {
if !ast_util::is_local(def_id) {
def_id = inline::maybe_instantiate_inline(cx, def_id, true);
}
@ -174,19 +173,20 @@ pub fn get_const_val(cx: @CrateContext, def_id: ast::def_id) -> ValueRef {
cx.const_values.get_copy(&def_id.node)
}
pub fn const_expr(cx: @CrateContext, e: @ast::expr) -> ValueRef {
pub fn const_expr(cx: @mut CrateContext, e: @ast::expr) -> ValueRef {
let mut llconst = const_expr_unadjusted(cx, e);
let ety = ty::expr_ty(cx.tcx, e);
match cx.tcx.adjustments.find(&e.id) {
let adjustment = cx.tcx.adjustments.find_copy(&e.id);
match adjustment {
None => { }
Some(&@ty::AutoAddEnv(ty::re_static, ast::BorrowedSigil)) => {
Some(@ty::AutoAddEnv(ty::re_static, ast::BorrowedSigil)) => {
llconst = C_struct([llconst, C_null(T_opaque_box_ptr(cx))])
}
Some(&@ty::AutoAddEnv(ref r, ref s)) => {
Some(@ty::AutoAddEnv(ref r, ref s)) => {
cx.sess.span_bug(e.span, fmt!("unexpected static function: \
region %? sigil %?", *r, *s))
}
Some(&@ty::AutoDerefRef(ref adj)) => {
Some(@ty::AutoDerefRef(ref adj)) => {
let mut ty = ety;
let mut maybe_ptr = None;
for adj.autoderefs.times {
@ -246,7 +246,7 @@ pub fn const_expr(cx: @CrateContext, e: @ast::expr) -> ValueRef {
llconst
}
fn const_expr_unadjusted(cx: @CrateContext, e: @ast::expr) -> ValueRef {
fn const_expr_unadjusted(cx: @mut CrateContext, e: @ast::expr) -> ValueRef {
unsafe {
let _icx = cx.insn_ctxt("const_expr");
return match e.node {
@ -445,7 +445,8 @@ fn const_expr_unadjusted(cx: @CrateContext, e: @ast::expr) -> ValueRef {
(expr::cast_enum, expr::cast_integral) |
(expr::cast_enum, expr::cast_float) => {
let repr = adt::represent_type(cx, basety);
let iv = C_int(cx, adt::const_get_discrim(cx, repr, v));
let discr = adt::const_get_discrim(cx, repr, v);
let iv = C_int(cx, discr);
let ety_cast = expr::cast_type_kind(ety);
match ety_cast {
expr::cast_integral => {
@ -470,17 +471,20 @@ fn const_expr_unadjusted(cx: @CrateContext, e: @ast::expr) -> ValueRef {
}
}
ast::expr_addr_of(ast::m_imm, sub) => {
const_addr_of(cx, const_expr(cx, sub))
let e = const_expr(cx, sub);
const_addr_of(cx, e)
}
ast::expr_tup(ref es) => {
let ety = ty::expr_ty(cx.tcx, e);
let repr = adt::represent_type(cx, ety);
adt::trans_const(cx, repr, 0, es.map(|e| const_expr(cx, *e)))
let vals = es.map(|&e| const_expr(cx, e));
adt::trans_const(cx, repr, 0, vals)
}
ast::expr_struct(_, ref fs, None) => {
let ety = ty::expr_ty(cx.tcx, e);
let repr = adt::represent_type(cx, ety);
do expr::with_field_tys(cx.tcx, ety, Some(e.id))
let tcx = cx.tcx;
do expr::with_field_tys(tcx, ety, Some(e.id))
|discr, field_tys| {
let cs = field_tys.map(|field_ty| {
match fs.find(|f| field_ty.ident == f.node.ident) {
@ -522,7 +526,8 @@ fn const_expr_unadjusted(cx: @CrateContext, e: @ast::expr) -> ValueRef {
}
ast::expr_path(pth) => {
assert_eq!(pth.types.len(), 0);
match cx.tcx.def_map.find(&e.id) {
let tcx = cx.tcx;
match tcx.def_map.find(&e.id) {
Some(&ast::def_fn(def_id, _purity)) => {
if !ast_util::is_local(def_id) {
let ty = csearch::get_type(cx.tcx, def_id).ty;
@ -554,12 +559,13 @@ fn const_expr_unadjusted(cx: @CrateContext, e: @ast::expr) -> ValueRef {
}
}
ast::expr_call(callee, ref args, _) => {
match cx.tcx.def_map.find(&callee.id) {
let tcx = cx.tcx;
match tcx.def_map.find(&callee.id) {
Some(&ast::def_struct(_)) => {
let ety = ty::expr_ty(cx.tcx, e);
let repr = adt::represent_type(cx, ety);
adt::trans_const(cx, repr, 0,
args.map(|a| const_expr(cx, *a)))
let arg_vals = args.map(|a| const_expr(cx, *a));
adt::trans_const(cx, repr, 0, arg_vals)
}
Some(&ast::def_variant(enum_did, variant_did)) => {
let ety = ty::expr_ty(cx.tcx, e);
@ -567,8 +573,8 @@ fn const_expr_unadjusted(cx: @CrateContext, e: @ast::expr) -> ValueRef {
let vinfo = ty::enum_variant_with_id(cx.tcx,
enum_did,
variant_did);
adt::trans_const(cx, repr, vinfo.disr_val,
args.map(|a| const_expr(cx, *a)))
let arg_vals = args.map(|a| const_expr(cx, *a));
adt::trans_const(cx, repr, vinfo.disr_val, arg_vals)
}
_ => cx.sess.span_bug(e.span, "expected a struct or variant def")
}
@ -580,7 +586,7 @@ fn const_expr_unadjusted(cx: @CrateContext, e: @ast::expr) -> ValueRef {
}
}
pub fn trans_const(ccx: @CrateContext, _e: @ast::expr, id: ast::node_id) {
pub fn trans_const(ccx: @mut CrateContext, _e: @ast::expr, id: ast::node_id) {
unsafe {
let _icx = ccx.insn_ctxt("trans_const");
let g = base::get_item_val(ccx, id);

View File

@ -1,3 +1,13 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use core::prelude::*;
use back::{upcall};
@ -39,29 +49,29 @@ pub struct CrateContext {
tn: @TypeNames,
externs: ExternMap,
intrinsics: HashMap<&'static str, ValueRef>,
item_vals: @mut HashMap<ast::node_id, ValueRef>,
item_vals: HashMap<ast::node_id, ValueRef>,
exp_map2: resolve::ExportMap2,
reachable: reachable::map,
item_symbols: @mut HashMap<ast::node_id, ~str>,
item_symbols: HashMap<ast::node_id, ~str>,
link_meta: LinkMeta,
enum_sizes: @mut HashMap<ty::t, uint>,
discrims: @mut HashMap<ast::def_id, ValueRef>,
discrim_symbols: @mut HashMap<ast::node_id, @str>,
tydescs: @mut HashMap<ty::t, @mut tydesc_info>,
enum_sizes: HashMap<ty::t, uint>,
discrims: HashMap<ast::def_id, ValueRef>,
discrim_symbols: HashMap<ast::node_id, @str>,
tydescs: HashMap<ty::t, @mut tydesc_info>,
// Set when running emit_tydescs to enforce that no more tydescs are
// created.
finished_tydescs: @mut bool,
finished_tydescs: bool,
// Track mapping of external ids to local items imported for inlining
external: @mut HashMap<ast::def_id, Option<ast::node_id>>,
external: HashMap<ast::def_id, Option<ast::node_id>>,
// Cache instances of monomorphized functions
monomorphized: @mut HashMap<mono_id, ValueRef>,
monomorphizing: @mut HashMap<ast::def_id, uint>,
monomorphized: HashMap<mono_id, ValueRef>,
monomorphizing: HashMap<ast::def_id, uint>,
// Cache computed type parameter uses (see type_use.rs)
type_use_cache: @mut HashMap<ast::def_id, @~[type_use::type_uses]>,
type_use_cache: HashMap<ast::def_id, @~[type_use::type_uses]>,
// Cache generated vtables
vtables: @mut HashMap<mono_id, ValueRef>,
vtables: HashMap<mono_id, ValueRef>,
// Cache of constant strings,
const_cstr_cache: @mut HashMap<@str, ValueRef>,
const_cstr_cache: HashMap<@str, ValueRef>,
// Reverse-direction for const ptrs cast from globals.
// Key is an int, cast from a ValueRef holding a *T,
@ -71,27 +81,27 @@ pub struct CrateContext {
// when we ptrcast, and we have to ptrcast during translation
// of a [T] const because we form a slice, a [*T,int] pair, not
// a pointer to an LLVM array type.
const_globals: @mut HashMap<int, ValueRef>,
const_globals: HashMap<int, ValueRef>,
// Cache of emitted const values
const_values: @mut HashMap<ast::node_id, ValueRef>,
const_values: HashMap<ast::node_id, ValueRef>,
// Cache of external const values
extern_const_values: @mut HashMap<ast::def_id, ValueRef>,
extern_const_values: HashMap<ast::def_id, ValueRef>,
module_data: @mut HashMap<~str, ValueRef>,
lltypes: @mut HashMap<ty::t, TypeRef>,
llsizingtypes: @mut HashMap<ty::t, TypeRef>,
adt_reprs: @mut HashMap<ty::t, @adt::Repr>,
module_data: HashMap<~str, ValueRef>,
lltypes: HashMap<ty::t, TypeRef>,
llsizingtypes: HashMap<ty::t, TypeRef>,
adt_reprs: HashMap<ty::t, @adt::Repr>,
names: namegen,
next_addrspace: addrspace_gen,
symbol_hasher: @mut hash::State,
type_hashcodes: @mut HashMap<ty::t, @str>,
type_short_names: @mut HashMap<ty::t, ~str>,
all_llvm_symbols: @mut HashSet<@str>,
symbol_hasher: hash::State,
type_hashcodes: HashMap<ty::t, @str>,
type_short_names: HashMap<ty::t, ~str>,
all_llvm_symbols: HashSet<@str>,
tcx: ty::ctxt,
maps: astencode::Maps,
stats: @mut Stats,
stats: Stats,
upcalls: @upcall::Upcalls,
tydesc_type: TypeRef,
int_type: TypeRef,
@ -103,15 +113,15 @@ pub struct CrateContext {
// Set when at least one function uses GC. Needed so that
// decl_gc_metadata knows whether to link to the module metadata, which
// is not emitted by LLVM's GC pass when no functions use GC.
uses_gc: @mut bool,
uses_gc: bool,
dbg_cx: Option<debuginfo::DebugContext>,
do_not_commit_warning_issued: @mut bool
do_not_commit_warning_issued: bool
}
impl CrateContext {
pub fn new(sess: session::Session, name: &str, tcx: ty::ctxt,
emap2: resolve::ExportMap2, maps: astencode::Maps,
symbol_hasher: @mut hash::State, link_meta: LinkMeta,
symbol_hasher: hash::State, link_meta: LinkMeta,
reachable: reachable::map) -> CrateContext {
unsafe {
let llcx = llvm::LLVMContextCreate();
@ -147,40 +157,40 @@ impl CrateContext {
llcx: llcx,
td: td,
tn: tn,
externs: @mut HashMap::new(),
externs: HashMap::new(),
intrinsics: intrinsics,
item_vals: @mut HashMap::new(),
item_vals: HashMap::new(),
exp_map2: emap2,
reachable: reachable,
item_symbols: @mut HashMap::new(),
item_symbols: HashMap::new(),
link_meta: link_meta,
enum_sizes: @mut HashMap::new(),
discrims: @mut HashMap::new(),
discrim_symbols: @mut HashMap::new(),
tydescs: @mut HashMap::new(),
finished_tydescs: @mut false,
external: @mut HashMap::new(),
monomorphized: @mut HashMap::new(),
monomorphizing: @mut HashMap::new(),
type_use_cache: @mut HashMap::new(),
vtables: @mut HashMap::new(),
const_cstr_cache: @mut HashMap::new(),
const_globals: @mut HashMap::new(),
const_values: @mut HashMap::new(),
extern_const_values: @mut HashMap::new(),
module_data: @mut HashMap::new(),
lltypes: @mut HashMap::new(),
llsizingtypes: @mut HashMap::new(),
adt_reprs: @mut HashMap::new(),
enum_sizes: HashMap::new(),
discrims: HashMap::new(),
discrim_symbols: HashMap::new(),
tydescs: HashMap::new(),
finished_tydescs: false,
external: HashMap::new(),
monomorphized: HashMap::new(),
monomorphizing: HashMap::new(),
type_use_cache: HashMap::new(),
vtables: HashMap::new(),
const_cstr_cache: HashMap::new(),
const_globals: HashMap::new(),
const_values: HashMap::new(),
extern_const_values: HashMap::new(),
module_data: HashMap::new(),
lltypes: HashMap::new(),
llsizingtypes: HashMap::new(),
adt_reprs: HashMap::new(),
names: new_namegen(),
next_addrspace: new_addrspace_gen(),
symbol_hasher: symbol_hasher,
type_hashcodes: @mut HashMap::new(),
type_short_names: @mut HashMap::new(),
all_llvm_symbols: @mut HashSet::new(),
type_hashcodes: HashMap::new(),
type_short_names: HashMap::new(),
all_llvm_symbols: HashSet::new(),
tcx: tcx,
maps: maps,
stats: @mut Stats {
stats: Stats {
n_static_tydescs: 0u,
n_glues_created: 0u,
n_null_glues: 0u,
@ -189,9 +199,9 @@ impl CrateContext {
n_monos: 0u,
n_inlines: 0u,
n_closures: 0u,
llvm_insn_ctxt: @mut ~[],
llvm_insns: @mut HashMap::new(),
fn_times: @mut ~[]
llvm_insn_ctxt: ~[],
llvm_insns: HashMap::new(),
fn_times: ~[]
},
upcalls: upcall::declare_upcalls(targ_cfg, llmod),
tydesc_type: tydesc_type,
@ -203,9 +213,9 @@ impl CrateContext {
}),
shape_cx: mk_ctxt(llmod),
crate_map: crate_map,
uses_gc: @mut false,
uses_gc: false,
dbg_cx: dbg_cx,
do_not_commit_warning_issued: @mut false
do_not_commit_warning_issued: false
}
}
}

View File

@ -844,7 +844,7 @@ impl DatumBlock {
rslt(self.bcx, self.datum.to_appropriate_llval(self.bcx))
}
pub fn ccx(&self) -> @CrateContext {
pub fn ccx(&self) -> @mut CrateContext {
self.bcx.ccx()
}

View File

@ -96,7 +96,7 @@ fn llnull() -> ValueRef {
}
}
fn add_named_metadata(cx: @CrateContext, name: ~str, val: ValueRef) {
fn add_named_metadata(cx: &CrateContext, name: ~str, val: ValueRef) {
str::as_c_str(name, |sbuf| {
unsafe {
llvm::LLVMAddNamedMetadataOperand(cx.llmod, sbuf, val)
@ -208,7 +208,7 @@ fn cached_metadata<T:Copy>(cache: metadata_cache,
return option::None;
}
fn create_compile_unit(cx: @CrateContext) -> @Metadata<CompileUnitMetadata> {
fn create_compile_unit(cx: &mut CrateContext) -> @Metadata<CompileUnitMetadata> {
let cache = get_cache(cx);
let crate_name = /*bad*/copy (/*bad*/copy cx.dbg_cx).get().crate_file;
let tg = CompileUnitTag;
@ -244,8 +244,8 @@ fn create_compile_unit(cx: @CrateContext) -> @Metadata<CompileUnitMetadata> {
return mdval;
}
fn get_cache(cx: @CrateContext) -> metadata_cache {
(/*bad*/copy cx.dbg_cx).get().llmetadata
fn get_cache(cx: &CrateContext) -> metadata_cache {
cx.dbg_cx.get_ref().llmetadata
}
fn get_file_path_and_dir(work_dir: &str, full_path: &str) -> (~str, ~str) {
@ -257,7 +257,7 @@ fn get_file_path_and_dir(work_dir: &str, full_path: &str) -> (~str, ~str) {
}, work_dir.to_owned())
}
fn create_file(cx: @CrateContext, full_path: ~str)
fn create_file(cx: &mut CrateContext, full_path: ~str)
-> @Metadata<FileMetadata> {
let cache = get_cache(cx);;
let tg = FileDescriptorTag;
@ -290,9 +290,8 @@ fn line_from_span(cm: @codemap::CodeMap, sp: span) -> uint {
cm.lookup_char_pos(sp.lo).line
}
fn create_block(cx: block) -> @Metadata<BlockMetadata> {
fn create_block(mut cx: block) -> @Metadata<BlockMetadata> {
let cache = get_cache(cx.ccx());
let mut cx = cx;
while cx.node_info.is_none() {
match cx.parent {
Some(b) => cx = b,
@ -340,13 +339,13 @@ fn create_block(cx: block) -> @Metadata<BlockMetadata> {
return mdval;
}
fn size_and_align_of(cx: @CrateContext, t: ty::t) -> (int, int) {
fn size_and_align_of(cx: &mut CrateContext, t: ty::t) -> (int, int) {
let llty = type_of::type_of(cx, t);
(machine::llsize_of_real(cx, llty) as int,
machine::llalign_of_pref(cx, llty) as int)
}
fn create_basic_type(cx: @CrateContext, t: ty::t, span: span)
fn create_basic_type(cx: &mut CrateContext, t: ty::t, span: span)
-> @Metadata<TyDescMetadata> {
let cache = get_cache(cx);
let tg = BasicTypeDescriptorTag;
@ -408,7 +407,7 @@ fn create_basic_type(cx: @CrateContext, t: ty::t, span: span)
return mdval;
}
fn create_pointer_type(cx: @CrateContext, t: ty::t, span: span,
fn create_pointer_type(cx: &mut CrateContext, t: ty::t, span: span,
pointee: @Metadata<TyDescMetadata>)
-> @Metadata<TyDescMetadata> {
let tg = PointerTypeTag;
@ -498,7 +497,7 @@ fn add_member(cx: @mut StructCtxt,
cx.total_size += size * 8;
}
fn create_struct(cx: @CrateContext, t: ty::t, fields: ~[ty::field],
fn create_struct(cx: &mut CrateContext, t: ty::t, fields: ~[ty::field],
span: span) -> @Metadata<TyDescMetadata> {
let fname = filename_from_span(cx, span);
let file_node = create_file(cx, fname.to_owned());
@ -521,7 +520,7 @@ fn create_struct(cx: @CrateContext, t: ty::t, fields: ~[ty::field],
return mdval;
}
fn create_tuple(cx: @CrateContext, t: ty::t, elements: &[ty::t], span: span)
fn create_tuple(cx: &mut CrateContext, t: ty::t, elements: &[ty::t], span: span)
-> @Metadata<TyDescMetadata> {
let fname = filename_from_span(cx, span);
let file_node = create_file(cx, fname.to_owned());
@ -555,7 +554,7 @@ fn voidptr() -> (ValueRef, int, int) {
return (vp, size, align);
}
fn create_boxed_type(cx: @CrateContext, contents: ty::t,
fn create_boxed_type(cx: &mut CrateContext, contents: ty::t,
span: span, boxed: @Metadata<TyDescMetadata>)
-> @Metadata<TyDescMetadata> {
//let tg = StructureTypeTag;
@ -624,7 +623,7 @@ fn create_composite_type(type_tag: int, name: &str, file: ValueRef,
return llmdnode(lldata);
}
fn create_fixed_vec(cx: @CrateContext, vec_t: ty::t, elem_t: ty::t,
fn create_fixed_vec(cx: &mut CrateContext, vec_t: ty::t, elem_t: ty::t,
len: int, span: span) -> @Metadata<TyDescMetadata> {
let t_md = create_ty(cx, elem_t, span);
let fname = filename_from_span(cx, span);
@ -643,7 +642,7 @@ fn create_fixed_vec(cx: @CrateContext, vec_t: ty::t, elem_t: ty::t,
}
}
fn create_boxed_vec(cx: @CrateContext, vec_t: ty::t, elem_t: ty::t,
fn create_boxed_vec(cx: &mut CrateContext, vec_t: ty::t, elem_t: ty::t,
vec_ty_span: codemap::span)
-> @Metadata<TyDescMetadata> {
let fname = filename_from_span(cx, vec_ty_span);
@ -695,7 +694,7 @@ fn create_boxed_vec(cx: @CrateContext, vec_t: ty::t, elem_t: ty::t,
return mdval;
}
fn create_vec_slice(cx: @CrateContext, vec_t: ty::t, elem_t: ty::t, span: span)
fn create_vec_slice(cx: &mut CrateContext, vec_t: ty::t, elem_t: ty::t, span: span)
-> @Metadata<TyDescMetadata> {
let fname = filename_from_span(cx, span);
let file_node = create_file(cx, fname.to_owned());
@ -717,7 +716,7 @@ fn create_vec_slice(cx: @CrateContext, vec_t: ty::t, elem_t: ty::t, span: span)
return mdval;
}
fn create_fn_ty(cx: @CrateContext, fn_ty: ty::t, inputs: ~[ty::t], output: ty::t,
fn create_fn_ty(cx: &mut CrateContext, fn_ty: ty::t, inputs: ~[ty::t], output: ty::t,
span: span) -> @Metadata<TyDescMetadata> {
let fname = filename_from_span(cx, span);
let file_node = create_file(cx, fname.to_owned());
@ -737,7 +736,7 @@ fn create_fn_ty(cx: @CrateContext, fn_ty: ty::t, inputs: ~[ty::t], output: ty::t
return mdval;
}
fn create_ty(cx: @CrateContext, t: ty::t, span: span)
fn create_ty(cx: &mut CrateContext, t: ty::t, span: span)
-> @Metadata<TyDescMetadata> {
debug!("create_ty: %?", ty::get(t));
/*let cache = get_cache(cx);
@ -817,7 +816,7 @@ fn create_ty(cx: @CrateContext, t: ty::t, span: span)
}
}
fn filename_from_span(cx: @CrateContext, sp: codemap::span) -> @str {
fn filename_from_span(cx: &CrateContext, sp: codemap::span) -> @str {
cx.sess.codemap.lookup_char_pos(sp.lo).file.name
}
@ -878,7 +877,7 @@ pub fn create_local_var(bcx: block, local: @ast::local)
}
};
let declargs = ~[llmdnode([llptr]), mdnode];
trans::build::Call(bcx, *cx.intrinsics.get(&("llvm.dbg.declare")),
trans::build::Call(bcx, cx.intrinsics.get_copy(&("llvm.dbg.declare")),
declargs);
return mdval;
}
@ -886,7 +885,7 @@ pub fn create_local_var(bcx: block, local: @ast::local)
pub fn create_arg(bcx: block, arg: ast::arg, sp: span)
-> Option<@Metadata<ArgumentMetadata>> {
let fcx = bcx.fcx;
let cx = *fcx.ccx;
let cx = fcx.ccx;
let cache = get_cache(cx);
let tg = ArgVariableTag;
match cached_metadata::<@Metadata<ArgumentMetadata>>(
@ -927,7 +926,7 @@ pub fn create_arg(bcx: block, arg: ast::arg, sp: span)
let llptr = fcx.llargs.get_copy(&arg.id);
let declargs = ~[llmdnode([llptr]), mdnode];
trans::build::Call(bcx,
*cx.intrinsics.get(&("llvm.dbg.declare")),
cx.intrinsics.get_copy(&("llvm.dbg.declare")),
declargs);
return Some(mdval);
}
@ -955,8 +954,7 @@ pub fn update_source_pos(cx: block, s: span) {
}
pub fn create_function(fcx: fn_ctxt) -> @Metadata<SubProgramMetadata> {
let cx = *fcx.ccx;
let dbg_cx = (/*bad*/copy cx.dbg_cx).get();
let mut cx = fcx.ccx;
debug!("~~");
@ -980,6 +978,7 @@ pub fn create_function(fcx: fn_ctxt) -> @Metadata<SubProgramMetadata> {
ast_map::node_expr(expr) => {
match expr.node {
ast::expr_fn_block(ref decl, _) => {
let dbg_cx = cx.dbg_cx.get_ref();
((dbg_cx.names)("fn"), decl.output, expr.id)
}
_ => fcx.ccx.sess.span_bug(expr.span,

View File

@ -171,7 +171,7 @@ pub enum Dest {
}
impl Dest {
pub fn to_str(&self, ccx: @CrateContext) -> ~str {
pub fn to_str(&self, ccx: &CrateContext) -> ~str {
match *self {
SaveIn(v) => fmt!("SaveIn(%s)", val_str(ccx.tn, v)),
Ignore => ~"Ignore"
@ -946,7 +946,7 @@ fn trans_lvalue_unadjusted(bcx: block, expr: @ast::expr) -> DatumBlock {
ast::def_const(did) => {
let const_ty = expr_ty(bcx, ref_expr);
fn get_did(ccx: @CrateContext, did: ast::def_id)
fn get_did(ccx: @mut CrateContext, did: ast::def_id)
-> ast::def_id {
if did.crate != ast::local_crate {
inline::maybe_instantiate_inline(ccx, did, true)
@ -958,20 +958,21 @@ fn trans_lvalue_unadjusted(bcx: block, expr: @ast::expr) -> DatumBlock {
fn get_val(bcx: block, did: ast::def_id, const_ty: ty::t)
-> ValueRef {
// For external constants, we don't inline.
let extern_const_values =
&mut *bcx.ccx().extern_const_values;
if did.crate == ast::local_crate {
// The LLVM global has the type of its initializer,
// which may not be equal to the enum's type for
// non-C-like enums.
PointerCast(bcx,
base::get_item_val(bcx.ccx(), did.node),
T_ptr(type_of(bcx.ccx(), const_ty)))
let val = base::get_item_val(bcx.ccx(), did.node);
let pty = T_ptr(type_of(bcx.ccx(), const_ty));
PointerCast(bcx, val, pty)
} else {
match extern_const_values.find(&did) {
None => {} // Continue.
Some(llval) => {
return *llval;
{
let extern_const_values = &bcx.ccx().extern_const_values;
match extern_const_values.find(&did) {
None => {} // Continue.
Some(llval) => {
return *llval;
}
}
}
@ -984,6 +985,7 @@ fn trans_lvalue_unadjusted(bcx: block, expr: @ast::expr) -> DatumBlock {
bcx.ccx().llmod,
llty,
transmute::<&u8,*i8>(&symbol[0]));
let extern_const_values = &mut bcx.ccx().extern_const_values;
extern_const_values.insert(did, llval);
llval
}

View File

@ -46,7 +46,7 @@ use syntax::abi::{X86, X86_64, Arm, Mips};
use syntax::abi::{RustIntrinsic, Rust, Stdcall, Fastcall,
Cdecl, Aapcs, C};
fn abi_info(ccx: @CrateContext) -> @cabi::ABIInfo {
fn abi_info(ccx: @mut CrateContext) -> @cabi::ABIInfo {
return match ccx.sess.targ_cfg.arch {
X86 => cabi_x86::abi_info(ccx),
X86_64 => cabi_x86_64::abi_info(),
@ -55,7 +55,7 @@ fn abi_info(ccx: @CrateContext) -> @cabi::ABIInfo {
}
}
pub fn link_name(ccx: @CrateContext, i: @ast::foreign_item) -> @str {
pub fn link_name(ccx: &CrateContext, i: @ast::foreign_item) -> @str {
match attr::first_attr_value_str_by_name(i.attrs, "link_name") {
None => ccx.sess.str_of(i.ident),
Some(ln) => ln,
@ -89,7 +89,7 @@ struct LlvmSignature {
sret: bool,
}
fn foreign_signature(ccx: @CrateContext, fn_sig: &ty::FnSig)
fn foreign_signature(ccx: @mut CrateContext, fn_sig: &ty::FnSig)
-> LlvmSignature {
/*!
* The ForeignSignature is the LLVM types of the arguments/return type
@ -108,7 +108,7 @@ fn foreign_signature(ccx: @CrateContext, fn_sig: &ty::FnSig)
}
}
fn shim_types(ccx: @CrateContext, id: ast::node_id) -> ShimTypes {
fn shim_types(ccx: @mut CrateContext, id: ast::node_id) -> ShimTypes {
let fn_sig = match ty::get(ty::node_id_to_type(ccx.tcx, id)).sty {
ty::ty_bare_fn(ref fn_ty) => copy fn_ty.sig,
_ => ccx.sess.bug("c_arg_and_ret_lltys called on non-function type")
@ -141,7 +141,7 @@ type shim_ret_builder<'self> =
llargbundle: ValueRef,
llretval: ValueRef);
fn build_shim_fn_(ccx: @CrateContext,
fn build_shim_fn_(ccx: @mut CrateContext,
shim_name: ~str,
llbasefn: ValueRef,
tys: &ShimTypes,
@ -184,7 +184,7 @@ type wrap_ret_builder<'self> = &'self fn(bcx: block,
tys: &ShimTypes,
llargbundle: ValueRef);
fn build_wrap_fn_(ccx: @CrateContext,
fn build_wrap_fn_(ccx: @mut CrateContext,
tys: &ShimTypes,
llshimfn: ValueRef,
llwrapfn: ValueRef,
@ -198,7 +198,7 @@ fn build_wrap_fn_(ccx: @CrateContext,
// Patch up the return type if it's not immediate and we're returning via
// the C ABI.
if needs_c_return && !ty::type_is_immediate(tys.fn_sig.output) {
let lloutputtype = type_of::type_of(*fcx.ccx, tys.fn_sig.output);
let lloutputtype = type_of::type_of(fcx.ccx, tys.fn_sig.output);
fcx.llretptr = Some(alloca(raw_block(fcx, false, fcx.llstaticallocas),
lloutputtype));
}
@ -282,7 +282,7 @@ fn build_wrap_fn_(ccx: @CrateContext,
// round of copies. (In fact, the shim function itself is
// unnecessary). We used to do this, in fact, and will perhaps do so
// in the future.
pub fn trans_foreign_mod(ccx: @CrateContext,
pub fn trans_foreign_mod(ccx: @mut CrateContext,
path: &ast_map::path,
foreign_mod: &ast::foreign_mod) {
let _icx = ccx.insn_ctxt("foreign::trans_foreign_mod");
@ -350,7 +350,7 @@ pub fn trans_foreign_mod(ccx: @CrateContext,
}
}
fn build_foreign_fn(ccx: @CrateContext,
fn build_foreign_fn(ccx: @mut CrateContext,
id: ast::node_id,
foreign_item: @ast::foreign_item,
cc: lib::llvm::CallConv) {
@ -367,7 +367,7 @@ pub fn trans_foreign_mod(ccx: @CrateContext,
}
}
fn build_shim_fn(ccx: @CrateContext,
fn build_shim_fn(ccx: @mut CrateContext,
foreign_item: @ast::foreign_item,
tys: &ShimTypes,
cc: lib::llvm::CallConv)
@ -415,7 +415,7 @@ pub fn trans_foreign_mod(ccx: @CrateContext,
build_ret)
}
fn base_fn(ccx: @CrateContext,
fn base_fn(ccx: &CrateContext,
lname: &str,
tys: &ShimTypes,
cc: lib::llvm::CallConv)
@ -428,7 +428,7 @@ pub fn trans_foreign_mod(ccx: @CrateContext,
// FIXME (#2535): this is very shaky and probably gets ABIs wrong all
// over the place
fn build_direct_fn(ccx: @CrateContext,
fn build_direct_fn(ccx: @mut CrateContext,
decl: ValueRef,
item: @ast::foreign_item,
tys: &ShimTypes,
@ -455,7 +455,7 @@ pub fn trans_foreign_mod(ccx: @CrateContext,
// FIXME (#2535): this is very shaky and probably gets ABIs wrong all
// over the place
fn build_fast_ffi_fn(ccx: @CrateContext,
fn build_fast_ffi_fn(ccx: @mut CrateContext,
decl: ValueRef,
item: @ast::foreign_item,
tys: &ShimTypes,
@ -482,7 +482,7 @@ pub fn trans_foreign_mod(ccx: @CrateContext,
finish_fn(fcx, lltop);
}
fn build_wrap_fn(ccx: @CrateContext,
fn build_wrap_fn(ccx: @mut CrateContext,
tys: &ShimTypes,
llshimfn: ValueRef,
llwrapfn: ValueRef) {
@ -546,7 +546,7 @@ pub fn trans_foreign_mod(ccx: @CrateContext,
}
}
pub fn trans_intrinsic(ccx: @CrateContext,
pub fn trans_intrinsic(ccx: @mut CrateContext,
decl: ValueRef,
item: @ast::foreign_item,
path: ast_map::path,
@ -811,7 +811,7 @@ pub fn trans_intrinsic(ccx: @CrateContext,
None);
}
"frame_address" => {
let frameaddress = *ccx.intrinsics.get(& &"llvm.frameaddress");
let frameaddress = ccx.intrinsics.get_copy(& &"llvm.frameaddress");
let frameaddress_val = Call(bcx, frameaddress, [C_i32(0i32)]);
let star_u8 = ty::mk_imm_ptr(
bcx.tcx(),
@ -857,7 +857,7 @@ pub fn trans_intrinsic(ccx: @CrateContext,
let src_ptr = PointerCast(bcx, get_param(decl, first_real_arg + 1), T_ptr(T_i8()));
let count = get_param(decl, first_real_arg + 2);
let volatile = C_i1(false);
let llfn = *bcx.ccx().intrinsics.get(& &"llvm.memcpy.p0i8.p0i8.i32");
let llfn = bcx.ccx().intrinsics.get_copy(& &"llvm.memcpy.p0i8.p0i8.i32");
Call(bcx, llfn, [dst_ptr, src_ptr, Mul(bcx, size, count), align, volatile]);
}
"memcpy64" => {
@ -870,7 +870,7 @@ pub fn trans_intrinsic(ccx: @CrateContext,
let src_ptr = PointerCast(bcx, get_param(decl, first_real_arg + 1), T_ptr(T_i8()));
let count = get_param(decl, first_real_arg + 2);
let volatile = C_i1(false);
let llfn = *bcx.ccx().intrinsics.get(& &"llvm.memcpy.p0i8.p0i8.i64");
let llfn = bcx.ccx().intrinsics.get_copy(& &"llvm.memcpy.p0i8.p0i8.i64");
Call(bcx, llfn, [dst_ptr, src_ptr, Mul(bcx, size, count), align, volatile]);
}
"memmove32" => {
@ -883,7 +883,7 @@ pub fn trans_intrinsic(ccx: @CrateContext,
let src_ptr = PointerCast(bcx, get_param(decl, first_real_arg + 1), T_ptr(T_i8()));
let count = get_param(decl, first_real_arg + 2);
let volatile = C_i1(false);
let llfn = *bcx.ccx().intrinsics.get(& &"llvm.memmove.p0i8.p0i8.i32");
let llfn = bcx.ccx().intrinsics.get_copy(& &"llvm.memmove.p0i8.p0i8.i32");
Call(bcx, llfn, [dst_ptr, src_ptr, Mul(bcx, size, count), align, volatile]);
}
"memmove64" => {
@ -896,7 +896,7 @@ pub fn trans_intrinsic(ccx: @CrateContext,
let src_ptr = PointerCast(bcx, get_param(decl, first_real_arg + 1), T_ptr(T_i8()));
let count = get_param(decl, first_real_arg + 2);
let volatile = C_i1(false);
let llfn = *bcx.ccx().intrinsics.get(& &"llvm.memmove.p0i8.p0i8.i64");
let llfn = bcx.ccx().intrinsics.get_copy(& &"llvm.memmove.p0i8.p0i8.i64");
Call(bcx, llfn, [dst_ptr, src_ptr, Mul(bcx, size, count), align, volatile]);
}
"memset32" => {
@ -909,7 +909,7 @@ pub fn trans_intrinsic(ccx: @CrateContext,
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(& &"llvm.memset.p0i8.i32");
let llfn = bcx.ccx().intrinsics.get_copy(& &"llvm.memset.p0i8.i32");
Call(bcx, llfn, [dst_ptr, val, Mul(bcx, size, count), align, volatile]);
}
"memset64" => {
@ -922,248 +922,248 @@ pub fn trans_intrinsic(ccx: @CrateContext,
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(& &"llvm.memset.p0i8.i64");
let llfn = bcx.ccx().intrinsics.get_copy(& &"llvm.memset.p0i8.i64");
Call(bcx, llfn, [dst_ptr, val, Mul(bcx, size, count), align, volatile]);
}
"sqrtf32" => {
let x = get_param(decl, first_real_arg);
let sqrtf = *ccx.intrinsics.get(& &"llvm.sqrt.f32");
let sqrtf = ccx.intrinsics.get_copy(& &"llvm.sqrt.f32");
Store(bcx, Call(bcx, sqrtf, [x]), fcx.llretptr.get());
}
"sqrtf64" => {
let x = get_param(decl, first_real_arg);
let sqrtf = *ccx.intrinsics.get(& &"llvm.sqrt.f64");
let sqrtf = ccx.intrinsics.get_copy(& &"llvm.sqrt.f64");
Store(bcx, Call(bcx, sqrtf, [x]), fcx.llretptr.get());
}
"powif32" => {
let a = get_param(decl, first_real_arg);
let x = get_param(decl, first_real_arg + 1u);
let powif = *ccx.intrinsics.get(& &"llvm.powi.f32");
let powif = ccx.intrinsics.get_copy(& &"llvm.powi.f32");
Store(bcx, Call(bcx, powif, [a, x]), fcx.llretptr.get());
}
"powif64" => {
let a = get_param(decl, first_real_arg);
let x = get_param(decl, first_real_arg + 1u);
let powif = *ccx.intrinsics.get(& &"llvm.powi.f64");
let powif = ccx.intrinsics.get_copy(& &"llvm.powi.f64");
Store(bcx, Call(bcx, powif, [a, x]), fcx.llretptr.get());
}
"sinf32" => {
let x = get_param(decl, first_real_arg);
let sinf = *ccx.intrinsics.get(& &"llvm.sin.f32");
let sinf = ccx.intrinsics.get_copy(& &"llvm.sin.f32");
Store(bcx, Call(bcx, sinf, [x]), fcx.llretptr.get());
}
"sinf64" => {
let x = get_param(decl, first_real_arg);
let sinf = *ccx.intrinsics.get(& &"llvm.sin.f64");
let sinf = ccx.intrinsics.get_copy(& &"llvm.sin.f64");
Store(bcx, Call(bcx, sinf, [x]), fcx.llretptr.get());
}
"cosf32" => {
let x = get_param(decl, first_real_arg);
let cosf = *ccx.intrinsics.get(& &"llvm.cos.f32");
let cosf = ccx.intrinsics.get_copy(& &"llvm.cos.f32");
Store(bcx, Call(bcx, cosf, [x]), fcx.llretptr.get());
}
"cosf64" => {
let x = get_param(decl, first_real_arg);
let cosf = *ccx.intrinsics.get(& &"llvm.cos.f64");
let cosf = ccx.intrinsics.get_copy(& &"llvm.cos.f64");
Store(bcx, Call(bcx, cosf, [x]), fcx.llretptr.get());
}
"powf32" => {
let a = get_param(decl, first_real_arg);
let x = get_param(decl, first_real_arg + 1u);
let powf = *ccx.intrinsics.get(& &"llvm.pow.f32");
let powf = ccx.intrinsics.get_copy(& &"llvm.pow.f32");
Store(bcx, Call(bcx, powf, [a, x]), fcx.llretptr.get());
}
"powf64" => {
let a = get_param(decl, first_real_arg);
let x = get_param(decl, first_real_arg + 1u);
let powf = *ccx.intrinsics.get(& &"llvm.pow.f64");
let powf = ccx.intrinsics.get_copy(& &"llvm.pow.f64");
Store(bcx, Call(bcx, powf, [a, x]), fcx.llretptr.get());
}
"expf32" => {
let x = get_param(decl, first_real_arg);
let expf = *ccx.intrinsics.get(& &"llvm.exp.f32");
let expf = ccx.intrinsics.get_copy(& &"llvm.exp.f32");
Store(bcx, Call(bcx, expf, [x]), fcx.llretptr.get());
}
"expf64" => {
let x = get_param(decl, first_real_arg);
let expf = *ccx.intrinsics.get(& &"llvm.exp.f64");
let expf = ccx.intrinsics.get_copy(& &"llvm.exp.f64");
Store(bcx, Call(bcx, expf, [x]), fcx.llretptr.get());
}
"exp2f32" => {
let x = get_param(decl, first_real_arg);
let exp2f = *ccx.intrinsics.get(& &"llvm.exp2.f32");
let exp2f = ccx.intrinsics.get_copy(& &"llvm.exp2.f32");
Store(bcx, Call(bcx, exp2f, [x]), fcx.llretptr.get());
}
"exp2f64" => {
let x = get_param(decl, first_real_arg);
let exp2f = *ccx.intrinsics.get(& &"llvm.exp2.f64");
let exp2f = ccx.intrinsics.get_copy(& &"llvm.exp2.f64");
Store(bcx, Call(bcx, exp2f, [x]), fcx.llretptr.get());
}
"logf32" => {
let x = get_param(decl, first_real_arg);
let logf = *ccx.intrinsics.get(& &"llvm.log.f32");
let logf = ccx.intrinsics.get_copy(& &"llvm.log.f32");
Store(bcx, Call(bcx, logf, [x]), fcx.llretptr.get());
}
"logf64" => {
let x = get_param(decl, first_real_arg);
let logf = *ccx.intrinsics.get(& &"llvm.log.f64");
let logf = ccx.intrinsics.get_copy(& &"llvm.log.f64");
Store(bcx, Call(bcx, logf, [x]), fcx.llretptr.get());
}
"log10f32" => {
let x = get_param(decl, first_real_arg);
let log10f = *ccx.intrinsics.get(& &"llvm.log10.f32");
let log10f = ccx.intrinsics.get_copy(& &"llvm.log10.f32");
Store(bcx, Call(bcx, log10f, [x]), fcx.llretptr.get());
}
"log10f64" => {
let x = get_param(decl, first_real_arg);
let log10f = *ccx.intrinsics.get(& &"llvm.log10.f64");
let log10f = ccx.intrinsics.get_copy(& &"llvm.log10.f64");
Store(bcx, Call(bcx, log10f, [x]), fcx.llretptr.get());
}
"log2f32" => {
let x = get_param(decl, first_real_arg);
let log2f = *ccx.intrinsics.get(& &"llvm.log2.f32");
let log2f = ccx.intrinsics.get_copy(& &"llvm.log2.f32");
Store(bcx, Call(bcx, log2f, [x]), fcx.llretptr.get());
}
"log2f64" => {
let x = get_param(decl, first_real_arg);
let log2f = *ccx.intrinsics.get(& &"llvm.log2.f64");
let log2f = ccx.intrinsics.get_copy(& &"llvm.log2.f64");
Store(bcx, Call(bcx, log2f, [x]), fcx.llretptr.get());
}
"fmaf32" => {
let a = get_param(decl, first_real_arg);
let b = get_param(decl, first_real_arg + 1u);
let c = get_param(decl, first_real_arg + 2u);
let fmaf = *ccx.intrinsics.get(& &"llvm.fma.f32");
let fmaf = ccx.intrinsics.get_copy(& &"llvm.fma.f32");
Store(bcx, Call(bcx, fmaf, [a, b, c]), fcx.llretptr.get());
}
"fmaf64" => {
let a = get_param(decl, first_real_arg);
let b = get_param(decl, first_real_arg + 1u);
let c = get_param(decl, first_real_arg + 2u);
let fmaf = *ccx.intrinsics.get(& &"llvm.fma.f64");
let fmaf = ccx.intrinsics.get_copy(& &"llvm.fma.f64");
Store(bcx, Call(bcx, fmaf, [a, b, c]), fcx.llretptr.get());
}
"fabsf32" => {
let x = get_param(decl, first_real_arg);
let fabsf = *ccx.intrinsics.get(& &"llvm.fabs.f32");
let fabsf = ccx.intrinsics.get_copy(& &"llvm.fabs.f32");
Store(bcx, Call(bcx, fabsf, [x]), fcx.llretptr.get());
}
"fabsf64" => {
let x = get_param(decl, first_real_arg);
let fabsf = *ccx.intrinsics.get(& &"llvm.fabs.f64");
let fabsf = ccx.intrinsics.get_copy(& &"llvm.fabs.f64");
Store(bcx, Call(bcx, fabsf, [x]), fcx.llretptr.get());
}
"floorf32" => {
let x = get_param(decl, first_real_arg);
let floorf = *ccx.intrinsics.get(& &"llvm.floor.f32");
let floorf = ccx.intrinsics.get_copy(& &"llvm.floor.f32");
Store(bcx, Call(bcx, floorf, [x]), fcx.llretptr.get());
}
"floorf64" => {
let x = get_param(decl, first_real_arg);
let floorf = *ccx.intrinsics.get(& &"llvm.floor.f64");
let floorf = ccx.intrinsics.get_copy(& &"llvm.floor.f64");
Store(bcx, Call(bcx, floorf, [x]), fcx.llretptr.get());
}
"ceilf32" => {
let x = get_param(decl, first_real_arg);
let ceilf = *ccx.intrinsics.get(& &"llvm.ceil.f32");
let ceilf = ccx.intrinsics.get_copy(& &"llvm.ceil.f32");
Store(bcx, Call(bcx, ceilf, [x]), fcx.llretptr.get());
}
"ceilf64" => {
let x = get_param(decl, first_real_arg);
let ceilf = *ccx.intrinsics.get(& &"llvm.ceil.f64");
let ceilf = ccx.intrinsics.get_copy(& &"llvm.ceil.f64");
Store(bcx, Call(bcx, ceilf, [x]), fcx.llretptr.get());
}
"truncf32" => {
let x = get_param(decl, first_real_arg);
let truncf = *ccx.intrinsics.get(& &"llvm.trunc.f32");
let truncf = ccx.intrinsics.get_copy(& &"llvm.trunc.f32");
Store(bcx, Call(bcx, truncf, [x]), fcx.llretptr.get());
}
"truncf64" => {
let x = get_param(decl, first_real_arg);
let truncf = *ccx.intrinsics.get(& &"llvm.trunc.f64");
let truncf = ccx.intrinsics.get_copy(& &"llvm.trunc.f64");
Store(bcx, Call(bcx, truncf, [x]), fcx.llretptr.get());
}
"ctpop8" => {
let x = get_param(decl, first_real_arg);
let ctpop = *ccx.intrinsics.get(& &"llvm.ctpop.i8");
let ctpop = ccx.intrinsics.get_copy(& &"llvm.ctpop.i8");
Store(bcx, Call(bcx, ctpop, [x]), fcx.llretptr.get())
}
"ctpop16" => {
let x = get_param(decl, first_real_arg);
let ctpop = *ccx.intrinsics.get(& &"llvm.ctpop.i16");
let ctpop = ccx.intrinsics.get_copy(& &"llvm.ctpop.i16");
Store(bcx, Call(bcx, ctpop, [x]), fcx.llretptr.get())
}
"ctpop32" => {
let x = get_param(decl, first_real_arg);
let ctpop = *ccx.intrinsics.get(& &"llvm.ctpop.i32");
let ctpop = ccx.intrinsics.get_copy(& &"llvm.ctpop.i32");
Store(bcx, Call(bcx, ctpop, [x]), fcx.llretptr.get())
}
"ctpop64" => {
let x = get_param(decl, first_real_arg);
let ctpop = *ccx.intrinsics.get(& &"llvm.ctpop.i64");
let ctpop = ccx.intrinsics.get_copy(& &"llvm.ctpop.i64");
Store(bcx, Call(bcx, ctpop, [x]), fcx.llretptr.get())
}
"ctlz8" => {
let x = get_param(decl, first_real_arg);
let y = C_i1(false);
let ctlz = *ccx.intrinsics.get(& &"llvm.ctlz.i8");
let ctlz = ccx.intrinsics.get_copy(& &"llvm.ctlz.i8");
Store(bcx, Call(bcx, ctlz, [x, y]), fcx.llretptr.get())
}
"ctlz16" => {
let x = get_param(decl, first_real_arg);
let y = C_i1(false);
let ctlz = *ccx.intrinsics.get(& &"llvm.ctlz.i16");
let ctlz = ccx.intrinsics.get_copy(& &"llvm.ctlz.i16");
Store(bcx, Call(bcx, ctlz, [x, y]), fcx.llretptr.get())
}
"ctlz32" => {
let x = get_param(decl, first_real_arg);
let y = C_i1(false);
let ctlz = *ccx.intrinsics.get(& &"llvm.ctlz.i32");
let ctlz = ccx.intrinsics.get_copy(& &"llvm.ctlz.i32");
Store(bcx, Call(bcx, ctlz, [x, y]), fcx.llretptr.get())
}
"ctlz64" => {
let x = get_param(decl, first_real_arg);
let y = C_i1(false);
let ctlz = *ccx.intrinsics.get(& &"llvm.ctlz.i64");
let ctlz = ccx.intrinsics.get_copy(& &"llvm.ctlz.i64");
Store(bcx, Call(bcx, ctlz, [x, y]), fcx.llretptr.get())
}
"cttz8" => {
let x = get_param(decl, first_real_arg);
let y = C_i1(false);
let cttz = *ccx.intrinsics.get(& &"llvm.cttz.i8");
let cttz = ccx.intrinsics.get_copy(& &"llvm.cttz.i8");
Store(bcx, Call(bcx, cttz, [x, y]), fcx.llretptr.get())
}
"cttz16" => {
let x = get_param(decl, first_real_arg);
let y = C_i1(false);
let cttz = *ccx.intrinsics.get(& &"llvm.cttz.i16");
let cttz = ccx.intrinsics.get_copy(& &"llvm.cttz.i16");
Store(bcx, Call(bcx, cttz, [x, y]), fcx.llretptr.get())
}
"cttz32" => {
let x = get_param(decl, first_real_arg);
let y = C_i1(false);
let cttz = *ccx.intrinsics.get(& &"llvm.cttz.i32");
let cttz = ccx.intrinsics.get_copy(& &"llvm.cttz.i32");
Store(bcx, Call(bcx, cttz, [x, y]), fcx.llretptr.get())
}
"cttz64" => {
let x = get_param(decl, first_real_arg);
let y = C_i1(false);
let cttz = *ccx.intrinsics.get(& &"llvm.cttz.i64");
let cttz = ccx.intrinsics.get_copy(& &"llvm.cttz.i64");
Store(bcx, Call(bcx, cttz, [x, y]), fcx.llretptr.get())
}
"bswap16" => {
let x = get_param(decl, first_real_arg);
let cttz = *ccx.intrinsics.get(& &"llvm.bswap.i16");
let cttz = ccx.intrinsics.get_copy(& &"llvm.bswap.i16");
Store(bcx, Call(bcx, cttz, [x]), fcx.llretptr.get())
}
"bswap32" => {
let x = get_param(decl, first_real_arg);
let cttz = *ccx.intrinsics.get(& &"llvm.bswap.i32");
let cttz = ccx.intrinsics.get_copy(& &"llvm.bswap.i32");
Store(bcx, Call(bcx, cttz, [x]), fcx.llretptr.get())
}
"bswap64" => {
let x = get_param(decl, first_real_arg);
let cttz = *ccx.intrinsics.get(& &"llvm.bswap.i64");
let cttz = ccx.intrinsics.get_copy(& &"llvm.bswap.i64");
Store(bcx, Call(bcx, cttz, [x]), fcx.llretptr.get())
}
_ => {
@ -1202,7 +1202,7 @@ pub fn trans_intrinsic(ccx: @CrateContext,
* R(args->z, NULL, args->x, args->y);
* }
*/
pub fn trans_foreign_fn(ccx: @CrateContext,
pub fn trans_foreign_fn(ccx: @mut CrateContext,
path: ast_map::path,
decl: &ast::fn_decl,
body: &ast::blk,
@ -1210,7 +1210,7 @@ pub fn trans_foreign_fn(ccx: @CrateContext,
id: ast::node_id) {
let _icx = ccx.insn_ctxt("foreign::build_foreign_fn");
fn build_rust_fn(ccx: @CrateContext,
fn build_rust_fn(ccx: @mut CrateContext,
path: ast_map::path,
decl: &ast::fn_decl,
body: &ast::blk,
@ -1238,7 +1238,7 @@ pub fn trans_foreign_fn(ccx: @CrateContext,
return llfndecl;
}
fn build_shim_fn(ccx: @CrateContext,
fn build_shim_fn(ccx: @mut CrateContext,
path: ast_map::path,
llrustfn: ValueRef,
tys: &ShimTypes)
@ -1323,7 +1323,7 @@ pub fn trans_foreign_fn(ccx: @CrateContext,
build_ret)
}
fn build_wrap_fn(ccx: @CrateContext,
fn build_wrap_fn(ccx: @mut CrateContext,
llshimfn: ValueRef,
llwrapfn: ValueRef,
tys: &ShimTypes) {
@ -1376,7 +1376,7 @@ pub fn trans_foreign_fn(ccx: @CrateContext,
build_wrap_fn(ccx, llshimfn, llwrapfn, &tys)
}
pub fn register_foreign_fn(ccx: @CrateContext,
pub fn register_foreign_fn(ccx: @mut CrateContext,
sp: span,
path: ast_map::path,
node_id: ast::node_id,

View File

@ -156,7 +156,7 @@ pub fn free_ty_immediate(bcx: block, v: ValueRef, t: ty::t) -> block {
}
}
pub fn lazily_emit_all_tydesc_glue(ccx: @CrateContext,
pub fn lazily_emit_all_tydesc_glue(ccx: @mut CrateContext,
static_ti: @mut tydesc_info) {
lazily_emit_tydesc_glue(ccx, abi::tydesc_field_take_glue, static_ti);
lazily_emit_tydesc_glue(ccx, abi::tydesc_field_drop_glue, static_ti);
@ -218,7 +218,7 @@ pub fn simplified_glue_type(tcx: ty::ctxt, field: uint, t: ty::t) -> ty::t {
return t;
}
pub fn lazily_emit_simplified_tydesc_glue(ccx: @CrateContext,
pub fn lazily_emit_simplified_tydesc_glue(ccx: @mut CrateContext,
field: uint,
ti: @mut tydesc_info) -> bool {
let _icx = ccx.insn_ctxt("lazily_emit_simplified_tydesc_glue");
@ -243,7 +243,7 @@ pub fn lazily_emit_simplified_tydesc_glue(ccx: @CrateContext,
}
pub fn lazily_emit_tydesc_glue(ccx: @CrateContext,
pub fn lazily_emit_tydesc_glue(ccx: @mut CrateContext,
field: uint,
ti: @mut tydesc_info) {
let _icx = ccx.insn_ctxt("lazily_emit_tydesc_glue");
@ -624,7 +624,7 @@ pub fn incr_refcnt_of_boxed(cx: block, box_ptr: ValueRef) {
// Chooses the addrspace for newly declared types.
pub fn declare_tydesc_addrspace(ccx: @CrateContext, t: ty::t) -> addrspace {
pub fn declare_tydesc_addrspace(ccx: &CrateContext, t: ty::t) -> addrspace {
if !ty::type_needs_drop(ccx.tcx, t) {
return default_addrspace;
} else if ty::type_is_immediate(t) {
@ -638,11 +638,10 @@ pub fn declare_tydesc_addrspace(ccx: @CrateContext, t: ty::t) -> addrspace {
}
// Generates the declaration for (but doesn't emit) a type descriptor.
pub fn declare_tydesc(ccx: @CrateContext, t: ty::t) -> @mut tydesc_info {
let _icx = ccx.insn_ctxt("declare_tydesc");
pub fn declare_tydesc(ccx: &mut CrateContext, t: ty::t) -> @mut tydesc_info {
// If emit_tydescs already ran, then we shouldn't be creating any new
// tydescs.
assert!(!*ccx.finished_tydescs);
assert!(!ccx.finished_tydescs);
let llty = type_of(ccx, t);
@ -680,7 +679,7 @@ pub fn declare_tydesc(ccx: @CrateContext, t: ty::t) -> @mut tydesc_info {
pub type glue_helper = @fn(block, ValueRef, ty::t);
pub fn declare_generic_glue(ccx: @CrateContext, t: ty::t, llfnty: TypeRef,
pub fn declare_generic_glue(ccx: @mut CrateContext, t: ty::t, llfnty: TypeRef,
name: ~str) -> ValueRef {
let _icx = ccx.insn_ctxt("declare_generic_glue");
let name = name;
@ -692,7 +691,7 @@ pub fn declare_generic_glue(ccx: @CrateContext, t: ty::t, llfnty: TypeRef,
return llfn;
}
pub fn make_generic_glue_inner(ccx: @CrateContext,
pub fn make_generic_glue_inner(ccx: @mut CrateContext,
t: ty::t,
llfn: ValueRef,
helper: glue_helper)
@ -717,7 +716,7 @@ pub fn make_generic_glue_inner(ccx: @CrateContext,
return llfn;
}
pub fn make_generic_glue(ccx: @CrateContext,
pub fn make_generic_glue(ccx: @mut CrateContext,
t: ty::t,
llfn: ValueRef,
helper: glue_helper,
@ -738,12 +737,13 @@ pub fn make_generic_glue(ccx: @CrateContext,
return llval;
}
pub fn emit_tydescs(ccx: @CrateContext) {
let _icx = ccx.insn_ctxt("emit_tydescs");
pub fn emit_tydescs(ccx: &mut CrateContext) {
//let _icx = ccx.insn_ctxt("emit_tydescs");
// As of this point, allow no more tydescs to be created.
*ccx.finished_tydescs = true;
for ccx.tydescs.each_value |&val| {
let glue_fn_ty = T_ptr(T_generic_glue_fn(ccx));
ccx.finished_tydescs = true;
let glue_fn_ty = T_ptr(T_generic_glue_fn(ccx));
let tyds = &mut ccx.tydescs;
for tyds.each_value |&val| {
let ti = val;
// Each of the glue functions needs to be cast to a generic type

View File

@ -27,7 +27,7 @@ use syntax::ast_util::local_def;
// `translate` will be true if this function is allowed to translate the
// item and false otherwise. Currently, this parameter is set to false when
// translating default methods.
pub fn maybe_instantiate_inline(ccx: @CrateContext, fn_id: ast::def_id,
pub fn maybe_instantiate_inline(ccx: @mut CrateContext, fn_id: ast::def_id,
translate: bool)
-> ast::def_id {
let _icx = ccx.insn_ctxt("maybe_instantiate_inline");

View File

@ -22,7 +22,7 @@ use util::ppaux::ty_to_str;
// compute sizeof / alignof
// Returns the number of bytes clobbered by a Store to this type.
pub fn llsize_of_store(cx: @CrateContext, t: TypeRef) -> uint {
pub fn llsize_of_store(cx: &CrateContext, t: TypeRef) -> uint {
unsafe {
return llvm::LLVMStoreSizeOfType(cx.td.lltd, t) as uint;
}
@ -30,7 +30,7 @@ pub fn llsize_of_store(cx: @CrateContext, t: TypeRef) -> uint {
// Returns the number of bytes between successive elements of type T in an
// array of T. This is the "ABI" size. It includes any ABI-mandated padding.
pub fn llsize_of_alloc(cx: @CrateContext, t: TypeRef) -> uint {
pub fn llsize_of_alloc(cx: &CrateContext, t: TypeRef) -> uint {
unsafe {
return llvm::LLVMABISizeOfType(cx.td.lltd, t) as uint;
}
@ -44,7 +44,7 @@ pub fn llsize_of_alloc(cx: @CrateContext, t: TypeRef) -> uint {
// that LLVM *does* distinguish between e.g. a 1-bit value and an 8-bit value
// at the codegen level! In general you should prefer `llbitsize_of_real`
// below.
pub fn llsize_of_real(cx: @CrateContext, t: TypeRef) -> uint {
pub fn llsize_of_real(cx: &CrateContext, t: TypeRef) -> uint {
unsafe {
let nbits = llvm::LLVMSizeOfTypeInBits(cx.td.lltd, t) as uint;
if nbits & 7u != 0u {
@ -57,14 +57,14 @@ pub fn llsize_of_real(cx: @CrateContext, t: TypeRef) -> uint {
}
/// Returns the "real" size of the type in bits.
pub fn llbitsize_of_real(cx: @CrateContext, t: TypeRef) -> uint {
pub fn llbitsize_of_real(cx: &CrateContext, t: TypeRef) -> uint {
unsafe {
llvm::LLVMSizeOfTypeInBits(cx.td.lltd, t) as uint
}
}
/// Returns the size of the type as an LLVM constant integer value.
pub fn llsize_of(cx: @CrateContext, t: TypeRef) -> ValueRef {
pub fn llsize_of(cx: &CrateContext, t: TypeRef) -> ValueRef {
// Once upon a time, this called LLVMSizeOf, which does a
// getelementptr(1) on a null pointer and casts to an int, in
// order to obtain the type size as a value without requiring the
@ -78,7 +78,7 @@ pub fn llsize_of(cx: @CrateContext, t: TypeRef) -> ValueRef {
// Returns the "default" size of t (see above), or 1 if the size would
// be zero. This is important for things like vectors that expect
// space to be consumed.
pub fn nonzero_llsize_of(cx: @CrateContext, t: TypeRef) -> ValueRef {
pub fn nonzero_llsize_of(cx: &CrateContext, t: TypeRef) -> ValueRef {
if llbitsize_of_real(cx, t) == 0 {
unsafe { llvm::LLVMConstInt(cx.int_type, 1, False) }
} else {
@ -90,7 +90,7 @@ pub fn nonzero_llsize_of(cx: @CrateContext, t: TypeRef) -> ValueRef {
// The preferred alignment may be larger than the alignment used when
// packing the type into structs. This will be used for things like
// allocations inside a stack frame, which LLVM has a free hand in.
pub fn llalign_of_pref(cx: @CrateContext, t: TypeRef) -> uint {
pub fn llalign_of_pref(cx: &CrateContext, t: TypeRef) -> uint {
unsafe {
return llvm::LLVMPreferredAlignmentOfType(cx.td.lltd, t) as uint;
}
@ -99,7 +99,7 @@ pub fn llalign_of_pref(cx: @CrateContext, t: TypeRef) -> uint {
// Returns the minimum alignment of a type required by the platform.
// This is the alignment that will be used for struct fields, arrays,
// and similar ABI-mandated things.
pub fn llalign_of_min(cx: @CrateContext, t: TypeRef) -> uint {
pub fn llalign_of_min(cx: &CrateContext, t: TypeRef) -> uint {
unsafe {
return llvm::LLVMABIAlignmentOfType(cx.td.lltd, t) as uint;
}
@ -108,7 +108,7 @@ pub fn llalign_of_min(cx: @CrateContext, t: TypeRef) -> uint {
// Returns the "default" alignment of t, which is calculated by casting
// null to a record containing a single-bit followed by a t value, then
// doing gep(0,1) to get at the trailing (and presumably padded) t cell.
pub fn llalign_of(cx: @CrateContext, t: TypeRef) -> ValueRef {
pub fn llalign_of(cx: &CrateContext, t: TypeRef) -> ValueRef {
unsafe {
return llvm::LLVMConstIntCast(
llvm::LLVMAlignOf(t), cx.int_type, False);
@ -116,7 +116,7 @@ pub fn llalign_of(cx: @CrateContext, t: TypeRef) -> ValueRef {
}
// Computes the size of the data part of an enum.
pub fn static_size_of_enum(cx: @CrateContext, t: ty::t) -> uint {
pub fn static_size_of_enum(cx: &mut CrateContext, t: ty::t) -> uint {
if cx.enum_sizes.contains_key(&t) {
return cx.enum_sizes.get_copy(&t);
}

View File

@ -42,7 +42,7 @@ for non-monomorphized methods only. Other methods will
be generated once they are invoked with specific type parameters,
see `trans::base::lval_static_fn()` or `trans::base::monomorphic_fn()`.
*/
pub fn trans_impl(ccx: @CrateContext,
pub fn trans_impl(ccx: @mut CrateContext,
path: path,
name: ast::ident,
methods: &[@ast::method],
@ -102,7 +102,7 @@ Translates a (possibly monomorphized) method body.
- `llfn`: the LLVM ValueRef for the method
- `impl_id`: the node ID of the impl this method is inside
*/
pub fn trans_method(ccx: @CrateContext,
pub fn trans_method(ccx: @mut CrateContext,
path: path,
method: &ast::method,
param_substs: Option<@param_substs>,
@ -378,7 +378,7 @@ pub fn method_from_methods(ms: &[@ast::method], name: ast::ident)
ms.find(|m| m.ident == name).map(|m| ast_util::local_def(m.id))
}
pub fn method_with_name_or_default(ccx: @CrateContext,
pub fn method_with_name_or_default(ccx: @mut CrateContext,
impl_id: ast::def_id,
name: ast::ident) -> ast::def_id {
*do ccx.impl_method_cache.find_or_insert_with((impl_id, name)) |_| {
@ -415,7 +415,7 @@ pub fn method_with_name_or_default(ccx: @CrateContext,
}
}
pub fn method_ty_param_count(ccx: @CrateContext, m_id: ast::def_id,
pub fn method_ty_param_count(ccx: &CrateContext, m_id: ast::def_id,
i_id: ast::def_id) -> uint {
debug!("method_ty_param_count: m_id: %?, i_id: %?", m_id, i_id);
if m_id.crate == ast::local_crate {
@ -734,7 +734,7 @@ pub fn trans_trait_callee_from_llval(bcx: block,
};
}
pub fn vtable_id(ccx: @CrateContext,
pub fn vtable_id(ccx: @mut CrateContext,
origin: &typeck::vtable_origin)
-> mono_id {
match origin {
@ -778,7 +778,7 @@ pub fn get_vtable(bcx: block,
}
/// Helper function to declare and initialize the vtable.
pub fn make_vtable(ccx: @CrateContext,
pub fn make_vtable(ccx: @mut CrateContext,
tydesc: @mut tydesc_info,
ptrs: &[ValueRef])
-> ValueRef {

View File

@ -40,7 +40,7 @@ use syntax::ast_util::local_def;
use syntax::opt_vec;
use syntax::abi::AbiSet;
pub fn monomorphic_fn(ccx: @CrateContext,
pub fn monomorphic_fn(ccx: @mut CrateContext,
fn_id: ast::def_id,
real_substs: &ty::substs,
vtables: Option<typeck::vtable_res>,
@ -329,7 +329,7 @@ pub fn normalize_for_monomorphization(tcx: ty::ctxt,
}
}
pub fn make_mono_id(ccx: @CrateContext,
pub fn make_mono_id(ccx: @mut CrateContext,
item: ast::def_id,
substs: &[ty::t],
vtables: Option<typeck::vtable_res>,

View File

@ -151,8 +151,7 @@ impl Reflector {
// Entrypoint
pub fn visit_ty(&mut self, t: ty::t) {
let bcx = self.bcx;
debug!("reflect::visit_ty %s",
ty_to_str(bcx.ccx().tcx, t));
debug!("reflect::visit_ty %s", ty_to_str(bcx.ccx().tcx, t));
match ty::get(t).sty {
ty::ty_bot => self.leaf(~"bot"),
@ -312,16 +311,17 @@ impl Reflector {
+ self.c_size_and_align(t);
do self.bracketed(~"enum", enum_args) |this| {
for variants.eachi |i, v| {
let name = ccx.sess.str_of(v.name);
let variant_args = ~[this.c_uint(i),
this.c_int(v.disr_val),
this.c_uint(v.args.len()),
this.c_slice(ccx.sess.str_of(v.name))];
this.c_slice(name)];
do this.bracketed(~"enum_variant", variant_args) |this| {
for v.args.eachi |j, a| {
let bcx = this.bcx;
let null = C_null(llptrty);
let offset = p2i(ccx, adt::trans_field_ptr(bcx, repr, null,
v.disr_val, j));
let ptr = adt::trans_field_ptr(bcx, repr, null, v.disr_val, j);
let offset = p2i(ccx, ptr);
let field_args = ~[this.c_uint(j),
offset,
this.c_tydesc(*a)];

View File

@ -25,8 +25,8 @@ pub struct Ctxt {
pad2: u32
}
pub fn mk_global(ccx: @CrateContext,
name: ~str,
pub fn mk_global(ccx: &CrateContext,
name: &str,
llval: ValueRef,
internal: bool)
-> ValueRef {

View File

@ -151,7 +151,7 @@ pub struct VecTypes {
}
impl VecTypes {
pub fn to_str(&self, ccx: @CrateContext) -> ~str {
pub fn to_str(&self, ccx: &CrateContext) -> ~str {
fmt!("VecTypes {vec_ty=%s, unit_ty=%s, llunit_ty=%s, llunit_size=%s}",
ty_to_str(ccx.tcx, self.vec_ty),
ty_to_str(ccx.tcx, self.unit_ty),

View File

@ -21,21 +21,21 @@ use util::ppaux;
use syntax::ast;
pub fn arg_is_indirect(_: @CrateContext, arg_ty: &ty::t) -> bool {
pub fn arg_is_indirect(_: &CrateContext, arg_ty: &ty::t) -> bool {
!ty::type_is_immediate(*arg_ty)
}
pub fn type_of_explicit_arg(ccx: @CrateContext, arg_ty: &ty::t) -> TypeRef {
pub fn type_of_explicit_arg(ccx: &mut CrateContext, arg_ty: &ty::t) -> TypeRef {
let llty = type_of(ccx, *arg_ty);
if arg_is_indirect(ccx, arg_ty) {T_ptr(llty)} else {llty}
}
pub fn type_of_explicit_args(ccx: @CrateContext,
pub fn type_of_explicit_args(ccx: &mut CrateContext,
inputs: &[ty::t]) -> ~[TypeRef] {
inputs.map(|arg_ty| type_of_explicit_arg(ccx, arg_ty))
}
pub fn type_of_fn(cx: @CrateContext, inputs: &[ty::t], output: ty::t)
pub fn type_of_fn(cx: &mut CrateContext, inputs: &[ty::t], output: ty::t)
-> TypeRef {
unsafe {
let mut atys: ~[TypeRef] = ~[];
@ -64,7 +64,7 @@ pub fn type_of_fn(cx: @CrateContext, inputs: &[ty::t], output: ty::t)
}
// Given a function type and a count of ty params, construct an llvm type
pub fn type_of_fn_from_ty(cx: @CrateContext, fty: ty::t) -> TypeRef {
pub fn type_of_fn_from_ty(cx: &mut CrateContext, fty: ty::t) -> TypeRef {
match ty::get(fty).sty {
ty::ty_closure(ref f) => type_of_fn(cx, f.sig.inputs, f.sig.output),
ty::ty_bare_fn(ref f) => type_of_fn(cx, f.sig.inputs, f.sig.output),
@ -74,7 +74,7 @@ pub fn type_of_fn_from_ty(cx: @CrateContext, fty: ty::t) -> TypeRef {
}
}
pub fn type_of_non_gc_box(cx: @CrateContext, t: ty::t) -> TypeRef {
pub fn type_of_non_gc_box(cx: &mut CrateContext, t: ty::t) -> TypeRef {
assert!(!ty::type_needs_infer(t));
let t_norm = ty::normalize_ty(cx.tcx, t);
@ -83,10 +83,12 @@ pub fn type_of_non_gc_box(cx: @CrateContext, t: ty::t) -> TypeRef {
} else {
match ty::get(t).sty {
ty::ty_box(mt) => {
T_ptr(T_box(cx, type_of(cx, mt.ty)))
let ty = type_of(cx, mt.ty);
T_ptr(T_box(cx, ty))
}
ty::ty_uniq(mt) => {
T_ptr(T_unique(cx, type_of(cx, mt.ty)))
let ty = type_of(cx, mt.ty);
T_ptr(T_unique(cx, ty))
}
_ => {
cx.sess.bug("non-box in type_of_non_gc_box");
@ -107,7 +109,7 @@ pub fn type_of_non_gc_box(cx: @CrateContext, t: ty::t) -> TypeRef {
// recursive types. For example, `static_size_of_enum()` relies on this
// behavior.
pub fn sizing_type_of(cx: @CrateContext, t: ty::t) -> TypeRef {
pub fn sizing_type_of(cx: &mut CrateContext, t: ty::t) -> TypeRef {
match cx.llsizingtypes.find(&t) {
Some(t) => return *t,
None => ()
@ -146,7 +148,10 @@ pub fn sizing_type_of(cx: @CrateContext, t: ty::t) -> TypeRef {
T_array(sizing_type_of(cx, mt.ty), size)
}
ty::ty_unboxed_vec(mt) => T_vec(cx, sizing_type_of(cx, mt.ty)),
ty::ty_unboxed_vec(mt) => {
let sz_ty = sizing_type_of(cx, mt.ty);
T_vec(cx, sz_ty)
}
ty::ty_tup(*) | ty::ty_enum(*) => {
let repr = adt::represent_type(cx, t);
@ -177,7 +182,7 @@ pub fn sizing_type_of(cx: @CrateContext, t: ty::t) -> TypeRef {
}
// NB: If you update this, be sure to update `sizing_type_of()` as well.
pub fn type_of(cx: @CrateContext, t: ty::t) -> TypeRef {
pub fn type_of(cx: &mut CrateContext, t: ty::t) -> TypeRef {
debug!("type_of %?: %?", t, ty::get(t));
// Check the cache.
@ -223,22 +228,35 @@ pub fn type_of(cx: @CrateContext, t: ty::t) -> TypeRef {
T_box_ptr(T_box(cx, T_vec(cx, T_i8())))
}
ty::ty_evec(ref mt, ty::vstore_box) => {
T_box_ptr(T_box(cx, T_vec(cx, type_of(cx, mt.ty))))
let e_ty = type_of(cx, mt.ty);
let v_ty = T_vec(cx, e_ty);
T_box_ptr(T_box(cx, v_ty))
}
ty::ty_box(ref mt) => {
let ty = type_of(cx, mt.ty);
T_box_ptr(T_box(cx, ty))
}
ty::ty_box(ref mt) => T_box_ptr(T_box(cx, type_of(cx, mt.ty))),
ty::ty_opaque_box => T_box_ptr(T_box(cx, T_i8())),
ty::ty_uniq(ref mt) => T_unique_ptr(T_unique(cx, type_of(cx, mt.ty))),
ty::ty_uniq(ref mt) => {
let ty = type_of(cx, mt.ty);
T_unique_ptr(T_unique(cx, ty))
}
ty::ty_evec(ref mt, ty::vstore_uniq) => {
T_unique_ptr(T_unique(cx, T_vec(cx, type_of(cx, mt.ty))))
let ty = type_of(cx, mt.ty);
let ty = T_vec(cx, ty);
T_unique_ptr(T_unique(cx, ty))
}
ty::ty_unboxed_vec(ref mt) => {
T_vec(cx, type_of(cx, mt.ty))
let ty = type_of(cx, mt.ty);
T_vec(cx, ty)
}
ty::ty_ptr(ref mt) => T_ptr(type_of(cx, mt.ty)),
ty::ty_rptr(_, ref mt) => T_ptr(type_of(cx, mt.ty)),
ty::ty_evec(ref mt, ty::vstore_slice(_)) => {
T_struct([T_ptr(type_of(cx, mt.ty)), T_uint_ty(cx, ast::ty_u)], false)
let p_ty = T_ptr(type_of(cx, mt.ty));
let u_ty = T_uint_ty(cx, ast::ty_u);
T_struct([p_ty, u_ty], false)
}
ty::ty_estr(ty::vstore_slice(_)) => {
@ -254,7 +272,10 @@ pub fn type_of(cx: @CrateContext, t: ty::t) -> TypeRef {
}
ty::ty_bare_fn(_) => T_ptr(type_of_fn_from_ty(cx, t)),
ty::ty_closure(_) => T_fn_pair(cx, type_of_fn_from_ty(cx, t)),
ty::ty_closure(_) => {
let ty = type_of_fn_from_ty(cx, t);
T_fn_pair(cx, ty)
}
ty::ty_trait(_, _, store, _) => T_opaque_trait(cx, store),
ty::ty_type => T_ptr(cx.tydesc_type),
ty::ty_tup(*) => {
@ -310,7 +331,7 @@ pub fn type_of(cx: @CrateContext, t: ty::t) -> TypeRef {
// Want refinements! (Or case classes, I guess
pub enum named_ty { a_struct, an_enum }
pub fn llvm_type_name(cx: @CrateContext,
pub fn llvm_type_name(cx: &CrateContext,
what: named_ty,
did: ast::def_id,
tps: &[ty::t]) -> ~str {
@ -330,18 +351,18 @@ pub fn llvm_type_name(cx: @CrateContext,
);
}
pub fn type_of_dtor(ccx: @CrateContext, self_ty: ty::t) -> TypeRef {
pub fn type_of_dtor(ccx: &mut CrateContext, self_ty: ty::t) -> TypeRef {
T_fn([T_ptr(type_of(ccx, self_ty))] /* self */, T_nil())
}
pub fn type_of_rooted(ccx: @CrateContext, t: ty::t) -> TypeRef {
pub fn type_of_rooted(ccx: &mut CrateContext, t: ty::t) -> TypeRef {
let addrspace = base::get_tydesc(ccx, t).addrspace;
debug!("type_of_rooted %s in addrspace %u",
ppaux::ty_to_str(ccx.tcx, t), addrspace as uint);
return T_root(type_of(ccx, t), addrspace);
}
pub fn type_of_glue_fn(ccx: @CrateContext) -> TypeRef {
pub fn type_of_glue_fn(ccx: &CrateContext) -> TypeRef {
let tydescpp = T_ptr(T_ptr(ccx.tydesc_type));
return T_fn([T_ptr(T_nil()), tydescpp, T_ptr(T_i8())], T_nil());
}

View File

@ -51,11 +51,11 @@ pub static use_repr: uint = 1; /* Dependency on size/alignment/mode and
pub static use_tydesc: uint = 2; /* Takes the tydesc, or compares */
pub struct Context {
ccx: @CrateContext,
ccx: @mut CrateContext,
uses: @mut ~[type_uses]
}
pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint)
pub fn type_uses_for(ccx: @mut CrateContext, fn_id: def_id, n_tps: uint)
-> @~[type_uses] {
match ccx.type_use_cache.find(&fn_id) {
Some(uses) => return *uses,