blob: 565f4dc26187fe172a1b286afa00f92a3014a54a [file] [log] [blame]
Chris Lattner5ba61f02006-10-14 07:39:34 +00001//===--- Targets.cpp - Implement -arch option and targets -----------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Chris Lattner and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the -arch command line option and creates a TargetInfo
11// that represents them.
12//
13//===----------------------------------------------------------------------===//
14
15#include "clang.h"
16#include "clang/Basic/Diagnostic.h"
17#include "clang/Basic/TargetInfo.h"
18#include "llvm/Support/CommandLine.h"
19using namespace llvm;
20using namespace clang;
21
22/// Note: a hard coded list of targets is clearly silly, these should be
23/// dynamicly registered and loadable with "-load".
24enum SupportedTargets {
25 target_ppc, target_ppc64,
26 target_i386, target_x86_64,
27 target_linux_i386
28};
29
30static cl::list<SupportedTargets>
31Archs("arch", cl::desc("Architectures to compile for"),
32 cl::values(clEnumValN(target_ppc, "ppc", "32-bit Darwin PowerPC"),
33 clEnumValN(target_ppc64, "ppc64", "64-bit Darwin PowerPC"),
34 clEnumValN(target_i386, "i386", "32-bit Darwin X86"),
35 clEnumValN(target_x86_64, "x86_64","64-bit Darwin X86"),
36 clEnumValN(target_linux_i386,"linux", "Linux i386"),
37 clEnumValEnd));
38
39//===----------------------------------------------------------------------===//
40// Common code shared among the Darwin targets.
41//===----------------------------------------------------------------------===//
42
43namespace {
44class DarwinTargetInfo : public TargetInfoImpl {
45public:
46
47 // nothing so far.
48};
49} // end anonymous namespace.
50
51
52//===----------------------------------------------------------------------===//
53// Specific target implementations.
54//===----------------------------------------------------------------------===//
55
Chris Lattner02dffbd2006-10-14 07:50:21 +000056// FIXME: Move target-specific preprocessor definitions here.
57
Chris Lattner5ba61f02006-10-14 07:39:34 +000058namespace {
59class DarwinPPCTargetInfo : public DarwinTargetInfo {
60public:
61 // nothing so far.
62};
63} // end anonymous namespace.
64
65namespace {
66class DarwinPPC64TargetInfo : public DarwinTargetInfo {
67public:
68 // nothing so far.
69};
70} // end anonymous namespace.
71
72namespace {
73class DarwinI386TargetInfo : public DarwinTargetInfo {
74public:
75 // nothing so far.
76};
77} // end anonymous namespace.
78
79namespace {
80class DarwinX86_64TargetInfo : public DarwinTargetInfo {
81public:
82 // nothing so far.
83};
84} // end anonymous namespace.
85
86namespace {
87class LinuxTargetInfo : public DarwinTargetInfo {
88public:
89 LinuxTargetInfo() {
90 // Note: I have no idea if this is right, just for testing.
91 WCharWidth = 2;
92 }
93};
94} // end anonymous namespace.
95
96
97//===----------------------------------------------------------------------===//
98// Driver code
99//===----------------------------------------------------------------------===//
100
101/// CreateTarget - Create the TargetInfoImpl object for the specified target
102/// enum value.
103static TargetInfoImpl *CreateTarget(SupportedTargets T) {
104 switch (T) {
105 default: assert(0 && "Unknown target!");
106 case target_ppc: return new DarwinPPCTargetInfo();
107 case target_ppc64: return new DarwinPPC64TargetInfo();
108 case target_i386: return new DarwinI386TargetInfo();
109 case target_x86_64: return new DarwinX86_64TargetInfo();
110 case target_linux_i386: return new LinuxTargetInfo();
111 }
112}
113
114/// CreateTargetInfo - Return the set of target info objects as specified by
115/// the -arch command line option.
116TargetInfo *clang::CreateTargetInfo(Diagnostic &Diags) {
117 // If the user didn't specify at least one architecture, auto-sense the
118 // current host. TODO: This is a hack. :)
119 if (Archs.empty()) {
120#ifndef __APPLE__
121 // Assume non-apple = linux.
122 Archs.push_back(target_linux_i386);
123#elif (defined(__POWERPC__) || defined (__ppc__) || defined(_POWER)) && \
124 defined(__ppc64__)
125 Archs.push_back(target_ppc64);
126#elif defined(__POWERPC__) || defined (__ppc__) || defined(_POWER)
127 Archs.push_back(target_ppc);
128#elif defined(__x86_64__)
129 Archs.push_back(target_x86_64);
130#elif defined(__i386__) || defined(i386) || defined(_M_IX86)
131 Archs.push_back(target_i386);
132#else
133 // Don't know what this is!
134 return 0;
135#endif
136 }
137
138 // Create the primary target and target info.
139 TargetInfo *TI = new TargetInfo(CreateTarget(Archs[0]), &Diags);
140
141 // Add all secondary targets.
142 for (unsigned i = 1, e = Archs.size(); i != e; ++i)
143 TI->AddSecondaryTarget(CreateTarget(Archs[i]));
144 return TI;
145}