Merge pull request #1986 from YosysHQ/eddie/verific_enum
[yosys.git] / passes / cmds / logger.cc
1 /*
2 * yosys -- Yosys Open SYnthesis Suite
3 *
4 * Copyright (C) 2020 Miodrag Milanovic <clifford@clifford.at>
5 *
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.
9 *
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.
17 *
18 */
19
20 #include "kernel/register.h"
21 #include "kernel/log.h"
22
23 USING_YOSYS_NAMESPACE
24 PRIVATE_NAMESPACE_BEGIN
25
26 struct LoggerPass : public Pass {
27 LoggerPass() : Pass("logger", "set logger properties") { }
28 void help() YS_OVERRIDE
29 {
30 // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
31 log("\n");
32 log(" logger [options]\n");
33 log("\n");
34 log("This command sets global logger properties, also available using command line\n");
35 log("options.\n");
36 log("\n");
37 log(" -[no]time\n");
38 log(" enable/disable display of timestamp in log output.\n");
39 log("\n");
40 log(" -[no]stderr\n");
41 log(" enable/disable logging errors to stderr.\n");
42 log("\n");
43 log(" -warn regex\n");
44 log(" print a warning for all log messages matching the regex.\n");
45 log("\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");
49 log("\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");
53 log("\n");
54 log(" -[no]debug\n");
55 log(" globally enable/disable debug log messages.\n");
56 log("\n");
57 log(" -experimental <feature>\n");
58 log(" do not print warnings for the specified experimental feature\n");
59 log("\n");
60 log(" -expect <type> <regex> <expected_count>\n");
61 log(" expect log,warning or error to appear. In case of error return code is 0.\n");
62 log("\n");
63 log(" -expect-no-warnings\n");
64 log(" gives error in case there is at least one warning that is not expected.\n");
65 log("\n");
66 }
67
68 void execute(std::vector<std::string> args, RTLIL::Design * design) YS_OVERRIDE
69 {
70 size_t argidx;
71 for (argidx = 1; argidx < args.size(); argidx++)
72 {
73
74 if (args[argidx] == "-time") {
75 log_time = true;
76 log("Enabled timestamp in logs.\n");
77 continue;
78 }
79 if (args[argidx] == "-notime") {
80 log_time = false;
81 log("Disabled timestamp in logs.\n");
82 continue;
83 }
84 if (args[argidx] == "-stderr") {
85 log_error_stderr = true;
86 log("Enabled loggint errors to stderr.\n");
87 continue;
88 }
89 if (args[argidx] == "-nostderr") {
90 log_error_stderr = false;
91 log("Disabled loggint errors to stderr.\n");
92 continue;
93 }
94 if (args[argidx] == "-warn" && argidx+1 < args.size()) {
95 std::string pattern = args[++argidx];
96 if (pattern.front() == '\"' && pattern.back() == '\"') pattern = pattern.substr(1, pattern.size() - 2);
97 try {
98 log("Added regex '%s' for warnings to warn list.\n", pattern.c_str());
99 log_warn_regexes.push_back(YS_REGEX_COMPILE(pattern));
100 }
101 catch (const YS_REGEX_NS::regex_error& e) {
102 log_cmd_error("Error in regex expression '%s' !\n", pattern.c_str());
103 }
104 continue;
105 }
106 if (args[argidx] == "-nowarn" && argidx+1 < args.size()) {
107 std::string pattern = args[++argidx];
108 if (pattern.front() == '\"' && pattern.back() == '\"') pattern = pattern.substr(1, pattern.size() - 2);
109 try {
110 log("Added regex '%s' for warnings to nowarn list.\n", pattern.c_str());
111 log_nowarn_regexes.push_back(YS_REGEX_COMPILE(pattern));
112 }
113 catch (const YS_REGEX_NS::regex_error& e) {
114 log_cmd_error("Error in regex expression '%s' !\n", pattern.c_str());
115 }
116 continue;
117 }
118 if (args[argidx] == "-werror" && argidx+1 < args.size()) {
119 std::string pattern = args[++argidx];
120 if (pattern.front() == '\"' && pattern.back() == '\"') pattern = pattern.substr(1, pattern.size() - 2);
121 try {
122 log("Added regex '%s' for warnings to werror list.\n", pattern.c_str());
123 log_werror_regexes.push_back(YS_REGEX_COMPILE(pattern));
124 }
125 catch (const YS_REGEX_NS::regex_error& e) {
126 log_cmd_error("Error in regex expression '%s' !\n", pattern.c_str());
127 }
128 continue;
129 }
130 if (args[argidx] == "-debug") {
131 log_force_debug = 1;
132 log("Enabled debug log messages.\n");
133 continue;
134 }
135 if (args[argidx] == "-nodebug") {
136 log_force_debug = 0;
137 log("Disabled debug log messages.\n");
138 continue;
139 }
140 if (args[argidx] == "-experimental" && argidx+1 < args.size()) {
141 std::string value = args[++argidx];
142 log("Added '%s' experimental ignore list.\n", value.c_str());
143 log_experimentals_ignored.insert(value);
144 continue;
145 }
146 if (args[argidx] == "-expect" && argidx+3 < args.size()) {
147 std::string type = args[++argidx];
148 if (type!="error" && type!="warning" && type!="log")
149 log_cmd_error("Expect command require type to be 'log', 'warning' or 'error' !\n");
150 if (type=="error" && log_expect_error.size()>0)
151 log_cmd_error("Only single error message can be expected !\n");
152 std::string pattern = args[++argidx];
153 if (pattern.front() == '\"' && pattern.back() == '\"') pattern = pattern.substr(1, pattern.size() - 2);
154 int count = atoi(args[++argidx].c_str());
155 if (count<=0)
156 log_cmd_error("Number of expected messages must be higher then 0 !\n");
157 if (type=="error" && count!=1)
158 log_cmd_error("Expected error message occurrences must be 1 !\n");
159 log("Added regex '%s' for warnings to expected %s list.\n", pattern.c_str(), type.c_str());
160 try {
161 if (type=="error")
162 log_expect_error.push_back(std::make_pair(YS_REGEX_COMPILE(pattern), LogExpectedItem(pattern, count)));
163 else if (type=="warning")
164 log_expect_warning.push_back(std::make_pair(YS_REGEX_COMPILE(pattern), LogExpectedItem(pattern, count)));
165 else
166 log_expect_log.push_back(std::make_pair(YS_REGEX_COMPILE(pattern), LogExpectedItem(pattern, count)));
167 }
168 catch (const YS_REGEX_NS::regex_error& e) {
169 log_cmd_error("Error in regex expression '%s' !\n", pattern.c_str());
170 }
171 continue;
172 }
173 if (args[argidx] == "-expect-no-warnings") {
174 log_expect_no_warnings = true;
175 continue;
176 }
177 break;
178 }
179 extra_args(args, argidx, design, false);
180 }
181 } LoggerPass;
182
183 PRIVATE_NAMESPACE_END