Skip to content

Commit 15e1e31

Browse files
committed
rt: Allow records and boxes to be logged
1 parent c7f1c36 commit 15e1e31

File tree

1 file changed

+48
-11
lines changed

1 file changed

+48
-11
lines changed

src/rt/rust_shape.cpp

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ class ptr_pair {
156156

157157
ptr_pair(uint8_t *in_fst, uint8_t *in_snd) : fst(in_fst), snd(in_snd) {}
158158

159+
ptr_pair(data_pair<uint8_t *> &other) : fst(other.fst), snd(other.snd) {}
160+
159161
inline void operator=(uint8_t *rhs) { fst = snd = rhs; }
160162

161163
inline ptr_pair operator+(size_t n) const {
@@ -890,6 +892,7 @@ size_of::walk_ivec(bool align, bool is_pod, size_align &elem_sa) {
890892
template<typename T,typename U>
891893
class data : public ctxt< data<T,U> > {
892894
protected:
895+
void walk_box_contents(bool align);
893896
void walk_variant(bool align, tag_info &tinfo, uint32_t variant);
894897

895898
static std::pair<uint8_t *,uint8_t *> get_evec_data_range(ptr dp);
@@ -953,6 +956,16 @@ class data : public ctxt< data<T,U> > {
953956
void walk_number(bool align) { DATA_SIMPLE(W, walk_number<W>()); }
954957
};
955958

959+
template<typename T,typename U>
960+
void
961+
data<T,U>::walk_box_contents(bool align) {
962+
typename U::template data<uint8_t *>::t box_ptr = bump_dp<uint8_t *>(dp);
963+
964+
U ref_count_dp(box_ptr);
965+
T sub(*static_cast<T *>(this), ref_count_dp + sizeof(uint32_t));
966+
static_cast<T *>(this)->walk_box_contents(align, sub, ref_count_dp);
967+
}
968+
956969
template<typename T,typename U>
957970
void
958971
data<T,U>::walk_variant(bool align, tag_info &tinfo, uint32_t variant_id) {
@@ -1079,6 +1092,12 @@ class cmp : public data<cmp,ptr_pair> {
10791092
result = sub.result;
10801093
}
10811094

1095+
inline void walk_box_contents(bool align, cmp &sub,
1096+
ptr_pair &ref_count_dp) {
1097+
sub.walk(true);
1098+
result = sub.result;
1099+
}
1100+
10821101
inline void cmp_two_pointers(bool align) {
10831102
if (align) dp = align_to(dp, ALIGNOF(uint8_t *) * 2);
10841103
data_pair<uint8_t *> fst = bump_dp<uint8_t *>(dp);
@@ -1135,6 +1154,10 @@ class cmp : public data<cmp,ptr_pair> {
11351154
walk_vec(align, is_pod, get_ivec_data_range(dp));
11361155
}
11371156

1157+
void walk_box(bool align) {
1158+
data<cmp,ptr_pair>::walk_box_contents(align);
1159+
}
1160+
11381161
void walk_fn(bool align) { return cmp_two_pointers(align); }
11391162
void walk_obj(bool align) { return cmp_two_pointers(align); }
11401163
void walk_port(bool align) { return cmp_pointer(align); }
@@ -1143,7 +1166,6 @@ class cmp : public data<cmp,ptr_pair> {
11431166

11441167
void walk_tag(bool align, tag_info &tinfo,
11451168
const data_pair<uint32_t> &tag_variants);
1146-
void walk_box(bool align);
11471169
void walk_struct(bool align, const uint8_t *end_sp);
11481170
void walk_res(bool align, const rust_fn *dtor, uint16_t n_ty_params,
11491171
const uint8_t *ty_params_sp);
@@ -1188,16 +1210,6 @@ cmp::walk_tag(bool align, tag_info &tinfo,
11881210
data<cmp,ptr_pair>::walk_variant(align, tinfo, tag_variants.fst);
11891211
}
11901212

1191-
void
1192-
cmp::walk_box(bool align) {
1193-
data_pair<uint8_t *> subdp = bump_dp<uint8_t *>(dp);
1194-
1195-
cmp sub(*this, ptr_pair::make(subdp));
1196-
sub.dp += sizeof(uint32_t); // Skip over the reference count.
1197-
sub.walk(true);
1198-
result = sub.result;
1199-
}
1200-
12011213
void
12021214
cmp::walk_struct(bool align, const uint8_t *end_sp) {
12031215
while (!result && this->sp != end_sp) {
@@ -1266,8 +1278,18 @@ class log : public data<log,ptr> {
12661278
data<log,ptr>::walk_variant(align, tinfo, tag_variant);
12671279
}
12681280

1281+
void walk_box(bool align) {
1282+
out << "@";
1283+
data<log,ptr>::walk_box_contents(align);
1284+
}
1285+
12691286
void walk_subcontext(bool align, log &sub) { sub.walk(align); }
12701287

1288+
void walk_box_contents(bool align, log &sub, ptr &ref_count_dp) {
1289+
sub.walk(true);
1290+
}
1291+
1292+
void walk_struct(bool align, const uint8_t *end_sp);
12711293
void walk_vec(bool align, bool is_pod, const std::pair<ptr,ptr> &data);
12721294
void walk_variant(bool align, tag_info &tinfo, uint32_t variant_id,
12731295
const std::pair<const uint8_t *,const uint8_t *>
@@ -1304,6 +1326,21 @@ log::walk_string(const std::pair<ptr,ptr> &data) {
13041326
out << "\"" << std::dec;
13051327
}
13061328

1329+
void
1330+
log::walk_struct(bool align, const uint8_t *end_sp) {
1331+
out << "(";
1332+
1333+
bool first = true;
1334+
while (sp != end_sp) {
1335+
if (!first)
1336+
out << ", ";
1337+
walk(align);
1338+
align = true, first = false;
1339+
}
1340+
1341+
out << ")";
1342+
}
1343+
13071344
void
13081345
log::walk_vec(bool align, bool is_pod, const std::pair<ptr,ptr> &data) {
13091346
if (peek() == SHAPE_U8) {

0 commit comments

Comments
 (0)