Making progress?

This commit is contained in:
Todd Strader 2020-01-17 18:18:42 -05:00
parent e4d75ed384
commit d8b75fa352
10 changed files with 74 additions and 55 deletions

View File

@ -39,6 +39,8 @@ int VerilatedReplay::init(std::string scope) {
++it) {
VL_PRINTF("%s = %d\n", it->second.fullName.c_str(), it->first);
fstReaderSetFacProcessMask(m_fstp, it->first);
m_signals[it->first] = FstSignal(it->second.hier.u.var.length,
reinterpret_cast<VM_PREFIX*>(m_modp)->??);
}
createMod();
@ -142,6 +144,7 @@ void VerilatedReplay::fstCb(uint64_t time, fstHandle facidx,
m_simTime = m_time;
}
// TODO -- remove
VL_PRINTF("%lu %u %s\n", time, facidx, valuep);
}
@ -165,6 +168,7 @@ void VerilatedReplay::fstCallback(void* userDatap, uint64_t time, fstHandle faci
}
void VerilatedReplay::createMod() {
// TODO -- maybe get rid of the need for VM_PREFIX by generating these things
m_modp = new VM_PREFIX;
// TODO -- make VerilatedModule destructor virtual so we can delete from the base class?
#if VM_TRACE

View File

@ -31,9 +31,16 @@
#include "verilated_replay_common.h"
#include "gtkwave/fstapi.h"
#include <string>
#include <map>
class VerilatedReplay: private VerilatedReplayCommon {
private:
struct FstSignal {
size_t bits;
vluint8_t* signal;
};
typedef std::map<fstHandle, FstSignal> SignalMap;
void createMod();
void eval();
void trace();
@ -50,6 +57,7 @@ private:
VerilatedModule* m_modp;
VerilatedFstC* m_tfp;
uint64_t m_time;
SignalMap m_signals;
public:
VerilatedReplay(const std::string& fstName, double& simTime):
m_fstName(fstName), m_simTime(simTime)

View File

@ -24,6 +24,7 @@
#include "verilated_replay_common.h"
#include <iostream>
using namespace std;
@ -39,23 +40,24 @@ using namespace std;
void VerilatedReplayCommon::openFst(const string& fstName) {
m_fstp = fstReaderOpen(fstName.c_str());
if (!m_fstp) {
// TODO -- Verilator runtime way of tossing a fatal error?, see elsewhere
VL_PRINTF("Could not open FST: %s\n", fstName.c_str());
// TODO -- a better way to fatal in either Verilator or in the runtime?
cout<<"Could not open FST: "<<fstName<<endl;
exit(-1);
}
}
void VerilatedReplayCommon::search(string targetScope) {
void VerilatedReplayCommon::searchFst(const string& targetScope) {
const char* scope = "";
string searchScope(targetScope);
while (fstHier* hierp = fstReaderIterateHier(m_fstp)) {
if (hierp->htyp == FST_HT_SCOPE) {
scope = fstReaderPushScope(m_fstp, hierp->u.scope.name, NULL);
if (targetScope.empty()) targetScope = string(scope);
if (searchScope.empty()) searchScope = string(scope);
} else if (hierp->htyp == FST_HT_UPSCOPE) {
scope = fstReaderPopScope(m_fstp);
} else if (hierp->htyp == FST_HT_VAR) {
if (string(scope) == targetScope) {
if (string(scope) == searchScope) {
string varName = string(scope) + "." + string(hierp->u.var.name);
switch (hierp->u.var.direction) {
case FST_VD_INPUT:

View File

@ -26,7 +26,6 @@
#ifndef _VERILATED_REPLAY_COMMON_H_
#define _VERILATED_REPLAY_COMMON_H_ 1 ///< Header Guard
#include "verilated.h"
#include "gtkwave/fstapi.h"
#include <string>
#include <map>
@ -51,7 +50,7 @@ public:
VerilatedReplayCommon() {}
~VerilatedReplayCommon() {}
void openFst(const std::string& fstName);
void search(std::string targetScope);
void searchFst(const std::string& targetScope);
};
#endif // Guard

View File

@ -260,6 +260,7 @@ VLCOV_OBJS = \
VLREPLAY_OBJS = \
V3Error.o \
VlrOptions.o \
verilated_replay_common.o \
VlrGenerator.o \
VlrMain.o \
@ -300,6 +301,9 @@ V3Number_test: V3Number_test.o
$(OBJCACHE) ${CXX} ${CXXFLAGS} ${CPPFLAGSWALL} -c $<
%.o: %.c
$(OBJCACHE) ${CC} ${CFLAGS} ${CPPFLAGSWALL} -c $<
# TODO -- this seems terrible
verilated_replay_common.o: ../include/verilated_replay_common.cpp
$(OBJCACHE) ${CXX} ${CXXFLAGS} ${CPPFLAGSWALL} -c $<
V3ParseLex.o: V3ParseLex.cpp V3Lexer.yy.cpp V3ParseBison.c
$(OBJCACHE) ${CXX} ${CXXFLAGS} ${CPPFLAGSPARSER} -c $<

View File

@ -2,47 +2,36 @@
#include "V3Error.h"
#include "gtkwave/fstapi.h"
// 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"
// TODO -- use verilator_replay_common.h instead
void VlrGenerator::getFstIO() {
void* fst = fstReaderOpen(opts().fst());
const char* scope = "";
string targetScope;
if (m_opts.scope()) targetScope = string(m_opts.scope());
while (struct fstHier* hier = fstReaderIterateHier(fst)) {
if (hier->htyp == FST_HT_SCOPE) {
scope = fstReaderPushScope(fst, hier->u.scope.name, NULL);
if (targetScope.empty()) targetScope = string(scope);
UINFO(3, "SCOPE "<<scope<<endl);
} else if (hier->htyp == FST_HT_UPSCOPE) {
scope = fstReaderPopScope(fst);
UINFO(3, "UPSCOPE "<<scope<<endl);
} else if (hier->htyp == FST_HT_VAR) {
if (string(scope) == targetScope) {
string varName = string(scope) + "." + string(hier->u.var.name);
switch (hier->u.var.direction) {
case FST_VD_INPUT:
UINFO(3, "VAR input "<<hier->u.var.name<<endl);
m_inputs.push_back(varName);
break;
case FST_VD_OUTPUT:
UINFO(3, "VAR output "<<hier->u.var.name<<endl);
m_outputs.push_back(varName);
break;
default: break;
}
}
}
}
void VlrGenerator::searchFst() {
openFst(string(m_opts.fst()));
VerilatedReplayCommon::searchFst(string(m_opts.scope()));
}
void VlrGenerator::emitVltCode() {
// TODO -- use V3OutCFile
cout << "#include \"verilated_replay.h\"" << endl;
cout << endl;
cout << "void VerilatedReplay() {" << endl;
for (VarMap::iterator it = m_inputs.begin(); it != m_inputs.end(); ++it) {
string sigName(it->second.fullName);
// TODO -- add a trailing dot for the user if they don't
if (m_opts.replayTop()) {
string replayTop(m_opts.replayTop());
size_t pos = sigName.find(replayTop);
if (pos != 0) {
cout << sigName << " did not start with " << replayTop << endl;
exit(-1);
}
sigName = sigName.substr(replayTop.length());
}
// TODO -- need to be able to specify a new top level
cout << " addInput(\"" << it->second.fullName <<
"\", reinterpret_cast<VM_PREFIX*>(m_modp)->" << sigName <<
", " << it->second.hier.u.var.length << ");" << endl;
}
cout << "}" << endl;
}

View File

@ -22,9 +22,10 @@
#define _VLRGENERATOR_H_ 1
#include "VlrOptions.h"
#include "verilated_replay_common.h"
#include <list>
class VlrGenerator {
class VlrGenerator: public VerilatedReplayCommon {
public:
// CONSTRUCTORS
VlrGenerator() {}
@ -32,14 +33,12 @@ public:
// METHODS
VlrOptions& opts() { return m_opts; }
void getFstIO();
void searchFst();
void emitVltCode();
private:
typedef std::list<std::string> StrList;
VlrOptions m_opts;
StrList m_inputs;
StrList m_outputs;
};
#endif // guard

View File

@ -21,6 +21,14 @@
#include "VlrGenerator.h"
#include "V3Error.h"
// 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"
int main(int argc, char** argv) {
VlrGenerator gen;
@ -29,7 +37,7 @@ int main(int argc, char** argv) {
// Read signals from FST or signals file
if (gen.opts().fst()) {
gen.getFstIO();
gen.searchFst();
}
// TODO -- manually specified lists
// TODO -- check for none of the above

View File

@ -48,6 +48,10 @@ void VlrOptions::parseOptsList(int argc, char** argv) {
++i;
m_fst = argv[i];
}
else if (!strcmp(sw, "-replay-top") && (i+1)<argc ) {
++i;
m_replayTop= argv[i];
}
else if (!strcmp(sw, "-scope") && (i+1)<argc ) {
++i;
m_scope = argv[i];

View File

@ -27,7 +27,7 @@ class VlrOptions {
public:
// CONSTRUCTORS
VlrOptions():
m_fst(NULL), m_scope(NULL), m_vlt(false)
m_fst(NULL), m_replayTop(NULL), m_scope(NULL), m_vlt(false)
{}
~VlrOptions() {}
@ -35,6 +35,7 @@ public:
void parseOptsList(int argc, char** argv);
const char* fst() { return m_fst; }
const char* replayTop() { return m_replayTop; }
const char* scope() { return m_scope; }
bool vlt() { return m_vlt; }
private:
@ -42,8 +43,9 @@ private:
std::string version();
bool onoff(const char* sw, const char* arg, bool& flag);
const char* m_fst;
const char* m_scope;
char* m_fst;
char* m_replayTop;
char* m_scope;
bool m_vlt;
};