svf-lib 1.0.1291 → 1.0.1292

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,188 @@
1
+ //===-- Graphs/DOTGraphTraits.h - Customize .dot output ---*- C++ -*-===//
2
+ //
3
+ // From the LLVM Project with some modifications, under the Apache License v2.0
4
+ // with LLVM Exceptions. See https://llvm.org/LICENSE.txt for license information.
5
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
+ //
7
+ //===----------------------------------------------------------------------===//
8
+ //
9
+ // This file defines a template class that can be used to customize dot output
10
+ // graphs generated by the GraphWriter.h file. The default implementation of
11
+ // this file will produce a simple, but not very polished graph. By
12
+ // specializing this template, lots of customization opportunities are possible.
13
+ //
14
+ //===----------------------------------------------------------------------===//
15
+
16
+ #ifndef LLVM_SUPPORT_DOTGRAPHTRAITS_H
17
+ #define LLVM_SUPPORT_DOTGRAPHTRAITS_H
18
+
19
+ #include <string>
20
+
21
+ namespace llvm
22
+ {
23
+
24
+ /// DefaultDOTGraphTraits - This class provides the default implementations of
25
+ /// all of the DOTGraphTraits methods. If a specialization does not need to
26
+ /// override all methods here it should inherit so that it can get the default
27
+ /// implementations.
28
+ ///
29
+ struct DefaultDOTGraphTraits
30
+ {
31
+ private:
32
+ bool IsSimple;
33
+
34
+ protected:
35
+ bool isSimple()
36
+ {
37
+ return IsSimple;
38
+ }
39
+
40
+ public:
41
+ explicit DefaultDOTGraphTraits(bool simple=false) : IsSimple (simple) {}
42
+
43
+ /// getGraphName - Return the label for the graph as a whole. Printed at the
44
+ /// top of the graph.
45
+ ///
46
+ template<typename GraphType>
47
+ static std::string getGraphName(const GraphType &)
48
+ {
49
+ return "";
50
+ }
51
+
52
+ /// getGraphProperties - Return any custom properties that should be included
53
+ /// in the top level graph structure for dot.
54
+ ///
55
+ template<typename GraphType>
56
+ static std::string getGraphProperties(const GraphType &)
57
+ {
58
+ return "";
59
+ }
60
+
61
+ /// renderGraphFromBottomUp - If this function returns true, the graph is
62
+ /// emitted bottom-up instead of top-down. This requires graphviz 2.0 to work
63
+ /// though.
64
+ static bool renderGraphFromBottomUp()
65
+ {
66
+ return false;
67
+ }
68
+
69
+ /// isNodeHidden - If the function returns true, the given node is not
70
+ /// displayed in the graph.
71
+ template <typename GraphType>
72
+ static bool isNodeHidden(const void *, const GraphType &)
73
+ {
74
+ return false;
75
+ }
76
+
77
+ /// getNodeLabel - Given a node and a pointer to the top level graph, return
78
+ /// the label to print in the node.
79
+ template<typename GraphType>
80
+ std::string getNodeLabel(const void *, const GraphType &)
81
+ {
82
+ return "";
83
+ }
84
+
85
+ // getNodeIdentifierLabel - Returns a string representing the
86
+ // address or other unique identifier of the node. (Only used if
87
+ // non-empty.)
88
+ template <typename GraphType>
89
+ static std::string getNodeIdentifierLabel(const void *, const GraphType &)
90
+ {
91
+ return "";
92
+ }
93
+
94
+ template<typename GraphType>
95
+ static std::string getNodeDescription(const void *, const GraphType &)
96
+ {
97
+ return "";
98
+ }
99
+
100
+ /// If you want to specify custom node attributes, this is the place to do so
101
+ ///
102
+ template<typename GraphType>
103
+ static std::string getNodeAttributes(const void *,
104
+ const GraphType &)
105
+ {
106
+ return "";
107
+ }
108
+
109
+ /// If you want to override the dot attributes printed for a particular edge,
110
+ /// override this method.
111
+ template<typename EdgeIter, typename GraphType>
112
+ static std::string getEdgeAttributes(const void *, EdgeIter,
113
+ const GraphType &)
114
+ {
115
+ return "";
116
+ }
117
+
118
+ /// getEdgeSourceLabel - If you want to label the edge source itself,
119
+ /// implement this method.
120
+ template<typename EdgeIter>
121
+ static std::string getEdgeSourceLabel(const void *, EdgeIter)
122
+ {
123
+ return "";
124
+ }
125
+
126
+ /// edgeTargetsEdgeSource - This method returns true if this outgoing edge
127
+ /// should actually target another edge source, not a node. If this method is
128
+ /// implemented, getEdgeTarget should be implemented.
129
+ template<typename EdgeIter>
130
+ static bool edgeTargetsEdgeSource(const void *, EdgeIter)
131
+ {
132
+ return false;
133
+ }
134
+
135
+ /// getEdgeTarget - If edgeTargetsEdgeSource returns true, this method is
136
+ /// called to determine which outgoing edge of Node is the target of this
137
+ /// edge.
138
+ template<typename EdgeIter>
139
+ static EdgeIter getEdgeTarget(const void *, EdgeIter I)
140
+ {
141
+ return I;
142
+ }
143
+
144
+ /// hasEdgeDestLabels - If this function returns true, the graph is able
145
+ /// to provide labels for edge destinations.
146
+ static bool hasEdgeDestLabels()
147
+ {
148
+ return false;
149
+ }
150
+
151
+ /// numEdgeDestLabels - If hasEdgeDestLabels, this function returns the
152
+ /// number of incoming edge labels the given node has.
153
+ static unsigned numEdgeDestLabels(const void *)
154
+ {
155
+ return 0;
156
+ }
157
+
158
+ /// getEdgeDestLabel - If hasEdgeDestLabels, this function returns the
159
+ /// incoming edge label with the given index in the given node.
160
+ static std::string getEdgeDestLabel(const void *, unsigned)
161
+ {
162
+ return "";
163
+ }
164
+
165
+ /// addCustomGraphFeatures - If a graph is made up of more than just
166
+ /// straight-forward nodes and edges, this is the place to put all of the
167
+ /// custom stuff necessary. The GraphWriter object, instantiated with your
168
+ /// GraphType is passed in as an argument. You may call arbitrary methods on
169
+ /// it to add things to the output graph.
170
+ ///
171
+ template<typename GraphType, typename GraphWriter>
172
+ static void addCustomGraphFeatures(const GraphType &, GraphWriter &) {}
173
+ };
174
+
175
+
176
+ /// DOTGraphTraits - Template class that can be specialized to customize how
177
+ /// graphs are converted to 'dot' graphs. When specializing, you may inherit
178
+ /// from DefaultDOTGraphTraits if you don't need to override everything.
179
+ ///
180
+ template <typename Ty>
181
+ struct DOTGraphTraits : public DefaultDOTGraphTraits
182
+ {
183
+ DOTGraphTraits (bool simple=false) : DefaultDOTGraphTraits (simple) {}
184
+ };
185
+
186
+ } // End llvm namespace
187
+
188
+ #endif
@@ -31,6 +31,7 @@
31
31
  #define GENERICGRAPH_H_
