Support `undefineall

This commit is contained in:
Wilson Snyder 2009-12-20 22:26:48 -05:00
parent f6758c397d
commit 9b0d26aedd
10 changed files with 83 additions and 19 deletions

View File

@ -22,6 +22,8 @@ indicates the contributor was also the author of the fix; Thanks!
*** Support $sformat and $swrite.
*** Support `undefineall.
*** Add VARHIDDEN warning when signal name hides module name.
**** Support optional cell parenthesis, bug179. [by Byron Bradley]

View File

@ -89,7 +89,7 @@ void V3Options::addDefine(const string& defline) {
value = def.substr(pos+1);
def.erase(pos);
}
V3PreShell::define(def,value);
V3PreShell::defineCmdLine(def,value);
}
void V3Options::addCppFile(const string& filename) {

View File

@ -43,6 +43,7 @@
#define VP_ELSE 262
#define VP_ELSIF 263
#define VP_LINE 264
#define VP_UNDEFINEALL 265
#define VP_SYMBOL 300
#define VP_STRING 301

View File

@ -79,14 +79,15 @@ psl [p]sl
return(VP_LINE); }
/* Special directives we recognize */
<INITIAL>"`include" { return(VP_INCLUDE); }
<INITIAL>"`ifdef" { return(VP_IFDEF); }
<INITIAL>"`ifndef" { return(VP_IFNDEF); }
<INITIAL>"`define" { return(VP_DEFINE); }
<INITIAL>"`else" { return(VP_ELSE); }
<INITIAL>"`elsif" { return(VP_ELSIF); }
<INITIAL>"`endif" { return(VP_ENDIF); }
<INITIAL>"`ifdef" { return(VP_IFDEF); }
<INITIAL>"`ifndef" { return(VP_IFNDEF); }
<INITIAL>"`include" { return(VP_INCLUDE); }
<INITIAL>"`undef" { return(VP_UNDEF); }
<INITIAL>"`define" { return(VP_DEFINE); }
<INITIAL>"`undefineall" { return(VP_UNDEFINEALL); }
/* Optional directives we recognize */
<INITIAL>"`__FILE__" { if (!pedantic()) {

View File

@ -53,12 +53,14 @@ class V3Define {
FileLine* m_fileline; // Where it was declared
string m_value; // Value of define
string m_params; // Parameters
bool m_cmdline; // Set on command line, don't `undefineall
public:
V3Define(FileLine* fl, const string& value, const string& params)
: m_fileline(fl), m_value(value), m_params(params) {}
V3Define(FileLine* fl, const string& value, const string& params, bool cmdline)
: m_fileline(fl), m_value(value), m_params(params), m_cmdline(cmdline) {}
FileLine* fileline() const { return m_fileline; }
string value() const { return m_value; }
string params() const { return m_params; }
bool cmdline() const { return m_cmdline; }
};
//*************************************************************************
@ -181,7 +183,9 @@ public:
virtual void comment(const string& cmt); // Comment detected (if keepComments==2)
virtual void include(const string& filename); // Request a include file be processed
virtual void undef (const string& name);
virtual void define (FileLine* fl, const string& name, const string& value, const string& params);
virtual void undefineall();
virtual void define (FileLine* fl, const string& name, const string& value,
const string& params, bool cmdline);
virtual string removeDefines(const string& text); // Remove defines in a text string
// CONSTRUCTORS
@ -215,6 +219,12 @@ bool V3PreProc::optPsl() {
void V3PreProcImp::undef(const string& name) {
m_defines.erase(name);
}
void V3PreProcImp::undefineall() {
for (DefinesMap::iterator nextit, it = m_defines.begin(); it != m_defines.end(); it=nextit) {
nextit = it; ++nextit;
if (!it->second.cmdline()) m_defines.erase(it);
}
}
bool V3PreProcImp::defExists(const string& name) {
DefinesMap::iterator iter = m_defines.find(name);
if (iter == m_defines.end()) return false;
@ -241,7 +251,8 @@ FileLine* V3PreProcImp::defFileline(const string& name) {
if (iter == m_defines.end()) return false;
return iter->second.fileline();
}
void V3PreProcImp::define(FileLine* fl, const string& name, const string& value, const string& params) {
void V3PreProcImp::define(FileLine* fl, const string& name, const string& value,
const string& params, bool cmdline) {
UINFO(4,"DEFINE '"<<name<<"' as '"<<value<<"' params '"<<params<<"'"<<endl);
if (defExists(name)) {
if (!(defValue(name)==value && defParams(name)==params)) { // Duplicate defs are OK
@ -250,7 +261,7 @@ void V3PreProcImp::define(FileLine* fl, const string& name, const string& value,
}
undef(name);
}
m_defines.insert(make_pair(name, V3Define(fl, value, params)));
m_defines.insert(make_pair(name, V3Define(fl, value, params, cmdline)));
}
string V3PreProcImp::removeDefines(const string& sym) {
@ -382,6 +393,7 @@ const char* V3PreProcImp::tokenName(int tok) {
case VP_DEFREF : return("DEFREF");
case VP_DEFARG : return("DEFARG");
case VP_ERROR : return("ERROR");
case VP_UNDEFINEALL : return("UNDEFINEALL");
case VP_PSL : return("PSL");
default: return("?");
}
@ -791,7 +803,7 @@ int V3PreProcImp::getToken() {
if (trailspace) formAndValue.erase(formAndValue.length()-trailspace,trailspace);
// Define it
UINFO(4,"Define "<<m_lastSym<<" = '"<<formAndValue<<"'"<<endl);
define(fileline(), m_lastSym, formAndValue, params);
define(fileline(), m_lastSym, formAndValue, params, false);
}
} else {
fileline()->v3fatalSrc("Bad define text\n");
@ -996,6 +1008,12 @@ int V3PreProcImp::getToken() {
fileline()->v3error("`ifdef not terminated at EOF\n");
}
return tok;
case VP_UNDEFINEALL:
if (!m_off) {
UINFO(4,"Undefineall "<<endl);
undefineall();
}
goto next_tok;
case VP_SYMBOL:
case VP_STRING:
case VP_PSL:

View File

@ -72,7 +72,11 @@ public:
virtual void undef(const string& name)=0; // Remove a definition
virtual void define(FileLine* fileline, const string& name,
const string& value, const string& params="")=0; // `define without any parameters
const string& value, const string& params="", bool cmdline=false)=0; // `define without any parameters
virtual void defineCmdLine(FileLine* fileline, const string& name,
const string& value) { // `define without any parameters
define(fileline, name, value, "", true);
}
virtual string removeDefines(const string& text)=0; // Remove defines in a text string
protected:

View File

@ -62,10 +62,10 @@ protected:
s_preprocp->debug(debug());
// Default defines
FileLine* prefl = new FileLine("INTERNAL_VERILATOR_DEFINE",0);
s_preprocp->define(prefl,"verilator", "1"); // LEAK_OK
s_preprocp->define(prefl,"verilator3", "1"); // LEAK_OK
s_preprocp->define(prefl,"systemc_clock", "/*verilator systemc_clock*/"); // LEAK_OK
s_preprocp->define(prefl,"coverage_block_off", "/*verilator coverage_block_off*/"); // LEAK_OK
s_preprocp->defineCmdLine(prefl,"verilator", "1"); // LEAK_OK
s_preprocp->defineCmdLine(prefl,"verilator3", "1"); // LEAK_OK
s_preprocp->defineCmdLine(prefl,"systemc_clock", "/*verilator systemc_clock*/"); // LEAK_OK
s_preprocp->defineCmdLine(prefl,"coverage_block_off", "/*verilator coverage_block_off*/"); // LEAK_OK
}
}
@ -117,9 +117,9 @@ void V3PreShell::preproc(FileLine* fl, const string& modname, V3ParseImp* parsep
void V3PreShell::preprocInclude(FileLine* fl, const string& modname) {
V3PreShellImp::s_preImp.preprocInclude(fl, modname);
}
void V3PreShell::define(const string& name, const string& value) {
void V3PreShell::defineCmdLine(const string& name, const string& value) {
FileLine* prefl = new FileLine("COMMAND_LINE_DEFINE",0);
V3PreShellImp::s_preprocp->define(prefl, name,value,"");
V3PreShellImp::s_preprocp->defineCmdLine(prefl, name, value);
}
void V3PreShell::undef(const string& name) {
V3PreShellImp::s_preprocp->undef(name);

View File

@ -38,7 +38,7 @@ public:
static void preproc(FileLine* fileline, const string& module, V3ParseImp* parsep);
static void preprocInclude(FileLine* fileline, const string& module);
static string dependFiles() { return ""; } // Perl only
static void define(const string& name, const string& value);
static void defineCmdLine(const string& name, const string& value);
static void undef(const string& name);
};

View File

@ -0,0 +1,19 @@
#!/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.
compile (
v_flags2 => ['+define+PREDEF_COMMAND_LINE',
"--lint-only"],
verilator_make_gcc => 0,
make_top_shell => 0,
make_main => 0,
);
ok(1);
1;

View File

@ -0,0 +1,19 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed into the Public Domain, for any use,
// without warranty, 2009 by Wilson Snyder.
module t;
`define UDALL
`ifndef PREDEF_COMMAND_LINE `error "Test setup error, PREDEF_COMMAND_LINE pre-missing" `endif
`undefineall
`ifdef UDALL `error "undefineall failed" `endif
`ifndef PREDEF_COMMAND_LINE `error "Deleted too much, no PREDEF_COMMAND_LINE" `endif
initial begin
$finish;
end
endmodule