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 QV4BYTECODEHANDLER_P_H
5#define QV4BYTECODEHANDLER_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/qtqmlcompilerglobal_p.h>
19#include <private/qv4instr_moth_p.h>
20
21QT_BEGIN_NAMESPACE
22
23namespace QV4 {
24namespace Moth {
25
26#define BYTECODE_HANDLER_DEFINE_ARGS(nargs, ...) \
27 MOTH_EXPAND_FOR_MSVC(BYTECODE_HANDLER_DEFINE_ARGS##nargs(__VA_ARGS__))
28
29#define BYTECODE_HANDLER_DEFINE_ARGS0()
30#define BYTECODE_HANDLER_DEFINE_ARGS1(arg) \
31 int arg
32#define BYTECODE_HANDLER_DEFINE_ARGS2(arg1, arg2) \
33 int arg1, \
34 int arg2
35#define BYTECODE_HANDLER_DEFINE_ARGS3(arg1, arg2, arg3) \
36 int arg1, \
37 int arg2, \
38 int arg3
39#define BYTECODE_HANDLER_DEFINE_ARGS4(arg1, arg2, arg3, arg4) \
40 int arg1, \
41 int arg2, \
42 int arg3, \
43 int arg4
44#define BYTECODE_HANDLER_DEFINE_ARGS5(arg1, arg2, arg3, arg4, arg5) \
45 int arg1, \
46 int arg2, \
47 int arg3, \
48 int arg4, \
49 int arg5
50
51#define BYTECODE_HANDLER_DEFINE_VIRTUAL_BYTECODE_HANDLER_INSTRUCTION(name, nargs, ...) \
52 virtual void generate_##name( \
53 BYTECODE_HANDLER_DEFINE_ARGS(nargs, __VA_ARGS__) \
54 ) = 0;
55
56#define BYTECODE_HANDLER_DEFINE_VIRTUAL_BYTECODE_HANDLER(instr) \
57 INSTR_##instr(BYTECODE_HANDLER_DEFINE_VIRTUAL_BYTECODE_HANDLER)
58
59class Q_QML_COMPILER_PRIVATE_EXPORT ByteCodeHandler
60{
61 Q_DISABLE_COPY_MOVE(ByteCodeHandler)
62public:
63 ByteCodeHandler() = default;
64 virtual ~ByteCodeHandler();
65
66 void decode(const char *code, uint len);
67 void reset() { _currentOffset = _nextOffset = 0; }
68
69 int currentInstructionOffset() const { return _currentOffset; }
70 int nextInstructionOffset() const { return _nextOffset; }
71 int absoluteOffset(int relativeOffset) const
72 { return nextInstructionOffset() + relativeOffset; }
73
74protected:
75 FOR_EACH_MOTH_INSTR(BYTECODE_HANDLER_DEFINE_VIRTUAL_BYTECODE_HANDLER)
76
77 enum Verdict { ProcessInstruction, SkipInstruction };
78 virtual Verdict startInstruction(Moth::Instr::Type instr) = 0;
79 virtual void endInstruction(Moth::Instr::Type instr) = 0;
80
81private:
82 int _currentOffset = 0;
83 int _nextOffset = 0;
84};
85
86} // Moth namespace
87} // QV4 namespace
88
89QT_END_NAMESPACE
90
91#endif // QV4BYTECODEHANDLER_P_H
92

source code of qtdeclarative/src/qml/compiler/qv4bytecodehandler_p.h