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

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