1 //===- Base.td - LLVMC toolchain descriptions --------------*- tablegen -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains compilation graph description used by llvmc.
12 //===----------------------------------------------------------------------===//
14 include "llvm/CompilerDriver/Common.td"
18 def OptList : OptionList<[
19 (switch_option "emit-llvm",
20 (help "Emit LLVM .ll files instead of native object files")),
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")),
28 (help "Stop after compilation, do not assemble")),
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_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"),
40 (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")),
44 (prefix_list_option "D",
45 (help "Define a macro")),
46 (prefix_list_option "Wa,",
47 (help "Pass options to assembler")),
48 (prefix_list_option "Wllc,",
49 (help "Pass options to llc")),
50 (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,",
55 (help "Pass options to linker")),
56 (prefix_list_option "Wo,",
57 (help "Pass options to opt"))
62 class llvm_gcc_based <string cmd_prefix, string in_lang, string E_ext> : Tool<
63 [(in_language in_lang),
64 (out_language "llvm-bitcode"),
68 (case (not_empty "o"),
69 !strconcat(cmd_prefix, " -E $INFILE -o $OUTFILE"),
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"),
77 !strconcat(cmd_prefix, " -c $INFILE -o $OUTFILE -emit-llvm"))),
80 (and (multiple_input_files), (or (switch_on "S"), (switch_on "c"))),
81 (error "cannot specify -o with -c or -S with multiple files"),
82 (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"),
88 (not_empty "I"), (forward "I"),
89 (not_empty "D"), (forward "D"),
90 (not_empty "MF"), (forward "MF"),
91 (not_empty "MT"), (forward "MT"))),
95 def llvm_gcc_c : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x c", "c", "i">;
96 def llvm_gcc_cpp : llvm_gcc_based<"@LLVMGXXCOMMAND@ -x c++", "c++", "i">;
97 def llvm_gcc_m : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c",
99 def llvm_gcc_mxx : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c++",
100 "objective-c++", "mi">;
103 [(in_language "llvm-bitcode"),
104 (out_language "llvm-bitcode"),
105 (output_suffix "bc"),
106 (actions (case (not_empty "Wo,"), (unpack_values "Wo,"))),
107 (cmd_line "opt -f $INFILE -o $OUTFILE")
111 [(in_language "llvm-assembler"),
112 (out_language "llvm-bitcode"),
113 (output_suffix "bc"),
114 (cmd_line "llvm-as $INFILE -o $OUTFILE"),
115 (actions (case (switch_on "emit-llvm"), (stop_compilation)))
118 def llvm_gcc_assembler : Tool<
119 [(in_language "assembler"),
120 (out_language "object-code"),
122 (cmd_line "@LLVMGCCCOMMAND@ -c -x assembler $INFILE -o $OUTFILE"),
124 (switch_on "c"), (stop_compilation),
125 (not_empty "Wa,"), (unpack_values "Wa,")))
129 [(in_language ["llvm-bitcode", "llvm-assembler"]),
130 (out_language "assembler"),
132 (cmd_line "llc -f $INFILE -o $OUTFILE"),
134 (switch_on "S"), (stop_compilation),
135 (not_empty "Wllc,"), (unpack_values "Wllc,")))
138 // Base class for linkers
139 class 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")),
146 (switch_on "pthread"), (append_cmd "-lpthread"),
147 (not_empty "L"), (forward "L"),
148 (not_empty "l"), (forward "l"),
149 (not_empty "Wl,"), (forward "Wl,")))
153 def llvm_gcc_linker : llvm_gcc_based_linker<"@LLVMGCCCOMMAND@">;
154 // Alternative linker for C++
155 def llvm_gcc_cpp_linker : llvm_gcc_based_linker<"@LLVMGXXCOMMAND@">;
159 def 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"]>
176 def CompilationGraph : CompilationGraph<[
177 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">,
184 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">,
190 OptionalEdge<"root", "llvm_as",
191 (case (switch_on "emit-llvm"), (inc_weight))>,
192 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))>,
199 Edge<"llc", "llvm_gcc_assembler">,
200 Edge<"llvm_gcc_assembler", "llvm_gcc_linker">,
201 OptionalEdge<"llvm_gcc_assembler", "llvm_gcc_cpp_linker",
203 (or (input_languages_contain "c++"),
204 (input_languages_contain "objective-c++")),
206 (or (parameter_equals "linker", "g++"),
207 (parameter_equals "linker", "c++")), (inc_weight))>,
210 Edge<"root", "llvm_gcc_linker">,
211 OptionalEdge<"root", "llvm_gcc_cpp_linker",
213 (or (input_languages_contain "c++"),
214 (input_languages_contain "objective-c++")),
216 (or (parameter_equals "linker", "g++"),
217 (parameter_equals "linker", "c++")), (inc_weight))>