From 82e2eea16861455b8a1f98756248b0f0baa0121b Mon Sep 17 00:00:00 2001
From: Bill Wendling
if (AllocationInst *AI = dyn_cast<AllocationInst>(Val)) {
- // ...
+ // ...
}
$ opt < a.bc > /dev/null -mypass
-<no output>
+<no output>
$ opt < a.bc > /dev/null -mypass -debug
I am here!
@@ -458,7 +458,7 @@ DEBUG(std::cerr << "No debug type (2)\n");
$ opt < a.bc > /dev/null -mypass
-<no output>
+<no output>
$ opt < a.bc > /dev/null -mypass -debug
No debug type
'foo' debug type
@@ -525,7 +525,7 @@ static Statistic<> NumXForms("mypassname", "The # of times I did stuff");
-++NumXForms; // I did stuff!
+++NumXForms; // I did stuff!
$ opt -stats -mypassname < program.bc > /dev/null
-... statistic output ...
+... statistics output ...
-// func is a pointer to a Function instance
-for (Function::iterator i = func->begin(), e = func->end(); i != e; ++i) {
- // print out the name of the basic block if it has one, and then the
- // number of instructions that it contains
+// func is a pointer to a Function instance
+for (Function::iterator i = func->begin(), e = func->end(); i != e; ++i)
+ // Print out the name of the basic block if it has one, and then the
+ // number of instructions that it contains
std::cerr << "Basic block (name=" << i->getName() << ") has "
<< i->size() << " instructions.\n";
-}
-// blk is a pointer to a BasicBlock instance
+// blk is a pointer to a BasicBlock instance
for (BasicBlock::iterator i = blk->begin(), e = blk->end(); i != e; ++i)
- // the next statement works since operator<<(ostream&,...)
- // is overloaded for Instruction&
+ // The next statement works since operator<<(ostream&,...)
+ // is overloaded for Instruction&
std::cerr << *i << "\n";
#include "llvm/Support/InstIterator.h"
-// Suppose F is a ptr to a function
+// F is a ptr to a Function instance
for (inst_iterator i = inst_begin(F), e = inst_end(F); i != e; ++i)
std::cerr << *i << "\n";
@@ -799,8 +798,8 @@ is a BasicBlock::const_iterator:
-Instruction& inst = *i; // grab reference to instruction reference
-Instruction* pinst = &*i; // grab pointer to instruction reference
+Instruction& inst = *i; // Grab reference to instruction reference
+Instruction* pinst = &*i; // Grab pointer to instruction reference
const Instruction& inst = *j;
void printNextInstruction(Instruction* inst) {
BasicBlock::iterator it(inst);
- ++it; // after this line, it refers to the instruction after *inst.
+ ++it; // After this line, it refers to the instruction after *inst
if (it != inst->getParent()->end()) std::cerr << *it << "\n";
}
@@ -889,16 +888,16 @@ class OurFunctionPass : public FunctionPass {
for (BasicBlock::iterator i = b->begin(); ie = b->end(); i != ie; ++i) {
if (CallInst* callInst = dyn_cast<CallInst>(&*i)) {
- // we know we've encountered a call instruction, so we
- // need to determine if it's a call to the
- // function pointed to by m_func or not.
+ // We know we've encountered a call instruction, so we
+ // need to determine if it's a call to the
+ // function pointed to by m_func or not
if (callInst->getCalledFunction() == targetFunc)
++callCounter;
}
}
}
-
+ }
private:
unsigned callCounter;
@@ -955,12 +954,11 @@ of F:
Function* F = ...;
-for (Value::use_iterator i = F->use_begin(), e = F->use_end(); i != e; ++i) {
+for (Value::use_iterator i = F->use_begin(), e = F->use_end(); i != e; ++i)
if (Instruction *Inst = dyn_cast<Instruction>(*i)) {
std::cerr << "F is used in instruction:\n";
std::cerr << *Inst << "\n";
}
-}
-// Create the initial outer struct.
+// Create the initial outer struct
PATypeHolder StructTy = OpaqueType::get();
std::vector<const Type*> Elts;
Elts.push_back(PointerType::get(StructTy));
Elts.push_back(Type::IntTy);
StructType *NewSTy = StructType::get(Elts);
-// At this point, NewSTy = "{ opaque*, int }". Tell VMCore that
-// the struct and the opaque type are actually the same.
+// At this point, NewSTy = "{ opaque*, int }". Tell VMCore that
+// the struct and the opaque type are actually the same.
cast<OpaqueType>(StructTy.get())->refineAbstractTypeTo(NewSTy);
// NewSTy is potentially invalidated, but StructTy (a PATypeHolder) is
-// kept up-to-date.
+// kept up-to-date
NewSTy = cast<StructType>(StructTy.get());
-// Add a name for the type to the module symbol table (optional).
+// Add a name for the type to the module symbol table (optional)
MyModule->addTypeName("mylist", NewSTy);
for (SymbolTable::plane_const_iterator PI = ST.plane_begin(), PE = ST.plane_end(); PI != PE; ++PI ) { - PI->first // This is the Type* of the plane - PI->second // This is the SymbolTable::ValueMap of name/Value pairs + PI->first // This is the Type* of the plane + PI->second // This is the SymbolTable::ValueMap of name/Value pairs }
for (SymbolTable::type_const_iterator TI = ST.type_begin(), TE = ST.type_end(); TI != TE; ++TI ) { - TI->first // This is the name of the type - TI->second // This is the Type* value associated with the name + TI->first // This is the name of the type + TI->second // This is the Type* value associated with the name }
for (SymbolTable::value_const_iterator VI = ST.value_begin(SomeType), VE = ST.value_end(SomeType); VI != VE; ++VI ) { - VI->first // This is the name of the Value - VI->second // This is the Value* value associated with the name + VI->first // This is the name of the Value + VI->second // This is the Value* value associated with the name }