No replay yet, but produces an FST

This commit is contained in:
Todd Strader 2020-01-15 18:12:07 -05:00
parent fdef131113
commit e4d75ed384
4 changed files with 35 additions and 19 deletions

View File

@ -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<VM_PREFIX*>(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<VM_PREFIX*>(m_modp)->trace();
#if VM_TRACE
if (m_tfp) m_tfp->dump(m_simTime);
#endif // VM_TRACE
}
void VerilatedReplay::final() {

View File

@ -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 <string>
@ -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):

View File

@ -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;
}

View File

@ -29,28 +29,29 @@
#include "verilated.h"
#include "gtkwave/fstapi.h"
#include <string>
#include <list>
#include <map>
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<const fstVar> VarList;
typedef std::map<fstHandle, fstVar> 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