2003-02-11 06:21:33 +01:00
|
|
|
/*
|
2010-01-06 19:46:39 +01:00
|
|
|
* Copyright (c) 2003-2010 Stephen Williams (steve@icarus.com)
|
2003-02-11 06:21:33 +01:00
|
|
|
*
|
|
|
|
|
* This source code is free software; you can redistribute it
|
|
|
|
|
* and/or modify it in source code form under the terms of the GNU
|
|
|
|
|
* General Public License as published by the Free Software
|
|
|
|
|
* Foundation; either version 2 of the License, or (at your option)
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
|
*/
|
|
|
|
|
|
2010-05-17 18:38:23 +02:00
|
|
|
#include "sys_priv.h"
|
2008-06-04 02:12:27 +02:00
|
|
|
#include "vcd_priv.h"
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
#include "stringheap.h"
|
2003-02-13 19:13:28 +01:00
|
|
|
|
2007-11-20 20:33:06 +01:00
|
|
|
int is_escaped_id(const char *name)
|
|
|
|
|
{
|
|
|
|
|
assert(name);
|
|
|
|
|
/* The first digit must be alpha or '_' to be a normal id. */
|
2010-04-11 20:00:39 +02:00
|
|
|
if (isalpha((int)name[0]) || name[0] == '_') {
|
2010-04-14 06:29:15 +02:00
|
|
|
int lp;
|
2007-11-20 20:33:06 +01:00
|
|
|
for (lp=1; name[lp] != '\0'; lp++) {
|
|
|
|
|
/* If this digit is not alpha-numeric or '_' we have
|
|
|
|
|
* an escaped identifier. */
|
2010-04-11 20:00:39 +02:00
|
|
|
if (!(isalnum((int)name[lp]) || name[lp] == '_')) {
|
2007-11-20 20:33:06 +01:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* We looked at all the digits, so this is a normal id. */
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-13 19:13:28 +01:00
|
|
|
struct stringheap_s name_heap = {0, 0};
|
2003-02-11 06:21:33 +01:00
|
|
|
|
|
|
|
|
struct vcd_names_s {
|
|
|
|
|
const char *name;
|
|
|
|
|
struct vcd_names_s *next;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void vcd_names_add(struct vcd_names_list_s*tab, const char *name)
|
|
|
|
|
{
|
|
|
|
|
struct vcd_names_s *nl = (struct vcd_names_s *)
|
|
|
|
|
malloc(sizeof(struct vcd_names_s));
|
|
|
|
|
assert(nl);
|
2003-02-13 19:13:28 +01:00
|
|
|
nl->name = strdup_sh(&name_heap, name);
|
2003-02-11 06:21:33 +01:00
|
|
|
nl->next = tab->vcd_names_list;
|
|
|
|
|
tab->vcd_names_list = nl;
|
|
|
|
|
tab->listed_names ++;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-24 01:04:44 +01:00
|
|
|
void vcd_names_delete(struct vcd_names_list_s*tab)
|
|
|
|
|
{
|
|
|
|
|
struct vcd_names_s *cur, *tmp;
|
|
|
|
|
for (cur = tab->vcd_names_list; cur; cur = tmp) {
|
|
|
|
|
tmp = cur->next;
|
|
|
|
|
free(cur);
|
|
|
|
|
}
|
|
|
|
|
tab->vcd_names_list = 0;
|
|
|
|
|
tab->listed_names = 0;
|
|
|
|
|
free(tab->vcd_names_sorted);
|
|
|
|
|
tab->vcd_names_sorted = 0;
|
|
|
|
|
tab->sorted_names = 0;
|
|
|
|
|
string_heap_delete(&name_heap);
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-11 06:21:33 +01:00
|
|
|
static int vcd_names_compare(const void *s1, const void *s2)
|
|
|
|
|
{
|
|
|
|
|
const char *v1 = *(const char **) s1;
|
|
|
|
|
const char *v2 = *(const char **) s2;
|
|
|
|
|
|
|
|
|
|
return strcmp(v1, v2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *vcd_names_search(struct vcd_names_list_s*tab, const char *key)
|
|
|
|
|
{
|
|
|
|
|
const char **v;
|
|
|
|
|
|
|
|
|
|
if (tab->vcd_names_sorted == 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2004-10-04 03:10:51 +02:00
|
|
|
v = (const char **) bsearch(&key,
|
2003-02-11 06:21:33 +01:00
|
|
|
tab->vcd_names_sorted, tab->sorted_names,
|
|
|
|
|
sizeof(const char *), vcd_names_compare );
|
|
|
|
|
|
|
|
|
|
return(v ? *v : NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vcd_names_sort(struct vcd_names_list_s*tab)
|
|
|
|
|
{
|
|
|
|
|
if (tab->listed_names) {
|
2004-10-04 03:10:51 +02:00
|
|
|
struct vcd_names_s *r;
|
2003-02-11 06:21:33 +01:00
|
|
|
const char **l;
|
2004-10-04 03:10:51 +02:00
|
|
|
|
2003-02-11 06:21:33 +01:00
|
|
|
tab->sorted_names += tab->listed_names;
|
2004-10-04 03:10:51 +02:00
|
|
|
tab->vcd_names_sorted = (const char **)
|
|
|
|
|
realloc(tab->vcd_names_sorted,
|
2003-02-11 06:21:33 +01:00
|
|
|
tab->sorted_names*(sizeof(const char *)));
|
|
|
|
|
assert(tab->vcd_names_sorted);
|
2004-10-04 03:10:51 +02:00
|
|
|
|
2003-02-11 06:21:33 +01:00
|
|
|
l = tab->vcd_names_sorted + tab->sorted_names - tab->listed_names;
|
|
|
|
|
tab->listed_names = 0;
|
|
|
|
|
|
|
|
|
|
r = tab->vcd_names_list;
|
|
|
|
|
tab->vcd_names_list = 0x0;
|
|
|
|
|
|
|
|
|
|
while (r) {
|
|
|
|
|
struct vcd_names_s *rr = r;
|
|
|
|
|
r = rr->next;
|
|
|
|
|
*(l++) = rr->name;
|
|
|
|
|
free(rr);
|
|
|
|
|
}
|
2004-10-04 03:10:51 +02:00
|
|
|
|
|
|
|
|
qsort(tab->vcd_names_sorted, tab->sorted_names,
|
2003-02-11 06:21:33 +01:00
|
|
|
sizeof(const char **), vcd_names_compare);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-11 01:14:02 +01:00
|
|
|
/*
|
|
|
|
|
* Since the compiletf routines are all the same they are located here,
|
2008-06-06 04:25:19 +02:00
|
|
|
* so we only need a single copy. Some are generic enough they can use
|
2008-06-14 05:46:18 +02:00
|
|
|
* the ones in sys_priv.c (no arg, one numeric argument, etc.).
|
2007-12-11 01:14:02 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* $dumpvars takes a variety of arguments. */
|
|
|
|
|
PLI_INT32 sys_dumpvars_compiletf(PLI_BYTE8 *name)
|
|
|
|
|
{
|
|
|
|
|
vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
|
|
|
|
|
vpiHandle argv = vpi_iterate(vpiArgument, callh);
|
|
|
|
|
vpiHandle arg;
|
|
|
|
|
|
|
|
|
|
/* No arguments is OK, dump everything. */
|
2008-06-04 02:12:27 +02:00
|
|
|
if (argv == 0) return 0;
|
2007-12-11 01:14:02 +01:00
|
|
|
|
|
|
|
|
/* The first argument is the numeric level. */
|
2008-06-04 02:12:27 +02:00
|
|
|
if (! is_numeric_obj(vpi_scan(argv))) {
|
Rework $plusarg routines.
This patch addresses a number of issues:
Rewrote the $test$plusargs and $value$plusargs routines to have
better error/warning messages, to support runtime strings, to
correctly load bit based values (truncating, padding, negative
value), added support for the real formats using strtod() and
added "x/X" as an alias for "h/H" to match the other part of
Icarus.
Rewrite the vpip_{bin,oct,hex}_str_to_vec4 routines to ignore
embedded "_" characters. Add support for a negative value and
set the entire value to 'bx if an invalid digit is found. A
warning is printed for this case.
Rewrite vpip_dec_str_to_vec4 to ignore embedded "_" characters,
to support a single "x" or "z" constant and to return 'bx if an
invalid digit is found. A warning is printed for this case.
It simplifies the system task/functions error/warning messages.
It removes the signed flag for the bin and dec string conversions.
This was not being used (was always false) and the new negative
value support makes this obsolete.
Add support for a real variable to handle Bin, Oct, Dec and Hex
strings. They are converted into a vvp_vector4_t which is then
converted to a real value.
Add support for setting a bit based value using a real value.
Removed an unneeded rfp signal in vpip_make_reg()
2008-11-13 22:28:19 +01:00
|
|
|
vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
|
2008-06-04 02:12:27 +02:00
|
|
|
(int)vpi_get(vpiLineNo, callh));
|
|
|
|
|
vpi_printf("%s's argument must be numeric.\n", name);
|
|
|
|
|
vpi_control(vpiFinish, 1);
|
|
|
|
|
}
|
2007-12-11 01:14:02 +01:00
|
|
|
|
|
|
|
|
/* The rest of the arguments are either a module or a variable. */
|
2007-12-19 18:29:47 +01:00
|
|
|
while ((arg=vpi_scan(argv)) != NULL) {
|
2007-12-15 02:17:51 +01:00
|
|
|
switch(vpi_get(vpiType, arg)) {
|
2008-06-04 02:12:27 +02:00
|
|
|
case vpiMemoryWord:
|
2009-04-16 20:57:00 +02:00
|
|
|
/*
|
|
|
|
|
* We need to allow non-constant selects to support the following:
|
|
|
|
|
*
|
|
|
|
|
* for (lp = 0; lp < max ; lp = lp + 1) $dumpvars(0, array[lp]);
|
|
|
|
|
*
|
|
|
|
|
* We need to do a direct callback on the selected element vs using
|
|
|
|
|
* the &A<> structure. The later will not give us what we want.
|
|
|
|
|
* This is implemented in the calltf routine.
|
|
|
|
|
*/
|
|
|
|
|
#if 0
|
2008-06-04 02:12:27 +02:00
|
|
|
if (vpi_get(vpiConstantSelect, arg) == 0) {
|
Rework $plusarg routines.
This patch addresses a number of issues:
Rewrote the $test$plusargs and $value$plusargs routines to have
better error/warning messages, to support runtime strings, to
correctly load bit based values (truncating, padding, negative
value), added support for the real formats using strtod() and
added "x/X" as an alias for "h/H" to match the other part of
Icarus.
Rewrite the vpip_{bin,oct,hex}_str_to_vec4 routines to ignore
embedded "_" characters. Add support for a negative value and
set the entire value to 'bx if an invalid digit is found. A
warning is printed for this case.
Rewrite vpip_dec_str_to_vec4 to ignore embedded "_" characters,
to support a single "x" or "z" constant and to return 'bx if an
invalid digit is found. A warning is printed for this case.
It simplifies the system task/functions error/warning messages.
It removes the signed flag for the bin and dec string conversions.
This was not being used (was always false) and the new negative
value support makes this obsolete.
Add support for a real variable to handle Bin, Oct, Dec and Hex
strings. They are converted into a vvp_vector4_t which is then
converted to a real value.
Add support for setting a bit based value using a real value.
Removed an unneeded rfp signal in vpip_make_reg()
2008-11-13 22:28:19 +01:00
|
|
|
vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
|
2008-06-04 02:12:27 +02:00
|
|
|
(int)vpi_get(vpiLineNo, callh));
|
|
|
|
|
vpi_printf("%s cannot dump a non-constant select %s.\n", name,
|
|
|
|
|
vpi_get_str(vpiType, arg));
|
|
|
|
|
vpi_control(vpiFinish, 1);
|
|
|
|
|
}
|
2009-04-16 20:57:00 +02:00
|
|
|
#endif
|
2007-12-15 02:17:51 +01:00
|
|
|
/* The module types. */
|
|
|
|
|
case vpiModule:
|
|
|
|
|
case vpiTask:
|
|
|
|
|
case vpiFunction:
|
|
|
|
|
case vpiNamedBegin:
|
|
|
|
|
case vpiNamedFork:
|
|
|
|
|
/* The variable types. */
|
2009-06-25 19:48:05 +02:00
|
|
|
#if 0
|
|
|
|
|
case vpiParameter: /* A constant! */
|
|
|
|
|
#endif
|
2007-12-15 02:17:51 +01:00
|
|
|
case vpiNet:
|
|
|
|
|
case vpiReg:
|
|
|
|
|
case vpiIntegerVar:
|
|
|
|
|
case vpiTimeVar:
|
|
|
|
|
case vpiRealVar:
|
2009-06-25 19:48:05 +02:00
|
|
|
case vpiNamedEvent:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vpiParameter: /* A constant! */
|
|
|
|
|
vpi_printf("SORRY: %s:%d: ", vpi_get_str(vpiFile, callh),
|
|
|
|
|
(int)vpi_get(vpiLineNo, callh));
|
|
|
|
|
vpi_printf("%s cannot currently dump a parameter.\n", name);
|
2007-12-15 02:17:51 +01:00
|
|
|
break;
|
2009-06-25 19:48:05 +02:00
|
|
|
|
2007-12-15 02:17:51 +01:00
|
|
|
default:
|
Rework $plusarg routines.
This patch addresses a number of issues:
Rewrote the $test$plusargs and $value$plusargs routines to have
better error/warning messages, to support runtime strings, to
correctly load bit based values (truncating, padding, negative
value), added support for the real formats using strtod() and
added "x/X" as an alias for "h/H" to match the other part of
Icarus.
Rewrite the vpip_{bin,oct,hex}_str_to_vec4 routines to ignore
embedded "_" characters. Add support for a negative value and
set the entire value to 'bx if an invalid digit is found. A
warning is printed for this case.
Rewrite vpip_dec_str_to_vec4 to ignore embedded "_" characters,
to support a single "x" or "z" constant and to return 'bx if an
invalid digit is found. A warning is printed for this case.
It simplifies the system task/functions error/warning messages.
It removes the signed flag for the bin and dec string conversions.
This was not being used (was always false) and the new negative
value support makes this obsolete.
Add support for a real variable to handle Bin, Oct, Dec and Hex
strings. They are converted into a vvp_vector4_t which is then
converted to a real value.
Add support for setting a bit based value using a real value.
Removed an unneeded rfp signal in vpip_make_reg()
2008-11-13 22:28:19 +01:00
|
|
|
vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
|
2008-06-04 02:12:27 +02:00
|
|
|
(int)vpi_get(vpiLineNo, callh));
|
|
|
|
|
vpi_printf("%s cannot dump a %s.\n", name,
|
|
|
|
|
vpi_get_str(vpiType, arg));
|
2007-12-15 02:17:51 +01:00
|
|
|
vpi_control(vpiFinish, 1);
|
|
|
|
|
}
|
2007-12-11 01:14:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|