11#include < unistd.h>
22#include < getopt.h>
33
4+ #ifdef DUMP_WAVE_VCD
45#include < verilated_vcd_c.h>
6+ #elif DUMP_WAVE_FST
7+ #include < verilated_fst_c.h>
8+ #endif
59#include < verilated.h>
610#include < VysyxSoCFull.h>
711
@@ -26,47 +30,53 @@ class Emulator
2630 flash_init (args.image );
2731
2832 printf (" Initializing and resetting DUT ...\n " );
29- dut_ptr = new VysyxSoCFull;
30- dut_ptr ->reset = 1 ;
33+ dutPtr = new VysyxSoCFull;
34+ dutPtr ->reset = 1 ;
3135 for (int i = 0 ; i < 10 ; i++)
3236 {
33- dut_ptr ->clock = 0 ;
34- dut_ptr ->eval ();
35- dut_ptr ->clock = 1 ;
36- dut_ptr ->eval ();
37+ dutPtr ->clock = 0 ;
38+ dutPtr ->eval ();
39+ dutPtr ->clock = 1 ;
40+ dutPtr ->eval ();
3741 }
38- dut_ptr ->clock = 0 ;
39- dut_ptr ->reset = 0 ;
40- dut_ptr ->eval ();
42+ dutPtr ->clock = 0 ;
43+ dutPtr ->reset = 0 ;
44+ dutPtr ->eval ();
4145
42- if (args.dump_wave )
46+ if (args.dumpWave )
4347 {
48+ #ifdef DUMP_WAVE_VCD
49+ wavePtr = new VerilatedVcdC;
50+ #elif DUMP_WAVE_FST
51+ wavePtr = new VerilatedFstC;
52+ #endif
4453 Verilated::traceEverOn (true );
45- printf (" `dump-wave` enabled, waves will be written to \" soc.vcd\" .\n " );
46- fp = new VerilatedVcdC;
47- dut_ptr->trace (fp, 1 );
48- fp->open (" soc.vcd" );
49- fp->dump (0 );
54+ printf (" `dump-wave` enabled, waves will be written to \" soc.wave\" .\n " );
55+ dutPtr->trace (wavePtr, 1 );
56+ wavePtr->open (" soc.wave" );
57+ wavePtr->dump (0 );
5058 }
5159 }
5260 ~Emulator ()
5361 {
54- if (args.dump_wave )
62+ if (args.dumpWave )
5563 {
56- fp ->close ();
57- delete fp ;
64+ wavePtr ->close ();
65+ delete wavePtr ;
5866 }
5967 }
6068
6169 void step ()
6270 {
63- dut_ptr ->clock = 1 ;
64- dut_ptr ->eval ();
71+ dutPtr ->clock = 1 ;
72+ dutPtr ->eval ();
6573 cycle++;
66- if (args.dump_wave && args.dump_begin <= cycle && cycle <= args.dump_end )
67- fp->dump ((vluint64_t )cycle);
68- dut_ptr->clock = 0 ;
69- dut_ptr->eval ();
74+ if (args.dumpWave && args.dumpBegin <= cycle && cycle <= args.dumpEnd )
75+ {
76+ wavePtr->dump ((vluint64_t )cycle);
77+ }
78+ dutPtr->clock = 0 ;
79+ dutPtr->eval ();
7080 }
7181
7282 unsigned long long get_cycle ()
@@ -77,7 +87,6 @@ class Emulator
7787private:
7888 void parseArgs (int argc, char *argv[])
7989 {
80-
8190 int long_index;
8291 const struct option long_options[] = {
8392 {" dump-wave" , 0 , NULL , 0 },
@@ -97,7 +106,7 @@ class Emulator
97106 switch (long_index)
98107 {
99108 case 0 :
100- args.dump_wave = true ;
109+ args.dumpWave = true ;
101110 continue ;
102111 }
103112 // fall through
@@ -108,10 +117,10 @@ class Emulator
108117 args.image = optarg;
109118 break ;
110119 case ' b' :
111- args.dump_begin = atoll (optarg);
120+ args.dumpBegin = atoll (optarg);
112121 break ;
113122 case ' e' :
114- args.dump_end = atoll (optarg);
123+ args.dumpEnd = atoll (optarg);
115124 break ;
116125 }
117126 }
@@ -123,24 +132,33 @@ class Emulator
123132 {
124133 printf (" Usage: %s [OPTION...]\n " , file);
125134 printf (" \n " );
126- printf (" -i, --image=FILE run with this image file\n " );
127- printf (" --dump-wave dump waveform when log is enabled\n " );
128- printf (" -b, --log-begin=NUM display log from NUM th cycle\n " );
129- printf (" -e, --log-end=NUM stop display log at NUM th cycle\n " );
130- printf (" -h, --help print program help info\n " );
135+ printf (" -i, --image=FILE run with this image file\n " );
136+ printf (" --dump-wave dump vcd(fst) format waveform when log is enabled.\n " );
137+ printf (" recommand use fst format, becuase fst format wave\n " );
138+ printf (" file is much smaller than vcd format. You need to\n " );
139+ printf (" change compiler option in Makefile to switch format.\n " );
140+ printf (" -b, --log-begin=NUM display log from NUM th cycle\n " );
141+ printf (" -e, --log-end=NUM stop display log at NUM th cycle\n " );
142+ printf (" -h, --help print program help info\n " );
131143 printf (" \n " );
132144 }
133145
134146 unsigned long long cycle = 0 ;
135147
136148 struct Args
137149 {
138- bool dump_wave = false ;
139- unsigned long dump_begin = 0 ;
140- unsigned long dump_end = -1 ;
150+ bool dumpWave = false ;
151+ unsigned long dumpBegin = 0 ;
152+ unsigned long dumpEnd = -1 ;
141153 const char *image = nullptr ;
142154 } args;
143155
144- VysyxSoCFull *dut_ptr = nullptr ;
145- VerilatedVcdC *fp = nullptr ;
156+ VysyxSoCFull *dutPtr = nullptr ;
157+
158+ #ifdef DUMP_WAVE_VCD
159+ VerilatedVcdC *wavePtr = nullptr ;
160+ #elif DUMP_WAVE_FST
161+ VerilatedFstC *wavePtr = nullptr ;
162+ #endif
163+
146164};
0 commit comments