Fix batch of converting RegisterPass<> to INTIALIZE_PASS().
[oota-llvm.git] / lib / Analysis / ModuleDebugInfoPrinter.cpp
1 //===-- ModuleDebugInfoPrinter.cpp - Prints module debug info metadata ----===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This pass decodes the debug info metadata in a module and prints in a
11 // (sufficiently-prepared-) human-readable form.
12 //
13 // For example, run this pass from opt along with the -analyze option, and
14 // it'll print to standard output.
15 //
16 //===----------------------------------------------------------------------===//
17
18 #include "llvm/Analysis/Passes.h"
19 #include "llvm/Analysis/DebugInfo.h"
20 #include "llvm/Assembly/Writer.h"
21 #include "llvm/Pass.h"
22 #include "llvm/Function.h"
23 #include "llvm/Support/ErrorHandling.h"
24 #include "llvm/Support/raw_ostream.h"
25 #include "llvm/ADT/Statistic.h"
26 using namespace llvm;
27
28 namespace {
29   class ModuleDebugInfoPrinter : public ModulePass {
30     DebugInfoFinder Finder;
31   public:
32     static char ID; // Pass identification, replacement for typeid
33     ModuleDebugInfoPrinter() : ModulePass(&ID) {}
34
35     virtual bool runOnModule(Module &M);
36
37     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
38       AU.setPreservesAll();
39     }
40     virtual void print(raw_ostream &O, const Module *M) const;
41   };
42 }
43
44 char ModuleDebugInfoPrinter::ID = 0;
45 INITIALIZE_PASS(ModuleDebugInfoPrinter, "module-debuginfo",
46                 "Decodes module-level debug info", false, true);
47
48 ModulePass *llvm::createModuleDebugInfoPrinterPass() {
49   return new ModuleDebugInfoPrinter();
50 }
51
52 bool ModuleDebugInfoPrinter::runOnModule(Module &M) {
53   Finder.processModule(M);
54   return false;
55 }
56
57 void ModuleDebugInfoPrinter::print(raw_ostream &O, const Module *M) const {
58   for (DebugInfoFinder::iterator I = Finder.compile_unit_begin(),
59        E = Finder.compile_unit_end(); I != E; ++I) {
60     O << "Compile Unit: ";
61     DICompileUnit(*I).print(O);
62     O << '\n';
63   }
64
65   for (DebugInfoFinder::iterator I = Finder.subprogram_begin(),
66        E = Finder.subprogram_end(); I != E; ++I) {
67     O << "Subprogram: ";
68     DISubprogram(*I).print(O);
69     O << '\n';
70   }
71
72   for (DebugInfoFinder::iterator I = Finder.global_variable_begin(),
73        E = Finder.global_variable_end(); I != E; ++I) {
74     O << "GlobalVariable: ";
75     DIGlobalVariable(*I).print(O);
76     O << '\n';
77   }
78
79   for (DebugInfoFinder::iterator I = Finder.type_begin(),
80        E = Finder.type_end(); I != E; ++I) {
81     O << "Type: ";
82     DIType(*I).print(O);
83     O << '\n';
84   }
85 }