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

SCM Repository

[diderot] Diff of /branches/charisee/src/compiler/mid-to-low/step2.sml
ViewVC logotype

Diff of /branches/charisee/src/compiler/mid-to-low/step2.sml

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

revision 2612, Wed May 7 02:58:55 2014 UTC revision 2628, Wed May 21 04:02:06 2014 UTC
# Line 1  Line 1 
1  (*hashs Ein Function after substitution*)  (*general function for scalars*)
2  structure step2 = struct  structure step2 = struct
3      local      local
4      structure DstIL = LowIL      structure DstIL = LowIL
# Line 8  Line 8 
8      structure E = Ein      structure E = Ein
9      structure S3=step3      structure S3=step3
10      structure genKrn=genKrn      structure genKrn=genKrn
11        structure tS= toStringEin
12    
13      in      in
14    
# Line 23  Line 24 
24  fun errS str=raise Fail(str)  fun errS str=raise Fail(str)
25    
26  (*Helpers for scalars*)  (*Helpers for scalars*)
27  fun mkCons(shape,rest)=S3.aaV(DstOp.cons(DstTy.TensorTy shape,0),rest,"Cons",DstTy.TensorTy(shape))  
28    fun mkCons(shape, rest)=let
29        val ty=DstTy.TensorTy shape
30        val a=DstIL.Var.new("Cons" ,ty)
31        val code=DstIL.ASSGN (a,DstIL.CONS(ty ,rest))
32        val _=print("###"^tS.toStringAll(ty,code))
33        in (a, [code])
34        end
35    
36    
37  val Sca=DstTy.TensorTy([])  val Sca=DstTy.TensorTy([])
38  fun mkProdSca rest=S3.aaV(DstOp.prodSca,rest,"prodSca",Sca)  fun mkProdSca rest=S3.aaV(DstOp.prodSca,rest,"prodSca",Sca)
39  fun mkSubSca rest= S3.aaV(DstOp.subSca,rest,"subSca",Sca)  fun mkSubSca rest= S3.aaV(DstOp.subSca,rest,"subSca",Sca)
40  fun mkDivSca rest= S3.aaV(DstOp.divSca,rest,"divSca",Sca)  fun mkDivSca rest= S3.aaV(DstOp.divSca,rest,"divSca",Sca)
41  fun mkMultipleSca(ids,rator)=S3.mkMultiple(ids,rator,Sca)  fun mkMultipleSca(ids,rator)=S3.mkMultiple(ids,rator,Sca)
42  fun mkInt n= S3.aaV(DstOp.C(n),[],"Int",Sca)  fun mkInt n= S3.aaV(DstOp.C n,[],"Int",Sca)
43    
44    
45    
46    
47    
48  fun prodIter(origIndex,index,nextfn,args)=(let  fun prodIter(origIndex,index,nextfn,args)=(let
49      val index'=List.map (fn (e)=>(e-1)) index      val index'=List.map (fn (e)=>(e-1)) index
# Line 76  Line 90 
90          in          in
91              (vA,code'@ccode)              (vA,code'@ccode)
92          end          end
93        | Iter _=raise Fail"index' is larger than origIndex"
94      in      in
95          Iter(empty,index',[],[],origIndex,0)          Iter(empty,index',[],[],origIndex,0)
96      end)      end)
# Line 127  Line 142 
142  (* general expressions-removes zeros*)  (* general expressions-removes zeros*)
143  fun generalfn(dict,(body,origargs,info))=let  fun generalfn(dict,(body,origargs,info))=let
144      val mapp=ref dict      val mapp=ref dict
145      (*val _=printMapp(!mapp)*)  
     val _=print "in General FUNCTIOn"  
146    
147    
148      fun gen body=let      fun gen body=let
# Line 153  Line 167 
167              end              end
168    
169          fun Sumcheck(sumx,e)=let          fun Sumcheck(sumx,e)=let
             val _=print "\n Found Sum"  
170              fun sumloop mapsum=let              fun sumloop mapsum=let
171                  val _ = mapp:=mapsum                  val _ = mapp:=mapsum
172                  val(vA,A)=gen e                  val(vA,A)=gen e
# Line 173  Line 186 
186                  val dict=insert(v, (s+lb1)) left                  val dict=insert(v, (s+lb1)) left
187                  val (rest',code')=sumI1(dict,(a,ub-lb2,lb2),sx,rest,code)                  val (rest',code')=sumI1(dict,(a,ub-lb2,lb2),sx,rest,code)
188                  in sumI1(dict,(v,s-1,lb1),(E.V a,lb2,ub)::sx,rest',code') end                  in sumI1(dict,(v,s-1,lb1),(E.V a,lb2,ub)::sx,rest',code') end
189                 | sumI1 _ =raise Fail"None Variable-index in summation"
190              val (E.V v,lb,ub)=hd(sumx)              val (E.V v,lb,ub)=hd(sumx)
191              in              in
192                  sumI1(!mapp,(v,ub-lb,lb),tl(sumx),[],[])                  sumI1(!mapp,(v,ub-lb,lb),tl(sumx),[],[])
# Line 197  Line 211 
211          | E.Const c             => mkInt c          | E.Const c             => mkInt c
212          | E.Epsilon(i,j,k)      => S3.evalEps(!mapp,i,j,k)          | E.Epsilon(i,j,k)      => S3.evalEps(!mapp,i,j,k)
213          | E.Delta(i,j)          => S3.evalDelta2(!mapp,i,j)          | E.Delta(i,j)          => S3.evalDelta2(!mapp,i,j)
214          | E.Tensor(id,ix)       => (print("\n Tensor: "^Int.toString(id));          | E.Tensor(id,ix)       => S3.mkSca(!mapp,(id,ix,info))
             S3.mkSca(!mapp,(id,ix,info)))  
215          | E.Neg e               => NegCheckO(gen e)          | E.Neg e               => NegCheckO(gen e)
216          | E.Sub (e1,e2)         => SubcheckO(gen e1,gen e2)          | E.Sub (e1,e2)         => SubcheckO(gen e1,gen e2)
217          | E.Div(e1,e2)          => let          | E.Div(e1,e2)          => let
# Line 211  Line 224 
224                      in (vD, A@B@D) end                      in (vD, A@B@D) end
225                  (*end case*))                  (*end case*))
226              end              end
227          | E.Add e               => (print "\n in Add";iterList(AddcheckO(e,[],[]),DstOp.addSca))          | E.Add e               => (iterList(AddcheckO(e,[],[]),DstOp.addSca))
228          | E.Prod e              => iterList(ProdcheckO(e,[],[]),DstOp.prodSca)          | E.Prod e              => iterList(ProdcheckO(e,[],[]),DstOp.prodSca)
229          | E.Sum(sx,E.Prod(E.Img (Vid,_,_)::E.Krn(Hid,del,pos)::es))=>let          | E.Sum(sx,E.Prod(E.Img (Vid,_,_)::E.Krn(Hid,del,pos)::es))=>let
230              val harg=List.nth(origargs,Hid)              val harg=List.nth(origargs,Hid)

Legend:
Removed from v.2612  
changed lines
  Added in v.2628

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