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 2681 - (download) (annotate)
Sun Aug 24 18:59:07 2014 UTC (5 years, 1 month ago) by cchiw
File size: 3663 byte(s)
cleanup tree-il exp/stmts
(* Get Types of Expressions *)

structure getTypes= struct

    structure Op = TreeOps
    structure Ty = TreeILTypes
    structure IL=TreeIL
    structure ILF=TreeFunc
    structure TySet=ILF.TySet
    structure OprSet=ILF.OprSet


    fun vecTy n= Ty.TensorTy[n]
    val testing=0
 

(*print Types*)
fun prnTy((t1,t2),prefix)=let

val typs=TySet.listItems(t1);
val ops=OprSet.listItems(t2);
val str1= List.map Ty.toString typs
val str2=List.map ILF.toString ops
val pnstr= String.concat["CCCC\n",prefix,"\n \t Types: ",String.concatWith "," str1,
"\n \t cFn: ",String.concatWith "\n\t" str2]

in pnstr end


  (* GetTypes TreeIL operator. *)
    val default=([],[])

    (*rator-> (types, cfns )*)
    fun TypeofOp rator = (case rator
        of  Op.IndexTensor(a,RTy,b,c)=>([RTy],[])
        (* Op.IndexTensor(a,RTy,b,c)=> ([RTy], [ILF.OP(Op.IndexTensor(a,RTy,b,c)))]*)
        | Op.addVec d               => ([vecTy d],[ILF.OP(Op.addVec d)])
        | Op.subVec d               => ([vecTy d],[ILF.OP(Op.subVec d)])
        | Op.prodVec d              => ([vecTy d],[ILF.OP(Op.prodVec d)])
        | Op.prodScaV d             => ([vecTy d],[ILF.CONSV d,ILF.OP(Op.prodScaV d)])
                    (*need different cons here*)
        | Op.sumVec d               => (([Ty.unionTy d],   [ILF.OP(Op.sumVec d)]))
        | Op.dotVec d               => ([Ty.vecTy d],   [ILF.OP(Op.dotVec d)]) (*check here*)
        | Op.Floor d                => ([vecTy d],[ILF.OP(Op.Floor d)])
        | Op.imgLoad(_,_,d)         => ([vecTy d],[ILF.CONS(vecTy d)])
        | _ => default
        (* end case *))



    (*fun peel(IL.E_Lit( offset))=offset*)

    fun mkFnC(IL.E_LoadArr(A,fTy, oTy,_, offset))=[ILF.LDArr(A,fTy,oTy)]
      | mkFnC(IL.E_Cons (ty , exps))= [ILF.CONS ty]
      | mkFnC e= []



    fun set(t,typ,cfn)= let
        val (ty1,opr1)=t
        val opr2=List.foldr (fn(e1,e2) =>OprSet.add(e2,e1)) opr1 cfn
        val ty2=List.foldr (fn(e1,e2) =>TySet.add(e2,e1)) ty1 typ
        in
            (ty2,opr2)
        end 

    (*Get types of Exp*)
    fun typeOfExp(t,exp)=let

        fun add(([],[]),rest)= List.foldr (fn(e1,e2) => typeOfExp(e2,e1)) t rest
        | add((typ,cfn),rest)= let
            val t2=set(t,typ, cfn)

            in
                List.foldr (fn(e1,e2) => typeOfExp(e2,e1)) t2 rest
            end
        in (case exp
            of IL.E_State(state_var)    => t
            | IL.E_Var(var)             => t
            | IL.E_Lit _                => t
            | IL.E_Apply (_, exps)      => add(default,exps)
            | IL.E_Cons (ty , exps)     => add(([ty],mkFnC exp),exps)
            | IL.E_LoadArr(_,ty,_,exps,_) => add(([vecTy ty],mkFnC exp),[exps])
            | IL.E_Op(Op, exps)         => add(TypeofOp Op, exps)
            | IL.E_tmp _                => t
            (*end case*))
        end

    fun typeOfStmt(t,stmt)=(case stmt
        of  IL.S_Assign (_,exp)=> typeOfExp(t,exp)
        | IL.S_StoreVec(_,A,rTy,oTy,_,Ty.vectorLength pieces,exps,toType) => let
            val typ=[vecTy oTy,Ty.unionTy oTy]
            val fnc=List.map (fn p => ILF.STORE (A,p,oTy,toType)) pieces
            val t2=set(t,typ, fnc)
            in
                List.foldr (fn(e1,e2) => typeOfExp(e2,e1)) t2 exps
            end 

            (*end case*))




    fun prnTyFinal(typs,ops,prefix)=let 
        val str1= List.map Ty.toString typs
        val str2=List.map ILF.toString ops
        val pnstr= String.concat["DDDD\n",prefix,"\n \t Types: ",String.concatWith "," str1,
            "\n \t cFn: ",String.concatWith "\n\t" str2]
        in pnstr end



    fun getTypesFiltered(t,stmt)=typeOfStmt(t,stmt)


end

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