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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 184, Sun Nov 8 21:18:20 1998 UTC revision 220, Tue Mar 9 02:15:05 1999 UTC
# Line 14  Line 14 
14        structure Closure = Closure(MachSpec)        structure Closure = Closure(MachSpec)
15        structure Spill = Spill(MachSpec)        structure Spill = Spill(MachSpec)
16        structure CpsSplit = CpsSplitFun (MachSpec)        structure CpsSplit = CpsSplitFun (MachSpec)
17        structure CTRL = Control.FLINT        structure CTRL = FLINT_Control
18          structure PP = PPFlint
19          structure LT = LtyExtern
20          structure O  = Option
21          structure F  = FLINT
22  in  in
23    
24  val architecture = Gen.MachSpec.architecture  val architecture = Gen.MachSpec.architecture
25  fun bug s = ErrorMsg.impossible ("FLINTComp:" ^ s)  fun bug s = ErrorMsg.impossible ("FLINTComp:" ^ s)
26  val say = Control.Print.say  val say = Control_Print.say
27    
28    datatype flintkind = FK_WRAP | FK_REIFY | FK_DEBRUIJN | FK_NAMED | FK_CPS
29    
30  fun phase x = Stats.doPhase (Stats.makePhase x)  fun phase x = Stats.doPhase (Stats.makePhase x)
31    
32    val deb2names = phase "Compiler 056 deb2names" TvarCvt.debIndex2names
33    val names2deb = phase "Compiler 057 names2deb" TvarCvt.names2debIndex
34    
35  val lcontract = phase "Compiler 052 lcontract" LContract.lcontract  val lcontract = phase "Compiler 052 lcontract" LContract.lcontract
36    (*  val lcontract' = phase "Compiler 052 lcontract'" LContract.lcontract *)
37  val fcollect  = phase "Compiler 052a fcollect" Collect.collect  val fcollect  = phase "Compiler 052a fcollect" Collect.collect
38  val fcontract = phase "Compiler 052b fcontract" FContract.contract  val fcontract = phase "Compiler 052b fcontract" FContract.contract
39  val fcontract = fcontract o fcollect  val fcontract = fcontract o fcollect
40    val loopify   = phase "Compiler 057 loopify" Loopify.loopify
41    val fixfix    = phase "Compiler 056 fixfix" FixFix.fixfix
42    
43    val split     = phase "Compiler 058 split" FSplit.split
44    
45    val typelift  = phase "Compiler 0535 typelift" Lift.typeLift
46    val wformed   = phase "Compiler 0536 wformed" Lift.wellFormed
47    
48  val specialize= phase "Compiler 053 specialize" Specialize.specialize  val specialize= phase "Compiler 053 specialize" Specialize.specialize
49  val wrapping  = phase "Compiler 054 wrapping" Wrapping.wrapping  val wrapping  = phase "Compiler 054 wrapping" Wrapping.wrapping
50  val reify     = phase "Compiler 055 reify" Reify.reify  val reify     = phase "Compiler 055 reify" Reify.reify
51  val fixfix    = phase "Compiler 056 fixfix" FixFix.fixfix  val recover   = phase "Compiler 05a recover" Recover.recover
52    
53  val convert   = phase "Compiler 060 convert" Convert.convert  val convert   = phase "Compiler 060 convert" Convert.convert
54  val cpstrans  = phase "Compiler 065 cpstrans" CPStrans.cpstrans  val cpstrans  = phase "Compiler 065 cpstrans" CPStrans.cpstrans
# Line 76  Line 93 
93        done ()        done ()
94    end (* function dumpTerm *)    end (* function dumpTerm *)
95    
96    val fcs : (FLINT.prog -> FLINT.prog) list ref = ref []
97    
98  (** compiling FLINT code into the binary machine code *)  (** compiling FLINT code into the binary machine code *)
99  fun flintcomp(flint, compInfo as {error, sourceName=src, ...}: CB.compInfo) =  fun flintcomp(flint, compInfo as {error, sourceName=src, ...}: CB.compInfo) =
100    let fun err severity s =    let fun err severity s =
101          error (0,0) severity (concat["Real constant out of range: ",s,"\n"])          error (0,0) severity (concat["Real constant out of range: ",s,"\n"])
102    
103        fun check (checkE,printE,chkId) (enableChk,lvl,logId) e =        fun check (checkE,printE,chkId) (lvl,logId) e =
104          (if !enableChk andalso checkE (e,lvl) then            if checkE (e,lvl) then
105             (dumpTerm (printE, src ^ "." ^ chkId ^ logId, e);             (dumpTerm (printE, src ^ "." ^ chkId ^ logId, e);
106              bug (chkId ^ " typing errors " ^ logId))              bug (chkId ^ " typing errors " ^ logId))
107           else ();            else ()
108           e)        fun wff (f, s) = if wformed f then ()
109        fun chkF (b, s) =                         else print ("\nAfter " ^ s ^ " CODE NOT WELL FORMED\n")
110          check (ChkFlint.checkTop, PPFlint.printFundec,  
111                 "FLINT") (CTRL.check, b, s)        (* f:prog         flint code
112           * fi:prog opt    inlinable approximation of f
113        (* f:FLINT.prog   flint codee         * fk:flintkind   what kind of flint variant this is
        * r:boot         whether it has gone through reify yet  
114         * l:string       last phase through which it went *)         * l:string       last phase through which it went *)
115        fun runphase (p as "fcontract",(f,r,l)) = (fcontract f, r, p)        fun runphase (p,(f,fi,fk,l)) =
116          | runphase (p as "lcontract",(f,r,l)) = (lcontract f, r, p)            case (p,fk)
117          | runphase (p as "fixfix",(f,r,l)) = (fixfix f, r, p)             of (("fcontract" | "lcontract"), FK_DEBRUIJN) =>
118          | runphase (p as "wrap",(f,false,l)) = (wrapping f, false, p)                (say("\n!! "^p^" cannot be applied to the DeBruijn form !!\n");
119          | runphase (p as "specialize",(f,false,l)) = (specialize f, false, p)                 (f, fi, fk, l))
120          | runphase (p as "reify",(f,false,l)) = (reify f, true, p)  
121                | ("fcontract",_)           => (fcontract f,  fi, fk, p)
122                | ("lcontract",_)           => (lcontract f,  fi, fk, p)
123                | ("fixfix",   _)           => (fixfix f,     fi, fk, p)
124                | ("loopify",  _)           => (loopify f,    fi, fk, p)
125                | ("specialize",FK_NAMED)   => (specialize f, fi, fk, p)
126                | ("wrap",FK_NAMED)         => (wrapping f,   fi, FK_WRAP, p)
127                | ("reify",FK_WRAP)         => (reify f,      fi, FK_REIFY, p)
128                | ("deb2names",FK_DEBRUIJN) => (deb2names f,  fi, FK_NAMED, p)
129                | ("names2deb",FK_NAMED)    => (names2deb f,  fi, FK_DEBRUIJN, p)
130                | ("typelift", _)           =>
131                  let val f = typelift f
132                  in if !CTRL.check then wff(f, p) else (); (f, fi, fk, p) end
133                | ("split",    FK_NAMED)    =>
134                  let val (f,fi) = split f in (f, fi, fk, p) end
135    
136          (* pseudo FLINT phases *)          (* pseudo FLINT phases *)
137          | runphase ("id",(f,r,l)) = (f,r,l)              | ("pickle",   _)           =>
138          | runphase (p as "print",(f,r,l)) =                (valOf(UnpickMod.unpickleFLINT(PickMod.pickleFLINT(SOME f))),
139            (say("\n[ After "^l^"... ]\n\n");                 UnpickMod.unpickleFLINT(PickMod.pickleFLINT fi),
140             PPFlint.printFundec f; (f,r,l)                 fk, p)
141             before say "\n")              | ("collect",_) => (fcollect f, fi, fk, p)
142          | runphase ("check",(f,r,l)) =              | _ =>
143                  ((case (p,fk)
144                     of ("id",_) => ()
145                      | ("wellformed",_) => wff(f,l)
146                      | ("recover",_) =>
147                        let val {getLty,...} = recover(f, fk = FK_REIFY)
148                        in CTRL.recover := (say o LT.lt_print o getLty o F.VAR)
149                        end
150                      | ("print",_) =>
151                        (say("\n[After "^l^"...]\n\n"); PP.printFundec f; say "\n")
152                      | ("printsplit", _) =>
153                        (say "[ splitted ]\n\n"; O.map PP.printFundec fi; say "\n")
154                      | ("check",_) =>
155            (check (ChkFlint.checkTop, PPFlint.printFundec, "FLINT")            (check (ChkFlint.checkTop, PPFlint.printFundec, "FLINT")
156                   (ref true, r, l) f; (f,r,l))                             (fk = FK_REIFY, l) f)
157          | runphase (p as ("reify"|"specialize"|"wrap"),(f,true,l)) =                    | _ =>
158            (say("\n"^p^"cannot be used after reify!\n"); (f,true,l))                      say("\n!! Unknown or badly scheduled FLINT phase '"^p^"' !!\n"));
159          | runphase (p,(f,r,l)) =                      (f, fi, fk, l))
160            (say("\n!! Unknown FLINT phase '"^p^"' !!\n"); (f,r,l))  
161          fun print (f,fi,fk,l) = (prF l f; (f, fi, fk, l))
162        fun print (f,r,l) = (prF l f; (f, r, l))        fun check' (f,fi,fk,l) =
163        fun check (f,r,l) = (chkF (r, l) f; (f, r, l))            let fun c n reified f =
164                      check (ChkFlint.checkTop, PPFlint.printFundec, n)
165                            (reified, l) (names2deb f)
166              in if !CTRL.check then
167                  (c "FLINT" (fk = FK_REIFY) f; O.map (c "iFLINT" false) fi; ())
168                 else ();
169                     (f, fi, fk, l)
170              end
171    
172        fun runphase' (arg as (p,{1=f,...})) =        fun runphase' (arg as (p,{1=f,...})) =
173            ((*  say("Phase "^p^"..."); *)            (if !CTRL.printPhases then say("Phase "^p^"...") else ();
174             (runphase arg) (*  before *)             ((check' o print o runphase) arg) before
175  (*         say("..."^p^" Done.\n") *))             (if !CTRL.printPhases then say("..."^p^" Done.\n") else ()))
176                handle x => (dumpTerm(PPFlint.printFundec,"FLINT.bug", f); raise x)                handle x => (say ("\nwhile in "^p^" phase\n");
177                               dumpTerm(PPFlint.printFundec,"FLINT.core", f);
178        (* the "id" phases is just added to do the print/check at the entrance *)                             raise x)
179        val (flint,r,_) = foldl (check o print o runphase')  
180                                (flint,false,"flintnm")        val (flint,fi,fk,_) = foldl runphase'
181                                ((*  "id" :: *) !CTRL.phases)                                    (flint, NONE, FK_DEBRUIJN, "flintnm")
182        val flint = if r then flint else (say "\n!!Forgot reify!!\n"; reify flint)                                    ((* "id" :: *) "deb2names" :: !CTRL.phases)
183    
184  (*        val _ = (chkF (false,"1") o prF "Translation/Normalization") flint *)        (* run any missing phases *)
185  (*        val flint = (chkF (false,"2") o prF "Fcontract" o fcontract) flint *)        val (flint,fk) =
186              if fk = FK_DEBRUIJN
187  (*        val flint = *)            then (say "\n!!Forgot deb2names!!\n"; (deb2names flint, FK_NAMED))
188  (*          if !Control.FLINT.specialize then *)            else (flint,fk)
189  (*             (chkF (false,"3") o prF "Specialization" o specialize) flint *)        val (flint,fk) =
190  (*          else flint *)            if fk = FK_NAMED
191  (*        val flint = (chkF (false,"2") o prF "Fcontract" o fcontract) flint *)            then (say "\n!!Forgot wrap!!\n"; (wrapping flint, FK_WRAP))
192              else (flint,fk)
193  (*        val flint = (chkF (false,"6") o prF "FixFix" o fixfix) flint *)        val (flint,fk) =
194  (*        val flint = (chkF (false,"2") o prF "Fcontract" o fcontract) flint *)            if fk = FK_WRAP
195              then (say "\n!!Forgot reify!!\n"; (reify flint, FK_REIFY))
196  (*        val flint = (chkF (false, "4") o prF "Wrapping" o wrapping) flint *)            else (flint,fk)
 (*        val flint = (chkF (true, "5") o prF "Reify" o reify) flint *)  
   
 (*        val flint = (chkF (true,"2") o prF "Fcontract" o fcontract) flint *)  
197    
198          (* finish up with CPS *)
199        val (nc0, ncn, dseg) =        val (nc0, ncn, dseg) =
200          let val function = convert flint          let val function = convert flint
201              val _ = prC "convert" function              val _ = prC "convert" function
# Line 183  Line 232 
232               of (fun0 :: funn) => (gen fun0, map gen funn, gdata data)               of (fun0 :: funn) => (gen fun0, map gen funn, gdata data)
233                | [] => bug "unexpected case on gen in flintcomp"                | [] => bug "unexpected case on gen in flintcomp"
234          end          end
235     in {c0=nc0, cn=ncn, data=dseg, name=ref (SOME src)}     in ({c0=nc0, cn=ncn, data=dseg, name=ref (SOME src)}, fi)
236    end (* function flintcomp *)    end (* function flintcomp *)
237    
238  val flintcomp = phase "Compiler 050 flintcomp" flintcomp  val flintcomp = phase "Compiler 050 flintcomp" flintcomp

Legend:
Removed from v.184  
changed lines
  Added in v.220

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