From 495585830d5fa58cfb450aa42db98a7951c8802e Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Mon, 22 Mar 2010 18:38:24 -0400 Subject: [PATCH] Fix trace files with empty modules crashing some viewers. --- Changes | 4 +++- include/verilated_vcd_c.cpp | 45 +++++++++++++++++++++++++++++-------- include/verilated_vcd_c.h | 1 + 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/Changes b/Changes index 6af2a885e..f581a6e8b 100644 --- a/Changes +++ b/Changes @@ -7,9 +7,11 @@ indicates the contributor was also the author of the fix; Thanks! *** Support runtime access to public signal names. +**** Improve error handling on slices of arrays, bug226. [by Bryon Bradley] + **** Fix "make install" with configure outside srcdir. [Stefan Wallentowitz] -**** Improve error handling on slices of arrays, bug226. [by Bryon Bradley] +**** Fix trace files with empty modules crashing some viewers. * Verilator 3.801 2010/03/17 diff --git a/include/verilated_vcd_c.cpp b/include/verilated_vcd_c.cpp index 94269fb76..d86dab751 100644 --- a/include/verilated_vcd_c.cpp +++ b/include/verilated_vcd_c.cpp @@ -154,6 +154,39 @@ void VerilatedVcd::openNext (bool incFilename) { m_wroteBytes = 0; } +void VerilatedVcd::makeNameMap() { + // Take signal information from each module and build m_namemapp + m_namemapp = new NameMap; + for (vluint32_t ent = 0; ent< m_callbacks.size(); ent++) { + VerilatedVcdCallInfo *cip = m_callbacks[ent]; + cip->m_code = nextCode(); + (cip->m_initcb) (this, cip->m_userthis, cip->m_code); + } + + // Though not speced, it's illegal to generate a vcd with signals + // not under any module - it crashes at least two viewers. + // If no scope was specified, prefix everything with a "top" + // This comes from user instantiations with no name - IE Vtop(""). + bool nullScope = false; + for (NameMap::iterator it=m_namemapp->begin(); it!=m_namemapp->end(); ++it) { + const char* hiername = (*it).first.c_str(); + if (hiername[0] == '\t') nullScope=true; + } + if (nullScope) { + NameMap* newmapp = new NameMap; + for (NameMap::iterator it=m_namemapp->begin(); it!=m_namemapp->end(); ++it) { + const string& hiername = it->first; + const string& decl = it->second; + string newname = string("top"); + if (hiername[0] != '\t') newname += ' '; + newname += hiername; + newmapp->insert(make_pair(newname,decl)); + } + delete m_namemapp; m_namemapp=NULL; + m_namemapp = newmapp; + } +} + VerilatedVcd::~VerilatedVcd() { close(); if (m_wrBufp) { delete[] m_wrBufp; m_wrBufp=NULL; } @@ -314,13 +347,7 @@ void VerilatedVcd::dumpHeader () { printStr(doubleToTimescale(m_timeRes).c_str()); printStr(" $end\n"); - // Take signal information from each module and build m_namemapp - m_namemapp = new NameMap; - for (vluint32_t ent = 0; ent< m_callbacks.size(); ent++) { - VerilatedVcdCallInfo *cip = m_callbacks[ent]; - cip->m_code = nextCode(); - (cip->m_initcb) (this, cip->m_userthis, cip->m_code); - } + makeNameMap(); // Signal header assert (m_modDepth==0); @@ -346,7 +373,7 @@ void VerilatedVcd::dumpHeader () { // Skip common prefix, it must break at a space or tab for (; *np && (*np == *lp); np++, lp++) {} while (np!=hiername && *np && *np!=' ' && *np!='\t') { np--; lp--; } - //cout <<"hier "<lsb)?(msb-lsb):(lsb-msb))+1; diff --git a/include/verilated_vcd_c.h b/include/verilated_vcd_c.h index 60c3aa3a0..2fb77b35e 100644 --- a/include/verilated_vcd_c.h +++ b/include/verilated_vcd_c.h @@ -99,6 +99,7 @@ private: void closePrev(); void closeErr(); void openNext(); + void makeNameMap(); void printIndent (int levelchange); void printStr (const char* str); void printQuad (vluint64_t n);