• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1//===- PIC16.td - PIC16 toolchain driver -------------------*- tablegen -*-===//
2//
3// A basic driver for the PIC16 toolchain.
4//
5//===----------------------------------------------------------------------===//
6
7include "llvm/CompilerDriver/Common.td"
8
9// Options
10
11def OptionList : OptionList<[
12 (switch_option "g",
13    (help "Enable Debugging")),
14 (switch_option "E",
15    (help "Stop after preprocessing, do not compile")),
16 (switch_option "S",
17    (help "Stop after compilation, do not assemble")),
18 (switch_option "bc",
19    (help "Stop after b-code generation, do not compile")),
20 (switch_option "c",
21    (help "Stop after assemble, do not link")),
22 (prefix_option "p",
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")),
38 (switch_option "X",
39    (help "Do not invoke mp2hex to create an output hex file.")),
40 (switch_option "O0",
41    (help "Do not optimize")),
42 (switch_option "O1",
43    (help "Optimization Level 1.")),
44 (switch_option "O2",
45    (help "Optimization Level 2.")),
46 (switch_option "O3",
47    (help "Optimization Level 3.")),
48 (switch_option "Od",
49    (help "Perform Debug-safe Optimizations only.")),
50 (switch_option "w",
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"))
68]>;
69
70// Tools
71class clang_based<string language, string cmd, string ext_E> : Tool<
72[(in_language language),
73 (out_language "llvm-bitcode"),
74 (output_suffix "bc"),
75 (command cmd),
76 (actions (case
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")))
94// (sink)
95]>;
96
97def clang_cc : clang_based<"c", "$CALL(GetBinDir)clang -cc1                                                        -I $CALL(GetStdHeadersDir)                                                      -D $CALL(GetLowerCasePartDefine)                                                -D $CALL(GetUpperCasePartDefine) -triple=pic16-                                 -emit-llvm-bc ", "i">;
98
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 "),
104// (cmd_line kkkkk
105// (actions (case
106//          (switch_on "g"), (append_cmd "g"),
107//          (not_empty "I"), (forward "I"))),
108// (sink)
109//]>;
110
111
112// pre-link-and-lto step.
113def llvm_ld : Tool<[
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"),
119 (actions (case
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"))),
126 (join)
127]>;
128
129// optimize single file
130def 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"),
138 (actions (case
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")))
145]>;
146
147// optimizer step.
148def pic16passes : Tool<[
149 (in_language "llvm-bitcode"),
150 (out_language "llvm-bitcode"),
151 (output_suffix "obc"),
152 (command "$CALL(GetBinDir)opt -pic16cloner -pic16overlay -f"),
153 (actions (case
154          (switch_on "O0"), (append_cmd "-disable-opt")))
155]>;
156
157def llc : Tool<[
158 (in_language "llvm-bitcode"),
159 (out_language "assembler"),
160 (output_suffix "s"),
161 (command "$CALL(GetBinDir)llc -march=pic16 -disable-jump-tables -pre-RA-sched=list-burr -f"),
162 (actions (case
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")))
168]>;
169
170def gpasm : Tool<[
171 (in_language "assembler"),
172 (out_language "object-code"),
173 (output_suffix "o"),
174 (command "$CALL(GetBinDir)gpasm -z -r decimal -I $CALL(GetStdAsmHeadersDir) -C -c -w 2"),
175 (actions (case
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,")))
181]>;
182
183def mplink : Tool<[
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"),
188 (actions (case
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"))),
199 (join)
200]>;
201
202// Language map
203
204def 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")
213]>;
214
215// Compilation graph
216
217def 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")
234]>;
235