From d95c77a58aa092823d148c91b820036a484f8059 Mon Sep 17 00:00:00 2001 From: Cary R Date: Sat, 29 Dec 2007 22:26:02 -0800 Subject: [PATCH 1/7] Add vvp flag that allows $stop to act like $finish. This patch adds a new flag to vvp "-n" that can be used to make $stop and hence act like $finish. This may be desired when using vvp in a non-interactive environment. --- vvp/main.cc | 10 +++++++++- vvp/stop.cc | 34 ++++++++-------------------------- vvp/vvp.man | 5 +++++ 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/vvp/main.cc b/vvp/main.cc index cecdd6990..598c349be 100644 --- a/vvp/main.cc +++ b/vvp/main.cc @@ -144,6 +144,7 @@ int main(int argc, char*argv[]) const char *logfile_name = 0x0; FILE *logfile = 0x0; extern void vpi_set_vlog_info(int, char**); + extern bool stop_is_finish; #ifdef __MINGW32__ /* In the Windows world, we get the first module path @@ -159,7 +160,10 @@ int main(int argc, char*argv[]) } #endif - while ((opt = getopt(argc, argv, "+hl:M:m:sv")) != EOF) switch (opt) { + /* For non-interactive runs we do not want to run the interactive + * debugger, so make $stop just execute a $finish. */ + stop_is_finish = false; + while ((opt = getopt(argc, argv, "+hl:M:m:nsv")) != EOF) switch (opt) { case 'h': fprintf(stderr, "Usage: vvp [options] input-file [+plusargs...]\n" @@ -169,6 +173,7 @@ int main(int argc, char*argv[]) " -M path VPI module directory\n" " -M - Clear VPI module path\n" " -m module Load vpi module.\n" + " -n Non-interctive ($stop = $finish).\n" " -s $stop right away.\n" " -v Verbose progress messages.\n" ); exit(0); @@ -186,6 +191,9 @@ int main(int argc, char*argv[]) case 'm': module_tab[module_cnt++] = optarg; break; + case 'n': + stop_is_finish = true; + break; case 's': schedule_stop(0); break; diff --git a/vvp/stop.cc b/vvp/stop.cc index 000187b1c..d3da3fe3f 100644 --- a/vvp/stop.cc +++ b/vvp/stop.cc @@ -43,6 +43,7 @@ #endif struct __vpiScope*stop_current_scope = 0; +bool stop_is_finish; /* When set, $stop acts like $finish (set in main.cc). */ #ifndef USE_READLINE static char* readline_stub(const char*prompt) @@ -474,6 +475,13 @@ static void invoke_command(char*txt) void stop_handler(int rc) { + /* The user may be running in a non-interactive environment, so + * they want $stop and to be the same as $finish. */ + if (stop_is_finish) { + schedule_finish(0); + return; + } + vpi_mcd_printf(1,"** VVP Stop(%d) **\n", rc); vpi_mcd_printf(1,"** Current simulation time is %" TIME_FMT "u ticks.\n", schedule_simtime()); @@ -503,29 +511,3 @@ void stop_handler(int rc) vpi_mcd_printf(1,"** Continue **\n"); } - -/* - * $Log: stop.cc,v $ - * Revision 1.16 2006/06/18 04:15:50 steve - * Add support for system functions in continuous assignments. - * - * Revision 1.15 2005/11/25 18:35:38 steve - * stop/continue messages go through MCD for logging. - * - * Revision 1.14 2005/09/20 18:34:02 steve - * Clean up compiler warnings. - * - * Revision 1.13 2005/01/29 06:29:17 steve - * Support interactive mode even without readline. - * - * Revision 1.12 2004/10/04 01:10:59 steve - * Clean up spurious trailing white space. - * - * Revision 1.11 2004/02/21 00:44:34 steve - * Add load command to interactive stop. - * Support decimal constants passed interactive to system tasks. - * - * Revision 1.10 2003/11/07 05:58:02 steve - * Fix conditional compilation of readline history. - */ - diff --git a/vvp/vvp.man b/vvp/vvp.man index 86f3d12bd..491cfa4da 100644 --- a/vvp/vvp.man +++ b/vvp/vvp.man @@ -41,6 +41,11 @@ the module. However, if the name includes at least one directory character, then the search path is not scanned and the name is assumed to be a complete file name. .TP 8 +.B -n +This flag makes $stop or a a synonym for $finish. +It can be used to give the program a more meaningful interface when +running in a non-interactive environment. +.TP 8 .B -s Stop. This will cause the simulation to stop in the beginning, before any events are scheduled. This allows the interactive user to get From a16f5bc7090e8acdce72a9c9b1fcb3343256d5b0 Mon Sep 17 00:00:00 2001 From: Cary R Date: Sun, 30 Dec 2007 12:19:36 -0800 Subject: [PATCH 2/7] Update driver-vpi/* to match iverilog-vpi.sh This patch updates the MinGW C version of iverilog-vpi to match the shell version. This allows the vpi tests in the test suite to be run. --- driver-vpi/Makefile.in | 13 +- driver-vpi/config.h.in | 8 ++ driver-vpi/main.c | 279 +++++++++++++++++++++++++---------------- iverilog-vpi.sh | 2 +- 4 files changed, 190 insertions(+), 112 deletions(-) create mode 100644 driver-vpi/config.h.in diff --git a/driver-vpi/Makefile.in b/driver-vpi/Makefile.in index 78c50a860..d166d562f 100644 --- a/driver-vpi/Makefile.in +++ b/driver-vpi/Makefile.in @@ -16,12 +16,12 @@ # 59 Temple Place - Suite 330 # Boston, MA 02111-1307, USA # -#ident "$Id: Makefile.in,v 1.7 2004/10/13 22:01:34 steve Exp $" +#ident "$Id: Makefile.in,v 1.7.2.1 2006/10/04 17:08:59 steve Exp $" # # SHELL = /bin/sh -VERSION = 0.8 +VERSION = 0.8.3 prefix = @prefix@ exec_prefix = @exec_prefix@ @@ -48,7 +48,7 @@ LDFLAGS = @LDFLAGS@ all: iverilog-vpi@EXEEXT@ clean: - rm -f *.o + rm -f *.o config.h rm -f iverilog-vpi@EXEEXT@ distclean: clean @@ -60,9 +60,14 @@ iverilog-vpi@EXEEXT@: $O $(CC) $(LDFLAGS) $O -o iverilog-vpi@EXEEXT@ @EXTRALIBS@ -main.o: main.c +main.o: main.c config.h $(CC) $(CPPFLAGS) $(CFLAGS) -c $(srcdir)/main.c +config.h: config.h.in + sed -e 's;@IVLCC@;@CC@;' -e 's;@IVLCXX@;@CXX@;' \ + -e 's;@IVLCFLAGS@;@CXXFLAGS@;' \ + -e 's;@SHARED@;@shared@;' $< > $@ + # Windows specific... res.o: res.rc windres -i res.rc -o res.o diff --git a/driver-vpi/config.h.in b/driver-vpi/config.h.in new file mode 100644 index 000000000..ca1005555 --- /dev/null +++ b/driver-vpi/config.h.in @@ -0,0 +1,8 @@ +/* For now do not put the Icarus Verilog include or library paths here. + * They are generated from a registry entry the user must set (-ivl=). + * This may change in the future once I have thought about it more. */ +#define IVERILOG_VPI_CC "@IVLCC@" +#define IVERILOG_VPI_CXX "@IVLCXX@" +#define IVERILOG_VPI_CFLAGS " @IVLCFLAGS@" +#define IVERILOG_VPI_LDFLAGS "@SHARED@" +#define IVERILOG_VPI_LDLIBS "-lveriuser -lvpi" diff --git a/driver-vpi/main.c b/driver-vpi/main.c index df325f8e9..9facd443e 100644 --- a/driver-vpi/main.c +++ b/driver-vpi/main.c @@ -32,28 +32,27 @@ #include -/* Macros used for compiling and linking */ +static void setup_ivl_environment(); -#define IVERILOG_VPI_CC "gcc" /* no .exe extension */ -#define IVERILOG_VPI_CXX "gcc" /* no .exe extension */ -#define IVERILOG_VPI_CFLAGS "-O" /* -I appended later */ -#define IVERILOG_VPI_LD "gcc" /* no .exe extension */ -#define IVERILOG_VPI_LDFLAGS "-shared -Wl,--enable-auto-image-base" -#define IVERILOG_VPI_LDLIBS "-lveriuser -lvpi" /* -L prepended later */ +/* The compile options: compiler, flags, etc. are in here */ +#include "config.h" /* pointers to global strings */ static struct global_strings { - char *pCCSRC; /* list of C source files */ - char *pCXSRC; /* list of C++ source files */ + char *pCCSRC; /* list of C source files (*.c) */ + char *pCXSRC; /* list of C++ source files (*.cc, *.cpp) */ char *pOBJ; /* list of object files */ char *pLIB; /* list of library files */ + char *pINCS; /* list of include directories */ + char *pDEFS; /* list of definitions */ char *pOUT; /* output file name (.vpi extension), if 0 length then no source files specified */ char *pMINGW; /* path to MinGW directory */ char *pIVL; /* path to IVL directory */ char *pCFLAGS; /* CFLAGS option */ char *pLDLIBS; /* LDLIBS option */ char *pNewPath; /* new PATH environment variable setting */ + char *pLD; /* what to use for a linker */ } gstr; @@ -70,6 +69,8 @@ static void myExit(int exitVal) deInitDynString(gstr.pCXSRC); deInitDynString(gstr.pOBJ); deInitDynString(gstr.pLIB); + deInitDynString(gstr.pINCS); + deInitDynString(gstr.pDEFS); deInitDynString(gstr.pOUT); deInitDynString(gstr.pMINGW); deInitDynString(gstr.pIVL); @@ -84,7 +85,7 @@ static void myExit(int exitVal) static void usage() { - fprintf(stderr,"usage: iverilog-vpi [--name=name] [-llibrary] [-mingw=dir] [-ivl=dir] sourcefile...\n"); + fprintf(stderr,"usage: iverilog-vpi [src and obj files]...\n"); fprintf(stderr," or iverilog-vpi -mingw=dir\n"); fprintf(stderr," or iverilog-vpi -ivl=dir\n"); myExit(1); @@ -110,12 +111,16 @@ static void init() initDynString(&gstr.pCXSRC); initDynString(&gstr.pOBJ); initDynString(&gstr.pLIB); + initDynString(&gstr.pINCS); + initDynString(&gstr.pDEFS); initDynString(&gstr.pOUT); initDynString(&gstr.pMINGW); initDynString(&gstr.pIVL); initDynString(&gstr.pCFLAGS); initDynString(&gstr.pLDLIBS); initDynString(&gstr.pNewPath); + /* By default use the C compiler to link the programs. */ + gstr.pLD = IVERILOG_VPI_CC; } /* return true if "str" is terminated with with "end", case insensitive */ @@ -281,67 +286,120 @@ static int parse(int argc, char *argv[]) char dot_o_ext[] = ".o"; char name_option[] = "--name="; char lib_option[] = "-l"; + char inc_option[] = "-I"; char mingw_option[] = "-mingw="; char ivl_option[] = "-ivl="; + char def_option[] = "-D"; - if (argc == 1) - return 0; + if (argc == 1) return 0; for (idx=1; idx Date: Fri, 4 Jan 2008 19:21:26 -0800 Subject: [PATCH 3/7] remove lint flagged by gcc-4.3 watch for possible behavior changes in elaborate.cc:3409 vvp/vvp_net.cc:600 --- PWire.cc | 3 ++- driver/cflexor.lex | 1 + elab_net.cc | 6 ++++-- elab_scope.cc | 4 ++-- elaborate.cc | 4 ++-- ivlpp/lexor.lex | 1 + vpi/sdf_lexor.lex | 1 + vpi/sys_readmem_lex.lex | 1 + vvp/logic.cc | 2 +- vvp/vvp_net.cc | 2 +- 10 files changed, 16 insertions(+), 9 deletions(-) diff --git a/PWire.cc b/PWire.cc index 404e12ef7..d26aa10af 100644 --- a/PWire.cc +++ b/PWire.cc @@ -103,11 +103,12 @@ bool PWire::set_port_type(NetNet::PortType pt) bool PWire::set_data_type(ivl_variable_type_t dt) { - if (data_type_ != IVL_VT_NO_TYPE) + if (data_type_ != IVL_VT_NO_TYPE) { if (data_type_ != dt) return false; else return true; + } assert(data_type_ == IVL_VT_NO_TYPE); data_type_ = dt; diff --git a/driver/cflexor.lex b/driver/cflexor.lex index 181e52330..4922f8807 100644 --- a/driver/cflexor.lex +++ b/driver/cflexor.lex @@ -1,5 +1,6 @@ %option nounput +%option noinput %{ /* diff --git a/elab_net.cc b/elab_net.cc index 04db2a8e0..ad8c2d51d 100644 --- a/elab_net.cc +++ b/elab_net.cc @@ -213,17 +213,19 @@ NetNet* PEBinary::elaborate_net_add_(Design*des, NetScope*scope, // Pad out the operands, if necessary, the match the width of // the adder device. - if (lsig->vector_width() < width) + if (lsig->vector_width() < width) { if (expr_signed) lsig = pad_to_width_signed(des, lsig, width); else lsig = pad_to_width(des, lsig, width); + } - if (rsig->vector_width() < width) + if (rsig->vector_width() < width) { if (expr_signed) rsig = pad_to_width_signed(des, rsig, width); else rsig = pad_to_width(des, rsig, width); + } // Check that the argument types match. if (lsig->data_type() != rsig->data_type()) { diff --git a/elab_scope.cc b/elab_scope.cc index 7dbdbc0b6..4581edf05 100644 --- a/elab_scope.cc +++ b/elab_scope.cc @@ -444,8 +444,8 @@ bool PGenerate::generate_scope_condit_(Design*des, NetScope*container, bool else // If the condition evaluates as false, then do not create the // scope. - if (test->value().as_long() == 0 && !else_flag - || test->value().as_long() != 0 && else_flag) { + if ( (test->value().as_long() == 0 && !else_flag) + || (test->value().as_long() != 0 && else_flag) ) { if (debug_elaborate) cerr << get_fileline() << ": debug: Generate condition " << (else_flag? "(else)" : "(if)") diff --git a/elaborate.cc b/elaborate.cc index 204b49c16..d5eefccfe 100644 --- a/elaborate.cc +++ b/elaborate.cc @@ -3405,8 +3405,8 @@ void PSpecPath::elaborate(Design*des, NetScope*scope) const NetNet*src_sig = scope->find_signal(*cur_src); assert(src_sig); - if (src_sig->port_type() != NetNet::PINPUT - & src_sig->port_type() != NetNet::PINOUT) { + if ( (src_sig->port_type() != NetNet::PINPUT) + && (src_sig->port_type() != NetNet::PINOUT) ) { cerr << get_fileline() << ": error: Path source " << *cur_src << " must be an input or inout port." diff --git a/ivlpp/lexor.lex b/ivlpp/lexor.lex index 009d8d190..9c101b595 100644 --- a/ivlpp/lexor.lex +++ b/ivlpp/lexor.lex @@ -159,6 +159,7 @@ static int ma_parenthesis_level = 0; %option stack %option nounput +%option noinput %option noyy_top_state %x PPINCLUDE diff --git a/vpi/sdf_lexor.lex b/vpi/sdf_lexor.lex index cebe3c5c2..f8a263ccf 100644 --- a/vpi/sdf_lexor.lex +++ b/vpi/sdf_lexor.lex @@ -1,6 +1,7 @@ %option never-interactive %option nounput +%option noinput %{ /* diff --git a/vpi/sys_readmem_lex.lex b/vpi/sys_readmem_lex.lex index ea34671b0..1755d25af 100644 --- a/vpi/sys_readmem_lex.lex +++ b/vpi/sys_readmem_lex.lex @@ -1,5 +1,6 @@ %option nounput +%option noinput %{ /* diff --git a/vvp/logic.cc b/vvp/logic.cc index 585ce8e52..3c7f79aab 100644 --- a/vvp/logic.cc +++ b/vvp/logic.cc @@ -629,7 +629,7 @@ void compile_functor(char*label, char*type, unsigned width, /* If both the strengths are the default strong drive, then there is no need for a specialized driver. Attach the label to this node and we are finished. */ - if (strength_aware || ostr0 == 6 && ostr1 == 6) { + if (strength_aware || (ostr0 == 6 && ostr1 == 6)) { define_functor_symbol(label, net); free(label); return; diff --git a/vvp/vvp_net.cc b/vvp/vvp_net.cc index 0a512ee66..cf383fe18 100644 --- a/vvp/vvp_net.cc +++ b/vvp/vvp_net.cc @@ -597,7 +597,7 @@ bool vvp_vector4_t::has_xz() const unsigned long mask = size_%BITS_PER_WORD; if (mask > 0) { mask = WORD_X_BITS >> 2*(BITS_PER_WORD - mask); - return 0 != bits_ptr_[words]&mask; + return 0 != (bits_ptr_[words]&mask); } return false; From d85683965de9a0668bcf7d26423cb85cb5de4ce1 Mon Sep 17 00:00:00 2001 From: Larry Doolittle Date: Fri, 4 Jan 2008 19:22:37 -0800 Subject: [PATCH 4/7] fix buggy SDF error message --- vpi/sys_sdf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vpi/sys_sdf.c b/vpi/sys_sdf.c index 253a0cd44..f4d332ae4 100644 --- a/vpi/sys_sdf.c +++ b/vpi/sys_sdf.c @@ -239,7 +239,7 @@ static PLI_INT32 sys_sdf_annotate_compiletf(PLI_BYTE8*name) return 0; if (vpi_get(vpiType,scope) != vpiModule) { - vpi_printf("SDF ERROR: The second argument of %s", + vpi_printf("SDF ERROR: The second argument of %s" " must be a module instance.\n", name); vpi_control(vpiFinish, 1); } From 4263f290442fef66eaac73280c315fd4a2f9edd7 Mon Sep 17 00:00:00 2001 From: Cary R Date: Sun, 6 Jan 2008 17:52:55 -0800 Subject: [PATCH 5/7] Schedule sfunc invocations to avoid recursion and clean up. This patch schedules the input value change to .sfuns calls to avoid potential recursion problems. It also cleans up two put_value calls that did unneeded loops when putting VectorVals and the width was greaten than 32 bits. --- vvp/sfunc.cc | 10 ++++++---- vvp/sfunc.h | 16 ++++------------ vvp/vpi_tasks.cc | 9 +++++---- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/vvp/sfunc.cc b/vvp/sfunc.cc index 074d329da..b4d8595d8 100644 --- a/vvp/sfunc.cc +++ b/vvp/sfunc.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2007 Stephen Williams (steve@icarus.com) + * Copyright (c) 2006-2008 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 @@ -51,7 +51,8 @@ void sfunc_core::recv_vec4_from_inputs(unsigned port) obj->bits = value(port); - invoke_function_(); + /* Schedule the actual call after this finishes. */ + schedule_generic(this, 0, false); } void sfunc_core::recv_real_from_inputs(unsigned port) @@ -64,10 +65,11 @@ void sfunc_core::recv_real_from_inputs(unsigned port) obj->value = value_r(port); - invoke_function_(); + /* Schedule the actual call after this finishes. */ + schedule_generic(this, 0, false); } -void sfunc_core::invoke_function_() +void sfunc_core::run_run() { vpip_execute_vpi_call(0, sys_); } diff --git a/vvp/sfunc.h b/vvp/sfunc.h index a3b203cb3..8b6b8eb13 100644 --- a/vvp/sfunc.h +++ b/vvp/sfunc.h @@ -1,7 +1,7 @@ #ifndef __sfunc_H #define __sfunc_H /* - * Copyright (c) 2006 Stephen Williams (steve@icarus.com) + * Copyright (c) 2006-2008 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 @@ -18,13 +18,10 @@ * 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: sfunc.h,v 1.1 2006/06/18 04:15:50 steve Exp $" -#endif # include "pointers.h" -class sfunc_core : public vvp_wide_fun_core { +class sfunc_core : public vvp_wide_fun_core, protected vvp_gen_event_s { public: sfunc_core(vvp_net_t*ptr, vpiHandle sys, unsigned argc, vpiHandle*argv); @@ -34,7 +31,8 @@ class sfunc_core : public vvp_wide_fun_core { void recv_vec4_from_inputs(unsigned port); void recv_real_from_inputs(unsigned port); - void invoke_function_(); + void run_run(); + private: vpiHandle sys_; @@ -42,10 +40,4 @@ class sfunc_core : public vvp_wide_fun_core { vpiHandle*argv_; }; -/* - * $Log: sfunc.h,v $ - * Revision 1.1 2006/06/18 04:15:50 steve - * Add support for system functions in continuous assignments. - * - */ #endif diff --git a/vvp/vpi_tasks.cc b/vvp/vpi_tasks.cc index 794f90c3c..7cace3ae3 100644 --- a/vvp/vpi_tasks.cc +++ b/vvp/vpi_tasks.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001-2007 Stephen Williams (steve@icarus.com) + * Copyright (c) 2001-2008 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 @@ -224,8 +224,8 @@ static vpiHandle sysfunc_put_value(vpiHandle ref, p_vpi_value vp) unsigned long aval = vp->value.vector[word].aval; unsigned long bval = vp->value.vector[word].bval; - for (unsigned idx = 0 ; (wdx+idx) < (unsigned)rfp->vwid ; - idx += 1) + for (unsigned idx = 0 ; (wdx+idx) < (unsigned)rfp->vwid && + idx < 32; idx += 1) { int bit = (aval&1) | ((bval<<1)&2); vvp_bit4_t bit4; @@ -339,7 +339,8 @@ static vpiHandle sysfunc_put_4net_value(vpiHandle ref, p_vpi_value vp) unsigned long aval = vp->value.vector[word].aval; unsigned long bval = vp->value.vector[word].bval; - for (unsigned idx = 0 ; (wdx+idx) < vwid ; idx += 1) { + for (unsigned idx = 0 ; (wdx+idx) < vwid && idx < 32; + idx += 1) { int bit = (aval&1) | ((bval<<1)&2); vvp_bit4_t bit4; From 61b6b8358dc1f5738fa2c3e09cc72f94e2f372a1 Mon Sep 17 00:00:00 2001 From: Cary R Date: Sun, 6 Jan 2008 19:50:59 -0800 Subject: [PATCH 6/7] Speed up the conversion functions and add file/line info. This patch modifies the conversion functions $rtoi, $itor, $realtobits and $bitstoreal calltf routines to be more efficient. This is done by caching the vpiHandle to the argument in the userdata pointer. This eliminated the need to get the argument iterator, scan and free the iterator. It also updates the error messages to use the new file and line number information that is available for system functions. It also adds a check that verifies the functions are only called with one argument and makes the errors fatal. --- vpi/sys_convert.c | 127 ++++++++++++++++------------------------------ 1 file changed, 44 insertions(+), 83 deletions(-) diff --git a/vpi/sys_convert.c b/vpi/sys_convert.c index 9c3564808..4b6ce77f3 100644 --- a/vpi/sys_convert.c +++ b/vpi/sys_convert.c @@ -16,9 +16,6 @@ * 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: sys_convert.c,v 1.7 2007/03/14 04:05:51 steve Exp $" -#endif # include "vpi_config.h" # include "vpi_user.h" @@ -86,48 +83,60 @@ static void double2bits(double real, PLI_UINT32 bits[2]) #endif } +static void error_message(vpiHandle callh, const char* msg) +{ + vpi_printf("ERROR: %s line %d: ", vpi_get_str(vpiFile, callh), + (int)vpi_get(vpiLineNo, callh)); + vpi_printf(msg, vpi_get_str(vpiName, callh)); + vpi_control(vpiFinish, 1); +} + static PLI_INT32 sizetf_32 (PLI_BYTE8*x) { return 32; } static PLI_INT32 sizetf_64 (PLI_BYTE8*x) { return 64; } static PLI_INT32 sys_convert_compiletf(PLI_BYTE8*name) { - vpiHandle call_hand, argv, arg; - PLI_INT32 rtn = 0; + vpiHandle callh = vpi_handle(vpiSysTfCall, 0); + vpiHandle argv = vpi_iterate(vpiArgument, callh); + vpiHandle arg; - call_hand = vpi_handle(vpiSysTfCall, 0); - argv = vpi_iterate(vpiArgument, call_hand); + /* Check that there is an argument. */ + if (argv == 0) { + error_message(callh, "%s requires one argument.\n"); + return 0; + } + + /* In Icarus if we have an argv we have at least one argument. */ arg = vpi_scan(argv); - if (!argv) { - vpi_printf("ERROR: %s requires a parameter.\n", - vpi_get_str(vpiName, call_hand)); - rtn = -1; - } - + /* Validate the argument. Only $bitstoreal for now. */ if (!strcmp("$bitstoreal", name) && vpi_get(vpiSize, arg) != 64) { - vpi_printf("ERROR: %s requires 64-bit argument.\n", - vpi_get_str(vpiName, call_hand)); - rtn = -1; + error_message(callh, "%s requires a 64-bit argument.\n"); + return 0; } - /* free iterator */ - vpi_free_object(argv); + /* Save the argument away to make the calltf faster. */ + vpi_put_userdata(callh, (void *) arg); - return rtn; + /* These functions only take one argument. */ + arg = vpi_scan(argv); + if (arg != 0) { + error_message(callh, "%s takes only one argument.\n"); + return 0; + } + + /* vpi_scan() returning 0 (NULL) had already freed argv. */ + return 0; } static PLI_INT32 sys_bitstoreal_calltf(PLI_BYTE8*user) { - vpiHandle sys, argv, arg; + vpiHandle callh = vpi_handle(vpiSysTfCall, 0); + vpiHandle arg = (vpiHandle) vpi_get_userdata(callh); s_vpi_value value; PLI_UINT32 bits[2]; - /* find argument handle */ - sys = vpi_handle(vpiSysTfCall, 0); - argv = vpi_iterate(vpiArgument, sys); - arg = vpi_scan(argv); - /* get value */ value.format = vpiVectorVal; vpi_get_value(arg, &value); @@ -139,24 +148,17 @@ static PLI_INT32 sys_bitstoreal_calltf(PLI_BYTE8*user) value.format = vpiRealVal; /* return converted value */ - vpi_put_value(sys, &value, 0, vpiNoDelay); - - /* free iterator */ - vpi_free_object(argv); + vpi_put_value(callh, &value, 0, vpiNoDelay); return 0; } static PLI_INT32 sys_itor_calltf(PLI_BYTE8*user) { - vpiHandle sys, argv, arg; + vpiHandle callh = vpi_handle(vpiSysTfCall, 0); + vpiHandle arg = (vpiHandle) vpi_get_userdata(callh); s_vpi_value value; - /* find argument handle */ - sys = vpi_handle(vpiSysTfCall, 0); - argv = vpi_iterate(vpiArgument, sys); - arg = vpi_scan(argv); - /* get value */ value.format = vpiIntVal; vpi_get_value(arg, &value); @@ -166,27 +168,20 @@ static PLI_INT32 sys_itor_calltf(PLI_BYTE8*user) value.format = vpiRealVal; /* return converted value */ - vpi_put_value(sys, &value, 0, vpiNoDelay); - - /* free iterator */ - vpi_free_object(argv); + vpi_put_value(callh, &value, 0, vpiNoDelay); return 0; } static PLI_INT32 sys_realtobits_calltf(PLI_BYTE8*user) { - vpiHandle sys, argv, arg; + vpiHandle callh = vpi_handle(vpiSysTfCall, 0); + vpiHandle arg = (vpiHandle) vpi_get_userdata(callh); s_vpi_value value; static struct t_vpi_vecval res[2]; PLI_UINT32 bits[2]; - /* find argument handle */ - sys = vpi_handle(vpiSysTfCall, 0); - argv = vpi_iterate(vpiArgument, sys); - arg = vpi_scan(argv); - /* get value */ value.format = vpiRealVal; vpi_get_value(arg, &value); @@ -203,25 +198,18 @@ static PLI_INT32 sys_realtobits_calltf(PLI_BYTE8*user) value.value.vector = res; /* return converted value */ - vpi_put_value(sys, &value, 0, vpiNoDelay); - - /* free iterator */ - vpi_free_object(argv); + vpi_put_value(callh, &value, 0, vpiNoDelay); return 0; } static PLI_INT32 sys_rtoi_calltf(PLI_BYTE8*user) { - vpiHandle sys, argv, arg; + vpiHandle callh = vpi_handle(vpiSysTfCall, 0); + vpiHandle arg = (vpiHandle) vpi_get_userdata(callh); s_vpi_value value; static struct t_vpi_vecval res; - /* find argument handle */ - sys = vpi_handle(vpiSysTfCall, 0); - argv = vpi_iterate(vpiArgument, sys); - arg = vpi_scan(argv); - /* get value */ value.format = vpiRealVal; vpi_get_value(arg, &value); @@ -234,10 +222,7 @@ static PLI_INT32 sys_rtoi_calltf(PLI_BYTE8*user) value.value.vector = &res; /* return converted value */ - vpi_put_value(sys, &value, 0, vpiNoDelay); - - /* free iterator */ - vpi_free_object(argv); + vpi_put_value(callh, &value, 0, vpiNoDelay); return 0; } @@ -279,27 +264,3 @@ void sys_convert_register() vpi_register_systf(&tf_data); } -/* - * $Log: sys_convert.c,v $ - * Revision 1.7 2007/03/14 04:05:51 steve - * VPI tasks take PLI_BYTE* by the standard. - * - * Revision 1.6 2006/10/30 22:45:37 steve - * Updates for Cygwin portability (pr1585922) - * - * Revision 1.5 2004/02/15 18:03:30 steve - * Cleanup of warnings. - * - * Revision 1.4 2004/01/21 01:22:53 steve - * Give the vip directory its own configure and vpi_config.h - * - * Revision 1.3 2003/03/17 21:59:54 steve - * Implement $itor and $bitstoreal - * - * Revision 1.2 2003/03/10 23:40:10 steve - * Add support for $rtoi - * - * Revision 1.1 2003/03/07 02:44:34 steve - * Implement $realtobits. - * - */ From c9e1e1b5ccb5218aea2584f4672db5aef96990f3 Mon Sep 17 00:00:00 2001 From: Cary R Date: Mon, 7 Jan 2008 12:12:06 -0800 Subject: [PATCH 7/7] Add missing include to sdf_lexor.lex sdf_lexor.lex was missing the include file which defines strdup and strlen. --- vpi/sdf_lexor.lex | 1 + 1 file changed, 1 insertion(+) diff --git a/vpi/sdf_lexor.lex b/vpi/sdf_lexor.lex index f8a263ccf..c14b89cca 100644 --- a/vpi/sdf_lexor.lex +++ b/vpi/sdf_lexor.lex @@ -27,6 +27,7 @@ # include "sdf_parse_priv.h" # include "sdf_parse.h" # include +# include # include # include