1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifndef PANDA_RUNTIME_INTERPRETER_DISPATCH_TABLE_H_
17 #define PANDA_RUNTIME_INTERPRETER_DISPATCH_TABLE_H_
18
19 #include <array>
20 #include <cstddef>
21 #include <cstdint>
22
23 #ifdef PANDA_ENABLE_GLOBAL_REGISTER_VARIABLES
24 #include "arch/global_regs.h"
25 #endif
26
27 namespace panda::interpreter {
28
29 #ifdef PANDA_ENABLE_GLOBAL_REGISTER_VARIABLES
30
31 template <size_t N>
SetDispatchTable(const std::array<const void *,N> & dispatch_table)32 ALWAYS_INLINE inline void SetDispatchTable(const std::array<const void *, N> &dispatch_table)
33 {
34 arch::regs::SetDispatchTable(dispatch_table.data());
35 }
36
37 template <size_t N>
GetDispatchTable(const std::array<const void *,N> & dispatch_table)38 ALWAYS_INLINE inline const void *const *GetDispatchTable([
39 [maybe_unused]] const std::array<const void *, N> &dispatch_table)
40 {
41 return arch::regs::GetDispatchTable();
42 }
43
44 #else
45
46 template <size_t N>
47 ALWAYS_INLINE inline void SetDispatchTable([[maybe_unused]] const std::array<const void *, N> &dispatch_table)
48 {
49 }
50
51 template <size_t N>
52 ALWAYS_INLINE inline const void *const *GetDispatchTable(const std::array<const void *, N> &dispatch_table)
53 {
54 return dispatch_table.data();
55 }
56
57 #endif // PANDA_ENABLE_GLOBAL_REGISTER_VARIABLES
58
59 } // namespace panda::interpreter
60
61 #endif // PANDA_RUNTIME_INTERPRETER_DISPATCH_TABLE_H_
62