mirror of
https://github.com/verilator/verilator.git
synced 2026-10-06 01:54:01 +02:00
Emit model implementation as loose methods. (#3006)
This patch introduces the concept of 'loose' methods, which semantically are methods, but are declared as global functions, and are passed an explicit 'self' pointer. This enables these methods to be declared outside the class, only when they are needed, therefore removing the header dependency. The bulk of the emitted model implementation now uses loose methods.
This commit is contained in:
+17
-15
@@ -61,23 +61,21 @@ private:
|
||||
const int funcNum = m_newFunctions.size();
|
||||
const string funcName = m_basename + "_" + cvtToStr(funcNum);
|
||||
AstCFunc* const funcp = new AstCFunc(m_modp->fileline(), funcName, nullptr, "void");
|
||||
funcp->isStatic(!m_type.isClass()); // Class constructors are non static
|
||||
funcp->isStatic(false);
|
||||
funcp->isLoose(!m_type.isClass());
|
||||
funcp->declPrivate(true);
|
||||
funcp->slow(!m_type.isClass()); // Only classes construct on fast path
|
||||
string preventUnusedStmt;
|
||||
if (m_type.isClass()) {
|
||||
funcp->argTypes(EmitCBaseVisitor::symClassVar());
|
||||
preventUnusedStmt = "if (false && vlSymsp) {}";
|
||||
preventUnusedStmt = "if (false && vlSymsp) {} // Prevent unused\n";
|
||||
} else if (m_type.isCoverage()) {
|
||||
funcp->argTypes(EmitCBaseVisitor::prefixNameProtect(m_modp) + "* self, "
|
||||
+ EmitCBaseVisitor::symClassVar() + ", bool first");
|
||||
preventUnusedStmt = "if (false && self && vlSymsp && first) {}";
|
||||
} else { // Module
|
||||
funcp->argTypes(EmitCBaseVisitor::prefixNameProtect(m_modp) + "* self");
|
||||
preventUnusedStmt = "if (false && self) {}";
|
||||
funcp->argTypes("bool first");
|
||||
preventUnusedStmt = "if (false && first) {} // Prevent unused\n";
|
||||
}
|
||||
if (!preventUnusedStmt.empty()) {
|
||||
funcp->addStmtsp(new AstCStmt(m_modp->fileline(), preventUnusedStmt));
|
||||
}
|
||||
preventUnusedStmt += " // Prevent unused\n";
|
||||
funcp->addStmtsp(new AstCStmt(m_modp->fileline(), preventUnusedStmt));
|
||||
m_modp->addStmtp(funcp);
|
||||
m_numStmts = 0;
|
||||
return funcp;
|
||||
@@ -113,10 +111,9 @@ public:
|
||||
AstCCall* const callp = new AstCCall(m_modp->fileline(), funcp);
|
||||
if (m_type.isClass()) {
|
||||
callp->argTypes("vlSymsp");
|
||||
} else if (m_type.isCoverage()) {
|
||||
callp->argTypes("self, vlSymsp, first");
|
||||
} else { // Module
|
||||
callp->argTypes("self");
|
||||
} else {
|
||||
if (m_type.isCoverage()) callp->argTypes("first");
|
||||
callp->selfPointer("this");
|
||||
}
|
||||
rootFuncp->addStmtsp(callp);
|
||||
}
|
||||
@@ -134,6 +131,7 @@ void V3CCtors::evalAsserts() {
|
||||
AstCFunc* funcp = new AstCFunc(modp->fileline(), "_eval_debug_assertions", nullptr, "void");
|
||||
funcp->declPrivate(true);
|
||||
funcp->isStatic(false);
|
||||
funcp->isLoose(true);
|
||||
funcp->slow(false);
|
||||
funcp->ifdef("VL_DEBUG");
|
||||
modp->addStmtp(funcp);
|
||||
@@ -145,7 +143,11 @@ void V3CCtors::evalAsserts() {
|
||||
int lastWordWidth = varp->width() % storedWidth;
|
||||
if (lastWordWidth != 0) {
|
||||
// if (signal & CONST(upper_non_clean_mask)) { fail; }
|
||||
AstNode* newp = new AstVarRef(varp->fileline(), varp, VAccess::READ);
|
||||
AstVarRef* const vrefp
|
||||
= new AstVarRef(varp->fileline(), varp, VAccess::READ);
|
||||
vrefp->selfPointer(v3Global.opt.relativeCFuncs() ? "this"
|
||||
: "vlSymsp->TOPp");
|
||||
AstNode* newp = vrefp;
|
||||
if (varp->isWide()) {
|
||||
newp = new AstWordSel(
|
||||
varp->fileline(), newp,
|
||||
|
||||
Reference in New Issue
Block a user