From 299f6f8551e5a3a72f60f91e8456c43bf8e0a9d1 Mon Sep 17 00:00:00 2001 From: steve Date: Sun, 20 Apr 2003 02:49:07 +0000 Subject: [PATCH] acc_fetch_value support for %v format. --- libveriuser/a_fetch_value.c | 14 ++++- vpi/sys_display.c | 84 ++------------------------ vpi_user.h | 23 +++++++- vvp/Makefile.in | 4 +- vvp/vpip_format.c | 115 ++++++++++++++++++++++++++++++++++++ vvp/vvp.def | 2 + 6 files changed, 155 insertions(+), 87 deletions(-) create mode 100644 vvp/vpip_format.c diff --git a/libveriuser/a_fetch_value.c b/libveriuser/a_fetch_value.c index 52b91c4dd..6c3c27afb 100644 --- a/libveriuser/a_fetch_value.c +++ b/libveriuser/a_fetch_value.c @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: a_fetch_value.c,v 1.1 2003/04/12 18:57:14 steve Exp $" +#ident "$Id: a_fetch_value.c,v 1.2 2003/04/20 02:49:07 steve Exp $" #endif # include @@ -62,12 +62,14 @@ static char* fetch_struct_value(handle obj, s_acc_value*value) static char* fetch_strength_value(handle obj) { struct t_vpi_value val; + char str[4]; val.format = vpiStrengthVal; vpi_get_value(obj, &val); - vpi_printf("XXXX acc_fetch_value(..., \"%%v\")\n"); - return __acc_newstring("StX"); + vpip_format_strength(str, &val); + + return __acc_newstring(str); } char* acc_fetch_value(handle obj, const char*fmt, s_acc_value*value) @@ -75,6 +77,9 @@ char* acc_fetch_value(handle obj, const char*fmt, s_acc_value*value) if (strcmp(fmt, "%%") == 0) return fetch_struct_value(obj, value); + if (strcmp(fmt, "%v") == 0) + return fetch_strength_value(obj); + vpi_printf("XXXX acc_fetch_value(..., \"%s\", ...)\n", fmt); return ""; } @@ -82,6 +87,9 @@ char* acc_fetch_value(handle obj, const char*fmt, s_acc_value*value) /* * $Log: a_fetch_value.c,v $ + * Revision 1.2 2003/04/20 02:49:07 steve + * acc_fetch_value support for %v format. + * * Revision 1.1 2003/04/12 18:57:14 steve * More acc_ function stubs. * diff --git a/vpi/sys_display.c b/vpi/sys_display.c index 5fff2af14..fcad4bf9f 100644 --- a/vpi/sys_display.c +++ b/vpi/sys_display.c @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: sys_display.c,v 1.56 2003/03/12 03:11:00 steve Exp $" +#ident "$Id: sys_display.c,v 1.57 2003/04/20 02:49:07 steve Exp $" #endif # include "config.h" @@ -295,88 +295,11 @@ static void format_time_real(unsigned mcd, int fsize, timeformat_info.suff); } -static const char str_char1_table[256] = { - ".HS1M222" "W3333333" /* 00 0F */ "L4444444" "44444444" /* 10 1F */ - "P5555555" "55555555" /* 20 2F */ "55555555" "55555555" /* 30 3F */ - "S6666666" "66666666" /* 40 4F */ "66666666" "66666666" /* 50 5F */ - "66666666" "66666666" /* 60 6F */ "66666666" "66666666" /* 70 7F */ - "S7777777" "77777777" /* 80 8F */ "77777777" "77777777" /* 90 9F */ - "77777777" "77777777" /* A0 AF */ "77777777" "77777777" /* B0 BF */ - "77777777" "77777777" /* C0 CF */ "77777777" "77777777" /* D0 DF */ - "77777777" "77777777" /* E0 EF */ "77777777" "77777777" /* F0 FF */ }; - -static const char str_char2_table[256] = { - ".im0e010" "e0102010" /* 00 0F */ "a0102010" "30102010" /* 10 1F */ - "u0102010" "30102010" /* 20 2F */ "40102010" "30102010" /* 30 3F */ - "t0102010" "30102010" /* 40 4F */ "40102010" "30102010" /* 50 5F */ - "50102010" "30102010" /* 60 6F */ "40102010" "30102010" /* 70 7F */ - "u0102010" "30102010" /* 80 8F */ "40102010" "30102010" /* 90 9F */ - "50102010" "30102010" /* A0 AF */ "40102010" "30102010" /* B0 BF */ - "60102010" "30102010" /* C0 CF */ "40102010" "30102010" /* D0 DF */ - "50102010" "30102010" /* E0 EF */ "40102010" "30102010" /* F0 FF */ }; static void format_strength(unsigned int mcd, s_vpi_value*value) { char str[4]; - - str[0] = '.'; - str[1] = '.'; - str[2] = '.'; - str[3] = 0; - - - switch (value->value.strength[0].logic) { - case vpi0: - str[0] = str_char1_table[value->value.strength[0].s0]; - str[1] = str_char2_table[value->value.strength[0].s0]; - str[2] = '0'; - break; - case vpi1: - str[0] = str_char1_table[value->value.strength[0].s1]; - str[1] = str_char2_table[value->value.strength[0].s1]; - str[2] = '1'; - break; - case vpiX: - if (value->value.strength[0].s0 == 1) { - str[0] = str_char1_table[value->value.strength[0].s1]; - str[1] = str_char2_table[value->value.strength[0].s1]; - str[2] = 'H'; - } else if (value->value.strength[0].s1 == 1) { - str[0] = str_char1_table[value->value.strength[0].s0]; - str[1] = str_char2_table[value->value.strength[0].s0]; - str[2] = 'L'; - } else if (value->value.strength[0].s1 == - value->value.strength[0].s0) { - str[0] = str_char1_table[value->value.strength[0].s0]; - str[1] = str_char2_table[value->value.strength[0].s0]; - str[2] = 'X'; - } else { - int ss; - - str[0] = '0'; - ss = value->value.strength[0].s0; - while (ss > 1) { - str[0] += 1; - ss >>= 1; - } - str[1] = '0'; - ss = value->value.strength[0].s1; - while (ss > 1) { - str[1] += 1; - ss >>= 1; - } - str[2] = 'X'; - } - break; - case vpiZ: - str[0] = 'H'; - str[1] = 'i'; - str[2] = 'Z'; - break; - default: - assert(0); - } - + vpip_format_strength(str, value); vpi_mcd_printf(mcd, "%s", str); } @@ -1726,6 +1649,9 @@ void sys_display_register() /* * $Log: sys_display.c,v $ + * Revision 1.57 2003/04/20 02:49:07 steve + * acc_fetch_value support for %v format. + * * Revision 1.56 2003/03/12 03:11:00 steve * Donot rely on persistence of format string. * diff --git a/vpi_user.h b/vpi_user.h index e1e2ffb66..c644786be 100644 --- a/vpi_user.h +++ b/vpi_user.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: vpi_user.h,v 1.23 2003/03/13 18:26:12 steve Exp $" +#ident "$Id: vpi_user.h,v 1.24 2003/04/20 02:49:07 steve Exp $" #endif @@ -218,13 +218,12 @@ extern void vpi_register_systf(const struct t_vpi_systf_data*ss); extern void vpi_printf(const char*fmt, ...) __attribute__((format (printf,1,2))); - /* vpi_vprintf is non-standard. */ extern void vpi_vprintf(const char*fmt, va_list ap); extern PLI_UINT32 vpi_mcd_close(unsigned int mcd); extern char *vpi_mcd_name(PLI_UINT32 mcd); extern PLI_UINT32 vpi_mcd_open(char *name); -extern PLI_UINT32 vpi_mcd_open_x(char *name, char *mode); +extern PLI_UINT32 vpi_mcd_open_x(char *name, char *mode); extern PLI_INT32 vpi_mcd_printf(unsigned int mcd, const char*fmt, ...) __attribute__((format (printf,2,3))); extern PLI_INT32 vpi_mcd_fputc(unsigned int mcd, unsigned char x); @@ -370,10 +369,28 @@ extern PLI_INT32 vpi_chk_error(p_vpi_error_info info); /* This is the table of startup routines included in each module. */ extern DLLEXPORT void (*vlog_startup_routines[])(); + +/* + * ICARUS VERILOG EXTENSIONS + * + * The vpip_* functions are Icarus Verilog extensions. They are not + * standard VPI functions, so use these at your own risk. + * + * The vpip_format_* functions format values in string format in the + * manner of the $display system task. + */ + + /* Format a scaler a la %v. The str points to a 4byte character + buffer. The value must be a vpiStrengthVal. */ +extern void vpip_format_strength(char*str, s_vpi_value*value); + EXTERN_C_END /* * $Log: vpi_user.h,v $ + * Revision 1.24 2003/04/20 02:49:07 steve + * acc_fetch_value support for %v format. + * * Revision 1.23 2003/03/13 18:26:12 steve * Verilog 2001 standart types. * diff --git a/vvp/Makefile.in b/vvp/Makefile.in index df15ea2f9..53862d3fa 100644 --- a/vvp/Makefile.in +++ b/vvp/Makefile.in @@ -16,7 +16,7 @@ # 59 Temple Place - Suite 330 # Boston, MA 02111-1307, USA # -#ident "$Id: Makefile.in,v 1.48 2003/03/13 04:36:57 steve Exp $" +#ident "$Id: Makefile.in,v 1.49 2003/04/20 02:49:07 steve Exp $" # # SHELL = /bin/sh @@ -66,7 +66,7 @@ check: all V = vpi_modules.o vpi_callback.o vpi_const.o vpi_event.o vpi_iter.o vpi_mcd.o \ vpi_priv.o vpi_scope.o vpi_real.o vpi_signal.o vpi_tasks.o vpi_time.o \ vpi_memory.o vpi_vthr_vector.o vpip_bin.o vpip_hex.o vpip_oct.o \ -vpip_to_dec.o vvp_vpi.o +vpip_to_dec.o vpip_format.o vvp_vpi.o O = main.o parse.o parse_misc.o lexor.o arith.o bufif.o compile.o \ functor.o fvectors.o npmos.o resolv.o stop.o symbols.o ufunc.o codes.o \ diff --git a/vvp/vpip_format.c b/vvp/vpip_format.c new file mode 100644 index 000000000..80f53f9c4 --- /dev/null +++ b/vvp/vpip_format.c @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2003 Stephen Williams (steve@icarus.com) + * + * 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 + */ +#ifdef HAVE_CVS_IDENT +#ident "$Id: vpip_format.c,v 1.1 2003/04/20 02:49:07 steve Exp $" +#endif + +# include +# include + +static const char str_char1_table[256] = { + ".HS1M222" "W3333333" /* 00 0F */ "L4444444" "44444444" /* 10 1F */ + "P5555555" "55555555" /* 20 2F */ "55555555" "55555555" /* 30 3F */ + "S6666666" "66666666" /* 40 4F */ "66666666" "66666666" /* 50 5F */ + "66666666" "66666666" /* 60 6F */ "66666666" "66666666" /* 70 7F */ + "S7777777" "77777777" /* 80 8F */ "77777777" "77777777" /* 90 9F */ + "77777777" "77777777" /* A0 AF */ "77777777" "77777777" /* B0 BF */ + "77777777" "77777777" /* C0 CF */ "77777777" "77777777" /* D0 DF */ + "77777777" "77777777" /* E0 EF */ "77777777" "77777777" /* F0 FF */ }; + +static const char str_char2_table[256] = { + ".im0e010" "e0102010" /* 00 0F */ "a0102010" "30102010" /* 10 1F */ + "u0102010" "30102010" /* 20 2F */ "40102010" "30102010" /* 30 3F */ + "t0102010" "30102010" /* 40 4F */ "40102010" "30102010" /* 50 5F */ + "50102010" "30102010" /* 60 6F */ "40102010" "30102010" /* 70 7F */ + "u0102010" "30102010" /* 80 8F */ "40102010" "30102010" /* 90 9F */ + "50102010" "30102010" /* A0 AF */ "40102010" "30102010" /* B0 BF */ + "60102010" "30102010" /* C0 CF */ "40102010" "30102010" /* D0 DF */ + "50102010" "30102010" /* E0 EF */ "40102010" "30102010" /* F0 FF */ }; + + +void vpip_format_strength(char*str, s_vpi_value*value) +{ + str[0] = '.'; + str[1] = '.'; + str[2] = '.'; + str[3] = 0; + + assert(value->format == vpiStrengthVal); + + switch (value->value.strength[0].logic) { + case vpi0: + str[0] = str_char1_table[value->value.strength[0].s0]; + str[1] = str_char2_table[value->value.strength[0].s0]; + str[2] = '0'; + break; + case vpi1: + str[0] = str_char1_table[value->value.strength[0].s1]; + str[1] = str_char2_table[value->value.strength[0].s1]; + str[2] = '1'; + break; + case vpiX: + if (value->value.strength[0].s0 == 1) { + str[0] = str_char1_table[value->value.strength[0].s1]; + str[1] = str_char2_table[value->value.strength[0].s1]; + str[2] = 'H'; + } else if (value->value.strength[0].s1 == 1) { + str[0] = str_char1_table[value->value.strength[0].s0]; + str[1] = str_char2_table[value->value.strength[0].s0]; + str[2] = 'L'; + } else if (value->value.strength[0].s1 == + value->value.strength[0].s0) { + str[0] = str_char1_table[value->value.strength[0].s0]; + str[1] = str_char2_table[value->value.strength[0].s0]; + str[2] = 'X'; + } else { + int ss; + + str[0] = '0'; + ss = value->value.strength[0].s0; + while (ss > 1) { + str[0] += 1; + ss >>= 1; + } + str[1] = '0'; + ss = value->value.strength[0].s1; + while (ss > 1) { + str[1] += 1; + ss >>= 1; + } + str[2] = 'X'; + } + break; + case vpiZ: + str[0] = 'H'; + str[1] = 'i'; + str[2] = 'Z'; + break; + default: + assert(0); + } +} + +/* + * $Log: vpip_format.c,v $ + * Revision 1.1 2003/04/20 02:49:07 steve + * acc_fetch_value support for %v format. + * + */ + diff --git a/vvp/vvp.def b/vvp/vvp.def index 47b4fe15f..20709de16 100644 --- a/vvp/vvp.def +++ b/vvp/vvp.def @@ -30,3 +30,5 @@ vpi_scan vpi_sim_control vpi_sim_vcontrol vpi_vprintf + +vpip_format_strength