2012-04-13 03:08:20 +02:00
|
|
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
2006-08-26 13:35:28 +02:00
|
|
|
//*************************************************************************
|
|
|
|
|
// DESCRIPTION: Verilator: Change names for __PVT__'s
|
|
|
|
|
//
|
2019-11-08 04:33:59 +01:00
|
|
|
// Code available from: https://verilator.org
|
2006-08-26 13:35:28 +02:00
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
//
|
2024-01-01 09:19:59 +01:00
|
|
|
// Copyright 2003-2024 by Wilson Snyder. This program is free software; you
|
2020-03-21 16:24:24 +01:00
|
|
|
// can redistribute it and/or modify it under the terms of either the GNU
|
2009-05-04 23:07:57 +02:00
|
|
|
// Lesser General Public License Version 3 or the Perl Artistic License
|
|
|
|
|
// Version 2.0.
|
2020-03-21 16:24:24 +01:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
2006-08-26 13:35:28 +02:00
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
// V3Name's Transformations:
|
2008-06-10 03:25:10 +02:00
|
|
|
//
|
2019-05-19 22:13:13 +02:00
|
|
|
// Cell/Var's
|
|
|
|
|
// Prepend __PVT__ to variable names
|
2006-08-26 13:35:28 +02:00
|
|
|
//*************************************************************************
|
2019-10-05 02:17:11 +02:00
|
|
|
|
2023-10-18 12:37:46 +02:00
|
|
|
#include "V3PchAstNoMT.h" // VL_MT_DISABLED_CODE_UNIT
|
|
|
|
|
|
2006-08-26 13:35:28 +02:00
|
|
|
#include "V3Name.h"
|
2022-08-05 11:56:57 +02:00
|
|
|
|
2009-07-22 21:21:41 +02:00
|
|
|
#include "V3LanguageWords.h"
|
2006-08-26 13:35:28 +02:00
|
|
|
|
2022-09-18 21:53:42 +02:00
|
|
|
VL_DEFINE_DEBUG_FUNCTIONS;
|
|
|
|
|
|
2006-08-26 13:35:28 +02:00
|
|
|
//######################################################################
|
|
|
|
|
// Name state, as a visitor of each AstNode
|
|
|
|
|
|
2023-11-13 00:26:29 +01:00
|
|
|
class NameVisitor final : public VNVisitorConst {
|
2006-08-26 13:35:28 +02:00
|
|
|
// NODE STATE
|
|
|
|
|
// Cleared on Netlist
|
2019-05-19 22:13:13 +02:00
|
|
|
// AstCell::user1() -> bool. Set true if already processed
|
|
|
|
|
// AstScope::user1() -> bool. Set true if already processed
|
|
|
|
|
// AstVar::user1() -> bool. Set true if already processed
|
2022-01-02 19:56:40 +01:00
|
|
|
const VNUser1InUse m_inuser1;
|
2006-08-26 13:35:28 +02:00
|
|
|
|
2023-05-27 15:43:23 +02:00
|
|
|
// STATE - for current visit position (use VL_RESTORER)
|
|
|
|
|
const AstNodeModule* m_modp = nullptr; // Current module
|
2006-08-26 13:35:28 +02:00
|
|
|
|
2009-01-21 22:56:50 +01:00
|
|
|
// METHODS
|
2009-07-22 21:21:41 +02:00
|
|
|
void rename(AstNode* nodep, bool addPvt) {
|
2019-05-19 22:13:13 +02:00
|
|
|
if (!nodep->user1()) { // Not already done
|
|
|
|
|
if (addPvt) {
|
2022-08-30 07:02:39 +02:00
|
|
|
const string newname = std::string{"__PVT__"} + nodep->name();
|
2019-05-19 22:13:13 +02:00
|
|
|
nodep->name(newname);
|
2020-01-20 22:53:27 +01:00
|
|
|
nodep->editCountInc();
|
2021-10-22 14:56:48 +02:00
|
|
|
} else if (VN_IS(nodep, CFunc) && VN_AS(nodep, CFunc)->isConstructor()) {
|
2019-05-19 22:13:13 +02:00
|
|
|
} else {
|
2021-06-21 00:32:57 +02:00
|
|
|
const string rsvd = V3LanguageWords::isKeyword(nodep->name());
|
2019-05-19 22:13:13 +02:00
|
|
|
if (rsvd != "") {
|
2020-04-14 04:51:35 +02:00
|
|
|
nodep->v3warn(SYMRSVDWORD,
|
|
|
|
|
"Symbol matches " + rsvd + ": " << nodep->prettyNameQ());
|
2022-08-30 07:02:39 +02:00
|
|
|
const string newname = std::string{"__SYM__"} + nodep->name();
|
2019-05-19 22:13:13 +02:00
|
|
|
nodep->name(newname);
|
2020-01-20 22:53:27 +01:00
|
|
|
nodep->editCountInc();
|
2019-05-19 22:13:13 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
nodep->user1(1);
|
|
|
|
|
}
|
2009-07-22 21:21:41 +02:00
|
|
|
}
|
|
|
|
|
|
2006-08-26 13:35:28 +02:00
|
|
|
// VISITORS
|
2022-09-16 12:22:11 +02:00
|
|
|
void visit(AstNodeModule* nodep) override {
|
2020-08-25 03:10:43 +02:00
|
|
|
VL_RESTORER(m_modp);
|
2020-01-20 19:27:27 +01:00
|
|
|
{
|
|
|
|
|
m_modp = nodep;
|
2023-11-13 00:26:29 +01:00
|
|
|
iterateChildrenConst(nodep);
|
2020-01-20 19:27:27 +01:00
|
|
|
}
|
2006-08-26 13:35:28 +02:00
|
|
|
}
|
|
|
|
|
// Add __PVT__ to names of local signals
|
2022-09-16 12:22:11 +02:00
|
|
|
void visit(AstVar* nodep) override {
|
2019-05-19 22:13:13 +02:00
|
|
|
// Don't iterate... Don't need temps for RANGES under the Var.
|
2020-04-14 04:51:35 +02:00
|
|
|
rename(nodep,
|
|
|
|
|
((!m_modp || !m_modp->isTop()) && !nodep->isSigPublic()
|
|
|
|
|
&& !nodep->isFuncLocal() // Isn't exposed, and would mess up dpi import wrappers
|
|
|
|
|
&& !nodep->isTemp())); // Don't bother to rename internal signals
|
2009-07-22 21:21:41 +02:00
|
|
|
}
|
2022-09-16 12:22:11 +02:00
|
|
|
void visit(AstCFunc* nodep) override {
|
2019-05-19 22:13:13 +02:00
|
|
|
if (!nodep->user1()) {
|
2023-11-13 00:26:29 +01:00
|
|
|
iterateChildrenConst(nodep);
|
2019-05-19 22:13:13 +02:00
|
|
|
rename(nodep, false);
|
|
|
|
|
}
|
2006-08-26 13:35:28 +02:00
|
|
|
}
|
2023-11-13 00:26:29 +01:00
|
|
|
void visit(AstVarRef* nodep) override { iterateConst(nodep->varp()); }
|
2022-09-16 12:22:11 +02:00
|
|
|
void visit(AstCell* nodep) override {
|
2019-05-19 22:13:13 +02:00
|
|
|
if (!nodep->user1()) {
|
2020-04-14 04:51:35 +02:00
|
|
|
rename(nodep, (!nodep->modp()->modPublic() && !VN_IS(nodep->modp(), ClassPackage)));
|
2023-11-13 00:26:29 +01:00
|
|
|
iterateChildrenConst(nodep);
|
2019-05-19 22:13:13 +02:00
|
|
|
}
|
2006-08-26 13:35:28 +02:00
|
|
|
}
|
2022-09-16 12:22:11 +02:00
|
|
|
void visit(AstMemberDType* nodep) override {
|
2019-05-19 22:13:13 +02:00
|
|
|
if (!nodep->user1()) {
|
2023-03-06 13:18:48 +01:00
|
|
|
rename(nodep, true);
|
2023-11-13 00:26:29 +01:00
|
|
|
iterateChildrenConst(nodep);
|
2019-05-19 22:13:13 +02:00
|
|
|
}
|
2014-04-16 01:35:44 +02:00
|
|
|
}
|
2022-09-16 12:22:11 +02:00
|
|
|
void visit(AstMemberSel* nodep) override {
|
2019-05-19 22:13:13 +02:00
|
|
|
if (!nodep->user1()) {
|
2023-03-06 13:18:48 +01:00
|
|
|
rename(nodep, true);
|
2023-11-13 00:26:29 +01:00
|
|
|
iterateChildrenConst(nodep);
|
2023-03-06 13:18:48 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void visit(AstStructSel* nodep) override {
|
|
|
|
|
if (!nodep->user1()) {
|
|
|
|
|
rename(nodep, true);
|
2023-11-13 00:26:29 +01:00
|
|
|
iterateChildrenConst(nodep);
|
2019-05-19 22:13:13 +02:00
|
|
|
}
|
2014-04-16 01:35:44 +02:00
|
|
|
}
|
2022-09-16 12:22:11 +02:00
|
|
|
void visit(AstScope* nodep) override {
|
2019-05-19 22:13:13 +02:00
|
|
|
if (!nodep->user1SetOnce()) {
|
2023-11-13 00:26:29 +01:00
|
|
|
if (nodep->aboveScopep()) iterateConst(nodep->aboveScopep());
|
|
|
|
|
if (nodep->aboveCellp()) iterateConst(nodep->aboveCellp());
|
2020-04-05 15:30:23 +02:00
|
|
|
// Always recompute name (as many levels above scope may have changed)
|
2019-05-19 22:13:13 +02:00
|
|
|
// Same formula as V3Scope
|
2021-06-14 20:50:40 +02:00
|
|
|
nodep->name(nodep->isTop() ? "TOP"
|
|
|
|
|
: VN_IS(m_modp, Class) ? ("TOP." + m_modp->name())
|
|
|
|
|
: VN_IS(m_modp, ClassPackage)
|
|
|
|
|
? ("TOP." + m_modp->name())
|
|
|
|
|
: (nodep->aboveScopep()->name() + "." + nodep->aboveCellp()->name()));
|
2020-04-05 15:30:23 +02:00
|
|
|
nodep->editCountInc();
|
2023-11-13 00:26:29 +01:00
|
|
|
iterateChildrenConst(nodep);
|
2019-05-19 22:13:13 +02:00
|
|
|
}
|
2006-08-26 13:35:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------
|
2023-11-13 00:26:29 +01:00
|
|
|
void visit(AstNode* nodep) override { iterateChildrenConst(nodep); }
|
2020-04-04 14:31:14 +02:00
|
|
|
|
2006-08-26 13:35:28 +02:00
|
|
|
public:
|
2019-09-12 13:22:22 +02:00
|
|
|
// CONSTRUCTORS
|
2023-11-13 00:26:29 +01:00
|
|
|
explicit NameVisitor(AstNetlist* nodep) { iterateConst(nodep); }
|
2022-09-16 12:22:11 +02:00
|
|
|
~NameVisitor() override = default;
|
2006-08-26 13:35:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
// Name class functions
|
|
|
|
|
|
|
|
|
|
void V3Name::nameAll(AstNetlist* nodep) {
|
2020-04-14 04:51:35 +02:00
|
|
|
UINFO(2, __FUNCTION__ << ": " << endl);
|
2021-11-26 16:52:36 +01:00
|
|
|
{ NameVisitor{nodep}; } // Destruct before checking
|
2023-05-04 00:04:10 +02:00
|
|
|
V3Global::dumpCheckGlobalTree("name", 0, dumpTreeLevel() >= 6);
|
2006-08-26 13:35:28 +02:00
|
|
|
}
|