Add --vpi flag, and fix VPI linkage, bug969.

This commit is contained in:
Wilson Snyder 2015-09-25 22:57:28 -04:00
parent 34870e899f
commit 9a16001e51
15 changed files with 1095 additions and 1052 deletions

View File

@ -5,6 +5,8 @@ indicates the contributor was also the author of the fix; Thanks!
* Verilator 3.877 devel
** Add --vpi flag, and fix VPI linkage, bug969. [Arthur Kahlich]
**** Add VerilatedScopeNameMap for introspection, bug966. [Todd Strader]
**** Fix very long module names, bug937. [Todd Strader]

View File

@ -331,6 +331,7 @@ descriptions in the next sections for more information.
-v <filename> Verilog library
+verilog1995ext+<ext> Synonym for +1364-1995ext+<ext>
+verilog2001ext+<ext> Synonym for +1364-2001ext+<ext>
--vpi Enable VPI compiles
-Werror-<message> Convert warning to error
-Wfuture-<message> Disable unknown message warnings
-Wno-<message> Disable warning
@ -1103,6 +1104,10 @@ Note -v is fairly standard across Verilog tools.
Synonyms for C<+1364-1995ext+>I<ext> and C<+1364-2001ext+>I<ext> respectively
=item --vpi
Enable use of VPI and linking against the verilated_vpi.cpp files.
=item -Wall
Enable all warnings, including code style warnings that are normally
@ -1802,6 +1807,8 @@ Verilator supports a very limited subset of the VPI. This subset allows
inspection, examination, value change callbacks, and depositing of values
to public signals only.
VPI is enabled with the verilator --vpi switch.
To access signals via the VPI, Verilator must be told exactly which signals
are to be accessed. This is done using the Verilator public pragmas
documented below.
@ -1835,17 +1842,28 @@ changed on the specified clock edge.
There are many online tutorials and books on the VPI, but an example that
accesses the above would be:
void read_and_check() {
vpiHandle vh1 = vpi_handle_by_name((PLI_BYTE8*)"t.readme", NULL);
if (!vh1) { error... }
const char* name = vpi_get_str(vpiName, vh1);
printf("Module name: %s\n"); // Prints "readme"
void read_and_check() {
vpiHandle vh1 = vpi_handle_by_name((PLI_BYTE8*)"t.readme", NULL);
if (!vh1) { error... }
const char* name = vpi_get_str(vpiName, vh1);
printf("Module name: %s\n"); // Prints "readme"
s_vpi_value v;
v.format = vpiIntVal;
vpi_get_value(vh1, &v);
printf("Value of v: %d\n", v.value.integer); // Prints "readme"
}
s_vpi_value v;
v.format = vpiIntVal;
vpi_get_value(vh1, &v);
printf("Value of v: %d\n", v.value.integer); // Prints "readme"
}
For signal callbacks to work the main loop of the program must call
VerilatedVpi::callValueCbs().
#include "verilated_vpi.h" // Required to get definitions
...
while (time passes) {
...
topp->eval();
VerilatedVpi::callValueCbs();
}
=head1 CROSS COMPILATION

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -81,6 +81,9 @@ public:
if (v3Global.dpi()) {
putMakeClassEntry(of, "verilated_dpi.cpp");
}
if (v3Global.opt.vpi()) {
putMakeClassEntry(of, "verilated_vpi.cpp");
}
if (v3Global.opt.savable()) {
putMakeClassEntry(of, "verilated_save.cpp");
}

View File

