* Narrow AsmWriter interface
authorChris Lattner <sabre@nondot.org>
Mon, 8 Apr 2002 22:03:40 +0000 (22:03 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 8 Apr 2002 22:03:40 +0000 (22:03 +0000)
* 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

lib/VMCore/AsmWriter.cpp

index 0af79bea5688d45edce3f0f928005a4ef2c1ec3d..e5f9114c8e1f7ece9b26ecf80cafb8393635ff0c 100644 (file)
@@ -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<const FunctionArgument>(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 << "<null> 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 << "<null> 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 << "<null> 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 << "<null> 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 << "<null> constant value\n"; return; }
+  o << " " << getType()->getDescription() << " " << getStrValue();
 }
 
-void WriteToAssembly(const Constant *CPV, ostream &o) {
-  if (CPV == 0) { o << "<null> constant pool value\n"; return; }
-  o << " " << CPV->getType()->getDescription() << " " << CPV->getStrValue();
+void Type::print(std::ostream &o) const { 
+  if (this == 0)
+    o << "<null Type>";
+  else
+    o << getDescription();
 }
 
-void WriteToAssembly(const Instruction *I, ostream &o) {
-  if (I == 0) { o << "<null> 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;