Re: Modified Proposal for Context Sensitive Function Calls


Subject: Re: Modified Proposal for Context Sensitive Function Calls
From: Kevin Cameron x3251 (Kevin.Cameron@nsc.com)
Date: Tue Nov 19 2002 - 11:41:59 PST


I just resent a couple of emails that I'd forgotten to send
to the reflector, the first one (http://www.eda.org/sv-cc/hm/0332.html)
has an alternative method for binding/calling an SV task/function
which should be more efficient since it avoids having to decoded
the task/context on every call - i.e. a task may have a per-instance
implementation so the call -

   <task name>(<sv context>,...)

- from C to SV requires a lookup on the context to obtain an entry-point
to the actual code. Decoding the actual entry-point at setup time avoids
the lookup overhead on later calls, and avoids the exported task/function
having to appear in the C routine name space (for linking).

The converse mechanism could be used to link module (class) specific
routines to module instances, i.e. if a module declares an XF (rather
than in $root) it would be bound to a C/C++ function pointer at elaboration
by calling a user-supplied (PLI) routine e.g.:

   pointer ($)svcGetXF(<module name>,<module instance name>,<function name>,
                       {,<argument type>});

The XF would then be called as:

   (*xf_pointer)(<instance pli handle>,<context pointer>,...);

Note: since multiple C/C++ libraries may be involved from different sources
it would probably be better to allow multiple "svcGetXF" functions by
providing a registration mechanism in SV, e.g.:

   bool svcXFlocater(<function name>,
                     <locater context>,
                     <module name regexp>); // returns false if registration fails

Which would lead to code like the following to bind a class method:

   static pointer myBinder(void *,char *,char *,char *,void **,...);
   class foo {

       bind(char *,char *,char *);

       my_class() { svcXFlocater(myBinder,
                                 this,"foo"); // XF locater for module "foo"
                    ... }

   }

   static pointer myBinder(void *context,char *modname,char *inst_name,char *rtn_name,
                           void **p_context,...)
   {
      pointer rtn_addr = ((foo *)context)->bind(modname,inst_name,rtn_name);

      if (rtn_addr) *p_context = this; // set context for future calls.

      return rtn_addr;
   }

The module name (regexp) with the svcXFlocater call is necessary to limit the scope
of the binding (and speed it up).

The locater function could create all the class/context data on the fly so
that it is only created if the calling module is instanced (maybe indicated
by a null locater context).

Kev.



This archive was generated by hypermail 2b28 : Tue Nov 19 2002 - 11:43:57 PST