diff options
author | Chris Lattner <sabre@nondot.org> | 2009-10-18 04:09:11 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-10-18 04:09:11 +0000 |
commit | 88067b9133103de3bfadd4f5166f4fb082ba2496 (patch) | |
tree | 5f3d1846541c919ff3106b5526a06dd8cb8b6ce4 /include/llvm/Analysis | |
parent | f0d24f1f597a84b1a164019ab81831ccd7aea47f (diff) | |
download | external_llvm-88067b9133103de3bfadd4f5166f4fb082ba2496.zip external_llvm-88067b9133103de3bfadd4f5166f4fb082ba2496.tar.gz external_llvm-88067b9133103de3bfadd4f5166f4fb082ba2496.tar.bz2 |
make DOTGraphTraits public, patch by Tobias Grosser!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84396 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Analysis')
-rw-r--r-- | include/llvm/Analysis/CFGPrinter.h | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/include/llvm/Analysis/CFGPrinter.h b/include/llvm/Analysis/CFGPrinter.h index 6a479d1..435f8ea 100644 --- a/include/llvm/Analysis/CFGPrinter.h +++ b/include/llvm/Analysis/CFGPrinter.h @@ -15,6 +15,67 @@ #ifndef LLVM_ANALYSIS_CFGPRINTER_H #define LLVM_ANALYSIS_CFGPRINTER_H +#include "llvm/Function.h" +#include "llvm/Instructions.h" +#include "llvm/Assembly/Writer.h" +#include "llvm/Support/CFG.h" +#include "llvm/Support/GraphWriter.h" + +namespace llvm { +template<> +struct DOTGraphTraits<const Function*> : public DefaultDOTGraphTraits { + static std::string getGraphName(const Function *F) { + return "CFG for '" + F->getNameStr() + "' function"; + } + + static std::string getNodeLabel(const BasicBlock *Node, + const Function *Graph, + bool ShortNames) { + if (ShortNames && !Node->getName().empty()) + return Node->getNameStr() + ":"; + + std::string Str; + raw_string_ostream OS(Str); + + if (ShortNames) { + WriteAsOperand(OS, Node, false); + return OS.str(); + } + + if (Node->getName().empty()) { + WriteAsOperand(OS, Node, false); + OS << ":"; + } + + OS << *Node; + std::string OutStr = OS.str(); + if (OutStr[0] == '\n') OutStr.erase(OutStr.begin()); + + // Process string output to make it nicer... + for (unsigned i = 0; i != OutStr.length(); ++i) + if (OutStr[i] == '\n') { // Left justify + OutStr[i] = '\\'; + OutStr.insert(OutStr.begin()+i+1, 'l'); + } else if (OutStr[i] == ';') { // Delete comments! + unsigned Idx = OutStr.find('\n', i+1); // Find end of line + OutStr.erase(OutStr.begin()+i, OutStr.begin()+Idx); + --i; + } + + return OutStr; + } + + static std::string getEdgeSourceLabel(const BasicBlock *Node, + succ_const_iterator I) { + // Label source of conditional branches with "T" or "F" + if (const BranchInst *BI = dyn_cast<BranchInst>(Node->getTerminator())) + if (BI->isConditional()) + return (I == succ_begin(Node)) ? "T" : "F"; + return ""; + } +}; +} // End llvm namespace + namespace llvm { class FunctionPass; FunctionPass *createCFGPrinterPass (); |