ROSE 0.11.145.229
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
37public:
51
57 using EndpointId = size_t;
58
63 using ArrowId = size_t;
64
71
75 struct ArrowStyle {
78 std::string sourceThenDown;
79 std::string sourceThenUp;
80 std::string verticalLine;
81 std::string downToTarget;
82 std::string upToTarget;
83 std::string blank;
84 std::string sourceHorizontal;
85 std::string targetHorizontal;
86 };
87
96
98 enum ArrowSide {
100 RIGHT
101 };
102
103private:
104 // Logical location of an arrow endpoint in the output. Each endpoint is assumed to occupy four logical lines, although each
105 // logical line may consist of multiple physical lines of output). They are:
106 //
107 // 1. a first line for the endpoint,
108 //
109 // 2. a middle line representative of all lines between #1 and #3
110 //
111 // 3. a last line for the endpoint
112 //
113 // 4. a separator line representative of all lines of output between #4 of this endpoint and #1 of the next endpoint.
114 using OutputLocation = Sawyer::Container::Interval<size_t>;
115
116 // Mapping from an endpoint to its logical location in the output.
118
119 // Arrow properties
120 struct Arrow {
121 OutputLocation location; // line numbers occupied by the arrow
122 bool isForward; // arrow points to a later vertex?
123 ArrowId arrowId; // ID for this arrow
124 size_t columnIdx = INVALID_INDEX; // column of arrows where this arrow appears (after its been assigned)
125
126 Arrow()
127 : isForward(true) {}
128
129 Arrow(const OutputLocation &location, const bool isForward, const ArrowId arrowId)
130 : location(location), isForward(isForward), arrowId(arrowId) {}
131
132 bool operator==(const Arrow &other) {
133 return location == other.location && isForward == other.isForward && arrowId == other.arrowId;
134 }
135 };
136
137 // One column of arrows. Maps line numbers of output to line numbers of edges.
138 using Column = Sawyer::Container::IntervalMap<OutputLocation /*line number*/, Arrow>;
139
140 // Columns of arrows
141 using Columns = std::vector<Column>;
142
143private:
144 OutputLocation outputHull_; // entire output
145 EndpointLocations endpointLocations_; // logical location of each endpointin the output
146 Columns columns_; // columns of arrows
147 ArrowStyle arrowStyle_; // how to render arrows
148 size_t minRenderColumns_ = 0; // minimum number of arrow columns to render
149 size_t maxRenderColumns_ = UNLIMITED; // maximum number of arrow columns to render
150
151public:
152 EdgeArrows() {
153 arrowStyle_ = asciiL3(); // maximum portability but slightly less clarity than unicodeL2
154 }
155
165 std::pair<size_t, size_t> minMaxRenderColumns() const;
166 void minMaxRenderColumns(size_t minColumns, size_t maxColumns);
174 bool columnIsRendered(size_t columnIdx) const;
175
185 void computeLayout(const Graph&, const std::vector<EndpointId> &order);
186
195
207
216 static EndpointId edgeToSourceEndpoint(size_t edgeId);
217 static EndpointId edgeToTargetEndpoint(size_t edgeId);
227 bool exists(EndpointId) const;
228
231
236 void reset();
237
246 size_t nArrowColumns() const;
247
252 size_t nRenderColumns() const;
253
257 const ArrowStyle& arrowStyle() const { return arrowStyle_; }
258 void arrowStyle(const ArrowStyle &t) { arrowStyle_ = t; }
263
296 std::string renderBlank() const;
297
299 std::string render(EndpointId, OutputPart) const;
300
305 size_t nSources(EndpointId) const;
306
311 size_t nTargets(EndpointId) const;
312
314 void debug(std::ostream&) const;
315
316private:
317 // Append an endpoint to the output. This doesn't actually create any output, it just reserves space for it.
318 void appendEndpoint(EndpointId);
319
320 // Is the length of arrow A less than the length of arrow B?
321 static bool ascendingLength(const Arrow &a, const Arrow &b);
322
323};
324
325} // namespace
326} // namespace
327} // namespace
328
329#endif
330#endif
Renders textual margin arrows.
Definition EdgeArrows.h:36
static bool isSourceEndpoint(EndpointId)
Endpoint IDs related to edge IDs.
Sawyer::Optional< Arrow > findArrow(ArrowId) const
Finds the arrow information for the specified edge.
static bool isTargetEndpoint(EndpointId)
Endpoint IDs related to edge IDs.
ArrowSide
Specifies on which side of the output the arrows appear.
Definition EdgeArrows.h:98
@ RIGHT
Arrows appear right of the main output and point to the left.
Definition EdgeArrows.h:100
@ LEFT
Arrows appear left of the main output and point to the right.
Definition EdgeArrows.h:99
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.
std::pair< size_t, size_t > minMaxRenderColumns() const
Property: Minimum and maximum number of columns to render.
void computeLayout(const Graph &, const std::vector< EndpointId > &order)
Analyze connectivity in order to assign arrow locations.
static EndpointId edgeToSourceEndpoint(size_t edgeId)
Endpoint IDs related to edge IDs.
size_t nTargets(EndpointId) const
Number of arrows that point to the given endpoint.
const ArrowStyle & arrowStyle() const
Property: Information about how to render an arrow.
Definition EdgeArrows.h:257
static ArrowStyle asciiR3()
Arrow rendering styles.
size_t nRenderColumns() const
Number of columns to render.
void arrowStyle(ArrowStylePreset, ArrowSide)
Set the arrow style to a preset value.
static EndpointId otherEndpoint(EndpointId)
Endpoint IDs related to edge IDs.
size_t EndpointId
Endpoint identification number.
Definition EdgeArrows.h:57
static ArrowStyle unicodeL2()
Arrow rendering styles.
bool columnIsRendered(size_t columnIdx) const
Predicate: Whether the specified arrow column is rendered.
static ArrowStyle unicodeL1()
Arrow rendering styles.
static size_t edgeFromEndpoint(EndpointId)
Endpoint IDs related to edge IDs.
bool exists(EndpointId) const
Tests whether endpoint ID is known.
@ ASCII_1
Single-character ASCII-art arrows.
Definition EdgeArrows.h:92
@ ASCII_3
Threee-character ASCII-art arrows.
Definition EdgeArrows.h:94
@ UNICODE_1
Single-character Unicode arrows.
Definition EdgeArrows.h:90
@ ASCII_2
Two-character ASCII-art arrows.
Definition EdgeArrows.h:93
@ UNICODE_2
Two-character Unicode arrows.
Definition EdgeArrows.h:91
static ArrowStyle asciiR4()
Arrow rendering styles.
@ MIDDLE_LINE
Non-arrow lines between target and source lines for a pointee.
Definition EdgeArrows.h:48
@ INTER_LINE
Lines between sources of this pointee and targets of next pointee.
Definition EdgeArrows.h:49
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 EndpointId edgeToTargetEndpoint(size_t edgeId)
Endpoint IDs related to edge IDs.
static ArrowStyle asciiL3()
Arrow rendering styles.
size_t nSources(EndpointId) const
Number of arrows that emanate from the given endpoint.
void arrowStyle(const ArrowStyle &t)
Property: Information about how to render an arrow.
Definition EdgeArrows.h:258
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.
void minMaxRenderColumns(size_t minColumns, size_t maxColumns)
Property: Minimum and maximum number of columns to render.
static ArrowStyle asciiL2()
Arrow rendering styles.
size_t ArrowId
Arrow identification number.
Definition EdgeArrows.h:63
std::string renderBlank() const
Render a field of blank characters for all the columns.
std::string render(EndpointId, OutputPart) const
Render arrow columns for an endpoint.
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
Holds a value or nothing.
Definition Optional.h:56
The ROSE library.
const size_t INVALID_INDEX
Invalid array index.
Definition Constants.h:25
const size_t UNLIMITED
Effectively unlimited size.
Definition Constants.h:19
std::string sourceHorizontal
Text for the horizontal source of an arrow.
Definition EdgeArrows.h:84
std::string upToTarget
Text for an arrow comming from below into a vertex.
Definition EdgeArrows.h:82
std::string targetHorizontal
Text for the horizontal target of an arrow.
Definition EdgeArrows.h:85
std::string sourceThenDown
Text for an arrow leaving a vertex and turning downward.
Definition EdgeArrows.h:78
size_t charactersPerColumn
Number of characters per arrow column.
Definition EdgeArrows.h:76
std::string downToTarget
Text for an arrow comming from above into a vertex.
Definition EdgeArrows.h:81
std::string verticalLine
Text for the vertical line part of an arrow.
Definition EdgeArrows.h:80
std::string blank
Text when there's lack of any arrow.
Definition EdgeArrows.h:83
std::string sourceThenUp
Text for an arrow leaving a vertex and turning upward.
Definition EdgeArrows.h:79
bool pointsRight
Arrows point right? Otherwise left.
Definition EdgeArrows.h:77