Otawa  0.10
ClpState.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  * CLP State definition
4  *
5  * This file is part of OTAWA
6  * Copyright (c) 2011, 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_DATA_CLP_STATE_H_
25 #define OTAWA_DATA_CLP_STATE_H_
26 
27 #include <elm/genstruct/Vector.h>
29 
30 namespace otawa {
31 
32 namespace hard {
33  class Platform;
34  class Register;
35 }
36 
37 namespace clp {
42  class State {
43  public:
44 
48  class Node {
49  public:
50  friend class State;
51  inline Node(void): next(0), addr(0), val(ALL) { }
52  inline Node(t::uint32 address, const Value& value): next(0), addr(address), val(value) { }
53  inline Node(const Node *node): next(0), addr(node->addr), val(node->val) { }
54  inline Node *getNext(void) const { return next; }
55  inline t::uint32 getAddress(void) const { return addr; }
56  inline const Value& getValue(void) const { return val; }
57 
58  private:
62  };
63 
65  State(const Value& def = Value::all): first(0, def) {}
67  State(const State& state): first(0, Value::all){copy(state);}
69  ~State(void) { clear(); }
70 
71  inline State& operator=(const State& state){copy(state); return *this; }
72  inline bool operator==(const State& state) const {
73  return equals(state);
74  }
75 
76  void copy(const State& state);
77  void clear(void);
78  void set(const Value& addr, const Value& val);
80  bool equals(const State& state) const;
81  void join(const State& state);
82  void widening(const State& state, int loopBound);
83  void print(io::Output& out, const hard::Platform *pf = 0) const;
84  const Value& get(const Value& addr) const;
85 
86  static const State EMPTY, FULL;
87 
88  class Iter: public PreIterator<Iter, const Value&> {
89  public:
90  inline Iter(State& s): state(s), i(0), node(state.first.getNext()) { }
91  inline Iter(const Iter& iter): state(iter.state), i(iter.i), node(iter.node) { }
92  inline const Value& item(void) const
93  { if(isReg()) return state.registers[i]; else return node->getValue(); }
94  inline void next(void) { if(isReg()) i++; else node = node->getNext(); }
95  inline bool ended(void) const { return !isReg() && !node; }
96  inline Value id(void) const { if(isReg()) return Value(REG, i); else return Value(VAL, node->getAddress()); }
97 
98  private:
99  inline bool isReg(void) const { return i < state.registers.count(); }
101  int i;
103  };
104 
105  protected:
109  };
110 
111 } // clp
112 
113 } // otawa
114 
115 #endif /* OTAWA_DATA_CLP_STATE_H_ */
int i
Definition: ClpState.h:101
Node * node
Definition: ClpState.h:102
void print(io::Output &out, const hard::Platform *pf=0) const
Print the state.
Definition: clp_analysis.cpp:1340
Value val
Definition: ClpState.h:61
void join(const State &state)
Merge a state with the current one.
Definition: clp_analysis.cpp:1192
static const State FULL
Definition: ClpState.h:86
void next(void)
Definition: ClpState.h:94
void clear(void)
Remove all nodes from the state.
Definition: clp_analysis.cpp:1036
State(const Value &def=Value::all)
Constructors of a new State.
Definition: ClpState.h:65
Definition: ClpValue.h:55
void set(const Value &addr, const Value &val)
Define a value into a register or the memory.
Definition: clp_analysis.cpp:1079
t::uint32 addr
Definition: ClpState.h:60
State(const State &state)
Copy constructor.
Definition: ClpState.h:67
Iter(const Iter &iter)
Definition: ClpState.h:91
const Value & item(void) const
Definition: ClpState.h:92
Value id(void) const
Definition: ClpState.h:96
uint32 size
elm::io::IntFormat address(Address addr)
Build a format to display addresses.
Definition: base.cpp:213
bool isReg(void) const
Definition: ClpState.h:99
genstruct::Vector< Value > registers
Definition: ClpState.h:107
t::uint32 getAddress(void) const
Definition: ClpState.h:55
A set of values represented by a Circular Linear Progression.
Definition: ClpValue.h:66
bool operator==(const State &state) const
Definition: ClpState.h:72
void widening(const State &state, int loopBound)
Perform a widening.
Definition: clp_analysis.cpp:1264
static const Value all
Represents the top element.
Definition: ClpValue.h:221
bool ended(void) const
Definition: ClpState.h:95
Definition: ClpValue.h:57
The abstract state of the computer (abstract domain).
Definition: ClpState.h:42
Node(t::uint32 address, const Value &value)
Definition: ClpState.h:52
sys::SystemOutStream & out
Node(const Node *node)
Definition: ClpState.h:53
Node * next
Definition: ClpState.h:59
Definition: ClpValue.h:56
Node first
Definition: ClpState.h:106
genstruct::Vector< Value > tmpreg
Definition: ClpState.h:108
const Value & getValue(void) const
Definition: ClpState.h:56
This class records information about the architecture where the processed program will run...
Definition: Platform.h:48
State & operator=(const State &state)
Definition: ClpState.h:71
static const State EMPTY
Definition: ClpState.h:86
A node in the memory list.
Definition: ClpState.h:48
bool equals(const State &state) const
Definition: clp_analysis.cpp:1159
void copy(const State &state)
Change the state to be a copy of the given one.
Definition: clp_analysis.cpp:1017
~State(void)
Destructor.
Definition: ClpState.h:69
State & state
Definition: ClpState.h:100
Node(void)
Definition: ClpState.h:51
IntFormat base(int base, IntFormat fmt)
Definition: ClpState.h:88
uint32_t uint32
Node * getNext(void) const
Definition: ClpState.h:54
Iter(State &s)
Definition: ClpState.h:90