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

SCM Repository

[diderot] Annotation of /branches/lamont/src/compiler/inputs/inputs.sml
ViewVC logotype

Annotation of /branches/lamont/src/compiler/inputs/inputs.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2011 - (view) (download)
Original Path: branches/vis12/src/compiler/inputs/inputs.sml

1 : jhr 2011 (* inputs.sml
2 :     *
3 :     * COPYRIGHT (c) 2012 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     * All rights reserved.
5 :     *
6 :     * Common representation for tracking inputs through the passes of the compiler.
7 :     *)
8 :    
9 :     structure Inputs : sig
10 :    
11 :     datatype initialization
12 :     = String of string
13 :     | Bool of bool
14 :     | Int of IntInf.int
15 :     | Real of FloatLit.float
16 :     | Tensor of int list * FloatLit.float vector
17 :     | Seq of initialization list
18 :     | DynSeq of string
19 :     | Proxy of string * ImageInfo.info (* input image specified by proxy *)
20 :     | Image of ImageInfo.info (* input image w/o proxy *)
21 :    
22 :     datatype 'ty input = INP of {
23 :     ty : 'ty,
24 :     name : string,
25 :     desc : string option,
26 :     init : initialization option
27 :     }
28 :    
29 :     val same : 'a input * 'a input -> bool
30 :    
31 :     val hash : 'a input -> word
32 :    
33 :     val initToString : initialization -> string
34 :    
35 :     val toString : 'ty input -> string
36 :    
37 :     val imageInfo : 'ty input -> ImageInfo.info option
38 :    
39 :     (* type conversion *)
40 :     val map : ('a -> 'b) -> 'a input -> 'b input
41 :    
42 :     end = struct
43 :    
44 :     (* initialization of input variables *)
45 :     datatype initialization
46 :     = String of string
47 :     | Bool of bool
48 :     | Int of IntInf.int
49 :     | Real of FloatLit.float
50 :     | Tensor of int list * FloatLit.float vector
51 :     | Seq of initialization list
52 :     | DynSeq of string
53 :     | Proxy of string * ImageInfo.info
54 :     | Image of ImageInfo.info
55 :    
56 :     datatype 'ty input = INP of {
57 :     ty : 'ty,
58 :     name : string,
59 :     desc : string option,
60 :     init : initialization option
61 :     }
62 :    
63 :     fun same (INP{name=n1, ...}, INP{name=n2, ...}) = (n1 = n2)
64 :    
65 :     fun hash (INP{name, ...}) = HashString.hashString name
66 :    
67 :     fun initToString (String s) = String.concat["\"", String.toString s, "\""]
68 :     | initToString (Bool b) = Bool.toString b
69 :     | initToString (Int n) = if (n < 0) then "-" ^ IntInf.toString(~n) else IntInf.toString n
70 :     | initToString (Real f) = FloatLit.toString f
71 :     | initToString (Tensor(dims, vals)) = "[...]"
72 :     | initToString (Seq vs) = String.concat["{", String.concatWith "," (List.map initToString vs), "}"]
73 :     | initToString (DynSeq name) = String.concat["load(\"", name, "\")"]
74 :     | initToString (Proxy(name, _)) = String.concat["image(\"", name, "\")"]
75 :     | initToString (Image info) = ImageInfo.toString info
76 :    
77 :     fun toString (INP{name, desc=NONE, init=NONE, ...}) = name
78 :     | toString (INP{name, desc=SOME desc, init=NONE, ...}) =
79 :     String.concat[name, "(\"", String.toString desc, "\""]
80 :     | toString (INP{name, desc=NONE, init=SOME v, ...}) =
81 :     String.concat[name, " = ", initToString v]
82 :     | toString (INP{name, desc=SOME desc, init=SOME v, ...}) =
83 :     String.concat[name, "(\"", String.toString desc, "\") = ", initToString v]
84 :    
85 :     fun imageInfo (INP{init=NONE, ...}) = NONE
86 :     | imageInfo (INP{init=SOME(Proxy(_, info)), ...}) = SOME info
87 :     | imageInfo (INP{init=SOME(Image info), ...}) = SOME info
88 :     | imageInfo _ = raise Fail "imageInfo: not image"
89 :    
90 :     (* type conversion *)
91 :     fun map f (INP{ty, name, desc, init}) = INP{ty = f ty, name = name, desc = desc, init = init}
92 :    
93 :     end

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