passes-quintus.pl
2.6 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
/*****************************************************************************/
/* */
/* Projecto de Compiladores ---------------------------------- VSPL */
/* Level 0 */
/* */
/* Compiler pass control and timing. */
/* */
/* Salvador Pinto Abreu */
/* */
/*****************************************************************************/
doPass(1, X) <-> T is cputime-T0, write(T), write(' seconds.'), nl
<= write('yacc: '), ttyflush, statistics(runtime, _),
make(stack, X).
doPass(2, X) <-> statistics(runtime, [_|T]), write(T), write(' msec.'), nl
<= write('loading: '), ttyflush, statistics(runtime, _),
load(X).
doPass(3, X) <-> try retract(apts0(X, _)), asserta(apts0(X, S)),
statistics(runtime, [_|T]), write(T), write(' msec.'), nl
<= write('type check: '), ttyflush, apt(X,A),
statistics(runtime, _),
initSymbols(S), tcStat(A,B,S).
doPass(4, X) <-> try retract(apts(X, _)), asserta(apts(X, S)),
statistics(runtime, [_|T]), write(T), write(' msec.'), nl
<= write('size symbols: '), ttyflush, apts0(X,S),
statistics(runtime, _),
sizeSymbols(S).
doPass(5, X) <-> statistics(runtime, [_|T]), write(T), write(' msec.'), nl
<= write('generate code: '), ttyflush, apts(X,S),
name(X, as, NN), name(N,NN), tell(N), statistics(runtime, _),
resetLabels(guard), resetLabels(if), resetLabels(rel),
resetLabels(proc), resetLabels(lit),
cgSymbols(S),
told.
doPass(6, X) <-> statistics(runtime, [_|T]), write(T), write(' msec.'), nl
<= write('assemble: '), ttyflush,
name(X, as, AS), name(X, object, OBJ),
append("as -o ", OBJ, X1), append(X1, " ", X2),
append(X2, AS, Command), statistics(runtime, _),
unix(shell(Command)).
doPass(_, X) # <= told, tell(user), write(' failed.'), nl.
compile(X) <-> pass(1-6, X).
link(X) <-> name(X, object, OBJ), name(X, NX),
append("cc -o ", NX, X1),
append(X1, " ", X2),
append(X2, OBJ, X3),
append(X3, " srt0.o srt0-aux.o", Command),
unix(shell(Command)).
run(X) <-> name(X, Command),
unix(shell(Command)).
pass(N, X) <-> pass(1, N, X) <= integer(N).
pass(N-M, X) <-> pass(N, M, X, []).
* * * * MUST FIX STUFF BELOW * * * * .
pass(N, M, X, _) ! <= N>M.
pass(N, M, X, _) ! <= M>6.
pass(N, N, X, Y) <-> doPass(N, X, Y).
pass(N, M, X, Z) <-> Np1 is N+1, pass(Np1, M, X) <= doPass(N, X, Y).