(* gen-load-nrrd.sml * * COPYRIGHT (c) 2012 The Diderot Project (http://diderot-language.cs.uchicago.edu) * All rights reserved. *) structure GenLoadNrrd : sig (* loadImage (lhs, info, name) * returns code to load an image from a Nrrd file, where "lhs" is the l-value to hold * the image, "info" specifies information about the image format, and "name" specifies * the file name. The generated code check the status of the load attempt and will * return "true" (i.e., error) if the load fails. *) val loadImage : CLang.exp * ImageInfo.info * CLang.exp -> CLang.stm (* setImage (lhs, info, nrrd) * returns code to initialize an image from a Nrrd, where "lhs" is the l-value to hold * the image, "info" specifies information about the image format, and "nrrd" specifies * the nrrd. The generated code check the status of the initialization and will * return "true" (i.e., error) if the load fails. *) val setImage : CLang.exp * ImageInfo.info * CLang.exp -> CLang.stm end = struct structure CL = CLang structure N = CNames val wrldPrefixTy = CL.T_Ptr(CL.T_Named "WorldPrefix_t") fun doImage imageFn (lhs, info, arg) = let val sts = "_sts" val dim = ImageInfo.dim info in CL.mkBlock [ CL.mkDecl( CL.T_Named N.statusTy, sts, SOME(CL.I_Exp(CL.E_Apply(imageFn dim, [ CL.mkCast(wrldPrefixTy, CL.mkVar "wrld"), arg, CL.mkUnOp(CL.%&, lhs) ])))), (* FIXME: we should also generate code to check that the loaded image has the right type, etc. *) CL.mkIfThen( CL.mkBinOp(CL.mkVar "DIDEROT_OK", CL.#!=, CL.mkVar sts), CL.mkReturn(SOME(CL.mkVar "true"))) ] end val loadImage = doImage N.loadImage val setImage = doImage N.setImage end (* | IL.S_LoadNrrd(lhs, Ty.DynSeqTy ty, nrrd) => let val lhs = VarToC.lvalueVar (env, lhs) val (nDims, dimInit, dimExp, elemTy) = (case ty of Ty.TensorTy(dims as _::_) => let val nDims = List.length dims fun lp (_, [], init) = CL.I_Array(List.rev init) | lp (i, d::dd, init) = lp(i+1, dd, (i, CL.I_Exp(CL.mkInt(IntInf.fromInt d)))::init) val dimInit = CL.mkDecl( CL.T_Ptr(CL.T_Named "unsigned int"), "_dims", SOME(lp(0, dims, []))) in (nDims, [dimInit], CL.mkVar "_dims", Ty.TensorTy[]) end | Ty.SeqTy ty' => raise Fail "type not supported yet" | _ => (0, [], CL.mkInt 0, ty) (* end case *)) val loadFn = N.loadDynSeqFromFile elemTy in [CL.mkBlock ( dimInit @ [ CL.mkAssign( lhs, CL.E_Apply(loadFn, [ CL.mkCast(CL.T_Ptr(CL.T_Named "WorldPrefix_t"), CL.mkVar "wrld"), CL.mkStr nrrd, CL.mkInt(IntInf.fromInt nDims), dimExp ])), CL.mkIfThen( CL.mkBinOp(lhs, CL.#==, CL.mkInt 0), CL.mkReturn(SOME(CL.mkVar "true"))) ] )] end *)
Click to toggle
does not end with </html> tag
does not end with </body> tag
The output has ended thus: ==, CL.mkInt 0), CL.mkReturn(SOME(CL.mkVar "true"))) ] )] end *)