From 7a8c425103ef647fb323f37eae078c4f5a827213 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Tue, 13 Nov 2012 20:12:23 -0500 Subject: [PATCH] Add +1364-1995ext and similar language options, bug532. --- Changes | 2 + bin/verilator | 86 +++++++++++++++++++++++++++---- src/V3Error.cpp | 23 +++++++-- src/V3Error.h | 22 ++++++-- src/V3LangCode.h | 72 ++++++++++++++++++++++++++ src/V3Options.cpp | 65 +++++++++++++++++++++-- src/V3Options.h | 48 +++-------------- src/V3ParseImp.cpp | 8 ++- test_regress/t/t_langext_1.pl | 16 ++++++ test_regress/t/t_langext_1.v | 51 ++++++++++++++++++ test_regress/t/t_langext_1_bad.pl | 19 +++++++ test_regress/t/t_langext_2.pl | 16 ++++++ test_regress/t/t_langext_2.v | 55 ++++++++++++++++++++ test_regress/t/t_langext_2_bad.pl | 19 +++++++ test_regress/t/t_langext_3.pl | 16 ++++++ test_regress/t/t_langext_3.v | 21 ++++++++ test_regress/t/t_langext_3_bad.pl | 19 +++++++ test_regress/t/t_langext_4.pl | 18 +++++++ test_regress/t/t_langext_4_bad.pl | 19 +++++++ 19 files changed, 531 insertions(+), 64 deletions(-) create mode 100644 src/V3LangCode.h create mode 100755 test_regress/t/t_langext_1.pl create mode 100644 test_regress/t/t_langext_1.v create mode 100755 test_regress/t/t_langext_1_bad.pl create mode 100755 test_regress/t/t_langext_2.pl create mode 100644 test_regress/t/t_langext_2.v create mode 100755 test_regress/t/t_langext_2_bad.pl create mode 100755 test_regress/t/t_langext_3.pl create mode 100644 test_regress/t/t_langext_3.v create mode 100755 test_regress/t/t_langext_3_bad.pl create mode 100755 test_regress/t/t_langext_4.pl create mode 100755 test_regress/t/t_langext_4_bad.pl diff --git a/Changes b/Changes index cf424e061..3700be2b3 100644 --- a/Changes +++ b/Changes @@ -5,6 +5,8 @@ indicates the contributor was also the author of the fix; Thanks! * Verilator 3.84** devel +*** Add +1364-1995ext and similar language options, bug532. [Jeremy Bennett] + **** Fix svdpi compile issue on MSVCC, bug571. [Amir Gonnen] diff --git a/bin/verilator b/bin/verilator index d5c796e51..ab946c061 100755 --- a/bin/verilator +++ b/bin/verilator @@ -241,6 +241,11 @@ descriptions in the next sections for more information. {file.c/cc/cpp} Optional C++ files to compile in {file.a/o/so} Optional C++ files to link in + +1364-1995ext+ Use Verilog 1995 with file extension + +1364-2001ext+ Use Verilog 2001 with file extension + +1364-2005ext+ Use Verilog 2005 with file extension + +1800-2005ext+ Use SystemVerilog 2005 with file extension + +1800-2009ext+ Use SystemVerilog 2009 with file extension --assert Enable all assertions --autoflush Flush streams after all $displays --bbox-sys Blackbox unknown $system calls @@ -261,6 +266,7 @@ descriptions in the next sections for more information. --debug-check Enable debugging assertions --debugi Enable debugging at a specified level --debugi- Enable debugging a source file at a level + --default-language Default language to parse +define++ Set preprocessor define --dump-tree Enable dumping .tree files --dump-treei Enable dumping .tree files at a level @@ -279,7 +285,7 @@ descriptions in the next sections for more information. --inline-mult Tune module inlining -LDFLAGS Linker pre-object flags for makefile -LDLIBS Linker library flags for makefile - --language Language standard to parse + --language Default language standard to parse +libext++[ext]... Extensions for finding modules --lint-only Lint, but do not make output --MMD Create .d dependency files @@ -308,6 +314,7 @@ descriptions in the next sections for more information. --sp Create SystemPerl output --stats Create statistics file -sv Enable SystemVerilog parsing + +systemverilogext+ Synonym for +1800-2009ext+ --top-module Name of top level input module --trace Enable waveform creation --trace-depth Depth of tracing @@ -320,6 +327,8 @@ descriptions in the next sections for more information. --unused-regexp Tune UNUSED lint signals -V Verbose version and config -v Verilog library + +verilog1995ext+ Synonym for +1364-1995ext+ + +verilog2001ext+ Synonym for +1364-2001ext+ -Werror- Convert warning to error -Wfuture- Disable unknown message warnings -Wno- Disable warning @@ -355,6 +364,41 @@ this way, Verilator will include a make rule that uses these files when linking the I executable. This generally is only useful when used with the --exe option. +=item +1364-1995ext+I + +=item +1364-2001ext+I + +=item +1364-2005ext+I + +=item +1800-2005ext+I + +=item +1800-2009ext+I + +Specifies the language standard to be used with a specific filename +extension, I. + +For compatibility with other simulators, see also the synonyms +C<+verilog1995ext+>I, C<+verilog2001ext+>I, and +C<+systemverilogext+>I. + +For any source file, the language specified by these options takes +precedence over any language specified by the C<--default-language> or +C<--language> options. + +These options take effect in the order they are encountered. Thus the +following would use Verilog 1995 for C and Verilog 2001 for C. + + verilator ... +1364-1995ext+v a.v +1364-2001ext+v b.v + +These flags are only recommended for legacy mixed language designs, as the +preferable option is to edit the code to repair new keywords, or add +appropriate C<`begin_keywords>. + +B C<`begin_keywords> is a SystemVerilog construct, which specifies +I which the set of keywords is to be recognized. Whatever set is +chosen, the semantics will be those of SystemVerilog. By contrast +C<+1364-1995ext+> etc. specify both the syntax I semantics to be used. + =item --assert Enable all assertions, includes enabling the --psl flag. (If psl is not @@ -536,6 +580,25 @@ to the specified debug level (1-10) or set the specified source file to the specified level. Higher levels produce more detailed messages (plain C<--debug> is equivalent to C<--debugi 4>). +=item --default-language I + +Select the language to be used by default when first processing each +Verilog file. The language value must be "1364-1995", "1364-2001", +"1364-2005", "1800-2005" or "1800-2009". + +Any language associated with a particular file extension (see the various ++Iext+ options) will be used in preference to the language specified +by --default-language. + +The --default-language flag is only recommended for legacy code using the +same language in all source files, as the preferable option is to edit the +code to repair new keywords, or add appropriate C<`begin_keywords>. For +legacy mixed language designs, the various +Iext+ options should be +used. + +If no language is specified, either by this flag or +Iext+ options, +then the latest SystemVerilog language (IEEE 1800-2009) is used. + =item +define+I+I Defines the given preprocessor symbol. Same as -D; +define is fairly @@ -645,15 +708,8 @@ in the Make variable LDLIBS, not LDFLAGS.) =item --language I -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", "1800-2005", "VAMS-2.3". Verilator also allows the -non-standard "1800+VAMS" to allow both the full SystemVerilog and -Verilog-AMS keywords. - -The --language flag is only recommended for legacy code, as the preferable -option is to edit the code to repair new keywords, or add appropriate -`begin_keywords. +A synonym for C<--default-langauge>, for compatibility with other tools and +earlier versions of Verilator. =item +libext+I+I... @@ -860,6 +916,10 @@ Specifies SystemVerilog language features should be enabled; equivalent to "--language 1800-2005". This option is selected by default, it exists for compatibility with other simulators. +=item +systemverilogext+I + +A synonym for C<+1800-2009ext+>I. + =item --top-module I When the input Verilog contains more than one top level module, specifies @@ -935,6 +995,12 @@ Read the filename as a Verilog library. Any modules in the file may be used to resolve cell instantiations in the top level module, else ignored. Note -v is fairly standard across Verilog tools. +=item +verilog1995ext+I + +=item +verilog2001ext+I + +Synonyms for C<+1364-1995ext+>I and C<+1364-2001ext+>I respectively + =item -Wall Enable all warnings, including code style warnings that are normally diff --git a/src/V3Error.cpp b/src/V3Error.cpp index 841b314ce..e265bac76 100644 --- a/src/V3Error.cpp +++ b/src/V3Error.cpp @@ -80,22 +80,33 @@ const string FileLineSingleton::filenameLetters(int no) { return op; } +//! Convert filenames to a filenameno + +//! This lets us assign a nice small identifier for debug messages, but more +//! importantly lets us use a 4 byte int instead of 8 byte pointer in every +//! FileLine. + +//! We associate a language with each source file, so we also set the default +//! for this. int FileLineSingleton::nameToNumber(const string& filename) { - // Convert filenames to a filenameno - // This lets us assign a nice small identifier for debug messages, but more - // importantly lets us use a 4 byte int instead of 8 byte pointer in every FileLine. FileNameNumMap::const_iterator iter = m_namemap.find(filename); if (VL_LIKELY(iter != m_namemap.end())) return iter->second; int num = m_names.size(); m_names.push_back(filename); + m_languages.push_back(V3LangCode::mostRecent()); m_namemap.insert(make_pair(filename,num)); return num; } +//! Support XML output + +//! Experimental. Updated to also put out the language. void FileLineSingleton::fileNameNumMapDumpXml(ostream& os) { os<<"\n"; for (FileNameNumMap::const_iterator it = m_namemap.begin(); it != m_namemap.end(); ++it) { - os<<"second)<<"\" filename=\""<first<<"\"/>\n"; + os<<"second) + <<"\" filename=\""<first + <<"\" language=\""<second).ascii()<<"\"/>\n"; } os<<"\n"; } @@ -170,6 +181,10 @@ FileLine* FileLine::copyOrSameFileLine() { return newp; } +void FileLine::updateLanguage () { + language(v3Global.opt.fileLanguage(filename())); +} + const string FileLine::filebasename() const { string name = filename(); string::size_type pos; diff --git a/src/V3Error.h b/src/V3Error.h index a3b5c5f83..16bd03c97 100644 --- a/src/V3Error.h +++ b/src/V3Error.h @@ -30,6 +30,8 @@ #include #include +#include "V3LangCode.h" + //###################################################################### class V3ErrorCode { @@ -271,12 +273,18 @@ inline uint32_t cvtToHash(const void* vp) { class FileLine; +//! Singleton class with tables of per-file data. + +//! This singleton class contains tables of data that are unchanging in each +//! source file (each with its own unique filename number). class FileLineSingleton { // TYPES typedef map FileNameNumMap; + typedef map FileLangNumMap; // MEMBERS FileNameNumMap m_namemap; // filenameno for each filename deque m_names; // filename text for each filenameno + deque m_languages; // language for each filenameno // COSNTRUCTORS FileLineSingleton() { } ~FileLineSingleton() { } @@ -285,17 +293,22 @@ protected: // METHODS int nameToNumber(const string& filename); const string numberToName(int filenameno) const { return m_names[filenameno]; } - void clear() { m_namemap.clear(); m_names.clear(); } + const V3LangCode numberToLang(int filenameno) const { return m_languages[filenameno]; } + void numberToLang(int filenameno, const V3LangCode l) { m_languages[filenameno] = l; } + void clear() { m_namemap.clear(); m_names.clear(); m_languages.clear(); } void fileNameNumMapDumpXml(ostream& os); static const string filenameLetters(int fileno); }; +//! File and line number of an object, mostly for error reporting + +//! This class is instantiated for every source code line (potentially +//! millions). To save space, per-file information (e.g. filename, source +//! language is held in tables in the FileLineSingleton class. class FileLine { - // File and line number of an object, mostly for error reporting int m_lineno; int m_filenameno; bitset m_warnOn; - // Consider moving opt.language() into here, so can know language per-node private: struct EmptySecret {}; @@ -315,6 +328,7 @@ protected: friend class V3PreLex; friend class V3PreProcImp; 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); } void lineDirective(const char* textp, int& enterExitRef); void linenoInc() { m_lineno++; } @@ -337,6 +351,8 @@ public: #endif int lineno () const { return m_lineno; } + V3LangCode language () const { return singleton().numberToLang(m_filenameno); } + void updateLanguage (); string ascii() const; const string filename () const { return singleton().numberToName(m_filenameno); } const string filenameLetters() const { return singleton().filenameLetters(m_filenameno); } diff --git a/src/V3LangCode.h b/src/V3LangCode.h new file mode 100644 index 000000000..3386564dd --- /dev/null +++ b/src/V3LangCode.h @@ -0,0 +1,72 @@ +// -*- mode: C++; c-file-style: "cc-mode" -*- +//************************************************************************* +// DESCRIPTION: Verilator: Language code class +// +// Code available from: http://www.veripool.org/verilator +// +//************************************************************************* +// +// Copyright 2003-2012 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. +// +// Verilator is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +//************************************************************************* + +#ifndef _V3LANGCODE_H_ +#define _V3LANGCODE_H_ 1 + +#include "config_build.h" +#include "verilatedos.h" +#include +#include +#include +#include + +//###################################################################### +//! Class for the different languages supported. +//! A separate file, since used both in V3Options (globally) and FileLine 9per +//! file). +class V3LangCode { +public: + enum en { + L_ERROR, // Must be first. + L1364_1995, + L1364_2001, + L1364_2005, + L1800_2005, + L1800_2009, + // ***Add new elements below also*** + _ENUM_END + }; + const char* ascii() const { + const char* names[] = { + // These must match the `begin_keywords values. + " ERROR", + "1364-1995", + "1364-2001", + "1364-2005", + "1800-2005", + "1800-2009" + }; + return names[m_e]; + }; + static V3LangCode mostRecent() { return V3LangCode(L1800_2009); } + bool legal() const { return m_e != L_ERROR; } + // + enum en m_e; + inline V3LangCode () : m_e(L_ERROR) {} + inline V3LangCode (en _e) : m_e(_e) {} + V3LangCode (const char* textp); + explicit inline V3LangCode (int _e) : m_e(static_cast(_e)) {} + operator en () const { return m_e; } +}; + +//###################################################################### + +#endif // guard diff --git a/src/V3Options.cpp b/src/V3Options.cpp index 37ab6c8f1..1ac2f37bf 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -55,6 +55,7 @@ struct V3OptionsImp { set m_incDirUserSet; // Include directories (for removing duplicates) list m_incDirFallbacks; // Include directories (ordered) set m_incDirFallbackSet; // Include directories (for removing duplicates) + map m_langExts; // Language extension map list m_libExtVs; // Library extensions (ordered) set m_libExtVSet; // Library extensions (for removing duplicates) DirMap m_dirMap; // Directory listing @@ -76,6 +77,12 @@ struct V3OptionsImp { } } } + void addLangExt(const string &langext, const V3LangCode lc) { + // New language extension replaces any pre-existing one. + (void)m_langExts.erase(langext); + m_langExts[langext] = lc; + } + void addLibExtV(const string& libext) { if (m_libExtVSet.find(libext) == m_libExtVSet.end()) { m_libExtVSet.insert(libext); @@ -91,6 +98,9 @@ void V3Options::addIncDirUser(const string& incdir) { void V3Options::addIncDirFallback(const string& incdir) { m_impp->addIncDirFallback(incdir); } +void V3Options::addLangExt(const string &langext, const V3LangCode lc) { + m_impp->addLangExt(langext, lc); +} void V3Options::addLibExtV(const string& libext) { m_impp->addLibExtV(libext); } @@ -158,7 +168,7 @@ string V3Options::allArgsString() { } //###################################################################### -// Language class +// V3LangCode class functions V3LangCode::V3LangCode (const char* textp) { // Return code for given string, or ERROR, which is a bad code @@ -365,6 +375,24 @@ void V3Options::filePathLookedMsg(FileLine* fl, const string& modname) { } } +//! Determine what language is associated with a filename + +//! If we recognize the extension, use its language, otherwise, use the +//! default language. +V3LangCode V3Options::fileLanguage(const string &filename) { + string ext = filenameNonDir(filename); + string::size_type pos; + if ((pos = ext.rfind(".")) != string::npos) { + ext.erase(0, pos + 1); + map::iterator it = m_impp->m_langExts.find(ext); + if (it != m_impp->m_langExts.end()) { + return it->second; + } + } + return m_defaultLanguage; +} + + void V3Options::unlinkRegexp(const string& dir, const string& regexp) { if (DIR* dirp = opendir(dir.c_str())) { while (struct dirent* direntp = readdir(dirp)) { @@ -633,6 +661,17 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char else if ( !strncmp (sw, "+incdir+", 8)) { addIncDirUser (parseFileArg(optdir, string (sw+strlen("+incdir+")))); } + else if (parseLangExt(sw, "+systemverilogext+", V3LangCode::L1800_2009) + || parseLangExt(sw, "+verilog1995ext+", V3LangCode::L1364_1995) + || parseLangExt(sw, "+verilog2001ext+", V3LangCode::L1364_2001) + || parseLangExt(sw, "+1364-1995ext+", V3LangCode::L1364_1995) + || parseLangExt(sw, "+1364-2001ext+", V3LangCode::L1364_2001) + || parseLangExt(sw, "+1364-2005ext+", V3LangCode::L1364_2005) + || parseLangExt(sw, "+1800-2005ext+", V3LangCode::L1800_2005) + || parseLangExt(sw, "+1800-2009ext+", V3LangCode::L1800_2009)) { + // Nothing to do here - all done in the test + + } else if ( !strncmp (sw, "+libext+", 8)) { string exts = string(sw+strlen("+libext+")); string::size_type pos; @@ -695,7 +734,7 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char else if ( onoff (sw, "-skip-identical", flag/*ref*/) ) { m_skipIdentical = flag; } else if ( !strcmp (sw, "-sp") ) { m_outFormatOk = true; m_systemC = true; m_systemPerl = true; } else if ( onoff (sw, "-stats", flag/*ref*/) ) { m_stats = flag; } - else if ( !strcmp (sw, "-sv") ) { m_language = V3LangCode::L1800_2005; } + else if ( !strcmp (sw, "-sv") ) { m_defaultLanguage = V3LangCode::L1800_2005; } else if ( onoff (sw, "-trace", flag/*ref*/) ) { m_trace = flag; } else if ( onoff (sw, "-trace-dups", flag/*ref*/) ) { m_traceDups = flag; } else if ( onoff (sw, "-trace-underscore", flag/*ref*/) ) { m_traceUnderscore = flag; } @@ -779,11 +818,12 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char shift; addLdLibs(argv[i]); } - else if ( !strcmp (sw, "-language") && (i+1)v3fatal("Unknown language specified: "< #include "V3Global.h" - -//###################################################################### - -class V3LangCode { -public: - enum en { - L_ERROR, // Must be first. - L1364_1995, - L1364_2001, - L1364_2005, - L1800_2005, - L1800_2009, - // ***Add new elements below also*** - _ENUM_END - }; - const char* ascii() const { - const char* names[] = { - // These must match the `begin_keywords values. - " ERROR", - "1364-1995", - "1364-2001", - "1364-2005", - "1800-2005", - "1800-2009" - }; - return names[m_e]; - }; - static V3LangCode mostRecent() { return V3LangCode(L1800_2009); } - bool legal() const { return m_e != L_ERROR; } - // - enum en m_e; - inline V3LangCode () : m_e(L_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(_e)) {} - operator en () const { return m_e; } -}; +#include "V3LangCode.h" //###################################################################### // V3Options - Command line options @@ -156,8 +120,9 @@ class V3Options { string m_unusedRegexp; // main switch: --unused-regexp string m_xAssign; // main switch: --x-assign - // Consider moving m_language into FileLine, so can know language per-node - V3LangCode m_language; // main switch: --language + // Language is now held in FileLine, on a per-node basis. However we still + // have a concept of the default language at a global level. + V3LangCode m_defaultLanguage; // main switch: --language // MEMBERS (optimizations) // // main switch: -Op: --public @@ -185,6 +150,7 @@ class V3Options { void addFuture(const string& flag); void addIncDirUser(const string& incdir); // User requested void addIncDirFallback(const string& incdir); // Low priority if not found otherwise + void addLangExt(const string &langext, const V3LangCode lc); void addLibExtV(const string& libext); void optimize(int level); void showVersion(bool verbose); @@ -192,6 +158,7 @@ class V3Options { bool onoff(const char* sw, const char* arg, bool& flag); bool suffixed(const char* sw, const char* arg); string parseFileArg(const string& optdir, const string& relfilename); + bool parseLangExt(const char* swp, const char* langswp, const V3LangCode lc); string filePathCheckOneDir(const string& modname, const string& dirname); static string getenvStr(const string& envvar, const string& defaultValue); @@ -288,7 +255,7 @@ class V3Options { const V3StringSet& ldLibs() const { return m_ldLibs; } const V3StringSet& libraryFiles() const { return m_libraryFiles; } const V3StringList& vFiles() const { return m_vFiles; } - const V3LangCode& language() const { return m_language; } + const V3LangCode& defaultLanguage() const { return m_defaultLanguage; } bool isFuture(const string& flag) const; bool isLibraryFile(const string& filename) const; @@ -351,6 +318,7 @@ class V3Options { string fileExists (const string& filename); string filePath (FileLine* fl, const string& modname, const string& errmsg); void filePathLookedMsg(FileLine* fl, const string& modname); + V3LangCode fileLanguage(const string &filename); static bool fileStatDir (const string& filename); static bool fileStatNormal (const string& filename); diff --git a/src/V3ParseImp.cpp b/src/V3ParseImp.cpp index 9647e101d..20f85c973 100644 --- a/src/V3ParseImp.cpp +++ b/src/V3ParseImp.cpp @@ -100,8 +100,12 @@ void V3ParseImp::parseFile(FileLine* fileline, const string& modfilename, bool i // 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"); + // 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->updateLanguage(); + ppPushText((string)"`begin_keywords \""+modfileline->language().ascii()+"\"\n"); } // Preprocess into m_ppBuffer diff --git a/test_regress/t/t_langext_1.pl b/test_regress/t/t_langext_1.pl new file mode 100755 index 000000000..27eeba84b --- /dev/null +++ b/test_regress/t/t_langext_1.pl @@ -0,0 +1,16 @@ +#!/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. + +# This is a compile only test. +compile ( + v_flags2 => ["+verilog2001ext+v"], + ); + +ok(1); +1; diff --git a/test_regress/t/t_langext_1.v b/test_regress/t/t_langext_1.v new file mode 100644 index 000000000..db02848ed --- /dev/null +++ b/test_regress/t/t_langext_1.v @@ -0,0 +1,51 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// A test of the +verilog1995ext+ and +verilog2001ext+ flags. +// +// This source code contains constructs that are valid in Verilog 2001 and +// SystemVerilog 2005/2009, but not in Verilog 1995. So it should fail if we +// set the language to be 1995, but not 2001. +// +// Compile only test, so no need for "All Finished" output. +// +// This file ONLY is placed into the Public Domain, for any use, +// without warranty, 2012 by Jeremy Bennett. + +module t (/*AUTOARG*/ + // Inputs + clk + ); + input clk; + + reg [1:0] res; + + // Instantiate the test + test test_i (/*AUTOINST*/ + // Outputs + .res (res), + // Inputs + .clk (clk), + .in (1'b1)); + +endmodule + +module test (// Outputs + res, + // Inputs + clk, + in + ); + output [1:0] res; + input clk; + input in; + + // This is a Verilog 2001 test + generate + genvar i; + for (i=0; i<2; i=i+1) begin + always @(posedge clk) begin + res[i:i] <= in; + end + end + endgenerate +endmodule diff --git a/test_regress/t/t_langext_1_bad.pl b/test_regress/t/t_langext_1_bad.pl new file mode 100755 index 000000000..2a52c30b4 --- /dev/null +++ b/test_regress/t/t_langext_1_bad.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. + +top_filename("t/t_langext_1.v"); + +# This is a compile only test. +compile ( + v_flags2 => ["+verilog1995ext+v"], + fails => 1 + ); + +ok(1); +1; diff --git a/test_regress/t/t_langext_2.pl b/test_regress/t/t_langext_2.pl new file mode 100755 index 000000000..c4138df15 --- /dev/null +++ b/test_regress/t/t_langext_2.pl @@ -0,0 +1,16 @@ +#!/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. + +# This is a compile only test. +compile ( + v_flags2 => ["+systemverilogext+v"], + ); + +ok(1); +1; diff --git a/test_regress/t/t_langext_2.v b/test_regress/t/t_langext_2.v new file mode 100644 index 000000000..96c00d892 --- /dev/null +++ b/test_regress/t/t_langext_2.v @@ -0,0 +1,55 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// A test of the +1364-1995ext+ and +systemverilogext+ flags. +// +// This source code contains constructs that are valid in SystemVerilog 2009 +// but not in Verilog 1995. So it should fail if we set the language to be +// Verilog 1995, but not SystemVerilog 2009. +// +// Compile only test, so no need for "All Finished" output. +// +// This file ONLY is placed into the Public Domain, for any use, +// without warranty, 2012 by Jeremy Bennett. + +module t (/*AUTOARG*/ + // Inputs + clk + ); + input clk; + + reg [1:0] res; + + + // Instantiate the test + test test_i (/*AUTOINST*/ + // Outputs + .res (res), + // Inputs + .clk (clk), + .in (1'b1)); + +endmodule + +module test (// Outputs + res, + // Inputs + clk, + in + ); + output [1:0] res; + input clk; + input in; + + // This is a SystemVerilog 2009 only test + generate + genvar i; + for (i=0; i<2; i=i+1) begin + always @(posedge clk) begin + unique0 case (i) + 0: res[0:0] <= in; + 1: res[1:1] <= in; + endcase + end + end + endgenerate +endmodule diff --git a/test_regress/t/t_langext_2_bad.pl b/test_regress/t/t_langext_2_bad.pl new file mode 100755 index 000000000..b0c2df446 --- /dev/null +++ b/test_regress/t/t_langext_2_bad.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. + +top_filename("t/t_langext_2.v"); + +# This is a compile only test. +compile ( + v_flags2 => ["+1364-1995ext+v"], + fails => 1 + ); + +ok(1); +1; diff --git a/test_regress/t/t_langext_3.pl b/test_regress/t/t_langext_3.pl new file mode 100755 index 000000000..4a402cf79 --- /dev/null +++ b/test_regress/t/t_langext_3.pl @@ -0,0 +1,16 @@ +#!/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. + +# This is a compile only test. +compile ( + v_flags2 => ["+1364-2005ext+v"], + ); + +ok(1); +1; diff --git a/test_regress/t/t_langext_3.v b/test_regress/t/t_langext_3.v new file mode 100644 index 000000000..fbe69ea72 --- /dev/null +++ b/test_regress/t/t_langext_3.v @@ -0,0 +1,21 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// A test of the +verilog2001ext+ and +verilog2005ext+ flags. +// +// This source code uses the uwire declaration, which is only valid in Verilog +// 2005. +// +// Compile only test, so no need for "All Finished" output. +// +// This file ONLY is placed into the Public Domain, for any use, +// without warranty, 2012 by Jeremy Bennett. + +module t (/*AUTOARG*/ + // Inputs + clk + ); + input clk; + + uwire w; // Only in Verilog 2005 + +endmodule diff --git a/test_regress/t/t_langext_3_bad.pl b/test_regress/t/t_langext_3_bad.pl new file mode 100755 index 000000000..760ff0d90 --- /dev/null +++ b/test_regress/t/t_langext_3_bad.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. + +top_filename("t/t_langext_3.v"); + +# This is a compile only test. +compile ( + v_flags2 => ["+1364-2001ext+v"], + fails => 1 + ); + +ok(1); +1; diff --git a/test_regress/t/t_langext_4.pl b/test_regress/t/t_langext_4.pl new file mode 100755 index 000000000..0f1a1c416 --- /dev/null +++ b/test_regress/t/t_langext_4.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. + +top_filename("t/t_langext_2.v"); + +# This is a compile only test. +compile ( + v_flags2 => ["+1800-2009ext+v"], + ); + +ok(1); +1; diff --git a/test_regress/t/t_langext_4_bad.pl b/test_regress/t/t_langext_4_bad.pl new file mode 100755 index 000000000..f8cc066ee --- /dev/null +++ b/test_regress/t/t_langext_4_bad.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. + +top_filename("t/t_langext_2.v"); + +# This is a compile only test. +compile ( + v_flags2 => ["+1800-2005ext+v"], + fails => 1 + ); + +ok(1); +1;