1 // A replacement for the Clang's ccc script.
2 // Depends on the Base plugin.
3 // To compile, use this command:
6 // make DRIVER_NAME=ccc2 BUILTIN_PLUGINS=Clang
8 // Or just use the default llvmc, which now has this plugin enabled.
10 include "llvm/CompilerDriver/Common.td"
12 def Priority : PluginPriority<1>;
14 def Options : OptionList<[
16 (switch_option "E", (extern)),
17 (switch_option "S", (extern)),
18 (switch_option "c", (extern)),
19 (switch_option "fsyntax-only", (extern)),
20 (switch_option "emit-llvm", (extern)),
21 (switch_option "pthread", (extern)),
22 (parameter_list_option "I", (extern)),
23 (parameter_list_option "include", (extern)),
24 (parameter_list_option "L", (extern)),
25 (parameter_list_option "l", (extern)),
26 (prefix_list_option "Wa,", (extern)),
27 (prefix_list_option "Wl,", (extern)),
29 (switch_option "clang", (help "Use Clang instead of llvm-gcc"))
32 class clang_based<string language, string cmd, string ext_E> : Tool<
33 [(in_language language),
34 (out_language "llvm-bitcode"),
40 !strconcat(cmd, " -E $INFILE -o $OUTFILE"),
42 !strconcat(cmd, " -E $INFILE")),
43 (and (switch_on "S"), (switch_on "emit-llvm")),
44 !strconcat(cmd, " -emit-llvm $INFILE -o $OUTFILE"),
46 !strconcat(cmd, " -emit-llvm-bc $INFILE -o $OUTFILE"))),
47 (actions (case (switch_on "E"),
48 [(stop_compilation), (output_suffix ext_E)],
49 (switch_on "fsyntax-only"), (stop_compilation),
50 (and (switch_on "S"), (switch_on "emit-llvm")),
51 [(stop_compilation), (output_suffix "ll")],
52 (and (switch_on "c"), (switch_on "emit-llvm")),
54 (not_empty "include"), (forward "include"),
55 (not_empty "I"), (forward "I"))),
59 def clang_c : clang_based<"c", "clang -x c", "i">;
60 def clang_cpp : clang_based<"c++", "clang -x c++", "i">;
61 def clang_objective_c : clang_based<"objective-c",
62 "clang -x objective-c", "mi">;
63 def clang_objective_cpp : clang_based<"objective-c++",
64 "clang -x objective-c++", "mi">;
67 [(in_language "assembler"),
68 (out_language "object-code"),
70 (cmd_line "as $INFILE -o $OUTFILE"),
71 (actions (case (not_empty "Wa,"), (unpack_values "Wa,"),
72 (switch_on "c"), (stop_compilation)))
77 [(in_language "object-code"),
78 (out_language "executable"),
79 (output_suffix "out"),
80 (cmd_line "llvm-ld -native -disable-internalize $INFILE -o $OUTFILE"),
82 (switch_on "pthread"), (append_cmd "-lpthread"),
83 (not_empty "L"), (forward "L"),
84 (not_empty "l"), (forward "l"),
85 (not_empty "Wl,"), (unpack_values "Wl,"))),
91 def LanguageMap : LanguageMap<[
92 LangToSuffixes<"c++", ["cc", "cp", "cxx", "cpp", "CPP", "c++", "C"]>,
93 LangToSuffixes<"c", ["c"]>,
94 LangToSuffixes<"objective-c", ["m"]>,
95 LangToSuffixes<"c-cpp-output", ["i"]>,
96 LangToSuffixes<"objective-c-cpp-output", ["mi"]>
101 def CompilationGraph : CompilationGraph<[
102 OptionalEdge<"root", "clang_c",
103 (case (switch_on "clang"), (inc_weight))>,
104 OptionalEdge<"root", "clang_cpp",
105 (case (switch_on "clang"), (inc_weight))>,
106 OptionalEdge<"root", "clang_objective_c",
107 (case (switch_on "clang"), (inc_weight))>,
108 OptionalEdge<"root", "clang_objective_cpp",
109 (case (switch_on "clang"), (inc_weight))>,
110 Edge<"clang_c", "llc">,
111 Edge<"clang_cpp", "llc">,
112 Edge<"clang_objective_c", "llc">,
113 Edge<"clang_objective_cpp", "llc">,
114 OptionalEdge<"llc", "as", (case (switch_on "clang"), (inc_weight))>,
115 Edge<"as", "llvm_ld">