1.接上回,编译完veriwell,提取出静态库和头文件
2.在这个基础上进行HelloWorld编写,测试
hello_vpi.c
#include <stdio.h>
#include <stdlib.h>
#include <veriuser.h>
#include <acc_user.h>
char *veriuser_version_str = "Hello Test\n";
int myfun(int data, int reason);
s_tfcell veriusertfs[]={
{userfunction, 0, myfun, myfun, myfun, 0, "$hello"},
{0}
};
int myfun(int data, int reason)
{
printf("%d %d\n",data, reason);
return 0;
}
s_tfcell veriusertfs是个全局变量,在此处定义,在静态库中被引用,这个结构体定义如下
typedef struct t_tfcell {
short type; /* 函数类型,function还是task */
short data; /* 数据 */
int (*checktf) (int, int); /* routine for checking parameters */
int (*sizetf) (int, int); /* for providing size of function return value */
int (*calltf) (int, int); /* routine called during simulation */
int (*misctf) (int, int); /* miscellaneous routine (see below) */
char *tfname; /* the name of the system task or function */
int forwref; /* indicates special parameters allowed */
char *tfveritool; /* Which Veritool owns the task */
char *tferrmessage; /* An optional special case error message
which will be printed if the task is skipped */
/* these components are for system usage only */
int hash;
struct t_tfcell *left_p;
struct t_tfcell *right_p;
char *namecell_p;
int warning_printed; /* Flag is set when skipping warning is printed */
struct t_call_stats call_stats[18];
int statsInit;
} s_tfcell, *p_tfcell;
3.编写testbench
tb.v
module tb;
integer ret;
initial
ret = $hello(100);
endmodule
4.编译运行
g++ -o hello hello_vpi.c -I../myveri ../myveri/libveriwell.a
运行
./hello tb.v