60689fc825ae6af6ed8932d6ac65e20a34e9ad10
2 * yosys -- Yosys Open SYnthesis Suite
4 * Copyright (C) 2014 Clifford Wolf <clifford@clifford.at>
5 * Copyright (C) 2014 Johann Glaser <Johann.Glaser@gmx.at>
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 #include "kernel/register.h"
22 #include "kernel/rtlil.h"
23 #include "kernel/log.h"
26 PRIVATE_NAMESPACE_BEGIN
28 struct TeePass
: public Pass
{
29 TeePass() : Pass("tee", "redirect command output to file") { }
32 // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
34 log(" tee [-q] [-o logfile|-a logfile] cmd\n");
36 log("Execute the specified command, optionally writing the commands output to the\n");
37 log("specified logfile(s).\n");
40 log(" Do not print output to the normal destination (console and/or log file).\n");
43 log(" Write output to this file, truncate if exists.\n");
46 log(" Write output to this file, append if exists.\n");
49 log(" Add/subtract INT from the -v setting for this command.\n");
52 void execute(std::vector
<std::string
> args
, RTLIL::Design
*design
) override
54 std::vector
<FILE*> backup_log_files
, files_to_close
;
55 std::vector
<std::ostream
*> backup_log_streams
;
56 int backup_log_verbose_level
= log_verbose_level
;
57 backup_log_streams
= log_streams
;
58 backup_log_files
= log_files
;
61 for (argidx
= 1; argidx
< args
.size(); argidx
++)
63 if (args
[argidx
] == "-q" && files_to_close
.empty()) {
68 if ((args
[argidx
] == "-o" || args
[argidx
] == "-a") && argidx
+1 < args
.size()) {
69 const char *open_mode
= args
[argidx
] == "-o" ? "w" : "a+";
70 FILE *f
= fopen(args
[++argidx
].c_str(), open_mode
);
71 yosys_input_files
.insert(args
[argidx
]);
73 for (auto cf
: files_to_close
)
75 log_cmd_error("Can't create file %s.\n", args
[argidx
].c_str());
77 log_files
.push_back(f
);
78 files_to_close
.push_back(f
);
81 if (GetSize(args
[argidx
]) >= 2 && (args
[argidx
][0] == '-' || args
[argidx
][0] == '+') && args
[argidx
][1] >= '0' && args
[argidx
][1] <= '9') {
82 log_verbose_level
+= atoi(args
[argidx
].c_str());
89 std::vector
<std::string
> new_args(args
.begin() + argidx
, args
.end());
90 Pass::call(design
, new_args
);
92 for (auto cf
: files_to_close
)
94 log_files
= backup_log_files
;
95 log_streams
= backup_log_streams
;
99 for (auto cf
: files_to_close
)
102 log_verbose_level
= backup_log_verbose_level
;
103 log_files
= backup_log_files
;
104 log_streams
= backup_log_streams
;
108 PRIVATE_NAMESPACE_END