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

SCM Repository

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

Annotation of /branches/vis12/src/compiler/simplify/simple.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1793 - (view) (download)

1 : jhr 171 (* simple.sml
2 :     *
3 : jhr 435 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 : jhr 171 * All rights reserved.
5 :     *
6 : jhr 511 * A simplified AST representation of a Diderot program. This representation has the property
7 :     * that the arguments to ifs, operators, etc. are variables and that the rhs of assignments
8 :     * consist of a single operation. It is not, however, a single-assignment representation.
9 : jhr 171 *)
10 :    
11 :     structure Simple =
12 :     struct
13 :    
14 :     datatype var_kind = datatype AST.var_kind
15 :    
16 :     datatype var = datatype AST.var
17 :    
18 : jhr 175 datatype program = Program of {
19 : jhr 171 globals : var list,
20 : jhr 192 globalInit : block,
21 : jhr 1116 strands : strand list,
22 :     init : init (* block evaluates any vars used in init *)
23 : jhr 171 }
24 :    
25 : jhr 1116 and init = Initially of {
26 :     isArray : bool,
27 :     rangeInit : block,
28 :     iters : {param : var, lo : var, hi : var} list,
29 :     create : create
30 :     }
31 :    
32 :     and create = C_Create of {
33 :     argInit : block,
34 :     name : Atom.atom,
35 :     args : var list
36 :     }
37 :    
38 :     and iter = I_Range of {
39 :     rangeInit : block,
40 :     param : var,
41 :     lo : var,
42 :     hi : var
43 :     }
44 :    
45 : jhr 511 and strand = Strand of {
46 : jhr 173 name : Atom.atom,
47 : jhr 171 params : var list,
48 :     state : var list,
49 : jhr 192 stateInit : block,
50 : jhr 171 methods : method list
51 :     }
52 :    
53 : jhr 1640 and method = Method of StrandUtil.method_name * block
54 : jhr 171
55 : jhr 192 and block = Block of stmt list
56 :    
57 : jhr 171 and stmt
58 : jhr 1116 = S_Var of var (* introduce an uninitialized local variable. *)
59 :     (* These stmts are needed for the results of *)
60 :     (* conditional expressions *)
61 :     | S_Assign of var * exp
62 : jhr 192 | S_IfThenElse of var * block * block
63 : jhr 171 | S_New of Atom.atom * var list
64 :     | S_Die
65 :     | S_Stabilize
66 : jhr 1640 | S_Print of var list
67 : jhr 171
68 :     and exp
69 :     = E_Var of var
70 :     | E_Lit of Literal.literal
71 :     | E_Tuple of var list
72 :     | E_Apply of var * Types.meta_var list * var list * Types.ty
73 :     | E_Cons of var list
74 : jhr 1688 | E_Seq of var list
75 : jhr 399 | E_Slice of var * var option list * Types.ty (* tensor slicing *)
76 : jhr 1301 | E_Input of Types.ty * string * string * var option
77 : jhr 1116 | E_LoadImage of ImageInfo.info * var
78 : jhr 1687 | E_Coerce of {srcTy : Types.ty, dstTy : Types.ty, x : var}
79 : jhr 171
80 :     fun typeOf (E_Var x) = Var.monoTypeOf x
81 :     | typeOf (E_Lit lit) = (case lit
82 :     of (Literal.Int _) => Types.T_Int
83 :     | (Literal.Float _) => Types.realTy
84 :     | (Literal.String s) => Types.T_String
85 :     | (Literal.Bool _) => Types.T_Bool
86 :     (* end case *))
87 :     | typeOf (E_Tuple _) = raise Fail "E_Tuple"
88 :     | typeOf (E_Apply(_, _, _, ty)) = ty
89 :     | typeOf (E_Cons(x::xs)) = let
90 :     val d = List.length xs + 1
91 :     val ty = Var.monoTypeOf x
92 :     in
93 :     case ty
94 :     of Types.T_Tensor shape => Types.T_Tensor(Types.shapeExt(shape, Types.DimConst d))
95 :     | _ => raise Fail "element of tensor construction not tensor"
96 :     (* end case *)
97 :     end
98 :     | typeOf (E_Cons[]) = raise Fail "impossible empty E_Cons"
99 : jhr 1688 | typeOf (E_Seq[]) = raise Fail "empty sequence not supported yet"
100 :     | typeOf (E_Seq(x::xs)) = let
101 :     val d = List.length xs + 1
102 :     val ty = Var.monoTypeOf x
103 :     in
104 :     Types.T_Sequence(ty, Types.DimConst d)
105 :     end
106 : jhr 399 | typeOf (E_Slice(_, _, ty)) = ty
107 : jhr 1301 | typeOf (E_Input(ty, _, _, _)) = ty
108 : jhr 1793 | typeOf (E_LoadImage(info, _)) =
109 : jhr 1116 Types.T_Image{
110 : jhr 1793 dim = Types.DimConst(ImageInfo.dim info),
111 :     shape = Types.Shape(List.map Types.DimConst (ImageInfo.voxelShape info))
112 : jhr 1116 }
113 : jhr 171
114 :     end

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