| 1 | /**************************************************************************** | 
| 2 | ** | 
| 3 | ** Copyright (C) 2018 The Qt Company Ltd. | 
| 4 | ** Contact: https://www.qt.io/licensing/ | 
| 5 | ** | 
| 6 | ** This file is part of the QtQml module of the Qt Toolkit. | 
| 7 | ** | 
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | 
| 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 The Qt Company. For licensing terms | 
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | 
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | 
| 16 | ** | 
| 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 3 as published by the Free Software | 
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | 
| 21 | ** packaging of this file. Please review the following information to | 
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | 
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | 
| 24 | ** | 
| 25 | ** GNU General Public License Usage | 
| 26 | ** Alternatively, this file may be used under the terms of the GNU | 
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | 
| 28 | ** Public license version 3 or any later version approved by the KDE Free | 
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | 
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | 
| 31 | ** included in the packaging of this file. Please review the following | 
| 32 | ** information to ensure the GNU General Public License requirements will | 
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | 
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | 
| 35 | ** | 
| 36 | ** $QT_END_LICENSE$ | 
| 37 | ** | 
| 38 | ****************************************************************************/ | 
| 39 |  | 
| 40 | #ifndef QV4BASELINEASSEMBLER_P_H | 
| 41 | #define QV4BASELINEASSEMBLER_P_H | 
| 42 |  | 
| 43 | // | 
| 44 | //  W A R N I N G | 
| 45 | //  ------------- | 
| 46 | // | 
| 47 | // This file is not part of the Qt API.  It exists purely as an | 
| 48 | // implementation detail.  This header file may change from version to | 
| 49 | // version without notice, or even be removed. | 
| 50 | // | 
| 51 | // We mean it. | 
| 52 | // | 
| 53 |  | 
| 54 | #include <private/qv4global_p.h> | 
| 55 | #include <private/qv4function_p.h> | 
| 56 | #include <QHash> | 
| 57 |  | 
| 58 | #if QT_CONFIG(qml_jit) | 
| 59 |  | 
| 60 | QT_BEGIN_NAMESPACE | 
| 61 |  | 
| 62 | namespace QV4 { | 
| 63 | namespace JIT { | 
| 64 |  | 
| 65 | #define GENERATE_RUNTIME_CALL(function, destination) \ | 
| 66 |     callRuntime(reinterpret_cast<void *>(&Runtime::function::call), \ | 
| 67 |                 destination) | 
| 68 | #define GENERATE_TAIL_CALL(function) \ | 
| 69 |     tailCallRuntime(reinterpret_cast<void *>(&function)) | 
| 70 |  | 
| 71 | class BaselineAssembler { | 
| 72 | public: | 
| 73 |     BaselineAssembler(const Value* constantTable); | 
| 74 |     ~BaselineAssembler(); | 
| 75 |  | 
| 76 |     // codegen infrastructure | 
| 77 |     void generatePrologue(); | 
| 78 |     void generateEpilogue(); | 
| 79 |     void link(Function *function); | 
| 80 |     void addLabel(int offset); | 
| 81 |  | 
| 82 |     // loads/stores/moves | 
| 83 |     void loadConst(int constIndex); | 
| 84 |     void copyConst(int constIndex, int destReg); | 
| 85 |     void loadReg(int reg); | 
| 86 |     void moveReg(int sourceReg, int destReg); | 
| 87 |     void storeReg(int reg); | 
| 88 |     void loadLocal(int index, int level = 0); | 
| 89 |     void storeLocal(int index, int level = 0); | 
| 90 |     void loadString(int stringId); | 
| 91 |     void loadValue(ReturnedValue value); | 
| 92 |     void storeHeapObject(int reg); | 
| 93 |     void loadImport(int index); | 
| 94 |  | 
| 95 |     // numeric ops | 
| 96 |     void unot(); | 
| 97 |     void toNumber(); | 
| 98 |     void uminus(); | 
| 99 |     void ucompl(); | 
| 100 |     void inc(); | 
| 101 |     void dec(); | 
| 102 |     void add(int lhs); | 
| 103 |     void bitAnd(int lhs); | 
| 104 |     void bitOr(int lhs); | 
| 105 |     void bitXor(int lhs); | 
| 106 |     void ushr(int lhs); | 
| 107 |     void shr(int lhs); | 
| 108 |     void shl(int lhs); | 
| 109 |     void bitAndConst(int rhs); | 
| 110 |     void bitOrConst(int rhs); | 
| 111 |     void bitXorConst(int rhs); | 
| 112 |     void ushrConst(int rhs); | 
| 113 |     void shrConst(int rhs); | 
| 114 |     void shlConst(int rhs); | 
| 115 |     void mul(int lhs); | 
| 116 |     void div(int lhs); | 
| 117 |     void mod(int lhs); | 
| 118 |     void sub(int lhs); | 
| 119 |  | 
| 120 |     // comparissons | 
| 121 |     void cmpeqNull(); | 
| 122 |     void cmpneNull(); | 
| 123 |     void cmpeqInt(int lhs); | 
| 124 |     void cmpneInt(int lhs); | 
| 125 |     void cmpeq(int lhs); | 
| 126 |     void cmpne(int lhs); | 
| 127 |     void cmpgt(int lhs); | 
| 128 |     void cmpge(int lhs); | 
| 129 |     void cmplt(int lhs); | 
| 130 |     void cmple(int lhs); | 
| 131 |     void cmpStrictEqual(int lhs); | 
| 132 |     void cmpStrictNotEqual(int lhs); | 
| 133 |  | 
| 134 |     // jumps | 
| 135 |     Q_REQUIRED_RESULT int jump(int offset); | 
| 136 |     Q_REQUIRED_RESULT int jumpTrue(int offset); | 
| 137 |     Q_REQUIRED_RESULT int jumpFalse(int offset); | 
| 138 |     Q_REQUIRED_RESULT int jumpNoException(int offset); | 
| 139 |     Q_REQUIRED_RESULT int jumpNotUndefined(int offset); | 
| 140 |  | 
| 141 |     // stuff for runtime calls | 
| 142 |     void prepareCallWithArgCount(int argc); | 
| 143 |     void storeInstructionPointer(int instructionOffset); | 
| 144 |     void passAccumulatorAsArg(int arg); | 
| 145 |     void passFunctionAsArg(int arg); | 
| 146 |     void passEngineAsArg(int arg); | 
| 147 |     void passJSSlotAsArg(int reg, int arg); | 
| 148 |     void passCppFrameAsArg(int arg); | 
| 149 |     void passInt32AsArg(int value, int arg); | 
| 150 |     void passPointerAsArg(void *ptr, int arg); | 
| 151 |     void callRuntime(const void *funcPtr, CallResultDestination dest); | 
| 152 |     void saveAccumulatorInFrame(); | 
| 153 |     void loadAccumulatorFromFrame(); | 
| 154 |     void jsTailCall(int func, int thisObject, int argc, int argv); | 
| 155 |  | 
| 156 |     // exception/context stuff | 
| 157 |     void checkException(); | 
| 158 |     void gotoCatchException(); | 
| 159 |     void getException(); | 
| 160 |     void setException(); | 
| 161 |     Q_REQUIRED_RESULT int setUnwindHandler(int offset); | 
| 162 |     void clearUnwindHandler(); | 
| 163 |     void unwindDispatch(); | 
| 164 |     Q_REQUIRED_RESULT int unwindToLabel(int level, int offset); | 
| 165 |     void pushCatchContext(int index, int name); | 
| 166 |     void popContext(); | 
| 167 |     void deadTemporalZoneCheck(int offsetForSavedIP, int variableName); | 
| 168 |  | 
| 169 |     // other stuff | 
| 170 |     void ret(); | 
| 171 |  | 
| 172 | protected: | 
| 173 |     void *d; | 
| 174 |  | 
| 175 | private: | 
| 176 |     typedef unsigned(*CmpFunc)(const Value&,const Value&); | 
| 177 |     void cmp(int cond, CmpFunc function, int lhs); | 
| 178 | }; | 
| 179 |  | 
| 180 | } // namespace JIT | 
| 181 | } // namespace QV4 | 
| 182 |  | 
| 183 | QT_END_NAMESPACE | 
| 184 |  | 
| 185 | #endif // QT_CONFIG(qml_jit) | 
| 186 |  | 
| 187 | #endif // QV4BASELINEASSEMBLER_P_H | 
| 188 |  |