OTAWA  2.0
Framework to perform machine analysis and compute WCET.
ContextualProperty.h
Go to the documentation of this file.
1 /*
2  * OTAWA -- WCET computation framework
3  * Copyright (C) 2009-17 IRIT - UPS <casse@irit.fr>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.package ojawa;
18  */
19 #ifndef OTAWA_PROP_CONTEXTUALPROPERTY_H_
20 #define OTAWA_PROP_CONTEXTUALPROPERTY_H_
21 
22 #include <elm/inhstruct/Tree.h>
23 #include <elm/io.h>
24 #include <elm/ptr.h>
25 
26 #include <otawa/base.h>
27 #include <otawa/prop/Property.h>
28 #include <otawa/prop/Identifier.h>
29 
30 namespace otawa {
31 
32 using namespace elm;
33 
34 // pre-declaration
35 class ContextualPath;
36 
37 
38 // ContextualStep class
40 public:
41  typedef enum kind_t {
42  NONE = 0,
48  } kind_t;
49 
50  inline ContextualStep(void): _kind(NONE) { }
51  inline ContextualStep(kind_t kind, const Address &address): _kind(kind), addr(address) { };
52  inline ContextualStep(const ContextualStep& step): _kind(step._kind), addr(step.addr) { };
53  static ContextualStep null;
54 
56  { _kind = step._kind; addr = step.addr; return *this; }
57 
58  inline kind_t kind(void) const { return _kind; }
59  inline const Address& address(void) const { return addr; }
60 
61  inline bool equals(const ContextualStep& step) const
62  { return _kind == step.kind() && addr == step.address(); }
63  inline bool operator==(const ContextualStep& step) const { return equals(step); }
64  inline bool operator!=(const ContextualStep& step) const { return !equals(step); }
65 
66  void print(io::Output& out) const;
67 
68 private:
71 };
73  { path.print(out); return out; }
74 
75 
76 // ContextualProperty class
78 
79  // Node class
80  class Node: public PropList, public inhstruct::Tree {
81  public:
82  inline Node(void) { }
83  inline Node(const ContextualStep& _step): step(_step) { }
85  };
86 
87 public:
88  ContextualProperty(void);
89 
90  static bool exists(const PropList& props, const ContextualPath& path, const AbstractIdentifier& id);
91  static PropList& ref(PropList& props, const ContextualPath& path, const AbstractIdentifier& id);
92 
93  static const PropList& find(const PropList& props, const ContextualPath& path, const AbstractIdentifier& id);
94  static PropList& make(PropList& props, const ContextualPath& path);
95  static void printFrom(io::Output& out, const PropList& props);
96 
97 private:
98  const PropList& findProps(const PropList& props, const ContextualPath& path, const AbstractIdentifier& id) const;
99  PropList& makeProps(const ContextualPath& path);
100  PropList& refProps(PropList& props, const ContextualPath& path, const AbstractIdentifier& id);
101  void printRec(io::Output& out, const Node& node, int indent = 0) const;
102 
105 };
106 
107 
108 class ContextualList: public Lock {
109 public:
110  inline ContextualList(const ContextualStep& step): s(step) { }
111  inline ContextualList(const ContextualStep& step, const LockPtr<ContextualList> next)
112  : s(step), n(next) { }
113 
114  inline const ContextualStep& step(void) const { return s; }
115  inline LockPtr<ContextualList> next(void) const { return n; }
116  int count(void) const;
117  const ContextualStep& ith(int i) const;
118  inline const ContextualStep& operator[](int i) const { return ith(i); }
119 
120 private:
123 };
124 
125 
126 // ContextualPath class
128 public:
129 
130  // Ref for ContextualPath
131  template <class T>
132  class Ref {
133  public:
134  inline Ref(const ContextualPath& _cp, PropList& _p, const Identifier<T>& _i): cp(_cp), p(_p), i(_i) { }
135  inline Ref(const Ref<T>& r): cp(r.cp), p(r.p), i(r.i) { }
136  inline Ref<T>& operator=(const Ref<T>& r) { cp = r.cp; p = r.p; i = r.i; return *this; }
137 
138  // immutable part
139  inline const ContextualPath& path(void) const { return cp; }
140  inline const PropList &proplist (void) const { return p; }
141  inline const Identifier<T>& identifier (void) const { return i; }
142  inline bool exists(void) const { return ContextualProperty::exists(p, cp, i); };
143  inline const T &get (void) const { return cp.get(i, p); }
144  inline operator const T &(void) const { return get(); }
145  inline T operator->(void) const { return get(); }
146  inline void print(io::Output& out) { i.print(out, find(p, cp, i).getProp(&i)); }
147 
148  // mutable part
149  inline const Ref<T> &add(const T &value) const { return i(ContextualProperty::make(p, cp, i)).add(value); }
150  inline void remove(void) const { ContextualProperty::make(p, cp).removeProp(i); }
151  inline T& ref(void) const { return i.ref(ContextualProperty::ref(p, cp, i)); }
152  inline T& operator&(void) const { return ref(); }
153  const Ref<T> &operator=(const T &v) const { ref() = v; return *this; }
154  inline Ref<T> &operator+= (const T &v) const { ref() += v; return *this; }
155  inline Ref<T> &operator-= (const T &v) const { ref() -= v; return *this; }
156  inline Ref<T> &operator *= (const T &v) const { ref() *= v; return *this; }
157  inline Ref<T> &operator/= (const T &v) const { ref() /= v; return *this; }
158  inline Ref<T> &operator%= (const T &v) const { ref() %= v; return *this; }
159  inline Ref<T> &operator &= (const T &v) const { ref() &= v; return *this; }
160  inline Ref<T> &operator|= (const T &v) const { ref() |= v; return *this; }
161  inline Ref<T> &operator^= (const T &v) const { ref() ^= v; return *this; }
162  inline Ref<T> &operator<<= (const T &v) const { ref() <<= v; return *this; }
163  inline Ref<T> &operator>>= (const T &v) const { ref() >>= v; return *this; }
164  inline Ref<T> &operator++ (void) const { ref()++; return *this; }
165  inline Ref<T> &operator-- (void) const { ref()--; return *this; }
166  inline Ref<T> &operator++ (int) const { ref()++; return *this; }
167  inline Ref<T> &operator-- (int) const { ref()--; return *this; }
168 
169  private:
172  const Identifier<T>& i;
173  };
174 
175  // constructors
176  inline ContextualPath(void) { }
177 
178  inline void clear(void) { p = 0; }
179  inline void push(const ContextualStep& step) { p = new ContextualList(step, p); }
180  inline void push(ContextualStep::kind_t kind, const Address& addr) { push(ContextualStep(kind, addr)); }
181  inline void pop(void) { ASSERT(&p); p = p->next(); }
182 
183  inline bool isEmpty(void) const { return p.isNull(); }
184  inline int count(void) const { return p.isNull() ? 0 : p->count(); }
185  inline const ContextualStep& step(int i) const { return p->ith(p->count() - i - 1); }
186  inline const ContextualStep& operator[](int i) const { return step(i); }
187  inline operator bool(void) const { return !isEmpty(); }
188  void print(io::Output& out) const;
189  inline const ContextualList *list(void) const { return &p; }
190 
191  Address getEnclosingFunction(void) const;
192 
193  template <class T> inline const T& get(const Identifier<T>& id, const PropList& props) const {
194  const PropList& fprops = ContextualProperty::find(props, *this, id);
195  return id.value(fprops);
196  }
197 
198  template <class T> inline Ref<T> ref(const Identifier<T>& id, PropList& props) const
199  { return Ref<T>(*this, props, id); }
200  template <class T> inline const T& get(const Identifier<T>& id, const PropList *props) const
201  { return get(id, *props); }
202  template <class T> inline Ref<T> ref(const Identifier<T>& id, PropList *props) const
203  { return ref(id, *props); }
204 
205  template <class T> inline const T& operator()(const Identifier<T>& id, const PropList *props) const
206  { return get(id, *props); }
207  template <class T> inline const T& operator()(const Identifier<T>& id, const PropList& props) const
208  { return get(id, props); }
209  template <class T> inline Ref<T> operator()(const Identifier<T>& id, PropList *props) const
210  { return ref(id, *props); }
211  template <class T> inline Ref<T> operator()(const Identifier<T>& id, PropList& props) const
212  { return ref(id, props); }
213 
214 private:
216 };
217 
218 // I/O
220  { path.print(out); return out; }
221 template <class T>
223  { r.print(out); return out; }
224 
225 } // otawa
226 
227 #endif /* OTAWA_PROP_CONTEXTUALPROPERTY_H_ */
otawa::ContextualPath::Ref::ref
T & ref(void) const
Definition: ContextualProperty.h:151
otawa::PropList::removeProp
void removeProp(const AbstractIdentifier *id)
Remove a property matching the given identifier.
Definition: prop_PropList.cpp:431
otawa::ContextualPath::Ref::identifier
const Identifier< T > & identifier(void) const
Definition: ContextualProperty.h:141
otawa::ContextualStep::print
void print(io::Output &out) const
Definition: prop_ContextualProperty.cpp:98
out
typename type_info< T >::out_t out
otawa::ContextualStep::OTHER_ITER
@ OTHER_ITER
Definition: ContextualProperty.h:46
otawa::ContextualPath::ref
Ref< T > ref(const Identifier< T > &id, PropList &props) const
Definition: ContextualProperty.h:198
otawa::ContextualProperty
Definition: ContextualProperty.h:77
p
Printable< T, M > p(const T &data, const M &man)
otawa::ContextualPath::push
void push(ContextualStep::kind_t kind, const Address &addr)
Definition: ContextualProperty.h:180
otawa::ContextualPath::list
const ContextualList * list(void) const
Definition: ContextualProperty.h:189
otawa::ContextualPath::ref
Ref< T > ref(const Identifier< T > &id, PropList *props) const
Definition: ContextualProperty.h:202
otawa::display::indent
Indent indent(int n=1)
Definition: display.h:187
otawa::ContextualPath::operator()
Ref< T > operator()(const Identifier< T > &id, PropList *props) const
Definition: ContextualProperty.h:209
otawa::ContextualPath::print
void print(io::Output &out) const
Print the contextual path.
Definition: prop_ContextualProperty.cpp:128
otawa::ContextualPath::isEmpty
bool isEmpty(void) const
Definition: ContextualProperty.h:183
otawa::ContextualStep::FIRST_ITER
@ FIRST_ITER
Definition: ContextualProperty.h:45
otawa::ContextualPath::Ref::cp
const ContextualPath & cp
Definition: ContextualProperty.h:170
ref
mut< T > ref(var< T > &x)
otawa::ContextualPath::Ref::operator&
T & operator&(void) const
Definition: ContextualProperty.h:152
equals
bool equals(const C1 &c1, const C2 &c2)
elm::Lock
otawa::ContextualStep::operator=
ContextualStep & operator=(const ContextualStep &step)
Definition: ContextualProperty.h:55
otawa::ContextualPath::Ref::i
const Identifier< T > & i
Definition: ContextualProperty.h:172
elm::io::NONE
NONE
otawa::ContextualPath::Ref::remove
void remove(void) const
Definition: ContextualProperty.h:150
otawa::ContextualPath::operator[]
const ContextualStep & operator[](int i) const
Definition: ContextualProperty.h:186
otawa::ContextualPath::operator()
const T & operator()(const Identifier< T > &id, const PropList &props) const
Definition: ContextualProperty.h:207
base.h
otawa::ContextualPath::Ref::add
const Ref< T > & add(const T &value) const
Definition: ContextualProperty.h:149
otawa::ContextualPath::Ref::operator=
const Ref< T > & operator=(const T &v) const
Definition: ContextualProperty.h:153
otawa::ContextualStep::CALL
@ CALL
Definition: ContextualProperty.h:44
otawa::ContextualStep::FUNCTION
@ FUNCTION
Definition: ContextualProperty.h:43
otawa::ContextualStep::kind
kind_t kind(void) const
Definition: ContextualProperty.h:58
otawa::ContextualStep
Definition: ContextualProperty.h:39
otawa::AbstractIdentifier
Definition: AbstractIdentifier.h:33
otawa::ContextualProperty::exists
static bool exists(const PropList &props, const ContextualPath &path, const AbstractIdentifier &id)
Test if a contextual property exists, that is, the property value is defined at any step of the given...
Definition: prop_ContextualProperty.cpp:282
void
otawa::ContextualProperty::find
static const PropList & find(const PropList &props, const ContextualPath &path, const AbstractIdentifier &id)
Get a contextual property from a property list.
Definition: prop_ContextualProperty.cpp:243
bool
otawa::ContextualStep::equals
bool equals(const ContextualStep &step) const
Definition: ContextualProperty.h:61
Identifier.h
otawa::ContextualPath
Definition: ContextualProperty.h:127
otawa::ContextualPath::clear
void clear(void)
Definition: ContextualProperty.h:178
otawa::ContextualStep::operator==
bool operator==(const ContextualStep &step) const
Definition: ContextualProperty.h:63
otawa::ContextualProperty::Node::step
ContextualStep step
Definition: ContextualProperty.h:84
elm::find
C::Iter find(const C &c, const P &p)
otawa::ContextualStep::address
const Address & address(void) const
Definition: ContextualProperty.h:59
otawa::ContextualProperty::Node::Node
Node(void)
Definition: ContextualProperty.h:82
kind
Inst::kind_t kind
Definition: odisasm.cpp:113
otawa::ContextualPath::Ref::proplist
const PropList & proplist(void) const
Definition: ContextualProperty.h:140
Property.h
otawa::ContextualStep::kind_t
kind_t
Definition: ContextualProperty.h:41
otawa::ContextualProperty::Node::Node
Node(const ContextualStep &_step)
Definition: ContextualProperty.h:83
value
value("ANY", otawa::display::OUTPUT_ANY) .value("PS"
otawa::ContextualPath::Ref::path
const ContextualPath & path(void) const
Definition: ContextualProperty.h:139
elm
otawa::Identifier
Definition: Identifier.h:50
otawa::clp::kind_t
kind_t
Allowed types for values: NONE represents nothing; REG is only used for addresses,...
Definition: ClpValue.h:51
otawa::ContextualStep::AFTER
@ AFTER
Definition: ContextualProperty.h:47
otawa::ContextualProperty::root
Node root
Definition: ContextualProperty.h:103
otawa::ContextualStep::_kind
kind_t _kind
Definition: ContextualProperty.h:69
otawa::ContextualPath::get
const T & get(const Identifier< T > &id, const PropList *props) const
Definition: ContextualProperty.h:200
otawa::ContextualList::s
ContextualStep s
Definition: ContextualProperty.h:121
otawa::ContextualPath::Ref::operator->
T operator->(void) const
Definition: ContextualProperty.h:145
otawa::ContextualPath::push
void push(const ContextualStep &step)
Definition: ContextualProperty.h:179
otawa::ContextualPath::Ref::get
const T & get(void) const
Definition: ContextualProperty.h:143
otawa::ContextualProperty::ref
static PropList & ref(PropList &props, const ContextualPath &path, const AbstractIdentifier &id)
Obtain a reference on a property value in the given contextual path.
Definition: prop_ContextualProperty.cpp:305
otawa::ContextualPath::operator()
const T & operator()(const Identifier< T > &id, const PropList *props) const
Definition: ContextualProperty.h:205
otawa::ContextualList
Definition: ContextualProperty.h:108
otawa::ContextualPath::get
const T & get(const Identifier< T > &id, const PropList &props) const
Definition: ContextualProperty.h:193
otawa::ContextualPath::Ref::Ref
Ref(const Ref< T > &r)
Definition: ContextualProperty.h:135
otawa::Address
Definition: base.h:56
otawa::ContextualList::ContextualList
ContextualList(const ContextualStep &step, const LockPtr< ContextualList > next)
Definition: ContextualProperty.h:111
otawa::ContextualList::step
const ContextualStep & step(void) const
Definition: ContextualProperty.h:114
otawa::ContextualList::n
LockPtr< ContextualList > n
Definition: ContextualProperty.h:122
elm::inhstruct::Tree
otawa::operator<<
elm::io::Output & operator<<(elm::io::Output &out, Address addr)
Definition: base.cpp:209
otawa::ContextualPath::p
LockPtr< ContextualList > p
Definition: ContextualProperty.h:215
otawa::ContextualPath::Ref::exists
bool exists(void) const
Definition: ContextualProperty.h:142
get
ret< T > get(const var< T > &v)
count
int count(const C &c, const P &p)
otawa::ContextualPath::ContextualPath
ContextualPath(void)
Definition: ContextualProperty.h:176
elm::LockPtr
otawa::ContextualProperty::Node
Definition: ContextualProperty.h:80
otawa::ContextualPath::Ref::Ref
Ref(const ContextualPath &_cp, PropList &_p, const Identifier< T > &_i)
Definition: ContextualProperty.h:134
exists
bool exists(const C &c, const P &p)
otawa::ContextualPath::operator()
Ref< T > operator()(const Identifier< T > &id, PropList &props) const
Definition: ContextualProperty.h:211
otawa::ContextualProperty::make
static PropList & make(PropList &props, const ContextualPath &path)
Set a contextual property.
Definition: prop_ContextualProperty.cpp:262
otawa::PropList
Definition: PropList.h:67
otawa::ContextualProperty::ID
static AbstractIdentifier ID
Private identifier for contextual properties.
Definition: ContextualProperty.h:104
otawa::ContextualPath::pop
void pop(void)
Definition: ContextualProperty.h:181
otawa::p::print
void print(Output &out, const T &v)
Definition: Identifier.h:43
otawa::Property
Definition: PropList.h:43
otawa::ContextualList::next
LockPtr< ContextualList > next(void) const
Definition: ContextualProperty.h:115
otawa::make
Property * make(const Identifier< T > &id, const T &v)
Definition: info.h:31
otawa::ContextualStep::operator!=
bool operator!=(const ContextualStep &step) const
Definition: ContextualProperty.h:64
otawa::ContextualPath::Ref
Definition: ContextualProperty.h:132
otawa::ContextualList::ContextualList
ContextualList(const ContextualStep &step)
Definition: ContextualProperty.h:110
otawa::ContextualStep::ContextualStep
ContextualStep(kind_t kind, const Address &address)
Definition: ContextualProperty.h:51
otawa::ContextualPath::Ref::operator=
Ref< T > & operator=(const Ref< T > &r)
Definition: ContextualProperty.h:136
otawa::ContextualPath::Ref::p
PropList & p
Definition: ContextualProperty.h:171
otawa
Development Note Letting the ToDo / ToDoList class visible in the header is clumsy.
Definition: ArrayStore.h:25
elm::io::Output
otawa::ContextualPath::step
const ContextualStep & step(int i) const
Definition: ContextualProperty.h:185
otawa::ContextualStep::addr
Address addr
Definition: ContextualProperty.h:70
otawa::ContextualPath::count
int count(void) const
Definition: ContextualProperty.h:184
otawa::ContextualList::operator[]
const ContextualStep & operator[](int i) const
Definition: ContextualProperty.h:118
otawa::ContextualPath::Ref::print
void print(io::Output &out)
Definition: ContextualProperty.h:146
otawa::ContextualStep::ContextualStep
ContextualStep(void)
Definition: ContextualProperty.h:50