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

source code of qtdeclarative/src/qml/jit/qv4baselineassembler_p.h