1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
/********************* */
/*! \file extract.cpp
** \verbatim
** Top contributors (to current version):
** Clark Barrett, Aina Niemetz
** This file is part of the CVC4 project.
** Copyright (c) 2009-2018 by the authors listed in the file AUTHORS
** in the top-level source directory) and their institutional affiliations.
** All rights reserved. See the file COPYING in the top-level source
** directory for licensing information.\endverbatim
**
** \brief A simple demonstration of the solving capabilities of the CVC4
** bit-vector solver.
**
**/
#include <iostream>
//#include <cvc4/cvc4.h> // use this after CVC4 is properly installed
#include "api/cvc4cpp.h"
using namespace std;
using namespace CVC4::api;
int main()
{
Solver slv;
slv.setLogic("QF_BV"); // Set the logic
Sort bitvector32 = slv.mkBitVectorSort(32);
Term x = slv.mkVar("a", bitvector32);
OpTerm ext_31_1 = slv.mkOpTerm(BITVECTOR_EXTRACT_OP, 31, 1);
Term x_31_1 = slv.mkTerm(ext_31_1, x);
OpTerm ext_30_0 = slv.mkOpTerm(BITVECTOR_EXTRACT_OP, 30, 0);
Term x_30_0 = slv.mkTerm(ext_30_0, x);
OpTerm ext_31_31 = slv.mkOpTerm(BITVECTOR_EXTRACT_OP, 31, 31);
Term x_31_31 = slv.mkTerm(ext_31_31, x);
OpTerm ext_0_0 = slv.mkOpTerm(BITVECTOR_EXTRACT_OP, 0, 0);
Term x_0_0 = slv.mkTerm(ext_0_0, x);
Term eq = slv.mkTerm(EQUAL, x_31_1, x_30_0);
cout << " Asserting: " << eq << endl;
slv.assertFormula(eq);
Term eq2 = slv.mkTerm(EQUAL, x_31_31, x_0_0);
cout << " Check validity assuming: " << eq2 << endl;
cout << " Expect valid. " << endl;
cout << " CVC4: " << slv.checkValidAssuming(eq2) << endl;
return 0;
}
|