• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     AnFileInfo() = default;
25     ~AnFileInfo() override = default;
26     void Save(const std::string &filename, Triple triple);
AddModuleDes(ModuleSectionDes & moduleDes)27     void AddModuleDes(ModuleSectionDes &moduleDes)
28     {
29         des_.emplace_back(moduleDes);
30         for (auto &s : moduleDes.GetSectionsInfo()) {
31             auto sec = ElfSection(s.first);
32             if (sec.isSequentialAOTSec()) {
33                 accumulateTotalSize(s.second.second);
34             }
35         }
36         accumulateTotalSize(moduleDes.GetArkStackMapSize());
37     }
38 
GetMainFuncEntry(uint32_t methodId)39     std::pair<uint64_t, bool> GetMainFuncEntry(uint32_t methodId) const
40     {
41         auto it = mainEntryMap_.find(methodId);
42         if (it == mainEntryMap_.end()) {
43             return std::make_pair(0, false);
44         }
45         return it->second;
46     }
47 
48     void TryRemoveAnFile(const char *filename);
49 
AlignTextSec(uint32_t alignSize)50     void AlignTextSec(uint32_t alignSize)
51     {
52         curTextSecOffset_ = AlignUp(curTextSecOffset_, alignSize);
53     }
54 
UpdateCurTextSecOffset(uint64_t size)55     void UpdateCurTextSecOffset(uint64_t size)
56     {
57         curTextSecOffset_ += size;
58     }
59 
GetCurTextSecOffset()60     uint64_t GetCurTextSecOffset() const
61     {
62         return curTextSecOffset_;
63     }
64 
65     bool IsLoadMain(const JSPandaFile *jsPandaFile, const CString &entry) const;
66 
IsLoad()67     bool IsLoad() const
68     {
69         return isLoad_;
70     }
71 
72     void Destroy() override;
73 
74     void Dump() const;
75 
76 private:
77     static const std::vector<ElfSecName> &GetDumpSectionNames();
78     bool Load(const std::string &filename);
79     void ParseFunctionEntrySection(ModuleSectionDes &moduleDes);
80     void UpdateFuncEntries();
81     void AddFuncEntrySec();
82     uint64_t curTextSecOffset_ {0};
83     std::unordered_map<uint32_t, std::pair<uint64_t, bool>> mainEntryMap_ {};
84     bool isLoad_ {false};
85 
86     friend class AnFileDataManager;
87 };
88 }  // namespace panda::ecmascript
89 #endif // ECMASCRIPT_COMPILER_AOT_FILE_AN_FILE_INFO_H
90