e2d32e88ff22433dd9380aac4b01f91a97601c93
[oota-llvm.git] / tools / llvmc / src / Clang.td
1 //===- Clang.td - LLVMC toolchain descriptions -------------*- 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 compilation graph description used by llvmc.
11 //
12 //===----------------------------------------------------------------------===//
13
14
15 def Options : OptionList<[
16 (switch_option "clang", (help "Use Clang instead of llvm-gcc"))
17 ]>;
18
19 class clang_based<string language, string cmd, string ext_E> : Tool<
20 [(in_language language),
21  (out_language "llvm-bitcode"),
22  (output_suffix "bc"),
23  (command cmd),
24  (actions (case (switch_on "E"),
25                     [(forward "E"), (stop_compilation), (output_suffix ext_E)],
26                 (and (switch_on "E"), (empty "o")), (no_out_file),
27                 (switch_on "fsyntax-only"), (stop_compilation),
28                 (switch_on "S", "emit-llvm"),
29                            [(append_cmd "-emit-llvm"),
30                             (stop_compilation), (output_suffix "ll")],
31                 (not (switch_on "S", "emit-llvm")),
32                      (append_cmd "-emit-llvm-bc"),
33                 (switch_on "c", "emit-llvm"),
34                            (stop_compilation),
35                 (not_empty "include"), (forward "include"),
36                 (not_empty "I"), (forward "I"))),
37  (sink)
38 ]>;
39
40 def clang_c : clang_based<"c", "clang -x c", "i">;
41 def clang_cpp : clang_based<"c++", "clang -x c++", "i">;
42 def clang_objective_c : clang_based<"objective-c",
43     "clang -x objective-c", "mi">;
44 def clang_objective_cpp : clang_based<"objective-c++",
45     "clang -x objective-c++", "mi">;
46
47 def as : Tool<
48 [(in_language "assembler"),
49  (out_language "object-code"),
50  (output_suffix "o"),
51  (command "as"),
52  (actions (case (not_empty "Wa,"), (forward_value "Wa,"),
53                 (switch_on "c"), (stop_compilation)))
54 ]>;
55
56 // Default linker
57 def llvm_ld : Tool<
58 [(in_language "object-code"),
59  (out_language "executable"),
60  (output_suffix "out"),
61  (command "llvm-ld -native -disable-internalize"),
62  (actions (case
63           (switch_on "pthread"), (append_cmd "-lpthread"),
64           (not_empty "L"), (forward "L"),
65           (not_empty "l"), (forward "l"),
66           (not_empty "Wl,"), (forward_value "Wl,"))),
67  (join)
68 ]>;
69
70 // Compilation graph
71
72 def ClangCompilationGraph : CompilationGraph<[
73     (optional_edge "root", "clang_c",
74                            (case (switch_on "clang"), (inc_weight))),
75     (optional_edge "root", "clang_cpp",
76                            (case (switch_on "clang"), (inc_weight))),
77     (optional_edge "root", "clang_objective_c",
78                            (case (switch_on "clang"), (inc_weight))),
79     (optional_edge "root", "clang_objective_cpp",
80                            (case (switch_on "clang"), (inc_weight))),
81     (edge "clang_c", "llc"),
82     (edge "clang_cpp", "llc"),
83     (edge "clang_objective_c", "llc"),
84     (edge "clang_objective_cpp", "llc"),
85     (optional_edge "llc", "as", (case (switch_on "clang"), (inc_weight))),
86     (edge "as", "llvm_ld")
87 ]>;