Interpreter.h

Go to the documentation of this file.
00001 //===-- Interpreter.h - Abstract Execution Engine Interface -----*- C++ -*-===//
00002 //
00003 //                     The KLEE Symbolic Virtual Machine
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //===----------------------------------------------------------------------===//
00008 
00009 #ifndef KLEE_INTERPRETER_H
00010 #define KLEE_INTERPRETER_H
00011 
00012 #include <vector>
00013 #include <string>
00014 #include <map>
00015 #include <set>
00016 
00017 struct KTest;
00018 
00019 namespace llvm {
00020 class Function;
00021 class Module;
00022 }
00023 
00024 namespace klee {
00025 class ExecutionState;
00026 class Interpreter;
00027 class TreeStreamWriter;
00028 
00029 class InterpreterHandler {
00030 public:
00031   InterpreterHandler() {}
00032   virtual ~InterpreterHandler() {};
00033 
00034   virtual std::ostream &getInfoStream() const = 0;
00035 
00036   virtual std::string getOutputFilename(const std::string &filename) = 0;
00037   virtual std::ostream *openOutputFile(const std::string &filename) = 0;
00038 
00039   virtual void incPathsExplored() = 0;
00040 
00041   virtual void processTestCase(const ExecutionState &state,
00042                                const char *err, 
00043                                const char *suffix) = 0;
00044 };
00045 
00046 class Interpreter {
00047 public:
00050   struct ModuleOptions {
00051     std::string LibraryDir;
00052     bool Optimize;
00053     bool CheckDivZero;
00054 
00055     ModuleOptions(const std::string& _LibraryDir, 
00056                   bool _Optimize, bool _CheckDivZero)
00057       : LibraryDir(_LibraryDir), Optimize(_Optimize), 
00058         CheckDivZero(_CheckDivZero) {}
00059   };
00060 
00063   struct InterpreterOptions {
00067     unsigned MakeConcreteSymbolic;
00068 
00069     InterpreterOptions()
00070       : MakeConcreteSymbolic(false)
00071     {}
00072   };
00073 
00074 protected:
00075   const InterpreterOptions interpreterOpts;
00076 
00077   Interpreter(const InterpreterOptions &_interpreterOpts)
00078     : interpreterOpts(_interpreterOpts)
00079   {};
00080 
00081 public:
00082   virtual ~Interpreter() {};
00083 
00084   static Interpreter *create(const InterpreterOptions &_interpreterOpts,
00085                              InterpreterHandler *ih);
00086 
00091   virtual const llvm::Module * 
00092   setModule(llvm::Module *module, 
00093             const ModuleOptions &opts) = 0;
00094 
00095   // supply a tree stream writer which the interpreter will use
00096   // to record the concrete path (as a stream of '0' and '1' bytes).
00097   virtual void setPathWriter(TreeStreamWriter *tsw) = 0;
00098 
00099   // supply a tree stream writer which the interpreter will use
00100   // to record the symbolic path (as a stream of '0' and '1' bytes).
00101   virtual void setSymbolicPathWriter(TreeStreamWriter *tsw) = 0;
00102 
00103   // supply a test case to replay from. this can be used to drive the
00104   // interpretation down a user specified path. use null to reset.
00105   virtual void setReplayOut(const struct KTest *out) = 0;
00106 
00107   // supply a list of branch decisions specifying which direction to
00108   // take on forks. this can be used to drive the interpretation down
00109   // a user specified path. use null to reset.
00110   virtual void setReplayPath(const std::vector<bool> *path) = 0;
00111 
00112   // supply a set of symbolic bindings that will be used as "seeds"
00113   // for the search. use null to reset.
00114   virtual void useSeeds(const std::vector<struct KTest *> *seeds) = 0;
00115 
00116   virtual void runFunctionAsMain(llvm::Function *f,
00117                                  int argc,
00118                                  char **argv,
00119                                  char **envp) = 0;
00120 
00121   /*** Runtime options ***/
00122 
00123   virtual void setHaltExecution(bool value) = 0;
00124 
00125   virtual void setInhibitForking(bool value) = 0;
00126 
00127   /*** State accessor methods ***/
00128 
00129   virtual unsigned getPathStreamID(const ExecutionState &state) = 0;
00130 
00131   virtual unsigned getSymbolicPathStreamID(const ExecutionState &state) = 0;
00132   
00133   virtual void getConstraintLog(const ExecutionState &state,
00134                                 std::string &res,
00135                                 bool asCVC = false) = 0;
00136 
00137   virtual bool getSymbolicSolution(const ExecutionState &state, 
00138                                    std::vector< 
00139                                    std::pair<std::string,
00140                                    std::vector<unsigned char> > >
00141                                    &res) = 0;
00142 
00143   virtual void getCoveredLines(const ExecutionState &state,
00144                                std::map<const std::string*, std::set<unsigned> > &res) = 0;
00145 };
00146 
00147 } // End klee namespace
00148 
00149 #endif

Generated on Fri Jun 5 03:31:31 2009 for klee by  doxygen 1.5.8