Subject: Alternative to SvccBindSVcallee/r
From: Kevin Cameron x3251 (Kevin.Cameron@nsc.com)
Date: Tue Nov 12 2002 - 10:40:26 PST
[I don't think this got to the reflector last time I sent it.]
To avoid using a seperate "bind" call, functions requiring context
can be called as -
<user func name>(<instance handle>,void **c_context,....)
The instance handle can be a PLI handle for call-backs, and c_context
points at a pointer location in the simulator which is initially zero
- the user can fill it if desired on the first call for future calls
(avoids hash-lookup).
e.g.
SV:
extern "C" context int uf(int);
int x;
always@(clock) x=uf(x);
C:
int uf(handle ip,void **p_cntxt,int data)
{
int *lst_data,
new_num;
if (!(lst_data = *(int **)p_cntxt)) {
/* first call only */
if(!(*p_cntxt = calloc(1,sizeof int)) {
reportError(ip,"C:uf","Out of memory");
return -1;
}
}
new_num = random_num(*lst_data);
*lst_data = new_num;
return new_num;
}
If you were calling a SystemC class (non-virtual) method it can
use the ip handle to locate the right "this" on the first call
and save it in *p_cntxt.
Regards,
Kev.
This archive was generated by hypermail 2b28 : Tue Nov 12 2002 - 10:41:15 PST