Otawa  0.10
ParamFeature.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  * ParamFeature and ActualFeature classes interface
4  *
5  * This file is part of OTAWA
6  * Copyright (c) 2010, IRIT UPS <casse@irit.fr>
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_PROC_PARAMFEATURE_H_
23 #define OTAWA_PROC_PARAMFEATURE_H_
24 
25 #include <elm/genstruct/Vector.h>
26 #include <otawa/proc/Feature.h>
27 #include <otawa/prog/WorkSpace.h>
28 
29 namespace otawa {
30 
31 // external definition
32 class AbstractParamIdentifier;
33 class AbstractParamProcessor;
34 class ParamFeature;
35 
36 // ActualFeature class
38 public:
40  inline const ParamFeature& feature(void) const { return feat; }
41  inline const AbstractParamProcessor& processor(void) { return proc; }
42 
43  // AbstractFeature overload
44  virtual void process(WorkSpace *ws, const PropList &props=PropList::EMPTY) const;
45  virtual void check(WorkSpace*) const { }
46  virtual void clean(WorkSpace*) const { }
47 
48 private:
49  ~ActualFeature(void);
50  void lock(void);
51  void unlock(void);
52 
55  int cnt;
56 };
57 
58 // ParamFeature class
59 class ParamFeature: public Identifier<AbstractParamProcessor *> {
60 public:
62 
64  ActualFeature *instantiate(const PropList& props);
65 
66 private:
67  bool matches(ActualFeature *feat, const PropList& def);
68 
71 };
72 
73 // AbstractParamIdentifier class
74 class AbstractParamIdentifier: public Identifier<AbstractIdentifier *> {
75 public:
77 
79  virtual AbstractIdentifier *instantiate(ActualFeature& feature) const = 0;
80 };
81 
82 // ParamIdentifier class
83 template <class T>
85 public:
87  : AbstractParamIdentifier(feature, name) { }
88  inline ParamIdentifier(ParamFeature& feature, cstring name, const T& def)
89  : AbstractParamIdentifier(feature, name), _def(def) { }
90 
91  inline Identifier<T>& operator[](const ActualFeature& feat) const
92  { return *static_cast<Identifier<T> *>(use(feat)); }
93  inline Identifier<T>& operator[](const ActualFeature *feat) const
94  { return *static_cast<Identifier<T> *>(use(feat)); }
95 
96  virtual AbstractIdentifier *instantiate(ActualFeature& feature) const { return new Identifier<T>("", _def); }
97 
98 private:
99  T _def;
100 };
101 
102 } // otawa
103 
104 #endif /* OTAWA_PROC_PARAMFEATURE_H_ */
T _def
Definition: ParamFeature.h:99
Identifier< T > & operator[](const ActualFeature &feat) const
Definition: ParamFeature.h:91
Implementation of AbstractParamIdentifier for an Identifier.
Definition: ParamFeature.h:84
ParamFeature(cstring id, AbstractParamProcessor &def)
Definition: proc_ParamFeature.cpp:230
static const PropList EMPTY
This is an empty proplist for convenience.
Definition: PropList.h:66
AbstractParamIdentifier(ParamFeature &feature, cstring name)
Build an abstract parametric identifier.
Definition: proc_ParamFeature.cpp:293
const AbstractParamProcessor & processor(void)
Get the default parametric processor.
Definition: ParamFeature.h:41
A parametric identifier allows to instantiate identifier depending on a parametric feature...
Definition: ParamFeature.h:74
const string name(void) const
Get the string name of the identifier.
Definition: AbstractIdentifier.h:43
Identifier< T > & operator[](const ActualFeature *feat) const
Definition: ParamFeature.h:93
Abstract form of a parametric processor.
Definition: ParamProcessor.h:35
void lock(void)
Lock the actual feature (prevent deletion).
Definition: proc_ParamFeature.cpp:204
static Identifier< AbstractParamIdentifier * > PARAM_ID
This identifier is used to hook parametric identifiers associated with a parametric feature...
Definition: ParamFeature.h:61
bool matches(ActualFeature *feat, const PropList &def)
Test if the given feature matches the given properties.
Definition: proc_ParamFeature.cpp:240
const AbstractParamProcessor & proc
Definition: ParamFeature.h:54
const ParamFeature & feat
Definition: ParamFeature.h:53
virtual void process(WorkSpace *ws, const PropList &props=PropList::EMPTY) const
This method is called, when a feature is not available, to provided a default implementation of the f...
Definition: proc_ParamFeature.cpp:179
Represents a unique identifier used by the annotation system.
Definition: AbstractIdentifier.h:32
Processor * def
Definition: Identifier.h:132
ActualFeature(const ParamFeature &feature, const AbstractParamProcessor &def)
Build the actual feature.
Definition: proc_ParamFeature.cpp:164
const AbstractIdentifier *& use(const PropList &list) const
A workspace represents a program, its run-time and all information about WCET computation or any othe...
Definition: WorkSpace.h:67
static AbstractIdentifier ACTUAL_ID
This identifier marks all parametric identifier.
Definition: ParamFeature.h:76
~ActualFeature(void)
Definition: proc_ParamFeature.cpp:170
ParamIdentifier(ParamFeature &feature, cstring name, const T &def)
Definition: ParamFeature.h:88
A parametric feature is a feature that may be instantiated according to some parameters passed in a p...
Definition: ParamFeature.h:59
An actual feature is the result of the instantiation of a parametric feature.
Definition: ParamFeature.h:37
This class represents identifier with a typed associated value.
Definition: Identifier.h:51
virtual void clean(WorkSpace *) const
This method is called each time a feature is invalidated.
Definition: ParamFeature.h:46
void unlock(void)
Unlock the current feature, possibly deleting it.
Definition: proc_ParamFeature.cpp:212
genstruct::Vector< ActualFeature * > feats
Definition: ParamFeature.h:70
const AbstractParamProcessor & proc
Definition: ParamFeature.h:69
const ParamFeature & feature(void) const
Get the instantiated parametric feature.
Definition: ParamFeature.h:40
See Feature.
Definition: AbstractFeature.h:36
This a list of properties.
Definition: PropList.h:63
ActualFeature * instantiate(const PropList &props)
Instantiate the feature.
Definition: proc_ParamFeature.cpp:256
ParamIdentifier(ParamFeature &feature, cstring name)
Definition: ParamFeature.h:86
virtual void check(WorkSpace *) const
Check if the framework really implement the current feature.
Definition: ParamFeature.h:45
virtual AbstractIdentifier * instantiate(ActualFeature &feature) const
Instantiate the identifier.
Definition: ParamFeature.h:96
virtual AbstractIdentifier * instantiate(ActualFeature &feature) const =0
Instantiate the identifier.
int cnt
Definition: ParamFeature.h:55