ELFObjectWriter.cpp: Prune obsolete \param since r234342. [-Wdocumentation]
[oota-llvm.git] / lib / Analysis / ModuleDebugInfoPrinter.cpp
index f8c751481976f2a560ba21bc5636af17b875b7e4..38007bbcd3f3b8b35ee6b2745210398ddf1c57e5 100644 (file)
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Analysis/Passes.h"
-#include "llvm/Assembly/Writer.h"
-#include "llvm/DebugInfo.h"
-#include "llvm/Function.h"
+#include "llvm/ADT/Statistic.h"
+#include "llvm/IR/DebugInfo.h"
+#include "llvm/IR/Function.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"
-#include "llvm/ADT/Statistic.h"
 using namespace llvm;
 
 namespace {
@@ -34,12 +33,12 @@ namespace {
       initializeModuleDebugInfoPrinterPass(*PassRegistry::getPassRegistry());
     }
 
-    virtual bool runOnModule(Module &M);
+    bool runOnModule(Module &M) override;
 
-    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+    void getAnalysisUsage(AnalysisUsage &AU) const override {
       AU.setPreservesAll();
     }
-    virtual void print(raw_ostream &O, const Module *M) const;
+    void print(raw_ostream &O, const Module *M) const override;
   };
 }
 
@@ -56,32 +55,72 @@ bool ModuleDebugInfoPrinter::runOnModule(Module &M) {
   return false;
 }
 
+static void printFile(raw_ostream &O, StringRef Filename, StringRef Directory,
+                      unsigned Line = 0) {
+  if (Filename.empty())
+    return;
+
+  O << " from ";
+  if (!Directory.empty())
+    O << Directory << "/";
+  O << Filename;
+  if (Line)
+    O << ":" << Line;
+}
+
 void ModuleDebugInfoPrinter::print(raw_ostream &O, const Module *M) const {
-  for (DebugInfoFinder::iterator I = Finder.compile_unit_begin(),
-       E = Finder.compile_unit_end(); I != E; ++I) {
-    O << "Compile Unit: ";
-    DICompileUnit(*I).print(O);
+  // Printing the nodes directly isn't particularly helpful (since they
+  // reference other nodes that won't be printed, particularly for the
+  // filenames), so just print a few useful things.
+  for (DICompileUnit CU : Finder.compile_units()) {
+    O << "Compile unit: ";
+    if (const char *Lang = LanguageString(CU.getLanguage()))
+      O << Lang;
+    else
+      O << "unknown-language(" << CU.getLanguage() << ")";
+    printFile(O, CU.getFilename(), CU.getDirectory());
     O << '\n';
   }
 
-  for (DebugInfoFinder::iterator I = Finder.subprogram_begin(),
-       E = Finder.subprogram_end(); I != E; ++I) {
-    O << "Subprogram: ";
-    DISubprogram(*I).print(O);
+  for (DISubprogram S : Finder.subprograms()) {
+    O << "Subprogram: " << S.getName();
+    printFile(O, S.getFilename(), S.getDirectory(), S.getLineNumber());
+    if (!S.getLinkageName().empty())
+      O << " ('" << S.getLinkageName() << "')";
     O << '\n';
   }
 
-  for (DebugInfoFinder::iterator I = Finder.global_variable_begin(),
-       E = Finder.global_variable_end(); I != E; ++I) {
-    O << "GlobalVariable: ";
-    DIGlobalVariable(*I).print(O);
+  for (DIGlobalVariable GV : Finder.global_variables()) {
+    O << "Global variable: " << GV.getName();
+    printFile(O, GV.getFilename(), GV.getDirectory(), GV.getLineNumber());
+    if (!GV.getLinkageName().empty())
+      O << " ('" << GV.getLinkageName() << "')";
     O << '\n';
   }
 
-  for (DebugInfoFinder::iterator I = Finder.type_begin(),
-       E = Finder.type_end(); I != E; ++I) {
-    O << "Type: ";
-    DIType(*I).print(O);
+  for (DIType T : Finder.types()) {
+    O << "Type:";
+    if (!T.getName().empty())
+      O << ' ' << T.getName();
+    printFile(O, T.getFilename(), T.getDirectory(), T.getLineNumber());
+    if (DIBasicType BT = dyn_cast<MDBasicType>(T)) {
+      O << " ";
+      if (const char *Encoding =
+              dwarf::AttributeEncodingString(BT.getEncoding()))
+        O << Encoding;
+      else
+        O << "unknown-encoding(" << BT.getEncoding() << ')';
+    } else {
+      O << ' ';
+      if (const char *Tag = dwarf::TagString(T.getTag()))
+        O << Tag;
+      else
+        O << "unknown-tag(" << T.getTag() << ")";
+    }
+    if (DICompositeType CT = dyn_cast<MDCompositeType>(T)) {
+      if (auto *S = CT.getIdentifier())
+        O << " (identifier: '" << S->getString() << "')";
+    }
     O << '\n';
   }
 }