1f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines//===- Target.h -----------------------------------------------------------===//
2f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines//
3f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines//                     The MCLinker Project
4f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines//
5f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines// This file is distributed under the University of Illinois Open Source
6f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines// License. See LICENSE.TXT for details.
7f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines//
8f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines//===----------------------------------------------------------------------===//
9f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines#ifndef MCLD_SUPPORT_TARGET_H
10f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines#define MCLD_SUPPORT_TARGET_H
11f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines#include <string>
12f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines#include <list>
13f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines
14f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hinesnamespace llvm {
15f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hinesclass Target;
16f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hinesclass Triple;
17f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hinesclass TargetMachine;
18f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines} // namespace of llvm
19f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines
20f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hinesnamespace mcld {
21f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines
22f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hinesclass MCLDTargetMachine;
23f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hinesclass TargetRegistry;
24f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hinesclass MCLinker;
25f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hinesclass LinkerScript;
26f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hinesclass LinkerConfig;
27f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hinesclass Module;
28f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hinesclass FileHandle;
29f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hinesclass DiagnosticLineInfo;
30f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hinesclass TargetLDBackend;
31f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines
32f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines/** \class Target
33f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines *  \brief Target collects target specific information
34f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines */
35f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hinesclass Target
36f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines{
37f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines  friend class mcld::MCLDTargetMachine;
38f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines  friend class mcld::TargetRegistry;
39f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines
40f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hinespublic:
41f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines  typedef unsigned int (*TripleMatchQualityFnTy)(const llvm::Triple& pTriple);
42f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines
43f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines  typedef MCLDTargetMachine *(*TargetMachineCtorTy)(const llvm::Target &,
44f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines                                                    const mcld::Target &,
45f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines                                                    llvm::TargetMachine &,
46f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines                                                    const std::string&);
47f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines
48f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines  typedef MCLinker *(*MCLinkerCtorTy)(const std::string& pTriple,
49f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines                                      LinkerConfig&,
50f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines                                      Module&,
51f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines                                      FileHandle& pFileHandle);
52f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines
53f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines  typedef bool (*EmulationFnTy)(LinkerScript&, LinkerConfig&);
54f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines
55f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines  typedef TargetLDBackend  *(*TargetLDBackendCtorTy)(const LinkerConfig&);
56f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines
57f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines  typedef DiagnosticLineInfo *(*DiagnosticLineInfoCtorTy)(const mcld::Target&,
58f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines                                                          const std::string&);
59f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines
60f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hinespublic:
61f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines  Target();
62f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines
63f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines  /// getName - get the target name
64f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines  const char* name() const { return Name; }
65f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines
66f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines  unsigned int getTripleQuality(const llvm::Triple& pTriple) const;
67f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines
68f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines  /// createTargetMachine - create target-specific TargetMachine
69f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines  MCLDTargetMachine* createTargetMachine(const std::string& pTriple,
70f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines                                         const llvm::Target& pTarget,
71f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines                                         llvm::TargetMachine& pTM) const;
72f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines
73f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines  /// createMCLinker - create target-specific MCLinker
74f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines  MCLinker *createMCLinker(const std::string &pTriple,
75f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines                           LinkerConfig& pConfig,
76f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines                           Module& pModule,
77f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines                           FileHandle& pFileHandle) const;
78f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines
79f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines  /// emulate - given MCLinker default values for the other aspects of the
80f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines  /// target system.
81f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines  bool emulate(LinkerScript& pScript, LinkerConfig& pConfig) const;
82f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines
83f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines  /// createLDBackend - create target-specific LDBackend
84f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines  TargetLDBackend* createLDBackend(const LinkerConfig& pConfig) const;
85f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines
86f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines  /// createDiagnosticLineInfo - create target-specific DiagnosticLineInfo
87f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines  DiagnosticLineInfo* createDiagnosticLineInfo(const mcld::Target& pTarget,
88f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines                                               const std::string& pTriple) const;
89f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines
90f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hinesprivate:
91f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines  /// Name - The target name
92f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines  const char* Name;
93f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines
94f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines  TripleMatchQualityFnTy TripleMatchQualityFn;
95f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines  TargetMachineCtorTy TargetMachineCtorFn;
96f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines  MCLinkerCtorTy MCLinkerCtorFn;
97f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines  EmulationFnTy EmulationFn;
98f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines  TargetLDBackendCtorTy TargetLDBackendCtorFn;
99f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines  DiagnosticLineInfoCtorTy DiagnosticLineInfoCtorFn;
100f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines};
101f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines
102f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines} //end namespace mcld
103f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines
104f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines#endif
105f33f6de54db174aa679a4b6d1e040d37e95541c0Stephen Hines
106