Internals: Factor out creating clocking event. No functional change.

Signed-off-by: Arkadiusz Kozdra <akozdra@antmicro.com>
This commit is contained in:
Arkadiusz Kozdra 2024-09-04 10:05:15 +02:00 committed by Wilson Snyder
parent e4ff0909dc
commit 409efa1249
4 changed files with 22 additions and 37 deletions

View File

@ -961,6 +961,7 @@ public:
std::string name() const override VL_MT_STABLE { return m_name; }
bool isDefault() const { return m_isDefault; }
bool isGlobal() const { return m_isGlobal; }
AstVar* ensureEventp(bool childDType = false);
};
class AstClockingItem final : public AstNode {
// Parents: CLOCKING

View File

@ -327,6 +327,24 @@ AstNodeExpr* AstInsideRange::newAndFromInside(AstNodeExpr* exprp, AstNodeExpr* l
return new AstLogAnd{fileline(), ap, bp};
}
AstVar* AstClocking::ensureEventp(bool childDType) {
if (!eventp()) {
AstVar* const evp
= childDType ? new AstVar{fileline(), VVarType::MODULETEMP, m_name, VFlagChildDType{},
new AstBasicDType{fileline(), VBasicDTypeKwd::EVENT}}
: new AstVar{fileline(), VVarType::MODULETEMP, m_name,
findBasicDType(VBasicDTypeKwd::EVENT)};
evp->lifetime(VLifetime::STATIC);
eventp(evp);
// Trigger the clocking event in Observed (IEEE 1800-2023 14.13)
addNextHere(new AstAlwaysObserved{
fileline(), new AstSenTree{fileline(), sensesp()->cloneTree(false)},
new AstFireEvent{fileline(), new AstVarRef{fileline(), evp, VAccess::WRITE}, false}});
v3Global.setHasEvents();
}
return eventp();
}
void AstConsDynArray::dump(std::ostream& str) const {
this->AstNodeExpr::dump(str);
if (lhsIsValue()) str << " [LVAL]";

View File

@ -2267,22 +2267,7 @@ class LinkDotResolveVisitor final : public VNVisitor {
}
}
VSymEnt* getCreateClockingEventSymEnt(AstClocking* clockingp) {
if (!clockingp->eventp()) {
AstVar* const eventp = new AstVar{
clockingp->fileline(), VVarType::MODULETEMP, clockingp->name(), VFlagChildDType{},
new AstBasicDType{clockingp->fileline(), VBasicDTypeKwd::EVENT}};
eventp->lifetime(VLifetime::STATIC);
clockingp->eventp(eventp);
// Trigger the clocking event in Observed (IEEE 1800-2023 14.13)
clockingp->addNextHere(new AstAlwaysObserved{
clockingp->fileline(),
new AstSenTree{clockingp->fileline(), clockingp->sensesp()->cloneTree(false)},
new AstFireEvent{clockingp->fileline(),
new AstVarRef{clockingp->fileline(), eventp, VAccess::WRITE},
false}});
v3Global.setHasEvents();
}
AstVar* const eventp = clockingp->eventp();
AstVar* const eventp = clockingp->ensureEventp(true);
if (!eventp->user1p()) eventp->user1p(new VSymEnt{m_statep->symsp(), eventp});
return reinterpret_cast<VSymEnt*>(eventp->user1p());
}

View File

@ -2911,27 +2911,8 @@ class WidthVisitor final : public VNVisitor {
if (memberSelClass(nodep, adtypep)) return;
} else if (AstIfaceRefDType* const adtypep = VN_CAST(fromDtp, IfaceRefDType)) {
if (AstNode* foundp = memberSelIface(nodep, adtypep)) {
if (AstClocking* const clockingp = VN_CAST(foundp, Clocking)) {
foundp = clockingp->eventp();
if (!foundp) {
AstVar* const eventp = new AstVar{
clockingp->fileline(), VVarType::MODULETEMP, clockingp->name(),
clockingp->findBasicDType(VBasicDTypeKwd::EVENT)};
eventp->lifetime(VLifetime::STATIC);
clockingp->eventp(eventp);
// Trigger the clocking event in Observed (IEEE 1800-2023 14.13)
clockingp->addNextHere(new AstAlwaysObserved{
clockingp->fileline(),
new AstSenTree{clockingp->fileline(),
clockingp->sensesp()->cloneTree(false)},
new AstFireEvent{
clockingp->fileline(),
new AstVarRef{clockingp->fileline(), eventp, VAccess::WRITE},
false}});
v3Global.setHasEvents();
foundp = eventp;
}
}
if (AstClocking* const clockingp = VN_CAST(foundp, Clocking))
foundp = clockingp->ensureEventp();
if (AstVar* const varp = VN_CAST(foundp, Var)) {
if (!varp->didWidth()) userIterate(varp, nullptr);
nodep->dtypep(foundp->dtypep());