2014-03-04 10:40:04 +00:00
|
|
|
//===- GetElementPtrTypeIterator.h ------------------------------*- C++ -*-===//
|
2005-04-21 20:48:15 +00:00
|
|
|
//
|
2003-11-25 19:37:28 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 20:48:15 +00:00
|
|
|
//
|
2003-11-25 19:37:28 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements an iterator for walking through the types indexed by
|
|
|
|
// getelementptr instructions.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-03-04 10:40:04 +00:00
|
|
|
#ifndef LLVM_IR_GETELEMENTPTRTYPEITERATOR_H
|
|
|
|
#define LLVM_IR_GETELEMENTPTRTYPEITERATOR_H
|
2003-11-25 19:37:28 +00:00
|
|
|
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/DerivedTypes.h"
|
|
|
|
#include "llvm/IR/User.h"
|
2003-11-25 19:37:28 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
2004-04-04 19:46:54 +00:00
|
|
|
template<typename ItTy = User::const_op_iterator>
|
2004-04-03 23:29:11 +00:00
|
|
|
class generic_gep_type_iterator
|
2011-07-18 04:54:35 +00:00
|
|
|
: public std::iterator<std::forward_iterator_tag, Type *, ptrdiff_t> {
|
2009-08-27 23:44:33 +00:00
|
|
|
typedef std::iterator<std::forward_iterator_tag,
|
2011-07-18 04:54:35 +00:00
|
|
|
Type *, ptrdiff_t> super;
|
2003-11-25 19:37:28 +00:00
|
|
|
|
2004-04-03 23:29:11 +00:00
|
|
|
ItTy OpIt;
|
2011-07-18 04:54:35 +00:00
|
|
|
Type *CurTy;
|
2004-04-03 23:29:11 +00:00
|
|
|
generic_gep_type_iterator() {}
|
2003-11-25 19:37:28 +00:00
|
|
|
public:
|
|
|
|
|
2011-07-18 04:54:35 +00:00
|
|
|
static generic_gep_type_iterator begin(Type *Ty, ItTy It) {
|
2004-04-03 23:29:11 +00:00
|
|
|
generic_gep_type_iterator I;
|
2004-02-22 06:27:03 +00:00
|
|
|
I.CurTy = Ty;
|
|
|
|
I.OpIt = It;
|
2003-11-25 19:37:28 +00:00
|
|
|
return I;
|
|
|
|
}
|
2004-04-03 23:29:11 +00:00
|
|
|
static generic_gep_type_iterator end(ItTy It) {
|
|
|
|
generic_gep_type_iterator I;
|
2014-04-09 06:08:46 +00:00
|
|
|
I.CurTy = nullptr;
|
2004-02-22 06:27:03 +00:00
|
|
|
I.OpIt = It;
|
2003-11-25 19:37:28 +00:00
|
|
|
return I;
|
|
|
|
}
|
|
|
|
|
2005-04-21 20:48:15 +00:00
|
|
|
bool operator==(const generic_gep_type_iterator& x) const {
|
2004-02-22 06:27:03 +00:00
|
|
|
return OpIt == x.OpIt;
|
2003-11-25 19:37:28 +00:00
|
|
|
}
|
2004-04-03 23:29:11 +00:00
|
|
|
bool operator!=(const generic_gep_type_iterator& x) const {
|
2003-11-25 19:37:28 +00:00
|
|
|
return !operator==(x);
|
|
|
|
}
|
|
|
|
|
2011-07-18 04:54:35 +00:00
|
|
|
Type *operator*() const {
|
2003-11-25 19:37:28 +00:00
|
|
|
return CurTy;
|
|
|
|
}
|
|
|
|
|
2011-07-18 04:54:35 +00:00
|
|
|
Type *getIndexedType() const {
|
|
|
|
CompositeType *CT = cast<CompositeType>(CurTy);
|
2005-01-13 23:26:28 +00:00
|
|
|
return CT->getTypeAtIndex(getOperand());
|
|
|
|
}
|
|
|
|
|
2003-11-25 19:37:28 +00:00
|
|
|
// This is a non-standard operator->. It allows you to call methods on the
|
|
|
|
// current type directly.
|
2011-07-18 04:54:35 +00:00
|
|
|
Type *operator->() const { return operator*(); }
|
2005-04-21 20:48:15 +00:00
|
|
|
|
2004-02-22 06:27:03 +00:00
|
|
|
Value *getOperand() const { return *OpIt; }
|
2003-11-25 19:37:28 +00:00
|
|
|
|
2004-04-03 23:29:11 +00:00
|
|
|
generic_gep_type_iterator& operator++() { // Preincrement
|
2011-07-18 04:54:35 +00:00
|
|
|
if (CompositeType *CT = dyn_cast<CompositeType>(CurTy)) {
|
2003-11-25 19:37:28 +00:00
|
|
|
CurTy = CT->getTypeAtIndex(getOperand());
|
|
|
|
} else {
|
2014-04-09 06:08:46 +00:00
|
|
|
CurTy = nullptr;
|
2003-11-25 19:37:28 +00:00
|
|
|
}
|
2004-02-22 06:27:03 +00:00
|
|
|
++OpIt;
|
2005-04-21 20:48:15 +00:00
|
|
|
return *this;
|
2003-11-25 19:37:28 +00:00
|
|
|
}
|
|
|
|
|
2004-04-03 23:29:11 +00:00
|
|
|
generic_gep_type_iterator operator++(int) { // Postincrement
|
2005-04-21 20:48:15 +00:00
|
|
|
generic_gep_type_iterator tmp = *this; ++*this; return tmp;
|
2003-11-25 19:37:28 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2004-04-03 23:29:11 +00:00
|
|
|
typedef generic_gep_type_iterator<> gep_type_iterator;
|
|
|
|
|
2004-04-04 19:46:54 +00:00
|
|
|
inline gep_type_iterator gep_type_begin(const User *GEP) {
|
2012-11-13 13:01:00 +00:00
|
|
|
return gep_type_iterator::begin
|
|
|
|
(GEP->getOperand(0)->getType()->getScalarType(), GEP->op_begin()+1);
|
2003-11-25 19:37:28 +00:00
|
|
|
}
|
2004-04-04 19:46:54 +00:00
|
|
|
inline gep_type_iterator gep_type_end(const User *GEP) {
|
2004-02-22 06:27:03 +00:00
|
|
|
return gep_type_iterator::end(GEP->op_end());
|
2003-11-25 19:37:28 +00:00
|
|
|
}
|
2004-04-04 19:46:54 +00:00
|
|
|
inline gep_type_iterator gep_type_begin(const User &GEP) {
|
2012-11-13 13:01:00 +00:00
|
|
|
return gep_type_iterator::begin
|
|
|
|
(GEP.getOperand(0)->getType()->getScalarType(), GEP.op_begin()+1);
|
2003-11-25 20:17:49 +00:00
|
|
|
}
|
2004-04-04 19:46:54 +00:00
|
|
|
inline gep_type_iterator gep_type_end(const User &GEP) {
|
2004-02-22 06:27:03 +00:00
|
|
|
return gep_type_iterator::end(GEP.op_end());
|
|
|
|
}
|
2004-04-03 23:29:11 +00:00
|
|
|
|
2011-07-19 14:42:50 +00:00
|
|
|
template<typename T>
|
|
|
|
inline generic_gep_type_iterator<const T *>
|
|
|
|
gep_type_begin(Type *Op0, ArrayRef<T> A) {
|
|
|
|
return generic_gep_type_iterator<const T *>::begin(Op0, A.begin());
|
2004-02-22 06:27:03 +00:00
|
|
|
}
|
2004-04-03 23:29:11 +00:00
|
|
|
|
2011-07-19 14:42:50 +00:00
|
|
|
template<typename T>
|
|
|
|
inline generic_gep_type_iterator<const T *>
|
2013-06-10 12:09:30 +00:00
|
|
|
gep_type_end(Type * /*Op0*/, ArrayRef<T> A) {
|
2011-07-19 14:42:50 +00:00
|
|
|
return generic_gep_type_iterator<const T *>::end(A.end());
|
2003-11-25 20:17:49 +00:00
|
|
|
}
|
2003-11-25 19:37:28 +00:00
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|