Otawa  0.10
concepts.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  * concept collection
4  *
5  * This file is part of OTAWA
6  * Copyright (c) 2007, IRIT UPS.
7  *
8  * OTAWA is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * OTAWA is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with OTAWA; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include <elm/genstruct/Vector.h>
24 
25 using namespace elm;
26 
27 namespace otawa { namespace concept {
28 
37 class DiGraph: public elm::concept::Collection<Vertex> {
38 public:
39 
41  class Vertex { };
42 
44  class Edge { };
45 
51  const Vertex& sinkOf(Edge& edge);
52 
58  int outDegree(const Vertex& vertex) const;
59 
66  bool isSuccessorOf(Vertex& succ, const Vertex& ref);
67 
69  class Successor: public Iterator<Edge> {
70  public:
71 
76  Successor(const DiGraph& graph, const Vertex& source);
77 
82  Successor(const OutIterator& iterator);
83  };
84 
85 };
86 
87 
89 class DiGraphWithLoop: public DiGraph {
90 
95  bool isLoopHeader(Vertex& vertex);
96 };
97 
98 
101 public:
102  int indexOf(const Vertex& vertex) const;
103 };
104 
105 
107 class BiDiGraph: public DiGraph {
108 
110  class Predecessor: public Iterator<Edge> {
111  public:
112 
117  Predecessor(const DiGraph& graph, const Vertex& source);
118 
123  Predecessor(const InIterator& iterator);
124  };
125 
131  const Vertex& sourceOf(const Edge& edge);
132 
138  int inDegree(const Vertex& vertex) const;
139 
146  bool isSuccessorOf(const Vertex& succ, const Vertex& ref);
147 };
148 
149 
152 public:
154  template <class T> class VertexMap: public Map<Vertex, T> { };
155 };
156 
157 
160 public:
162  template <class T> class EdgeMap: public Map<Edge, T> { };
163 };
164 
165 
167 class DiGraphWithEntry: public DiGraph {
168 public:
170  Vertex entry(void);
171 };
172 
173 
175 class DiGraphWithExit: public BiDiGraph {
176 public:
178  Vertex exit(void);
179 };
180 
182 class InstBlock {
183 public:
184 
189  Address address(void);
190 
195  size_t size(void);
196 
201  Address topAddress(void);
202 
207  int countInsts(void);
208 
212  class InstIter: public Iterator<Inst *> {
213  public:
214 
216  InstIter(const InstBlock *block);
217 
219  InstIter(const InstIter& iter);
220  };
221 };
222 
223 
228 template <class T, class G>
230 public:
231 
233  typedef T t;
234 
236  t initial(void);
237 
240  t bottom(void);
241 
248  void join(t& d, t s);
249 
255  bool equals(t v1, t v2);
256 
262  void set(t& d, t s);
263 
270  void dump(io::Output& out, t c);
271 
279  void update(const typename G::Vertex& vertex, t& d);
280 
281 };
282 
285 public:
286 
288  typedef struct Set Set;
289 
294  Set *empty(void);
295 
301  Set *gen(BasicBlock *bb);
302 
308  Set *kill(BasicBlock *bb);
309 
316  bool equals(Set *set1, Set *set2);
317 
323  void reset(Set *set);
324 
330  void merge(Set *set1, Set *set2);
331 
337  void set(Set *dset, Set *tset);
338 
344  void add(Set *dset, Set *tset);
345 
351  void diff(Set *dset, Set *tset);
352 
357  void free(Set *set);
358 };
359 
360 } // dfa
361 
362 
363 namespace ai {
364 
369 class Graph {
370 public:
371 
375  typedef void *vertex_t;
376 
380  typedef void *edge_t;
381 
386  vertex_t entry(void) const;
387 
392  vertex_t exit(void) const;
393 
399  vertex_t sinkOf(edge_t e) const;
400 
406  vertex_t sourceOf(edge_t e) const;
407 
411  class Predecessor {
412  public:
413  Predecessor(const CFGGraph& graph, vertex_t v);
414  Predecessor(const Predecessor& p);
415  };
416 
420  class Successor {
421  public:
422  Successor(const CFGGraph& graph, vertex_t v);
423  Successor(const Successor& p);
424  };
425 
429  class Iterator {
430  public:
431  Iterator(const CFGGraph& g);
432  Iterator(const Iterator& i);
433  };
434 
440  int index(vertex_t v) const;
441 
446  int count(void) const;
447 };
448 
449 
454 class Domain {
455 public:
456 
460  typedef void *t;
461 
466  t init(void);
467 
472  t bot(void);
473 
480  t join(t v1, t v2);
481 
488  bool equals(t v1, t v2);
489 
496  template <class I>
497  t input(Graph::vertex_t vertex, I& ins);
498 
506  template <class O>
507  void output(Graph::vertex_t vertex, t in, O& outs);
508 
509 };
510 
515 class InputIter {
516 public:
517 
522  Graph::edge_t edge(void);
523 
528  const Domain::t& get(void);
529 };
530 
535 class OutputIter {
536 public:
537 
542  Graph::edge_t edge(void);
543 
548  void set(const Domain::t& value);
549 
554  void setAll(const Domain::t& value);
555 };
556 
557 } // ai
558 
559 } // otawa
void free(void *)
dtd::RefAttr< BasicBlock * > source("source", dtd::STRICT|dtd::REQUIRED)
void set(T *target, int size, const T &v)
dtd::Element edge(dtd::make("edge", _EDGE).attr(source).attr(target).attr(called))
Concept of directed graph providing an edge map.
Definition: concepts.h:159
Concept of directed graph with predecessor available.
Definition: concepts.h:107
Iterator on the vertices of the graph.
Definition: concepts.h:429
Iterator to set output values.
Definition: concepts.h:535
Entering-in edge iterator on a node.
Definition: concepts.h:110
Content & empty
Definition: cfgio_Input.cpp:174
Concept used to implements AbsIntLite domain.
Definition: concepts.h:229
struct Set Set
Type of the set of the problem.
Definition: concepts.h:288
Directed graph with a unique entry and exit points.
Definition: concepts.h:175
sys::SystemInStream & in
BiDiGraph implementation for CFG.
Definition: ai.h:212
void * t
Type of domain values.
Definition: concepts.h:460
dtd::Element bb(dtd::make("bb", _BB).attr(id).attr(address).attr(size))
Iterator on input of a vertex.
Definition: concepts.h:515
uint32 size
elm::io::IntFormat address(Address addr)
Build a format to display addresses.
Definition: base.cpp:213
Directed graph with a unique entry point.
Definition: concepts.h:167
void * edge_t
Graph edge type.
Definition: concepts.h:380
dtd::Element exit(dtd::make("exit", _EXIT).attr(id))
value_t value(CString name, int value)
Domain concept for ai module.
Definition: concepts.h:454
An iterable block of instruction.
Definition: concepts.h:182
Vertex class.
Definition: concepts.h:41
Concept of directed graph providing a vertex map.
Definition: concepts.h:151
dtd::Element entry(dtd::make("entry", _ENTRY).attr(id))
void * vertex_t
Graph vertex type.
Definition: concepts.h:375
The representation of an address in OTAWA.
Definition: base.h:54
Concept used to implements IterativeDFA problems.
Definition: concepts.h:284
T t
Type of the values of the domain.
Definition: concepts.h:233
This concept attempts to provide a representation of a digraph that may only be traversed in the edge...
Definition: concepts.h:37
Efficient map for the edges.
Definition: concepts.h:162
sys::SystemOutStream & out
inst add(int d, int a, int b)
Definition: inst.h:163
A digraph that supports loop identification.
Definition: concepts.h:89
Graph concept for ai module.
Definition: concepts.h:369
This is the minimal definition of a basic block.
Definition: BasicBlock.h:43
Iterator on the entering edges on the given vertex.
Definition: concepts.h:411
Efficient map for the nodes.
Definition: concepts.h:154
Iterator on the instruction of the block.
Definition: concepts.h:212
Opaque type for the edges.
Definition: concepts.h:44
Outing edge iterator on a node.
Definition: concepts.h:69
Iterator on the leaving edges of the given vertex.
Definition: concepts.h:420
This kind of digraph contain indexed graph.
Definition: concepts.h:100