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 2670 - (download) (annotate)
Wed Jul 9 21:54:54 2014 UTC (5 years, 3 months ago) by cchiw
File size: 3328 byte(s)
 
(* 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
 

  (* 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)])
        | _ => default
        (* end case *))



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

    fun mkFnC(IL.E_LoadVec(A,fTy, oTy,_, offset))=[ILF.LD(A,fTy,oTy)]
      | mkFnC(IL.E_mkVec(A,rTy,oTy,_,_,_))= [ILF.MKVEC(A,rTy,oTy)]
      | mkFnC(IL.E_Cons (ty , exps))= [ILF.CONS ty]
      | mkFnC e= []



    (*Get types of Exp*)
    fun typeOfExp(t,exp)=let
        val (ty1,opr1)=t
        fun add(([],[]),rest)= List.foldr (fn(e1,e2) => typeOfExp(e2,e1)) t rest
        | add((typ,cfn),rest)= let
     
            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
            val t2=(ty2,opr2)
         
            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_LoadVec(_,ty,_,exps,_) => add(([vecTy ty],mkFnC exp),[exps])
            | IL.E_mkVec(_,_,ty,_,_,exps)   => add(([vecTy ty,Ty.unionTy ty],mkFnC exp), exps)
            | IL.E_Op(Op, exps)         => add(TypeofOp Op, 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 ILF.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 ILF.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