Otawa  0.10
CFGAdapter.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  * CFGAdapter class interface
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 #ifndef OTAWA_DISPLAY_CFGADAPTER_H_
23 #define OTAWA_DISPLAY_CFGADAPTER_H_
24 
25 #include <otawa/cfg.h>
26 
27 namespace otawa { namespace display {
28 
29 // CFGAdapter class
30 class CFGAdapter {
31 public:
32 
33  // DiGraph concept
34  class Vertex {
35  public:
36  inline Vertex(BasicBlock *_bb): bb(_bb) { }
37  inline int index(void) { return bb->number(); }
39  };
40 
41  class Edge {
42  public:
43  inline Edge(otawa::Edge *_edge): edge(_edge) { }
44  inline Vertex source(void) const { return Vertex(edge->source()); }
45  inline Vertex sink(void) const { return Vertex(edge->target()); }
47  };
48 
49  class Successor: public PreIterator<Successor, Edge> {
50  public:
51  inline Successor(const CFGAdapter& ad, Vertex source): iter(source.bb)
52  { step(); }
53  inline Successor(const Successor& succ): iter(succ.iter) { }
54  inline bool ended(void) const { return iter.ended(); }
55  inline Edge item(void) const { return Edge(*iter); }
56  inline void next(void) { iter.next(); step(); }
57  private:
58  void step(void) {
59  while(!iter.ended() && iter->kind() == otawa::Edge::CALL)
60  iter.next();
61  }
63  };
64 
65  // Collection concept
66  class Iterator: public PreIterator<Iterator, Vertex> {
67  public:
68  inline Iterator(const CFGAdapter& adapter): iter(adapter.cfg) { }
69  inline Iterator(const Iterator& _iter): iter(_iter.iter) { }
70  inline bool ended(void) const { return iter.ended(); }
71  inline Vertex item(void) const { return Vertex(iter); }
72  inline void next(void) { iter.next(); }
73  private:
75  };
76 
77  // DiGraphWithVertexMap concept
78  template <class T>
79  class VertexMap {
80  public:
81  inline VertexMap(const CFGAdapter& adapter)
82  : vals(new T[adapter.count()]) { }
83  inline const T& get(const Vertex& vertex) const
84  { return vals[vertex.bb->number()]; }
85  inline void put(const Vertex& vertex, const T& val)
86  { vals[vertex.bb->number()] = val; }
87  private:
88  T *vals;
89  };
90 
91  inline CFGAdapter(CFG *_cfg, WorkSpace *_ws = 0): cfg(_cfg), ws(_ws) { }
92  inline int count(void) const{ return cfg->countBB(); }
93  CFG *cfg;
95 };
96 
97 } } // otawa::display
98 
99 #endif // OTAWA_DISPLAY_CFGADAPTER_H_
Iterator(const CFGAdapter &adapter)
Definition: CFGAdapter.h:68
Definition: CFG.h:48
dtd::RefAttr< BasicBlock * > source("source", dtd::STRICT|dtd::REQUIRED)
Iterator(const Iterator &_iter)
Definition: CFGAdapter.h:69
VertexMap(const CFGAdapter &adapter)
Definition: CFGAdapter.h:81
Definition: CFGAdapter.h:41
int count(void) const
Definition: CFGAdapter.h:92
void next(void)
Definition: CFGAdapter.h:72
BasicBlock * source(void) const
Definition: Edge.h:52
Kind of an edge matching a sub-program call.
Definition: Edge.h:40
Definition: CFGAdapter.h:34
int index(void)
Definition: CFGAdapter.h:37
void put(const Vertex &vertex, const T &val)
Definition: CFGAdapter.h:85
dtd::Element bb(dtd::make("bb", _BB).attr(id).attr(address).attr(size))
Definition: CFGAdapter.h:66
Control Flow Graph representation.
Definition: CFG.h:42
Successor(const Successor &succ)
Definition: CFGAdapter.h:53
bool ended(void) const
Definition: CFGAdapter.h:70
void step(void)
Definition: CFGAdapter.h:58
This adapter implements the otawa::concept::DiGraphWithNodeMap and allows to use apply the GenDrawer ...
Definition: CFGAdapter.h:30
WorkSpace * ws
Definition: CFGAdapter.h:94
A workspace represents a program, its run-time and all information about WCET computation or any othe...
Definition: WorkSpace.h:67
T * vals
Definition: CFGAdapter.h:88
Definition: BasicBlock.h:165
int number(void) const
Get the number hooked on this basic block, that is, value of ID_Index property.
Definition: BasicBlock.h:146
CFG * cfg
Definition: CFGAdapter.h:93
Definition: CFGAdapter.h:49
Vertex source(void) const
Definition: CFGAdapter.h:44
BasicBlock * bb
Definition: CFGAdapter.h:38
This class represents edges in the CFG representation.
Definition: Edge.h:33
BasicBlock * target(void) const
Definition: Edge.h:53
void next(void)
Definition: CFGAdapter.h:56
BasicBlock::OutIterator iter
Definition: CFGAdapter.h:62
This is the minimal definition of a basic block.
Definition: BasicBlock.h:43
bool ended(void) const
Definition: CFGAdapter.h:54
CFGAdapter(CFG *_cfg, WorkSpace *_ws=0)
Build the adapter.
Definition: CFGAdapter.h:91
Edge item(void) const
Definition: CFGAdapter.h:55
Definition: CFGAdapter.h:79
Vertex(BasicBlock *_bb)
Definition: CFGAdapter.h:36
Vertex sink(void) const
Definition: CFGAdapter.h:45
Vertex item(void) const
Definition: CFGAdapter.h:71
Successor(const CFGAdapter &ad, Vertex source)
Definition: CFGAdapter.h:51
int countBB(void)
Definition: CFG.h:105
Edge(otawa::Edge *_edge)
Definition: CFGAdapter.h:43
CFG::BBIterator iter
Definition: CFGAdapter.h:74
otawa::Edge * edge
Definition: CFGAdapter.h:46