files.new_contents: #!/usr/bin/env python
  
  # Copyright (c) 2013, 2018 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.
  
  """Coroutine scheduler.
  
  
  FIXME: We have a problem here.  If a coroutine schedules a read-only but we
  also have pending writes we have to schedule the ReadWrite callback before
  the ReadOnly (and this is invalid, at least in Modelsim).
  """
  import collections
  import copy
  import os
  import time
  import logging
  import threading
  
  
  # For autodocumentation don't need the extension modules
  if "SPHINX_BUILD" in os.environ:
      simulator = None
  else:
      import simulator
  
  # Debug mode controlled by environment variables
  if "COCOTB_ENABLE_PROFILING" in os.environ:
      import cProfile, StringIO, pstats
      _profile = cProfile.Profile()
      _profiling = True
  else:
      _profiling = False
  
  # 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
  
  
  import cocotb
  import cocotb.decorators
  from cocotb.triggers import (Trigger, GPITrigger, Timer, ReadOnly, PythonTrigger,
                               NextTimeStep, ReadWrite, Event, Join)
  from cocotb.log import SimLog
  from cocotb.result import (TestComplete, TestError, ReturnValue, raise_error,
                             create_error, ExternalException)
  from cocotb.utils import nullcontext
  
  
  class profiling_context(object):
      """ Context manager that profiles its contents """
      def __enter__(self):
          _profile.enable()
  
      def __exit__(self, *excinfo):
          _profile.disable()
  
  
  class external_state(object):
      INIT = 0
      RUNNING = 1
      PAUSED = 2
      EXITED = 3
  
  @cocotb.decorators.public
  class external_waiter(object):
  
      def __init__(self):
          self.result = None
          self.thread = None
          self.event = Event()
          self.state = external_state.INIT
          self.cond = threading.Condition()
          self._log = SimLog("cocotb.external.thead.%s" % self.thread, id(self))
  
      def _propogate_state(self, new_state):
          self.cond.acquire()
          if _debug:
              self._log.debug("Changing state from %d -> %d from %s" % (self.state, new_state, threading.current_thread()))
          self.state = new_state
          self.cond.notify()
          self.cond.release()
  
      def thread
  
  [... the rest is omitted ...]
files.new_path: cocotb/scheduler.py
files.old_contents: #!/usr/bin/env python
  
  # Copyright (c) 2013, 2018 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.
  
  """Coroutine scheduler.
  
  
  FIXME: We have a problem here.  If a coroutine schedules a read-only but we
  also have pending writes we have to schedule the ReadWrite callback before
  the ReadOnly (and this is invalid, at least in Modelsim).
  """
  import collections
  import copy
  import os
  import time
  import logging
  import threading
  
  
  # For autodocumentation don't need the extension modules
  if "SPHINX_BUILD" in os.environ:
      simulator = None
  else:
      import simulator
  
  # Debug mode controlled by environment variables
  if "COCOTB_ENABLE_PROFILING" in os.environ:
      import cProfile, StringIO, pstats
      _profile = cProfile.Profile()
      _profiling = True
  else:
      _profiling = False
  
  # 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
  
  
  import cocotb
  import cocotb.decorators
  from cocotb.triggers import (Trigger, GPITrigger, Timer, ReadOnly, PythonTrigger,
                               NextTimeStep, ReadWrite, Event, Join)
  from cocotb.log import SimLog
  from cocotb.result import (TestComplete, TestError, ReturnValue, raise_error,
                             create_error, ExternalException)
  
  class external_state(object):
      INIT = 0
      RUNNING = 1
      PAUSED = 2
      EXITED = 3
  
  @cocotb.decorators.public
  class external_waiter(object):
  
      def __init__(self):
          self.result = None
          self.thread = None
          self.event = Event()
          self.state = external_state.INIT
          self.cond = threading.Condition()
          self._log = SimLog("cocotb.external.thead.%s" % self.thread, id(self))
  
      def _propogate_state(self, new_state):
          self.cond.acquire()
          if _debug:
              self._log.debug("Changing state from %d -> %d from %s" % (self.state, new_state, threading.current_thread()))
          self.state = new_state
          self.cond.notify()
          self.cond.release()
  
      def thread_done(self):
          if _debug:
              self._log.debug("Thread finished from %s" % (threading.current_thread()))
          self._propogate_state(external_state.EXITED)
  
      def thread_suspend(self):
          self._prop
  
  [... the rest is omitted ...]
files.old_path: cocotb/scheduler.py
files.new_contents: from __future__ import print_function
  
  # Copyright (c) 2013, 2018 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
  
  # For autodocumentation don't need the extension modules
  if "SPHINX_BUILD" in os.environ:
      simulator = None
      _LOG_SIM_PRECISION = -15
  else:
      import simulator
      _LOG_SIM_PRECISION = simulator.get_precision() # request once and cache
  
  # python2 to python3 helper functions
  def get_python_integer_types():
      try:
          isinstance(1, long)
      except NameError:
          return (int,)  # python 3
      else:
          return (int, long)  # python 2
  
  # 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 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.
      """
      result = steps * (10.0**(_LOG_SIM_PRECISION - _get_log_time_scale(units)))
  
      return result
  
  def get_sim_steps(time, units=None):
      """Calculates the number of simulation time steps for a given amount of *time*.
  
      Args:
          time (int or float):  The value to convert to simulation time steps.
          units (str or None, optional):  String specifying the units of the result
              (one of ``None``, ``'fs'``, ``'ps'``, ``'ns'``, ``'us'``, ``'ms'
  
  [... the rest is omitted ...]
files.new_path: cocotb/utils.py
files.old_contents: from __future__ import print_function
  
  # Copyright (c) 2013, 2018 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
  
  # For autodocumentation don't need the extension modules
  if "SPHINX_BUILD" in os.environ:
      simulator = None
      _LOG_SIM_PRECISION = -15
  else:
      import simulator
      _LOG_SIM_PRECISION = simulator.get_precision() # request once and cache
  
  # python2 to python3 helper functions
  def get_python_integer_types():
      try:
          isinstance(1, long)
      except NameError:
          return (int,)  # python 3
      else:
          return (int, long)  # python 2
  
  # 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 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.
      """
      result = steps * (10.0**(_LOG_SIM_PRECISION - _get_log_time_scale(units)))
  
      return result
  
  def get_sim_steps(time, units=None):
      """Calculates the number of simulation time steps for a given amount of *time*.
  
      Args:
          time (int or float):  The value to convert to simulation time steps.
          units (str or None, optional):  String specifying the units of the result
              (one of ``None``, ``'fs'``, ``'ps'``, ``'ns'``, ``'us'``, ``'ms'
  
  [... the rest is omitted ...]
files.old_path: cocotb/utils.py