Build system tweaks to make it more convenient for the plugin authors.
authorMikhail Glushenkov <foldr@codedgers.com>
Thu, 2 Oct 2008 21:15:05 +0000 (21:15 +0000)
committerMikhail Glushenkov <foldr@codedgers.com>
Thu, 2 Oct 2008 21:15:05 +0000 (21:15 +0000)
Plugins can be now compiled in with a slight Makefile change.
For example, to compile the new Clang driver, use:

cd $LLVMC2_DIR
make TOOLNAME=ccc2 BUILTIN_PLUGINS=Clang

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56967 91177308-0d34-0410-b5e6-96231b3b80d8

15 files changed:
include/llvm/CompilerDriver/Common.td [new file with mode: 0644]
include/llvm/CompilerDriver/Tools.td [new file with mode: 0644]
tools/llvmc2/AutoGenerated.cpp [deleted file]
tools/llvmc2/Common.td [deleted file]
tools/llvmc2/Graph.td [deleted file]
tools/llvmc2/Makefile
tools/llvmc2/Tools.td [deleted file]
tools/llvmc2/examples/Clang.td [deleted file]
tools/llvmc2/plugins/Base/AutoGenerated.cpp [new file with mode: 0644]
tools/llvmc2/plugins/Base/Base.td [new file with mode: 0644]
tools/llvmc2/plugins/Base/Makefile [new file with mode: 0644]
tools/llvmc2/plugins/Clang/AutoGenerated.cpp [new file with mode: 0644]
tools/llvmc2/plugins/Clang/Clang.td [new file with mode: 0644]
tools/llvmc2/plugins/Clang/Makefile [new file with mode: 0644]
tools/llvmc2/plugins/Hello/Makefile

