2020-02-01 21:45:11 +00:00
|
|
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
|
|
|
//*************************************************************************
|
|
|
|
// DESCRIPTION: Verilator: Handle SV classes
|
|
|
|
//
|
|
|
|
// Code available from: https://verilator.org
|
|
|
|
//
|
|
|
|
//*************************************************************************
|
|
|
|
//
|
2020-03-21 15:24:24 +00:00
|
|
|
// Copyright 2003-2020 by Wilson Snyder. This program is free software; you
|
|
|
|
// can redistribute it and/or modify it under the terms of either the GNU
|
2020-02-01 21:45:11 +00:00
|
|
|
// Lesser General Public License Version 3 or the Perl Artistic License
|
|
|
|
// Version 2.0.
|
2020-03-21 15:24:24 +00:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
2020-02-01 21:45:11 +00:00
|
|
|
//
|
|
|
|
//*************************************************************************
|
|
|
|
// V3Class's Transformations:
|
|
|
|
//
|
2020-02-02 00:11:19 +00:00
|
|
|
// Each module:
|
|
|
|
// Each cell:
|
|
|
|
// Create CUse for cell forward declaration
|
2020-02-01 21:45:11 +00:00
|
|
|
//
|
|
|
|
//*************************************************************************
|
|
|
|
|
|
|
|
#include "config_build.h"
|
|
|
|
#include "verilatedos.h"
|
|
|
|
|
|
|
|
#include "V3Global.h"
|
|
|
|
#include "V3CUse.h"
|
|
|
|
#include "V3Ast.h"
|
|
|
|
#include "V3EmitCBase.h"
|
|
|
|
|
|
|
|
#include VL_INCLUDE_UNORDERED_MAP
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
2020-02-02 00:11:19 +00:00
|
|
|
class CUseState {
|
2020-02-01 21:45:11 +00:00
|
|
|
private:
|
|
|
|
// MEMBERS
|
|
|
|
AstNodeModule* m_modInsertp; // Current module to insert AstCUse under
|
|
|
|
typedef std::pair<VUseType, string> UseString;
|
|
|
|
std::map<UseString, AstCUse*> m_didUse; // What we already used
|
|
|
|
|
|
|
|
// NODE STATE
|
|
|
|
// Entire netlist:
|
2020-02-02 00:11:19 +00:00
|
|
|
// AstClass::user1() -> bool. True if class needs to_string dumper
|
2020-02-01 21:45:11 +00:00
|
|
|
AstUser1InUse m_inuser1;
|
|
|
|
|
|
|
|
// METHODS
|
|
|
|
VL_DEBUG_FUNC; // Declare debug()
|
|
|
|
|
2020-02-02 00:11:19 +00:00
|
|
|
public:
|
2020-02-01 21:45:11 +00:00
|
|
|
AstCUse* newUse(AstNode* nodep, VUseType useType, const string& name) {
|
|
|
|
UseString key(useType, name);
|
|
|
|
if (m_didUse.find(key) == m_didUse.end()) {
|
|
|
|
AstCUse* newp = new AstCUse(nodep->fileline(), useType, name);
|
|
|
|
m_modInsertp->addStmtp(newp);
|
|
|
|
UINFO(8, "Insert " << newp << endl);
|
|
|
|
m_didUse[key] = newp;
|
|
|
|
}
|
|
|
|
return m_didUse[key];
|
|
|
|
}
|
2020-02-02 00:11:19 +00:00
|
|
|
|
|
|
|
// CONSTRUCTORS
|
|
|
|
explicit CUseState(AstNodeModule* nodep)
|
|
|
|
: m_modInsertp(nodep) {}
|
|
|
|
virtual ~CUseState() {}
|
|
|
|
VL_UNCOPYABLE(CUseState);
|
|
|
|
};
|
|
|
|
|
|
|
|
class CUseVisitor : public AstNVisitor {
|
|
|
|
// MEMBERS
|
|
|
|
CUseState m_state; // Inserter state
|
|
|
|
|
|
|
|
// METHODS
|
|
|
|
VL_DEBUG_FUNC; // Declare debug()
|
|
|
|
|
|
|
|
// Module use builders
|
2020-02-01 21:45:11 +00:00
|
|
|
void makeUseCells(AstNodeModule* nodep) {
|
|
|
|
for (AstNode* itemp = nodep->stmtsp(); itemp; itemp = itemp->nextp()) {
|
|
|
|
if (AstCell* cellp = VN_CAST(itemp, Cell)) {
|
|
|
|
// Currently no include because we include __Syms which has them all
|
2020-02-02 11:52:28 +00:00
|
|
|
m_state.newUse(nodep, VUseType::INT_FWD_CLASS, cellp->modp()->name());
|
2020-02-01 21:45:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-02 00:11:19 +00:00
|
|
|
// VISITORS
|
2020-02-01 21:45:11 +00:00
|
|
|
virtual void visit(AstNodeModule* nodep) VL_OVERRIDE {
|
|
|
|
if (v3Global.opt.trace()) {
|
2020-02-02 00:11:19 +00:00
|
|
|
AstCUse* usep
|
|
|
|
= m_state.newUse(nodep, VUseType::INT_FWD_CLASS, v3Global.opt.traceClassBase());
|
2020-02-01 21:45:11 +00:00
|
|
|
usep->protect(false);
|
|
|
|
}
|
|
|
|
makeUseCells(nodep);
|
|
|
|
}
|
2020-04-04 12:31:14 +00:00
|
|
|
virtual void visit(AstNode*) VL_OVERRIDE {} // All in AstNodeModule
|
2020-02-01 21:45:11 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
// CONSTRUCTORS
|
2020-02-02 00:11:19 +00:00
|
|
|
explicit CUseVisitor(AstNodeModule* nodep)
|
|
|
|
: m_state(nodep) {
|
|
|
|
iterate(nodep);
|
2020-02-01 21:45:11 +00:00
|
|
|
}
|
|
|
|
virtual ~CUseVisitor() {}
|
|
|
|
VL_UNCOPYABLE(CUseVisitor);
|
|
|
|
};
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
// Class class functions
|
|
|
|
|
|
|
|
void V3CUse::cUseAll(AstNetlist* nodep) {
|
|
|
|
UINFO(2, __FUNCTION__ << ": " << endl);
|
2020-02-02 00:11:19 +00:00
|
|
|
// Call visitor separately for each module, so visitor state is cleared
|
2020-02-04 04:21:56 +00:00
|
|
|
for (AstNodeModule* modp = v3Global.rootp()->modulesp(); modp;
|
|
|
|
modp = VN_CAST(modp->nextp(), NodeModule)) {
|
2020-02-02 00:11:19 +00:00
|
|
|
// Insert under this module; someday we should e.g. make Ast
|
|
|
|
// for each output file and put under that
|
2020-02-04 04:21:56 +00:00
|
|
|
CUseVisitor visitor(modp);
|
2020-02-02 00:11:19 +00:00
|
|
|
}
|
2020-02-01 21:45:11 +00:00
|
|
|
V3Global::dumpCheckGlobalTree("cuse", 0, v3Global.opt.dumpTreeLevel(__FILE__) >= 3);
|
|
|
|
}
|