• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)27     explicit EmitSingleAbcJob(const std::string &outputFileName, panda::pandasm::Program *prog,
28                               std::map<std::string, size_t> *statp)
29         : outputFileName_(outputFileName), prog_(prog), statp_(statp) {};
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 };
40 
41 class EmitMergedAbcJob : public util::WorkerJob {
42 public:
EmitMergedAbcJob(const std::string & outputFileName,const std::map<std::string,panda::es2panda::util::ProgramCache * > & progsInfo)43     explicit EmitMergedAbcJob(const std::string &outputFileName,
44                               const std::map<std::string, panda::es2panda::util::ProgramCache*> &progsInfo)
45         : outputFileName_(outputFileName), progsInfo_(progsInfo) {};
46     NO_COPY_SEMANTIC(EmitMergedAbcJob);
47     NO_MOVE_SEMANTIC(EmitMergedAbcJob);
48     ~EmitMergedAbcJob() override = default;
49 
50     void Run() override;
51 private:
52     std::string outputFileName_;
53     const std::map<std::string, panda::es2panda::util::ProgramCache*> &progsInfo_;
54 };
55 
56 class EmitCacheJob : public util::WorkerJob {
57 public:
EmitCacheJob(const std::string & outputProtoName,panda::es2panda::util::ProgramCache * progCache)58     explicit EmitCacheJob(const std::string &outputProtoName, panda::es2panda::util::ProgramCache *progCache)
59         : outputProtoName_(outputProtoName), progCache_(progCache) {};
60     NO_COPY_SEMANTIC(EmitCacheJob);
61     NO_MOVE_SEMANTIC(EmitCacheJob);
62     ~EmitCacheJob() override = default;
63 
64     void Run() override;
65 private:
66     std::string outputProtoName_;
67     panda::es2panda::util::ProgramCache *progCache_;
68 };
69 
70 class EmitFileQueue : public util::WorkerQueue {
71 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)72     explicit EmitFileQueue(const std::unique_ptr<panda::es2panda::aot::Options> &options,
73                            std::map<std::string, size_t> *statp,
74                            const std::map<std::string, panda::es2panda::util::ProgramCache*> &progsInfo)
75         : WorkerQueue(options->CompilerOptions().fileThreadCount), options_(options), statp_(statp),
76         progsInfo_(progsInfo) {
77             mergeAbc_ = options_->CompilerOptions().mergeAbc;
78         }
79 
80     NO_COPY_SEMANTIC(EmitFileQueue);
81     NO_MOVE_SEMANTIC(EmitFileQueue);
82     ~EmitFileQueue() override = default;
83 
84     void Schedule() override;
85 
86 private:
87     const std::unique_ptr<panda::es2panda::aot::Options> &options_;
88     std::map<std::string, size_t> *statp_;
89     const std::map<std::string, panda::es2panda::util::ProgramCache*> &progsInfo_;
90     bool mergeAbc_ { false };
91 };
92 }  // namespace panda::es2panda::aot
93 
94 #endif
95