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

SCM Repository

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

View of /branches/vis15/src/compiler/simple/simple.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3462 - (download) (annotate)
Tue Nov 24 19:06:11 2015 UTC (3 years, 9 months ago) by jhr
File size: 4689 byte(s)
working on merge
(* simple.sml
 *
 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
 *
 * COPYRIGHT (c) 2015 The University of Chicago
 * 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

    type var = SimpleVar.t

  (* types with the meta variables resolved *)
    type ty = SimpleTypes.ty

  (* resolved meta-variable arguments to basis functions *)
    datatype meta_arg = datatype SimpleTypes.meta_arg

    datatype input_init
      = NoDefault			(* uninitialized input *)
      | ConstExpr			(* initialized to constant.  The actual initialization
					 * is handled in the constInit block.
					 *)
      | LoadSeq of string		(* load a sequence from a file *)
      | Proxy of string * ImageInfo.info (* input image specified by proxy *)
      | Image of ImageInfo.info		(* input image w/o proxy *)

    datatype input = INP of {		(* global input variable *)
	var : var,			(* the global variable *)
        desc : string option,		(* the optional descriptor *)
        init : input_init		(* the optional default value *)
      }

    datatype program = Program of {
        props : Properties.t list,
	consts : var list,		(* constant variables *)
        inputs : input list,		(* input globals *)
	constInit : block,		(* code that initializes constants and inputs *)
        globals : var list,             (* non-input globals *)
        funcs : func list,
        init : block,
        strand : strand,
        create : create,
	update : block option
      }

    and func = Func of {
        f : var,
        params : var list,
        body : block
      }

    and strand = Strand of {
        name : Atom.atom,
        params : var list,
        state : var list,
        stateInit : block,
	initM : block option,
	updateM : block,
	stabilizeM : block option
      }

  (* initial-strands creation; the stmt will be a loop nest with a "new" as the body *)
    and create
      = C_Grid of int * block			(* grid; first argument specifies dimension *)
      | C_Collection of block			(* collection *)

    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_Foreach of var * var * block
      | S_New of Atom.atom * var list
      | S_Continue
      | S_Die
      | S_Stabilize
      | S_Return of var
      | S_Print of var list
      | S_MapReduce of {			(* parallel map-reduce *)
	    results : var list,			(* the results of reduction phase *)
	    reductions : AST.var list,		(* the reduction operators (one per result) *)
	    body : func,			(* a function that implements map part *)
	    args : var list,			(* the invariant arguments to the map phase *)
	    source : AST.var			(* the set of strands that we map over *)
	  }

    and exp
      = E_Var of var
      | E_Lit of Literal.t
      | E_Select of var * var					(* strand-field selection *)
      | E_Apply of var * var list * ty                          (* user-defined function *)
      | E_Prim of AST.var * meta_arg list * var list * ty       (* Diderot builtin *)
      | E_Tensor of var list * ty
      | E_Seq of var list * ty                                  (* sequence (ty is result type) *)
      | E_Slice of var * var option list * ty                   (* tensor slicing (ty is result type) *)
      | E_Coerce of {srcTy : ty, dstTy : ty, x : var}
      | E_LoadSeq of ty * string
      | E_LoadImage of ty * string * ImageInfo.info

    fun typeOf (E_Var x) = SimpleVar.typeOf x
      | typeOf (E_Lit lit) = (case lit
           of (Literal.Int _) => SimpleTypes.T_Int
            | (Literal.Real _) => SimpleTypes.T_Tensor[]
            | (Literal.String s) => SimpleTypes.T_String
            | (Literal.Bool _) => SimpleTypes.T_Bool
          (* end case *))
      | typeOf (E_Select(_, fld)) = SimpleVar.typeOf fld
      | typeOf (E_Apply(_, _, ty)) = ty
      | typeOf (E_Prim(_, _, _, ty)) = ty
      | typeOf (E_Tensor(_, ty)) = ty
      | typeOf (E_Seq(_, ty)) = ty
      | typeOf (E_Slice(_, _, ty)) = ty
      | typeOf (E_Coerce{dstTy, ...}) = dstTy
      | typeOf (E_LoadSeq(ty, _)) = ty
      | typeOf (E_LoadImage(ty, _, _)) = ty

  end

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