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

SCM Repository

[diderot] View of /branches/charisee/src/compiler/tree-il/getTypes.sml
ViewVC logotype

View of /branches/charisee/src/compiler/tree-il/getTypes.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2631 - (download) (annotate)
Fri May 23 18:13:12 2014 UTC (5 years, 2 months ago) by cchiw
File size: 4755 byte(s)
cFn added
(* Get Types of Expressions *)

structure getTypes= struct

    structure Op = TreeOps
    structure Ty = TreeILTypes
    structure IL=TreeIL
    structure TS=tString


    (* utility function for synthesizing eigenvector/eigenvalue signature *)
    fun eigenSig dim = let
        val tplTy = Ty.TupleTy[
        Ty.SeqTy(Ty.realTy, dim),
        Ty.SeqTy(Ty.vecTy dim, dim)]
        in
            tplTy
        end


    val intTy=Ty.intTy
    val realTy=Ty.TensorTy[]
    val boolTy=Ty.BoolTy
    fun vecTy n=Ty.TensorTy[n]


  (* GetTypes TreeIL operator. *)
    fun TypeofOp rator = (case rator
           of  Op.IAdd  => intTy
            | Op.ISub => intTy
            | Op.IMul  => intTy
            | Op.IDiv => intTy
            | Op.INeg  =>intTy
            | Op.IndexTensor(_,resultTy,_,argTy)=> resultTy
            | Op.addSca => realTy
            | Op.subSca => realTy
            | Op.prodSca => realTy
            | Op.divSca => realTy
            | Op.addVec d=> vecTy d
            | Op.subVec d => vecTy d
            | Op.prodVec d => vecTy d
            | Op.prodScaV d =>vecTy d
            | Op.sumVec _=> realTy
            | Op.Abs ty => ty
            | Op.LT _ => boolTy
            | Op.LTE _ => boolTy
            | Op.EQ _ => boolTy
            | Op.NEQ _ => boolTy
            | Op.GT _ => boolTy
            | Op.GTE _ => boolTy
            | Op.Not => boolTy
            | Op.Max => realTy
            | Op.Min => realTy
            | Op.Clamp ty => ty
            | Op.Lerp ty => ty
            | Op.Norm(ty as Ty.TensorTy _) =>realTy
            | Op.Normalize d => vecTy d
            | Op.EigenVecs2x2 => eigenSig 2
            | Op.EigenVecs3x3 => eigenSig 3
            | Op.EigenVals2x2 => Ty.SeqTy(Ty.realTy, 2)
            | Op.EigenVals3x3 => Ty.SeqTy(Ty.realTy, 3)
            | Op.Zero ty => ty
            | Op.Select(ty as Ty.TupleTy tys, i) => List.nth(tys, i-1)
            | Op.Index(ty as Ty.TensorTy[d], _) => realTy
            | Op.Index(ty as Ty.SeqTy(elemTy, _), _) => elemTy
            | Op.Subscript(ty as Ty.TensorTy dd) => realTy
            | Op.Subscript(ty as Ty.SeqTy(elemTy, d)) => elemTy
            | Op.Ceiling d => vecTy d
            | Op.Floor d => vecTy d
            | Op.Round d => vecTy d
            | Op.Trunc d => vecTy d
            | Op.IntToReal => realTy
            | Op.RealToInt 1 => intTy
            | Op.RealToInt d => Ty.SeqTy(Ty.IntTy, d)
            | Op.Transform info => let
                val dim = ImageInfo.dim info
                in  Ty.TensorTy[dim,dim]
                end
            | Op.Translate info  => let
                val dim = ImageInfo.dim info
                in Ty.TensorTy[dim,dim]
                end
            | Op.Kernel _ => Ty.KernelTy
            | Op.ImageAddress info => Ty.AddrTy info
            | Op.LoadVoxels(_, n) =>  vecTy n
            | Op.LoadImage info =>  Ty.ImageTy info
            | Op.Inside _ => boolTy
            | Op.Print _ => Ty.TupleTy[]
            | Op.imgAddr _=> intTy
            | Op.imgLoad (_,_,j) => vecTy j
            | _ => raise Fail("getTypes: In tree-IL Does not have: invalid operator " ^ Op.toString rator)
          (* end case *))


    fun flat [] = []
      | flat (l::ls) = l @ flat ls;

    fun typeOfExp exp=(case exp
       of (IL.E_State(state_var))=>[]
      | IL.E_Var(var)=> []
      | IL.E_Lit _ =>[]
      | IL.E_Op(Op, exp) => [TypeofOp  Op]@ (flat(List.map typeOfExp exp))
      | IL.E_Apply (_, exp)=> flat(List.map typeOfExp exp)
      | IL.E_Cons (ty , exp)=> [ty]@(flat(List.map typeOfExp exp))
      | IL.E_LoadVec(fullTy, _,_,exp)=>[vecTy fullTy]@(typeOfExp exp)
      | IL.E_mkVec(_,ty,_,exp)=>  [vecTy ty]@(flat(List.map typeOfExp exp))
        (*end case*))


    (*Filter Types, Just one of each *)
    fun m([],rest)=rest
      | m (e1::es, rest)=(case (List.find(fn x=> Ty.same(x,e1)) rest)
        of NONE=> m (es, rest@[e1])
        | _ => m (es, rest)
        (*end case*))


    fun getTypesFilteredPnt(IL.S_Assign (_,exp))= let

        val types=typeOfExp exp
        val types2=m (types,[])
        val str2= List.map Ty.toString types2
        val pnstr2= print(String.concat["\n ---",TS.toStringEx exp ,"\n \t Types: ",String.concatWith "," str2])
        in types2
        end
      | getTypesFilteredPnt _= []


    fun getTypesFiltered(IL.S_Assign (_,exp))= let

        val types=typeOfExp exp
        in m (types,[])
        end
    | getTypesFiltered _= []




fun gotFiltered []= (print(String.concat["\n \t No Types"]);1)
   |gotFiltered types= let
    val types2=m (types,[])
    val str2= List.map Ty.toString types2
    val pnstr2= print(String.concat["\n \t Final Types: ",String.concatWith "," str2,"\n\n "])
    in 1
    end





end

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