Predator
[unstable] git snapshot
Main Page
Related Pages
Namespaces
Data Structures
Files
File List
Globals
fixed_point_rewrite.hh
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2014 Kamil Dudka <kdudka@redhat.com>
3
*
4
* This file is part of predator.
5
*
6
* predator is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* any later version.
10
*
11
* predator is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with predator. If not, see <http://www.gnu.org/licenses/>.
18
*/
19
20
#ifndef H_GUARD_FIXED_POINT_REWRITE_H
21
#define H_GUARD_FIXED_POINT_REWRITE_H
22
23
#include "
fixed_point.hh
"
24
25
namespace
FixedPoint {
26
27
class
IStateRewriter
{
28
public
:
29
virtual
~IStateRewriter
() { }
30
virtual
void
insertInsn
(
TLocIdx
src,
TLocIdx
dst,
GenericInsn
*) = 0;
31
virtual
void
replaceInsn
(
TLocIdx
at,
GenericInsn
*insn) = 0;
32
virtual
void
dropInsn
(
TLocIdx
at) = 0;
33
virtual
void
dropEdge
(
TLocIdx
src,
TLocIdx
dst) = 0;
34
virtual
void
redirEdge
(
TLocIdx
from,
TLocIdx
to,
TLocIdx
redirTo) = 0;
35
};
36
37
class
MultiRewriter
:
public
IStateRewriter
{
38
public
:
39
virtual
void
insertInsn
(
TLocIdx
src,
TLocIdx
dst,
GenericInsn
*insn);
40
virtual
void
replaceInsn
(
TLocIdx
at,
GenericInsn
*insn);
41
virtual
void
dropInsn
(
TLocIdx
at);
42
virtual
void
dropEdge
(
TLocIdx
src,
TLocIdx
dst);
43
virtual
void
redirEdge
(
TLocIdx
from,
TLocIdx
to,
TLocIdx
redirTo);
44
45
/// does NOT take ownership of writer
46
void
appendWriter
(
IStateRewriter
&slave);
47
48
private
:
49
std::vector<IStateRewriter *>
slaveList_
;
50
};
51
52
class
RecordRewriter
:
public
IStateRewriter
{
53
public
:
54
RecordRewriter
();
55
virtual
~RecordRewriter
();
56
57
virtual
void
insertInsn
(
TLocIdx
src,
TLocIdx
dst,
GenericInsn
*insn);
58
virtual
void
replaceInsn
(
TLocIdx
at,
GenericInsn
*insn);
59
virtual
void
dropInsn
(
TLocIdx
at);
60
virtual
void
dropEdge
(
TLocIdx
src,
TLocIdx
dst);
61
virtual
void
redirEdge
(
TLocIdx
from,
TLocIdx
to,
TLocIdx
redirTo);
62
63
// apply the changes in the same order as they came; and drop them
64
void
flush
(
IStateRewriter
*pConsumer);
65
66
bool
empty
()
const
;
67
68
private
:
69
RecordRewriter
(
const
RecordRewriter
&);
70
RecordRewriter
&
operator=
(
const
RecordRewriter
&);
71
72
private
:
73
struct
Private;
74
Private *
d
;
75
};
76
77
class
StateRewriter
:
public
IStateRewriter
{
78
public
:
79
/// *pState has to be valid till the destruction of StateRewriter
80
StateRewriter
(
GlobalState
*pState);
81
82
~StateRewriter
();
83
84
/// takes ownership of *insn
85
virtual
void
insertInsn
(
TLocIdx
src,
TLocIdx
dst,
GenericInsn
*insn);
86
87
/// takes ownership of *insn
88
virtual
void
replaceInsn
(
TLocIdx
at,
GenericInsn
*insn);
89
90
virtual
void
dropInsn
(
TLocIdx
at);
91
92
virtual
void
dropEdge
(
TLocIdx
src,
TLocIdx
dst);
93
94
virtual
void
redirEdge
(
TLocIdx
from,
TLocIdx
to,
TLocIdx
redirTo);
95
96
bool
/* any change */
dedupOutgoingEdges
(
TLocIdx
at);
97
98
void
mergeInsns
(
TLocIdx
locAt,
TLocIdx
locWith);
99
100
private
:
101
struct
Private;
102
Private *
d
;
103
};
104
105
enum
EVarLevel
{
106
VL_NONE
,
107
VL_CODE_LISTENER
,
108
VL_CONTAINER_VAR
,
109
VL_COND_VAR
110
};
111
112
typedef
int
TBoolVarId
;
113
114
struct
GenericVar
{
115
EVarLevel
code
;
116
int
uid
;
117
118
GenericVar
():
119
code
(
VL_NONE
),
120
uid
(0)
121
{
122
}
123
124
GenericVar
(
const
EVarLevel
code_,
const
int
uid_):
125
code
(code_),
126
uid
(uid_)
127
{
128
}
129
};
130
131
/// required by std::set<GenericVar>
132
inline
bool
operator<
(
const
GenericVar
&a,
const
GenericVar
&b)
133
{
134
RETURN_IF_COMPARED
(a, b, code);
135
RETURN_IF_COMPARED
(a, b, uid);
136
return
false
;
137
}
138
139
/// required by operator== over std::set<GenericVar>
140
inline
bool
operator==
(
const
GenericVar
&a,
const
GenericVar
&b)
141
{
142
return
a.
code
== b.
code
143
&& a.
uid
== b.
uid
;
144
}
145
inline
bool
operator!=
(
const
GenericVar
&a,
const
GenericVar
&b)
146
{
147
return
!
operator==
(a, b);
148
}
149
150
typedef
std::set<GenericVar>
TGenericVarSet
;
151
152
class
AnnotatedInsn
:
public
GenericInsn
{
153
public
:
154
virtual
const
TGenericVarSet
&
liveVars
()
const
= 0;
155
virtual
const
TGenericVarSet
&
killVars
()
const
= 0;
156
};
157
158
class
ClInsn
:
public
AnnotatedInsn
{
159
public
:
160
ClInsn
(
TInsn
insn):
161
insn_
(insn),
162
done_
(false)
163
{
164
}
165
166
virtual
void
writeToStream
(std::ostream &str)
const
;
167
168
virtual
const
TGenericVarSet
&
liveVars
()
const
;
169
virtual
const
TGenericVarSet
&
killVars
()
const
;
170
171
virtual
TInsn
clInsn
()
const
172
{
173
return
insn_
;
174
}
175
176
private
:
177
TInsn
insn_
;
178
mutable
TGenericVarSet
live_
;
179
mutable
TGenericVarSet
kill_
;
180
mutable
bool
done_
;
181
182
virtual
GenericInsn
*
doClone
()
const
183
{
184
return
new
ClInsn
(*
this
);
185
}
186
187
void
lazyInit
()
const
;
188
};
189
190
class
TextInsn
:
public
AnnotatedInsn
{
191
public
:
192
TextInsn
(
193
const
std::string &text,
194
const
TGenericVarSet
&live,
195
const
TGenericVarSet
&kill):
196
text_
(text),
197
live_
(live),
198
kill_
(kill)
199
{
200
}
201
202
virtual
void
writeToStream
(std::ostream &str)
const
;
203
204
virtual
const
TGenericVarSet
&
liveVars
()
const
205
{
206
return
live_
;
207
}
208
209
virtual
const
TGenericVarSet
&
killVars
()
const
210
{
211
return
kill_
;
212
}
213
214
virtual
TInsn
clInsn
()
const
215
{
216
return
0;
217
}
218
219
private
:
220
const
std::string
text_
;
221
const
TGenericVarSet
live_
;
222
const
TGenericVarSet
kill_
;
223
224
virtual
GenericInsn
*
doClone
()
const
225
{
226
return
new
TextInsn
(*
this
);
227
}
228
};
229
230
}
// namespace FixedPoint
231
232
#endif
/* H_GUARD_FIXED_POINT_REWRITE_H */
Generated on Mon Nov 9 2015 14:51:59 for Predator by
1.8.1.2