diff --git a/Makefile b/Makefile index 9a8127c87..d0872317f 100644 --- a/Makefile +++ b/Makefile @@ -176,7 +176,7 @@ ifeq ($(OS), Haiku) CXXFLAGS += -D_DEFAULT_SOURCE endif -YOSYS_VER := 0.53+3 +YOSYS_VER := 0.53+15 YOSYS_MAJOR := $(shell echo $(YOSYS_VER) | cut -d'.' -f1) YOSYS_MINOR := $(shell echo $(YOSYS_VER) | cut -d'.' -f2) YOSYS_COMMIT := $(shell echo $(YOSYS_VER) | cut -d'.' -f3) diff --git a/backends/aiger/aiger.cc b/backends/aiger/aiger.cc index f2cb5d9bc..617d7d85f 100644 --- a/backends/aiger/aiger.cc +++ b/backends/aiger/aiger.cc @@ -662,8 +662,7 @@ struct AigerWriter f << std::endl; } } - - f << stringf("c\nGenerated by %s\n", yosys_version_str); + f << stringf("c\nGenerated by %s\n", yosys_maybe_version()); } void write_map(std::ostream &f, bool verbose_map, bool no_startoffset) @@ -746,7 +745,7 @@ struct AigerWriter { json.begin_object(); json.entry("version", "Yosys Witness Aiger map"); - json.entry("gennerator", yosys_version_str); + json.entry("gennerator", yosys_maybe_version()); json.entry("latch_count", aig_l); json.entry("input_count", aig_i); diff --git a/backends/aiger/xaiger.cc b/backends/aiger/xaiger.cc index baf504ba2..97dec40e4 100644 --- a/backends/aiger/xaiger.cc +++ b/backends/aiger/xaiger.cc @@ -671,7 +671,7 @@ struct XAigerWriter //f.write(reinterpret_cast(&buffer_size_be), sizeof(buffer_size_be)); //f.write(buffer_str.data(), buffer_str.size()); - f << stringf("Generated by %s\n", yosys_version_str); + f << stringf("Generated by %s\n", yosys_maybe_version()); design->scratchpad_set_int("write_xaiger.num_ands", and_map.size()); design->scratchpad_set_int("write_xaiger.num_wires", aig_map.size()); diff --git a/backends/blif/blif.cc b/backends/blif/blif.cc index 049a3c680..5a5b9219f 100644 --- a/backends/blif/blif.cc +++ b/backends/blif/blif.cc @@ -649,7 +649,7 @@ struct BlifBackend : public Backend { if (module->get_bool_attribute(ID::top)) top_module_name = module->name.str(); - *f << stringf("# Generated by %s\n", yosys_version_str); + *f << stringf("# Generated by %s\n", yosys_maybe_version()); std::vector mod_list; diff --git a/backends/btor/btor.cc b/backends/btor/btor.cc index fa3cc728e..bfd293557 100644 --- a/backends/btor/btor.cc +++ b/backends/btor/btor.cc @@ -1499,7 +1499,7 @@ struct BtorWorker { ywmap_json.begin_object(); ywmap_json.entry("version", "Yosys Witness BTOR map"); - ywmap_json.entry("generator", yosys_version_str); + ywmap_json.entry("generator", yosys_maybe_version()); ywmap_json.name("clocks"); ywmap_json.begin_array(); @@ -1613,7 +1613,7 @@ struct BtorBackend : public Backend { log_cmd_error("No top module found.\n"); *f << stringf("; BTOR description generated by %s for module %s.\n", - yosys_version_str, log_id(topmod)); + yosys_maybe_version(), log_id(topmod)); BtorWorker(*f, topmod, verbose, single_bad, cover_mode, print_internal_names, info_filename, ywmap_filename); diff --git a/backends/edif/edif.cc b/backends/edif/edif.cc index d751a5996..581590287 100644 --- a/backends/edif/edif.cc +++ b/backends/edif/edif.cc @@ -231,7 +231,8 @@ struct EdifBackend : public Backend { *f << stringf(" (edifVersion 2 0 0)\n"); *f << stringf(" (edifLevel 0)\n"); *f << stringf(" (keywordMap (keywordLevel 0))\n"); - *f << stringf(" (comment \"Generated by %s\")\n", yosys_version_str); + + *f << stringf(" (comment \"Generated by %s\")\n", yosys_maybe_version()); *f << stringf(" (external LIB\n"); *f << stringf(" (edifLevel 0)\n"); diff --git a/backends/jny/jny.cc b/backends/jny/jny.cc index 1c163dba5..4aacb4e20 100644 --- a/backends/jny/jny.cc +++ b/backends/jny/jny.cc @@ -125,7 +125,7 @@ struct JnyWriter f << "{\n"; f << " \"$schema\": \"https://raw.githubusercontent.com/YosysHQ/yosys/main/misc/jny.schema.json\",\n"; - f << stringf(" \"generator\": \"%s\",\n", escape_string(yosys_version_str).c_str()); + f << stringf(" \"generator\": \"%s\",\n", escape_string(yosys_maybe_version()).c_str()); f << " \"version\": \"0.0.1\",\n"; f << " \"invocation\": \"" << escape_string(invk) << "\",\n"; f << " \"features\": ["; diff --git a/backends/json/json.cc b/backends/json/json.cc index 749fe1fc3..98e929dfa 100644 --- a/backends/json/json.cc +++ b/backends/json/json.cc @@ -291,7 +291,7 @@ struct JsonWriter design->sort(); f << stringf("{\n"); - f << stringf(" \"creator\": %s,\n", get_string(yosys_version_str).c_str()); + f << stringf(" \"creator\": %s,\n", get_string(yosys_maybe_version()).c_str()); f << stringf(" \"modules\": {\n"); vector modules = use_selection ? design->selected_modules() : design->modules(); bool first_module = true; diff --git a/backends/rtlil/rtlil_backend.cc b/backends/rtlil/rtlil_backend.cc index ae60ee6c7..adde37356 100644 --- a/backends/rtlil/rtlil_backend.cc +++ b/backends/rtlil/rtlil_backend.cc @@ -459,7 +459,8 @@ struct RTLILBackend : public Backend { design->sort(); log("Output filename: %s\n", filename.c_str()); - *f << stringf("# Generated by %s\n", yosys_version_str); + + *f << stringf("# Generated by %s\n", yosys_maybe_version()); RTLIL_BACKEND::dump_design(*f, design, selected, true, false); } } RTLILBackend; diff --git a/backends/smt2/smt2.cc b/backends/smt2/smt2.cc index 02784b975..87f5a08c8 100644 --- a/backends/smt2/smt2.cc +++ b/backends/smt2/smt2.cc @@ -1831,7 +1831,7 @@ struct Smt2Backend : public Backend { } } - *f << stringf("; SMT-LIBv2 description generated by %s\n", yosys_version_str); + *f << stringf("; SMT-LIBv2 description generated by %s\n", yosys_maybe_version()); if (!bvmode) *f << stringf("; yosys-smt2-nobv\n"); diff --git a/backends/smv/smv.cc b/backends/smv/smv.cc index 44e200384..1c2b2a224 100644 --- a/backends/smv/smv.cc +++ b/backends/smv/smv.cc @@ -797,7 +797,7 @@ struct SmvBackend : public Backend { if (module == nullptr) log_error("Module '%s' not found.\n", stmt[1].c_str()); - *f << stringf("-- SMV description generated by %s\n", yosys_version_str); + *f << stringf("-- SMV description generated by %s\n", yosys_maybe_version()); log("Creating SMV representation of module %s.\n", log_id(module)); SmvWorker worker(module, verbose, *f); @@ -816,7 +816,7 @@ struct SmvBackend : public Backend { if (!modules.empty()) { - *f << stringf("-- SMV description generated by %s\n", yosys_version_str); + *f << stringf("-- SMV description generated by %s\n", yosys_maybe_version()); for (auto module : modules) { log("Creating SMV representation of module %s.\n", log_id(module)); diff --git a/backends/spice/spice.cc b/backends/spice/spice.cc index 1160a01a1..e55db95e1 100644 --- a/backends/spice/spice.cc +++ b/backends/spice/spice.cc @@ -215,7 +215,7 @@ struct SpiceBackend : public Backend { if (module->get_bool_attribute(ID::top)) top_module_name = module->name.str(); - *f << stringf("* SPICE netlist generated by %s\n", yosys_version_str); + *f << stringf("* SPICE netlist generated by %s\n", yosys_maybe_version()); *f << stringf("\n"); for (auto module : design->modules()) diff --git a/backends/verilog/verilog_backend.cc b/backends/verilog/verilog_backend.cc index 0dfd4d96b..d161e4b8a 100644 --- a/backends/verilog/verilog_backend.cc +++ b/backends/verilog/verilog_backend.cc @@ -2621,7 +2621,8 @@ struct VerilogBackend : public Backend { design->sort(); - *f << stringf("/* Generated by %s */\n", yosys_version_str); + *f << stringf("/* Generated by %s */\n", yosys_maybe_version()); + for (auto module : design->modules()) { if (module->get_blackbox_attribute() != blackboxes) continue; diff --git a/kernel/driver.cc b/kernel/driver.cc index b7f0268db..9acc58dc4 100644 --- a/kernel/driver.cc +++ b/kernel/driver.cc @@ -252,6 +252,7 @@ int main(int argc, char **argv) options.add_options("logging") ("Q", "suppress printing of banner (copyright, disclaimer, version)") ("T", "suppress printing of footer (log hash, version, timing statistics)") + ("no-version", "suppress writing out Yosys version anywhere excluding -V, --version") ("q,quiet", "quiet operation. Only write warnings and error messages to console. " \ "Use this option twice to also quiet warning messages") ("v,verbose", "print log headers up to to the console. " \ @@ -318,6 +319,7 @@ int main(int argc, char **argv) if (result.count("A")) call_abort = true; if (result.count("Q")) print_banner = false; if (result.count("T")) print_stats = false; + if (result.count("no-version")) yosys_write_versions = false; if (result.count("V")) { std::cout << yosys_version_str << std::endl; exit(0); @@ -691,7 +693,7 @@ int main(int argc, char **argv) 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()); #endif - log("%s\n", yosys_version_str); + log("%s\n", yosys_maybe_version()); int64_t total_ns = 0; std::set> timedat; @@ -731,7 +733,7 @@ int main(int argc, char **argv) log_error("Can't open performance log file for writing: %s\n", strerror(errno)); fprintf(f, "{\n"); - fprintf(f, " \"generator\": \"%s\",\n", yosys_version_str); + fprintf(f, " \"generator\": \"%s\",\n", yosys_maybe_version()); fprintf(f, " \"total_ns\": %" PRIu64 ",\n", total_ns); fprintf(f, " \"passes\": {"); diff --git a/kernel/gzip.cc b/kernel/gzip.cc index 4567fe03b..6790b536e 100644 --- a/kernel/gzip.cc +++ b/kernel/gzip.cc @@ -102,6 +102,8 @@ gzip_istream::ibuf::~ibuf() { // returns the original ifstream, rewound to the start. // Never returns nullptr or failed state istream* std::istream* uncompressed(const std::string filename, std::ios_base::openmode mode) { + if (!check_file_exists(filename)) + log_cmd_error("File `%s' not found or is a directory\n", filename.c_str()); std::ifstream* f = new std::ifstream(); f->open(filename, mode); if (f->fail()) diff --git a/kernel/hashlib.h b/kernel/hashlib.h index 5a316a636..ad1ed8843 100644 --- a/kernel/hashlib.h +++ b/kernel/hashlib.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include diff --git a/kernel/io.cc b/kernel/io.cc index 5331e2ed8..d5d2994b2 100644 --- a/kernel/io.cc +++ b/kernel/io.cc @@ -247,7 +247,7 @@ std::string make_temp_dir(std::string template_str) #endif } -bool check_directory_exists(const std::string& dirname) +bool check_is_directory(const std::string& dirname) { #if defined(_WIN32) struct _stat info; @@ -267,17 +267,26 @@ bool check_directory_exists(const std::string& dirname) } #ifdef _WIN32 -bool check_file_exists(std::string filename, bool) +bool check_accessible(const std::string& filename, bool) { return _access(filename.c_str(), 0) == 0; } #else -bool check_file_exists(std::string filename, bool is_exec) +bool check_accessible(const std::string& filename, bool is_exec) { return access(filename.c_str(), is_exec ? X_OK : F_OK) == 0; } #endif +bool check_file_exists(const std::string& filename, bool is_exec) +{ + return check_accessible(filename, is_exec) && !check_is_directory(filename); +} +bool check_directory_exists(const std::string& filename, bool is_exec) +{ + return check_accessible(filename, is_exec) && check_is_directory(filename); +} + bool is_absolute_path(std::string filename) { #ifdef _WIN32 diff --git a/kernel/io.h b/kernel/io.h index b21d4d9c8..91699d775 100644 --- a/kernel/io.h +++ b/kernel/io.h @@ -64,6 +64,23 @@ inline std::string stringf(const char *fmt, ...) return string; } +int readsome(std::istream &f, char *s, int n); +std::string next_token(std::string &text, const char *sep = " \t\r\n", bool long_strings = false); +std::vector split_tokens(const std::string &text, const char *sep = " \t\r\n"); +bool patmatch(const char *pattern, const char *string); +#if !defined(YOSYS_DISABLE_SPAWN) +int run_command(const std::string &command, std::function process_line = std::function()); +#endif +std::string get_base_tmpdir(); +std::string make_temp_file(std::string template_str = get_base_tmpdir() + "/yosys_XXXXXX"); +std::string make_temp_dir(std::string template_str = get_base_tmpdir() + "/yosys_XXXXXX"); +bool check_file_exists(const std::string& filename, bool is_exec = false); +bool check_directory_exists(const std::string& dirname, bool is_exec = false); +bool is_absolute_path(std::string filename); +void remove_directory(std::string dirname); +bool create_directory(const std::string& dirname); +std::string escape_filename_spaces(const std::string& filename); + YOSYS_NAMESPACE_END #endif // YOSYS_IO_H diff --git a/kernel/register.cc b/kernel/register.cc index a82f93555..af1823b5b 100644 --- a/kernel/register.cc +++ b/kernel/register.cc @@ -860,7 +860,7 @@ struct HelpPass : public Pass { // init json json.begin_object(); json.entry("version", "Yosys internal cells"); - json.entry("generator", yosys_version_str); + json.entry("generator", yosys_maybe_version()); dict> groups; dict> cells; diff --git a/kernel/yosys.cc b/kernel/yosys.cc index 6eb22202d..6bfa423ac 100644 --- a/kernel/yosys.cc +++ b/kernel/yosys.cc @@ -84,6 +84,14 @@ YOSYS_NAMESPACE_BEGIN int autoidx = 1; int yosys_xtrace = 0; std::set seen_ids; +bool yosys_write_versions = true; +const char* yosys_maybe_version() { + if (yosys_write_versions) + return yosys_version_str; + else + return "Yosys"; +} + RTLIL::Design *yosys_design = NULL; CellTypes yosys_celltypes; @@ -147,7 +155,7 @@ void yosys_banner() log(" | Copyright (C) 2012 - 2025 Claire Xenia Wolf |\n"); log(" | Distributed under an ISC-like license, type \"license\" to see terms |\n"); log(" \\----------------------------------------------------------------------------/\n"); - log(" %s\n", yosys_version_str); + log(" %s\n", yosys_maybe_version()); } #if !defined(YOSYS_DISABLE_SPAWN) @@ -551,29 +559,29 @@ 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)) { + if (check_directory_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)) { + if (check_directory_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)) { + if (check_directory_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)) { + if (check_directory_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)) { + if (check_directory_exists(proc_share_path, true)) { yosys_share_dirname = proc_share_path; return; } diff --git a/kernel/yosys.h b/kernel/yosys.h index d0359aea8..7dfe8aa0b 100644 --- a/kernel/yosys.h +++ b/kernel/yosys.h @@ -81,6 +81,7 @@ extern std::set yosys_input_files, yosys_output_files; // from kernel/version_*.o (cc source generated from Makefile) extern const char *yosys_version_str; +const char* yosys_maybe_version(); // from passes/cmds/design.cc extern std::map saved_designs; diff --git a/kernel/yosys_common.h b/kernel/yosys_common.h index c06863a83..f423ebbe1 100644 --- a/kernel/yosys_common.h +++ b/kernel/yosys_common.h @@ -252,29 +252,13 @@ inline void memhasher() { if (memhasher_active) memhasher_do(); } void yosys_banner(); int ceil_log2(int x) YS_ATTRIBUTE(const); -int readsome(std::istream &f, char *s, int n); -std::string next_token(std::string &text, const char *sep = " \t\r\n", bool long_strings = false); -std::vector split_tokens(const std::string &text, const char *sep = " \t\r\n"); -bool patmatch(const char *pattern, const char *string); -#if !defined(YOSYS_DISABLE_SPAWN) -int run_command(const std::string &command, std::function process_line = std::function()); -#endif -std::string get_base_tmpdir(); -std::string make_temp_file(std::string template_str = get_base_tmpdir() + "/yosys_XXXXXX"); -std::string make_temp_dir(std::string template_str = get_base_tmpdir() + "/yosys_XXXXXX"); -bool check_file_exists(std::string filename, bool is_exec = false); -bool check_directory_exists(const std::string& dirname); -bool is_absolute_path(std::string filename); -void remove_directory(std::string dirname); -bool create_directory(const std::string& dirname); -std::string escape_filename_spaces(const std::string& filename); - template int GetSize(const T &obj) { return obj.size(); } inline int GetSize(RTLIL::Wire *wire); extern int autoidx; extern int yosys_xtrace; extern std::set seen_ids; +extern bool yosys_write_versions; RTLIL::IdString new_id(std::string file, int line, std::string func); RTLIL::IdString new_id_suffix(std::string file, int line, std::string func, std::string suffix); diff --git a/passes/cmds/internal_stats.cc b/passes/cmds/internal_stats.cc index cc35dcc5f..28822f237 100644 --- a/passes/cmds/internal_stats.cc +++ b/passes/cmds/internal_stats.cc @@ -99,7 +99,7 @@ struct InternalStatsPass : public Pass { if (json_mode) { log("{\n"); - log(" \"creator\": %s,\n", json11::Json(yosys_version_str).dump().c_str()); + log(" \"creator\": %s,\n", json11::Json(yosys_maybe_version()).dump().c_str()); std::stringstream invocation; std::copy(args.begin(), args.end(), std::ostream_iterator(invocation, " ")); log(" \"invocation\": %s,\n", json11::Json(invocation.str()).dump().c_str()); diff --git a/passes/cmds/stat.cc b/passes/cmds/stat.cc index b7cc27847..cad51f2e7 100644 --- a/passes/cmds/stat.cc +++ b/passes/cmds/stat.cc @@ -493,7 +493,7 @@ struct StatPass : public Pass { if (json_mode) { log("{\n"); - log(" \"creator\": %s,\n", json11::Json(yosys_version_str).dump().c_str()); + log(" \"creator\": %s,\n", json11::Json(yosys_maybe_version()).dump().c_str()); std::stringstream invocation; std::copy(args.begin(), args.end(), std::ostream_iterator(invocation, " ")); log(" \"invocation\": %s,\n", json11::Json(invocation.str()).dump().c_str()); diff --git a/passes/sat/sat.cc b/passes/sat/sat.cc index 53f009e40..0c2143fc9 100644 --- a/passes/sat/sat.cc +++ b/passes/sat/sat.cc @@ -691,7 +691,7 @@ struct SatHelper fprintf(f, " %s\n", stime); fprintf(f, "$end\n"); fprintf(f, "$version\n"); - fprintf(f, " Generated by %s\n", yosys_version_str); + fprintf(f, " Generated by %s\n", yosys_maybe_version()); fprintf(f, "$end\n"); fprintf(f, "$comment\n"); fprintf(f, " Generated from SAT problem in module %s (declared at %s)\n", diff --git a/passes/sat/sim.cc b/passes/sat/sim.cc index b658de383..96b04159d 100644 --- a/passes/sat/sim.cc +++ b/passes/sat/sim.cc @@ -2067,7 +2067,7 @@ struct SimWorker : SimShared json.begin_object(); json.entry("version", "Yosys sim summary"); - json.entry("generator", yosys_version_str); + json.entry("generator", yosys_maybe_version()); json.entry("steps", step); json.entry("top", log_id(top->module->name)); json.name("assertions"); @@ -2346,7 +2346,7 @@ struct VCDWriter : public OutputWriter void write(std::map &use_signal) override { if (!vcdfile.is_open()) return; - vcdfile << stringf("$version %s $end\n", worker->date ? yosys_version_str : "Yosys"); + vcdfile << stringf("$version %s $end\n", worker->date ? yosys_maybe_version() : "Yosys"); if (worker->date) { std::time_t t = std::time(nullptr); @@ -2637,7 +2637,7 @@ struct FSTWriter : public OutputWriter { if (!fstfile) return; std::time_t t = std::time(nullptr); - fstWriterSetVersion(fstfile, worker->date ? yosys_version_str : "Yosys"); + fstWriterSetVersion(fstfile, worker->date ? yosys_maybe_version() : "Yosys"); if (worker->date) fstWriterSetDate(fstfile, asctime(std::localtime(&t))); else