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

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