blob: 18372de617e943373f4b41e4d8ff3cc2958a64dc [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")),
41 (prefix_list_option "L",
42 (help "Add a directory to link path")),
43 (prefix_list_option "l",
44 (help "Search a library when linking")),
45 (prefix_list_option "Wl,",
Mikhail Glushenkovba71d672008-12-11 22:19:14 +000046 (help "Pass options to linker")),
47 (prefix_list_option "Wo,",
48 (help "Pass options to opt"))
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +000049]>;
50
51// Tools
52
53class llvm_gcc_based <string cmd_prefix, string in_lang, string E_ext> : Tool<
54[(in_language in_lang),
55 (out_language "llvm-bitcode"),
56 (output_suffix "bc"),
57 (cmd_line (case
58 (switch_on "E"),
59 (case (not_empty "o"),
60 !strconcat(cmd_prefix, " -E $INFILE -o $OUTFILE"),
61 (default),
62 !strconcat(cmd_prefix, " -E $INFILE")),
63 (switch_on "fsyntax-only"),
64 !strconcat(cmd_prefix, " -fsyntax-only $INFILE"),
65 (and (switch_on "S"), (switch_on "emit-llvm")),
66 !strconcat(cmd_prefix, " -S $INFILE -o $OUTFILE -emit-llvm"),
67 (default),
68 !strconcat(cmd_prefix, " -c $INFILE -o $OUTFILE -emit-llvm"))),
69 (actions
70 (case
71 (switch_on "E"), [(stop_compilation), (output_suffix E_ext)],
72 (and (switch_on "emit-llvm"), (switch_on "S")),
73 [(output_suffix "ll"), (stop_compilation)],
74 (and (switch_on "emit-llvm"), (switch_on "c")), (stop_compilation),
75 (switch_on "fsyntax-only"), (stop_compilation),
76 (not_empty "include"), (forward "include"),
77 (not_empty "I"), (forward "I"))),
78 (sink)
79]>;
80
81def llvm_gcc_c : llvm_gcc_based<"llvm-gcc -x c", "c", "i">;
82def llvm_gcc_cpp : llvm_gcc_based<"llvm-g++ -x c++", "c++", "i">;
83def llvm_gcc_m : llvm_gcc_based<"llvm-gcc -x objective-c", "objective-c", "mi">;
84def llvm_gcc_mxx : llvm_gcc_based<"llvm-gcc -x objective-c++",
85 "objective-c++", "mi">;
86
87def opt : Tool<
88[(in_language "llvm-bitcode"),
89 (out_language "llvm-bitcode"),
90 (output_suffix "bc"),
Mikhail Glushenkovba71d672008-12-11 22:19:14 +000091 (actions (case (not_empty "Wo,"), (unpack_values "Wo,"))),
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +000092 (cmd_line "opt -f $INFILE -o $OUTFILE")
93]>;
94
95def llvm_as : Tool<
96[(in_language "llvm-assembler"),
97 (out_language "llvm-bitcode"),
98 (output_suffix "bc"),
99 (cmd_line "llvm-as $INFILE -o $OUTFILE")
100]>;
101
102def llvm_gcc_assembler : Tool<
103[(in_language "assembler"),
104 (out_language "object-code"),
105 (output_suffix "o"),
106 (cmd_line "llvm-gcc -c -x assembler $INFILE -o $OUTFILE"),
107 (actions (case
108 (switch_on "c"), (stop_compilation),
109 (not_empty "Wa,"), (unpack_values "Wa,")))
110]>;
111
112def llc : Tool<
113[(in_language "llvm-bitcode"),
114 (out_language "assembler"),
115 (output_suffix "s"),
116 (cmd_line "llc -relocation-model=pic -f $INFILE -o $OUTFILE"),
117 (actions (case (switch_on "S"), (stop_compilation)))
118]>;
119
120// Base class for linkers
121class llvm_gcc_based_linker <string cmd_prefix> : Tool<
122[(in_language "object-code"),
123 (out_language "executable"),
124 (output_suffix "out"),
125 (cmd_line !strconcat(cmd_prefix, " $INFILE -o $OUTFILE")),
126 (join),
127 (actions (case
128 (switch_on "pthread"), (append_cmd "-lpthread"),
129 (not_empty "L"), (forward "L"),
130 (not_empty "l"), (forward "l"),
131 (not_empty "Wl,"), (unpack_values "Wl,")))
132]>;
133
134// Default linker
135def llvm_gcc_linker : llvm_gcc_based_linker<"llvm-gcc">;
136// Alternative linker for C++
137def llvm_gcc_cpp_linker : llvm_gcc_based_linker<"llvm-g++">;
138
139// Language map
140
141def LanguageMap : LanguageMap<
142 [LangToSuffixes<"c++", ["cc", "cp", "cxx", "cpp", "CPP", "c++", "C"]>,
143 LangToSuffixes<"c", ["c"]>,
144 LangToSuffixes<"c-cpp-output", ["i"]>,
145 LangToSuffixes<"objective-c-cpp-output", ["mi"]>,
146 LangToSuffixes<"objective-c++", ["mm"]>,
147 LangToSuffixes<"objective-c", ["m"]>,
148 LangToSuffixes<"assembler", ["s"]>,
149 LangToSuffixes<"assembler-with-cpp", ["S"]>,
150 LangToSuffixes<"llvm-assembler", ["ll"]>,
151 LangToSuffixes<"llvm-bitcode", ["bc"]>,
152 LangToSuffixes<"object-code", ["o"]>,
153 LangToSuffixes<"executable", ["out"]>
154 ]>;
155
156// Compilation graph
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000157
Mikhail Glushenkov0d08db02008-05-06 16:35:25 +0000158def CompilationGraph : CompilationGraph<[
Mikhail Glushenkov01088772008-11-17 17:29:18 +0000159 Edge<"root", "llvm_gcc_c">,
160 Edge<"root", "llvm_gcc_assembler">,
161 Edge<"root", "llvm_gcc_cpp">,
162 Edge<"root", "llvm_gcc_m">,
163 Edge<"root", "llvm_gcc_mxx">,
164 Edge<"root", "llvm_as">,
Mikhail Glushenkovd752c3f2008-05-06 16:36:50 +0000165
Mikhail Glushenkov01088772008-11-17 17:29:18 +0000166 Edge<"llvm_gcc_c", "llc">,
167 Edge<"llvm_gcc_cpp", "llc">,
168 Edge<"llvm_gcc_m", "llc">,
169 Edge<"llvm_gcc_mxx", "llc">,
170 Edge<"llvm_as", "llc">,
Mikhail Glushenkovd752c3f2008-05-06 16:36:50 +0000171
Mikhail Glushenkov01088772008-11-17 17:29:18 +0000172 OptionalEdge<"llvm_gcc_c", "opt", (case (switch_on "opt"), (inc_weight))>,
173 OptionalEdge<"llvm_gcc_cpp", "opt", (case (switch_on "opt"), (inc_weight))>,
174 OptionalEdge<"llvm_gcc_m", "opt", (case (switch_on "opt"), (inc_weight))>,
175 OptionalEdge<"llvm_gcc_mxx", "opt", (case (switch_on "opt"), (inc_weight))>,
176 OptionalEdge<"llvm_as", "opt", (case (switch_on "opt"), (inc_weight))>,
177 Edge<"opt", "llc">,
Mikhail Glushenkovd752c3f2008-05-06 16:36:50 +0000178
Mikhail Glushenkov01088772008-11-17 17:29:18 +0000179 Edge<"llc", "llvm_gcc_assembler">,
180 Edge<"llvm_gcc_assembler", "llvm_gcc_linker">,
181 OptionalEdge<"llvm_gcc_assembler", "llvm_gcc_cpp_linker",
Mikhail Glushenkove5557f42008-05-30 06:08:50 +0000182 (case
Daniel Dunbar77e0c852008-11-08 03:25:47 +0000183 (or (input_languages_contain "c++"),
Mikhail Glushenkov01088772008-11-17 17:29:18 +0000184 (input_languages_contain "objective-c++")),
Daniel Dunbar77e0c852008-11-08 03:25:47 +0000185 (inc_weight),
Mikhail Glushenkove5557f42008-05-30 06:08:50 +0000186 (or (parameter_equals "linker", "g++"),
187 (parameter_equals "linker", "c++")), (inc_weight))>,
Mikhail Glushenkov35a85e82008-05-06 18:10:20 +0000188
Mikhail Glushenkov978d4982008-05-06 18:13:00 +0000189
Mikhail Glushenkov01088772008-11-17 17:29:18 +0000190 Edge<"root", "llvm_gcc_linker">,
191 OptionalEdge<"root", "llvm_gcc_cpp_linker",
Mikhail Glushenkove5557f42008-05-30 06:08:50 +0000192 (case
Daniel Dunbar77e0c852008-11-08 03:25:47 +0000193 (or (input_languages_contain "c++"),
Mikhail Glushenkov01088772008-11-17 17:29:18 +0000194 (input_languages_contain "objective-c++")),
Daniel Dunbar77e0c852008-11-08 03:25:47 +0000195 (inc_weight),
Mikhail Glushenkove5557f42008-05-30 06:08:50 +0000196 (or (parameter_equals "linker", "g++"),
197 (parameter_equals "linker", "c++")), (inc_weight))>
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000198 ]>;