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
16#ifndef ECMASCRIPT_COMPILER_AOT_COMPILATION_ENV_H
17#define ECMASCRIPT_COMPILER_AOT_COMPILATION_ENV_H
18
19#include "ecmascript/compiler/compilation_env.h"
20
21namespace panda::ecmascript {
22class AOTCompilationEnv final : public CompilationEnv {
23public:
24    AOTCompilationEnv(EcmaVM *vm);
25    ~AOTCompilationEnv() = default;
26    bool IsAotCompiler() const override
27    {
28        return true;
29    }
30
31    JSRuntimeOptions &GetJSOptions() override;
32
33    // thread
34    const CMap<ElementsKind, std::pair<ConstantIndex, ConstantIndex>> &GetArrayHClassIndexMap() const override;
35    const BuiltinHClassEntries &GetBuiltinHClassEntries() const override;
36    JSHClass *GetBuiltinPrototypeHClass(BuiltinTypeId type) const override;
37
38    // context
39    JSTaggedValue FindConstpool(const JSPandaFile *jsPandaFile, panda_file::File::EntityId id) const override;
40    JSTaggedValue FindConstpool(const JSPandaFile *jsPandaFile, int32_t index) const override;
41    JSTaggedValue FindOrCreateUnsharedConstpool(const uint32_t methodOffset) const override;
42    JSTaggedValue FindOrCreateUnsharedConstpool(JSTaggedValue sharedConstpool) const override;
43    JSHandle<ConstantPool> FindOrCreateConstPool(const JSPandaFile *jsPandaFile,
44        panda_file::File::EntityId id) override;
45    JSTaggedValue GetConstantPoolByMethodOffset(const uint32_t methodOffset) const override;
46
47    // ConstantPool
48    JSTaggedValue GetArrayLiteralFromCache(JSTaggedValue constpool, uint32_t index, CString entry) const override;
49    JSTaggedValue GetObjectLiteralFromCache(JSTaggedValue constpool, uint32_t index, CString entry) const override;
50    JSTaggedValue GetMethodFromCache(JSTaggedValue constpool, uint32_t index) const override;
51    panda_file::File::EntityId GetIdFromCache(JSTaggedValue constpool, uint32_t index) const override;
52
53    // GlobalEnv
54    JSHandle<GlobalEnv> GetGlobalEnv() const override;
55
56    // GlobalConstants
57    const GlobalEnvConstants *GlobalConstants() const override;
58
59    JSTaggedValue GetStringFromConstantPool(const uint32_t methodOffset, const uint16_t cpIdx,
60        bool allowAlloc = true) const override;
61};
62} // namespace panda::ecmascript
63#endif  // ECMASCRIPT_COMPILER_AOT_COMPILATION_ENV_H
64