1 /* Display a GHDL Wavefile for debugging.
2 Copyright (C) 2005 Tristan Gingold
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <gnu.org/licenses>.
27 static const char *progname
;
31 printf ("usage: %s [OPTIONS] FILEs...\n", progname
);
32 printf ("Options are:\n"
34 " -h display hierarchy\n"
35 " -H display hierarchy with full pathnames\n"
37 " -s display signals (and time)\n"
38 " -S display strings\n"
39 " -f <lst> list of signals to display (default: all, example: -f "
41 " -l display list of sections\n" " -v verbose\n");
45 add_single_signal (int **signalSet
, int *nbSignals
, int signal
)
47 assert (NULL
!= signalSet
);
48 assert (NULL
!= nbSignals
);
49 assert (0 <= nbSignals
[0]);
52 int newSize
= (1 + nbSignals
[0]);
53 /*printf("adding signal %6d set of signals to display\n", signal); */
54 signalSet
[0] = (int *) realloc (signalSet
[0], newSize
* sizeof (int));
55 signalSet
[0][nbSignals
[0]] = signal
;
56 nbSignals
[0] = newSize
;
60 add_signal_range (int **signalSet
, int *nbSignals
, const char *s
,
68 int bytesMatched
= -1;
69 int expected
= ((e
- s
) - 1);
71 sscanf (s
, "%d-%d%n", &rangeStart
, &rangeEnd
, &bytesMatched
);
72 if (2 == itemsMatched
&& expected
== bytesMatched
)
74 if (rangeEnd
< rangeStart
)
77 rangeEnd
= rangeStart
;
83 itemsMatched
= sscanf (s
, "%d%n", &rangeStart
, &bytesMatched
);
84 if (1 == itemsMatched
&& expected
== bytesMatched
)
88 rangeEnd
= rangeStart
;
93 rangeSize
= (rangeEnd
- rangeStart
);
94 if (rangeEnd
< 0 || rangeStart
< 0 || rangeSize
< 0)
97 "incorrect signal range specification\"%s\" found in "
98 "command line, aborting\n", s
);
102 for (i
= rangeStart
; i
<= rangeEnd
; ++i
)
104 add_single_signal (signalSet
, nbSignals
, i
);
109 add_signals (int **signalSet
, int *nbSignals
, const char *arg
)
113 const char *s
= e
= arg
;
117 if (',' == c
|| 0 == c
)
119 add_signal_range (signalSet
, nbSignals
, s
, e
);
126 disp_string_table (struct ghw_handler
*hp
)
129 printf ("String table:\n");
131 for (i
= 1; i
< hp
->nbr_str
; i
++)
132 printf (" %s\n", hp
->str_table
[i
]);
136 main (int argc
, char **argv
)
140 int flag_disp_hierarchy
;
142 int flag_disp_signals
;
143 int flag_disp_strings
;
155 flag_disp_hierarchy
= 0;
158 flag_disp_signals
= 0;
159 flag_disp_strings
= 0;
166 /* Disp help if there is only an help option. */
168 && (strcmp (argv
[1], "--help") == 0 || strcmp (argv
[1], "-h") == 0))
178 c
= getopt (argc
, argv
, "thHTsSlvf:");
187 flag_disp_hierarchy
= 1;
190 flag_disp_hierarchy
= 1;
197 flag_disp_signals
= 1;
201 flag_disp_strings
= 1;
204 add_signals (&signal_set
, &nb_signals
, optarg
);
224 for (i
= optind
; i
< argc
; i
++)
226 struct ghw_handler h
;
227 struct ghw_handler
*hp
= &h
;
229 hp
->flag_verbose
= flag_verbose
;
231 if (ghw_open (hp
, argv
[i
]) != 0)
233 fprintf (stderr
, "cannot open ghw file %s\n", argv
[i
]);
240 const char *section_name
;
243 section
= ghw_read_section (hp
);
246 printf ("eof of file\n");
249 else if (section
< 0)
251 printf ("Error in file\n");
254 else if (section
== 0)
256 printf ("Unknown section\n");
259 section_name
= ghw_sections
[section
].name
;
260 printf ("Section %s\n", section_name
);
261 if ((*ghw_sections
[section
].handler
) (hp
) < 0)
264 if (flag_disp_strings
&& strcmp (section_name
, "STR") == 0)
265 disp_string_table (hp
);
266 else if (flag_disp_types
&& strcmp (section_name
, "TYP") == 0)
272 if (ghw_read_base (hp
) < 0)
274 fprintf (stderr
, "cannot read ghw file\n");
279 if (flag_disp_hierarchy
)
281 hp
->flag_full_names
= flag_full_names
;
282 ghw_disp_hie (hp
, hp
->hie
);
290 switch (ghw_read_sm (hp
, &sm
))
292 case ghw_res_snapshot
:
295 printf ("Time is " GHWPRI64
" fs\n", hp
->snap_time
);
296 if (flag_disp_signals
)
300 ghw_filter_signals (hp
, signal_set
, nb_signals
);
303 ghw_disp_values (hp
);
315 if (ghw_read_dump (hp
) < 0)
317 fprintf (stderr
, "error in ghw dump\n");