• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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,const MethodLogList * logList,bool enablePGOProfiler)27     StubCompiler(std::string &triple, std::string &filePath, size_t optLevel, size_t relocMode,
28         CompilerLog *log, const MethodLogList *logList, bool enablePGOProfiler) : triple_(triple),
29         filePath_(filePath), optLevel_(optLevel), relocMode_(relocMode), log_(log), logList_(logList),
30         enablePGOProfiler_(enablePGOProfiler) {}
31 
32     ~StubCompiler() = default;
33 
34     bool BuildStubModuleAndSave() const;
35 
GetLog()36     CompilerLog *GetLog() const
37     {
38         return log_;
39     }
40 
GetLogList()41     const MethodLogList *GetLogList() const
42     {
43         return logList_;
44     }
45 private:
46     void RunPipeline(LLVMModule *module) const;
47     void InitializeCS() const;
48     std::string triple_ {};
49     std::string filePath_ {};
50     size_t optLevel_ {3}; // 3 : default backend optimization level
51     size_t relocMode_ {2}; // 2 : default relocation mode-- PIC
52     CompilerLog *log_ {nullptr};
53     const MethodLogList *logList_ {nullptr};
54     bool enablePGOProfiler_ {false};
55 };
56 }  // namespace panda::ecmascript::kungfu
57 #endif  // ECMASCRIPT_COMPILER_STUB_COMPILER_H
58