-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
106 lines (81 loc) · 3.71 KB
/
Copy pathMakefile
File metadata and controls
106 lines (81 loc) · 3.71 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
TARGET = tinyc
CC = gcc
CFLAGS = -Wall -Wextra -g -Isrc
LDFLAGS =
BUILD_DIR = build
SRCS = src/main.c \
src/lexer/token.c \
src/parser/ast.c \
src/parser/parser.c \
src/ir/ir.c \
src/codegen/x86/x86_ast.c \
src/codegen/codegen.c \
src/codegen/emit.c \
src/strlib/str.c
OBJS = $(SRCS:src/%.c=$(BUILD_DIR)/%.o)
TEST_TARGETS = tests/test_list tests/test_token tests/test_parser tests/test_str tests/test_codegen tests/test_ir tests/test_ast tests/test_scoping tests/test_typecheck
all: $(TARGET)
$(TARGET): $(OBJS)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
$(BUILD_DIR)/%.o: src/%.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c -o $@ $<
test: build_tests
@echo "Running tests..."
@./tests/test_list
@./tests/test_token
@./tests/test_parser
@./tests/test_codegen
@./tests/test_ir
@./tests/test_ast
@./tests/test_scoping
@./tests/test_typecheck
@echo "test_str skipped: str_split not yet implemented"
# End-to-end: compile each tests/e2e/cases/*.c with tinyc, link, run, and check
# the exit code against its .expect file (cross-checked against cc).
test-e2e: $(TARGET)
@echo "Running e2e tests..."
@bash tests/e2e/run_e2e.sh $(abspath $(TARGET))
# Static System V ABI checks on the assembly generated for the call_*.c cases:
# stack alignment at each call, no pushq of a 4-byte memory slot, pushed
# argument bytes reclaimed. These catch misalignment that a runtime test only
# finds by luck.
# System V AMD64 conformance: pins the argument registers, stack argument
# offsets, return register, pushq width and call alignment that src/codegen
# assumes, using hand-written reference assembly rather than tinyc output.
test-abi: tests/abi/test_abi
@./tests/abi/test_abi
tests/abi/test_abi: tests/abi/test_abi.c tests/abi/abi_reference.s
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
test-asm: $(TARGET)
@echo "Running asm ABI checks..."
@bash tests/e2e/check_call_asm.sh $(abspath $(TARGET))
build_tests: tests/test_list tests/test_token tests/test_parser tests/test_codegen tests/test_ir tests/test_ast tests/test_scoping tests/test_typecheck
tests/test_list: tests/test_list.c $(BUILD_DIR)/lexer/token.o
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
tests/test_token: tests/test_token.c $(BUILD_DIR)/lexer/token.o
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
tests/test_parser: tests/test_parser.c $(BUILD_DIR)/parser/ast.o $(BUILD_DIR)/parser/parser.o $(BUILD_DIR)/lexer/token.o $(BUILD_DIR)/strlib/str.o
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
tests/test_codegen: tests/test_codegen.c $(BUILD_DIR)/codegen/x86/x86_ast.o $(BUILD_DIR)/codegen/codegen.o $(BUILD_DIR)/codegen/emit.o $(BUILD_DIR)/ir/ir.o $(BUILD_DIR)/parser/ast.o
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
tests/test_ir: tests/test_ir.c $(BUILD_DIR)/ir/ir.o $(BUILD_DIR)/parser/ast.o
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
tests/test_ast: tests/test_ast.c $(BUILD_DIR)/parser/ast.o
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
tests/test_scoping: tests/test_scoping.c $(BUILD_DIR)/parser/ast.o $(BUILD_DIR)/parser/parser.o $(BUILD_DIR)/lexer/token.o $(BUILD_DIR)/strlib/str.o
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
tests/test_typecheck: tests/test_typecheck.c $(BUILD_DIR)/parser/ast.o $(BUILD_DIR)/parser/parser.o $(BUILD_DIR)/lexer/token.o $(BUILD_DIR)/strlib/str.o
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
tests/test_str:
@echo "test_str skipped: str_split not yet implemented"
@touch tests/test_str
@# dummy target
clean:
rm -rf $(BUILD_DIR)
find . -name "*.o" -delete
rm -f $(TARGET) $(TEST_TARGETS) tests/abi/test_abi
find . -name "*.dSYM" -type d -exec rm -rf {} +
@# stray e2e artifacts (the runner cleans up, but guard against interrupted runs)
find tests/e2e/cases -type f ! -name '*.c' ! -name '*.expect' -delete 2>/dev/null || true
.PHONY: all test test-e2e test-asm test-abi clean