14514f5e3Sopenharmony_ci/* 24514f5e3Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License. 54514f5e3Sopenharmony_ci * You may obtain a copy of the License at 64514f5e3Sopenharmony_ci * 74514f5e3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 84514f5e3Sopenharmony_ci * 94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and 134514f5e3Sopenharmony_ci * limitations under the License. 144514f5e3Sopenharmony_ci */ 154514f5e3Sopenharmony_ci 164514f5e3Sopenharmony_ci#ifndef ECMASCRIPT_COMPILER_COMPILATION_ENV_H 174514f5e3Sopenharmony_ci#define ECMASCRIPT_COMPILER_COMPILATION_ENV_H 184514f5e3Sopenharmony_ci 194514f5e3Sopenharmony_ci#include "ecmascript/global_env.h" 204514f5e3Sopenharmony_ci#include "ecmascript/js_handle.h" 214514f5e3Sopenharmony_ci#include "ecmascript/jspandafile/method_literal.h" 224514f5e3Sopenharmony_ci#include "ecmascript/pgo_profiler/pgo_utils.h" 234514f5e3Sopenharmony_ci 244514f5e3Sopenharmony_cinamespace panda::ecmascript { 254514f5e3Sopenharmony_cinamespace kungfu { 264514f5e3Sopenharmony_ciclass PGOTypeManager; 274514f5e3Sopenharmony_ci}; 284514f5e3Sopenharmony_ciclass ConstantPool; 294514f5e3Sopenharmony_cinamespace pgo { 304514f5e3Sopenharmony_ciclass PGOProfiler; 314514f5e3Sopenharmony_ci}; 324514f5e3Sopenharmony_ciclass JSThread; 334514f5e3Sopenharmony_ci 344514f5e3Sopenharmony_ciclass CompilationEnv { 354514f5e3Sopenharmony_cipublic: 364514f5e3Sopenharmony_ci CompilationEnv(EcmaVM *vm); 374514f5e3Sopenharmony_ci virtual ~CompilationEnv() = default; 384514f5e3Sopenharmony_ci virtual bool IsJitCompiler() const 394514f5e3Sopenharmony_ci { 404514f5e3Sopenharmony_ci return false; 414514f5e3Sopenharmony_ci } 424514f5e3Sopenharmony_ci virtual bool IsAotCompiler() const 434514f5e3Sopenharmony_ci { 444514f5e3Sopenharmony_ci return false; 454514f5e3Sopenharmony_ci } 464514f5e3Sopenharmony_ci EcmaVM *GetEcmaVM() const 474514f5e3Sopenharmony_ci { 484514f5e3Sopenharmony_ci return vm_; 494514f5e3Sopenharmony_ci } 504514f5e3Sopenharmony_ci 514514f5e3Sopenharmony_ci JSThread *GetJSThread() const 524514f5e3Sopenharmony_ci { 534514f5e3Sopenharmony_ci return thread_; 544514f5e3Sopenharmony_ci } 554514f5e3Sopenharmony_ci 564514f5e3Sopenharmony_ci kungfu::PGOTypeManager *GetPTManager() const 574514f5e3Sopenharmony_ci { 584514f5e3Sopenharmony_ci return ptManager_; 594514f5e3Sopenharmony_ci } 604514f5e3Sopenharmony_ci 614514f5e3Sopenharmony_ci NativeAreaAllocator *GetNativeAreaAllocator() const; 624514f5e3Sopenharmony_ci virtual JSRuntimeOptions &GetJSOptions() = 0; 634514f5e3Sopenharmony_ci virtual std::shared_ptr<pgo::PGOProfiler> GetPGOProfiler() const; 644514f5e3Sopenharmony_ci 654514f5e3Sopenharmony_ci // thread 664514f5e3Sopenharmony_ci virtual const CMap<ElementsKind, std::pair<ConstantIndex, ConstantIndex>> &GetArrayHClassIndexMap() const = 0; 674514f5e3Sopenharmony_ci virtual const BuiltinHClassEntries &GetBuiltinHClassEntries() const = 0; 684514f5e3Sopenharmony_ci virtual JSHClass *GetBuiltinPrototypeHClass(BuiltinTypeId type) const = 0; 694514f5e3Sopenharmony_ci 704514f5e3Sopenharmony_ci // context 714514f5e3Sopenharmony_ci virtual JSTaggedValue FindConstpool(const JSPandaFile *jsPandaFile, panda_file::File::EntityId id) const = 0; 724514f5e3Sopenharmony_ci virtual JSTaggedValue FindConstpool(const JSPandaFile *jsPandaFile, int32_t index) const = 0; 734514f5e3Sopenharmony_ci virtual JSTaggedValue FindOrCreateUnsharedConstpool(const uint32_t methodOffset) const = 0; 744514f5e3Sopenharmony_ci virtual JSTaggedValue FindOrCreateUnsharedConstpool(JSTaggedValue sharedConstpool) const = 0; 754514f5e3Sopenharmony_ci virtual JSHandle<ConstantPool> FindOrCreateConstPool(const JSPandaFile *jsPandaFile, 764514f5e3Sopenharmony_ci panda_file::File::EntityId id) = 0; 774514f5e3Sopenharmony_ci virtual JSTaggedValue GetConstantPoolByMethodOffset(const uint32_t methodOffset) const = 0; 784514f5e3Sopenharmony_ci 794514f5e3Sopenharmony_ci // ConstantPool 804514f5e3Sopenharmony_ci virtual JSTaggedValue GetArrayLiteralFromCache(JSTaggedValue constpool, uint32_t index, CString entry) const = 0; 814514f5e3Sopenharmony_ci virtual JSTaggedValue GetObjectLiteralFromCache(JSTaggedValue constpool, uint32_t index, CString entry) const = 0; 824514f5e3Sopenharmony_ci virtual JSTaggedValue GetMethodFromCache(JSTaggedValue constpool, uint32_t index) const = 0; 834514f5e3Sopenharmony_ci virtual panda_file::File::EntityId GetIdFromCache(JSTaggedValue constpool, uint32_t index) const = 0; 844514f5e3Sopenharmony_ci virtual JSTaggedValue GetStringFromConstantPool(const uint32_t methodOffset, const uint16_t cpIdx, 854514f5e3Sopenharmony_ci bool allowAlloc = true) const = 0; 864514f5e3Sopenharmony_ci 874514f5e3Sopenharmony_ci // GlobalEnv 884514f5e3Sopenharmony_ci virtual JSHandle<GlobalEnv> GetGlobalEnv() const = 0; 894514f5e3Sopenharmony_ci 904514f5e3Sopenharmony_ci // GlobalConstants 914514f5e3Sopenharmony_ci virtual const GlobalEnvConstants *GlobalConstants() const = 0; 924514f5e3Sopenharmony_ci 934514f5e3Sopenharmony_ci virtual JSThread *GetHostThread() const 944514f5e3Sopenharmony_ci { 954514f5e3Sopenharmony_ci ASSERT(0); 964514f5e3Sopenharmony_ci return nullptr; 974514f5e3Sopenharmony_ci } 984514f5e3Sopenharmony_ci 994514f5e3Sopenharmony_ci virtual JSPandaFile *GetJSPandaFile() const 1004514f5e3Sopenharmony_ci { 1014514f5e3Sopenharmony_ci ASSERT(0); 1024514f5e3Sopenharmony_ci return nullptr; 1034514f5e3Sopenharmony_ci } 1044514f5e3Sopenharmony_ci 1054514f5e3Sopenharmony_ci virtual MethodLiteral *GetMethodLiteral() const 1064514f5e3Sopenharmony_ci { 1074514f5e3Sopenharmony_ci ASSERT(0); 1084514f5e3Sopenharmony_ci return nullptr; 1094514f5e3Sopenharmony_ci } 1104514f5e3Sopenharmony_ci 1114514f5e3Sopenharmony_ci virtual const uint8_t *GetMethodPcStart() const 1124514f5e3Sopenharmony_ci { 1134514f5e3Sopenharmony_ci ASSERT(0); 1144514f5e3Sopenharmony_ci return nullptr; 1154514f5e3Sopenharmony_ci } 1164514f5e3Sopenharmony_ci 1174514f5e3Sopenharmony_ci virtual pgo::ApEntityId GetMethodAbcId() const 1184514f5e3Sopenharmony_ci { 1194514f5e3Sopenharmony_ci ASSERT(0); 1204514f5e3Sopenharmony_ci return 0; 1214514f5e3Sopenharmony_ci } 1224514f5e3Sopenharmony_ci 1234514f5e3Sopenharmony_ciprotected: 1244514f5e3Sopenharmony_ci EcmaVM *vm_ {nullptr}; 1254514f5e3Sopenharmony_ci JSThread *thread_ {nullptr}; 1264514f5e3Sopenharmony_ci kungfu::PGOTypeManager *ptManager_ {nullptr}; 1274514f5e3Sopenharmony_ci}; 1284514f5e3Sopenharmony_ci} // namespace panda::ecmascript 1294514f5e3Sopenharmony_ci#endif // ECMASCRIPT_COMPILER_COMPILATION_ENV_H 130