Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

path getter, messages api, move tb generation to Tcl #1691

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 56 additions & 2 deletions src/Compiler/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ bool Compiler::RegisterCommands(TclInterpreter* interp, bool batchMode) {
const char* argv[]) -> int {
Compiler* compiler = (Compiler*)clientData;
std::string name = compiler->ProjManager()->projectName();
Tcl_AppendResult(interp, strdup(name.c_str()), nullptr);
Tcl_SetResult(interp, (char*)name.c_str(), TCL_VOLATILE);
return TCL_OK;
};
interp->registerCmd("get_design_name", get_design_name, this, nullptr);
Expand All @@ -427,11 +427,65 @@ bool Compiler::RegisterCommands(TclInterpreter* interp, bool batchMode) {
const char* argv[]) -> int {
Compiler* compiler = (Compiler*)clientData;
std::string name = compiler->ProjManager()->DesignTopModule();
Tcl_AppendResult(interp, strdup(name.c_str()), nullptr);
Tcl_SetResult(interp, (char*)name.c_str(), TCL_VOLATILE);
return TCL_OK;
};
interp->registerCmd("get_top_module", get_top_module, this, nullptr);

auto get_bin_path = [](void* clientData, Tcl_Interp* interp, int argc,
const char* argv[]) -> int {
Compiler* compiler = (Compiler*)clientData;
std::string name = compiler->GetBinPath().string();
Tcl_SetResult(interp, (char*)name.c_str(), TCL_VOLATILE);
return TCL_OK;
};
interp->registerCmd("get_bin_path", get_bin_path, this, nullptr);

auto get_data_path = [](void* clientData, Tcl_Interp* interp, int argc,
const char* argv[]) -> int {
Compiler* compiler = (Compiler*)clientData;
std::string name = compiler->GetDataPath().string();
Tcl_SetResult(interp, (char*)name.c_str(), TCL_VOLATILE);
return TCL_OK;
};
interp->registerCmd("get_data_path", get_data_path, this, nullptr);

auto get_python3_path = [](void* clientData, Tcl_Interp* interp, int argc,
const char* argv[]) -> int {
Compiler* compiler = (Compiler*)clientData;
std::filesystem::path python3Path = compiler->GetDataPath() / ".." /
"envs" / "python3.8" / "bin" /
"python3";
std::string name = python3Path.string();
Tcl_SetResult(interp, (char*)name.c_str(), TCL_VOLATILE);
return TCL_OK;
};
interp->registerCmd("get_python3_path", get_python3_path, this, nullptr);

auto message = [](void* clientData, Tcl_Interp* interp, int argc,
const char* argv[]) -> int {
Compiler* compiler = (Compiler*)clientData;
std::string text;
for (int i = 1; i < argc; i++) {
text += std::string(argv[i]) + " ";
}
compiler->Message(text);
return TCL_OK;
};
interp->registerCmd("message", message, this, nullptr);

auto error_message = [](void* clientData, Tcl_Interp* interp, int argc,
const char* argv[]) -> int {
Compiler* compiler = (Compiler*)clientData;
std::string text;
for (int i = 1; i < argc; i++) {
text += std::string(argv[i]) + " ";
}
compiler->ErrorMessage(text);
return TCL_ERROR;
};
interp->registerCmd("error_message", error_message, this, nullptr);

auto get_top_simulation_module = [](void* clientData, Tcl_Interp* interp,
int argc, const char* argv[]) -> int {
Compiler* compiler = (Compiler*)clientData;
Expand Down
46 changes: 0 additions & 46 deletions src/Simulation/Simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,55 +253,9 @@ 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;
float clock_period = 5.0;
for (int i = 1; i < argc; i++) {
std::string arg = argv[i];
if (arg == "-clock_period") {
i++;
arg = argv[i];
clock_period = std::atof(arg.c_str());
}
}
int result = simulator->GenerateAutoTestbench(clock_period);
if (result != 0) {
return TCL_ERROR;
}
return TCL_OK;
};
interp->registerCmd("auto_testbench", auto_testbench, this, 0);

return ok;
}

int Simulator::GenerateAutoTestbench(float clock_period) {
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";
const auto& path = std::filesystem::current_path();
std::string workingDir =
std::filesystem::path(path / ProjManager()->projectName()).string();
std::string command = std::string(python3Path.string()) + " " +
std::string(scriptPath.string()) + " " +
ProjManager()->projectName() + " " +
std::string(path.string()) + " " + std::to_string(100) +
" " + std::to_string(clock_period);
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));
Expand Down
2 changes: 0 additions & 2 deletions src/Simulation/Simulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ class Simulator {
void UserSimulationType(SimulationType simulation, SimulatorType simulator);
SimulatorType UserSimulationType(SimulationType simulation, bool& ok) const;

int GenerateAutoTestbench(float clock_period);

bool IsTimedSimulation() { return m_timed_simulation; }
void SetTimedSimulation(bool timed) { m_timed_simulation = timed; }

Expand Down
Loading