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

SCM Repository

[diderot] Diff of /branches/charisee_dev/src/compiler/ein/printer.sml
ViewVC logotype

Diff of /branches/charisee_dev/src/compiler/ein/printer.sml

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

revision 2496, Tue Oct 29 05:29:46 2013 UTC revision 2533, Thu Jan 30 04:58:56 2014 UTC
# Line 3  Line 3 
3  structure Printer = struct  structure Printer = struct
4    
5      local      local
6        structure G = GenericEin  
7        structure E = Ein        structure E = Ein
8        structure S = Specialize  
      (* structure R = Rewrite*)  
9      in      in
10    
11      fun intList l = String.concat[String.concatWith "," (List.map Int.toString l)]      fun intList l = String.concat[String.concatWith "," (List.map Int.toString l)]
12    
13      fun printIndex e= (case e  fun handleIndex e= (case e
14          of E.C(cx)=> String.concat["'",Int.toString(cx),"'"]          of E.C(cx)=> String.concat["'",Int.toString(cx),"'"]
15          |  E.V(ix)=> Int.toString(ix)          |  E.V(ix)=> Int.toString(ix)
16      )      )
17    
18      fun printAlpha alpha= String.concat[String.concatWith "," (List.map printIndex alpha)]  fun handleAlpha alpha= String.concat[String.concatWith "," (List.map handleIndex alpha)]
19    
20    
21      fun handleBeta(a,b)=String.concat["Delta_(",printIndex a, ",", printIndex b,")"]  fun handleBeta(a,b)=String.concat["δ_(",handleIndex a, ",", handleIndex b,")"]
22    
23    fun handleSumRange (mu,lb,ub)= String.concat[(handleIndex mu),"[",Int.toString(lb),"-",Int.toString(ub),"]"]
24    
25            fun printbody term = (case term            fun printbody term = (case term
26              of E.Const r => Real.toString(r)              of E.Const r => Real.toString(r)
27              | E.Tensor(id, []) =>String.concat[" S",Int.toString(id)]              | E.Tensor(id, []) =>String.concat[" S",Int.toString(id)]
28              | E.Tensor(id, alpha) =>String.concat[" T",Int.toString(id),"_",printAlpha alpha]      | E.Tensor(id, alpha) =>String.concat[" T",Int.toString(id),"_",handleAlpha alpha]
29              | E.Field(id, []) =>String.concat[" F",Int.toString(id)]              | E.Field(id, []) =>String.concat[" F",Int.toString(id)]
30              | E.Field(id, alpha) =>String.concat[" F",Int.toString(id),"_",printAlpha alpha]      | E.Field(id, alpha) =>String.concat[" F",Int.toString(id),"_",handleAlpha alpha]
   
   
31              | E.Krn(tid,[],pos) =>String.concat["h ",Int.toString(tid),"[",  (printbody pos),"]"]              | E.Krn(tid,[],pos) =>String.concat["h ",Int.toString(tid),"[",  (printbody pos),"]"]
32        | E.Krn(tid,betas,pos) => String.concat[" h",Int.toString(tid),"^{", String.concat (List.map handleBeta betas),"} [",(printbody pos),"]"]
             | E.Krn(tid,betas,pos) =>String.concat["h",Int.toString(tid),"^{",String.concat(List.map handleBeta betas),"} [",  
                 (printbody pos),"]"]  
   
   
33              | E.Delta(ix) =>  handleBeta ix              | E.Delta(ix) =>  handleBeta ix
34              | E.Value(ix)=> String.concat["_",Int.toString(ix),"_"]              | E.Value(ix)=> String.concat["_",Int.toString(ix),"_"]
35              | E.Epsilon(ix, jx, kx) => String.concat["E_",Int.toString(ix), Int.toString(jx), Int.toString(kx)]              | E.Epsilon(ix, jx, kx) => String.concat["E_",Int.toString(ix), Int.toString(jx), Int.toString(kx)]
36              | E.Sum (alpha,e1)=> String.concat["\n \t Sigma:", printAlpha alpha," (", printbody e1,")"]      | E.Sum (sumindex,e1)=>String.concat[" Σ_",String.concatWith ","(List.map handleSumRange sumindex),"~" ,printbody e1,"~"]
37              | E.Neg e1 => String.concat["-", printbody e1]      | E.Neg e1 => String.concat["-NEG-", printbody e1]
38              | E.Add el => String.concat["(",String.concatWith "+" (List.map printbody el),")"]              | E.Add el => String.concat["(",String.concatWith "+" (List.map printbody el),")"]
39              | E.Sub(e1, e2) => String.concat ["(",printbody(e1),"- ",printbody(e2), ")"]              | E.Sub(e1, e2) => String.concat ["(",printbody(e1),"- ",printbody(e2), ")"]
40              | E.Prod el => String.concat["{{",String.concatWith "* " (List.map printbody el),"}}"]              | E.Prod el => String.concat["{{",String.concatWith "* " (List.map printbody el),"}}"]
41              | E.Div(e1,e2) => String.concat ["(",printbody(e1),"/ ",printbody (e2), ")"]              | E.Div(e1,e2) => String.concat ["(",printbody(e1),"/ ",printbody (e2), ")"]
42              | E.Partial alpha => String.concat["d/dx_",printAlpha alpha]      | E.Partial alpha => String.concat["d/dx_",handleAlpha alpha]
43              | E.Apply(e1, e2)=> String.concat [ printbody(e1),"@{", printbody(e2),"} "]              | E.Apply(e1, e2)=> String.concat [ printbody(e1),"@{", printbody(e2),"} "]
44        | E.Conv(fid,alpha, tid ,[])=> String.concat["|V",Int.toString(fid),"_{",handleAlpha alpha, "}★h",Int.toString(tid),"|"]
45              | E.Conv(fid,alpha, tid ,[])=> String.concat["|V",Int.toString(fid),"_{",printAlpha alpha, "}★h|"]      | E.Conv(fid,alpha, tid, beta)=> String.concat["|V",Int.toString(fid),"_{",handleAlpha alpha, "}★d/dx_{",handleAlpha beta,"}h",Int.toString(tid),"|"]
             | E.Conv(fid,alpha, tid, beta)=> String.concat["|V",Int.toString(fid),"_{",printAlpha alpha, "}★d/dx_{",printAlpha beta,"}h|"]  
   
46              | E.Probe (e1,e2)=> String.concat ["",printbody(e1), "","[", printbody(e2),"]"]              | E.Probe (e1,e2)=> String.concat ["",printbody(e1), "","[", printbody(e2),"]"]
47              | E.Img (fid,alpha,pos)=> String.concat ["V", Int.toString(fid),"_",printAlpha alpha,"[",      | E.Img (fid,alpha,pos)=> String.concat [" V", Int.toString(fid),"_",handleAlpha alpha,"[",
48                  (String.concatWith "," (List.map printbody pos)),"]"]                  (String.concatWith "," (List.map printbody pos)),"]"]
49    
50    
51    
52              (* end case *))              (* end case *))
53          fun printerE (Ein.EIN{params, index, body}) = let          fun printerE (Ein.EIN{params, index, body}) = let
54          fun Index ((E.IX(dim))::i, count) = String.concat["(", Int.toString count,          fun Index (dim::i, count) = String.concat["(", Int.toString count,
55                  " DIM:", Int.toString dim, ")", Index(i,count+1)]                  " DIM:", Int.toString dim, ")", Index(i,count+1)]
             | Index ((E.SX(lb,ub))::i, count) = String.concat[ "} {Summation:(",Int.toString(count),  
                 " DIM:",Int.toString(lb),",", Int.toString(ub),")", Index(i,count+1)]  
