Plugin updates: support more options.
[oota-llvm.git] / include / llvm / CompilerDriver / Tools.td
1 //===- Tools.td - Tools description for LLVMC2 -------------*- tablegen -*-===//
2 //
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 //
10 // This file contains descriptions of the various build tools run by llvmc2.
11 //
12 //===----------------------------------------------------------------------===//
13
14 def OptList : OptionList<[
15  (switch_option "emit-llvm",
16     (help "Emit LLVM bitcode files instead of native object files")),
17  (switch_option "E",
18     (help "Stop after the preprocessing stage, do not run the compiler")),
19  (switch_option "fsyntax-only",
20     (help "Stop after checking the input for syntax errors")),
21  (switch_option "opt",
22     (help "Enable opt")),
23  (switch_option "S",
24     (help "Stop after compilation, do not assemble")),
25  (switch_option "c",
26     (help "Compile and assemble, but do not link")),
27  (switch_option "pthread",
28     (help "Enable threads")),
29  (parameter_option "linker",
30     (help "Choose linker (possible values: gcc, g++)")),
31  (parameter_list_option "include",
32     (help "Include the named file prior to preprocessing")),
33  (prefix_list_option "I",
34     (help "Add a directory to include path")),
35  (prefix_list_option "Wa,",
36     (help "Pass options to assembler")),
37  (prefix_list_option "L",
38     (help "Add a directory to link path")),
39  (prefix_list_option "l",
40     (help "Search a library when linking")),
41  (prefix_list_option "Wl,",
42     (help "Pass options to linker"))
43 ]>;
44
45 class llvm_gcc_based <string cmd_prefix, string in_lang> : Tool<
46 [(in_language in_lang),
47  (out_language "llvm-bitcode"),
48  (output_suffix "bc"),
49  (cmd_line (case
50             (switch_on "E"),
51               (case (not_empty "o"),
52                     !strconcat(cmd_prefix, " -E $INFILE -o $OUTFILE"),
53                     (default),
54                     !strconcat(cmd_prefix, " -E $INFILE")),
55             (switch_on "fsyntax-only"),
56               !strconcat(cmd_prefix, " -fsyntax-only $INFILE"),
57             (default),
58               !strconcat(cmd_prefix, " -c $INFILE -o $OUTFILE -emit-llvm"))),
59  (actions
60      (case
61          (switch_on "emit-llvm"), (stop_compilation),
62          (switch_on "E"), [(stop_compilation), (output_suffix "i")],
63          (switch_on "S"), (stop_compilation),
64          (switch_on "fsyntax-only"), (stop_compilation),
65          (not_empty "include"), (forward "include"),
66          (not_empty "I"), (forward "I"))),
67  (sink)
68 ]>;
69
70 def llvm_gcc_c : llvm_gcc_based<"llvm-gcc -x c", "c">;
71 def llvm_gcc_cpp : llvm_gcc_based<"llvm-g++ -x c++", "c++">;
72 def llvm_gcc_m : llvm_gcc_based<"llvm-gcc -x objective-c", "objective-c">;
73 def llvm_gcc_mxx : llvm_gcc_based<"llvm-gcc -x objective-c++", "objective-c++">;
74
75 def opt : Tool<
76 [(in_language "llvm-bitcode"),
77  (out_language "llvm-bitcode"),
78  (output_suffix "bc"),
79  (cmd_line "opt -f $INFILE -o $OUTFILE")
80 ]>;
81
82 def llvm_as : Tool<
83 [(in_language "llvm-assembler"),
84  (out_language "llvm-bitcode"),
85  (output_suffix "bc"),
86  (cmd_line "llvm-as $INFILE -o $OUTFILE")
87 ]>;
88
89 def llvm_gcc_assembler : Tool<
90 [(in_language "assembler"),
91  (out_language "object-code"),
92  (output_suffix "o"),
93  (cmd_line "llvm-gcc -c -x assembler $INFILE -o $OUTFILE"),
94  (actions (case
95           (switch_on "c"), (stop_compilation),
96           (not_empty "Wa,"), (unpack_values "Wa,")))
97 ]>;
98
99 def llc : Tool<
100 [(in_language "llvm-bitcode"),
101  (out_language "assembler"),
102  (output_suffix "s"),
103  (cmd_line "llc -relocation-model=pic -f $INFILE -o $OUTFILE"),
104  (actions (case (switch_on "S"), (stop_compilation)))
105 ]>;
106
107 // Base class for linkers
108 class llvm_gcc_based_linker <string cmd_prefix> : Tool<
109 [(in_language "object-code"),
110  (out_language "executable"),
111  (output_suffix "out"),
112  (cmd_line !strconcat(cmd_prefix, " $INFILE -o $OUTFILE")),
113  (join),
114  (actions (case
115           (switch_on "pthread"), (append_cmd "-lpthread"),
116           (not_empty "L"), (forward "L"),
117           (not_empty "l"), (forward "l"),
118           (not_empty "Wl,"), (unpack_values "Wl,")))
119 ]>;
120
121 // Default linker
122 def llvm_gcc_linker : llvm_gcc_based_linker<"llvm-gcc">;
123 // Alternative linker for C++
124 def llvm_gcc_cpp_linker : llvm_gcc_based_linker<"llvm-g++">;
125
126 // Language map
127
128 def LanguageMap : LanguageMap<
129     [LangToSuffixes<"c++", ["cc", "cp", "cxx", "cpp", "CPP", "c++", "C"]>,
130      LangToSuffixes<"c", ["c"]>,
131      LangToSuffixes<"c-cpp-output", ["i"]>,
132      LangToSuffixes<"objective-c-cpp-output", ["mi"]>,
133      LangToSuffixes<"objective-c++", ["mm"]>,
134      LangToSuffixes<"objective-c", ["m"]>,
135      LangToSuffixes<"assembler", ["s"]>,
136      LangToSuffixes<"assembler-with-cpp", ["S"]>,
137      LangToSuffixes<"llvm-assembler", ["ll"]>,
138      LangToSuffixes<"llvm-bitcode", ["bc"]>,
139      LangToSuffixes<"object-code", ["o"]>,
140      LangToSuffixes<"executable", ["out"]>
141      ]>;