Otawa  0.10
State.h
Go to the documentation of this file.
1 /*
2  * dfa::State class -- state description for data flow analysis.
3  *
4  * This file is part of OTAWA
5  * Copyright (c) 2014, IRIT UPS.
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_DFA_STATE_H_
22 #define OTAWA_DFA_STATE_H_
23 
24 #include <elm/avl/Map.h>
25 #include <elm/stree/Tree.h>
26 #include <otawa/base.h>
27 #include <otawa/prog/Process.h>
28 
29 namespace otawa {
30 
31 namespace hard { class Register; }
32 
33 namespace dfa {
34 
35 using namespace elm;
36 
37 class Value {
38 public:
39  typedef enum {
40  NONE = 0,
41  CONST = 1,
42  INTERVAL = 2,
43  CLP = 3
44  } kind_t;
45 
46  Value(void);
47  Value(t::uint32 base);
48  Value(t::uint32 lo, t::uint32 up);
49  Value(t::uint32 base, t::uint32 delta, t::uint32 count);
50  static Value parse(const string& str) throw(io::IOException);
51 
52  inline kind_t kind(void) const { return _kind; }
53  inline operator bool(void) const { return _kind != NONE; }
54  inline bool isConst(void) const { return _kind > NONE && _kind <= CONST; }
55  inline bool isInterval(void) const { return _kind > NONE && _kind <= INTERVAL; }
56  inline bool isCLP(void) const { return _kind > NONE && _kind <= CLP; }
57 
58  inline t::uint32 value(void) const { return _base; }
59  inline t::uint32 base(void) const { return _base; }
60  inline t::uint32 delta(void) const { return _delta; }
61  inline t::uint32 count(void) const { return _count; }
62  inline t::uint32 low(void) const { return _base; }
63  inline t::uint32 up(void) const { return _base + _delta * _count; }
64 
65 private:
70 };
71 
72 
73 class MemCell {
74 public:
75  inline MemCell(void): _type(&Type::no_type) { }
76  inline MemCell(Address addr, const Type *type, Value val): _addr(addr), _type(type), _val(val) { }
77  inline Address address(void) const { return _addr; }
78  inline const Type *type(void) const { return _type; }
79  inline const Value& value(void) const { return _val; }
80 private:
82  const Type *_type;
84 };
85 
86 class State {
89 public:
90 
92  State(Process& process);
93  inline Process& process(void) const { return proc; }
94 
95  // accessing registers
96  void set(const hard::Register *reg, Value value);
97  Value get(const hard::Register *reg) const;
98  class RegIter: public reg_map_t::PairIterator {
99  public:
100  inline RegIter(State *state): reg_map_t::PairIterator(state->regs) { }
101  inline RegIter(const RegIter& i): reg_map_t::PairIterator(i) { }
102  };
103 
104  // accessing configured memory
105  void record(const MemCell& cell);
106  class MemIter: public mem_map_t::Iterator {
107  public:
108  inline MemIter(State *state): mem_map_t::Iterator(state->cmem) { }
109  inline MemIter(const MemIter& iter): mem_map_t::Iterator(iter) { }
110  };
111 
112  // accessing initialized memory
113  inline bool isInitialized(Address addr) const { return mem.get(addr.offset(), false); }
114  inline void get(const Address& a, t::uint8 &v) const { proc.get(a, v); }
115  inline void get(const Address& a, t::uint16 &v) const { proc.get(a, v); }
116  inline void get(const Address& a, t::uint32 &v) const { proc.get(a, v); }
117  inline void get(const Address& a, t::uint64 &v) const { proc.get(a, v); }
118  inline void get(const Address& a, float &v) const { proc.get(a, v); }
119  inline void get(const Address& a, double &v) const { proc.get(a, v); }
120  inline void get(const Address& a, Address &v) const { proc.get(a, v); }
121 
122 private:
127 };
128 
133 
134 } } // otawa::dfa
135 
136 #endif /* OTAWA_DFA_STATE_H_ */
reg_map_t regs
Definition: State.h:123
const Type * _type
Definition: State.h:82
stree::Tree< address_t, bool > mem
Definition: State.h:124
Definition: ClpValue.h:54
t::uint32 count(void) const
Get the count value of a CLP.
Definition: State.h:61
bool isInterval(void) const
Definition: State.h:55
avl::Map< Address, MemCell > mem_map_t
Definition: State.h:88
avl::Map< const hard::Register *, Value > reg_map_t
Definition: State.h:87
Definition: SymbolicExpr.h:51
Value _val
Definition: State.h:83
t::uint32 _base
Definition: State.h:67
Definition: State.h:73
kind_t
Definition: State.h:39
StringOption proc(command, 'p',"processor","used processor","path","")
IntOption delta(command, 'D',"delta","use delta method with given sequence length","length", 4)
t::uint32 base(void) const
Get base value of a CLP.
Definition: State.h:59
const Value & value(void) const
Definition: State.h:79
t::uint32 value(void) const
Get the value for a constant.
Definition: State.h:58
kind_t
Allowed types for values: NONE represents nothing; REG is only used for addresses, and represents a register; VAL represents some values (either a constant or an interval); ALL is the Top element.
Definition: ClpValue.h:53
t::uint32 delta(void) const
Get the delta value of a CLP.
Definition: State.h:60
MemCell(Address addr, const Type *type, Value val)
Definition: State.h:76
offset_t offset(void) const
Get the offset value.
Definition: base.h:70
A process is the realization of a program on a platform.
Definition: Process.h:136
The representation of an address in OTAWA.
Definition: base.h:54
Process & proc
Definition: State.h:126
t::uint32 _count
Definition: State.h:69
Represents a value of the data state.
Definition: State.h:86
Identifier< State * > INITIAL_STATE
This attribute provides the initial state of the task.
t::uint32 up(void) const
Get the upper value of the interval.
Definition: State.h:63
uint8_t uint8
MemIter(const MemIter &iter)
Definition: State.h:109
t::uint32 address_t
Definition: State.h:91
kind_t kind(void) const
Get the kind of the value.
Definition: State.h:52
bool isInitialized(Address addr) const
Test if the current state contains initialized data.
Definition: State.h:113
bool isConst(void) const
Definition: State.h:54
MemIter(State *state)
Definition: State.h:108
Identifier< Pair< const hard::Register *, Value > > REG_INIT
This configuration attribute allows to specify an initial value for a register.
RegIter(State *state)
Definition: State.h:100
const Type * type(void) const
Definition: State.h:78
p::feature INITIAL_STATE_FEATURE
This feature ensures that the executable and user information have been parsed to make the initial st...
This class represents identifier with a typed associated value.
Definition: Identifier.h:51
Identifier< MemCell > MEM_INIT
This configuration attribute allows to specify an initial value for a memory cell.
Address _addr
Definition: State.h:81
RegIter(const RegIter &i)
Definition: State.h:101
MemCell(void)
Definition: State.h:75
bool isCLP(void) const
Definition: State.h:56
Process & process(void) const
Definition: State.h:93
Objects of this class are simple machine register, more accurately unbreakable atomic registers...
Definition: Register.h:38
t::uint32 _delta
Definition: State.h:68
const Type & type(void)
Definition: type.h:163
Definition: State.h:98
Definition: State.h:37
mem_map_t cmem
Definition: State.h:125
This class describes the type of the data in the program.
Definition: type.h:39
kind_t _kind
Definition: State.h:66
t::uint32 low(void) const
Get the lower value of the interval.
Definition: State.h:62
uint16_t uint16
Shortcut to create a feature with a maker (without the mess of SilentFeature).
Definition: AbstractFeature.h:51
uint32_t uint32
uint64_t uint64
Address address(void) const
Definition: State.h:77
Definition: State.h:106