Fix implicit dtype numbering to be per-module.
Internals: Remove use of parser in implicit dtype numbering.
This commit is contained in:
parent
d5f773f385
commit
b099d6fe63
|
|
@ -666,16 +666,12 @@ class AstDefImplicitDType final : public AstNodeDType {
|
||||||
// After link, these become typedefs
|
// After link, these become typedefs
|
||||||
// @astgen op1 := childDTypep : Optional[AstNodeDType]
|
// @astgen op1 := childDTypep : Optional[AstNodeDType]
|
||||||
string m_name;
|
string m_name;
|
||||||
void* m_containerp; // In what scope is the name unique, so we can know what are duplicate
|
|
||||||
// definitions (arbitrary value)
|
|
||||||
const int m_uniqueNum;
|
const int m_uniqueNum;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AstDefImplicitDType(FileLine* fl, const string& name, void* containerp, VFlagChildDType,
|
AstDefImplicitDType(FileLine* fl, const string& name, VFlagChildDType, AstNodeDType* dtp)
|
||||||
AstNodeDType* dtp)
|
|
||||||
: ASTGEN_SUPER_DefImplicitDType(fl)
|
: ASTGEN_SUPER_DefImplicitDType(fl)
|
||||||
, m_name{name}
|
, m_name{name}
|
||||||
, m_containerp{containerp}
|
|
||||||
, m_uniqueNum{uniqueNumInc()} {
|
, m_uniqueNum{uniqueNumInc()} {
|
||||||
childDTypep(dtp); // Only for parser
|
childDTypep(dtp); // Only for parser
|
||||||
dtypep(nullptr); // V3Width will resolve
|
dtypep(nullptr); // V3Width will resolve
|
||||||
|
|
@ -683,7 +679,6 @@ public:
|
||||||
AstDefImplicitDType(const AstDefImplicitDType& other)
|
AstDefImplicitDType(const AstDefImplicitDType& other)
|
||||||
: AstNodeDType(other)
|
: AstNodeDType(other)
|
||||||
, m_name(other.m_name)
|
, m_name(other.m_name)
|
||||||
, m_containerp(other.m_containerp)
|
|
||||||
, m_uniqueNum(uniqueNumInc()) {}
|
, m_uniqueNum(uniqueNumInc()) {}
|
||||||
ASTGEN_MEMBERS_AstDefImplicitDType;
|
ASTGEN_MEMBERS_AstDefImplicitDType;
|
||||||
int uniqueNum() const { return m_uniqueNum; }
|
int uniqueNum() const { return m_uniqueNum; }
|
||||||
|
|
@ -696,7 +691,6 @@ public:
|
||||||
AstNodeDType* subDTypep() const override VL_MT_STABLE {
|
AstNodeDType* subDTypep() const override VL_MT_STABLE {
|
||||||
return dtypep() ? dtypep() : childDTypep();
|
return dtypep() ? dtypep() : childDTypep();
|
||||||
}
|
}
|
||||||
void* containerp() const { return m_containerp; }
|
|
||||||
// METHODS
|
// METHODS
|
||||||
// op1 = Range of variable
|
// op1 = Range of variable
|
||||||
AstNodeDType* dtypeSkipRefp() const { return dtypep()->skipRefp(); }
|
AstNodeDType* dtypeSkipRefp() const { return dtypep()->skipRefp(); }
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ class LinkParseVisitor final : public VNVisitor {
|
||||||
const VNUser2InUse m_inuser2;
|
const VNUser2InUse m_inuser2;
|
||||||
|
|
||||||
// TYPES
|
// TYPES
|
||||||
using ImplTypedefMap = std::map<const std::pair<void*, std::string>, AstTypedef*>;
|
using ImplTypedefMap = std::map<std::string, AstTypedef*>;
|
||||||
|
|
||||||
// STATE
|
// STATE
|
||||||
AstVar* m_varp = nullptr; // Variable we're under
|
AstVar* m_varp = nullptr; // Variable we're under
|
||||||
|
|
@ -498,14 +498,14 @@ class LinkParseVisitor final : public VNVisitor {
|
||||||
cleanFileline(nodep);
|
cleanFileline(nodep);
|
||||||
UINFO(8, " DEFIMPLICIT " << nodep << endl);
|
UINFO(8, " DEFIMPLICIT " << nodep << endl);
|
||||||
// Must remember what names we've already created, and combine duplicates
|
// Must remember what names we've already created, and combine duplicates
|
||||||
// so that for "var enum {...} a,b" a & b will share a common typedef
|
// so that for "var enum {...} a,b" a & b will share a common typedef.
|
||||||
// Unique name space under each containerp() so that an addition of
|
// Change to unique name space per module so that an addition of
|
||||||
// a new type won't change every verilated module.
|
// a new type won't change every verilated module.
|
||||||
AstTypedef* defp = nullptr;
|
AstTypedef* defp = nullptr;
|
||||||
const ImplTypedefMap::iterator it
|
const ImplTypedefMap::iterator it = m_implTypedef.find(nodep->name());
|
||||||
= m_implTypedef.find(std::make_pair(nodep->containerp(), nodep->name()));
|
|
||||||
if (it != m_implTypedef.end()) {
|
if (it != m_implTypedef.end()) {
|
||||||
defp = it->second;
|
defp = it->second;
|
||||||
|
UINFO(9, "Reused impltypedef " << nodep << " --> " << defp << endl);
|
||||||
} else {
|
} else {
|
||||||
// Definition must be inserted right after the variable (etc) that needed it
|
// Definition must be inserted right after the variable (etc) that needed it
|
||||||
// AstVar, AstTypedef, AstNodeFTask are common containers
|
// AstVar, AstTypedef, AstNodeFTask are common containers
|
||||||
|
|
@ -526,7 +526,11 @@ class LinkParseVisitor final : public VNVisitor {
|
||||||
} else {
|
} else {
|
||||||
defp = new AstTypedef{nodep->fileline(), nodep->name(), nullptr, VFlagChildDType{},
|
defp = new AstTypedef{nodep->fileline(), nodep->name(), nullptr, VFlagChildDType{},
|
||||||
dtypep};
|
dtypep};
|
||||||
m_implTypedef.emplace(std::make_pair(nodep->containerp(), defp->name()), defp);
|
m_implTypedef.emplace(defp->name(), defp);
|
||||||
|
// Rename so that name doesn't change if a type is added/removed elsewhere
|
||||||
|
// But the m_implTypedef is stil by old name so we can find it for next new lookups
|
||||||
|
defp->name("__typeimpmod" + cvtToStr(m_implTypedef.size()));
|
||||||
|
UINFO(9, "New impltypedef " << defp << endl);
|
||||||
backp->addNextHere(defp);
|
backp->addNextHere(defp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -618,6 +622,7 @@ class LinkParseVisitor final : public VNVisitor {
|
||||||
VL_RESTORER(m_genblkAbove);
|
VL_RESTORER(m_genblkAbove);
|
||||||
VL_RESTORER(m_genblkNum);
|
VL_RESTORER(m_genblkNum);
|
||||||
VL_RESTORER(m_beginDepth);
|
VL_RESTORER(m_beginDepth);
|
||||||
|
VL_RESTORER(m_implTypedef);
|
||||||
VL_RESTORER(m_lifetime);
|
VL_RESTORER(m_lifetime);
|
||||||
VL_RESTORER(m_lifetimeAllowed);
|
VL_RESTORER(m_lifetimeAllowed);
|
||||||
{
|
{
|
||||||
|
|
@ -630,6 +635,7 @@ class LinkParseVisitor final : public VNVisitor {
|
||||||
m_genblkAbove = 0;
|
m_genblkAbove = 0;
|
||||||
m_genblkNum = 0;
|
m_genblkNum = 0;
|
||||||
m_beginDepth = 0;
|
m_beginDepth = 0;
|
||||||
|
m_implTypedef.clear();
|
||||||
m_valueModp = nodep;
|
m_valueModp = nodep;
|
||||||
m_lifetime = nodep->lifetime();
|
m_lifetime = nodep->lifetime();
|
||||||
m_lifetimeAllowed = VN_IS(nodep, Class);
|
m_lifetimeAllowed = VN_IS(nodep, Class);
|
||||||
|
|
|
||||||
|
|
@ -749,7 +749,12 @@ int V3ParseImp::tokenToBison() {
|
||||||
// V3ParseBisonYYSType functions
|
// V3ParseBisonYYSType functions
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& os, const V3ParseBisonYYSType& rhs) {
|
std::ostream& operator<<(std::ostream& os, const V3ParseBisonYYSType& rhs) {
|
||||||
os << "TOKEN {" << rhs.fl->filenameLetters() << rhs.fl->asciiLineCol() << "}";
|
os << "TOKEN {";
|
||||||
|
if (VL_UNCOVERABLE(!rhs.fl))
|
||||||
|
os << "%E-null-fileline";
|
||||||
|
else
|
||||||
|
os << rhs.fl->filenameLetters() << rhs.fl->asciiLineCol();
|
||||||
|
os << "}";
|
||||||
os << "=" << rhs.token << " " << V3ParseImp::tokenName(rhs.token);
|
os << "=" << rhs.token << " " << V3ParseImp::tokenName(rhs.token);
|
||||||
if (rhs.token == yaID__ETC //
|
if (rhs.token == yaID__ETC //
|
||||||
|| rhs.token == yaID__CC //
|
|| rhs.token == yaID__CC //
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,7 @@ public:
|
||||||
int m_pinNum = -1; // Pin number currently parsing
|
int m_pinNum = -1; // Pin number currently parsing
|
||||||
std::stack<int> m_pinStack; // Queue of pin numbers being parsed
|
std::stack<int> m_pinStack; // Queue of pin numbers being parsed
|
||||||
|
|
||||||
static int s_modTypeImpNum; // Implicit type number, incremented each module
|
static int s_typeImpNum; // Implicit type number, incremented each module
|
||||||
|
|
||||||
// CONSTRUCTORS
|
// CONSTRUCTORS
|
||||||
V3ParseGrammar() {}
|
V3ParseGrammar() {}
|
||||||
|
|
@ -300,7 +300,7 @@ public:
|
||||||
const VBasicDTypeKwd LOGIC = VBasicDTypeKwd::LOGIC; // Shorthand "LOGIC"
|
const VBasicDTypeKwd LOGIC = VBasicDTypeKwd::LOGIC; // Shorthand "LOGIC"
|
||||||
const VBasicDTypeKwd LOGIC_IMPLICIT = VBasicDTypeKwd::LOGIC_IMPLICIT;
|
const VBasicDTypeKwd LOGIC_IMPLICIT = VBasicDTypeKwd::LOGIC_IMPLICIT;
|
||||||
|
|
||||||
int V3ParseGrammar::s_modTypeImpNum = 0;
|
int V3ParseGrammar::s_typeImpNum = 0;
|
||||||
|
|
||||||
//======================================================================
|
//======================================================================
|
||||||
// Macro functions
|
// Macro functions
|
||||||
|
|
@ -2233,12 +2233,12 @@ data_typeNoRef<nodeDTypep>: // ==IEEE: data_type, excluding class_ty
|
||||||
| struct_unionDecl packed_dimensionListE
|
| struct_unionDecl packed_dimensionListE
|
||||||
{ $$ = GRAMMARP->createArray(
|
{ $$ = GRAMMARP->createArray(
|
||||||
new AstDefImplicitDType{$1->fileline(),
|
new AstDefImplicitDType{$1->fileline(),
|
||||||
"__typeimpsu" + cvtToStr(GRAMMARP->s_modTypeImpNum++),
|
"__typeimpsu" + cvtToStr(GRAMMARP->s_typeImpNum++),
|
||||||
SYMP, VFlagChildDType{}, $1}, $2, true); }
|
VFlagChildDType{}, $1}, $2, true); }
|
||||||
| enumDecl
|
| enumDecl
|
||||||
{ $$ = new AstDefImplicitDType{$1->fileline(),
|
{ $$ = new AstDefImplicitDType{$1->fileline(),
|
||||||
"__typeimpenum" + cvtToStr(GRAMMARP->s_modTypeImpNum++),
|
"__typeimpenum" + cvtToStr(GRAMMARP->s_typeImpNum++),
|
||||||
SYMP, VFlagChildDType{}, $1}; }
|
VFlagChildDType{}, $1}; }
|
||||||
| ySTRING
|
| ySTRING
|
||||||
{ $$ = new AstBasicDType{$1, VBasicDTypeKwd::STRING}; }
|
{ $$ = new AstBasicDType{$1, VBasicDTypeKwd::STRING}; }
|
||||||
| yCHANDLE
|
| yCHANDLE
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
"int$[$:3]" ==? "int$[$:3]"
|
"int$[$:3]" ==? "int$[$:3]"
|
||||||
"bit$[]" ==? "bit$[]"
|
"bit$[]" ==? "bit$[]"
|
||||||
|
|
||||||
"enum{A=32'h0;B=32'h1;C=32'h63;}A::__typeimpenum1" ==? "enum{A=32'sd0,B=32'sd1,C=32'sd99}A::<unspecified>"
|
"enum{A=32'h0;B=32'h1;C=32'h63;}A::__typeimpmod1" ==? "enum{A=32'sd0,B=32'sd1,C=32'sd99}A::<unspecified>"
|
||||||
"struct{bit A;bit B;}t.AB_t" ==? "struct{bit A;bit B;}<some_have_typename>"
|
"struct{bit A;bit B;}t.AB_t" ==? "struct{bit A;bit B;}<some_have_typename>"
|
||||||
"struct{bit A;bit B;}t.AB_t$[0:9]" ==? "struct{bit A;bit B;}top.AB_t$[0:9]"
|
"struct{bit A;bit B;}t.AB_t$[0:9]" ==? "struct{bit A;bit B;}top.AB_t$[0:9]"
|
||||||
"union{bit A;bit B;}t.UAB_t" ==? "union{bit A;bit B;}"
|
"union{bit A;bit B;}t.UAB_t" ==? "union{bit A;bit B;}"
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
import vltest_bootstrap
|
import vltest_bootstrap
|
||||||
|
|
||||||
test.scenarios('simulator')
|
test.scenarios('simulator_st')
|
||||||
|
|
||||||
test.compile()
|
test.compile()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue