From 37e61b993a3bea45bff5dd6f2c5b6239fdff7694 Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Thu, 17 Oct 2024 22:21:50 +0200 Subject: [PATCH 1/8] yosys: fix pyosys initialization segfault --- kernel/yosys.cc | 13 +++++++------ setup.py | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/kernel/yosys.cc b/kernel/yosys.cc index 374b07d06..774c7f37d 100644 --- a/kernel/yosys.cc +++ b/kernel/yosys.cc @@ -547,12 +547,6 @@ void yosys_setup() if(already_setup) return; already_setup = true; - init_share_dirname(); - init_abc_executable_name(); - -#define X(_id) RTLIL::ID::_id = "\\" # _id; -#include "kernel/constids.inc" -#undef X #ifdef WITH_PYTHON // With Python 3.12, calling PyImport_AppendInittab on an already @@ -566,6 +560,13 @@ void yosys_setup() } #endif + init_share_dirname(); + init_abc_executable_name(); + +#define X(_id) RTLIL::ID::_id = "\\" # _id; +#include "kernel/constids.inc" +#undef X + Pass::init_register(); yosys_design = new RTLIL::Design; yosys_celltypes.setup(); diff --git a/setup.py b/setup.py index b3a6a9280..b39b579e0 100644 --- a/setup.py +++ b/setup.py @@ -76,7 +76,7 @@ class libyosys_so_ext(Extension): # yosys-abc yosys_abc_target = os.path.join(pyosys_path, "yosys-abc") shutil.copy("yosys-abc", yosys_abc_target) - bext.spawn(["strip", "-S", "yosys-abc"]) + bext.spawn(["strip", "-S", yosys_abc_target]) # share directory share_target = os.path.join(pyosys_path, "share") From dbfca1bdff2b4213a08cdc28e5503b254f2d20a0 Mon Sep 17 00:00:00 2001 From: George Rennie Date: Fri, 1 Nov 2024 16:57:10 +0100 Subject: [PATCH 2/8] frontends/ast.cc: special-case zero width strings as "\0" * Fixes #4696 --- frontends/ast/ast.cc | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/frontends/ast/ast.cc b/frontends/ast/ast.cc index 935273c9f..c5bf5b4ad 100644 --- a/frontends/ast/ast.cc +++ b/frontends/ast/ast.cc @@ -877,16 +877,25 @@ AstNode *AstNode::mkconst_str(const std::vector &v) // create an AST node for a constant (using a string as value) AstNode *AstNode::mkconst_str(const std::string &str) { - std::vector data; - data.reserve(str.size() * 8); - for (size_t i = 0; i < str.size(); i++) { - unsigned char ch = str[str.size() - i - 1]; - for (int j = 0; j < 8; j++) { - data.push_back((ch & 1) ? State::S1 : State::S0); - ch = ch >> 1; + AstNode *node; + + // LRM 1364-2005 5.2.3.3 The empty string literal ("") shall be considered + // equivalent to the ASCII NUL ("\0") + if (str.empty()) { + node = AstNode::mkconst_int(0, false, 8); + } else { + std::vector data; + data.reserve(str.size() * 8); + for (size_t i = 0; i < str.size(); i++) { + unsigned char ch = str[str.size() - i - 1]; + for (int j = 0; j < 8; j++) { + data.push_back((ch & 1) ? State::S1 : State::S0); + ch = ch >> 1; + } } + node = AstNode::mkconst_bits(data, false); } - AstNode *node = AstNode::mkconst_bits(data, false); + node->is_string = true; node->str = str; return node; From 7aa3fdab806c7df29345da5f0f2319edca35ca28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Povi=C5=A1er?= Date: Wed, 16 Oct 2024 11:43:26 +0200 Subject: [PATCH 3/8] select: Add `-list-mod` option --- passes/cmds/select.cc | 12 +++++++++--- tests/select/list_mod.ys | 13 +++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 tests/select/list_mod.ys diff --git a/passes/cmds/select.cc b/passes/cmds/select.cc index ff72724ae..aec4c964b 100644 --- a/passes/cmds/select.cc +++ b/passes/cmds/select.cc @@ -1041,7 +1041,7 @@ struct SelectPass : public Pass { log(" select [ -add | -del | -set ] {-read | }\n"); log(" select [ -unset ]\n"); log(" select [ ] {-read | }\n"); - log(" select [ -list | -write | -count | -clear ]\n"); + log(" select [ -list | -list-mod | -write | -count | -clear ]\n"); log(" select -module \n"); log("\n"); log("Most commands use the list of currently selected objects to determine which part\n"); @@ -1277,6 +1277,7 @@ struct SelectPass : public Pass { bool clear_mode = false; bool none_mode = false; bool list_mode = false; + bool list_mod_mode = false; bool count_mode = false; bool got_module = false; bool assert_none = false; @@ -1338,6 +1339,11 @@ struct SelectPass : public Pass { list_mode = true; continue; } + if (arg == "-list-mod") { + list_mode = true; + list_mod_mode = true; + continue; + } if (arg == "-write" && argidx+1 < args.size()) { write_file = args[++argidx]; continue; @@ -1416,7 +1422,7 @@ struct SelectPass : public Pass { log_cmd_error("Options %s can not be combined.\n", common_flagset); if ((list_mode || !write_file.empty() || count_mode) && common_flagset_tally) - log_cmd_error("Options -list, -write and -count can not be combined with %s.\n", common_flagset); + log_cmd_error("Options -list, -list-mod, -write and -count can not be combined with %s.\n", common_flagset); if (!set_name.empty() && (list_mode || !write_file.empty() || count_mode || !unset_name.empty() || common_flagset_tally)) log_cmd_error("Option -set can not be combined with -list, -write, -count, -unset, %s.\n", common_flagset); @@ -1467,7 +1473,7 @@ struct SelectPass : public Pass { { if (sel->selected_whole_module(mod->name) && list_mode) log("%s\n", id2cstr(mod->name)); - if (sel->selected_module(mod->name)) { + if (sel->selected_module(mod->name) && !list_mod_mode) { for (auto wire : mod->wires()) if (sel->selected_member(mod->name, wire->name)) LOG_OBJECT("%s/%s\n", id2cstr(mod->name), id2cstr(wire->name)) diff --git a/tests/select/list_mod.ys b/tests/select/list_mod.ys new file mode 100644 index 000000000..c8a3ac8b5 --- /dev/null +++ b/tests/select/list_mod.ys @@ -0,0 +1,13 @@ +read_verilog < Date: Mon, 4 Nov 2024 13:16:40 +0100 Subject: [PATCH 4/8] logger: Adjust print --- passes/cmds/logger.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/passes/cmds/logger.cc b/passes/cmds/logger.cc index 9e45e86af..3277e1608 100644 --- a/passes/cmds/logger.cc +++ b/passes/cmds/logger.cc @@ -162,7 +162,8 @@ struct LoggerPass : public Pass { log_cmd_error("Number of expected messages must be higher then 0 !\n"); if (type=="error" && count!=1) log_cmd_error("Expected error message occurrences must be 1 !\n"); - log("Added regex '%s' for warnings to expected %s list.\n", pattern.c_str(), type.c_str()); + log("Added regex '%s' to expected %s messages list.\n", + pattern.c_str(), type.c_str()); try { if (type == "error") log_expect_error[pattern] = LogExpectedItem(YS_REGEX_COMPILE(pattern), count); From c9ed6d8dcf2ae1612422bd34c37441c926d5bddc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Povi=C5=A1er?= Date: Wed, 16 Oct 2024 11:43:54 +0200 Subject: [PATCH 5/8] cellmatch: Rename `-lut_attrs` to `-derive_luts`; document option --- passes/techmap/cellmatch.cc | 18 +++++++++++------- tests/techmap/cellmatch.ys | 8 ++++++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/passes/techmap/cellmatch.cc b/passes/techmap/cellmatch.cc index 235599972..48b1eebf7 100644 --- a/passes/techmap/cellmatch.cc +++ b/passes/techmap/cellmatch.cc @@ -155,18 +155,22 @@ struct CellmatchPass : Pass { log("equivalent as long as their truth tables are identical upto a permutation of\n"); log("inputs and outputs. The supported number of inputs is limited to 6.\n"); log("\n"); + log(" cellmatch -derive_luts [module selection]\n"); + log("\n"); + log("For every port in each selected module, characterize its combinational\n"); + log("function with a 'lut' attribute if possible.\n"); + log("\n"); } void execute(std::vector args, RTLIL::Design *d) override { log_header(d, "Executing CELLMATCH pass. (match cells)\n"); size_t argidx; - bool lut_attrs = false; + bool derive_luts = false; Design *lib = NULL; for (argidx = 1; argidx < args.size(); argidx++) { - if (args[argidx] == "-lut_attrs") { - // an undocumented debugging option - lut_attrs = true; + if (args[argidx] == "-derive_luts") { + derive_luts = true; } else if (args[argidx] == "-lib" && argidx + 1 < args.size()) { if (!saved_designs.count(args[++argidx])) log_cmd_error("No design '%s' found!\n", args[argidx].c_str()); @@ -177,8 +181,8 @@ struct CellmatchPass : Pass { } extra_args(args, argidx, d); - if (!lib && !lut_attrs) - log_cmd_error("Missing required -lib option.\n"); + if (!lib && !derive_luts) + log_cmd_error("Missing required -lib or -derive_luts option.\n"); struct Target { Module *module; @@ -218,7 +222,7 @@ struct CellmatchPass : Pass { SigSpec inputs = module_inputs(m); SigSpec outputs = module_outputs(m); - if (lut_attrs) { + if (derive_luts) { int no = 0; for (auto bit : outputs) { log_assert(bit.is_wire()); diff --git a/tests/techmap/cellmatch.ys b/tests/techmap/cellmatch.ys index bea2f598d..05368fb3b 100644 --- a/tests/techmap/cellmatch.ys +++ b/tests/techmap/cellmatch.ys @@ -77,3 +77,11 @@ opt_clean equiv_induct equiv equiv_status -assert +design -reset +design -load gatelib +cellmatch -derive_luts +select -assert-any bufgate/w:Y a:lut=2'b10 %i +select -assert-any reducegate/w:X a:lut=8'b10000000 %i +select -assert-any reducegate/w:Y a:lut=8'b11111110 %i +select -assert-any fagate/w:X a:lut=8'b10010110 %i +select -assert-any fagate/w:Y a:lut=8'b11101000 %i From cbe73c9047f36e9c11fc6af8b640f6e329f8bb7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Povi=C5=A1er?= Date: Sat, 19 Oct 2024 01:17:43 +0200 Subject: [PATCH 6/8] cellmatch: Visit whiteboxes for `-derive_luts` --- passes/techmap/cellmatch.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/passes/techmap/cellmatch.cc b/passes/techmap/cellmatch.cc index 48b1eebf7..a2a4c4b2c 100644 --- a/passes/techmap/cellmatch.cc +++ b/passes/techmap/cellmatch.cc @@ -214,7 +214,7 @@ struct CellmatchPass : Pass { r.first->second = new Design; Design *map_design = r.first->second; - for (auto m : d->selected_whole_modules_warn()) { + for (auto m : d->selected_whole_modules_warn(/* visit whiteboxes */derive_luts)) { std::vector luts; if (!derive_module_luts(m, luts)) continue; From d752ca48472d83fc589bb6424d9e2f1d09b3903f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Povi=C5=A1er?= Date: Mon, 4 Nov 2024 16:26:46 +0100 Subject: [PATCH 7/8] Fix test after option change --- tests/select/mod-attribute.ys | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/select/mod-attribute.ys b/tests/select/mod-attribute.ys index 4d3704378..8b0ad8506 100644 --- a/tests/select/mod-attribute.ys +++ b/tests/select/mod-attribute.ys @@ -41,7 +41,7 @@ module \top end EOT -cellmatch -lut_attrs * +cellmatch -derive_luts * select -set buffers a:lut=2'b10 %m select -set inverters a:lut=2'b01 %m From 2999f5589caa4862f9299a4fc568112bc2945d94 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 5 Nov 2024 00:20:31 +0000 Subject: [PATCH 8/8] Bump version --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a56ca172f..bb81c4658 100644 --- a/Makefile +++ b/Makefile @@ -154,7 +154,7 @@ ifeq ($(OS), Haiku) CXXFLAGS += -D_DEFAULT_SOURCE endif -YOSYS_VER := 0.46+135 +YOSYS_VER := 0.46+147 # Note: We arrange for .gitcommit to contain the (short) commit hash in # tarballs generated with git-archive(1) using .gitattributes. The git repo