diff --git a/docs/ProgrammersManual.html b/docs/ProgrammersManual.html index 36e59200683..20340c29812 100644 --- a/docs/ProgrammersManual.html +++ b/docs/ProgrammersManual.html @@ -218,13 +218,26 @@ that you should know about.
Basic Inspection and Traversal Routines
+ +Because the pattern for iteration is common across many different aspects of the +program representation, the standard template library algorithms may be used on +them, and it is easier to remember how to iterate. First we show a few common +examples of the data structures that need to be traversed. Other data +structures are traversed in very similar ways.
- -
// blk is a pointer to a BasicBlock instance - for(BasicBlock::iterator i = blk->begin(), e = blk->end(); i != e; ++i) { + for(BasicBlock::iterator i = blk->begin(), e = blk->end(); i != e; ++i) // the next statement works since operator<<(ostream&,...) // is overloaded for Instruction& - cerr << *i << endl; + cerr << *i << "\n";However, this isn't really the best way to print out the contents of a @@ -281,21 +295,23 @@ the pointer value you might expect. This is a deprecated interface that will be removed in the future, so it's best not to depend on it. To print out the pointer value for now, you must cast to void*.
+ -
-#include "llvm/Support/InstIterator.h" +#include "llvm/Support/InstIterator.h" ... // Suppose F is a ptr to a function for(inst_iterator i = inst_begin(F), e = inst_end(F); i != e; ++i) @@ -352,7 +368,7 @@ still need the following in order for things to work properly:Of course, this example is strictly pedagogical, because it'd be much @@ -411,10 +427,10 @@ class OurFunctionPass : public FunctionPass { public: OurFunctionPass(): callCounter(0) { } - virtual runOnFunction(Function& F) { + virtual runOnFunction(Function& F) { for(Function::iterator b = F.begin(), be = F.end(); b != be; ++b) { for(BasicBlock::iterator i = b->begin(); ie = b->end(); i != ie; ++i) { - if(CallInst* callInst = dyn_castBasicBlock::iterator bbi = ...; -BranchInst* b = dyn_cast<BranchInst>(&*bbi); +BranchInst* b = dyn_cast<BranchInst>(&*bbi);It's also possible to turn a class pointer into the corresponding @@ -366,7 +382,7 @@ over some structure: void printNextInstruction(Instruction* inst) { BasicBlock::iterator it(inst); ++it; // after this line, it refers to the instruction after *inst. - if(it != inst->getParent()->end()) cerr << *it << endl; + if(it != inst->getParent()->end()) cerr << *it << "\n"; }