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 | #include <private/qv4bytecodehandler_p.h> |
5 | |
6 | QT_USE_NAMESPACE |
7 | using namespace QV4; |
8 | using namespace Moth; |
9 | |
10 | ByteCodeHandler::~ByteCodeHandler() |
11 | { |
12 | } |
13 | |
14 | #define DISPATCH_INSTRUCTION(name, nargs, ...) \ |
15 | generate_##name( \ |
16 | __VA_ARGS__ \ |
17 | ); |
18 | |
19 | #define DECODE_AND_DISPATCH(instr) \ |
20 | { \ |
21 | INSTR_##instr(MOTH_DECODE_WITH_BASE) \ |
22 | Q_UNUSED(base_ptr); \ |
23 | _currentOffset = _nextOffset; \ |
24 | _nextOffset = code - start; \ |
25 | if (startInstruction(Instr::Type::instr) == ProcessInstruction) { \ |
26 | INSTR_##instr(DISPATCH) \ |
27 | endInstruction(Instr::Type::instr); \ |
28 | } \ |
29 | continue; \ |
30 | } |
31 | |
32 | void ByteCodeHandler::decode(const char *code, uint len) |
33 | { |
34 | MOTH_JUMP_TABLE; |
35 | |
36 | const char *start = code; |
37 | const char *end = code + len; |
38 | while (code < end) { |
39 | MOTH_DISPATCH() |
40 | |
41 | FOR_EACH_MOTH_INSTR(DECODE_AND_DISPATCH) |
42 | } |
43 | } |
44 | |
45 | #undef DECODE_AND_DISPATCH |
46 | #undef DISPATCH_INSTRUCTION |
47 |