about summary refs log tree commit diff homepage
path: root/lib/Solver/SMTLIBLoggingSolver.cpp
blob: f64e11e08ed5adff5b65bf27eca684a21747a7e1 (plain) (blame)
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
57
58
59
60
61
62
63
64
65
66
67
//===-- SMTLIBLoggingSolver.cpp -------------------------------------------===//
//
//                     The KLEE Symbolic Virtual Machine
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "QueryLoggingSolver.h"
#include "klee/util/ExprSMTLIBLetPrinter.h"

using namespace klee;

/// This QueryLoggingSolver will log queries to a file in the SMTLIBv2 format
/// and pass the query down to the underlying solver.
class SMTLIBLoggingSolver : public QueryLoggingSolver
{
        private:
    
                ExprSMTLIBPrinter* printer;

                virtual void printQuery(const Query& query,
                                        const Query* falseQuery = 0,
                                        const std::vector<const Array*>* objects = 0) 
                {
                        if (0 == falseQuery) 
                        {
                                printer->setQuery(query);
                        }
                        else
                        {
                                printer->setQuery(*falseQuery);                
                        }

                        if (0 != objects)
                        {
                                printer->setArrayValuesToGet(*objects);
                        }

                        printer->generateOutput();
                }    
        
	public:
		SMTLIBLoggingSolver(Solver *_solver,
                                    std::string path,
                                    int queryTimeToLog)                
		: QueryLoggingSolver(_solver, path, ";", queryTimeToLog),
		printer()
		{
		  //Setup the printer
		  printer = createSMTLIBPrinter();
		  printer->setOutput(logBuffer);
		}

		~SMTLIBLoggingSolver()
		{
			delete printer;
		}
};


Solver* klee::createSMTLIBLoggingSolver(Solver *_solver, std::string path,
                                        int minQueryTimeToLog)
{
  return new Solver(new SMTLIBLoggingSolver(_solver, path, minQueryTimeToLog));
}