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

SCM Repository

[diderot] View of /branches/pure-cfg/src/compiler/c-target/runtime-names.sml
ViewVC logotype

View of /branches/pure-cfg/src/compiler/c-target/runtime-names.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 561 - (download) (annotate)
Wed Feb 23 00:31:32 2011 UTC (8 years, 6 months ago) by jhr
File size: 2641 byte(s)
  Working on C target and code generation
(* runtime-names.sml
 *
 * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 *)

structure RuntimeNames =
  struct

  (* globals that specify the target characteristics.  These should be initialized
   * when the program object is created.
   *)
    val gVectorWid = ref 4
    val gIntTy = ref CLang.int32
    val gRealTy = ref CLang.float
    val gRealSuffix = ref "?"
    val gIntSuffix = ref "?"

  (* initialize globals based on target precision *)
    fun initTargetSpec () = if !Controls.doublePrecision
	  then (
	    gVectorWid := 2;
	    gIntTy := CLang.int64;
	    gRealTy := CLang.double;
	    gRealSuffix := "d";
	    gIntSuffix := "l")
	  else (
	    gVectorWid := 4;
	    gIntTy := CLang.int32;
	    gRealTy := CLang.float;
	    gRealSuffix := "f";
	    gIntSuffix := "i")

    fun addVecSuffix stem n = concat[stem, Int.toString n, !gRealSuffix]
    fun addIVecSuffix stem n = concat[stem, Int.toString n, !gIntSuffix]

    fun addTySuffix (stem, TargetTy.T_Real) = stem ^ !gRealSuffix
      | addTySuffix (stem, TargetTy.T_Vec n) = addVecSuffix stem n
      | addTySuffix (stem, ty) = raise Fail(concat["invalid type ", TargetTy.toString ty, " for ", stem])

    fun vecTy n = concat["vec", Int.toString n, !gRealSuffix, "_t"]
    fun ivecTy n = concat["vec", Int.toString n, !gIntSuffix, "_t"]
    fun imageTy n = concat["Diderot_image", Int.toString n, "D_t"]

  (* names of generated functions *)
    val initGlobals = "Diderot_InitGlobals"	(* function for initializing program globals *)
    fun strandInit strand = strand ^ "_InitState"
    fun strandTy strand = concat["Strand_", strand, "_t"]

  (* scalar math functions *)
    fun max ty = addTySuffix ("max", ty)
    fun min ty = addTySuffix ("min", ty)

  (* vector math functions *)
    val mkVec = addVecSuffix "vec"
    val scale = addVecSuffix "scale"
    val truncToInt = addVecSuffix "truncToInt"
    val dot = addVecSuffix "dot"
    fun cross () = addVecSuffix "cross" 3
    val length = addVecSuffix "length"
    val normalize = addVecSuffix "normalize"

  (* Diderot runtime system hooks *)
    val statusTy = "Status_t"
    val toImageSpace = addVecSuffix "Diderot_ToImageSpace"
    val inside = addVecSuffix "Diderot_Inside"
    fun loadImage dim = concat["Diderot_LoadImage", Int.toString dim, "D"]

    fun input ty = (case ty
	   of TargetTy.T_String => "Diderot_InputString"
	    | TargetTy.T_Real => "Diderot_Input" ^ !gRealSuffix
	    | TargetTy.T_Vec 3 => "Diderot_InputVec3" ^ !gRealSuffix
	    | ty => raise Fail("unsupported input type " ^ TargetTy.toString ty)
	  (* end case *))

  end

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