• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-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_COMPILER_INCLUDE_COMPILER_IMPL_H
17 #define ES2PANDA_COMPILER_INCLUDE_COMPILER_IMPL_H
18 
19 #include "es2panda.h"
20 #include "compiler/core/compileQueue.h"
21 #include "macros.h"
22 #include "mem/arena_allocator.h"
23 #include "os/thread.h"
24 
25 #include <string>
26 
27 namespace ark::pandasm {
28 struct Program;
29 }  // namespace ark::pandasm
30 
31 namespace ark::es2panda::compiler {
32 class CompileQueue;
33 
34 class CompilationUnit {
35 public:
CompilationUnit(const SourceFile & i,const util::Options & o,uint32_t s,ScriptExtension e)36     explicit CompilationUnit(const SourceFile &i, const util::Options &o, uint32_t s, ScriptExtension e)
37         : input(i), options(o), rawParserStatus(s), ext(e)
38     {
39     }
40 
41     // NOLINTBEGIN(misc-non-private-member-variables-in-classes)
42     const SourceFile &input;
43     const util::Options &options;
44     uint32_t rawParserStatus;
45     ScriptExtension ext;
46     // NOLINTEND(misc-non-private-member-variables-in-classes)
47 };
48 
49 class CompilerImpl {
50 public:
CompilerImpl(size_t threadCount,std::vector<util::Plugin> const * plugins)51     explicit CompilerImpl(size_t threadCount, std::vector<util::Plugin> const *plugins)
52         : queue_(threadCount), plugins_(plugins)
53     {
54     }
55     NO_COPY_SEMANTIC(CompilerImpl);
56     NO_MOVE_SEMANTIC(CompilerImpl);
57     ~CompilerImpl() = default;
58 
59     pandasm::Program *Compile(const CompilationUnit &unit);
60 
Plugins()61     std::vector<util::Plugin> const &Plugins()
62     {
63         return *plugins_;
64     }
65 
66     static void DumpAsm(const ark::pandasm::Program *prog);
67     static std::string GetPhasesList(const ScriptExtension ext);
68 
69     ark::pandasm::Program *Emit(public_lib::Context *context);
70 
Queue()71     CompileQueue *Queue()
72     {
73         return &queue_;
74     }
75 
IsAnyError()76     bool IsAnyError()
77     {
78         return isAnyError_;
79     }
80 
SetIsAnyError(bool value)81     void SetIsAnyError(bool value)
82     {
83         isAnyError_ = value;
84     }
85 
86 private:
87     static void HandleContextLiterals(public_lib::Context *context);
88 
89     CompileQueue queue_;
90     std::vector<util::Plugin> const *plugins_;
91     bool isAnyError_ = false;
92 };
93 }  // namespace ark::es2panda::compiler
94 
95 #endif
96