mirror of
https://github.com/YosysHQ/yosys
synced 2025-04-23 09:05:32 +00:00
Merge pull request #943 from YosysHQ/clifford/whitebox
[WIP] Add "whitebox" attribute, add "read_verilog -wb"
This commit is contained in:
commit
f84a84e3f1
27 changed files with 157 additions and 55 deletions
|
@ -71,7 +71,7 @@ static void add_wire(RTLIL::Design *design, RTLIL::Module *module, std::string n
|
|||
RTLIL::Module *mod = design->modules_.at(it.second->type);
|
||||
if (!design->selected_whole_module(mod->name))
|
||||
continue;
|
||||
if (mod->get_bool_attribute("\\blackbox"))
|
||||
if (mod->get_blackbox_attribute())
|
||||
continue;
|
||||
if (it.second->hasPort(name))
|
||||
continue;
|
||||
|
|
|
@ -128,7 +128,7 @@ struct BugpointPass : public Pass {
|
|||
{
|
||||
for (auto &it : design_copy->modules_)
|
||||
{
|
||||
if (it.second->get_bool_attribute("\\blackbox"))
|
||||
if (it.second->get_blackbox_attribute())
|
||||
continue;
|
||||
|
||||
if (index++ == seed)
|
||||
|
@ -143,7 +143,7 @@ struct BugpointPass : public Pass {
|
|||
{
|
||||
for (auto mod : design_copy->modules())
|
||||
{
|
||||
if (mod->get_bool_attribute("\\blackbox"))
|
||||
if (mod->get_blackbox_attribute())
|
||||
continue;
|
||||
|
||||
for (auto wire : mod->wires())
|
||||
|
@ -168,7 +168,7 @@ struct BugpointPass : public Pass {
|
|||
{
|
||||
for (auto mod : design_copy->modules())
|
||||
{
|
||||
if (mod->get_bool_attribute("\\blackbox"))
|
||||
if (mod->get_blackbox_attribute())
|
||||
continue;
|
||||
|
||||
for (auto &it : mod->cells_)
|
||||
|
@ -186,7 +186,7 @@ struct BugpointPass : public Pass {
|
|||
{
|
||||
for (auto mod : design_copy->modules())
|
||||
{
|
||||
if (mod->get_bool_attribute("\\blackbox"))
|
||||
if (mod->get_blackbox_attribute())
|
||||
continue;
|
||||
|
||||
for (auto cell : mod->cells())
|
||||
|
|
|
@ -128,6 +128,45 @@ struct SetattrPass : public Pass {
|
|||
}
|
||||
} SetattrPass;
|
||||
|
||||
struct WbflipPass : public Pass {
|
||||
WbflipPass() : Pass("wbflip", "flip the whitebox attribute") { }
|
||||
void help() YS_OVERRIDE
|
||||
{
|
||||
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
|
||||
log("\n");
|
||||
log(" wbflip [selection]\n");
|
||||
log("\n");
|
||||
log("Flip the whitebox attribute on selected cells. I.e. if it's set, unset it, and\n");
|
||||
log("vice-versa. Blackbox cells are not effected by this command.\n");
|
||||
log("\n");
|
||||
}
|
||||
void execute(std::vector<std::string> args, RTLIL::Design *design) YS_OVERRIDE
|
||||
{
|
||||
size_t argidx;
|
||||
for (argidx = 1; argidx < args.size(); argidx++)
|
||||
{
|
||||
std::string arg = args[argidx];
|
||||
// if (arg == "-mod") {
|
||||
// flag_mod = true;
|
||||
// continue;
|
||||
// }
|
||||
break;
|
||||
}
|
||||
extra_args(args, argidx, design);
|
||||
|
||||
for (Module *module : design->modules())
|
||||
{
|
||||
if (!design->selected(module))
|
||||
continue;
|
||||
|
||||
if (module->get_bool_attribute("\\blackbox"))
|
||||
continue;
|
||||
|
||||
module->set_bool_attribute("\\whitebox", !module->get_bool_attribute("\\whitebox"));
|
||||
}
|
||||
}
|
||||
} WbflipPass;
|
||||
|
||||
struct SetparamPass : public Pass {
|
||||
SetparamPass() : Pass("setparam", "set/unset parameters on objects") { }
|
||||
void help() YS_OVERRIDE
|
||||
|
|
|
@ -574,7 +574,7 @@ struct ShowWorker
|
|||
if (!design->selected_module(module->name))
|
||||
continue;
|
||||
if (design->selected_whole_module(module->name)) {
|
||||
if (module->get_bool_attribute("\\blackbox")) {
|
||||
if (module->get_blackbox_attribute()) {
|
||||
// log("Skipping blackbox module %s.\n", id2cstr(module->name));
|
||||
continue;
|
||||
} else
|
||||
|
@ -790,7 +790,7 @@ struct ShowPass : public Pass {
|
|||
if (format != "ps" && format != "dot") {
|
||||
int modcount = 0;
|
||||
for (auto &mod_it : design->modules_) {
|
||||
if (mod_it.second->get_bool_attribute("\\blackbox"))
|
||||
if (mod_it.second->get_blackbox_attribute())
|
||||
continue;
|
||||
if (mod_it.second->cells_.empty() && mod_it.second->connections().empty())
|
||||
continue;
|
||||
|
|
|
@ -134,7 +134,7 @@ struct EquivOptPass:public ScriptPass
|
|||
opts = " -map <filename> ...";
|
||||
else
|
||||
opts = techmap_opts;
|
||||
run("techmap -D EQUIV -autoproc" + opts);
|
||||
run("techmap -wb -D EQUIV -autoproc" + opts);
|
||||
}
|
||||
|
||||
if (check_label("prove")) {
|
||||
|
|
|
@ -346,9 +346,9 @@ bool expand_module(RTLIL::Design *design, RTLIL::Module *module, bool flag_check
|
|||
}
|
||||
RTLIL::Module *mod = design->modules_[cell->type];
|
||||
|
||||
if (design->modules_.at(cell->type)->get_bool_attribute("\\blackbox")) {
|
||||
if (design->modules_.at(cell->type)->get_blackbox_attribute()) {
|
||||
if (flag_simcheck)
|
||||
log_error("Module `%s' referenced in module `%s' in cell `%s' is a blackbox module.\n",
|
||||
log_error("Module `%s' referenced in module `%s' in cell `%s' is a blackbox/whitebox module.\n",
|
||||
cell->type.c_str(), module->name.c_str(), cell->name.c_str());
|
||||
continue;
|
||||
}
|
||||
|
@ -451,7 +451,7 @@ void hierarchy_worker(RTLIL::Design *design, std::set<RTLIL::Module*, IdString::
|
|||
|
||||
if (indent == 0)
|
||||
log("Top module: %s\n", mod->name.c_str());
|
||||
else if (!mod->get_bool_attribute("\\blackbox"))
|
||||
else if (!mod->get_blackbox_attribute())
|
||||
log("Used module: %*s%s\n", indent, "", mod->name.c_str());
|
||||
used.insert(mod);
|
||||
|
||||
|
@ -491,7 +491,7 @@ void hierarchy_clean(RTLIL::Design *design, RTLIL::Module *top, bool purge_lib)
|
|||
|
||||
int del_counter = 0;
|
||||
for (auto mod : del_modules) {
|
||||
if (!purge_lib && mod->get_bool_attribute("\\blackbox"))
|
||||
if (!purge_lib && mod->get_blackbox_attribute())
|
||||
continue;
|
||||
log("Removing unused module `%s'.\n", mod->name.c_str());
|
||||
design->modules_.erase(mod->name);
|
||||
|
@ -910,7 +910,7 @@ struct HierarchyPass : public Pass {
|
|||
if (m == nullptr)
|
||||
continue;
|
||||
|
||||
if (m->get_bool_attribute("\\blackbox") && !cell->parameters.empty() && m->get_bool_attribute("\\dynports")) {
|
||||
if (m->get_blackbox_attribute() && !cell->parameters.empty() && m->get_bool_attribute("\\dynports")) {
|
||||
IdString new_m_name = m->derive(design, cell->parameters, true);
|
||||
if (new_m_name.empty())
|
||||
continue;
|
||||
|
|
|
@ -75,7 +75,7 @@ struct UniquifyPass : public Pass {
|
|||
if (tmod == nullptr)
|
||||
continue;
|
||||
|
||||
if (tmod->get_bool_attribute("\\blackbox"))
|
||||
if (tmod->get_blackbox_attribute())
|
||||
continue;
|
||||
|
||||
if (tmod->get_bool_attribute("\\unique") && newname == tmod->name)
|
||||
|
|
|
@ -254,7 +254,7 @@ void create_miter_equiv(struct Pass *that, std::vector<std::string> args, RTLIL:
|
|||
|
||||
if (flag_flatten) {
|
||||
log_push();
|
||||
Pass::call_on_module(design, miter_module, "flatten; opt_expr -keepdc -undriven;;");
|
||||
Pass::call_on_module(design, miter_module, "flatten -wb; opt_expr -keepdc -undriven;;");
|
||||
log_pop();
|
||||
}
|
||||
}
|
||||
|
@ -308,7 +308,7 @@ void create_miter_assert(struct Pass *that, std::vector<std::string> args, RTLIL
|
|||
|
||||
if (flag_flatten) {
|
||||
log_push();
|
||||
Pass::call_on_module(design, module, "flatten;;");
|
||||
Pass::call_on_module(design, module, "flatten -wb;;");
|
||||
log_pop();
|
||||
}
|
||||
|
||||
|
@ -385,7 +385,7 @@ struct MiterPass : public Pass {
|
|||
log(" also create an 'assert' cell that checks if trigger is always low.\n");
|
||||
log("\n");
|
||||
log(" -flatten\n");
|
||||
log(" call 'flatten; opt_expr -keepdc -undriven;;' on the miter circuit.\n");
|
||||
log(" call 'flatten -wb; opt_expr -keepdc -undriven;;' on the miter circuit.\n");
|
||||
log("\n");
|
||||
log("\n");
|
||||
log(" miter -assert [options] module [miter_name]\n");
|
||||
|
@ -399,7 +399,7 @@ struct MiterPass : public Pass {
|
|||
log(" keep module output ports.\n");
|
||||
log("\n");
|
||||
log(" -flatten\n");
|
||||
log(" call 'flatten; opt_expr -keepdc -undriven;;' on the miter circuit.\n");
|
||||
log(" call 'flatten -wb; opt_expr -keepdc -undriven;;' on the miter circuit.\n");
|
||||
log("\n");
|
||||
}
|
||||
void execute(std::vector<std::string> args, RTLIL::Design *design) YS_OVERRIDE
|
||||
|
|
|
@ -664,7 +664,7 @@ struct DfflibmapPass : public Pass {
|
|||
logmap_all();
|
||||
|
||||
for (auto &it : design->modules_)
|
||||
if (design->selected(it.second) && !it.second->get_bool_attribute("\\blackbox"))
|
||||
if (design->selected(it.second) && !it.second->get_blackbox_attribute())
|
||||
dfflibmap(design, it.second, prepare_mode);
|
||||
|
||||
cell_mappings.clear();
|
||||
|
|
|
@ -599,7 +599,7 @@ struct SimplemapPass : public Pass {
|
|||
simplemap_get_mappers(mappers);
|
||||
|
||||
for (auto mod : design->modules()) {
|
||||
if (!design->selected(mod))
|
||||
if (!design->selected(mod) || mod->get_blackbox_attribute())
|
||||
continue;
|
||||
std::vector<RTLIL::Cell*> cells = mod->cells();
|
||||
for (auto cell : cells) {
|
||||
|
|
|
@ -84,6 +84,7 @@ struct TechmapWorker
|
|||
bool flatten_mode;
|
||||
bool recursive_mode;
|
||||
bool autoproc_mode;
|
||||
bool ignore_wb;
|
||||
|
||||
TechmapWorker()
|
||||
{
|
||||
|
@ -92,6 +93,7 @@ struct TechmapWorker
|
|||
flatten_mode = false;
|
||||
recursive_mode = false;
|
||||
autoproc_mode = false;
|
||||
ignore_wb = false;
|
||||
}
|
||||
|
||||
std::string constmap_tpl_name(SigMap &sigmap, RTLIL::Module *tpl, RTLIL::Cell *cell, bool verbose)
|
||||
|
@ -383,7 +385,7 @@ struct TechmapWorker
|
|||
{
|
||||
std::string mapmsg_prefix = in_recursion ? "Recursively mapping" : "Mapping";
|
||||
|
||||
if (!design->selected(module))
|
||||
if (!design->selected(module) || module->get_blackbox_attribute(ignore_wb))
|
||||
return false;
|
||||
|
||||
bool log_continue = false;
|
||||
|
@ -472,7 +474,7 @@ struct TechmapWorker
|
|||
RTLIL::Module *tpl = map->modules_[tpl_name];
|
||||
std::map<RTLIL::IdString, RTLIL::Const> parameters(cell->parameters.begin(), cell->parameters.end());
|
||||
|
||||
if (tpl->get_bool_attribute("\\blackbox"))
|
||||
if (tpl->get_blackbox_attribute(ignore_wb))
|
||||
continue;
|
||||
|
||||
if (!flatten_mode)
|
||||
|
@ -925,6 +927,9 @@ struct TechmapPass : public Pass {
|
|||
log(" -autoproc\n");
|
||||
log(" Automatically call \"proc\" on implementations that contain processes.\n");
|
||||
log("\n");
|
||||
log(" -wb\n");
|
||||
log(" Ignore the 'whitebox' attribute on cell implementations.\n");
|
||||
log("\n");
|
||||
log(" -assert\n");
|
||||
log(" this option will cause techmap to exit with an error if it can't map\n");
|
||||
log(" a selected cell. only cell types that end on an underscore are accepted\n");
|
||||
|
@ -1068,6 +1073,10 @@ struct TechmapPass : public Pass {
|
|||
worker.autoproc_mode = true;
|
||||
continue;
|
||||
}
|
||||
if (args[argidx] == "-wb") {
|
||||
worker.ignore_wb = true;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
extra_args(args, argidx, design);
|
||||
|
@ -1145,7 +1154,7 @@ struct FlattenPass : public Pass {
|
|||
{
|
||||
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
|
||||
log("\n");
|
||||
log(" flatten [selection]\n");
|
||||
log(" flatten [options] [selection]\n");
|
||||
log("\n");
|
||||
log("This pass flattens the design by replacing cells by their implementation. This\n");
|
||||
log("pass is very similar to the 'techmap' pass. The only difference is that this\n");
|
||||
|
@ -1154,17 +1163,29 @@ struct FlattenPass : public Pass {
|
|||
log("Cells and/or modules with the 'keep_hierarchy' attribute set will not be\n");
|
||||
log("flattened by this command.\n");
|
||||
log("\n");
|
||||
log(" -wb\n");
|
||||
log(" Ignore the 'whitebox' attribute on cell implementations.\n");
|
||||
log("\n");
|
||||
}
|
||||
void execute(std::vector<std::string> args, RTLIL::Design *design) YS_OVERRIDE
|
||||
{
|
||||
log_header(design, "Executing FLATTEN pass (flatten design).\n");
|
||||
log_push();
|
||||
|
||||
extra_args(args, 1, design);
|
||||
|
||||
TechmapWorker worker;
|
||||
worker.flatten_mode = true;
|
||||
|
||||
size_t argidx;
|
||||
for (argidx = 1; argidx < args.size(); argidx++) {
|
||||
if (args[argidx] == "-wb") {
|
||||
worker.ignore_wb = true;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
extra_args(args, argidx, design);
|
||||
|
||||
|
||||
std::map<RTLIL::IdString, std::set<RTLIL::IdString, RTLIL::sort_by_id_str>> celltypeMap;
|
||||
for (auto module : design->modules())
|
||||
celltypeMap[module->name].insert(module->name);
|
||||
|
@ -1209,7 +1230,7 @@ struct FlattenPass : public Pass {
|
|||
|
||||
dict<RTLIL::IdString, RTLIL::Module*> new_modules;
|
||||
for (auto mod : vector<Module*>(design->modules()))
|
||||
if (used_modules[mod->name] || mod->get_bool_attribute("\\blackbox")) {
|
||||
if (used_modules[mod->name] || mod->get_blackbox_attribute(worker.ignore_wb)) {
|
||||
new_modules[mod->name] = mod;
|
||||
} else {
|
||||
log("Deleting now unused module %s.\n", log_id(mod));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue