D:\ccc101\Verilog\c>vvp -M. -mhello2 hello2.vvp
Hello, World!
Link C success!
Link C success!
原理解說
在 Using VPI — http://iverilog.wikia.com/wiki/Using_VPI 這篇文章中,記載了這個機製的運作原理,以下是我認為最重要的一段話:
The simulator run time (The "vvp" program) gets a handle on a freshly loaded module by looking for the symbol "vlog_startup_routines" in the loaded module. This table, provided by the module author and compiled into the module, is a null terminated table of function pointers. The simulator calls each of the functions in the table in order. The following simple C definition defines a sample table:
Note that the "vlog_startup_routines" table is an array of function pointers, with the last pointer a 0 to mark the end. The programmer can organize the module to include many startup functions in this table, if desired.