source: sources/test_regression/15092005d/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.0 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    t.clk(clk);
93    t.o(out);
94    t.i(in);
95
96#ifdef SYSTEMCASS_SPECIFIC
97    t.o(t.i);
98#endif
99
100    sc_start(sc_time(0, sc_core::SC_NS));
101
102    /* simulation */
103    int i = 0;
104    while (i++ < 5) {
105        sc_start(sc_time(1, sc_core::SC_NS));
106        ASSERT(out.read() == t.obs1.i.read());
107        ASSERT(out.read() == t.obs2.i.read());
108    }
109
110    return 0;
111}
112
113
114/*
115# Local Variables:
116# tab-width: 4;
117# c-basic-offset: 4;
118# c-file-offsets:((innamespace . 0)(inline-open . 0));
119# indent-tabs-mode: nil;
120# End:
121#
122# vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
123*/
124
Note: See TracBrowser for help on using the repository browser.