aboutsummaryrefslogtreecommitdiffstats
path: root/moth/qv4instr_moth_p.h
blob: 6fba81496e5bf5da8e08df378d58d2ab3dd4a6c1 (plain)
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
#ifndef QV4INSTR_MOTH_P_H
#define QV4INSTR_MOTH_P_H

#include <QtCore/qglobal.h>
#include "qmljs_objects.h"

#define FOR_EACH_MOTH_INSTR(F) \
    F(Ret, ret) \
    F(LoadUndefined, loadUndefined) \
    F(LoadNull, loadNull) \
    F(LoadFalse, loadFalse) \
    F(LoadTrue, loadTrue) \
    F(LoadNumber, loadNumber) \
    F(LoadString, loadString) \
    F(LoadClosure, loadClosure) \
    F(MoveTemp, moveTemp) \
    F(LoadName, loadName) \
    F(StoreName, storeName) \
    F(LoadElement, loadElement) \
    F(StoreElement, storeElement) \
    F(LoadProperty, loadProperty) \
    F(StoreProperty, storeProperty) \
    F(Push, push) \
    F(CallValue, callValue) \
    F(CallProperty, callProperty) \
    F(CallBuiltin, callBuiltin) \
    F(CallBuiltinDeleteMember, callBuiltinDeleteMember) \
    F(CallBuiltinDeleteSubscript, callBuiltinDeleteSubscript) \
    F(CallBuiltinDeleteName, callBuiltinDeleteName) \
    F(CallBuiltinDeleteValue, callBuiltinDeleteValue) \
    F(CreateValue, createValue) \
    F(CreateProperty, createProperty) \
    F(CreateActivationProperty, createActivationProperty) \
    F(Jump, jump) \
    F(CJump, cjump) \
    F(Unop, unop) \
    F(Binop, binop) \
    F(LoadThis, loadThis) \
    F(InplaceElementOp, inplaceElementOp) \
    F(InplaceMemberOp, inplaceMemberOp) \
    F(InplaceNameOp, inplaceNameOp)

#if defined(Q_CC_GNU) && (!defined(Q_CC_INTEL) || __INTEL_COMPILER >= 1200)
#  define MOTH_THREADED_INTERPRETER
#endif

#define MOTH_INSTR_ALIGN_MASK (Q_ALIGNOF(QQmlJS::Moth::Instr) - 1)

#ifdef MOTH_THREADED_INTERPRETER
#  define MOTH_INSTR_HEADER void *code;
#else
#  define MOTH_INSTR_HEADER quint8 instructionType;
#endif

#define MOTH_INSTR_ENUM(I, FMT)  I,
#define MOTH_INSTR_SIZE(I, FMT) ((sizeof(QQmlJS::Moth::Instr::instr_##FMT) + MOTH_INSTR_ALIGN_MASK) & ~MOTH_INSTR_ALIGN_MASK)


namespace QQmlJS {
namespace Moth {

union Instr
{
    union ValueOrTemp {
        VM::Value value;
        int tempIndex;
    };

    enum Type {
        FOR_EACH_MOTH_INSTR(MOTH_INSTR_ENUM)
    };

