Add --language option for supporting older code. [Stefan Thiede]

git-svn-id: file://localhost/svn/verilator/trunk/verilator@1015 77ca24e4-aefa-0310-84f0-b9a241c72d87
This commit is contained in:
Wilson Snyder 2008-03-28 20:41:21 +00:00
parent ebe5711b40
commit 280eb48ba4
7 changed files with 120 additions and 10 deletions

View File

@ -8,6 +8,8 @@ indicates the contributor was also the author of the fix; Thanks!
*** The --enable-defenv configure option added in 3.660 is now the default.
This hard-codes a default for VERILATOR_ROOT etc in the executables.
*** Add --language option for supporting older code. [Stefan Thiede]
*** Add --top-module option to select between multiple tops. [Stefan Thiede]
**** Fix SystemVerilog parameterized defines with `` expansion,

View File

@ -197,6 +197,7 @@ descriptions in the next sections for more information.
-I<dir> Directory to search for includes
--inhibit-sim Create function to turn off sim
--inline-mult <value> Tune module inlining
--language <lang> Language standard to parse
--lint-only Lint, but do not make output
--MMD Create .d dependency files
--MP Create phony dependency targets
@ -380,6 +381,14 @@ values, or a value <= 1 will inline everything, will lead to longer compile
times, but potentially faster runtimes. This setting is ignored for very
small modules; they will always be inlined, if allowed.
=item --language I<value>
Select the language to be used when first processing each Verilog file.
The language value must be "1364-1995", "1364-2001", "1364-2001",
"1364-2005", or "1800-2005". This should only be used for legacy code, as
the preferable option is to edit the code to repair new keywords, or add
appropriate `begin_keywords.
=item --lint-only
Check the files for lint violations only, do not create any other output.

View File

@ -118,6 +118,20 @@ string V3Options::allArgsString() {
return out;
}
//######################################################################
// Language class
V3LangCode::V3LangCode (const char* textp) {
// Return code for given string, or ERROR, which is a bad code
for (int codei=V3LangCode::ERROR; codei<V3LangCode::MAX; codei++) {
V3LangCode code = (V3LangCode)codei;
if (0==strcasecmp(textp,code.ascii())) {
m_e = code; return;
}
}
m_e = V3LangCode::ERROR;
}
//######################################################################
// File searching
@ -498,15 +512,6 @@ void V3Options::parseOptsList(FileLine* fl, int argc, char** argv) {
shift;
setDebugMode(atoi(argv[i]));
}
else if ( !strcmp (sw, "-v") ) {
shift;
V3Options::addLibraryFile(argv[i]);
}
else if ( !strcmp (sw, "-version") ) {
cout <<version();
cout <<endl;
exit(0);
}
else if ( !strcmp (sw, "-error-limit") ) {
shift;
m_inlineMult = atoi(argv[i]);
@ -515,6 +520,15 @@ void V3Options::parseOptsList(FileLine* fl, int argc, char** argv) {
shift;
m_inlineMult = atoi(argv[i]);
}
else if ( !strcmp (sw, "-language") ) {
shift;
V3LangCode optval = V3LangCode(argv[i]);
if (optval.legal()) {
m_language = optval;
} else {
fl->v3fatal("Unknown language specified: "<<argv[i]);
}
}
else if ( !strcmp (sw, "-output-split") ) {
shift;
m_outputSplit = atoi(argv[i]);
@ -535,6 +549,15 @@ void V3Options::parseOptsList(FileLine* fl, int argc, char** argv) {
shift;
m_unrollStmts = atoi(argv[i]);
}
else if ( !strcmp (sw, "-v") ) {
shift;
V3Options::addLibraryFile(argv[i]);
}
else if ( !strcmp (sw, "-version") ) {
cout <<version();
cout <<endl;
exit(0);
}
// Single switches
else if ( !strcmp (sw, "-E") ) { m_preprocOnly = true; }
else if ( onoff (sw, "-MMD", flag/*ref*/) ) { m_makeDepend = flag; }
@ -794,6 +817,8 @@ V3Options::V3Options() {
m_flags = "";
m_xAssign = "unique";
m_language = V3LangCode::mostRecent();
optimize(true);
// Default +libext+
addLibExt(""); // So include "filename.v" will find the same file

View File

@ -29,6 +29,41 @@
#include "V3Global.h"
//######################################################################
class V3LangCode {
public:
enum en {
ERROR, // Must be first.
L1364_1995,
L1364_2001,
L1364_2005,
L1800_2005,
// ***Add new elements below also***
MAX
};
const char* ascii() const {
const char* names[] = {
// These must match the `begin_keywords values.
" ERROR",
"1364-1995",
"1364-2001",
"1364-2005",
"1800-2005"
};
return names[m_e];
};
static V3LangCode mostRecent() { return V3LangCode(L1800_2005); }
bool legal() const { return m_e != ERROR; }
//
enum en m_e;
inline V3LangCode () : m_e(ERROR) {};
inline V3LangCode (en _e) : m_e(_e) {};
V3LangCode (const char* textp); // Return matching code or ERROR
explicit inline V3LangCode (int _e) : m_e(static_cast<en>(_e)) {};
operator en () const { return m_e; };
};
//######################################################################
// V3Options - Command line options
@ -90,6 +125,8 @@ class V3Options {
string m_xAssign; // main switch: --x-assign
string m_topModule; // main switch: --top-module
V3LangCode m_language; // main switch: --language
// MEMBERS (optimizations)
// // main switch: -Op: --public
bool m_oAcycSimp; // main switch: -Oy: acyclic pre-optimizations
@ -181,7 +218,7 @@ class V3Options {
const V3StringSet& cppFiles() const { return m_cppFiles; }
const V3StringSet& libraryFiles() const { return m_libraryFiles; }
const V3StringSet& vFiles() const { return m_vFiles; }
const V3LangCode& language() const { return m_language; }
// ACCESSORS (optimization options)
bool oAcycSimp() const { return m_oAcycSimp; }

View File

@ -121,6 +121,13 @@ void V3Read::readFile(FileLine* fileline, const string& modfilename, bool inLibr
m_fileline = new FileLine(fileline);
m_inLibrary = inLibrary;
// Set language standard up front
if (!v3Global.opt.preprocOnly()) {
// Leting lex parse this saves us from having to specially en/decode
// from the V3LangCode to the various Lex BEGIN states.
ppPushText((string)"`begin_keywords \""+v3Global.opt.language().ascii()+"\"\n");
}
// Preprocess into m_ppBuffer
V3PreShell::preproc(fileline, modfilename, this);

View File

@ -0,0 +1,13 @@
#!/usr/bin/perl
if (!$::Driver) { use FindBin; exec("./driver.pl", @ARGV, $0); die; }
compile (
verilator_flags2 => ['--language 1364-2001'],
);
execute (
check_finished=>1,
);
ok(1);
1;

View File

@ -0,0 +1,17 @@
// $Id$
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed into the Public Domain, for any use,
// without warranty, 2008 by Wilson Snyder.
module t (/*AUTOARG*/);
// See also t_preproc_kwd.v
integer bit; initial bit = 1;
initial begin
$write("*-* All Finished *-*\n");
$finish;
end
endmodule