13af6ab5fSopenharmony_ci/*
23af6ab5fSopenharmony_ci * Copyright (c) 2023 - 2024 Huawei Device Co., Ltd.
33af6ab5fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
43af6ab5fSopenharmony_ci * you may not use this file except in compliance with the License.
53af6ab5fSopenharmony_ci * You may obtain a copy of the License at
63af6ab5fSopenharmony_ci *
73af6ab5fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
83af6ab5fSopenharmony_ci *
93af6ab5fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
103af6ab5fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
113af6ab5fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
123af6ab5fSopenharmony_ci * See the License for the specific language governing permissions and
133af6ab5fSopenharmony_ci * limitations under the License.
143af6ab5fSopenharmony_ci */
153af6ab5fSopenharmony_ci
163af6ab5fSopenharmony_ci#ifndef ES2PANDA_AOT_EMITFILES_H
173af6ab5fSopenharmony_ci#define ES2PANDA_AOT_EMITFILES_H
183af6ab5fSopenharmony_ci
193af6ab5fSopenharmony_ci#include <aot/options.h>
203af6ab5fSopenharmony_ci#include <util/helpers.h>
213af6ab5fSopenharmony_ci#include <util/workerQueue.h>
223af6ab5fSopenharmony_ci
233af6ab5fSopenharmony_ci#include <mutex>
243af6ab5fSopenharmony_ci
253af6ab5fSopenharmony_cinamespace panda::es2panda::aot {
263af6ab5fSopenharmony_ciclass EmitSingleAbcJob : public util::WorkerJob {
273af6ab5fSopenharmony_cipublic:
283af6ab5fSopenharmony_ci    explicit EmitSingleAbcJob(const std::string &outputFileName, panda::pandasm::Program *prog,
293af6ab5fSopenharmony_ci                              std::map<std::string, size_t> *statp, uint8_t targetApi, std::string targetSubApi)
303af6ab5fSopenharmony_ci        : outputFileName_(outputFileName), prog_(prog), statp_(statp),
313af6ab5fSopenharmony_ci          targetApiVersion_(targetApi), targetApiSubVersion_(targetSubApi) {};
323af6ab5fSopenharmony_ci    NO_COPY_SEMANTIC(EmitSingleAbcJob);
333af6ab5fSopenharmony_ci    NO_MOVE_SEMANTIC(EmitSingleAbcJob);
343af6ab5fSopenharmony_ci    ~EmitSingleAbcJob() override = default;
353af6ab5fSopenharmony_ci
363af6ab5fSopenharmony_ci    void Run() override;
373af6ab5fSopenharmony_ciprivate:
383af6ab5fSopenharmony_ci    std::string outputFileName_;
393af6ab5fSopenharmony_ci    panda::pandasm::Program *prog_;
403af6ab5fSopenharmony_ci    std::map<std::string, size_t> *statp_;
413af6ab5fSopenharmony_ci    uint8_t targetApiVersion_ = 0;
423af6ab5fSopenharmony_ci    std::string targetApiSubVersion_ { util::Helpers::DEFAULT_SUB_API_VERSION };
433af6ab5fSopenharmony_ci};
443af6ab5fSopenharmony_ci
453af6ab5fSopenharmony_ciclass EmitMergedAbcJob : public util::WorkerJob {
463af6ab5fSopenharmony_cipublic:
473af6ab5fSopenharmony_ci    explicit EmitMergedAbcJob(const std::string &outputFileName, const std::string &transformLib,
483af6ab5fSopenharmony_ci                              const std::map<std::string, panda::es2panda::util::ProgramCache*> &progsInfo,
493af6ab5fSopenharmony_ci                              uint8_t targetApi, std::string targetSubApi)
503af6ab5fSopenharmony_ci        : outputFileName_(outputFileName), transformLib_(transformLib),
513af6ab5fSopenharmony_ci        progsInfo_(progsInfo), targetApiVersion_(targetApi), targetApiSubVersion_(targetSubApi) {};
523af6ab5fSopenharmony_ci    NO_COPY_SEMANTIC(EmitMergedAbcJob);
533af6ab5fSopenharmony_ci    NO_MOVE_SEMANTIC(EmitMergedAbcJob);
543af6ab5fSopenharmony_ci    ~EmitMergedAbcJob() override = default;
553af6ab5fSopenharmony_ci
563af6ab5fSopenharmony_ci    void Run() override;
573af6ab5fSopenharmony_ciprivate:
583af6ab5fSopenharmony_ci    std::string outputFileName_;
593af6ab5fSopenharmony_ci    std::string transformLib_;
603af6ab5fSopenharmony_ci    const std::map<std::string, panda::es2panda::util::ProgramCache*> &progsInfo_;
613af6ab5fSopenharmony_ci    uint8_t targetApiVersion_ = 0;
623af6ab5fSopenharmony_ci    std::string targetApiSubVersion_ { util::Helpers::DEFAULT_SUB_API_VERSION };
633af6ab5fSopenharmony_ci};
643af6ab5fSopenharmony_ci
653af6ab5fSopenharmony_ciclass EmitCacheJob : public util::WorkerJob {
663af6ab5fSopenharmony_cipublic:
673af6ab5fSopenharmony_ci    explicit EmitCacheJob(const std::string &outputProtoName, panda::es2panda::util::ProgramCache *progCache)
683af6ab5fSopenharmony_ci        : outputProtoName_(outputProtoName), progCache_(progCache) {};
693af6ab5fSopenharmony_ci    NO_COPY_SEMANTIC(EmitCacheJob);
703af6ab5fSopenharmony_ci    NO_MOVE_SEMANTIC(EmitCacheJob);
713af6ab5fSopenharmony_ci    ~EmitCacheJob() override = default;
723af6ab5fSopenharmony_ci
733af6ab5fSopenharmony_ci    void Run() override;
743af6ab5fSopenharmony_ciprivate:
753af6ab5fSopenharmony_ci    std::string outputProtoName_;
763af6ab5fSopenharmony_ci    panda::es2panda::util::ProgramCache *progCache_;
773af6ab5fSopenharmony_ci};
783af6ab5fSopenharmony_ci
793af6ab5fSopenharmony_ciclass EmitFileQueue : public util::WorkerQueue {
803af6ab5fSopenharmony_cipublic:
813af6ab5fSopenharmony_ci    explicit EmitFileQueue(const std::unique_ptr<panda::es2panda::aot::Options> &options,
823af6ab5fSopenharmony_ci                           std::map<std::string, size_t> *statp,
833af6ab5fSopenharmony_ci                           const std::map<std::string, panda::es2panda::util::ProgramCache*> &progsInfo)
843af6ab5fSopenharmony_ci        : WorkerQueue(options->CompilerOptions().fileThreadCount), options_(options), statp_(statp),
853af6ab5fSopenharmony_ci        progsInfo_(progsInfo) {
863af6ab5fSopenharmony_ci            mergeAbc_ = options_->CompilerOptions().mergeAbc;
873af6ab5fSopenharmony_ci        }
883af6ab5fSopenharmony_ci
893af6ab5fSopenharmony_ci    NO_COPY_SEMANTIC(EmitFileQueue);
903af6ab5fSopenharmony_ci    NO_MOVE_SEMANTIC(EmitFileQueue);
913af6ab5fSopenharmony_ci    ~EmitFileQueue() override = default;
923af6ab5fSopenharmony_ci
933af6ab5fSopenharmony_ci    void Schedule() override;
943af6ab5fSopenharmony_ci
953af6ab5fSopenharmony_ciprivate:
963af6ab5fSopenharmony_ci    void ScheduleEmitCacheJobs(EmitMergedAbcJob *emitMergedAbcJob);
973af6ab5fSopenharmony_ci    const std::unique_ptr<panda::es2panda::aot::Options> &options_;
983af6ab5fSopenharmony_ci    std::map<std::string, size_t> *statp_;
993af6ab5fSopenharmony_ci    const std::map<std::string, panda::es2panda::util::ProgramCache*> &progsInfo_;
1003af6ab5fSopenharmony_ci    bool mergeAbc_ { false };
1013af6ab5fSopenharmony_ci};
1023af6ab5fSopenharmony_ci}  // namespace panda::es2panda::aot
1033af6ab5fSopenharmony_ci
1043af6ab5fSopenharmony_ci#endif
105