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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 194 - (download) (annotate)
Mon Aug 2 16:40:29 2010 UTC (8 years, 10 months ago) by jhr
File size: 4098 byte(s)
  Working on translation to IL
(* translate-basis.sml
 *
 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
 * All rights reserved.
 *
 * Translation for basis operations in Simple AST to HighIL code
 *)

structure TranslateBasis : sig

  (* translate(lhs, f, mvs, args) translates the application of f (specialized
   * to the instantiated meta variables mvs) to a list of SSA assignments in
   * reverse order.
   *)
    val translate : (HighIL.var * Var.var * Types.meta_var list * HighIL.var list)
	  -> HighIL.assign list

  end = struct

    structure BV = BasisVars
    structure IL = HighIL
    structure Op = HighOps
    structure Ty = Types
    structure TU = TypeUtil
    structure MV = MetaVar
    structure VTbl = Var.Tbl

    fun assign (y, rator, xs) = [(y, IL.OP(rator, xs))]

    fun simpleOp rator (y, [], xs) = assign (y, rator, xs)

    fun tensorOp rator (y, [sv], xs) = (case TU.pruneShape(MV.toShape sv)
	   of Ty.Shape dd => assign (y, rator(Op.TensorTy dd), xs)
	    | shp => raise Fail("unresolved shape " ^ TU.shapeToString shp)
	  (* end case *))

  (* build a table that maps Basis variables to their translation functions *)
    val tbl = let
	  val tbl = VTbl.mkTable (128, Fail "Translate table")
	  in
	    List.app (VTbl.insert tbl) [
		(BV.add_ii,		simpleOp(Op.Add Op.IntTy)),
		(BV.add_tt,		tensorOp Op.Add),
		(BV.sub_ii,		simpleOp(Op.Sub Op.IntTy)),
		(BV.sub_tt,		tensorOp Op.Sub),
		(BV.mul_ii,		simpleOp(Op.Mul Op.IntTy)),
		(BV.mul_rr,		simpleOp(Op.Mul(Op.TensorTy[]))),
		(BV.mul_rt,		tensorOp Op.Scale),
		(BV.mul_tr,		fn (y, sv, [t, r]) => tensorOp Op.Scale (y, sv, [r, t])),
		(BV.div_ii,		simpleOp(Op.Div Op.IntTy)),
		(BV.div_rr,		simpleOp(Op.Div(Op.TensorTy[]))),
		(BV.div_tr,		tensorOp Op.InvScale),
		(BV.lt_ii,		simpleOp(Op.LT Op.IntTy)),
		(BV.lt_rr,		simpleOp(Op.LT(Op.TensorTy[]))),
		(BV.lte_ii,		simpleOp(Op.LTE Op.IntTy)),
		(BV.lte_rr,		simpleOp(Op.LTE(Op.TensorTy[]))),
		(BV.gte_ii,		simpleOp(Op.GTE Op.IntTy)),
		(BV.gte_rr,		simpleOp(Op.GTE(Op.TensorTy[]))),
		(BV.gt_ii,		simpleOp(Op.GT Op.IntTy)),
		(BV.gt_rr,		simpleOp(Op.GT(Op.TensorTy[]))),
		(BV.equ_bb,		simpleOp(Op.EQ Op.BoolTy)),
		(BV.equ_ii,		simpleOp(Op.EQ Op.IntTy)),
		(BV.equ_ss,		simpleOp(Op.EQ Op.StringTy)),
		(BV.equ_rr,		simpleOp(Op.EQ(Op.TensorTy[]))),
		(BV.neq_bb,		simpleOp(Op.NEQ Op.BoolTy)),
		(BV.neq_ii,		simpleOp(Op.NEQ Op.IntTy)),
		(BV.neq_ss,		simpleOp(Op.NEQ Op.StringTy)),
		(BV.neq_rr,		simpleOp(Op.NEQ(Op.TensorTy[]))),
		(BV.neg_i,		simpleOp(Op.Neg Op.IntTy)),
		(BV.neg_t,		tensorOp Op.Neg),
		(BV.neg_f,		fn (y, [DK, NK, SK], xs) => ??), (*FIXME*)
		(BV.op_at,		fn (y, [DK, NK, SK], xs) => ??), (*FIXME*)
		(BV.op_D,		fn (y, [DK, NK, SK], xs) => ??), (*FIXME*)
		(BV.op_norm,		tensorOp Op.Norm),
		(BV.op_not,		simpleOp Op.Not),
		(BV.op_subscript,	fn (y, [SK, NK], xs) => ??), (*FIXME*)
		(BV.fn_CL,		fn (y, [N3, N3], xs) => ??), (*FIXME*)
		(BV.fn_convolve,	fn (y, [DK, NK, SK], xs) => ??), (*FIXME*)
		(BV.fn_cos,		simpleOp Op.Cos),
		(BV.fn_dot,		fn (y, [dv], xs) => (case TU.pruneDim(MV.toDim dv)
					   of Ty.DimConst d => assign (y, Op.Dot(Op.TensorTy[d]), xs)
					    | dim => raise Fail("unresolved dimension "^TU.dimToString dim)
					  (* end case *))),
		(BV.fn_inside,		fn (y, [DK, NK, SK], xs) => ??), (*FIXME*)
		(BV.fn_load,		fn (y, [NK, SK], xs) => ??), (*FIXME*)
		(BV.fn_max,		simpleOp Op.Min),
		(BV.fn_min,		simpleOp Op.Max),
		(BV.fn_modulate,	fn (y, [NK], xs) => ??), (*FIXME*)
		(BV.fn_pow,		simpleOp Op.Pow),
		(BV.fn_principleEvec,	fn (y, [NK], xs) => ??), (*FIXME*)
		(BV.fn_sin,		simpleOp Op.Sin),
		(BV.kn_bspln3,		fn (y, [], xs) => ??), (*FIXME*)
		(BV.kn_bspln5,		fn (y, [], xs) => ??), (*FIXME*)
		(BV.kn_ctmr,		fn (y, [], xs) => ??), (*FIXME*)
		(BV.kn_tent,		fn (y, [], xs) => ??), (*FIXME*)
		(BV.i2r,		simpleOp Op.IntToReal),
		(BV.input,		fn (y, [TK], xs) => ??) (*FIXME*)
	      ];
	    tbl
	  end

    fun translate (y, f, mvs, xs) = (case VTbl.find tbl f
	   of SOME transFn => transFn(mvs, xs)
	    | NONE => raise Fail("TranslateBasis.translate: unknown function " ^ Var.nameOf f)
	  (* end case *))

  end

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