From e4d75ed3841208f50cf67de648b029b3993e3044 Mon Sep 17 00:00:00 2001 From: Todd Strader Date: Wed, 15 Jan 2020 18:12:07 -0500 Subject: [PATCH] No replay yet, but produces an FST --- include/verilated_replay.cpp | 22 ++++++++++++++++------ include/verilated_replay.h | 2 ++ include/verilated_replay_common.cpp | 17 ++++++++++------- include/verilated_replay_common.h | 13 +++++++------ 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/include/verilated_replay.cpp b/include/verilated_replay.cpp index 5b402d0b4..721f356ad 100644 --- a/include/verilated_replay.cpp +++ b/include/verilated_replay.cpp @@ -35,11 +35,10 @@ int VerilatedReplay::init(std::string scope) { // TODO -- use FST timescale m_simTime = m_time; - for (VarList::iterator it = m_inputs.begin(); it != m_inputs.end(); + for (VarMap::iterator it = m_inputs.begin(); it != m_inputs.end(); ++it) { - VL_PRINTF("%s = %d\n", it->fullName.c_str(), - it->hier.u.var.handle); - fstReaderSetFacProcessMask(m_fstp, it->hier.u.var.handle); + VL_PRINTF("%s = %d\n", it->second.fullName.c_str(), it->first); + fstReaderSetFacProcessMask(m_fstp, it->first); } createMod(); @@ -49,6 +48,9 @@ int VerilatedReplay::init(std::string scope) { VerilatedReplay::~VerilatedReplay() { fstReaderClose(m_fstp); +#if VM_TRACE + if (m_tfp) m_tfp->close(); +#endif delete(m_modp); } @@ -165,6 +167,13 @@ void VerilatedReplay::fstCallback(void* userDatap, uint64_t time, fstHandle faci void VerilatedReplay::createMod() { m_modp = new VM_PREFIX; // TODO -- make VerilatedModule destructor virtual so we can delete from the base class? +#if VM_TRACE + Verilated::traceEverOn(true); + m_tfp = new VerilatedFstC; + reinterpret_cast(m_modp)->trace(m_tfp, 99); + // TODO -- command line parameter + m_tfp->open("replay.fst"); +#endif // VM_TRACE } void VerilatedReplay::eval() { @@ -173,8 +182,9 @@ void VerilatedReplay::eval() { } void VerilatedReplay::trace() { - // TODO -- need VerilatedFstC, etc. - //reinterpret_cast(m_modp)->trace(); +#if VM_TRACE + if (m_tfp) m_tfp->dump(m_simTime); +#endif // VM_TRACE } void VerilatedReplay::final() { diff --git a/include/verilated_replay.h b/include/verilated_replay.h index efdb4fb5e..cfc667359 100644 --- a/include/verilated_replay.h +++ b/include/verilated_replay.h @@ -27,6 +27,7 @@ #define _VERILATED_REPLAY_H_ 1 ///< Header Guard #include "verilated.h" +#include "verilated_fst_c.h" #include "verilated_replay_common.h" #include "gtkwave/fstapi.h" #include @@ -47,6 +48,7 @@ private: std::string m_fstName; double& m_simTime; VerilatedModule* m_modp; + VerilatedFstC* m_tfp; uint64_t m_time; public: VerilatedReplay(const std::string& fstName, double& simTime): diff --git a/include/verilated_replay_common.cpp b/include/verilated_replay_common.cpp index c730fecfa..9fbdd0b66 100644 --- a/include/verilated_replay_common.cpp +++ b/include/verilated_replay_common.cpp @@ -29,11 +29,12 @@ using namespace std; // TODO -- can we not do this? // Include the GTKWave implementation directly -#define FST_CONFIG_INCLUDE "fst_config.h" -#include "gtkwave/fastlz.c" -#include "gtkwave/fstapi.c" -// TODO -- use the system's LZ4 library, not this copy -#include "gtkwave/lz4.c" +// Ugh, building with verilated_fst_c.cpp, brings this in, let's really not do this +//#define FST_CONFIG_INCLUDE "fst_config.h" +//#include "gtkwave/fastlz.c" +//#include "gtkwave/fstapi.c" +//// TODO -- use the system's LZ4 library, not this copy +//#include "gtkwave/lz4.c" void VerilatedReplayCommon::openFst(const string& fstName) { m_fstp = fstReaderOpen(fstName.c_str()); @@ -58,10 +59,12 @@ void VerilatedReplayCommon::search(string targetScope) { string varName = string(scope) + "." + string(hierp->u.var.name); switch (hierp->u.var.direction) { case FST_VD_INPUT: - m_inputs.push_back(fstVar(hierp, varName)); + m_inputs[hierp->u.var.handle] = + fstVar(hierp, varName); break; case FST_VD_OUTPUT: - m_outputs.push_back(fstVar(hierp, varName)); + m_outputs[hierp->u.var.handle] = + fstVar(hierp, varName); break; default: break; } diff --git a/include/verilated_replay_common.h b/include/verilated_replay_common.h index 83578b9ac..d36446921 100644 --- a/include/verilated_replay_common.h +++ b/include/verilated_replay_common.h @@ -29,28 +29,29 @@ #include "verilated.h" #include "gtkwave/fstapi.h" #include -#include +#include class VerilatedReplayCommon { public: struct fstVar { + // Can't just save the struct fstHier* that fstReadIterateHier() + // gives us because it recycles that pointer struct fstHier hier; std::string fullName; fstVar(struct fstHier* _hierp, std::string _fullName): hier(*_hierp), fullName(_fullName) {} + fstVar() {} }; - typedef std::list VarList; + typedef std::map VarMap; protected: void* m_fstp; - VarList m_inputs; - VarList m_outputs; + VarMap m_inputs; + VarMap m_outputs; public: VerilatedReplayCommon() {} ~VerilatedReplayCommon() {} void openFst(const std::string& fstName); void search(std::string targetScope); - VarList& inputs() { return m_inputs; } - VarList& outputs() { return m_outputs; } }; #endif // Guard