Skip to content

Commit 279a229

Browse files
committed
Move metadata tag definition to metadata::defs
1 parent 6c23e09 commit 279a229

File tree

4 files changed

+77
-92
lines changed

4 files changed

+77
-92
lines changed

src/comp/metadata/creader.rs

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import std::option::none;
3030
import std::option::some;
3131
import std::os;
3232
import std::map::hashmap;
33+
import defs::*;
3334

3435
export get_symbol;
3536
export get_tag_variants;
@@ -404,15 +405,15 @@ fn parse_def_id(vec[u8] buf) -> ast::def_id {
404405

405406
fn lookup_hash(&ebml::doc d, fn(vec[u8]) -> bool eq_fn, uint hash) ->
406407
vec[ebml::doc] {
407-
auto index = ebml::get_doc(d, cwriter::tag_index);
408-
auto table = ebml::get_doc(index, cwriter::tag_index_table);
408+
auto index = ebml::get_doc(d, tag_index);
409+
auto table = ebml::get_doc(index, tag_index_table);
409410
auto hash_pos = table.start + hash % 256u * 4u;
410411
auto pos = ebml::be_uint_from_bytes(d.data, hash_pos, 4u);
411412
auto bucket = ebml::doc_at(d.data, pos);
412413
// Awkward logic because we can't ret from foreach yet
413414

414415
let vec[ebml::doc] result = [];
415-
auto belt = cwriter::tag_index_buckets_bucket_elt;
416+
auto belt = tag_index_buckets_bucket_elt;
416417
for each (ebml::doc elt in ebml::tagged_docs(bucket, belt)) {
417418
auto pos = ebml::be_uint_from_bytes(elt.data, elt.start, 4u);
418419
if (eq_fn(vec::slice[u8](elt.data, elt.start + 4u, elt.end))) {
@@ -431,11 +432,11 @@ fn resolve_path(vec[ast::ident] path, vec[u8] data) -> vec[ast::def_id] {
431432
}
432433
auto s = str::connect(path, "::");
433434
auto md = ebml::new_doc(data);
434-
auto paths = ebml::get_doc(md, cwriter::tag_paths);
435+
auto paths = ebml::get_doc(md, tag_paths);
435436
auto eqer = bind eq_item(_, s);
436437
let vec[ast::def_id] result = [];
437438
for (ebml::doc doc in lookup_hash(paths, eqer, cwriter::hash_path(s))) {
438-
auto did_doc = ebml::get_doc(doc, cwriter::tag_def_id);
439+
auto did_doc = ebml::get_doc(doc, tag_def_id);
439440
vec::push(result, parse_def_id(ebml::doc_data(did_doc)));
440441
}
441442
ret result;
@@ -460,22 +461,22 @@ fn find_item(int item_id, &ebml::doc items) -> ebml::doc {
460461
// Looks up an item in the given metadata and returns an ebml doc pointing
461462
// to the item data.
462463
fn lookup_item(int item_id, vec[u8] data) -> ebml::doc {
463-
auto items = ebml::get_doc(ebml::new_doc(data), cwriter::tag_items);
464+
auto items = ebml::get_doc(ebml::new_doc(data), tag_items);
464465
ret find_item(item_id, items);
465466
}
466467

467468
fn item_kind(&ebml::doc item) -> u8 {
468-
auto kind = ebml::get_doc(item, cwriter::tag_items_data_item_kind);
469+
auto kind = ebml::get_doc(item, tag_items_data_item_kind);
469470
ret ebml::doc_as_uint(kind) as u8;
470471
}
471472

472473
fn item_symbol(&ebml::doc item) -> str {
473-
auto sym = ebml::get_doc(item, cwriter::tag_items_data_item_symbol);
474+
auto sym = ebml::get_doc(item, tag_items_data_item_symbol);
474475
ret str::unsafe_from_bytes(ebml::doc_data(sym));
475476
}
476477

477478
fn variant_tag_id(&ebml::doc d) -> ast::def_id {
478-
auto tagdoc = ebml::get_doc(d, cwriter::tag_items_data_item_tag_id);
479+
auto tagdoc = ebml::get_doc(d, tag_items_data_item_tag_id);
479480
ret parse_def_id(ebml::doc_data(tagdoc));
480481
}
481482

@@ -490,15 +491,15 @@ fn item_type(&ebml::doc item, int this_cnum, ty::ctxt tcx) -> ty::t {
490491
auto external_def_id = parse_def_id(buf);
491492
ret tup(this_cnum, external_def_id._1);
492493
}
493-
auto tp = ebml::get_doc(item, cwriter::tag_items_data_item_type);
494+
auto tp = ebml::get_doc(item, tag_items_data_item_type);
494495
auto s = str::unsafe_from_bytes(ebml::doc_data(tp));
495496
ret parse_ty_data(item.data, this_cnum, tp.start, tp.end - tp.start,
496497
bind parse_external_def_id(this_cnum, _), tcx);
497498
}
498499

499500
fn item_ty_param_count(&ebml::doc item, int this_cnum) -> uint {
500501
let uint ty_param_count = 0u;
501-
auto tp = cwriter::tag_items_data_item_ty_param_count;
502+
auto tp = tag_items_data_item_ty_param_count;
502503
for each (ebml::doc p in ebml::tagged_docs(item, tp)) {
503504
ty_param_count = ebml::vint_at(ebml::doc_data(p), 0u)._0;
504505
}
@@ -507,7 +508,7 @@ fn item_ty_param_count(&ebml::doc item, int this_cnum) -> uint {
507508

508509
fn tag_variant_ids(&ebml::doc item, int this_cnum) -> vec[ast::def_id] {
509510
let vec[ast::def_id] ids = [];
510-
auto v = cwriter::tag_items_data_item_variant;
511+
auto v = tag_items_data_item_variant;
511512
for each (ebml::doc p in ebml::tagged_docs(item, v)) {
512513
auto ext = parse_def_id(ebml::doc_data(p));
513514
vec::push[ast::def_id](ids, tup(this_cnum, ext._1));
@@ -538,12 +539,12 @@ fn get_metadata_section(str filename) -> option::t[vec[u8]] {
538539
fn get_exported_metadata(&session::session sess, &str path, &vec[u8] data) ->
539540
hashmap[str, str] {
540541
auto meta_items =
541-
ebml::get_doc(ebml::new_doc(data), cwriter::tag_meta_export);
542+
ebml::get_doc(ebml::new_doc(data), tag_meta_export);
542543
auto mm = common::new_str_hash[str]();
543544
for each (ebml::doc m in
544-
ebml::tagged_docs(meta_items, cwriter::tag_meta_item)) {
545-
auto kd = ebml::get_doc(m, cwriter::tag_meta_item_key);
546-
auto vd = ebml::get_doc(m, cwriter::tag_meta_item_value);
545+
ebml::tagged_docs(meta_items, tag_meta_item)) {
546+
auto kd = ebml::get_doc(m, tag_meta_item_key);
547+
auto vd = ebml::get_doc(m, tag_meta_item_value);
547548
auto k = str::unsafe_from_bytes(ebml::doc_data(kd));
548549
auto v = str::unsafe_from_bytes(ebml::doc_data(vd));
549550
log #fmt("metadata in %s: %s = %s", path, k, v);
@@ -807,7 +808,7 @@ fn get_symbol(session::session sess, ast::def_id def) -> str {
807808
fn get_tag_variants(ty::ctxt tcx, ast::def_id def) -> vec[ty::variant_info] {
808809
auto external_crate_id = def._0;
809810
auto data = tcx.sess.get_external_crate(external_crate_id).data;
810-
auto items = ebml::get_doc(ebml::new_doc(data), cwriter::tag_items);
811+
auto items = ebml::get_doc(ebml::new_doc(data), tag_items);
811812
auto item = find_item(def._1, items);
812813
let vec[ty::variant_info] infos = [];
813814
auto variant_ids = tag_variant_ids(item, external_crate_id);
@@ -848,17 +849,17 @@ fn read_path(&ebml::doc d) -> tup(str, uint) {
848849

849850
fn list_crate_metadata(vec[u8] bytes, io::writer out) {
850851
auto md = ebml::new_doc(bytes);
851-
auto paths = ebml::get_doc(md, cwriter::tag_paths);
852-
auto items = ebml::get_doc(md, cwriter::tag_items);
853-
auto index = ebml::get_doc(paths, cwriter::tag_index);
854-
auto bs = ebml::get_doc(index, cwriter::tag_index_buckets);
852+
auto paths = ebml::get_doc(md, tag_paths);
853+
auto items = ebml::get_doc(md, tag_items);
854+
auto index = ebml::get_doc(paths, tag_index);
855+
auto bs = ebml::get_doc(index, tag_index_buckets);
855856
for each (ebml::doc bucket in
856-
ebml::tagged_docs(bs, cwriter::tag_index_buckets_bucket)) {
857-
auto et = cwriter::tag_index_buckets_bucket_elt;
857+
ebml::tagged_docs(bs, tag_index_buckets_bucket)) {
858+
auto et = tag_index_buckets_bucket_elt;
858859
for each (ebml::doc elt in ebml::tagged_docs(bucket, et)) {
859860
auto data = read_path(elt);
860861
auto def = ebml::doc_at(bytes, data._1);
861-
auto did_doc = ebml::get_doc(def, cwriter::tag_def_id);
862+
auto did_doc = ebml::get_doc(def, tag_def_id);
862863
auto did = parse_def_id(ebml::doc_data(did_doc));
863864
out.write_str(#fmt("%s (%s)\n", data._0,
864865
describe_def(items, did)));

src/comp/metadata/cwriter.rs

Lines changed: 1 addition & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -19,83 +19,16 @@ import pretty::ppaux::lit_to_str;
1919
import lib::llvm::llvm;
2020
import lib::llvm::llvm::ValueRef;
2121
import lib::llvm::False;
22+
import defs::*;
2223

2324
export ac_no_abbrevs;
2425
export def_to_str;
2526
export encode;
2627
export hash_def_id;
2728
export hash_path;
28-
export tag_def_id;
29-
export tag_index;
30-
export tag_index_table;
31-
export tag_index_buckets;
32-
export tag_index_buckets_bucket;
33-
export tag_index_buckets_bucket_elt;
34-
export tag_items;
35-
export tag_items_data_item_kind;
36-
export tag_items_data_item_symbol;
37-
export tag_items_data_item_tag_id;
38-
export tag_items_data_item_type;
39-
export tag_items_data_item_ty_param_count;
40-
export tag_items_data_item_variant;
41-
export tag_meta_export;
42-
export tag_meta_item;
43-
export tag_meta_item_key;
44-
export tag_meta_item_value;
45-
export tag_paths;
4629
export ty_abbrev;
4730
export write_metadata;
4831

49-
const uint tag_paths = 0x01u;
50-
51-
const uint tag_items = 0x02u;
52-
53-
const uint tag_paths_data = 0x03u;
54-
55-
const uint tag_paths_data_name = 0x04u;
56-
57-
const uint tag_paths_data_item = 0x05u;
58-
59-
const uint tag_paths_data_mod = 0x06u;
60-
61-
const uint tag_def_id = 0x07u;
62-
63-
const uint tag_items_data = 0x08u;
64-
65-
const uint tag_items_data_item = 0x09u;
66-
67-
const uint tag_items_data_item_kind = 0x0au;
68-
69-
const uint tag_items_data_item_ty_param_count = 0x0bu;
70-
71-
const uint tag_items_data_item_type = 0x0cu;
72-
73-
const uint tag_items_data_item_symbol = 0x0du;
74-
75-
const uint tag_items_data_item_variant = 0x0eu;
76-
77-
const uint tag_items_data_item_tag_id = 0x0fu;
78-
79-
const uint tag_index = 0x11u;
80-
81-
const uint tag_index_buckets = 0x12u;
82-
83-
const uint tag_index_buckets_bucket = 0x13u;
84-
85-
const uint tag_index_buckets_bucket_elt = 0x14u;
86-
87-
const uint tag_index_table = 0x15u;
88-
89-
const uint tag_meta_export = 0x16u;
90-
91-
const uint tag_meta_local = 0x17u;
92-
93-
const uint tag_meta_item = 0x18u;
94-
95-
const uint tag_meta_item_key = 0x19u;
96-
97-
const uint tag_meta_item_value = 0x20u;
98-
9932

10033
// Returns a Plain Old LLVM String:
10134
fn C_postr(&str s) -> ValueRef {

src/comp/metadata/defs.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
const uint tag_paths = 0x01u;
3+
4+
const uint tag_items = 0x02u;
5+
6+
const uint tag_paths_data = 0x03u;
7+
8+
const uint tag_paths_data_name = 0x04u;
9+
10+
const uint tag_paths_data_item = 0x05u;
11+
12+
const uint tag_paths_data_mod = 0x06u;
13+
14+
const uint tag_def_id = 0x07u;
15+
16+
const uint tag_items_data = 0x08u;
17+
18+
const uint tag_items_data_item = 0x09u;
19+
20+
const uint tag_items_data_item_kind = 0x0au;
21+
22+
const uint tag_items_data_item_ty_param_count = 0x0bu;
23+
24+
const uint tag_items_data_item_type = 0x0cu;
25+
26+
const uint tag_items_data_item_symbol = 0x0du;
27+
28+
const uint tag_items_data_item_variant = 0x0eu;
29+
30+
const uint tag_items_data_item_tag_id = 0x0fu;
31+
32+
const uint tag_index = 0x11u;
33+
34+
const uint tag_index_buckets = 0x12u;
35+
36+
const uint tag_index_buckets_bucket = 0x13u;
37+
38+
const uint tag_index_buckets_bucket_elt = 0x14u;
39+
40+
const uint tag_index_table = 0x15u;
41+
42+
const uint tag_meta_export = 0x16u;
43+
44+
const uint tag_meta_local = 0x17u;
45+
46+
const uint tag_meta_item = 0x18u;
47+
48+
const uint tag_meta_item_key = 0x19u;
49+
50+
const uint tag_meta_item_value = 0x20u;

src/comp/rustc.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ mod back {
6363
}
6464

6565
mod metadata {
66+
mod defs;
6667
mod tyencode;
6768
mod creader;
6869
mod cwriter;

0 commit comments

Comments
 (0)