Exemplo n.º 1
0
void
sh_shadform_fprint (FILE* stream, ap_environment_t* env, sh_shadform_t* f)
{
  fprintf (stream, "\tor {\n");
  if (f)
    {

      size_t i;
      ap_environment_t* nnenv;
      fprintf (stream, "\t\tnodes ");
      sh_env_fprint (stream, f->nodes);
      nnenv = ap_environment_alloc (env->var_of_dim, env->intdim,
                                    f->nodes->var_of_dim, f->nodes->realdim);

      fprintf (stream, "\t\tedges ");
      sh_edgeform_fprint (stream, f->nodes, f->eform, f->length_eform);
      fprintf (stream, ";\n");
      fprintf (stream, "\t\tlabels ");
      sh_labelform_fprint (stream, env, f->nodes, f->pform, f->length_pform);
      fprintf (stream, ";\n");
      fprintf (stream, "\t\tdata \t");
      sh_dataform_fprint (stream, nnenv, f->dform, f->length_dform);
      fprintf (stream, ";\n");
      fprintf (stream, "\t\twords ");
      sh_univform_fprint (stream, nnenv, f->uform, f->length_uform);
      fprintf (stream, ";\n");
    }
  fprintf (stream, "\t};\n");
  fflush (stream);
}
Exemplo n.º 2
0
  void init(clang::Decl *D) {
    clang::FunctionDecl *FD = clang::dyn_cast<clang::FunctionDecl>(D);
    for (clang::FunctionDecl::param_iterator P = FD->param_begin();
            P != FD->param_end(); ++P) {
        clang::ParmVarDecl *Parm = *P;
        const char *varName = Parm->getNameAsString().c_str();
        clang::QualType ty = Parm->getType();
        if (ty->isScalarType()) {
            char *s = strdup_e(varName);
            numerics.insert(s);
            printf("Tracking numeric paramater variable %s\n", s);
        }
    }
    
    dc = clang::cast<clang::DeclContext>(D);

    for (clang::DeclContext::specific_decl_iterator<clang::VarDecl>
           I(dc->decls_begin()), E(dc->decls_end()); I != E; ++I) {
        const clang::VarDecl *vd = *I;
  
        if (!isTrackedVar(vd))
            continue;
  
        const char *varName = vd->getNameAsString().c_str();
        clang::QualType ty = vd->getType();
        if (ty->isScalarType()) {
            char *name = strdup_e(varName);
            numerics.insert(name);
            printf("Tracking numeric variable %s\n", name);
        } else if (ty->isArrayType()) {
            const clang::ArrayType *at = ty->getAsArrayTypeUnsafe();
            const clang::ConstantArrayType *cat;
            if (!(cat = clang::dyn_cast<const clang::ConstantArrayType>(at))) {
                printf("Can't handle non-constant arrays (%s). Aborting\n",
                        varName);
                exit(1);
            }
            char *name = strdup_e(varName);
            const unsigned long size = *cat->getSize().getRawData();
            array2size[name] = size;
            printf("Tracking array variable %s\n", name);
        }
    }

    ap_var_t temp_ap_var_array[numerics.size()];
    int i = 0;
    for (std::set<char *>::iterator it = numerics.begin(); it != numerics.end();
            ++it) {
        temp_ap_var_array[i++] = (ap_var_t)(*it);
    }

    // Assuming integers only. The allocation copies the content of
    // temp_ap_var_array so its OK its local
    env = ap_environment_alloc(temp_ap_var_array, numerics.size(), NULL, 0);
  }
static void loop_example(void)
{
    /* One integer vars, none real */
    ap_var_t name_of_dim[] = { (ap_var_t)"x" };
    env = ap_environment_alloc(&name_of_dim[0], 1, NULL,0);

    /* Set all as bottom because there are 'joins' before assignments */
    ap_abstract1_t R[7], abs_temp;
    init_abstract_array(R, 7);

    int x;

    printf("Library %s, version %s\n", man->library, man->version);

    /* concrete: R[0] = {x ∈ Z} */
    /* abstract: R[0] = Top */
    R[0] = ap_abstract1_top(man, env);
    x = 7;
    /* R[1] = [x := 7]#R[0] = x ∈ [7, 7] */
    R[1] = assign_const(R[0], "x", 7);
    fprintf(stdout, "R[1] (x := 7):\n");
    ap_abstract1_fprint(stdout, man, &R[1]);

Label0:
    /* R[2] = R[1] U R[4] */
    R[2] = ap_abstract1_join(man, false, &R[1], &R[4]);
//    fprintf(stdout, "R[2] (join of R[1] and R[4]):\n");
//    ap_abstract1_fprint(stdout, man, &R[2]);

    /* while (x < 1000) */
    if (!(x < 1000))
        goto Label1;

    /* Concrete: R[3] = intersect(R[2], {s | s(x) < 1000}) */
    /* Abstract: R[3] = meet(R[2], [-inf, 999]) */
    abs_temp = create_constraint1();
    R[3] = ap_abstract1_meet(man, false, &R[2], &abs_temp);
//    fprintf(stdout,"Abstract value R[3] (meet of R[2] and x<1000):\n");
//    ap_abstract1_fprint(stdout, man, &R[3]);

    ++x;
    
    /* Concrete: R[4] = [x := x+1]R[3] */
    /* abstract: R[4] = R[3] + [1, 1] */
    R[4] = assign_bin_exp(R[3], "x", "x", 1);

    /* End of while scope */
    goto Label0;

Label1:
    fprintf(stdout, "R[4] ([x:=x+1]R[3]):\n");
    ap_abstract1_fprint(stdout, man, &R[4]);
    fprintf(stdout, "R[2] (join of R[1] and R[4]):\n");
    ap_abstract1_fprint(stdout, man, &R[2]);

    /* Concrete: R[5] = intersect(R[2], {s | s(x) >= 1000}) */
    /* Abstract: R[5] = meet(R[2], [1000, inf]) */
    abs_temp = create_constraint2();
    R[5] = ap_abstract1_meet(man, false, &R[2], &abs_temp);
    fprintf(stdout, "R[5]: meet(R[2], x >= 1000):\n");
    ap_abstract1_fprint(stdout, man, &R[5]);


    if (!(x == 1000))
    {
        /* Concrete: R[6] = intersect(R[5], x != 1000) */
        /* Concrete: R[6] = intersect(R[5],x<=999) U intersect(R[5],x>=1001) */
        /* Abstract: R[6] = Join(Meet(R[5],[-inf,999]),Meet(R[5],[1001,inf])) */
        abs_temp = create_constraint3();
        R[6] = ap_abstract1_meet(man, false, &R[5], &abs_temp);
        fprintf(stdout, "R[6]: Abstract value:\n");
        ap_abstract1_fprint(stdout, man, &R[6]);
        printf("Unable to prove x == 1000!\n");
    }
}