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

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