From 0eb5a0a539a73380cbd00a44dd4179da6b59d634 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Fri, 6 Jun 2014 20:22:20 -0400 Subject: [PATCH] Add -P to suppress `line and blanks with preprocessing, bug781. --- Changes | 2 ++ bin/verilator | 6 ++++++ src/V3Options.cpp | 2 ++ src/V3Options.h | 2 ++ src/V3ParseImp.cpp | 8 ++++++++ src/V3PreProc.h | 4 +++- test_regress/t/t_preproc_noline.out | 5 +++++ test_regress/t/t_preproc_noline.pl | 24 ++++++++++++++++++++++++ test_regress/t/t_preproc_noline.v | 20 ++++++++++++++++++++ 9 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 test_regress/t/t_preproc_noline.out create mode 100755 test_regress/t/t_preproc_noline.pl create mode 100644 test_regress/t/t_preproc_noline.v diff --git a/Changes b/Changes index 400bf896b..028b719c6 100644 --- a/Changes +++ b/Changes @@ -7,6 +7,8 @@ indicates the contributor was also the author of the fix; Thanks! *** Using command line -Wno-{WARNING} now overrides file-local lint_on. +*** Add -P to suppress `line and blanks with preprocessing, bug781. [Derek Lockhart] + *** Support SV 2012 package import before port list. **** Change SYMRSVDWORD to print as warning rather than error. diff --git a/bin/verilator b/bin/verilator index 27a324a75..3e58b7c52 100755 --- a/bin/verilator +++ b/bin/verilator @@ -303,6 +303,7 @@ descriptions in the next sections for more information. --output-split Split .cpp files into pieces --output-split-cfuncs Split .cpp functions --output-split-ctrace Split tracing functions + -P Disable line numbers and blanks with -E --pins-bv Specify types for top level ports --pins-sc-uint Specify types for top level ports --pins-sc-biguint Specify types for top level ports @@ -830,6 +831,11 @@ function. Enables splitting trace functions in the output .cpp/.sp files into multiple functions. Defaults to same setting as --output-split-cfuncs. +=item -P + +With -E, disable generation of `line markers and blank lines, similar to +GCC -P flag. + =item --pins64 Backward compatible alias for "--pins-bv 65". Note that's a 65, not a 64. diff --git a/src/V3Options.cpp b/src/V3Options.cpp index 54a766496..76d35dce4 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -712,6 +712,7 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char else if ( !strcmp (sw, "-E") ) { m_preprocOnly = true; } else if ( onoff (sw, "-MMD", flag/*ref*/) ) { m_makeDepend = flag; } else if ( onoff (sw, "-MP", flag/*ref*/) ) { m_makePhony = flag; } + else if ( !strcmp (sw, "-P") ) { m_preprocNoLine = true; } else if ( onoff (sw, "-assert", flag/*ref*/) ) { m_assert = flag; } else if ( onoff (sw, "-autoflush", flag/*ref*/) ) { m_autoflush = flag; } else if ( onoff (sw, "-bbox-sys", flag/*ref*/) ) { m_bboxSys = flag; } @@ -1212,6 +1213,7 @@ V3Options::V3Options() { m_pinsBv = 65; m_profileCFuncs = false; m_preprocOnly = false; + m_preprocNoLine = false; m_psl = false; m_public = false; m_savable = false; diff --git a/src/V3Options.h b/src/V3Options.h index 45e8cf754..a05924fe9 100644 --- a/src/V3Options.h +++ b/src/V3Options.h @@ -59,6 +59,7 @@ class V3Options { bool m_preprocOnly; // main switch: -E bool m_makeDepend; // main switch: -MMD bool m_makePhony; // main switch: -MP + bool m_preprocNoLine;// main switch: -P bool m_assert; // main switch: --assert bool m_autoflush; // main switch: --autoflush bool m_bboxSys; // main switch: --bbox-sys @@ -192,6 +193,7 @@ class V3Options { bool preprocOnly() const { return m_preprocOnly; } bool makeDepend() const { return m_makeDepend; } bool makePhony() const { return m_makePhony; } + bool preprocNoLine() const { return m_preprocNoLine; } bool underlineZero() const { return m_underlineZero; } string bin() const { return m_bin; } string flags() const { return m_flags; } diff --git a/src/V3ParseImp.cpp b/src/V3ParseImp.cpp index 1161bb31b..48fb58b6e 100644 --- a/src/V3ParseImp.cpp +++ b/src/V3ParseImp.cpp @@ -123,6 +123,7 @@ void V3ParseImp::parseFile(FileLine* fileline, const string& modfilename, bool i string vppfilename = v3Global.opt.makeDir()+"/"+v3Global.opt.prefix()+"_"+modname+".vpp"; ofstream* ofp = NULL; ostream* osp; + bool noblanks = v3Global.opt.preprocOnly() && v3Global.opt.preprocNoLine(); if (v3Global.opt.preprocOnly()) { osp = &cout; } else { @@ -133,6 +134,13 @@ void V3ParseImp::parseFile(FileLine* fileline, const string& modfilename, bool i return; } else { for (deque::iterator it = m_ppBuffers.begin(); it!=m_ppBuffers.end(); ++it) { + if (noblanks) { + bool blank = true; + for (string::iterator its = it->begin(); its != it->end(); ++its) { + if (!isspace(*its) && *its!='\n') { blank=false; break; } + } + if (blank) continue; + } *osp << *it; } if (ofp) { diff --git a/src/V3PreProc.h b/src/V3PreProc.h index b9678d5c0..9e47d3c3d 100644 --- a/src/V3PreProc.h +++ b/src/V3PreProc.h @@ -71,7 +71,9 @@ public: // These options control how the parsing proceeds static int keepComments() { return 2; } // Return comments, 0=no, 1=yes, 2=callback static bool keepWhitespace() { return false; } - static bool lineDirectives() { return true; } // Insert `line directives + static bool lineDirectives() { // Insert `line directives + return !(v3Global.opt.preprocOnly() && v3Global.opt.preprocNoLine()); + } static bool pedantic() { return false; } // Obey standard; Don't substitute `error static bool optPsl(); diff --git a/test_regress/t/t_preproc_noline.out b/test_regress/t/t_preproc_noline.out new file mode 100644 index 000000000..f7b77d57c --- /dev/null +++ b/test_regress/t/t_preproc_noline.out @@ -0,0 +1,5 @@ +Hello in t_preproc_psl.v + yes +Multi text + multiline line +Line: 20 diff --git a/test_regress/t/t_preproc_noline.pl b/test_regress/t/t_preproc_noline.pl new file mode 100755 index 000000000..0bb99340a --- /dev/null +++ b/test_regress/t/t_preproc_noline.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-2009 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"); + +my $stdout_filename = "$Self->{obj_dir}/$Self->{name}__test.vpp"; + +top_filename("t/t_preproc_noline.v"); + +compile ( + verilator_flags2 => ['-E -P'], + verilator_make_gcc=>0, + stdout_filename => $stdout_filename, + ); + +ok(files_identical($stdout_filename, "t/$Self->{name}.out")); + +1; diff --git a/test_regress/t/t_preproc_noline.v b/test_regress/t/t_preproc_noline.v new file mode 100644 index 000000000..8d89b0e5e --- /dev/null +++ b/test_regress/t/t_preproc_noline.v @@ -0,0 +1,20 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed into the Public Domain, for any use, +// without warranty, 2014 by Wilson Snyder. + +`define CHECK text \ + multiline + +Hello in t_preproc_psl.v + +`ifdef NEVER + not +`else + yes +`endif + +Multi `CHECK line + +// Did we end up right? +Line: `__LINE__