]> Joshua Wise's Git repositories - snipe.git/blame - optimize/optimizer.sml
Rename output binary from l5c to snipe
[snipe.git] / optimize / optimizer.sml
CommitLineData
5c79bb68
JW
1signature OPTIMIZER =
2sig
3 datatype optfunc =
4 IRPROG of (Tree.program -> Tree.program) |
5 IRFUNC of (Tree.func -> Tree.func) |
6 IRSTM of (Tree.stm -> Tree.stm list) |
7 IREXP of (Tree.exp -> Tree.exp) |
8 PRELIVENESS of (x86.insn list -> x86.insn list) |
9 FINAL of (x86.insn list -> x86.insn list)
10
11 type optimization = {
12 shortname : string,
13 description : string,
14 func : optfunc
15 }
16
17 val optimize_ir : optimization list -> Tree.program -> Tree.program
18 val optimize_preliveness : optimization list -> x86.insn list -> x86.insn list
19 val optimize_final : optimization list -> x86.insn list -> x86.insn list
20end
21
22structure Optimizer :> OPTIMIZER =
23struct
24 structure T = Tree
25
26 datatype optfunc =
27 IRPROG of (Tree.program -> Tree.program) |
28 IRFUNC of (Tree.func -> Tree.func) |
29 IRSTM of (Tree.stm -> Tree.stm list) |
30 IREXP of (Tree.exp -> Tree.exp) |
31 PRELIVENESS of (x86.insn list -> x86.insn list) |
32 FINAL of (x86.insn list -> x86.insn list)
33
34 type optimization = {
35 shortname : string,
36 description : string,
37 func : optfunc
38 }
39
40 fun foldfunc f (T.FUNCTION (id, stml)) = T.FUNCTION (id, List.concat (List.map f stml))
41 fun expfunc f (T.MOVE (e1, e2)) = [T.MOVE (f e1, f e2)]
42 | expfunc f (T.RETURN (e, s)) = [T.RETURN (f e, s)]
43 | expfunc f (T.EFFECT e) = [T.EFFECT (f e)]
44 | expfunc f (a as T.LABEL _) = [a]
45 | expfunc f (T.JUMPIFN (e, l)) = [T.JUMPIFN (f e, l)]
46 | expfunc f (a as T.JUMP _) = [a]
47
48 fun optimize_ir ol prog =
49 foldr (
50 fn (IRPROG f, prog) => f prog
51 | (IRFUNC f, prog) => List.map f prog
52 | (IRSTM f, prog) => List.map (foldfunc (f)) prog
53 | (IREXP f, prog) => List.map (foldfunc (expfunc f)) prog
54 | (_, prog) => prog)
55 prog
56 (map (fn (x : optimization) => #func x) ol)
57
58 fun optimize_preliveness ol assem =
59 foldr (
60 fn (PRELIVENESS f, assem) => f assem
61 | (_, assem) => assem)
62 assem
63 (map (fn (x : optimization) => #func x) ol)
64
65 fun optimize_final ol assem =
66 foldr (
67 fn (FINAL f, assem) => f assem
68 | (_, assem) => assem)
69 assem
70 (map (fn (x : optimization) => #func x) ol)
71end
72
73signature OPTIMIZATION =
74sig
75 val optimizer : Optimizer.optimization
76end
This page took 0.027243 seconds and 4 git commands to generate.