Support some more Darwin-only options.
[oota-llvm.git] / tools / llvmc / plugins / Base / Base.td.in
1 //===- Base.td - LLVMC toolchain descriptions --------------*- 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 compilation graph description used by llvmc.
11 //
12 //===----------------------------------------------------------------------===//
13
14 include "llvm/CompilerDriver/Common.td"
15
16 // Options
17
18 def OptList : OptionList<[
19  (switch_option "emit-llvm",
20     (help "Emit LLVM .ll files instead of native object files")),
21  (switch_option "E",
22     (help "Stop after the preprocessing stage, do not run the compiler")),
23  (switch_option "fsyntax-only",
24     (help "Stop after checking the input for syntax errors")),
25  (switch_option "opt",
26     (help "Enable opt")),
27  (switch_option "O0",
28     (help "Turn off optimization")),
29  (switch_option "O1",
30     (help "Optimization level 1")),
31  (switch_option "O2",
32     (help "Optimization level 2")),
33  (switch_option "O3",
34     (help "Optimization level 3")),
35  (switch_option "S",
36     (help "Stop after compilation, do not assemble")),
37  (switch_option "c",
38     (help "Compile and assemble, but do not link")),
39  (switch_option "pthread",
40     (help "Enable threads")),
41  (switch_option "m32",
42     (help "Generate code for a 32-bit environment"), (hidden)),
43  (switch_option "m64",
44     (help "Generate code for a 64-bit environment"), (hidden)),
45  (switch_option "fPIC",
46     (help "Relocation model: PIC"), (hidden)),
47  (switch_option "mdynamic-no-pic",
48     (help "Relocation model: dynamic-no-pic"), (hidden)),
49  (parameter_option "linker",
50     (help "Choose linker (possible values: gcc, g++)")),
51  (parameter_option "mtune",
52     (help "Target a specific CPU type"), (hidden)),
53
54  // TODO: Add a conditional compilation mechanism to make Darwin-only options
55  // like '-arch' really Darwin-only.
56
57  (parameter_option "arch",
58     (help "Compile for the specified target architecture"), (hidden)),
59  (parameter_option "march",
60     (help "A synonym for -mtune"), (hidden)),
61  (parameter_option "mcpu",
62     (help "A deprecated synonym for -mtune"), (hidden)),
63  (switch_option "mfix-and-continue",
64     (help "Needed by gdb to load .o files dynamically"), (hidden)),
65  (parameter_option "MF",
66     (help "Specify a file to write dependencies to"), (hidden)),
67  (parameter_list_option "MT",
68     (help "Change the name of the rule emitted by dependency generation"),
69     (hidden)),
70  (parameter_list_option "include",
71     (help "Include the named file prior to preprocessing")),
72  (parameter_list_option "iquote",
73     (help "Search dir only for files requested with #inlcude \"file\""),
74     (hidden)),
75  (parameter_list_option "framework",
76     (help "Specifies a framework to link against")),
77  (parameter_list_option "weak_framework",
78     (help "Specifies a framework to weakly link against"), (hidden)),
79  (prefix_list_option "F",
80     (help "Add a directory to framework search path")),
81  (prefix_list_option "I",
82     (help "Add a directory to include path")),
83  (prefix_list_option "D",
84     (help "Define a macro")),
85  (prefix_list_option "Wa,", (comma_separated),
86     (help "Pass options to assembler")),
87  (prefix_list_option "Wllc,", (comma_separated),
88     (help "Pass options to llc")),
89  (prefix_list_option "L",
90     (help "Add a directory to link path")),
91  (prefix_list_option "l",
92     (help "Search a library when linking")),
93  (prefix_list_option "Wl,",
94     (help "Pass options to linker")),
95  (prefix_list_option "Wo,", (comma_separated),
96     (help "Pass options to opt")),
97  (prefix_list_option "m",
98      (help "Enable or disable various extensions (-mmmx, -msse, etc.)"),
99      (hidden)),
100  (switch_option "dynamiclib", (hidden),
101      (help "Produce a dynamic library")),
102  (switch_option "prebind", (hidden),
103      (help "Prebind all undefined symbols")),
104  (switch_option "dead_strip", (hidden),
105      (help "Remove unreachable blocks of code")),
106  (switch_option "single_module", (hidden),
107      (help "Build the library so it contains only one module")),
108  (parameter_option "compatibility_version", (hidden),
109      (help "Compatibility version number")),
110  (parameter_option "current_version", (hidden),
111      (help "Current version number"))
112 ]>;
113
114 // Option preprocessor.
115
116 def Preprocess : OptionPreprocessor<
117 (case (not (any_switch_on ["O0", "O1", "O2", "O3"])),
118            (set_option "O2"),
119       (and (switch_on "O3"), (any_switch_on ["O0", "O1", "O2"])),
120            (unset_option ["O0", "O1", "O2"]),
121       (and (switch_on "O2"), (any_switch_on ["O0", "O1"])),
122            (unset_option ["O0", "O1"]),
123       (switch_on ["O1", "O0"]),
124            (unset_option "O0"))
125 >;
126
127 // Tools
128
129 class llvm_gcc_based <string cmd_prefix, string in_lang, string E_ext> : Tool<
130 [(in_language in_lang),
131  (out_language "llvm-bitcode"),
132  (output_suffix "bc"),
133  (cmd_line (case
134             (switch_on "E"),
135               (case (not_empty "o"),
136                     !strconcat(cmd_prefix, " -E $INFILE -o $OUTFILE"),
137                     (default),
138                     !strconcat(cmd_prefix, " -E $INFILE")),
139             (switch_on "fsyntax-only"),
140               !strconcat(cmd_prefix, " -fsyntax-only $INFILE"),
141             (and (switch_on "S"), (switch_on "emit-llvm")),
142               !strconcat(cmd_prefix, " -S $INFILE -o $OUTFILE -emit-llvm"),
143             (default),
144               !strconcat(cmd_prefix, " -c $INFILE -o $OUTFILE -emit-llvm"))),
145  (actions
146      (case
147          (and (multiple_input_files), (or (switch_on "S"), (switch_on "c"))),
148               (error "cannot specify -o with -c or -S with multiple files"),
149          (switch_on "E"), [(stop_compilation), (output_suffix E_ext)],
150          (switch_on ["emit-llvm", "S"]),
151               [(output_suffix "ll"), (stop_compilation)],
152          (switch_on ["emit-llvm", "c"]), (stop_compilation),
153          (switch_on "fsyntax-only"), (stop_compilation),
154          (not_empty "include"), (forward "include"),
155          (not_empty "iquote"), (forward "iquote"),
156          (not_empty "save-temps"), (append_cmd "-save-temps"),
157          (not_empty "I"), (forward "I"),
158          (not_empty "F"), (forward "F"),
159          (not_empty "D"), (forward "D"),
160          (not_empty "arch"), (forward "arch"),
161          (not_empty "march"), (forward "march"),
162          (not_empty "mtune"), (forward "mtune"),
163          (not_empty "mcpu"), (forward "mcpu"),
164          (not_empty "m"), (forward "m"),
165          (switch_on "mfix-and-continue"), (forward "mfix-and-continue"),
166          (switch_on "m32"), (forward "m32"),
167          (switch_on "m64"), (forward "m64"),
168          (switch_on "O0"), (forward "O0"),
169          (switch_on "O1"), (forward "O1"),
170          (switch_on "O2"), (forward "O2"),
171          (switch_on "O3"), (forward "O3"),
172          (switch_on "fPIC"), (forward "fPIC"),
173          (switch_on "mdynamic-no-pic"), (forward "mdynamic-no-pic"),
174          (not_empty "MF"), (forward "MF"),
175          (not_empty "MT"), (forward "MT"))),
176  (sink)
177 ]>;
178
179 def llvm_gcc_c : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x c", "c", "i">;
180 def llvm_gcc_cpp : llvm_gcc_based<"@LLVMGXXCOMMAND@ -x c++", "c++", "i">;
181 def llvm_gcc_m : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c",
182                                                   "objective-c", "mi">;
183 def llvm_gcc_mxx : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c++",
184                                   "objective-c++", "mi">;
185
186 def opt : Tool<
187 [(in_language "llvm-bitcode"),
188  (out_language "llvm-bitcode"),
189  (output_suffix "bc"),
190  (actions (case (not_empty "Wo,"), (forward_value "Wo,"),
191                 (switch_on "O1"), (forward "O1"),
192                 (switch_on "O2"), (forward "O2"),
193                 (switch_on "O3"), (forward "O3"))),
194  (cmd_line "opt -f $INFILE -o $OUTFILE")
195 ]>;
196
197 def llvm_as : Tool<
198 [(in_language "llvm-assembler"),
199  (out_language "llvm-bitcode"),
200  (output_suffix "bc"),
201  (cmd_line "llvm-as $INFILE -o $OUTFILE"),
202  (actions (case (switch_on "emit-llvm"), (stop_compilation)))
203 ]>;
204
205 def llvm_gcc_assembler : Tool<
206 [(in_language "assembler"),
207  (out_language "object-code"),
208  (output_suffix "o"),
209  (cmd_line "@LLVMGCCCOMMAND@ -c -x assembler $INFILE -o $OUTFILE"),
210  (actions (case
211           (switch_on "c"), (stop_compilation),
212           (not_empty "arch"), (forward "arch"),
213           (not_empty "Wa,"), (forward_value "Wa,")))
214 ]>;
215
216 def llc : Tool<
217 [(in_language ["llvm-bitcode", "llvm-assembler"]),
218  (out_language "assembler"),
219  (output_suffix "s"),
220  (cmd_line "llc -f $INFILE -o $OUTFILE"),
221  (actions (case
222           (switch_on "S"), (stop_compilation),
223           (switch_on "O0"), (forward "O0"),
224           (switch_on "O1"), (forward "O1"),
225           (switch_on "O2"), (forward "O2"),
226           (switch_on "O3"), (forward "O3"),
227           (switch_on "fPIC"), (append_cmd "-relocation-model=pic"),
228           (switch_on "mdynamic-no-pic"),
229                      (append_cmd "-relocation-model=dynamic-no-pic"),
230           (not_empty "march"), (forward "mcpu"),
231           (not_empty "mtune"), (forward "mcpu"),
232           (not_empty "mcpu"), (forward "mcpu"),
233           (not_empty "m"), (forward_transformed_value "m", "ConvertToMAttr"),
234           (not_empty "Wllc,"), (forward_value "Wllc,")))
235 ]>;
236
237 // Base class for linkers
238 class llvm_gcc_based_linker <string cmd_prefix> : Tool<
239 [(in_language "object-code"),
240  (out_language "executable"),
241  (output_suffix "out"),
242  (cmd_line !strconcat(cmd_prefix, " $INFILE -o $OUTFILE")),
243  (join),
244  (actions (case
245           (switch_on "pthread"), (append_cmd "-lpthread"),
246           (not_empty "L"), (forward "L"),
247           (not_empty "F"), (forward "F"),
248           (not_empty "arch"), (forward "arch"),
249           (not_empty "framework"), (forward "framework"),
250           (not_empty "weak_framework"), (forward "weak_framework"),
251           (switch_on "m32"), (forward "m32"),
252           (switch_on "m64"), (forward "m64"),
253           (not_empty "l"), (forward "l"),
254           (not_empty "Wl,"), (forward "Wl,"),
255           (switch_on "dynamiclib"), (forward "dynamiclib"),
256           (switch_on "prebind"), (forward "prebind"),
257           (switch_on "dead_strip"), (forward "dead_strip"),
258           (switch_on "single_module"), (forward "single_module"),
259           (not_empty "compatibility_version"),
260                      (forward "compatibility_version"),
261           (not_empty "current_version"),
262                      (forward "current_version")))
263 ]>;
264
265 // Default linker
266 def llvm_gcc_linker : llvm_gcc_based_linker<"@LLVMGCCCOMMAND@">;
267 // Alternative linker for C++
268 def llvm_gcc_cpp_linker : llvm_gcc_based_linker<"@LLVMGXXCOMMAND@">;
269
270 // Language map
271
272 def LanguageMap : LanguageMap<
273     [LangToSuffixes<"c++", ["cc", "cp", "cxx", "cpp", "CPP", "c++", "C"]>,
274      LangToSuffixes<"c", ["c"]>,
275      LangToSuffixes<"c-cpp-output", ["i"]>,
276      LangToSuffixes<"objective-c-cpp-output", ["mi"]>,
277      LangToSuffixes<"objective-c++", ["mm"]>,
278      LangToSuffixes<"objective-c", ["m"]>,
279      LangToSuffixes<"assembler", ["s"]>,
280      LangToSuffixes<"assembler-with-cpp", ["S"]>,
281      LangToSuffixes<"llvm-assembler", ["ll"]>,
282      LangToSuffixes<"llvm-bitcode", ["bc"]>,
283      LangToSuffixes<"object-code", ["o"]>,
284      LangToSuffixes<"executable", ["out"]>
285      ]>;
286
287 // Compilation graph
288
289 def CompilationGraph : CompilationGraph<[
290     Edge<"root", "llvm_gcc_c">,
291     Edge<"root", "llvm_gcc_assembler">,
292     Edge<"root", "llvm_gcc_cpp">,
293     Edge<"root", "llvm_gcc_m">,
294     Edge<"root", "llvm_gcc_mxx">,
295     Edge<"root", "llc">,
296
297     Edge<"llvm_gcc_c", "llc">,
298     Edge<"llvm_gcc_cpp", "llc">,
299     Edge<"llvm_gcc_m", "llc">,
300     Edge<"llvm_gcc_mxx", "llc">,
301     Edge<"llvm_as", "llc">,
302
303     OptionalEdge<"root", "llvm_as",
304                          (case (switch_on "emit-llvm"), (inc_weight))>,
305     OptionalEdge<"llvm_gcc_c", "opt", (case (switch_on "opt"), (inc_weight))>,
306     OptionalEdge<"llvm_gcc_cpp", "opt", (case (switch_on "opt"), (inc_weight))>,
307     OptionalEdge<"llvm_gcc_m", "opt", (case (switch_on "opt"), (inc_weight))>,
308     OptionalEdge<"llvm_gcc_mxx", "opt", (case (switch_on "opt"), (inc_weight))>,
309     OptionalEdge<"llvm_as", "opt", (case (switch_on "opt"), (inc_weight))>,
310     Edge<"opt", "llc">,
311
312     Edge<"llc", "llvm_gcc_assembler">,
313     Edge<"llvm_gcc_assembler", "llvm_gcc_linker">,
314     OptionalEdge<"llvm_gcc_assembler", "llvm_gcc_cpp_linker",
315                  (case
316                      (or (input_languages_contain "c++"),
317                          (input_languages_contain "objective-c++")),
318                      (inc_weight),
319                      (or (parameter_equals "linker", "g++"),
320                          (parameter_equals "linker", "c++")), (inc_weight))>,
321
322
323     Edge<"root", "llvm_gcc_linker">,
324     OptionalEdge<"root", "llvm_gcc_cpp_linker",
325                  (case
326                      (or (input_languages_contain "c++"),
327                          (input_languages_contain "objective-c++")),
328                      (inc_weight),
329                      (or (parameter_equals "linker", "g++"),
330                          (parameter_equals "linker", "c++")), (inc_weight))>
331     ]>;