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 17 - (view) (download)
Original Path: sml/branches/SMLNJ/src/compiler/FLINT/main/flintcomp.sml

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 :     structure CGC = Control.CG
10 :     structure MachSpec = Gen.MachSpec
11 :     structure Convert = Convert(MachSpec)
12 :     structure CPStrans = CPStrans(MachSpec)
13 :     structure CPSopt = CPSopt(MachSpec)
14 :     structure NewClosure = NClosure(MachSpec)
15 :     structure Spill = Spill(MachSpec)
16 :     structure CpsSplit = CpsSplitFun (MachSpec)
17 :     in
18 :    
19 :     val architecture = Gen.MachSpec.architecture
20 :     fun bug s = ErrorMsg.impossible ("FLINTComp:" ^ s)
21 :     val say = Control.Print.say
22 :    
23 :     fun phase x = Stats.doPhase (Stats.makePhase x)
24 :    
25 :     val lconLexp = phase "Compiler 052 lcontract" LContract.lcontract
26 :     val specLexp = phase "Compiler 053 specLexp" Specialize.specialize
27 :     val wrapLexp = phase "Compiler 054 wrapLexp" Wrapping.wrapLexp
28 :     val ltyComp = phase "Compiler 055 ltyComp" Reify.ltyComp
29 :     val narrow = phase "Compiler 056 ltNarrow" LtNarrow.narrow
30 :     (* val lambdaopt = phase "Compiler 057 lambdaopt" LContract.lcontract *)
31 :    
32 :     val convert = phase "Compiler 060 Convert" Convert.convert
33 :     val cpstrans = phase "Compiler 065 CPStrans" CPStrans.cpstrans
34 :     val cpsopt = phase "Compiler 070 cpsopt" CPSopt.reduce
35 :     val closure = phase "Compiler 080 closure" NewClosure.closeCPS
36 :     val globalfix = phase "Compiler 090 globalfix" GlobalFix.globalfix
37 :     val spill = if MachSpec.spillAreaSz < 500 * MachSpec.valueSize
38 :     then phase "Compiler 100 spill" Spill.spill
39 :     else fn x => x
40 :     val limit = phase "Compiler 110 limit" Limit.nolimit
41 :     val codegen = phase "Compiler 120 cpsgen" Gen.codegen
42 :    
43 :     fun prGen (flag,printE) s e =
44 :     (if !flag then (say ("\n\n[After " ^ s ^ " ...]\n\n"); printE e) else ();
45 :     e)
46 :    
47 :     val prLexp = prGen (CGC.printLambda, MCprint.printLexp)
48 :     val prFlint = prGen (CGC.printLambda, PPFlint.printProg)
49 :     val prCps = prGen (CGC.printit, PPCps.printcps0)
50 :    
51 :     (** compiling FLINT code into the binary machine code *)
52 :     fun flintcomp(flint, compInfo as {error, sourceName=src, ...}: CB.compInfo) =
53 :     let fun err severity s =
54 :     error (0,0) severity (concat["Real constant out of range: ",s,"\n"])
55 :    
56 :     fun dumpTerm (printE, s, le) =
57 :     let val outS = TextIO.openAppend (src ^ s);
58 :     val saveOut = !Control.Print.out
59 :     fun done () =
60 :     (TextIO.closeOut outS; Control.Print.out := saveOut)
61 :     in Control.Print.out := {say = fn s => TextIO.output(outS,s),
62 :     flush = fn () => TextIO.flushOut outS};
63 :     printE le handle x => (done () handle _ => (); raise x);
64 :     done ()
65 :     end
66 :     fun check (checkE,printE,chkId) (enableChk,lvl,logId) e =
67 :     (if !enableChk andalso checkE (e,lvl) then
68 :     (dumpTerm (printE, "." ^ chkId ^ logId, e);
69 :     bug (chkId ^ " typing errors " ^ logId))
70 :     else ();
71 :     e)
72 :     val chkLexp = check (CheckLty.checkLty, MCprint.printLexp, "lambda")
73 :     val chkFlint = check (ChkFlint.checkTop, PPFlint.printFundec, "FLINT")
74 :    
75 :     val _ = (chkFlint (CGC.checkflint1,1,"1") o prFlint "Translation") flint
76 :    
77 :     val flint =
78 :     (chkFlint (CGC.checkflint1,1,"2") o prFlint "Lcontract" o lconLexp)
79 :     flint
80 :    
81 :     val flint =
82 :     if !CGC.specialize then
83 :     (chkFlint (CGC.checkflint1,1,"3")
84 :     o prFlint "Specialization" o specLexp) flint
85 :     else flint
86 :    
87 :     val lambda =
88 :     (chkLexp (CGC.checklty1,1,"1")
89 :     o prLexp "Translation-To-Lambda"
90 :     o Flint2Lambda.transFundec)
91 :     flint
92 :    
93 :     val lambda =
94 :     (chkLexp (CGC.checklty1,11,"2") o prLexp "Wrapping" o wrapLexp)
95 :     lambda
96 :    
97 :     val lambda = (chkLexp (CGC.checklty1,21,"3") o ltyComp) lambda
98 :    
99 :     val lambda =
100 :     (chkLexp (CGC.checklty1,21,"4") o prLexp "Narrowing" o narrow) lambda
101 :    
102 :     (*
103 :     val lambda = (chkLexp (CGC.checklty2,21,"5") o lambdaopt) lambda
104 :     *)
105 :    
106 :     val (function,table) = convert lambda
107 :     val _ = prCps "convert" function
108 :    
109 :     val function = (prCps "cpstrans" o cpstrans) function
110 :    
111 :     val (function,table) =
112 :     if !CGC.cpsopt then cpsopt (function,table,NONE,false)
113 :     else (function,table)
114 :     val _ = prCps "cpsopt" function
115 :    
116 :     fun gen function = let
117 :     val function = (prCps "closure" o closure) function
118 :     val carg = globalfix function
119 :     val carg = spill carg
120 :     val (carg, limit) = limit carg
121 :     in
122 :     codegen (carg, limit, err);
123 :     collect ()
124 :     end
125 :    
126 :     val fun0 :: funn = CpsSplit.cpsSplit function
127 :     val c0 = gen fun0
128 :     val cn = map gen funn
129 :    
130 :     in {c0=c0, cn=cn , name=ref (SOME src)}
131 :     end (* function flintcomp *)
132 :    
133 :     val flintcomp = phase "Compiler 050 FLINTComp" flintcomp
134 :    
135 :     end (* local *)
136 :     end (* structure FLINTComp *)

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