Project

General

Profile

[logo] 
 
Home
News
Activity
About/Contact
Major Tools
  Dinotrace
  Verilator
  Verilog-mode
  Verilog-Perl
Other Tools
  IPC::Locker
  Parallel::Forker
  Voneline
General Info
  Papers

Issue #1598

Problems attempting to redefine VL_PRINTF

Added by Julien Margetts 26 days ago. Updated 7 days ago.

Status:
Closed
Priority:
Low
Category:
Documentation
% Done:

0%


Description

I need my verilated model to call something other than printf to perform output $display, and the intended way to do that (according to verilated.h) appears to be to re-define VL_PRINTF

However doing so seems to cause a number of unexpected warnings. It is also unclear what the proper approach should be to make the verilator generated make file 'aware' of the declaration of my new output function (I.e. how do I tell verilator to put "#include "my_printf.h" into the verilated output code)

I'm sure I'm making a schoolboy error here but any pointers would be helpful.

verilator -cc --exe -O3 -Wno-lint -Wno-UNOPTFLAT -Wno-COMBDLY -LDFLAGS "-fPIC --shared" --top-module xxxx_wrapper --unroll-count 150 -Mdir obj -CFLAGS "-fPIC -DVL_PRINTF=my_printf" +incdir+. -f ../core.flist --clk clk verilated_xxxx_wrapper.cpp -o ../verilated_xxxx_wrapper.so
make -s -j 4 -C obj OPT=-Os -f Vnvme_core_wrapper.mk 
make[2]: Entering directory `xxxxx/verilator/obj'
<command-line>:0:0: warning: "VL_PRINTF" redefined [enabled by default]
<command-line>:0:0: note: this is the location of the previous definition
<command-line>:0:0: warning: "VL_PRINTF" redefined [enabled by default]
<command-line>:0:0: note: this is the location of the previous definition
<command-line>:0:0: warning: "VL_PRINTF" redefined [enabled by default]
<command-line>:0:0: note: this is the location of the previous definition
<command-line>:0:0: warning: "VL_PRINTF" redefined [enabled by default]
<command-line>:0:0: note: this is the location of the previous definition
<command-line>:0:0: warning: "VL_PRINTF" redefined [enabled by default]
<command-line>:0:0: note: this is the location of the previous definition
In file included from /tools/verilator/verilator-4.018/include/verilated.cpp:29:0:
/tools/verilator/verilator-4.018/include/verilated_imp.h: In static member function ‘static void VerilatedImp::userDump()’:
/tools/verilator/verilator-4.018/include/verilated_imp.h:279:54: error: ‘my_printf’ was not declared in this scope
             if (first) { VL_PRINTF_MT("  userDump:\n"); first=false; }

NOTE: I can work around this by overiding printf itself (and not using -DVL_PRINTF=my_printf) by adding my own version of printf as a wrapper for my new output function to the verilator input files, but I would rather use -DVL_PRINTF=xxxx if that was the intended approach.

Issue1598.patch View (792 Bytes) Julien Margetts, 12/03/2019 12:01 PM

History

#1 Updated by Wilson Snyder 26 days ago

  • Description updated (diff)
  • Status changed from New to Confirmed

Originally VL_PRINTF was intended to be overridden in a .mk file which overrode the default verilator.mk file. For this reason VL_PRINTF is also defined in verilated.mk, hence the GCC warning about multiple definitions of it. That overriding also edited the make rules to insert a special #include.

What you are doing is perfectly reasonable, and probably a better way.

Please try removing VL_PRINTF from verilated.mk.in, and reinstall verilator (or just hack verilated.mk yourself.)

Then you have the missing definition problem... For that I'd suggest we add to the top of verilatedos.h

#ifdef VL_VERILATED_INCLUDE
# include VL_VERILATED_INCLUDE
#endif

then add -DVL_VERILATED_INCLUDE="foo"

If this all works out send a patch and I'll merge it upstream.

Thanks.

#2 Updated by Julien Margetts 26 days ago

Thanks for the pointers, I will persevere with that aproach and try and get a patch out ...

#3 Updated by Wilson Snyder 8 days ago

Did the redefinition etc work for you? if so, can you send back a patch of what worked out? Thanks.

#4 Updated by Julien Margetts 7 days ago

Just got round to this, yes, the attached patch works when combined with adding the following to the Verilator command line:

my_printf.cpp --CFLAGS '-DVL_PRINTF=my_printf -DVL_VERILATED_INCLUDE=\"my_printf.h\" -I..'

Thanks

PS: I included VL_VERILATED_INCLUDE in verilated.h rather than verilatedos.h since it seems a better fit (given it is intended only for verilated output, not the host side tool itself?)

#5 Updated by Wilson Snyder 7 days ago

Yes, that looks like a fine place. Do you agree this (and future so don't need to ask again) contributions are open sourced as per the Developer Certificate of Origin (https://developercertificate.org/)?

#6 Updated by Julien Margetts 7 days ago

Yes, Agreed

#7 Updated by Wilson Snyder 7 days ago

  • Status changed from Confirmed to Closed
  • Assignee set to Julien Margetts

Thanks for your work. Pushed to git towards eventual 4.024 release.

Also available in: Atom