[cfe-commits] r67036 - in /cfe/trunk: include/clang/Driver/Driver.h include/clang/Driver/Tool.h include/clang/Driver/ToolChain.h lib/Driver/Driver.cpp lib/Driver/Tool.cpp lib/Driver/ToolChain.cpp

Daniel Dunbar daniel at zuster.org
Sun Mar 15 22:25:36 PDT 2009


Author: ddunbar
Date: Mon Mar 16 00:25:36 2009
New Revision: 67036

URL: http://llvm.org/viewvc/llvm-project?rev=67036&view=rev
Log:
Driver: Sketch Tool and ToolChain classes.

Added:
    cfe/trunk/include/clang/Driver/Tool.h
    cfe/trunk/include/clang/Driver/ToolChain.h
    cfe/trunk/lib/Driver/Tool.cpp
    cfe/trunk/lib/Driver/ToolChain.cpp
Modified:
    cfe/trunk/include/clang/Driver/Driver.h
    cfe/trunk/lib/Driver/Driver.cpp

Modified: cfe/trunk/include/clang/Driver/Driver.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Driver.h?rev=67036&r1=67035&r2=67036&view=diff

==============================================================================
--- cfe/trunk/include/clang/Driver/Driver.h (original)
+++ cfe/trunk/include/clang/Driver/Driver.h Mon Mar 16 00:25:36 2009
@@ -155,13 +155,21 @@
   void PrintActions(const ArgList &Args, const ActionList &Actions) const;
 
   /// GetFilePath - Lookup \arg Name in the list of file search paths.
+  ///
+  /// \arg TC - Use the provided tool chain for additional information
+  /// on directories to search, or the DefaultToolChain if not
+  /// provided.
   // FIXME: This should be in CompilationInfo.
-  llvm::sys::Path GetFilePath(const char *Name) const;
+  llvm::sys::Path GetFilePath(const char *Name, const ToolChain *TC=0) const;
 
   /// GetProgramPath - Lookup \arg Name in the list of program search
   /// paths.
+  ///
+  /// \arg TC - Use the provided tool chain for additional information
+  /// on directories to search, or the DefaultToolChain if not
+  /// provided.
   // FIXME: This should be in CompilationInfo.
-  llvm::sys::Path GetProgramPath(const char *Name) const;
+  llvm::sys::Path GetProgramPath(const char *Name, const ToolChain *TC=0) const;
 
   /// HandleImmediateArgs - Handle any arguments which should be
   /// treated before building actions or binding tools.

Added: cfe/trunk/include/clang/Driver/Tool.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Tool.h?rev=67036&view=auto

==============================================================================
--- cfe/trunk/include/clang/Driver/Tool.h (added)
+++ cfe/trunk/include/clang/Driver/Tool.h Mon Mar 16 00:25:36 2009
@@ -0,0 +1,32 @@
+//===--- Tool.h - Compilation Tools -----------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef CLANG_DRIVER_TOOL_H_
+#define CLANG_DRIVER_TOOL_H_
+
+namespace clang {
+namespace driver {
+
+/// Tool - Information on a specific compilation tool.
+class Tool {
+protected:
+  Tool();
+
+public:
+  virtual ~Tool();
+
+  virtual bool acceptsPipedInput() const = 0;
+  virtual bool canPipeOutput() const = 0;
+  virtual bool hasIntegratedCPP() const = 0;
+};
+
+} // end namespace driver
+} // end namespace clang
+
+#endif

Added: cfe/trunk/include/clang/Driver/ToolChain.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ToolChain.h?rev=67036&view=auto

==============================================================================
--- cfe/trunk/include/clang/Driver/ToolChain.h (added)
+++ cfe/trunk/include/clang/Driver/ToolChain.h Mon Mar 16 00:25:36 2009
@@ -0,0 +1,84 @@
+//===--- ToolChain.h - Collections of tools for one platform ----*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef CLANG_DRIVER_TOOLCHAIN_H_
+#define CLANG_DRIVER_TOOLCHAIN_H_
+
+#include "llvm/System/Path.h"
+#include <string>
+
+namespace clang {
+namespace driver {
+  class ArgList;
+  class Compilation;
+  class Driver;
+  class JobAction;
+  class Tool;
+
+/// ToolChain - Access to tools for a single platform.
+class ToolChain {
+  Driver &TheDriver;
+
+  std::string Arch, Platform, OS;
+
+protected:
+  ToolChain(Driver &D, const char *_Arch, const char *_Platform, 
+            const char *_OS);
+
+public:
+  virtual ~ToolChain();
+
+  // Accessors
+
+  const std::string &getArchName() const { return Arch; }
+  const std::string &getPlatform() const { return Platform; }
+  const std::string &getOS() const { return OS; }
+
+  // Tool access.
+
+  /// TranslateArgs - Create a new derived argument list for any
+  /// argument translations this ToolChain may wish to perform.
+  virtual ArgList *TranslateArgs(const ArgList &Args) const = 0;
+
+  /// SelectTool - Choose a tool to use to handle the action \arg JA.
+  virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const = 0;
+
+  // Helper methods
+
+  llvm::sys::Path GetFilePath(const Compilation &C, const char *Name) const;
+  llvm::sys::Path GetProgramPath(const Compilation &C, const char *Name) const;
+
+  /// ShouldUseClangCompilar - Should the clang compiler be used to
+  /// handle this action.
+  bool ShouldUseClangCompiler(const Compilation &C, const JobAction &JA) const;
+
+  // Platform defaults information
+
+  /// IsMathErrnoDefault - Does this tool chain set -fmath-errno by
+  /// default.
+  virtual bool IsMathErrnoDefault() const = 0;
+
+  /// IsUnwindTablesDefault - Does this tool chain use -funwind-tables
+  /// by default.
+  virtual bool IsUnwindTablesDefault() const = 0;
+
+  /// GetDefaultRelocationModel - Return the LLVM name of the default
+  /// relocation model for this tool chain.
+  virtual const char *GetDefaultRelocationModel() const = 0;
+
+  /// GetForcedPicModel - Return the LLVM name of the forced PIC model
+  /// for this tool chain, or 0 if this tool chain does not force a
+  /// particular PIC mode.
+  virtual const char *GetForcedPicModel() const = 0;
+};
+
+} // end namespace driver
+} // end namespace clang
+
+#endif

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=67036&r1=67035&r2=67036&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Mon Mar 16 00:25:36 2009
@@ -582,13 +582,19 @@
   return 0;
 }
 
