1 #ifndef ROSE_BinaryAnalysis_Unparser_EdgeArrows_H
2 #define ROSE_BinaryAnalysis_Unparser_EdgeArrows_H
3 #include <featureTests.h>
6 #include <Rose/BinaryAnalysis/Partitioner2/BasicTypes.h>
7 #include <Sawyer/Graph.h>
8 #include <Sawyer/Interval.h>
9 #include <Sawyer/IntervalMap.h>
10 #include <Sawyer/Map.h>
11 #include <Rose/StringUtility.h>
12 #include <ostream>
13 #include <vector>
15 namespace Rose {
16 namespace BinaryAnalysis {
17 namespace Unparser {
20 // Basic block arrow information
30 class EdgeArrows {
31 public:
33  enum OutputPart {
38  };
41  typedef rose_addr_t VertexId;
47  struct ArrowStyle {
49  bool pointsRight;
50  std::string sourceThenDown;
51  std::string sourceThenUp;
52  std::string verticalLine;
53  std::string downToTarget;
54  std::string upToTarget;
55  std::string blank;
56  std::string sourceHorizontal;
57  std::string targetHorizontal;
58  };
67  };
70  enum ArrowSide {
71  LEFT,
73  };
75 private:
76  // Location of a vertex in the output. Each vertex is assumed to occupy four lines: a first line for incoming edges,
77  // a middle line representative of all lines of output between the first and last lines, a last line for outgoing
78  // edges, and a separator line representative of all lines of output between vertices.
79  typedef Sawyer::Container::Interval<size_t> OutputLocation;
81  // Mapping from vertex ID to its location in the output.
84  // Edge properties
85  struct Arrow {
86  OutputLocation location; // line numbers occupied by the arrow
87  bool isForward; // arrow points to a later vertex?
89  Arrow()
90  : isForward(true) {}
92  Arrow(const OutputLocation &location, bool isForward)
93  : location(location), isForward(isForward) {}
95  bool operator==(const Arrow &other) {
96  return location == other.location && isForward == other.isForward;
97  }
98  };
100  // One column of arrows. Maps line numbers of output to line numbers of edges.
101  typedef Sawyer::Container::IntervalMap<OutputLocation /*line number*/, Arrow> Column;
103  // Columns of arrows
104  typedef std::vector<Column> Columns;
106 private:
107  OutputLocation outputHull_; // entire output
108  VertexLocations vertexLocations_; // location of each vertex in the output
109  Columns columns_; // columns of arrows
110  ArrowStyle arrowStyle_; // how to render arrows
112 public:
113  EdgeArrows() {
114  arrowStyle_ = asciiL3(); // maximum portability but slightly less clarity than unicodeL2
115  }
126  void computeLayout(const Graph&, const std::vector<VertexId> &order = std::vector<VertexId>());
135  void computeCfgBlockLayout(const Partitioner2::Partitioner&, const Partitioner2::FunctionPtr&);
147  void computeCfgEdgeLayout(const Partitioner2::Partitioner&, const Partitioner2::FunctionPtr&);
155  static VertexId cfgEdgeSourceEndpoint(size_t edgeId);
156  static VertexId cfgEdgeTargetEndpoint(size_t edgeId);
163  void reset();
171  size_t nArrowColumns() const;
176  const ArrowStyle& arrowStyle() const { return arrowStyle_; }
177  void arrowStyle(const ArrowStyle &t) { arrowStyle_ = t; }
197  static ArrowStyle unicodeL1();
198  static ArrowStyle unicodeR1();
199  static ArrowStyle unicodeL2();
200  static ArrowStyle unicodeR2();
201  static ArrowStyle asciiL1();
202  static ArrowStyle asciiR1();
203  static ArrowStyle asciiL2();
204  static ArrowStyle asciiR2();
205  static ArrowStyle asciiL3();
206  static ArrowStyle asciiR3();
207  static ArrowStyle asciiL4();
208  static ArrowStyle asciiR4();
213  std::string renderBlank() const;
216  std::string render(VertexId, OutputPart) const;
222  size_t nSources(VertexId) const;
228  size_t nTargets(VertexId) const;
231  void debug(std::ostream&) const;
233 private:
234  // Append a vertex to the output. This doesn't actually create any output, it just reserves space for it.
235  void appendVertex(VertexId);
237  // Is the length of arrow A less than the length of arrow B?
238  static bool ascendingLength(const Arrow &a, const Arrow &b);
240 };
242 } // namespace
243 } // namespace
244 } // namespace
246 #endif
247 #endif
On which side of the listing do the errors appear.
Definition: EdgeArrows.h:70
std::string downToTarget
Text for an arrow comming from above into a vertex.
Definition: EdgeArrows.h:53
std::string verticalLine
Text for the vertical line part of an arrow.
Definition: EdgeArrows.h:52
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.
Definition: EdgeArrows.h:51
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.
Definition: EdgeArrows.h:55
Lines in the middle of a printed vertex.
Definition: EdgeArrows.h:36
First line of a vertex when printed.
Definition: EdgeArrows.h:34
static ArrowStyle asciiR2()
Arrow rendering styles.
Single-character ASCII-art arrows.
Definition: EdgeArrows.h:64
std::string targetHorizontal
Text for the horizontal target of an arrow.
Definition: EdgeArrows.h:57
static ArrowStyle unicodeL1()
Arrow rendering styles.
Sawyer::Container::Graph< VertexId, Sawyer::Nothing, VertexId > Graph
Graph relating vertices by their edges with vertex index.
Definition: EdgeArrows.h:44
std::string sourceThenDown
Text for an arrow leaving a vertex and turning downward.
Definition: EdgeArrows.h:50
rose_addr_t VertexId
Vertex identification numbers.
Definition: EdgeArrows.h:41
Main namespace for the ROSE library.
std::string upToTarget
Text for an arrow comming from below into a vertex.
Definition: EdgeArrows.h:54
Threee-character ASCII-art arrows.
Definition: EdgeArrows.h:66
Arrows appear right of the listing and point to the left.
Definition: EdgeArrows.h:72
Sawyer::SharedPointer< Function > FunctionPtr
Shared-ownership pointer for function.
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.
Definition: EdgeArrows.h:56
static ArrowStyle asciiL1()
Arrow rendering styles.
size_t charactersPerColumn
Number of characters per arrow column.
Definition: EdgeArrows.h:48
bool pointsRight
Arrows point right? Otherwise left.
Definition: EdgeArrows.h:49
Two-character ASCII-art arrows.
Definition: EdgeArrows.h:65
static ArrowStyle asciiR3()
Arrow rendering styles.
Analysis to generate arrows from one basic block to another.
Definition: EdgeArrows.h:30
static ArrowStyle unicodeR1()
Arrow rendering styles.
Arrows appear left of the listing and point to the right.
Definition: EdgeArrows.h:71
Last line of a vertex when printed.
Definition: EdgeArrows.h:35
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.
Definition: EdgeArrows.h:177
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.
Definition: EdgeArrows.h:176