passes.pl
2.41 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
/*****************************************************************************/
/* */
/* 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, T0 is cputime,
make(stack, X).
doPass(2, X) <-> T is cputime-T0, write(T), write(' seconds.'), nl
<= write('loading: '), ttyflush, T0 is cputime,
load(X).
doPass(3, X) <-> try retract(apts0(X, _)), asserta(apts0(X, S)),
T is cputime-T0, write(T), write(' seconds.'), nl
<= write('type check: '), ttyflush, apt(X,A), T0 is cputime,
initSymbols(S), tcStat(A,B,S).
doPass(4, X) <-> try retract(apts(X, _)), asserta(apts(X, S)),
T is cputime-T0, write(T), write(' seconds.'), nl
<= write('size symbols: '), ttyflush, apts0(X,S), T0 is cputime,
sizeSymbols(S).
doPass(5, X) <-> T is cputime-T0, write(T), write(' seconds.'), nl
<= write('generate code: '), ttyflush, apts(X,S),
name(X, as, NN), name(N,NN), tell(N), T0 is cputime,
resetLabels(guard), resetLabels(if), resetLabels(rel),
resetLabels(proc), resetLabels(lit),
cgSymbols(S),
told.
doPass(6, X) <-> T is cputime-T0, write(T), write(' seconds.'), nl
<= write('assemble: '), ttyflush,
name(X, as, AS), name(X, object, OBJ),
append("as -o ", OBJ, X1), append(X1, " ", X2),
append(X2, AS, Command), T0 is cputime,
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),
shell(Command).
run(X) <-> name(X, Command),
shell(Command).
pass(N, X) <-> pass(1, N, X) <= integer(N).
pass(N-M, X) <-> pass(N, M, X).
pass(N, M, X) ! <= N>M.
pass(N, M, X) ! <= M>6.
pass(N, N, X) <-> doPass(N, X).
pass(N, M, X) <-> Np1 is N+1, pass(Np1, M, X) <= doPass(N, X).