44 #define VCD_SKIP_ARRAYS 1
45 #define VCD_INCLUDE_RANGE 0
46 #define VCD_TIMEVAR "dtime"
61 for (scope = root; scope; scope = scope->
next) {
64 if (!strcmp (var->
code, code))
68 if ((var = vcd_find_code (scope->
scopes, code)) != NULL)
75 static void vcd_free_change (
struct vcd_change * vc) {
84 for (vc = cs->
changes; vc; vc = vnext) {
99 if (last) last = last->
next;
108 while (root != NULL) {
125 double Min = root ? root->
t : 0;
126 for (cs = root; cs; cs = cs->
next) {
127 if (!cs->done && cs->
t <= Min) {
141 if (!strcmp (vv->code, var->
code))
150 static void vcd_sort_changesets (
struct vcd_changeset * root) {
152 struct vcd_set * vs, * current = NULL;
158 root = vcd_reverse_changesets (root);
163 while ((cs = vcd_find_firstset_fast (root)) != NULL) {
165 while ((cs = vcd_find_firstset (root)) != NULL) {
168 if (current == NULL || current->
t != cs->
t) {
186 if (current->
t > 0) {
187 fprintf (stderr,
"vcd notice, duplicate value change at t = %g of "
188 "variable `%s'\n", current->
t, vc->
var->
ident);
216 while (scope && scope != vcd->
scopes) {
224 char * txt = (
char *) malloc (strlen (ident) + strlen (scope->
ident) + 2);
225 sprintf (txt,
"%s.%s", scope->
ident, ident);
236 vcd_create_variable (
struct vcd_vardef * var) {
238 int len = strlen (var->
ident) + 1;
244 #if VCD_INCLUDE_RANGE
245 if (var->
range) len += 32;
247 char * id1, * id2 = (
char *) malloc (len);
252 if (strstr (var->
ident,
"implicit_wait_for"))
256 if (strstr (var->
ident,
"net") == var->
ident) {
257 id1 = strdup (&var->
ident[3]);
259 id1 = strdup (var->
ident);
264 id1 = strdup (var->
ident);
269 id1 = strdup (var->
ident);
272 #if VCD_INCLUDE_RANGE
275 sprintf (id2,
"%s", id1);
276 }
else if (var->
range->
l == -1) {
278 sprintf (id2,
"%s[%d]", id1, var->
range->
h);
279 }
else if (var->
range->
h == -1) {
281 sprintf (id2,
"%s[%d]", id1, var->
range->
l);
284 sprintf (id2,
"%s[%d:%d]", id1, var->
range->
l, var->
range->
h);
287 sprintf (id2,
"%s", id1);
296 ds->
ident = strdup (id2);
298 ds->
ident = vcd_prepend_scopes (var, ds->
ident);
309 int i, len = strlen (vv->
value);
315 double val = strtod (vv->
value, NULL);
316 sprintf (txt,
"%+.11e", val);
317 value = strdup (txt);
321 long val = 0, bit, i = strlen (vv->
value) - 1;
322 for (bit = 1; i >= 0; i--, bit <<= 1) {
323 if (vv->
value[i] ==
'1')
325 else if (vv->
value[i] ==
'0')
328 sprintf (txt,
"%+ld", val);
329 value = strdup (txt);
331 }
else if (size == len) {
333 value = strdup (vv->
value);
336 value = (
char *) calloc (1, size + 1);
338 fill = (vv->
value[0] ==
'1') ?
'0' : vv->
value[0];
339 for (i = 0; i < size - len; i++) value[i] = fill;
340 strcpy (&value[i], vv->
value);
348 vcd_create_dataset (
struct vcd_vardef * var) {
353 char * currentval = NULL;
356 ds = vcd_create_variable (var);
359 for (vs = vcd_sets; vs; vs = vs->
next) {
363 if (!strcmp (vv->
code, var->
code)) {
367 dv->
value = vcd_create_value (vv, var->
size);
377 currentval = dv->
value;
386 fprintf (stderr,
"vcd error, variable `%s' has no initial value\n",
393 dv->
value = strdup (currentval);
417 ds->
ident = strdup (name);
421 for (vs = vcd_sets; vs; vs = vs->
next) {
426 sprintf (txt,
"%+.11e", vs->
t * vcd->
t * vcd->
scale);
427 dv->
value = strdup (txt);
439 static void vcd_prepare_variable_datasets (
struct vcd_scope * root) {
443 for (scope = root; scope; scope = scope->
next) {
447 data = vcd_create_dataset (var);
453 vcd_prepare_variable_datasets (scope->
scopes);
459 static void vcd_prepare_datasets (
void) {
462 vcd_prepare_variable_datasets (vcd->
scopes);
472 static void vcd_print_sets (
void) {
476 fprintf (stderr,
"--- t => %g\n", vs->
t);
484 static void vcd_dataset_print (
void) {
487 for (ds = dataset_root; ds; ds = ds->
next) {
488 fprintf (stderr,
"\n%s%s => %s\n",
504 for (changeset = vcd->
changesets; changeset; changeset = changeset->
next) {
506 for (change = changeset->
changes; change; change = change->
next) {
508 if (change->
var == NULL) {
509 fprintf (stderr,
"vcd error, no such variable reference `%s' "
510 "found\n", change->
code);
522 vcd_prepare_datasets ();
526 vcd_dataset_print ();
533 static void vcd_free_scope (
struct vcd_scope * root) {
535 for (vs = root; vs; vs = snext) {
539 for (vv = vs->
vardefs; vv; vv = vnext) {
546 vcd_free_scope (vs->
scopes);
552 static void vcd_free_file (
struct vcd_file * vcd) {
553 vcd_free_scope (vcd->
scopes);
557 vcd_free_changeset (cs);
563 static void vcd_free_set (
struct vcd_set * root) {
565 for (vs = root; vs; vs = snext) {
568 for (vv = vs->
variables; vv; vv = vnext) {
579 for (ds = root; ds; ds = snext) {
584 for (dv = ds->
values; dv; dv = dnext) {
598 vcd_free_set (vcd_sets);
600 vcd_free_dataset (dataset_root);