<commit_before>from hwt.synthesizer.unit import Unit
from hwt.synthesizer.exceptions import IntfLvlConfErr
from hwt.doc_markers import internal
from ipCorePackager.constants import DIRECTION


class EmptyUnit(Unit):
    """
    Unit used for prototyping all output interfaces are connected
    to _def_val and this is only think which architecture contains

    :cvar _def_val: this value is used to initialize all signals
    """
    _def_val = None

    @internal
    def _toRtl(self, targetPlatform):
        assert not self._wasSynthetised()
        self._targetPlatform = targetPlatform

        if not hasattr(self, "_name"):
            self._name = self._getDefaultName()

        self._loadMyImplementations()
        # construct params for entity (generics)
        self._ctx.params = self._buildParams()
        externInterf = {}
        # prepare connections
        for i in self._interfaces:
            i._signalsForInterface(self._ctx, externInterf, reverse_dir=True)
            if not i._isExtern:
                raise IntfLvlConfErr(
                    "All interfaces in EmptyUnit has to be extern, %s: %s is not"
                    % (self.__class__.__name__, i._getFullName()))
        # connect outputs to dummy value
        for s, d in externInterf.items():
            if d == DIRECTION.OUT:
                s(s._dtype.from_py(self._def_val))

        if not externInterf:
            raise IntfLvlConfErr(
                "Can not find any external interface for unit %s"
                "- unit without interfaces are not allowed"
                % self._name)
        yield from self._synthetiseContext(externInterf)
        # self._checkEntityPortDirections()<commit_msg>EmptyUnit: update for new serializer api<commit_after>from hwt.synthesizer.interface import Interface
from hwt.synthesizer.unit import Unit
from ipCorePackager.constants import INTF_DIRECTION


def connect_to_const(val, intf: Interface):
    """
    Connect constant to all output ports, used mainly during the debbug
    to dissable interface
    """
    if intf._interfaces:
        for i in intf._interfaces:
            connect_to_const(val, i)
    else:
        if intf._direction == INTF_DIRECTION.SLAVE:
            intf(val)


class EmptyUnit(Unit):
    """
    Unit used for prototyping all output interfaces are connected
    to _def_val and this is only think which architecture contains

    :cvar _def_val: this value is used to initialize all signals
    """
    _def_val = None

    def _impl(self):
        for i in self._interfaces:
            connect_to_const(self._def_val, i)
{'fraction_non_alphanumeric': 0.06846153846153846, 'fraction_numerical': 0.0, 'mean_word_length': 2.514864864864865, 'pattern_counts': {'":': 0, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6428652', 'n_tokens_mistral': 748, 'n_tokens_neox': 714, 'n_words': 228}