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

SCM Repository

[diderot] Diff of /branches/vis15/src/compiler/high-to-mid/clean-index.sml
ViewVC logotype

Diff of /branches/vis15/src/compiler/high-to-mid/clean-index.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3564, Sun Jan 10 17:21:18 2016 UTC revision 3565, Sun Jan 10 17:29:35 2016 UTC
# Line 25  Line 25 
25      structure E = Ein      structure E = Ein
26      structure S = GetShape      structure S = GetShape
27      structure R = RewriteIndices      structure R = RewriteIndices
28        structure IMap = IntRedBlackMap
29    
30      fun getShapes e= S.getShapes e      fun getShapes e= S.getShapes e
31      fun rewriteIx e= R.rewrite e      fun rewriteIx e= R.rewrite e
32    
     fun iTos i =Int.toString i  
 (* FIXME *)  
     fun insert (key, value) d =(fn s =>  
         if s = key then SOME value  
         else d s)  
     fun lookup k d = d k  
     val empty =fn key =>NONE  
   
33      fun err str=raise Fail str      fun err str=raise Fail str
34    
35      (*dictionary to lookup mapp*)      (*dictionary to lookup mapp*)
36      fun lkupIX(e1,mapp,str)=(case (lookup e1 mapp)      fun lookupIx (e1, mapp, str) = (case IMap.find(mapp, e1)
37          of SOME l=>l          of SOME l=>l
38          | _=> raise Fail(str^iTos(e1))              | _ => raise Fail(str^ Integer.toString e1)
39          (*endcase*))          (*endcase*))
40    
41      (*sizeMapp:->int      (*sizeMapp:->int
# Line 49  Line 43 
43      *)      *)
44      fun mkSizeMapp (index, sx) = let      fun mkSizeMapp (index, sx) = let
45            fun m ([],mapp) = mapp            fun m ([],mapp) = mapp
46              | m ((E.V v, _,ub)::es,mapp)= m(es,insert(v,ub+1) mapp)              | m ((E.V v, _, ub)::es, mapp) = m (es, IMap.insert(mapp, v, ub+1))
47              | m ( _,_)=err"Non-V-index in sx"              | m ( _,_)=err"Non-V-index in sx"
48            fun f (_,[],mapp)= mapp            fun f (_,[],mapp)= mapp
49              | f (counter,ix::es,mapp) = f(counter+1, es, insert(counter, ix) mapp)              | f (counter, ix::es, mapp) = f (counter+1, es, IMap.insert(mapp, counter, ix))
50            val mapp = f(0, index, empty)            val mapp = f(0, index, IMap.empty)
51            in            in
52              m (sx, mapp)              m (sx, mapp)
53            end            end
# Line 68  Line 62 
62      fun mkIndexMapp (index, sx, ashape, tshape) = let      fun mkIndexMapp (index, sx, ashape, tshape) = let
63            fun f (mapp, [],tocounter) = (mapp, tocounter)            fun f (mapp, [],tocounter) = (mapp, tocounter)
64              | f (mapp, (E.V e1)::es, tocounter) = let              | f (mapp, (E.V e1)::es, tocounter) = let
65                  val dict=insert(e1, tocounter) mapp                  val dict = IMap.insert(mapp, e1, tocounter)
66                  in                  in
67                    f(dict,es,tocounter+1)                    f(dict,es,tocounter+1)
68                  end                  end
69            fun m (mapp, [], tocounter) = mapp            fun m (mapp, [], tocounter) = mapp
70              | m (mapp, e1::es, tocounter) = (case (lookup e1 mapp)              | m (mapp, e1::es, tocounter) = (case IMap.lookup(mapp, e1)
71                      of SOME _=> m (mapp, es, tocounter)                      of SOME _=> m (mapp, es, tocounter)
72                       | _ => (case (List.find (fn x => x = E.V e1) ashape)                       | _ => (case (List.find (fn x => x = E.V e1) ashape)
73                             of NONE => m (mapp, es, tocounter)                             of NONE => m (mapp, es, tocounter)
74                              | SOME _ => let                              | SOME _ => let
75                                  val dict = insert (e1, tocounter) mapp                                  val dict = IMap.insert (mapp, e1, tocounter)
76                                  in                                  in
77                                    m(dict,es,tocounter+1)                                    m(dict,es,tocounter+1)
78                                  end                                  end
79                            (* end case *))                            (* end case *))
80                    (* end case *))                    (* end case *))
81            val (mapp, tocounter) =f (empty, tshape, 0)            val (mapp, tocounter) = f (IMap.empty, tshape, 0)
82            val pp = List.map (fn E.V v => v | _ => 0) ashape            val pp = List.map (fn E.V v => v | _ => 0) ashape
83            val max = List.foldl (fn (a, b) => Int.max(a, b)) (length index-1) pp            val max = List.foldl (fn (a, b) => Int.max(a, b)) (length index-1) pp
84            (*finds max element in ashape and creates [0,1,2,....,max]*)            (*finds max element in ashape and creates [0,1,2,....,max]*)
# Line 101  Line 95 
95      fun clean (e, index, sx) = let      fun clean (e, index, sx) = let
96            val (ashape, tshape) = getShapes(e, index, sx)            val (ashape, tshape) = getShapes(e, index, sx)
97            val sizeMapp = mkSizeMapp(index, sx)            val sizeMapp = mkSizeMapp(index, sx)
98            val sizes = List.map (fn E.V e1 => lkupIX(e1,sizeMapp,"Could not find Size of")) tshape            val sizes = List.map (fn E.V e1 => lookupIx(e1, sizeMapp, "Could not find Size of")) tshape
99            val indexMapp = mkIndexMapp (index, sx, ashape, tshape)            val indexMapp = mkIndexMapp (index, sx, ashape, tshape)
100            val body = rewriteIx (indexMapp, e)            val body = rewriteIx (indexMapp, e)
101            in            in

Legend:
Removed from v.3564  
changed lines
  Added in v.3565

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