pyGHDL.dom._Utils
This module offers helper functions to read an IIR node’s kind, name, label, mode and documentation.
Functions
CheckForErrors(): Check if an error occurred in libghdl and raise an exception if so.GetIirKindOfNode(): Return the kind of a node in the IIR tree.GetNameOfNode(): Return the Python string from nodenodeidentifier.GetLabelOfNode(): Return the Python string from nodenode’s optional label.GetSourceTextOfNode(): Reads the source text starting at an IIR node’s location.GetDocumentationOfNode(): Collects the doc-comment lines attached to an IIR node.GetDocumentationOfDesignUnit(): Collects the doc-comment lines of a design unit (entity, architecture, package, …).GetModeOfNode(): Return the mode of anode.
Functions
- pyGHDL.dom._Utils.CheckForErrors()[source]
Check if an error occurred in libghdl and raise an exception if so.
Behavior:
read the error buffer and clear it afterwards.
convert it into a list of internal messages for a
LibGHDLException.raise a
DOMExceptionwith a nestedLibGHDLExceptionas a__cause__.
- Raises:
DOMException – If an error occurred in libghdl.
- Return type:
- pyGHDL.dom._Utils.GetIirKindOfNode(node)[source]
Return the kind of a node in the IIR tree.
- Parameters:
node (
Iir) – The IIR node to read the kind of.- Return type:
- Returns:
The IIR kind of a node.
- Raises:
ValueError – If parameter
nodeisNull_Iir.
- pyGHDL.dom._Utils.GetNameOfNode(node)[source]
Return the Python string from node
nodeidentifier.A character literal (
'0') is returned as its character, without quotes (0). An operator symbol ("and") is returned with its quotation marks.- Parameters:
node (
Iir) – The IIR node to read the identifier of.- Return type:
- Returns:
The node’s identifier as written in the source file.
- Raises:
ValueError – If parameter
nodeisNull_Iir.
- pyGHDL.dom._Utils.GetLabelOfNode(node)[source]
Return the Python string from node
node’s optional label.A statement carries its label in
Label, while a generate-statement body - the branch of an if-generate or case-generate statement - carries it inAlternative_Label. No node kind has both, so the field is chosen from the node’s kind.The label is returned as written in the source file (
U1), read at the node’s location, which is the label’s.- Parameters:
node (
Iir) – The IIR node to read the label of.- Return type:
- Returns:
The label, or
Noneif the node has no label field or no label was given in the source.- Raises:
ValueError – If parameter
nodeisNull_Iir.
- pyGHDL.dom._Utils.GetSourceTextOfNode(node, length=None)[source]
Reads the source text starting at an IIR node’s location.
- pyGHDL.dom._Utils.GetDocumentationOfNode(node)[source]
Collects the doc-comment lines attached to an IIR node.
libghdl only gathers comments if
Flag_Gather_Commentswas enabled before parsing, whichDesigndoes.
- pyGHDL.dom._Utils.GetDocumentationOfDesignUnit(unitNode)[source]
Collects the doc-comment lines of a design unit (entity, architecture, package, …).
In IIR, a design unit is a
Design_Unitnode holding the context clause and the unit’s declaration (theLibrary_Unit), as in IEEE Std 1076, 13.1. A design unit’s documentation consists of the comments libghdl attached to theDesign_Unitnode (the comments before the unit, except the file header), followed by the comments attached to the declaration node itself. A nested package has noDesign_Unitnode, so only its own comments are read.
- pyGHDL.dom._Utils.GetModeOfNode(node)[source]
Return the mode of a
node.If the source text gives no mode (
generic (G : natural)), the mode isDefault.- Parameters:
node (
Iir) – The IIR node to read the mode of.- Return type:
- Returns:
The node’s mode as a pyVHDLModel enumeration value.
- Raises:
ValueError – If parameter
nodeisNull_Iir.DOMException – If mode returned by libghdl is not known by
__MODE_TRANSLATION.