mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
Revert "auto merge of #8745 : brson/rust/metadata, r=cmr"
This reverts commit491bc3568c
, reversing changes made to05f1bbba16
.
This commit is contained in:
parent
491bc3568c
commit
4aa342b868
3
configure
vendored
3
configure
vendored
@ -381,8 +381,7 @@ opt mingw-cross 0 "cross-compile for win32 using mingw"
|
||||
opt clang 0 "prefer clang to gcc for building the runtime"
|
||||
opt ccache 0 "invoke gcc/clang via ccache to reuse object files between builds"
|
||||
opt local-rust 0 "use an installed rustc rather than downloading a snapshot"
|
||||
opt pax-flags 0 "apply PaX flags to rustc binaries (required for GRSecurity/PaX-patched
|
||||
kernels)"
|
||||
opt pax-flags 0 "apply PaX flags to rustc binaries (required for GRSecurity/PaX-patched kernels)"
|
||||
valopt prefix "/usr/local" "set installation prefix"
|
||||
valopt local-rust-root "/usr/local" "set prefix for local rust binary"
|
||||
valopt llvm-root "" "set LLVM root"
|
||||
|
@ -12,8 +12,6 @@
|
||||
|
||||
|
||||
use std::str;
|
||||
use std::cast;
|
||||
use std::vec;
|
||||
|
||||
// Simple Extensible Binary Markup Language (ebml) reader and writer on a
|
||||
// cursor model. See the specification here:
|
||||
@ -31,42 +29,9 @@ struct EbmlState {
|
||||
data_pos: uint,
|
||||
}
|
||||
|
||||
#[deriving(Clone)]
|
||||
pub enum EbmlData {
|
||||
SafeData(@~[u8]),
|
||||
UnsafeData(*u8, uint)
|
||||
}
|
||||
|
||||
impl EbmlData {
|
||||
#[inline]
|
||||
pub fn slice<'a>(&'a self, start: uint, end: uint) -> &'a [u8] {
|
||||
match *self {
|
||||
SafeData(@ref v) => v.slice(start, end),
|
||||
UnsafeData(buf, len) => unsafe {
|
||||
do vec::raw::buf_as_slice(buf, len) |s| {
|
||||
cast::transmute(s.slice(start, end))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn as_slice<'a>(&'a self) -> &'a [u8] {
|
||||
self.slice(0, self.len())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn len(&self) -> uint {
|
||||
match *self {
|
||||
SafeData(@ref v) => v.len(),
|
||||
UnsafeData(_, len) => len
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[deriving(Clone)]
|
||||
pub struct Doc {
|
||||
data: EbmlData,
|
||||
data: @~[u8],
|
||||
start: uint,
|
||||
end: uint,
|
||||
}
|
||||
@ -220,28 +185,24 @@ pub mod reader {
|
||||
}
|
||||
|
||||
pub fn Doc(data: @~[u8]) -> Doc {
|
||||
Doc { data: SafeData(data), start: 0u, end: data.len() }
|
||||
Doc { data: data, start: 0u, end: data.len() }
|
||||
}
|
||||
|
||||
pub fn unsafe_Doc(buf: *u8, len: uint) -> Doc {
|
||||
Doc { data: UnsafeData(buf, len), start: 0u, end: len }
|
||||
}
|
||||
|
||||
pub fn doc_at(data: &EbmlData, start: uint) -> TaggedDoc {
|
||||
let elt_tag = vuint_at(data.as_slice(), start);
|
||||
let elt_size = vuint_at(data.as_slice(), elt_tag.next);
|
||||
pub fn doc_at(data: @~[u8], start: uint) -> TaggedDoc {
|
||||
let elt_tag = vuint_at(*data, start);
|
||||
let elt_size = vuint_at(*data, elt_tag.next);
|
||||
let end = elt_size.next + elt_size.val;
|
||||
TaggedDoc {
|
||||
tag: elt_tag.val,
|
||||
doc: Doc { data: data.clone(), start: elt_size.next, end: end }
|
||||
doc: Doc { data: data, start: elt_size.next, end: end }
|
||||
}
|
||||
}
|
||||
|
||||
pub fn maybe_get_doc(d: Doc, tg: uint) -> Option<Doc> {
|
||||
let mut pos = d.start;
|
||||
while pos < d.end {
|
||||
let elt_tag = vuint_at(d.data.as_slice(), pos);
|
||||
let elt_size = vuint_at(d.data.as_slice(), elt_tag.next);
|
||||
let elt_tag = vuint_at(*d.data, pos);
|
||||
let elt_size = vuint_at(*d.data, elt_tag.next);
|
||||
pos = elt_size.next + elt_size.val;
|
||||
if elt_tag.val == tg {
|
||||
return Some(Doc { data: d.data, start: elt_size.next,
|
||||
@ -264,8 +225,8 @@ pub mod reader {
|
||||
pub fn docs(d: Doc, it: &fn(uint, Doc) -> bool) -> bool {
|
||||
let mut pos = d.start;
|
||||
while pos < d.end {
|
||||
let elt_tag = vuint_at(d.data.as_slice(), pos);
|
||||
let elt_size = vuint_at(d.data.as_slice(), elt_tag.next);
|
||||
let elt_tag = vuint_at(*d.data, pos);
|
||||
let elt_size = vuint_at(*d.data, elt_tag.next);
|
||||
pos = elt_size.next + elt_size.val;
|
||||
let doc = Doc { data: d.data, start: elt_size.next, end: pos };
|
||||
if !it(elt_tag.val, doc) {
|
||||
@ -278,8 +239,8 @@ pub mod reader {
|
||||
pub fn tagged_docs(d: Doc, tg: uint, it: &fn(Doc) -> bool) -> bool {
|
||||
let mut pos = d.start;
|
||||
while pos < d.end {
|
||||
let elt_tag = vuint_at(d.data.as_slice(), pos);
|
||||
let elt_size = vuint_at(d.data.as_slice(), elt_tag.next);
|
||||
let elt_tag = vuint_at(*d.data, pos);
|
||||
let elt_size = vuint_at(*d.data, elt_tag.next);
|
||||
pos = elt_size.next + elt_size.val;
|
||||
if elt_tag.val == tg {
|
||||
let doc = Doc { data: d.data, start: elt_size.next,
|
||||
@ -299,22 +260,22 @@ pub mod reader {
|
||||
|
||||
pub fn doc_as_u8(d: Doc) -> u8 {
|
||||
assert_eq!(d.end, d.start + 1u);
|
||||
d.data.as_slice()[d.start]
|
||||
(*d.data)[d.start]
|
||||
}
|
||||
|
||||
pub fn doc_as_u16(d: Doc) -> u16 {
|
||||
assert_eq!(d.end, d.start + 2u);
|
||||
io::u64_from_be_bytes(d.data.as_slice(), d.start, 2u) as u16
|
||||
io::u64_from_be_bytes(*d.data, d.start, 2u) as u16
|
||||
}
|
||||
|
||||
pub fn doc_as_u32(d: Doc) -> u32 {
|
||||
assert_eq!(d.end, d.start + 4u);
|
||||
io::u64_from_be_bytes(d.data.as_slice(), d.start, 4u) as u32
|
||||
io::u64_from_be_bytes(*d.data, d.start, 4u) as u32
|
||||
}
|
||||
|
||||
pub fn doc_as_u64(d: Doc) -> u64 {
|
||||
assert_eq!(d.end, d.start + 8u);
|
||||
io::u64_from_be_bytes(d.data.as_slice(), d.start, 8u)
|
||||
io::u64_from_be_bytes(*d.data, d.start, 8u)
|
||||
}
|
||||
|
||||
pub fn doc_as_i8(d: Doc) -> i8 { doc_as_u8(d) as i8 }
|
||||
@ -337,7 +298,8 @@ pub mod reader {
|
||||
impl Decoder {
|
||||
fn _check_label(&mut self, lbl: &str) {
|
||||
if self.pos < self.parent.end {
|
||||
let TaggedDoc { tag: r_tag, doc: r_doc } = doc_at(&self.parent.data, self.pos);
|
||||
let TaggedDoc { tag: r_tag, doc: r_doc } =
|
||||
doc_at(self.parent.data, self.pos);
|
||||
|
||||
if r_tag == (EsLabel as uint) {
|
||||
self.pos = r_doc.end;
|
||||
@ -354,7 +316,8 @@ pub mod reader {
|
||||
if self.pos >= self.parent.end {
|
||||
fail!("no more documents in current node!");
|
||||
}
|
||||
let TaggedDoc { tag: r_tag, doc: r_doc } = doc_at(&self.parent.data, self.pos);
|
||||
let TaggedDoc { tag: r_tag, doc: r_doc } =
|
||||
doc_at(self.parent.data, self.pos);
|
||||
debug!("self.parent=%?-%? self.pos=%? r_tag=%? r_doc=%?-%?",
|
||||
self.parent.start,
|
||||
self.parent.end,
|
||||
|
@ -763,7 +763,7 @@ pub fn build_session_options(binary: @str,
|
||||
parse_only: parse_only,
|
||||
no_trans: no_trans,
|
||||
debugging_opts: debugging_opts,
|
||||
android_cross_path: android_cross_path,
|
||||
android_cross_path: android_cross_path
|
||||
};
|
||||
return sopts;
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ use metadata::cstore;
|
||||
use metadata::decoder;
|
||||
use metadata::filesearch::FileSearch;
|
||||
use metadata::loader;
|
||||
use metadata::loader::MetadataSection;
|
||||
|
||||
use std::hashmap::HashMap;
|
||||
use syntax::ast;
|
||||
@ -309,7 +308,7 @@ fn resolve_crate(e: @mut Env,
|
||||
}
|
||||
|
||||
// Go through the crate metadata and load any crates that it references
|
||||
fn resolve_crate_deps(e: @mut Env, cdata: MetadataSection) -> cstore::cnum_map {
|
||||
fn resolve_crate_deps(e: @mut Env, cdata: @~[u8]) -> cstore::cnum_map {
|
||||
debug!("resolving deps of external crate");
|
||||
// The map from crate numbers in the crate we're resolving to local crate
|
||||
// numbers
|
||||
|
@ -188,7 +188,7 @@ pub fn get_field_type(tcx: ty::ctxt, class_id: ast::def_id,
|
||||
def: ast::def_id) -> ty::ty_param_bounds_and_ty {
|
||||
let cstore = tcx.cstore;
|
||||
let cdata = cstore::get_crate_data(cstore, class_id.crate);
|
||||
let all_items = reader::get_doc(decoder::section_to_ebml_doc(cdata.data), tag_items);
|
||||
let all_items = reader::get_doc(reader::Doc(cdata.data), tag_items);
|
||||
debug!("Looking up %?", class_id);
|
||||
let class_doc = expect(tcx.diag,
|
||||
decoder::maybe_find_item(class_id.node, all_items),
|
||||
|
@ -15,7 +15,6 @@
|
||||
|
||||
use metadata::cstore;
|
||||
use metadata::decoder;
|
||||
use metadata::loader::MetadataSection;
|
||||
|
||||
use std::hashmap::HashMap;
|
||||
use extra;
|
||||
@ -30,7 +29,7 @@ pub type cnum_map = @mut HashMap<ast::CrateNum, ast::CrateNum>;
|
||||
|
||||
pub struct crate_metadata {
|
||||
name: @str,
|
||||
data: MetadataSection,
|
||||
data: @~[u8],
|
||||
cnum_map: cnum_map,
|
||||
cnum: ast::CrateNum
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ use metadata::decoder;
|
||||
use metadata::tydecode::{parse_ty_data, parse_def_id,
|
||||
parse_type_param_def_data,
|
||||
parse_bare_fn_ty_data, parse_trait_ref_data};
|
||||
use metadata::loader::{MetadataSection, UnsafeSection};
|
||||
use middle::ty;
|
||||
use middle::typeck;
|
||||
use middle::astencode::vtable_decoder_helpers;
|
||||
@ -57,16 +56,16 @@ fn lookup_hash(d: ebml::Doc, eq_fn: &fn(x:&[u8]) -> bool, hash: u64) ->
|
||||
let index = reader::get_doc(d, tag_index);
|
||||
let table = reader::get_doc(index, tag_index_table);
|
||||
let hash_pos = table.start + (hash % 256 * 4) as uint;
|
||||
let pos = io::u64_from_be_bytes(d.data.as_slice(), hash_pos, 4) as uint;
|
||||
let tagged_doc = reader::doc_at(&d.data, pos);
|
||||
let pos = io::u64_from_be_bytes(*d.data, hash_pos, 4) as uint;
|
||||
let tagged_doc = reader::doc_at(d.data, pos);
|
||||
|
||||
let belt = tag_index_buckets_bucket_elt;
|
||||
|
||||
let mut ret = None;
|
||||
do reader::tagged_docs(tagged_doc.doc, belt) |elt| {
|
||||
let pos = io::u64_from_be_bytes(elt.data.as_slice(), elt.start, 4) as uint;
|
||||
let pos = io::u64_from_be_bytes(*elt.data, elt.start, 4) as uint;
|
||||
if eq_fn(elt.data.slice(elt.start + 4, elt.end)) {
|
||||
ret = Some(reader::doc_at(&d.data, pos).doc);
|
||||
ret = Some(reader::doc_at(d.data, pos).doc);
|
||||
false
|
||||
} else {
|
||||
true
|
||||
@ -97,8 +96,8 @@ fn find_item(item_id: int, items: ebml::Doc) -> ebml::Doc {
|
||||
|
||||
// Looks up an item in the given metadata and returns an ebml doc pointing
|
||||
// to the item data.
|
||||
fn lookup_item(item_id: int, data: MetadataSection) -> ebml::Doc {
|
||||
let items = reader::get_doc(section_to_ebml_doc(data), tag_items);
|
||||
fn lookup_item(item_id: int, data: @~[u8]) -> ebml::Doc {
|
||||
let items = reader::get_doc(reader::Doc(data), tag_items);
|
||||
find_item(item_id, items)
|
||||
}
|
||||
|
||||
@ -216,13 +215,13 @@ fn variant_disr_val(d: ebml::Doc) -> Option<uint> {
|
||||
|
||||
fn doc_type(doc: ebml::Doc, tcx: ty::ctxt, cdata: cmd) -> ty::t {
|
||||
let tp = reader::get_doc(doc, tag_items_data_item_type);
|
||||
parse_ty_data(tp.data.as_slice(), cdata.cnum, tp.start, tcx,
|
||||
parse_ty_data(*tp.data, cdata.cnum, tp.start, tcx,
|
||||
|_, did| translate_def_id(cdata, did))
|
||||
}
|
||||
|
||||
fn doc_method_fty(doc: ebml::Doc, tcx: ty::ctxt, cdata: cmd) -> ty::BareFnTy {
|
||||
let tp = reader::get_doc(doc, tag_item_method_fty);
|
||||
parse_bare_fn_ty_data(tp.data.as_slice(), cdata.cnum, tp.start, tcx,
|
||||
parse_bare_fn_ty_data(*tp.data, cdata.cnum, tp.start, tcx,
|
||||
|_, did| translate_def_id(cdata, did))
|
||||
}
|
||||
|
||||
@ -231,7 +230,7 @@ fn doc_transformed_self_ty(doc: ebml::Doc,
|
||||
cdata: cmd) -> Option<ty::t>
|
||||
{
|
||||
do reader::maybe_get_doc(doc, tag_item_method_transformed_self_ty).map |tp| {
|
||||
parse_ty_data(tp.data.as_slice(), cdata.cnum, tp.start, tcx,
|
||||
parse_ty_data(*tp.data, cdata.cnum, tp.start, tcx,
|
||||
|_, did| translate_def_id(cdata, did))
|
||||
}
|
||||
}
|
||||
@ -242,7 +241,7 @@ pub fn item_type(_item_id: ast::def_id, item: ebml::Doc,
|
||||
}
|
||||
|
||||
fn doc_trait_ref(doc: ebml::Doc, tcx: ty::ctxt, cdata: cmd) -> ty::TraitRef {
|
||||
parse_trait_ref_data(doc.data.as_slice(), cdata.cnum, doc.start, tcx,
|
||||
parse_trait_ref_data(*doc.data, cdata.cnum, doc.start, tcx,
|
||||
|_, did| translate_def_id(cdata, did))
|
||||
}
|
||||
|
||||
@ -257,7 +256,7 @@ fn item_ty_param_defs(item: ebml::Doc, tcx: ty::ctxt, cdata: cmd,
|
||||
let mut bounds = ~[];
|
||||
do reader::tagged_docs(item, tag) |p| {
|
||||
let bd = parse_type_param_def_data(
|
||||
p.data.as_slice(), p.start, cdata.cnum, tcx,
|
||||
*p.data, p.start, cdata.cnum, tcx,
|
||||
|_, did| translate_def_id(cdata, did));
|
||||
bounds.push(bd);
|
||||
true
|
||||
@ -360,7 +359,7 @@ fn item_to_def_like(item: ebml::Doc, did: ast::def_id, cnum: ast::CrateNum)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lookup_def(cnum: ast::CrateNum, data: MetadataSection, did_: ast::def_id) ->
|
||||
pub fn lookup_def(cnum: ast::CrateNum, data: @~[u8], did_: ast::def_id) ->
|
||||
ast::def {
|
||||
let item = lookup_item(did_.node, data);
|
||||
let did = ast::def_id { crate: cnum, node: did_.node };
|
||||
@ -419,7 +418,7 @@ pub fn get_region_param(cdata: cmd, id: ast::NodeId)
|
||||
return item_ty_region_param(item);
|
||||
}
|
||||
|
||||
pub fn get_type_param_count(data: MetadataSection, id: ast::NodeId) -> uint {
|
||||
pub fn get_type_param_count(data: @~[u8], id: ast::NodeId) -> uint {
|
||||
item_ty_param_count(lookup_item(id, data))
|
||||
}
|
||||
|
||||
@ -450,7 +449,7 @@ pub fn get_impl_vtables(cdata: cmd,
|
||||
|
||||
pub fn get_impl_method(intr: @ident_interner, cdata: cmd, id: ast::NodeId,
|
||||
name: ast::ident) -> Option<ast::def_id> {
|
||||
let items = reader::get_doc(section_to_ebml_doc(cdata.data), tag_items);
|
||||
let items = reader::get_doc(reader::Doc(cdata.data), tag_items);
|
||||
let mut found = None;
|
||||
do reader::tagged_docs(find_item(id, items), tag_item_impl_method) |mid| {
|
||||
let m_did = reader::with_doc_data(mid, parse_def_id);
|
||||
@ -462,7 +461,7 @@ pub fn get_impl_method(intr: @ident_interner, cdata: cmd, id: ast::NodeId,
|
||||
found
|
||||
}
|
||||
|
||||
pub fn get_symbol(data: MetadataSection, id: ast::NodeId) -> ~str {
|
||||
pub fn get_symbol(data: @~[u8], id: ast::NodeId) -> ~str {
|
||||
return item_symbol(lookup_item(id, data));
|
||||
}
|
||||
|
||||
@ -483,7 +482,7 @@ fn def_like_to_def(def_like: def_like) -> ast::def {
|
||||
|
||||
/// Iterates over the language items in the given crate.
|
||||
pub fn each_lang_item(cdata: cmd, f: &fn(ast::NodeId, uint) -> bool) -> bool {
|
||||
let root = section_to_ebml_doc(cdata.data);
|
||||
let root = reader::Doc(cdata.data);
|
||||
let lang_items = reader::get_doc(root, tag_lang_items);
|
||||
do reader::tagged_docs(lang_items, tag_lang_items_item) |item_doc| {
|
||||
let id_doc = reader::get_doc(item_doc, tag_lang_items_item_id);
|
||||
@ -578,10 +577,10 @@ impl<'self> EachItemContext<'self> {
|
||||
fn each_item_of_module(&mut self, def_id: ast::def_id) -> bool {
|
||||
// This item might not be in this crate. If it's not, look it up.
|
||||
let items = if def_id.crate == self.cdata.cnum {
|
||||
reader::get_doc(section_to_ebml_doc(self.cdata.data), tag_items)
|
||||
reader::get_doc(reader::Doc(self.cdata.data), tag_items)
|
||||
} else {
|
||||
let crate_data = (self.get_crate_data)(def_id.crate);
|
||||
let root = section_to_ebml_doc(crate_data.data);
|
||||
let root = reader::Doc(crate_data.data);
|
||||
reader::get_doc(root, tag_items)
|
||||
};
|
||||
|
||||
@ -607,10 +606,10 @@ impl<'self> EachItemContext<'self> {
|
||||
// a reexport.
|
||||
let other_crates_items = if child_def_id.crate ==
|
||||
self.cdata.cnum {
|
||||
reader::get_doc(section_to_ebml_doc(self.cdata.data), tag_items)
|
||||
reader::get_doc(reader::Doc(self.cdata.data), tag_items)
|
||||
} else {
|
||||
let crate_data = (self.get_crate_data)(child_def_id.crate);
|
||||
let root = section_to_ebml_doc(crate_data.data);
|
||||
let root = reader::Doc(crate_data.data);
|
||||
reader::get_doc(root, tag_items)
|
||||
};
|
||||
|
||||
@ -674,10 +673,10 @@ impl<'self> EachItemContext<'self> {
|
||||
|
||||
// This reexport may be in yet another crate.
|
||||
let other_crates_items = if def_id.crate == self.cdata.cnum {
|
||||
reader::get_doc(section_to_ebml_doc(self.cdata.data), tag_items)
|
||||
reader::get_doc(reader::Doc(self.cdata.data), tag_items)
|
||||
} else {
|
||||
let crate_data = (self.get_crate_data)(def_id.crate);
|
||||
let root = section_to_ebml_doc(crate_data.data);
|
||||
let root = reader::Doc(crate_data.data);
|
||||
reader::get_doc(root, tag_items)
|
||||
};
|
||||
|
||||
@ -709,7 +708,7 @@ pub fn each_path(intr: @ident_interner,
|
||||
// make fast. It's the source of most of the performance problems when
|
||||
// compiling small crates.
|
||||
|
||||
let root_doc = section_to_ebml_doc(cdata.data);
|
||||
let root_doc = reader::Doc(cdata.data);
|
||||
let misc_info_doc = reader::get_doc(root_doc, tag_misc_info);
|
||||
let crate_items_doc = reader::get_doc(misc_info_doc,
|
||||
tag_misc_info_crate_items);
|
||||
@ -769,7 +768,7 @@ pub fn maybe_get_item_ast(cdata: cmd, tcx: ty::ctxt,
|
||||
pub fn get_enum_variants(intr: @ident_interner, cdata: cmd, id: ast::NodeId,
|
||||
tcx: ty::ctxt) -> ~[@ty::VariantInfo] {
|
||||
let data = cdata.data;
|
||||
let items = reader::get_doc(section_to_ebml_doc(data), tag_items);
|
||||
let items = reader::get_doc(reader::Doc(data), tag_items);
|
||||
let item = find_item(id, items);
|
||||
let mut infos: ~[@ty::VariantInfo] = ~[];
|
||||
let variant_ids = enum_variant_ids(item, cdata);
|
||||
@ -1207,14 +1206,8 @@ fn list_crate_attributes(intr: @ident_interner, md: ebml::Doc, hash: &str,
|
||||
out.write_str("\n\n");
|
||||
}
|
||||
|
||||
pub fn get_crate_attributes(data: MetadataSection) -> ~[ast::Attribute] {
|
||||
return get_attributes(section_to_ebml_doc(data));
|
||||
}
|
||||
|
||||
pub fn section_to_ebml_doc(data: MetadataSection) -> ebml::Doc {
|
||||
match data {
|
||||
UnsafeSection(_, buf, len) => reader::unsafe_Doc(buf, len)
|
||||
}
|
||||
pub fn get_crate_attributes(data: @~[u8]) -> ~[ast::Attribute] {
|
||||
return get_attributes(reader::Doc(data));
|
||||
}
|
||||
|
||||
#[deriving(Clone)]
|
||||
@ -1225,9 +1218,9 @@ pub struct crate_dep {
|
||||
hash: @str
|
||||
}
|
||||
|
||||
pub fn get_crate_deps(data: MetadataSection) -> ~[crate_dep] {
|
||||
pub fn get_crate_deps(data: @~[u8]) -> ~[crate_dep] {
|
||||
let mut deps: ~[crate_dep] = ~[];
|
||||
let cratedoc = section_to_ebml_doc(data);
|
||||
let cratedoc = reader::Doc(data);
|
||||
let depsdoc = reader::get_doc(cratedoc, tag_crate_deps);
|
||||
let mut crate_num = 1;
|
||||
fn docstr(doc: ebml::Doc, tag_: uint) -> @str {
|
||||
@ -1245,7 +1238,7 @@ pub fn get_crate_deps(data: MetadataSection) -> ~[crate_dep] {
|
||||
return deps;
|
||||
}
|
||||
|
||||
fn list_crate_deps(data: MetadataSection, out: @io::Writer) {
|
||||
fn list_crate_deps(data: @~[u8], out: @io::Writer) {
|
||||
out.write_str("=External Dependencies=\n");
|
||||
|
||||
let r = get_crate_deps(data);
|
||||
@ -1258,13 +1251,13 @@ fn list_crate_deps(data: MetadataSection, out: @io::Writer) {
|
||||
out.write_str("\n");
|
||||
}
|
||||
|
||||
pub fn get_crate_hash(data: MetadataSection) -> @str {
|
||||
let cratedoc = section_to_ebml_doc(data);
|
||||
pub fn get_crate_hash(data: @~[u8]) -> @str {
|
||||
let cratedoc = reader::Doc(data);
|
||||
let hashdoc = reader::get_doc(cratedoc, tag_crate_hash);
|
||||
hashdoc.as_str_slice().to_managed()
|
||||
}
|
||||
|
||||
pub fn get_crate_vers(data: MetadataSection) -> @str {
|
||||
pub fn get_crate_vers(data: @~[u8]) -> @str {
|
||||
let attrs = decoder::get_crate_attributes(data);
|
||||
let linkage_attrs = attr::find_linkage_metas(attrs);
|
||||
|
||||
@ -1289,10 +1282,10 @@ fn iter_crate_items(intr: @ident_interner, cdata: cmd,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn list_crate_metadata(intr: @ident_interner, bytes: MetadataSection,
|
||||
pub fn list_crate_metadata(intr: @ident_interner, bytes: @~[u8],
|
||||
out: @io::Writer) {
|
||||
let hash = get_crate_hash(bytes);
|
||||
let md = section_to_ebml_doc(bytes);
|
||||
let md = reader::Doc(bytes);
|
||||
list_crate_attributes(intr, md, hash, out);
|
||||
list_crate_deps(bytes, out);
|
||||
}
|
||||
@ -1314,7 +1307,7 @@ pub fn translate_def_id(cdata: cmd, did: ast::def_id) -> ast::def_id {
|
||||
}
|
||||
|
||||
pub fn get_link_args_for_crate(cdata: cmd) -> ~[~str] {
|
||||
let link_args = reader::get_doc(section_to_ebml_doc(cdata.data), tag_link_args);
|
||||
let link_args = reader::get_doc(reader::Doc(cdata.data), tag_link_args);
|
||||
let mut result = ~[];
|
||||
do reader::tagged_docs(link_args, tag_link_args_arg) |arg_doc| {
|
||||
result.push(arg_doc.as_str());
|
||||
|
@ -26,6 +26,7 @@ use std::hashmap::{HashMap, HashSet};
|
||||
use std::io;
|
||||
use std::str;
|
||||
use std::vec;
|
||||
use extra::flate;
|
||||
use extra::serialize::Encodable;
|
||||
use extra;
|
||||
use syntax::abi::AbiSet;
|
||||
@ -1569,7 +1570,7 @@ pub static metadata_encoding_version : &'static [u8] =
|
||||
0x75, //'u' as u8,
|
||||
0x73, //'s' as u8,
|
||||
0x74, //'t' as u8,
|
||||
0, 0, 0, 2 ];
|
||||
0, 0, 0, 1 ];
|
||||
|
||||
pub fn encode_metadata(parms: EncodeParams, crate: &Crate) -> ~[u8] {
|
||||
let wr = @io::BytesWriter::new();
|
||||
@ -1682,7 +1683,8 @@ pub fn encode_metadata(parms: EncodeParams, crate: &Crate) -> ~[u8] {
|
||||
|
||||
let writer_bytes: &mut ~[u8] = wr.bytes;
|
||||
|
||||
return metadata_encoding_version.to_owned() + *writer_bytes;
|
||||
metadata_encoding_version.to_owned() +
|
||||
flate::deflate_bytes(*writer_bytes)
|
||||
}
|
||||
|
||||
// Get the encoded string for a type
|
||||
|
@ -11,7 +11,7 @@
|
||||
//! Finds crate binaries and loads their metadata
|
||||
|
||||
|
||||
use lib::llvm::{False, llvm, mk_object_file, mk_section_iter, ObjectFile};
|
||||
use lib::llvm::{False, llvm, mk_object_file, mk_section_iter};
|
||||
use metadata::decoder;
|
||||
use metadata::encoder;
|
||||
use metadata::filesearch::FileSearch;
|
||||
@ -32,6 +32,7 @@ use std::os::consts::{macos, freebsd, linux, android, win32};
|
||||
use std::ptr;
|
||||
use std::str;
|
||||
use std::vec;
|
||||
use extra::flate;
|
||||
|
||||
pub enum os {
|
||||
os_macos,
|
||||
@ -53,14 +54,7 @@ pub struct Context {
|
||||
intr: @ident_interner
|
||||
}
|
||||
|
||||
#[deriving(Clone)]
|
||||
pub enum MetadataSection {
|
||||
// A pointer to the object file metadata section, along with
|
||||
// the ObjectFile handle that keeps it from being destructed
|
||||
UnsafeSection(@ObjectFile, *u8, uint)
|
||||
}
|
||||
|
||||
pub fn load_library_crate(cx: &Context) -> (~str, MetadataSection) {
|
||||
pub fn load_library_crate(cx: &Context) -> (~str, @~[u8]) {
|
||||
match find_library_crate(cx) {
|
||||
Some(t) => t,
|
||||
None => {
|
||||
@ -71,7 +65,7 @@ pub fn load_library_crate(cx: &Context) -> (~str, MetadataSection) {
|
||||
}
|
||||
}
|
||||
|
||||
fn find_library_crate(cx: &Context) -> Option<(~str, MetadataSection)> {
|
||||
fn find_library_crate(cx: &Context) -> Option<(~str, @~[u8])> {
|
||||
attr::require_unique_names(cx.diag, cx.metas);
|
||||
find_library_crate_aux(cx, libname(cx), cx.filesearch)
|
||||
}
|
||||
@ -93,7 +87,7 @@ fn find_library_crate_aux(
|
||||
cx: &Context,
|
||||
(prefix, suffix): (~str, ~str),
|
||||
filesearch: @filesearch::FileSearch
|
||||
) -> Option<(~str, MetadataSection)> {
|
||||
) -> Option<(~str, @~[u8])> {
|
||||
let crate_name = crate_name_from_metas(cx.metas);
|
||||
// want: crate_name.dir_part() + prefix + crate_name.file_part + "-"
|
||||
let prefix = fmt!("%s%s-", prefix, crate_name);
|
||||
@ -177,7 +171,7 @@ pub fn note_linkage_attrs(intr: @ident_interner,
|
||||
}
|
||||
}
|
||||
|
||||
fn crate_matches(crate_data: MetadataSection,
|
||||
fn crate_matches(crate_data: @~[u8],
|
||||
metas: &[@ast::MetaItem],
|
||||
hash: @str) -> bool {
|
||||
let attrs = decoder::get_crate_attributes(crate_data);
|
||||
@ -203,17 +197,17 @@ pub fn metadata_matches(extern_metas: &[@ast::MetaItem],
|
||||
}
|
||||
|
||||
fn get_metadata_section(os: os,
|
||||
filename: &Path) -> Option<MetadataSection> {
|
||||
filename: &Path) -> Option<@~[u8]> {
|
||||
unsafe {
|
||||
let mb = do filename.with_c_str |buf| {
|
||||
llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf)
|
||||
};
|
||||
if mb as int == 0 { return None; }
|
||||
let of = @match mk_object_file(mb) {
|
||||
if mb as int == 0 { return option::None::<@~[u8]>; }
|
||||
let of = match mk_object_file(mb) {
|
||||
option::Some(of) => of,
|
||||
_ => return None
|
||||
_ => return option::None::<@~[u8]>
|
||||
};
|
||||
let si = mk_section_iter((*of).llof);
|
||||
let si = mk_section_iter(of.llof);
|
||||
while llvm::LLVMIsSectionIteratorAtEnd(of.llof, si.llsi) == False {
|
||||
let name_buf = llvm::LLVMGetSectionName(si.llsi);
|
||||
let name = str::raw::from_c_str(name_buf);
|
||||
@ -221,6 +215,7 @@ fn get_metadata_section(os: os,
|
||||
if name == read_meta_section_name(os) {
|
||||
let cbuf = llvm::LLVMGetSectionContents(si.llsi);
|
||||
let csz = llvm::LLVMGetSectionSize(si.llsi) as uint;
|
||||
let mut found = None;
|
||||
let cvbuf: *u8 = cast::transmute(cbuf);
|
||||
let vlen = encoder::metadata_encoding_version.len();
|
||||
debug!("checking %u bytes of metadata-version stamp",
|
||||
@ -234,12 +229,19 @@ fn get_metadata_section(os: os,
|
||||
if !version_ok { return None; }
|
||||
|
||||
let cvbuf1 = ptr::offset(cvbuf, vlen as int);
|
||||
|
||||
return Some(UnsafeSection(of, cvbuf1, csz-vlen))
|
||||
debug!("inflating %u bytes of compressed metadata",
|
||||
csz - vlen);
|
||||
do vec::raw::buf_as_slice(cvbuf1, csz-vlen) |bytes| {
|
||||
let inflated = flate::inflate_bytes(bytes);
|
||||
found = Some(@(inflated));
|
||||
}
|
||||
if found != None {
|
||||
return found;
|
||||
}
|
||||
}
|
||||
llvm::LLVMMoveToNextSection(si.llsi);
|
||||
}
|
||||
return None;
|
||||
return option::None::<@~[u8]>;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1022,7 +1022,7 @@ impl ebml_decoder_decoder_helpers for reader::Decoder {
|
||||
tcx: ty::ctxt, cdata: @cstore::crate_metadata) -> ty::t {
|
||||
do self.read_opaque |_, doc| {
|
||||
tydecode::parse_ty_data(
|
||||
doc.data.as_slice(),
|
||||
*doc.data,
|
||||
cdata.cnum,
|
||||
doc.start,
|
||||
tcx,
|
||||
@ -1044,7 +1044,7 @@ impl ebml_decoder_decoder_helpers for reader::Decoder {
|
||||
|
||||
return do self.read_opaque |this, doc| {
|
||||
let ty = tydecode::parse_ty_data(
|
||||
doc.data.as_slice(),
|
||||
*doc.data,
|
||||
xcx.dcx.cdata.cnum,
|
||||
doc.start,
|
||||
xcx.dcx.tcx,
|
||||
@ -1060,7 +1060,7 @@ impl ebml_decoder_decoder_helpers for reader::Decoder {
|
||||
fn type_string(doc: ebml::Doc) -> ~str {
|
||||
let mut str = ~"";
|
||||
for i in range(doc.start, doc.end) {
|
||||
str.push_char(doc.data.as_slice()[i] as char);
|
||||
str.push_char(doc.data[i] as char);
|
||||
}
|
||||
str
|
||||
}
|
||||
@ -1074,7 +1074,7 @@ impl ebml_decoder_decoder_helpers for reader::Decoder {
|
||||
-> ty::TypeParameterDef {
|
||||
do self.read_opaque |this, doc| {
|
||||
tydecode::parse_type_param_def_data(
|
||||
doc.data.as_slice(),
|
||||
*doc.data,
|
||||
doc.start,
|
||||
xcx.dcx.cdata.cnum,
|
||||
xcx.dcx.tcx,
|
||||
|
Loading…
Reference in New Issue
Block a user