diff options
| author | Patrick Walton <[email protected]> | 2011-03-24 17:21:09 -0700 |
|---|---|---|
| committer | Patrick Walton <[email protected]> | 2011-03-24 17:22:07 -0700 |
| commit | af3d0d1848116f0e29dcaf8859d27fd4555f3444 (patch) | |
| tree | 18984d72de2f122692b820259e06504621c42842 /src/comp | |
| parent | Remove obsolete Makefiles. (diff) | |
| download | rust-af3d0d1848116f0e29dcaf8859d27fd4555f3444.tar.xz rust-af3d0d1848116f0e29dcaf8859d27fd4555f3444.zip | |
rustc: Open "use"d crates; add a _vec.vec_from_buf() method along the way; XFAIL use-import-export.rs in rustc
Diffstat (limited to 'src/comp')
| -rw-r--r-- | src/comp/front/ast.rs | 3 | ||||
| -rw-r--r-- | src/comp/front/creader.rs | 41 | ||||
| -rw-r--r-- | src/comp/rustc.rc | 1 |
3 files changed, 37 insertions, 8 deletions
diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs index d48792d1..349f887a 100644 --- a/src/comp/front/ast.rs +++ b/src/comp/front/ast.rs @@ -374,8 +374,7 @@ tag native_item_ { fn_decl, vec[ty_param], def_id, ann); } -// TODO: Actually store something here. -type external_crate_info = (); +type external_crate_info = rec(vec[u8] data); fn index_view_item(mod_index index, @view_item it) { alt (it.node) { diff --git a/src/comp/front/creader.rs b/src/comp/front/creader.rs index 7212840c..e052e94a 100644 --- a/src/comp/front/creader.rs +++ b/src/comp/front/creader.rs @@ -2,11 +2,14 @@ import driver.session; import front.ast; +import lib.llvm.False; +import lib.llvm.llvm; import lib.llvm.llvmext; import lib.llvm.mk_object_file; import lib.llvm.mk_section_iter; import middle.fold; import middle.ty; +import back.x86; import util.common; import util.common.span; @@ -19,6 +22,7 @@ import std.map.hashmap; // TODO: map to a real type here. type env = @rec( + session.session sess, @hashmap[str, @ast.external_crate_info] crate_cache, vec[str] library_search_paths ); @@ -204,15 +208,39 @@ impure fn parse_ty_fn(@pstate st, str_def sd) -> tup(vec[ty.arg], @ty.t) { } +// Rust metadata parsing -// TODO: return something -fn load_crate(ast.ident ident, vec[str] library_search_paths) -> @() { +// TODO + + +fn load_crate(session.session sess, + ast.ident ident, + vec[str] library_search_paths) -> @ast.external_crate_info { + auto filename = parser.default_native_name(sess, ident); for (str library_search_path in library_search_paths) { - auto path = fs.connect(library_search_path, ident); - // TODO + auto path = fs.connect(library_search_path, filename); + auto pbuf = _str.buf(path); + auto mb = llvmext.LLVMRustCreateMemoryBufferWithContentsOfFile(pbuf); + if (mb as int != 0) { + auto of = mk_object_file(mb); + auto si = mk_section_iter(of.llof); + while (llvmext.LLVMIsSectionIteratorAtEnd(of.llof, si.llsi) == + False) { + auto name_buf = llvmext.LLVMGetSectionName(si.llsi); + auto name = _str.str_from_cstr(name_buf); + if (_str.eq(name, x86.get_meta_sect_name())) { + auto cbuf = llvmext.LLVMGetSectionContents(si.llsi); + auto csz = llvmext.LLVMGetSectionSize(si.llsi); + auto cvbuf = cbuf as _vec.vbuf; + ret @rec(data=_vec.vec_from_vbuf[u8](cvbuf, csz)); + } + } + } } - ret @(); + log #fmt("can't open crate '%s' (looked for '%s' in lib search paths)", + ident, filename); + fail; } fn fold_view_item_use(&env e, &span sp, ast.ident ident, @@ -220,7 +248,7 @@ fn fold_view_item_use(&env e, &span sp, ast.ident ident, -> @ast.view_item { auto external_crate; if (!e.crate_cache.contains_key(ident)) { - external_crate = load_crate(ident, e.library_search_paths); + external_crate = load_crate(e.sess, ident, e.library_search_paths); e.crate_cache.insert(ident, external_crate); } else { external_crate = e.crate_cache.get(ident); @@ -236,6 +264,7 @@ fn read_crates(session.session sess, @ast.crate crate, vec[str] library_search_paths) -> @ast.crate { auto e = @rec( + sess=sess, [email protected]_str_hash[@ast.external_crate_info](), library_search_paths=library_search_paths ); diff --git a/src/comp/rustc.rc b/src/comp/rustc.rc index a0c8aecb..db1f1b24 100644 --- a/src/comp/rustc.rc +++ b/src/comp/rustc.rc @@ -42,6 +42,7 @@ mod util { } auth driver.rustc.main = impure; +auth front.creader.load_crate = unsafe; auth middle.metadata = unsafe; auth middle.trans = unsafe; auth middle.trans.copy_args_to_allocas = impure; |