Skip to content

Commit b23ecd4

Browse files
committed
Introduce metadata::cstore
I intend for this to be the location for storing all the data retrieved by creader, most of which is currently in the session.
1 parent c7bfef4 commit b23ecd4

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

src/comp/driver/rustc.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,9 @@ fn build_session_options(str binary, getopts::match match, str binary_dir) ->
352352

353353
fn build_session(@session::options sopts) -> session::session {
354354
auto target_cfg = build_target_config();
355+
auto cstore = metadata::cstore::mk_cstore();
355356
auto crate_cache = std::map::new_int_hash[session::crate_metadata]();
356-
ret session::session(target_cfg, sopts, crate_cache, [],
357+
ret session::session(target_cfg, sopts, cstore, crate_cache, [],
357358
[], [], codemap::new_codemap(), 0u);
358359
}
359360

src/comp/driver/session.rs

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type crate_metadata = rec(str name, vec[u8] data);
4545

4646
obj session(@config targ_cfg,
4747
@options opts,
48+
metadata::cstore::cstore cstore,
4849
map::hashmap[int, crate_metadata] crates,
4950
mutable vec[str] used_crate_files,
5051
mutable vec[str] used_libraries,
@@ -53,6 +54,7 @@ obj session(@config targ_cfg,
5354
mutable uint err_count) {
5455
fn get_targ_cfg() -> @config { ret targ_cfg; }
5556
fn get_opts() -> @options { ret opts; }
57+
fn get_cstore() -> metadata::cstore::cstore { cstore }
5658
fn span_fatal(span sp, str msg) -> ! {
5759
// FIXME: Use constants, but rustboot doesn't know how to export them.
5860
codemap::emit_error(some(sp), msg, cm);

src/comp/metadata/cstore.rs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import std::map;
2+
3+
type crate_metadata = rec(str name, vec[u8] data);
4+
5+
type cstore = @rec(map::hashmap[int, crate_metadata] metas,
6+
vec[str] used_crate_files,
7+
vec[str] used_libraries,
8+
vec[str] used_link_args);
9+
10+
fn mk_cstore() -> cstore {
11+
auto meta_cache = map::new_int_hash[crate_metadata]();
12+
ret @rec(metas = meta_cache,
13+
used_crate_files = [],
14+
used_libraries = [],
15+
used_link_args = []);
16+
}
17+
18+
fn get_crate_data(&cstore cstore, int cnum) -> crate_metadata {
19+
ret cstore.metas.get(cnum);
20+
}
21+
22+
fn set_crate_data(&cstore cstore, int cnum, &crate_metadata data) {
23+
cstore.metas.insert(cnum, data);
24+
}
25+
26+
fn have_crate_data(&cstore cstore, int cnum) -> bool {
27+
ret cstore.metas.contains_key(cnum);
28+
}
29+
30+
// Local Variables:
31+
// mode: rust
32+
// fill-column: 78;
33+
// indent-tabs-mode: nil
34+
// c-basic-offset: 4
35+
// buffer-file-coding-system: utf-8-unix
36+
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
37+
// End:

src/comp/rustc.rc

+2
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,15 @@ mod metadata {
8181
export encoder;
8282
export decoder;
8383
export creader;
84+
export cstore;
8485

8586
mod common;
8687
mod tyencode;
8788
mod tydecode;
8889
mod encoder;
8990
mod decoder;
9091
mod creader;
92+
mod cstore;
9193
}
9294

9395
mod driver {

0 commit comments

Comments
 (0)