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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 806 - (view) (download)

1 : jhr 551 (* runtime-names.sml
2 :     *
3 :     * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     * All rights reserved.
5 :     *)
6 :    
7 :     structure RuntimeNames =
8 :     struct
9 :    
10 :     (* globals that specify the target characteristics. These should be initialized
11 :     * when the program object is created.
12 :     *)
13 :     val gVectorWid = ref 4
14 :     val gIntTy = ref CLang.int32
15 :     val gRealTy = ref CLang.float
16 :     val gRealSuffix = ref "?"
17 :     val gIntSuffix = ref "?"
18 : jhr 654 val gIntFormat = ref "?"
19 : jhr 551
20 :     (* initialize globals based on target precision *)
21 :     fun initTargetSpec () = if !Controls.doublePrecision
22 :     then (
23 :     gVectorWid := 2;
24 :     gIntTy := CLang.int64;
25 :     gRealTy := CLang.double;
26 :     gRealSuffix := "d";
27 : jhr 654 gIntSuffix := "l";
28 :     gIntFormat := "%ld")
29 : jhr 551 else (
30 :     gVectorWid := 4;
31 :     gIntTy := CLang.int32;
32 :     gRealTy := CLang.float;
33 :     gRealSuffix := "f";
34 : jhr 654 gIntSuffix := "i";
35 :     gIntFormat := "%d")
36 : jhr 551
37 :     fun addVecSuffix stem n = concat[stem, Int.toString n, !gRealSuffix]
38 :     fun addIVecSuffix stem n = concat[stem, Int.toString n, !gIntSuffix]
39 :    
40 :     fun addTySuffix (stem, TargetTy.T_Real) = stem ^ !gRealSuffix
41 :     | addTySuffix (stem, TargetTy.T_Vec n) = addVecSuffix stem n
42 :     | addTySuffix (stem, ty) = raise Fail(concat["invalid type ", TargetTy.toString ty, " for ", stem])
43 :    
44 : jhr 561 fun vecTy n = concat["vec", Int.toString n, !gRealSuffix, "_t"]
45 :     fun ivecTy n = concat["vec", Int.toString n, !gIntSuffix, "_t"]
46 : jhr 551 fun imageTy n = concat["Diderot_image", Int.toString n, "D_t"]
47 : jhr 683 fun matTy (n, m) = concat["Diderot_Mat", Int.toString n, "x", Int.toString m, "_t"]
48 : jhr 551
49 : jhr 623 (* names of generated tyes, functions, and globals *)
50 : jhr 551 val initGlobals = "Diderot_InitGlobals" (* function for initializing program globals *)
51 : jhr 618 val initially = "Diderot_Initially" (* function for creating initial strands *)
52 : jhr 551 fun strandInit strand = strand ^ "_InitState"
53 : jhr 552 fun strandTy strand = concat["Strand_", strand, "_t"]
54 : jhr 623 fun strandDesc strand = concat["Strand_", strand]
55 :     val numStrands = "Diderot_NumStrands"
56 :     val strands = "Diderot_Strands"
57 : jhr 551
58 : jhr 561 (* scalar math functions *)
59 :     fun max ty = addTySuffix ("max", ty)
60 :     fun min ty = addTySuffix ("min", ty)
61 :    
62 : jhr 754 (* lerp *)
63 :     fun lerp 0 = "lerp" ^ !gRealSuffix
64 :     | lerp n = concat["lerp", Int.toString n, !gRealSuffix]
65 :    
66 : jhr 551 (* vector math functions *)
67 : jhr 553 val mkVec = addVecSuffix "vec"
68 : jhr 551 val scale = addVecSuffix "scale"
69 :     val truncToInt = addVecSuffix "truncToInt"
70 :     val dot = addVecSuffix "dot"
71 :     fun cross () = addVecSuffix "cross" 3
72 :     val length = addVecSuffix "length"
73 :     val normalize = addVecSuffix "normalize"
74 : jhr 584 fun vecitof n = concat["vec", Int.toString n, "ito", !gRealSuffix]
75 :     fun vecftoi n = concat["vec", Int.toString n, !gRealSuffix, "toi"]
76 : jhr 551
77 : jhr 683 (* matrix operations *)
78 :     fun trace n = concat["trace", Int.toString n, "x", Int.toString n, !gRealSuffix]
79 : jhr 806 fun copyMat (n, m) = concat["copy", Int.toString n, "x", Int.toString m, !gRealSuffix]
80 : jhr 683
81 : jhr 562 (* Status_t symbols *)
82 :     val kActive = "DIDEROT_ACTIVE"
83 :     val kDie = "DIDEROT_DIE"
84 :     val kStabilize = "DIDEROT_STABILIZE"
85 :    
86 : jhr 551 (* Diderot runtime system hooks *)
87 : jhr 552 val statusTy = "Status_t"
88 : jhr 551 val toImageSpace = addVecSuffix "Diderot_ToImageSpace"
89 :     val inside = addVecSuffix "Diderot_Inside"
90 :     fun loadImage dim = concat["Diderot_LoadImage", Int.toString dim, "D"]
91 : jhr 573 val strandDescTy = "Strand_t"
92 : jhr 623 val worldTy = "Diderot_World_t"
93 :     val allocInitially = "Diderot_AllocInitially"
94 :     val inState = "Diderot_InState"
95 : jhr 551
96 :     fun input ty = (case ty
97 :     of TargetTy.T_String => "Diderot_InputString"
98 :     | TargetTy.T_Real => "Diderot_Input" ^ !gRealSuffix
99 :     | TargetTy.T_Vec 3 => "Diderot_InputVec3" ^ !gRealSuffix
100 :     | ty => raise Fail("unsupported input type " ^ TargetTy.toString ty)
101 :     (* end case *))
102 :    
103 :     end

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