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 2141 - (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 2012 inputs : (var * Types.ty Inputs.input) list,
20 : jhr 171 globals : var list,
21 : jhr 192 globalInit : block,
22 : jhr 2135 funcs : func list,
23 : jhr 1116 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 :     f : var,
29 :     params : var list,
30 :     body : block
31 :     }
32 :    
33 : jhr 1116 and init = Initially of {
34 :     isArray : bool,
35 :     rangeInit : block,
36 :     iters : {param : var, lo : var, hi : var} list,
37 :     create : create
38 :     }
39 :    
40 :     and create = C_Create of {
41 :     argInit : block,
42 :     name : Atom.atom,
43 :     args : var list
44 :     }
45 :    
46 : jhr 2141 (* do we use this?
47 : jhr 1116 and iter = I_Range of {
48 :     rangeInit : block,
49 :     param : var,
50 :     lo : var,
51 :     hi : var
52 :     }
53 : jhr 2141 *)
54 : jhr 1116
55 : jhr 511 and strand = Strand of {
56 : jhr 173 name : Atom.atom,
57 : jhr 171 params : var list,
58 :     state : var list,
59 : jhr 192 stateInit : block,
60 : jhr 171 methods : method list
61 :     }
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 1116 = S_Var of var (* introduce an uninitialized local variable. *)
69 :     (* These stmts are needed for the results of *)
70 :     (* conditional expressions *)
71 :     | 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 2016 | 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 :     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 :     | 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 :     val d = List.length xs + 1
103 :     val ty = Var.monoTypeOf x
104 :     in
105 :     case ty
106 :     of Types.T_Tensor shape => Types.T_Tensor(Types.shapeExt(shape, Types.DimConst d))
107 :     | _ => raise Fail "element of tensor construction not tensor"
108 :     (* end case *)
109 :     end
110 : jhr 1688 | typeOf (E_Seq[]) = raise Fail "empty sequence not supported yet"
111 :     | typeOf (E_Seq(x::xs)) = let
112 :     val d = List.length xs + 1
113 :     val ty = Var.monoTypeOf x
114 :     in
115 :     Types.T_Sequence(ty, Types.DimConst d)
116 :     end
117 : jhr 399 | typeOf (E_Slice(_, _, ty)) = ty
118 : jhr 1992 | typeOf (E_Coerce{dstTy, ...}) = dstTy
119 : jhr 2026 | typeOf (E_LoadSeq(ty, _)) = ty
120 :     | typeOf (E_LoadImage(ty, _, _)) = ty
121 : jhr 171
122 :     end

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