2014-02-05 04:11:55 -06:00
|
|
|
/*
|
|
|
|
* yosys -- Yosys Open SYnthesis Suite
|
|
|
|
*
|
2021-06-07 17:39:36 -05:00
|
|
|
* Copyright (C) 2012 Claire Xenia Wolf <claire@yosyshq.com>
|
2015-07-02 04:14:30 -05:00
|
|
|
*
|
2014-02-05 04:11:55 -06:00
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
2015-07-02 04:14:30 -05:00
|
|
|
*
|
2014-02-05 04:11:55 -06:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "kernel/register.h"
|
|
|
|
#include "kernel/rtlil.h"
|
|
|
|
#include "kernel/log.h"
|
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
USING_YOSYS_NAMESPACE
|
|
|
|
PRIVATE_NAMESPACE_BEGIN
|
|
|
|
|
2014-02-05 04:11:55 -06:00
|
|
|
struct setunset_t
|
|
|
|
{
|
|
|
|
RTLIL::IdString name;
|
|
|
|
RTLIL::Const value;
|
|
|
|
bool unset;
|
|
|
|
|
|
|
|
setunset_t(std::string unset_name) : name(RTLIL::escape_id(unset_name)), value(), unset(true) { }
|
|
|
|
|
2015-04-08 05:14:34 -05:00
|
|
|
setunset_t(std::string set_name, std::string set_value) : name(RTLIL::escape_id(set_name)), value(), unset(false)
|
2014-02-05 04:11:55 -06:00
|
|
|
{
|
2019-08-07 14:20:08 -05:00
|
|
|
if (set_value.compare(0, 1, "\"") == 0 && set_value.compare(GetSize(set_value)-1, std::string::npos, "\"") == 0) {
|
2015-04-08 05:14:34 -05:00
|
|
|
value = RTLIL::Const(set_value.substr(1, GetSize(set_value)-2));
|
2014-02-05 04:11:55 -06:00
|
|
|
} else {
|
|
|
|
RTLIL::SigSpec sig_value;
|
2020-04-06 01:52:18 -05:00
|
|
|
if (!RTLIL::SigSpec::parse(sig_value, nullptr, set_value))
|
2015-04-08 05:14:34 -05:00
|
|
|
log_cmd_error("Can't decode value '%s'!\n", set_value.c_str());
|
2014-02-05 04:11:55 -06:00
|
|
|
value = sig_value.as_const();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-06-29 18:38:34 -05:00
|
|
|
static void do_setunset(dict<RTLIL::IdString, RTLIL::Const> &attrs, const std::vector<setunset_t> &list)
|
2014-02-05 04:11:55 -06:00
|
|
|
{
|
|
|
|
for (auto &item : list)
|
|
|
|
if (item.unset)
|
|
|
|
attrs.erase(item.name);
|
|
|
|
else
|
|
|
|
attrs[item.name] = item.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SetattrPass : public Pass {
|
|
|
|
SetattrPass() : Pass("setattr", "set/unset attributes on objects") { }
|
2020-06-18 18:34:52 -05:00
|
|
|
void help() override
|
2014-02-05 04:11:55 -06:00
|
|
|
{
|
|
|
|
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
|
|
|
|
log("\n");
|
|
|
|
log(" setattr [ -mod ] [ -set name value | -unset name ]... [selection]\n");
|
|
|
|
log("\n");
|
|
|
|
log("Set/unset the given attributes on the selected objects. String values must be\n");
|
|
|
|
log("passed in double quotes (\").\n");
|
|
|
|
log("\n");
|
|
|
|
log("When called with -mod, this command will set and unset attributes on modules\n");
|
|
|
|
log("instead of objects within modules.\n");
|
|
|
|
log("\n");
|
|
|
|
}
|
2020-06-18 18:34:52 -05:00
|
|
|
void execute(std::vector<std::string> args, RTLIL::Design *design) override
|
2014-02-05 04:11:55 -06:00
|
|
|
{
|
|
|
|
std::vector<setunset_t> setunset_list;
|
|
|
|
bool flag_mod = false;
|
|
|
|
|
|
|
|
size_t argidx;
|
|
|
|
for (argidx = 1; argidx < args.size(); argidx++)
|
|
|
|
{
|
|
|
|
std::string arg = args[argidx];
|
|
|
|
if (arg == "-set" && argidx+2 < args.size()) {
|
2015-04-08 05:14:34 -05:00
|
|
|
string set_key = args[++argidx];
|
|
|
|
string set_val = args[++argidx];
|
|
|
|
setunset_list.push_back(setunset_t(set_key, set_val));
|
2014-02-05 04:11:55 -06:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (arg == "-unset" && argidx+1 < args.size()) {
|
|
|
|
setunset_list.push_back(setunset_t(args[++argidx]));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (arg == "-mod") {
|
|
|
|
flag_mod = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
extra_args(args, argidx, design);
|
|
|
|
|
2020-04-06 01:52:18 -05:00
|
|
|
for (auto module : design->modules())
|
2014-02-05 04:11:55 -06:00
|
|
|
{
|
|
|
|
if (flag_mod) {
|
|
|
|
if (design->selected_whole_module(module->name))
|
|
|
|
do_setunset(module->attributes, setunset_list);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!design->selected(module))
|
|
|
|
continue;
|
|
|
|
|
2020-04-06 01:52:18 -05:00
|
|
|
for (auto wire : module->wires())
|
|
|
|
if (design->selected(module, wire))
|
|
|
|
do_setunset(wire->attributes, setunset_list);
|
2014-02-05 04:11:55 -06:00
|
|
|
|
|
|
|
for (auto &it : module->memories)
|
|
|
|
if (design->selected(module, it.second))
|
|
|
|
do_setunset(it.second->attributes, setunset_list);
|
|
|
|
|
2020-04-06 01:52:18 -05:00
|
|
|
for (auto cell : module->cells())
|
|
|
|
if (design->selected(module, cell))
|
|
|
|
do_setunset(cell->attributes, setunset_list);
|
2014-02-05 04:11:55 -06:00
|
|
|
|
|
|
|
for (auto &it : module->processes)
|
|
|
|
if (design->selected(module, it.second))
|
|
|
|
do_setunset(it.second->attributes, setunset_list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} SetattrPass;
|
2015-07-02 04:14:30 -05:00
|
|
|
|
2019-04-20 04:04:46 -05:00
|
|
|
struct WbflipPass : public Pass {
|
|
|
|
WbflipPass() : Pass("wbflip", "flip the whitebox attribute") { }
|
2020-06-18 18:34:52 -05:00
|
|
|
void help() override
|
2019-04-20 04:04:46 -05:00
|
|
|
{
|
|
|
|
// |---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");
|
|
|
|
}
|
2020-06-18 18:34:52 -05:00
|
|
|
void execute(std::vector<std::string> args, RTLIL::Design *design) override
|
2019-04-20 04:04:46 -05:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
if (module->get_bool_attribute(ID::blackbox))
|
2019-04-20 04:04:46 -05:00
|
|
|
continue;
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
module->set_bool_attribute(ID::whitebox, !module->get_bool_attribute(ID::whitebox));
|
2019-04-20 04:04:46 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} WbflipPass;
|
|
|
|
|
2014-02-05 04:11:55 -06:00
|
|
|
struct SetparamPass : public Pass {
|
|
|
|
SetparamPass() : Pass("setparam", "set/unset parameters on objects") { }
|
2020-06-18 18:34:52 -05:00
|
|
|
void help() override
|
2014-02-05 04:11:55 -06:00
|
|
|
{
|
|
|
|
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
|
|
|
|
log("\n");
|
2016-10-19 06:54:04 -05:00
|
|
|
log(" setparam [ -type cell_type ] [ -set name value | -unset name ]... [selection]\n");
|
2014-02-05 04:11:55 -06:00
|
|
|
log("\n");
|
|
|
|
log("Set/unset the given parameters on the selected cells. String values must be\n");
|
|
|
|
log("passed in double quotes (\").\n");
|
|
|
|
log("\n");
|
2016-10-19 06:54:04 -05:00
|
|
|
log("The -type option can be used to change the cell type of the selected cells.\n");
|
|
|
|
log("\n");
|
2014-02-05 04:11:55 -06:00
|
|
|
}
|
2020-06-18 18:34:52 -05:00
|
|
|
void execute(std::vector<std::string> args, RTLIL::Design *design) override
|
2014-02-05 04:11:55 -06:00
|
|
|
{
|
2016-10-19 06:54:04 -05:00
|
|
|
vector<setunset_t> setunset_list;
|
|
|
|
string new_cell_type;
|
2014-02-05 04:11:55 -06:00
|
|
|
|
|
|
|
size_t argidx;
|
|
|
|
for (argidx = 1; argidx < args.size(); argidx++)
|
|
|
|
{
|
|
|
|
std::string arg = args[argidx];
|
|
|
|
if (arg == "-set" && argidx+2 < args.size()) {
|
2015-04-08 05:14:34 -05:00
|
|
|
string set_key = args[++argidx];
|
|
|
|
string set_val = args[++argidx];
|
|
|
|
setunset_list.push_back(setunset_t(set_key, set_val));
|
2014-02-05 04:11:55 -06:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (arg == "-unset" && argidx+1 < args.size()) {
|
|
|
|
setunset_list.push_back(setunset_t(args[++argidx]));
|
|
|
|
continue;
|
|
|
|
}
|
2016-10-19 06:54:04 -05:00
|
|
|
if (arg == "-type" && argidx+1 < args.size()) {
|
|
|
|
new_cell_type = RTLIL::escape_id(args[++argidx]);
|
|
|
|
continue;
|
|
|
|
}
|
2014-02-05 04:11:55 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
extra_args(args, argidx, design);
|
|
|
|
|
2020-04-06 01:52:18 -05:00
|
|
|
for (auto module : design->selected_modules())
|
2014-02-05 04:11:55 -06:00
|
|
|
{
|
2020-04-06 01:52:18 -05:00
|
|
|
for (auto cell : module->selected_cells()) {
|
|
|
|
if (!new_cell_type.empty())
|
|
|
|
cell->type = new_cell_type;
|
|
|
|
do_setunset(cell->parameters, setunset_list);
|
|
|
|
}
|
2014-02-05 04:11:55 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} SetparamPass;
|
2015-07-02 04:14:30 -05:00
|
|
|
|
2015-04-07 00:30:14 -05:00
|
|
|
struct ChparamPass : public Pass {
|
|
|
|
ChparamPass() : Pass("chparam", "re-evaluate modules with new parameters") { }
|
2020-06-18 18:34:52 -05:00
|
|
|
void help() override
|
2015-04-07 00:30:14 -05:00
|
|
|
{
|
|
|
|
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
|
|
|
|
log("\n");
|
|
|
|
log(" chparam [ -set name value ]... [selection]\n");
|
|
|
|
log("\n");
|
|
|
|
log("Re-evaluate the selected modules with new parameters. String values must be\n");
|
|
|
|
log("passed in double quotes (\").\n");
|
|
|
|
log("\n");
|
2015-04-07 12:21:30 -05:00
|
|
|
log("\n");
|
|
|
|
log(" chparam -list [selection]\n");
|
|
|
|
log("\n");
|
|
|
|
log("List the available parameters of the selected modules.\n");
|
|
|
|
log("\n");
|
2015-04-07 00:30:14 -05:00
|
|
|
}
|
2020-06-18 18:34:52 -05:00
|
|
|
void execute(std::vector<std::string> args, RTLIL::Design *design) override
|
2015-04-07 00:30:14 -05:00
|
|
|
{
|
|
|
|
std::vector<setunset_t> setunset_list;
|
|
|
|
dict<RTLIL::IdString, RTLIL::Const> new_parameters;
|
2015-04-07 12:21:30 -05:00
|
|
|
bool list_mode = false;
|
2015-04-07 00:30:14 -05:00
|
|
|
|
|
|
|
size_t argidx;
|
|
|
|
for (argidx = 1; argidx < args.size(); argidx++)
|
|
|
|
{
|
|
|
|
std::string arg = args[argidx];
|
|
|
|
if (arg == "-set" && argidx+2 < args.size()) {
|
2015-04-08 05:14:34 -05:00
|
|
|
string set_key = args[++argidx];
|
|
|
|
string set_val = args[++argidx];
|
|
|
|
setunset_list.push_back(setunset_t(set_key, set_val));
|
2015-04-07 00:30:14 -05:00
|
|
|
continue;
|
|
|
|
}
|
2015-04-07 12:21:30 -05:00
|
|
|
if (arg == "-list") {
|
|
|
|
list_mode = true;
|
|
|
|
continue;
|
|
|
|
}
|
2015-04-07 00:30:14 -05:00
|
|
|
break;
|
|
|
|
}
|
2016-03-21 10:30:55 -05:00
|
|
|
|
|
|
|
for (int i = argidx; i < GetSize(args); i++)
|
|
|
|
if (design->module("$abstract\\" + args[i]) != nullptr &&
|
|
|
|
design->module(RTLIL::escape_id(args[i])) == nullptr)
|
|
|
|
args[i] = "$abstract\\" + args[i];
|
|
|
|
|
2015-04-07 00:30:14 -05:00
|
|
|
extra_args(args, argidx, design);
|
|
|
|
|
2015-06-29 18:38:34 -05:00
|
|
|
do_setunset(new_parameters, setunset_list);
|
|
|
|
|
2015-04-07 12:21:30 -05:00
|
|
|
if (list_mode) {
|
|
|
|
if (!new_parameters.empty())
|
|
|
|
log_cmd_error("The options -set and -list cannot be used together.\n");
|
|
|
|
for (auto module : design->selected_modules()) {
|
|
|
|
log("%s:\n", log_id(module));
|
|
|
|
for (auto param : module->avail_parameters)
|
|
|
|
log(" %s\n", log_id(param));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-07 00:30:14 -05:00
|
|
|
pool<IdString> modnames, old_modnames;
|
2015-06-29 18:38:34 -05:00
|
|
|
for (auto module : design->selected_whole_modules_warn()) {
|
|
|
|
modnames.insert(module->name);
|
2015-04-07 00:30:14 -05:00
|
|
|
old_modnames.insert(module->name);
|
|
|
|
}
|
|
|
|
modnames.sort();
|
|
|
|
|
|
|
|
for (auto modname : modnames) {
|
|
|
|
Module *module = design->module(modname);
|
|
|
|
Module *new_module = design->module(module->derive(design, new_parameters));
|
|
|
|
if (module != new_module) {
|
|
|
|
Module *m = new_module->clone();
|
|
|
|
m->name = module->name;
|
|
|
|
design->remove(module);
|
|
|
|
design->add(m);
|
|
|
|
}
|
|
|
|
if (old_modnames.count(new_module->name) == 0)
|
|
|
|
design->remove(new_module);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} ChparamPass;
|
2015-07-02 04:14:30 -05:00
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
PRIVATE_NAMESPACE_END
|