blob: be325a00410460b7ab11fb41fb904f5977dcc879 [file] [log] [blame]
Mikhail Glushenkov6d80d2b2009-10-08 04:40:28 +00001//===- Base.td - LLVMC toolchain descriptions --------------*- tablegen -*-===//
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +00002//
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//
Mikhail Glushenkov6d80d2b2009-10-08 04:40:28 +000010// This file contains compilation graph description used by llvmc.
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +000011//
12//===----------------------------------------------------------------------===//
13
Mikhail Glushenkove4a5ea32008-10-02 21:15:05 +000014include "llvm/CompilerDriver/Common.td"
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +000015
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +000016// Options
17
18def 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++)")),
Mikhail Glushenkov6d80d2b2009-10-08 04:40:28 +000035 (parameter_option "MF",
36 (help "Specify a file to write dependencies to"), (hidden)),
37 (parameter_option "MT",
38 (help "Change the name of the rule emitted by dependency generation"),
39 (hidden)),
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +000040 (parameter_list_option "include",
41 (help "Include the named file prior to preprocessing")),
42 (prefix_list_option "I",
43 (help "Add a directory to include path")),
Mikhail Glushenkov6d80d2b2009-10-08 04:40:28 +000044 (prefix_list_option "D",
45 (help "Define a macro")),
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +000046 (prefix_list_option "Wa,",
47 (help "Pass options to assembler")),
Mikhail Glushenkov46801022009-03-31 18:33:54 +000048 (prefix_list_option "Wllc,",
49 (help "Pass options to llc")),
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +000050 (prefix_list_option "L",
51 (help "Add a directory to link path")),
52 (prefix_list_option "l",
53 (help "Search a library when linking")),
54 (prefix_list_option "Wl,",
Mikhail Glushenkovba71d672008-12-11 22:19:14 +000055 (help "Pass options to linker")),
56 (prefix_list_option "Wo,",
57 (help "Pass options to opt"))
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +000058]>;
59
60// Tools
61
62class llvm_gcc_based <string cmd_prefix, string in_lang, string E_ext> : Tool<
63[(in_language in_lang),
64 (out_language "llvm-bitcode"),
65 (output_suffix "bc"),
66 (cmd_line (case
67 (switch_on "E"),
68 (case (not_empty "o"),
69 !strconcat(cmd_prefix, " -E $INFILE -o $OUTFILE"),
70 (default),
71 !strconcat(cmd_prefix, " -E $INFILE")),
72 (switch_on "fsyntax-only"),
73 !strconcat(cmd_prefix, " -fsyntax-only $INFILE"),
74 (and (switch_on "S"), (switch_on "emit-llvm")),
75 !strconcat(cmd_prefix, " -S $INFILE -o $OUTFILE -emit-llvm"),
76 (default),
77 !strconcat(cmd_prefix, " -c $INFILE -o $OUTFILE -emit-llvm"))),
78 (actions
79 (case
Mikhail Glushenkovad981bf2009-09-28 01:16:42 +000080 (and (multiple_input_files), (or (switch_on "S"), (switch_on "c"))),
81 (error "cannot specify -o with -c or -S with multiple files"),
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +000082 (switch_on "E"), [(stop_compilation), (output_suffix E_ext)],
83 (and (switch_on "emit-llvm"), (switch_on "S")),
84 [(output_suffix "ll"), (stop_compilation)],
85 (and (switch_on "emit-llvm"), (switch_on "c")), (stop_compilation),
86 (switch_on "fsyntax-only"), (stop_compilation),
87 (not_empty "include"), (forward "include"),
Mikhail Glushenkov976248d2009-10-08 06:03:38 +000088 (not_empty "I"), (forward "I"),
89 (not_empty "D"), (forward "D"),
90 (not_empty "MF"), (forward "MF"),
Mikhail Glushenkov6d80d2b2009-10-08 04:40:28 +000091 (not_empty "MT"), (forward "MT"))),
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +000092 (sink)
93]>;
94
Mikhail Glushenkov4558f482009-04-21 19:46:10 +000095def llvm_gcc_c : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x c", "c", "i">;
96def llvm_gcc_cpp : llvm_gcc_based<"@LLVMGXXCOMMAND@ -x c++", "c++", "i">;
Mikhail Glushenkov6d80d2b2009-10-08 04:40:28 +000097def llvm_gcc_m : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c",
98 "objective-c", "mi">;
Mikhail Glushenkov4558f482009-04-21 19:46:10 +000099def llvm_gcc_mxx : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c++",
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +0000100 "objective-c++", "mi">;
101
102def opt : Tool<
103[(in_language "llvm-bitcode"),
104 (out_language "llvm-bitcode"),
105 (output_suffix "bc"),
Mikhail Glushenkovba71d672008-12-11 22:19:14 +0000106 (actions (case (not_empty "Wo,"), (unpack_values "Wo,"))),
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +0000107 (cmd_line "opt -f $INFILE -o $OUTFILE")
108]>;
109
110def llvm_as : Tool<
111[(in_language "llvm-assembler"),
112 (out_language "llvm-bitcode"),
113 (output_suffix "bc"),
Mikhail Glushenkov3ab68892009-10-09 05:45:01 +0000114 (cmd_line "llvm-as $INFILE -o $OUTFILE"),
115 (actions (case (switch_on "emit-llvm"), (stop_compilation)))
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +0000116]>;
117
118def llvm_gcc_assembler : Tool<
119[(in_language "assembler"),
120 (out_language "object-code"),
121 (output_suffix "o"),
Mikhail Glushenkov4558f482009-04-21 19:46:10 +0000122 (cmd_line "@LLVMGCCCOMMAND@ -c -x assembler $INFILE -o $OUTFILE"),
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +0000123 (actions (case
124 (switch_on "c"), (stop_compilation),
125 (not_empty "Wa,"), (unpack_values "Wa,")))
126]>;
127
128def llc : Tool<
Mikhail Glushenkov3ab68892009-10-09 05:45:01 +0000129[(in_language ["llvm-bitcode", "llvm-assembler"]),
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +0000130 (out_language "assembler"),
131 (output_suffix "s"),
Mikhail Glushenkov46801022009-03-31 18:33:54 +0000132 (cmd_line "llc -f $INFILE -o $OUTFILE"),
133 (actions (case
134 (switch_on "S"), (stop_compilation),
135 (not_empty "Wllc,"), (unpack_values "Wllc,")))
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +0000136]>;
137
138// Base class for linkers
139class llvm_gcc_based_linker <string cmd_prefix> : Tool<
140[(in_language "object-code"),
141 (out_language "executable"),
142 (output_suffix "out"),
143 (cmd_line !strconcat(cmd_prefix, " $INFILE -o $OUTFILE")),
144 (join),
145 (actions (case
146 (switch_on "pthread"), (append_cmd "-lpthread"),
147 (not_empty "L"), (forward "L"),
148 (not_empty "l"), (forward "l"),
Mikhail Glushenkov6d80d2b2009-10-08 04:40:28 +0000149 (not_empty "Wl,"), (forward "Wl,")))
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +0000150]>;
151
152// Default linker
Mikhail Glushenkov4558f482009-04-21 19:46:10 +0000153def llvm_gcc_linker : llvm_gcc_based_linker<"@LLVMGCCCOMMAND@">;
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +0000154// Alternative linker for C++
Mikhail Glushenkov4558f482009-04-21 19:46:10 +0000155def llvm_gcc_cpp_linker : llvm_gcc_based_linker<"@LLVMGXXCOMMAND@">;
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +0000156
157// Language map
158
159def LanguageMap : LanguageMap<
160 [LangToSuffixes<"c++", ["cc", "cp", "cxx", "cpp", "CPP", "c++", "C"]>,
161 LangToSuffixes<"c", ["c"]>,
162 LangToSuffixes<"c-cpp-output", ["i"]>,
163 LangToSuffixes<"objective-c-cpp-output", ["mi"]>,
164 LangToSuffixes<"objective-c++", ["mm"]>,
165 LangToSuffixes<"objective-c", ["m"]>,
166 LangToSuffixes<"assembler", ["s"]>,
167 LangToSuffixes<"assembler-with-cpp", ["S"]>,
168 LangToSuffixes<"llvm-assembler", ["ll"]>,
169 LangToSuffixes<"llvm-bitcode", ["bc"]>,
170 LangToSuffixes<"object-code", ["o"]>,
171 LangToSuffixes<"executable", ["out"]>
172 ]>;
173
174// Compilation graph
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000175
Mikhail Glushenkov0d08db02008-05-06 16:35:25 +0000176def CompilationGraph : CompilationGraph<[
Mikhail Glushenkov01088772008-11-17 17:29:18 +0000177 Edge<"root", "llvm_gcc_c">,
178 Edge<"root", "llvm_gcc_assembler">,
179 Edge<"root", "llvm_gcc_cpp">,
180 Edge<"root", "llvm_gcc_m">,
181 Edge<"root", "llvm_gcc_mxx">,
Mikhail Glushenkov57a7e942009-09-10 17:04:32 +0000182 Edge<"root", "llc">,
Mikhail Glushenkovd752c3f2008-05-06 16:36:50 +0000183
Mikhail Glushenkov01088772008-11-17 17:29:18 +0000184 Edge<"llvm_gcc_c", "llc">,
185 Edge<"llvm_gcc_cpp", "llc">,
186 Edge<"llvm_gcc_m", "llc">,
187 Edge<"llvm_gcc_mxx", "llc">,
188 Edge<"llvm_as", "llc">,
Mikhail Glushenkovd752c3f2008-05-06 16:36:50 +0000189
Mikhail Glushenkov3ab68892009-10-09 05:45:01 +0000190 OptionalEdge<"root", "llvm_as",
191 (case (switch_on "emit-llvm"), (inc_weight))>,
Mikhail Glushenkov01088772008-11-17 17:29:18 +0000192 OptionalEdge<"llvm_gcc_c", "opt", (case (switch_on "opt"), (inc_weight))>,
193 OptionalEdge<"llvm_gcc_cpp", "opt", (case (switch_on "opt"), (inc_weight))>,
194 OptionalEdge<"llvm_gcc_m", "opt", (case (switch_on "opt"), (inc_weight))>,
195 OptionalEdge<"llvm_gcc_mxx", "opt", (case (switch_on "opt"), (inc_weight))>,
196 OptionalEdge<"llvm_as", "opt", (case (switch_on "opt"), (inc_weight))>,
197 Edge<"opt", "llc">,
Mikhail Glushenkovd752c3f2008-05-06 16:36:50 +0000198
Mikhail Glushenkov01088772008-11-17 17:29:18 +0000199 Edge<"llc", "llvm_gcc_assembler">,
200 Edge<"llvm_gcc_assembler", "llvm_gcc_linker">,
201 OptionalEdge<"llvm_gcc_assembler", "llvm_gcc_cpp_linker",
Mikhail Glushenkove5557f42008-05-30 06:08:50 +0000202 (case
Daniel Dunbar77e0c852008-11-08 03:25:47 +0000203 (or (input_languages_contain "c++"),
Mikhail Glushenkov01088772008-11-17 17:29:18 +0000204 (input_languages_contain "objective-c++")),
Daniel Dunbar77e0c852008-11-08 03:25:47 +0000205 (inc_weight),
Mikhail Glushenkove5557f42008-05-30 06:08:50 +0000206 (or (parameter_equals "linker", "g++"),
207 (parameter_equals "linker", "c++")), (inc_weight))>,
Mikhail Glushenkov35a85e82008-05-06 18:10:20 +0000208
Mikhail Glushenkov978d4982008-05-06 18:13:00 +0000209
Mikhail Glushenkov01088772008-11-17 17:29:18 +0000210 Edge<"root", "llvm_gcc_linker">,
211 OptionalEdge<"root", "llvm_gcc_cpp_linker",
Mikhail Glushenkove5557f42008-05-30 06:08:50 +0000212 (case
Daniel Dunbar77e0c852008-11-08 03:25:47 +0000213 (or (input_languages_contain "c++"),
Mikhail Glushenkov01088772008-11-17 17:29:18 +0000214 (input_languages_contain "objective-c++")),
Daniel Dunbar77e0c852008-11-08 03:25:47 +0000215 (inc_weight),
Mikhail Glushenkove5557f42008-05-30 06:08:50 +0000216 (or (parameter_equals "linker", "g++"),
217 (parameter_equals "linker", "c++")), (inc_weight))>
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000218 ]>;