• 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/jspandafile/program_object.h"
18 
19 namespace panda::ecmascript {
AOTCompilationEnv(EcmaVM * vm)20 AOTCompilationEnv::AOTCompilationEnv(EcmaVM *vm) : CompilationEnv(vm)
21 {
22     ptManager_ = thread_->GetCurrentEcmaContext()->GetPTManager();
23 }
24 
GetJSOptions()25 JSRuntimeOptions &AOTCompilationEnv::GetJSOptions()
26 {
27     return vm_->GetJSOptions();
28 }
29 
GetGlobalEnv() const30 JSHandle<GlobalEnv> AOTCompilationEnv::GetGlobalEnv() const
31 {
32     return vm_->GetGlobalEnv();
33 }
34 
GetArrayHClassIndex(ElementsKind kind,bool isProtoType) const35 ConstantIndex AOTCompilationEnv::GetArrayHClassIndex(ElementsKind kind, bool isProtoType) const
36 {
37     return thread_->GetArrayInstanceHClassIndex(kind, isProtoType);
38 }
39 
GetBuiltinHClassEntries() const40 const BuiltinHClassEntries &AOTCompilationEnv::GetBuiltinHClassEntries() const
41 {
42     return thread_->GetBuiltinHClassEntries();
43 }
44 
GetBuiltinPrototypeHClass(BuiltinTypeId type) const45 JSHClass *AOTCompilationEnv::GetBuiltinPrototypeHClass(BuiltinTypeId type) const
46 {
47     return thread_->GetBuiltinPrototypeHClass(type);
48 }
49 
FindConstpool(const JSPandaFile * jsPandaFile,panda_file::File::EntityId id) const50 JSTaggedValue AOTCompilationEnv::FindConstpool(const JSPandaFile *jsPandaFile, panda_file::File::EntityId id) const
51 {
52     return thread_->GetCurrentEcmaContext()->FindConstpool(jsPandaFile, id);
53 }
54 
FindConstpool(const JSPandaFile * jsPandaFile,int32_t index) const55 JSTaggedValue AOTCompilationEnv::FindConstpool(const JSPandaFile *jsPandaFile, int32_t index) const
56 {
57     return thread_->GetCurrentEcmaContext()->FindConstpool(jsPandaFile, index);
58 }
59 
FindOrCreateUnsharedConstpool(const uint32_t methodOffset) const60 JSTaggedValue AOTCompilationEnv::FindOrCreateUnsharedConstpool(const uint32_t methodOffset) const
61 {
62     JSTaggedValue cp = ptManager_->GetConstantPoolByMethodOffset(methodOffset);
63     return thread_->GetCurrentEcmaContext()->FindOrCreateUnsharedConstpool(cp);
64 }
65 
FindOrCreateUnsharedConstpool(JSTaggedValue sharedConstpool) const66 JSTaggedValue AOTCompilationEnv::FindOrCreateUnsharedConstpool(JSTaggedValue sharedConstpool) const
67 {
68     return thread_->GetCurrentEcmaContext()->FindOrCreateUnsharedConstpool(sharedConstpool);
69 }
70 
FindOrCreateConstPool(const JSPandaFile * jsPandaFile,panda_file::File::EntityId id)71 JSHandle<ConstantPool> AOTCompilationEnv::FindOrCreateConstPool(const JSPandaFile *jsPandaFile,
72     panda_file::File::EntityId id)
73 {
74     return thread_->GetCurrentEcmaContext()->FindOrCreateConstPool(jsPandaFile, id);
75 }
76 
GetConstantPoolByMethodOffset(const uint32_t methodOffset) const77 JSTaggedValue AOTCompilationEnv::GetConstantPoolByMethodOffset(const uint32_t methodOffset) const
78 {
79     return ptManager_->GetConstantPoolByMethodOffset(methodOffset);
80 }
81 
GlobalConstants() const82 const GlobalEnvConstants *AOTCompilationEnv::GlobalConstants() const
83 {
84     return thread_->GlobalConstants();
85 }
86 
GetArrayLiteralFromCache(JSTaggedValue constpool,uint32_t index,CString entry) const87 JSTaggedValue AOTCompilationEnv::GetArrayLiteralFromCache(JSTaggedValue constpool, uint32_t index, CString entry) const
88 {
89     return ConstantPool::GetLiteralFromCache<ConstPoolType::ARRAY_LITERAL>(thread_, constpool, index, entry);
90 }
91 
GetObjectLiteralFromCache(JSTaggedValue constpool,uint32_t index,CString entry) const92 JSTaggedValue AOTCompilationEnv::GetObjectLiteralFromCache(JSTaggedValue constpool, uint32_t index, CString entry) const
93 {
94     return ConstantPool::GetLiteralFromCache<ConstPoolType::OBJECT_LITERAL>(thread_, constpool, index, entry);
95 }
96 
GetMethodFromCache(JSTaggedValue constpool,uint32_t index) const97 JSTaggedValue AOTCompilationEnv::GetMethodFromCache(JSTaggedValue constpool, uint32_t index) const
98 {
99     return ConstantPool::GetMethodFromCache(thread_, constpool, index);
100 }
101 
GetIdFromCache(JSTaggedValue constpool,uint32_t index) const102 panda_file::File::EntityId AOTCompilationEnv::GetIdFromCache(JSTaggedValue constpool, uint32_t index) const
103 {
104     return ConstantPool::GetIdFromCache(constpool, index);
105 }
106 
GetStringFromConstantPool(const uint32_t methodOffset,const uint16_t cpIdx,bool allowAlloc) const107 JSTaggedValue AOTCompilationEnv::GetStringFromConstantPool(const uint32_t methodOffset, const uint16_t cpIdx,
108     [[maybe_unused]] bool allowAlloc) const
109 {
110     return ptManager_->GetStringFromConstantPool(methodOffset, cpIdx);
111 }
112 } // namespace panda::ecmascript
113