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

SCM Repository

[diderot] View of /branches/vis15/src/compiler/cxx-util/gen-load-nrrd.sml
ViewVC logotype

View of /branches/vis15/src/compiler/cxx-util/gen-load-nrrd.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3988 - (download) (annotate)
Fri Jun 17 17:26:51 2016 UTC (3 years, 9 months ago) by jhr
File size: 1685 byte(s)
working on merge
(* gen-load-nrrd.sml
 *
 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
 *
 * COPYRIGHT (c) 2015 The University of Chicago
 * All rights reserved.
 *)

structure GenLoadNrrd : sig

  (* loadImage (img, arg)
   *    returns code to load an image from either a Nrrd file or an in-memory Nrrd, where
   *    "lhs" is the image object and arg specifies either the file or nrrd.
   *    The generated code checks the status of the load attempt and will return "true"
   *    (i.e., error) if the load fails.
   *)
    val loadImage : CLang.exp * CLang.exp -> CLang.stm

    val loadSeqFromFile : CodeGenEnv.t * CLang.exp * APITypes.t * CLang.exp -> CLang.stm
    val loadSeq : CodeGenEnv.t * CLang.exp * APITypes.t * CLang.exp -> CLang.stm

  end = struct

    structure CL = CLang
    structure RN = CxxNames
    structure Ty = APITypes

    val wrldV = CL.mkVar "wrld"

    fun loadImage (img, arg) = let
	  val loadExp = CL.mkApplyExp(CL.mkSelect(img, "load"), [wrldV, arg])
          in
(* FIXME: we should also generate code to check that the loaded image has the right type, etc. *)
            CL.mkIfThen(loadExp, CL.mkReturn(SOME(CL.mkVar "true")))
          end

    fun loadSeq loadFn (env, lhs, elemTy, file) = let
	  val stsDcl = CL.mkDecl(CL.boolTy, "sts", NONE)
	  val stsV = CL.mkVar "sts"
	  val loadExp = CL.mkTemplateApply(loadFn,
		[TypeToCxx.trAPIType(env, elemTy)],
		[wrldV, file, stsV])
	  in
	    CL.mkBlock [
		stsDcl,
		CL.mkAssign (lhs, loadExp),
		CL.mkIfThen (stsV, CL.mkReturn(SOME(CL.mkVar "true")))
	      ]
	  end

    val loadSeqFromFile = loadSeq RN.loadDynSeqFromFile
    val loadSeq = loadSeq RN.loadDynSeq

  end

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