mirror of
https://github.com/YosysHQ/yosys
synced 2025-04-14 04:48:46 +00:00
Add "paramap" pass
Signed-off-by: Clifford Wolf <clifford@clifford.at>
This commit is contained in:
parent
70c0cddb1e
commit
0fda0e821c
|
@ -143,17 +143,8 @@ void attrmap_apply(string objname, vector<std::unique_ptr<AttrmapAction>> &actio
|
||||||
attributes.swap(new_attributes);
|
attributes.swap(new_attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct AttrmapPass : public Pass {
|
void log_attrmap_paramap_options()
|
||||||
AttrmapPass() : Pass("attrmap", "renaming attributes") { }
|
{
|
||||||
void help() YS_OVERRIDE
|
|
||||||
{
|
|
||||||
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
|
|
||||||
log("\n");
|
|
||||||
log(" attrmap [options] [selection]\n");
|
|
||||||
log("\n");
|
|
||||||
log("This command renames attributes and/or mapps key/value pairs to\n");
|
|
||||||
log("other key/value pairs.\n");
|
|
||||||
log("\n");
|
|
||||||
log(" -tocase <name>\n");
|
log(" -tocase <name>\n");
|
||||||
log(" Match attribute names case-insensitively and set it to the specified\n");
|
log(" Match attribute names case-insensitively and set it to the specified\n");
|
||||||
log(" name.\n");
|
log(" name.\n");
|
||||||
|
@ -170,39 +161,23 @@ struct AttrmapPass : public Pass {
|
||||||
log("\n");
|
log("\n");
|
||||||
log(" -remove <name>=<value>\n");
|
log(" -remove <name>=<value>\n");
|
||||||
log(" Remove attributes matching this pattern.\n");
|
log(" Remove attributes matching this pattern.\n");
|
||||||
log("\n");
|
}
|
||||||
log(" -modattr\n");
|
|
||||||
log(" Operate on module attributes instead of attributes on wires and cells.\n");
|
|
||||||
log("\n");
|
|
||||||
log("For example, mapping Xilinx-style \"keep\" attributes to Yosys-style:\n");
|
|
||||||
log("\n");
|
|
||||||
log(" attrmap -tocase keep -imap keep=\"true\" keep=1 \\\n");
|
|
||||||
log(" -imap keep=\"false\" keep=0 -remove keep=0\n");
|
|
||||||
log("\n");
|
|
||||||
}
|
|
||||||
void execute(std::vector<std::string> args, RTLIL::Design *design) YS_OVERRIDE
|
|
||||||
{
|
|
||||||
log_header(design, "Executing ATTRMAP pass (move or copy attributes).\n");
|
|
||||||
|
|
||||||
bool modattr_mode = false;
|
bool parse_attrmap_paramap_options(size_t &argidx, std::vector<std::string> &args, vector<std::unique_ptr<AttrmapAction>> &actions)
|
||||||
vector<std::unique_ptr<AttrmapAction>> actions;
|
{
|
||||||
|
|
||||||
size_t argidx;
|
|
||||||
for (argidx = 1; argidx < args.size(); argidx++)
|
|
||||||
{
|
|
||||||
std::string arg = args[argidx];
|
std::string arg = args[argidx];
|
||||||
if (arg == "-tocase" && argidx+1 < args.size()) {
|
if (arg == "-tocase" && argidx+1 < args.size()) {
|
||||||
auto action = new AttrmapTocase;
|
auto action = new AttrmapTocase;
|
||||||
action->name = args[++argidx];
|
action->name = args[++argidx];
|
||||||
actions.push_back(std::unique_ptr<AttrmapAction>(action));
|
actions.push_back(std::unique_ptr<AttrmapAction>(action));
|
||||||
continue;
|
return true;
|
||||||
}
|
}
|
||||||
if (arg == "-rename" && argidx+2 < args.size()) {
|
if (arg == "-rename" && argidx+2 < args.size()) {
|
||||||
auto action = new AttrmapRename;
|
auto action = new AttrmapRename;
|
||||||
action->old_name = args[++argidx];
|
action->old_name = args[++argidx];
|
||||||
action->new_name = args[++argidx];
|
action->new_name = args[++argidx];
|
||||||
actions.push_back(std::unique_ptr<AttrmapAction>(action));
|
actions.push_back(std::unique_ptr<AttrmapAction>(action));
|
||||||
continue;
|
return true;
|
||||||
}
|
}
|
||||||
if ((arg == "-map" || arg == "-imap") && argidx+2 < args.size()) {
|
if ((arg == "-map" || arg == "-imap") && argidx+2 < args.size()) {
|
||||||
string arg1 = args[++argidx];
|
string arg1 = args[++argidx];
|
||||||
|
@ -225,7 +200,7 @@ struct AttrmapPass : public Pass {
|
||||||
action->old_value = val1;
|
action->old_value = val1;
|
||||||
action->new_value = val2;
|
action->new_value = val2;
|
||||||
actions.push_back(std::unique_ptr<AttrmapAction>(action));
|
actions.push_back(std::unique_ptr<AttrmapAction>(action));
|
||||||
continue;
|
return true;
|
||||||
}
|
}
|
||||||
if (arg == "-remove" && argidx+1 < args.size()) {
|
if (arg == "-remove" && argidx+1 < args.size()) {
|
||||||
string arg1 = args[++argidx], val1;
|
string arg1 = args[++argidx], val1;
|
||||||
|
@ -239,9 +214,46 @@ struct AttrmapPass : public Pass {
|
||||||
action->has_value = (p != string::npos);
|
action->has_value = (p != string::npos);
|
||||||
action->value = val1;
|
action->value = val1;
|
||||||
actions.push_back(std::unique_ptr<AttrmapAction>(action));
|
actions.push_back(std::unique_ptr<AttrmapAction>(action));
|
||||||
continue;
|
return true;
|
||||||
}
|
}
|
||||||
if (arg == "-modattr") {
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct AttrmapPass : public Pass {
|
||||||
|
AttrmapPass() : Pass("attrmap", "renaming attributes") { }
|
||||||
|
void help() YS_OVERRIDE
|
||||||
|
{
|
||||||
|
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
|
||||||
|
log("\n");
|
||||||
|
log(" attrmap [options] [selection]\n");
|
||||||
|
log("\n");
|
||||||
|
log("This command renames attributes and/or mapps key/value pairs to\n");
|
||||||
|
log("other key/value pairs.\n");
|
||||||
|
log("\n");
|
||||||
|
log_attrmap_paramap_options();
|
||||||
|
log("\n");
|
||||||
|
log(" -modattr\n");
|
||||||
|
log(" Operate on module attributes instead of attributes on wires and cells.\n");
|
||||||
|
log("\n");
|
||||||
|
log("For example, mapping Xilinx-style \"keep\" attributes to Yosys-style:\n");
|
||||||
|
log("\n");
|
||||||
|
log(" attrmap -tocase keep -imap keep=\"true\" keep=1 \\\n");
|
||||||
|
log(" -imap keep=\"false\" keep=0 -remove keep=0\n");
|
||||||
|
log("\n");
|
||||||
|
}
|
||||||
|
void execute(std::vector<std::string> args, RTLIL::Design *design) YS_OVERRIDE
|
||||||
|
{
|
||||||
|
log_header(design, "Executing ATTRMAP pass (move or copy attributes).\n");
|
||||||
|
|
||||||
|
bool modattr_mode = false;
|
||||||
|
vector<std::unique_ptr<AttrmapAction>> actions;
|
||||||
|
|
||||||
|
size_t argidx;
|
||||||
|
for (argidx = 1; argidx < args.size(); argidx++)
|
||||||
|
{
|
||||||
|
if (parse_attrmap_paramap_options(argidx, args, actions))
|
||||||
|
continue;
|
||||||
|
if (args[argidx] == "-modattr") {
|
||||||
modattr_mode = true;
|
modattr_mode = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -287,4 +299,43 @@ struct AttrmapPass : public Pass {
|
||||||
}
|
}
|
||||||
} AttrmapPass;
|
} AttrmapPass;
|
||||||
|
|
||||||
|
struct ParamapPass : public Pass {
|
||||||
|
ParamapPass() : Pass("paramap", "renaming cell parameters") { }
|
||||||
|
void help() YS_OVERRIDE
|
||||||
|
{
|
||||||
|
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
|
||||||
|
log("\n");
|
||||||
|
log(" paramap [options] [selection]\n");
|
||||||
|
log("\n");
|
||||||
|
log("This command renames cell parameters and/or mapps key/value pairs to\n");
|
||||||
|
log("other key/value pairs.\n");
|
||||||
|
log("\n");
|
||||||
|
log_attrmap_paramap_options();
|
||||||
|
log("\n");
|
||||||
|
log("For example, mapping Diamond-style ECP5 \"init\" attributes to Yosys-style:\n");
|
||||||
|
log("\n");
|
||||||
|
log(" paramap -tocase INIT t:LUT4\n");
|
||||||
|
log("\n");
|
||||||
|
}
|
||||||
|
void execute(std::vector<std::string> args, RTLIL::Design *design) YS_OVERRIDE
|
||||||
|
{
|
||||||
|
log_header(design, "Executing PARAMAP pass (move or copy cell parameters).\n");
|
||||||
|
|
||||||
|
vector<std::unique_ptr<AttrmapAction>> actions;
|
||||||
|
|
||||||
|
size_t argidx;
|
||||||
|
for (argidx = 1; argidx < args.size(); argidx++)
|
||||||
|
{
|
||||||
|
if (parse_attrmap_paramap_options(argidx, args, actions))
|
||||||
|
continue;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
extra_args(args, argidx, design);
|
||||||
|
|
||||||
|
for (auto module : design->selected_modules())
|
||||||
|
for (auto cell : module->selected_cells())
|
||||||
|
attrmap_apply(stringf("%s.%s", log_id(module), log_id(cell)), actions, cell->parameters);
|
||||||
|
}
|
||||||
|
} ParamapPass;
|
||||||
|
|
||||||
PRIVATE_NAMESPACE_END
|
PRIVATE_NAMESPACE_END
|
||||||
|
|
Loading…
Reference in a new issue