SpecialCaseList: Add support for parsing multiple input files.
[oota-llvm.git] / lib / IR / DebugInfo.cpp
index 76836fd95517870f27aeef1c65d132fc68ae19dc..88f7e33b7dc1b302e2c360295d86b09873f65e47 100644 (file)
@@ -162,6 +162,19 @@ uint64_t DIExpression::getPieceSize() const {
   return getElement(getNumElements()-1);
 }
 
+DIExpression::iterator DIExpression::begin() const {
+ return DIExpression::iterator(*this);
+}
+
+DIExpression::iterator DIExpression::end() const {
+ return DIExpression::iterator();
+}
+
+DIExpression::Operand DIExpression::Operand::getNext() const {
+  iterator it(I);
+  return *(++it);
+}
+
 //===----------------------------------------------------------------------===//
 // Predicates
 //===----------------------------------------------------------------------===//
@@ -595,25 +608,25 @@ bool DIExpression::Verify() const {
   if (!DbgNode)
     return true;
 
-  unsigned N = getNumElements();
-  for (unsigned I = 0; I < N; ++I)
-    switch (getElement(I)) {
+  if (!(isExpression() && DbgNode->getNumOperands() == 1))
+    return false;
+
+  for (auto Op : *this)
+    switch (Op) {
     case DW_OP_piece:
-      // DW_OP_piece has to be the last element in the expression and take two
-      // arguments.
-      if (getElement(I) == DW_OP_piece && !isVariablePiece())
-        return false;
-      I += 2;
-      break;
+      // Must be the last element of the expression.
+      return std::distance(Op.getBase(), DIHeaderFieldIterator()) == 3;
     case DW_OP_plus:
-      // Takes one argument.
-      if (I+1 == N)
+      if (std::distance(Op.getBase(), DIHeaderFieldIterator()) < 2)
         return false;
-      I += 1;
       break;
-    default: break;
-  }
-  return isExpression() && DbgNode->getNumOperands() == 1;
+    case DW_OP_deref:
+      break;
+    default:
+      // Other operators are not yet supported by the backend.
+      return false;
+    }
+  return true;
 }
 
 bool DILocation::Verify() const {
@@ -1398,27 +1411,22 @@ void DIVariable::printInternal(raw_ostream &OS) const {
 }
 
 void DIExpression::printInternal(raw_ostream &OS) const {
-  for (unsigned I = 0; I < getNumElements(); ++I) {
-    uint64_t OpCode = getElement(I);
-    OS << " [" << OperationEncodingString(OpCode);
-    switch (OpCode) {
+  for (auto Op : *this) {
+    OS << " [" << OperationEncodingString(Op);
+    switch (Op) {
     case DW_OP_plus: {
-      OS << " " << getElement(++I);
+      OS << " " << Op.getArg(1);
       break;
     }
     case DW_OP_piece: {
-      unsigned Offset = getElement(++I);
-      unsigned Size = getElement(++I);
-      OS << " offset=" << Offset << ", size=" << Size;
+      OS << " offset=" << Op.getArg(1) << ", size=" << Op.getArg(2);
       break;
     }
     case DW_OP_deref:
       // No arguments.
       break;
     default:
-      // Else bail out early. This may be a line table entry.
-      OS << "Unknown]";
-      return;
+      llvm_unreachable("unhandled operation");
     }
     OS << "]";
   }