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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 197 - (download) (annotate)
Mon Aug 2 20:51:47 2010 UTC (9 years, 2 months ago) by jhr
File size: 8046 byte(s)
  Working on translation to HighIL
(* high-il.sml
 *
 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
 * All rights reserved.
 *
 * High-level version of the Diderot IL.
 *
 * Note: this file is generated from gen/high-il.spec and gen/high-il.in.
 *)

structure HighOps =
  struct

    datatype ty = BoolTy | StringTy | IntTy | TensorTy of int list

    fun samety (ty1 : ty, ty2) = (ty1 = ty2)
    fun hashty BoolTy = 0w1
      | hashty StringTy = 0w2
      | hashty IntTy = 0w3
      | hashty (TensorTy dd) = List.foldl (fn (d, s) => Word.fromInt d + s) 0w4 dd
    fun tyToString BoolTy = "bool"
      | tyToString StringTy = "string"
      | tyToString IntTy = "int"
      | tyToString (TensorTy dd) = String.concat[
	    "tensor[", String.concatWith "," (List.map Int.toString dd), "]"
	  ]

    datatype rator
      = Add of ty
      | Sub of ty
      | 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
      | Scale of ty
      | InvScale of ty
      | CL
      | PrincipleEvec of ty
      | Subscript of ty
      | Max
      | Min
      | Sin
      | Cos
      | Pow
      | Not
      | IntToReal
      | TruncToInt
      | RoundToInt
      | CeilToInt
      | FloorToInt
      | Kernel of Kernel.kernel
      | LoadImage of ImageInfo.info
      | Convolve
      | Inside
      | Field of FieldDef.field_def
      | AddField
      | ScaleField
      | NegField
      | DiffField
      | Probe
      | Transform of ImageInfo.info

    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 (InvScale _) = 2
      | arity CL = 1
      | arity (PrincipleEvec _) = 2
      | arity (Subscript _) = 2
      | arity Max = 2
      | arity Min = 2
      | 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 (Kernel _) = 0
      | arity (LoadImage _) = 1
      | arity Convolve = 2
      | arity Inside = 2
      | arity (Field _) = 0
      | arity AddField = 2
      | arity ScaleField = 2
      | arity NegField = 1
      | arity DiffField = 1
      | arity Probe = 2
      | arity (Transform _) = 1

    fun same (Add a, Add b) = samety(a, b)
      | same (Sub a, Sub b) = samety(a, b)
      | same (Mul a, Mul b) = samety(a, b)
      | same (Div a, Div b) = samety(a, b)
      | same (Neg a, Neg b) = samety(a, b)
      | same (LT a, LT b) = samety(a, b)
      | same (LTE a, LTE b) = samety(a, b)
      | same (EQ a, EQ b) = samety(a, b)
      | same (NEQ a, NEQ b) = samety(a, b)
      | same (GT a, GT b) = samety(a, b)
      | same (GTE a, GTE b) = samety(a, b)
      | same (Dot a, Dot b) = samety(a, b)
      | same (Cross, Cross) = true
      | same (Norm a, Norm b) = samety(a, b)
      | same (Scale a, Scale b) = samety(a, b)
      | same (InvScale a, InvScale b) = samety(a, b)
      | same (CL, CL) = true
      | same (PrincipleEvec a, PrincipleEvec b) = samety(a, b)
      | same (Subscript a, Subscript b) = samety(a, b)
      | 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 (Kernel a, Kernel b) = Kernel.same(a, b)
      | same (LoadImage a, LoadImage b) = ImageInfo.same(a, b)
      | same (Convolve, Convolve) = true
      | same (Inside, Inside) = true
      | same (Field a, Field b) = FieldDef.same(a, b)
      | same (AddField, AddField) = true
      | same (ScaleField, ScaleField) = true
      | same (NegField, NegField) = true
      | same (DiffField, DiffField) = true
      | same (Probe, Probe) = true
      | same (Transform a, Transform b) = ImageInfo.same(a, b)
      | same _ = false

    fun hash (Add a) = 0w3 + hashty a
      | hash (Sub a) = 0w5 + hashty a
      | hash (Mul a) = 0w7 + hashty a
      | hash (Div a) = 0w11 + hashty a
      | hash (Neg a) = 0w13 + hashty a
      | hash (LT a) = 0w17 + hashty a
      | hash (LTE a) = 0w19 + hashty a
      | hash (EQ a) = 0w23 + hashty a
      | hash (NEQ a) = 0w29 + hashty a
      | hash (GT a) = 0w31 + hashty a
      | hash (GTE a) = 0w37 + hashty a
      | hash (Dot a) = 0w41 + hashty a
      | hash Cross = 0w43
      | hash (Norm a) = 0w47 + hashty a
      | hash (Scale a) = 0w53 + hashty a
      | hash (InvScale a) = 0w59 + hashty a
      | hash CL = 0w61
      | hash (PrincipleEvec a) = 0w67 + hashty a
      | hash (Subscript a) = 0w71 + hashty a
      | hash Max = 0w73
      | hash Min = 0w79
      | hash Sin = 0w83
      | hash Cos = 0w89
      | hash Pow = 0w97
      | hash Not = 0w101
      | hash IntToReal = 0w103
      | hash TruncToInt = 0w107
      | hash RoundToInt = 0w109
      | hash CeilToInt = 0w113
      | hash FloorToInt = 0w127
      | hash (Kernel a) = 0w131 + Kernel.hash a
      | hash (LoadImage a) = 0w137 + ImageInfo.hash a
      | hash Convolve = 0w139
      | hash Inside = 0w149
      | hash (Field a) = 0w151 + FieldDef.hash a
      | hash AddField = 0w157
      | hash ScaleField = 0w163
      | hash NegField = 0w167
      | hash DiffField = 0w173
      | hash Probe = 0w179
      | hash (Transform a) = 0w181 + ImageInfo.hash a

    fun toString (Add a) = concat["Add(", tyToString a, ")"]
      | toString (Sub a) = concat["Sub(", tyToString a, ")"]
      | toString (Mul a) = concat["Mul(", tyToString a, ")"]
      | toString (Div a) = concat["Div(", tyToString a, ")"]
      | toString (Neg a) = concat["Neg(", tyToString a, ")"]
      | toString (LT a) = concat["LT(", tyToString a, ")"]
      | toString (LTE a) = concat["LTE(", tyToString a, ")"]
      | toString (EQ a) = concat["EQ(", tyToString a, ")"]
      | toString (NEQ a) = concat["NEQ(", tyToString a, ")"]
      | toString (GT a) = concat["GT(", tyToString a, ")"]
      | toString (GTE a) = concat["GTE(", tyToString a, ")"]
      | toString (Dot a) = concat["Dot(", tyToString a, ")"]
      | toString Cross = "Cross"
      | toString (Norm a) = concat["Norm(", tyToString a, ")"]
      | toString (Scale a) = concat["Scale(", tyToString a, ")"]
      | toString (InvScale a) = concat["InvScale(", tyToString a, ")"]
      | toString CL = "CL"
      | toString (PrincipleEvec a) = concat["PrincipleEvec(", tyToString a, ")"]
      | toString (Subscript a) = concat["Subscript(", tyToString a, ")"]
      | toString Max = "Max"
      | toString Min = "Min"
      | toString Sin = "Sin"
      | toString Cos = "Cos"
      | toString Pow = "Pow"
      | toString Not = "Not"
      | toString IntToReal = "IntToReal"
      | toString TruncToInt = "TruncToInt"
      | toString RoundToInt = "RoundToInt"
      | toString CeilToInt = "CeilToInt"
      | toString FloorToInt = "FloorToInt"
      | toString (Kernel a) = concat["Kernel(", Kernel.toString a, ")"]
      | toString (LoadImage a) = concat["LoadImage(", ImageInfo.toString a, ")"]
      | toString Convolve = "Convolve"
      | toString Inside = "Inside"
      | toString (Field a) = concat["Field(", FieldDef.toString a, ")"]
      | toString AddField = "AddField"
      | toString ScaleField = "ScaleField"
      | toString NegField = "NegField"
      | toString DiffField = "DiffField"
      | toString Probe = "Probe"
      | toString (Transform a) = concat["Transform(", ImageInfo.toString a, ")"]

  end

structure HighIL = SSAFn(HighOps)

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