cascada.bitvector.core module
Provide the basic bit-vector types.
Represent bit-vector terms.  | 
|
Represent bit-vector constants.  | 
|
Represent bit-vector variables.  | 
|
Convert the argument t to a bit-vector   | 
- class cascada.bitvector.core.Term(*args, width)[source]
 Bases:
sympy.core.basic.BasicRepresent bit-vector terms.
Bit-vector terms are constants, variables and operations applied to terms.
Bit-vector terms support many operations with the standard operators symbols (<=, +, ^, etc.). See
operationfor more information.This class is not meant to be instantiated but to provide a base class for the different types of terms.
Note that Term inherits the methods of the SymPy class Basic; many of these methods work with bit-vector terms out of the box.
- property width
 The bit-width of the term.
- formula_size()[source]
 Return the formula size of the bit-vector term.
As defined in Complexity of Fixed-Size Bit-Vector Logics.
- vrepr()[source]
 Return an executable string representation.
This method returns a string so that the relation
eval(expr.vrepr())) == exprholds whenexpris aTerm.
- srepr()[source]
 Return a short string representation.
This method returns a short string describing the bit-vector term, as opposed to
vreprwhich returns a long and executable string representation.
- crepr()[source]
 Return a C code representation.
This method returns a string with an expression in the C programming language that evaluates to
self.Bit-vector widths larger than 128 are not supported.
>>> from cascada.bitvector.core import Constant, Variable >>> (Variable("a", 4) * Constant(2, 4)).crepr() '(a * 0x2U) & 0xfU' >>> (Variable("a", 8) < Constant(1, 8)).crepr() '(_Bool)((a < 0x1U) & 0x1U)' >>> Variable('a', 8)[2:1].crepr() '(a >> 0x1U) & 0x3U' >>> Constant(1, 96).crepr() '((__uint128)(0x1ULL)) & (((__uint128)(0xffffffffULL) << 64) | ((__uint128)(0xffffffffffffffffULL)))'
- doit(eval_sec_ops=True, sort_symmetric_args=False)[source]
 Evaluate the term.
Similar to Sympy’s doit method, this method evaluate the term in case it was not evaluated by default (like
SecondaryOperationobjects).If
eval_sec_opsisTrue, the evaluation is done with the contextSecondaryOperationEvaluationenabled.If
sort_symmetric_argsisTrue, arguments of symmetricOperationobjects are sorted.See also
PrimaryOperationEvaluationandSecondaryOperationEvaluation.
- atoms(*types)[source]
 Returns the atoms that form the current object.
This can be used to get all the bit-vectors of type
Constantor the bit-vectors of typeVariablefrom a bit-vector expression.For more information see SymPy’s atoms method. This method is similar to the SymPy variant but this method doesn’t throw an exception when one of the arguments is of type ‘int’.
>>> from cascada.bitvector.core import Constant, Variable >>> expr = Constant(1, 4) + Variable("a", 4) >>> expr.atoms(Constant) {0x1} >>> expr.atoms(Variable) {a}
- class cascada.bitvector.core.Constant(val, width)[source]
 Bases:
sympy.core.basic.Atom,cascada.bitvector.core.TermRepresent bit-vector constants.
Bit-vector constants are interpreted as unsigned integers in base 2, that is, a bit-vector \((x_{n-1}, \dots, x_1, x_0)\), where \(x_0\) or
x[0]denotes the LSB located at position 0, represents the non-negative integer \(x_0 + 2 x_1 + \dots + 2^{n-1} x_{n-1}\).- Parameters
 val – the integer value.
width – the bit-width.
>>> from cascada.bitvector.core import Constant >>> Constant(3, 12) 0x003 >>> Constant(0b11, 12) 0x003 >>> Constant(0x003, 12) 0x003 >>> Constant(3, 12).vrepr() 'Constant(0x003, width=12)'
- property val
 The integer represented by the bit-vector constant.
- bin()[source]
 Return the python-like binary representation.
>>> from cascada.bitvector.core import Constant >>> print(Constant(3, 4).bin()) 0b0011 >>> print(Constant(4, 6).bin()) 0b000100
- class cascada.bitvector.core.Variable(name, width, **kwargs)[source]
 Bases:
sympy.core.basic.Atom,cascada.bitvector.core.TermRepresent bit-vector variables.
- Parameters
 name – the name of the variable.
width – the bit-width.
>>> from cascada.bitvector.core import Variable >>> Variable("x", 12) x >>> Variable("x", 12).vrepr() "Variable('x', width=12)"
- property name
 The name of the variable.