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

SCM Repository

[diderot] Annotation of /branches/vis12/src/compiler/c-util/runtime-names.sml
ViewVC logotype

Annotation of /branches/vis12/src/compiler/c-util/runtime-names.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3291 - (view) (download)

1 : jhr 1115 (* runtime-names.sml
2 :     *
3 : jhr 3291 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     *
5 :     * COPYRIGHT (c) 2015 The University of Chicago
6 : jhr 1115 * All rights reserved.
7 : jhr 1373 *
8 : jhr 3098 * These are C-code names, types, and variables that are common to all of the targets.
9 :     * Additional names are defined in CTypeNames (scalar and tensor types), and MathNames
10 :     * (math functions).
11 : jhr 1115 *)
12 :    
13 : jhr 3098 structure RuntimeNames : sig
14 : jhr 1115
15 : jhr 3098 (* qualify a name by the target's namespace *)
16 :     val qualifyName : string -> Properties.props -> string
17 :     (* qualify a composite name by the target's namespace *)
18 :     val qualifyName' : string -> (Properties.props * string) -> string
19 : jhr 1115
20 : jhr 3098 (* the name/type of the world type *)
21 :     val worldTyName : Properties.props -> string
22 :     val worldPtrTy : Properties.props -> CLang.ty
23 : jhr 1815
24 : jhr 3098 (* the name/type of the program's global variables struct *)
25 :     val globalsTyName : Properties.props -> string
26 :     val globalsPtrTy : Properties.props -> CLang.ty
27 :    
28 :     (* pointer to scheduler data structure *)
29 :     val schedTyName : Properties.props -> string
30 :     val schedPtrTy : Properties.props -> CLang.ty
31 :    
32 :     (* the name/type of the program's input variables struct *)
33 :     val inputsTyName : Properties.props -> string
34 :     val inputsPtrTy : Properties.props -> CLang.ty
35 :    
36 :     (* the name/type of the program's defined-inputs struct *)
37 :     val definedInpTyName : Properties.props -> string
38 :     val definedInpPtrTy : Properties.props -> CLang.ty
39 :    
40 :     (* the holder for command-line options *)
41 :     val optionsTyName : string
42 :     val optionsPtrTy : CLang.ty
43 :    
44 :     (* names for input and output variable operations *)
45 :     val inputDesc : (Properties.props * string) -> string
46 :     val inputGet : (Properties.props * string) -> string
47 :     val inputSet : (Properties.props * string) -> string
48 :     val inputSetByName : (Properties.props * string) -> string
49 :     val outputGet : (Properties.props * string) -> string
50 :     val snapshotGet : (Properties.props * string) -> string
51 :    
52 :     (* names of generated functions *)
53 :     val initGlobals : string (* function for initializing program globals *)
54 :     val freeGlobals : string (* function for freeing program globals *)
55 :     val initDefaults : string (* function for initializing input defaults *)
56 :     val registerOpts : string (* function for registering command-line options *)
57 :     val registerOutputOpts : string (* function for registering output redirection options *)
58 :     val initInputs : string (* function for initializing global inputs *)
59 :     val initDefined : Properties.props -> string (* function for initializing input-defined flags *)
60 :     val checkDefined : Properties.props -> string (* function for checking input-defined flags *)
61 :     val shutdown : Properties.props -> string (* function that gets called at the end *)
62 :     val initially : Properties.props -> string (* function for creating initial strands *)
63 :     val allocInitially : string (* function for allocating initial strands *)
64 :    
65 :     (* strand initialization function *)
66 :     val strandInit : string -> string
67 :    
68 :     (* the name/type of a strand object *)
69 :     val strandTyName : string -> string
70 :     val strandPtrTy : string -> CLang.ty
71 :    
72 :     val strandDescTy : CLang.ty
73 :     val strandDesc : string -> string
74 :     val strands : string
75 :    
76 :     (* Run-time system functions for images *)
77 :     val setImage : int -> string
78 :     val loadImage : int -> string
79 :     val freeImage : int -> string
80 :    
81 :     (* Run-time system functions for dynamic sequences *)
82 :     val loadDynSeq : TreeIL.Ty.ty -> string
83 :     val loadDynSeqFromFile : TreeIL.Ty.ty -> string
84 :    
85 :     (* functions for defining program-input command-line options *)
86 :     val inputOpt : TreeIL.Ty.ty -> string
87 :    
88 :     (* Status_t symbols *)
89 :     val kActive : string
90 :     val kNew : string
91 :     val kDie : string
92 :     val kStabilize : string
93 :     val kStable : string
94 :    
95 :     (* image types *)
96 :     val imageTyName : int -> string
97 :     val imagePtrTy : int -> CLang.ty
98 :    
99 :     (* function mapping world to image space *)
100 :     val toImageSpace : int -> string
101 :    
102 :     (* function mapping image space to world space *)
103 :     val toWorldSpace : TreeIL.Ty.ty -> string
104 :    
105 :     (* inside test for images *)
106 :     val inside : int -> string
107 :    
108 :     (* image index control operations *)
109 :     val indexControl : int * IndexCtl.ctl -> string
110 :    
111 :     (* pointer to a dynamic sequence *)
112 :     val dynSeqTy : CLang.ty
113 :    
114 :     end = struct
115 :    
116 :     structure Ty = TreeIL.Ty
117 :     structure CL = CLang
118 :    
119 :     fun qualifyName name (tgt : Properties.props) = #namespace tgt ^ name
120 :     fun qualifyName' fixed (tgt : Properties.props, name) =
121 :     concat[#namespace tgt, fixed, "_", name]
122 :     fun ptrTy name = CL.T_Ptr(CL.T_Named name)
123 :    
124 :     (* the name/type of the world type *)
125 :     val worldTyName = qualifyName "World_t"
126 :     fun worldPtrTy tgt = ptrTy(worldTyName tgt)
127 :    
128 :     (* the name/type of the program's global variables struct *)
129 :     val globalsTyName = qualifyName "Globals_t"
130 :     fun globalsPtrTy tgt = ptrTy(globalsTyName tgt)
131 :    
132 :     (* pointer to scheduler data structure *)
133 :     val schedTyName = qualifyName "Sched_t"
134 :     fun schedPtrTy tgt = CL.T_Ptr(CL.T_Named(schedTyName tgt))
135 :    
136 :     (* the name/type of the program's input variables struct *)
137 :     val inputsTyName = qualifyName "Inputs_t"
138 :     fun inputsPtrTy tgt = ptrTy(inputsTyName tgt)
139 :    
140 :     (* the name/type of the program's defined-inputs struct *)
141 :     val definedInpTyName = qualifyName "DefinedInputs_t"
142 :     fun definedInpPtrTy tgt = ptrTy(definedInpTyName tgt)
143 :    
144 :     (* the holder for command-line options *)
145 :     val optionsTyName = "Diderot_Options_t"
146 :     val optionsPtrTy = CL.T_Ptr(CL.T_Named optionsTyName)
147 :    
148 : jhr 1815 (* generate names for input and output variables *)
149 :     val inputDesc = qualifyName' "InVarDesc"
150 :     val inputGet = qualifyName' "InVarGet"
151 :     val inputSet = qualifyName' "InVarSet"
152 :     val inputSetByName = qualifyName' "InVarSetByName"
153 :     val outputGet = qualifyName' "OutputGet"
154 : jhr 1912 val snapshotGet = qualifyName' "Snapshot"
155 : jhr 1815
156 : jhr 1373 (* names of generated types, functions, and globals *)
157 : jhr 3098 val initGlobals = "InitGlobals" (* function for initializing program globals *)
158 :     val freeGlobals = "FreeGlobals" (* function for freeing program globals *)
159 :     val initDefaults = "InitDefaults" (* function for initializing input defaults *)
160 :     val registerOpts = "RegisterGlobalOpts" (* function for registering command-line options *)
161 : jhr 2833 val registerOutputOpts = "RegisterOutputOpts" (* function for registering output redirection options *)
162 : jhr 3098 val initInputs = "InitInputs" (* function for initializing global inputs *)
163 :     val initDefined = qualifyName "InitDefined" (* function for initializing input-defined flags *)
164 :     val checkDefined = qualifyName "ChkDefined" (* function for checking input-defined flags *)
165 :     val shutdown = qualifyName "Shutdown" (* function that gets called at the end *)
166 :     val initially = qualifyName "Initially" (* function for creating initial strands *)
167 :     val allocInitially = "AllocInitially"
168 :    
169 :     (* strand initialization function *)
170 : jhr 1115 fun strandInit strand = strand ^ "_InitState"
171 : jhr 3098
172 :     (* the name/type of a strand object *)
173 :     fun strandTyName strand = concat["Strand_", strand, "_t"]
174 :     fun strandPtrTy strand = ptrTy(strandTyName strand)
175 :    
176 :     val strandDescTy = CL.T_Named "Strand_t"
177 : jhr 1115 fun strandDesc strand = concat["Strand_", strand]
178 :     val strands = "Diderot_Strands"
179 :    
180 : jhr 3098 (* Run-time system functions for images *)
181 : jhr 1807 fun setImage dim = concat["Diderot_SetImage", Int.toString dim, "D"]
182 : jhr 1115 fun loadImage dim = concat["Diderot_LoadImage", Int.toString dim, "D"]
183 : nseltzer 1870 fun freeImage dim = concat["Diderot_FreeImage", Int.toString dim, "D"]
184 : jhr 3098
185 :     (* Run-time system functions for dynamic sequences *)
186 : jhr 1999 fun loadDynSeq ty = (case ty
187 : jhr 3098 of Ty.BoolTy => "Diderot_DynSeqLoadBool"
188 :     | Ty.IntTy => "Diderot_DynSeqLoadInt"
189 :     | Ty.TensorTy _ => "Diderot_DynSeqLoadReal"
190 :     | ty => raise Fail("unsupported sequence type " ^ Ty.toString ty)
191 : jhr 1999 (* end case *))
192 : jhr 2029 fun loadDynSeqFromFile ty = (case ty
193 : jhr 3098 of Ty.BoolTy => "Diderot_DynSeqLoadBoolFromFile"
194 :     | Ty.IntTy => "Diderot_DynSeqLoadIntFromFile"
195 :     | Ty.TensorTy _ => "Diderot_DynSeqLoadRealFromFile"
196 :     | ty => raise Fail("unsupported sequence type " ^ Ty.toString ty)
197 : jhr 2029 (* end case *))
198 : jhr 1115
199 : jhr 3098 (* functions for defining program-input command-line options; note that sequences
200 :     * and images come from nrrd files, which are specified by their filenames.
201 : jhr 2041 *)
202 : jhr 3098 fun inputOpt ty = (case ty
203 :     of Ty.StringTy => "Diderot_OptAddString"
204 :     | Ty.BoolTy => "Diderot_OptAddBool"
205 :     | Ty.IntTy => "Diderot_OptAddInt"
206 :     | Ty.TensorTy[] => "Diderot_OptAddReal"
207 :     | Ty.TensorTy[2] => "Diderot_OptAddReal2"
208 :     | Ty.TensorTy[3] => "Diderot_OptAddReal3"
209 :     | Ty.TensorTy[4] => "Diderot_OptAddReal4"
210 :     | Ty.DynSeqTy _ => "Diderot_OptAddString"
211 : jhr 2041 | Ty.ImageTy _ => "Diderot_OptAddString"
212 : jhr 2030 | ty => raise Fail("unsupported input type " ^ Ty.toString ty)
213 : jhr 3098 (* end case *))
214 : jhr 1115
215 : jhr 3098 (* Status_t symbols *)
216 :     val kActive = "DIDEROT_ACTIVE"
217 :     val kNew = "DIDEROT_NEW"
218 :     val kDie = "DIDEROT_DIE"
219 :     val kStabilize = "DIDEROT_STABILIZE"
220 :     val kStable = "DIDEROT_STABLE"
221 :    
222 :     (* image operations *)
223 :    
224 :     fun imageTyName n = concat["Diderot_image", Int.toString n, "D_t"]
225 :     fun imagePtrTy n = ptrTy(imageTyName n)
226 :    
227 :     fun toImageSpace d = "ToImageSpace" ^ Int.toString d
228 :    
229 :     fun toWorldSpace ty = let
230 :     val suffix = (case ty
231 :     of Ty.TensorTy[d] => [Int.toString d]
232 :     | Ty.TensorTy[m,n] => [Int.toString n, "x", Int.toString n]
233 :     | Ty.TensorTy[m,n,p] => [Int.toString n, "x", Int.toString n, "x", Int.toString p]
234 :     (* end case *))
235 :     in
236 :     concat("ToWorldSpace" :: suffix)
237 :     end
238 :    
239 :     fun inside d = "Inside" ^ Int.toString d
240 :    
241 :     (* image index control operations *)
242 :     fun indexControl (dim, ctl) = concat["Index", IndexCtl.toString ctl, Int.toString dim]
243 :    
244 :     (* pointer to a dynamic sequence *)
245 :     val dynSeqTy = ptrTy "Diderot_DynSeq_t"
246 :    
247 : jhr 1115 end

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