blob: ac786b137cf5aa055f49cb02cc140dc8870a0cd3 [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
56namespace {
57class DarwinPPCTargetInfo : public DarwinTargetInfo {
58public:
59 // nothing so far.
60};
61} // end anonymous namespace.
62
63namespace {
64class DarwinPPC64TargetInfo : public DarwinTargetInfo {
65public:
66 // nothing so far.
67};
68} // end anonymous namespace.
69
70namespace {
71class DarwinI386TargetInfo : public DarwinTargetInfo {
72public:
73 // nothing so far.
74};
75} // end anonymous namespace.
76
77namespace {
78class DarwinX86_64TargetInfo : public DarwinTargetInfo {
79public:
80 // nothing so far.
81};
82} // end anonymous namespace.
83
84namespace {
85class LinuxTargetInfo : public DarwinTargetInfo {
86public:
87 LinuxTargetInfo() {
88 // Note: I have no idea if this is right, just for testing.
89 WCharWidth = 2;
90 }
91};
92} // end anonymous namespace.
93
94
95//===----------------------------------------------------------------------===//
96// Driver code
97//===----------------------------------------------------------------------===//
98
99/// CreateTarget - Create the TargetInfoImpl object for the specified target
100/// enum value.
101static TargetInfoImpl *CreateTarget(SupportedTargets T) {
102 switch (T) {
103 default: assert(0 && "Unknown target!");
104 case target_ppc: return new DarwinPPCTargetInfo();
105 case target_ppc64: return new DarwinPPC64TargetInfo();
106 case target_i386: return new DarwinI386TargetInfo();
107 case target_x86_64: return new DarwinX86_64TargetInfo();
108 case target_linux_i386: return new LinuxTargetInfo();
109 }
110}
111
112/// CreateTargetInfo - Return the set of target info objects as specified by
113/// the -arch command line option.
114TargetInfo *clang::CreateTargetInfo(Diagnostic &Diags) {
115 // If the user didn't specify at least one architecture, auto-sense the
116 // current host. TODO: This is a hack. :)
117 if (Archs.empty()) {
118#ifndef __APPLE__
119 // Assume non-apple = linux.
120 Archs.push_back(target_linux_i386);
121#elif (defined(__POWERPC__) || defined (__ppc__) || defined(_POWER)) && \
122 defined(__ppc64__)
123 Archs.push_back(target_ppc64);
124#elif defined(__POWERPC__) || defined (__ppc__) || defined(_POWER)
125 Archs.push_back(target_ppc);
126#elif defined(__x86_64__)
127 Archs.push_back(target_x86_64);
128#elif defined(__i386__) || defined(i386) || defined(_M_IX86)
129 Archs.push_back(target_i386);
130#else
131 // Don't know what this is!
132 return 0;
133#endif
134 }
135
136 // Create the primary target and target info.
137 TargetInfo *TI = new TargetInfo(CreateTarget(Archs[0]), &Diags);
138
139 // Add all secondary targets.
140 for (unsigned i = 1, e = Archs.size(); i != e; ++i)
141 TI->AddSecondaryTarget(CreateTarget(Archs[i]));
142 return TI;
143}