From df848c949176753f11925cc237312fbbc1ccbfe9 Mon Sep 17 00:00:00 2001 From: alaindargelas Date: Thu, 22 Aug 2024 20:43:21 -0700 Subject: [PATCH] auto_testbench Tcl command --- src/Simulation/Simulator.cpp | 35 +++++++++++++++++++++++++++++++++++ src/Simulation/Simulator.h | 2 ++ 2 files changed, 37 insertions(+) diff --git a/src/Simulation/Simulator.cpp b/src/Simulation/Simulator.cpp index d38009254..ee0b1e37e 100644 --- a/src/Simulation/Simulator.cpp +++ b/src/Simulation/Simulator.cpp @@ -253,9 +253,44 @@ bool Simulator::RegisterCommands(TclInterpreter* interp) { }; interp->registerCmd("simulation_options", simulation_options, this, 0); + auto auto_testbench = [](void* clientData, Tcl_Interp* interp, int argc, + const char* argv[]) -> int { + Simulator* simulator = (Simulator*)clientData; + int result = simulator->GenerateAutoTestbench(); + if (result != 0) { + return TCL_ERROR; + } + return TCL_OK; + }; + interp->registerCmd("auto_testbench", auto_testbench, this, 0); + return ok; } +int Simulator::GenerateAutoTestbench() { + Message("##################################################"); + Message("Generating automatic RTL vs gate-level testbench "); + Message("##################################################"); + std::filesystem::path python3Path = m_compiler->GetDataPath() / ".." / + "envs" / "python3.8" / "bin" / "python3"; + std::filesystem::path scriptPath = + m_compiler->GetDataPath() / "python3" / "tb_generator.py"; + std::string workingDir = + std::filesystem::current_path() / ProjManager()->projectName(); + std::string command = std::string(python3Path) + " " + + std::string(scriptPath) + " " + + ProjManager()->projectName() + " " + + std::string(std::filesystem::current_path()); + FileUtils::WriteToFile(CommandLogFile("comp"), command); + int status = m_compiler->ExecuteAndMonitorSystemCommand( + command, "auto-testbench.log", false, workingDir); + if (status == 0) + Message("Testbench is generated."); + else + ErrorMessage("Testbench generation failed"); + return status; +} + bool Simulator::Clean(SimulationType action) { Message("Cleaning simulation results for " + ProjManager()->projectName()); auto base = m_compiler->FilePath(Compiler::ToCompilerAction(action)); diff --git a/src/Simulation/Simulator.h b/src/Simulation/Simulator.h index db27174b6..5cc4c94be 100644 --- a/src/Simulation/Simulator.h +++ b/src/Simulation/Simulator.h @@ -115,6 +115,8 @@ class Simulator { void UserSimulationType(SimulationType simulation, SimulatorType simulator); SimulatorType UserSimulationType(SimulationType simulation, bool& ok) const; + int GenerateAutoTestbench(); + protected: virtual bool SimulateRTL(SimulatorType type); virtual bool SimulateGate(SimulatorType type);