From 3258b7726b5390049c33f46b1f68bd691dc9373f Mon Sep 17 00:00:00 2001 From: Cary R Date: Fri, 28 Sep 2007 11:21:08 -0700 Subject: [PATCH] Pass local scope precision from compiler to vvp/etc. This patch adds ivl_scope_time_precision() to the compiler which can be used to extract the local scope precision. tgt-stub and tgt-vvp have been modified to use this new function and output a value that is appropriate. The vvp runtime has been altered to use this new data which is accessed with the vpip_time_precision_from_handle() function. vpiTimePrecision uses this function to return the correct precision. --- ivl.def | 1 + ivl_target.h | 6 ++ t-dll-api.cc | 234 ++------------------------------------------ t-dll.cc | 2 + t-dll.h | 158 +----------------------------- tgt-stub/stub.c | 1 + tgt-vvp/vvp_scope.c | 3 +- vpi/sys_display.c | 2 +- vvp/compile.h | 2 +- vvp/parse.y | 164 ++----------------------------- vvp/vpi_priv.cc | 38 ++++++- vvp/vpi_priv.h | 95 +----------------- vvp/vpi_scope.cc | 12 ++- 13 files changed, 75 insertions(+), 643 deletions(-) diff --git a/ivl.def b/ivl.def index d46fef22c..65a0e7cbf 100644 --- a/ivl.def +++ b/ivl.def @@ -134,6 +134,7 @@ ivl_scope_port ivl_scope_ports ivl_scope_sigs ivl_scope_sig +ivl_scope_time_precision ivl_scope_time_units ivl_scope_type ivl_scope_tname diff --git a/ivl_target.h b/ivl_target.h index 1b15a54f8..7b06582ae 100644 --- a/ivl_target.h +++ b/ivl_target.h @@ -1408,6 +1408,11 @@ extern ivl_expr_t ivl_parameter_expr(ivl_parameter_t net); * anything that can become and ivl_signal_t, include synthetic * signals generated by the compiler. * + * ivl_scope_time_precision + * Scopes have their own intrinsic time precision, typically from + * the timescale compiler directive. This method returns the + * precision as a signed power of 10 value. + * * ivl_scope_time_units * Scopes have their own intrinsic time units, typically from the * timescale compiler directive. This method returns the units as a @@ -1446,6 +1451,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_precision(ivl_scope_t net); extern int ivl_scope_time_units(ivl_scope_t net); diff --git a/t-dll-api.cc b/t-dll-api.cc index c6aa73034..0d74ef637 100644 --- a/t-dll-api.cc +++ b/t-dll-api.cc @@ -1474,6 +1474,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_precision(ivl_scope_t net) +{ + assert(net); + return net->time_precision; +} + extern "C" int ivl_scope_time_units(ivl_scope_t net) { assert(net); @@ -1963,231 +1969,3 @@ extern "C" ivl_statement_t ivl_stmt_sub_stmt(ivl_statement_t net) return 0; } -/* - * $Log: t-dll-api.cc,v $ - * Revision 1.144 2007/04/02 01:12:34 steve - * Seperate arrayness from word count - * - * Revision 1.143 2007/03/26 16:51:48 steve - * do not calculate nexus name unless needed. - * - * Revision 1.142 2007/03/02 06:13:22 steve - * Add support for edge sensitive spec paths. - * - * Revision 1.141 2007/03/01 06:19:39 steve - * Add support for conditional specify delay paths. - * - * Revision 1.140 2007/01/17 05:00:12 steve - * Dead code for memories in scopes. - * - * Revision 1.139 2007/01/17 04:39:18 steve - * Remove dead code related to memories. - * - * Revision 1.138 2007/01/16 05:44:15 steve - * Major rework of array handling. Memories are replaced with the - * more general concept of arrays. The NetMemory and NetEMemory - * classes are removed from the ivl core program, and the IVL_LPM_RAM - * lpm type is removed from the ivl_target API. - * - * Revision 1.137 2006/09/23 04:57:19 steve - * Basic support for specify timing. - * - * Revision 1.136 2006/09/20 22:31:23 steve - * Remove dead code. - * - * Revision 1.135 2006/08/08 05:11:37 steve - * Handle 64bit delay constants. - * - * Revision 1.134 2006/06/18 04:15:50 steve - * Add support for system functions in continuous assignments. - * - * Revision 1.133 2006/02/02 02:43:59 steve - * Allow part selects of memory words in l-values. - * - * Revision 1.132 2006/01/02 05:33:19 steve - * Node delays can be more general expressions in structural contexts. - * - * Revision 1.131 2005/08/06 17:58:16 steve - * Implement bi-directional part selects. - * - * Revision 1.130 2005/07/11 16:56:51 steve - * Remove NetVariable and ivl_variable_t structures. - * - * Revision 1.129 2005/07/07 16:22:49 steve - * Generalize signals to carry types. - * - * Revision 1.128 2005/06/13 23:22:37 steve - * Fix compile errors. - * - * Revision 1.127 2005/05/24 01:44:28 steve - * Do sign extension of structuran nets. - * - * Revision 1.126 2005/05/08 23:44:08 steve - * Add support for variable part select. - * - * Revision 1.125 2005/04/24 23:44:02 steve - * Update DFF support to new data flow. - * - * Revision 1.124 2005/04/13 06:35:11 steve - * Make logic aware of strength. - * - * Revision 1.123 2005/04/06 05:29:08 steve - * Rework NetRamDq and IVL_LPM_RAM nodes. - * - * Revision 1.122 2005/04/01 06:04:30 steve - * Clean up handle of UDPs. - * - * Revision 1.121 2005/03/18 02:56:04 steve - * Add support for LPM_UFUNC user defined functions. - * - * Revision 1.120 2005/03/09 05:52:04 steve - * Handle case inequality in netlists. - * - * Revision 1.119 2005/02/19 02:43:38 steve - * Support shifts and divide. - * - * Revision 1.118 2005/02/12 06:25:40 steve - * Restructure NetMux devices to pass vectors. - * Generate NetMux devices from ternary expressions, - * Reduce NetMux devices to bufif when appropriate. - * - * Revision 1.117 2005/02/08 00:12:36 steve - * Add the NetRepeat node, and code generator support. - * - * Revision 1.116 2005/02/03 04:56:20 steve - * laborate reduction gates into LPM_RED_ nodes. - * - * Revision 1.115 2005/01/24 05:28:31 steve - * Remove the NetEBitSel and combine all bit/part select - * behavior into the NetESelect node and IVL_EX_SELECT - * ivl_target expression type. - * - * Revision 1.114 2005/01/22 01:06:55 steve - * Change case compare from logic to an LPM node. - * - * Revision 1.113 2005/01/09 20:16:01 steve - * Use PartSelect/PV and VP to handle part selects through ports. - * - * Revision 1.112 2004/12/29 23:55:43 steve - * Unify elaboration of l-values for all proceedural assignments, - * including assing, cassign and force. - * - * Generate NetConcat devices for gate outputs that feed into a - * vector results. Use this to hande gate arrays. Also let gate - * arrays handle vectors of gates when the outputs allow for it. - * - * Revision 1.111 2004/12/18 18:56:18 steve - * Add ivl_event_scope, and better document ivl_event_X methods. - * - * Revision 1.110 2004/12/15 17:10:40 steve - * Fixup force statement elaboration. - * - * Revision 1.109 2004/12/11 02:31:27 steve - * Rework of internals to carry vectors through nexus instead - * of single bits. Make the ivl, tgt-vvp and vvp initial changes - * down this path. - * - * Revision 1.108 2004/10/04 01:10:55 steve - * Clean up spurious trailing white space. - * - * Revision 1.107 2004/06/30 02:16:27 steve - * Implement signed divide and signed right shift in nets. - * - * Revision 1.106 2003/12/03 02:46:24 steve - * Add support for wait on list of named events. - * - * Revision 1.105 2003/11/10 20:59:03 steve - * Design::get_flag returns const char* instead of string. - * - * Revision 1.104 2003/09/03 23:33:30 steve - * Pass FF synchronous set values to code generator. - * - * Revision 1.103 2003/08/22 23:14:26 steve - * Preserve variable ranges all the way to the vpi. - * - * Revision 1.102 2003/08/15 02:23:53 steve - * Add synthesis support for synchronous reset. - * - * Revision 1.101 2003/06/24 01:38:03 steve - * Various warnings fixed. - * - * Revision 1.100 2003/06/23 01:25:44 steve - * Module attributes make it al the way to ivl_target. - * - * Revision 1.99 2003/05/14 05:26:41 steve - * Support real expressions in case statements. - * - * Revision 1.98 2003/04/22 04:48:30 steve - * Support event names as expressions elements. - * - * Revision 1.97 2003/04/11 05:18:08 steve - * Handle signed magnitude compare all the - * way through to the vvp code generator. - * - * Revision 1.96 2003/03/10 23:40:53 steve - * Keep parameter constants for the ivl_target API. - * - * Revision 1.95 2003/03/06 04:32:40 steve - * Wrong sense of need compared to have. - * - * Revision 1.94 2003/03/06 01:24:37 steve - * Obsolete the ivl_event_name function. - * - * Revision 1.93 2003/03/06 00:28:42 steve - * All NetObj objects have lex_string base names. - * - * Revision 1.92 2003/03/03 02:22:41 steve - * Scope names stored only as basename. - * - * Revision 1.91 2003/02/26 01:29:24 steve - * LPM objects store only their base names. - * - * Revision 1.90 2003/01/26 21:15:59 steve - * Rework expression parsing and elaboration to - * accommodate real/realtime values and expressions. - * - * 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. - * - * Revision 1.87 2002/09/26 03:18:04 steve - * Generate vvp code for asynch set/reset of NetFF. - * - * Revision 1.86 2002/08/12 01:35:00 steve - * conditional ident string using autoconfig. - * - * Revision 1.85 2002/08/07 02:17:14 steve - * Dead code. - * - * Revision 1.84 2002/08/05 04:18:45 steve - * Store only the base name of memories. - * - * Revision 1.83 2002/07/05 21:26:17 steve - * Avoid emitting to vvp local net symbols. - * - * Revision 1.82 2002/06/21 04:59:35 steve - * Carry integerness throughout the compilation. - * - * Revision 1.81 2002/05/27 00:08:45 steve - * Support carrying the scope of named begin-end - * blocks down to the code generator, and have - * the vvp code generator use that to support disable. - * - * Revision 1.80 2002/05/26 01:39:03 steve - * Carry Verilog 2001 attributes with processes, - * all the way through to the ivl_target API. - * - * Divide signal reference counts between rval - * and lval references. - * - * Revision 1.79 2002/05/24 04:36:23 steve - * Verilog 2001 attriubtes on nets/wires. - */ - diff --git a/t-dll.cc b/t-dll.cc index bd5fc87a6..b8d068669 100644 --- a/t-dll.cc +++ b/t-dll.cc @@ -542,6 +542,7 @@ void dll_target::add_root(ivl_design_s &des_, const NetScope *s) make_scope_parameters(root_, s); root_->type_ = IVL_SCT_MODULE; root_->tname_ = root_->name_; + root_->time_precision = s->time_precision(); root_->time_units = s->time_unit(); root_->nattr = s->attr_cnt(); root_->attr = fill_in_attributes(s); @@ -2001,6 +2002,7 @@ void dll_target::scope(const NetScope*net) scope->lpm_ = 0; scope->def = 0; make_scope_parameters(scope, net); + scope->time_precision = net->time_precision(); scope->time_units = net->time_unit(); scope->nattr = net->attr_cnt(); scope->attr = fill_in_attributes(net); diff --git a/t-dll.h b/t-dll.h index 7f1e4c86e..b1e0a1949 100644 --- a/t-dll.h +++ b/t-dll.h @@ -551,6 +551,7 @@ struct ivl_scope_s { unsigned ports; ivl_signal_t*port; + signed int time_precision :8; signed int time_units :8; struct ivl_attribute_s*attr; @@ -678,161 +679,4 @@ struct ivl_statement_s { } u_; }; -/* - * $Log: t-dll.h,v $ - * Revision 1.143 2007/06/02 03:42:13 steve - * Properly evaluate scope path expressions. - * - * Revision 1.142 2007/04/02 01:12:34 steve - * Seperate arrayness from word count - * - * Revision 1.141 2007/03/26 20:32:47 steve - * More efficient allocate of ivl_nexus_t objects. - * - * Revision 1.140 2007/03/26 16:51:49 steve - * do not calculate nexus name unless needed. - * - * Revision 1.139 2007/03/02 06:13:22 steve - * Add support for edge sensitive spec paths. - * - * Revision 1.138 2007/03/01 06:19:39 steve - * Add support for conditional specify delay paths. - * - * Revision 1.137 2007/01/17 05:00:12 steve - * Dead code for memories in scopes. - * - * Revision 1.136 2007/01/17 04:39:18 steve - * Remove dead code related to memories. - * - * Revision 1.135 2007/01/16 05:44:16 steve - * Major rework of array handling. Memories are replaced with the - * more general concept of arrays. The NetMemory and NetEMemory - * classes are removed from the ivl core program, and the IVL_LPM_RAM - * lpm type is removed from the ivl_target API. - * - * Revision 1.134 2006/11/10 05:44:45 steve - * Process delay paths in second path over signals. - * - * Revision 1.133 2006/09/23 04:57:19 steve - * Basic support for specify timing. - * - * Revision 1.132 2006/08/08 05:11:37 steve - * Handle 64bit delay constants. - * - * Revision 1.131 2006/06/18 04:15:50 steve - * Add support for system functions in continuous assignments. - * - * Revision 1.130 2006/02/02 02:43:59 steve - * Allow part selects of memory words in l-values. - * - * Revision 1.129 2006/01/02 05:33:19 steve - * Node delays can be more general expressions in structural contexts. - * - * Revision 1.128 2005/07/11 16:56:51 steve - * Remove NetVariable and ivl_variable_t structures. - * - * Revision 1.127 2005/07/07 16:22:49 steve - * Generalize signals to carry types. - * - * Revision 1.126 2005/05/24 01:44:28 steve - * Do sign extension of structuran nets. - * - * Revision 1.125 2005/05/08 23:44:08 steve - * Add support for variable part select. - * - * Revision 1.124 2005/04/01 06:04:30 steve - * Clean up handle of UDPs. - * - * Revision 1.123 2005/03/18 02:56:04 steve - * Add support for LPM_UFUNC user defined functions. - * - * Revision 1.122 2005/02/19 02:43:39 steve - * Support shifts and divide. - * - * Revision 1.121 2005/02/12 06:25:40 steve - * Restructure NetMux devices to pass vectors. - * Generate NetMux devices from ternary expressions, - * Reduce NetMux devices to bufif when appropriate. - * - * Revision 1.120 2005/02/08 00:12:36 steve - * Add the NetRepeat node, and code generator support. - * - * Revision 1.119 2005/02/03 04:56:20 steve - * laborate reduction gates into LPM_RED_ nodes. - * - * Revision 1.118 2005/01/24 05:28:31 steve - * Remove the NetEBitSel and combine all bit/part select - * behavior into the NetESelect node and IVL_EX_SELECT - * ivl_target expression type. - * - * Revision 1.117 2004/12/29 23:55:43 steve - * Unify elaboration of l-values for all proceedural assignments, - * including assing, cassign and force. - * - * Generate NetConcat devices for gate outputs that feed into a - * vector results. Use this to hande gate arrays. Also let gate - * arrays handle vectors of gates when the outputs allow for it. - * - * Revision 1.116 2004/12/11 02:31:28 steve - * Rework of internals to carry vectors through nexus instead - * of single bits. Make the ivl, tgt-vvp and vvp initial changes - * down this path. - * - * Revision 1.115 2004/10/04 01:10:56 steve - * Clean up spurious trailing white space. - * - * Revision 1.114 2004/06/30 02:16:27 steve - * Implement signed divide and signed right shift in nets. - * - * Revision 1.113 2004/05/31 23:34:39 steve - * Rewire/generalize parsing an elaboration of - * function return values to allow for better - * speed and more type support. - * - * Revision 1.112 2004/02/20 06:22:58 steve - * parameter keys are per_strings. - * - * Revision 1.111 2004/02/19 07:06:57 steve - * LPM, logic and Variables have perm_string names. - * - * Revision 1.110 2004/02/19 06:57:11 steve - * Memory and Event names use perm_string. - * - * Revision 1.109 2004/02/18 17:11:58 steve - * Use perm_strings for named langiage items. - * - * Revision 1.108 2003/12/03 02:46:24 steve - * Add support for wait on list of named events. - * - * Revision 1.107 2003/11/10 20:59:04 steve - * Design::get_flag returns const char* instead of string. - * - * Revision 1.106 2003/09/03 23:33:29 steve - * Pass FF synchronous set values to code generator. - * - * Revision 1.105 2003/08/15 02:23:53 steve - * Add synthesis support for synchronous reset. - * - * Revision 1.104 2003/06/23 01:25:44 steve - * Module attributes make it al the way to ivl_target. - * - * Revision 1.103 2003/06/17 21:28:59 steve - * Remove short int restrictions from vvp opcodes. (part 2) - * - * Revision 1.102 2003/04/22 04:48:30 steve - * Support event names as expressions elements. - * - * Revision 1.101 2003/04/11 05:18:08 steve - * Handle signed magnitude compare all the - * way through to the vvp code generator. - * - * Revision 1.100 2003/03/10 23:40:54 steve - * Keep parameter constants for the ivl_target API. - * - * Revision 1.99 2003/03/01 06:25:30 steve - * Add the lex_strings string handler, and put - * scope names and system task/function names - * into this table. Also, permallocate event - * names from the beginning. - */ #endif diff --git a/tgt-stub/stub.c b/tgt-stub/stub.c index 30dace3d7..468b7dd05 100644 --- a/tgt-stub/stub.c +++ b/tgt-stub/stub.c @@ -1387,6 +1387,7 @@ static int show_scope(ivl_scope_t net, void*x) } fprintf(out, " time units = 1e%d\n", ivl_scope_time_units(net)); + fprintf(out, " time precision = 1e%d\n", ivl_scope_time_precision(net)); for (idx = 0 ; idx < ivl_scope_attr_cnt(net) ; idx += 1) { ivl_attribute_t attr = ivl_scope_attr_val(net, idx); diff --git a/tgt-vvp/vvp_scope.c b/tgt-vvp/vvp_scope.c index 32fbb5367..79036b54b 100644 --- a/tgt-vvp/vvp_scope.c +++ b/tgt-vvp/vvp_scope.c @@ -2363,7 +2363,8 @@ int draw_scope(ivl_scope_t net, ivl_scope_t parent) fprintf(vvp_out, ";\n"); } - fprintf(vvp_out, " .timescale %d;\n", ivl_scope_time_units(net)); + fprintf(vvp_out, " .timescale %d %d;\n", ivl_scope_time_units(net), + ivl_scope_time_precision(net)); for (idx = 0 ; idx < ivl_scope_params(net) ; idx += 1) { ivl_parameter_t par = ivl_scope_param(net, idx); diff --git a/vpi/sys_display.c b/vpi/sys_display.c index 0f6b57bdf..adffe9862 100644 --- a/vpi/sys_display.c +++ b/vpi/sys_display.c @@ -2133,7 +2133,7 @@ static char *pts_convert(int value) { char *string; switch (value) { - case 0: string = "s"; break; + case 0: string = "1s"; break; case -1: string = "100ms"; break; case -2: string = "10ms"; break; case -3: string = "1ms"; break; diff --git a/vvp/compile.h b/vvp/compile.h index 88dbbe992..b66d779dd 100644 --- a/vvp/compile.h +++ b/vvp/compile.h @@ -205,7 +205,7 @@ extern void compile_shiftl(char*label, long width, extern void compile_shiftr(char*label, long width, bool signed_flag, unsigned argc, struct symb_s*argv); -extern void compile_timescale(long units); +extern void compile_timescale(long units, long precision); extern void compile_vpi_symbol(const char*label, vpiHandle obj); extern void compile_vpi_lookup(vpiHandle *objref, char*label); diff --git a/vvp/parse.y b/vvp/parse.y index 5d31b1e1c..618f73f63 100644 --- a/vvp/parse.y +++ b/vvp/parse.y @@ -482,10 +482,14 @@ statement { compile_scope_recall($2); } - | K_TIMESCALE T_NUMBER ';' - { compile_timescale($2); } - | K_TIMESCALE '-' T_NUMBER ';' - { compile_timescale(-$3); } + | K_TIMESCALE T_NUMBER T_NUMBER';' + { compile_timescale($2, $3); } + | K_TIMESCALE '-' T_NUMBER T_NUMBER';' + { compile_timescale(-$3, $4); } + | K_TIMESCALE T_NUMBER '-' T_NUMBER';' + { compile_timescale($2, -$4); } + | K_TIMESCALE '-' T_NUMBER '-' T_NUMBER';' + { compile_timescale(-$3, -$5); } /* Thread statements declare a thread with its starting address. The starting address must already be defined. The .thread statement @@ -837,155 +841,3 @@ int compile_design(const char*path) return rc; } - -/* - * $Log: parse.y,v $ - * Revision 1.93 2007/04/19 01:19:06 steve - * Handle arrayed strength-aware net devices. - * - * Revision 1.92 2007/04/14 03:27:51 steve - * Handle system functions with no arguments. - * - * Revision 1.91 2007/04/12 04:25:58 steve - * vpip_make_binary_const cannot free the string passed in to it. - * - * Revision 1.90 2007/04/10 01:26:16 steve - * variable arrays generated without writing a record for each word. - * - * Revision 1.89 2007/03/02 06:13:22 steve - * Add support for edge sensitive spec paths. - * - * Revision 1.88 2007/03/01 06:19:39 steve - * Add support for conditional specify delay paths. - * - * Revision 1.87 2007/01/16 05:44:16 steve - * Major rework of array handling. Memories are replaced with the - * more general concept of arrays. The NetMemory and NetEMemory - * classes are removed from the ivl core program, and the IVL_LPM_RAM - * lpm type is removed from the ivl_target API. - * - * Revision 1.86 2006/11/22 06:10:05 steve - * Fix spurious event from net8 that is forced. - * - * Revision 1.85 2006/09/23 04:57:20 steve - * Basic support for specify timing. - * - * Revision 1.84 2006/07/30 02:51:36 steve - * Fix/implement signed right shift. - * - * Revision 1.83 2006/06/18 04:15:50 steve - * Add support for system functions in continuous assignments. - * - * Revision 1.82 2006/03/18 22:51:10 steve - * Syntax for carrying sign with parameter. - * - * Revision 1.81 2006/03/08 05:29:42 steve - * Add support for logic parameters. - * - * Revision 1.80 2006/01/02 05:32:07 steve - * Require explicit delay node from source. - * - * Revision 1.79 2005/11/25 17:55:26 steve - * Put vec8 and vec4 nets into seperate net classes. - * - * Revision 1.78 2005/10/12 17:23:15 steve - * Add alias nodes. - * - * Revision 1.77 2005/07/06 04:29:25 steve - * Implement real valued signals and arith nodes. - * - * Revision 1.76 2005/06/17 03:46:53 steve - * Make functors know their own width. - * - * Revision 1.75 2005/05/24 01:43:27 steve - * Add a sign-extension node. - * - * Revision 1.74 2005/05/08 23:40:14 steve - * Add support for variable part select. - * - * Revision 1.73 2005/04/28 04:59:53 steve - * Remove dead functor code. - * - * Revision 1.72 2005/04/24 20:07:26 steve - * Add DFF nodes. - * - * Revision 1.71 2005/04/03 05:45:51 steve - * Rework the vvp_delay_t class. - * - * Revision 1.70 2005/03/18 02:56:04 steve - * Add support for LPM_UFUNC user defined functions. - * - * Revision 1.69 2005/03/09 05:52:04 steve - * Handle case inequality in netlists. - * - * Revision 1.68 2005/03/09 04:52:40 steve - * reimplement memory ports. - * - * Revision 1.67 2005/03/03 04:33:10 steve - * Rearrange how memories are supported as vvp_vector4 arrays. - * - * Revision 1.66 2005/02/07 22:42:42 steve - * Add .repeat functor and BIFIF functors. - * - * Revision 1.65 2005/02/03 04:55:13 steve - * Add support for reduction logic gates. - * - * Revision 1.64 2005/01/22 01:06:20 steve - * Implement the .cmp/eeq LPM node. - * - * Revision 1.63 2005/01/09 20:11:15 steve - * Add the .part/pv node and related functionality. - * - * Revision 1.62 2004/12/29 23:45:13 steve - * Add the part concatenation node (.concat). - * - * Add a vvp_event_anyedge class to handle the special - * case of .event statements of edge type. This also - * frees the posedge/negedge types to handle all 4 inputs. - * - * Implement table functor recv_vec4 method to receive - * and process vectors. - * - * Revision 1.61 2004/12/11 02:31:30 steve - * Rework of internals to carry vectors through nexus instead - * of single bits. Make the ivl, tgt-vvp and vvp initial changes - * down this path. - * - * Revision 1.60 2004/10/04 01:10:59 steve - * Clean up spurious trailing white space. - * - * Revision 1.59 2004/08/28 16:26:41 steve - * .net range values can be signed. - * - * Revision 1.58 2004/06/30 02:15:57 steve - * Add signed LPM divide. - * - * Revision 1.57 2004/06/16 16:33:26 steve - * Add structural equality compare nodes. - * - * Revision 1.56 2003/09/04 20:26:31 steve - * Add $push flag for threads. - * - * Revision 1.55 2003/08/22 23:14:27 steve - * Preserve variable ranges all the way to the vpi. - * - * Revision 1.54 2003/05/29 02:21:45 steve - * Implement acc_fetch_defname and its infrastructure in vvp. - * - * Revision 1.53 2003/04/11 05:15:39 steve - * Add signed versions of .cmp/gt/ge - * - * Revision 1.52 2003/03/10 23:37:07 steve - * Direct support for string parameters. - * - * Revision 1.51 2003/02/09 23:33:26 steve - * Spelling fixes. - * - * Revision 1.50 2003/01/27 00:14:37 steve - * Support in various contexts the $realtime - * system task. - * - * Revision 1.49 2003/01/25 23:48:06 steve - * Add thread word array, and add the instructions, - * %add/wr, %cmp/wr, %load/wr, %mul/wr and %set/wr. - */ diff --git a/vvp/vpi_priv.cc b/vvp/vpi_priv.cc index 7e33a7084..671bab4b1 100644 --- a/vvp/vpi_priv.cc +++ b/vvp/vpi_priv.cc @@ -151,6 +151,7 @@ static int vpip_get_global(int property) { switch (property) { + case vpiTimeUnit: case vpiTimePrecision: return vpip_get_time_precision(); @@ -173,6 +174,8 @@ static const char* vpi_property_str(PLI_INT32 code) return "vpiFullName"; case vpiTimeUnit: return "vpiTimeUnit"; + case vpiTimePrecision: + return "vpiTimePrecision"; default: sprintf(buf, "%d", code); } @@ -309,8 +312,39 @@ int vpip_time_units_from_handle(vpiHandle obj) return signal->scope->time_units; default: - fprintf(stderr, "ERROR: vpi_get_time called with object " - "handle type=%u\n", obj->vpi_type->type_code); + fprintf(stderr, "ERROR: vpip_time_units_from_handle called with " + "object handle type=%u\n", obj->vpi_type->type_code); + assert(0); + return 0; + } +} + +int vpip_time_precision_from_handle(vpiHandle obj) +{ + struct __vpiSysTaskCall*task; + struct __vpiScope*scope; + struct __vpiSignal*signal; + + if (obj == 0) + return vpip_get_time_precision(); + + switch (obj->vpi_type->type_code) { + case vpiSysTaskCall: + task = (struct __vpiSysTaskCall*)obj; + return task->scope->time_precision; + + case vpiModule: + scope = (struct __vpiScope*)obj; + return scope->time_precision; + + case vpiNet: + case vpiReg: + signal = (struct __vpiSignal*)obj; + return signal->scope->time_precision; + + default: + fprintf(stderr, "ERROR: vpip_time_precision_from_handle called " + "with object handle type=%u\n", obj->vpi_type->type_code); assert(0); return 0; } diff --git a/vvp/vpi_priv.h b/vvp/vpi_priv.h index a4eaefb5c..8983daacd 100644 --- a/vvp/vpi_priv.h +++ b/vvp/vpi_priv.h @@ -169,6 +169,7 @@ struct __vpiScope { /* Keep a list of threads in the scope. */ vthread_t threads; signed int time_units :8; + signed int time_precision :8; }; extern struct __vpiScope* vpip_peek_current_scope(void); @@ -508,6 +509,7 @@ extern int vpip_get_time_precision(void); extern void vpip_set_time_precision(int pres); extern int vpip_time_units_from_handle(vpiHandle obj); +extern int vpip_time_precision_from_handle(vpiHandle obj); extern void vpip_time_to_timestruct(struct t_vpi_time*ts, vvp_time64_t ti); extern vvp_time64_t vpip_timestruct_to_time(const struct t_vpi_time*ts); @@ -568,97 +570,4 @@ enum vpi_rbuf_t { }; extern char *need_result_buf(unsigned cnt, vpi_rbuf_t type); -/* - * $Log: vpi_priv.h,v $ - * Revision 1.74 2007/04/12 04:25:59 steve - * vpip_make_binary_const cannot free the string passed in to it. - * - * Revision 1.73 2007/02/25 23:08:24 steve - * Process Verilog escape sequences much earlier. - * - * Revision 1.72 2007/01/16 05:44:16 steve - * Major rework of array handling. Memories are replaced with the - * more general concept of arrays. The NetMemory and NetEMemory - * classes are removed from the ivl core program, and the IVL_LPM_RAM - * lpm type is removed from the ivl_target API. - * - * Revision 1.71 2006/06/18 04:15:50 steve - * Add support for system functions in continuous assignments. - * - * Revision 1.70 2006/03/18 22:51:10 steve - * Syntax for carrying sign with parameter. - * - * Revision 1.69 2006/03/08 05:29:42 steve - * Add support for logic parameters. - * - * Revision 1.68 2006/03/06 05:43:15 steve - * Cleanup vpi_const to use vec4 values. - * - * Revision 1.67 2006/03/05 05:45:58 steve - * Add support for memory value change callbacks. - * - * Revision 1.66 2006/02/21 05:31:54 steve - * Put strings for reg objects. - * - * Revision 1.65 2006/02/21 02:39:27 steve - * Support string values for memory words. - * - * Revision 1.64 2005/07/06 04:29:25 steve - * Implement real valued signals and arith nodes. - * - * Revision 1.63 2005/06/13 00:54:04 steve - * More unified vec4 to hex string functions. - * - * Revision 1.62 2005/04/28 04:59:53 steve - * Remove dead functor code. - * - * Revision 1.61 2005/03/03 04:33:10 steve - * Rearrange how memories are supported as vvp_vector4 arrays. - * - * Revision 1.60 2004/12/11 02:31:30 steve - * Rework of internals to carry vectors through nexus instead - * of single bits. Make the ivl, tgt-vvp and vvp initial changes - * down this path. - * - * Revision 1.59 2004/10/04 01:10:59 steve - * Clean up spurious trailing white space. - * - * Revision 1.58 2004/06/30 03:00:36 steve - * Some explination of vpi_func arguments. - * - * Revision 1.57 2004/05/19 03:26:24 steve - * Support delayed/non-blocking assignment to reals and others. - * - * Revision 1.56 2003/06/17 19:17:42 steve - * Remove short int restrictions from vvp opcodes. - * - * Revision 1.55 2003/05/29 02:21:45 steve - * Implement acc_fetch_defname and its infrastructure in vvp. - * - * Revision 1.54 2003/05/02 04:29:57 steve - * Add put_value with transport delay. - * - * Revision 1.53 2003/04/23 03:09:25 steve - * VPI Access to named events. - * - * Revision 1.52 2003/03/10 23:37:07 steve - * Direct support for string parameters. - * - * Revision 1.51 2003/03/06 04:32:00 steve - * Use hashed name strings for identifiers. - * - * Revision 1.50 2003/02/24 06:35:45 steve - * Interactive task calls take string arguments. - * - * Revision 1.49 2003/02/23 06:41:54 steve - * Add to interactive stop mode support for - * current scope, the ability to scan/traverse - * scopes, and the ability to call system tasks. - * - * Revision 1.48 2003/02/10 05:20:10 steve - * Add value change callbacks to real variables. - * - * Revision 1.47 2003/02/09 23:33:26 steve - * Spelling fixes. - */ #endif diff --git a/vvp/vpi_scope.cc b/vvp/vpi_scope.cc index 4eaf21060..6815dcfc6 100644 --- a/vvp/vpi_scope.cc +++ b/vvp/vpi_scope.cc @@ -67,7 +67,7 @@ static int scope_get(int code, vpiHandle obj) case vpiTimeUnit: return ref->time_units; case vpiTimePrecision: - return vpip_get_time_precision(); + return ref->time_precision; } return 0; @@ -358,8 +358,9 @@ compile_scope_decl(char*label, char*type, char*name, char*tname, char*parent) attach_to_scope_(sp, &scope->base); scope->scope = (struct __vpiScope*)obj; - /* Inherit time units from the parent scope. */ + /* Inherit time units and precision from the parent scope. */ scope->time_units = sp->time_units; + scope->time_precision = sp->time_precision; } else { scope->scope = 0x0; @@ -370,8 +371,10 @@ compile_scope_decl(char*label, char*type, char*name, char*tname, char*parent) vpip_root_table_ptr[vpip_root_table_cnt] = &scope->base; vpip_root_table_cnt = cnt; - /* Root scopes inherit time_units from system precision. */ + /* Root scopes inherit time_units and precision from the + system precision. */ scope->time_units = vpip_get_time_precision(); + scope->time_precision = vpip_get_time_precision(); } #if 0 functor_set_scope(¤t_scope->base); @@ -391,10 +394,11 @@ void compile_scope_recall(char*symbol) * 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) +void compile_timescale(long units, long precision) { assert(current_scope); current_scope->time_units = units; + current_scope->time_precision = precision; } struct __vpiScope* vpip_peek_current_scope(void)