Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/compiler/FLINT/main/flintcomp.sml
ViewVC logotype

Annotation of /sml/trunk/src/compiler/FLINT/main/flintcomp.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 162 - (view) (download)

1 : monnier 16 (* COPYRIGHT (c) 1998 YALE FLINT PROJECT *)
2 :     (* flintcomp.sml *)
3 :    
4 :     functor FLINTComp (structure Gen: CPSGEN
5 :     val collect: unit -> Word8Vector.vector) : CODEGENERATOR =
6 :     struct
7 :    
8 :     local structure CB = CompBasic
9 : monnier 122 (* structure CGC = Control.CG *)
10 : monnier 16 structure MachSpec = Gen.MachSpec
11 :     structure Convert = Convert(MachSpec)
12 :     structure CPStrans = CPStrans(MachSpec)
13 :     structure CPSopt = CPSopt(MachSpec)
14 : monnier 102 structure Closure = Closure(MachSpec)
15 : monnier 16 structure Spill = Spill(MachSpec)
16 :     structure CpsSplit = CpsSplitFun (MachSpec)
17 : monnier 162 structure CTRL = Control.FLINT
18 : monnier 16 in
19 :    
20 :     val architecture = Gen.MachSpec.architecture
21 :     fun bug s = ErrorMsg.impossible ("FLINTComp:" ^ s)
22 :     val say = Control.Print.say
23 :    
24 :     fun phase x = Stats.doPhase (Stats.makePhase x)
25 :    
26 : monnier 162 val lcontract = phase "Compiler 052 lcontract" LContract.lcontract
27 : monnier 122 val fcontract = phase "Compiler 052 fcontract" FContract.contract
28 : monnier 71 val specialize= phase "Compiler 053 specialize" Specialize.specialize
29 :     val wrapping = phase "Compiler 054 wrapping" Wrapping.wrapping
30 :     val reify = phase "Compiler 055 reify" Reify.reify
31 : monnier 122 val fixfix = phase "Compiler 056 fixfix" FixFix.fixfix
32 : monnier 16
33 : monnier 71 val convert = phase "Compiler 060 convert" Convert.convert
34 :     val cpstrans = phase "Compiler 065 cpstrans" CPStrans.cpstrans
35 : monnier 16 val cpsopt = phase "Compiler 070 cpsopt" CPSopt.reduce
36 : monnier 102 val litsplit = phase "Compiler 075 litsplit" Literals.litsplit
37 :     val lit2cps = phase "Compiler 076 lit2cps" Literals.lit2cps
38 :     val closure = phase "Compiler 080 closure" Closure.closeCPS
39 : monnier 16 val globalfix = phase "Compiler 090 globalfix" GlobalFix.globalfix
40 :     val spill = if MachSpec.spillAreaSz < 500 * MachSpec.valueSize
41 :     then phase "Compiler 100 spill" Spill.spill
42 :     else fn x => x
43 :     val limit = phase "Compiler 110 limit" Limit.nolimit
44 :     val codegen = phase "Compiler 120 cpsgen" Gen.codegen
45 :    
46 : monnier 102 val closureD = phase "Compiler 081 closureD" Closure.closeCPS
47 :     val globalfixD= phase "Compiler 091 globalfixD" GlobalFix.globalfix
48 :     val spillD = if MachSpec.spillAreaSz < 500 * MachSpec.valueSize
49 :     then phase "Compiler 101 spillD" Spill.spill
50 :     else fn x => x
51 :     val limitD = phase "Compiler 110 limitD" Limit.nolimit
52 :     val codegenD = phase "Compiler 121 cpsgenD" Gen.codegen
53 : monnier 16
54 : monnier 71 (** pretty printing for the FLINT and CPS code *)
55 :     val (prF, prC) =
56 :     let fun prGen (flag,printE) s e =
57 : monnier 102 if !flag then (say ("\n[After " ^ s ^ " ...]\n\n"); printE e;
58 :     say "\n"; e)
59 : monnier 71 else e
60 : monnier 162 in (prGen (CTRL.print, PPFlint.printProg),
61 : monnier 122 prGen (Control.CG.printit, PPCps.printcps0))
62 : monnier 71 end
63 : monnier 16
64 : monnier 71 (** writing out a term into a error output file *)
65 :     fun dumpTerm (printE, s, le) =
66 :     let val outS = TextIO.openAppend s;
67 :     val saveOut = !Control.Print.out
68 :     fun done () =
69 :     (TextIO.closeOut outS; Control.Print.out := saveOut)
70 :     in Control.Print.out := {say = fn s => TextIO.output(outS,s),
71 :     flush = fn () => TextIO.flushOut outS};
72 :     printE le handle x => (done () handle _ => (); raise x);
73 :     done ()
74 :     end (* function dumpTerm *)
75 :    
76 : monnier 16 (** compiling FLINT code into the binary machine code *)
77 :     fun flintcomp(flint, compInfo as {error, sourceName=src, ...}: CB.compInfo) =
78 :     let fun err severity s =
79 :     error (0,0) severity (concat["Real constant out of range: ",s,"\n"])
80 :    
81 :     fun check (checkE,printE,chkId) (enableChk,lvl,logId) e =
82 :     (if !enableChk andalso checkE (e,lvl) then
83 : monnier 71 (dumpTerm (printE, src ^ "." ^ chkId ^ logId, e);
84 :     bug (chkId ^ " typing errors " ^ logId))
85 : monnier 16 else ();
86 :     e)
87 : monnier 71 fun chkF (b, s) =
88 :     check (ChkFlint.checkTop, PPFlint.printFundec,
89 : monnier 162 "FLINT") (CTRL.check, b, s)
90 : monnier 16
91 : monnier 162 (* f:FLINT.prog flint codee
92 :     * r:boot whether it has gone through reify yet
93 :     * l:string last phase through which it went *)
94 :     fun runphase (p as "fcontract",(f,r,l)) = (fcontract f, r, p)
95 :     | runphase (p as "lcontract",(f,r,l)) = (lcontract f, r, p)
96 :     | runphase (p as "fixfix",(f,r,l)) = (fixfix f, r, p)
97 :     | runphase (p as "wrap",(f,false,l)) = (wrapping f, false, p)
98 :     | runphase (p as "specialize",(f,false,l)) = (specialize f, false, p)
99 :     | runphase (p as "reify",(f,false,l)) = (reify f, true, p)
100 : monnier 122
101 : monnier 162 (* pseudo FLINT phases *)
102 :     | runphase ("id",(f,r,l)) = (f,r,l)
103 :     | runphase (p as "print",(f,r,l)) =
104 :     (say("\n[ After "^l^"... ]\n"); PPFlint.printFundec f; (f,r,l))
105 :     | runphase ("check",(f,r,l)) =
106 :     (check (ChkFlint.checkTop, PPFlint.printFundec, "FLINT")
107 :     (ref true, r, l) f; (f,r,l))
108 :     | runphase (p as ("reify"|"specialize"|"wrap"),(f,true,l)) =
109 :     (say("\n"^p^"cannot be used after reify!\n"); (f,true,l))
110 :     | runphase (p,(f,r,l)) =
111 :     (say("\n!! Unknown FLINT phase '"^p^"' !!\n"); (f,r,l))
112 : monnier 16
113 : monnier 162 fun print (f,r,l) = (prF l f; (f, r, l))
114 :     fun check (f,r,l) = (chkF (r, l) f; (f, r, l))
115 :    
116 :     (* the "id" phases is just added to do the print/check at the entrance *)
117 :     val (flint,true,_) = foldl (check o print o runphase)
118 :     (flint,false,"flintnm")
119 :     ("id" :: !CTRL.phases)
120 :    
121 :     (* val _ = (chkF (false,"1") o prF "Translation/Normalization") flint *)
122 :     (* val flint = (chkF (false,"2") o prF "Fcontract" o fcontract) flint *)
123 :    
124 :     (* val flint = *)
125 :     (* if !Control.FLINT.specialize then *)
126 :     (* (chkF (false,"3") o prF "Specialization" o specialize) flint *)
127 :     (* else flint *)
128 :     (* val flint = (chkF (false,"2") o prF "Fcontract" o fcontract) flint *)
129 :    
130 : monnier 122 (* val flint = (chkF (false,"6") o prF "FixFix" o fixfix) flint *)
131 : monnier 162 (* val flint = (chkF (false,"2") o prF "Fcontract" o fcontract) flint *)
132 : monnier 122
133 : monnier 162 (* val flint = (chkF (false, "4") o prF "Wrapping" o wrapping) flint *)
134 :     (* val flint = (chkF (true, "5") o prF "Reify" o reify) flint *)
135 : monnier 102
136 : monnier 162 (* val flint = (chkF (true,"2") o prF "Fcontract" o fcontract) flint *)
137 : monnier 122
138 : monnier 102 val (nc0, ncn, dseg) =
139 :     let val function = convert flint
140 :     val _ = prC "convert" function
141 : monnier 71 val function = (prC "cpstrans" o cpstrans) function
142 : monnier 162 val function = cpsopt (function,NONE,false)
143 : monnier 71 val _ = prC "cpsopt" function
144 : monnier 45
145 : monnier 102 val (function, dlit) = litsplit function
146 :     val data = lit2cps dlit
147 :     val _ = prC "cpsopt-code" function
148 :     val _ = prC "cpsopt-data" data
149 :    
150 : monnier 71 fun gen fx =
151 :     let val fx = (prC "closure" o closure) fx
152 :     val carg = globalfix fx
153 :     val carg = spill carg
154 :     val (carg, limit) = limit carg
155 :     in codegen (carg, limit, err);
156 :     collect ()
157 :     end
158 : monnier 102
159 :     fun gdata dd =
160 :     let val x = Control.CG.printit
161 :     val y = !x
162 :     val _ = (x := false)
163 :     val fx = (prC "closure" o closureD) dd
164 :     val carg = globalfixD fx
165 :     val carg = spillD carg
166 :     val (carg, limit) = limitD carg
167 :     in codegenD (carg, limit, err);
168 :     (collect ()) before (x := y)
169 :     end
170 : monnier 71 in case CpsSplit.cpsSplit function
171 : monnier 102 of (fun0 :: funn) => (gen fun0, map gen funn, gdata data)
172 : monnier 71 | [] => bug "unexpected case on gen in flintcomp"
173 :     end
174 : monnier 102 in {c0=nc0, cn=ncn, data=dseg, name=ref (SOME src)}
175 : monnier 16 end (* function flintcomp *)
176 :    
177 : monnier 71 val flintcomp = phase "Compiler 050 flintcomp" flintcomp
178 : monnier 16
179 :     end (* local *)
180 :     end (* structure FLINTComp *)
181 : monnier 95
182 :     (*
183 : monnier 118 * $Log$
184 : monnier 95 *)

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0