From da22d376bf47213c800115864747b1864eba7558 Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Thu, 10 Apr 2025 20:12:00 +0200 Subject: [PATCH] dump: sort lhs and rhs in a connection --- backends/rtlil/rtlil_backend.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/backends/rtlil/rtlil_backend.cc b/backends/rtlil/rtlil_backend.cc index 08cd7f754..a23e5ec21 100644 --- a/backends/rtlil/rtlil_backend.cc +++ b/backends/rtlil/rtlil_backend.cc @@ -313,7 +313,17 @@ void RTLIL_BACKEND::dump_module(std::ostream &f, std::string indent, RTLIL::Modu module->cloneInto(new_module); module = new_module; module->sort(); - std::sort(module->connections_.begin(), module->connections_.end()); + 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)