2012-04-13 01:08:20 +00:00
|
|
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
2006-08-26 11:35:28 +00:00
|
|
|
//*************************************************************************
|
|
|
|
// DESCRIPTION: Verilator: Waves tracing
|
|
|
|
//
|
2008-04-25 12:14:27 +00:00
|
|
|
// Code available from: http://www.veripool.org/verilator
|
2006-08-26 11:35:28 +00:00
|
|
|
//
|
|
|
|
//*************************************************************************
|
|
|
|
//
|
2018-01-02 23:05:06 +00:00
|
|
|
// Copyright 2003-2018 by Wilson Snyder. This program is free software; you can
|
2006-08-26 11:35:28 +00:00
|
|
|
// redistribute it and/or modify it under the terms of either the GNU
|
2009-05-04 21:07:57 +00:00
|
|
|
// Lesser General Public License Version 3 or the Perl Artistic License
|
|
|
|
// Version 2.0.
|
2006-08-26 11:35:28 +00:00
|
|
|
//
|
|
|
|
// Verilator is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
//*************************************************************************
|
|
|
|
// V3TraceDecl's Transformations:
|
|
|
|
// Create trace CFUNCs
|
|
|
|
// For each VARSCOPE
|
|
|
|
// If appropriate type of signal, create a TRACE
|
2008-06-10 01:25:10 +00:00
|
|
|
//
|
2006-08-26 11:35:28 +00:00
|
|
|
//*************************************************************************
|
|
|
|
|
2006-12-18 19:20:45 +00:00
|
|
|
#include "config_build.h"
|
|
|
|
#include "verilatedos.h"
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
#include "V3Global.h"
|
|
|
|
#include "V3TraceDecl.h"
|
|
|
|
#include "V3EmitCBase.h"
|
|
|
|
#include "V3Stats.h"
|
|
|
|
|
2018-10-14 17:43:24 +00:00
|
|
|
#include <cstdarg>
|
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
//######################################################################
|
|
|
|
// TraceDecl state, as a visitor of each AstNode
|
|
|
|
|
|
|
|
class TraceDeclVisitor : public EmitCBaseVisitor {
|
|
|
|
private:
|
|
|
|
// NODE STATE
|
|
|
|
|
|
|
|
// STATE
|
|
|
|
AstScope* m_scopetopp; // Current top scope
|
|
|
|
AstCFunc* m_initFuncp; // Trace function being built
|
2008-11-17 22:13:57 +00:00
|
|
|
AstCFunc* m_initSubFuncp; // Trace function being built (under m_init)
|
|
|
|
int m_initSubStmts; // Number of statements in function
|
2006-08-26 11:35:28 +00:00
|
|
|
AstCFunc* m_fullFuncp; // Trace function being built
|
|
|
|
AstCFunc* m_chgFuncp; // Trace function being built
|
2008-11-17 22:13:57 +00:00
|
|
|
int m_funcNum; // Function number being built
|
2013-12-14 21:51:08 +00:00
|
|
|
AstVarScope* m_traVscp; // Signal being trace constructed
|
|
|
|
AstNode* m_traValuep; // Signal being traced's value to trace in it
|
|
|
|
string m_traShowname; // Signal being traced's component name
|
2008-11-17 22:13:57 +00:00
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
V3Double0 m_statSigs; // Statistic tracking
|
|
|
|
V3Double0 m_statIgnSigs; // Statistic tracking
|
|
|
|
|
|
|
|
// METHODS
|
2018-05-14 10:50:47 +00:00
|
|
|
VL_DEBUG_FUNC; // Declare debug()
|
2009-01-21 21:56:50 +00:00
|
|
|
|
2014-11-08 19:15:10 +00:00
|
|
|
const char* vscIgnoreTrace(AstVarScope* nodep) {
|
2006-08-26 11:35:28 +00:00
|
|
|
// Return true if this shouldn't be traced
|
2008-12-12 20:34:02 +00:00
|
|
|
// See also similar rule in V3Coverage::varIgnoreToggle
|
2014-11-08 19:15:10 +00:00
|
|
|
AstVar* varp = nodep->varp();
|
|
|
|
if (!varp->isTrace()) {
|
2006-08-26 11:35:28 +00:00
|
|
|
return "Verilator trace_off";
|
2013-12-14 21:51:08 +00:00
|
|
|
}
|
2014-11-08 19:15:10 +00:00
|
|
|
else if (!nodep->isTrace()) {
|
|
|
|
return "Verilator cell trace_off";
|
|
|
|
}
|
2013-12-14 21:51:08 +00:00
|
|
|
else if (!v3Global.opt.traceUnderscore()) {
|
2016-09-13 01:52:40 +00:00
|
|
|
string prettyName = varp->prettyName();
|
2014-06-09 01:36:18 +00:00
|
|
|
if (prettyName.size()>=1 && prettyName[0] == '_')
|
2010-08-29 23:28:46 +00:00
|
|
|
return "Leading underscore";
|
|
|
|
if (prettyName.find("._") != string::npos)
|
|
|
|
return "Inlined leading underscore";
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-11-17 22:13:57 +00:00
|
|
|
AstCFunc* newCFunc(AstCFuncType type, const string& name, bool slow) {
|
|
|
|
AstCFunc* funcp = new AstCFunc(m_scopetopp->fileline(), name, m_scopetopp);
|
|
|
|
funcp->slow(slow);
|
2010-01-24 23:37:01 +00:00
|
|
|
funcp->argTypes(EmitCBaseVisitor::symClassVar()+", "+v3Global.opt.traceClassBase()+"* vcdp, uint32_t code");
|
2008-11-17 22:13:57 +00:00
|
|
|
funcp->funcType(type);
|
|
|
|
funcp->symProlog(true);
|
|
|
|
m_scopetopp->addActivep(funcp);
|
|
|
|
UINFO(5," Newfunc "<<funcp<<endl);
|
|
|
|
return funcp;
|
|
|
|
}
|
|
|
|
AstCFunc* newCFuncSub(AstCFunc* basep) {
|
|
|
|
string name = basep->name()+"__"+cvtToStr(++m_funcNum);
|
|
|
|
AstCFunc* funcp = NULL;
|
|
|
|
if (basep->funcType()==AstCFuncType::TRACE_INIT) {
|
|
|
|
funcp = newCFunc(AstCFuncType::TRACE_INIT_SUB, name, basep->slow());
|
|
|
|
} else {
|
|
|
|
basep->v3fatalSrc("Strange base function type");
|
|
|
|
}
|
2011-08-05 01:58:45 +00:00
|
|
|
// cppcheck-suppress nullPointer // above fatal prevents it
|
2008-11-17 22:13:57 +00:00
|
|
|
AstCCall* callp = new AstCCall(funcp->fileline(), funcp);
|
|
|
|
callp->argTypes("vlSymsp, vcdp, code");
|
|
|
|
basep->addStmtsp(callp);
|
|
|
|
return funcp;
|
|
|
|
}
|
2014-04-16 00:20:45 +00:00
|
|
|
void addTraceDecl(const VNumRange& arrayRange,
|
|
|
|
int widthOverride) { // If !=0, is packed struct/array where basicp size misreflects one element
|
2013-12-14 21:51:08 +00:00
|
|
|
VNumRange bitRange;
|
|
|
|
AstBasicDType* bdtypep = m_traValuep->dtypep()->basicp();
|
2014-04-16 00:20:45 +00:00
|
|
|
if (widthOverride) bitRange = VNumRange(widthOverride-1,0,false);
|
|
|
|
else if (bdtypep) bitRange = bdtypep->nrange();
|
2018-10-03 23:51:05 +00:00
|
|
|
AstTraceDecl* declp = new AstTraceDecl(m_traVscp->fileline(), m_traShowname,
|
|
|
|
m_traVscp->varp(), m_traValuep,
|
2013-12-14 21:51:08 +00:00
|
|
|
bitRange, arrayRange);
|
2014-04-16 00:20:45 +00:00
|
|
|
UINFO(9,"Decl "<<declp<<endl);
|
2013-12-14 21:51:08 +00:00
|
|
|
|
|
|
|
if (m_initSubStmts && v3Global.opt.outputSplitCTrace()
|
|
|
|
&& m_initSubStmts > v3Global.opt.outputSplitCTrace()) {
|
|
|
|
m_initSubFuncp = newCFuncSub(m_initFuncp);
|
|
|
|
m_initSubStmts = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_initSubFuncp->addStmtsp(declp);
|
|
|
|
m_initSubStmts += EmitCBaseCounterVisitor(declp).count();
|
|
|
|
|
|
|
|
m_chgFuncp->addStmtsp(new AstTraceInc(m_traVscp->fileline(), declp, m_traValuep->cloneTree(true)));
|
|
|
|
// The full version will get constructed in V3Trace
|
|
|
|
}
|
|
|
|
void addIgnore(const char* why) {
|
|
|
|
++m_statIgnSigs;
|
|
|
|
m_initSubFuncp->addStmtsp(
|
|
|
|
new AstComment(m_traVscp->fileline(), "Tracing: "+m_traShowname+" // Ignored: "+why));
|
|
|
|
}
|
2008-11-17 22:13:57 +00:00
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
// VISITORS
|
2016-11-27 13:11:38 +00:00
|
|
|
virtual void visit(AstTopScope* nodep) {
|
2006-08-29 19:10:55 +00:00
|
|
|
m_scopetopp = nodep->scopep();
|
2008-11-17 22:13:57 +00:00
|
|
|
// Make containers for TRACEDECLs first
|
|
|
|
m_initFuncp = newCFunc(AstCFuncType::TRACE_INIT, "traceInitThis", true);
|
|
|
|
m_fullFuncp = newCFunc(AstCFuncType::TRACE_FULL, "traceFullThis", true);
|
|
|
|
m_chgFuncp = newCFunc(AstCFuncType::TRACE_CHANGE, "traceChgThis", false);
|
|
|
|
//
|
|
|
|
m_initSubFuncp = newCFuncSub(m_initFuncp);
|
|
|
|
// And find variables
|
2018-05-11 00:55:37 +00:00
|
|
|
iterateChildren(nodep);
|
2006-08-26 11:35:28 +00:00
|
|
|
}
|
2016-11-27 13:11:38 +00:00
|
|
|
virtual void visit(AstVarScope* nodep) {
|
2018-05-11 00:55:37 +00:00
|
|
|
iterateChildren(nodep);
|
2014-03-08 20:36:04 +00:00
|
|
|
// Avoid updating this if (), instead see varp->isTrace()
|
|
|
|
if (!nodep->varp()->isTemp() && !nodep->varp()->isFuncLocal()) {
|
2006-08-26 11:35:28 +00:00
|
|
|
UINFO(5, " vsc "<<nodep<<endl);
|
|
|
|
AstVar* varp = nodep->varp();
|
|
|
|
AstScope* scopep = nodep->scopep();
|
|
|
|
// Compute show name
|
2009-09-26 13:31:50 +00:00
|
|
|
// This code assumes SPTRACEVCDC_VERSION >= 1330;
|
|
|
|
// it uses spaces to separate hierarchy components.
|
2013-12-14 21:51:08 +00:00
|
|
|
m_traShowname = AstNode::vcdName(scopep->name() + " " + varp->name());
|
|
|
|
if (m_traShowname.substr(0,4) == "TOP ") m_traShowname.replace(0,4,"");
|
2008-11-17 22:13:57 +00:00
|
|
|
if (!m_initSubFuncp) nodep->v3fatalSrc("NULL");
|
2013-12-14 21:51:08 +00:00
|
|
|
|
|
|
|
m_traVscp = nodep;
|
|
|
|
m_traValuep = NULL;
|
2014-11-08 19:15:10 +00:00
|
|
|
if (vscIgnoreTrace(nodep)) {
|
|
|
|
addIgnore(vscIgnoreTrace(nodep));
|
2006-08-26 11:35:28 +00:00
|
|
|
} else {
|
2011-08-05 01:15:24 +00:00
|
|
|
++m_statSigs;
|
2013-12-14 21:51:08 +00:00
|
|
|
if (nodep->valuep()) m_traValuep = nodep->valuep()->cloneTree(true);
|
|
|
|
else m_traValuep = new AstVarRef(nodep->fileline(), nodep, false);
|
|
|
|
{
|
|
|
|
// Recurse into data type of the signal; the visitors will call addTraceDecl()
|
2018-05-11 00:55:37 +00:00
|
|
|
iterate(varp->dtypeSkipRefp());
|
2008-11-17 22:13:57 +00:00
|
|
|
}
|
2013-12-14 21:51:08 +00:00
|
|
|
// Cleanup
|
|
|
|
if (m_traValuep) { m_traValuep->deleteTree(); m_traValuep=NULL; }
|
|
|
|
}
|
|
|
|
m_traVscp = NULL;
|
|
|
|
m_traValuep = NULL;
|
|
|
|
m_traShowname = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// VISITORS - Data types when tracing
|
2016-11-27 13:11:38 +00:00
|
|
|
virtual void visit(AstConstDType* nodep) {
|
2013-12-14 21:51:08 +00:00
|
|
|
if (m_traVscp) {
|
2018-05-11 00:55:37 +00:00
|
|
|
iterate(nodep->subDTypep()->skipRefp());
|
2013-12-14 21:51:08 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-27 13:11:38 +00:00
|
|
|
virtual void visit(AstRefDType* nodep) {
|
2013-12-14 21:51:08 +00:00
|
|
|
if (m_traVscp) {
|
2018-05-11 00:55:37 +00:00
|
|
|
iterate(nodep->subDTypep()->skipRefp());
|
2013-12-14 21:51:08 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-27 13:11:38 +00:00
|
|
|
virtual void visit(AstUnpackArrayDType* nodep) {
|
2013-12-14 21:51:08 +00:00
|
|
|
// Note more specific dtypes above
|
|
|
|
if (m_traVscp) {
|
|
|
|
if ((int)nodep->arrayUnpackedElements() > v3Global.opt.traceMaxArray()) {
|
|
|
|
addIgnore("Wide memory > --trace-max-array ents");
|
2018-02-02 02:32:58 +00:00
|
|
|
} else if (VN_IS(nodep->subDTypep()->skipRefp(), BasicDType) // Nothing lower than this array
|
2013-12-14 21:51:08 +00:00
|
|
|
&& m_traVscp->dtypep()->skipRefp() == nodep) { // Nothing above this array
|
|
|
|
// Simple 1-D array, use exising V3EmitC runtime loop rather than unrolling
|
|
|
|
// This will put "(index)" at end of signal name for us
|
2018-09-08 05:16:07 +00:00
|
|
|
if (m_traVscp->dtypep()->skipRefp()->isString()) {
|
|
|
|
addIgnore("Unsupported: strings");
|
|
|
|
} else {
|
|
|
|
addTraceDecl(nodep->declRange(), 0);
|
|
|
|
}
|
2013-12-14 21:51:08 +00:00
|
|
|
} else {
|
|
|
|
// Unroll now, as have no other method to get right signal names
|
|
|
|
AstNodeDType* subtypep = nodep->subDTypep()->skipRefp();
|
|
|
|
for (int i=nodep->lsb(); i<=nodep->msb(); ++i) {
|
|
|
|
string oldShowname = m_traShowname;
|
|
|
|
AstNode* oldValuep = m_traValuep;
|
|
|
|
{
|
|
|
|
m_traShowname += string("(")+cvtToStr(i)+string(")");
|
|
|
|
m_traValuep = new AstArraySel(nodep->fileline(), m_traValuep->cloneTree(true),
|
|
|
|
i - nodep->lsb());
|
2008-11-17 22:13:57 +00:00
|
|
|
|
2018-05-11 00:55:37 +00:00
|
|
|
iterate(subtypep);
|
2013-12-14 21:51:08 +00:00
|
|
|
m_traValuep->deleteTree(); m_traValuep = NULL;
|
|
|
|
}
|
|
|
|
m_traShowname = oldShowname;
|
|
|
|
m_traValuep = oldValuep;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-11-27 13:11:38 +00:00
|
|
|
virtual void visit(AstPackArrayDType* nodep) {
|
2013-12-14 21:51:08 +00:00
|
|
|
if (m_traVscp) {
|
2013-12-15 00:13:31 +00:00
|
|
|
if (!v3Global.opt.traceStructs()) {
|
|
|
|
// Everything downstream is packed, so deal with as one trace unit
|
|
|
|
// This may not be the nicest for user presentation, but is a much faster way to trace
|
2014-04-16 00:20:45 +00:00
|
|
|
addTraceDecl(VNumRange(), nodep->width());
|
2013-12-15 00:13:31 +00:00
|
|
|
} else {
|
|
|
|
AstNodeDType* subtypep = nodep->subDTypep()->skipRefp();
|
|
|
|
for (int i=nodep->lsb(); i<=nodep->msb(); ++i) {
|
|
|
|
string oldShowname = m_traShowname;
|
|
|
|
AstNode* oldValuep = m_traValuep;
|
|
|
|
{
|
|
|
|
m_traShowname += string("(")+cvtToStr(i)+string(")");
|
|
|
|
m_traValuep = new AstSel(nodep->fileline(), m_traValuep->cloneTree(true),
|
|
|
|
(i - nodep->lsb())*subtypep->width(),
|
|
|
|
subtypep->width());
|
2018-05-11 00:55:37 +00:00
|
|
|
iterate(subtypep);
|
2013-12-15 00:13:31 +00:00
|
|
|
m_traValuep->deleteTree(); m_traValuep = NULL;
|
|
|
|
}
|
|
|
|
m_traShowname = oldShowname;
|
|
|
|
m_traValuep = oldValuep;
|
|
|
|
}
|
|
|
|
}
|
2013-12-14 21:51:08 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-27 13:11:38 +00:00
|
|
|
virtual void visit(AstNodeClassDType* nodep) {
|
2013-12-14 21:51:08 +00:00
|
|
|
if (m_traVscp) {
|
2013-12-15 00:13:31 +00:00
|
|
|
if (nodep->packed() && !v3Global.opt.traceStructs()) {
|
2013-12-14 21:51:08 +00:00
|
|
|
// Everything downstream is packed, so deal with as one trace unit
|
|
|
|
// This may not be the nicest for user presentation, but is a much faster way to trace
|
2014-04-16 00:20:45 +00:00
|
|
|
addTraceDecl(VNumRange(), nodep->width());
|
2013-12-14 21:51:08 +00:00
|
|
|
} else {
|
2013-12-15 00:13:31 +00:00
|
|
|
if (!nodep->packed()) {
|
|
|
|
addIgnore("Unsupported: Unpacked struct/union");
|
|
|
|
} else {
|
2018-02-02 02:32:58 +00:00
|
|
|
for (AstMemberDType* itemp = nodep->membersp(); itemp; itemp=VN_CAST(itemp->nextp(), MemberDType)) {
|
2013-12-15 00:13:31 +00:00
|
|
|
AstNodeDType* subtypep = itemp->subDTypep()->skipRefp();
|
|
|
|
string oldShowname = m_traShowname;
|
|
|
|
AstNode* oldValuep = m_traValuep;
|
|
|
|
{
|
|
|
|
m_traShowname += string(" ")+itemp->prettyName();
|
2018-02-02 02:32:58 +00:00
|
|
|
if (VN_IS(nodep, StructDType)) {
|
2013-12-15 00:13:31 +00:00
|
|
|
m_traValuep = new AstSel(nodep->fileline(), m_traValuep->cloneTree(true),
|
|
|
|
itemp->lsb(), subtypep->width());
|
2018-05-11 00:55:37 +00:00
|
|
|
iterate(subtypep);
|
2013-12-15 00:13:31 +00:00
|
|
|
m_traValuep->deleteTree(); m_traValuep = NULL;
|
|
|
|
} else { // Else union, replicate fields
|
2018-05-11 00:55:37 +00:00
|
|
|
iterate(subtypep);
|
2013-12-15 00:13:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
m_traShowname = oldShowname;
|
|
|
|
m_traValuep = oldValuep;
|
|
|
|
}
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-11-27 13:11:38 +00:00
|
|
|
virtual void visit(AstBasicDType* nodep) {
|
2013-12-14 21:51:08 +00:00
|
|
|
if (m_traVscp) {
|
2018-09-08 05:16:07 +00:00
|
|
|
if (nodep->isString()) {
|
2014-03-15 00:36:47 +00:00
|
|
|
addIgnore("Unsupported: strings");
|
|
|
|
} else {
|
2014-04-16 00:20:45 +00:00
|
|
|
addTraceDecl(VNumRange(), 0);
|
2014-03-15 00:36:47 +00:00
|
|
|
}
|
2013-12-14 21:51:08 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-27 13:11:38 +00:00
|
|
|
virtual void visit(AstNodeDType* nodep) {
|
2013-12-14 21:51:08 +00:00
|
|
|
// Note more specific dtypes above
|
|
|
|
if (!m_traVscp) return;
|
|
|
|
addIgnore("Unsupported: data type");
|
|
|
|
}
|
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
//--------------------
|
2016-11-27 13:11:38 +00:00
|
|
|
virtual void visit(AstNode* nodep) {
|
2018-05-11 00:55:37 +00:00
|
|
|
iterateChildren(nodep);
|
2006-08-26 11:35:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
// CONSTUCTORS
|
2015-10-04 02:33:06 +00:00
|
|
|
explicit TraceDeclVisitor(AstNetlist* nodep) {
|
2006-08-26 11:35:28 +00:00
|
|
|
m_scopetopp = NULL;
|
|
|
|
m_initFuncp = NULL;
|
2008-11-17 22:13:57 +00:00
|
|
|
m_initSubFuncp = NULL;
|
|
|
|
m_initSubStmts = 0;
|
2006-08-26 11:35:28 +00:00
|
|
|
m_fullFuncp = NULL;
|
|
|
|
m_chgFuncp = NULL;
|
2008-11-17 22:13:57 +00:00
|
|
|
m_funcNum = 0;
|
2013-12-14 21:51:08 +00:00
|
|
|
m_traVscp = NULL;
|
|
|
|
m_traValuep = NULL;
|
2018-05-11 00:55:37 +00:00
|
|
|
iterate(nodep);
|
2006-08-26 11:35:28 +00:00
|
|
|
}
|
|
|
|
virtual ~TraceDeclVisitor() {
|
|
|
|
V3Stats::addStat("Tracing, Traced signals", m_statSigs);
|
|
|
|
V3Stats::addStat("Tracing, Ignored signals", m_statIgnSigs);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
// Trace class functions
|
|
|
|
|
|
|
|
void V3TraceDecl::traceDeclAll(AstNetlist* nodep) {
|
|
|
|
UINFO(2,__FUNCTION__<<": "<<endl);
|
2018-03-10 17:57:50 +00:00
|
|
|
{
|
|
|
|
TraceDeclVisitor visitor (nodep);
|
|
|
|
} // Destruct before checking
|
2017-09-18 02:52:57 +00:00
|
|
|
V3Global::dumpCheckGlobalTree("tracedecl", 0, v3Global.opt.dumpTreeLevel(__FILE__) >= 3);
|
2006-08-26 11:35:28 +00:00
|
|
|
}
|