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/expandOp.sml
ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2628 - (download) (annotate)
Wed May 21 04:02:06 2014 UTC (5 years, 4 months ago) by cchiw
File size: 5344 byte(s)
scan for types
(*This function transitions low-il operators to tree-il operators *)
structure ExpOp = struct
local

    structure SrcOp = LowOps
    structure DstOp = TreeOps
    structure SrcTy = LowILTypes
    structure DstTy = TreeILTypes
    structure T = TreeIL
    structure P= TreeILPP
    structure Var = T.Var
in

    val testing=0

    fun q m=Int.toString(m)

    fun toStringEx(T.E_LoadVec(tyNew, tyOrig,offset,arg))=
        String.concat["LDVec:", q tyNew ,"|",q  tyOrig,Int.toString(offset),"(",toStringEx arg,")"]
      | toStringEx(T.E_mkVec(tyNew, tyOrig,pieces,args)) =let
        val a=String.concatWith "," (List.map toStringEx args)
        in
                String.concat["mkVec:",q tyNew,"|",
                q tyOrig,"[", DstTy.toString pieces ,"]\n\t",a]
        end
      | toStringEx(T.E_Op(rator, args)) =
        String.concat[DstOp.toString rator,"(", String.concatWith"," (List.map toStringEx args),")"]
      | toStringEx(T.E_Cons(ty, args)) =
        String.concat ["Cons:", DstTy.toString ty, "(",String.concatWith"," (List.map toStringEx args),")"]
      | toStringEx(T.E_State x) = "State"
      | toStringEx (T.E_Var x) = Var.name x
      | toStringEx (T.E_Lit lit) = Literal.toString lit




    (*Low-IL vector operators to Tree-IL Assignmentss*)
    fun creatLd(lhs,rator,n,origLength,pieces,args)= let
        val newTy=n
        val origTy= origLength
        val splitTy=DstTy.vectorLength pieces
      
        fun createOps([],_,code)=code
          | createOps(vn::es,offset, code)=let
            val vnTy= vn
            val args'=List.map (fn A=>T.E_LoadVec(vnTy,origTy,offset,A)) args
            val exp=T.E_Op(rator vn,args')
            in
                createOps (es,offset+vn,code@[exp])
            end
        val code=createOps(pieces,0,[])
        val exp=T.E_mkVec(newTy,origTy,splitTy,code)
        val _=(case testing
            of 1=>(print((toStringEx exp)^"\n\n");1)
            |_ =>1)
        in
            [T.S_Assign([lhs],exp)]
        end


    (*Convert Types*)
    (*fun cvtTy SrcTy.BoolTy = DstTy.BoolTy
      | cvtTy SrcTy.StringTy = DstTy.StringTy
      | cvtTy SrcTy.IntTy = DstTy.intTy
      | cvtTy (SrcTy.TensorTy dd) = DstTy.tensorTy dd
      | cvtTy (SrcTy.TupleTy tys) = DstTy.TupleTy(List.map cvtTy tys)
      | cvtTy (SrcTy.SeqTy(ty, n)) = DstTy.SeqTy(cvtTy ty, n)
      | cvtTy (SrcTy.AddrTy v) = DstTy.AddrTy v
      | cvtTy (SrcTy.ImageTy  v) = DstTy.ImageTy v
      | cvtTy SrcTy.KernelTy = DstTy.KernelTy
      | cvtTy (SrcTy.indexTy indexAt) = DstTy.indexTy indexAt
      | cvtTy (SrcTy.imgIndex indexAt) = DstTy.imgIndex indexAt
      | cvtTy (SrcTy.vectorLength pieces) = DstTy.vectorLength pieces


*)


    (*Low-IL operators to Tree-IL operators*)
    fun expandOp rator=(case rator
        of SrcOp.IAdd  =>    DstOp.IAdd
        | SrcOp.ISub  =>    DstOp.ISub
        | SrcOp.IMul  =>    DstOp.IMul
        | SrcOp.IDiv  =>    DstOp.IDiv
        | SrcOp.INeg  =>    DstOp.INeg
        | SrcOp.Abs ty =>    DstOp.Abs ty
        | SrcOp.LT ty =>    DstOp.LT  ty
        | SrcOp.LTE ty =>    DstOp.LTE  ty
        | SrcOp.EQ ty =>    DstOp.EQ  ty
        | SrcOp.NEQ ty =>    DstOp.NEQ  ty
        | SrcOp.GT ty =>    DstOp.GT  ty
        | SrcOp.GTE ty =>    DstOp.GTE  ty
        | SrcOp.Not =>    DstOp.Not 
        | SrcOp.Max =>    DstOp.Max 
        | SrcOp.Min =>    DstOp.Min 
        | SrcOp.Clamp ty =>    DstOp.Clamp ty
        | SrcOp.Lerp ty =>    DstOp.Lerp  ty
        | SrcOp.Norm ty =>    DstOp.Norm  ty
        | SrcOp.Normalize d =>    DstOp.Normalize d
        | SrcOp.Zero ty =>    DstOp.Zero  ty
        | SrcOp.PrincipleEvec ty =>    DstOp.PrincipleEvec ty
        | SrcOp.EigenVals2x2 =>    DstOp.EigenVals2x2 
        | SrcOp.EigenVals3x3 =>    DstOp.EigenVals3x3 
        | SrcOp.Select(ty as SrcTy.TupleTy tys, i)  =>    DstOp.Select( ty, i)
        | SrcOp.Index (ty, i ) =>    DstOp.Index ( ty, i)
        | SrcOp.Subscript ty =>    DstOp.Subscript  ty
        | SrcOp.Ceiling d =>    DstOp.Ceiling d 
        | SrcOp.Floor d =>    DstOp.Floor d 
        | SrcOp.Round d =>    DstOp.Round d
        | SrcOp.Trunc d =>    DstOp.Trunc d 
        | SrcOp.IntToReal =>    DstOp.IntToReal 
        | SrcOp.RealToInt d =>    DstOp.RealToInt d 
        (*| SrcOp.VoxelAddress( info, offset)  => expandVoxelAddress  (y, info, offset, args')
        | SrcOp.LoadVoxels (rty, d ) =>    DstOp.LoadVoxels( rty, d)*)
        | SrcOp.Kernel h =>    DstOp.Kernel h 
        | SrcOp.LoadImage info =>    DstOp.LoadImage info 
        | SrcOp.Inside info =>    DstOp.Inside info 
        | SrcOp.Transform V=>    DstOp.Transform V 
        | SrcOp.Translate V=>  DstOp.Translate V
        | SrcOp.addSca =>DstOp.addSca
        | SrcOp.subSca=>DstOp.subSca
        | SrcOp.prodSca=>DstOp.prodSca
        | SrcOp.divSca=>DstOp.divSca

        (*Still need to sort *)
        | SrcOp.V(id,length,indexAt,shape)=> DstOp.V(id,length,indexAt,shape)
        | SrcOp.S(id,indexAt,shape)=>DstOp.S(id,indexAt,shape)
        | SrcOp.imgAddr(v,indexAt, dim)=>DstOp.imgAddr(v, indexAt, dim)
        | SrcOp.imgLoad(v,dim,n)=>DstOp.imgLoad(v,dim,n)
     
        (*EigenVecs,mkDynamic, Append,Prepend, Concat,Length,ImageAddress,LoadVoxel,Inputs, and Pritns*)
        | rator => raise Fail ("bogus operator " ^ SrcOp.toString rator)
  (* end case *))
end;
end

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