1 /** 2 * Copyright (c) 2021-2022 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 COMPILER_OPTIMIZER_IR_RUNTIME_INTERFACE_H 17 #define COMPILER_OPTIMIZER_IR_RUNTIME_INTERFACE_H 18 19 #include <cstdint> 20 #include <cstddef> 21 #include "assembler/assembly-literals.h" 22 #include "constants.h" 23 #include "datatype.h" 24 #include "ir-dyn-base-types.h" 25 #include "mem/gc_barrier.h" 26 #include "source_languages.h" 27 #include "utils/arch.h" 28 #include "utils/span.h" 29 #include "utils/arena_containers.h" 30 31 namespace panda::compiler { 32 enum class ClassType { 33 UNRESOLVED_CLASS = 0, 34 OBJECT_CLASS, 35 ARRAY_CLASS, 36 ARRAY_OBJECT_CLASS, 37 INTERFACE_CLASS, 38 OTHER_CLASS, 39 FINAL_CLASS, 40 COUNT 41 }; 42 43 class Inst; 44 45 class RuntimeInterface { 46 public: 47 using BinaryFilePtr = void *; 48 using MethodPtr = void *; 49 using FieldPtr = void *; 50 using MethodId = uint32_t; 51 using StringPtr = void *; 52 using ClassPtr = void *; 53 using IdType = uint32_t; 54 using FieldId = uint32_t; 55 using StringId = uint32_t; 56 using LiteralArrayId = uint32_t; 57 using MethodIndex = uint16_t; 58 using FieldIndex = uint16_t; 59 using TypeIndex = uint16_t; 60 using StringIndex = uint16_t; 61 using LiteralArrayIndex = uint16_t; 62 63 static const uintptr_t RESOLVE_STRING_AOT_COUNTER_LIMIT = PANDA_32BITS_HEAP_START_ADDRESS; 64 65 RuntimeInterface() = default; 66 virtual ~RuntimeInterface() = default; 67 ResolveOffsetByIndex(MethodPtr parent_method,uint16_t index)68 virtual uint32_t ResolveOffsetByIndex([[maybe_unused]] MethodPtr parent_method, 69 [[maybe_unused]] uint16_t index) const 70 { 71 return 0; 72 } 73 GetBinaryFileForMethod(MethodPtr method)74 virtual BinaryFilePtr GetBinaryFileForMethod([[maybe_unused]] MethodPtr method) const 75 { 76 return nullptr; 77 } 78 GetMethodId(MethodPtr method)79 virtual MethodId GetMethodId([[maybe_unused]] MethodPtr method) const 80 { 81 return 0; 82 } 83 84 // Return total arguments count including this for instance method GetMethodTotalArgumentsCount(MethodPtr method)85 virtual size_t GetMethodTotalArgumentsCount([[maybe_unused]] MethodPtr method) const 86 { 87 return 0; 88 } GetMethodArgumentsCount(MethodPtr parent_method,MethodId id)89 virtual size_t GetMethodArgumentsCount([[maybe_unused]] MethodPtr parent_method, [[maybe_unused]] MethodId id) const 90 { 91 return 0; 92 } GetMethodArgumentsCount(MethodPtr method)93 virtual size_t GetMethodArgumentsCount([[maybe_unused]] MethodPtr method) const 94 { 95 return 0; 96 } GetMethodRegistersCount(MethodPtr method)97 virtual size_t GetMethodRegistersCount([[maybe_unused]] MethodPtr method) const 98 { 99 return 0; 100 } GetMethodCode(MethodPtr method)101 virtual const uint8_t *GetMethodCode([[maybe_unused]] MethodPtr method) const 102 { 103 return nullptr; 104 } GetMethodCodeSize(MethodPtr method)105 virtual size_t GetMethodCodeSize([[maybe_unused]] MethodPtr method) const 106 { 107 return 0; 108 } 109 GetMethodSourceLanguage(MethodPtr method)110 virtual SourceLanguage GetMethodSourceLanguage([[maybe_unused]] MethodPtr method) const 111 { 112 return SourceLanguage::PANDA_ASSEMBLY; 113 } 114 GetClassNameFromMethod(MethodPtr method)115 virtual std::string GetClassNameFromMethod([[maybe_unused]] MethodPtr method) const 116 { 117 return "UnknownClass"; 118 } 119 GetClass(MethodPtr method)120 virtual ClassPtr GetClass([[maybe_unused]] MethodPtr method) const 121 { 122 return nullptr; 123 } 124 GetMethodName(MethodPtr method)125 virtual std::string GetMethodName([[maybe_unused]] MethodPtr method) const 126 { 127 return "UnknownMethod"; 128 } 129 GetMethodFullName(MethodPtr method,bool with_signature)130 virtual std::string GetMethodFullName([[maybe_unused]] MethodPtr method, [[maybe_unused]] bool with_signature) const 131 { 132 return "UnknownMethod"; 133 } 134 GetMethodFullName(MethodPtr method)135 std::string GetMethodFullName(MethodPtr method) const 136 { 137 return GetMethodFullName(method, false); 138 } 139 140 /************************************************************************** 141 * Class information 142 */ 143 144 // returns Class Id for Method GetClassIdForMethod(MethodPtr method)145 virtual size_t GetClassIdForMethod([[maybe_unused]] MethodPtr method) const 146 { 147 return 0; 148 } 149 150 #include <ecma_intrinsics_enum.inl> 151 152 // TypeInfoIndex adaption GetTypeInfoIndexByInstId(size_t id)153 virtual TypeInfoIndex GetTypeInfoIndexByInstId([[maybe_unused]] size_t id) const 154 { 155 return NO_EXPLICIT_TYPE; 156 } 157 IsPcBindType(int32_t pc)158 virtual bool IsPcBindType([[maybe_unused]] int32_t pc) const 159 { 160 return false; 161 } 162 FillInstIdTypePairByPc(size_t id,int32_t pc)163 virtual bool FillInstIdTypePairByPc([[maybe_unused]] size_t id, [[maybe_unused]] int32_t pc) 164 { 165 return false; 166 } 167 HasInsTypeinfo()168 virtual bool HasInsTypeinfo() const 169 { 170 return false; 171 } 172 AddPcTypePair(int32_t pc,TypeInfoIndex type)173 virtual bool AddPcTypePair([[maybe_unused]] int32_t pc, [[maybe_unused]] TypeInfoIndex type) 174 { 175 return false; 176 } 177 FillArgTypePairs(std::unordered_map<int32_t,TypeInfoIndex> * map)178 virtual bool FillArgTypePairs([[maybe_unused]] std::unordered_map<int32_t, TypeInfoIndex> *map) const 179 { 180 return false; 181 } 182 SetTypeLiteralArrayKey(std::string key)183 virtual bool SetTypeLiteralArrayKey([[maybe_unused]] std::string key) 184 { 185 return false; 186 } 187 GetTypeLiteralArrayKey()188 virtual const std::string *GetTypeLiteralArrayKey() const 189 { 190 return nullptr; 191 } 192 193 NO_COPY_SEMANTIC(RuntimeInterface); 194 NO_MOVE_SEMANTIC(RuntimeInterface); 195 196 private: 197 static constexpr uint32_t ARRAY_DEFAULT_ELEMENT_SIZE = 4; 198 }; 199 } // namespace panda::compiler 200 201 #endif // COMPILER_OPTIMIZER_IR_RUNTIME_INTERFACE_H 202