1 /* 2 * Copyright (c) 2023 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 ECMASCRIPT_COMPILER_AOT_FILE_AN_FILE_INFO_H 16 #define ECMASCRIPT_COMPILER_AOT_FILE_AN_FILE_INFO_H 17 18 #include "ecmascript/compiler/aot_file/aot_file_info.h" 19 #include "ecmascript/compiler/assembler/assembler.h" 20 21 namespace panda::ecmascript { 22 class PUBLIC_API AnFileInfo : public AOTFileInfo { 23 public: 24 using FuncEntryIndexKey = std::pair<std::string, uint32_t>; // (compilefileName, MethodID) 25 AnFileInfo() = default; 26 ~AnFileInfo() override = default; 27 void Save(const std::string &filename, Triple triple); AddModuleDes(ModuleSectionDes & moduleDes)28 void AddModuleDes(ModuleSectionDes &moduleDes) 29 { 30 des_.emplace_back(moduleDes); 31 for (auto &s : moduleDes.GetSectionsInfo()) { 32 auto sec = ElfSection(s.first); 33 if (sec.isSequentialAOTSec()) { 34 accumulateTotalSize(s.second.second); 35 } 36 } 37 accumulateTotalSize(moduleDes.GetArkStackMapSize()); 38 } 39 GetMainFuncEntry(uint32_t fileIndex,uint32_t methodId)40 std::pair<uint64_t, bool> GetMainFuncEntry(uint32_t fileIndex, uint32_t methodId) const 41 { 42 auto it = mainEntryMap_.find(std::make_pair(fileIndex, methodId)); 43 if (it == mainEntryMap_.end()) { 44 return std::make_pair(0, false); 45 } 46 return it->second; 47 } 48 49 void TryRemoveAnFile(const char *filename); 50 AlignTextSec(uint32_t alignSize)51 void AlignTextSec(uint32_t alignSize) 52 { 53 curTextSecOffset_ = AlignUp(curTextSecOffset_, alignSize); 54 } 55 UpdateCurTextSecOffset(uint64_t size)56 void UpdateCurTextSecOffset(uint64_t size) 57 { 58 curTextSecOffset_ += size; 59 } 60 GetCurTextSecOffset()61 uint64_t GetCurTextSecOffset() const 62 { 63 return curTextSecOffset_; 64 } 65 66 bool IsLoadMain(uint32_t fileIndex, const JSPandaFile *jsPandaFile, const CString &entry) const; 67 IsLoad()68 bool IsLoad() const 69 { 70 return isLoad_; 71 } 72 73 void Destroy() override; 74 MappingEntryFuncsToAbcFiles(std::string curCompileFileName,uint32_t start,uint32_t end)75 void MappingEntryFuncsToAbcFiles(std::string curCompileFileName, uint32_t start, uint32_t end) 76 { 77 while (start < end) { 78 entryIdxToFileNameMap_[start] = curCompileFileName; 79 ++start; 80 } 81 } 82 GetMethodToEntryIndexMap()83 const CMap<FuncEntryIndexKey, uint32_t>& GetMethodToEntryIndexMap() const 84 { 85 return methodToEntryIndexMap_; 86 } 87 88 void GenerateMethodToEntryIndexMap(); 89 90 void Dump() const; 91 92 private: 93 static const std::vector<ElfSecName> &GetDumpSectionNames(); 94 using EntryKey = std::pair<uint32_t, uint32_t>; 95 bool Load(const std::string &filename); 96 void ParseFunctionEntrySection(ModuleSectionDes &moduleDes); 97 void UpdateFuncEntries(); 98 void AddFuncEntrySec(); 99 uint64_t curTextSecOffset_ {0}; 100 // Future work: add main entry mapping to ai file 101 std::map<EntryKey, std::pair<uint64_t, bool>> mainEntryMap_ {}; 102 bool isLoad_ {false}; 103 CUnorderedMap<uint32_t, std::string> entryIdxToFileNameMap_ {}; 104 CMap<FuncEntryIndexKey, uint32_t> methodToEntryIndexMap_ {}; 105 106 friend class AnFileDataManager; 107 }; 108 } // namespace panda::ecmascript 109 #endif // ECMASCRIPT_COMPILER_AOT_FILE_AN_FILE_INFO_H 110