1 /* GHDL Wavefile reader library.
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>.
26 /* Reopen H through decompressor DECOMP. */
29 ghw_openz (struct ghw_handler
*h
, const char *decomp
, const char *filename
)
31 int plen
= strlen (decomp
) + 1 + strlen (filename
) + 1;
32 char *p
= malloc (plen
);
34 snprintf (p
, plen
, "%s %s", decomp
, filename
);
36 h
->stream
= popen (p
, "r");
39 if (h
->stream
== NULL
)
48 ghw_open (struct ghw_handler
*h
, const char *filename
)
52 h
->stream
= fopen (filename
, "rb");
53 if (h
->stream
== NULL
)
56 if (fread (hdr
, sizeof (hdr
), 1, h
->stream
) != 1)
59 /* Check compression layer. */
60 if (!memcmp (hdr
, "\x1f\x8b", 2))
62 if (ghw_openz (h
, "gzip -cd", filename
) < 0)
64 if (fread (hdr
, sizeof (hdr
), 1, h
->stream
) != 1)
67 else if (!memcmp (hdr
, "BZ", 2))
69 if (ghw_openz (h
, "bzip2 -cd", filename
) < 0)
71 if (fread (hdr
, sizeof (hdr
), 1, h
->stream
) != 1)
80 if (memcmp (hdr
, "GHDLwave\n", 9) != 0)
83 if (hdr
[9] != 16 || hdr
[10] != 0)
90 else if (hdr
[12] == 2)
106 else if (v
.b
[0] == 0x44)
111 if (hdr
[12] != 1 && hdr
[12] != 2)
113 if (hdr
[12] != endian
)
119 h
->word_len
= hdr
[13];
120 h
->off_len
= hdr
[14];
130 ghw_get_i32 (struct ghw_handler
*h
, unsigned char *b
)
133 return (b
[0] << 24) | (b
[1] << 16) | (b
[2] << 8) | (b
[3] << 0);
135 return (b
[3] << 24) | (b
[2] << 16) | (b
[1] << 8) | (b
[0] << 0);
139 ghw_get_i64 (struct ghw_handler
*ghw_h
, unsigned char *b
)
145 h
= (b
[0] << 24) | (b
[1] << 16) | (b
[2] << 8) | (b
[3] << 0);
146 l
= (b
[4] << 24) | (b
[5] << 16) | (b
[6] << 8) | (b
[7] << 0);
150 l
= (b
[3] << 24) | (b
[2] << 16) | (b
[1] << 8) | (b
[0] << 0);
151 h
= (b
[7] << 24) | (b
[6] << 16) | (b
[5] << 8) | (b
[4] << 0);
153 return (((int64_t) h
) << 32) | l
;
157 ghw_read_byte (struct ghw_handler
*h
, unsigned char *res
)
161 v
= fgetc (h
->stream
);
169 ghw_read_uleb128 (struct ghw_handler
*h
, uint32_t * res
)
172 unsigned int off
= 0;
176 int v
= fgetc (h
->stream
);
179 r
|= (v
& 0x7f) << off
;
189 ghw_read_sleb128 (struct ghw_handler
*h
, int32_t * res
)
192 unsigned int off
= 0;
196 int v
= fgetc (h
->stream
);
199 r
|= ((int32_t) (v
& 0x7f)) << off
;
203 if ((v
& 0x40) && off
< 32)
213 ghw_read_lsleb128 (struct ghw_handler
*h
, int64_t * res
)
215 static const int64_t r_mask
= -1;
217 unsigned int off
= 0;
221 int v
= fgetc (h
->stream
);
224 r
|= ((int64_t) (v
& 0x7f)) << off
;
228 if ((v
& 0x40) && off
< 64)
238 ghw_read_f64 (struct ghw_handler
*h
, double *res
)
240 /* FIXME: handle byte order. */
241 if (fread (res
, sizeof (*res
), 1, h
->stream
) != 1)
247 ghw_read_strid (struct ghw_handler
*h
)
251 if (ghw_read_uleb128 (h
, &id
) != 0)
253 return h
->str_table
[id
];
257 ghw_read_typeid (struct ghw_handler
*h
)
261 if (ghw_read_uleb128 (h
, &id
) != 0)
263 return h
->types
[id
- 1];
267 ghw_read_range (struct ghw_handler
*h
)
269 int t
= fgetc (h
->stream
);
274 case ghdl_rtik_type_b2
:
276 struct ghw_range_b2
*r
;
277 r
= malloc (sizeof (struct ghw_range_b2
));
279 r
->dir
= (t
& 0x80) != 0;
280 if (ghw_read_byte (h
, &r
->left
) != 0)
282 if (ghw_read_byte (h
, &r
->right
) != 0)
284 return (union ghw_range
*) r
;
289 case ghdl_rtik_type_e8
:
291 struct ghw_range_e8
*r
;
292 r
= malloc (sizeof (struct ghw_range_e8
));
294 r
->dir
= (t
& 0x80) != 0;
295 if (ghw_read_byte (h
, &r
->left
) != 0)
297 if (ghw_read_byte (h
, &r
->right
) != 0)
299 return (union ghw_range
*) r
;
304 case ghdl_rtik_type_i32
:
305 case ghdl_rtik_type_p32
:
307 struct ghw_range_i32
*r
;
308 r
= malloc (sizeof (struct ghw_range_i32
));
310 r
->dir
= (t
& 0x80) != 0;
311 if (ghw_read_sleb128 (h
, &r
->left
) != 0)
313 if (ghw_read_sleb128 (h
, &r
->right
) != 0)
315 return (union ghw_range
*) r
;
320 case ghdl_rtik_type_i64
:
321 case ghdl_rtik_type_p64
:
323 struct ghw_range_i64
*r
;
324 r
= malloc (sizeof (struct ghw_range_i64
));
326 r
->dir
= (t
& 0x80) != 0;
327 if (ghw_read_lsleb128 (h
, &r
->left
) != 0)
329 if (ghw_read_lsleb128 (h
, &r
->right
) != 0)
331 return (union ghw_range
*) r
;
336 case ghdl_rtik_type_f64
:
338 struct ghw_range_f64
*r
;
339 r
= malloc (sizeof (struct ghw_range_f64
));
341 r
->dir
= (t
& 0x80) != 0;
342 if (ghw_read_f64 (h
, &r
->left
) != 0)
344 if (ghw_read_f64 (h
, &r
->right
) != 0)
346 return (union ghw_range
*) r
;
352 fprintf (stderr
, "ghw_read_range: type %d unhandled\n", t
& 0x7f);
358 ghw_read_str (struct ghw_handler
*h
)
360 unsigned char hdr
[12];
365 if (fread (hdr
, sizeof (hdr
), 1, h
->stream
) != 1)
368 if (hdr
[0] != 0 || hdr
[1] != 0 || hdr
[2] != 0 || hdr
[3] != 0)
370 h
->nbr_str
= ghw_get_i32 (h
, &hdr
[4]);
372 h
->str_size
= ghw_get_i32 (h
, &hdr
[8]);
373 h
->str_table
= (char **) malloc ((h
->nbr_str
+ 1) * sizeof (char *));
374 h
->str_content
= (char *) malloc (h
->str_size
+ h
->nbr_str
+ 1);
378 printf ("Number of strings: %u\n", h
->nbr_str
- 1);
379 printf ("String table size: %u\n", h
->str_size
);
382 h
->str_table
[0] = "<anon>";
385 for (i
= 1; i
< h
->nbr_str
; i
++)
393 prev
= h
->str_table
[i
- 1];
394 for (j
= 0; j
< prev_len
; j
++)
399 c
= fgetc (h
->stream
);
402 if ((c
>= 0 && c
<= 31) || (c
>= 128 && c
<= 159))
408 if (h
->flag_verbose
> 1)
409 printf (" string %u (pl=%d): %s\n", i
, prev_len
, h
->str_table
[i
]);
415 c
= fgetc (h
->stream
);
418 prev_len
|= (c
& 0x1f) << sh
;
422 if (fread (hdr
, 4, 1, h
->stream
) != 1)
424 if (memcmp (hdr
, "EOS", 4) != 0)
430 ghw_get_base_type (union ghw_type
*t
)
434 case ghdl_rtik_type_b2
:
435 case ghdl_rtik_type_e8
:
436 case ghdl_rtik_type_e32
:
437 case ghdl_rtik_type_i32
:
438 case ghdl_rtik_type_i64
:
439 case ghdl_rtik_type_f64
:
440 case ghdl_rtik_type_p32
:
441 case ghdl_rtik_type_p64
:
442 case ghdl_rtik_type_array
:
444 case ghdl_rtik_subtype_scalar
:
446 case ghdl_rtik_subtype_array
:
448 case ghdl_rtik_subtype_unbounded_array
:
451 fprintf (stderr
, "ghw_get_base_type: cannot handle type %d\n", t
->kind
);
456 /* Return -1 for unbounded types. */
458 get_nbr_elements (union ghw_type
*t
)
462 case ghdl_rtik_type_b2
:
463 case ghdl_rtik_type_e8
:
464 case ghdl_rtik_type_e32
:
465 case ghdl_rtik_type_i32
:
466 case ghdl_rtik_type_i64
:
467 case ghdl_rtik_type_f64
:
468 case ghdl_rtik_type_p32
:
469 case ghdl_rtik_type_p64
:
470 case ghdl_rtik_subtype_scalar
:
472 case ghdl_rtik_type_array
:
474 case ghdl_rtik_subtype_array
:
475 return t
->sa
.nbr_scalars
;
476 case ghdl_rtik_type_record
:
477 return t
->rec
.nbr_scalars
;
478 case ghdl_rtik_subtype_record
:
479 return t
->sr
.nbr_scalars
;
480 case ghdl_rtik_subtype_unbounded_record
:
481 case ghdl_rtik_subtype_unbounded_array
:
484 fprintf (stderr
, "get_nbr_elements: unhandled type %d\n", t
->kind
);
490 ghw_get_range_length (union ghw_range
*rng
)
494 assert (rng
!= NULL
);
498 case ghdl_rtik_type_i32
:
500 res
= rng
->i32
.left
- rng
->i32
.right
+ 1;
502 res
= rng
->i32
.right
- rng
->i32
.left
+ 1;
504 case ghdl_rtik_type_b2
:
506 res
= rng
->b2
.left
- rng
->b2
.right
+ 1;
508 res
= rng
->b2
.right
- rng
->b2
.left
+ 1;
510 case ghdl_rtik_type_e8
:
512 res
= rng
->e8
.left
- rng
->e8
.right
+ 1;
514 res
= rng
->e8
.right
- rng
->e8
.left
+ 1;
517 fprintf (stderr
, "get_range_length: unhandled kind %d\n", rng
->kind
);
520 /* The length of a null range is 0. */
521 return (res
<= 0) ? 0 : res
;
524 static union ghw_type
*ghw_read_type_bounds (struct ghw_handler
*h
,
525 union ghw_type
*base
);
527 /* Create an array subtype using BASE and ranges read from H. */
529 struct ghw_subtype_array
*
530 ghw_read_array_subtype (struct ghw_handler
*h
, union ghw_type
*base
)
532 struct ghw_type_array
*arr
=
533 (struct ghw_type_array
*) ghw_get_base_type (base
);
534 struct ghw_subtype_array
*sa
;
539 sa
= malloc (sizeof (struct ghw_subtype_array
));
540 sa
->kind
= ghdl_rtik_subtype_array
;
543 nbr_els
= get_nbr_elements (arr
->el
);
545 sa
->rngs
= malloc (arr
->nbr_dim
* sizeof (union ghw_range
*));
546 for (j
= 0; j
< arr
->nbr_dim
; j
++)
548 sa
->rngs
[j
] = ghw_read_range (h
);
549 nbr_scalars
*= ghw_get_range_length (sa
->rngs
[j
]);
553 /* Element type is bounded. */
558 /* Read bounds for the elements. */
559 sa
->el
= ghw_read_type_bounds (h
, arr
->el
);
560 nbr_els
= get_nbr_elements (sa
->el
);
562 sa
->nbr_scalars
= nbr_scalars
* nbr_els
;
566 struct ghw_subtype_record
*
567 ghw_read_record_subtype (struct ghw_handler
*h
, struct ghw_type_record
*base
)
569 struct ghw_subtype_record
*sr
;
571 sr
= malloc (sizeof (struct ghw_subtype_record
));
572 sr
->kind
= ghdl_rtik_subtype_record
;
575 if (base
->nbr_scalars
>= 0)
577 /* Record base type is bounded. */
578 sr
->nbr_scalars
= base
->nbr_scalars
;
588 malloc (base
->nbr_fields
* sizeof (struct ghw_record_element
));
590 for (j
= 0; j
< base
->nbr_fields
; j
++)
592 union ghw_type
*btype
= base
->els
[j
].type
;
593 int el_nbr_scalars
= get_nbr_elements (btype
);
595 sr
->els
[j
].name
= base
->els
[j
].name
;
596 if (el_nbr_scalars
>= 0)
598 /* Element is constrained. */
599 sr
->els
[j
].type
= btype
;
603 sr
->els
[j
].type
= ghw_read_type_bounds (h
, btype
);
604 el_nbr_scalars
= get_nbr_elements (sr
->els
[j
].type
);
606 nbr_scalars
+= el_nbr_scalars
;
608 sr
->nbr_scalars
= nbr_scalars
;
613 /* Read bounds for BASE and create a subtype. */
615 static union ghw_type
*
616 ghw_read_type_bounds (struct ghw_handler
*h
, union ghw_type
*base
)
620 case ghdl_rtik_type_array
:
621 case ghdl_rtik_subtype_unbounded_array
:
622 return (union ghw_type
*) ghw_read_array_subtype (h
, base
);
624 case ghdl_rtik_type_record
:
625 case ghdl_rtik_subtype_unbounded_record
:
626 return (union ghw_type
*) ghw_read_record_subtype (h
, &base
->rec
);
629 fprintf (stderr
, "ghw_read_type_bounds: unhandled kind %d\n",
636 ghw_read_type (struct ghw_handler
*h
)
638 unsigned char hdr
[8];
641 if (fread (hdr
, sizeof (hdr
), 1, h
->stream
) != 1)
644 if (hdr
[0] != 0 || hdr
[1] != 0 || hdr
[2] != 0 || hdr
[3] != 0)
646 h
->nbr_types
= ghw_get_i32 (h
, &hdr
[4]);
648 (union ghw_type
**) malloc (h
->nbr_types
* sizeof (union ghw_type
*));
650 for (i
= 0; i
< h
->nbr_types
; i
++)
654 t
= fgetc (h
->stream
);
657 if (h
->flag_verbose
> 1)
658 printf ("type[%u]= %d\n", i
, t
);
661 case ghdl_rtik_type_b2
:
662 case ghdl_rtik_type_e8
:
664 struct ghw_type_enum
*e
;
667 e
= malloc (sizeof (struct ghw_type_enum
));
669 e
->wkt
= ghw_wkt_unknown
;
670 e
->name
= ghw_read_strid (h
);
671 if (ghw_read_uleb128 (h
, &e
->nbr
) != 0)
673 e
->lits
= (const char **) malloc (e
->nbr
* sizeof (char *));
674 if (h
->flag_verbose
> 1)
675 printf ("enum %s:", e
->name
);
676 for (j
= 0; j
< e
->nbr
; j
++)
678 e
->lits
[j
] = ghw_read_strid (h
);
679 if (h
->flag_verbose
> 1)
680 printf (" %s", e
->lits
[j
]);
682 if (h
->flag_verbose
> 1)
684 h
->types
[i
] = (union ghw_type
*) e
;
692 case ghdl_rtik_type_i32
:
693 case ghdl_rtik_type_i64
:
694 case ghdl_rtik_type_f64
:
696 struct ghw_type_scalar
*sc
;
698 sc
= malloc (sizeof (struct ghw_type_scalar
));
700 sc
->name
= ghw_read_strid (h
);
701 if (h
->flag_verbose
> 1)
702 printf ("scalar: %s\n", sc
->name
);
703 h
->types
[i
] = (union ghw_type
*) sc
;
705 case ghdl_rtik_type_p32
:
706 case ghdl_rtik_type_p64
:
708 struct ghw_type_physical
*ph
;
710 ph
= malloc (sizeof (struct ghw_type_physical
));
712 ph
->name
= ghw_read_strid (h
);
720 if (ghw_read_uleb128 (h
, &ph
->nbr_units
) != 0)
722 ph
->units
= malloc (ph
->nbr_units
* sizeof (struct ghw_unit
));
723 for (j
= 0; j
< ph
->nbr_units
; j
++)
725 ph
->units
[j
].name
= ghw_read_strid (h
);
726 if (ghw_read_lsleb128 (h
, &ph
->units
[j
].val
) < 0)
730 if (h
->flag_verbose
> 1)
731 printf ("physical: %s\n", ph
->name
);
732 h
->types
[i
] = (union ghw_type
*) ph
;
740 case ghdl_rtik_subtype_scalar
:
742 struct ghw_subtype_scalar
*ss
;
744 ss
= malloc (sizeof (struct ghw_subtype_scalar
));
746 ss
->name
= ghw_read_strid (h
);
747 ss
->base
= ghw_read_typeid (h
);
748 ss
->rng
= ghw_read_range (h
);
749 if (h
->flag_verbose
> 1)
750 printf ("subtype scalar: %s\n", ss
->name
);
751 h
->types
[i
] = (union ghw_type
*) ss
;
753 case ghdl_rtik_type_array
:
755 struct ghw_type_array
*arr
;
758 arr
= malloc (sizeof (struct ghw_type_array
));
760 arr
->name
= ghw_read_strid (h
);
761 arr
->el
= ghw_read_typeid (h
);
762 if (ghw_read_uleb128 (h
, &arr
->nbr_dim
) != 0)
765 (union ghw_type
**) malloc (arr
->nbr_dim
*
766 sizeof (union ghw_type
*));
767 for (j
= 0; j
< arr
->nbr_dim
; j
++)
768 arr
->dims
[j
] = ghw_read_typeid (h
);
769 if (h
->flag_verbose
> 1)
770 printf ("array: %s (ndim=%u) of %s\n", arr
->name
, arr
->nbr_dim
,
771 arr
->el
->common
.name
);
772 h
->types
[i
] = (union ghw_type
*) arr
;
780 case ghdl_rtik_subtype_array
:
782 struct ghw_subtype_array
*sa
;
784 union ghw_type
*base
;
786 name
= ghw_read_strid (h
);
787 base
= ghw_read_typeid (h
);
789 sa
= ghw_read_array_subtype (h
, base
);
791 h
->types
[i
] = (union ghw_type
*) sa
;
792 if (h
->flag_verbose
> 1)
793 printf ("subtype array: %s (nbr_scalars=%d)\n", sa
->name
,
797 case ghdl_rtik_subtype_unbounded_array
:
799 struct ghw_subtype_unbounded_array
*sua
;
801 sua
= malloc (sizeof (struct ghw_subtype_unbounded_array
));
803 sua
->name
= ghw_read_strid (h
);
804 sua
->base
= ghw_read_typeid (h
);
805 h
->types
[i
] = (union ghw_type
*) sua
;
806 if (h
->flag_verbose
> 1)
807 printf ("subtype unbounded array: %s\n", sua
->name
);
810 case ghdl_rtik_type_record
:
812 struct ghw_type_record
*rec
;
816 rec
= malloc (sizeof (struct ghw_type_record
));
818 rec
->name
= ghw_read_strid (h
);
820 if (ghw_read_uleb128 (h
, &rec
->nbr_fields
) != 0)
823 malloc (rec
->nbr_fields
* sizeof (struct ghw_record_element
));
825 for (j
= 0; j
< rec
->nbr_fields
; j
++)
827 rec
->els
[j
].name
= ghw_read_strid (h
);
828 rec
->els
[j
].type
= ghw_read_typeid (h
);
829 if (nbr_scalars
!= -1)
831 int field_nbr_scalars
=
832 get_nbr_elements (rec
->els
[j
].type
);
833 if (field_nbr_scalars
== -1)
836 nbr_scalars
+= field_nbr_scalars
;
839 rec
->nbr_scalars
= nbr_scalars
;
840 if (h
->flag_verbose
> 1)
841 printf ("record type: %s (nbr_scalars=%d)\n", rec
->name
,
843 h
->types
[i
] = (union ghw_type
*) rec
;
851 case ghdl_rtik_subtype_record
:
853 struct ghw_subtype_record
*sr
;
855 struct ghw_type_record
*base
;
857 name
= ghw_read_strid (h
);
858 base
= (struct ghw_type_record
*) ghw_read_typeid (h
);
860 sr
= ghw_read_record_subtype (h
, base
);
862 h
->types
[i
] = (union ghw_type
*) sr
;
863 if (h
->flag_verbose
> 1)
864 printf ("subtype record: %s (nbr_scalars=%d)\n", sr
->name
,
868 case ghdl_rtik_subtype_unbounded_record
:
870 struct ghw_subtype_unbounded_record
*sur
;
872 sur
= malloc (sizeof (struct ghw_subtype_unbounded_record
));
874 sur
->name
= ghw_read_strid (h
);
875 sur
->base
= (struct ghw_type_record
*) ghw_read_typeid (h
);
876 h
->types
[i
] = (union ghw_type
*) sur
;
877 if (h
->flag_verbose
> 1)
878 printf ("subtype unbounded record: %s\n", sur
->name
);
882 fprintf (stderr
, "ghw_read_type: unknown type %d\n", t
);
886 if (fgetc (h
->stream
) != 0)
892 ghw_read_wk_types (struct ghw_handler
*h
)
896 if (fread (hdr
, sizeof (hdr
), 1, h
->stream
) != 1)
899 if (hdr
[0] != 0 || hdr
[1] != 0 || hdr
[2] != 0 || hdr
[3] != 0)
907 t
= fgetc (h
->stream
);
913 tid
= ghw_read_typeid (h
);
914 if (tid
->kind
== ghdl_rtik_type_b2
|| tid
->kind
== ghdl_rtik_type_e8
)
916 if (h
->flag_verbose
> 0)
917 printf ("%s: wkt=%d\n", tid
->en
.name
, t
);
925 ghw_disp_typename (struct ghw_handler
*h
, union ghw_type
*t
)
928 printf ("%s", t
->common
.name
);
931 /* Read a signal composed of severals elements.
932 Return 0 for success. */
934 ghw_read_signal (struct ghw_handler
*h
, unsigned int *sigs
, union ghw_type
*t
)
938 case ghdl_rtik_type_b2
:
939 case ghdl_rtik_type_e8
:
940 case ghdl_rtik_type_e32
:
941 case ghdl_rtik_subtype_scalar
:
945 if (ghw_read_uleb128 (h
, &sig_el
) < 0)
948 if (sig_el
== 0 || sig_el
>= h
->nbr_sigs
)
950 if (h
->sigs
[sig_el
].type
== NULL
)
951 h
->sigs
[sig_el
].type
= ghw_get_base_type (t
);
954 case ghdl_rtik_subtype_array
:
960 len
= t
->sa
.nbr_scalars
;
961 stride
= get_nbr_elements (t
->sa
.el
);
963 for (i
= 0; i
< len
; i
+= stride
)
964 if (ghw_read_signal (h
, &sigs
[i
], t
->sa
.el
) < 0)
968 case ghdl_rtik_type_record
:
970 struct ghw_type_record
*r
= &t
->rec
;
971 int nbr_fields
= r
->nbr_fields
;
976 for (i
= 0; i
< nbr_fields
; i
++)
978 if (ghw_read_signal (h
, &sigs
[off
], r
->els
[i
].type
) < 0)
980 off
+= get_nbr_elements (r
->els
[i
].type
);
984 case ghdl_rtik_subtype_record
:
986 struct ghw_subtype_record
*sr
= &t
->sr
;
987 int nbr_fields
= sr
->base
->nbr_fields
;
992 for (i
= 0; i
< nbr_fields
; i
++)
994 if (ghw_read_signal (h
, &sigs
[off
], sr
->els
[i
].type
) < 0)
996 off
+= get_nbr_elements (sr
->els
[i
].type
);
1001 fprintf (stderr
, "ghw_read_signal: type kind %d unhandled\n", t
->kind
);
1007 ghw_read_value (struct ghw_handler
*h
,
1008 union ghw_val
*val
, union ghw_type
*type
)
1010 switch (ghw_get_base_type (type
)->kind
)
1012 case ghdl_rtik_type_b2
:
1015 v
= fgetc (h
->stream
);
1021 case ghdl_rtik_type_e8
:
1024 v
= fgetc (h
->stream
);
1030 case ghdl_rtik_type_i32
:
1031 case ghdl_rtik_type_p32
:
1034 if (ghw_read_sleb128 (h
, &v
) < 0)
1039 case ghdl_rtik_type_f64
:
1042 if (ghw_read_f64 (h
, &v
) < 0)
1047 case ghdl_rtik_type_p64
:
1050 if (ghw_read_lsleb128 (h
, &v
) < 0)
1056 fprintf (stderr
, "read_value: cannot handle format %d\n", type
->kind
);
1063 ghw_read_hie (struct ghw_handler
*h
)
1065 unsigned char hdr
[16];
1069 struct ghw_hie
*blk
;
1070 struct ghw_hie
**last
;
1072 if (fread (hdr
, sizeof (hdr
), 1, h
->stream
) != 1)
1075 if (hdr
[0] != 0 || hdr
[1] != 0 || hdr
[2] != 0 || hdr
[3] != 0)
1077 nbr_scopes
= ghw_get_i32 (h
, &hdr
[4]);
1078 /* Number of declared signals (which may be composite). */
1079 nbr_sigs
= ghw_get_i32 (h
, &hdr
[8]);
1080 /* Number of basic signals. */
1081 h
->nbr_sigs
= ghw_get_i32 (h
, &hdr
[12]);
1083 if (h
->flag_verbose
)
1084 printf ("%d scopes, %d signals, %u signal elements\n", nbr_scopes
,
1085 nbr_sigs
, h
->nbr_sigs
);
1087 blk
= (struct ghw_hie
*) malloc (sizeof (struct ghw_hie
));
1088 blk
->kind
= ghw_hie_design
;
1091 blk
->brother
= NULL
;
1092 blk
->u
.blk
.child
= NULL
;
1094 last
= &blk
->u
.blk
.child
;
1098 h
->skip_sigs
= NULL
;
1099 h
->flag_full_names
= 0;
1100 h
->sigs
= (struct ghw_sig
*) malloc (h
->nbr_sigs
* sizeof (struct ghw_sig
));
1101 memset (h
->sigs
, 0, h
->nbr_sigs
* sizeof (struct ghw_sig
));
1109 t
= fgetc (h
->stream
);
1115 if (t
== ghw_hie_eos
)
1118 if (blk
->u
.blk
.child
== NULL
)
1119 last
= &blk
->u
.blk
.child
;
1122 struct ghw_hie
*l
= blk
->u
.blk
.child
;
1123 while (l
->brother
!= NULL
)
1131 el
= (struct ghw_hie
*) malloc (sizeof (struct ghw_hie
));
1138 last
= &el
->brother
;
1141 if (ghw_read_uleb128 (h
, &str
) != 0)
1143 el
->name
= h
->str_table
[str
];
1148 case ghw_hie_design
:
1150 /* Should not be here. */
1152 case ghw_hie_process
:
1153 el
->u
.blk
.child
= NULL
;
1156 case ghw_hie_generate_if
:
1157 case ghw_hie_generate_for
:
1158 case ghw_hie_instance
:
1159 case ghw_hie_generic
:
1160 case ghw_hie_package
:
1161 /* Create a block. */
1162 el
->u
.blk
.child
= NULL
;
1164 if (t
== ghw_hie_generate_for
)
1166 el
->u
.blk
.iter_type
= ghw_read_typeid (h
);
1167 el
->u
.blk
.iter_value
= malloc (sizeof (union ghw_val
));
1169 (h
, el
->u
.blk
.iter_value
, el
->u
.blk
.iter_type
) < 0)
1173 last
= &el
->u
.blk
.child
;
1175 case ghw_hie_signal
:
1176 case ghw_hie_port_in
:
1177 case ghw_hie_port_out
:
1178 case ghw_hie_port_inout
:
1179 case ghw_hie_port_buffer
:
1180 case ghw_hie_port_linkage
:
1181 /* For a signal, read type. */
1186 el
->u
.sig
.type
= ghw_read_typeid (h
);
1187 nbr_el
= get_nbr_elements (el
->u
.sig
.type
);
1191 (unsigned int *) malloc ((nbr_el
+ 1) * sizeof (unsigned int));
1192 el
->u
.sig
.sigs
= sigs
;
1193 /* Last element is NULL. */
1196 if (h
->flag_verbose
> 1)
1197 printf ("signal %s: %d el [", el
->name
, nbr_el
);
1198 if (ghw_read_signal (h
, sigs
, el
->u
.sig
.type
) < 0)
1200 if (h
->flag_verbose
> 1)
1203 for (j
= 0; j
< nbr_el
; j
++)
1204 printf (" #%u", sigs
[j
]);
1210 fprintf (stderr
, "ghw_read_hie: unhandled kind %d\n", t
);
1215 /* Allocate values. */
1216 for (i
= 0; i
< h
->nbr_sigs
; i
++)
1217 if (h
->sigs
[i
].type
!= NULL
)
1218 h
->sigs
[i
].val
= (union ghw_val
*) malloc (sizeof (union ghw_val
));
1223 ghw_get_hie_name (struct ghw_hie
*h
)
1229 case ghw_hie_design
:
1233 case ghw_hie_generate_if
:
1234 return "generate-if";
1235 case ghw_hie_generate_for
:
1236 return "generate-for";
1237 case ghw_hie_instance
:
1239 case ghw_hie_package
:
1241 case ghw_hie_process
:
1243 case ghw_hie_generic
:
1247 case ghw_hie_signal
:
1249 case ghw_hie_port_in
:
1251 case ghw_hie_port_out
:
1253 case ghw_hie_port_inout
:
1254 return "port-inout";
1255 case ghw_hie_port_buffer
:
1256 return "port-buffer";
1257 case ghw_hie_port_linkage
:
1258 return "port-linkage";
1264 void ghw_disp_value (union ghw_val
*val
, union ghw_type
*type
);
1267 print_name (struct ghw_hie
*hie
, int full_names
)
1272 struct ghw_hie
**buf
;
1273 struct ghw_hie
**end
;
1275 /* HIE must be valid. */
1276 assert (hie
->name
!= NULL
);
1278 if (0 == full_names
)
1280 printf (" %s: ", hie
->name
);
1286 while (p
&& p
->name
)
1291 buf
= (struct ghw_hie
**) malloc (depth
* sizeof (struct ghw_hie
*));
1295 while (p
&& p
->name
)
1303 for (i
= 0; i
< depth
; ++i
)
1305 printf ("%s%s", i
? "/" : "", buf
[i
]->name
);
1306 if (ghw_hie_generate_for
== buf
[i
]->kind
)
1309 ghw_disp_value (buf
[i
]->u
.blk
.iter_value
, buf
[i
]->u
.blk
.iter_type
);
1319 ghw_disp_hie (struct ghw_handler
*h
, struct ghw_hie
*top
)
1323 struct ghw_hie
*hie
;
1331 if (0 == h
->flag_full_names
)
1332 for (i
= 0; i
< indent
; i
++)
1333 fputc (' ', stdout
);
1334 printf ("%s", ghw_get_hie_name (hie
));
1338 case ghw_hie_design
:
1340 case ghw_hie_generate_if
:
1341 case ghw_hie_generate_for
:
1342 case ghw_hie_instance
:
1343 case ghw_hie_process
:
1344 case ghw_hie_package
:
1346 print_name (hie
, h
->flag_full_names
);
1347 if (hie
->kind
== ghw_hie_generate_for
)
1350 ghw_disp_value (hie
->u
.blk
.iter_value
, hie
->u
.blk
.iter_type
);
1353 n
= hie
->u
.blk
.child
;
1359 case ghw_hie_generic
:
1362 case ghw_hie_signal
:
1363 case ghw_hie_port_in
:
1364 case ghw_hie_port_out
:
1365 case ghw_hie_port_inout
:
1366 case ghw_hie_port_buffer
:
1367 case ghw_hie_port_linkage
:
1369 unsigned int *sigs
= hie
->u
.sig
.sigs
;
1370 unsigned int k
, num
;
1372 print_name (hie
, h
->flag_full_names
);
1373 ghw_disp_subtype_indication (h
, hie
->u
.sig
.type
);
1376 /* There can be 0-length signals. */
1377 while (sigs
[k
] != GHW_NO_SIG
)
1379 /* First signal of the range. */
1380 printf (" #%u", sigs
[k
]);
1381 for (num
= 1; sigs
[k
+ num
] != GHW_NO_SIG
; num
++)
1382 if (sigs
[k
+ num
] != sigs
[k
+ num
- 1] + 1)
1385 printf ("-#%u", sigs
[k
+ num
- 1]);
1398 if (hie
->parent
== NULL
)
1409 ghw_read_eoh (struct ghw_handler
*h
)
1416 ghw_read_base (struct ghw_handler
*h
)
1418 unsigned char hdr
[4];
1423 if (fread (hdr
, sizeof (hdr
), 1, h
->stream
) != 1)
1425 if (memcmp (hdr
, "STR", 4) == 0)
1426 res
= ghw_read_str (h
);
1427 else if (memcmp (hdr
, "HIE", 4) == 0)
1428 res
= ghw_read_hie (h
);
1429 else if (memcmp (hdr
, "TYP", 4) == 0)
1430 res
= ghw_read_type (h
);
1431 else if (memcmp (hdr
, "WKT", 4) == 0)
1432 res
= ghw_read_wk_types (h
);
1433 else if (memcmp (hdr
, "EOH", 4) == 0)
1437 fprintf (stderr
, "ghw_read_base: unknown GHW section %c%c%c%c\n",
1438 hdr
[0], hdr
[1], hdr
[2], hdr
[3]);
1443 fprintf (stderr
, "ghw_read_base: error in section %s\n", hdr
);
1450 ghw_read_signal_value (struct ghw_handler
*h
, struct ghw_sig
*s
)
1452 return ghw_read_value (h
, s
->val
, s
->type
);
1456 ghw_read_snapshot (struct ghw_handler
*h
)
1458 unsigned char hdr
[12];
1462 if (fread (hdr
, sizeof (hdr
), 1, h
->stream
) != 1)
1465 if (hdr
[0] != 0 || hdr
[1] != 0 || hdr
[2] != 0 || hdr
[3] != 0)
1467 h
->snap_time
= ghw_get_i64 (h
, &hdr
[4]);
1468 if (h
->flag_verbose
> 1)
1469 printf ("Time is " GHWPRI64
" fs\n", h
->snap_time
);
1471 for (i
= 0; i
< h
->nbr_sigs
; i
++)
1474 if (s
->type
!= NULL
)
1476 if (h
->flag_verbose
> 1)
1477 printf ("read type %d for sig %u\n", s
->type
->kind
, i
);
1478 if (ghw_read_signal_value (h
, s
) < 0)
1482 if (fread (hdr
, 4, 1, h
->stream
) != 1)
1485 if (memcmp (hdr
, "ESN", 4))
1491 void ghw_disp_values (struct ghw_handler
*h
);
1494 ghw_read_cycle_start (struct ghw_handler
*h
)
1496 unsigned char hdr
[8];
1498 if (fread (hdr
, sizeof (hdr
), 1, h
->stream
) != 1)
1501 h
->snap_time
= ghw_get_i64 (h
, hdr
);
1506 ghw_read_cycle_cont (struct ghw_handler
*h
, int *list
)
1517 /* Read delta to next signal. */
1518 if (ghw_read_uleb128 (h
, &d
) < 0)
1522 /* Last signal reached. */
1526 /* Find next signal. */
1530 if (h
->sigs
[i
].type
!= NULL
)
1534 if (ghw_read_signal_value (h
, &h
->sigs
[i
]) < 0)
1546 ghw_read_cycle_next (struct ghw_handler
*h
)
1550 if (ghw_read_lsleb128 (h
, &d_time
) < 0)
1554 h
->snap_time
+= d_time
;
1559 ghw_read_cycle_end (struct ghw_handler
*h
)
1563 if (fread (hdr
, sizeof (hdr
), 1, h
->stream
) != 1)
1565 if (memcmp (hdr
, "ECY", 4))
1572 ghw_get_lit (union ghw_type
*type
, unsigned e
)
1574 if (e
>= type
->en
.nbr
)
1577 return type
->en
.lits
[e
];
1581 ghw_disp_lit (union ghw_type
*type
, unsigned e
)
1583 printf ("%s (%u)", ghw_get_lit (type
, e
), e
);
1587 ghw_disp_value (union ghw_val
*val
, union ghw_type
*type
)
1589 switch (ghw_get_base_type (type
)->kind
)
1591 case ghdl_rtik_type_b2
:
1592 ghw_disp_lit (type
, val
->b2
);
1594 case ghdl_rtik_type_e8
:
1595 ghw_disp_lit (type
, val
->e8
);
1597 case ghdl_rtik_type_i32
:
1598 printf (GHWPRI32
, val
->i32
);
1600 case ghdl_rtik_type_p64
:
1601 printf (GHWPRI64
, val
->i64
);
1603 case ghdl_rtik_type_f64
:
1604 printf ("%g", val
->f64
);
1607 fprintf (stderr
, "ghw_disp_value: cannot handle type %d\n", type
->kind
);
1612 /* Put the ASCII representation of VAL into BUF, whose size if LEN.
1613 A NUL is always written to BUF.
1616 ghw_get_value (char *buf
, int len
, union ghw_val
*val
, union ghw_type
*type
)
1618 union ghw_type
*base
= ghw_get_base_type (type
);
1622 case ghdl_rtik_type_b2
:
1625 strncpy (buf
, base
->en
.lits
[val
->b2
], len
- 1);
1630 snprintf (buf
, len
, "?%d", val
->b2
);
1633 case ghdl_rtik_type_e8
:
1634 if (val
->b2
<= base
->en
.nbr
)
1636 strncpy (buf
, base
->en
.lits
[val
->e8
], len
- 1);
1641 snprintf (buf
, len
, "?%d", val
->e8
);
1644 case ghdl_rtik_type_i32
:
1645 snprintf (buf
, len
, GHWPRI32
, val
->i32
);
1647 case ghdl_rtik_type_p64
:
1648 snprintf (buf
, len
, GHWPRI64
, val
->i64
);
1650 case ghdl_rtik_type_f64
:
1651 snprintf (buf
, len
, "%g", val
->f64
);
1654 snprintf (buf
, len
, "?bad type %d?", type
->kind
);
1659 is_skip_signal (int *signals_to_keep
, int nb_signals_to_keep
, int signal
)
1662 for (i
= 0; i
< nb_signals_to_keep
; ++i
)
1664 if (signal
== signals_to_keep
[i
])
1673 ghw_filter_signals (struct ghw_handler
*h
, int *signals_to_keep
,
1674 int nb_signals_to_keep
)
1678 if (0 < nb_signals_to_keep
&& 0 != signals_to_keep
)
1680 if (0 == h
->skip_sigs
)
1682 h
->skip_sigs
= (char *) malloc (sizeof (char) * h
->nbr_sigs
);
1684 for (i
= 0; i
< h
->nbr_sigs
; ++i
)
1687 is_skip_signal (signals_to_keep
, nb_signals_to_keep
, i
);
1692 if (0 != h
->skip_sigs
)
1694 free (h
->skip_sigs
);
1701 ghw_disp_values (struct ghw_handler
*h
)
1704 for (i
= 0; i
< h
->nbr_sigs
; i
++)
1706 struct ghw_sig
*s
= &h
->sigs
[i
];
1707 int skip
= (0 != h
->skip_sigs
&& (0 != h
->skip_sigs
[i
]));
1708 if (s
->type
!= NULL
&& !skip
)
1710 printf ("#%u: ", i
);
1711 ghw_disp_value (s
->val
, s
->type
);
1718 ghw_read_directory (struct ghw_handler
*h
)
1720 unsigned char hdr
[8];
1724 if (fread (hdr
, sizeof (hdr
), 1, h
->stream
) != 1)
1727 nbr_entries
= ghw_get_i32 (h
, &hdr
[4]);
1729 if (h
->flag_verbose
)
1730 printf ("Directory (%d entries):\n", nbr_entries
);
1732 for (i
= 0; i
< nbr_entries
; i
++)
1734 unsigned char ent
[8];
1737 if (fread (ent
, sizeof (ent
), 1, h
->stream
) != 1)
1740 pos
= ghw_get_i32 (h
, &ent
[4]);
1741 if (h
->flag_verbose
)
1742 printf (" %s at %d\n", ent
, pos
);
1745 if (fread (hdr
, 4, 1, h
->stream
) != 1)
1747 if (memcmp (hdr
, "EOD", 4))
1753 ghw_read_tailer (struct ghw_handler
*h
)
1755 unsigned char hdr
[8];
1758 if (fread (hdr
, sizeof (hdr
), 1, h
->stream
) != 1)
1761 pos
= ghw_get_i32 (h
, &hdr
[4]);
1763 if (h
->flag_verbose
)
1764 printf ("Tailer: directory at %d\n", pos
);
1769 ghw_read_sm_hdr (struct ghw_handler
*h
, int *list
)
1771 unsigned char hdr
[4];
1774 if (fread (hdr
, sizeof (hdr
), 1, h
->stream
) != 1)
1776 if (feof (h
->stream
))
1779 return ghw_res_error
;
1781 if (memcmp (hdr
, "SNP", 4) == 0)
1783 res
= ghw_read_snapshot (h
);
1786 return ghw_res_snapshot
;
1788 else if (memcmp (hdr
, "CYC", 4) == 0)
1790 res
= ghw_read_cycle_start (h
);
1793 res
= ghw_read_cycle_cont (h
, list
);
1797 return ghw_res_cycle
;
1799 else if (memcmp (hdr
, "DIR", 4) == 0)
1801 res
= ghw_read_directory (h
);
1803 else if (memcmp (hdr
, "TAI", 4) == 0)
1805 res
= ghw_read_tailer (h
);
1809 fprintf (stderr
, "unknown GHW section %c%c%c%c\n", hdr
[0], hdr
[1],
1815 return ghw_res_other
;
1819 ghw_read_sm (struct ghw_handler
*h
, enum ghw_sm_type
*sm
)
1825 /* printf ("sm: state = %d\n", *sm); */
1830 res
= ghw_read_sm_hdr (h
, NULL
);
1835 case ghw_res_snapshot
:
1847 printf ("Time is " GHWPRI64
" fs\n", h
->snap_time
);
1849 ghw_disp_values (h
);
1851 res
= ghw_read_cycle_next (h
);
1856 res
= ghw_read_cycle_cont (h
, NULL
);
1859 return ghw_res_cycle
;
1861 res
= ghw_read_cycle_end (h
);
1871 ghw_read_cycle (struct ghw_handler
*h
)
1875 res
= ghw_read_cycle_start (h
);
1880 res
= ghw_read_cycle_cont (h
, NULL
);
1885 printf ("Time is " GHWPRI64
" fs\n", h
->snap_time
);
1887 ghw_disp_values (h
);
1889 res
= ghw_read_cycle_next (h
);
1895 res
= ghw_read_cycle_end (h
);
1900 ghw_read_dump (struct ghw_handler
*h
)
1902 unsigned char hdr
[4];
1907 if (fread (hdr
, sizeof (hdr
), 1, h
->stream
) != 1)
1909 if (feof (h
->stream
))
1914 if (memcmp (hdr
, "SNP", 4) == 0)
1916 res
= ghw_read_snapshot (h
);
1918 ghw_disp_values (h
);
1920 else if (memcmp (hdr
, "CYC", 4) == 0)
1922 res
= ghw_read_cycle (h
);
1924 else if (memcmp (hdr
, "DIR", 4) == 0)
1926 res
= ghw_read_directory (h
);
1928 else if (memcmp (hdr
, "TAI", 4) == 0)
1930 res
= ghw_read_tailer (h
);
1934 fprintf (stderr
, "unknown GHW section %c%c%c%c\n", hdr
[0], hdr
[1],
1943 struct ghw_section ghw_sections
[] = { {"\0\0\0", NULL
},
1944 {"STR", ghw_read_str
},
1945 {"HIE", ghw_read_hie
},
1946 {"TYP", ghw_read_type
},
1947 {"WKT", ghw_read_wk_types
},
1948 {"EOH", ghw_read_eoh
},
1949 {"SNP", ghw_read_snapshot
},
1950 {"CYC", ghw_read_cycle
},
1951 {"DIR", ghw_read_directory
},
1952 {"TAI", ghw_read_tailer
}
1956 ghw_read_section (struct ghw_handler
*h
)
1958 unsigned char hdr
[4];
1961 if (fread (hdr
, sizeof (hdr
), 1, h
->stream
) != 1)
1963 if (feof (h
->stream
))
1969 for (i
= 1; i
< sizeof (ghw_sections
) / sizeof (*ghw_sections
); i
++)
1970 if (memcmp (hdr
, ghw_sections
[i
].name
, 4) == 0)
1973 fprintf (stderr
, "ghw_read_section: unknown GHW section %c%c%c%c\n", hdr
[0],
1974 hdr
[1], hdr
[2], hdr
[3]);
1979 ghw_close (struct ghw_handler
*h
)
1983 if (h
->stream_ispipe
)
1993 ghw_get_dir (int is_downto
)
1995 return is_downto
? "downto" : "to";
1999 ghw_disp_range (union ghw_type
*type
, union ghw_range
*rng
)
2003 case ghdl_rtik_type_b2
:
2004 printf ("%s %s %s", ghw_get_lit (type
, rng
->b2
.left
),
2005 ghw_get_dir (rng
->b2
.dir
), ghw_get_lit (type
, rng
->b2
.right
));
2007 case ghdl_rtik_type_e8
:
2008 printf ("%s %s %s", ghw_get_lit (type
, rng
->e8
.left
),
2009 ghw_get_dir (rng
->e8
.dir
), ghw_get_lit (type
, rng
->e8
.right
));
2011 case ghdl_rtik_type_i32
:
2012 case ghdl_rtik_type_p32
:
2013 printf (GHWPRI32
" %s " GHWPRI32
, rng
->i32
.left
,
2014 ghw_get_dir (rng
->i32
.dir
), rng
->i32
.right
);
2016 case ghdl_rtik_type_i64
:
2017 case ghdl_rtik_type_p64
:
2018 printf (GHWPRI64
" %s " GHWPRI64
, rng
->i64
.left
,
2019 ghw_get_dir (rng
->i64
.dir
), rng
->i64
.right
);
2021 case ghdl_rtik_type_f64
:
2022 printf ("%g %s %g", rng
->f64
.left
, ghw_get_dir (rng
->f64
.dir
),
2026 printf ("?(%d)", rng
->kind
);
2031 ghw_disp_array_subtype_bounds (struct ghw_subtype_array
*a
)
2034 struct ghw_type_array
*base
=
2035 (struct ghw_type_array
*) ghw_get_base_type (a
->base
);
2038 for (i
= 0; i
< base
->nbr_dim
; i
++)
2042 ghw_disp_range (base
->dims
[i
], a
->rngs
[i
]);
2048 ghw_disp_record_subtype_bounds (struct ghw_subtype_record
*sr
)
2050 struct ghw_type_record
*base
= sr
->base
;
2054 for (i
= 0; i
< base
->nbr_fields
; i
++)
2056 if (sr
->els
[i
].type
!= base
->els
[i
].type
)
2065 printf ("%s", base
->els
[i
].name
);
2066 switch (sr
->els
[i
].type
->kind
)
2068 case ghdl_rtik_subtype_array
:
2069 ghw_disp_array_subtype_bounds (&sr
->els
[i
].type
->sa
);
2071 case ghdl_rtik_subtype_record
:
2072 ghw_disp_record_subtype_bounds (&sr
->els
[i
].type
->sr
);
2075 printf ("??? (%d)", sr
->els
[i
].type
->kind
);
2084 ghw_disp_subtype_definition (struct ghw_handler
*h
, union ghw_type
*t
)
2088 case ghdl_rtik_subtype_scalar
:
2090 struct ghw_subtype_scalar
*s
= &t
->ss
;
2091 ghw_disp_typename (h
, s
->base
);
2093 ghw_disp_range (s
->base
, s
->rng
);
2095 case ghdl_rtik_subtype_array
:
2097 struct ghw_subtype_array
*a
= &t
->sa
;
2099 ghw_disp_typename (h
, (union ghw_type
*) a
->base
);
2100 ghw_disp_array_subtype_bounds (a
);
2102 case ghdl_rtik_subtype_record
:
2104 struct ghw_subtype_record
*sr
= &t
->sr
;
2106 ghw_disp_typename (h
, (union ghw_type
*) sr
->base
);
2107 ghw_disp_record_subtype_bounds (sr
);
2109 case ghdl_rtik_subtype_unbounded_array
:
2110 case ghdl_rtik_subtype_unbounded_record
:
2112 struct ghw_subtype_unbounded_record
*sur
= &t
->sur
;
2114 ghw_disp_typename (h
, (union ghw_type
*) sur
->base
);
2117 printf ("ghw_disp_subtype_definition: unhandled type kind %d\n",
2123 ghw_is_anonymous_type (struct ghw_handler
*h
, union ghw_type
*t
)
2125 return t
->common
.name
== h
->str_table
[0];
2129 ghw_disp_subtype_indication (struct ghw_handler
*h
, union ghw_type
*t
)
2131 if (ghw_is_anonymous_type (h
, t
))
2133 /* Anonymous subtype. */
2134 ghw_disp_subtype_definition (h
, t
);
2137 ghw_disp_typename (h
, t
);
2141 ghw_disp_type (struct ghw_handler
*h
, union ghw_type
*t
)
2145 case ghdl_rtik_type_b2
:
2146 case ghdl_rtik_type_e8
:
2148 struct ghw_type_enum
*e
= &t
->en
;
2151 printf ("type %s is (", e
->name
);
2152 for (i
= 0; i
< e
->nbr
; i
++)
2156 printf ("%s", e
->lits
[i
]);
2159 if (e
->wkt
!= ghw_wkt_unknown
)
2160 printf (" -- WKT:%d", e
->wkt
);
2164 case ghdl_rtik_type_i32
:
2165 case ghdl_rtik_type_f64
:
2167 struct ghw_type_scalar
*s
= &t
->sc
;
2168 printf ("type %s is range <>;\n", s
->name
);
2170 case ghdl_rtik_type_p32
:
2171 case ghdl_rtik_type_p64
:
2175 struct ghw_type_physical
*p
= &t
->ph
;
2176 printf ("type %s is range <> units\n", p
->name
);
2177 for (i
= 0; i
< p
->nbr_units
; i
++)
2179 struct ghw_unit
*u
= &p
->units
[i
];
2180 printf (" %s = " GHWPRI64
" %s;\n", u
->name
, u
->val
,
2183 printf ("end units;\n");
2185 case ghdl_rtik_type_array
:
2187 struct ghw_type_array
*a
= &t
->ar
;
2190 printf ("type %s is array (", a
->name
);
2191 for (i
= 0; i
< a
->nbr_dim
; i
++)
2195 ghw_disp_typename (h
, a
->dims
[i
]);
2196 printf (" range <>");
2199 ghw_disp_subtype_indication (h
, a
->el
);
2203 case ghdl_rtik_type_record
:
2205 struct ghw_type_record
*r
= &t
->rec
;
2208 printf ("type %s is record\n", r
->name
);
2209 for (i
= 0; i
< r
->nbr_fields
; i
++)
2211 printf (" %s: ", r
->els
[i
].name
);
2212 ghw_disp_subtype_indication (h
, r
->els
[i
].type
);
2215 printf ("end record;\n");
2218 case ghdl_rtik_subtype_array
:
2219 case ghdl_rtik_subtype_scalar
:
2220 case ghdl_rtik_subtype_record
:
2221 case ghdl_rtik_subtype_unbounded_array
:
2222 case ghdl_rtik_subtype_unbounded_record
:
2224 struct ghw_type_common
*c
= &t
->common
;
2225 printf ("subtype %s is ", c
->name
);
2226 ghw_disp_subtype_definition (h
, t
);
2230 printf ("ghw_disp_type: unhandled type kind %d\n", t
->kind
);
2235 ghw_disp_types (struct ghw_handler
*h
)
2239 for (i
= 0; i
< h
->nbr_types
; i
++)
2240 if (h
->flag_verbose
|| !ghw_is_anonymous_type (h
, h
->types
[i
]))
2241 ghw_disp_type (h
, h
->types
[i
]);