#include "kernel/rtlil.h"
#include "kernel/log.h"
+std::map<std::string, RTLIL::Design*> saved_designs;
+std::vector<RTLIL::Design*> pushed_designs;
+
struct DesignPass : public Pass {
DesignPass() : Pass("design", "save, restore and reset current design") { }
- std::map<std::string, RTLIL::Design*> 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()
{
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 <name>\n");
log("\n");
log("Reset the current design and load the design previously saved under the given\n");
{
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<RTLIL::Module*> copy_src_modules;
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];
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)
{
}
}
- if (!save_name.empty())
+ if (!save_name.empty() || push_mode)
{
RTLIL::Design *design_copy = new RTLIL::Design;
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;
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();
}
}
} DesignPass;
-
+