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 2637 - (download) (annotate)
Wed May 28 05:20:45 2014 UTC (5 years, 4 months ago) by cchiw
File size: 3640 byte(s)
add Types and oprators as sets in tree-il
(* Get Types of Expressions *)

structure getTypes= struct

    structure Op = TreeOps
    structure Ty = TreeILTypes
    structure IL=TreeIL
    structure setTyfn=TreeFunc
 

    structure  TySet=setTyfn.TySet
    structure  OprSet=setTyfn.OprSet

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

  (* GetTypes TreeIL operator. *)
    val default=(NONE,NONE)
    fun m(e1,e2)=(SOME e1, SOME e2)
    fun TypeofOp rator = (case rator
        of  Op.IndexTensor(a,RTy,b,c)=> (SOME RTy,NONE)
        (* Op.IndexTensor(a,RTy,b,c)=> m(RTy,setTyfn.OP(Op.IndexTensor(a,RTy,b,c)))*)
        | Op.addVec d               => m(vecTy d,setTyfn.OP(Op.addVec d))
        | Op.subVec d               => m(vecTy d,setTyfn.OP(Op.subVec d))
        | Op.prodVec d              => m(vecTy d,setTyfn.OP(Op.prodVec d))
        | Op.prodScaV d             => m(vecTy d,setTyfn.OP(Op.prodScaV d))
        | _ => default
        (* end case *))



    fun peel(IL.E_Lit( offset))=offset
    fun mkFnC(IL.E_LoadVec(fTy, oTy,_, offset))=setTyfn.LD(fTy,oTy,peel offset)
      | mkFnC(IL.E_mkVec(_,oTy,_,_))= setTyfn.MKVEC oTy
      | mkFnC(IL.E_Cons (ty , exps))= setTyfn.CONS ty 
      | mkFnC(IL.E_FillVec(fTy, oTy,_, offset))= setTyfn.FVEC(fTy,oTy)
      | mkFnC(IL.E_SliceVec(fTy, oTy,_, offset))=setTyfn.SVEC(fTy)


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

        fun add((NONE,NONE),rest)=List.foldr (fn(e1,e2) => typeOfExp(e2,e1)) t rest
          | add((SOME typ,NONE),rest)= let
            val (ty1,opr1)=t
            val t2=(TySet.add(ty1,typ),opr1)
            in
                List.foldr (fn(e1,e2) => typeOfExp(e2,e1)) t2 rest
            end
        | add((SOME typ,SOME cfn),rest)= let
            val (ty1,opr1)=t
            val t2=(TySet.add(ty1,typ),OprSet.add(opr1, 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(m(ty,mkFnC exp),exps)
            | IL.E_LoadVec(ty,_,exps,_)  => add(m(vecTy ty,mkFnC exp),[exps])
            | IL.E_mkVec(_,ty,_,exps)   => add(m(vecTy ty,mkFnC exp), exps)
            | IL.E_Op(Op, exps)         => add(TypeofOp Op, exps)
            | IL.E_FillVec(ty,_,exps,_)  => add(m(vecTy ty,mkFnC exp),[exps])
            | IL.E_SliceVec(ty,_,exps,_) => add(m(vecTy ty,mkFnC exp),[exps])


            (*end case*))
        end 


    (*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 setTyfn.toString ops
        val pnstr= String.concat["\n",prefix,"\n \t Types: ",String.concatWith "," str1,
            "\n \t cFn: ",String.concatWith "\n\t" str2]
   
        in pnstr end

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



    fun getTypesFiltered(t,IL.S_Assign (_,exp))= let
        val t2=typeOfExp(t,exp)
        val _=(case testing
            of 1=> (print(String.concat["\n ---",IL.toString exp,prnTy(t2,"Current")]);1)
            | _=>1
            (*end case*))

        in t2
        end
      | getTypesFiltered(t, _)= t



end

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