2 * yosys -- Yosys Open SYnthesis Suite
4 * Copyright (C) 2012 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 LogPass
: public Pass
{
29 LogPass() : Pass("log", "print text and log files") { }
30 void help() YS_OVERRIDE
32 // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
36 log("Print the given string to the screen and/or the log file. This is useful for TCL\n");
37 log("scripts, because the TCL command \"puts\" only goes to stdout but not to\n");
41 log(" Print the output to stdout too. This is useful when all Yosys is executed\n");
42 log(" with a script and the -q (quiet operation) argument to notify the user.\n");
45 log(" Print the output to stderr too.\n");
48 log(" Don't use the internal log() command. Use either -stdout or -stderr,\n");
49 log(" otherwise no output will be generated at all.\n");
52 log(" do not append a newline\n");
55 void execute(std::vector
<std::string
> args
, RTLIL::Design
*) YS_OVERRIDE
58 bool to_stdout
= false;
59 bool to_stderr
= false;
64 for (argidx
= 1; argidx
< args
.size(); argidx
++)
66 if (args
[argidx
] == "-stdout") to_stdout
= true;
67 else if (args
[argidx
] == "-stderr") to_stderr
= true;
68 else if (args
[argidx
] == "-nolog") to_log
= false;
69 else if (args
[argidx
] == "-n") newline
= false;
72 for (; argidx
< args
.size(); argidx
++)
73 text
+= args
[argidx
] + ' ';
74 if (!text
.empty()) text
.resize(text
.size()-1);
76 if (to_stdout
) fprintf(stdout
, (newline
? "%s\n" : "%s"), text
.c_str());
77 if (to_stderr
) fprintf(stderr
, (newline
? "%s\n" : "%s"), text
.c_str());
78 if (to_log
) log ( (newline
? "%s\n" : "%s"), text
.c_str());