-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.sh
executable file
·95 lines (88 loc) · 2.96 KB
/
bootstrap.sh
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
#!/bin/bash
#
# A three-stage bootstrap for SCC. SCC is known to bootstrap partially with GCC 11.2.0 but should
# bootstrap just fine with any reasonable C compiler.
#
# Like most bootstraps, it's split into three stages:
# * Stage 1 - gcc builds scc and produces a stage1 scc compiler
# * Stage 2 - stage 1 scc builds scc and produces a stage2 scc compiler
# * Stage 3 - stage 2 scc builds scc and produces a stage3 scc compiler,
# which should be bit-by-bit identical to the stage 1 compiler
# if there are no bugs.
#
# SCC can't fully bootstrap yet, so the stage 2 and stage 3 compiles use gcc's stage 1 artifacts
# for files that scc can't handle yet.
set -x -e
STAGE_1="./scratch/bootstrap/stage1"
STAGE_2="./scratch/bootstrap/stage2"
STAGE_3="./scratch/bootstrap/stage3"
stage1() {
mkdir -p $STAGE_1
local cflags="--std=gnu11 -Wpedantic -Wall -Wextra -g"
gcc $cflags -c -o $STAGE_1/main.o main.c
gcc $cflags -c -o $STAGE_1/codegen.o codegen.c
gcc $cflags -c -o $STAGE_1/parse.o parse.c
gcc $cflags -c -o $STAGE_1/tokenize.o tokenize.c
gcc $cflags -c -o $STAGE_1/type.o type.c
gcc $cflags -c -o $STAGE_1/diag.o diag.c
gcc -static -o $STAGE_1/scc \
$STAGE_1/main.o \
$STAGE_1/codegen.o \
$STAGE_1/parse.o \
$STAGE_1/tokenize.o \
$STAGE_1/type.o \
$STAGE_1/diag.o
}
stage2() {
mkdir -p scratch/bootstrap/stage2
local scc="$STAGE_1/scc"
$scc main.c -o $STAGE_2/main.s
gcc -c -o $STAGE_2/main.o $STAGE_2/main.s
$scc parse.c -o $STAGE_2/parse.s
gcc -c -o $STAGE_2/parse.o $STAGE_2/parse.s
$scc codegen.c -o $STAGE_2/codegen.s
gcc -c -o $STAGE_2/codegen.o $STAGE_2/codegen.s
$scc tokenize.c -o $STAGE_2/tokenize.s
gcc -c -o $STAGE_2/tokenize.o $STAGE_2/tokenize.s
$scc type.c -o $STAGE_2/type.s
gcc -c -o $STAGE_2/type.o $STAGE_2/type.s
cp $STAGE_1/diag.o $STAGE_2/diag.o
gcc -static -o $STAGE_2/scc \
$STAGE_2/main.o \
$STAGE_2/codegen.o \
$STAGE_2/parse.o \
$STAGE_2/tokenize.o \
$STAGE_2/type.o \
$STAGE_2/diag.o
}
stage3() {
mkdir -p scratch/bootstrap/stage3
local scc="$STAGE_2/scc"
$scc main.c -o $STAGE_3/main.s
gcc -c -o $STAGE_3/main.o $STAGE_3/main.s
$scc parse.c -o $STAGE_3/parse.s
gcc -c -o $STAGE_3/parse.o $STAGE_3/parse.s
$scc codegen.c -o $STAGE_3/codegen.s
gcc -c -o $STAGE_3/codegen.o $STAGE_3/codegen.s
$scc tokenize.c -o $STAGE_3/tokenize.s
gcc -c -o $STAGE_3/tokenize.o $STAGE_3/tokenize.s
$scc type.c -o $STAGE_3/type.s
gcc -c -o $STAGE_3/type.o $STAGE_3/type.s
cp $STAGE_2/diag.o $STAGE_3/diag.o
gcc -static -o $STAGE_3/scc \
$STAGE_3/main.o \
$STAGE_3/codegen.o \
$STAGE_3/parse.o \
$STAGE_3/tokenize.o \
$STAGE_3/type.o \
$STAGE_3/diag.o
diff $STAGE_2/scc $STAGE_3/scc
}
main() {
mkdir -p scratch/bootstrap
stage1
stage2
stage3
cp $STAGE_3/scc ./scc
}
main