From b1c0f7306d78bbd5cb9bc1b20e3b380e9063c3d9 Mon Sep 17 00:00:00 2001 From: steve Date: Sat, 18 May 2002 02:34:11 +0000 Subject: [PATCH] Add vpi support for named events. Add vpi_mode_flag to track the mode of the vpi engine. This is for error checking. --- vpi_user.h | 9 +++++- vvp/Makefile.in | 4 +-- vvp/compile.h | 9 +++++- vvp/event.cc | 34 ++++++++++++++++---- vvp/parse.y | 10 ++++-- vvp/vpi_callback.cc | 27 +++++++++++++++- vvp/vpi_event.cc | 77 +++++++++++++++++++++++++++++++++++++++++++++ vvp/vpi_modules.cc | 11 +++++-- vvp/vpi_priv.cc | 36 ++++++++++----------- vvp/vpi_priv.h | 34 +++++++++++++++++++- vvp/vpi_scope.cc | 11 ++++++- vvp/vpi_tasks.cc | 18 +++++++++-- 12 files changed, 241 insertions(+), 39 deletions(-) create mode 100644 vvp/vpi_event.cc diff --git a/vpi_user.h b/vpi_user.h index 2a2193dfb..c78d48ace 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 */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: vpi_user.h,v 1.8 2002/05/17 16:13:08 steve Exp $" +#ident "$Id: vpi_user.h,v 1.9 2002/05/18 02:34:11 steve Exp $" #endif @@ -150,6 +150,7 @@ typedef struct t_vpi_value { #define vpiMemoryWord 30 #define vpiModule 32 #define vpiNamedBegin 33 +#define vpiNamedEvent 34 #define vpiNamedFork 35 #define vpiNet 36 #define vpiReg 48 @@ -312,6 +313,12 @@ EXTERN_C_END /* * $Log: vpi_user.h,v $ + * Revision 1.9 2002/05/18 02:34:11 steve + * Add vpi support for named events. + * + * Add vpi_mode_flag to track the mode of the + * vpi engine. This is for error checking. + * * Revision 1.8 2002/05/17 16:13:08 steve * Add vpiIndex update. * diff --git a/vvp/Makefile.in b/vvp/Makefile.in index 129664847..f4ff819d5 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.37 2002/05/11 04:39:35 steve Exp $" +#ident "$Id: Makefile.in,v 1.38 2002/05/18 02:34:11 steve Exp $" # # SHELL = /bin/sh @@ -61,7 +61,7 @@ distclean: clean check: all ./vvp -M../vpi $(srcdir)/examples/hello.vvp | grep 'Hello, World.' -V = vpi_modules.o vpi_callback.o vpi_const.o vpi_iter.o vpi_mcd.o \ +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_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 diff --git a/vvp/compile.h b/vvp/compile.h index 337b62e46..498fd72d8 100644 --- a/vvp/compile.h +++ b/vvp/compile.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) -#ident "$Id: compile.h,v 1.41 2002/03/18 00:19:34 steve Exp $" +#ident "$Id: compile.h,v 1.42 2002/05/18 02:34:11 steve Exp $" #endif # include @@ -183,6 +183,7 @@ extern void compile_ufunc(char*label, char*code, unsigned wid, */ extern void compile_event(char*label, char*type, unsigned argc, struct symb_s*argv); +extern void compile_named_event(char*label, char*type); /* * A code statement is a label, an opcode and up to 3 operands. There @@ -248,6 +249,12 @@ extern void compile_net(char*label, char*name, /* * $Log: compile.h,v $ + * Revision 1.42 2002/05/18 02:34:11 steve + * Add vpi support for named events. + * + * Add vpi_mode_flag to track the mode of the + * vpi engine. This is for error checking. + * * Revision 1.41 2002/03/18 00:19:34 steve * Add the .ufunc statement. * diff --git a/vvp/event.cc b/vvp/event.cc index 88f2ee570..c454bb5e7 100644 --- a/vvp/event.cc +++ b/vvp/event.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) -#ident "$Id: event.cc,v 1.5 2002/03/17 03:24:34 steve Exp $" +#ident "$Id: event.cc,v 1.6 2002/05/18 02:34:11 steve Exp $" #endif # include "event.h" @@ -91,7 +91,8 @@ void event_functor_s::set(vvp_ipoint_t ptr, bool, unsigned val, unsigned) ** Create an event functor ** edge: compile_event(label, type, argc, argv) ** or: compile_event(label, NULL, argc, argv) -** name: compile_event(label, name, NULL, NULL) +** +** Named events are handled elsewhere. */ void compile_event(char*label, char*type, @@ -109,10 +110,6 @@ void compile_event(char*label, char*type, assert(argc <= 4 || edge == vvp_edge_none); } - - if (!argc && type) { - // "type" is the name of the named event - } free(type); @@ -144,8 +141,33 @@ void compile_event(char*label, char*type, free(argv); } +/* + * This handles the compile of named events. This functor has no + * inputs, it is only accessed by behavioral trigger statements, which + * in vvp are %set instructions. + */ +void compile_named_event(char*label, char*name) +{ + functor_t obj = new event_functor_s(vvp_edge_none); + + vvp_ipoint_t fdx = functor_allocate(1); + functor_define(fdx, obj); + define_functor_symbol(label, fdx); + + vpiHandle vpi = vpip_make_named_event(name); + vpip_attach_to_current_scope(vpi); + + free(label); +} + /* * $Log: event.cc,v $ + * Revision 1.6 2002/05/18 02:34:11 steve + * Add vpi support for named events. + * + * Add vpi_mode_flag to track the mode of the + * vpi engine. This is for error checking. + * * Revision 1.5 2002/03/17 03:24:34 steve * Clean up edge detection code. * diff --git a/vvp/parse.y b/vvp/parse.y index aef9f48ce..9c3096850 100644 --- a/vvp/parse.y +++ b/vvp/parse.y @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) -#ident "$Id: parse.y,v 1.45 2002/03/31 04:06:49 steve Exp $" +#ident "$Id: parse.y,v 1.46 2002/05/18 02:34:11 steve Exp $" #endif # include "parse_misc.h" @@ -244,7 +244,7 @@ statement { compile_event($1, $3, $5.cnt, $5.vect); } | T_LABEL K_EVENT T_STRING ';' - { compile_event($1, $3, 0, 0); } + { compile_named_event($1, $3); } | T_LABEL K_EVENT_OR symbols ';' { compile_event($1, 0, $3.cnt, $3.vect); } @@ -550,6 +550,12 @@ int compile_design(const char*path) /* * $Log: parse.y,v $ + * Revision 1.46 2002/05/18 02:34:11 steve + * Add vpi support for named events. + * + * Add vpi_mode_flag to track the mode of the + * vpi engine. This is for error checking. + * * Revision 1.45 2002/03/31 04:06:49 steve * Update for newer bison. * diff --git a/vvp/vpi_callback.cc b/vvp/vpi_callback.cc index 5101c0b03..15fa5f45a 100644 --- a/vvp/vpi_callback.cc +++ b/vvp/vpi_callback.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) -#ident "$Id: vpi_callback.cc,v 1.15 2002/05/09 03:34:31 steve Exp $" +#ident "$Id: vpi_callback.cc,v 1.16 2002/05/18 02:34:11 steve Exp $" #endif /* @@ -237,7 +237,11 @@ static void make_sync_run(vvp_gen_event_t obj, unsigned char) struct __vpiCallback*cur = cb->handle; cur->cb_data.time->type = vpiSimTime; vpip_time_to_timestruct(cur->cb_data.time, schedule_simtime()); + + assert(vpi_mode_flag == VPI_MODE_NONE); + vpi_mode_flag = VPI_MODE_RWSYNC; (cur->cb_data.cb_rtn)(&cur->cb_data); + vpi_mode_flag = VPI_MODE_NONE; vpi_free_object(&cur->base); } @@ -297,6 +301,9 @@ void vpiPresim() { * Walk the list of register callbacks, executing them and * freeing them when done. */ + assert(vpi_mode_flag == VPI_MODE_NONE); + vpi_mode_flag = VPI_MODE_RWSYNC; + while (EndOfCompile) { cur = EndOfCompile; EndOfCompile = cur->next; @@ -310,6 +317,8 @@ void vpiPresim() { (cur->cb_data.cb_rtn)(&cur->cb_data); vpi_free_object(&cur->base); } + + vpi_mode_flag = VPI_MODE_NONE; } void vpiPostsim() { @@ -318,12 +327,17 @@ void vpiPostsim() { /* * Walk the list of register callbacks */ + assert(vpi_mode_flag == VPI_MODE_NONE); + vpi_mode_flag = VPI_MODE_ROSYNC; + while (EndOfSimulation) { cur = EndOfSimulation; EndOfSimulation = cur->next; (cur->cb_data.cb_rtn)(&cur->cb_data); vpi_free_object(&cur->base); } + + vpi_mode_flag = VPI_MODE_NONE; } static struct __vpiCallback* make_prepost(p_cb_data data) @@ -420,10 +434,15 @@ void callback_functor_s::set(vvp_ipoint_t, bool, unsigned val, unsigned) fprintf(stderr, "vpi_callback: value format %d not supported\n", cur->cb_data.value->format); } } + + assert(vpi_mode_flag == VPI_MODE_NONE); + vpi_mode_flag = VPI_MODE_RWSYNC; + cur->cb_data.time->type = vpiSimTime; vpip_time_to_timestruct(cur->cb_data.time, schedule_simtime()); (cur->cb_data.cb_rtn)(&cur->cb_data); + vpi_mode_flag = VPI_MODE_NONE; } } @@ -431,6 +450,12 @@ void callback_functor_s::set(vvp_ipoint_t, bool, unsigned val, unsigned) /* * $Log: vpi_callback.cc,v $ + * Revision 1.16 2002/05/18 02:34:11 steve + * Add vpi support for named events. + * + * Add vpi_mode_flag to track the mode of the + * vpi engine. This is for error checking. + * * Revision 1.15 2002/05/09 03:34:31 steve * Handle null time and calltf pointers. * diff --git a/vvp/vpi_event.cc b/vvp/vpi_event.cc new file mode 100644 index 000000000..bcf452645 --- /dev/null +++ b/vvp/vpi_event.cc @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2002 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 + */ +#if !defined(WINNT) +#ident "$Id: vpi_event.cc,v 1.1 2002/05/18 02:34:11 steve Exp $" +#endif + +# include "vpi_priv.h" +# include "functor.h" +# include +#ifdef HAVE_MALLOC_H +# include +#endif +# include +# include +# include + +struct __vpiNamedEvent { + struct __vpiHandle base; + /* base name of the event object */ + char*name; + /* Parent scope of this object. */ + struct __vpiScope*scope; +}; + +static const struct __vpirt vpip_named_event_rt = { + vpiNamedEvent, + + 0, + 0, + 0, + 0, + + 0, + 0, + 0, + + 0 +}; + +vpiHandle vpip_make_named_event(char*name) +{ + struct __vpiNamedEvent*obj = (struct __vpiNamedEvent*) + malloc(sizeof(struct __vpiNamedEvent)); + + obj->base.vpi_type = &vpip_named_event_rt; + obj->name = name; + obj->scope = vpip_peek_current_scope(); + + return &obj->base; +} + +/* + * $Log: vpi_event.cc,v $ + * Revision 1.1 2002/05/18 02:34:11 steve + * Add vpi support for named events. + * + * Add vpi_mode_flag to track the mode of the + * vpi engine. This is for error checking. + * + */ + diff --git a/vvp/vpi_modules.cc b/vvp/vpi_modules.cc index a7367dbe6..876d47215 100644 --- a/vvp/vpi_modules.cc +++ b/vvp/vpi_modules.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) -#ident "$Id: vpi_modules.cc,v 1.10 2002/03/05 05:31:52 steve Exp $" +#ident "$Id: vpi_modules.cc,v 1.11 2002/05/18 02:34:11 steve Exp $" #endif # include "config.h" @@ -130,14 +130,21 @@ void vpip_load_module(const char*name) return; } + vpi_mode_flag = VPI_MODE_REGISTER; vlog_startup_routines_t*routines = (vlog_startup_routines_t*)table; for (unsigned tmp = 0 ; routines[tmp] ; tmp += 1) (routines[tmp])(); - + vpi_mode_flag = VPI_MODE_NONE; } /* * $Log: vpi_modules.cc,v $ + * Revision 1.11 2002/05/18 02:34:11 steve + * Add vpi support for named events. + * + * Add vpi_mode_flag to track the mode of the + * vpi engine. This is for error checking. + * * Revision 1.10 2002/03/05 05:31:52 steve * Better linker error messages. * diff --git a/vvp/vpi_priv.cc b/vvp/vpi_priv.cc index 9ca28b30f..a9fa24ac5 100644 --- a/vvp/vpi_priv.cc +++ b/vvp/vpi_priv.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) -#ident "$Id: vpi_priv.cc,v 1.14 2002/05/03 15:44:11 steve Exp $" +#ident "$Id: vpi_priv.cc,v 1.15 2002/05/18 02:34:11 steve Exp $" #endif # include "vpi_priv.h" @@ -30,6 +30,8 @@ #endif # include +vpi_mode_t vpi_mode_flag = VPI_MODE_NONE; + /* * When a task is called, this value is set so that vpi_handle can * fathom the vpi_handle(vpiSysTfCall,0) function. @@ -157,6 +159,13 @@ static vpiHandle vpi_iterate_global(int type) vpiHandle vpi_iterate(int type, vpiHandle ref) { + assert(vpi_mode_flag != VPI_MODE_NONE); + if (vpi_mode_flag == VPI_MODE_REGISTER) { + fprintf(stderr, "vpi error: vpi_iterate called during " + "vpi_register_systf. You can't do that!\n"); + return 0; + } + if (ref == 0) return vpi_iterate_global(type); @@ -190,6 +199,12 @@ extern "C" void vpi_sim_vcontrol(int operation, va_list ap) /* * $Log: vpi_priv.cc,v $ + * Revision 1.15 2002/05/18 02:34:11 steve + * Add vpi support for named events. + * + * Add vpi_mode_flag to track the mode of the + * vpi engine. This is for error checking. + * * Revision 1.14 2002/05/03 15:44:11 steve * Add vpiModule iterator to vpiScope objects. * @@ -219,24 +234,5 @@ extern "C" void vpi_sim_vcontrol(int operation, va_list ap) * * Revision 1.6 2001/06/21 22:54:12 steve * Support cbValueChange callbacks. - * - * Revision 1.5 2001/06/12 03:53:11 steve - * Change the VPI call process so that loaded .vpi modules - * use a function table instead of implicit binding. - * - * Revision 1.4 2001/06/10 16:47:49 steve - * support scan of scope from VPI. - * - * Revision 1.3 2001/04/03 03:46:14 steve - * VPI access time as a decimal string, and - * stub vpi access to the scopes. - * - * Revision 1.2 2001/03/19 01:55:38 steve - * Add support for the vpiReset sim control. - * - * Revision 1.1 2001/03/16 01:44:34 steve - * Add structures for VPI support, and all the %vpi_call - * instruction. Get linking of VPI modules to work. - * */ diff --git a/vvp/vpi_priv.h b/vvp/vpi_priv.h index 347bf943b..767e3b283 100644 --- a/vvp/vpi_priv.h +++ b/vvp/vpi_priv.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) -#ident "$Id: vpi_priv.h,v 1.34 2002/05/17 04:12:19 steve Exp $" +#ident "$Id: vpi_priv.h,v 1.35 2002/05/18 02:34:11 steve Exp $" #endif # include "vpi_user.h" @@ -33,6 +33,25 @@ */ +/* + * The vpi_mode_flag contains the major mode for VPI use. This is used + * to generate error messages whe vpi functions are called + * incorrectly. + */ +enum vpi_mode_t { + VPI_MODE_NONE =0, + /* The compiler is calling a register function. */ + VPI_MODE_REGISTER, + /* The compiler is calling a compiletf function. */ + VPI_MODE_COMPILETF, + /* The compiler is calling a calltf function. */ + VPI_MODE_CALLTF, + /* We are in the midst of a RWSync callback. */ + VPI_MODE_RWSYNC, + /* We are in a ROSync callback. */ + VPI_MODE_ROSYNC +}; +extern vpi_mode_t vpi_mode_flag; /* * This structure is the very base of a vpiHandle. Every handle @@ -131,6 +150,13 @@ extern vpiHandle vpip_make_reg(char*name, int msb, int lsb, bool signed_flag, extern vpiHandle vpip_make_net(char*name, int msb, int lsb, bool signed_flag, vvp_fvector_t vec); +/* + * These methods support the vpi creation of events. The name string + * passed in will be saved, so the caller must allocate it (or not + * free it) after it is handed to this function. + */ +extern vpiHandle vpip_make_named_event(char*name); + /* * Memory is an array of bits that is accessible in N-bit chunks, with * N being the width of a word. The memory word handle just points @@ -300,6 +326,12 @@ extern void vpip_oct_str_to_bits(unsigned char*bits, unsigned nbits, /* * $Log: vpi_priv.h,v $ + * Revision 1.35 2002/05/18 02:34:11 steve + * Add vpi support for named events. + * + * Add vpi_mode_flag to track the mode of the + * vpi engine. This is for error checking. + * * Revision 1.34 2002/05/17 04:12:19 steve * Rewire vpiMemory and vpiMemoryWord handles to * support proper iteration of words, and the diff --git a/vvp/vpi_scope.cc b/vvp/vpi_scope.cc index 014656c66..174ade008 100644 --- a/vvp/vpi_scope.cc +++ b/vvp/vpi_scope.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) -#ident "$Id: vpi_scope.cc,v 1.14 2002/05/10 16:00:57 steve Exp $" +#ident "$Id: vpi_scope.cc,v 1.15 2002/05/18 02:34:11 steve Exp $" #endif # include "compile.h" @@ -35,6 +35,8 @@ static unsigned vpip_root_table_cnt = 0; vpiHandle vpip_make_root_iterator(void) { + assert(vpip_root_table_ptr); + assert(vpip_root_table_cnt); return vpip_make_iterator(vpip_root_table_cnt, vpip_root_table_ptr, false); } @@ -136,6 +138,7 @@ static vpiHandle module_iter(int code, vpiHandle obj) in this scope. */ case vpiMemory: case vpiModule: + case vpiNamedEvent: case vpiNet: case vpiReg: return module_iter_subset(code, ref); @@ -381,6 +384,12 @@ void vpip_attach_to_current_scope(vpiHandle obj) /* * $Log: vpi_scope.cc,v $ + * Revision 1.15 2002/05/18 02:34:11 steve + * Add vpi support for named events. + * + * Add vpi_mode_flag to track the mode of the + * vpi engine. This is for error checking. + * * Revision 1.14 2002/05/10 16:00:57 steve * Support scope iterate over vpiNet,vpiReg/vpiMemory. * diff --git a/vvp/vpi_tasks.cc b/vvp/vpi_tasks.cc index 3e22c7a84..c7f9b2be4 100644 --- a/vvp/vpi_tasks.cc +++ b/vvp/vpi_tasks.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) -#ident "$Id: vpi_tasks.cc,v 1.13 2002/05/09 03:34:31 steve Exp $" +#ident "$Id: vpi_tasks.cc,v 1.14 2002/05/18 02:34:11 steve Exp $" #endif /* @@ -279,9 +279,13 @@ vpiHandle vpip_build_vpi_call(const char*name, unsigned vbit, unsigned vwid, /* If there is a compiletf function, call it here. */ if (obj->defn->info.compiletf) { + + assert(vpi_mode_flag == VPI_MODE_NONE); + vpi_mode_flag = VPI_MODE_COMPILETF; vpip_cur_task = obj; obj->defn->info.compiletf (obj->defn->info.user_data); vpip_cur_task = 0; + vpi_mode_flag = VPI_MODE_NONE; } return &obj->base; @@ -305,8 +309,12 @@ void vpip_execute_vpi_call(vthread_t thr, vpiHandle ref) vpip_cur_task = (struct __vpiSysTaskCall*)ref; - if (vpip_cur_task->defn->info.calltf) + if (vpip_cur_task->defn->info.calltf) { + assert(vpi_mode_flag == VPI_MODE_NONE); + vpi_mode_flag = VPI_MODE_CALLTF; vpip_cur_task->defn->info.calltf(vpip_cur_task->defn->info.user_data); + vpi_mode_flag = VPI_MODE_NONE; + } } /* @@ -335,6 +343,12 @@ void vpi_register_systf(const struct t_vpi_systf_data*ss) /* * $Log: vpi_tasks.cc,v $ + * Revision 1.14 2002/05/18 02:34:11 steve + * Add vpi support for named events. + * + * Add vpi_mode_flag to track the mode of the + * vpi engine. This is for error checking. + * * Revision 1.13 2002/05/09 03:34:31 steve * Handle null time and calltf pointers. *