Otawa  0.10
PFG.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  * PFG class interface
4  *
5  * This file is part of OTAWA
6  * Copyright (c) 2008, 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
21  * 02110-1301 USA
22  */
23 #ifndef OTAWA_CFG_PFG_H_
24 #define OTAWA_CFG_PFG_H_
25 
26 #include <elm/genstruct/HashTable.h>
27 #include <otawa/prop/Identifier.h>
28 #include <otawa/prog/Inst.h>
29 #include <otawa/graph/GenGraph.h>
30 
31 namespace otawa { namespace pfg {
32 
33 using namespace elm;
34 class BB;
35 class Edge;
37 class PFG;
38 
39 // BasicBlock class
40 class BB: public graph_t::GenNode {
41 public:
42 
43  inline BB(void): _first(0), _size(0) { }
44  inline BB(Inst *first, t::uint32 size): _first(first), _size(size) { }
45  inline Address address(void) const { return _first->address(); }
46  inline Address topAddress(void) const { return address() + _size; }
47  inline t::uint32 size(void) const { return _size; }
48  inline Inst *first(void) const { return _first; }
49  inline int count(void) const;
50  inline PFG& pfg(void) const;
51  bool isControl(void) const;
52  bool isBranch(void) const;
53  bool isConditional(void) const;
54  bool isBranched(void) const;
55  bool isCall(void) const;
56  bool isReturn(void) const;
57  bool isMultiTarget(void) const;
58  inline void setSize(size_t size) { _size = size; }
59 
60  // InstIter class
61  class InstIter: public PreIterator<InstIter, Inst *> {
62  public:
63  inline InstIter(const BB *bb): inst(bb->first()), top(bb->topAddress()) { }
64  inline InstIter(const InstIter& iter): inst(iter.inst), top(iter.top) { }
65  inline InstIter& operator=(const InstIter& iter)
66  { inst = iter.inst; top = iter.top; return *this; }
67 
68  inline bool ended(void) const { return !inst || inst->address() >= top; }
69  inline Inst *item(void) const { return inst; }
70  inline void next(void) { inst = inst->nextInst(); }
71 
72  private:
75  };
76 
77 private:
80 };
81 
82 // Edge class
83 class Edge: public graph_t::GenEdge {
84 public:
85  typedef enum kind_t {
86  NONE = 0,
87  SEQ = 1,
88  BRANCH = 2,
89  COND_BRANCH = 3,
90  CALL = 4,
91  COND_CALL = 5,
92  RETURN = 6,
93  COND_RETURN = 7
94  } kind_t;
95 
96  inline Edge(BB *source, BB *sink, kind_t kind)
97  : graph_t::GenEdge(source, sink), _kind(kind) { }
98  inline kind_t kind(void) const { return _kind; }
99 
100 private:
102 };
103 
104 // PFG class
105 class PFG: public graph_t {
106 public:
107 
110 
111  PFG(void);
112  void add(BB *bb);
113  BB *get(Address addr);
114 
115 private:
117 };
118 
119 } } // otawa::pfg
120 
121 #endif /* OTAWA_CFG_PFG_H_ */
122 
struct otawa::sem::inst inst
Definition: GenGraph.h:38
Identifier< pfg::PFG * > PFG
PFG of the program.
void setSize(size_t size)
Definition: PFG.h:58
dtd::RefAttr< BasicBlock * > source("source", dtd::STRICT|dtd::REQUIRED)
InstIter & operator=(const InstIter &iter)
Definition: PFG.h:65
Definition: GenGraph.h:44
Inst * inst
Definition: PFG.h:73
Inst * first(void) const
Get the first instruction of the basic block.
Definition: PFG.h:48
genstruct::HashTable< Address, BB * > bbs
Definition: PFG.h:116
BB(Inst *first, t::uint32 size)
Definition: PFG.h:44
kind_t _kind
Definition: PFG.h:101
Definition: ClpValue.h:54
InstIter(const BB *bb)
Definition: PFG.h:63
kind_t
Type of edges.
Definition: PFG.h:85
Edge(BB *source, BB *sink, kind_t kind)
Definition: PFG.h:96
dtd::Element bb(dtd::make("bb", _BB).attr(id).attr(address).attr(size))
uint32 size
elm::io::IntFormat address(Address addr)
Build a format to display addresses.
Definition: base.cpp:213
Inst::kind_t kind
Definition: odisasm.cpp:106
This class represents the control transfer between basic block (BB).
Definition: PFG.h:83
otawa::GenGraph< BB, Edge > graph_t
Definition: PFG.h:35
t::uint32 size(void) const
Get the size of the basic block.
Definition: PFG.h:47
kind_t
Allowed types for values: NONE represents nothing; REG is only used for addresses, and represents a register; VAL represents some values (either a constant or an interval); ALL is the Top element.
Definition: ClpValue.h:53
BB ret
This special basic block is used as the sink vertex of edges representing sub-program return...
Definition: PFG.h:108
The representation of an address in OTAWA.
Definition: base.h:54
A basic block in a otawa::pfg::PFG .
Definition: PFG.h:40
InstIter(const InstIter &iter)
Definition: PFG.h:64
A PFG (Program Flow Graph) is built from the binary form of the program to represent all possible pat...
Definition: PFG.h:105
Definition: util_fft_parser.cpp:161
Definition: ast_parser.cpp:134
Address top
Definition: PFG.h:74
Definition: ipet_parser.cpp:125
inst add(int d, int a, int b)
Definition: inst.h:163
Definition: features.h:46
BB unknown
This special basic block is used as the sink vertex of edges representing branch or call to an unknow...
Definition: PFG.h:109
Inst * _first
Definition: PFG.h:78
bool ended(void) const
Definition: PFG.h:68
Iterator on the instructions of a basic block.
Definition: PFG.h:61
This class represents assembly instruction of a piece of code.
Definition: Inst.h:62
kind_t kind(void) const
Get the kind of an edge.
Definition: PFG.h:98
BB(void)
Definition: PFG.h:43
Address address(void) const
Get the start address of the basic block.
Definition: PFG.h:45
t::uint32 _size
Definition: PFG.h:79
void next(void)
Definition: PFG.h:70
Inst * item(void) const
Definition: PFG.h:69
Definition: GenGraph.h:61
uint32_t uint32
Address topAddress(void) const
Get the address next after the basic block, that is, address + size.
Definition: PFG.h:46