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.
This commit is contained in:
Martin Whitaker 2020-12-03 23:55:22 +00:00
parent 3f9a49ae01
commit 360d1ca447
14 changed files with 57 additions and 64 deletions

View File

@ -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);
}

View File

@ -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);

View File

@ -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) {

View File

@ -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 <acc_user.h>
#include <vpi_user.h>
#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;
}

View File

@ -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 <veriuser.h>
#include <vpi_user.h>
#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;
}

View File

@ -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 <assert.h>
#include <veriuser.h>
#include <vpi_user.h>
#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) {

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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 <vpi_user.h>
#include <stdio.h>
#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);
}

View File

@ -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 <assert.h>
#include <veriuser.h>
#include <vpi_user.h>
#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);

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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 <assert.h>
#include <veriuser.h>
#include <vpi_user.h>
#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) {

View File

@ -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 <vpi_user.h>
# include <stdlib.h>
# 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;
}