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