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

SCM Repository

[diderot] Diff of /trunk/src/compiler/low-il/low-il.sml
ViewVC logotype

Diff of /trunk/src/compiler/low-il/low-il.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1444, Mon Jul 11 12:11:53 2011 UTC revision 1640, Wed Nov 16 02:19:51 2011 UTC
# Line 10  Line 10 
10  structure LowOps =  structure LowOps =
11    struct    struct
12    
13      (* required helper functions for types *)
14      type ty = LowILTypes.ty      type ty = LowILTypes.ty
   
15      val samety = LowILTypes.same      val samety = LowILTypes.same
16      val hashty = LowILTypes.hash      val hashty = LowILTypes.hash
17      val tyToString = LowILTypes.toString      val tyToString = LowILTypes.toString
18    
19      (* 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      fun sameint (i1 : int, i2) = (i1 = i2)      fun sameint (i1 : int, i2) = (i1 = i2)
27      fun hashint i = Word.fromInt i      fun hashint i = Word.fromInt i
28      fun intToString i = Int.toString i      fun intToString i = Int.toString i
29    
30      (* required helper functions for the string type *)
31      fun samestring (s1 : string, s2) = (s1 = s2)      fun samestring (s1 : string, s2) = (s1 = s2)
32      val hashstring = HashString.hashString      val hashstring = HashString.hashString
33      fun stringToString s = String.concat["\"", s, "\""]      fun stringToString s = String.concat["\"", s, "\""]
# Line 47  Line 55 
55        | MulMatVec of int * int        | MulMatVec of int * int
56        | MulMatMat of int * int * int        | MulMatMat of int * int * int
57        | Cross        | Cross
       | Select of ty * int  
58        | Norm of ty        | Norm of ty
59        | Normalize of int        | Normalize of int
60        | Scale of ty        | Scale of ty
61        | PrincipleEvec of ty        | PrincipleEvec of ty
62          | EigenVecs2x2
63          | EigenVecs3x3
64          | EigenVals2x2
65          | EigenVals3x3
66        | Identity of int        | Identity of int
67        | Zero of ty        | Zero of ty
68          | Select of ty * int
69          | Index of ty * int
70        | Subscript of ty        | Subscript of ty
71        | Ceiling of int        | Ceiling of int
72        | Floor of int        | Floor of int
# Line 69  Line 82 
82        | Inside of ImageInfo.info * int        | Inside of ImageInfo.info * int
83        | Input of ty * string * string        | Input of ty * string * string
84        | InputWithDefault of ty * string * string        | InputWithDefault of ty * string * string
85          | Print of tys
86    
87        fun resultArity (Add _) = 1
88          | resultArity (Sub _) = 1
89          | resultArity (Mul _) = 1
90          | resultArity (Div _) = 1
91          | resultArity (Neg _) = 1
92          | resultArity (Abs _) = 1
93          | resultArity (LT _) = 1
94          | resultArity (LTE _) = 1
95          | resultArity (EQ _) = 1
96          | resultArity (NEQ _) = 1
97          | resultArity (GT _) = 1
98          | resultArity (GTE _) = 1
99          | resultArity Not = 1
100          | resultArity Max = 1
101          | resultArity Min = 1
102          | resultArity (Clamp _) = 1
103          | resultArity (Lerp _) = 1
104          | resultArity (Dot _) = 1
105          | resultArity (MulVecMat _) = 1
106          | resultArity (MulMatVec _) = 1
107          | resultArity (MulMatMat _) = 1
108          | resultArity Cross = 1
109          | resultArity (Norm _) = 1
110          | resultArity (Normalize _) = 1
111          | resultArity (Scale _) = 1
112          | resultArity (PrincipleEvec _) = 1
113          | resultArity EigenVecs2x2 = 1
114          | resultArity EigenVecs3x3 = 1
115          | resultArity EigenVals2x2 = 1
116          | resultArity EigenVals3x3 = 1
117          | resultArity (Identity _) = 1
118          | resultArity (Zero _) = 1
119          | resultArity (Select _) = 1
120          | resultArity (Index _) = 1
121          | resultArity (Subscript _) = 1
122          | resultArity (Ceiling _) = 1
123          | resultArity (Floor _) = 1
124          | resultArity (Round _) = 1
125          | resultArity (Trunc _) = 1
126          | resultArity IntToReal = 1
127          | resultArity (RealToInt _) = 1
128          | resultArity (ImageAddress _) = 1
129          | resultArity (LoadVoxels _) = 1
130          | resultArity (PosToImgSpace _) = 1
131          | resultArity (TensorToWorldSpace _) = 1
132          | resultArity (LoadImage _) = 1
133          | resultArity (Inside _) = 1
134          | resultArity (Input _) = 1
135          | resultArity (InputWithDefault _) = 1
136          | resultArity (Print _) = 0
137    
138      fun arity (Add _) = 2      fun arity (Add _) = 2
139        | arity (Sub _) = 2        | arity (Sub _) = 2
# Line 92  Line 157 
157        | arity (MulMatVec _) = 2        | arity (MulMatVec _) = 2
158        | arity (MulMatMat _) = 2        | arity (MulMatMat _) = 2
159        | arity Cross = 2        | arity Cross = 2
       | arity (Select _) = 1  
160        | arity (Norm _) = 1        | arity (Norm _) = 1
161        | arity (Normalize _) = 1        | arity (Normalize _) = 1
162        | arity (Scale _) = 2        | arity (Scale _) = 2
163        | arity (PrincipleEvec _) = 2        | arity (PrincipleEvec _) = 2
164          | arity EigenVecs2x2 = 1
165          | arity EigenVecs3x3 = 1
166          | arity EigenVals2x2 = 1
167          | arity EigenVals3x3 = 1
168        | arity (Identity _) = 0        | arity (Identity _) = 0
169        | arity (Zero _) = 0        | arity (Zero _) = 0
170          | arity (Select _) = 1
171          | arity (Index _) = 1
172        | arity (Subscript _) = 2        | arity (Subscript _) = 2
173        | arity (Ceiling _) = 1        | arity (Ceiling _) = 1
174        | arity (Floor _) = 1        | arity (Floor _) = 1
# Line 114  Line 184 
184        | arity (Inside _) = 2        | arity (Inside _) = 2
185        | arity (Input _) = 0        | arity (Input _) = 0
186        | arity (InputWithDefault _) = 1        | arity (InputWithDefault _) = 1
187          | arity (Print _) = ~1
188    
189      fun same (Add(a0), Add(b0)) = samety(a0, b0)      fun same (Add(a0), Add(b0)) = samety(a0, b0)
190        | same (Sub(a0), Sub(b0)) = samety(a0, b0)        | same (Sub(a0), Sub(b0)) = samety(a0, b0)
# Line 137  Line 208 
208        | same (MulMatVec(a0,a1), MulMatVec(b0,b1)) = sameint(a0, b0) andalso sameint(a1, b1)        | same (MulMatVec(a0,a1), MulMatVec(b0,b1)) = sameint(a0, b0) andalso sameint(a1, b1)
209        | same (MulMatMat(a0,a1,a2), MulMatMat(b0,b1,b2)) = sameint(a0, b0) andalso sameint(a1, b1) andalso sameint(a2, b2)        | same (MulMatMat(a0,a1,a2), MulMatMat(b0,b1,b2)) = sameint(a0, b0) andalso sameint(a1, b1) andalso sameint(a2, b2)
210        | same (Cross, Cross) = true        | same (Cross, Cross) = true
       | same (Select(a0,a1), Select(b0,b1)) = samety(a0, b0) andalso sameint(a1, b1)  
211        | same (Norm(a0), Norm(b0)) = samety(a0, b0)        | same (Norm(a0), Norm(b0)) = samety(a0, b0)
212        | same (Normalize(a0), Normalize(b0)) = sameint(a0, b0)        | same (Normalize(a0), Normalize(b0)) = sameint(a0, b0)
213        | same (Scale(a0), Scale(b0)) = samety(a0, b0)        | same (Scale(a0), Scale(b0)) = samety(a0, b0)
214        | same (PrincipleEvec(a0), PrincipleEvec(b0)) = samety(a0, b0)        | same (PrincipleEvec(a0), PrincipleEvec(b0)) = samety(a0, b0)
215          | same (EigenVecs2x2, EigenVecs2x2) = true
216          | same (EigenVecs3x3, EigenVecs3x3) = true
217          | same (EigenVals2x2, EigenVals2x2) = true
218          | same (EigenVals3x3, EigenVals3x3) = true
219        | same (Identity(a0), Identity(b0)) = sameint(a0, b0)        | same (Identity(a0), Identity(b0)) = sameint(a0, b0)
220        | same (Zero(a0), Zero(b0)) = samety(a0, b0)        | same (Zero(a0), Zero(b0)) = samety(a0, b0)
221          | same (Select(a0,a1), Select(b0,b1)) = samety(a0, b0) andalso sameint(a1, b1)
222          | same (Index(a0,a1), Index(b0,b1)) = samety(a0, b0) andalso sameint(a1, b1)
223        | same (Subscript(a0), Subscript(b0)) = samety(a0, b0)        | same (Subscript(a0), Subscript(b0)) = samety(a0, b0)
224        | same (Ceiling(a0), Ceiling(b0)) = sameint(a0, b0)        | same (Ceiling(a0), Ceiling(b0)) = sameint(a0, b0)
225        | same (Floor(a0), Floor(b0)) = sameint(a0, b0)        | same (Floor(a0), Floor(b0)) = sameint(a0, b0)
# Line 159  Line 235 
235        | same (Inside(a0,a1), Inside(b0,b1)) = ImageInfo.same(a0, b0) andalso sameint(a1, b1)        | same (Inside(a0,a1), Inside(b0,b1)) = ImageInfo.same(a0, b0) andalso sameint(a1, b1)
236        | same (Input(a0,a1,a2), Input(b0,b1,b2)) = samety(a0, b0) andalso samestring(a1, b1) andalso samestring(a2, b2)        | same (Input(a0,a1,a2), Input(b0,b1,b2)) = samety(a0, b0) andalso samestring(a1, b1) andalso samestring(a2, b2)
237        | same (InputWithDefault(a0,a1,a2), InputWithDefault(b0,b1,b2)) = samety(a0, b0) andalso samestring(a1, b1) andalso samestring(a2, b2)        | same (InputWithDefault(a0,a1,a2), InputWithDefault(b0,b1,b2)) = samety(a0, b0) andalso samestring(a1, b1) andalso samestring(a2, b2)
238          | same (Print(a0), Print(b0)) = sametys(a0, b0)
239        | same _ = false        | same _ = false
240    
241      fun hash (Add(a0)) = 0w3 + hashty a0      fun hash (Add(a0)) = 0w3 + hashty a0
# Line 183  Line 260 
260        | hash (MulMatVec(a0,a1)) = 0w73 + hashint a0 + hashint a1        | hash (MulMatVec(a0,a1)) = 0w73 + hashint a0 + hashint a1
261        | hash (MulMatMat(a0,a1,a2)) = 0w79 + hashint a0 + hashint a1 + hashint a2        | hash (MulMatMat(a0,a1,a2)) = 0w79 + hashint a0 + hashint a1 + hashint a2
262        | hash Cross = 0w83        | hash Cross = 0w83
263        | hash (Select(a0,a1)) = 0w89 + hashty a0 + hashint a1        | hash (Norm(a0)) = 0w89 + hashty a0
264        | hash (Norm(a0)) = 0w97 + hashty a0        | hash (Normalize(a0)) = 0w97 + hashint a0
265        | hash (Normalize(a0)) = 0w101 + hashint a0        | hash (Scale(a0)) = 0w101 + hashty a0
266        | hash (Scale(a0)) = 0w103 + hashty a0        | hash (PrincipleEvec(a0)) = 0w103 + hashty a0
267        | hash (PrincipleEvec(a0)) = 0w107 + hashty a0        | hash EigenVecs2x2 = 0w107
268        | hash (Identity(a0)) = 0w109 + hashint a0        | hash EigenVecs3x3 = 0w109
269        | hash (Zero(a0)) = 0w113 + hashty a0        | hash EigenVals2x2 = 0w113
270        | hash (Subscript(a0)) = 0w127 + hashty a0        | hash EigenVals3x3 = 0w127
271        | hash (Ceiling(a0)) = 0w131 + hashint a0        | hash (Identity(a0)) = 0w131 + hashint a0
272        | hash (Floor(a0)) = 0w137 + hashint a0        | hash (Zero(a0)) = 0w137 + hashty a0
273        | hash (Round(a0)) = 0w139 + hashint a0        | hash (Select(a0,a1)) = 0w139 + hashty a0 + hashint a1
274        | hash (Trunc(a0)) = 0w149 + hashint a0        | hash (Index(a0,a1)) = 0w149 + hashty a0 + hashint a1
275        | hash IntToReal = 0w151        | hash (Subscript(a0)) = 0w151 + hashty a0
276        | hash (RealToInt(a0)) = 0w157 + hashint a0        | hash (Ceiling(a0)) = 0w157 + hashint a0
277        | hash (ImageAddress(a0)) = 0w163 + ImageInfo.hash a0        | hash (Floor(a0)) = 0w163 + hashint a0
278        | hash (LoadVoxels(a0,a1)) = 0w167 + ImageInfo.hash a0 + hashint a1        | hash (Round(a0)) = 0w167 + hashint a0
279        | hash (PosToImgSpace(a0)) = 0w173 + ImageInfo.hash a0        | hash (Trunc(a0)) = 0w173 + hashint a0
280        | hash (TensorToWorldSpace(a0,a1)) = 0w179 + ImageInfo.hash a0 + hashty a1        | hash IntToReal = 0w179
281        | hash (LoadImage(a0)) = 0w181 + ImageInfo.hash a0        | hash (RealToInt(a0)) = 0w181 + hashint a0
282        | hash (Inside(a0,a1)) = 0w191 + ImageInfo.hash a0 + hashint a1        | hash (ImageAddress(a0)) = 0w191 + ImageInfo.hash a0
283        | hash (Input(a0,a1,a2)) = 0w193 + hashty a0 + hashstring a1 + hashstring a2        | hash (LoadVoxels(a0,a1)) = 0w193 + ImageInfo.hash a0 + hashint a1
284        | hash (InputWithDefault(a0,a1,a2)) = 0w197 + hashty a0 + hashstring a1 + hashstring a2        | hash (PosToImgSpace(a0)) = 0w197 + ImageInfo.hash a0
285          | hash (TensorToWorldSpace(a0,a1)) = 0w199 + ImageInfo.hash a0 + hashty a1
286          | hash (LoadImage(a0)) = 0w211 + ImageInfo.hash a0
287          | hash (Inside(a0,a1)) = 0w223 + ImageInfo.hash a0 + hashint a1
288          | hash (Input(a0,a1,a2)) = 0w227 + hashty a0 + hashstring a1 + hashstring a2
289          | hash (InputWithDefault(a0,a1,a2)) = 0w229 + hashty a0 + hashstring a1 + hashstring a2
290          | hash (Print(a0)) = 0w233 + hashtys a0
291    
292      fun toString (Add(a0)) = concat["Add<", tyToString a0, ">"]      fun toString (Add(a0)) = concat["Add<", tyToString a0, ">"]
293        | toString (Sub(a0)) = concat["Sub<", tyToString a0, ">"]        | toString (Sub(a0)) = concat["Sub<", tyToString a0, ">"]
# Line 228  Line 311 
311        | toString (MulMatVec(a0,a1)) = concat["MulMatVec<", intToString a0, ",", intToString a1, ">"]        | toString (MulMatVec(a0,a1)) = concat["MulMatVec<", intToString a0, ",", intToString a1, ">"]
312        | toString (MulMatMat(a0,a1,a2)) = concat["MulMatMat<", intToString a0, ",", intToString a1, ",", intToString a2, ">"]        | toString (MulMatMat(a0,a1,a2)) = concat["MulMatMat<", intToString a0, ",", intToString a1, ",", intToString a2, ">"]
313        | toString Cross = "Cross"        | toString Cross = "Cross"
       | toString (Select(a0,a1)) = concat["Select<", tyToString a0, ",", intToString a1, ">"]  
314        | toString (Norm(a0)) = concat["Norm<", tyToString a0, ">"]        | toString (Norm(a0)) = concat["Norm<", tyToString a0, ">"]
315        | toString (Normalize(a0)) = concat["Normalize<", intToString a0, ">"]        | toString (Normalize(a0)) = concat["Normalize<", intToString a0, ">"]
316        | toString (Scale(a0)) = concat["Scale<", tyToString a0, ">"]        | toString (Scale(a0)) = concat["Scale<", tyToString a0, ">"]
317        | toString (PrincipleEvec(a0)) = concat["PrincipleEvec<", tyToString a0, ">"]        | toString (PrincipleEvec(a0)) = concat["PrincipleEvec<", tyToString a0, ">"]
318          | toString EigenVecs2x2 = "EigenVecs2x2"
319          | toString EigenVecs3x3 = "EigenVecs3x3"
320          | toString EigenVals2x2 = "EigenVals2x2"
321          | toString EigenVals3x3 = "EigenVals3x3"
322        | toString (Identity(a0)) = concat["Identity<", intToString a0, ">"]        | toString (Identity(a0)) = concat["Identity<", intToString a0, ">"]
323        | toString (Zero(a0)) = concat["Zero<", tyToString a0, ">"]        | toString (Zero(a0)) = concat["Zero<", tyToString a0, ">"]
324          | toString (Select(a0,a1)) = concat["Select<", tyToString a0, ",", intToString a1, ">"]
325          | toString (Index(a0,a1)) = concat["Index<", tyToString a0, ",", intToString a1, ">"]
326        | toString (Subscript(a0)) = concat["Subscript<", tyToString a0, ">"]        | toString (Subscript(a0)) = concat["Subscript<", tyToString a0, ">"]
327        | toString (Ceiling(a0)) = concat["Ceiling<", intToString a0, ">"]        | toString (Ceiling(a0)) = concat["Ceiling<", intToString a0, ">"]
328        | toString (Floor(a0)) = concat["Floor<", intToString a0, ">"]        | toString (Floor(a0)) = concat["Floor<", intToString a0, ">"]
# Line 250  Line 338 
338        | toString (Inside(a0,a1)) = concat["Inside<", ImageInfo.toString a0, ",", intToString a1, ">"]        | toString (Inside(a0,a1)) = concat["Inside<", ImageInfo.toString a0, ",", intToString a1, ">"]
339        | toString (Input(a0,a1,a2)) = concat["Input<", tyToString a0, ",", stringToString a1, ",", stringToString a2, ">"]        | toString (Input(a0,a1,a2)) = concat["Input<", tyToString a0, ",", stringToString a1, ",", stringToString a2, ">"]
340        | toString (InputWithDefault(a0,a1,a2)) = concat["InputWithDefault<", tyToString a0, ",", stringToString a1, ",", stringToString a2, ">"]        | toString (InputWithDefault(a0,a1,a2)) = concat["InputWithDefault<", tyToString a0, ",", stringToString a1, ",", stringToString a2, ">"]
341          | toString (Print(a0)) = concat["Print<", tysToString a0, ">"]
342    
343    end    end
344    

Legend:
Removed from v.1444  
changed lines
  Added in v.1640

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