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

SCM Repository

[diderot] View of /branches/pure-cfg/src/compiler/c-util/nrrd-types.sml
ViewVC logotype

View of /branches/pure-cfg/src/compiler/c-util/nrrd-types.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1479 - (download) (annotate)
Fri Sep 2 14:17:54 2011 UTC (9 years, 3 months ago) by nseltzer
File size: 2296 byte(s)
Moved output proceedure to seperate file and updated c-target to use new output.
(* nrrd-types.sml
 *
 * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 *
 * NOTE: we may want to generate this file at configure time so that we don't
 * have to track the nrrd type codes by hand
 *)

structure NrrdTypes =
  struct

    local
      structure N = CNames
      structure Ty = TreeIL.Ty
    in

  (* integer codes for nrrd types (must track nrrdEnums.h) *)
    val nrrdTypeUnknown : IntInf.int = 0
    val nrrdTypeInt : IntInf.int = 5
    val nrrdTypeLLong : IntInf.int = 7
    val nrrdTypeFloat : IntInf.int = 9
    val nrrdTypeDouble : IntInf.int = 10

  (* translate a TreeIL type to its nrrd representation *)
    fun toNrrdType ty = (case ty
          of Ty.BoolTy => nrrdTypeUnknown
           | Ty.StringTy => nrrdTypeUnknown
           | Ty.IVecTy 1 => (if !N.doublePrecision then nrrdTypeLLong else nrrdTypeInt)
           | Ty.IVecTy n => (if !N.doublePrecision then nrrdTypeLLong else nrrdTypeInt)
           | Ty.TensorTy[] => (if !N.doublePrecision then nrrdTypeDouble else nrrdTypeFloat)
           | Ty.TensorTy[n] => (if !N.doublePrecision then nrrdTypeDouble else nrrdTypeFloat)
           | Ty.TensorTy[n, m] => (if !N.doublePrecision then nrrdTypeDouble else nrrdTypeFloat)
           | Ty.AddrTy(ImageInfo.ImgInfo{...}) => nrrdTypeUnknown
           | Ty.ImageTy(ImageInfo.ImgInfo{...}) => nrrdTypeUnknown
           | _ => raise Fail(concat["trNrrdType(", Ty.toString ty, ")"])
         (* end case *))

  (* translate a TreeIL type and shape to the correct size in memory *)
    fun toNrrdSize ty = let
        val num : IntInf.int = (case ty
          of Ty.BoolTy => 0 : IntInf.int
           | Ty.StringTy => 0 : IntInf.int
           | Ty.IVecTy 1 => 1 : IntInf.int
           | Ty.IVecTy n => IntInf.fromInt n
           | Ty.TensorTy[] => 1 : IntInf.int
           | Ty.TensorTy[n] => IntInf.fromInt n
           | Ty.TensorTy[n, m] => IntInf.fromInt (n * m)
           | Ty.AddrTy(ImageInfo.ImgInfo{...}) => 0 : IntInf.int
           | Ty.ImageTy(ImageInfo.ImgInfo{...}) => 0 : IntInf.int
           | _ => raise Fail(concat["trNrrdType(", Ty.toString ty, ")"])
         (* end case *))
        in 
            num * (if !N.doublePrecision then 8 else 4)
        end

    end (* local *)
  end

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