Otawa  0.10
CFG.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  * CFG class interface
4  *
5  * This file is part of OTAWA
6  * Copyright (c) 2003-07, 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_CFG_CFG_H
23 #define OTAWA_CFG_CFG_H
24 
25 #include <elm/assert.h>
26 #include <elm/genstruct/FragTable.h>
27 #include <otawa/cfg/BasicBlock.h>
28 
29 namespace otawa {
30 
31 // Classes
32 class BasicBlock;
33 class CodeItem;
34 class CFG;
35 class CFGInfo;
36 
37 // Properties
38 extern Identifier<CFG *> ENTRY;
40 
41 // CFG class
42 class CFG: public PropList {
44 public:
45  //static Identifier ID_Dom;
46 
47  // Iterator
48  class BBIterator: public bbs_t::Iterator {
49  public:
50  inline BBIterator(CFG *cfg): bbs_t::Iterator(cfg->getBBS()) { }
51  inline BBIterator(const BBIterator& iter): bbs_t::Iterator(iter) { }
52  };
53 
54  // Methods
55  CFG(Segment *seg, BasicBlock *entry);
56  virtual ~CFG(void);
57  inline Segment *segment(void) const;
58  string label(void);
59  string name(void);
60  string format(const Address& addr);
61  inline int number(void);
62  address_t address(void);
63  inline BasicBlock *entry(void)
64  { if(!(flags & FLAG_Scanned)) scan(); return &_entry; }
65  inline BasicBlock *exit(void)
66  { if(!(flags & FLAG_Scanned)) scan(); return &_exit; }
67  inline int countBB(void);
68  inline bool isVirtual(void) const;
69  inline bool isInlined(void) const;
70  void numberBB(void);
71  BasicBlock *firstBB(void);
72  Inst *firstInst(void);
73  void print(io::Output& out);
74 
75 protected:
76  friend class CFGInfo;
77 
78  unsigned long flags;
80  static const unsigned long FLAG_Scanned = 0x01;
81  static const unsigned long FLAG_Virtual = 0x02;
82  static const unsigned long FLAG_Inlined = 0x04;
84 
85  CFG(void);
86  virtual void scan(void);
87 
88 private:
89  inline const bbs_t& getBBS(void) {
90  if(!(flags & FLAG_Scanned))
91  scan();
92  return _bbs;
93  }
95  mutable BasicBlock *ent;
96 };
97 inline io::Output& operator<<(io::Output& out, CFG *cfg) { cfg->print(out); return out; }
98 
99 
100 // CFG inlines
101 inline Segment *CFG::segment(void) const {
102  return _seg;
103 };
104 
105 inline int CFG::countBB(void) {
106  if(!(flags & FLAG_Scanned))
107  scan();
108  return _bbs.length();
109 }
110 
111 inline int CFG::number(void) {
112  return(INDEX(this));
113 }
114 
115 inline bool CFG::isVirtual(void) const {
116  return flags & FLAG_Virtual;
117 }
118 inline bool CFG::isInlined(void) const {
119  return flags & FLAG_Inlined;
120 }
121 
122 } // otawa
123 
124 #endif // OTAWA_CFG_CFG_H
Definition: CFG.h:48
string format(const Address &addr)
Format the display of the given address relativelt to the given CFG.
Definition: CFG.cpp:295
void numberBB(void)
Number the basic block of the CFG, that is, hook a property with ID_Index identifier and the integer ...
Definition: CFG.cpp:516
void print(io::Output &out)
Print a reference for the CFG.
Definition: CFG.cpp:572
Segment * _seg
Definition: CFG.h:94
static const unsigned long FLAG_Scanned
Definition: CFG.h:80
int length(void) const
EndBasicBlock _entry
Definition: CFG.h:79
address_t address(void)
Get the address of the first instruction of the CFG.
Definition: CFG.cpp:404
static const unsigned long FLAG_Virtual
Definition: CFG.h:81
int number(void)
Definition: CFG.h:111
BBIterator(const BBIterator &iter)
Definition: CFG.h:51
BasicBlock * entry(void)
Get the entry basic block of the CFG.
Definition: CFG.h:63
Identifier< int > INDEX
Identifier used for storing in each basic block from the CFG its index.
Definition: CFG.h:39
elm::io::Output & operator<<(elm::io::Output &out, Address addr)
Definition: base.cpp:188
Control Flow Graph representation.
Definition: CFG.h:42
unsigned long flags
Definition: CFG.h:78
In usual file format like ELF, COFF and so on, the program file is divided in segment according platf...
Definition: Segment.h:40
BasicBlock * exit(void)
Get the exit basic block of the CFG.
Definition: CFG.h:65
bool isInlined(void) const
Definition: CFG.h:118
static const unsigned long FLAG_Inlined
Definition: CFG.h:82
string name(void)
Build a name that identifies this CFG and is valid C name.
Definition: CFG.cpp:392
Definition: BasicBlock.h:203
virtual ~CFG(void)
Definition: CFG.cpp:524
EndBasicBlock _exit
Definition: CFG.h:79
Segment * segment(void) const
Definition: CFG.h:101
The representation of an address in OTAWA.
Definition: base.h:54
const bbs_t & getBBS(void)
Definition: CFG.h:89
sys::SystemOutStream & out
BasicBlock * ent
Definition: CFG.h:95
genstruct::FragTable< BasicBlock * > bbs_t
Definition: CFG.h:43
dtd::Element cfg(dtd::make("cfg", _CFG).attr(id).content((entry,*bb, exit,*edge)))
This is the minimal definition of a basic block.
Definition: BasicBlock.h:43
string label(void)
Get some label to identify the CFG.
Definition: CFG.cpp:368
This class represents assembly instruction of a piece of code.
Definition: Inst.h:62
This allows storing all CFG available in a workspace.
Definition: CFGInfo.h:29
This a list of properties.
Definition: PropList.h:63
CFG(void)
Build an empty CFG.
Definition: CFG.cpp:333
BBIterator(CFG *cfg)
Definition: CFG.h:50
BasicBlock * firstBB(void)
Get the first basic block of the CFG.
Definition: CFG.cpp:548
bbs_t _bbs
Definition: CFG.h:83
virtual void scan(void)
Scan the CFG for finding exit and builds virtual edges with entry and exit.
Definition: CFG.cpp:428
bool isVirtual(void) const
Definition: CFG.h:115
Identifier< CFG * > ENTRY
Identifier used for storing and retrieving the CFG on its entry BB.
Inst * firstInst(void)
Get the first instruction of the CFG.
Definition: CFG.cpp:559
int countBB(void)
Definition: CFG.h:105