1 //===- Base.td - LLVMC2 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 llvmc2.
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_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"))
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"),
61 (case (not_empty "o"),
62 !strconcat(cmd_prefix, " -E $INFILE -o $OUTFILE"),
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"),
70 !strconcat(cmd_prefix, " -c $INFILE -o $OUTFILE -emit-llvm"))),
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"))),
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">;
90 [(in_language "llvm-bitcode"),
91 (out_language "llvm-bitcode"),
93 (actions (case (not_empty "Wo,"), (unpack_values "Wo,"))),
94 (cmd_line "opt -f $INFILE -o $OUTFILE")
98 [(in_language "llvm-assembler"),
99 (out_language "llvm-bitcode"),
100 (output_suffix "bc"),
101 (cmd_line "llvm-as $INFILE -o $OUTFILE")
104 def llvm_gcc_assembler : Tool<
105 [(in_language "assembler"),
106 (out_language "object-code"),
108 (cmd_line "@LLVMGCCCOMMAND@ -c -x assembler $INFILE -o $OUTFILE"),
110 (switch_on "c"), (stop_compilation),
111 (not_empty "Wa,"), (unpack_values "Wa,")))
115 [(in_language "llvm-bitcode"),
116 (out_language "assembler"),
118 (cmd_line "llc -f $INFILE -o $OUTFILE"),
120 (switch_on "S"), (stop_compilation),
121 (not_empty "Wllc,"), (unpack_values "Wllc,")))
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")),
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,")))
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@">;
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"]>
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">,
171 Edge<"llvm_gcc_c", "llc">,
172 Edge<"llvm_gcc_cpp", "llc">,
173 Edge<"llvm_gcc_m", "llc">,
174 Edge<"llvm_gcc_mxx", "llc">,
175 Edge<"llvm_as", "llc">,
177 OptionalEdge<"llvm_gcc_c", "opt", (case (switch_on "opt"), (inc_weight))>,
178 OptionalEdge<"llvm_gcc_cpp", "opt", (case (switch_on "opt"), (inc_weight))>,
179 OptionalEdge<"llvm_gcc_m", "opt", (case (switch_on "opt"), (inc_weight))>,
180 OptionalEdge<"llvm_gcc_mxx", "opt", (case (switch_on "opt"), (inc_weight))>,
181 OptionalEdge<"llvm_as", "opt", (case (switch_on "opt"), (inc_weight))>,
184 Edge<"llc", "llvm_gcc_assembler">,
185 Edge<"llvm_gcc_assembler", "llvm_gcc_linker">,
186 OptionalEdge<"llvm_gcc_assembler", "llvm_gcc_cpp_linker",
188 (or (input_languages_contain "c++"),
189 (input_languages_contain "objective-c++")),
191 (or (parameter_equals "linker", "g++"),
192 (parameter_equals "linker", "c++")), (inc_weight))>,
195 Edge<"root", "llvm_gcc_linker">,
196 OptionalEdge<"root", "llvm_gcc_cpp_linker",
198 (or (input_languages_contain "c++"),
199 (input_languages_contain "objective-c++")),
201 (or (parameter_equals "linker", "g++"),
202 (parameter_equals "linker", "c++")), (inc_weight))>