source: sources/test_regression/15042009a/system.cpp @ 55

Last change on this file since 55 was 55, checked in by meunier, 11 years ago

Tried to clean the test_regression directory:

  • Code formatting
  • Supressed warnings
  • Made comprehensible outputs
  • Factorized Makefiles

There's still a lot to do (many tests don't pass for either good or bad reasons)

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