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.
This commit is contained in:
Brian Anderson 2011-07-07 18:00:16 -07:00
parent c7bfef43c8
commit b23ecd47ce
4 changed files with 43 additions and 1 deletions

View File

@ -352,8 +352,9 @@ fn build_session_options(str binary, getopts::match match, str binary_dir) ->
fn build_session(@session::options sopts) -> session::session { fn build_session(@session::options sopts) -> session::session {
auto target_cfg = build_target_config(); auto target_cfg = build_target_config();
auto cstore = metadata::cstore::mk_cstore();
auto crate_cache = std::map::new_int_hash[session::crate_metadata](); auto crate_cache = std::map::new_int_hash[session::crate_metadata]();
ret session::session(target_cfg, sopts, crate_cache, [], ret session::session(target_cfg, sopts, cstore, crate_cache, [],
[], [], codemap::new_codemap(), 0u); [], [], codemap::new_codemap(), 0u);
} }

View File

@ -45,6 +45,7 @@ type crate_metadata = rec(str name, vec[u8] data);
obj session(@config targ_cfg, obj session(@config targ_cfg,
@options opts, @options opts,
metadata::cstore::cstore cstore,
map::hashmap[int, crate_metadata] crates, map::hashmap[int, crate_metadata] crates,
mutable vec[str] used_crate_files, mutable vec[str] used_crate_files,
mutable vec[str] used_libraries, mutable vec[str] used_libraries,
@ -53,6 +54,7 @@ obj session(@config targ_cfg,
mutable uint err_count) { mutable uint err_count) {
fn get_targ_cfg() -> @config { ret targ_cfg; } fn get_targ_cfg() -> @config { ret targ_cfg; }
fn get_opts() -> @options { ret opts; } fn get_opts() -> @options { ret opts; }
fn get_cstore() -> metadata::cstore::cstore { cstore }
fn span_fatal(span sp, str msg) -> ! { fn span_fatal(span sp, str msg) -> ! {
// FIXME: Use constants, but rustboot doesn't know how to export them. // FIXME: Use constants, but rustboot doesn't know how to export them.
codemap::emit_error(some(sp), msg, cm); codemap::emit_error(some(sp), msg, cm);

View File

@ -0,0 +1,37 @@
import std::map;
type crate_metadata = rec(str name, vec[u8] data);
type cstore = @rec(map::hashmap[int, crate_metadata] metas,
vec[str] used_crate_files,
vec[str] used_libraries,
vec[str] used_link_args);
fn mk_cstore() -> cstore {
auto meta_cache = map::new_int_hash[crate_metadata]();
ret @rec(metas = meta_cache,
used_crate_files = [],
used_libraries = [],
used_link_args = []);
}
fn get_crate_data(&cstore cstore, int cnum) -> crate_metadata {
ret cstore.metas.get(cnum);
}
fn set_crate_data(&cstore cstore, int cnum, &crate_metadata data) {
cstore.metas.insert(cnum, data);
}
fn have_crate_data(&cstore cstore, int cnum) -> bool {
ret cstore.metas.contains_key(cnum);
}
// Local Variables:
// mode: rust
// fill-column: 78;
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
// End:

View File

@ -81,6 +81,7 @@ mod metadata {
export encoder; export encoder;
export decoder; export decoder;
export creader; export creader;
export cstore;
mod common; mod common;
mod tyencode; mod tyencode;
@ -88,6 +89,7 @@ mod metadata {
mod encoder; mod encoder;
mod decoder; mod decoder;
mod creader; mod creader;
mod cstore;
} }
mod driver { mod driver {