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 1444 - (view) (download)
Original Path: trunk/src/compiler/simplify/simple.sml

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 1444 and method = Method of MethodName.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 :    
67 :     and exp
68 :     = E_Var of var
69 :     | E_Lit of Literal.literal
70 :     | E_Tuple of var list
71 :     | E_Apply of var * Types.meta_var list * var list * Types.ty
72 :     | E_Cons of var list
73 : jhr 399 | E_Slice of var * var option list * Types.ty (* tensor slicing *)
74 : jhr 1301 | E_Input of Types.ty * string * string * var option
75 : jhr 1116 | E_LoadImage of ImageInfo.info * var
76 : jhr 171
77 :     fun typeOf (E_Var x) = Var.monoTypeOf x
78 :     | typeOf (E_Lit lit) = (case lit
79 :     of (Literal.Int _) => Types.T_Int
80 :     | (Literal.Float _) => Types.realTy
81 :     | (Literal.String s) => Types.T_String
82 :     | (Literal.Bool _) => Types.T_Bool
83 :     (* end case *))
84 :     | typeOf (E_Tuple _) = raise Fail "E_Tuple"
85 :     | typeOf (E_Apply(_, _, _, ty)) = ty
86 :     | typeOf (E_Cons(x::xs)) = let
87 :     val d = List.length xs + 1
88 :     val ty = Var.monoTypeOf x
89 :     in
90 :     case ty
91 :     of Types.T_Tensor shape => Types.T_Tensor(Types.shapeExt(shape, Types.DimConst d))
92 :     | _ => raise Fail "element of tensor construction not tensor"
93 :     (* end case *)
94 :     end
95 :     | typeOf (E_Cons[]) = raise Fail "impossible empty E_Cons"
96 : jhr 399 | typeOf (E_Slice(_, _, ty)) = ty
97 : jhr 1301 | typeOf (E_Input(ty, _, _, _)) = ty
98 : jhr 1116 | typeOf (E_LoadImage(ImageInfo.ImgInfo{dim, ty=(dd, _), ...}, _)) =
99 :     Types.T_Image{
100 :     dim = Types.DimConst dim,
101 :     shape = Types.Shape(List.map Types.DimConst dd)
102 :     }
103 : jhr 171
104 :     end

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