SCM Repository
Annotation of /branches/vis12/src/compiler/tree-il/tree-il.sml
Parent Directory
|
Revision Log
Revision 2023 - (view) (download)
1 : | jhr | 1115 | (* tree-il.sml |
2 : | * | ||
3 : | * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu) | ||
4 : | * All rights reserved. | ||
5 : | * | ||
6 : | * This representation restores the block structure and nested expression syntax | ||
7 : | * of the source language. | ||
8 : | *) | ||
9 : | |||
10 : | structure TreeIL = | ||
11 : | struct | ||
12 : | |||
13 : | structure Op = LowOps | ||
14 : | structure Ty = LowILTypes | ||
15 : | |||
16 : | datatype program = Program of { | ||
17 : | jhr | 1640 | props : StrandUtil.program_prop list, |
18 : | jhr | 1115 | globals : var list, |
19 : | jhr | 1301 | inputInit : block, |
20 : | jhr | 1115 | globalInit : block, |
21 : | strands : strand list, | ||
22 : | initially : { | ||
23 : | isArray : bool, | ||
24 : | iterPrefix : block, | ||
25 : | iters : (var * exp * exp) list, | ||
26 : | createPrefix : block, | ||
27 : | strand : Atom.atom, | ||
28 : | args : exp list | ||
29 : | } | ||
30 : | } | ||
31 : | |||
32 : | and strand = Strand of { | ||
33 : | name : Atom.atom, | ||
34 : | params : var list, | ||
35 : | jhr | 1640 | state : state_var list, |
36 : | jhr | 1115 | stateInit : block, |
37 : | methods : method list | ||
38 : | } | ||
39 : | |||
40 : | jhr | 1640 | and state_var = SV of { |
41 : | name : string, (* name (should be unique) *) | ||
42 : | id : Stamp.stamp, (* unique ID *) | ||
43 : | ty : Ty.ty, (* type *) | ||
44 : | jhr | 1115 | varying : bool, (* varies over the lifetime of the strand *) |
45 : | jhr | 1640 | output : bool (* is the output value of the strand *) |
46 : | jhr | 1115 | } |
47 : | |||
48 : | and method = Method of { | ||
49 : | jhr | 1640 | name : StrandUtil.method_name, |
50 : | jhr | 1115 | body : block (* method body *) |
51 : | } | ||
52 : | |||
53 : | and block = Block of { | ||
54 : | locals : var list, | ||
55 : | body : stm list | ||
56 : | } | ||
57 : | |||
58 : | and stm | ||
59 : | = S_Comment of string list | ||
60 : | jhr | 1640 | | S_Assign of var list * exp |
61 : | jhr | 1115 | | S_IfThen of exp * block |
62 : | | S_IfThenElse of exp * block * block | ||
63 : | (* special Diderot forms *) | ||
64 : | jhr | 2004 | (* DEPRECATED |
65 : | jhr | 1115 | | S_LoadImage of var * int * exp (* load image data *) |
66 : | jhr | 2004 | *) |
67 : | jhr | 2012 | | S_Input of var * string * string option * exp option (* get input *) |
68 : | jhr | 2023 | | S_InputNrrd of var * string * string option * string option (* get image/seq input *) |
69 : | jhr | 1131 | | S_New of Atom.atom * exp list (* new strand creation *) |
70 : | jhr | 1640 | | S_Save of state_var list * exp (* save strand state *) |
71 : | jhr | 1115 | | S_Exit of exp list |
72 : | (* return functions for methods *) | ||
73 : | jhr | 1640 | | S_Active |
74 : | | S_Stabilize | ||
75 : | jhr | 1115 | | S_Die |
76 : | |||
77 : | and exp | ||
78 : | jhr | 1640 | = E_State of state_var |
79 : | | E_Var of var | ||
80 : | jhr | 1115 | | E_Lit of Literal.literal |
81 : | | E_Op of Op.rator * exp list | ||
82 : | jhr | 1922 | | E_Apply of MathFuns.name * exp list |
83 : | jhr | 1115 | | E_Cons of Ty.ty * exp list |
84 : | |||
85 : | and var = V of { | ||
86 : | name : string, (* name (should be unique) *) | ||
87 : | id : Stamp.stamp, (* unique ID *) | ||
88 : | kind : var_kind, | ||
89 : | ty : Ty.ty (* type *) | ||
90 : | } | ||
91 : | |||
92 : | and var_kind | ||
93 : | jhr | 1706 | = VK_Input (* global input variable *) |
94 : | | VK_Global (* global variable *) | ||
95 : | jhr | 1115 | | VK_Local (* includes strand parameters *) |
96 : | |||
97 : | structure Var : sig | ||
98 : | |||
99 : | val kind : var -> var_kind | ||
100 : | val name : var -> string | ||
101 : | val toString : var -> string | ||
102 : | val ty : var -> Ty.ty | ||
103 : | |||
104 : | structure Map : ORD_MAP where type Key.ord_key = var | ||
105 : | |||
106 : | end = struct | ||
107 : | fun kind (V{kind, ...}) = kind | ||
108 : | fun name (V{name, ...}) = name | ||
109 : | fun toString (V{name, id, ...}) = concat[name, "$", Stamp.toString id] | ||
110 : | fun ty (V{ty, ...}) = ty | ||
111 : | local | ||
112 : | structure VarOrd = | ||
113 : | struct | ||
114 : | type ord_key = var | ||
115 : | fun compare (V{id=a, ...}, V{id=b, ...}) = Stamp.compare(a, b) | ||
116 : | end | ||
117 : | in | ||
118 : | structure Map = RedBlackMapFn (VarOrd) | ||
119 : | end (* local *) | ||
120 : | end | ||
121 : | |||
122 : | jhr | 1640 | structure StateVar : sig |
123 : | val name : state_var -> string | ||
124 : | val ty : state_var -> Ty.ty | ||
125 : | val isOutput : state_var -> bool | ||
126 : | val isVarying : state_var -> bool | ||
127 : | val toString : state_var -> string | ||
128 : | end = struct | ||
129 : | fun name (SV{name, ...}) = name | ||
130 : | fun ty (SV{ty, ...}) = ty | ||
131 : | fun isOutput (SV{output, ...}) = output | ||
132 : | fun isVarying (SV{varying, ...}) = varying | ||
133 : | fun toString (SV{name, ...}) = "self." ^ name | ||
134 : | end | ||
135 : | jhr | 1131 | |
136 : | fun kindToString k = (case k | ||
137 : | jhr | 1706 | of VK_Input => "Input" |
138 : | | VK_Global => "Global" | ||
139 : | jhr | 1131 | | VK_Local => "Local" |
140 : | (* end case *)) | ||
141 : | |||
142 : | jhr | 1640 | fun stateVarToString (SV{name, ...}) = "self." ^ name |
143 : | |||
144 : | jhr | 1115 | end |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |