Home | History | Annotate | Download | only in Target
      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_MACHINE_H
     10 #define MCLD_TARGET_MACHINE_H
     11 #ifdef ENABLE_UNITTEST
     12 #include <gtest.h>
     13 #endif
     14 #include <llvm/Target/TargetMachine.h>
     15 #include <string>
     16 #include "mcld/MC/MCLDFile.h"
     17 
     18 namespace llvm
     19 {
     20 class Target;
     21 class TargetData;
     22 class TargetMachine;
     23 class PassManagerBase;
     24 class formatted_raw_ostream;
     25 
     26 } // namespace of llvm
     27 
     28 namespace mcld
     29 {
     30 
     31 class Target;
     32 class MCLDInfo;
     33 class SectLinkerOption;
     34 using namespace llvm;
     35 
     36 enum CodeGenFileType {
     37   CGFT_ASMFile,
     38   CGFT_OBJFile,
     39   CGFT_DSOFile,
     40   CGFT_EXEFile,
     41   CGFT_NULLFile
     42 };
     43 
     44 
     45 /** \class mcld::LLVMTargetMachine
     46  *  \brief mcld::LLVMTargetMachine is a object adapter of
     47  *  llvm::LLVMTargetMachine.
     48  *
     49  *  mcld::LLVMTargetMachine is also in charge of MCLDInfo.
     50  *
     51  *  @see MCLDInfo
     52  */
     53 class LLVMTargetMachine
     54 {
     55 public:
     56   /// Adapter of llvm::TargetMachine
     57   ///
     58   LLVMTargetMachine(llvm::TargetMachine &pTM,
     59                     const mcld::Target &pTarget,
     60                     const std::string &pTriple);
     61   virtual ~LLVMTargetMachine();
     62 
     63   /// getTarget - adapt llvm::TargetMachine::getTarget
     64   const mcld::Target& getTarget() const;
     65 
     66   /// getTM - return adapted the llvm::TargetMachine.
     67   const llvm::TargetMachine& getTM() const { return m_TM; }
     68   llvm::TargetMachine& getTM() { return m_TM; }
     69 
     70   /// getLDInfo - return the mcld::MCLDInfo
     71   virtual mcld::MCLDInfo& getLDInfo() = 0;
     72   virtual const mcld::MCLDInfo& getLDInfo() const = 0;
     73 
     74   /// appPassesToEmitFile - The target function which we has to modify as
     75   /// upstreaming.
     76   bool addPassesToEmitFile(PassManagerBase &,
     77                            formatted_raw_ostream &Out,
     78                            const std::string &pOutputFilename,
     79                            mcld::CodeGenFileType,
     80                            CodeGenOpt::Level,
     81                            SectLinkerOption *pLinkerOpt = NULL,
     82                            bool DisableVerify = true);
     83 
     84   /// getTargetData
     85   const TargetData *getTargetData() const { return m_TM.getTargetData(); }
     86 
     87   /// setAsmVerbosityDefault
     88   static void setAsmVerbosityDefault(bool pAsmVerbose) {
     89     llvm::TargetMachine::setAsmVerbosityDefault(pAsmVerbose);
     90   }
     91 
     92 private:
     93   /// addCommonCodeGenPasses - Add standard LLVM codegen passes used for
     94   /// both emitting to assembly files or machine code output.
     95   bool addCommonCodeGenPasses(PassManagerBase &,
     96                               mcld::CodeGenFileType,
     97                               CodeGenOpt::Level,
     98                               bool DisableVerify,
     99                               llvm::MCContext *&OutCtx);
    100 
    101   bool addCompilerPasses(PassManagerBase &,
    102                          formatted_raw_ostream &Out,
    103                          const std::string& pOutputFilename,
    104                          llvm::MCContext *&OutCtx);
    105 
    106   bool addAssemblerPasses(PassManagerBase &,
    107                           formatted_raw_ostream &Out,
    108                           const std::string& pOutputFilename,
    109                           llvm::MCContext *&OutCtx);
    110 
    111   bool addLinkerPasses(PassManagerBase &,
    112                        SectLinkerOption *pLinkerOpt,
    113                        const std::string& pOutputFilename,
    114                        MCLDFile::Type pOutputLinkType,
    115                        llvm::MCContext *&OutCtx);
    116 
    117 private:
    118   llvm::TargetMachine &m_TM;
    119   const mcld::Target *m_pTarget;
    120   const std::string& m_Triple;
    121 };
    122 
    123 } // namespace of mcld
    124 
    125 #endif
    126 
    127