blob: 3e0f75e273698818b4e998637350510c2625d525 (
plain)
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
|
# Makefile for the bootstrap compiler.
#
# Copyright © 2021-2025 Samuel Lidén Borell <samuel@kodafritt.se>
#
# SPDX-License-Identifier: EUPL-1.2+ OR LGPL-2.1-or-later
srcdir = .
builddir = .
VPATH = $(srcdir)
MKDIR = mkdir
MKDIR_P = $(MKDIR) -p
RM = rm
RM_F = $(RM) -f
HOST_CC = $(CC)
CFLAGS = -g
HOST_CFLAGS = $(CFLAGS)
HOST_LDFLAGS = $(LDFLAGS)
BASE_WARNINGS = -Wall -Wextra -pedantic \
-Walloca \
-Wbad-function-cast \
-Wcast-align \
-Wconversion \
-Wdate-time \
-Wmissing-declarations \
-Wmissing-prototypes \
-Wmissing-noreturn \
-Wnested-externs \
-Wnull-dereference \
-Wold-style-definition \
-Wshadow \
-Wshift-negative-value \
-Wshift-overflow \
-Wstrict-aliasing \
-Wstrict-overflow=5 \
-Wstrict-prototypes \
-Wswitch-enum \
-Wundef \
-Wunused \
-Wvla \
-Wwrite-strings
BASE_CFLAGS = -std=c89 $(WARNINGS) $(BASE_WARNINGS)
CLANG_ANALYZE_OPTS = --analyzer-output text
OBJECTS = \
$(builddir)/ast.o \
$(builddir)/builtins.o \
$(builddir)/funccall.o \
$(builddir)/intrange.o \
$(builddir)/main.o \
$(builddir)/parsedecl.o \
$(builddir)/parseexpr.o \
$(builddir)/parsestmt.o \
$(builddir)/out.o \
$(builddir)/outcommon.o \
$(builddir)/outdecl.o \
$(builddir)/outexpr.o \
$(builddir)/outstmt.o \
$(builddir)/tree.o \
$(builddir)/token.o \
$(builddir)/typechk.o \
$(builddir)/typecompat.o \
$(builddir)/util.o
C_SOURCES = \
$(srcdir)/ast.c \
$(srcdir)/builtins.c \
$(srcdir)/funccall.c \
$(srcdir)/intrange.c \
$(srcdir)/main.c \
$(srcdir)/parsedecl.c \
$(srcdir)/parseexpr.c \
$(srcdir)/parsestmt.c \
$(srcdir)/out.c \
$(srcdir)/outcommon.c \
$(srcdir)/outdecl.c \
$(srcdir)/outexpr.c \
$(srcdir)/outstmt.c \
$(srcdir)/tree.c \
$(srcdir)/token.c \
$(srcdir)/typechk.c \
$(srcdir)/typecompat.c \
$(srcdir)/util.c
C_HEADERS = \
$(srcdir)/out.h \
$(srcdir)/compiler.h \
$(srcdir)/token.h
RTL_OBJECTS = \
$(builddir)/rtl/cli.o \
$(builddir)/rtl/fail.o \
$(builddir)/rtl/message.o \
$(builddir)/rtl/string.o \
$(builddir)/rtl/writer.o
RTL_C_SOURCES = \
$(srcdir)/rtl/cli.c \
$(srcdir)/rtl/fail.c \
$(srcdir)/rtl/message.c \
$(srcdir)/rtl/string.c \
$(srcdir)/rtl/writer.c
RTL_C_HEADERS = \
$(srcdir)/rtlincl/rtl.h \
$(srcdir)/rtl/internal.h
STAGE2_OBJECTS = \
$(RTL_OBJECTS) \
$(builddir)/stage2_gen.o
STAGE2_C_SOURCE = \
$(builddir)/stage2_gen.c
STAGE2_INCLUDE = \
-I$(srcdir)/rtlincl
# perhaps it could pass multiple paths here, to include the backend library
# (or, in the future, whatever vendored libraries that the compiler needs)
STAGE1_ARGS = $(builddir)/stage2_gen.c $(srcdir)/../compiler
COMPILER_SOURCES = \
$(srcdir)/../compiler/misc.slul \
$(srcdir)/../compiler/SomeClass.slul \
$(srcdir)/../compiler/TheCommand.slul
all: $(builddir)/stage2
$(OBJECTS): $(srcdir)/compiler.h
out.o outcommon.o outdecl.o outexpr.o outstmt.o: $(srcdir)/out.h
ast.o funccall.o out.o parsedecl.o parseexpr.o parsestmt.o \
token.o typechk.o: $(srcdir)/token.h
$(RTL_OBJECTS): $(RTL_C_HEADERS)
.SUFFIXES: .c .o
# Note: the stage2 includes (rtlincl/ and rtl/) may only be used in actual
# stage2 code and in the RTL code, not in any other places!
.c.o:
$(HOST_CC) $(HOST_CFLAGS) $(BASE_CFLAGS) $(STAGE2_INCLUDE) -c -o $@ $<
$(builddir)/stage1: $(OBJECTS)
$(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ $(OBJECTS)
$(builddir)/stage1-boundschecked: $(C_SOURCES) $(C_HEADERS)
tcc -b -bt24 -o $@ $(C_SOURCES)
$(builddir)/stage2_gen.c: $(builddir)/stage1 $(COMPILER_SOURCES)
$(builddir)/stage1 $(STAGE1_ARGS)
$(builddir)/stage2: $(STAGE2_OBJECTS) $(RTL_C_HEADERS)
$(CC) $(CFLAGS) $(BASE_CFLAGS) $(STAGE2_DISABLED_WARNINGS) \
$(STAGE2_CFLAGS) $(LDFLAGS) \
$(STAGE2_INCLUDE) \
-o $@ \
$(STAGE2_OBJECTS)
.PHONY: all check check-all check-boundschecked check-valgrind \
check-pmccabe clang-analyze clean gcc-analyzer gdb-stage1 \
longlines outdirs
# TODO add a proper test once the stage2 compiler is done
check: $(builddir)/stage2
check-all: check check-valgrind check-boundschecked clang-analyze longlines
check-valgrind: $(builddir)/stage1
valgrind --leak-check=yes -q $(builddir)/stage1 $(STAGE1_ARGS)
check-boundschecked: $(builddir)/stage1-boundschecked
TCC_BOUNDS_WARN_POINTER_ADD=1 $(builddir)/stage1-boundschecked \
$(STAGE1_ARGS)
clang-analyze:
clang --analyze $(CLANG_ANALYZE_OPTS) $(C_SOURCES)
longlines:
if grep -nE '^.{80,}' $(C_SOURCES) $(C_HEADERS); then \
echo "error: Too long lines detected. Maximum is 80 characters" ;\
false ;\
else \
true ;\
fi
# Gives a lot of warnings (possibly false positives) and output gets mixed
# up (unless a single file is processed). So not included in check-all.
gcc-analyzer:
gcc -fanalyzer $(C_SOURCES)
check-pmccabe:
pmccabe -c $(C_SOURCES) | sort -nr | head -n 20
gdb-stage1: $(builddir)/stage1
gdb -q --args $(builddir)/stage1 $(STAGE1_ARGS)
clean:
-$(RM_F) \
$(builddir)/stage1 \
$(builddir)/stage1-boundschecked \
$(builddir)/stage2_gen.c \
$(builddir)/stage2 \
$(OBJECTS) \
$(STAGE2_OBJECTS)
outdirs:
$(MKDIR_P) $(builddir) $(builddir)/rtl
|