32
32
 
33
33
  #include "SVFIR/SVFValue.h"
34
+ #include "Util/iterator.h"
34
35
 
35
36
  namespace SVF
36
37
  {
@@ -452,6 +453,44 @@ public:
452
453
  namespace llvm
453
454
  {
454
455
 
456
+ // mapped_iter - This is a simple iterator adapter that causes a function to
457
+ // be applied whenever operator* is invoked on the iterator.
458
+
459
+ template <typename ItTy, typename FuncTy,
460
+ typename FuncReturnTy =
461
+ decltype(std::declval<FuncTy>()(*std::declval<ItTy>()))>
462
+ class mapped_iter
463
+ : public iterator_adaptor_base<
464
+ mapped_iter<ItTy, FuncTy>, ItTy,
465
+ typename std::iterator_traits<ItTy>::iterator_category,
466
+ typename std::remove_reference<FuncReturnTy>::type>
467
+ {
468
+ public:
469
+ mapped_iter(ItTy U, FuncTy F)
470
+ : mapped_iter::iterator_adaptor_base(std::move(U)), F(std::move(F)) {}
471
+
472
+ ItTy getCurrent()
473
+ {
474
+ return this->I;
475
+ }
476
+
477
+ FuncReturnTy operator*() const
478
+ {
479
+ return F(*this->I);
480
+ }
481
+
482
+ private:
483
+ FuncTy F;
484
+ };
485
+
486
+ // map_iter - Provide a convenient way to create mapped_iters, just like
487
+ // make_pair is useful for creating pairs...
488
+ template <class ItTy, class FuncTy>
489
+ inline mapped_iter<ItTy, FuncTy> map_iter(ItTy I, FuncTy F)
490
+ {
491
+ return mapped_iter<ItTy, FuncTy>(std::move(I), std::move(F));
492
+ }
493
+
455
494
  /*!
456
495
  * GraphTraits for nodes
457
496
  */
@@ -466,7 +505,7 @@ template<class NodeTy,class EdgeTy> struct GraphTraits<SVF::GenericNode<NodeTy,E
466
505
  }
467
506
 
468
507
  // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
469
- typedef mapped_iterator<typename SVF::GenericNode<NodeTy,EdgeTy>::iterator, decltype(&edge_dest)> ChildIteratorType;
508
+ typedef mapped_iter<typename SVF::GenericNode<NodeTy,EdgeTy>::iterator, decltype(&edge_dest)> ChildIteratorType;
470
509
 
471
510
  static NodeType* getEntryNode(NodeType* pagN)
472
511
  {
@@ -475,19 +514,19 @@ template<class NodeTy,class EdgeTy> struct GraphTraits<SVF::GenericNode<NodeTy,E
475
514
 
476
515
  static inline ChildIteratorType child_begin(const NodeType* N)
477
516
  {
478
- return map_iterator(N->OutEdgeBegin(), &edge_dest);
517
+ return map_iter(N->OutEdgeBegin(), &edge_dest);
479
518
  }
480
519
  static inline ChildIteratorType child_end(const NodeType* N)
481
520
  {
482
- return map_iterator(N->OutEdgeEnd(), &edge_dest);
521
+ return map_iter(N->OutEdgeEnd(), &edge_dest);
483
522
  }
484
523
  static inline ChildIteratorType direct_child_begin(const NodeType *N)
485
524
  {
486
- return map_iterator(N->directOutEdgeBegin(), &edge_dest);
525
+ return map_iter(N->directOutEdgeBegin(), &edge_dest);
487
526
  }
488
527
  static inline ChildIteratorType direct_child_end(const NodeType *N)
489
528
  {
490
- return map_iterator(N->directOutEdgeEnd(), &edge_dest);
529
+ return map_iter(N->directOutEdgeEnd(), &edge_dest);
491
530
  }
492
531
  };
493
532
 
@@ -506,7 +545,7 @@ struct GraphTraits<Inverse<SVF::GenericNode<NodeTy,EdgeTy>* > >
506
545
  }
507
546
 
508
547
  // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
509
- typedef mapped_iterator<typename SVF::GenericNode<NodeTy,EdgeTy>::iterator, decltype(&edge_dest)> ChildIteratorType;
548
+ typedef mapped_iter<typename SVF::GenericNode<NodeTy,EdgeTy>::iterator, decltype(&edge_dest)> ChildIteratorType;
510
549
 
511
550
  static inline NodeType* getEntryNode(Inverse<NodeType* > G)
512
551
  {
@@ -515,11 +554,11 @@ struct GraphTraits<Inverse<SVF::GenericNode<NodeTy,EdgeTy>* > >
515
554
 
516
555
  static inline ChildIteratorType child_begin(const NodeType* N)
517
556
  {
518
- return map_iterator(N->InEdgeBegin(), &edge_dest);
557
+ return map_iter(N->InEdgeBegin(), &edge_dest);
519
558
  }
520
559
  static inline ChildIteratorType child_end(const NodeType* N)
521
560
  {
522
- return map_iterator(N->InEdgeEnd(), &edge_dest);
561
+ return map_iter(N->InEdgeEnd(), &edge_dest);
523
562
  }
524
563
 
525
564
  static inline unsigned getNodeID(const NodeType* N)
@@ -549,15 +588,15 @@ template<class NodeTy,class EdgeTy> struct GraphTraits<SVF::GenericGraph<NodeTy,
549
588
  }
550
589
 
551
590
  // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
552
- typedef mapped_iterator<typename GenericGraphTy::iterator, decltype(&deref_val)> nodes_iterator;
591
+ typedef mapped_iter<typename GenericGraphTy::iterator, decltype(&deref_val)> nodes_iterator;
553
592
 
554
593
  static nodes_iterator nodes_begin(GenericGraphTy *G)
555
594
  {
556
- return map_iterator(G->begin(), &deref_val);
595
+ return map_iter(G->begin(), &deref_val);
557
596
  }
558
597
  static nodes_iterator nodes_end(GenericGraphTy *G)
559
598
  {
560
- return map_iterator(G->end(), &deref_val);
599
+ return map_iter(G->end(), &deref_val);
561
600
  }
562
601
 
563
602
  static unsigned graphSize(GenericGraphTy* G)
@@ -32,10 +32,8 @@
32
32
  #define INCLUDE_GRAPHS_GRAPHPRINTER_H_
33
33
 
34
34
  #include <system_error>
35
- #include <llvm/Support/ToolOutputFile.h>
36
- #include <llvm/Support/GraphWriter.h> // for graph write
37
- #include <llvm/Support/FileSystem.h> // for file open flag
38
- #include <llvm/ADT/GraphTraits.h>
35
+ #include "Graphs/GraphWriter.h" // for graph write
36
+ #include <fstream>
39
37
 
40
38
  namespace llvm
