From 4fc782ef2b7212b5484c418b72b229e15a62604d Mon Sep 17 00:00:00 2001 From: Robert O'Callahan Date: Mon, 22 Sep 2025 04:35:48 +0000 Subject: [PATCH] Make ABC_DONE detection more robust. 1) Change token from ABC_DONE to YOSYS_ABC_DONE to be a bit more robust against false matches. 2) Emit the token from the sourced script so that we don't have to worry about it showing up in the echoing of the command as it executes. It will only appear in ABC stdout when it executes, i.e. when our script has completed. 3) `set abcout` doesn't actually switch ABC to line buffering on stdout, since HAVE_SETVBUF is not actually set in ABC builds in general. So stop using that. ABC does the necessary flushing when `source` has finished. --- passes/techmap/abc.cc | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/passes/techmap/abc.cc b/passes/techmap/abc.cc index 06b30b9b3..ff0aa2975 100644 --- a/passes/techmap/abc.cc +++ b/passes/techmap/abc.cc @@ -1065,6 +1065,9 @@ void AbcModuleState::prepare_module(RTLIL::Design *design, RTLIL::Module *module abc_script += stringf("; dress \"%s/input.blif\"", run_abc.tempdir_name); abc_script += stringf("; write_blif %s/output.blif", run_abc.tempdir_name); abc_script = add_echos_to_abc_cmd(abc_script); +#if defined(__linux__) && !defined(YOSYS_DISABLE_SPAWN) + abc_script += "; echo \"YOSYS_ABC_DONE\"\n"; +#endif for (size_t i = 0; i+1 < abc_script.size(); i++) if (abc_script[i] == ';' && abc_script[i+1] == ' ') @@ -1147,9 +1150,7 @@ bool read_until_abc_done(abc_output_filter &filt, int fd, DeferredLogs &logs) { break; } line.append(start, p + 1 - start); - // ABC seems to actually print "ABC_DONE \n", but we probably shouldn't - // rely on that extra space being output. - if (line.substr(0, 8) == "ABC_DONE") { + if (line.substr(0, 14) == "YOSYS_ABC_DONE") { // Ignore any leftover output, there should only be a prompt perhaps return true; } @@ -1344,12 +1345,8 @@ void RunAbcState::run(ConcurrentStack &process_pool) return; } std::string cmd = stringf( - // This makes ABC switch stdout to line buffering, which we need - // to see our ABC_DONE message. - "set abcout /dev/stdout\n" "empty\n" - "source %s\n" - "echo \"ABC_DONE\"\n", tmp_script_name); + "source %s\n", tmp_script_name); int ret = write(process.to_child_pipe, cmd.c_str(), cmd.size()); if (ret != static_cast(cmd.size())) { logs.log_error("write failed");