Skip to content

Commit 1db4a04

Browse files
peterschrammeltautschnig
authored andcommitted
Initial set of mini-system-c tests
1 parent 6dc9b9b commit 1db4a04

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+2795
-0
lines changed

regression/systemc/Array1/main.cpp

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#include <assert.h>
2+
3+
#define COPY
4+
5+
typedef unsigned uint;
6+
7+
template <class T, uint m>
8+
class myarray {
9+
10+
T elt[m];
11+
12+
public:
13+
#if 0
14+
myarray &operator=(const myarray &other) {
15+
for (int i=0; i<m; i++) {
16+
elt[i] = other.elt[i];
17+
}
18+
return *this;
19+
}
20+
#endif
21+
22+
T& operator[] (int idx) {
23+
return elt[idx];
24+
}
25+
};
26+
27+
#ifdef COPY
28+
myarray<uint, 3> rev3u(myarray<uint, 3> x) {
29+
myarray<uint, 3> y;
30+
y[0] = x[2];
31+
y[1] = x[1];
32+
y[2] = x[0];
33+
return y;
34+
}
35+
36+
#else
37+
38+
void rev3u(myarray<uint, 3> x, myarray<uint, 3> &y) {
39+
y[0] = x[2];
40+
y[1] = x[1];
41+
y[2] = x[0];
42+
}
43+
#endif
44+
45+
extern bool arbb();
46+
extern uint arbu();
47+
48+
int main(void) {
49+
myarray<bool, 4> arrb;
50+
51+
for (int i=0; i<4; i++) {
52+
bool cond = (i%2 == 0);
53+
arrb[i] = cond;
54+
}
55+
56+
assert(arrb[0] == true);
57+
assert(arrb[1] == false);
58+
assert(arrb[2] == true);
59+
assert(arrb[3] == false);
60+
61+
myarray<uint, 3> arru;
62+
for (int i=0; i<3; i++) {
63+
arru[i] = arbu();
64+
}
65+
66+
myarray<uint, 3> arru2;
67+
#ifdef COPY
68+
arru2 = rev3u(arru); //problem: copy constructor refuses to copy array (solved)
69+
//new problem: byte_extract_little_endian ignored
70+
#else
71+
rev3u(arru,arru2);
72+
#endif
73+
assert (arru2[0] == arru[2]);
74+
assert (arru2[1] == arru[1]);
75+
assert (arru2[2] == arru[0]);
76+
77+
return 0;
78+
}

regression/systemc/Array1/test.desc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.cpp
3+
-DNO_IO -DNO_STRING
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

regression/systemc/Array1/tuple.h

