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

SCM Repository

[diderot] Annotation of /branches/vis15/src/compiler/cxx-util/gen-load-nrrd.sml
ViewVC logotype

Annotation of /branches/vis15/src/compiler/cxx-util/gen-load-nrrd.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3988 - (view) (download)

1 : jhr 3810 (* gen-load-nrrd.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 :    
9 :     structure GenLoadNrrd : sig
10 :    
11 : jhr 3900 (* loadImage (img, arg)
12 :     * returns code to load an image from either a Nrrd file or an in-memory Nrrd, where
13 :     * "lhs" is the image object and arg specifies either the file or nrrd.
14 : jhr 3988 * The generated code checks the status of the load attempt and will return "true"
15 : jhr 3900 * (i.e., error) if the load fails.
16 : jhr 3810 *)
17 : jhr 3900 val loadImage : CLang.exp * CLang.exp -> CLang.stm
18 : jhr 3810
19 : jhr 3988 val loadSeqFromFile : CodeGenEnv.t * CLang.exp * APITypes.t * CLang.exp -> CLang.stm
20 :     val loadSeq : CodeGenEnv.t * CLang.exp * APITypes.t * CLang.exp -> CLang.stm
21 : jhr 3810
22 :     end = struct
23 :    
24 :     structure CL = CLang
25 : jhr 3906 structure RN = CxxNames
26 : jhr 3810 structure Ty = APITypes
27 :    
28 : jhr 3988 val wrldV = CL.mkVar "wrld"
29 :    
30 : jhr 3900 fun loadImage (img, arg) = let
31 : jhr 3988 val loadExp = CL.mkApplyExp(CL.mkSelect(img, "load"), [wrldV, arg])
32 : jhr 3810 in
33 :     (* FIXME: we should also generate code to check that the loaded image has the right type, etc. *)
34 :     CL.mkIfThen(loadExp, CL.mkReturn(SOME(CL.mkVar "true")))
35 :     end
36 :    
37 : jhr 3988 fun loadSeq loadFn (env, lhs, elemTy, file) = let
38 :     val stsDcl = CL.mkDecl(CL.boolTy, "sts", NONE)
39 :     val stsV = CL.mkVar "sts"
40 :     val loadExp = CL.mkTemplateApply(loadFn,
41 :     [TypeToCxx.trAPIType(env, elemTy)],
42 :     [wrldV, file, stsV])
43 :     in
44 :     CL.mkBlock [
45 :     stsDcl,
46 :     CL.mkAssign (lhs, loadExp),
47 :     CL.mkIfThen (stsV, CL.mkReturn(SOME(CL.mkVar "true")))
48 :     ]
49 :     end
50 : jhr 3810
51 : jhr 3988 val loadSeqFromFile = loadSeq RN.loadDynSeqFromFile
52 :     val loadSeq = loadSeq RN.loadDynSeq
53 : jhr 3810
54 :     end

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