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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3383 - (view) (download)

1 : cchiw 2845 (* Expands probe ein
2 :     *
3 : jhr 3349 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     *
5 :     * COPYRIGHT (c) 2015 The University of Chicago
6 : cchiw 2845 * All rights reserved.
7 :     *)
8 :    
9 :     structure handleEin = struct
10 :    
11 :     local
12 :    
13 :     structure E = Ein
14 :     structure DstIL = MidIL
15 :     structure P=Printer
16 :     structure MidToS=MidToString
17 : cchiw 3325 structure L=LiftEin
18 : cchiw 2845 in
19 :    
20 : cchiw 3355 val testinitial=0
21 : cchiw 3259 val testing=0
22 : cchiw 2845 fun testp n=(case testing
23 :     of 0=> 1
24 :     | _ =>(print(String.concat n);1)
25 :     (*end case*))
26 : cchiw 3166 fun test0 n=(case testinitial
27 : cchiw 3203 of 0=>testp n
28 : cchiw 3166 | _ => (print(String.concat n);1))
29 : cchiw 3324 fun toStringBind e= MidToS.toStringBind e
30 : cchiw 3271 fun useCount (HighIL.V{useCnt, ...}) = !useCnt
31 :     fun expandEinOp (srcy,bind00)=let
32 : cchiw 3383 val _=raise Fail"development branch- do not use"
33 : cchiw 3033 val star="************"
34 : cchiw 3383 val _=print ("\n Start"^star)
35 : cchiw 3260 val _ =test0[star,"\n Original EinApp",star,"\n\n","start get test",toStringBind bind00]
36 : cchiw 3203 val (y,einapp as DstIL.EINAPP(Ein.EIN{params, index, body},args))=bind00
37 : cchiw 3166
38 : cchiw 3033
39 :     (* ************* Sweep for 0's'*********** *)
40 : cchiw 3374 val _ =(String.concat["Pre Sweep\n",P.printbody body,"\n"])
41 : cchiw 3203 val bodysweep=sweepEin.sweep body
42 : cchiw 3033 val ein1=Ein.EIN{params=params, index=index, body=bodysweep}
43 : cchiw 3374 val _ =(String.concat["Post Sweep\n",P.printbody bodysweep,"\n"])
44 : cchiw 3033
45 :    
46 : cchiw 3203 (* ************** distribute and push Summation*********** *)
47 :     val bind3 = (y,DstIL.EINAPP(SummationEin.main ein1,args))
48 : cchiw 3260 val _ =testp["\n\n summation \n\n =>", toStringBind bind3]
49 : cchiw 3033
50 : cchiw 3369 (* **************** lift no split ************* *)
51 :     (*
52 :     val (einapp1,e2)=L.testLift bind3
53 :     val newbies5=e2@[einapp1]
54 :     val _ = print("\n **** lift Length"^(Int.toString(length(e2))))
55 :     *)
56 : cchiw 3383
57 : cchiw 3358 (* **************** lift field phase ************* *)
58 : cchiw 3383
59 : cchiw 3344 val (einapp1,e2)=L.testLift bind3
60 : cchiw 3383 val _ = print("\n **** lift Length"^(Int.toString(length(e2))))
61 : cchiw 3344 val newbies5= Split.iterAll2(einapp1,e2)
62 :     val n =length(newbies5)
63 :     val _ = if (n > 10) then print("\n **** SPLIT Length"^(Int.toString(n))) else print ""
64 :    
65 :    
66 : cchiw 3383
67 : cchiw 3166 (* **************** split phase ************* *)
68 : cchiw 3383 (*
69 : cchiw 3353 val (newbies5)= Split.splitEinApp(bind3,9)
70 : cchiw 3276 val _ =test0["\n\n Returning \n\n =>",
71 : cchiw 3344 String.concatWith",\n\t"(List.map toStringBind newbies5)]
72 : cchiw 3383 *)
73 :     val _=print"probein\n"
74 : cchiw 3166 (* ************** ProbeEIN *********** *)
75 : cchiw 3189 (*gives probeEIN the set. Could split into a sepearate step*)
76 : cchiw 3174 val fieldset= einSet.EinSet.empty
77 : cchiw 3271 val isField = ref 0
78 :     val isFieldR = ref 0
79 :     val isReplaced = ref 0
80 : cchiw 3174 fun iter([],_)=[]
81 :     | iter(e1::es,fieldset)= let
82 : cchiw 3271 val (e2,fieldset,isFieldt,isReplacedt) = ProbeEin.expandEinOp(e1,fieldset)
83 :     val rtn=[e2]@(iter(es,fieldset))
84 :     val isFieldRt=if ((isFieldt+isReplacedt)=2) then 1 else 0
85 :     in (isField:=(!isField)+isFieldt;isReplaced:=(!isReplaced )+isReplacedt;
86 :     isFieldR:=(!isFieldR)+isFieldRt;rtn)
87 :     end
88 : cchiw 3174 val code=iter(newbies5, fieldset)
89 : cchiw 3271
90 :     val n= List.length(code)
91 :    
92 :     val _ = if (n>5)
93 : cchiw 3383 then print(String.concat["\n\n",star,":Name:",HighIL.Var.name srcy ,
94 : cchiw 3271 ":VarCount(",Int.toString(useCount srcy),")",
95 :     "\n\t",star,"Pieces now: ",Int.toString (n),
96 :     " Fields:",Int.toString(!isField)," isReplaced:",Int.toString(!isReplaced),
97 : cchiw 3369 " Replaced_Fields:",Int.toString(!isFieldR)])
98 : cchiw 3383 else print ""
99 : cchiw 3271
100 : cchiw 3383 val flatcode= List.foldr op@ [] code
101 : cchiw 3369
102 : cchiw 3383 (*
103 :     (*added extra step*)
104 :     val tbl0= einSet.EinSet.empty
105 :     fun getSet([],done,_,cnt)=(done,cnt)
106 :     | getSet((lhs,rhs)::es,done,opset,cnt)=let
107 :     val (opset,var) = einSet.rtnVarN(opset,(lhs,rhs))
108 :     in (case var
109 :     of NONE => getSet(es,done@[(lhs,rhs)], opset,cnt)
110 :     | SOME v=> getSet(es,done@[(lhs,DstIL.VAR v)], opset,cnt+1)
111 :     (*end case*))
112 :     end
113 :    
114 :     val (flatcode,cnt)=getSet(flatcode, [],tbl0,0)
115 :    
116 :     val n=length(flatcode)
117 :     val _ =print(String.concat["\n Length: ",Int.toString n," Replaced: ", Int.toString cnt,
118 :     "\n",DstIL.Var.toString(y),"\n"])
119 :    
120 :     *)
121 : cchiw 3048 (*val _=List.map (fn(_,DstIL.EINAPP(e,_))=>checkEin.checkEIN e | _=> 1) flatcode*)
122 : cchiw 3344 val _=(star^"end")
123 : cchiw 3033 in
124 :     List.map (fn (y,rator)=> DstIL.ASSGN(y,rator)) flatcode
125 :     end
126 :    
127 : cchiw 2845 end; (* local *)
128 :    
129 :     end (* local *)

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