Subject: [sv-cc] LRM modifications for svGet/PutUserData proposal
From: Stickley, John (john_stickley@mentorg.com)
Date: Tue Mar 25 2003 - 14:07:11 PST
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 archive was generated by hypermail 2b28 : Tue Mar 25 2003 - 14:09:12 PST