From d7affb8821b343277c6760b1bbaf774c74dd0dd0 Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Mon, 5 May 2025 13:12:08 +0200 Subject: [PATCH 1/7] driver: add --no-version to suppress writing Yosys version in command outputs --- backends/aiger/aiger.cc | 4 ++-- backends/aiger/xaiger.cc | 3 ++- backends/blif/blif.cc | 3 ++- backends/edif/edif.cc | 4 +++- backends/json/json.cc | 3 ++- backends/rtlil/rtlil_backend.cc | 4 +++- backends/smt2/smtio.py | 1 + backends/verilog/verilog_backend.cc | 4 +++- kernel/driver.cc | 2 ++ kernel/yosys.cc | 1 + kernel/yosys_common.h | 1 + passes/cmds/internal_stats.cc | 3 ++- passes/cmds/stat.cc | 3 ++- passes/sat/sat.cc | 8 +++++--- 14 files changed, 31 insertions(+), 13 deletions(-) diff --git a/backends/aiger/aiger.cc b/backends/aiger/aiger.cc index f2cb5d9bc..2b10f7082 100644 --- a/backends/aiger/aiger.cc +++ b/backends/aiger/aiger.cc @@ -662,8 +662,8 @@ struct AigerWriter f << std::endl; } } - - f << stringf("c\nGenerated by %s\n", yosys_version_str); + if (yosys_write_versions) + f << stringf("c\nGenerated by %s\n", yosys_version_str); } void write_map(std::ostream &f, bool verbose_map, bool no_startoffset) diff --git a/backends/aiger/xaiger.cc b/backends/aiger/xaiger.cc index baf504ba2..200ae1a3b 100644 --- a/backends/aiger/xaiger.cc +++ b/backends/aiger/xaiger.cc @@ -671,7 +671,8 @@ 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); + if (yosys_write_versions) + f << stringf("Generated by %s\n", yosys_version_str); 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..01507c115 100644 --- a/backends/blif/blif.cc +++ b/backends/blif/blif.cc @@ -649,7 +649,8 @@ 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); + if (yosys_write_versions) + *f << stringf("# Generated by %s\n", yosys_version_str); std::vector mod_list; diff --git a/backends/edif/edif.cc b/backends/edif/edif.cc index d751a5996..1b67d0b4d 100644 --- a/backends/edif/edif.cc +++ b/backends/edif/edif.cc @@ -231,7 +231,9 @@ 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); + + if (yosys_write_versions) + *f << stringf(" (comment \"Generated by %s\")\n", yosys_version_str); *f << stringf(" (external LIB\n"); *f << stringf(" (edifLevel 0)\n"); diff --git a/backends/json/json.cc b/backends/json/json.cc index 749fe1fc3..7108f5f77 100644 --- a/backends/json/json.cc +++ b/backends/json/json.cc @@ -291,7 +291,8 @@ struct JsonWriter design->sort(); f << stringf("{\n"); - f << stringf(" \"creator\": %s,\n", get_string(yosys_version_str).c_str()); + if (yosys_write_versions) + f << stringf(" \"creator\": %s,\n", get_string(yosys_version_str).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..7a657d9e5 100644 --- a/backends/rtlil/rtlil_backend.cc +++ b/backends/rtlil/rtlil_backend.cc @@ -459,7 +459,9 @@ struct RTLILBackend : public Backend { design->sort(); log("Output filename: %s\n", filename.c_str()); - *f << stringf("# Generated by %s\n", yosys_version_str); + + if (yosys_write_versions) + *f << stringf("# Generated by %s\n", yosys_version_str); RTLIL_BACKEND::dump_design(*f, design, selected, true, false); } } RTLILBackend; diff --git a/backends/smt2/smtio.py b/backends/smt2/smtio.py index 2bc7daddc..ab25eee72 100644 --- a/backends/smt2/smtio.py +++ b/backends/smt2/smtio.py @@ -1289,6 +1289,7 @@ class MkVcd: assert t >= self.t if t != self.t: if self.t == -1: + # TODO if (yosys_write_versions) equivalent? print("$version Generated by Yosys-SMTBMC $end", file=self.f) print("$timescale 1ns $end", file=self.f) print("$var integer 32 t smt_step $end", file=self.f) diff --git a/backends/verilog/verilog_backend.cc b/backends/verilog/verilog_backend.cc index 2bc6ff3b8..98a8cc30d 100644 --- a/backends/verilog/verilog_backend.cc +++ b/backends/verilog/verilog_backend.cc @@ -2596,7 +2596,9 @@ struct VerilogBackend : public Backend { design->sort(); - *f << stringf("/* Generated by %s */\n", yosys_version_str); + if (yosys_write_versions) + *f << stringf("/* Generated by %s */\n", yosys_version_str); + for (auto module : design->modules()) { if (module->get_blackbox_attribute() != blackboxes) continue; diff --git a/kernel/driver.cc b/kernel/driver.cc index b7f0268db..e3a4cfa3e 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 Yosys version in command outputs") ("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); diff --git a/kernel/yosys.cc b/kernel/yosys.cc index 9b0bc92ce..5b89fc9b1 100644 --- a/kernel/yosys.cc +++ b/kernel/yosys.cc @@ -81,6 +81,7 @@ YOSYS_NAMESPACE_BEGIN int autoidx = 1; int yosys_xtrace = 0; +bool yosys_write_versions = true; RTLIL::Design *yosys_design = NULL; CellTypes yosys_celltypes; diff --git a/kernel/yosys_common.h b/kernel/yosys_common.h index 6fadf788f..16215fb76 100644 --- a/kernel/yosys_common.h +++ b/kernel/yosys_common.h @@ -274,6 +274,7 @@ inline int GetSize(RTLIL::Wire *wire); extern int autoidx; extern int yosys_xtrace; +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..bdf556e81 100644 --- a/passes/cmds/internal_stats.cc +++ b/passes/cmds/internal_stats.cc @@ -99,7 +99,8 @@ struct InternalStatsPass : public Pass { if (json_mode) { log("{\n"); - log(" \"creator\": %s,\n", json11::Json(yosys_version_str).dump().c_str()); + if (yosys_write_versions) + log(" \"creator\": %s,\n", json11::Json(yosys_version_str).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 63926c6e7..4c1331d35 100644 --- a/passes/cmds/stat.cc +++ b/passes/cmds/stat.cc @@ -444,7 +444,8 @@ struct StatPass : public Pass { if (json_mode) { log("{\n"); - log(" \"creator\": %s,\n", json11::Json(yosys_version_str).dump().c_str()); + if (yosys_write_versions) + log(" \"creator\": %s,\n", json11::Json(yosys_version_str).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..46cc00981 100644 --- a/passes/sat/sat.cc +++ b/passes/sat/sat.cc @@ -690,9 +690,11 @@ struct SatHelper fprintf(f, "$date\n"); fprintf(f, " %s\n", stime); fprintf(f, "$end\n"); - fprintf(f, "$version\n"); - fprintf(f, " Generated by %s\n", yosys_version_str); - fprintf(f, "$end\n"); + if (yosys_write_versions) { + fprintf(f, "$version\n"); + fprintf(f, " Generated by %s\n", yosys_version_str); + fprintf(f, "$end\n"); + } fprintf(f, "$comment\n"); fprintf(f, " Generated from SAT problem in module %s (declared at %s)\n", module->name.c_str(), module_fname.c_str()); From 93780bb8691ebaf81fa5320b93ffedbfdaf406d8 Mon Sep 17 00:00:00 2001 From: mikesinouye Date: Tue, 6 May 2025 09:57:03 -0700 Subject: [PATCH 2/7] Add to haslib.h which uses std::optional --- kernel/hashlib.h | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/hashlib.h b/kernel/hashlib.h index 6e3eb32a4..4144d701d 100644 --- a/kernel/hashlib.h +++ b/kernel/hashlib.h @@ -14,6 +14,7 @@ #include #include +#include #include #include #include From 90a2c92370e313d5b1443c925fa762381f78e5a6 Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Wed, 7 May 2025 11:34:23 +0200 Subject: [PATCH 3/7] driver: allow --no-version still write things like Generated by Yosys --- backends/aiger/aiger.cc | 5 ++--- backends/aiger/xaiger.cc | 3 +-- backends/blif/blif.cc | 3 +-- backends/btor/btor.cc | 4 ++-- backends/edif/edif.cc | 3 +-- backends/jny/jny.cc | 2 +- backends/json/json.cc | 3 +-- backends/rtlil/rtlil_backend.cc | 3 +-- backends/smt2/smt2.cc | 2 +- backends/smt2/smtio.py | 1 - backends/smv/smv.cc | 4 ++-- backends/spice/spice.cc | 2 +- backends/verilog/verilog_backend.cc | 3 +-- kernel/driver.cc | 6 +++--- kernel/register.cc | 2 +- kernel/yosys.cc | 9 ++++++++- kernel/yosys.h | 1 + passes/cmds/internal_stats.cc | 3 +-- passes/cmds/stat.cc | 3 +-- passes/sat/sat.cc | 8 +++----- passes/sat/sim.cc | 6 +++--- 21 files changed, 36 insertions(+), 40 deletions(-) diff --git a/backends/aiger/aiger.cc b/backends/aiger/aiger.cc index 2b10f7082..617d7d85f 100644 --- a/backends/aiger/aiger.cc +++ b/backends/aiger/aiger.cc @@ -662,8 +662,7 @@ struct AigerWriter f << std::endl; } } - if (yosys_write_versions) - 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 200ae1a3b..97dec40e4 100644 --- a/backends/aiger/xaiger.cc +++ b/backends/aiger/xaiger.cc @@ -671,8 +671,7 @@ struct XAigerWriter //f.write(reinterpret_cast(&buffer_size_be), sizeof(buffer_size_be)); //f.write(buffer_str.data(), buffer_str.size()); - if (yosys_write_versions) - 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 01507c115..5a5b9219f 100644 --- a/backends/blif/blif.cc +++ b/backends/blif/blif.cc @@ -649,8 +649,7 @@ struct BlifBackend : public Backend { if (module->get_bool_attribute(ID::top)) top_module_name = module->name.str(); - if (yosys_write_versions) - *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 1b67d0b4d..581590287 100644 --- a/backends/edif/edif.cc +++ b/backends/edif/edif.cc @@ -232,8 +232,7 @@ struct EdifBackend : public Backend { *f << stringf(" (edifLevel 0)\n"); *f << stringf(" (keywordMap (keywordLevel 0))\n"); - if (yosys_write_versions) - *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 7108f5f77..98e929dfa 100644 --- a/backends/json/json.cc +++ b/backends/json/json.cc @@ -291,8 +291,7 @@ struct JsonWriter design->sort(); f << stringf("{\n"); - if (yosys_write_versions) - 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 7a657d9e5..adde37356 100644 --- a/backends/rtlil/rtlil_backend.cc +++ b/backends/rtlil/rtlil_backend.cc @@ -460,8 +460,7 @@ struct RTLILBackend : public Backend { log("Output filename: %s\n", filename.c_str()); - if (yosys_write_versions) - *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/smt2/smtio.py b/backends/smt2/smtio.py index ab25eee72..2bc7daddc 100644 --- a/backends/smt2/smtio.py +++ b/backends/smt2/smtio.py @@ -1289,7 +1289,6 @@ class MkVcd: assert t >= self.t if t != self.t: if self.t == -1: - # TODO if (yosys_write_versions) equivalent? print("$version Generated by Yosys-SMTBMC $end", file=self.f) print("$timescale 1ns $end", file=self.f) print("$var integer 32 t smt_step $end", file=self.f) 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 98a8cc30d..19be9914e 100644 --- a/backends/verilog/verilog_backend.cc +++ b/backends/verilog/verilog_backend.cc @@ -2596,8 +2596,7 @@ struct VerilogBackend : public Backend { design->sort(); - if (yosys_write_versions) - *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) diff --git a/kernel/driver.cc b/kernel/driver.cc index e3a4cfa3e..9acc58dc4 100644 --- a/kernel/driver.cc +++ b/kernel/driver.cc @@ -252,7 +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 Yosys version in command outputs") + ("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. " \ @@ -693,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; @@ -733,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/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 5b89fc9b1..60b1bef4d 100644 --- a/kernel/yosys.cc +++ b/kernel/yosys.cc @@ -82,6 +82,13 @@ YOSYS_NAMESPACE_BEGIN int autoidx = 1; int yosys_xtrace = 0; 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; @@ -145,7 +152,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) 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/passes/cmds/internal_stats.cc b/passes/cmds/internal_stats.cc index bdf556e81..28822f237 100644 --- a/passes/cmds/internal_stats.cc +++ b/passes/cmds/internal_stats.cc @@ -99,8 +99,7 @@ struct InternalStatsPass : public Pass { if (json_mode) { log("{\n"); - if (yosys_write_versions) - 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 4c1331d35..6b93621f1 100644 --- a/passes/cmds/stat.cc +++ b/passes/cmds/stat.cc @@ -444,8 +444,7 @@ struct StatPass : public Pass { if (json_mode) { log("{\n"); - if (yosys_write_versions) - 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 46cc00981..0c2143fc9 100644 --- a/passes/sat/sat.cc +++ b/passes/sat/sat.cc @@ -690,11 +690,9 @@ struct SatHelper fprintf(f, "$date\n"); fprintf(f, " %s\n", stime); fprintf(f, "$end\n"); - if (yosys_write_versions) { - fprintf(f, "$version\n"); - fprintf(f, " Generated by %s\n", yosys_version_str); - fprintf(f, "$end\n"); - } + fprintf(f, "$version\n"); + 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", module->name.c_str(), module_fname.c_str()); diff --git a/passes/sat/sim.cc b/passes/sat/sim.cc index dd2f1d255..bb4eb3d82 100644 --- a/passes/sat/sim.cc +++ b/passes/sat/sim.cc @@ -2065,7 +2065,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"); @@ -2344,7 +2344,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); @@ -2412,7 +2412,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 From 55bd950af404741a97f595c9f40c2b5c871868fb Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 9 May 2025 00:27:47 +0000 Subject: [PATCH 4/7] Bump version --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 5986b1091..5692ba3c1 100644 --- a/Makefile +++ b/Makefile @@ -160,7 +160,7 @@ ifeq ($(OS), Haiku) CXXFLAGS += -D_DEFAULT_SOURCE endif -YOSYS_VER := 0.53+3 +YOSYS_VER := 0.53+11 YOSYS_MAJOR := $(shell echo $(YOSYS_VER) | cut -d'.' -f1) YOSYS_MINOR := $(shell echo $(YOSYS_VER) | cut -d'.' -f2 | cut -d'+' -f1) YOSYS_COMMIT := $(shell echo $(YOSYS_VER) | cut -d'+' -f2) From b05c0c70af50ac2efd1e8f4c8989468e024055a8 Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Fri, 9 May 2025 22:30:43 +0200 Subject: [PATCH 5/7] io: don't accept a directory when file expected --- kernel/io.cc | 15 ++++++++++++--- kernel/io.h | 17 +++++++++++++++++ kernel/yosys.cc | 10 +++++----- kernel/yosys_common.h | 17 ----------------- 4 files changed, 34 insertions(+), 25 deletions(-) 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/yosys.cc b/kernel/yosys.cc index 60b1bef4d..7d0d688fc 100644 --- a/kernel/yosys.cc +++ b/kernel/yosys.cc @@ -556,29 +556,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_common.h b/kernel/yosys_common.h index 16215fb76..e84676bc0 100644 --- a/kernel/yosys_common.h +++ b/kernel/yosys_common.h @@ -252,23 +252,6 @@ 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); From 2e9a194ce90e0f0021f5c23caaa09aac0c71107f Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Fri, 9 May 2025 21:23:34 +0200 Subject: [PATCH 6/7] gzip: reject uncompressing directories --- kernel/gzip.cc | 2 ++ 1 file changed, 2 insertions(+) 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()) From 6900818105f23cef4111a8ac0aa5e903b63577e8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 10 May 2025 00:22:55 +0000 Subject: [PATCH 7/7] Bump version --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 5692ba3c1..f733eed8f 100644 --- a/Makefile +++ b/Makefile @@ -160,7 +160,7 @@ ifeq ($(OS), Haiku) CXXFLAGS += -D_DEFAULT_SOURCE endif -YOSYS_VER := 0.53+11 +YOSYS_VER := 0.53+15 YOSYS_MAJOR := $(shell echo $(YOSYS_VER) | cut -d'.' -f1) YOSYS_MINOR := $(shell echo $(YOSYS_VER) | cut -d'.' -f2 | cut -d'+' -f1) YOSYS_COMMIT := $(shell echo $(YOSYS_VER) | cut -d'+' -f2)