    struct instr_common {
        MOTH_INSTR_HEADER
        int tempIndex;
    };
    struct instr_ret {
        MOTH_INSTR_HEADER
        int tempIndex;
    }; 
    struct instr_loadUndefined {
        MOTH_INSTR_HEADER
        int targetTempIndex;
    };
    struct instr_loadNull {
        MOTH_INSTR_HEADER
        int targetTempIndex;
    };
    struct instr_loadFalse {
        MOTH_INSTR_HEADER
        int targetTempIndex;
    };
    struct instr_loadTrue {
        MOTH_INSTR_HEADER
        int targetTempIndex;
    };
    struct instr_moveTemp {
        MOTH_INSTR_HEADER
        int fromTempIndex;
        int toTempIndex;
    };
    struct instr_loadNumber {
        MOTH_INSTR_HEADER
        double value;
        int targetTempIndex;
    };
    struct instr_loadString {
        MOTH_INSTR_HEADER
        VM::String *value;
        int targetTempIndex;
    };
    struct instr_loadClosure {
        MOTH_INSTR_HEADER
        IR::Function *value;
        int targetTempIndex;
    };
    struct instr_loadName {
        MOTH_INSTR_HEADER
        VM::String *name;
        int targetTempIndex;
    };
    struct instr_storeName {
        MOTH_INSTR_HEADER
        VM::String *name;
        ValueOrTemp source;
        unsigned sourceIsTemp:1;
    };
    struct instr_loadProperty {
        MOTH_INSTR_HEADER
        int baseTemp;
        int targetTempIndex;
        VM::String *name;
    };
    struct instr_storeProperty {
        MOTH_INSTR_HEADER
        int baseTemp;
        VM::String *name;
        ValueOrTemp source;
        unsigned sourceIsTemp:1;
    };
    struct instr_loadElement {
        MOTH_INSTR_HEADER
        int base;
        int index;
        int targetTempIndex;
    };
    struct instr_storeElement {
        MOTH_INSTR_HEADER
        int base;
        int index;
        ValueOrTemp source;
        unsigned sourceIsTemp:1;
    };
    struct instr_push {
        MOTH_INSTR_HEADER
        quint32 value;
    };
    struct instr_callValue {
        MOTH_INSTR_HEADER
        quint32 argc;
        quint32 args;
        int destIndex;
        int targetTempIndex;
    };
    struct instr_callProperty {
        MOTH_INSTR_HEADER
        VM::String *name;
        int baseTemp;
        quint32 argc;
        quint32 args;
        int targetTempIndex;
    };
    struct instr_callBuiltin {
        MOTH_INSTR_HEADER
        enum {
            builtin_typeof,
            builtin_throw,
            builtin_create_exception_handler,
            builtin_delete_exception_handler,
            builtin_get_exception,
            builtin_foreach_iterator_object,
            builtin_foreach_next_property_name
        } builtin;
        quint32 argc;
        quint32 args;
        int targetTempIndex;
    };
    struct instr_callBuiltinDeleteMember {
        MOTH_INSTR_HEADER
        int base;
        VM::String *member;
        int targetTempIndex;
    };
    struct instr_callBuiltinDeleteSubscript {
        MOTH_INSTR_HEADER
        int base;
        int index;
        int targetTempIndex;
    };
    struct instr_callBuiltinDeleteName {
        MOTH_INSTR_HEADER
        VM::String *name;
        int targetTempIndex;
    };
    struct instr_callBuiltinDeleteValue {
        MOTH_INSTR_HEADER
        int tempIndex;
        int targetTempIndex;
    };
    struct instr_createValue {
        MOTH_INSTR_HEADER
        int func;
        quint32 argc;
        quint32 args;
        int targetTempIndex;
    };
    struct instr_createProperty {
        MOTH_INSTR_HEADER
        int base;
        VM::String *name;
        quint32 argc;
        quint32 args;
        int targetTempIndex;
    };
    struct instr_createActivationProperty {
        MOTH_INSTR_HEADER
        VM::String *name;
        quint32 argc;
        quint32 args;
        int targetTempIndex;
    };
    struct instr_jump {
        MOTH_INSTR_HEADER
        ptrdiff_t offset; 
    };
    struct instr_cjump {
        MOTH_INSTR_HEADER
        ptrdiff_t offset;
        int tempIndex;
    };
    struct instr_unop {
        MOTH_INSTR_HEADER
        VM::Value (*alu)(const VM::Value value, VM::ExecutionContext *ctx);
        int e;
        int targetTempIndex;
    };
    struct instr_binop {
        MOTH_INSTR_HEADER
        VM::Value (*alu)(const VM::Value , const VM::Value, VM::ExecutionContext *);
        int targetTempIndex;
        ValueOrTemp lhs;
        ValueOrTemp rhs;
        unsigned lhsIsTemp:1;
        unsigned rhsIsTemp:1;
    };
    struct instr_loadThis {
        MOTH_INSTR_HEADER
        int targetTempIndex;
    };
    struct instr_inplaceElementOp {
        MOTH_INSTR_HEADER
        void (*alu)(VM::Value, VM::Value, VM::Value, VM::ExecutionContext *);
        int targetBase;
        int targetIndex;
        ValueOrTemp source;
        unsigned sourceIsTemp:1;
    };
    struct instr_inplaceMemberOp {
        MOTH_INSTR_HEADER
        void (*alu)(VM::Value, VM::Value, VM::String *, VM::ExecutionContext *);
        int targetBase;
        VM::String *targetMember;
        ValueOrTemp source;
        unsigned sourceIsTemp:1;
    };
    struct instr_inplaceNameOp {
        MOTH_INSTR_HEADER
        void (*alu)(VM::Value, VM::String *, VM::ExecutionContext *);
        VM::String *targetName;
        ValueOrTemp source;
        unsigned sourceIsTemp:1;
    };

    instr_common common;
    instr_ret ret;
    instr_loadUndefined loadUndefined;
    instr_loadNull loadNull;
    instr_loadFalse loadFalse;
    instr_loadTrue loadTrue;
    instr_moveTemp moveTemp;
    instr_loadNumber loadNumber;
    instr_loadString loadString;
    instr_loadClosure loadClosure;
    instr_loadName loadName;
    instr_storeName storeName;
    instr_loadElement loadElement;
    instr_storeElement storeElement;
    instr_loadProperty loadProperty;
    instr_storeProperty storeProperty;
    instr_push push;
    instr_callValue callValue;
    instr_callProperty callProperty;
    instr_callBuiltin callBuiltin;
    instr_callBuiltinDeleteMember callBuiltinDeleteMember;
    instr_callBuiltinDeleteSubscript callBuiltinDeleteSubscript;
    instr_callBuiltinDeleteName callBuiltinDeleteName;
    instr_callBuiltinDeleteValue callBuiltinDeleteValue;
    instr_createValue createValue;
    instr_createProperty createProperty;
    instr_createActivationProperty createActivationProperty;
    instr_jump jump;
    instr_cjump cjump;
    instr_unop unop;
    instr_binop binop;
    instr_loadThis loadThis;
    instr_inplaceElementOp inplaceElementOp;
    instr_inplaceMemberOp inplaceMemberOp;
    instr_inplaceNameOp inplaceNameOp;

    static int size(Type type);
};

template<int N>
struct InstrMeta {
};

#define MOTH_INSTR_META_TEMPLATE(I, FMT) \
    template<> struct InstrMeta<(int)Instr::I> { \
        enum { Size = MOTH_INSTR_SIZE(I, FMT) }; \
        typedef Instr::instr_##FMT DataType; \
        static const DataType &data(const Instr &instr) { return instr.FMT; } \
        static void setData(Instr &instr, const DataType &v) { instr.FMT = v; } \
    }; 
FOR_EACH_MOTH_INSTR(MOTH_INSTR_META_TEMPLATE);
#undef MOTH_INSTR_META_TEMPLATE

template<int InstrType>
class InstrData : public InstrMeta<InstrType>::DataType
{
};

} // namespace Moth
} // namespace QQmlJS

#endif // QV4INSTR_MOTH_P_H