Otawa  0.10
features.h
Go to the documentation of this file.
1 /*
2  * stack module features
3  *
4  * This file is part of OTAWA
5  * Copyright (c) 2015, 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
20  * 02110-1301 USA
21  */
22 #ifndef OTAWA_STACK_FEATURES_H_
23 #define OTAWA_STACK_FEATURES_H_
24 
25 #include <otawa/sem/PathIter.h>
26 
27 namespace otawa {
28 
29 class StackProblem;
30 
31 namespace stack {
32 
33 class State;
34 
35 typedef enum {
37  REG, // only used for addresses
38  SP,
39  CST,
41 } kind_t;
42 
43 class Value {
44 public:
45  typedef t::uint32 int_t;
46  typedef t::int32 signed_t;
47  typedef t::uint64 upper_t;
48 private:
49  static const int_t
50  bot_id = -1,
51  top_id = -2;
52  typedef t::int32 page_t;
53  static const page_t
56 
57  inline Value(page_t page, int_t val = 0): _page(page), _val(val) { }
58 
59 public:
60 
61  static Value bot, top;
62  inline Value(void): _page(spec_page), _val(bot_id) { }
63  Value(kind_t k, int_t v = 0);
64  static inline Value reg(int n) { return Value(spec_page, n); }
65  static inline Value addr(Address a) { return Value(a); }
66  static inline Value cst(int_t k) { return Value(0, k); }
67  static inline Value sp(int_t off) { return Value(sp_page, off); }
68  inline Value& operator=(const Value& val) { _page = val._page; _val = val._val; return *this; }
69 
70  inline bool isTop(void) const { return _page == spec_page && _val == top_id; }
71  inline bool isBot(void) const { return _page == spec_page && _val == bot_id; }
72  inline bool isReg(void) const { return _page == spec_page && _val >= 0; }
73  inline bool isSP(void) const { return _page == sp_page; }
74  inline bool isConst(void) const { return _page > sp_page; }
75 
76  inline bool operator==(const Value& val) const { return _page == val._page && _val == val._val; }
77  inline bool operator!=(const Value& val) const { return ! operator==(val); }
78  inline bool operator<(const Value& val) const { return (_page < val._page) || (_page == val._page && _val < val._val); }
79 
80  kind_t kind(void) const;
81  inline int_t value(void) const { return _val; }
82 
83  void add(const Value& val);
84  void sub(const Value& val);
85  void shl(const Value& val);
86  void shr(const Value& val);
87  void asr(const Value& val);
88  void neg(void);
89  void _not(void);
90  void _or(const Value& val);
91  void _and(const Value& val);
92  void _xor(const Value& val);
93  void mul(const Value& val);
94  void div(const Value& val);
95  void divu(const Value& val);
96  void mod(const Value& val);
97  void modu(const Value& val);
98  void mulh(const Value& val);
99  void join(const Value& val);
100  void print(io::Output& out) const;
101 
102  static const Value& none, all;
103 
104 private:
105  inline void set(page_t kind, int_t value) { _page = kind; _val = value; }
108 };
109 
110 inline io::Output& operator<<(io::Output& out, const Value& v) { v.print(out); return out; }
111 io::Output& operator<<(io::Output& out, const State& state);
112 
113 
114 class Iter: public PreIterator<Iter, sem::inst> {
115 public:
116  Iter(WorkSpace *ws);
117  ~Iter(void);
118 
119  void start(BasicBlock *bb);
120 
121  inline bool pathEnd(void) const { return si.pathEnd(); }
122  inline bool isCond(void) const { return si.isCond(); }
123  inline bool instEnd(void) const { return si.ended(); }
124 
125  inline bool ended(void) const { return i.ended() && si.ended(); }
126  inline sem::inst item(void) const { return si.item(); }
127  void next(void);
128  void nextInst(void);
129 
130  inline State& state(void) const { return *s; }
131  Value getReg(int i);
132  Value getMem(Value addr, int size);
133  inline Inst *instruction(void) const { return *i; }
134 
135 private:
139  State *s, *es;
141  StackProblem *p;
142 };
143 
145 
146 } // stack
147 
149 
150 } // otawa
151 
152 #endif /* OTAWA_STACK_FEATURES_H_ */
sem::PathIter si
Definition: features.h:137
Values in the StackAnalysis.
Definition: features.h:43
Value & operator=(const Value &val)
Definition: features.h:68
void print(io::Output &out) const
Print the value.
Definition: util_StackAnalysis.cpp:297
bool pathEnd(void) const
Test if the current instruction is a path end.
Definition: PathIter.h:41
Value(page_t page, int_t val=0)
Definition: features.h:57
kind_t
Definition: features.h:35
Feature< StackAnalysis > STACK_ANALYSIS_FEATURE
This features ensure that the stack analysis has been identified.
Definition: features.h:148
bool isCond(void) const
Test if the current instruction is a conditional, that means that two different paths will be created...
Definition: PathIter.h:42
t::int32 page_t
Definition: features.h:52
sem::inst item(void) const
Definition: features.h:126
Definition: features.h:39
Inst * instruction(void) const
Definition: features.h:133
void sub(const Value &val)
Perform subtraction of values.
Definition: util_StackAnalysis.cpp:157
bool operator!=(const Value &val) const
Definition: features.h:77
Value(void)
Definition: features.h:62
static Value reg(int n)
Definition: features.h:64
static Value addr(Address a)
Definition: features.h:65
int_t value(void) const
Definition: features.h:81
static Value bot
Bottom value (uninitialized value).
Definition: features.h:61
int32_t int32
static const page_t null_page
Definition: base.h:59
t::int32 signed_t
Definition: features.h:46
bool operator<(const Value &val) const
Definition: features.h:78
sem::inst item(void) const
Definition: PathIter.h:45
static const int_t bot_id
Definition: features.h:50
void nextInst(void)
Compute the state at the end of the instruction.
Definition: util_StackAnalysis.cpp:1042
bool pathEnd(void) const
Definition: features.h:121
void _xor(const Value &val)
Perform XOR operator on values (modifying current one).
Definition: util_StackAnalysis.cpp:200
State & state(void) const
Definition: features.h:130
Definition: features.h:40
StackProblem * p
Definition: features.h:141
dtd::Element bb(dtd::make("bb", _BB).attr(id).attr(address).attr(size))
Definition: features.h:36
State * es
Definition: features.h:139
void _or(const Value &val)
Perform OR operator on values (modifying current one).
Definition: util_StackAnalysis.cpp:172
A block represents a sequence of semantic instructions inst.
Definition: inst.h:183
Value getReg(int i)
Get register value.
Definition: util_StackAnalysis.cpp:1054
void asr(const Value &val)
Arithmetic right-shift on a value.
Definition: util_StackAnalysis.cpp:345
void add(const Value &val)
Perform addition of values.
Definition: util_StackAnalysis.cpp:139
void start(BasicBlock *bb)
Start the state calculation for a new basic block.
Definition: util_StackAnalysis.cpp:973
t::uint64 upper_t
Definition: features.h:47
void mod(const Value &val)
Perform modulo on values (modifying current one).
Definition: util_StackAnalysis.cpp:256
uint32 size
kind_t kind(void) const
Get the kind of the value.
Definition: util_StackAnalysis.cpp:110
bool ended(void) const
Definition: features.h:125
void shr(const Value &val)
Right-shift on a value.
Definition: util_StackAnalysis.cpp:332
Iterator on the result of stack analysis.
Definition: features.h:114
Definition: features.h:38
bool isBot(void) const
Definition: features.h:71
void neg(void)
Invert sign of value.
Definition: util_StackAnalysis.cpp:358
void divu(const Value &val)
Perform division on values (modifying current one).
Definition: util_StackAnalysis.cpp:242
~Iter(void)
Definition: util_StackAnalysis.cpp:963
bool isConst(void) const
Definition: features.h:74
bool isTop(void) const
Definition: features.h:70
bool ended(void) const
Definition: PathIter.h:44
void shl(const Value &val)
Left-shit on a value.
Definition: util_StackAnalysis.cpp:319
A workspace represents a program, its run-time and all information about WCET computation or any othe...
Definition: WorkSpace.h:67
Value getMem(Value addr, int size)
Get value from memory.
Definition: util_StackAnalysis.cpp:1065
void set(page_t kind, int_t value)
Definition: features.h:105
The representation of an address in OTAWA.
Definition: base.h:54
static const Value all
undefined value
Definition: features.h:102
sem::Block b
Definition: features.h:136
bool instEnd(void) const
Definition: features.h:123
sys::SystemOutStream & out
State * s
Definition: features.h:139
static Value top
Top value (any value).
Definition: features.h:61
void mulh(const Value &val)
Compute upper-word multiplication on values (modifying current one).
Definition: util_StackAnalysis.cpp:284
BasicBlock::InstIter i
Definition: features.h:138
static const page_t spec_page
Definition: features.h:54
void modu(const Value &val)
Perform modulo on values (modifying current one).
Definition: util_StackAnalysis.cpp:270
void next(void)
Compute the state for the next semantic instruction.
Definition: util_StackAnalysis.cpp:991
io::Output & operator<<(io::Output &out, const Value &v)
Definition: features.h:110
p::feature ADDRESS_FEATURE
Feature ensuring that addresses are built from stack analysis.
This is the minimal definition of a basic block.
Definition: BasicBlock.h:43
void _not(void)
Invert bits of the value.
Definition: util_StackAnalysis.cpp:371
bool isSP(void) const
Definition: features.h:73
bool ended(void) const
Definition: BasicBlock.h:76
This class represents assembly instruction of a piece of code.
Definition: Inst.h:62
bool operator==(const Value &val) const
Definition: features.h:76
void mul(const Value &val)
Perform MUL operator on values (modifying current one).
Definition: util_StackAnalysis.cpp:214
Definition: features.h:37
static const int_t top_id
Definition: features.h:51
static const Value & none
Definition: features.h:102
bool isReg(void) const
Definition: features.h:72
Iter(WorkSpace *ws)
Definition: util_StackAnalysis.cpp:957
static Value sp(int_t off)
Definition: features.h:67
page_t _page
Definition: features.h:106
This structure class represents an instruction in the semantics representation of machine instruction...
Definition: inst.h:110
This iterator allows easily to traverse all execution paths of a block of semantic instructions...
Definition: PathIter.h:29
void _and(const Value &val)
Perform AND operator on values (modifying current one).
Definition: util_StackAnalysis.cpp:186
void join(const Value &val)
Join of values.
Definition: util_StackAnalysis.cpp:384
genstruct::Vector< State * > ss
Definition: features.h:140
t::uint32 int_t
Definition: features.h:45
static const page_t sp_page
Definition: features.h:55
static Value cst(int_t k)
Definition: features.h:66
int_t _val
Definition: features.h:107
Shortcut to create a feature with a maker (without the mess of SilentFeature).
Definition: AbstractFeature.h:51
uint32_t uint32
uint64_t uint64
void div(const Value &val)
Perform division on values (modifying current one).
Definition: util_StackAnalysis.cpp:228
Iterator for instructions in the basic block.
Definition: BasicBlock.h:70
bool isCond(void) const
Definition: features.h:122