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