Skip to content

Commit 826c8fc

Browse files
committed
---
yaml --- r: 1843 b: refs/heads/master c: af3d0d1 h: refs/heads/master i: 1841: 07bdb1f 1839: 6c4debd v: v3
1 parent 0d710e4 commit 826c8fc

File tree

8 files changed

+54
-10
lines changed

8 files changed

+54
-10
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 29d853dd19a67c77ee6e03653a02289b6319abc3
2+
refs/heads/master: af3d0d1848116f0e29dcaf8859d27fd4555f3444

trunk/Makefile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,7 @@ TEST_XFAILS_STAGE0 := $(FLOAT_XFAILS) \
696696
threads.rs \
697697
type-sizes.rs \
698698
typestate-cfg-nesting.rs \
699+
use-import-export.rs \
699700
user.rs \
700701
utf8.rs \
701702
vec-alloc-append.rs \

trunk/src/comp/front/ast.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,7 @@ tag native_item_ {
374374
fn_decl, vec[ty_param], def_id, ann);
375375
}
376376
377-
// TODO: Actually store something here.
378-
type external_crate_info = ();
377+
type external_crate_info = rec(vec[u8] data);
379378
380379
fn index_view_item(mod_index index, @view_item it) {
381380
alt (it.node) {

trunk/src/comp/front/creader.rs

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
import driver.session;
44
import front.ast;
5+
import lib.llvm.False;
6+
import lib.llvm.llvm;
57
import lib.llvm.llvmext;
68
import lib.llvm.mk_object_file;
79
import lib.llvm.mk_section_iter;
810
import middle.fold;
911
import middle.ty;
12+
import back.x86;
1013
import util.common;
1114
import util.common.span;
1215

@@ -19,6 +22,7 @@ import std.map.hashmap;
1922

2023
// TODO: map to a real type here.
2124
type env = @rec(
25+
session.session sess,
2226
@hashmap[str, @ast.external_crate_info] crate_cache,
2327
vec[str] library_search_paths
2428
);
@@ -204,23 +208,47 @@ impure fn parse_ty_fn(@pstate st, str_def sd) -> tup(vec[ty.arg], @ty.t) {
204208
}
205209

206210

211+
// Rust metadata parsing
207212

208-
// TODO: return something
209-
fn load_crate(ast.ident ident, vec[str] library_search_paths) -> @() {
213+
// TODO
214+
215+
216+
fn load_crate(session.session sess,
217+
ast.ident ident,
218+
vec[str] library_search_paths) -> @ast.external_crate_info {
219+
auto filename = parser.default_native_name(sess, ident);
210220
for (str library_search_path in library_search_paths) {
211-
auto path = fs.connect(library_search_path, ident);
212-
// TODO
221+
auto path = fs.connect(library_search_path, filename);
222+
auto pbuf = _str.buf(path);
223+
auto mb = llvmext.LLVMRustCreateMemoryBufferWithContentsOfFile(pbuf);
224+
if (mb as int != 0) {
225+
auto of = mk_object_file(mb);
226+
auto si = mk_section_iter(of.llof);
227+
while (llvmext.LLVMIsSectionIteratorAtEnd(of.llof, si.llsi) ==
228+
False) {
229+
auto name_buf = llvmext.LLVMGetSectionName(si.llsi);
230+
auto name = _str.str_from_cstr(name_buf);
231+
if (_str.eq(name, x86.get_meta_sect_name())) {
232+
auto cbuf = llvmext.LLVMGetSectionContents(si.llsi);
233+
auto csz = llvmext.LLVMGetSectionSize(si.llsi);
234+
auto cvbuf = cbuf as _vec.vbuf;
235+
ret @rec(data=_vec.vec_from_vbuf[u8](cvbuf, csz));
236+
}
237+
}
238+
}
213239
}
214240

215-
ret @();
241+
log #fmt("can't open crate '%s' (looked for '%s' in lib search paths)",
242+
ident, filename);
243+
fail;
216244
}
217245

218246
fn fold_view_item_use(&env e, &span sp, ast.ident ident,
219247
vec[@ast.meta_item] meta_items, ast.def_id id, ast.ann orig_ann)
220248
-> @ast.view_item {
221249
auto external_crate;
222250
if (!e.crate_cache.contains_key(ident)) {
223-
external_crate = load_crate(ident, e.library_search_paths);
251+
external_crate = load_crate(e.sess, ident, e.library_search_paths);
224252
e.crate_cache.insert(ident, external_crate);
225253
} else {
226254
external_crate = e.crate_cache.get(ident);
@@ -236,6 +264,7 @@ fn read_crates(session.session sess,
236264
@ast.crate crate,
237265
vec[str] library_search_paths) -> @ast.crate {
238266
auto e = @rec(
267+
sess=sess,
239268
crate_cache=@common.new_str_hash[@ast.external_crate_info](),
240269
library_search_paths=library_search_paths
241270
);

trunk/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;

trunk/src/lib/_vec.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import option.none;
22
import option.some;
33

4-
import vbuf = rustrt.vbuf;
4+
type vbuf = rustrt.vbuf;
55

66
type operator2[T,U,V] = fn(&T, &U) -> V;
77

@@ -28,6 +28,8 @@ native "rust" mod rustrt {
2828
fn refcount[T](vec[T] v) -> uint;
2929

3030
fn vec_print_debug_info[T](vec[T] v);
31+
32+
fn vec_from_vbuf[T](vbuf v, uint n_elts) -> vec[T];
3133
}
3234

3335
fn alloc[T](uint n_elts) -> vec[T] {
@@ -48,6 +50,10 @@ fn refcount[T](vec[mutable? T] v) -> uint {
4850
}
4951
}
5052

53+
unsafe fn vec_from_vbuf[T](vbuf v, uint n_elts) -> vec[T] {
54+
ret rustrt.vec_from_vbuf[T](v, n_elts);
55+
}
56+
5157
type init_op[T] = fn(uint i) -> T;
5258

5359
fn init_fn[T](&init_op[T] op, uint n_elts) -> vec[T] {

trunk/src/rt/rust_builtin.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@ vec_alloc_with_data(rust_task *task,
170170
return new (mem) rust_vec(dom, alloc, fill * elt_size, (uint8_t*)d);
171171
}
172172

173+
extern "C" CDECL rust_vec*
174+
vec_from_vbuf(rust_task *task, type_desc *ty, void *vbuf, size_t n_elts)
175+
{
176+
return vec_alloc_with_data(task, n_elts, n_elts * ty->size, ty->size,
177+
vbuf);
178+
}
179+
173180
extern "C" CDECL rust_str*
174181
str_alloc(rust_task *task, size_t n_bytes)
175182
{

trunk/src/rt/rustrt.def.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ upcall_yield
6262
vec_alloc
6363
vec_alloc_mut
6464
vec_buf
65+
vec_from_vbuf
6566
vec_len
6667
vec_len_set
6768
vec_print_debug_info

0 commit comments

Comments
 (0)