Som*_*ing 4 c system-verilog synopsys-vcs system-verilog-dpi
我有以下文件:
带有功能的C文件:
// funcs.c
#include <stdio.h>
void something() {
printf("something\n");
sayHello();
}
Run Code Online (Sandbox Code Playgroud)
系统verilog文件:
// hello_world.v
module kuku;
export "DPI-C" function sayHello;
import "DPI-C" function void something();
initial something();
function int sayHello ();
$display("hello world");
sayHello = 1;
endfunction
endmodule
Run Code Online (Sandbox Code Playgroud)
如何编译它并使其工作,所以当我something()从SV 调用时,它将调用C函数,当我sayHello()从C 调用时,它将调用SV函数?
回答我自己:
当使用VCS编译SV代码时,首先将其转换为C代码.
当exporting一个函数退出SV时,它会生成一个vc_hdrs.h应该包含在C文件中的C头文件.
所以我在C文件中做的更改是添加行:
#include "vc_hdrs.h"
Run Code Online (Sandbox Code Playgroud)
然后,我刚刚将C函数文件添加到VCS编译命令:
> vcs -sverilog hello_world.v funcs.c
Run Code Online (Sandbox Code Playgroud)
有用!
我得到的输出是:
something
hello world
Run Code Online (Sandbox Code Playgroud)