summaryrefslogtreecommitdiff
path: root/passes
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2014-02-20 23:28:59 +0100
committerClifford Wolf <clifford@clifford.at>2014-02-20 23:28:59 +0100
commit483c99fe46d6b1cd35abddd38a629d30e13289b4 (patch)
treeac28b35d3cb6516c7f098740c005a0dd063b08cc /passes
parentb0e84802ecf3e224387317245786cd1437773a42 (diff)
Added "design -push" and "design -pop"
Diffstat (limited to 'passes')
-rw-r--r--passes/cmds/design.cc53
1 files changed, 45 insertions, 8 deletions
diff --git a/passes/cmds/design.cc b/passes/cmds/design.cc
index 80a6c073..7b8889d6 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<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()
{
@@ -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 <name>\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<RTLIL::Module*> 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;
-
+