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

SCM Repository

[diderot] View of /branches/vis15/src/compiler/tree-ir/tree-ir.sml
ViewVC logotype

View of /branches/vis15/src/compiler/tree-ir/tree-ir.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4175 - (download) (annotate)
Fri Jul 8 15:26:30 2016 UTC (2 years, 11 months ago) by jhr
File size: 5192 byte(s)
  Working on merge: finishing up support for user-defined functions.
(* tree-ir.sml
 *
 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
 *
 * COPYRIGHT (c) 2016 The University of Chicago
 * All rights reserved.
 *
 * This representation restores the block structure and nested expression syntax
 * of the source language.
 *)

structure TreeIR =
  struct

    structure Op = TreeOps
    structure Ty = TreeTypes

    type target_info = {
	layout : int -> TreeTypes.vec_layout,
	isInline : LowOps.rator -> bool
      }

    datatype program = Program of {
        props : Properties.t list,
	target : target_info,		(* target-specific info about representation invariants *)
        consts : global_var list,       (* large constant variables *)
        inputs : input list,            (* global input variables *)
        constInit : block,              (* code that initializes constants and inputs *)
        globals : global_var list,      (* other global variables *)
	funcs : func_def list,		(* user-defined functions *)
        globInit : block,               (* CFG to initialize other globals (if any) *)
        strand : strand,                (* the strand definition *)
        create : create,                (* initial strand creation *)
	init : block option,		(* optional global initially code *)
        update : block option           (* optional global update code. *)
      }

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

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

    and method = Method of {
	  needsW : bool,		(* does the method need the world (e.g., to print) *)
	  hasG : bool,			(* does the method contain references to globals? *)
	  body : block			(* the method body *)
	}

    and block = Block of {
        locals : var list ref,		(* the local variables that are used in this block *)
        body : stm list
      }

    and stm
      = S_Comment of string list
      | S_Assign of bool * var * exp	(* assignment; the boolean is true for var decls *)
      | S_MAssign of var list * exp
      | S_GAssign of global_var * exp
      | S_IfThen of exp * block
      | S_IfThenElse of exp * block * block
      | S_For of var * exp * exp * block
      | S_Foreach of var * exp * block
    (* special Diderot forms *)
      | S_LoadNrrd of var * APITypes.t * string
      | S_Input of global_var * string * string option * exp option (* get input *)
      | S_InputNrrd of global_var * string * string option * string option (* get image/seq input *)
      | S_New of Atom.atom * exp list   (* new strand creation *)
      | S_Save of state_var * exp  (* save strand state *)
      | S_Print of Ty.t list * exp list
      | S_Return of exp
    (* return functions for methods *)
      | S_Active
      | S_Stabilize
      | S_Die

    and exp
      = E_Global of global_var
      | E_State of exp option * state_var
      | E_Var of var
      | E_Lit of Literal.t
      | E_Op of Op.rator * exp list
      | E_Apply of func * exp list		(* user-defined function application *)
      | E_Vec of int * int * exp list		(* vector value; the ints are the width and the
					         * padded width
						 *)
      | E_Cons of exp list * Ty.t		(* in-memory tensor value *)
      | E_Seq of exp list * Ty.t
      | E_Pack of Ty.vec_layout * exp list	(* pack vector pieces into composite vector value *)
      | E_VLoad of Ty.vec_layout * exp * int	(* load a piece of a composite vector value from
						 * a tensor.  The integer specifies the index of
						 * the piece.
						 *)

    and global_var = GV of {
        name : string,                  (* name (should be unique) *)
        ty : Ty.t,                      (* type *)
	xty : APITypes.t option,	(* external type (for inputs and outputs) *)
        input : bool,                   (* is an input variable *)
        output : bool,                  (* is the output value of the strand *)
        varying : bool                  (* varies over the execution of the program *)
      }

    and state_var = SV of {
        name : string,                  (* name (should be unique) *)
        ty : Ty.t,                      (* type *)
	xty : APITypes.t option,	(* external type (for outputs) *)
        varying : bool                  (* varies over the lifetime of the strand *)
      }

    and var = V of {
        name : string,                  (* name (should be unique) *)
        id : Stamp.stamp,               (* unique ID *)
        ty : Ty.t                       (* type *)
      }

    and func = FV of {
        name : string,                  (* name (should be unique) *)
        id : Stamp.stamp,               (* unique ID *)
        ty : Ty.t,                      (* return type *)
        paramTys : Ty.t list,           (* parameter types *)
	needsW : bool,			(* does the function need the world (e.g., to print) *)
	hasG : bool			(* does the function contain references to globals? *)
      }

    withtype input = global_var Inputs.input
         and create = block Create.t

  end

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