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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4043 - (download) (annotate)
Sun Jun 26 14:00:38 2016 UTC (3 years, 2 months ago) by jhr
File size: 3763 byte(s)
  Working on merge: changed the way that we handle kernels in the AST and SimpleAST IRs (treat
  them like literals, instead of like variables).  Added code to rewrite Inside tests in Simple
  IR to use the image instead of the field, which fixes a problem with trying to do inside tests
  on Ein fields.  Added code to promote locals to globals as part of the simplify-vars phase.
(* ast.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 typed abstract-syntax tree representation of Diderot programs.
 *)

structure AST =
  struct

    structure Ty = Types

    type var = Var.t

  (* we tag variable uses with their location for error reporting *)
    type var_use = var * Error.span

    datatype var_kind = datatype Var.kind

    datatype program = Program of {
        props : Properties.t list,
	const_dcls : var_dcl list,			(* constant variable declarations *)
	input_dcls : (var_dcl * string option) list,	(* input variable declarations *)
	globals : global_dcl list,			(* global variable and function declarations *)
	globInit : stmt option,				(* additional global init code (optional) *)
	strand : strand,				(* strand definition *)
	create : create,				(* initial strand creation *)
	init : stmt option,				(* global initially block (optional) *)
	update : stmt option				(* global update block (optional) *)
      }

  (* global declarations *)
    and global_dcl
      = D_Var of var_dcl				(* global-variable declaration *)
      | D_Func of var * var list * stmt			(* user-defined function *)

    and strand = Strand of {
        name : Atom.atom,				(* the strand name *)
        params : var list,				(* strand parameters *)
        state : var_dcl list,				(* state-variable declarations *)
	stateInit : stmt option,			(* additional state-variable init code (optional) *)
	initM : stmt option,				(* optional initially method *)
	updateM : stmt,					(* required update method *)
	stabilizeM : stmt option			(* optional stabilize method *)
      }

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

    and stmt
      = S_Block of stmt list
      | S_Decl of var_dcl
      | S_IfThenElse of expr * stmt * stmt
      | S_Foreach of iter * stmt
      | S_Assign of var_use * expr
      | S_New of Atom.atom * expr list
      | S_Continue
      | S_Die
      | S_Stabilize
      | S_Return of expr
      | S_Print of expr list

    and expr
      = E_Var of var_use
      | E_Lit of Literal.t
      | E_Kernel of Kernel.t
      | E_Select of expr * var_use			(* strand state-variable selection *)
      | E_Prim						(* application of primitive operator or *)
	  of var * Ty.meta_var list * expr list * Ty.ty	(* function; we record the meta-variable *)
							(* arguments so that we know how the the *)
							(* parameters were instantiated. *)
      | E_Apply of var_use * expr list * Ty.ty		(* application of field or user function *)
      | E_Comprehension of expr * iter * Ty.ty	        (* sequence comprehension *)
      | E_ParallelMap of expr * var * var * Ty.ty	(* parallel map over a global set of strands *)
      | E_Tensor of expr list * Ty.ty                   (* tensor-value construction *)
      | E_Seq of expr list * Ty.ty                      (* sequence-value construction (ty is result type) *)
      | E_Slice of expr * expr option list * Ty.ty      (* tensor slicing (ty is result type). Note
							 * that we restrict the indices to be
							 * constant expressions. *)
      | E_Cond of expr * expr * expr * Ty.ty            (* ty is result type *)
      | E_LoadNrrd of Ty.meta_var list * string * Ty.ty (* dynamic sequence and image loading *)
      | E_Coerce of {                                   (* coercion between types *)
            srcTy : Ty.ty,
            dstTy : Ty.ty,
            e : expr
          }

    withtype var_dcl = var * expr option
	 and iter = var * expr

  end

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