1 //===- PIC16.td - PIC16 toolchain driver -------------------*- tablegen -*-===//
3 // A basic driver for the PIC16 toolchain.
5 //===----------------------------------------------------------------------===//
7 include "llvm/CompilerDriver/Common.td"
11 def OptionList : OptionList<[
13 (help "Enable Debugging")),
15 (help "Stop after preprocessing, do not compile")),
17 (help "Stop after compilation, do not assemble")),
19 (help "Stop after b-code generation, do not compile")),
21 (help "Stop after assemble, do not link")),
23 (help "Specify part name")),
24 (prefix_list_option "I",
25 (help "Add a directory to include path")),
26 (prefix_list_option "L",
27 (help "Add a directory to library path")),
28 (prefix_list_option "K",
29 (help "Add a directory to linker script search path")),
30 (parameter_option "l",
31 (help "Specify a library to link")),
32 (parameter_option "k",
33 (help "Specify a linker script")),
34 (parameter_option "m",
35 (help "Generate linker map file with the given name")),
36 (prefix_list_option "D",
37 (help "Define a macro")),
39 (help "Do not invoke mp2hex to create an output hex file.")),
41 (help "Do not optimize")),
43 (help "Optimization Level 1.")),
45 (help "Optimization Level 2.")),
47 (help "Optimization Level 3.")),
49 (help "Perform Debug-safe Optimizations only.")),
51 (help "Disable all warnings.")),
52 // (switch_option "O1",
53 // (help "Optimization level 1")),
54 // (switch_option "O2",
55 // (help "Optimization level 2. (Default)")),
56 // (parameter_option "pre-RA-sched",
57 // (help "Example of an option that is passed to llc")),
58 (parameter_option "regalloc",
59 (help "Register allocator to use (possible values: simple, linearscan, pbqp, local; default=linearscan)")),
60 (prefix_list_option "Wa,", (comma_separated),
61 (help "Pass options to assembler (Run 'gpasm -help' for assembler options)")),
62 (prefix_list_option "Wl,", (comma_separated),
63 (help "Pass options to linker (Run 'mplink -help' for linker options)"))
64 // (prefix_list_option "Wllc,",
65 // (help "Pass options to llc")),
66 // (prefix_list_option "Wo,",
67 // (help "Pass options to llvm-ld"))
71 class clang_based<string language, string cmd, string ext_E> : Tool<
72 [(in_language language),
73 (out_language "llvm-bitcode"),
77 (and (multiple_input_files),
78 (or (switch_on "S"), (switch_on "c"))),
79 (error "cannot specify -o with -c or -S with multiple files"),
80 (switch_on "E"), [(forward "E"),
81 (stop_compilation), (output_suffix ext_E)],
82 (and (switch_on "E"), (empty "o")), (no_out_file),
83 (switch_on "bc"),[(stop_compilation), (output_suffix "bc")],
84 (switch_on "g"), (append_cmd "-g"),
85 (switch_on "w"), (append_cmd "-w"),
86 (switch_on "O1"), (append_cmd ""),
87 (switch_on "O2"), (append_cmd ""),
88 (switch_on "O3"), (append_cmd ""),
89 (switch_on "Od"), (append_cmd ""),
90 (not_empty "D"), (forward "D"),
91 (not_empty "I"), (forward "I"),
92 (switch_on "O0"), (append_cmd "-O0"),
93 (default), (append_cmd "-O1")))
97 def clang_cc : clang_based<"c", "$CALL(GetBinDir)clang -cc1 -I $CALL(GetStdHeadersDir) -D $CALL(GetLowerCasePartDefine) -D $CALL(GetUpperCasePartDefine) -triple=pic16- -emit-llvm-bc ", "i">;
99 //def clang_cc : Tool<[
100 // (in_language "c"),
101 // (out_language "llvm-bitcode"),
102 // (output_suffix "bc"),
103 // (cmd_line "$CALL(GetBinDir)clang-cc -I $CALL(GetStdHeadersDir) -triple=pic16- -emit-llvm-bc "),
106 // (switch_on "g"), (append_cmd "g"),
107 // (not_empty "I"), (forward "I"))),
112 // pre-link-and-lto step.
114 (in_language "llvm-bitcode"),
115 (out_language "llvm-bitcode"),
116 (output_suffix "bc"),
117 (command "$CALL(GetBinDir)llvm-ld -L $CALL(GetStdLibsDir) -disable-licm-promotion -l std"),
118 (out_file_option "-b"),
120 (switch_on "O0"), (append_cmd "-disable-opt"),
121 (switch_on "O1"), (append_cmd "-disable-opt"),
122 // Whenever O3 is not specified on the command line, default i.e. disable-inlining will always be added.
123 (switch_on "O2"), (append_cmd ""),
124 (switch_on "O3"), (append_cmd ""),
125 (default), (append_cmd "-disable-inlining"))),
129 // optimize single file
130 def llvm_ld_optimizer : Tool<[
131 (in_language "llvm-bitcode"),
132 (out_language "llvm-bitcode"),
133 (output_suffix "bc"),
134 // FIXME: we are still not disabling licm-promotion.
135 // -disable-licm-promotion and building stdn library causes c16-71 to fail.
136 (command "$CALL(GetBinDir)llvm-ld "),
137 (out_file_option "-b"),
139 (switch_on "O0"), (append_cmd "-disable-opt"),
140 (switch_on "O1"), (append_cmd "-disable-opt"),
141 // Whenever O3 is not specified on the command line, default i.e. disable-inlining will always be added.
142 (switch_on "O2"), (append_cmd ""),
143 (switch_on "O3"), (append_cmd ""),
144 (default), (append_cmd "-disable-inlining")))
148 def pic16passes : Tool<[
149 (in_language "llvm-bitcode"),
150 (out_language "llvm-bitcode"),
151 (output_suffix "obc"),
152 (command "$CALL(GetBinDir)opt -pic16cloner -pic16overlay -f"),
154 (switch_on "O0"), (append_cmd "-disable-opt")))
158 (in_language "llvm-bitcode"),
159 (out_language "assembler"),
161 (command "$CALL(GetBinDir)llc -march=pic16 -disable-jump-tables -pre-RA-sched=list-burr -f"),
163 (switch_on "S"), (stop_compilation),
164 // (not_empty "Wllc,"), (unpack_values "Wllc,"),
165 // (not_empty "pre-RA-sched"), (forward "pre-RA-sched")))
166 (not_empty "regalloc"), (forward "regalloc"),
167 (empty "regalloc"), (append_cmd "-regalloc=linearscan")))
171 (in_language "assembler"),
172 (out_language "object-code"),
174 (command "$CALL(GetBinDir)gpasm -z -r decimal -I $CALL(GetStdAsmHeadersDir) -C -c -w 2"),
176 (switch_on "c"), (stop_compilation),
177 (switch_on "g"), (append_cmd "-g"),
178 (not_empty "p"), (forward "p"),
179 (empty "p"), (append_cmd "-p 16f1xxx"),
180 (not_empty "Wa,"), (forward_value "Wa,")))
184 (in_language "object-code"),
185 (out_language "executable"),
186 (output_suffix "cof"),
187 (command "$CALL(GetBinDir)mplink -e -k $CALL(GetStdLinkerScriptsDir) -l $CALL(GetStdLibsDir) intrinsics.lib stdn.lib"),
189 (not_empty "Wl,"), (forward_value "Wl,"),
190 (switch_on "X"), (append_cmd "-x"),
191 (not_empty "L"), (forward_as "L", "-l"),
192 (not_empty "K"), (forward_as "K", "-k"),
193 (not_empty "m"), (forward "m"),
194 (not_empty "p"), [(forward "p"), (append_cmd "-c")],
195 (empty "p"), (append_cmd "-p 16f1xxx -c"),
196 // (not_empty "l"), [(unpack_values "l"),(append_cmd ".lib")])),
197 (not_empty "k"), (forward "k"),
198 (not_empty "l"), (forward "l"))),
204 def LanguageMap : LanguageMap<[
205 (lang_to_suffixes "c", "c"),
206 (lang_to_suffixes "c-cpp-output", "i"),
207 (lang_to_suffixes "assembler", "s"),
208 (lang_to_suffixes "assembler-with-cpp", "S"),
209 (lang_to_suffixes "llvm-assembler", "ll"),
210 (lang_to_suffixes "llvm-bitcode", "bc"),
211 (lang_to_suffixes "object-code", "o"),
212 (lang_to_suffixes "executable", "cof")
217 def CompilationGraph : CompilationGraph<[
218 (edge "root", "clang_cc"),
219 (edge "root", "llvm_ld"),
220 (optional_edge "root", "llvm_ld_optimizer",
221 (case (switch_on "S"), (inc_weight),
222 (switch_on "c"), (inc_weight))),
223 (edge "root", "gpasm"),
224 (edge "root", "mplink"),
225 (edge "clang_cc", "llvm_ld"),
226 (optional_edge "clang_cc", "llvm_ld_optimizer",
227 (case (switch_on "S"), (inc_weight),
228 (switch_on "c"), (inc_weight))),
229 (edge "llvm_ld", "pic16passes"),
230 (edge "llvm_ld_optimizer", "pic16passes"),
231 (edge "pic16passes", "llc"),
232 (edge "llc", "gpasm"),
233 (edge "gpasm", "mplink")