Skip to content

Commit 0aeddb3

Browse files
committed
rt: Stub compare glue
1 parent d7828e6 commit 0aeddb3

File tree

1 file changed

+60
-22
lines changed

1 file changed

+60
-22
lines changed

src/rt/rust_shape.cpp

Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ round_up(T size, size_t alignment) {
7575
return x;
7676
}
7777

78+
template<typename T>
79+
static inline T
80+
bump_dp(uint8_t *dp) {
81+
T x = *((T *)dp);
82+
dp += sizeof(T);
83+
return x;
84+
}
85+
7886

7987
// Utility classes
8088

@@ -125,6 +133,34 @@ struct tag_info {
125133
const type_param *params; // Array of type parameters.
126134
};
127135

136+
template<typename T>
137+
class data_pair {
138+
public:
139+
T fst, snd;
140+
inline void operator=(const T rhs) { fst = snd = rhs; }
141+
};
142+
143+
class ptr_pair {
144+
public:
145+
uint8_t *fst, *snd;
146+
147+
template<typename T>
148+
class data { typedef data_pair<T> t; };
149+
150+
ptr_pair(uint8_t *in_fst, uint8_t *in_snd) : fst(in_fst), snd(in_snd) {}
151+
152+
inline void operator=(uint8_t *rhs) { fst = snd = rhs; }
153+
154+
inline ptr_pair operator+(size_t n) const {
155+
return make(fst + n, snd + n);
156+
}
157+
158+
static inline ptr_pair make(uint8_t *fst, uint8_t *snd) {
159+
ptr_pair self(fst, snd);
160+
return self;
161+
}
162+
};
163+
128164

129165
// Contexts
130166

@@ -719,16 +755,15 @@ size_of::walk_ivec(bool align, bool is_pod, size_align &elem_sa) {
719755
// for methods that actually manipulate the data involved.
720756

721757
#define DATA_SIMPLE(ty, call) \
722-
if (align) dp.align_to(sizeof(ty)); \
758+
if (align) dp = align_to(dp, sizeof(ty)); \
723759
static_cast<T *>(this)->call; \
724760
dp += sizeof(ty);
725761

726-
template<typename T>
727-
class data : public ctxt< data<T> > {
728-
private:
729-
typename T::data_ptr dp;
730-
762+
template<typename T,typename U>
763+
class data : public ctxt< data<T,U> > {
731764
public:
765+
U dp;
766+
732767
void walk_tag(bool align, tag_info &tinfo);
733768
void walk_ivec(bool align, bool is_pod, size_align &elem_sa);
734769

@@ -750,13 +785,13 @@ class data : public ctxt< data<T> > {
750785
void walk_task(bool align) { DATA_SIMPLE(void *, walk_task(align)); }
751786

752787
void walk_fn(bool align) {
753-
if (align) dp.align_to(sizeof(void *));
788+
if (align) dp = align_to(dp, sizeof(void *));
754789
static_cast<T *>(this)->walk_fn(align);
755790
dp += sizeof(void *) * 2;
756791
}
757792

758793
void walk_obj(bool align) {
759-
if (align) dp.align_to(sizeof(void *));
794+
if (align) dp = align_to(dp, sizeof(void *));
760795
static_cast<T *>(this)->walk_obj(align);
761796
dp += sizeof(void *) * 2;
762797
}
@@ -766,43 +801,40 @@ class data : public ctxt< data<T> > {
766801
}
767802

768803
template<typename W>
769-
void walk_number(bool align) {
770-
DATA_SIMPLE(W, walk_number<W>(align));
771-
}
804+
void walk_number(bool align) { DATA_SIMPLE(W, walk_number<W>(align)); }
772805
};
773806

774-
template<typename T>
807+
template<typename T,typename U>
775808
void
776-
data<T>::walk_ivec(bool align, bool is_pod, size_align &elem_sa) {
809+
data<T,U>::walk_ivec(bool align, bool is_pod, size_align &elem_sa) {
777810
if (!elem_sa.is_set())
778811
elem_sa = size_of::get(*this);
779812
else if (elem_sa.alignment == 8)
780813
elem_sa.alignment = 4; // FIXME: This is an awful hack.
781814

782815
// Get a pointer to the interior vector, and skip over it.
783-
if (align) dp.align_to(ALIGNOF(rust_ivec *));
784-
typename T::data_ptr end_dp = dp + sizeof(rust_ivec) - sizeof(uintptr_t) +
785-
elem_sa.size * 4;
816+
if (align) dp = align_to(dp, ALIGNOF(rust_ivec *));
817+
U end_dp = dp + sizeof(rust_ivec) - sizeof(uintptr_t) + elem_sa.size * 4;
786818

787819
// Call to the implementation.
788820
static_cast<T *>(this)->walk_ivec(align, is_pod, elem_sa);
789821

790822
dp = end_dp;
791823
}
792824

793-
template<typename T>
825+
template<typename T,typename U>
794826
void
795-
data<T>::walk_tag(bool align, tag_info &tinfo) {
827+
data<T,U>::walk_tag(bool align, tag_info &tinfo) {
796828
size_of::compute_tag_size(tinfo);
797829

798830
if (tinfo.variant_count > 1 && align)
799-
dp.align_to(ALIGNOF(uint32_t));
831+
dp = align_to(dp, ALIGNOF(uint32_t));
800832

801-
typename T::data_ptr end_dp = tinfo.tag_sa.size;
833+
U end_dp = tinfo.tag_sa.size;
802834

803-
typename T::template data<uint32_t> tag_variant;
835+
typename U::template data<uint32_t>::t tag_variant;
804836
if (tinfo.variant_count > 1)
805-
tag_variant = dp.template get_bump<uint32_t>();
837+
tag_variant = bump_dp<uint32_t>(dp);
806838
else
807839
tag_variant = 0;
808840

@@ -820,5 +852,11 @@ class copy : public data<copy> {
820852

821853
#endif
822854

855+
856+
// Structural comparison glue.
857+
858+
class cmp : public data<cmp,ptr_pair> {
859+
};
860+
823861
} // end namespace shape
824862

0 commit comments

Comments
 (0)