source: sources/test_regression/19122005/system3.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: 3.0 KB
Line 
1
2#include "systemc.h"
3#include "test.h"
4
5
6using namespace std;
7
8
9struct inner : sc_module {
10    sc_in_clk clk;
11    sc_in<int> i1;
12    int reg;
13
14    void save_state (FILE * fic) {
15        cerr << "saving " << name() << "\n";
16        fprintf (fic, "%d\n", reg);
17    }
18
19    void restore_state (FILE * fic) {
20        cerr << "restoring " << name() << "\n";
21        int i;
22        fscanf (fic, "%d\n", &i);
23        reg = i;
24    }
25
26    void trans() {
27        reg = i1.read();
28    }
29
30    SC_HAS_PROCESS(inner);
31    inner(sc_module_name n) : sc_module(n),
32    clk("clk"),
33    i1("i1") {
34        SC_METHOD(trans);
35        sensitive << clk.pos();
36        dont_initialize();
37#ifdef SYSTEMCASS_SPECIFIC
38        SAVE_HANDLER(save_state);
39#endif
40    }
41
42};
43
44
45struct test : sc_module {
46    sc_in_clk clk;
47    sc_in<bool> i1;
48    sc_in<int> i2;
49    sc_in<int> i3;
50    inner inner1;
51
52    int tab[16];
53    bool b;
54
55    void trans() {
56        b = i1.read() ^ b;
57        tab[i3.read() % 16] = i2;
58    }
59
60    void save_state (FILE * fic) {
61        cerr << "saving " << name() << "\n";
62        fprintf(fic, "%c\n", ((b) ? '1' : '0'));
63        int i;
64        for (i = 0; i < 16; ++i) {
65            fprintf(fic, "%d\n", tab[i]);
66        }
67    }
68
69    void restore_state(FILE * fic) {
70        cerr << "restoring " << name() << "\n";
71        int j;
72        fscanf (fic, "%d\n", &j);
73        b = (j > 0);
74        int i;
75        for (i = 0; i < 16; ++i) {
76            fscanf (fic, "%d\n", &j);
77            tab[i] = j;
78        }
79    }
80
81    SC_HAS_PROCESS(test);
82    test (sc_module_name n) : sc_module (n),
83    clk("clk"),
84    i1("i1"), i2("i2"), i3("i3"),
85    inner1 ("inner1") {
86        SC_METHOD(trans);
87        sensitive << clk.pos();
88        dont_initialize();
89#ifdef SYSTEMCASS_SPECIFIC
90        SAVE_HANDLER(save_state);
91#endif
92    }
93
94};
95
96
97int usage(const char * com) {
98    cout << "Usage :\n" << com << " [#cycles]\n";
99    return EXIT_FAILURE;
100}
101
102sc_signal<bool> s01("bool");
103sc_signal<int> s02("tab_index"), s03("value_to_write_in_tab");
104
105
106void * func() {
107    cerr << "func () at #" << sc_time_stamp() << endl;
108    int i = (int)(sc_time_stamp().to_double()) / 1000;
109    s01  = (i & 1) > 0;
110    s02  = (i + (i << 1)) << 6;
111    s03  = i;
112    ++i;
113    return 0;
114}
115
116
117int sc_main (int argc, char * argv[]) {
118    sc_clock signal_clk("my_clock", 1, 0.5);
119
120    test test1("test1");
121    test1.clk(signal_clk);
122    test1.i1(s01);
123    test1.i2(s02);
124    test1.i3(s03);
125    test1.inner1.clk(signal_clk);
126    test1.inner1.i1(s02);
127
128    // Init & run
129    sc_start(sc_time(0, sc_core::SC_NS));
130
131#ifndef SOCVIEW
132    if (argc != 2) {
133        return usage(argv[0]);
134    }
135
136    int nb = atoi(argv[1]);
137
138    if (nb == 0) {
139        return usage(argv[0]);
140    } 
141
142    int i = 0;
143    while (i++ < nb) {
144        func();
145        sc_start(sc_time(1, sc_core::SC_NS));
146    }
147#else
148    debug(&func); 
149#endif
150
151    return EXIT_SUCCESS;
152}
153
154
155/*
156# Local Variables:
157# tab-width: 4;
158# c-basic-offset: 4;
159# c-file-offsets:((innamespace . 0)(inline-open . 0));
160# indent-tabs-mode: nil;
161# End:
162#
163# vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
164*/
165
Note: See TracBrowser for help on using the repository browser.