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

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