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