Add "yosys -e regex" for turning warnings into errors
authorClifford Wolf <clifford@clifford.at>
Fri, 4 May 2018 13:27:28 +0000 (15:27 +0200)
committerClifford Wolf <clifford@clifford.at>
Fri, 4 May 2018 13:27:28 +0000 (15:27 +0200)
Signed-off-by: Clifford Wolf <clifford@clifford.at>
kernel/driver.cc
kernel/log.cc
kernel/log.h

index 3c16e5fd49b1d71a22ec448eee932b08a673f389..7a1dce4970b2a1ad33371cbbdf8593f2f8453d2a 100644 (file)
@@ -255,9 +255,13 @@ int main(int argc, char **argv)
                printf("        print a warning for all log messages matching the regex.\n");
                printf("\n");
                printf("    -w regex\n");
-               printf("        if a warning message matches the regex, it is printes as regular\n");
+               printf("        if a warning message matches the regex, it is printed as regular\n");
                printf("        message instead.\n");
                printf("\n");
+               printf("    -e regex\n");
+               printf("        if a warning message matches the regex, it is printed as error\n");
+               printf("        message instead and the tool terminates with a nonzero return code.\n");
+               printf("\n");
                printf("    -E <depsfile>\n");
                printf("        write a Makefile dependencies file with in- and output file names\n");
                printf("\n");
@@ -281,7 +285,7 @@ int main(int argc, char **argv)
        }
 
        int opt;
-       while ((opt = getopt(argc, argv, "MXAQTVSm:f:Hh:b:o:p:l:L:qv:tds:c:W:w:D:E:")) != -1)
+       while ((opt = getopt(argc, argv, "MXAQTVSm:f:Hh:b:o:p:l:L:qv:tds:c:W:w:e:D:E:")) != -1)
        {
                switch (opt)
                {
@@ -375,6 +379,12 @@ int main(int argc, char **argv)
                                        std::regex_constants::optimize |
                                        std::regex_constants::egrep));
                        break;
+               case 'e':
+                       log_werror_regexes.push_back(std::regex(optarg,
+                                       std::regex_constants::nosubs |
+                                       std::regex_constants::optimize |
+                                       std::regex_constants::egrep));
+                       break;
                case 'D':
                        {
                                auto args = split_tokens(optarg, ":");
index de564cb362dac18caf6ec8ce14a458933e43a5bb..ff171f3e6c578c222d8066897b75d18bbdba975f 100644 (file)
@@ -41,7 +41,7 @@ YOSYS_NAMESPACE_BEGIN
 std::vector<FILE*> log_files;
 std::vector<std::ostream*> log_streams;
 std::map<std::string, std::set<std::string>> log_hdump;
-std::vector<std::regex> log_warn_regexes, log_nowarn_regexes;
+std::vector<std::regex> log_warn_regexes, log_nowarn_regexes, log_werror_regexes;
 std::set<std::string> log_warnings;
 int log_warnings_count = 0;
 bool log_hdump_all = false;
@@ -218,6 +218,10 @@ void logv_warning(const char *format, va_list ap)
        }
        else
        {
+               for (auto &re : log_werror_regexes)
+                       if (std::regex_search(message, re))
+                               log_error("%s",  message.c_str());
+
                if (log_warnings.count(message))
                {
                        log("Warning: %s", message.c_str());
@@ -256,6 +260,10 @@ void logv_warning_noprefix(const char *format, va_list ap)
        }
        else
        {
+               for (auto &re : log_werror_regexes)
+                       if (std::regex_search(message, re))
+                               log_error("%s",  message.c_str());
+
                if (log_warnings.count(message))
                {
                        log("%s", message.c_str());
index 90a12df36cfc654041188d65fc5fe6eee0ce676c..457229c877e2bad4fc9242bcced92048fab2bd37 100644 (file)
@@ -49,7 +49,7 @@ struct log_cmd_error_exception { };
 extern std::vector<FILE*> log_files;
 extern std::vector<std::ostream*> log_streams;
 extern std::map<std::string, std::set<std::string>> log_hdump;
-extern std::vector<std::regex> log_warn_regexes, log_nowarn_regexes;
+extern std::vector<std::regex> log_warn_regexes, log_nowarn_regexes, log_werror_regexes;
 extern std::set<std::string> log_warnings;
 extern int log_warnings_count;
 extern bool log_hdump_all;