From 956dbea1e112d5bfdab41131b14fe81202b66ceb Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Fri, 26 Jun 2020 23:31:33 +0100 Subject: [PATCH] fix prefixes on RecordObject --- src/nmutil/iocontrol.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/nmutil/iocontrol.py b/src/nmutil/iocontrol.py index 5a1e2cf..917e105 100644 --- a/src/nmutil/iocontrol.py +++ b/src/nmutil/iocontrol.py @@ -23,6 +23,7 @@ from nmigen import Signal, Cat, Const, Module, Value, Elaboratable from nmigen.cli import verilog, rtlil from nmigen.hdl.rec import Record +from nmigen import tracer from collections.abc import Sequence, Iterable from collections import OrderedDict @@ -85,8 +86,11 @@ def add_prefix_to_record_signals(prefix, record): class RecordObject(Record): def __init__(self, layout=None, name=None): + #if name is None: + # name = tracer.get_var_name(depth=2, default="$ro") Record.__init__(self, layout=layout or [], name=name) + def __setattr__(self, k, v): #print(f"RecordObject setattr({k}, {v})") #print (dir(Record)) @@ -94,13 +98,17 @@ class RecordObject(Record): k in dir(Record) or "fields" not in self.__dict__): return object.__setattr__(self, k, v) + if self.name is None: + prefix = "" + else: + prefix = self.name + "_" # Prefix the signal name with the name of the recordobject if isinstance(v, Signal): - v.name = self.name + "_" + v.name + print (self, self.name, v.name) + v.name = prefix + v.name elif isinstance(v, Record): add_prefix_to_record_signals(self.name + "_", v) - self.fields[k] = v #print ("RecordObject setattr", k, v) if isinstance(v, Record): -- 2.30.2