1 /** 2 * Copyright (c) 2021-2025 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 "compiler/core/compileQueue.h" 20 21 namespace ark::pandasm { 22 struct Program; 23 } // namespace ark::pandasm 24 25 namespace ark::es2panda::compiler { 26 class CompileQueue; 27 28 void HandleGenerateDecl(const parser::Program &program, util::DiagnosticEngine &diagnosticEngine, 29 const std::string &outputPath, bool isIsolatedDeclgen); 30 31 class CompilationUnit { 32 public: CompilationUnit(const SourceFile & i,const util::Options & o,uint32_t s,ScriptExtension e,util::DiagnosticEngine & de)33 explicit CompilationUnit(const SourceFile &i, const util::Options &o, uint32_t s, ScriptExtension e, 34 util::DiagnosticEngine &de) 35 : input(i), options(o), rawParserStatus(s), ext(e), diagnosticEngine(de) 36 { 37 } 38 39 // NOLINTBEGIN(misc-non-private-member-variables-in-classes) 40 const SourceFile &input; 41 const util::Options &options; 42 uint32_t rawParserStatus; 43 ScriptExtension ext; 44 util::DiagnosticEngine &diagnosticEngine; 45 // NOLINTEND(misc-non-private-member-variables-in-classes) 46 }; 47 48 class CompilerImpl { 49 public: CompilerImpl(size_t threadCount,std::vector<util::Plugin> const * plugins)50 explicit CompilerImpl(size_t threadCount, std::vector<util::Plugin> const *plugins) 51 : queue_(threadCount), plugins_(plugins) 52 { 53 } 54 NO_COPY_SEMANTIC(CompilerImpl); 55 NO_MOVE_SEMANTIC(CompilerImpl); 56 ~CompilerImpl() = default; 57 58 pandasm::Program *Compile(const CompilationUnit &unit, public_lib::Context *context); 59 Plugins()60 std::vector<util::Plugin> const &Plugins() 61 { 62 return *plugins_; 63 } 64 65 static void DumpAsm(const ark::pandasm::Program *prog); 66 static std::string GetPhasesList(ScriptExtension ext); 67 68 ark::pandasm::Program *Emit(public_lib::Context *context); 69 Queue()70 CompileQueue *Queue() 71 { 72 return &queue_; 73 } 74 75 private: 76 static void HandleContextLiterals(public_lib::Context *context); 77 78 CompileQueue queue_; 79 std::vector<util::Plugin> const *plugins_; 80 }; 81 } // namespace ark::es2panda::compiler 82 83 #endif 84