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

SCM Repository

[diderot] View of /branches/charisee/src/compiler/tree-il/tree-il.sml
ViewVC logotype

View of /branches/charisee/src/compiler/tree-il/tree-il.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1444 - (download) (annotate)
Mon Jul 11 12:11:53 2011 UTC (8 years, 2 months ago) by jhr
Original Path: trunk/src/compiler/tree-il/tree-il.sml
File size: 3484 byte(s)
  Merging in changes from pure-cfg branch: removed CL, expanded trace, and added method name
  datatype.
(* tree-il.sml
 *
 * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 *
 * This representation restores the block structure and nested expression syntax
 * of the source language.
 *)

structure TreeIL =
  struct

    structure Op = LowOps
    structure Ty = LowILTypes

  (* program properties *)
    datatype program_prop
      = StrandsMayDie			(* present if strands may die *)
      | NewStrands			(* present if new strands may be created dynamically *)
      | StrandCommunication		(* present is strands read the state of other strands *)

    datatype program = Program of {
	props : program_prop list,
	globals : var list,
	inputInit : block,
	globalInit : block,
	strands : strand list,
	initially : {
	    isArray : bool,
	    iterPrefix : block,
	    iters : (var * exp * exp) list,
	    createPrefix : block,
	    strand : Atom.atom,
	    args : exp list
	  }
      }

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

    and strand_var = SV of {
	varying : bool,		(* varies over the lifetime of the strand *)
	output : bool,		(* is the output value of the strand *)
	var : var		(* the variable itself *)
      }

    and method = Method of {
	name : MethodName.name,
	body : block		(* method body *)
      }

    and block = Block of {
	locals : var list,
	body : stm list
      }

    and stm
      = S_Comment of string list
      | S_Assign of var * exp
      | S_IfThen of exp * block
      | S_IfThenElse of exp * block * block
    (* special Diderot forms *)
      | S_LoadImage of var * int * exp	(* load image data *)
      | S_Input of var * string * string * exp option (* get input *)
      | S_New of Atom.atom * exp list	(* new strand creation *)
      | S_Exit of exp list
    (* return functions for methods *)
      | S_Active of exp list
      | S_Stabilize of exp list
      | S_Die

    and exp
      = E_Var of var
      | E_Lit of Literal.literal
      | E_Op of Op.rator * exp list
      | E_Apply of ILBasis.name * exp list
      | E_Cons of Ty.ty * exp list

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

    and var_kind
      = VK_Global			(* global variable *)
      | VK_State of Atom.atom		(* strand state variable; argument is strand name *)
      | VK_Local			(* includes strand parameters *)

    structure Var : sig

	val kind : var -> var_kind
	val name : var -> string
	val toString : var -> string
	val ty : var -> Ty.ty

	structure Map : ORD_MAP where type Key.ord_key = var

      end = struct
	fun kind (V{kind, ...}) = kind
	fun name (V{name, ...}) = name
	fun toString (V{name, id, ...}) = concat[name, "$", Stamp.toString id]
	fun ty (V{ty, ...}) = ty
	local
	  structure VarOrd =
	    struct
	      type ord_key = var
	      fun compare (V{id=a, ...}, V{id=b, ...}) = Stamp.compare(a, b)
	    end
	in
	structure Map = RedBlackMapFn (VarOrd)
	end (* local *)
      end

  (* printing utilities for debugging *)
    fun propToString p = (case p
	   of StrandsMayDie => "StrandsMayDie"
	    | NewStrands => "NewStrands"
	    | StrandCommunication => "StrandCommunication"
	  (* end case *))

    fun kindToString k = (case k
	   of VK_Global => "Global"
	    | VK_State s => concat["State(", Atom.toString s, ")"]
	    | VK_Local => "Local"
	  (* end case *))

  end

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