Home | History | Annotate | Download | only in Support
      1 //===- Target.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_SUPPORT_TARGET_H_
     10 #define MCLD_SUPPORT_TARGET_H_
     11 #include <string>
     12 
     13 namespace llvm {
     14 class Target;
     15 class Triple;
     16 class TargetMachine;
     17 }  // namespace llvm
     18 
     19 namespace mcld {
     20 
     21 class MCLDTargetMachine;
     22 class TargetRegistry;
     23 class MCLinker;
     24 class LinkerScript;
     25 class LinkerConfig;
     26 class Module;
     27 class FileHandle;
     28 class DiagnosticLineInfo;
     29 class TargetLDBackend;
     30 
     31 /** \class Target
     32  *  \brief Target collects target specific information
     33  */
     34 class Target {
     35   friend class mcld::MCLDTargetMachine;
     36   friend class mcld::TargetRegistry;
     37 
     38  public:
     39   typedef unsigned int (*TripleMatchQualityFnTy)(const llvm::Triple& pTriple);
     40 
     41   typedef MCLDTargetMachine* (*TargetMachineCtorTy)(const llvm::Target&,
     42                                                     const mcld::Target&,
     43                                                     llvm::TargetMachine&,
     44                                                     const std::string&);
     45 
     46   typedef MCLinker* (*MCLinkerCtorTy)(const std::string& pTriple,
     47                                       LinkerConfig&,
     48                                       Module&,
     49                                       FileHandle& pFileHandle);
     50 
     51   typedef bool (*EmulationFnTy)(LinkerScript&, LinkerConfig&);
     52 
     53   typedef TargetLDBackend* (*TargetLDBackendCtorTy)(const LinkerConfig&);
     54 
     55   typedef DiagnosticLineInfo* (*DiagnosticLineInfoCtorTy)(const mcld::Target&,
     56                                                           const std::string&);
     57 
     58  public:
     59   Target();
     60 
     61   /// getName - get the target name
     62   const char* name() const { return Name; }
     63 
     64   unsigned int getTripleQuality(const llvm::Triple& pTriple) const;
     65 
     66   /// createTargetMachine - create target-specific TargetMachine
     67   MCLDTargetMachine* createTargetMachine(const std::string& pTriple,
     68                                          const llvm::Target& pTarget,
     69                                          llvm::TargetMachine& pTM) const;
     70 
     71   /// createMCLinker - create target-specific MCLinker
     72   MCLinker* createMCLinker(const std::string& pTriple,
     73                            LinkerConfig& pConfig,
     74                            Module& pModule,
     75                            FileHandle& pFileHandle) const;
     76 
     77   /// emulate - given MCLinker default values for the other aspects of the
     78   /// target system.
     79   bool emulate(LinkerScript& pScript, LinkerConfig& pConfig) const;
     80 
     81   /// createLDBackend - create target-specific LDBackend
     82   TargetLDBackend* createLDBackend(const LinkerConfig& pConfig) const;
     83 
     84   /// createDiagnosticLineInfo - create target-specific DiagnosticLineInfo
     85   DiagnosticLineInfo* createDiagnosticLineInfo(
     86       const mcld::Target& pTarget,
     87       const std::string& pTriple) const;
     88 
     89  private:
     90   /// Name - The target name
     91   const char* Name;
     92 
     93   TripleMatchQualityFnTy TripleMatchQualityFn;
     94   TargetMachineCtorTy TargetMachineCtorFn;
     95   MCLinkerCtorTy MCLinkerCtorFn;
     96   EmulationFnTy EmulationFn;
     97   TargetLDBackendCtorTy TargetLDBackendCtorFn;
     98   DiagnosticLineInfoCtorTy DiagnosticLineInfoCtorFn;
     99 };
    100 
    101 }  // namespace mcld
    102 
    103 #endif  // MCLD_SUPPORT_TARGET_H_
    104