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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2051 - (view) (download)

1 : jhr 2051 (* 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 :    
30 :     val wrldPrefixTy = CL.T_Ptr(CL.T_Named "WorldPrefix_t")
31 :    
32 :     fun doImage imageFn (lhs, info, arg) = let
33 :     val sts = "_sts"
34 :     val dim = ImageInfo.dim info
35 :     in CL.mkBlock [
36 :     CL.mkDecl(
37 :     CL.T_Named N.statusTy, sts,
38 :     SOME(CL.I_Exp(CL.E_Apply(imageFn dim, [
39 :     CL.mkCast(wrldPrefixTy, CL.mkVar "wrld"),
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.mkReturn(SOME(CL.mkVar "true")))
47 :     ] end
48 :    
49 :    
50 :     val loadImage = doImage N.loadImage
51 :     val setImage = doImage N.setImage
52 :    
53 :     end
54 :    
55 :     (*
56 :     | IL.S_LoadNrrd(lhs, Ty.DynSeqTy ty, nrrd) => let
57 :     val lhs = VarToC.lvalueVar (env, lhs)
58 :     val (nDims, dimInit, dimExp, elemTy) = (case ty
59 :     of Ty.TensorTy(dims as _::_) => let
60 :     val nDims = List.length dims
61 :     fun lp (_, [], init) = CL.I_Array(List.rev init)
62 :     | lp (i, d::dd, init) =
63 :     lp(i+1, dd, (i, CL.I_Exp(CL.mkInt(IntInf.fromInt d)))::init)
64 :     val dimInit = CL.mkDecl(
65 :     CL.T_Ptr(CL.T_Named "unsigned int"), "_dims",
66 :     SOME(lp(0, dims, [])))
67 :     in
68 :     (nDims, [dimInit], CL.mkVar "_dims", Ty.TensorTy[])
69 :     end
70 :     | Ty.SeqTy ty' => raise Fail "type not supported yet"
71 :     | _ => (0, [], CL.mkInt 0, ty)
72 :     (* end case *))
73 :     val loadFn = N.loadDynSeqFromFile elemTy
74 :     in [CL.mkBlock (
75 :     dimInit @ [
76 :     CL.mkAssign(
77 :     lhs,
78 :     CL.E_Apply(loadFn, [
79 :     CL.mkCast(CL.T_Ptr(CL.T_Named "WorldPrefix_t"), CL.mkVar "wrld"),
80 :     CL.mkStr nrrd,
81 :     CL.mkInt(IntInf.fromInt nDims),
82 :     dimExp
83 :     ])),
84 :     CL.mkIfThen(
85 :     CL.mkBinOp(lhs, CL.#==, CL.mkInt 0),
86 :     CL.mkReturn(SOME(CL.mkVar "true")))
87 :     ]
88 :     )] end
89 :     *)

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