From: Clifford Wolf Date: Thu, 20 Feb 2014 22:28:59 +0000 (+0100) Subject: Added "design -push" and "design -pop" X-Git-Tag: yosys-0.3.0~128 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=483c99fe46d6b1cd35abddd38a629d30e13289b4;p=yosys.git Added "design -push" and "design -pop" --- diff --git a/kernel/register.h b/kernel/register.h index 83e1059c6..b582f98c9 100644 --- a/kernel/register.h +++ b/kernel/register.h @@ -40,6 +40,10 @@ std::string rewrite_yosys_exe(std::string exe); std::string get_share_file_name(std::string file); const char *create_prompt(RTLIL::Design *design, int recursion_counter); +// from passes/cmds/design.cc +extern std::map saved_designs; +extern std::vector pushed_designs; + struct Pass { std::string pass_name, short_help; diff --git a/passes/cmds/design.cc b/passes/cmds/design.cc index 80a6c0731..7b8889d60 100644 --- a/passes/cmds/design.cc +++ b/passes/cmds/design.cc @@ -22,13 +22,18 @@ #include "kernel/rtlil.h" #include "kernel/log.h" +std::map saved_designs; +std::vector pushed_designs; + struct DesignPass : public Pass { DesignPass() : Pass("design", "save, restore and reset current design") { } - std::map saved_designs; virtual ~DesignPass() { for (auto &it : saved_designs) delete it.second; saved_designs.clear(); + for (auto &it : pushed_designs) + delete it; + pushed_designs.clear(); } virtual void help() { @@ -49,6 +54,16 @@ struct DesignPass : public Pass { log("Save the current design under the given name and then clear the current design.\n"); log("\n"); log("\n"); + log(" design -push\n"); + log("\n"); + log("Push the current design to the stack and then clear the current design.\n"); + log("\n"); + log("\n"); + log(" design -pop\n"); + log("\n"); + log("Reset the current design and pop the last design from the stack.\n"); + log("\n"); + log("\n"); log(" design -load \n"); log("\n"); log("Reset the current design and load the design previously saved under the given\n"); @@ -70,6 +85,8 @@ struct DesignPass : public Pass { { bool got_mode = false; bool reset_mode = false; + bool push_mode = false; + bool pop_mode = false; RTLIL::Design *copy_from_design = NULL, *copy_to_design = NULL; std::string save_name, load_name, as_name; std::vector copy_src_modules; @@ -83,6 +100,16 @@ struct DesignPass : public Pass { reset_mode = true; continue; } + if (!got_mode && args[argidx] == "-push") { + got_mode = true; + push_mode = true; + continue; + } + if (!got_mode && args[argidx] == "-pop") { + got_mode = true; + pop_mode = true; + continue; + } if (!got_mode && args[argidx] == "-save" && argidx+1 < args.size()) { got_mode = true; save_name = args[++argidx]; @@ -151,7 +178,10 @@ struct DesignPass : public Pass { extra_args(args, argidx, design, false); if (!got_mode) - cmd_error(args, argidx, "Missing mode argument (-reset, -save, -load, -copy-from, or -copy-to)."); + cmd_error(args, argidx, "Missing mode argument."); + + if (pop_mode && pushed_designs.empty()) + log_cmd_error("No pushed designs.\n"); if (copy_to_design != NULL) { @@ -169,7 +199,7 @@ struct DesignPass : public Pass { } } - if (!save_name.empty()) + if (!save_name.empty() || push_mode) { RTLIL::Design *design_copy = new RTLIL::Design; @@ -182,10 +212,14 @@ struct DesignPass : public Pass { if (saved_designs.count(save_name)) delete saved_designs.at(save_name); - saved_designs[save_name] = design_copy; + + if (push_mode) + pushed_designs.push_back(design_copy); + else + saved_designs[save_name] = design_copy; } - if (reset_mode || !load_name.empty()) + if (reset_mode || !load_name.empty() || push_mode || pop_mode) { for (auto &it : design->modules) delete it.second; @@ -198,9 +232,12 @@ struct DesignPass : public Pass { design->selection_stack.push_back(RTLIL::Selection()); } - if (!load_name.empty()) + if (!load_name.empty() || pop_mode) { - RTLIL::Design *saved_design = saved_designs.at(load_name); + RTLIL::Design *saved_design = pop_mode ? pushed_designs.back() : saved_designs.at(load_name); + + if (pop_mode) + pushed_designs.pop_back(); for (auto &it : saved_design->modules) design->modules[it.first] = it.second->clone(); @@ -211,4 +248,4 @@ struct DesignPass : public Pass { } } } DesignPass; - +