source: sources/test_regression/15092005d/system.cpp @ 60

Last change on this file since 60 was 60, checked in by meunier, 7 years ago
  • Intégration des modifications de Clément, qui a intégré la version parallélisée de systemcass faite par Manuel.
File size: 2.1 KB
Line 
1
2
3#include <iostream>
4
5#include "systemc.h"
6#include "test.h"
7
8using namespace std;
9
10struct observer : sc_module {
11    sc_in_clk clk;
12
13    sc_in<int> i;
14
15    void f() {}
16
17    SC_HAS_PROCESS(observer);
18    observer(sc_module_name) : clk("clk"), i("i") {
19        SC_METHOD(f);
20        sensitive << clk.pos();
21        dont_initialize();
22    }
23
24};
25
26
27struct generator : sc_module {
28    sc_in_clk clk;
29
30    sc_out<int> o;
31    sc_in<int>  i;
32
33    void f() {
34        int t = (int) (sc_time_stamp ().to_double());
35        o.write(t);
36    }
37
38    SC_HAS_PROCESS(generator);
39    generator(sc_module_name) : clk ("clk"), o("o") {
40        SC_METHOD(f);
41        sensitive << clk.neg() << i;
42        dont_initialize();
43#ifdef SYSTEMCASS_SPECIFIC
44        o(i);
45#endif
46    }
47
48};
49
50
51struct top_level : sc_module {
52    sc_in_clk clk;
53
54    sc_out<int> o;
55    sc_in <int> i;
56
57    generator g;
58    observer obs1, obs2;
59
60    SC_HAS_PROCESS(top_level);
61    top_level(sc_module_name) :
62    clk ("clk"),
63    o("o"),
64    i("i"),
65    g("generator"), 
66    obs1("observer1"),
67    obs2("observer2") {
68        g.clk(clk);
69        obs1.clk(clk);
70        obs2.clk(clk);
71
72        g.i(i);
73        g.o(o);
74        obs1.i(o);
75        obs2.i(o);
76
77#ifdef SYSTEMCASS_SPECIFIC
78        o(i); // wrong declaration that needs detection (no sc_method)
79#endif
80    }
81
82};
83
84
85int sc_main (int argc, char ** argv) {
86    sc_clock       clk("top_clk");
87    sc_signal<int> out("top_out");
88    sc_signal<int> in ("top_in");
89
90    top_level t("top_level");
91
92    // Setup number of threads open-mp to 1 with the macro threads_omp()
93    threads_omp();
94
95    t.clk(clk);
96    t.o(out);
97    t.i(in);
98
99#ifdef SYSTEMCASS_SPECIFIC
100    t.o(t.i);
101#endif
102
103    sc_start(sc_time(0, sc_core::SC_NS));
104
105    /* simulation */
106    int i = 0;
107    while (i++ < 5) {
108        sc_start(sc_time(1, sc_core::SC_NS));
109        ASSERT(out.read() == t.obs1.i.read());
110        ASSERT(out.read() == t.obs2.i.read());
111    }
112
113    return 0;
114}
115
116
117/*
118# Local Variables:
119# tab-width: 4;
120# c-basic-offset: 4;
121# c-file-offsets:((innamespace . 0)(inline-open . 0));
122# indent-tabs-mode: nil;
123# End:
124#
125# vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
126*/
127
Note: See TracBrowser for help on using the repository browser.