1 /* 2 * Copyright (c) 2021-2022 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 ES2PANDA_COMPILER_CORE_COMPILEQUEUE_H 17 #define ES2PANDA_COMPILER_CORE_COMPILEQUEUE_H 18 19 #include <aot/options.h> 20 #include <macros.h> 21 #include <os/thread.h> 22 #include <util/symbolTable.h> 23 #include <util/workerQueue.h> 24 25 #include <condition_variable> 26 #include <mutex> 27 28 namespace panda::es2panda::binder { 29 class FunctionScope; 30 } // namespace panda::es2panda::binder 31 32 namespace panda::es2panda::compiler { 33 34 class CompilerContext; 35 36 class CompileFunctionJob : public util::WorkerJob { 37 public: CompileFunctionJob(CompilerContext * context)38 explicit CompileFunctionJob(CompilerContext *context) : context_(context) {}; 39 NO_COPY_SEMANTIC(CompileFunctionJob); 40 NO_MOVE_SEMANTIC(CompileFunctionJob); 41 ~CompileFunctionJob() override = default; 42 Scope()43 binder::FunctionScope *Scope() const 44 { 45 return scope_; 46 } 47 SetFunctionScope(binder::FunctionScope * scope)48 void SetFunctionScope(binder::FunctionScope *scope) 49 { 50 scope_ = scope; 51 } 52 53 void Run() override; 54 55 private: 56 CompilerContext *context_ {}; 57 binder::FunctionScope *scope_ {}; 58 }; 59 60 class CompileModuleRecordJob : public util::WorkerJob { 61 public: CompileModuleRecordJob(CompilerContext * context)62 explicit CompileModuleRecordJob(CompilerContext *context) : context_(context) {}; 63 NO_COPY_SEMANTIC(CompileModuleRecordJob); 64 NO_MOVE_SEMANTIC(CompileModuleRecordJob); 65 ~CompileModuleRecordJob() override = default; 66 67 void Run() override; 68 69 private: 70 CompilerContext *context_ {}; 71 }; 72 73 class CompileFileJob : public util::WorkerJob { 74 public: CompileFileJob(es2panda::SourceFile * src,es2panda::CompilerOptions * options,std::map<std::string,panda::es2panda::util::ProgramCache * > & progsInfo,util::SymbolTable * symbolTable,panda::ArenaAllocator * allocator)75 explicit CompileFileJob(es2panda::SourceFile *src, es2panda::CompilerOptions *options, 76 std::map<std::string, panda::es2panda::util::ProgramCache*> &progsInfo, 77 util::SymbolTable *symbolTable, panda::ArenaAllocator *allocator) 78 : src_(src), options_(options), progsInfo_(progsInfo), symbolTable_(symbolTable), allocator_(allocator) {}; 79 NO_COPY_SEMANTIC(CompileFileJob); 80 NO_MOVE_SEMANTIC(CompileFileJob); 81 ~CompileFileJob() override = default; 82 83 void Run() override; 84 85 private: 86 static std::mutex global_m_; 87 es2panda::SourceFile *src_; 88 es2panda::CompilerOptions *options_; 89 std::map<std::string, panda::es2panda::util::ProgramCache*> &progsInfo_; 90 util::SymbolTable *symbolTable_; 91 panda::ArenaAllocator *allocator_; 92 }; 93 94 class CompileFuncQueue : public util::WorkerQueue { 95 public: CompileFuncQueue(size_t threadCount,CompilerContext * context)96 explicit CompileFuncQueue(size_t threadCount, CompilerContext *context) 97 : util::WorkerQueue(threadCount), context_(context) {} 98 99 NO_COPY_SEMANTIC(CompileFuncQueue); 100 NO_MOVE_SEMANTIC(CompileFuncQueue); 101 ~CompileFuncQueue() override = default; 102 103 void Schedule() override; 104 105 private: 106 CompilerContext *context_; 107 }; 108 109 class CompileFileQueue : public util::WorkerQueue { 110 public: CompileFileQueue(size_t threadCount,es2panda::CompilerOptions * options,std::map<std::string,panda::es2panda::util::ProgramCache * > & progsInfo,util::SymbolTable * symbolTable,panda::ArenaAllocator * allocator)111 explicit CompileFileQueue(size_t threadCount, es2panda::CompilerOptions *options, 112 std::map<std::string, panda::es2panda::util::ProgramCache*> &progsInfo, 113 util::SymbolTable *symbolTable, panda::ArenaAllocator *allocator) 114 : util::WorkerQueue(threadCount), options_(options), progsInfo_(progsInfo), 115 symbolTable_(symbolTable), allocator_(allocator) {} 116 117 NO_COPY_SEMANTIC(CompileFileQueue); 118 NO_MOVE_SEMANTIC(CompileFileQueue); 119 ~CompileFileQueue() override = default; 120 121 void Schedule() override; 122 123 private: 124 es2panda::CompilerOptions *options_; 125 std::map<std::string, panda::es2panda::util::ProgramCache*> &progsInfo_; 126 util::SymbolTable *symbolTable_; 127 panda::ArenaAllocator *allocator_; 128 }; 129 130 } // namespace panda::es2panda::compiler 131 132 #endif 133