Example #1
0
/*
 * All variables in solver
 */
void print_bv_solver_vars(FILE *f, bv_solver_t *solver) {
  bv_vartable_t *vtbl;
  literal_t *map;
  uint32_t i, n;
  thvar_t y;

  vtbl = &solver->vtbl;
  n = vtbl->nvars;
  for (i=1; i<n; i++) {
    print_bv_vardef(f, vtbl, i);
    fputc('\n', f);
    map = bvvar_get_map(vtbl, i);
    if (map != NULL) {
      assert(solver->remap != NULL);
      fputs("              lit array: ", f);
      print_pseudo_litarray(f, solver->remap, map, bvvar_bitsize(vtbl, i));
      fputc('\n', f);
    }
    y = bv_solver_var_compiles_to(solver, i);
    if (y >= 0) {
      fputs("              compiled to: ", f);
      print_bvvar(f, y);
      fputc('\n', f);
    }
  }
}
Example #2
0
/*
 * Delete the table
 */
void delete_bvexp_table(bvexp_table_t *table) {
  uint32_t i, n, b;
  void *p;

  n = table->nvars;
  for (i=0; i<n; i++) {
    p = table->def[i];
    if (p != NULL) {
      b = bvvar_bitsize(table->vtbl, i);
      if (b > 64) {
        delete_bvmlist_coeffs(p, b);
      }
    }
  }

  // aux buffers must be deleted first
  delete_bvarith_buffer(&table->aux);
  delete_bvarith64_buffer(&table->aux64);
  delete_pp_buffer(&table->pp);
  delete_bvconstant(&table->bvconst);

  safe_free(table->def);
  table->def = NULL;
  delete_bvmlist_store(&table->store);
  delete_bvmlist64_store(&table->store64);
  delete_pprod_table(&table->pprods);
  delete_int_htbl(&table->htbl);
}
Example #3
0
static void test_buffer(bvexp_table_t *table, bvarith_buffer_t *b) {
  bvmlist_t *p;
  thvar_t x;
  uint32_t h, n;

  printf("=== test ===\n");
  n = b->bitsize;

  printf("poly = ");
  print_bvexp(stdout, b->list, n);
  printf("\n");

  h = hash_bvmlist(b->list, n);
  printf("hash code = %"PRIu32"\n", h);

  x = bvexp_table_find(table, b, h);
  if (x < 0) {
    printf("not in table\n");
    x = make_bvvar(table->vtbl, n);
    bvexp_table_add(table, x, b, h);
    printf("adding variable: ");
    print_def(stdout, table, x);
  } else {
    printf("found matching variable: ");
    print_def(stdout, table, x);
    p = bvexp_def(table, x);
    if (p == NULL || !equal_bvmlists(b->list, p, n) || bvvar_bitsize(table->vtbl, x) != n) {
      printf("BUG\n");
      exit(1);
    }
  }
  printf("\n");
}
Example #4
0
/*
 * Add the mapping def[v] = p to the table
 * - v must be a new variable (v >= table->nvars)
 * - p is the polynomial stored in buffer
 * - p must not be present in table (call find first)
 * - buffer must be normalized and h must be the hash code of p
 * Side effect: buffer is reset to the zero polynomial
 */
void bvexp_table_add(bvexp_table_t *table, thvar_t v, bvarith_buffer_t *buffer, uint32_t h) {
  bvmlist_t *p;

  assert(bvvar_bitsize(table->vtbl, v) > 64);
  assert(h == hash_bvmlist(buffer->list, buffer->bitsize));
  assert(buffer->store == &table->store && buffer->ptbl == &table->pprods);

  p = bvarith_buffer_get_mlist(buffer);
  bvexp_set_def(table, v, p);
  int_htbl_add_record(&table->htbl, h, v);
}
Example #5
0
/*
 * Remove variable x from the table
 */
static void bvexp_table_remove_var(bvexp_table_t *table, thvar_t x) {
  void *p;
  uint32_t n, h;

  assert(0 <= x && x < table->nvars);
  p = table->def[x];
  if (p != NULL) {
    n = bvvar_bitsize(table->vtbl, x);
    if (n > 64) {
      h = hash_bvmlist(p, n);
      free_bvmlist(p, &table->store, n);
    } else {
      h = hash_bvmlist64(p, n);
      free_bvmlist64(p, &table->store64);
    }
    int_htbl_erase_record(&table->htbl, h, x);
  }
}
Example #6
0
/*
 * Print the pseudo literal array mapped to bitvariable x
 * - x must be a valid variable
 * - it this is called before bit blasting, we print 'not mapped'
 *   otherwise we print the pseudo literal array mapped to x
 */
