| 1 | // Copyright (C) 2018 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | // Qt-Security score:significant |
| 4 | |
| 5 | #ifndef QV4BASELINEASSEMBLER_P_H |
| 6 | #define QV4BASELINEASSEMBLER_P_H |
| 7 | |
| 8 | // |
| 9 | // W A R N I N G |
| 10 | // ------------- |
| 11 | // |
| 12 | // This file is not part of the Qt API. It exists purely as an |
| 13 | // implementation detail. This header file may change from version to |
| 14 | // version without notice, or even be removed. |
| 15 | // |
| 16 | // We mean it. |
| 17 | // |
| 18 | |
| 19 | #include <private/qv4global_p.h> |
| 20 | #include <private/qv4function_p.h> |
| 21 | #include <QHash> |
| 22 | |
| 23 | #if QT_CONFIG(qml_jit) |
| 24 | |
| 25 | QT_BEGIN_NAMESPACE |
| 26 | |
| 27 | namespace QV4 { |
| 28 | namespace JIT { |
| 29 | |
| 30 | #define GENERATE_RUNTIME_CALL(function, destination) \ |
| 31 | callRuntime(reinterpret_cast<void *>(&Runtime::function::call), \ |
| 32 | destination) |
| 33 | #define GENERATE_TAIL_CALL(function) \ |
| 34 | tailCallRuntime(reinterpret_cast<void *>(&function)) |
| 35 | |
| 36 | class BaselineAssembler { |
| 37 | public: |
| 38 | BaselineAssembler(const Value* constantTable); |
| 39 | ~BaselineAssembler(); |
| 40 | |
| 41 | // codegen infrastructure |
| 42 | void generatePrologue(); |
| 43 | void generateEpilogue(); |
| 44 | void link(Function *function); |
| 45 | void addLabel(int offset); |
| 46 | |
| 47 | // loads/stores/moves |
| 48 | void loadConst(int constIndex); |
| 49 | void copyConst(int constIndex, int destReg); |
| 50 | void loadReg(int reg); |
| 51 | void moveReg(int sourceReg, int destReg); |
| 52 | void storeReg(int reg); |
| 53 | void loadLocal(int index, int level = 0); |
| 54 | void storeLocal(int index, int level = 0); |
| 55 | void loadString(int stringId); |
| 56 | void loadValue(ReturnedValue value); |
| 57 | void storeHeapObject(int reg); |
| 58 | void loadImport(int index); |
| 59 | |
| 60 | // numeric ops |
| 61 | void unot(); |
| 62 | void toNumber(); |
| 63 | void uminus(); |
| 64 | void ucompl(); |
| 65 | void inc(); |
| 66 | void dec(); |
| 67 | void add(int lhs); |
| 68 | void bitAnd(int lhs); |
| 69 | void bitOr(int lhs); |
| 70 | void bitXor(int lhs); |
| 71 | void ushr(int lhs); |
| 72 | void shr(int lhs); |
| 73 | void shl(int lhs); |
| 74 | void bitAndConst(int rhs); |
| 75 | void bitOrConst(int rhs); |
| 76 | void bitXorConst(int rhs); |
| 77 | void ushrConst(int rhs); |
| 78 | void shrConst(int rhs); |
| 79 | void shlConst(int rhs); |
| 80 | void mul(int lhs); |
| 81 | void div(int lhs); |
| 82 | void mod(int lhs); |
| 83 | void sub(int lhs); |
| 84 | |
| 85 | // comparissons |
| 86 | void cmpeqNull(); |
| 87 | void cmpneNull(); |
| 88 | void cmpeqInt(int lhs); |
| 89 | void cmpneInt(int lhs); |
| 90 | void cmpeq(int lhs); |
| 91 | void cmpne(int lhs); |
| 92 | void cmpgt(int lhs); |
| 93 | void cmpge(int lhs); |
| 94 | void cmplt(int lhs); |
| 95 | void cmple(int lhs); |
| 96 | void cmpStrictEqual(int lhs); |
| 97 | void cmpStrictNotEqual(int lhs); |
| 98 | |
| 99 | // jumps |
| 100 | Q_REQUIRED_RESULT int jump(int offset); |
| 101 | Q_REQUIRED_RESULT int jumpTrue(int offset); |
| 102 | Q_REQUIRED_RESULT int jumpFalse(int offset); |
| 103 | Q_REQUIRED_RESULT int jumpNoException(int offset); |
| 104 | Q_REQUIRED_RESULT int jumpNotUndefined(int offset); |
| 105 | Q_REQUIRED_RESULT int jumpEqNull(int offset); |
| 106 | |
| 107 | // stuff for runtime calls |
| 108 | void prepareCallWithArgCount(int argc); |
| 109 | void storeInstructionPointer(int instructionOffset); |
| 110 | void passAccumulatorAsArg(int arg); |
| 111 | void passFunctionAsArg(int arg); |
| 112 | void passEngineAsArg(int arg); |
| 113 | void passJSSlotAsArg(int reg, int arg); |
| 114 | void passCppFrameAsArg(int arg); |
| 115 | void passInt32AsArg(int value, int arg); |
| 116 | void passPointerAsArg(void *ptr, int arg); |
| 117 | void callRuntime(const void *funcPtr, CallResultDestination dest); |
| 118 | void saveAccumulatorInFrame(); |
| 119 | void loadAccumulatorFromFrame(); |
| 120 | void jsTailCall(int func, int thisObject, int argc, int argv); |
| 121 | |
| 122 | // exception/context stuff |
| 123 | void checkException(); |
| 124 | void gotoCatchException(); |
| 125 | void getException(); |
| 126 | void setException(); |
| 127 | Q_REQUIRED_RESULT int setUnwindHandler(int offset); |
| 128 | void clearUnwindHandler(); |
| 129 | void unwindDispatch(); |
| 130 | Q_REQUIRED_RESULT int unwindToLabel(int level, int offset); |
| 131 | void pushCatchContext(int index, int name); |
| 132 | void popContext(); |
| 133 | void deadTemporalZoneCheck(int offsetForSavedIP, int variableName); |
| 134 | |
| 135 | // other stuff |
| 136 | void ret(); |
| 137 | |
| 138 | protected: |
| 139 | void *d; |
| 140 | |
| 141 | private: |
| 142 | typedef unsigned(*CmpFunc)(const Value&,const Value&); |
| 143 | void cmp(int cond, CmpFunc function, int lhs); |
| 144 | }; |
| 145 | |
| 146 | } // namespace JIT |
| 147 | } // namespace QV4 |
| 148 | |
| 149 | QT_END_NAMESPACE |
| 150 | |
| 151 | #endif // QT_CONFIG(qml_jit) |
| 152 | |
| 153 | #endif // QV4BASELINEASSEMBLER_P_H |
| 154 | |