1 /* 2 * Copyright (c) 2021 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_STUB_COMPILER_H 17 #define ECMASCRIPT_COMPILER_STUB_COMPILER_H 18 19 #include <cstring> 20 21 #include "ecmascript/compiler/compiler_log.h" 22 #include "ecmascript/compiler/llvm_ir_builder.h" 23 24 namespace panda::ecmascript::kungfu { 25 class StubCompiler { 26 public: StubCompiler(std::string & triple,std::string & filePath,size_t optLevel,size_t relocMode,CompilerLog * log,MethodLogList * logList)27 StubCompiler(std::string &triple, std::string &filePath, size_t optLevel, size_t relocMode, 28 CompilerLog *log, MethodLogList *logList) 29 : triple_(triple), 30 filePath_(filePath), 31 optLevel_(optLevel), 32 relocMode_(relocMode), 33 log_(log), 34 logList_(logList) 35 { 36 } 37 38 ~StubCompiler() = default; 39 40 bool BuildStubModuleAndSave() const; 41 GetLog()42 CompilerLog *GetLog() const 43 { 44 return log_; 45 } 46 GetLogList()47 MethodLogList *GetLogList() const 48 { 49 return logList_; 50 } 51 private: 52 void RunPipeline(LLVMModule *module, NativeAreaAllocator *allocator) const; 53 void InitializeCS() const; 54 std::string triple_ {}; 55 std::string filePath_ {}; 56 size_t optLevel_ {3}; // 3 : default backend optimization level 57 size_t relocMode_ {2}; // 2 : default relocation mode-- PIC 58 CompilerLog *log_ {nullptr}; 59 MethodLogList *logList_ {nullptr}; 60 }; 61 } // namespace panda::ecmascript::kungfu 62 #endif // ECMASCRIPT_COMPILER_STUB_COMPILER_H 63