Added debugging support.
authorVikram S. Adve <vadve@cs.uiuc.edu>
Tue, 18 Sep 2001 12:44:41 +0000 (12:44 +0000)
committerVikram S. Adve <vadve@cs.uiuc.edu>
Tue, 18 Sep 2001 12:44:41 +0000 (12:44 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@605 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/Value.cpp

index a41262d0c64caa3ff0077bab7e88d9a107cc70ea..723a71cd195cc852c639b5c516be867029d3c9c1 100644 (file)
@@ -83,6 +83,44 @@ User *Value::use_remove(use_iterator &I) {
   return i;
 }
 
+void
+Value::dump() const
+{
+  DebugValue(*this);
+}
+
+ostream&
+operator<<(ostream &o, const Value& I)
+{
+  switch (I.getValueType()) {
+  case Value::TypeVal:       return o << I.castTypeAsserting();
+  case Value::ConstantVal:   WriteToAssembly((const ConstPoolVal*)&I,o);break;
+  case Value::MethodArgumentVal: return o << I.getType() << " "<< I.getName();
+  case Value::InstructionVal:WriteToAssembly((const Instruction *)&I, o);break;
+  case Value::BasicBlockVal: WriteToAssembly((const BasicBlock  *)&I, o);break;
+  case Value::MethodVal:     WriteToAssembly((const Method      *)&I, o);break;
+  case Value::GlobalVal:     WriteToAssembly((const GlobalVariable*)&I,o);break;
+  case Value::ModuleVal:     WriteToAssembly((const Module      *)&I,o); break;
+  default: return o << "<unknown value type: " << I.getValueType() << ">";
+  }
+  return o;
+}
+
+void
+DebugValue(const Value* V)
+{
+  if (V)
+    cerr << *V << endl;
+  else
+    cerr << "<NULL value>" << endl;
+}
+
+void
+DebugValue(const Value& V)
+{
+  cerr << V << endl;
+}
+
 
 //===----------------------------------------------------------------------===//
 //                                 User Class