Otawa  0.10
DefaultListener.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  * Listener associated with DefaultFixPoint
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
21  * 02110-1301 USA
22  */
23 
24 #ifndef OTAWA_DFA_HAI_DEFAULTLISTENER_H_
25 #define OTAWA_DFA_HAI_DEFAULTLISTENER_H_
26 
27 #include "DefaultFixPoint.h"
28 #include <otawa/cfg/CFG.h>
29 #include <otawa/cfg/CFGCollector.h>
30 #include <otawa/cfg/BasicBlock.h>
31 #include <otawa/cfg/Edge.h>
32 #include <otawa/prop/PropList.h>
33 #include <elm/genstruct/Vector.h>
34 
35 namespace otawa { namespace dfa { namespace hai {
36 
37 template <class P>
39 public:
40 
41  typedef P Problem;
42 
44 
45  typename Problem::Domain ***results;
46  typename Problem::Domain ***results_out;
47 
48  DefaultListener(WorkSpace *_fw, Problem& _prob, bool _store_out = false) : fw(_fw), prob(_prob), store_out(_store_out) {
49  const CFGCollection *col = INVOLVED_CFGS(fw);
50  results = new typename Problem::Domain**[col->count()];
51  if (store_out)
52  results_out = new typename Problem::Domain**[col->count()];
53  for (int i = 0; i < col->count(); i++) {
54  CFG *cfg = col->get(i);
55  results[i] = new typename Problem::Domain*[cfg->countBB()];
56  if (store_out)
57  results_out[i] = new typename Problem::Domain*[cfg->countBB()];
58  for (int j = 0; j < cfg->countBB(); j++){
59  results[i][j] = new typename Problem::Domain(prob.bottom());
60  if (store_out)
61  results_out[i][j] = new typename Problem::Domain(prob.bottom());
62  }
63  }
64  }
65 
67  const CFGCollection *col = INVOLVED_CFGS(fw);
68  for (int i = 0; i < col->count(); i++) {
69  CFG *cfg = col->get(i);
70  for (int j = 0; j < cfg->countBB(); j++){
71  delete results[i][j];
72  if (store_out)
73  delete results_out[i][j];
74  }
75  delete [] results[i];
76  if (store_out)
77  delete [] results_out[i];
78  }
79  delete [] results;
80  if (store_out)
81  delete [] results_out;
82  }
83 
84  void blockInterpreted(const DefaultFixPoint< DefaultListener > *fp, BasicBlock* bb, const typename Problem::Domain& in, const typename Problem::Domain& out, CFG *cur_cfg, elm::genstruct::Vector<Edge*> *callStack) const;
85 
87 
88  inline Problem& getProb() {
89  return(prob);
90  }
91 
92 private:
95  bool store_out;
96 
97 };
98 
102 template <class Problem >
104 
105 template <class Problem >
106 void DefaultListener<Problem>::blockInterpreted(const DefaultFixPoint<DefaultListener> *fp, BasicBlock* bb, const typename Problem::Domain& in, const typename Problem::Domain& out, CFG *cur_cfg, elm::genstruct::Vector<Edge*> *callStack) const {
107 
108  int bbnumber = bb->number() ;
109  int cfgnumber = cur_cfg->number();
110 
111  prob.lub(*results[cfgnumber][bbnumber], in);
112 
113  if (BB_OUT_STATE(bb) != 0)
114  prob.lub(**BB_OUT_STATE(bb), out);
115 
116  if (store_out)
117  prob.lub(*results_out[cfgnumber][bbnumber], out);
118 #ifdef HAI_LISTENER_DEBUG
119  cerr << "INFO: " << bb << "\n\tIN = " << in << "\n\tOUT= " << out << "\n";
120 #endif
121 }
122 
123 template <class Problem >
125 }
126 
127 } } } // otawa::dfa::hai
128 
129 #endif // OTAWA_DFA_HAI_DEFAULTLISTENER_H_
Problem & getProb()
Definition: DefaultListener.h:88
Definition: DefaultFixPoint.h:38
bool store_out
Definition: DefaultListener.h:95
DefaultListener(WorkSpace *_fw, Problem &_prob, bool _store_out=false)
Definition: DefaultListener.h:48
void blockInterpreted(const DefaultFixPoint< DefaultListener > *fp, BasicBlock *bb, const typename Problem::Domain &in, const typename Problem::Domain &out, CFG *cur_cfg, elm::genstruct::Vector< Edge * > *callStack) const
This is called whenever a block is processed.
Definition: DefaultListener.h:106
sys::SystemInStream & in
int number(void)
Definition: CFG.h:111
dtd::Element bb(dtd::make("bb", _BB).attr(id).attr(address).attr(size))
io::Output cerr
Control Flow Graph representation.
Definition: CFG.h:42
~DefaultListener()
Definition: DefaultListener.h:66
Problem::Domain *** results_out
Definition: DefaultListener.h:46
CFG * get(int index) const
Get a CFG from the collection using its index.
Definition: features.h:51
static Identifier< typename Problem::Domain * > BB_OUT_STATE
PRIVATE - DO NOT USE.
Definition: DefaultListener.h:43
A workspace represents a program, its run-time and all information about WCET computation or any othe...
Definition: WorkSpace.h:67
Contains a collection of CFGs (used with INVOLVED_CFGS property).
Definition: features.h:45
WorkSpace * fw
Definition: DefaultListener.h:93
int number(void) const
Get the number hooked on this basic block, that is, value of ID_Index property.
Definition: BasicBlock.h:146
sys::SystemOutStream & out
Problem & prob
Definition: DefaultListener.h:94
Identifier< const CFGCollection * > INVOLVED_CFGS
This property is used to link the current computation involved CFG on the framework.
P Problem
Definition: DefaultListener.h:41
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
int count(void) const
Get the count of CFG in the collection.
Definition: features.h:50
Problem::Domain *** results
Definition: DefaultListener.h:45
void fixPointReached(const DefaultFixPoint< DefaultListener > *fp, BasicBlock *bb)
This is called whenever a loop's fixpoint is reached.
Definition: DefaultListener.h:124
This listener gathers in an array the LUB of the in-states for all analyzed basic blocks...
Definition: DefaultListener.h:38
int countBB(void)
Definition: CFG.h:105