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 3894 - (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 3894 (* loadImage (lhs, dim, name)
12 : jhr 3810 * returns code to load an image from a Nrrd file, where "lhs" is the l-value to hold
13 : jhr 3894 * the image, "dim" specifies the dimension of the image format, and "name" specifies
14 : jhr 3810 * the file name. The generated code check the status of the load attempt and will
15 :     * return "true" (i.e., error) if the load fails.
16 :     *)
17 : jhr 3894 val loadImage : CLang.exp * int * CLang.exp -> CLang.stm
18 : jhr 3810
19 :     (* setImage (lhs, info, nrrd)
20 :     * returns code to initialize an image from a Nrrd, where "lhs" is the l-value to hold
21 : jhr 3894 * the image, "dim" specifies the dimension of the image format, and "nrrd" specifies
22 : jhr 3810 * the nrrd. The generated code check the status of the initialization and will
23 :     * return "true" (i.e., error) if the load fails.
24 :     *)
25 : jhr 3894 val setImage : CLang.exp * int * CLang.exp -> CLang.stm
26 : jhr 3810
27 :     val loadSeqFromFile : CLang.exp * APITypes.t * CLang.exp -> CLang.stm
28 :     val loadSeq : CLang.exp * APITypes.t * CLang.exp -> CLang.stm
29 :    
30 :     end = struct
31 :    
32 :     structure CL = CLang
33 :     structure RN = RuntimeNames
34 :     structure Ty = APITypes
35 :    
36 :     val wrldPrefixTy = CL.T_Ptr(CL.T_Named "WorldBase")
37 :    
38 : jhr 3894 fun doImage imageFn (lhs, dim, arg) = let
39 : jhr 3810 val loadExp = CL.mkApply(imageFn dim, [
40 :     CL.mkCast(wrldPrefixTy, CL.mkVar "wrld"),
41 :     arg,
42 :     CL.mkUnOp(CL.%&, lhs)
43 :     ])
44 :     in
45 :     (* FIXME: we should also generate code to check that the loaded image has the right type, etc. *)
46 :     CL.mkIfThen(loadExp, CL.mkReturn(SOME(CL.mkVar "true")))
47 :     end
48 :    
49 :     val loadImage = doImage RN.loadImage
50 :     val setImage = doImage RN.setImage
51 :    
52 :     fun doSeq loadFn (lhs, elemTy, arg) = let
53 :     val (nDims, dimInit, dimExp, elemTy) = (case elemTy
54 :     of Ty.TensorTy(dims as _::_) => let
55 :     val nDims = List.length dims
56 :     fun lp (_, [], init) = CL.I_Array(List.rev init)
57 :     | lp (i, d::dd, init) =
58 :     lp(i+1, dd, (i, CL.I_Exp(CL.mkInt(IntInf.fromInt d)))::init)
59 :     val dimInit = CL.mkDecl(
60 :     CL.T_Array(CL.T_Named "unsigned int", SOME nDims), "_dims",
61 :     SOME(lp(0, dims, [])))
62 :     in
63 :     (nDims, [dimInit], CL.mkVar "_dims", Ty.realTy)
64 :     end
65 : jhr 3894 | Ty.SeqTy(ty', _) => raise Fail(concat[
66 :     "loading sequences of type ", Ty.toString ty', " not supported yet"
67 :     ])
68 : jhr 3810 | _ => (0, [], CL.mkInt 0, elemTy)
69 :     (* end case *))
70 :     in CL.mkBlock (
71 :     dimInit @ [
72 :     CL.mkAssign(
73 :     lhs,
74 :     CL.mkApply(loadFn elemTy, [
75 :     CL.mkCast(CL.T_Ptr(CL.T_Named "WorldBase"), CL.mkVar "wrld"),
76 :     arg,
77 :     CL.mkInt(IntInf.fromInt nDims),
78 :     dimExp
79 :     ])),
80 :     CL.mkIfThen(
81 :     CL.mkBinOp(lhs, CL.#==, CL.mkInt 0),
82 :     CL.mkReturn(SOME(CL.mkVar "true")))
83 :     ]
84 :     ) end
85 :    
86 :     val loadSeqFromFile = doSeq RN.loadDynSeqFromFile
87 :     val loadSeq = doSeq RN.loadDynSeq
88 :    
89 :     end

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