1 //===- Tools.td - Tools description for LLVMC2 -------------*- 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 descriptions of the various build tools run by llvmc2.
12 //===----------------------------------------------------------------------===//
14 def OptList : OptionList<[
15 (switch_option "emit-llvm",
16 (help "Emit LLVM bitcode files instead of native object files")),
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")),
24 (help "Stop after compilation, do not assemble")),
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"))
45 class llvm_gcc_based <string cmd_prefix, string in_lang> : Tool<
46 [(in_language in_lang),
47 (out_language "llvm-bitcode"),
51 (case (not_empty "o"),
52 !strconcat(cmd_prefix, " -E $INFILE -o $OUTFILE"),
54 !strconcat(cmd_prefix, " -E $INFILE")),
55 (switch_on "fsyntax-only"),
56 !strconcat(cmd_prefix, " -fsyntax-only $INFILE"),
58 !strconcat(cmd_prefix, " -c $INFILE -o $OUTFILE -emit-llvm"))),
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"))),
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++">;
76 [(in_language "llvm-bitcode"),
77 (out_language "llvm-bitcode"),
79 (cmd_line "opt -f $INFILE -o $OUTFILE")
83 [(in_language "llvm-assembler"),
84 (out_language "llvm-bitcode"),
86 (cmd_line "llvm-as $INFILE -o $OUTFILE")
89 def llvm_gcc_assembler : Tool<
90 [(in_language "assembler"),
91 (out_language "object-code"),
93 (cmd_line "llvm-gcc -c -x assembler $INFILE -o $OUTFILE"),
95 (switch_on "c"), (stop_compilation),
96 (not_empty "Wa,"), (unpack_values "Wa,")))
100 [(in_language "llvm-bitcode"),
101 (out_language "assembler"),
103 (cmd_line "llc -relocation-model=pic -f $INFILE -o $OUTFILE"),
104 (actions (case (switch_on "S"), (stop_compilation)))
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")),
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,")))
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++">;
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"]>