@ -672,6 +672,7 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char
else if ( onoff (sw, "-trace-structs", flag/*ref*/) ) { m_traceStructs = flag; }
else if ( onoff (sw, "-trace-underscore", flag/*ref*/) ) { m_traceUnderscore = flag; }
else if ( onoff (sw, "-underline-zero", flag/*ref*/) ) { m_underlineZero = flag; } // Undocumented, old Verilator-2
else if ( onoff (sw, "-vpi", flag/*ref*/) ) { m_vpi = flag; }
else if ( onoff (sw, "-x-initial-edge", flag/*ref*/) ) { m_xInitialEdge = flag; }
else if ( onoff (sw, "-xml-only", flag/*ref*/) ) { m_xmlOnly = flag; } // Undocumented, still experimental
// Optimization
@ -1154,6 +1155,7 @@ V3Options::V3Options() {
m_preprocOnly = false;
m_preprocNoLine = false;
m_public = false;
m_reportUnoptflat = false;
m_savable = false;
m_skipIdentical = true;
m_stats = false;
@ -1166,7 +1168,7 @@ V3Options::V3Options() {
m_traceStructs = false;
m_traceUnderscore = false;
m_underlineZero = false;
m_reportUnoptflat = false;
m_vpi = false;
m_xInitialEdge = false;
m_xmlOnly = false;

View File

@ -85,6 +85,7 @@ class V3Options {
bool m_pinsUint8; // main switch: --pins-uint8
bool m_profileCFuncs;// main switch: --profile-cfuncs
bool m_public; // main switch: --public
bool m_reportUnoptflat; // main switch: --report-unoptflat
bool m_savable; // main switch: --savable
bool m_systemC; // main switch: --sc: System C instead of simple C++
bool m_skipIdentical;// main switch: --skip-identical
@ -97,7 +98,7 @@ class V3Options {
bool m_traceStructs; // main switch: --trace-structs
bool m_traceUnderscore;// main switch: --trace-underscore
bool m_underlineZero;// main switch: --underline-zero; undocumented old Verilator 2
bool m_reportUnoptflat; // main switch: --report-unoptflat
bool m_vpi; // main switch: --vpi
bool m_xInitialEdge; // main switch: --x-initial-edge
bool m_xmlOnly; // main switch: --xml-netlist
@ -239,6 +240,7 @@ class V3Options {
bool ignc() const { return m_ignc; }
bool inhibitSim() const { return m_inhibitSim; }
bool reportUnoptflat() const { return m_reportUnoptflat; }
bool vpi() const { return m_vpi; }
bool xInitialEdge() const { return m_xInitialEdge; }
bool xmlOnly() const { return m_xmlOnly; }

View File

@ -27,7 +27,6 @@
#include "Vt_vpi_get__Dpi.h"
#include "verilated_vpi.h"
#include "verilated_vpi.cpp"
#include "verilated_vcd_c.h"
#endif

View File

@ -10,7 +10,7 @@ if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); di
compile (
make_top_shell => 0,
make_main => 0,
verilator_flags2 => ["-CFLAGS '-DVL_DEBUG -ggdb' --exe --no-l2name $Self->{t_dir}/t_vpi_get.cpp"],
verilator_flags2 => ["-CFLAGS '-DVL_DEBUG -ggdb' --exe --vpi --no-l2name $Self->{t_dir}/t_vpi_get.cpp"],
make_pli => 1,
iv_flags2 => ["-g2005-sv -D USE_VPI_NOT_DPI"],
v_flags2 => ["+define+USE_VPI_NOT_DPI"],

View File

@ -27,7 +27,6 @@
#include "Vt_vpi_memory__Dpi.h"
#include "verilated_vpi.h"
#include "verilated_vpi.cpp"
#include "verilated_vcd_c.h"
#endif

View File

@ -13,7 +13,7 @@ compile (
make_pli => 1,
iv_flags2 => ["-g2005-sv -D USE_VPI_NOT_DPI"],
v_flags2 => ["+define+USE_VPI_NOT_DPI"],
verilator_flags2 => ["-CFLAGS '-DVL_DEBUG -ggdb' --exe --no-l2name $Self->{t_dir}/t_vpi_memory.cpp"],
verilator_flags2 => ["-CFLAGS '-DVL_DEBUG -ggdb' --exe --vpi --no-l2name $Self->{t_dir}/t_vpi_memory.cpp"],
);
execute (

View File

@ -19,9 +19,8 @@
#include "Vt_vpi_unimpl__Dpi.h"
#include "verilated_vpi.h"
#include "verilated_vpi.cpp"
#include "verilated_vcd_c.h"
// No verilated_vpi.h, make sure can link without it
#include <iostream>
@ -174,7 +173,7 @@ int main(int argc, char **argv, char **env) {
while (sc_time_stamp() < sim_time && !Verilated::gotFinish()) {
main_time += 1;
topp->eval();
VerilatedVpi::callValueCbs();
//VerilatedVpi::callValueCbs(); // Make sure can link without verilated_vpi.h included
topp->clk = !topp->clk;
//mon_do();
#if VM_TRACE

View File

@ -10,7 +10,7 @@ if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); di
compile (
make_top_shell => 0,
make_main => 0,
verilator_flags2 => ["-CFLAGS '-DVL_DEBUG -ggdb' --exe --no-l2name $Self->{t_dir}/t_vpi_unimpl.cpp"],
verilator_flags2 => ["-CFLAGS '-DVL_DEBUG -ggdb' --exe --vpi --no-l2name $Self->{t_dir}/t_vpi_unimpl.cpp"],
);
execute (

View File

@ -26,7 +26,6 @@
#include "Vt_vpi_var__Dpi.h"
#include "verilated_vpi.h"
#include "verilated_vpi.cpp"
#include "verilated_vcd_c.h"
#endif
@ -550,47 +549,6 @@ int _mon_check_vlog_info() {
return 0;
}
#ifndef IS_VPI
#define CHECK_ENUM_STR(fn, enum) \
do { \
const char* strVal = VerilatedVpiError::fn(enum); \
CHECK_RESULT_CSTR(strVal, #enum); \
} while (0)
int _mon_check_vl_str() {
CHECK_ENUM_STR(strFromVpiVal, vpiBinStrVal);
CHECK_ENUM_STR(strFromVpiVal, vpiRawFourStateVal);
CHECK_ENUM_STR(strFromVpiObjType, vpiAlways);
CHECK_ENUM_STR(strFromVpiObjType, vpiWhile);
CHECK_ENUM_STR(strFromVpiObjType, vpiAttribute);
CHECK_ENUM_STR(strFromVpiObjType, vpiUdpArray);
CHECK_ENUM_STR(strFromVpiObjType, vpiContAssignBit);
CHECK_ENUM_STR(strFromVpiObjType, vpiGenVar);
CHECK_ENUM_STR(strFromVpiMethod, vpiCondition);
CHECK_ENUM_STR(strFromVpiMethod, vpiStmt);
CHECK_ENUM_STR(strFromVpiCallbackReason, cbValueChange);
CHECK_ENUM_STR(strFromVpiCallbackReason, cbAtEndOfSimTime);
CHECK_ENUM_STR(strFromVpiProp, vpiType);
CHECK_ENUM_STR(strFromVpiProp, vpiProtected);
CHECK_ENUM_STR(strFromVpiProp, vpiDirection);
CHECK_ENUM_STR(strFromVpiProp, vpiTermIndex);
CHECK_ENUM_STR(strFromVpiProp, vpiConstType);
CHECK_ENUM_STR(strFromVpiProp, vpiAutomatic);
CHECK_ENUM_STR(strFromVpiProp, vpiOffset);
CHECK_ENUM_STR(strFromVpiProp, vpiStop);
CHECK_ENUM_STR(strFromVpiProp, vpiIsProtected);
return 0;
}
#endif
int mon_check() {
// Callback from initial block in monitor
if (int status = _mon_check_mcd()) return status;
@ -604,7 +562,7 @@ int mon_check() {
if (int status = _mon_check_putget_str(NULL)) return status;
if (int status = _mon_check_vlog_info()) return status;
#ifndef IS_VPI
if (int status = _mon_check_vl_str()) return status;
VerilatedVpiError::selfTest();
#endif
return 0; // Ok
}

View File

@ -14,7 +14,7 @@ compile (
sim_time => 2100,
iv_flags2 => ["-g2005-sv -D USE_VPI_NOT_DPI -DWAVES"],
v_flags2 => ["+define+USE_VPI_NOT_DPI"],
verilator_flags2 => ["-CFLAGS '-DVL_DEBUG -ggdb' --exe --no-l2name $Self->{t_dir}/t_vpi_var.cpp"],
verilator_flags2 => ["-CFLAGS '-DVL_DEBUG -ggdb' --exe --vpi --no-l2name $Self->{t_dir}/t_vpi_var.cpp"],
);
execute (