2021-07-20 17:40:38 +02:00
|
|
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
// DESCRIPTION: Verilator: Add common contents to modules
|
|
|
|
|
//
|
|
|
|
|
// Code available from: https://verilator.org
|
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
//
|
2026-01-27 02:24:34 +01:00
|
|
|
// This program is free software; you can redistribute it and/or modify it
|
|
|
|
|
// under the terms of either the GNU Lesser General Public License Version 3
|
|
|
|
|
// or the Perl Artistic License Version 2.0.
|
|
|
|
|
// SPDX-FileCopyrightText: 2003-2026 Wilson Snyder
|
2021-07-20 17:40:38 +02:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
// V3Common's Transformations:
|
|
|
|
|
//
|
|
|
|
|
// Each class:
|
2026-05-12 15:49:21 +02:00
|
|
|
// Emit to_string() if given class is printed from (used as format arg), or any of its
|
|
|
|
|
// parents/children is printed from, or if any of its children has another parent that is
|
|
|
|
|
// printed from. If class emits to_string(), emit to_string() for its struct/union/interface
|
|
|
|
|
// fields.
|
|
|
|
|
// Each struct/union:
|
|
|
|
|
// Emit to_string() if given struct/union is used as format arg or is a field of a
|
|
|
|
|
// class/struct/union that emits to_string(). If struct/union emits to_string(), emit
|
|
|
|
|
// to_string() for its struct/union fields.
|
|
|
|
|
// Each interface:
|
|
|
|
|
// Emit to_string() if given interface is a field of a class that emits to_string()
|
2021-07-20 17:40:38 +02:00
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
|
2023-10-18 12:37:46 +02:00
|
|
|
#include "V3PchAstNoMT.h" // VL_MT_DISABLED_CODE_UNIT
|
|
|
|
|
|
2021-07-20 17:40:38 +02:00
|
|
|
#include "V3Common.h"
|
2022-08-05 11:56:57 +02:00
|
|
|
|
2021-07-20 17:40:38 +02:00
|
|
|
#include "V3EmitCBase.h"
|
|
|
|
|
|
2022-09-18 21:53:42 +02:00
|
|
|
VL_DEFINE_DEBUG_FUNCTIONS;
|
|
|
|
|
|
2021-07-20 17:40:38 +02:00
|
|
|
//######################################################################
|
|
|
|
|
// Common component builders
|
|
|
|
|
|
2024-10-12 04:37:48 +02:00
|
|
|
string V3Common::makeToStringCall(AstNodeDType* nodep, const std::string& lhs) {
|
|
|
|
|
std::string stmt;
|
|
|
|
|
if (VN_IS(nodep->skipRefp(), BasicDType) && nodep->isWide()) {
|
|
|
|
|
stmt += "VL_TO_STRING_W(";
|
|
|
|
|
stmt += cvtToStr(nodep->widthWords());
|
|
|
|
|
stmt += ", ";
|
|
|
|
|
} else {
|
|
|
|
|
stmt += "VL_TO_STRING(";
|
|
|
|
|
}
|
|
|
|
|
stmt += lhs;
|
|
|
|
|
stmt += ")";
|
|
|
|
|
return stmt;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-20 12:31:00 +02:00
|
|
|
static void makeVlToString(AstIface* nodep) {
|
|
|
|
|
AstCFunc* const funcp
|
|
|
|
|
= new AstCFunc{nodep->fileline(), "VL_TO_STRING", nullptr, "std::string"};
|
2025-08-26 04:05:40 +02:00
|
|
|
funcp->argTypes("const " + EmitCUtil::prefixNameProtect(nodep) + "* obj");
|
2022-10-20 12:31:00 +02:00
|
|
|
funcp->isMethod(false);
|
|
|
|
|
funcp->isConst(false);
|
|
|
|
|
funcp->isStatic(false);
|
|
|
|
|
funcp->protect(false);
|
2025-11-07 20:57:10 +01:00
|
|
|
AstNodeExpr* const exprp = new AstCExpr{nodep->fileline(), "obj ? obj->vlNamep : \"null\""};
|
2022-10-20 12:31:00 +02:00
|
|
|
exprp->dtypeSetString();
|
|
|
|
|
funcp->addStmtsp(new AstCReturn{nodep->fileline(), exprp});
|
|
|
|
|
nodep->addStmtsp(funcp);
|
|
|
|
|
}
|
2023-01-28 04:41:12 +01:00
|
|
|
static void makeVlToString(AstNodeUOrStructDType* nodep) {
|
2022-12-21 01:22:42 +01:00
|
|
|
AstNodeModule* const modp = nodep->classOrPackagep();
|
2023-05-07 03:41:17 +02:00
|
|
|
UASSERT_OBJ(modp, nodep, "Unlinked struct package");
|
2022-12-21 01:22:42 +01:00
|
|
|
AstCFunc* const funcp
|
|
|
|
|
= new AstCFunc{nodep->fileline(), "VL_TO_STRING", nullptr, "std::string"};
|
2025-08-26 04:05:40 +02:00
|
|
|
funcp->argTypes("const " + EmitCUtil::prefixNameProtect(nodep) + "& obj");
|
2022-12-21 01:22:42 +01:00
|
|
|
funcp->isMethod(false);
|
|
|
|
|
funcp->isConst(false);
|
|
|
|
|
funcp->isStatic(false);
|
|
|
|
|
funcp->protect(false);
|
2025-09-26 14:25:47 +02:00
|
|
|
funcp->addStmtsp(new AstCStmt{nodep->fileline(), "std::string out;"});
|
2022-12-21 01:22:42 +01:00
|
|
|
for (const AstMemberDType* itemp = nodep->membersp(); itemp;
|
|
|
|
|
itemp = VN_AS(itemp->nextp(), MemberDType)) {
|
|
|
|
|
std::string stmt = "out += \"";
|
|
|
|
|
if (itemp == nodep->membersp()) {
|
|
|
|
|
stmt += "'{";
|
|
|
|
|
} else {
|
|
|
|
|
stmt += ", ";
|
|
|
|
|
}
|
2023-03-04 00:49:26 +01:00
|
|
|
stmt += VIdProtect::protect(itemp->prettyName()) + ":\" + ";
|
2024-10-12 04:37:48 +02:00
|
|
|
stmt += V3Common::makeToStringCall(itemp->dtypep(), "obj."s + itemp->nameProtect());
|
2025-09-26 14:25:47 +02:00
|
|
|
stmt += ";";
|
2022-12-21 01:22:42 +01:00
|
|
|
funcp->addStmtsp(new AstCStmt{nodep->fileline(), stmt});
|
|
|
|
|
}
|
2025-09-26 14:25:47 +02:00
|
|
|
funcp->addStmtsp(new AstCStmt{nodep->fileline(), "out += \"}\";"});
|
|
|
|
|
|
Internals: Refactor text based Ast constructs (#6280) (#6571)
Remove the large variety of ways raw "text" is represented in the Ast.
Particularly, the only thing that represents a string to be emitted in
the output is AstText.
There are 5 AstNodes that can contain AstText, and V3Emit will throw an
error if an AstText is encountered anywhere else:
- AstCStmt: Internally generated procedural statements involving raw
text.
- AstCStmtUser: This is the old AstUCStmt, renamed so it sorts next to
AstCStmt, as it's largely equivalent. We should never create this
internally unless used to represent user input. It is used for $c,
statements in the input, and for some 'systemc_* blocks.
- AstCExpr: Internally generaged expression involving raw text.
- AstCExprUser: This is the old AstUCFunc, renamed so it sorts next to
AstCExpr. It is largely equivalent, but also has more optimizations
disabled. This should never be created internally, it is only used for
$c expressions in the input.
- AstTextBlock: Use by V3ProtectLib only, to generate the hierarchical
wrappers.
Text "tracking" for indentation is always on for AstCStmt, AstCExpr, and
AstTextBlock, as these are always generated by us, and should always be
well formed.
Tracking is always off for AstCStmtUser and AstCExprUser, as these
contain arbitrary user input that might not be safe to parse for
indentation.
Remove subsequently redundant AstNodeSimpleText and AstNodeText types.
This patch also fixes incorrect indentation in emitted waveform tracing
functions, and makes the output more readable for hier block SV stubs.
With that, all raw text nodes are handled as a proper AstNodeStmt or
AstNodeExpr as required for #6280.
2025-10-21 13:41:29 +02:00
|
|
|
AstCExpr* const exprp = new AstCExpr{nodep->fileline(), "out"};
|
2025-09-26 14:25:47 +02:00
|
|
|
exprp->dtypeSetString();
|
|
|
|
|
funcp->addStmtsp(new AstCReturn{nodep->fileline(), exprp});
|
|
|
|
|
|
2022-12-21 01:22:42 +01:00
|
|
|
modp->addStmtsp(funcp);
|
|
|
|
|
}
|
2021-07-20 17:40:38 +02:00
|
|
|
static void makeToString(AstClass* nodep) {
|
|
|
|
|
AstCFunc* const funcp = new AstCFunc{nodep->fileline(), "to_string", nullptr, "std::string"};
|
|
|
|
|
funcp->isConst(true);
|
|
|
|
|
funcp->isStatic(false);
|
2026-02-20 03:34:17 +01:00
|
|
|
funcp->isVirtual(true);
|
2021-07-20 17:40:38 +02:00
|
|
|
funcp->protect(false);
|
Internals: Refactor text based Ast constructs (#6280) (#6571)
Remove the large variety of ways raw "text" is represented in the Ast.
Particularly, the only thing that represents a string to be emitted in
the output is AstText.
There are 5 AstNodes that can contain AstText, and V3Emit will throw an
error if an AstText is encountered anywhere else:
- AstCStmt: Internally generated procedural statements involving raw
text.
- AstCStmtUser: This is the old AstUCStmt, renamed so it sorts next to
AstCStmt, as it's largely equivalent. We should never create this
internally unless used to represent user input. It is used for $c,
statements in the input, and for some 'systemc_* blocks.
- AstCExpr: Internally generaged expression involving raw text.
- AstCExprUser: This is the old AstUCFunc, renamed so it sorts next to
AstCExpr. It is largely equivalent, but also has more optimizations
disabled. This should never be created internally, it is only used for
$c expressions in the input.
- AstTextBlock: Use by V3ProtectLib only, to generate the hierarchical
wrappers.
Text "tracking" for indentation is always on for AstCStmt, AstCExpr, and
AstTextBlock, as these are always generated by us, and should always be
well formed.
Tracking is always off for AstCStmtUser and AstCExprUser, as these
contain arbitrary user input that might not be safe to parse for
indentation.
Remove subsequently redundant AstNodeSimpleText and AstNodeText types.
This patch also fixes incorrect indentation in emitted waveform tracing
functions, and makes the output more readable for hier block SV stubs.
With that, all raw text nodes are handled as a proper AstNodeStmt or
AstNodeExpr as required for #6280.
2025-10-21 13:41:29 +02:00
|
|
|
AstCExpr* const exprp = new AstCExpr{nodep->fileline(), R"("'{"s + to_string_middle() + "}")"};
|
2021-07-20 17:40:38 +02:00
|
|
|
exprp->dtypeSetString();
|
|
|
|
|
funcp->addStmtsp(new AstCReturn{nodep->fileline(), exprp});
|
2022-09-15 20:43:56 +02:00
|
|
|
nodep->addStmtsp(funcp);
|
2021-07-20 17:40:38 +02:00
|
|
|
}
|
|
|
|
|
static void makeToStringMiddle(AstClass* nodep) {
|
|
|
|
|
AstCFunc* const funcp
|
|
|
|
|
= new AstCFunc{nodep->fileline(), "to_string_middle", nullptr, "std::string"};
|
|
|
|
|
funcp->isConst(true);
|
|
|
|
|
funcp->isStatic(false);
|
|
|
|
|
funcp->protect(false);
|
2026-02-27 00:12:12 +01:00
|
|
|
AstNodeStmt* stmtsp = nullptr;
|
2021-07-20 17:40:38 +02:00
|
|
|
std::string comma;
|
|
|
|
|
for (AstNode* itemp = nodep->membersp(); itemp; itemp = itemp->nextp()) {
|
2021-11-13 19:50:44 +01:00
|
|
|
if (const auto* const varp = VN_CAST(itemp, Var)) {
|
2026-02-20 02:15:37 +01:00
|
|
|
const AstBasicDType* const basicp = varp->dtypeSkipRefp()->basicp();
|
2024-05-17 16:38:34 +02:00
|
|
|
if (!varp->isParam() && !varp->isInternal()
|
2026-02-20 02:15:37 +01:00
|
|
|
&& !(basicp && (basicp->isRandomGenerator() || basicp->isStdRandomGenerator()))) {
|
2021-07-20 17:40:38 +02:00
|
|
|
string stmt = "out += \"";
|
|
|
|
|
stmt += comma;
|
|
|
|
|
comma = ", ";
|
|
|
|
|
stmt += itemp->origNameProtect();
|
|
|
|
|
stmt += ":\" + ";
|
2024-10-12 04:37:48 +02:00
|
|
|
stmt += V3Common::makeToStringCall(itemp->dtypep(), itemp->nameProtect());
|
2025-09-26 14:25:47 +02:00
|
|
|
stmt += ";";
|
2021-07-20 17:40:38 +02:00
|
|
|
nodep->user1(true); // So what we extend dumps this
|
2026-02-27 00:12:12 +01:00
|
|
|
stmtsp = AstNode::addNextNull(stmtsp, new AstCStmt{nodep->fileline(), stmt});
|
2021-07-20 17:40:38 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-28 16:24:55 +02:00
|
|
|
if (nodep->extendsp()) {
|
2022-08-18 00:08:43 +02:00
|
|
|
string stmt = "out += ";
|
2026-02-20 02:15:37 +01:00
|
|
|
if (!comma.empty()) stmt += "\", \" + ";
|
2021-07-20 17:40:38 +02:00
|
|
|
// comma = ", "; // Nothing further so not needed
|
2025-08-26 04:05:40 +02:00
|
|
|
stmt += EmitCUtil::prefixNameProtect(nodep->extendsp()->dtypep());
|
2025-09-26 14:25:47 +02:00
|
|
|
stmt += "::to_string_middle();";
|
2021-07-20 17:40:38 +02:00
|
|
|
nodep->user1(true); // So what we extend dumps this
|
2026-02-27 00:12:12 +01:00
|
|
|
stmtsp = AstNode::addNextNull(stmtsp, new AstCStmt{nodep->fileline(), stmt});
|
2021-07-20 17:40:38 +02:00
|
|
|
}
|
2025-09-26 14:25:47 +02:00
|
|
|
|
2026-02-27 00:12:12 +01:00
|
|
|
AstNodeExpr* exprp;
|
|
|
|
|
if (stmtsp) {
|
|
|
|
|
funcp->addStmtsp(new AstCStmt{nodep->fileline(), "std::string out;"});
|
|
|
|
|
funcp->addStmtsp(stmtsp);
|
|
|
|
|
exprp = new AstCExpr{nodep->fileline(), "out"};
|
|
|
|
|
exprp->dtypeSetString();
|
|
|
|
|
} else { // Nothing to print, return ""
|
|
|
|
|
exprp = new AstConst{nodep->fileline(), AstConst::String{}, ""};
|
|
|
|
|
}
|
2025-09-26 14:25:47 +02:00
|
|
|
funcp->addStmtsp(new AstCReturn{nodep->fileline(), exprp});
|
|
|
|
|
|
2022-09-15 20:43:56 +02:00
|
|
|
nodep->addStmtsp(funcp);
|
2021-07-20 17:40:38 +02:00
|
|
|
}
|
|
|
|
|
|
2026-05-12 15:49:21 +02:00
|
|
|
class ToStringVisitor final : public VNVisitorConst {
|
2022-08-18 00:08:43 +02:00
|
|
|
// NODE STATE
|
2026-05-12 15:49:21 +02:00
|
|
|
// AstNode::user1() -> bool. to_string() was emitted
|
|
|
|
|
// AstClass::user2() -> PrintedFromParent. Used to propagate emission of to_string() from
|
|
|
|
|
// parent to child
|
2022-08-18 00:08:43 +02:00
|
|
|
const VNUser1InUse m_inuser1;
|
2026-05-12 15:49:21 +02:00
|
|
|
const VNUser2InUse m_inuser2;
|
|
|
|
|
size_t m_emitTowardsRoot
|
|
|
|
|
= 0; // class that require its ancestors to emit to_string() sets this
|
|
|
|
|
size_t m_emitForMembers = 0; // class/struct that requires its members (and their members
|
|
|
|
|
// recursively) to emit to_string() sets this
|
|
|
|
|
enum class PrintedFromParent : uint8_t {
|
|
|
|
|
UNRESOLVED,
|
|
|
|
|
PRINTED_FROM_PARENT,
|
|
|
|
|
NO_PRINTED_FROM_PARENT
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
VDouble0 m_statClassToString;
|
|
|
|
|
VDouble0 m_statInterfaceToString;
|
|
|
|
|
VDouble0 m_statStructUnionToString;
|
|
|
|
|
|
|
|
|
|
void markClassIterate(AstClass* classp) {
|
|
|
|
|
if (classp->user1SetOnce()) return;
|
|
|
|
|
VL_RESTORER(m_emitForMembers);
|
|
|
|
|
++m_emitForMembers;
|
|
|
|
|
for (AstNode* stmtp = classp->stmtsp(); stmtp; stmtp = stmtp->nextp()) {
|
|
|
|
|
if (AstVar* const varp = VN_CAST(stmtp, Var)) {
|
|
|
|
|
AstNodeDType* nodeDtypep = varp->dtypep();
|
|
|
|
|
if (AstIfaceRefDType* const ifaceRedDTypep = VN_CAST(nodeDtypep, IfaceRefDType)) {
|
|
|
|
|
if (ifaceRedDTypep->ifacep()) iterateConst(ifaceRedDTypep->ifacep());
|
|
|
|
|
} else {
|
|
|
|
|
while (nodeDtypep && nodeDtypep->subDTypep()
|
|
|
|
|
&& nodeDtypep->subDTypep()->skipRefp()) {
|
|
|
|
|
nodeDtypep = nodeDtypep->subDTypep()->skipRefp();
|
|
|
|
|
if (AstIfaceRefDType* const ifaceRedDTypep
|
|
|
|
|
= VN_CAST(nodeDtypep, IfaceRefDType)) {
|
|
|
|
|
if (ifaceRedDTypep->ifacep()) {
|
|
|
|
|
iterateConst(ifaceRedDTypep->ifacep());
|
|
|
|
|
}
|
|
|
|
|
} else if (AstNodeUOrStructDType* const uOrStructDTypep
|
|
|
|
|
= VN_CAST(nodeDtypep, NodeUOrStructDType)) {
|
|
|
|
|
iterateConst(uOrStructDTypep);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
makeToString(classp);
|
|
|
|
|
makeToStringMiddle(classp);
|
|
|
|
|
++m_statClassToString;
|
|
|
|
|
}
|
|
|
|
|
void visit(AstNodeUOrStructDType* structp) override {
|
|
|
|
|
if (structp->user1())
|
|
|
|
|
return; // if to_string() was already emitted skip the rest of the function
|
|
|
|
|
if (structp->emitToString()) ++m_emitForMembers;
|
|
|
|
|
if (m_emitForMembers
|
|
|
|
|
> 0) { // either this struct directly requires emission of to_string() or the
|
|
|
|
|
// class/struct that has this struct as a field requires it to emit to_string()
|
|
|
|
|
for (AstMemberDType* memberp = structp->membersp(); memberp;
|
|
|
|
|
memberp = VN_AS(memberp->nextp(), MemberDType)) {
|
|
|
|
|
AstNodeDType* nodeDtypep = memberp->dtypep();
|
|
|
|
|
if (AstNodeUOrStructDType* const uOrStructDTypep
|
|
|
|
|
= VN_CAST(nodeDtypep, NodeUOrStructDType)) {
|
|
|
|
|
iterateConst(uOrStructDTypep);
|
|
|
|
|
} else {
|
|
|
|
|
while (nodeDtypep && nodeDtypep->subDTypep()) {
|
|
|
|
|
nodeDtypep = nodeDtypep->subDTypep()->skipRefp();
|
|
|
|
|
if (AstNodeUOrStructDType* const uOrStructDTypep
|
|
|
|
|
= VN_CAST(nodeDtypep, NodeUOrStructDType)) {
|
|
|
|
|
iterateConst(uOrStructDTypep);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (structp->emitToString()) --m_emitForMembers;
|
|
|
|
|
|
|
|
|
|
if (!structp->packed()) {
|
|
|
|
|
makeVlToString(structp);
|
|
|
|
|
++m_statStructUnionToString;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
structp->user1(true); // mark that to_string() was emitted to not emit it twice (if
|
|
|
|
|
// e.g two printed classes have this struct as a field)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void visit(AstIface* ifacep) override {
|
|
|
|
|
if (ifacep->user1())
|
|
|
|
|
return; // if to_string() was already emitted skip the rest of the function
|
|
|
|
|
if (m_emitForMembers
|
|
|
|
|
> 0) { // class that has this iface as a field requires it to emit to_string()
|
2022-10-20 12:31:00 +02:00
|
|
|
makeVlToString(ifacep);
|
2026-05-12 15:49:21 +02:00
|
|
|
++m_statInterfaceToString;
|
|
|
|
|
ifacep->user1(true); // mark that to_string() was emitted to not emit it twice (if e.g
|
|
|
|
|
// two printed classes have this interface as a field)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// go towards class hierarchy root, if there is any printed from class on the way, mark its
|
|
|
|
|
// ancestors, and mark everything on the return path from the printed from class
|
|
|
|
|
void visit(AstClass* classp) override {
|
|
|
|
|
if (classp->user1()) return;
|
|
|
|
|
if (classp->isPrintedFrom()) {
|
|
|
|
|
markClassIterate(classp);
|
|
|
|
|
VL_RESTORER(m_emitTowardsRoot);
|
|
|
|
|
++m_emitTowardsRoot;
|
|
|
|
|
for (const AstClassExtends* extendp = classp->extendsp(); extendp;
|
|
|
|
|
extendp = VN_AS(extendp->nextp(), ClassExtends)) {
|
|
|
|
|
if (extendp->classp() && !extendp->classp()->user1()) {
|
|
|
|
|
iterateConst(extendp->classp());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
classp->user2(static_cast<int>(PrintedFromParent::PRINTED_FROM_PARENT));
|
|
|
|
|
} else {
|
|
|
|
|
PrintedFromParent printed_parent = static_cast<PrintedFromParent>(classp->user2());
|
|
|
|
|
if (printed_parent != PrintedFromParent::UNRESOLVED && m_emitTowardsRoot == 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_emitTowardsRoot > 0) markClassIterate(classp);
|
|
|
|
|
|
|
|
|
|
bool is_root = true;
|
|
|
|
|
for (const AstClassExtends* extendp = classp->extendsp(); extendp;
|
|
|
|
|
extendp = VN_AS(extendp->nextp(), ClassExtends)) {
|
|
|
|
|
if (extendp->classp()) {
|
|
|
|
|
if (static_cast<PrintedFromParent>(extendp->classp()->user2())
|
|
|
|
|
== PrintedFromParent::UNRESOLVED
|
|
|
|
|
|| (m_emitTowardsRoot > 0 && !extendp->classp()->user1())) {
|
|
|
|
|
iterateConst(extendp->classp());
|
|
|
|
|
}
|
|
|
|
|
if (printed_parent != PrintedFromParent::PRINTED_FROM_PARENT) {
|
|
|
|
|
printed_parent
|
|
|
|
|
= static_cast<PrintedFromParent>(extendp->classp()->user2());
|
|
|
|
|
}
|
|
|
|
|
is_root = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (is_root) printed_parent = PrintedFromParent::NO_PRINTED_FROM_PARENT;
|
|
|
|
|
|
|
|
|
|
classp->user2(static_cast<int>(printed_parent));
|
|
|
|
|
if (printed_parent == PrintedFromParent::PRINTED_FROM_PARENT) {
|
|
|
|
|
markClassIterate(classp);
|
|
|
|
|
|
|
|
|
|
// If one parent is printed from, other parent also has to emit to_string() to
|
|
|
|
|
// handle cases like:
|
|
|
|
|
// Base IFaceClass (printed from)
|
|
|
|
|
// V V
|
|
|
|
|
// Derived (this class)
|
|
|
|
|
VL_RESTORER(m_emitTowardsRoot);
|
|
|
|
|
++m_emitTowardsRoot;
|
|
|
|
|
for (const AstClassExtends* extendp = classp->extendsp(); extendp;
|
|
|
|
|
extendp = VN_AS(extendp->nextp(), ClassExtends)) {
|
|
|
|
|
if (extendp->classp() && !extendp->classp()->user1()) {
|
|
|
|
|
iterateConst(extendp->classp());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-07-20 17:40:38 +02:00
|
|
|
}
|
|
|
|
|
}
|
2026-05-12 15:49:21 +02:00
|
|
|
void visit(AstConstPool*) override {} // Accelerate
|
|
|
|
|
void visit(AstNode* nodep) override { iterateChildrenConst(nodep); }
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit ToStringVisitor(AstNode* nodep) {
|
|
|
|
|
if (v3Global.hasPrintedObjects()) {
|
|
|
|
|
AstNode::user1ClearTree();
|
|
|
|
|
AstNode::user2ClearTree();
|
|
|
|
|
|
|
|
|
|
iterateConst(nodep);
|
2022-12-21 01:22:42 +01:00
|
|
|
}
|
2026-05-12 15:49:21 +02:00
|
|
|
|
|
|
|
|
V3Stats::addStat("Optimizations, Class ToString emitted", m_statClassToString);
|
|
|
|
|
V3Stats::addStat("Optimizations, Interface ToString emitted", m_statInterfaceToString);
|
|
|
|
|
V3Stats::addStat("Optimizations, Struct/union ToString emitted",
|
|
|
|
|
m_statStructUnionToString);
|
2022-12-21 01:22:42 +01:00
|
|
|
}
|
2026-05-12 15:49:21 +02:00
|
|
|
~ToStringVisitor() override = default;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
// V3Common class functions
|
|
|
|
|
|
|
|
|
|
void V3Common::commonAll() {
|
|
|
|
|
UINFO(2, __FUNCTION__ << ":");
|
|
|
|
|
|
|
|
|
|
ToStringVisitor{v3Global.rootp()};
|
|
|
|
|
|
2024-01-09 16:35:13 +01:00
|
|
|
V3Global::dumpCheckGlobalTree("common", 0, dumpTreeEitherLevel() >= 3);
|
2021-07-20 17:40:38 +02:00
|
|
|
}
|