4、linux环境下,使用VCS进行Verilog和C语言联编译


`timescale 1ns / 1ns
module test;

  initial
    begin
      $hello;
//      #10 $stop;
      #10 $finish;
    end
endmodule
/**********************************************************************/

文件名为hello_test.v



#include <stdlib.h>    /* ANSI C standard library */
#include <stdio.h>     /* ANSI C standard input/output library */
#include <stdarg.h>    /* ANSI C standard arguments library */
#include "vpi_user.h"  /* IEEE 1364 PLI VPI routine library  */

/**********************************************************************
 * calltf routine
 *********************************************************************/
PLI_INT32 PLIbook_hello_calltf(PLI_BYTE8 *user_data)
{
  vpi_printf("\nHello World!\n\n");
  return(0);
}

/**********************************************************************
 * $hello Registration Data
 * (add this function name to the vlog_startup_routines array)
 *********************************************************************/
void PLIbook_hello_register()
{
  s_vpi_systf_data tf_data;

  tf_data.type        = vpiSysTask;
  tf_data.sysfunctype = 0;
  tf_data.tfname      = "$hello";
  tf_data.calltf      = PLIbook_hello_calltf;
  tf_data.compiletf   = NULL;
  tf_data.sizetf      = NULL;
  tf_data.user_data   = NULL;
  vpi_register_systf(&tf_data);
}

文件名为hello_vpi.c



#include "vpi_user.h"

/* prototypes of the PLI registration routines */
extern void PLIbook_hello_register();

void (*vlog_startup_routines[])() = 
{
    /*** add user entries here ***/
  PLIbook_hello_register,
  0 /*** final entry must be 0 ***/
};

文件名为 vpi_user.c

进行VCS编译 执行

gcc -m32 vpi_user.c hello_vpi.c -fPIC -shared -o hello.so
vcs +cli+3 +vpi -R -load ./hello.so:PLIbook_hello_register ./hello_test.v

进行NCverilog编译 执行

gcc -m32 vpi_user.c hello_vpi.c -fPIC -shared -o hello.so
ncverilog +access+r -loadvpi ./hello.so:PLIbook_hello_register ./hello_test.v

前提:存在vpi_user.h文件 》》》》github存在 https://github.com/steveicarus/iverilog (缺失的两个文件都在这里面,另一个文件去掉多余的后缀.in 就可以)

猜你喜欢

转载自blog.csdn.net/sxj731533730/article/details/87987307