ROSE  0.9.10.135
BinaryEdgeArrows.h
1 #ifndef Rose_BinaryAnalysis_Unparser_EdgeArrows_H
2 #define Rose_BinaryAnalysis_Unparser_EdgeArrows_H
3 
4 #include <Partitioner2/BasicTypes.h>
5 #include <Sawyer/Graph.h>
6 #include <Sawyer/Interval.h>
7 #include <Sawyer/IntervalMap.h>
8 #include <Sawyer/Map.h>
9 #include <StringUtility.h>
10 #include <ostream>
11 #include <vector>
12 
13 namespace Rose {
14 namespace BinaryAnalysis {
15 namespace Unparser {
16 
18 // Basic block arrow information
20 
28 class EdgeArrows {
29 public:
31  enum OutputPart {
36  };
37 
39  typedef rose_addr_t VertexId;
40 
43 
45  struct ArrowStyle {
47  bool pointsRight;
48  std::string sourceThenDown;
49  std::string sourceThenUp;
50  std::string verticalLine;
51  std::string downToTarget;
52  std::string upToTarget;
53  std::string blank;
54  std::string sourceHorizontal;
55  std::string targetHorizontal;
56  };
57 
65  };
66 
68  enum ArrowSide {
69  LEFT,
71  };
72 
73 private:
74  // Location of a vertex in the output. Each vertex is assumed to occupy four lines: a first line for incoming edges,
75  // a middle line representative of all lines of output between the first and last lines, a last line for outgoing
76  // edges, and a separator line representative of all lines of output between vertices.
77  typedef Sawyer::Container::Interval<size_t> OutputLocation;
78 
79  // Mapping from vertex ID to its location in the output.
81 
82  // Edge properties
83  struct Arrow {
84  OutputLocation location; // line numbers occupied by the arrow
85  bool isForward; // arrow points to a later vertex?
86 
87  Arrow()
88  : isForward(true) {}
89 
90  Arrow(const OutputLocation &location, bool isForward)
91  : location(location), isForward(isForward) {}
92 
93  bool operator==(const Arrow &other) {
94  return location == other.location && isForward == other.isForward;
95  }
96  };
97 
98  // One column of arrows. Maps line numbers of output to line numbers of edges.
99  typedef Sawyer::Container::IntervalMap<OutputLocation /*line number*/, Arrow> Column;
100 
101  // Columns of arrows
102  typedef std::vector<Column> Columns;
103 
104 private:
105  OutputLocation outputHull_; // entire output
106  VertexLocations vertexLocations_; // location of each vertex in the output
107  Columns columns_; // columns of arrows
108  ArrowStyle arrowStyle_; // how to render arrows
109 
110 public:
111  EdgeArrows() {
112  arrowStyle_ = asciiL3(); // maximum portability but slightly less clarity than unicodeL2
113  }
114 
124  void computeLayout(const Graph&, const std::vector<VertexId> &order = std::vector<VertexId>());
125 
133  void computeCfgBlockLayout(const Partitioner2::Partitioner&, const Partitioner2::FunctionPtr&);
134 
145  void computeCfgEdgeLayout(const Partitioner2::Partitioner&, const Partitioner2::FunctionPtr&);
146 
153  static VertexId cfgEdgeSourceEndpoint(size_t edgeId);
154  static VertexId cfgEdgeTargetEndpoint(size_t edgeId);
161  void reset();
162 
169  size_t nArrowColumns() const;
170 
174  const ArrowStyle& arrowStyle() const { return arrowStyle_; }
175  void arrowStyle(const ArrowStyle &t) { arrowStyle_ = t; }
180 
195  static ArrowStyle unicodeL1();
196  static ArrowStyle unicodeR1();
197  static ArrowStyle unicodeL2();
198  static ArrowStyle unicodeR2();
199  static ArrowStyle asciiL1();
200  static ArrowStyle asciiR1();
201  static ArrowStyle asciiL2();
202  static ArrowStyle asciiR2();
203  static ArrowStyle asciiL3();
204  static ArrowStyle asciiR3();
205  static ArrowStyle asciiL4();
206  static ArrowStyle asciiR4();
211  std::string renderBlank() const;
212 
214  std::string render(VertexId, OutputPart) const;
215 
220  size_t nSources(VertexId) const;
221 
226  size_t nTargets(VertexId) const;
227 
229  void debug(std::ostream&) const;
230 
231 private:
232  // Append a vertex to the output. This doesn't actually create any output, it just reserves space for it.
233  void appendVertex(VertexId);
234 
235  // Is the length of arrow A less than the length of arrow B?
236  static bool ascendingLength(const Arrow &a, const Arrow &b);
237 
238 };
239 
240 } // namespace
241 } // namespace
242 } // namespace
243 
244 #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:434
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.