Use (actions) instead of option properties, support external options.
[oota-llvm.git] / include / llvm / CompilerDriver / Tools.td
1 //===- Tools.td - Tools description for LLVMC2 -------------*- tablegen -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains descriptions of the various build tools run by llvmc2.
11 //
12 //===----------------------------------------------------------------------===//
13
14 def OptList : OptionList<[
15  (switch_option "emit-llvm",
16     (help "Emit LLVM bitcode files instead of native object files")),
17  (switch_option "E",
18     (help "Stop after the preprocessing stage, do not run the compiler")),
19  (switch_option "fsyntax-only",
20     (help "Stop after checking the input for syntax errors")),
21  (switch_option "opt",
22     (help "Enable opt")),
23  (switch_option "S",
24     (help "Stop after compilation, do not assemble")),
25  (switch_option "c",
26     (help "Compile and assemble, but do not link")),
27  (parameter_option "linker",
28     (help "Choose linker (possible values: gcc, g++)")),
29  (parameter_list_option "include",
30     (help "Include the named file prior to preprocessing")),
31  (prefix_list_option "I",
32     (help "Add a directory to include path")),
33  (prefix_list_option "Wa,",
34     (help "Pass options to assembler")),
35  (prefix_list_option "L",
36     (help "Add a directory to link path")),
37  (prefix_list_option "l",
38     (help "Search a library when linking")),
39  (prefix_list_option "Wl,",
40     (help "Pass options to linker"))
41 ]>;
42
43 class llvm_gcc_based <string cmd_prefix, string in_lang> : Tool<
44 [(in_language in_lang),
45  (out_language "llvm-bitcode"),
46  (output_suffix "bc"),
47  (cmd_line (case
48             (switch_on "E"),
49               (case (not_empty "o"),
50                     !strconcat(cmd_prefix, " -E $INFILE -o $OUTFILE"),
51                     (default),
52                     !strconcat(cmd_prefix, " -E $INFILE")),
53             (switch_on "fsyntax-only"),
54               !strconcat(cmd_prefix, " -fsyntax-only $INFILE"),
55             (default),
56               !strconcat(cmd_prefix, " -c $INFILE -o $OUTFILE -emit-llvm"))),
57  (actions
58      (case
59          (switch_on "emit-llvm"), (stop_compilation),
60          (switch_on "E"), (stop_compilation),
61          (switch_on "fsyntax-only"), (stop_compilation),
62          (not_empty "include"), (forward "include"),
63          (not_empty "I"), (forward "include"))),
64  (sink)
65 ]>;
66
67 def llvm_gcc_c : llvm_gcc_based<"llvm-gcc -x c", "c">;
68 def llvm_gcc_cpp : llvm_gcc_based<"llvm-g++ -x c++", "c++">;
69 def llvm_gcc_m : llvm_gcc_based<"llvm-gcc -x objective-c", "objective-c">;
70 def llvm_gcc_mxx : llvm_gcc_based<"llvm-gcc -x objective-c++", "objective-c++">;
71
72 def opt : Tool<
73 [(in_language "llvm-bitcode"),
74  (out_language "llvm-bitcode"),
75  (output_suffix "bc"),
76  (cmd_line "opt -f $INFILE -o $OUTFILE")
77 ]>;
78
79 def llvm_as : Tool<
80 [(in_language "llvm-assembler"),
81  (out_language "llvm-bitcode"),
82  (output_suffix "bc"),
83  (cmd_line "llvm-as $INFILE -o $OUTFILE")
84 ]>;
85
86 def llc : Tool<
87 [(in_language "llvm-bitcode"),
88  (out_language "assembler"),
89  (output_suffix "s"),
90  (actions (case
91           (switch_on "S"), (stop_compilation))),
92  (cmd_line "llc -f $INFILE -o $OUTFILE")
93 ]>;
94
95 def llvm_gcc_assembler : Tool<
96 [(in_language "assembler"),
97  (out_language "object-code"),
98  (output_suffix "o"),
99  (cmd_line "llvm-gcc -c -x assembler $INFILE -o $OUTFILE"),
100  (actions (case
101           (switch_on "c"), (stop_compilation),
102           (not_empty "Wa,"), (unpack_values "Wa,")))
103 ]>;
104
105 // Base class for linkers
106 class llvm_gcc_based_linker <string cmd_prefix> : Tool<
107 [(in_language "object-code"),
108  (out_language "executable"),
109  (output_suffix "out"),
110  (cmd_line !strconcat(cmd_prefix, " $INFILE -o $OUTFILE")),
111  (join),
112  (actions (case
113           (not_empty "L"), (forward "L"),
114           (not_empty "l"), (forward "l"),
115           (not_empty "Wl,"), (unpack_values "Wl,")))
116 ]>;
117
118 // Default linker
119 def llvm_gcc_linker : llvm_gcc_based_linker<"llvm-gcc">;
120 // Alternative linker for C++
121 def llvm_gcc_cpp_linker : llvm_gcc_based_linker<"llvm-g++">;
122
123 // Language map
124
125 def LanguageMap : LanguageMap<
126     [LangToSuffixes<"c++", ["cc", "cp", "cxx", "cpp", "CPP", "c++", "C"]>,
127      LangToSuffixes<"c", ["c"]>,
128      LangToSuffixes<"objective-c++", ["mm"]>,
129      LangToSuffixes<"objective-c", ["m"]>,
130      LangToSuffixes<"assembler", ["s"]>,
131      LangToSuffixes<"llvm-assembler", ["ll"]>,
132      LangToSuffixes<"llvm-bitcode", ["bc"]>,
133      LangToSuffixes<"object-code", ["o"]>,
134      LangToSuffixes<"executable", ["out"]>
135      ]>;