SCM Repository
View of /branches/pure-cfg/src/compiler/c-target/runtime-names.sml
Parent Directory
|
Revision Log
Revision 833 -
(download)
(annotate)
Sun Apr 17 20:00:11 2011 UTC (11 years, 2 months ago) by jhr
File size: 4098 byte(s)
Sun Apr 17 20:00:11 2011 UTC (11 years, 2 months ago) by jhr
File size: 4098 byte(s)
Working on refactoring code generation
(* runtime-names.sml * * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu) * All rights reserved. *) structure RuntimeNames = struct local structure Ty = TreeIL.Ty structure F = Format in (* 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 "?" val gIntFormat = 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"; gIntFormat := "%ld") else ( gVectorWid := 4; gIntTy := CLang.int32; gRealTy := CLang.float; gRealSuffix := "f"; gIntSuffix := "i"; gIntFormat := "%d") fun addRealSuffix stem = stem ^ !gRealSuffix fun addVecSuffix stem n = concat[stem, Int.toString n, !gRealSuffix] fun addIVecSuffix stem n = concat[stem, Int.toString n, !gIntSuffix] fun addTySuffix (stem, 0) = stem ^ !gRealSuffix | addTySuffix (stem, n) = addVecSuffix stem n 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"] fun matTy (n, m) = concat["Diderot_Mat", Int.toString n, "x", Int.toString m, "_t"] (* names of generated tyes, functions, and globals *) val initGlobals = "Diderot_InitGlobals" (* function for initializing program globals *) val initially = "Diderot_Initially" (* function for creating initial strands *) fun strandInit strand = strand ^ "_InitState" fun strandTy strand = concat["Strand_", strand, "_t"] fun strandDesc strand = concat["Strand_", strand] val numStrands = "Diderot_NumStrands" val strands = "Diderot_Strands" (* scalar math functions *) fun max () = addRealSuffix "max" fun min () = addRealSuffix "min" fun fabs () = addRealSuffix "fabs" (* lerp *) fun lerp n = addTySuffix("lerp", n) (* vector math functions *) val mkVec = addVecSuffix "vec" val scale = addVecSuffix "scale" val truncToInt = addVecSuffix "truncToInt" val dot = addVecSuffix "dot" fun mulVecMat (m, n) = F.format "mulVec%dMat%dx%d%s" [F.INT m, F.INT m, F.INT n, F.STR(!gRealSuffix)] fun mulMatVec (m, n) = F.format "mulMat%dx%dVec%d%s" [F.INT n, F.INT m, F.INT n, F.STR(!gRealSuffix)] fun mulMatMat (m, n, p) = F.format "mulMat%dx%dMat%dx%d%s" [F.INT m, F.INT n, F.INT n, F.INT p, F.STR(!gRealSuffix)] fun cross () = addVecSuffix "cross" 3 val length = addVecSuffix "length" val normalize = addVecSuffix "normalize" fun vecitof n = concat["vec", Int.toString n, "ito", !gRealSuffix] fun vecftoi n = concat["vec", Int.toString n, !gRealSuffix, "toi"] (* matrix operations *) fun trace n = concat["trace", Int.toString n, "x", Int.toString n, !gRealSuffix] fun copyMat (n, m) = concat["copy", Int.toString n, "x", Int.toString m, !gRealSuffix] (* Status_t symbols *) val kActive = "DIDEROT_ACTIVE" val kDie = "DIDEROT_DIE" val kStabilize = "DIDEROT_STABILIZE" (* 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"] val strandDescTy = "Strand_t" val worldTy = "Diderot_World_t" val allocInitially = "Diderot_AllocInitially" val inState = "Diderot_InState" fun input ty = (case ty of Ty.StringTy => "Diderot_InputString" | Ty.TensorTy[] => "Diderot_Input" ^ !gRealSuffix | Ty.TensorTy[3] => "Diderot_InputVec3" ^ !gRealSuffix | ty => raise Fail("unsupported input type " ^ Ty.toString ty) (* end case *)) end (* local *) end
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |