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 3453 - (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 3446 datatype init_from_nrrd
25 :     = DynSeq of string
26 :     | Proxy of string * ImageInfo.info (* input image specified by proxy *)
27 :     | Image of ImageInfo.info (* input image w/o proxy *)
28 : jhr 3416
29 : jhr 3446 datatype input = INP of { (* global input variable *)
30 :     var : var, (* the global variable *)
31 :     desc : string option, (* the optional descriptor *)
32 :     init : init_from_nrrd option (* the optional initialization *)
33 : jhr 3416 }
34 :    
35 :     datatype program = Program of {
36 : jhr 3431 props : Properties.t list,
37 : jhr 3430 (* consts? *)
38 : jhr 3446 inputs : input list, (* input globals *)
39 : jhr 3416 globals : var list, (* non-input globals *)
40 :     funcs : func list,
41 : jhr 3451 init : block,
42 : jhr 3446 strand : strand,
43 : jhr 3453 create : create,
44 : jhr 3430 update : block option
45 : jhr 3416 }
46 :    
47 :     and func = Func of {
48 :     f : var,
49 :     params : var list,
50 :     body : block
51 :     }
52 :    
53 :     and strand = Strand of {
54 :     name : Atom.atom,
55 :     params : var list,
56 :     state : var list,
57 :     stateInit : block,
58 : jhr 3451 initM : block option,
59 :     updateM : block,
60 :     stabilizeM : block option
61 : jhr 3416 }
62 :    
63 : jhr 3453 (* initial-strands creation; the stmt will be a loop nest with a "new" as the body *)
64 :     and create
65 :     = C_Grid of int * block (* grid; first argument specifies dimension *)
66 :     | C_Collection of block (* collection *)
67 :    
68 : jhr 3416 and block = Block of stmt list
69 :    
70 :     and stmt
71 :     = S_Var of var (* introduce an uninitialized local variable. *)
72 :     (* These stmts are needed for the results of *)
73 :     (* conditional expressions *)
74 :     | S_Assign of var * exp
75 :     | S_IfThenElse of var * block * block
76 : jhr 3451 | S_Foreach of var * var * block
77 : jhr 3416 | S_New of Atom.atom * var list
78 :     | S_Continue
79 :     | S_Die
80 :     | S_Stabilize
81 :     | S_Return of var
82 :     | S_Print of var list
83 :    
84 :     and exp
85 :     = E_Var of var
86 : jhr 3446 | E_Lit of Literal.t
87 : jhr 3416 | E_Apply of var * var list * ty (* user-defined function *)
88 :     | E_Prim of AST.var * meta_arg list * var list * ty (* Diderot builtin *)
89 : jhr 3452 | E_Tensor of var list * ty
90 : jhr 3416 | E_Seq of var list * ty (* sequence (ty is result type) *)
91 :     | E_Slice of var * var option list * ty (* tensor slicing (ty is result type) *)
92 :     | E_Coerce of {srcTy : ty, dstTy : ty, x : var}
93 :     | E_LoadSeq of ty * string
94 :     | E_LoadImage of ty * string * ImageInfo.info
95 :    
96 : jhr 3446 fun typeOf (E_Var x) = SimpleVar.typeOf x
97 : jhr 3416 | typeOf (E_Lit lit) = (case lit
98 :     of (Literal.Int _) => SimpleTypes.T_Int
99 : jhr 3446 | (Literal.Real _) => SimpleTypes.T_Tensor[]
100 : jhr 3416 | (Literal.String s) => SimpleTypes.T_String
101 :     | (Literal.Bool _) => SimpleTypes.T_Bool
102 :     (* end case *))
103 :     | typeOf (E_Apply(_, _, ty)) = ty
104 :     | typeOf (E_Prim(_, _, _, ty)) = ty
105 : jhr 3452 | typeOf (E_Tensor(_, ty)) = ty
106 : jhr 3416 | typeOf (E_Seq(_, ty)) = ty
107 :     | typeOf (E_Slice(_, _, ty)) = ty
108 :     | typeOf (E_Coerce{dstTy, ...}) = dstTy
109 :     | typeOf (E_LoadSeq(ty, _)) = ty
110 :     | typeOf (E_LoadImage(ty, _, _)) = ty
111 :    
112 :     end

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