mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-01 00:33:09 +00:00
Allow for use of arbitrary iterator types...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12642 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
5da80974c0
commit
43cb041754
@ -19,32 +19,33 @@
|
|||||||
#include "llvm/DerivedTypes.h"
|
#include "llvm/DerivedTypes.h"
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
class gep_type_iterator
|
template<typename ItTy = User::op_iterator>
|
||||||
|
class generic_gep_type_iterator
|
||||||
: public forward_iterator<const Type *, ptrdiff_t> {
|
: public forward_iterator<const Type *, ptrdiff_t> {
|
||||||
typedef forward_iterator<const Type*, ptrdiff_t> super;
|
typedef forward_iterator<const Type*, ptrdiff_t> super;
|
||||||
|
|
||||||
User::op_iterator OpIt;
|
ItTy OpIt;
|
||||||
const Type *CurTy;
|
const Type *CurTy;
|
||||||
gep_type_iterator() {}
|
generic_gep_type_iterator() {}
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static gep_type_iterator begin(const Type *Ty, User::op_iterator It) {
|
static generic_gep_type_iterator begin(const Type *Ty, ItTy It) {
|
||||||
gep_type_iterator I;
|
generic_gep_type_iterator I;
|
||||||
I.CurTy = Ty;
|
I.CurTy = Ty;
|
||||||
I.OpIt = It;
|
I.OpIt = It;
|
||||||
return I;
|
return I;
|
||||||
}
|
}
|
||||||
static gep_type_iterator end(User::op_iterator It) {
|
static generic_gep_type_iterator end(ItTy It) {
|
||||||
gep_type_iterator I;
|
generic_gep_type_iterator I;
|
||||||
I.CurTy = 0;
|
I.CurTy = 0;
|
||||||
I.OpIt = It;
|
I.OpIt = It;
|
||||||
return I;
|
return I;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const gep_type_iterator& x) const {
|
bool operator==(const generic_gep_type_iterator& x) const {
|
||||||
return OpIt == x.OpIt;
|
return OpIt == x.OpIt;
|
||||||
}
|
}
|
||||||
bool operator!=(const gep_type_iterator& x) const {
|
bool operator!=(const generic_gep_type_iterator& x) const {
|
||||||
return !operator==(x);
|
return !operator==(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +59,7 @@ namespace llvm {
|
|||||||
|
|
||||||
Value *getOperand() const { return *OpIt; }
|
Value *getOperand() const { return *OpIt; }
|
||||||
|
|
||||||
gep_type_iterator& operator++() { // Preincrement
|
generic_gep_type_iterator& operator++() { // Preincrement
|
||||||
if (const CompositeType *CT = dyn_cast<CompositeType>(CurTy)) {
|
if (const CompositeType *CT = dyn_cast<CompositeType>(CurTy)) {
|
||||||
CurTy = CT->getTypeAtIndex(getOperand());
|
CurTy = CT->getTypeAtIndex(getOperand());
|
||||||
} else {
|
} else {
|
||||||
@ -68,14 +69,16 @@ namespace llvm {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
gep_type_iterator operator++(int) { // Postincrement
|
generic_gep_type_iterator operator++(int) { // Postincrement
|
||||||
gep_type_iterator tmp = *this; ++*this; return tmp;
|
generic_gep_type_iterator tmp = *this; ++*this; return tmp;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef generic_gep_type_iterator<> gep_type_iterator;
|
||||||
|
|
||||||
inline gep_type_iterator gep_type_begin(User *GEP) {
|
inline gep_type_iterator gep_type_begin(User *GEP) {
|
||||||
return gep_type_iterator::begin(GEP->getOperand(0)->getType(),
|
return gep_type_iterator::begin(GEP->getOperand(0)->getType(),
|
||||||
GEP->op_begin()+1);
|
GEP->op_begin()+1);
|
||||||
}
|
}
|
||||||
inline gep_type_iterator gep_type_end(User *GEP) {
|
inline gep_type_iterator gep_type_end(User *GEP) {
|
||||||
return gep_type_iterator::end(GEP->op_end());
|
return gep_type_iterator::end(GEP->op_end());
|
||||||
@ -87,13 +90,17 @@ namespace llvm {
|
|||||||
inline gep_type_iterator gep_type_end(User &GEP) {
|
inline gep_type_iterator gep_type_end(User &GEP) {
|
||||||
return gep_type_iterator::end(GEP.op_end());
|
return gep_type_iterator::end(GEP.op_end());
|
||||||
}
|
}
|
||||||
inline gep_type_iterator gep_type_begin(const Type *Op0, User::op_iterator I,
|
|
||||||
User::op_iterator E) {
|
template<typename ItTy>
|
||||||
return gep_type_iterator::begin(Op0, I);
|
inline generic_gep_type_iterator<ItTy>
|
||||||
|
gep_type_begin(const Type *Op0, ItTy I, ItTy E) {
|
||||||
|
return generic_gep_type_iterator<ItTy>::begin(Op0, I);
|
||||||
}
|
}
|
||||||
inline gep_type_iterator gep_type_end(const Type *Op0, User::op_iterator I,
|
|
||||||
User::op_iterator E) {
|
template<typename ItTy>
|
||||||
return gep_type_iterator::end(E);
|
inline generic_gep_type_iterator<ItTy>
|
||||||
|
gep_type_end(const Type *Op0, ItTy I, ItTy E) {
|
||||||
|
return generic_gep_type_iterator<ItTy>::end(E);
|
||||||
}
|
}
|
||||||
} // end namespace llvm
|
} // end namespace llvm
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user