diff --git a/include/llvm/CompilerDriver/Common.td b/include/llvm/CompilerDriver/Common.td
new file mode 100644 (file)
index 0000000..4551838
--- /dev/null
@@ -0,0 +1,106 @@
+//===- Common.td - Common definitions for LLVMC2  ----------*- 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 common definitions used in llvmc2 tool description files.
+//
+//===----------------------------------------------------------------------===//
+
+class Tool<list<dag> l> {
+      list<dag> properties = l;
+}
+
+// Special Tool instance - the root node of the compilation graph.
+
+def root : Tool<[]>;
+
+// Possible Tool properties
+
+def in_language;
+def out_language;
+def output_suffix;
+def cmd_line;
+def join;
+def sink;
+
+// Possible option types
+
+def alias_option;
+def switch_option;
+def parameter_option;
+def parameter_list_option;
+def prefix_option;
+def prefix_list_option;
+
+// Possible option properties
+
+def append_cmd;
+def forward;
+def forward_as;
+def stop_compilation;
+def unpack_values;
+def help;
+def required;
+
+// Empty DAG marker.
+def empty;
+
+// The 'case' construct.
+def case;
+
+// Primitive tests.
+def switch_on;
+def parameter_equals;
+def element_in_list;
+def input_languages_contain;
+def not_empty;
+def default;
+
+// Boolean operators.
+def and;
+def or;
+
+// Increase/decrease the edge weight.
+def inc_weight;
+def dec_weight;
+
+// Option list - used to specify aliases and sometimes help strings.
+class OptionList<list<dag> l> {
+      list<dag> options = l;
+}
+
+// Map from suffixes to language names
+
+class LangToSuffixes<string str, list<string> lst> {
+      string lang = str;
+      list<string> suffixes = lst;
+}
+
+class LanguageMap<list<LangToSuffixes> lst> {
+      list<LangToSuffixes> map = lst;
+}
+
+// Compilation graph
+
+class EdgeBase<Tool t1, Tool t2, dag d> {
+      Tool a = t1;
+      Tool b = t2;
+      dag weight = d;
+}
+
+class Edge<Tool t1, Tool t2> : EdgeBase<t1, t2, (empty)>;
+
+// Edge and SimpleEdge are synonyms.
+class SimpleEdge<Tool t1, Tool t2> : EdgeBase<t1, t2, (empty)>;
+
+// Optionally enabled edge.
+class OptionalEdge<Tool t1, Tool t2, dag props> : EdgeBase<t1, t2, props>;
+
+class CompilationGraph<list<EdgeBase> lst> {
+      list<EdgeBase> edges = lst;
+}
diff --git a/include/llvm/CompilerDriver/Tools.td b/include/llvm/CompilerDriver/Tools.td
new file mode 100644 (file)
index 0000000..1a466a2
--- /dev/null
@@ -0,0 +1,117 @@
+//===- Tools.td - Tools description for LLVMC2 -------------*- 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 descriptions of the various build tools run by llvmc2.
+//
+//===----------------------------------------------------------------------===//
+
+def llvm_gcc_c : Tool<
+[(in_language "c"),
+ (out_language "llvm-bitcode"),
+ (output_suffix "bc"),
+ (cmd_line (case
+            (switch_on "E"),
+              (case (not_empty "o"),
+                    "llvm-gcc -E -x c++ $INFILE -o $OUTFILE",
+                    (default),
+                    "llvm-gcc -E -x c++ $INFILE"),
+            (default),
+              "llvm-gcc -c -x c $INFILE -o $OUTFILE -emit-llvm")),
+ (switch_option "E", (stop_compilation),
+   (help "Stop after the preprocessing stage, do not run the compiler")),
+ (sink)
+]>;
+
+def llvm_gcc_cpp : Tool<
+[(in_language "c++"),
+ (out_language "llvm-bitcode"),
+ (output_suffix "bc"),
+ (cmd_line (case
+            (switch_on "E"),
+              (case (not_empty "o"),
+                    "llvm-g++ -E -x c++ $INFILE -o $OUTFILE",
+                    (default),
+                    "llvm-g++ -E -x c++ $INFILE"),
+            (default),
+              "llvm-g++ -c -x c++ $INFILE -o $OUTFILE -emit-llvm")),
+ (switch_option "E", (stop_compilation)),
+ (sink)
+]>;
+
+def opt : Tool<
+[(in_language "llvm-bitcode"),
+ (out_language "llvm-bitcode"),
+ (switch_option "opt", (help "Enable opt")),
+ (output_suffix "bc"),
+ (cmd_line "opt -f $INFILE -o $OUTFILE")
+]>;
+
+def llvm_as : Tool<
+[(in_language "llvm-assembler"),
+ (out_language "llvm-bitcode"),
+ (output_suffix "bc"),
+ (cmd_line "llvm-as $INFILE -o $OUTFILE")
+]>;
+
+def llc : Tool<
+[(in_language "llvm-bitcode"),
+ (out_language "assembler"),
+ (output_suffix "s"),
+ (switch_option "S", (stop_compilation),
+                (help "Stop after compilation, do not assemble")),
+ (cmd_line "llc -f $INFILE -o $OUTFILE")
+]>;
+
+def llvm_gcc_assembler : Tool<
+[(in_language "assembler"),
+ (out_language "object-code"),
+ (output_suffix "o"),
+ (cmd_line "llvm-gcc -c -x assembler $INFILE -o $OUTFILE"),
+ (switch_option "c", (stop_compilation),
+                (help "Compile and assemble, but do not link")),
+ (prefix_list_option "Wa,", (unpack_values), (help "Pass options to assembler"))
+]>;
+
+// Default linker
+def llvm_gcc_linker : Tool<
+[(in_language "object-code"),
+ (out_language "executable"),
+ (output_suffix "out"),
+ (cmd_line "llvm-gcc $INFILE -o $OUTFILE"),
+ (join),
+ (prefix_list_option "L", (forward), (help "Add a directory to link path")),
+ (prefix_list_option "l", (forward), (help "Search a library when linking")),
+ (prefix_list_option "Wl,", (unpack_values), (help "Pass options to linker"))
+]>;
+
+// Alternative linker for C++
+def llvm_gcc_cpp_linker : Tool<
+[(in_language "object-code"),
+ (out_language "executable"),
+ (output_suffix "out"),
+ (cmd_line "llvm-g++ $INFILE -o $OUTFILE"),
+ (join),
+ (parameter_option "linker",
+                   (help "Choose linker (possible values: gcc, g++)")),
+ (prefix_list_option "L", (forward)),
+ (prefix_list_option "l", (forward)),
+ (prefix_list_option "Wl,", (unpack_values))
+]>;
+
+// Language map
+
+def LanguageMap : LanguageMap<
+    [LangToSuffixes<"c++", ["cc", "cp", "cxx", "cpp", "CPP", "c++", "C"]>,
+     LangToSuffixes<"c", ["c"]>,
+     LangToSuffixes<"assembler", ["s"]>,
+     LangToSuffixes<"llvm-assembler", ["ll"]>,
+     LangToSuffixes<"llvm-bitcode", ["bc"]>,
+     LangToSuffixes<"object-code", ["o"]>,
+     LangToSuffixes<"executable", ["out"]>
+     ]>;
diff --git a/tools/llvmc2/AutoGenerated.cpp b/tools/llvmc2/AutoGenerated.cpp
deleted file mode 100644 (file)
index 9f34e58..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-//===--- AutoGenerated.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.
-//
-//===----------------------------------------------------------------------===//
-//
-//  Auto-generated tool descriptions - implementation.
-//
-//===----------------------------------------------------------------------===//
-
-// The auto-generated file
-#include "AutoGenerated.inc"
diff --git a/tools/llvmc2/Common.td b/tools/llvmc2/Common.td
deleted file mode 100644 (file)
index 4551838..0000000
+++ /dev/null
@@ -1,106 +0,0 @@
-//===- Common.td - Common definitions for LLVMC2  ----------*- 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 common definitions used in llvmc2 tool description files.
-//
-//===----------------------------------------------------------------------===//
-
-class Tool<list<dag> l> {
-      list<dag> properties = l;
-}
-
-// Special Tool instance - the root node of the compilation graph.
-
-def root : Tool<[]>;
-
-// Possible Tool properties
-
-def in_language;
-def out_language;
-def output_suffix;
-def cmd_line;
-def join;
-def sink;
-
-// Possible option types
-
-def alias_option;
-def switch_option;
-def parameter_option;
-def parameter_list_option;
-def prefix_option;
-def prefix_list_option;
-
-// Possible option properties
-
-def append_cmd;
-def forward;
-def forward_as;
-def stop_compilation;
-def unpack_values;
-def help;
-def required;
-
-// Empty DAG marker.
-def empty;
-
-// The 'case' construct.
-def case;
-
-// Primitive tests.
-def switch_on;
-def parameter_equals;
-def element_in_list;
-def input_languages_contain;
-def not_empty;
-def default;
-
-// Boolean operators.
-def and;
-def or;
-
-// Increase/decrease the edge weight.
-def inc_weight;
-def dec_weight;
-
-// Option list - used to specify aliases and sometimes help strings.
-class OptionList<list<dag> l> {
-      list<dag> options = l;
-}
-
-// Map from suffixes to language names
-
-class LangToSuffixes<string str, list<string> lst> {
-      string lang = str;
-      list<string> suffixes = lst;
-}
-
-class LanguageMap<list<LangToSuffixes> lst> {
-      list<LangToSuffixes> map = lst;
-}
-
-// Compilation graph
-
-class EdgeBase<Tool t1, Tool t2, dag d> {
-      Tool a = t1;
-      Tool b = t2;
-      dag weight = d;
-}
-
-class Edge<Tool t1, Tool t2> : EdgeBase<t1, t2, (empty)>;
-
-// Edge and SimpleEdge are synonyms.
-class SimpleEdge<Tool t1, Tool t2> : EdgeBase<t1, t2, (empty)>;
-
-// Optionally enabled edge.
-class OptionalEdge<Tool t1, Tool t2, dag props> : EdgeBase<t1, t2, props>;
-
-class CompilationGraph<list<EdgeBase> lst> {
-      list<EdgeBase> edges = lst;
-}
diff --git a/tools/llvmc2/Graph.td b/tools/llvmc2/Graph.td
deleted file mode 100644 (file)
index b09d8ce..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-//===- Graph.td - LLVMC2 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 llvmc2.
-//
-//===----------------------------------------------------------------------===//
-
-include "Common.td"
-include "Tools.td"
-
-// Toolchains
-
-def CompilationGraph : CompilationGraph<[
-    Edge<root, llvm_gcc_c>,
-    Edge<root, llvm_gcc_assembler>,
-    Edge<root, llvm_gcc_cpp>,
-    Edge<root, llvm_as>,
-
-    Edge<llvm_gcc_c, llc>,
-    Edge<llvm_gcc_cpp, llc>,
-    Edge<llvm_as, llc>,
-
-    OptionalEdge<llvm_gcc_c, opt, (case (switch_on "opt"), (inc_weight))>,
-    OptionalEdge<llvm_gcc_cpp, 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
-                     (input_languages_contain "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
-                     (input_languages_contain "c++"), (inc_weight),
-                     (or (parameter_equals "linker", "g++"),
-                         (parameter_equals "linker", "c++")), (inc_weight))>
-    ]>;
index 0d64088cedcd033ec7ef26f7c002123bd73c6a2c..93501657fb63a915042db21dacc7b6ebceb26235 100644 (file)
@@ -6,24 +6,39 @@
 # Source License. See LICENSE.TXT for details.
 #
 ##===----------------------------------------------------------------------===##
