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

SCM Repository

[diderot] Annotation of /branches/pure-cfg/src/compiler/translate/translate-basis.sml
ViewVC logotype

Annotation of /branches/pure-cfg/src/compiler/translate/translate-basis.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 184 - (view) (download)
Original Path: trunk/src/compiler/translate/translate-basis.sml

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

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