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