#include "llvm/ValueSymbolTable.h"
#include "llvm/TypeSymbolTable.h"
#include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/CFG.h"
+#include "llvm/Support/Debug.h"
#include "llvm/Support/Dwarf.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
const Function* TheFunction;
bool FunctionProcessed;
- /// TheMDNode - The MDNode for which we are holding slot numbers.
- const MDNode *TheMDNode;
-
/// mMap - The TypePlanes map for the module level data.
ValueMap mMap;
unsigned mNext;
unsigned fNext;
/// mdnMap - Map for MDNodes.
- ValueMap mdnMap;
+ DenseMap<const MDNode*, unsigned> mdnMap;
unsigned mdnNext;
public:
/// Construct from a module
explicit SlotTracker(const Module *M);
/// Construct from a function, starting out in incorp state.
explicit SlotTracker(const Function *F);
- /// Construct from a mdnode.
- explicit SlotTracker(const MDNode *N);
/// Return the slot number of the specified value in it's type
/// plane. If something is not in the SlotTracker, return -1.
void purgeFunction();
/// MDNode map iterators.
- ValueMap::iterator mdnBegin() { return mdnMap.begin(); }
- ValueMap::iterator mdnEnd() { return mdnMap.end(); }
- unsigned mdnSize() const { return mdnMap.size(); }
- bool mdnEmpty() const { return mdnMap.empty(); }
+ typedef DenseMap<const MDNode*, unsigned>::iterator mdn_iterator;
+ mdn_iterator mdn_begin() { return mdnMap.begin(); }
+ mdn_iterator mdn_end() { return mdnMap.end(); }
+ unsigned mdn_size() const { return mdnMap.size(); }
+ bool mdn_empty() const { return mdnMap.empty(); }
/// This function does the actual initialization.
inline void initialize();
/// Add all of the functions arguments, basic blocks, and instructions.
void processFunction();
- /// Add all MDNode operands.
- void processMDNode();
-
SlotTracker(const SlotTracker &); // DO NOT IMPLEMENT
void operator=(const SlotTracker &); // DO NOT IMPLEMENT
};
if (const Function *Func = dyn_cast<Function>(V))
return new SlotTracker(Func);
+ if (isa<MDNode>(V))
+ return new SlotTracker((Function *)0);
+
return 0;
}
#if 0
-#define ST_DEBUG(X) errs() << X
+#define ST_DEBUG(X) dbgs() << X
#else
#define ST_DEBUG(X)
#endif
// Module level constructor. Causes the contents of the Module (sans functions)
// to be added to the slot table.
SlotTracker::SlotTracker(const Module *M)
- : TheModule(M), TheFunction(0), FunctionProcessed(false), TheMDNode(0),
+ : TheModule(M), TheFunction(0), FunctionProcessed(false),
mNext(0), fNext(0), mdnNext(0) {
}
// function provided to be added to the slot table.
SlotTracker::SlotTracker(const Function *F)
: TheModule(F ? F->getParent() : 0), TheFunction(F), FunctionProcessed(false),
- TheMDNode(0), mNext(0), fNext(0), mdnNext(0) {
-}
-
-// Constructor to handle single MDNode.
-SlotTracker::SlotTracker(const MDNode *C)
- : TheModule(0), TheFunction(0), FunctionProcessed(false), TheMDNode(C),
- mNext(0), fNext(0), mdnNext(0) {
+ mNext(0), fNext(0), mdnNext(0) {
}
inline void SlotTracker::initialize() {
if (TheFunction && !FunctionProcessed)
processFunction();
-
- if (TheMDNode)
- processMDNode();
}
// Iterate through all the global variables, functions, and global
E = TheModule->global_end(); I != E; ++I) {
if (!I->hasName())
CreateModuleSlot(I);
- if (I->hasInitializer()) {
- if (MDNode *N = dyn_cast<MDNode>(I->getInitializer()))
- CreateMetadataSlot(N);
- }
}
// Add metadata used by named metadata.
E = TheModule->named_metadata_end(); I != E; ++I) {
const NamedMDNode *NMD = I;
for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
- MDNode *MD = dyn_cast_or_null<MDNode>(NMD->getOperand(i));
- if (MD)
+ if (MDNode *MD = NMD->getOperand(i))
CreateMetadataSlot(MD);
}
}
ST_DEBUG("Inserting Instructions:\n");
- SmallVector<std::pair<unsigned, MDNode*>, 2> MDForInst;
+ SmallVector<std::pair<unsigned, MDNode*>, 4> MDForInst;
// Add all of the basic blocks and instructions with no names.
for (Function::const_iterator BB = TheFunction->begin(),
CreateMetadataSlot(N);
// Process metadata attached with this instruction.
- MDForInst.clear();
I->getAllMetadata(MDForInst);
for (unsigned i = 0, e = MDForInst.size(); i != e; ++i)
CreateMetadataSlot(MDForInst[i].second);
+ MDForInst.clear();
}
}
ST_DEBUG("end processFunction!\n");
}
-/// processMDNode - Process TheMDNode.
-void SlotTracker::processMDNode() {
- ST_DEBUG("begin processMDNode!\n");
- mdnNext = 0;
- CreateMetadataSlot(TheMDNode);
- TheMDNode = 0;
- ST_DEBUG("end processMDNode!\n");
-}
-
/// Clean up after incorporating a function. This is the only way to get out of
/// the function incorporation state that affects get*Slot/Create*Slot. Function
/// incorporation state is indicated by TheFunction != 0.
return MI == mMap.end() ? -1 : (int)MI->second;
}
-/// getGlobalSlot - Get the slot number of a MDNode.
+/// getMetadataSlot - Get the slot number of a MDNode.
int SlotTracker::getMetadataSlot(const MDNode *N) {
// Check for uninitialized state and do lazy initialization.
initialize();
// Find the type plane in the module map
- ValueMap::iterator MI = mdnMap.find(N);
+ mdn_iterator MI = mdnMap.find(N);
return MI == mdnMap.end() ? -1 : (int)MI->second;
}
void SlotTracker::CreateMetadataSlot(const MDNode *N) {
assert(N && "Can't insert a null Value into SlotTracker!");
- // Don't insert if N is a function-local metadata.
+ // Don't insert if N is a function-local metadata, these are always printed
+ // inline.
if (N->isFunctionLocal())
return;
- ValueMap::iterator I = mdnMap.find(N);
+ mdn_iterator I = mdnMap.find(N);
if (I != mdnMap.end())
return;
unsigned DestSlot = mdnNext++;
mdnMap[N] = DestSlot;
- for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
- const Value *TV = N->getOperand(i);
- if (TV)
- if (const MDNode *N2 = dyn_cast<MDNode>(TV))
- CreateMetadataSlot(N2);
- }
+ // Recursively add any MDNodes referenced by operands.
+ for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
+ if (const MDNode *Op = dyn_cast_or_null<MDNode>(N->getOperand(i)))
+ CreateMetadataSlot(Op);
}
//===----------------------------------------------------------------------===//
static const char *getPredicateText(unsigned predicate) {
const char * pred = "unknown";
switch (predicate) {
- case FCmpInst::FCMP_FALSE: pred = "false"; break;
- case FCmpInst::FCMP_OEQ: pred = "oeq"; break;
- case FCmpInst::FCMP_OGT: pred = "ogt"; break;
- case FCmpInst::FCMP_OGE: pred = "oge"; break;
- case FCmpInst::FCMP_OLT: pred = "olt"; break;
- case FCmpInst::FCMP_OLE: pred = "ole"; break;
- case FCmpInst::FCMP_ONE: pred = "one"; break;
- case FCmpInst::FCMP_ORD: pred = "ord"; break;
- case FCmpInst::FCMP_UNO: pred = "uno"; break;
- case FCmpInst::FCMP_UEQ: pred = "ueq"; break;
- case FCmpInst::FCMP_UGT: pred = "ugt"; break;
- case FCmpInst::FCMP_UGE: pred = "uge"; break;
- case FCmpInst::FCMP_ULT: pred = "ult"; break;
- case FCmpInst::FCMP_ULE: pred = "ule"; break;
- case FCmpInst::FCMP_UNE: pred = "une"; break;
- case FCmpInst::FCMP_TRUE: pred = "true"; break;
- case ICmpInst::ICMP_EQ: pred = "eq"; break;
- case ICmpInst::ICMP_NE: pred = "ne"; break;
- case ICmpInst::ICMP_SGT: pred = "sgt"; break;
- case ICmpInst::ICMP_SGE: pred = "sge"; break;
- case ICmpInst::ICMP_SLT: pred = "slt"; break;
- case ICmpInst::ICMP_SLE: pred = "sle"; break;
- case ICmpInst::ICMP_UGT: pred = "ugt"; break;
- case ICmpInst::ICMP_UGE: pred = "uge"; break;
- case ICmpInst::ICMP_ULT: pred = "ult"; break;
- case ICmpInst::ICMP_ULE: pred = "ule"; break;
+ case FCmpInst::FCMP_FALSE: pred = "false"; break;
+ case FCmpInst::FCMP_OEQ: pred = "oeq"; break;
+ case FCmpInst::FCMP_OGT: pred = "ogt"; break;
+ case FCmpInst::FCMP_OGE: pred = "oge"; break;
+ case FCmpInst::FCMP_OLT: pred = "olt"; break;
+ case FCmpInst::FCMP_OLE: pred = "ole"; break;
+ case FCmpInst::FCMP_ONE: pred = "one"; break;
+ case FCmpInst::FCMP_ORD: pred = "ord"; break;
+ case FCmpInst::FCMP_UNO: pred = "uno"; break;
+ case FCmpInst::FCMP_UEQ: pred = "ueq"; break;
+ case FCmpInst::FCMP_UGT: pred = "ugt"; break;
+ case FCmpInst::FCMP_UGE: pred = "uge"; break;
+ case FCmpInst::FCMP_ULT: pred = "ult"; break;
+ case FCmpInst::FCMP_ULE: pred = "ule"; break;
+ case FCmpInst::FCMP_UNE: pred = "une"; break;
+ case FCmpInst::FCMP_TRUE: pred = "true"; break;
+ case ICmpInst::ICMP_EQ: pred = "eq"; break;
+ case ICmpInst::ICMP_NE: pred = "ne"; break;
+ case ICmpInst::ICMP_SGT: pred = "sgt"; break;
+ case ICmpInst::ICMP_SGE: pred = "sge"; break;
+ case ICmpInst::ICMP_SLT: pred = "slt"; break;
+ case ICmpInst::ICMP_SLE: pred = "sle"; break;
+ case ICmpInst::ICMP_UGT: pred = "ugt"; break;
+ case ICmpInst::ICMP_UGE: pred = "uge"; break;
+ case ICmpInst::ICMP_ULT: pred = "ult"; break;
+ case ICmpInst::ICMP_ULE: pred = "ule"; break;
}
return pred;
}
-static void WriteMDNodeComment(const MDNode *Node,
- formatted_raw_ostream &Out) {
- if (Node->getNumOperands() < 1)
- return;
- ConstantInt *CI = dyn_cast_or_null<ConstantInt>(Node->getOperand(0));
- if (!CI) return;
- unsigned Val = CI->getZExtValue();
- unsigned Tag = Val & ~LLVMDebugVersionMask;
- if (Val < LLVMDebugVersion)
- return;
-
- Out.PadToColumn(50);
- if (Tag == dwarf::DW_TAG_auto_variable)
- Out << "; [ DW_TAG_auto_variable ]";
- else if (Tag == dwarf::DW_TAG_arg_variable)
- Out << "; [ DW_TAG_arg_variable ]";
- else if (Tag == dwarf::DW_TAG_return_variable)
- Out << "; [ DW_TAG_return_variable ]";
- else if (Tag == dwarf::DW_TAG_vector_type)
- Out << "; [ DW_TAG_vector_type ]";
- else if (Tag == dwarf::DW_TAG_user_base)
- Out << "; [ DW_TAG_user_base ]";
- else if (const char *TagName = dwarf::TagString(Tag))
- Out << "; [ " << TagName << " ]";
-}
-
-static void WriteMDNodes(formatted_raw_ostream &Out, TypePrinting &TypePrinter,
- SlotTracker &Machine) {
- SmallVector<const MDNode *, 16> Nodes;
- Nodes.resize(Machine.mdnSize());
- for (SlotTracker::ValueMap::iterator I =
- Machine.mdnBegin(), E = Machine.mdnEnd(); I != E; ++I)
- Nodes[I->second] = cast<MDNode>(I->first);
-
- for (unsigned i = 0, e = Nodes.size(); i != e; ++i) {
- Out << '!' << i << " = metadata ";
- const MDNode *Node = Nodes[i];
- Out << "!{";
- for (unsigned mi = 0, me = Node->getNumOperands(); mi != me; ++mi) {
- const Value *V = Node->getOperand(mi);
- if (!V)
- Out << "null";
- else if (const MDNode *N = dyn_cast<MDNode>(V)) {
- Out << "metadata ";
- Out << '!' << Machine.getMetadataSlot(N);
- }
- else {
- TypePrinter.print(V->getType(), Out);
- Out << ' ';
- WriteAsOperandInternal(Out, Node->getOperand(mi),
- &TypePrinter, &Machine);
- }
- if (mi + 1 != me)
- Out << ", ";
- }
-
- Out << "}";
- WriteMDNodeComment(Node, Out);
- Out << "\n";
- }
-}
static void WriteOptimizationInfo(raw_ostream &Out, const User *U) {
if (const OverflowingBinaryOperator *OBO =
static void WriteConstantInt(raw_ostream &Out, const Constant *CV,
TypePrinting &TypePrinter, SlotTracker *Machine) {
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
- if (CI->getType() == Type::getInt1Ty(CV->getContext())) {
+ if (CI->getType()->isInteger(1)) {
Out << (CI->getZExtValue() ? "true" : "false");
return;
}
bool isDouble = &CFP->getValueAPF().getSemantics()==&APFloat::IEEEdouble;
double Val = isDouble ? CFP->getValueAPF().convertToDouble() :
CFP->getValueAPF().convertToFloat();
- std::string StrVal = ftostr(CFP->getValueAPF());
+ SmallString<128> StrVal;
+ raw_svector_ostream(StrVal) << Val;
// Check to make sure that the stringized number is not some string like
// "Inf" or NaN, that atof will accept, but the lexer will not. Check
(StrVal[1] >= '0' && StrVal[1] <= '9'))) {
// Reparse stringized version!
if (atof(StrVal.c_str()) == Val) {
- Out << StrVal;
+ Out << StrVal.str();
return;
}
}
Out << "<placeholder or erroneous Constant>";
}
+static void WriteMDNodeBodyInternal(raw_ostream &Out, const MDNode *Node,
+ TypePrinting *TypePrinter,
+ SlotTracker *Machine) {
+ Out << "!{";
+ for (unsigned mi = 0, me = Node->getNumOperands(); mi != me; ++mi) {
+ const Value *V = Node->getOperand(mi);
+ if (V == 0)
+ Out << "null";
+ else {
+ TypePrinter->print(V->getType(), Out);
+ Out << ' ';
+ WriteAsOperandInternal(Out, Node->getOperand(mi),
+ TypePrinter, Machine);
+ }
+ if (mi + 1 != me)
+ Out << ", ";
+ }
+
+ Out << "}";
+}
+
/// WriteAsOperand - Write the name of the specified value out to the specified
/// ostream. This can be useful when you just want to print int %reg126, not
if (const MDNode *N = dyn_cast<MDNode>(V)) {
if (N->isFunctionLocal()) {
// Print metadata inline, not via slot reference number.
- Out << "!{";
- for (unsigned mi = 0, me = N->getNumOperands(); mi != me; ++mi) {
- const Value *Val = N->getOperand(mi);
- if (!Val)
- Out << "null";
- else {
- TypePrinter->print(N->getOperand(0)->getType(), Out);
- Out << ' ';
- WriteAsOperandInternal(Out, N->getOperand(0), TypePrinter, Machine);
- }
- if (mi + 1 != me)
- Out << ", ";
- }
- Out << '}';
+ WriteMDNodeBodyInternal(Out, N, TypePrinter, Machine);
return;
}
+ if (!Machine)
+ Machine = createSlotTracker(V);
Out << '!' << Machine->getMetadataSlot(N);
return;
}
AssemblyAnnotationWriter *AAW)
: Out(o), Machine(Mac), TheModule(M), AnnotationWriter(AAW) {
AddModuleTypesToPrinter(TypePrinter, NumberedTypes, M);
- // FIXME: Provide MDPrinter
if (M)
M->getMDKindNames(MDNames);
}
- void write(const Module *M) { printModule(M); }
-
- void write(const GlobalValue *G) {
- if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(G))
- printGlobal(GV);
- else if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(G))
- printAlias(GA);
- else if (const Function *F = dyn_cast<Function>(G))
- printFunction(F);
- else
- llvm_unreachable("Unknown global");
- }
-
- void write(const BasicBlock *BB) { printBasicBlock(BB); }
- void write(const Instruction *I) { printInstruction(*I); }
+ void printMDNodeBody(const MDNode *MD);
+ void printNamedMDNode(const NamedMDNode *NMD);
+
+ void printModule(const Module *M);
void writeOperand(const Value *Op, bool PrintType);
void writeParamOperand(const Value *Operand, Attributes Attrs);
-private:
- void printModule(const Module *M);
+ void writeAllMDNodes();
+
void printTypeSymbolTable(const TypeSymbolTable &ST);
void printGlobal(const GlobalVariable *GV);
void printAlias(const GlobalAlias *GV);
void printArgument(const Argument *FA, Attributes Attrs);
void printBasicBlock(const BasicBlock *BB);
void printInstruction(const Instruction &I);
+private:
// printInfoComment - Print a little comment after the instruction indicating
// which slot it occupies.
void AssemblyWriter::writeOperand(const Value *Operand, bool PrintType) {
if (Operand == 0) {
Out << "<null operand!>";
- } else {
- if (PrintType) {
- TypePrinter.print(Operand->getType(), Out);
- Out << ' ';
- }
- WriteAsOperandInternal(Out, Operand, &TypePrinter, &Machine);
+ return;
+ }
+ if (PrintType) {
+ TypePrinter.print(Operand->getType(), Out);
+ Out << ' ';
}
+ WriteAsOperandInternal(Out, Operand, &TypePrinter, &Machine);
}
void AssemblyWriter::writeParamOperand(const Value *Operand,
Attributes Attrs) {
if (Operand == 0) {
Out << "<null operand!>";
- } else {
- // Print the type
- TypePrinter.print(Operand->getType(), Out);
- // Print parameter attributes list
- if (Attrs != Attribute::None)
- Out << ' ' << Attribute::getAsString(Attrs);
- Out << ' ';
- // Print the operand
- WriteAsOperandInternal(Out, Operand, &TypePrinter, &Machine);
+ return;
}
+
+ // Print the type
+ TypePrinter.print(Operand->getType(), Out);
+ // Print parameter attributes list
+ if (Attrs != Attribute::None)
+ Out << ' ' << Attribute::getAsString(Attrs);
+ Out << ' ';
+ // Print the operand
+ WriteAsOperandInternal(Out, Operand, &TypePrinter, &Machine);
}
void AssemblyWriter::printModule(const Module *M) {
// Output named metadata.
if (!M->named_metadata_empty()) Out << '\n';
+
for (Module::const_named_metadata_iterator I = M->named_metadata_begin(),
- E = M->named_metadata_end(); I != E; ++I) {
- const NamedMDNode *NMD = I;
- Out << "!" << NMD->getName() << " = !{";
- for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
- if (i) Out << ", ";
- MDNode *MD = dyn_cast_or_null<MDNode>(NMD->getOperand(i));
- Out << '!' << Machine.getMetadataSlot(MD);
- }
- Out << "}\n";
- }
+ E = M->named_metadata_end(); I != E; ++I)
+ printNamedMDNode(I);
// Output metadata.
- if (!Machine.mdnEmpty()) Out << '\n';
- WriteMDNodes(Out, TypePrinter, Machine);
+ if (!Machine.mdn_empty()) {
+ Out << '\n';
+ writeAllMDNodes();
+ }
+}
+
+void AssemblyWriter::printNamedMDNode(const NamedMDNode *NMD) {
+ Out << "!" << NMD->getName() << " = !{";
+ for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
+ if (i) Out << ", ";
+ if (MDNode *MD = NMD->getOperand(i))
+ Out << '!' << Machine.getMetadataSlot(MD);
+ else
+ Out << "null";
+ }
+ Out << "}\n";
}
+
static void PrintLinkage(GlobalValue::LinkageTypes LT,
formatted_raw_ostream &Out) {
switch (LT) {
case GlobalValue::AvailableExternallyLinkage:
Out << "available_externally ";
break;
- // This is invalid syntax and just a debugging aid.
- case GlobalValue::GhostLinkage: Out << "ghost "; break;
}
}
}
void AssemblyWriter::printGlobal(const GlobalVariable *GV) {
+ if (GV->isMaterializable())
+ Out << "; Materializable\n";
+
WriteAsOperandInternal(Out, GV, &TypePrinter, &Machine);
Out << " = ";
}
void AssemblyWriter::printAlias(const GlobalAlias *GA) {
+ if (GA->isMaterializable())
+ Out << "; Materializable\n";
+
// Don't crash when dumping partially built GA
if (!GA->hasName())
Out << "<<nameless>> = ";
if (AnnotationWriter) AnnotationWriter->emitFunctionAnnot(F, Out);
+ if (F->isMaterializable())
+ Out << "; Materializable\n";
+
if (F->isDeclaration())
Out << "declare ";
else
printInfoComment(I);
}
+static void WriteMDNodeComment(const MDNode *Node,
+ formatted_raw_ostream &Out) {
+ if (Node->getNumOperands() < 1)
+ return;
+ ConstantInt *CI = dyn_cast_or_null<ConstantInt>(Node->getOperand(0));
+ if (!CI) return;
+ unsigned Val = CI->getZExtValue();
+ unsigned Tag = Val & ~LLVMDebugVersionMask;
+ if (Val < LLVMDebugVersion)
+ return;
+
+ Out.PadToColumn(50);
+ if (Tag == dwarf::DW_TAG_auto_variable)
+ Out << "; [ DW_TAG_auto_variable ]";
+ else if (Tag == dwarf::DW_TAG_arg_variable)
+ Out << "; [ DW_TAG_arg_variable ]";
+ else if (Tag == dwarf::DW_TAG_return_variable)
+ Out << "; [ DW_TAG_return_variable ]";
+ else if (Tag == dwarf::DW_TAG_vector_type)
+ Out << "; [ DW_TAG_vector_type ]";
+ else if (Tag == dwarf::DW_TAG_user_base)
+ Out << "; [ DW_TAG_user_base ]";
+ else if (const char *TagName = dwarf::TagString(Tag))
+ Out << "; [ " << TagName << " ]";
+}
+
+void AssemblyWriter::writeAllMDNodes() {
+ SmallVector<const MDNode *, 16> Nodes;
+ Nodes.resize(Machine.mdn_size());
+ for (SlotTracker::mdn_iterator I = Machine.mdn_begin(), E = Machine.mdn_end();
+ I != E; ++I)
+ Nodes[I->second] = cast<MDNode>(I->first);
+
+ for (unsigned i = 0, e = Nodes.size(); i != e; ++i) {
+ Out << '!' << i << " = metadata ";
+ printMDNodeBody(Nodes[i]);
+ }
+}
+
+void AssemblyWriter::printMDNodeBody(const MDNode *Node) {
+ WriteMDNodeBodyInternal(Out, Node, &TypePrinter, &Machine);
+ WriteMDNodeComment(Node, Out);
+ Out << "\n";
+}
//===----------------------------------------------------------------------===//
// External Interface declarations
SlotTracker SlotTable(this);
formatted_raw_ostream OS(ROS);
AssemblyWriter W(OS, SlotTable, this, AAW);
- W.write(this);
+ W.printModule(this);
}
void Type::print(raw_ostream &OS) const {
if (const Instruction *I = dyn_cast<Instruction>(this)) {
const Function *F = I->getParent() ? I->getParent()->getParent() : 0;
SlotTracker SlotTable(F);
- AssemblyWriter W(OS, SlotTable, F ? F->getParent() : 0, AAW);
- W.write(I);
+ AssemblyWriter W(OS, SlotTable, getModuleFromVal(I), AAW);
+ W.printInstruction(*I);
} else if (const BasicBlock *BB = dyn_cast<BasicBlock>(this)) {
SlotTracker SlotTable(BB->getParent());
- AssemblyWriter W(OS, SlotTable,
- BB->getParent() ? BB->getParent()->getParent() : 0, AAW);
- W.write(BB);
+ AssemblyWriter W(OS, SlotTable, getModuleFromVal(BB), AAW);
+ W.printBasicBlock(BB);
} else if (const GlobalValue *GV = dyn_cast<GlobalValue>(this)) {
SlotTracker SlotTable(GV->getParent());
AssemblyWriter W(OS, SlotTable, GV->getParent(), AAW);
- W.write(GV);
+ if (const GlobalVariable *V = dyn_cast<GlobalVariable>(GV))
+ W.printGlobal(V);
+ else if (const Function *F = dyn_cast<Function>(GV))
+ W.printFunction(F);
+ else
+ W.printAlias(cast<GlobalAlias>(GV));
} else if (const MDNode *N = dyn_cast<MDNode>(this)) {
- SlotTracker SlotTable(N);
- TypePrinting TypePrinter;
- SlotTable.initialize();
- WriteMDNodes(OS, TypePrinter, SlotTable);
+ const Function *F = N->getFunction();
+ SlotTracker SlotTable(F);
+ AssemblyWriter W(OS, SlotTable, F ? getModuleFromVal(F) : 0, AAW);
+ W.printMDNodeBody(N);
} else if (const NamedMDNode *N = dyn_cast<NamedMDNode>(this)) {
SlotTracker SlotTable(N->getParent());
- TypePrinting TypePrinter;
- SlotTable.initialize();
- OS << "!" << N->getName() << " = !{";
- for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
- if (i) OS << ", ";
- MDNode *MD = dyn_cast_or_null<MDNode>(N->getOperand(i));
- if (MD)
- OS << '!' << SlotTable.getMetadataSlot(MD);
- else
- OS << "null";
- }
- OS << "}\n";
- WriteMDNodes(OS, TypePrinter, SlotTable);
+ AssemblyWriter W(OS, SlotTable, N->getParent(), AAW);
+ W.printNamedMDNode(N);
} else if (const Constant *C = dyn_cast<Constant>(this)) {
TypePrinting TypePrinter;
TypePrinter.print(C->getType(), OS);
}
// Value::dump - allow easy printing of Values from the debugger.
-void Value::dump() const { print(errs()); errs() << '\n'; }
+void Value::dump() const { print(dbgs()); dbgs() << '\n'; }
// Type::dump - allow easy printing of Types from the debugger.
// This one uses type names from the given context module
void Type::dump(const Module *Context) const {
- WriteTypeSymbolic(errs(), this, Context);
- errs() << '\n';
+ WriteTypeSymbolic(dbgs(), this, Context);
+ dbgs() << '\n';
}
// Type::dump - allow easy printing of Types from the debugger.
void Type::dump() const { dump(0); }
// Module::dump() - Allow printing of Modules from the debugger.
-void Module::dump() const { print(errs(), 0); }
+void Module::dump() const { print(dbgs(), 0); }