def setimmediatevalue(self, value): """ Set the value of the underlying simulation object to value. Args: value (ctypes.Structure, cocotb.binary.BinaryValue, int, double) The value to drive onto the simulator object Raises: TypeError This operation will fail unless the handle refers to a modifiable object eg net, signal or variable. We determine the library call to make based on the type of the value Assigning integers less than 32-bits is faster """ if isinstance(value, get_python_integer_types()) and value < 0x7fffffff: simulator.set_signal_val_long(self._handle, value) return if isinstance(value, ctypes.Structure): value = BinaryValue(value=cocotb.utils.pack(value), bits=len(self)) elif isinstance(value, get_python_integer_types()): value = BinaryValue(value=value, bits=len(self), bigEndian=False) elif not isinstance(value, BinaryValue): self._log.critical( "Unsupported type for value assignment: %s (%s)" % (type(value), repr(value))) raise TypeError("Unable to set simulator value with type %s" % (type(value))) simulator.set_signal_val_str(self._handle, value.binstr)
def setimmediatevalue(self, value): """ Set the value of the underlying simulation object to value. Args: value (ctypes.Structure, cocotb.binary.BinaryValue, int, double) The value to drive onto the simulator object Raises: TypeError This operation will fail unless the handle refers to a modifiable object eg net, signal or variable. We determine the library call to make based on the type of the value Assigning integers less than 32-bits is faster """ if isinstance(value, get_python_integer_types()) and value < 0x7fffffff: simulator.set_signal_val_long(self._handle, value) return if isinstance(value, ctypes.Structure): value = BinaryValue(value=cocotb.utils.pack(value), bits=len(self)) elif isinstance(value, get_python_integer_types()): value = BinaryValue(value=value, bits=len(self), bigEndian=False) elif not isinstance(value, BinaryValue): self._log.critical("Unsupported type for value assignment: %s (%s)" % (type(value), repr(value))) raise TypeError("Unable to set simulator value with type %s" % (type(value))) simulator.set_signal_val_str(self._handle, value.binstr)
def setimmediatevalue(self, value): """Set the value of the underlying simulation object to *value*. This operation will fail unless the handle refers to a modifiable object, e.g. net, signal or variable. Args: value (int): The value to drive onto the simulator object. Raises: TypeError: If target has an unsupported type for integer value assignment. """ value, set_action = self._check_for_set_action(value) if isinstance(value, BinaryValue): value = int(value) elif not isinstance(value, int): self._log.critical( "Unsupported type for integer value assignment: %s (%s)", type(value), repr(value)) raise TypeError("Unable to set simulator value with type %s" % (type(value))) simulator.set_signal_val_long(self._handle, set_action, value)
def setimmediatevalue(self, value): """ Set the value of the underlying simulation object to value. Args: value (ctypes.Structure, cocotb.binary.BinaryValue, int, double) The value to drive onto the simulator object Raises: TypeError This operation will fail unless the handle refers to a modifiable object eg net, signal or variable. We determine the library call to make based on the type of the value Assigning integers less than 32-bits is faster """ if isinstance(value, get_python_integer_types() ) and value < 0x7fffffff and len(self) <= 32: simulator.set_signal_val_long(self._handle, value) return if isinstance(value, ctypes.Structure): value = BinaryValue(value=cocotb.utils.pack(value), n_bits=len(self)) elif isinstance(value, get_python_integer_types()): value = BinaryValue(value=value, n_bits=len(self), bigEndian=False) elif isinstance(value, dict): #We're given a dictionary with a list of values and a bit size... num = 0 vallist = list(value["values"]) vallist.reverse() if len(vallist) * value["bits"] != len(self): self._log.critical( "Unable to set with array length %d of %d bit entries = %d total, target is only %d bits long" % (len(value["values"]), value["bits"], len(value["values"]) * value["bits"], len(self))) raise TypeError( "Unable to set with array length %d of %d bit entries = %d total, target is only %d bits long" % (len(value["values"]), value["bits"], len(value["values"]) * value["bits"], len(self))) for val in vallist: num = (num << value["bits"]) + val value = BinaryValue(value=num, n_bits=len(self), bigEndian=False) elif not isinstance(value, BinaryValue): self._log.critical( "Unsupported type for value assignment: %s (%s)" % (type(value), repr(value))) raise TypeError("Unable to set simulator value with type %s" % (type(value))) simulator.set_signal_val_str(self._handle, value.binstr)
def setimmediatevalue(self, value): """ Set the value of the underlying simulation object to value. Args: value (ctypes.Structure, cocotb.binary.BinaryValue, int, double) The value to drive onto the simulator object Raises: TypeError This operation will fail unless the handle refers to a modifiable object eg net, signal or variable. We determine the library call to make based on the type of the value Assigning integers less than 32-bits is faster """ if isinstance(value, get_python_integer_types()) and value < 0x7fffffff: simulator.set_signal_val_long(self._handle, value) return if isinstance(value, ctypes.Structure): value = BinaryValue(value=cocotb.utils.pack(value), bits=len(self)) elif isinstance(value, get_python_integer_types()): value = BinaryValue(value=value, bits=len(self), bigEndian=False) elif isinstance(value, dict): #We're given a dictionary with a list of values and a bit size... num = 0; vallist = list(value["values"]) vallist.reverse() if len(vallist) * value["bits"] != len(self): self._log.critical("Unable to set with array length %d of %d bit entries = %d total, target is only %d bits long" % (len(value["values"]), value["bits"], len(value["values"]) * value["bits"], len(self))); raise TypeError("Unable to set with array length %d of %d bit entries = %d total, target is only %d bits long" % (len(value["values"]), value["bits"], len(value["values"]) * value["bits"], len(self))); for val in vallist: num = (num << value["bits"]) + val; value = BinaryValue(value=num, bits=len(self), bigEndian=False) elif not isinstance(value, BinaryValue): self._log.critical("Unsupported type for value assignment: %s (%s)" % (type(value), repr(value))) raise TypeError("Unable to set simulator value with type %s" % (type(value))) simulator.set_signal_val_str(self._handle, value.binstr)
def setimmediatevalue(self, value): """Set the value of the underlying simulation object to value. This operation will fail unless the handle refers to a modifiable object, e.g. net, signal or variable. Args: value (int): The value to drive onto the simulator object. Raises: TypeError: If target has an unsupported type for integer value assignment. """ if isinstance(value, BinaryValue): value = int(value) elif not isinstance(value, get_python_integer_types()): self._log.critical("Unsupported type for integer value assignment: %s (%s)" % (type(value), repr(value))) raise TypeError("Unable to set simulator value with type %s" % (type(value))) simulator.set_signal_val_long(self._handle, value)
def setimmediatevalue(self, value): """ Set the value of the underlying simulation object to value. Args: value (int) The value to drive onto the simulator object Raises: TypeError This operation will fail unless the handle refers to a modifiable object eg net, signal or variable. """ if isinstance(value, BinaryValue): value = int(value) elif not isinstance(value, get_python_integer_types()): self._log.critical("Unsupported type for integer value assignment: %s (%s)" % (type(value), repr(value))) raise TypeError("Unable to set simulator value with type %s" % (type(value))) simulator.set_signal_val_long(self._handle, value)