Skip to content

Commit

Permalink
Always provide run_command and raise an error if YOSYS_DISABLE_SPAWN
Browse files Browse the repository at this point in the history
  • Loading branch information
Coloquinte committed Mar 28, 2024
1 parent 0fe82c5 commit a477dff
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 32 deletions.
2 changes: 0 additions & 2 deletions kernel/fstdata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ static std::string file_base_name(std::string const & path)

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);
Expand All @@ -40,7 +39,6 @@ FstData::FstData(std::string filename) : ctx(nullptr)
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)
Expand Down
4 changes: 0 additions & 4 deletions kernel/register.cc
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ void Pass::call(RTLIL::Design *design, std::string command)
return;

if (tok[0] == '!') {
#if !defined(YOSYS_DISABLE_SPAWN)
cmd_buf = command.substr(command.find('!') + 1);
while (!cmd_buf.empty() && (cmd_buf.back() == ' ' || cmd_buf.back() == '\t' ||
cmd_buf.back() == '\r' || cmd_buf.back() == '\n'))
Expand All @@ -249,9 +248,6 @@ void Pass::call(RTLIL::Design *design, std::string command)
if (retCode != 0)
log_cmd_error("Shell command returned error code %d.\n", retCode);
return;
#else
log_cmd_error("Shell is not available.\n");
#endif
}

while (!tok.empty()) {
Expand Down
6 changes: 4 additions & 2 deletions kernel/yosys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,9 @@ bool patmatch(const char *pattern, const char *string)
return false;
}

#if !defined(YOSYS_DISABLE_SPAWN)
int run_command(const std::string &command, std::function<void(const std::string&)> process_line)
{
#if !defined(YOSYS_DISABLE_SPAWN)
if (!process_line)
return system(command.c_str());

Expand All @@ -318,8 +318,10 @@ int run_command(const std::string &command, std::function<void(const std::string
#else
return WEXITSTATUS(ret);
#endif
}
#else
log_cmd_error("Command execution is disabled in this build.\n");
#endif
}

std::string get_base_tmpdir()
{
Expand Down
2 changes: 0 additions & 2 deletions kernel/yosys.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,7 @@ int readsome(std::istream &f, char *s, int n);
std::string next_token(std::string &text, const char *sep = " \t\r\n", bool long_strings = false);
std::vector<std::string> split_tokens(const std::string &text, const char *sep = " \t\r\n");
bool patmatch(const char *pattern, const char *string);
#if !defined(YOSYS_DISABLE_SPAWN)
int run_command(const std::string &command, std::function<void(const std::string&)> process_line = std::function<void(const std::string&)>());
#endif
std::string get_base_tmpdir();
std::string make_temp_file(std::string template_str = get_base_tmpdir() + "/yosys_XXXXXX");
std::string make_temp_dir(std::string template_str = get_base_tmpdir() + "/yosys_XXXXXX");
Expand Down
4 changes: 0 additions & 4 deletions libs/ezsat/ezcommand.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ ezSATCommand::~ezSATCommand() {}

bool ezSATCommand::solver(const std::vector<int> &modelExpressions, std::vector<bool> &modelValues, const std::vector<int> &assumptions)
{
#if !defined(YOSYS_DISABLE_SPAWN)
const std::string tempdir_name = Yosys::make_temp_dir(Yosys::get_base_tmpdir() + "/yosys-sat-XXXXXX");
const std::string cnf_filename = Yosys::stringf("%s/problem.cnf", tempdir_name.c_str());
const std::string sat_command = Yosys::stringf("%s %s", command.c_str(), cnf_filename.c_str());
Expand Down Expand Up @@ -82,7 +81,4 @@ bool ezSATCommand::solver(const std::vector<int> &modelExpressions, std::vector<
modelValues[i] = (values.at(idx - 1) == refvalue);
}
return true;
#else
Yosys::log_error("SAT solver command not available in this build!\n");
#endif
}
12 changes: 3 additions & 9 deletions passes/cmds/show.cc
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ struct ShowPass : public Pass {
std::vector<std::pair<std::string, RTLIL::Selection>> color_selections;
std::vector<std::pair<std::string, RTLIL::Selection>> label_selections;

#if defined(_WIN32) || defined(YOSYS_DISABLE_SPAWN)
#if defined(_WIN32)
std::string format = "dot";
std::string prefix = "show";
#else
Expand Down Expand Up @@ -931,15 +931,10 @@ struct ShowPass : public Pass {
std::string cmd = stringf(DOT_CMD, format.c_str(), dot_file.c_str(), out_file.c_str(), out_file.c_str(), out_file.c_str());
#undef DOT_CMD
log("Exec: %s\n", cmd.c_str());
#if !defined(YOSYS_DISABLE_SPAWN)
if (run_command(cmd) != 0)
log_cmd_error("Shell command failed!\n");
#endif
if (run_command(cmd) != 0)
log_cmd_error("Shell command failed!\n");
}

#if defined(YOSYS_DISABLE_SPAWN)
log_assert(viewer_exe.empty() && !format.empty());
#else
if (viewer_exe != "none") {
if (!viewer_exe.empty()) {
#ifdef _WIN32
Expand All @@ -965,7 +960,6 @@ struct ShowPass : public Pass {
log_cmd_error("Shell command failed!\n");
}
}
#endif

if (flag_pause) {
#ifdef YOSYS_ENABLE_READLINE
Expand Down
12 changes: 3 additions & 9 deletions passes/cmds/viz.cc
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ struct VizPass : public Pass {
log_header(design, "Generating Graphviz representation of design.\n");
log_push();

#if defined(_WIN32) || defined(YOSYS_DISABLE_SPAWN)
#if defined(_WIN32)
std::string format = "dot";
std::string prefix = "show";
#else
Expand Down Expand Up @@ -1023,15 +1023,10 @@ struct VizPass : public Pass {
std::string cmd = stringf(DOT_CMD, format.c_str(), dot_file.c_str(), out_file.c_str(), out_file.c_str(), out_file.c_str());
#undef DOT_CMD
log("Exec: %s\n", cmd.c_str());
#if !defined(YOSYS_DISABLE_SPAWN)
if (run_command(cmd) != 0)
log_cmd_error("Shell command failed!\n");
#endif
if (run_command(cmd) != 0)
log_cmd_error("Shell command failed!\n");
}

#if defined(YOSYS_DISABLE_SPAWN)
log_assert(viewer_exe.empty() && !format.empty());
#else
if (!viewer_exe.empty()) {
#ifdef _WIN32
// system()/cmd.exe does not understand single quotes nor
Expand All @@ -1055,7 +1050,6 @@ struct VizPass : public Pass {
if (run_command(cmd) != 0)
log_cmd_error("Shell command failed!\n");
}
#endif

if (flag_pause) {
#ifdef YOSYS_ENABLE_READLINE
Expand Down

0 comments on commit a477dff

Please sign in to comment.