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 183 - (download) (annotate)
Wed Jul 28 16:28:10 2010 UTC (10 years ago) by jhr
File size: 3627 byte(s)
  Working on translation to HighIL
(* 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

    val translate : (HighIL.var * Var.var * Types.meta_var list * HighIL.var list)
	  -> HighIL.simple_stmt list

  end = struct

    structure IL = HighIL
    structure Op = HighOps
    structure Ty = Types
    structure TU = TypeUtil
    structure MV = MetaVar

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

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

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

    val tbl = let
	  val tbl = Var.Tbl.mkTable (128, Fail "Translate table")
	    List.app (Var.Tbl.insert tbl) [
		(add_ii,	simpleOp(OP.Add OP.IntTy)),
		(add_tt,	tensorOp OP.Add),
		(sub_ii,	simpleOp(OP.Sub OP.IntTy)),
		(sub_tt,	tensorOp OP.Sub),
		(mul_ii,	simpleOp(OP.Mul OP.IntTy)),
		(mul_rr,	simpleOp(OP.Mul(OP.TensorTy[]))),
		(mul_rt,	tensorOp OP.Scale),
		(mul_tr,	fn (y, sv, [t, r]) => tensorOp OP.Scale (y, sv, [r, t])),
		(div_ii,	simpleOp(OP.Div OP.IntTy)),
		(div_rr,	simpleOp(OP.Div(OP.TensorTy[]))),
		(div_tr,	fn (y, [SK], xs) => ??), (*FIXME*)
		(lt_ii,		simpleOp(OP.LT OP.IntTy)),
		(lt_rr,		simpleOp(OP.LT(OP.TensorTy[]))),
		(lte_ii,	simpleOp(OP.LTE OP.IntTy)),
		(lte_rr,	simpleOp(OP.LTE(OP.TensorTy[]))),
		(gte_ii,	simpleOp(OP.GTE OP.IntTy)),
		(gte_rr,	simpleOp(OP.GTE(OP.TensorTy[]))),
		(gt_ii,		simpleOp(OP.GT OP.IntTy)),
		(gt_rr,		simpleOp(OP.GT(OP.TensorTy[]))),
		(equ_bb,	simpleOp(OP.EQ OP.BoolTy)),
		(equ_ii,	simpleOp(OP.EQ OP.IntTy)),
		(equ_ss,	simpleOp(OP.EQ OP.StringTy)),
		(equ_rr,	simpleOp(OP.EQ(OP.TensorTy[]))),
		(neq_bb,	simpleOp(OP.NEQ OP.BoolTy)),
		(neq_ii,	simpleOp(OP.NEQ OP.IntTy)),
		(neq_ss,	simpleOp(OP.NEQ OP.StringTy)),
		(neq_rr,	simpleOp(OP.NEQ(OP.TensorTy[]))),
		(neg_i,		simpleOp(OP.Neg OP.IntTy)),
		(neg_t,		tensorOp OP.Neg),
		(neg_f,		fn (y, [DK, NK, SK], xs) => ??), (*FIXME*)
		(op_at,		fn (y, [DK, NK, SK], xs) => ??), (*FIXME*)
		(op_D,		fn (y, [DK, NK, SK], xs) => ??), (*FIXME*)
		(op_norm,	tensorOp OP.Norm),
		(op_not,	simpleOp OP.Not),
		(op_subscript,	fn (y, [SK, NK], xs) => ??), (*FIXME*)
		(fn_CL,		fn (y, [N3, N3], xs) => ??), (*FIXME*)
		(fn_convolve,	fn (y, [DK, NK, SK], xs) => ??), (*FIXME*)
		(fn_cos,	simpleOp OP.Cos),
		(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 *))),
		(fn_inside,	fn (y, [DK, NK, SK], xs) => ??), (*FIXME*)
		(fn_load,	fn (y, [NK, SK], xs) => ??), (*FIXME*)
		(fn_max,	simpleOp Op.Min),
		(fn_min,	simpleOp OP.Max),
		(fn_modulate,	fn (y, [NK], xs) => ??), (*FIXME*)
		(fn_pow,	simpleOp OP.Pow),
		(fn_principleEvec,	fn (y, [NK], xs) => ??), (*FIXME*)
		(fn_sin,	simpleOp OP.Sin),
		(kn_bspln3,	fn (y, [], xs) => ??, (*FIXME*)
		(kn_bspln5,	fn (y, [], xs) => ??, (*FIXME*)
		(kn_ctmr,	fn (y, [], xs) => ??, (*FIXME*)
		(kn_tent,	fn (y, [], xs) => ??, (*FIXME*)
		(i2r,		fn (y, [], xs) => ??, (*FIXME*)
		(input,		fn (y, [TK], xs) => ??) (*FIXME*)

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


ViewVC Help
Powered by ViewVC 1.0.0