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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2298 - (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 : lamonts 2098 datatype reduction = datatype AST.reduction
19 :    
20 :     datatype strand_set = datatype AST.strand_set
21 :    
22 : jhr 175 datatype program = Program of {
23 : jhr 2298 inputs : (var * Types.ty Inputs.input) list,
24 :     globals : var list,
25 :     globalInit : block,
26 :     funcs : func list,
27 :     strands : strand list,
28 :     globalBlock : block,
29 :     init : init (* block evaluates any vars used in init *)
30 : jhr 171 }
31 :    
32 : jhr 2298 and func = Func of {
33 :     f : var,
34 :     params : var list,
35 :     body : block
36 :     }
37 :    
38 : jhr 1116 and init = Initially of {
39 : jhr 2298 isArray : bool,
40 :     rangeInit : block,
41 :     iters : {param : var, lo : var, hi : var} list,
42 :     create : create
43 : jhr 1116 }
44 :    
45 :     and create = C_Create of {
46 : jhr 2298 argInit : block,
47 :     name : Atom.atom,
48 :     args : var list
49 : jhr 1116 }
50 :    
51 : jhr 2298 (* do we use this?
52 : jhr 1116 and iter = I_Range of {
53 : jhr 2298 rangeInit : block,
54 :     param : var,
55 :     lo : var,
56 :     hi : var
57 : jhr 1116 }
58 : jhr 2298 *)
59 : jhr 1116
60 : jhr 511 and strand = Strand of {
61 : jhr 2298 name : Atom.atom,
62 :     params : var list,
63 :     state : var list,
64 :     stateInit : block,
65 :     methods : method list
66 : jhr 171 }
67 :    
68 : jhr 1640 and method = Method of StrandUtil.method_name * block
69 : jhr 171
70 : jhr 192 and block = Block of stmt list
71 :    
72 : jhr 171 and stmt
73 : jhr 2298 = S_Var of var (* introduce an uninitialized local variable. *)
74 :     (* These stmts are needed for the results of *)
75 :     (* conditional expressions *)
76 : jhr 1116 | S_Assign of var * exp
77 : jhr 192 | S_IfThenElse of var * block * block
78 : lamonts 2083 | S_Foreach of var * exp * block
79 : jhr 171 | S_New of Atom.atom * var list
80 :     | S_Die
81 :     | S_Stabilize
82 : jhr 2298 | S_Return of var
83 : jhr 1640 | S_Print of var list
84 : jhr 171
85 :     and exp
86 :     = E_Var of var
87 :     | E_Lit of Literal.literal
88 : jhr 2298 | E_Selector of var * Atom.atom * Types.ty
89 : lamonts 2101 | E_StrandSet of strand_set list * Types.ty
90 : lamonts 2251 | E_Reduction of reduction * var list * Types.ty * Types.ty
91 : jhr 171 | E_Tuple of var list
92 :     | E_Apply of var * Types.meta_var list * var list * Types.ty
93 :     | E_Cons of var list
94 : jhr 1688 | E_Seq of var list
95 : jhr 2298 | E_Slice of var * var option list * Types.ty (* tensor slicing *)
96 : jhr 1687 | E_Coerce of {srcTy : Types.ty, dstTy : Types.ty, x : var}
97 : jhr 2026 | E_LoadSeq of Types.ty * string
98 :     | E_LoadImage of Types.ty * string * ImageInfo.info
99 : jhr 171
100 :     fun typeOf (E_Var x) = Var.monoTypeOf x
101 :     | typeOf (E_Lit lit) = (case lit
102 : jhr 2298 of (Literal.Int _) => Types.T_Int
103 :     | (Literal.Float _) => Types.realTy
104 :     | (Literal.String s) => Types.T_String
105 :     | (Literal.Bool _) => Types.T_Bool
106 :     (* end case *))
107 : lamonts 2098 | typeOf (E_Selector(v,f,ty)) = ty
108 : jhr 171 | typeOf (E_Tuple _) = raise Fail "E_Tuple"
109 : lamonts 2101 | typeOf (E_StrandSet (_,ty)) = ty
110 : lamonts 2251 | typeOf (E_Reduction(_,_,_,ty)) = ty
111 : jhr 171 | typeOf (E_Apply(_, _, _, ty)) = ty
112 : jhr 2016 | typeOf (E_Cons[]) = raise Fail "impossible empty E_Cons"
113 : jhr 171 | typeOf (E_Cons(x::xs)) = let
114 : jhr 2298 val d = List.length xs + 1
115 :     val ty = Var.monoTypeOf x
116 :     in
117 :     case TypeUtil.pruneHead ty
118 :     of Types.T_Tensor shape => Types.T_Tensor(Types.shapeExt(shape, Types.DimConst d))
119 :     | _ => raise Fail(concat[
120 :     "element of tensor construction is ", TypeUtil.toString ty, ", expected tensor"
121 :     ])
122 :     (* end case *)
123 :     end
124 : jhr 1688 | typeOf (E_Seq[]) = raise Fail "empty sequence not supported yet"
125 :     | typeOf (E_Seq(x::xs)) = let
126 : jhr 2298 val d = List.length xs + 1
127 :     val ty = TypeUtil.pruneHead(Var.monoTypeOf x)
128 :     in
129 :     Types.T_Sequence(ty, Types.DimConst d)
130 :     end
131 : jhr 399 | typeOf (E_Slice(_, _, ty)) = ty
132 : jhr 1992 | typeOf (E_Coerce{dstTy, ...}) = dstTy
133 : jhr 2026 | typeOf (E_LoadSeq(ty, _)) = ty
134 :     | typeOf (E_LoadImage(ty, _, _)) = ty
135 : jhr 171
136 :     end

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