Skip to content

Commit b1f39ce

Browse files
AatchJames Miller
authored andcommitted
Move CrateContext into it's own file
1 parent 98b1c9e commit b1f39ce

File tree

4 files changed

+127
-81
lines changed

4 files changed

+127
-81
lines changed

src/librustc/back/link.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use lib::llvm::ModuleRef;
1818
use lib;
1919
use metadata::common::LinkMeta;
2020
use metadata::{encoder, csearch, cstore};
21-
use middle::trans::common::CrateContext;
21+
use middle::trans::context::CrateContext;
2222
use middle::ty;
2323
use util::ppaux;
2424

src/librustc/middle/trans/common.rs

Lines changed: 2 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ use syntax::parse::token;
5555
use syntax::{ast, ast_map};
5656
use syntax::abi::{X86, X86_64, Arm, Mips};
5757

58+
pub use middle::trans::context::CrateContext;
59+
5860
// NOTE: this thunk is totally pointless now that we're not passing
5961
// interners around...
6062
pub type namegen = @fn(s: &str) -> ident;
@@ -156,86 +158,6 @@ pub fn BuilderRef_res(B: BuilderRef) -> BuilderRef_res {
156158

157159
pub type ExternMap = @mut HashMap<@str, ValueRef>;
158160

159-
// Crate context. Every crate we compile has one of these.
160-
pub struct CrateContext {
161-
sess: session::Session,
162-
llmod: ModuleRef,
163-
llcx: ContextRef,
164-
td: TargetData,
165-
tn: @TypeNames,
166-
externs: ExternMap,
167-
intrinsics: HashMap<&'static str, ValueRef>,
168-
item_vals: @mut HashMap<ast::node_id, ValueRef>,
169-
exp_map2: resolve::ExportMap2,
170-
reachable: reachable::map,
171-
item_symbols: @mut HashMap<ast::node_id, ~str>,
172-
link_meta: LinkMeta,
173-
enum_sizes: @mut HashMap<ty::t, uint>,
174-
discrims: @mut HashMap<ast::def_id, ValueRef>,
175-
discrim_symbols: @mut HashMap<ast::node_id, @str>,
176-
tydescs: @mut HashMap<ty::t, @mut tydesc_info>,
177-
// Set when running emit_tydescs to enforce that no more tydescs are
178-
// created.
179-
finished_tydescs: @mut bool,
180-
// Track mapping of external ids to local items imported for inlining
181-
external: @mut HashMap<ast::def_id, Option<ast::node_id>>,
182-
// Cache instances of monomorphized functions
183-
monomorphized: @mut HashMap<mono_id, ValueRef>,
184-
monomorphizing: @mut HashMap<ast::def_id, uint>,
185-
// Cache computed type parameter uses (see type_use.rs)
186-
type_use_cache: @mut HashMap<ast::def_id, @~[type_use::type_uses]>,
187-
// Cache generated vtables
188-
vtables: @mut HashMap<mono_id, ValueRef>,
189-
// Cache of constant strings,
190-
const_cstr_cache: @mut HashMap<@str, ValueRef>,
191-
192-
// Reverse-direction for const ptrs cast from globals.
193-
// Key is an int, cast from a ValueRef holding a *T,
194-
// Val is a ValueRef holding a *[T].
195-
//
196-
// Needed because LLVM loses pointer->pointee association
197-
// when we ptrcast, and we have to ptrcast during translation
198-
// of a [T] const because we form a slice, a [*T,int] pair, not
199-
// a pointer to an LLVM array type.
200-
const_globals: @mut HashMap<int, ValueRef>,
201-
202-
// Cache of emitted const values
203-
const_values: @mut HashMap<ast::node_id, ValueRef>,
204-
205-
// Cache of external const values
206-
extern_const_values: @mut HashMap<ast::def_id, ValueRef>,
207-
208-
impl_method_cache: @mut HashMap<(ast::def_id, ast::ident), ast::def_id>,
209-
210-
module_data: @mut HashMap<~str, ValueRef>,
211-
lltypes: @mut HashMap<ty::t, TypeRef>,
212-
llsizingtypes: @mut HashMap<ty::t, TypeRef>,
213-
adt_reprs: @mut HashMap<ty::t, @adt::Repr>,
214-
names: namegen,
215-
next_addrspace: addrspace_gen,
216-
symbol_hasher: @mut hash::State,
217-
type_hashcodes: @mut HashMap<ty::t, @str>,
218-
type_short_names: @mut HashMap<ty::t, ~str>,
219-
all_llvm_symbols: @mut HashSet<@str>,
220-
tcx: ty::ctxt,
221-
maps: astencode::Maps,
222-
stats: @mut Stats,
223-
upcalls: @upcall::Upcalls,
224-
tydesc_type: TypeRef,
225-
int_type: TypeRef,
226-
float_type: TypeRef,
227-
opaque_vec_type: TypeRef,
228-
builder: BuilderRef_res,
229-
shape_cx: shape::Ctxt,
230-
crate_map: ValueRef,
231-
// Set when at least one function uses GC. Needed so that
232-
// decl_gc_metadata knows whether to link to the module metadata, which
233-
// is not emitted by LLVM's GC pass when no functions use GC.
234-
uses_gc: @mut bool,
235-
dbg_cx: Option<debuginfo::DebugContext>,
236-
do_not_commit_warning_issued: @mut bool
237-
}
238-
239161
// Types used for llself.
240162
pub struct ValSelfData {
241163
v: ValueRef,

src/librustc/middle/trans/context.rs

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
use core::prelude::*;
2+
3+
use back::{abi, upcall};
4+
use driver::session;
5+
use driver::session::Session;
6+
use lib::llvm::{ModuleRef, ValueRef, TypeRef, BasicBlockRef, BuilderRef};
7+
use lib::llvm::{ContextRef, True, False, Bool};
8+
use lib::llvm::{llvm, TargetData, TypeNames, associate_type, name_has_type};
9+
use lib;
10+
use metadata::common::LinkMeta;
11+
use middle::astencode;
12+
use middle::resolve;
13+
use middle::trans::adt;
14+
use middle::trans::base;
15+
use middle::trans::build;
16+
use middle::trans::datum;
17+
use middle::trans::debuginfo;
18+
use middle::trans::glue;
19+
use middle::trans::reachable;
20+
use middle::trans::shape;
21+
use middle::trans::type_of;
22+
use middle::trans::type_use;
23+
use middle::trans::write_guard;
24+
use middle::ty::substs;
25+
use middle::ty;
26+
use middle::typeck;
27+
use middle::borrowck::root_map_key;
28+
29+
use core::cast::transmute;
30+
use core::cast;
31+
use core::hash;
32+
use core::hashmap::{HashMap, HashSet};
33+
use core::libc::{c_uint, c_longlong, c_ulonglong};
34+
use core::str;
35+
use core::to_bytes;
36+
use core::vec::raw::to_ptr;
37+
use core::vec;
38+
use syntax::ast::ident;
39+
use syntax::ast_map::{path, path_elt};
40+
use syntax::codemap::span;
41+
use syntax::parse::token;
42+
use syntax::{ast, ast_map};
43+
use syntax::abi::{X86, X86_64, Arm, Mips};
44+
45+
use middle::trans::common::{ExternMap,tydesc_info,BuilderRef_res,Stats,namegen,addrspace_gen};
46+
use middle::trans::common::{mono_id};
47+
48+
pub struct CrateContext {
49+
sess: session::Session,
50+
llmod: ModuleRef,
51+
llcx: ContextRef,
52+
td: TargetData,
53+
tn: @TypeNames,
54+
externs: ExternMap,
55+
intrinsics: HashMap<&'static str, ValueRef>,
56+
item_vals: @mut HashMap<ast::node_id, ValueRef>,
57+
exp_map2: resolve::ExportMap2,
58+
reachable: reachable::map,
59+
item_symbols: @mut HashMap<ast::node_id, ~str>,
60+
link_meta: LinkMeta,
61+
enum_sizes: @mut HashMap<ty::t, uint>,
62+
discrims: @mut HashMap<ast::def_id, ValueRef>,
63+
discrim_symbols: @mut HashMap<ast::node_id, @str>,
64+
tydescs: @mut HashMap<ty::t, @mut tydesc_info>,
65+
// Set when running emit_tydescs to enforce that no more tydescs are
66+
// created.
67+
finished_tydescs: @mut bool,
68+
// Track mapping of external ids to local items imported for inlining
69+
external: @mut HashMap<ast::def_id, Option<ast::node_id>>,
70+
// Cache instances of monomorphized functions
71+
monomorphized: @mut HashMap<mono_id, ValueRef>,
72+
monomorphizing: @mut HashMap<ast::def_id, uint>,
73+
// Cache computed type parameter uses (see type_use.rs)
74+
type_use_cache: @mut HashMap<ast::def_id, @~[type_use::type_uses]>,
75+
// Cache generated vtables
76+
vtables: @mut HashMap<mono_id, ValueRef>,
77+
// Cache of constant strings,
78+
const_cstr_cache: @mut HashMap<@str, ValueRef>,
79+
80+
// Reverse-direction for const ptrs cast from globals.
81+
// Key is an int, cast from a ValueRef holding a *T,
82+
// Val is a ValueRef holding a *[T].
83+
//
84+
// Needed because LLVM loses pointer->pointee association
85+
// when we ptrcast, and we have to ptrcast during translation
86+
// of a [T] const because we form a slice, a [*T,int] pair, not
87+
// a pointer to an LLVM array type.
88+
const_globals: @mut HashMap<int, ValueRef>,
89+
90+
// Cache of emitted const values
91+
const_values: @mut HashMap<ast::node_id, ValueRef>,
92+
93+
// Cache of external const values
94+
extern_const_values: @mut HashMap<ast::def_id, ValueRef>,
95+
96+
module_data: @mut HashMap<~str, ValueRef>,
97+
lltypes: @mut HashMap<ty::t, TypeRef>,
98+
llsizingtypes: @mut HashMap<ty::t, TypeRef>,
99+
adt_reprs: @mut HashMap<ty::t, @adt::Repr>,
100+
names: namegen,
101+
next_addrspace: addrspace_gen,
102+
symbol_hasher: @mut hash::State,
103+
type_hashcodes: @mut HashMap<ty::t, @str>,
104+
type_short_names: @mut HashMap<ty::t, ~str>,
105+
all_llvm_symbols: @mut HashSet<@str>,
106+
tcx: ty::ctxt,
107+
maps: astencode::Maps,
108+
stats: @mut Stats,
109+
upcalls: @upcall::Upcalls,
110+
tydesc_type: TypeRef,
111+
int_type: TypeRef,
112+
float_type: TypeRef,
113+
opaque_vec_type: TypeRef,
114+
builder: BuilderRef_res,
115+
shape_cx: shape::Ctxt,
116+
crate_map: ValueRef,
117+
// Set when at least one function uses GC. Needed so that
118+
// decl_gc_metadata knows whether to link to the module metadata, which
119+
// is not emitted by LLVM's GC pass when no functions use GC.
120+
uses_gc: @mut bool,
121+
dbg_cx: Option<debuginfo::DebugContext>,
122+
do_not_commit_warning_issued: @mut bool
123+
}

src/librustc/middle/trans/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub mod write_guard;
1818
pub mod callee;
1919
pub mod expr;
2020
pub mod common;
21+
pub mod context;
2122
pub mod consts;
2223
pub mod type_of;
2324
pub mod build;

0 commit comments

Comments
 (0)