• 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 
16 #ifndef ECMASCRIPT_JIT_RESOURCES_H
17 #define ECMASCRIPT_JIT_RESOURCES_H
18 
19 #include "ecmascript/ecma_vm.h"
20 
21 namespace panda::ecmascript {
22 class JitTask;
23 using InitJitCompilerFuncType = void (*)(JSRuntimeOptions options);
24 using JitCompileFuncType = bool(*)(void*, JitTask*);
25 using JitFinalizeFuncType = bool(*)(void*, JitTask*);
26 using CreateJitCompilerTaskFuncType = void*(*)(JitTask*);
27 using DeleteJitCompilerTaskFuncType = void(*)(void*);
28 
29 class JitResources {
30 public:
31     JitResources() = default;
32     ~JitResources() = default;
33 
34     void Resolve();
35     void Destroy();
36 
IsLibResolved()37     bool IsLibResolved() const
38     {
39         return libResolved_;
40     }
41 
Compile(void * compiler,JitTask * jitTask)42     bool Compile(void *compiler, JitTask *jitTask)
43     {
44         if (jitCompile_ == nullptr) {
45             return false;
46         }
47         return jitCompile_(compiler, jitTask);
48     }
49 
Finalize(void * compiler,JitTask * jitTask)50     bool Finalize(void *compiler, JitTask *jitTask)
51     {
52         if (jitFinalize_ == nullptr) {
53             return false;
54         }
55         return jitFinalize_(compiler, jitTask);
56     }
57 
CreateJitCompilerTask(JitTask * jitTask)58     void *CreateJitCompilerTask(JitTask *jitTask)
59     {
60         if (createJitCompilerTask_ == nullptr) {
61             return nullptr;
62         }
63         return createJitCompilerTask_(jitTask);
64     }
65 
DeleteJitCompilerTask(void * compilerTask)66     void DeleteJitCompilerTask(void *compilerTask)
67     {
68         if (deleteJitCompilerTask_ == nullptr) {
69             return;
70         }
71         deleteJitCompilerTask_(compilerTask);
72     }
73     bool ResolveLib();
74     bool InitJitEnv(const JSRuntimeOptions &options);
75 
76 private:
77     void DoResolve();
78     void InitCompiler();
79     void InitJitTaskpool();
80 
81     JSRuntimeOptions jsRuntimeOptions_;
82     bool libResolved_ {false};
83 
84     InitJitCompilerFuncType initJitCompiler_ {nullptr};
85     JitCompileFuncType jitCompile_ {nullptr};
86     JitFinalizeFuncType jitFinalize_ {nullptr};
87     CreateJitCompilerTaskFuncType createJitCompilerTask_ {nullptr};
88     DeleteJitCompilerTaskFuncType deleteJitCompilerTask_ {nullptr};
89     void *libHandle_ {nullptr};
90 
91     NO_COPY_SEMANTIC(JitResources);
92     NO_MOVE_SEMANTIC(JitResources);
93 };
94 }  // namespace panda::ecmascript
95 #endif  // ECMASCRIPT_JIT_RESOURCES_H
96