Re: [sv-cc] LRM modifications for svGet/PutUserData proposal


Subject: Re: [sv-cc] LRM modifications for svGet/PutUserData proposal
From: Stickley, John (john_stickley@mentorg.com)
Date: Tue Mar 25 2003 - 22:11:02 PST


Francoise, Andrzej, Doug,

It occurs to me there's still a fundamental flaw with

      int svGetUserDataIdForScope(const svScope scope);

What you really want is an ID for a given module *type*,
not instance - that can be shared among all module
instances.

In other words, the when you do an svSetUserData()
you do so with the combination of the module scope
handle and the ID that is applicable to *all* instances
of the given module type (think of it as in index
to something like a single "vtable" of user data pointers
that is referenced from each instance
of a module scope just as instances of C++ objects
all access a vtable common to the class type).

So for this reason, svScope should not be the arg
to this function but really module name should.

Something like this:

      int svGetUserDataIdForScope(const char *moduleName);

Do you see the problem I'm alluding to and why the
it will not work as originally proposed ?

If you're going to store the ID as a static variable
then you cannot have a different ID per module instance.
You only want a different ID per module type.

Otherwise the static ID storage scheme will just
not work.

Do you agree ?

This is why I'm still uncomfortable with "keys"
that are not based on the function names themselves
being used in conjunction with the module instance
scope.

But I think the ID scheme can work if it is based
on module type rather than scope.

-- johnS

Stickley, John wrote:
> Team,
>
> In the interest of expediency and ease of insertion, I've
> tried to frame Francoise's proposal in the form that can
> be inserted directly into Joao's draft of the LRM.
>
> Note to Joao: There are a number of errors in the example
> in section A.8.4. Please supersede with my version where those
> errors have been corrected (and where the new get/putUserData()
> usage is demonstrated). Also, what is missing is an
> example of invoking an exported function after setting
> svPutScope(). I can provide an extension to the existing
> example that shows this if you wish.
>
> Here are the required updates to the LRM.
>
> ---------------------- cut here ----------------------
>
> A.8.3 Working with DPI context functions in C code
>
> [...]
>
> /* Return a unique ID that can be used as a key to store user
> data in a given module scope. */
> int svGetUserDataIdForScope(const svScope scope);
>
> /* Set arbitrary user data pointer into specified instance scope */
> void svPutUserData(const svScope scope, int userDataId, void* userData);
>
> /* Retrieve arbitrary user data from specified instance scope */
> void* svGetUserData(const svScope scope, int userDataId );
>
> [...]
>
> New section
> | | | | |
> V V V V V
>
> A.8.3.1 Associating User Data with Module Contexts
>
> The DPI allows association of multiple user defined data
> pointers with module instances by allocating unique ID's
> that can serve has keys to identify each distinct user
> data pointer to be associated with a given module instance.
>
> The user data pointer is of type void * and is never
> interpreted by the SV infrastructure - only by the user
> application.
>
> The svGetUserDataIdForScope() function can be called at
> initialization time to request unique IDs that can be
> used to identify user data pointers to be associated
> with a given module scope.
>
> The returned ID can be stored in a place known to the
> C code (most likely a static or global variable) and
> later be frequently referenced during run-time when
> svGetUserData() is called to retrieve user data
> pointers inside imported C functions that are called
> from SystemVerilog.
>
> The functions svPutUserData() and svGetuserData() each
> require a module scope handle and a user data ID argument.
>
> ID=0 is reserved to denote the NULL or invalid ID. This
> allows a variable used to store an ID to be conveniently
> tested for validity.
>
> A.8.4 Example 1 — Using DPI context functions
>
> SV Side:
>
> [...]
>
> C Side:
>
> // Define the function and model class on the C++ side:
> class MyCModel {
> private:
> static int dUserDataId;
> int locallyMapped(int portID); // Does something interesting...
>
> public:
> // Constructor
> MyCModel(const char* instancePath) {
> svScope scope = svGetScopeByName(instancePath);
>
> // Allocate a unique ID to be used as key to associate
> // user data with module scope. Skip this step if ID
> // has already been assigned.
> if( dUserDataId != 0 )
> dUserDataId = svGetUserDataIdForScope( scope );
>
> // Associate “this” with SV scope (avoids a hash in C++ code)
> svPutUserData(scope, this);
> }
>
> friend int MyCFunc(int portID);
> };
>
> int MyCModel::dUserDataId = 0;
>
> // Implementation of external context function callable in SV
> int MyCFunc(int portID) {
> // Retrieve SV module instance scope (i.e. this function’s context).
> svScope scope = svGetScope();
>
> // Retrieve and make use of user data stored in SV scope
> MyCModel* me = (MyCModel*)svGetUserData( scope, dUserDataId );
>
> return me->locallyMapped(portID);
> }
>
> -- johnS
>
>
> __
> ______ | \
> ______________________/ \__ / \
> \ H Dome ___/ |
> John Stickley E | a __ ___/ / \____
> Principal Engineer l | l | \ /
> Verification Solutions Group | f | \/ ____
> Mentor Graphics Corp. - MED C \ -- / /
> 17 E. Cedar Place a \ __/ / /
> Ramsey, NJ 07446 p | / ___/
> | / /
> mailto:John_Stickley@mentor.com \ /
> Phone: (201)818-2585 \ /
> ---------
>

-- 

This email may contain material that is confidential, privileged and/or attorney work product for the sole use of the intended recipient. Any review, reliance or distribution by others or forwarding without express permission is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies. __ ______ | \ ______________________/ \__ / \ \ H Dome ___/ | John Stickley E | a __ ___/ / \____ Principal Engineer l | l | \ / Verification Solutions Group | f | \/ ____ Mentor Graphics Corp. - MED C \ -- / / 17 E. Cedar Place a \ __/ / / Ramsey, NJ 07446 p | / ___/ | / / mailto:John_Stickley@mentor.com \ / Phone: (201)818-2585 \ / ---------



This archive was generated by hypermail 2b28 : Tue Mar 25 2003 - 22:13:12 PST