Skip to content

Commit 6fdb81f

Browse files
committed
rustc: Open "use"d crates with the LLVM object file reader
1 parent 71b6e60 commit 6fdb81f

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/comp/front/creader.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22

33
import driver.session;
44
import front.ast;
5+
import lib.llvm.llvmext;
6+
import lib.llvm.mk_memory_buffer;
7+
import lib.llvm.mk_object_file;
8+
import lib.llvm.mk_section_iter;
59
import middle.fold;
610
import util.common;
711
import util.common.span;
812

13+
import std._str;
914
import std.fs;
15+
import std.os;
1016
import std.map.hashmap;
1117

1218
// TODO: map to a real type here.
@@ -17,12 +23,29 @@ type env = @rec(
1723

1824
// TODO: return something
1925
fn load_crate(ast.ident ident, vec[str] library_search_paths) -> @() {
26+
auto filename = os.dylib_filename(ident);
2027
for (str library_search_path in library_search_paths) {
21-
auto path = fs.connect(library_search_path, ident);
22-
// TODO
28+
auto path = fs.connect(library_search_path, filename);
29+
auto pb = _str.buf(path);
30+
auto llmb = llvmext.LLVMRustCreateMemoryBufferWithContentsOfFile(pb);
31+
if ((llmb as int) != 0) {
32+
auto llof = mk_object_file(llmb);
33+
if ((llof.llof as int) != 0) {
34+
auto llsi = mk_section_iter(llof.llof);
35+
while ((llvmext.LLVMIsSectionIteratorAtEnd(llof.llof,
36+
llsi.llsi) as int) == 0) {
37+
// TODO: check name, pass contents off.
38+
39+
llvmext.LLVMMoveToNextSection(llsi.llsi);
40+
}
41+
}
42+
}
2343
}
2444

25-
ret @();
45+
// TODO: write line number of "use" statement
46+
log #fmt("can't find a crate named '%s' (looked for '%s' in %s)",
47+
ident, filename, _str.connect(library_search_paths, ", "));
48+
fail;
2649
}
2750

2851
fn fold_view_item_use(&env e, &span sp, ast.ident ident,

src/comp/rustc.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ mod util {
4242
}
4343

4444
auth driver.rustc.main = impure;
45+
auth front.creader.load_crate = unsafe;
4546
auth middle.metadata = unsafe;
4647
auth middle.trans = unsafe;
4748
auth middle.trans.copy_args_to_allocas = impure;

0 commit comments

Comments
 (0)