Add -FI option to force includes,msg2146.

This commit is contained in:
Wilson Snyder 2017-02-09 07:43:43 -05:00
parent 4a0db26c36
commit 15082a178b
11 changed files with 131 additions and 9 deletions

View File

@ -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]

View File

@ -280,6 +280,7 @@ descriptions in the next sections for more information.
--exe Link to create executable
-F <file> Parse options from a file, relatively
-f <file> Parse options from a file
-FI <file> Force include of a file
-G<name>=<value> 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 <file>
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<name>=I<value>
Overwrites the given parameter of the toplevel module. The value is limited

View File

@ -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 {

View File

@ -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");
}
}

View File

@ -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");
}

View File

@ -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)<argc ) {
shift;
addForceInc(parseFileArg(optdir, string (argv[i])));
}
else if ( !strncmp (sw, "-G", strlen("-G"))) {
addParameter (string (sw+strlen("-G")), false);
addParameter(string (sw+strlen("-G")), false);
}
else if ( !strncmp (sw, "-I", 2)) {
addIncDirUser (parseFileArg(optdir, string (sw+strlen("-I"))));
addIncDirUser(parseFileArg(optdir, string (sw+strlen("-I"))));
}
else if ( !strcmp (sw, "-if-depth") && (i+1)<argc ) {
shift;

View File

@ -56,6 +56,7 @@ class V3Options {
V3StringSet m_clockers; // argument: Verilog -clk signals
V3StringSet m_noClockers; // argument: Verilog -noclk signals
V3StringList m_vFiles; // argument: Verilog files to read
V3StringList m_forceIncs; // argument: -FI
DebugSrcMap m_debugSrcs; // argument: --debugi-<srcfile>=<level>
DebugSrcMap m_dumpTrees; // argument: --dump-treei-<srcfile>=<level>
map<string,string> 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);

View File

@ -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 <verilated.h>
#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;
}

24
test_regress/t/t_flag_fi.pl Executable file
View File

@ -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;

View File

@ -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

View File

@ -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();