source: latest/test_regression/17022006/system.cpp @ 1

Last change on this file since 1 was 1, checked in by buchmann, 17 years ago

Initial import from CVS repository

File size: 2.4 KB
Line 
1#include <systemc.h>
2
3#define ASSERT(x) \
4  { errnum++; \
5    if (!(x)) \
6    { \
7    cerr << "ASSERT : " #x "\n"; \
8    exit (errnum); \
9    } \
10  }
11
12using namespace std;
13
14struct test : sc_module {
15        sc_in_clk                       clk;
16  sc_in<int>                      i1;
17  sc_in<bool>                     i2[4];
18  sc_out<int>                     o1;
19  sc_out<char>                    o2[3];
20
21  sc_signal<bool>                 reg1;
22  sc_signal<int>                  reg2;
23  sc_signal<int>                  reg3;
24  sc_signal<int>                  reg4[10];
25
26  void trans ()
27  {
28  }
29
30  void gen ()
31  {
32  }
33
34  SC_HAS_PROCESS(test);
35        test (sc_module_name n) : sc_module (n),
36    clk("clk"),
37    i1("i1"), 
38    o1("o1"),
39    reg1("reg1"),
40    reg2("reg2"),
41    reg3("reg3")
42  {
43                SC_METHOD(trans);
44                sensitive << clk.pos();
45    dont_initialize();
46                SC_METHOD(gen);
47                sensitive << clk.neg();
48    dont_initialize();
49#ifdef NONAME_RENAME
50    char str[100];
51    for (int i=0; i<3; i++ ) {
52      sprintf(str,"o2_%d", i);
53      o2[i].rename(str);
54    }
55    for (int i=0; i<4; i++ ) {
56      sprintf(str,"i2_%d", i);
57      i2[i].rename(str);
58    }
59    for (int i=0; i<10; i++ ) {
60      sprintf(str,"reg4_%d", i);
61      reg4[i].rename(str);
62    }
63#endif
64        };
65};
66
67int sc_main (int argc, char *argv[])
68{
69  int errnum = 0;
70        sc_clock        signal_clk("my_clock",1, 0.5);
71  sc_signal<int>     s01("s01");
72  sc_signal<bool>    s02_0("s02_0"), s02_1("s02_1"), s02_2("s02_2"), s02_3("s02_3");
73  sc_signal<int>     s03("s03");
74  sc_signal<char>    s04_0("s04_0"),s04_1("s04_1"),s04_2("s04_2");
75
76  test test1("test1");
77  test1.clk (signal_clk);
78  test1.i1 (s01);
79  test1.i2[0] (s02_0);
80  test1.i2[1] (s02_1);
81  test1.i2[2] (s02_2);
82  test1.i2[3] (s02_3);
83  test1.o1 (s03);
84  test1.o2[0] (s04_0);
85  test1.o2[1] (s04_1);
86  test1.o2[2] (s04_2);
87
88        // Init & run
89        sc_start (0);
90
91  ASSERT(strcmp (test1.o1.name (), "test1.o1") == 0);
92  ASSERT(strcmp (test1.i1.name (), "test1.i1") == 0);
93  ASSERT(strcmp (test1.reg1.name (), "test1.reg1") == 0);
94  ASSERT(strcmp (test1.reg2.basename (), "reg2") == 0);
95  ASSERT(strcmp (test1.reg3.name (), "test1.reg3") == 0);
96#if defined(NONAME_RENAME)
97  ASSERT(strcmp (test1.o2[1].name (), "test1.o2_1") == 0);
98  ASSERT(strcmp (test1.i2[2].basename (), "i2_2") == 0);
99  ASSERT(strcmp (test1.reg4[1].name (), "test1.reg4_1") == 0);
100  ASSERT(strcmp (test1.reg4[9].basename (), "reg4_9") == 0);
101#endif
102        return EXIT_SUCCESS;
103}
104
105#undef sc_inout
Note: See TracBrowser for help on using the repository browser.