Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /branches/charisee/src/compiler/high-il/order-ein.sml
ViewVC logotype

View of /branches/charisee/src/compiler/high-il/order-ein.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: 2318 byte(s)
code cleanup
(*Orders Ein Function after substitution
*Could be moved to High-IL
*)
structure OrderEin = struct

    local

    structure E = Ein
    structure F = Filter

    in

(*rewriteProd:ein_exp list ->ein_exp*)
fun rewriteProd A=(case A
    of [A]=> A
    | A => E.Prod A
    (*end case*))

(*rewriteProd:ein_exp * ein_exp list ->ein_exp*)
fun rewriteApply(c,p)= E.Apply(c, rewriteProd p)

(*pushApply:ein_exp * ein_exp list ->int* ein_exp
*Moves non-field expression outside of apply
*)
fun pushApply (del,p)=(case F.filterField p
    of ([],[])    => raise Fail"No Field in Apply expression"
    | ([],post) => (0,rewriteApply(del,post))
    | (pre,post)=> (1,rewriteProd(pre@[rewriteApply(del,post)]))
    (*end case*))


(*orderfn:EIN->EIN
 Does some smple ordering
Scalars*Epsilons*deltas*else
*)
fun orderfn(Ein.EIN{params, index, body})= let
   val changed =ref false
   fun order(body)=(case body
        of E.Const _ => body
        | E.Tensor _=> body
        | E.Field _ => body
        | E.Krn _ => body
        | E.Img _ => body
        | E.Delta _ => body
        | E.Value _ => body
        | E.Epsilon _=>body
        | E.Eps2 _  =>body
        | E.Partial _ => body
        | E.Conv _=>body 
        | E.Sum(c1,E.Sum(c2, e))=>(changed:=true;E.Sum(c1@c2,order e))
        | E.Sum(c,e)=> E.Sum(c, order e)
        | E.Lift e => E.Lift(order e)
        | E.Neg e => E.Neg(order e)
        | E.Add es => E.Add (List.map order es)
        | E.Sub(e1,e2) => E.Sub(order e1, order e2)
        | E.Div(e1,e2)=> E.Div(order e1, order e2)
        | E.Apply(e1,E.Prod e2) => let
            val(change,e')=pushApply (e1,e2)
            in (case change of 1=>(changed:=true; e') |_=> e')
            end
        | E.Apply(e1,e2)=> E.Apply(e1, order e2)
        | E.Probe(e1,e2)=>  E.Probe(order e1,order e2)
        | E.Prod [e1]=>e1
        | E.Prod e=> let
            val(s,eps,dels,p)= F.filterGreek e
            val p'=List.map order p
            in E.Prod(s@eps@dels@p')
            end
        (*end case*))
    fun loop body = let
    val body' = order body
        in
            if !changed
                then (changed := false; loop body')
            else body'
        end
        val b = loop body
        val b'=order b
   in (Ein.EIN{params=params, index=index, body=b'}) end

end (* local *)

end 

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