Support --with-llvmgccdir and friends in llvmc, take 2.
[oota-llvm.git] / tools / llvmc / plugins / Base / Base.td.in
1 //===- Base.td - LLVMC2 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 llvmc2.
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 "S",
28     (help "Stop after compilation, do not assemble")),
29  (switch_option "c",
30     (help "Compile and assemble, but do not link")),
31  (switch_option "pthread",
32     (help "Enable threads")),
33  (parameter_option "linker",
34     (help "Choose linker (possible values: gcc, g++)")),
35  (parameter_list_option "include",
36     (help "Include the named file prior to preprocessing")),
37  (prefix_list_option "I",
38     (help "Add a directory to include path")),
39  (prefix_list_option "Wa,",
40     (help "Pass options to assembler")),
41  (prefix_list_option "Wllc,",
42     (help "Pass options to llc")),
43  (prefix_list_option "L",
44     (help "Add a directory to link path")),
45  (prefix_list_option "l",
46     (help "Search a library when linking")),
47  (prefix_list_option "Wl,",
48     (help "Pass options to linker")),
49  (prefix_list_option "Wo,",
50     (help "Pass options to opt"))
51 ]>;
52
53 // Tools
54
55 class llvm_gcc_based <string cmd_prefix, string in_lang, string E_ext> : Tool<
56 [(in_language in_lang),
57  (out_language "llvm-bitcode"),
58  (output_suffix "bc"),
59  (cmd_line (case
60             (switch_on "E"),
61               (case (not_empty "o"),
62                     !strconcat(cmd_prefix, " -E $INFILE -o $OUTFILE"),
63                     (default),
64                     !strconcat(cmd_prefix, " -E $INFILE")),
65             (switch_on "fsyntax-only"),
66               !strconcat(cmd_prefix, " -fsyntax-only $INFILE"),
67             (and (switch_on "S"), (switch_on "emit-llvm")),
68               !strconcat(cmd_prefix, " -S $INFILE -o $OUTFILE -emit-llvm"),
69             (default),
70               !strconcat(cmd_prefix, " -c $INFILE -o $OUTFILE -emit-llvm"))),
71  (actions
72      (case
73          (switch_on "E"), [(stop_compilation), (output_suffix E_ext)],
74          (and (switch_on "emit-llvm"), (switch_on "S")),
75               [(output_suffix "ll"), (stop_compilation)],
76          (and (switch_on "emit-llvm"), (switch_on "c")), (stop_compilation),
77          (switch_on "fsyntax-only"), (stop_compilation),
78          (not_empty "include"), (forward "include"),
79          (not_empty "I"), (forward "I"))),
80  (sink)
81 ]>;
82
83 def llvm_gcc_c : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x c", "c", "i">;
84 def llvm_gcc_cpp : llvm_gcc_based<"@LLVMGXXCOMMAND@ -x c++", "c++", "i">;
85 def llvm_gcc_m : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c", "objective-c", "mi">;
86 def llvm_gcc_mxx : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c++",
87                                   "objective-c++", "mi">;
88
89 def opt : Tool<
90 [(in_language "llvm-bitcode"),
91  (out_language "llvm-bitcode"),
92  (output_suffix "bc"),
93  (actions (case (not_empty "Wo,"), (unpack_values "Wo,"))),
94  (cmd_line "opt -f $INFILE -o $OUTFILE")
95 ]>;
96
97 def llvm_as : Tool<
98 [(in_language "llvm-assembler"),
99  (out_language "llvm-bitcode"),
100  (output_suffix "bc"),
101  (cmd_line "llvm-as $INFILE -o $OUTFILE")
102 ]>;
103
104 def llvm_gcc_assembler : Tool<
105 [(in_language "assembler"),
106  (out_language "object-code"),
107  (output_suffix "o"),
108  (cmd_line "@LLVMGCCCOMMAND@ -c -x assembler $INFILE -o $OUTFILE"),
109  (actions (case
110           (switch_on "c"), (stop_compilation),
111           (not_empty "Wa,"), (unpack_values "Wa,")))
112 ]>;
113
114 def llc : Tool<
115 [(in_language "llvm-bitcode"),
116  (out_language "assembler"),
117  (output_suffix "s"),
118  (cmd_line "llc -f $INFILE -o $OUTFILE"),
119  (actions (case
120           (switch_on "S"), (stop_compilation),
121           (not_empty "Wllc,"), (unpack_values "Wllc,")))
122 ]>;
123
124 // Base class for linkers
125 class llvm_gcc_based_linker <string cmd_prefix> : Tool<
126 [(in_language "object-code"),
127  (out_language "executable"),
128  (output_suffix "out"),
129  (cmd_line !strconcat(cmd_prefix, " $INFILE -o $OUTFILE")),
130  (join),
131  (actions (case
132           (switch_on "pthread"), (append_cmd "-lpthread"),
133           (not_empty "L"), (forward "L"),
134           (not_empty "l"), (forward "l"),
135           (not_empty "Wl,"), (unpack_values "Wl,")))
136 ]>;
137
138 // Default linker
139 def llvm_gcc_linker : llvm_gcc_based_linker<"@LLVMGCCCOMMAND@">;
140 // Alternative linker for C++
141 def llvm_gcc_cpp_linker : llvm_gcc_based_linker<"@LLVMGXXCOMMAND@">;
142
143 // Language map
144
145 def LanguageMap : LanguageMap<
146     [LangToSuffixes<"c++", ["cc", "cp", "cxx", "cpp", "CPP", "c++", "C"]>,
147      LangToSuffixes<"c", ["c"]>,
148      LangToSuffixes<"c-cpp-output", ["i"]>,
149      LangToSuffixes<"objective-c-cpp-output", ["mi"]>,
150      LangToSuffixes<"objective-c++", ["mm"]>,
151      LangToSuffixes<"objective-c", ["m"]>,
152      LangToSuffixes<"assembler", ["s"]>,
153      LangToSuffixes<"assembler-with-cpp", ["S"]>,
154      LangToSuffixes<"llvm-assembler", ["ll"]>,
155      LangToSuffixes<"llvm-bitcode", ["bc"]>,
156      LangToSuffixes<"object-code", ["o"]>,
157      LangToSuffixes<"executable", ["out"]>
158      ]>;
159
160 // Compilation graph
161
162 def CompilationGraph : CompilationGraph<[
163     Edge<"root", "llvm_gcc_c">,
164     Edge<"root", "llvm_gcc_assembler">,
165     Edge<"root", "llvm_gcc_cpp">,
166     Edge<"root", "llvm_gcc_m">,
167     Edge<"root", "llvm_gcc_mxx">,
168     Edge<"root", "llvm_as">,
169
170     Edge<"llvm_gcc_c", "llc">,
171     Edge<"llvm_gcc_cpp", "llc">,
172     Edge<"llvm_gcc_m", "llc">,
173     Edge<"llvm_gcc_mxx", "llc">,
174     Edge<"llvm_as", "llc">,
175
176     OptionalEdge<"llvm_gcc_c", "opt", (case (switch_on "opt"), (inc_weight))>,
177     OptionalEdge<"llvm_gcc_cpp", "opt", (case (switch_on "opt"), (inc_weight))>,
178     OptionalEdge<"llvm_gcc_m", "opt", (case (switch_on "opt"), (inc_weight))>,
179     OptionalEdge<"llvm_gcc_mxx", "opt", (case (switch_on "opt"), (inc_weight))>,
180     OptionalEdge<"llvm_as", "opt", (case (switch_on "opt"), (inc_weight))>,
181     Edge<"opt", "llc">,
182
183     Edge<"llc", "llvm_gcc_assembler">,
184     Edge<"llvm_gcc_assembler", "llvm_gcc_linker">,
185     OptionalEdge<"llvm_gcc_assembler", "llvm_gcc_cpp_linker",
186                  (case
187                      (or (input_languages_contain "c++"),
188                          (input_languages_contain "objective-c++")),
189                      (inc_weight),
190                      (or (parameter_equals "linker", "g++"),
191                          (parameter_equals "linker", "c++")), (inc_weight))>,
192
193
194     Edge<"root", "llvm_gcc_linker">,
195     OptionalEdge<"root", "llvm_gcc_cpp_linker",
196                  (case
197                      (or (input_languages_contain "c++"),
198                          (input_languages_contain "objective-c++")),
199                      (inc_weight),
200                      (or (parameter_equals "linker", "g++"),
201                          (parameter_equals "linker", "c++")), (inc_weight))>
202     ]>;