zcov: / include/clang/Driver/Driver.h


Files: 1 Branches Taken: 0.0% 0 / 0
Generated: 2010-02-10 01:31 Branches Executed: 0.0% 0 / 0
Line Coverage: 100.0% 5 / 5


Programs: 12 Runs 18108


       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/ADT/StringRef.h"
      19                 : #include "llvm/ADT/Triple.h"
      20                 : #include "llvm/System/Path.h" // FIXME: Kill when CompilationInfo
      21                 :                               // lands.
      22                 : #include <list>
      23                 : #include <set>
      24                 : #include <string>
      25                 : 
      26                 : namespace llvm {
      27                 :   class raw_ostream;
      28                 : }
      29                 : namespace clang {
      30                 : namespace driver {
      31                 :   class Action;
      32                 :   class ArgList;
      33                 :   class Compilation;
      34                 :   class HostInfo;
      35                 :   class InputArgList;
      36                 :   class InputInfo;
      37                 :   class JobAction;
      38                 :   class OptTable;
      39                 :   class PipedJob;
      40                 :   class ToolChain;
      41                 : 
      42                 : /// Driver - Encapsulate logic for constructing compilation processes
      43                 : /// from a set of gcc-driver-like command line arguments.
      44                 : class Driver {
      45                 :   OptTable *Opts;
      46                 : 
      47                 :   Diagnostic &Diags;
      48                 : 
      49                 : public:
      50                 :   // Diag - Forwarding function for diagnostics.
      51               40:   DiagnosticBuilder Diag(unsigned DiagID) const {
      52               40:     return Diags.Report(DiagID);
      53                 :   }
      54                 : 
      55                 :   // FIXME: Privatize once interface is stable.
      56                 : public:
      57                 :   /// The name the driver was invoked as.
      58                 :   std::string Name;
      59                 : 
      60                 :   /// The path the driver executable was in, as invoked from the
      61                 :   /// command line.
      62                 :   std::string Dir;
      63                 : 
      64                 :   /// The path to the compiler resource directory.
      65                 :   std::string ResourceDir;
      66                 : 
      67                 :   /// Default host triple.
      68                 :   std::string DefaultHostTriple;
      69                 : 
      70                 :   /// Default name for linked images (e.g., "a.out").
      71                 :   std::string DefaultImageName;
      72                 : 
      73                 :   /// Host information for the platform the driver is running as. This
      74                 :   /// will generally be the actual host platform, but not always.
      75                 :   const HostInfo *Host;
      76                 : 
      77                 :   /// Information about the host which can be overriden by the user.
      78                 :   std::string HostBits, HostMachine, HostSystem, HostRelease;
      79                 : 
      80                 :   /// Name to use when calling the generic gcc.
      81                 :   std::string CCCGenericGCCName;
      82                 : 
      83                 :   /// Whether the driver should follow g++ like behavior.
      84                 :   unsigned CCCIsCXX : 1;
      85                 : 
      86                 :   /// Echo commands while executing (in -v style).
      87                 :   unsigned CCCEcho : 1;
      88                 : 
      89                 :   /// Only print tool bindings, don't build any jobs.
      90                 :   unsigned CCCPrintBindings : 1;
      91                 : 
      92                 : private:
      93                 :   /// Whether to check that input files exist when constructing compilation
      94                 :   /// jobs.
      95                 :   unsigned CheckInputsExist : 1;
      96                 : 
      97                 :   /// Use the clang compiler where possible.
      98                 :   unsigned CCCUseClang : 1;
      99                 : 
     100                 :   /// Use clang for handling C++ and Objective-C++ inputs.
     101                 :   unsigned CCCUseClangCXX : 1;
     102                 : 
     103                 :   /// Use clang as a preprocessor (clang's preprocessor will still be
     104                 :   /// used where an integrated CPP would).
     105                 :   unsigned CCCUseClangCPP : 1;
     106                 : 
     107                 : public:
     108                 :   /// Use lazy precompiled headers for PCH support.
     109                 :   unsigned CCCUsePCH : 1;
     110                 : 
     111                 : private:
     112                 :   /// Only use clang for the given architectures (only used when
     113                 :   /// non-empty).
     114                 :   std::set<llvm::Triple::ArchType> CCCClangArchs;
     115                 : 
     116                 :   /// Certain options suppress the 'no input files' warning.
     117                 :   bool SuppressMissingInputWarning : 1;
     118                 : 
     119                 :   std::list<std::string> TempFiles;
     120                 :   std::list<std::string> ResultFiles;
     121                 : 
     122                 : public:
     123                 :   Driver(llvm::StringRef _Name, llvm::StringRef _Dir,
     124                 :          llvm::StringRef _DefaultHostTriple,
     125                 :          llvm::StringRef _DefaultImageName,
     126                 :          bool IsProduction, Diagnostic &_Diags);
     127                 :   ~Driver();
     128                 : 
     129                 :   /// @name Accessors
     130                 :   /// @{
     131                 : 
     132              302:   const OptTable &getOpts() const { return *Opts; }
     133                 : 
     134              187:   const Diagnostic &getDiags() const { return Diags; }
     135                 : 
     136                 :   bool getCheckInputsExist() const { return CheckInputsExist; }
     137                 : 
     138                9:   void setCheckInputsExist(bool Value) { CheckInputsExist = Value; }
     139                 : 
     140                 :   /// @}
     141                 :   /// @name Primary Functionality
     142                 :   /// @{
     143                 : 
     144                 :   /// BuildCompilation - Construct a compilation object for a command
     145                 :   /// line argument vector.
     146                 :   ///
     147                 :   /// \return A compilation, or 0 if none was built for the given
     148                 :   /// argument vector. A null return value does not necessarily
     149                 :   /// indicate an error condition, the diagnostics should be queried
     150                 :   /// to determine if an error occurred.
     151                 :   Compilation *BuildCompilation(int argc, const char **argv);
     152                 : 
     153                 :   /// @name Driver Steps
     154                 :   /// @{
     155                 : 
     156                 :   /// ParseArgStrings - Parse the given list of strings into an
     157                 :   /// ArgList.
     158                 :   InputArgList *ParseArgStrings(const char **ArgBegin, const char **ArgEnd);
     159                 : 
     160                 :   /// BuildActions - Construct the list of actions to perform for the
     161                 :   /// given arguments, which are only done for a single architecture.
     162                 :   ///
     163                 :   /// \param Args - The input arguments.
     164                 :   /// \param Actions - The list to store the resulting actions onto.
     165                 :   void BuildActions(const ArgList &Args, ActionList &Actions) const;
     166                 : 
     167                 :   /// BuildUniversalActions - Construct the list of actions to perform
     168                 :   /// for the given arguments, which may require a universal build.
     169                 :   ///
     170                 :   /// \param Args - The input arguments.
     171                 :   /// \param Actions - The list to store the resulting actions onto.
     172                 :   void BuildUniversalActions(const ArgList &Args, ActionList &Actions) const;
     173                 : 
     174                 :   /// BuildJobs - Bind actions to concrete tools and translate
     175                 :   /// arguments to form the list of jobs to run.
     176                 :   ///
     177                 :   /// \arg C - The compilation that is being built.
     178                 :   void BuildJobs(Compilation &C) const;
     179                 : 
     180                 :   /// ExecuteCompilation - Execute the compilation according to the command line
     181                 :   /// arguments and return an appropriate exit code.
     182                 :   ///
     183                 :   /// This routine handles additional processing that must be done in addition
     184                 :   /// to just running the subprocesses, for example reporting errors, removing
     185                 :   /// temporary files, etc.
     186                 :   int ExecuteCompilation(const Compilation &C) const;
     187                 : 
     188                 :   /// @}
     189                 :   /// @name Helper Methods
     190                 :   /// @{
     191                 : 
     192                 :   /// PrintActions - Print the list of actions.
     193                 :   void PrintActions(const Compilation &C) const;
     194                 : 
     195                 :   /// PrintHelp - Print the help text.
     196                 :   ///
     197                 :   /// \param ShowHidden - Show hidden options.
     198                 :   void PrintHelp(bool ShowHidden) const;
     199                 : 
     200                 :   /// PrintOptions - Print the list of arguments.
     201                 :   void PrintOptions(const ArgList &Args) const;
     202                 : 
     203                 :   /// PrintVersion - Print the driver version.
     204                 :   void PrintVersion(const Compilation &C, llvm::raw_ostream &OS) const;
     205                 : 
     206                 :   /// GetFilePath - Lookup \arg Name in the list of file search paths.
     207                 :   ///
     208                 :   /// \arg TC - The tool chain for additional information on
     209                 :   /// directories to search.
     210                 :   //
     211                 :   // FIXME: This should be in CompilationInfo.
     212                 :   std::string GetFilePath(const char *Name, const ToolChain &TC) const;
     213                 : 
     214                 :   /// GetProgramPath - Lookup \arg Name in the list of program search
     215                 :   /// paths.
     216                 :   ///
     217                 :   /// \arg TC - The provided tool chain for additional information on
     218                 :   /// directories to search.
     219                 :   ///
     220                 :   /// \arg WantFile - False when searching for an executable file, otherwise
     221                 :   /// true.  Defaults to false.
     222                 :   //
     223                 :   // FIXME: This should be in CompilationInfo.
     224                 :   std::string GetProgramPath(const char *Name, const ToolChain &TC,
     225                 :                               bool WantFile = false) const;
     226                 : 
     227                 :   /// HandleImmediateArgs - Handle any arguments which should be
     228                 :   /// treated before building actions or binding tools.
     229                 :   ///
     230                 :   /// \return Whether any compilation should be built for this
     231                 :   /// invocation.
     232                 :   bool HandleImmediateArgs(const Compilation &C);
     233                 : 
     234                 :   /// ConstructAction - Construct the appropriate action to do for
     235                 :   /// \arg Phase on the \arg Input, taking in to account arguments
     236                 :   /// like -fsyntax-only or --analyze.
     237                 :   Action *ConstructPhaseAction(const ArgList &Args, phases::ID Phase,
     238                 :                                Action *Input) const;
     239                 : 
     240                 : 
     241                 :   /// BuildJobsForAction - Construct the jobs to perform for the
     242                 :   /// action \arg A.
     243                 :   void BuildJobsForAction(Compilation &C,
     244                 :                           const Action *A,
     245                 :                           const ToolChain *TC,
     246                 :                           const char *BoundArch,
     247                 :                           bool CanAcceptPipe,
     248                 :                           bool AtTopLevel,
     249                 :                           const char *LinkingOutput,
     250                 :                           InputInfo &Result) const;
     251                 : 
     252                 :   /// GetNamedOutputPath - Return the name to use for the output of
     253                 :   /// the action \arg JA. The result is appended to the compilation's
     254                 :   /// list of temporary or result files, as appropriate.
     255                 :   ///
     256                 :   /// \param C - The compilation.
     257                 :   /// \param JA - The action of interest.
     258                 :   /// \param BaseInput - The original input file that this action was
     259                 :   /// triggered by.
     260                 :   /// \param AtTopLevel - Whether this is a "top-level" action.
     261                 :   const char *GetNamedOutputPath(Compilation &C,
     262                 :                                  const JobAction &JA,
     263                 :                                  const char *BaseInput,
     264                 :                                  bool AtTopLevel) const;
     265                 : 
     266                 :   /// GetTemporaryPath - Return the pathname of a temporary file to
     267                 :   /// use as part of compilation; the file will have the given suffix.
     268                 :   ///
     269                 :   /// GCC goes to extra lengths here to be a bit more robust.
     270                 :   std::string GetTemporaryPath(const char *Suffix) const;
     271                 : 
     272                 :   /// GetHostInfo - Construct a new host info object for the given
     273                 :   /// host triple.
     274                 :   const HostInfo *GetHostInfo(const char *HostTriple) const;
     275                 : 
     276                 :   /// ShouldUseClangCompilar - Should the clang compiler be used to
     277                 :   /// handle this action.
     278                 :   bool ShouldUseClangCompiler(const Compilation &C, const JobAction &JA,
     279                 :                               const llvm::Triple &ArchName) const;
     280                 : 
     281                 :   /// @}
     282                 : 
     283                 :   /// GetReleaseVersion - Parse (([0-9]+)(.([0-9]+)(.([0-9]+)?))?)? and
     284                 :   /// return the grouped values as integers. Numbers which are not
     285                 :   /// provided are set to 0.
     286                 :   ///
     287                 :   /// \return True if the entire string was parsed (9.2), or all
     288                 :   /// groups were parsed (10.3.5extrastuff). HadExtra is true if all
     289                 :   /// groups were parsed but extra characters remain at the end.
     290                 :   static bool GetReleaseVersion(const char *Str, unsigned &Major,
     291                 :                                 unsigned &Minor, unsigned &Micro,
     292                 :                                 bool &HadExtra);
     293                 : };
     294                 : 
     295                 : } // end namespace driver
     296                 : } // end namespace clang
     297                 : 
     298                 : #endif

Generated: 2010-02-10 01:31 by zcov