ROSE 0.11.145.272
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 <ROSE_DEPRECATED.h>
13
14#include <ostream>
15#include <vector>
16
17namespace Rose {
18namespace BinaryAnalysis {
19namespace Unparser {
20
22// Basic block arrow information
24
39public:
53
59 using EndpointId = size_t;
60
65 using ArrowId = size_t;
66
73
77 struct ArrowStyle {
80 std::string sourceThenDown;
81 std::string sourceThenUp;
82 std::string verticalLine;
83 std::string downToTarget;
84 std::string upToTarget;
85 std::string blank;
86 std::string sourceHorizontal;
87 std::string targetHorizontal;
88 };
89
98
104
105private:
106 // Logical location of an arrow endpoint in the output. Each endpoint is assumed to occupy four logical lines, although each
107 // logical line may consist of multiple physical lines of output). They are:
108 //
109 // 1. a first line for the endpoint,
110 //
111 // 2. a middle line representative of all lines between #1 and #3
112 //
113 // 3. a last line for the endpoint
114 //
115 // 4. a separator line representative of all lines of output between #4 of this endpoint and #1 of the next endpoint.
116 using OutputLocation = Sawyer::Container::Interval<size_t>;
117
118 // Mapping from an endpoint to its logical location in the output.
120
121 // Arrow properties
122 struct Arrow {
123 OutputLocation location; // line numbers occupied by the arrow
124 bool isForward; // arrow points to a later vertex?
125 ArrowId arrowId; // ID for this arrow
126 size_t columnIdx = INVALID_INDEX; // column of arrows where this arrow appears (after its been assigned)
127
128 Arrow()
129 : isForward(true) {}
130
131 Arrow(const OutputLocation &location, const bool isForward, const ArrowId arrowId)
132 : location(location), isForward(isForward), arrowId(arrowId) {}
133
134 bool operator==(const Arrow &other) {
135 return location == other.location && isForward == other.isForward && arrowId == other.arrowId;
136 }
137 };
138
139 // One column of arrows. Maps line numbers of output to line numbers of edges.
140 using Column = Sawyer::Container::IntervalMap<OutputLocation /*line number*/, Arrow>;
141
142 // Columns of arrows
143 using Columns = std::vector<Column>;
144
145private:
146 OutputLocation outputHull_; // entire output
147 EndpointLocations endpointLocations_; // logical location of each endpoint in the output
148 Columns columns_; // columns of arrows
149 ArrowStyle arrowStyle_; // how to render arrows
150 size_t minRenderColumns_ = 0; // minimum number of arrow columns to render
151 size_t maxRenderColumns_ = UNLIMITED; // maximum number of arrow columns to render
152
153public:
154 EdgeArrows() {
155 arrowStyle_ = asciiL3(); // maximum portability but slightly less clarity than unicodeL2
156 }
157
167 std::pair<size_t, size_t> minMaxRenderColumns() const;
168 void minMaxRenderColumns(size_t minColumns, size_t maxColumns);
176 bool columnIsRendered(size_t columnIdx) const;
177
187 void computeLayout(const Graph&, const std::vector<EndpointId> &order);
188
197
209
218 static EndpointId toSourceEndpoint(size_t cfgEdgeOrVertexId);
219 static EndpointId toTargetEndpoint(size_t cfgEdgeOrVertexId);
220 static size_t fromEndpoint(EndpointId);
226 // [Robb Matzke 2025-04-04]: Deprecated
227 static EndpointId edgeToSourceEndpoint(size_t edgeId) ROSE_DEPRECATED("use toSourceEndpoint");
228 static EndpointId edgeToTargetEndpoint(size_t edgeId) ROSE_DEPRECATED("use toTargetEndpoint");
229 static size_t edgeFromEndpoint(EndpointId) ROSE_DEPRECATED("use fromEndpoint");
230
234 bool exists(EndpointId) const;
235
238
243 void reset();
244
253 size_t nArrowColumns() const;
254
259 size_t nRenderColumns() const;
260
264 const ArrowStyle& arrowStyle() const { return arrowStyle_; }
265 void arrowStyle(const ArrowStyle &t) { arrowStyle_ = t; }
270
303 std::string renderBlank() const;
304
306 std::string render(EndpointId, OutputPart) const;
307
312 size_t nSources(EndpointId) const;
313
318 size_t nTargets(EndpointId) const;
319
323 void debug(std::ostream&) const;
324 void debugGraph(std::ostream&, const Graph&) const;
325 void debugLines(std::ostream&, const std::vector<EndpointId>&) const;
328private:
329 // Append an endpoint to the output. This doesn't actually create any output, it just reserves space for it.
330 void appendEndpoint(EndpointId);
331
332 // Is the length of arrow A less than the length of arrow B?
333 static bool ascendingLength(const Arrow &a, const Arrow &b);
334
335};
336
337} // namespace
338} // namespace
339} // namespace
340
341#endif
342#endif
Renders textual margin arrows.
Definition EdgeArrows.h:38
static bool isSourceEndpoint(EndpointId)
Arrow endpoint IDs related to edge or vertex IDs.
Sawyer::Optional< Arrow > findArrow(ArrowId) const
Finds the arrow information for the specified edge.
static bool isTargetEndpoint(EndpointId)
Arrow endpoint IDs related to edge or vertex IDs.
ArrowSide
Specifies on which side of the output the arrows appear.
Definition EdgeArrows.h:100
@ RIGHT
Arrows appear right of the main output and point to the left.
Definition EdgeArrows.h:102
@ LEFT
Arrows appear left of the main output and point to the right.
Definition EdgeArrows.h:101
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.
static size_t fromEndpoint(EndpointId)
Arrow endpoint IDs related to edge or vertex IDs.
static EndpointId toTargetEndpoint(size_t cfgEdgeOrVertexId)
Arrow endpoint IDs related to edge or vertex IDs.
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 toSourceEndpoint(size_t cfgEdgeOrVertexId)
Arrow endpoint IDs related to edge or vertex 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:264
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)
Arrow endpoint IDs related to edge or vertex IDs.
size_t EndpointId
Endpoint identification number.
Definition EdgeArrows.h:59
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.
void debugGraph(std::ostream &, const Graph &) const
Print implementation-defined debugging information.
void debugLines(std::ostream &, const std::vector< EndpointId > &) const
Print implementation-defined debugging information.
bool exists(EndpointId) const
Tests whether endpoint ID is known.
@ ASCII_1
Single-character ASCII-art arrows.
Definition EdgeArrows.h:94
@ ASCII_3
Threee-character ASCII-art arrows.
Definition EdgeArrows.h:96
@ UNICODE_1
Single-character Unicode arrows.
Definition EdgeArrows.h:92
@ ASCII_2
Two-character ASCII-art arrows.
Definition EdgeArrows.h:95
@ UNICODE_2
Two-character Unicode arrows.
Definition EdgeArrows.h:93
static ArrowStyle asciiR4()
Arrow rendering styles.
@ MIDDLE_LINE
Non-arrow lines between target and source lines for a pointee.
Definition EdgeArrows.h:50
@ INTER_LINE
Lines between sources of this pointee and targets of next pointee.
Definition EdgeArrows.h:51
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.
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:265
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:65
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.
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:86
std::string upToTarget
Text for an arrow comming from below into a vertex.
Definition EdgeArrows.h:84
std::string targetHorizontal
Text for the horizontal target of an arrow.
Definition EdgeArrows.h:87
std::string sourceThenDown
Text for an arrow leaving a vertex and turning downward.
Definition EdgeArrows.h:80
size_t charactersPerColumn
Number of characters per arrow column.
Definition EdgeArrows.h:78
std::string downToTarget
Text for an arrow comming from above into a vertex.
Definition EdgeArrows.h:83
std::string verticalLine
Text for the vertical line part of an arrow.
Definition EdgeArrows.h:82
std::string blank
Text when there's lack of any arrow.
Definition EdgeArrows.h:85
std::string sourceThenUp
Text for an arrow leaving a vertex and turning upward.
Definition EdgeArrows.h:81
bool pointsRight
Arrows point right? Otherwise left.
Definition EdgeArrows.h:79