1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
|
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/
**
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QV4INSTRUCTION_P_H
#define QV4INSTRUCTION_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include <QtCore/qglobal.h>
#include <QtCore/qbytearray.h>
#include <QtCore/qvector.h>
#include <QtCore/qvarlengtharray.h>
#include <private/qdeclarativepropertycache_p.h>
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
#define FOR_EACH_V4_INSTR(F) \
F(Noop, common) \
F(BindingId, id) \
F(Subscribe, subscribeop) \
F(SubscribeId, subscribeop) \
F(FetchAndSubscribe, fetchAndSubscribe) \
F(LoadId, load) \
F(LoadScope, load) \
F(LoadRoot, load) \
F(LoadAttached, attached) \
F(UnaryNot, unaryop) \
F(UnaryMinusReal, unaryop) \
F(UnaryMinusInt, unaryop) \
F(UnaryPlusReal, unaryop) \
F(UnaryPlusInt, unaryop) \
F(ConvertBoolToInt, unaryop) \
F(ConvertBoolToReal, unaryop) \
F(ConvertBoolToString, unaryop) \
F(ConvertIntToBool, unaryop) \
F(ConvertIntToReal, unaryop) \
F(ConvertIntToString, unaryop) \
F(ConvertRealToBool, unaryop) \
F(ConvertRealToInt, unaryop) \
F(ConvertRealToString, unaryop) \
F(ConvertStringToBool, unaryop) \
F(ConvertStringToInt, unaryop) \
F(ConvertStringToReal, unaryop) \
F(ConvertStringToUrl, unaryop) \
F(ConvertUrlToBool, unaryop) \
F(ConvertUrlToString, unaryop) \
F(ResolveUrl, unaryop) \
F(MathSinReal, unaryop) \
F(MathCosReal, unaryop) \
F(MathRoundReal, unaryop) \
F(MathFloorReal, unaryop) \
F(MathPIReal, unaryop) \
F(LoadReal, real_value) \
F(LoadInt, int_value) \
F(LoadBool, bool_value) \
F(LoadString, string_value) \
F(EnableV4Test, string_value) \
F(TestV4Store, storetest) \
F(BitAndInt, binaryop) \
F(BitOrInt, binaryop) \
F(BitXorInt, binaryop) \
F(AddReal, binaryop) \
F(AddString, binaryop) \
F(SubReal, binaryop) \
F(MulReal, binaryop) \
F(DivReal, binaryop) \
F(ModReal, binaryop) \
F(LShiftInt, binaryop) \
F(RShiftInt, binaryop) \
F(URShiftInt, binaryop) \
F(GtReal, binaryop) \
F(LtReal, binaryop) \
F(GeReal, binaryop) \
F(LeReal, binaryop) \
F(EqualReal, binaryop) \
F(NotEqualReal, binaryop) \
F(StrictEqualReal, binaryop) \
F(StrictNotEqualReal, binaryop) \
F(GtString, binaryop) \
F(LtString, binaryop) \
F(GeString, binaryop) \
F(LeString, binaryop) \
F(EqualString, binaryop) \
F(NotEqualString, binaryop) \
F(StrictEqualString, binaryop) \
F(StrictNotEqualString, binaryop) \
F(NewString, construct) \
F(NewUrl, construct) \
F(CleanupRegister, cleanup) \
F(Copy, copy) \
F(Fetch, fetch) \
F(Store, store) \
F(Jump, jump) \
F(BranchTrue, branchop) \
F(BranchFalse, branchop) \
F(Branch, branchop) \
F(Block, blockop) \
/* Speculative property resolution */ \
F(InitString, initstring)
#if defined(Q_CC_GNU) && (!defined(Q_CC_INTEL) || __INTEL_COMPILER >= 1200)
# define QML_THREADED_INTERPRETER
#endif
#ifdef Q_ALIGNOF
# define QML_V4_INSTR_ALIGN_MASK (Q_ALIGNOF(V4Instr) - 1)
#else
# define QML_V4_INSTR_ALIGN_MASK (sizeof(void *) - 1)
#endif
#define QML_V4_INSTR_ENUM(I, FMT) I,
#define QML_V4_INSTR_ADDR(I, FMT) &&op_##I,
#define QML_V4_INSTR_SIZE(I, FMT) ((sizeof(V4Instr::instr_##FMT) + QML_V4_INSTR_ALIGN_MASK) & ~QML_V4_INSTR_ALIGN_MASK)
#ifdef QML_THREADED_INTERPRETER
# define QML_V4_BEGIN_INSTR(I,FMT) op_##I:
# define QML_V4_END_INSTR(I,FMT) code += QML_V4_INSTR_SIZE(I, FMT); instr = (const V4Instr *) code; goto *instr->common.code;
# define QML_V4_INSTR_HEADER void *code;
#else
# define QML_V4_BEGIN_INSTR(I,FMT) case V4Instr::I:
# define QML_V4_END_INSTR(I,FMT) code += QML_V4_INSTR_SIZE(I, FMT); instr = (const V4Instr *) code; break;
# define QML_V4_INSTR_HEADER quint8 type;
#endif
class QObject;
class QDeclarativeNotifier;
namespace QDeclarativeJS {
union V4Instr {
enum Type {
FOR_EACH_V4_INSTR(QML_V4_INSTR_ENUM)
};
static int size(Type type);
struct instr_common {
QML_V4_INSTR_HEADER
};
struct instr_id {
QML_V4_INSTR_HEADER
quint16 column;
quint32 line;
};
struct instr_init {
QML_V4_INSTR_HEADER
quint16 subscriptions;
quint16 identifiers;
};
struct instr_subscribeop {
QML_V4_INSTR_HEADER
qint8 reg;
quint16 offset;
quint32 index;
};
struct instr_load {
QML_V4_INSTR_HEADER
qint8 reg;
quint32 index;
};
struct instr_attached {
QML_V4_INSTR_HEADER
qint8 output;
qint8 reg;
quint8 exceptionId;
quint32 id;
};
struct instr_store {
QML_V4_INSTR_HEADER
qint8 output;
qint8 reg;
quint8 exceptionId;
quint32 index;
};
struct instr_storetest {
QML_V4_INSTR_HEADER
qint8 reg;
qint32 regType;
};
struct instr_fetchAndSubscribe {
QML_V4_INSTR_HEADER
qint8 reg;
quint8 exceptionId;
quint8 valueType;
quint16 subscription;
QDeclarativePropertyRawData property;
};
struct instr_fetch{
QML_V4_INSTR_HEADER
qint8 reg;
quint8 exceptionId;
quint8 valueType;
quint32 index;
};
struct instr_copy {
QML_V4_INSTR_HEADER
qint8 reg;
qint8 src;
};
struct instr_construct {
QML_V4_INSTR_HEADER
qint8 reg;
};
struct instr_real_value {
QML_V4_INSTR_HEADER
qint8 reg;
qreal value; // XXX Makes the instruction 12 bytes
};
struct instr_int_value {
QML_V4_INSTR_HEADER
qint8 reg;
int value;
};
struct instr_bool_value {
QML_V4_INSTR_HEADER
qint8 reg;
bool value;
};
struct instr_string_value {
QML_V4_INSTR_HEADER
qint8 reg;
quint16 length;
quint32 offset;
};
struct instr_binaryop {
QML_V4_INSTR_HEADER
qint8 output;
qint8 left;
qint8 right;
};
struct instr_unaryop {
QML_V4_INSTR_HEADER
qint8 output;
qint8 src;
};
struct instr_jump {
QML_V4_INSTR_HEADER
qint8 reg;
quint32 count;
};
struct instr_find {
QML_V4_INSTR_HEADER
qint8 reg;
qint8 src;
quint8 exceptionId;
quint16 name;
quint16 subscribeIndex;
};
struct instr_cleanup {
QML_V4_INSTR_HEADER
qint8 reg;
};
struct instr_initstring {
QML_V4_INSTR_HEADER
quint16 offset;
quint32 dataIdx;
};
struct instr_branchop {
QML_V4_INSTR_HEADER
quint8 reg;
qint16 offset;
};
struct instr_blockop {
QML_V4_INSTR_HEADER
quint32 block;
};
instr_common common;
instr_id id;
instr_init init;
instr_subscribeop subscribeop;
instr_load load;
instr_attached attached;
instr_store store;
instr_storetest storetest;
instr_fetchAndSubscribe fetchAndSubscribe;
instr_fetch fetch;
instr_copy copy;
instr_construct construct;
instr_real_value real_value;
instr_int_value int_value;
instr_bool_value bool_value;
instr_string_value string_value;
instr_binaryop binaryop;
instr_unaryop unaryop;
instr_jump jump;
instr_find find;
instr_cleanup cleanup;
instr_initstring initstring;
instr_branchop branchop;
instr_blockop blockop;
};
template<int N>
struct V4InstrMeta {
};
#define QML_V4_INSTR_META_TEMPLATE(I, FMT) \
template<> struct V4InstrMeta<(int)V4Instr::I> { \
enum { Size = QML_V4_INSTR_SIZE(I, FMT) }; \
typedef V4Instr::instr_##FMT DataType; \
static const DataType &data(const V4Instr &instr) { return instr.FMT; } \
static void setData(V4Instr &instr, const DataType &v) { instr.FMT = v; } \
};
FOR_EACH_V4_INSTR(QML_V4_INSTR_META_TEMPLATE);
#undef QML_V4_INSTR_META_TEMPLATE
template<int Instr>
class V4InstrData : public V4InstrMeta<Instr>::DataType
{
};
class Bytecode
{
Q_DISABLE_COPY(Bytecode)
public:
Bytecode();
const char *constData() const { return d.constData(); }
int size() const { return d.size(); }
int count() const { return d.count(); }
void clear() { d.clear(); }
bool isEmpty() const { return d.isEmpty(); }
V4Instr::Type instructionType(const V4Instr *instr) const;
template <int Instr>
void append(const V4InstrData<Instr> &data)
{
V4Instr genericInstr;
V4InstrMeta<Instr>::setData(genericInstr, data);
return append(static_cast<V4Instr::Type>(Instr), genericInstr);
}
void append(V4Instr::Type type, V4Instr &instr);
int remove(int index);
const V4Instr &operator[](int offset) const;
V4Instr &operator[](int offset);
void dump(const char *start, const char *end) const;
private:
void dump(const V4Instr *instr, int = -1) const;
QVarLengthArray<char, 4 * 1024> d;
#ifdef QML_THREADED_INTERPRETER
void **decodeInstr;
#endif
};
}
QT_END_NAMESPACE
QT_END_HEADER
#endif // QV4INSTRUCTION_P_H
|