Fix very long module names, bug937.

This commit is contained in:
Wilson Snyder 2015-09-19 20:12:35 -04:00
parent 64748b7b1d
commit d0653f72e2
8 changed files with 112 additions and 1 deletions

View File

@ -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]

View File

@ -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;
}

View File

@ -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)<argc ) { // Undocumented
shift;
VName::maxLength(atoi(argv[i]));
}
else if ( !strcmp (sw, "-converge-limit") && (i+1)<argc ) {
shift;
m_convergeLimit = atoi(argv[i]);
@ -1190,6 +1194,8 @@ V3Options::V3Options() {
m_defaultLanguage = V3LangCode::mostRecent();
VName::maxLength(128); // Linux filename limits 256; leave half for prefix
optimize(true);
// Default +libext+
addLibExtV(""); // So include "filename.v" will find the same file

View File

@ -470,6 +470,7 @@ void ParamVisitor::visitCell(AstCell* nodep) {
} else {
// If the name is very long, we don't want to overwhelm the filename limit
// We don't do this always, as it aids debugability to have intuitive naming.
// TODO can use new V3Name hash replacement instead of this
string newname = longname;
if (longname.length()>30) {
LongMap::iterator iter = m_longMap.find(longname);

View File

@ -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;
}
}

View File

@ -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

View File

@ -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;

View File

@ -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