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/compiler/CPS/cps/ppcps.sml
ViewVC logotype

Annotation of /sml/trunk/compiler/CPS/cps/ppcps.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1094 - (view) (download)
Original Path: sml/trunk/src/compiler/FLINT/cps/ppcps.sml

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

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