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 3986 - (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 :     * The generated code check the status of the load attempt and will return "true"
15 :     * (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 :     val loadSeqFromFile : CLang.exp * APITypes.t * CLang.exp -> CLang.stm
20 :     val loadSeq : CLang.exp * APITypes.t * CLang.exp -> CLang.stm
21 :    
22 :     end = struct
23 :    
24 :     structure CL = CLang
25 : jhr 3906 structure RN = CxxNames
26 : jhr 3810 structure Ty = APITypes
27 :    
28 : jhr 3900 fun loadImage (img, arg) = let
29 :     val loadExp = CL.mkApplyExp(CL.mkSelect(img, "load"), [CL.mkVar "wrld", arg])
30 : jhr 3810 in
31 :     (* FIXME: we should also generate code to check that the loaded image has the right type, etc. *)
32 :     CL.mkIfThen(loadExp, CL.mkReturn(SOME(CL.mkVar "true")))
33 :     end
34 :    
35 :     fun doSeq loadFn (lhs, elemTy, arg) = let
36 :     val (nDims, dimInit, dimExp, elemTy) = (case elemTy
37 :     of Ty.TensorTy(dims as _::_) => let
38 :     val nDims = List.length dims
39 :     fun lp (_, [], init) = CL.I_Array(List.rev init)
40 :     | lp (i, d::dd, init) =
41 :     lp(i+1, dd, (i, CL.I_Exp(CL.mkInt(IntInf.fromInt d)))::init)
42 :     val dimInit = CL.mkDecl(
43 :     CL.T_Array(CL.T_Named "unsigned int", SOME nDims), "_dims",
44 :     SOME(lp(0, dims, [])))
45 :     in
46 :     (nDims, [dimInit], CL.mkVar "_dims", Ty.realTy)
47 :     end
48 : jhr 3894 | Ty.SeqTy(ty', _) => raise Fail(concat[
49 :     "loading sequences of type ", Ty.toString ty', " not supported yet"
50 :     ])
51 : jhr 3810 | _ => (0, [], CL.mkInt 0, elemTy)
52 :     (* end case *))
53 :     in CL.mkBlock (
54 :     dimInit @ [
55 :     CL.mkAssign(
56 :     lhs,
57 :     CL.mkApply(loadFn elemTy, [
58 : jhr 3986 CL.mkVar "wrld",
59 : jhr 3810 arg,
60 :     CL.mkInt(IntInf.fromInt nDims),
61 :     dimExp
62 :     ])),
63 :     CL.mkIfThen(
64 :     CL.mkBinOp(lhs, CL.#==, CL.mkInt 0),
65 :     CL.mkReturn(SOME(CL.mkVar "true")))
66 :     ]
67 :     ) end
68 :    
69 :     val loadSeqFromFile = doSeq RN.loadDynSeqFromFile
70 :     val loadSeq = doSeq RN.loadDynSeq
71 :    
72 :     end

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