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_ADAPTER_DYNAMIC_RUNTIME_ADAPTER_DYNAMIC_H 17 #define LIBABCKIT_SRC_ADAPTER_DYNAMIC_RUNTIME_ADAPTER_DYNAMIC_H 18 19 #include "compiler/optimizer/ir/runtime_interface.h" 20 #include "libabckit/src/wrappers/abcfile_wrapper.h" 21 22 namespace libabckit { 23 24 using ark::compiler::RuntimeInterface; 25 26 class AbckitRuntimeAdapterDynamic : public RuntimeInterface { 27 public: AbckitRuntimeAdapterDynamic(const FileWrapper & abcFile)28 explicit AbckitRuntimeAdapterDynamic(const FileWrapper &abcFile) : abcFile_(abcFile) {} 29 GetBinaryFileForMethod(MethodPtr method)30 BinaryFilePtr GetBinaryFileForMethod([[maybe_unused]] MethodPtr method) const override 31 { 32 return const_cast<FileWrapper *>(&abcFile_); 33 } 34 ResolveMethodIndex(MethodPtr parentMethod,uint16_t index)35 uint32_t ResolveMethodIndex(MethodPtr parentMethod, uint16_t index) const override 36 { 37 return abcFile_.ResolveOffsetByIndex(parentMethod, index); 38 } 39 GetMethodId(MethodPtr method)40 MethodId GetMethodId(MethodPtr method) const override 41 { 42 return static_cast<MethodId>(reinterpret_cast<uintptr_t>(method)); 43 } 44 GetMethodTotalArgumentsCount(MethodPtr method)45 size_t GetMethodTotalArgumentsCount(MethodPtr method) const override 46 { 47 return abcFile_.GetMethodTotalArgumentsCount(method); 48 } 49 GetMethodArgumentsCount(MethodPtr caller,MethodId id)50 size_t GetMethodArgumentsCount([[maybe_unused]] MethodPtr caller, MethodId id) const override 51 { 52 return abcFile_.GetMethodArgumentsCount(caller, id); 53 } 54 GetMethodRegistersCount(MethodPtr method)55 size_t GetMethodRegistersCount(MethodPtr method) const override 56 { 57 return abcFile_.GetMethodRegistersCount(method); 58 } 59 GetMethodCode(MethodPtr method)60 const uint8_t *GetMethodCode(MethodPtr method) const override 61 { 62 return abcFile_.GetMethodCode(method); 63 } 64 GetMethodCodeSize(MethodPtr method)65 size_t GetMethodCodeSize(MethodPtr method) const override 66 { 67 return abcFile_.GetMethodCodeSize(method); 68 } 69 GetMethodSourceLanguage(MethodPtr method)70 ark::SourceLanguage GetMethodSourceLanguage(MethodPtr method) const override 71 { 72 return static_cast<ark::SourceLanguage>(abcFile_.GetMethodSourceLanguage(method)); 73 } 74 GetClassIdForMethod(MethodPtr method)75 uint32_t GetClassIdForMethod(MethodPtr method) const override 76 { 77 return abcFile_.GetClassIdForMethod(method); 78 } 79 GetClassNameFromMethod(MethodPtr method)80 std::string GetClassNameFromMethod(MethodPtr method) const override 81 { 82 return abcFile_.GetClassNameFromMethod(method); 83 } 84 GetMethodName(MethodPtr method)85 std::string GetMethodName(MethodPtr method) const override 86 { 87 return abcFile_.GetMethodName(method); 88 } 89 GetMethodFullName(MethodPtr method,bool)90 std::string GetMethodFullName(MethodPtr method, bool /* with_signature */) const override 91 { 92 auto className = GetClassNameFromMethod(method); 93 auto methodName = GetMethodName(method); 94 95 return className + "::" + methodName; 96 } 97 98 private: 99 const FileWrapper &abcFile_; 100 }; 101 102 } // namespace libabckit 103 104 #endif // LIBABCKIT_SRC_ADAPTER_DYNAMIC_RUNTIME_ADAPTER_DYNAMIC_H 105