Make the asmwriter much more tolerant of errors (which are common when working
authorChris Lattner <sabre@nondot.org>
Wed, 9 Jun 2004 19:41:19 +0000 (19:41 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 9 Jun 2004 19:41:19 +0000 (19:41 +0000)
on new front-ends and stuff).  Also get rid of some tabs that snuck in.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14100 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/AsmWriter.cpp

index 24c33489a8eca8e8a2947863c4eaa6a950395637..72caa80b5b337f67f55c368072ebd83959b9c701 100644 (file)
@@ -74,7 +74,7 @@ public:
   /// Return the slot number of the specified value in it's type
   /// plane.  Its an error to ask for something not in the SlotMachine.
   /// Its an error to ask for a Type*
-  unsigned getSlot(const Value *V, bool ignoreMissing = false ) ;
+  int getSlot(const Value *V);
 
   /// Determine if a Value has a slot or not
   bool hasSlot(const Value* V);
@@ -525,12 +525,16 @@ static void WriteAsOperandInternal(std::ostream &Out, const Value *V,
         }
 
         Machine = createSlotMachine(V);
-        if (Machine == 0) { Out << "BAD VALUE TYPE!"; return; }
-
-        Slot = Machine->getSlot(V);
+        if (Machine == 0) 
+          Slot = Machine->getSlot(V);
+        else
+          Slot = -1;
         delete Machine;
       }
-      Out << '%' << Slot;
+      if (Slot != -1)
+        Out << '%' << Slot;
+      else
+        Out << "<badref>";
     }
   }
 }
@@ -841,7 +845,12 @@ void AssemblyWriter::printBasicBlock(const BasicBlock *BB) {
   if (BB->hasName()) {              // Print out the label if it exists...
     *Out << "\n" << BB->getName() << ':';
   } else if (!BB->use_empty()) {      // Don't print block # of no uses...
-    *Out << "\n; <label>:" << Machine.getSlot(BB);
+    *Out << "\n; <label>:";
+    int Slot = Machine.getSlot(BB);
+    if (Slot != -1)
+      *Out << Slot;
+    else
+      *Out << "<badref>";
   }
 
   if (BB->getParent() == 0)
@@ -886,11 +895,11 @@ void AssemblyWriter::printInfoComment(const Value &V) {
     printType(V.getType()) << '>';
 
     if (!V.hasName()) {
-      unsigned SlotNum = Machine.getSlot(&V,true);
-      if ( unsigned(-1) == SlotNum )
-       *Out << ":??";
+      int SlotNum = Machine.getSlot(&V);
+      if (SlotNum == -1)
+        *Out << ":<badref>";
       else
-       *Out << ':' << SlotNum; // Print out the def slot taken.
+        *Out << ':' << SlotNum; // Print out the def slot taken.
     }
     *Out << " [#uses=" << V.use_size() << ']';  // Output # uses
   }
@@ -1273,7 +1282,7 @@ void SlotMachine::purgeFunction() {
 /// Get the slot number for a value. This function will assert if you
 /// ask for a Value that hasn't previously been inserted with createSlot.
 /// Types are forbidden because Type does not inherit from Value (any more).
-unsigned SlotMachine::getSlot(const Value *V, bool ignoreMissing ) {
+int SlotMachine::getSlot(const Value *V) {
   assert( V && "Can't get slot for null Value" );
   assert( !isa<Type>(V) && "Can't get slot for a type" );
   assert(!isa<Constant>(V) || isa<GlobalValue>(V) && 
@@ -1304,7 +1313,7 @@ unsigned SlotMachine::getSlot(const Value *V, bool ignoreMissing ) {
         // Look up the value in the module map
         ValueMap::const_iterator MVI = MI->second.map.find(V);
         // If we didn't find it, it wasn't inserted
-       if ( ignoreMissing && MVI == MI->second.map.end()) return unsigned(-1);
+        if (MVI == MI->second.map.end()) return -1;
         assert( MVI != MI->second.map.end() && "Value not found");
         // We found it only at the module level
         return MVI->second; 
@@ -1323,13 +1332,11 @@ unsigned SlotMachine::getSlot(const Value *V, bool ignoreMissing ) {
   // have a corresponding type plane for the Value
 
   // Make sure the type plane exists
-  if ( ignoreMissing && MI == mMap.end()) return unsigned(-1);
-  assert( MI != mMap.end() && "No such type plane!" );
+  if (MI == mMap.end()) return -1;
   // Lookup the value in the module's map
   ValueMap::const_iterator MVI = MI->second.map.find(V);
   // Make sure we found it.
-  if ( ignoreMissing && MVI == MI->second.map.end()) return unsigned(-1);
-  assert( MVI != MI->second.map.end() && "Value not found" );
+  if (MVI == MI->second.map.end()) return -1;
   // Return it.
   return MVI->second;
 }