about summary refs log tree commit diff homepage
path: root/lib/Solver/KQueryLoggingSolver.cpp
blob: 4be24e9c18c80237e3cf12f785864c3a504305db (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
68
69
70
71
72
//===-- KQueryLoggingSolver.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/Expr/Expr.h"
#include "klee/Expr/ExprPPrinter.h"
#include "klee/System/Time.h"

#include <utility>

using namespace klee;

class KQueryLoggingSolver : public QueryLoggingSolver {

private :
    ExprPPrinter *printer;

    virtual void printQuery(const Query& query,
                            const Query* falseQuery = 0,
                            const std::vector<const Array*>* objects = 0) {

        const ref<Expr>* evalExprsBegin = 0;
        const ref<Expr>* evalExprsEnd = 0;

        if (0 != falseQuery) {
            evalExprsBegin = &query.expr;
            evalExprsEnd = &query.expr + 1;
        }

        const Array* const *evalArraysBegin = 0;
        const Array* const *evalArraysEnd = 0;

        if ((0 != objects) && (false == objects->empty())) {
            evalArraysBegin = &((*objects)[0]);
            evalArraysEnd = &((*objects)[0]) + objects->size();
        }

        const Query* q = (0 == falseQuery) ? &query : falseQuery;

        printer->printQuery(logBuffer, q->constraints, q->expr,
                            evalExprsBegin, evalExprsEnd,
                            evalArraysBegin, evalArraysEnd);
    }

public:
  KQueryLoggingSolver(std::unique_ptr<Solver> solver, std::string path,
                      time::Span queryTimeToLog, bool logTimedOut)
      : QueryLoggingSolver(std::move(solver), std::move(path), "#",
                           queryTimeToLog, logTimedOut),
        printer(ExprPPrinter::create(logBuffer)) {}

    virtual ~KQueryLoggingSolver() {
        delete printer;
    }
};

///

std::unique_ptr<Solver>
klee::createKQueryLoggingSolver(std::unique_ptr<Solver> solver,
                                std::string path, time::Span minQueryTimeToLog,
                                bool logTimedOut) {
  return std::make_unique<Solver>(std::make_unique<KQueryLoggingSolver>(
      std::move(solver), std::move(path), minQueryTimeToLog, logTimedOut));
}