Plugin updates: support more options.
authorMikhail Glushenkov <foldr@codedgers.com>
Sun, 7 Dec 2008 16:46:23 +0000 (16:46 +0000)
committerMikhail Glushenkov <foldr@codedgers.com>
Sun, 7 Dec 2008 16:46:23 +0000 (16:46 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60666 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CompilerDriver/Tools.td
tools/llvmc/plugins/Clang/Clang.td

index d8248acae249d846a012170544650c8777a97f0a..27d49a0d2fe6fea6256a2d81157144c2c45cd746 100644 (file)
@@ -24,6 +24,8 @@ def OptList : OptionList<[
     (help "Stop after compilation, do not assemble")),
  (switch_option "c",
     (help "Compile and assemble, but do not link")),
+ (switch_option "pthread",
+    (help "Enable threads")),
  (parameter_option "linker",
     (help "Choose linker (possible values: gcc, g++)")),
  (parameter_list_option "include",
@@ -57,10 +59,11 @@ class llvm_gcc_based <string cmd_prefix, string in_lang> : Tool<
  (actions
      (case
          (switch_on "emit-llvm"), (stop_compilation),
-         (switch_on "E"), (stop_compilation),
+         (switch_on "E"), [(stop_compilation), (output_suffix "i")],
+         (switch_on "S"), (stop_compilation),
          (switch_on "fsyntax-only"), (stop_compilation),
          (not_empty "include"), (forward "include"),
-         (not_empty "I"), (forward "include"))),
+         (not_empty "I"), (forward "I"))),
  (sink)
 ]>;
 
@@ -83,15 +86,6 @@ def llvm_as : Tool<
  (cmd_line "llvm-as $INFILE -o $OUTFILE")
 ]>;
 
-def llc : Tool<
-[(in_language "llvm-bitcode"),
- (out_language "assembler"),
- (output_suffix "s"),
- (actions (case
-          (switch_on "S"), (stop_compilation))),
- (cmd_line "llc -f $INFILE -o $OUTFILE")
-]>;
-
 def llvm_gcc_assembler : Tool<
 [(in_language "assembler"),
  (out_language "object-code"),
@@ -102,6 +96,14 @@ def llvm_gcc_assembler : Tool<
           (not_empty "Wa,"), (unpack_values "Wa,")))
 ]>;
 
