2 * yosys -- Yosys Open SYnthesis Suite
4 * Copyright (C) 2020 Miodrag Milanovic <clifford@clifford.at>
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include "kernel/register.h"
21 #include "kernel/log.h"
24 PRIVATE_NAMESPACE_BEGIN
26 struct LoggerPass
: public Pass
{
27 LoggerPass() : Pass("logger", "set logger properties") { }
30 // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
32 log(" logger [options]\n");
34 log("This command sets global logger properties, also available using command line\n");
38 log(" enable/disable display of timestamp in log output.\n");
40 log(" -[no]stderr\n");
41 log(" enable/disable logging errors to stderr.\n");
43 log(" -warn regex\n");
44 log(" print a warning for all log messages matching the regex.\n");
46 log(" -nowarn regex\n");
47 log(" if a warning message matches the regex, it is printed as regular\n");
48 log(" message instead.\n");
50 log(" -werror regex\n");
51 log(" if a warning message matches the regex, it is printed as error\n");
52 log(" message instead and the tool terminates with a nonzero return code.\n");
55 log(" globally enable/disable debug log messages.\n");
57 log(" -experimental <feature>\n");
58 log(" do not print warnings for the specified experimental feature\n");
60 log(" -expect <type> <regex> <expected_count>\n");
61 log(" expect log, warning or error to appear. matched errors will terminate\n");
62 log(" with exit code 0.\n");
64 log(" -expect-no-warnings\n");
65 log(" gives error in case there is at least one warning that is not expected.\n");
69 void execute(std::vector
<std::string
> args
, RTLIL::Design
* design
) override
72 for (argidx
= 1; argidx
< args
.size(); argidx
++)
75 if (args
[argidx
] == "-time") {
77 log("Enabled timestamp in logs.\n");
80 if (args
[argidx
] == "-notime") {
82 log("Disabled timestamp in logs.\n");
85 if (args
[argidx
] == "-stderr") {
86 log_error_stderr
= true;
87 log("Enabled loggint errors to stderr.\n");
90 if (args
[argidx
] == "-nostderr") {
91 log_error_stderr
= false;
92 log("Disabled loggint errors to stderr.\n");
95 if (args
[argidx
] == "-warn" && argidx
+1 < args
.size()) {
96 std::string pattern
= args
[++argidx
];
97 if (pattern
.front() == '\"' && pattern
.back() == '\"') pattern
= pattern
.substr(1, pattern
.size() - 2);
99 log("Added regex '%s' for warnings to warn list.\n", pattern
.c_str());
100 log_warn_regexes
.push_back(YS_REGEX_COMPILE(pattern
));
102 catch (const YS_REGEX_NS::regex_error
& e
) {
103 log_cmd_error("Error in regex expression '%s' !\n", pattern
.c_str());
107 if (args
[argidx
] == "-nowarn" && argidx
+1 < args
.size()) {
108 std::string pattern
= args
[++argidx
];
109 if (pattern
.front() == '\"' && pattern
.back() == '\"') pattern
= pattern
.substr(1, pattern
.size() - 2);
111 log("Added regex '%s' for warnings to nowarn list.\n", pattern
.c_str());
112 log_nowarn_regexes
.push_back(YS_REGEX_COMPILE(pattern
));
114 catch (const YS_REGEX_NS::regex_error
& e
) {
115 log_cmd_error("Error in regex expression '%s' !\n", pattern
.c_str());
119 if (args
[argidx
] == "-werror" && argidx
+1 < args
.size()) {
120 std::string pattern
= args
[++argidx
];
121 if (pattern
.front() == '\"' && pattern
.back() == '\"') pattern
= pattern
.substr(1, pattern
.size() - 2);
123 log("Added regex '%s' for warnings to werror list.\n", pattern
.c_str());
124 log_werror_regexes
.push_back(YS_REGEX_COMPILE(pattern
));
126 catch (const YS_REGEX_NS::regex_error
& e
) {
127 log_cmd_error("Error in regex expression '%s' !\n", pattern
.c_str());
131 if (args
[argidx
] == "-debug") {
133 log("Enabled debug log messages.\n");
136 if (args
[argidx
] == "-nodebug") {
138 log("Disabled debug log messages.\n");
141 if (args
[argidx
] == "-experimental" && argidx
+1 < args
.size()) {
142 std::string value
= args
[++argidx
];
143 log("Added '%s' experimental ignore list.\n", value
.c_str());
144 log_experimentals_ignored
.insert(value
);
147 if (args
[argidx
] == "-expect" && argidx
+3 < args
.size()) {
148 std::string type
= args
[++argidx
];
149 if (type
!="error" && type
!="warning" && type
!="log")
150 log_cmd_error("Expect command require type to be 'log', 'warning' or 'error' !\n");
151 if (type
=="error" && log_expect_error
.size()>0)
152 log_cmd_error("Only single error message can be expected !\n");
153 std::string pattern
= args
[++argidx
];
154 if (pattern
.front() == '\"' && pattern
.back() == '\"') pattern
= pattern
.substr(1, pattern
.size() - 2);
155 int count
= atoi(args
[++argidx
].c_str());
157 log_cmd_error("Number of expected messages must be higher then 0 !\n");
158 if (type
=="error" && count
!=1)
159 log_cmd_error("Expected error message occurrences must be 1 !\n");
160 log("Added regex '%s' for warnings to expected %s list.\n", pattern
.c_str(), type
.c_str());
163 log_expect_error
[pattern
] = LogExpectedItem(YS_REGEX_COMPILE(pattern
), count
);
164 else if (type
== "warning")
165 log_expect_warning
[pattern
] = LogExpectedItem(YS_REGEX_COMPILE(pattern
), count
);
166 else if (type
== "log")
167 log_expect_log
[pattern
] = LogExpectedItem(YS_REGEX_COMPILE(pattern
), count
);
170 catch (const YS_REGEX_NS::regex_error
& e
) {
171 log_cmd_error("Error in regex expression '%s' !\n", pattern
.c_str());
175 if (args
[argidx
] == "-expect-no-warnings") {
176 log_expect_no_warnings
= true;
181 extra_args(args
, argidx
, design
, false);
185 PRIVATE_NAMESPACE_END