klee
ExprSMTLIBPrinter.h
Go to the documentation of this file.
1//===-- ExprSMTLIBPrinter.h ------------------------------------------*- C++
2//-*-===//
3//
4// The KLEE Symbolic Virtual Machine
5//
6// This file is distributed under the University of Illinois Open Source
7// License. See LICENSE.TXT for details.
8//
9//===----------------------------------------------------------------------===//
10
11#ifndef KLEE_EXPRSMTLIBPRINTER_H
12#define KLEE_EXPRSMTLIBPRINTER_H
13
15#include "klee/Expr/Expr.h"
16#include "klee/Solver/Solver.h"
18
19#include <map>
20#include <set>
21#include <string>
22
23namespace llvm {
24class raw_ostream;
25}
26
27namespace klee {
28
80public:
87 };
88
95 };
96
104 };
105
109 DECIMAL
110 };
111
118 };
119
122
127
129
131
134
137 void setOutput(llvm::raw_ostream &output);
138
142 void setQuery(const Query &q);
143
145
163 void generateOutput();
164
171 bool setLogic(SMTLIBv2Logic l);
172
180 void setHumanReadable(bool hr);
181
194
208 void setArrayValuesToGet(const std::vector<const Array *> &a);
209
211 bool isHumanReadable();
212
213protected:
215 std::set<const Array *> usedArrays;
216
218 std::set<ref<Expr> > seenExprs;
219
220 typedef std::map<const ref<Expr>, int> BindingMap;
221
226
230 std::vector<BindingMap> orderedBindings;
231
233 llvm::raw_ostream *o;
234
236 const Query *query;
237
239 SMTLIB_SORT getSort(const ref<Expr> &e);
240
243
244 // Resets various internal objects for a new query
245 void reset();
246
247 // Scan all constraints and the query
248 void scanAll();
249
250 // Print an initial SMTLIBv2 comment before anything else is printed
251 void printNotice();
252
253 // Print SMTLIBv2 options e.g. (set-option :option-name <value>) command
254 void printOptions();
255
256 // Print SMTLIBv2 logic to use e.g. (set-logic QF_ABV)
257 void printSetLogic();
258
259 // Print SMTLIBv2 assertions for constant arrays
261
262 // Print SMTLIBv2 for the query optimised for human readability
264
265 // Print SMTLIBv2 for the query optimised for minimal query size.
266 // This does not imply ABBR_LET or ABBR_NAMED (although it would be wise
267 // to use them to minimise the query size further)
269
271
275 void printAction();
276
278 void printExit();
279
282 void printConstant(const ref<ConstantExpr> &e);
283
289 void printExpression(const ref<Expr> &e, SMTLIB_SORT expectedSort);
290
294 void scan(const ref<Expr> &e);
295
299 void scanBindingExprDeps();
300
301 /* Rules of recursion for "Special Expression handlers" and
302 *printSortArgsExpr()
303 *
304 * 1. The parent of the recursion will have created an indent level for you so
305 *you don't need to add another initially.
306 * 2. You do not need to add a line break (via printSeperator() ) at the end,
307 *the parent caller will handle that.
308 * 3. The effect of a single recursive call should not affect the depth of the
309 *indent stack (nor the contents
310 * of the indent stack prior to the call). I.e. After executing a single
311 *recursive call the indent stack
312 * should have the same size and contents as before executing the recursive
313 *call.
314 */
315
316 // Special Expression handlers
317 void printReadExpr(const ref<ReadExpr> &e);
318 void printExtractExpr(const ref<ExtractExpr> &e);
319 void printCastExpr(const ref<CastExpr> &e);
321 void printSelectExpr(const ref<SelectExpr> &e,
323 void printAShrExpr(const ref<AShrExpr> &e);
324
325 // For the set of operators that take sort "s" arguments
326 void printSortArgsExpr(const ref<Expr> &e,
328
336
338 void printUpdatesAndArray(const UpdateNode *un, const Array *root);
339
343 const char *getSMTLIBKeyword(const ref<Expr> &e);
344
345 void printSeperator();
346
348 void scanUpdates(const UpdateNode *un);
349
352
356
359
360private:
362
363 volatile bool humanReadable;
364
365 // Map of enabled SMTLIB Options
366 std::map<SMTLIBboolOptions, bool> smtlibBoolOptions;
367
368 // Print a SMTLIBv2 option as a C-string
369 const char *
371
373 void printFullExpression(const ref<Expr> &e, SMTLIB_SORT expectedSort);
374
376 void printAssert(const ref<Expr> &e);
377
378 // Pointer to a vector of Arrays. These will be used for the (get-value () )
379 // call.
380 const std::vector<const Array *> *arraysToCallGetValueOn;
381
384};
385}
386
387#endif /* KLEE_EXPRSMTLIBPRINTER_H */
@ PRODUCE_MODELS
produce-models SMTLIBv2 option
@ PRINT_SUCCESS
print-success SMTLIBv2 option
@ INTERACTIVE_MODE
interactive-mode SMTLIBv2 option
const char * getSMTLIBOptionString(ExprSMTLIBPrinter::SMTLIBboolOptions option)
std::map< SMTLIBboolOptions, bool > smtlibBoolOptions
ConstantDisplayMode getConstantDisplayMode()
@ ABBR_LET
Abbreviate with let.
@ ABBR_NAMED
Abbreviate with :named annotations.
@ ABBR_NONE
Do not abbreviate.
void printExit()
Print the SMTLIBv2 command to exit.
llvm::raw_ostream * o
Output stream to write to.
void printReadExpr(const ref< ReadExpr > &e)
void setQuery(const Query &q)
void setOutput(llvm::raw_ostream &output)
const char * getSMTLIBKeyword(const ref< Expr > &e)
void scan(const ref< Expr > &e)
SMTLIB_SORT getSort(const ref< Expr > &e)
Determine the SMTLIBv2 sort of the expression.
void printAShrExpr(const ref< AShrExpr > &e)
bool setLogic(SMTLIBv2Logic l)
bool setConstantDisplayMode(ConstantDisplayMode cdm)
void printFullExpression(const ref< Expr > &e, SMTLIB_SORT expectedSort)
Print expression without top-level abbreviations.
void printConstant(const ref< ConstantExpr > &e)
void setAbbreviationMode(AbbreviationMode am)
void printCastExpr(const ref< CastExpr > &e)
@ QF_ABV
Logic using Theory of Arrays and Theory of Bitvectors.
const std::vector< const Array * > * arraysToCallGetValueOn
std::map< const ref< Expr >, int > BindingMap
void printCastToSort(const ref< Expr > &e, ExprSMTLIBPrinter::SMTLIB_SORT sort)
Print an expression but cast it to a particular SMTLIBv2 sort first.
bool haveConstantArray
Indicates if there were any constant arrays founds during a scan()
const Query * query
The query to print.
SMTLIB_SORT
Different supported SMTLIBv2 sorts (a.k.a type) in QF_AUFBV.
PrintContext * p
Helper printer class.
std::set< const Array * > usedArrays
Contains the arrays found during scans.
void setArrayValuesToGet(const std::vector< const Array * > &a)
void printExpression(const ref< Expr > &e, SMTLIB_SORT expectedSort)
void printSelectExpr(const ref< SelectExpr > &e, ExprSMTLIBPrinter::SMTLIB_SORT s)
void scanUpdates(const UpdateNode *un)
Helper function for scan() that scans the expressions of an update node.
@ OPTION_TRUE
Set option to true.
@ OPTION_FALSE
Set option to false.
void printUpdatesAndArray(const UpdateNode *un, const Array *root)
Recursively prints updatesNodes.
void printSortArgsExpr(const ref< Expr > &e, ExprSMTLIBPrinter::SMTLIB_SORT s)
@ HEX
Display bit vector constants in Hexidecimal e.g.#x2D.
@ BINARY
Display bit vector constants in binary e.g. #b00101101.
@ DECIMAL
Display bit vector constants in Decimal e.g. (_ bv45 8)
std::set< ref< Expr > > seenExprs
Set of expressions seen during scan.
void printAssert(const ref< Expr > &e)
Print an assert statement for the given expr.
ExprSMTLIBPrinter()
Create a new printer that will print a query in the SMTLIBv2 language.
std::vector< BindingMap > orderedBindings
void printExtractExpr(const ref< ExtractExpr > &e)
bool setSMTLIBboolOption(SMTLIBboolOptions option, SMTLIBboolValues value)
void printNotEqualExpr(const ref< NeExpr > &e)
ConstantDisplayMode cdm
void printLogicalOrBitVectorExpr(const ref< Expr > &e, ExprSMTLIBPrinter::SMTLIB_SORT s)
Class representing a byte update of an array.
Definition: Expr.h:451
Definition: main.cpp:291