Otawa  0.10
PathIter.h
Go to the documentation of this file.
1 /*
2  * PathIter class -- semantics path iterator
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_SEM_PATHITER_H_
22 #define OTAWA_SEM_PATHITER_H_
23 
24 #include <otawa/prog/Inst.h>
25 #include <otawa/sem/inst.h>
26 
27 namespace otawa { namespace sem {
28 
29 class PathIter: public PreIterator<PathIter, sem::inst> {
30 public:
31 
32  inline void start(Inst *inst) {
33  bb.clear();
34  _inst = inst;
35  inst->semInsts(bb);
36  todo.clear();
37  pc = 0;
38  bb.add(sem::cont());
39  }
40 
41  inline bool pathEnd(void) const { return bb[pc].op == sem::CONT; }
42  inline bool isCond(void) const { return bb[pc].op == sem::IF; }
43 
44  inline bool ended(void) const { return pathEnd() && !todo; }
45  inline sem::inst item(void) const { return bb[pc]; }
46  inline void next(void) {
47  if(pathEnd())
48  pc = todo.pop();
49  else {
50  if(isCond())
51  todo.push(pc + bb[pc].jump());
52  pc++;
53  }
54  }
55 
56  inline opcode op(void) const { return opcode(item().op); }
57  inline t::int16 d(void) const { return item().d(); }
58  inline t::int16 a(void) const { return item().a(); }
59  inline t::int16 b(void) const { return item().b(); }
60  inline t::uint32 cst(void) const { return item().cst(); }
61  inline t::uint32 reg(void) const { return item().reg(); }
62  inline t::uint32 addr(void) const { return item().addr(); }
63 
64 private:
68  int pc;
69 };
70 
71 } } // otawa::sem
72 
73 #endif /* OTAWA_SEM_PATHITER_H_ */
struct otawa::sem::inst inst
t::int16 b
Definition: inst.h:115
t::uint32 addr(void) const
Definition: PathIter.h:62
void start(Inst *inst)
Definition: PathIter.h:32
t::int16 a
Definition: inst.h:115
bool pathEnd(void) const
Test if the current instruction is a path end.
Definition: PathIter.h:41
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::uint32 reg(void) const
Definition: PathIter.h:61
sem::Block bb
Definition: PathIter.h:66
t::int16 addr(void) const
Definition: inst.h:136
sem::inst item(void) const
Definition: PathIter.h:45
A block represents a sequence of semantic instructions inst.
Definition: inst.h:183
Inst * _inst
Definition: PathIter.h:65
t::int16 reg(void) const
Definition: inst.h:135
opcode op(void) const
Definition: PathIter.h:56
Definition: inst.h:45
void next(void)
Definition: PathIter.h:46
int16_t int16
t::int16 b(void) const
Definition: PathIter.h:59
genstruct::Vector< int > todo
Definition: PathIter.h:67
inst cont(void)
Definition: inst.h:151
t::int16 a(void) const
Definition: PathIter.h:58
bool ended(void) const
Definition: PathIter.h:44
opcode
Definition: inst.h:40
int pc
Definition: PathIter.h:68
virtual void semInsts(sem::Block &block)
Return a list of semantics pseudo-instruction representing the effect of the instruction.
Definition: instruction.cpp:413
t::int16 d(void) const
Definition: inst.h:127
Definition: inst.h:44
void push(const T &value)
t::uint32 cst
Definition: inst.h:114
This class represents assembly instruction of a piece of code.
Definition: Inst.h:62
t::uint32 cst(void) const
Definition: PathIter.h:60
This structure class represents an instruction in the semantics representation of machine instruction...
Definition: inst.h:110
t::int16 d(void) const
Definition: PathIter.h:57
This iterator allows easily to traverse all execution paths of a block of semantic instructions...
Definition: PathIter.h:29
uint32_t uint32