mirror of
https://github.com/verilator/verilator.git
synced 2026-10-06 01:54:01 +02:00
Change package import/export to link post-parsing, prep for later commit.
This commit is contained in:
+30
-4
@@ -1339,19 +1339,32 @@ class AstPackageExport final : public AstNode {
|
||||
// A package export declaration
|
||||
//
|
||||
// @astgen ptr := m_packagep : Optional[AstPackage] // Package hierarchy
|
||||
string m_name;
|
||||
string m_name; // What imported e.g. "*"
|
||||
string m_pkgName; // Module the cell instances
|
||||
|
||||
public:
|
||||
AstPackageExport(FileLine* fl, AstPackage* packagep, const string& name)
|
||||
: ASTGEN_SUPER_PackageExport(fl)
|
||||
, m_name{name}
|
||||
, m_packagep{packagep} {}
|
||||
, m_packagep{packagep} {
|
||||
pkgNameFrom();
|
||||
}
|
||||
AstPackageExport(FileLine* fl, const string& pkgName, const string& name)
|
||||
: ASTGEN_SUPER_PackageExport(fl)
|
||||
, m_name{name}
|
||||
, m_pkgName{pkgName}
|
||||
, m_packagep{nullptr} {}
|
||||
ASTGEN_MEMBERS_AstPackageExport;
|
||||
void dump(std::ostream& str) const override;
|
||||
void dumpJson(std::ostream& str) const override;
|
||||
string name() const override VL_MT_STABLE { return m_name; }
|
||||
string pkgName() const VL_MT_STABLE { return m_pkgName; }
|
||||
string prettyPkgNameQ() const { return "'" + prettyName(pkgName()) + "'"; }
|
||||
AstPackage* packagep() const { return m_packagep; }
|
||||
void packagep(AstPackage* nodep) { m_packagep = nodep; }
|
||||
|
||||
private:
|
||||
void pkgNameFrom();
|
||||
};
|
||||
class AstPackageExportStarStar final : public AstNode {
|
||||
// A package export *::* declaration
|
||||
@@ -1365,19 +1378,32 @@ class AstPackageImport final : public AstNode {
|
||||
// A package import declaration
|
||||
//
|
||||
// @astgen ptr := m_packagep : Optional[AstPackage] // Package hierarchy
|
||||
string m_name;
|
||||
string m_name; // What imported e.g. "*"
|
||||
string m_pkgName; // Module the cell instances
|
||||
|
||||
public:
|
||||
AstPackageImport(FileLine* fl, AstPackage* packagep, const string& name)
|
||||
: ASTGEN_SUPER_PackageImport(fl)
|
||||
, m_name{name}
|
||||
, m_packagep{packagep} {}
|
||||
, m_packagep{packagep} {
|
||||
pkgNameFrom();
|
||||
}
|
||||
AstPackageImport(FileLine* fl, const string& pkgName, const string& name)
|
||||
: ASTGEN_SUPER_PackageImport(fl)
|
||||
, m_name{name}
|
||||
, m_pkgName{pkgName}
|
||||
, m_packagep{nullptr} {}
|
||||
ASTGEN_MEMBERS_AstPackageImport;
|
||||
void dump(std::ostream& str) const override;
|
||||
void dumpJson(std::ostream& str) const override;
|
||||
string name() const override VL_MT_STABLE { return m_name; }
|
||||
string pkgName() const VL_MT_STABLE { return m_pkgName; }
|
||||
string prettyPkgNameQ() const { return "'" + prettyName(pkgName()) + "'"; }
|
||||
AstPackage* packagep() const { return m_packagep; }
|
||||
void packagep(AstPackage* nodep) { m_packagep = nodep; }
|
||||
|
||||
private:
|
||||
void pkgNameFrom();
|
||||
};
|
||||
class AstPin final : public AstNode {
|
||||
// A port or parameter assignment on an instantiation
|
||||
|
||||
+16
-2
@@ -2196,14 +2196,28 @@ void AstNodeModule::dumpJson(std::ostream& str) const {
|
||||
}
|
||||
void AstPackageExport::dump(std::ostream& str) const {
|
||||
this->AstNode::dump(str);
|
||||
str << " -> " << packagep();
|
||||
if (packagep()) {
|
||||
str << " -> " << packagep();
|
||||
} else {
|
||||
str << " ->UNLINKED:" << pkgName();
|
||||
}
|
||||
}
|
||||
void AstPackageExport::dumpJson(std::ostream& str) const { dumpJsonGen(str); }
|
||||
void AstPackageExport::pkgNameFrom() {
|
||||
if (packagep()) m_pkgName = packagep()->name();
|
||||
}
|
||||
void AstPackageImport::dump(std::ostream& str) const {
|
||||
this->AstNode::dump(str);
|
||||
str << " -> " << packagep();
|
||||
if (packagep()) {
|
||||
str << " -> " << packagep();
|
||||
} else {
|
||||
str << " ->UNLINKED:" << pkgName();
|
||||
}
|
||||
}
|
||||
void AstPackageImport::dumpJson(std::ostream& str) const { dumpJsonGen(str); }
|
||||
void AstPackageImport::pkgNameFrom() {
|
||||
if (packagep()) m_pkgName = packagep()->name();
|
||||
}
|
||||
void AstPatMember::dump(std::ostream& str) const {
|
||||
this->AstNodeExpr::dump(str);
|
||||
if (isDefault()) str << " [DEFAULT]";
|
||||
|
||||
+21
-1
@@ -247,10 +247,30 @@ class LinkCellsVisitor final : public VNVisitor {
|
||||
// Note cannot do modport resolution here; modports are allowed underneath generates
|
||||
}
|
||||
|
||||
void visit(AstPackageExport* nodep) override {
|
||||
// Package Import: We need to do the package before the use of a package
|
||||
iterateChildren(nodep);
|
||||
if (!nodep->packagep()) {
|
||||
AstNodeModule* const modp = resolveModule(nodep, nodep->pkgName());
|
||||
if (AstPackage* const pkgp = VN_CAST(modp, Package)) nodep->packagep(pkgp);
|
||||
if (!nodep->packagep()) {
|
||||
nodep->v3error("Export package not found: " << nodep->prettyPkgNameQ());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
void visit(AstPackageImport* nodep) override {
|
||||
// Package Import: We need to do the package before the use of a package
|
||||
iterateChildren(nodep);
|
||||
UASSERT_OBJ(nodep->packagep(), nodep, "Unlinked package"); // Parser should set packagep
|
||||
if (!nodep->packagep()) {
|
||||
AstNodeModule* const modp = resolveModule(nodep, nodep->pkgName());
|
||||
if (AstPackage* const pkgp = VN_CAST(modp, Package)) nodep->packagep(pkgp);
|
||||
// If not found, V3LinkDot will report errors
|
||||
if (!nodep->packagep()) {
|
||||
nodep->v3error("Import package not found: " << nodep->prettyPkgNameQ());
|
||||
return;
|
||||
}
|
||||
}
|
||||
new V3GraphEdge{&m_graph, vertex(m_modp), vertex(nodep->packagep()), 1, false};
|
||||
}
|
||||
|
||||
|
||||
+3
-4
@@ -1496,6 +1496,7 @@ class LinkDotFindVisitor final : public VNVisitor {
|
||||
}
|
||||
void visit(AstPackageImport* nodep) override {
|
||||
UINFO(4, " Link: " << nodep << endl);
|
||||
if (!nodep->packagep()) return; // Errored in V3LinkCells
|
||||
VSymEnt* const srcp = m_statep->getNodeSym(nodep->packagep());
|
||||
if (nodep->name() == "*") {
|
||||
if (nodep->packagep() != v3Global.rootp()->stdPackagep()) {
|
||||
@@ -1506,10 +1507,7 @@ class LinkDotFindVisitor final : public VNVisitor {
|
||||
}
|
||||
} else {
|
||||
VSymEnt* const impp = srcp->findIdFlat(nodep->name());
|
||||
if (!impp) {
|
||||
nodep->v3error("Import object not found: '" << nodep->packagep()->prettyName()
|
||||
<< "::" << nodep->prettyName() << "'");
|
||||
}
|
||||
if (!impp) { nodep->v3error("Import object not found: " << nodep->prettyPkgNameQ()); }
|
||||
}
|
||||
m_curSymp->importFromPackage(m_statep->symsp(), srcp, nodep->name());
|
||||
UINFO(9, " Link Done: " << nodep << endl);
|
||||
@@ -1517,6 +1515,7 @@ class LinkDotFindVisitor final : public VNVisitor {
|
||||
}
|
||||
void visit(AstPackageExport* nodep) override {
|
||||
UINFO(9, " Link: " << nodep << endl);
|
||||
if (!nodep->packagep()) return; // Errored in V3LinkCells
|
||||
VSymEnt* const srcp = m_statep->getNodeSym(nodep->packagep());
|
||||
if (nodep->name() != "*") {
|
||||
VSymEnt* const impp = srcp->findIdFlat(nodep->name());
|
||||
|
||||
+2
-2
@@ -1325,7 +1325,7 @@ package_import_item<nodep>: // ==IEEE: package_import_item
|
||||
$$ = nullptr;
|
||||
$<fl>1->v3error("Importing from missing package '" << *$<strp>1 << "'");
|
||||
} else {
|
||||
$$ = new AstPackageImport{$<fl>2, VN_CAST($<scp>1, Package), *$3};
|
||||
$$ = new AstPackageImport{$<fl>2, *$<strp>1, *$3};
|
||||
SYMP->importItem($<scp>1, *$3);
|
||||
} }
|
||||
;
|
||||
@@ -1348,7 +1348,7 @@ package_export_itemList<nodep>:
|
||||
|
||||
package_export_item<nodep>: // ==IEEE: package_export_item
|
||||
idCC yP_COLONCOLON package_import_itemObj
|
||||
{ $$ = new AstPackageExport{$<fl>3, VN_CAST($<scp>1, Package), *$3};
|
||||
{ $$ = new AstPackageExport{$<fl>3, *$<strp>1, *$3};
|
||||
if ($<scp>1) SYMP->exportItem($<scp>1, *$3); }
|
||||
;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user