From 360d1ca44726add66faae1ff90f16e976b90aae0 Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Thu, 3 Dec 2020 23:55:22 +0000 Subject: [PATCH] Fix the libveriuser TF and ACC functions to work in callbacks. Use the new cur_instance variable to get the call handle instead of calling vpi_handle(vpiSysTfCall, 0). This completes a proper fix for issue #141, to replace the problematic fix that was reverted in commit 8da8261f. --- libveriuser/a_fetch_tfarg.c | 8 ++++---- libveriuser/a_handle_by_name.c | 5 ++--- libveriuser/a_handle_object.c | 5 ++--- libveriuser/a_handle_tfarg.c | 10 +++++----- libveriuser/getinstance.c | 5 +++-- libveriuser/getlongp.c | 8 ++++---- libveriuser/getp.c | 8 ++++---- libveriuser/getsimtime.c | 18 ++++++++---------- libveriuser/nump.c | 6 +++--- libveriuser/putlongp.c | 12 ++++++------ libveriuser/putp.c | 6 +++--- libveriuser/spname.c | 9 ++++----- libveriuser/typep.c | 8 ++++---- libveriuser/workarea.c | 13 +++++-------- 14 files changed, 57 insertions(+), 64 deletions(-) diff --git a/libveriuser/a_fetch_tfarg.c b/libveriuser/a_fetch_tfarg.c index 036100958..774d9695e 100644 --- a/libveriuser/a_fetch_tfarg.c +++ b/libveriuser/a_fetch_tfarg.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002-2009 Michael Ruff (mruff at chiaro.com) + * Copyright (c) 2002-2020 Michael Ruff (mruff at chiaro.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 @@ -55,7 +55,7 @@ double acc_fetch_itfarg(PLI_INT32 n, handle obj) double acc_fetch_tfarg(PLI_INT32 n) { - return acc_fetch_itfarg_int(n, vpi_handle(vpiSysTfCall,0)); + return acc_fetch_itfarg_int(n, cur_instance); } @@ -90,7 +90,7 @@ PLI_INT32 acc_fetch_itfarg_int(PLI_INT32 n, handle obj) PLI_INT32 acc_fetch_tfarg_int(PLI_INT32 n) { - return acc_fetch_itfarg_int(n, vpi_handle(vpiSysTfCall,0)); + return acc_fetch_itfarg_int(n, cur_instance); } @@ -126,5 +126,5 @@ char *acc_fetch_itfarg_str(PLI_INT32 n, handle obj) char *acc_fetch_tfarg_str(PLI_INT32 n) { - return acc_fetch_itfarg_str(n, vpi_handle(vpiSysTfCall,0)); + return acc_fetch_itfarg_str(n, cur_instance); } diff --git a/libveriuser/a_handle_by_name.c b/libveriuser/a_handle_by_name.c index c6a96c878..5d54adba6 100644 --- a/libveriuser/a_handle_by_name.c +++ b/libveriuser/a_handle_by_name.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2012 Michael Ruff (mruff at chiaro.com) + * Copyright (c) 2003-2020 Michael Ruff (mruff at chiaro.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 @@ -32,8 +32,7 @@ handle acc_handle_by_name(const char*obj_name, handle scope) /* if no scope provided, use tasks scope */ if (!scope) { - vpiHandle sys_h = vpi_handle(vpiSysTfCall, 0 /* NULL */); - scope = vpi_handle(vpiScope, sys_h); + scope = vpi_handle(vpiScope, cur_instance); } res = vpi_handle_by_name(obj_name, scope); diff --git a/libveriuser/a_handle_object.c b/libveriuser/a_handle_object.c index b92bd7171..aa59478f8 100644 --- a/libveriuser/a_handle_object.c +++ b/libveriuser/a_handle_object.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003 Stephen Williams (steve@icarus.com) + * Copyright (c) 2003-2020 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 @@ -25,8 +25,7 @@ static vpiHandle search_scope = 0; handle acc_handle_object(const char*name) { - vpiHandle sys = vpi_handle(vpiSysTfCall, 0); - vpiHandle scope = search_scope? search_scope : vpi_handle(vpiScope, sys); + vpiHandle scope = search_scope? search_scope : vpi_handle(vpiScope, cur_instance); vpiHandle res = vpi_handle_by_name(name, scope); if (pli_trace) { diff --git a/libveriuser/a_handle_tfarg.c b/libveriuser/a_handle_tfarg.c index 4f92116bf..e1f343d1c 100644 --- a/libveriuser/a_handle_tfarg.c +++ b/libveriuser/a_handle_tfarg.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002-2012 Michael Ruff (mruff at chiaro.com) + * Copyright (c) 2002-2020 Michael Ruff (mruff at chiaro.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 @@ -19,6 +19,7 @@ #include #include +#include "priv.h" /* * acc_handle_tfarg implemented using VPI interface @@ -28,10 +29,9 @@ handle acc_handle_tfarg(int n) vpiHandle rtn_h = 0; if (n > 0) { - vpiHandle sys_h, sys_i; + vpiHandle sys_i; - sys_h = vpi_handle(vpiSysTfCall, 0 /* NULL */); - sys_i = vpi_iterate(vpiArgument, sys_h); + sys_i = vpi_iterate(vpiArgument, cur_instance); /* find nth arg */ while (n > 0) { @@ -52,5 +52,5 @@ handle acc_handle_tfarg(int n) handle acc_handle_tfinst(void) { - return vpi_handle(vpiSysTfCall, 0); + return cur_instance; } diff --git a/libveriuser/getinstance.c b/libveriuser/getinstance.c index b887e86be..e30bd05b9 100644 --- a/libveriuser/getinstance.c +++ b/libveriuser/getinstance.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002 Michael Ruff (mruff at chiaro.com) + * Copyright (c) 2002-2020 Michael Ruff (mruff at chiaro.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 @@ -19,11 +19,12 @@ #include #include +#include "priv.h" /* * tf_getinstance implemented using VPI interface */ PLI_BYTE8* tf_getinstance(void) { - return (PLI_BYTE8 *)vpi_handle(vpiSysTfCall, 0 /* NULL */); + return (PLI_BYTE8 *)cur_instance; } diff --git a/libveriuser/getlongp.c b/libveriuser/getlongp.c index b3930cb13..4b247a9d9 100644 --- a/libveriuser/getlongp.c +++ b/libveriuser/getlongp.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002-2012 Michael Ruff (mruff at chiaro.com) + * Copyright (c) 2002-2020 Michael Ruff (mruff at chiaro.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 @@ -22,13 +22,14 @@ #include #include #include +#include "priv.h" /* * tf_getlongp implemented using VPI interface */ int tf_getlongp(int *highvalue, int n) { - vpiHandle sys_h, sys_i, arg_h = 0; + vpiHandle sys_i, arg_h = 0; s_vpi_value value; int len, rtn; @@ -36,8 +37,7 @@ int tf_getlongp(int *highvalue, int n) assert(n > 0); /* get task/func handle */ - sys_h = vpi_handle(vpiSysTfCall, 0); - sys_i = vpi_iterate(vpiArgument, sys_h); + sys_i = vpi_iterate(vpiArgument, cur_instance); /* find nth arg */ while (n > 0) { diff --git a/libveriuser/getp.c b/libveriuser/getp.c index a32852bfd..c98b0d177 100644 --- a/libveriuser/getp.c +++ b/libveriuser/getp.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002-2009 Michael Ruff (mruff at chiaro.com) + * Copyright (c) 2002-2020 Michael Ruff (mruff at chiaro.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 @@ -72,7 +72,7 @@ out: PLI_INT32 tf_getp(PLI_INT32 n) { - int rtn = tf_igetp(n, vpi_handle(vpiSysTfCall, 0)); + int rtn = tf_igetp(n, cur_instance); return rtn; } @@ -119,7 +119,7 @@ out: double tf_getrealp(PLI_INT32 n) { - double rtn = tf_igetrealp(n, vpi_handle(vpiSysTfCall, 0)); + double rtn = tf_igetrealp(n, cur_instance); return rtn; } @@ -176,7 +176,7 @@ out: char *tf_strgetp(PLI_INT32 n, PLI_INT32 fmt) { - char *rtn = tf_istrgetp(n, fmt, vpi_handle(vpiSysTfCall, 0)); + char *rtn = tf_istrgetp(n, fmt, cur_instance); return rtn; } diff --git a/libveriuser/getsimtime.c b/libveriuser/getsimtime.c index a8812bd0c..8724cf6c7 100644 --- a/libveriuser/getsimtime.c +++ b/libveriuser/getsimtime.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002-2014 Michael Ruff (mruff at chiaro.com) + * Copyright (c) 2002-2020 Michael Ruff (mruff at chiaro.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 @@ -46,7 +46,7 @@ scale(int high, int low, void*obj) vpiHandle use_obj = obj; if (use_obj == 0) { /* If object is not passed in, then use current scope. */ - vpiHandle hand = vpi_handle(vpiScope, vpi_handle(vpiSysTfCall,0)); + vpiHandle hand = vpi_handle(vpiScope, cur_instance); use_obj = hand; } else { /* If object IS passed in, make sure it is a scope. If @@ -145,7 +145,7 @@ void tf_unscale_longdelay(void*obj, PLI_INT32 low, PLI_INT32 high, PLI_INT32 *alow, PLI_INT32 *ahigh) { ivl_u64_t unscaled; - vpiHandle hand = vpi_handle(vpiScope, vpi_handle(vpiSysTfCall,0)); + vpiHandle hand = vpi_handle(vpiScope, cur_instance); (void)obj; /* Parameter is not used. */ @@ -160,7 +160,7 @@ void tf_unscale_longdelay(void*obj, PLI_INT32 low, PLI_INT32 high, void tf_scale_realdelay(void*obj, double real, double *areal) { - vpiHandle hand = vpi_handle(vpiScope, vpi_handle(vpiSysTfCall,0)); + vpiHandle hand = vpi_handle(vpiScope, cur_instance); (void)obj; /* Parameter is not used. */ @@ -170,7 +170,7 @@ void tf_scale_realdelay(void*obj, double real, double *areal) void tf_unscale_realdelay(void*obj, double real, double *areal) { - vpiHandle hand = vpi_handle(vpiScope, vpi_handle(vpiSysTfCall,0)); + vpiHandle hand = vpi_handle(vpiScope, cur_instance); (void)obj; /* Parameter is not used. */ @@ -182,15 +182,13 @@ PLI_INT32 tf_gettimeprecision(void) { PLI_INT32 rc; vpiHandle hand; - vpiHandle sys = vpi_handle(vpiSysTfCall,0); - assert(sys); - hand = vpi_handle(vpiScope, sys); + hand = vpi_handle(vpiScope, cur_instance); rc = vpi_get(vpiTimePrecision, hand); if (pli_trace) fprintf(pli_trace, "tf_gettimeprecision(<%s>) --> %d\n", - vpi_get_str(vpiName, sys), (int)rc); + vpi_get_str(vpiName, cur_instance), (int)rc); return rc; } @@ -221,7 +219,7 @@ PLI_INT32 tf_igettimeprecision(void*obj) PLI_INT32 tf_gettimeunit() { - vpiHandle hand = vpi_handle(vpiScope, vpi_handle(vpiSysTfCall,0)); + vpiHandle hand = vpi_handle(vpiScope, cur_instance); return vpi_get(vpiTimeUnit, hand); } diff --git a/libveriuser/nump.c b/libveriuser/nump.c index 38d574020..8cf4da3a5 100644 --- a/libveriuser/nump.c +++ b/libveriuser/nump.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002 Michael Ruff (mruff at chiaro.com) + * Copyright (c) 2002-2020 Michael Ruff (mruff at chiaro.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 @@ -20,6 +20,7 @@ #include #include #include "veriuser.h" +#include "priv.h" /* * tf_nump implemented using VPI interface @@ -41,6 +42,5 @@ int tf_inump(void *obj) int tf_nump(void) { - vpiHandle sys_h = vpi_handle(vpiSysTfCall, 0 /* NULL */); - return tf_inump(sys_h); + return tf_inump(cur_instance); } diff --git a/libveriuser/putlongp.c b/libveriuser/putlongp.c index 1093d9507..ea489cc7c 100644 --- a/libveriuser/putlongp.c +++ b/libveriuser/putlongp.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002 Michael Ruff (mruff at chiaro.com) + * Copyright (c) 2002-2020 Michael Ruff (mruff at chiaro.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 @@ -21,13 +21,14 @@ #include #include #include +#include "priv.h" /* * tf_putlongp implemented using VPI interface */ void tf_putlongp(int n, int lowvalue, int highvalue) { - vpiHandle sys_h, sys_i, arg_h = 0; + vpiHandle sys_i, arg_h = 0; s_vpi_value val; int type; char str[20]; @@ -36,10 +37,9 @@ void tf_putlongp(int n, int lowvalue, int highvalue) assert(n >= 0); /* get task/func handle */ - sys_h = vpi_handle(vpiSysTfCall, 0); - sys_i = vpi_iterate(vpiArgument, sys_h); + sys_i = vpi_iterate(vpiArgument, cur_instance); - type = vpi_get(vpiType, sys_h); + type = vpi_get(vpiType, cur_instance); /* verify function */ assert(!(n == 0 && type != vpiSysFuncCall)); @@ -49,7 +49,7 @@ void tf_putlongp(int n, int lowvalue, int highvalue) if (!(arg_h = vpi_scan(sys_i))) assert(0); n--; } - if (!arg_h) arg_h = sys_h; + if (!arg_h) arg_h = cur_instance; /* fill in vpi_value */ sprintf(str, "%x%08x", highvalue, lowvalue); diff --git a/libveriuser/putp.c b/libveriuser/putp.c index 1a6e71b39..c81b2f724 100644 --- a/libveriuser/putp.c +++ b/libveriuser/putp.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002-2009 Michael Ruff (mruff at chiaro.com) + * Copyright (c) 2002-2020 Michael Ruff (mruff at chiaro.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 @@ -87,7 +87,7 @@ PLI_INT32 tf_iputp(PLI_INT32 n, PLI_INT32 value, void *obj) PLI_INT32 tf_putp(PLI_INT32 n, PLI_INT32 value) { - int rtn = tf_iputp(n, value, vpi_handle(vpiSysTfCall, 0)); + int rtn = tf_iputp(n, value, cur_instance); return rtn; } @@ -136,7 +136,7 @@ out: PLI_INT32 tf_putrealp(PLI_INT32 n, double value) { - int rtn = tf_iputrealp(n, value, vpi_handle(vpiSysTfCall, 0)); + int rtn = tf_iputrealp(n, value, cur_instance); return rtn; } diff --git a/libveriuser/spname.c b/libveriuser/spname.c index bb00d0deb..98f43821e 100644 --- a/libveriuser/spname.c +++ b/libveriuser/spname.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003 Stephen Williams (steve@icarus.com) + * Copyright (c) 2003-2020 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 @@ -26,14 +26,13 @@ char* tf_spname(void) { char*rtn; - vpiHandle sys = vpi_handle(vpiSysTfCall, 0); - vpiHandle scope = vpi_handle(vpiScope, sys); + vpiHandle scope = vpi_handle(vpiScope, cur_instance); rtn = __acc_newstring(vpi_get_str(vpiFullName, scope)); if (pli_trace) { fprintf(pli_trace, "%s: tf_spname() --> %s\n", - vpi_get_str(vpiName,sys), rtn); + vpi_get_str(vpiName, cur_instance), rtn); } return rtn; @@ -46,5 +45,5 @@ char *tf_imipname(void *obj) char *tf_mipname(void) { - return tf_imipname(vpi_handle(vpiSysTfCall,0)); + return tf_imipname(cur_instance); } diff --git a/libveriuser/typep.c b/libveriuser/typep.c index 23fbc6eb8..e43d4dce6 100644 --- a/libveriuser/typep.c +++ b/libveriuser/typep.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002 Stephen Williams (steve@icarus.com) + * Copyright (c) 2002-2020 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 @@ -20,17 +20,17 @@ #include #include #include +#include "priv.h" PLI_INT32 tf_typep(PLI_INT32 narg) { - vpiHandle sys_h, argv, arg_h = 0; + vpiHandle argv, arg_h = 0; int rtn; assert(narg > 0); /* get task/func handle */ - sys_h = vpi_handle(vpiSysTfCall, 0); - argv = vpi_iterate(vpiArgument, sys_h); + argv = vpi_iterate(vpiArgument, cur_instance); /* find nth arg */ while (narg > 0) { diff --git a/libveriuser/workarea.c b/libveriuser/workarea.c index 30c14dab1..8d1dd4051 100644 --- a/libveriuser/workarea.c +++ b/libveriuser/workarea.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002-2010 Stephen Williams (steve@icarus.com) + * Copyright (c) 2002-2020 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 @@ -21,6 +21,7 @@ # include # include # include "ivl_alloc.h" +#include "priv.h" /* * Keep a list of sys handle to work area bindings. @@ -35,14 +36,12 @@ static struct workarea_cell*area_list = 0; PLI_INT32 tf_setworkarea(void*workarea) { - vpiHandle sys; struct workarea_cell*cur; - sys = vpi_handle(vpiSysTfCall, 0); cur = area_list; while (cur) { - if (cur->sys == sys) { + if (cur->sys == cur_instance) { cur->area = workarea; return 0; } @@ -52,7 +51,7 @@ PLI_INT32 tf_setworkarea(void*workarea) cur = calloc(1, sizeof (struct workarea_cell)); cur->next = area_list; - cur->sys = sys; + cur->sys = cur_instance; cur->area = workarea; area_list = cur; @@ -62,13 +61,11 @@ PLI_INT32 tf_setworkarea(void*workarea) PLI_BYTE8* tf_getworkarea(void) { struct workarea_cell*cur; - vpiHandle sys; - sys = vpi_handle(vpiSysTfCall, 0); cur = area_list; while (cur) { - if (cur->sys == sys) { + if (cur->sys == cur_instance) { return cur->area; }