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 3349 - (view) (download)

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

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