• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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::string & outputFileName,const std::string & transformLib,const std::map<std::string,panda::es2panda::util::ProgramCache * > & progsInfo,uint8_t targetApi,std::string targetSubApi)48     explicit EmitMergedAbcJob(const std::string &outputFileName, const std::string &transformLib,
49                               const std::map<std::string, panda::es2panda::util::ProgramCache*> &progsInfo,
50                               uint8_t targetApi, std::string targetSubApi)
51         : outputFileName_(outputFileName), transformLib_(transformLib),
52         progsInfo_(progsInfo), targetApiVersion_(targetApi), targetApiSubVersion_(targetSubApi) {};
53     NO_COPY_SEMANTIC(EmitMergedAbcJob);
54     NO_MOVE_SEMANTIC(EmitMergedAbcJob);
55     ~EmitMergedAbcJob() override = default;
56 
57     void Run() override;
58 private:
59     std::string outputFileName_;
60     std::string transformLib_;
61     const std::map<std::string, panda::es2panda::util::ProgramCache*> &progsInfo_;
62     uint8_t targetApiVersion_ = 0;
63     std::string targetApiSubVersion_ { util::Helpers::DEFAULT_SUB_API_VERSION };
64 };
65 
66 class EmitCacheJob : public util::WorkerJob {
67 public:
EmitCacheJob(const std::string & outputProtoName,panda::es2panda::util::ProgramCache * progCache)68     explicit EmitCacheJob(const std::string &outputProtoName, panda::es2panda::util::ProgramCache *progCache)
69         : outputProtoName_(outputProtoName), progCache_(progCache) {};
70     NO_COPY_SEMANTIC(EmitCacheJob);
71     NO_MOVE_SEMANTIC(EmitCacheJob);
72     ~EmitCacheJob() override = default;
73 
74     void Run() override;
75 private:
76     std::string outputProtoName_;
77     panda::es2panda::util::ProgramCache *progCache_;
78 };
79 
80 class EmitFileQueue : public util::WorkerQueue {
81 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)82     explicit EmitFileQueue(const std::unique_ptr<panda::es2panda::aot::Options> &options,
83                            std::map<std::string, size_t> *statp,
84                            const std::map<std::string, panda::es2panda::util::ProgramCache*> &progsInfo)
85         : WorkerQueue(options->CompilerOptions().fileThreadCount), options_(options), statp_(statp),
86         progsInfo_(progsInfo) {
87             mergeAbc_ = options_->CompilerOptions().mergeAbc;
88         }
89 
90     NO_COPY_SEMANTIC(EmitFileQueue);
91     NO_MOVE_SEMANTIC(EmitFileQueue);
92     ~EmitFileQueue() override = default;
93 
94     void Schedule() override;
95 
96 private:
97     void ScheduleEmitCacheJobs(EmitMergedAbcJob *emitMergedAbcJob);
98     const std::unique_ptr<panda::es2panda::aot::Options> &options_;
99     std::map<std::string, size_t> *statp_;
100     const std::map<std::string, panda::es2panda::util::ProgramCache*> &progsInfo_;
101     bool mergeAbc_ { false };
102 };
103 }  // namespace panda::es2panda::aot
104 
105 #endif
106