gen/fhdl/namer: Cleanup & add comments on Namespace.

This commit is contained in:
Florent Kermarrec 2022-05-06 20:07:18 +02:00
parent 61eead5170
commit 7800858c7a
1 changed files with 22 additions and 10 deletions

View File

@ -237,18 +237,30 @@ class Namespace:
self.clock_domains = dict() self.clock_domains = dict()
def get_name(self, sig): def get_name(self, sig):
# Clock Signal.
# -------------
if isinstance(sig, ClockSignal): if isinstance(sig, ClockSignal):
sig = self.clock_domains[sig.cd].clk sig = self.clock_domains[sig.cd].clk
# Reset Signal.
# -------------
if isinstance(sig, ResetSignal): if isinstance(sig, ResetSignal):
sig = self.clock_domains[sig.cd].rst sig = self.clock_domains[sig.cd].rst
if sig is None: if sig is None:
raise ValueError("Attempted to obtain name of non-existent " msg = f"Clock Domain {sig.cd} is reset-less, can't obtain name"
"reset signal of domain "+sig.cd) raise ValueError(msg)
# Regular Signal.
# ---------------
# Use Name's override when set...
if sig.name_override is not None: if sig.name_override is not None:
sig_name = sig.name_override sig_name = sig.name_override
# ... else get Name from pnd.
else: else:
sig_name = self.pnd[sig] sig_name = self.pnd[sig]
# Check/Add numbering suffix when required.
# -----------------------------------------
try: try:
n = self.sigs[sig] n = self.sigs[sig]
except KeyError: except KeyError:
@ -258,7 +270,7 @@ class Namespace:
n = 0 n = 0
self.sigs[sig] = n self.sigs[sig] = n
self.counts[sig_name] = n + 1 self.counts[sig_name] = n + 1
if n: suffix = "" if n == 0 else f"_{n}"
return sig_name + "_" + str(n)
else: # Return Name.
return sig_name return sig_name + suffix