diff options
Diffstat (limited to 'kernel/driver.cc')
-rw-r--r-- | kernel/driver.cc | 175 |
1 files changed, 154 insertions, 21 deletions
diff --git a/kernel/driver.cc b/kernel/driver.cc index 1fe61b499..9040408bc 100644 --- a/kernel/driver.cc +++ b/kernel/driver.cc @@ -25,16 +25,26 @@ # include <readline/history.h> #endif +#ifdef YOSYS_ENABLE_EDITLINE +# include <editline/readline.h> +#endif + #include <stdio.h> #include <string.h> #include <limits.h> #include <errno.h> -#ifdef __linux__ +#if defined (__linux__) || defined(__FreeBSD__) +# include <sys/resource.h> # include <sys/types.h> # include <unistd.h> #endif +#ifdef __FreeBSD__ +# include <sys/sysctl.h> +# include <sys/user.h> +#endif + #if !defined(_WIN32) || defined(__MINGW32__) # include <unistd.h> #else @@ -75,20 +85,41 @@ USING_YOSYS_NAMESPACE #ifdef EMSCRIPTEN # include <sys/stat.h> # include <sys/types.h> +# include <emscripten.h> extern "C" int main(int, char**); extern "C" void run(const char*); extern "C" const char *errmsg(); extern "C" const char *prompt(); -int main(int, char**) +int main(int argc, char **argv) { + EM_ASM( + if (ENVIRONMENT_IS_NODE) + { + FS.mkdir('/hostcwd'); + FS.mount(NODEFS, { root: '.' }, '/hostcwd'); + FS.mkdir('/hostfs'); + FS.mount(NODEFS, { root: '/' }, '/hostfs'); + } + ); + mkdir("/work", 0777); chdir("/work"); log_files.push_back(stdout); log_error_stderr = true; yosys_banner(); yosys_setup(); +#ifdef WITH_PYTHON + PyRun_SimpleString(("sys.path.append(\""+proc_self_dirname()+"\")").c_str()); + PyRun_SimpleString(("sys.path.append(\""+proc_share_dirname()+"plugins\")").c_str()); +#endif + + if (argc == 2) + { + // Run the first argument as a script file + run_frontend(argv[1], "script", 0, 0, 0); + } } void run(const char *command) @@ -119,37 +150,45 @@ const char *prompt() #else /* EMSCRIPTEN */ -#ifdef YOSYS_ENABLE_READLINE +#if defined(YOSYS_ENABLE_READLINE) || defined(YOSYS_ENABLE_EDITLINE) int yosys_history_offset = 0; std::string yosys_history_file; #endif void yosys_atexit() { -#ifdef YOSYS_ENABLE_READLINE +#if defined(YOSYS_ENABLE_READLINE) || defined(YOSYS_ENABLE_EDITLINE) if (!yosys_history_file.empty()) { +#if defined(YOSYS_ENABLE_READLINE) if (yosys_history_offset > 0) { history_truncate_file(yosys_history_file.c_str(), 100); append_history(where_history() - yosys_history_offset, yosys_history_file.c_str()); } else write_history(yosys_history_file.c_str()); +#else + write_history(yosys_history_file.c_str()); +#endif } clear_history(); +#if defined(YOSYS_ENABLE_READLINE) HIST_ENTRY **hist_list = history_list(); if (hist_list != NULL) free(hist_list); #endif +#endif } int main(int argc, char **argv) { std::string frontend_command = "auto"; std::string backend_command = "auto"; + std::vector<std::string> vlog_defines; std::vector<std::string> passes_commands; std::vector<std::string> plugin_filenames; std::string output_filename = ""; std::string scriptfile = ""; + std::string depsfile = ""; bool scriptfile_tcl = false; bool got_output_filename = false; bool print_banner = true; @@ -159,7 +198,7 @@ int main(int argc, char **argv) bool mode_v = false; bool mode_q = false; -#ifdef YOSYS_ENABLE_READLINE +#if defined(YOSYS_ENABLE_READLINE) || defined(YOSYS_ENABLE_EDITLINE) if (getenv("HOME") != NULL) { yosys_history_file = stringf("%s/.yosys_history", getenv("HOME")); read_history(yosys_history_file.c_str()); @@ -234,7 +273,10 @@ int main(int argc, char **argv) printf(" -A\n"); printf(" will call abort() at the end of the script. for debugging\n"); printf("\n"); - printf(" -D <header_id>[:<filename>]\n"); + printf(" -D <macro>[=<value>]\n"); + printf(" set the specified Verilog define (via \"read -define\")\n"); + printf("\n"); + printf(" -P <header_id>[:<filename>]\n"); printf(" dump the design when printing the specified log header to a file.\n"); printf(" yosys_dump_<header_id>.il is used as filename if none is specified.\n"); printf(" Use 'ALL' as <header_id> to dump at every header.\n"); @@ -243,9 +285,22 @@ 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"); + 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"); printf(" -V\n"); printf(" print version information and exit\n"); printf("\n"); @@ -265,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, "MXAQTVSm:f:Hh:b:o:p:l:L:qv:tds:c:W:w:D:")) != -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) { @@ -291,6 +352,9 @@ int main(int argc, char **argv) case 'S': passes_commands.push_back("synth"); break; + case 'g': + log_force_debug++; + break; case 'm': plugin_filenames.push_back(optarg); break; @@ -360,7 +424,16 @@ 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': + vlog_defines.push_back(optarg); + break; + case 'P': { auto args = split_tokens(optarg, ":"); if (!args.empty() && args[0] == "ALL") { @@ -382,6 +455,12 @@ int main(int argc, char **argv) } } break; + case 'E': + depsfile = optarg; + break; + case 'x': + log_experimentals_ignored.insert(optarg); + break; default: fprintf(stderr, "Run '%s -h' for help.\n", argv[0]); exit(1); @@ -399,7 +478,23 @@ int main(int argc, char **argv) if (print_stats) log_hasher = new SHA1; +#if defined(__linux__) + // set stack size to >= 128 MB + { + struct rlimit rl; + const rlim_t stack_size = 128L * 1024L * 1024L; + if (getrlimit(RLIMIT_STACK, &rl) == 0 && rl.rlim_cur < stack_size) { + rl.rlim_cur = stack_size; + setrlimit(RLIMIT_STACK, &rl); + } + } +#endif + yosys_setup(); +#ifdef WITH_PYTHON + PyRun_SimpleString(("sys.path.append(\""+proc_self_dirname()+"\")").c_str()); + PyRun_SimpleString(("sys.path.append(\""+proc_share_dirname()+"plugins\")").c_str()); +#endif log_error_atexit = yosys_atexit; for (auto &fn : plugin_filenames) @@ -411,6 +506,13 @@ int main(int argc, char **argv) shell(yosys_design); } + if (!vlog_defines.empty()) { + std::string vdef_cmd = "read -define"; + for (auto vdef : vlog_defines) + vdef_cmd += " " + vdef; + run_pass(vdef_cmd); + } + while (optind < argc) run_frontend(argv[optind++], frontend_command, output_filename == "-" ? &backend_command : NULL); @@ -432,6 +534,30 @@ 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"); + if (f == nullptr) + 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 ? "" : " ", 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", escape_filename_spaces(fn).c_str()); + } + fprintf(f, "\n"); + } + if (print_stats) { std::string hash = log_hasher->final().substr(0, 10); @@ -445,26 +571,33 @@ int main(int argc, char **argv) if (mode_v && !mode_q) log_files.push_back(stderr); + if (log_warnings_count) + log("Warnings: %d unique messages, %d total\n", GetSize(log_warnings), log_warnings_count); + + if (!log_experimentals.empty()) + log("Warnings: %d experimental features used (not excluded with -x).\n", GetSize(log_experimentals)); + #ifdef _WIN32 log("End of script. Logfile hash: %s\n", hash.c_str()); #else std::string meminfo; std::string stats_divider = ", "; -# ifdef __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"; - } -# 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()); @@ -504,7 +637,7 @@ int main(int argc, char **argv) } } -#if defined(YOSYS_ENABLE_COVER) && defined(__linux__) +#if defined(YOSYS_ENABLE_COVER) && (defined(__linux__) || defined(__FreeBSD__)) if (getenv("YOSYS_COVER_DIR") || getenv("YOSYS_COVER_FILE")) { string filename; |