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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3690 - (download) (annotate)
Thu Mar 17 20:09:08 2016 UTC (3 years, 6 months ago) by cchiw
File size: 4055 byte(s)
tree-il code for vis15 branch
(* TreeIL stmt to (types, opr) sets *)

structure TreeToOpr = struct

    structure Op = TreeOps
    structure Ty = TreeTypes
    structure IL = TreeIR
    structure Fnc = TreeFunc
    structure TySet = Fnc.TySet
    structure OprSet = Fnc.OprSet
     structure V = IL.Var

    fun vecTy n = Ty.TensorTy[n]
    val default = ([], [])

    (*stmt-> sets(TySet, OprSet)*)
    (* TypeofOp:  TreeIL operator -> TreeIL types list * TreeIL function list
    * operator uses tensors in types list and creates calls to functions to function list.
    *)
    fun TypeofOp rator = (case rator
        of Op.VScale 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.VScale d)])
        | Op.VSum (nSize, oSize)    => (([], [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_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_Var x                        => (case IL.Var.ty x
            of Ty.TensorTy ty   => addToSet(set1, ([], [Fnc.COPY (size ty)]), [])
            | _                 => set1
            (*end case*))
        (*end case*))
    and addToSet(set1, (typ, cfn), rest) = let
        (*adds typs and cfn to set*)
        val (ty1, opr1) = set1
        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) = (case stmt
	       of IL.S_LoadNrrd _                   => set1
            | IL.S_InputNrrd _                  => 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_Input(_, _, _, SOME exp)     => expToOpr(set1, exp)
            | IL.S_Save(_, exp)                 => expToOpr(set1, exp)
            | IL.S_Copy(_, exp, offset, 1)      => expToOpr(set1, exp)
            | IL.S_Copy(_, exp, offset, n)      => addToSet(set1, ([], [Fnc.COPY n]), [exp])
            | IL.S_Cons(x, oSize, exp)          => addToSet(set1, ([], [Fnc.CONS oSize]), exp) (*calls array function*)
            | 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_StoreVec(_, _, A, true, oSize, ty, pieces, exps) => let
                val typ = [vecTy 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, pieces, exps) => let
                val typ = [vecTy oSize]
                val fnc = List.map (fn p => Fnc.STORE (A, p, p)) pieces
                in
                   addToSet(set1, (typ, fnc), exps)
                end
            | _ => set1
        (*end case*))
    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