[sv-cc] svPut/GetUserData()


Subject: [sv-cc] svPut/GetUserData()
From: Stickley, John (john_stickley@mentorg.com)
Date: Wed Mar 12 2003 - 15:28:20 PST


Team,

At Joao's request, I'm renaming this thread so it does not
get mixed in with extern/export language extensions discussions
that need to be concluded by tomorrow.

Continuing my train of thought from before, it occurs to me
that we may just want to make svGetUserData() work just
like svGetScope() in that it takes *no* arguments.

That is, the knowledge of current context and current function
call is already there when an extern'ed function is called.
So the infrastructure can simply return it without being given
the scope handle.

In the use models I'm thinking of, actually svGetUserData()
would be used most of the time. svGetScope() would rarely be
used.

So, to summarize, let's consider the following for svPut/GetUserData()

     void* svGetUserData();
         // Returns user context for current extern'ed function
         // of current scope

     void svPutUserData( const svScope, const char *cname, void *userData );
         // Associates a user context with a specific extern'ed function
         // of a specific module instance.

How does this sound ? (It also solves the dilema we discussed
in today's meeting of having multiple externed functions set
individual user context pointers in the same SV module scope)

Also in these use models, svGetScopeByName() would typically
be used once at init(construction) time then the return handle
would be stored and reused with each call to an exported function
when such functions are called from C models (using svSetScope()).

So, to summarize this use model:

---------------------------------------
C Side:

class MyCModel {
     private:
         dSvScope svScope;
         void *processArgs( args ... );

     public:
         MyCModel( const char *svModulePath ){
             dSvScope = svGetScopeByName( svModulePath );
             svPutUserData( dSvScope, "MyExternedCFunc", this );
         }

     // This function is called from SV ...
     friend void MyExternedCFunc( args ... ){
         MyCModel *me = (MyCModel *)svGetUserData(); // <- No args !!!

         me->processArgs( args ... );
     }

     public:
         // This public method calls an exported SV function ...
         void CallExportedFunction( args ... ){
             svPutScope( dSvScope );
             MyExportedSvFunc( args ... );
         }
};

---------------------------------------
SV Side:

module MySvModel();
     extern "DPI" context MyExternedCFunc = CFunc( args ... );

     export "DPI" MyExportedSvFunc = function SvFunc;
     void function SvFunc( args ... ) begin
         ...
     endfunction

endmodule

I think these changes make the interface a lot cleaner.

-- 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 : Wed Mar 12 2003 - 15:30:03 PST