1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
//===--- Tools.cpp - Tools Implementations ------------------------------*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "Tools.h"
#include "clang/Driver/Arg.h"
#include "clang/Driver/ArgList.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Job.h"
#include "clang/Driver/HostInfo.h"
#include "clang/Driver/Option.h"
#include "clang/Driver/ToolChain.h"
#include "clang/Driver/Util.h"
#include "llvm/ADT/SmallVector.h"
#include "InputInfo.h"
using namespace clang::driver;
using namespace clang::driver::tools;
void Clang::ConstructJob(Compilation &C, const JobAction &JA,
Job &Dest,
const InputInfo &Output,
const InputInfoList &Inputs,
const ArgList &TCArgs,
const char *LinkingOutput) const {
ArgStringList CmdArgs;
for (InputInfoList::const_iterator
it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
const InputInfo &II = *it;
if (II.isPipe())
CmdArgs.push_back("-");
else
CmdArgs.push_back(II.getInputFilename());
}
if (Output.isPipe()) {
CmdArgs.push_back("-o");
CmdArgs.push_back("-");
} else if (const char *N = Output.getInputFilename()) {
CmdArgs.push_back("-o");
CmdArgs.push_back(N);
}
Dest.addCommand(new Command("clang", CmdArgs));
}
void gcc::Common::ConstructJob(Compilation &C, const JobAction &JA,
Job &Dest,
const InputInfo &Output,
const InputInfoList &Inputs,
const ArgList &TCArgs,
const char *LinkingOutput) const {
ArgStringList CmdArgs;
for (ArgList::const_iterator
it = TCArgs.begin(), ie = TCArgs.end(); it != ie; ++it) {
Arg *A = *it;
if (A->getOption().hasForwardToGCC())
A->render(TCArgs, CmdArgs);
}
RenderExtraToolArgs(CmdArgs);
// If using a driver driver, force the arch.
if (getToolChain().getHost().useDriverDriver()) {
CmdArgs.push_back("-arch");
CmdArgs.push_back(getToolChain().getArchName().c_str());
}
if (Output.isPipe()) {
CmdArgs.push_back("-o");
CmdArgs.push_back("-");
} else if (const char *N = Output.getInputFilename()) {
CmdArgs.push_back("-o");
CmdArgs.push_back(N);
} else
CmdArgs.push_back("-fsyntax-only");
// Only pass -x if gcc will understand it; otherwise hope gcc
// understands the suffix correctly. The main use case this would go
// wrong in is for linker inputs if they happened to have an odd
// suffix; really the only way to get this to happen is a command
// like '-x foobar a.c' which will treat a.c like a linker input.
//
// FIXME: For the linker case specifically, can we safely convert
// inputs into '-Wl,' options?
for (InputInfoList::const_iterator
it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
const InputInfo &II = *it;
if (types::canTypeBeUserSpecified(II.getType())) {
CmdArgs.push_back("-x");
CmdArgs.push_back(types::getTypeName(II.getType()));
}
if (II.isPipe())
CmdArgs.push_back("-");
else
// FIXME: Linker inputs
CmdArgs.push_back(II.getInputFilename());
}
Dest.addCommand(new Command("gcc", CmdArgs));
}
void gcc::Preprocess::RenderExtraToolArgs(ArgStringList &CmdArgs) const {
CmdArgs.push_back("-E");
}
void gcc::Precompile::RenderExtraToolArgs(ArgStringList &CmdArgs) const {
// The type is good enough.
}
void gcc::Compile::RenderExtraToolArgs(ArgStringList &CmdArgs) const {
CmdArgs.push_back("-S");
}
void gcc::Assemble::RenderExtraToolArgs(ArgStringList &CmdArgs) const {
CmdArgs.push_back("-c");
}
void gcc::Link::RenderExtraToolArgs(ArgStringList &CmdArgs) const {
// The types are (hopefully) good enough.
}
|