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/branches/SMLNJ/src/compiler/FLINT/cps/ppcps.sml
ViewVC logotype

Annotation of /sml/branches/SMLNJ/src/compiler/FLINT/cps/ppcps.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 475 - (view) (download)

1 : monnier 245 (* Copyright 1996 by Bell Laboratories *)
2 :     (* ppcps.sml *)
3 :    
4 :     signature PPCPS =
5 :     sig
6 :     val printcps : (CPS.function * LtyDef.lty Intmap.intmap) -> unit
7 :     val printcps0: CPS.function -> unit
8 :     val prcps : CPS.cexp -> unit
9 :    
10 :     end (* signature PPCPS *)
11 :    
12 :     structure PPCps : PPCPS =
13 :     struct
14 :    
15 :     local open CPS
16 :     structure LV = LambdaVar
17 :     in
18 :    
19 :     val say = Control.Print.say
20 :    
21 : monnier 475 val sayt = say o CPS.ctyToString
22 : monnier 245
23 :     fun numkindName (P.INT bits) = "i" ^ Int.toString bits
24 :     | numkindName (P.UINT bits) = "u" ^ Int.toString bits
25 :     | numkindName (P.FLOAT bits) = "f" ^ Int.toString bits
26 :    
27 :     fun lookerName P.! = "!"
28 :     | lookerName P.gethdlr = "gethdlr"
29 :     | lookerName P.subscript = "subscript"
30 :     | lookerName (P.numsubscript{kind}) = ("numsubscript" ^ numkindName kind)
31 :     | lookerName P.getrunvec = "getrunvec"
32 :     | lookerName P.getvar = "getvar"
33 :     | lookerName P.deflvar = "deflvar"
34 :     | lookerName P.getspecial = "getspecial"
35 :     | lookerName P.getpseudo = "getpseudo"
36 :    
37 :     fun branchName P.boxed = "boxed"
38 :     | branchName P.unboxed = "unboxed"
39 :     | branchName (P.cmp{oper, kind}) =
40 :     (numkindName kind ^
41 :     (case oper
42 :     of P.> => ">"
43 :     | P.< => "<"
44 :     | P.>= => ">="
45 :     | P.<= => "<="
46 :     | P.eql => "="
47 :     | P.neq => "<>"
48 :     (*esac*)))
49 :     | branchName(P.fcmp{oper, size}) =
50 :     (numkindName (P.FLOAT size) ^
51 :     (case oper
52 :     of P.fEQ => "="
53 :     | P.fULG => "?<>"
54 :     | P.fGT => ">"
55 :     | P.fGE => ">="
56 :     | P.fLT => "<"
57 :     | P.fLE => "<="
58 :     | P.fLG => "<>"
59 :     | P.fLEG => "<=>"
60 :     | P.fUGT => "?>"
61 :     | P.fUGE => "?>="
62 :     | P.fULT => "?<"
63 :     | P.fULE => "?<="
64 :     | P.fUE => "?="
65 :     | P.fUN => "?"
66 :     (*esac*)))
67 :     | branchName P.pneq = "pneq"
68 :     | branchName P.peql = "peql"
69 :     | branchName P.streq = "streq"
70 :     | branchName P.strneq = "strneq"
71 :    
72 :     fun setterName P.unboxedupdate = "unboxedupdate"
73 :     | setterName P.boxedupdate = "boxedupdate"
74 :     | setterName P.update = "update"
75 :     | setterName (P.numupdate{kind}) = ("numupdate" ^ numkindName kind)
76 :     | setterName P.unboxedassign = "unboxedassign"
77 :     | setterName P.assign = "assign"
78 :     | setterName P.sethdlr = "sethdlr"
79 :     | setterName P.setvar = "setvar"
80 :     | setterName P.uselvar = "uselvar"
81 :     | setterName P.free = "free"
82 :     | setterName P.setspecial = "setspecial"
83 :     | setterName P.setpseudo = "setpseudo"
84 :     | setterName P.setmark = "setmark"
85 :     | setterName P.acclink = "acclink"
86 :    
87 :     fun cvtParams(from, to) = Int.toString from ^ "_" ^ Int.toString to
88 :    
89 :     fun arithName (P.arith{oper,kind}) =
90 :     ((case oper of P.+ => "+" | P.- => "-" | P.* => "*"
91 :     | P./ => "/" | P.~ => "~" | P.abs => "abs"
92 :     | P.rshift => "rshift" | P.rshiftl => "rshiftl"
93 :     | P.lshift => "lshift" | P.andb => "andb"
94 :     | P.orb => "orb" | P.xorb => "xorb" | P.notb => "notb")
95 :     ^ numkindName kind)
96 :     | arithName(P.test arg) = "test_" ^ cvtParams arg
97 :     | arithName(P.testu arg) = "testu_" ^ cvtParams arg
98 :     | arithName (P.round{floor=true,fromkind=P.FLOAT 64,tokind=P.INT 31}) =
99 :     "floor"
100 :     | arithName (P.round{floor=false,fromkind=P.FLOAT 64,tokind=P.INT 31}) =
101 :     "round"
102 :     | arithName (P.round{floor,fromkind,tokind}) =
103 :     ((if floor then "floor" else "round")
104 :     ^ numkindName fromkind ^ "_" ^ numkindName tokind)
105 :    
106 :     fun pureName P.length = "length"
107 :     | pureName (P.pure_arith x) = arithName(P.arith x)
108 :     | pureName P.objlength = "objlength"
109 :     | pureName P.makeref = "makeref"
110 :     | pureName (P.extend arg) = "extend_" ^ cvtParams arg
111 :     | pureName (P.copy arg) = "copy_" ^ cvtParams arg
112 :     | pureName (P.trunc arg) = "trunc_" ^ cvtParams arg
113 :     | pureName (P.real{fromkind=P.FLOAT 64,tokind=P.INT 31}) = "real"
114 :     | pureName (P.real{fromkind,tokind}) =
115 :     ("real" ^ numkindName fromkind ^ "_" ^ numkindName tokind)
116 :     | pureName P.subscriptv = "subscriptv"
117 :     | pureName (P.pure_numsubscript{kind}) = ("numsubscriptv" ^ numkindName kind)
118 :     | pureName P.gettag = "gettag"
119 :     | pureName P.mkspecial = "mkspecial"
120 :     | pureName P.wrap = "wrap"
121 :     | pureName P.unwrap = "unwrap"
122 :     | pureName P.cast = "cast"
123 :     | pureName P.getcon = "getcon"
124 :     | pureName P.getexn = "getexn"
125 :     | pureName P.fwrap = "fwrap"
126 :     | pureName P.funwrap = "funwrap"
127 :     | pureName P.iwrap = "iwrap"
128 :     | pureName P.iunwrap = "iunwrap"
129 :     | pureName P.i32wrap = "i32wrap"
130 :     | pureName P.i32unwrap = "i32unwrap"
131 :     | pureName P.getseqdata = "getseqdata"
132 :     | pureName P.recsubscript = "recsubscript"
133 :     | pureName P.raw64subscript = "raw64subscript"
134 :     | pureName P.newarray0 = "newarray0"
135 :    
136 :     fun show0 say =
137 :     let fun sayc (#"\n") = say "\\n"
138 :     | sayc c = say(String.str c)
139 :    
140 :     fun sayv(VAR v) = say(LV.lvarName v)
141 :     | sayv(LABEL v) = say("(L)" ^ LV.lvarName v)
142 :     | sayv(INT i) = say("(I)" ^ Int.toString i)
143 :     | sayv(INT32 i) = say("(I32)" ^ Word32.toString i)
144 :     | sayv(REAL r) = say r
145 :     | sayv(STRING s) = (say "\""; app sayc (explode s); say "\"")
146 :     | sayv(OBJECT _) = say("(object)")
147 :     | sayv(VOID) = say("(void)")
148 :    
149 :     fun sayvlist [v] = sayv v
150 :     | sayvlist nil = ()
151 :     | sayvlist (v::vl) = (sayv v; say ","; sayvlist vl)
152 :    
153 :    
154 :     fun rkstring rk = (case rk
155 :     of RK_VECTOR => "RK_VECTOR"
156 :     | RK_RECORD => "RK_RECORD"
157 :     | RK_SPILL => "RK_SPILL"
158 :     | RK_ESCAPE => "RK_ESCAPE"
159 :     | RK_EXN => "RK_EXN"
160 :     | RK_CONT => "RK_CONT"
161 :     | RK_FCONT => "RK_FCONT"
162 :     | RK_KNOWN => "RK_KNOWN"
163 :     | RK_BLOCK => "RK_BLOCK"
164 :     | RK_FBLOCK => "RK_FBLOCK"
165 :     | RK_I32BLOCK => "RK_I32BLOCK")
166 :    
167 :     fun sayrk(RK_RECORD,n) = ()
168 :     | sayrk(RK_VECTOR,n) = ()
169 :     | sayrk(k,n : int) = (say (rkstring k); say " ";
170 :     say (Int.toString n); say ",")
171 :    
172 :     fun sayparam ([v],[ct]) = (sayv v; sayt ct)
173 :     | sayparam (nil,nil) = ()
174 :     | sayparam (v::vl,ct::cl) = (sayv v; sayt ct; say ","; sayparam(vl,cl))
175 :     | sayparam _ = ErrorMsg.impossible "sayparam in ppcps.sml"
176 :    
177 :     fun saypath(OFFp 0) = ()
178 :     | saypath(OFFp i) = (say "+"; say(Int.toString i))
179 :     | saypath(SELp(j,p)) = (say "."; say(Int.toString j); saypath p)
180 :     fun sayvp (v,path) = (sayv v; saypath path)
181 :     fun saylist f [x] = f x | saylist f nil = ()
182 :     | saylist f (x::r) = (f x; say ","; saylist f r)
183 :     fun indent n =
184 :     let fun space 0 = () | space k = (say " "; space(k-1))
185 :     fun nl() = say "\n"
186 :     val rec f =
187 :     fn RECORD(k,vl,v,c) => (
188 :     space n;
189 :     case k of RK_VECTOR => say "#{" | _ => say "{";
190 :     sayrk(k,length vl);
191 :     saylist sayvp vl; say "} -> ";
192 :     sayv(VAR v);
193 :     nl(); f c)
194 :     | SELECT(i,v,w,t,c) =>
195 :     (space n; sayv v; say "."; say(Int.toString i); say " -> ";
196 :     sayv(VAR w); sayt(t); nl(); f c)
197 :     | OFFSET(i,v,w,c) =>
198 :     (space n; sayv v; say "+"; say(Int.toString i); say " -> ";
199 :     sayv(VAR w); nl(); f c)
200 :     | APP(w,vl) =>
201 :     (space n; sayv w; say "("; sayvlist vl; say ")\n")
202 :     | FIX(bl,c) =>
203 :     let fun g(_,v,wl,cl,d) =
204 :     (space n; sayv(VAR v); say "(";
205 :     sayparam (map VAR wl,cl);
206 :     say ") =\n";
207 :     indent (n+3) d)
208 :     in app g bl; f c
209 :     end
210 :     | SWITCH(v,c,cl) =>
211 :     let fun g(i,c::cl) =
212 :     (space(n+1); say(Int.toString(i:int));
213 :     say " =>\n"; indent (n+3) c; g(i+1,cl))
214 :     | g(_,nil) = ()
215 :     in space n; say "case "; sayv v; say " [";
216 :     say(Int.toString(c));
217 :     say "] of\n";
218 :     g(0,cl)
219 :     end
220 :     | LOOKER(i,vl,w,t,e) =>
221 :     (space n; say(lookerName i); say "("; sayvlist vl;
222 :     say ") -> "; sayv(VAR w); sayt(t); nl(); f e)
223 :     | ARITH(i,vl,w,t,e) =>
224 :     (space n; say(arithName i); say "("; sayvlist vl;
225 :     say ") -> "; sayv(VAR w); sayt(t); nl(); f e)
226 :     | PURE(i,vl,w,t,e) =>
227 :     (space n; say(pureName i); say "("; sayvlist vl;
228 :     say ") -> "; sayv(VAR w); sayt(t); nl(); f e)
229 :     | SETTER(i,vl,e) =>
230 :     (space n; say(setterName i); say "("; sayvlist vl;
231 :     say ")"; nl(); f e)
232 :     | BRANCH(i,vl,c,e1,e2) =>
233 :     (space n; say "if "; say(branchName i);
234 :     say "("; sayvlist vl; say ") [";
235 :     sayv(VAR c); say "] then\n";
236 :     indent (n+3) e1;
237 :     space n; say "else\n";
238 :     indent (n+3) e2)
239 :     in f
240 :     end
241 :     in indent
242 :     end
243 :    
244 :     fun printcps((_,f,vl,cl,e),m)=
245 :     let fun ptv(v,t) = (say(LV.lvarName v); say " type ===>>>";
246 :     say(LtyExtern.lt_print t); say "\n")
247 :    
248 :     val _ = if (!Control.CG.debugRep)
249 :     then (say "************************************************\n";
250 :     Intmap.app ptv m;
251 :     say "************************************************\n")
252 :     else ()
253 :    
254 :     fun sayv(v) = say(LV.lvarName v)
255 :     fun sayparam ([v],[ct]) = (sayv v; sayt ct)
256 :     | sayparam (nil,nil) = ()
257 :     | sayparam (v::vl,ct::cl) = (sayv v; sayt ct; say ","; sayparam(vl,cl))
258 :     | sayparam _ = ErrorMsg.impossible "sayparam in ppcps.sml 3435"
259 :    
260 :     in
261 :     (say(LV.lvarName f); say "("; sayparam(vl,cl); say ") =\n";
262 :     show0 say 3 e)
263 :     end
264 :    
265 :     exception NULLTABLE
266 :     val nulltable : LtyDef.lty Intmap.intmap= Intmap.new(8,NULLTABLE)
267 :    
268 :     fun printcps0 f = printcps(f,nulltable)
269 :    
270 :     fun prcps(ce) = show0 (Control.Print.say) 1 ce
271 :    
272 :     end (* toplevel local *)
273 :     end (* structure PPCps *)
274 :    

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