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 3753 - (download) (annotate)
Thu Apr 14 06:02:18 2016 UTC (3 years, 2 months ago) by jhr
File size: 5001 byte(s)
working on merge
(* 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 = LowOps
    structure Ty = TreeTypes

    datatype program = Program of {
        props : Properties.t list,
        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 *)
        globalInit : block,             (* CFG to initialize other globals (if any) *)
        strand : strand,                (* the strand definition *)
        create : create,                (* initial strand creation *)
        update : block option           (* optional update code. *)
      }

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

    and create = Create of {
        dim : int option,               (* grid dimension; NONE for collections *)
        code : block                    (* the loop nest for creating the strands *)
      }

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

    and stm
      = S_Comment of string list
      | S_Assign of var list * exp
      | S_GAssign of global_var * exp
      | S_IfThen of exp * block
      | S_IfThenElse of exp * block * block
      | S_Foreach of var * exp * block
    (* special Diderot forms *)
      | S_LoadNrrd of var * Ty.ty * 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 list * exp  (* save strand state *)
      | S_Exit of exp list
    (* return functions for methods *)
      | S_Active
      | S_Stabilize
      | S_Die

    and exp
      = E_Global of global_var
      | E_State of state_var
      | E_Var of var
      | E_Lit of Literal.t
      | E_Op of Op.rator * exp list
      | E_Cons of exp list * Ty.ty
      | E_Seq of exp list * Ty.ty

    and global_var = GV of {
        name : string,          (* name (should be unique) *)
        ty : Ty.ty,             (* type *)
        input : bool            (* is an input variable *)
      }

    and state_var = SV of {
        name : string,          (* name (should be unique) *)
        ty : Ty.ty,             (* type *)
        varying : bool,         (* varies over the lifetime of the strand *)
        output : bool           (* is the output value of the strand *)
      }

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

    withtype input = global_var Inputs.input

    structure GlobalVar : sig
        val name : global_var -> string
        val ty : global_var -> Ty.ty
        val isInput : global_var -> bool
        val toString : global_var -> string
      end = struct
        fun name (GV{name, ...}) = name
        fun ty (GV{ty, ...}) = ty
        fun isInput (GV{input, ...}) = input
        fun toString (GV{name, ...}) = "globals." ^ name
      end

    structure StateVar : sig
        val name : state_var -> string
        val ty : state_var -> Ty.ty
        val isOutput : state_var -> bool
        val isVarying : state_var -> bool
        val toString : state_var -> string
      end = struct
        fun name (SV{name, ...}) = name
        fun ty (SV{ty, ...}) = ty
        fun isOutput (SV{output, ...}) = output
        fun isVarying (SV{varying, ...}) = varying
        fun toString (SV{name, ...}) = "self." ^ name
      end

    structure Var : sig

        val new : string * Ty.ty -> var
        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 new (name, ty) = V{
                name = name,
                id = Stamp.new(),
                ty = ty
              }
        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

  end

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