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

SCM Repository

[diderot] Diff of /branches/vis12/src/compiler/simplify/simplify.sml
ViewVC logotype

Diff of /branches/vis12/src/compiler/simplify/simplify.sml

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

revision 2812, Sat Nov 8 18:39:08 2014 UTC revision 2813, Sat Nov 8 21:48:17 2014 UTC
# Line 43  Line 43 
43    (* make a block out of a list of statements that are in reverse order *)    (* make a block out of a list of statements that are in reverse order *)
44      fun mkBlock stms = S.Block(List.rev stms)      fun mkBlock stms = S.Block(List.rev stms)
45    
   (* convert an AST expression to an input initialization.  Note that the Diderot grammar  
    * limits the forms of expression that we might encounter in this context.  
    *)  
     fun expToInit (ty, exp) = (case exp  
            of AST.E_Lit(Literal.Int n) => InP.Int n  
             | AST.E_Lit(Literal.Float f) => InP.Real f  
             | AST.E_Lit(Literal.String s) => InP.String s  
             | AST.E_Lit(Literal.Bool b) => InP.Bool b  
             | AST.E_Tuple es => raise Fail "E_Tuple not yet implemented"  
             | AST.E_Cons es => let  
                 val shp = (case ty  
                        of SimpleTypes.T_Tensor shp => shp  
                         | _ => raise Fail "not tensor type"  
                       (* end case *))  
                 fun flatten (AST.E_Lit(Literal.Int n), l) = FloatLit.fromInt n :: l  
                   | flatten (AST.E_Lit(Literal.Float f), l) = f :: l  
                   | flatten (AST.E_Coerce{e, ...}, l) = flatten(e, l)  
                   | flatten (AST.E_Cons es, l) = flattenList (es, l)  
                   | flatten _ = raise Fail "impossible"  
                 and flattenList ([], l) = l  
                   | flattenList (x::xs, l) = flatten(x, flattenList(xs, l))  
                 in  
                   InP.Tensor(shp, Vector.fromList(flattenList (es, [])))  
                 end  
 (*  
             | AST.E_Seq es => ??  
             | AST.E_Coerce{srcTy, dstTy, e} => ??  
 *)  
             | _ => raise Fail "impossible initialization expression"  
           (* end case *))  
   
46      fun inputImage (nrrd, dim, shape) = (      fun inputImage (nrrd, dim, shape) = (
47            case ImageInfo.fromNrrd(NrrdInfo.getInfo nrrd, dim, shape)            case ImageInfo.fromNrrd(NrrdInfo.getInfo nrrd, dim, shape)
48             of NONE => raise Fail(concat["nrrd file \"", nrrd, "\" does not have expected type"])             of NONE => raise Fail(concat["nrrd file \"", nrrd, "\" does not have expected type"])
# Line 90  Line 59 
59    
60      fun simplifyProgram (AST.Program{props, decls}) = let      fun simplifyProgram (AST.Program{props, decls}) = let
61            val inputs = ref []            val inputs = ref []
62              val inputInit = ref []
63            val globals = ref []            val globals = ref []
64            val globalInit = ref []            val globalInit = ref []
65            val funcs = ref []            val funcs = ref []
# Line 142  Line 112 
112                        end                        end
113                    | AST.D_Input(x, desc, SOME e) => let                    | AST.D_Input(x, desc, SOME e) => let
114                        val (x', env) = cvtVar(env, x)                        val (x', env) = cvtVar(env, x)
115                          val (stms, e') = simplifyExp (env, e, [])
116                        val inp = InP.INP{                        val inp = InP.INP{
117                                ty = SimpleVar.typeOf x',                                ty = SimpleVar.typeOf x',
118                                name = SimpleVar.nameOf x',                                name = SimpleVar.nameOf x',
119                                desc = desc,                                desc = desc,
120                                init = SOME(expToInit(SimpleVar.typeOf x', e))                                init = NONE
121                              }                              }
122                        in                        in
123                          inputs := (x', inp) :: !inputs;                          inputs := (x', inp) :: !inputs;
124                            inputInit := S.S_Assign(x', e') :: (stms @ !inputInit);
125                          env                          env
126                        end                        end
127                    | AST.D_Var(AST.VD_Decl(x, e)) => let                    | AST.D_Var(AST.VD_Decl(x, e)) => let
# Line 182  Line 154 
154            in            in
155              S.Program{              S.Program{
156                  props = props,                  props = props,
157                    inputDefaults = mkBlock (!inputInit),
158                  inputs = List.rev(!inputs),                  inputs = List.rev(!inputs),
159                  globals = List.rev(!globals),                  globals = List.rev(!globals),
160                  globalInit = mkBlock (!globalInit),                  globalInit = mkBlock (!globalInit),

Legend:
Removed from v.2812  
changed lines
  Added in v.2813

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