Hello,
I have imported .c file in .sv(systemverilog) file using dpi and its runs
now i want to import .cpp file in .sv file using dpi
explain it with a simple example based on class
Is there any changes in syntax for .cpp and .sv file connection using dpi
how to do that ?
help me
Thanks and regards
You cannot use the DPI to call class methods across the language boundary.
But if you can make your C++ code interface with C code, you can make it interface with SystemVerilog. See DPI C++ Exports | Verification Academy
I have below example for c++
#include <iostream>
using namespace std;
class Rectangle {
int width, height;
public:
void set_values (int,int);
int area () {return width*height;}
};
void Rectangle::set_values (int x, int y) {
width = x;
height = y;
}
int main () {
Rectangle rect, rectb;
rect.set_values (3,4);
rectb.set_values (5,6);
cout << "rect area: " << rect.area() << endl;
cout << "rectb area: " << rectb.area() << endl;
return 0;
}
i want to import this function in my systemverilog file So,what changes i have to do in my .sv file and .cpp file?
In reply to hirenpatel:
You cannot call a method of a C++ class from the SystemVerilog DPI. Think of how you would call C++ from C. You need to call a non-class function, and that function needs to either construct the class before calling the class method, or have the class handle initialized before the function is called.
Can you please explain me with one little example ?
So, I can easily understand
In reply to hirenpatel:
OK, here are two example in one testcase. There are probably many more ways of doing this, but I hope this gives you the basic ideas of how to map to class objects.
cpp.tar.gz (2.1 KB)