From 15082a178beaa7dab6ec11f0a11ef1c9a33976c1 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Thu, 9 Feb 2017 07:43:43 -0500 Subject: [PATCH] Add -FI option to force includes,msg2146. --- Changes | 2 ++ bin/verilator | 9 +++++++++ src/V3EmitCSyms.cpp | 7 +------ src/V3File.cpp | 7 +++++++ src/V3File.h | 7 ++++++- src/V3Options.cpp | 12 +++++++++-- src/V3Options.h | 3 +++ test_regress/t/t_flag_fi.cpp | 39 ++++++++++++++++++++++++++++++++++++ test_regress/t/t_flag_fi.pl | 24 ++++++++++++++++++++++ test_regress/t/t_flag_fi.v | 14 +++++++++++++ test_regress/t/t_flag_fi_h.h | 16 +++++++++++++++ 11 files changed, 131 insertions(+), 9 deletions(-) create mode 100644 test_regress/t/t_flag_fi.cpp create mode 100755 test_regress/t/t_flag_fi.pl create mode 100644 test_regress/t/t_flag_fi.v create mode 100644 test_regress/t/t_flag_fi_h.h diff --git a/Changes b/Changes index 74722c4d0..77161b5a7 100644 --- a/Changes +++ b/Changes @@ -5,6 +5,8 @@ The contributors that suggested a given feature are shown in []. Thanks! * Verilator 3.901 devel +** Add -FI option to force includes,msg2146. [Amir Gonnen] + **** Fix 2009 localparam syntax, msg2139. [Galen Seitz] diff --git a/bin/verilator b/bin/verilator index 466cb9061..abe8359a0 100755 --- a/bin/verilator +++ b/bin/verilator @@ -280,6 +280,7 @@ descriptions in the next sections for more information. --exe Link to create executable -F Parse options from a file, relatively -f Parse options from a file + -FI Force include of a file -G= Overwrite toplevel parameter --gdb Run Verilator under GDB interactively --gdbbt Run Verilator under GDB for backtrace @@ -704,6 +705,14 @@ The file may contain // comments which are ignored to the end of the line. Any $VAR, $(VAR), or ${VAR} will be replaced with the specified environment variable. +=item -FI + +Force include of the specified C++ header file. All generated C++ files +will insert a #include of the specified file before any other includes. The +specified file might be used to contain define prototypes of custom +VL_VPRINTF functions, and may need to include verilatedos.h as this file is +included before any other standard includes. + =item -GI=I Overwrites the given parameter of the toplevel module. The value is limited diff --git a/src/V3EmitCSyms.cpp b/src/V3EmitCSyms.cpp index c7a47f671..6e861a940 100644 --- a/src/V3EmitCSyms.cpp +++ b/src/V3EmitCSyms.cpp @@ -270,12 +270,7 @@ void EmitCSyms::emitSymHdr() { puts("#define _"+symClassName()+"_H_\n"); puts("\n"); - if (optSystemPerl()) puts("#include \"systemperl.h\"\n"); - else if (optSystemC()) puts("#include \"systemc.h\"\n"); - - if (optSystemPerl() || optSystemC()) { - puts("#include \"verilated_sc.h\"\n"); - } + ofp()->putsIntTopInclude(); if (v3Global.needHeavy()) { puts("#include \"verilated_heavy.h\"\n"); } else { diff --git a/src/V3File.cpp b/src/V3File.cpp index f3b2ae5d7..2ad8db3cb 100644 --- a/src/V3File.cpp +++ b/src/V3File.cpp @@ -841,3 +841,10 @@ V3OutFile::~V3OutFile() { if (m_fp) fclose(m_fp); m_fp = NULL; } + +void V3OutFile::putsForceIncs() { + const V3StringList& forceIncs = v3Global.opt.forceIncs(); + for (V3StringList::const_iterator it = forceIncs.begin(); it != forceIncs.end(); ++it) { + puts("#include \""+*it+"\"\n"); + } +} diff --git a/src/V3File.h b/src/V3File.h index eff3fc13c..c0d36aba7 100644 --- a/src/V3File.h +++ b/src/V3File.h @@ -173,6 +173,7 @@ class V3OutFile : public V3OutFormatter { public: V3OutFile(const string& filename, V3OutFormatter::Language lang); virtual ~V3OutFile(); + void putsForceIncs(); private: // CALLBACKS virtual void putcOutput(char chr) { fputc(chr, m_fp); } @@ -193,7 +194,9 @@ public: this->printf("%-19s\t%s;\n", classStar.c_str(), cellname.c_str()); } virtual void putsHeader() { puts("// Verilated -*- C++ -*-\n"); } - virtual void putsIntTopInclude() { } + virtual void putsIntTopInclude() { + putsForceIncs(); + } // Print out public/privates void resetPrivate() { m_private = 0; } void putsPrivate(bool setPrivate) { @@ -213,6 +216,7 @@ public: virtual ~V3OutScFile() {} virtual void putsHeader() { puts("// Verilated -*- SystemC -*-\n"); } virtual void putsIntTopInclude() { + putsForceIncs(); puts("#include \"systemc.h\"\n"); puts("#include \"verilated_sc.h\"\n"); } @@ -224,6 +228,7 @@ public: virtual ~V3OutSpFile() {} virtual void putsHeader() { puts("// Verilated -*- SystemC -*-\n"); } virtual void putsIntTopInclude() { + putsForceIncs(); puts("#include \"systemperl.h\"\n"); puts("#include \"verilated_sc.h\"\n"); } diff --git a/src/V3Options.cpp b/src/V3Options.cpp index 1a7ce2e0e..eecc61b00 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -229,6 +229,10 @@ void V3Options::addVFile(const string& filename) { // in a specific order and multiple of them. m_vFiles.push_back(filename); } +void V3Options::addForceInc(const string& filename) { + m_forceIncs.push_back(filename); +} + void V3Options::addArg(const string& arg) { m_impp->m_allArgs.push_back(arg); } @@ -795,11 +799,15 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char shift; V3Error::errorLimit(atoi(argv[i])); } + else if ( !strcmp (sw, "-FI") && (i+1)= DebugSrcMap m_dumpTrees; // argument: --dump-treei-= map m_parameters; // Parameters @@ -199,6 +200,7 @@ class V3Options { void addClocker(const string& signame); void addNoClocker(const string& signame); void addVFile(const string& filename); + void addForceInc(const string& filename); // ACCESSORS (options) bool preprocOnly() const { return m_preprocOnly; } @@ -282,6 +284,7 @@ class V3Options { const V3StringSet& ldLibs() const { return m_ldLibs; } const V3StringSet& libraryFiles() const { return m_libraryFiles; } const V3StringList& vFiles() const { return m_vFiles; } + const V3StringList& forceIncs() const { return m_forceIncs; } const V3LangCode& defaultLanguage() const { return m_defaultLanguage; } bool hasParameter(string name); diff --git a/test_regress/t/t_flag_fi.cpp b/test_regress/t/t_flag_fi.cpp new file mode 100644 index 000000000..9f0868a8e --- /dev/null +++ b/test_regress/t/t_flag_fi.cpp @@ -0,0 +1,39 @@ +// -*- mode: C++; c-file-style: "cc-mode" -*- +// +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed into the Public Domain, for any use, +// without warranty, 2017 by Wilson Snyder. + +#include +#include "Vt_flag_fi.h" + +//====================================================================== + +unsigned int main_time = 0; + +double sc_time_stamp () { + return main_time; +} + +VM_PREFIX* topp = NULL; +bool gotit = false; + +void myfunction() { + gotit = true; +} + +int main (int argc, char *argv[]) { + topp = new VM_PREFIX; + + Verilated::debug(0); + + topp->eval(); + if (!gotit) { + vl_fatal (__FILE__, __LINE__, "dut", "Never got call to myfunction"); + } + + topp->final(); + + return 0; +} diff --git a/test_regress/t/t_flag_fi.pl b/test_regress/t/t_flag_fi.pl new file mode 100755 index 000000000..4191f83b6 --- /dev/null +++ b/test_regress/t/t_flag_fi.pl @@ -0,0 +1,24 @@ +#!/usr/bin/perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2003 by Wilson Snyder. This program is free software; you can +# redistribute it and/or modify it under the terms of either the GNU +# Lesser General Public License Version 3 or the Perl Artistic License +# Version 2.0. + +$Self->{vlt} or $Self->skip("Verilator only test"); + +compile ( + make_top_shell => 0, + make_main => 0, + v_flags2 => ["-FI $Self->{t_dir}/t_flag_fi_h.h", + "--exe $Self->{t_dir}/$Self->{name}.cpp"], + ); + +execute ( + check_finished=>1, + ); + +ok(1); +1; diff --git a/test_regress/t/t_flag_fi.v b/test_regress/t/t_flag_fi.v new file mode 100644 index 000000000..5ff06341e --- /dev/null +++ b/test_regress/t/t_flag_fi.v @@ -0,0 +1,14 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// Copyright 2017 by Wilson Snyder. This program is free software; you can +// redistribute it and/or modify it under the terms of either the GNU +// Lesser General Public License Version 3 or the Perl Artistic License +// Version 2.0. + +module t (); + initial begin + $c("myfunction();"); + $write("*-* All Finished *-*\n"); + $finish; + end +endmodule diff --git a/test_regress/t/t_flag_fi_h.h b/test_regress/t/t_flag_fi_h.h new file mode 100644 index 000000000..3bbbeb84d --- /dev/null +++ b/test_regress/t/t_flag_fi_h.h @@ -0,0 +1,16 @@ +// -*- mode: C++; c-file-style: "cc-mode" -*- +//************************************************************************* +// +// Copyright 2010-2017 by Wilson Snyder. This program is free software; you can +// redistribute it and/or modify it under the terms of either the GNU +// Lesser General Public License Version 3 or the Perl Artistic License. +// Version 2.0. +// +// Verilator is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +//************************************************************************* + +extern void myfunction();