blob: 1d75743f4fee281abc11f802b8895d2cf9001770 [file] [log] [blame]
Mikhail Glushenkovb3d36292010-08-15 07:07:12 +00001//===- 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//===----------------------------------------------------------------------===//
Mikhail Glushenkov163dc1e2008-05-30 06:16:32 +000013
Mikhail Glushenkov940cdfe2008-12-07 16:46:23 +000014
Mikhail Glushenkove43228952008-05-30 06:26:08 +000015def Options : OptionList<[
Mikhail Glushenkovc8813da2008-12-07 16:43:17 +000016(switch_option "clang", (help "Use Clang instead of llvm-gcc"))
Mikhail Glushenkove43228952008-05-30 06:26:08 +000017]>;
18
Mikhail Glushenkov940cdfe2008-12-07 16:46:23 +000019class clang_based<string language, string cmd, string ext_E> : Tool<
Mikhail Glushenkove43228952008-05-30 06:26:08 +000020[(in_language language),
Mikhail Glushenkov163dc1e2008-05-30 06:16:32 +000021 (out_language "llvm-bitcode"),
22 (output_suffix "bc"),
Mikhail Glushenkov9e7d90b2010-02-23 09:59:30 +000023 (command cmd),
Mikhail Glushenkovc8813da2008-12-07 16:43:17 +000024 (actions (case (switch_on "E"),
Mikhail Glushenkov9e7d90b2010-02-23 09:59:30 +000025 [(forward "E"), (stop_compilation), (output_suffix ext_E)],
26 (and (switch_on "E"), (empty "o")), (no_out_file),
Mikhail Glushenkov940cdfe2008-12-07 16:46:23 +000027 (switch_on "fsyntax-only"), (stop_compilation),
Mikhail Glushenkov9e7d90b2010-02-23 09:59:30 +000028 (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"]),
Mikhail Glushenkov74bcb052008-12-09 14:40:18 +000034 (stop_compilation),
Mikhail Glushenkov940cdfe2008-12-07 16:46:23 +000035 (not_empty "include"), (forward "include"),
36 (not_empty "I"), (forward "I"))),
Mikhail Glushenkov163dc1e2008-05-30 06:16:32 +000037 (sink)
38]>;
39
Mikhail Glushenkov940cdfe2008-12-07 16:46:23 +000040def clang_c : clang_based<"c", "clang -x c", "i">;
41def clang_cpp : clang_based<"c++", "clang -x c++", "i">;
42def clang_objective_c : clang_based<"objective-c",
43 "clang -x objective-c", "mi">;
Mikhail Glushenkovbfdef3a2008-11-28 00:14:11 +000044def clang_objective_cpp : clang_based<"objective-c++",
Mikhail Glushenkov940cdfe2008-12-07 16:46:23 +000045 "clang -x objective-c++", "mi">;
46
47def as : Tool<
48[(in_language "assembler"),
49 (out_language "object-code"),
50 (output_suffix "o"),
Mikhail Glushenkov9e7d90b2010-02-23 09:59:30 +000051 (command "as"),
Mikhail Glushenkov5b9b3ba2009-12-07 18:25:54 +000052 (actions (case (not_empty "Wa,"), (forward_value "Wa,"),
Mikhail Glushenkov74bcb052008-12-09 14:40:18 +000053 (switch_on "c"), (stop_compilation)))
Mikhail Glushenkov940cdfe2008-12-07 16:46:23 +000054]>;
Mikhail Glushenkove43228952008-05-30 06:26:08 +000055
Mikhail Glushenkov163dc1e2008-05-30 06:16:32 +000056// Default linker
57def llvm_ld : Tool<
Mikhail Glushenkov940cdfe2008-12-07 16:46:23 +000058[(in_language "object-code"),
Mikhail Glushenkov163dc1e2008-05-30 06:16:32 +000059 (out_language "executable"),
60 (output_suffix "out"),
Mikhail Glushenkov9e7d90b2010-02-23 09:59:30 +000061 (command "llvm-ld -native -disable-internalize"),
Mikhail Glushenkov940cdfe2008-12-07 16:46:23 +000062 (actions (case
63 (switch_on "pthread"), (append_cmd "-lpthread"),
64 (not_empty "L"), (forward "L"),
65 (not_empty "l"), (forward "l"),
Mikhail Glushenkov5b9b3ba2009-12-07 18:25:54 +000066 (not_empty "Wl,"), (forward_value "Wl,"))),
Mikhail Glushenkov163dc1e2008-05-30 06:16:32 +000067 (join)
68]>;
69
Mikhail Glushenkov163dc1e2008-05-30 06:16:32 +000070// Compilation graph
71
Mikhail Glushenkovb3d36292010-08-15 07:07:12 +000072def ClangCompilationGraph : CompilationGraph<[
Mikhail Glushenkovd9a73162010-08-23 23:21:23 +000073 (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")
Mikhail Glushenkov940cdfe2008-12-07 16:46:23 +000087]>;