<commit_before>import importlib
import os
import sys
from types import ModuleType
from typing import Optional

from hwt.serializer.simModel.serializer import SimModelSerializer
from hwt.simulator.basicRtlSimConfigVcd import BasicRtlSimConfigVcd
from hwt.synthesizer.dummyPlatform import DummyPlatform
from hwt.synthesizer.unit import Unit
from hwt.synthesizer.utils import toRtl
from pycocotb.basic_hdl_simulator.rtlSimulator import BasicRtlSimulator


class BasicRtlSimulatorWithVCD(BasicRtlSimulator):

    def __init__(self, synthesised_unit):
        BasicRtlSimulator.__init__(self)
        self.synthesised_unit = synthesised_unit

    def set_trace_file(self, file_name, trace_depth):
        self.config = BasicRtlSimConfigVcd(open(file_name, "w"))
        beforeSim = self.config.beforeSim
        if beforeSim is not None:
            beforeSim(self, self.synthesised_unit, self.model)

    def finalize(self):
        self.config.vcdWriter._oFile.close()<commit_msg>BasicRtlSimulatorWithVCD: support for no logging<commit_after>import importlib
import os
import sys
from types import ModuleType
from typing import Optional

from hwt.serializer.simModel.serializer import SimModelSerializer
from hwt.simulator.basicRtlSimConfigVcd import BasicRtlSimConfigVcd
from hwt.synthesizer.dummyPlatform import DummyPlatform
from hwt.synthesizer.unit import Unit
from hwt.synthesizer.utils import toRtl
from pycocotb.basic_hdl_simulator.rtlSimulator import BasicRtlSimulator


class BasicRtlSimulatorWithVCD(BasicRtlSimulator):

    def __init__(self, synthesised_unit):
        BasicRtlSimulator.__init__(self)
        self.synthesised_unit = synthesised_unit

    def set_trace_file(self, file_name, trace_depth):
        self.config = BasicRtlSimConfigVcd(open(file_name, "w"))
        beforeSim = self.config.beforeSim
        if beforeSim is not None:
            beforeSim(self, self.synthesised_unit, self.model)

    def finalize(self):
        # because set_trace_file() may not be called
        # and it this case the vcd config is not set
        if isinstance(self.config, BasicRtlSimConfigVcd):
            self.config.vcdWriter._oFile.close()
{'fraction_non_alphanumeric': 0.061196105702364396, 'fraction_numerical': 0.0, 'mean_word_length': 4.463291139240506, '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': '404822', 'n_tokens_mistral': 674, 'n_tokens_neox': 647, 'n_words': 154}