VCD reader support by using external tool
authorMiodrag Milanovic <mmicko@gmail.com>
Mon, 28 Feb 2022 08:09:07 +0000 (09:09 +0100)
committerMiodrag Milanovic <mmicko@gmail.com>
Mon, 28 Feb 2022 08:09:07 +0000 (09:09 +0100)
kernel/fstdata.cc
kernel/fstdata.h
passes/sat/sim.cc

index af816e57eac0294ae116656091aea7d07afcecef..587678ce33ab2fc71c6d2e7255fd12b65ee0c9bf 100644 (file)
 USING_YOSYS_NAMESPACE
 
 
+static std::string file_base_name(std::string const & path)
+{
+       return path.substr(path.find_last_of("/\\") + 1);
+}
+
 FstData::FstData(std::string filename) : ctx(nullptr)
 {
+       #if !defined(YOSYS_DISABLE_SPAWN)
+       std::string filename_trim = file_base_name(filename);
+       if (filename_trim.size() > 4 && filename_trim.compare(filename_trim.size()-4, std::string::npos, ".vcd") == 0) {
+               filename_trim.erase(filename_trim.size()-4);
+               tmp_file = stringf("/tmp/converted_%s.fst", filename_trim.c_str());
+               std::string cmd = stringf("vcd2fst %s %s", filename.c_str(), tmp_file.c_str());
+               log("Exec: %s\n", cmd.c_str());
+               if (run_command(cmd) != 0)
+                       log_cmd_error("Shell command failed!\n");
+               filename = tmp_file;
+       }
+       #endif
        const std::vector<std::string> g_units = { "s", "ms", "us", "ns", "ps", "fs", "as", "zs" };
        ctx = (fstReaderContext *)fstReaderOpen(filename.c_str());
        if (!ctx)
@@ -53,6 +70,8 @@ FstData::~FstData()
 {
        if (ctx)
                fstReaderClose(ctx);
+       if (!tmp_file.empty())
+               remove(tmp_file.c_str());
 }
 
 uint64_t FstData::getStartTime() { return fstReaderGetStartTime(ctx); }
index 707d1b64e90147cb5dea24237e1b6fc78f293d1c..4a355fd775ac2b33444e0a8b8a25808b8051cdc3 100644 (file)
@@ -74,6 +74,7 @@ private:
        CallbackFunction callback;
        std::vector<fstHandle> clk_signals;
        bool all_samples;
+       std::string tmp_file;
 };
 
 YOSYS_NAMESPACE_END
index 1cd0a033803544f07b0cc0722383dca2ba85c44d..bdec54a965a7a951f78e62ea7b32f9cd3a871d2d 100644 (file)
@@ -1160,6 +1160,7 @@ struct SimWorker : SimShared
                        pool<Module*> wbmods;
                        top->writeback(wbmods);
                }
+               delete fst;
        }
 
        void run_cosim_witness(Module *topmod)