From 21abdefac0a97a0a668ac33e8caa53c4c0fd4020 Mon Sep 17 00:00:00 2001 From: Dennis Date: Thu, 3 Jun 2021 18:07:17 +0200 Subject: [PATCH] Add genvar declaration to addrmap --- srdl2sv/components/addrmap.py | 8 ++++++++ srdl2sv/components/component.py | 15 +++++++++++++++ srdl2sv/components/field.py | 1 + 3 files changed, 24 insertions(+) diff --git a/srdl2sv/components/addrmap.py b/srdl2sv/components/addrmap.py index 8bd182a..ce9dccf 100644 --- a/srdl2sv/components/addrmap.py +++ b/srdl2sv/components/addrmap.py @@ -147,6 +147,14 @@ class AddrMap(Component): inputs = '\n'.join(input_ports_rtl), outputs = '\n'.join(output_ports_rtl))) + # Append genvars + genvars = ''.join([ + '\ngenvar ', + ','.join([chr(97+i) for i in range(self.get_max_dim_depth())]), + ';\n' + ]) + + self.rtl_header.append(genvars) # Add endmodule keyword self.rtl_footer.append('endmodule') diff --git a/srdl2sv/components/component.py b/srdl2sv/components/component.py index 3277c4e..6d6bb7f 100644 --- a/srdl2sv/components/component.py +++ b/srdl2sv/components/component.py @@ -65,6 +65,21 @@ class Component(): return self.ports[port_type] + def get_max_dim_depth(self) -> int: + try: + total_dimensions = self.total_dimensions + total_array_dimensions = self.total_array_dimensions + except AttributeError: + total_dimensions = 0 + total_array_dimensions = [] + + self.logger.debug("Return depth '{}' for dimensions (including "\ + "parents) '{}'".format(total_dimensions, total_array_dimensions)) + return max([ + total_dimensions, + *[x.get_max_dim_depth() for x in self.children] + ]) + def get_signals(self): self.logger.debug("Return signal list") diff --git a/srdl2sv/components/field.py b/srdl2sv/components/field.py index 539884b..0a64e8f 100644 --- a/srdl2sv/components/field.py +++ b/srdl2sv/components/field.py @@ -145,6 +145,7 @@ class Field(Component): # Save dimensions of unpacked dimension self.array_dimensions = array_dimensions self.total_array_dimensions = array_dimensions + self.total_dimensions = len(self.total_array_dimensions) # Calculate how many genvars shall be added genvars = ['[{}]'.format(chr(97+i)) for i in range(len(array_dimensions))]