Skip to content

Commit bdd681d

Browse files
committed
---
yaml --- r: 5095 b: refs/heads/master c: cc08fd1 h: refs/heads/master i: 5093: e1fda70 5091: aafd323 5087: 289d39d v: v3
1 parent b416545 commit bdd681d

File tree

3 files changed

+110
-18
lines changed

3 files changed

+110
-18
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: 9d00ef9a461ec04962f4ffbd6567364c0c2e9d73
2+
refs/heads/master: cc08fd1ef9eecf325e370b4aeeba7d69ded65814

trunk/src/rt/rust_obstack.cpp

Lines changed: 60 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,14 @@ const size_t DEFAULT_ALIGNMENT = 16;
2525
struct rust_obstack_alloc {
2626
size_t len;
2727
const type_desc *tydesc;
28+
uint32_t pad0; // FIXME: x86-specific
29+
uint32_t pad1;
2830
uint8_t data[];
2931

3032
rust_obstack_alloc(size_t in_len, const type_desc *in_tydesc)
3133
: len(in_len), tydesc(in_tydesc) {}
3234
};
3335

34-
// A contiguous set of allocations.
35-
struct rust_obstack_chunk {
36-
rust_obstack_chunk *prev;
37-
size_t size;
38-
size_t alen;
39-
size_t pad;
40-
uint8_t data[];
41-
42-
rust_obstack_chunk(rust_obstack_chunk *in_prev, size_t in_size)
43-
: prev(in_prev), size(in_size), alen(0) {}
44-
45-
void *alloc(size_t len, type_desc *tydesc);
46-
bool free(void *ptr);
47-
void *mark();
48-
};
49-
5036
void *
5137
rust_obstack_chunk::alloc(size_t len, type_desc *tydesc) {
5238
alen = align_to(alen, DEFAULT_ALIGNMENT);
@@ -132,3 +118,61 @@ rust_obstack::mark() {
132118
return chunk ? chunk->mark() : NULL;
133119
}
134120

121+
122+
// Iteration over self-describing obstacks
123+
124+
std::pair<const type_desc *,void *>
125+
rust_obstack::iterator::operator*() const {
126+
return std::make_pair(alloc->tydesc, alloc->data);
127+
}
128+
129+
rust_obstack::iterator &
130+
rust_obstack::iterator::operator++() {
131+
uint8_t *adata = align_to(alloc->data + alloc->len, DEFAULT_ALIGNMENT);
132+
alloc = reinterpret_cast<rust_obstack_alloc *>(adata);
133+
if (reinterpret_cast<uint8_t *>(alloc) >= chunk->data + chunk->alen) {
134+
// We reached the end of this chunk; go on to the next one.
135+
chunk = chunk->prev;
136+
if (chunk)
137+
alloc = reinterpret_cast<rust_obstack_alloc *>(chunk->data);
138+
else
139+
alloc = NULL;
140+
}
141+
return *this;
142+
}
143+
144+
bool
145+
rust_obstack::iterator::operator==(const rust_obstack::iterator &other)
146+
const {
147+
return chunk == other.chunk && alloc == other.alloc;
148+
}
149+
150+
bool
151+
rust_obstack::iterator::operator!=(const rust_obstack::iterator &other)
152+
const {
153+
return !(*this == other);
154+
}
155+
156+
157+
// Debugging
158+
159+
void
160+
rust_obstack::dump() const {
161+
iterator b = begin(), e = end();
162+
while (b != e) {
163+
std::pair<const type_desc *,void *> data = *b;
164+
shape::arena arena;
165+
shape::type_param *params = shape::type_param::from_tydesc(data.first,
166+
arena);
167+
shape::log log(task, true, data.first->shape, params,
168+
data.first->shape_tables,
169+
reinterpret_cast<uint8_t *>(data.second), std::cerr);
170+
log.walk();
171+
std::cerr << "\n";
172+
173+
++b;
174+
}
175+
176+
std::cerr << "end of dynastack dump\n";
177+
}
178+

trunk/src/rt/rust_obstack.h

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,28 @@
33
#ifndef RUST_OBSTACK_H
44
#define RUST_OBSTACK_H
55

6-
struct rust_obstack_chunk;
6+
#include <utility>
7+
8+
struct rust_obstack_alloc;
79
struct rust_task;
810
struct type_desc;
911

12+
// A contiguous set of allocations.
13+
struct rust_obstack_chunk {
14+
rust_obstack_chunk *prev;
15+
size_t size;
16+
size_t alen;
17+
size_t pad;
18+
uint8_t data[];
19+
20+
rust_obstack_chunk(rust_obstack_chunk *in_prev, size_t in_size)
21+
: prev(in_prev), size(in_size), alen(0) {}
22+
23+
void *alloc(size_t len, type_desc *tydesc);
24+
bool free(void *ptr);
25+
void *mark();
26+
};
27+
1028
class rust_obstack {
1129
rust_obstack_chunk *chunk;
1230
rust_task *task;
@@ -15,12 +33,42 @@ class rust_obstack {
1533
void *alloc_new(size_t len, type_desc *tydesc);
1634

1735
public:
36+
class iterator {
37+
rust_obstack_chunk *chunk;
38+
rust_obstack_alloc *alloc;
39+
40+
public:
41+
iterator(rust_obstack_chunk *in_chunk)
42+
: chunk(in_chunk),
43+
alloc(in_chunk
44+
? reinterpret_cast<rust_obstack_alloc *>(in_chunk->data)
45+
: NULL) {}
46+
47+
std::pair<const type_desc *,void *> operator*() const;
48+
iterator &operator++();
49+
bool operator==(const iterator &other) const;
50+
bool operator!=(const iterator &other) const;
51+
};
52+
1853
rust_obstack(rust_task *in_task) : chunk(NULL), task(in_task) {}
1954
~rust_obstack();
2055

56+
inline iterator begin() const {
57+
iterator it(chunk);
58+
return it;
59+
}
60+
61+
inline iterator end() const {
62+
iterator it(NULL);
63+
return it;
64+
}
65+
2166
void *alloc(size_t len, type_desc *tydesc);
2267
void free(void *ptr);
2368
void *mark();
69+
70+
/** Debugging tool: dumps the contents of this obstack to stderr. */
71+
void dump() const;
2472
};
2573

2674
#endif

0 commit comments

Comments
 (0)