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 #ifndef ABCKIT_SUBCLASSES_SCANNER_H 16 #define ABCKIT_SUBCLASSES_SCANNER_H 17 18 #include "libabckit/include/c/isa/isa_dynamic.h" 19 #include "helpers/helpers.h" 20 #include "helpers/helpers_runtime.h" 21 #include "helpers/visit_helper/visit_helper.h" 22 #include "helpers/visit_helper/visit_helper-inl.h" 23 #include "libabckit/include/c/metadata_core.h" 24 25 struct ClassInfo { 26 std::string path; 27 std::string className; 28 }; 29 30 class SubclassesScanner { 31 public: SubclassesScanner(enum AbckitApiVersion version,const AbckitApi * impl,AbckitFile * file,std::vector<ClassInfo> baseClasses)32 SubclassesScanner(enum AbckitApiVersion version, const AbckitApi *impl, AbckitFile *file, 33 std::vector<ClassInfo> baseClasses) 34 : file_(file), baseClasses_ {std::move(baseClasses)} 35 { 36 implI_ = AbckitGetInspectApiImpl(version); 37 implG_ = AbckitGetGraphApiImpl(version); 38 dynG_ = AbckitGetIsaApiDynamicImpl(version); 39 visitor_ = VisitHelper(file_, impl, implI_, implG_, dynG_); 40 } 41 GetSubclasses()42 const std::vector<ClassInfo> &GetSubclasses() 43 { 44 return subClasses_; 45 } 46 47 void Run(); 48 49 bool IsEqualsSubClasses(const std::vector<ClassInfo> &otherSubClasses); 50 51 private: 52 void CollectSubClasses(AbckitCoreFunction *method, 53 const std::vector<std::pair<AbckitCoreImportDescriptor *, size_t>> &impDescrs); 54 55 bool IsLoadApi(AbckitCoreImportDescriptor *id, AbckitInst *inst, ClassInfo &subclassInfo); 56 57 void GetImportDescriptors(AbckitCoreModule *mod, 58 std::vector<std::pair<AbckitCoreImportDescriptor *, size_t>> &importDescriptors); 59 60 private: 61 const AbckitInspectApi *implI_ = nullptr; 62 const AbckitGraphApi *implG_ = nullptr; 63 const AbckitIsaApiDynamic *dynG_ = nullptr; 64 AbckitFile *file_ = nullptr; 65 VisitHelper visitor_; 66 std::vector<ClassInfo> subClasses_; 67 std::vector<ClassInfo> baseClasses_; 68 }; 69 70 #endif // ABCKIT_SUBCLASSES_SCANNER_H 71