Internals: Use pure expressions in V3Randomize (#6974)
This commit is contained in:
parent
122ceb2258
commit
f0afcede10
|
|
@ -595,7 +595,7 @@ bool VlRandomizer::parseSolution(std::iostream& os, bool log) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VlRandomizer::hard(std::string&& constraint, const char* filename, int linenum,
|
void VlRandomizer::hard(std::string&& constraint, const char* filename, uint32_t linenum,
|
||||||
const char* source) {
|
const char* source) {
|
||||||
m_constraints.emplace_back(std::move(constraint));
|
m_constraints.emplace_back(std::move(constraint));
|
||||||
// Format constraint location: "filename:linenum source"
|
// Format constraint location: "filename:linenum source"
|
||||||
|
|
|
||||||
|
|
@ -581,7 +581,7 @@ public:
|
||||||
+ std::to_string(idx);
|
+ std::to_string(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void hard(std::string&& constraint, const char* filename = "", int linenum = 0,
|
void hard(std::string&& constraint, const char* filename = "", uint32_t linenum = 0,
|
||||||
const char* source = "");
|
const char* source = "");
|
||||||
void clearConstraints();
|
void clearConstraints();
|
||||||
void clearAll(); // Clear both constraints and variables
|
void clearAll(); // Clear both constraints and variables
|
||||||
|
|
|
||||||
|
|
@ -901,8 +901,7 @@ class ConstraintExprVisitor final : public VNVisitor {
|
||||||
AstNodeExpr* exprp;
|
AstNodeExpr* exprp;
|
||||||
if (randMode.usesMode) {
|
if (randMode.usesMode) {
|
||||||
// Use string literal to avoid double formatting
|
// Use string literal to avoid double formatting
|
||||||
exprp = new AstCExpr{nodep->fileline(), "std::string(\"" + smtName + "\")", 1};
|
exprp = new AstConst{nodep->fileline(), AstConst::String{}, smtName};
|
||||||
exprp->dtypeSetString();
|
|
||||||
|
|
||||||
// Get const format, using membersel if available for correct width/value
|
// Get const format, using membersel if available for correct width/value
|
||||||
AstNodeExpr* constFormatp
|
AstNodeExpr* constFormatp
|
||||||
|
|
@ -1003,8 +1002,8 @@ class ConstraintExprVisitor final : public VNVisitor {
|
||||||
const size_t width = tmpDtypep->width();
|
const size_t width = tmpDtypep->width();
|
||||||
methodp->addPinsp(
|
methodp->addPinsp(
|
||||||
new AstConst{varp->dtypep()->fileline(), AstConst::Unsized64{}, width});
|
new AstConst{varp->dtypep()->fileline(), AstConst::Unsized64{}, width});
|
||||||
AstNodeExpr* const varnamep
|
AstNodeExpr* const varnamep = new AstCExpr{varp->fileline(), AstCExpr::Pure{},
|
||||||
= new AstCExpr{varp->fileline(), "\"" + smtName + "\"", varp->width()};
|
"\"" + smtName + "\"", varp->width()};
|
||||||
varnamep->dtypep(varp->dtypep());
|
varnamep->dtypep(varp->dtypep());
|
||||||
methodp->addPinsp(varnamep);
|
methodp->addPinsp(varnamep);
|
||||||
methodp->addPinsp(
|
methodp->addPinsp(
|
||||||
|
|
@ -1434,10 +1433,11 @@ class ConstraintExprVisitor final : public VNVisitor {
|
||||||
// Pass filename, lineno, and source as separate arguments
|
// Pass filename, lineno, and source as separate arguments
|
||||||
// This allows EmitC to call protect() on filename, similar to VL_STOP
|
// This allows EmitC to call protect() on filename, similar to VL_STOP
|
||||||
// Add filename parameter
|
// Add filename parameter
|
||||||
callp->addPinsp(
|
callp->addPinsp(new AstCExpr{nodep->fileline(), AstCExpr::Pure{},
|
||||||
new AstCExpr{nodep->fileline(), "\"" + nodep->fileline()->filename() + "\""});
|
"\"" + nodep->fileline()->filename() + "\""});
|
||||||
// Add line number parameter
|
// Add line number parameter
|
||||||
callp->addPinsp(new AstCExpr{nodep->fileline(), cvtToStr(nodep->fileline()->lineno())});
|
const uint32_t lineno = static_cast<uint32_t>(nodep->fileline()->lineno());
|
||||||
|
callp->addPinsp(new AstConst{nodep->fileline(), lineno});
|
||||||
// Add source text parameter (empty if --protect-ids to avoid source leakage)
|
// Add source text parameter (empty if --protect-ids to avoid source leakage)
|
||||||
std::string prettyText;
|
std::string prettyText;
|
||||||
if (!v3Global.opt.protectIds()) {
|
if (!v3Global.opt.protectIds()) {
|
||||||
|
|
@ -1448,7 +1448,8 @@ class ConstraintExprVisitor final : public VNVisitor {
|
||||||
pos += std::strlen("\\\"");
|
pos += std::strlen("\\\"");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
callp->addPinsp(new AstCExpr{nodep->fileline(), "\"" + prettyText + "\""});
|
callp->addPinsp(
|
||||||
|
new AstCExpr{nodep->fileline(), AstCExpr::Pure{}, "\"" + prettyText + "\""});
|
||||||
nodep->replaceWith(callp->makeStmt());
|
nodep->replaceWith(callp->makeStmt());
|
||||||
VL_DO_DANGLING(nodep->deleteTree(), nodep);
|
VL_DO_DANGLING(nodep->deleteTree(), nodep);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue