source: sources/test_regression/15042009/system.cpp@ 32

Last change on this file since 32 was 19, checked in by buchmann, 17 years ago

Add LLU suffix to a 64 bits constants.

File size: 2.7 KB
Line 
1#include "systemc.h"
2#include <iostream>
3
4using namespace std;
5
6#define ASSERT(x) \
7 { errnum++; \
8 if (!(x)) \
9 { \
10 cerr << "ASSERT : " #x "\n"; \
11 exit (errnum); \
12 } \
13 }
14
15using namespace std;
16
17#define MASK 0x0000000FFFFFFFFFLLU
18typedef sc_uint<36> data_type;
19
20struct observer : sc_module
21{
22 sc_in_clk clk;
23
24 sc_in<data_type> i;
25
26 void f ()
27 {
28 cout << "0x" << hex << i.read() << endl;
29 data_type t = i.read();
30 if (t == 7)
31 cout << "(== 0x7)\n";
32 t <<= 1;
33 if (t == 14)
34 cout << "((t << 1) == 0xe)\n";
35 t += 1;
36 if (t == 15)
37 cout << "(((t << 1) + 1) == 0xf)\n";
38 t = t >> 1;
39 if (t == 7)
40 cout << "((((t << 1) + 1) >> 1) == 0x7)\n";
41 }
42
43 SC_HAS_PROCESS(observer);
44 observer(sc_module_name) : clk ("clk"),
45 i ("i")
46
47 {
48 SC_METHOD(f);
49 dont_initialize();
50 sensitive << clk.pos();
51#ifdef SYSTEMCASS_SPECIFIC
52#endif
53 }
54};
55
56struct generator : sc_module
57{
58 sc_in_clk clk;
59
60 sc_out<data_type> o;
61 sc_in<data_type> i;
62
63 long long int t;
64
65 void f ()
66 {
67 t <<= 1;
68 t++;
69#if 0
70 cout << "0x" << hex << (MASK & t) << " ; ";
71#endif
72 o.write(t);
73 }
74
75 SC_HAS_PROCESS(generator);
76 generator(sc_module_name) : clk ("clk"),
77 o ("o")
78 {
79 t = 1;
80 SC_METHOD(f);
81 dont_initialize();
82 sensitive << clk.neg() << i;
83#ifdef SYSTEMCASS_SPECIFIC
84 o(i);
85#endif
86 }
87};
88
89struct top_level : sc_module
90{
91 sc_in_clk clk;
92
93 sc_out<data_type> o;
94 sc_in <data_type> i;
95// sc_out<int> io;
96// sc_signal<int> s;
97// sc_signal<int> s2;
98
99 generator g;
100 observer obs1, obs2;
101
102 SC_HAS_PROCESS(top_level);
103 top_level(sc_module_name) : g ("generator"),
104 obs1("observer1"),
105 obs2("observer2"),
106 clk ("clk"),
107 o ("o"),
108 i ("i")/*,
109 s ("s")*/
110 {
111 g.clk (clk);
112 obs1.clk (clk);
113 obs2.clk (clk);
114
115 g.i (i);
116 g.o (o);
117 obs1.i(o);
118 obs2.i(o);
119
120#ifdef SYSTEMCASS_SPECIFIC
121 o (i); // wrong declaration that needs detection (no sc_method)
122#endif
123 }
124};
125
126int
127sc_main (int argc, char ** argv)
128{
129 int errnum = 0;
130 sc_clock clk("top_clk");
131 sc_signal<data_type> out("top_out");
132 sc_signal<data_type> in ("top_in");
133
134 top_level t("top_level");
135
136 t.clk (clk);
137 t.o (out);
138 t.i (in);
139
140 /* initilization */
141 sc_initialize ();
142
143 /* simulation */
144 int i = 0;
145 while (i++ < 40)
146 {
147 sc_start (1);
148 ASSERT(out.read() == t.obs1.i.read())
149 ASSERT(out.read() == t.obs2.i.read())
150 ASSERT(out.read() == (t.g.t & MASK) )
151 }
152
153 return 0;
154}
155
Note: See TracBrowser for help on using the repository browser.