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

SCM Repository

[diderot] View of /trunk/src/compiler/c-util/gen-load-nrrd.sml
ViewVC logotype

View of /trunk/src/compiler/c-util/gen-load-nrrd.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2636 - (download) (annotate)
Tue May 27 16:18:36 2014 UTC (5 years ago) by jhr
File size: 1887 byte(s)
  Merging changes from vis12 branch (via staging).  The main change is the new
  syntax for inputs (especially image inputs).
(* 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
    structure Ty = TreeIL.Ty

    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, [
                  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.mkCall("exit", [CL.mkInt 1]))
          ] end


    val loadImage = doImage N.loadImage
    val setImage = doImage N.setImage

  end

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