1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
//===- PIC16Base.td - PIC16 toolchain driver ---------------*- tablegen -*-===//
//
// A basic driver for the PIC16 toolchain.
//
//===----------------------------------------------------------------------===//
include "llvm/CompilerDriver/Common.td"
// Options
def OptionList : OptionList<[
(switch_option "g",
(help "Enable Debugging")),
(switch_option "S",
(help "Stop after compilation, do not assemble")),
(switch_option "c",
(help "Stop after assemble, do not link")),
(parameter_option "I",
(help "Add a directory to include path")),
(parameter_option "pre-RA-sched",
(help "Example of an option that is passed to llc")),
(prefix_list_option "Wa,",
(help "Pass options to native assembler")),
(prefix_list_option "Wl,",
(help "Pass options to native linker")),
(prefix_list_option "Wllc,",
(help "Pass options to llc")),
(prefix_list_option "Wo,",
(help "Pass options to llvm-ld"))
]>;
// Tools
def clang_cc : Tool<[
(in_language "c"),
(out_language "llvm-bitcode"),
(output_suffix "bc"),
(cmd_line "$CALL(GetBinDir)clang-cc -I $CALL(GetStdHeadersDir) -triple=pic16- -emit-llvm-bc $INFILE -o $OUTFILE"),
(actions (case
(not_empty "I"), (forward "I"))),
(sink)
]>;
def llvm_ld : Tool<[
(in_language "llvm-bitcode"),
(out_language "llvm-bitcode"),
(output_suffix "bc"),
(cmd_line "$CALL(GetBinDir)llvm-ld -link-as-library $INFILE -o $OUTFILE"),
(actions (case
(switch_on "g"), (append_cmd "-disable-opt"),
(not_empty "Wo,"), (unpack_values "Wo,")))
]>;
def llvm_ld_lto : Tool<[
(in_language "llvm-bitcode"),
(out_language "llvm-bitcode"),
(output_suffix "bc"),
(cmd_line "$CALL(GetBinDir)llvm-ld -link-as-library $INFILE -o $OUTFILE"),
(actions (case
(switch_on "g"), (append_cmd "-disable-opt"),
(not_empty "Wo,"), (unpack_values "Wo,"))),
(join)
]>;
def llc : Tool<[
(in_language "llvm-bitcode"),
(out_language "assembler"),
(output_suffix "s"),
(cmd_line "$CALL(GetBinDir)llc -march=pic16 -f $INFILE -o $OUTFILE"),
(actions (case
(switch_on "S"), (stop_compilation),
(not_empty "Wllc,"), (unpack_values "Wllc,"),
(not_empty "pre-RA-sched"), (forward "pre-RA-sched")))
]>;
def gpasm : Tool<[
(in_language "assembler"),
(out_language "object-code"),
(output_suffix "o"),
(cmd_line "$CALL(GetBinDir)gpasm -r decimal -p p16F1937 -I $CALL(GetStdAsmHeadersDir) -C -c $INFILE -o $OUTFILE"),
(actions (case
(switch_on "c"), (stop_compilation),
(not_empty "Wa,"), (unpack_values "Wa,")))
]>;
def mplink : Tool<[
(in_language "object-code"),
(out_language "executable"),
(output_suffix "out"),
(cmd_line "$CALL(GetBinDir)mplink.exe /k $CALL(GetStdLinkerScriptsDir) /l $CALL(GetStdLibsDir) 16f1937.lkr intrinsics.lib std.lib $INFILE -o $OUTFILE"),
(actions (case
(not_empty "Wl,"), (unpack_values "Wl,"))),
(join)
]>;
// Language map
def LanguageMap : LanguageMap<[
LangToSuffixes<"c", ["c"]>,
LangToSuffixes<"c-cpp-output", ["i"]>,
LangToSuffixes<"assembler", ["s"]>,
LangToSuffixes<"assembler-with-cpp", ["S"]>,
LangToSuffixes<"llvm-assembler", ["ll"]>,
LangToSuffixes<"llvm-bitcode", ["bc"]>,
LangToSuffixes<"object-code", ["o"]>,
LangToSuffixes<"executable", ["out"]>
]>;
// Compilation graph
def CompilationGraph : CompilationGraph<[
Edge<"root", "clang_cc">,
Edge<"clang_cc", "llvm_ld_lto">,
Edge<"llvm_ld_lto", "llc">,
OptionalEdge<"clang_cc", "llvm_ld", (case
(switch_on "S"), (inc_weight),
(switch_on "c"), (inc_weight))>,
Edge<"llvm_ld", "llc">,
Edge<"llc", "gpasm">,
Edge<"gpasm", "mplink">
]>;
|