aboutsummaryrefslogtreecommitdiffstats
path: root/pyGHDL/libghdl/libraries.py
blob: 7dd4170543082880a72f736bfbd10a76ad0eb32b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58pre { line-height: 125%; margin: 0; }
td.linenos pre { color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px; }
span.linenos { color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px; }
td.linenos pre.special { color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight { background: #ffffff; }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlig
# =============================================================================
#               ____ _   _ ____  _       _ _ _           _         _ _
#  _ __  _   _ / ___| | | |  _ \| |     | (_) |__   __ _| |__   __| | |
# | '_ \| | | | |  _| |_| | | | | |     | | | '_ \ / _` | '_ \ / _` | |
# | |_) | |_| | |_| |  _  | |_| | |___ _| | | |_) | (_| | | | | (_| | |
# | .__/ \__, |\____|_| |_|____/|_____(_)_|_|_.__/ \__, |_| |_|\__,_|_|
# |_|    |___/                                     |___/
# =============================================================================
#  Authors:
#    Tristan Gingold
#    Patrick Lehmann
#
# Package module:   Python binding and low-level API for shared library 'libghdl'.
#
# License:
# ============================================================================
#  Copyright (C) 2019-2021 Tristan Gingold
#
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <gnu.org/licenses>.
#
# SPDX-License-Identifier: GPL-2.0-or-later
# ============================================================================

from ctypes import c_int32

from pydecor import export

from pyGHDL.libghdl import libghdl
from pyGHDL.libghdl._types import (
    NameId,
    Iir_Library_Declaration,
    Iir_Design_Unit,
    Iir_Design_File,
    LocationType,
)
from pyGHDL.libghdl._decorator import BindToLibGHDL

__all__ = ["Library_Location", "Work_Library"]

Library_Location: LocationType = c_int32.in_dll(libghdl, "libraries__library_location")
"""
A location for library declarations (such as library WORK). Use ``.value`` to
access this variable inside libghdl.
"""

Work_Library: Iir_Library_Declaration = c_int32.in_dll(
    libghdl, "libraries__work_library"
)
"""
Library declaration for the work library. Note: the identifier of the work_library
is ``work_library_name``, which may be different from 'WORK'. Use ``.value`` to
access this variable inside libghdl.
"""


@export
@BindToLibGHDL("libraries__get_libraries_chain")
def Get_Libraries_Chain() -> Iir_Library_Declaration:
    """
    Get the chain of libraries. Can be used only to read (it mustn't be modified).

    :return: undocumented
    """


@export
@BindToLibGHDL("libraries__add_design_unit_into_library")
def Add_Design_Unit_Into_Library(Unit: Iir_Design_Unit, Keep_Obsolete: bool) -> None:
    """
    Add or replace an design unit in the work library. DECL must not have a chain
    (because it may be modified).

    If the design_file of UNIT is not already in the library, a new one is created.

    Units are always appended to the design_file. Therefore, the order is kept.

    :param Unit:          undocumented
    :param Keep_Obsolete: If :obj:`Keep_Obsolete` is True, obsoleted units are
                          kept in the library.

                          This is used when a whole design file has to be added
                          in the library and then processed (without that feature,
                          redefined units would disappear).
    """


@export
@BindToLibGHDL("libraries__purge_design_file")
def Purge_Design_File(Design_File: Iir_Design_File) -> None:
    """
    Remove the same file as :obj:`Design_File` from work library and all of its units.

    :param Design_File: undocumented
    """


@export
@BindToLibGHDL("libraries__find_entity_for_component")
def Find_Entity_For_Component(Name: NameId) -> Iir_Design_Unit:
    """
    Find an entity whose name is :obj:`Name` in any library. |br|
    If there is no such entity, return :attr:`~pyGHDL.libghdl.vhdl.nodes.Null_Iir`. |br|
    If there are several entities, return :attr:`~pyGHDL.libghdl.vhdl.nodes.Null_Iir`;

    :param Name: Entity name to search for.
    :return:     undocumented
    """


@export
@BindToLibGHDL("libraries__get_library_no_create")
def Get_Library_No_Create(Ident: NameId) -> Iir_Library_Declaration:
    """
    Get the library named :obj:`Ident`.

    :param Ident: Library to look for.
    :return:      Return :attr:`~pyGHDL.libghdl.vhdl.nodes.Null_Iir` if it doesn't exist.
    """


@export
@BindToLibGHDL("libraries__find_primary_unit")
def Find_Primary_Unit(
    Library: Iir_Library_Declaration, Name: NameId
) -> Iir_Design_Unit:
    """
    Just return the design_unit for :obj:`Name`, or ``NULL`` if not found.

    :param Library: Library to look in.
    :param Name:    Primary unit to search for.
    :return:        undocumented
    """