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

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