From b1831d7e33664e0abb400046631e7e4de1b036c8 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sun, 10 Mar 2019 14:09:22 -0400 Subject: [PATCH] Fix +1364-1995ext flags applying too late, bug1384. --- Changes | 2 ++ src/V3FileLine.h | 1 + src/V3ParseImp.cpp | 11 ---------- src/V3PreShell.cpp | 32 +++++++++++++++++++++------- test_regress/t/t_langext_order.pl | 18 ++++++++++++++++ test_regress/t/t_langext_order.v | 12 +++++++++++ test_regress/t/t_langext_order_sub.v | 11 ++++++++++ 7 files changed, 68 insertions(+), 19 deletions(-) create mode 100755 test_regress/t/t_langext_order.pl create mode 100644 test_regress/t/t_langext_order.v create mode 100644 test_regress/t/t_langext_order_sub.v diff --git a/Changes b/Changes index 0d51fb2fe..460708884 100644 --- a/Changes +++ b/Changes @@ -18,6 +18,8 @@ The contributors that suggested a given feature are shown in []. Thanks! **** Fix maintainer test when no Parallel::Forker, msg2630. [Enzo Chi] +**** Fix +1364-1995ext flags applying too late, bug1384. [Al Grant] + * Verilator 4.010 2019-01-27 diff --git a/src/V3FileLine.h b/src/V3FileLine.h index 89cf0ca57..3af449b3d 100644 --- a/src/V3FileLine.h +++ b/src/V3FileLine.h @@ -91,6 +91,7 @@ protected: friend class V3ParseImp; friend class V3PreLex; friend class V3PreProcImp; + friend class V3PreShellImp; void lineno(int num) { m_lineno = num; } void language(V3LangCode lang) { singleton().numberToLang(m_filenameno, lang); } void filename(const string& name) { m_filenameno = singleton().nameToNumber(name); } diff --git a/src/V3ParseImp.cpp b/src/V3ParseImp.cpp index 646c3c652..4bf75d399 100644 --- a/src/V3ParseImp.cpp +++ b/src/V3ParseImp.cpp @@ -115,17 +115,6 @@ void V3ParseImp::parseFile(FileLine* fileline, const string& modfilename, bool i 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. The language - // of this source file is updated here, in case there have been any - // intervening +ext+ options since it was first ecountered. - FileLine *modfileline = new FileLine(modfilename, 0); - modfileline->language(v3Global.opt.fileLanguage(modfilename)); - ppPushText(string("`begin_keywords \"")+modfileline->language().ascii()+"\"\n"); - } - // Preprocess into m_ppBuffer bool ok = V3PreShell::preproc(fileline, modfilename, m_filterp, this, errmsg); if (!ok) { diff --git a/src/V3PreShell.cpp b/src/V3PreShell.cpp index 2c6a348d2..ae7145c97 100644 --- a/src/V3PreShell.cpp +++ b/src/V3PreShell.cpp @@ -102,8 +102,20 @@ protected: // Preprocess s_filterp = filterp; - bool ok = preprocOpen(fl, s_filterp, modname, "", errmsg); - if (!ok) return false; + string modfilename = preprocOpen(fl, s_filterp, modname, "", errmsg); + if (modfilename.empty()) return false; + + // 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. The language + // of this source file is updated here, in case there have been any + // intervening +ext+ options since it was first ecountered. + FileLine* modfileline = new FileLine(modfilename, 0); + modfileline->language(v3Global.opt.fileLanguage(modfilename)); + V3Parse::ppPushText(parsep, (string("`begin_keywords \"") + +modfileline->language().ascii()+"\"\n")); + } while (!s_preprocp->isEof()) { string line = s_preprocp->getline(); @@ -116,12 +128,15 @@ protected: if (modname[0]=='/' || modname[0]=='\\') { fl->v3warn(INCABSPATH,"Suggest `include with absolute path be made relative, and use +include: "<filename()), "Cannot find include file: "); + preprocOpen(fl, s_filterp, modname, V3Os::filenameDir(fl->filename()), + "Cannot find include file: "); } - bool preprocOpen(FileLine* fl, V3InFilter* filterp, const string& modname, const string& lastpath, - const string& errmsg) { // Error message or "" to suppress - // Returns true if successful +private: + string preprocOpen(FileLine* fl, V3InFilter* filterp, + const string& modname, const string& lastpath, + const string& errmsg) { // Error message or "" to suppress + // Returns filename if successful // Try a pure name in case user has a bogus `filename they don't expect string filename = v3Global.opt.filePath(fl, modname, lastpath, errmsg); if (filename=="") { @@ -131,13 +146,14 @@ protected: filename = v3Global.opt.filePath(fl, ppmodname, lastpath, errmsg); } - if (filename=="") return false; // Not found + if (filename=="") return ""; // Not found UINFO(2," Reading "<openFile(fl, filterp, filename); - return true; + return filename; } +public: // CONSTRUCTORS V3PreShellImp() {} ~V3PreShellImp() {} diff --git a/test_regress/t/t_langext_order.pl b/test_regress/t/t_langext_order.pl new file mode 100755 index 000000000..7dee7e04c --- /dev/null +++ b/test_regress/t/t_langext_order.pl @@ -0,0 +1,18 @@ +#!/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. + +scenarios(simulator => 1); + +# This is a compile only test. +compile( + v_flags2 => ["+1364-2005ext+v"], + ); + +ok(1); +1; diff --git a/test_regress/t/t_langext_order.v b/test_regress/t/t_langext_order.v new file mode 100644 index 000000000..aea0dc00f --- /dev/null +++ b/test_regress/t/t_langext_order.v @@ -0,0 +1,12 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// A test of the +verilog2001ext+ and +verilog2005ext+ flags. +// +// This file ONLY is placed into the Public Domain, for any use, +// without warranty, 2019 by Wilson Snyder. + +// verilator lint_off SYMRSVDWORD + +module t(input do); + t_langext_order_sub sub (.do(do)); +endmodule diff --git a/test_regress/t/t_langext_order_sub.v b/test_regress/t/t_langext_order_sub.v new file mode 100644 index 000000000..79cdaaa2a --- /dev/null +++ b/test_regress/t/t_langext_order_sub.v @@ -0,0 +1,11 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// A test of the +verilog2001ext+ and +verilog2005ext+ flags. +// +// This file ONLY is placed into the Public Domain, for any use, +// without warranty, 2019 by Wilson Snyder. + +// verilator lint_off SYMRSVDWORD + +module t_langext_order_sub(input do); +endmodule