1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QV4INSTRUCTION_P_H
43 #define QV4INSTRUCTION_P_H
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
56 #include <QtCore/qglobal.h>
57 #include <QtCore/qbytearray.h>
58 #include <QtCore/qvector.h>
59 #include <QtCore/qvarlengtharray.h>
61 #include <private/qdeclarativepropertycache_p.h>
67 #define FOR_EACH_V4_INSTR(F) \
70 F(Subscribe, subscribeop) \
71 F(SubscribeId, subscribeop) \
72 F(FetchAndSubscribe, fetchAndSubscribe) \
76 F(LoadAttached, attached) \
77 F(UnaryNot, unaryop) \
78 F(UnaryMinusReal, unaryop) \
79 F(UnaryMinusInt, unaryop) \
80 F(UnaryPlusReal, unaryop) \
81 F(UnaryPlusInt, unaryop) \
82 F(ConvertBoolToInt, unaryop) \
83 F(ConvertBoolToReal, unaryop) \
84 F(ConvertBoolToString, unaryop) \
85 F(ConvertIntToBool, unaryop) \
86 F(ConvertIntToReal, unaryop) \
87 F(ConvertIntToString, unaryop) \
88 F(ConvertRealToBool, unaryop) \
89 F(ConvertRealToInt, unaryop) \
90 F(ConvertRealToString, unaryop) \
91 F(ConvertStringToBool, unaryop) \
92 F(ConvertStringToInt, unaryop) \
93 F(ConvertStringToReal, unaryop) \
94 F(ConvertStringToUrl, unaryop) \
95 F(ConvertUrlToBool, unaryop) \
96 F(ConvertUrlToString, unaryop) \
97 F(ResolveUrl, unaryop) \
98 F(MathSinReal, unaryop) \
99 F(MathCosReal, unaryop) \
100 F(MathRoundReal, unaryop) \
101 F(MathFloorReal, unaryop) \
102 F(MathPIReal, unaryop) \
103 F(LoadReal, real_value) \
104 F(LoadInt, int_value) \
105 F(LoadBool, bool_value) \
106 F(LoadString, string_value) \
107 F(EnableV4Test, string_value) \
108 F(TestV4Store, storetest) \
109 F(BitAndInt, binaryop) \
110 F(BitOrInt, binaryop) \
111 F(BitXorInt, binaryop) \
112 F(AddReal, binaryop) \
113 F(AddString, binaryop) \
114 F(SubReal, binaryop) \
115 F(MulReal, binaryop) \
116 F(DivReal, binaryop) \
117 F(ModReal, binaryop) \
118 F(LShiftInt, binaryop) \
119 F(RShiftInt, binaryop) \
120 F(URShiftInt, binaryop) \
121 F(GtReal, binaryop) \
122 F(LtReal, binaryop) \
123 F(GeReal, binaryop) \
124 F(LeReal, binaryop) \
125 F(EqualReal, binaryop) \
126 F(NotEqualReal, binaryop) \
127 F(StrictEqualReal, binaryop) \
128 F(StrictNotEqualReal, binaryop) \
129 F(GtString, binaryop) \
130 F(LtString, binaryop) \
131 F(GeString, binaryop) \
132 F(LeString, binaryop) \
133 F(EqualString, binaryop) \
134 F(NotEqualString, binaryop) \
135 F(StrictEqualString, binaryop) \
136 F(StrictNotEqualString, binaryop) \
137 F(NewString, construct) \
138 F(NewUrl, construct) \
139 F(CleanupRegister, cleanup) \
144 F(BranchTrue, branchop) \
145 F(BranchFalse, branchop) \
146 F(Branch, branchop) \
148 /* Speculative property resolution */ \
149 F(InitString, initstring)
151 #if defined(Q_CC_GNU) && (!defined(Q_CC_INTEL) || __INTEL_COMPILER >= 1200)
152 # define QML_THREADED_INTERPRETER
156 # define QML_V4_INSTR_ALIGN_MASK (Q_ALIGNOF(V4Instr) - 1)
158 # define QML_V4_INSTR_ALIGN_MASK (sizeof(void *) - 1)
161 #define QML_V4_INSTR_ENUM(I, FMT) I,
162 #define QML_V4_INSTR_ADDR(I, FMT) &&op_##I,
163 #define QML_V4_INSTR_SIZE(I, FMT) ((sizeof(V4Instr::instr_##FMT) + QML_V4_INSTR_ALIGN_MASK) & ~QML_V4_INSTR_ALIGN_MASK)
165 #ifdef QML_THREADED_INTERPRETER
166 # define QML_V4_BEGIN_INSTR(I,FMT) op_##I:
167 # define QML_V4_END_INSTR(I,FMT) code += QML_V4_INSTR_SIZE(I, FMT); instr = (const V4Instr *) code; goto *instr->common.code;
168 # define QML_V4_INSTR_HEADER void *code;
170 # define QML_V4_BEGIN_INSTR(I,FMT) case V4Instr::I:
171 # define QML_V4_END_INSTR(I,FMT) code += QML_V4_INSTR_SIZE(I, FMT); instr = (const V4Instr *) code; break;
172 # define QML_V4_INSTR_HEADER quint8 type;
176 class QDeclarativeNotifier;
178 namespace QDeclarativeJS {
182 FOR_EACH_V4_INSTR(QML_V4_INSTR_ENUM)
185 static int size(Type type);
187 struct instr_common {
199 quint16 subscriptions;
203 struct instr_subscribeop {
216 struct instr_attached {
232 struct instr_storetest {
238 struct instr_fetchAndSubscribe {
243 quint16 subscription;
244 QDeclarativePropertyRawData property;
261 struct instr_construct {
266 struct instr_real_value {
269 qreal value; // XXX Makes the instruction 12 bytes
272 struct instr_int_value {
278 struct instr_bool_value {
284 struct instr_string_value {
291 struct instr_binaryop {
298 struct instr_unaryop {
316 quint16 subscribeIndex;
319 struct instr_cleanup {
324 struct instr_initstring {
330 struct instr_branchop {
336 struct instr_blockop {
344 instr_subscribeop subscribeop;
346 instr_attached attached;
348 instr_storetest storetest;
349 instr_fetchAndSubscribe fetchAndSubscribe;
352 instr_construct construct;
353 instr_real_value real_value;
354 instr_int_value int_value;
355 instr_bool_value bool_value;
356 instr_string_value string_value;
357 instr_binaryop binaryop;
358 instr_unaryop unaryop;
361 instr_cleanup cleanup;
362 instr_initstring initstring;
363 instr_branchop branchop;
364 instr_blockop blockop;
371 #define QML_V4_INSTR_META_TEMPLATE(I, FMT) \
372 template<> struct V4InstrMeta<(int)V4Instr::I> { \
373 enum { Size = QML_V4_INSTR_SIZE(I, FMT) }; \
374 typedef V4Instr::instr_##FMT DataType; \
375 static const DataType &data(const V4Instr &instr) { return instr.FMT; } \
376 static void setData(V4Instr &instr, const DataType &v) { instr.FMT = v; } \
378 FOR_EACH_V4_INSTR(QML_V4_INSTR_META_TEMPLATE);
379 #undef QML_V4_INSTR_META_TEMPLATE
382 class V4InstrData : public V4InstrMeta<Instr>::DataType
388 Q_DISABLE_COPY(Bytecode)
393 const char *constData() const { return d.constData(); }
394 int size() const { return d.size(); }
395 int count() const { return d.count(); }
396 void clear() { d.clear(); }
397 bool isEmpty() const { return d.isEmpty(); }
398 V4Instr::Type instructionType(const V4Instr *instr) const;
401 void append(const V4InstrData<Instr> &data)
403 V4Instr genericInstr;
404 V4InstrMeta<Instr>::setData(genericInstr, data);
405 return append(static_cast<V4Instr::Type>(Instr), genericInstr);
407 void append(V4Instr::Type type, V4Instr &instr);
409 int remove(int index);
411 const V4Instr &operator[](int offset) const;
412 V4Instr &operator[](int offset);
414 void dump(const char *start, const char *end) const;
417 void dump(const V4Instr *instr, int = -1) const;
419 QVarLengthArray<char, 4 * 1024> d;
420 #ifdef QML_THREADED_INTERPRETER
431 #endif // QV4INSTRUCTION_P_H