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

SCM Repository

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

Annotation of /branches/vis15/src/compiler/simple/simple.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3797 - (view) (download)

1 : jhr 3416 (* simple.sml
2 :     *
3 :     * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     *
5 :     * COPYRIGHT (c) 2015 The University of Chicago
6 :     * All rights reserved.
7 :     *
8 :     * A simplified AST representation of a Diderot program. This representation has the property
9 :     * that the arguments to ifs, operators, etc. are variables and that the rhs of assignments
10 :     * consist of a single operation. It is not, however, a single-assignment representation.
11 :     *)
12 :    
13 :     structure Simple =
14 :     struct
15 :    
16 : jhr 3430 type var = SimpleVar.t
17 :    
18 : jhr 3416 (* types with the meta variables resolved *)
19 :     type ty = SimpleTypes.ty
20 :    
21 :     (* resolved meta-variable arguments to basis functions *)
22 :     datatype meta_arg = datatype SimpleTypes.meta_arg
23 :    
24 : jhr 3504 datatype input_init = datatype Inputs.input_init
25 : jhr 3416
26 : jhr 3504 datatype input = datatype Inputs.input
27 : jhr 3416
28 :     datatype program = Program of {
29 : jhr 3431 props : Properties.t list,
30 : jhr 3456 consts : var list, (* constant variables *)
31 : jhr 3504 inputs : var input list, (* input globals *)
32 : jhr 3456 constInit : block, (* code that initializes constants and inputs *)
33 : jhr 3416 globals : var list, (* non-input globals *)
34 :     funcs : func list,
35 : jhr 3451 init : block,
36 : jhr 3446 strand : strand,
37 : jhr 3453 create : create,
38 : jhr 3430 update : block option
39 : jhr 3416 }
40 :    
41 :     and func = Func of {
42 :     f : var,
43 :     params : var list,
44 :     body : block
45 :     }
46 :    
47 :     and strand = Strand of {
48 :     name : Atom.atom,
49 :     params : var list,
50 :     state : var list,
51 :     stateInit : block,
52 : jhr 3451 initM : block option,
53 :     updateM : block,
54 :     stabilizeM : block option
55 : jhr 3416 }
56 :    
57 : jhr 3453 (* initial-strands creation; the stmt will be a loop nest with a "new" as the body *)
58 : jhr 3485 and create = Create of {
59 : jhr 3501 dim : int option, (* grid dimension; NONE for collections *)
60 :     code : block (* the loop nest for creating the strands *)
61 : jhr 3485 }
62 : jhr 3453
63 : jhr 3501 and block = Block of {
64 :     code : stmt list, (* the body of the block *)
65 :     props : PropList.holder (* property list *)
66 :     }
67 : jhr 3416
68 :     and stmt
69 : jhr 3465 = S_Var of var * exp option (* introduce a local variable. The uninitialized *)
70 :     (* form is needed for the results of conditional *)
71 :     (* expressions *)
72 : jhr 3416 | S_Assign of var * exp
73 :     | S_IfThenElse of var * block * block
74 : jhr 3451 | S_Foreach of var * var * block
75 : jhr 3416 | S_New of Atom.atom * var list
76 :     | S_Continue
77 :     | S_Die
78 :     | S_Stabilize
79 :     | S_Return of var
80 :     | S_Print of var list
81 : jhr 3465 (* FIXME: to support fusion of reductions, we'll have to add tuples or change S_Return
82 :     * to support multiple return values.
83 :     *)
84 : jhr 3462 | S_MapReduce of { (* parallel map-reduce *)
85 :     results : var list, (* the results of reduction phase *)
86 :     reductions : AST.var list, (* the reduction operators (one per result) *)
87 :     body : func, (* a function that implements map part *)
88 :     args : var list, (* the invariant arguments to the map phase *)
89 :     source : AST.var (* the set of strands that we map over *)
90 :     }
91 : jhr 3416
92 :     and exp
93 :     = E_Var of var
94 : jhr 3446 | E_Lit of Literal.t
95 : jhr 3456 | E_Select of var * var (* strand-field selection *)
96 : jhr 3416 | E_Apply of var * var list * ty (* user-defined function *)
97 :     | E_Prim of AST.var * meta_arg list * var list * ty (* Diderot builtin *)
98 : jhr 3452 | E_Tensor of var list * ty
99 : jhr 3416 | E_Seq of var list * ty (* sequence (ty is result type) *)
100 : jhr 3797 | E_Slice of var * int option list * ty (* tensor slicing (ty is result type) *)
101 : jhr 3416 | E_Coerce of {srcTy : ty, dstTy : ty, x : var}
102 :     | E_LoadSeq of ty * string
103 :     | E_LoadImage of ty * string * ImageInfo.info
104 :    
105 : jhr 3446 fun typeOf (E_Var x) = SimpleVar.typeOf x
106 : jhr 3416 | typeOf (E_Lit lit) = (case lit
107 :     of (Literal.Int _) => SimpleTypes.T_Int
108 : jhr 3446 | (Literal.Real _) => SimpleTypes.T_Tensor[]
109 : jhr 3416 | (Literal.String s) => SimpleTypes.T_String
110 :     | (Literal.Bool _) => SimpleTypes.T_Bool
111 :     (* end case *))
112 : jhr 3456 | typeOf (E_Select(_, fld)) = SimpleVar.typeOf fld
113 : jhr 3416 | typeOf (E_Apply(_, _, ty)) = ty
114 :     | typeOf (E_Prim(_, _, _, ty)) = ty
115 : jhr 3452 | typeOf (E_Tensor(_, ty)) = ty
116 : jhr 3416 | typeOf (E_Seq(_, ty)) = ty
117 :     | typeOf (E_Slice(_, _, ty)) = ty
118 :     | typeOf (E_Coerce{dstTy, ...}) = dstTy
119 :     | typeOf (E_LoadSeq(ty, _)) = ty
120 :     | typeOf (E_LoadImage(ty, _, _)) = ty
121 :    
122 : jhr 3501 fun newProp initFn = PropList.newProp (fn (Block{props, ...}) => props, initFn)
123 :     fun newFlag () = PropList.newFlag (fn (Block{props, ...}) => props)
124 :    
125 : jhr 3416 end

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