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