Otawa  0.10
ContextTree.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  * ContextTree class interface
4  *
5  * This file is part of OTAWA
6  * Copyright (c) 2005-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_CONTEXT_TREE_H
23 #define OTAWA_CONTEXT_TREE_H
24 
25 #include <elm/assert.h>
26 #include <elm/genstruct/Vector.h>
27 #include <otawa/properties.h>
29 #include <otawa/proc/Feature.h>
30 
31 namespace otawa {
32 
33 class BasicBlock;
34 class CFG;
35 
36 // ContextTree class
37 class ContextTree: public PropList {
38 public:
39  // Kind
40  typedef enum kind_t {
41  ROOT = 0,
44  } kind_t;
45 
46 private:
52 
55  void addChild(ContextTree *tree);
56  void addBB(BasicBlock *bb, bool _inline);
57 public:
58 
59  // Methods
60  ContextTree(CFG *cfg, ContextTree *parent = 0, bool _inline = true);
61  ~ContextTree(void);
62  inline BasicBlock *bb(void) const;
63  inline kind_t kind(void) const;
64  inline CFG *cfg(void) const;
65  inline ContextTree *parent(void) const;
66  /*inline elm::Collection<ContextTree *>& children(void);
67  inline elm::Collection<BasicBlock *>& bbs(void);*/
68  inline bool isChildOf(const ContextTree *ct);
70 
71  // ChildrenIterator class
72  class ChildrenIterator: public elm::genstruct::Vector<ContextTree *>::Iterator {
73  public:
74  inline ChildrenIterator(ContextTree *tree);
75  };
76 
77  // BBIterator class
78  class BBIterator: public elm::genstruct::Vector<BasicBlock *>::Iterator {
79  public:
80  inline BBIterator(ContextTree *tree):
81  elm::genstruct::Vector<BasicBlock *>::Iterator(tree->_bbs) { }
82  };
83 };
84 
85 
86 // ContextTreeBuilder class
88 public:
89  ContextTreeBuilder(void);
90 protected:
91  virtual void processWorkSpace(WorkSpace *fw);
92 };
93 
94 
95 // ContextTreeByCFGBuilder class
97 public:
99 protected:
100  virtual void processCFG(WorkSpace *fw, CFG *cfg);
101 };
102 
103 // Features
106 
107 // Identifiers
110 
111 
112 
113 // ContextTree inlines
114 inline BasicBlock *ContextTree::bb(void) const {
115  return _bb;
116 };
117 
119  return _kind;
120 };
121 
122 inline ContextTree *ContextTree::parent(void) const {
123  return _parent;
124 };
125 
126 /*inline elm::Collection<BasicBlock *>& ContextTree::bbs(void) {
127  return _bbs;
128 }
129 
130 inline elm::Collection<ContextTree *>& ContextTree::children(void) {
131  return _children;
132 }*/
133 
134 
135 inline bool ContextTree::isChildOf(const ContextTree *ct) {
136  ContextTree *cur = this;
137  while(ct) {
138  if(cur == ct)
139  return true;
140  else
141  cur = cur->_parent;
142  }
143  return false;
144 }
145 
146 inline CFG *ContextTree::cfg(void) const {
147  return _cfg;
148 }
149 
150 // ContextTree::ChildrenIterator class
152 : elm::genstruct::Vector<ContextTree *>::Iterator(tree->_children) {
153  ASSERT(tree);
154 };
155 
156 // Output
158  out << "context_tree(" << (void *)ct << ")";
159  return out;
160 }
161 
162 } // otawa
163 
164 #endif // OTAWA_CONTEXT_TREE_H
Iterator for the children of a context tree.
Definition: ContextTree.h:72
void addChild(ContextTree *tree)
Add a children context tree.
Definition: util_ContextTree.cpp:179
CFG * cfg(void) const
Get the current CFG.
Definition: CFGProcessor.h:56
A loop context tree.
Definition: ContextTree.h:43
virtual void processWorkSpace(WorkSpace *fw)
Process the given framework.
Definition: util_ContextTree.cpp:317
This processor produces context tree information.
Definition: ContextTree.h:87
kind_t _kind
Definition: ContextTree.h:47
Feature< ContextTreeByCFGBuilder > CONTEXT_TREE_BY_CFG_FEATURE
Assert that a context tree has been built for each CFG involved in the current computation.
~ContextTree(void)
Free the entire tree.
Definition: util_ContextTree.cpp:138
ContextTree * enclosingFunction(void)
Find the enclosing function containing this context tree.
Definition: util_ContextTree.cpp:232
elm::genstruct::Vector< BasicBlock * > _bbs
Definition: ContextTree.h:50
elm::genstruct::Vector< ContextTree * > _children
Definition: ContextTree.h:51
ContextTreeBuilder(void)
Definition: util_ContextTree.cpp:306
bool isChildOf(const ContextTree *ct)
Test transitively if the current context tree is a child of the given one.
Definition: ContextTree.h:135
Feature< ContextTreeBuilder > CONTEXT_TREE_FEATURE
This feature asserts that a context tree of the task is available in the framework.
elm::io::Output & operator<<(elm::io::Output &out, Address addr)
Definition: base.cpp:188
Control Flow Graph representation.
Definition: CFG.h:42
void addBB(BasicBlock *bb, bool _inline)
Add the given basic block to the context tree.
Definition: util_ContextTree.cpp:149
The processor class is implemented by all code processor.
Definition: Processor.h:49
A function context tree (due to a function call).
Definition: ContextTree.h:42
kind_t kind(void) const
Get the kind of the tree node.
Definition: ContextTree.h:118
A workspace represents a program, its run-time and all information about WCET computation or any othe...
Definition: WorkSpace.h:67
ContextTree * parent(void) const
Get the parent tree of the current one.
Definition: ContextTree.h:122
This is a specialization of the processor class dedicated to CFG processing.
Definition: CFGProcessor.h:35
sys::SystemOutStream & out
virtual void processCFG(WorkSpace *fw, CFG *cfg)
Definition: util_ContextTree.cpp:356
kind_t
This enumerate represents the kind of a context tree.
Definition: ContextTree.h:40
ContextTreeByCFGBuilder(void)
Definition: util_ContextTree.cpp:345
Definition: ContextTree.h:37
ContextTree(BasicBlock *bb, CFG *cfg, ContextTree *parent)
Build the context tree of a loop.
Definition: util_ContextTree.cpp:124
This class represents identifier with a typed associated value.
Definition: Identifier.h:51
CFG * cfg(void) const
Get the CFG containing this context tree.
Definition: ContextTree.h:146
This is the minimal definition of a basic block.
Definition: BasicBlock.h:43
ContextTree * _parent
Definition: ContextTree.h:53
BasicBlock * bb(void) const
Get the BB that heads this tree (enter of functions for ROOT and FUNCTION, header for LOOP)...
Definition: ContextTree.h:114
This a list of properties.
Definition: PropList.h:63
A function context tree root of the whole tree.
Definition: ContextTree.h:41
Identifier< ContextTree * > OWNER_CONTEXT_TREE
Annotations with this identifier are hooked to basic blocks and gives the owner context tree (Context...
ChildrenIterator(ContextTree *tree)
Build a new iterator.
Definition: ContextTree.h:151
Definition: ContextTree.h:78
Build a context tree for each CFG involved in the current computation.
Definition: ContextTree.h:96
BBIterator(ContextTree *tree)
Definition: ContextTree.h:80
CFG * _cfg
Definition: ContextTree.h:49
Identifier< ContextTree * > CONTEXT_TREE
This property identifier provides a context tree hooked to a framework.
BasicBlock * _bb
Definition: ContextTree.h:48
A feature is a set of facilities, usually provided using properties, available on a framework...
Definition: Feature.h:46