Fix missing var access functions when no DPI, bug572.

This commit is contained in:
Wilson Snyder 2012-10-30 03:02:35 -04:00
parent dce227684a
commit 7ef37d6e17
4 changed files with 27 additions and 9 deletions

View File

@ -11,6 +11,8 @@ indicates the contributor was also the author of the fix; Thanks!
**** Fix $display mangling on GCC 4.7, msg927. [R Diez] **** Fix $display mangling on GCC 4.7, msg927. [R Diez]
**** Fix missing var access functions when no DPI, bug572. [Amir Gonnen]
* Verilator 3.841 2012/09/03 * Verilator 3.841 2012/09/03

View File

@ -115,8 +115,8 @@ class EmitCSyms : EmitCBaseVisitor {
AstScope* scopep = it->first; AstNodeModule* smodp = it->second; AstScope* scopep = it->first; AstNodeModule* smodp = it->second;
for (vector<ModVarPair>::iterator it = m_modVars.begin(); it != m_modVars.end(); ++it) { for (vector<ModVarPair>::iterator it = m_modVars.begin(); it != m_modVars.end(); ++it) {
AstNodeModule* modp = it->first; AstNodeModule* modp = it->first;
AstVar* varp = it->second;
if (modp == smodp) { if (modp == smodp) {
AstVar* varp = it->second;
// Need to split the module + var name into the original-ish full scope and variable name under that scope. // Need to split the module + var name into the original-ish full scope and variable name under that scope.
// The module instance name is included later, when we know the scopes this module is under // The module instance name is included later, when we know the scopes this module is under
string whole = scopep->name()+"__DOT__"+varp->name(); string whole = scopep->name()+"__DOT__"+varp->name();
@ -204,7 +204,8 @@ class EmitCSyms : EmitCBaseVisitor {
} }
virtual void visit(AstVar* nodep, AstNUser*) { virtual void visit(AstVar* nodep, AstNUser*) {
nodep->iterateChildren(*this); nodep->iterateChildren(*this);
if (nodep->isSigUserRdPublic()) { if (nodep->isSigUserRdPublic()
&& !nodep->isParam()) { // The VPI functions require a pointer to allow modification, but parameters are constants
m_modVars.push_back(make_pair(m_modp, nodep)); m_modVars.push_back(make_pair(m_modp, nodep));
} }
} }

View File

@ -1488,7 +1488,7 @@ non_port_module_item<nodep>: // ==IEEE: non_port_module_item
| yaSCDTOR { $$ = new AstScDtor($<fl>1,*$1); } | yaSCDTOR { $$ = new AstScDtor($<fl>1,*$1); }
| yVL_INLINE_MODULE { $$ = new AstPragma($1,AstPragmaType::INLINE_MODULE); } | yVL_INLINE_MODULE { $$ = new AstPragma($1,AstPragmaType::INLINE_MODULE); }
| yVL_NO_INLINE_MODULE { $$ = new AstPragma($1,AstPragmaType::NO_INLINE_MODULE); } | yVL_NO_INLINE_MODULE { $$ = new AstPragma($1,AstPragmaType::NO_INLINE_MODULE); }
| yVL_PUBLIC_MODULE { $$ = new AstPragma($1,AstPragmaType::PUBLIC_MODULE); } | yVL_PUBLIC_MODULE { $$ = new AstPragma($1,AstPragmaType::PUBLIC_MODULE); v3Global.dpi(true); }
; ;
module_or_generate_item<nodep>: // ==IEEE: module_or_generate_item module_or_generate_item<nodep>: // ==IEEE: module_or_generate_item
@ -1745,11 +1745,11 @@ sigAttrList<nodep>:
sigAttr<nodep>: sigAttr<nodep>:
yVL_CLOCK { $$ = new AstAttrOf($1,AstAttrType::VAR_CLOCK); } yVL_CLOCK { $$ = new AstAttrOf($1,AstAttrType::VAR_CLOCK); }
| yVL_CLOCK_ENABLE { $$ = new AstAttrOf($1,AstAttrType::VAR_CLOCK_ENABLE); } | yVL_CLOCK_ENABLE { $$ = new AstAttrOf($1,AstAttrType::VAR_CLOCK_ENABLE); }
| yVL_PUBLIC { $$ = new AstAttrOf($1,AstAttrType::VAR_PUBLIC); } | yVL_PUBLIC { $$ = new AstAttrOf($1,AstAttrType::VAR_PUBLIC); v3Global.dpi(true); }
| yVL_PUBLIC_FLAT { $$ = new AstAttrOf($1,AstAttrType::VAR_PUBLIC_FLAT); } | yVL_PUBLIC_FLAT { $$ = new AstAttrOf($1,AstAttrType::VAR_PUBLIC_FLAT); v3Global.dpi(true); }
| yVL_PUBLIC_FLAT_RD { $$ = new AstAttrOf($1,AstAttrType::VAR_PUBLIC_FLAT_RD); } | yVL_PUBLIC_FLAT_RD { $$ = new AstAttrOf($1,AstAttrType::VAR_PUBLIC_FLAT_RD); v3Global.dpi(true); }
| yVL_PUBLIC_FLAT_RW { $$ = new AstAttrOf($1,AstAttrType::VAR_PUBLIC_FLAT_RW); } | yVL_PUBLIC_FLAT_RW { $$ = new AstAttrOf($1,AstAttrType::VAR_PUBLIC_FLAT_RW); v3Global.dpi(true); }
| yVL_PUBLIC_FLAT_RW attr_event_control { $$ = new AstAttrOf($1,AstAttrType::VAR_PUBLIC_FLAT_RW); | yVL_PUBLIC_FLAT_RW attr_event_control { $$ = new AstAttrOf($1,AstAttrType::VAR_PUBLIC_FLAT_RW); v3Global.dpi(true);
$$ = $$->addNext(new AstAlwaysPublic($1,$2,NULL)); } $$ = $$->addNext(new AstAlwaysPublic($1,$2,NULL)); }
| yVL_ISOLATE_ASSIGNMENTS { $$ = new AstAttrOf($1,AstAttrType::VAR_ISOLATE_ASSIGNMENTS); } | yVL_ISOLATE_ASSIGNMENTS { $$ = new AstAttrOf($1,AstAttrType::VAR_ISOLATE_ASSIGNMENTS); }
| yVL_SC_BV { $$ = new AstAttrOf($1,AstAttrType::VAR_SC_BV); } | yVL_SC_BV { $$ = new AstAttrOf($1,AstAttrType::VAR_SC_BV); }
@ -2540,7 +2540,7 @@ tf_item_declaration<nodep>: // ==IEEE: tf_item_declaration
; ;
tf_item_declarationVerilator<nodep>: // Verilator extensions tf_item_declarationVerilator<nodep>: // Verilator extensions
yVL_PUBLIC { $$ = new AstPragma($1,AstPragmaType::PUBLIC_TASK); } yVL_PUBLIC { $$ = new AstPragma($1,AstPragmaType::PUBLIC_TASK); v3Global.dpi(true); }
| yVL_NO_INLINE_TASK { $$ = new AstPragma($1,AstPragmaType::NO_INLINE_TASK); } | yVL_NO_INLINE_TASK { $$ = new AstPragma($1,AstPragmaType::NO_INLINE_TASK); }
; ;

View File

@ -5,12 +5,23 @@
// Lesser General Public License Version 3 or the Perl Artistic License // Lesser General Public License Version 3 or the Perl Artistic License
// Version 2.0. // Version 2.0.
`ifdef VERILATOR
//We call it via $c so we can verify DPI isn't required - see bug572
`else
import "DPI-C" context function integer mon_check(); import "DPI-C" context function integer mon_check();
`endif
module t (/*AUTOARG*/ module t (/*AUTOARG*/
// Inputs // Inputs
clk clk
); );
`ifdef VERILATOR
`systemc_header
extern "C" int mon_check();
`verilog
`endif
input clk; input clk;
reg onebit /*verilator public_flat_rw @(posedge clk) */; reg onebit /*verilator public_flat_rw @(posedge clk) */;
@ -29,7 +40,11 @@ module t (/*AUTOARG*/
// Test loop // Test loop
initial begin initial begin
onebit = 1'b0; onebit = 1'b0;
`ifdef VERILATOR
status = $c32("mon_check()");
`else
status = mon_check(); status = mon_check();
`endif
if (status!=0) begin if (status!=0) begin
$write("%%Error: t_vpi_var.cpp:%0d: C Test failed\n", status); $write("%%Error: t_vpi_var.cpp:%0d: C Test failed\n", status);
$stop; $stop;