ROSE 0.11.145.147
EdgeArrows.h
1#ifndef ROSE_BinaryAnalysis_Unparser_EdgeArrows_H
2#define ROSE_BinaryAnalysis_Unparser_EdgeArrows_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5
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>
14
15namespace Rose {
16namespace BinaryAnalysis {
17namespace Unparser {
18
20// Basic block arrow information
22
31public:
39
41 typedef rose_addr_t VertexId;
42
45
47 struct ArrowStyle {
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 };
59
68
70 enum ArrowSide {
72 RIGHT
73 };
74
75private:
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;
80
81 // Mapping from vertex ID to its location in the output.
83
84 // Edge properties
85 struct Arrow {
86 OutputLocation location; // line numbers occupied by the arrow
87 bool isForward; // arrow points to a later vertex?
88
89 Arrow()
90 : isForward(true) {}
91
92 Arrow(const OutputLocation &location, bool isForward)
93 : location(location), isForward(isForward) {}
94
95 bool operator==(const Arrow &other) {
96 return location == other.location && isForward == other.isForward;
97 }
98 };
99
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;
102
103 // Columns of arrows
104 typedef std::vector<Column> Columns;
105
106private:
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
111
112public:
113 EdgeArrows() {
114 arrowStyle_ = asciiL3(); // maximum portability but slightly less clarity than unicodeL2
115 }
116
126 void computeLayout(const Graph&, const std::vector<VertexId> &order = std::vector<VertexId>());
127
136
148
155 static VertexId cfgEdgeSourceEndpoint(size_t edgeId);
156 static VertexId cfgEdgeTargetEndpoint(size_t edgeId);
163 void reset();
164
171 size_t nArrowColumns() const;
172
176 const ArrowStyle& arrowStyle() const { return arrowStyle_; }
177 void arrowStyle(const ArrowStyle &t) { arrowStyle_ = t; }
182
213 std::string renderBlank() const;
214
216 std::string render(VertexId, OutputPart) const;
217
222 size_t nSources(VertexId) const;
223
228 size_t nTargets(VertexId) const;
229
231 void debug(std::ostream&) const;
232
233private:
234 // Append a vertex to the output. This doesn't actually create any output, it just reserves space for it.
235 void appendVertex(VertexId);
236
237 // Is the length of arrow A less than the length of arrow B?
238 static bool ascendingLength(const Arrow &a, const Arrow &b);
239
240};
241
242} // namespace
243} // namespace
244} // namespace
245
246#endif
247#endif
Analysis to generate arrows from one basic block to another.
Definition EdgeArrows.h:30
std::string render(VertexId, OutputPart) const
Render arrow columsn for a vertex.
void computeLayout(const Graph &, const std::vector< VertexId > &order=std::vector< VertexId >())
Analyze connectivity in order to assign arrow locations.
ArrowSide
On which side of the listing do the errors appear.
Definition EdgeArrows.h:70
@ RIGHT
Arrows appear right of the listing and point to the left.
Definition EdgeArrows.h:72
@ LEFT
Arrows appear left of the listing and point to the right.
Definition EdgeArrows.h:71
Sawyer::Container::Graph< VertexId, Sawyer::Nothing, VertexId > Graph
Graph relating vertices by their edges with vertex index.
Definition EdgeArrows.h:44
static ArrowStyle asciiL4()
Arrow rendering styles.
void computeCfgEdgeLayout(const Partitioner2::PartitionerConstPtr &, const Partitioner2::FunctionPtr &)
Compute arrow layout for a control flow graph for a function.
const ArrowStyle & arrowStyle() const
Property: Information about how to render an arrow.
Definition EdgeArrows.h:176
static ArrowStyle asciiR3()
Arrow rendering styles.
void arrowStyle(ArrowStylePreset, ArrowSide)
Set the arrow style to a preset value.
static ArrowStyle unicodeL2()
Arrow rendering styles.
rose_addr_t VertexId
Vertex identification numbers.
Definition EdgeArrows.h:41
size_t nSources(VertexId) const
Number of arrows that emanate from the given vertex.
static VertexId cfgEdgeTargetEndpoint(size_t edgeId)
Endpoint ID for CFG edge arrows.
static VertexId cfgEdgeSourceEndpoint(size_t edgeId)
Endpoint ID for CFG edge arrows.
static ArrowStyle unicodeL1()
Arrow rendering styles.
size_t nTargets(VertexId) const
Number of arrows that point to the given vertex.
@ ASCII_1
Single-character ASCII-art arrows.
Definition EdgeArrows.h:64
@ ASCII_3
Threee-character ASCII-art arrows.
Definition EdgeArrows.h:66
@ UNICODE_1
Single-character Unicode arrows.
Definition EdgeArrows.h:62
@ ASCII_2
Two-character ASCII-art arrows.
Definition EdgeArrows.h:65
@ UNICODE_2
Two-character Unicode arrows.
Definition EdgeArrows.h:63
static ArrowStyle asciiR4()
Arrow rendering styles.
@ MIDDLE_LINE
Lines in the middle of a printed vertex.
Definition EdgeArrows.h:36
@ FIRST_LINE
First line of a vertex when printed.
Definition EdgeArrows.h:34
@ LAST_LINE
Last line of a vertex when printed.
Definition EdgeArrows.h:35
@ INTER_LINE
Lines output between vertices.
Definition EdgeArrows.h:37
void debug(std::ostream &) const
Print implementation-defined debugging information.
static ArrowStyle unicodeR1()
Arrow rendering styles.
void computeCfgBlockLayout(const Partitioner2::PartitionerConstPtr &, const Partitioner2::FunctionPtr &)
Compute arrow layout for a control flow graph for a function.
static ArrowStyle asciiL3()
Arrow rendering styles.
void arrowStyle(const ArrowStyle &t)
Property: Information about how to render an arrow.
Definition EdgeArrows.h:177
static ArrowStyle asciiR1()
Arrow rendering styles.
static ArrowStyle asciiR2()
Arrow rendering styles.
size_t nArrowColumns() const
Number of arrow columns.
static ArrowStyle unicodeR2()
Arrow rendering styles.
static ArrowStyle asciiL2()
Arrow rendering styles.
std::string renderBlank() const
Render a field of blank characters for all the columns.
static ArrowStyle asciiL1()
Arrow rendering styles.
Graph containing user-defined vertices and edges.
Definition Graph.h:634
An associative container whose keys are non-overlapping intervals.
Range of values delimited by endpoints.
Definition Interval.h:31
Container associating values with keys.
Definition Sawyer/Map.h:72
The ROSE library.
std::string sourceHorizontal
Text for the horizontal source of an arrow.
Definition EdgeArrows.h:56
std::string upToTarget
Text for an arrow comming from below into a vertex.
Definition EdgeArrows.h:54
std::string targetHorizontal
Text for the horizontal target of an arrow.
Definition EdgeArrows.h:57
std::string sourceThenDown
Text for an arrow leaving a vertex and turning downward.
Definition EdgeArrows.h:50
size_t charactersPerColumn
Number of characters per arrow column.
Definition EdgeArrows.h:48
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
std::string blank
Text when there's lack of any arrow.
Definition EdgeArrows.h:55
std::string sourceThenUp
Text for an arrow leaving a vertex and turning upward.
Definition EdgeArrows.h:51
bool pointsRight
Arrows point right? Otherwise left.
Definition EdgeArrows.h:49