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 183 - (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 :     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 180 val tbl = let
32 : jhr 183 val tbl = Var.Tbl.mkTable (128, Fail "Translate table")
33 : jhr 180 in
34 :     List.app (Var.Tbl.insert tbl) [
35 :     (add_ii, simpleOp(OP.Add OP.IntTy)),
36 : jhr 183 (add_tt, tensorOp OP.Add),
37 : jhr 180 (sub_ii, simpleOp(OP.Sub OP.IntTy)),
38 : jhr 183 (sub_tt, tensorOp OP.Sub),
39 : jhr 180 (mul_ii, simpleOp(OP.Mul OP.IntTy)),
40 :     (mul_rr, simpleOp(OP.Mul(OP.TensorTy[]))),
41 : jhr 183 (mul_rt, tensorOp OP.Scale),
42 :     (mul_tr, fn (y, sv, [t, r]) => tensorOp OP.Scale (y, sv, [r, t])),
43 : jhr 180 (div_ii, simpleOp(OP.Div OP.IntTy)),
44 :     (div_rr, simpleOp(OP.Div(OP.TensorTy[]))),
45 : jhr 183 (div_tr, fn (y, [SK], xs) => ??), (*FIXME*)
46 : jhr 180 (lt_ii, simpleOp(OP.LT OP.IntTy)),
47 :     (lt_rr, simpleOp(OP.LT(OP.TensorTy[]))),
48 :     (lte_ii, simpleOp(OP.LTE OP.IntTy)),
49 :     (lte_rr, simpleOp(OP.LTE(OP.TensorTy[]))),
50 :     (gte_ii, simpleOp(OP.GTE OP.IntTy)),
51 :     (gte_rr, simpleOp(OP.GTE(OP.TensorTy[]))),
52 :     (gt_ii, simpleOp(OP.GT OP.IntTy)),
53 :     (gt_rr, simpleOp(OP.GT(OP.TensorTy[]))),
54 :     (equ_bb, simpleOp(OP.EQ OP.BoolTy)),
55 :     (equ_ii, simpleOp(OP.EQ OP.IntTy)),
56 :     (equ_ss, simpleOp(OP.EQ OP.StringTy)),
57 :     (equ_rr, simpleOp(OP.EQ(OP.TensorTy[]))),
58 :     (neq_bb, simpleOp(OP.NEQ OP.BoolTy)),
59 :     (neq_ii, simpleOp(OP.NEQ OP.IntTy)),
60 :     (neq_ss, simpleOp(OP.NEQ OP.StringTy)),
61 :     (neq_rr, simpleOp(OP.NEQ(OP.TensorTy[]))),
62 :     (neg_i, simpleOp(OP.Neg OP.IntTy)),
63 : jhr 183 (neg_t, tensorOp OP.Neg),
64 :     (neg_f, fn (y, [DK, NK, SK], xs) => ??), (*FIXME*)
65 :     (op_at, fn (y, [DK, NK, SK], xs) => ??), (*FIXME*)
66 :     (op_D, fn (y, [DK, NK, SK], xs) => ??), (*FIXME*)
67 :     (op_norm, tensorOp OP.Norm),
68 : jhr 180 (op_not, simpleOp OP.Not),
69 : jhr 183 (op_subscript, fn (y, [SK, NK], xs) => ??), (*FIXME*)
70 :     (fn_CL, fn (y, [N3, N3], xs) => ??), (*FIXME*)
71 :     (fn_convolve, fn (y, [DK, NK, SK], xs) => ??), (*FIXME*)
72 : jhr 180 (fn_cos, simpleOp OP.Cos),
73 : jhr 183 (fn_dot, fn (y, [dv], xs) => (case TU.pruneDim(MV.toDim dv)
74 :     of Ty.DimConst d => assign (y, OP.Dot(OP.TensorTy[d]), xs)
75 :     | dim => raise Fail("unresolved dimension "^TU.dimToString dim)
76 :     (* end case *))),
77 :     (fn_inside, fn (y, [DK, NK, SK], xs) => ??), (*FIXME*)
78 :     (fn_load, fn (y, [NK, SK], xs) => ??), (*FIXME*)
79 : jhr 180 (fn_max, simpleOp Op.Min),
80 :     (fn_min, simpleOp OP.Max),
81 : jhr 183 (fn_modulate, fn (y, [NK], xs) => ??), (*FIXME*)
82 : jhr 180 (fn_pow, simpleOp OP.Pow),
83 : jhr 183 (fn_principleEvec, fn (y, [NK], xs) => ??), (*FIXME*)
84 : jhr 180 (fn_sin, simpleOp OP.Sin),
85 : jhr 183 (kn_bspln3, fn (y, [], xs) => ??, (*FIXME*)
86 :     (kn_bspln5, fn (y, [], xs) => ??, (*FIXME*)
87 :     (kn_ctmr, fn (y, [], xs) => ??, (*FIXME*)
88 :     (kn_tent, fn (y, [], xs) => ??, (*FIXME*)
89 :     (i2r, fn (y, [], xs) => ??, (*FIXME*)
90 :     (input, fn (y, [TK], xs) => ??) (*FIXME*)
91 : jhr 180 ];
92 :     tbl
93 :     end
94 :    
95 :     fun translate (y, f, mvs, xs) = (case Var.Tbl.find tbl f
96 :     of SOME transFn => transFn(mvs, xs)
97 :     | NONE => raise Fail("TranslateBasis.translate: unknown function " ^ Var.toString f)
98 :     (* end case *))
99 :    
100 :     end

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