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 2695 - (download) (annotate)
Fri Sep 12 01:55:00 2014 UTC (4 years, 11 months ago) by cchiw
File size: 7813 byte(s)
change to vector ops
(* 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 = TreeOps
    structure Ty = TreeILTypes
    structure Fnc=TreeFunc
    structure OprSet=Fnc.OprSet
    structure TySet=Fnc.TySet


    datatype program = Program of {
        props : StrandUtil.program_prop list,

	types : Ty.ty list,
	oprations : Fnc.oprator 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 : state_var list,
        stateInit : block,
        methods : method list
      }

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

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

    and subblock = Pink of {
        locals : var list,
        types:  TySet.set,
        opr:  OprSet.set,
        body : stm list
      }
    and block = Block of {
        locals : var list,
        body : stm list
    }

    and stm
      = S_Comment of string list
      | S_Assign of var list * 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_Save of state_var list * exp  (* save strand state *)
      | S_Exit of exp list
    (* return functions for methods *)
      | S_Active
      | S_Stabilize
      | S_Die
      | S_StoreVec of exp * bool*int *int * Ty.ty* exp list
            (*lhs var, isAligned, newSize,origSize,pieces, Operations, isArr*)
      | S_Cons of var * Ty.ty *Ty.ty * exp list (* Cons->Array  ,var,OriginalType,pieceSizes *)

 
    and exp
      = E_State of state_var
      | E_Var of var
      | E_Lit of Literal.literal
      | E_Op of Op.rator * exp list
      | E_Apply of MathFuns.name * exp list
      | E_Cons of Ty.ty*  exp list  (*Cons->Vector *)
      | E_LoadArr of bool*int * int * exp * exp
        (*aligned, newVecSize,originalVecSize, addr, offset *)
      | E_LoadVec of bool*int * int * exp * exp
      | E_Mux of bool*int *int * Ty.ty*exp list (* same as storeVec stmt*)
            (*eventual Merging of these two expressions*)
      
 
  (*When occurance >1  local variables are created, and the expression list are vars. Then other operators call the vars*)
 (*otherwise use entire expression.*)
 

    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_Local                        (* includes strand parameters *)




    structure Var : sig

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

    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

    fun kindToString k = (case k
           of VK_Global => "Global"
            | VK_Local => "Local"
          (* end case *))

    fun stateVarToString (SV{name, ...}) = "self." ^ name

 
     fun iTos m=Int.toString m
 
    fun toString(E_LoadArr(_,nSize,oSize, arg, offset)) = String.concat[" LDArray<",iTos nSize ,
            ":",iTos  oSize, ">", "( ", toString arg, ",", toString offset, ")"]
     |  toString(E_LoadVec(_,nSize,oSize, arg, offset)) = String.concat[" LDVec<",iTos nSize ,
            ":",iTos  oSize, ">", "( ", toString arg, ",", toString offset, ")"]
     | toString (E_Op(rator, args)) = String.concat["OP",Op.toString rator,"(",
        String.concatWith"," (List.map toString args),")"]
     | toString (E_Cons(ty, args)) =String.concat ["ConsExp:", Ty.toString ty, "(",
        String.concatWith"," (List.map toString args),")"]
     | toString (E_State x) = "StateVar"^stateVarToString x
     | toString (E_Var x) = String.concat[kindToString(Var.kind x),"- Var: "^Var.name x]
     | toString (E_Lit lit) = Literal.toString lit
     | toString(E_Apply(mathfn, args))=String.concat["Apply (",
        String.concatWith"," (List.map toString args),")"]
     | toString(E_Mux(_,nSize,oSize,pieces,args)) =  String.concat["Mux",iTos nSize,"|",iTos oSize,"@ [",
        Ty.toString pieces ,"]",(String.concatWith "," (List.map toString args))]

    fun toStringS(S_Assign( [v],e))=String.concat["Assignments : ",Var.name v,"=",toString e]
        | toStringS(S_Assign( _,e))=String.concat ["Assignments : -multiple =",toString e]
        | toStringS(  S_Comment _ )=String.concat["Comment"]
        | toStringS(S_IfThen _ )=String.concat["ifthen"]
        | toStringS(S_IfThenElse _ )=String.concat["ifthenelse"]
        | toStringS(S_LoadImage _ )=String.concat["ldimage"]
        | toStringS( S_Input _ )=String.concat["input"]
        | toStringS( S_New _ )=String.concat["new"]
        | toStringS( S_Save (xs,e) )=String.concat["savestmt:\n\t(", toString e,")"]
        | toStringS( S_Exit _ )=String.concat["exit"]
        | toStringS(S_Active  )=String.concat["active"]
        | toStringS( S_Stabilize  )=String.concat["stablize"]
        | toStringS( S_Die  )=String.concat["die"]
        | toStringS(S_StoreVec(x,_,tyNew, tyOrig,pieces,args)) =let
            val a= String.concatWith "," (List.map toString args)
            in
                String.concat["Statment Store-Arr: ",toString x,  "=",iTos tyNew,"|",iTos tyOrig,"@ [",
                Ty.toString pieces ,"]",a]
            end
         | toStringS (S_Cons(x,_,ty, args)) = String.concat ["ConsStmt:", Var.name x, "] =",Ty.toString ty, "(",
         String.concatWith"," (List.map toString args),")"]

       

      end

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