From: Chris Lattner Date: Mon, 8 Apr 2002 22:03:40 +0000 (+0000) Subject: * Narrow AsmWriter interface X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=75cf7cf00d391ac6ca22d6240fa9d99ed427d1d5;p=oota-llvm.git * Narrow AsmWriter interface * Implement Value::print methods here instead of WriteToAssembly git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2179 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index 0af79bea568..e5f9114c8e1 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Assembly/CachedWriter.h" +#include "llvm/Assembly/Writer.h" #include "llvm/SlotCalculator.h" #include "llvm/Module.h" #include "llvm/Function.h" @@ -28,10 +29,6 @@ using std::map; using std::vector; using std::ostream; -void Value::dump() const { - std::cerr << this; -} - static const Module *getModuleFromVal(const Value *V) { if (const FunctionArgument *MA = dyn_cast(V)) return MA->getParent() ? MA->getParent()->getParent() : 0; @@ -636,55 +633,61 @@ ostream &AssemblyWriter::printType(const Type *Ty) { //===----------------------------------------------------------------------===// - -void WriteToAssembly(const Module *M, ostream &o) { - if (M == 0) { o << " module\n"; return; } - SlotCalculator SlotTable(M, true); - AssemblyWriter W(o, SlotTable, M); - - W.write(M); +void Module::print(std::ostream &o) const { + SlotCalculator SlotTable(this, true); + AssemblyWriter W(o, SlotTable, this); + W.write(this); } -void WriteToAssembly(const GlobalVariable *G, ostream &o) { - if (G == 0) { o << " global variable\n"; return; } - SlotCalculator SlotTable(G->getParent(), true); - AssemblyWriter W(o, SlotTable, G->getParent()); - W.write(G); +void GlobalVariable::print(std::ostream &o) const { + SlotCalculator SlotTable(getParent(), true); + AssemblyWriter W(o, SlotTable, getParent()); + W.write(this); } -void WriteToAssembly(const Function *F, ostream &o) { - if (F == 0) { o << " function\n"; return; } - SlotCalculator SlotTable(F->getParent(), true); - AssemblyWriter W(o, SlotTable, F->getParent()); +void Function::print(std::ostream &o) const { + SlotCalculator SlotTable(getParent(), true); + AssemblyWriter W(o, SlotTable, getParent()); - W.write(F); + W.write(this); } +void BasicBlock::print(std::ostream &o) const { + SlotCalculator SlotTable(getParent(), true); + AssemblyWriter W(o, SlotTable, + getParent() ? getParent()->getParent() : 0); + W.write(this); +} -void WriteToAssembly(const BasicBlock *BB, ostream &o) { - if (BB == 0) { o << " basic block\n"; return; } +void Instruction::print(std::ostream &o) const { + const Function *F = getParent() ? getParent()->getParent() : 0; + SlotCalculator SlotTable(F, true); + AssemblyWriter W(o, SlotTable, F ? F->getParent() : 0); - SlotCalculator SlotTable(BB->getParent(), true); - AssemblyWriter W(o, SlotTable, - BB->getParent() ? BB->getParent()->getParent() : 0); + W.write(this); +} - W.write(BB); +void Constant::print(std::ostream &o) const { + if (this == 0) { o << " constant value\n"; return; } + o << " " << getType()->getDescription() << " " << getStrValue(); } -void WriteToAssembly(const Constant *CPV, ostream &o) { - if (CPV == 0) { o << " constant pool value\n"; return; } - o << " " << CPV->getType()->getDescription() << " " << CPV->getStrValue(); +void Type::print(std::ostream &o) const { + if (this == 0) + o << ""; + else + o << getDescription(); } -void WriteToAssembly(const Instruction *I, ostream &o) { - if (I == 0) { o << " instruction\n"; return; } +void FunctionArgument::print(std::ostream &o) const { + o << getType() << " " << getName(); +} - const Function *F = I->getParent() ? I->getParent()->getParent() : 0; - SlotCalculator SlotTable(F, true); - AssemblyWriter W(o, SlotTable, F ? F->getParent() : 0); +void Value::dump() const { print(std::cerr); } - W.write(I); -} +//===----------------------------------------------------------------------===// +// CachedWriter Class Implementation +//===----------------------------------------------------------------------===// void CachedWriter::setModule(const Module *M) { delete SC; delete AW;