Belle II Software development
VectorVariable Class Reference
Inheritance diagram for VectorVariable:
Variable

Public Member Functions

def format_value (self, value, check=True)
 

Protected Member Functions

def _format_value (self, value, size, check)
 

Static Private Attributes

tuple __slots__ = ()
 variables
 

Detailed Description

Bit vector variable type.

This is for the various non-scalar and non-real variable types including
integer, register, wire, etc.

Definition at line 537 of file writer.py.

Member Function Documentation

◆ _format_value()

def _format_value (   self,
  value,
  size,
  check 
)
protected
format value function of VCDWriter

Definition at line 594 of file writer.py.

594 def _format_value(self, value, size, check):
595 """format value function of VCDWriter"""
596 if isinstance(value, int):
597 max_val = 1 << size
598 if check and (-value > (max_val >> 1) or value >= max_val):
599 raise ValueError(f'Value ({value}) not representable in {size} bits')
600 if value < 0:
601 value += max_val
602 return format(value, 'b')
603 elif value is None:
604 return 'z'
605 else:
606 if check and (not isinstance(value, str) or
607 len(value) > size or
608 any(c not in '01xzXZ-' for c in value)):
609 raise ValueError(f'Invalid vector value ({value})')
610 return value

◆ format_value()

def format_value (   self,
  value,
  check = True 
)
Format value change for VCD stream.

:param value: New value for the variable.
:types value: int, str, or None
:raises ValueError: for *some* invalid values.

A *value* of `None` is the same as `'z'`.

.. Warning::

    If *value* is of type :py:class:`str`, all characters must be one
    of `'01xzXZ'`. For the sake of performance, checking **is not**
    done to ensure value strings only contain conforming characters.
    Thus it is possible to produce invalid VCD streams with invalid
    string values.

Reimplemented from Variable.

Definition at line 548 of file writer.py.

548 def format_value(self, value, check=True):
549 """Format value change for VCD stream.
550
551 :param value: New value for the variable.
552 :types value: int, str, or None
553 :raises ValueError: for *some* invalid values.
554
555 A *value* of `None` is the same as `'z'`.
556
557 .. Warning::
558
559 If *value* is of type :py:class:`str`, all characters must be one
560 of `'01xzXZ'`. For the sake of performance, checking **is not**
561 done to ensure value strings only contain conforming characters.
562 Thus it is possible to produce invalid VCD streams with invalid
563 string values.
564
565 """
566 if isinstance(self.size, tuple):
567 # The string is built-up right-to-left in order to minimize/avoid
568 # left-extension in the final value string.
569 vstr_list = []
570 vstr_len = 0
571 size_sum = 0
572 for i, (v, size) in enumerate(zip(reversed(value),
573 reversed(self.size))):
574 vstr = self._format_value(v, size, check)
575 if not vstr_list:
576 vstr_list.insert(0, vstr)
577 vstr_len += len(vstr)
578 else:
579 leftc = vstr_list[0][0]
580 rightc = vstr[0]
581 if len(vstr) > 1 or ((rightc != leftc or leftc == '1') and
582 (rightc != '0' or leftc != '1')):
583 extendc = '0' if leftc == '1' else leftc
584 extend_size = size_sum - vstr_len
585 vstr_list.insert(0, extendc * extend_size)
586 vstr_list.insert(0, vstr)
587 vstr_len += extend_size + len(vstr)
588 size_sum += size
589 value_str = ''.join(vstr_list)
590 else:
591 value_str = self._format_value(value, self.size, check)
592 return f'b{value_str} {self.ident}'
593

Member Data Documentation

◆ __slots__

tuple __slots__ = ()
staticprivate

variables

Definition at line 546 of file writer.py.


The documentation for this class was generated from the following file: