コード例 #1
0
static void alloc_constants() {
  uint32_t i;

  init_bvconstants();
  //  a = (uint32_t *) safe_malloc(4 * sizeof(uint32_t));
  //  b = (uint32_t *) safe_malloc(4 * sizeof(uint32_t));
  //  c = (uint32_t *) safe_malloc(4 * sizeof(uint32_t));
  //  d = (uint32_t *) safe_malloc(4 * sizeof(uint32_t));
  //  e = (uint32_t *) safe_malloc(4 * sizeof(uint32_t));
  a = bvconst_alloc(4);
  b = bvconst_alloc(4);
  c = bvconst_alloc(4);
  d = bvconst_alloc(4);
  e = bvconst_alloc(4);

  for (i=0; i<4; i++) {
    a[i] = 0;
    b[i] = 0xffffffff;
    c[i] = 0;
    d[i] = 0;
    e[i] = 0;
  }

  c[0] = 1;
  d[0] = 0x80000000;
  e[1] = 1;
}
コード例 #2
0
static void test_set_extend(uint32_t size1, uint32_t size2) {
  uint32_t *bv1, *bv2;
  uint32_t i, w1, w2;

  assert(size1 >= size2);

  w1 = (size1 + 31) >> 5;
  w2 = (size2 + 31) >> 5;

  bv1 = bvconst_alloc(w1);
  bv2 = bvconst_alloc(w2);

  printf("=== test_set_extend: size1 = %"PRIu32", size2 = %"PRIu32" ===\n", size1, size2);

  for (i=0; i<20; i++) {
    random_vector(vector, size2);
    bvconst_set_array(bv2, vector, size2);

    printf("%"PRIu32" to %"PRIu32" bits\n", size2, size1);
    printf("bv2            = ");
    bvconst_print(stdout, bv2, size2);
    printf("\n");
    bvconst_set_extend(bv1, size1, bv2, size2, 0);
    printf("ext(bv2, %"PRIu32", 0) = ", size1);
    bvconst_print(stdout, bv1, size1);
    printf("\n");
    bvconst_set_extend(bv1, size1, bv2, size2, 1);
    printf("ext(bv2, %"PRIu32", 1) = ", size1);
    bvconst_print(stdout, bv1, size1);
    printf("\n");
    bvconst_set_extend(bv1, size1, bv2, size2, -1);
    printf("sgnext(bv2, %"PRIu32", 0) = ", size1);
    bvconst_print(stdout, bv1, size1);
    printf("\n\n");
  }

  printf("===\n");
  bvconst_free(bv1, w1);
  bvconst_free(bv2, w2);
}
コード例 #3
0
int main() {
  int32_t x, y;
  uint32_t a, b, n;
  char c;
  string_buffer_t *s;

  s = &buffer;
  init_string_buffer(s, 0);
  show_test("empty buffer", s);

  string_buffer_reset(s);
  for (c = 'a'; c <= 'z'; c++) {
    string_buffer_append_char(s, c);
  }
  show_test("alphabet", s);

  string_buffer_reset(s);
  for (c = 'a'; c <= 'z'; c++) {
    string_buffer_append_char(s, c);
  }
  string_buffer_append_string(s, "au898ue2bcc90219");
  show_test("alphabet+au898ue2bcc90219", s);

  x = INT32_MIN;
  for (;;){
    sprintf(aux, "signed number: %" PRId32, x);
    string_buffer_reset(s);
    string_buffer_append_int32(s, x);
    show_test(aux, s);
    y = x >> 1;
    if (y == x) break;
    x = y;
  }

  x = INT32_MAX;
  for (;;) {
    sprintf(aux, "signed number: %" PRId32, x);
    string_buffer_reset(s);
    string_buffer_append_int32(s, x);
    show_test(aux, s);
    y = x>>1;
    if (y == x) break;
    x = y;
  }

  a = UINT32_MAX;
  for (;;){
    sprintf(aux, "unsigned number: %" PRIu32, a);
    string_buffer_reset(s);
    string_buffer_append_uint32(s, a);
    show_test(aux, s);
    b = a >> 1;
    if (b == a) break;
    a = b;
  }

  mpz_init(z0);
  mpz_init(z1);
  mpq_init(q0);

  mpz_set_str(z0, "111102222033330123456789", 10);
  string_buffer_reset(s);
  string_buffer_append_mpz(s, z0);
  show_test("mpz: 111102222033330123456789", s);

  mpz_set_str(z0, "-111102222033330123456789", 10);
  string_buffer_reset(s);
  string_buffer_append_mpz(s, z0);
  show_test("mpz: -111102222033330123456789", s);

  string_buffer_reset(s);
  string_buffer_append_mpz(s, z1);
  show_test("mpz: 0", s);

  mpq_set_str(q0, "-98765432109876543210", 10);
  string_buffer_reset(s);
  string_buffer_append_mpq(s, q0);
  show_test("mpq: -98765432109876543210", s);

  mpq_set_str(q0, "-98765432109876543210/38192839777", 10);
  string_buffer_reset(s);
  string_buffer_append_mpq(s, q0);
  show_test("mpq: -98765432109876543210/38192839777", s);

  init_rationals();
  rational_t r0;
  q_init(&r0);
  string_buffer_reset(s);
  string_buffer_append_rational(s, &r0);
  show_test("rational: 0", s);

  q_set_int32(&r0, -12, 73);
  string_buffer_reset(s);
  string_buffer_append_rational(s, &r0);
  show_test("rational: -12/73", s);

  q_set_mpq(&r0, q0);
  string_buffer_reset(s);
  string_buffer_append_rational(s, &r0);
  show_test("rational: -98765432109876543210/38192839777", s);

  q_set_mpz(&r0, z0);
  string_buffer_reset(s);
  string_buffer_append_rational(s, &r0);
  show_test("rational: -111102222033330123456789", s);


  printf("\nBit Vectors\n");
  init_bvconstants();
  bv0 = bvconst_alloc(1);
  bvconst_clear(bv0, 1);
  for (n=1; n<= 32; n++) {
    string_buffer_reset(s);
    string_buffer_append_bvconst(s, bv0, n);
    sprintf(aux, "bv[%" PRIu32"]: 0b000...", n);
    show_test(aux, s);
  }

  for (n=1; n <= 32; n++) {
    bvconst_clear(bv0, 1);
    bvconst_set_bit(bv0, n-1);
    string_buffer_reset(s);
    string_buffer_append_bvconst(s, bv0, n);
    sprintf(aux, "bv[%" PRIu32"]: 0b100...", n);
    show_test(aux, s);
  }


  bvconst_free(bv0, 1);

  cleanup_bvconstants();

  cleanup_rationals();

  mpz_clear(z0);
  mpz_clear(z1);
  mpq_clear(q0);

  delete_string_buffer(s);

  return 0;
}