<commit_before># Copyright edalize contributors
# Licensed under the 2-Clause BSD License, see LICENSE for details.
# SPDX-License-Identifier: BSD-2-Clause

import collections
import logging
import os.path
from edalize.edatool import Edatool

logger = logging.getLogger(__name__)


class Ghdl(Edatool):

    argtypes = ['vlogparam', 'generic']

    @classmethod
    def get_doc(cls, api_ver):
        if api_ver == 0:
            return {'description' : "GHDL is an open source VHDL simulator, which fully supports IEEE 1076-1987, IEEE 1076-1993, IEE 1076-2002 and partially the 1076-2008 version of VHDL",
                    'lists' : [
                        {'name' : 'analyze_options',
                         'type' : 'String',
                         'desc' : 'Options to use for the import (ghdl -i) and make (ghdl -m) phases'},
                        {'name' : 'run_options',
                         'type' : 'String',
                         'desc' : 'Options to use for the run (ghdl -r) phase'},
                        ]}

    def configure_main(self):
        (src_files, incdirs) = self._get_fileset_files()
        analyze_options = self.tool_options.get('analyze_options', '')

        # Check of std=xx analyze option, this overyides the dynamic determination of vhdl standard
        import re
        rx = re.compile("^--std=([0-9]+)")
        m = None
        for o in analyze_options:
            m = rx.match(o)
            if m:
                stdarg = [ m.group() ]
                analyze_options.remove(o)
                break

        if m:
          logger.warning("Analyze option "+ m.group() + " given, will override any vhdlSource-xxxx specification\n")
          standard = m.group(1)
        else:
            # ghdl does not support mixing incompatible versions
            # specifying 93c as std should allow 87 syntax
            # 2008 can't be combined so try to parse everthing with 08 std


            has87 = has93 = has08 = False
            for f in src_files:
                if f.file_type == "vhdlSource-87":
                    has87 = True
                elif f.file_type == "vhdlSource-93":
                    has93 = True
                elif f.file_type == "vhdlSource-2008":
                    has08 = True
            stdarg = []
            if has08:
                if has87 or has93:
                    logger.warning("ghdl can't mix vhdlSource-2008 with other standard version\n"+
                                   "Trying with treating all as vhdlSource-2008"
                    )
                stdarg = ['--std=08']
            elif has87 and has93:
                stdarg = ['--std=93c']
            elif has87:
                stdarg = ['--std=87']
            elif has93:
                stdarg = ['--std=93']
            else:
                stdarg = ['--std=93c']

            standard =  rx.match(stdarg[0]).group(1)


        run_options = self.tool_options.get('run_options', [])

        analyze_options=' '.join(analyze_options)

        _vhdltypes = ("vhdlSource", "vhdlSource-87", "vhdlSource-93", "vhdlSource-2008")

        libraries = collections.OrderedDict()
        library_options = "--work={lib} --workdir=./{lib}"
        ghdlimport = ""
        vhdl_sources = ""

        # GHDL doesn't support the dot notation used by other tools (e.g.
        # my_lib.top_design) for the top level so work around this if the user
        # has specified the top level in this manner.<commit_msg>[GHDL] Dot notation for specifying my_lib.top_unit is supported<commit_after># Copyright edalize contributors
# Licensed under the 2-Clause BSD License, see LICENSE for details.
# SPDX-License-Identifier: BSD-2-Clause

import collections
import logging
import os.path
from edalize.edatool import Edatool

logger = logging.getLogger(__name__)


class Ghdl(Edatool):

    argtypes = ['vlogparam', 'generic']

    @classmethod
    def get_doc(cls, api_ver):
        if api_ver == 0:
            return {'description' : "GHDL is an open source VHDL simulator, which fully supports IEEE 1076-1987, IEEE 1076-1993, IEE 1076-2002 and partially the 1076-2008 version of VHDL",
                    'lists' : [
                        {'name' : 'analyze_options',
                         'type' : 'String',
                         'desc' : 'Options to use for the import (ghdl -i) and make (ghdl -m) phases'},
                        {'name' : 'run_options',
                         'type' : 'String',
                         'desc' : 'Options to use for the run (ghdl -r) phase'},
                        ]}

    def configure_main(self):
        (src_files, incdirs) = self._get_fileset_files()
        analyze_options = self.tool_options.get('analyze_options', '')

        # Check of std=xx analyze option, this overyides the dynamic determination of vhdl standard
        import re
        rx = re.compile("^--std=([0-9]+)")
        m = None
        for o in analyze_options:
            m = rx.match(o)
            if m:
                stdarg = [ m.group() ]
                analyze_options.remove(o)
                break

        if m:
          logger.warning("Analyze option "+ m.group() + " given, will override any vhdlSource-xxxx specification\n")
          standard = m.group(1)
        else:
            # ghdl does not support mixing incompatible versions
            # specifying 93c as std should allow 87 syntax
            # 2008 can't be combined so try to parse everthing with 08 std


            has87 = has93 = has08 = False
            for f in src_files:
                if f.file_type == "vhdlSource-87":
                    has87 = True
                elif f.file_type == "vhdlSource-93":
                    has93 = True
                elif f.file_type == "vhdlSource-2008":
                    has08 = True
            stdarg = []
            if has08:
                if has87 or has93:
                    logger.warning("ghdl can't mix vhdlSource-2008 with other standard version\n"+
                                   "Trying with treating all as vhdlSource-2008"
                    )
                stdarg = ['--std=08']
            elif has87 and has93:
                stdarg = ['--std=93c']
            elif has87:
                stdarg = ['--std=87']
            elif has93:
                stdarg = ['--std=93']
            else:
                stdarg = ['--std=93c']

            standard =  rx.match(stdarg[0]).group(1)


        run_options = self.tool_options.get('run_options', [])

        analyze_options=' '.join(analyze_options)

        _vhdltypes = ("vhdlSource", "vhdlSource-87", "vhdlSource-93", "vhdlSource-2008")

        libraries = collections.OrderedDict()
        library_options = "--work={lib} --workdir=./{lib}"
        ghdlimport = ""
        vhdl_sources = ""

        # GHDL versions older than 849a25e0 don't support the dot notation (e.g.
        # my_lib.top_design) for the top level.
        # Nonetheless, we unconditionally split the library and the primary unit,
        # if the user specified the top level using the dot notation.
{'fraction_non_alphanumeric': 0.1008462623413258, 'fraction_numerical': 0.03187588152327221, 'mean_word_length': 1.6331229112513925, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '178753', 'n_tokens_mistral': 2194, 'n_tokens_neox': 1921, 'n_words': 590}