@@ -22,6 +22,12 @@ class Standard(enum.IntEnum):
2222 #: IP-XACT - IEEE Std. 1685-2014
2323 IEEE_1685_2014 = 2014
2424
25+ @property
26+ def supports_isPresent (self ) -> bool :
27+ # Only 2014 supports ispresent
28+ return self == Standard .IEEE_1685_2014
29+
30+
2531#===============================================================================
2632class IPXACTExporter :
2733 def __init__ (self , ** kwargs : Any ) -> None :
@@ -65,6 +71,9 @@ def __init__(self, **kwargs: Any) -> None:
6571 else :
6672 self .ns = "spirit:"
6773
74+ # If standard supports isPresent tags, don't skip them
75+ self .skip_not_present = not self .standard .supports_isPresent
76+
6877 #---------------------------------------------------------------------------
6978 def export (self , node : Union [AddrmapNode , RootNode ], path : str , ** kwargs : Any ) -> None :
7079 """
@@ -148,7 +157,7 @@ def export(self, node: Union[AddrmapNode, RootNode], path: str, **kwargs: Any) -
148157 addrblockable_children = 0
149158 non_addrblockable_children = 0
150159
151- for child in node .children (skip_not_present = False ):
160+ for child in node .children (skip_not_present = self . skip_not_present ):
152161 if not isinstance (child , AddressableNode ):
153162 continue
154163
@@ -172,7 +181,7 @@ def export(self, node: Union[AddrmapNode, RootNode], path: str, **kwargs: Any) -
172181 mmaps .appendChild (mmap )
173182
174183 # Top-node's children become their own addressBlocks
175- for child in node .children (skip_not_present = False ):
184+ for child in node .children (skip_not_present = self . skip_not_present ):
176185 if not isinstance (child , AddressableNode ):
177186 continue
178187
@@ -214,36 +223,34 @@ def add_nameGroup(self, parent: minidom.Element, name: str, displayName: Optiona
214223
215224 #---------------------------------------------------------------------------
216225 def add_registerData (self , parent : minidom .Element , node : RegNode ) -> None :
217- if self .standard == Standard .IEEE_1685_2014 :
218- # registers and registerFiles can be interleaved
219- for child in node .children (skip_not_present = False ):
226+ if self .standard == Standard .IEEE_1685_2009 :
227+ # registers must all be listed before register files
228+ for child in node .children (skip_not_present = self . skip_not_present ):
220229 if isinstance (child , RegNode ):
221230 self .add_register (parent , child )
222- elif isinstance (child , (AddrmapNode , RegfileNode )):
231+
232+ for child in node .children (skip_not_present = self .skip_not_present ):
233+ if isinstance (child , (AddrmapNode , RegfileNode )):
223234 self .add_registerFile (parent , child )
224235 elif isinstance (child , MemNode ):
225236 self .msg .warning (
226237 "IP-XACT does not support 'mem' nodes that are nested in hierarchy. Discarding '%s'"
227238 % child .get_path (),
228239 child .inst .inst_src_ref
229240 )
230- elif self . standard == Standard . IEEE_1685_2009 :
231- # registers must all be listed before register files
232- for child in node .children (skip_not_present = False ):
241+ else :
242+ # registers and registerFiles can be interleaved
243+ for child in node .children (skip_not_present = self . skip_not_present ):
233244 if isinstance (child , RegNode ):
234245 self .add_register (parent , child )
235-
236- for child in node .children (skip_not_present = False ):
237- if isinstance (child , (AddrmapNode , RegfileNode )):
246+ elif isinstance (child , (AddrmapNode , RegfileNode )):
238247 self .add_registerFile (parent , child )
239248 elif isinstance (child , MemNode ):
240249 self .msg .warning (
241250 "IP-XACT does not support 'mem' nodes that are nested in hierarchy. Discarding '%s'"
242251 % child .get_path (),
243252 child .inst .inst_src_ref
244253 )
245- else :
246- raise RuntimeError
247254
248255 #---------------------------------------------------------------------------
249256 def hex_str (self , v : int ) -> str :
@@ -275,7 +282,7 @@ def add_addressBlock(self, parent: minidom.Element, node: AddressableNode) -> No
275282 node .get_property ("desc" )
276283 )
277284
278- if ( self .standard >= Standard . IEEE_1685_2014 ) and not node .get_property ("ispresent" ):
285+ if self .standard . supports_isPresent and not node .get_property ("ispresent" ):
279286 self .add_value (addressBlock , self .ns + "isPresent" , "0" )
280287
281288 self .add_value (addressBlock , self .ns + "baseAddress" , self .hex_str (node .absolute_address ))
@@ -329,7 +336,7 @@ def add_registerFile(self, parent: minidom.Element, node: Union[RegfileNode, Add
329336 node .get_property ("desc" )
330337 )
331338
332- if ( self .standard >= Standard . IEEE_1685_2014 ) and not node .get_property ("ispresent" ):
339+ if self .standard . supports_isPresent and not node .get_property ("ispresent" ):
333340 self .add_value (registerFile , self .ns + "isPresent" , "0" )
334341
335342 if node .is_array :
@@ -367,7 +374,7 @@ def add_register(self, parent: minidom.Element, node: RegNode) -> None:
367374 node .get_property ("desc" )
368375 )
369376
370- if ( self .standard >= Standard . IEEE_1685_2014 ) and not node .get_property ("ispresent" ):
377+ if self .standard . supports_isPresent and not node .get_property ("ispresent" ):
371378 self .add_value (register , self .ns + "isPresent" , "0" )
372379
373380 if node .is_array :
@@ -396,7 +403,7 @@ def add_register(self, parent: minidom.Element, node: RegNode) -> None:
396403 if self .standard <= Standard .IEEE_1685_2009 :
397404 reset = 0
398405 mask = 0
399- for field in node .fields (skip_not_present = False ):
406+ for field in node .fields (skip_not_present = self . skip_not_present ):
400407 field_reset = field .get_property ("reset" )
401408 if isinstance (field_reset , int ):
402409 field_mask = ((1 << field .width ) - 1 ) << field .lsb
@@ -410,7 +417,7 @@ def add_register(self, parent: minidom.Element, node: RegNode) -> None:
410417 self .add_value (reset_el , self .ns + "value" , self .hex_str (reset ))
411418 self .add_value (reset_el , self .ns + "mask" , self .hex_str (mask ))
412419
413- for field in node .fields (skip_not_present = False ):
420+ for field in node .fields (skip_not_present = self . skip_not_present ):
414421 self .add_field (register , field )
415422
416423 # DNE: <spirit/ipxact:alternateRegisters> [...]
@@ -432,7 +439,7 @@ def add_field(self, parent: minidom.Element, node: FieldNode) -> None:
432439 node .get_property ("desc" )
433440 )
434441
435- if ( self .standard >= Standard . IEEE_1685_2014 ) and not node .get_property ("ispresent" ):
442+ if self .standard . supports_isPresent and not node .get_property ("ispresent" ):
436443 self .add_value (field , self .ns + "isPresent" , "0" )
437444
438445 self .add_value (field , self .ns + "bitOffset" , "%d" % node .low )
0 commit comments