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

SCM Repository

[diderot] Annotation of /trunk/src/compiler/translate/translate-basis.sml
ViewVC logotype

Annotation of /trunk/src/compiler/translate/translate-basis.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 189 - (view) (download)

1 : jhr 180 (* translate-basis.sml
2 :     *
3 :     * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
4 :     * All rights reserved.
5 :     *
6 :     * Translation for basis operations in Simple AST to HighIL code
7 :     *)
8 :    
9 :     structure TranslateBasis : sig
10 :    
11 : jhr 189 (* translate(lhs, f, mvs, args) translates the application of f (specialized
12 :     * to the instantiated meta variables mvs) to a list of SSA assignments in
13 :     * reverse order.
14 :     *)
15 : jhr 180 val translate : (HighIL.var * Var.var * Types.meta_var list * HighIL.var list)
16 : jhr 188 -> HighIL.assign list
17 : jhr 180
18 :     end = struct
19 :    
20 :     structure IL = HighIL
21 :     structure Op = HighOps
22 : jhr 183 structure Ty = Types
23 :     structure TU = TypeUtil
24 :     structure MV = MetaVar
25 : jhr 180
26 : jhr 188 fun assign (y, rator, xs) = [(y, IL.OP(rator, xs))]
27 : jhr 180
28 : jhr 183 fun simpleOP rator (y, [], xs) = assign (y, rator, xs)
29 :    
30 :     fun tensorOP rator (y, [sv], xs) = (case TU.prunShape(MV.toShape sv)
31 :     of Ty.Shape dd => assign (y, IP.OP(rator(Op.TensorTy dd), xs))
32 :     | shp => raise Fail("unresolved shape " ^ TU.shapeToString shp)
33 :     (* end case *))
34 :    
35 : jhr 184 (* build a table that maps Basis variables to their translation functions *)
36 : jhr 180 val tbl = let
37 : jhr 183 val tbl = Var.Tbl.mkTable (128, Fail "Translate table")
38 : jhr 180 in
39 :     List.app (Var.Tbl.insert tbl) [
40 :     (add_ii, simpleOp(OP.Add OP.IntTy)),
41 : jhr 183 (add_tt, tensorOp OP.Add),
42 : jhr 180 (sub_ii, simpleOp(OP.Sub OP.IntTy)),
43 : jhr 183 (sub_tt, tensorOp OP.Sub),
44 : jhr 180 (mul_ii, simpleOp(OP.Mul OP.IntTy)),
45 :     (mul_rr, simpleOp(OP.Mul(OP.TensorTy[]))),
46 : jhr 183 (mul_rt, tensorOp OP.Scale),
47 :     (mul_tr, fn (y, sv, [t, r]) => tensorOp OP.Scale (y, sv, [r, t])),
48 : jhr 180 (div_ii, simpleOp(OP.Div OP.IntTy)),
49 :     (div_rr, simpleOp(OP.Div(OP.TensorTy[]))),
50 : jhr 184 (div_tr, tensorOp OP.InvScale),
51 : jhr 180 (lt_ii, simpleOp(OP.LT OP.IntTy)),
52 :     (lt_rr, simpleOp(OP.LT(OP.TensorTy[]))),
53 :     (lte_ii, simpleOp(OP.LTE OP.IntTy)),
54 :     (lte_rr, simpleOp(OP.LTE(OP.TensorTy[]))),
55 :     (gte_ii, simpleOp(OP.GTE OP.IntTy)),
56 :     (gte_rr, simpleOp(OP.GTE(OP.TensorTy[]))),
57 :     (gt_ii, simpleOp(OP.GT OP.IntTy)),
58 :     (gt_rr, simpleOp(OP.GT(OP.TensorTy[]))),
59 :     (equ_bb, simpleOp(OP.EQ OP.BoolTy)),
60 :     (equ_ii, simpleOp(OP.EQ OP.IntTy)),
61 :     (equ_ss, simpleOp(OP.EQ OP.StringTy)),
62 :     (equ_rr, simpleOp(OP.EQ(OP.TensorTy[]))),
63 :     (neq_bb, simpleOp(OP.NEQ OP.BoolTy)),
64 :     (neq_ii, simpleOp(OP.NEQ OP.IntTy)),
65 :     (neq_ss, simpleOp(OP.NEQ OP.StringTy)),
66 :     (neq_rr, simpleOp(OP.NEQ(OP.TensorTy[]))),
67 :     (neg_i, simpleOp(OP.Neg OP.IntTy)),
68 : jhr 183 (neg_t, tensorOp OP.Neg),
69 :     (neg_f, fn (y, [DK, NK, SK], xs) => ??), (*FIXME*)
70 :     (op_at, fn (y, [DK, NK, SK], xs) => ??), (*FIXME*)
71 :     (op_D, fn (y, [DK, NK, SK], xs) => ??), (*FIXME*)
72 :     (op_norm, tensorOp OP.Norm),
73 : jhr 180 (op_not, simpleOp OP.Not),
74 : jhr 183 (op_subscript, fn (y, [SK, NK], xs) => ??), (*FIXME*)
75 :     (fn_CL, fn (y, [N3, N3], xs) => ??), (*FIXME*)
76 :     (fn_convolve, fn (y, [DK, NK, SK], xs) => ??), (*FIXME*)
77 : jhr 180 (fn_cos, simpleOp OP.Cos),
78 : jhr 183 (fn_dot, fn (y, [dv], xs) => (case TU.pruneDim(MV.toDim dv)
79 :     of Ty.DimConst d => assign (y, OP.Dot(OP.TensorTy[d]), xs)
80 :     | dim => raise Fail("unresolved dimension "^TU.dimToString dim)
81 :     (* end case *))),
82 :     (fn_inside, fn (y, [DK, NK, SK], xs) => ??), (*FIXME*)
83 :     (fn_load, fn (y, [NK, SK], xs) => ??), (*FIXME*)
84 : jhr 180 (fn_max, simpleOp Op.Min),
85 :     (fn_min, simpleOp OP.Max),
86 : jhr 183 (fn_modulate, fn (y, [NK], xs) => ??), (*FIXME*)
87 : jhr 180 (fn_pow, simpleOp OP.Pow),
88 : jhr 183 (fn_principleEvec, fn (y, [NK], xs) => ??), (*FIXME*)
89 : jhr 180 (fn_sin, simpleOp OP.Sin),
90 : jhr 183 (kn_bspln3, fn (y, [], xs) => ??, (*FIXME*)
91 :     (kn_bspln5, fn (y, [], xs) => ??, (*FIXME*)
92 :     (kn_ctmr, fn (y, [], xs) => ??, (*FIXME*)
93 :     (kn_tent, fn (y, [], xs) => ??, (*FIXME*)
94 : jhr 184 (i2r, simpleOp OP.IntToReal),
95 : jhr 183 (input, fn (y, [TK], xs) => ??) (*FIXME*)
96 : jhr 180 ];
97 :     tbl
98 :     end
99 :    
100 :     fun translate (y, f, mvs, xs) = (case Var.Tbl.find tbl f
101 :     of SOME transFn => transFn(mvs, xs)
102 :     | NONE => raise Fail("TranslateBasis.translate: unknown function " ^ Var.toString f)
103 :     (* end case *))
104 :    
105 :     end

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