Skip to content

Commit

Permalink
A few VCD trace changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mortbopet committed Nov 4, 2023
1 parent 8cb60ad commit cbc7cf6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
16 changes: 9 additions & 7 deletions interface/vsrtl_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -712,14 +712,15 @@ class SimDesign : public SimComponent {
long long getCycleCount() const { return m_cycleCount; }

/**
* @brief vcdDump
* @param enabled; enables dumping of all ports to a vcd file. For each port
* in the circuit, we connect an additional slot which will queue a notice to
* this top-level Design that the variable change is to be written to the VCD
* file.
* @brief vcdTrace
* @param enabled; enables dumping of all ports to a vcd file. For each
* port in the circuit, we connect an additional slot which will queue a
* notice to this top-level Design that the variable change is to be
* written to the VCD file.
*/
void vcdDump(bool enabled) {
void vcdTrace(bool enabled, const std::string &filename = "") {
m_dumpVcdFiles = enabled;
m_vcdFileName = filename.empty() ? getName() + ".vcd" : filename;
std::map<SimComponent *, std::vector<SimComponent *>> componentGraph;
getComponentGraph(componentGraph);
for (const auto &compIt : componentGraph) {
Expand All @@ -745,7 +746,7 @@ class SimDesign : public SimComponent {
* wherein they reside.
*/
void resetVcdFile() {
m_vcdFile = std::make_unique<VCDFile>(getName() + ".vcd");
m_vcdFile = std::make_unique<VCDFile>(m_vcdFileName);
{
auto def1 = m_vcdFile->writeHeader();
auto def2 = m_vcdFile->scopeDef("TOP");
Expand Down Expand Up @@ -819,6 +820,7 @@ class SimDesign : public SimComponent {
std::set<const SimPort *> m_vcdVarChangeQueue;
std::string m_vcdClkId;
bool m_dumpVcdFiles = false;
std::string m_vcdFileName;

#ifndef NDEBUG
long long m_cycleCountPre = 0;
Expand Down
12 changes: 7 additions & 5 deletions interface/vsrtl_vcdfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,18 @@ std::string binStr(T val, unsigned width) {
return s;
}

VCDFile::VCDFile(const std::string &filename) {
m_file.open(filename, std::ios_base::trunc);
VCDFile::VCDFile(const std::string &filename) { m_filename = filename; }

void VCDFile::ensureOpen() {
if (m_file.is_open())
return;
m_file.open(m_filename, std::ios_base::trunc);
}

VCDFile::~VCDFile() { m_file.close(); }

void VCDFile::writeLine(const std::string &line) {
if (!m_file.is_open()) {
throw std::runtime_error("Tried to write to file, but file was not open");
}
ensureOpen();
const std::string indent = std::string(m_scopeLevel * 4, ' ');
m_file << indent << line + "\n";
};
Expand Down
3 changes: 3 additions & 0 deletions interface/vsrtl_vcdfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ class VCDFile {
}

private:
// Ensures that the file is opened and ready for writing.
void ensureOpen();
std::string genId();
void writeLine(const std::string &line);
std::ofstream m_file;
std::map<std::string, unsigned> m_varWidths;
std::map<std::string, uint64_t> m_dumpVars;

std::string m_filename;
unsigned m_varCntr = 0;
unsigned m_scopeLevel = 0;
};
Expand Down

0 comments on commit cbc7cf6

Please sign in to comment.