def GetTypeFromNode(node: Iir) -> BaseType: typeName = GetNameOfNode(node) typeDefinition = nodes.Get_Type_Definition(node) if typeDefinition is nodes.Null_Iir: return IncompleteType(node, typeName) kind = GetIirKindOfNode(typeDefinition) if kind == nodes.Iir_Kind.Enumeration_Type_Definition: return EnumeratedType.parse(typeName, typeDefinition) elif kind == nodes.Iir_Kind.Array_Type_Definition: return ArrayType.parse(typeName, typeDefinition) elif kind == nodes.Iir_Kind.Record_Type_Definition: return RecordType.parse(typeName, typeDefinition) elif kind == nodes.Iir_Kind.Access_Type_Definition: return AccessType.parse(typeName, typeDefinition) elif kind == nodes.Iir_Kind.File_Type_Definition: return FileType.parse(typeName, typeDefinition) elif kind == nodes.Iir_Kind.Protected_Type_Declaration: return ProtectedType.parse(typeName, typeDefinition) else: position = Position.parse(typeDefinition) raise DOMException( "GetTypeFromNode: Unknown type definition kind '{kind}' for type '{name}' at {file}:{line}:{column}." .format( kind=kind.name, name=typeName, file=position.Filename, line=position.Line, column=position.Column, ))
def GetAnonymousTypeFromNode(node: Iir) -> BaseType: typeName = GetNameOfNode(node) typeDefinition = nodes.Get_Type_Definition(node) if typeDefinition is nodes.Null_Iir: return IncompleteType(node, typeName) kind = GetIirKindOfNode(typeDefinition) if kind == nodes.Iir_Kind.Range_Expression: r = GetRangeFromNode(typeDefinition) return IntegerType(node, typeName, r) elif kind in (nodes.Iir_Kind.Attribute_Name, nodes.Iir_Kind.Parenthesis_Name): n = GetNameFromNode(typeDefinition) return IntegerType(node, typeName, n) elif kind == nodes.Iir_Kind.Physical_Type_Definition: return PhysicalType.parse(typeName, typeDefinition) elif kind == nodes.Iir_Kind.Array_Subtype_Definition: print("[NOT IMPLEMENTED] Array_Subtype_Definition") return ArrayType(typeDefinition, "????", [], None) else: position = Position.parse(typeDefinition) raise DOMException( "GetAnonymousTypeFromNode: Unknown type definition kind '{kind}' for type '{name}' at {file}:{line}:{column}." .format( kind=kind.name, name=typeName, file=position.Filename, line=position.Line, column=position.Column, ))
def GetArrayConstraintsFromSubtypeIndication( subtypeIndication: Iir, ) -> List[ConstraintUnion]: constraints = [] for constraint in utils.flist_iter( nodes.Get_Index_Constraint_List(subtypeIndication)): constraintKind = GetIirKindOfNode(constraint) if constraintKind == nodes.Iir_Kind.Range_Expression: constraints.append(RangeExpression.parse(constraint)) elif constraintKind in ( nodes.Iir_Kind.Simple_Name, nodes.Iir_Kind.Parenthesis_Name, nodes.Iir_Kind.Selected_Name, nodes.Iir_Kind.Attribute_Name, ): constraints.append(GetNameFromNode(constraint)) else: position = Position.parse(constraint) raise DOMException( "Unknown constraint kind '{kind}' for constraint '{constraint}' in subtype indication '{indication}' at {file}:{line}:{column}." .format( kind=constraintKind.name, constraint=constraint, indication=subtypeIndication, file=position.Filename, line=position.Line, column=position.Column, )) return constraints
def GetMapAspect(mapAspect: Iir, cls: Type, entity: str) -> Generator[AssociationItem, None, None]: for generic in utils.chain_iter(mapAspect): kind = GetIirKindOfNode(generic) if kind is nodes.Iir_Kind.Association_Element_By_Expression: formalNode = nodes.Get_Formal(generic) if formalNode is nodes.Null_Iir: formal = None else: formal = GetNameFromNode(formalNode) actual = GetExpressionFromNode(nodes.Get_Actual(generic)) yield cls(generic, actual, formal) elif kind is nodes.Iir_Kind.Association_Element_Open: formalNode = nodes.Get_Formal(generic) if formalNode is nodes.Null_Iir: formal = None else: formal = GetNameFromNode(formalNode) yield cls(generic, OpenName(generic), formal) else: pos = Position.parse(generic) raise DOMException( "Unknown association kind '{kind}' in {entity} map at line {line}." .format(kind=kind.name, entity=entity, line=pos.Line))
def parse(cls, loopNode: Iir, label: str) -> "ForLoopStatement": from pyGHDL.dom._Utils import GetIirKindOfNode from pyGHDL.dom._Translate import ( GetSequentialStatementsFromChainedNodes, GetRangeFromNode, GetNameFromNode, ) spec = nodes.Get_Parameter_Specification(loopNode) loopIndex = GetNameOfNode(spec) discreteRange = nodes.Get_Discrete_Range(spec) rangeKind = GetIirKindOfNode(discreteRange) if rangeKind == nodes.Iir_Kind.Range_Expression: rng = GetRangeFromNode(discreteRange) elif rangeKind in ( nodes.Iir_Kind.Attribute_Name, nodes.Iir_Kind.Parenthesis_Name, ): rng = GetNameFromNode(discreteRange) else: pos = Position.parse(loopNode) raise DOMException( "Unknown discete range kind '{kind}' in for...loop statement at line {line}.".format( kind=rangeKind.name, line=pos.Line ) ) statementChain = nodes.Get_Sequential_Statement_Chain(loopNode) statements = GetSequentialStatementsFromChainedNodes(statementChain, "for", label) return cls(loopNode, loopIndex, rng, statements, label)
def parse(cls, typeName: str, typeDefinitionNode: Iir) -> "PhysicalType": from pyGHDL.dom._Utils import GetIirKindOfNode, GetNameOfNode from pyGHDL.dom._Translate import GetRangeFromNode, GetNameFromNode rangeConstraint = nodes.Get_Range_Constraint(typeDefinitionNode) rangeKind = GetIirKindOfNode(rangeConstraint) if rangeKind == nodes.Iir_Kind.Range_Expression: rng = GetRangeFromNode(rangeConstraint) elif rangeKind in ( nodes.Iir_Kind.Attribute_Name, nodes.Iir_Kind.Parenthesis_Name, ): rng = GetNameFromNode(rangeConstraint) else: pos = Position.parse(typeDefinitionNode) raise DOMException( "Unknown range kind '{kind}' in physical type definition at line {line}." .format(kind=rangeKind.name, line=pos.Line)) primaryUnit = nodes.Get_Primary_Unit(typeDefinitionNode) primaryUnitName = GetNameOfNode(primaryUnit) units = [] for secondaryUnit in utils.chain_iter( nodes.Get_Unit_Chain(typeDefinitionNode)): secondaryUnitName = GetNameOfNode(secondaryUnit) if secondaryUnit == primaryUnit: continue physicalLiteral = PhysicalIntegerLiteral.parse( nodes.Get_Physical_Literal(secondaryUnit)) units.append((secondaryUnitName, physicalLiteral)) return cls(typeDefinitionNode, typeName, rng, primaryUnitName, units)
def parse(cls, contextNode: Iir): from pyGHDL.dom._Utils import GetIirKindOfNode name = GetNameOfNode(contextNode) items = [] names = [] for item in utils.chain_iter(nodes.Get_Context_Items(contextNode)): kind = GetIirKindOfNode(item) if kind is nodes.Iir_Kind.Library_Clause: names.append(SimpleName(item, GetNameOfNode(item))) if nodes.Get_Has_Identifier_List(item): continue items.append(LibraryClause(item, names)) names = [] elif kind is nodes.Iir_Kind.Use_Clause: items.append(UseClause.parse(item)) else: pos = Position.parse(item) raise DOMException( "Unknown context item kind '{kind}' in context at line {line}." .format(kind=kind.name, line=pos.Line)) return cls(contextNode, name, items)
def parse(cls, attributeNode: Iir) -> "AttributeSpecification": attributeDesignator = nodes.Get_Attribute_Designator(attributeNode) attributeName = GetNameFromNode(attributeDesignator) names = [] entityNameList = nodes.Get_Entity_Name_List(attributeNode) for name in utils.flist_iter(entityNameList): nameKind = GetIirKindOfNode(name) if nameKind == nodes.Iir_Kind.Simple_Name: names.append(SimpleName(name, GetNameOfNode(name))) elif nameKind == nodes.Iir_Kind.Signature: print( "[NOT IMPLEMENTED] Signature name in attribute specifications." ) else: position = Position.parse(name) raise DOMException( "Unknown name kind '{kind}' in attribute specification '{attr}' at {file}:{line}:{column}." .format( kind=nameKind.name, attr=attributeNode, file=position.Filename, line=position.Line, column=position.Column, )) entityClassToken = nodes.Get_Entity_Class(attributeNode) try: entityClass = _TOKEN_TRANSLATION[entityClassToken] except KeyError: position = Position.parse(attributeNode) raise DOMException( "Unknown token '{token}' in attribute specification for entity class '{entityClass}' at {file}:{line}:{column}." .format( token=entityClassToken.name, entityClass=attributeNode, file=position.Filename, line=position.Line, column=position.Column, )) expression = GetExpressionFromNode(nodes.Get_Expression(attributeNode)) return cls(attributeNode, names, attributeName, entityClass, expression)
def GetParameterFromChainedNodes( nodeChain: Iir, ) -> Generator[ParameterInterfaceItem, None, None]: parameter = nodeChain while parameter != nodes.Null_Iir: kind = GetIirKindOfNode(parameter) if kind == nodes.Iir_Kind.Interface_Constant_Declaration: from pyGHDL.dom.InterfaceItem import ParameterConstantInterfaceItem param = ParameterConstantInterfaceItem.parse(parameter) elif kind == nodes.Iir_Kind.Interface_Variable_Declaration: from pyGHDL.dom.InterfaceItem import ParameterVariableInterfaceItem param = ParameterVariableInterfaceItem.parse(parameter) elif kind == nodes.Iir_Kind.Interface_Signal_Declaration: from pyGHDL.dom.InterfaceItem import ParameterSignalInterfaceItem param = ParameterSignalInterfaceItem.parse(parameter) elif kind == nodes.Iir_Kind.Interface_File_Declaration: from pyGHDL.dom.InterfaceItem import ParameterFileInterfaceItem param = ParameterFileInterfaceItem.parse(parameter) else: position = Position.parse(parameter) raise DOMException( "Unknown parameter kind '{kind}' in parameter '{param}' at {file}:{line}:{column}." .format( kind=kind.name, param=parameter, file=position.Filename, line=position.Line, column=position.Column, )) # Lookahead for parameters with multiple identifiers at once if nodes.Get_Has_Identifier_List(parameter): nextNode = nodes.Get_Chain(parameter) for nextParameter in utils.chain_iter(nextNode): # Consecutive identifiers are found, if the subtype indication is Null if nodes.Get_Subtype_Indication( nextParameter) == nodes.Null_Iir: param.Identifiers.append(GetNameOfNode(nextParameter)) else: parameter = nextParameter break # The last consecutive identifiers has no Identifier_List flag if not nodes.Get_Has_Identifier_List(nextParameter): parameter = nodes.Get_Chain(nextParameter) break else: parameter = nodes.Null_Iir else: parameter = nodes.Get_Chain(parameter) yield param
def parse(cls, node: Iir) -> "Aggregate": from pyGHDL.dom._Translate import ( GetExpressionFromNode, GetRangeFromNode, GetNameFromNode, ) choices = [] choicesChain = nodes.Get_Association_Choices_Chain(node) for item in utils.chain_iter(choicesChain): kind = GetIirKindOfNode(item) value = GetExpressionFromNode(nodes.Get_Associated_Expr(item)) if kind == nodes.Iir_Kind.Choice_By_None: choices.append(SimpleAggregateElement(item, value)) elif kind == nodes.Iir_Kind.Choice_By_Expression: index = GetExpressionFromNode(nodes.Get_Choice_Expression(item)) choices.append(IndexedAggregateElement(item, index, value)) elif kind == nodes.Iir_Kind.Choice_By_Range: choiceRange = nodes.Get_Choice_Range(item) rangeKind = GetIirKindOfNode(choiceRange) if rangeKind == nodes.Iir_Kind.Range_Expression: rng = GetRangeFromNode(choiceRange) elif rangeKind in ( nodes.Iir_Kind.Attribute_Name, nodes.Iir_Kind.Parenthesis_Name, ): rng = GetNameFromNode(choiceRange) else: pos = Position.parse(item) raise DOMException( "Unknown discete range kind '{kind}' in for...generate statement at line {line}.".format( kind=rangeKind.name, line=pos.Line ) ) choices.append(RangedAggregateElement(item, rng, value)) elif kind == nodes.Iir_Kind.Choice_By_Name: name = GetNameFromNode(nodes.Get_Choice_Name(item)) symbol = Symbol(item, name) choices.append(NamedAggregateElement(item, symbol, value)) elif kind == nodes.Iir_Kind.Choice_By_Others: choices.append(OthersAggregateElement(item, value)) else: raise DOMException( "Unknown choice kind '{kind}' in aggregate '{aggr}'.".format(kind=kind.name, aggr=node) ) return cls(node, choices)
def GetSequentialStatementsFromChainedNodes( nodeChain: Iir, entity: str, name: str) -> Generator[SequentialStatement, None, None]: for statement in utils.chain_iter(nodeChain): label = nodes.Get_Label(statement) label = name_table.Get_Name_Ptr( label) if label != nodes.Null_Iir else None pos = Position.parse(statement) kind = GetIirKindOfNode(statement) if kind == nodes.Iir_Kind.If_Statement: yield IfStatement.parse(statement, label) elif kind == nodes.Iir_Kind.For_Loop_Statement: yield ForLoopStatement.parse(statement, label) elif kind == nodes.Iir_Kind.Case_Statement: yield CaseStatement.parse(statement, label) elif kind == nodes.Iir_Kind.Simple_Signal_Assignment_Statement: yield SequentialSimpleSignalAssignment.parse(statement, label) elif kind in ( nodes.Iir_Kind.Variable_Assignment_Statement, nodes.Iir_Kind.Conditional_Variable_Assignment_Statement, ): print( "[NOT IMPLEMENTED] Variable assignment (label: '{label}') at line {line}" .format(label=label, line=pos.Line)) elif kind == nodes.Iir_Kind.Wait_Statement: yield WaitStatement.parse(statement, label) elif kind == nodes.Iir_Kind.Procedure_Call_Statement: yield SequentialProcedureCall.parse(statement, label) elif kind == nodes.Iir_Kind.Report_Statement: yield SequentialReportStatement.parse(statement, label) elif kind == nodes.Iir_Kind.Assertion_Statement: yield SequentialAssertStatement.parse(statement, label) elif kind == nodes.Iir_Kind.Null_Statement: yield NullStatement(statement, label) else: raise DOMException( "Unknown statement of kind '{kind}' in {entity} '{name}' at {file}:{line}:{column}." .format( kind=kind.name, entity=entity, name=name, file=pos.Filename, line=pos.Line, column=pos.Column, ))
def GetPortsFromChainedNodes( nodeChain: Iir, ) -> Generator[PortInterfaceItem, None, None]: port = nodeChain while port != nodes.Null_Iir: kind = GetIirKindOfNode(port) if kind == nodes.Iir_Kind.Interface_Signal_Declaration: from pyGHDL.dom.InterfaceItem import PortSignalInterfaceItem portSignal = PortSignalInterfaceItem.parse(port) # Lookahead for ports with multiple identifiers at once if nodes.Get_Has_Identifier_List(port): nextNode = nodes.Get_Chain(port) for nextPort in utils.chain_iter(nextNode): # Consecutive identifiers are found, if the subtype indication is Null if nodes.Get_Subtype_Indication( nextPort) == nodes.Null_Iir: portSignal.Identifiers.append(GetNameOfNode(nextPort)) else: port = nextPort break # The last consecutive identifiers has no Identifier_List flag if not nodes.Get_Has_Identifier_List(nextPort): port = nodes.Get_Chain(nextPort) break else: port = nodes.Null_Iir else: port = nodes.Get_Chain(port) yield portSignal continue else: position = Position.parse(port) raise DOMException( "Unknown port kind '{kind}' in port '{port}' at {file}:{line}:{column}." .format( kind=kind.name, port=port, file=position.Filename, line=position.Line, column=position.Column, ))
def GetExpressionFromNode(node: Iir) -> ExpressionUnion: kind = GetIirKindOfNode(node) try: cls = __EXPRESSION_TRANSLATION[kind] except KeyError: position = Position.parse(node) raise DOMException( "Unknown expression kind '{kind}' in expression '{expr}' at {file}:{line}:{column}." .format( kind=kind.name, expr=node, file=position.Filename, line=position.Line, column=position.Column, )) return cls.parse(node)
def parse(cls, generateNode: Iir, label: str) -> "ForGenerateStatement": from pyGHDL.dom._Utils import GetIirKindOfNode from pyGHDL.dom._Translate import ( GetDeclaredItemsFromChainedNodes, GetConcurrentStatementsFromChainedNodes, GetRangeFromNode, GetNameFromNode, ) spec = nodes.Get_Parameter_Specification(generateNode) loopIndex = GetNameOfNode(spec) discreteRange = nodes.Get_Discrete_Range(spec) rangeKind = GetIirKindOfNode(discreteRange) if rangeKind == nodes.Iir_Kind.Range_Expression: rng = GetRangeFromNode(discreteRange) elif rangeKind in ( nodes.Iir_Kind.Attribute_Name, nodes.Iir_Kind.Parenthesis_Name, ): rng = GetNameFromNode(discreteRange) else: pos = Position.parse(generateNode) raise DOMException( "Unknown discete range kind '{kind}' in for...generate statement at line {line}." .format(kind=rangeKind.name, line=pos.Line)) body = nodes.Get_Generate_Statement_Body(generateNode) declarationChain = nodes.Get_Declaration_Chain(body) declaredItems = GetDeclaredItemsFromChainedNodes( declarationChain, "for-generate", label) statementChain = nodes.Get_Concurrent_Statement_Chain(body) statements = GetConcurrentStatementsFromChainedNodes( statementChain, "for-generate", label) return cls(generateNode, label, loopIndex, rng, declaredItems, statements)
def parse(cls, caseNode: Iir, label: str) -> "CaseStatement": from pyGHDL.dom._Utils import GetIirKindOfNode from pyGHDL.dom._Translate import ( GetExpressionFromNode, GetRangeFromNode, GetNameFromNode, ) expression = GetExpressionFromNode(nodes.Get_Expression(caseNode)) cases = [] choices = None alternative = nodes.Get_Case_Statement_Alternative_Chain(caseNode) cNode = alternative while alternative != nodes.Null_Iir: choiceKind = GetIirKindOfNode(alternative) sameAlternative = nodes.Get_Same_Alternative_Flag(alternative) if choiceKind in ( nodes.Iir_Kind.Choice_By_Name, nodes.Iir_Kind.Choice_By_Expression, ): choiceExpression = GetExpressionFromNode(nodes.Get_Choice_Expression(alternative)) choice = IndexedChoice(alternative, choiceExpression) if sameAlternative: choices.append(choice) alternative = nodes.Get_Chain(alternative) continue elif choiceKind is nodes.Iir_Kind.Choice_By_Range: choiceRange = nodes.Get_Choice_Range(alternative) choiceRangeKind = GetIirKindOfNode(choiceRange) if choiceRangeKind == nodes.Iir_Kind.Range_Expression: rng = GetRangeFromNode(choiceRange) elif choiceRangeKind in ( nodes.Iir_Kind.Attribute_Name, nodes.Iir_Kind.Parenthesis_Name, ): rng = GetNameFromNode(choiceRange) else: pos = Position.parse(alternative) raise DOMException( "Unknown choice range kind '{kind}' in case statement at line {line}.".format( kind=choiceRangeKind.name, line=pos.Line ) ) choice = RangedChoice(alternative, rng) if sameAlternative: choices.append(choice) alternative = nodes.Get_Chain(alternative) continue elif choiceKind is nodes.Iir_Kind.Choice_By_Others: if choices is not None: cases.append(Case.parse(alternative, choices, label)) choices = None cases.append(OthersCase.parse(alternative, label)) alternative = nodes.Get_Chain(alternative) cNode = alternative continue else: pos = Position.parse(alternative) raise DOMException( "Unknown choice kind '{kind}' in case statement at line {line}.".format( kind=choiceKind.name, line=pos.Line ) ) if choices is not None: cases.append(Case.parse(cNode, choices, label)) cNode = alternative choices = [ choice, ] alternative = nodes.Get_Chain(alternative) if choices is not None: cases.append(Case.parse(cNode, choices, label)) return cls(caseNode, label, expression, cases)
def GetConcurrentStatementsFromChainedNodes( nodeChain: Iir, entity: str, name: str) -> Generator[ConcurrentStatement, None, None]: for statement in utils.chain_iter(nodeChain): label = nodes.Get_Label(statement) label = name_table.Get_Name_Ptr( label) if label != nodes.Null_Iir else None pos = Position.parse(statement) kind = GetIirKindOfNode(statement) if kind == nodes.Iir_Kind.Sensitized_Process_Statement: yield ProcessStatement.parse(statement, label, True) elif kind == nodes.Iir_Kind.Process_Statement: yield ProcessStatement.parse(statement, label, False) elif kind == nodes.Iir_Kind.Concurrent_Simple_Signal_Assignment: yield ConcurrentSimpleSignalAssignment.parse(statement, label) elif kind == nodes.Iir_Kind.Concurrent_Conditional_Signal_Assignment: print( "[NOT IMPLEMENTED] Concurrent (conditional) signal assignment (label: '{label}') at line {line}" .format(label=label, line=pos.Line)) elif kind == nodes.Iir_Kind.Concurrent_Selected_Signal_Assignment: print( "[NOT IMPLEMENTED] Concurrent (selected) signal assignment (label: '{label}') at line {line}" .format(label=label, line=pos.Line)) elif kind == nodes.Iir_Kind.Concurrent_Procedure_Call_Statement: yield ConcurrentProcedureCall.parse(statement, label) elif kind == nodes.Iir_Kind.Component_Instantiation_Statement: instantiatedUnit = nodes.Get_Instantiated_Unit(statement) instantiatedUnitKind = GetIirKindOfNode(instantiatedUnit) if instantiatedUnitKind == nodes.Iir_Kind.Entity_Aspect_Entity: yield EntityInstantiation.parse(statement, instantiatedUnit, label) elif instantiatedUnitKind == nodes.Iir_Kind.Entity_Aspect_Configuration: yield ConfigurationInstantiation.parse(statement, instantiatedUnit, label) elif instantiatedUnitKind == nodes.Iir_Kind.Simple_Name: yield ComponentInstantiation.parse(statement, instantiatedUnit, label) else: raise DOMException( "Unknown instantiation kind '{kind}' in instantiation of label {label} at {file}:{line}:{column}." .format( kind=instantiatedUnitKind.name, label=label, file=pos.Filename, line=pos.Line, column=pos.Column, )) elif kind == nodes.Iir_Kind.Block_Statement: yield ConcurrentBlockStatement.parse(statement, label) elif kind == nodes.Iir_Kind.If_Generate_Statement: yield IfGenerateStatement.parse(statement, label) elif kind == nodes.Iir_Kind.Case_Generate_Statement: yield CaseGenerateStatement.parse(statement, label) elif kind == nodes.Iir_Kind.For_Generate_Statement: yield ForGenerateStatement.parse(statement, label) elif kind == nodes.Iir_Kind.Psl_Assert_Directive: yield ConcurrentAssertStatement.parse(statement, label) else: raise DOMException( "Unknown statement of kind '{kind}' in {entity} '{name}' at {file}:{line}:{column}." .format( kind=kind.name, entity=entity, name=name, file=pos.Filename, line=pos.Line, column=pos.Column, ))
def GetDeclaredItemsFromChainedNodes( nodeChain: Iir, entity: str, name: str) -> Generator[ModelEntity, None, None]: item = nodeChain lastKind = None while item != nodes.Null_Iir: kind = GetIirKindOfNode(item) if kind == nodes.Iir_Kind.Constant_Declaration: from pyGHDL.dom.Object import Constant obj = Constant.parse(item) elif kind == nodes.Iir_Kind.Variable_Declaration: from pyGHDL.dom.Object import SharedVariable if nodes.Get_Shared_Flag(item): obj = SharedVariable.parse(item) else: obj = Variable.parse(item) elif kind == nodes.Iir_Kind.Signal_Declaration: from pyGHDL.dom.Object import Signal obj = Signal.parse(item) elif kind == nodes.Iir_Kind.File_Declaration: from pyGHDL.dom.Object import File obj = File.parse(item) else: if kind == nodes.Iir_Kind.Type_Declaration: yield GetTypeFromNode(item) elif kind == nodes.Iir_Kind.Anonymous_Type_Declaration: yield GetAnonymousTypeFromNode(item) elif kind == nodes.Iir_Kind.Subtype_Declaration: yield GetSubtypeFromNode(item) elif kind == nodes.Iir_Kind.Function_Declaration: if nodes.Get_Has_Body(item): yield Function.parse(item) else: print( "[NOT IMPLEMENTED] function declaration without body") lastKind = kind item = nodes.Get_Chain(item) continue elif kind == nodes.Iir_Kind.Function_Body: if lastKind is nodes.Iir_Kind.Function_Declaration: pass else: position = Position.parse(item) raise DOMException( "Found unexpected function body '{functionName}' in {entity} '{name}' at {file}:{line}:{column}." .format( functionName=GetNameOfNode(item), entity=entity, name=name, file=position.Filename, line=position.Line, column=position.Column, )) elif kind == nodes.Iir_Kind.Procedure_Declaration: if nodes.Get_Has_Body(item): yield Procedure.parse(item) else: print( "[NOT IMPLEMENTED] procedure declaration without body") lastKind = kind item = nodes.Get_Chain(item) continue elif kind == nodes.Iir_Kind.Procedure_Body: if lastKind is nodes.Iir_Kind.Procedure_Declaration: pass else: position = Position.parse(item) raise DOMException( "Found unexpected procedure body '{functionName}' in {entity} '{name}' at {file}:{line}:{column}." .format( functionName=GetNameOfNode(item), entity=entity, name=name, file=position.Filename, line=position.Line, column=position.Column, )) elif kind == nodes.Iir_Kind.Protected_Type_Body: yield ProtectedTypeBody.parse(item) elif kind == nodes.Iir_Kind.Object_Alias_Declaration: yield GetAliasFromNode(item) elif kind == nodes.Iir_Kind.Component_Declaration: from pyGHDL.dom.DesignUnit import Component yield Component.parse(item) elif kind == nodes.Iir_Kind.Attribute_Declaration: from pyGHDL.dom.Attribute import Attribute yield Attribute.parse(item) elif kind == nodes.Iir_Kind.Attribute_Specification: from pyGHDL.dom.Attribute import AttributeSpecification yield AttributeSpecification.parse(item) elif kind == nodes.Iir_Kind.Use_Clause: from pyGHDL.dom.DesignUnit import UseClause yield UseClause.parse(item) elif kind == nodes.Iir_Kind.Package_Declaration: from pyGHDL.dom.DesignUnit import Package yield Package.parse(item, None) # TODO: Can it have a context? elif kind == nodes.Iir_Kind.Package_Instantiation_Declaration: from pyGHDL.dom.DesignUnit import PackageInstantiation yield PackageInstantiation.parse(item) elif kind == nodes.Iir_Kind.Configuration_Specification: print( "[NOT IMPLEMENTED] Configuration specification in {name}". format(name=name)) elif kind == nodes.Iir_Kind.Psl_Default_Clock: yield DefaultClock.parse(item) elif kind == nodes.Iir_Kind.Group_Declaration: print("[NOT IMPLEMENTED] Group declaration in {name}".format( name=name)) elif kind == nodes.Iir_Kind.Group_Template_Declaration: print("[NOT IMPLEMENTED] Group template declaration in {name}". format(name=name)) elif kind == nodes.Iir_Kind.Disconnection_Specification: print("[NOT IMPLEMENTED] Disconnect specification in {name}". format(name=name)) else: position = Position.parse(item) raise DOMException( "Unknown declared item kind '{kind}' in {entity} '{name}' at {file}:{line}:{column}." .format( kind=kind.name, entity=entity, name=name, file=position.Filename, line=position.Line, column=position.Column, )) lastKind = None item = nodes.Get_Chain(item) continue # Lookahead for objects with multiple identifiers at once if nodes.Get_Has_Identifier_List(item): nextNode = nodes.Get_Chain(item) for nextItem in utils.chain_iter(nextNode): # Consecutive identifiers are found, if the subtype indication is Null if nodes.Get_Subtype_Indication(nextItem) == nodes.Null_Iir: obj.Identifiers.append(GetNameOfNode(nextItem)) else: item = nextItem break # The last consecutive identifiers has no Identifier_List flag if not nodes.Get_Has_Identifier_List(nextItem): item = nodes.Get_Chain(nextItem) break else: item = nodes.Null_Iir else: item = nodes.Get_Chain(item) yield obj
def translate(self): firstUnit = nodes.Get_First_Design_Unit(self.__ghdlFile) for unit in utils.chain_iter(firstUnit): libraryUnit = nodes.Get_Library_Unit(unit) nodeKind = GetIirKindOfNode(libraryUnit) contextItems = [] contextNames = [] context = nodes.Get_Context_Items(unit) if context is not nodes.Null_Iir: for item in utils.chain_iter(context): itemKind = GetIirKindOfNode(item) if itemKind is nodes.Iir_Kind.Library_Clause: contextNames.append( SimpleName(item, GetNameOfNode(item))) if nodes.Get_Has_Identifier_List(item): continue contextItems.append(LibraryClause(item, contextNames)) contextNames = [] elif itemKind is nodes.Iir_Kind.Use_Clause: contextItems.append(UseClause.parse(item)) elif itemKind is nodes.Iir_Kind.Context_Reference: contextItems.append(ContextReference.parse(item)) else: pos = Position.parse(item) raise DOMException( "Unknown context item kind '{kind}' in context at line {line}." .format(kind=itemKind.name, line=pos.Line)) if nodeKind == nodes.Iir_Kind.Entity_Declaration: entity = Entity.parse(libraryUnit, contextItems) self.Entities.append(entity) elif nodeKind == nodes.Iir_Kind.Architecture_Body: architecture = Architecture.parse(libraryUnit, contextItems) self.Architectures.append(architecture) elif nodeKind == nodes.Iir_Kind.Package_Declaration: package = Package.parse(libraryUnit, contextItems) self.Packages.append(package) elif nodeKind == nodes.Iir_Kind.Package_Body: packageBody = PackageBody.parse(libraryUnit, contextItems) self.PackageBodies.append(packageBody) elif nodeKind == nodes.Iir_Kind.Package_Instantiation_Declaration: package = PackageInstantiation.parse(libraryUnit) self.Packages.append(package) elif nodeKind == nodes.Iir_Kind.Context_Declaration: context = Context.parse(libraryUnit) self.Contexts.append(context) elif nodeKind == nodes.Iir_Kind.Configuration_Declaration: configuration = Configuration.parse(libraryUnit, contextItems) self.Configurations.append(configuration) elif nodeKind == nodes.Iir_Kind.Vunit_Declaration: vunit = VerificationUnit.parse(libraryUnit) self.VerificationUnits.append(vunit) elif nodeKind == nodes.Iir_Kind.Vprop_Declaration: vprop = VerificationProperty.parse(libraryUnit) self.VerificationProperties.append(vprop) elif nodeKind == nodes.Iir_Kind.Vmode_Declaration: vmod = VerificationMode.parse(libraryUnit) self.VerificationModes.append(vmod) else: raise DOMException("Unknown design unit kind '{kind}'.".format( kind=nodeKind.name))
def GetGenericsFromChainedNodes( nodeChain: Iir, ) -> Generator[GenericInterfaceItem, None, None]: from pyGHDL.dom.InterfaceItem import ( GenericTypeInterfaceItem, GenericPackageInterfaceItem, GenericProcedureInterfaceItem, GenericFunctionInterfaceItem, ) generic = nodeChain while generic != nodes.Null_Iir: kind = GetIirKindOfNode(generic) if kind == nodes.Iir_Kind.Interface_Constant_Declaration: from pyGHDL.dom.InterfaceItem import GenericConstantInterfaceItem genericConstant = GenericConstantInterfaceItem.parse(generic) # Lookahead for generics with multiple identifiers at once if nodes.Get_Has_Identifier_List(generic): nextNode = nodes.Get_Chain(generic) for nextGeneric in utils.chain_iter(nextNode): # Consecutive identifiers are found, if the subtype indication is Null if nodes.Get_Subtype_Indication( nextGeneric) == nodes.Null_Iir: genericConstant.Identifiers.append( GetNameOfNode(nextGeneric)) else: generic = nextGeneric break # The last consecutive identifiers has no Identifier_List flag if not nodes.Get_Has_Identifier_List(nextGeneric): generic = nodes.Get_Chain(nextGeneric) break else: generic = nodes.Null_Iir else: generic = nodes.Get_Chain(generic) yield genericConstant continue else: if kind == nodes.Iir_Kind.Interface_Type_Declaration: yield GenericTypeInterfaceItem.parse(generic) elif kind == nodes.Iir_Kind.Interface_Package_Declaration: yield GenericPackageInterfaceItem.parse(generic) elif kind == nodes.Iir_Kind.Interface_Procedure_Declaration: yield GenericProcedureInterfaceItem.parse(generic) elif kind == nodes.Iir_Kind.Interface_Function_Declaration: yield GenericFunctionInterfaceItem.parse(generic) else: position = Position.parse(generic) raise DOMException( "Unknown generic kind '{kind}' in generic '{generic}' at {file}:{line}:{column}." .format( kind=kind.name, generic=generic, file=position.Filename, line=position.Line, column=position.Column, )) generic = nodes.Get_Chain(generic)