summaryrefslogtreecommitdiff
path: root/kernel/yosys.cc
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2014-10-12 10:57:15 +0200
committerClifford Wolf <clifford@clifford.at>2014-10-12 10:57:15 +0200
commitb1596bc0e7e5269fd610508f608f65f3aa696bd9 (patch)
treea02538fb81ddef273cac8cc3f382b3be644c2449 /kernel/yosys.cc
parentd2b8b48bf3bc6b202c31db62ef5e2b63041e775e (diff)
Added run_command() api to replace system() and popen()
Diffstat (limited to 'kernel/yosys.cc')
-rw-r--r--kernel/yosys.cc25
1 files changed, 25 insertions, 0 deletions
diff --git a/kernel/yosys.cc b/kernel/yosys.cc
index a40ad437..50da13ae 100644
--- a/kernel/yosys.cc
+++ b/kernel/yosys.cc
@@ -182,6 +182,31 @@ int readsome(std::istream &f, char *s, int n)
return rc;
}
+int run_command(const std::string &command, std::function<void(const std::string&)> process_line)
+{
+ if (!process_line)
+ return system(command.c_str());
+
+ FILE *f = popen(command.c_str(), "r");
+ if (f == nullptr)
+ return -1;
+
+ std::string line;
+ char logbuf[128];
+ while (fgets(logbuf, 128, f) != NULL) {
+ line += logbuf;
+ if (!line.empty() && line.back() == '\n')
+ process_line(line), line.clear();
+ }
+ if (!line.empty())
+ process_line(line);
+
+ int ret = pclose(f);
+ if (ret < 0)
+ return -1;
+ return WEXITSTATUS(ret);
+}
+
int GetSize(RTLIL::Wire *wire)
{
return wire->width;