Driver.h revision af61c71137d1f7239d6b9d7425ce083db7ba31df
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/Util.h"
16
17#include <list>
18#include <set>
19#include <string>
20
21namespace clang {
22namespace driver {
23  class Action;
24  class ArgList;
25  class Compilation;
26  class HostInfo;
27  class OptTable;
28
29/// Driver - Encapsulate logic for constructing compilation processes
30/// from a set of gcc-driver-like command line arguments.
31class Driver {
32  /// PhaseOrder - Ordered values for successive stages in the
33  /// compilation process which interact with user options.
34  enum PhaseOrder {
35    /// Nothing.
36    NoPhaseOrder = 0,
37
38    /// Only run the preprocessor.
39    PreprocessPhaseOrder,
40
41    /// Only run the preprocessor and compiler.
42    CompilePhaseOrder,
43
44    /// Only run the preprocessor, compiler, and assembler.
45    AssemblePhaseOrder,
46
47    /// Run everything.
48    PostAssemblePhaseOrder
49  };
50
51  OptTable *Opts;
52
53  Diagnostic &Diags;
54
55  /// ParseArgStrings - Parse the given list of strings into an
56  /// ArgList.
57  ArgList *ParseArgStrings(const char **ArgBegin, const char **ArgEnd);
58
59  // Diag - Forwarding function for diagnostics.
60  DiagnosticBuilder Diag(unsigned DiagID) {
61    return Diags.Report(FullSourceLoc(), DiagID);
62  }
63
64  // FIXME: Privatize once interface is stable.
65public:
66  /// The name the driver was invoked as.
67  std::string Name;
68
69  /// The path the driver executable was in, as invoked from the
70  /// command line.
71  std::string Dir;
72
73  /// Default host triple.
74  std::string DefaultHostTriple;
75
76  /// Host information for the platform the driver is running as. This
77  /// will generally be the actual host platform, but not always.
78  HostInfo *Host;
79
80  /// Information about the host which can be overriden by the user.
81  std::string HostBits, HostMachine, HostSystem, HostRelease;
82
83  /// Whether the driver should follow g++ like behavior.
84  bool CCCIsCXX : 1;
85
86  /// Echo commands while executing (in -v style).
87  bool CCCEcho : 1;
88
89  /// Don't use clang for any tasks.
90  bool CCCNoClang : 1;
91
92  /// Don't use clang for handling C++ and Objective-C++ inputs.
93  bool CCCNoClangCXX : 1;
94
95  /// Don't use clang as a preprocessor (clang's preprocessor will
96  /// still be used where an integrated CPP would).
97  bool CCCNoClangCPP : 1;
98
99  /// Only use clang for the given architectures. Only used when
100  /// non-empty.
101  std::set<std::string> CCCClangArchs;
102
103  /// Certain options suppress the 'no input files' warning.
104  bool SuppressMissingInputWarning : 1;
105
106  std::list<std::string> TempFiles;
107  std::list<std::string> ResultFiles;
108
109public:
110  Driver(const char *_Name, const char *_Dir,
111         const char *_DefaultHostTriple,
112         Diagnostic &_Diags);
113  ~Driver();
114
115  const OptTable &getOpts() const { return *Opts; }
116
117  /// BuildCompilation - Construct a compilation object for a command
118  /// line argument vector.
119  Compilation *BuildCompilation(int argc, const char **argv);
120
121  /// PrintOptions - Print the list of arguments.
122  void PrintOptions(const ArgList &Args) const;
123
124  /// PrintActions - Print the list of actions.
125  void PrintActions(const ActionList &Actions) const;
126
127  /// GetHostInfo - Construct a new host info object for the given
128  /// host triple.
129  static HostInfo *GetHostInfo(const char *HostTriple);
130
131  /// BuildUniversalActions - Construct the list of actions to perform
132  /// for the given arguments, which may require a universal build.
133  ///
134  /// \param Args - The input arguments.
135  /// \param Actions - The list to store the resulting actions onto.
136  void BuildUniversalActions(ArgList &Args, ActionList &Actions);
137
138  /// BuildActions - Construct the list of actions to perform for the
139  /// given arguments, which are only done for a single architecture.
140  ///
141  /// \param Args - The input arguments.
142  /// \param Actions - The list to store the resulting actions onto.
143  void BuildActions(ArgList &Args, ActionList &Actions);
144};
145
146} // end namespace driver
147} // end namespace clang
148
149#endif
150