(* high-il.sml * * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu) * All rights reserved. * * High-level version of the Diderot IL. *) structure HighOps = struct type ty = BoolTy | StringTy | IntTy | TensorTy of int list fun sameTy (ty1 : ty, ty2) = (ty1 = ty2) datatype rator = Add of ty | Sub of ty (* type-indexed arithmetic operations *) | Mul of ty | Div of ty | Neg of ty | LT of ty | LTE of ty | EQ of ty | NEQ of ty | GT of ty | GTE of ty | Dot of ty | Cross | Norm of ty (* vector operations *) | Scale of ty (* scalar*tensor multiplication *) | InvScale of ty (* tensor/scalar division *) | CL (* linear anisotropy measure *) | PrincipleEvec (* principle eigenvector *) | Subscript of ty | Max | Min | Sin | Cos | Pow | Not (* boolean negation *) (* conversions *) | IntToReal | TruncToInt | RoundToInt | CeilToInt | FloorToInt (* image/field operations *) | LoadImage of ImageInfo.info (* image-file loading *) | Inside | Field of FieldDef.field_def | Probe | Transform of ImageInfo.info (* transform to image-space *) fun arity (Add _) = 2 | arity (Sub _) = 2 | arity (Mul _) = 2 | arity (Div _) = 2 | arity (Neg _) = 1 | arity (LT _) = 2 | arity (LTE _) = 2 | arity (EQ _) = 2 | arity (NEQ _) = 2 | arity (GT _) = 2 | arity (GTE _) = 2 | arity (Dot _) = 2 | arity Cross = 2 | arity (Norm _) = 1 | arity (Scale _) = 2 | arity CL = 2 | arity PrincipleEvec = 1 | arity (Subscript _) = 2 | arity Max = 1 | arity Min = 1 | arity Sin = 1 | arity Cos = 1 | arity Pow = 2 | arity Not = 1 | arity IntToReal = 1 | arity TruncToInt = 1 | arity RoundToInt = 1 | arity CeilToInt = 1 | arity FloorToInt = 1 | arity (LoadImage _) = 1 | arity Inside = 2 | arity (Field _) = 0 | arity Probe = 2 | arity (Transform _) = 1 fun same (Add ty1, Add ty2) = sameTy(ty1, ty2) | same (Sub ty1, Sub ty2) = sameTy(ty1, ty2) | same (Mul ty1, Mul ty2) = sameTy(ty1, ty2) | same (Div ty1, Div ty2) = sameTy(ty1, ty2) | same (Neg ty1, Neg ty2) = sameTy(ty1, ty2) | same (LT ty1, LT ty2) = sameTy(ty1, ty2) | same (LTE ty1, LTE ty2) = sameTy(ty1, ty2) | same (EQ ty1, EQ ty2) = sameTy(ty1, ty2) | same (NEQ ty1, NEQ ty2) = sameTy(ty1, ty2) | same (GT ty1, GT ty2) = sameTy(ty1, ty2) | same (GTE ty1, GTE ty2) = sameTy(ty1, ty2) | same (Dot ty1, Dot ty2) = sameTy(ty1, ty2) | same (Cross, Cross) = true | same (Norm ty1, Norm ty2) = sameTy(ty1, ty2) | same (Scale ty1, Scale ty2) = sameTy(ty1, ty2) | same (CL, CL) = true | same (PrincipleEvec, PrincipleEvec) = true | same (Subscript ty1, Subscript ty2) = sameTy(ty1, ty2) | same (Max, Max) = true | same (Min, Min) = true | same (Sin, Sin) = true | same (Cos, Cos) = true | same (Pow, Pow) = true | same (Not, Not) = true | same (IntToReal, IntToReal) = true | same (TruncToInt, TruncToInt) = true | same (RoundToInt, RoundToInt) = true | same (CeilToInt, CeilToInt) = true | same (FloorToInt, FloorToInt) = true | same (LoadImage img1, LoadImage img2) = ImageInfo.same(img1, img2) | same (Inside, Inside) = true | same (Field fld1, Field fld2) = FieldDef.same(fld1, fld2) | same (Probe, Probe) = true | same (Transform img1, Transform img2) = ImageInfo.same(img1, img2) | same _ = false fun hash (Add ty) = 0w11 + hashTy ty | hash (Sub ty) = 0w13 + hashTy ty | hash (Mul ty) = 0w17 + hashTy ty | hash (Div ty) = 0w19 + hashTy ty | hash (Neg ty) = 0w23 + hashTy ty | hash (Dot ty) = 0w29 + hashTy ty | hash Cross = 0w31 | hash (Norm ty) = 0w37 + hashTy ty | hash (Scale ty) = 0w41 + hashTy ty | hash CL = 0w43 | hash PrincipleEvec = 0w47 | hash (Subscript ty) = 0w53 + hashTy ty | hash Max = 0w59 | hash Min = 0w61 | hash Sin = 0w67 | hash Cos = 0w71 | hash Pow = 0w73 | hash IntToReal = 0w79 | hash TruncToInt = 0w83 | hash RoundToInt = 0w89 | hash CeilToInt = 0w97 | hash FloorToInt = 0w101 | hash (LoadImage img) = 0w103 + ImageInfo.hash img | hash Inside = 0w107 | hash (Field fld) = 0w109 + FieldDef.hash fld | hash Probe = 0w113 | hash (Transform img) = 0w127 + ImageInfo.hash img val toString : rator -> string end structure HighIL = SSAFn(HighOps)