Fix FST when multi-model tracing.

This commit is contained in:
Wilson Snyder 2020-03-07 18:39:58 -05:00
parent 6f49f802b1
commit 6c6d70a5e5
9 changed files with 183 additions and 146 deletions

View File

@ -77,10 +77,11 @@ protected:
// VerilatedFst // VerilatedFst
VerilatedFst::VerilatedFst(void* fst) VerilatedFst::VerilatedFst(void* fst)
: m_fst(fst), : m_fst(fst)
m_fullDump(true), , m_fullDump(true)
m_scopeEscape('.') { , m_nextCode(1)
m_valueStrBuffer.reserve(64+1); // Need enough room for quad , m_scopeEscape('.') {
m_valueStrBuffer.reserve(64 + 1); // Need enough room for quad
} }
void VerilatedFst::open(const char* filename) VL_MT_UNSAFE { void VerilatedFst::open(const char* filename) VL_MT_UNSAFE {
@ -91,10 +92,12 @@ void VerilatedFst::open(const char* filename) VL_MT_UNSAFE {
fstWriterSetParallelMode(m_fst, 1); fstWriterSetParallelMode(m_fst, 1);
#endif #endif
m_curScope.clear(); m_curScope.clear();
m_nextCode = 1;
for (vluint32_t ent = 0; ent< m_callbacks.size(); ++ent) { for (vluint32_t ent = 0; ent< m_callbacks.size(); ++ent) {
VerilatedFstCallInfo* cip = m_callbacks[ent]; VerilatedFstCallInfo* cip = m_callbacks[ent];
cip->m_code = 1; cip->m_code = m_nextCode;
// Initialize; callbacks will call decl* which update m_nextCode
(cip->m_initcb)(this, cip->m_userthis, cip->m_code); (cip->m_initcb)(this, cip->m_userthis, cip->m_code);
} }
@ -121,9 +124,15 @@ void VerilatedFst::declDTypeEnum(int dtypenum, const char* name, vluint32_t elem
m_local2fstdtype[dtypenum] = enumNum; m_local2fstdtype[dtypenum] = enumNum;
} }
void VerilatedFst::declSymbol(vluint32_t code, const char* name, void VerilatedFst::declSymbol(vluint32_t code, const char* name, int dtypenum, fstVarDir vardir,
int dtypenum, fstVarDir vardir, fstVarType vartype, fstVarType vartype, bool array, int arraynum, vluint32_t len,
bool array, int arraynum, vluint32_t len) { vluint32_t bits) {
// Make sure deduplicate tracking increments for future declarations
int codesNeeded = 1 + int(bits / 32);
//Not supported: if (tri) codesNeeded *= 2; // Space in change array for __en signals
m_nextCode = std::max(m_nextCode, code + codesNeeded);
std::pair<Code2SymbolType::iterator, bool> p std::pair<Code2SymbolType::iterator, bool> p
= m_code2symbol.insert(std::make_pair(code, static_cast<fstHandle>(NULL))); = m_code2symbol.insert(std::make_pair(code, static_cast<fstHandle>(NULL)));
std::istringstream nameiss(name); std::istringstream nameiss(name);

View File

@ -50,6 +50,7 @@ private:
void* m_fst; void* m_fst;
VerilatedAssertOneThread m_assertOne; ///< Assert only called from single thread VerilatedAssertOneThread m_assertOne; ///< Assert only called from single thread
bool m_fullDump; bool m_fullDump;
vluint32_t m_nextCode; ///< Next code number to assign
char m_scopeEscape; char m_scopeEscape;
std::string m_module; std::string m_module;
CallbackVec m_callbacks; ///< Routines to perform dumping CallbackVec m_callbacks; ///< Routines to perform dumping
@ -60,7 +61,7 @@ private:
VL_UNCOPYABLE(VerilatedFst); VL_UNCOPYABLE(VerilatedFst);
void declSymbol(vluint32_t code, const char* name, void declSymbol(vluint32_t code, const char* name,
int dtypenum, fstVarDir vardir, fstVarType vartype, int dtypenum, fstVarDir vardir, fstVarType vartype,
bool array, int arraynum, vluint32_t len); bool array, int arraynum, vluint32_t len, vluint32_t bits);
// helpers // helpers
std::vector<char> m_valueStrBuffer; std::vector<char> m_valueStrBuffer;
public: public:
@ -105,32 +106,35 @@ public:
void declBit(vluint32_t code, const char* name, void declBit(vluint32_t code, const char* name,
int dtypenum, fstVarDir vardir, fstVarType vartype, int dtypenum, fstVarDir vardir, fstVarType vartype,
bool array, int arraynum) { bool array, int arraynum) {
declSymbol(code, name, dtypenum, vardir, vartype, array, arraynum, 1); declSymbol(code, name, dtypenum, vardir, vartype, array, arraynum, 1, 1);
} }
void declBus(vluint32_t code, const char* name, void declBus(vluint32_t code, const char* name,
int dtypenum, fstVarDir vardir, fstVarType vartype, int dtypenum, fstVarDir vardir, fstVarType vartype,
bool array, int arraynum, int msb, int lsb) { bool array, int arraynum, int msb, int lsb) {
declSymbol(code, name, dtypenum, vardir, vartype, array, arraynum, msb - lsb + 1); declSymbol(code, name, dtypenum, vardir, vartype, array, arraynum, msb - lsb + 1,
msb - lsb + 1);
} }
void declDouble(vluint32_t code, const char* name, void declDouble(vluint32_t code, const char* name,
int dtypenum, fstVarDir vardir, fstVarType vartype, int dtypenum, fstVarDir vardir, fstVarType vartype,
bool array, int arraynum) { bool array, int arraynum) {
declSymbol(code, name, dtypenum, vardir, vartype, array, arraynum, 2); declSymbol(code, name, dtypenum, vardir, vartype, array, arraynum, 2, 64);
} }
void declFloat(vluint32_t code, const char* name, void declFloat(vluint32_t code, const char* name,
int dtypenum, fstVarDir vardir, fstVarType vartype, int dtypenum, fstVarDir vardir, fstVarType vartype,
bool array, int arraynum) { bool array, int arraynum) {
declSymbol(code, name, dtypenum, vardir, vartype, array, arraynum, 1); declSymbol(code, name, dtypenum, vardir, vartype, array, arraynum, 1, 32);
} }
void declQuad(vluint32_t code, const char* name, void declQuad(vluint32_t code, const char* name,
int dtypenum, fstVarDir vardir, fstVarType vartype, int dtypenum, fstVarDir vardir, fstVarType vartype,
bool array, int arraynum, int msb, int lsb) { bool array, int arraynum, int msb, int lsb) {
declSymbol(code, name, dtypenum, vardir, vartype, array, arraynum, msb - lsb + 1); declSymbol(code, name, dtypenum, vardir, vartype, array, arraynum, msb - lsb + 1,
msb - lsb + 1);
} }
void declArray(vluint32_t code, const char* name, void declArray(vluint32_t code, const char* name,
int dtypenum, fstVarDir vardir, fstVarType vartype, int dtypenum, fstVarDir vardir, fstVarType vartype,
bool array, int arraynum, int msb, int lsb) { bool array, int arraynum, int msb, int lsb) {
declSymbol(code, name, dtypenum, vardir, vartype, array, arraynum, msb - lsb + 1); declSymbol(code, name, dtypenum, vardir, vartype, array, arraynum, msb - lsb + 1,
msb - lsb + 1);
} }
/// Inside dumping routines, dump one signal if it has changed /// Inside dumping routines, dump one signal if it has changed

View File

@ -239,6 +239,7 @@ void VerilatedVcd::makeNameMap() {
for (vluint32_t ent = 0; ent < m_callbacks.size(); ent++) { for (vluint32_t ent = 0; ent < m_callbacks.size(); ent++) {
VerilatedVcdCallInfo* cip = m_callbacks[ent]; VerilatedVcdCallInfo* cip = m_callbacks[ent];
cip->m_code = m_nextCode; cip->m_code = m_nextCode;
// Initialize; callbacks will call decl* which update m_nextCode
(cip->m_initcb)(this, cip->m_userthis, cip->m_code); (cip->m_initcb)(this, cip->m_userthis, cip->m_code);
} }
@ -535,12 +536,12 @@ void VerilatedVcd::declare(vluint32_t code, const char* name, const char* wirep,
if (!code) { VL_FATAL_MT(__FILE__, __LINE__, "", if (!code) { VL_FATAL_MT(__FILE__, __LINE__, "",
"Internal: internal trace problem, code 0 is illegal"); } "Internal: internal trace problem, code 0 is illegal"); }
int bits = ((msb>lsb)?(msb-lsb):(lsb-msb))+1; int bits = ((msb > lsb) ? (msb - lsb) : (lsb - msb)) + 1;
int codesNeeded = 1+int(bits/32); int codesNeeded = 1 + int(bits / 32);
if (tri) codesNeeded *= 2; // Space in change array for __en signals if (tri) codesNeeded *= 2; // Space in change array for __en signals
// Make sure array is large enough // Make sure array is large enough
m_nextCode = std::max(m_nextCode, code+codesNeeded); m_nextCode = std::max(m_nextCode, code + codesNeeded);
if (m_sigs.capacity() <= m_nextCode) { if (m_sigs.capacity() <= m_nextCode) {
m_sigs.reserve(m_nextCode*2); // Power-of-2 allocation speeds things up m_sigs.reserve(m_nextCode*2); // Power-of-2 allocation speeds things up
} }

View File

@ -36,10 +36,6 @@ int main(int argc, char** argv, char** env) {
srand48(5); srand48(5);
ap = new VM_PREFIX("topa"); ap = new VM_PREFIX("topa");
bp = new Vt_trace_two_b("topb"); bp = new Vt_trace_two_b("topb");
ap->eval_step();
bp->eval_step();
ap->eval_end_step();
bp->eval_end_step();
#ifdef TEST_HDR_TRACE #ifdef TEST_HDR_TRACE
Verilated::traceEverOn(true); Verilated::traceEverOn(true);
@ -54,8 +50,16 @@ int main(int argc, char** argv, char** env) {
bp->trace(tfp, 99); bp->trace(tfp, 99);
tfp->open(VL_STRINGIFY(TEST_OBJ_DIR) "/simx.vcd"); tfp->open(VL_STRINGIFY(TEST_OBJ_DIR) "/simx.vcd");
# endif # endif
#endif
#ifdef TEST_HDR_TRACE
ap->eval_step();
bp->eval_step();
ap->eval_end_step();
bp->eval_end_step();
if (tfp) tfp->dump(main_time); if (tfp) tfp->dump(main_time);
#endif #endif
{ {
ap->clk = false; ap->clk = false;
ap->clk = false; ap->clk = false;
@ -78,6 +82,7 @@ int main(int argc, char** argv, char** env) {
} }
ap->final(); ap->final();
bp->final(); bp->final();
#ifdef TEST_HDR_TRACE #ifdef TEST_HDR_TRACE
if (tfp) tfp->close(); if (tfp) tfp->close();
#endif #endif

View File

@ -1,5 +1,5 @@
$version Generated by VerilatedVcd $end $version Generated by VerilatedVcd $end
$date Sun Mar 1 20:48:56 2020 $date Sat Mar 7 18:39:02 2020
$end $end
$timescale 1ns $end $timescale 1ns $end
@ -17,86 +17,89 @@ $timescale 1ns $end
$enddefinitions $end $enddefinitions $end
#0 #10
b00000000000000000000000000000001 # b00000000000000000000000000000001 #
b00000000000000000000000000000000 + b00000000000000000000000000000000 +
03 13
b00000000000000000000000000000001 ; b00000000000000000000000000000001 ;
#0
#10
#10 #10
#15
#15
03
#20
#20
b00000000000000000000000000000010 # b00000000000000000000000000000010 #
b00000000000000000000000000000011 + b00000000000000000000000000000011 +
13 13
#15 #25
#15 #25
03 03
#20 #30
#20 #30
b00000000000000000000000000000011 # b00000000000000000000000000000011 #
b00000000000000000000000000000100 + b00000000000000000000000000000100 +
13 13
#25 #35
#25 #35
03 03
#30 #40
#30 #40
b00000000000000000000000000000100 # b00000000000000000000000000000100 #
b00000000000000000000000000000101 + b00000000000000000000000000000101 +
13 13
#35 #45
#35 #45
03 03
#40 #50
#40 #50
b00000000000000000000000000000101 # b00000000000000000000000000000101 #
b00000000000000000000000000000110 + b00000000000000000000000000000110 +
13 13
#45 #55
#45 #55
03 03
#50 #60
#50 #60
b00000000000000000000000000000110 # b00000000000000000000000000000110 #
b00000000000000000000000000000111 + b00000000000000000000000000000111 +
13 13
#55 #65
#55 #65
03 03
#60 #70
#60 #70
b00000000000000000000000000000111 # b00000000000000000000000000000111 #
b00000000000000000000000000001000 + b00000000000000000000000000001000 +
13 13
#65 #75
#65 #75
03 03
#70 #80
#70 #80
b00000000000000000000000000001000 # b00000000000000000000000000001000 #
b00000000000000000000000000001001 + b00000000000000000000000000001001 +
13 13
#75 #85
#75 #85
03 03
#80 #90
#80 #90
b00000000000000000000000000001001 # b00000000000000000000000000001001 #
b00000000000000000000000000001010 + b00000000000000000000000000001010 +
13 13
#85 #95
#85 #95
03 03
#90 #100
#90 #100
b00000000000000000000000000001010 # b00000000000000000000000000001010 #
b00000000000000000000000000001011 + b00000000000000000000000000001011 +
13 13
#95 #105
#95 #105
03 03
#100 #110
#100 #110
b00000000000000000000000000001011 # b00000000000000000000000000001011 #
b00000000000000000000000000001100 + b00000000000000000000000000001100 +
13 13

View File

@ -1,5 +1,5 @@
$date $date
Sun Mar 1 21:31:56 2020 Sat Mar 7 18:39:05 2020
$end $end
$version $version
@ -21,63 +21,69 @@ $upscope $end
$upscope $end $upscope $end
$enddefinitions $end $enddefinitions $end
$dumpvars $dumpvars
#0 1!
0! b00000000000000000000000000000001 "
b00000000000000000000000000000000 #
b00000000000000000000000000000001 $
#10 #10
1! 1!
b00000000000000000000000000000011 #
b00000000000000000000000000000010 "
#15 #15
0! 0!
#20 #20
1! 1!
b00000000000000000000000000000011 " b00000000000000000000000000000011 #
b00000000000000000000000000000100 # b00000000000000000000000000000010 "
#25 #25
0! 0!
#30 #30
1! 1!
b00000000000000000000000000000101 # b00000000000000000000000000000011 "
b00000000000000000000000000000100 " b00000000000000000000000000000100 #
#35 #35
0! 0!
#40 #40
1! 1!
b00000000000000000000000000000101 " b00000000000000000000000000000101 #
b00000000000000000000000000000110 # b00000000000000000000000000000100 "
#45 #45
0! 0!
#50 #50
1! 1!
b00000000000000000000000000000111 # b00000000000000000000000000000101 "
b00000000000000000000000000000110 " b00000000000000000000000000000110 #
#55 #55
0! 0!
#60 #60
1! 1!
b00000000000000000000000000000111 " b00000000000000000000000000000111 #
b00000000000000000000000000001000 # b00000000000000000000000000000110 "
#65 #65
0! 0!
#70 #70
1! 1!
b00000000000000000000000000001001 # b00000000000000000000000000000111 "
b00000000000000000000000000001000 " b00000000000000000000000000001000 #
#75 #75
0! 0!
#80 #80
1! 1!
b00000000000000000000000000001001 " b00000000000000000000000000001001 #
b00000000000000000000000000001010 # b00000000000000000000000000001000 "
#85 #85
0! 0!
#90 #90
1! 1!
b00000000000000000000000000001011 # b00000000000000000000000000001001 "
b00000000000000000000000000001010 " b00000000000000000000000000001010 #
#95 #95
0! 0!
#100 #100
1! 1!
b00000000000000000000000000001011 #
b00000000000000000000000000001010 "
#105
0!
#110
1!
b00000000000000000000000000001011 " b00000000000000000000000000001011 "
b00000000000000000000000000001100 # b00000000000000000000000000001100 #

View File

@ -1,5 +1,5 @@
$version Generated by VerilatedVcd $end $version Generated by VerilatedVcd $end
$date Sun Mar 1 21:32:13 2020 $date Sat Mar 7 18:38:11 2020
$end $end
$timescale 1ns $end $timescale 1ns $end
@ -17,86 +17,89 @@ $timescale 1ns $end
$enddefinitions $end $enddefinitions $end
#0 #10
b00000000000000000000000000000001 # b00000000000000000000000000000001 #
b00000000000000000000000000000000 + b00000000000000000000000000000000 +
03 13
b00000000000000000000000000000001 ; b00000000000000000000000000000001 ;
#0
#10
#10 #10
#15
#15
03
#20
#20
b00000000000000000000000000000010 # b00000000000000000000000000000010 #
b00000000000000000000000000000011 + b00000000000000000000000000000011 +
13 13
#15 #25
#15 #25
03 03
#20 #30
#20 #30
b00000000000000000000000000000011 # b00000000000000000000000000000011 #
b00000000000000000000000000000100 + b00000000000000000000000000000100 +
13 13
#25 #35
#25 #35
03 03
#30 #40
#30 #40
b00000000000000000000000000000100 # b00000000000000000000000000000100 #
b00000000000000000000000000000101 + b00000000000000000000000000000101 +
13 13
#35 #45
#35 #45
03 03
#40 #50
#40 #50
b00000000000000000000000000000101 # b00000000000000000000000000000101 #
b00000000000000000000000000000110 + b00000000000000000000000000000110 +
13 13
#45 #55
#45 #55
03 03
#50 #60
#50 #60
b00000000000000000000000000000110 # b00000000000000000000000000000110 #
b00000000000000000000000000000111 + b00000000000000000000000000000111 +
13 13
#55 #65
#55 #65
03 03
#60 #70
#60 #70
b00000000000000000000000000000111 # b00000000000000000000000000000111 #
b00000000000000000000000000001000 + b00000000000000000000000000001000 +
13 13
#65 #75
#65 #75
03 03
#70 #80
#70 #80
b00000000000000000000000000001000 # b00000000000000000000000000001000 #
b00000000000000000000000000001001 + b00000000000000000000000000001001 +
13 13
#75 #85
#75 #85
03 03
#80 #90
#80 #90
b00000000000000000000000000001001 # b00000000000000000000000000001001 #
b00000000000000000000000000001010 + b00000000000000000000000000001010 +
13 13
#85 #95
#85 #95
03 03
#90 #100
#90 #100
b00000000000000000000000000001010 # b00000000000000000000000000001010 #
b00000000000000000000000000001011 + b00000000000000000000000000001011 +
13 13
#95 #105
#95 #105
03 03
#100 #110
#100 #110
b00000000000000000000000000001011 # b00000000000000000000000000001011 #
b00000000000000000000000000001100 + b00000000000000000000000000001100 +
13 13

View File

@ -1,5 +1,5 @@
$date $date
Sun Mar 1 21:32:04 2020 Sat Mar 7 18:37:58 2020
$end $end
$version $version
@ -21,63 +21,69 @@ $upscope $end
$upscope $end $upscope $end
$enddefinitions $end $enddefinitions $end
$dumpvars $dumpvars
#0 1!
0! b00000000000000000000000000000001 "
b00000000000000000000000000000000 #
b00000000000000000000000000000001 $
#10 #10
1! 1!
b00000000000000000000000000000011 #
b00000000000000000000000000000010 "
#15 #15
0! 0!
#20 #20
1! 1!
b00000000000000000000000000000011 " b00000000000000000000000000000011 #
b00000000000000000000000000000100 # b00000000000000000000000000000010 "
#25 #25
0! 0!
#30 #30
1! 1!
b00000000000000000000000000000101 # b00000000000000000000000000000011 "
b00000000000000000000000000000100 " b00000000000000000000000000000100 #
#35 #35
0! 0!
#40 #40
1! 1!
b00000000000000000000000000000101 " b00000000000000000000000000000101 #
b00000000000000000000000000000110 # b00000000000000000000000000000100 "
#45 #45
0! 0!
#50 #50
1! 1!
b00000000000000000000000000000111 # b00000000000000000000000000000101 "
b00000000000000000000000000000110 " b00000000000000000000000000000110 #
#55 #55
0! 0!
#60 #60
1! 1!
b00000000000000000000000000000111 " b00000000000000000000000000000111 #
b00000000000000000000000000001000 # b00000000000000000000000000000110 "
#65 #65
0! 0!
#70 #70
1! 1!
b00000000000000000000000000001001 # b00000000000000000000000000000111 "
b00000000000000000000000000001000 " b00000000000000000000000000001000 #
#75 #75
0! 0!
#80 #80
1! 1!
b00000000000000000000000000001001 " b00000000000000000000000000001001 #
b00000000000000000000000000001010 # b00000000000000000000000000001000 "
#85 #85
0! 0!
#90 #90
1! 1!
b00000000000000000000000000001011 # b00000000000000000000000000001001 "
b00000000000000000000000000001010 " b00000000000000000000000000001010 #
#95 #95
0! 0!
#100 #100
1! 1!
b00000000000000000000000000001011 #
b00000000000000000000000000001010 "
#105
0!
#110
1!
b00000000000000000000000000001011 " b00000000000000000000000000001011 "
b00000000000000000000000000001100 # b00000000000000000000000000001100 #