From: Clifford Wolf Date: Thu, 14 Mar 2013 12:02:10 +0000 (+0100) Subject: Added "select -write" command X-Git-Tag: yosys-0.2.0~724 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b0f386751c8c61b6929f0398c2b06915e312a8fd;p=yosys.git Added "select -write" command --- diff --git a/kernel/select.cc b/kernel/select.cc index 8e42b007a..725f296b0 100644 --- a/kernel/select.cc +++ b/kernel/select.cc @@ -555,7 +555,7 @@ struct SelectPass : public Pass { // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---| log("\n"); log(" select [ -add | -del | -set ] \n"); - log(" select [ -list | -count | -clear ]\n"); + log(" select [ -list | -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"); @@ -578,6 +578,9 @@ struct SelectPass : public Pass { log(" -list\n"); log(" list all objects in the current selection\n"); log("\n"); + log(" -write \n"); + log(" like -list but write the output to the specified file\n"); + log("\n"); log(" -count\n"); log(" count all objects in the current selection\n"); log("\n"); @@ -691,6 +694,7 @@ struct SelectPass : public Pass { bool list_mode = false; bool count_mode = false; bool got_module = false; + std::string write_file; std::string set_name; work_stack.clear(); @@ -715,6 +719,10 @@ struct SelectPass : public Pass { list_mode = true; continue; } + if (arg == "-write" && argidx+1 < args.size()) { + write_file = args[++argidx]; + continue; + } if (arg == "-count") { count_mode = true; continue; @@ -742,11 +750,11 @@ struct SelectPass : public Pass { if (add_mode && del_mode) log_cmd_error("Options -add and -del can not be combined.\n"); - if ((list_mode || count_mode) && (add_mode || del_mode)) - log_cmd_error("Options -list and -count can not be combined with -add or -del.\n"); + if ((list_mode || !write_file.empty() || count_mode) && (add_mode || del_mode)) + log_cmd_error("Options -list, -write and -count can not be combined with -add or -del.\n"); - if (!set_name.empty() && (list_mode || count_mode || add_mode || del_mode)) - log_cmd_error("Option -set can not be combined with -list, -count, -add or -del.\n"); + if (!set_name.empty() && (list_mode || !write_file.empty() || count_mode || add_mode || del_mode)) + log_cmd_error("Option -set can not be combined with -list, -write, -count, -add or -del.\n"); if (work_stack.size() == 0 && got_module) { RTLIL::Selection sel; @@ -768,10 +776,16 @@ struct SelectPass : public Pass { return; } - if (list_mode || count_mode) + if (list_mode || count_mode || !write_file.empty()) { - #define LOG_OBJECT(...) do { if (list_mode) log(__VA_ARGS__); total_count++; } while (0) + #define LOG_OBJECT(...) do { if (list_mode) log(__VA_ARGS__); if (f != NULL) fprintf(f, __VA_ARGS__); total_count++; } while (0) int total_count = 0; + FILE *f = NULL; + if (!write_file.empty()) { + f = fopen(write_file.c_str(), "w"); + if (f == NULL) + log_error("Can't open '%s' for writing: %s\n", write_file.c_str(), strerror(errno)); + } RTLIL::Selection *sel = &design->selection_stack.back(); if (work_stack.size() > 0) sel = &work_stack.back(); @@ -797,6 +811,8 @@ struct SelectPass : public Pass { } if (count_mode) log("%d objects.\n", total_count); + if (f != NULL) + fclose(f); #undef LOG_OBJECT return; }