diff options
| author | Patrick Walton <[email protected]> | 2011-03-15 18:05:29 -0700 |
|---|---|---|
| committer | Patrick Walton <[email protected]> | 2011-03-15 18:05:29 -0700 |
| commit | 6fdb81fa17b3c7147a69edc5217c9f93ff485410 (patch) | |
| tree | 8597afa912813b40e1ce54436309c0e8df99bb30 | |
| parent | rustc: Add an annotation for the crate definition to view_item_use (diff) | |
| download | rust-6fdb81fa17b3c7147a69edc5217c9f93ff485410.tar.xz rust-6fdb81fa17b3c7147a69edc5217c9f93ff485410.zip | |
rustc: Open "use"d crates with the LLVM object file reader
| -rw-r--r-- | src/comp/front/creader.rs | 29 | ||||
| -rw-r--r-- | src/comp/rustc.rc | 1 |
2 files changed, 27 insertions, 3 deletions
diff --git a/src/comp/front/creader.rs b/src/comp/front/creader.rs index d1eaba85..2a4b4c57 100644 --- a/src/comp/front/creader.rs +++ b/src/comp/front/creader.rs @@ -2,11 +2,17 @@ import driver.session; import front.ast; +import lib.llvm.llvmext; +import lib.llvm.mk_memory_buffer; +import lib.llvm.mk_object_file; +import lib.llvm.mk_section_iter; import middle.fold; import util.common; import util.common.span; +import std._str; import std.fs; +import std.os; import std.map.hashmap; // TODO: map to a real type here. @@ -17,12 +23,29 @@ type env = @rec( // TODO: return something fn load_crate(ast.ident ident, vec[str] library_search_paths) -> @() { + auto filename = os.dylib_filename(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 pb = _str.buf(path); + auto llmb = llvmext.LLVMRustCreateMemoryBufferWithContentsOfFile(pb); + if ((llmb as int) != 0) { + auto llof = mk_object_file(llmb); + if ((llof.llof as int) != 0) { + auto llsi = mk_section_iter(llof.llof); + while ((llvmext.LLVMIsSectionIteratorAtEnd(llof.llof, + llsi.llsi) as int) == 0) { + // TODO: check name, pass contents off. + + llvmext.LLVMMoveToNextSection(llsi.llsi); + } + } + } } - ret @(); + // TODO: write line number of "use" statement + log #fmt("can't find a crate named '%s' (looked for '%s' in %s)", + ident, filename, _str.connect(library_search_paths, ", ")); + fail; } fn fold_view_item_use(&env e, &span sp, ast.ident ident, diff --git a/src/comp/rustc.rc b/src/comp/rustc.rc index 7f1a7a03..4bf1161d 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; |