gen/fhdl/namer: Add update method to HierarchyNode to replace update_hierarchy_node.
This commit is contained in:
parent
c0057672d6
commit
c8a96b8d79
|
@ -27,33 +27,32 @@ class HierarchyNode:
|
||||||
self.use_number = False
|
self.use_number = False
|
||||||
self.children = {}
|
self.children = {}
|
||||||
|
|
||||||
def update_hierarchy_node(current, name, number, use_number, current_base):
|
def update(self, name, number, use_number, current_base=None):
|
||||||
"""
|
"""
|
||||||
Updates or creates a hierarchy node based on the current position, name, and number.
|
Updates or creates a hierarchy node based on the current position, name, and number.
|
||||||
If numbering is used, sorts and stores all numbers associated with the base node.
|
If numbering is used, sorts and stores all numbers associated with the base node.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
curren t (HierarchyNode): The current node in the hierarchy.
|
name (str): The name of the current hierarchy level.
|
||||||
name (str): The name of the current hierarchy level.
|
number (int): The number associated with the current hierarchy level.
|
||||||
number (int): The number associated with the current hierarchy level.
|
use_number (bool): Flag indicating whether to use the number in the hierarchy.
|
||||||
use_number (bool): Flag indicating whether to use the number in the hierarchy.
|
current_base (HierarchyNode, optional): The base node for number usage information.
|
||||||
current_base (HierarchyNode): The base node for number usage information.
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
HierarchyNode: The updated or created node.
|
HierarchyNode: The updated or created child node.
|
||||||
"""
|
"""
|
||||||
# Create the appropriate key for the node.
|
# Create the appropriate key for the node.
|
||||||
key = (name, number) if use_number else name
|
key = (name, number) if use_number else name
|
||||||
# Use setdefault to either get the existing child node or create a new one.
|
# Use setdefault to either get the existing child node or create a new one.
|
||||||
current = current.children.setdefault(key, HierarchyNode())
|
child = self.children.setdefault(key, HierarchyNode())
|
||||||
# Add the number to the set of numbers associated with this node.
|
# Add the number to the set of numbers associated with this node.
|
||||||
current.numbers.add(number)
|
child.numbers.add(number)
|
||||||
# Increment the count of signals that have traversed this node.
|
# Increment the count of signals that have traversed this node.
|
||||||
current.signal_count += 1
|
child.signal_count += 1
|
||||||
# If numbering is used, sort and store all numbers associated with the base node.
|
# If numbering is used, sort and store all numbers associated with the base node.
|
||||||
if use_number and current_base:
|
if use_number and current_base:
|
||||||
current.all_numbers = sorted(current_base.numbers)
|
child.all_numbers = sorted(current_base.numbers)
|
||||||
return current
|
return child
|
||||||
|
|
||||||
def build_hierarchy_tree(signals, base_tree=None):
|
def build_hierarchy_tree(signals, base_tree=None):
|
||||||
"""
|
"""
|
||||||
|
@ -82,7 +81,7 @@ def build_hierarchy_tree(signals, base_tree=None):
|
||||||
use_number = current_base.use_number if current_base else False
|
use_number = current_base.use_number if current_base else False
|
||||||
|
|
||||||
# Update the current node in the hierarchy.
|
# Update the current node in the hierarchy.
|
||||||
current = update_hierarchy_node(current, name, number, use_number, current_base)
|
current = current.update(name, number, use_number, current_base)
|
||||||
|
|
||||||
return root
|
return root
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue