#include #define ASSERT(x) \ { errnum++; \ if (!(x)) \ { \ cerr << "ASSERT : " #x "\n"; \ exit (errnum); \ } \ } using namespace std; struct inner : sc_module { sc_in_clk clk; sc_in i1; int reg; void save_state (FILE *fic) { cerr << "saving " << name () << "\n"; fprintf (fic, "%d\n", reg); } void restore_state (FILE *fic) { cerr << "restoring " << name () << "\n"; int i; fscanf (fic, "%d\n", &i); reg = i; } void trans () { reg = i1.read(); } SC_HAS_PROCESS(inner); inner (sc_module_name n) : sc_module (n), clk("clk"), i1("i1") { SC_METHOD(trans); sensitive << clk.pos(); dont_initialize(); #ifdef SYSTEMCASS_SPECIFIC SAVE_HANDLER(save_state); #endif }; }; struct test : sc_module { sc_in_clk clk; sc_in i1; sc_in i2; sc_in i3; inner inner1; int tab[16]; bool b; void trans () { b = i1.read() ^ b; tab[i3.read() % 16] = i2; } void save_state (FILE *fic) { cerr << "saving " << name () << "\n"; fprintf (fic, "%c\n", ((b)?'1':'0')); int i; for (i = 0; i < 16; ++i) { fprintf (fic, "%d\n", tab[i]); } } void restore_state (FILE *fic) { cerr << "restoring " << name () << "\n"; int j; fscanf (fic, "%d\n", &j); b = (j > 0); int i; for (i = 0; i < 16; ++i) { fscanf (fic, "%d\n", &j); tab[i] = j; } } SC_HAS_PROCESS(test); test (sc_module_name n) : sc_module (n), clk("clk"), i1("i1"), i2("i2"), i3("i3"), inner1 ("inner1") { SC_METHOD(trans); sensitive << clk.pos(); dont_initialize(); #ifdef SYSTEMCASS_SPECIFIC SAVE_HANDLER(save_state); #endif }; }; int usage (const char *com) { cout << "Usage :\n" << com << " [#cycles]\n"; return EXIT_FAILURE; } sc_signal s01 ("bool"); sc_signal s02 ("tab_index"), s03 ("value_to_write_in_tab"); void* func () { cerr << "func () at #" << sc_time_stamp () << endl; int i = (int)(sc_time_stamp ().to_double ()) / 1000; s01 = (i & 1) > 0; s02 = (i + (i << 1)) << 6; s03 = i; ++i; return 0; } int sc_main (int argc, char *argv[]) { int errnum = 0; sc_clock signal_clk("my_clock",1, 0.5); test test1("test1"); test1.clk (signal_clk); test1.i1 (s01); test1.i2 (s02); test1.i3 (s03); test1.inner1.clk (signal_clk); test1.inner1.i1 (s02); // Init & run sc_start (0); #ifndef SOCVIEW if (argc != 2) { return usage (argv[0]); } int nb = atoi(argv[1]); if (nb == 0) { return usage (argv[0]); } int i = 0; while (i++ < nb) { func (); sc_start (1); } #else debug(&func); #endif return EXIT_SUCCESS; }