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

SCM Repository

[diderot] Annotation of /trunk/src/compiler/c-util/gen-load-nrrd.sml
ViewVC logotype

Annotation of /trunk/src/compiler/c-util/gen-load-nrrd.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2636 - (view) (download)

1 : jhr 2636 (* gen-load-nrrd.sml
2 :     *
3 :     * COPYRIGHT (c) 2012 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     * All rights reserved.
5 :     *)
6 :    
7 :     structure GenLoadNrrd : sig
8 :    
9 :     (* loadImage (lhs, info, name)
10 :     * returns code to load an image from a Nrrd file, where "lhs" is the l-value to hold
11 :     * the image, "info" specifies information about the image format, and "name" specifies
12 :     * the file name. The generated code check the status of the load attempt and will
13 :     * return "true" (i.e., error) if the load fails.
14 :     *)
15 :     val loadImage : CLang.exp * ImageInfo.info * CLang.exp -> CLang.stm
16 :    
17 :     (* setImage (lhs, info, nrrd)
18 :     * returns code to initialize an image from a Nrrd, where "lhs" is the l-value to hold
19 :     * the image, "info" specifies information about the image format, and "nrrd" specifies
20 :     * the nrrd. The generated code check the status of the initialization and will
21 :     * return "true" (i.e., error) if the load fails.
22 :     *)
23 :     val setImage : CLang.exp * ImageInfo.info * CLang.exp -> CLang.stm
24 :    
25 :     end = struct
26 :    
27 :     structure CL = CLang
28 :     structure N = CNames
29 :     structure Ty = TreeIL.Ty
30 :    
31 :     val wrldPrefixTy = CL.T_Ptr(CL.T_Named "WorldPrefix_t")
32 :    
33 :     fun doImage imageFn (lhs, info, arg) = let
34 :     val sts = "_sts"
35 :     val dim = ImageInfo.dim info
36 :     in CL.mkBlock [
37 :     CL.mkDecl(
38 :     CL.T_Named N.statusTy, sts,
39 :     SOME(CL.I_Exp(CL.E_Apply(imageFn dim, [
40 :     arg,
41 :     CL.mkUnOp(CL.%&, lhs)
42 :     ])))),
43 :     (* FIXME: we should also generate code to check that the loaded image has the right type, etc. *)
44 :     CL.mkIfThen(
45 :     CL.mkBinOp(CL.mkVar "DIDEROT_OK", CL.#!=, CL.mkVar sts),
46 :     CL.mkCall("exit", [CL.mkInt 1]))
47 :     ] end
48 :    
49 :    
50 :     val loadImage = doImage N.loadImage
51 :     val setImage = doImage N.setImage
52 :    
53 :     end

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