Skip to content

Commit ee66cf2

Browse files
committed
Driver: Handle magic -ccc- options.
- Follows ccc currently, but this functionality should eventually be outside the Driver lib. llvm-svn: 66575
1 parent aa88765 commit ee66cf2

File tree

4 files changed

+146
-11
lines changed

4 files changed

+146
-11
lines changed

clang/include/clang/Driver/Driver.h

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@
1010
#ifndef CLANG_DRIVER_DRIVER_H_
1111
#define CLANG_DRIVER_DRIVER_H_
1212

13+
#include <list>
14+
#include <set>
15+
#include <string>
16+
1317
namespace clang {
1418
namespace driver {
1519
class ArgList;
1620
class Compilation;
21+
class HostInfo;
1722
class OptTable;
1823

1924
/// Driver - Encapsulate logic for constructing compilation processes
@@ -25,15 +30,61 @@ class Driver {
2530
/// ArgList.
2631
ArgList *ParseArgStrings(const char **ArgBegin, const char **ArgEnd);
2732

33+
// FIXME: Privatize once interface is stable.
34+
public:
35+
/// The name the driver was invoked as.
36+
std::string Name;
37+
38+
/// The path the driver executable was in, as invoked from the
39+
/// command line.
40+
std::string Dir;
41+
42+
/// Host information for the platform the driver is running as. This
43+
/// will generally be the actual host platform, but not always.
44+
HostInfo *Host;
45+
46+
/// Information about the host which can be overriden by the user.
47+
std::string HostBits, HostMachine, HostSystem, HostRelease;
48+
49+
/// Whether the driver should follow g++ like behavior.
50+
bool CCCIsCXX : 1;
51+
52+
/// Echo commands while executing (in -v style).
53+
bool CCCEcho : 1;
54+
55+
/// Don't use clang for any tasks.
56+
bool CCCNoClang : 1;
57+
58+
/// Don't use clang for handling C++ and Objective-C++ inputs.
59+
bool CCCNoClangCXX : 1;
60+
61+
/// Don't use clang as a preprocessor (clang's preprocessor will
62+
/// still be used where an integrated CPP would).
63+
bool CCCNoClangCPP : 1;
64+
65+
/// Only use clang for the given architectures. Only used when
66+
/// non-empty.
67+
std::set<std::string> CCCClangArchs;
68+
69+
/// Certain options suppress the 'no input files' warning.
70+
bool SuppressMissingInputWarning : 1;
71+
72+
std::list<std::string> TempFiles;
73+
std::list<std::string> ResultFiles;
74+
2875
public:
29-
Driver();
76+
Driver(const char *_Name, const char *_Dir);
3077
~Driver();
3178

79+
3280
const OptTable &getOpts() const { return *Opts; }
3381

3482
/// BuildCompilation - Construct a compilation object for a command
3583
/// line argument vector.
3684
Compilation *BuildCompilation(int argc, const char **argv);
85+
86+
/// PrintOptions - Print the given list of arguments.
87+
void PrintOptions(const ArgList *Args);
3788
};
3889

3990
} // end namespace driver

clang/lib/Driver/Driver.cpp

Lines changed: 86 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@
1818
#include "llvm/Support/raw_ostream.h"
1919
using namespace clang::driver;
2020

21-
Driver::Driver() : Opts(new OptTable()) {
21+
Driver::Driver(const char *_Name, const char *_Dir)
22+
: Opts(new OptTable()),
23+
Name(_Name), Dir(_Dir), Host(0),
24+
CCCIsCXX(false), CCCEcho(false),
25+
CCCNoClang(false), CCCNoClangCXX(false), CCCNoClangCPP(false)
26+
{
2227

2328
}
2429

@@ -43,11 +48,88 @@ ArgList *Driver::ParseArgStrings(const char **ArgBegin, const char **ArgEnd) {
4348
}
4449

4550
Compilation *Driver::BuildCompilation(int argc, const char **argv) {
46-
ArgList *Args = ParseArgStrings(argv + 1, argv + argc);
51+
// FIXME: This stuff needs to go into the Compilation, not the
52+
// driver.
53+
bool CCCPrintOptions = false, CCCPrintPhases = false;
4754

48-
// Hard coded to print-options behavior.
55+
const char **Start = argv + 1, **End = argv + argc;
56+
57+
// Read -ccc args.
58+
//
59+
// FIXME: We need to figure out where this behavior should
60+
// live. Most of it should be outside in the client; the parts that
61+
// aren't should have proper options, either by introducing new ones
62+
// or by overloading gcc ones like -V or -b.
63+
for (; Start != End && memcmp(*Start, "-ccc-", 5) == 0; ++Start) {
64+
const char *Opt = *Start + 5;
65+
66+
if (!strcmp(Opt, "print-options")) {
67+
CCCPrintOptions = true;
68+
} else if (!strcmp(Opt, "print-phases")) {
69+
CCCPrintPhases = true;
70+
} else if (!strcmp(Opt, "cxx")) {
71+
CCCIsCXX = true;
72+
} else if (!strcmp(Opt, "echo")) {
73+
CCCEcho = true;
74+
75+
} else if (!strcmp(Opt, "no-clang")) {
76+
CCCNoClang = true;
77+
} else if (!strcmp(Opt, "no-clang-cxx")) {
78+
CCCNoClangCXX = true;
79+
} else if (!strcmp(Opt, "no-clang-cpp")) {
80+
CCCNoClangCPP = true;
81+
} else if (!strcmp(Opt, "clang-archs")) {
82+
assert(Start+1 < End && "FIXME: -ccc- argument handling.");
83+
const char *Cur = *++Start;
84+
85+
for (;;) {
86+
const char *Next = strchr(Cur, ',');
87+
88+
if (Next) {
89+
CCCClangArchs.insert(std::string(Cur, Next));
90+
Cur = Next + 1;
91+
} else {
92+
CCCClangArchs.insert(std::string(Cur));
93+
break;
94+
}
95+
}
96+
97+
} else if (!strcmp(Opt, "host-bits")) {
98+
assert(Start+1 < End && "FIXME: -ccc- argument handling.");
99+
HostBits = *++Start;
100+
} else if (!strcmp(Opt, "host-machine")) {
101+
assert(Start+1 < End && "FIXME: -ccc- argument handling.");
102+
HostMachine = *++Start;
103+
} else if (!strcmp(Opt, "host-release")) {
104+
assert(Start+1 < End && "FIXME: -ccc- argument handling.");
105+
HostRelease = *++Start;
106+
} else if (!strcmp(Opt, "host-system")) {
107+
assert(Start+1 < End && "FIXME: -ccc- argument handling.");
108+
HostSystem = *++Start;
109+
110+
} else {
111+
// FIXME: Error handling.
112+
llvm::errs() << "invalid option: " << *Start << "\n";
113+
exit(1);
114+
}
115+
}
116+
117+
ArgList *Args = ParseArgStrings(Start, End);
118+
119+
// FIXME: This behavior shouldn't be here.
120+
if (CCCPrintOptions) {
121+
PrintOptions(Args);
122+
exit(0);
123+
}
124+
125+
assert(0 && "FIXME: Implement");
126+
127+
return new Compilation();
128+
}
129+
130+
void Driver::PrintOptions(const ArgList *Args) {
49131
unsigned i = 0;
50-
for (ArgList::iterator it = Args->begin(), ie = Args->end();
132+
for (ArgList::const_iterator it = Args->begin(), ie = Args->end();
51133
it != ie; ++it, ++i) {
52134
Arg *A = *it;
53135
llvm::errs() << "Option " << i << " - "
@@ -60,6 +142,4 @@ Compilation *Driver::BuildCompilation(int argc, const char **argv) {
60142
}
61143
llvm::errs() << "}\n";
62144
}
63-
64-
return new Compilation();
65145
}

clang/tools/ccc/ccclib/Driver.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ def __init__(self, driverName, driverDir):
3030
self.cccHostSystem = self.cccHostRelease = None
3131
self.cccCXX = False
3232
self.cccEcho = False
33-
self.cccFallback = False
3433
self.cccNoClang = self.cccNoClangCXX = self.cccNoClangPreprocessor = False
3534
self.cccClangArchs = None
3635

@@ -139,8 +138,6 @@ def run(self, argv):
139138
self.cccCXX = True
140139
elif opt == 'echo':
141140
self.cccEcho = True
142-
elif opt == 'fallback':
143-
self.cccFallback = True
144141

145142
elif opt == 'no-clang':
146143
self.cccNoClang = True

clang/tools/driver/driver.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,20 @@
1818
#include "clang/Driver/Options.h"
1919

2020
#include "llvm/ADT/OwningPtr.h"
21+
#include "llvm/System/Path.h"
2122
#include "llvm/System/Signals.h"
2223
using namespace clang::driver;
2324

2425
int main(int argc, const char **argv) {
2526
llvm::sys::PrintStackTraceOnErrorSignal();
2627

27-
llvm::OwningPtr<Driver> TheDriver(new Driver());
28+
// FIXME: We should use GetMainExecutable here, probably, but we may
29+
// want to handle symbolic links slightly differently. The problem
30+
// is that the path derived from this will influence search paths.
31+
llvm::sys::Path Path(argv[0]);
32+
33+
llvm::OwningPtr<Driver> TheDriver(new Driver(Path.getBasename().c_str(),
34+
Path.getDirname().c_str()));
2835

2936
llvm::OwningPtr<Compilation> C(TheDriver->BuildCompilation(argc, argv));
3037

0 commit comments

Comments
 (0)