@@ -25,28 +25,14 @@ const size_t DEFAULT_ALIGNMENT = 16;
25
25
struct rust_obstack_alloc {
26
26
size_t len;
27
27
const type_desc *tydesc;
28
+ uint32_t pad0; // FIXME: x86-specific
29
+ uint32_t pad1;
28
30
uint8_t data[];
29
31
30
32
rust_obstack_alloc (size_t in_len, const type_desc *in_tydesc)
31
33
: len(in_len), tydesc(in_tydesc) {}
32
34
};
33
35
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
-
50
36
void *
51
37
rust_obstack_chunk::alloc (size_t len, type_desc *tydesc) {
52
38
alen = align_to (alen, DEFAULT_ALIGNMENT);
@@ -132,3 +118,61 @@ rust_obstack::mark() {
132
118
return chunk ? chunk->mark () : NULL ;
133
119
}
134
120
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
+
0 commit comments