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

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