From 9b0d26aeddf99b28a29522ec19927d4c88b2c34b Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sun, 20 Dec 2009 22:26:48 -0500 Subject: [PATCH] Support `undefineall --- Changes | 2 ++ src/V3Options.cpp | 2 +- src/V3PreLex.h | 1 + src/V3PreLex.l | 9 ++++---- src/V3PreProc.cpp | 30 ++++++++++++++++++++----- src/V3PreProc.h | 6 ++++- src/V3PreShell.cpp | 12 +++++----- src/V3PreShell.h | 2 +- test_regress/t/t_preproc_undefineall.pl | 19 ++++++++++++++++ test_regress/t/t_preproc_undefineall.v | 19 ++++++++++++++++ 10 files changed, 83 insertions(+), 19 deletions(-) create mode 100755 test_regress/t/t_preproc_undefineall.pl create mode 100644 test_regress/t/t_preproc_undefineall.v diff --git a/Changes b/Changes index 8fd72a57a..cf4f8f150 100644 --- a/Changes +++ b/Changes @@ -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] diff --git a/src/V3Options.cpp b/src/V3Options.cpp index 53a95c6bc..342a5532d 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -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) { diff --git a/src/V3PreLex.h b/src/V3PreLex.h index 2170034e8..818a9c2c0 100644 --- a/src/V3PreLex.h +++ b/src/V3PreLex.h @@ -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 diff --git a/src/V3PreLex.l b/src/V3PreLex.l index 3980745a7..291fdb2de 100644 --- a/src/V3PreLex.l +++ b/src/V3PreLex.l @@ -79,14 +79,15 @@ psl [p]sl return(VP_LINE); } /* Special directives we recognize */ -"`include" { return(VP_INCLUDE); } -"`ifdef" { return(VP_IFDEF); } -"`ifndef" { return(VP_IFNDEF); } +"`define" { return(VP_DEFINE); } "`else" { return(VP_ELSE); } "`elsif" { return(VP_ELSIF); } "`endif" { return(VP_ENDIF); } +"`ifdef" { return(VP_IFDEF); } +"`ifndef" { return(VP_IFNDEF); } +"`include" { return(VP_INCLUDE); } "`undef" { return(VP_UNDEF); } -"`define" { return(VP_DEFINE); } +"`undefineall" { return(VP_UNDEFINEALL); } /* Optional directives we recognize */ "`__FILE__" { if (!pedantic()) { diff --git a/src/V3PreProc.cpp b/src/V3PreProc.cpp index 357dbf36c..f0d6e0f0c 100644 --- a/src/V3PreProc.cpp +++ b/src/V3PreProc.cpp @@ -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 '"<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 "<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); diff --git a/src/V3PreShell.h b/src/V3PreShell.h index 14bdd4279..985863aea 100644 --- a/src/V3PreShell.h +++ b/src/V3PreShell.h @@ -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); }; diff --git a/test_regress/t/t_preproc_undefineall.pl b/test_regress/t/t_preproc_undefineall.pl new file mode 100755 index 000000000..07f70d571 --- /dev/null +++ b/test_regress/t/t_preproc_undefineall.pl @@ -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; diff --git a/test_regress/t/t_preproc_undefineall.v b/test_regress/t/t_preproc_undefineall.v new file mode 100644 index 000000000..2f86b17e9 --- /dev/null +++ b/test_regress/t/t_preproc_undefineall.v @@ -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