SCM Repository
[diderot] / trunk / src / compiler / mid-to-low / mid-to-low.sml |
View of /trunk/src/compiler/mid-to-low/mid-to-low.sml
Parent Directory
|
Revision Log
Revision 431 -
(download)
(annotate)
Mon Oct 18 22:27:21 2010 UTC (10 years, 3 months ago) by jhr
File size: 3810 byte(s)
Mon Oct 18 22:27:21 2010 UTC (10 years, 3 months ago) by jhr
File size: 3810 byte(s)
Starting to work on mid-to-low translation
(* mid-to-low.sml * * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu) * All rights reserved. * * Translation from MidIL to LowIL representations. *) structure MidToLow : sig val translate : HighIL.program -> MidIL.program end = struct structure SrcIL = MidIL structure SrcOp = MidOps structure VTbl = SrcIL.Var.Tbl structure DstIL = LowIL structure DstOp = LowOps type var_env = DstIL.var VTbl.hash_table fun rename (env : var_env, x) = (case VTbl.find env x of SOME x' => x' | NONE => let val x' = DstIL.Var.new (SrcIL.Var.name x) in VTbl.insert env (x, x'); x' end (* end case *)) fun renameList (env, xs) = List.map (fn x => rename(env, x)) xs (* expand the EvalKernel operations into vector operations *) fun expandKernel (dimSize, kern, k, vec) = ?? (* compute the load address for a given set of voxels indices *) fun computeVoxelAddress (info, vec) = ?? fun expandOp (env, y, rator, args) = let fun assign rator' = [(y, DstIL.OP(rator', renameList(env, args)))] in case rator of SrcOp.Add ty => | SrcOp.Sub ty => | SrcOp.Mul ty => | SrcOp.Div ty => | SrcOp.Neg ty => | SrcOp.LT ty => | SrcOp.LTE ty => | SrcOp.EQ ty => | SrcOp.NEQ ty => | SrcOp.GT ty => | SrcOp.GTE ty => | SrcOp.Not => | SrcOp.Max => | SrcOp.Min => | SrcOp.Sin => | SrcOp.Cos => | SrcOp.Pow => | SrcOp.Dot d => | SrcOp.Cross => | SrcOp.Select ty => * int | SrcOp.Norm d => | SrcOp.Scale d => | SrcOp.InvScale d => | SrcOp.CL => | SrcOp.PrincipleEvec ty => | SrcOp.Subscript ty => | SrcOp.Floor d => | SrcOp.IntToReal => | SrcOp.TruncToInt d => | SrcOp.RoundToInt d => | SrcOp.CeilToInt d => | SrcOp.FloorToInt d => | SrcOp.VoxelAddress info => | SrcOp.LoadVoxels(rty, d) => | SrcOp.Transform info => | SrcOp.EvalKernel(d, h, k) => | SrcOp.LoadImage info => | SrcOp.Inside info => | SrcOp.Input(ty, name) => | SrcOp.InputWithDefault(ty, name) => | _ => raise Fail("unexpected " ^ SrcOp.toString rator) (* end case *) end (* expand a SrcIL assignment to a list of DstIL assignments *) fun expand (env, (y, rhs)) = let val y' = rename (env, y) fun assign rhs = [(y', rhs)] in case rhs of SrcIL.VAR x => assign (DstIL.VAR(rename(env, x))) | SrcIL.LIT lit => assign (DstIL.LIT lit) | SrcIL.OP(rator, args) => expandOp (env, y', rator, args) | SrcIL.CONS args => assign (DstIL.CONS(renameList(env, args))) (* end case *) end structure Trans = TranslateFn ( struct structure SrcIL = SrcIL structure DstIL = DstIL type var_env = var_env val rename = rename val expand = expand end) fun translate (SrcIL.Program{globals, globalInit, actors}) = let val env = VTbl.mkTable (256, Fail "env") fun transMethod (SrcIL.Method{name, stateIn, stateOut, body}) = DstIL.Method{ name = name, stateIn = renameList (env, stateIn), stateOut = renameList (env, stateOut), body = Trans.translate (env, body) } fun transActor (SrcIL.Actor{name, params, state, stateInit, methods}) = DstIL.Actor{ name = name, params = renameList (env, params), state = renameList (env, state), stateInit = Trans.translate (env, stateInit), methods = List.map transMethod methods } in DstIL.Program{ globals = renameList (env, globals), globalInit = Trans.translate (env, globalInit), actors = List.map transActor actors } end end
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |