Skip to content

Commit

Permalink
WIP: Create and call runtime .randomize() on dynamic array randomization
Browse files Browse the repository at this point in the history
  • Loading branch information
kiryk committed Oct 31, 2023
1 parent 8210d21 commit e3f8bfe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions include/verilated_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,10 @@ class VlQueue final {
}
void reverse() { std::reverse(m_deque.begin(), m_deque.end()); }
void shuffle() { std::shuffle(m_deque.begin(), m_deque.end(), VlURNG{}); }
void randomize() {
// TODO: Use emitted .randomize()/RAND Funcs
for (const auto& i : m_deque) { m_deque[i] = rand()%10; }
}
VlQueue unique() const {
VlQueue out;
std::set<T_Value> saw;
Expand Down
12 changes: 11 additions & 1 deletion src/V3Randomize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,12 @@ class RandomizeVisitor final : public VNVisitor {
}
}
return stmtsp;
} else if (const auto* const arrayDtp
= VN_CAST(varrefp->dtypep()->skipRefp(), DynArrayDType)) {
AstNode* argsp = new AstVarRef{fl, varrefp->varp(), VAccess::READWRITE};
argsp->addNext(new AstText{fl, randcVarp ? ".randomize(__Vm_rng);\n" : ".randomize();\n"});
AstCStmt* stmtp = new AstCStmt{fl, argsp};
return stmtp;
} else {
AstNodeExpr* valp;
if (AstEnumDType* const enumDtp = VN_CAST(memberp ? memberp->subDTypep()->subDTypep()
Expand Down Expand Up @@ -327,7 +333,11 @@ class RandomizeVisitor final : public VNVisitor {
if (VN_IS(dtypep, BasicDType) || VN_IS(dtypep, StructDType)) {
AstVar* const randcVarp = newRandcVarsp(memberVarp);
AstVarRef* const refp = new AstVarRef{fl, memberVarp, VAccess::WRITE};
AstNodeStmt* const stmtp = newRandStmtsp(fl, refp, randcVarp);
AstNodeStmt* const stmtp = newRandStmtsp(fl, refp, nullptr);
funcp->addStmtsp(stmtp);
} else if (const auto* const arrayp = VN_CAST(dtypep, DynArrayDType)) {
AstVarRef* const refp = new AstVarRef{fl, memberVarp, VAccess::WRITE};
AstNodeStmt* const stmtp = newRandStmtsp(fl, refp, nullptr);
funcp->addStmtsp(stmtp);
} else if (const auto* const classRefp = VN_CAST(dtypep, ClassRefDType)) {
if (classRefp->classp() == nodep) {
Expand Down

0 comments on commit e3f8bfe

Please sign in to comment.