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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3682 - (download) (annotate)
Thu Feb 18 20:13:18 2016 UTC (4 years, 5 months ago) by cchiw
File size: 2963 byte(s)
creating stable branch that represents ein ir
(* inputs.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.
 *
 * 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
      | 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
      | 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 (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