The $time system task returns the integer time

scaled to the local units. Change the internal
 implementation of vpiSystemTime the $time functions
 to properly account for this. Also add $simtime
 to get the simulation time.
This commit is contained in:
steve 2002-12-21 00:55:57 +00:00
parent 42b34c2ce6
commit c2070777b2
22 changed files with 372 additions and 58 deletions

View File

@ -344,6 +344,19 @@ language that are defined.
The $sizeof function is deprecated in favor of $bits, which is
the same thing, but included in the SystemVerilog definition.
$simtime
The $simtime system function returns as a 64bit value the
simulation time, unscaled by the time units of local
scope. This is different from the $time and $stime functions
which return the scaled times. This function is added for
regression testing of the compiler and run time, but can be
used by applications who really want the simulation time.
Note that the simulation time can be confusing if there are
lots of different `timescales within a design. It is not in
general possible to predict what the simulation precision will
turn out to be.
Builtin system functions
Certain of the system functions have well defined meanings, so

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: elab_expr.cc,v 1.66 2002/09/21 21:28:18 steve Exp $"
#ident "$Id: elab_expr.cc,v 1.67 2002/12/21 00:55:57 steve Exp $"
#endif
# include "config.h"
@ -215,6 +215,8 @@ NetExpr* PECallFunction::elaborate_sfunc_(Design*des, NetScope*scope) const
if (strcmp(path_.peek_name(0), "$time") == 0)
wid = 64;
if (strcmp(path_.peek_name(0), "$simtime") == 0)
wid = 64;
if (strcmp(path_.peek_name(0), "$stime") == 0)
wid = 32;
@ -885,6 +887,13 @@ NetExpr* PEUnary::elaborate_expr(Design*des, NetScope*scope, bool) const
/*
* $Log: elab_expr.cc,v $
* Revision 1.67 2002/12/21 00:55:57 steve
* The $time system task returns the integer time
* scaled to the local units. Change the internal
* implementation of vpiSystemTime the $time functions
* to properly account for this. Also add $simtime
* to get the simulation time.
*
* Revision 1.66 2002/09/21 21:28:18 steve
* Allow constant bit selects out of range.
*

View File

@ -120,6 +120,7 @@ ivl_scope_port
ivl_scope_ports
ivl_scope_sigs
ivl_scope_sig
ivl_scope_time_units
ivl_scope_type
ivl_scope_tname

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: ivl_target.h,v 1.108 2002/10/23 01:47:17 steve Exp $"
#ident "$Id: ivl_target.h,v 1.109 2002/12/21 00:55:58 steve Exp $"
#endif
#ifdef __cplusplus
@ -861,6 +861,11 @@ extern ivl_signal_t ivl_nexus_ptr_sig(ivl_nexus_ptr_t net);
* anything that can become and ivl_signal_t, include synthetic
* signals generated by the compiler.
*
* ivl_scope_time_units
* Scopes have their own intrinsic time units, typically from the
* timescale compiler directive. This method returns the units as a
* signed power of 10 value.
*
* ivl_scope_type
* ivl_scope_tname
* Scopes have a type and a type name. For example, if a scope is
@ -891,6 +896,7 @@ extern unsigned ivl_scope_sigs(ivl_scope_t net);
extern ivl_signal_t ivl_scope_sig(ivl_scope_t net, unsigned idx);
extern ivl_scope_type_t ivl_scope_type(ivl_scope_t net);
extern const char* ivl_scope_tname(ivl_scope_t net);
extern int ivl_scope_time_units(ivl_scope_t net);
/* SIGNALS
@ -1091,6 +1097,13 @@ _END_DECL
/*
* $Log: ivl_target.h,v $
* Revision 1.109 2002/12/21 00:55:58 steve
* The $time system task returns the integer time
* scaled to the local units. Change the internal
* implementation of vpiSystemTime the $time functions
* to properly account for this. Also add $simtime
* to get the simulation time.
*
* Revision 1.108 2002/10/23 01:47:17 steve
* Fix synth2 handling of aset/aclr signals where
* flip-flops are split by begin-end blocks.

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: t-dll-api.cc,v 1.88 2002/10/23 01:47:17 steve Exp $"
#ident "$Id: t-dll-api.cc,v 1.89 2002/12/21 00:55:58 steve Exp $"
#endif
# include "config.h"
@ -1157,6 +1157,12 @@ extern "C" ivl_signal_t ivl_scope_sig(ivl_scope_t net, unsigned idx)
return net->sigs_[idx];
}
extern "C" int ivl_scope_time_units(ivl_scope_t net)
{
assert(net);
return net->time_units;
}
extern "C" ivl_scope_type_t ivl_scope_type(ivl_scope_t net)
{
assert(net);
@ -1585,6 +1591,13 @@ extern "C" ivl_statement_t ivl_stmt_sub_stmt(ivl_statement_t net)
/*
* $Log: t-dll-api.cc,v $
* Revision 1.89 2002/12/21 00:55:58 steve
* The $time system task returns the integer time
* scaled to the local units. Change the internal
* implementation of vpiSystemTime the $time functions
* to properly account for this. Also add $simtime
* to get the simulation time.
*
* Revision 1.88 2002/10/23 01:47:17 steve
* Fix synth2 handling of aset/aclr signals where
* flip-flops are split by begin-end blocks.

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: t-dll.cc,v 1.100 2002/11/05 02:12:35 steve Exp $"
#ident "$Id: t-dll.cc,v 1.101 2002/12/21 00:55:58 steve Exp $"
#endif
# include "config.h"
@ -435,6 +435,8 @@ void dll_target::add_root(ivl_design_s &des_, const NetScope *s)
root_->mem_ = 0;
root_->type_ = IVL_SCT_MODULE;
root_->tname_ = root_->name_;
root_->time_units = s->time_unit();
des_.nroots_++;
if (des_.roots_)
des_.roots_ = (ivl_scope_t *)realloc(des_.roots_, des_.nroots_ * sizeof(ivl_scope_t));
@ -1776,6 +1778,7 @@ void dll_target::scope(const NetScope*net)
scope->lpm_ = 0;
scope->nmem_ = 0;
scope->mem_ = 0;
scope->time_units = net->time_unit();
switch (net->type()) {
case NetScope::MODULE:
@ -1981,6 +1984,13 @@ extern const struct target tgt_dll = { "dll", &dll_target_obj };
/*
* $Log: t-dll.cc,v $
* Revision 1.101 2002/12/21 00:55:58 steve
* The $time system task returns the integer time
* scaled to the local units. Change the internal
* implementation of vpiSystemTime the $time functions
* to properly account for this. Also add $simtime
* to get the simulation time.
*
* Revision 1.100 2002/11/05 02:12:35 steve
* Fix the call to FormatMessage under Windows.
*

11
t-dll.h
View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: t-dll.h,v 1.95 2002/10/23 01:47:17 steve Exp $"
#ident "$Id: t-dll.h,v 1.96 2002/12/21 00:55:58 steve Exp $"
#endif
# include "target.h"
@ -500,6 +500,8 @@ struct ivl_scope_s {
unsigned ports;
ivl_signal_t*port;
signed int time_units :8;
};
/*
@ -622,6 +624,13 @@ struct ivl_statement_s {
/*
* $Log: t-dll.h,v $
* Revision 1.96 2002/12/21 00:55:58 steve
* The $time system task returns the integer time
* scaled to the local units. Change the internal
* implementation of vpiSystemTime the $time functions
* to properly account for this. Also add $simtime
* to get the simulation time.
*
* Revision 1.95 2002/10/23 01:47:17 steve
* Fix synth2 handling of aset/aclr signals where
* flip-flops are split by begin-end blocks.

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: stub.c,v 1.70 2002/10/23 01:45:24 steve Exp $"
#ident "$Id: stub.c,v 1.71 2002/12/21 00:55:58 steve Exp $"
#endif
# include "config.h"
@ -666,26 +666,28 @@ static int show_scope(ivl_scope_t net, void*x)
switch (ivl_scope_type(net)) {
case IVL_SCT_MODULE:
fprintf(out, " module %s\n", ivl_scope_tname(net));
fprintf(out, " module %s", ivl_scope_tname(net));
break;
case IVL_SCT_FUNCTION:
fprintf(out, " function %s\n", ivl_scope_tname(net));
fprintf(out, " function %s", ivl_scope_tname(net));
break;
case IVL_SCT_BEGIN:
fprintf(out, " begin : %s\n", ivl_scope_tname(net));
fprintf(out, " begin : %s", ivl_scope_tname(net));
break;
case IVL_SCT_FORK:
fprintf(out, " fork : %s\n", ivl_scope_tname(net));
fprintf(out, " fork : %s", ivl_scope_tname(net));
break;
case IVL_SCT_TASK:
fprintf(out, " task %s\n", ivl_scope_tname(net));
fprintf(out, " task %s", ivl_scope_tname(net));
break;
default:
fprintf(out, " type(%u) %s\n", ivl_scope_type(net),
fprintf(out, " type(%u) %s", ivl_scope_type(net),
ivl_scope_tname(net));
break;
}
fprintf(out, " time units = 10e%d\n", ivl_scope_time_units(net));
for (idx = 0 ; idx < ivl_scope_events(net) ; idx += 1)
show_event(ivl_scope_event(net, idx));
@ -728,6 +730,13 @@ int target_design(ivl_design_t des)
/*
* $Log: stub.c,v $
* Revision 1.71 2002/12/21 00:55:58 steve
* The $time system task returns the integer time
* scaled to the local units. Change the internal
* implementation of vpiSystemTime the $time functions
* to properly account for this. Also add $simtime
* to get the simulation time.
*
* Revision 1.70 2002/10/23 01:45:24 steve
* Fix synth2 handling of aset/aclr signals where
* flip-flops are split by begin-end blocks.

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: vvp_scope.c,v 1.81 2002/11/21 18:08:09 steve Exp $"
#ident "$Id: vvp_scope.c,v 1.82 2002/12/21 00:55:58 steve Exp $"
#endif
# include "vvp_priv.h"
@ -1547,12 +1547,16 @@ int draw_scope(ivl_scope_t net, ivl_scope_t parent)
vvp_mangle_id(ivl_scope_name(net)),
type,
vvp_mangle_name(ivl_scope_name(net)));
if (parent) {
fprintf(vvp_out, ", S_%s;\n",
vvp_mangle_id(ivl_scope_name(parent)));
}
else
} else {
fprintf(vvp_out, ";\n");
}
fprintf(vvp_out, " .timescale %d;\n", ivl_scope_time_units(net));
/* Scan the scope for logic devices. For each device, draw out
a functor that connects pin 0 to the output, and the
@ -1607,6 +1611,13 @@ int draw_scope(ivl_scope_t net, ivl_scope_t parent)
/*
* $Log: vvp_scope.c,v $
* Revision 1.82 2002/12/21 00:55:58 steve
* The $time system task returns the integer time
* scaled to the local units. Change the internal
* implementation of vpiSystemTime the $time functions
* to properly account for this. Also add $simtime
* to get the simulation time.
*
* Revision 1.81 2002/11/21 18:08:09 steve
* Better handling of select width of shifters.
*

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: sys_lxt.c,v 1.12 2002/11/17 22:28:42 steve Exp $"
#ident "$Id: sys_lxt.c,v 1.13 2002/12/21 00:55:58 steve Exp $"
#endif
# include "config.h"
@ -343,6 +343,7 @@ static int sys_dumpoff_calltf(char*name)
if (dump_header_pending())
return 0;
now.type = vpiSimTime;
vpi_get_time(0, &now);
if (now.low > vcd_cur_time)
lt_set_time(dump_file, now.low);
@ -368,6 +369,7 @@ static int sys_dumpon_calltf(char*name)
if (dump_header_pending())
return 0;
now.type = vpiSimTime;
vpi_get_time(0, &now);
if (now.low > vcd_cur_time)
lt_set_time(dump_file, now.low);
@ -388,6 +390,7 @@ static int sys_dumpall_calltf(char*name)
if (dump_header_pending())
return 0;
now.type = vpiSimTime;
vpi_get_time(0, &now);
if (now.low > vcd_cur_time)
lt_set_time(dump_file, now.low);
@ -817,6 +820,13 @@ void sys_lxt_register()
/*
* $Log: sys_lxt.c,v $
* Revision 1.13 2002/12/21 00:55:58 steve
* The $time system task returns the integer time
* scaled to the local units. Change the internal
* implementation of vpiSystemTime the $time functions
* to properly account for this. Also add $simtime
* to get the simulation time.
*
* Revision 1.12 2002/11/17 22:28:42 steve
* Close old file if $dumpfile is called again.
*

View File

@ -17,14 +17,25 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: sys_time.c,v 1.4 2002/08/12 01:35:05 steve Exp $"
#ident "$Id: sys_time.c,v 1.5 2002/12/21 00:55:58 steve Exp $"
#endif
# include "config.h"
# include "vpi_user.h"
# include <string.h>
# include <assert.h>
static vpiHandle module_of_function(vpiHandle obj)
{
while (vpi_get(vpiType, obj) != vpiModule) {
obj = vpi_handle(vpiScope, obj);
assert(obj);
}
return obj;
}
static int sys_time_sizetf(char*x)
{
return 64;
@ -40,16 +51,39 @@ static int sys_time_calltf(char*name)
s_vpi_value val;
s_vpi_time now;
vpiHandle call_handle;
vpiHandle mod;
int units, prec;
long scale;
call_handle = vpi_handle(vpiSysTfCall, 0);
assert(call_handle);
mod = module_of_function(call_handle);
now.type = vpiSimTime;
vpi_get_time(0, &now);
/* All the variants but $simtime return the time in units of
the local scope. The $simtime function returns the
simulation time. */
if (strcmp(name, "$simtime") == 0)
units = vpi_get(vpiTimePrecision, 0);
else
units = vpi_get(vpiTimeUnit, mod);
prec = vpi_get(vpiTimePrecision, 0);
scale = 1;
while (units > prec) {
scale *= 10;
units -= 1;
}
val.format = vpiIntVal;
val.value.integer = now.low;
assert(now.high == 0);
val.value.integer /= scale;
vpi_put_value(call_handle, &val, 0, vpiNoDelay);
return 0;
@ -64,6 +98,7 @@ void sys_time_register()
tf_data.calltf = sys_time_calltf;
tf_data.compiletf = 0;
tf_data.sizetf = sys_time_sizetf;
tf_data.user_data = "$time";
vpi_register_systf(&tf_data);
tf_data.type = vpiSysFunc;
@ -71,11 +106,27 @@ void sys_time_register()
tf_data.calltf = sys_time_calltf;
tf_data.compiletf = 0;
tf_data.sizetf = sys_stime_sizetf;
tf_data.user_data = "$stime";
vpi_register_systf(&tf_data);
tf_data.type = vpiSysFunc;
tf_data.tfname = "$simtime";
tf_data.calltf = sys_time_calltf;
tf_data.compiletf = 0;
tf_data.sizetf = sys_time_sizetf;
tf_data.user_data = "$simtime";
vpi_register_systf(&tf_data);
}
/*
* $Log: sys_time.c,v $
* Revision 1.5 2002/12/21 00:55:58 steve
* The $time system task returns the integer time
* scaled to the local units. Change the internal
* implementation of vpiSystemTime the $time functions
* to properly account for this. Also add $simtime
* to get the simulation time.
*
* Revision 1.4 2002/08/12 01:35:05 steve
* conditional ident string using autoconfig.
*

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: sys_vcd.c,v 1.39 2002/11/17 22:28:42 steve Exp $"
#ident "$Id: sys_vcd.c,v 1.40 2002/12/21 00:55:58 steve Exp $"
#endif
# include "config.h"
@ -315,6 +315,7 @@ static int sys_dumpoff_calltf(char*name)
if (dump_header_pending())
return 0;
now.type = vpiSimTime;
vpi_get_time(0, &now);
if (now.low > vcd_cur_time)
fprintf(dump_file, "#%u\n", now.low);
@ -342,6 +343,7 @@ static int sys_dumpon_calltf(char*name)
if (dump_header_pending())
return 0;
now.type = vpiSimTime;
vpi_get_time(0, &now);
if (now.low > vcd_cur_time)
fprintf(dump_file, "#%u\n", now.low);
@ -364,6 +366,7 @@ static int sys_dumpall_calltf(char*name)
if (dump_header_pending())
return 0;
now.type = vpiSimTime;
vpi_get_time(0, &now);
if (now.low > vcd_cur_time)
fprintf(dump_file, "#%u\n", now.low);
@ -849,6 +852,13 @@ void sys_vcd_register()
/*
* $Log: sys_vcd.c,v $
* Revision 1.40 2002/12/21 00:55:58 steve
* The $time system task returns the integer time
* scaled to the local units. Change the internal
* implementation of vpiSystemTime the $time functions
* to properly account for this. Also add $simtime
* to get the simulation time.
*
* Revision 1.39 2002/11/17 22:28:42 steve
* Close old file if $dumpfile is called again.
*

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: compile.cc,v 1.146 2002/11/21 22:43:13 steve Exp $"
#ident "$Id: compile.cc,v 1.147 2002/12/21 00:55:58 steve Exp $"
#endif
# include "arith.h"
@ -418,6 +418,18 @@ bool vpi_handle_resolv_list_s::resolve(bool mes)
void compile_vpi_lookup(vpiHandle *handle, char*label)
{
if (strcmp(label, "$time") == 0) {
*handle = vpip_sim_time(vpip_peek_current_scope());
free(label);
return;
}
if (strcmp(label, "$stime") == 0) {
*handle = vpip_sim_time(vpip_peek_current_scope());
free(label);
return;
}
struct vpi_handle_resolv_list_s*res
= new struct vpi_handle_resolv_list_s;
@ -576,8 +588,6 @@ void compile_vpi_symbol(const char*label, vpiHandle obj)
void compile_init(void)
{
sym_vpi = new_symbol_table();
compile_vpi_symbol("$time", vpip_sim_time());
compile_vpi_symbol("$stime", vpip_sim_time());
sym_functors = new_symbol_table();
functor_init();
@ -1483,6 +1493,13 @@ void compile_net(char*label, char*name, int msb, int lsb, bool signed_flag,
/*
* $Log: compile.cc,v $
* Revision 1.147 2002/12/21 00:55:58 steve
* The $time system task returns the integer time
* scaled to the local units. Change the internal
* implementation of vpiSystemTime the $time functions
* to properly account for this. Also add $simtime
* to get the simulation time.
*
* Revision 1.146 2002/11/21 22:43:13 steve
* %set/x0 instruction to support bounds checking.
*

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: compile.h,v 1.45 2002/08/12 01:35:07 steve Exp $"
#ident "$Id: compile.h,v 1.46 2002/12/21 00:55:58 steve Exp $"
#endif
# include <stdio.h>
@ -116,6 +116,7 @@ extern void compile_shiftl(char*label, long width,
extern void compile_shiftr(char*label, long width,
unsigned argc, struct symb_s*argv);
extern void compile_timescale(long units);
extern void compile_vpi_symbol(const char*label, vpiHandle obj);
extern void compile_vpi_lookup(vpiHandle *objref, char*label);
@ -251,6 +252,13 @@ extern void compile_net(char*label, char*name,
/*
* $Log: compile.h,v $
* Revision 1.46 2002/12/21 00:55:58 steve
* The $time system task returns the integer time
* scaled to the local units. Change the internal
* implementation of vpiSystemTime the $time functions
* to properly account for this. Also add $simtime
* to get the simulation time.
*
* Revision 1.45 2002/08/12 01:35:07 steve
* conditional ident string using autoconfig.
*

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: lexor.lex,v 1.34 2002/06/21 04:58:55 steve Exp $"
#ident "$Id: lexor.lex,v 1.35 2002/12/21 00:55:58 steve Exp $"
#endif
# include "parse_misc.h"
@ -100,6 +100,7 @@
".shift/l" { return K_SHIFTL; }
".shift/r" { return K_SHIFTR; }
".thread" { return K_THREAD; }
".timescale" { return K_TIMESCALE; }
".ufunc" { return K_UFUNC; }
".var" { return K_VAR; }
".var/s" { return K_VAR_S; }
@ -173,6 +174,13 @@ int yywrap()
/*
* $Log: lexor.lex,v $
* Revision 1.35 2002/12/21 00:55:58 steve
* The $time system task returns the integer time
* scaled to the local units. Change the internal
* implementation of vpiSystemTime the $time functions
* to properly account for this. Also add $simtime
* to get the simulation time.
*
* Revision 1.34 2002/06/21 04:58:55 steve
* Add support for special integer vectors.
*

View File

@ -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.47 2002/06/21 04:58:55 steve Exp $"
#ident "$Id: parse.y,v 1.48 2002/12/21 00:55:58 steve Exp $"
#endif
# include "parse_misc.h"
@ -60,7 +60,7 @@ extern FILE*yyin;
%token K_ARITH_DIV K_ARITH_MOD K_ARITH_MULT K_ARITH_SUB K_ARITH_SUM
%token K_CMP_GE K_CMP_GT
%token K_EVENT K_EVENT_OR K_FUNCTOR K_NET K_NET_S
%token K_RESOLV K_SCOPE K_SHIFTL K_SHIFTR K_THREAD K_UFUNC
%token K_RESOLV K_SCOPE K_SHIFTL K_SHIFTR K_THREAD K_TIMESCALE K_UFUNC
%token K_UDP K_UDP_C K_UDP_S
%token K_MEM K_MEM_P K_MEM_I
%token K_FORCE
@ -295,6 +295,12 @@ statement
| K_SCOPE T_SYMBOL ';'
{ compile_scope_recall($2); }
| K_TIMESCALE T_NUMBER ';'
{ compile_timescale($2); }
| K_TIMESCALE '-' T_NUMBER ';'
{ compile_timescale(-$3); }
/* Thread statements declare a thread with its starting address. The
starting address must already be defined. */
@ -553,6 +559,13 @@ int compile_design(const char*path)
/*
* $Log: parse.y,v $
* Revision 1.48 2002/12/21 00:55:58 steve
* The $time system task returns the integer time
* scaled to the local units. Change the internal
* implementation of vpiSystemTime the $time functions
* to properly account for this. Also add $simtime
* to get the simulation time.
*
* Revision 1.47 2002/06/21 04:58:55 steve
* Add support for special integer vectors.
*

View File

@ -1,7 +1,7 @@
/*
* Copyright (c) 2001 Stephen Williams (steve@icarus.com)
*
* $Id: vpi.txt,v 1.5 2001/03/20 06:16:24 steve Exp $
* $Id: vpi.txt,v 1.6 2002/12/21 00:55:58 steve Exp $
*/
@ -103,6 +103,7 @@ placed.
A scope is created with a .scope directive, like so:
<label> .scope "name" [, <parent>];
.timescale <units>;
The scope takes a string name as the first parameter. If there is an
additional parameter, it is a label of the directive for the parent
@ -114,6 +115,10 @@ scope. The vvp automatically constructs full names from the scope
hierarchy, and runtime VPI code can access that full name with the
vpiFullname reference.
The .timescale directive changes the scope units from the simulation
precision to the specified precision. The .timescale directive affects
the current scope.
Objects that place themselves in a scope place themselves in the
current scope. The current scope is the one that was last mentioned by
a .scope directive. If the wrong scope is current, the label on a

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: vpi_priv.cc,v 1.25 2002/12/11 23:55:22 steve Exp $"
#ident "$Id: vpi_priv.cc,v 1.26 2002/12/21 00:55:58 steve Exp $"
#endif
# include "vpi_priv.h"
@ -150,8 +150,8 @@ void vpi_get_time(vpiHandle obj, s_vpi_time*vp)
{
assert(vp);
// XXXX Cheat. Ignore timescale for the scope.
vp->type = vpiSimTime;
// Only vpiSimTime is supported, for now.
assert(vp->type == vpiSimTime);
vp->high = 0;
vp->low = schedule_simtime();
}
@ -369,6 +369,13 @@ extern "C" void vpi_sim_vcontrol(int operation, va_list ap)
/*
* $Log: vpi_priv.cc,v $
* Revision 1.26 2002/12/21 00:55:58 steve
* The $time system task returns the integer time
* scaled to the local units. Change the internal
* implementation of vpiSystemTime the $time functions
* to properly account for this. Also add $simtime
* to get the simulation time.
*
* Revision 1.25 2002/12/11 23:55:22 steve
* Add vpi_handle_by_name to the VPI interface,
* and bump the vpithunk magic number.

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: vpi_priv.h,v 1.40 2002/08/12 01:35:09 steve Exp $"
#ident "$Id: vpi_priv.h,v 1.41 2002/12/21 00:55:58 steve Exp $"
#endif
# include "vpi_user.h"
@ -128,19 +128,29 @@ struct __vpiCallback {
extern struct __vpiCallback* new_vpi_callback();
extern void callback_execute(struct __vpiCallback*cur);
struct __vpiSystemTime {
struct __vpiHandle base;
struct __vpiScope *scope;
};
/*
* Scopes are created by .scope statements in the source.
* Scopes are created by .scope statements in the source. These
* objects hold the items and properties that are knowably bound to a
* scope.
*/
struct __vpiScope {
struct __vpiHandle base;
struct __vpiScope *scope;
/* The scope has a name. */
const char*name;
/* Keep an array of internal scope items. */
/* The scope has a system time of its own. */
struct __vpiSystemTime scoped_time;
/* Keep an array of internal scope items. */
struct __vpiHandle**intern;
unsigned nintern;
/* Keep a list of threads in the scope. */
vthread_t threads;
signed int time_units :8;
};
extern struct __vpiScope* vpip_peek_current_scope(void);
@ -317,7 +327,7 @@ extern void vpip_execute_vpi_call(vthread_t thr, vpiHandle obj);
* and to finish compilation in preparation for execution.
*/
vpiHandle vpip_sim_time(void);
vpiHandle vpip_sim_time(struct __vpiScope*scope);
extern int vpip_get_time_precision(void);
extern void vpip_set_time_precision(int pres);
@ -374,6 +384,13 @@ extern char *need_result_buf(unsigned cnt, vpi_rbuf_t type);
/*
* $Log: vpi_priv.h,v $
* Revision 1.41 2002/12/21 00:55:58 steve
* The $time system task returns the integer time
* scaled to the local units. Change the internal
* implementation of vpiSystemTime the $time functions
* to properly account for this. Also add $simtime
* to get the simulation time.
*
* Revision 1.40 2002/08/12 01:35:09 steve
* conditional ident string using autoconfig.
*

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: vpi_scope.cc,v 1.21 2002/11/15 22:14:12 steve Exp $"
#ident "$Id: vpi_scope.cc,v 1.22 2002/12/21 00:55:58 steve Exp $"
#endif
# include "compile.h"
@ -43,17 +43,36 @@ vpiHandle vpip_make_root_iterator(void)
vpip_root_table_ptr, false);
}
static bool handle_is_scope(vpiHandle obj)
{
return (obj->vpi_type->type_code == vpiModule)
|| (obj->vpi_type->type_code == vpiFunction)
|| (obj->vpi_type->type_code == vpiTask)
|| (obj->vpi_type->type_code == vpiNamedBegin)
|| (obj->vpi_type->type_code == vpiNamedFork);
}
static int scope_get(int code, vpiHandle obj)
{
struct __vpiScope*ref = (struct __vpiScope*)obj;
assert(handle_is_scope(obj));
switch (code) {
case vpiTimeUnit:
return ref->time_units;
}
return 0;
}
static char* scope_get_str(int code, vpiHandle obj)
{
struct __vpiScope*ref = (struct __vpiScope*)obj;
const char *n, *nn, *name = ref->name;
char *rbuf = need_result_buf(strlen(name) + 1, RBUF_STR);
assert((obj->vpi_type->type_code == vpiModule)
|| (obj->vpi_type->type_code == vpiFunction)
|| (obj->vpi_type->type_code == vpiTask)
|| (obj->vpi_type->type_code == vpiNamedBegin)
|| (obj->vpi_type->type_code == vpiNamedFork));
assert(handle_is_scope(obj));
switch (code) {
case vpiFullName:
@ -254,7 +273,7 @@ vpiHandle ipoint_get_scope(vvp_ipoint_t ipt)
static const struct __vpirt vpip_scope_module_rt = {
vpiModule,
0,
scope_get,
scope_get_str,
0,
0,
@ -302,6 +321,11 @@ static const struct __vpirt vpip_scope_fork_rt = {
module_iter
};
/*
* The current_scope is a compile time concept. As the vvp source is
* compiled, items that have scope are placed in the current
* scope. The ".scope" directives select the scope that is current.
*/
static struct __vpiScope*current_scope = 0;
static void attach_to_scope_(struct __vpiScope*scope, vpiHandle obj)
@ -373,6 +397,10 @@ void compile_scope_decl(char*label, char*type, char*name, char*parent)
struct __vpiScope*sp = (struct __vpiScope*) obj;
attach_to_scope_(sp, &scope->base);
scope->scope = (struct __vpiScope*)obj;
/* Inherit time units from the parent scope. */
scope->time_units = sp->time_units;
} else {
scope->scope = 0x0;
@ -381,6 +409,9 @@ void compile_scope_decl(char*label, char*type, char*name, char*parent)
realloc(vpip_root_table_ptr, cnt * sizeof(vpiHandle));
vpip_root_table_ptr[vpip_root_table_cnt] = &scope->base;
vpip_root_table_cnt = cnt;
/* Root scopes inherit time_units from system precision. */
scope->time_units = vpip_get_time_precision();
}
functor_set_scope(&current_scope->base);
@ -393,6 +424,16 @@ void compile_scope_recall(char*symbol)
functor_set_scope(&current_scope->base);
}
/*
* This function handles the ".timescale" directive in the vvp
* source. It sets in the current scope the specified units value.
*/
void compile_timescale(long units)
{
assert(current_scope);
current_scope->time_units = units;
}
struct __vpiScope* vpip_peek_current_scope(void)
{
return current_scope;
@ -406,6 +447,13 @@ void vpip_attach_to_current_scope(vpiHandle obj)
/*
* $Log: vpi_scope.cc,v $
* Revision 1.22 2002/12/21 00:55:58 steve
* The $time system task returns the integer time
* scaled to the local units. Change the internal
* implementation of vpiSystemTime the $time functions
* to properly account for this. Also add $simtime
* to get the simulation time.
*
* Revision 1.21 2002/11/15 22:14:12 steve
* Add vpiScope iterate on vpiScope objects.
*

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: vpi_tasks.cc,v 1.16 2002/08/12 01:35:09 steve Exp $"
#ident "$Id: vpi_tasks.cc,v 1.17 2002/12/21 00:55:58 steve Exp $"
#endif
/*
@ -176,7 +176,7 @@ static const struct __vpirt vpip_sysfunc_rt = {
0,
0,
sysfunc_put_value,
0,
systask_handle,
systask_iter
};
@ -344,6 +344,13 @@ void vpi_register_systf(const struct t_vpi_systf_data*ss)
/*
* $Log: vpi_tasks.cc,v $
* Revision 1.17 2002/12/21 00:55:58 steve
* The $time system task returns the integer time
* scaled to the local units. Change the internal
* implementation of vpiSystemTime the $time functions
* to properly account for this. Also add $simtime
* to get the simulation time.
*
* Revision 1.16 2002/08/12 01:35:09 steve
* conditional ident string using autoconfig.
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001 Stephen Williams (steve@icarus.com)
* Copyright (c) 2001-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
@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: vpi_time.cc,v 1.8 2002/08/12 01:35:09 steve Exp $"
#ident "$Id: vpi_time.cc,v 1.9 2002/12/21 00:55:58 steve Exp $"
#endif
# include "vpi_priv.h"
@ -25,7 +25,17 @@
# include <stdio.h>
# include <assert.h>
/*
* The $time system function is supported in VPI contexts (i.e. an
* argument to a system task/function) as a magical time variable. The
* VPI sees it as a vpiTimeVar object, but reads from it get the
* current value instead of some assigned value.
*/
/*
* vpi_time_precision is the precision of the simulation clock. It is
* set by the :vpi_time_precision directive in the vvp source file.
*/
static int vpi_time_precision = 0;
void vpip_time_to_timestruct(struct t_vpi_time*ts, vvp_time64_t ti)
@ -42,10 +52,6 @@ vvp_time64_t vpip_timestruct_to_time(const struct t_vpi_time*ts)
return ti;
}
static struct __vpiSystemTime {
struct __vpiHandle base;
struct t_vpi_time value;
} time_handle;
static int timevar_get(int code, vpiHandle ref)
{
@ -66,20 +72,31 @@ static int timevar_get(int code, vpiHandle ref)
static void timevar_get_value(vpiHandle ref, s_vpi_value*vp)
{
static char buf_obj[128];
assert(ref == &time_handle.base);
/* Keep a persistent structure for passing time values back to
the caller. */
static struct t_vpi_time time_value;
struct __vpiSystemTime*rfp = reinterpret_cast<struct __vpiSystemTime*>(ref);
unsigned long x, num_bits;
vvp_time64_t simtime = schedule_simtime();
int units = rfp->scope->time_units;
while (units > vpi_time_precision) {
simtime /= 10;
units -= 1;
}
switch (vp->format) {
case vpiObjTypeVal:
case vpiTimeVal:
vp->value.time = &time_handle.value;
vp->value.time = &time_value;
vp->value.time->type = vpiSimTime;
vpip_time_to_timestruct(vp->value.time, schedule_simtime());
vpip_time_to_timestruct(vp->value.time, simtime);
vp->format = vpiTimeVal;
break;
case vpiBinStrVal:
x = schedule_simtime();
x = simtime;
num_bits = 8 * sizeof(unsigned long);
buf_obj[num_bits] = 0;
@ -92,17 +109,17 @@ static void timevar_get_value(vpiHandle ref, s_vpi_value*vp)
break;
case vpiDecStrVal:
sprintf(buf_obj, "%lu", schedule_simtime());
sprintf(buf_obj, "%lu", simtime);
vp->value.str = buf_obj;
break;
case vpiOctStrVal:
sprintf(buf_obj, "%lo", schedule_simtime());
sprintf(buf_obj, "%lo", simtime);
vp->value.str = buf_obj;
break;
case vpiHexStrVal:
sprintf(buf_obj, "%lx", schedule_simtime());
sprintf(buf_obj, "%lx", simtime);
vp->value.str = buf_obj;
break;
@ -123,10 +140,11 @@ static const struct __vpirt vpip_system_time_rt = {
};
vpiHandle vpip_sim_time(void)
vpiHandle vpip_sim_time(struct __vpiScope*scope)
{
time_handle.base.vpi_type = &vpip_system_time_rt;
return &time_handle.base;
scope->scoped_time.base.vpi_type = &vpip_system_time_rt;
scope->scoped_time.scope = scope;
return &scope->scoped_time.base;
}
int vpip_get_time_precision(void)
@ -142,6 +160,13 @@ void vpip_set_time_precision(int pre)
/*
* $Log: vpi_time.cc,v $
* Revision 1.9 2002/12/21 00:55:58 steve
* The $time system task returns the integer time
* scaled to the local units. Change the internal
* implementation of vpiSystemTime the $time functions
* to properly account for this. Also add $simtime
* to get the simulation time.
*
* Revision 1.8 2002/08/12 01:35:09 steve
* conditional ident string using autoconfig.
*