ROSE  0.11.2.0
BinaryEdgeArrows.h
1 #ifndef Rose_BinaryAnalysis_Unparser_EdgeArrows_H
2 #define Rose_BinaryAnalysis_Unparser_EdgeArrows_H
3 
4 #include <rosePublicConfig.h>
5 #ifdef ROSE_BUILD_BINARY_ANALYSIS_SUPPORT
6 
7 #include <Partitioner2/BasicTypes.h>
8 #include <Sawyer/Graph.h>
9 #include <Sawyer/Interval.h>
10 #include <Sawyer/IntervalMap.h>
11 #include <Sawyer/Map.h>
12 #include <StringUtility.h>
13 #include <ostream>
14 #include <vector>
15 
16 namespace Rose {
17 namespace BinaryAnalysis {
18 namespace Unparser {
19 
21 // Basic block arrow information
23 
31 class EdgeArrows {
32 public:
34  enum OutputPart {
39  };
40 
42  typedef rose_addr_t VertexId;
43 
46 
48  struct ArrowStyle {
50  bool pointsRight;
51  std::string sourceThenDown;
52  std::string sourceThenUp;
53  std::string verticalLine;
54  std::string downToTarget;
55  std::string upToTarget;
56  std::string blank;
57  std::string sourceHorizontal;
58  std::string targetHorizontal;
59  };
60 
68  };
69 
71  enum ArrowSide {
72  LEFT,
74  };
75 
76 private:
77  // Location of a vertex in the output. Each vertex is assumed to occupy four lines: a first line for incoming edges,
78  // a middle line representative of all lines of output between the first and last lines, a last line for outgoing
79  // edges, and a separator line representative of all lines of output between vertices.
80  typedef Sawyer::Container::Interval<size_t> OutputLocation;
81 
82  // Mapping from vertex ID to its location in the output.
84 
85  // Edge properties
86  struct Arrow {
87  OutputLocation location; // line numbers occupied by the arrow
88  bool isForward; // arrow points to a later vertex?
89 
90  Arrow()
91  : isForward(true) {}
92 
93  Arrow(const OutputLocation &location, bool isForward)
94  : location(location), isForward(isForward) {}
95 
96  bool operator==(const Arrow &other) {
97  return location == other.location && isForward == other.isForward;
98  }
99  };
100 
101  // One column of arrows. Maps line numbers of output to line numbers of edges.
102  typedef Sawyer::Container::IntervalMap<OutputLocation /*line number*/, Arrow> Column;
103 
104  // Columns of arrows
105  typedef std::vector<Column> Columns;
106 
107 private:
108  OutputLocation outputHull_; // entire output
109  VertexLocations vertexLocations_; // location of each vertex in the output
110  Columns columns_; // columns of arrows
111  ArrowStyle arrowStyle_; // how to render arrows
112 
113 public:
114  EdgeArrows() {
115  arrowStyle_ = asciiL3(); // maximum portability but slightly less clarity than unicodeL2
116  }
117 
127  void computeLayout(const Graph&, const std::vector<VertexId> &order = std::vector<VertexId>());
128 
136  void computeCfgBlockLayout(const Partitioner2::Partitioner&, const Partitioner2::FunctionPtr&);
137 
148  void computeCfgEdgeLayout(const Partitioner2::Partitioner&, const Partitioner2::FunctionPtr&);
149 
156  static VertexId cfgEdgeSourceEndpoint(size_t edgeId);
157  static VertexId cfgEdgeTargetEndpoint(size_t edgeId);
164  void reset();
165 
172  size_t nArrowColumns() const;
173 
177  const ArrowStyle& arrowStyle() const { return arrowStyle_; }
178  void arrowStyle(const ArrowStyle &t) { arrowStyle_ = t; }
183 
198  static ArrowStyle unicodeL1();
199  static ArrowStyle unicodeR1();
200  static ArrowStyle unicodeL2();
201  static ArrowStyle unicodeR2();
202  static ArrowStyle asciiL1();
203  static ArrowStyle asciiR1();
204  static ArrowStyle asciiL2();
205  static ArrowStyle asciiR2();
206  static ArrowStyle asciiL3();
207  static ArrowStyle asciiR3();
208  static ArrowStyle asciiL4();
209  static ArrowStyle asciiR4();
214  std::string renderBlank() const;
215 
217  std::string render(VertexId, OutputPart) const;
218 
223  size_t nSources(VertexId) const;
224 
229  size_t nTargets(VertexId) const;
230 
232  void debug(std::ostream&) const;
233 
234 private:
235  // Append a vertex to the output. This doesn't actually create any output, it just reserves space for it.
236  void appendVertex(VertexId);
237 
238  // Is the length of arrow A less than the length of arrow B?
239  static bool ascendingLength(const Arrow &a, const Arrow &b);
240 
241 };
242 
243 } // namespace
244 } // namespace
245 } // namespace
246 
247 #endif
248 #endif
ArrowSide
On which side of the listing do the errors appear.
std::string downToTarget
Text for an arrow comming from above into a vertex.
std::string verticalLine
Text for the vertical line part of an arrow.
size_t nArrowColumns() const
Number of arrow columns.
static ArrowStyle unicodeL2()
Arrow rendering styles.
An associative container whose keys are non-overlapping intervals.
Definition: IntervalMap.h:171
Graph containing user-defined vertices and edges.
Definition: Graph.h:625
std::string sourceThenUp
Text for an arrow leaving a vertex and turning upward.
size_t nSources(VertexId) const
Number of arrows that emanate from the given vertex.
std::string blank
Text when there's lack of any arrow.
Lines in the middle of a printed vertex.
static ArrowStyle asciiR2()
Arrow rendering styles.
std::string targetHorizontal
Text for the horizontal target of an arrow.
static ArrowStyle unicodeL1()
Arrow rendering styles.
Sawyer::Container::Graph< VertexId, Sawyer::Nothing, VertexId > Graph
Graph relating vertices by their edges with vertex index.
std::string sourceThenDown
Text for an arrow leaving a vertex and turning downward.
rose_addr_t VertexId
Vertex identification numbers.
Main namespace for the ROSE library.
std::string upToTarget
Text for an arrow comming from below into a vertex.
Arrows appear right of the listing and point to the left.
Sawyer::SharedPointer< Function > FunctionPtr
Shared-ownership pointer for function.
Definition: BasicTypes.h:492
static VertexId cfgEdgeSourceEndpoint(size_t edgeId)
Endpoint ID for CFG edge arrows.
static ArrowStyle asciiL3()
Arrow rendering styles.
size_t nTargets(VertexId) const
Number of arrows that point to the given vertex.
static ArrowStyle unicodeR2()
Arrow rendering styles.
static ArrowStyle asciiR4()
Arrow rendering styles.
static ArrowStyle asciiL4()
Arrow rendering styles.
std::string renderBlank() const
Render a field of blank characters for all the columns.
std::string render(VertexId, OutputPart) const
Render arrow columsn for a vertex.
void debug(std::ostream &) const
Print implementation-defined debugging information.
std::string sourceHorizontal
Text for the horizontal source of an arrow.
static ArrowStyle asciiL1()
Arrow rendering styles.
size_t charactersPerColumn
Number of characters per arrow column.
bool pointsRight
Arrows point right? Otherwise left.
static ArrowStyle asciiR3()
Arrow rendering styles.
Analysis to generate arrows from one basic block to another.
static ArrowStyle unicodeR1()
Arrow rendering styles.
Arrows appear left of the listing and point to the right.
void computeCfgEdgeLayout(const Partitioner2::Partitioner &, const Partitioner2::FunctionPtr &)
Compute arrow layout for a control flow graph for a function.
void computeCfgBlockLayout(const Partitioner2::Partitioner &, const Partitioner2::FunctionPtr &)
Compute arrow layout for a control flow graph for a function.
static ArrowStyle asciiL2()
Arrow rendering styles.
static VertexId cfgEdgeTargetEndpoint(size_t edgeId)
Endpoint ID for CFG edge arrows.
static ArrowStyle asciiR1()
Arrow rendering styles.
void arrowStyle(const ArrowStyle &t)
Property: Information about how to render an arrow.
void computeLayout(const Graph &, const std::vector< VertexId > &order=std::vector< VertexId >())
Analyze connectivity in order to assign arrow locations.
const ArrowStyle & arrowStyle() const
Property: Information about how to render an arrow.