Skip to content

Commit 8854285

Browse files
committed
---
yaml --- r: 28658 b: refs/heads/try c: 3c2b611 h: refs/heads/master v: v3
1 parent 60ee956 commit 8854285

File tree

5 files changed

+85
-13
lines changed

5 files changed

+85
-13
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
5-
refs/heads/try: a51a561852805cea58fbe106a28645e3d34b61e3
5+
refs/heads/try: 3c2b6110ddb99e3d4b67c15321b957bdd4b37671
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df

branches/try/src/rt/rust_crate_map.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ void iter_crate_map(const cratemap* map,
1212
void (*fn)(const mod_entry* map, void *cookie),
1313
void *cookie) {
1414
// First iterate this crate
15-
iter_module_map(map->entries, fn, cookie);
15+
iter_module_map(map->entries(), fn, cookie);
1616
// Then recurse on linked crates
1717
// FIXME (#2673) this does double work in diamond-shaped deps. could
1818
// keep a set of visited addresses, if it turns out to be actually
1919
// slow
20-
for (size_t i = 0; map->children[i]; i++) {
21-
iter_crate_map(map->children[i], fn, cookie);
20+
for (cratemap::iterator i = map->begin(), e = map->end(); i != e; ++i) {
21+
iter_crate_map(*i, fn, cookie);
2222
}
2323
}
2424

branches/try/src/rt/rust_crate_map.h

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,71 @@
22
#define RUST_CRATE_MAP_H
33

44
#include "rust_log.h"
5+
#include <stdint.h>
56

67
struct mod_entry {
78
const char* name;
89
uint32_t* state;
910
};
1011

11-
struct cratemap {
12-
const mod_entry* entries;
13-
const cratemap* children[1];
12+
class cratemap;
13+
14+
class cratemap_v0 {
15+
friend class cratemap;
16+
const mod_entry *m_entries;
17+
const cratemap* m_children[1];
18+
};
19+
20+
class cratemap {
21+
private:
22+
int32_t m_version;
23+
const void *m_annihilate_fn;
24+
const mod_entry* m_entries;
25+
const cratemap* m_children[1];
26+
27+
inline int32_t version() const {
28+
switch (m_version) {
29+
case 1: return 1;
30+
default: return 0;
31+
}
32+
}
33+
34+
public:
35+
typedef const cratemap *const *iterator;
36+
37+
inline const void *annihilate_fn() const {
38+
switch (version()) {
39+
case 0: return NULL;
40+
case 1: return m_annihilate_fn;
41+
default: assert(false && "Unknown crate map version!");
42+
}
43+
}
44+
45+
inline const mod_entry *entries() const {
46+
switch (version()) {
47+
case 0: return reinterpret_cast<const cratemap_v0 *>(this)->m_entries;
48+
case 1: return m_entries;
49+
default: assert(false && "Unknown crate map version!");
50+
}
51+
}
52+
53+
inline const iterator begin() const {
54+
switch (version()) {
55+
case 0:
56+
return &reinterpret_cast<const cratemap_v0 *>(this)->
57+
m_children[0];
58+
case 1:
59+
return &m_children[1];
60+
default: assert(false && "Unknown crate map version!");
61+
}
62+
}
63+
64+
inline const iterator end() const {
65+
iterator i = begin();
66+
while (*i)
67+
i++;
68+
return i;
69+
}
1470
};
1571

1672
void iter_module_map(const mod_entry* map,

branches/try/src/rt/rust_log.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,11 @@ void update_crate_map(const cratemap* map, log_directive* dirs,
236236
}
237237

238238
void print_crate_log_map(const cratemap* map) {
239-
for (const mod_entry* cur = map->entries; cur->name; cur++) {
239+
for (const mod_entry* cur = map->entries(); cur->name; cur++) {
240240
printf(" %s\n", cur->name);
241241
}
242-
for (size_t i = 0; map->children[i]; i++) {
243-
print_crate_log_map(map->children[i]);
242+
for (cratemap::iterator i = map->begin(), e = map->end(); i != e; ++i) {
243+
print_crate_log_map(*i);
244244
}
245245
}
246246

branches/try/src/rustc/middle/trans/base.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2478,7 +2478,7 @@ fn decl_crate_map(sess: session::session, mapmeta: link_meta,
24782478
} else { ~"toplevel" };
24792479
let sym_name = ~"_rust_crate_map_" + mapname;
24802480
let arrtype = T_array(int_type, n_subcrates as uint);
2481-
let maptype = T_struct(~[int_type, arrtype]);
2481+
let maptype = T_struct(~[T_i32(), T_ptr(T_i8()), int_type, arrtype]);
24822482
let map = str::as_c_str(sym_name, |buf| {
24832483
llvm::LLVMAddGlobal(llmod, maptype, buf)
24842484
});
@@ -2502,9 +2502,25 @@ fn fill_crate_map(ccx: @crate_ctxt, map: ValueRef) {
25022502
i += 1;
25032503
}
25042504
vec::push(subcrates, C_int(ccx, 0));
2505+
2506+
let llannihilatefn;
2507+
let annihilate_def_id = ccx.tcx.lang_items.annihilate_fn.get();
2508+
if annihilate_def_id.crate == ast::local_crate {
2509+
llannihilatefn = get_item_val(ccx, annihilate_def_id.node);
2510+
} else {
2511+
let annihilate_fn_type = csearch::get_type(ccx.tcx,
2512+
annihilate_def_id).ty;
2513+
llannihilatefn = trans_external_path(ccx,
2514+
annihilate_def_id,
2515+
annihilate_fn_type);
2516+
}
2517+
25052518
llvm::LLVMSetInitializer(map, C_struct(
2506-
~[p2i(ccx, create_module_map(ccx)),
2507-
C_array(ccx.int_type, subcrates)]));
2519+
~[C_i32(1),
2520+
lib::llvm::llvm::LLVMConstPointerCast(llannihilatefn,
2521+
T_ptr(T_i8())),
2522+
p2i(ccx, create_module_map(ccx)),
2523+
C_array(ccx.int_type, subcrates)]));
25082524
}
25092525

25102526
fn crate_ctxt_to_encode_parms(cx: @crate_ctxt)

0 commit comments

Comments
 (0)