#include "llvm/SlotCalculator.h"
#include "llvm/Analysis/ConstantsScanner.h"
-#include "llvm/Function.h"
-#include "llvm/GlobalVariable.h"
#include "llvm/Module.h"
-#include "llvm/BasicBlock.h"
-#include "llvm/ConstantVals.h"
#include "llvm/iOther.h"
+#include "llvm/Constant.h"
#include "llvm/DerivedTypes.h"
#include "llvm/SymbolTable.h"
-#include "llvm/Argument.h"
#include "Support/DepthFirstIterator.h"
#include "Support/STLExtras.h"
#include <algorithm>
// Add all of the constants that the global variables might refer to first.
//
for (Module::const_giterator I = TheModule->gbegin(), E = TheModule->gend();
- I != E; ++I) {
- if ((*I)->hasInitializer())
- insertValue((*I)->getInitializer());
- }
+ I != E; ++I)
+ if (I->hasInitializer())
+ insertValue(I->getInitializer());
// Add all of the global variables to the value table...
//
- for_each(TheModule->gbegin(), TheModule->gend(),
- bind_obj(this, &SlotCalculator::insertValue));
+ for(Module::const_giterator I = TheModule->gbegin(), E = TheModule->gend();
+ I != E; ++I)
+ insertValue(I);
// Scavenge the types out of the functions, then add the functions themselves
// to the value table...
//
- for_each(TheModule->begin(), TheModule->end(), // Insert functions...
- bind_obj(this, &SlotCalculator::insertValue));
+ for(Module::const_iterator I = TheModule->begin(), E = TheModule->end();
+ I != E; ++I)
+ insertValue(I);
// Insert constants that are named at module level into the slot pool so that
// the module symbol table can refer to them...
SC_DEBUG("Inserting function arguments\n");
// Iterate over function arguments, adding them to the value table...
- for_each(M->getArgumentList().begin(), M->getArgumentList().end(),
- bind_obj(this, &SlotCalculator::insertValue));
+ for(Function::const_aiterator I = M->abegin(), E = M->aend(); I != E; ++I)
+ insertValue(I);
// Iterate over all of the instructions in the function, looking for constant
// values that are referenced. Add these to the value pools before any
SC_DEBUG("Inserting function constants:\n";
for (constant_iterator I = constant_begin(M), E = constant_end(M);
I != E; ++I) {
- cerr << " " << I->getType()->getDescription()
- << " " << I->getStrValue() << endl;
+ cerr << " " << *I->getType()
+ << " " << *I << "\n";
});
// Emit all of the constants that are being used by the instructions in the
SC_DEBUG("Inserting Labels:\n");
// Iterate over basic blocks, adding them to the value table...
- for_each(M->begin(), M->end(),
- bind_obj(this, &SlotCalculator::insertValue));
+ for (Function::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
+ insertValue(I);
+ /* for_each(M->begin(), M->end(),
+ bind_obj(this, &SlotCalculator::insertValue));*/
SC_DEBUG("Inserting Instructions:\n");
for (unsigned i = 0; i < NumModuleTypes; ++i) {
unsigned ModuleSize = ModuleLevel[i]; // Size of plane before function came
TypePlane &CurPlane = Table[i];
- //SC_DEBUG("Processing Plane " <<i<< " of size " << CurPlane.size() <<endl);
+ //SC_DEBUG("Processing Plane " <<i<< " of size " << CurPlane.size() <<"\n");
while (CurPlane.size() != ModuleSize) {
//SC_DEBUG(" Removing [" << i << "] Value=" << CurPlane.back() << "\n");
while (NumModuleTypes != Table.size()) {
TypePlane &Plane = Table.back();
SC_DEBUG("Removing Plane " << (Table.size()-1) << " of size "
- << Plane.size() << endl);
+ << Plane.size() << "\n");
while (Plane.size()) {
NodeMap.erase(NodeMap.find(Plane.back())); // Erase from nodemap
Plane.pop_back(); // Shrink plane
// initializers.
//
for(User::const_op_iterator I = U->op_begin(), E = U->op_end(); I != E; ++I)
- if (!isa<GlobalValue>(*I)) // Don't chain insert global values
+ if (!isa<GlobalValue>(*I)) // Don't chain insert global values
insertValue(*I);
}
}
-int SlotCalculator::insertVal(const Value *D, bool dontIgnore = false) {
+int SlotCalculator::insertVal(const Value *D, bool dontIgnore) {
assert(D && "Can't insert a null value!");
assert(getValSlot(D) == -1 && "Value is already in the table!");
if (D->getType() == Type::VoidTy || // Ignore void type nodes
(IgnoreNamedNodes && // Ignore named and constants
(D->hasName() || isa<Constant>(D)) && !isa<Type>(D))) {
- SC_DEBUG("ignored value " << D << endl);
+ SC_DEBUG("ignored value " << D << "\n");
return -1; // We do need types unconditionally though
}
if ((ResultSlot = getValSlot(TheTy)) == -1) {
ResultSlot = doInsertVal(TheTy);
SC_DEBUG(" Inserted type: " << TheTy->getDescription() << " slot=" <<
- ResultSlot << endl);
+ ResultSlot << "\n");
}
// Loop over any contained types in the definition... in reverse depth first
// If we haven't seen this sub type before, add it to our type table!
const Type *SubTy = *I;
if (getValSlot(SubTy) == -1) {
- SC_DEBUG(" Inserting subtype: " << SubTy->getDescription() << endl);
+ SC_DEBUG(" Inserting subtype: " << SubTy->getDescription() << "\n");
int Slot = doInsertVal(SubTy);
SC_DEBUG(" Inserted subtype: " << SubTy->getDescription() <<
- " slot=" << Slot << endl);
+ " slot=" << Slot << "\n");
}
}
return ResultSlot;