Check that we don't have external varaibles with internal linkage
[oota-llvm.git] / lib / VMCore / AsmWriter.cpp
index c1af5e4c8567b98cf6a504062140abfe1821a5e3..8c7b06ba0f17f264409a724303051e88e1dc959f 100644 (file)
@@ -21,6 +21,7 @@
 #include "llvm/iPHINode.h"
 #include "llvm/iOther.h"
 #include "llvm/SymbolTable.h"
+#include "llvm/Support/CFG.h"
 #include "Support/StringExtras.h"
 #include "Support/STLExtras.h"
 #include <algorithm>
@@ -271,7 +272,7 @@ static void WriteConstantInt(ostream &Out, const Constant *CV, bool PrintName,
           (unsigned char)cast<ConstantSInt>(CA->getOperand(i))->getValue() :
           (unsigned char)cast<ConstantUInt>(CA->getOperand(i))->getValue();
         
-        if (isprint(C) && C != '"') {
+        if (isprint(C) && C != '"' && C != '\\') {
           Out << C;
         } else {
           Out << '\\'
@@ -333,21 +334,25 @@ static void WriteConstantInt(ostream &Out, const Constant *CV, bool PrintName,
       Out << "<pointer reference without context info>";
     }
 
-  } else if (const ConstantExpr *CE=dyn_cast<ConstantExpr>(CV)) {
+  } else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
     Out << CE->getOpcodeName();
 
     bool isGEP = CE->getOpcode() == Instruction::GetElementPtr;
-    Out << (isGEP? " (" : " ");
+    Out << " (";
     
     for (User::const_op_iterator OI=CE->op_begin(); OI != CE->op_end(); ++OI) {
       printTypeInt(Out, (*OI)->getType(), TypeTable);
       WriteAsOperandInternal(Out, *OI, PrintName, TypeTable, Table);
       if (OI+1 != CE->op_end())
-        Out << ", ";    // ((isGEP && OI == CE->op_begin())? " " : ", ");
+        Out << ", ";
     }
     
-    if (isGEP)
-      Out << ")";
+    if (CE->getOpcode() == Instruction::Cast) {
+      Out << " to ";
+      printTypeInt(Out, CE->getType(), TypeTable);
+    }
+    Out << ")";
+
   } else {
     Out << "<placeholder or erroneous Constant>";
   }
@@ -657,8 +662,7 @@ void AssemblyWriter::printArgument(const Argument *Arg) {
 //
 void AssemblyWriter::printBasicBlock(const BasicBlock *BB) {
   if (BB->hasName()) {              // Print out the label if it exists...
-    Out << "\n" << BB->getName() << ":\t\t\t\t\t;[#uses="
-        << BB->use_size() << "]";  // Output # uses
+    Out << "\n" << BB->getName() << ":";
   } else if (!BB->use_empty()) {      // Don't print block # of no uses...
     int Slot = Table.getValSlot(BB);
     Out << "\n; <label>:";
@@ -666,7 +670,21 @@ void AssemblyWriter::printBasicBlock(const BasicBlock *BB) {
       Out << Slot;         // Extra newline seperates out label's
     else 
       Out << "<badref>"; 
-    Out << "\t\t\t\t\t;[#uses=" << BB->use_size() << "]";  // Output # uses
+  }
+  
+  // Output predecessors for the block...
+  Out << "\t\t;";
+  pred_const_iterator PI = pred_begin(BB), PE = pred_end(BB);
+
+  if (PI == PE) {
+    Out << " No predecessors!";
+  } else {
+    Out << " preds =";
+    writeOperand(*PI, false, true);
+    for (++PI; PI != PE; ++PI) {
+      Out << ",";
+      writeOperand(*PI, false, true);
+    }
   }
   
   Out << "\n";
@@ -868,6 +886,13 @@ void Instruction::print(std::ostream &o) const {
 
 void Constant::print(std::ostream &o) const {
   if (this == 0) { o << "<null> constant value\n"; return; }
+
+  // Handle CPR's special, because they have context information...
+  if (const ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(this)) {
+    CPR->getValue()->print(o);  // Print as a global value, with context info.
+    return;
+  }
+
   o << " " << getType()->getDescription() << " ";
 
   map<const Type *, string> TypeTable;