aboutsummaryrefslogtreecommitdiffstats
path: root/src/grt
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2017-06-07 04:50:52 +0200
committerTristan Gingold <tgingold@free.fr>2017-06-07 04:50:52 +0200
commit761618ebc4e00fbf3642948f4220a18de002b8b1 (patch)
tree5f57b48b2fb2c4a2757c578cb8e65f25df338bfc /src/grt
parentbe0bbfc67b73988ed28319fd6173107cfee0449f (diff)
downloadghdl-761618ebc4e00fbf3642948f4220a18de002b8b1.tar.gz
ghdl-761618ebc4e00fbf3642948f4220a18de002b8b1.tar.bz2
ghdl-761618ebc4e00fbf3642948f4220a18de002b8b1.zip
ghwlib: provides format specifiers.
Diffstat (limited to 'src/grt')
-rw-r--r--src/grt/ghwlib.c39
-rw-r--r--src/grt/ghwlib.h19
2 files changed, 36 insertions, 22 deletions
diff --git a/src/grt/ghwlib.c b/src/grt/ghwlib.c
index 5bb867716..426a01973 100644
--- a/src/grt/ghwlib.c
+++ b/src/grt/ghwlib.c
@@ -332,8 +332,8 @@ ghw_read_str (struct ghw_handler *h)
if (h->flag_verbose)
{
- printf ("Number of strings: %d\n", h->nbr_str - 1);
- printf ("String table size: %d\n", h->str_size);
+ printf ("Number of strings: %u\n", h->nbr_str - 1);
+ printf ("String table size: %u\n", h->str_size);
}
h->str_table[0] = "<anon>";
@@ -364,7 +364,7 @@ ghw_read_str (struct ghw_handler *h)
*p++ = 0;
if (h->flag_verbose > 1)
- printf (" string %d (pl=%d): %s\n", i, prev_len, h->str_table[i]);
+ printf (" string %u (pl=%d): %s\n", i, prev_len, h->str_table[i]);
prev_len = c & 0x1f;
sh = 5;
@@ -482,7 +482,7 @@ ghw_read_array_subtype (struct ghw_handler *h, struct ghw_type_array *base)
for (j = 0; j < base->nbr_dim; j++)
{
sa->rngs[j] = ghw_read_range (h);
- nbr_scalars *= get_range_length (sa->rngs[j]);
+ nbr_scalars *= ghw_get_range_length (sa->rngs[j]);
}
sa->nbr_scalars = nbr_scalars;
return sa;
@@ -745,7 +745,7 @@ ghw_read_type (struct ghw_handler *h)
err_record:
free (rec->els);
free (rec);
- return NULL;
+ return -1;
}
break;
case ghdl_rtik_subtype_record:
@@ -970,7 +970,7 @@ ghw_read_hie (struct ghw_handler *h)
h->nbr_sigs = ghw_get_i32 (h, &hdr[12]);
if (h->flag_verbose)
- printf ("%d scopes, %d signals, %d signal elements\n",
+ printf ("%u scopes, %u signals, %u signal elements\n",
nbr_scopes, nbr_sigs, h->nbr_sigs);
blk = (struct ghw_hie *)malloc (sizeof (struct ghw_hie));
@@ -1355,7 +1355,7 @@ ghw_read_snapshot (struct ghw_handler *h)
return -1;
h->snap_time = ghw_get_i64 (h, &hdr[4]);
if (h->flag_verbose > 1)
- printf ("Time is %lld fs\n", h->snap_time);
+ printf ("Time is " GHWPRI64 " fs\n", h->snap_time);
for (i = 0; i < h->nbr_sigs; i++)
{
@@ -1363,7 +1363,7 @@ ghw_read_snapshot (struct ghw_handler *h)
if (s->type != NULL)
{
if (h->flag_verbose > 1)
- printf ("read type %d for sig %d\n", s->type->kind, i);
+ printf ("read type %d for sig %u\n", s->type->kind, i);
if (ghw_read_signal_value (h, s) < 0)
return -1;
}
@@ -1470,7 +1470,7 @@ ghw_get_lit (union ghw_type *type, unsigned e)
static void
ghw_disp_lit (union ghw_type *type, unsigned e)
{
- printf ("%s (%d)", ghw_get_lit (type, e), e);
+ printf ("%s (%u)", ghw_get_lit (type, e), e);
}
void
@@ -1485,10 +1485,10 @@ ghw_disp_value (union ghw_val *val, union ghw_type *type)
ghw_disp_lit (type, val->e8);
break;
case ghdl_rtik_type_i32:
- printf ("%d", val->i32);
+ printf (GHWPRI32, val->i32);
break;
case ghdl_rtik_type_p64:
- printf ("%lld", val->i64);
+ printf (GHWPRI64, val->i64);
break;
case ghdl_rtik_type_f64:
printf ("%g", val->f64);
@@ -1533,10 +1533,10 @@ ghw_get_value (char *buf, int len, union ghw_val *val, union ghw_type *type)
}
break;
case ghdl_rtik_type_i32:
- snprintf (buf, len, "%d", val->i32);
+ snprintf (buf, len, GHWPRI32, val->i32);
break;
case ghdl_rtik_type_p64:
- snprintf (buf, len, "%lld", val->i64);
+ snprintf (buf, len, GHWPRI64, val->i64);
break;
case ghdl_rtik_type_f64:
snprintf (buf, len, "%g", val->f64);
@@ -1598,7 +1598,7 @@ ghw_disp_values (struct ghw_handler *h)
int skip = (0 != h->skip_sigs && (0 != h->skip_sigs[i]));
if (s->type != NULL && !skip)
{
- printf ("#%d: ", i);
+ printf ("#%u: ", i);
ghw_disp_value (s->val, s->type);
printf ("\n");
}
@@ -1734,7 +1734,7 @@ ghw_read_sm (struct ghw_handler *h, enum ghw_sm_type *sm)
break;
case ghw_sm_cycle:
if (0)
- printf ("Time is %lld fs\n", h->snap_time);
+ printf ("Time is " GHWPRI64 " fs\n", h->snap_time);
if (0)
ghw_disp_values (h);
@@ -1772,7 +1772,7 @@ ghw_read_cycle (struct ghw_handler *h)
return res;
if (0)
- printf ("Time is %lld fs\n", h->snap_time);
+ printf ("Time is " GHWPRI64 " fs\n", h->snap_time);
if (0)
ghw_disp_values (h);
@@ -1898,12 +1898,12 @@ ghw_disp_range (union ghw_type *type, union ghw_range *rng)
break;
case ghdl_rtik_type_i32:
case ghdl_rtik_type_p32:
- printf ("%d %s %d",
+ printf (GHWPRI32 " %s " GHWPRI32,
rng->i32.left, ghw_get_dir (rng->i32.dir), rng->i32.right);
break;
case ghdl_rtik_type_i64:
case ghdl_rtik_type_p64:
- printf ("%lld %s %lld",
+ printf (GHWPRI64 " %s " GHWPRI64,
rng->i64.left, ghw_get_dir (rng->i64.dir), rng->i64.right);
break;
case ghdl_rtik_type_f64:
@@ -2060,7 +2060,8 @@ ghw_disp_type (struct ghw_handler *h, union ghw_type *t)
for (i = 0; i < p->nbr_units; i++)
{
struct ghw_unit *u = &p->units[i];
- printf (" %s = %lld %s;\n", u->name, u->val, p->units[0].name);
+ printf (" %s = " GHWPRI64 " %s;\n",
+ u->name, u->val, p->units[0].name);
}
printf ("end units\n");
}
diff --git a/src/grt/ghwlib.h b/src/grt/ghwlib.h
index ad9f93c79..b5347bc46 100644
--- a/src/grt/ghwlib.h
+++ b/src/grt/ghwlib.h
@@ -1,5 +1,5 @@
/* GHDL Wavefile reader library.
- Copyright (C) 2005 Tristan Gingold
+ Copyright (C) 2005-2017 Tristan Gingold
GHDL is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
@@ -24,8 +24,21 @@
#include <stdio.h>
#include <stdlib.h>
-#ifdef __GNUC__
-#include <stdint.h>
+/* The ghwlib uses the standard c99 int32_t and int64_t. They are declared
+ in stdint.h. Header inttypes.h includes stdint.h and provides macro for
+ printf and co specifiers. Use it if known to be available. */
+
+#if defined(__cplusplus) \
+ || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) \
+ || defined(HAVE_INTTYPES_H)
+/* Use C99 standard header. */
+# include <inttypes.h>
+# define GHWPRI64 "%"PRId64
+# define GHWPRI32 "%"PRId32
+#else
+# include <stdint.h>
+# define GHWPRI64 "%lld"
+# define GHWPRI32 "%d"
#endif
enum ghdl_rtik {