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 158 - (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 :     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 : monnier 158 (* val lcontract = phase "Compiler 052 lcontract" LContract.lcontract *)
26 : monnier 122 val fcontract = phase "Compiler 052 fcontract" FContract.contract
27 : monnier 71 val specialize= phase "Compiler 053 specialize" Specialize.specialize
28 :     val wrapping = phase "Compiler 054 wrapping" Wrapping.wrapping
29 :     val reify = phase "Compiler 055 reify" Reify.reify
30 : monnier 122 val fixfix = phase "Compiler 056 fixfix" FixFix.fixfix
31 : monnier 16
32 : monnier 71 val convert = phase "Compiler 060 convert" Convert.convert
33 :     val cpstrans = phase "Compiler 065 cpstrans" CPStrans.cpstrans
34 : monnier 16 val cpsopt = phase "Compiler 070 cpsopt" CPSopt.reduce
35 : monnier 102 val litsplit = phase "Compiler 075 litsplit" Literals.litsplit
36 :     val lit2cps = phase "Compiler 076 lit2cps" Literals.lit2cps
37 :     val closure = phase "Compiler 080 closure" Closure.closeCPS
38 : monnier 16 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 : monnier 102 val closureD = phase "Compiler 081 closureD" Closure.closeCPS
46 :     val globalfixD= phase "Compiler 091 globalfixD" GlobalFix.globalfix
47 :     val spillD = if MachSpec.spillAreaSz < 500 * MachSpec.valueSize
48 :     then phase "Compiler 101 spillD" Spill.spill
49 :     else fn x => x
50 :     val limitD = phase "Compiler 110 limitD" Limit.nolimit
51 :     val codegenD = phase "Compiler 121 cpsgenD" Gen.codegen
52 : monnier 16
53 : monnier 71 (** pretty printing for the FLINT and CPS code *)
54 :     val (prF, prC) =
55 :     let fun prGen (flag,printE) s e =
56 : monnier 102 if !flag then (say ("\n[After " ^ s ^ " ...]\n\n"); printE e;
57 :     say "\n"; e)
58 : monnier 71 else e
59 : monnier 122 in (prGen (Control.FLINT.print, PPFlint.printProg),
60 :     prGen (Control.CG.printit, PPCps.printcps0))
61 : monnier 71 end
62 : monnier 16
63 : monnier 71 (** writing out a term into a error output file *)
64 :     fun dumpTerm (printE, s, le) =
65 :     let val outS = TextIO.openAppend s;
66 :     val saveOut = !Control.Print.out
67 :     fun done () =
68 :     (TextIO.closeOut outS; Control.Print.out := saveOut)
69 :     in Control.Print.out := {say = fn s => TextIO.output(outS,s),
70 :     flush = fn () => TextIO.flushOut outS};
71 :     printE le handle x => (done () handle _ => (); raise x);
72 :     done ()
73 :     end (* function dumpTerm *)
74 :    
75 : monnier 16 (** compiling FLINT code into the binary machine code *)
76 :     fun flintcomp(flint, compInfo as {error, sourceName=src, ...}: CB.compInfo) =
77 :     let fun err severity s =
78 :     error (0,0) severity (concat["Real constant out of range: ",s,"\n"])
79 :    
80 :     fun check (checkE,printE,chkId) (enableChk,lvl,logId) e =
81 :     (if !enableChk andalso checkE (e,lvl) then
82 : monnier 71 (dumpTerm (printE, src ^ "." ^ chkId ^ logId, e);
83 :     bug (chkId ^ " typing errors " ^ logId))
84 : monnier 16 else ();
85 :     e)
86 : monnier 71 fun chkF (b, s) =
87 :     check (ChkFlint.checkTop, PPFlint.printFundec,
88 : monnier 122 "FLINT") (Control.FLINT.check, b, s)
89 : monnier 16
90 : monnier 102 val _ = (chkF (false,"1") o prF "Translation/Normalization") flint
91 : monnier 122 val flint = (chkF (false,"2") o prF "Fcontract" o fcontract) flint
92 :    
93 : monnier 16 val flint =
94 : monnier 122 if !Control.FLINT.specialize then
95 : monnier 71 (chkF (false,"3") o prF "Specialization" o specialize) flint
96 : monnier 16 else flint
97 : monnier 158 val flint = (chkF (false,"2") o prF "Fcontract" o fcontract) flint
98 : monnier 16
99 : monnier 122 (* val flint = (chkF (false,"6") o prF "FixFix" o fixfix) flint *)
100 :     val flint = (chkF (false,"2") o prF "Fcontract" o fcontract) flint
101 :    
102 : monnier 71 val flint = (chkF (false, "4") o prF "Wrapping" o wrapping) flint
103 :     val flint = (chkF (true, "5") o prF "Reify" o reify) flint
104 : monnier 102
105 : monnier 122 val flint = (chkF (true,"2") o prF "Fcontract" o fcontract) flint
106 :    
107 : monnier 102 val (nc0, ncn, dseg) =
108 :     let val function = convert flint
109 :     val _ = prC "convert" function
110 : monnier 71 val function = (prC "cpstrans" o cpstrans) function
111 : monnier 102 val function =
112 : monnier 122 if !Control.CG.cpsopt then cpsopt (function,NONE,false)
113 : monnier 102 else function
114 : monnier 71 val _ = prC "cpsopt" function
115 : monnier 45
116 : monnier 102 val (function, dlit) = litsplit function
117 :     val data = lit2cps dlit
118 :     val _ = prC "cpsopt-code" function
119 :     val _ = prC "cpsopt-data" data
120 :    
121 : monnier 71 fun gen fx =
122 :     let val fx = (prC "closure" o closure) fx
123 :     val carg = globalfix fx
124 :     val carg = spill carg
125 :     val (carg, limit) = limit carg
126 :     in codegen (carg, limit, err);
127 :     collect ()
128 :     end
129 : monnier 102
130 :     fun gdata dd =
131 :     let val x = Control.CG.printit
132 :     val y = !x
133 :     val _ = (x := false)
134 :     val fx = (prC "closure" o closureD) dd
135 :     val carg = globalfixD fx
136 :     val carg = spillD carg
137 :     val (carg, limit) = limitD carg
138 :     in codegenD (carg, limit, err);
139 :     (collect ()) before (x := y)
140 :     end
141 : monnier 71 in case CpsSplit.cpsSplit function
142 : monnier 102 of (fun0 :: funn) => (gen fun0, map gen funn, gdata data)
143 : monnier 71 | [] => bug "unexpected case on gen in flintcomp"
144 :     end
145 : monnier 102 in {c0=nc0, cn=ncn, data=dseg, name=ref (SOME src)}
146 : monnier 16 end (* function flintcomp *)
147 :    
148 : monnier 71 val flintcomp = phase "Compiler 050 flintcomp" flintcomp
149 : monnier 16
150 :     end (* local *)
151 :     end (* structure FLINTComp *)
152 : monnier 95
153 :     (*
154 : monnier 118 * $Log$
155 : monnier 95 *)

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