summaryrefslogtreecommitdiff
path: root/passes
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2014-06-03 09:23:31 +0200
committerClifford Wolf <clifford@clifford.at>2014-06-03 09:23:31 +0200
commit7020f7fc138ac9bad46f9f2b41150321f315f992 (patch)
treee9309484c6bb54f236f286c429187bb915b57d83 /passes
parent68c99bf7349cf56385ee803144dd7d8e219be8d5 (diff)
added tee cmd
Diffstat (limited to 'passes')
-rw-r--r--passes/cmds/Makefile.inc1
-rw-r--r--passes/cmds/tee.cc88
2 files changed, 89 insertions, 0 deletions
diff --git a/passes/cmds/Makefile.inc b/passes/cmds/Makefile.inc
index 77cac2b4..3a4b2da7 100644
--- a/passes/cmds/Makefile.inc
+++ b/passes/cmds/Makefile.inc
@@ -15,5 +15,6 @@ OBJS += passes/cmds/copy.o
OBJS += passes/cmds/splice.o
OBJS += passes/cmds/scc.o
OBJS += passes/cmds/log.o
+OBJS += passes/cmds/tee.o
OBJS += passes/cmds/connwrappers.o
diff --git a/passes/cmds/tee.cc b/passes/cmds/tee.cc
new file mode 100644
index 00000000..dd959195
--- /dev/null
+++ b/passes/cmds/tee.cc
@@ -0,0 +1,88 @@
+/*
+ * yosys -- Yosys Open SYnthesis Suite
+ *
+ * Copyright (C) 2014 Clifford Wolf <clifford@clifford.at>
+ * Copyright (C) 2014 Johann Glaser <Johann.Glaser@gmx.at>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+#include "kernel/register.h"
+#include "kernel/rtlil.h"
+#include "kernel/log.h"
+
+struct TeePass : public Pass {
+ TeePass() : Pass("tee", "redirect command output to file") { }
+ virtual void help()
+ {
+ // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
+ log("\n");
+ log(" tee [-q] [-o logfile|-a logfile] cmd\n");
+ log("\n");
+ log("Execute the specified command, optionally writing the commands output to the\n");
+ log("specified logfile(s).\n");
+ log("\n");
+ log(" -q\n");
+ log(" Do not print output to the normal destination (console and/or log file)\n");
+ log("\n");
+ log(" -o logfile\n");
+ log(" Write output to this file, truncate if exists.\n");
+ log("\n");
+ log(" -a logfile\n");
+ log(" Write output to this file, append if exists.\n");
+ log("\n");
+ }
+ virtual void execute(std::vector<std::string> args, RTLIL::Design *design)
+ {
+ std::vector<FILE*> backup_log_files, files_to_close;
+ backup_log_files = log_files;
+
+ size_t argidx;
+ for (argidx = 1; argidx < args.size(); argidx++)
+ {
+ if (args[argidx] == "-q" && files_to_close.empty()) {
+ log_files.clear();
+ continue;
+ }
+ if ((args[argidx] == "-o" || args[argidx] == "-a") && argidx+1 < args.size()) {
+ const char *open_mode = args[argidx] == "-o" ? "wt" : "at";
+ FILE *f = fopen(args[++argidx].c_str(), open_mode);
+ if (f == NULL) {
+ for (auto cf : files_to_close)
+ fclose(cf);
+ log_cmd_error("Can't create file %s.\n", args[argidx].c_str());
+ }
+ log_files.push_back(f);
+ files_to_close.push_back(f);
+ continue;
+ }
+ break;
+ }
+
+ try {
+ std::vector<std::string> new_args(args.begin() + argidx, args.end());
+ Pass::call(design, new_args);
+ } catch (int ex) {
+ for (auto cf : files_to_close)
+ fclose(cf);
+ log_files = backup_log_files;
+ throw ex;
+ }
+
+ for (auto cf : files_to_close)
+ fclose(cf);
+ log_files = backup_log_files;
+ }
+} TeePass;
+