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

SCM Repository

[diderot] View of /branches/pure-cfg/src/compiler/codegen/target-sig.sml
ViewVC logotype

View of /branches/pure-cfg/src/compiler/codegen/target-sig.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 615 - (download) (annotate)
Sun Mar 13 14:36:05 2011 UTC (8 years, 6 months ago) by jhr
File size: 4777 byte(s)
  Adding for loops to TreeIL to support initially code generation
(* target-sig.sml
 *
 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 *
 * Support for generating C-like code (e.g., C, OpenCL, or CUDA)
 *)

signature TARGET =
  sig

    type program
    type strand
    type var
    type exp
    type stm
    type method
    type ty

  (* the maximum width of a vector of reals on the target.  This value takes into
   * account the actual size of reals (i.e., 32 or 64 bits).
   *)
    val vectorWidth : unit -> int

  (* target types *)
    val boolTy : ty
    val intTy : ty
    val realTy : ty
    val vecTy : int -> ty
    val ivecTy : int -> ty
    val stringTy : ty
    val imageTy : ImageInfo.info -> ty
    val imageDataTy : ImageInfo.info -> ty

    val newProgram : unit -> program

  (* output the code to a file.  The string is the basename of the file, the extension
   * is provided by the target.
   *)
    val generate : string * program -> unit

  (* register the global initialization part of a program *)
    val globalInit : program * stm -> unit

    structure Var : sig
	val global : program * ty * string -> var
	val param : ty * string -> var
	val state : strand * ty * string -> var
	val var : ty * string -> var
	val tmp : ty -> var
      end

  (* expression construction *)
    structure Expr : sig
      (* return true if the given expression from is allowed as a subexpression *)
	val allowedInline : exp -> bool
      (* variable references *)
	val global : var -> exp
	val getState : var -> exp
	val param : var -> exp
	val var : var -> exp
      (* literals *)
	val intLit : IntegerLit.integer -> exp
	val floatLit : FloatLit.float -> exp
	val stringLit : string -> exp
	val boolLit : bool -> exp
      (* select from a vector *)
	val select : int * exp -> exp
      (* vector (and scalar) arithmetic *)
	val add : exp * exp -> exp
	val mul : exp * exp -> exp
	val sub : exp * exp -> exp
	val divide : exp * exp -> exp
	val neg : exp -> exp
	val abs : exp -> exp
	val dot : exp * exp -> exp		(* dot product *)
	val cross : exp * exp -> exp		(* cross product *)
	val length : exp -> exp			(* vector length *)
	val normalize : exp -> exp		(* normalize vector *)
      (* comparisons *)
	val lt : exp * exp -> exp
	val lte : exp * exp -> exp
	val equ : exp * exp -> exp
	val neq : exp * exp -> exp
	val gte : exp * exp -> exp
	val gt : exp * exp -> exp
      (* logical connectives *)
	val not : exp -> exp
	val && : exp * exp -> exp
	val || : exp * exp -> exp
      (* misc functions *)
	val min : exp * exp -> exp
	val max : exp * exp -> exp
      (* math functions *)
	val pow : exp * exp -> exp
	val sin : exp -> exp
	val cos : exp -> exp
	val sqrt : exp -> exp
      (* rounding *)
	val trunc : exp -> exp			(* truncate real to integral real *)
	val round : exp -> exp			(* round real to integral real *)
	val floor : exp -> exp			(* real to integral real floor *)
	val ceil : exp -> exp			(* real to integral real ceiling *)
      (* conversions *)
	val toInt : exp -> exp			(* real to integer *)
	val toReal : exp -> exp			(* integer to real *)
      (* runtime system hooks *)
	val imageAddr : exp -> exp		(* based address of image data *)
	val getImgData : exp -> exp		(* fetch a data value from the *)
						(* specified address and convert to *)
						(* a real *)
	val posToImgSpace : exp * exp -> exp	(* map world-space pos to image-space *)
	val inside : exp * exp * int -> exp	(* inside image domain test, *)
						(* where params are: dim, pos, *)
						(* img , and border width *)
      end

  (* statement construction *)
    structure Stmt : sig
	val comment : string list -> stm
	val assignState : var * exp -> stm
	val decl : var * exp option -> stm	(* local variable declaration *)
	val assign : var * exp -> stm
	val block : stm list -> stm
	val ifthen : exp * stm -> stm
	val ifthenelse : exp * stm * stm -> stm
	val for : (ty * var * exp) list * exp * (var * exp) list * stm -> stm
      (* special Diderot forms *)
	val cons : var * exp list -> stm
	val getImgData : var * exp -> stm list	(* load a vector of data from the *)
						(* specified address and convert to *)
						(* a vector *)
	val loadImage : var * int * exp -> stm list
	val input : var * string * exp option -> stm list
	val exit : unit -> stm
      (* update method exits *)
	val active : unit -> stm
	val stabilize : unit -> stm
	val die : unit -> stm
      end

  (* strands *)
    structure Strand : sig
      (* define a strand with the given name *)
	val define : program * string -> strand
      (* register the strand-state initialization code.  The variables are the strand
       * parameters.
       *)
	val init : strand * var list * stm -> unit
      (* register a strand method *)
	val method : strand * string * stm -> unit
      end

  end

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