+
+# Compiled-in plugins
+BUILTIN_PLUGINS = Base
+
 LEVEL = ../..
 TOOLNAME = llvmc2
-BUILT_SOURCES = AutoGenerated.inc
 LINK_COMPONENTS = support system
 REQUIRES_EH := 1
 
+ifneq ($(BUILTIN_PLUGINS),)
+
+export BUILTIN_LLVMC_PLUGIN=1
+USEDLIBS = $(patsubst %,LLVMC%,$(BUILTIN_PLUGINS))
+
+endif
+
 include $(LEVEL)/Makefile.common
 
-GRAPH=Graph.td
-$(GRAPH) : Common.td
-Graph.td : Tools.td
-TOOLS_SOURCE=$(GRAPH)
+TD_COMMON = $(wildcard $(LLVM_SRC_ROOT)/include/llvm/CompilerDriver/*.td)
+
+# There is probably a better way to do this: currently we enter the
+# subdirectory 2 times - the second time is not needed.
+# This probably also needs to be integrated into Makefile.rules.
+define PLUGIN_template
+PLUGIN_$(1)_SOURCES=$$(wildcard plugins/$(1)/*.cpp)
+PLUGIN_$(1)_TD_SOURCES=$$(wildcard plugins/$(1)/*.cpp)
+
+$$(LibDir)/LLVMC$(1).o: $$(PLUGIN_$(1)_SOURCES) $$(PLUGIN_$(1)_TD_SOURCES) \
+                       $$(TD_COMMON)
+       @$$(MAKE) -C plugins/$(1)
 
-# TOFIX: integrate this part into Makefile.rules?
-# The degree of horrorshowness in that file is too much for me atm.
-$(ObjDir)/AutoGenerated.inc.tmp: $(TOOLS_SOURCE) $(ObjDir)/.dir $(TBLGEN)
-       $(Echo) "Building LLVMC configuration library with tblgen"
-       $(Verb) $(TableGen) -gen-llvmc -o $(call SYSPATH, $@) $<
+$$(RecursiveTargets) ::
+       @$$(MAKE) -C plugins/$(1) $$@
+endef
 
-AutoGenerated.inc : $(ObjDir)/AutoGenerated.inc.tmp
-       $(Verb) $(CMP) -s $@ $< || $(CP) $< $@
+$(foreach plugin,$(BUILTIN_PLUGINS),$(eval $(call PLUGIN_template,$(plugin))))
diff --git a/tools/llvmc2/Tools.td b/tools/llvmc2/Tools.td
deleted file mode 100644 (file)
index 1a466a2..0000000
+++ /dev/null
@@ -1,117 +0,0 @@
-//===- Tools.td - Tools description for LLVMC2 -------------*- 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 descriptions of the various build tools run by llvmc2.
-//
-//===----------------------------------------------------------------------===//
-
-def llvm_gcc_c : Tool<
-[(in_language "c"),
- (out_language "llvm-bitcode"),
- (output_suffix "bc"),
- (cmd_line (case
-            (switch_on "E"),
-              (case (not_empty "o"),
-                    "llvm-gcc -E -x c++ $INFILE -o $OUTFILE",
-                    (default),
-                    "llvm-gcc -E -x c++ $INFILE"),
-            (default),
-              "llvm-gcc -c -x c $INFILE -o $OUTFILE -emit-llvm")),
- (switch_option "E", (stop_compilation),
-   (help "Stop after the preprocessing stage, do not run the compiler")),
- (sink)
-]>;
-
-def llvm_gcc_cpp : Tool<
-[(in_language "c++"),
- (out_language "llvm-bitcode"),
- (output_suffix "bc"),
- (cmd_line (case
-            (switch_on "E"),
-              (case (not_empty "o"),
-                    "llvm-g++ -E -x c++ $INFILE -o $OUTFILE",
-                    (default),
-                    "llvm-g++ -E -x c++ $INFILE"),
-            (default),
-              "llvm-g++ -c -x c++ $INFILE -o $OUTFILE -emit-llvm")),
- (switch_option "E", (stop_compilation)),
- (sink)
-]>;
-
-def opt : Tool<
-[(in_language "llvm-bitcode"),
- (out_language "llvm-bitcode"),
- (switch_option "opt", (help "Enable opt")),
- (output_suffix "bc"),
- (cmd_line "opt -f $INFILE -o $OUTFILE")
-]>;
-
-def llvm_as : Tool<
-[(in_language "llvm-assembler"),
- (out_language "llvm-bitcode"),
- (output_suffix "bc"),
- (cmd_line "llvm-as $INFILE -o $OUTFILE")
-]>;
-
-def llc : Tool<
-[(in_language "llvm-bitcode"),
- (out_language "assembler"),
- (output_suffix "s"),
- (switch_option "S", (stop_compilation),
-                (help "Stop after compilation, do not assemble")),
- (cmd_line "llc -f $INFILE -o $OUTFILE")
-]>;
-
-def llvm_gcc_assembler : Tool<
-[(in_language "assembler"),
- (out_language "object-code"),
- (output_suffix "o"),
- (cmd_line "llvm-gcc -c -x assembler $INFILE -o $OUTFILE"),
- (switch_option "c", (stop_compilation),
-                (help "Compile and assemble, but do not link")),
- (prefix_list_option "Wa,", (unpack_values), (help "Pass options to assembler"))
-]>;
-
-// Default linker
-def llvm_gcc_linker : Tool<
-[(in_language "object-code"),
- (out_language "executable"),
- (output_suffix "out"),
- (cmd_line "llvm-gcc $INFILE -o $OUTFILE"),
- (join),
- (prefix_list_option "L", (forward), (help "Add a directory to link path")),
- (prefix_list_option "l", (forward), (help "Search a library when linking")),
- (prefix_list_option "Wl,", (unpack_values), (help "Pass options to linker"))
-]>;
-
-// Alternative linker for C++
-def llvm_gcc_cpp_linker : Tool<
-[(in_language "object-code"),
- (out_language "executable"),
- (output_suffix "out"),
- (cmd_line "llvm-g++ $INFILE -o $OUTFILE"),
- (join),
- (parameter_option "linker",
-                   (help "Choose linker (possible values: gcc, g++)")),
- (prefix_list_option "L", (forward)),
- (prefix_list_option "l", (forward)),
- (prefix_list_option "Wl,", (unpack_values))
-]>;
-
-// Language map
-
-def LanguageMap : LanguageMap<
-    [LangToSuffixes<"c++", ["cc", "cp", "cxx", "cpp", "CPP", "c++", "C"]>,
-     LangToSuffixes<"c", ["c"]>,
-     LangToSuffixes<"assembler", ["s"]>,
-     LangToSuffixes<"llvm-assembler", ["ll"]>,
-     LangToSuffixes<"llvm-bitcode", ["bc"]>,
-     LangToSuffixes<"object-code", ["o"]>,
-     LangToSuffixes<"executable", ["out"]>
-     ]>;
diff --git a/tools/llvmc2/examples/Clang.td b/tools/llvmc2/examples/Clang.td
deleted file mode 100644 (file)
index 383984a..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-// A (first stab at a) replacement for the Clang's ccc script.
-// To compile, use this command:
-//    make TOOLNAME=ccc2 GRAPH=examples/Clang.td
-
-include "Common.td"
-
-
-// TOFIX: Add an explicit option list for aliases and things like this.
-def Options : OptionList<[
-(switch_option "E",
-    (help "Stop after the preprocessing stage, do not run the compiler"))
-]>;
-
-class clang_base<string language, dag cmdline> : Tool<
-[(in_language language),
- (out_language "llvm-bitcode"),
- (output_suffix "bc"),
- (cmd_line cmdline),
- (switch_option "E", (stop_compilation), (output_suffix "i")),
- (sink)
-]>;
-
-def clang_c : clang_base<"c",
-(case
-(switch_on "E"),
-    (case
-    (not_empty "o"),
-        "clang -E -x c $INFILE -o $OUTFILE",
-    (default),
-        "clang -E -x c $INFILE"),
-(default),
-    "clang -emit-llvm-bc -x c $INFILE -o $OUTFILE")>;
-
-def clang_cpp : clang_base<"c++",
-(case
-(switch_on "E"),
-    (case
-    (not_empty "o"),
-        "clang -E -x c++ $INFILE -o $OUTFILE",
-    (default),
-        "clang -E -x c++ $INFILE"),
-(default),
-    "clang -emit-llvm-bc -x c++ $INFILE -o $OUTFILE")>;
-
-def clang_objective_c : clang_base<"objective-c",
-(case
-(switch_on "E"),
-    (case
-    (not_empty "o"),
-        "clang -E -x objective-c $INFILE -o $OUTFILE",
-    (default),
-        "clang -E -x objective-c $INFILE"),
-(default),
-    "clang -emit-llvm-bc -x objective-c $INFILE -o $OUTFILE")>;
-
-// Default linker
-def llvm_ld : Tool<
-[(in_language "llvm-bitcode"),
- (out_language "executable"),
- (output_suffix "out"),
- (cmd_line "llvm-ld -native -disable-internalize $INFILE -o $OUTFILE"),
- (prefix_list_option "L", (forward), (help "Specify a library search path")),
- (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<[
-    Edge<root, clang_c>,
-    Edge<root, clang_cpp>,
-    Edge<root, clang_objective_c>,
-    Edge<clang_c, llvm_ld>,
-    Edge<clang_cpp, llvm_ld>,
-    Edge<clang_objective_c, llvm_ld>
-    ]>;
-
diff --git a/tools/llvmc2/plugins/Base/AutoGenerated.cpp b/tools/llvmc2/plugins/Base/AutoGenerated.cpp
new file mode 100644 (file)
index 0000000..add8acb
--- /dev/null
@@ -0,0 +1 @@
+#include "AutoGenerated.inc"
diff --git a/tools/llvmc2/plugins/Base/Base.td b/tools/llvmc2/plugins/Base/Base.td
new file mode 100644 (file)
index 0000000..bc40dd5
--- /dev/null
@@ -0,0 +1,49 @@
+//===- Graph.td - LLVMC2 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 llvmc2.
+//
+//===----------------------------------------------------------------------===//
+
+include "llvm/CompilerDriver/Common.td"
+include "llvm/CompilerDriver/Tools.td"
+
+// Toolchains
+
+def CompilationGraph : CompilationGraph<[
+    Edge<root, llvm_gcc_c>,
+    Edge<root, llvm_gcc_assembler>,
+    Edge<root, llvm_gcc_cpp>,
+    Edge<root, llvm_as>,
+
+    Edge<llvm_gcc_c, llc>,
+    Edge<llvm_gcc_cpp, llc>,
+    Edge<llvm_as, llc>,
+
+    OptionalEdge<llvm_gcc_c, opt, (case (switch_on "opt"), (inc_weight))>,
+    OptionalEdge<llvm_gcc_cpp, 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
+                     (input_languages_contain "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
+                     (input_languages_contain "c++"), (inc_weight),
+                     (or (parameter_equals "linker", "g++"),
+                         (parameter_equals "linker", "c++")), (inc_weight))>
+    ]>;
diff --git a/tools/llvmc2/plugins/Base/Makefile b/tools/llvmc2/plugins/Base/Makefile
new file mode 100644 (file)
index 0000000..e72f4fe
--- /dev/null
@@ -0,0 +1,12 @@
+##===- tools/llvmc2/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.
+#
+##===----------------------------------------------------------------------===##
+
+LLVMC_PLUGIN = Base
+
+include ../Makefile.common
diff --git a/tools/llvmc2/plugins/Clang/AutoGenerated.cpp b/tools/llvmc2/plugins/Clang/AutoGenerated.cpp
new file mode 100644 (file)
index 0000000..add8acb
--- /dev/null
@@ -0,0 +1 @@
+#include "AutoGenerated.inc"
diff --git a/tools/llvmc2/plugins/Clang/Clang.td b/tools/llvmc2/plugins/Clang/Clang.td
new file mode 100644 (file)
index 0000000..9985d70
--- /dev/null
@@ -0,0 +1,86 @@
+// A (first stab at a) replacement for the Clang's ccc script.
+// To compile, use this command:
+//    cd $LLVMC2_DIR
+//    make TOOLNAME=ccc2 BUILTIN_PLUGINS=Clang
+
+include "llvm/CompilerDriver/Common.td"
+
+
+def Options : OptionList<[
+(switch_option "E",
+    (help "Stop after the preprocessing stage, do not run the compiler"))
+]>;
+
+class clang_base<string language, dag cmdline> : Tool<
+[(in_language language),
+ (out_language "llvm-bitcode"),
+ (output_suffix "bc"),
+ (cmd_line cmdline),
+ (switch_option "E", (stop_compilation), (output_suffix "i")),
+ (sink)
+]>;
+
+def clang_c : clang_base<"c",
+(case
+(switch_on "E"),
+    (case
+    (not_empty "o"),
+        "clang -E -x c $INFILE -o $OUTFILE",
+    (default),
+        "clang -E -x c $INFILE"),
+(default),
+    "clang -emit-llvm-bc -x c $INFILE -o $OUTFILE")>;
+
+def clang_cpp : clang_base<"c++",
+(case
+(switch_on "E"),
+    (case
+    (not_empty "o"),
+        "clang -E -x c++ $INFILE -o $OUTFILE",
+    (default),
+        "clang -E -x c++ $INFILE"),
+(default),
+    "clang -emit-llvm-bc -x c++ $INFILE -o $OUTFILE")>;
+
+def clang_objective_c : clang_base<"objective-c",
+(case
+(switch_on "E"),
+    (case
+    (not_empty "o"),
+        "clang -E -x objective-c $INFILE -o $OUTFILE",
+    (default),
+        "clang -E -x objective-c $INFILE"),
+(default),
+    "clang -emit-llvm-bc -x objective-c $INFILE -o $OUTFILE")>;
+
+// Default linker
+def llvm_ld : Tool<
+[(in_language "llvm-bitcode"),
+ (out_language "executable"),
+ (output_suffix "out"),
+ (cmd_line "llvm-ld -native -disable-internalize $INFILE -o $OUTFILE"),
+ (prefix_list_option "L", (forward), (help "Specify a library search path")),
+ (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<[
+    Edge<root, clang_c>,
+    Edge<root, clang_cpp>,
+    Edge<root, clang_objective_c>,
+    Edge<clang_c, llvm_ld>,
+    Edge<clang_cpp, llvm_ld>,
+    Edge<clang_objective_c, llvm_ld>
+    ]>;
+
diff --git a/tools/llvmc2/plugins/Clang/Makefile b/tools/llvmc2/plugins/Clang/Makefile
new file mode 100644 (file)
index 0000000..8904588
--- /dev/null
@@ -0,0 +1,13 @@
+##===- tools/llvmc2/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.
+#
+##===----------------------------------------------------------------------===##
+
+LLVMC_PLUGIN = Clang
+
+include ../Makefile.common
+
index 3aeef24eeaa80a99f8df646783316535f33c8a07..8cd0b57a0030ffc3970f858968c105547c53f01f 100644 (file)
@@ -1,4 +1,4 @@
-##===- lib/Transforms/Hello/Makefile -----------------------*- Makefile -*-===##
+##===- tools/llvmc2/plugins/Hello/Makefile -----------------*- Makefile -*-===##
 #
 #                     The LLVM Compiler Infrastructure
 #
@@ -7,11 +7,6 @@
 #
 ##===----------------------------------------------------------------------===##
 
-LEVEL = ../../../..
-LIBRARYNAME = LLVMCHello
-LOADABLE_MODULE = 1
-REQUIRES_EH = 1
-USEDLIBS =
-
-include $(LEVEL)/Makefile.common
+LLVMC_PLUGIN = Hello
 
+include ../Makefile.common