source: sources/test_regression/11062007/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.6 KB
Line 
1
2#include <signal.h>
3
4#include "systemc.h"
5
6#include "test.h"
7
8using namespace std;
9
10
11struct A : sc_module {
12    sc_in_clk clk;
13    sc_out<bool> o1;
14
15    void eval() {
16        o1 = (rand() % 2) == 0;
17    }
18
19    SC_CTOR(A) : clk ("clk"), o1("o1") {
20        SC_METHOD(eval);
21        sensitive << clk.neg();
22        dont_initialize();
23    }
24};
25
26
27struct B : sc_module {
28    sc_in_clk    clk;
29    sc_in<bool>  i1;
30    sc_in<bool>  i2;
31    sc_out<bool> o1;
32    sc_out<bool> o2;
33
34    void eval1() {
35        o1 = ~i1;
36    }
37
38    void eval2() {
39        o2 = ~i2;
40    }
41
42    SC_CTOR(B) : clk("clk"), i1("i1"), i2("i2"), o1("o1"), o2("o2") {
43        SC_METHOD(eval1);
44        sensitive << clk.neg();
45        sensitive << i1;
46        dont_initialize();
47#ifdef SYSTEMCASS_SPECIFIC
48        o1(i1);
49#endif
50        SC_METHOD(eval2);
51        sensitive << clk.neg();
52        sensitive << i2;
53        dont_initialize();
54#ifdef SYSTEMCASS_SPECIFIC
55        o2(i2);
56#endif
57    }
58};
59
60
61struct C : sc_module {
62    sc_in_clk    clk;
63    sc_in<bool>  i1;
64    sc_in<bool>  i2;
65    sc_out<bool> o1;
66
67    void eval1() {
68        o1 = i1 ^ i2;
69    }
70
71    SC_CTOR(C) : clk ("clk"), i1 ("i1"), i2("i2"), o1("o1") {
72        SC_METHOD(eval1);
73        sensitive << clk.neg();
74        sensitive << i1 << i2;
75        dont_initialize();
76#ifdef SYSTEMCASS_SPECIFIC
77        o1(i1);
78        o1(i2);
79#endif
80    }
81
82};
83
84
85struct D : sc_module {
86    sc_in_clk    clk;
87    sc_out<bool> o1;
88
89    void eval () {
90        o1 = (rand() % 2) == 0;
91    }
92
93    SC_CTOR(D) : clk ("clk"), o1("o1") {
94        SC_METHOD(eval);
95        sensitive << clk.neg();
96        dont_initialize();
97    }
98
99};
100
101
102int sc_main (int argc, char * argv[]) {
103    sc_clock signal_clk("my_clock",1, 0.5);
104    sc_signal<bool> s1("s1"),s2("s2"),s3("s3"),s4("s4"),s5("s5");
105
106    A a("a");
107    B b("b");
108    C c("c");
109    D d("d");
110
111    a.clk(signal_clk);
112    b.clk(signal_clk);
113    c.clk(signal_clk);
114    d.clk(signal_clk);
115
116    a.o1(s1);
117    b.i1(s1);
118
119    d.o1(s2);
120    c.i2(s2);
121
122    b.o1(s3);
123    c.i1(s3);
124
125    c.o1(s4);
126    b.i2(s4);
127
128    b.o2(s5);
129
130    // Init & run
131    sc_start(sc_time(0, sc_core::SC_NS));
132
133    if (argc == 1) {
134        cout << "Usage :\n" << argv[0] << " [#cycles]\n";
135        return EXIT_SUCCESS;
136    }
137
138    sc_start(sc_time(atoi(argv[1]), sc_core::SC_NS));
139
140    cout << s1.read() << endl;
141    cout << s2.read() << endl;
142    cout << s3.read() << endl;
143    cout << s4.read() << endl;
144    cout << s5.read() << endl;
145
146    return EXIT_SUCCESS;
147}
148
149/*
150# Local Variables:
151# tab-width: 4;
152# c-basic-offset: 4;
153# c-file-offsets:((innamespace . 0)(inline-open . 0));
154# indent-tabs-mode: nil;
155# End:
156#
157# vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
158*/
159
Note: See TracBrowser for help on using the repository browser.