blob: d4bff17a3180368006d759b0ef81ef032f17b6c4 [file] [log] [blame]
Mikhail Glushenkov9d1b6962008-10-03 09:09:34 +00001//===- Base.td - LLVMC2 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 Glushenkovd92f2e02008-09-22 20:46:44 +000010// This file contains compilation graph description used by llvmc2.
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++)")),
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")),
Mikhail Glushenkov46801022009-03-31 18:33:54 +000041 (prefix_list_option "Wllc,",
42 (help "Pass options to llc")),
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +000043 (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,",
Mikhail Glushenkovba71d672008-12-11 22:19:14 +000048 (help "Pass options to linker")),
49 (prefix_list_option "Wo,",
50 (help "Pass options to opt"))
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +000051]>;
52
53// Tools
54
55class 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
Mikhail Glushenkov4558f482009-04-21 19:46:10 +000083def llvm_gcc_c : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x c", "c", "i">;
84def llvm_gcc_cpp : llvm_gcc_based<"@LLVMGXXCOMMAND@ -x c++", "c++", "i">;
85def llvm_gcc_m : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c", "objective-c", "mi">;
86def llvm_gcc_mxx : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c++",
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +000087 "objective-c++", "mi">;
88
89def opt : Tool<
90[(in_language "llvm-bitcode"),
91 (out_language "llvm-bitcode"),
92 (output_suffix "bc"),
Mikhail Glushenkovba71d672008-12-11 22:19:14 +000093 (actions (case (not_empty "Wo,"), (unpack_values "Wo,"))),
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +000094 (cmd_line "opt -f $INFILE -o $OUTFILE")
95]>;
96
97def 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
104def llvm_gcc_assembler : Tool<
105[(in_language "assembler"),
106 (out_language "object-code"),
107 (output_suffix "o"),
Mikhail Glushenkov4558f482009-04-21 19:46:10 +0000108 (cmd_line "@LLVMGCCCOMMAND@ -c -x assembler $INFILE -o $OUTFILE"),
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +0000109 (actions (case
110 (switch_on "c"), (stop_compilation),
111 (not_empty "Wa,"), (unpack_values "Wa,")))
112]>;
113
114def llc : Tool<
115[(in_language "llvm-bitcode"),
116 (out_language "assembler"),
117 (output_suffix "s"),
Mikhail Glushenkov46801022009-03-31 18:33:54 +0000118 (cmd_line "llc -f $INFILE -o $OUTFILE"),
119 (actions (case
120 (switch_on "S"), (stop_compilation),
121 (not_empty "Wllc,"), (unpack_values "Wllc,")))
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +0000122]>;
123
124// Base class for linkers
125class 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
Mikhail Glushenkov4558f482009-04-21 19:46:10 +0000139def llvm_gcc_linker : llvm_gcc_based_linker<"@LLVMGCCCOMMAND@">;
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +0000140// Alternative linker for C++
Mikhail Glushenkov4558f482009-04-21 19:46:10 +0000141def llvm_gcc_cpp_linker : llvm_gcc_based_linker<"@LLVMGXXCOMMAND@">;
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +0000142
143// Language map
144
145def 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
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000161
Mikhail Glushenkov0d08db02008-05-06 16:35:25 +0000162def CompilationGraph : CompilationGraph<[
Mikhail Glushenkov01088772008-11-17 17:29:18 +0000163 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">,
Mikhail Glushenkov57a7e942009-09-10 17:04:32 +0000169 Edge<"root", "llc">,
Mikhail Glushenkovd752c3f2008-05-06 16:36:50 +0000170
Mikhail Glushenkov01088772008-11-17 17:29:18 +0000171 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">,
Mikhail Glushenkovd752c3f2008-05-06 16:36:50 +0000176
Mikhail Glushenkov01088772008-11-17 17:29:18 +0000177 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))>,
182 Edge<"opt", "llc">,
Mikhail Glushenkovd752c3f2008-05-06 16:36:50 +0000183
Mikhail Glushenkov01088772008-11-17 17:29:18 +0000184 Edge<"llc", "llvm_gcc_assembler">,
185 Edge<"llvm_gcc_assembler", "llvm_gcc_linker">,
186 OptionalEdge<"llvm_gcc_assembler", "llvm_gcc_cpp_linker",
Mikhail Glushenkove5557f42008-05-30 06:08:50 +0000187 (case
Daniel Dunbar77e0c852008-11-08 03:25:47 +0000188 (or (input_languages_contain "c++"),
Mikhail Glushenkov01088772008-11-17 17:29:18 +0000189 (input_languages_contain "objective-c++")),
Daniel Dunbar77e0c852008-11-08 03:25:47 +0000190 (inc_weight),
Mikhail Glushenkove5557f42008-05-30 06:08:50 +0000191 (or (parameter_equals "linker", "g++"),
192 (parameter_equals "linker", "c++")), (inc_weight))>,
Mikhail Glushenkov35a85e82008-05-06 18:10:20 +0000193
Mikhail Glushenkov978d4982008-05-06 18:13:00 +0000194
Mikhail Glushenkov01088772008-11-17 17:29:18 +0000195 Edge<"root", "llvm_gcc_linker">,
196 OptionalEdge<"root", "llvm_gcc_cpp_linker",
Mikhail Glushenkove5557f42008-05-30 06:08:50 +0000197 (case
Daniel Dunbar77e0c852008-11-08 03:25:47 +0000198 (or (input_languages_contain "c++"),
Mikhail Glushenkov01088772008-11-17 17:29:18 +0000199 (input_languages_contain "objective-c++")),
Daniel Dunbar77e0c852008-11-08 03:25:47 +0000200 (inc_weight),
Mikhail Glushenkove5557f42008-05-30 06:08:50 +0000201 (or (parameter_equals "linker", "g++"),
202 (parameter_equals "linker", "c++")), (inc_weight))>
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000203 ]>;