+171
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
2+
#ifndef TUPLE_H
3+
#define TUPLE_H
4+
5+
#define DECLARE_INSIDE
6+
7+
#ifndef NO_IO
8+
#include <iostream>
9+
#endif
10+
11+
// ---------------------------------------------------------------------
12+
// Templates for passing & returning tuples
13+
14+
// null type
15+
struct null_type {};
16+
17+
// a const value of null_type
18+
inline const null_type cnull() {return null_type();}
19+
20+
#ifndef NO_IO
21+
std::ostream& operator<<(std::ostream& os, const null_type dummy)
22+
{
23+
os << "-";
24+
return os;
25+
}
26+
#endif
27+
28+
// a global to absorb "writes" to unused tuple fields.
29+
// would be good to get rid of this.
30+
null_type dummy;
31+
32+
template
33+
<class T0 = null_type,
34+
class T1 = null_type,
35+
class T2 = null_type,
36+
class T3 = null_type>
37+
class ltuple;
38+
39+
template
40+
<class T0 = null_type,
41+
class T1 = null_type,
42+
class T2 = null_type,
43+
class T3 = null_type>
44+
class tuple
45+
{
46+
47+
T0 el0;
48+
T1 el1;
49+
T2 el2;
50+
T3 el3;
51+
52+
public:
53+
54+
friend tuple<T0,T1,T2,T3>
55+
ltuple<T0,T1,T2,T3>::operator= (tuple<T0,T1,T2,T3>);
56+
57+
#ifndef NO_IO
58+
std::ostream&
59+
dump (std::ostream& os) {
60+
os << "(" << el0 << "," << el1 << "," << el2 << "," << el3 << ")";
61+
return os;
62+
}
63+
#endif
64+
65+
tuple() {}
66+
67+
tuple(T0 t0): el0(t0), el1(cnull()), el2(cnull()), el3(cnull()) {}
68+
69+
tuple(T0 t0, T1 t1): el0(t0), el1(t1), el2(cnull()), el3(cnull()) {}
70+
71+
tuple(T0 t0, T1 t1, T2 t2): el0(t0), el1(t1), el2(t2), el3(cnull()) {}
72+
73+
tuple(T0 t0, T1 t1, T2 t2, T3 t3): el0(t0), el1(t1), el2(t2), el3(t3) {}
74+
75+
};
76+
77+
#ifndef NO_IO
78+
template<class T0, class T1, class T2, class T3>
79+
std::ostream& operator<<(std::ostream& os, tuple<T0,T1,T2,T3> src)
80+
{
81+
return src.dump(os);
82+
}
83+
#endif
84+
85+
template
86+
<class T0,
87+
class T1,
88+
class T2,
89+
class T3>
90+
class ltuple
91+
{
92+
93+
private:
94+
T0 &el0;
95+
T1 &el1;
96+
T2 &el2;
97+
T3 &el3;
98+
99+
public:
100+
101+
#ifdef DECLARE_INSIDE
102+
ltuple(T0 &t0, T1 &t1, T2 &t2, T3 &t3 )
103+
: el0(t0), el1(t1), el2(t2), el3(t3)
104+
{}
105+
106+
tuple<T0,T1,T2,T3>
107+
operator= (tuple<T0,T1,T2,T3> src)
108+
{
109+
el0 = src.el0;
110+
el1 = src.el1;
111+
el2 = src.el2;
112+
el3 = src.el3;
113+
return src;
114+
}
115+
#else
116+
ltuple(T0 &t0, T1 &t1, T2 &t2, T3 &t3 );
117+
118+
tuple<T0,T1,T2,T3>
119+
operator= (tuple<T0,T1,T2,T3> src);
120+
#endif
121+
};
122+
123+
124+
#ifndef DECLARE_INSIDE
125+
template <class T0, class T1, class T2, class T3>
126+
ltuple<T0,T1,T2,T3>::ltuple(T0 &t0, T1 &t1, T2 &t2, T3 &t3 )
127+
: el0(t0), el1(t1), el2(t2), el3(t3)
128+
{}
129+
130+
template <class T0, class T1, class T2, class T3>
131+
tuple<T0,T1,T2,T3>
132+
ltuple<T0,T1,T2,T3>::operator= (tuple<T0,T1,T2,T3> src)
133+
{
134+
el0 = src.el0;
135+
el1 = src.el1;
136+
el2 = src.el2;
137+
el3 = src.el3;
138+
return src;
139+
}
140+
#endif
141+
142+
template <class T0>
143+
ltuple<T0>
144+
tie(T0 &t0)
145+
{
146+
return ltuple<T0>(t0, dummy, dummy, dummy);
147+
}
148+
149+
template <class T0, class T1>
150+
ltuple<T0,T1>
151+
tie(T0 &t0, T1 &t1)
152+
{
153+
return ltuple<T0,T1>(t0,t1,dummy,dummy);
154+
}
155+
156+
template <class T0, class T1, class T2>
157+
ltuple<T0,T1,T2>
158+
tie(T0 &t0, T1 &t1, T2 &t2)
159+
{
160+
return ltuple<T0,T1,T2>(t0,t1,t2,dummy);
161+
}
162+
163+
template <class T0, class T1, class T2, class T3>
164+
ltuple<T0,T1,T2,T3>
165+
tie(T0 &t0, T1 &t1, T2 &t2, T3 &t3)
166+
{
167+
return ltuple<T0,T1,T2>(t0,t1,t2,t3);
168+
}
169+
170+
#endif
171+

regression/systemc/Array2/main.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <assert.h>
2+
3+
class myarray {
4+
5+
int elt[4];
6+
7+
public:
8+
int& operator[] (int idx) {
9+
return elt[idx];
10+
}
11+
};
12+
13+
int main(void) {
14+
myarray x;
15+
16+
for (int i=0; i<4; i++) {
17+
x[i] = i;
18+
}
19+
20+
assert(x[0] == 0);
21+
assert(x[3] == 3);
22+
23+
myarray y = x; //copy constructor does not typecheck
24+
assert(y[0] == 0);
25+
assert(y[3] == 3);
26+
27+
return 0;
28+
}

regression/systemc/Array2/test.desc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.cpp
3+
-DNO_IO -DNO_STRING
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

0 commit comments

Comments
 (0)