From 254d38ca671c0933687034f317be07a5f3395e10 Mon Sep 17 00:00:00 2001 From: Eddie Hung Date: Tue, 14 Apr 2020 10:58:42 -0700 Subject: [PATCH] select: add select -unset option --- CHANGELOG | 1 + passes/cmds/select.cc | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index f9e420a09..df8e14b26 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -65,6 +65,7 @@ Yosys 0.9 .. Yosys 0.9-dev - Added "logger" pass - Removed "dffsr2dff" (use opt_rmdff instead) - Added "design -delete" + - Added "select -unset" Yosys 0.8 .. Yosys 0.9 ---------------------- diff --git a/passes/cmds/select.cc b/passes/cmds/select.cc index b64b077e4..c04ff438a 100644 --- a/passes/cmds/select.cc +++ b/passes/cmds/select.cc @@ -1007,6 +1007,7 @@ struct SelectPass : public Pass { // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---| log("\n"); log(" select [ -add | -del | -set ] {-read | }\n"); + log(" select [ -unset ]\n"); log(" select [ ] {-read | }\n"); log(" select [ -list | -write | -count | -clear ]\n"); log(" select -module \n"); @@ -1029,6 +1030,10 @@ struct SelectPass : public Pass { log(" under the given name (see @ below). to save the current selection,\n"); log(" use \"select -set %%\"\n"); log("\n"); + log(" -unset \n"); + log(" do not modify the current selection. instead remove a previously saved\n"); + log(" selection under the given name (see @ below)."); + log("\n"); log(" -assert-none\n"); log(" do not modify the current selection. instead assert that the given\n"); log(" selection is empty. i.e. produce an error if any object matching the\n"); @@ -1238,7 +1243,7 @@ struct SelectPass : public Pass { int assert_max = -1; int assert_min = -1; std::string write_file, read_file; - std::string set_name, sel_str; + std::string set_name, unset_name, sel_str; work_stack.clear(); @@ -1310,6 +1315,10 @@ struct SelectPass : public Pass { set_name = RTLIL::escape_id(args[++argidx]); continue; } + if (arg == "-unset" && argidx+1 < args.size()) { + unset_name = RTLIL::escape_id(args[++argidx]); + continue; + } if (arg.size() > 0 && arg[0] == '-') log_cmd_error("Unknown option %s.\n", arg.c_str()); bool disable_empty_warning = count_mode || assert_none || assert_any || (assert_count != -1) || (assert_max != -1) || (assert_min != -1); @@ -1358,8 +1367,11 @@ struct SelectPass : public Pass { if ((list_mode || !write_file.empty() || count_mode) && (add_mode || del_mode || assert_none || assert_any || assert_count >= 0 || assert_max >= 0 || assert_min >= 0)) log_cmd_error("Options -list, -write and -count can not be combined with -add, -del, -assert-none, -assert-any, assert-count, -assert-max, or -assert-min.\n"); - if (!set_name.empty() && (list_mode || !write_file.empty() || count_mode || add_mode || del_mode || assert_none || assert_any || assert_count >= 0 || assert_max >= 0 || assert_min >= 0)) - log_cmd_error("Option -set can not be combined with -list, -write, -count, -add, -del, -assert-none, -assert-any, -assert-count, -assert-max, or -assert-min.\n"); + if (!set_name.empty() && (list_mode || !write_file.empty() || count_mode || add_mode || !unset_name.empty() || del_mode || assert_none || assert_any || assert_count >= 0 || assert_max >= 0 || assert_min >= 0)) + log_cmd_error("Option -set can not be combined with -list, -write, -count, -add, -del, -unset, -assert-none, -assert-any, -assert-count, -assert-max, or -assert-min.\n"); + + if (!unset_name.empty() && (list_mode || !write_file.empty() || count_mode || add_mode || !set_name.empty() || del_mode || assert_none || assert_any || assert_count >= 0 || assert_max >= 0 || assert_min >= 0)) + log_cmd_error("Option -unset can not be combined with -list, -write, -count, -add, -del, -set, -assert-none, -assert-any, -assert-count, -assert-max, or -assert-min.\n"); if (work_stack.size() == 0 && got_module) { RTLIL::Selection sel; @@ -1527,6 +1539,13 @@ struct SelectPass : public Pass { return; } + if (!unset_name.empty()) + { + if (!design->selection_vars.erase(unset_name)) + log_error("Selection '%s' does not exist!\n", unset_name.c_str()); + return; + } + if (work_stack.size() == 0) { RTLIL::Selection &sel = design->selection_stack.back(); if (sel.full_selection) -- 2.30.2