Internals: Cleanup some vlSelf code. No functional change intended.

This commit is contained in:
Wilson Snyder 2025-04-26 09:51:02 -04:00
parent abc46db3c0
commit e7adae6f81
4 changed files with 14 additions and 11 deletions

View File

@ -64,10 +64,12 @@ std::ostream& operator<<(std::ostream& os, VNType rhs);
const std::shared_ptr<const string> VSelfPointerText::s_emptyp = std::make_shared<string>("");
const std::shared_ptr<const string> VSelfPointerText::s_thisp = std::make_shared<string>("this");
string VSelfPointerText::replaceThis(bool useSelfForThis, const string& text) {
return useSelfForThis ? VString::replaceWord(text, "this", "vlSelf") : text;
}
string VSelfPointerText::protect(bool useSelfForThis, bool protect) const {
const string& sp
= useSelfForThis ? VString::replaceWord(asString(), "this", "vlSelf") : asString();
return VIdProtect::protectWordsIf(sp, protect);
return VIdProtect::protectWordsIf(replaceThis(useSelfForThis, asString()), protect);
}
//######################################################################

View File

@ -1686,6 +1686,7 @@ public:
bool isVlSym() const { return m_strp->find("vlSymsp") != string::npos; }
bool hasThis() const { return m_strp == s_thisp || VString::startsWith(*m_strp, "this"); }
string protect(bool useSelfForThis, bool protect) const;
static string replaceThis(bool useSelfForThis, const string& text);
const std::string& asString() const { return *m_strp; }
bool operator==(const VSelfPointerText& other) const { return *m_strp == *other.m_strp; }
};

View File

@ -631,8 +631,10 @@ class AstCFunc final : public AstNode {
bool m_isConstructor : 1; // Is C class constructor
bool m_isDestructor : 1; // Is C class destructor
bool m_isMethod : 1; // Is inside a class definition
bool m_isLoose : 1; // Semantically this is a method, but is implemented as a function
// with an explicitly passed 'self' pointer as the first argument
bool m_isLoose : 1; // Semantically this is a method, but is implemented as a function with
// an explicitly passed 'self' pointer as the first argument. This can
// be slightly faster due to __restrict, and we do not declare in header
// so adding/removing loose functions doesn't recompile everything.
bool m_isInline : 1; // Inline function
bool m_isVirtual : 1; // Virtual function
bool m_entryPoint : 1; // User may call into this top level function

View File

@ -356,8 +356,7 @@ public:
// code to allow the compiler to generate load store after the
// if condition (including short-circuit evaluation)
// speculatively and also reduce the data cache pollution when
// executing in the wrong path to make verilator-generated code
// run faster.
// executing in the wrong path to make Verilated code faster.
puts("auto& vlSelfRef = std::ref(*vlSelf).get();\n");
}
@ -1064,9 +1063,8 @@ public:
putns(nodep, "vlSymsp->_vm_contextp__->timeprecision()");
}
void visit(AstNodeSimpleText* nodep) override {
const string text = m_inUC && m_useSelfForThis
? VString::replaceWord(nodep->text(), "this", "vlSelf")
: nodep->text();
const string text
= VSelfPointerText::replaceThis(m_inUC && m_useSelfForThis, nodep->text());
if (nodep->tracking() || m_trackText) {
puts(text);
} else {
@ -1342,7 +1340,7 @@ public:
void visit(AstThisRef* nodep) override {
putnbs(nodep, nodep->dtypep()->cType("", false, false));
puts("{");
puts(m_useSelfForThis ? "vlSelf" : "this");
puts(VSelfPointerText::replaceThis(m_useSelfForThis, "this"));
puts("}");
}