Wednesday, February 08, 2012     Register | Login | Search | Contact Us
     

Many of you already received communications about the move of the Cadence user community into cadence.com. And many of you have already joined, with over 4000 registrations in the first two weeks.

The new Cadence Community enhances the ability of Cadence users to connect and collaborate. In addition to moving the community into cadence.com -- enabling single sign-on for community, Sourcelink and Cadence events -- the new site is organized around nine technology segments, giving you easy access to product information, training, forums and blogs. Some of the new features include:
  • Ability to respond to posts via e-mail
  • Technology-specific blogs
  • Latest Web 2.0 social networking capabilities
  • Public profile options
  • Private messaging
  • Friends lists
Visit the new Cadence Community today at www.cadence.com/community and join the discussions!

Registration note: Due to the scope of the enhancements and the new SSO registration system, we were not able to migrate existing cdnusers.org member accounts. So new registrations are required, but this enables a broader set of functionality we think you'll enjoy.

Forum note: Under the guidance of forum moderators, we have taken the 20+ cdnusers.org forums and consolidated them into 11 forums on the new site. Posts have been brought over so you can leverage that posting history. CDNusers forums will be set to read only starting 7/30, and cdnusers.org will be redirected to the new community on 8/4.

Best regards,
Mike and Tom

Michael A. Catrambone - Steering Committee Chairman
Distinguished Engineer
PCB/Mechanical
UTStarcom, Inc.

Tom Diederich
Cadence Community Manager
Home
Forums
Subject: C++ code through DPI?
Posting to forums is available to community members only.
Login or Register
Rate this topic:
   
Author Messages
davyzhu
Posts: 90
Online: User is Offline
4/23/2007 12:30 AM  
Hi all,

I have to encapsulte some transaction layer C++ code using DPI, is there any example on how to do it?

Shall I simply replace gcc with g++ to compile my code?

Thanks!

Best regards,
Davy
jlrose
Posts: 2
Online: User is Offline
4/23/2007 1:08 PM  
Hi Davy,

It depends on exactly what you are trying to do. DPI is a C interface, so you can't blindly compile the DPI code using g++ and have that work. At a minimum, you need to make sure that the import and export c functions are defined as extern "C" so that they don't use mangled names. The export functions will always be C functions (that is how the verilog simulator exposes them), so all you need to do is make sure that your header file has extern "C" in front of the import function name. Your import functions are presumably the functions which are wrapping your c++ code. Again, you should be able to just wrap the functions with extern "C".

For instance, you can have the following:
//my.cpp
#include
using namespace std;
extern "C" void doit() ;
void doit() {
cout << "hi from doit" << endl;
}
//test.sv
module test;
initial doit();
import"DPI" function void doit();
endmodule

Now, if what you want to do is call a class method from a dpi import function, you will need to be a little more clever. The easiest thing to do is to keep a map on the c++ side which has string (or integral) lookup keys to access specific objects. Then, you need the sv function call to include the key for the object that you want to execute the function on. This means basically wrapping each class method with a c function (there are tricks you can do like using the boost bind library to create a more generic way of doing this, but the basic requirments are still the same).

john
davyzhu
Posts: 90
Online: User is Offline
4/24/2007 2:02 AM  
Hi John,

Sorry for the ambiguous problem and I will try to clarify it. The C++ files mainly for reference model in testbench (written by other people).

Now image I have a c++ file have just one class, and I can use your turn function in class to pure function method.

But If I have a c++ file have several class (class A contains class B object, class B contains class C object , and so on), how can I modify so many things by hand. And I don't want to break the encapsulation for it will be hard for me to update the C++ code.

Any suggestions are welcome!

Best regards,
Davy
Posting to forums is available to community members only.
Login or Register

Forums > Functional Verification > SystemVerilog > C++ code through DPI?


ActiveForums 3.6
     
Copyright 2006 Cadence Design Systems, Inc.