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

SCM Repository

[diderot] View of /branches/charisee_dev/src/compiler/high-to-mid/handleEin.sml
ViewVC logotype

View of /branches/charisee_dev/src/compiler/high-to-mid/handleEin.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2845 - (download) (annotate)
Fri Dec 12 06:46:23 2014 UTC (4 years, 9 months ago) by cchiw
Original Path: branches/charisee/src/compiler/high-to-mid/handleEin.sml
File size: 2662 byte(s)
added norm
(* Expands probe ein
 *
 * COPYRIGHT (c) 2012 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 *)

structure handleEin = struct

    local
   
    structure E = Ein
    structure DstIL = MidIL
    structure DstOp = MidOps
    structure P=Printer
    structure T=TransformEin
    structure MidToS=MidToString
    structure DstV = DstIL.Var
    in

    val testing=1
    fun setEin(params,index,body)=Ein.EIN{params=params, index=index, body=body}
    fun assignEinApp(y,params,index,body,args)= (y,DstIL.EINAPP(setEin(params,index,body),args))
    fun assignEinApp(y,params,index,body,args)= (y,DstIL.EINAPP(setEin(params,index,body),args))
      fun iTos i =Int.toString i 
    fun testp n=(case testing
        of 0=> 1
        | _ =>(print(String.concat n);1)
        (*end case*))
    val einappzero=DstIL.EINAPP(setEin([],[],E.Const 0),[])
    fun setEinZero y=  (y,einappzero)

    (* isZero:ein_exp->int
    *  Checks to see if the entire body is 0. If so returns 1.
    *)
    fun isZero e=let
        val _=print(String.concat["\n Started Zero",P.printbody e])
        fun iterList []= 1
            | iterList(e1::list)=(case (isZero e1)
            of 0=>0
            | _ => iterList list
            (*end case*))
        fun iterProdList []= 0
        | iterProdList(e1::list)=(case (isZero e1)
            of 1=>1
            | _ => iterList list
            (*end case*))
        val z=(case e
            of E.Add e             => iterList e
            | E.Sub(e1,e2)         => iterList [e1,e2]
            | E.Div(e1,e2)         => isZero e1
            | E.Sum(_ ,e)          => isZero e
            | E.Prod e             => iterProdList e
            | E.Neg e              => isZero e
            | E.Probe(E.Conv _,_)         => 0
            | E.Const 0            => 1
            | E.Field _            => 1
            | E.Partial _          => 1
            | E.Apply _            => 1
            | E.Lift _             => 1
            | E.Conv _             => 1
            | _                    => 0
            (*end case*))
        val _=print(String.concat["\n Is it Zero",P.printbody e,"--", iTos z])
        in
            z
        end

    (*isZero: var* einapp params*index list*mid-il vars
        When the operation is zero then we return a real.
        *)
    fun zeroSweep(y,einapp as DstIL.EINAPP(ein,_))=let
            val _ =testp["\n Starting is zero for var-",DstV.name y]
            in (case (isZero(E.body ein))
                of 1=>  setEinZero y
                | _ =>(y,einapp)
                (*end case*))
            end 


  end; (* local *)

end (* local *)

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