Ejemplo n.º 1
0
def z3_to_python_value(value):
    """
    is_expr: Return `True` if `a` is a Z3 expression, is_expr(1) is False
    """
    assert z3p.is_expr(value)
    if z3p.is_int_value(value):
        return value.as_long()
    elif value.sort() == z3p.BoolSort():
        if z3p.is_true(value):
            return True
        elif z3p.is_false(value):
            return False
    raise NotImplementedError
Ejemplo n.º 2
0
def z3_to_python_value(value):
    """
    is_expr: Return `True` if `a` is a Z3 expression, is_expr(1) is False
    """
    assert z3p.is_expr(value)
    if z3p.is_int_value(value):
        return value.as_long()
    elif value.sort() == z3p.BoolSort():
        if z3p.is_true(value):
            return True
        elif z3p.is_false(value):
            return False
    raise NotImplementedError
Ejemplo n.º 3
0
 def guard_enabled(self, state, guard, verbose=0):
     if guard.decl().name().startswith('table'):
         conditional = self.tables[guard.decl().name()]
         expression = z3p.BoolVal(False)
         for condition, result in conditional:
             expression = z3p.Or(expression, condition if z3p.is_true(result) else z3p.BoolVal(False))
         guard = expression
     guard_evaluated = util.evaluate_expression(guard, {}, state, self.tables)
     if verbose > 0:
         print 'Evaluated guard is {}'.format(guard_evaluated)
         print 'Simplified guard is {}'.format(z3p.simplify(guard_evaluated))
     s = z3p.Solver()
     s.add(z3p.Neq(guard_evaluated, True))
     if s.check() == z3p.unsat:
         return True
     else:
         return False
Ejemplo n.º 4
0
 def draw(self, filename=None, transition_labels=False):
     """
     TODO: draw initial state
     """
     A = networkx.to_agraph(self)
     if filename is None:
         output = util.file_in_temp('temp.png')
     seen_edges = {}
     for source, target, attributes in self.edges(data=True):
         channel = attributes['channel']
         channel_expression = attributes['channel_expression']
         guard = attributes['guard']
         update = attributes['update']
         label = None
         if channel in self.input_channels:
             label = '{}?'.format(channel)
         elif channel in self.output_channels:
             if channel.sort() == util.UNIT_SORT:
                 label = '{}!'.format(channel)
             else:
                 label = '{}({})!'.format(channel, channel_expression)
         if not z3p.is_true(guard):
             if label:
                 label += '\n{}'.format(guard)
             else:
                 label = '{}'.format(guard)
         if update:
             if label:
                 label += '\n{}'.format(update)
             else:
                 label = '{}'.format(update)
         if transition_labels:
             label = attributes['name'] + ':' + label
         if (source, target) not in seen_edges:
             key = 0
             seen_edges[(source, target)] = 1
         else:
             key = seen_edges[(source, target)]
             seen_edges[(source, target)] += 1
         A.get_edge(source, target, key).attr['label'] = label
     A.layout(prog='dot')
     A.draw(output, format='png')
     output.close()