Changeset 55 for sources/test_regression/19122005
- Timestamp:
- May 28, 2013, 11:17:14 AM (11 years ago)
- Location:
- sources/test_regression/19122005
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
sources/test_regression/19122005/system.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 5 11 6 12 7 using namespace std; 13 8 9 14 10 struct test : sc_module { 15 sc_in_clk clk; 16 sc_in<bool> i1; 17 sc_in<int> i2; 18 sc_in<int> i3; 19 #if 0 20 sc_in<sc_int<4> > i4; 21 sc_in<sc_uint<4> > i5; 22 #endif 23 #if 0 24 sc_in<sc_uint<64> > i6; 25 #endif 26 sc_out<bool> o1; 27 sc_out<int> o2; 28 sc_out<int > o3; 29 #if 0 30 sc_out<sc_int<4> > o4; 31 sc_out<sc_uint<4> > o5; 32 #endif 33 #if 0 34 sc_out<sc_uint<64> > o6; 35 sc_inout<sc_uint<64> > io1; 36 #endif 37 // sc_inout<sc_signed > io2; 38 // sc_inout<sc_unsigned > io3; 39 sc_inout<sc_uint<32> > io4; 40 sc_out<int> mealy1; 41 sc_out<int> mealy2; 11 sc_in_clk clk; 12 sc_in<bool> i1; 13 sc_in<int> i2; 14 sc_in<int> i3; 15 sc_out<bool> o1; 16 sc_out<int> o2; 17 sc_out<int> o3; 18 sc_inout< sc_uint<32> > io4; 19 sc_out<int> mealy1; 20 sc_out<int> mealy2; 42 21 43 sc_signal<bool> reg1; 44 sc_signal<int> reg2; 45 sc_signal<int> reg3; 46 #if 0 47 sc_signal<sc_int<4> > reg4; 48 sc_signal<sc_uint<4> > reg5; 49 #endif 50 #if 0 51 sc_signal<sc_uint<64> > reg6; 52 #endif 53 // sc_signal<sc_signed > reg7; 54 // sc_signal<sc_unsigned > reg8; 55 sc_signal<sc_uint<32> > reg9; 56 sc_signal<int> reg10; 22 sc_signal<bool> reg1; 23 sc_signal<int> reg2; 24 sc_signal<int> reg3; 25 sc_signal<sc_uint<32> > reg9; 26 sc_signal<int> reg10; 57 27 58 void fmealy1 () 59 { 60 mealy1 = i2.read(); 61 } 28 void fmealy1() { 29 mealy1 = i2.read(); 30 } 62 31 63 void fmealy2 () 64 { 65 mealy2 = i2.read() + reg2.read(); 66 } 32 void fmealy2() { 33 mealy2 = i2.read() + reg2.read(); 34 } 67 35 68 void gen () 69 { 70 o1 = reg1.read() ^ true; 71 o2 = reg2.read()+ 1; 72 o3 = reg3.read()+ 1; 73 // o4 = reg4.read()+ 1; 74 // o5 = reg5.read()+ 1; 75 // o6 = reg6.read()+ 1; 76 // io1 = reg6.read() * 2 + 1; 77 io4 = reg9.read()+ 1; 78 } 36 void gen() { 37 o1 = reg1.read() ^ true; 38 o2 = reg2.read() + 1; 39 o3 = reg3.read() + 1; 40 io4 = reg9.read() + 1; 41 } 79 42 80 void trans () 81 { 82 // io2 = io2.read() + 1; 83 // io3 = io3.read() + 1; 84 reg1 = reg1.read() ^ 1; 85 reg2 = reg2.read() + 1; 86 reg3 = reg3.read() + 1; 87 // reg4 = reg4.read() + 1; 88 // reg5 = reg5.read() + 1; 89 // reg6 = reg6.read() * 2 + 1; 90 reg9 = reg9.read() + 2; 91 reg10 = reg10.read() + i2.read(); 92 } 43 void trans() { 44 reg1 = reg1.read() ^ 1; 45 reg2 = reg2.read() + 1; 46 reg3 = reg3.read() + 1; 47 reg9 = reg9.read() + 2; 48 reg10 = reg10.read() + i2.read(); 49 } 93 50 94 SC_HAS_PROCESS(test);95 test (sc_module_name n) : sc_module(n),51 SC_HAS_PROCESS(test); 52 test(sc_module_name n) : sc_module(n), 96 53 clk("clk"), 97 i1("i1"), i2("i2"), i3("i3"), /*i4("i4"), i5("i5"), */ /*i6("i6"),*/98 o1("o1"), o2("o2"), o3("o3"), /*o4("o4"), o5("o5"), */ /*o6("o6"),99 io 1("io1"), */io4("io4"),54 i1("i1"), i2("i2"), i3("i3"), 55 o1("o1"), o2("o2"), o3("o3"), 56 io4("io4"), 100 57 mealy1("mealy1_equivalent_to_i2"), 101 58 mealy2("mealy2_equivalent_to_i2_plus_reg2"), … … 103 60 reg2("reg2_cycle_number"), 104 61 reg3("reg3_cycle_number"), 105 // reg4("reg4"),106 // reg5("reg5"),107 // reg6("reg6"),108 // reg7("reg7"),109 // reg8("reg8"),110 62 reg9("reg9_cycle_number_x2"), 111 reg10("reg10_sum_cycle_number") 112 { 113 SC_METHOD(trans); 114 sensitive << clk.pos(); 115 dont_initialize(); 116 SC_METHOD(gen); 117 sensitive << clk.neg(); 118 dont_initialize(); 119 SC_METHOD(fmealy1); 120 sensitive << i2; 121 dont_initialize(); 122 SC_METHOD(fmealy2); 123 sensitive << i2 << clk.neg(); 124 dont_initialize(); 125 }; 63 reg10("reg10_sum_cycle_number") { 64 SC_METHOD(trans); 65 sensitive << clk.pos(); 66 dont_initialize(); 67 68 SC_METHOD(gen); 69 sensitive << clk.neg(); 70 dont_initialize(); 71 72 SC_METHOD(fmealy1); 73 sensitive << i2; 74 dont_initialize(); 75 76 SC_METHOD(fmealy2); 77 sensitive << i2 << clk.neg(); 78 dont_initialize(); 79 } 126 80 }; 127 81 128 int 129 usage (const char *com) 130 { 131 cout << "Usage :\n" << com << " [#cycles]\n"; 132 return EXIT_FAILURE; 82 83 int usage (const char * com) { 84 cout << "Usage :\n" << com << " [#cycles]\n"; 85 return EXIT_FAILURE; 133 86 } 134 87 135 sc_signal<bool> s01 ("i1_cycle_number_not_parity"),136 s02 ("o2_not_reg1");137 sc_signal<int> s03 ("i2_cycle_number_x2"),138 s04 ("o2_reg2_plus_one");139 sc_signal<int> s05 ("i3_cycle_number_x3"),140 s06 ("o3_reg3_plus_one");141 #if 0142 sc_signal<sc_int<4> > s07 ("s07"),143 s08 ("s08");144 sc_signal<sc_uint<4> > s09 ("s09"),145 s10 ("s10");146 #endif147 #if 0148 sc_signal<sc_uint<64> > s11 ("s11"),149 s12 ("s12"),150 s13 ("s13");151 #endif152 //sc_signal<sc_signed > s14("s14");153 //sc_signal<sc_unsigned > s15("s15");154 sc_signal<sc_uint<32> > s16 ("io4_reg9_plus_one");155 sc_signal<int> s17 ("mealy1_equivalent_to_i2");156 sc_signal<int> s18 ("mealy2_i2_plus_reg2");157 88 158 int 159 s (int i) 160 { 161 int val = 0; 162 while (i) 163 val += i--; 164 return val; 89 sc_signal<bool> s01("i1_cycle_number_not_parity"), s02("o2_not_reg1"); 90 sc_signal<int> s03("i2_cycle_number_x2"), s04("o2_reg2_plus_one"); 91 sc_signal<int> s05("i3_cycle_number_x3"), s06("o3_reg3_plus_one"); 92 sc_signal< sc_uint<32> > s16("io4_reg9_plus_one"); 93 sc_signal<int> s17("mealy1_equivalent_to_i2"); 94 sc_signal<int> s18("mealy2_i2_plus_reg2"); 95 96 97 int s(int i) { 98 int val = 0; 99 while (i) { 100 val += i--; 101 } 102 return val; 165 103 } 166 104 167 void* 168 func () 169 { 170 cerr << "func () at #" << sc_time_stamp () << endl; 171 int i = (int)(sc_time_stamp ().to_double ()) / 1000; 172 s01 = (i & 1) > 0; 173 s03 = i * 2; 174 s05 = i * 3; 175 // s07 = i * 4; 176 // s09 = i * 5; 177 // s11 = i * 6; 178 ++i; 179 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 s03 = i * 2; 111 s05 = i * 3; 112 ++i; 113 return 0; 180 114 } 181 115 182 void 183 save () 184 { 116 117 void save() { 185 118 #ifdef SYSTEMCASS_SPECIFIC 186 char name[256];187 sprintf (name,"test_systemcass_%d.dat",((int)sc_time_stamp().to_double() / 1000));188 sc_save_simulation(name);119 char name[256]; 120 sprintf(name, "test_systemcass_%d.dat", ((int) sc_time_stamp().to_double() / 1000)); 121 sc_save_simulation(name); 189 122 #endif 190 123 } 191 124 192 int sc_main (int argc, char *argv[])193 {194 int errnum = 0;195 sc_clock signal_clk("my_clock",1, 0.5);196 125 197 test test1("test1"); 198 test1.clk (signal_clk); 199 test1.i1 (s01); 200 test1.o1 (s02); 201 test1.i2 (s03); 202 test1.o2 (s04); 203 test1.i3 (s05); 204 test1.o3 (s06); 205 // test1.i4 (s07); 206 // test1.o4 (s08); 207 // test1.i5 (s09); 208 // test1.o5 (s10); 209 // test1.i6 (s11); 210 // test1.o6 (s12); 211 // test1.io1(s13); 212 // test1.io2(s14); 213 // test1.io3(s15); 214 test1.io4(s16); 215 test1.mealy1(s17); 216 test1.mealy2(s18); 126 int sc_main (int argc, char * argv[]) { 127 sc_clock signal_clk("my_clock", 1, 0.5); 217 128 218 // Init & run 219 sc_start (0); 129 test test1("test1"); 130 test1.clk(signal_clk); 131 test1.i1(s01); 132 test1.o1(s02); 133 test1.i2(s03); 134 test1.o2(s04); 135 test1.i3(s05); 136 test1.o3(s06); 137 test1.io4(s16); 138 test1.mealy1(s17); 139 test1.mealy2(s18); 140 141 // Init & run 142 sc_start(sc_time(0, sc_core::SC_NS)); 220 143 221 144 #ifndef SOCVIEW 222 if (argc != 2) 223 { 224 return usage (argv[0]); 225 } 145 if (argc != 2) { 146 return usage(argv[0]); 147 } 226 148 227 149 int nb = atoi(argv[1]); 228 150 229 if (nb == 0) 230 { 231 return usage (argv[0]); 232 } 151 if (nb == 0) { 152 return usage(argv[0]); 153 } 233 154 234 int i = 0; 235 save (); 236 while (i++ < nb) 237 { 238 func (); 239 sc_start (1); 240 save (); 241 } 155 int i = 0; 156 save(); 157 while (i++ < nb) { 158 func(); 159 sc_start(sc_time(1, sc_core::SC_NS)); 160 save(); 161 } 242 162 #else 243 debug(&func);163 debug(&func); 244 164 #endif 245 165 246 166 return EXIT_SUCCESS; 247 167 } 248 168 249 169 #undef sc_inout 170 171 /* 172 # Local Variables: 173 # tab-width: 4; 174 # c-basic-offset: 4; 175 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 176 # indent-tabs-mode: nil; 177 # End: 178 # 179 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 180 */ 181 -
sources/test_regression/19122005/system2.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 (ostream &o) 20 { 21 o << reg << endl; 22 } 14 void save(ostream & o) { 15 o << reg << endl; 16 } 23 17 24 void save_state (FILE *fic) 25 { 26 cerr << "saving " << name () << "\n"; 27 fprintf (fic, "%d\n", reg); 28 } 18 void save_state(FILE * fic) { 19 cerr << "saving " << name() << "\n"; 20 fprintf (fic, "%d\n", reg); 21 } 29 22 30 void restore_state (FILE *fic) 31 { 32 cerr << "restoring " << name () << "\n"; 33 int i; 34 fscanf (fic, "%d\n", &i); 35 reg = i; 36 } 23 void restore_state(FILE * fic) { 24 cerr << "restoring " << name () << "\n"; 25 int i; 26 fscanf (fic, "%d\n", &i); 27 reg = i; 28 } 37 29 38 void trans () 39 { 40 reg = i1.read(); 41 } 30 void trans() { 31 reg = i1.read(); 32 } 42 33 43 SC_HAS_PROCESS(inner);44 inner (sc_module_name n) : sc_module(n),34 SC_HAS_PROCESS(inner); 35 inner(sc_module_name n) : sc_module(n), 45 36 clk("clk"), 46 i1("i1") 47 { 48 SC_METHOD(trans); 49 sensitive << clk.pos(); 50 dont_initialize(); 37 i1("i1") { 38 SC_METHOD(trans); 39 sensitive << clk.pos(); 40 dont_initialize(); 51 41 #ifdef SYSTEMCASS_SPECIFIC 52 //SAVE_HANDLER(save); 53 SAVE_HANDLER(save_state); 42 SAVE_HANDLER(save_state); 54 43 #endif 55 }; 44 } 45 56 46 }; 57 47 48 58 49 struct test : sc_module { 59 sc_in_clkclk;60 sc_in<bool>i1;61 sc_in<int>i2;62 sc_in<int>i3;63 innerinner1;50 sc_in_clk clk; 51 sc_in<bool> i1; 52 sc_in<int> i2; 53 sc_in<int> i3; 54 inner inner1; 64 55 65 int tab[16];66 bool b;56 int tab[16]; 57 bool b; 67 58 68 void trans () 69 { 70 b = i1.read() ^ b; 71 tab[i3.read() % 16] = i2; 72 } 59 void trans() { 60 b = i1.read() ^ b; 61 tab[i3.read() % 16] = i2; 62 } 73 63 74 64 75 void save (ostream &o)76 {77 o << ((b)?1:0) << endl;78 int i;79 for (i = 0; i < 16; ++i)80 o << tab[i] << endl;81 }65 void save(ostream & o) { 66 o << ((b) ? 1 : 0) << endl; 67 int i; 68 for (i = 0; i < 16; ++i) { 69 o << tab[i] << endl; 70 } 71 } 82 72 83 void save_state (FILE *fic) 84 { 85 cerr << "saving " << name () << "\n"; 86 fprintf (fic, "%c\n", ((b)?'1':'0')); 87 int i; 88 for (i = 0; i < 16; ++i) 89 { 90 fprintf (fic, "%d\n", tab[i]); 73 void save_state(FILE * fic) { 74 cerr << "saving " << name() << "\n"; 75 fprintf (fic, "%c\n", ((b) ? '1' : '0')); 76 int i; 77 for (i = 0; i < 16; ++i) { 78 fprintf(fic, "%d\n", tab[i]); 79 } 91 80 } 92 }93 81 94 void restore_state (FILE *fic) 95 { 96 cerr << "restoring " << name () << "\n"; 97 int j; 98 fscanf (fic, "%d\n", &j); 99 b = (j > 0); 100 int i; 101 for (i = 0; i < 16; ++i) 102 { 103 fscanf (fic, "%d\n", &j); 104 tab[i] = j; 82 void restore_state(FILE * fic) { 83 cerr << "restoring " << name() << "\n"; 84 int j; 85 fscanf (fic, "%d\n", &j); 86 b = (j > 0); 87 int i; 88 for (i = 0; i < 16; ++i) { 89 fscanf(fic, "%d\n", &j); 90 tab[i] = j; 91 } 105 92 } 106 }107 93 108 SC_HAS_PROCESS(test);109 94 SC_HAS_PROCESS(test); 95 test (sc_module_name n) : sc_module (n), 110 96 clk("clk"), 111 97 i1("i1"), i2("i2"), i3("i3"), 112 inner1 ("inner1") 113 { 114 SC_METHOD(trans); 115 sensitive << clk.pos(); 116 dont_initialize(); 98 inner1 ("inner1") { 99 SC_METHOD(trans); 100 sensitive << clk.pos(); 101 dont_initialize(); 117 102 #ifdef SYSTEMCASS_SPECIFIC 118 //SAVE_HANDLER(save); 119 SAVE_HANDLER(save_state); 103 SAVE_HANDLER(save_state); 120 104 #endif 121 }; 105 } 106 122 107 }; 123 108 124 int 125 usage (const char *com) 126 { 127 cout << "Usage :\n" << com << " [#cycles]\n"; 128 return EXIT_FAILURE; 109 110 int usage (const char * com) { 111 cout << "Usage :\n" << com << " [#cycles]\n"; 112 return EXIT_FAILURE; 129 113 } 130 114 131 sc_signal<bool> s01 ("bool");132 sc_signal<int> s02 ("tab_index"),133 s03 ("value_to_write_in_tab");134 115 135 void* 136 func () 137 { 138 cerr << "func () at #" << sc_time_stamp () << endl; 139 int i = (int)(sc_time_stamp ().to_double ()) / 1000; 140 s01 = (i & 1) > 0; 141 s02 = (i + (i << 1)) << 6; 142 s03 = i; 143 ++i; 144 return 0; 116 sc_signal<bool> s01("bool"); 117 sc_signal<int> s02("tab_index"), 118 s03 ("value_to_write_in_tab"); 119 120 121 void * func() { 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; 145 129 } 146 130 147 void 148 save () 149 { 131 132 void save() { 150 133 #ifdef SYSTEMCASS_SPECIFIC 151 int current_cycle = ((int)sc_time_stamp().to_double() / 1000); 152 if (current_cycle != 20) 153 return; 154 char name[256]; 155 sprintf (name,"test2_systemcass_%d.dat",current_cycle); 156 sc_save_simulation (name); 134 int current_cycle = ((int) sc_time_stamp().to_double() / 1000); 135 if (current_cycle != 20) { 136 return; 137 } 138 char name[256]; 139 sprintf(name, "test2_systemcass_%d.dat", current_cycle); 140 sc_save_simulation(name); 157 141 #endif 158 142 } 159 143 160 int sc_main (int argc, char *argv[])161 {162 int errnum = 0;163 sc_clock signal_clk("my_clock",1, 0.5);164 144 165 test test1("test1"); 166 test1.clk (signal_clk); 167 test1.i1 (s01); 168 test1.i2 (s02); 169 test1.i3 (s03); 170 test1.inner1.clk (signal_clk); 171 test1.inner1.i1 (s02); 145 int sc_main (int argc, char * argv[]) { 146 sc_clock signal_clk("my_clock",1, 0.5); 172 147 173 // Init & run 174 sc_start (0); 148 test test1("test1"); 149 test1.clk(signal_clk); 150 test1.i1(s01); 151 test1.i2(s02); 152 test1.i3(s03); 153 test1.inner1.clk(signal_clk); 154 test1.inner1.i1(s02); 155 156 // Init & run 157 sc_start(sc_time(0, sc_core::SC_NS)); 175 158 176 159 #ifndef SOCVIEW 177 if (argc != 2) 178 { 179 return usage (argv[0]); 180 } 160 if (argc != 2) { 161 return usage(argv[0]); 162 } 181 163 182 164 int nb = atoi(argv[1]); 183 165 184 if (nb == 0) 185 { 186 return usage (argv[0]); 187 } 166 if (nb == 0) { 167 return usage(argv[0]); 168 } 188 169 189 int i = 0; 190 while (i++ < nb) 191 { 192 func (); 193 sc_start (1); 194 save (); 195 } 170 int i = 0; 171 while (i++ < nb) { 172 func(); 173 sc_start(sc_time(1, sc_core::SC_NS)); 174 save(); 175 } 196 176 #else 197 debug(&func);177 debug(&func); 198 178 #endif 199 179 200 180 return EXIT_SUCCESS; 201 181 } 202 182 183 184 /* 185 # Local Variables: 186 # tab-width: 4; 187 # c-basic-offset: 4; 188 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 189 # indent-tabs-mode: nil; 190 # End: 191 # 192 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 193 */ 194 -
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.