• 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 ABCKIT_API_MODIFIER_H
17 #define ABCKIT_API_MODIFIER_H
18 
19 #include <vector>
20 #include "libabckit/include/c/abckit.h"
21 #include "helpers/visit_helper/visit_helper.h"
22 
23 struct MethodInfo {
24     std::string path;
25     std::string className;
26     std::string methodName;
27 };
28 
29 class ApiModifier {
30 public:
ApiModifier(enum AbckitApiVersion version,AbckitFile * file,const AbckitApi * impl,MethodInfo methodInfo)31     ApiModifier(enum AbckitApiVersion version, AbckitFile *file, const AbckitApi *impl, MethodInfo methodInfo)
32         : impl_(impl), file_(file), methodInfo_(std::move(methodInfo))
33     {
34         implM_ = AbckitGetModifyApiImpl(version);
35         implI_ = AbckitGetInspectApiImpl(version);
36         implG_ = AbckitGetGraphApiImpl(version);
37         dynG_ = AbckitGetIsaApiDynamicImpl(version);
38         visitor_ = VisitHelper(file_, impl_, implI_, implG_, dynG_);
39     }
40 
41     void Run();
42 
GetFile()43     AbckitFile *GetFile()
44     {
45         return file_;
46     }
47 
48 private:
49     AbckitCoreImportDescriptor *GetImportDescriptor(AbckitCoreModule *module);
50     void ModifyFunction(AbckitCoreFunction *method, AbckitCoreImportDescriptor *id);
51     void AddParamChecker(AbckitCoreFunction *method);
52     AbckitCoreFunction *GetSubclassMethod(AbckitCoreImportDescriptor *id, AbckitInst *inst);
53     AbckitCoreFunction *GetMethodToModify(AbckitCoreClass *klass);
54 
55 private:
56     const AbckitApi *impl_ = nullptr;
57     const AbckitModifyApi *implM_ = nullptr;
58     const AbckitInspectApi *implI_ = nullptr;
59     const AbckitGraphApi *implG_ = nullptr;
60     const AbckitIsaApiDynamic *dynG_ = nullptr;
61     AbckitFile *file_ = nullptr;
62     VisitHelper visitor_;
63     MethodInfo methodInfo_;
64 };
65 
66 #endif  // ABCKIT_API_MODIFIER_H
67