2011-06-27 18:03:01 -05:00
|
|
|
// Metadata encoding
|
|
|
|
|
2011-08-15 18:38:23 -05:00
|
|
|
import std::vec;
|
2011-08-24 23:26:19 -05:00
|
|
|
import std::istr;
|
2011-06-27 17:20:17 -05:00
|
|
|
import std::uint;
|
2011-08-11 21:14:38 -05:00
|
|
|
import std::io;
|
2011-06-27 17:20:17 -05:00
|
|
|
import std::option;
|
|
|
|
import std::option::some;
|
|
|
|
import std::option::none;
|
2011-08-12 00:58:14 -05:00
|
|
|
import std::ebml;
|
2011-07-08 01:55:41 -05:00
|
|
|
import std::map;
|
2011-07-05 04:48:19 -05:00
|
|
|
import syntax::ast::*;
|
2011-08-21 23:44:41 -05:00
|
|
|
import syntax::ast_util;
|
|
|
|
import syntax::ast_util::local_def;
|
2011-07-07 14:22:39 -05:00
|
|
|
import common::*;
|
2011-07-21 19:27:34 -05:00
|
|
|
import middle::trans_common::crate_ctxt;
|
2011-06-27 17:20:17 -05:00
|
|
|
import middle::ty;
|
2011-07-07 12:10:10 -05:00
|
|
|
import middle::ty::node_id_to_monotype;
|
2011-06-30 01:42:35 -05:00
|
|
|
import front::attr;
|
2011-06-27 17:20:17 -05:00
|
|
|
|
|
|
|
export encode_metadata;
|
2011-07-07 14:56:01 -05:00
|
|
|
export encoded_ty;
|
2011-06-27 17:20:17 -05:00
|
|
|
|
2011-08-12 09:15:18 -05:00
|
|
|
type abbrev_map = map::hashmap<ty::t, tyencode::ty_abbrev>;
|
2011-07-08 01:55:41 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
type encode_ctxt = {ccx: @crate_ctxt, type_abbrevs: abbrev_map};
|
2011-07-08 01:55:41 -05:00
|
|
|
|
2011-06-27 17:20:17 -05:00
|
|
|
// Path table encoding
|
2011-08-25 00:13:16 -05:00
|
|
|
fn encode_name(ebml_w: &ebml::writer, name: &istr) {
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_paths_data_name);
|
2011-08-25 00:13:16 -05:00
|
|
|
ebml_w.writer.write(istr::bytes(name));
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
|
2011-08-12 00:58:14 -05:00
|
|
|
fn encode_def_id(ebml_w: &ebml::writer, id: &def_id) {
|
|
|
|
ebml::start_tag(ebml_w, tag_def_id);
|
2011-08-27 00:48:10 -05:00
|
|
|
ebml_w.writer.write(istr::bytes(def_to_str(id)));
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
|
2011-08-12 08:36:51 -05:00
|
|
|
type entry<T> = {val: T, pos: uint};
|
2011-07-26 07:06:02 -05:00
|
|
|
|
2011-08-12 00:58:14 -05:00
|
|
|
fn encode_tag_variant_paths(ebml_w: &ebml::writer, variants: &[variant],
|
2011-08-25 00:13:16 -05:00
|
|
|
path: &[istr], index: &mutable [entry<istr>]) {
|
2011-08-15 23:54:52 -05:00
|
|
|
for variant: variant in variants {
|
2011-08-25 19:00:12 -05:00
|
|
|
add_to_index(ebml_w, path, index, variant.node.name);
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_paths_data_item);
|
2011-08-25 19:00:12 -05:00
|
|
|
encode_name(ebml_w, variant.node.name);
|
2011-06-27 17:20:17 -05:00
|
|
|
encode_def_id(ebml_w, local_def(variant.node.id));
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-25 00:13:16 -05:00
|
|
|
fn add_to_index(ebml_w: &ebml::writer, path: &[istr],
|
|
|
|
index: &mutable [entry<istr>], name: &istr) {
|
2011-08-19 17:16:48 -05:00
|
|
|
let full_path = path + [name];
|
2011-07-27 07:19:39 -05:00
|
|
|
index +=
|
2011-08-25 00:13:16 -05:00
|
|
|
[{val: istr::connect(full_path, ~"::"), pos: ebml_w.writer.tell()}];
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
fn encode_native_module_item_paths(ebml_w: &ebml::writer, nmod: &native_mod,
|
2011-08-25 00:13:16 -05:00
|
|
|
path: &[istr],
|
|
|
|
index: &mutable [entry<istr>]) {
|
2011-08-15 23:54:52 -05:00
|
|
|
for nitem: @native_item in nmod.items {
|
2011-08-25 19:00:12 -05:00
|
|
|
add_to_index(ebml_w, path, index, nitem.ident);
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_paths_data_item);
|
2011-08-25 19:00:12 -05:00
|
|
|
encode_name(ebml_w, nitem.ident);
|
2011-06-27 17:20:17 -05:00
|
|
|
encode_def_id(ebml_w, local_def(nitem.id));
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-12 00:58:14 -05:00
|
|
|
fn encode_module_item_paths(ebml_w: &ebml::writer, module: &_mod,
|
2011-08-25 00:13:16 -05:00
|
|
|
path: &[istr], index: &mutable [entry<istr>]) {
|
2011-08-15 23:54:52 -05:00
|
|
|
for it: @item in module.items {
|
2011-08-21 23:44:41 -05:00
|
|
|
if !ast_util::is_exported(it.ident, module) { cont; }
|
2011-07-27 07:19:39 -05:00
|
|
|
alt it.node {
|
|
|
|
item_const(_, _) {
|
2011-08-25 19:00:12 -05:00
|
|
|
add_to_index(ebml_w, path, index, it.ident);
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_paths_data_item);
|
2011-08-25 19:00:12 -05:00
|
|
|
encode_name(ebml_w, it.ident);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_def_id(ebml_w, local_def(it.id));
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2011-08-05 13:38:06 -05:00
|
|
|
item_fn(_, tps) {
|
2011-08-25 19:00:12 -05:00
|
|
|
add_to_index(ebml_w, path, index, it.ident);
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_paths_data_item);
|
2011-08-25 19:00:12 -05:00
|
|
|
encode_name(ebml_w, it.ident);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_def_id(ebml_w, local_def(it.id));
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
item_mod(_mod) {
|
2011-08-25 19:00:12 -05:00
|
|
|
add_to_index(ebml_w, path, index, it.ident);
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_paths_data_mod);
|
2011-08-25 19:00:12 -05:00
|
|
|
encode_name(ebml_w, it.ident);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_def_id(ebml_w, local_def(it.id));
|
2011-08-25 00:13:16 -05:00
|
|
|
encode_module_item_paths(ebml_w, _mod,
|
2011-08-25 19:00:12 -05:00
|
|
|
path + [it.ident],
|
2011-08-25 00:13:16 -05:00
|
|
|
index);
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
item_native_mod(nmod) {
|
2011-08-25 19:00:12 -05:00
|
|
|
add_to_index(ebml_w, path, index, it.ident);
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_paths_data_mod);
|
2011-08-25 19:00:12 -05:00
|
|
|
encode_name(ebml_w, it.ident);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_def_id(ebml_w, local_def(it.id));
|
2011-08-25 00:13:16 -05:00
|
|
|
encode_native_module_item_paths(
|
|
|
|
ebml_w, nmod,
|
2011-08-25 19:00:12 -05:00
|
|
|
path + [it.ident],
|
2011-08-25 00:13:16 -05:00
|
|
|
index);
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
item_ty(_, tps) {
|
2011-08-25 19:00:12 -05:00
|
|
|
add_to_index(ebml_w, path, index, it.ident);
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_paths_data_item);
|
2011-08-25 19:00:12 -05:00
|
|
|
encode_name(ebml_w, it.ident);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_def_id(ebml_w, local_def(it.id));
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
item_res(_, _, tps, ctor_id) {
|
2011-08-25 19:00:12 -05:00
|
|
|
add_to_index(ebml_w, path, index, it.ident);
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_paths_data_item);
|
2011-08-25 19:00:12 -05:00
|
|
|
encode_name(ebml_w, it.ident);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_def_id(ebml_w, local_def(ctor_id));
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-08-25 19:00:12 -05:00
|
|
|
add_to_index(ebml_w, path, index, it.ident);
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_paths_data_item);
|
2011-08-25 19:00:12 -05:00
|
|
|
encode_name(ebml_w, it.ident);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_def_id(ebml_w, local_def(it.id));
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
item_tag(variants, tps) {
|
2011-08-25 19:00:12 -05:00
|
|
|
add_to_index(ebml_w, path, index, it.ident);
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_paths_data_item);
|
2011-08-25 19:00:12 -05:00
|
|
|
encode_name(ebml_w, it.ident);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_def_id(ebml_w, local_def(it.id));
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_tag_variant_paths(ebml_w, variants, path, index);
|
|
|
|
}
|
|
|
|
item_obj(_, tps, ctor_id) {
|
2011-08-25 19:00:12 -05:00
|
|
|
add_to_index(ebml_w, path, index, it.ident);
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_paths_data_item);
|
2011-08-25 19:00:12 -05:00
|
|
|
encode_name(ebml_w, it.ident);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_def_id(ebml_w, local_def(ctor_id));
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-08-25 19:00:12 -05:00
|
|
|
add_to_index(ebml_w, path, index, it.ident);
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_paths_data_item);
|
2011-08-25 19:00:12 -05:00
|
|
|
encode_name(ebml_w, it.ident);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_def_id(ebml_w, local_def(it.id));
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-25 00:13:16 -05:00
|
|
|
fn encode_item_paths(ebml_w: &ebml::writer, crate: &@crate) -> [entry<istr>] {
|
|
|
|
let index: [entry<istr>] = [];
|
|
|
|
let path: [istr] = [];
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_paths);
|
2011-06-27 17:20:17 -05:00
|
|
|
encode_module_item_paths(ebml_w, crate.node.module, path, index);
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-06-27 17:20:17 -05:00
|
|
|
ret index;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Item info table encoding
|
2011-08-12 00:58:14 -05:00
|
|
|
fn encode_family(ebml_w: &ebml::writer, c: u8) {
|
|
|
|
ebml::start_tag(ebml_w, tag_items_data_item_family);
|
2011-08-19 17:16:48 -05:00
|
|
|
ebml_w.writer.write([c]);
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
|
2011-08-12 00:58:14 -05:00
|
|
|
fn encode_inlineness(ebml_w: &ebml::writer, c: u8) {
|
|
|
|
ebml::start_tag(ebml_w, tag_items_data_item_inlineness);
|
2011-08-19 17:16:48 -05:00
|
|
|
ebml_w.writer.write([c]);
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-08-05 15:58:33 -05:00
|
|
|
}
|
|
|
|
|
2011-08-27 00:48:10 -05:00
|
|
|
fn def_to_str(did: &def_id) -> istr {
|
2011-08-28 02:24:28 -05:00
|
|
|
ret #ifmt["%d:%d", did.crate, did.node];
|
2011-08-27 00:48:10 -05:00
|
|
|
}
|
2011-06-27 17:20:17 -05:00
|
|
|
|
2011-08-12 00:58:14 -05:00
|
|
|
fn encode_type_param_kinds(ebml_w: &ebml::writer, tps: &[ty_param]) {
|
|
|
|
ebml::start_tag(ebml_w, tag_items_data_item_ty_param_kinds);
|
2011-08-13 02:09:25 -05:00
|
|
|
ebml::write_vint(ebml_w.writer, vec::len::<ty_param>(tps));
|
2011-07-29 18:40:23 -05:00
|
|
|
for tp: ty_param in tps {
|
2011-08-19 17:16:48 -05:00
|
|
|
let c =
|
|
|
|
alt tp.kind {
|
|
|
|
kind_unique. { 'u' }
|
|
|
|
kind_shared. { 's' }
|
|
|
|
kind_pinned. { 'p' }
|
|
|
|
};
|
|
|
|
ebml_w.writer.write([c as u8]);
|
2011-07-29 18:40:23 -05:00
|
|
|
}
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
|
2011-08-12 00:58:14 -05:00
|
|
|
fn encode_variant_id(ebml_w: &ebml::writer, vid: &def_id) {
|
|
|
|
ebml::start_tag(ebml_w, tag_items_data_item_variant);
|
2011-08-27 00:48:10 -05:00
|
|
|
ebml_w.writer.write(istr::bytes(def_to_str(vid)));
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
|
2011-08-22 05:45:18 -05:00
|
|
|
fn encode_type(ecx: &@encode_ctxt, ebml_w: &ebml::writer, typ: ty::t) {
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_items_data_item_type);
|
2011-07-27 07:19:39 -05:00
|
|
|
let f = def_to_str;
|
|
|
|
let ty_str_ctxt =
|
|
|
|
@{ds: f,
|
|
|
|
tcx: ecx.ccx.tcx,
|
|
|
|
abbrevs: tyencode::ac_use_abbrevs(ecx.type_abbrevs)};
|
2011-08-23 20:09:30 -05:00
|
|
|
tyencode::enc_ty(io::new_writer(ebml_w.writer), ty_str_ctxt, typ);
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
|
2011-08-12 00:58:14 -05:00
|
|
|
fn encode_symbol(ecx: &@encode_ctxt, ebml_w: &ebml::writer, id: node_id) {
|
|
|
|
ebml::start_tag(ebml_w, tag_items_data_item_symbol);
|
2011-08-26 19:14:13 -05:00
|
|
|
ebml_w.writer.write(istr::bytes(ecx.ccx.item_symbols.get(id)));
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
|
2011-08-12 00:58:14 -05:00
|
|
|
fn encode_discriminant(ecx: &@encode_ctxt, ebml_w: &ebml::writer,
|
2011-07-27 07:19:39 -05:00
|
|
|
id: node_id) {
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_items_data_item_symbol);
|
2011-08-26 19:14:13 -05:00
|
|
|
ebml_w.writer.write(istr::bytes(ecx.ccx.discrim_symbols.get(id)));
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
|
2011-08-12 00:58:14 -05:00
|
|
|
fn encode_tag_id(ebml_w: &ebml::writer, id: &def_id) {
|
|
|
|
ebml::start_tag(ebml_w, tag_items_data_item_tag_id);
|
2011-08-27 00:48:10 -05:00
|
|
|
ebml_w.writer.write(istr::bytes(def_to_str(id)));
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
|
2011-08-12 00:58:14 -05:00
|
|
|
fn encode_tag_variant_info(ecx: &@encode_ctxt, ebml_w: &ebml::writer,
|
2011-08-04 18:20:09 -05:00
|
|
|
id: node_id, variants: &[variant],
|
2011-08-12 09:15:18 -05:00
|
|
|
index: &mutable [entry<int>],
|
2011-08-04 18:20:09 -05:00
|
|
|
ty_params: &[ty_param]) {
|
2011-08-15 23:54:52 -05:00
|
|
|
for variant: variant in variants {
|
2011-08-19 17:16:48 -05:00
|
|
|
index += [{val: variant.node.id, pos: ebml_w.writer.tell()}];
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_items_data_item);
|
2011-06-27 17:20:17 -05:00
|
|
|
encode_def_id(ebml_w, local_def(variant.node.id));
|
2011-07-29 18:40:23 -05:00
|
|
|
encode_family(ebml_w, 'v' as u8);
|
2011-06-27 17:20:17 -05:00
|
|
|
encode_tag_id(ebml_w, local_def(id));
|
2011-07-08 01:55:41 -05:00
|
|
|
encode_type(ecx, ebml_w,
|
|
|
|
node_id_to_monotype(ecx.ccx.tcx, variant.node.id));
|
2011-08-13 02:09:25 -05:00
|
|
|
if vec::len::<variant_arg>(variant.node.args) > 0u {
|
2011-07-08 01:55:41 -05:00
|
|
|
encode_symbol(ecx, ebml_w, variant.node.id);
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
2011-07-08 01:55:41 -05:00
|
|
|
encode_discriminant(ecx, ebml_w, variant.node.id);
|
2011-07-29 18:40:23 -05:00
|
|
|
encode_type_param_kinds(ebml_w, ty_params);
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: &ebml::writer, item: @item,
|
|
|
|
index: &mutable [entry<int>]) {
|
2011-07-27 07:19:39 -05:00
|
|
|
alt item.node {
|
|
|
|
item_const(_, _) {
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_items_data_item);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_def_id(ebml_w, local_def(item.id));
|
2011-07-29 18:40:23 -05:00
|
|
|
encode_family(ebml_w, 'c' as u8);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, item.id));
|
|
|
|
encode_symbol(ecx, ebml_w, item.id);
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2011-08-05 13:38:06 -05:00
|
|
|
item_fn(fd, tps) {
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_items_data_item);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_def_id(ebml_w, local_def(item.id));
|
2011-07-29 18:40:23 -05:00
|
|
|
encode_family(ebml_w,
|
2011-08-19 17:16:48 -05:00
|
|
|
alt fd.decl.purity {
|
|
|
|
pure_fn. { 'p' }
|
|
|
|
impure_fn. { 'f' }
|
|
|
|
} as u8);
|
2011-08-05 15:58:33 -05:00
|
|
|
encode_inlineness(ebml_w,
|
|
|
|
alt fd.decl.il {
|
|
|
|
il_normal. { 'n' }
|
|
|
|
il_inline. { 'i' }
|
|
|
|
} as u8);
|
2011-07-29 18:40:23 -05:00
|
|
|
encode_type_param_kinds(ebml_w, tps);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, item.id));
|
|
|
|
encode_symbol(ecx, ebml_w, item.id);
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
item_mod(_) {
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_items_data_item);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_def_id(ebml_w, local_def(item.id));
|
2011-07-29 18:40:23 -05:00
|
|
|
encode_family(ebml_w, 'm' as u8);
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
item_native_mod(_) {
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_items_data_item);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_def_id(ebml_w, local_def(item.id));
|
2011-07-29 18:40:23 -05:00
|
|
|
encode_family(ebml_w, 'n' as u8);
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
item_ty(_, tps) {
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_items_data_item);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_def_id(ebml_w, local_def(item.id));
|
2011-07-29 18:40:23 -05:00
|
|
|
encode_family(ebml_w, 'y' as u8);
|
|
|
|
encode_type_param_kinds(ebml_w, tps);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, item.id));
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
item_tag(variants, tps) {
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_items_data_item);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_def_id(ebml_w, local_def(item.id));
|
2011-07-29 18:40:23 -05:00
|
|
|
encode_family(ebml_w, 't' as u8);
|
|
|
|
encode_type_param_kinds(ebml_w, tps);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, item.id));
|
2011-08-15 23:54:52 -05:00
|
|
|
for v: variant in variants {
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_variant_id(ebml_w, local_def(v.node.id));
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_tag_variant_info(ecx, ebml_w, item.id, variants, index, tps);
|
|
|
|
}
|
|
|
|
item_res(_, _, tps, ctor_id) {
|
|
|
|
let fn_ty = node_id_to_monotype(ecx.ccx.tcx, ctor_id);
|
2011-06-27 17:20:17 -05:00
|
|
|
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_items_data_item);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_def_id(ebml_w, local_def(ctor_id));
|
2011-07-29 18:40:23 -05:00
|
|
|
encode_family(ebml_w, 'y' as u8);
|
|
|
|
encode_type_param_kinds(ebml_w, tps);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_type(ecx, ebml_w, ty::ty_fn_ret(ecx.ccx.tcx, fn_ty));
|
|
|
|
encode_symbol(ecx, ebml_w, item.id);
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-06-27 17:20:17 -05:00
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
index += [{val: ctor_id, pos: ebml_w.writer.tell()}];
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_items_data_item);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_def_id(ebml_w, local_def(ctor_id));
|
2011-07-29 18:40:23 -05:00
|
|
|
encode_family(ebml_w, 'f' as u8);
|
|
|
|
encode_type_param_kinds(ebml_w, tps);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_type(ecx, ebml_w, fn_ty);
|
|
|
|
encode_symbol(ecx, ebml_w, ctor_id);
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
item_obj(_, tps, ctor_id) {
|
|
|
|
let fn_ty = node_id_to_monotype(ecx.ccx.tcx, ctor_id);
|
2011-06-27 17:20:17 -05:00
|
|
|
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_items_data_item);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_def_id(ebml_w, local_def(item.id));
|
2011-07-29 18:40:23 -05:00
|
|
|
encode_family(ebml_w, 'y' as u8);
|
|
|
|
encode_type_param_kinds(ebml_w, tps);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_type(ecx, ebml_w, ty::ty_fn_ret(ecx.ccx.tcx, fn_ty));
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-07-27 07:19:39 -05:00
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
index += [{val: ctor_id, pos: ebml_w.writer.tell()}];
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_items_data_item);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_def_id(ebml_w, local_def(ctor_id));
|
2011-07-29 18:40:23 -05:00
|
|
|
encode_family(ebml_w, 'f' as u8);
|
|
|
|
encode_type_param_kinds(ebml_w, tps);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_type(ecx, ebml_w, fn_ty);
|
|
|
|
encode_symbol(ecx, ebml_w, ctor_id);
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-12 00:58:14 -05:00
|
|
|
fn encode_info_for_native_item(ecx: &@encode_ctxt, ebml_w: &ebml::writer,
|
2011-07-27 07:19:39 -05:00
|
|
|
nitem: &@native_item) {
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_items_data_item);
|
2011-07-27 07:19:39 -05:00
|
|
|
alt nitem.node {
|
|
|
|
native_item_ty. {
|
|
|
|
encode_def_id(ebml_w, local_def(nitem.id));
|
2011-07-29 18:40:23 -05:00
|
|
|
encode_family(ebml_w, 'T' as u8);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_type(ecx, ebml_w,
|
|
|
|
ty::mk_native(ecx.ccx.tcx, local_def(nitem.id)));
|
|
|
|
}
|
|
|
|
native_item_fn(_, _, tps) {
|
|
|
|
encode_def_id(ebml_w, local_def(nitem.id));
|
2011-07-29 18:40:23 -05:00
|
|
|
encode_family(ebml_w, 'F' as u8);
|
|
|
|
encode_type_param_kinds(ebml_w, tps);
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, nitem.id));
|
|
|
|
encode_symbol(ecx, ebml_w, nitem.id);
|
|
|
|
}
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
|
2011-08-12 00:58:14 -05:00
|
|
|
fn encode_info_for_items(ecx: &@encode_ctxt, ebml_w: &ebml::writer) ->
|
2011-08-12 09:15:18 -05:00
|
|
|
[entry<int>] {
|
2011-08-19 17:16:48 -05:00
|
|
|
let index: [entry<int>] = [];
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_items_data);
|
2011-08-19 17:16:48 -05:00
|
|
|
for each kvp: @{key: node_id, val: middle::ast_map::ast_node} in
|
2011-07-27 07:19:39 -05:00
|
|
|
ecx.ccx.ast_map.items() {
|
|
|
|
alt kvp.val {
|
|
|
|
middle::ast_map::node_item(i) {
|
2011-08-19 17:16:48 -05:00
|
|
|
index += [{val: kvp.key, pos: ebml_w.writer.tell()}];
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_info_for_item(ecx, ebml_w, i, index);
|
|
|
|
}
|
|
|
|
middle::ast_map::node_native_item(i) {
|
2011-08-19 17:16:48 -05:00
|
|
|
index += [{val: kvp.key, pos: ebml_w.writer.tell()}];
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_info_for_native_item(ecx, ebml_w, i);
|
|
|
|
}
|
|
|
|
_ { }
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
}
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-06-27 17:20:17 -05:00
|
|
|
ret index;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Path and definition ID indexing
|
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
fn create_index<T>(index: &[entry<T>], hash_fn: fn(&T) -> uint) ->
|
2011-08-12 09:15:18 -05:00
|
|
|
[@[entry<T>]] {
|
2011-08-19 17:16:48 -05:00
|
|
|
let buckets: [@mutable [entry<T>]] = [];
|
|
|
|
for each i: uint in uint::range(0u, 256u) { buckets += [@mutable []]; }
|
2011-08-12 09:15:18 -05:00
|
|
|
for elt: entry<T> in index {
|
2011-07-27 07:19:39 -05:00
|
|
|
let h = hash_fn(elt.val);
|
2011-08-19 17:16:48 -05:00
|
|
|
*buckets[h % 256u] += [elt];
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
2011-07-14 16:25:43 -05:00
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
let buckets_frozen = [];
|
2011-08-12 09:15:18 -05:00
|
|
|
for bucket: @mutable [entry<T>] in buckets {
|
2011-08-19 17:16:48 -05:00
|
|
|
buckets_frozen += [@*bucket];
|
2011-07-14 16:25:43 -05:00
|
|
|
}
|
|
|
|
ret buckets_frozen;
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
|
2011-08-12 08:36:51 -05:00
|
|
|
fn encode_index<T>(ebml_w: &ebml::writer, buckets: &[@[entry<T>]],
|
2011-08-19 17:16:48 -05:00
|
|
|
write_fn: fn(&io::writer, &T)) {
|
2011-08-23 20:09:30 -05:00
|
|
|
let writer = io::new_writer(ebml_w.writer);
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_index);
|
2011-08-19 17:16:48 -05:00
|
|
|
let bucket_locs: [uint] = [];
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_index_buckets);
|
2011-08-12 09:15:18 -05:00
|
|
|
for bucket: @[entry<T>] in buckets {
|
2011-08-19 17:16:48 -05:00
|
|
|
bucket_locs += [ebml_w.writer.tell()];
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_index_buckets_bucket);
|
2011-08-12 09:15:18 -05:00
|
|
|
for elt: entry<T> in *bucket {
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_index_buckets_bucket_elt);
|
2011-07-26 07:06:02 -05:00
|
|
|
writer.write_be_uint(elt.pos, 4u);
|
|
|
|
write_fn(writer, elt.val);
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
|
|
|
ebml::start_tag(ebml_w, tag_index_table);
|
2011-08-15 23:54:52 -05:00
|
|
|
for pos: uint in bucket_locs { writer.write_be_uint(pos, 4u); }
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
|
|
|
ebml::end_tag(ebml_w);
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
|
|
|
|
2011-08-25 00:13:16 -05:00
|
|
|
fn write_str(writer: &io::writer, s: &istr) {
|
|
|
|
writer.write_str(s);
|
2011-08-24 23:26:19 -05:00
|
|
|
}
|
2011-06-27 17:20:17 -05:00
|
|
|
|
2011-08-11 21:14:38 -05:00
|
|
|
fn write_int(writer: &io::writer, n: &int) {
|
2011-06-27 17:20:17 -05:00
|
|
|
writer.write_be_uint(n as uint, 4u);
|
|
|
|
}
|
|
|
|
|
2011-08-12 00:58:14 -05:00
|
|
|
fn encode_meta_item(ebml_w: &ebml::writer, mi: &meta_item) {
|
2011-07-27 07:19:39 -05:00
|
|
|
alt mi.node {
|
|
|
|
meta_word(name) {
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_meta_item_word);
|
|
|
|
ebml::start_tag(ebml_w, tag_meta_item_name);
|
2011-08-25 19:00:12 -05:00
|
|
|
ebml_w.writer.write(istr::bytes(name));
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
|
|
|
ebml::end_tag(ebml_w);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
meta_name_value(name, value) {
|
|
|
|
alt value.node {
|
|
|
|
lit_str(value, _) {
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_meta_item_name_value);
|
|
|
|
ebml::start_tag(ebml_w, tag_meta_item_name);
|
2011-08-25 19:00:12 -05:00
|
|
|
ebml_w.writer.write(istr::bytes(name));
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
|
|
|
ebml::start_tag(ebml_w, tag_meta_item_value);
|
2011-08-26 20:48:08 -05:00
|
|
|
ebml_w.writer.write(istr::bytes(value));
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
|
|
|
ebml::end_tag(ebml_w);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
|
|
|
_ {/* FIXME (#611) */ }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
meta_list(name, items) {
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_meta_item_list);
|
|
|
|
ebml::start_tag(ebml_w, tag_meta_item_name);
|
2011-08-25 19:00:12 -05:00
|
|
|
ebml_w.writer.write(istr::bytes(name));
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-08-15 23:54:52 -05:00
|
|
|
for inner_item: @meta_item in items {
|
2011-07-27 07:19:39 -05:00
|
|
|
encode_meta_item(ebml_w, *inner_item);
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2011-06-27 21:41:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-12 00:58:14 -05:00
|
|
|
fn encode_attributes(ebml_w: &ebml::writer, attrs: &[attribute]) {
|
|
|
|
ebml::start_tag(ebml_w, tag_attributes);
|
2011-08-15 23:54:52 -05:00
|
|
|
for attr: attribute in attrs {
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_attribute);
|
2011-06-27 21:41:48 -05:00
|
|
|
encode_meta_item(ebml_w, attr.node.value);
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-06-27 21:41:48 -05:00
|
|
|
}
|
|
|
|
|
2011-06-29 17:11:20 -05:00
|
|
|
// So there's a special crate attribute called 'link' which defines the
|
|
|
|
// metadata that Rust cares about for linking crates. This attribute requires
|
2011-06-30 19:03:08 -05:00
|
|
|
// 'name' and 'vers' items, so if the user didn't provide them we will throw
|
2011-06-29 17:11:20 -05:00
|
|
|
// them in anyway with default values.
|
2011-08-04 18:20:09 -05:00
|
|
|
fn synthesize_crate_attrs(ecx: &@encode_ctxt, crate: &@crate) -> [attribute] {
|
2011-06-29 16:17:23 -05:00
|
|
|
|
2011-08-04 18:20:09 -05:00
|
|
|
fn synthesize_link_attr(ecx: &@encode_ctxt, items: &[@meta_item]) ->
|
2011-07-27 07:19:39 -05:00
|
|
|
attribute {
|
2011-06-29 16:17:23 -05:00
|
|
|
|
2011-08-25 23:04:04 -05:00
|
|
|
assert (ecx.ccx.link_meta.name != ~"");
|
|
|
|
assert (ecx.ccx.link_meta.vers != ~"");
|
2011-06-29 16:17:23 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
let name_item =
|
2011-08-25 23:04:04 -05:00
|
|
|
attr::mk_name_value_item_str(
|
2011-08-27 20:01:52 -05:00
|
|
|
~"name", ecx.ccx.link_meta.name);
|
2011-07-27 07:19:39 -05:00
|
|
|
let vers_item =
|
2011-08-25 23:04:04 -05:00
|
|
|
attr::mk_name_value_item_str(
|
2011-08-27 20:01:52 -05:00
|
|
|
~"vers", ecx.ccx.link_meta.vers);
|
2011-06-29 16:17:23 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
let other_items =
|
|
|
|
{
|
2011-08-25 19:00:12 -05:00
|
|
|
let tmp = attr::remove_meta_items_by_name(items, ~"name");
|
|
|
|
attr::remove_meta_items_by_name(tmp, ~"vers")
|
2011-07-27 07:19:39 -05:00
|
|
|
};
|
2011-06-29 16:17:23 -05:00
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
let meta_items = [name_item, vers_item] + other_items;
|
2011-08-25 19:00:12 -05:00
|
|
|
let link_item = attr::mk_list_item(~"link", meta_items);
|
2011-06-29 16:17:23 -05:00
|
|
|
|
2011-06-30 19:03:08 -05:00
|
|
|
ret attr::mk_attr(link_item);
|
2011-06-29 16:17:23 -05:00
|
|
|
}
|
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
let attrs: [attribute] = [];
|
2011-07-27 07:19:39 -05:00
|
|
|
let found_link_attr = false;
|
2011-08-15 23:54:52 -05:00
|
|
|
for attr: attribute in crate.node.attrs {
|
2011-07-27 07:19:39 -05:00
|
|
|
attrs +=
|
2011-08-25 19:00:12 -05:00
|
|
|
if attr::get_attr_name(attr) != ~"link" {
|
2011-08-19 17:16:48 -05:00
|
|
|
[attr]
|
2011-07-27 07:19:39 -05:00
|
|
|
} else {
|
|
|
|
alt attr.node.value.node {
|
|
|
|
meta_list(n, l) {
|
2011-06-29 16:17:23 -05:00
|
|
|
found_link_attr = true;
|
2011-08-19 17:16:48 -05:00
|
|
|
[synthesize_link_attr(ecx, l)]
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2011-08-19 17:16:48 -05:00
|
|
|
_ { [attr] }
|
2011-06-29 16:17:23 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
if !found_link_attr { attrs += [synthesize_link_attr(ecx, [])]; }
|
2011-06-29 16:17:23 -05:00
|
|
|
|
|
|
|
ret attrs;
|
|
|
|
}
|
|
|
|
|
2011-08-12 00:58:14 -05:00
|
|
|
fn encode_crate_deps(ebml_w: &ebml::writer, cstore: &cstore::cstore) {
|
2011-07-08 13:29:56 -05:00
|
|
|
|
2011-08-27 00:48:10 -05:00
|
|
|
fn get_ordered_names(cstore: &cstore::cstore) -> [istr] {
|
2011-07-27 07:19:39 -05:00
|
|
|
type hashkv = @{key: crate_num, val: cstore::crate_metadata};
|
2011-08-27 00:48:10 -05:00
|
|
|
type numname = {crate: crate_num, ident: istr};
|
2011-07-08 13:29:56 -05:00
|
|
|
|
|
|
|
// Pull the cnums and names out of cstore
|
2011-08-19 17:16:48 -05:00
|
|
|
let pairs: [mutable numname] = [mutable];
|
2011-08-15 23:54:52 -05:00
|
|
|
for each hashkv: hashkv in cstore::iter_crate_data(cstore) {
|
2011-08-19 17:16:48 -05:00
|
|
|
pairs += [mutable {crate: hashkv.key, ident: hashkv.val.name}];
|
2011-07-08 13:29:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Sort by cnum
|
2011-07-27 07:19:39 -05:00
|
|
|
fn lteq(kv1: &numname, kv2: &numname) -> bool {
|
|
|
|
kv1.crate <= kv2.crate
|
|
|
|
}
|
2011-08-12 00:48:08 -05:00
|
|
|
std::sort::quick_sort(lteq, pairs);
|
2011-07-08 13:29:56 -05:00
|
|
|
|
|
|
|
// Sanity-check the crate numbers
|
2011-07-27 07:19:39 -05:00
|
|
|
let expected_cnum = 1;
|
2011-08-15 23:54:52 -05:00
|
|
|
for n: numname in pairs {
|
2011-07-27 07:19:39 -05:00
|
|
|
assert (n.crate == expected_cnum);
|
2011-07-08 13:29:56 -05:00
|
|
|
expected_cnum += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return just the names
|
2011-08-27 00:48:10 -05:00
|
|
|
fn name(kv: &numname) -> istr { kv.ident }
|
2011-08-15 18:38:23 -05:00
|
|
|
// mutable -> immutable hack for vec::map
|
|
|
|
let immpairs = vec::slice(pairs, 0u, vec::len(pairs));
|
|
|
|
ret vec::map(name, immpairs);
|
2011-07-08 13:29:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// We're just going to write a list of crate names, with the assumption
|
|
|
|
// that they are numbered 1 to n.
|
|
|
|
// FIXME: This is not nearly enough to support correct versioning
|
|
|
|
// but is enough to get transitive crate dependencies working.
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_crate_deps);
|
2011-08-27 00:48:10 -05:00
|
|
|
for cname: istr in get_ordered_names(cstore) {
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_crate_dep);
|
2011-08-27 00:48:10 -05:00
|
|
|
ebml_w.writer.write(istr::bytes(cname));
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-07-08 13:29:56 -05:00
|
|
|
}
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-07-08 13:29:56 -05:00
|
|
|
}
|
|
|
|
|
2011-08-27 00:48:10 -05:00
|
|
|
fn encode_metadata(cx: &@crate_ctxt, crate: &@crate) -> istr {
|
2011-07-08 01:55:41 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
let abbrevs = map::mk_hashmap(ty::hash_ty, ty::eq_ty);
|
|
|
|
let ecx = @{ccx: cx, type_abbrevs: abbrevs};
|
2011-07-08 01:55:41 -05:00
|
|
|
|
2011-08-11 21:14:38 -05:00
|
|
|
let string_w = io::string_writer();
|
2011-07-27 07:19:39 -05:00
|
|
|
let buf_w = string_w.get_writer().get_buf_writer();
|
2011-08-12 00:58:14 -05:00
|
|
|
let ebml_w = ebml::create_writer(buf_w);
|
2011-06-27 17:20:17 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
let crate_attrs = synthesize_crate_attrs(ecx, crate);
|
2011-06-29 16:17:23 -05:00
|
|
|
encode_attributes(ebml_w, crate_attrs);
|
2011-07-08 13:29:56 -05:00
|
|
|
|
|
|
|
encode_crate_deps(ebml_w, cx.sess.get_cstore());
|
|
|
|
|
2011-06-27 17:20:17 -05:00
|
|
|
// Encode and index the paths.
|
|
|
|
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_paths);
|
2011-07-27 07:19:39 -05:00
|
|
|
let paths_index = encode_item_paths(ebml_w, crate);
|
|
|
|
let paths_buckets = create_index(paths_index, hash_path);
|
2011-07-25 08:07:48 -05:00
|
|
|
encode_index(ebml_w, paths_buckets, write_str);
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-06-27 17:20:17 -05:00
|
|
|
// Encode and index the items.
|
|
|
|
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::start_tag(ebml_w, tag_items);
|
2011-07-27 07:19:39 -05:00
|
|
|
let items_index = encode_info_for_items(ecx, ebml_w);
|
|
|
|
let items_buckets = create_index(items_index, hash_node_id);
|
2011-07-25 08:07:48 -05:00
|
|
|
encode_index(ebml_w, items_buckets, write_int);
|
2011-08-12 00:58:14 -05:00
|
|
|
ebml::end_tag(ebml_w);
|
2011-06-27 17:20:17 -05:00
|
|
|
// Pad this, since something (LLVM, presumably) is cutting off the
|
2011-08-11 18:36:20 -05:00
|
|
|
// remaining % 4 bytes.
|
2011-06-27 17:20:17 -05:00
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
buf_w.write([0u8, 0u8, 0u8, 0u8]);
|
2011-08-27 00:48:10 -05:00
|
|
|
ret string_w.get_str();
|
2011-06-27 17:20:17 -05:00
|
|
|
}
|
2011-06-27 21:16:16 -05:00
|
|
|
|
2011-07-07 14:47:39 -05:00
|
|
|
// Get the encoded string for a type
|
2011-08-25 00:13:16 -05:00
|
|
|
fn encoded_ty(tcx: &ty::ctxt, t: ty::t) -> istr {
|
2011-07-27 07:19:39 -05:00
|
|
|
let cx = @{ds: def_to_str, tcx: tcx, abbrevs: tyencode::ac_no_abbrevs};
|
2011-08-11 21:14:38 -05:00
|
|
|
let sw = io::string_writer();
|
2011-07-07 14:47:39 -05:00
|
|
|
tyencode::enc_ty(sw.get_writer(), cx, t);
|
2011-08-25 00:13:16 -05:00
|
|
|
ret sw.get_str();
|
2011-07-07 14:47:39 -05:00
|
|
|
}
|
|
|
|
|
2011-06-27 21:16:16 -05:00
|
|
|
|
|
|
|
// 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:
|