llvmc: remove dynamic plugins.
authorMikhail Glushenkov <foldr@codedgers.com>
Sun, 15 Aug 2010 07:07:12 +0000 (07:07 +0000)
committerMikhail Glushenkov <foldr@codedgers.com>
Sun, 15 Aug 2010 07:07:12 +0000 (07:07 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111094 91177308-0d34-0410-b5e6-96231b3b80d8

32 files changed:
Makefile
Makefile.rules
autoconf/configure.ac
include/llvm/CompilerDriver/AutoGenerated.h [new file with mode: 0644]
include/llvm/CompilerDriver/Common.td
include/llvm/CompilerDriver/ForceLinkage.h [deleted file]
include/llvm/CompilerDriver/ForceLinkageMacros.h [deleted file]
include/llvm/CompilerDriver/Main.h [new file with mode: 0644]
include/llvm/CompilerDriver/Main.inc
include/llvm/CompilerDriver/Plugin.h [deleted file]
lib/CompilerDriver/Main.cpp
lib/CompilerDriver/Makefile
lib/CompilerDriver/Plugin.cpp [deleted file]
tools/llvmc/CMakeLists.txt
tools/llvmc/Makefile
tools/llvmc/driver/Main.cpp [deleted file]
tools/llvmc/driver/Makefile [deleted file]
tools/llvmc/plugins/Base/Base.td.in [deleted file]
tools/llvmc/plugins/Base/Hooks.cpp [deleted file]
tools/llvmc/plugins/Base/Makefile [deleted file]
tools/llvmc/plugins/Base/PluginMain.cpp [deleted file]
tools/llvmc/plugins/Clang/Clang.td [deleted file]
tools/llvmc/plugins/Clang/Makefile [deleted file]
tools/llvmc/plugins/Clang/PluginMain.cpp [deleted file]
tools/llvmc/plugins/Makefile [deleted file]
tools/llvmc/src/AutoGenerated.td [new file with mode: 0644]
tools/llvmc/src/Base.td.in [new file with mode: 0644]
tools/llvmc/src/Clang.td [new file with mode: 0644]
tools/llvmc/src/Hooks.cpp [new file with mode: 0644]
tools/llvmc/src/Main.cpp [new file with mode: 0644]
tools/llvmc/src/Makefile [new file with mode: 0644]
utils/TableGen/LLVMCConfigurationEmitter.cpp

index d810b5f681a1f35aa63f06ba6d0b1d36ceac0a34..ae650b7f2d938873675a892e84ae54854099ae68 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -170,7 +170,7 @@ FilesToConfig := \
   include/llvm/Config/AsmParsers.def \
   include/llvm/Config/Disassemblers.def \
   include/llvm/System/DataTypes.h \
-  tools/llvmc/plugins/Base/Base.td
+  tools/llvmc/src/Base.td
 FilesToConfigPATH  := $(addprefix $(LLVM_OBJ_ROOT)/,$(FilesToConfig))
 
 all-local:: $(FilesToConfigPATH)
index 056a0ea3eff5ce47b38e293bb0b959b472540c2b..2e14094b3a1872fb02d76d2613cb5f9504a1cc0d 100644 (file)
@@ -196,57 +196,15 @@ install-local:: all-local
 install-bytecode:: install-bytecode-local
 
 ###############################################################################
-# LLVMC: Provide rules for compiling llvmc plugins
+# LLVMC: Provide rules for compiling llvmc-based driver
 ###############################################################################
 
-ifdef LLVMC_PLUGIN
-
-LIBRARYNAME := $(patsubst %,plugin_llvmc_%,$(LLVMC_PLUGIN))
-CPP.Flags += -DLLVMC_PLUGIN_NAME=$(LLVMC_PLUGIN)
-
-ifeq ($(ENABLE_LLVMC_DYNAMIC),1)
-  LD.Flags += -lCompilerDriver
-endif
-
-# Build a dynamic library if the user runs `make` directly from the plugin
-# directory.
-ifndef LLVMC_BUILTIN_PLUGIN
-  LOADABLE_MODULE = 1
-endif
-
-# TableGen stuff...
-ifneq ($(BUILT_SOURCES),)
-  LLVMC_BUILD_AUTOGENERATED_INC=1
-endif
-
-endif # LLVMC_PLUGIN
-
 ifdef LLVMC_BASED_DRIVER
 
 TOOLNAME = $(LLVMC_BASED_DRIVER)
 
-ifeq ($(ENABLE_LLVMC_DYNAMIC),1)
-  LD.Flags += -lCompilerDriver
-else
-  LLVMLIBS = CompilerDriver.a
-  LINK_COMPONENTS = support system
-endif
-
-# Preprocessor magic that generates references to static variables in built-in
-# plugins.
-ifneq ($(LLVMC_BUILTIN_PLUGINS),)
-
-USEDLIBS += $(patsubst %,plugin_llvmc_%.a,$(LLVMC_BUILTIN_PLUGINS))
-
-LLVMC_BUILTIN_PLUGINS.pre := \
-  $(patsubst %,-DLLVMC_BUILTIN_PLUGIN_%=, \
-    1 2 3 4 5 6 7 8 9 10)
-
-CPP.Flags += \
-  $(filter-out $(LLVMC_BUILTIN_PLUGINS.pre) $(LLVMC_BUILTIN_PLUGINS), \
-    $(join $(LLVMC_BUILTIN_PLUGINS.pre), $(LLVMC_BUILTIN_PLUGINS)))
-
-endif
+LLVMLIBS = CompilerDriver.a
+LINK_COMPONENTS = support system
 
 endif # LLVMC_BASED_DRIVER
 
@@ -1601,7 +1559,7 @@ ifdef TARGET
 TABLEGEN_INC_FILES_COMMON = 1
 endif
 
-ifdef LLVMC_BUILD_AUTOGENERATED_INC
+ifdef LLVMC_BASED_DRIVER
 TABLEGEN_INC_FILES_COMMON = 1
 endif
 
@@ -1725,20 +1683,26 @@ clean-local::
 
 endif # TARGET
 
-ifdef LLVMC_BUILD_AUTOGENERATED_INC
+ifdef LLVMC_BASED_DRIVER
+
+TDSrc := $(sort $(strip $(wildcard $(PROJ_SRC_DIR)/*.td)) \
+               $(strip $(wildcard $(PROJ_OBJ_DIR)/*.td)))
 
-LLVMCPluginSrc := $(sort $(strip $(wildcard $(PROJ_SRC_DIR)/*.td)) \
-       $(strip $(wildcard $(PROJ_OBJ_DIR)/*.td)))
+TDCommon := $(strip $(wildcard \
+               $(LLVM_SRC_ROOT)/include/llvm/CompilerDriver/*.td))
 
-TDFiles := $(LLVMCPluginSrc) \
-       $(strip $(wildcard $(LLVM_SRC_ROOT)/include/llvm/CompilerDriver/*.td))
+TDFiles := $(TDSrc) $(TDCommon)
 
-$(ObjDir)/AutoGenerated.inc.tmp: $(LLVMCPluginSrc) $(ObjDir)/.dir \
-                               $(TBLGEN) $(TD_COMMON)
-       $(Echo) "Building LLVMC configuration library with tblgen"
+$(INCTMPFiles) : $(TBLGEN) $(TDFiles)
+
+$(ObjDir)/%.inc.tmp: %.td $(ObjDir)/.dir
+       $(Echo) "Building LLVMC compilation graph description with tblgen"
        $(Verb) $(TableGen) -gen-llvmc -o $(call SYSPATH, $@) $<
 
-endif # LLVMC_BUILD_AUTOGENERATED_INC
+clean-local::
+       -$(Verb) $(RM) -f $(INCFiles)
+
+endif # LLVMC_BASED_DRIVER
 
 ###############################################################################
 # OTHER RULES: Other rules needed
index 7211fe1972a95ef63987b4898bfbd15ca44f55d0..8a42d326666651a17062705f5ced0294d11637ff 100644 (file)
@@ -858,35 +858,6 @@ AC_ARG_ENABLE(libffi,AS_HELP_STRING(
   esac],
   llvm_cv_enable_libffi=no)
 
-dnl Only Windows needs dynamic libCompilerDriver to support plugins.
-if test "$llvm_cv_os_type" = "Win32" ; then
-   llvmc_dynamic="yes"
-else
-   llvmc_dynamic="no"
-fi
-
-dnl --enable-llvmc-dynamic : should LLVMC link libCompilerDriver dynamically?
-AC_ARG_ENABLE(llvmc-dynamic,AS_HELP_STRING(
---enable-llvmc-dynamic,
-[Link LLVMC dynamically (default is NO, unless on Win32)]),,
-enableval=$llvmc_dynamic)
-if test ${enableval} = "yes" && test "$ENABLE_PIC" -eq 1 ; then
-   AC_SUBST(ENABLE_LLVMC_DYNAMIC,[[ENABLE_LLVMC_DYNAMIC=1]])
-else
-   AC_SUBST(ENABLE_LLVMC_DYNAMIC,[[]])
-fi
-
-dnl --enable-llvmc-dynamic-plugins : should LLVMC support dynamic plugins?
-AC_ARG_ENABLE(llvmc-dynamic-plugins,AS_HELP_STRING(
---enable-llvmc-dynamic-plugins,
-[Enable dynamic LLVMC plugins (default is YES)]),,
-enableval=yes)
-if test ${enableval} = "yes" ; then
-   AC_SUBST(ENABLE_LLVMC_DYNAMIC_PLUGINS,[[ENABLE_LLVMC_DYNAMIC_PLUGINS=1]])
-else
-   AC_SUBST(ENABLE_LLVMC_DYNAMIC_PLUGINS,[[]])
-fi
-
 dnl===-----------------------------------------------------------------------===
 dnl===
 dnl=== SECTION 4: Check for programs we need and that they are the right version
@@ -1601,7 +1572,7 @@ dnl Configure the RPM spec file for LLVM
 AC_CONFIG_FILES([llvm.spec])
 
 dnl Configure llvmc's Base plugin
-AC_CONFIG_FILES([tools/llvmc/plugins/Base/Base.td])
+AC_CONFIG_FILES([tools/llvmc/src/Base.td])
 
 dnl Do the first stage of configuration for llvm-config.in.
 AC_CONFIG_FILES([tools/llvm-config/llvm-config.in])
diff --git a/include/llvm/CompilerDriver/AutoGenerated.h b/include/llvm/CompilerDriver/AutoGenerated.h
new file mode 100644 (file)
index 0000000..7b926c6
--- /dev/null
@@ -0,0 +1,40 @@
+//===--- AutoGenerated.h - The LLVM Compiler Driver -------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open
+// Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//  Interface to the autogenerated driver code.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_INCLUDE_COMPILER_DRIVER_AUTOGENERATED_H
+#define LLVM_INCLUDE_COMPILER_DRIVER_AUTOGENERATED_H
+
+namespace llvmc {
+  class LanguageMap;
+  class CompilationGraph;
+
+  namespace autogenerated {
+
+    int PreprocessOptions();
+    int PopulateLanguageMap(LanguageMap& langMap);
+    int PopulateCompilationGraph(CompilationGraph& graph);
+
+    inline int RunInitialization (LanguageMap& M, CompilationGraph& G) {
+      if (int ret = PreprocessOptions())
+        return ret;
+      if (int ret = PopulateLanguageMap(M))
+        return ret;
+      if (int ret = PopulateCompilationGraph(G))
+        return ret;
+
+      return 0;
+    }
+  }
+}
+
+#endif // LLVM_INCLUDE_COMPILER_DRIVER_AUTOGENERATED_H
index 6527ab5d4f12be61c9116b42bc5cd2f85d4eb703..d378bb74d22ffb9d10531621f01f8075dc329eab 100644 (file)
@@ -40,7 +40,6 @@ def prefix_list_option;
 
 // Possible option properties.
 
-def extern;
 def help;
 def hidden;
 def init;
@@ -101,11 +100,6 @@ def dec_weight;
 // Empty DAG marker.
 def empty_dag_marker;
 
-// Used to specify plugin priority.
-class PluginPriority<int p> {
-      int priority = p;
-}
-
 // Option list - a single place to specify options.
 class OptionList<list<dag> l> {
       list<dag> options = l;
diff --git a/include/llvm/CompilerDriver/ForceLinkage.h b/include/llvm/CompilerDriver/ForceLinkage.h
deleted file mode 100644 (file)
index 830c04e..0000000
+++ /dev/null
@@ -1,122 +0,0 @@
-//===--- ForceLinkage.h - The LLVM Compiler Driver --------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open
-// Source License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-//  A bit of preprocessor magic to force references to static libraries. Needed
-//  because plugin initialization is done via static variables.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_INCLUDE_COMPILER_DRIVER_FORCE_LINKAGE_H
-#define LLVM_INCLUDE_COMPILER_DRIVER_FORCE_LINKAGE_H
-
-#include "llvm/CompilerDriver/ForceLinkageMacros.h"
-
-namespace llvmc {
-
-// Declare all ForceLinkage$(PluginName) functions.
-
-#ifdef LLVMC_BUILTIN_PLUGIN_1
-      LLVMC_FORCE_LINKAGE_DECL(LLVMC_BUILTIN_PLUGIN_1);
-#endif
-
-#ifdef LLVMC_BUILTIN_PLUGIN_2
-      LLVMC_FORCE_LINKAGE_DECL(LLVMC_BUILTIN_PLUGIN_2);
-#endif
-
-#ifdef LLVMC_BUILTIN_PLUGIN_3
-      LLVMC_FORCE_LINKAGE_DECL(LLVMC_BUILTIN_PLUGIN_3);
-#endif
-
-#ifdef LLVMC_BUILTIN_PLUGIN_4
-      LLVMC_FORCE_LINKAGE_DECL(LLVMC_BUILTIN_PLUGIN_4);
-#endif
-
-#ifdef LLVMC_BUILTIN_PLUGIN_5
-      LLVMC_FORCE_LINKAGE_DECL(LLVMC_BUILTIN_PLUGIN_5);
-#endif
-
-#ifdef LLVMC_BUILTIN_PLUGIN_6
-      LLVMC_FORCE_LINKAGE_DECL(LLVMC_BUILTIN_PLUGIN_6);
-#endif
-
-#ifdef LLVMC_BUILTIN_PLUGIN_7
-      LLVMC_FORCE_LINKAGE_DECL(LLVMC_BUILTIN_PLUGIN_7);
-#endif
-
-#ifdef LLVMC_BUILTIN_PLUGIN_8
-      LLVMC_FORCE_LINKAGE_DECL(LLVMC_BUILTIN_PLUGIN_8);
-#endif
-
-#ifdef LLVMC_BUILTIN_PLUGIN_9
-      LLVMC_FORCE_LINKAGE_DECL(LLVMC_BUILTIN_PLUGIN_9);
-#endif
-
-#ifdef LLVMC_BUILTIN_PLUGIN_10
-      LLVMC_FORCE_LINKAGE_DECL(LLVMC_BUILTIN_PLUGIN_10);
-#endif
-
-namespace force_linkage {
-
-  struct LinkageForcer {
-
-    LinkageForcer() {
-
-// Call all ForceLinkage$(PluginName) functions.
-#ifdef LLVMC_BUILTIN_PLUGIN_1
-      LLVMC_FORCE_LINKAGE_CALL(LLVMC_BUILTIN_PLUGIN_1);
-#endif
-
-#ifdef LLVMC_BUILTIN_PLUGIN_2
-      LLVMC_FORCE_LINKAGE_CALL(LLVMC_BUILTIN_PLUGIN_2);
-#endif
-
-#ifdef LLVMC_BUILTIN_PLUGIN_3
-      LLVMC_FORCE_LINKAGE_CALL(LLVMC_BUILTIN_PLUGIN_3);
-#endif
-
-#ifdef LLVMC_BUILTIN_PLUGIN_4
-      LLVMC_FORCE_LINKAGE_CALL(LLVMC_BUILTIN_PLUGIN_4);
-#endif
-
-#ifdef LLVMC_BUILTIN_PLUGIN_5
-      LLVMC_FORCE_LINKAGE_CALL(LLVMC_BUILTIN_PLUGIN_5);
-#endif
-
-#ifdef LLVMC_BUILTIN_PLUGIN_6
-      LLVMC_FORCE_LINKAGE_CALL(LLVMC_BUILTIN_PLUGIN_6);
-#endif
-
-#ifdef LLVMC_BUILTIN_PLUGIN_7
-      LLVMC_FORCE_LINKAGE_CALL(LLVMC_BUILTIN_PLUGIN_7);
-#endif
-
-#ifdef LLVMC_BUILTIN_PLUGIN_8
-      LLVMC_FORCE_LINKAGE_CALL(LLVMC_BUILTIN_PLUGIN_8);
-#endif
-
-#ifdef LLVMC_BUILTIN_PLUGIN_9
-      LLVMC_FORCE_LINKAGE_CALL(LLVMC_BUILTIN_PLUGIN_9);
-#endif
-
-#ifdef LLVMC_BUILTIN_PLUGIN_10
-      LLVMC_FORCE_LINKAGE_CALL(LLVMC_BUILTIN_PLUGIN_10);
-#endif
-
-    }
-  };
-} // End namespace force_linkage.
-
-// The only externally used bit.
-void ForceLinkage() {
-  force_linkage::LinkageForcer dummy;
-}
-
-} // End namespace llvmc.
-
-#endif // LLVM_INCLUDE_COMPILER_DRIVER_FORCE_LINKAGE_H
diff --git a/include/llvm/CompilerDriver/ForceLinkageMacros.h b/include/llvm/CompilerDriver/ForceLinkageMacros.h
deleted file mode 100644 (file)
index 8862b00..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-//===--- ForceLinkageMacros.h - The LLVM Compiler Driver --------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open
-// Source License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-//  Preprocessor magic that forces references to static libraries - common
-//  macros used by both driver and plugins.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_INCLUDE_COMPILER_DRIVER_FORCE_LINKAGE_MACROS_H
-#define LLVM_INCLUDE_COMPILER_DRIVER_FORCE_LINKAGE_MACROS_H
-
-#define LLVMC_FORCE_LINKAGE_PREFIX(PluginName) ForceLinkage ## PluginName
-
-#define LLVMC_FORCE_LINKAGE_FUN(PluginName) \
-  LLVMC_FORCE_LINKAGE_PREFIX(PluginName)
-
-#define LLVMC_FORCE_LINKAGE_DECL(PluginName) \
-  void LLVMC_FORCE_LINKAGE_FUN(PluginName) ()
-
-#define LLVMC_FORCE_LINKAGE_CALL(PluginName) \
-  LLVMC_FORCE_LINKAGE_FUN(PluginName) ()
-
-#endif // LLVM_INCLUDE_COMPILER_DRIVER_FORCE_LINKAGE_MACROS_H
diff --git a/include/llvm/CompilerDriver/Main.h b/include/llvm/CompilerDriver/Main.h
new file mode 100644 (file)
index 0000000..d136a5d
--- /dev/null
@@ -0,0 +1,21 @@
+//===--- Main.h - The LLVM Compiler Driver ----------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open
+// Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//  Entry point for the driver executable.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_INCLUDE_COMPILER_DRIVER_MAIN_H
+#define LLVM_INCLUDE_COMPILER_DRIVER_MAIN_H
+
+namespace llvmc {
+  int Main(int argc, char** argv);
+}
+
+#endif // LLVM_INCLUDE_COMPILER_DRIVER_MAIN_H
index 71bb8cb3bf733e931dc8755318b439b3b473a9fe..41640437de8964709b3b02d277c5bedce7b4c3ab 100644 (file)
@@ -7,26 +7,16 @@
 //
 //===----------------------------------------------------------------------===//
 //
-//  This tool provides a single point of access to the LLVM
-//  compilation tools.  It has many options. To discover the options
-//  supported please refer to the tools' manual page or run the tool
-//  with the -help option.
-//
-//  This file provides the default entry point for the driver executable.
+//  Default main() for the driver executable.
 //
 //===----------------------------------------------------------------------===//
 
 #ifndef LLVM_INCLUDE_COMPILER_DRIVER_MAIN_INC
 #define LLVM_INCLUDE_COMPILER_DRIVER_MAIN_INC
 
-#include "llvm/CompilerDriver/ForceLinkage.h"
-
-namespace llvmc {
-  int Main(int argc, char** argv);
-}
+#include "llvm/CompilerDriver/Main.h"
 
 int main(int argc, char** argv) {
-  llvmc::ForceLinkage();
   return llvmc::Main(argc, argv);
 }
 
diff --git a/include/llvm/CompilerDriver/Plugin.h b/include/llvm/CompilerDriver/Plugin.h
deleted file mode 100644 (file)
index 75fd916..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-//===--- Plugin.h - The LLVM Compiler Driver --------------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open
-// Source License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-//  Plugin support for llvmc.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_INCLUDE_COMPILER_DRIVER_PLUGIN_H
-#define LLVM_INCLUDE_COMPILER_DRIVER_PLUGIN_H
-
-#include "llvm/Support/Registry.h"
-
-namespace llvmc {
-
-  class LanguageMap;
-  class CompilationGraph;
-
-  /// BasePlugin - An abstract base class for all LLVMC plugins.
-  struct BasePlugin {
-
-    /// Priority - Plugin priority, useful for handling dependencies
-    /// between plugins. Plugins with lower priorities are loaded
-    /// first.
-    virtual int Priority() const { return 0; }
-
-    /// PreprocessOptions - The auto-generated function that performs various
-    /// consistency checks on options (like ensuring that -O2 and -O3 are not
-    /// used together).
-    virtual int PreprocessOptions() const = 0;
-
-    /// PopulateLanguageMap - The auto-generated function that fills in
-    /// the language map (map from file extensions to language names).
-    virtual int PopulateLanguageMap(LanguageMap&) const = 0;
-
-    /// PopulateCompilationGraph - The auto-generated function that
-    /// populates the compilation graph with nodes and edges.
-    virtual int PopulateCompilationGraph(CompilationGraph&) const = 0;
-
-    /// Needed to avoid a compiler warning.
-    virtual ~BasePlugin() {}
-  };
-
-  typedef llvm::Registry<BasePlugin> PluginRegistry;
-
-  template <class P>
-  struct RegisterPlugin
-    : public PluginRegistry::Add<P> {
-    typedef PluginRegistry::Add<P> Base;
-
-    RegisterPlugin(const char* Name = "Nameless",
-                   const char* Desc = "Auto-generated plugin")
-      : Base(Name, Desc) {}
-  };
-
-
-  /// PluginLoader - Helper class used by the main program for
-  /// lifetime management.
-  struct PluginLoader {
-    PluginLoader();
-    ~PluginLoader();
-
-    /// RunInitialization - Calls PreprocessOptions, PopulateLanguageMap and
-    /// PopulateCompilationGraph methods of all plugins. This populates the
-    /// global language map and the compilation graph.
-    int RunInitialization(LanguageMap& langMap, CompilationGraph& graph) const;
-
-  private:
-    // noncopyable
-    PluginLoader(const PluginLoader& other);
-    const PluginLoader& operator=(const PluginLoader& other);
-  };
-
-}
-
-#endif // LLVM_INCLUDE_COMPILER_DRIVER_PLUGIN_H
index 898f16d515fc98fcc6eae62ffc3846ed63037cad..0a6613aa77a3b4e4d1f172e88b4c4a9da01cad37 100644 (file)
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/CompilerDriver/AutoGenerated.h"
 #include "llvm/CompilerDriver/BuiltinOptions.h"
 #include "llvm/CompilerDriver/CompilationGraph.h"
 #include "llvm/CompilerDriver/Error.h"
-#include "llvm/CompilerDriver/Plugin.h"
 
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/System/Path.h"
@@ -62,7 +62,8 @@ namespace {
     return 0;
   }
 
-  /// BuildTargets - A small wrapper for CompilationGraph::Build. Returns non-zero value
+  /// BuildTargets - A small wrapper for CompilationGraph::Build. Returns
+  /// non-zero value in case of error.
   int BuildTargets(CompilationGraph& graph, const LanguageMap& langMap) {
     int ret;
     sys::Path tempDir;
@@ -87,7 +88,7 @@ void AppendToGlobalTimeLog(const std::string& cmd, double time) {
   *GlobalTimeLog << "# " << cmd << ' ' << time << '\n';
 }
 
-// Sometimes plugins want to condition on the value in argv[0].
+// Sometimes user code wants to access the argv[0] value.
 const char* ProgramName;
 
 int Main(int argc, char** argv) {
@@ -98,11 +99,11 @@ int Main(int argc, char** argv) {
   ProgramName = argv[0];
 
   cl::ParseCommandLineOptions
-    (argc, argv, "LLVM Compiler Driver (Work In Progress)",
+    (argc, argv,
+     /* Overview = */ "LLVM Compiler Driver (Work In Progress)",
      /* ReadResponseFiles = */ false);
 
-  PluginLoader Plugins;
-  if (int ret = Plugins.RunInitialization(langMap, graph))
+  if (int ret = autogenerated::RunInitialization(langMap, graph))
     return ret;
 
   if (CheckGraph) {
index b829f5261c4e3355c6d4b98bdde6ff69dbbe7e55..69c3707780a6596489464d896bccf958cb70773d 100644 (file)
@@ -12,34 +12,7 @@ LEVEL = ../..
 # We don't want this library to appear in `llvm-config --libs` output, so its
 # name doesn't start with "LLVM".
 
-ifeq ($(ENABLE_LLVMC_DYNAMIC),1)
-  LIBRARYNAME = libCompilerDriver
-  LLVMLIBS = LLVMSupport.a LLVMSystem.a
-  LOADABLE_MODULE := 1
-else
-  LIBRARYNAME = CompilerDriver
-  LINK_COMPONENTS = support system
-endif
+LIBRARYNAME = CompilerDriver
+LINK_COMPONENTS = support system
 
 include $(LEVEL)/Makefile.common
-
-ifeq ($(ENABLE_LLVMC_DYNAMIC_PLUGINS), 1)
-    CPP.Flags += -DENABLE_LLVMC_DYNAMIC_PLUGINS
-endif
-
-# Copy libCompilerDriver to the bin dir so that llvmc can find it.
-ifeq ($(ENABLE_LLVMC_DYNAMIC),1)
-
-FullLibName = $(LIBRARYNAME)$(SHLIBEXT)
-
-all-local:: $(ToolDir)/$(FullLibName)
-
-$(ToolDir)/$(FullLibName): $(LibDir)/$(FullLibName) $(ToolDir)/.dir
-       $(Echo) Copying $(BuildMode) Shared Library $(FullLibName) to $@
-       -$(Verb) $(CP) $< $@
-
-clean-local::
-       $(Echo) Removing $(BuildMode) Shared Library $(FullLibName) \
-       from $(ToolDir)
-       -$(Verb) $(RM) -f $(ToolDir)/$(FullLibName)
-endif
diff --git a/lib/CompilerDriver/Plugin.cpp b/lib/CompilerDriver/Plugin.cpp
deleted file mode 100644 (file)
index d520d4f..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-//===--- Plugin.cpp - The LLVM Compiler Driver ------------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open
-// Source License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-//  Plugin support.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/CompilerDriver/Plugin.h"
-#include "llvm/Support/ManagedStatic.h"
-#include "llvm/System/Mutex.h"
-#include <algorithm>
-#include <vector>
-
-namespace {
-
-  // Registry::Add<> does not do lifetime management (probably issues
-  // with static constructor/destructor ordering), so we have to
-  // implement it here.
-  //
-  // All this static registration/life-before-main model seems
-  // unnecessary convoluted to me.
-
-  static bool pluginListInitialized = false;
-  typedef std::vector<const llvmc::BasePlugin*> PluginList;
-  static PluginList Plugins;
-  static llvm::ManagedStatic<llvm::sys::SmartMutex<true> > PluginMutex;
-
-  struct ByPriority {
-    bool operator()(const llvmc::BasePlugin* lhs,
-                    const llvmc::BasePlugin* rhs) {
-      return lhs->Priority() < rhs->Priority();
-    }
-  };
-}
-
-namespace llvmc {
-
-  PluginLoader::PluginLoader() {
-    llvm::sys::SmartScopedLock<true> Lock(*PluginMutex);
-    if (!pluginListInitialized) {
-      for (PluginRegistry::iterator B = PluginRegistry::begin(),
-             E = PluginRegistry::end(); B != E; ++B)
-        Plugins.push_back(B->instantiate());
-      std::sort(Plugins.begin(), Plugins.end(), ByPriority());
-    }
-    pluginListInitialized = true;
-  }
-
-  PluginLoader::~PluginLoader() {
-    llvm::sys::SmartScopedLock<true> Lock(*PluginMutex);
-    if (pluginListInitialized) {
-      for (PluginList::iterator B = Plugins.begin(), E = Plugins.end();
-           B != E; ++B)
-        delete (*B);
-    }
-    pluginListInitialized = false;
-  }
-
-  int PluginLoader::RunInitialization(LanguageMap& langMap,
-                                      CompilationGraph& graph) const
-  {
-    llvm::sys::SmartScopedLock<true> Lock(*PluginMutex);
-    for (PluginList::iterator B = Plugins.begin(), E = Plugins.end();
-         B != E; ++B) {
-      const BasePlugin* BP = *B;
-      if (int ret = BP->PreprocessOptions())
-        return ret;
-      if (int ret = BP->PopulateLanguageMap(langMap))
-        return ret;
-      if (int ret = BP->PopulateCompilationGraph(graph))
-        return ret;
-    }
-
-    return 0;
-  }
-
-}
index bebaaebca8d6c23c3975732b643cc77a052d93e0..10ad5d82009f18ebd4919099d30d86fba7730dc4 100644 (file)
@@ -1,4 +1,4 @@
-# add_subdirectory(driver)
+# add_subdirectory(src)
 
 # TODO: support plugins and user-configured builds.
 # See ./doc/LLVMC-Reference.rst "Customizing LLVMC: the compilation graph"
index df91728ea360251779c0a2b34ae4790c727da6f7..9bcb96c954e1a46faffb2b3425d720f7df2272fa 100644 (file)
@@ -9,9 +9,6 @@
 
 LEVEL = ../..
 
-export LLVMC_BASED_DRIVER_NAME = llvmc
-export LLVMC_BUILTIN_PLUGINS = Base Clang
-
-DIRS = plugins driver
+DIRS = src
 
 include $(LEVEL)/Makefile.common
diff --git a/tools/llvmc/driver/Main.cpp b/tools/llvmc/driver/Main.cpp
deleted file mode 100644 (file)
index b1f5b67..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-//===--- Main.cpp - The LLVM Compiler Driver -------------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open
-// Source License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-//  Just include CompilerDriver/Main.inc.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/CompilerDriver/Main.inc"
diff --git a/tools/llvmc/driver/Makefile b/tools/llvmc/driver/Makefile
deleted file mode 100644 (file)
index 2f3104b..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-##===- tools/llvmc/driver/Makefile -------------------------*- Makefile -*-===##
-#
-#                     The LLVM Compiler Infrastructure
-#
-# This file is distributed under the University of Illinois Open
-# Source License. See LICENSE.TXT for details.
-#
-##===----------------------------------------------------------------------===##
-
-LEVEL = ../../..
-LLVMC_BASED_DRIVER = $(LLVMC_BASED_DRIVER_NAME)
-
-include $(LEVEL)/Makefile.common
diff --git a/tools/llvmc/plugins/Base/Base.td.in b/tools/llvmc/plugins/Base/Base.td.in
deleted file mode 100644 (file)
index a042997..0000000
+++ /dev/null
@@ -1,377 +0,0 @@
-//===- Base.td - LLVMC toolchain descriptions --------------*- tablegen -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file contains compilation graph description used by llvmc.
-//
-//===----------------------------------------------------------------------===//
-
-include "llvm/CompilerDriver/Common.td"
-
-// Options
-
-def OptList : OptionList<[
- (switch_option "emit-llvm",
-    (help "Emit LLVM .ll files instead of native object files")),
- (switch_option "E",
-    (help "Stop after the preprocessing stage, do not run the compiler")),
- (switch_option "fsyntax-only",
-    (help "Stop after checking the input for syntax errors")),
- (switch_option "opt",
-    (help "Enable opt")),
- (switch_option "O0",
-    (help "Turn off optimization"), (zero_or_more)),
- (switch_option "O1",
-    (help "Optimization level 1"), (zero_or_more)),
- (switch_option "O2",
-    (help "Optimization level 2"), (zero_or_more)),
- (switch_option "O3",
-    (help "Optimization level 3"), (zero_or_more)),
- (switch_option "S",
-    (help "Stop after compilation, do not assemble")),
- (switch_option "c",
-    (help "Compile and assemble, but do not link")),
- (switch_option "pthread",
-    (help "Enable threads")),
- (switch_option "m32",
-    (help "Generate code for a 32-bit environment"), (hidden)),
- (switch_option "m64",
-    (help "Generate code for a 64-bit environment"), (hidden)),
- (switch_option "fPIC",
-    (help "Relocation model: PIC"), (hidden)),
- (switch_option "mdynamic-no-pic",
-    (help "Relocation model: dynamic-no-pic"), (hidden)),
- (switch_option "shared",
-     (help "Create a DLL instead of the regular executable")),
- (parameter_option "linker",
-    (help "Choose linker (possible values: gcc, g++)")),
- (parameter_option "mtune",
-    (help "Target a specific CPU type"), (hidden), (forward_not_split)),
-
- // TODO: Add a conditional compilation mechanism to make Darwin-only options
- // like '-arch' really Darwin-only.
-
- (parameter_option "arch",
-    (help "Compile for the specified target architecture"), (hidden)),
- (parameter_option "march",
-    (help "A synonym for -mtune"), (hidden), (forward_not_split)),
- (parameter_option "mcpu",
-    (help "A deprecated synonym for -mtune"), (hidden), (forward_not_split)),
- (switch_option "mfix-and-continue",
-    (help "Needed by gdb to load .o files dynamically"), (hidden)),
- (parameter_option "MF",
-    (help "Specify a file to write dependencies to"), (hidden)),
- (parameter_list_option "MT",
-    (help "Change the name of the rule emitted by dependency generation"),
-    (hidden)),
- (parameter_list_option "include",
-    (help "Include the named file prior to preprocessing")),
- (parameter_list_option "iquote",
-    (help "Search dir only for files requested with #inlcude \"file\""),
-    (hidden)),
- (parameter_list_option "framework",
-    (help "Specifies a framework to link against")),
- (parameter_list_option "weak_framework",
-    (help "Specifies a framework to weakly link against"), (hidden)),
- (parameter_option "filelist", (hidden),
-    (help "Link the files listed in file")),
- (prefix_list_option "F",
-    (help "Add a directory to framework search path")),
- (prefix_list_option "I",
-    (help "Add a directory to include path")),
- (prefix_list_option "D",
-    (help "Define a macro")),
- (parameter_list_option "Xpreprocessor", (hidden),
-    (help "Pass options to preprocessor")),
- (prefix_list_option "Wa,", (comma_separated),
-    (help "Pass options to assembler")),
- (parameter_list_option "Xassembler", (hidden),
-    (help "Pass options to assembler")),
- (prefix_list_option "Wllc,", (comma_separated),
-    (help "Pass options to llc")),
- (prefix_list_option "L",
-    (help "Add a directory to link path")),
- (prefix_list_option "l",
-    (help "Search a library when linking")),
- (prefix_list_option "Wl,",
-    (help "Pass options to linker")),
- (parameter_list_option "Xlinker", (hidden),
-    (help "Pass options to linker")),
- (prefix_list_option "Wo,", (comma_separated),
-    (help "Pass options to opt")),
- (prefix_list_option "m",
-     (help "Enable or disable various extensions (-mmmx, -msse, etc.)"),
-     (hidden)),
- (switch_option "dynamiclib", (hidden),
-     (help "Produce a dynamic library")),
- (switch_option "prebind", (hidden),
-     (help "Prebind all undefined symbols")),
- (switch_option "dead_strip", (hidden),
-     (help "Remove unreachable blocks of code")),
- (switch_option "single_module", (hidden),
-     (help "Build the library so it contains only one module")),
- (parameter_option "install_name", (hidden),
-     (help "File name the library will be installed in")),
- (parameter_option "compatibility_version", (hidden),
-     (help "Compatibility version number")),
- (parameter_option "current_version", (hidden),
-     (help "Current version number"))
-]>;
-
-// Option preprocessor.
-
-def Preprocess : OptionPreprocessor<
-(case (not (any_switch_on ["O0", "O1", "O2", "O3"])),
-           (set_option "O2"),
-      (and (switch_on "O3"), (any_switch_on ["O0", "O1", "O2"])),
-           (unset_option ["O0", "O1", "O2"]),
-      (and (switch_on "O2"), (any_switch_on ["O0", "O1"])),
-           (unset_option ["O0", "O1"]),
-      (switch_on ["O1", "O0"]),
-           (unset_option "O0"))
->;
-
-// Tools
-
-class llvm_gcc_based <string cmd_prefix, string in_lang,
-                      string E_ext, string out_lang> : Tool<
-[(in_language in_lang),
- (out_language "llvm-bitcode"),
- (output_suffix out_lang),
- (command cmd_prefix),
- (actions
-     (case
-         (and (not_empty "o"),
-              (multiple_input_files), (or (switch_on "S"), (switch_on "c"))),
-              (error "cannot specify -o with -c or -S with multiple files"),
-         (switch_on "E"),
-              [(forward "E"), (stop_compilation), (output_suffix E_ext)],
-         (and (switch_on "E"), (empty "o")), (no_out_file),
-         (switch_on ["emit-llvm", "S"]),
-              [(output_suffix "ll"), (stop_compilation)],
-         (switch_on ["emit-llvm", "c"]), (stop_compilation),
-         (switch_on "fsyntax-only"), [(forward "fsyntax-only"),
-                                      (no_out_file), (stop_compilation)],
-         (switch_on ["S", "emit-llvm"]), [(forward "S"), (forward "emit-llvm")],
-         (not (or (switch_on ["S", "emit-llvm"]), (switch_on "fsyntax-only"))),
-             [(append_cmd "-c"), (append_cmd "-emit-llvm")],
-
-         // Forwards
-         (not_empty "Xpreprocessor"), (forward "Xpreprocessor"),
-         (not_empty "include"), (forward "include"),
-         (not_empty "iquote"), (forward "iquote"),
-         (not_empty "save-temps"), (append_cmd "-save-temps"),
-         (not_empty "I"), (forward "I"),
-         (not_empty "F"), (forward "F"),
-         (not_empty "D"), (forward "D"),
-         (not_empty "arch"), (forward "arch"),
-         (not_empty "march"), (forward "march"),
-         (not_empty "mtune"), (forward "mtune"),
-         (not_empty "mcpu"), (forward "mcpu"),
-         (not_empty "m"), (forward "m"),
-         (switch_on "mfix-and-continue"), (forward "mfix-and-continue"),
-         (switch_on "m32"), (forward "m32"),
-         (switch_on "m64"), (forward "m64"),
-         (switch_on "O0"), (forward "O0"),
-         (switch_on "O1"), (forward "O1"),
-         (switch_on "O2"), (forward "O2"),
-         (switch_on "O3"), (forward "O3"),
-         (switch_on "fPIC"), (forward "fPIC"),
-         (switch_on "mdynamic-no-pic"), (forward "mdynamic-no-pic"),
-         (not_empty "MF"), (forward "MF"),
-         (not_empty "MT"), (forward "MT"))),
- (sink)
-]>;
-
-def llvm_gcc_c : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x c", "c", "i", "bc">;
-def llvm_gcc_cpp : llvm_gcc_based<"@LLVMGXXCOMMAND@ -x c++", "c++", "i", "bc">;
-def llvm_gcc_m : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c",
-                                                  "objective-c", "mi", "bc">;
-def llvm_gcc_mxx : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c++",
-                                  "objective-c++", "mi", "bc">;
-
-def llvm_gcc_c_pch : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x c-header",
-                                                      "c-header", "i", "gch">;
-def llvm_gcc_cpp_pch : llvm_gcc_based<"@LLVMGXXCOMMAND@ -x c++-header",
-                                                        "c++-header",
-                                                        "i", "gch">;
-def llvm_gcc_m_pch : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c-header",
-                                                      "objective-c-header",
-                                                      "mi", "gch">;
-def llvm_gcc_mxx_pch
-    : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c++-header",
-                                       "objective-c++-header", "mi", "gch">;
-
-def opt : Tool<
-[(in_language "llvm-bitcode"),
- (out_language "llvm-bitcode"),
- (output_suffix "bc"),
- (actions (case (not_empty "Wo,"), (forward_value "Wo,"),
-                (switch_on "O1"), (forward "O1"),
-                (switch_on "O2"), (forward "O2"),
-                (switch_on "O3"), (forward "O3"))),
- (command "opt -f")
-]>;
-
-def llvm_as : Tool<
-[(in_language "llvm-assembler"),
- (out_language "llvm-bitcode"),
- (output_suffix "bc"),
- (command "llvm-as"),
- (actions (case (switch_on "emit-llvm"), (stop_compilation)))
-]>;
-
-def llvm_gcc_assembler : Tool<
-[(in_language "assembler"),
- (out_language "object-code"),
- (output_suffix "o"),
- (command "@LLVMGCCCOMMAND@ -c -x assembler"),
- (actions (case
-          (switch_on "c"), (stop_compilation),
-          (not_empty "arch"), (forward "arch"),
-          (not_empty "Xassembler"), (forward "Xassembler"),
-          (switch_on "m32"), (forward "m32"),
-          (switch_on "m64"), (forward "m64"),
-          (not_empty "Wa,"), (forward "Wa,")))
-]>;
-
-def llc : Tool<
-[(in_language ["llvm-bitcode", "llvm-assembler"]),
- (out_language "assembler"),
- (output_suffix "s"),
- (command "llc"),
- (actions (case
-          (switch_on "S"), (stop_compilation),
-          (switch_on "O0"), (forward "O0"),
-          (switch_on "O1"), (forward "O1"),
-          (switch_on "O2"), (forward "O2"),
-          (switch_on "O3"), (forward "O3"),
-          (switch_on "fPIC"), (append_cmd "-relocation-model=pic"),
-          (switch_on "mdynamic-no-pic"),
-                     (append_cmd "-relocation-model=dynamic-no-pic"),
-          (not_empty "march"), (forward_as "mtune", "-mcpu"),
-          (not_empty "mtune"), (forward_as "mtune", "-mcpu"),
-          (not_empty "mcpu"), (forward "mcpu"),
-          (not_empty "m"), (forward_transformed_value "m", "ConvertToMAttr"),
-          (not_empty "Wllc,"), (forward_value "Wllc,")))
-]>;
-
-// Base class for linkers
-class llvm_gcc_based_linker <string cmd_prefix, dag on_empty> : Tool<
-[(in_language ["object-code", "static-library"]),
- (out_language "executable"),
- (output_suffix "out"),
- (command cmd_prefix),
- (works_on_empty (case (and (not_empty "filelist"), on_empty), true,
-                       (default), false)),
- (join),
- (actions (case
-          (switch_on "pthread"), (append_cmd "-lpthread"),
-          (not_empty "L"), (forward "L"),
-          (not_empty "F"), (forward "F"),
-          (not_empty "arch"), (forward "arch"),
-          (not_empty "framework"), (forward "framework"),
-          (not_empty "weak_framework"), (forward "weak_framework"),
-          (not_empty "filelist"), (forward "filelist"),
-          (switch_on "m32"), (forward "m32"),
-          (switch_on "m64"), (forward "m64"),
-          (not_empty "l"), (forward "l"),
-          (not_empty "Xlinker"), (forward "Xlinker"),
-          (not_empty "Wl,"), (forward "Wl,"),
-          (switch_on "shared"), (forward "shared"),
-          (switch_on "dynamiclib"), (forward "dynamiclib"),
-          (switch_on "prebind"), (forward "prebind"),
-          (switch_on "dead_strip"), (forward "dead_strip"),
-          (switch_on "single_module"), (forward "single_module"),
-          (not_empty "compatibility_version"),
-                     (forward "compatibility_version"),
-          (not_empty "current_version"), (forward "current_version"),
-          (not_empty "install_name"), (forward "install_name")))
-]>;
-
-// Default linker
-def llvm_gcc_linker : llvm_gcc_based_linker<"@LLVMGCCCOMMAND@",
-    (not (or (parameter_equals "linker", "g++"),
-         (parameter_equals "linker", "c++")))>;
-// Alternative linker for C++
-def llvm_gcc_cpp_linker : llvm_gcc_based_linker<"@LLVMGXXCOMMAND@",
-    (or (parameter_equals "linker", "g++"),
-        (parameter_equals "linker", "c++"))>;
-
-// Language map
-
-def LanguageMap : LanguageMap<
-    [LangToSuffixes<"c++", ["cc", "cp", "cxx", "cpp", "CPP", "c++", "C"]>,
-     LangToSuffixes<"c++-header", ["hpp"]>,
-     LangToSuffixes<"c", ["c"]>,
-     LangToSuffixes<"c-header", ["h"]>,
-     LangToSuffixes<"c-cpp-output", ["i"]>,
-     LangToSuffixes<"objective-c-cpp-output", ["mi"]>,
-     LangToSuffixes<"objective-c++", ["mm"]>,
-     LangToSuffixes<"objective-c++-header", ["hmm"]>,
-     LangToSuffixes<"objective-c", ["m"]>,
-     LangToSuffixes<"objective-c-header", ["hm"]>,
-     LangToSuffixes<"assembler", ["s"]>,
-     LangToSuffixes<"assembler-with-cpp", ["S"]>,
-     LangToSuffixes<"llvm-assembler", ["ll"]>,
-     LangToSuffixes<"llvm-bitcode", ["bc"]>,
-     LangToSuffixes<"object-code", ["o", "*empty*"]>,
-     LangToSuffixes<"static-library", ["a", "lib"]>,
-     LangToSuffixes<"executable", ["out"]>
-     ]>;
-
-// Compilation graph
-
-def CompilationGraph : CompilationGraph<[
-    Edge<"root", "llvm_gcc_c">,
-    Edge<"root", "llvm_gcc_assembler">,
-    Edge<"root", "llvm_gcc_cpp">,
-    Edge<"root", "llvm_gcc_m">,
-    Edge<"root", "llvm_gcc_mxx">,
-    Edge<"root", "llc">,
-
-    Edge<"root", "llvm_gcc_c_pch">,
-    Edge<"root", "llvm_gcc_cpp_pch">,
-    Edge<"root", "llvm_gcc_m_pch">,
-    Edge<"root", "llvm_gcc_mxx_pch">,
-
-    Edge<"llvm_gcc_c", "llc">,
-    Edge<"llvm_gcc_cpp", "llc">,
-    Edge<"llvm_gcc_m", "llc">,
-    Edge<"llvm_gcc_mxx", "llc">,
-    Edge<"llvm_as", "llc">,
-
-    OptionalEdge<"root", "llvm_as",
-                         (case (switch_on "emit-llvm"), (inc_weight))>,
-    OptionalEdge<"llvm_gcc_c", "opt", (case (switch_on "opt"), (inc_weight))>,
-    OptionalEdge<"llvm_gcc_cpp", "opt", (case (switch_on "opt"), (inc_weight))>,
-    OptionalEdge<"llvm_gcc_m", "opt", (case (switch_on "opt"), (inc_weight))>,
-    OptionalEdge<"llvm_gcc_mxx", "opt", (case (switch_on "opt"), (inc_weight))>,
-    OptionalEdge<"llvm_as", "opt", (case (switch_on "opt"), (inc_weight))>,
-    Edge<"opt", "llc">,
-
-    Edge<"llc", "llvm_gcc_assembler">,
-    Edge<"llvm_gcc_assembler", "llvm_gcc_linker">,
-    OptionalEdge<"llvm_gcc_assembler", "llvm_gcc_cpp_linker",
-                 (case
-                     (or (input_languages_contain "c++"),
-                         (input_languages_contain "objective-c++")),
-                     (inc_weight),
-                     (or (parameter_equals "linker", "g++"),
-                         (parameter_equals "linker", "c++")), (inc_weight))>,
-
-
-    Edge<"root", "llvm_gcc_linker">,
-    OptionalEdge<"root", "llvm_gcc_cpp_linker",
-                 (case
-                     (or (input_languages_contain "c++"),
-                         (input_languages_contain "objective-c++")),
-                     (inc_weight),
-                     (or (parameter_equals "linker", "g++"),
-                         (parameter_equals "linker", "c++")), (inc_weight))>
-    ]>;
diff --git a/tools/llvmc/plugins/Base/Hooks.cpp b/tools/llvmc/plugins/Base/Hooks.cpp
deleted file mode 100644 (file)
index 661a914..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-#include <string>
-#include <vector>
-
-namespace hooks {
-typedef std::vector<std::string> StrVec;
-
-/// ConvertToMAttr - Convert -m* and -mno-* to -mattr=+*,-*
-std::string ConvertToMAttr(const StrVec& Opts) {
-  std::string out("-mattr=");
-
-  bool firstIter = true;
-  for (StrVec::const_iterator B = Opts.begin(), E = Opts.end(); B!=E; ++B) {
-    const std::string& Arg = *B;
-
-    if (firstIter)
-      firstIter = false;
-    else
-      out += ",";
-
-    if (Arg.find("no-") == 0 && Arg[3] != 0) {
-      out += '-';
-      out += Arg.c_str() + 3;
-    }
-    else {
-      out += '+';
-      out += Arg;
-    }
-  }
-
-  return out;
-}
-
-}
diff --git a/tools/llvmc/plugins/Base/Makefile b/tools/llvmc/plugins/Base/Makefile
deleted file mode 100644 (file)
index ebc4335..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-##===- tools/llvmc/plugins/Base/Makefile -------------------*- Makefile -*-===##
-#
-#                     The LLVM Compiler Infrastructure
-#
-# This file is distributed under the University of Illinois Open Source
-# License. See LICENSE.TXT for details.
-#
-##===----------------------------------------------------------------------===##
-
-LEVEL = ../../../..
-
-LLVMC_PLUGIN = Base
-BUILT_SOURCES = AutoGenerated.inc
-
-include $(LEVEL)/Makefile.common
diff --git a/tools/llvmc/plugins/Base/PluginMain.cpp b/tools/llvmc/plugins/Base/PluginMain.cpp
deleted file mode 100644 (file)
index add8acb..0000000
+++ /dev/null
@@ -1 +0,0 @@
-#include "AutoGenerated.inc"
diff --git a/tools/llvmc/plugins/Clang/Clang.td b/tools/llvmc/plugins/Clang/Clang.td
deleted file mode 100644 (file)
index 988d9b1..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-include "llvm/CompilerDriver/Common.td"
-
-def Priority : PluginPriority<1>;
-
-def Options : OptionList<[
-// Extern options
-(switch_option "E", (extern)),
-(switch_option "S", (extern)),
-(switch_option "c", (extern)),
-(switch_option "fsyntax-only", (extern)),
-(switch_option "emit-llvm", (extern)),
-(switch_option "pthread", (extern)),
-(parameter_list_option "I", (extern)),
-(parameter_list_option "include", (extern)),
-(parameter_list_option "L", (extern)),
-(parameter_list_option "l", (extern)),
-(prefix_list_option "Wa,", (extern)),
-(prefix_list_option "Wl,", (extern)),
-
-(switch_option "clang", (help "Use Clang instead of llvm-gcc"))
-]>;
-
-class clang_based<string language, string cmd, string ext_E> : Tool<
-[(in_language language),
- (out_language "llvm-bitcode"),
- (output_suffix "bc"),
- (command cmd),
- (actions (case (switch_on "E"),
-                    [(forward "E"), (stop_compilation), (output_suffix ext_E)],
-                (and (switch_on "E"), (empty "o")), (no_out_file),
-                (switch_on "fsyntax-only"), (stop_compilation),
-                (switch_on ["S", "emit-llvm"]),
-                           [(append_cmd "-emit-llvm"),
-                            (stop_compilation), (output_suffix "ll")],
-                (not (switch_on ["S", "emit-llvm"])),
-                     (append_cmd "-emit-llvm-bc"),
-                (switch_on ["c", "emit-llvm"]),
-                           (stop_compilation),
-                (not_empty "include"), (forward "include"),
-                (not_empty "I"), (forward "I"))),
- (sink)
-]>;
-
-def clang_c : clang_based<"c", "clang -x c", "i">;
-def clang_cpp : clang_based<"c++", "clang -x c++", "i">;
-def clang_objective_c : clang_based<"objective-c",
-    "clang -x objective-c", "mi">;
-def clang_objective_cpp : clang_based<"objective-c++",
-    "clang -x objective-c++", "mi">;
-
-def as : Tool<
-[(in_language "assembler"),
- (out_language "object-code"),
- (output_suffix "o"),
- (command "as"),
- (actions (case (not_empty "Wa,"), (forward_value "Wa,"),
-                (switch_on "c"), (stop_compilation)))
-]>;
-
-// Default linker
-def llvm_ld : Tool<
-[(in_language "object-code"),
- (out_language "executable"),
- (output_suffix "out"),
- (command "llvm-ld -native -disable-internalize"),
- (actions (case
-          (switch_on "pthread"), (append_cmd "-lpthread"),
-          (not_empty "L"), (forward "L"),
-          (not_empty "l"), (forward "l"),
-          (not_empty "Wl,"), (forward_value "Wl,"))),
- (join)
-]>;
-
-// Language map
-
-def LanguageMap : LanguageMap<[
-    LangToSuffixes<"c++", ["cc", "cp", "cxx", "cpp", "CPP", "c++", "C"]>,
-    LangToSuffixes<"c", ["c"]>,
-    LangToSuffixes<"objective-c", ["m"]>,
-    LangToSuffixes<"c-cpp-output", ["i"]>,
-    LangToSuffixes<"objective-c-cpp-output", ["mi"]>
-]>;
-
-// Compilation graph
-
-def CompilationGraph : CompilationGraph<[
-    OptionalEdge<"root", "clang_c",
-                         (case (switch_on "clang"), (inc_weight))>,
-    OptionalEdge<"root", "clang_cpp",
-                         (case (switch_on "clang"), (inc_weight))>,
-    OptionalEdge<"root", "clang_objective_c",
-                         (case (switch_on "clang"), (inc_weight))>,
-    OptionalEdge<"root", "clang_objective_cpp",
-                         (case (switch_on "clang"), (inc_weight))>,
-    Edge<"clang_c", "llc">,
-    Edge<"clang_cpp", "llc">,
-    Edge<"clang_objective_c", "llc">,
-    Edge<"clang_objective_cpp", "llc">,
-    OptionalEdge<"llc", "as", (case (switch_on "clang"), (inc_weight))>,
-    Edge<"as", "llvm_ld">
-]>;
diff --git a/tools/llvmc/plugins/Clang/Makefile b/tools/llvmc/plugins/Clang/Makefile
deleted file mode 100644 (file)
index 5e5b88a..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-##===- tools/llvmc/plugins/Clang/Makefile ------------------*- Makefile -*-===##
-#
-#                     The LLVM Compiler Infrastructure
-#
-# This file is distributed under the University of Illinois Open Source
-# License. See LICENSE.TXT for details.
-#
-##===----------------------------------------------------------------------===##
-
-LEVEL = ../../../..
-
-LLVMC_PLUGIN = Clang
-BUILT_SOURCES = AutoGenerated.inc
-
-include $(LEVEL)/Makefile.common
diff --git a/tools/llvmc/plugins/Clang/PluginMain.cpp b/tools/llvmc/plugins/Clang/PluginMain.cpp
deleted file mode 100644 (file)
index add8acb..0000000
+++ /dev/null
@@ -1 +0,0 @@
-#include "AutoGenerated.inc"
diff --git a/tools/llvmc/plugins/Makefile b/tools/llvmc/plugins/Makefile
deleted file mode 100644 (file)
index 37dac6f..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-##===- tools/llvmc/plugins/Makefile ------------------------*- Makefile -*-===##
-#
-#                     The LLVM Compiler Infrastructure
-#
-# This file is distributed under the University of Illinois Open
-# Source License. See LICENSE.TXT for details.
-#
-##===----------------------------------------------------------------------===##
-
-LEVEL = ../../..
-
-ifneq ($(LLVMC_BUILTIN_PLUGINS),)
-DIRS = $(LLVMC_BUILTIN_PLUGINS)
-endif
-
-export LLVMC_BUILTIN_PLUGIN=1
-
-include $(LEVEL)/Makefile.common
diff --git a/tools/llvmc/src/AutoGenerated.td b/tools/llvmc/src/AutoGenerated.td
new file mode 100644 (file)
index 0000000..8507b1f
--- /dev/null
@@ -0,0 +1,17 @@
+//===- AutoGenerated.td - LLVMC toolchain descriptions -----*- tablegen -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains compilation graph description used by llvmc.
+//
+//===----------------------------------------------------------------------===//
+
+include "llvm/CompilerDriver/Common.td"
+
+include "Base.td"
+include "Clang.td"
diff --git a/tools/llvmc/src/Base.td.in b/tools/llvmc/src/Base.td.in
new file mode 100644 (file)
index 0000000..45b60b7
--- /dev/null
@@ -0,0 +1,376 @@
+//===- Base.td - LLVMC toolchain descriptions --------------*- tablegen -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains compilation graph description used by llvmc.
+//
+//===----------------------------------------------------------------------===//
+
+
+// Options
+
+def OptList : OptionList<[
+ (switch_option "emit-llvm",
+    (help "Emit LLVM .ll files instead of native object files")),
+ (switch_option "E",
+    (help "Stop after the preprocessing stage, do not run the compiler")),
+ (switch_option "fsyntax-only",
+    (help "Stop after checking the input for syntax errors")),
+ (switch_option "opt",
+    (help "Enable opt")),
+ (switch_option "O0",
+    (help "Turn off optimization"), (zero_or_more)),
+ (switch_option "O1",
+    (help "Optimization level 1"), (zero_or_more)),
+ (switch_option "O2",
+    (help "Optimization level 2"), (zero_or_more)),
+ (switch_option "O3",
+    (help "Optimization level 3"), (zero_or_more)),
+ (switch_option "S",
+    (help "Stop after compilation, do not assemble")),
+ (switch_option "c",
+    (help "Compile and assemble, but do not link")),
+ (switch_option "pthread",
+    (help "Enable threads")),
+ (switch_option "m32",
+    (help "Generate code for a 32-bit environment"), (hidden)),
+ (switch_option "m64",
+    (help "Generate code for a 64-bit environment"), (hidden)),
+ (switch_option "fPIC",
+    (help "Relocation model: PIC"), (hidden)),
+ (switch_option "mdynamic-no-pic",
+    (help "Relocation model: dynamic-no-pic"), (hidden)),
+ (switch_option "shared",
+     (help "Create a DLL instead of the regular executable")),
+ (parameter_option "linker",
+    (help "Choose linker (possible values: gcc, g++)")),
+ (parameter_option "mtune",
+    (help "Target a specific CPU type"), (hidden), (forward_not_split)),
+
+ // TODO: Add a conditional compilation mechanism to make Darwin-only options
+ // like '-arch' really Darwin-only.
+
+ (parameter_option "arch",
+    (help "Compile for the specified target architecture"), (hidden)),
+ (parameter_option "march",
+    (help "A synonym for -mtune"), (hidden), (forward_not_split)),
+ (parameter_option "mcpu",
+    (help "A deprecated synonym for -mtune"), (hidden), (forward_not_split)),
+ (switch_option "mfix-and-continue",
+    (help "Needed by gdb to load .o files dynamically"), (hidden)),
+ (parameter_option "MF",
+    (help "Specify a file to write dependencies to"), (hidden)),
+ (parameter_list_option "MT",
+    (help "Change the name of the rule emitted by dependency generation"),
+    (hidden)),
+ (parameter_list_option "include",
+    (help "Include the named file prior to preprocessing")),
+ (parameter_list_option "iquote",
+    (help "Search dir only for files requested with #inlcude \"file\""),
+    (hidden)),
+ (parameter_list_option "framework",
+    (help "Specifies a framework to link against")),
+ (parameter_list_option "weak_framework",
+    (help "Specifies a framework to weakly link against"), (hidden)),
+ (parameter_option "filelist", (hidden),
+    (help "Link the files listed in file")),
+ (prefix_list_option "F",
+    (help "Add a directory to framework search path")),
+ (prefix_list_option "I",
+    (help "Add a directory to include path")),
+ (prefix_list_option "D",
+    (help "Define a macro")),
+ (parameter_list_option "Xpreprocessor", (hidden),
+    (help "Pass options to preprocessor")),
+ (prefix_list_option "Wa,", (comma_separated),
+    (help "Pass options to assembler")),
+ (parameter_list_option "Xassembler", (hidden),
+    (help "Pass options to assembler")),
+ (prefix_list_option "Wllc,", (comma_separated),
+    (help "Pass options to llc")),
+ (prefix_list_option "L",
+    (help "Add a directory to link path")),
+ (prefix_list_option "l",
+    (help "Search a library when linking")),
+ (prefix_list_option "Wl,",
+    (help "Pass options to linker")),
+ (parameter_list_option "Xlinker", (hidden),
+    (help "Pass options to linker")),
+ (prefix_list_option "Wo,", (comma_separated),
+    (help "Pass options to opt")),
+ (prefix_list_option "m",
+     (help "Enable or disable various extensions (-mmmx, -msse, etc.)"),
+     (hidden)),
+ (switch_option "dynamiclib", (hidden),
+     (help "Produce a dynamic library")),
+ (switch_option "prebind", (hidden),
+     (help "Prebind all undefined symbols")),
+ (switch_option "dead_strip", (hidden),
+     (help "Remove unreachable blocks of code")),
+ (switch_option "single_module", (hidden),
+     (help "Build the library so it contains only one module")),
+ (parameter_option "install_name", (hidden),
+     (help "File name the library will be installed in")),
+ (parameter_option "compatibility_version", (hidden),
+     (help "Compatibility version number")),
+ (parameter_option "current_version", (hidden),
+     (help "Current version number"))
+]>;
+
+// Option preprocessor.
+
+def Preprocess : OptionPreprocessor<
+(case (not (any_switch_on ["O0", "O1", "O2", "O3"])),
+           (set_option "O2"),
+      (and (switch_on "O3"), (any_switch_on ["O0", "O1", "O2"])),
+           (unset_option ["O0", "O1", "O2"]),
+      (and (switch_on "O2"), (any_switch_on ["O0", "O1"])),
+           (unset_option ["O0", "O1"]),
+      (switch_on ["O1", "O0"]),
+           (unset_option "O0"))
+>;
+
+// Tools
+
+class llvm_gcc_based <string cmd_prefix, string in_lang,
+                      string E_ext, string out_lang> : Tool<
+[(in_language in_lang),
+ (out_language "llvm-bitcode"),
+ (output_suffix out_lang),
+ (command cmd_prefix),
+ (actions
+     (case
+         (and (not_empty "o"),
+              (multiple_input_files), (or (switch_on "S"), (switch_on "c"))),
+              (error "cannot specify -o with -c or -S with multiple files"),
+         (switch_on "E"),
+              [(forward "E"), (stop_compilation), (output_suffix E_ext)],
+         (and (switch_on "E"), (empty "o")), (no_out_file),
+         (switch_on ["emit-llvm", "S"]),
+              [(output_suffix "ll"), (stop_compilation)],
+         (switch_on ["emit-llvm", "c"]), (stop_compilation),
+         (switch_on "fsyntax-only"), [(forward "fsyntax-only"),
+                                      (no_out_file), (stop_compilation)],
+         (switch_on ["S", "emit-llvm"]), [(forward "S"), (forward "emit-llvm")],
+         (not (or (switch_on ["S", "emit-llvm"]), (switch_on "fsyntax-only"))),
+             [(append_cmd "-c"), (append_cmd "-emit-llvm")],
+
+         // Forwards
+         (not_empty "Xpreprocessor"), (forward "Xpreprocessor"),
+         (not_empty "include"), (forward "include"),
+         (not_empty "iquote"), (forward "iquote"),
+         (not_empty "save-temps"), (append_cmd "-save-temps"),
+         (not_empty "I"), (forward "I"),
+         (not_empty "F"), (forward "F"),
+         (not_empty "D"), (forward "D"),
+         (not_empty "arch"), (forward "arch"),
+         (not_empty "march"), (forward "march"),
+         (not_empty "mtune"), (forward "mtune"),
+         (not_empty "mcpu"), (forward "mcpu"),
+         (not_empty "m"), (forward "m"),
+         (switch_on "mfix-and-continue"), (forward "mfix-and-continue"),
+         (switch_on "m32"), (forward "m32"),
+         (switch_on "m64"), (forward "m64"),
+         (switch_on "O0"), (forward "O0"),
+         (switch_on "O1"), (forward "O1"),
+         (switch_on "O2"), (forward "O2"),
+         (switch_on "O3"), (forward "O3"),
+         (switch_on "fPIC"), (forward "fPIC"),
+         (switch_on "mdynamic-no-pic"), (forward "mdynamic-no-pic"),
+         (not_empty "MF"), (forward "MF"),
+         (not_empty "MT"), (forward "MT"))),
+ (sink)
+]>;
+
+def llvm_gcc_c : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x c", "c", "i", "bc">;
+def llvm_gcc_cpp : llvm_gcc_based<"@LLVMGXXCOMMAND@ -x c++", "c++", "i", "bc">;
+def llvm_gcc_m : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c",
+                                                  "objective-c", "mi", "bc">;
+def llvm_gcc_mxx : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c++",
+                                  "objective-c++", "mi", "bc">;
+
+def llvm_gcc_c_pch : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x c-header",
+                                                      "c-header", "i", "gch">;
+def llvm_gcc_cpp_pch : llvm_gcc_based<"@LLVMGXXCOMMAND@ -x c++-header",
+                                                        "c++-header",
+                                                        "i", "gch">;
+def llvm_gcc_m_pch : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c-header",
+                                                      "objective-c-header",
+                                                      "mi", "gch">;
+def llvm_gcc_mxx_pch
+    : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c++-header",
+                                       "objective-c++-header", "mi", "gch">;
+
+def opt : Tool<
+[(in_language "llvm-bitcode"),
+ (out_language "llvm-bitcode"),
+ (output_suffix "bc"),
+ (actions (case (not_empty "Wo,"), (forward_value "Wo,"),
+                (switch_on "O1"), (forward "O1"),
+                (switch_on "O2"), (forward "O2"),
+                (switch_on "O3"), (forward "O3"))),
+ (command "opt -f")
+]>;
+
+def llvm_as : Tool<
+[(in_language "llvm-assembler"),
+ (out_language "llvm-bitcode"),
+ (output_suffix "bc"),
+ (command "llvm-as"),
+ (actions (case (switch_on "emit-llvm"), (stop_compilation)))
+]>;
+
+def llvm_gcc_assembler : Tool<
+[(in_language "assembler"),
+ (out_language "object-code"),
+ (output_suffix "o"),
+ (command "@LLVMGCCCOMMAND@ -c -x assembler"),
+ (actions (case
+          (switch_on "c"), (stop_compilation),
+          (not_empty "arch"), (forward "arch"),
+          (not_empty "Xassembler"), (forward "Xassembler"),
+          (switch_on "m32"), (forward "m32"),
+          (switch_on "m64"), (forward "m64"),
+          (not_empty "Wa,"), (forward "Wa,")))
+]>;
+
+def llc : Tool<
+[(in_language ["llvm-bitcode", "llvm-assembler"]),
+ (out_language "assembler"),
+ (output_suffix "s"),
+ (command "llc"),
+ (actions (case
+          (switch_on "S"), (stop_compilation),
+          (switch_on "O0"), (forward "O0"),
+          (switch_on "O1"), (forward "O1"),
+          (switch_on "O2"), (forward "O2"),
+          (switch_on "O3"), (forward "O3"),
+          (switch_on "fPIC"), (append_cmd "-relocation-model=pic"),
+          (switch_on "mdynamic-no-pic"),
+                     (append_cmd "-relocation-model=dynamic-no-pic"),
+          (not_empty "march"), (forward_as "mtune", "-mcpu"),
+          (not_empty "mtune"), (forward_as "mtune", "-mcpu"),
+          (not_empty "mcpu"), (forward "mcpu"),
+          (not_empty "m"), (forward_transformed_value "m", "ConvertToMAttr"),
+          (not_empty "Wllc,"), (forward_value "Wllc,")))
+]>;
+
+// Base class for linkers
+class llvm_gcc_based_linker <string cmd_prefix, dag on_empty> : Tool<
+[(in_language ["object-code", "static-library"]),
+ (out_language "executable"),
+ (output_suffix "out"),
+ (command cmd_prefix),
+ (works_on_empty (case (and (not_empty "filelist"), on_empty), true,
+                       (default), false)),
+ (join),
+ (actions (case
+          (switch_on "pthread"), (append_cmd "-lpthread"),
+          (not_empty "L"), (forward "L"),
+          (not_empty "F"), (forward "F"),
+          (not_empty "arch"), (forward "arch"),
+          (not_empty "framework"), (forward "framework"),
+          (not_empty "weak_framework"), (forward "weak_framework"),
+          (not_empty "filelist"), (forward "filelist"),
+          (switch_on "m32"), (forward "m32"),
+          (switch_on "m64"), (forward "m64"),
+          (not_empty "l"), (forward "l"),
+          (not_empty "Xlinker"), (forward "Xlinker"),
+          (not_empty "Wl,"), (forward "Wl,"),
+          (switch_on "shared"), (forward "shared"),
+          (switch_on "dynamiclib"), (forward "dynamiclib"),
+          (switch_on "prebind"), (forward "prebind"),
+          (switch_on "dead_strip"), (forward "dead_strip"),
+          (switch_on "single_module"), (forward "single_module"),
+          (not_empty "compatibility_version"),
+                     (forward "compatibility_version"),
+          (not_empty "current_version"), (forward "current_version"),
+          (not_empty "install_name"), (forward "install_name")))
+]>;
+
+// Default linker
+def llvm_gcc_linker : llvm_gcc_based_linker<"@LLVMGCCCOMMAND@",
+    (not (or (parameter_equals "linker", "g++"),
+         (parameter_equals "linker", "c++")))>;
+// Alternative linker for C++
+def llvm_gcc_cpp_linker : llvm_gcc_based_linker<"@LLVMGXXCOMMAND@",
+    (or (parameter_equals "linker", "g++"),
+        (parameter_equals "linker", "c++"))>;
+
+// Language map
+
+def LanguageMap : LanguageMap<
+    [LangToSuffixes<"c++", ["cc", "cp", "cxx", "cpp", "CPP", "c++", "C"]>,
+     LangToSuffixes<"c++-header", ["hpp"]>,
+     LangToSuffixes<"c", ["c"]>,
+     LangToSuffixes<"c-header", ["h"]>,
+     LangToSuffixes<"c-cpp-output", ["i"]>,
+     LangToSuffixes<"objective-c-cpp-output", ["mi"]>,
+     LangToSuffixes<"objective-c++", ["mm"]>,
+     LangToSuffixes<"objective-c++-header", ["hmm"]>,
+     LangToSuffixes<"objective-c", ["m"]>,
+     LangToSuffixes<"objective-c-header", ["hm"]>,
+     LangToSuffixes<"assembler", ["s"]>,
+     LangToSuffixes<"assembler-with-cpp", ["S"]>,
+     LangToSuffixes<"llvm-assembler", ["ll"]>,
+     LangToSuffixes<"llvm-bitcode", ["bc"]>,
+     LangToSuffixes<"object-code", ["o", "*empty*"]>,
+     LangToSuffixes<"static-library", ["a", "lib"]>,
+     LangToSuffixes<"executable", ["out"]>
+     ]>;
+
+// Compilation graph
+
+def CompilationGraph : CompilationGraph<[
+    Edge<"root", "llvm_gcc_c">,
+    Edge<"root", "llvm_gcc_assembler">,
+    Edge<"root", "llvm_gcc_cpp">,
+    Edge<"root", "llvm_gcc_m">,
+    Edge<"root", "llvm_gcc_mxx">,
+    Edge<"root", "llc">,
+
+    Edge<"root", "llvm_gcc_c_pch">,
+    Edge<"root", "llvm_gcc_cpp_pch">,
+    Edge<"root", "llvm_gcc_m_pch">,
+    Edge<"root", "llvm_gcc_mxx_pch">,
+
+    Edge<"llvm_gcc_c", "llc">,
+    Edge<"llvm_gcc_cpp", "llc">,
+    Edge<"llvm_gcc_m", "llc">,
+    Edge<"llvm_gcc_mxx", "llc">,
+    Edge<"llvm_as", "llc">,
+
+    OptionalEdge<"root", "llvm_as",
+                         (case (switch_on "emit-llvm"), (inc_weight))>,
+    OptionalEdge<"llvm_gcc_c", "opt", (case (switch_on "opt"), (inc_weight))>,
+    OptionalEdge<"llvm_gcc_cpp", "opt", (case (switch_on "opt"), (inc_weight))>,
+    OptionalEdge<"llvm_gcc_m", "opt", (case (switch_on "opt"), (inc_weight))>,
+    OptionalEdge<"llvm_gcc_mxx", "opt", (case (switch_on "opt"), (inc_weight))>,
+    OptionalEdge<"llvm_as", "opt", (case (switch_on "opt"), (inc_weight))>,
+    Edge<"opt", "llc">,
+
+    Edge<"llc", "llvm_gcc_assembler">,
+    Edge<"llvm_gcc_assembler", "llvm_gcc_linker">,
+    OptionalEdge<"llvm_gcc_assembler", "llvm_gcc_cpp_linker",
+                 (case
+                     (or (input_languages_contain "c++"),
+                         (input_languages_contain "objective-c++")),
+                     (inc_weight),
+                     (or (parameter_equals "linker", "g++"),
+                         (parameter_equals "linker", "c++")), (inc_weight))>,
+
+
+    Edge<"root", "llvm_gcc_linker">,
+    OptionalEdge<"root", "llvm_gcc_cpp_linker",
+                 (case
+                     (or (input_languages_contain "c++"),
+                         (input_languages_contain "objective-c++")),
+                     (inc_weight),
+                     (or (parameter_equals "linker", "g++"),
+                         (parameter_equals "linker", "c++")), (inc_weight))>
+    ]>;
diff --git a/tools/llvmc/src/Clang.td b/tools/llvmc/src/Clang.td
new file mode 100644 (file)
index 0000000..c8c396e
--- /dev/null
@@ -0,0 +1,87 @@
+//===- Clang.td - LLVMC toolchain descriptions -------------*- tablegen -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains compilation graph description used by llvmc.
+//
+//===----------------------------------------------------------------------===//
+
+
+def Options : OptionList<[
+(switch_option "clang", (help "Use Clang instead of llvm-gcc"))
+]>;
+
+class clang_based<string language, string cmd, string ext_E> : Tool<
+[(in_language language),
+ (out_language "llvm-bitcode"),
+ (output_suffix "bc"),
+ (command cmd),
+ (actions (case (switch_on "E"),
+                    [(forward "E"), (stop_compilation), (output_suffix ext_E)],
+                (and (switch_on "E"), (empty "o")), (no_out_file),
+                (switch_on "fsyntax-only"), (stop_compilation),
+                (switch_on ["S", "emit-llvm"]),
+                           [(append_cmd "-emit-llvm"),
+                            (stop_compilation), (output_suffix "ll")],
+                (not (switch_on ["S", "emit-llvm"])),
+                     (append_cmd "-emit-llvm-bc"),
+                (switch_on ["c", "emit-llvm"]),
+                           (stop_compilation),
+                (not_empty "include"), (forward "include"),
+                (not_empty "I"), (forward "I"))),
+ (sink)
+]>;
+
+def clang_c : clang_based<"c", "clang -x c", "i">;
+def clang_cpp : clang_based<"c++", "clang -x c++", "i">;
+def clang_objective_c : clang_based<"objective-c",
+    "clang -x objective-c", "mi">;
+def clang_objective_cpp : clang_based<"objective-c++",
+    "clang -x objective-c++", "mi">;
+
+def as : Tool<
+[(in_language "assembler"),
+ (out_language "object-code"),
+ (output_suffix "o"),
+ (command "as"),
+ (actions (case (not_empty "Wa,"), (forward_value "Wa,"),
+                (switch_on "c"), (stop_compilation)))
+]>;
+
+// Default linker
+def llvm_ld : Tool<
+[(in_language "object-code"),
+ (out_language "executable"),
+ (output_suffix "out"),
+ (command "llvm-ld -native -disable-internalize"),
+ (actions (case
+          (switch_on "pthread"), (append_cmd "-lpthread"),
+          (not_empty "L"), (forward "L"),
+          (not_empty "l"), (forward "l"),
+          (not_empty "Wl,"), (forward_value "Wl,"))),
+ (join)
+]>;
+
+// Compilation graph
+
+def ClangCompilationGraph : CompilationGraph<[
+    OptionalEdge<"root", "clang_c",
+                         (case (switch_on "clang"), (inc_weight))>,
+    OptionalEdge<"root", "clang_cpp",
+                         (case (switch_on "clang"), (inc_weight))>,
+    OptionalEdge<"root", "clang_objective_c",
+                         (case (switch_on "clang"), (inc_weight))>,
+    OptionalEdge<"root", "clang_objective_cpp",
+                         (case (switch_on "clang"), (inc_weight))>,
+    Edge<"clang_c", "llc">,
+    Edge<"clang_cpp", "llc">,
+    Edge<"clang_objective_c", "llc">,
+    Edge<"clang_objective_cpp", "llc">,
+    OptionalEdge<"llc", "as", (case (switch_on "clang"), (inc_weight))>,
+    Edge<"as", "llvm_ld">
+]>;
diff --git a/tools/llvmc/src/Hooks.cpp b/tools/llvmc/src/Hooks.cpp
new file mode 100644 (file)
index 0000000..661a914
--- /dev/null
@@ -0,0 +1,33 @@
+#include <string>
+#include <vector>
+
+namespace hooks {
+typedef std::vector<std::string> StrVec;
+
+/// ConvertToMAttr - Convert -m* and -mno-* to -mattr=+*,-*
+std::string ConvertToMAttr(const StrVec& Opts) {
+  std::string out("-mattr=");
+
+  bool firstIter = true;
+  for (StrVec::const_iterator B = Opts.begin(), E = Opts.end(); B!=E; ++B) {
+    const std::string& Arg = *B;
+
+    if (firstIter)
+      firstIter = false;
+    else
+      out += ",";
+
+    if (Arg.find("no-") == 0 && Arg[3] != 0) {
+      out += '-';
+      out += Arg.c_str() + 3;
+    }
+    else {
+      out += '+';
+      out += Arg;
+    }
+  }
+
+  return out;
+}
+
+}
diff --git a/tools/llvmc/src/Main.cpp b/tools/llvmc/src/Main.cpp
new file mode 100644 (file)
index 0000000..9f9c71a
--- /dev/null
@@ -0,0 +1,16 @@
+//===--- Main.cpp - The LLVM Compiler Driver -------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open
+// Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//  Just include AutoGenerated.inc and CompilerDriver/Main.inc.
+//
+//===----------------------------------------------------------------------===//
+
+#include "AutoGenerated.inc"
+
+#include "llvm/CompilerDriver/Main.inc"
diff --git a/tools/llvmc/src/Makefile b/tools/llvmc/src/Makefile
new file mode 100644 (file)
index 0000000..9cfb27f
--- /dev/null
@@ -0,0 +1,14 @@
+##===- tools/llvmc/driver/Makefile -------------------------*- Makefile -*-===##
+#
+#                     The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open
+# Source License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+
+LEVEL = ../../..
+LLVMC_BASED_DRIVER = llvmc
+BUILT_SOURCES = AutoGenerated.inc
+
+include $(LEVEL)/Makefile.common
index 7a68d696f9213283ba88c45ccf9b6e233f2badbd..2d4455078216d9c97098b4113d6aa59ca855beff 100644 (file)
@@ -234,10 +234,9 @@ OptionType::OptionType stringToOptionType(const std::string& T) {
 
 namespace OptionDescriptionFlags {
   enum OptionDescriptionFlags { Required = 0x1, Hidden = 0x2,
-                                ReallyHidden = 0x4, Extern = 0x8,
-                                OneOrMore = 0x10, Optional = 0x20,
-                                CommaSeparated = 0x40, ForwardNotSplit = 0x80,
-                                ZeroOrMore = 0x100 };
+                                ReallyHidden = 0x4, OneOrMore = 0x8,
+                                Optional = 0x10, CommaSeparated = 0x20,
+                                ForwardNotSplit = 0x40, ZeroOrMore = 0x80 };
 }
 
 /// OptionDescription - Represents data contained in a single
@@ -279,9 +278,6 @@ struct OptionDescription {
   bool isCommaSeparated() const;
   void setCommaSeparated();
 
-  bool isExtern() const;
-  void setExtern();
-
   bool isForwardNotSplit() const;
   void setForwardNotSplit();
 
@@ -372,13 +368,6 @@ void OptionDescription::setForwardNotSplit() {
   Flags |= OptionDescriptionFlags::ForwardNotSplit;
 }
 
-bool OptionDescription::isExtern() const {
-  return Flags & OptionDescriptionFlags::Extern;
-}
-void OptionDescription::setExtern() {
-  Flags |= OptionDescriptionFlags::Extern;
-}
-
 bool OptionDescription::isRequired() const {
   return Flags & OptionDescriptionFlags::Required;
 }
@@ -653,7 +642,6 @@ public:
     : optDesc_(OD)
   {
     if (!staticMembersInitialized_) {
-      AddHandler("extern", &CollectOptionProperties::onExtern);
       AddHandler("help", &CollectOptionProperties::onHelp);
       AddHandler("hidden", &CollectOptionProperties::onHidden);
       AddHandler("init", &CollectOptionProperties::onInit);
@@ -682,11 +670,6 @@ private:
   /// Option property handlers --
   /// Methods that handle option properties such as (help) or (hidden).
 
-  void onExtern (const DagInit& d) {
-    CheckNumberOfArguments(d, 0);
-    optDesc_.setExtern();
-  }
-
   void onHelp (const DagInit& d) {
     CheckNumberOfArguments(d, 1);
     optDesc_.Help = EscapeQuotes(InitPtrToString(d.getArg(0)));
@@ -799,16 +782,17 @@ public:
 
     OptionDescription OD(Type, Name);
 
-    if (!OD.isExtern())
-      CheckNumberOfArguments(d, 2);
+
+    CheckNumberOfArguments(d, 2);
 
     if (OD.isAlias()) {
       // Aliases store the aliased option name in the 'Help' field.
       OD.Help = InitPtrToString(d.getArg(1));
     }
-    else if (!OD.isExtern()) {
+    else {
       processOptionProperties(d, OD);
     }
+
     OptDescs_.InsertDescription(OD);
   }
 
@@ -1043,22 +1027,6 @@ void FillInEdgeVector(RecordVector::const_iterator B,
   }
 }
 
-/// CalculatePriority - Calculate the priority of this plugin.
-int CalculatePriority(RecordVector::const_iterator B,
-                      RecordVector::const_iterator E) {
-  int priority = 0;
-
-  if (B != E) {
-    priority  = static_cast<int>((*B)->getValueAsInt("priority"));
-
-    if (++B != E)
-      throw "More than one 'PluginPriority' instance found: "
-        "most probably an error!";
-  }
-
-  return priority;
-}
-
 /// NotInGraph - Helper function object for FilterNotInGraph.
 struct NotInGraph {
 private:
@@ -2382,8 +2350,7 @@ void EmitToolClassDefinition (const ToolDescription& D,
 /// EmitOptionDefinitions - Iterate over a list of option descriptions
 /// and emit registration code.
 void EmitOptionDefinitions (const OptionDescriptions& descs,
-                            bool HasSink, bool HasExterns,
-                            raw_ostream& O)
+                            bool HasSink, raw_ostream& O)
 {
   std::vector<OptionDescription> Aliases;
 
@@ -2397,17 +2364,9 @@ void EmitOptionDefinitions (const OptionDescriptions& descs,
       continue;
     }
 
-    if (val.isExtern())
-      O << "extern ";
-
     O << val.GenTypeDeclaration() << ' '
       << val.GenVariableName();
 
-    if (val.isExtern()) {
-      O << ";\n";
-      continue;
-    }
-
     O << "(\"" << val.Name << "\"\n";
 
     if (val.Type == OptionType::Prefix || val.Type == OptionType::PrefixList)
@@ -2468,9 +2427,7 @@ void EmitOptionDefinitions (const OptionDescriptions& descs,
 
   // Emit the sink option.
   if (HasSink)
-    O << (HasExterns ? "extern cl" : "cl")
-      << "::list<std::string> " << SinkOptionName
-      << (HasExterns ? ";\n" : "(cl::Sink);\n");
+    O << "cl" << "::list<std::string> " << SinkOptionName << "(cl::Sink);\n";
 
   O << '\n';
 }
@@ -2629,11 +2586,11 @@ public:
 
 };
 
-/// EmitPreprocessOptions - Emit the PreprocessOptionsLocal() function.
+/// EmitPreprocessOptions - Emit the PreprocessOptions() function.
 void EmitPreprocessOptions (const RecordKeeper& Records,
                             const OptionDescriptions& OptDecs, raw_ostream& O)
 {
-  O << "int PreprocessOptionsLocal() {\n";
+  O << "int PreprocessOptions () {\n";
 
   const RecordVector& OptionPreprocessors =
     Records.getAllDerivedDefinitions("OptionPreprocessor");
@@ -2651,12 +2608,13 @@ void EmitPreprocessOptions (const RecordKeeper& Records,
   O << "}\n\n";
 }
 
-/// EmitPopulateLanguageMap - Emit the PopulateLanguageMapLocal() function.
+/// EmitPopulateLanguageMap - Emit the PopulateLanguageMap() function.
 void EmitPopulateLanguageMap (const RecordKeeper& Records, raw_ostream& O)
 {
-  O << "int PopulateLanguageMapLocal(LanguageMap& langMap) {\n";
+  O << "int PopulateLanguageMap (LanguageMap& langMap) {\n";
 
   // Get the relevant field out of RecordKeeper
+  // TODO: change this to getAllDerivedDefinitions.
   const Record* LangMapRecord = Records.getDef("LanguageMap");
 
   // It is allowed for a plugin to have no language map.
@@ -2758,13 +2716,12 @@ void EmitEdgeClasses (const RecordVector& EdgeVector,
   }
 }
 
-/// EmitPopulateCompilationGraph - Emit the PopulateCompilationGraphLocal()
-/// function.
+/// EmitPopulateCompilationGraph - Emit the PopulateCompilationGraph() function.
 void EmitPopulateCompilationGraph (const RecordVector& EdgeVector,
                                    const ToolDescriptions& ToolDescs,
                                    raw_ostream& O)
 {
-  O << "int PopulateCompilationGraphLocal(CompilationGraph& G) {\n";
+  O << "int PopulateCompilationGraph (CompilationGraph& G) {\n";
 
   for (ToolDescriptions::const_iterator B = ToolDescs.begin(),
          E = ToolDescs.end(); B != E; ++B)
@@ -2974,30 +2931,12 @@ void EmitHookDeclarations(const ToolDescriptions& ToolDescs,
   O << "}\n\n";
 }
 
-/// EmitRegisterPlugin - Emit code to register this plugin.
-void EmitRegisterPlugin(int Priority, raw_ostream& O) {
-  O << "struct Plugin : public llvmc::BasePlugin {\n\n";
-  O.indent(Indent1) << "int Priority() const { return "
-                    << Priority << "; }\n\n";
-  O.indent(Indent1) << "int PreprocessOptions() const\n";
-  O.indent(Indent1) << "{ return PreprocessOptionsLocal(); }\n\n";
-  O.indent(Indent1) << "int PopulateLanguageMap(LanguageMap& langMap) const\n";
-  O.indent(Indent1) << "{ return PopulateLanguageMapLocal(langMap); }\n\n";
-  O.indent(Indent1)
-    << "int PopulateCompilationGraph(CompilationGraph& graph) const\n";
-  O.indent(Indent1) << "{ return PopulateCompilationGraphLocal(graph); }\n"
-                    << "};\n\n"
-                    << "static llvmc::RegisterPlugin<Plugin> RP;\n\n";
-}
-
 /// EmitIncludes - Emit necessary #include directives and some
 /// additional declarations.
 void EmitIncludes(raw_ostream& O) {
   O << "#include \"llvm/CompilerDriver/BuiltinOptions.h\"\n"
     << "#include \"llvm/CompilerDriver/CompilationGraph.h\"\n"
     << "#include \"llvm/CompilerDriver/Error.h\"\n"
-    << "#include \"llvm/CompilerDriver/ForceLinkageMacros.h\"\n"
-    << "#include \"llvm/CompilerDriver/Plugin.h\"\n"
     << "#include \"llvm/CompilerDriver/Tool.h\"\n\n"
 
     << "#include \"llvm/Support/CommandLine.h\"\n"
@@ -3022,10 +2961,8 @@ void EmitIncludes(raw_ostream& O) {
 struct PluginData {
   OptionDescriptions OptDescs;
   bool HasSink;
-  bool HasExterns;
   ToolDescriptions ToolDescs;
   RecordVector Edges;
-  int Priority;
 };
 
 /// HasSink - Go through the list of tool descriptions and check if
@@ -3039,19 +2976,8 @@ bool HasSink(const ToolDescriptions& ToolDescs) {
   return false;
 }
 
-/// HasExterns - Go through the list of option descriptions and check
-/// if there are any external options.
-bool HasExterns(const OptionDescriptions& OptDescs) {
- for (OptionDescriptions::const_iterator B = OptDescs.begin(),
-         E = OptDescs.end(); B != E; ++B)
-    if (B->second.isExtern())
-      return true;
-
-  return false;
-}
-
-/// CollectPluginData - Collect tool and option properties,
-/// compilation graph edges and plugin priority from the parse tree.
+/// CollectPluginData - Collect compilation graph edges, tool properties and
+/// option properties from the parse tree.
 void CollectPluginData (const RecordKeeper& Records, PluginData& Data) {
   // Collect option properties.
   const RecordVector& OptionLists =
@@ -3063,18 +2989,12 @@ void CollectPluginData (const RecordKeeper& Records, PluginData& Data) {
   const RecordVector& Tools = Records.getAllDerivedDefinitions("Tool");
   CollectToolDescriptions(Tools.begin(), Tools.end(), Data.ToolDescs);
   Data.HasSink = HasSink(Data.ToolDescs);
-  Data.HasExterns = HasExterns(Data.OptDescs);
 
   // Collect compilation graph edges.
   const RecordVector& CompilationGraphs =
     Records.getAllDerivedDefinitions("CompilationGraph");
   FillInEdgeVector(CompilationGraphs.begin(), CompilationGraphs.end(),
                    Data.Edges);
-
-  // Calculate the priority of this plugin.
-  const RecordVector& Priorities =
-    Records.getAllDerivedDefinitions("PluginPriority");
-  Data.Priority = CalculatePriority(Priorities.begin(), Priorities.end());
 }
 
 /// CheckPluginData - Perform some sanity checks on the collected data.
@@ -3095,20 +3015,13 @@ void EmitPluginCode(const PluginData& Data, raw_ostream& O) {
   EmitIncludes(O);
 
   // Emit global option registration code.
-  EmitOptionDefinitions(Data.OptDescs, Data.HasSink, Data.HasExterns, O);
+  EmitOptionDefinitions(Data.OptDescs, Data.HasSink, O);
 
   // Emit hook declarations.
   EmitHookDeclarations(Data.ToolDescs, Data.OptDescs, O);
 
   O << "namespace {\n\n";
 
-  // Emit PreprocessOptionsLocal() function.
-  EmitPreprocessOptions(Records, Data.OptDescs, O);
-
-  // Emit PopulateLanguageMapLocal() function
-  // (language map maps from file extensions to language names).
-  EmitPopulateLanguageMap(Records, O);
-
   // Emit Tool classes.
   for (ToolDescriptions::const_iterator B = Data.ToolDescs.begin(),
          E = Data.ToolDescs.end(); B!=E; ++B)
@@ -3117,18 +3030,23 @@ void EmitPluginCode(const PluginData& Data, raw_ostream& O) {
   // Emit Edge# classes.
   EmitEdgeClasses(Data.Edges, Data.OptDescs, O);
 
-  // Emit PopulateCompilationGraphLocal() function.
-  EmitPopulateCompilationGraph(Data.Edges, Data.ToolDescs, O);
-
-  // Emit code for plugin registration.
-  EmitRegisterPlugin(Data.Priority, O);
-
   O << "} // End anonymous namespace.\n\n";
 
-  // Force linkage magic.
   O << "namespace llvmc {\n";
-  O << "LLVMC_FORCE_LINKAGE_DECL(LLVMC_PLUGIN_NAME) {}\n";
-  O << "}\n";
+  O << "namespace autogenerated {\n\n";
+
+  // Emit PreprocessOptions() function.
+  EmitPreprocessOptions(Records, Data.OptDescs, O);
+
+  // Emit PopulateLanguageMap() function
+  // (language map maps from file extensions to language names).
+  EmitPopulateLanguageMap(Records, O);
+
+  // Emit PopulateCompilationGraph() function.
+  EmitPopulateCompilationGraph(Data.Edges, Data.ToolDescs, O);
+
+  O << "} // End namespace autogenerated.\n";
+  O << "} // End namespace llvmc.\n\n";
 
   // EOF
 }