#include "llvm/Support/CFG.h"
#include <sstream>
#include <fstream>
+using namespace llvm;
/// CFGOnly flag - This is used to control whether or not the CFG graph printer
/// prints out the contents of basic blocks or not. This is acceptable because
///
static bool CFGOnly = false;
+namespace llvm {
template<>
struct DOTGraphTraits<const Function*> : public DefaultDOTGraphTraits {
static std::string getGraphName(const Function *F) {
static std::string getNodeLabel(const BasicBlock *Node,
const Function *Graph) {
- if (CFGOnly && !Node->getName().empty()) return Node->getName() + ":";
+ if (CFGOnly && !Node->getName().empty())
+ return Node->getName() + ":";
std::ostringstream Out;
if (CFGOnly) {
return Out.str();
}
+ if (Node->getName().empty()) {
+ WriteAsOperand(Out, Node, false, true);
+ Out << ":";
+ }
+
Out << *Node;
std::string OutStr = Out.str();
if (OutStr[0] == '\n') OutStr.erase(OutStr.begin());
return "";
}
};
+}
namespace {
struct CFGPrinter : public FunctionPass {
RegisterAnalysis<CFGPrinter> P1("print-cfg",
"Print CFG of function to 'dot' file");
-};
-
+ struct CFGOnlyPrinter : public CFGPrinter {
+ virtual bool runOnFunction(Function &F) {
+ bool OldCFGOnly = CFGOnly;
+ CFGOnly = true;
+ CFGPrinter::runOnFunction(F);
+ CFGOnly = OldCFGOnly;
+ return false;
+ }
+ void print(std::ostream &OS) const {}
+
+ virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+ AU.setPreservesAll();
+ }
+ };
+ RegisterAnalysis<CFGOnlyPrinter>
+ P2("print-cfg-only",
+ "Print CFG of function to 'dot' file (with no function bodies)");
+}
/// viewCFG - This function is meant for use from the debugger. You can just
/// say 'call F->viewCFG()' and a ghostview window should pop up from the