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

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