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 158, Mon Oct 12 02:41:33 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 = 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 lcontract = phase "Compiler 052 lcontract" LContract.lcontract  *)  val deb2names = phase "Compiler 056 deb2names" TvarCvt.debIndex2names
33  val fcontract = phase "Compiler 052 fcontract" FContract.contract  val names2deb = phase "Compiler 057 names2deb" TvarCvt.names2debIndex
34    
35    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
38    val fcontract = phase "Compiler 052b fcontract" FContract.contract
39    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 56  Line 77 
77          if !flag then (say ("\n[After " ^ s ^ " ...]\n\n"); printE e;          if !flag then (say ("\n[After " ^ s ^ " ...]\n\n"); printE e;
78                         say "\n"; e)                         say "\n"; e)
79          else e          else e
80     in (prGen (Control.FLINT.print, PPFlint.printProg),     in (prGen (CTRL.print, PPFlint.printProg),
81         prGen (Control.CG.printit, PPCps.printcps0))         prGen (Control.CG.printit, PPCps.printcps0))
82    end    end
83    
# Line 72  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 ()
108          fun wff (f, s) = if wformed f then ()
109                           else print ("\nAfter " ^ s ^ " CODE NOT WELL FORMED\n")
110    
111          (* f:prog         flint code
112           * fi:prog opt    inlinable approximation of f
113           * fk:flintkind   what kind of flint variant this is
114           * l:string       last phase through which it went *)
115          fun runphase (p,(f,fi,fk,l)) =
116              case (p,fk)
117               of (("fcontract" | "lcontract"), FK_DEBRUIJN) =>
118                  (say("\n!! "^p^" cannot be applied to the DeBruijn form !!\n");
119                   (f, fi, fk, l))
120    
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 *)
137                | ("pickle",   _)           =>
138                  (valOf(UnpickMod.unpickleFLINT(PickMod.pickleFLINT(SOME f))),
139                   UnpickMod.unpickleFLINT(PickMod.pickleFLINT fi),
140                   fk, p)
141                | ("collect",_) => (fcollect f, fi, fk, p)
142                | _ =>
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")
156                               (fk = FK_REIFY, l) f)
157                      | _ =>
158                        say("\n!! Unknown or badly scheduled FLINT phase '"^p^"' !!\n"));
159                        (f, fi, fk, l))
160    
161          fun print (f,fi,fk,l) = (prF l f; (f, fi, fk, l))
162          fun check' (f,fi,fk,l) =
163              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 ();           else ();
169           e)                   (f, fi, fk, l)
170        fun chkF (b, s) =            end
         check (ChkFlint.checkTop, PPFlint.printFundec,  
                "FLINT") (Control.FLINT.check, b, s)  
   
       val _ = (chkF (false,"1") o prF "Translation/Normalization") flint  
       val flint = (chkF (false,"2") o prF "Fcontract" o fcontract) flint  
   
       val flint =  
         if !Control.FLINT.specialize then  
            (chkF (false,"3") o prF "Specialization" o specialize) flint  
         else flint  
       val flint = (chkF (false,"2") o prF "Fcontract" o fcontract) flint  
   
 (*        val flint = (chkF (false,"6") o prF "FixFix" o fixfix) flint *)  
       val flint = (chkF (false,"2") o prF "Fcontract" o fcontract) flint  
   
       val flint = (chkF (false, "4") o prF "Wrapping" o wrapping) flint  
       val flint = (chkF (true, "5") o prF "Reify" o reify) flint  
171    
172        val flint = (chkF (true,"2") o prF "Fcontract" o fcontract) flint        fun runphase' (arg as (p,{1=f,...})) =
173              (if !CTRL.printPhases then say("Phase "^p^"...") else ();
174               ((check' o print o runphase) arg) before
175               (if !CTRL.printPhases then say("..."^p^" Done.\n") else ()))
176                  handle x => (say ("\nwhile in "^p^" phase\n");
177                               dumpTerm(PPFlint.printFundec,"FLINT.core", f);
178                               raise x)
179    
180          val (flint,fi,fk,_) = foldl runphase'
181                                      (flint, NONE, FK_DEBRUIJN, "flintnm")
182                                      ((* "id" :: *) "deb2names" :: !CTRL.phases)
183    
184          (* run any missing phases *)
185          val (flint,fk) =
186              if fk = FK_DEBRUIJN
187              then (say "\n!!Forgot deb2names!!\n"; (deb2names flint, FK_NAMED))
188              else (flint,fk)
189          val (flint,fk) =
190              if fk = FK_NAMED
191              then (say "\n!!Forgot wrap!!\n"; (wrapping flint, FK_WRAP))
192              else (flint,fk)
193          val (flint,fk) =
194              if fk = FK_WRAP
195              then (say "\n!!Forgot reify!!\n"; (reify flint, FK_REIFY))
196              else (flint,fk)
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
202              val function = (prC "cpstrans" o cpstrans) function              val function = (prC "cpstrans" o cpstrans) function
203              val function =              val function = cpsopt (function,NONE,false)
               if !Control.CG.cpsopt then cpsopt (function,NONE,false)  
               else function  
204              val _ = prC "cpsopt" function              val _ = prC "cpsopt" function
205    
206              val (function, dlit) = litsplit function              val (function, dlit) = litsplit function
# Line 142  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.158  
changed lines
  Added in v.220

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