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_IR_MODULE_H 17#define ECMASCRIPT_COMPILER_IR_MODULE_H 18 19#include "ecmascript/compiler/circuit_builder_helper.h" 20#include "ecmascript/compiler/debug_info.h" 21#include "ecmascript/jspandafile/js_pandafile.h" 22 23namespace panda::ecmascript::kungfu { 24enum ModuleKind : uint8_t { 25 MODULE_LITECG, 26 MODULE_LLVM, 27}; 28 29class IRModule { 30public: 31 IRModule(NativeAreaAllocator *allocator, bool logDbg, const std::string &triple) 32 { 33 tripleStr_ = triple; 34 CompilationConfig cfg(tripleStr_); 35 is64Bit_ = cfg.Is64Bit(); 36 triple_ = cfg.GetTriple(); 37 debugInfo_ = new DebugInfo(allocator, logDbg); 38 } 39 40 virtual ~IRModule() 41 { 42 if (debugInfo_ == nullptr) { 43 return; 44 } 45 delete debugInfo_; 46 debugInfo_ = nullptr; 47 } 48 49 DebugInfo *GetDebugInfo() const 50 { 51 return debugInfo_; 52 } 53 54 Triple GetTriple() const 55 { 56 return triple_; 57 } 58 59 const std::string &GetTripleStr() const 60 { 61 return tripleStr_; 62 } 63 64 bool Is64Bit() const 65 { 66 return is64Bit_; 67 } 68 69 bool Is32Bit() const 70 { 71 return !is64Bit_; 72 } 73 74 virtual ModuleKind GetModuleKind() const = 0; 75 76 static std::string GetFuncName(const MethodLiteral *methodLiteral, const JSPandaFile *jsPandaFile); 77 78private: 79 DebugInfo *debugInfo_ {nullptr}; 80 std::string tripleStr_; 81 Triple triple_; 82 bool is64Bit_ {false}; 83}; 84} // namespace panda::ecmascript::kungfu 85#endif // ECMASCRIPT_COMPILER_IR_MODULE_H 86