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 ECMASCRIPT_COMPILER_LITECG_CODEGEN_H 17 #define ECMASCRIPT_COMPILER_LITECG_CODEGEN_H 18 19 #include "ecmascript/compiler/binary_section.h" 20 #include "ecmascript/compiler/code_generator.h" 21 #include "ecmascript/compiler/litecg_ir_builder.h" 22 23 namespace panda::ecmascript::kungfu { 24 class CompilerLog; 25 26 class LiteCGAssembler : public Assembler { 27 public: 28 explicit LiteCGAssembler(LMIRModule &module); 29 virtual ~LiteCGAssembler() = default; 30 void Run(const CompilerLog &log, bool fastCompileMode) override; 31 void CollectAnStackMap(CGStackMapInfo &stackMapInfo); 32 33 private: 34 LMIRModule &lmirModule; 35 }; 36 37 class LiteCGIRGeneratorImpl : public CodeGeneratorImpl { 38 public: LiteCGIRGeneratorImpl(LMIRModule * module,bool enableLog)39 LiteCGIRGeneratorImpl(LMIRModule *module, bool enableLog) : module_(module), enableLog_(enableLog) {} 40 ~LiteCGIRGeneratorImpl() override = default; 41 void GenerateCodeForStub(Circuit *circuit, const ControlFlowGraph &graph, size_t index, 42 const CompilationConfig *cfg) override; 43 void GenerateCode(Circuit *circuit, const ControlFlowGraph &graph, const CompilationConfig *cfg, 44 const MethodLiteral *methodLiteral, const JSPandaFile *jsPandaFile, const std::string &methodName, 45 bool enableOptInlining, bool enableBranchProfiling) override; 46 IsLogEnabled()47 bool IsLogEnabled() const 48 { 49 return enableLog_; 50 } 51 GetModule()52 LMIRModule *GetModule() const 53 { 54 return module_; 55 } 56 57 private: 58 LMIRModule *module_; 59 bool enableLog_ {false}; 60 }; 61 } // namespace panda::ecmascript::kungfu 62 #endif // ECMASCRIPT_COMPILER_LITECG_CODEGEN_H 63