• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 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 LIBABCKIT_SRC_IR_IMPL_H
17 #define LIBABCKIT_SRC_IR_IMPL_H
18 
19 #include "libabckit/include/c/metadata_core.h"
20 #include "libabckit/include/c/ir_core.h"
21 #include "libabckit/src/metadata_inspect_impl.h"
22 #include "macros.h"
23 #include "libpandabase/macros.h"
24 
25 namespace ark::compiler {
26 class BasicBlock;
27 class Inst;
28 class Graph;
29 }  // namespace ark::compiler
30 
31 // NOLINTBEGIN(misc-non-private-member-variables-in-classes)
32 struct AbckitIrInterface final {
AbckitIrInterfacefinal33     AbckitIrInterface(std::unordered_map<uint32_t, std::string> methodsArg,
34                       std::unordered_map<uint32_t, std::string> fieldsArg,
35                       std::unordered_map<uint32_t, std::string> classesArg,
36                       std::unordered_map<uint32_t, std::string> stringsArg,
37                       std::unordered_map<uint32_t, std::string> literalarraysArg)
38         : methods(std::move(methodsArg)),
39           fields(std::move(fieldsArg)),
40           classes(std::move(classesArg)),
41           strings(std::move(stringsArg)),
42           literalarrays(std::move(literalarraysArg))
43     {
44     }
45 
46     std::string GetMethodIdByOffset(uint32_t offset) const;
47     std::string GetStringIdByOffset(uint32_t offset) const;
48     std::string GetLiteralArrayIdByOffset(uint32_t offset) const;
49     std::string GetTypeIdByOffset(uint32_t offset) const;
50     std::string GetFieldIdByOffset(uint32_t offset) const;
51 
52     std::unordered_map<uint32_t, std::string> methods;
53     std::unordered_map<uint32_t, std::string> fields;
54     std::unordered_map<uint32_t, std::string> classes;
55     std::unordered_map<uint32_t, std::string> strings;
56     std::unordered_map<uint32_t, std::string> literalarrays;
57 };
58 
59 struct AbckitInst {
60     AbckitGraph *graph = nullptr;
61     ark::compiler::Inst *impl = nullptr;
62 
AbckitInstAbckitInst63     AbckitInst(AbckitGraph *graph, ark::compiler::Inst *impl) : graph(graph), impl(impl) {}
64     AbckitInst() = default;
65     DEFAULT_COPY_SEMANTIC(AbckitInst);
66     DEFAULT_NOEXCEPT_MOVE_SEMANTIC(AbckitInst);
67     ~AbckitInst() = default;
68 };
69 
70 struct AbckitBasicBlock {
71     AbckitGraph *graph;
72     ark::compiler::BasicBlock *impl;
73 };
74 
75 struct AbckitGraph {
76     AbckitFile *file = nullptr;
77     AbckitCoreFunction *function = nullptr;
78     AbckitIrInterface *irInterface = nullptr;
79     std::unordered_map<ark::compiler::BasicBlock *, AbckitBasicBlock *> implToBB;
80     std::unordered_map<ark::compiler::Inst *, AbckitInst *> implToInst;
81     std::unordered_map<uintptr_t, AbckitCoreClass *> ptrToClass;
82     ark::compiler::Graph *impl = nullptr;
83     void *internal = nullptr;
84 };
85 // NOLINTEND(misc-non-private-member-variables-in-classes)
86 
87 #endif  // LIBABCKIT_SRC_IR_IMPL_H
88