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/tree-to-opr.sml
ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2844 - (download) (annotate)
Tue Dec 9 18:05:29 2014 UTC (4 years, 11 months ago) by cchiw
File size: 4451 byte(s)
code cleanup
(* TreeIL stmt to (types, opr) sets *)

structure TreeToOpr= struct

    structure Op = TreeOps
    structure Ty = TreeILTypes
    structure IL=TreeIL
    structure Fnc=TreeFunc
    structure TySet=Fnc.TySet
    structure OprSet=Fnc.OprSet
     structure V = IL.Var

    fun vecTy n= Ty.TensorTy[n]
    val testing=0
    fun testp str=(case testing
        of 1=> (print(String.concat str);1)
        | _ =>1
    (*end case*))

    val default=([],[])

    (*stmt-> sets(TySet, OprSet)*)
    fun TypeofOp rator = (case rator
        of Op.prodScaV d               => ([vecTy d],[Fnc.CONSV d,Fnc.OP(rator)])
        | Op.Floor d                   => ([vecTy d],[Fnc.OP rator])
        | Op.clampVec d                => ([vecTy d],[Fnc.OP rator])
        | Op.lerpVec d                 => ([vecTy d],[Fnc.OP rator,Fnc.CONSV d,Fnc.OP (Op.prodScaV d)])
        | Op.sumVec (nSize,oSize)      => (([Ty.unionTy nSize],[Fnc.OP rator]))
        | Op.Zero(Ty.TensorTy n)       => ([],[Fnc.OP rator])
        | _                            => default
        (* end case *))
    and size n=foldl (fn (a,b) => b*a) 1 n 
    and expToOpr(set1,exp)=(case exp
        of IL.E_State _                 => set1
        | IL.E_Var x                    => (case IL.Var.ty x
            of Ty.TensorTy ty               =>  addToSet(set1,([], [Fnc.COPY (size ty)]),[])
            | _                             => set1
            (*end case*))
        | IL.E_Lit _                    => set1
        | IL.E_Mux (_,_,_,_,exps)       => addToSet(set1,([],[]),exps)
        | IL.E_Apply (_, exps)          => addToSet(set1,default,exps)
        | IL.E_Cons (n,_,exps)          => addToSet(set1,([vecTy n ], [Fnc.CONSV n]),exps)
        | IL.E_LoadArr(A,fTy,oTy,exp,_) => addToSet(set1,([vecTy fTy],[Fnc.LDArr(A,fTy,oTy)]),[exp])
        | IL.E_Op(Op, exps)             => addToSet(set1,TypeofOp Op, exps)
        | IL.E_Holder _                 => set1 
        (*end case*)) 
    and addToSet(set1,(typ,cfn),rest)= let
        (*adds typs and cfn to set*)
        val (ty1,opr1)=set1
        val _ = testp[ Fnc.setToString(ty1,opr1,"\npre add to set")]
        val _ = testp (List.map (fn e=> Fnc.toString e) cfn)
        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 sets2=(ty2,opr2)
        in
             List.foldr (fn(e1,e2) => expToOpr(e2,e1)) sets2 rest
        end
    and stmtToOpr(set1,stmt)=let
        val (tys,oprs)=set1
        val _ =testp[ Fnc.setToString(tys,oprs,"\npre calling stmtToOpr")]
        val _ =testp["\n\n\n\n StmttoOpr \t",IL.toStringS stmt]
        val newset= (case stmt
        of IL.S_Input (_,_,_, NONE)     => set1
        | IL.S_Assign (v,exp)           => expToOpr(set1,exp)
        | IL.S_IfThen(exp,_)            => expToOpr(set1,exp)
        | IL.S_IfThenElse( exp,_,_)     => expToOpr(set1,exp)
        | IL.S_LoadImage(v,_, exp)      => expToOpr(set1,exp)
        | IL.S_Input (v,_,_, SOME exp ) => expToOpr(set1,exp)
        | IL.S_Save(_,exp)              => expToOpr(set1,exp) (*FIX ME*)
        | IL.S_New (_, exps)            => List.foldr (fn(e1,e2)=> expToOpr(e2,e1)) set1 exps
        | IL.S_Exit exps                => List.foldr (fn(e1,e2)=> expToOpr(e2,e1)) set1 exps
        | IL.S_Copy(_,exp,offset,1)     =>expToOpr(set1,exp)
        | IL.S_Copy(_,exp,offset,n)            =>let
            val fnc= [Fnc.COPY n]
            in
               addToSet(set1,([],fnc),[exp])
            end
        | IL.S_StoreVec(_,_,A,true,oSize,ty,Ty.vectorLength pieces,exps) => let
            val typ=[vecTy oSize,Ty.unionTy oSize]
            val fnc=List.map (fn p => Fnc.STORE (A,oSize, p)) pieces
            in
                addToSet(set1, (typ,fnc),exps)
            end
        | IL.S_StoreVec(_,_,A,_,oSize,ty,Ty.vectorLength pieces,exps) => let
            val typ=[vecTy oSize,Ty.unionTy oSize]
            val fnc=List.map (fn p => Fnc.STORE (A,p,p)) pieces
            in
                addToSet(set1, (typ,fnc),exps)
            end
        | IL.S_Cons(x,oSize, exp)=>addToSet(set1,([],[Fnc.CONS oSize]),exp) (*calls array function*)
        | _                             => set1
    (*end case*))
        val (tys,oprs)=newset
        (*val _ =print( Fnc.setToString(tys,oprs,"\nin set"))*)
        in newset
        end
    and stmtsToOpr(set1,stmts)= List.foldr (fn(e1,e2) => stmtToOpr (e2,e1)) set1 stmts

end

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