Add log_experimental() and experimental() API and "yosys -x"
[yosys.git] / kernel / driver.cc
index 1bc7a5935a41541b7114ea7dadeee00f90d7be7d..acbf6b55d5d344d0142db93ed18347de6ce81a80 100644 (file)
@@ -295,6 +295,9 @@ int main(int argc, char **argv)
                printf("    -E <depsfile>\n");
                printf("        write a Makefile dependencies file with in- and output file names\n");
                printf("\n");
+               printf("    -x <feature>\n");
+               printf("        do not print warnings for the specified experimental feature\n");
+               printf("\n");
                printf("    -g\n");
                printf("        globally enable debug log messages\n");
                printf("\n");
@@ -317,8 +320,14 @@ int main(int argc, char **argv)
                exit(0);
        }
 
+       if (argc == 2 && (!strcmp(argv[1], "-V") || !strcmp(argv[1], "-version") || !strcmp(argv[1], "--version")))
+       {
+               printf("%s\n", yosys_version_str);
+               exit(0);
+       }
+
        int opt;
-       while ((opt = getopt(argc, argv, "MXAQTVSgm:f:Hh:b:o:p:l:L:qv:tds:c:W:w:e:D:P:E:")) != -1)
+       while ((opt = getopt(argc, argv, "MXAQTVSgm:f:Hh:b:o:p:l:L:qv:tds:c:W:w:e:D:P:E:x:")) != -1)
        {
                switch (opt)
                {
@@ -449,6 +458,9 @@ int main(int argc, char **argv)
                case 'E':
                        depsfile = optarg;
                        break;
+               case 'x':
+                       log_experimentals.insert(optarg);
+                       break;
                default:
                        fprintf(stderr, "Run '%s -h' for help.\n", argv[0]);
                        exit(1);
@@ -522,6 +534,12 @@ int main(int argc, char **argv)
        if (!backend_command.empty())
                run_backend(output_filename, backend_command);
 
+       yosys_design->check();
+       for (auto it : saved_designs)
+               it.second->check();
+       for (auto it : pushed_designs)
+               it->check();
+
        if (!depsfile.empty())
        {
                FILE *f = fopen(depsfile.c_str(), "wt");
@@ -529,13 +547,13 @@ int main(int argc, char **argv)
                        log_error("Can't open dependencies file for writing: %s\n", strerror(errno));
                bool first = true;
                for (auto fn : yosys_output_files) {
-                       fprintf(f, "%s%s", first ? "" : " ", fn.c_str());
+                       fprintf(f, "%s%s", first ? "" : " ", escape_filename_spaces(fn).c_str());
                        first = false;
                }
                fprintf(f, ":");
                for (auto fn : yosys_input_files) {
                        if (yosys_output_files.count(fn) == 0)
-                               fprintf(f, " %s", fn.c_str());
+                               fprintf(f, " %s", escape_filename_spaces(fn).c_str());
                }
                fprintf(f, "\n");
        }
@@ -560,34 +578,22 @@ int main(int argc, char **argv)
 #else
                std::string meminfo;
                std::string stats_divider = ", ";
-#  if defined(__linux__)
-               std::ifstream statm;
-               statm.open(stringf("/proc/%lld/statm", (long long)getpid()));
-               if (statm.is_open()) {
-                       int sz_total, sz_resident;
-                       statm >> sz_total >> sz_resident;
-                       meminfo = stringf(", MEM: %.2f MB total, %.2f MB resident",
-                                       sz_total * (getpagesize() / 1024.0 / 1024.0),
-                                       sz_resident * (getpagesize() / 1024.0 / 1024.0));
-                       stats_divider = "\n";
-               }
-#  elif defined(__FreeBSD__)
-               pid_t pid = getpid();
-               int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, (int)pid};
-               struct kinfo_proc kip;
-               size_t kip_len = sizeof(kip);
-               if (sysctl(mib, 4, &kip, &kip_len, NULL, 0) == 0) {
-                       vm_size_t sz_total = kip.ki_size;
-                       segsz_t sz_resident = kip.ki_rssize;
-                       meminfo = stringf(", MEM: %.2f MB total, %.2f MB resident",
-                               (int)sz_total / 1024.0 / 1024.0,
-                               (int)sz_resident * (getpagesize() / 1024.0 / 1024.0));
-                       stats_divider = "\n";
-               }
-#  endif
 
                struct rusage ru_buffer;
                getrusage(RUSAGE_SELF, &ru_buffer);
+               if (yosys_design->scratchpad_get_bool("print_stats.include_children")) {
+                       struct rusage ru_buffer_children;
+                       getrusage(RUSAGE_CHILDREN, &ru_buffer_children);
+                       ru_buffer.ru_utime.tv_sec += ru_buffer_children.ru_utime.tv_sec;
+                       ru_buffer.ru_utime.tv_usec += ru_buffer_children.ru_utime.tv_usec;
+                       ru_buffer.ru_stime.tv_sec += ru_buffer_children.ru_stime.tv_sec;
+                       ru_buffer.ru_stime.tv_usec += ru_buffer_children.ru_stime.tv_usec;
+                       ru_buffer.ru_maxrss = std::max(ru_buffer.ru_maxrss, ru_buffer_children.ru_maxrss);
+               }
+#  if defined(__linux__) || defined(__FreeBSD__)
+               meminfo = stringf(", MEM: %.2f MB peak",
+                               ru_buffer.ru_maxrss / 1024.0);
+#endif
                log("End of script. Logfile hash: %s%sCPU: user %.2fs system %.2fs%s\n", hash.c_str(),
                                stats_divider.c_str(), ru_buffer.ru_utime.tv_sec + 1e-6 * ru_buffer.ru_utime.tv_usec,
                                ru_buffer.ru_stime.tv_sec + 1e-6 * ru_buffer.ru_stime.tv_usec, meminfo.c_str());