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

SCM Repository

[diderot] View of /branches/vis12/src/compiler/simplify/simple.sml
ViewVC logotype

View of /branches/vis12/src/compiler/simplify/simple.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1688 - (download) (annotate)
Wed Jan 25 13:36:13 2012 UTC (7 years, 7 months ago) by jhr
File size: 3290 byte(s)
  More work on dynamic sequences.
(* simple.sml
 *
 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 *
 * A simplified AST representation of a Diderot program.  This representation has the property
 * that the arguments to ifs, operators, etc. are variables and that the rhs of assignments
 * consist of a single operation.  It is not, however, a single-assignment representation.
 *)

structure Simple =
  struct

    datatype var_kind = datatype AST.var_kind

    datatype var = datatype AST.var

    datatype program = Program of {
	globals : var list,
	globalInit : block,
	strands : strand list,
	init : init			(* block evaluates any vars used in init *)
      }

    and init = Initially of {
	isArray : bool,
	rangeInit : block,
	iters : {param : var, lo : var, hi : var} list,
	create : create
      }

    and create = C_Create of {
	argInit : block,
	name : Atom.atom,
	args : var list
      }

    and iter = I_Range of {
	rangeInit : block,
	param : var,
	lo : var,
	hi : var
      }

    and strand = Strand of {
	name : Atom.atom,
	params : var list,
	state : var list,
	stateInit : block,
	methods : method list
      }

    and method = Method of StrandUtil.method_name * block

    and block = Block of stmt list

    and stmt
      = S_Var of var				(* introduce an uninitialized local variable. *)
						(* These stmts are needed for the results of *)
						(* conditional expressions *)
      | S_Assign of var * exp
      | S_IfThenElse of var * block * block
      | S_New of Atom.atom * var list
      | S_Die
      | S_Stabilize
      | S_Print of var list

    and exp
      = E_Var of var
      | E_Lit of Literal.literal
      | E_Tuple of var list
      | E_Apply of var * Types.meta_var list * var list * Types.ty
      | E_Cons of var list
      | E_Seq of var list
      | E_Slice of var * var option list * Types.ty	(* tensor slicing *)
      | E_Input of Types.ty * string * string * var option
      | E_LoadImage of ImageInfo.info * var
      | E_Coerce of {srcTy : Types.ty, dstTy : Types.ty, x : var}

    fun typeOf (E_Var x) = Var.monoTypeOf x
      | typeOf (E_Lit lit) = (case lit
	   of (Literal.Int _) => Types.T_Int
	    | (Literal.Float _) => Types.realTy
	    | (Literal.String s) => Types.T_String
	    | (Literal.Bool _) => Types.T_Bool
	  (* end case *))
      | typeOf (E_Tuple _) = raise Fail "E_Tuple"
      | typeOf (E_Apply(_, _, _, ty)) = ty
      | typeOf (E_Cons(x::xs)) = let
	  val d = List.length xs + 1
	  val ty = Var.monoTypeOf x
	  in
	    case ty
	     of Types.T_Tensor shape => Types.T_Tensor(Types.shapeExt(shape, Types.DimConst d))
	      | _ => raise Fail "element of tensor construction not tensor"
	    (* end case *)
	  end
      | typeOf (E_Cons[]) = raise Fail "impossible empty E_Cons"
      | typeOf (E_Seq[]) = raise Fail "empty sequence not supported yet"
      | typeOf (E_Seq(x::xs)) = let
	  val d = List.length xs + 1
	  val ty = Var.monoTypeOf x
	  in
	    Types.T_Sequence(ty, Types.DimConst d)
	  end
      | typeOf (E_Slice(_, _, ty)) = ty
      | typeOf (E_Input(ty, _, _, _)) = ty
      | typeOf (E_LoadImage(ImageInfo.ImgInfo{dim, ty=(dd, _), ...}, _)) =
	  Types.T_Image{
	      dim = Types.DimConst dim,
	      shape = Types.Shape(List.map Types.DimConst dd)
	    }

  end

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