source: sources/test_regression/15092005a/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#include <iostream>
3
4#include "systemc.h"
5#include "test.h"
6
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
26struct generator : sc_module {
27    sc_in_clk clk;
28
29    sc_out<int> o;
30    sc_in<int> i;
31
32    void f() {
33        int t = (int) (sc_time_stamp().to_double());
34        o.write(t);
35    }
36
37    SC_HAS_PROCESS(generator);
38    generator(sc_module_name) : clk("clk"), o("o") {
39        SC_METHOD(f);
40        sensitive << clk.neg() << i;
41        dont_initialize();
42#ifdef SYSTEMCASS_SPECIFIC
43        o(i);
44#endif
45    }
46
47};
48
49
50struct top_level : sc_module {
51    sc_in_clk clk;
52
53    sc_out<int> o;
54    sc_in <int> i;
55
56    generator g;
57    observer obs1, obs2;
58
59    SC_HAS_PROCESS(top_level);
60    top_level(sc_module_name) :
61    clk("clk"),
62    o("o"),
63    i("i"),
64    g("generator"), 
65    obs1("observer1"),
66    obs2("observer2") {
67        g.clk(clk);
68        obs1.clk(clk);
69        obs2.clk(clk);
70
71        g.i(i);
72        g.o(o);
73        obs1.i(o);
74        obs2.i(o);
75
76#ifdef SYSTEMCASS_SPECIFIC
77        o(i); // wrong declaration that needs detection (no sc_method)
78#endif
79    }
80
81};
82
83
84int sc_main (int argc, char ** argv) {
85    sc_clock clk("top_clk");
86    sc_signal<int> out("top_out");
87    sc_signal<int> in ("top_in");
88
89    top_level t("top_level");
90
91    t.clk(clk);
92    t.o(out);
93    t.i(in);
94
95    sc_start(sc_time(0, sc_core::SC_NS));
96
97    int i = 0;
98    while (i++ < 5) {
99        sc_start(sc_time(1, sc_core::SC_NS));
100        ASSERT(out.read() == t.obs1.i.read());
101        ASSERT(out.read() == t.obs2.i.read());
102    }
103
104    cout << "OK" << endl;
105    return 0;
106}
107
108
109/*
110# Local Variables:
111# tab-width: 4;
112# c-basic-offset: 4;
113# c-file-offsets:((innamespace . 0)(inline-open . 0));
114# indent-tabs-mode: nil;
115# End:
116#
117# vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
118*/
119
Note: See TracBrowser for help on using the repository browser.