+def llc : Tool<
+[(in_language "llvm-bitcode"),
+ (out_language "assembler"),
+ (output_suffix "s"),
+ (cmd_line "llc -relocation-model=pic -f $INFILE -o $OUTFILE"),
+ (actions (case (switch_on "S"), (stop_compilation)))
+]>;
+
 // Base class for linkers
 class llvm_gcc_based_linker <string cmd_prefix> : Tool<
 [(in_language "object-code"),
@@ -110,6 +112,7 @@ class llvm_gcc_based_linker <string cmd_prefix> : Tool<
  (cmd_line !strconcat(cmd_prefix, " $INFILE -o $OUTFILE")),
  (join),
  (actions (case
+          (switch_on "pthread"), (append_cmd "-lpthread"),
           (not_empty "L"), (forward "L"),
           (not_empty "l"), (forward "l"),
           (not_empty "Wl,"), (unpack_values "Wl,")))
@@ -125,9 +128,12 @@ def llvm_gcc_cpp_linker : llvm_gcc_based_linker<"llvm-g++">;
 def LanguageMap : LanguageMap<
     [LangToSuffixes<"c++", ["cc", "cp", "cxx", "cpp", "CPP", "c++", "C"]>,
      LangToSuffixes<"c", ["c"]>,
+     LangToSuffixes<"c-cpp-output", ["i"]>,
+     LangToSuffixes<"objective-c-cpp-output", ["mi"]>,
      LangToSuffixes<"objective-c++", ["mm"]>,
      LangToSuffixes<"objective-c", ["m"]>,
      LangToSuffixes<"assembler", ["s"]>,
+     LangToSuffixes<"assembler-with-cpp", ["S"]>,
      LangToSuffixes<"llvm-assembler", ["ll"]>,
      LangToSuffixes<"llvm-bitcode", ["bc"]>,
      LangToSuffixes<"object-code", ["o"]>,
index 4e1bd1d1886ab1c0df0f43a4b81ea11aa4079641..2267baf609ca738ffab60a39444ad8c3fee7f011 100644 (file)
@@ -6,14 +6,24 @@
 
 include "llvm/CompilerDriver/Common.td"
 
+def Priority : PluginPriority<1>;
+
 def Options : OptionList<[
-(extern_switch "E",
-    (help "Stop after the preprocessing stage, do not run the compiler")),
-(extern_list "L", (help "Specify a library search path")),
+(extern_switch "E"),
+(extern_switch "c"),
+(extern_switch "fsyntax-only"),
+(extern_switch "emit-llvm"),
+(extern_switch "pthread"),
+(extern_list "I"),
+(extern_list "include"),
+(extern_list "L"),
+(extern_list "l"),
+(extern_list "Wa,"),
+(extern_list "Wl,"),
 (switch_option "clang", (help "Use Clang instead of llvm-gcc"))
 ]>;
 
-class clang_based<string language, string cmd> : Tool<
+class clang_based<string language, string cmd, string ext_E> : Tool<
 [(in_language language),
  (out_language "llvm-bitcode"),
  (output_suffix "bc"),
@@ -24,38 +34,58 @@ class clang_based<string language, string cmd> : Tool<
                 !strconcat(cmd, " -E $INFILE -o $OUTFILE"),
                 (default),
                 !strconcat(cmd, " -E $INFILE")),
+          (switch_on "c"),
+          !strconcat(cmd, " -fsyntax-only $INFILE"),
           (default),
           !strconcat(cmd, " -emit-llvm-bc $INFILE -o $OUTFILE"))),
  (actions (case (switch_on "E"),
-                [(stop_compilation), (output_suffix "i")])),
+                [(stop_compilation), (output_suffix ext_E)],
+                (switch_on "c"), (stop_compilation),
+                (switch_on "fsyntax-only"), (stop_compilation),
+                (switch_on "emit-llvm"), (stop_compilation),
+                (not_empty "include"), (forward "include"),
+                (not_empty "I"), (forward "I"))),
  (sink)
 ]>;
 
-def clang_c : clang_based<"c", "clang -x c">;
-def clang_cpp : clang_based<"c++", "clang -x c++">;
-def clang_objective_c : clang_based<"objective-c", "clang -x objective-c">;
+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++">;
+    "clang -x objective-c++", "mi">;
+
+def as : Tool<
+[(in_language "assembler"),
+ (out_language "object-code"),
+ (output_suffix "o"),
+ (cmd_line "as $INFILE -o $OUTFILE"),
+ (actions (case (not_empty "Wa,"), (unpack_values "Wa,")))
+]>;
 
 // Default linker
 def llvm_ld : Tool<
-[(in_language "llvm-bitcode"),
+[(in_language "object-code"),
  (out_language "executable"),
  (output_suffix "out"),
  (cmd_line "llvm-ld -native -disable-internalize $INFILE -o $OUTFILE"),
- (actions (case (not_empty "L"), (forward "L"))),
+ (actions (case
+          (switch_on "pthread"), (append_cmd "-lpthread"),
+          (not_empty "L"), (forward "L"),
+          (not_empty "l"), (forward "l"),
+          (not_empty "Wl,"), (unpack_values "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"]>
-     ]>;
+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
 
@@ -66,7 +96,12 @@ def CompilationGraph : CompilationGraph<[
                          (case (switch_on "clang"), (inc_weight))>,
     OptionalEdge<"root", "clang_objective_c",
                          (case (switch_on "clang"), (inc_weight))>,
-    Edge<"clang_c", "llvm_ld">,
-    Edge<"clang_cpp", "llvm_ld">,
-    Edge<"clang_objective_c", "llvm_ld">
-    ]>;
+    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">
+]>;