aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2014-08-16 23:50:36 +0200
committerClifford Wolf <clifford@clifford.at>2014-08-16 23:50:36 +0200
commit7f734ecc098a2a113ced835cefc9d4e1982f08d0 (patch)
tree0e73ad74bd4602da7a6a1a3b264e1842deccac18 /kernel
parentf82c978e08604c596b034fb6e74ac34c78b9364b (diff)
downloadyosys-7f734ecc098a2a113ced835cefc9d4e1982f08d0.tar.gz
yosys-7f734ecc098a2a113ced835cefc9d4e1982f08d0.tar.bz2
yosys-7f734ecc098a2a113ced835cefc9d4e1982f08d0.zip
Added module->uniquify()
Diffstat (limited to 'kernel')
-rw-r--r--kernel/rtlil.cc22
-rw-r--r--kernel/rtlil.h3
2 files changed, 25 insertions, 0 deletions
diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc
index 3df7d83c4..60c514d19 100644
--- a/kernel/rtlil.cc
+++ b/kernel/rtlil.cc
@@ -1108,6 +1108,28 @@ void RTLIL::Module::swap_names(RTLIL::Cell *c1, RTLIL::Cell *c2)
cells_[c2->name] = c2;
}
+RTLIL::IdString RTLIL::Module::uniquify(RTLIL::IdString name)
+{
+ int index = 0;
+ return uniquify(name, index);
+}
+
+RTLIL::IdString RTLIL::Module::uniquify(RTLIL::IdString name, int &index)
+{
+ if (index == 0) {
+ if (count_id(name) == 0)
+ return name;
+ index++;
+ }
+
+ while (1) {
+ RTLIL::IdString new_name = stringf("%s_%d", name.c_str(), index);
+ if (count_id(new_name) == 0)
+ return new_name;
+ index++;
+ }
+}
+
static bool fixup_ports_compare(const RTLIL::Wire *a, const RTLIL::Wire *b)
{
if (a->port_id && !b->port_id)
diff --git a/kernel/rtlil.h b/kernel/rtlil.h
index 43e36cbde..7e052b091 100644
--- a/kernel/rtlil.h
+++ b/kernel/rtlil.h
@@ -625,6 +625,9 @@ public:
void swap_names(RTLIL::Wire *w1, RTLIL::Wire *w2);
void swap_names(RTLIL::Cell *c1, RTLIL::Cell *c2);
+ RTLIL::IdString uniquify(RTLIL::IdString name);
+ RTLIL::IdString uniquify(RTLIL::IdString name, int &index);
+
RTLIL::Wire *addWire(RTLIL::IdString name, int width = 1);
RTLIL::Wire *addWire(RTLIL::IdString name, const RTLIL::Wire *other);