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

SCM Repository

[diderot] View of /branches/vis12/src/compiler/inputs/inputs.sml
ViewVC logotype

View of /branches/vis12/src/compiler/inputs/inputs.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2056 - (download) (annotate)
Wed Oct 24 12:46:03 2012 UTC (6 years, 11 months ago) by jhr
File size: 3035 byte(s)
  fix high to mid translation to handle image inputs
(* inputs.sml
 *
 * COPYRIGHT (c) 2012 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 *
 * Common representation for tracking inputs through the passes of the compiler.
 *)

structure Inputs : sig

    datatype initialization
      = String of string
      | Bool of bool
      | Int of IntInf.int
      | Real of FloatLit.float
      | Tensor of int list * FloatLit.float vector
      | Seq of initialization list
      | DynSeq of string
      | Proxy of string * ImageInfo.info		(* input image specified by proxy *)
      | Image of ImageInfo.info				(* input image w/o proxy *)

    datatype 'ty input = INP of {
	ty : 'ty,
	name : string,
	desc : string option,
	init : initialization option
      }

    val same : 'a input * 'a input -> bool

    val hash : 'a input -> word

    val initToString : initialization -> string

    val toString : 'ty input -> string

    val imageInfo : 'ty input -> ImageInfo.info option

  (* type conversion *)
    val map : ('a -> 'b) -> 'a input -> 'b input

  end = struct

  (* initialization of input variables *)
    datatype initialization
      = String of string
      | Bool of bool
      | Int of IntInf.int
      | Real of FloatLit.float
      | Tensor of int list * FloatLit.float vector
      | Seq of initialization list
      | DynSeq of string
      | Proxy of string * ImageInfo.info
      | Image of ImageInfo.info

    datatype 'ty input = INP of {
	ty : 'ty,
	name : string,
	desc : string option,
	init : initialization option
      }

    fun same (INP{name=n1, ...}, INP{name=n2, ...}) = (n1 = n2)

    fun hash (INP{name, ...}) = HashString.hashString name

    fun initToString (String s) = String.concat["\"", String.toString s, "\""]
      | initToString (Bool b) = Bool.toString b
      | initToString (Int n) = if (n < 0) then "-" ^ IntInf.toString(~n) else IntInf.toString n
      | initToString (Real f) = FloatLit.toString f
      | initToString (Tensor(dims, vals)) = "[...]"
      | initToString (Seq vs) = String.concat["{", String.concatWith "," (List.map initToString vs), "}"]
      | initToString (DynSeq name) = String.concat["load(\"", name, "\")"]
      | initToString (Proxy(name, _)) = String.concat["image(\"", name, "\")"]
      | initToString (Image info) = ImageInfo.toString info

    fun toString (INP{name, desc=NONE, init=NONE, ...}) = name
      | toString (INP{name, desc=SOME desc, init=NONE, ...}) =
	  String.concat[name, "(\"", String.toString desc, "\""]
      | toString (INP{name, desc=NONE, init=SOME v, ...}) =
	  String.concat[name, " = ", initToString v]
      | toString (INP{name, desc=SOME desc, init=SOME v, ...}) =
	  String.concat[name, "(\"", String.toString desc, "\") = ", initToString v]

    fun imageInfo (INP{init=SOME(Proxy(_, info)), ...}) = SOME info
      | imageInfo (INP{init=SOME(Image info), ...}) = SOME info
      | imageInfo _ = NONE

  (* type conversion *)
    fun map f (INP{ty, name, desc, init}) = INP{ty = f ty, name = name, desc = desc, init = init}

  end

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