• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "ecmascript/compiler/aot_compilation_env.h"
16 #include "ecmascript/compiler/pgo_type/pgo_type_manager.h"
17 #include "ecmascript/ecma_context.h"
18 #include "ecmascript/jspandafile/program_object.h"
19 
20 namespace panda::ecmascript {
AOTCompilationEnv(EcmaVM * vm)21 AOTCompilationEnv::AOTCompilationEnv(EcmaVM *vm) : CompilationEnv(vm)
22 {
23     ptManager_ = thread_->GetCurrentEcmaContext()->GetPTManager();
24 }
25 
GetJSOptions()26 JSRuntimeOptions &AOTCompilationEnv::GetJSOptions()
27 {
28     return vm_->GetJSOptions();
29 }
30 
GetGlobalEnv() const31 JSHandle<GlobalEnv> AOTCompilationEnv::GetGlobalEnv() const
32 {
33     return vm_->GetGlobalEnv();
34 }
35 
GetArrayHClassIndexMap() const36 const CMap<ElementsKind, std::pair<ConstantIndex, ConstantIndex>> &AOTCompilationEnv::GetArrayHClassIndexMap() const
37 {
38     return thread_->GetArrayHClassIndexMap();
39 }
40 
GetBuiltinHClassEntries() const41 const BuiltinHClassEntries &AOTCompilationEnv::GetBuiltinHClassEntries() const
42 {
43     return thread_->GetBuiltinHClassEntries();
44 }
45 
GetBuiltinPrototypeHClass(BuiltinTypeId type) const46 JSHClass *AOTCompilationEnv::GetBuiltinPrototypeHClass(BuiltinTypeId type) const
47 {
48     return thread_->GetBuiltinPrototypeHClass(type);
49 }
50 
FindConstpool(const JSPandaFile * jsPandaFile,panda_file::File::EntityId id) const51 JSTaggedValue AOTCompilationEnv::FindConstpool(const JSPandaFile *jsPandaFile, panda_file::File::EntityId id) const
52 {
53     return thread_->GetCurrentEcmaContext()->FindConstpool(jsPandaFile, id);
54 }
55 
FindConstpool(const JSPandaFile * jsPandaFile,int32_t index) const56 JSTaggedValue AOTCompilationEnv::FindConstpool(const JSPandaFile *jsPandaFile, int32_t index) const
57 {
58     return thread_->GetCurrentEcmaContext()->FindConstpool(jsPandaFile, index);
59 }
60 
FindOrCreateUnsharedConstpool(const uint32_t methodOffset) const61 JSTaggedValue AOTCompilationEnv::FindOrCreateUnsharedConstpool(const uint32_t methodOffset) const
62 {
63     JSTaggedValue cp = ptManager_->GetConstantPoolByMethodOffset(methodOffset);
64     return thread_->GetCurrentEcmaContext()->FindOrCreateUnsharedConstpool(cp);
65 }
66 
FindOrCreateUnsharedConstpool(JSTaggedValue sharedConstpool) const67 JSTaggedValue AOTCompilationEnv::FindOrCreateUnsharedConstpool(JSTaggedValue sharedConstpool) const
68 {
69     return thread_->GetCurrentEcmaContext()->FindOrCreateUnsharedConstpool(sharedConstpool);
70 }
71 
FindOrCreateConstPool(const JSPandaFile * jsPandaFile,panda_file::File::EntityId id)72 JSHandle<ConstantPool> AOTCompilationEnv::FindOrCreateConstPool(const JSPandaFile *jsPandaFile,
73     panda_file::File::EntityId id)
74 {
75     return thread_->GetCurrentEcmaContext()->FindOrCreateConstPool(jsPandaFile, id);
76 }
77 
GetConstantPoolByMethodOffset(const uint32_t methodOffset) const78 JSTaggedValue AOTCompilationEnv::GetConstantPoolByMethodOffset(const uint32_t methodOffset) const
79 {
80     return ptManager_->GetConstantPoolByMethodOffset(methodOffset);
81 }
82 
GlobalConstants() const83 const GlobalEnvConstants *AOTCompilationEnv::GlobalConstants() const
84 {
85     return thread_->GlobalConstants();
86 }
87 
GetArrayLiteralFromCache(JSTaggedValue constpool,uint32_t index,CString entry) const88 JSTaggedValue AOTCompilationEnv::GetArrayLiteralFromCache(JSTaggedValue constpool, uint32_t index, CString entry) const
89 {
90     return ConstantPool::GetLiteralFromCache<ConstPoolType::ARRAY_LITERAL>(thread_, constpool, index, entry);
91 }
92 
GetObjectLiteralFromCache(JSTaggedValue constpool,uint32_t index,CString entry) const93 JSTaggedValue AOTCompilationEnv::GetObjectLiteralFromCache(JSTaggedValue constpool, uint32_t index, CString entry) const
94 {
95     return ConstantPool::GetLiteralFromCache<ConstPoolType::OBJECT_LITERAL>(thread_, constpool, index, entry);
96 }
97 
GetMethodFromCache(JSTaggedValue constpool,uint32_t index) const98 JSTaggedValue AOTCompilationEnv::GetMethodFromCache(JSTaggedValue constpool, uint32_t index) const
99 {
100     return ConstantPool::GetMethodFromCache(thread_, constpool, index);
101 }
102 
GetIdFromCache(JSTaggedValue constpool,uint32_t index) const103 panda_file::File::EntityId AOTCompilationEnv::GetIdFromCache(JSTaggedValue constpool, uint32_t index) const
104 {
105     return ConstantPool::GetIdFromCache(constpool, index);
106 }
107 
GetStringFromConstantPool(const uint32_t methodOffset,const uint16_t cpIdx,bool allowAlloc) const108 JSTaggedValue AOTCompilationEnv::GetStringFromConstantPool(const uint32_t methodOffset, const uint16_t cpIdx,
109     [[maybe_unused]] bool allowAlloc) const
110 {
111     return ptManager_->GetStringFromConstantPool(methodOffset, cpIdx);
112 }
113 } // namespace panda::ecmascript
114