3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-05-09 08:45:48 +00:00
This commit is contained in:
Emil J 2025-05-08 11:39:08 +00:00 committed by GitHub
commit 9c70e59507
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 7 deletions

View file

@ -302,11 +302,30 @@ void RTLIL_BACKEND::dump_conn(std::ostream &f, std::string indent, const RTLIL::
f << stringf("\n");
}
void RTLIL_BACKEND::dump_module(std::ostream &f, std::string indent, RTLIL::Module *module, RTLIL::Design *design, bool only_selected, bool flag_m, bool flag_n)
void RTLIL_BACKEND::dump_module(std::ostream &f, std::string indent, RTLIL::Module *module, RTLIL::Design *design, bool only_selected, bool flag_m, bool flag_n, bool flag_sorted)
{
bool print_header = flag_m || module->is_selected_whole();
bool print_body = !flag_n || !module->is_selected_whole();
std::unique_ptr<Design> d(new Design);
if (flag_sorted) {
Module* new_module = d->addModule(module->name);
module->cloneInto(new_module);
module = new_module;
module->sort();
for (auto& [lhs, rhs] : module->connections_) {
if (std::string(log_signal(lhs)) < std::string(log_signal(rhs))) {
std::swap(lhs, rhs);
}
}
std::sort(module->connections_.begin(), module->connections_.end(), [](const auto &a, const auto &b) {
if (std::string(log_signal(a.first)) != std::string(log_signal(b.first))) {
return std::string(log_signal(a.first)) < std::string(log_signal(b.first));
}
return std::string(log_signal(a.second)) < std::string(log_signal(b.second));
});
}
if (print_header)
{
for (auto it = module->attributes.begin(); it != module->attributes.end(); ++it) {
@ -386,9 +405,10 @@ void RTLIL_BACKEND::dump_module(std::ostream &f, std::string indent, RTLIL::Modu
if (print_header)
f << stringf("%s" "end\n", indent.c_str());
}
void RTLIL_BACKEND::dump_design(std::ostream &f, RTLIL::Design *design, bool only_selected, bool flag_m, bool flag_n)
void RTLIL_BACKEND::dump_design(std::ostream &f, RTLIL::Design *design, bool only_selected, bool flag_m, bool flag_n, bool flag_sorted)
{
int init_autoidx = autoidx;
@ -414,7 +434,7 @@ void RTLIL_BACKEND::dump_design(std::ostream &f, RTLIL::Design *design, bool onl
if (!only_selected || design->selected(module)) {
if (only_selected)
f << stringf("\n");
dump_module(f, "", module, design, only_selected, flag_m, flag_n);
dump_module(f, "", module, design, only_selected, flag_m, flag_n, flag_sorted);
}
}
@ -488,11 +508,14 @@ struct DumpPass : public Pass {
log(" -a <filename>\n");
log(" like -outfile but append instead of overwrite\n");
log("\n");
log(" --sorted\n");
log(" dump sorted representation for nicer diffs. Doesn't modify design\n");
log("\n");
}
void execute(std::vector<std::string> args, RTLIL::Design *design) override
{
std::string filename;
bool flag_m = false, flag_n = false, append = false;
bool flag_m = false, flag_n = false, append = false, flag_sorted = false;
size_t argidx;
for (argidx = 1; argidx < args.size(); argidx++)
@ -516,6 +539,10 @@ struct DumpPass : public Pass {
flag_n = true;
continue;
}
if (arg == "--sorted") {
flag_sorted = true;
continue;
}
break;
}
extra_args(args, argidx, design);
@ -537,7 +564,7 @@ struct DumpPass : public Pass {
f = &buf;
}
RTLIL_BACKEND::dump_design(*f, design, true, flag_m, flag_n);
RTLIL_BACKEND::dump_design(*f, design, true, flag_m, flag_n, flag_sorted);
if (!empty) {
delete f;

View file

@ -42,8 +42,8 @@ namespace RTLIL_BACKEND {
void dump_proc_sync(std::ostream &f, std::string indent, const RTLIL::SyncRule *sy);
void dump_proc(std::ostream &f, std::string indent, const RTLIL::Process *proc);
void dump_conn(std::ostream &f, std::string indent, const RTLIL::SigSpec &left, const RTLIL::SigSpec &right);
void dump_module(std::ostream &f, std::string indent, RTLIL::Module *module, RTLIL::Design *design, bool only_selected, bool flag_m = true, bool flag_n = false);
void dump_design(std::ostream &f, RTLIL::Design *design, bool only_selected, bool flag_m = true, bool flag_n = false);
void dump_module(std::ostream &f, std::string indent, RTLIL::Module *module, RTLIL::Design *design, bool only_selected, bool flag_m = true, bool flag_n = false, bool flag_sorted = false);
void dump_design(std::ostream &f, RTLIL::Design *design, bool only_selected, bool flag_m = true, bool flag_n = false, bool flag_sorted = false);
}
YOSYS_NAMESPACE_END