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

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