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 3358 - (download) (annotate)
Fri Oct 30 21:30:53 2015 UTC (3 years, 11 months ago) by cchiw
File size: 3471 byte(s)
mid-to-low uses set
(* Expands probe ein
 *
 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
 *
 * COPYRIGHT (c) 2015 The University of Chicago
 * All rights reserved.
 *)

structure handleEin = struct

    local
   
    structure E = Ein
    structure DstIL = MidIL
    structure P=Printer
    structure MidToS=MidToString
    structure L=LiftEin
    in

    val testinitial=0
    val testing=0
    fun testp n=(case testing
        of 0=> 1
        | _ =>(print(String.concat n);1)
        (*end case*))
    fun test0 n=(case testinitial
        of 0=>testp n
        | _ => (print(String.concat n);1))
    fun toStringBind e= MidToS.toStringBind e
    fun useCount (HighIL.V{useCnt, ...}) = !useCnt
    fun expandEinOp (srcy,bind00)=let
        (*val _=raise Fail"development branch- do not use"*)
        val star="************"
        val _=("\n Start"^star)
        val _ =test0[star,"\n Original EinApp",star,"\n\n","start get test",toStringBind bind00]
        val (y,einapp as DstIL.EINAPP(Ein.EIN{params, index, body},args))=bind00
      

        (* ************* Sweep for 0's'*********** *)
        val bodysweep=sweepEin.sweep body
        val ein1=Ein.EIN{params=params, index=index, body=bodysweep}
        val _=testp["Post Sweep\n",P.printbody bodysweep,"\n"]


        (* ************** distribute and push Summation*********** *)
        val bind3 = (y,DstIL.EINAPP(SummationEin.main ein1,args))
        val _ =testp["\n\n summation \n\n =>", toStringBind bind3]


    (* **************** lift field phase ************* *)
(*
         val (einapp1,e2)=L.testLift  bind3
        val newbies5=  Split.iterAll2(einapp1,e2)
        val n =length(newbies5)
        val _ = if (n > 10) then print("\n **** SPLIT Length"^(Int.toString(n))) else print ""

*)

        (* **************** split phase ************* *)

        val (newbies5)= Split.splitEinApp(bind3,9)
        val _ =test0["\n\n Returning \n\n =>",
        String.concatWith",\n\t"(List.map toStringBind newbies5)]

         (* ************** ProbeEIN *********** *)
        (*gives probeEIN the set. Could split into a sepearate step*)
        val fieldset= einSet.EinSet.empty
        val isField = ref 0
        val isFieldR = ref 0
        val isReplaced = ref 0
        fun iter([],_)=[]
         | iter(e1::es,fieldset)= let
            val (e2,fieldset,isFieldt,isReplacedt) = ProbeEin.expandEinOp(e1,fieldset)
            val rtn=[e2]@(iter(es,fieldset))
            val isFieldRt=if ((isFieldt+isReplacedt)=2) then 1 else 0
            in (isField:=(!isField)+isFieldt;isReplaced:=(!isReplaced )+isReplacedt;
            isFieldR:=(!isFieldR)+isFieldRt;rtn)
            end
        val code=iter(newbies5, fieldset)

        val n= List.length(code)

          val _ = if (n>5)
         then  (String.concat["\n\n",star,":Name:",HighIL.Var.name srcy ,
            ":VarCount(",Int.toString(useCount srcy),")",
                "\n\t",star,"Pieces now: ",Int.toString (n),
            " Fields:",Int.toString(!isField)," isReplaced:",Int.toString(!isReplaced),
            " Replaced_Fields:",Int.toString(!isFieldR)
               ,toStringBind bind3])
            else  ""

        val flatcode= List.foldr op@ [] code
        (*val _=List.map (fn(_,DstIL.EINAPP(e,_))=>checkEin.checkEIN e | _=> 1) flatcode*)
        val _=(star^"end")
        in
            List.map (fn (y,rator)=> DstIL.ASSGN(y,rator)) flatcode
        end

  end; (* local *)

end (* local *)

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