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/codegen/llvm/llvm_ir_builder.h" 22 #include "ecmascript/compiler/compiler_log.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, bool concurrentCompile)27 StubCompiler(std::string &triple, std::string &filePath, size_t optLevel, size_t relocMode, 28 CompilerLog *log, MethodLogList *logList, bool concurrentCompile) 29 : triple_(triple), 30 filePath_(filePath), 31 optLevel_(optLevel), 32 relocMode_(relocMode), 33 log_(log), 34 logList_(logList), 35 concurrentCompile_(concurrentCompile) 36 { 37 } 38 39 ~StubCompiler() = default; 40 41 bool BuildStubModuleAndSave() const; 42 GetLog() const43 CompilerLog *GetLog() const 44 { 45 return log_; 46 } 47 GetLogList() const48 MethodLogList *GetLogList() const 49 { 50 return logList_; 51 } 52 private: 53 void RunPipeline(LLVMModule *module, NativeAreaAllocator *allocator) const; 54 void InitializeCS() const; 55 std::string triple_ {}; 56 std::string filePath_ {}; 57 size_t optLevel_ {3}; // 3 : default backend optimization level 58 size_t relocMode_ {2}; // 2 : default relocation mode-- PIC 59 CompilerLog *log_ {nullptr}; 60 MethodLogList *logList_ {nullptr}; 61 bool concurrentCompile_ {false}; 62 }; 63 } // namespace panda::ecmascript::kungfu 64 #endif // ECMASCRIPT_COMPILER_STUB_COMPILER_H 65