[cfe-commits] r38972 - in /cfe/cfe/trunk/Driver: Targets.cpp clang.cpp clang.h

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:26:23 PDT 2007


Author: sabre
Date: Wed Jul 11 11:26:23 2007
New Revision: 38972

URL: http://llvm.org/viewvc/llvm-project?rev=38972&view=rev
Log:
Add Targets.cpp, which implements the -arch command line option in terms of
TargetInfo.

Added:
    cfe/cfe/trunk/Driver/Targets.cpp   (with props)
Modified:
    cfe/cfe/trunk/Driver/clang.cpp
    cfe/cfe/trunk/Driver/clang.h

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

==============================================================================
--- cfe/cfe/trunk/Driver/Targets.cpp (added)
+++ cfe/cfe/trunk/Driver/Targets.cpp Wed Jul 11 11:26:23 2007
@@ -0,0 +1,143 @@
+//===--- Targets.cpp - Implement -arch option and targets -----------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Chris Lattner and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements the -arch command line option and creates a TargetInfo
+// that represents them.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/TargetInfo.h"
+#include "llvm/Support/CommandLine.h"
+using namespace llvm;
+using namespace clang;
+
+/// Note: a hard coded list of targets is clearly silly, these should be
+/// dynamicly registered and loadable with "-load".
+enum SupportedTargets {
+  target_ppc, target_ppc64,
+  target_i386, target_x86_64,
+  target_linux_i386
+};
+
+static cl::list<SupportedTargets>
+Archs("arch", cl::desc("Architectures to compile for"),
+      cl::values(clEnumValN(target_ppc,       "ppc",   "32-bit Darwin PowerPC"),
+                 clEnumValN(target_ppc64,     "ppc64", "64-bit Darwin PowerPC"),
+                 clEnumValN(target_i386,      "i386",  "32-bit Darwin X86"),
+                 clEnumValN(target_x86_64,    "x86_64","64-bit Darwin X86"),
+                 clEnumValN(target_linux_i386,"linux", "Linux i386"),
+                 clEnumValEnd));
+
+//===----------------------------------------------------------------------===//
+//  Common code shared among the Darwin targets.
+//===----------------------------------------------------------------------===//
+
+namespace {
+class DarwinTargetInfo : public TargetInfoImpl {
+public:
+  
+  // nothing so far.
+};
+} // end anonymous namespace.
+
+
+//===----------------------------------------------------------------------===//
+// Specific target implementations.
+//===----------------------------------------------------------------------===//
+
+namespace {
+class DarwinPPCTargetInfo : public DarwinTargetInfo {
+public:
+  // nothing so far.
+};
+} // end anonymous namespace.
+
+namespace {
+class DarwinPPC64TargetInfo : public DarwinTargetInfo {
+public:
+    // nothing so far.
+};
+} // end anonymous namespace.
+
+namespace {
+class DarwinI386TargetInfo : public DarwinTargetInfo {
+public:
+    // nothing so far.
+};
+} // end anonymous namespace.
+
+namespace {
+class DarwinX86_64TargetInfo : public DarwinTargetInfo {
+public:
+    // nothing so far.
+};
+} // end anonymous namespace.
+
+namespace {
+class LinuxTargetInfo : public DarwinTargetInfo {
+public:
+  LinuxTargetInfo() {
+    // Note: I have no idea if this is right, just for testing.
+    WCharWidth = 2;
+  }
+};
+} // end anonymous namespace.
+
+
+//===----------------------------------------------------------------------===//
+// Driver code
+//===----------------------------------------------------------------------===//
+
+/// CreateTarget - Create the TargetInfoImpl object for the specified target
+/// enum value.
+static TargetInfoImpl *CreateTarget(SupportedTargets T) {
+  switch (T) {
+  default: assert(0 && "Unknown target!");
+  case target_ppc:        return new DarwinPPCTargetInfo();
+  case target_ppc64:      return new DarwinPPC64TargetInfo();
+  case target_i386:       return new DarwinI386TargetInfo();
+  case target_x86_64:     return new DarwinX86_64TargetInfo();
+  case target_linux_i386: return new LinuxTargetInfo();
+  }
+}
+
+/// CreateTargetInfo - Return the set of target info objects as specified by
+/// the -arch command line option.
+TargetInfo *clang::CreateTargetInfo(Diagnostic &Diags) {
+  // If the user didn't specify at least one architecture, auto-sense the
+  // current host.  TODO: This is a hack. :)
+  if (Archs.empty()) {
+#ifndef __APPLE__
+    // Assume non-apple = linux.
+    Archs.push_back(target_linux_i386);
+#elif (defined(__POWERPC__) || defined (__ppc__) || defined(_POWER)) && \
+      defined(__ppc64__)
+    Archs.push_back(target_ppc64);
+#elif defined(__POWERPC__) || defined (__ppc__) || defined(_POWER)
+    Archs.push_back(target_ppc);
+#elif defined(__x86_64__)
+    Archs.push_back(target_x86_64);
+#elif defined(__i386__) || defined(i386) || defined(_M_IX86)
+    Archs.push_back(target_i386);
+#else
+    // Don't know what this is!
+    return 0;
+#endif
+  }
+
+  // Create the primary target and target info.
+  TargetInfo *TI = new TargetInfo(CreateTarget(Archs[0]), &Diags);
+  
+  // Add all secondary targets.
+  for (unsigned i = 1, e = Archs.size(); i != e; ++i)
+    TI->AddSecondaryTarget(CreateTarget(Archs[i]));
+  return TI;
+}

Propchange: cfe/cfe/trunk/Driver/Targets.cpp

------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/cfe/trunk/Driver/Targets.cpp

------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: cfe/cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Driver/clang.cpp?rev=38972&r1=38971&r2=38972&view=diff

==============================================================================
--- cfe/cfe/trunk/Driver/clang.cpp (original)
+++ cfe/cfe/trunk/Driver/clang.cpp Wed Jul 11 11:26:23 2007
@@ -678,6 +678,15 @@
   Options.DollarIdents = Options.Digraphs = 1;
   Options.ObjC1 = Options.ObjC2 = 1;
 
+  // Get information about the targets being compiled for.  Note that this
+  // pointer and the TargetInfoImpl objects are never deleted by this toy
+  // driver.
+  TargetInfo *Target = CreateTargetInfo(OurDiagnostics);
+  if (Target == 0) {
+    std::cerr << "Sorry, don't know what target this is, please use -arch.\n";
+    return 1;
+  }
+  
   // Create a file manager object to provide access to and cache the filesystem.
   FileManager FileMgr;
   

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

==============================================================================
--- cfe/cfe/trunk/Driver/clang.h (original)
+++ cfe/cfe/trunk/Driver/clang.h Wed Jul 11 11:26:23 2007
@@ -19,6 +19,8 @@
 class Preprocessor;
 class LangOptions;
 class Action;
+class TargetInfo;
+class Diagnostic;
 
 /// DoPrintPreprocessedInput - Implement -E mode.
 void DoPrintPreprocessedInput(unsigned MainFileID, Preprocessor &PP,
@@ -28,6 +30,10 @@
 /// implements the -parse-print-callbacks option.
 Action *CreatePrintParserActionsAction();
 
+/// CreateTargetInfo - Return the set of target info objects as specified by
+/// the -arch command line option.
+TargetInfo *CreateTargetInfo(Diagnostic &Diags);
+
 }  // end namespace clang
 }  // end namespace llvm
 





More information about the cfe-commits mailing list