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/src/MLRISC/mltree/mltree-utils.sml
ViewVC logotype

Annotation of /sml/trunk/src/MLRISC/mltree/mltree-utils.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 624 - (view) (download)

1 : monnier 473 (*
2 :     * Common operations on MLTREE
3 :     *
4 :     * -- Allen
5 :     *)
6 : george 555 functor MLTreeUtils
7 :     (structure T : MLTREE
8 :     (* Hashing extensions *)
9 :     val hashSext : T.hasher -> T.sext -> word
10 :     val hashRext : T.hasher -> T.rext -> word
11 :     val hashFext : T.hasher -> T.fext -> word
12 :     val hashCCext : T.hasher -> T.ccext -> word
13 :    
14 :     (* Equality extensions *)
15 :     val eqSext : T.equality -> T.sext * T.sext -> bool
16 :     val eqRext : T.equality -> T.rext * T.rext -> bool
17 :     val eqFext : T.equality -> T.fext * T.fext -> bool
18 :     val eqCCext : T.equality -> T.ccext * T.ccext -> bool
19 :    
20 :     (* Pretty printing extensions *)
21 :     val showSext : T.printer -> T.sext -> string
22 :     val showRext : T.printer -> T.ty * T.rext -> string
23 :     val showFext : T.printer -> T.fty * T.fext -> string
24 :     val showCCext : T.printer -> T.ty * T.ccext -> string
25 :     ) : MLTREE_UTILS =
26 : monnier 473 struct
27 :    
28 :     structure T = T
29 :     structure Constant = T.Constant
30 : george 545 structure LabelExp = T.LabelExp
31 : monnier 473 structure Region = T.Region
32 : george 545 structure B = T.Basis
33 : monnier 473 structure W = Word
34 :    
35 :     val w = W.fromInt
36 :    
37 :     fun error msg = MLRiscErrorMsg.error("MLTreeUtils",msg)
38 :     fun ws is =
39 :     let fun f([],h) = h
40 :     | f(i::is,h) = f(is,w i+h)
41 :     in f(is,0w0) end
42 :    
43 :     (*
44 :     * Hashing
45 :     *)
46 : george 545 fun hashLabel(Label.Label{id,...}) = w id
47 : george 555 and hashCtrls ctrl = ws ctrl
48 :     and hashCtrl ctrl = w ctrl
49 :     and hasher() = {stm=hashStm, rexp=hashRexp, fexp=hashFexp, ccexp=hashCCexp}
50 : george 545 and hashStm stm =
51 : monnier 473 case stm of
52 :     T.MV(t,dst,rexp) => 0w123 + w t + w dst + hashRexp rexp
53 :     | T.CCMV(dst,ccexp) => 0w1234 + w dst + hashCCexp ccexp
54 :     | T.FMV(fty,dst,fexp) => 0w12345 + w fty + w dst + hashFexp fexp
55 :     | T.COPY(ty,dst,src) => 0w234 + w ty + ws dst + ws src
56 :     | T.FCOPY(fty,dst,src) => 0w456 + w fty + ws dst + ws src
57 : george 545 | T.JMP(ctrl,ea,labels) => 0w45 + hashRexp ea
58 : leunga 591 | T.CALL{funct,targets,defs,uses,cdefs,cuses,region} =>
59 :     hashRexp funct + hashMlriscs defs + hashMlriscs uses +
60 : george 545 hashCtrls cdefs + hashCtrls cuses
61 :     | T.RET _ => 0w567
62 :     | T.STORE(ty,ea,data,mem) => 0w888 + w ty + hashRexp ea + hashRexp data
63 :     | T.FSTORE(fty,ea,data,mem) => 0w7890 + w fty + hashRexp ea + hashFexp data
64 :     | T.BCC(ctrl,a,lab) => 0w233 + hashCtrls ctrl + hashCCexp a + hashLabel lab
65 :     | T.IF(ctrl,a,b,c) =>
66 :     0w233 + hashCtrls ctrl + hashCCexp a + hashStm b + hashStm c
67 : monnier 473 | T.ANNOTATION(stm, a) => hashStm stm
68 : leunga 624 | T.PHI{preds, block} => w block + ws preds
69 :     | T.SOURCE{block, liveIn} => 0w123 + w block + ws liveIn
70 :     | T.SINK{block, liveOut} => 0w423 + w block + ws liveOut
71 : george 545 | T.REGION(stm,ctrl) => hashStm stm + hashCtrl ctrl
72 :     | T.RTL{hash,...} => !hash
73 :     | T.SEQ ss => hashStms(ss, 0w23)
74 :     | _ => error "hashStm"
75 : monnier 473
76 : george 545 and hashStms([],h) = h
77 :     | hashStms(s::ss,h) = hashStms(ss,hashStm s + h)
78 :    
79 : monnier 473 and hashMlrisc(T.CCR ccexp) = hashCCexp ccexp
80 :     | hashMlrisc(T.GPR rexp) = hashRexp rexp
81 :     | hashMlrisc(T.FPR fexp) = hashFexp fexp
82 :    
83 :     and hashMlriscs [] = 0w123
84 :     | hashMlriscs(m::ms) = hashMlrisc m + hashMlriscs ms
85 :    
86 :     and hash2(ty,x,y) = w ty + hashRexp x + hashRexp y
87 :    
88 :     and hashRexp rexp =
89 :     case rexp of
90 :     T.REG(ty, src) => w ty + w src
91 :     | T.LI i => w i
92 :     | T.LI32 w => W.fromLargeWord w
93 :     | T.LI64 w => W.fromLargeWord(Word64.toLargeWord w)
94 :     | T.LABEL le => LabelExp.hash le
95 :     | T.CONST c => Constant.hash c
96 : george 545 | T.NEG(ty, x) => w ty + hashRexp x + 0w24
97 : monnier 473 | T.ADD x => hash2 x + 0w234
98 :     | T.SUB x => hash2 x + 0w456
99 :     | T.MULS x => hash2 x + 0w2131
100 :     | T.DIVS x => hash2 x + 0w156
101 : george 545 | T.QUOTS x => hash2 x + 0w1565
102 : monnier 473 | T.REMS x => hash2 x + 0w231
103 :     | T.MULU x => hash2 x + 0w123
104 :     | T.DIVU x => hash2 x + 0w1234
105 :     | T.REMU x => hash2 x + 0w211
106 : george 545 | T.NEGT(ty, x) => w ty + hashRexp x + 0w1224
107 : monnier 473 | T.ADDT x => hash2 x + 0w1219
108 :     | T.SUBT x => hash2 x + 0w999
109 :     | T.MULT x => hash2 x + 0w7887
110 :     | T.DIVT x => hash2 x + 0w88884
111 : george 545 | T.QUOTT x => hash2 x + 0w8884
112 : monnier 473 | T.REMT x => hash2 x + 0w99
113 :     | T.ANDB x => hash2 x + 0w12312
114 :     | T.ORB x => hash2 x + 0w558
115 :     | T.XORB x => hash2 x + 0w234
116 :     | T.NOTB(ty, x) => w ty + hashRexp x
117 :     | T.SRA x => hash2 x + 0w874
118 :     | T.SRL x => hash2 x + 0w223
119 :     | T.SLL x => hash2 x + 0w499
120 :     | T.COND(ty,e,e1,e2) => w ty + hashCCexp e + hashRexp e1 + hashRexp e2
121 : george 545 | T.CVTI2I(ty, T.SIGN_EXTEND, ty', rexp) =>
122 :     0w232 + w ty + w ty' + hashRexp rexp
123 :     | T.CVTI2I(ty, T.ZERO_EXTEND, ty', rexp) =>
124 :     0w737 + w ty + w ty' + hashRexp rexp
125 : monnier 473 | T.CVTF2I(ty, round, ty', fexp) =>
126 : george 545 w ty + B.hashRoundingMode round + w ty' + hashFexp fexp
127 : monnier 473 | T.LOAD(ty, ea, mem) => w ty + hashRexp ea + 0w342
128 : george 545 | T.LET(stm, rexp) => hashStm stm + hashRexp rexp
129 :     | T.PRED(e, ctrl) => hashRexp e + hashCtrl ctrl
130 : monnier 473 | T.MARK(e, _) => hashRexp e
131 : george 545 | T.REXT(ty, rext) => w ty + hashRext (hasher()) rext
132 : monnier 473
133 :     and hashRexps([],h) = h
134 :     | hashRexps(e::es,h) = hashRexps(es,hashRexp e + h)
135 :    
136 :     and hash2'(ty,x,y) = w ty + hashFexp x + hashFexp y
137 :    
138 :     and hashFexp fexp =
139 :     case fexp of
140 :     T.FREG(fty, src) => w fty + w src
141 :     | T.FLOAD(fty, ea, mem) => w fty + hashRexp ea
142 :     | T.FADD x => hash2' x + 0w123
143 :     | T.FMUL x => hash2' x + 0w1234
144 :     | T.FSUB x => hash2' x + 0w12345
145 :     | T.FDIV x => hash2' x + 0w234
146 : george 545 | T.FCOPYSIGN x => hash2' x + 0w883
147 :     | T.FCOND(fty,c,x,y) => w fty + hashCCexp c + hashFexp x + hashFexp y
148 : monnier 473 | T.FABS(fty, fexp) => w fty + hashFexp fexp + 0w2345
149 :     | T.FNEG(fty, fexp) => w fty + hashFexp fexp + 0w23456
150 :     | T.FSQRT(fty, fexp) => w fty + hashFexp fexp + 0w345
151 : george 545 | T.CVTI2F(fty, ty, rexp) => w fty + w ty + hashRexp rexp
152 :     | T.CVTF2F(fty, fty', fexp) => w fty + hashFexp fexp + w fty'
153 : monnier 473 | T.FMARK(e, _) => hashFexp e
154 : george 545 | T.FPRED(e, ctrl) => hashFexp e + hashCtrl ctrl
155 :     | T.FEXT(fty, fext) => w fty + hashFext (hasher()) fext
156 : monnier 473
157 :     and hashFexps([],h) = h
158 :     | hashFexps(e::es,h) = hashFexps(es,hashFexp e + h)
159 :    
160 :     and hashCCexp ccexp =
161 :     case ccexp of
162 : george 545 T.CC(cc, src) => B.hashCond cc + w src
163 :     | T.FCC(fcc, src) => B.hashFcond fcc + w src
164 : monnier 473 | T.CMP(ty, cond, x, y) =>
165 : george 545 w ty + B.hashCond cond + hashRexp x + hashRexp y
166 : monnier 473 | T.FCMP(fty, fcond, x, y) =>
167 : george 545 w fty + B.hashFcond fcond + hashFexp x + hashFexp y
168 :     | T.NOT x => 0w2321 + hashCCexp x
169 :     | T.AND(x,y) => 0w2321 + hashCCexp x + hashCCexp y
170 :     | T.OR(x,y) => 0w8721 + hashCCexp x + hashCCexp y
171 :     | T.XOR(x,y) => 0w6178 + hashCCexp x + hashCCexp y
172 :     | T.TRUE => 0w0
173 :     | T.FALSE => 0w1232
174 : monnier 473 | T.CCMARK(e, _) => hashCCexp e
175 : george 545 | T.CCEXT(ty,ccext) => w ty + hashCCext (hasher()) ccext
176 : monnier 473
177 :     and hashCCexps([],h) = h
178 :     | hashCCexps(e::es,h) = hashCCexps(es,hashCCexp e + h)
179 :    
180 :     (*
181 :     * Equality
182 :     *)
183 :    
184 : george 545 fun eqLabel(Label.Label{id=x,...},Label.Label{id=y,...}) = x=y
185 : george 555 and eqLabels([],[]) = true
186 : george 545 | eqLabels(a::b,c::d) = eqLabel(a,c) andalso eqLabels(b,d)
187 :     | eqLabels _ = false
188 : monnier 473
189 :     (* statements *)
190 : george 555 and equality() = {stm=eqStm, rexp=eqRexp, fexp=eqFexp, ccexp=eqCCexp}
191 : george 545 and eqStm(T.MV(a,b,c),T.MV(d,e,f)) = b=e andalso a=d andalso eqRexp(c,f)
192 : monnier 473 | eqStm(T.CCMV(a,b),T.CCMV(c,d)) = a=c andalso eqCCexp(b,d)
193 :     | eqStm(T.FMV(a,b,c),T.FMV(d,e,f)) = b=e andalso a=d andalso eqFexp(c,f)
194 :     | eqStm(T.COPY x,T.COPY y) = x = y
195 :     | eqStm(T.FCOPY x,T.FCOPY y) = x = y
196 : george 545 | eqStm(T.JMP(a,b,c),T.JMP(a',b',c')) =
197 :     a=a' andalso eqRexp(b,b') andalso eqLabels(c,c')
198 : leunga 591 | eqStm(T.CALL{funct=a,defs=b,uses=c,...},
199 :     T.CALL{funct=d,defs=e,uses=f,...}) =
200 : monnier 473 eqRexp(a,d) andalso eqMlriscs(b,e) andalso eqMlriscs(c,f)
201 : george 545 | eqStm(T.RET _,T.RET _) = true
202 : monnier 473 | eqStm(T.STORE(a,b,c,_),T.STORE(d,e,f,_)) =
203 :     a=d andalso eqRexp(b,e) andalso eqRexp(c,f)
204 :     | eqStm(T.FSTORE(a,b,c,_),T.FSTORE(d,e,f,_)) =
205 :     a=d andalso eqRexp(b,e) andalso eqFexp(c,f)
206 :     | eqStm(T.ANNOTATION(s1, _),s2) = eqStm(s1,s2)
207 :     | eqStm(s1,T.ANNOTATION(s2, _)) = eqStm(s1,s2)
208 : george 545 | eqStm(T.PHI x,T.PHI y) = x=y
209 : leunga 624 | eqStm(T.SOURCE x,T.SOURCE y) = x=y
210 :     | eqStm(T.SINK x,T.SINK y) = x=y
211 : george 545 | eqStm(T.BCC(a,b,c),T.BCC(a',b',c')) =
212 :     a=a' andalso eqCCexp(b,b') andalso eqLabel(c,c')
213 :     | eqStm(T.IF(a,b,c,d),T.IF(a',b',c',d')) =
214 :     a=a' andalso eqCCexp(b,b') andalso eqStm(c,c') andalso eqStm(d,d')
215 :     | eqStm(T.RTL{hash=x,...},T.RTL{hash=y,...}) = x=y
216 :     | eqStm(T.REGION(a,b),T.REGION(a',b')) = b = b' andalso eqStm(a,a')
217 :     | eqStm(T.EXT a,T.EXT a') = eqSext (equality()) (a,a')
218 : monnier 473 | eqStm _ = false
219 :    
220 :     and eqStms([],[]) = true
221 :     | eqStms(a::b,c::d) = eqStm(a,c) andalso eqStms(b,d)
222 :     | eqStms _ = false
223 :    
224 :     and eqMlrisc(T.CCR a,T.CCR b) = eqCCexp(a,b)
225 :     | eqMlrisc(T.GPR a,T.GPR b) = eqRexp(a,b)
226 :     | eqMlrisc(T.FPR a,T.FPR b) = eqFexp(a,b)
227 :     | eqMlrisc _ = false
228 :    
229 :     and eqMlriscs([],[]) = true
230 :     | eqMlriscs(a::b,c::d) = eqMlrisc(a,c) andalso eqMlriscs(b,d)
231 :     | eqMlriscs _ = false
232 :    
233 :     and eq2((a,b,c),(d,e,f)) = a=d andalso eqRexp(b,e) andalso eqRexp(c,f)
234 :    
235 :     and eqRexp(T.REG(a,b),T.REG(c,d)) = a=c andalso b=d
236 :     | eqRexp(T.LI a,T.LI b) = a=b
237 :     | eqRexp(T.LI32 a,T.LI32 b) = a=b
238 :     | eqRexp(T.LI64 a,T.LI64 b) = a=b
239 :     | eqRexp(T.LABEL a,T.LABEL b) = LabelExp.==(a,b)
240 :     | eqRexp(T.CONST a,T.CONST b) = Constant.==(a,b)
241 : george 545 | eqRexp(T.NEG(t,x),T.NEG(t',x')) = t = t' andalso eqRexp(x,x')
242 : monnier 473 | eqRexp(T.ADD x,T.ADD y) = eq2(x,y)
243 :     | eqRexp(T.SUB x,T.SUB y) = eq2(x,y)
244 :     | eqRexp(T.MULS x,T.MULS y) = eq2(x,y)
245 :     | eqRexp(T.DIVS x,T.DIVS y) = eq2(x,y)
246 : george 545 | eqRexp(T.QUOTS x,T.QUOTS y) = eq2(x,y)
247 : monnier 473 | eqRexp(T.REMS x,T.REMS y) = eq2(x,y)
248 :     | eqRexp(T.MULU x,T.MULU y) = eq2(x,y)
249 :     | eqRexp(T.DIVU x,T.DIVU y) = eq2(x,y)
250 :     | eqRexp(T.REMU x,T.REMU y) = eq2(x,y)
251 : george 545 | eqRexp(T.NEGT(t,x),T.NEGT(t',x')) = t = t' andalso eqRexp(x,x')
252 : monnier 473 | eqRexp(T.ADDT x,T.ADDT y) = eq2(x,y)
253 :     | eqRexp(T.SUBT x,T.SUBT y) = eq2(x,y)
254 :     | eqRexp(T.MULT x,T.MULT y) = eq2(x,y)
255 :     | eqRexp(T.DIVT x,T.DIVT y) = eq2(x,y)
256 : george 545 | eqRexp(T.QUOTT x,T.QUOTT y) = eq2(x,y)
257 : monnier 473 | eqRexp(T.REMT x,T.REMT y) = eq2(x,y)
258 :     | eqRexp(T.ANDB x,T.ANDB y) = eq2(x,y)
259 :     | eqRexp(T.ORB x,T.ORB y) = eq2(x,y)
260 :     | eqRexp(T.XORB x,T.XORB y) = eq2(x,y)
261 :     | eqRexp(T.NOTB(a,b),T.NOTB(c,d)) = a=c andalso eqRexp(b,d)
262 :     | eqRexp(T.SRA x,T.SRA y) = eq2(x,y)
263 :     | eqRexp(T.SRL x,T.SRL y) = eq2(x,y)
264 :     | eqRexp(T.SLL x,T.SLL y) = eq2(x,y)
265 :     | eqRexp(T.COND(a,b,c,d),T.COND(e,f,g,h)) =
266 :     a=e andalso eqCCexp(b,f) andalso eqRexp(c,g) andalso eqRexp(d,h)
267 : george 545 | eqRexp(T.CVTI2I(a,b,c,d),T.CVTI2I(a',b',c',d')) =
268 :     a=a' andalso b=b' andalso c=c' andalso eqRexp(d,d')
269 : monnier 473 | eqRexp(T.CVTF2I(a,b,c,d),T.CVTF2I(e,f,g,h)) =
270 :     a=e andalso b=f andalso c=g andalso eqFexp(d,h)
271 :     | eqRexp(T.LOAD(a,b,_),T.LOAD(c,d,_)) = a=c andalso eqRexp(b,d)
272 : george 545 | eqRexp(T.LET(a,b),T.LET(c,d)) = eqStm(a,c) andalso eqRexp(b,d)
273 : monnier 473 | eqRexp(T.MARK(a,_),b) = eqRexp(a,b)
274 :     | eqRexp(a,T.MARK(b,_)) = eqRexp(a,b)
275 : george 545 | eqRexp(T.PRED(a,b),T.PRED(a',b')) = b = b' andalso eqRexp(a,a')
276 :     | eqRexp(T.REXT(a,b),T.REXT(a',b')) =
277 :     a=a' andalso eqRext (equality()) (b,b')
278 : monnier 473 | eqRexp _ = false
279 :    
280 :     and eqRexps([],[]) = true
281 :     | eqRexps(a::b,c::d) = eqRexp(a,c) andalso eqRexps(b,d)
282 :     | eqRexps _ = false
283 :    
284 :     and eq2'((a,b,c),(d,e,f)) = a=d andalso eqFexp(b,e) andalso eqFexp(c,f)
285 :     and eq1'((a,b),(d,e)) = a=d andalso eqFexp(b,e)
286 :    
287 :     and eqFexp(T.FREG x,T.FREG y) = x = y
288 :     | eqFexp(T.FLOAD(a,b,_),T.FLOAD(c,d,_)) = a=c andalso eqRexp(b,d)
289 :     | eqFexp(T.FADD x,T.FADD y) = eq2'(x,y)
290 :     | eqFexp(T.FMUL x,T.FMUL y) = eq2'(x,y)
291 :     | eqFexp(T.FSUB x,T.FSUB y) = eq2'(x,y)
292 :     | eqFexp(T.FDIV x,T.FDIV y) = eq2'(x,y)
293 : george 545 | eqFexp(T.FCOPYSIGN x, T.FCOPYSIGN y) = eq2'(x,y)
294 :     | eqFexp(T.FCOND(t,x,y,z), T.FCOND(t',x',y',z')) =
295 :     t=t' andalso eqCCexp(x,x') andalso eqFexp(y,y') andalso eqFexp(z,z')
296 : monnier 473 | eqFexp(T.FABS x,T.FABS y) = eq1'(x,y)
297 :     | eqFexp(T.FNEG x,T.FNEG y) = eq1'(x,y)
298 :     | eqFexp(T.FSQRT x,T.FSQRT y) = eq1'(x,y)
299 : george 545 | eqFexp(T.CVTI2F(a,b,c),T.CVTI2F(a',b',c')) =
300 :     a=a' andalso b=b' andalso eqRexp(c,c')
301 :     | eqFexp(T.CVTF2F(a,b,c),T.CVTF2F(a',b',c')) =
302 :     a=a' andalso b=b' andalso eqFexp(c,c')
303 :     | eqFexp(T.FEXT(a,f),T.FEXT(b,g)) = a=b andalso eqFext (equality()) (f,g)
304 : monnier 473 | eqFexp(T.FMARK(a,_),b) = eqFexp(a,b)
305 :     | eqFexp(a,T.FMARK(b,_)) = eqFexp(a,b)
306 : george 545 | eqFexp(T.FPRED(a,b),T.FPRED(a',b')) = b = b' andalso eqFexp(a,a')
307 : monnier 473 | eqFexp _ = false
308 :    
309 :     and eqFexps([],[]) = true
310 :     | eqFexps(a::b,c::d) = eqFexp(a,c) andalso eqFexps(b,d)
311 :     | eqFexps _ = false
312 :    
313 :     and eqCCexp(T.CC x,T.CC y) = x=y
314 : george 545 | eqCCexp(T.FCC x,T.FCC y) = x=y
315 : monnier 473 | eqCCexp(T.CMP(x,a,b,c),T.CMP(y,d,e,f)) =
316 :     a=d andalso eqRexp(b,e) andalso eqRexp(c,f) andalso x = y
317 :     | eqCCexp(T.FCMP(x,a,b,c),T.FCMP(y,d,e,f)) =
318 :     a=d andalso eqFexp(b,e) andalso eqFexp(c,f) andalso x = y
319 : george 545 | eqCCexp(T.NOT x, T.NOT y) = eqCCexp(x,y)
320 :     | eqCCexp(T.AND x, T.AND y) = eqCCexp2(x,y)
321 :     | eqCCexp(T.OR x, T.OR y) = eqCCexp2(x,y)
322 :     | eqCCexp(T.XOR x, T.XOR y) = eqCCexp2(x,y)
323 : monnier 473 | eqCCexp(T.CCMARK(a,_),b) = eqCCexp(a,b)
324 :     | eqCCexp(a,T.CCMARK(b,_)) = eqCCexp(a,b)
325 : george 545 | eqCCexp(T.CCEXT(t,a),T.CCEXT(t',b)) =
326 :     t=t' andalso eqCCext (equality()) (a,b)
327 :     | eqCCexp(T.TRUE, T.TRUE) = true
328 :     | eqCCexp(T.FALSE, T.FALSE) = true
329 : monnier 473 | eqCCexp _ = false
330 :    
331 : george 545 and eqCCexp2((x,y),(x',y')) = eqCCexp(x,x') andalso eqCCexp(y,y')
332 :    
333 : monnier 473 and eqCCexps([],[]) = true
334 :     | eqCCexps(a::b,c::d) = eqCCexp(a,c) andalso eqCCexps(b,d)
335 :     | eqCCexps _ = false
336 : george 545
337 : monnier 473 (*
338 :     * Pretty printing
339 :     *)
340 : leunga 601 fun show {def,use,regionDef,regionUse} =
341 : monnier 473 let fun ty t = "."^Int.toString t
342 :     fun fty 32 = ".s"
343 :     | fty 64 = ".d"
344 :     | fty 128 = ".q"
345 :     | fty t = ty t
346 :    
347 :     fun reg(t,v) = "r"^Int.toString v^ty t
348 :     fun freg(t,v) = "f"^Int.toString v^fty t
349 :     fun ccreg v = "cc"^Int.toString v
350 : george 545 fun ctrlreg v = "p"^Int.toString v
351 :    
352 : leunga 601 fun srcReg(t,v) = use v handle _ => reg(t,v)
353 :     fun srcFreg(t,v) = use v handle _ => freg(t,v)
354 :     fun srcCCreg v = use v handle _ => ccreg v
355 :     fun srcCtrlreg v = use v handle _ => ctrlreg v
356 : monnier 473
357 : leunga 601 fun dstReg(t,v) = def v handle _ => reg(t,v)
358 :     fun dstFreg(t,v) = def v handle _ => freg(t,v)
359 :     fun dstCCreg v = def v handle _ => ccreg v
360 :     fun dstCtrlreg v = def v handle _ => ctrlreg v
361 : monnier 473
362 : george 545 fun listify f =
363 :     let fun g(t,[]) = ""
364 :     | g(t,[r]) = f(t,r)
365 :     | g(t,r::rs) = f(t,r)^","^g(t,rs)
366 :     in g end
367 : monnier 473
368 : george 545 fun listify' f =
369 :     let fun g([]) = ""
370 :     | g([r]) = f(r)
371 :     | g(r::rs) = f(r)^","^g(rs)
372 :     in g end
373 : monnier 473
374 : george 545 val srcRegs = listify srcReg
375 :     val dstRegs = listify dstReg
376 :     val srcFregs = listify srcFreg
377 :     val dstFregs = listify dstFreg
378 :     val srcCCregs = listify' srcCCreg
379 :     val dstCCregs = listify' dstCCreg
380 :     val srcCtrlregs = listify' srcCtrlreg
381 :     val dstCtrlregs = listify' dstCtrlreg
382 :     fun usectrl cr = " ["^srcCtrlreg cr^"]"
383 :     fun usectrls [] = ""
384 :     | usectrls cr = " ["^srcCtrlregs cr^"]"
385 :     fun defctrl cr = ""^dstCtrlreg cr^" <- "
386 :     fun defctrls [] = ""
387 :     | defctrls cr = ""^dstCtrlregs cr^" <- "
388 : monnier 473
389 : george 545 fun copy(t,dst,src) = dstRegs(t, dst)^" := "^srcRegs(t, src)
390 : monnier 473 fun fcopy(t,dst,src) = dstFregs(t, dst)^" := "^srcFregs(t, src)
391 :    
392 : george 545 fun shower() = {stm=stm, rexp=rexp, fexp=fexp, ccexp=ccexp,
393 : george 555 dstReg=dstReg, srcReg=srcReg}
394 : monnier 473 (* pretty print a statement *)
395 : george 545 and stm(T.MV(t,dst,e)) = dstReg(t,dst)^" := "^rexp e
396 : monnier 473 | stm(T.CCMV(dst,e)) = dstCCreg dst^" := "^ccexp e
397 :     | stm(T.FMV(fty,dst,e)) = dstFreg(fty,dst)^" := "^fexp e
398 :     | stm(T.COPY(ty,dst,src)) = copy(ty,dst,src)
399 :     | stm(T.FCOPY(fty,dst,src)) = fcopy(fty,dst,src)
400 : george 545 | stm(T.JMP(cr,ea,labels)) = defctrls cr^"jmp "^rexp ea
401 : leunga 591 | stm(T.CALL{funct,targets,defs,uses,cdefs,cuses,region}) =
402 :     defctrls cdefs^"call "^rexp funct^usectrls cuses
403 : george 545 | stm(T.RET(cr,flow)) = defctrls cr^"ret"
404 : monnier 473 | stm(T.STORE(ty,ea,e,mem)) = store(ty,"",ea,mem,e)
405 :     | stm(T.FSTORE(fty,ea,e,mem)) = fstore(fty,"",ea,mem,e)
406 : george 545 | stm(T.BCC(cr,a,lab)) =
407 :     defctrls cr^"bcc "^ccexp a^" "^Label.nameOf lab
408 :     | stm(T.IF(cr,a,b,c)) =
409 :     defctrls cr^"if "^ccexp a^" then "^stm b^" else "^stm c
410 :     | stm(T.SEQ []) = "skip"
411 :     | stm(T.SEQ s) = stms(";",s)
412 :     | stm(T.REGION(s,cr)) = stm s^usectrl cr
413 : monnier 473 | stm(T.ANNOTATION(s, a)) = stm s
414 : leunga 624 | stm(T.PHI{preds, block}) = "phi["^Int.toString block^"]"
415 :     | stm(T.SOURCE{block,...}) = "source["^Int.toString block^"]"
416 :     | stm(T.SINK{block,...}) = "sink["^Int.toString block^"]"
417 : george 545 | stm(T.RTL{e,...}) = stm e
418 : george 555 | stm(T.EXT x) = showSext (shower()) x
419 : george 545 | stm _ = error "stm"
420 : monnier 473
421 :     and stms(sep,[]) = ""
422 :     | stms(sep,[s]) = stm s
423 :     | stms(sep,s::ss) = stm s^sep^stms(sep,ss)
424 :    
425 :     (* pretty print an expression *)
426 :     and rexp(T.REG(ty, src)) = srcReg(ty,src)
427 : george 545 | rexp(T.LI i) = Int.toString i
428 : leunga 601 | rexp(T.LI32 w) = "0x"^Word32.toString w
429 :     | rexp(T.LI64 w) = "0x"^Word64.toString w
430 : monnier 473 | rexp(T.LABEL le) = LabelExp.toString le
431 :     | rexp(T.CONST c) = Constant.toString c
432 : leunga 601 | rexp(T.NEG x) = unary("~",x)
433 :     | rexp(T.ADD x) = binary("+",x)
434 :     | rexp(T.SUB x) = binary("-",x)
435 : monnier 473 | rexp(T.MULS x) = two("muls",x)
436 :     | rexp(T.DIVS x) = two("divs",x)
437 : george 545 | rexp(T.QUOTS x) = two("quots",x)
438 : monnier 473 | rexp(T.REMS x) = two("rems",x)
439 :     | rexp(T.MULU x) = two("mulu",x)
440 :     | rexp(T.DIVU x) = two("divu",x)
441 :     | rexp(T.REMU x) = two("remu",x)
442 : george 545 | rexp(T.NEGT x) = one("negt",x)
443 : monnier 473 | rexp(T.ADDT x) = two("addt",x)
444 :     | rexp(T.SUBT x) = two("subt",x)
445 :     | rexp(T.MULT x) = two("mult",x)
446 :     | rexp(T.DIVT x) = two("divt",x)
447 : george 545 | rexp(T.QUOTT x) = two("quott",x)
448 : monnier 473 | rexp(T.REMT x) = two("remt",x)
449 : leunga 601 | rexp(T.ANDB x) = binary("&",x)
450 :     | rexp(T.ORB x) = binary("|",x)
451 :     | rexp(T.XORB x) = binary("^",x)
452 :     | rexp(T.NOTB x) = unary("!",x)
453 :     | rexp(T.SRA x) = binary("~>>",x)
454 :     | rexp(T.SRL x) = binary(">>",x)
455 :     | rexp(T.SLL x) = binary("<<",x)
456 : monnier 473 | rexp(T.COND(t,cc,e1,e2)) =
457 :     "cond"^ty t^ccexp cc^"("^rexp e1^","^rexp e2^")"
458 : george 545 | rexp(T.CVTI2I(t, T.SIGN_EXTEND, t', e)) = "sx"^ty t^ty t'^" "^rexp e
459 :     | rexp(T.CVTI2I(t, T.ZERO_EXTEND, t', e)) = "zx"^ty t^ty t'^" "^rexp e
460 : monnier 473 | rexp(T.CVTF2I(t, round, t', e)) =
461 : george 545 "cvtf2i"^ty t^B.roundingModeToString round^fty t'^" "^fexp e
462 : monnier 473 | rexp(T.LOAD(ty, ea, mem)) = load(ty,"",ea,mem)
463 : george 545 | rexp(T.LET(s, e)) = stm s^";"^rexp e
464 :     | rexp(T.PRED(e, cr)) = rexp e^usectrl cr
465 : monnier 473 | rexp(T.MARK(e, _)) = rexp e
466 : george 555 | rexp(T.REXT e) = showRext (shower()) e
467 : monnier 473
468 : leunga 601 and parenRexp(e as (T.REG _ | T.LI _ | T.LI32 _ | T.LI64 _)) = rexp e
469 :     | parenRexp e = "("^rexp e^")"
470 :    
471 : george 545 and slices sc = listify' (fn {from,to} => rexp from^".."^rexp to) sc
472 :    
473 : monnier 473 (* pretty print a real expression *)
474 :     and fexp(T.FREG f) = srcFreg f
475 :     | fexp(T.FLOAD(fty, ea, mem)) = fload(fty,"",ea,mem)
476 :     | fexp(T.FADD x) = two'("fadd",x)
477 :     | fexp(T.FMUL x) = two'("fmul",x)
478 :     | fexp(T.FSUB x) = two'("fsub",x)
479 :     | fexp(T.FDIV x) = two'("fdiv",x)
480 : george 545 | fexp(T.FCOPYSIGN x) = two'("fcopysign",x)
481 : monnier 473 | fexp(T.FABS x) = one'("fabs",x)
482 :     | fexp(T.FNEG x) = one'("fneg",x)
483 :     | fexp(T.FSQRT x) = one'("fsqrt",x)
484 : george 545 | fexp(T.FCOND(t,cc,e1,e2)) =
485 :     "fcond"^fty t^ccexp cc^"("^fexp e1^","^fexp e2^")"
486 :     | fexp(T.CVTI2F(t, t', e)) = "cvti2f"^ty t'^" "^rexp e
487 :     | fexp(T.CVTF2F(t, t', e)) = "cvtf2f"^fty t^fty t'^" "^fexp e
488 :     | fexp(T.FPRED(e, cr)) = fexp e^usectrl cr
489 : monnier 473 | fexp(T.FMARK(e, _)) = fexp e
490 : george 555 | fexp(T.FEXT e) = showFext (shower()) e
491 : monnier 473
492 : george 545 and ccexp(T.CC(cc,r)) = srcCCreg r^B.condToString cc
493 :     | ccexp(T.FCC(fcc,r)) = srcCCreg r^B.fcondToString fcc
494 :     | ccexp(T.CMP(t,cc,x,y)) = "cmp"^B.condToString cc^ty t^pair(x,y)
495 :     | ccexp(T.FCMP(t,fcc,x,y)) = "fcmp"^B.fcondToString fcc^fty t^pair'(x,y)
496 :     | ccexp(T.NOT x) = "not "^ccexp x
497 :     | ccexp(T.AND(x,y)) = two''(" and ",x,y)
498 :     | ccexp(T.OR(x,y)) = two''(" or ",x,y)
499 :     | ccexp(T.XOR(x,y)) = two''(" xor ",x,y)
500 : monnier 473 | ccexp(T.CCMARK(e, _)) = ccexp e
501 : george 545 | ccexp(T.TRUE) = "true"
502 :     | ccexp(T.FALSE) = "false"
503 : george 555 | ccexp(T.CCEXT(e)) = showCCext (shower()) e
504 : monnier 473
505 : george 545 and mlrisc(T.GPR e) = rexp e
506 :     | mlrisc(T.FPR e) = fexp e
507 :     | mlrisc(T.CCR e) = ccexp e
508 :    
509 :     and mlriscs l = listify' mlrisc l
510 :    
511 : monnier 473 (* Auxiliary functions *)
512 :     and one(opcode,(t,x)) = opcode^ty t^"("^rexp x^")"
513 :     and two(opcode,(t,x,y)) = opcode^ty t^pair(x,y)
514 : leunga 601 and binary(opcode,(t,x,y)) = parenRexp x^" "^opcode^ty t^" "^parenRexp y
515 :     and unary(opcode,(t,x)) = opcode^ty t^" "^parenRexp x
516 : monnier 473 and pair(x,y) = "("^rexp x^","^rexp y^")"
517 :     and one'(opcode,(t,x)) = opcode^fty t^"("^fexp x^")"
518 :     and two'(opcode,(t,x,y)) = opcode^fty t^pair'(x,y)
519 : george 545 and two''(c,x,y) = "("^ccexp x^ c ^ ccexp y^")"
520 : monnier 473 and pair'(x,y) = "("^fexp x^","^fexp y^")"
521 :     and rexps es = "("^foldr (fn (e,"") => rexp e
522 :     | (e,x) => rexp e^","^x) "" es^")"
523 :     and fexps es = "("^foldr (fn (e,"") => fexp e
524 :     | (e,x) => fexp e^","^x) "" es^")"
525 :     and ccexps es = "("^foldr (fn (e,"") => ccexp e
526 :     | (e,x) => ccexp e^","^x) "" es^")"
527 : leunga 601 and store(t,u,ea,m,e) = memdef(t,u,ea,m)^" := "^rexp e
528 :     and fstore(t,u,ea,m,e) = fmemdef(t,u,ea,m)^" := "^fexp e
529 :     and ccstore(u,ea,m,e) = ccmemdef(u,ea,m)^" := "^ccexp e
530 :     and load(t,u,ea,m) = memuse(t,u,ea,m)
531 :     and fload(t,u,ea,m) = fmemuse(t,u,ea,m)
532 :     and ccload(u,ea,m) = ccmemuse(u,ea,m)
533 :     and addr(u,ea,m,show) =
534 :     let val r = show m handle _ => Region.toString m
535 :     val r = if r = "" then r else ":"^r
536 : george 545 in u^"["^rexp ea^r^"]" end
537 : leunga 601 and mem(t,u,ea,m,show) = "mem"^ty t^addr(u,ea,m,show)
538 :     and fmem(t,u,ea,m,show) = "mem"^fty t^addr(u,ea,m,show)
539 :     and ccmem(u,ea,m,show) = "mem"^addr(u,ea,m,show)
540 :     and memdef(t,u,ea,m) = mem(t,u,ea,m,regionDef)
541 :     and fmemdef(t,u,ea,m) = fmem(t,u,ea,m,regionDef)
542 :     and ccmemdef(u,ea,m) = ccmem(u,ea,m,regionDef)
543 :     and memuse(t,u,ea,m) = mem(t,u,ea,m,regionUse)
544 :     and fmemuse(t,u,ea,m) = fmem(t,u,ea,m,regionUse)
545 :     and ccmemuse(u,ea,m) = ccmem(u,ea,m,regionUse)
546 : george 545 in shower()
547 : monnier 473 end
548 :    
549 : leunga 601 exception Nothing
550 : monnier 473
551 : leunga 601 fun dummy _ = raise Nothing
552 :     val dummy = {def=dummy, use=dummy, regionDef=dummy, regionUse=dummy}
553 :    
554 :     fun stmToString s = #stm(show dummy) s
555 :     fun rexpToString s = #rexp(show dummy) s
556 :     fun fexpToString s = #fexp(show dummy) s
557 :     fun ccexpToString s = #ccexp(show dummy) s
558 :    
559 : monnier 473 end

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