From 597bc9928352ba187bdb0a707332a5f7a0a28e1a Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Mon, 16 Aug 2021 23:56:16 +0200 Subject: Handle context references. --- pyGHDL/dom/DesignUnit.py | 26 ++++++++++++++++++++++---- pyGHDL/dom/NonStandard.py | 3 +++ 2 files changed, 25 insertions(+), 4 deletions(-) (limited to 'pyGHDL/dom') diff --git a/pyGHDL/dom/DesignUnit.py b/pyGHDL/dom/DesignUnit.py index c905a439d..7f4d8e964 100644 --- a/pyGHDL/dom/DesignUnit.py +++ b/pyGHDL/dom/DesignUnit.py @@ -47,6 +47,7 @@ from pydecor import export from pyVHDLModel.SyntaxModel import ( LibraryClause as VHDLModel_LibraryClause, UseClause as VHDLModel_UseClause, + ContextReference as VHDLModel_ContextReference, Entity as VHDLModel_Entity, Architecture as VHDLModel_Architecture, Package as VHDLModel_Package, @@ -82,16 +83,16 @@ __all__ = [] @export class LibraryClause(VHDLModel_LibraryClause, DOMMixin): - def __init__(self, node: Iir, names: Iterable[Name]): + def __init__(self, libraryNode: Iir, names: Iterable[Name]): super().__init__(names) - DOMMixin.__init__(self, node) + DOMMixin.__init__(self, libraryNode) @export class UseClause(VHDLModel_UseClause, DOMMixin): - def __init__(self, node: Iir, names: Iterable[Name]): + def __init__(self, useNode: Iir, names: Iterable[Name]): super().__init__(names) - DOMMixin.__init__(self, node) + DOMMixin.__init__(self, useNode) @classmethod def parse(cls, useNode: Iir): @@ -104,6 +105,23 @@ class UseClause(VHDLModel_UseClause, DOMMixin): return cls(useNode, uses) +@export +class ContextReference(VHDLModel_ContextReference, DOMMixin): + def __init__(self, contextNode: Iir, names: Iterable[Name]): + super().__init__(names) + DOMMixin.__init__(self, contextNode) + + @classmethod + def parse(cls, contextNode: Iir): + from pyGHDL.dom._Translate import GetNameFromNode + + contexts = [GetNameFromNode(nodes.Get_Selected_Name(contextNode))] + for context in utils.chain_iter(nodes.Get_Context_Reference_Chain(contextNode)): + contexts.append(GetNameFromNode(nodes.Get_Selected_Name(context))) + + return cls(contextNode, contexts) + + @export class Entity(VHDLModel_Entity, DOMMixin): def __init__( diff --git a/pyGHDL/dom/NonStandard.py b/pyGHDL/dom/NonStandard.py index b59efeacb..1cd98b4fa 100644 --- a/pyGHDL/dom/NonStandard.py +++ b/pyGHDL/dom/NonStandard.py @@ -74,6 +74,7 @@ from pyGHDL.dom.DesignUnit import ( PackageInstantiation, LibraryClause, UseClause, + ContextReference, ) from pyGHDL.dom.PSL import VerificationUnit, VerificationProperty, VerificationMode @@ -189,6 +190,8 @@ class Document(VHDLModel_Document): 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( -- cgit v1.2.3