Internals: Favor UASSERT over v3fatalSrc. No functional change intended.

This commit is contained in:
Wilson Snyder 2024-01-05 18:00:06 -05:00
parent 47b129bf07
commit a36a07c297
14 changed files with 41 additions and 57 deletions

View File

@ -732,7 +732,7 @@ string EmitCFunc::emitVarResetRecurse(const AstVar* varp, const string& varNameP
string out;
if (varp->valuep()) {
const AstConst* const constp = VN_AS(varp->valuep(), Const);
if (!constp) varp->v3fatalSrc("non-const initializer for variable");
UASSERT_OBJ(constp, varp, "non-const initializer for variable");
for (int w = 0; w < varp->widthWords(); ++w) {
out += varNameProtected + suffix + "[" + cvtToStr(w) + "] = ";
out += cvtToStr(constp->num().edataWord(w)) + "U;\n";

View File

@ -993,14 +993,14 @@ public:
}
void visit(AstTime* nodep) override {
puts("VL_TIME_UNITED_Q(");
if (nodep->timeunit().isNone()) nodep->v3fatalSrc("$time has no units");
UASSERT_OBJ(!nodep->timeunit().isNone(), nodep, "$time has no units");
puts(cvtToStr(nodep->timeunit().multiplier()
/ v3Global.rootp()->timeprecision().multiplier()));
puts(")");
}
void visit(AstTimeD* nodep) override {
puts("VL_TIME_UNITED_D(");
if (nodep->timeunit().isNone()) nodep->v3fatalSrc("$realtime has no units");
UASSERT_OBJ(!nodep->timeunit().isNone(), nodep, "$realtime has no units");
puts(cvtToStr(nodep->timeunit().multiplier()
/ v3Global.rootp()->timeprecision().multiplier()));
puts(")");

View File

@ -256,9 +256,8 @@ void V3Error::init() {
describedEachWarn(static_cast<V3ErrorCode>(i), false);
pretendError(static_cast<V3ErrorCode>(i), V3ErrorCode{i}.pretendError());
}
if (VL_UNCOVERABLE(string{V3ErrorCode{V3ErrorCode::_ENUM_MAX}.ascii()} != " MAX")) {
v3fatalSrc("Enum table in V3ErrorCode::EC_ascii() is munged");
}
UASSERT(std::string{V3ErrorCode{V3ErrorCode::_ENUM_MAX}.ascii()} == " MAX",
"Enum table in V3ErrorCode::EC_ascii() is munged");
}
string V3Error::lineStr(const char* filename, int lineno) VL_PURE {

View File

@ -605,7 +605,7 @@ VInFilter::~VInFilter() {
}
bool VInFilter::readWholefile(const string& filename, VInFilter::StrList& outl) {
if (!m_impp) v3fatalSrc("readWholefile on invalid filter");
UASSERT(m_impp, "readWholefile on invalid filter");
return m_impp->readWholefile(filename, outl);
}

View File

@ -65,7 +65,7 @@ private:
using OrigEdgeList = std::list<V3GraphEdge*>; // List of orig edges, see also GraphAcyc's decl
V3GraphEdge* origEdgep() const {
const OrigEdgeList* const oEListp = static_cast<OrigEdgeList*>(userp());
if (!oEListp) v3fatalSrc("No original edge associated with acyc edge " << this);
UASSERT(oEListp, "No original edge associated with acyc edge " << this);
return (oEListp->front());
}

View File

@ -206,7 +206,7 @@ public:
}
void lifeToAbove() {
// Any varrefs under a if/else branch affect statements outside and after the if/else
if (!m_aboveLifep) v3fatalSrc("Pushing life when already at the top level");
UASSERT(m_aboveLifep, "Pushing life when already at the top level");
for (auto& itr : m_map) {
AstVarScope* const nodep = itr.first;
m_aboveLifep->complexAssignFind(nodep);

View File

@ -429,7 +429,7 @@ V3Number& V3Number::setLongS(int32_t value) {
return *this;
}
V3Number& V3Number::setDouble(double value) {
if (VL_UNCOVERABLE(width() != 64)) v3fatalSrc("Real operation on wrong sized number");
UASSERT(width() == 64, "Real operation on wrong sized number");
m_data.setDouble();
union {
double d;
@ -920,9 +920,7 @@ uint32_t V3Number::toUInt() const VL_MT_SAFE {
}
double V3Number::toDouble() const VL_MT_SAFE {
if (VL_UNCOVERABLE(!isDouble() || width() != 64)) {
v3fatalSrc("Real operation on wrong sized/non-real number");
}
UASSERT(isDouble() && width() == 64, "Real operation on wrong sized/non-real number");
union {
double d;
uint32_t u[2];
@ -2395,7 +2393,7 @@ V3Number& V3Number::opRToIRoundS(const V3Number& lhs) {
V3Number& V3Number::opRealToBits(const V3Number& lhs) {
NUM_ASSERT_OP_ARGS1(lhs);
NUM_ASSERT_DOUBLE_ARGS1(lhs);
if (lhs.width() != 64 || width() != 64) v3fatalSrc("Real operation on wrong sized number");
UASSERT(lhs.width() == 64 && width() == 64, "Real operation on wrong sized number");
union {
double m_d;
uint64_t m_v;
@ -2405,7 +2403,7 @@ V3Number& V3Number::opRealToBits(const V3Number& lhs) {
}
V3Number& V3Number::opBitsToRealD(const V3Number& lhs) {
NUM_ASSERT_OP_ARGS1(lhs);
if (lhs.width() != 64 || width() != 64) v3fatalSrc("Real operation on wrong sized number");
UASSERT(lhs.width() == 64 && width() == 64, "Real operation on wrong sized number");
union {
double m_d;
uint64_t m_v;

View File

@ -2777,7 +2777,7 @@ void V3Partition::go(V3Graph* mtasksp) {
mtasksp->orderPreRanked();
const int targetParFactor = v3Global.opt.threads();
if (targetParFactor < 2) v3fatalSrc("We should not reach V3Partition when --threads <= 1");
UASSERT(targetParFactor >= 2, "Should not reach V3Partition when --threads <= 1");
// Set cpLimit to roughly totalGraphCost / nThreads
//

View File

@ -1180,9 +1180,7 @@ int V3PreProcImp::getStateToken() {
stateChange(ps_DEFARG);
goto next_tok;
} else {
if (VL_UNCOVERABLE(m_defRefs.empty())) {
v3fatalSrc("Shouldn't be in DEFPAREN w/o active defref");
}
UASSERT(!m_defRefs.empty(), "Shouldn't be in DEFPAREN w/o active defref");
const VDefineRef* const refp = &(m_defRefs.top());
error(std::string{"Expecting ( to begin argument list for define reference `"}
+ refp->name() + "\n");
@ -1191,9 +1189,7 @@ int V3PreProcImp::getStateToken() {
}
}
case ps_DEFARG: {
if (VL_UNCOVERABLE(m_defRefs.empty())) {
v3fatalSrc("Shouldn't be in DEFARG w/o active defref");
}
UASSERT(!m_defRefs.empty(), "Shouldn't be in DEFARG w/o active defref");
VDefineRef* refp = &(m_defRefs.top());
refp->nextarg(refp->nextarg() + m_lexp->m_defValue);
m_lexp->m_defValue = "";
@ -1218,9 +1214,7 @@ int V3PreProcImp::getStateToken() {
statePop();
if (state()
== ps_JOIN) { // Handle {left}```FOO(ARG) where `FOO(ARG) might be empty
if (VL_UNCOVERABLE(m_joinStack.empty())) {
v3fatalSrc("`` join stack empty, but in a ``");
}
UASSERT(!m_joinStack.empty(), "`` join stack empty, but in a ``");
const string lhs = m_joinStack.top();
m_joinStack.pop();
out.insert(0, lhs);
@ -1308,9 +1302,7 @@ int V3PreProcImp::getStateToken() {
}
case ps_JOIN: {
if (tok == VP_SYMBOL || tok == VP_TEXT) {
if (VL_UNCOVERABLE(m_joinStack.empty())) {
v3fatalSrc("`` join stack empty, but in a ``");
}
UASSERT(!m_joinStack.empty(), "`` join stack empty, but in a ``");
const string lhs = m_joinStack.top();
m_joinStack.pop();
UINFO(5, "`` LHS:" << lhs << endl);
@ -1446,9 +1438,7 @@ int V3PreProcImp::getStateToken() {
if (m_defRefs.empty()) {
// Just output the substitution
if (state() == ps_JOIN) { // Handle {left}```FOO where `FOO might be empty
if (VL_UNCOVERABLE(m_joinStack.empty())) {
v3fatalSrc("`` join stack empty, but in a ``");
}
UASSERT(!m_joinStack.empty(), "`` join stack empty, but in a ``");
const string lhs = m_joinStack.top();
m_joinStack.pop();
out.insert(0, lhs);

View File

@ -302,7 +302,7 @@ private:
}
void scoreboardPopStmt() {
// UINFO(9, " pop" << endl);
if (m_stmtStackps.empty()) v3fatalSrc("Stack underflow");
UASSERT(!m_stmtStackps.empty(), "Stack underflow");
m_stmtStackps.pop_back();
}

View File

@ -162,11 +162,10 @@ class SplitAsVisitor final : public VNVisitor {
if (splitVscp) {
UINFO(3, "Split " << nodep << endl);
UINFO(3, " For " << splitVscp << endl);
if (splitVscp == lastSplitVscp) {
// We did this last time! Something's stuck!
nodep->v3fatalSrc("Infinite loop in isolate_assignments removal for: "
<< splitVscp->prettyNameQ());
}
// If we did this last time! Something's stuck!
UASSERT_OBJ(splitVscp != lastSplitVscp, nodep,
"Infinite loop in isolate_assignments removal for: "
<< splitVscp->prettyNameQ());
lastSplitVscp = splitVscp;
splitAlways(nodep, splitVscp);
++m_statSplits;

View File

@ -1033,11 +1033,10 @@ class TaskVisitor final : public VNVisitor {
if (portp->isDpiOpenArray()) {
AstNodeDType* const dtypep = portp->dtypep()->skipRefp();
if (VN_IS(dtypep, DynArrayDType) || VN_IS(dtypep, QueueDType)) {
v3fatalSrc("Passing dynamic array or queue as actual argument to DPI "
"open array is not yet supported");
}
UASSERT_OBJ(!VN_IS(dtypep, DynArrayDType) && !VN_IS(dtypep, QueueDType),
portp,
"Passing dynamic array or queue as actual argument to DPI "
"open array is not yet supported");
// Ideally we'd make a table of variable
// characteristics, and reuse it wherever we can
// At least put them into the module's CTOR as static?

View File

@ -76,7 +76,7 @@ public:
~TraceActivityVertex() override = default;
// ACCESSORS
AstNode* insertp() const {
if (!m_insertp) v3fatalSrc("Null insertp; probably called on a special always/slow.");
UASSERT(m_insertp, "Null insertp; probably called on a special always/slow");
return m_insertp;
}
string name() const override {

View File

@ -137,7 +137,7 @@ public:
bool selfDtm() const { return m_dtypep == nullptr; }
AstNodeDType* dtypep() const {
// Detect where overrideDType is probably the intended call
if (!m_dtypep) v3fatalSrc("Width dtype request on self-determined or preliminary VUP");
UASSERT(m_dtypep, "Width dtype request on self-determined or preliminary VUP");
return m_dtypep;
}
AstNodeDType* dtypeNullp() const { return m_dtypep; }
@ -147,15 +147,15 @@ public:
return dtp;
}
AstNodeDType* dtypeOverridep(AstNodeDType* defaultp) const {
if (m_stage == PRELIM) v3fatalSrc("Parent dtype should be a final-stage action");
UASSERT(m_stage != PRELIM, "Parent dtype should be a final-stage action");
return m_dtypep ? m_dtypep : defaultp;
}
int width() const {
if (!m_dtypep) v3fatalSrc("Width request on self-determined or preliminary VUP");
UASSERT(m_dtypep, "Width request on self-determined or preliminary VUP");
return m_dtypep->width();
}
int widthMin() const {
if (!m_dtypep) v3fatalSrc("Width request on self-determined or preliminary VUP");
UASSERT(m_dtypep, "Width request on self-determined or preliminary VUP");
return m_dtypep->widthMin();
}
bool prelim() const { return m_stage & PRELIM; }
@ -366,7 +366,7 @@ class WidthVisitor final : public VNVisitor {
if (m_vup->prelim()) { // First stage evaluation
iterateCheckReal(nodep, "LHS", nodep->lhsp(), BOTH);
}
if (!nodep->dtypep()->widthSized()) nodep->v3fatalSrc("RToIRoundS should be presized");
UASSERT_OBJ(nodep->dtypep()->widthSized(), nodep, "RToIRoundS should be presized");
}
// Widths: Output integer unsigned, input real
@ -1442,10 +1442,10 @@ class WidthVisitor final : public VNVisitor {
// Need to round to time units and precision
userIterateAndNext(nodep->lhsp(), WidthVP{SELF, BOTH}.p());
const AstConst* const constp = VN_CAST(nodep->lhsp(), Const);
if (!constp || !constp->isDouble()) nodep->v3fatalSrc("Times should be doubles");
if (nodep->timeunit().isNone()) nodep->v3fatalSrc("$time import no units");
UASSERT_OBJ(constp && constp->isDouble(), nodep, "Times should be doubles");
UASSERT_OBJ(!nodep->timeunit().isNone(), nodep, "$time import no units");
double time = constp->num().toDouble();
if (v3Global.rootp()->timeprecision().isNone()) nodep->v3fatalSrc("Never set precision?");
UASSERT_OBJ(!v3Global.rootp()->timeprecision().isNone(), nodep, "Never set precision?");
time /= nodep->timeunit().multiplier();
// IEEE claims you should round to time precision here, but no simulator seems to do this
AstConst* const newp = new AstConst{nodep->fileline(), AstConst::RealDouble{}, time};
@ -2730,7 +2730,7 @@ class WidthVisitor final : public VNVisitor {
userIterateChildren(nodep, WidthVP{SELF, BOTH}.p());
if (debug() >= 9) nodep->dumpTree("- mbs-ic: ");
// Find the fromp dtype - should be a class
if (!nodep->fromp()->dtypep()) nodep->fromp()->v3fatalSrc("Unlinked data type");
UASSERT_OBJ(nodep->fromp()->dtypep(), nodep->fromp(), "Unlinked data type");
AstNodeDType* const fromDtp = nodep->fromp()->dtypep()->skipRefToEnump();
UINFO(9, " from dt " << fromDtp << endl);
if (AstNodeUOrStructDType* const adtypep = VN_CAST(fromDtp, NodeUOrStructDType)) {
@ -5024,9 +5024,8 @@ class WidthVisitor final : public VNVisitor {
if (argp) {
AstNodeExpr* const nextp = VN_AS(argp->nextp(), NodeExpr);
if (argp->isDouble()) ch = '^'; // Convert it
if (nodep->timeunit().isNone()) {
nodep->v3fatalSrc("display %t has no time units");
}
UASSERT_OBJ(!nodep->timeunit().isNone(), nodep,
"display %t has no time units");
argp = nextp;
}
break;
@ -5309,8 +5308,8 @@ class WidthVisitor final : public VNVisitor {
userIterateAndNext(nodep->exprp(), WidthVP{nodep->modVarp()->dtypep(), PRELIM}.p());
AstNodeDType* modDTypep = nodep->modVarp()->dtypep();
AstNodeDType* conDTypep = nodep->exprp()->dtypep();
if (!modDTypep) nodep->v3fatalSrc("Unlinked pin data type");
if (!conDTypep) nodep->v3fatalSrc("Unlinked pin data type");
UASSERT_OBJ(modDTypep, nodep, "Unlinked pin data type");
UASSERT_OBJ(conDTypep, nodep, "Unlinked pin data type");
modDTypep = modDTypep->skipRefp();
conDTypep = conDTypep->skipRefp();
AstNodeDType* subDTypep = modDTypep;