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