56              | Index (_, count) = ""              | Index (_, count) = ""
57          fun Param(E.TEN::param, i)=String.concat[Int.toString(i), ":TEN ", Param(param, i+1)]          fun Param(E.TEN(t,shape)::param, i)=let
58                    val shape'=List.map(fn e1=>Int.toString(e1)) shape
59                    in String.concat[Int.toString(i), ":TEN", Int.toString t," ", String.concatWith"," shape'," --",Param(param, i+1)]
60                    end
61              | Param(E.FLD(d)::param, i)= String.concat[Int.toString(i), ":FLD-", Int.toString d," ",Param(param, i+1)]              | Param(E.FLD(d)::param, i)= String.concat[Int.toString(i), ":FLD-", Int.toString d," ",Param(param, i+1)]
62                   | Param(E.IMG(d)::param, i)= String.concat[Int.toString(i), ":IMG-", Int.toString d," ",Param(param, i+1)]
63                   | Param(E.KRN::param, i)= String.concat[Int.toString(i), ":KRN ",Param(param, i+1)]
64              | Param(_,_)=""              | Param(_,_)=""
65    
66          val str=String.concat ["\n\t" ,Param(params, 0)," \n \t <",printbody(body),">","\n \t _{",Index(index,0),"} \n "]          val str=String.concat ["" ,Param(params, 0)," <",printbody(body),">"," _{",Index(index,0),"}  "]
67          in          in
68              str              str
69          end          end

Legend:
Removed from v.2496  
changed lines
  Added in v.2533

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