cascada.bitvector.printing module

Manage the representation of bit-vector expressions.

BvStrPrinter

Printing class that handles the str method of Term.

BvShortPrinter

Printing class that handles the Term.srepr method of Term.

BvReprPrinter

Printing class that handles the Term.vrepr method.

BvWrapPrinter

Printing class similar to BvStrPrinter but prints bit-vector expressions in multiple compact lines.

BvCCodePrinter

Printing class that handles the Term.crepr method.

dotprinting

Return the DOT description of a bit-vector Term expression tree.

class cascada.bitvector.printing.BvStrPrinter(settings=None)[source]

Bases: sympy.printing.str.StrPrinter

Printing class that handles the str method of Term.

class cascada.bitvector.printing.BvShortPrinter(settings=None)[source]

Bases: cascada.bitvector.printing.BvStrPrinter

Printing class that handles the Term.srepr method of Term.

class cascada.bitvector.printing.BvReprPrinter(settings=None)[source]

Bases: sympy.printing.repr.ReprPrinter

Printing class that handles the Term.vrepr method.

class cascada.bitvector.printing.BvWrapPrinter(settings=None)[source]

Bases: cascada.bitvector.printing.BvStrPrinter

Printing class similar to BvStrPrinter but prints bit-vector expressions in multiple compact lines.

class cascada.bitvector.printing.BvCCodePrinter(settings=None)[source]

Bases: sympy.printing.str.StrPrinter

Printing class that handles the Term.crepr method.

cascada.bitvector.printing.dotprinting(bv, repeat=True, vrepr_label=False, **kwargs)[source]

Return the DOT description of a bit-vector Term expression tree.

For more information see SymPy’s dotprinting method.

Parameters
  • bv – a bit-vector Term

  • repeat – whether to use different nodes for common subexpressions (default True)

  • vrepr_label – wheter to use the verbose representation (Term.vrepr) to label the nodes (default False)

  • kwargs – additional arguments passed to SymPy’s dotprinting method

>>> from cascada.bitvector.core import Constant, Variable
>>> from cascada.bitvector.operation import make_partial_operation, RotateLeft, Extract
>>> LSB = make_partial_operation(Extract, (None, 0, 0))
>>> expr = LSB(RotateLeft((Constant(1, 8) + Variable("x", 8)), 1))
>>> print(dotprinting(expr))  
digraph{
# Graph style
"ordering"="out"
"rankdir"="TD"
#########
# Nodes #
#########
"Extract_{·, 0, 0}(RotateLeft(BvAdd(Constant(0b00000001, width=8), Variable('x', width=8)), 1))_()" ["color"="black", "label"="Extract_{·, 0, 0}", "shape"="ellipse"];
"RotateLeft(BvAdd(Constant(0b00000001, width=8), Variable('x', width=8)), 1)_(0,)" ["color"="black", "label"="RotateLeft", "shape"="ellipse"];
"BvAdd(Constant(0b00000001, width=8), Variable('x', width=8))_(0, 0)" ["color"="black", "label"="BvAdd", "shape"="ellipse"];
"Constant(0b00000001, width=8)_(0, 0, 0)" ["color"="blue1", "label"="0x01", "shape"="box"];
"Variable('x', width=8)_(0, 0, 1)" ["color"="aquamarine3", "label"="x", "shape"="box"];
"1_(0, 1)" ["color"="blue4", "label"="1", "shape"="box"];
#########
# Edges #
#########
"Extract_{·, 0, 0}(RotateLeft(BvAdd(Constant(0b00000001, width=8), Variable('x', width=8)), 1))_()" -> "RotateLeft(BvAdd(Constant(0b00000001, width=8), Variable('x', width=8)), 1)_(0,)";
"RotateLeft(BvAdd(Constant(0b00000001, width=8), Variable('x', width=8)), 1)_(0,)" -> "BvAdd(Constant(0b00000001, width=8), Variable('x', width=8))_(0, 0)";
"RotateLeft(BvAdd(Constant(0b00000001, width=8), Variable('x', width=8)), 1)_(0,)" -> "1_(0, 1)";
"BvAdd(Constant(0b00000001, width=8), Variable('x', width=8))_(0, 0)" -> "Constant(0b00000001, width=8)_(0, 0, 0)";
"BvAdd(Constant(0b00000001, width=8), Variable('x', width=8))_(0, 0)" -> "Variable('x', width=8)_(0, 0, 1)";
}
>>> print(dotprinting(expr, repeat=False, vrepr_label=True))  
digraph{
# Graph style
"ordering"="out"
"rankdir"="TD"
#########
# Nodes #
#########
"Extract_{·, 0, 0}(RotateLeft(BvAdd(Constant(0b00000001, width=8), Variable('x', width=8)), 1))" ["color"="black", "label"="Extract_{·, 0, 0}", "shape"="ellipse"];
"RotateLeft(BvAdd(Constant(0b00000001, width=8), Variable('x', width=8)), 1)" ["color"="black", "label"="RotateLeft", "shape"="ellipse"];
"BvAdd(Constant(0b00000001, width=8), Variable('x', width=8))" ["color"="black", "label"="BvAdd", "shape"="ellipse"];
"Constant(0b00000001, width=8)" ["color"="blue1", "label"="Constant(0b00000001, width=8)", "shape"="box"];
"Variable('x', width=8)" ["color"="aquamarine3", "label"="Variable('x', width=8)", "shape"="box"];
"1" ["color"="blue4", "label"="int(1)", "shape"="box"];
#########
# Edges #
#########
"Extract_{·, 0, 0}(RotateLeft(BvAdd(Constant(0b00000001, width=8), Variable('x', width=8)), 1))" -> "RotateLeft(BvAdd(Constant(0b00000001, width=8), Variable('x', width=8)), 1)";
"RotateLeft(BvAdd(Constant(0b00000001, width=8), Variable('x', width=8)), 1)" -> "BvAdd(Constant(0b00000001, width=8), Variable('x', width=8))";
"RotateLeft(BvAdd(Constant(0b00000001, width=8), Variable('x', width=8)), 1)" -> "1";
"BvAdd(Constant(0b00000001, width=8), Variable('x', width=8))" -> "Constant(0b00000001, width=8)";
"BvAdd(Constant(0b00000001, width=8), Variable('x', width=8))" -> "Variable('x', width=8)";
}

Note

This method requires graphviz and its python interface to be installed.