@@ -135,25 +135,29 @@ def visit_Task(self, node):
135135 self .generic_visit (node )
136136 self .frames .unsetTaskDef ()
137137
138- def _visit_Instance_primitive (self , node ):
139- primitive_type = primitives [node .module ]
140- left = node .portlist [0 ].argname
141- right = None
142- if primitive_type == None :
143- right = Partselect (node .portlist [1 ].argname , IntConst ('0' ), IntConst ('0' ))
144- elif primitive_type == Unot :
145- right = Ulnot (Partselect (node .portlist [1 ].argname , IntConst ('0' ), IntConst ('0' )))
146- else :
147- concat_list = [Partselect (p .argname , IntConst ('0' ), IntConst ('0' )) for p in node .portlist [1 :]]
148- right = primitive_type (Concat (concat_list ))
149- self .addBind (left , right , bindtype = 'assign' )
138+ def visit_InstanceList (self , node ):
139+ for i in node .instances :
140+ self .visit (i )
150141
151142 def visit_Instance (self , node ):
152- if node .module in primitives :
153- self ._visit_Instance_primitive (node )
154- return
143+ if node .array : return self ._visit_Instance_array (node )
144+ nodename = node .name
145+ return self ._visit_Instance_body (node , nodename )
146+
147+ def _visit_Instance_array (self , node ):
148+ current = self .frames .getCurrent ()
149+ msb = self .optimize (self .getTree (node .array .msb , current )).value
150+ lsb = self .optimize (self .getTree (node .array .lsb , current )).value
151+ num_of_pins = msb + 1 - lsb
152+
153+ for i in range (lsb , msb + 1 ):
154+ nodename = node .name + '_' + str (i )
155+ self ._visit_Instance_body (node , nodename , arrayindex = i )
155156
156- current = self .stackInstanceFrame (node .name , node .module )
157+ def _visit_Instance_body (self , node , nodename , arrayindex = None ):
158+ if node .module in primitives : return self ._visit_Instance_primitive (node , arrayindex )
159+
160+ current = self .stackInstanceFrame (nodename , node .module )
157161
158162 scope = self .frames .getCurrent ()
159163
@@ -164,7 +168,7 @@ def visit_Instance(self, node):
164168 paramname = paramnames [paramnames_i ] if param .paramname is None else param .paramname
165169 if paramname not in paramnames :
166170 raise verror .FormatError ("No such parameter: %s in %s" %
167- (paramname , node . name ))
171+ (paramname , nodename ))
168172 name = scope + ScopeLabel (paramname , 'signal' )
169173 self .setConstant (name , value )
170174 definition = Parameter (paramname , str (value .value ))
@@ -175,15 +179,33 @@ def visit_Instance(self, node):
175179 for ioport_i , port in enumerate (node .portlist ):
176180 if port .portname is not None and not (port .portname in ioports ):
177181 raise verror .FormatError ("No such port: %s in %s" %
178- (port .argname .name , node . name ))
179- self .addInstancePortBind (port , ioports [ioport_i ])
182+ (port .argname .name , nodename ))
183+ self .addInstancePortBind (port , ioports [ioport_i ], arrayindex )
180184
181185 new_current = self .frames .getCurrent ()
182186 self .copyFrameInfo (new_current )
183187
184188 self .visit (self .moduleinfotable .getDefinition (node .module ))
185189 self .frames .setCurrent (current )
186190
191+ def _visit_Instance_primitive (self , node , arrayindex = None ):
192+ primitive_type = primitives [node .module ]
193+ left = node .portlist [0 ].argname
194+ if arrayindex is not None :
195+ left = Pointer (left , IntConst (str (arrayindex )))
196+ right = None
197+ if primitive_type == None :
198+ right = (Pointer (node .portlist [1 ].argname , IntConst ('0' )) if arrayindex is None else
199+ Pointer (node .portlist [1 ].argname , IntConst (str (arrayindex ))))
200+ elif primitive_type == Unot :
201+ right = (Ulnot (Pointer (node .portlist [1 ].argname , IntConst ('0' ))) if arrayindex is None else
202+ Ulnot (Pointer (node .portlist [1 ].argname , IntConst (str (arrayindex )))))
203+ else :
204+ concat_list = ([Pointer (p .argname , IntConst ('0' )) for p in node .portlist [1 :]] if arrayindex is None else
205+ [Pointer (p .argname , IntConst (str (arrayindex ))) for p in node .portlist [1 :]])
206+ right = primitive_type (Concat (concat_list ))
207+ self .addBind (left , right , bindtype = 'assign' )
208+
187209 def visit_Initial (self , node ):
188210 pass
189211 #label = self.labels.get( self.frames.getLabelKey('initial') )
@@ -806,11 +828,10 @@ def addInstanceParameterBind(self, param, name=None):
806828
807829 self .addDataflow (dst , param .argname , lscope , rscope , None , 'parameter' )
808830
809- def addInstancePortBind (self , port , instportname = None ):
831+ def addInstancePortBind (self , port , instportname = None , arrayindex = None ):
810832 lscope = self .frames .getCurrent ()
811833 rscope = lscope [:- 1 ]
812834 portname = instportname if port .portname is None else port .portname
813-
814835 ldst = self .getDestinations (portname , lscope )
815836 if ldst [0 ][0 ] is None :
816837 raise verror .DefinitionError ('No such port: %s' % portname )
@@ -819,15 +840,21 @@ def addInstancePortBind(self, port, instportname=None):
819840 for t in termtype :
820841 if t == 'Input' :
821842 if port .argname is None : continue
822- self .addDataflow (ldst , port .argname , lscope , rscope )
843+ portarg = (port .argname if arrayindex is None else
844+ Pointer (port .argname , IntConst (str (arrayindex ))))
845+ self .addDataflow (ldst , portarg , lscope , rscope )
823846 elif t == 'Output' :
824847 if port .argname is None : continue
825- rdst = self .getDestinations (port .argname , rscope )
848+ portarg = (port .argname if arrayindex is None else
849+ Pointer (port .argname , IntConst (str (arrayindex ))))
850+ rdst = self .getDestinations (portarg , rscope )
826851 self .addDataflow (rdst , portname , rscope , lscope )
827852 elif t == 'Inout' :
828853 if port .argname is None : continue
829- self .addDataflow (ldst , port .argname , lscope , rscope )
830- rdst = self .getDestinations (port .argname , rscope )
854+ portarg = (port .argname if arrayindex is None else
855+ Pointer (port .argname , IntConst (str (arrayindex ))))
856+ self .addDataflow (ldst , portarg , lscope , rscope )
857+ rdst = self .getDestinations (portarg , rscope )
831858 self .addDataflow (rdst , portname , rscope , lscope )
832859
833860 ############################################################################
0 commit comments