X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=kernel%2Fyosys.cc;h=39d6a1ec1484f0833693d3ab88a00b7eeaa8a2aa;hb=5cebf6a8efb4f1e9b836db76be0bb2a964932905;hp=01131601f8b3d8feb7acaa2de4093a732473437d;hpb=0e1beb6f308da18b952e562b85504258d20ffcc7;p=yosys.git diff --git a/kernel/yosys.cc b/kernel/yosys.cc index 01131601f..39d6a1ec1 100644 --- a/kernel/yosys.cc +++ b/kernel/yosys.cc @@ -1,7 +1,7 @@ /* * yosys -- Yosys Open SYnthesis Suite * - * Copyright (C) 2012 Clifford Wolf + * Copyright (C) 2012 Claire Xenia Wolf * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -45,8 +45,10 @@ # include # include # include -# include # include +# if !defined(YOSYS_DISABLE_SPAWN) +# include +# endif #endif #if !defined(_WIN32) && defined(YOSYS_ENABLE_GLOB) @@ -65,6 +67,7 @@ # define INIT_MODULE initlibyosys extern "C" void INIT_MODULE(); #endif +#include #endif #include @@ -87,6 +90,12 @@ bool memhasher_active = false; uint32_t memhasher_rng = 123456; std::vector memhasher_store; +std::string yosys_share_dirname; +std::string yosys_abc_executable; + +void init_share_dirname(); +void init_abc_executable_name(); + void memhasher_on() { #if defined(__linux__) || defined(__FreeBSD__) @@ -129,7 +138,7 @@ void yosys_banner() log(" | |\n"); log(" | yosys -- Yosys Open SYnthesis Suite |\n"); log(" | |\n"); - log(" | Copyright (C) 2012 - 2020 Claire Wolf |\n"); + log(" | Copyright (C) 2012 - 2020 Claire Xenia Wolf |\n"); log(" | |\n"); log(" | Permission to use, copy, modify, and/or distribute this software for any |\n"); log(" | purpose with or without fee is hereby granted, provided that the above |\n"); @@ -336,16 +345,13 @@ bool patmatch(const char *pattern, const char *string) return false; } +#if !defined(YOSYS_DISABLE_SPAWN) int run_command(const std::string &command, std::function process_line) { if (!process_line) return system(command.c_str()); -#ifdef EMSCRIPTEN - FILE *f = nullptr; -#else FILE *f = popen(command.c_str(), "r"); -#endif if (f == nullptr) return -1; @@ -368,10 +374,16 @@ int run_command(const std::string &command, std::function [args]\n"); @@ -721,7 +740,7 @@ struct TclPass : public Pass { log("the standard $argc and $argv variables.\n"); log("\n"); } - void execute(std::vector args, RTLIL::Design *) YS_OVERRIDE { + void execute(std::vector args, RTLIL::Design *) override { if (args.size() < 2) log_cmd_error("Missing script file.\n"); @@ -780,7 +799,9 @@ std::string proc_self_dirname() path = (char *) realloc((void *) path, buflen); while (buflen > 0 && path[buflen-1] != '/') buflen--; - return std::string(path, buflen); + std::string str(path, buflen); + free(path); + return str; } #elif defined(_WIN32) std::string proc_self_dirname() @@ -806,7 +827,7 @@ std::string proc_self_dirname() path += char(shortpath[i]); return path; } -#elif defined(EMSCRIPTEN) +#elif defined(EMSCRIPTEN) || defined(__wasm) std::string proc_self_dirname() { return "/"; @@ -815,39 +836,75 @@ std::string proc_self_dirname() #error "Don't know how to determine process executable base path!" #endif -#ifdef EMSCRIPTEN -std::string proc_share_dirname() +#if defined(EMSCRIPTEN) || defined(__wasm) +void init_share_dirname() { - return "/share/"; + yosys_share_dirname = "/share/"; } #else -std::string proc_share_dirname() +void init_share_dirname() { std::string proc_self_path = proc_self_dirname(); # if defined(_WIN32) && !defined(YOSYS_WIN32_UNIX_DIR) std::string proc_share_path = proc_self_path + "share\\"; - if (check_file_exists(proc_share_path, true)) - return proc_share_path; + if (check_file_exists(proc_share_path, true)) { + yosys_share_dirname = proc_share_path; + return; + } proc_share_path = proc_self_path + "..\\share\\"; - if (check_file_exists(proc_share_path, true)) - return proc_share_path; + if (check_file_exists(proc_share_path, true)) { + yosys_share_dirname = proc_share_path; + return; + } # else std::string proc_share_path = proc_self_path + "share/"; - if (check_file_exists(proc_share_path, true)) - return proc_share_path; + if (check_file_exists(proc_share_path, true)) { + yosys_share_dirname = proc_share_path; + return; + } proc_share_path = proc_self_path + "../share/" + proc_program_prefix()+ "yosys/"; - if (check_file_exists(proc_share_path, true)) - return proc_share_path; + if (check_file_exists(proc_share_path, true)) { + yosys_share_dirname = proc_share_path; + return; + } # ifdef YOSYS_DATDIR proc_share_path = YOSYS_DATDIR "/"; - if (check_file_exists(proc_share_path, true)) - return proc_share_path; + if (check_file_exists(proc_share_path, true)) { + yosys_share_dirname = proc_share_path; + return; + } # endif # endif - log_error("proc_share_dirname: unable to determine share/ directory!\n"); } #endif +void init_abc_executable_name() +{ +#ifdef ABCEXTERNAL + std::string exe_file; + if (std::getenv("ABC")) { + yosys_abc_executable = std::getenv("ABC"); + } else { + yosys_abc_executable = ABCEXTERNAL; + } +#else + yosys_abc_executable = proc_self_dirname() + proc_program_prefix()+ "yosys-abc"; +#endif +#ifdef _WIN32 +#ifndef ABCEXTERNAL + if (!check_file_exists(yosys_abc_executable + ".exe") && check_file_exists(proc_self_dirname() + "..\\" + proc_program_prefix() + "yosys-abc.exe")) + yosys_abc_executable = proc_self_dirname() + "..\\" + proc_program_prefix() + "yosys-abc"; +#endif +#endif +} + +std::string proc_share_dirname() +{ + if (yosys_share_dirname.empty()) + log_error("init_share_dirname: unable to determine share/ directory!\n"); + return yosys_share_dirname; +} + std::string proc_program_prefix() { std::string program_prefix; @@ -921,7 +978,7 @@ void run_frontend(std::string filename, std::string command, std::string *backen else if (filename_trim.size() > 4 && filename_trim.compare(filename_trim.size()-5, std::string::npos, ".json") == 0) command = "json"; else if (filename_trim.size() > 3 && filename_trim.compare(filename_trim.size()-3, std::string::npos, ".il") == 0) - command = "ilang"; + command = "rtlil"; else if (filename_trim.size() > 3 && filename_trim.compare(filename_trim.size()-3, std::string::npos, ".ys") == 0) command = "script"; else if (filename_trim.size() > 3 && filename_trim.compare(filename_trim.size()-4, std::string::npos, ".tcl") == 0) @@ -1041,8 +1098,10 @@ void run_backend(std::string filename, std::string command, RTLIL::Design *desig if (command == "auto") { if (filename.size() > 2 && filename.compare(filename.size()-2, std::string::npos, ".v") == 0) command = "verilog"; + else if (filename.size() > 3 && filename.compare(filename.size()-3, std::string::npos, ".sv") == 0) + command = "verilog -sv"; else if (filename.size() > 3 && filename.compare(filename.size()-3, std::string::npos, ".il") == 0) - command = "ilang"; + command = "rtlil"; else if (filename.size() > 3 && filename.compare(filename.size()-3, std::string::npos, ".cc") == 0) command = "cxxrtl"; else if (filename.size() > 4 && filename.compare(filename.size()-4, std::string::npos, ".aig") == 0) @@ -1054,7 +1113,7 @@ void run_backend(std::string filename, std::string command, RTLIL::Design *desig else if (filename.size() > 5 && filename.compare(filename.size()-5, std::string::npos, ".json") == 0) command = "json"; else if (filename == "-") - command = "ilang"; + command = "rtlil"; else if (filename.empty()) return; else @@ -1211,7 +1270,7 @@ void shell(RTLIL::Design *design) struct ShellPass : public Pass { ShellPass() : Pass("shell", "enter interactive command mode") { } - void help() YS_OVERRIDE { + void help() override { log("\n"); log(" shell\n"); log("\n"); @@ -1243,7 +1302,7 @@ struct ShellPass : public Pass { log("Press Ctrl-D or type 'exit' to leave the interactive shell.\n"); log("\n"); } - void execute(std::vector args, RTLIL::Design *design) YS_OVERRIDE { + void execute(std::vector args, RTLIL::Design *design) override { extra_args(args, 1, design, false); shell(design); } @@ -1252,7 +1311,7 @@ struct ShellPass : public Pass { #if defined(YOSYS_ENABLE_READLINE) || defined(YOSYS_ENABLE_EDITLINE) struct HistoryPass : public Pass { HistoryPass() : Pass("history", "show last interactive commands") { } - void help() YS_OVERRIDE { + void help() override { log("\n"); log(" history\n"); log("\n"); @@ -1261,7 +1320,7 @@ struct HistoryPass : public Pass { log("from executed scripts.\n"); log("\n"); } - void execute(std::vector args, RTLIL::Design *design) YS_OVERRIDE { + void execute(std::vector args, RTLIL::Design *design) override { extra_args(args, 1, design, false); #ifdef YOSYS_ENABLE_READLINE for(HIST_ENTRY **list = history_list(); *list != NULL; list++) @@ -1276,7 +1335,7 @@ struct HistoryPass : public Pass { struct ScriptCmdPass : public Pass { ScriptCmdPass() : Pass("script", "execute commands from file or wire") { } - void help() YS_OVERRIDE { + void help() override { // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---| log("\n"); log(" script [:]\n"); @@ -1299,7 +1358,7 @@ struct ScriptCmdPass : public Pass { log("'-module' mode can be exited by using the 'cd' command.\n"); log("\n"); } - void execute(std::vector args, RTLIL::Design *design) YS_OVERRIDE + void execute(std::vector args, RTLIL::Design *design) override { bool scriptwire = false;