Internals: Use pure expressions in V3Randomize (#6974)

This commit is contained in:
Geza Lore 2026-02-01 05:09:19 +00:00 committed by GitHub
parent 122ceb2258
commit f0afcede10
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 10 deletions

View File

@ -595,7 +595,7 @@ bool VlRandomizer::parseSolution(std::iostream& os, bool log) {
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) {
m_constraints.emplace_back(std::move(constraint));
// Format constraint location: "filename:linenum source"

View File

@ -581,7 +581,7 @@ public:
+ 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 = "");
void clearConstraints();
void clearAll(); // Clear both constraints and variables

View File

@ -901,8 +901,7 @@ class ConstraintExprVisitor final : public VNVisitor {
AstNodeExpr* exprp;
if (randMode.usesMode) {
// Use string literal to avoid double formatting
exprp = new AstCExpr{nodep->fileline(), "std::string(\"" + smtName + "\")", 1};
exprp->dtypeSetString();
exprp = new AstConst{nodep->fileline(), AstConst::String{}, smtName};
// Get const format, using membersel if available for correct width/value
AstNodeExpr* constFormatp
@ -1003,8 +1002,8 @@ class ConstraintExprVisitor final : public VNVisitor {
const size_t width = tmpDtypep->width();
methodp->addPinsp(
new AstConst{varp->dtypep()->fileline(), AstConst::Unsized64{}, width});
AstNodeExpr* const varnamep
= new AstCExpr{varp->fileline(), "\"" + smtName + "\"", varp->width()};
AstNodeExpr* const varnamep = new AstCExpr{varp->fileline(), AstCExpr::Pure{},
"\"" + smtName + "\"", varp->width()};
varnamep->dtypep(varp->dtypep());
methodp->addPinsp(varnamep);
methodp->addPinsp(
@ -1434,10 +1433,11 @@ class ConstraintExprVisitor final : public VNVisitor {
// Pass filename, lineno, and source as separate arguments
// This allows EmitC to call protect() on filename, similar to VL_STOP
// Add filename parameter
callp->addPinsp(
new AstCExpr{nodep->fileline(), "\"" + nodep->fileline()->filename() + "\""});
callp->addPinsp(new AstCExpr{nodep->fileline(), AstCExpr::Pure{},
"\"" + nodep->fileline()->filename() + "\""});
// 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)
std::string prettyText;
if (!v3Global.opt.protectIds()) {
@ -1448,7 +1448,8 @@ class ConstraintExprVisitor final : public VNVisitor {
pos += std::strlen("\\\"");
}
}
callp->addPinsp(new AstCExpr{nodep->fileline(), "\"" + prettyText + "\""});
callp->addPinsp(
new AstCExpr{nodep->fileline(), AstCExpr::Pure{}, "\"" + prettyText + "\""});
nodep->replaceWith(callp->makeStmt());
VL_DO_DANGLING(nodep->deleteTree(), nodep);
}