Support soft foreach in constraint (#8174)

This commit is contained in:
Kamil Danecki
2026-08-26 11:05:12 -04:00
committed by GitHub
parent 7f9333723f
commit f055eeabe0
8 changed files with 172 additions and 2 deletions
+8 -2
View File
@@ -1675,10 +1675,16 @@ public:
// === AstNodeForeach ===
class AstConstraintForeach final : public AstNodeForeach {
// Constraint foreach statement
bool m_soft; // is soft foreach, non-standard extension
public:
AstConstraintForeach(FileLine* fl, AstForeachHeader* headerp, AstNode* bodyp)
: ASTGEN_SUPER_ConstraintForeach(fl, headerp, bodyp) {}
AstConstraintForeach(FileLine* fl, AstForeachHeader* headerp, AstNode* bodyp,
bool soft = false)
: ASTGEN_SUPER_ConstraintForeach(fl, headerp, bodyp)
, m_soft{soft} {}
ASTGEN_MEMBERS_AstConstraintForeach;
bool isSoft() const { return m_soft; }
void dump(std::ostream& str) const override;
void dumpJson(std::ostream& str) const override;
};
class AstForeach final : public AstNodeForeach {
public:
+8
View File
@@ -2307,6 +2307,14 @@ void AstCover::dumpJson(std::ostream& str) const {
dumpJsonBoolFuncIf(str, isSeqEvent);
this->AstNodeCoverOrAssert::dumpJson(str);
}
void AstConstraintForeach::dump(std::ostream& str) const {
this->AstNodeForeach::dump(str);
if (isSoft()) str << "[SOFT]";
}
void AstConstraintForeach::dumpJson(std::ostream& str) const {
dumpJsonBoolFuncIf(str, isSoft);
dumpJsonGen(str);
}
void AstClocking::dump(std::ostream& str) const {
this->AstNode::dump(str);
if (isDefault()) str << " [DEFAULT]";
+6
View File
@@ -298,6 +298,12 @@ class LinkParseVisitor final : public VNVisitor {
v3Global.useRandomizeMethods(true);
iterateChildren(nodep);
}
void visit(AstConstraintForeach* nodep) override {
if (nodep->isSoft()) {
nodep->v3warn(NONSTD, "Non-standard soft foreach");
nodep->foreach([](AstConstraintExpr* exprp) { exprp->isSoft(true); });
}
}
void visit(AstEnumDType* nodep) override {
if (nodep->name() == "") {
nodep->name(nameFromTypedef(nodep)); // Might still remain ""
+3
View File
@@ -8166,6 +8166,9 @@ constraint_expression<nodep>: // ==IEEE: constraint_expression
// // IEEE says array_identifier here, but dotted accepted in VMM + 1800-2009
| yFOREACH '(' idClassSelForeach ')' constraint_set
{ $$ = new AstConstraintForeach{$1, $3, $5}; }
// // Non-IEEE extension, soft foreach
| ySOFT yFOREACH '(' idClassSelForeach ')' constraint_set
{ $$ = new AstConstraintForeach{$2, $4, $6, true}; }
// // soft is 1800-2012
| yDISABLE ySOFT constraint_primary ';'
{ AstConstraintExpr* const newp = new AstConstraintExpr{$1, $3};