1
/****************************************************************************
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the QtQml module of the Qt Toolkit.
8
** $QT_BEGIN_LICENSE:LGPL21$
9
** Commercial License Usage
10
** Licensees holding valid commercial Qt licenses may use this file in
11
** accordance with the commercial license agreement provided with the
12
** Software or, alternatively, in accordance with the terms contained in
13
** a written agreement between you and Digia. For licensing terms and
14
** conditions see http://qt.digia.com/licensing. For further information
15
** use the contact form at http://qt.digia.com/contact-us.
17
** GNU Lesser General Public License Usage
18
** Alternatively, this file may be used under the terms of the GNU Lesser
19
** General Public License version 2.1 or version 3 as published by the Free
20
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22
** following information to ensure the GNU Lesser General Public License
23
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
26
** In addition, as a special exception, Digia gives you certain additional
27
** rights. These rights are described in the Digia Qt LGPL Exception
28
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
32
****************************************************************************/
34
#ifndef QV4ISEL_MOTH_P_H
35
#define QV4ISEL_MOTH_P_H
37
#include <private/qv4global_p.h>
38
#include <private/qv4isel_p.h>
39
#include <private/qv4isel_util_p.h>
40
#include <private/qv4jsir_p.h>
41
#include <private/qv4value_p.h>
42
#include "qv4instr_moth_p.h"
49
struct CompilationUnit : public QV4::CompiledData::CompilationUnit
51
virtual ~CompilationUnit();
52
virtual void linkBackendToEngine(QV4::ExecutionEngine *engine);
54
QVector<QByteArray> codeRefs;
58
class Q_QML_EXPORT InstructionSelection:
60
public EvalInstructionSelection
63
InstructionSelection(QQmlEnginePrivate *qmlEngine, QV4::ExecutableAllocator *execAllocator, IR::Module *module, QV4::Compiler::JSUnitGenerator *jsGenerator);
64
~InstructionSelection();
66
virtual void run(int functionIndex);
69
virtual QQmlRefPointer<CompiledData::CompilationUnit> backendCompileStep();
71
virtual void visitJump(IR::Jump *);
72
virtual void visitCJump(IR::CJump *);
73
virtual void visitRet(IR::Ret *);
75
virtual void callBuiltinInvalid(IR::Name *func, IR::ExprList *args, IR::Expr *result);
76
virtual void callBuiltinTypeofMember(IR::Expr *base, const QString &name, IR::Expr *result);
77
virtual void callBuiltinTypeofSubscript(IR::Expr *base, IR::Expr *index, IR::Expr *result);
78
virtual void callBuiltinTypeofName(const QString &name, IR::Expr *result);
79
virtual void callBuiltinTypeofValue(IR::Expr *value, IR::Expr *result);
80
virtual void callBuiltinDeleteMember(IR::Expr *base, const QString &name, IR::Expr *result);
81
virtual void callBuiltinDeleteSubscript(IR::Expr *base, IR::Expr *index, IR::Expr *result);
82
virtual void callBuiltinDeleteName(const QString &name, IR::Expr *result);
83
virtual void callBuiltinDeleteValue(IR::Expr *result);
84
virtual void callBuiltinThrow(IR::Expr *arg);
85
virtual void callBuiltinReThrow();
86
virtual void callBuiltinUnwindException(IR::Expr *);
87
virtual void callBuiltinPushCatchScope(const QString &exceptionName);
88
virtual void callBuiltinForeachIteratorObject(IR::Expr *arg, IR::Expr *result);
89
virtual void callBuiltinForeachNextPropertyname(IR::Expr *arg, IR::Expr *result);
90
virtual void callBuiltinPushWithScope(IR::Expr *arg);
91
virtual void callBuiltinPopScope();
92
virtual void callBuiltinDeclareVar(bool deletable, const QString &name);
93
virtual void callBuiltinDefineArray(IR::Expr *result, IR::ExprList *args);
94
virtual void callBuiltinDefineObjectLiteral(IR::Expr *result, int keyValuePairCount, IR::ExprList *keyValuePairs, IR::ExprList *arrayEntries, bool needSparseArray);
95
virtual void callBuiltinSetupArgumentObject(IR::Expr *result);
96
virtual void callBuiltinConvertThisToObject();
97
virtual void callValue(IR::Expr *value, IR::ExprList *args, IR::Expr *result);
98
virtual void callProperty(IR::Expr *base, const QString &name, IR::ExprList *args, IR::Expr *result);
99
virtual void callSubscript(IR::Expr *base, IR::Expr *index, IR::ExprList *args, IR::Expr *result);
100
virtual void convertType(IR::Expr *source, IR::Expr *target);
101
virtual void constructActivationProperty(IR::Name *func, IR::ExprList *args, IR::Expr *result);
102
virtual void constructProperty(IR::Expr *base, const QString &name, IR::ExprList *args, IR::Expr *result);
103
virtual void constructValue(IR::Expr *value, IR::ExprList *args, IR::Expr *result);
104
virtual void loadThisObject(IR::Expr *e);
105
virtual void loadQmlIdArray(IR::Expr *e);
106
virtual void loadQmlImportedScripts(IR::Expr *e);
107
virtual void loadQmlContextObject(IR::Expr *e);
108
virtual void loadQmlScopeObject(IR::Expr *e);
109
virtual void loadQmlSingleton(const QString &name, IR::Expr *e);
110
virtual void loadConst(IR::Const *sourceConst, IR::Expr *e);
111
virtual void loadString(const QString &str, IR::Expr *target);
112
virtual void loadRegexp(IR::RegExp *sourceRegexp, IR::Expr *target);
113
virtual void getActivationProperty(const IR::Name *name, IR::Expr *target);
114
virtual void setActivationProperty(IR::Expr *source, const QString &targetName);
115
virtual void initClosure(IR::Closure *closure, IR::Expr *target);
116
virtual void getProperty(IR::Expr *base, const QString &name, IR::Expr *target);
117
virtual void setProperty(IR::Expr *source, IR::Expr *targetBase, const QString &targetName);
118
virtual void setQObjectProperty(IR::Expr *source, IR::Expr *targetBase, int propertyIndex);
119
virtual void getQObjectProperty(IR::Expr *base, int propertyIndex, bool captureRequired, bool isSingleton, int attachedPropertiesId, IR::Expr *target);
120
virtual void getElement(IR::Expr *base, IR::Expr *index, IR::Expr *target);
121
virtual void setElement(IR::Expr *source, IR::Expr *targetBase, IR::Expr *targetIndex);
122
virtual void copyValue(IR::Expr *source, IR::Expr *target);
123
virtual void swapValues(IR::Expr *source, IR::Expr *target);
124
virtual void unop(IR::AluOp oper, IR::Expr *source, IR::Expr *target);
125
virtual void binop(IR::AluOp oper, IR::Expr *leftSource, IR::Expr *rightSource, IR::Expr *target);
128
Param binopHelper(IR::AluOp oper, IR::Expr *leftSource, IR::Expr *rightSource, IR::Expr *target);
131
#define MOTH_INSTR_DATA_TYPEDEF(I, FMT) typedef InstrData<Instr::I> I;
132
FOR_EACH_MOTH_INSTR(MOTH_INSTR_DATA_TYPEDEF)
133
#undef MOTH_INSTR_DATA_TYPEDEF
138
Param getParam(IR::Expr *e);
140
Param getResultParam(IR::Expr *result)
143
return getParam(result);
145
return Param::createTemp(scratchTempIndex());
148
void simpleMove(IR::Move *);
149
void prepareCallArgs(IR::ExprList *, quint32 &, quint32 * = 0);
151
int scratchTempIndex() const { return _function->tempCount; }
152
int callDataStart() const { return scratchTempIndex() + 1; }
153
int outgoingArgumentTempStart() const { return callDataStart() + qOffsetOf(QV4::CallData, args)/sizeof(QV4::Value); }
154
int frameSize() const { return outgoingArgumentTempStart() + _function->maxNumberOfArguments; }
157
inline ptrdiff_t addInstruction(const InstrData<Instr> &data);
158
ptrdiff_t addInstructionHelper(Instr::Type type, Instr &instr);
159
void patchJumpAddresses();
160
QByteArray squeezeCode() const;
162
QQmlEnginePrivate *qmlEngine;
164
bool blockNeedsDebugInstruction;
166
IR::BasicBlock *_block;
167
IR::BasicBlock *_nextBlock;
169
QHash<IR::BasicBlock *, QVector<ptrdiff_t> > _patches;
170
QHash<IR::BasicBlock *, ptrdiff_t> _addrs;
176
QSet<IR::Jump *> _removableJumps;
177
IR::Stmt *_currentStatement;
179
QScopedPointer<CompilationUnit> compilationUnit;
180
QHash<IR::Function *, QByteArray> codeRefs;
183
class Q_QML_EXPORT ISelFactory: public EvalISelFactory
186
virtual ~ISelFactory() {}
187
virtual EvalInstructionSelection *create(QQmlEnginePrivate *qmlEngine, QV4::ExecutableAllocator *execAllocator, IR::Module *module, QV4::Compiler::JSUnitGenerator *jsGenerator)
188
{ return new InstructionSelection(qmlEngine, execAllocator, module, jsGenerator); }
189
virtual bool jitCompileRegexps() const
194
ptrdiff_t InstructionSelection::addInstruction(const InstrData<InstrT> &data)
197
InstrMeta<InstrT>::setDataNoCommon(genericInstr, data);
198
return addInstructionHelper(static_cast<Instr::Type>(InstrT), genericInstr);
206
#endif // QV4ISEL_MOTH_P_H