Esempio n. 1
0
def resolve_runtime_index(lval, index):
    max_idx = lval.locals["size"]
    return_expr = lval.locals["0"]
    for hdr_idx in range(1, max_idx):
        cond = index == hdr_idx
        return_expr = handle_mux(cond, lval.locals[f"{hdr_idx}"], return_expr)
    return return_expr
Esempio n. 2
0
 def eval_callable(self, ctx, merged_args, var_buffer):
     # execute the action expression with the new environment
     ctx.return_type = self.return_type
     self.statements.eval(ctx)
     return_expr = None
     if len(ctx.return_exprs) == 1:
         _, return_expr = ctx.return_exprs.pop()
     elif len(ctx.return_exprs) > 1:
         # the first condition is not needed since it is the default
         _, return_expr = ctx.return_exprs.pop()
         if isinstance(return_expr, StructInstance):
             while ctx.return_exprs:
                 then_cond, then_expr = ctx.return_exprs.pop()
                 return_expr = handle_mux(then_cond, then_expr, return_expr)
         else:
             while ctx.return_exprs:
                 then_cond, then_expr = ctx.return_exprs.pop()
                 return_expr = z3.If(then_cond, then_expr, return_expr)
     return return_expr
Esempio n. 3
0
    def eval(self, p4_state):
        cond = z3.simplify(p4_state.resolve_expr(self.cond))

        # handle side effects for function and table calls
        if cond == z3.BoolVal(False):
            return p4_state.resolve_expr(self.else_val)
        if cond == z3.BoolVal(True):
            return p4_state.resolve_expr(self.then_val)

        var_store, chain_copy = p4_state.checkpoint()
        context = p4_state.current_context()
        forward_cond_copy = context.tmp_forward_cond
        context.tmp_forward_cond = z3.And(forward_cond_copy, cond)
        then_expr = p4_state.resolve_expr(self.then_val)
        then_vars = p4_state.get_attrs()
        p4_state.restore(var_store, chain_copy)
        context.tmp_forward_cond = forward_cond_copy

        else_expr = p4_state.resolve_expr(self.else_val)
        merge_attrs(p4_state, cond, then_vars)

        return handle_mux(cond, then_expr, else_expr)