diff --git a/Changes b/Changes index 9cd7d5638..02aefa713 100644 --- a/Changes +++ b/Changes @@ -5,6 +5,8 @@ indicates the contributor was also the author of the fix; Thanks! * Verilator 3.877 devel +**** Fix very long module names, bug937. [Todd Strader] + **** Fix internal error on dotted refs into generates, bug958. [Jie Xu] **** Fix mis-optimizing public DPI functions, bug963. [Wei Song] diff --git a/src/V3Ast.cpp b/src/V3Ast.cpp index 8b577113a..65786faaa 100644 --- a/src/V3Ast.cpp +++ b/src/V3Ast.cpp @@ -28,6 +28,7 @@ #include "V3File.h" #include "V3Global.h" #include "V3Broken.h" +#include "V3String.h" //====================================================================== // Statics @@ -115,6 +116,10 @@ string AstNode::encodeName(const string& namein) { out += hex; } } + // Shorten names + // TODO long term use VName in place of "string name" + VName vname(out); + out = vname.hashedName(); return out; } diff --git a/src/V3Options.cpp b/src/V3Options.cpp index 8570953b8..edcd57786 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -711,6 +711,10 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char shift; addCFlags(argv[i]); } + else if ( !strcmp (sw, "-comp-limits-syms") && (i+1)30) { LongMap::iterator iter = m_longMap.find(longname); diff --git a/src/V3String.cpp b/src/V3String.cpp index fa417195e..151849bc2 100644 --- a/src/V3String.cpp +++ b/src/V3String.cpp @@ -21,9 +21,14 @@ #include "config_build.h" #include "verilatedos.h" +#include "V3Global.h" #include "V3String.h" #include "V3Error.h" + +size_t VName::s_minLength = 32; +size_t VName::s_maxLength = 0; // Disabled + //###################################################################### // Wildcard @@ -282,3 +287,24 @@ void VHashSha1::selfTest() { "9026e8faed6ef4ec5ae3ff049020d7f0af7abbbf", "kCboAu1u9Oxa4B8EkCDX8K96u78"); } + +//###################################################################### +// VName + +string VName::hashedName() { + if (m_name=="") return ""; + if (m_hashed!="") return m_hashed; // Memoized + if (s_maxLength==0 || m_name.length() < s_maxLength) { + m_hashed = m_name; + return m_hashed; + } else { + VHashSha1 hash(m_name); + string suffix = "__Vhsh"+hash.digestSymbol(); + if (s_minLength < s_maxLength) { + m_hashed = m_name.substr(0,s_minLength) + suffix; + } else { + m_hashed = suffix; + } + return m_hashed; + } +} diff --git a/src/V3String.h b/src/V3String.h index 1cf35abab..99c256e58 100644 --- a/src/V3String.h +++ b/src/V3String.h @@ -56,8 +56,8 @@ public: VHashSha1() { init(); } VHashSha1(const string& data) { init(); insert(data); } ~VHashSha1() {} + // METHODS - string digestBinary(); // Return digest as 20 character binary string digestHex(); // Return digest formatted as a hex string string digestSymbol(); // Return digest formatted as C symbol/base64ish @@ -81,6 +81,29 @@ private: void finalize(); // Process remaining data }; +//###################################################################### +// VName - string which contains a possibly hashed string +// TODO use this wherever there is currently a "string m_name" + +class VName { + string m_name; + string m_hashed; + + static size_t s_maxLength; // Length at which to start hashing + static size_t s_minLength; // Length to preserve if over maxLength +public: + // CONSTRUCTORS + VName (const string& name) : m_name(name) {} + ~VName() {} + // METHODS + void name(const string& name) { m_name = name; m_hashed = ""; } + string name() const { return m_name; } + string hashedName(); + // CONFIG STATIC METHORS + static void maxLength(size_t flag) { s_maxLength=flag; } // Length at which to start hashing, 0=disable + static size_t maxLength() { return s_maxLength; } +}; + //###################################################################### #endif // guard diff --git a/test_regress/t/t_mod_longname.pl b/test_regress/t/t_mod_longname.pl new file mode 100755 index 000000000..f91289753 --- /dev/null +++ b/test_regress/t/t_mod_longname.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. + +compile ( + ); + +execute ( + check_finished=>1, + ); + +ok(1); +1; diff --git a/test_regress/t/t_mod_longname.v b/test_regress/t/t_mod_longname.v new file mode 100644 index 000000000..8198fda02 --- /dev/null +++ b/test_regress/t/t_mod_longname.v @@ -0,0 +1,30 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// The code as shown makes a really big file name with Verilator. +// +// This file ONLY is placed into the Public Domain, for any use, +// without warranty, 2015 by Todd Strader. + +`define LONG_NAME_MOD modlongnameiuqyrewewriqyewroiquyweriuqyewriuyewrioryqoiewyriuewyrqrqioeyriuqyewriuqyeworqiurewyqoiuewyrqiuewoyewriuoeyqiuewryqiuewyroiqyewiuryqeiuwryuqiyreoiqyewiuryqewiruyqiuewyroiuqyewroiuyqewoiryqiewuyrqiuewyroqiyewriuqyewrewqroiuyqiuewyriuqyewroiqyewroiquewyriuqyewroiqewyriuqewyroiqyewroiyewoiuryqoiewyriuqyewiuryqoierwyqoiuewyrewoiuyqroiewuryewurqyoiweyrqiuewyreqwroiyweroiuyqweoiuryqiuewyroiuqyroie +`define LONG_NAME_SUB sublongnameiuqyrewewriqyewroiquyweriuqyewriuyewrioryqoiewyriuewyrqrqioeyriuqyewriuqyeworqiurewyqoiuewyrqiuewoyewriuoeyqiuewryqiuewyroiqyewiuryqeiuwryuqiyreoiqyewiuryqewiruyqiuewyroiuqyewroiuyqewoiryqiewuyrqiuewyroqiyewriuqyewrewqroiuyqiuewyriuqyewroiqyewroiquewyriuqyewroiqewyriuqewyroiqyewroiyewoiuryqoiewyriuqyewiuryqoierwyqoiuewyrewoiuyqroiewuryewurqyoiweyrqiuewyreqwroiyweroiuyqweoiuryqiuewyroiuqyroie +`define LONG_NAME_VAR varlongnameiuqyrewewriqyewroiquyweriuqyewriuyewrioryqoiewyriuewyrqrqioeyriuqyewriuqyeworqiurewyqoiuewyrqiuewoyewriuoeyqiuewryqiuewyroiqyewiuryqeiuwryuqiyreoiqyewiuryqewiruyqiuewyroiuqyewroiuyqewoiryqiewuyrqiuewyroqiyewriuqyewrewqroiuyqiuewyriuqyewroiqyewroiquewyriuqyewroiqewyriuqewyroiqyewroiyewoiuryqoiewyriuqyewiuryqoierwyqoiuewyrewoiuyqroiewuryewurqyoiweyrqiuewyreqwroiyweroiuyqweoiuryqiuewyroiuqyroie + +module t (); + + initial begin + $write("*-* All Finished *-*\n"); + $finish; + end + + logic `LONG_NAME_VAR; + + `LONG_NAME_MOD + `LONG_NAME_SUB + (); + +endmodule + +module `LONG_NAME_MOD (); + // Force Verilator to make a new class + logic a1 /* verilator public */; +endmodule