Skip to content

Commit

Permalink
WIP: Add solve..before edges
Browse files Browse the repository at this point in the history
Signed-off-by: Ryszard Rozak <[email protected]>
  • Loading branch information
RRozak committed Jan 8, 2025
1 parent e171463 commit 3a97a11
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions include/verilated_random.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ class VlRandomizer final {
std::vector<std::string> m_constraints; // Solver-dependent constraints
std::map<std::string, std::shared_ptr<const VlRandomVar>> m_vars; // Solver-dependent
// variables
std::vector<std::pair<std::string, std::string>> m_solveBefores; // solve..before rules
// solve 1st begore 2nd
ArrayInfoMap m_arr_vars; // Tracks each element in array structures for iteration
std::map<size_t, std::string> seen_values; // Record String Index to avoid conflicts
const VlQueue<CData>* m_randmode; // rand_mode state;
Expand Down Expand Up @@ -347,6 +349,9 @@ class VlRandomizer final {
}
}
}
void add_solve_before(std::string first, std::string second) {
m_solveBefores.push_back(std::make_pair(first, second));
}

void hard(std::string&& constraint);
void clear();
Expand Down
3 changes: 2 additions & 1 deletion src/V3AstNodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2889,7 +2889,8 @@ int AstCMethodHard::instrCount() const {
return 0;
}
void AstCMethodHard::setPurity() {
static const std::map<std::string, bool> isPureMethod{{"andNot", false},
static const std::map<std::string, bool> isPureMethod{{"add_solve_before", false},
{"andNot", false},
{"any", true},
{"anyTriggered", false},
{"assign", false},
Expand Down
10 changes: 9 additions & 1 deletion src/V3Randomize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,15 @@ class ConstraintExprVisitor final : public VNVisitor {
VL_DO_DANGLING(nodep->deleteTree(), nodep);
}
void visit(AstConstraintBefore* nodep) override {
nodep->v3warn(CONSTRAINTIGN, "Constraint expression ignored (imperfect distribution)");
iterateChildren(nodep);
AstCMethodHard* const methodp = new AstCMethodHard{
nodep->fileline(),
new AstVarRef{nodep->fileline(), VN_AS(m_genp->user2p(), NodeModule), m_genp,
VAccess::READWRITE},
"add_solve_before"};
methodp->addPinsp(nodep->lhssp()->unlinkFrBack());
methodp->addPinsp(nodep->rhssp()->unlinkFrBack());

VL_DO_DANGLING(nodep->unlinkFrBack()->deleteTree(), nodep);
}
void visit(AstConstraintUnique* nodep) override {
Expand Down

0 comments on commit 3a97a11

Please sign in to comment.