1// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#define RUNTIME_VM_CONSTANTS_H_ // To work around include guard.
6#include "vm/constants_kbc.h"
7
8namespace dart {
9
10static const intptr_t kInstructionSize0 = 1;
11static const intptr_t kInstructionSizeA = 2;
12static const intptr_t kInstructionSizeD = 2;
13static const intptr_t kInstructionSizeWideD = 5;
14static const intptr_t kInstructionSizeX = 2;
15static const intptr_t kInstructionSizeWideX = 5;
16static const intptr_t kInstructionSizeT = 2;
17static const intptr_t kInstructionSizeWideT = 4;
18static const intptr_t kInstructionSizeA_E = 3;
19static const intptr_t kInstructionSizeWideA_E = 6;
20static const intptr_t kInstructionSizeA_Y = 3;
21static const intptr_t kInstructionSizeWideA_Y = 6;
22static const intptr_t kInstructionSizeD_F = 3;
23static const intptr_t kInstructionSizeWideD_F = 6;
24static const intptr_t kInstructionSizeA_B_C = 4;
25
26const intptr_t KernelBytecode::kInstructionSize[] = {
27#define SIZE_ORDN(encoding) kInstructionSize##encoding
28#define SIZE_WIDE(encoding) kInstructionSizeWide##encoding
29#define SIZE_RESV(encoding) SIZE_ORDN(encoding)
30#define SIZE(name, encoding, kind, op1, op2, op3) SIZE_##kind(encoding),
31 KERNEL_BYTECODES_LIST(SIZE)
32#undef SIZE_ORDN
33#undef SIZE_WIDE
34#undef SIZE_RESV
35#undef SIZE
36};
37
38#define DECLARE_INSTRUCTIONS(name, fmt, kind, fmta, fmtb, fmtc) \
39 static const KBCInstr k##name##Instructions[] = { \
40 KernelBytecode::k##name, \
41 KernelBytecode::kReturnTOS, \
42 };
43INTERNAL_KERNEL_BYTECODES_LIST(DECLARE_INSTRUCTIONS)
44#undef DECLARE_INSTRUCTIONS
45
46void KernelBytecode::GetVMInternalBytecodeInstructions(
47 Opcode opcode,
48 const KBCInstr** instructions,
49 intptr_t* instructions_size) {
50 switch (opcode) {
51#define CASE(name, fmt, kind, fmta, fmtb, fmtc) \
52 case k##name: \
53 *instructions = k##name##Instructions; \
54 *instructions_size = sizeof(k##name##Instructions); \
55 return;
56
57 INTERNAL_KERNEL_BYTECODES_LIST(CASE)
58#undef CASE
59
60 default:
61 UNREACHABLE();
62 }
63}
64
65static const KBCInstr kNativeCallToGrowableListReturnTrampoline[] = {
66 KernelBytecode::kDirectCall,
67 0, // target (doesn't matter)
68 KernelBytecode::kNativeCallToGrowableListArgc, // number of arguments
69 KernelBytecode::kReturnTOS,
70};
71
72const KBCInstr* KernelBytecode::GetNativeCallToGrowableListReturnTrampoline() {
73 return KernelBytecode::Next(&kNativeCallToGrowableListReturnTrampoline[0]);
74}
75
76} // namespace dart
77