From 5d80c4856de569e634d3c7115329700fff3b94b8 Mon Sep 17 00:00:00 2001 From: Cary R Date: Tue, 20 Nov 2007 11:33:06 -0800 Subject: [PATCH] Prefix escaped identifiers in VCD and LXT(2) output with a back slash. GTKWave needs to have escaped identifiers properly escaped (preceded with a back slash) in its VCD input. Without this the name may not display correctly. Even though it is not required, to keep things consistent LXT and LXT2 formats also prefix escaped identifiers with a back slash. --- vpi/sys_lxt.c | 6 ++++++ vpi/sys_lxt2.c | 6 ++++++ vpi/sys_vcd.c | 11 +++++++---- vpi/vcd_priv.c | 44 +++++++++++++++++++++----------------------- vpi/vcd_priv.h | 11 ++--------- 5 files changed, 42 insertions(+), 36 deletions(-) diff --git a/vpi/sys_lxt.c b/vpi/sys_lxt.c index ad4b38a7..266eae95 100644 --- a/vpi/sys_lxt.c +++ b/vpi/sys_lxt.c @@ -108,6 +108,7 @@ static char *create_full_name(const char *name) { char *n, *n2; int len = 0; + int is_esc_id = is_escaped_id(name); struct lxt_scope *t = lxt_scope_head; /* Figure out how long the combined string will be. */ @@ -117,6 +118,7 @@ static char *create_full_name(const char *name) } len += strlen(name) + 1; + if (is_esc_id) len += 1; /* Allocate a string buffer. */ n = n2 = malloc(len); @@ -130,6 +132,10 @@ static char *create_full_name(const char *name) t=t->next; } + if (is_esc_id) { + *n2 = '\\'; + n2++; + } strcpy(n2, name); n2 += strlen(n2); assert( (n2 - n + 1) == len ); diff --git a/vpi/sys_lxt2.c b/vpi/sys_lxt2.c index 68c6c654..5963d024 100644 --- a/vpi/sys_lxt2.c +++ b/vpi/sys_lxt2.c @@ -109,6 +109,7 @@ static char *create_full_name(const char *name) { char *n, *n2; int len = 0; + int is_esc_id = is_escaped_id(name); struct lxt_scope *t = lxt_scope_head; /* Figure out how long the combined string will be. */ @@ -118,6 +119,7 @@ static char *create_full_name(const char *name) } len += strlen(name) + 1; + if (is_esc_id) len += 1; /* Allocate a string buffer. */ n = n2 = malloc(len); @@ -131,6 +133,10 @@ static char *create_full_name(const char *name) t=t->next; } + if (is_esc_id) { + *n2 = '\\'; + n2++; + } strcpy(n2, name); n2 += strlen(n2); assert( (n2 - n + 1) == len ); diff --git a/vpi/sys_vcd.c b/vpi/sys_vcd.c index 6430c8b9..7590caff 100644 --- a/vpi/sys_vcd.c +++ b/vpi/sys_vcd.c @@ -549,6 +549,7 @@ static void scan_item(unsigned depth, vpiHandle item, int skip) const char* type; const char* name; + const char* prefix; const char* ident; int nexus_id; @@ -587,6 +588,7 @@ static void scan_item(unsigned depth, vpiHandle item, int skip) break; name = vpi_get_str(vpiName, item); + prefix = is_escaped_id(name) ? "\\" : ""; nexus_id = vpi_get(_vpiNexusId, item); @@ -625,9 +627,9 @@ static void scan_item(unsigned depth, vpiHandle item, int skip) info->cb = vpi_register_cb(&cb); } - fprintf(dump_file, "$var %s %u %s %s", + fprintf(dump_file, "$var %s %u %s %s%s", type, vpi_get(vpiSize, item), ident, - name); + prefix, name); /* FIXME if (vpi_get(vpiVector, item) */ @@ -646,10 +648,11 @@ static void scan_item(unsigned depth, vpiHandle item, int skip) /* Declare the variable in the VCD file. */ name = vpi_get_str(vpiName, item); + prefix = is_escaped_id(name) ? "\\" : ""; ident = strdup(vcdid); gen_new_vcd_id(); - fprintf(dump_file, "$var real 1 %s %s $end\n", - ident, name); + fprintf(dump_file, "$var real 1 %s %s%s $end\n", + ident, prefix, name); /* Add a callback for the variable. */ info = malloc(sizeof(*info)); diff --git a/vpi/vcd_priv.c b/vpi/vcd_priv.c index 014faeb1..1f9f2311 100644 --- a/vpi/vcd_priv.c +++ b/vpi/vcd_priv.c @@ -29,8 +29,29 @@ #ifdef HAVE_MALLOC_H # include #endif +# include # include "stringheap.h" +int is_escaped_id(const char *name) +{ + int lp; + + assert(name); + /* The first digit must be alpha or '_' to be a normal id. */ + if (isalpha(name[0]) || name[0] == '_') { + for (lp=1; name[lp] != '\0'; lp++) { + /* If this digit is not alpha-numeric or '_' we have + * an escaped identifier. */ + if (!(isalnum(name[lp]) || name[lp] == '_')) { + return 1; + } + } + /* We looked at all the digits, so this is a normal id. */ + return 0; + } + return 1; +} + struct stringheap_s name_heap = {0, 0}; struct vcd_names_s { @@ -167,26 +188,3 @@ void set_nexus_ident(int nex, const char *id) vcd_ids[ihash(nex)] = bucket; } - -/* - * $Log: vcd_priv.c,v $ - * Revision 1.6 2004/10/04 01:10:58 steve - * Clean up spurious trailing white space. - * - * Revision 1.5 2004/01/21 01:22:53 steve - * Give the vip directory its own configure and vpi_config.h - * - * Revision 1.4 2003/11/10 20:18:02 steve - * Missing config.h. - * - * Revision 1.3 2003/04/28 01:03:11 steve - * Fix stringheap list management failure. - * - * Revision 1.2 2003/02/13 18:13:28 steve - * Make lxt use stringheap to perm-allocate strings. - * - * Revision 1.1 2003/02/11 05:21:33 steve - * Support dump of vpiRealVar objects. - * - */ - diff --git a/vpi/vcd_priv.h b/vpi/vcd_priv.h index f5f1ed70..14a201cf 100644 --- a/vpi/vcd_priv.h +++ b/vpi/vcd_priv.h @@ -22,6 +22,8 @@ #ident "$Id: vcd_priv.h,v 1.2 2003/02/13 18:13:28 steve Exp $" #endif +extern int is_escaped_id(const char *name); + struct vcd_names_s; extern struct stringheap_s name_heap; @@ -42,13 +44,4 @@ extern void vcd_names_sort(struct vcd_names_list_s*tab); extern const char*find_nexus_ident(int nex); extern void set_nexus_ident(int nex, const char *id); -/* - * $Log: vcd_priv.h,v $ - * Revision 1.2 2003/02/13 18:13:28 steve - * Make lxt use stringheap to perm-allocate strings. - * - * Revision 1.1 2003/02/11 05:21:33 steve - * Support dump of vpiRealVar objects. - * - */ #endif -- 2.11.4.GIT