-llvm::sys::Path Driver::GetFilePath(const char *Name) const {
+llvm::sys::Path Driver::GetFilePath(const char *Name,
+                                    const ToolChain *TC) const {
   // FIXME: Implement.
+  if (!TC) TC = DefaultToolChain;
+
   return llvm::sys::Path(Name);
 }
 
-llvm::sys::Path Driver::GetProgramPath(const char *Name) const {
+llvm::sys::Path Driver::GetProgramPath(const char *Name, 
+                                       const ToolChain *TC) const {
   // FIXME: Implement.
+  if (!TC) TC = DefaultToolChain;
+
   return llvm::sys::Path(Name);
 }
 

Added: cfe/trunk/lib/Driver/Tool.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tool.cpp?rev=67036&view=auto

==============================================================================
--- cfe/trunk/lib/Driver/Tool.cpp (added)
+++ cfe/trunk/lib/Driver/Tool.cpp Mon Mar 16 00:25:36 2009
@@ -0,0 +1,15 @@
+//===--- Tool.cpp - Compilation Tools -----------------------------------*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Driver/Tool.h"
+
+using namespace clang::driver;
+
+Tool::~Tool() {
+}

Added: cfe/trunk/lib/Driver/ToolChain.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChain.cpp?rev=67036&view=auto

==============================================================================
--- cfe/trunk/lib/Driver/ToolChain.cpp (added)
+++ cfe/trunk/lib/Driver/ToolChain.cpp Mon Mar 16 00:25:36 2009
@@ -0,0 +1,62 @@
+//===--- ToolChain.cpp - Collections of tools for one platform ----------*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Driver/ToolChain.h"
+
+#include "clang/Driver/Action.h"
+#include "clang/Driver/Driver.h"
+
+using namespace clang::driver;
+
+ToolChain::ToolChain(Driver &_TheDriver, const char *_Arch, 
+                     const char *_Platform, const char *_OS) 
+  : TheDriver(_TheDriver), Arch(_Arch), Platform(_Platform), OS(_OS) {
+}
+
+ToolChain::~ToolChain() {
+}
+
+llvm::sys::Path ToolChain::GetFilePath(const Compilation &C, 
+                                       const char *Name) const {
+  return TheDriver.GetFilePath(Name, this);
+  
+}
+
+llvm::sys::Path ToolChain::GetProgramPath(const Compilation &C, 
+                                          const char *Name) const {
+  return TheDriver.GetProgramPath(Name, this);
+}
+
+bool ToolChain::ShouldUseClangCompiler(const Compilation &C, 
+                                       const JobAction &JA) const {
+  // Check if user requested no clang, or clang doesn't understand
+  // this type (we only handle single inputs for now).
+  if (TheDriver.CCCNoClang || JA.size() != 1 || 
+      !types::isAcceptedByClang((*JA.begin())->getType()))
+    return false;
+
+  // Otherwise make sure this is an action clang undertands.
+  if (isa<PreprocessJobAction>(JA)) {
+    if (TheDriver.CCCNoClangCPP)
+      return false;
+  } else if (!isa<PrecompileJobAction>(JA) && !isa<CompileJobAction>(JA))
+    return false;
+
+  // Avoid CXX if the user requested.
+  if (TheDriver.CCCNoClangCXX && types::isCXX((*JA.begin())->getType()))
+    return false;
+
+  // Finally, don't use clang if this isn't one of the user specified
+  // archs to build.
+  if (!TheDriver.CCCClangArchs.empty() && 
+      TheDriver.CCCClangArchs.count(getArchName()))
+    return false;
+
+  return true;
+}





More information about the cfe-commits mailing list