diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Core/Executor.cpp | 2 | ||||
-rw-r--r-- | lib/Core/GetElementPtrTypeIterator.h | 154 | ||||
-rw-r--r-- | lib/Core/Memory.cpp | 1 | ||||
-rw-r--r-- | lib/Core/MergeHandler.h | 4 | ||||
-rw-r--r-- | lib/Expr/ArrayExprOptimizer.cpp | 2 | ||||
-rw-r--r-- | lib/Expr/ArrayExprRewriter.cpp | 2 | ||||
-rw-r--r-- | lib/Expr/ExprPPrinter.cpp | 2 | ||||
-rw-r--r-- | lib/Solver/ConstantDivision.cpp | 2 | ||||
-rw-r--r-- | lib/Solver/STPBuilder.cpp | 2 | ||||
-rw-r--r-- | lib/Solver/Z3Builder.cpp | 4 |
10 files changed, 165 insertions, 10 deletions
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp index 693ac006..0664e606 100644 --- a/lib/Core/Executor.cpp +++ b/lib/Core/Executor.cpp @@ -13,6 +13,7 @@ #include "CoreStats.h" #include "ExecutionState.h" #include "ExternalDispatcher.h" +#include "GetElementPtrTypeIterator.h" #include "ImpliedValue.h" #include "Memory.h" #include "MemoryManager.h" @@ -49,7 +50,6 @@ #include "klee/System/MemoryUsage.h" #include "klee/System/Time.h" #include "klee/TimerStatIncrementer.h" -#include "klee/util/GetElementPtrTypeIterator.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/StringExtras.h" diff --git a/lib/Core/GetElementPtrTypeIterator.h b/lib/Core/GetElementPtrTypeIterator.h new file mode 100644 index 00000000..cdbc36bc --- /dev/null +++ b/lib/Core/GetElementPtrTypeIterator.h @@ -0,0 +1,154 @@ +//===-- GetElementPtrTypeIterator.h -----------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements an iterator for walking through the types indexed by +// getelementptr, insertvalue and extractvalue instructions. +// +// It is an enhanced version of llvm::gep_type_iterator which only handles +// getelementptr. +// +//===----------------------------------------------------------------------===// + +#ifndef KLEE_GETELEMENTPTRTYPEITERATOR_H +#define KLEE_GETELEMENTPTRTYPEITERATOR_H + +#include "llvm/IR/User.h" +#include "llvm/IR/DerivedTypes.h" +#include "llvm/IR/Instructions.h" +#include "llvm/IR/Constants.h" + +#include "klee/Config/Version.h" + +namespace klee { +template <typename ItTy = llvm::User::const_op_iterator> +class generic_gep_type_iterator + : public std::iterator<std::forward_iterator_tag, llvm::Type *, ptrdiff_t> { + typedef std::iterator<std::forward_iterator_tag, llvm::Type *, ptrdiff_t> + super; + + ItTy OpIt; + llvm::Type *CurTy; + generic_gep_type_iterator() {} + + llvm::Value *asValue(llvm::Value *V) const { return V; } + llvm::Value *asValue(unsigned U) const { + return llvm::ConstantInt::get(CurTy->getContext(), llvm::APInt(32, U)); + } + + public: + static generic_gep_type_iterator begin(llvm::Type *Ty, ItTy It) { + generic_gep_type_iterator I; + I.CurTy = Ty; + I.OpIt = It; + return I; + } + static generic_gep_type_iterator end(ItTy It) { + generic_gep_type_iterator I; + I.CurTy = 0; + I.OpIt = It; + return I; + } + + bool operator==(const generic_gep_type_iterator& x) const { + return OpIt == x.OpIt; + } + bool operator!=(const generic_gep_type_iterator& x) const { + return !operator==(x); + } + + llvm::Type *operator*() const { return CurTy; } + + llvm::Type *getIndexedType() const { + llvm::CompositeType *CT = cast<llvm::CompositeType>(CurTy); + return CT->getTypeAtIndex(getOperand()); + } + + // This is a non-standard operator->. It allows you to call methods on the + // current type directly. + llvm::Type *operator->() const { return operator*(); } + + llvm::Value *getOperand() const { return asValue(*OpIt); } + + generic_gep_type_iterator& operator++() { // Preincrement + if (llvm::CompositeType *CT = dyn_cast<llvm::CompositeType>(CurTy)) { + CurTy = CT->getTypeAtIndex(getOperand()); +#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0) + } else if (auto ptr = dyn_cast<llvm::PointerType>(CurTy)) { + CurTy = ptr->getElementType(); +#endif + } else { + CurTy = 0; + } + ++OpIt; + return *this; + } + + generic_gep_type_iterator operator++(int) { // Postincrement + generic_gep_type_iterator tmp = *this; ++*this; return tmp; + } + }; + + typedef generic_gep_type_iterator<> gep_type_iterator; + typedef generic_gep_type_iterator<llvm::ExtractValueInst::idx_iterator> ev_type_iterator; + typedef generic_gep_type_iterator<llvm::InsertValueInst::idx_iterator> iv_type_iterator; + typedef generic_gep_type_iterator<llvm::SmallVector<unsigned, 4>::const_iterator> vce_type_iterator; + + inline gep_type_iterator gep_type_begin(const llvm::User *GEP) { + return gep_type_iterator::begin(GEP->getOperand(0)->getType(), + GEP->op_begin()+1); + } + inline gep_type_iterator gep_type_end(const llvm::User *GEP) { + return gep_type_iterator::end(GEP->op_end()); + } + inline gep_type_iterator gep_type_begin(const llvm::User &GEP) { + return gep_type_iterator::begin(GEP.getOperand(0)->getType(), + GEP.op_begin()+1); + } + inline gep_type_iterator gep_type_end(const llvm::User &GEP) { + return gep_type_iterator::end(GEP.op_end()); + } + + inline ev_type_iterator ev_type_begin(const llvm::ExtractValueInst *EV) { + return ev_type_iterator::begin(EV->getOperand(0)->getType(), + EV->idx_begin()); + } + inline ev_type_iterator ev_type_end(const llvm::ExtractValueInst *EV) { + return ev_type_iterator::end(EV->idx_end()); + } + + inline iv_type_iterator iv_type_begin(const llvm::InsertValueInst *IV) { + return iv_type_iterator::begin(IV->getType(), + IV->idx_begin()); + } + inline iv_type_iterator iv_type_end(const llvm::InsertValueInst *IV) { + return iv_type_iterator::end(IV->idx_end()); + } + + inline vce_type_iterator vce_type_begin(const llvm::ConstantExpr *CE) { + return vce_type_iterator::begin(CE->getOperand(0)->getType(), + CE->getIndices().begin()); + } + inline vce_type_iterator vce_type_end(const llvm::ConstantExpr *CE) { + return vce_type_iterator::end(CE->getIndices().end()); + } + + template <typename ItTy> + inline generic_gep_type_iterator<ItTy> gep_type_begin(llvm::Type *Op0, ItTy I, + ItTy E) { + return generic_gep_type_iterator<ItTy>::begin(Op0, I); + } + + template <typename ItTy> + inline generic_gep_type_iterator<ItTy> gep_type_end(llvm::Type *Op0, ItTy I, + ItTy E) { + return generic_gep_type_iterator<ItTy>::end(E); + } +} // end namespace klee + +#endif /* KLEE_GETELEMENTPTRTYPEITERATOR_H */ diff --git a/lib/Core/Memory.cpp b/lib/Core/Memory.cpp index b93373b8..35b09011 100644 --- a/lib/Core/Memory.cpp +++ b/lib/Core/Memory.cpp @@ -18,7 +18,6 @@ #include "klee/OptionCategories.h" #include "klee/Solver/Solver.h" #include "klee/Support/ErrorHandling.h" -#include "klee/util/BitArray.h" #include "llvm/IR/Function.h" #include "llvm/IR/Instruction.h" diff --git a/lib/Core/MergeHandler.h b/lib/Core/MergeHandler.h index 48b67467..f7380415 100644 --- a/lib/Core/MergeHandler.h +++ b/lib/Core/MergeHandler.h @@ -69,8 +69,10 @@ #ifndef KLEE_MERGEHANDLER_H #define KLEE_MERGEHANDLER_H -#include "klee/util/Ref.h" +#include "klee/ADT/Ref.h" + #include "llvm/Support/CommandLine.h" + #include <map> #include <stdint.h> #include <vector> diff --git a/lib/Expr/ArrayExprOptimizer.cpp b/lib/Expr/ArrayExprOptimizer.cpp index 6e10461f..bb949fac 100644 --- a/lib/Expr/ArrayExprOptimizer.cpp +++ b/lib/Expr/ArrayExprOptimizer.cpp @@ -9,6 +9,7 @@ #include "klee/Expr/ArrayExprOptimizer.h" +#include "klee/ADT/BitArray.h" #include "klee/Config/Version.h" #include "klee/Expr/ArrayExprRewriter.h" #include "klee/Expr/ArrayExprVisitor.h" @@ -17,7 +18,6 @@ #include "klee/Expr/ExprBuilder.h" #include "klee/OptionCategories.h" #include "klee/Support/ErrorHandling.h" -#include "klee/util/BitArray.h" #include <llvm/ADT/APInt.h> #include <llvm/Support/Casting.h> diff --git a/lib/Expr/ArrayExprRewriter.cpp b/lib/Expr/ArrayExprRewriter.cpp index 32851679..4de76d43 100644 --- a/lib/Expr/ArrayExprRewriter.cpp +++ b/lib/Expr/ArrayExprRewriter.cpp @@ -9,8 +9,8 @@ #include "klee/Expr/ArrayExprRewriter.h" +#include "klee/ADT/BitArray.h" #include "klee/Expr/ArrayExprVisitor.h" -#include "klee/util/BitArray.h" #include <llvm/ADT/APInt.h> #include <llvm/Support/Casting.h> diff --git a/lib/Expr/ExprPPrinter.cpp b/lib/Expr/ExprPPrinter.cpp index 9d34e356..50a61cfd 100644 --- a/lib/Expr/ExprPPrinter.cpp +++ b/lib/Expr/ExprPPrinter.cpp @@ -11,7 +11,7 @@ #include "klee/Expr/Constraints.h" #include "klee/OptionCategories.h" -#include "klee/util/PrintContext.h" +#include "klee/Support/PrintContext.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/raw_ostream.h" diff --git a/lib/Solver/ConstantDivision.cpp b/lib/Solver/ConstantDivision.cpp index 8ebf39ad..d822de1a 100644 --- a/lib/Solver/ConstantDivision.cpp +++ b/lib/Solver/ConstantDivision.cpp @@ -9,7 +9,7 @@ #include "ConstantDivision.h" -#include "klee/util/Bits.h" +#include "klee/ADT/Bits.h" #include <algorithm> #include <cassert> diff --git a/lib/Solver/STPBuilder.cpp b/lib/Solver/STPBuilder.cpp index 5857e6f0..9fd9dc8e 100644 --- a/lib/Solver/STPBuilder.cpp +++ b/lib/Solver/STPBuilder.cpp @@ -10,10 +10,10 @@ #ifdef ENABLE_STP #include "STPBuilder.h" +#include "klee/ADT/Bits.h" #include "klee/Expr/Expr.h" #include "klee/Solver/Solver.h" #include "klee/Solver/SolverStats.h" -#include "klee/util/Bits.h" #include "ConstantDivision.h" diff --git a/lib/Solver/Z3Builder.cpp b/lib/Solver/Z3Builder.cpp index 7db377eb..ce584175 100644 --- a/lib/Solver/Z3Builder.cpp +++ b/lib/Solver/Z3Builder.cpp @@ -10,11 +10,11 @@ #ifdef ENABLE_Z3 #include "Z3Builder.h" +#include "klee/ADT/Bits.h" #include "klee/Expr/Expr.h" -#include "klee/Support/ErrorHandling.h" #include "klee/Solver/Solver.h" #include "klee/Solver/SolverStats.h" -#include "klee/util/Bits.h" +#include "klee/Support/ErrorHandling.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Support/CommandLine.h" |