simplify by using CallSite constructors; virtually eliminates CallSite::get from...
[oota-llvm.git] / tools / opt / GraphPrinters.cpp
index 31515c89931633d13937ffe29f4298eb2e539c02..e7c6d1e6af8579fadf56656d1a860ccddd838d16 100644 (file)
 #include "llvm/Value.h"
 #include "llvm/Analysis/CallGraph.h"
 #include "llvm/Analysis/Dominators.h"
-#include <iostream>
-#include <fstream>
+#include "llvm/Support/raw_ostream.h"
 using namespace llvm;
 
 template<typename GraphType>
-static void WriteGraphToFile(std::ostream &O, const std::string &GraphName,
+static void WriteGraphToFile(raw_ostream &O, const std::string &GraphName,
                              const GraphType &GT) {
   std::string Filename = GraphName + ".dot";
   O << "Writing '" << Filename << "'...";
-  std::ofstream F(Filename.c_str());
+  std::string ErrInfo;
+  raw_fd_ostream F(Filename.c_str(), ErrInfo);
 
-  if (F.good())
+  if (ErrInfo.empty())
     WriteGraph(F, GT);
   else
     O << "  error opening file for writing!";
@@ -45,6 +45,9 @@ static void WriteGraphToFile(std::ostream &O, const std::string &GraphName,
 namespace llvm {
   template<>
   struct DOTGraphTraits<CallGraph*> : public DefaultDOTGraphTraits {
+
+  DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple) {}
+
     static std::string getGraphName(CallGraph *F) {
       return "Call Graph";
     }
@@ -53,7 +56,7 @@ namespace llvm {
       if (Node->getFunction())
         return ((Value*)Node->getFunction())->getName();
       else
-        return "Indirect call node";
+        return "external node";
     }
   };
 }
@@ -62,15 +65,14 @@ namespace llvm {
 namespace {
   struct CallGraphPrinter : public ModulePass {
     static char ID; // Pass ID, replacement for typeid
-    CallGraphPrinter() : ModulePass((intptr_t)&ID) {}
+    CallGraphPrinter() : ModulePass(&ID) {}
 
     virtual bool runOnModule(Module &M) {
-      WriteGraphToFile(std::cerr, "callgraph", &getAnalysis<CallGraph>());
+      WriteGraphToFile(llvm::errs(), "callgraph", &getAnalysis<CallGraph>());
       return false;
     }
 
-    void print(std::ostream &OS) const {}
-    void print(std::ostream &OS, const llvm::Module*) const {}
+    void print(raw_ostream &OS, const llvm::Module*) const {}
 
     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
       AU.addRequired<CallGraph>();
@@ -91,7 +93,7 @@ namespace {
   class DomInfoPrinter : public FunctionPass {
   public:
     static char ID; // Pass identification, replacement for typeid
-    DomInfoPrinter() : FunctionPass((intptr_t)&ID) {}
+    DomInfoPrinter() : FunctionPass(&ID) {}
 
     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
       AU.setPreservesAll();