• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- TargetMachine.h ----------------------------------------------------===//
2 //
3 //                     The MCLinker Project
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 #ifndef MCLD_TARGET_TARGET_MACHINE_H
10 #define MCLD_TARGET_TARGET_MACHINE_H
11 #ifdef ENABLE_UNITTEST
12 #include <gtest.h>
13 #endif
14 #include <llvm/Target/TargetMachine.h>
15 #include <string>
16 
17 namespace llvm {
18 
19 class Target;
20 class TargetData;
21 class TargetMachine;
22 class PassManagerBase;
23 
24 } // namespace of llvm
25 
26 namespace mcld {
27 
28 class Module;
29 class Target;
30 class MemoryArea;
31 class LinkerConfig;
32 class ToolOutputFile;
33 
34 using namespace llvm;
35 
36 enum CodeGenFileType {
37   CGFT_ASMFile,
38   CGFT_OBJFile,
39   CGFT_DSOFile,
40   CGFT_EXEFile,
41   CGFT_PARTIAL,
42   CGFT_BINARY,
43   CGFT_NULLFile
44 };
45 
46 
47 /** \class mcld::MCLDTargetMachine
48  *  \brief mcld::MCLDTargetMachine is a object adapter of LLVMTargetMachine.
49  */
50 class MCLDTargetMachine
51 {
52 public:
53   /// Adapter of llvm::TargetMachine
54   ///
55   MCLDTargetMachine(llvm::TargetMachine &pTM,
56                     const mcld::Target &pTarget,
57                     const std::string &pTriple);
58 
59   virtual ~MCLDTargetMachine();
60 
61   /// getTarget - adapt llvm::TargetMachine::getTarget
62   const mcld::Target& getTarget() const;
63 
64   /// getTM - return adapted the llvm::TargetMachine.
getTM()65   const llvm::TargetMachine& getTM() const { return m_TM; }
getTM()66   llvm::TargetMachine&       getTM()       { return m_TM; }
67 
68   /// appPassesToEmitFile - The target function which we has to modify as
69   /// upstreaming.
70   bool addPassesToEmitFile(PassManagerBase &,
71                            mcld::ToolOutputFile& pOutput,
72                            mcld::CodeGenFileType,
73                            CodeGenOpt::Level,
74                            mcld::Module& pModule,
75                            mcld::LinkerConfig& pConfig,
76                            bool DisableVerify = true);
77 
78   /// getDataLayout
getDataLayout()79   const DataLayout *getDataLayout() const { return m_TM.getDataLayout(); }
80 
81   /// setAsmVerbosityDefault
setAsmVerbosityDefault(bool pAsmVerbose)82   static void setAsmVerbosityDefault(bool pAsmVerbose) {
83     llvm::TargetMachine::setAsmVerbosityDefault(pAsmVerbose);
84   }
85 
86 private:
87   /// addCommonCodeGenPasses - Add standard LLVM codegen passes used for
88   /// both emitting to assembly files or machine code output.
89   bool addCommonCodeGenPasses(PassManagerBase &,
90                               mcld::CodeGenFileType,
91                               CodeGenOpt::Level,
92                               bool DisableVerify,
93                               llvm::MCContext *&OutCtx);
94 
95   bool addCompilerPasses(PassManagerBase &pPM,
96                          llvm::formatted_raw_ostream &pOutput,
97                          llvm::MCContext *&OutCtx);
98 
99   bool addAssemblerPasses(PassManagerBase &pPM,
100                           llvm::raw_ostream &pOutput,
101                           llvm::MCContext *&OutCtx);
102 
103   bool addLinkerPasses(PassManagerBase &pPM,
104                        LinkerConfig& pConfig,
105                        Module& pModule,
106                        mcld::MemoryArea& pOutput,
107                        llvm::MCContext *&OutCtx);
108 
109 private:
110   llvm::TargetMachine &m_TM;
111   const mcld::Target *m_pTarget;
112   const std::string& m_Triple;
113 };
114 
115 } // namespace of mcld
116 
117 #endif
118 
119