Home My Page Projects Code Snippets Project Openings diderot

# SCM Repository

[diderot] View of /trunk/src/compiler/IL/high-il.sml
 [diderot] / trunk / src / compiler / IL / high-il.sml

# View of /trunk/src/compiler/IL/high-il.sml

Wed Jul 21 15:21:12 2010 UTC (11 years, 2 months ago) by jhr
File size: 4096 byte(s)
```  New file
```
```(* high-il.sml
*
* COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
*
* High-level version of the Diderot IL.
*)

structure HighOps =
struct

type ty = 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
| Dot of ty | Cross | Norm of ty		(* vector operations *)
| Scale of ty				(* scalar/tensor multiplication *)
| CL					(* linear anisotropy measure *)
| PrincipleEvec				(* principle eigenvector *)
| Subscript of ty
| Max | Min
| Sin | Cos
| Pow
(* conversions *)
| IntToReal
| TruncToInt
| RoundToInt
| CeilToInt
| FloorToInt
(* image/field operations *)
| 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 (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 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

| 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 (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 (IntToReal, IntToReal) = true
| same (TruncToInt, TruncToInt) = true
| same (RoundToInt, RoundToInt) = true
| same (CeilToInt, CeilToInt) = true
| same (FloorToInt, FloorToInt) = true
| 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)
```