mirror of https://github.com/YosysHQ/yosys.git
Added "design -push" and "design -pop"
This commit is contained in:
parent
b0e84802ec
commit
483c99fe46
|
@ -40,6 +40,10 @@ std::string rewrite_yosys_exe(std::string exe);
|
||||||
std::string get_share_file_name(std::string file);
|
std::string get_share_file_name(std::string file);
|
||||||
const char *create_prompt(RTLIL::Design *design, int recursion_counter);
|
const char *create_prompt(RTLIL::Design *design, int recursion_counter);
|
||||||
|
|
||||||
|
// from passes/cmds/design.cc
|
||||||
|
extern std::map<std::string, RTLIL::Design*> saved_designs;
|
||||||
|
extern std::vector<RTLIL::Design*> pushed_designs;
|
||||||
|
|
||||||
struct Pass
|
struct Pass
|
||||||
{
|
{
|
||||||
std::string pass_name, short_help;
|
std::string pass_name, short_help;
|
||||||
|
|
|
@ -22,13 +22,18 @@
|
||||||
#include "kernel/rtlil.h"
|
#include "kernel/rtlil.h"
|
||||||
#include "kernel/log.h"
|
#include "kernel/log.h"
|
||||||
|
|
||||||
|
std::map<std::string, RTLIL::Design*> saved_designs;
|
||||||
|
std::vector<RTLIL::Design*> pushed_designs;
|
||||||
|
|
||||||
struct DesignPass : public Pass {
|
struct DesignPass : public Pass {
|
||||||
DesignPass() : Pass("design", "save, restore and reset current design") { }
|
DesignPass() : Pass("design", "save, restore and reset current design") { }
|
||||||
std::map<std::string, RTLIL::Design*> saved_designs;
|
|
||||||
virtual ~DesignPass() {
|
virtual ~DesignPass() {
|
||||||
for (auto &it : saved_designs)
|
for (auto &it : saved_designs)
|
||||||
delete it.second;
|
delete it.second;
|
||||||
saved_designs.clear();
|
saved_designs.clear();
|
||||||
|
for (auto &it : pushed_designs)
|
||||||
|
delete it;
|
||||||
|
pushed_designs.clear();
|
||||||
}
|
}
|
||||||
virtual void help()
|
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("Save the current design under the given name and then clear the current design.\n");
|
||||||
log("\n");
|
log("\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(" design -load <name>\n");
|
||||||
log("\n");
|
log("\n");
|
||||||
log("Reset the current design and load the design previously saved under the given\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 got_mode = false;
|
||||||
bool reset_mode = false;
|
bool reset_mode = false;
|
||||||
|
bool push_mode = false;
|
||||||
|
bool pop_mode = false;
|
||||||
RTLIL::Design *copy_from_design = NULL, *copy_to_design = NULL;
|
RTLIL::Design *copy_from_design = NULL, *copy_to_design = NULL;
|
||||||
std::string save_name, load_name, as_name;
|
std::string save_name, load_name, as_name;
|
||||||
std::vector<RTLIL::Module*> copy_src_modules;
|
std::vector<RTLIL::Module*> copy_src_modules;
|
||||||
|
@ -83,6 +100,16 @@ struct DesignPass : public Pass {
|
||||||
reset_mode = true;
|
reset_mode = true;
|
||||||
continue;
|
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()) {
|
if (!got_mode && args[argidx] == "-save" && argidx+1 < args.size()) {
|
||||||
got_mode = true;
|
got_mode = true;
|
||||||
save_name = args[++argidx];
|
save_name = args[++argidx];
|
||||||
|
@ -151,7 +178,10 @@ struct DesignPass : public Pass {
|
||||||
extra_args(args, argidx, design, false);
|
extra_args(args, argidx, design, false);
|
||||||
|
|
||||||
if (!got_mode)
|
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 (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;
|
RTLIL::Design *design_copy = new RTLIL::Design;
|
||||||
|
|
||||||
|
@ -182,10 +212,14 @@ struct DesignPass : public Pass {
|
||||||
|
|
||||||
if (saved_designs.count(save_name))
|
if (saved_designs.count(save_name))
|
||||||
delete saved_designs.at(save_name);
|
delete saved_designs.at(save_name);
|
||||||
|
|
||||||
|
if (push_mode)
|
||||||
|
pushed_designs.push_back(design_copy);
|
||||||
|
else
|
||||||
saved_designs[save_name] = design_copy;
|
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)
|
for (auto &it : design->modules)
|
||||||
delete it.second;
|
delete it.second;
|
||||||
|
@ -198,9 +232,12 @@ struct DesignPass : public Pass {
|
||||||
design->selection_stack.push_back(RTLIL::Selection());
|
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)
|
for (auto &it : saved_design->modules)
|
||||||
design->modules[it.first] = it.second->clone();
|
design->modules[it.first] = it.second->clone();
|
||||||
|
|
Loading…
Reference in New Issue