• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-2024 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_IRTOC_INTERPRETER_UTILS_H_
17#define PANDA_IRTOC_INTERPRETER_UTILS_H_
18
19// NOLINTBEGIN(readability-identifier-naming)
20
21namespace ark::interpreter {
22
23% # If it is GN Build with disabled asmjit and irtoc is disabled
24#if defined(PANDA_TARGET_AMD64) && !defined(PANDA_COMPILER_TARGET_X86_64)
25% Panda::instructions.each do |i|
26    static constexpr void (*HANDLE_FAST_<%= i.handler_name %>)() = nullptr;
27% end
28% Panda::prefixes.each do |p|
29    static constexpr void (*HANDLE_FAST_<%= p.handler_name %>)() = nullptr;
30% end
31    static constexpr void (*HANDLE_FAST_INVALID)() = nullptr;
32    static constexpr void (*HANDLE_FAST_EXCEPTION)() = nullptr;
33
34% Panda::instructions.each do |i|
35    static constexpr void (*HANDLE_FAST_<%= i.handler_name %>_LLVM)() = nullptr;
36% end
37% Panda::prefixes.each do |p|
38    static constexpr void (*HANDLE_FAST_<%= p.handler_name %>_LLVM)() = nullptr;
39% end
40    static constexpr void (*HANDLE_FAST_INVALID_LLVM)() = nullptr;
41    static constexpr void (*HANDLE_FAST_EXCEPTION_LLVM)() = nullptr;
42
43#else
44% Panda::instructions.each do |i|
45    extern "C" void HANDLE_FAST_<%= i.handler_name %>();
46% end
47% Panda::prefixes.each do |p|
48    extern "C" void HANDLE_FAST_<%= p.handler_name %>();
49% end
50    extern "C" void HANDLE_FAST_INVALID();
51    extern "C" void HANDLE_FAST_EXCEPTION();
52
53% Panda::instructions.each do |i|
54    extern "C" void HANDLE_FAST_<%= i.handler_name %>_LLVM();
55% end
56% Panda::prefixes.each do |p|
57    extern "C" void HANDLE_FAST_<%= p.handler_name %>_LLVM();
58% end
59    extern "C" void HANDLE_FAST_INVALID_LLVM();
60    extern "C" void HANDLE_FAST_EXCEPTION_LLVM();
61#endif
62
63// NOLINTNEXTLINE(readability-function-size)
64inline void* SetupDispatchTableImpl()
65{
66    static const std::array<void (*)(), <%= Panda::dispatch_table.handler_names.size() + 1 %>> dispatch_table {
67#if defined(PANDA_TARGET_AMD64) && !defined(PANDA_COMPILER_TARGET_X86_64)
68% Panda::dispatch_table.handler_names.each do |name|
69        HANDLE_FAST_<%= name %>,
70% end
71#else
72% Panda::dispatch_table.handler_names.each do |name|
73        &HANDLE_FAST_<%= name %>,
74% end
75        &HANDLE_FAST_EXCEPTION
76#endif
77    };
78    return (void *)dispatch_table.data();
79}
80
81// NOLINTNEXTLINE(readability-function-size)
82inline void* SetupLLVMDispatchTableImpl()
83{
84    static const std::array<void (*)(), <%= Panda::dispatch_table.handler_names.size() + 1 %>> dispatch_table {
85#if defined(PANDA_TARGET_AMD64) && !defined(PANDA_COMPILER_TARGET_X86_64)
86% Panda::dispatch_table.handler_names.each do |name|
87        HANDLE_FAST_<%= name %>_LLVM,
88% end
89#else
90% Panda::dispatch_table.handler_names.each do |name|
91        &HANDLE_FAST_<%= name %>_LLVM,
92% end
93        &HANDLE_FAST_EXCEPTION_LLVM
94#endif
95    };
96    return (void *)dispatch_table.data();
97}
98
99}  // namespace ark::interpreter
100
101// NOLINTEND(readability-identifier-naming)
102
103#endif  // PANDA_IRTOC_INTERPRETER_UTILS_H_
104