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 418 - (view) (download)
Original Path: sml/branches/SMLNJ/src/compiler/FLINT/cps/ppcps.sml

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 :     fun sayt(INTt) = say "[I]"
22 :     | sayt(INT32t) = say "[I32]"
23 :     | sayt(FLTt) = say "[R]"
24 :     | sayt(PTRt (RPT k)) = say ("[PR"^(Int.toString(k))^"]")
25 :     | sayt(PTRt (FPT k)) = say ("[PF"^(Int.toString(k))^"]")
26 :     | sayt(PTRt (VPT)) = say "[PV]"
27 :     | sayt(FUNt) = say "[F]"
28 :     | sayt(CNTt) = say "[C]"
29 :     | sayt(DSPt) = say "[D]"
30 :    
31 :     fun numkindName (P.INT bits) = "i" ^ Int.toString bits
32 :     | numkindName (P.UINT bits) = "u" ^ Int.toString bits
33 :     | numkindName (P.FLOAT bits) = "f" ^ Int.toString bits
34 :    
35 :     fun lookerName P.! = "!"
36 :     | lookerName P.gethdlr = "gethdlr"
37 :     | lookerName P.subscript = "subscript"
38 :     | lookerName (P.numsubscript{kind}) = ("numsubscript" ^ numkindName kind)
39 :     | lookerName P.getrunvec = "getrunvec"
40 :     | lookerName P.getvar = "getvar"
41 :     | lookerName P.deflvar = "deflvar"
42 :     | lookerName P.getspecial = "getspecial"
43 :     | lookerName P.getpseudo = "getpseudo"
44 :    
45 :     fun branchName P.boxed = "boxed"
46 :     | branchName P.unboxed = "unboxed"
47 :     | branchName (P.cmp{oper, kind}) =
48 :     (numkindName kind ^
49 :     (case oper
50 :     of P.> => ">"
51 :     | P.< => "<"
52 :     | P.>= => ">="
53 :     | P.<= => "<="
54 :     | P.eql => "="
55 :     | P.neq => "<>"
56 :     (*esac*)))
57 :     | branchName(P.fcmp{oper, size}) =
58 :     (numkindName (P.FLOAT size) ^
59 :     (case oper
60 :     of P.fEQ => "="
61 :     | P.fULG => "?<>"
62 :     | P.fGT => ">"
63 :     | P.fGE => ">="
64 :     | P.fLT => "<"
65 :     | P.fLE => "<="
66 :     | P.fLG => "<>"
67 :     | P.fLEG => "<=>"
68 :     | P.fUGT => "?>"
69 :     | P.fUGE => "?>="
70 :     | P.fULT => "?<"
71 :     | P.fULE => "?<="
72 :     | P.fUE => "?="
73 :     | P.fUN => "?"
74 :     (*esac*)))
75 :     | branchName P.pneq = "pneq"
76 :     | branchName P.peql = "peql"
77 :     | branchName P.streq = "streq"
78 :     | branchName P.strneq = "strneq"
79 :    
80 :     fun setterName P.unboxedupdate = "unboxedupdate"
81 :     | setterName P.boxedupdate = "boxedupdate"
82 :     | setterName P.update = "update"
83 :     | setterName (P.numupdate{kind}) = ("numupdate" ^ numkindName kind)
84 :     | setterName P.unboxedassign = "unboxedassign"
85 :     | setterName P.assign = "assign"
86 :     | setterName P.sethdlr = "sethdlr"
87 :     | setterName P.setvar = "setvar"
88 :     | setterName P.uselvar = "uselvar"
89 :     | setterName P.free = "free"
90 :     | setterName P.setspecial = "setspecial"
91 :     | setterName P.setpseudo = "setpseudo"
92 :     | setterName P.setmark = "setmark"
93 :     | setterName P.acclink = "acclink"
94 :    
95 :     fun cvtParams(from, to) = Int.toString from ^ "_" ^ Int.toString to
96 :    
97 :     fun arithName (P.arith{oper,kind}) =
98 :     ((case oper of P.+ => "+" | P.- => "-" | P.* => "*"
99 :     | P./ => "/" | P.~ => "~" | P.abs => "abs"
100 :     | P.rshift => "rshift" | P.rshiftl => "rshiftl"
101 :     | P.lshift => "lshift" | P.andb => "andb"
102 :     | P.orb => "orb" | P.xorb => "xorb" | P.notb => "notb")
103 :     ^ numkindName kind)
104 :     | arithName(P.test arg) = "test_" ^ cvtParams arg
105 :     | arithName(P.testu arg) = "testu_" ^ cvtParams arg
106 :     | arithName (P.round{floor=true,fromkind=P.FLOAT 64,tokind=P.INT 31}) =
107 :     "floor"
108 :     | arithName (P.round{floor=false,fromkind=P.FLOAT 64,tokind=P.INT 31}) =
109 :     "round"
110 :     | arithName (P.round{floor,fromkind,tokind}) =
111 :     ((if floor then "floor" else "round")
112 :     ^ numkindName fromkind ^ "_" ^ numkindName tokind)
113 :    
114 :     fun pureName P.length = "length"
115 :     | pureName (P.pure_arith x) = arithName(P.arith x)
116 :     | pureName P.objlength = "objlength"
117 :     | pureName P.makeref = "makeref"
118 :     | pureName (P.extend arg) = "extend_" ^ cvtParams arg
119 :     | pureName (P.copy arg) = "copy_" ^ cvtParams arg
120 :     | pureName (P.trunc arg) = "trunc_" ^ cvtParams arg
121 :     | 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 :    
144 :     fun show0 say =
145 :     let fun sayc (#"\n") = say "\\n"
146 :     | sayc c = say(String.str c)
147 :    
148 :     fun sayv(VAR v) = say(LV.lvarName v)
149 :     | sayv(LABEL v) = say("(L)" ^ LV.lvarName v)
150 :     | sayv(INT i) = say("(I)" ^ Int.toString i)
151 :     | sayv(INT32 i) = say("(I32)" ^ Word32.toString i)
152 :     | sayv(REAL r) = say r
153 :     | sayv(STRING s) = (say "\""; app sayc (explode s); say "\"")
154 :     | sayv(OBJECT _) = say("(object)")
155 :     | sayv(VOID) = say("(void)")
156 :    
157 :     fun sayvlist [v] = sayv v
158 :     | sayvlist nil = ()
159 :     | sayvlist (v::vl) = (sayv v; say ","; sayvlist vl)
160 :    
161 :    
162 :     fun rkstring rk = (case rk
163 :     of RK_VECTOR => "RK_VECTOR"
164 :     | RK_RECORD => "RK_RECORD"
165 :     | RK_SPILL => "RK_SPILL"
166 :     | RK_ESCAPE => "RK_ESCAPE"
167 :     | RK_EXN => "RK_EXN"
168 :     | RK_CONT => "RK_CONT"
169 :     | RK_FCONT => "RK_FCONT"
170 :     | RK_KNOWN => "RK_KNOWN"
171 :     | RK_BLOCK => "RK_BLOCK"
172 :     | RK_FBLOCK => "RK_FBLOCK"
173 :     | RK_I32BLOCK => "RK_I32BLOCK")
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 :     in f
248 :     end
249 :     in indent
250 :     end
251 :    
252 :     fun printcps((_,f,vl,cl,e),m)=
253 :     let fun ptv(v,t) = (say(LV.lvarName v); say " type ===>>>";
254 :     say(LtyExtern.lt_print t); say "\n")
255 :    
256 :     val _ = if (!Control.CG.debugRep)
257 :     then (say "************************************************\n";
258 :     Intmap.app ptv m;
259 :     say "************************************************\n")
260 :     else ()
261 :    
262 :     fun sayv(v) = say(LV.lvarName v)
263 :     fun sayparam ([v],[ct]) = (sayv v; sayt ct)
264 :     | sayparam (nil,nil) = ()
265 :     | sayparam (v::vl,ct::cl) = (sayv v; sayt ct; say ","; sayparam(vl,cl))
266 :     | sayparam _ = ErrorMsg.impossible "sayparam in ppcps.sml 3435"
267 :    
268 :     in
269 :     (say(LV.lvarName f); say "("; sayparam(vl,cl); say ") =\n";
270 :     show0 say 3 e)
271 :     end
272 :    
273 :     exception NULLTABLE
274 :     val nulltable : LtyDef.lty Intmap.intmap= Intmap.new(8,NULLTABLE)
275 :    
276 :     fun printcps0 f = printcps(f,nulltable)
277 :    
278 :     fun prcps(ce) = show0 (Control.Print.say) 1 ce
279 :    
280 :     end (* toplevel local *)
281 :     end (* structure PPCps *)
282 :    

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