Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Annotation of /branches/charisee/src/compiler/low-il/low-il.sml
ViewVC logotype

Annotation of /branches/charisee/src/compiler/low-il/low-il.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2522 - (view) (download)

1 : jhr 458 (* low-il.in
2 :     *
3 :     * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     * All rights reserved.
5 :     *
6 :     * Lower-level version of the Diderot IL input file.
7 :     *
8 :     *)
9 :    
10 :     structure LowOps =
11 :     struct
12 :    
13 : jhr 1640 (* required helper functions for types *)
14 : jhr 458 type ty = LowILTypes.ty
15 :     val samety = LowILTypes.same
16 :     val hashty = LowILTypes.hash
17 :     val tyToString = LowILTypes.toString
18 :    
19 : jhr 1640 (* required helper functions for type lists *)
20 :     type tys = ty list
21 :     fun sametys (tys1, tys2) = ListPair.allEq samety (tys1, tys2)
22 :     fun hashtys tys = List.foldl (fn (ty, s) => hashty ty + 0w3 * s) 0w0 tys
23 :     fun tysToString tys = String.concat["[", String.concatWith "," (List.map tyToString tys), "]" ]
24 :    
25 :     (* required helper functions for the int type *)
26 : jhr 458 fun sameint (i1 : int, i2) = (i1 = i2)
27 :     fun hashint i = Word.fromInt i
28 :     fun intToString i = Int.toString i
29 :    
30 : jhr 1640 (* required helper functions for the string type *)
31 : jhr 458 fun samestring (s1 : string, s2) = (s1 = s2)
32 :     val hashstring = HashString.hashString
33 :     fun stringToString s = String.concat["\"", s, "\""]
34 :    
35 : cchiw 2522 (* Was left out of my version
36 :     (* required helper functions for the input type *)
37 :     type input = ty Inputs.input
38 :     val sameinput = Inputs.same
39 :     val hashinput = Inputs.hash
40 :     val inputToString = Inputs.toString
41 :     *)
42 :    
43 : jhr 458 datatype rator
44 : cchiw 2522 = IAdd
45 :     | ISub
46 :     | IMul
47 :     | IDiv
48 :     | INeg
49 : jhr 1116 | Abs of ty
50 : jhr 458 | LT of ty
51 :     | LTE of ty
52 :     | EQ of ty
53 :     | NEQ of ty
54 :     | GT of ty
55 :     | GTE of ty
56 :     | Not
57 :     | Max
58 :     | Min
59 : jhr 1295 | Clamp of ty
60 : jhr 1116 | Lerp of ty
61 :     | Norm of ty
62 :     | Normalize of int
63 : jhr 458 | PrincipleEvec of ty
64 : jhr 1640 | EigenVecs2x2
65 :     | EigenVecs3x3
66 :     | EigenVals2x2
67 :     | EigenVals3x3
68 : jhr 1116 | Zero of ty
69 : jhr 1640 | Select of ty * int
70 :     | Index of ty * int
71 : jhr 458 | Subscript of ty
72 : cchiw 2400 | MkDynamic of ty * int
73 :     | Append of ty
74 :     | Prepend of ty
75 :     | Concat of ty
76 :     | Length of ty
77 : jhr 1116 | Ceiling of int
78 : jhr 458 | Floor of int
79 : jhr 1116 | Round of int
80 :     | Trunc of int
81 : jhr 458 | IntToReal
82 : jhr 1116 | RealToInt of int
83 : cchiw 2522
84 :     (*Error here, could not find image)
85 : cchiw 2414 | Transform of Imageinfo.info
86 : cchiw 2522 | Translate of Imageinfo.info*)
87 :    
88 : jhr 511 | ImageAddress of ImageInfo.info
89 : jhr 1116 | LoadVoxels of ImageInfo.info * int
90 :     | Inside of ImageInfo.info * int
91 : cchiw 2400 | LoadSeq of ty * string
92 :     | LoadImage of ty * string * ImageInfo.info
93 : cchiw 2522
94 :     (*Input is not defined*)
95 :     (*| Input of input*)
96 : jhr 1640 | Print of tys
97 : cchiw 2522
98 :     (*gen types*)
99 :    
100 :     | V of T (*Projection of a Vector *)
101 :     | S of T (*Specific row/col indo*)
102 :     | C of int (*Constant, like ~1*)
103 :     | addVec
104 :     | addSca
105 :     | subVec
106 :     | subSca
107 :     | prodVec
108 :     | prodSca
109 :     | prodScaV
110 :     | divSca
111 :     | sumVec
112 :     | cons
113 :     | img of T
114 :     | krn of int * int
115 :     withtype T=int*int list
116 :    
117 :    
118 :    
119 : jhr 458
120 : cchiw 2522 fun resultArity (IAdd ) = 1
121 :     | resultArity (ISub ) = 1
122 :     | resultArity (IMul ) = 1
123 :     | resultArity (IDiv ) = 1
124 :     | resultArity (INeg ) = 1
125 : jhr 1640 | resultArity (Abs _) = 1
126 :     | resultArity (LT _) = 1
127 :     | resultArity (LTE _) = 1
128 :     | resultArity (EQ _) = 1
129 :     | resultArity (NEQ _) = 1
130 :     | resultArity (GT _) = 1
131 :     | resultArity (GTE _) = 1
132 :     | resultArity Not = 1
133 :     | resultArity Max = 1
134 :     | resultArity Min = 1
135 :     | resultArity (Clamp _) = 1
136 :     | resultArity (Lerp _) = 1
137 :     | resultArity (Norm _) = 1
138 :     | resultArity (Normalize _) = 1
139 :     | resultArity (PrincipleEvec _) = 1
140 :     | resultArity EigenVecs2x2 = 1
141 :     | resultArity EigenVecs3x3 = 1
142 :     | resultArity EigenVals2x2 = 1
143 :     | resultArity EigenVals3x3 = 1
144 :     | resultArity (Zero _) = 1
145 :     | resultArity (Select _) = 1
146 :     | resultArity (Index _) = 1
147 :     | resultArity (Subscript _) = 1
148 : cchiw 2400 | resultArity (MkDynamic _) = 1
149 :     | resultArity (Append _) = 2
150 :     | resultArity (Prepend _) = 2
151 :     | resultArity (Concat _) = 2
152 :     | resultArity (Length _) = 1
153 : jhr 1640 | resultArity (Ceiling _) = 1
154 :     | resultArity (Floor _) = 1
155 :     | resultArity (Round _) = 1
156 :     | resultArity (Trunc _) = 1
157 :     | resultArity IntToReal = 1
158 :     | resultArity (RealToInt _) = 1
159 : cchiw 2522 (*| resultArity (Transform _) = 1
160 :     | resultArity (Translate _) = 1*)
161 : jhr 1640 | resultArity (ImageAddress _) = 1
162 :     | resultArity (LoadVoxels _) = 1
163 : cchiw 2400 | resultArity (Inside _) = 1
164 :     | resultArity (LoadSeq _) = 1
165 : jhr 1640 | resultArity (LoadImage _) = 1
166 : cchiw 2522 (*| resultArity (Input _) = 0*)
167 : jhr 1640 | resultArity (Print _) = 0
168 :    
169 : cchiw 2522 fun arity (IAdd ) = 2
170 :     | arity (ISub ) = 2
171 :     | arity (IMul ) = 2
172 :     | arity (IDiv ) = 2
173 :     | arity (INeg ) = 1
174 : jhr 1116 | arity (Abs _) = 1
175 : jhr 458 | arity (LT _) = 2
176 :     | arity (LTE _) = 2
177 :     | arity (EQ _) = 2
178 :     | arity (NEQ _) = 2
179 :     | arity (GT _) = 2
180 :     | arity (GTE _) = 2
181 :     | arity Not = 1
182 :     | arity Max = 2
183 :     | arity Min = 2
184 : jhr 1295 | arity (Clamp _) = 3
185 : jhr 1116 | arity (Lerp _) = 3
186 : jhr 458 | arity (Norm _) = 1
187 : jhr 1116 | arity (Normalize _) = 1
188 : jhr 458 | arity (PrincipleEvec _) = 2
189 : jhr 1640 | arity EigenVecs2x2 = 1
190 :     | arity EigenVecs3x3 = 1
191 :     | arity EigenVals2x2 = 1
192 :     | arity EigenVals3x3 = 1
193 : jhr 1116 | arity (Zero _) = 0
194 : jhr 1640 | arity (Select _) = 1
195 :     | arity (Index _) = 1
196 : jhr 458 | arity (Subscript _) = 2
197 : cchiw 2400 | arity (MkDynamic _) = 1
198 :     | arity (Append _) = 1
199 :     | arity (Prepend _) = 1
200 :     | arity (Concat _) = 1
201 :     | arity (Length _) = 1
202 : jhr 1116 | arity (Ceiling _) = 1
203 : jhr 458 | arity (Floor _) = 1
204 : jhr 1116 | arity (Round _) = 1
205 :     | arity (Trunc _) = 1
206 : jhr 458 | arity IntToReal = 1
207 : jhr 1116 | arity (RealToInt _) = 1
208 : cchiw 2522 (*| arity (Transform _) = 2
209 :     | arity (Translate _) = 2*)
210 : jhr 1116 | arity (ImageAddress _) = 1
211 : jhr 458 | arity (LoadVoxels _) = 1
212 : jhr 1116 | arity (Inside _) = 2
213 : cchiw 2400 | arity (LoadSeq _) = 0
214 :     | arity (LoadImage _) = 0
215 : cchiw 2522 (* | arity (Input _) = 0*)
216 : jhr 1640 | arity (Print _) = ~1
217 : jhr 458
218 : cchiw 2400 fun isPure (MkDynamic _) = false
219 :     | isPure (Append _) = false
220 :     | isPure (Prepend _) = false
221 :     | isPure (Concat _) = false
222 :     | isPure (Print _) = false
223 : jhr 2356 | isPure _ = true
224 :    
225 : cchiw 2522 fun same (IAdd, IAdd) = true
226 :     | same (ISub, ISub) = true
227 :     | same (IMul, IMul) = true
228 :     | same (IDiv, IDiv) = true
229 :     | same (INeg, INeg) = true
230 : jhr 1116 | same (Abs(a0), Abs(b0)) = samety(a0, b0)
231 : jhr 458 | same (LT(a0), LT(b0)) = samety(a0, b0)
232 :     | same (LTE(a0), LTE(b0)) = samety(a0, b0)
233 :     | same (EQ(a0), EQ(b0)) = samety(a0, b0)
234 :     | same (NEQ(a0), NEQ(b0)) = samety(a0, b0)
235 :     | same (GT(a0), GT(b0)) = samety(a0, b0)
236 :     | same (GTE(a0), GTE(b0)) = samety(a0, b0)
237 :     | same (Not, Not) = true
238 :     | same (Max, Max) = true
239 :     | same (Min, Min) = true
240 : jhr 1295 | same (Clamp(a0), Clamp(b0)) = samety(a0, b0)
241 : jhr 1116 | same (Lerp(a0), Lerp(b0)) = samety(a0, b0)
242 :     | same (Norm(a0), Norm(b0)) = samety(a0, b0)
243 :     | same (Normalize(a0), Normalize(b0)) = sameint(a0, b0)
244 : jhr 458 | same (PrincipleEvec(a0), PrincipleEvec(b0)) = samety(a0, b0)
245 : jhr 1640 | same (EigenVecs2x2, EigenVecs2x2) = true
246 :     | same (EigenVecs3x3, EigenVecs3x3) = true
247 :     | same (EigenVals2x2, EigenVals2x2) = true
248 :     | same (EigenVals3x3, EigenVals3x3) = true
249 : jhr 1116 | same (Zero(a0), Zero(b0)) = samety(a0, b0)
250 : jhr 1640 | same (Select(a0,a1), Select(b0,b1)) = samety(a0, b0) andalso sameint(a1, b1)
251 :     | same (Index(a0,a1), Index(b0,b1)) = samety(a0, b0) andalso sameint(a1, b1)
252 : jhr 458 | same (Subscript(a0), Subscript(b0)) = samety(a0, b0)
253 : cchiw 2400 | same (MkDynamic(a0,a1), MkDynamic(b0,b1)) = samety(a0, b0) andalso sameint(a1, b1)
254 :     | same (Append(a0), Append(b0)) = samety(a0, b0)
255 :     | same (Prepend(a0), Prepend(b0)) = samety(a0, b0)
256 :     | same (Concat(a0), Concat(b0)) = samety(a0, b0)
257 :     | same (Length(a0), Length(b0)) = samety(a0, b0)
258 : jhr 1116 | same (Ceiling(a0), Ceiling(b0)) = sameint(a0, b0)
259 : jhr 458 | same (Floor(a0), Floor(b0)) = sameint(a0, b0)
260 : jhr 1116 | same (Round(a0), Round(b0)) = sameint(a0, b0)
261 :     | same (Trunc(a0), Trunc(b0)) = sameint(a0, b0)
262 : jhr 458 | same (IntToReal, IntToReal) = true
263 : jhr 1116 | same (RealToInt(a0), RealToInt(b0)) = sameint(a0, b0)
264 : cchiw 2522 (*| same (Transform(a0), Transform(b0)) = Imageinfo.same(a0, b0)
265 :     | same (Translate(a0), Translate(b0)) = Imageinfo.same(a0, b0)*)
266 : jhr 511 | same (ImageAddress(a0), ImageAddress(b0)) = ImageInfo.same(a0, b0)
267 : jhr 1116 | same (LoadVoxels(a0,a1), LoadVoxels(b0,b1)) = ImageInfo.same(a0, b0) andalso sameint(a1, b1)
268 :     | same (Inside(a0,a1), Inside(b0,b1)) = ImageInfo.same(a0, b0) andalso sameint(a1, b1)
269 : cchiw 2400 | same (LoadSeq(a0,a1), LoadSeq(b0,b1)) = samety(a0, b0) andalso samestring(a1, b1)
270 :     | same (LoadImage(a0,a1,a2), LoadImage(b0,b1,b2)) = samety(a0, b0) andalso samestring(a1, b1) andalso ImageInfo.same(a2, b2)
271 : cchiw 2522 (*| same (Input(a0), Input(b0)) = sameinput(a0, b0)*)
272 : jhr 1640 | same (Print(a0), Print(b0)) = sametys(a0, b0)
273 : jhr 458 | same _ = false
274 :    
275 : cchiw 2522 fun hash (IAdd) = 0w3
276 :     | hash (ISub) = 0w5
277 :     | hash (IMul) = 0w7
278 :     | hash (IDiv) = 0w11
279 :     | hash (INeg) = 0w13
280 : jhr 1116 | hash (Abs(a0)) = 0w17 + hashty a0
281 :     | hash (LT(a0)) = 0w19 + hashty a0
282 :     | hash (LTE(a0)) = 0w23 + hashty a0
283 :     | hash (EQ(a0)) = 0w29 + hashty a0
284 :     | hash (NEQ(a0)) = 0w31 + hashty a0
285 :     | hash (GT(a0)) = 0w37 + hashty a0
286 :     | hash (GTE(a0)) = 0w41 + hashty a0
287 :     | hash Not = 0w43
288 :     | hash Max = 0w47
289 :     | hash Min = 0w53
290 : jhr 1295 | hash (Clamp(a0)) = 0w59 + hashty a0
291 :     | hash (Lerp(a0)) = 0w61 + hashty a0
292 : cchiw 2400 | hash (Norm(a0)) = 0w67 + hashty a0
293 :     | hash (Normalize(a0)) = 0w71 + hashint a0
294 :     | hash (PrincipleEvec(a0)) = 0w73 + hashty a0
295 :     | hash EigenVecs2x2 = 0w79
296 :     | hash EigenVecs3x3 = 0w83
297 :     | hash EigenVals2x2 = 0w89
298 :     | hash EigenVals3x3 = 0w97
299 :     | hash (Zero(a0)) = 0w101 + hashty a0
300 :     | hash (Select(a0,a1)) = 0w103 + hashty a0 + hashint a1
301 :     | hash (Index(a0,a1)) = 0w107 + hashty a0 + hashint a1
302 :     | hash (Subscript(a0)) = 0w109 + hashty a0
303 :     | hash (MkDynamic(a0,a1)) = 0w113 + hashty a0 + hashint a1
304 :     | hash (Append(a0)) = 0w127 + hashty a0
305 :     | hash (Prepend(a0)) = 0w131 + hashty a0
306 :     | hash (Concat(a0)) = 0w137 + hashty a0
307 :     | hash (Length(a0)) = 0w139 + hashty a0
308 :     | hash (Ceiling(a0)) = 0w149 + hashint a0
309 :     | hash (Floor(a0)) = 0w151 + hashint a0
310 :     | hash (Round(a0)) = 0w157 + hashint a0
311 :     | hash (Trunc(a0)) = 0w163 + hashint a0
312 :     | hash IntToReal = 0w167
313 :     | hash (RealToInt(a0)) = 0w173 + hashint a0
314 : cchiw 2522 (*| hash (Transform(a0)) = 0w179 + Imageinfo.hash a0
315 :     | hash (Translate(a0)) = 0w181 + Imageinfo.hash a0*)
316 : cchiw 2414 | hash (ImageAddress(a0)) = 0w191 + ImageInfo.hash a0
317 :     | hash (LoadVoxels(a0,a1)) = 0w193 + ImageInfo.hash a0 + hashint a1
318 : cchiw 2400 | hash (Inside(a0,a1)) = 0w197 + ImageInfo.hash a0 + hashint a1
319 :     | hash (LoadSeq(a0,a1)) = 0w199 + hashty a0 + hashstring a1
320 :     | hash (LoadImage(a0,a1,a2)) = 0w211 + hashty a0 + hashstring a1 + ImageInfo.hash a2
321 : cchiw 2522 (*| hash (Input(a0)) = 0w223 + hashinput a0*)
322 : cchiw 2400 | hash (Print(a0)) = 0w227 + hashtys a0
323 : jhr 458
324 : cchiw 2522
325 :     fun intList(ix)=String.concat (List.map (fn(e)=>Int.toString(e)) ix)
326 :    
327 :     fun toString (IAdd) = concat["IAdd"]
328 :     | toString (ISub) = concat["ISub"]
329 :     | toString (IMul) = concat["IMul"]
330 :     | toString (IDiv) = concat["IDiv"]
331 :     | toString (INeg) = concat["INeg"]
332 : jhr 1116 | toString (Abs(a0)) = concat["Abs<", tyToString a0, ">"]
333 : jhr 458 | toString (LT(a0)) = concat["LT<", tyToString a0, ">"]
334 :     | toString (LTE(a0)) = concat["LTE<", tyToString a0, ">"]
335 :     | toString (EQ(a0)) = concat["EQ<", tyToString a0, ">"]
336 :     | toString (NEQ(a0)) = concat["NEQ<", tyToString a0, ">"]
337 :     | toString (GT(a0)) = concat["GT<", tyToString a0, ">"]
338 :     | toString (GTE(a0)) = concat["GTE<", tyToString a0, ">"]
339 :     | toString Not = "Not"
340 :     | toString Max = "Max"
341 :     | toString Min = "Min"
342 : jhr 1295 | toString (Clamp(a0)) = concat["Clamp<", tyToString a0, ">"]
343 : jhr 1116 | toString (Lerp(a0)) = concat["Lerp<", tyToString a0, ">"]
344 :     | toString (Norm(a0)) = concat["Norm<", tyToString a0, ">"]
345 :     | toString (Normalize(a0)) = concat["Normalize<", intToString a0, ">"]
346 : jhr 458 | toString (PrincipleEvec(a0)) = concat["PrincipleEvec<", tyToString a0, ">"]
347 : jhr 1640 | toString EigenVecs2x2 = "EigenVecs2x2"
348 :     | toString EigenVecs3x3 = "EigenVecs3x3"
349 :     | toString EigenVals2x2 = "EigenVals2x2"
350 :     | toString EigenVals3x3 = "EigenVals3x3"
351 : jhr 1116 | toString (Zero(a0)) = concat["Zero<", tyToString a0, ">"]
352 : jhr 1640 | toString (Select(a0,a1)) = concat["Select<", tyToString a0, ",", intToString a1, ">"]
353 :     | toString (Index(a0,a1)) = concat["Index<", tyToString a0, ",", intToString a1, ">"]
354 : jhr 458 | toString (Subscript(a0)) = concat["Subscript<", tyToString a0, ">"]
355 : cchiw 2400 | toString (MkDynamic(a0,a1)) = concat["MkDynamic<", tyToString a0, ",", intToString a1, ">"]
356 :     | toString (Append(a0)) = concat["Append<", tyToString a0, ">"]
357 :     | toString (Prepend(a0)) = concat["Prepend<", tyToString a0, ">"]
358 :     | toString (Concat(a0)) = concat["Concat<", tyToString a0, ">"]
359 :     | toString (Length(a0)) = concat["Length<", tyToString a0, ">"]
360 : jhr 1116 | toString (Ceiling(a0)) = concat["Ceiling<", intToString a0, ">"]
361 : jhr 458 | toString (Floor(a0)) = concat["Floor<", intToString a0, ">"]
362 : jhr 1116 | toString (Round(a0)) = concat["Round<", intToString a0, ">"]
363 :     | toString (Trunc(a0)) = concat["Trunc<", intToString a0, ">"]
364 : jhr 458 | toString IntToReal = "IntToReal"
365 : jhr 1116 | toString (RealToInt(a0)) = concat["RealToInt<", intToString a0, ">"]
366 : cchiw 2522 (* | toString (Transform(a0)) = concat["Transform<", Imageinfo.toString a0, ">"]
367 :     | toString (Translate(a0)) = concat["Translate<", Imageinfo.toString a0, ">"]*)
368 : jhr 511 | toString (ImageAddress(a0)) = concat["ImageAddress<", ImageInfo.toString a0, ">"]
369 : jhr 1116 | toString (LoadVoxels(a0,a1)) = concat["LoadVoxels<", ImageInfo.toString a0, ",", intToString a1, ">"]
370 :     | toString (Inside(a0,a1)) = concat["Inside<", ImageInfo.toString a0, ",", intToString a1, ">"]
371 : cchiw 2400 | toString (LoadSeq(a0,a1)) = concat["LoadSeq<", tyToString a0, ",", stringToString a1, ">"]
372 :     | toString (LoadImage(a0,a1,a2)) = concat["LoadImage<", tyToString a0, ",", stringToString a1, ",", ImageInfo.toString a2, ">"]
373 : cchiw 2522 (*| toString (Input(a0)) = concat["Input<", inputToString a0, ">"]*)
374 :     | toString(V(id,ix))=concat["Projection:",Int.toString(id)," at ",(intList ix)," "]
375 :     | toString(S (id,ix))=concat["Sca:",Int.toString(id)," at ",(intList ix)," "]
376 :     | toString(C c)=concat["Const: ",Int.toString(c)," "]
377 :     | toString(addVec)="AddVec"
378 :     | toString(addSca)="addSca"
379 :     | toString(subVec)="SubVec"
380 :     | toString(subSca)="SubSca"
381 :     | toString(prodVec)="ProdVec"
382 :     | toString(prodSca)="ProdSca"
383 :     | toString(prodScaV)="ProdScaV"
384 :     | toString(divSca)="DivSca"
385 :     | toString(sumVec)="SumVec"
386 :     | toString(cons)="Cons"
387 :     | toString(img (id,ix))=concat["Image:",Int.toString(id)," at ",(intList ix)," "]
388 :     | toString(krn _)="Krn"
389 :     | toString (Print(a0)) = concat["Print<", tysToString a0, ">"]
390 :    
391 :    
392 : jhr 458
393 :     end
394 :    
395 :     structure LowIL = SSAFn(
396 : jhr 1232 val ilName = "low-il"
397 : jhr 458 structure Ty = LowILTypes
398 :     structure Op = LowOps)
399 : jhr 1116
400 :     structure LowILCensus = CensusFn(LowIL)
401 :    

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