Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
116 lines (102 loc) · 3.16 KB
/
Copy pathMakefile
File metadata and controls
116 lines (102 loc) · 3.16 KB
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
.PHONY: all build test test-all clean renumber dist optim-compares-% test-%
# Default target: build the compiler
all: build
# Build compiler binary (delegates to compiler/Makefile)
build:
@echo "Building compiler..."
@$(MAKE) -C compiler ifcc
test-all:
python3 ifcc-test.py testfiles
test-arm-%:
python3 ifcc-test.py --arch arm testfiles/$*_*
test-x86-%:
python3 ifcc-test.py --arch x86 testfiles/$*_*
# Usage:
# make test -> run full test suite
# make test-09 -> run all tests matching testfiles/09_*
test: test-all
test-%:
@if [ -d testfiles/$* ]; then \
python3 ifcc-test.py testfiles/$*; \
else \
python3 ifcc-test.py testfiles/$*_*; \
fi
# Compiles the tests in the directory testfiles/%* both with and without optimizations, and compares the assembly
optim-compares-%:
$(MAKE) -C compiler ifcc
@set -e; \
if [ -d testfiles/$* ]; then \
test_dirs="testfiles/$*"; \
else \
test_dirs=$$(ls -d testfiles/$*_* 2>/dev/null || true); \
fi; \
if [ -z "$$test_dirs" ]; then \
echo "No matching test directory for pattern '$*'"; \
exit 1; \
fi; \
out_root=ifcc-optim-compare/$*; \
rm -rf "$$out_root"; \
mkdir -p "$$out_root"; \
fails=0; \
for dir in $$test_dirs; do \
echo "==> $$dir"; \
for src in $$(find "$$dir" -type f -name '*.c' | sort); do \
name=$$(basename "$$src" .c); \
src_base=$$(basename "$$src"); \
case_out="$$out_root/$${name}"; \
mkdir -p "$$case_out"; \
src_copy="$$case_out/$$src_base"; \
cp "$$src" "$$src_copy"; \
asm_opt="$$case_out/opt.s"; \
asm_noopt="$$case_out/noopt.s"; \
diff_out="$$case_out/$${name}.diff"; \
if ! compiler/ifcc "$$src_copy" > "$$asm_opt" 2> "$$case_out/opt.compile.log"; then \
echo " FAIL $$name (compile opt)"; \
fails=$$((fails + 1)); \
continue; \
fi; \
if ! compiler/ifcc --nooptim "$$src_copy" > "$$asm_noopt" 2> "$$case_out/noopt.compile.log"; then \
echo " FAIL $$name (compile noopt)"; \
fails=$$((fails + 1)); \
continue; \
fi; \
diff -u "$$asm_noopt" "$$asm_opt" > "$$diff_out" || true; \
echo " OK $$name -> $$diff_out"; \
done; \
done; \
echo "Summary: $$fails compile failures"; \
if [ "$$fails" -ne 0 ]; then \
exit 1; \
fi
# Renumber tests in all test directories
renumber:
@echo "Renumbering all test files..."
@find testfiles -type d | while read dir; do \
if ls "$$dir"/*.c >/dev/null 2>&1; then \
echo "Renumbering tests in $$dir..."; \
cd "$$dir" && \
i=0; \
for file in $$(ls -1 *.c 2>/dev/null | sort -V); do \
newname=$$(echo $$file | sed -E "s/^[0-9]+_/$$(printf "%02d" $$i)_/"); \
if [ "$$file" != "$$newname" ]; then \
echo " $$file -> $$newname"; \
mv "$$file" "$$newname"; \
fi; \
i=$$((i + 1)); \
done; \
cd - >/dev/null; \
fi; \
done
@echo "Done renumbering all tests."
clean:
rm -rf compiler/build generated
rm -f compiler/ifcc
dist: all
@echo "Creating release ZIP..."
@rm -f release.zip
@mkdir -p release_tmp
@cp -r README.md Makefile compiler src docs testfiles release_tmp 2>/dev/null || true
@if [ -f presentation.pdf ]; then cp presentation.pdf release_tmp || true; fi
@zip -r release.zip release_tmp >/dev/null
@rm -rf release_tmp
@echo "release.zip created"