forked from plclub/hs-to-coq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
391 lines (318 loc) · 12.3 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
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
include ../../common.mk
OUT=lib
CORE_EDITS=axiomatize-types.edits
# Not all of these need to be handwritten. Eventually we should be able to
# generate some of these modules as hs-to-coq is improved.
# see [notes.md] for discussion of issues
# Handwritten modules (usually by modification of generated version)
HANDMOD = \
FastString \
AxiomatizedTypes \
NestedRecursionHelpers \
IntMap \
# Used by CSE
# TysWiredIn \
# generated from drop-in/
DROPIN = \
# These are core dependencies that we do not need to translate
#
EXTRA_CORE = Json \
FastFunctions \
Encoding \
ErrUtils \
Annotations \
GhcPrelude \
Packages \
Foreign \
IfaceType \
PrelNames \
TysWiredIn \
CoAxiom
UTILS = \
Util \
SrcLoc \
Unique \
UniqSupply \
BasicTypes \
DynFlags \
Panic \
OccName \
Module \
DATASTRUCTS = \
Bag \
EnumSet \
BooleanFormula \
UniqFM \
UniqSet \
OrdList \
FiniteMap \
ListSetOps \
Pair \
State \
Maybes \
MonadUtils \
# Generated modules
# generated directly from ghc/compiler/*/
# These are general purpose utility modules
MODULES = \
$(UTILS) \
$(DATASTRUCTS) \
## Not actually used??
# CmmType \
##
CORESYN = \
IdInfo Class TyCon DataCon PatSyn Var VarSet VarEnv CoreSyn Demand Type TyCoRep Coercion \
##
CONSTRUCTORS = \
# These are modules that we translate but do not do anything about
EXTRAS = \
TrieMap \
CSE \
CoreStats \
UnVarGraph \
CoreArity \
CoreTidy \
CallArity \
CoAxiom \
TysWiredIn \
MkCore \
Digraph \
SetLevels \
CoreMonad \
OccurAnal \
FloatIn \
FloatOut \
## These are the modules most directly related to the core language
CORE_MODULES = \
FastStringEnv \
Constants \
Id \
CoreSubst \
PrelNames \
CoreUtils \
Name \
NameEnv \
NameSet \
FV \
Literal \
FieldLabel \
ConLike \
CoreFVs \
Exitify \
NOTRANSLATE = \
Constructors \
CoreType \
IdInfo2 \
CORETYPE = \
TyCoRep \
Coercion \
# These modules translate, but do not compile, at the moment and
# should not be processed by coq
BROKEN_MODULES = \
VFILES_GEN = $(addsuffix .v,$(MODULES))
VFILES_MAN = $(addsuffix .v,$(HANDMOD))
VFILES_DROPIN = $(addsuffix .v,$(DROPIN))
VFILES_CORE = $(addsuffix .v,$(CORE_MODULES) $(EXTRAS))
VFILES_CONSTR = Constructors.v
VFILES_CORESYN = Core.v
VFILES_TYPE = Type_.v
VFILES = $(VFILES_GEN) $(VFILES_MAN) $(VFILES_DROPIN) $(VFILES_CORE) $(VFILES_CORESYN)
OUTFILES_GEN = $(addprefix $(OUT)/,$(VFILES_GEN))
OUTFILES_MAN = $(addprefix $(OUT)/,$(VFILES_MAN))
OUTFILES_CORE = $(addprefix $(OUT)/,$(VFILES_CORE))
OUTFILES_DROPIN = $(addprefix $(OUT)/,$(VFILES_DROPIN))
OUTFILES_CORETYPE = $(addprefix $(OUT)/,$(VFILES_CORETYPE))
OUTFILES_CONSTR = $(addprefix $(OUT)/,$(VFILES_CONSTR))
OUTFILES_CORESYN = $(addprefix $(OUT)/,$(VFILES_CORESYN))
OUTFILES_TYPE = $(addprefix $(OUT)/,$(VFILES_TYPE))
OUTFILES = $(OUTFILES_GEN) $(OUTFILES_MAN) $(OUTFILES_DROPIN) $(OUTFILES_CORE) $(OUTFILES_CORESYN)
HSFILES = $(addsuffix .hs,$(MODULES) $(CORESYN) $(CORE_MODULES))
HSFILESPATH = $(addprefix ghc/compiler/*/,$(HSFILES))
SMALLCORE = $(addsuffix .hs,$(CORESYN))
SMALLPATH = $(addprefix ghc/compiler/*/,$(SMALLCORE))
EDITPATHS = $(addprefix module-edits/,$(MODULES) $(CORESYN) $(CORE_MODULES))
EDITFILES = edits $(CORE_EDITS) $(addsuffix /edits,$(EDITPATHS)) $(addsuffix /*.v, $(EDITPATHS))
all: vfiles coq
vfiles: $(OUT)/edits $(OUT)/README.md $(OUT)/_CoqProject $(OUTFILES)
core: $(OUT)/README.md coq
filelist:
@ls -1 $(HSFILESPATH)
editlist:
@ls -1 $(EDITFILES) 2>/dev/null | xargs cloc --by-file-by-lang --lang-no-ext=zsh --force-lang=zsh,edits --force-lang=Coq,v --skip-uniqueness
edittable:
@echo "skip"
@cat $(EDITFILES) 2>/dev/null | grep "skip" | grep -v "#" | grep -v "constructor" | grep -v "module" | wc -l
@echo "skip constructor"
@cat $(EDITFILES) 2>/dev/null | grep "skip constructor" | grep -v "#" | wc -l
@echo "skip module"
@cat $(EDITFILES) 2>/dev/null | grep "skip module" | grep -v "#" | wc -l
@echo "axiomatize"
@cat $(EDITFILES) 2>/dev/null | grep "axiomatize" | grep -v "#" | grep -v "module" | wc -l
@echo "redefine Axiom"
@cat $(EDITFILES) 2>/dev/null | grep "redefine Axiom" | grep -v "#" | wc -l
@echo "axiomatize module"
@cat $(EDITFILES) 2>/dev/null | grep "axiomatize" | grep "module" | grep -v "#" | wc -l
@echo "order"
@cat $(EDITFILES) 2>/dev/null | grep "order" | grep -v "#" | wc -l
@echo "termination"
@cat $(EDITFILES) 2>/dev/null | grep "termination" | grep -v "#" | wc -l
@echo "rewrite"
@cat $(EDITFILES) 2>/dev/null | grep "rewrite" | grep -v "#" | wc -l
@echo "redefine"
@cat $(EDITFILES) 2>/dev/null | grep "redefine" | grep -v "#" | grep -v "Axiom"
@echo "rename type"
@cat $(EDITFILES) 2>/dev/null | grep "rename type" | grep -v "#" | wc -l
@echo "rename value"
@cat $(EDITFILES) 2>/dev/null | grep "rename value" | grep -v "#" | wc -l
@echo "set type"
@cat $(EDITFILES) 2>/dev/null | grep "set type" | grep -v "#" | wc -l
@echo "inline mutual"
@cat $(EDITFILES) 2>/dev/null | grep "inline mutual" | grep -v "#" | wc -l
@echo "rename module"
@cat $(EDITFILES) 2>/dev/null | grep "rename module" | grep -v "#" | wc -l
@echo "TOTAL"
@cat $(EDITFILES) 2>/dev/null | grep -v "#" --include "*edits" | wc -l
ghc.all.pdf: Makefile
find ghc/compiler -name \*.hs | xargs graphmod --no-cluster --prune-edges -r Outputable -r GhcPrelude | dot -Tpdf -o ghc.all.pdf
ghc.core.pdf: Makefile
@ls -1 $(HSFILESPATH) | xargs graphmod -i ghc/compiler/coreSyn -i ghc/compiler/basicTypes -i ghc/compiler/types -i ghc/compiler/utils -i ghc/compiler/simplCore -i ghc/compiler/main --no-cluster --prune-edges | dot -Tpdf -o ghc.core.pdf
# ghcrec.dot: Makefile
# @ls -1 $(SMALLPATH) | xargs graphmod -s 2 -i ghc/compiler/coreSyn -i ghc/compiler/basicTypes -i ghc/compiler/types -i ghc/compiler/utils -i ghc/compiler/simplCore -i ghc/compiler/main --prune-edges -r BooleanFormula -r Outputable -r Util -r DynFlags -r Module -r FiniteMap -r MonadUtils -r GhcPrelude -r FastString -r StringBuffer -r Lexeme -r UniqSupply -r BasicTypes -r CmdLineParser -r Packages -r Platform -r Binary -r UniqDSet -r OccName -r Digraph -r ErrUtils -r Panic -r Bag -r CoreStats -r SrcLoc -r Maybes -r Unique -r ListSetOps -r FastStringEnv -r UniqFM -r InteractiveEvalTypes -r OrdList -r DriverPhases -r Exception -r Pair -r UniqDFM -r UniqSet -r Constants > ghcrec.dot
ghcrec.pdf: ghcrec.dot
dot -Tpdf -o ghcrec.pdf ghcrec.dot
cloc_table_hs:
echo UTIL
cloc --by-file $(addsuffix .hs,$(addprefix ghc/compiler/*/,$(UTILS)))
echo DATASTRUCTS
cloc --by-file $(addsuffix .hs,$(addprefix ghc/compiler/*/,$(DATASTRUCTS)))
echo CORESYN
cloc --by-file $(addsuffix .hs,$(addprefix ghc/compiler/*/,$(CORESYN)))
echo CORE_MODULES
cloc --by-file $(addsuffix .hs,$(addprefix ghc/compiler/*/,$(CORE_MODULES)))
echo TOTAL
cloc $(addsuffix .hs,$(addprefix ghc/compiler/*/,$(MODULES) $(CORESYN) $(CORE_MODULES)))
cloc_table_v:
echo MANUAL
cloc --by-file $(addsuffix .v, $(addprefix manual/,$(HANDMOD)))
echo UTIL
cloc --by-file $(addsuffix .v,$(addprefix lib/,$(UTILS)))
echo DATASTRUCTS
cloc --by-file $(addsuffix .v,$(addprefix lib/,$(DATASTRUCTS)))
echo CORESYN
cloc --by-file lib/Core.v
echo CORE_MODULES
cloc --by-file $(addsuffix .v,$(addprefix lib/,$(CORE_MODULES)))
echo TOTAL
cloc $(addsuffix .v,$(addprefix lib/,$(MODULES) $(CORE_MODULES))) lib/Core.v $(addsuffix .v, $(addprefix manual/,$(HANDMOD)))
# This target is also used as a dependecy to ensure that $(OUT) exists.
$(OUT)/README.md:
mkdir -p $(OUT)
mkdir -p deps
> $@
echo 'This directory contains a Coq’ified version of parts of GHC' >> $@
echo 'Do not edit files here! Instead, look in `examples/ghc`.' >> $@
$(OUT)/edits:
mkdir -p $(OUT)
ln -fs ../edits $(OUT)/edits
$(OUT)/_CoqProject: $(OUT)/README.md Makefile
> $@
echo '-Q . ""' >> $@
echo '-Q ../../../base ""' >> $@
echo '-Q ../../../base-thy Proofs' >> $@
echo '-Q ../../containers/lib ""' >> $@
echo '-Q ../../containers/theories ""' >> $@
echo '-Q ../../transformers/lib ""' >> $@
echo $(filter-out $(addsuffix .v,$(BROKEN_MODULES)), $(VFILES)) >> $@
$(OUT)/Makefile: $(OUT)/README.md $(OUT)/_CoqProject $(OUTFILES) Makefile
cd $(OUT); coq_makefile -f _CoqProject -o Makefile
coq: $(OUT)/Makefile $(OUTFILES)
$(MAKE) -C $(OUT) -f Makefile OPT=$(COQFLAGS)
HS_TO_COQ_GHC_OPTS=\
--ghc-tree ghc \
-i gen-files \
-I gen-files \
-I ghc/includes \
-I ghc/compiler \
--ghc -DSTAGE=2 \
--ghc -package=ghc-boot-th \
--ghc -XNoImplicitPrelude \
-e ../../base/edits \
-e ../containers/edits \
-e ../transformers/edits \
--iface-dir ../../base \
--iface-dir ../containers/lib \
--iface-dir ../transformers/lib \
--iface-dir $(OUT) \
--dependency-dir deps \
-e edits \
-N \
-include deps/*.mk
%.h2ci: %.v
test -e $@
.SECONDEXPANSION:
$(OUTFILES_GEN): $(OUT)/%.v : $$(wildcard module-edits/$$*/preamble.v) $$(wildcard module-edits/$$*/midamble.v) $$(wildcard module-edits/$$*/edits) edits
$(HS_TO_COQ) $(addprefix -e , $(wildcard module-edits/$*/edits)) \
$(addprefix -p , $(wildcard module-edits/$*/preamble.v)) \
$(addprefix --midamble , $(wildcard module-edits/$*/midamble.v)) \
$(HS_TO_COQ_GHC_OPTS) \
-o $(OUT) \
$(word 1,$(wildcard ghc-head/$*.hs ghc/compiler/*/$*.hs))
test -e $@
$(OUTFILES_CORE): $(OUT)/%.v : $$(wildcard module-edits/$$*/preamble.v) $$(wildcard module-edits/$$*/midamble.v) $$(wildcard module-edits/$$*/edits) edits $(CORE_EDITS)
$(HS_TO_COQ) $(addprefix -e , $(wildcard module-edits/$*/edits)) \
$(addprefix -p , $(wildcard module-edits/$*/preamble.v)) \
$(addprefix --midamble , $(wildcard module-edits/$*/midamble.v)) \
$(HS_TO_COQ_GHC_OPTS) \
-e $(CORE_EDITS) \
-o $(OUT) \
$(word 1,$(wildcard ghc-head/$*.hs ghc/compiler/*/$*.hs))
test -e $@
CORESYN_PRE = $(wildcard $(addprefix module-edits/, $(addsuffix /preamble.v, $(CORESYN))))
CORESYN_MID = $(wildcard $(addprefix module-edits/, $(addsuffix /midamble.v, $(CORESYN))))
$(OUTFILES_CORESYN) : edits $(CORE_EDITS) $(CORESYN_PRE) $(CORESYN_MID) $(wildcard $(addprefix module-edits/, $(addsuffix /edits, $(CORESYN))))
cat $(CORESYN_PRE) > CoreSyn_preamble.v
cat $(CORESYN_MID) > CoreSyn_midamble.v
$(HS_TO_COQ) $(HS_TO_COQ_GHC_OPTS) \
-p CoreSyn_preamble.v \
--midamble CoreSyn_midamble.v \
$(addprefix -e , $(wildcard $(addprefix module-edits/, $(addsuffix /edits, $(CORESYN))))) \
-e $(CORE_EDITS) \
-o $(OUT) \
$(addprefix ghc/compiler/*/, $(addsuffix .hs, $(CORESYN)))
test -e $@
rm -f CoreSyn_preamble.v CoreSyn_midamble.v
$(OUTFILES_TYPE) : edits $(CORE_EDITS) $$(wildcard module-edits/Type/preamble.v) $$(wildcard module-edits/Type/midamble.v) $$(wildcard module-edits/Type/edits)
$(HS_TO_COQ) $(addprefix -e , $(wildcard module-edits/Type/edits)) \
$(addprefix -p , $(wildcard module-edits/Type/preamble.v)) \
$(addprefix --midamble , $(wildcard module-edits/Type/midamble.v)) \
$(HS_TO_COQ_GHC_OPTS) \
-o Type_.v \
$(word 1,$(wildcard ghc-head/Type.hs ghc/compiler/*/Type.hs))
test -e $@
$(OUTFILES_CONSTR) : edits $(CORE_EDITS) module-edits/Constructors/preamble.v module-edits/Constructors/midamble.v module-edits/Constructors/edits
$(HS_TO_COQ) -e module-edits/Constructors/edits \
-p module-edits/Constructors/preamble.v \
--midamble module-edits/Constructors/midamble.v \
$(HS_TO_COQ_GHC_OPTS) \
-e $(CORE_EDITS) \
-o $(OUT) \
$(addprefix ghc/compiler/*/, $(addsuffix .hs, $(CONSTRUCTORS)))
test -e $@
$(OUTFILES_CORETYPE) : edits core-edits module-edits/CoreType/preamble.v module-edits/CoreType/midamble.v module-edits/CoreType/edits
$(HS_TO_COQ) -e module-edits/CoreType/edits \
-p module-edits/CoreType/preamble.v \
--midamble module-edits/CoreType/midamble.v \
$(HS_TO_COQ_GHC_OPTS) \
-e core-edits \
-o $(OUT) \
$(addprefix ghc/compiler/*/, $(addsuffix .hs, $(CORETYPE)))
test -e $@
$(OUTFILES_MAN): $(OUT)/%.v : manual/%.v
mkdir -p "$$(dirname $(OUT)/$*.v)"
rm -f $@
lndir ../manual $(OUT)/
clean:
rm -rf $(OUT)
rm -f *.aux *.log
cleancore:
rm -rf $(OUTFILES_CORE)