0

是否可以将 SystemVerilog 结构转换为某些类型擦除的指针,例如void *

我需要将不同结构类型的对象从 SV 传递到 C。我希望有一个 DPI 函数来处理任何类型的受支持结构。

在 SystemVerilog 方面,我有很多类型:

typedef struct { ... } stype1;
typedef struct { ... } stype2;
typedef struct { ... } stype3;
typedef struct { ... } stype4;

stype1 var1;
stype2 var2;
stype3 var3;
stype4 var4;

在 C 端,我有一个接受任何类型的函数:

void send_sv_data(const char* type_name, void *ptr);

我希望在 SV 端像这样使用它:

send_sv_data("stype1", var1);
send_sv_data("stype2", var2);

而且它通常可以工作,唯一的问题是 SystemVerilog 不支持重载。所以我只能为一种类型声明它:

import "DPI" function void  send_sv_data(string port_name, stype1 data);

我试图将 chandle 作为论据:

 import "DPI" function void  send_sv_data(string port_name, chandle data);

但是我还没有找到一种方法如何将结构类型的变量转换为 chandle。

4

1 回答 1

2

SystemVerilog 中没有指针,也没有指针转换。最简单的做法是将您的 SystemVerilog 结构打包到一个字节数组中,然后将它们解包到您的 C 结构中。

于 2019-06-18T22:21:20.133 回答