41
39
  {
@@ -60,24 +58,18 @@ public:
60
58
  {
61
59
  // Filename of the output dot file
62
60
  std::string Filename = GraphName + ".dot";
63
- O << "Writing '" << Filename << "'...";
64
- std::error_code ErrInfo;
65
- llvm::ToolOutputFile F(Filename.c_str(), ErrInfo, llvm::sys::fs::OF_None);
66
-
67
- if (!ErrInfo)
61
+ std::ofstream outFile(Filename);
62
+ if (outFile.fail())
68
63
  {
69
- // dump the ValueFlowGraph here
70
- WriteGraph(F.os(), GT, simple);
71
- F.os().close();
72
- if (!F.os().has_error())
73
- {
74
- O << "\n";
75
- F.keep();
76
- return;
77
- }
64
+ O << " error opening file for writing!\n";
65
+ outFile.close();
66
+ return;
78
67
  }
79
- O << " error opening file for writing!\n";
80
- F.os().clear_error();
68
+
69
+ O << "Writing '" << Filename << "'...";
70
+
71
+ WriteGraph(outFile, GT, simple);
72
+ outFile.close();
81
73
  }
82
74
 
83
75
  /*!
@@ -0,0 +1,150 @@
1
+ //===- llvm/ADT/GraphTraits.h - Graph traits template -----------*- C++ -*-===//
2
+ //
3
+ // From the LLVM Project with some modifications, under the Apache License v2.0
4
+ // with LLVM Exceptions. See https://llvm.org/LICENSE.txt for license information.
5
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
+ //
7
+ //===----------------------------------------------------------------------===//
8
+ //
9
+ // This file defines the little GraphTraits<X> template class that should be
10
+ // specialized by classes that want to be iteratable by generic graph iterators.
11
+ //
12
+ // This file also defines the marker class Inverse that is used to iterate over
13
+ // graphs in a graph defined, inverse ordering...
14
+ //
15
+ //===----------------------------------------------------------------------===//
16
+
17
+ #ifndef LLVM_ADT_GRAPHTRAITS_H
18
+ #define LLVM_ADT_GRAPHTRAITS_H
19
+
20
+ #include "Util/iterator_range.h"
21
+
22
+ namespace llvm
23
+ {
24
+
25
+ // GraphTraits - This class should be specialized by different graph types...
26
+ // which is why the default version is empty.
27
+ //
28
+ // This template evolved from supporting `BasicBlock` to also later supporting
29
+ // more complex types (e.g. CFG and DomTree).
30
+ //
31
+ // GraphTraits can be used to create a view over a graph interpreting it
32
+ // differently without requiring a copy of the original graph. This could
33
+ // be achieved by carrying more data in NodeRef. See LoopBodyTraits for one
34
+ // example.
35
+ template<class GraphType>
36
+ struct GraphTraits
37
+ {
38
+ // Elements to provide:
39
+
40
+ // typedef NodeRef - Type of Node token in the graph, which should
41
+ // be cheap to copy.
42
+ // typedef ChildIteratorType - Type used to iterate over children in graph,
43
+ // dereference to a NodeRef.
44
+
45
+ // static NodeRef getEntryNode(const GraphType &)
46
+ // Return the entry node of the graph
47
+
48
+ // static ChildIteratorType child_begin(NodeRef)
49
+ // static ChildIteratorType child_end (NodeRef)
50
+ // Return iterators that point to the beginning and ending of the child
51
+ // node list for the specified node.
52
+
53
+ // typedef ...iterator nodes_iterator; - dereference to a NodeRef
54
+ // static nodes_iterator nodes_begin(GraphType *G)
55
+ // static nodes_iterator nodes_end (GraphType *G)
56
+ // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
57
+
58
+ // typedef EdgeRef - Type of Edge token in the graph, which should
59
+ // be cheap to copy.
60
+ // typedef ChildEdgeIteratorType - Type used to iterate over children edges in
61
+ // graph, dereference to a EdgeRef.
62
+
63
+ // static ChildEdgeIteratorType child_edge_begin(NodeRef)
64
+ // static ChildEdgeIteratorType child_edge_end(NodeRef)
65
+ // Return iterators that point to the beginning and ending of the
66
+ // edge list for the given callgraph node.
67
+ //
68
+ // static NodeRef edge_dest(EdgeRef)
69
+ // Return the destination node of an edge.
70
+
71
+ // static unsigned size (GraphType *G)
72
+ // Return total number of nodes in the graph
73
+
74
+ // If anyone tries to use this class without having an appropriate
75
+ // specialization, make an error. If you get this error, it's because you
76
+ // need to include the appropriate specialization of GraphTraits<> for your
77
+ // graph, or you need to define it for a new graph type. Either that or
78
+ // your argument to XXX_begin(...) is unknown or needs to have the proper .h
79
+ // file #include'd.
80
+ using NodeRef = typename GraphType::UnknownGraphTypeError;
81
+ };
82
+
83
+ // Inverse - This class is used as a little marker class to tell the graph
84
+ // iterator to iterate over the graph in a graph defined "Inverse" ordering.
85
+ // Not all graphs define an inverse ordering, and if they do, it depends on
86
+ // the graph exactly what that is. Here's an example of usage with the
87
+ // df_iterator:
88
+ //
89
+ // idf_iterator<Method*> I = idf_begin(M), E = idf_end(M);
90
+ // for (; I != E; ++I) { ... }
91
+ //
92
+ // Which is equivalent to:
93
+ // df_iterator<Inverse<Method*>> I = idf_begin(M), E = idf_end(M);
94
+ // for (; I != E; ++I) { ... }
95
+ //
96
+ template <class GraphType>
97
+ struct Inverse
98
+ {
99
+ const GraphType &Graph;
100
+
101
+ inline Inverse(const GraphType &G) : Graph(G) {}
102
+ };
103
+
104
+ // Provide a partial specialization of GraphTraits so that the inverse of an
105
+ // inverse falls back to the original graph.
106
+ template <class T> struct GraphTraits<Inverse<Inverse<T>>> : GraphTraits<T> {};
107
+
108
+ // Provide iterator ranges for the graph traits nodes and children
109
+ template <class GraphType>
110
+ iterator_range<typename GraphTraits<GraphType>::nodes_iterator>
111
+ nodes(const GraphType &G)
112
+ {
113
+ return make_range(GraphTraits<GraphType>::nodes_begin(G),
114
+ GraphTraits<GraphType>::nodes_end(G));
115
+ }
116
+ template <class GraphType>
117
+ iterator_range<typename GraphTraits<Inverse<GraphType>>::nodes_iterator>
118
+ inverse_nodes(const GraphType &G)
119
+ {
120
+ return make_range(GraphTraits<Inverse<GraphType>>::nodes_begin(G),
121
+ GraphTraits<Inverse<GraphType>>::nodes_end(G));
122
+ }
123
+
124
+ template <class GraphType>
125
+ iterator_range<typename GraphTraits<GraphType>::ChildIteratorType>
126
+ children(const typename GraphTraits<GraphType>::NodeRef &G)
127
+ {
128
+ return make_range(GraphTraits<GraphType>::child_begin(G),
129
+ GraphTraits<GraphType>::child_end(G));
130
+ }
131
+
132
+ template <class GraphType>
133
+ iterator_range<typename GraphTraits<Inverse<GraphType>>::ChildIteratorType>
134
+ inverse_children(const typename GraphTraits<GraphType>::NodeRef &G)
135
+ {
136
+ return make_range(GraphTraits<Inverse<GraphType>>::child_begin(G),
137
+ GraphTraits<Inverse<GraphType>>::child_end(G));
138
+ }
139
+
140
+ template <class GraphType>
141
+ iterator_range<typename GraphTraits<GraphType>::ChildEdgeIteratorType>
142
+ children_edges(const typename GraphTraits<GraphType>::NodeRef &G)
143
+ {
144
+ return make_range(GraphTraits<GraphType>::child_edge_begin(G),
145
+ GraphTraits<GraphType>::child_edge_end(G));
146
+ }
147
+
148
+ } // end namespace llvm
149
+
150
+ #endif // LLVM_ADT_GRAPHTRAITS_H
@@ -0,0 +1,380 @@
1
+ //===- Graphs/GraphWriter.h - Write graph to a .dot file --*- C++ -*-===//
2
+ //
3
+ // From the LLVM Project with some modifications, under the Apache License v2.0
4
+ // with LLVM Exceptions. See https://llvm.org/LICENSE.txt for license information.
5
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
+ //
7
+ //===----------------------------------------------------------------------===//
8
+ //
9
+ // This file defines a simple interface that can be used to print out generic
10
+ // LLVM graphs to ".dot" files. "dot" is a tool that is part of the AT&T
11
+ // graphviz package (http://www.research.att.com/sw/tools/graphviz/) which can
12
+ // be used to turn the files output by this interface into a variety of
13
+ // different graphics formats.
14
+ //
15
+ // Graphs do not need to implement any interface past what is already required
16
+ // by the GraphTraits template, but they can choose to implement specializations
17
+ // of the DOTGraphTraits template if they want to customize the graphs output in
18
+ // any way.
19
+ //
20
+ //===----------------------------------------------------------------------===//
21
+
22
+ #ifndef LLVM_SUPPORT_GRAPHWRITER_H
23
+ #define LLVM_SUPPORT_GRAPHWRITER_H
24
+
25
+ #include "Graphs/GraphTraits.h"
26
+ #include "Graphs/DOTGraphTraits.h"
27
+ #include <algorithm>
28
+ #include <cstddef>
29
+ #include <iterator>
30
+ #include <string>
31
+ #include <type_traits>
32
+ #include <vector>
33
+ #include <fstream>
34
+ #include <sstream>
35
+ #include <iostream>
36
+
37
+ namespace llvm
38
+ {
39
+
40
+ namespace DOT // Private functions...
41
+ {
42
+
43
+ std::string EscapeStr(const std::string &Label);
44
+
45
+ } // end namespace DOT
46
+
47
+ namespace GraphProgram
48
+ {
49
+
50
+ enum Name
51
+ {
52
+ DOT,
53
+ FDP,
54
+ NEATO,
55
+ TWOPI,
56
+ CIRCO
57
+ };
58
+
59
+ } // end namespace GraphProgram
60
+
61
+ template<typename GraphType>
62
+ class GraphWriter
63
+ {
64
+ std::ofstream &O;
65
+ const GraphType &G;
66
+
67
+ using DOTTraits = DOTGraphTraits<GraphType>;
68
+ using GTraits = GraphTraits<GraphType>;
69
+ using NodeRef = typename GTraits::NodeRef;
70
+ using node_iterator = typename GTraits::nodes_iterator;
71
+ using child_iterator = typename GTraits::ChildIteratorType;
72
+ DOTTraits DTraits;
73
+
74
+ static_assert(std::is_pointer<NodeRef>::value,
75
+ "FIXME: Currently GraphWriter requires the NodeRef type to be "
76
+ "a pointer.\nThe pointer usage should be moved to "
77
+ "DOTGraphTraits, and removed from GraphWriter itself.");
78
+
79
+ // Writes the edge labels of the node to O and returns true if there are any
80
+ // edge labels not equal to the empty string "".
81
+ bool getEdgeSourceLabels(std::stringstream &O2, NodeRef Node)
82
+ {
83
+ child_iterator EI = GTraits::child_begin(Node);
84
+ child_iterator EE = GTraits::child_end(Node);
85
+ bool hasEdgeSourceLabels = false;
86
+
87
+ for (unsigned i = 0; EI != EE && i != 64; ++EI, ++i)
88
+ {
89
+ std::string label = DTraits.getEdgeSourceLabel(Node, EI);
90
+
91
+ if (label.empty())
92
+ continue;
93
+
94
+ hasEdgeSourceLabels = true;
95
+
96
+ if (i)
97
+ O2 << "|";
98
+
99
+ O2 << "<s" << i << ">" << DOT::EscapeStr(label);
100
+ }
101
+
102
+ if (EI != EE && hasEdgeSourceLabels)
103
+ O2 << "|<s64>truncated...";
104
+
105
+ return hasEdgeSourceLabels;
106
+ }
107
+
108
+ public:
109
+ GraphWriter(std::ofstream &o, const GraphType &g, bool SN) : O(o), G(g)
110
+ {
111
+ DTraits = DOTTraits(SN);
112
+ }
113
+
114
+ void writeGraph(const std::string &Title = "")
115
+ {
116
+ // Output the header for the graph...
117
+ writeHeader(Title);
118
+
119
+ // Emit all of the nodes in the graph...
120
+ writeNodes();
121
+
122
+ // Output any customizations on the graph
123
+ DOTGraphTraits<GraphType>::addCustomGraphFeatures(G, *this);
124
+
125
+ // Output the end of the graph
126
+ writeFooter();
127
+ }
128
+
129
+ void writeHeader(const std::string &Title)
130
+ {
131
+ std::string GraphName(DTraits.getGraphName(G));
132
+
133
+ if (!Title.empty())
134
+ O << "digraph \"" << DOT::EscapeStr(Title) << "\" {\n";
135
+ else if (!GraphName.empty())
136
+ O << "digraph \"" << DOT::EscapeStr(GraphName) << "\" {\n";
137
+ else
138
+ O << "digraph unnamed {\n";
139
+
140
+ if (DTraits.renderGraphFromBottomUp())
141
+ O << "\trankdir=\"BT\";\n";
142
+
143
+ if (!Title.empty())
144
+ O << "\tlabel=\"" << DOT::EscapeStr(Title) << "\";\n";
145
+ else if (!GraphName.empty())
146
+ O << "\tlabel=\"" << DOT::EscapeStr(GraphName) << "\";\n";
147
+ O << DTraits.getGraphProperties(G);
148
+ O << "\n";
149
+ }
150
+
151
+ void writeFooter()
152
+ {
153
+ // Finish off the graph
154
+ O << "}\n";
155
+ }
156
+
157
+ void writeNodes()
158
+ {
159
+ // Loop over the graph, printing it out...
160
+ for (const auto Node : nodes<GraphType>(G))
161
+ if (!isNodeHidden(Node))
162
+ writeNode(Node);
163
+ }
164
+
165
+ bool isNodeHidden(NodeRef Node)
166
+ {
167
+ return DTraits.isNodeHidden(Node, G);
168
+ }
169
+
170
+ void writeNode(NodeRef Node)
171
+ {
172
+ std::string NodeAttributes = DTraits.getNodeAttributes(Node, G);
173
+
174
+ O << "\tNode" << static_cast<const void*>(Node) << " [shape=record,";
175
+ if (!NodeAttributes.empty()) O << NodeAttributes << ",";
176
+ O << "label=\"{";
177
+
178
+ if (!DTraits.renderGraphFromBottomUp())
179
+ {
180
+ O << DOT::EscapeStr(DTraits.getNodeLabel(Node, G));
181
+
182
+ // If we should include the address of the node in the label, do so now.
183
+ std::string Id = DTraits.getNodeIdentifierLabel(Node, G);
184
+ if (!Id.empty())
185
+ O << "|" << DOT::EscapeStr(Id);
186
+
187
+ std::string NodeDesc = DTraits.getNodeDescription(Node, G);
188
+ if (!NodeDesc.empty())
189
+ O << "|" << DOT::EscapeStr(NodeDesc);
190
+ }
191
+
192
+ std::string edgeSourceLabels;
193
+ std::stringstream EdgeSourceLabels(edgeSourceLabels);
194
+ bool hasEdgeSourceLabels = getEdgeSourceLabels(EdgeSourceLabels, Node);
195
+
196
+ if (hasEdgeSourceLabels)
197
+ {
198
+ if (!DTraits.renderGraphFromBottomUp()) O << "|";
199
+
200
+ O << "{" << EdgeSourceLabels.str() << "}";
201
+
202
+ if (DTraits.renderGraphFromBottomUp()) O << "|";
203
+ }
204
+
205
+ if (DTraits.renderGraphFromBottomUp())
206
+ {
207
+ O << DOT::EscapeStr(DTraits.getNodeLabel(Node, G));
208
+
209
+ // If we should include the address of the node in the label, do so now.
210
+ std::string Id = DTraits.getNodeIdentifierLabel(Node, G);
211
+ if (!Id.empty())
212
+ O << "|" << DOT::EscapeStr(Id);
213
+
214
+ std::string NodeDesc = DTraits.getNodeDescription(Node, G);
215
+ if (!NodeDesc.empty())
216
+ O << "|" << DOT::EscapeStr(NodeDesc);
217
+ }
218
+
219
+ if (DTraits.hasEdgeDestLabels())
220
+ {
221
+ O << "|{";
222
+
223
+ unsigned i = 0, e = DTraits.numEdgeDestLabels(Node);
224
+ for (; i != e && i != 64; ++i)
225
+ {
226
+ if (i) O << "|";
227
+ O << "<d" << i << ">"
228
+ << DOT::EscapeStr(DTraits.getEdgeDestLabel(Node, i));
229
+ }
230
+
231
+ if (i != e)
232
+ O << "|<d64>truncated...";
233
+ O << "}";
234
+ }
235
+
236
+ O << "}\"];\n"; // Finish printing the "node" line
237
+
238
+ // Output all of the edges now
239
+ child_iterator EI = GTraits::child_begin(Node);
240
+ child_iterator EE = GTraits::child_end(Node);
241
+ for (unsigned i = 0; EI != EE && i != 64; ++EI, ++i)
242
+ if (!DTraits.isNodeHidden(*EI, G))
243
+ writeEdge(Node, i, EI);
244
+ for (; EI != EE; ++EI)
245
+ if (!DTraits.isNodeHidden(*EI, G))
246
+ writeEdge(Node, 64, EI);
247
+ }
248
+
249
+ void writeEdge(NodeRef Node, unsigned edgeidx, child_iterator EI)
250
+ {
251
+ if (NodeRef TargetNode = *EI)
252
+ {
253
+ int DestPort = -1;
254
+ if (DTraits.edgeTargetsEdgeSource(Node, EI))
255
+ {
256
+ child_iterator TargetIt = DTraits.getEdgeTarget(Node, EI);
257
+
258
+ // Figure out which edge this targets...
259
+ unsigned Offset =
260
+ (unsigned)std::distance(GTraits::child_begin(TargetNode), TargetIt);
261
+ DestPort = static_cast<int>(Offset);
262
+ }
263
+
264
+ if (DTraits.getEdgeSourceLabel(Node, EI).empty())
265
+ edgeidx = -1;
266
+
267
+ emitEdge(static_cast<const void*>(Node), edgeidx,
268
+ static_cast<const void*>(TargetNode), DestPort,
269
+ DTraits.getEdgeAttributes(Node, EI, G));
270
+ }
271
+ }
272
+
273
+ /// emitSimpleNode - Outputs a simple (non-record) node
274
+ void emitSimpleNode(const void *ID, const std::string &Attr,
275
+ const std::string &Label, unsigned NumEdgeSources = 0,
276
+ const std::vector<std::string> *EdgeSourceLabels = nullptr)
277
+ {
278
+ O << "\tNode" << ID << "[ ";
279
+ if (!Attr.empty())
280
+ O << Attr << ",";
281
+ O << " label =\"";
282
+ if (NumEdgeSources) O << "{";
283
+ O << DOT::EscapeStr(Label);
284
+ if (NumEdgeSources)
285
+ {
286
+ O << "|{";
287
+
288
+ for (unsigned i = 0; i != NumEdgeSources; ++i)
289
+ {
290
+ if (i) O << "|";
291
+ O << "<s" << i << ">";
292
+ if (EdgeSourceLabels) O << DOT::EscapeStr((*EdgeSourceLabels)[i]);
293
+ }
294
+ O << "}}";
295
+ }
296
+ O << "\"];\n";
297
+ }
298
+
299
+ /// emitEdge - Output an edge from a simple node into the graph...
300
+ void emitEdge(const void *SrcNodeID, int SrcNodePort,
301
+ const void *DestNodeID, int DestNodePort,
302
+ const std::string &Attrs)
303
+ {
304
+ if (SrcNodePort > 64) return; // Eminating from truncated part?
305
+ if (DestNodePort > 64) DestNodePort = 64; // Targeting the truncated part?
306
+
307
+ O << "\tNode" << SrcNodeID;
308
+ if (SrcNodePort >= 0)
309
+ O << ":s" << SrcNodePort;
310
+ O << " -> Node" << DestNodeID;
311
+ if (DestNodePort >= 0 && DTraits.hasEdgeDestLabels())
312
+ O << ":d" << DestNodePort;
313
+
314
+ if (!Attrs.empty())
315
+ O << "[" << Attrs << "]";
316
+ O << ";\n";
317
+ }
318
+
319
+ /// getOStream - Get the raw output stream into the graph file. Useful to
320
+ /// write fancy things using addCustomGraphFeatures().
321
+ std::ofstream &getOStream()
322
+ {
323
+ return O;
324
+ }
325
+ };
326
+
327
+ template<typename GraphType>
328
+ std::ofstream &WriteGraph(std::ofstream &O, const GraphType &G,
329
+ bool ShortNames = false)
330
+ {
331
+ // Start the graph emission process...
332
+ GraphWriter<GraphType> W(O, G, ShortNames);
333
+
334
+ // Emit the graph.
335
+ W.writeGraph("");
336
+
337
+ return O;
338
+ }
339
+
340
+ /// Writes graph into a provided @c Filename.
341
+ /// If @c Filename is empty, generates a random one.
342
+ /// \return The resulting filename, or an empty string if writing
343
+ /// failed.
344
+ template <typename GraphType>
345
+ std::string WriteGraph(const GraphType &G,
346
+ bool ShortNames = false,
347
+ std::string Filename = "")
348
+ {
349
+
350
+ std::ofstream O(Filename);
351
+
352
+ if (O.fail())
353
+ {
354
+ std::cerr << "error opening file '" << Filename << "' for writing!\n";
355
+ O.close();
356
+ return "";
357
+ }
358
+
359
+ llvm::WriteGraph(O, G, ShortNames);
360
+ O.close();
361
+
362
+ std::cerr << " done. \n";
363
+
364
+ return Filename;
365
+ }
366
+
367
+ /// ViewGraph - Emit a dot graph, run 'dot', run gv on the postscript file,
368
+ /// then cleanup. For use from the debugger.
369
+ ///
370
+ template<typename GraphType>
371
+ void ViewGraph(const GraphType &G,const std::string& name,
372
+ bool ShortNames = false,
373
+ GraphProgram::Name Program = GraphProgram::DOT)
374
+ {
375
+ llvm::WriteGraph(G, ShortNames);
376
+ }
377
+
378
+ } // end namespace llvm
379
+
380
+ #endif // LLVM_SUPPORT_GRAPHWRITER_H
@@ -0,0 +1,407 @@
1
+ //===- iterator.h - Utilities for using and defining iterators --*- C++ -*-===//
2
+ //
3
+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
+ // See https://llvm.org/LICENSE.txt for license information.
5
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
+ //
7
+ //===----------------------------------------------------------------------===//
8
+
9
+ #ifndef LLVM_ADT_ITERATOR_H
10
+ #define LLVM_ADT_ITERATOR_H
11
+
12
+ #include "Util/iterator_range.h"
13
+ #include <cstddef>
14
+ #include <iterator>
15
+ #include <type_traits>
16
+ #include <utility>
17
+
18
+ namespace llvm
19
+ {
20
+
21
+ /// CRTP base class which implements the entire standard iterator facade
22
+ /// in terms of a minimal subset of the interface.
23
+ ///
24
+ /// Use this when it is reasonable to implement most of the iterator
25
+ /// functionality in terms of a core subset. If you need special behavior or
26
+ /// there are performance implications for this, you may want to override the
27
+ /// relevant members instead.
28
+ ///
29
+ /// Note, one abstraction that this does *not* provide is implementing
30
+ /// subtraction in terms of addition by negating the difference. Negation isn't
31
+ /// always information preserving, and I can see very reasonable iterator
32
+ /// designs where this doesn't work well. It doesn't really force much added
33
+ /// boilerplate anyways.
34
+ ///
35
+ /// Another abstraction that this doesn't provide is implementing increment in
36
+ /// terms of addition of one. These aren't equivalent for all iterator
37
+ /// categories, and respecting that adds a lot of complexity for little gain.
38
+ ///
39
+ /// Classes wishing to use `iterator_facade_base` should implement the following
40
+ /// methods:
41
+ ///
42
+ /// Forward Iterators:
43
+ /// (All of the following methods)
44
+ /// - DerivedT &operator=(const DerivedT &R);
45
+ /// - bool operator==(const DerivedT &R) const;
46
+ /// - const T &operator*() const;
47
+ /// - T &operator*();
48
+ /// - DerivedT &operator++();
49
+ ///
50
+ /// Bidirectional Iterators:
51
+ /// (All methods of forward iterators, plus the following)
52
+ /// - DerivedT &operator--();
53
+ ///
54
+ /// Random-access Iterators:
55
+ /// (All methods of bidirectional iterators excluding the following)
56
+ /// - DerivedT &operator++();
57
+ /// - DerivedT &operator--();
58
+ /// (and plus the following)
59
+ /// - bool operator<(const DerivedT &RHS) const;
60
+ /// - DifferenceTypeT operator-(const DerivedT &R) const;
61
+ /// - DerivedT &operator+=(DifferenceTypeT N);
62
+ /// - DerivedT &operator-=(DifferenceTypeT N);
63
+ ///
64
+ template <typename DerivedT, typename IteratorCategoryT, typename T,
65
+ typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *,
66
+ typename ReferenceT = T &>
67
+ class iterator_facade_base
68
+ {
69
+ public:
70
+ using iterator_category = IteratorCategoryT;
71
+ using value_type = T;
72
+ using difference_type = DifferenceTypeT;
73
+ using pointer = PointerT;
74
+ using reference = ReferenceT;
75
+
76
+ protected:
77
+ enum
78
+ {
79
+ IsRandomAccess = std::is_base_of<std::random_access_iterator_tag,
80
+ IteratorCategoryT>::value,
81
+ IsBidirectional = std::is_base_of<std::bidirectional_iterator_tag,
82
+ IteratorCategoryT>::value,
83
+ };
84
+
85
+ /// A proxy object for computing a reference via indirecting a copy of an
86
+ /// iterator. This is used in APIs which need to produce a reference via
87
+ /// indirection but for which the iterator object might be a temporary. The
88
+ /// proxy preserves the iterator internally and exposes the indirected
89
+ /// reference via a conversion operator.
90
+ class ReferenceProxy
91
+ {
92
+ friend iterator_facade_base;
93
+
94
+ DerivedT I;
95
+
96
+ ReferenceProxy(DerivedT I) : I(std::move(I)) {}
97
+
98
+ public:
99
+ operator ReferenceT() const
100
+ {
101
+ return *I;
102
+ }
103
+ };
104
+
105
+ public:
106
+ DerivedT operator+(DifferenceTypeT n) const
107
+ {
108
+ static_assert(std::is_base_of<iterator_facade_base, DerivedT>::value,
109
+ "Must pass the derived type to this template!");
110
+ static_assert(
111
+ IsRandomAccess,
112
+ "The '+' operator is only defined for random access iterators.");
113
+ DerivedT tmp = *static_cast<const DerivedT *>(this);
114
+ tmp += n;
115
+ return tmp;
116
+ }
117
+ friend DerivedT operator+(DifferenceTypeT n, const DerivedT &i)
118
+ {
119
+ static_assert(
120
+ IsRandomAccess,
121
+ "The '+' operator is only defined for random access iterators.");
122
+ return i + n;
123
+ }
124
+ DerivedT operator-(DifferenceTypeT n) const
125
+ {
126
+ static_assert(
127
+ IsRandomAccess,
128
+ "The '-' operator is only defined for random access iterators.");
129
+ DerivedT tmp = *static_cast<const DerivedT *>(this);
130
+ tmp -= n;
131
+ return tmp;
132
+ }
133
+
134
+ DerivedT &operator++()
135
+ {
136
+ static_assert(std::is_base_of<iterator_facade_base, DerivedT>::value,
137
+ "Must pass the derived type to this template!");
138
+ return static_cast<DerivedT *>(this)->operator+=(1);
139
+ }
140
+ DerivedT operator++(int)
141
+ {
142
+ DerivedT tmp = *static_cast<DerivedT *>(this);
143
+ ++*static_cast<DerivedT *>(this);
144
+ return tmp;
145
+ }
146
+ DerivedT &operator--()
147
+ {
148
+ static_assert(
149
+ IsBidirectional,
150
+ "The decrement operator is only defined for bidirectional iterators.");
151
+ return static_cast<DerivedT *>(this)->operator-=(1);
152
+ }
153
+ DerivedT operator--(int)
154
+ {
155
+ static_assert(
156
+ IsBidirectional,
157
+ "The decrement operator is only defined for bidirectional iterators.");
158
+ DerivedT tmp = *static_cast<DerivedT *>(this);
159
+ --*static_cast<DerivedT *>(this);
160
+ return tmp;
161
+ }
162
+
163
+ #ifndef __cpp_impl_three_way_comparison
164
+ bool operator!=(const DerivedT &RHS) const
165
+ {
166
+ return !(static_cast<const DerivedT &>(*this) == RHS);
167
+ }
168
+ #endif
169
+
170
+ bool operator>(const DerivedT &RHS) const
171
+ {
172
+ static_assert(
173
+ IsRandomAccess,
174
+ "Relational operators are only defined for random access iterators.");
175
+ return !(static_cast<const DerivedT &>(*this) < RHS) &&
176
+ !(static_cast<const DerivedT &>(*this) == RHS);
177
+ }
178
+ bool operator<=(const DerivedT &RHS) const
179
+ {
180
+ static_assert(
181
+ IsRandomAccess,
182
+ "Relational operators are only defined for random access iterators.");
183
+ return !(static_cast<const DerivedT &>(*this) > RHS);
184
+ }
185
+ bool operator>=(const DerivedT &RHS) const
186
+ {
187
+ static_assert(
188
+ IsRandomAccess,
189
+ "Relational operators are only defined for random access iterators.");
190
+ return !(static_cast<const DerivedT &>(*this) < RHS);
191
+ }
192
+
193
+ PointerT operator->()
194
+ {
195
+ return &static_cast<DerivedT *>(this)->operator*();
196
+ }
197
+ PointerT operator->() const
198
+ {
199
+ return &static_cast<const DerivedT *>(this)->operator*();
200
+ }
201
+ ReferenceProxy operator[](DifferenceTypeT n)
202
+ {
203
+ static_assert(IsRandomAccess,
204
+ "Subscripting is only defined for random access iterators.");
205
+ return ReferenceProxy(static_cast<DerivedT *>(this)->operator+(n));
206
+ }
207
+ ReferenceProxy operator[](DifferenceTypeT n) const
208
+ {
209
+ static_assert(IsRandomAccess,
210
+ "Subscripting is only defined for random access iterators.");
211
+ return ReferenceProxy(static_cast<const DerivedT *>(this)->operator+(n));
212
+ }
213
+ };
214
+
215
+ /// CRTP base class for adapting an iterator to a different type.
216
+ ///
217
+ /// This class can be used through CRTP to adapt one iterator into another.
218
+ /// Typically this is done through providing in the derived class a custom \c
219
+ /// operator* implementation. Other methods can be overridden as well.
220
+ template <
221
+ typename DerivedT, typename WrappedIteratorT,
222
+ typename IteratorCategoryT =
223
+ typename std::iterator_traits<WrappedIteratorT>::iterator_category,
224
+ typename T = typename std::iterator_traits<WrappedIteratorT>::value_type,
225
+ typename DifferenceTypeT =
226
+ typename std::iterator_traits<WrappedIteratorT>::difference_type,
227
+ typename PointerT = std::conditional_t<
228
+ std::is_same<T, typename std::iterator_traits<
229
+ WrappedIteratorT>::value_type>::value,
230
+ typename std::iterator_traits<WrappedIteratorT>::pointer, T *>,
231
+ typename ReferenceT = std::conditional_t<
232
+ std::is_same<T, typename std::iterator_traits<
233
+ WrappedIteratorT>::value_type>::value,
234
+ typename std::iterator_traits<WrappedIteratorT>::reference, T &>>
235
+ class iterator_adaptor_base
236
+ : public iterator_facade_base<DerivedT, IteratorCategoryT, T,
237
+ DifferenceTypeT, PointerT, ReferenceT>
238
+ {
239
+ using BaseT = typename iterator_adaptor_base::iterator_facade_base;
240
+
241
+ protected:
242
+ WrappedIteratorT I;
243
+
244
+ iterator_adaptor_base() = default;
245
+
246
+ explicit iterator_adaptor_base(WrappedIteratorT u) : I(std::move(u))
247
+ {
248
+ static_assert(std::is_base_of<iterator_adaptor_base, DerivedT>::value,
249
+ "Must pass the derived type to this template!");
250
+ }
251
+
252
+ const WrappedIteratorT &wrapped() const
253
+ {
254
+ return I;
255
+ }
256
+
257
+ public:
258
+ using difference_type = DifferenceTypeT;
259
+
260
+ DerivedT &operator+=(difference_type n)
261
+ {
262
+ static_assert(
263
+ BaseT::IsRandomAccess,
264
+ "The '+=' operator is only defined for random access iterators.");
265
+ I += n;
266
+ return *static_cast<DerivedT *>(this);
267
+ }
268
+ DerivedT &operator-=(difference_type n)
269
+ {
270
+ static_assert(
271
+ BaseT::IsRandomAccess,
272
+ "The '-=' operator is only defined for random access iterators.");
273
+ I -= n;
274
+ return *static_cast<DerivedT *>(this);
275
+ }
276
+ using BaseT::operator-;
277
+ difference_type operator-(const DerivedT &RHS) const
278
+ {
279
+ static_assert(
280
+ BaseT::IsRandomAccess,
281
+ "The '-' operator is only defined for random access iterators.");
282
+ return I - RHS.I;
283
+ }
284
+
285
+ // We have to explicitly provide ++ and -- rather than letting the facade
286
+ // forward to += because WrappedIteratorT might not support +=.
287
+ using BaseT::operator++;
288
+ DerivedT &operator++()
289
+ {
290
+ ++I;
291
+ return *static_cast<DerivedT *>(this);
292
+ }
293
+ using BaseT::operator--;
294
+ DerivedT &operator--()
295
+ {
296
+ static_assert(
297
+ BaseT::IsBidirectional,
298
+ "The decrement operator is only defined for bidirectional iterators.");
299
+ --I;
300
+ return *static_cast<DerivedT *>(this);
301
+ }
302
+
303
+ friend bool operator==(const iterator_adaptor_base &LHS,
304
+ const iterator_adaptor_base &RHS)
305
+ {
306
+ return LHS.I == RHS.I;
307
+ }
308
+ friend bool operator<(const iterator_adaptor_base &LHS,
309
+ const iterator_adaptor_base &RHS)
310
+ {
311
+ static_assert(
312
+ BaseT::IsRandomAccess,
313
+ "Relational operators are only defined for random access iterators.");
314
+ return LHS.I < RHS.I;
315
+ }
316
+
317
+ ReferenceT operator*() const
318
+ {
319
+ return *I;
320
+ }
321
+ };
322
+
323
+ /// An iterator type that allows iterating over the pointees via some
324
+ /// other iterator.
325
+ ///
326
+ /// The typical usage of this is to expose a type that iterates over Ts, but
327
+ /// which is implemented with some iterator over T*s:
328
+ ///
329
+ /// \code
330
+ /// using iterator = pointee_iterator<SmallVectorImpl<T *>::iterator>;
331
+ /// \endcode
332
+ template <typename WrappedIteratorT,
333
+ typename T = std::remove_reference_t<decltype(
334
+ **std::declval<WrappedIteratorT>())>>
335
+ struct pointee_iterator
336
+ : iterator_adaptor_base<
337
+ pointee_iterator<WrappedIteratorT, T>, WrappedIteratorT,
338
+ typename std::iterator_traits<WrappedIteratorT>::iterator_category,
339
+ T>
340
+ {
341
+ pointee_iterator() = default;
342
+ template <typename U>
343
+ pointee_iterator(U &&u)
344
+ : pointee_iterator::iterator_adaptor_base(std::forward<U &&>(u)) {}
345
+
346
+ T &operator*() const
347
+ {
348
+ return **this->I;
349
+ }
350
+ };
351
+
352
+ template <typename RangeT, typename WrappedIteratorT =
353
+ decltype(std::begin(std::declval<RangeT>()))>
354
+ iterator_range<pointee_iterator<WrappedIteratorT>>
355
+ make_pointee_range(RangeT &&Range)
356
+ {
357
+ using PointeeIteratorT = pointee_iterator<WrappedIteratorT>;
358
+ return make_range(PointeeIteratorT(std::begin(std::forward<RangeT>(Range))),
359
+ PointeeIteratorT(std::end(std::forward<RangeT>(Range))));
360
+ }
361
+
362
+ template <typename WrappedIteratorT,
363
+ typename T = decltype(&*std::declval<WrappedIteratorT>())>
364
+ class pointer_iterator
365
+ : public iterator_adaptor_base<
366
+ pointer_iterator<WrappedIteratorT, T>, WrappedIteratorT,
367
+ typename std::iterator_traits<WrappedIteratorT>::iterator_category,
368
+ T>
369
+ {
370
+ mutable T Ptr;
371
+
372
+ public:
373
+ pointer_iterator() = default;
374
+
375
+ explicit pointer_iterator(WrappedIteratorT u)
376
+ : pointer_iterator::iterator_adaptor_base(std::move(u)) {}
377
+
378
+ T &operator*()
379
+ {
380
+ return Ptr = &*this->I;
381
+ }
382
+ const T &operator*() const
383
+ {
384
+ return Ptr = &*this->I;
385
+ }
386
+ };
387
+
388
+ template <typename RangeT, typename WrappedIteratorT =
389
+ decltype(std::begin(std::declval<RangeT>()))>
390
+ iterator_range<pointer_iterator<WrappedIteratorT>>
391
+ make_pointer_range(RangeT &&Range)
392
+ {
393
+ using PointerIteratorT = pointer_iterator<WrappedIteratorT>;
394
+ return make_range(PointerIteratorT(std::begin(std::forward<RangeT>(Range))),
395
+ PointerIteratorT(std::end(std::forward<RangeT>(Range))));
396
+ }
397
+
398
+ template <typename WrappedIteratorT,
399
+ typename T1 = std::remove_reference_t<decltype(
400
+ **std::declval<WrappedIteratorT>())>,
401
+ typename T2 = std::add_pointer_t<T1>>
402
+ using raw_pointer_iterator =
403
+ pointer_iterator<pointee_iterator<WrappedIteratorT, T1>, T2>;
404
+
405
+ } // end namespace llvm
406
+
407
+ #endif // LLVM_ADT_ITERATOR_H
@@ -0,0 +1,76 @@
1
+ //===- iterator_range.h - A range adaptor for iterators ---------*- C++ -*-===//
2
+ //
3
+ // From the LLVM Project with some modifications, under the Apache License v2.0
4
+ // with LLVM Exceptions. See https://llvm.org/LICENSE.txt for license information.
5
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
+ //
7
+ //===----------------------------------------------------------------------===//
8
+ /// \file
9
+ /// This provides a very simple, boring adaptor for a begin and end iterator
10
+ /// into a range type. This should be used to build range views that work well
11
+ /// with range based for loops and range based constructors.
12
+ ///
13
+ /// Note that code here follows more standards-based coding conventions as it
14
+ /// is mirroring proposed interfaces for standardization.
15
+ ///
16
+ //===----------------------------------------------------------------------===//
17
+
18
+ #ifndef LLVM_ADT_ITERATOR_RANGE_H
19
+ #define LLVM_ADT_ITERATOR_RANGE_H
20
+
21
+ #include <utility>
22
+
23
+ namespace llvm
24
+ {
25
+
26
+ /// A range adaptor for a pair of iterators.
27
+ ///
28
+ /// This just wraps two iterators into a range-compatible interface. Nothing
29
+ /// fancy at all.
30
+ template <typename IteratorT>
31
+ class iterator_range
32
+ {
33
+ IteratorT begin_iterator, end_iterator;
34
+
35
+ public:
36
+ //TODO: Add SFINAE to test that the Container's iterators match the range's
37
+ // iterators.
38
+ template <typename Container>
39
+ iterator_range(Container &&c)
40
+ //TODO: Consider ADL/non-member begin/end calls.
41
+ : begin_iterator(c.begin()), end_iterator(c.end()) {}
42
+ iterator_range(IteratorT begin_iterator, IteratorT end_iterator)
43
+ : begin_iterator(std::move(begin_iterator)),
44
+ end_iterator(std::move(end_iterator)) {}
45
+
46
+ IteratorT begin() const
47
+ {
48
+ return begin_iterator;
49
+ }
50
+ IteratorT end() const
51
+ {
52
+ return end_iterator;
53
+ }
54
+ bool empty() const
55
+ {
56
+ return begin_iterator == end_iterator;
57
+ }
58
+ };
59
+
60
+ /// Convenience function for iterating over sub-ranges.
61
+ ///
62
+ /// This provides a bit of syntactic sugar to make using sub-ranges
63
+ /// in for loops a bit easier. Analogous to std::make_pair().
64
+ template <class T> iterator_range<T> make_range(T x, T y)
65
+ {
66
+ return iterator_range<T>(std::move(x), std::move(y));
67
+ }
68
+
69
+ template <typename T> iterator_range<T> make_range(std::pair<T, T> p)
70
+ {
71
+ return iterator_range<T>(std::move(p.first), std::move(p.second));
72
+ }
73
+
74
+ }
75
+
76
+ #endif
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svf-lib",
3
- "version": "1.0.1291",
3
+ "version": "1.0.1292",
4
4
  "description": "SVF's npm support",
5
5
  "main": "index.js",
6
6
  "scripts": {