-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.c
200 lines (161 loc) · 5.23 KB
/
build.c
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#include "build_c/build.h"
/* ========================================================================= */
enum CompileResult target_deps() {
ONLY_IF({
CHANGED("allib/");
NOT_FILE("allib/build/all.a");
});
START;
ssx("allib/", "-DHAVE_WINSOCK=0", ({
ss_task("all.a");
}));
END;
}
/* ========================================================================= */
struct CompileData target_gen_files[] = {
DIR("build"),
DIR("build/targets"),
SP(CT_CDEF, "targets/targets.cdef"),
DIR("build/targets/etca"),
SP(CT_CDEF, "targets/etca/etca.cdef"),
DIR("build/targets/x86"),
SP(CT_CDEF, "targets/x86/x86.cdef"),
// add target (cdef file)
DIR("build/ir"),
SP(CT_CDEF, "ir/ops.cdef"),
};
enum CompileResult target_gen() {
if (!withPipPackage("generic-lexer")) {
error("pip package generic-lexer required and could not be installted!");
return CR_FAIL;
}
START;
DO(compile(LI(target_gen_files)));
END;
}
/* ========================================================================= */
struct CompileData ir_files[] = {
DIR("build"),
DIR("build/targets"),
SP(CT_C, "targets/targets.c"),
DIR("build/ir"),
SP(CT_C, "ir/verify.c"),
SP(CT_C, "ir/fastalloc.c"),
SP(CT_C, "ir/dump.c"),
SP(CT_C, "ir/lifetimes.c"),
SP(CT_C, "ir/transform.c"),
SP(CT_C, "ir/builder.c"),
SP(CT_C, "ir/ir.c"),
SP(CT_C, "ir/eval.c"),
SP(CT_C, "ir/analysis.c"),
};
struct CompileData ir_opt_files[] = {
DIR("build"),
DIR("build/ir"),
SP(CT_C, "ir/passes.c"),
DIR("build/ir/opt"),
SP(CT_C, "ir/opt/tailcall.c"),
SP(CT_C, "ir/opt/loop_simplify.c"),
SP(CT_C, "ir/opt/reduce_loops.c"),
SP(CT_C, "ir/opt/vars.c"),
SP(CT_C, "ir/opt/constant_eval.c"),
SP(CT_C, "ir/opt/inline_vars.c"),
SP(CT_C, "ir/opt/reduce_if.c"),
SP(CT_C, "ir/opt/cmov.c"),
SP(CT_C, "ir/opt/comparisions.c"),
SP(CT_C, "ir/opt/dce.c"),
SP(CT_C, "ir/opt/join_compute.c"),
SP(CT_C, "ir/opt/ll_jumps.c"),
SP(CT_C, "ir/opt/ll_binary.c"),
SP(CT_C, "ir/opt/simple_patterns.c"),
SP(CT_C, "ir/opt/ll_sched.c"),
SP(CT_C, "ir/opt/if_opts.c"),
SP(CT_C, "ir/opt/swap_if_cases.c"),
};
struct CompileData ir_transform_files[] = {
DIR("build"),
DIR("build/ir"),
DIR("build/ir/transform"),
SP(CT_C, "ir/transform/single_assign_conditional.c"),
SP(CT_C, "ir/transform/single_assign.c"),
SP(CT_C, "ir/transform/normalize.c"),
SP(CT_C, "ir/transform/share_slots.c"),
SP(CT_C, "ir/transform/ssair_llir_lower.c"),
SP(CT_C, "ir/transform/cmov_expand.c"),
SP(CT_C, "ir/transform/ll_finalize.c"),
SP(CT_C, "ir/transform/lower_loops.c"),
};
struct CompileData ir_verify_files[] = {
DIR("build"),
DIR("build/ir"),
SP(CT_C, "ir/verify_cir.c"),
SP(CT_C, "ir/verify_common.c"),
SP(CT_C, "ir/verify_ssa.c"),
};
struct CompileData cg_files[] = {
DIR("build"),
DIR("build/targets"),
SP(CT_C, "targets/targets.c"),
DIR("build/targets/etca"),
SP(CT_C, "targets/etca/etca.c"),
DIR("build/targets/x86"),
SP(CT_C, "targets/x86/x86.c"),
SP(CT_C, "targets/x86/cg.c"),
// add target
};
struct CompileData parser_files[] = {
DIR("build"),
DIR("build/irparser"),
SP(CT_C, "irparser/parser.c"),
SP(CT_C, "irparser/match.c"),
};
struct CompileData always_files[] = {
DEP("build/targets/etca/etca.cdef.o"),
DEP("build/targets/x86/x86.cdef.o"),
DEP("build/targets/targets.cdef.o"),
// add target (cdef file)
DEP("build/ir/ops.cdef.o"),
NOLD_DEP("ir/ir.h"),
};
enum CompileResult target_lib() {
START;
bool all = file_changed("ir/ir.h");
VaList comp = ASVAR(always_files);
if (source_changed(LI(ir_files)) || all)
comp = vaListConcat(comp, ASVAR(ir_files));
if (file_changed("ir/opt/") || all)
comp = vaListConcat(comp, ASVAR(ir_opt_files));
if (file_changed("ir/transform/") || all)
comp = vaListConcat(comp, ASVAR(ir_transform_files));
if (source_changed(LI(ir_verify_files)) || all)
comp = vaListConcat(comp, ASVAR(ir_verify_files));
if (file_changed("cg/") || all)
comp = vaListConcat(comp, ASVAR(cg_files));
if (file_changed("irparser/") || all)
comp = vaListConcat(comp, ASVAR(parser_files));
DO(compile(VLI(comp)));
VaList link = ASVAR(always_files);
link = vaListConcat(link, ASVAR(ir_files));
link = vaListConcat(link, ASVAR(ir_opt_files));
link = vaListConcat(link, ASVAR(ir_transform_files));
link = vaListConcat(link, ASVAR(ir_verify_files));
link = vaListConcat(link, ASVAR(cg_files));
link = vaListConcat(link, ASVAR(parser_files));
DO(linkTask(VLI(link), "build/lib.a"));
END;
}
/* ========================================================================= */
enum CompileResult target_tests() {
START_TESTING;
test("", "test.c", 0, CT_C,
DEP("build/lib.a"));
END_TESTING;
}
/* ========================================================================= */
struct Target targets[] = {
{ .name = "deps", .run = target_deps },
{ .name = "gen", .run = target_gen },
{ .name = "lib.a", .run = target_lib },
{ .name = "tests", .run = target_tests },
};
automain(targets);