files.new_contents: # Copyright (c) 2013 Potential Ventures Ltd
  # Copyright (c) 2013 SolarFlare Communications Inc
  # All rights reserved.
  #
  # Redistribution and use in source and binary forms, with or without
  # modification, are permitted provided that the following conditions are met:
  #     * Redistributions of source code must retain the above copyright
  #       notice, this list of conditions and the following disclaimer.
  #     * Redistributions in binary form must reproduce the above copyright
  #       notice, this list of conditions and the following disclaimer in the
  #       documentation and/or other materials provided with the distribution.
  #     * Neither the name of Potential Ventures Ltd,
  #       SolarFlare Communications Inc nor the
  #       names of its contributors may be used to endorse or promote products
  #       derived from this software without specific prior written permission.
  #
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  # DISCLAIMED. IN NO EVENT SHALL POTENTIAL VENTURES LTD BE LIABLE FOR ANY
  # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
  import sys
  import time
  import logging
  import functools
  import inspect
  import os
  
  import cocotb
  from cocotb.log import SimLog
  from cocotb.result import ReturnValue
  from cocotb.utils import get_sim_time, lazy_property, remove_traceback_frames, extract_coro_stack
  from cocotb import outcomes
  
  # Sadly the Python standard logging module is very slow so it's better not to
  # make any calls by testing a boolean flag first
  if "COCOTB_SCHEDULER_DEBUG" in os.environ:
      _debug = True
  else:
      _debug = False
  
  
  def public(f):
      """Use a decorator to avoid retyping function/class names.
  
      * Based on an idea by Duncan Booth:
      http://groups.google.com/group/comp.lang.python/msg/11cbb03e09611b8a
      * Improved via a suggestion by Dave Angel:
      http://groups.google.com/group/comp.lang.python/msg/3d400fb22d8a42e1
      """
      all = sys.modules[f.__module__].__dict__.setdefault('__all__', [])
      if f.__name__ not in all:  # Prevent duplicates if run from an IDE.
          all.append(f.__name__)
      return f
  
  
  public(public)  # Emulate decorating ourself
  
  
  @public
  class CoroutineComplete(Exception):
      """To ensure that a coroutine has completed before we fire any triggers
      that are blocked waiting for the coroutine to end, we create a sub-class
      exception that the scheduler catches and the callbacks are attached
      here.
      """
  
      def __init__(self, text=""):
          Exception.__init__(self, text)
  
  
  class RunningTask:
      """Per instance wrapper around a running generator.
  
      Provides the following:
  
          task.join() creates a Trigger that will fire when this coroutine
          completes.
  
          task.kill() will destroy a coroutine instance (and cause any Join
          triggers to fire.
      """
  
      _id_count = 0  # used by the scheduler for debug
  
      def __init__(self, inst):
  
          if inspect.iscoroutine(inst):
              self._natively_awaitable = True
          elif inspect.isgenerator(inst):
              self._natively_awaitable = False
          elif inspect.iscoroutinefunction(inst):
              raise TypeError(
                  "Coroutine function {} should be called prior to being "
                  "scheduled."
                  .format(inst))
          elif sys.version_info >= (3, 6) and inspect.isasyncgen(inst):
              raise TypeError(
                  "{} is an async generator, not a coroutine. "
                  "
  
  [... the rest is omitted ...]
files.new_path: cocotb/decorators.py
files.old_contents: # Copyright (c) 2013 Potential Ventures Ltd
  # Copyright (c) 2013 SolarFlare Communications Inc
  # All rights reserved.
  #
  # Redistribution and use in source and binary forms, with or without
  # modification, are permitted provided that the following conditions are met:
  #     * Redistributions of source code must retain the above copyright
  #       notice, this list of conditions and the following disclaimer.
  #     * Redistributions in binary form must reproduce the above copyright
  #       notice, this list of conditions and the following disclaimer in the
  #       documentation and/or other materials provided with the distribution.
  #     * Neither the name of Potential Ventures Ltd,
  #       SolarFlare Communications Inc nor the
  #       names of its contributors may be used to endorse or promote products
  #       derived from this software without specific prior written permission.
  #
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  # DISCLAIMED. IN NO EVENT SHALL POTENTIAL VENTURES LTD BE LIABLE FOR ANY
  # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
  import sys
  import time
  import logging
  import functools
  import inspect
  import os
  
  import cocotb
  from cocotb.log import SimLog
  from cocotb.result import ReturnValue
  from cocotb.utils import get_sim_time, lazy_property, remove_traceback_frames
  from cocotb import outcomes
  
  # Sadly the Python standard logging module is very slow so it's better not to
  # make any calls by testing a boolean flag first
  if "COCOTB_SCHEDULER_DEBUG" in os.environ:
      _debug = True
  else:
      _debug = False
  
  
  def public(f):
      """Use a decorator to avoid retyping function/class names.
  
      * Based on an idea by Duncan Booth:
      http://groups.google.com/group/comp.lang.python/msg/11cbb03e09611b8a
      * Improved via a suggestion by Dave Angel:
      http://groups.google.com/group/comp.lang.python/msg/3d400fb22d8a42e1
      """
      all = sys.modules[f.__module__].__dict__.setdefault('__all__', [])
      if f.__name__ not in all:  # Prevent duplicates if run from an IDE.
          all.append(f.__name__)
      return f
  
  
  public(public)  # Emulate decorating ourself
  
  
  @public
  class CoroutineComplete(Exception):
      """To ensure that a coroutine has completed before we fire any triggers
      that are blocked waiting for the coroutine to end, we create a sub-class
      exception that the scheduler catches and the callbacks are attached
      here.
      """
  
      def __init__(self, text=""):
          Exception.__init__(self, text)
  
  
  class RunningTask:
      """Per instance wrapper around a running generator.
  
      Provides the following:
  
          task.join() creates a Trigger that will fire when this coroutine
          completes.
  
          task.kill() will destroy a coroutine instance (and cause any Join
          triggers to fire.
      """
  
      def __init__(self, inst):
  
          if inspect.iscoroutine(inst):
              self._natively_awaitable = True
          elif inspect.isgenerator(inst):
              self._natively_awaitable = False
          elif inspect.iscoroutinefunction(inst):
              raise TypeError(
                  "Coroutine function {} should be called prior to being "
                  "scheduled."
                  .format(inst))
          elif sys.version_info >= (3, 6) and inspect.isasyncgen(inst):
              raise TypeError(
                  "{} is an async generator, not a coroutine. "
                  "You likely used the yield keyword instead of await.".format(
                      inst.__qualname__))
          else
  
  [... the rest is omitted ...]
files.old_path: cocotb/decorators.py
files.new_contents: # Copyright (c) 2013 Potential Ventures Ltd
  # Copyright (c) 2013 SolarFlare Communications Inc
  # All rights reserved.
  #
  # Redistribution and use in source and binary forms, with or without
  # modification, are permitted provided that the following conditions are met:
  #     * Redistributions of source code must retain the above copyright
  #       notice, this list of conditions and the following disclaimer.
  #     * Redistributions in binary form must reproduce the above copyright
  #       notice, this list of conditions and the following disclaimer in the
  #       documentation and/or other materials provided with the distribution.
  #     * Neither the name of Potential Ventures Ltd,
  #       SolarFlare Communications Inc nor the
  #       names of its contributors may be used to endorse or promote products
  #       derived from this software without specific prior written permission.
  #
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  # DISCLAIMED. IN NO EVENT SHALL POTENTIAL VENTURES LTD BE LIABLE FOR ANY
  # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
  """Collection of handy functions."""
  
  import ctypes
  import math
  import os
  import sys
  import traceback
  import weakref
  import functools
  import warnings
  
  from cocotb import simulator
  
  
  def _get_simulator_precision():
      # cache and replace this function
      precision = simulator.get_precision()
      global _get_simulator_precision
      _get_simulator_precision = precision.__int__
      return _get_simulator_precision()
  
  
  def get_python_integer_types():
      warnings.warn(
          "This is an internal cocotb function, use six.integer_types instead",
          DeprecationWarning)
      return (int,)
  
  
  # Simulator helper functions
  def get_sim_time(units=None):
      """Retrieves the simulation time from the simulator.
  
      Args:
          units (str or None, optional): String specifying the units of the result
              (one of ``None``, ``'fs'``, ``'ps'``, ``'ns'``, ``'us'``, ``'ms'``, ``'sec'``).
              ``None`` will return the raw simulation time.
  
      Returns:
          The simulation time in the specified units.
      """
      timeh, timel = simulator.get_sim_time()
  
      result = (timeh << 32 | timel)
  
      if units is not None:
          result = get_time_from_sim_steps(result, units)
  
      return result
  
  
  def _ldexp10(frac, exp):
      """ Like math.ldexp, but base 10 """
      # using * or / separately prevents rounding errors if `frac` is a
      # high-precision type
      if exp > 0:
          return frac * (10 ** exp)
      else:
          return frac / (10 ** -exp)
  
  
  def get_time_from_sim_steps(steps, units):
      """Calculates simulation time in the specified *units* from the *steps* based
      on the simulator precision.
  
      Args:
          steps (int): Number of simulation steps.
          units (str): String specifying the units of the result
              (one of ``'fs'``, ``'ps'``, ``'ns'``, ``'us'``, ``'ms'``, ``'sec'``).
  
      Returns:
          The simulation time in the specified units.
      """
      return _ldexp10(steps, _get_simulator_precision() - _get_log_time_scale(units))
  
  
  def get_sim_steps(time, units=None):
      """Calculates the number of simulation time steps for a given amount of *time*.
  
      Args:
          time (numbers.Real or decimal.Decimal):  The value to convert to simulation time steps.
          units
  
  [... the rest is omitted ...]
files.new_path: cocotb/utils.py
files.old_contents: # Copyright (c) 2013 Potential Ventures Ltd
  # Copyright (c) 2013 SolarFlare Communications Inc
  # All rights reserved.
  #
  # Redistribution and use in source and binary forms, with or without
  # modification, are permitted provided that the following conditions are met:
  #     * Redistributions of source code must retain the above copyright
  #       notice, this list of conditions and the following disclaimer.
  #     * Redistributions in binary form must reproduce the above copyright
  #       notice, this list of conditions and the following disclaimer in the
  #       documentation and/or other materials provided with the distribution.
  #     * Neither the name of Potential Ventures Ltd,
  #       SolarFlare Communications Inc nor the
  #       names of its contributors may be used to endorse or promote products
  #       derived from this software without specific prior written permission.
  #
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  # DISCLAIMED. IN NO EVENT SHALL POTENTIAL VENTURES LTD BE LIABLE FOR ANY
  # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
  """Collection of handy functions."""
  
  import ctypes
  import math
  import os
  import sys
  import weakref
  import functools
  import warnings
  
  from cocotb import simulator
  
  
  def _get_simulator_precision():
      # cache and replace this function
      precision = simulator.get_precision()
      global _get_simulator_precision
      _get_simulator_precision = precision.__int__
      return _get_simulator_precision()
  
  
  def get_python_integer_types():
      warnings.warn(
          "This is an internal cocotb function, use six.integer_types instead",
          DeprecationWarning)
      return (int,)
  
  
  # Simulator helper functions
  def get_sim_time(units=None):
      """Retrieves the simulation time from the simulator.
  
      Args:
          units (str or None, optional): String specifying the units of the result
              (one of ``None``, ``'fs'``, ``'ps'``, ``'ns'``, ``'us'``, ``'ms'``, ``'sec'``).
              ``None`` will return the raw simulation time.
  
      Returns:
          The simulation time in the specified units.
      """
      timeh, timel = simulator.get_sim_time()
  
      result = (timeh << 32 | timel)
  
      if units is not None:
          result = get_time_from_sim_steps(result, units)
  
      return result
  
  
  def _ldexp10(frac, exp):
      """ Like math.ldexp, but base 10 """
      # using * or / separately prevents rounding errors if `frac` is a
      # high-precision type
      if exp > 0:
          return frac * (10 ** exp)
      else:
          return frac / (10 ** -exp)
  
  
  def get_time_from_sim_steps(steps, units):
      """Calculates simulation time in the specified *units* from the *steps* based
      on the simulator precision.
  
      Args:
          steps (int): Number of simulation steps.
          units (str): String specifying the units of the result
              (one of ``'fs'``, ``'ps'``, ``'ns'``, ``'us'``, ``'ms'``, ``'sec'``).
  
      Returns:
          The simulation time in the specified units.
      """
      return _ldexp10(steps, _get_simulator_precision() - _get_log_time_scale(units))
  
  
  def get_sim_steps(time, units=None):
      """Calculates the number of simulation time steps for a given amount of *time*.
  
      Args:
          time (numbers.Real or decimal.Decimal):  The value to convert to simulation time steps.
          units (str or None
  
  [... the rest is omitted ...]
files.old_path: cocotb/utils.py