1 /* 2 * Copyright (c) 2023 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_AOT_EMITFILES_H 17 #define ES2PANDA_AOT_EMITFILES_H 18 19 #include <aot/options.h> 20 #include <util/workerQueue.h> 21 22 #include <mutex> 23 24 namespace panda::es2panda::aot { 25 class EmitSingleAbcJob : public util::WorkerJob { 26 public: EmitSingleAbcJob(const std::string & outputFileName,panda::pandasm::Program * prog,std::map<std::string,size_t> * statp,uint8_t targetApi)27 explicit EmitSingleAbcJob(const std::string &outputFileName, panda::pandasm::Program *prog, 28 std::map<std::string, size_t> *statp, uint8_t targetApi) 29 : outputFileName_(outputFileName), prog_(prog), statp_(statp), targetApiVersion_(targetApi) {}; 30 NO_COPY_SEMANTIC(EmitSingleAbcJob); 31 NO_MOVE_SEMANTIC(EmitSingleAbcJob); 32 ~EmitSingleAbcJob() override = default; 33 34 void Run() override; 35 private: 36 std::string outputFileName_; 37 panda::pandasm::Program *prog_; 38 std::map<std::string, size_t> *statp_; 39 uint8_t targetApiVersion_ = 0; 40 }; 41 42 class EmitMergedAbcJob : public util::WorkerJob { 43 public: EmitMergedAbcJob(const std::string & outputFileName,const std::map<std::string,panda::es2panda::util::ProgramCache * > & progsInfo,uint8_t targetApi)44 explicit EmitMergedAbcJob(const std::string &outputFileName, 45 const std::map<std::string, panda::es2panda::util::ProgramCache*> &progsInfo, 46 uint8_t targetApi) 47 : outputFileName_(outputFileName), progsInfo_(progsInfo), targetApiVersion_(targetApi) {}; 48 NO_COPY_SEMANTIC(EmitMergedAbcJob); 49 NO_MOVE_SEMANTIC(EmitMergedAbcJob); 50 ~EmitMergedAbcJob() override = default; 51 52 void Run() override; 53 private: 54 std::string outputFileName_; 55 const std::map<std::string, panda::es2panda::util::ProgramCache*> &progsInfo_; 56 uint8_t targetApiVersion_ = 0; 57 }; 58 59 class EmitCacheJob : public util::WorkerJob { 60 public: EmitCacheJob(const std::string & outputProtoName,panda::es2panda::util::ProgramCache * progCache)61 explicit EmitCacheJob(const std::string &outputProtoName, panda::es2panda::util::ProgramCache *progCache) 62 : outputProtoName_(outputProtoName), progCache_(progCache) {}; 63 NO_COPY_SEMANTIC(EmitCacheJob); 64 NO_MOVE_SEMANTIC(EmitCacheJob); 65 ~EmitCacheJob() override = default; 66 67 void Run() override; 68 private: 69 std::string outputProtoName_; 70 panda::es2panda::util::ProgramCache *progCache_; 71 }; 72 73 class EmitFileQueue : public util::WorkerQueue { 74 public: EmitFileQueue(const std::unique_ptr<panda::es2panda::aot::Options> & options,std::map<std::string,size_t> * statp,const std::map<std::string,panda::es2panda::util::ProgramCache * > & progsInfo)75 explicit EmitFileQueue(const std::unique_ptr<panda::es2panda::aot::Options> &options, 76 std::map<std::string, size_t> *statp, 77 const std::map<std::string, panda::es2panda::util::ProgramCache*> &progsInfo) 78 : WorkerQueue(options->CompilerOptions().fileThreadCount), options_(options), statp_(statp), 79 progsInfo_(progsInfo) { 80 mergeAbc_ = options_->CompilerOptions().mergeAbc; 81 } 82 83 NO_COPY_SEMANTIC(EmitFileQueue); 84 NO_MOVE_SEMANTIC(EmitFileQueue); 85 ~EmitFileQueue() override = default; 86 87 void Schedule() override; 88 89 private: 90 const std::unique_ptr<panda::es2panda::aot::Options> &options_; 91 std::map<std::string, size_t> *statp_; 92 const std::map<std::string, panda::es2panda::util::ProgramCache*> &progsInfo_; 93 bool mergeAbc_ { false }; 94 }; 95 } // namespace panda::es2panda::aot 96 97 #endif 98