Add parsing but otherwise ignore std::randomize (#5354)

This commit is contained in:
Arkadiusz Kozdra
2024-08-09 17:21:32 -04:00
committed by GitHub
parent f4acc59b82
commit 367249ec84
6 changed files with 70 additions and 4 deletions
+9 -4
View File
@@ -1508,11 +1508,15 @@ class LinkDotFindVisitor final : public VNVisitor {
void visit(AstWithParse* nodep) override {
// Change WITHPARSE(FUNCREF, equation) to FUNCREF(WITH(equation))
const auto funcrefp = VN_AS(nodep->funcrefp(), NodeFTaskRef);
AstNodeFTaskRef* funcrefp = VN_CAST(nodep->funcrefp(), NodeFTaskRef);
if (const AstDot* const dotp = VN_CAST(nodep->funcrefp(), Dot))
funcrefp = VN_CAST(dotp->rhsp(), NodeFTaskRef);
UASSERT_OBJ(funcrefp, nodep, "'with' only can operate on a function/task");
string name = "item";
FileLine* argFl = nodep->fileline();
if (const auto argp = VN_CAST(funcrefp->pinsp(), Arg)) {
AstArg* argp = VN_CAST(funcrefp->pinsp(), Arg);
if (argp) argp->unlinkFrBackWithNext();
if (argp && funcrefp->name() != "randomize") {
if (const auto parserefp = VN_CAST(argp->exprp(), ParseRef)) {
name = parserefp->name();
argFl = parserefp->fileline();
@@ -1521,7 +1525,7 @@ class LinkDotFindVisitor final : public VNVisitor {
}
if (argp->nextp())
argp->nextp()->v3error("'with' function expects only up to one argument");
VL_DO_DANGLING(argp->unlinkFrBackWithNext()->deleteTree(), argp);
VL_DO_DANGLING(argp->deleteTree(), argp);
}
// Type depends on the method used, let V3Width figure it out later
if (nodep->exprsp()) { // Else empty expression and pretend no "with"
@@ -1531,7 +1535,8 @@ class LinkDotFindVisitor final : public VNVisitor {
nodep->exprsp()->unlinkFrBackWithNext()};
funcrefp->addPinsp(newp);
}
nodep->replaceWith(funcrefp->unlinkFrBack());
funcrefp->addPinsp(argp);
nodep->replaceWith(nodep->funcrefp()->unlinkFrBack());
VL_DO_DANGLING(nodep->deleteTree(), nodep);
}
void visit(AstWith* nodep) override {
+12
View File
@@ -5917,6 +5917,18 @@ class WidthVisitor final : public VNVisitor {
|| nodep->name() == "set_randstate"))) {
// TODO perhaps this should move to V3LinkDot
AstClass* const classp = VN_CAST(nodep->classOrPackagep(), Class);
if (!classp) {
AstNodeDType* const adtypep = nodep->findBitDType();
withp = methodWithArgument(nodep, false, false, adtypep->findVoidDType(),
adtypep->findBitDType(), adtypep);
for (const AstNode* argp = nodep->pinsp(); argp; argp = argp->nextp())
userIterateAndNext(VN_AS(argp, Arg)->exprp(), WidthVP{SELF, BOTH}.p());
nodep->addPinsp(withp);
nodep->v3warn(CONSTRAINTIGN, "std::randomize ignored (unsupported)");
nodep->replaceWith(new AstConst{nodep->fileline(), 0});
VL_DO_DANGLING(pushDeletep(nodep), nodep);
return;
}
UASSERT_OBJ(classp, nodep, "Should have failed in V3LinkDot");
if (nodep->name() == "randomize") {
nodep->taskp(V3Randomize::newRandomizeFunc(m_memberMap, classp));