Home | History | Annotate | Download | only in Support
      1 //===- Target.cpp ---------------------------------------------------------===//
      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 #include "mcld/Support/Target.h"
     10 
     11 #include <llvm/ADT/Triple.h>
     12 
     13 namespace mcld {
     14 
     15 //===----------------------------------------------------------------------===//
     16 // Target
     17 //===----------------------------------------------------------------------===//
     18 Target::Target()
     19     : Name(NULL),
     20       TripleMatchQualityFn(NULL),
     21       TargetMachineCtorFn(NULL),
     22       MCLinkerCtorFn(NULL),
     23       TargetLDBackendCtorFn(NULL),
     24       DiagnosticLineInfoCtorFn(NULL) {
     25 }
     26 
     27 unsigned int Target::getTripleQuality(const llvm::Triple& pTriple) const {
     28   if (TripleMatchQualityFn == NULL)
     29     return 0;
     30   return TripleMatchQualityFn(pTriple);
     31 }
     32 
     33 MCLDTargetMachine* Target::createTargetMachine(const std::string& pTriple,
     34                                                const llvm::Target& pTarget,
     35                                                llvm::TargetMachine& pTM) const {
     36   if (TargetMachineCtorFn == NULL)
     37     return NULL;
     38   return TargetMachineCtorFn(pTarget, *this, pTM, pTriple);
     39 }
     40 
     41 /// createMCLinker - create target-specific MCLinker
     42 MCLinker* Target::createMCLinker(const std::string& pTriple,
     43                                  LinkerConfig& pConfig,
     44                                  Module& pModule,
     45                                  FileHandle& pFileHandle) const {
     46   if (MCLinkerCtorFn == NULL)
     47     return NULL;
     48   return MCLinkerCtorFn(pTriple, pConfig, pModule, pFileHandle);
     49 }
     50 
     51 /// emulate - given MCLinker default values for the other aspects of the
     52 /// target system.
     53 bool Target::emulate(LinkerScript& pScript, LinkerConfig& pConfig) const {
     54   if (EmulationFn == NULL)
     55     return false;
     56   return EmulationFn(pScript, pConfig);
     57 }
     58 
     59 /// createLDBackend - create target-specific LDBackend
     60 TargetLDBackend* Target::createLDBackend(const LinkerConfig& pConfig) const {
     61   if (TargetLDBackendCtorFn == NULL)
     62     return NULL;
     63   return TargetLDBackendCtorFn(pConfig);
     64 }
     65 
     66 /// createDiagnosticLineInfo - create target-specific DiagnosticLineInfo
     67 DiagnosticLineInfo* Target::createDiagnosticLineInfo(
     68     const mcld::Target& pTarget,
     69     const std::string& pTriple) const {
     70   if (DiagnosticLineInfoCtorFn == NULL)
     71     return NULL;
     72   return DiagnosticLineInfoCtorFn(pTarget, pTriple);
     73 }
     74 
     75 }  // namespace mcld
     76