[cfe-commits] r68061 - in /cfe/trunk: include/clang/Driver/HostInfo.h lib/Driver/Driver.cpp lib/Driver/HostInfo.cpp lib/Driver/ToolChains.cpp lib/Driver/ToolChains.h

Daniel Dunbar daniel at zuster.org
Mon Mar 30 14:06:07 PDT 2009


Author: ddunbar
Date: Mon Mar 30 16:06:03 2009
New Revision: 68061

URL: http://llvm.org/viewvc/llvm-project?rev=68061&view=rev
Log:
Driver: Sketch FreeBSD tool chain.
 - Patch by Ed Schouten!

Modified:
    cfe/trunk/include/clang/Driver/HostInfo.h
    cfe/trunk/lib/Driver/Driver.cpp
    cfe/trunk/lib/Driver/HostInfo.cpp
    cfe/trunk/lib/Driver/ToolChains.cpp
    cfe/trunk/lib/Driver/ToolChains.h

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

==============================================================================
--- cfe/trunk/include/clang/Driver/HostInfo.h (original)
+++ cfe/trunk/include/clang/Driver/HostInfo.h Mon Mar 30 16:06:03 2009
@@ -67,6 +67,8 @@
 
 const HostInfo *createDarwinHostInfo(const Driver &D, const char *Arch, 
                                      const char *Platform, const char *OS);
+const HostInfo *createFreeBSDHostInfo(const Driver &D, const char *Arch, 
+                                      const char *Platform, const char *OS);
 const HostInfo *createUnknownHostInfo(const Driver &D, const char *Arch, 
                                       const char *Platform, const char *OS);
 

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

==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Mon Mar 30 16:06:03 2009
@@ -999,6 +999,9 @@
   if (memcmp(&OS[0], "darwin", 6) == 0)
     return createDarwinHostInfo(*this, Arch.c_str(), Platform.c_str(), 
                                 OS.c_str());
+  if (memcmp(&OS[0], "freebsd", 7) == 0)
+    return createFreeBSDHostInfo(*this, Arch.c_str(), Platform.c_str(), 
+                                 OS.c_str());
     
   return createUnknownHostInfo(*this, Arch.c_str(), Platform.c_str(), 
                                OS.c_str());

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

==============================================================================
--- cfe/trunk/lib/Driver/HostInfo.cpp (original)
+++ cfe/trunk/lib/Driver/HostInfo.cpp Mon Mar 30 16:06:03 2009
@@ -205,6 +205,68 @@
   return TC;
 }
 
+// FreeBSD Host Info
+
+/// FreeBSDHostInfo -  Similar to UnknownHostInfo, but doesn't depend on
+class FreeBSDHostInfo : public HostInfo {
+  /// Cache of tool chains we have created.
+  mutable llvm::StringMap<ToolChain*> ToolChains;
+
+public:
+  FreeBSDHostInfo(const Driver &D, const char *Arch, 
+                  const char *Platform, const char *OS);
+  ~FreeBSDHostInfo();
+
+  virtual bool useDriverDriver() const;
+
+  virtual types::ID lookupTypeForExtension(const char *Ext) const {
+    return types::lookupTypeForExtension(Ext);
+  }
+
+  virtual ToolChain *getToolChain(const ArgList &Args, 
+                                  const char *ArchName) const;
+};
+
+FreeBSDHostInfo::FreeBSDHostInfo(const Driver &D, const char *Arch, 
+                                 const char *Platform, const char *OS) 
+  : HostInfo(D, Arch, Platform, OS) {
+}
+
+FreeBSDHostInfo::~FreeBSDHostInfo() {
+  for (llvm::StringMap<ToolChain*>::iterator
+         it = ToolChains.begin(), ie = ToolChains.end(); it != ie; ++it)
+    delete it->second;
+}
+
+bool FreeBSDHostInfo::useDriverDriver() const { 
+  return false;
+}
+
+ToolChain *FreeBSDHostInfo::getToolChain(const ArgList &Args, 
+                                         const char *ArchName) const {
+  bool Lib32 = false;
+
+  assert(!ArchName && 
+         "Unexpected arch name on platform without driver driver support.");
+  
+  // On x86_64 we need to be able to compile 32-bits binaries as well.
+  // Compiling 64-bit binaries on i386 is not supported. We don't have a
+  // lib64.
+  ArchName = getArchName().c_str();
+  if (Args.hasArg(options::OPT_m32) && getArchName() == "x86_64") {
+    ArchName = "i386";
+    Lib32 = true;
+  } 
+  
+  ToolChain *&TC = ToolChains[ArchName];
+  if (!TC)
+    TC = new toolchains::FreeBSD(*this, ArchName, 
+                                 getPlatformName().c_str(), 
+                                 getOSName().c_str(), Lib32);
+
+  return TC;
+}
+
 }
 
 const HostInfo *clang::driver::createDarwinHostInfo(const Driver &D,
@@ -214,6 +276,13 @@
   return new DarwinHostInfo(D, Arch, Platform, OS);
 }
 
+const HostInfo *clang::driver::createFreeBSDHostInfo(const Driver &D,
+                                                     const char *Arch, 
+                                                     const char *Platform, 
+                                                     const char *OS) {
+  return new FreeBSDHostInfo(D, Arch, Platform, OS);
+}
+
 const HostInfo *clang::driver::createUnknownHostInfo(const Driver &D,
                                                      const char *Arch, 
                                                      const char *Platform, 

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

==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Mon Mar 30 16:06:03 2009
@@ -367,3 +367,32 @@
 DerivedArgList *Generic_GCC::TranslateArgs(InputArgList &Args) const {
   return new DerivedArgList(Args, true);
 }
+
+/// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly.
+
+FreeBSD::FreeBSD(const HostInfo &Host, const char *Arch, 
+                 const char *Platform, const char *OS, bool Lib32)
+  : Generic_GCC(Host, Arch, Platform, OS) {
+  if (Lib32)
+    getFilePaths().push_back(getHost().getDriver().Dir + "/../lib32");
+  else
+    getFilePaths().push_back(getHost().getDriver().Dir + "/../lib");
+}
+
+Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
+  Action::ActionClass Key;
+  if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getArchName()))
+    Key = Action::AnalyzeJobClass;
+  else
+    Key = JA.getKind();
+
+  Tool *&T = Tools[Key];
+  if (!T) {
+    switch (Key) {
+    default:
+      T = &Generic_GCC::SelectTool(C, JA);
+    }
+  }
+
+  return *T;
+}

Modified: cfe/trunk/lib/Driver/ToolChains.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.h?rev=68061&r1=68060&r2=68061&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.h (original)
+++ cfe/trunk/lib/Driver/ToolChains.h Mon Mar 30 16:06:03 2009
@@ -26,6 +26,7 @@
   /// all subcommands; this relies on gcc translating the majority of
   /// command line options.
 class VISIBILITY_HIDDEN Generic_GCC : public ToolChain {
+protected:
   mutable llvm::DenseMap<unsigned, Tool*> Tools;
 
 public:
@@ -107,6 +108,14 @@
   virtual const char *GetDefaultRelocationModel() const { return "pic"; }
 };
 
+class VISIBILITY_HIDDEN FreeBSD : public Generic_GCC {
+public:
+  FreeBSD(const HostInfo &Host, const char *Arch, const char *Platform, 
+          const char *OS, bool Lib32);
+
+  virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
+};
+
 } // end namespace toolchains
 } // end namespace driver
 } // end namespace clang





More information about the cfe-commits mailing list