Driver.h revision 57b704d8d8f49bcaf856a3e37941d5ac6456eb50
1//===--- Driver.h - Clang GCC Compatible Driver -----------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef CLANG_DRIVER_DRIVER_H_
11#define CLANG_DRIVER_DRIVER_H_
12
13#include "clang/Basic/Diagnostic.h"
14
15#include "clang/Driver/Phases.h"
16#include "clang/Driver/Util.h"
17
18#include "llvm/System/Path.h" // FIXME: Kill when CompilationInfo
19                              // lands.
20#include <list>
21#include <set>
22#include <string>
23
24namespace clang {
25namespace driver {
26  class Action;
27  class ArgList;
28  class Compilation;
29  class HostInfo;
30  class OptTable;
31  class ToolChain;
32
33/// Driver - Encapsulate logic for constructing compilation processes
34/// from a set of gcc-driver-like command line arguments.
35class Driver {
36  OptTable *Opts;
37
38  Diagnostic &Diags;
39
40  // Diag - Forwarding function for diagnostics.
41  DiagnosticBuilder Diag(unsigned DiagID) const {
42    return Diags.Report(FullSourceLoc(), DiagID);
43  }
44
45  // FIXME: Privatize once interface is stable.
46public:
47  /// The name the driver was invoked as.
48  std::string Name;
49
50  /// The path the driver executable was in, as invoked from the
51  /// command line.
52  std::string Dir;
53
54  /// Default host triple.
55  std::string DefaultHostTriple;
56
57  /// Host information for the platform the driver is running as. This
58  /// will generally be the actual host platform, but not always.
59  HostInfo *Host;
60
61  /// The default tool chain for this host.
62  // FIXME: This shouldn't be here; this should be in a
63  // CompilationInfo structure.
64  ToolChain *DefaultToolChain;
65
66  /// Information about the host which can be overriden by the user.
67  std::string HostBits, HostMachine, HostSystem, HostRelease;
68
69  /// Whether the driver should follow g++ like behavior.
70  bool CCCIsCXX : 1;
71
72  /// Echo commands while executing (in -v style).
73  bool CCCEcho : 1;
74
75  /// Don't use clang for any tasks.
76  bool CCCNoClang : 1;
77
78  /// Don't use clang for handling C++ and Objective-C++ inputs.
79  bool CCCNoClangCXX : 1;
80
81  /// Don't use clang as a preprocessor (clang's preprocessor will
82  /// still be used where an integrated CPP would).
83  bool CCCNoClangCPP : 1;
84
85  /// Only use clang for the given architectures. Only used when
86  /// non-empty.
87  std::set<std::string> CCCClangArchs;
88
89  /// Certain options suppress the 'no input files' warning.
90  bool SuppressMissingInputWarning : 1;
91
92  std::list<std::string> TempFiles;
93  std::list<std::string> ResultFiles;
94
95public:
96  Driver(const char *_Name, const char *_Dir,
97         const char *_DefaultHostTriple,
98         Diagnostic &_Diags);
99  ~Driver();
100
101  /// @name Accessors
102  /// @{
103
104  const OptTable &getOpts() const { return *Opts; }
105
106  /// @}
107  /// @name Primary Functionality
108  /// @{
109
110  /// BuildCompilation - Construct a compilation object for a command
111  /// line argument vector.
112  ///
113  /// \return A compilation, or 0 if none was built for the given
114  /// argument vector. A null return value does not necessarily
115  /// indicate an error condition, the diagnostics should be queried
116  /// to determine if an error occurred.
117  Compilation *BuildCompilation(int argc, const char **argv);
118
119  /// @name Driver Steps
120  /// @{
121
122  /// ParseArgStrings - Parse the given list of strings into an
123  /// ArgList.
124  ArgList *ParseArgStrings(const char **ArgBegin, const char **ArgEnd);
125
126  /// BuildActions - Construct the list of actions to perform for the
127  /// given arguments, which are only done for a single architecture.
128  ///
129  /// \param Args - The input arguments.
130  /// \param Actions - The list to store the resulting actions onto.
131  void BuildActions(ArgList &Args, ActionList &Actions) const;
132
133  /// BuildUniversalActions - Construct the list of actions to perform
134  /// for the given arguments, which may require a universal build.
135  ///
136  /// \param Args - The input arguments.
137  /// \param Actions - The list to store the resulting actions onto.
138  void BuildUniversalActions(ArgList &Args, ActionList &Actions) const;
139
140  /// BuildJobs - Bind actions to concrete tools and translate
141  /// arguments to form the list of jobs to run.
142  Compilation *BuildJobs(const ArgList &Args, const ActionList &Actions) const;
143
144  /// @}
145  /// @name Helper Methods
146  /// @{
147
148  /// PrintOptions - Print the list of arguments.
149  void PrintOptions(const ArgList &Args) const;
150
151  /// PrintVersion - Print the driver version.
152  void PrintVersion() const;
153
154  /// PrintActions - Print the list of actions.
155  void PrintActions(const ArgList &Args, const ActionList &Actions) const;
156
157  /// GetFilePath - Lookup \arg Name in the list of file search paths.
158  // FIXME: This should be in CompilationInfo.
159  llvm::sys::Path GetFilePath(const char *Name) const;
160
161  /// GetProgramPath - Lookup \arg Name in the list of program search
162  /// paths.
163  // FIXME: This should be in CompilationInfo.
164  llvm::sys::Path GetProgramPath(const char *Name) const;
165
166  /// HandleImmediateArgs - Handle any arguments which should be
167  /// treated before building actions or binding tools.
168  ///
169  /// \return Whether any compilation should be built for this
170  /// invocation.
171  bool HandleImmediateArgs(const ArgList &Args);
172
173  /// ConstructAction - Construct the appropriate action to do for
174  /// \arg Phase on the \arg Input, taking in to account arguments
175  /// like -fsyntax-only or --analyze.
176  Action *ConstructPhaseAction(const ArgList &Args, phases::ID Phase,
177                               Action *Input) const;
178
179  /// GetHostInfo - Construct a new host info object for the given
180  /// host triple.
181  static HostInfo *GetHostInfo(const char *HostTriple);
182
183  /// @}
184};
185
186} // end namespace driver
187} // end namespace clang
188
189#endif
190