Use (actions) instead of option properties, support external options.
[oota-llvm.git] / include / llvm / CompilerDriver / Tools.td
index fa2cd33ffbdde88033b35f48a90e2f813e29e60d..d8248acae249d846a012170544650c8777a97f0a 100644 (file)
 //
 //===----------------------------------------------------------------------===//
 
-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"),
-            (switch_on "fsyntax-only"),
-              "llvm-gcc -c -x c $INFILE",
-            (default),
-              "llvm-gcc -c -x c $INFILE -o $OUTFILE -emit-llvm")),
- (switch_option "emit-llvm", (stop_compilation),
-   (help "Emit LLVM intermediate files instead of native object files")),
- (switch_option "E", (stop_compilation),
-   (help "Stop after the preprocessing stage, do not run the compiler")),
- (switch_option "fsyntax-only", (stop_compilation),
-   (help "Stop after checking the input for syntax errors")),
- (parameter_list_option "include", (forward),
-   (help "Include the named file prior to preprocessing")),
- (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 OptList : OptionList<[
+ (switch_option "emit-llvm",
+    (help "Emit LLVM bitcode 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 "S",
+    (help "Stop after compilation, do not assemble")),
+ (switch_option "c",
+    (help "Compile and assemble, but do not link")),
+ (parameter_option "linker",
+    (help "Choose linker (possible values: gcc, g++)")),
+ (parameter_list_option "include",
+    (help "Include the named file prior to preprocessing")),
+ (prefix_list_option "I",
+    (help "Add a directory to include path")),
+ (prefix_list_option "Wa,",
+    (help "Pass options to assembler")),
+ (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"))
 ]>;
 
-def llvm_gcc_m : Tool<
-[(in_language "objective-c"),
+class llvm_gcc_based <string cmd_prefix, string in_lang> : Tool<
+[(in_language in_lang),
  (out_language "llvm-bitcode"),
  (output_suffix "bc"),
  (cmd_line (case
             (switch_on "E"),
               (case (not_empty "o"),
-                    "llvm-gcc -E -x objective-c $INFILE -o $OUTFILE",
+                    !strconcat(cmd_prefix, " -E $INFILE -o $OUTFILE"),
                     (default),
-                    "llvm-gcc -E -x objective-c $INFILE"),
+                    !strconcat(cmd_prefix, " -E $INFILE")),
+            (switch_on "fsyntax-only"),
+              !strconcat(cmd_prefix, " -fsyntax-only $INFILE"),
             (default),
-              "llvm-gcc -c -x objective-c $INFILE -o $OUTFILE -emit-llvm")),
- (switch_option "E", (stop_compilation)),
+              !strconcat(cmd_prefix, " -c $INFILE -o $OUTFILE -emit-llvm"))),
+ (actions
+     (case
+         (switch_on "emit-llvm"), (stop_compilation),
+         (switch_on "E"), (stop_compilation),
+         (switch_on "fsyntax-only"), (stop_compilation),
+         (not_empty "include"), (forward "include"),
+         (not_empty "I"), (forward "include"))),
  (sink)
 ]>;
 
-def llvm_gcc_mxx : Tool<
-[(in_language "objective-c++"),
- (out_language "llvm-bitcode"),
- (output_suffix "bc"),
- (cmd_line (case
-            (switch_on "E"),
-              (case (not_empty "o"),
-                    "llvm-gcc -E -x objective-c++ $INFILE -o $OUTFILE",
-                    (default),
-                    "llvm-gcc -E -x objective-c++ $INFILE"),
-            (default),
-              "llvm-gcc -c -x objective-c++ $INFILE -o $OUTFILE -emit-llvm")),
- (switch_option "E", (stop_compilation)),
- (sink)
-]>;
+def llvm_gcc_c : llvm_gcc_based<"llvm-gcc -x c", "c">;
+def llvm_gcc_cpp : llvm_gcc_based<"llvm-g++ -x c++", "c++">;
+def llvm_gcc_m : llvm_gcc_based<"llvm-gcc -x objective-c", "objective-c">;
+def llvm_gcc_mxx : llvm_gcc_based<"llvm-gcc -x objective-c++", "objective-c++">;
 
 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")
 ]>;
@@ -103,8 +87,8 @@ 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")),
+ (actions (case
+          (switch_on "S"), (stop_compilation))),
  (cmd_line "llc -f $INFILE -o $OUTFILE")
 ]>;
 
@@ -113,36 +97,28 @@ def llvm_gcc_assembler : Tool<
  (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"))
+ (actions (case
+          (switch_on "c"), (stop_compilation),
         (not_empty "Wa,"), (unpack_values "Wa,")))
 ]>;
 
-// Default linker
-def llvm_gcc_linker : Tool<
+// Base class for linkers
+class llvm_gcc_based_linker <string cmd_prefix> : Tool<
 [(in_language "object-code"),
  (out_language "executable"),
  (output_suffix "out"),
- (cmd_line "llvm-gcc $INFILE -o $OUTFILE"),
+ (cmd_line !strconcat(cmd_prefix, " $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"))
+ (actions (case
+          (not_empty "L"), (forward "L"),
+          (not_empty "l"), (forward "l"),
+          (not_empty "Wl,"), (unpack_values "Wl,")))
 ]>;
 
+// Default linker
+def llvm_gcc_linker : llvm_gcc_based_linker<"llvm-gcc">;
 // 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))
-]>;
+def llvm_gcc_cpp_linker : llvm_gcc_based_linker<"llvm-g++">;
 
 // Language map