• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 MAPLE_LITECG_LITECG_H
17 #define MAPLE_LITECG_LITECG_H
18 
19 #include "lmir_builder.h"
20 #include "cg_option.h"
21 
22 namespace maple {
23 namespace litecg {
24 
25 enum OutputType {
26     kAsm,  // AT&T assembly file
27     kElf,  // elf object file
28 };
29 
30 enum TargetType {
31     kX86_64,
32     kAarch64,
33 };
34 
35 enum DebugType {
36     kDebug,
37     kNoDebug,
38 };
39 
40 enum InfoType { kQuiet, kVerbose };
41 
42 class LiteCG {
43 public:
44     LiteCG(Module &mirModule);
45     ~LiteCG() = default;
46 
47     // configurations API.
48     // If not specified, default to: Ofastcompile, Elf, X86_64, NoDebug, Quiet
49 
50     // O0/O1/Ofastcompile
51 
52     // return LiteCG& enables chaining of config functions.
53     LiteCG &SetOutputType(OutputType config);
54     LiteCG &SetTargetType(TargetType config);
55     LiteCG &SetDebugType(DebugType config);
56     LiteCG &SetVerbose(InfoType config);
57     LiteCG &SetupLiteCGEmitMemoryManager(void *codeSpace,
58                                          maplebe::MemoryManagerAllocateDataSectionCallback dataSectionAllocator,
59                                          maplebe::MemoryManagerSaveFunc2AddressInfoCallback funcAddrSaver,
60                                          maplebe::MemoryManagerSaveFunc2FPtoPrevSPDeltaCallback funcFpSPDeltaSaver,
61                                          maplebe::MemoryManagerSaveFunc2CalleeOffsetInfoCallback funcCallOffsetSaver,
62                                          maplebe::MemoryManagerSavePC2DeoptInfoCallback pc2DeoptInfoSaver,
63                                          maplebe::MemoryManagerSavePC2CallSiteInfoCallback pc2CallSiteInfoSaver);
64 
65     void DumpIRToFile(const std::string &fileName);
66     void DumpCGIR();
67     void DoCG();
68 
69 private:
70     Module &module;
71     maplebe::CGOptions *cgOptions;
72 };
73 
74 }  // namespace litecg
75 
76 }  // namespace maple
77 
78 #endif  // MAPLE_LITECG_LITECG_H
79