void dimacs_print_bvvar(FILE *f, bv_solver_t *solver, thvar_t x) {
  bv_vartable_t *vtbl;
  literal_t *map;
  uint32_t n;

  vtbl = &solver->vtbl;
  n = vtbl->nvars;
  if (0 <= x && x < n) {
    map = bvvar_get_map(vtbl, x);
    if (map != NULL) {
      assert(solver->remap != NULL);
      dimacs_print_pseudo_litarray(f, solver->remap, map, bvvar_bitsize(vtbl, x));
    } else {
      fputs("not mapped", f);
    }
  } else {
    fputs("invalid bitvector variable", f);
  }
}
Example #7
0
/*
 * Print the polynomial attached to variable x in table
 */
static void print_def(FILE *f, bvexp_table_t *table, thvar_t x) {
  bv_vartable_t *vtbl;
  void *def;
  uint32_t n;

  vtbl = table->vtbl;
  n = bvvar_bitsize(vtbl, x);
  def = bvexp_get_def(table, x);

  print_bv_solver_var(f, NULL, x);
  fputs(" = ", f);
  if (def == NULL) {
    fputs("<none>", f);
  } else if (n <= 64) {
    print_bvexp64(f, def, n);
  } else {
    print_bvexp(f, def, n);
  }
  fputc('\n', f);
}
Example #8
0
/*
 * Equality test
 */
static bool eq_hash_bvexp_hobj(bvexp_hobj_t *o, thvar_t i) {
  bvexp_table_t *table;
  uint32_t n;
  bool result;

  table = o->table;
  assert(0 <= i && i < table->nvars && table->def[i] != NULL);

  n = o->bitsize;
  result = false;

  if (bvvar_bitsize(table->vtbl, i) == n) {
    if (n <= 64) {
      result = equal_bvmlists64(o->def, table->def[i]);
    } else {
      result = equal_bvmlists(o->def, table->def[i], n);
    }
  }

  return result;
}
Example #9
0
/*
 * Print the definition of x in vtbl
 */
static void print_bv_vardef(FILE *f, bv_vartable_t *vtbl, thvar_t x) {
  uint32_t nbits;

  assert(valid_bvvar(vtbl, x));

  nbits = bvvar_bitsize(vtbl, x);
  print_bvvar(f, x);
  fprintf(f, ":bv[%"PRIu32"] = ", nbits);
  switch (bvvar_tag(vtbl, x)) {
  case BVTAG_VAR:
    fputs("var", f);
    break;

  case BVTAG_CONST64:
    bvconst64_print(f, bvvar_val64(vtbl, x), nbits);
    break;

  case BVTAG_CONST:
    bvconst_print(f, bvvar_val(vtbl, x), nbits);
    break;

  case BVTAG_POLY64:
    print_bv_poly64(f, bvvar_poly64_def(vtbl, x));
    break;

  case BVTAG_POLY:
    print_bv_poly(f, bvvar_poly_def(vtbl, x));
    break;

  case BVTAG_PPROD:
    print_bv_product(f, bvvar_pprod_def(vtbl, x));
    break;

  case BVTAG_BIT_ARRAY:
    print_litarray(f, nbits, bvvar_bvarray_def(vtbl, x));
    break;

  case BVTAG_ITE:
    print_bv_ite(f, bvvar_ite_def(vtbl, x));
    break;

  case BVTAG_UDIV:
    print_bv_binop(f, "div", bvvar_binop(vtbl, x));
    break;

  case BVTAG_UREM:
    print_bv_binop(f, "rem", bvvar_binop(vtbl, x));
    break;

  case BVTAG_SDIV:
    print_bv_binop(f, "sdiv", bvvar_binop(vtbl, x));
    break;

  case BVTAG_SREM:
    print_bv_binop(f, "srem", bvvar_binop(vtbl, x));
    break;

  case BVTAG_SMOD:
    print_bv_binop(f, "smod", bvvar_binop(vtbl, x));
    break;

  case BVTAG_SHL:
    print_bv_binop(f, "shl", bvvar_binop(vtbl, x));
    break;

  case BVTAG_LSHR:
    print_bv_binop(f, "lshr", bvvar_binop(vtbl, x));
    break;

  case BVTAG_ASHR:
    print_bv_binop(f, "ashr", bvvar_binop(vtbl, x));
    break;

  case BVTAG_ADD:
    print_bv_binop(f, "add", bvvar_binop(vtbl, x));
    break;

  case BVTAG_SUB:
    print_bv_binop(f, "sub", bvvar_binop(vtbl, x));
    break;

  case BVTAG_MUL:
    print_bv_binop(f, "mul", bvvar_binop(vtbl, x));
    break;

  case BVTAG_NEG:
    print_bvneg(f, bvvar_binop(vtbl, x));
    break;
  }
}