2
2
3
3
import driver. session ;
4
4
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 ;
5
9
import middle. fold ;
6
10
import util. common ;
7
11
import util. common . span ;
8
12
13
+ import std. _str ;
9
14
import std. fs ;
15
+ import std. os ;
10
16
import std. map . hashmap ;
11
17
12
18
// TODO: map to a real type here.
@@ -17,12 +23,29 @@ type env = @rec(
17
23
18
24
// TODO: return something
19
25
fn load_crate ( ast . ident ident, vec[ str] library_search_paths ) -> @( ) {
26
+ auto filename = os. dylib_filename ( ident) ;
20
27
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
+ }
23
43
}
24
44
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;
26
49
}
27
50
28
51
fn fold_view_item_use( & env e, & span sp, ast. ident ident,
0 commit comments