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 3900 - (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 :     structure RN = RuntimeNames
26 :     structure Ty = APITypes
27 :    
28 :     val wrldPrefixTy = CL.T_Ptr(CL.T_Named "WorldBase")
29 :    
30 : jhr 3900 fun loadImage (img, arg) = let
31 :     val loadExp = CL.mkApplyExp(CL.mkSelect(img, "load"), [CL.mkVar "wrld", 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 :     fun doSeq loadFn (lhs, elemTy, arg) = let
38 :     val (nDims, dimInit, dimExp, elemTy) = (case elemTy
39 :     of Ty.TensorTy(dims as _::_) => let
40 :     val nDims = List.length dims
41 :     fun lp (_, [], init) = CL.I_Array(List.rev init)
42 :     | lp (i, d::dd, init) =
43 :     lp(i+1, dd, (i, CL.I_Exp(CL.mkInt(IntInf.fromInt d)))::init)
44 :     val dimInit = CL.mkDecl(
45 :     CL.T_Array(CL.T_Named "unsigned int", SOME nDims), "_dims",
46 :     SOME(lp(0, dims, [])))
47 :     in
48 :     (nDims, [dimInit], CL.mkVar "_dims", Ty.realTy)
49 :     end
50 : jhr 3894 | Ty.SeqTy(ty', _) => raise Fail(concat[
51 :     "loading sequences of type ", Ty.toString ty', " not supported yet"
52 :     ])
53 : jhr 3810 | _ => (0, [], CL.mkInt 0, elemTy)
54 :     (* end case *))
55 :     in CL.mkBlock (
56 :     dimInit @ [
57 :     CL.mkAssign(
58 :     lhs,
59 :     CL.mkApply(loadFn elemTy, [
60 :     CL.mkCast(CL.T_Ptr(CL.T_Named "WorldBase"), CL.mkVar "wrld"),
61 :     arg,
62 :     CL.mkInt(IntInf.fromInt nDims),
63 :     dimExp
64 :     ])),
65 :     CL.mkIfThen(
66 :     CL.mkBinOp(lhs, CL.#==, CL.mkInt 0),
67 :     CL.mkReturn(SOME(CL.mkVar "true")))
68 :     ]
69 :     ) end
70 :    
71 :     val loadSeqFromFile = doSeq RN.loadDynSeqFromFile
72 :     val loadSeq = doSeq RN.loadDynSeq
73 :    
74 :     end

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