-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
137 lines (96 loc) · 4.15 KB
/
Makefile
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
# Can be Jlr1 or Jlalr1
GRAMMAR := Jlalr1
GHC_WARNINGS := -w -Wmissing-fields -Woverflowed-literals -Werror
GHC_OPTIONS = -threaded -rtsopts -with-rtsopts=-N -outputdir ${HS_BUILD} -O3 ${GHC_WARNINGS} -i${HS_INCLUDE}
GHC = stack build --only-dependencies && stack ghc -- ${GHC_OPTIONS}
DOC_INPUT := $(sort $(shell find ./docs -name '*.md'))
DOC_OUTPUT := $(patsubst %.md,%.pdf,${DOC_INPUT})
HS_LIB := src/lib
HS_LIB_FILES := $(shell find ${HS_LIB} -name '*.hs')
COMPILER_SRC := src/compiler
COMPILER_FILES := $(shell find ${COMPILER_SRC} -name '*.hs')
COMPILER_MAIN := ${COMPILER_SRC}/Main.hs
LEXER_SRC := src/lexer
LEXER_FILES := $(shell find ${LEXER_SRC} -name '*.hs')
LEXER_MAIN := ${LEXER_SRC}/Lexer.hs
WEEDER_SRC := src/weeder
WEEDER_FILES := $(shell find ${WEEDER_SRC} -name '*.hs')
HS_BUILD := ghc_build
HS_TEST := test/haskell
HS_INCLUDE := "${HS_LIB}:${LEXER_SRC}:${COMPILER_SRC}:${HS_TEST}"
ALL_HS_FILES := ${HS_LIB_FILES} ${LEXER_FILES} ${WEEDER_FILES} ${COMPILER_FILES}
# Includes all the files tracked by git.
ZIP_FILES := $(shell git ls-files)
.PHONY : compiler all zip clean docs grammar test.positive test.negative \
test test.unit hfmt ghci
# Only builds the compiler. This is the recipe run by Marmoset.
compiler : bin bin/parser bin/lexer bin/weeder bin/compiler
# Builds everything including the grammar and report.
all : compiler grammar docs
zip : joosc
rm -f submission.zip
@zip submission $(ZIP_FILES) --exclude 'test/*'
bin :
mkdir -p bin
bin/lexer : ${LEXER_FILES} ${HS_LIB_FILES}
${GHC} ${LEXER_MAIN} -o bin/lexer
bin/parser : src/rust/parser.rs
rustc --codegen opt-level=2 src/rust/parser.rs -o bin/parser
bin/weeder : src/weeder/weeder.hs ${HS_LIB_FILES}
${GHC} -o bin/weeder src/weeder/weeder.hs
bin/compiler : ${COMPILER_FILES} ${HS_LIB_FILES}
${GHC} -o $@ $^
docs : ${DOC_OUTPUT}
docs/%.pdf : docs/%.md
cd docs && ./generate-docs.sh $@ $<
grammar : def/joos.lr1
src/java/jlalr/${GRAMMAR}.class : src/java/jlalr/Jlalr1.java
javac src/java/jlalr/Jlalr1.java
# cfg2 is a human-readable format of cfg.
bin/joos.cfg : bin def/joos.cfg2
sed -e '/^#/d' -e '/^\s*$$/d' < def/joos.cfg2 > bin/productions.txt
sed 's/\s\s*/\n/g' bin/productions.txt | sort -u > bin/symbols.txt
cut -d' ' -f1 bin/productions.txt | sort -u > bin/nonterminals.txt
comm -23 bin/symbols.txt bin/nonterminals.txt > bin/terminals.txt
bash -c "cat <(wc -l < bin/terminals.txt) bin/terminals.txt \
<(wc -l < bin/nonterminals.txt) bin/nonterminals.txt \
<(echo S) \
<(wc -l < bin/productions.txt) bin/productions.txt" > bin/joos.cfg
def/joos.lr1 : src/java/jlalr/${GRAMMAR}.class bin/joos.cfg
java -classpath src/java jlalr.${GRAMMAR} < bin/joos.cfg > def/joos.lr1
# Format haskell code
hfmt :
stack build hfmt && stack exec hfmt -- -w src
ghci :
stack ghci --ghci-options -i"${HS_INCLUDE}"
test.unit :
stack exec runghc -- -i"${HS_INCLUDE}" test/haskell/UnitTest.hs
test.positive : compiler
@TESTNUM=1 ./testrunner-sequential.sh positive
test.negative : compiler
@./testrunner-sequential.sh negative
test.java : compiler
@COMPILER=javac ./testrunner-sequential.sh positive
test : compiler
@./testrunner-sequential-sequenial.sh all
test.a1 : compiler
@TESTNUM=1 TESTSET=test/marmoset/a1 ./testrunner-sequential.sh all
test.a2 : compiler
@TESTNUM=2 TESTSET=test/marmoset/a2 ./testrunner-sequential.sh all
test.a3 : compiler
@TESTNUM=3 TESTSET=test/marmoset/a3 ./testrunner-sequential.sh all
test.a4 : compiler
@TESTNUM=4 TESTSET=test/marmoset/a4 ./testrunner-sequential.sh all
test.a5 : compiler
@./testrunner-codegen.sh
test.all : compiler
@OUT="A1 $$(make test.a1 | tee /dev/stderr | grep Passed)\n"; \
OUT="$${OUT}A2 $$(make test.a2 | tee /dev/stderr | grep Passed)\n"; \
OUT="$${OUT}A3 $$(make test.a3 | tee /dev/stderr | grep Passed)\n"; \
OUT="$${OUT}A4 $$(make test.a4 | tee /dev/stderr | grep Passed)\n"; \
OUT="$${OUT}A5 $$(make test.a5 | tee /dev/stderr | grep Passed)\n"; \
echo -e "\n\n$${OUT}"
clean :
find src \( -name '*.o' -o -name '*.hi' \) -delete
find test \( -name '*.tokens' -o -name '*.parse' -o -name '*.ast' \) -delete
rm -rf bin/ ${DOC_OUTPUT} src/java/jlalr/*.class submission.zip ${HS_BUILD}