Otawa  0.10
Processor.h
Go to the documentation of this file.
1 /*
2  * Processor class interface
3  *
4  * This file is part of OTAWA
5  * Copyright (c) 2005-7, IRIT UPS <casse@irit.fr>
6  *
7  * OTAWA is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * OTAWA is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OTAWA; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 #ifndef OTAWA_PROC_PROCESSOR_H
22 #define OTAWA_PROC_PROCESSOR_H
23 
24 #include <elm/io.h>
25 #include <elm/util/Cleaner.h>
26 #include <elm/util/Version.h>
27 #include <elm/system/StopWatch.h>
28 #include <elm/genstruct/Vector.h>
29 #include <elm/genstruct/HashTable.h>
30 #include <elm/util/Cleaner.h>
31 #include <otawa/properties.h>
34 #include <otawa/proc/Monitor.h>
35 
36 namespace otawa {
37 
38 using namespace elm;
39 using namespace elm::genstruct;
40 class AbstractFeature;
41 class Configuration;
42 class WorkSpace;
43 class FeatureDependency;
44 class Progress;
45 class StatCollector;
46 
47 
48 // Processor class
49 class Processor: public otawa::Monitor {
50 
51  template <class T>
52  class Remover: public elm::Cleaner {
53  public:
54  inline Remover(const Ref<T, Identifier<T> >& ref): _ref(ref.props(), ref.id()) { }
55  virtual void clean(void) { _ref.remove(); }
56  protected:
57  inline const Ref<T, Identifier<T> >& ref(void) const { return _ref; }
59  };
60 
61  template <class T>
62  class Deletor: public Remover<T *> {
63  public:
64  inline Deletor(const Ref<T *, Identifier<T *> >& ref): Remover<T *>(ref) { }
65  virtual void clean(void) { delete Remover<T *>::ref().get(); Remover<T *>::clean(); }
66  };
67 
68 public:
69 
70  /*typedef enum log_level_t {
71  LOG_NONE = 0,
72  LOG_PROC = 1,
73  LOG_FILE = 2,
74  LOG_DEPS = LOG_FILE,
75  LOG_FUN = 3,
76  LOG_CFG = LOG_FUN,
77  LOG_BLOCK = 4,
78  LOG_BB = LOG_BLOCK,
79  LOG_INST = 5
80  } log_level_t;*/
81 
82  // Constructors
83  Processor(void);
85  Processor(String name, Version version);
87  virtual ~Processor(void);
89 
90  // Accessors
91  inline elm::String name(void) const { return _reg->name(); }
92  inline elm::Version version(void) const { return _reg->version(); }
93 
94  // Mutators
95  virtual void configure(const PropList& props);
96  void process(WorkSpace *ws, const PropList& props = PropList::EMPTY);
97 
98  // Configuration Properties
104 
105  // deprecated
110 
111  // Statistics Properties
113 
114  // Deprecated
115  Processor(const PropList& props);
116  Processor(elm::String name, elm::Version version, const PropList& props);
117 
118 protected:
119  static const t::uint32
120  IS_TIMED = 0x01 << CUSTOM_SHIFT,
121  //IS_VERBOSE = 0x02,
122  IS_ALLOCATED = 0x04 << CUSTOM_SHIFT,
123  IS_PREPARED = 0x08 << CUSTOM_SHIFT,
124  IS_COLLECTING = 0x10 << CUSTOM_SHIFT;
125  //unsigned long flags;
126  //elm::io::Output out;
127  //elm::io::Output log;
129 
130  // accessors
131  friend class FeatureRequirer;
132  //inline bool isVerbose(void) const { return flags & IS_VERBOSE; }
133  inline bool isTimed(void) const { return flags & IS_TIMED; }
134  inline bool recordsStats(void) const { return stats; }
135  inline bool isAllocated(void) const { return flags & IS_ALLOCATED; }
136  inline bool isPrepared(void) const { return flags & IS_PREPARED; }
137  inline bool isCollectingStats(void) const { return flags & IS_COLLECTING; }
138  //inline bool logFor(log_level_t tested) const { return tested <= log_level; }
139  //inline log_level_t logLevel(void) const { return log_level; }
140 
141  // configuration
142  void require(const AbstractFeature& feature);
143  void provide(const AbstractFeature& feature);
144  void invalidate(const AbstractFeature& feature);
145  void use(const AbstractFeature& feature);
146 
147  // utilities
148  void warn(const String& message);
149  inline WorkSpace *workspace(void) const { return ws; }
150  inline Progress& progress(void) { return *_progress; }
151  void recordStat(const AbstractFeature& feature, StatCollector *collector);
152 
153  // cleanup
154  inline void addCleaner(const AbstractFeature& feature, Cleaner *cleaner)
155  { cleaners.add(clean_t(&feature, cleaner)); }
156  template <class T> void addRemover(const AbstractFeature& feature, const Ref<T, Identifier<T> >& ref)
157  { addCleaner(feature, new Remover<T>(ref)); }
158  template <class T> void addDeletor(const AbstractFeature& feature, const Ref<T *, Identifier<T *> >& ref)
159  { addCleaner(feature, new Deletor<T>(ref)); }
160 
161 
162  // Methods for customizing
163  virtual void prepare(WorkSpace *ws);
164  virtual void processWorkSpace(WorkSpace *ws);
165  virtual void setup(WorkSpace *ws);
166  virtual void cleanup(WorkSpace *ws);
167  virtual void collectStats(WorkSpace *ws);
168 
169  // Deprecated
170  virtual void processFrameWork(WorkSpace *fw);
171 
172  template <class T> T *track(const AbstractFeature& feature, T *object)
173  { addCleaner(feature, new elm::Deletor<T>(object)); return object; }
174  template <class T> void track(const AbstractFeature& feature, const Ref<T *, Identifier<T *> >& ref)
175  { addCleaner(feature, new Deletor<T>(ref)); }
176  template <class T> void track(const AbstractFeature& feature, const Ref<T *, const Identifier<T *> >& ref)
177  { addCleaner(feature, new Deletor<T>(ref)); }
178 
179  // internal use only
180  virtual void requireDyn(WorkSpace *ws, const PropList& props);
181 
182 private:
183  void init(const PropList& props);
190  //log_level_t log_level;
191 };
192 
193 
194 // NullProcessor class
195 class NullProcessor: public Processor {
196 public:
197  NullProcessor(void);
198 };
199 
200 
201 // NoProcessor class
202 class NoProcessor: public Processor {
203 protected:
204  virtual void processWorkSpace(WorkSpace *fw);
205 public:
206  NoProcessor(void);
207 };
208 
209 
210 // NoProcessorException class
212 };
213 
214 
215 // UnavailableFeatureException class
217 public:
218 
220  const Processor *processor,
221  const AbstractFeature& feature
222  ): ProcessorException(*processor, ""), f(feature) { }
223 
224  inline const AbstractFeature& feature(void) const { return f; }
225  virtual String message(void);
226 private:
228 };
229 
230 } // otawa
231 
232 #endif // OTAWA_PROC_PROCESSOR_H
This class is an interface to get progress information about execution of a processor.
Definition: Progress.h:33
bool isCollectingStats(void) const
Definition: Processor.h:137
static Identifier< bool > TIMED
If the value of the associated property is true (default to false), time statistics will also be coll...
Definition: Processor.h:100
int flags
void addDeletor(const AbstractFeature &feature, const Ref< T *, Identifier< T * > > &ref)
Definition: Processor.h:158
Definition: Registration.h:127
elm::String name(void) const
Definition: Processor.h:91
A simple processor that does nothing.
Definition: Processor.h:195
This class provided feature requirement for non-program processor classes.
Definition: FeatureRequirer.h:31
A processor whise execution cause an exception throw.
Definition: Processor.h:202
static const PropList EMPTY
This is an empty proplist for convenience.
Definition: PropList.h:66
Abstract class to represent the registered processors.
Definition: Registration.h:80
bool isTimed(void) const
Test if the timed mode is activated (recording of timings in the statistics).
Definition: Processor.h:133
virtual void clean(void)
Definition: Processor.h:65
Definition: Processor.h:62
const AbstractFeature & feature(void) const
Get the feature causing the exception.
Definition: Processor.h:224
static Identifier< bool > COLLECT_STATS
This property allows to activate collection of statistics for the work of the current processor...
Definition: Processor.h:103
bool isAllocated(void) const
Definition: Processor.h:135
This exception is thrown when an feature can not be computed.
Definition: Processor.h:216
clean_list_t cleaners
Definition: Processor.h:188
void track(const AbstractFeature &feature, const Ref< T *, Identifier< T * > > &ref)
Track the release of an allocated object assigned to an identifier relatively to the given feature...
Definition: Processor.h:174
void addRemover(const AbstractFeature &feature, const Ref< T, Identifier< T > > &ref)
Definition: Processor.h:156
WorkSpace * ws
Definition: Processor.h:185
const int provide
Definition: Registration.h:44
Definition: Processor.h:211
virtual void clean(void)
Definition: Processor.h:55
const AbstractRegistration & registration(void)
Definition: Registry.h:54
PropList * stats
Definition: Processor.h:128
static Identifier< elm::system::time_t > RUNTIME
This property identifier is used to store in the statistics of a processor the overall run time of th...
Definition: Processor.h:112
AbstractRegistration * _reg
Definition: Processor.h:184
Progress * _progress
Definition: Processor.h:189
static Identifier< elm::io::OutStream * > & OUTPUT
This property identifier is used for setting the output stream used by the processor to write results...
Definition: Processor.h:106
The processor class is implemented by all code processor.
Definition: Processor.h:49
Progress & progress(void)
Get the current progress handler.
Definition: Processor.h:150
A statistics collector allows to access statistics produced by an analysis.
Definition: StatCollector.h:30
const int use
Definition: Registration.h:46
A workspace represents a program, its run-time and all information about WCET computation or any othe...
Definition: WorkSpace.h:67
static Identifier< bool > & VERBOSE
This property activates the verbose mode of the processor: information about the processor work will ...
Definition: Processor.h:108
static Identifier< Progress * > PROGRESS
Install.
Definition: Processor.h:102
const int require
Definition: Registration.h:43
elm::Version version(void) const
Definition: Processor.h:92
static Identifier< PropList * > STATS
This property identifiers is used to pass a property list to the processor that will be used to store...
Definition: Processor.h:99
IntFormat f(signed char value)
Ref< T, Identifier< T > > _ref
Definition: Processor.h:58
const int invalidate
Definition: Registration.h:45
Deletor(const Ref< T *, Identifier< T * > > &ref)
Definition: Processor.h:64
WorkSpace * workspace(void) const
Get the current workspace.
Definition: Processor.h:149
T * track(const AbstractFeature &feature, T *object)
Definition: Processor.h:172
static Identifier< elm::io::OutStream * > & LOG
This property identifier is used for setting the log stream used by the processor to write messages (...
Definition: Processor.h:107
This class represents identifier with a typed associated value.
Definition: Identifier.h:51
cstring name
Definition: odisasm.cpp:107
static MetaRegistration reg
Definition: Processor.h:88
const Ref< T, Identifier< T > > & ref(void) const
Definition: Processor.h:57
elm::genstruct::SLList< clean_t > clean_list_t
Definition: Processor.h:187
bool recordsStats(void) const
Test if the statictics mode is activated.
Definition: Processor.h:134
See Feature.
Definition: AbstractFeature.h:36
This a list of properties.
Definition: PropList.h:63
static Identifier< bool > RECURSIVE
Definition: Processor.h:101
bool isPrepared(void) const
Definition: Processor.h:136
This class is used for returning exceptions from the processors.
Definition: ProcessorException.h:17
const AbstractFeature & f
Definition: Processor.h:227
Remover(const Ref< T, Identifier< T > > &ref)
Definition: Processor.h:54
void track(const AbstractFeature &feature, const Ref< T *, const Identifier< T * > > &ref)
Track the release of an allocated object assigned to an identifier relatively to the given feature...
Definition: Processor.h:176
static Identifier< log_level_t > & LOG_LEVEL
Property passed in the configuration property list of a processor to select the log level between LOG...
Definition: Processor.h:109
UnavailableFeatureException(const Processor *processor, const AbstractFeature &feature)
Definition: Processor.h:219
void addCleaner(const AbstractFeature &feature, Cleaner *cleaner)
Add a cleaner for the given feature.
Definition: Processor.h:154
uint32_t uint32
Pair< const AbstractFeature *, Cleaner * > clean_t
Definition: Processor.h:186
Definition: Processor.h:52